@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.cjs
CHANGED
|
@@ -41,9 +41,6 @@ __export(index_exports, {
|
|
|
41
41
|
});
|
|
42
42
|
module.exports = __toCommonJS(index_exports);
|
|
43
43
|
|
|
44
|
-
// src/http-client.ts
|
|
45
|
-
var import_node_crypto2 = require("crypto");
|
|
46
|
-
|
|
47
44
|
// src/errors.ts
|
|
48
45
|
var WaffoPancakeError = class extends Error {
|
|
49
46
|
status;
|
|
@@ -57,6 +54,45 @@ var WaffoPancakeError = class extends Error {
|
|
|
57
54
|
}
|
|
58
55
|
};
|
|
59
56
|
|
|
57
|
+
// src/buyer-http-client.ts
|
|
58
|
+
var DEFAULT_BASE_URL = "https://api.waffo.ai";
|
|
59
|
+
var BuyerHttpClient = class {
|
|
60
|
+
token;
|
|
61
|
+
baseUrl;
|
|
62
|
+
_fetch;
|
|
63
|
+
constructor(token, config) {
|
|
64
|
+
this.token = token;
|
|
65
|
+
this.baseUrl = (config.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
66
|
+
this._fetch = config.fetch ?? fetch;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Send a Bearer-authenticated POST request and return the parsed `data` field.
|
|
70
|
+
*
|
|
71
|
+
* @param path - API path
|
|
72
|
+
* @param body - Request body object
|
|
73
|
+
* @returns Parsed `data` field from the response
|
|
74
|
+
* @throws {WaffoPancakeError} When the API returns errors
|
|
75
|
+
*/
|
|
76
|
+
async post(path, body) {
|
|
77
|
+
const response = await this._fetch(`${this.baseUrl}${path}`, {
|
|
78
|
+
method: "POST",
|
|
79
|
+
headers: {
|
|
80
|
+
"Content-Type": "application/json",
|
|
81
|
+
"Authorization": `Bearer ${this.token}`
|
|
82
|
+
},
|
|
83
|
+
body: JSON.stringify(body)
|
|
84
|
+
});
|
|
85
|
+
const result = await response.json();
|
|
86
|
+
if ("errors" in result && result.errors) {
|
|
87
|
+
throw new WaffoPancakeError(response.status, result.errors);
|
|
88
|
+
}
|
|
89
|
+
return result.data;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
// src/http-client.ts
|
|
94
|
+
var import_node_crypto2 = require("crypto");
|
|
95
|
+
|
|
60
96
|
// src/signing.ts
|
|
61
97
|
var import_node_crypto = require("crypto");
|
|
62
98
|
var PKCS8_HEADER = "-----BEGIN PRIVATE KEY-----";
|
|
@@ -169,7 +205,7 @@ ${bodyHash}`;
|
|
|
169
205
|
}
|
|
170
206
|
|
|
171
207
|
// src/http-client.ts
|
|
172
|
-
var
|
|
208
|
+
var DEFAULT_BASE_URL2 = "https://api.waffo.ai";
|
|
173
209
|
var HttpClient = class {
|
|
174
210
|
merchantId;
|
|
175
211
|
privateKey;
|
|
@@ -178,7 +214,7 @@ var HttpClient = class {
|
|
|
178
214
|
constructor(config) {
|
|
179
215
|
this.merchantId = config.merchantId;
|
|
180
216
|
this.privateKey = normalizePrivateKey(config.privateKey);
|
|
181
|
-
this.baseUrl = (config.baseUrl ??
|
|
217
|
+
this.baseUrl = (config.baseUrl ?? DEFAULT_BASE_URL2).replace(/\/+$/, "");
|
|
182
218
|
this._fetch = config.fetch ?? fetch;
|
|
183
219
|
}
|
|
184
220
|
/**
|
|
@@ -217,6 +253,105 @@ var HttpClient = class {
|
|
|
217
253
|
}
|
|
218
254
|
};
|
|
219
255
|
|
|
256
|
+
// src/validation.ts
|
|
257
|
+
var SHORT_ID_REGEX = /^[A-Z]{2,4}_[A-Za-z0-9]+$/;
|
|
258
|
+
var CURRENCY_CODE_REGEX = /^[A-Z]{3}$/;
|
|
259
|
+
var COUNTRY_CODE_REGEX = /^[A-Z]{2}$/;
|
|
260
|
+
var AMOUNT_STRING_REGEX = /^\d+(\.\d+)?$/;
|
|
261
|
+
var SHORT_ID_LABELS = {
|
|
262
|
+
STO: "Store",
|
|
263
|
+
PROD: "Product",
|
|
264
|
+
ORD: "Order",
|
|
265
|
+
PAY: "Payment",
|
|
266
|
+
REF: "Refund",
|
|
267
|
+
TKT: "Ticket",
|
|
268
|
+
MER: "Merchant"
|
|
269
|
+
};
|
|
270
|
+
function fail(message) {
|
|
271
|
+
throw new WaffoPancakeError(400, [{ message, layer: "sdk" }]);
|
|
272
|
+
}
|
|
273
|
+
function validateRequired(field, value) {
|
|
274
|
+
if (value === void 0 || value === null) {
|
|
275
|
+
fail(`Missing required field: ${field}`);
|
|
276
|
+
}
|
|
277
|
+
if (typeof value === "string" && value.trim() === "") {
|
|
278
|
+
fail(`${field} cannot be empty`);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
function validateShortId(field, value, prefix) {
|
|
282
|
+
validateRequired(field, value);
|
|
283
|
+
const label = SHORT_ID_LABELS[prefix] ?? prefix;
|
|
284
|
+
if (!SHORT_ID_REGEX.test(value)) {
|
|
285
|
+
fail(`Invalid ${field}: expected ${label} Short ID format (${prefix}_xxx), got "${value}"`);
|
|
286
|
+
}
|
|
287
|
+
if (!value.startsWith(`${prefix}_`)) {
|
|
288
|
+
fail(`Invalid ${field}: expected ${prefix}_ prefix (${label}), got "${value.split("_")[0]}_"`);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
function validateCurrencyCode(field, value) {
|
|
292
|
+
validateRequired(field, value);
|
|
293
|
+
if (!CURRENCY_CODE_REGEX.test(value)) {
|
|
294
|
+
fail(`Invalid ${field}: expected 3-letter ISO 4217 currency code (e.g., "USD"), got "${value}"`);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
function validateAmountString(field, value) {
|
|
298
|
+
validateRequired(field, value);
|
|
299
|
+
if (!AMOUNT_STRING_REGEX.test(value)) {
|
|
300
|
+
fail(`Invalid ${field}: expected numeric string in display format (e.g., "9.99", "1000"), got "${value}"`);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
function validateEnum(field, value, allowed) {
|
|
304
|
+
validateRequired(field, value);
|
|
305
|
+
if (!allowed.includes(value)) {
|
|
306
|
+
fail(`Invalid ${field}: expected one of [${allowed.join(", ")}], got "${value}"`);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
function validatePositiveInteger(field, value) {
|
|
310
|
+
if (!Number.isInteger(value) || value <= 0) {
|
|
311
|
+
fail(`Invalid ${field}: expected positive integer, got ${value}`);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
function validateCountryCode(field, value) {
|
|
315
|
+
validateRequired(field, value);
|
|
316
|
+
if (!COUNTRY_CODE_REGEX.test(value)) {
|
|
317
|
+
fail(`Invalid ${field}: expected 2-letter ISO 3166-1 country code (e.g., "US"), got "${value}"`);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
function validatePrices(field, prices) {
|
|
321
|
+
validateRequired(field, prices);
|
|
322
|
+
const entries = Object.entries(prices);
|
|
323
|
+
if (entries.length === 0) {
|
|
324
|
+
fail(`${field} must contain at least one currency`);
|
|
325
|
+
}
|
|
326
|
+
for (const [currency, info] of entries) {
|
|
327
|
+
validateCurrencyCode(`${field}.${currency} (key)`, currency);
|
|
328
|
+
validateAmountString(`${field}.${currency}.amount`, info.amount);
|
|
329
|
+
validateRequired(`${field}.${currency}.taxCategory`, info.taxCategory);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
function validateBillingDetail(detail) {
|
|
333
|
+
validateCountryCode("billingDetail.country", detail.country);
|
|
334
|
+
if (typeof detail.isBusiness !== "boolean") {
|
|
335
|
+
fail(`Invalid billingDetail.isBusiness: expected boolean, got ${typeof detail.isBusiness}`);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
function validateCheckoutCommon(params) {
|
|
339
|
+
validateShortId("storeId", params.storeId, "STO");
|
|
340
|
+
validateShortId("productId", params.productId, "PROD");
|
|
341
|
+
validateEnum("productType", params.productType, ["onetime", "subscription"]);
|
|
342
|
+
validateCurrencyCode("currency", params.currency);
|
|
343
|
+
if (params.priceSnapshot) {
|
|
344
|
+
validateAmountString("priceSnapshot.amount", params.priceSnapshot.amount);
|
|
345
|
+
validateRequired("priceSnapshot.taxCategory", params.priceSnapshot.taxCategory);
|
|
346
|
+
}
|
|
347
|
+
if (params.billingDetail) {
|
|
348
|
+
validateBillingDetail(params.billingDetail);
|
|
349
|
+
}
|
|
350
|
+
if (params.expiresInSeconds !== void 0) {
|
|
351
|
+
validatePositiveInteger("expiresInSeconds", params.expiresInSeconds);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
220
355
|
// src/resources/auth.ts
|
|
221
356
|
var AuthResource = class {
|
|
222
357
|
constructor(http) {
|
|
@@ -235,10 +370,140 @@ var AuthResource = class {
|
|
|
235
370
|
* });
|
|
236
371
|
*/
|
|
237
372
|
async issueSessionToken(params) {
|
|
373
|
+
validateShortId("storeId", params.storeId, "STO");
|
|
374
|
+
validateRequired("buyerIdentity", params.buyerIdentity);
|
|
238
375
|
return this.http.post("/v1/actions/auth/issue-session-token", params);
|
|
239
376
|
}
|
|
240
377
|
};
|
|
241
378
|
|
|
379
|
+
// src/resources/buyer.ts
|
|
380
|
+
var BuyerSession = class {
|
|
381
|
+
constructor(http) {
|
|
382
|
+
this.http = http;
|
|
383
|
+
this.graphql = new BuyerGraphQL(http);
|
|
384
|
+
}
|
|
385
|
+
/** GraphQL query access scoped to the buyer's data. */
|
|
386
|
+
graphql;
|
|
387
|
+
/**
|
|
388
|
+
* Cancel a subscription order.
|
|
389
|
+
*
|
|
390
|
+
* @param params - Order to cancel
|
|
391
|
+
* @returns Order ID and resulting status
|
|
392
|
+
*
|
|
393
|
+
* @example
|
|
394
|
+
* const { orderId, status } = await buyer.cancelSubscription({ orderId: "ORD_xxx" });
|
|
395
|
+
* // status: "canceled" (was pending) or "canceling" (was active)
|
|
396
|
+
*/
|
|
397
|
+
async cancelSubscription(params) {
|
|
398
|
+
validateShortId("orderId", params.orderId, "ORD");
|
|
399
|
+
return this.http.post(
|
|
400
|
+
"/v1/actions/subscription-order/cancel-order",
|
|
401
|
+
params
|
|
402
|
+
);
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Cancel a one-time order (only while payment is still pending).
|
|
406
|
+
*
|
|
407
|
+
* @param params - Order to cancel
|
|
408
|
+
* @returns Order ID and resulting status
|
|
409
|
+
*
|
|
410
|
+
* @example
|
|
411
|
+
* const { orderId, status } = await buyer.cancelOnetimeOrder({ orderId: "ORD_xxx" });
|
|
412
|
+
*/
|
|
413
|
+
async cancelOnetimeOrder(params) {
|
|
414
|
+
validateShortId("orderId", params.orderId, "ORD");
|
|
415
|
+
return this.http.post(
|
|
416
|
+
"/v1/actions/onetime-order/cancel-order",
|
|
417
|
+
params
|
|
418
|
+
);
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* Reactivate a subscription that is in `canceling` status.
|
|
422
|
+
*
|
|
423
|
+
* @param params - Order to reactivate
|
|
424
|
+
* @returns Order ID and resulting status
|
|
425
|
+
*
|
|
426
|
+
* @example
|
|
427
|
+
* const { orderId, status } = await buyer.reactivateSubscription({ orderId: "ORD_xxx" });
|
|
428
|
+
* // status: "active"
|
|
429
|
+
*/
|
|
430
|
+
async reactivateSubscription(params) {
|
|
431
|
+
validateShortId("orderId", params.orderId, "ORD");
|
|
432
|
+
return this.http.post(
|
|
433
|
+
"/v1/actions/subscription-order/reactivate-order",
|
|
434
|
+
params
|
|
435
|
+
);
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* Submit a refund request for a payment.
|
|
439
|
+
*
|
|
440
|
+
* @param params - Refund ticket details
|
|
441
|
+
* @returns Created refund ticket
|
|
442
|
+
*
|
|
443
|
+
* @example
|
|
444
|
+
* const { ticket } = await buyer.createRefundTicket({
|
|
445
|
+
* paymentId: "PAY_xxx",
|
|
446
|
+
* reason: "Product not as described",
|
|
447
|
+
* requestedAmount: { amount: "29.00", currency: "USD" },
|
|
448
|
+
* });
|
|
449
|
+
*/
|
|
450
|
+
async createRefundTicket(params) {
|
|
451
|
+
validateShortId("paymentId", params.paymentId, "PAY");
|
|
452
|
+
validateRequired("reason", params.reason);
|
|
453
|
+
validateAmountString("requestedAmount.amount", params.requestedAmount.amount);
|
|
454
|
+
validateCurrencyCode("requestedAmount.currency", params.requestedAmount.currency);
|
|
455
|
+
return this.http.post(
|
|
456
|
+
"/v1/actions/refund-ticket/create-ticket",
|
|
457
|
+
params
|
|
458
|
+
);
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* Resubmit a previously rejected refund ticket with updated details.
|
|
462
|
+
*
|
|
463
|
+
* @param params - Updated ticket details
|
|
464
|
+
* @returns Updated refund ticket
|
|
465
|
+
*
|
|
466
|
+
* @example
|
|
467
|
+
* const { ticket } = await buyer.resubmitRefundTicket({
|
|
468
|
+
* ticketId: "TKT_xxx",
|
|
469
|
+
* paymentId: "PAY_xxx",
|
|
470
|
+
* reason: "Updated reason with more detail",
|
|
471
|
+
* requestedAmount: { amount: "29.00", currency: "USD" },
|
|
472
|
+
* });
|
|
473
|
+
*/
|
|
474
|
+
async resubmitRefundTicket(params) {
|
|
475
|
+
validateShortId("ticketId", params.ticketId, "TKT");
|
|
476
|
+
validateShortId("paymentId", params.paymentId, "PAY");
|
|
477
|
+
validateRequired("reason", params.reason);
|
|
478
|
+
validateAmountString("requestedAmount.amount", params.requestedAmount.amount);
|
|
479
|
+
validateCurrencyCode("requestedAmount.currency", params.requestedAmount.currency);
|
|
480
|
+
return this.http.post(
|
|
481
|
+
"/v1/actions/refund-ticket/resubmit-ticket",
|
|
482
|
+
params
|
|
483
|
+
);
|
|
484
|
+
}
|
|
485
|
+
};
|
|
486
|
+
var BuyerGraphQL = class {
|
|
487
|
+
constructor(http) {
|
|
488
|
+
this.http = http;
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Execute a GraphQL query scoped to the buyer's data.
|
|
492
|
+
*
|
|
493
|
+
* @param params - GraphQL query and variables
|
|
494
|
+
* @returns GraphQL response
|
|
495
|
+
*
|
|
496
|
+
* @example
|
|
497
|
+
* const result = await buyer.graphql.query({
|
|
498
|
+
* query: `query { orders { id status } }`,
|
|
499
|
+
* });
|
|
500
|
+
*/
|
|
501
|
+
async query(params) {
|
|
502
|
+
validateRequired("query", params.query);
|
|
503
|
+
return this.http.post("/v1/graphql", params);
|
|
504
|
+
}
|
|
505
|
+
};
|
|
506
|
+
|
|
242
507
|
// src/resources/checkout-anonymous.ts
|
|
243
508
|
var CheckoutAnonymousResource = class {
|
|
244
509
|
constructor(http) {
|
|
@@ -260,6 +525,7 @@ var CheckoutAnonymousResource = class {
|
|
|
260
525
|
* // Redirect to result.checkoutUrl
|
|
261
526
|
*/
|
|
262
527
|
async create(params) {
|
|
528
|
+
validateCheckoutCommon(params);
|
|
263
529
|
return this.http.post(
|
|
264
530
|
"/v1/actions/checkout/create-session",
|
|
265
531
|
params
|
|
@@ -295,6 +561,8 @@ var CheckoutAuthenticatedResource = class {
|
|
|
295
561
|
* // Redirect to result.checkoutUrl (includes #token=...)
|
|
296
562
|
*/
|
|
297
563
|
async create(params) {
|
|
564
|
+
validateCheckoutCommon(params);
|
|
565
|
+
validateRequired("buyerIdentity", params.buyerIdentity);
|
|
298
566
|
const { buyerIdentity, buyerEmail, ...sessionFields } = params;
|
|
299
567
|
const [tokenResult, sessionResult] = await Promise.all([
|
|
300
568
|
this.http.post("/v1/actions/auth/issue-session-token", {
|
|
@@ -323,7 +591,7 @@ var CheckoutResource = class {
|
|
|
323
591
|
this.anonymous = new CheckoutAnonymousResource(http);
|
|
324
592
|
this.authenticated = new CheckoutAuthenticatedResource(http);
|
|
325
593
|
}
|
|
326
|
-
/** Anonymous checkout —
|
|
594
|
+
/** Anonymous checkout — no buyer identity, empty form. */
|
|
327
595
|
anonymous;
|
|
328
596
|
/** Authenticated checkout — merchant provides buyer identity. */
|
|
329
597
|
authenticated;
|
|
@@ -375,6 +643,7 @@ var GraphQLResource = class {
|
|
|
375
643
|
* });
|
|
376
644
|
*/
|
|
377
645
|
async query(params) {
|
|
646
|
+
validateRequired("query", params.query);
|
|
378
647
|
return this.http.post("/v1/graphql", params);
|
|
379
648
|
}
|
|
380
649
|
};
|
|
@@ -398,6 +667,9 @@ var OnetimeProductsResource = class {
|
|
|
398
667
|
* });
|
|
399
668
|
*/
|
|
400
669
|
async create(params) {
|
|
670
|
+
validateShortId("storeId", params.storeId, "STO");
|
|
671
|
+
validateRequired("name", params.name);
|
|
672
|
+
validatePrices("prices", params.prices);
|
|
401
673
|
return this.http.post("/v1/actions/onetime-product/create-product", params);
|
|
402
674
|
}
|
|
403
675
|
/**
|
|
@@ -414,6 +686,9 @@ var OnetimeProductsResource = class {
|
|
|
414
686
|
* });
|
|
415
687
|
*/
|
|
416
688
|
async update(params) {
|
|
689
|
+
validateShortId("id", params.id, "PROD");
|
|
690
|
+
validateRequired("name", params.name);
|
|
691
|
+
validatePrices("prices", params.prices);
|
|
417
692
|
return this.http.post("/v1/actions/onetime-product/update-product", params);
|
|
418
693
|
}
|
|
419
694
|
/**
|
|
@@ -426,6 +701,7 @@ var OnetimeProductsResource = class {
|
|
|
426
701
|
* const { product } = await client.onetimeProducts.publish({ id: "PROD_xxx" });
|
|
427
702
|
*/
|
|
428
703
|
async publish(params) {
|
|
704
|
+
validateShortId("id", params.id, "PROD");
|
|
429
705
|
return this.http.post("/v1/actions/onetime-product/publish-product", params);
|
|
430
706
|
}
|
|
431
707
|
/**
|
|
@@ -441,6 +717,8 @@ var OnetimeProductsResource = class {
|
|
|
441
717
|
* });
|
|
442
718
|
*/
|
|
443
719
|
async updateStatus(params) {
|
|
720
|
+
validateShortId("id", params.id, "PROD");
|
|
721
|
+
validateEnum("status", params.status, ["active", "inactive"]);
|
|
444
722
|
return this.http.post("/v1/actions/onetime-product/update-status", params);
|
|
445
723
|
}
|
|
446
724
|
};
|
|
@@ -466,6 +744,7 @@ var OrdersResource = class {
|
|
|
466
744
|
* // status: "canceled" or "canceling"
|
|
467
745
|
*/
|
|
468
746
|
async cancelSubscription(params) {
|
|
747
|
+
validateShortId("orderId", params.orderId, "ORD");
|
|
469
748
|
return this.http.post("/v1/actions/subscription-order/cancel-order", params);
|
|
470
749
|
}
|
|
471
750
|
};
|
|
@@ -489,6 +768,9 @@ var StoreMerchantsResource = class {
|
|
|
489
768
|
* });
|
|
490
769
|
*/
|
|
491
770
|
async add(params) {
|
|
771
|
+
validateShortId("storeId", params.storeId, "STO");
|
|
772
|
+
validateRequired("email", params.email);
|
|
773
|
+
validateEnum("role", params.role, ["admin", "member"]);
|
|
492
774
|
return this.http.post("/v1/actions/store-merchant/add-merchant", params);
|
|
493
775
|
}
|
|
494
776
|
/**
|
|
@@ -504,6 +786,8 @@ var StoreMerchantsResource = class {
|
|
|
504
786
|
* });
|
|
505
787
|
*/
|
|
506
788
|
async remove(params) {
|
|
789
|
+
validateShortId("storeId", params.storeId, "STO");
|
|
790
|
+
validateShortId("merchantId", params.merchantId, "MER");
|
|
507
791
|
return this.http.post("/v1/actions/store-merchant/remove-merchant", params);
|
|
508
792
|
}
|
|
509
793
|
/**
|
|
@@ -520,6 +804,9 @@ var StoreMerchantsResource = class {
|
|
|
520
804
|
* });
|
|
521
805
|
*/
|
|
522
806
|
async updateRole(params) {
|
|
807
|
+
validateShortId("storeId", params.storeId, "STO");
|
|
808
|
+
validateShortId("merchantId", params.merchantId, "MER");
|
|
809
|
+
validateEnum("role", params.role, ["admin", "member"]);
|
|
523
810
|
return this.http.post("/v1/actions/store-merchant/update-role", params);
|
|
524
811
|
}
|
|
525
812
|
};
|
|
@@ -539,6 +826,7 @@ var StoresResource = class {
|
|
|
539
826
|
* const { store } = await client.stores.create({ name: "My Store" });
|
|
540
827
|
*/
|
|
541
828
|
async create(params) {
|
|
829
|
+
validateRequired("name", params.name);
|
|
542
830
|
return this.http.post("/v1/actions/store/create-store", params);
|
|
543
831
|
}
|
|
544
832
|
/**
|
|
@@ -554,6 +842,7 @@ var StoresResource = class {
|
|
|
554
842
|
* });
|
|
555
843
|
*/
|
|
556
844
|
async update(params) {
|
|
845
|
+
validateShortId("id", params.id, "STO");
|
|
557
846
|
return this.http.post("/v1/actions/store/update-store", params);
|
|
558
847
|
}
|
|
559
848
|
/**
|
|
@@ -566,6 +855,7 @@ var StoresResource = class {
|
|
|
566
855
|
* const { store } = await client.stores.delete({ id: "STO_xxx" });
|
|
567
856
|
*/
|
|
568
857
|
async delete(params) {
|
|
858
|
+
validateShortId("id", params.id, "STO");
|
|
569
859
|
return this.http.post("/v1/actions/store/delete-store", params);
|
|
570
860
|
}
|
|
571
861
|
};
|
|
@@ -590,6 +880,8 @@ var SubscriptionProductGroupsResource = class {
|
|
|
590
880
|
* });
|
|
591
881
|
*/
|
|
592
882
|
async create(params) {
|
|
883
|
+
validateShortId("storeId", params.storeId, "STO");
|
|
884
|
+
validateRequired("name", params.name);
|
|
593
885
|
return this.http.post("/v1/actions/subscription-product-group/create-group", params);
|
|
594
886
|
}
|
|
595
887
|
/**
|
|
@@ -605,6 +897,7 @@ var SubscriptionProductGroupsResource = class {
|
|
|
605
897
|
* });
|
|
606
898
|
*/
|
|
607
899
|
async update(params) {
|
|
900
|
+
validateRequired("id", params.id);
|
|
608
901
|
return this.http.post("/v1/actions/subscription-product-group/update-group", params);
|
|
609
902
|
}
|
|
610
903
|
/**
|
|
@@ -617,6 +910,7 @@ var SubscriptionProductGroupsResource = class {
|
|
|
617
910
|
* const { group } = await client.subscriptionProductGroups.delete({ id: "GRP_xxx" });
|
|
618
911
|
*/
|
|
619
912
|
async delete(params) {
|
|
913
|
+
validateRequired("id", params.id);
|
|
620
914
|
return this.http.post("/v1/actions/subscription-product-group/delete-group", params);
|
|
621
915
|
}
|
|
622
916
|
/**
|
|
@@ -629,6 +923,7 @@ var SubscriptionProductGroupsResource = class {
|
|
|
629
923
|
* const { group } = await client.subscriptionProductGroups.publish({ id: "GRP_xxx" });
|
|
630
924
|
*/
|
|
631
925
|
async publish(params) {
|
|
926
|
+
validateRequired("id", params.id);
|
|
632
927
|
return this.http.post("/v1/actions/subscription-product-group/publish-group", params);
|
|
633
928
|
}
|
|
634
929
|
};
|
|
@@ -653,6 +948,10 @@ var SubscriptionProductsResource = class {
|
|
|
653
948
|
* });
|
|
654
949
|
*/
|
|
655
950
|
async create(params) {
|
|
951
|
+
validateShortId("storeId", params.storeId, "STO");
|
|
952
|
+
validateRequired("name", params.name);
|
|
953
|
+
validateEnum("billingPeriod", params.billingPeriod, ["weekly", "monthly", "quarterly", "yearly"]);
|
|
954
|
+
validatePrices("prices", params.prices);
|
|
656
955
|
return this.http.post("/v1/actions/subscription-product/create-product", params);
|
|
657
956
|
}
|
|
658
957
|
/**
|
|
@@ -670,6 +969,10 @@ var SubscriptionProductsResource = class {
|
|
|
670
969
|
* });
|
|
671
970
|
*/
|
|
672
971
|
async update(params) {
|
|
972
|
+
validateShortId("id", params.id, "PROD");
|
|
973
|
+
validateRequired("name", params.name);
|
|
974
|
+
validateEnum("billingPeriod", params.billingPeriod, ["weekly", "monthly", "quarterly", "yearly"]);
|
|
975
|
+
validatePrices("prices", params.prices);
|
|
673
976
|
return this.http.post("/v1/actions/subscription-product/update-product", params);
|
|
674
977
|
}
|
|
675
978
|
/**
|
|
@@ -682,6 +985,7 @@ var SubscriptionProductsResource = class {
|
|
|
682
985
|
* const { product } = await client.subscriptionProducts.publish({ id: "PROD_xxx" });
|
|
683
986
|
*/
|
|
684
987
|
async publish(params) {
|
|
988
|
+
validateShortId("id", params.id, "PROD");
|
|
685
989
|
return this.http.post("/v1/actions/subscription-product/publish-product", params);
|
|
686
990
|
}
|
|
687
991
|
/**
|
|
@@ -697,6 +1001,8 @@ var SubscriptionProductsResource = class {
|
|
|
697
1001
|
* });
|
|
698
1002
|
*/
|
|
699
1003
|
async updateStatus(params) {
|
|
1004
|
+
validateShortId("id", params.id, "PROD");
|
|
1005
|
+
validateEnum("status", params.status, ["active", "inactive"]);
|
|
700
1006
|
return this.http.post("/v1/actions/subscription-product/update-status", params);
|
|
701
1007
|
}
|
|
702
1008
|
};
|
|
@@ -848,6 +1154,7 @@ var WebhooksResource = class {
|
|
|
848
1154
|
// src/client.ts
|
|
849
1155
|
var WaffoPancake = class {
|
|
850
1156
|
http;
|
|
1157
|
+
config;
|
|
851
1158
|
auth;
|
|
852
1159
|
stores;
|
|
853
1160
|
storeMerchants;
|
|
@@ -859,6 +1166,7 @@ var WaffoPancake = class {
|
|
|
859
1166
|
graphql;
|
|
860
1167
|
webhooks;
|
|
861
1168
|
constructor(config) {
|
|
1169
|
+
this.config = config;
|
|
862
1170
|
this.http = new HttpClient(config);
|
|
863
1171
|
this.auth = new AuthResource(this.http);
|
|
864
1172
|
this.stores = new StoresResource(this.http);
|
|
@@ -871,6 +1179,31 @@ var WaffoPancake = class {
|
|
|
871
1179
|
this.graphql = new GraphQLResource(this.http);
|
|
872
1180
|
this.webhooks = new WebhooksResource(config.webhookPublicKey);
|
|
873
1181
|
}
|
|
1182
|
+
/**
|
|
1183
|
+
* Create a buyer session for self-service operations.
|
|
1184
|
+
*
|
|
1185
|
+
* The returned session uses Bearer token authentication and provides
|
|
1186
|
+
* methods for order cancellation, subscription management, refund tickets,
|
|
1187
|
+
* and scoped GraphQL queries.
|
|
1188
|
+
*
|
|
1189
|
+
* @param token - Session token from `client.auth.issueSessionToken()`
|
|
1190
|
+
* @returns A buyer session with self-service methods
|
|
1191
|
+
*
|
|
1192
|
+
* @example
|
|
1193
|
+
* const { token } = await client.auth.issueSessionToken({
|
|
1194
|
+
* storeId: "STO_xxx",
|
|
1195
|
+
* buyerIdentity: "customer@example.com",
|
|
1196
|
+
* });
|
|
1197
|
+
* const buyer = client.buyer(token);
|
|
1198
|
+
* await buyer.cancelSubscription({ orderId: "ORD_xxx" });
|
|
1199
|
+
*/
|
|
1200
|
+
buyer(token) {
|
|
1201
|
+
const buyerHttp = new BuyerHttpClient(token, {
|
|
1202
|
+
baseUrl: this.config.baseUrl,
|
|
1203
|
+
fetch: this.config.fetch
|
|
1204
|
+
});
|
|
1205
|
+
return new BuyerSession(buyerHttp);
|
|
1206
|
+
}
|
|
874
1207
|
};
|
|
875
1208
|
|
|
876
1209
|
// src/types.ts
|
|
@@ -938,11 +1271,14 @@ var PaymentStatus = /* @__PURE__ */ ((PaymentStatus2) => {
|
|
|
938
1271
|
})(PaymentStatus || {});
|
|
939
1272
|
var RefundTicketStatus = /* @__PURE__ */ ((RefundTicketStatus2) => {
|
|
940
1273
|
RefundTicketStatus2["Pending"] = "pending";
|
|
1274
|
+
RefundTicketStatus2["UnderReview"] = "under_review";
|
|
941
1275
|
RefundTicketStatus2["Approved"] = "approved";
|
|
942
1276
|
RefundTicketStatus2["Rejected"] = "rejected";
|
|
1277
|
+
RefundTicketStatus2["Returned"] = "returned";
|
|
943
1278
|
RefundTicketStatus2["Processing"] = "processing";
|
|
944
1279
|
RefundTicketStatus2["Succeeded"] = "succeeded";
|
|
945
1280
|
RefundTicketStatus2["Failed"] = "failed";
|
|
1281
|
+
RefundTicketStatus2["Cancelled"] = "cancelled";
|
|
946
1282
|
return RefundTicketStatus2;
|
|
947
1283
|
})(RefundTicketStatus || {});
|
|
948
1284
|
var RefundStatus = /* @__PURE__ */ ((RefundStatus2) => {
|
|
@@ -970,6 +1306,7 @@ var ErrorLayer = /* @__PURE__ */ ((ErrorLayer2) => {
|
|
|
970
1306
|
ErrorLayer2["GraphQL"] = "graphql";
|
|
971
1307
|
ErrorLayer2["Resource"] = "resource";
|
|
972
1308
|
ErrorLayer2["Email"] = "email";
|
|
1309
|
+
ErrorLayer2["Sdk"] = "sdk";
|
|
973
1310
|
return ErrorLayer2;
|
|
974
1311
|
})(ErrorLayer || {});
|
|
975
1312
|
var WebhookEventType = /* @__PURE__ */ ((WebhookEventType2) => {
|