fresh-squeezy 0.1.13 → 0.1.15

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.cjs CHANGED
@@ -32,19 +32,32 @@ __export(src_exports, {
32
32
  SUPPORTED_RESOURCES: () => SUPPORTED_RESOURCES,
33
33
  buildResult: () => buildResult,
34
34
  buildSubscriptionItemUpdateBody: () => buildSubscriptionItemUpdateBody,
35
+ cancelSubscription: () => cancelSubscription,
35
36
  checkDiscount: () => checkDiscount,
36
37
  checkLicenseKey: () => checkLicenseKey,
37
38
  checkProduct: () => checkProduct,
38
39
  checkSubscriptionPlan: () => checkSubscriptionPlan,
40
+ createCheckout: () => createCheckout,
41
+ createCustomer: () => createCustomer,
42
+ createDiscount: () => createDiscount,
39
43
  createFreshSqueezy: () => createFreshSqueezy,
44
+ createUsageRecord: () => createUsageRecord,
45
+ createWebhook: () => createWebhook,
46
+ deleteDiscount: () => deleteDiscount,
47
+ deleteWebhook: () => deleteWebhook,
40
48
  doctor: () => doctor,
41
49
  fetchActualMode: () => fetchActualMode,
50
+ findResourceVerb: () => findResourceVerb,
51
+ generateOrderInvoice: () => generateOrderInvoice,
52
+ generateSubscriptionInvoice: () => generateSubscriptionInvoice,
42
53
  getAffiliate: () => getAffiliate,
43
54
  getAuthenticatedUser: () => getAuthenticatedUser,
44
55
  getCheckout: () => getCheckout,
45
56
  getCustomer: () => getCustomer,
57
+ getDiscount: () => getDiscount,
46
58
  getDiscountRedemption: () => getDiscountRedemption,
47
59
  getFile: () => getFile,
60
+ getLicenseKey: () => getLicenseKey,
48
61
  getLicenseKeyInstance: () => getLicenseKeyInstance,
49
62
  getOrder: () => getOrder,
50
63
  getOrderItem: () => getOrderItem,
@@ -54,27 +67,44 @@ __export(src_exports, {
54
67
  getSubscription: () => getSubscription,
55
68
  getSubscriptionInvoice: () => getSubscriptionInvoice,
56
69
  getSubscriptionItem: () => getSubscriptionItem,
70
+ getSubscriptionItemCurrentUsage: () => getSubscriptionItemCurrentUsage,
57
71
  getUsageRecord: () => getUsageRecord,
58
72
  getVariant: () => getVariant,
73
+ getWebhook: () => getWebhook,
74
+ invokeOp: () => invokeOp,
59
75
  isOk: () => isOk,
60
76
  issue: () => issue,
61
77
  listAffiliatesForStore: () => listAffiliatesForStore,
62
78
  listCheckoutsForStore: () => listCheckoutsForStore,
63
79
  listCustomersForStore: () => listCustomersForStore,
64
80
  listDiscountRedemptionsForDiscount: () => listDiscountRedemptionsForDiscount,
81
+ listDiscountsForStore: () => listDiscountsForStore,
65
82
  listFilesForVariant: () => listFilesForVariant,
66
83
  listLicenseKeyInstancesForLicenseKey: () => listLicenseKeyInstancesForLicenseKey,
84
+ listLicenseKeysForStore: () => listLicenseKeysForStore,
67
85
  listOrderItemsForOrder: () => listOrderItemsForOrder,
86
+ listOrdersForStore: () => listOrdersForStore,
87
+ listPricesForVariant: () => listPricesForVariant,
68
88
  listProducts: () => listProducts,
89
+ listRegisteredResources: () => listRegisteredResources,
69
90
  listStores: () => listStores,
70
91
  listSubscriptionInvoicesForSubscription: () => listSubscriptionInvoicesForSubscription,
71
92
  listSubscriptionItemsForSubscription: () => listSubscriptionItemsForSubscription,
93
+ listSubscriptionsForStore: () => listSubscriptionsForStore,
72
94
  listUsageRecordsForSubscriptionItem: () => listUsageRecordsForSubscriptionItem,
73
95
  listVariantsForProduct: () => listVariantsForProduct,
74
96
  listWebhooksForStore: () => listWebhooksForStore,
97
+ refundOrder: () => refundOrder,
98
+ refundSubscriptionInvoice: () => refundSubscriptionInvoice,
75
99
  resolveActualMode: () => resolveActualMode,
76
100
  resolveConfig: () => resolveConfig,
101
+ resourceRegistry: () => resourceRegistry,
77
102
  sameWebhookUrl: () => sameWebhookUrl,
103
+ updateCustomer: () => updateCustomer,
104
+ updateLicenseKey: () => updateLicenseKey,
105
+ updateSubscription: () => updateSubscription,
106
+ updateSubscriptionItem: () => updateSubscriptionItem,
107
+ updateWebhook: () => updateWebhook,
78
108
  userResource: () => userResource,
79
109
  validateConnection: () => validateConnection,
80
110
  validateDiscount: () => validateDiscount,
@@ -108,7 +138,7 @@ var ENV_KEYS = {
108
138
  storeId: "LEMON_SQUEEZY_STORE_ID",
109
139
  mode: "LEMON_SQUEEZY_MODE"
110
140
  };
111
- function resolveConfig(input = {}) {
141
+ var resolveConfig = (input = {}) => {
112
142
  const apiKey = input.apiKey ?? process.env[ENV_KEYS.apiKey];
113
143
  if (!apiKey) {
114
144
  throw new FreshSqueezyError({
@@ -125,14 +155,14 @@ function resolveConfig(input = {}) {
125
155
  baseUrl: input.baseUrl ?? DEFAULT_BASE_URL,
126
156
  fetch: input.fetch ?? globalThis.fetch
127
157
  };
128
- }
129
- function normalizeMode(value) {
158
+ };
159
+ var normalizeMode = (value) => {
130
160
  if (value === "test" || value === "live") return value;
131
161
  throw new FreshSqueezyError({
132
162
  code: "INVALID_MODE",
133
163
  message: `Mode must be "test" or "live", got "${value}".`
134
164
  });
135
- }
165
+ };
136
166
 
137
167
  // src/core/http.ts
138
168
  var HttpClient = class {
@@ -178,6 +208,37 @@ var HttpClient = class {
178
208
  const doc = await this.request({ path });
179
209
  return doc.data;
180
210
  }
211
+ /**
212
+ * POST a JSON:API document and return the created `data` resource.
213
+ *
214
+ * @param path - API path starting with `/v1/...`.
215
+ * @param body - JSON:API create document.
216
+ * @returns The created resource.
217
+ */
218
+ async postResource(path, body) {
219
+ const doc = await this.request({ method: "POST", path, body });
220
+ return doc.data;
221
+ }
222
+ /**
223
+ * PATCH a JSON:API document and return the updated `data` resource.
224
+ *
225
+ * @param path - API path starting with `/v1/...`.
226
+ * @param body - JSON:API update document.
227
+ * @returns The updated resource.
228
+ */
229
+ async patchResource(path, body) {
230
+ const doc = await this.request({ method: "PATCH", path, body });
231
+ return doc.data;
232
+ }
233
+ /**
234
+ * DELETE a resource. Lemon Squeezy often returns an empty body on success.
235
+ *
236
+ * @param path - API path starting with `/v1/...`.
237
+ * @returns Nothing — single void return, not a multi-field bag.
238
+ */
239
+ async deleteResource(path) {
240
+ await this.request({ method: "DELETE", path });
241
+ }
181
242
  /**
182
243
  * Fetch a single page of a JSON:API collection. Most callers want
183
244
  * `paginate()` instead — this method is kept for one-shot lookups where
@@ -225,51 +286,922 @@ var HttpClient = class {
225
286
  return url.toString();
226
287
  }
227
288
  };
228
- function safeJsonParse(text) {
289
+ var safeJsonParse = (text) => {
229
290
  try {
230
291
  return JSON.parse(text);
231
292
  } catch {
232
293
  return text;
233
294
  }
234
- }
235
- function toApiError(status, body) {
295
+ };
296
+ var toApiError = (status, body) => {
236
297
  const errors = extractJsonApiErrors(body);
237
298
  const first = errors[0];
238
299
  const code = status === 401 ? "UNAUTHORIZED" : status === 404 ? "NOT_FOUND" : status === 429 ? "RATE_LIMITED" : first?.code ?? `HTTP_${status}`;
239
300
  const message = first?.detail ?? first?.title ?? `Lemon Squeezy request failed with status ${status}`;
240
301
  return new FreshSqueezyError({ code, status, message, detail: body });
241
- }
242
- function extractJsonApiErrors(body) {
302
+ };
303
+ var extractJsonApiErrors = (body) => {
243
304
  if (!body || typeof body !== "object") return [];
244
305
  const errors = body.errors;
245
306
  if (!Array.isArray(errors)) return [];
246
307
  return errors.filter(
247
308
  (entry) => typeof entry === "object" && entry !== null
248
309
  );
249
- }
310
+ };
250
311
 
251
- // src/core/mode.ts
252
- function resolveActualMode(testMode) {
253
- if (testMode === true) return "test";
254
- if (testMode === false) return "live";
255
- return void 0;
256
- }
312
+ // src/resources/affiliates.ts
313
+ var getAffiliate = async (http, affiliateId) => {
314
+ return http.getResource(`/v1/affiliates/${affiliateId}`);
315
+ };
316
+ var listAffiliatesForStore = async (http, storeId) => {
317
+ return http.paginate("/v1/affiliates", {
318
+ "filter[store_id]": String(storeId)
319
+ });
320
+ };
321
+
322
+ // src/resources/checkouts.ts
323
+ var getCheckout = async (http, checkoutId) => {
324
+ return http.getResource(`/v1/checkouts/${checkoutId}`);
325
+ };
326
+ var listCheckoutsForStore = async (http, storeId) => {
327
+ return http.paginate("/v1/checkouts", {
328
+ "filter[store_id]": String(storeId)
329
+ });
330
+ };
331
+ var createCheckout = async (http, body) => {
332
+ return http.postResource("/v1/checkouts", body);
333
+ };
334
+
335
+ // src/resources/customers.ts
336
+ var getCustomer = async (http, customerId) => {
337
+ return http.getResource(`/v1/customers/${customerId}`);
338
+ };
339
+ var listCustomersForStore = async (http, storeId) => {
340
+ return http.paginate("/v1/customers", {
341
+ "filter[store_id]": String(storeId)
342
+ });
343
+ };
344
+ var createCustomer = async (http, body) => {
345
+ return http.postResource("/v1/customers", body);
346
+ };
347
+ var updateCustomer = async (http, customerId, body) => {
348
+ return http.patchResource(`/v1/customers/${customerId}`, body);
349
+ };
350
+
351
+ // src/resources/discountRedemptions.ts
352
+ var getDiscountRedemption = async (http, discountRedemptionId) => {
353
+ return http.getResource(
354
+ `/v1/discount-redemptions/${discountRedemptionId}`
355
+ );
356
+ };
357
+ var listDiscountRedemptionsForDiscount = async (http, discountId) => {
358
+ return http.paginate("/v1/discount-redemptions", {
359
+ "filter[discount_id]": String(discountId)
360
+ });
361
+ };
362
+
363
+ // src/resources/discounts.ts
364
+ var getDiscount = async (http, discountId) => {
365
+ return http.getResource(`/v1/discounts/${discountId}`);
366
+ };
367
+ var listDiscountsForStore = async (http, storeId) => {
368
+ return http.paginate("/v1/discounts", {
369
+ "filter[store_id]": String(storeId)
370
+ });
371
+ };
372
+ var createDiscount = async (http, body) => {
373
+ return http.postResource("/v1/discounts", body);
374
+ };
375
+ var deleteDiscount = async (http, discountId) => {
376
+ await http.deleteResource(`/v1/discounts/${discountId}`);
377
+ };
378
+
379
+ // src/resources/files.ts
380
+ var getFile = async (http, fileId) => {
381
+ return http.getResource(`/v1/files/${fileId}`);
382
+ };
383
+ var listFilesForVariant = async (http, variantId) => {
384
+ return http.paginate("/v1/files", {
385
+ "filter[variant_id]": String(variantId)
386
+ });
387
+ };
388
+
389
+ // src/resources/licenseKeyInstances.ts
390
+ var getLicenseKeyInstance = async (http, licenseKeyInstanceId) => {
391
+ return http.getResource(
392
+ `/v1/license-key-instances/${licenseKeyInstanceId}`
393
+ );
394
+ };
395
+ var listLicenseKeyInstancesForLicenseKey = async (http, licenseKeyId) => {
396
+ return http.paginate("/v1/license-key-instances", {
397
+ "filter[license_key_id]": String(licenseKeyId)
398
+ });
399
+ };
400
+
401
+ // src/resources/licenseKeys.ts
402
+ var getLicenseKey = async (http, licenseKeyId) => {
403
+ return http.getResource(`/v1/license-keys/${licenseKeyId}`);
404
+ };
405
+ var listLicenseKeysForStore = async (http, storeId) => {
406
+ return http.paginate("/v1/license-keys", {
407
+ "filter[store_id]": String(storeId)
408
+ });
409
+ };
410
+ var updateLicenseKey = async (http, licenseKeyId, body) => {
411
+ return http.patchResource(`/v1/license-keys/${licenseKeyId}`, body);
412
+ };
413
+
414
+ // src/resources/orderItems.ts
415
+ var getOrderItem = async (http, orderItemId) => {
416
+ return http.getResource(`/v1/order-items/${orderItemId}`);
417
+ };
418
+ var listOrderItemsForOrder = async (http, orderId) => {
419
+ return http.paginate("/v1/order-items", {
420
+ "filter[order_id]": String(orderId)
421
+ });
422
+ };
423
+
424
+ // src/resources/orders.ts
425
+ var getOrder = async (http, orderId) => {
426
+ return http.getResource(`/v1/orders/${orderId}`);
427
+ };
428
+ var listOrdersForStore = async (http, storeId) => {
429
+ return http.paginate("/v1/orders", {
430
+ "filter[store_id]": String(storeId)
431
+ });
432
+ };
433
+ var refundOrder = async (http, orderId, body) => {
434
+ return http.postResource(`/v1/orders/${orderId}/refund`, body ?? {});
435
+ };
436
+ var generateOrderInvoice = async (http, orderId, body) => {
437
+ return http.request({
438
+ method: "POST",
439
+ path: `/v1/orders/${orderId}/generate-invoice`,
440
+ body: body ?? {}
441
+ });
442
+ };
443
+
444
+ // src/resources/prices.ts
445
+ var getPrice = async (http, priceId) => {
446
+ return http.getResource(`/v1/prices/${priceId}`);
447
+ };
448
+ var listPricesForVariant = async (http, variantId) => {
449
+ return http.paginate("/v1/prices", {
450
+ "filter[variant_id]": String(variantId)
451
+ });
452
+ };
453
+
454
+ // src/resources/products.ts
455
+ var getProduct = async (http, productId) => {
456
+ return http.getResource(`/v1/products/${productId}`);
457
+ };
458
+ var listProducts = async (http, storeId) => {
459
+ return http.paginate("/v1/products", {
460
+ "filter[store_id]": String(storeId)
461
+ });
462
+ };
463
+
464
+ // src/resources/registry.ts
465
+ var resourceRegistry = [
466
+ // users
467
+ { resource: "user", verb: "get", docsPath: "users/retrieve-user", body: "none", idRole: "none" },
468
+ // stores (read-only)
469
+ { resource: "store", verb: "get", docsPath: "stores/retrieve-store", body: "none", idRole: "id" },
470
+ {
471
+ resource: "store",
472
+ verb: "list",
473
+ docsPath: "stores/list-all-stores",
474
+ body: "none",
475
+ idRole: "none"
476
+ },
477
+ // products (read-only)
478
+ {
479
+ resource: "product",
480
+ verb: "get",
481
+ docsPath: "products/retrieve-product",
482
+ body: "none",
483
+ idRole: "id"
484
+ },
485
+ {
486
+ resource: "product",
487
+ verb: "list",
488
+ docsPath: "products/list-all-products",
489
+ body: "none",
490
+ idRole: "store"
491
+ },
492
+ // variants (read-only)
493
+ {
494
+ resource: "variant",
495
+ verb: "get",
496
+ docsPath: "variants/retrieve-variant",
497
+ body: "none",
498
+ idRole: "id"
499
+ },
500
+ {
501
+ resource: "variant",
502
+ verb: "list",
503
+ docsPath: "variants/list-all-variants",
504
+ body: "none",
505
+ idRole: "parent"
506
+ },
507
+ // prices (read-only)
508
+ { resource: "price", verb: "get", docsPath: "prices/retrieve-price", body: "none", idRole: "id" },
509
+ {
510
+ resource: "price",
511
+ verb: "list",
512
+ docsPath: "prices/list-all-prices",
513
+ body: "none",
514
+ idRole: "parent"
515
+ },
516
+ // files (read-only)
517
+ { resource: "file", verb: "get", docsPath: "files/retrieve-file", body: "none", idRole: "id" },
518
+ {
519
+ resource: "file",
520
+ verb: "list",
521
+ docsPath: "files/list-all-files",
522
+ body: "none",
523
+ idRole: "parent"
524
+ },
525
+ // customers
526
+ {
527
+ resource: "customer",
528
+ verb: "get",
529
+ docsPath: "customers/retrieve-customer",
530
+ body: "none",
531
+ idRole: "id"
532
+ },
533
+ {
534
+ resource: "customer",
535
+ verb: "list",
536
+ docsPath: "customers/list-all-customers",
537
+ body: "none",
538
+ idRole: "store"
539
+ },
540
+ {
541
+ resource: "customer",
542
+ verb: "create",
543
+ docsPath: "customers/create-customer",
544
+ body: "required",
545
+ idRole: "none"
546
+ },
547
+ {
548
+ resource: "customer",
549
+ verb: "update",
550
+ docsPath: "customers/update-customer",
551
+ body: "required",
552
+ idRole: "id"
553
+ },
554
+ // orders
555
+ { resource: "order", verb: "get", docsPath: "orders/retrieve-order", body: "none", idRole: "id" },
556
+ {
557
+ resource: "order",
558
+ verb: "list",
559
+ docsPath: "orders/list-all-orders",
560
+ body: "none",
561
+ idRole: "store"
562
+ },
563
+ {
564
+ resource: "order",
565
+ verb: "refund",
566
+ docsPath: "orders/issue-refund",
567
+ body: "optional",
568
+ destructive: true,
569
+ idRole: "id"
570
+ },
571
+ {
572
+ resource: "order",
573
+ verb: "generate-invoice",
574
+ docsPath: "orders/generate-order-invoice",
575
+ body: "optional",
576
+ idRole: "id"
577
+ },
578
+ // order-items (read-only)
579
+ {
580
+ resource: "order-item",
581
+ verb: "get",
582
+ docsPath: "order-items/retrieve-order-item",
583
+ body: "none",
584
+ idRole: "id"
585
+ },
586
+ {
587
+ resource: "order-item",
588
+ verb: "list",
589
+ docsPath: "order-items/list-all-order-items",
590
+ body: "none",
591
+ idRole: "parent"
592
+ },
593
+ // subscriptions
594
+ {
595
+ resource: "subscription",
596
+ verb: "get",
597
+ docsPath: "subscriptions/retrieve-subscription",
598
+ body: "none",
599
+ idRole: "id"
600
+ },
601
+ {
602
+ resource: "subscription",
603
+ verb: "list",
604
+ docsPath: "subscriptions/list-all-subscriptions",
605
+ body: "none",
606
+ idRole: "store"
607
+ },
608
+ {
609
+ resource: "subscription",
610
+ verb: "update",
611
+ docsPath: "subscriptions/update-subscription",
612
+ body: "required",
613
+ idRole: "id"
614
+ },
615
+ {
616
+ resource: "subscription",
617
+ verb: "cancel",
618
+ docsPath: "subscriptions/cancel-subscription",
619
+ body: "none",
620
+ destructive: true,
621
+ idRole: "id"
622
+ },
623
+ // subscription-items
624
+ {
625
+ resource: "subscription-item",
626
+ verb: "get",
627
+ docsPath: "subscription-items/retrieve-subscription-item",
628
+ body: "none",
629
+ idRole: "id"
630
+ },
631
+ {
632
+ resource: "subscription-item",
633
+ verb: "list",
634
+ docsPath: "subscription-items/list-all-subscription-items",
635
+ body: "none",
636
+ idRole: "parent"
637
+ },
638
+ {
639
+ resource: "subscription-item",
640
+ verb: "update",
641
+ docsPath: "subscription-items/update-subscription-item",
642
+ body: "required",
643
+ idRole: "id"
644
+ },
645
+ {
646
+ resource: "subscription-item",
647
+ verb: "current-usage",
648
+ docsPath: "subscription-items/retrieve-subscription-item-current-usage",
649
+ body: "none",
650
+ idRole: "id"
651
+ },
652
+ // subscription-invoices
653
+ {
654
+ resource: "subscription-invoice",
655
+ verb: "get",
656
+ docsPath: "subscription-invoices/retrieve-subscription-invoice",
657
+ body: "none",
658
+ idRole: "id"
659
+ },
660
+ {
661
+ resource: "subscription-invoice",
662
+ verb: "list",
663
+ docsPath: "subscription-invoices/list-all-subscription-invoices",
664
+ body: "none",
665
+ idRole: "parent"
666
+ },
667
+ {
668
+ resource: "subscription-invoice",
669
+ verb: "refund",
670
+ docsPath: "subscription-invoices/issue-refund",
671
+ body: "optional",
672
+ destructive: true,
673
+ idRole: "id"
674
+ },
675
+ {
676
+ resource: "subscription-invoice",
677
+ verb: "generate-invoice",
678
+ docsPath: "subscription-invoices/generate-subscription-invoice",
679
+ body: "optional",
680
+ idRole: "id"
681
+ },
682
+ // usage-records
683
+ {
684
+ resource: "usage-record",
685
+ verb: "get",
686
+ docsPath: "usage-records/retrieve-usage-record",
687
+ body: "none",
688
+ idRole: "id"
689
+ },
690
+ {
691
+ resource: "usage-record",
692
+ verb: "list",
693
+ docsPath: "usage-records/list-all-usage-records",
694
+ body: "none",
695
+ idRole: "parent"
696
+ },
697
+ {
698
+ resource: "usage-record",
699
+ verb: "create",
700
+ docsPath: "usage-records/create-usage-record",
701
+ body: "required",
702
+ idRole: "none"
703
+ },
704
+ // discounts
705
+ {
706
+ resource: "discount",
707
+ verb: "get",
708
+ docsPath: "discounts/retrieve-discount",
709
+ body: "none",
710
+ idRole: "id"
711
+ },
712
+ {
713
+ resource: "discount",
714
+ verb: "list",
715
+ docsPath: "discounts/list-all-discounts",
716
+ body: "none",
717
+ idRole: "store"
718
+ },
719
+ {
720
+ resource: "discount",
721
+ verb: "create",
722
+ docsPath: "discounts/create-discount",
723
+ body: "required",
724
+ idRole: "none"
725
+ },
726
+ {
727
+ resource: "discount",
728
+ verb: "delete",
729
+ docsPath: "discounts/delete-discount",
730
+ body: "none",
731
+ destructive: true,
732
+ idRole: "id"
733
+ },
734
+ // discount-redemptions (read-only)
735
+ {
736
+ resource: "discount-redemption",
737
+ verb: "get",
738
+ docsPath: "discount-redemptions/retrieve-discount-redemption",
739
+ body: "none",
740
+ idRole: "id"
741
+ },
742
+ {
743
+ resource: "discount-redemption",
744
+ verb: "list",
745
+ docsPath: "discount-redemptions/list-all-discount-redemptions",
746
+ body: "none",
747
+ idRole: "parent"
748
+ },
749
+ // license-keys
750
+ {
751
+ resource: "license-key",
752
+ verb: "get",
753
+ docsPath: "license-keys/retrieve-license-key",
754
+ body: "none",
755
+ idRole: "id"
756
+ },
757
+ {
758
+ resource: "license-key",
759
+ verb: "list",
760
+ docsPath: "license-keys/list-all-license-keys",
761
+ body: "none",
762
+ idRole: "store"
763
+ },
764
+ {
765
+ resource: "license-key",
766
+ verb: "update",
767
+ docsPath: "license-keys/update-license-key",
768
+ body: "required",
769
+ idRole: "id"
770
+ },
771
+ // license-key-instances (read-only)
772
+ {
773
+ resource: "license-key-instance",
774
+ verb: "get",
775
+ docsPath: "license-key-instances/retrieve-license-key-instance",
776
+ body: "none",
777
+ idRole: "id"
778
+ },
779
+ {
780
+ resource: "license-key-instance",
781
+ verb: "list",
782
+ docsPath: "license-key-instances/list-all-license-key-instances",
783
+ body: "none",
784
+ idRole: "parent"
785
+ },
786
+ // checkouts
787
+ {
788
+ resource: "checkout",
789
+ verb: "get",
790
+ docsPath: "checkouts/retrieve-checkout",
791
+ body: "none",
792
+ idRole: "id"
793
+ },
794
+ {
795
+ resource: "checkout",
796
+ verb: "list",
797
+ docsPath: "checkouts/list-all-checkouts",
798
+ body: "none",
799
+ idRole: "store"
800
+ },
801
+ {
802
+ resource: "checkout",
803
+ verb: "create",
804
+ docsPath: "checkouts/create-checkout",
805
+ body: "required",
806
+ idRole: "none"
807
+ },
808
+ // webhooks
809
+ {
810
+ resource: "webhook",
811
+ verb: "get",
812
+ docsPath: "webhooks/retrieve-webhook",
813
+ body: "none",
814
+ idRole: "id"
815
+ },
816
+ {
817
+ resource: "webhook",
818
+ verb: "list",
819
+ docsPath: "webhooks/list-all-webhooks",
820
+ body: "none",
821
+ idRole: "store"
822
+ },
823
+ {
824
+ resource: "webhook",
825
+ verb: "create",
826
+ docsPath: "webhooks/create-webhook",
827
+ body: "required",
828
+ idRole: "none"
829
+ },
830
+ {
831
+ resource: "webhook",
832
+ verb: "update",
833
+ docsPath: "webhooks/update-webhook",
834
+ body: "required",
835
+ idRole: "id"
836
+ },
837
+ {
838
+ resource: "webhook",
839
+ verb: "delete",
840
+ docsPath: "webhooks/delete-webhook",
841
+ body: "none",
842
+ destructive: true,
843
+ idRole: "id"
844
+ },
845
+ // affiliates (read-only)
846
+ {
847
+ resource: "affiliate",
848
+ verb: "get",
849
+ docsPath: "affiliates/retrieve-affiliate",
850
+ body: "none",
851
+ idRole: "id"
852
+ },
853
+ {
854
+ resource: "affiliate",
855
+ verb: "list",
856
+ docsPath: "affiliates/list-all-affiliates",
857
+ body: "none",
858
+ idRole: "store"
859
+ }
860
+ ];
861
+ var findResourceVerb = (resource, verb) => {
862
+ const normalized = resource.replace(/_/g, "-").toLowerCase();
863
+ const singular = normalized.endsWith("s") && normalized !== "status" ? normalized.slice(0, -1) : normalized;
864
+ const aliases = {
865
+ products: "product",
866
+ stores: "store",
867
+ customers: "customer",
868
+ orders: "order",
869
+ "order-items": "order-item",
870
+ subscriptions: "subscription",
871
+ "subscription-items": "subscription-item",
872
+ "subscription-invoices": "subscription-invoice",
873
+ "usage-records": "usage-record",
874
+ discounts: "discount",
875
+ "discount-redemptions": "discount-redemption",
876
+ "license-keys": "license-key",
877
+ "license-key-instances": "license-key-instance",
878
+ checkouts: "checkout",
879
+ webhooks: "webhook",
880
+ affiliates: "affiliate",
881
+ variants: "variant",
882
+ prices: "price",
883
+ files: "file",
884
+ users: "user"
885
+ };
886
+ const key = aliases[normalized] ?? singular;
887
+ return resourceRegistry.find((entry) => entry.resource === key && entry.verb === verb);
888
+ };
889
+ var listRegisteredResources = () => {
890
+ return [...new Set(resourceRegistry.map((entry) => entry.resource))].sort();
891
+ };
257
892
 
258
893
  // src/resources/stores.ts
259
- async function getStore(http, storeId) {
894
+ var getStore = async (http, storeId) => {
260
895
  return http.getResource(`/v1/stores/${storeId}`);
261
- }
262
- async function listStores(http) {
896
+ };
897
+ var listStores = async (http) => {
263
898
  return http.paginate("/v1/stores");
264
- }
899
+ };
900
+
901
+ // src/resources/subscriptionInvoices.ts
902
+ var getSubscriptionInvoice = async (http, subscriptionInvoiceId) => {
903
+ return http.getResource(
904
+ `/v1/subscription-invoices/${subscriptionInvoiceId}`
905
+ );
906
+ };
907
+ var listSubscriptionInvoicesForSubscription = async (http, subscriptionId) => {
908
+ return http.paginate("/v1/subscription-invoices", {
909
+ "filter[subscription_id]": String(subscriptionId)
910
+ });
911
+ };
912
+ var refundSubscriptionInvoice = async (http, subscriptionInvoiceId, body) => {
913
+ return http.postResource(
914
+ `/v1/subscription-invoices/${subscriptionInvoiceId}/refund`,
915
+ body ?? {}
916
+ );
917
+ };
918
+ var generateSubscriptionInvoice = async (http, subscriptionInvoiceId, body) => {
919
+ return http.request({
920
+ method: "POST",
921
+ path: `/v1/subscription-invoices/${subscriptionInvoiceId}/generate-invoice`,
922
+ body: body ?? {}
923
+ });
924
+ };
925
+
926
+ // src/resources/subscriptionItems.ts
927
+ var getSubscriptionItem = async (http, subscriptionItemId) => {
928
+ return http.getResource(
929
+ `/v1/subscription-items/${subscriptionItemId}`
930
+ );
931
+ };
932
+ var listSubscriptionItemsForSubscription = async (http, subscriptionId) => {
933
+ return http.paginate("/v1/subscription-items", {
934
+ "filter[subscription_id]": String(subscriptionId)
935
+ });
936
+ };
937
+ var buildSubscriptionItemUpdateBody = (subscriptionItemId, attributes) => {
938
+ return {
939
+ data: {
940
+ type: "subscription-items",
941
+ id: String(subscriptionItemId),
942
+ attributes
943
+ }
944
+ };
945
+ };
946
+ var updateSubscriptionItem = async (http, subscriptionItemId, body) => {
947
+ return http.patchResource(
948
+ `/v1/subscription-items/${subscriptionItemId}`,
949
+ body
950
+ );
951
+ };
952
+ var getSubscriptionItemCurrentUsage = async (http, subscriptionItemId) => {
953
+ return http.request({
954
+ path: `/v1/subscription-items/${subscriptionItemId}/current-usage`
955
+ });
956
+ };
957
+
958
+ // src/resources/subscriptions.ts
959
+ var getSubscription = async (http, subscriptionId) => {
960
+ return http.getResource(`/v1/subscriptions/${subscriptionId}`);
961
+ };
962
+ var listSubscriptionsForStore = async (http, storeId) => {
963
+ return http.paginate("/v1/subscriptions", {
964
+ "filter[store_id]": String(storeId)
965
+ });
966
+ };
967
+ var updateSubscription = async (http, subscriptionId, body) => {
968
+ return http.patchResource(`/v1/subscriptions/${subscriptionId}`, body);
969
+ };
970
+ var cancelSubscription = async (http, subscriptionId) => {
971
+ const doc = await http.request({
972
+ method: "DELETE",
973
+ path: `/v1/subscriptions/${subscriptionId}`
974
+ });
975
+ return doc?.data;
976
+ };
977
+
978
+ // src/resources/usageRecords.ts
979
+ var getUsageRecord = async (http, usageRecordId) => {
980
+ return http.getResource(`/v1/usage-records/${usageRecordId}`);
981
+ };
982
+ var listUsageRecordsForSubscriptionItem = async (http, subscriptionItemId) => {
983
+ return http.paginate("/v1/usage-records", {
984
+ "filter[subscription_item_id]": String(subscriptionItemId)
985
+ });
986
+ };
987
+ var createUsageRecord = async (http, body) => {
988
+ return http.postResource("/v1/usage-records", body);
989
+ };
265
990
 
266
991
  // src/resources/users.ts
267
- async function getAuthenticatedUser(http) {
992
+ var getAuthenticatedUser = async (http) => {
268
993
  return http.request({ path: "/v1/users/me" });
269
- }
270
- function userResource(doc) {
994
+ };
995
+ var userResource = (doc) => {
271
996
  return doc.data;
272
- }
997
+ };
998
+
999
+ // src/resources/variants.ts
1000
+ var getVariant = async (http, variantId) => {
1001
+ return http.getResource(`/v1/variants/${variantId}`);
1002
+ };
1003
+ var listVariantsForProduct = async (http, productId) => {
1004
+ return http.paginate("/v1/variants", {
1005
+ "filter[product_id]": String(productId)
1006
+ });
1007
+ };
1008
+
1009
+ // src/resources/webhooks.ts
1010
+ var getWebhook = async (http, webhookId) => {
1011
+ return http.getResource(`/v1/webhooks/${webhookId}`);
1012
+ };
1013
+ var listWebhooksForStore = async (http, storeId) => {
1014
+ return http.paginate("/v1/webhooks", {
1015
+ "filter[store_id]": String(storeId)
1016
+ });
1017
+ };
1018
+ var createWebhook = async (http, body) => {
1019
+ return http.postResource("/v1/webhooks", body);
1020
+ };
1021
+ var updateWebhook = async (http, webhookId, body) => {
1022
+ return http.patchResource(`/v1/webhooks/${webhookId}`, body);
1023
+ };
1024
+ var deleteWebhook = async (http, webhookId) => {
1025
+ await http.deleteResource(`/v1/webhooks/${webhookId}`);
1026
+ };
1027
+
1028
+ // src/resources/invokeOp.ts
1029
+ var invokeOp = async (http, resource, verb, args = {}) => {
1030
+ const spec = findResourceVerb(resource, verb);
1031
+ if (!spec) {
1032
+ throw new FreshSqueezyError({
1033
+ code: "UNKNOWN_OP",
1034
+ message: `Unknown or unsupported op: ${verb} ${resource}. Run \`fresh-squeezy ops --list\`.`
1035
+ });
1036
+ }
1037
+ const key = `${spec.resource}:${spec.verb}`;
1038
+ switch (key) {
1039
+ case "user:get":
1040
+ return userResource(await getAuthenticatedUser(http));
1041
+ case "store:get":
1042
+ return getStore(http, requireId(args, "store"));
1043
+ case "store:list":
1044
+ return listStores(http);
1045
+ case "product:get":
1046
+ return getProduct(http, requireId(args, "product"));
1047
+ case "product:list":
1048
+ return listProducts(http, requireStore(args));
1049
+ case "variant:get":
1050
+ return getVariant(http, requireId(args, "variant"));
1051
+ case "variant:list":
1052
+ return listVariantsForProduct(http, requireParent(args, "product"));
1053
+ case "price:get":
1054
+ return getPrice(http, requireId(args, "price"));
1055
+ case "price:list":
1056
+ return listPricesForVariant(http, requireParent(args, "variant"));
1057
+ case "file:get":
1058
+ return getFile(http, requireId(args, "file"));
1059
+ case "file:list":
1060
+ return listFilesForVariant(http, requireParent(args, "variant"));
1061
+ case "customer:get":
1062
+ return getCustomer(http, requireId(args, "customer"));
1063
+ case "customer:list":
1064
+ return listCustomersForStore(http, requireStore(args));
1065
+ case "customer:create":
1066
+ return createCustomer(http, requireBody(args));
1067
+ case "customer:update":
1068
+ return updateCustomer(http, requireId(args, "customer"), requireBody(args));
1069
+ case "order:get":
1070
+ return getOrder(http, requireId(args, "order"));
1071
+ case "order:list":
1072
+ return listOrdersForStore(http, requireStore(args));
1073
+ case "order:refund":
1074
+ return refundOrder(http, requireId(args, "order"), args.body);
1075
+ case "order:generate-invoice":
1076
+ return generateOrderInvoice(http, requireId(args, "order"), args.body);
1077
+ case "order-item:get":
1078
+ return getOrderItem(http, requireId(args, "order-item"));
1079
+ case "order-item:list":
1080
+ return listOrderItemsForOrder(http, requireParent(args, "order"));
1081
+ case "subscription:get":
1082
+ return getSubscription(http, requireId(args, "subscription"));
1083
+ case "subscription:list":
1084
+ return listSubscriptionsForStore(http, requireStore(args));
1085
+ case "subscription:update":
1086
+ return updateSubscription(http, requireId(args, "subscription"), requireBody(args));
1087
+ case "subscription:cancel":
1088
+ return cancelSubscription(http, requireId(args, "subscription"));
1089
+ case "subscription-item:get":
1090
+ return getSubscriptionItem(http, requireId(args, "subscription-item"));
1091
+ case "subscription-item:list":
1092
+ return listSubscriptionItemsForSubscription(http, requireParent(args, "subscription"));
1093
+ case "subscription-item:update":
1094
+ return updateSubscriptionItem(http, requireId(args, "subscription-item"), requireBody(args));
1095
+ case "subscription-item:current-usage":
1096
+ return getSubscriptionItemCurrentUsage(http, requireId(args, "subscription-item"));
1097
+ case "subscription-invoice:get":
1098
+ return getSubscriptionInvoice(http, requireId(args, "subscription-invoice"));
1099
+ case "subscription-invoice:list":
1100
+ return listSubscriptionInvoicesForSubscription(http, requireParent(args, "subscription"));
1101
+ case "subscription-invoice:refund":
1102
+ return refundSubscriptionInvoice(http, requireId(args, "subscription-invoice"), args.body);
1103
+ case "subscription-invoice:generate-invoice":
1104
+ return generateSubscriptionInvoice(http, requireId(args, "subscription-invoice"), args.body);
1105
+ case "usage-record:get":
1106
+ return getUsageRecord(http, requireId(args, "usage-record"));
1107
+ case "usage-record:list":
1108
+ return listUsageRecordsForSubscriptionItem(http, requireParent(args, "subscription-item"));
1109
+ case "usage-record:create":
1110
+ return createUsageRecord(http, requireBody(args));
1111
+ case "discount:get":
1112
+ return getDiscount(http, requireId(args, "discount"));
1113
+ case "discount:list":
1114
+ return listDiscountsForStore(http, requireStore(args));
1115
+ case "discount:create":
1116
+ return createDiscount(http, requireBody(args));
1117
+ case "discount:delete":
1118
+ await deleteDiscount(http, requireId(args, "discount"));
1119
+ return void 0;
1120
+ case "discount-redemption:get":
1121
+ return getDiscountRedemption(http, requireId(args, "discount-redemption"));
1122
+ case "discount-redemption:list":
1123
+ return listDiscountRedemptionsForDiscount(http, requireParent(args, "discount"));
1124
+ case "license-key:get":
1125
+ return getLicenseKey(http, requireId(args, "license-key"));
1126
+ case "license-key:list":
1127
+ return listLicenseKeysForStore(http, requireStore(args));
1128
+ case "license-key:update":
1129
+ return updateLicenseKey(http, requireId(args, "license-key"), requireBody(args));
1130
+ case "license-key-instance:get":
1131
+ return getLicenseKeyInstance(http, requireId(args, "license-key-instance"));
1132
+ case "license-key-instance:list":
1133
+ return listLicenseKeyInstancesForLicenseKey(http, requireParent(args, "license-key"));
1134
+ case "checkout:get":
1135
+ return getCheckout(http, requireId(args, "checkout"));
1136
+ case "checkout:list":
1137
+ return listCheckoutsForStore(http, requireStore(args));
1138
+ case "checkout:create":
1139
+ return createCheckout(http, requireBody(args));
1140
+ case "webhook:get":
1141
+ return getWebhook(http, requireId(args, "webhook"));
1142
+ case "webhook:list":
1143
+ return listWebhooksForStore(http, requireStore(args));
1144
+ case "webhook:create":
1145
+ return createWebhook(http, requireBody(args));
1146
+ case "webhook:update":
1147
+ return updateWebhook(http, requireId(args, "webhook"), requireBody(args));
1148
+ case "webhook:delete":
1149
+ await deleteWebhook(http, requireId(args, "webhook"));
1150
+ return void 0;
1151
+ case "affiliate:get":
1152
+ return getAffiliate(http, requireId(args, "affiliate"));
1153
+ case "affiliate:list":
1154
+ return listAffiliatesForStore(http, requireStore(args));
1155
+ default:
1156
+ throw new FreshSqueezyError({
1157
+ code: "UNKNOWN_OP",
1158
+ message: `Op registered but not wired: ${key}`
1159
+ });
1160
+ }
1161
+ };
1162
+ var requireId = (args, label) => {
1163
+ if (args.id === void 0 || args.id === "") {
1164
+ throw new FreshSqueezyError({
1165
+ code: "MISSING_ARG",
1166
+ message: `--id is required for this ${label} operation.`
1167
+ });
1168
+ }
1169
+ return args.id;
1170
+ };
1171
+ var requireStore = (args) => {
1172
+ if (args.storeId === void 0 || args.storeId === "") {
1173
+ throw new FreshSqueezyError({
1174
+ code: "MISSING_ARG",
1175
+ message: "--store-ids (or store id) is required for this list operation."
1176
+ });
1177
+ }
1178
+ return args.storeId;
1179
+ };
1180
+ var requireParent = (args, label) => {
1181
+ if (args.parentId === void 0 || args.parentId === "") {
1182
+ throw new FreshSqueezyError({
1183
+ code: "MISSING_ARG",
1184
+ message: `--parent-id (${label} id) is required for this list operation.`
1185
+ });
1186
+ }
1187
+ return args.parentId;
1188
+ };
1189
+ var requireBody = (args) => {
1190
+ if (args.body === void 0) {
1191
+ throw new FreshSqueezyError({
1192
+ code: "MISSING_ARG",
1193
+ message: "A JSON body is required (--body, --body-file, or stdin)."
1194
+ });
1195
+ }
1196
+ return args.body;
1197
+ };
1198
+
1199
+ // src/core/mode.ts
1200
+ var resolveActualMode = (testMode) => {
1201
+ if (testMode === true) return "test";
1202
+ if (testMode === false) return "live";
1203
+ return void 0;
1204
+ };
273
1205
 
274
1206
  // src/validate/rules.ts
275
1207
  var ISSUE_CODES = {
@@ -308,16 +1240,16 @@ var ISSUE_CODES = {
308
1240
  NETWORK_ERROR: "NETWORK_ERROR",
309
1241
  UNKNOWN: "UNKNOWN"
310
1242
  };
311
- function issue(code, severity, message, extras = {}) {
1243
+ var issue = (code, severity, message, extras = {}) => {
312
1244
  const base = { code, severity, message };
313
1245
  if (extras.suggestedFix !== void 0) base.suggestedFix = extras.suggestedFix;
314
1246
  if (extras.context !== void 0) base.context = extras.context;
315
1247
  return base;
316
- }
317
- function isOk(issues) {
1248
+ };
1249
+ var isOk = (issues) => {
318
1250
  return !issues.some((entry) => entry.severity === "error");
319
- }
320
- function buildResult(name, mode, issues, resource, target) {
1251
+ };
1252
+ var buildResult = (name, mode, issues, resource, target) => {
321
1253
  const result = {
322
1254
  name,
323
1255
  ok: isOk(issues),
@@ -327,10 +1259,10 @@ function buildResult(name, mode, issues, resource, target) {
327
1259
  if (resource !== void 0) result.resource = resource;
328
1260
  if (target !== void 0) result.target = target;
329
1261
  return result;
330
- }
1262
+ };
331
1263
 
332
1264
  // src/validate/probe.ts
333
- function mapErrorToIssue(err, mapping = {}) {
1265
+ var mapErrorToIssue = (err, mapping = {}) => {
334
1266
  if (err instanceof FreshSqueezyError) {
335
1267
  if (mapping.unauthorized && (err.status === 401 || err.code === "UNAUTHORIZED")) {
336
1268
  return issue(mapping.unauthorized.code, "error", mapping.unauthorized.message, {
@@ -357,8 +1289,8 @@ function mapErrorToIssue(err, mapping = {}) {
357
1289
  }
358
1290
  const message = err instanceof Error ? err.message : "Unknown error";
359
1291
  return issue(ISSUE_CODES.UNKNOWN, "error", message);
360
- }
361
- async function probeFetch(fetcher, options) {
1292
+ };
1293
+ var probeFetch = async (fetcher, options) => {
362
1294
  return probeCollection(fetcher, {
363
1295
  notFound: {
364
1296
  code: options.notFoundCode,
@@ -367,15 +1299,15 @@ async function probeFetch(fetcher, options) {
367
1299
  ...options.notFoundContext !== void 0 ? { context: options.notFoundContext } : {}
368
1300
  }
369
1301
  });
370
- }
371
- async function probeCollection(fetcher, mapping = {}) {
1302
+ };
1303
+ var probeCollection = async (fetcher, mapping = {}) => {
372
1304
  try {
373
1305
  return { ok: true, resource: await fetcher() };
374
1306
  } catch (err) {
375
1307
  return { ok: false, issue: mapErrorToIssue(err, mapping) };
376
1308
  }
377
- }
378
- function checkStoreOwnership(check) {
1309
+ };
1310
+ var checkStoreOwnership = (check) => {
379
1311
  const expected = String(check.expectedStoreId);
380
1312
  const actual = String(check.actualStoreId);
381
1313
  if (expected === actual) return null;
@@ -393,10 +1325,10 @@ function checkStoreOwnership(check) {
393
1325
  context
394
1326
  }
395
1327
  );
396
- }
1328
+ };
397
1329
 
398
1330
  // src/validate/connection.ts
399
- async function validateConnection(http, mode) {
1331
+ var validateConnection = async (http, mode) => {
400
1332
  const issues = [];
401
1333
  const fetched = await probeCollection(
402
1334
  async () => {
@@ -449,19 +1381,14 @@ async function validateConnection(http, mode) {
449
1381
  );
450
1382
  }
451
1383
  return buildResult("connection", mode, issues, summary);
452
- }
453
- async function fetchActualMode(http) {
1384
+ };
1385
+ var fetchActualMode = async (http) => {
454
1386
  const doc = await getAuthenticatedUser(http);
455
1387
  return resolveActualMode(doc.meta?.test_mode);
456
- }
457
-
458
- // src/resources/discounts.ts
459
- async function getDiscount(http, discountId) {
460
- return http.getResource(`/v1/discounts/${discountId}`);
461
- }
1388
+ };
462
1389
 
463
1390
  // src/validate/discount.ts
464
- async function validateDiscount(http, mode, options) {
1391
+ var validateDiscount = async (http, mode, options) => {
465
1392
  const issues = [];
466
1393
  const fetched = await probeFetch(() => getDiscount(http, options.discountId), {
467
1394
  notFoundCode: ISSUE_CODES.DISCOUNT_NOT_FOUND,
@@ -482,8 +1409,8 @@ async function validateDiscount(http, mode, options) {
482
1409
  label: `${attrs.name} (${attrs.code})`,
483
1410
  id: String(options.discountId)
484
1411
  });
485
- }
486
- function checkDiscount(attrs, options) {
1412
+ };
1413
+ var checkDiscount = (attrs, options) => {
487
1414
  const issues = [];
488
1415
  const mismatch = checkStoreOwnership({
489
1416
  expectedStoreId: options.storeId,
@@ -572,15 +1499,10 @@ function checkDiscount(attrs, options) {
572
1499
  );
573
1500
  }
574
1501
  return issues;
575
- }
576
-
577
- // src/resources/licenseKeys.ts
578
- async function getLicenseKey(http, licenseKeyId) {
579
- return http.getResource(`/v1/license-keys/${licenseKeyId}`);
580
- }
1502
+ };
581
1503
 
582
1504
  // src/validate/licenseKey.ts
583
- async function validateLicenseKey(http, mode, options) {
1505
+ var validateLicenseKey = async (http, mode, options) => {
584
1506
  const issues = [];
585
1507
  const fetched = await probeFetch(() => getLicenseKey(http, options.licenseKeyId), {
586
1508
  notFoundCode: ISSUE_CODES.LICENSE_KEY_NOT_FOUND,
@@ -601,8 +1523,8 @@ async function validateLicenseKey(http, mode, options) {
601
1523
  label: attrs.key_short,
602
1524
  id: String(options.licenseKeyId)
603
1525
  });
604
- }
605
- function checkLicenseKey(attrs, options) {
1526
+ };
1527
+ var checkLicenseKey = (attrs, options) => {
606
1528
  const issues = [];
607
1529
  const mismatch = checkStoreOwnership({
608
1530
  expectedStoreId: options.storeId,
@@ -656,30 +1578,10 @@ function checkLicenseKey(attrs, options) {
656
1578
  );
657
1579
  }
658
1580
  return issues;
659
- }
660
-
661
- // src/resources/products.ts
662
- async function getProduct(http, productId) {
663
- return http.getResource(`/v1/products/${productId}`);
664
- }
665
- async function listProducts(http, storeId) {
666
- return http.paginate("/v1/products", {
667
- "filter[store_id]": String(storeId)
668
- });
669
- }
670
-
671
- // src/resources/variants.ts
672
- async function getVariant(http, variantId) {
673
- return http.getResource(`/v1/variants/${variantId}`);
674
- }
675
- async function listVariantsForProduct(http, productId) {
676
- return http.paginate("/v1/variants", {
677
- "filter[product_id]": String(productId)
678
- });
679
- }
1581
+ };
680
1582
 
681
1583
  // src/validate/product.ts
682
- async function validateProduct(http, mode, options) {
1584
+ var validateProduct = async (http, mode, options) => {
683
1585
  const issues = [];
684
1586
  const fetched = await probeFetch(() => getProduct(http, options.productId), {
685
1587
  notFoundCode: ISSUE_CODES.PRODUCT_NOT_FOUND,
@@ -725,8 +1627,8 @@ async function validateProduct(http, mode, options) {
725
1627
  label: attrs.name,
726
1628
  id: String(options.productId)
727
1629
  });
728
- }
729
- function checkProduct(attrs, options = {}) {
1630
+ };
1631
+ var checkProduct = (attrs, options = {}) => {
730
1632
  const issues = [];
731
1633
  if (options.expectedStoreId !== void 0) {
732
1634
  const mismatch = checkStoreOwnership({
@@ -762,10 +1664,10 @@ function checkProduct(attrs, options = {}) {
762
1664
  );
763
1665
  }
764
1666
  return issues;
765
- }
1667
+ };
766
1668
 
767
1669
  // src/validate/store.ts
768
- async function validateStore(http, mode, storeId) {
1670
+ var validateStore = async (http, mode, storeId) => {
769
1671
  const issues = [];
770
1672
  const fetched = await probeFetch(() => getStore(http, storeId), {
771
1673
  notFoundCode: ISSUE_CODES.STORE_NOT_FOUND,
@@ -784,11 +1686,11 @@ async function validateStore(http, mode, storeId) {
784
1686
  label: fetched.resource.attributes.name,
785
1687
  id: String(storeId)
786
1688
  });
787
- }
1689
+ };
788
1690
 
789
1691
  // src/validate/subscriptionPlan.ts
790
1692
  var VALID_INTERVALS = /* @__PURE__ */ new Set(["day", "week", "month", "year"]);
791
- async function validateSubscriptionPlan(http, mode, options) {
1693
+ var validateSubscriptionPlan = async (http, mode, options) => {
792
1694
  const issues = [];
793
1695
  const fetched = await probeFetch(
794
1696
  () => getVariant(http, options.variantId),
@@ -834,8 +1736,8 @@ async function validateSubscriptionPlan(http, mode, options) {
834
1736
  label: attrs.name,
835
1737
  id: String(options.variantId)
836
1738
  });
837
- }
838
- function checkSubscriptionPlan(attrs, options) {
1739
+ };
1740
+ var checkSubscriptionPlan = (attrs, options) => {
839
1741
  const issues = [];
840
1742
  if (!attrs.is_subscription) {
841
1743
  issues.push(
@@ -919,22 +1821,15 @@ function checkSubscriptionPlan(attrs, options) {
919
1821
  );
920
1822
  }
921
1823
  return issues;
922
- }
1824
+ };
923
1825
 
924
1826
  // src/core/equality.ts
925
- function sameWebhookUrl(a, b) {
1827
+ var sameWebhookUrl = (a, b) => {
926
1828
  return normalizeWebhookUrl(a) === normalizeWebhookUrl(b);
927
- }
928
- function normalizeWebhookUrl(raw) {
1829
+ };
1830
+ var normalizeWebhookUrl = (raw) => {
929
1831
  return raw.replace(/\/+$/, "").toLowerCase();
930
- }
931
-
932
- // src/resources/webhooks.ts
933
- async function listWebhooksForStore(http, storeId) {
934
- return http.paginate("/v1/webhooks", {
935
- "filter[store_id]": String(storeId)
936
- });
937
- }
1832
+ };
938
1833
 
939
1834
  // src/generated/lemonSqueezyApiTypes.ts
940
1835
  var GENERATED_LEMON_SQUEEZY_RESOURCES = [
@@ -1110,7 +2005,7 @@ var ACKNOWLEDGED_CHANGELOG_ENTRIES = [
1110
2005
  ];
1111
2006
 
1112
2007
  // src/validate/webhook.ts
1113
- async function validateWebhook(http, mode, options) {
2008
+ var validateWebhook = async (http, mode, options) => {
1114
2009
  const issues = [];
1115
2010
  const fetched = await probeCollection(() => listWebhooksForStore(http, options.storeId));
1116
2011
  if (!fetched.ok) {
@@ -1170,7 +2065,7 @@ async function validateWebhook(http, mode, options) {
1170
2065
  id: match.id,
1171
2066
  url: match.attributes.url
1172
2067
  });
1173
- }
2068
+ };
1174
2069
 
1175
2070
  // src/validate/doctor.ts
1176
2071
  var DEFAULT_VALIDATORS = {
@@ -1182,7 +2077,7 @@ var DEFAULT_VALIDATORS = {
1182
2077
  licenseKey: validateLicenseKey,
1183
2078
  subscriptionPlan: validateSubscriptionPlan
1184
2079
  };
1185
- async function doctor(http, mode, options = {}, validators = DEFAULT_VALIDATORS) {
2080
+ var doctor = async (http, mode, options = {}, validators = DEFAULT_VALIDATORS) => {
1186
2081
  assertOptionsCoherent(options);
1187
2082
  const results = [];
1188
2083
  const productIds = collectValues(options.productId, options.productIds);
@@ -1248,8 +2143,8 @@ async function doctor(http, mode, options = {}, validators = DEFAULT_VALIDATORS)
1248
2143
  }
1249
2144
  const ok = results.every((result) => result.ok);
1250
2145
  return { ok, mode, results };
1251
- }
1252
- function assertOptionsCoherent(options) {
2146
+ };
2147
+ var assertOptionsCoherent = (options) => {
1253
2148
  if (options.storeId !== void 0) return;
1254
2149
  const dependent = [];
1255
2150
  if (hasAny(options.webhookUrl, options.webhookUrls)) dependent.push("webhookUrl");
@@ -1261,23 +2156,24 @@ function assertOptionsCoherent(options) {
1261
2156
  code: "DOCTOR_OPTIONS_INVALID",
1262
2157
  message: `doctor() received ${dependent.join(", ")} without storeId. These validators cannot run without a store; pass \`storeId\` or remove the dependent options.`
1263
2158
  });
1264
- }
1265
- function collectValues(single, many) {
2159
+ };
2160
+ var collectValues = (single, many) => {
1266
2161
  const values = /* @__PURE__ */ new Set();
1267
2162
  if (single !== void 0) values.add(single);
1268
2163
  for (const value of many ?? []) {
1269
2164
  if (value !== void 0) values.add(value);
1270
2165
  }
1271
2166
  return Array.from(values);
1272
- }
1273
- function hasAny(single, many) {
2167
+ };
2168
+ var hasAny = (single, many) => {
1274
2169
  return single !== void 0 || (many?.length ?? 0) > 0;
1275
- }
2170
+ };
1276
2171
 
1277
2172
  // src/createFreshSqueezy.ts
1278
- function createFreshSqueezy(config = {}) {
2173
+ var createFreshSqueezy = (config = {}) => {
1279
2174
  const resolved = resolveConfig(config);
1280
2175
  const http = new HttpClient(resolved);
2176
+ const op = (resource, verb, args = {}) => invokeOp(http, resource, verb, args);
1281
2177
  return {
1282
2178
  mode: resolved.mode,
1283
2179
  request: (options) => http.request(options),
@@ -1300,141 +2196,106 @@ function createFreshSqueezy(config = {}) {
1300
2196
  licenseKeyIds: options?.licenseKeyIds,
1301
2197
  variantId: options?.variantId,
1302
2198
  variantIds: options?.variantIds
1303
- })
1304
- };
1305
- }
1306
-
1307
- // src/resources/affiliates.ts
1308
- async function getAffiliate(http, affiliateId) {
1309
- return http.getResource(`/v1/affiliates/${affiliateId}`);
1310
- }
1311
- async function listAffiliatesForStore(http, storeId) {
1312
- return http.paginate("/v1/affiliates", {
1313
- "filter[store_id]": String(storeId)
1314
- });
1315
- }
1316
-
1317
- // src/resources/checkouts.ts
1318
- async function getCheckout(http, checkoutId) {
1319
- return http.getResource(`/v1/checkouts/${checkoutId}`);
1320
- }
1321
- async function listCheckoutsForStore(http, storeId) {
1322
- return http.paginate("/v1/checkouts", {
1323
- "filter[store_id]": String(storeId)
1324
- });
1325
- }
1326
-
1327
- // src/resources/customers.ts
1328
- async function getCustomer(http, customerId) {
1329
- return http.getResource(`/v1/customers/${customerId}`);
1330
- }
1331
- async function listCustomersForStore(http, storeId) {
1332
- return http.paginate("/v1/customers", {
1333
- "filter[store_id]": String(storeId)
1334
- });
1335
- }
1336
-
1337
- // src/resources/discountRedemptions.ts
1338
- async function getDiscountRedemption(http, discountRedemptionId) {
1339
- return http.getResource(
1340
- `/v1/discount-redemptions/${discountRedemptionId}`
1341
- );
1342
- }
1343
- async function listDiscountRedemptionsForDiscount(http, discountId) {
1344
- return http.paginate("/v1/discount-redemptions", {
1345
- "filter[discount_id]": String(discountId)
1346
- });
1347
- }
1348
-
1349
- // src/resources/files.ts
1350
- async function getFile(http, fileId) {
1351
- return http.getResource(`/v1/files/${fileId}`);
1352
- }
1353
- async function listFilesForVariant(http, variantId) {
1354
- return http.paginate("/v1/files", {
1355
- "filter[variant_id]": String(variantId)
1356
- });
1357
- }
1358
-
1359
- // src/resources/licenseKeyInstances.ts
1360
- async function getLicenseKeyInstance(http, licenseKeyInstanceId) {
1361
- return http.getResource(
1362
- `/v1/license-key-instances/${licenseKeyInstanceId}`
1363
- );
1364
- }
1365
- async function listLicenseKeyInstancesForLicenseKey(http, licenseKeyId) {
1366
- return http.paginate("/v1/license-key-instances", {
1367
- "filter[license_key_id]": String(licenseKeyId)
1368
- });
1369
- }
1370
-
1371
- // src/resources/orderItems.ts
1372
- async function getOrderItem(http, orderItemId) {
1373
- return http.getResource(`/v1/order-items/${orderItemId}`);
1374
- }
1375
- async function listOrderItemsForOrder(http, orderId) {
1376
- return http.paginate("/v1/order-items", {
1377
- "filter[order_id]": String(orderId)
1378
- });
1379
- }
1380
-
1381
- // src/resources/orders.ts
1382
- async function getOrder(http, orderId) {
1383
- return http.getResource(`/v1/orders/${orderId}`);
1384
- }
1385
-
1386
- // src/resources/prices.ts
1387
- async function getPrice(http, priceId) {
1388
- return http.getResource(`/v1/prices/${priceId}`);
1389
- }
1390
-
1391
- // src/resources/subscriptions.ts
1392
- async function getSubscription(http, subscriptionId) {
1393
- return http.getResource(`/v1/subscriptions/${subscriptionId}`);
1394
- }
1395
-
1396
- // src/resources/subscriptionInvoices.ts
1397
- async function getSubscriptionInvoice(http, subscriptionInvoiceId) {
1398
- return http.getResource(
1399
- `/v1/subscription-invoices/${subscriptionInvoiceId}`
1400
- );
1401
- }
1402
- async function listSubscriptionInvoicesForSubscription(http, subscriptionId) {
1403
- return http.paginate("/v1/subscription-invoices", {
1404
- "filter[subscription_id]": String(subscriptionId)
1405
- });
1406
- }
1407
-
1408
- // src/resources/subscriptionItems.ts
1409
- async function getSubscriptionItem(http, subscriptionItemId) {
1410
- return http.getResource(
1411
- `/v1/subscription-items/${subscriptionItemId}`
1412
- );
1413
- }
1414
- async function listSubscriptionItemsForSubscription(http, subscriptionId) {
1415
- return http.paginate("/v1/subscription-items", {
1416
- "filter[subscription_id]": String(subscriptionId)
1417
- });
1418
- }
1419
- function buildSubscriptionItemUpdateBody(subscriptionItemId, attributes) {
1420
- return {
1421
- data: {
1422
- type: "subscription-items",
1423
- id: String(subscriptionItemId),
1424
- attributes
2199
+ }),
2200
+ users: {
2201
+ me: () => op("user", "get")
2202
+ },
2203
+ stores: {
2204
+ get: (id) => op("store", "get", { id }),
2205
+ list: () => op("store", "list")
2206
+ },
2207
+ products: {
2208
+ get: (id) => op("product", "get", { id }),
2209
+ list: (storeId) => op("product", "list", { storeId })
2210
+ },
2211
+ variants: {
2212
+ get: (id) => op("variant", "get", { id }),
2213
+ list: (productId) => op("variant", "list", { parentId: productId })
2214
+ },
2215
+ prices: {
2216
+ get: (id) => op("price", "get", { id }),
2217
+ list: (variantId) => op("price", "list", { parentId: variantId })
2218
+ },
2219
+ files: {
2220
+ get: (id) => op("file", "get", { id }),
2221
+ list: (variantId) => op("file", "list", { parentId: variantId })
2222
+ },
2223
+ customers: {
2224
+ get: (id) => op("customer", "get", { id }),
2225
+ list: (storeId) => op("customer", "list", { storeId }),
2226
+ create: (body) => op("customer", "create", { body }),
2227
+ update: (id, body) => op("customer", "update", { id, body })
2228
+ },
2229
+ orders: {
2230
+ get: (id) => op("order", "get", { id }),
2231
+ list: (storeId) => op("order", "list", { storeId }),
2232
+ refund: (id, body) => op("order", "refund", { id, body }),
2233
+ generateInvoice: (id, body) => op("order", "generate-invoice", { id, body })
2234
+ },
2235
+ orderItems: {
2236
+ get: (id) => op("order-item", "get", { id }),
2237
+ list: (orderId) => op("order-item", "list", { parentId: orderId })
2238
+ },
2239
+ subscriptions: {
2240
+ get: (id) => op("subscription", "get", { id }),
2241
+ list: (storeId) => op("subscription", "list", { storeId }),
2242
+ update: (id, body) => op("subscription", "update", { id, body }),
2243
+ cancel: (id) => op("subscription", "cancel", { id })
2244
+ },
2245
+ subscriptionItems: {
2246
+ get: (id) => op("subscription-item", "get", { id }),
2247
+ list: (subscriptionId) => op("subscription-item", "list", { parentId: subscriptionId }),
2248
+ update: (id, body) => op("subscription-item", "update", { id, body }),
2249
+ currentUsage: (id) => op("subscription-item", "current-usage", { id })
2250
+ },
2251
+ subscriptionInvoices: {
2252
+ get: (id) => op("subscription-invoice", "get", { id }),
2253
+ list: (subscriptionId) => op("subscription-invoice", "list", { parentId: subscriptionId }),
2254
+ refund: (id, body) => op("subscription-invoice", "refund", { id, body }),
2255
+ generateInvoice: (id, body) => op("subscription-invoice", "generate-invoice", { id, body })
2256
+ },
2257
+ usageRecords: {
2258
+ get: (id) => op("usage-record", "get", { id }),
2259
+ list: (subscriptionItemId) => op("usage-record", "list", { parentId: subscriptionItemId }),
2260
+ create: (body) => op("usage-record", "create", { body })
2261
+ },
2262
+ discounts: {
2263
+ get: (id) => op("discount", "get", { id }),
2264
+ list: (storeId) => op("discount", "list", { storeId }),
2265
+ create: (body) => op("discount", "create", { body }),
2266
+ delete: (id) => op("discount", "delete", { id })
2267
+ },
2268
+ discountRedemptions: {
2269
+ get: (id) => op("discount-redemption", "get", { id }),
2270
+ list: (discountId) => op("discount-redemption", "list", { parentId: discountId })
2271
+ },
2272
+ licenseKeys: {
2273
+ get: (id) => op("license-key", "get", { id }),
2274
+ list: (storeId) => op("license-key", "list", { storeId }),
2275
+ update: (id, body) => op("license-key", "update", { id, body })
2276
+ },
2277
+ licenseKeyInstances: {
2278
+ get: (id) => op("license-key-instance", "get", { id }),
2279
+ list: (licenseKeyId) => op("license-key-instance", "list", { parentId: licenseKeyId })
2280
+ },
2281
+ checkouts: {
2282
+ get: (id) => op("checkout", "get", { id }),
2283
+ list: (storeId) => op("checkout", "list", { storeId }),
2284
+ create: (body) => op("checkout", "create", { body })
2285
+ },
2286
+ webhooks: {
2287
+ get: (id) => op("webhook", "get", { id }),
2288
+ list: (storeId) => op("webhook", "list", { storeId }),
2289
+ create: (body) => op("webhook", "create", { body }),
2290
+ update: (id, body) => op("webhook", "update", { id, body }),
2291
+ delete: (id) => op("webhook", "delete", { id })
2292
+ },
2293
+ affiliates: {
2294
+ get: (id) => op("affiliate", "get", { id }),
2295
+ list: (storeId) => op("affiliate", "list", { storeId })
1425
2296
  }
1426
2297
  };
1427
- }
1428
-
1429
- // src/resources/usageRecords.ts
1430
- async function getUsageRecord(http, usageRecordId) {
1431
- return http.getResource(`/v1/usage-records/${usageRecordId}`);
1432
- }
1433
- async function listUsageRecordsForSubscriptionItem(http, subscriptionItemId) {
1434
- return http.paginate("/v1/usage-records", {
1435
- "filter[subscription_item_id]": String(subscriptionItemId)
1436
- });
1437
- }
2298
+ };
1438
2299
  // Annotate the CommonJS export names for ESM import in node:
1439
2300
  0 && (module.exports = {
1440
2301
  ACKNOWLEDGED_CHANGELOG_ENTRIES,
@@ -1449,19 +2310,32 @@ async function listUsageRecordsForSubscriptionItem(http, subscriptionItemId) {
1449
2310
  SUPPORTED_RESOURCES,
1450
2311
  buildResult,
1451
2312
  buildSubscriptionItemUpdateBody,
2313
+ cancelSubscription,
1452
2314
  checkDiscount,
1453
2315
  checkLicenseKey,
1454
2316
  checkProduct,
1455
2317
  checkSubscriptionPlan,
2318
+ createCheckout,
2319
+ createCustomer,
2320
+ createDiscount,
1456
2321
  createFreshSqueezy,
2322
+ createUsageRecord,
2323
+ createWebhook,
2324
+ deleteDiscount,
2325
+ deleteWebhook,
1457
2326
  doctor,
1458
2327
  fetchActualMode,
2328
+ findResourceVerb,
2329
+ generateOrderInvoice,
2330
+ generateSubscriptionInvoice,
1459
2331
  getAffiliate,
1460
2332
  getAuthenticatedUser,
1461
2333
  getCheckout,
1462
2334
  getCustomer,
2335
+ getDiscount,
1463
2336
  getDiscountRedemption,
1464
2337
  getFile,
2338
+ getLicenseKey,
1465
2339
  getLicenseKeyInstance,
1466
2340
  getOrder,
1467
2341
  getOrderItem,
@@ -1471,27 +2345,44 @@ async function listUsageRecordsForSubscriptionItem(http, subscriptionItemId) {
1471
2345
  getSubscription,
1472
2346
  getSubscriptionInvoice,
1473
2347
  getSubscriptionItem,
2348
+ getSubscriptionItemCurrentUsage,
1474
2349
  getUsageRecord,
1475
2350
  getVariant,
2351
+ getWebhook,
2352
+ invokeOp,
1476
2353
  isOk,
1477
2354
  issue,
1478
2355
  listAffiliatesForStore,
1479
2356
  listCheckoutsForStore,
1480
2357
  listCustomersForStore,
1481
2358
  listDiscountRedemptionsForDiscount,
2359
+ listDiscountsForStore,
1482
2360
  listFilesForVariant,
1483
2361
  listLicenseKeyInstancesForLicenseKey,
2362
+ listLicenseKeysForStore,
1484
2363
  listOrderItemsForOrder,
2364
+ listOrdersForStore,
2365
+ listPricesForVariant,
1485
2366
  listProducts,
2367
+ listRegisteredResources,
1486
2368
  listStores,
1487
2369
  listSubscriptionInvoicesForSubscription,
1488
2370
  listSubscriptionItemsForSubscription,
2371
+ listSubscriptionsForStore,
1489
2372
  listUsageRecordsForSubscriptionItem,
1490
2373
  listVariantsForProduct,
1491
2374
  listWebhooksForStore,
2375
+ refundOrder,
2376
+ refundSubscriptionInvoice,
1492
2377
  resolveActualMode,
1493
2378
  resolveConfig,
2379
+ resourceRegistry,
1494
2380
  sameWebhookUrl,
2381
+ updateCustomer,
2382
+ updateLicenseKey,
2383
+ updateSubscription,
2384
+ updateSubscriptionItem,
2385
+ updateWebhook,
1495
2386
  userResource,
1496
2387
  validateConnection,
1497
2388
  validateDiscount,