test-gstable-sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,166 @@
1
+ # GStable SDK for Node.js
2
+
3
+ Official-style TypeScript / JavaScript client for the **GStable Payment API**. Use it to manage products, payment links, checkout sessions, webhooks, accounts, and public payment-capability data from Node.js **≥ 18**.
4
+
5
+ **Highlights**
6
+
7
+ - **Zero runtime dependencies** — uses the built-in `fetch` (Node 18+).
8
+ - **Dual publishing** — ESM and CommonJS builds plus `.d.ts` from one `tsup` pipeline.
9
+ - **Uniform API shape** — methods resolve to the JSON envelope `data` field; non-zero business `code` throws typed errors.
10
+
11
+ **Documentation:** [API introduction](https://docs.gstable.io/docs/api/overview/introduction) · [简体中文](https://docs.gstable.io/zh-Hans/docs/api/overview/introduction)
12
+
13
+ ---
14
+
15
+ ## Requirements
16
+
17
+ | Requirement | Version |
18
+ |-------------|---------|
19
+ | Node.js | **≥ 18** (global `fetch`) |
20
+
21
+ ---
22
+
23
+ ## Installation
24
+
25
+ ```bash
26
+ npm install @tian_zhao_car/gstable-sdk
27
+ ```
28
+
29
+ To depend on a local checkout instead of the registry:
30
+
31
+ ```bash
32
+ npm install file:../GStable-SDK
33
+ ```
34
+
35
+ *(Replace the package name if you publish under a different npm scope or unscoped name.)*
36
+
37
+ ---
38
+
39
+ ## Quick start
40
+
41
+ Create a client with your **API key**. The key may be the raw secret or already prefixed with `Bearer ` — the SDK normalizes it.
42
+
43
+ ```ts
44
+ import { GStableClient, GStableError, DEFAULT_BASE_URL } from '@tian_zhao_car/gstable-sdk'
45
+
46
+ const client = new GStableClient({
47
+ apiKey: process.env.GSTABLE_API_KEY!,
48
+ // Optional overrides:
49
+ // baseUrl: DEFAULT_BASE_URL,
50
+ // publicBaseUrl: 'https://api.gstable.io/public/api/v1',
51
+ })
52
+
53
+ try {
54
+ const product = await client.product.create({
55
+ name: 'Pro plan',
56
+ commonPrices: [1_000_000, 5_000_000], // micro-USD; 1_000_000 === USD 1.00
57
+ description: 'Optional description',
58
+ })
59
+ console.log(product.productId)
60
+ } catch (err) {
61
+ if (err instanceof GStableError) {
62
+ console.error(err.code, err.message) // branch on err.code, not message text
63
+ }
64
+ throw err
65
+ }
66
+ ```
67
+
68
+ **CommonJS**
69
+
70
+ ```js
71
+ const { GStableClient } = require('@tian_zhao_car/gstable-sdk')
72
+
73
+ const client = new GStableClient({ apiKey: process.env.GSTABLE_API_KEY })
74
+ client.product.list(1, 10).then(console.log)
75
+ ```
76
+
77
+ ---
78
+
79
+ ## Configuration
80
+
81
+ | Option | Default | Purpose |
82
+ |--------|---------|---------|
83
+ | `apiKey` | *(required)* | Sent as `Authorization: Bearer <key>` on private routes. |
84
+ | `baseUrl` | `https://api.gstable.io/api/v1` (see `DEFAULT_BASE_URL`) | Private API origin; trailing slashes are trimmed. |
85
+ | `publicBaseUrl` | `https://api.gstable.io/public/api/v1` (`DEFAULT_PUBLIC_BASE_URL`) | Public routes (e.g. capabilities); no `Authorization` header. |
86
+ | `fetchImpl` | `globalThis.fetch` | Inject for tests or custom environments. |
87
+
88
+ If public docs show a different host or path, **trust your integration**: override `baseUrl` / `publicBaseUrl` to match the environment you target.
89
+
90
+ ---
91
+
92
+ ## API surface (`GStableClient`)
93
+
94
+ | Property | Resource | Typical use |
95
+ |----------|-----------|-------------|
96
+ | `product` | Products | Create, update, list, archive, remove catalog items. |
97
+ | `account` | Accounts | Read-only list / detail for settlement accounts. |
98
+ | `paymentLink` | Payment links | Create and manage reusable payment URLs. |
99
+ | `checkoutSession` | Checkout sessions | One-off hosted checkout flows. |
100
+ | `webhook` | Webhooks | CRUD and lifecycle for event endpoints. |
101
+ | `capability` | Public capabilities | Supported tokens and payment routing matrix (no API key required by the server; client still needs `apiKey` today to construct `GStableClient`). |
102
+
103
+ Endpoint paths and HTTP verbs follow the [API documentation](https://docs.gstable.io/docs/api/overview/introduction).
104
+
105
+ ---
106
+
107
+ ## Responses and errors
108
+
109
+ - Successful calls return the **`data`** payload from the standard envelope `{ code, message, data }`.
110
+ - When `code !== 0` or HTTP indicates failure, the SDK throws **`GStableError`** with numeric **`code`** and **`message`**. Prefer **`code`** for branching; **do not** parse `message` for business logic (wording may change).
111
+ - Subclasses such as **`GStableProductError`**, **`GStableCommonError`**, and **`GStablePlatformError`** are used for documented code ranges — import them from the package when you need `instanceof` checks.
112
+
113
+ ---
114
+
115
+ ## Local development
116
+
117
+ ```bash
118
+ git clone <repo-url>
119
+ cd GStable-SDK
120
+ npm install
121
+ npm run build # output: dist/*.js, *.cjs, *.d.ts
122
+ npm run typecheck # tsc --noEmit
123
+ npm run dev # tsup watch
124
+ ```
125
+
126
+ `prepublishOnly` runs `npm run build` before publish. Published tarball includes **`dist/`** and **`README.md`** only (`package.json` `files` field).
127
+
128
+ ---
129
+
130
+ ## Runnable examples
131
+
132
+ From the repo root after `npm run build`:
133
+
134
+ ```bash
135
+ export GSTABLE_API_KEY="sk_live_..."
136
+ node examples/product/product-list.mjs
137
+ ```
138
+
139
+ | Folder | Topic |
140
+ |--------|--------|
141
+ | `examples/product/` | Product CRUD and listing |
142
+ | `examples/payment-link/` | Payment links |
143
+ | `examples/checkout-session/` | Checkout sessions |
144
+ | `examples/webhook/` | Webhook management |
145
+ | `examples/account-list-detail.mjs` | Accounts |
146
+
147
+ Set `GSTABLE_DEBUG=1` to log outbound URLs and headers (contains secrets — use only in safe environments).
148
+
149
+ ---
150
+
151
+ ## cURL reference
152
+
153
+ Same list call without the SDK:
154
+
155
+ ```bash
156
+ curl -sS 'https://api.gstable.io/api/v1/product/list/1/10' \
157
+ -H "Authorization: Bearer sk_live_..." \
158
+ -H "Accept: application/json" \
159
+ -H "Content-Type: application/json"
160
+ ```
161
+
162
+ ---
163
+
164
+ ## License
165
+
166
+ MIT — see `package.json`.