npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@pichxyaponn/tw-angpao

v1.3.0

Published

ระบบรับเงินจาก Truewallet (ซองอั่งเปา) ด้วย ElysiaJS

Downloads

332

Readme

tw-angpao

ระบบรับเงินจาก Truewallet (ซองอั่งเปา) ด้วย ElysiaJS

ติดตั้ง:

bun add @pichxyaponn/tw-angpao
# หรือ
npm install @pichxyaponn/tw-angpao

ตัวอย่างการใช้งาน:

example/index.ts

import { Elysia, t } from "elysia";
import { TWAngpao } from "@pichxyaponn/tw-angpao";

// Reusable validation models — a single source of truth for both
// runtime validation and TypeScript types.
const models = new Elysia().model({
  "redeem.body": t.Object({
    phoneNumber: t.String({
      minLength: 1,
      description: "Thai mobile number (e.g. 0812345678 or +66812345678)"
    }),
    voucherCode: t.String({
      minLength: 1,
      description: "TrueMoney voucher hash or full gift link"
    })
  }),
  "redeem.error": t.Object({
    status: t.Object({
      code: t.String(),
      message: t.String(),
      error: t.Optional(t.Any())
    }),
    data: t.Optional(t.Any())
  })
});

const app = new Elysia()
  .use(models)
  .use(TWAngpao("TWA"))
  .post(
    "/redeem",
    async ({ body, TWA, status }) => {
      const response = await TWA.redeem(body.phoneNumber, body.voucherCode);

      if (response.status.code !== "SUCCESS") {
        const code = response.status.code;
        // Server-side failures -> 5xx, invalid input / voucher problems -> 4xx
        const httpStatus =
          code.startsWith("HTTP_ERROR_") ||
          code.startsWith("NETWORK_ERROR") ||
          code === "INVALID_JSON_RESPONSE"
            ? 500
            : 400;
        return status(httpStatus, response);
      }

      // Success (200) — already shaped as { status: { code, message, data } }
      return response;
    },
    {
      body: "redeem.body",
      response: {
        400: "redeem.error",
        500: "redeem.error"
      }
    }
  )
  .listen(3000);

POST

host:port/redeem

Body

{
  "phoneNumber": "0881234567",
  "voucherCode": "c0d3v0ch3r1_c0d3v0ch3r2_c0d3v0ch3r3"
}

Response

{
  "status": {
    "code": "SUCCESS",
    "message": "Voucher redeemed successfully!",
    "data": {
      "voucher": {
        "voucher_id": "...",
        "amount_baht": "10.00",
        "redeemed_amount_baht": "10.00",
        "member": 1,
        "status": "active",
        "link": "...",
        "detail": "Your pocket money",
        "expire_date": 1728661892014,
        "type": "R",
        "redeemed": 1,
        "available": 0
      },
      "owner_profile": {
        "full_name": "... ***"
      },
      "redeemer_profile": {
        "mobile_number": "..."
      },
      "my_ticket": {
        "mobile": "...",
        "update_date": 1728402860358,
        "amount_baht": "10.00",
        "full_name": "...",
        "profile_pic": null
      },
      "tickets": [
        {
          "mobile": "...-xxx-...",
          "update_date": 1728402860358,
          "amount_baht": "10.00",
          "full_name": "... ***",
          "profile_pic": "..."
        }
      ]
    }
  }
}

Status codes จาก TrueMoney (ส่งต่อจาก API ปลายทาง)

| code | message | | ---------------------- | ---------------------------------- | | VOUCHER_OUT_OF_STOCK | Voucher ticket is out of stock. | | TARGET_USER_REDEEMED | Redeemed | | VOUCHER_NOT_FOUND | Voucher doesn't exist. | | CANNOT_GET_OWN_VOUCHER | Cannot claim your own voucher. | | VOUCHER_EXPIRED | The gift voucher link has expired. | | SUCCESS | Voucher redeemed successfully! |

Status codes จากตัว library เอง

| code | สาเหตุ | | --------------------- | ----------------------------------------------- | | INVALID_PHONE_NUMBER | เบอร์โทรไม่ใช่รูปแบบเบอร์มือถือไทยที่ถูกต้อง | | INVALID_VOUCHER_CODE | voucher code/link ว่างหรือแกะ code ไม่ได้ | | HTTP_ERROR_UNKNOWN | API ปลายทางตอบกลับไม่สำเร็จ (response ไม่ ok) | | INVALID_JSON_RESPONSE | API ตอบกลับมาไม่ใช่ JSON ที่ถูกต้อง | | NETWORK_ERROR | error ที่ไม่คาดคิด/เชื่อมต่อปลายทางไม่ได้ |

Config

name

ตั้งชื่อให้ Decorate method ได้:

เช่น TWA จะ Decorate Context ด้วย Context.TWA

Support

มีคำแนะนำหรืออยากช่วยพัฒนา ให้ส่ง Pull Request ได้เลย

Issues

มีปัญหาหรือฟีเจอร์ที่อยากให้เพิ่ม แจ้งได้ที่ หน้า Issues