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 +166 -0
- package/dist/index.cjs +604 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +737 -0
- package/dist/index.d.ts +737 -0
- package/dist/index.js +573 -0
- package/dist/index.js.map +1 -0
- package/package.json +48 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,573 @@
|
|
|
1
|
+
// src/errors.ts
|
|
2
|
+
var GStableError = class extends Error {
|
|
3
|
+
code;
|
|
4
|
+
constructor(code, message) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = "GStableError";
|
|
7
|
+
this.code = code;
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
function isGStableError(e) {
|
|
11
|
+
return e instanceof GStableError;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// src/errors/common-platform.ts
|
|
15
|
+
var CommonErrorCodes = {
|
|
16
|
+
INVALID_FIELD_FORMAT: 400101,
|
|
17
|
+
UNSUPPORTED_CURRENCY: 400201,
|
|
18
|
+
UNSUPPORTED_CHANNEL: 400202,
|
|
19
|
+
SETTLEMENT_CAPABILITIES_NOT_FOUND: 400203,
|
|
20
|
+
STAT_NOT_FOUND: 400301
|
|
21
|
+
};
|
|
22
|
+
var COMMON_ERROR_CODE_SET = new Set(
|
|
23
|
+
Object.values(CommonErrorCodes)
|
|
24
|
+
);
|
|
25
|
+
var CommonErrorMessages = {
|
|
26
|
+
[CommonErrorCodes.INVALID_FIELD_FORMAT]: "Invalid field format",
|
|
27
|
+
[CommonErrorCodes.UNSUPPORTED_CURRENCY]: "Unsupported currency",
|
|
28
|
+
[CommonErrorCodes.UNSUPPORTED_CHANNEL]: "Unsupported channel",
|
|
29
|
+
[CommonErrorCodes.SETTLEMENT_CAPABILITIES_NOT_FOUND]: "Settlement capabilities not found",
|
|
30
|
+
[CommonErrorCodes.STAT_NOT_FOUND]: "Stat not found"
|
|
31
|
+
};
|
|
32
|
+
function isCommonErrorCode(code) {
|
|
33
|
+
return COMMON_ERROR_CODE_SET.has(code);
|
|
34
|
+
}
|
|
35
|
+
var GStableCommonError = class extends GStableError {
|
|
36
|
+
commonErrorCode;
|
|
37
|
+
constructor(code, message) {
|
|
38
|
+
super(code, message);
|
|
39
|
+
this.name = "GStableCommonError";
|
|
40
|
+
this.commonErrorCode = code;
|
|
41
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
function isGStableCommonError(e) {
|
|
45
|
+
return e instanceof GStableCommonError;
|
|
46
|
+
}
|
|
47
|
+
var PlatformErrorCodes = {
|
|
48
|
+
TOO_MANY_REQUESTS: 900101,
|
|
49
|
+
FAILED_TO_CREATE_RECORD: 900201,
|
|
50
|
+
FAILED_TO_UPDATE_RECORD: 900202,
|
|
51
|
+
FAILED_TO_QUERY_RECORD: 900203,
|
|
52
|
+
IMAGE_PROCESSING_FAILED: 900301,
|
|
53
|
+
INTERNAL_SYSTEM_ERROR: 999999
|
|
54
|
+
};
|
|
55
|
+
var PLATFORM_ERROR_CODE_SET = new Set(
|
|
56
|
+
Object.values(PlatformErrorCodes)
|
|
57
|
+
);
|
|
58
|
+
var PlatformErrorMessages = {
|
|
59
|
+
[PlatformErrorCodes.TOO_MANY_REQUESTS]: "Too many requests",
|
|
60
|
+
[PlatformErrorCodes.FAILED_TO_CREATE_RECORD]: "Failed to create record",
|
|
61
|
+
[PlatformErrorCodes.FAILED_TO_UPDATE_RECORD]: "Failed to update record",
|
|
62
|
+
[PlatformErrorCodes.FAILED_TO_QUERY_RECORD]: "Failed to query record",
|
|
63
|
+
[PlatformErrorCodes.IMAGE_PROCESSING_FAILED]: "Image processing failed",
|
|
64
|
+
[PlatformErrorCodes.INTERNAL_SYSTEM_ERROR]: "Internal system error"
|
|
65
|
+
};
|
|
66
|
+
function isPlatformErrorCode(code) {
|
|
67
|
+
return PLATFORM_ERROR_CODE_SET.has(code);
|
|
68
|
+
}
|
|
69
|
+
var GStablePlatformError = class extends GStableError {
|
|
70
|
+
platformErrorCode;
|
|
71
|
+
constructor(code, message) {
|
|
72
|
+
super(code, message);
|
|
73
|
+
this.name = "GStablePlatformError";
|
|
74
|
+
this.platformErrorCode = code;
|
|
75
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
function isGStablePlatformError(e) {
|
|
79
|
+
return e instanceof GStablePlatformError;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// src/errors/product.ts
|
|
83
|
+
var ProductErrorCodes = {
|
|
84
|
+
/** 指定的 Product ID 不存在 */
|
|
85
|
+
NOT_FOUND: 100301,
|
|
86
|
+
/** 批量操作中部分商品 ID 不存在 */
|
|
87
|
+
PARTIAL_MISSING: 100302,
|
|
88
|
+
/** 批量操作中部分商品状态不可用 */
|
|
89
|
+
PARTIALLY_UNAVAILABLE: 100303,
|
|
90
|
+
/** 商品未处于激活状态,无法用于创建链接或会话 */
|
|
91
|
+
NOT_ACTIVE: 100304,
|
|
92
|
+
/** 商品已被关联使用,无法执行某些特定修改 */
|
|
93
|
+
HAS_BEEN_USED: 100305,
|
|
94
|
+
/** 商品已被逻辑删除 */
|
|
95
|
+
HAS_BEEN_REMOVED: 100306
|
|
96
|
+
};
|
|
97
|
+
var PRODUCT_ERROR_CODE_SET = new Set(
|
|
98
|
+
Object.values(ProductErrorCodes)
|
|
99
|
+
);
|
|
100
|
+
var ProductErrorMessages = {
|
|
101
|
+
[ProductErrorCodes.NOT_FOUND]: "Product not found",
|
|
102
|
+
[ProductErrorCodes.PARTIAL_MISSING]: "Product partial missing",
|
|
103
|
+
[ProductErrorCodes.PARTIALLY_UNAVAILABLE]: "Product partially unavailable",
|
|
104
|
+
[ProductErrorCodes.NOT_ACTIVE]: "Product is not active",
|
|
105
|
+
[ProductErrorCodes.HAS_BEEN_USED]: "Product has been used",
|
|
106
|
+
[ProductErrorCodes.HAS_BEEN_REMOVED]: "Product has been removed"
|
|
107
|
+
};
|
|
108
|
+
function isProductErrorCode(code) {
|
|
109
|
+
return PRODUCT_ERROR_CODE_SET.has(code);
|
|
110
|
+
}
|
|
111
|
+
var GStableProductError = class extends GStableError {
|
|
112
|
+
productErrorCode;
|
|
113
|
+
constructor(code, message) {
|
|
114
|
+
super(code, message);
|
|
115
|
+
this.name = "GStableProductError";
|
|
116
|
+
this.productErrorCode = code;
|
|
117
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
function isGStableProductError(e) {
|
|
121
|
+
return e instanceof GStableProductError;
|
|
122
|
+
}
|
|
123
|
+
function rewriteProductBusinessError(error) {
|
|
124
|
+
if (error instanceof GStableProductError) {
|
|
125
|
+
return error;
|
|
126
|
+
}
|
|
127
|
+
if (error instanceof GStableError && isProductErrorCode(error.code)) {
|
|
128
|
+
return new GStableProductError(error.code, error.message);
|
|
129
|
+
}
|
|
130
|
+
return error;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// src/errors/api-error.ts
|
|
134
|
+
function createTypedApiError(code, message) {
|
|
135
|
+
if (isProductErrorCode(code)) {
|
|
136
|
+
return new GStableProductError(code, message);
|
|
137
|
+
}
|
|
138
|
+
if (isCommonErrorCode(code)) {
|
|
139
|
+
return new GStableCommonError(code, message);
|
|
140
|
+
}
|
|
141
|
+
if (isPlatformErrorCode(code)) {
|
|
142
|
+
return new GStablePlatformError(code, message);
|
|
143
|
+
}
|
|
144
|
+
return new GStableError(code, message);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// src/http.ts
|
|
148
|
+
var DEFAULT_BASE_URL = "https://api.gstable.io/api/v1/";
|
|
149
|
+
var DEFAULT_PUBLIC_BASE_URL = "https://api.gstable.io/public/api/v1";
|
|
150
|
+
function isApiEnvelope(v) {
|
|
151
|
+
return v !== null && typeof v === "object" && "code" in v && typeof v.code === "number";
|
|
152
|
+
}
|
|
153
|
+
function messageForNonJsonBody(status, bodyPreview) {
|
|
154
|
+
const trimmed = bodyPreview.trim().slice(0, 280).replace(/\s+/g, " ");
|
|
155
|
+
if (status === 403) {
|
|
156
|
+
return [
|
|
157
|
+
"HTTP 403: The server rejected the request and the response body is not typical API JSON.",
|
|
158
|
+
"Common causes: invalid API key or insufficient permissions, WAF blocking, or base URL mismatch with https://docs.gstable.io.",
|
|
159
|
+
"Verify GSTABLE_API_KEY and endpoint URLs; retry from a server or trusted network.",
|
|
160
|
+
trimmed ? `(response snippet) ${trimmed}` : ""
|
|
161
|
+
].filter(Boolean).join(" ");
|
|
162
|
+
}
|
|
163
|
+
if (status === 401) {
|
|
164
|
+
return `HTTP 401: Authentication failed. Check the Authorization header / API key.${trimmed ? ` ${trimmed}` : ""}`;
|
|
165
|
+
}
|
|
166
|
+
return `HTTP ${status}${trimmed ? `: ${trimmed}` : " (response is not JSON or is empty)"}`;
|
|
167
|
+
}
|
|
168
|
+
function isGStableHttpDebug() {
|
|
169
|
+
if (typeof process === "undefined" || process.env == null) return false;
|
|
170
|
+
const v = process.env.GSTABLE_DEBUG;
|
|
171
|
+
return v === "1" || v === "true";
|
|
172
|
+
}
|
|
173
|
+
function logOutgoingRequest(method, url, headers) {
|
|
174
|
+
if (!isGStableHttpDebug()) return;
|
|
175
|
+
console.error("[GStable SDK debug]", JSON.stringify({ method, url, headers }, null, 2));
|
|
176
|
+
}
|
|
177
|
+
var GStableHttp = class {
|
|
178
|
+
baseUrl;
|
|
179
|
+
publicBaseUrl;
|
|
180
|
+
authHeader;
|
|
181
|
+
fetchFn;
|
|
182
|
+
constructor(options) {
|
|
183
|
+
this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/$/, "");
|
|
184
|
+
this.publicBaseUrl = (options.publicBaseUrl ?? DEFAULT_PUBLIC_BASE_URL).replace(/\/$/, "");
|
|
185
|
+
const key = options.apiKey.trim();
|
|
186
|
+
this.authHeader = key.startsWith("Bearer ") ? key : `Bearer ${key}`;
|
|
187
|
+
this.fetchFn = options.fetchImpl ?? globalThis.fetch.bind(globalThis);
|
|
188
|
+
}
|
|
189
|
+
extractEnvelopeData(res, rawText, parsed) {
|
|
190
|
+
if (!isApiEnvelope(parsed)) {
|
|
191
|
+
throw new GStableError(
|
|
192
|
+
res.status || -1,
|
|
193
|
+
!res.ok ? messageForNonJsonBody(res.status, rawText) : "Unexpected response: not a valid API envelope JSON"
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
const envelope = parsed;
|
|
197
|
+
if (!res.ok) {
|
|
198
|
+
throw createTypedApiError(
|
|
199
|
+
envelope.code ?? res.status,
|
|
200
|
+
envelope.message || `HTTP ${res.status}`
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
if (envelope.code !== 0) {
|
|
204
|
+
throw createTypedApiError(envelope.code, envelope.message ?? "API error");
|
|
205
|
+
}
|
|
206
|
+
return envelope.data;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* 调用公共 API(不携带 Authorization),响应格式与私有 API 相同。
|
|
210
|
+
*/
|
|
211
|
+
async requestPublicJson(method, path, body) {
|
|
212
|
+
const url = `${this.publicBaseUrl}${path.startsWith("/") ? path : `/${path}`}`;
|
|
213
|
+
const headers = {
|
|
214
|
+
Accept: "application/json",
|
|
215
|
+
"Content-Type": "application/json"
|
|
216
|
+
};
|
|
217
|
+
logOutgoingRequest(method, url, headers);
|
|
218
|
+
const init = { method, headers };
|
|
219
|
+
if (method === "POST" && body !== void 0) {
|
|
220
|
+
init.body = JSON.stringify(body);
|
|
221
|
+
}
|
|
222
|
+
let res;
|
|
223
|
+
try {
|
|
224
|
+
res = await this.fetchFn(url, init);
|
|
225
|
+
} catch (e) {
|
|
226
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
227
|
+
throw new GStableError(-1, `Network error: ${msg}`);
|
|
228
|
+
}
|
|
229
|
+
const rawText = await res.text().catch(() => "");
|
|
230
|
+
let parsed;
|
|
231
|
+
try {
|
|
232
|
+
parsed = rawText.length > 0 ? JSON.parse(rawText) : void 0;
|
|
233
|
+
} catch {
|
|
234
|
+
throw new GStableError(
|
|
235
|
+
res.status || -1,
|
|
236
|
+
messageForNonJsonBody(res.status, rawText)
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
return this.extractEnvelopeData(res, rawText, parsed);
|
|
240
|
+
}
|
|
241
|
+
async requestJson(method, path, body) {
|
|
242
|
+
const url = `${this.baseUrl}${path.startsWith("/") ? path : `/${path}`}`;
|
|
243
|
+
const headers = {
|
|
244
|
+
Accept: "application/json",
|
|
245
|
+
Authorization: this.authHeader,
|
|
246
|
+
"Content-Type": "application/json"
|
|
247
|
+
};
|
|
248
|
+
logOutgoingRequest(method, url, headers);
|
|
249
|
+
const init = { method, headers };
|
|
250
|
+
if (method === "POST" && body !== void 0) {
|
|
251
|
+
init.body = JSON.stringify(body);
|
|
252
|
+
}
|
|
253
|
+
let res;
|
|
254
|
+
try {
|
|
255
|
+
res = await this.fetchFn(url, init);
|
|
256
|
+
} catch (e) {
|
|
257
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
258
|
+
throw new GStableError(-1, `Network error: ${msg}`);
|
|
259
|
+
}
|
|
260
|
+
const rawText = await res.text().catch(() => "");
|
|
261
|
+
let parsed;
|
|
262
|
+
try {
|
|
263
|
+
parsed = rawText.length > 0 ? JSON.parse(rawText) : void 0;
|
|
264
|
+
} catch {
|
|
265
|
+
throw new GStableError(
|
|
266
|
+
res.status || -1,
|
|
267
|
+
messageForNonJsonBody(res.status, rawText)
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
return this.extractEnvelopeData(res, rawText, parsed);
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
// src/resources/account.ts
|
|
275
|
+
var AccountResource = class {
|
|
276
|
+
constructor(http) {
|
|
277
|
+
this.http = http;
|
|
278
|
+
}
|
|
279
|
+
http;
|
|
280
|
+
/** GET /account/detail/:accountId */
|
|
281
|
+
detail(accountId) {
|
|
282
|
+
const id = encodeURIComponent(accountId);
|
|
283
|
+
return this.http.requestJson("GET", `/account/detail/${id}`);
|
|
284
|
+
}
|
|
285
|
+
/** GET /account/list — 全量返回,无分页(单商户最多 20 个账户) */
|
|
286
|
+
list() {
|
|
287
|
+
return this.http.requestJson("GET", "/account/list");
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
// src/resources/capability.ts
|
|
292
|
+
var CapabilityResource = class {
|
|
293
|
+
constructor(http) {
|
|
294
|
+
this.http = http;
|
|
295
|
+
}
|
|
296
|
+
http;
|
|
297
|
+
/** GET /capabilities/all */
|
|
298
|
+
all() {
|
|
299
|
+
return this.http.requestPublicJson("GET", "/capabilities/all");
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
// src/resources/checkout-session.ts
|
|
304
|
+
var CheckoutSessionResource = class {
|
|
305
|
+
constructor(http) {
|
|
306
|
+
this.http = http;
|
|
307
|
+
}
|
|
308
|
+
http;
|
|
309
|
+
/** POST /session/checkout/create */
|
|
310
|
+
create(body) {
|
|
311
|
+
return this.http.requestJson("POST", "/session/checkout/create", body);
|
|
312
|
+
}
|
|
313
|
+
/** POST /session/checkout/cancel(仅 initialized 且 signedOnce = 0) */
|
|
314
|
+
cancel(sessionId) {
|
|
315
|
+
return this.http.requestJson("POST", "/session/checkout/cancel", {
|
|
316
|
+
sessionId
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
/** GET /session/:sessionId — Checkout 与 Payment Link 会话均可查 */
|
|
320
|
+
detail(sessionId) {
|
|
321
|
+
const id = encodeURIComponent(sessionId);
|
|
322
|
+
return this.http.requestJson("GET", `/session/${id}`);
|
|
323
|
+
}
|
|
324
|
+
listByPath(path, page, size) {
|
|
325
|
+
const p = encodeURIComponent(String(page));
|
|
326
|
+
const s = encodeURIComponent(String(size));
|
|
327
|
+
return this.http.requestJson("GET", `${path}/${p}/${s}`);
|
|
328
|
+
}
|
|
329
|
+
/** GET /session/list/all/:page/:size */
|
|
330
|
+
listAll(page, size) {
|
|
331
|
+
return this.listByPath("/session/list/all", page, size);
|
|
332
|
+
}
|
|
333
|
+
/** GET /session/list/paid/:page/:size */
|
|
334
|
+
listPaid(page, size) {
|
|
335
|
+
return this.listByPath("/session/list/paid", page, size);
|
|
336
|
+
}
|
|
337
|
+
/** GET /session/list/settling/:page/:size */
|
|
338
|
+
listSettling(page, size) {
|
|
339
|
+
return this.listByPath("/session/list/settling", page, size);
|
|
340
|
+
}
|
|
341
|
+
/** GET /session/list/completed/:page/:size */
|
|
342
|
+
listCompleted(page, size) {
|
|
343
|
+
return this.listByPath("/session/list/completed", page, size);
|
|
344
|
+
}
|
|
345
|
+
/** GET /session/list/cancelled/:page/:size */
|
|
346
|
+
listCancelled(page, size) {
|
|
347
|
+
return this.listByPath("/session/list/cancelled", page, size);
|
|
348
|
+
}
|
|
349
|
+
/** GET /session/list/settlement/pending/:page/:size */
|
|
350
|
+
listSettlementPending(page, size) {
|
|
351
|
+
return this.listByPath("/session/list/settlement/pending", page, size);
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
// src/resources/payment-link.ts
|
|
356
|
+
var PaymentLinkResource = class {
|
|
357
|
+
constructor(http) {
|
|
358
|
+
this.http = http;
|
|
359
|
+
}
|
|
360
|
+
http;
|
|
361
|
+
/** POST /payment/link/create */
|
|
362
|
+
create(body) {
|
|
363
|
+
return this.http.requestJson("POST", "/payment/link/create", body);
|
|
364
|
+
}
|
|
365
|
+
/** POST /payment/link/update(全量替换) */
|
|
366
|
+
update(body) {
|
|
367
|
+
return this.http.requestJson("POST", "/payment/link/update", body);
|
|
368
|
+
}
|
|
369
|
+
/** POST /payment/link/disable */
|
|
370
|
+
disable(linkId) {
|
|
371
|
+
return this.http.requestJson("POST", "/payment/link/disable", {
|
|
372
|
+
linkId
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
/** POST /payment/link/enable */
|
|
376
|
+
enable(linkId) {
|
|
377
|
+
return this.http.requestJson("POST", "/payment/link/enable", {
|
|
378
|
+
linkId
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
/** GET /payment/link/:linkId */
|
|
382
|
+
detail(linkId) {
|
|
383
|
+
const id = encodeURIComponent(linkId);
|
|
384
|
+
return this.http.requestJson("GET", `/payment/link/${id}`);
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* GET /payment/link/list/:page/:size
|
|
388
|
+
* @param page 从 1 开始
|
|
389
|
+
*/
|
|
390
|
+
list(page, size) {
|
|
391
|
+
const p = encodeURIComponent(String(page));
|
|
392
|
+
const s = encodeURIComponent(String(size));
|
|
393
|
+
return this.http.requestJson(
|
|
394
|
+
"GET",
|
|
395
|
+
`/payment/link/list/${p}/${s}`
|
|
396
|
+
);
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
|
|
400
|
+
// src/resources/product.ts
|
|
401
|
+
var ProductResource = class {
|
|
402
|
+
constructor(http) {
|
|
403
|
+
this.http = http;
|
|
404
|
+
}
|
|
405
|
+
http;
|
|
406
|
+
async invoke(operation) {
|
|
407
|
+
try {
|
|
408
|
+
return await operation();
|
|
409
|
+
} catch (e) {
|
|
410
|
+
throw rewriteProductBusinessError(e);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
/** POST /product/create */
|
|
414
|
+
create(body) {
|
|
415
|
+
return this.invoke(
|
|
416
|
+
() => this.http.requestJson("POST", "/product/create", body)
|
|
417
|
+
);
|
|
418
|
+
}
|
|
419
|
+
/** POST /product/update(全量替换) */
|
|
420
|
+
update(body) {
|
|
421
|
+
return this.invoke(
|
|
422
|
+
() => this.http.requestJson("POST", "/product/update", body)
|
|
423
|
+
);
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* GET /product/list/:page/:size
|
|
427
|
+
* @param page 从 1 开始
|
|
428
|
+
* @param size 每页条数,最大 100
|
|
429
|
+
*/
|
|
430
|
+
list(page, size) {
|
|
431
|
+
const p = encodeURIComponent(String(page));
|
|
432
|
+
const s = encodeURIComponent(String(size));
|
|
433
|
+
return this.invoke(
|
|
434
|
+
() => this.http.requestJson("GET", `/product/list/${p}/${s}`)
|
|
435
|
+
);
|
|
436
|
+
}
|
|
437
|
+
/** POST /product/list/by/ids — 不存在的 id 会被静默忽略 */
|
|
438
|
+
listByIds(body) {
|
|
439
|
+
return this.invoke(
|
|
440
|
+
() => this.http.requestJson("POST", "/product/list/by/ids", body)
|
|
441
|
+
);
|
|
442
|
+
}
|
|
443
|
+
/** POST /product/archive */
|
|
444
|
+
archive(productId) {
|
|
445
|
+
return this.invoke(
|
|
446
|
+
() => this.http.requestJson("POST", "/product/archive", {
|
|
447
|
+
productId
|
|
448
|
+
})
|
|
449
|
+
);
|
|
450
|
+
}
|
|
451
|
+
/** POST /product/unarchive */
|
|
452
|
+
unarchive(productId) {
|
|
453
|
+
return this.invoke(
|
|
454
|
+
() => this.http.requestJson("POST", "/product/unarchive", {
|
|
455
|
+
productId
|
|
456
|
+
})
|
|
457
|
+
);
|
|
458
|
+
}
|
|
459
|
+
/** POST /product/remove — 仅未被任何 Payment Link 引用过的商品可删 */
|
|
460
|
+
remove(productId) {
|
|
461
|
+
return this.invoke(
|
|
462
|
+
() => this.http.requestJson("POST", "/product/remove", {
|
|
463
|
+
productId
|
|
464
|
+
})
|
|
465
|
+
);
|
|
466
|
+
}
|
|
467
|
+
};
|
|
468
|
+
|
|
469
|
+
// src/resources/webhook.ts
|
|
470
|
+
var WebhookResource = class {
|
|
471
|
+
constructor(http) {
|
|
472
|
+
this.http = http;
|
|
473
|
+
}
|
|
474
|
+
http;
|
|
475
|
+
/** POST /webhook/create */
|
|
476
|
+
create(body) {
|
|
477
|
+
return this.http.requestJson("POST", "/webhook/create", body);
|
|
478
|
+
}
|
|
479
|
+
/** POST /webhook/update(全量替换) */
|
|
480
|
+
update(body) {
|
|
481
|
+
return this.http.requestJson("POST", "/webhook/update", body);
|
|
482
|
+
}
|
|
483
|
+
/** GET /webhook/list — 全量,无分页 */
|
|
484
|
+
list() {
|
|
485
|
+
return this.http.requestJson("GET", "/webhook/list");
|
|
486
|
+
}
|
|
487
|
+
/** GET /webhook/detail/:webhookId */
|
|
488
|
+
detail(webhookId) {
|
|
489
|
+
const id = encodeURIComponent(webhookId);
|
|
490
|
+
return this.http.requestJson("GET", `/webhook/detail/${id}`);
|
|
491
|
+
}
|
|
492
|
+
/** POST /webhook/disable */
|
|
493
|
+
disable(webhookId) {
|
|
494
|
+
return this.http.requestJson("POST", "/webhook/disable", {
|
|
495
|
+
webhookId
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
/** POST /webhook/enable(含从 paused 恢复) */
|
|
499
|
+
enable(webhookId) {
|
|
500
|
+
return this.http.requestJson("POST", "/webhook/enable", {
|
|
501
|
+
webhookId
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
/** POST /webhook/key/refresh — 旧 key 立即失效 */
|
|
505
|
+
refreshKey(webhookId) {
|
|
506
|
+
return this.http.requestJson("POST", "/webhook/key/refresh", {
|
|
507
|
+
webhookId
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
/** POST /webhook/remove */
|
|
511
|
+
remove(webhookId) {
|
|
512
|
+
return this.http.requestJson("POST", "/webhook/remove", {
|
|
513
|
+
webhookId
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
};
|
|
517
|
+
|
|
518
|
+
// src/client.ts
|
|
519
|
+
var GStableClient = class {
|
|
520
|
+
http;
|
|
521
|
+
product;
|
|
522
|
+
account;
|
|
523
|
+
paymentLink;
|
|
524
|
+
capability;
|
|
525
|
+
checkoutSession;
|
|
526
|
+
/** AI Payment Protocol(创建会话 / 查询 / 准备支付) */
|
|
527
|
+
// readonly aiPayment: AiPaymentResource
|
|
528
|
+
webhook;
|
|
529
|
+
constructor(options) {
|
|
530
|
+
if (!options.apiKey?.trim()) {
|
|
531
|
+
throw new Error("GStableClient: apiKey is required");
|
|
532
|
+
}
|
|
533
|
+
this.http = new GStableHttp(options);
|
|
534
|
+
this.product = new ProductResource(this.http);
|
|
535
|
+
this.account = new AccountResource(this.http);
|
|
536
|
+
this.paymentLink = new PaymentLinkResource(this.http);
|
|
537
|
+
this.capability = new CapabilityResource(this.http);
|
|
538
|
+
this.checkoutSession = new CheckoutSessionResource(this.http);
|
|
539
|
+
this.webhook = new WebhookResource(this.http);
|
|
540
|
+
}
|
|
541
|
+
};
|
|
542
|
+
|
|
543
|
+
// src/resources/ai-payment.ts
|
|
544
|
+
var AiPaymentResource = class {
|
|
545
|
+
constructor(http) {
|
|
546
|
+
this.http = http;
|
|
547
|
+
}
|
|
548
|
+
http;
|
|
549
|
+
/** POST /payment/session/create */
|
|
550
|
+
createSession(body) {
|
|
551
|
+
return this.http.requestJson(
|
|
552
|
+
"POST",
|
|
553
|
+
"/payment/session/create",
|
|
554
|
+
body
|
|
555
|
+
);
|
|
556
|
+
}
|
|
557
|
+
/**
|
|
558
|
+
* GET /session/:sessionId
|
|
559
|
+
* 与核心 `checkoutSession.detail` 同路径;本方法按 AI 文档将 data 解析为含 `aiView` 的扁平结构。
|
|
560
|
+
*/
|
|
561
|
+
getSession(sessionId) {
|
|
562
|
+
const id = encodeURIComponent(sessionId);
|
|
563
|
+
return this.http.requestJson("GET", `/session/${id}`);
|
|
564
|
+
}
|
|
565
|
+
/** POST /payment/prepare */
|
|
566
|
+
preparePayment(body) {
|
|
567
|
+
return this.http.requestJson("POST", "/payment/prepare", body);
|
|
568
|
+
}
|
|
569
|
+
};
|
|
570
|
+
|
|
571
|
+
export { AccountResource, AiPaymentResource, CapabilityResource, CheckoutSessionResource, CommonErrorCodes, CommonErrorMessages, DEFAULT_BASE_URL, DEFAULT_PUBLIC_BASE_URL, GStableClient, GStableCommonError, GStableError, GStableHttp, GStablePlatformError, GStableProductError, PaymentLinkResource, PlatformErrorCodes, PlatformErrorMessages, ProductErrorCodes, ProductErrorMessages, ProductResource, WebhookResource, createTypedApiError, isCommonErrorCode, isGStableCommonError, isGStableError, isGStablePlatformError, isGStableProductError, isPlatformErrorCode, isProductErrorCode, rewriteProductBusinessError };
|
|
572
|
+
//# sourceMappingURL=index.js.map
|
|
573
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/errors.ts","../src/errors/common-platform.ts","../src/errors/product.ts","../src/errors/api-error.ts","../src/http.ts","../src/resources/account.ts","../src/resources/capability.ts","../src/resources/checkout-session.ts","../src/resources/payment-link.ts","../src/resources/product.ts","../src/resources/webhook.ts","../src/client.ts","../src/resources/ai-payment.ts"],"names":[],"mappings":";AAAO,IAAM,YAAA,GAAN,cAA2B,KAAA,CAAM;AAAA,EAC7B,IAAA;AAAA,EAET,WAAA,CAAY,MAAc,OAAA,EAAiB;AACzC,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,IAAA,GAAO,cAAA;AACZ,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AAAA,EACd;AACF;AAEO,SAAS,eAAe,CAAA,EAA+B;AAC5D,EAAA,OAAO,CAAA,YAAa,YAAA;AACtB;;;ACNO,IAAM,gBAAA,GAAmB;AAAA,EAC9B,oBAAA,EAAsB,MAAA;AAAA,EACtB,oBAAA,EAAsB,MAAA;AAAA,EACtB,mBAAA,EAAqB,MAAA;AAAA,EACrB,iCAAA,EAAmC,MAAA;AAAA,EACnC,cAAA,EAAgB;AAClB;AAIA,IAAM,wBAA6C,IAAI,GAAA;AAAA,EACrD,MAAA,CAAO,OAAO,gBAAgB;AAChC,CAAA;AAEO,IAAM,mBAAA,GAAuD;AAAA,EAClE,CAAC,gBAAA,CAAiB,oBAAoB,GAAG,sBAAA;AAAA,EACzC,CAAC,gBAAA,CAAiB,oBAAoB,GAAG,sBAAA;AAAA,EACzC,CAAC,gBAAA,CAAiB,mBAAmB,GAAG,qBAAA;AAAA,EACxC,CAAC,gBAAA,CAAiB,iCAA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IAAA,CAAK,WAAA,GAAc,IAAI,mBAAA,CAAoB,IAAA,CAAK,IAAI,CAAA;AACpD,IAAA,IAAA,CAAK,UAAA,GAAa,IAAI,kBAAA,CAAmB,IAAA,CAAK,IAAI,CAAA;AAClD,IAAA,IAAA,CAAK,eAAA,GAAkB,IAAI,uBAAA,CAAwB,IAAA,CAAK,IAAI,CAAA;AAE5D,IAAA,IAAA,CAAK,OAAA,GAAU,IAAI,eAAA,CAAgB,IAAA,CAAK,IAAI,CAAA;AAAA,EAC9C;AACF;;;AC3BO,IAAM,oBAAN,MAAwB;AAAA,EAC7B,YAA6B,IAAA,EAAmB;AAAnB,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAAA,EAAoB;AAAA,EAApB,IAAA;AAAA;AAAA,EAG7B,cAAc,IAAA,EAAqE;AACjF,IAAA,OAAO,KAAK,IAAA,CAAK,WAAA;AAAA,MACf,MAAA;AAAA,MACA,yBAAA;AAAA,MACA;AAAA,KACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,WAAW,SAAA,EAA8C;AACvD,IAAA,MAAM,EAAA,GAAK,mBAAmB,SAAS,CAAA;AACvC,IAAA,OAAO,KAAK,IAAA,CAAK,WAAA,CAA8B,KAAA,EAAO,CAAA,SAAA,EAAY,EAAE,CAAA,CAAE,CAAA;AAAA,EACxE;AAAA;AAAA,EAGA,eAAe,IAAA,EAAyD;AACtE,IAAA,OAAO,IAAA,CAAK,IAAA,CAAK,WAAA,CAAkC,MAAA,EAAQ,oBAAoB,IAAI,CAAA;AAAA,EACrF;AACF","file":"index.js","sourcesContent":["export class GStableError extends Error {\n readonly code: number\n\n constructor(code: number, message: string) {\n super(message)\n this.name = 'GStableError'\n this.code = code\n }\n}\n\nexport function isGStableError(e: unknown): e is GStableError {\n return e instanceof GStableError\n}\n","import { GStableError } from '../errors'\n\n/**\n * 通用与验证错误(400XXX)\n * @see https://docs.gstable.io/zh-Hans/docs/api/overview/errors#4-%E9%80%9A%E7%94%A8%E4%B8%8E%E9%AA%8C%E8%AF%81%E9%94%99%E8%AF%AF-common\n */\nexport const CommonErrorCodes = {\n INVALID_FIELD_FORMAT: 400101,\n UNSUPPORTED_CURRENCY: 400201,\n UNSUPPORTED_CHANNEL: 400202,\n SETTLEMENT_CAPABILITIES_NOT_FOUND: 400203,\n STAT_NOT_FOUND: 400301,\n} as const\n\nexport type CommonErrorCode = (typeof CommonErrorCodes)[keyof typeof CommonErrorCodes]\n\nconst COMMON_ERROR_CODE_SET: ReadonlySet<number> = new Set<number>(\n Object.values(CommonErrorCodes) as CommonErrorCode[],\n)\n\nexport const CommonErrorMessages: Record<CommonErrorCode, string> = {\n [CommonErrorCodes.INVALID_FIELD_FORMAT]: 'Invalid field format',\n [CommonErrorCodes.UNSUPPORTED_CURRENCY]: 'Unsupported currency',\n [CommonErrorCodes.UNSUPPORTED_CHANNEL]: 'Unsupported channel',\n [CommonErrorCodes.SETTLEMENT_CAPABILITIES_NOT_FOUND]: 'Settlement capabilities not found',\n [CommonErrorCodes.STAT_NOT_FOUND]: 'Stat not found',\n}\n\nexport function isCommonErrorCode(code: number): code is CommonErrorCode {\n return COMMON_ERROR_CODE_SET.has(code)\n}\n\nexport class GStableCommonError extends GStableError {\n readonly commonErrorCode: CommonErrorCode\n\n constructor(code: CommonErrorCode, message: string) {\n super(code, message)\n this.name = 'GStableCommonError'\n this.commonErrorCode = code\n Object.setPrototypeOf(this, new.target.prototype)\n }\n}\n\nexport function isGStableCommonError(e: unknown): e is GStableCommonError {\n return e instanceof GStableCommonError\n}\n\n/**\n * 平台系统错误(900XXX / 999999)\n * @see https://docs.gstable.io/zh-Hans/docs/api/overview/errors#5-%E5%B9%B3%E5%8F%B0%E7%B3%BB%E7%BB%9F%E9%94%99%E8%AF%AF-platform\n */\nexport const PlatformErrorCodes = {\n TOO_MANY_REQUESTS: 900101,\n FAILED_TO_CREATE_RECORD: 900201,\n FAILED_TO_UPDATE_RECORD: 900202,\n FAILED_TO_QUERY_RECORD: 900203,\n IMAGE_PROCESSING_FAILED: 900301,\n INTERNAL_SYSTEM_ERROR: 999999,\n} as const\n\nexport type PlatformErrorCode = (typeof PlatformErrorCodes)[keyof typeof PlatformErrorCodes]\n\nconst PLATFORM_ERROR_CODE_SET: ReadonlySet<number> = new Set<number>(\n Object.values(PlatformErrorCodes) as PlatformErrorCode[],\n)\n\nexport const PlatformErrorMessages: Record<PlatformErrorCode, string> = {\n [PlatformErrorCodes.TOO_MANY_REQUESTS]: 'Too many requests',\n [PlatformErrorCodes.FAILED_TO_CREATE_RECORD]: 'Failed to create record',\n [PlatformErrorCodes.FAILED_TO_UPDATE_RECORD]: 'Failed to update record',\n [PlatformErrorCodes.FAILED_TO_QUERY_RECORD]: 'Failed to query record',\n [PlatformErrorCodes.IMAGE_PROCESSING_FAILED]: 'Image processing failed',\n [PlatformErrorCodes.INTERNAL_SYSTEM_ERROR]: 'Internal system error',\n}\n\nexport function isPlatformErrorCode(code: number): code is PlatformErrorCode {\n return PLATFORM_ERROR_CODE_SET.has(code)\n}\n\nexport class GStablePlatformError extends GStableError {\n readonly platformErrorCode: PlatformErrorCode\n\n constructor(code: PlatformErrorCode, message: string) {\n super(code, message)\n this.name = 'GStablePlatformError'\n this.platformErrorCode = code\n Object.setPrototypeOf(this, new.target.prototype)\n }\n}\n\nexport function isGStablePlatformError(e: unknown): e is GStablePlatformError {\n return e instanceof GStablePlatformError\n}\n","import { GStableError } from '../errors'\n\n/**\n * 商品管理业务错误码(1003XX)\n * @see https://docs.gstable.io/zh-Hans/docs/api/overview/errors#%E5%95%86%E5%93%81%E7%AE%A1%E7%90%86-1003xx\n */\nexport const ProductErrorCodes = {\n /** 指定的 Product ID 不存在 */\n NOT_FOUND: 100301,\n /** 批量操作中部分商品 ID 不存在 */\n PARTIAL_MISSING: 100302,\n /** 批量操作中部分商品状态不可用 */\n PARTIALLY_UNAVAILABLE: 100303,\n /** 商品未处于激活状态,无法用于创建链接或会话 */\n NOT_ACTIVE: 100304,\n /** 商品已被关联使用,无法执行某些特定修改 */\n HAS_BEEN_USED: 100305,\n /** 商品已被逻辑删除 */\n HAS_BEEN_REMOVED: 100306,\n} as const\n\nexport type ProductErrorCode = (typeof ProductErrorCodes)[keyof typeof ProductErrorCodes]\n\nconst PRODUCT_ERROR_CODE_SET: ReadonlySet<number> = new Set<number>(\n Object.values(ProductErrorCodes) as ProductErrorCode[],\n)\n\n/** 文档中的英文 message,仅作展示参考;业务判断请使用 {@link ProductErrorCodes} */\nexport const ProductErrorMessages: Record<ProductErrorCode, string> = {\n [ProductErrorCodes.NOT_FOUND]: 'Product not found',\n [ProductErrorCodes.PARTIAL_MISSING]: 'Product partial missing',\n [ProductErrorCodes.PARTIALLY_UNAVAILABLE]: 'Product partially unavailable',\n [ProductErrorCodes.NOT_ACTIVE]: 'Product is not active',\n [ProductErrorCodes.HAS_BEEN_USED]: 'Product has been used',\n [ProductErrorCodes.HAS_BEEN_REMOVED]: 'Product has been removed',\n}\n\nexport function isProductErrorCode(code: number): code is ProductErrorCode {\n return PRODUCT_ERROR_CODE_SET.has(code)\n}\n\n/**\n * 商品模块 API 返回 1003XX 时的专用异常,可通过 `instanceof` 与 `productErrorCode` 分支处理。\n * 请依据 `code` / `productErrorCode` 编写逻辑,勿依赖 `message` 文案。\n */\nexport class GStableProductError extends GStableError {\n readonly productErrorCode: ProductErrorCode\n\n constructor(code: ProductErrorCode, message: string) {\n super(code, message)\n this.name = 'GStableProductError'\n this.productErrorCode = code\n Object.setPrototypeOf(this, new.target.prototype)\n }\n}\n\nexport function isGStableProductError(e: unknown): e is GStableProductError {\n return e instanceof GStableProductError\n}\n\n/** 将 {@link GStableError} 中属于商品业务码的异常转为 {@link GStableProductError},其它值原样返回 */\nexport function rewriteProductBusinessError(error: unknown): unknown {\n if (error instanceof GStableProductError) {\n return error\n }\n if (error instanceof GStableError && isProductErrorCode(error.code)) {\n return new GStableProductError(error.code, error.message)\n }\n return error\n}\n","import { GStableError } from '../errors'\nimport {\n GStableCommonError,\n GStablePlatformError,\n isCommonErrorCode,\n isPlatformErrorCode,\n} from './common-platform'\nimport { GStableProductError, isProductErrorCode } from './product'\n\n/**\n * 根据官方错误码构造对应的 {@link GStableError} 子类(商品 / 通用与验证 / 平台),供 HTTP 层与各资源统一使用。\n * @see https://docs.gstable.io/zh-Hans/docs/api/overview/errors\n */\nexport function createTypedApiError(code: number, message: string): GStableError {\n if (isProductErrorCode(code)) {\n return new GStableProductError(code, message)\n }\n if (isCommonErrorCode(code)) {\n return new GStableCommonError(code, message)\n }\n if (isPlatformErrorCode(code)) {\n return new GStablePlatformError(code, message)\n }\n return new GStableError(code, message)\n}\n","import { GStableError } from './errors'\nimport { createTypedApiError } from './errors/api-error'\nimport type { ApiEnvelope } from './types/common'\n\n/**\n * Default private API origin for this SDK (see `GStableHttpOptions.baseUrl` to override).\n * Trailing slashes are normalized when building request URLs.\n */\nexport const DEFAULT_BASE_URL = 'https://api.gstable.io/api/v1/'\n\n/**\n * Default public API origin (no `Authorization`; see `GStableHttpOptions.publicBaseUrl`).\n */\nexport const DEFAULT_PUBLIC_BASE_URL = 'https://api.gstable.io/public/api/v1'\n\nfunction isApiEnvelope(v: unknown): v is ApiEnvelope<unknown> {\n return (\n v !== null &&\n typeof v === 'object' &&\n 'code' in v &&\n typeof (v as ApiEnvelope<unknown>).code === 'number'\n )\n}\n\n/** Human-readable hint when the body is not JSON (e.g. gateway/HTML error page). */\nfunction messageForNonJsonBody(status: number, bodyPreview: string): string {\n const trimmed = bodyPreview.trim().slice(0, 280).replace(/\\s+/g, ' ')\n if (status === 403) {\n return [\n 'HTTP 403: The server rejected the request and the response body is not typical API JSON.',\n 'Common causes: invalid API key or insufficient permissions, WAF blocking, or base URL mismatch with https://docs.gstable.io.',\n 'Verify GSTABLE_API_KEY and endpoint URLs; retry from a server or trusted network.',\n trimmed ? `(response snippet) ${trimmed}` : '',\n ]\n .filter(Boolean)\n .join(' ')\n }\n if (status === 401) {\n return `HTTP 401: Authentication failed. Check the Authorization header / API key.${trimmed ? ` ${trimmed}` : ''}`\n }\n return `HTTP ${status}${trimmed ? `: ${trimmed}` : ' (response is not JSON or is empty)'}`\n}\n\nfunction isGStableHttpDebug(): boolean {\n if (typeof process === 'undefined' || process.env == null) return false\n const v = process.env.GSTABLE_DEBUG\n return v === '1' || v === 'true'\n}\n\nfunction logOutgoingRequest(\n method: HttpMethod,\n url: string,\n headers: Record<string, string>,\n): void {\n if (!isGStableHttpDebug()) return\n console.error('[GStable SDK debug]', JSON.stringify({ method, url, headers }, null, 2))\n}\n\nexport type HttpMethod = 'GET' | 'POST'\n\nexport interface GStableHttpOptions {\n /** API Key,无需带 `Bearer ` 前缀 */\n apiKey: string\n /** 未设置时使用 {@link DEFAULT_BASE_URL} */\n baseUrl?: string\n /** 公共 API 根路径,未设置时使用 {@link DEFAULT_PUBLIC_BASE_URL} */\n publicBaseUrl?: string\n /** 可注入 fetch(测试或自定义环境) */\n fetchImpl?: typeof fetch\n}\n\nexport class GStableHttp {\n private readonly baseUrl: string\n private readonly publicBaseUrl: string\n private readonly authHeader: string\n private readonly fetchFn: typeof fetch\n\n constructor(options: GStableHttpOptions) {\n this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/$/, '')\n this.publicBaseUrl = (options.publicBaseUrl ?? DEFAULT_PUBLIC_BASE_URL).replace(/\\/$/, '')\n const key = options.apiKey.trim()\n this.authHeader = key.startsWith('Bearer ') ? key : `Bearer ${key}`\n this.fetchFn = options.fetchImpl ?? globalThis.fetch.bind(globalThis)\n }\n\n private extractEnvelopeData<T>(res: Response, rawText: string, parsed: unknown): T {\n if (!isApiEnvelope(parsed)) {\n throw new GStableError(\n res.status || -1,\n !res.ok\n ? messageForNonJsonBody(res.status, rawText)\n : 'Unexpected response: not a valid API envelope JSON',\n )\n }\n\n const envelope = parsed as ApiEnvelope<T>\n\n if (!res.ok) {\n throw createTypedApiError(\n envelope.code ?? res.status,\n envelope.message || `HTTP ${res.status}`,\n )\n }\n\n if (envelope.code !== 0) {\n throw createTypedApiError(envelope.code, envelope.message ?? 'API error')\n }\n\n return envelope.data\n }\n\n /**\n * 调用公共 API(不携带 Authorization),响应格式与私有 API 相同。\n */\n async requestPublicJson<T>(method: HttpMethod, path: string, body?: unknown): Promise<T> {\n const url = `${this.publicBaseUrl}${path.startsWith('/') ? path : `/${path}`}`\n const headers: Record<string, string> = {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n }\n logOutgoingRequest(method, url, headers)\n\n const init: RequestInit = { method, headers }\n\n if (method === 'POST' && body !== undefined) {\n init.body = JSON.stringify(body)\n }\n\n let res: Response\n try {\n res = await this.fetchFn(url, init)\n } catch (e) {\n const msg = e instanceof Error ? e.message : String(e)\n throw new GStableError(-1, `Network error: ${msg}`)\n }\n\n const rawText = await res.text().catch(() => '')\n\n let parsed: unknown\n try {\n parsed = rawText.length > 0 ? JSON.parse(rawText) : undefined\n } catch {\n throw new GStableError(\n res.status || -1,\n messageForNonJsonBody(res.status, rawText),\n )\n }\n\n return this.extractEnvelopeData<T>(res, rawText, parsed)\n }\n\n async requestJson<T>(method: HttpMethod, path: string, body?: unknown): Promise<T> {\n const url = `${this.baseUrl}${path.startsWith('/') ? path : `/${path}`}`\n const headers: Record<string, string> = {\n Accept: 'application/json',\n Authorization: this.authHeader,\n 'Content-Type': 'application/json',\n }\n logOutgoingRequest(method, url, headers)\n\n const init: RequestInit = { method, headers }\n\n if (method === 'POST' && body !== undefined) {\n init.body = JSON.stringify(body)\n }\n\n let res: Response\n try {\n res = await this.fetchFn(url, init)\n } catch (e) {\n const msg = e instanceof Error ? e.message : String(e)\n throw new GStableError(-1, `Network error: ${msg}`)\n }\n\n const rawText = await res.text().catch(() => '')\n\n let parsed: unknown\n try {\n parsed = rawText.length > 0 ? JSON.parse(rawText) : undefined\n } catch {\n throw new GStableError(\n res.status || -1,\n messageForNonJsonBody(res.status, rawText),\n )\n }\n\n return this.extractEnvelopeData<T>(res, rawText, parsed)\n }\n}\n","import type { GStableHttp } from '../http'\nimport type { Account } from '../types/account'\n\n/**\n * 账户模块 API(只读;创建/修改须在 Dashboard 完成)\n * @see https://docs.gstable.io/zh-Hans/docs/api/core-api/account\n */\nexport class AccountResource {\n constructor(private readonly http: GStableHttp) {}\n\n /** GET /account/detail/:accountId */\n detail(accountId: string): Promise<Account> {\n const id = encodeURIComponent(accountId)\n return this.http.requestJson<Account>('GET', `/account/detail/${id}`)\n }\n\n /** GET /account/list — 全量返回,无分页(单商户最多 20 个账户) */\n list(): Promise<Account[]> {\n return this.http.requestJson<Account[]>('GET', '/account/list')\n }\n}\n","import type { GStableHttp } from '../http'\nimport type { PaymentCapabilities } from '../types/capability'\n\n/**\n * 公共「支付能力」查询(无需鉴权,使用 public Base URL)\n * @see https://docs.gstable.io/zh-Hans/docs/api/overview/supported-assets#%E6%9F%A5%E8%AF%A2%E8%83%BD%E5%8A%9B-api\n */\nexport class CapabilityResource {\n constructor(private readonly http: GStableHttp) {}\n\n /** GET /capabilities/all */\n all(): Promise<PaymentCapabilities> {\n return this.http.requestPublicJson<PaymentCapabilities>('GET', '/capabilities/all')\n }\n}\n","import type { GStableHttp } from '../http'\nimport type {\n CheckoutSession,\n CheckoutSessionListData,\n CreateCheckoutSessionBody,\n SessionDetail,\n} from '../types/checkout-session'\nimport type { OperationSuccess } from '../types/product'\n\n/**\n * 支付会话(Checkout Session)API\n */\nexport class CheckoutSessionResource {\n constructor(private readonly http: GStableHttp) {}\n\n /** POST /session/checkout/create */\n create(body: CreateCheckoutSessionBody): Promise<CheckoutSession> {\n return this.http.requestJson<CheckoutSession>('POST', '/session/checkout/create', body)\n }\n\n /** POST /session/checkout/cancel(仅 initialized 且 signedOnce = 0) */\n cancel(sessionId: string): Promise<OperationSuccess> {\n return this.http.requestJson<OperationSuccess>('POST', '/session/checkout/cancel', {\n sessionId,\n })\n }\n\n /** GET /session/:sessionId — Checkout 与 Payment Link 会话均可查 */\n detail(sessionId: string): Promise<SessionDetail> {\n const id = encodeURIComponent(sessionId)\n return this.http.requestJson<SessionDetail>('GET', `/session/${id}`)\n }\n\n private listByPath(path: string, page: number, size: number): Promise<CheckoutSessionListData> {\n const p = encodeURIComponent(String(page))\n const s = encodeURIComponent(String(size))\n return this.http.requestJson<CheckoutSessionListData>('GET', `${path}/${p}/${s}`)\n }\n\n /** GET /session/list/all/:page/:size */\n listAll(page: number, size: number): Promise<CheckoutSessionListData> {\n return this.listByPath('/session/list/all', page, size)\n }\n\n /** GET /session/list/paid/:page/:size */\n listPaid(page: number, size: number): Promise<CheckoutSessionListData> {\n return this.listByPath('/session/list/paid', page, size)\n }\n\n /** GET /session/list/settling/:page/:size */\n listSettling(page: number, size: number): Promise<CheckoutSessionListData> {\n return this.listByPath('/session/list/settling', page, size)\n }\n\n /** GET /session/list/completed/:page/:size */\n listCompleted(page: number, size: number): Promise<CheckoutSessionListData> {\n return this.listByPath('/session/list/completed', page, size)\n }\n\n /** GET /session/list/cancelled/:page/:size */\n listCancelled(page: number, size: number): Promise<CheckoutSessionListData> {\n return this.listByPath('/session/list/cancelled', page, size)\n }\n\n /** GET /session/list/settlement/pending/:page/:size */\n listSettlementPending(page: number, size: number): Promise<CheckoutSessionListData> {\n return this.listByPath('/session/list/settlement/pending', page, size)\n }\n}\n","import type { GStableHttp } from '../http'\nimport type { OperationSuccess } from '../types/product'\nimport type {\n CreatePaymentLinkBody,\n PaymentLink,\n PaymentLinkListData,\n UpdatePaymentLinkBody,\n} from '../types/payment-link'\n\n/**\n * 支付链接模块 API\n * @see https://docs.gstable.io/zh-Hans/docs/api/core-api/payment-link\n */\nexport class PaymentLinkResource {\n constructor(private readonly http: GStableHttp) {}\n\n /** POST /payment/link/create */\n create(body: CreatePaymentLinkBody): Promise<PaymentLink> {\n return this.http.requestJson<PaymentLink>('POST', '/payment/link/create', body)\n }\n\n /** POST /payment/link/update(全量替换) */\n update(body: UpdatePaymentLinkBody): Promise<OperationSuccess> {\n return this.http.requestJson<OperationSuccess>('POST', '/payment/link/update', body)\n }\n\n /** POST /payment/link/disable */\n disable(linkId: string): Promise<OperationSuccess> {\n return this.http.requestJson<OperationSuccess>('POST', '/payment/link/disable', {\n linkId,\n })\n }\n\n /** POST /payment/link/enable */\n enable(linkId: string): Promise<OperationSuccess> {\n return this.http.requestJson<OperationSuccess>('POST', '/payment/link/enable', {\n linkId,\n })\n }\n\n /** GET /payment/link/:linkId */\n detail(linkId: string): Promise<PaymentLink> {\n const id = encodeURIComponent(linkId)\n return this.http.requestJson<PaymentLink>('GET', `/payment/link/${id}`)\n }\n\n /**\n * GET /payment/link/list/:page/:size\n * @param page 从 1 开始\n */\n list(page: number, size: number): Promise<PaymentLinkListData> {\n const p = encodeURIComponent(String(page))\n const s = encodeURIComponent(String(size))\n return this.http.requestJson<PaymentLinkListData>(\n 'GET',\n `/payment/link/list/${p}/${s}`,\n )\n }\n}\n","import { rewriteProductBusinessError } from '../errors/product'\nimport type { GStableHttp } from '../http'\nimport type {\n CreateProductBody,\n OperationSuccess,\n Product,\n ProductListByIdsBody,\n ProductListData,\n UpdateProductBody,\n} from '../types/product'\n\n/**\n * 商品模块 API\n * @see https://docs.gstable.io/zh-Hans/docs/api/core-api/product\n *\n * 商品业务错误码 100301–100306 会抛出 `GStableProductError`(仍为 `GStableError` 子类),\n * @see https://docs.gstable.io/zh-Hans/docs/api/overview/errors#%E5%95%86%E5%93%81%E7%AE%A1%E7%90%86-1003xx\n */\nexport class ProductResource {\n constructor(private readonly http: GStableHttp) {}\n\n private async invoke<T>(operation: () => Promise<T>): Promise<T> {\n try {\n return await operation()\n } catch (e) {\n throw rewriteProductBusinessError(e)\n }\n }\n\n /** POST /product/create */\n create(body: CreateProductBody): Promise<Product> {\n return this.invoke(() =>\n this.http.requestJson<Product>('POST', '/product/create', body),\n )\n }\n\n /** POST /product/update(全量替换) */\n update(body: UpdateProductBody): Promise<OperationSuccess> {\n return this.invoke(() =>\n this.http.requestJson<OperationSuccess>('POST', '/product/update', body),\n )\n }\n\n /**\n * GET /product/list/:page/:size\n * @param page 从 1 开始\n * @param size 每页条数,最大 100\n */\n list(page: number, size: number): Promise<ProductListData> {\n const p = encodeURIComponent(String(page))\n const s = encodeURIComponent(String(size))\n return this.invoke(() =>\n this.http.requestJson<ProductListData>('GET', `/product/list/${p}/${s}`),\n )\n }\n\n /** POST /product/list/by/ids — 不存在的 id 会被静默忽略 */\n listByIds(body: ProductListByIdsBody): Promise<Product[]> {\n return this.invoke(() =>\n this.http.requestJson<Product[]>('POST', '/product/list/by/ids', body),\n )\n }\n\n /** POST /product/archive */\n archive(productId: string): Promise<OperationSuccess> {\n return this.invoke(() =>\n this.http.requestJson<OperationSuccess>('POST', '/product/archive', {\n productId,\n }),\n )\n }\n\n /** POST /product/unarchive */\n unarchive(productId: string): Promise<OperationSuccess> {\n return this.invoke(() =>\n this.http.requestJson<OperationSuccess>('POST', '/product/unarchive', {\n productId,\n }),\n )\n }\n\n /** POST /product/remove — 仅未被任何 Payment Link 引用过的商品可删 */\n remove(productId: string): Promise<OperationSuccess> {\n return this.invoke(() =>\n this.http.requestJson<OperationSuccess>('POST', '/product/remove', {\n productId,\n }),\n )\n }\n}\n","import type { GStableHttp } from '../http'\nimport type { OperationSuccess } from '../types/product'\nimport type {\n CreateWebhookBody,\n UpdateWebhookBody,\n Webhook,\n WebhookListData,\n} from '../types/webhook'\n\n/**\n * Webhook 管理 API(单账户最多 10 个端点)\n */\nexport class WebhookResource {\n constructor(private readonly http: GStableHttp) {}\n\n /** POST /webhook/create */\n create(body: CreateWebhookBody): Promise<Webhook> {\n return this.http.requestJson<Webhook>('POST', '/webhook/create', body)\n }\n\n /** POST /webhook/update(全量替换) */\n update(body: UpdateWebhookBody): Promise<OperationSuccess> {\n return this.http.requestJson<OperationSuccess>('POST', '/webhook/update', body)\n }\n\n /** GET /webhook/list — 全量,无分页 */\n list(): Promise<WebhookListData> {\n return this.http.requestJson<WebhookListData>('GET', '/webhook/list')\n }\n\n /** GET /webhook/detail/:webhookId */\n detail(webhookId: string): Promise<Webhook> {\n const id = encodeURIComponent(webhookId)\n return this.http.requestJson<Webhook>('GET', `/webhook/detail/${id}`)\n }\n\n /** POST /webhook/disable */\n disable(webhookId: string): Promise<OperationSuccess> {\n return this.http.requestJson<OperationSuccess>('POST', '/webhook/disable', {\n webhookId,\n })\n }\n\n /** POST /webhook/enable(含从 paused 恢复) */\n enable(webhookId: string): Promise<OperationSuccess> {\n return this.http.requestJson<OperationSuccess>('POST', '/webhook/enable', {\n webhookId,\n })\n }\n\n /** POST /webhook/key/refresh — 旧 key 立即失效 */\n refreshKey(webhookId: string): Promise<OperationSuccess> {\n return this.http.requestJson<OperationSuccess>('POST', '/webhook/key/refresh', {\n webhookId,\n })\n }\n\n /** POST /webhook/remove */\n remove(webhookId: string): Promise<OperationSuccess> {\n return this.http.requestJson<OperationSuccess>('POST', '/webhook/remove', {\n webhookId,\n })\n }\n}\n","import { GStableHttp, type GStableHttpOptions } from './http'\nimport { AccountResource } from './resources/account'\n// import { AiPaymentResource } from './resources/ai-payment'\nimport { CapabilityResource } from './resources/capability'\nimport { CheckoutSessionResource } from './resources/checkout-session'\nimport { PaymentLinkResource } from './resources/payment-link'\nimport { ProductResource } from './resources/product'\nimport { WebhookResource } from './resources/webhook'\n\nexport interface GStableClientOptions extends GStableHttpOptions {}\n\nexport class GStableClient {\n private readonly http: GStableHttp\n\n readonly product: ProductResource\n\n readonly account: AccountResource\n\n readonly paymentLink: PaymentLinkResource\n\n readonly capability: CapabilityResource\n\n readonly checkoutSession: CheckoutSessionResource\n\n /** AI Payment Protocol(创建会话 / 查询 / 准备支付) */\n // readonly aiPayment: AiPaymentResource\n\n readonly webhook: WebhookResource\n\n constructor(options: GStableClientOptions) {\n if (!options.apiKey?.trim()) {\n throw new Error('GStableClient: apiKey is required')\n }\n this.http = new GStableHttp(options)\n this.product = new ProductResource(this.http)\n this.account = new AccountResource(this.http)\n this.paymentLink = new PaymentLinkResource(this.http)\n this.capability = new CapabilityResource(this.http)\n this.checkoutSession = new CheckoutSessionResource(this.http)\n // this.aiPayment = new AiPaymentResource(this.http)\n this.webhook = new WebhookResource(this.http)\n }\n}\n","import type { GStableHttp } from '../http'\nimport type {\n AiPaymentSession,\n CreatePaymentSessionBody,\n CreatePaymentSessionResult,\n PreparePaymentBody,\n PreparePaymentResult,\n} from '../types/ai-payment'\n\n/**\n * AI Payment Protocol(EIP-712 签名由调用方生成后传入)\n * @see https://docs.gstable.io/zh-Hans/docs/api/ai-payment/create-session\n * @see https://docs.gstable.io/zh-Hans/docs/api/ai-payment/get-session\n * @see https://docs.gstable.io/zh-Hans/docs/api/ai-payment/prepare-payment\n */\nexport class AiPaymentResource {\n constructor(private readonly http: GStableHttp) {}\n\n /** POST /payment/session/create */\n createSession(body: CreatePaymentSessionBody): Promise<CreatePaymentSessionResult> {\n return this.http.requestJson<CreatePaymentSessionResult>(\n 'POST',\n '/payment/session/create',\n body,\n )\n }\n\n /**\n * GET /session/:sessionId\n * 与核心 `checkoutSession.detail` 同路径;本方法按 AI 文档将 data 解析为含 `aiView` 的扁平结构。\n */\n getSession(sessionId: string): Promise<AiPaymentSession> {\n const id = encodeURIComponent(sessionId)\n return this.http.requestJson<AiPaymentSession>('GET', `/session/${id}`)\n }\n\n /** POST /payment/prepare */\n preparePayment(body: PreparePaymentBody): Promise<PreparePaymentResult> {\n return this.http.requestJson<PreparePaymentResult>('POST', '/payment/prepare', body)\n }\n}\n"]}
|