@waffo/pancake-ts 0.3.0 → 0.3.2

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/dist/index.d.cts CHANGED
@@ -452,8 +452,8 @@ interface CreateOnetimeProductParams {
452
452
  */
453
453
  interface UpdateOnetimeProductParams {
454
454
  id: string;
455
- name: string;
456
- prices: Prices;
455
+ name?: string;
456
+ prices?: Prices;
457
457
  description?: string;
458
458
  media?: MediaItem[];
459
459
  successUrl?: string;
@@ -510,9 +510,9 @@ interface CreateSubscriptionProductParams {
510
510
  */
511
511
  interface UpdateSubscriptionProductParams {
512
512
  id: string;
513
- name: string;
514
- billingPeriod: BillingPeriod;
515
- prices: Prices;
513
+ name?: string;
514
+ billingPeriod?: BillingPeriod;
515
+ prices?: Prices;
516
516
  description?: string;
517
517
  media?: MediaItem[];
518
518
  successUrl?: string;
@@ -1312,13 +1312,20 @@ declare class OnetimeProductsResource {
1312
1312
  /**
1313
1313
  * Update a one-time product. Creates a new version; skips if unchanged.
1314
1314
  *
1315
- * @param params - Product update parameters (all content fields required)
1315
+ * @param params - Product update parameters (only `id` is required)
1316
1316
  * @returns Updated product detail
1317
1317
  *
1318
1318
  * @example
1319
+ * // Update only the name
1319
1320
  * const { product } = await client.onetimeProducts.update({
1320
1321
  * id: "PROD_xxx",
1321
1322
  * name: "E-Book v2",
1323
+ * });
1324
+ *
1325
+ * @example
1326
+ * // Update prices while preserving other fields
1327
+ * const { product } = await client.onetimeProducts.update({
1328
+ * id: "PROD_xxx",
1322
1329
  * prices: { USD: { amount: "39.00", taxCategory: "digital_goods" } },
1323
1330
  * });
1324
1331
  */
@@ -1554,15 +1561,22 @@ declare class SubscriptionProductsResource {
1554
1561
  /**
1555
1562
  * Update a subscription product. Creates a new version; skips if unchanged.
1556
1563
  *
1557
- * @param params - Product update parameters (all content fields required)
1564
+ * @param params - Product update parameters (only `id` is required)
1558
1565
  * @returns Updated product detail
1559
1566
  *
1560
1567
  * @example
1568
+ * // Update only the name
1561
1569
  * const { product } = await client.subscriptionProducts.update({
1562
1570
  * id: "PROD_xxx",
1563
1571
  * name: "Pro Plan v2",
1564
- * billingPeriod: "monthly",
1565
- * prices: { USD: { amount: "14.99", taxCategory: "saas" } },
1572
+ * });
1573
+ *
1574
+ * @example
1575
+ * // Update prices and billing period
1576
+ * const { product } = await client.subscriptionProducts.update({
1577
+ * id: "PROD_xxx",
1578
+ * billingPeriod: "yearly",
1579
+ * prices: { USD: { amount: "99.00", taxCategory: "saas" } },
1566
1580
  * });
1567
1581
  */
1568
1582
  update(params: UpdateSubscriptionProductParams): Promise<{
package/dist/index.d.ts CHANGED
@@ -452,8 +452,8 @@ interface CreateOnetimeProductParams {
452
452
  */
453
453
  interface UpdateOnetimeProductParams {
454
454
  id: string;
455
- name: string;
456
- prices: Prices;
455
+ name?: string;
456
+ prices?: Prices;
457
457
  description?: string;
458
458
  media?: MediaItem[];
459
459
  successUrl?: string;
@@ -510,9 +510,9 @@ interface CreateSubscriptionProductParams {
510
510
  */
511
511
  interface UpdateSubscriptionProductParams {
512
512
  id: string;
513
- name: string;
514
- billingPeriod: BillingPeriod;
515
- prices: Prices;
513
+ name?: string;
514
+ billingPeriod?: BillingPeriod;
515
+ prices?: Prices;
516
516
  description?: string;
517
517
  media?: MediaItem[];
518
518
  successUrl?: string;
@@ -1312,13 +1312,20 @@ declare class OnetimeProductsResource {
1312
1312
  /**
1313
1313
  * Update a one-time product. Creates a new version; skips if unchanged.
1314
1314
  *
1315
- * @param params - Product update parameters (all content fields required)
1315
+ * @param params - Product update parameters (only `id` is required)
1316
1316
  * @returns Updated product detail
1317
1317
  *
1318
1318
  * @example
1319
+ * // Update only the name
1319
1320
  * const { product } = await client.onetimeProducts.update({
1320
1321
  * id: "PROD_xxx",
1321
1322
  * name: "E-Book v2",
1323
+ * });
1324
+ *
1325
+ * @example
1326
+ * // Update prices while preserving other fields
1327
+ * const { product } = await client.onetimeProducts.update({
1328
+ * id: "PROD_xxx",
1322
1329
  * prices: { USD: { amount: "39.00", taxCategory: "digital_goods" } },
1323
1330
  * });
1324
1331
  */
@@ -1554,15 +1561,22 @@ declare class SubscriptionProductsResource {
1554
1561
  /**
1555
1562
  * Update a subscription product. Creates a new version; skips if unchanged.
1556
1563
  *
1557
- * @param params - Product update parameters (all content fields required)
1564
+ * @param params - Product update parameters (only `id` is required)
1558
1565
  * @returns Updated product detail
1559
1566
  *
1560
1567
  * @example
1568
+ * // Update only the name
1561
1569
  * const { product } = await client.subscriptionProducts.update({
1562
1570
  * id: "PROD_xxx",
1563
1571
  * name: "Pro Plan v2",
1564
- * billingPeriod: "monthly",
1565
- * prices: { USD: { amount: "14.99", taxCategory: "saas" } },
1572
+ * });
1573
+ *
1574
+ * @example
1575
+ * // Update prices and billing period
1576
+ * const { product } = await client.subscriptionProducts.update({
1577
+ * id: "PROD_xxx",
1578
+ * billingPeriod: "yearly",
1579
+ * prices: { USD: { amount: "99.00", taxCategory: "saas" } },
1566
1580
  * });
1567
1581
  */
1568
1582
  update(params: UpdateSubscriptionProductParams): Promise<{
package/dist/index.js CHANGED
@@ -20,7 +20,7 @@ var BuyerHttpClient = class {
20
20
  constructor(token, config) {
21
21
  this.token = token;
22
22
  this.baseUrl = (config.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
23
- this._fetch = config.fetch ?? fetch;
23
+ this._fetch = config.fetch ?? globalThis.fetch.bind(globalThis);
24
24
  }
25
25
  /**
26
26
  * Send a Bearer-authenticated POST request and return the parsed `data` field.
@@ -35,7 +35,7 @@ var BuyerHttpClient = class {
35
35
  method: "POST",
36
36
  headers: {
37
37
  "Content-Type": "application/json",
38
- "Authorization": `Bearer ${this.token}`
38
+ Authorization: `Bearer ${this.token}`
39
39
  },
40
40
  body: JSON.stringify(body)
41
41
  });
@@ -62,9 +62,7 @@ var PKCS1_PUB_HEADER = "-----BEGIN RSA PUBLIC KEY-----";
62
62
  var PKCS1_PUB_FOOTER = "-----END RSA PUBLIC KEY-----";
63
63
  function normalizePrivateKey(raw) {
64
64
  if (!raw || !raw.trim()) {
65
- throw new Error(
66
- "Private key is empty. Provide an RSA private key in PEM format."
67
- );
65
+ throw new Error("Private key is empty. Provide an RSA private key in PEM format.");
68
66
  }
69
67
  let pem = raw.replace(/\\n/g, "\n").replace(/\r\n/g, "\n");
70
68
  pem = pem.trim();
@@ -74,9 +72,7 @@ function normalizePrivateKey(raw) {
74
72
  if (hasHeader) {
75
73
  const base64 = pem.replace(/-----BEGIN (?:RSA )?PRIVATE KEY-----/g, "").replace(/-----END (?:RSA )?PRIVATE KEY-----/g, "").replace(/\s+/g, "");
76
74
  if (!base64) {
77
- throw new Error(
78
- "Private key contains PEM headers but no key data. Check the key content."
79
- );
75
+ throw new Error("Private key contains PEM headers but no key data. Check the key content.");
80
76
  }
81
77
  const header = hasPkcs1Header ? PKCS1_HEADER : PKCS8_HEADER;
82
78
  const footer = hasPkcs1Header ? PKCS1_FOOTER : PKCS8_FOOTER;
@@ -87,9 +83,7 @@ ${footer}`;
87
83
  } else {
88
84
  const base64 = pem.replace(/\s+/g, "");
89
85
  if (!/^[A-Za-z0-9+/]+=*$/.test(base64)) {
90
- throw new Error(
91
- "Private key is not valid PEM or base64. Expected an RSA private key in PEM format or raw base64."
92
- );
86
+ throw new Error("Private key is not valid PEM or base64. Expected an RSA private key in PEM format or raw base64.");
93
87
  }
94
88
  const wrapped = base64.match(/.{1,64}/g).join("\n");
95
89
  pem = `${PKCS8_HEADER}
@@ -99,17 +93,13 @@ ${PKCS8_FOOTER}`;
99
93
  try {
100
94
  createPrivateKey(pem);
101
95
  } catch {
102
- throw new Error(
103
- "Private key could not be parsed. Ensure it is a valid RSA private key in PKCS#8 or PKCS#1 (PEM) format."
104
- );
96
+ throw new Error("Private key could not be parsed. Ensure it is a valid RSA private key in PKCS#8 or PKCS#1 (PEM) format.");
105
97
  }
106
98
  return pem;
107
99
  }
108
100
  function normalizePublicKey(raw) {
109
101
  if (!raw || !raw.trim()) {
110
- throw new Error(
111
- "Public key is empty. Provide an RSA public key in PEM format."
112
- );
102
+ throw new Error("Public key is empty. Provide an RSA public key in PEM format.");
113
103
  }
114
104
  let pem = raw.replace(/\\n/g, "\n").replace(/\r\n/g, "\n");
115
105
  pem = pem.trim();
@@ -119,9 +109,7 @@ function normalizePublicKey(raw) {
119
109
  if (hasHeader) {
120
110
  const base64 = pem.replace(/-----BEGIN (?:RSA )?PUBLIC KEY-----/g, "").replace(/-----END (?:RSA )?PUBLIC KEY-----/g, "").replace(/\s+/g, "");
121
111
  if (!base64) {
122
- throw new Error(
123
- "Public key contains PEM headers but no key data. Check the key content."
124
- );
112
+ throw new Error("Public key contains PEM headers but no key data. Check the key content.");
125
113
  }
126
114
  const header = hasPkcs1PubHeader ? PKCS1_PUB_HEADER : SPKI_HEADER;
127
115
  const footer = hasPkcs1PubHeader ? PKCS1_PUB_FOOTER : SPKI_FOOTER;
@@ -132,9 +120,7 @@ ${footer}`;
132
120
  } else {
133
121
  const base64 = pem.replace(/\s+/g, "");
134
122
  if (!/^[A-Za-z0-9+/]+=*$/.test(base64)) {
135
- throw new Error(
136
- "Public key is not valid PEM or base64. Expected an RSA public key in PEM format or raw base64."
137
- );
123
+ throw new Error("Public key is not valid PEM or base64. Expected an RSA public key in PEM format or raw base64.");
138
124
  }
139
125
  const wrapped = base64.match(/.{1,64}/g).join("\n");
140
126
  pem = `${SPKI_HEADER}
@@ -144,9 +130,7 @@ ${SPKI_FOOTER}`;
144
130
  try {
145
131
  createPublicKey(pem);
146
132
  } catch {
147
- throw new Error(
148
- "Public key could not be parsed. Ensure it is a valid RSA public key in SPKI or PKCS#1 (PEM) format."
149
- );
133
+ throw new Error("Public key could not be parsed. Ensure it is a valid RSA public key in SPKI or PKCS#1 (PEM) format.");
150
134
  }
151
135
  return pem;
152
136
  }
@@ -172,7 +156,7 @@ var HttpClient = class {
172
156
  this.merchantId = config.merchantId;
173
157
  this.privateKey = normalizePrivateKey(config.privateKey);
174
158
  this.baseUrl = (config.baseUrl ?? DEFAULT_BASE_URL2).replace(/\/+$/, "");
175
- this._fetch = config.fetch ?? fetch;
159
+ this._fetch = config.fetch ?? globalThis.fetch.bind(globalThis);
176
160
  }
177
161
  /**
178
162
  * Send a signed POST request and return the parsed `data` field.
@@ -342,9 +326,7 @@ var AuthResource = class {
342
326
  */
343
327
  async issueSessionToken(params) {
344
328
  if (!params.storeId && !params.productId) {
345
- throw new WaffoPancakeError(400, [
346
- { message: "Missing required field: provide storeId or productId", layer: "sdk" }
347
- ]);
329
+ throw new WaffoPancakeError(400, [{ message: "Missing required field: provide storeId or productId", layer: "sdk" }]);
348
330
  }
349
331
  if (params.storeId) {
350
332
  validateShortId("storeId", params.storeId, "STO");
@@ -377,10 +359,7 @@ var BuyerSession = class {
377
359
  */
378
360
  async cancelSubscription(params) {
379
361
  validateShortId("orderId", params.orderId, "ORD");
380
- return this.http.post(
381
- "/v1/actions/subscription-order/cancel-order",
382
- params
383
- );
362
+ return this.http.post("/v1/actions/subscription-order/cancel-order", params);
384
363
  }
385
364
  /**
386
365
  * Cancel a one-time order (only while payment is still pending).
@@ -393,10 +372,7 @@ var BuyerSession = class {
393
372
  */
394
373
  async cancelOnetimeOrder(params) {
395
374
  validateShortId("orderId", params.orderId, "ORD");
396
- return this.http.post(
397
- "/v1/actions/onetime-order/cancel-order",
398
- params
399
- );
375
+ return this.http.post("/v1/actions/onetime-order/cancel-order", params);
400
376
  }
401
377
  /**
402
378
  * Reactivate a subscription that is in `canceling` status.
@@ -410,10 +386,7 @@ var BuyerSession = class {
410
386
  */
411
387
  async reactivateSubscription(params) {
412
388
  validateShortId("orderId", params.orderId, "ORD");
413
- return this.http.post(
414
- "/v1/actions/subscription-order/reactivate-order",
415
- params
416
- );
389
+ return this.http.post("/v1/actions/subscription-order/reactivate-order", params);
417
390
  }
418
391
  /**
419
392
  * Submit a refund request for a payment.
@@ -433,10 +406,7 @@ var BuyerSession = class {
433
406
  validateRequired("reason", params.reason);
434
407
  validateAmountString("requestedAmount.amount", params.requestedAmount.amount);
435
408
  validateCurrencyCode("requestedAmount.currency", params.requestedAmount.currency);
436
- return this.http.post(
437
- "/v1/actions/refund-ticket/create-ticket",
438
- params
439
- );
409
+ return this.http.post("/v1/actions/refund-ticket/create-ticket", params);
440
410
  }
441
411
  /**
442
412
  * Resubmit a previously rejected refund ticket with updated details.
@@ -458,10 +428,7 @@ var BuyerSession = class {
458
428
  validateRequired("reason", params.reason);
459
429
  validateAmountString("requestedAmount.amount", params.requestedAmount.amount);
460
430
  validateCurrencyCode("requestedAmount.currency", params.requestedAmount.currency);
461
- return this.http.post(
462
- "/v1/actions/refund-ticket/resubmit-ticket",
463
- params
464
- );
431
+ return this.http.post("/v1/actions/refund-ticket/resubmit-ticket", params);
465
432
  }
466
433
  };
467
434
  var BuyerGraphQL = class {
@@ -505,11 +472,7 @@ var CheckoutAnonymousResource = class {
505
472
  */
506
473
  async create(params) {
507
474
  validateCheckoutCommon(params);
508
- return this.http.post(
509
- "/v1/actions/checkout/create-session",
510
- params,
511
- { idempotencyWindow: 60 }
512
- );
475
+ return this.http.post("/v1/actions/checkout/create-session", params, { idempotencyWindow: 60 });
513
476
  }
514
477
  };
515
478
 
@@ -543,14 +506,22 @@ var CheckoutAuthenticatedResource = class {
543
506
  validateRequired("buyerIdentity", params.buyerIdentity);
544
507
  const { buyerIdentity, buyerEmail, ...sessionFields } = params;
545
508
  const [tokenResult, sessionResult] = await Promise.all([
546
- this.http.post("/v1/actions/auth/issue-session-token", {
547
- productId: params.productId,
548
- buyerIdentity
549
- }, { idempotencyWindow: 60 }),
550
- this.http.post("/v1/actions/checkout/create-session", {
551
- ...sessionFields,
552
- buyerEmail: buyerEmail ?? buyerIdentity
553
- }, { idempotencyWindow: 60 })
509
+ this.http.post(
510
+ "/v1/actions/auth/issue-session-token",
511
+ {
512
+ productId: params.productId,
513
+ buyerIdentity
514
+ },
515
+ { idempotencyWindow: 60 }
516
+ ),
517
+ this.http.post(
518
+ "/v1/actions/checkout/create-session",
519
+ {
520
+ ...sessionFields,
521
+ buyerEmail: buyerEmail ?? buyerIdentity
522
+ },
523
+ { idempotencyWindow: 60 }
524
+ )
554
525
  ]);
555
526
  return {
556
527
  sessionId: sessionResult.sessionId,
@@ -651,20 +622,27 @@ var OnetimeProductsResource = class {
651
622
  /**
652
623
  * Update a one-time product. Creates a new version; skips if unchanged.
653
624
  *
654
- * @param params - Product update parameters (all content fields required)
625
+ * @param params - Product update parameters (only `id` is required)
655
626
  * @returns Updated product detail
656
627
  *
657
628
  * @example
629
+ * // Update only the name
658
630
  * const { product } = await client.onetimeProducts.update({
659
631
  * id: "PROD_xxx",
660
632
  * name: "E-Book v2",
633
+ * });
634
+ *
635
+ * @example
636
+ * // Update prices while preserving other fields
637
+ * const { product } = await client.onetimeProducts.update({
638
+ * id: "PROD_xxx",
661
639
  * prices: { USD: { amount: "39.00", taxCategory: "digital_goods" } },
662
640
  * });
663
641
  */
664
642
  async update(params) {
665
643
  validateShortId("id", params.id, "PROD");
666
- validateRequired("name", params.name);
667
- validatePrices("prices", params.prices);
644
+ if (params.name !== void 0) validateRequired("name", params.name);
645
+ if (params.prices) validatePrices("prices", params.prices);
668
646
  return this.http.post("/v1/actions/onetime-product/update-product", params);
669
647
  }
670
648
  /**
@@ -933,22 +911,30 @@ var SubscriptionProductsResource = class {
933
911
  /**
934
912
  * Update a subscription product. Creates a new version; skips if unchanged.
935
913
  *
936
- * @param params - Product update parameters (all content fields required)
914
+ * @param params - Product update parameters (only `id` is required)
937
915
  * @returns Updated product detail
938
916
  *
939
917
  * @example
918
+ * // Update only the name
940
919
  * const { product } = await client.subscriptionProducts.update({
941
920
  * id: "PROD_xxx",
942
921
  * name: "Pro Plan v2",
943
- * billingPeriod: "monthly",
944
- * prices: { USD: { amount: "14.99", taxCategory: "saas" } },
922
+ * });
923
+ *
924
+ * @example
925
+ * // Update prices and billing period
926
+ * const { product } = await client.subscriptionProducts.update({
927
+ * id: "PROD_xxx",
928
+ * billingPeriod: "yearly",
929
+ * prices: { USD: { amount: "99.00", taxCategory: "saas" } },
945
930
  * });
946
931
  */
947
932
  async update(params) {
948
933
  validateShortId("id", params.id, "PROD");
949
- validateRequired("name", params.name);
950
- validateEnum("billingPeriod", params.billingPeriod, ["weekly", "monthly", "quarterly", "yearly"]);
951
- validatePrices("prices", params.prices);
934
+ if (params.name !== void 0) validateRequired("name", params.name);
935
+ if (params.billingPeriod !== void 0)
936
+ validateEnum("billingPeriod", params.billingPeriod, ["weekly", "monthly", "quarterly", "yearly"]);
937
+ if (params.prices) validatePrices("prices", params.prices);
952
938
  return this.http.post("/v1/actions/subscription-product/update-product", params);
953
939
  }
954
940
  /**