@waffo/pancake-ts 0.1.9 → 0.2.1
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/CHANGELOG.md +22 -5
- package/README.md +98 -12
- package/dist/index.cjs +343 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +259 -15
- package/dist/index.d.ts +259 -15
- package/dist/index.js +343 -6
- package/dist/index.js.map +1 -1
- package/docs/api-reference.md +92 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
// src/http-client.ts
|
|
2
|
-
import { createHash as createHash2 } from "crypto";
|
|
3
|
-
|
|
4
1
|
// src/errors.ts
|
|
5
2
|
var WaffoPancakeError = class extends Error {
|
|
6
3
|
status;
|
|
@@ -14,6 +11,45 @@ var WaffoPancakeError = class extends Error {
|
|
|
14
11
|
}
|
|
15
12
|
};
|
|
16
13
|
|
|
14
|
+
// src/buyer-http-client.ts
|
|
15
|
+
var DEFAULT_BASE_URL = "https://api.waffo.ai";
|
|
16
|
+
var BuyerHttpClient = class {
|
|
17
|
+
token;
|
|
18
|
+
baseUrl;
|
|
19
|
+
_fetch;
|
|
20
|
+
constructor(token, config) {
|
|
21
|
+
this.token = token;
|
|
22
|
+
this.baseUrl = (config.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
23
|
+
this._fetch = config.fetch ?? fetch;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Send a Bearer-authenticated POST request and return the parsed `data` field.
|
|
27
|
+
*
|
|
28
|
+
* @param path - API path
|
|
29
|
+
* @param body - Request body object
|
|
30
|
+
* @returns Parsed `data` field from the response
|
|
31
|
+
* @throws {WaffoPancakeError} When the API returns errors
|
|
32
|
+
*/
|
|
33
|
+
async post(path, body) {
|
|
34
|
+
const response = await this._fetch(`${this.baseUrl}${path}`, {
|
|
35
|
+
method: "POST",
|
|
36
|
+
headers: {
|
|
37
|
+
"Content-Type": "application/json",
|
|
38
|
+
"Authorization": `Bearer ${this.token}`
|
|
39
|
+
},
|
|
40
|
+
body: JSON.stringify(body)
|
|
41
|
+
});
|
|
42
|
+
const result = await response.json();
|
|
43
|
+
if ("errors" in result && result.errors) {
|
|
44
|
+
throw new WaffoPancakeError(response.status, result.errors);
|
|
45
|
+
}
|
|
46
|
+
return result.data;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// src/http-client.ts
|
|
51
|
+
import { createHash as createHash2 } from "crypto";
|
|
52
|
+
|
|
17
53
|
// src/signing.ts
|
|
18
54
|
import { createHash, createPrivateKey, createPublicKey, createSign } from "crypto";
|
|
19
55
|
var PKCS8_HEADER = "-----BEGIN PRIVATE KEY-----";
|
|
@@ -126,7 +162,7 @@ ${bodyHash}`;
|
|
|
126
162
|
}
|
|
127
163
|
|
|
128
164
|
// src/http-client.ts
|
|
129
|
-
var
|
|
165
|
+
var DEFAULT_BASE_URL2 = "https://api.waffo.ai";
|
|
130
166
|
var HttpClient = class {
|
|
131
167
|
merchantId;
|
|
132
168
|
privateKey;
|
|
@@ -135,7 +171,7 @@ var HttpClient = class {
|
|
|
135
171
|
constructor(config) {
|
|
136
172
|
this.merchantId = config.merchantId;
|
|
137
173
|
this.privateKey = normalizePrivateKey(config.privateKey);
|
|
138
|
-
this.baseUrl = (config.baseUrl ??
|
|
174
|
+
this.baseUrl = (config.baseUrl ?? DEFAULT_BASE_URL2).replace(/\/+$/, "");
|
|
139
175
|
this._fetch = config.fetch ?? fetch;
|
|
140
176
|
}
|
|
141
177
|
/**
|
|
@@ -174,6 +210,105 @@ var HttpClient = class {
|
|
|
174
210
|
}
|
|
175
211
|
};
|
|
176
212
|
|
|
213
|
+
// src/validation.ts
|
|
214
|
+
var SHORT_ID_REGEX = /^[A-Z]{2,4}_[A-Za-z0-9]+$/;
|
|
215
|
+
var CURRENCY_CODE_REGEX = /^[A-Z]{3}$/;
|
|
216
|
+
var COUNTRY_CODE_REGEX = /^[A-Z]{2}$/;
|
|
217
|
+
var AMOUNT_STRING_REGEX = /^\d+(\.\d+)?$/;
|
|
218
|
+
var SHORT_ID_LABELS = {
|
|
219
|
+
STO: "Store",
|
|
220
|
+
PROD: "Product",
|
|
221
|
+
ORD: "Order",
|
|
222
|
+
PAY: "Payment",
|
|
223
|
+
REF: "Refund",
|
|
224
|
+
TKT: "Ticket",
|
|
225
|
+
MER: "Merchant"
|
|
226
|
+
};
|
|
227
|
+
function fail(message) {
|
|
228
|
+
throw new WaffoPancakeError(400, [{ message, layer: "sdk" }]);
|
|
229
|
+
}
|
|
230
|
+
function validateRequired(field, value) {
|
|
231
|
+
if (value === void 0 || value === null) {
|
|
232
|
+
fail(`Missing required field: ${field}`);
|
|
233
|
+
}
|
|
234
|
+
if (typeof value === "string" && value.trim() === "") {
|
|
235
|
+
fail(`${field} cannot be empty`);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
function validateShortId(field, value, prefix) {
|
|
239
|
+
validateRequired(field, value);
|
|
240
|
+
const label = SHORT_ID_LABELS[prefix] ?? prefix;
|
|
241
|
+
if (!SHORT_ID_REGEX.test(value)) {
|
|
242
|
+
fail(`Invalid ${field}: expected ${label} Short ID format (${prefix}_xxx), got "${value}"`);
|
|
243
|
+
}
|
|
244
|
+
if (!value.startsWith(`${prefix}_`)) {
|
|
245
|
+
fail(`Invalid ${field}: expected ${prefix}_ prefix (${label}), got "${value.split("_")[0]}_"`);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
function validateCurrencyCode(field, value) {
|
|
249
|
+
validateRequired(field, value);
|
|
250
|
+
if (!CURRENCY_CODE_REGEX.test(value)) {
|
|
251
|
+
fail(`Invalid ${field}: expected 3-letter ISO 4217 currency code (e.g., "USD"), got "${value}"`);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
function validateAmountString(field, value) {
|
|
255
|
+
validateRequired(field, value);
|
|
256
|
+
if (!AMOUNT_STRING_REGEX.test(value)) {
|
|
257
|
+
fail(`Invalid ${field}: expected numeric string in display format (e.g., "9.99", "1000"), got "${value}"`);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
function validateEnum(field, value, allowed) {
|
|
261
|
+
validateRequired(field, value);
|
|
262
|
+
if (!allowed.includes(value)) {
|
|
263
|
+
fail(`Invalid ${field}: expected one of [${allowed.join(", ")}], got "${value}"`);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
function validatePositiveInteger(field, value) {
|
|
267
|
+
if (!Number.isInteger(value) || value <= 0) {
|
|
268
|
+
fail(`Invalid ${field}: expected positive integer, got ${value}`);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
function validateCountryCode(field, value) {
|
|
272
|
+
validateRequired(field, value);
|
|
273
|
+
if (!COUNTRY_CODE_REGEX.test(value)) {
|
|
274
|
+
fail(`Invalid ${field}: expected 2-letter ISO 3166-1 country code (e.g., "US"), got "${value}"`);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
function validatePrices(field, prices) {
|
|
278
|
+
validateRequired(field, prices);
|
|
279
|
+
const entries = Object.entries(prices);
|
|
280
|
+
if (entries.length === 0) {
|
|
281
|
+
fail(`${field} must contain at least one currency`);
|
|
282
|
+
}
|
|
283
|
+
for (const [currency, info] of entries) {
|
|
284
|
+
validateCurrencyCode(`${field}.${currency} (key)`, currency);
|
|
285
|
+
validateAmountString(`${field}.${currency}.amount`, info.amount);
|
|
286
|
+
validateRequired(`${field}.${currency}.taxCategory`, info.taxCategory);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
function validateBillingDetail(detail) {
|
|
290
|
+
validateCountryCode("billingDetail.country", detail.country);
|
|
291
|
+
if (typeof detail.isBusiness !== "boolean") {
|
|
292
|
+
fail(`Invalid billingDetail.isBusiness: expected boolean, got ${typeof detail.isBusiness}`);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
function validateCheckoutCommon(params) {
|
|
296
|
+
validateShortId("storeId", params.storeId, "STO");
|
|
297
|
+
validateShortId("productId", params.productId, "PROD");
|
|
298
|
+
validateEnum("productType", params.productType, ["onetime", "subscription"]);
|
|
299
|
+
validateCurrencyCode("currency", params.currency);
|
|
300
|
+
if (params.priceSnapshot) {
|
|
301
|
+
validateAmountString("priceSnapshot.amount", params.priceSnapshot.amount);
|
|
302
|
+
validateRequired("priceSnapshot.taxCategory", params.priceSnapshot.taxCategory);
|
|
303
|
+
}
|
|
304
|
+
if (params.billingDetail) {
|
|
305
|
+
validateBillingDetail(params.billingDetail);
|
|
306
|
+
}
|
|
307
|
+
if (params.expiresInSeconds !== void 0) {
|
|
308
|
+
validatePositiveInteger("expiresInSeconds", params.expiresInSeconds);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
177
312
|
// src/resources/auth.ts
|
|
178
313
|
var AuthResource = class {
|
|
179
314
|
constructor(http) {
|
|
@@ -192,10 +327,140 @@ var AuthResource = class {
|
|
|
192
327
|
* });
|
|
193
328
|
*/
|
|
194
329
|
async issueSessionToken(params) {
|
|
330
|
+
validateShortId("storeId", params.storeId, "STO");
|
|
331
|
+
validateRequired("buyerIdentity", params.buyerIdentity);
|
|
195
332
|
return this.http.post("/v1/actions/auth/issue-session-token", params);
|
|
196
333
|
}
|
|
197
334
|
};
|
|
198
335
|
|
|
336
|
+
// src/resources/buyer.ts
|
|
337
|
+
var BuyerSession = class {
|
|
338
|
+
constructor(http) {
|
|
339
|
+
this.http = http;
|
|
340
|
+
this.graphql = new BuyerGraphQL(http);
|
|
341
|
+
}
|
|
342
|
+
/** GraphQL query access scoped to the buyer's data. */
|
|
343
|
+
graphql;
|
|
344
|
+
/**
|
|
345
|
+
* Cancel a subscription order.
|
|
346
|
+
*
|
|
347
|
+
* @param params - Order to cancel
|
|
348
|
+
* @returns Order ID and resulting status
|
|
349
|
+
*
|
|
350
|
+
* @example
|
|
351
|
+
* const { orderId, status } = await buyer.cancelSubscription({ orderId: "ORD_xxx" });
|
|
352
|
+
* // status: "canceled" (was pending) or "canceling" (was active)
|
|
353
|
+
*/
|
|
354
|
+
async cancelSubscription(params) {
|
|
355
|
+
validateShortId("orderId", params.orderId, "ORD");
|
|
356
|
+
return this.http.post(
|
|
357
|
+
"/v1/actions/subscription-order/cancel-order",
|
|
358
|
+
params
|
|
359
|
+
);
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Cancel a one-time order (only while payment is still pending).
|
|
363
|
+
*
|
|
364
|
+
* @param params - Order to cancel
|
|
365
|
+
* @returns Order ID and resulting status
|
|
366
|
+
*
|
|
367
|
+
* @example
|
|
368
|
+
* const { orderId, status } = await buyer.cancelOnetimeOrder({ orderId: "ORD_xxx" });
|
|
369
|
+
*/
|
|
370
|
+
async cancelOnetimeOrder(params) {
|
|
371
|
+
validateShortId("orderId", params.orderId, "ORD");
|
|
372
|
+
return this.http.post(
|
|
373
|
+
"/v1/actions/onetime-order/cancel-order",
|
|
374
|
+
params
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Reactivate a subscription that is in `canceling` status.
|
|
379
|
+
*
|
|
380
|
+
* @param params - Order to reactivate
|
|
381
|
+
* @returns Order ID and resulting status
|
|
382
|
+
*
|
|
383
|
+
* @example
|
|
384
|
+
* const { orderId, status } = await buyer.reactivateSubscription({ orderId: "ORD_xxx" });
|
|
385
|
+
* // status: "active"
|
|
386
|
+
*/
|
|
387
|
+
async reactivateSubscription(params) {
|
|
388
|
+
validateShortId("orderId", params.orderId, "ORD");
|
|
389
|
+
return this.http.post(
|
|
390
|
+
"/v1/actions/subscription-order/reactivate-order",
|
|
391
|
+
params
|
|
392
|
+
);
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Submit a refund request for a payment.
|
|
396
|
+
*
|
|
397
|
+
* @param params - Refund ticket details
|
|
398
|
+
* @returns Created refund ticket
|
|
399
|
+
*
|
|
400
|
+
* @example
|
|
401
|
+
* const { ticket } = await buyer.createRefundTicket({
|
|
402
|
+
* paymentId: "PAY_xxx",
|
|
403
|
+
* reason: "Product not as described",
|
|
404
|
+
* requestedAmount: { amount: "29.00", currency: "USD" },
|
|
405
|
+
* });
|
|
406
|
+
*/
|
|
407
|
+
async createRefundTicket(params) {
|
|
408
|
+
validateShortId("paymentId", params.paymentId, "PAY");
|
|
409
|
+
validateRequired("reason", params.reason);
|
|
410
|
+
validateAmountString("requestedAmount.amount", params.requestedAmount.amount);
|
|
411
|
+
validateCurrencyCode("requestedAmount.currency", params.requestedAmount.currency);
|
|
412
|
+
return this.http.post(
|
|
413
|
+
"/v1/actions/refund-ticket/create-ticket",
|
|
414
|
+
params
|
|
415
|
+
);
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Resubmit a previously rejected refund ticket with updated details.
|
|
419
|
+
*
|
|
420
|
+
* @param params - Updated ticket details
|
|
421
|
+
* @returns Updated refund ticket
|
|
422
|
+
*
|
|
423
|
+
* @example
|
|
424
|
+
* const { ticket } = await buyer.resubmitRefundTicket({
|
|
425
|
+
* ticketId: "TKT_xxx",
|
|
426
|
+
* paymentId: "PAY_xxx",
|
|
427
|
+
* reason: "Updated reason with more detail",
|
|
428
|
+
* requestedAmount: { amount: "29.00", currency: "USD" },
|
|
429
|
+
* });
|
|
430
|
+
*/
|
|
431
|
+
async resubmitRefundTicket(params) {
|
|
432
|
+
validateShortId("ticketId", params.ticketId, "TKT");
|
|
433
|
+
validateShortId("paymentId", params.paymentId, "PAY");
|
|
434
|
+
validateRequired("reason", params.reason);
|
|
435
|
+
validateAmountString("requestedAmount.amount", params.requestedAmount.amount);
|
|
436
|
+
validateCurrencyCode("requestedAmount.currency", params.requestedAmount.currency);
|
|
437
|
+
return this.http.post(
|
|
438
|
+
"/v1/actions/refund-ticket/resubmit-ticket",
|
|
439
|
+
params
|
|
440
|
+
);
|
|
441
|
+
}
|
|
442
|
+
};
|
|
443
|
+
var BuyerGraphQL = class {
|
|
444
|
+
constructor(http) {
|
|
445
|
+
this.http = http;
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Execute a GraphQL query scoped to the buyer's data.
|
|
449
|
+
*
|
|
450
|
+
* @param params - GraphQL query and variables
|
|
451
|
+
* @returns GraphQL response
|
|
452
|
+
*
|
|
453
|
+
* @example
|
|
454
|
+
* const result = await buyer.graphql.query({
|
|
455
|
+
* query: `query { orders { id status } }`,
|
|
456
|
+
* });
|
|
457
|
+
*/
|
|
458
|
+
async query(params) {
|
|
459
|
+
validateRequired("query", params.query);
|
|
460
|
+
return this.http.post("/v1/graphql", params);
|
|
461
|
+
}
|
|
462
|
+
};
|
|
463
|
+
|
|
199
464
|
// src/resources/checkout-anonymous.ts
|
|
200
465
|
var CheckoutAnonymousResource = class {
|
|
201
466
|
constructor(http) {
|
|
@@ -217,6 +482,7 @@ var CheckoutAnonymousResource = class {
|
|
|
217
482
|
* // Redirect to result.checkoutUrl
|
|
218
483
|
*/
|
|
219
484
|
async create(params) {
|
|
485
|
+
validateCheckoutCommon(params);
|
|
220
486
|
return this.http.post(
|
|
221
487
|
"/v1/actions/checkout/create-session",
|
|
222
488
|
params
|
|
@@ -252,6 +518,8 @@ var CheckoutAuthenticatedResource = class {
|
|
|
252
518
|
* // Redirect to result.checkoutUrl (includes #token=...)
|
|
253
519
|
*/
|
|
254
520
|
async create(params) {
|
|
521
|
+
validateCheckoutCommon(params);
|
|
522
|
+
validateRequired("buyerIdentity", params.buyerIdentity);
|
|
255
523
|
const { buyerIdentity, buyerEmail, ...sessionFields } = params;
|
|
256
524
|
const [tokenResult, sessionResult] = await Promise.all([
|
|
257
525
|
this.http.post("/v1/actions/auth/issue-session-token", {
|
|
@@ -280,7 +548,7 @@ var CheckoutResource = class {
|
|
|
280
548
|
this.anonymous = new CheckoutAnonymousResource(http);
|
|
281
549
|
this.authenticated = new CheckoutAuthenticatedResource(http);
|
|
282
550
|
}
|
|
283
|
-
/** Anonymous checkout —
|
|
551
|
+
/** Anonymous checkout — no buyer identity, empty form. */
|
|
284
552
|
anonymous;
|
|
285
553
|
/** Authenticated checkout — merchant provides buyer identity. */
|
|
286
554
|
authenticated;
|
|
@@ -332,6 +600,7 @@ var GraphQLResource = class {
|
|
|
332
600
|
* });
|
|
333
601
|
*/
|
|
334
602
|
async query(params) {
|
|
603
|
+
validateRequired("query", params.query);
|
|
335
604
|
return this.http.post("/v1/graphql", params);
|
|
336
605
|
}
|
|
337
606
|
};
|
|
@@ -355,6 +624,9 @@ var OnetimeProductsResource = class {
|
|
|
355
624
|
* });
|
|
356
625
|
*/
|
|
357
626
|
async create(params) {
|
|
627
|
+
validateShortId("storeId", params.storeId, "STO");
|
|
628
|
+
validateRequired("name", params.name);
|
|
629
|
+
validatePrices("prices", params.prices);
|
|
358
630
|
return this.http.post("/v1/actions/onetime-product/create-product", params);
|
|
359
631
|
}
|
|
360
632
|
/**
|
|
@@ -371,6 +643,9 @@ var OnetimeProductsResource = class {
|
|
|
371
643
|
* });
|
|
372
644
|
*/
|
|
373
645
|
async update(params) {
|
|
646
|
+
validateShortId("id", params.id, "PROD");
|
|
647
|
+
validateRequired("name", params.name);
|
|
648
|
+
validatePrices("prices", params.prices);
|
|
374
649
|
return this.http.post("/v1/actions/onetime-product/update-product", params);
|
|
375
650
|
}
|
|
376
651
|
/**
|
|
@@ -383,6 +658,7 @@ var OnetimeProductsResource = class {
|
|
|
383
658
|
* const { product } = await client.onetimeProducts.publish({ id: "PROD_xxx" });
|
|
384
659
|
*/
|
|
385
660
|
async publish(params) {
|
|
661
|
+
validateShortId("id", params.id, "PROD");
|
|
386
662
|
return this.http.post("/v1/actions/onetime-product/publish-product", params);
|
|
387
663
|
}
|
|
388
664
|
/**
|
|
@@ -398,6 +674,8 @@ var OnetimeProductsResource = class {
|
|
|
398
674
|
* });
|
|
399
675
|
*/
|
|
400
676
|
async updateStatus(params) {
|
|
677
|
+
validateShortId("id", params.id, "PROD");
|
|
678
|
+
validateEnum("status", params.status, ["active", "inactive"]);
|
|
401
679
|
return this.http.post("/v1/actions/onetime-product/update-status", params);
|
|
402
680
|
}
|
|
403
681
|
};
|
|
@@ -423,6 +701,7 @@ var OrdersResource = class {
|
|
|
423
701
|
* // status: "canceled" or "canceling"
|
|
424
702
|
*/
|
|
425
703
|
async cancelSubscription(params) {
|
|
704
|
+
validateShortId("orderId", params.orderId, "ORD");
|
|
426
705
|
return this.http.post("/v1/actions/subscription-order/cancel-order", params);
|
|
427
706
|
}
|
|
428
707
|
};
|
|
@@ -446,6 +725,9 @@ var StoreMerchantsResource = class {
|
|
|
446
725
|
* });
|
|
447
726
|
*/
|
|
448
727
|
async add(params) {
|
|
728
|
+
validateShortId("storeId", params.storeId, "STO");
|
|
729
|
+
validateRequired("email", params.email);
|
|
730
|
+
validateEnum("role", params.role, ["admin", "member"]);
|
|
449
731
|
return this.http.post("/v1/actions/store-merchant/add-merchant", params);
|
|
450
732
|
}
|
|
451
733
|
/**
|
|
@@ -461,6 +743,8 @@ var StoreMerchantsResource = class {
|
|
|
461
743
|
* });
|
|
462
744
|
*/
|
|
463
745
|
async remove(params) {
|
|
746
|
+
validateShortId("storeId", params.storeId, "STO");
|
|
747
|
+
validateShortId("merchantId", params.merchantId, "MER");
|
|
464
748
|
return this.http.post("/v1/actions/store-merchant/remove-merchant", params);
|
|
465
749
|
}
|
|
466
750
|
/**
|
|
@@ -477,6 +761,9 @@ var StoreMerchantsResource = class {
|
|
|
477
761
|
* });
|
|
478
762
|
*/
|
|
479
763
|
async updateRole(params) {
|
|
764
|
+
validateShortId("storeId", params.storeId, "STO");
|
|
765
|
+
validateShortId("merchantId", params.merchantId, "MER");
|
|
766
|
+
validateEnum("role", params.role, ["admin", "member"]);
|
|
480
767
|
return this.http.post("/v1/actions/store-merchant/update-role", params);
|
|
481
768
|
}
|
|
482
769
|
};
|
|
@@ -496,6 +783,7 @@ var StoresResource = class {
|
|
|
496
783
|
* const { store } = await client.stores.create({ name: "My Store" });
|
|
497
784
|
*/
|
|
498
785
|
async create(params) {
|
|
786
|
+
validateRequired("name", params.name);
|
|
499
787
|
return this.http.post("/v1/actions/store/create-store", params);
|
|
500
788
|
}
|
|
501
789
|
/**
|
|
@@ -511,6 +799,7 @@ var StoresResource = class {
|
|
|
511
799
|
* });
|
|
512
800
|
*/
|
|
513
801
|
async update(params) {
|
|
802
|
+
validateShortId("id", params.id, "STO");
|
|
514
803
|
return this.http.post("/v1/actions/store/update-store", params);
|
|
515
804
|
}
|
|
516
805
|
/**
|
|
@@ -523,6 +812,7 @@ var StoresResource = class {
|
|
|
523
812
|
* const { store } = await client.stores.delete({ id: "STO_xxx" });
|
|
524
813
|
*/
|
|
525
814
|
async delete(params) {
|
|
815
|
+
validateShortId("id", params.id, "STO");
|
|
526
816
|
return this.http.post("/v1/actions/store/delete-store", params);
|
|
527
817
|
}
|
|
528
818
|
};
|
|
@@ -547,6 +837,8 @@ var SubscriptionProductGroupsResource = class {
|
|
|
547
837
|
* });
|
|
548
838
|
*/
|
|
549
839
|
async create(params) {
|
|
840
|
+
validateShortId("storeId", params.storeId, "STO");
|
|
841
|
+
validateRequired("name", params.name);
|
|
550
842
|
return this.http.post("/v1/actions/subscription-product-group/create-group", params);
|
|
551
843
|
}
|
|
552
844
|
/**
|
|
@@ -562,6 +854,7 @@ var SubscriptionProductGroupsResource = class {
|
|
|
562
854
|
* });
|
|
563
855
|
*/
|
|
564
856
|
async update(params) {
|
|
857
|
+
validateRequired("id", params.id);
|
|
565
858
|
return this.http.post("/v1/actions/subscription-product-group/update-group", params);
|
|
566
859
|
}
|
|
567
860
|
/**
|
|
@@ -574,6 +867,7 @@ var SubscriptionProductGroupsResource = class {
|
|
|
574
867
|
* const { group } = await client.subscriptionProductGroups.delete({ id: "GRP_xxx" });
|
|
575
868
|
*/
|
|
576
869
|
async delete(params) {
|
|
870
|
+
validateRequired("id", params.id);
|
|
577
871
|
return this.http.post("/v1/actions/subscription-product-group/delete-group", params);
|
|
578
872
|
}
|
|
579
873
|
/**
|
|
@@ -586,6 +880,7 @@ var SubscriptionProductGroupsResource = class {
|
|
|
586
880
|
* const { group } = await client.subscriptionProductGroups.publish({ id: "GRP_xxx" });
|
|
587
881
|
*/
|
|
588
882
|
async publish(params) {
|
|
883
|
+
validateRequired("id", params.id);
|
|
589
884
|
return this.http.post("/v1/actions/subscription-product-group/publish-group", params);
|
|
590
885
|
}
|
|
591
886
|
};
|
|
@@ -610,6 +905,10 @@ var SubscriptionProductsResource = class {
|
|
|
610
905
|
* });
|
|
611
906
|
*/
|
|
612
907
|
async create(params) {
|
|
908
|
+
validateShortId("storeId", params.storeId, "STO");
|
|
909
|
+
validateRequired("name", params.name);
|
|
910
|
+
validateEnum("billingPeriod", params.billingPeriod, ["weekly", "monthly", "quarterly", "yearly"]);
|
|
911
|
+
validatePrices("prices", params.prices);
|
|
613
912
|
return this.http.post("/v1/actions/subscription-product/create-product", params);
|
|
614
913
|
}
|
|
615
914
|
/**
|
|
@@ -627,6 +926,10 @@ var SubscriptionProductsResource = class {
|
|
|
627
926
|
* });
|
|
628
927
|
*/
|
|
629
928
|
async update(params) {
|
|
929
|
+
validateShortId("id", params.id, "PROD");
|
|
930
|
+
validateRequired("name", params.name);
|
|
931
|
+
validateEnum("billingPeriod", params.billingPeriod, ["weekly", "monthly", "quarterly", "yearly"]);
|
|
932
|
+
validatePrices("prices", params.prices);
|
|
630
933
|
return this.http.post("/v1/actions/subscription-product/update-product", params);
|
|
631
934
|
}
|
|
632
935
|
/**
|
|
@@ -639,6 +942,7 @@ var SubscriptionProductsResource = class {
|
|
|
639
942
|
* const { product } = await client.subscriptionProducts.publish({ id: "PROD_xxx" });
|
|
640
943
|
*/
|
|
641
944
|
async publish(params) {
|
|
945
|
+
validateShortId("id", params.id, "PROD");
|
|
642
946
|
return this.http.post("/v1/actions/subscription-product/publish-product", params);
|
|
643
947
|
}
|
|
644
948
|
/**
|
|
@@ -654,6 +958,8 @@ var SubscriptionProductsResource = class {
|
|
|
654
958
|
* });
|
|
655
959
|
*/
|
|
656
960
|
async updateStatus(params) {
|
|
961
|
+
validateShortId("id", params.id, "PROD");
|
|
962
|
+
validateEnum("status", params.status, ["active", "inactive"]);
|
|
657
963
|
return this.http.post("/v1/actions/subscription-product/update-status", params);
|
|
658
964
|
}
|
|
659
965
|
};
|
|
@@ -805,6 +1111,7 @@ var WebhooksResource = class {
|
|
|
805
1111
|
// src/client.ts
|
|
806
1112
|
var WaffoPancake = class {
|
|
807
1113
|
http;
|
|
1114
|
+
config;
|
|
808
1115
|
auth;
|
|
809
1116
|
stores;
|
|
810
1117
|
storeMerchants;
|
|
@@ -816,6 +1123,7 @@ var WaffoPancake = class {
|
|
|
816
1123
|
graphql;
|
|
817
1124
|
webhooks;
|
|
818
1125
|
constructor(config) {
|
|
1126
|
+
this.config = config;
|
|
819
1127
|
this.http = new HttpClient(config);
|
|
820
1128
|
this.auth = new AuthResource(this.http);
|
|
821
1129
|
this.stores = new StoresResource(this.http);
|
|
@@ -828,6 +1136,31 @@ var WaffoPancake = class {
|
|
|
828
1136
|
this.graphql = new GraphQLResource(this.http);
|
|
829
1137
|
this.webhooks = new WebhooksResource(config.webhookPublicKey);
|
|
830
1138
|
}
|
|
1139
|
+
/**
|
|
1140
|
+
* Create a buyer session for self-service operations.
|
|
1141
|
+
*
|
|
1142
|
+
* The returned session uses Bearer token authentication and provides
|
|
1143
|
+
* methods for order cancellation, subscription management, refund tickets,
|
|
1144
|
+
* and scoped GraphQL queries.
|
|
1145
|
+
*
|
|
1146
|
+
* @param token - Session token from `client.auth.issueSessionToken()`
|
|
1147
|
+
* @returns A buyer session with self-service methods
|
|
1148
|
+
*
|
|
1149
|
+
* @example
|
|
1150
|
+
* const { token } = await client.auth.issueSessionToken({
|
|
1151
|
+
* storeId: "STO_xxx",
|
|
1152
|
+
* buyerIdentity: "customer@example.com",
|
|
1153
|
+
* });
|
|
1154
|
+
* const buyer = client.buyer(token);
|
|
1155
|
+
* await buyer.cancelSubscription({ orderId: "ORD_xxx" });
|
|
1156
|
+
*/
|
|
1157
|
+
buyer(token) {
|
|
1158
|
+
const buyerHttp = new BuyerHttpClient(token, {
|
|
1159
|
+
baseUrl: this.config.baseUrl,
|
|
1160
|
+
fetch: this.config.fetch
|
|
1161
|
+
});
|
|
1162
|
+
return new BuyerSession(buyerHttp);
|
|
1163
|
+
}
|
|
831
1164
|
};
|
|
832
1165
|
|
|
833
1166
|
// src/types.ts
|
|
@@ -895,11 +1228,14 @@ var PaymentStatus = /* @__PURE__ */ ((PaymentStatus2) => {
|
|
|
895
1228
|
})(PaymentStatus || {});
|
|
896
1229
|
var RefundTicketStatus = /* @__PURE__ */ ((RefundTicketStatus2) => {
|
|
897
1230
|
RefundTicketStatus2["Pending"] = "pending";
|
|
1231
|
+
RefundTicketStatus2["UnderReview"] = "under_review";
|
|
898
1232
|
RefundTicketStatus2["Approved"] = "approved";
|
|
899
1233
|
RefundTicketStatus2["Rejected"] = "rejected";
|
|
1234
|
+
RefundTicketStatus2["Returned"] = "returned";
|
|
900
1235
|
RefundTicketStatus2["Processing"] = "processing";
|
|
901
1236
|
RefundTicketStatus2["Succeeded"] = "succeeded";
|
|
902
1237
|
RefundTicketStatus2["Failed"] = "failed";
|
|
1238
|
+
RefundTicketStatus2["Cancelled"] = "cancelled";
|
|
903
1239
|
return RefundTicketStatus2;
|
|
904
1240
|
})(RefundTicketStatus || {});
|
|
905
1241
|
var RefundStatus = /* @__PURE__ */ ((RefundStatus2) => {
|
|
@@ -927,6 +1263,7 @@ var ErrorLayer = /* @__PURE__ */ ((ErrorLayer2) => {
|
|
|
927
1263
|
ErrorLayer2["GraphQL"] = "graphql";
|
|
928
1264
|
ErrorLayer2["Resource"] = "resource";
|
|
929
1265
|
ErrorLayer2["Email"] = "email";
|
|
1266
|
+
ErrorLayer2["Sdk"] = "sdk";
|
|
930
1267
|
return ErrorLayer2;
|
|
931
1268
|
})(ErrorLayer || {});
|
|
932
1269
|
var WebhookEventType = /* @__PURE__ */ ((WebhookEventType2) => {
|