{"_id":"@byteindev/truemoney-voucher","_rev":"3-aa56c996cbeab3e6ecfb2ee8c4ed4468","name":"@byteindev/truemoney-voucher","dist-tags":{"latest":"1.1.1"},"versions":{"1.0.0":{"name":"@byteindev/truemoney-voucher","version":"1.0.0","keywords":["truemoney","voucher","gift","redeem","thailand","api-client","vercel"],"license":"MIT","_id":"@byteindev/truemoney-voucher@1.0.0","maintainers":[{"name":"byteindev","email":"zelthr.premium@gmail.com"}],"dist":{"shasum":"4933077edf6c1db412edcdea0289f68dd73cb1a3","tarball":"https://registry.npmjs.org/@byteindev/truemoney-voucher/-/truemoney-voucher-1.0.0.tgz","fileCount":10,"integrity":"sha512-3vs6rQ0RBw5/yxdMhnveG39Bd2g7/NQkU57gPi61i+Wy8YWNaXW1R40cU5VKjp5g2x6IFDLK9yQuzpkavhfEIQ==","signatures":[{"sig":"MEQCIFPnxUrmMLTuztMn2T4w+lHg+kXGqS8YikoqybyQ/BZAAiAnQKr/u6Fg3om99PuN2TotNoB6uOX0ducnrDY0fYq0bg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":57322},"main":"./dist/index.cjs","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","engines":{"node":">=18"},"exports":{".":{"types":{"import":"./dist/index.d.ts","require":"./dist/index.d.cts"},"import":"./dist/index.js","require":"./dist/index.cjs"},"./package.json":"./package.json"},"gitHead":"a7c562a013b9af8b35535a836873a7b524eefcf1","scripts":{"test":"vitest run","build":"tsup","test:live":"cross-env LIVE=1 vitest run test/live.test.ts","typecheck":"tsc --noEmit","prepublishOnly":"npm run build"},"_npmUser":{"name":"byteindev","email":"zelthr.premium@gmail.com"},"_npmVersion":"12.0.2","description":"Zero-dependency client for the Truemoney-Voucher REST APIs (Go / NestJS / FastAPI ports) — redeem TrueMoney gift vouchers from npm, pnpm, bun, yarn or the browser","directories":{},"sideEffects":false,"_nodeVersion":"24.18.0","allowScripts":{"esbuild@0.27.7":true},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.5.0","vitest":"^3.2.0","cross-env":"^7.0.3","typescript":"^5.8.0","@types/node":"^24.0.0"},"_npmOperationalInternal":{"tmp":"tmp/truemoney-voucher_1.0.0_1786483869015_0.5845959983443811","host":"s3://npm-registry-packages-npm-production"}},"1.1.0":{"name":"@byteindev/truemoney-voucher","version":"1.1.0","keywords":["truemoney","voucher","gift","redeem","thailand","api-client","vercel"],"license":"MIT","_id":"@byteindev/truemoney-voucher@1.1.0","maintainers":[{"name":"byteindev","email":"zelthr.premium@gmail.com"}],"dist":{"shasum":"fb07d95ab96625b2ef02d68a7f0e08f22adb2f97","tarball":"https://registry.npmjs.org/@byteindev/truemoney-voucher/-/truemoney-voucher-1.1.0.tgz","fileCount":10,"integrity":"sha512-ZjKmdBirqzfCSr1idTJBGFIa3w9D0eMeG/CICdP/UFcwlAcY/3cpDVglB24+B/02jfQMQ/MQG80rmZOepQZLUQ==","signatures":[{"sig":"MEUCIQCXfS6mY0xBQs8TYLbwGpAwTnPuKPT843HaXm3EjcKCZAIgMtgDVS3OTabZV9OA4AcWr97MeAH677JjY28d6Ty0t68=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":94165},"main":"./dist/index.cjs","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","engines":{"node":">=18"},"exports":{".":{"types":{"import":"./dist/index.d.ts","require":"./dist/index.d.cts"},"import":"./dist/index.js","require":"./dist/index.cjs"},"./package.json":"./package.json"},"gitHead":"a826c9dee78a7534e626e91239aedeb906783af6","scripts":{"test":"vitest run","build":"tsup","test:live":"cross-env LIVE=1 vitest run test/live.test.ts","typecheck":"tsc --noEmit","prepublishOnly":"npm run build"},"_npmUser":{"name":"byteindev","email":"zelthr.premium@gmail.com"},"_npmVersion":"12.0.2","description":"Zero-dependency client for the Truemoney-Voucher REST APIs (Go / NestJS / FastAPI ports) — redeem TrueMoney gift vouchers from npm, pnpm, bun, yarn or the browser","directories":{},"sideEffects":false,"_nodeVersion":"24.18.0","allowScripts":{"esbuild@0.27.7":true},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.5.0","vitest":"^3.2.0","cross-env":"^7.0.3","typescript":"^5.8.0","@types/node":"^24.0.0"},"_npmOperationalInternal":{"tmp":"tmp/truemoney-voucher_1.1.0_1786485844571_0.7408249724800977","host":"s3://npm-registry-packages-npm-production"}},"1.1.1":{"name":"@byteindev/truemoney-voucher","version":"1.1.1","description":"Zero-dependency client for the Truemoney-Voucher REST APIs (Go / NestJS / FastAPI ports) — redeem TrueMoney gift vouchers from npm, pnpm, bun, yarn or the browser","license":"MIT","author":{"name":"ByteInDev"},"homepage":"https://github.com/ByteInDev/Truemoney-Voucher-Package-npm","repository":{"type":"git","url":"git+https://github.com/ByteInDev/Truemoney-Voucher-Package-npm.git"},"type":"module","publishConfig":{"access":"public"},"main":"./dist/index.cjs","module":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"types":{"import":"./dist/index.d.ts","require":"./dist/index.d.cts"},"import":"./dist/index.js","require":"./dist/index.cjs"},"./package.json":"./package.json"},"sideEffects":false,"engines":{"node":">=18"},"scripts":{"build":"tsup","test":"vitest run","test:live":"cross-env LIVE=1 vitest run test/live.test.ts","typecheck":"tsc --noEmit","prepublishOnly":"npm run build"},"keywords":["truemoney","voucher","gift","redeem","thailand","api-client","vercel"],"devDependencies":{"@types/node":"^24.13.3","cross-env":"^7.0.3","tsup":"^8.5.0","typescript":"^5.9.3","vitest":"^3.2.7"},"allowScripts":{"esbuild@0.27.2":true},"overrides":{"esbuild":"0.27.2"},"gitHead":"592b78f06f4de97e32d9b6fc377cfc6631a67d77","_id":"@byteindev/truemoney-voucher@1.1.1","bugs":{"url":"https://github.com/ByteInDev/Truemoney-Voucher-Package-npm/issues"},"_nodeVersion":"24.18.0","_npmVersion":"12.0.2","dist":{"integrity":"sha512-g2B65+2kKA4zhSilj/tJ3XjVj7o0VS+zcVaMoJOOHyDVyd28Nm9Lzsgns+vqHbFUjliMEdmzahvctu4xDX43qw==","shasum":"7947eb2424332979ef1859c9494eec32edf9e3e8","tarball":"https://registry.npmjs.org/@byteindev/truemoney-voucher/-/truemoney-voucher-1.1.1.tgz","fileCount":10,"unpackedSize":83909,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCkNx7SFC4d9IDoKrM8q0Xcgj7zvgWthSuuAhH0AHLSdAIgZsMb2BZ2WlXrNB6LqIzCPUTNjuylwRvXAMkwLKmDYik="}]},"_npmUser":{"name":"byteindev","email":"zelthr.premium@gmail.com"},"directories":{},"maintainers":[{"name":"byteindev","email":"zelthr.premium@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/truemoney-voucher_1.1.1_1786492265482_0.9885558994588157"},"_hasShrinkwrap":false}},"time":{"created":"2026-08-11T21:31:08.765Z","modified":"2026-08-11T23:51:05.769Z","1.0.0":"2026-08-11T21:31:09.192Z","1.1.0":"2026-08-11T22:04:04.753Z","1.1.1":"2026-08-11T23:51:05.629Z"},"license":"MIT","keywords":["truemoney","voucher","gift","redeem","thailand","api-client","vercel"],"description":"Zero-dependency client for the Truemoney-Voucher REST APIs (Go / NestJS / FastAPI ports) — redeem TrueMoney gift vouchers from npm, pnpm, bun, yarn or the browser","maintainers":[{"name":"byteindev","email":"zelthr.premium@gmail.com"}],"readme":"<br>\n\n<div align=\"center\">\n\n# Truemoney-Voucher (npm)\n\n**ไคลเอนต์แบบ zero-dependency สำหรับ REST APIs ของ Truemoney-Voucher** — แลกรับ TrueMoney gift voucher จาก npm, pnpm, bun, yarn หรือเบราว์เซอร์\n\n![License: MIT](https://img.shields.io/badge/license-MIT-yellow.svg)\n![TypeScript](https://img.shields.io/badge/TypeScript-5.8-3178C6?logo=typescript&logoColor=white)\n![Node.js](https://img.shields.io/badge/Node.js-%3E%3D18-339933?logo=nodedotjs&logoColor=white)\n![Zero dependencies](https://img.shields.io/badge/dependencies-0-6DA55F)\n![ESM + CJS](https://img.shields.io/badge/ESM%20%2B%20CJS-both-8A2BE2)\n\n[English](README.md) - **ไทย**\n\n</div>\n\n---\n\nไคลเอนต์แบบ zero-dependency สำหรับตระกูล API [Truemoney-Voucher](https://github.com/ByteInDev) — มี backend สามตัวที่ใช้ HTTP contract เดียวกัน **และไคลเอนต์เลือกตัวที่เร็วที่สุดให้อัตโนมัติ**:\n\n| Provider | Backend | ที่อยู่ |\n| --- | --- | --- |\n| `auto` (ค่าเริ่มต้น) | probe ทั้งสามตัว ใช้ตัว healthy ที่เร็วที่สุด | failover อัตโนมัติเมื่อ network error |\n| `go` | [Go](https://github.com/ByteInDev/Truemoney-Voucher-Go) (uTLS `HelloFirefox_148` + HTTP/2 framer) | https://truemoney-voucher-go.vercel.app |\n| `nestjs` | [NestJS](https://github.com/ByteInDev/Truemoney-Voucher-NestJS) (cycletls Firefox 148 fingerprint) | https://truemoney-voucher-nestjs.vercel.app |\n| `fastapi` | [FastAPI](https://github.com/ByteInDev/Truemoney-Voucher-FastAPI) (curl_cffi Firefox 147 fingerprint) | https://truemoney-voucher-fastapi.vercel.app |\n\n## ความสามารถ\n\n| ความสามารถ | รายละเอียด |\n| ----------- | ----------- |\n| แลกรับโค้ด | `Client.redeem(code, mobile)` — ใส่โค้ดตรงๆ หรือลิงก์เต็ม `gift.truemoney.com` ก็ได้ |\n| Auto provider | ค่าเริ่มต้น `'auto'` — probe ทุก backend แล้วใช้ตัว healthy ที่เร็วสุด พร้อม failover เมื่อ network error |\n| Static API | `import { Client }` — ไม่ต้องสร้าง instance ไม่ต้อง config แค่ `await Client.redeem(...)` |\n| Zero dependencies | ไม่มี install scripts, ไม่มี native binaries, ไม่มี runtime deps — มีทั้ง ESM + CJS + types |\n| รันได้ทุกที่ | Node.js >= 18, Bun, Deno, เบราว์เซอร์ — อะไรก็ได้ที่มี `fetch` |\n| Error แบบมี type | `TruemoneyApiError`, `TruemoneyTimeoutError`, `TruemoneyError` พร้อมเข้าถึง envelope ได้ |\n\n## เริ่มต้นใช้งาน\n\nติดตั้งด้วย package manager ตัวไหนก็ได้:\n\n```bash\nnpm install @byteindev/truemoney-voucher\n# หรือ\npnpm add @byteindev/truemoney-voucher\n# หรือ\nyarn add @byteindev/truemoney-voucher\n# หรือ\nbun add @byteindev/truemoney-voucher\n```\n\nไม่ต้องตั้งค่าอะไร — `Client` คือ static wrapper พร้อมใช้ ครอบ instance ที่ config แบบ auto ให้แล้ว:\n\n```ts\nimport { Client } from '@byteindev/truemoney-voucher';\n\n// auto: probe backend สามตัวที่โฮสต์อยู่ แล้วใช้ตัว healthy ที่เร็วที่สุด\nconst result = await Client.redeem('12345678901234', '0812345678');\nconsole.log(result.status.code); // เช่น \"VOUCHER_NOT_FOUND\", \"TARGET_USER_REDEEMED\"\n\n// ตรวจว่า service ยังทำงานอยู่:\nconst alive = await Client.status();\n\n// ข้อมูลบริการ:\nconst info = await Client.info();\n```\n\n### เลือก provider เอง (หรือใช้ deployment ของตัวเอง)\n\n```ts\nimport { createClient } from '@byteindev/truemoney-voucher';\n\n// เลือก backend ตัวใดตัวหนึ่งจากสามตัวที่โฮสต์อยู่:\nconst client = createClient({ provider: 'nestjs' }); // 'go' | 'nestjs' | 'fastapi'\n\n// หรือใช้ base URL ของตัวเอง (ชนะ `provider` เสมอ):\nconst custom = createClient({\n  baseUrl: 'https://api.example.com',\n  timeoutMs: 15_000,\n});\n\n// `Client.configure()` สร้าง instance ใหม่ด้วยวิธีเดียวกัน:\nClient.configure({ provider: 'fastapi' });\n```\n\n## API Reference\n\n### Static `Client` (ไม่ต้องสร้าง instance)\n\n| Method | คำอธิบาย |\n| --- | --- |\n| `Client.redeem(code, mobile)` | แลกรับโค้ดตรงๆ หรือ campaign URL เต็ม ผ่าน backend healthy ที่เร็วที่สุด |\n| `Client.status()` | `true` เมื่อมี backend อย่างน้อยหนึ่งตัวตอบ 2xx ที่ `/status` |\n| `Client.info()` | service info + routes ของ backend ที่เลือก |\n| `Client.configure(options?)` | แทนที่ instance ร่วม (ค่าเริ่มต้น auto) |\n\n### `createClient(options?) => TruemoneyClient`\n\n| ตัวเลือก | Type | ค่าเริ่มต้น | คำอธิบาย |\n| --- | --- | --- | --- |\n| `provider` | `'auto' \\| 'go' \\| 'nestjs' \\| 'fastapi'` | `'auto'` | backend ที่จะเรียก — `'auto'` probe แล้วเลือกตัว healthy ที่เร็วสุด |\n| `baseUrl` | `string` | URL ของ provider | base URL เต็ม (ชนะ `provider`) |\n| `timeoutMs` | `number` | `30_000` | หมดเวลา per-request |\n| `fetch` | `typeof fetch` | global | fetch แบบกำหนดเอง (ทดสอบ, proxy) |\n| `userAgent` | `string` | `truemoney-voucher/1.1.0` | header `User-Agent` |\n| `headers` | `Record<string, string>` | — | header เพิ่มเติมในทุก request |\n\n### Auto provider\n\n- ใน request แรก (หรือเมื่อ cache 60 วินาทีหมดอายุ) backend ทั้งสามจะถูก probe พร้อมกัน (`GET /status`, probe timeout 3 วินาที) และจัดอันดับตาม latency\n- `redeem`, `status()` และ `info()` ไปที่ backend healthy ที่เร็วที่สุด — การจัดอันดับ cache ไว้ 60 วินาที\n- ถ้า redeem ล้มเหลวด้วย **network error** ไคลเอนต์ลอง backend healthy ตัวถัดไปอัตโนมัติ — validation error (`TruemoneyApiError`) **ไม่** trigger failover เพราะ redeem ใช้ครั้งเดียว ย้อนไม่ได้ failover แล้วก็ไม่ซ้ำ — กรณีแย่สุดแค่ `TARGET_USER_REDEEMED`\n- `client.explicitBaseUrl` คืน base URL ของ backend ที่เลือกแบบชัดเจน (`undefined` สำหรับ auto)\n\n### `client.redeem(code, mobile) => Promise<RedeemResult>`\n\nรับโค้ดตรงๆ **หรือ** ลิงก์เต็ม campaign URL (percent-encode ลงใน path —\nbackend รักษา `%2F` ไว้ ตรงกับ CLI ต้นฉบับ)\n\n- สำเร็จ → `{ ok: true, status: { message, code }, data }` เมื่อ upstream call สำเร็จ\n- ผิดพลาด → throw `TruemoneyApiError` สำหรับ validation/routing errors (`{ code, message }` envelope หรือ error body แบบ Spring ที่ normalize ให้แล้ว)\n\n### `client.status() => Promise<boolean>`\n\n`true` เมื่อได้ 2xx, `false` เมื่ออื่นๆ — ไม่ throw เด็ดขาด ปลอดภัยสำหรับ uptime checks\nโหมด auto: `true` เมื่อมี backend อย่างน้อยหนึ่งตัว healthy\n\n### `client.info() => Promise<ServiceInfo>`\n\nชื่อ service, เวอร์ชันที่ deploy (ถ้ามีการ expose), และรายการ routes\n\n### Errors\n\n| Error | เมื่อเกิด |\n| --- | --- |\n| `TruemoneyApiError` | API ตอบ `{ code, message }` (validation 400, not found 404, …) หรือ error body แบบ Spring — เปิดดู `status`, `code`, `envelope` ได้ |\n| `TruemoneyTimeoutError` | ไม่มีการตอบกลับภายใน `timeoutMs` |\n| `TruemoneyError` | network ล้มเหลว, response ไม่ใช่ JSON, envelope แปลกๆ |\n\nทุก error สืบทอดจาก `TruemoneyError`:\n\n```ts\nimport { TruemoneyApiError } from '@byteindev/truemoney-voucher';\n\ntry {\n  await Client.redeem(code, mobile);\n} catch (err) {\n  if (err instanceof TruemoneyApiError) {\n    console.log(err.code, err.message); // 400 \"Bad Request\"\n  }\n}\n```\n\n## TrueMoney status codes\n\nเมื่อ upstream call สำเร็จ `result.status.code` จะมีคำตอบของ TrueMoney:\n\n| Code | ความหมาย |\n| ---- | -------- |\n| `SUCCESS` | รับเงินสำเร็จ |\n| `TARGET_USER_REDEEMED` | คุณแลกโค้ดนี้ไปแล้ว |\n| `VOUCHER_OUT_OF_STOCK` | คนอื่นแลกไปแล้ว |\n| `VOUCHER_EXPIRED` | วอเล็ต voucher หมดอายุแล้ว |\n| `VOUCHER_NOT_FOUND` | ไม่พบโค้ดในระบบ |\n| `CANNOT_GET_OWN_VOUCHER` | แลกโค้ดของตัวเองไม่ได้ |\n| `TARGET_USER_NOT_FOUND` | ไม่พบเบอร์โทรศัพท์ในระบบ |\n| `INTERNAL_ERROR` | ไม่พบโค้ด หรือ URL ผิด |\n\n## เบราว์เซอร์\n\nไม่ต้อง build — package มีทั้ง ESM + CJS พร้อม TypeScript types:\n\n```html\n<script type=\"module\">\n  import { Client } from 'https://esm.sh/@byteindev/truemoney-voucher';\n  document.body.textContent = JSON.stringify(await Client.info());\n</script>\n```\n\n## การทดสอบ\n\n```bash\nnpm test                # unit tests (client, errors, providers) — offline\nnpm run test:live       # ตรวจกับ backend ที่โฮสต์อยู่ทั้งสามตัวแบบ real\n```\n\nชุดเทสต์แบบ live รัน `status`/`info` และตรวจ invalid voucher กับ Vercel\ndeployments ทั้งสามตัว บวก upstream call จริง — ยืนยันแล้วบน npm, pnpm 11\nและ Bun 1.3\n\n## Contributing\n\nยินดีรับ contribution! กรุณา:\n\n1. เปิด issue ก่อนสำหรับการเปลี่ยนแปลงใหญ่ๆ\n2. รักษา `npm run typecheck` และ `npm test` ให้เขียวเสมอ\n3. เพิ่ม `VERSION` ใน `src/version.ts` พร้อมกับ `package.json`\n\n## ข้อควรทราบ\n\n> **สำหรับการศึกษาหรือที่ผู้ให้บริการอนุญาตเท่านั้น**\n> การแลกโค้ดย้อนกลับไม่ได้ และอยู่ภายใต้ข้อกำหนดการใช้งานของ TrueMoney\n> โค้ด voucher เทียบเท่าเงินสด — อย่า log โค้ดเต็ม\n\n## License\n\nLicensed under the [MIT License](./LICENSE) © 2026 ByteInDev","readmeFilename":"README.th.md","homepage":"https://github.com/ByteInDev/Truemoney-Voucher-Package-npm","repository":{"type":"git","url":"git+https://github.com/ByteInDev/Truemoney-Voucher-Package-npm.git"},"author":{"name":"ByteInDev"},"bugs":{"url":"https://github.com/ByteInDev/Truemoney-Voucher-Package-npm/issues"}}