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.cjs
ADDED
|
@@ -0,0 +1,604 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/errors.ts
|
|
4
|
+
var GStableError = class extends Error {
|
|
5
|
+
code;
|
|
6
|
+
constructor(code, message) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = "GStableError";
|
|
9
|
+
this.code = code;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
function isGStableError(e) {
|
|
13
|
+
return e instanceof GStableError;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// src/errors/common-platform.ts
|
|
17
|
+
var CommonErrorCodes = {
|
|
18
|
+
INVALID_FIELD_FORMAT: 400101,
|
|
19
|
+
UNSUPPORTED_CURRENCY: 400201,
|
|
20
|
+
UNSUPPORTED_CHANNEL: 400202,
|
|
21
|
+
SETTLEMENT_CAPABILITIES_NOT_FOUND: 400203,
|
|
22
|
+
STAT_NOT_FOUND: 400301
|
|
23
|
+
};
|
|
24
|
+
var COMMON_ERROR_CODE_SET = new Set(
|
|
25
|
+
Object.values(CommonErrorCodes)
|
|
26
|
+
);
|
|
27
|
+
var CommonErrorMessages = {
|
|
28
|
+
[CommonErrorCodes.INVALID_FIELD_FORMAT]: "Invalid field format",
|
|
29
|
+
[CommonErrorCodes.UNSUPPORTED_CURRENCY]: "Unsupported currency",
|
|
30
|
+
[CommonErrorCodes.UNSUPPORTED_CHANNEL]: "Unsupported channel",
|
|
31
|
+
[CommonErrorCodes.SETTLEMENT_CAPABILITIES_NOT_FOUND]: "Settlement capabilities not found",
|
|
32
|
+
[CommonErrorCodes.STAT_NOT_FOUND]: "Stat not found"
|
|
33
|
+
};
|
|
34
|
+
function isCommonErrorCode(code) {
|
|
35
|
+
return COMMON_ERROR_CODE_SET.has(code);
|
|
36
|
+
}
|
|
37
|
+
var GStableCommonError = class extends GStableError {
|
|
38
|
+
commonErrorCode;
|
|
39
|
+
constructor(code, message) {
|
|
40
|
+
super(code, message);
|
|
41
|
+
this.name = "GStableCommonError";
|
|
42
|
+
this.commonErrorCode = code;
|
|
43
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
function isGStableCommonError(e) {
|
|
47
|
+
return e instanceof GStableCommonError;
|
|
48
|
+
}
|
|
49
|
+
var PlatformErrorCodes = {
|
|
50
|
+
TOO_MANY_REQUESTS: 900101,
|
|
51
|
+
FAILED_TO_CREATE_RECORD: 900201,
|
|
52
|
+
FAILED_TO_UPDATE_RECORD: 900202,
|
|
53
|
+
FAILED_TO_QUERY_RECORD: 900203,
|
|
54
|
+
IMAGE_PROCESSING_FAILED: 900301,
|
|
55
|
+
INTERNAL_SYSTEM_ERROR: 999999
|
|
56
|
+
};
|
|
57
|
+
var PLATFORM_ERROR_CODE_SET = new Set(
|
|
58
|
+
Object.values(PlatformErrorCodes)
|
|
59
|
+
);
|
|
60
|
+
var PlatformErrorMessages = {
|
|
61
|
+
[PlatformErrorCodes.TOO_MANY_REQUESTS]: "Too many requests",
|
|
62
|
+
[PlatformErrorCodes.FAILED_TO_CREATE_RECORD]: "Failed to create record",
|
|
63
|
+
[PlatformErrorCodes.FAILED_TO_UPDATE_RECORD]: "Failed to update record",
|
|
64
|
+
[PlatformErrorCodes.FAILED_TO_QUERY_RECORD]: "Failed to query record",
|
|
65
|
+
[PlatformErrorCodes.IMAGE_PROCESSING_FAILED]: "Image processing failed",
|
|
66
|
+
[PlatformErrorCodes.INTERNAL_SYSTEM_ERROR]: "Internal system error"
|
|
67
|
+
};
|
|
68
|
+
function isPlatformErrorCode(code) {
|
|
69
|
+
return PLATFORM_ERROR_CODE_SET.has(code);
|
|
70
|
+
}
|
|
71
|
+
var GStablePlatformError = class extends GStableError {
|
|
72
|
+
platformErrorCode;
|
|
73
|
+
constructor(code, message) {
|
|
74
|
+
super(code, message);
|
|
75
|
+
this.name = "GStablePlatformError";
|
|
76
|
+
this.platformErrorCode = code;
|
|
77
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
function isGStablePlatformError(e) {
|
|
81
|
+
return e instanceof GStablePlatformError;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// src/errors/product.ts
|
|
85
|
+
var ProductErrorCodes = {
|
|
86
|
+
/** 指定的 Product ID 不存在 */
|
|
87
|
+
NOT_FOUND: 100301,
|
|
88
|
+
/** 批量操作中部分商品 ID 不存在 */
|
|
89
|
+
PARTIAL_MISSING: 100302,
|
|
90
|
+
/** 批量操作中部分商品状态不可用 */
|
|
91
|
+
PARTIALLY_UNAVAILABLE: 100303,
|
|
92
|
+
/** 商品未处于激活状态,无法用于创建链接或会话 */
|
|
93
|
+
NOT_ACTIVE: 100304,
|
|
94
|
+
/** 商品已被关联使用,无法执行某些特定修改 */
|
|
95
|
+
HAS_BEEN_USED: 100305,
|
|
96
|
+
/** 商品已被逻辑删除 */
|
|
97
|
+
HAS_BEEN_REMOVED: 100306
|
|
98
|
+
};
|
|
99
|
+
var PRODUCT_ERROR_CODE_SET = new Set(
|
|
100
|
+
Object.values(ProductErrorCodes)
|
|
101
|
+
);
|
|
102
|
+
var ProductErrorMessages = {
|
|
103
|
+
[ProductErrorCodes.NOT_FOUND]: "Product not found",
|
|
104
|
+
[ProductErrorCodes.PARTIAL_MISSING]: "Product partial missing",
|
|
105
|
+
[ProductErrorCodes.PARTIALLY_UNAVAILABLE]: "Product partially unavailable",
|
|
106
|
+
[ProductErrorCodes.NOT_ACTIVE]: "Product is not active",
|
|
107
|
+
[ProductErrorCodes.HAS_BEEN_USED]: "Product has been used",
|
|
108
|
+
[ProductErrorCodes.HAS_BEEN_REMOVED]: "Product has been removed"
|
|
109
|
+
};
|
|
110
|
+
function isProductErrorCode(code) {
|
|
111
|
+
return PRODUCT_ERROR_CODE_SET.has(code);
|
|
112
|
+
}
|
|
113
|
+
var GStableProductError = class extends GStableError {
|
|
114
|
+
productErrorCode;
|
|
115
|
+
constructor(code, message) {
|
|
116
|
+
super(code, message);
|
|
117
|
+
this.name = "GStableProductError";
|
|
118
|
+
this.productErrorCode = code;
|
|
119
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
function isGStableProductError(e) {
|
|
123
|
+
return e instanceof GStableProductError;
|
|
124
|
+
}
|
|
125
|
+
function rewriteProductBusinessError(error) {
|
|
126
|
+
if (error instanceof GStableProductError) {
|
|
127
|
+
return error;
|
|
128
|
+
}
|
|
129
|
+
if (error instanceof GStableError && isProductErrorCode(error.code)) {
|
|
130
|
+
return new GStableProductError(error.code, error.message);
|
|
131
|
+
}
|
|
132
|
+
return error;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// src/errors/api-error.ts
|
|
136
|
+
function createTypedApiError(code, message) {
|
|
137
|
+
if (isProductErrorCode(code)) {
|
|
138
|
+
return new GStableProductError(code, message);
|
|
139
|
+
}
|
|
140
|
+
if (isCommonErrorCode(code)) {
|
|
141
|
+
return new GStableCommonError(code, message);
|
|
142
|
+
}
|
|
143
|
+
if (isPlatformErrorCode(code)) {
|
|
144
|
+
return new GStablePlatformError(code, message);
|
|
145
|
+
}
|
|
146
|
+
return new GStableError(code, message);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// src/http.ts
|
|
150
|
+
var DEFAULT_BASE_URL = "https://api.gstable.io/api/v1/";
|
|
151
|
+
var DEFAULT_PUBLIC_BASE_URL = "https://api.gstable.io/public/api/v1";
|
|
152
|
+
function isApiEnvelope(v) {
|
|
153
|
+
return v !== null && typeof v === "object" && "code" in v && typeof v.code === "number";
|
|
154
|
+
}
|
|
155
|
+
function messageForNonJsonBody(status, bodyPreview) {
|
|
156
|
+
const trimmed = bodyPreview.trim().slice(0, 280).replace(/\s+/g, " ");
|
|
157
|
+
if (status === 403) {
|
|
158
|
+
return [
|
|
159
|
+
"HTTP 403: The server rejected the request and the response body is not typical API JSON.",
|
|
160
|
+
"Common causes: invalid API key or insufficient permissions, WAF blocking, or base URL mismatch with https://docs.gstable.io.",
|
|
161
|
+
"Verify GSTABLE_API_KEY and endpoint URLs; retry from a server or trusted network.",
|
|
162
|
+
trimmed ? `(response snippet) ${trimmed}` : ""
|
|
163
|
+
].filter(Boolean).join(" ");
|
|
164
|
+
}
|
|
165
|
+
if (status === 401) {
|
|
166
|
+
return `HTTP 401: Authentication failed. Check the Authorization header / API key.${trimmed ? ` ${trimmed}` : ""}`;
|
|
167
|
+
}
|
|
168
|
+
return `HTTP ${status}${trimmed ? `: ${trimmed}` : " (response is not JSON or is empty)"}`;
|
|
169
|
+
}
|
|
170
|
+
function isGStableHttpDebug() {
|
|
171
|
+
if (typeof process === "undefined" || process.env == null) return false;
|
|
172
|
+
const v = process.env.GSTABLE_DEBUG;
|
|
173
|
+
return v === "1" || v === "true";
|
|
174
|
+
}
|
|
175
|
+
function logOutgoingRequest(method, url, headers) {
|
|
176
|
+
if (!isGStableHttpDebug()) return;
|
|
177
|
+
console.error("[GStable SDK debug]", JSON.stringify({ method, url, headers }, null, 2));
|
|
178
|
+
}
|
|
179
|
+
var GStableHttp = class {
|
|
180
|
+
baseUrl;
|
|
181
|
+
publicBaseUrl;
|
|
182
|
+
authHeader;
|
|
183
|
+
fetchFn;
|
|
184
|
+
constructor(options) {
|
|
185
|
+
this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/$/, "");
|
|
186
|
+
this.publicBaseUrl = (options.publicBaseUrl ?? DEFAULT_PUBLIC_BASE_URL).replace(/\/$/, "");
|
|
187
|
+
const key = options.apiKey.trim();
|
|
188
|
+
this.authHeader = key.startsWith("Bearer ") ? key : `Bearer ${key}`;
|
|
189
|
+
this.fetchFn = options.fetchImpl ?? globalThis.fetch.bind(globalThis);
|
|
190
|
+
}
|
|
191
|
+
extractEnvelopeData(res, rawText, parsed) {
|
|
192
|
+
if (!isApiEnvelope(parsed)) {
|
|
193
|
+
throw new GStableError(
|
|
194
|
+
res.status || -1,
|
|
195
|
+
!res.ok ? messageForNonJsonBody(res.status, rawText) : "Unexpected response: not a valid API envelope JSON"
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
const envelope = parsed;
|
|
199
|
+
if (!res.ok) {
|
|
200
|
+
throw createTypedApiError(
|
|
201
|
+
envelope.code ?? res.status,
|
|
202
|
+
envelope.message || `HTTP ${res.status}`
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
if (envelope.code !== 0) {
|
|
206
|
+
throw createTypedApiError(envelope.code, envelope.message ?? "API error");
|
|
207
|
+
}
|
|
208
|
+
return envelope.data;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* 调用公共 API(不携带 Authorization),响应格式与私有 API 相同。
|
|
212
|
+
*/
|
|
213
|
+
async requestPublicJson(method, path, body) {
|
|
214
|
+
const url = `${this.publicBaseUrl}${path.startsWith("/") ? path : `/${path}`}`;
|
|
215
|
+
const headers = {
|
|
216
|
+
Accept: "application/json",
|
|
217
|
+
"Content-Type": "application/json"
|
|
218
|
+
};
|
|
219
|
+
logOutgoingRequest(method, url, headers);
|
|
220
|
+
const init = { method, headers };
|
|
221
|
+
if (method === "POST" && body !== void 0) {
|
|
222
|
+
init.body = JSON.stringify(body);
|
|
223
|
+
}
|
|
224
|
+
let res;
|
|
225
|
+
try {
|
|
226
|
+
res = await this.fetchFn(url, init);
|
|
227
|
+
} catch (e) {
|
|
228
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
229
|
+
throw new GStableError(-1, `Network error: ${msg}`);
|
|
230
|
+
}
|
|
231
|
+
const rawText = await res.text().catch(() => "");
|
|
232
|
+
let parsed;
|
|
233
|
+
try {
|
|
234
|
+
parsed = rawText.length > 0 ? JSON.parse(rawText) : void 0;
|
|
235
|
+
} catch {
|
|
236
|
+
throw new GStableError(
|
|
237
|
+
res.status || -1,
|
|
238
|
+
messageForNonJsonBody(res.status, rawText)
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
return this.extractEnvelopeData(res, rawText, parsed);
|
|
242
|
+
}
|
|
243
|
+
async requestJson(method, path, body) {
|
|
244
|
+
const url = `${this.baseUrl}${path.startsWith("/") ? path : `/${path}`}`;
|
|
245
|
+
const headers = {
|
|
246
|
+
Accept: "application/json",
|
|
247
|
+
Authorization: this.authHeader,
|
|
248
|
+
"Content-Type": "application/json"
|
|
249
|
+
};
|
|
250
|
+
logOutgoingRequest(method, url, headers);
|
|
251
|
+
const init = { method, headers };
|
|
252
|
+
if (method === "POST" && body !== void 0) {
|
|
253
|
+
init.body = JSON.stringify(body);
|
|
254
|
+
}
|
|
255
|
+
let res;
|
|
256
|
+
try {
|
|
257
|
+
res = await this.fetchFn(url, init);
|
|
258
|
+
} catch (e) {
|
|
259
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
260
|
+
throw new GStableError(-1, `Network error: ${msg}`);
|
|
261
|
+
}
|
|
262
|
+
const rawText = await res.text().catch(() => "");
|
|
263
|
+
let parsed;
|
|
264
|
+
try {
|
|
265
|
+
parsed = rawText.length > 0 ? JSON.parse(rawText) : void 0;
|
|
266
|
+
} catch {
|
|
267
|
+
throw new GStableError(
|
|
268
|
+
res.status || -1,
|
|
269
|
+
messageForNonJsonBody(res.status, rawText)
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
return this.extractEnvelopeData(res, rawText, parsed);
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
// src/resources/account.ts
|
|
277
|
+
var AccountResource = class {
|
|
278
|
+
constructor(http) {
|
|
279
|
+
this.http = http;
|
|
280
|
+
}
|
|
281
|
+
http;
|
|
282
|
+
/** GET /account/detail/:accountId */
|
|
283
|
+
detail(accountId) {
|
|
284
|
+
const id = encodeURIComponent(accountId);
|
|
285
|
+
return this.http.requestJson("GET", `/account/detail/${id}`);
|
|
286
|
+
}
|
|
287
|
+
/** GET /account/list — 全量返回,无分页(单商户最多 20 个账户) */
|
|
288
|
+
list() {
|
|
289
|
+
return this.http.requestJson("GET", "/account/list");
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
// src/resources/capability.ts
|
|
294
|
+
var CapabilityResource = class {
|
|
295
|
+
constructor(http) {
|
|
296
|
+
this.http = http;
|
|
297
|
+
}
|
|
298
|
+
http;
|
|
299
|
+
/** GET /capabilities/all */
|
|
300
|
+
all() {
|
|
301
|
+
return this.http.requestPublicJson("GET", "/capabilities/all");
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
// src/resources/checkout-session.ts
|
|
306
|
+
var CheckoutSessionResource = class {
|
|
307
|
+
constructor(http) {
|
|
308
|
+
this.http = http;
|
|
309
|
+
}
|
|
310
|
+
http;
|
|
311
|
+
/** POST /session/checkout/create */
|
|
312
|
+
create(body) {
|
|
313
|
+
return this.http.requestJson("POST", "/session/checkout/create", body);
|
|
314
|
+
}
|
|
315
|
+
/** POST /session/checkout/cancel(仅 initialized 且 signedOnce = 0) */
|
|
316
|
+
cancel(sessionId) {
|
|
317
|
+
return this.http.requestJson("POST", "/session/checkout/cancel", {
|
|
318
|
+
sessionId
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
/** GET /session/:sessionId — Checkout 与 Payment Link 会话均可查 */
|
|
322
|
+
detail(sessionId) {
|
|
323
|
+
const id = encodeURIComponent(sessionId);
|
|
324
|
+
return this.http.requestJson("GET", `/session/${id}`);
|
|
325
|
+
}
|
|
326
|
+
listByPath(path, page, size) {
|
|
327
|
+
const p = encodeURIComponent(String(page));
|
|
328
|
+
const s = encodeURIComponent(String(size));
|
|
329
|
+
return this.http.requestJson("GET", `${path}/${p}/${s}`);
|
|
330
|
+
}
|
|
331
|
+
/** GET /session/list/all/:page/:size */
|
|
332
|
+
listAll(page, size) {
|
|
333
|
+
return this.listByPath("/session/list/all", page, size);
|
|
334
|
+
}
|
|
335
|
+
/** GET /session/list/paid/:page/:size */
|
|
336
|
+
listPaid(page, size) {
|
|
337
|
+
return this.listByPath("/session/list/paid", page, size);
|
|
338
|
+
}
|
|
339
|
+
/** GET /session/list/settling/:page/:size */
|
|
340
|
+
listSettling(page, size) {
|
|
341
|
+
return this.listByPath("/session/list/settling", page, size);
|
|
342
|
+
}
|
|
343
|
+
/** GET /session/list/completed/:page/:size */
|
|
344
|
+
listCompleted(page, size) {
|
|
345
|
+
return this.listByPath("/session/list/completed", page, size);
|
|
346
|
+
}
|
|
347
|
+
/** GET /session/list/cancelled/:page/:size */
|
|
348
|
+
listCancelled(page, size) {
|
|
349
|
+
return this.listByPath("/session/list/cancelled", page, size);
|
|
350
|
+
}
|
|
351
|
+
/** GET /session/list/settlement/pending/:page/:size */
|
|
352
|
+
listSettlementPending(page, size) {
|
|
353
|
+
return this.listByPath("/session/list/settlement/pending", page, size);
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
|
|
357
|
+
// src/resources/payment-link.ts
|
|
358
|
+
var PaymentLinkResource = class {
|
|
359
|
+
constructor(http) {
|
|
360
|
+
this.http = http;
|
|
361
|
+
}
|
|
362
|
+
http;
|
|
363
|
+
/** POST /payment/link/create */
|
|
364
|
+
create(body) {
|
|
365
|
+
return this.http.requestJson("POST", "/payment/link/create", body);
|
|
366
|
+
}
|
|
367
|
+
/** POST /payment/link/update(全量替换) */
|
|
368
|
+
update(body) {
|
|
369
|
+
return this.http.requestJson("POST", "/payment/link/update", body);
|
|
370
|
+
}
|
|
371
|
+
/** POST /payment/link/disable */
|
|
372
|
+
disable(linkId) {
|
|
373
|
+
return this.http.requestJson("POST", "/payment/link/disable", {
|
|
374
|
+
linkId
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
/** POST /payment/link/enable */
|
|
378
|
+
enable(linkId) {
|
|
379
|
+
return this.http.requestJson("POST", "/payment/link/enable", {
|
|
380
|
+
linkId
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
/** GET /payment/link/:linkId */
|
|
384
|
+
detail(linkId) {
|
|
385
|
+
const id = encodeURIComponent(linkId);
|
|
386
|
+
return this.http.requestJson("GET", `/payment/link/${id}`);
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* GET /payment/link/list/:page/:size
|
|
390
|
+
* @param page 从 1 开始
|
|
391
|
+
*/
|
|
392
|
+
list(page, size) {
|
|
393
|
+
const p = encodeURIComponent(String(page));
|
|
394
|
+
const s = encodeURIComponent(String(size));
|
|
395
|
+
return this.http.requestJson(
|
|
396
|
+
"GET",
|
|
397
|
+
`/payment/link/list/${p}/${s}`
|
|
398
|
+
);
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
|
|
402
|
+
// src/resources/product.ts
|
|
403
|
+
var ProductResource = class {
|
|
404
|
+
constructor(http) {
|
|
405
|
+
this.http = http;
|
|
406
|
+
}
|
|
407
|
+
http;
|
|
408
|
+
async invoke(operation) {
|
|
409
|
+
try {
|
|
410
|
+
return await operation();
|
|
411
|
+
} catch (e) {
|
|
412
|
+
throw rewriteProductBusinessError(e);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
/** POST /product/create */
|
|
416
|
+
create(body) {
|
|
417
|
+
return this.invoke(
|
|
418
|
+
() => this.http.requestJson("POST", "/product/create", body)
|
|
419
|
+
);
|
|
420
|
+
}
|
|
421
|
+
/** POST /product/update(全量替换) */
|
|
422
|
+
update(body) {
|
|
423
|
+
return this.invoke(
|
|
424
|
+
() => this.http.requestJson("POST", "/product/update", body)
|
|
425
|
+
);
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* GET /product/list/:page/:size
|
|
429
|
+
* @param page 从 1 开始
|
|
430
|
+
* @param size 每页条数,最大 100
|
|
431
|
+
*/
|
|
432
|
+
list(page, size) {
|
|
433
|
+
const p = encodeURIComponent(String(page));
|
|
434
|
+
const s = encodeURIComponent(String(size));
|
|
435
|
+
return this.invoke(
|
|
436
|
+
() => this.http.requestJson("GET", `/product/list/${p}/${s}`)
|
|
437
|
+
);
|
|
438
|
+
}
|
|
439
|
+
/** POST /product/list/by/ids — 不存在的 id 会被静默忽略 */
|
|
440
|
+
listByIds(body) {
|
|
441
|
+
return this.invoke(
|
|
442
|
+
() => this.http.requestJson("POST", "/product/list/by/ids", body)
|
|
443
|
+
);
|
|
444
|
+
}
|
|
445
|
+
/** POST /product/archive */
|
|
446
|
+
archive(productId) {
|
|
447
|
+
return this.invoke(
|
|
448
|
+
() => this.http.requestJson("POST", "/product/archive", {
|
|
449
|
+
productId
|
|
450
|
+
})
|
|
451
|
+
);
|
|
452
|
+
}
|
|
453
|
+
/** POST /product/unarchive */
|
|
454
|
+
unarchive(productId) {
|
|
455
|
+
return this.invoke(
|
|
456
|
+
() => this.http.requestJson("POST", "/product/unarchive", {
|
|
457
|
+
productId
|
|
458
|
+
})
|
|
459
|
+
);
|
|
460
|
+
}
|
|
461
|
+
/** POST /product/remove — 仅未被任何 Payment Link 引用过的商品可删 */
|
|
462
|
+
remove(productId) {
|
|
463
|
+
return this.invoke(
|
|
464
|
+
() => this.http.requestJson("POST", "/product/remove", {
|
|
465
|
+
productId
|
|
466
|
+
})
|
|
467
|
+
);
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
|
|
471
|
+
// src/resources/webhook.ts
|
|
472
|
+
var WebhookResource = class {
|
|
473
|
+
constructor(http) {
|
|
474
|
+
this.http = http;
|
|
475
|
+
}
|
|
476
|
+
http;
|
|
477
|
+
/** POST /webhook/create */
|
|
478
|
+
create(body) {
|
|
479
|
+
return this.http.requestJson("POST", "/webhook/create", body);
|
|
480
|
+
}
|
|
481
|
+
/** POST /webhook/update(全量替换) */
|
|
482
|
+
update(body) {
|
|
483
|
+
return this.http.requestJson("POST", "/webhook/update", body);
|
|
484
|
+
}
|
|
485
|
+
/** GET /webhook/list — 全量,无分页 */
|
|
486
|
+
list() {
|
|
487
|
+
return this.http.requestJson("GET", "/webhook/list");
|
|
488
|
+
}
|
|
489
|
+
/** GET /webhook/detail/:webhookId */
|
|
490
|
+
detail(webhookId) {
|
|
491
|
+
const id = encodeURIComponent(webhookId);
|
|
492
|
+
return this.http.requestJson("GET", `/webhook/detail/${id}`);
|
|
493
|
+
}
|
|
494
|
+
/** POST /webhook/disable */
|
|
495
|
+
disable(webhookId) {
|
|
496
|
+
return this.http.requestJson("POST", "/webhook/disable", {
|
|
497
|
+
webhookId
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
/** POST /webhook/enable(含从 paused 恢复) */
|
|
501
|
+
enable(webhookId) {
|
|
502
|
+
return this.http.requestJson("POST", "/webhook/enable", {
|
|
503
|
+
webhookId
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
/** POST /webhook/key/refresh — 旧 key 立即失效 */
|
|
507
|
+
refreshKey(webhookId) {
|
|
508
|
+
return this.http.requestJson("POST", "/webhook/key/refresh", {
|
|
509
|
+
webhookId
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
/** POST /webhook/remove */
|
|
513
|
+
remove(webhookId) {
|
|
514
|
+
return this.http.requestJson("POST", "/webhook/remove", {
|
|
515
|
+
webhookId
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
};
|
|
519
|
+
|
|
520
|
+
// src/client.ts
|
|
521
|
+
var GStableClient = class {
|
|
522
|
+
http;
|
|
523
|
+
product;
|
|
524
|
+
account;
|
|
525
|
+
paymentLink;
|
|
526
|
+
capability;
|
|
527
|
+
checkoutSession;
|
|
528
|
+
/** AI Payment Protocol(创建会话 / 查询 / 准备支付) */
|
|
529
|
+
// readonly aiPayment: AiPaymentResource
|
|
530
|
+
webhook;
|
|
531
|
+
constructor(options) {
|
|
532
|
+
if (!options.apiKey?.trim()) {
|
|
533
|
+
throw new Error("GStableClient: apiKey is required");
|
|
534
|
+
}
|
|
535
|
+
this.http = new GStableHttp(options);
|
|
536
|
+
this.product = new ProductResource(this.http);
|
|
537
|
+
this.account = new AccountResource(this.http);
|
|
538
|
+
this.paymentLink = new PaymentLinkResource(this.http);
|
|
539
|
+
this.capability = new CapabilityResource(this.http);
|
|
540
|
+
this.checkoutSession = new CheckoutSessionResource(this.http);
|
|
541
|
+
this.webhook = new WebhookResource(this.http);
|
|
542
|
+
}
|
|
543
|
+
};
|
|
544
|
+
|
|
545
|
+
// src/resources/ai-payment.ts
|
|
546
|
+
var AiPaymentResource = class {
|
|
547
|
+
constructor(http) {
|
|
548
|
+
this.http = http;
|
|
549
|
+
}
|
|
550
|
+
http;
|
|
551
|
+
/** POST /payment/session/create */
|
|
552
|
+
createSession(body) {
|
|
553
|
+
return this.http.requestJson(
|
|
554
|
+
"POST",
|
|
555
|
+
"/payment/session/create",
|
|
556
|
+
body
|
|
557
|
+
);
|
|
558
|
+
}
|
|
559
|
+
/**
|
|
560
|
+
* GET /session/:sessionId
|
|
561
|
+
* 与核心 `checkoutSession.detail` 同路径;本方法按 AI 文档将 data 解析为含 `aiView` 的扁平结构。
|
|
562
|
+
*/
|
|
563
|
+
getSession(sessionId) {
|
|
564
|
+
const id = encodeURIComponent(sessionId);
|
|
565
|
+
return this.http.requestJson("GET", `/session/${id}`);
|
|
566
|
+
}
|
|
567
|
+
/** POST /payment/prepare */
|
|
568
|
+
preparePayment(body) {
|
|
569
|
+
return this.http.requestJson("POST", "/payment/prepare", body);
|
|
570
|
+
}
|
|
571
|
+
};
|
|
572
|
+
|
|
573
|
+
exports.AccountResource = AccountResource;
|
|
574
|
+
exports.AiPaymentResource = AiPaymentResource;
|
|
575
|
+
exports.CapabilityResource = CapabilityResource;
|
|
576
|
+
exports.CheckoutSessionResource = CheckoutSessionResource;
|
|
577
|
+
exports.CommonErrorCodes = CommonErrorCodes;
|
|
578
|
+
exports.CommonErrorMessages = CommonErrorMessages;
|
|
579
|
+
exports.DEFAULT_BASE_URL = DEFAULT_BASE_URL;
|
|
580
|
+
exports.DEFAULT_PUBLIC_BASE_URL = DEFAULT_PUBLIC_BASE_URL;
|
|
581
|
+
exports.GStableClient = GStableClient;
|
|
582
|
+
exports.GStableCommonError = GStableCommonError;
|
|
583
|
+
exports.GStableError = GStableError;
|
|
584
|
+
exports.GStableHttp = GStableHttp;
|
|
585
|
+
exports.GStablePlatformError = GStablePlatformError;
|
|
586
|
+
exports.GStableProductError = GStableProductError;
|
|
587
|
+
exports.PaymentLinkResource = PaymentLinkResource;
|
|
588
|
+
exports.PlatformErrorCodes = PlatformErrorCodes;
|
|
589
|
+
exports.PlatformErrorMessages = PlatformErrorMessages;
|
|
590
|
+
exports.ProductErrorCodes = ProductErrorCodes;
|
|
591
|
+
exports.ProductErrorMessages = ProductErrorMessages;
|
|
592
|
+
exports.ProductResource = ProductResource;
|
|
593
|
+
exports.WebhookResource = WebhookResource;
|
|
594
|
+
exports.createTypedApiError = createTypedApiError;
|
|
595
|
+
exports.isCommonErrorCode = isCommonErrorCode;
|
|
596
|
+
exports.isGStableCommonError = isGStableCommonError;
|
|
597
|
+
exports.isGStableError = isGStableError;
|
|
598
|
+
exports.isGStablePlatformError = isGStablePlatformError;
|
|
599
|
+
exports.isGStableProductError = isGStableProductError;
|
|
600
|
+
exports.isPlatformErrorCode = isPlatformErrorCode;
|
|
601
|
+
exports.isProductErrorCode = isProductErrorCode;
|
|
602
|
+
exports.rewriteProductBusinessError = rewriteProductBusinessError;
|
|
603
|
+
//# sourceMappingURL=index.cjs.map
|
|
604
|
+
//# sourceMappingURL=index.cjs.map
|