@moonbase.sh/storefront-api 0.1.96 → 0.1.97

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.js CHANGED
@@ -49,10 +49,10 @@ function quantifiable(itemSchema) {
49
49
  });
50
50
  }
51
51
 
52
- // src/products/schemas.ts
52
+ // src/inventory/products/schemas.ts
53
53
  import { z as z2 } from "zod";
54
54
 
55
- // src/products/models.ts
55
+ // src/inventory/products/models.ts
56
56
  var Platform = /* @__PURE__ */ ((Platform2) => {
57
57
  Platform2["Universal"] = "Universal";
58
58
  Platform2["Windows"] = "Windows";
@@ -61,7 +61,7 @@ var Platform = /* @__PURE__ */ ((Platform2) => {
61
61
  return Platform2;
62
62
  })(Platform || {});
63
63
 
64
- // src/products/schemas.ts
64
+ // src/inventory/products/schemas.ts
65
65
  var downloadSchema = z2.object({
66
66
  name: z2.string(),
67
67
  key: z2.string(),
@@ -106,7 +106,7 @@ var storefrontBundleSchema = z3.object({
106
106
  owned: z3.boolean(),
107
107
  partial: z3.boolean(),
108
108
  products: storefrontProductSchema.and(z3.object({
109
- included: z3.boolean()
109
+ included: z3.boolean().optional()
110
110
  })).array(),
111
111
  defaultVariation: pricingVariationSchema.optional(),
112
112
  variations: pricingVariationSchema.array().optional(),
@@ -328,66 +328,8 @@ var IdentityEndpoints = class {
328
328
  }
329
329
  };
330
330
 
331
- // src/licenses/schemas.ts
332
- import { z as z8 } from "zod";
333
-
334
- // src/licenses/models.ts
335
- var LicenseStatus = /* @__PURE__ */ ((LicenseStatus2) => {
336
- LicenseStatus2["Active"] = "Active";
337
- LicenseStatus2["Revoked"] = "Revoked";
338
- return LicenseStatus2;
339
- })(LicenseStatus || {});
340
- var ActivationStatus = /* @__PURE__ */ ((ActivationStatus2) => {
341
- ActivationStatus2["Active"] = "Active";
342
- ActivationStatus2["Revoked"] = "Revoked";
343
- return ActivationStatus2;
344
- })(ActivationStatus || {});
345
- var ActivationMethod = /* @__PURE__ */ ((ActivationMethod2) => {
346
- ActivationMethod2["Online"] = "Online";
347
- ActivationMethod2["Offline"] = "Offline";
348
- return ActivationMethod2;
349
- })(ActivationMethod || {});
350
-
351
- // src/licenses/schemas.ts
352
- var licenseSchema = z8.object({
353
- id: z8.string(),
354
- status: z8.nativeEnum(LicenseStatus),
355
- product: productSummarySchema.optional(),
356
- activeNumberOfActivations: z8.number(),
357
- maxNumberOfActivations: z8.number(),
358
- createdAt: z8.coerce.date()
359
- });
360
- var activationSchema = z8.object({
361
- id: z8.string(),
362
- licenseId: z8.string(),
363
- name: z8.string(),
364
- status: z8.nativeEnum(ActivationStatus),
365
- activationMethod: z8.nativeEnum(ActivationMethod),
366
- lastValidatedAt: z8.coerce.date().nullable()
367
- });
368
-
369
- // src/licenses/endpoints.ts
370
- var LicenseEndpoints = class {
371
- constructor(api) {
372
- this.api = api;
373
- }
374
- async get(nextUrl) {
375
- const response = await this.api.authenticatedFetch(nextUrl || "/api/customer/licenses");
376
- return paged(licenseSchema).parse(response.data);
377
- }
378
- async getActivations(licenseId, nextUrl) {
379
- const response = await this.api.authenticatedFetch(
380
- nextUrl || `/api/customer/licenses/${licenseId}/activations`
381
- );
382
- return paged(activationSchema).parse(response.data);
383
- }
384
- async revokeActivation(licenseId, activationId) {
385
- await this.api.authenticatedFetch(`/api/customer/licenses/${licenseId}/activations/${activationId}/revoke`, "POST");
386
- }
387
- };
388
-
389
331
  // src/orders/schemas.ts
390
- import { z as z9 } from "zod";
332
+ import { z as z8 } from "zod";
391
333
 
392
334
  // src/orders/models.ts
393
335
  var OrderStatus = /* @__PURE__ */ ((OrderStatus2) => {
@@ -401,65 +343,65 @@ var OrderStatus = /* @__PURE__ */ ((OrderStatus2) => {
401
343
  })(OrderStatus || {});
402
344
 
403
345
  // src/orders/schemas.ts
404
- var couponSchema = z9.object({
405
- code: z9.string(),
406
- name: z9.string(),
407
- description: z9.string()
346
+ var couponSchema = z8.object({
347
+ code: z8.string(),
348
+ name: z8.string(),
349
+ description: z8.string()
408
350
  });
409
- var percentageOffDiscountSchema2 = z9.object({
410
- type: z9.literal("PercentageOffDiscount"),
411
- name: z9.string(),
412
- description: z9.string().optional(),
413
- percentage: z9.number(),
351
+ var percentageOffDiscountSchema2 = z8.object({
352
+ type: z8.literal("PercentageOffDiscount"),
353
+ name: z8.string(),
354
+ description: z8.string().optional(),
355
+ percentage: z8.number(),
414
356
  total: priceCollectionSchema.optional(),
415
- isExclusive: z9.boolean()
357
+ isExclusive: z8.boolean()
416
358
  });
417
- var flatAmountOffDiscountSchema2 = z9.object({
418
- type: z9.literal("FlatAmountOffDiscount"),
419
- name: z9.string(),
420
- description: z9.string().optional(),
359
+ var flatAmountOffDiscountSchema2 = z8.object({
360
+ type: z8.literal("FlatAmountOffDiscount"),
361
+ name: z8.string(),
362
+ description: z8.string().optional(),
421
363
  total: priceCollectionSchema.optional(),
422
- isExclusive: z9.boolean()
364
+ isExclusive: z8.boolean()
423
365
  });
424
- var discountSchema2 = z9.discriminatedUnion("type", [
366
+ var discountSchema2 = z8.discriminatedUnion("type", [
425
367
  percentageOffDiscountSchema2,
426
368
  flatAmountOffDiscountSchema2
427
369
  ]);
428
- var openProductLineItem = z9.object({
429
- id: z9.string(),
430
- type: z9.literal("Product"),
431
- productId: z9.string(),
432
- quantity: z9.number(),
433
- variationId: z9.string(),
370
+ var openProductLineItem = z8.object({
371
+ id: z8.string(),
372
+ type: z8.literal("Product"),
373
+ productId: z8.string(),
374
+ quantity: z8.number(),
375
+ variationId: z8.string(),
434
376
  price: priceCollectionSchema.optional(),
435
377
  variation: pricingVariationSchema.optional(),
436
378
  product: storefrontProductSchema.optional(),
437
379
  appliedDiscount: discountSchema2.optional()
438
380
  });
439
- var openBundleLineItem = z9.object({
440
- id: z9.string(),
441
- type: z9.literal("Bundle"),
442
- bundleId: z9.string(),
443
- quantity: z9.number(),
444
- variationId: z9.string(),
381
+ var openBundleLineItem = z8.object({
382
+ id: z8.string(),
383
+ type: z8.literal("Bundle"),
384
+ bundleId: z8.string(),
385
+ quantity: z8.number(),
386
+ variationId: z8.string(),
445
387
  price: priceCollectionSchema.optional(),
446
388
  variation: pricingVariationSchema.optional(),
447
389
  bundle: storefrontBundleSchema.optional(),
448
390
  appliedDiscount: discountSchema2.optional()
449
391
  });
450
- var openOrderLineItem = z9.discriminatedUnion("type", [
392
+ var openOrderLineItem = z8.discriminatedUnion("type", [
451
393
  openProductLineItem,
452
394
  openBundleLineItem
453
395
  ]);
454
- var openOrderSchema = z9.object({
455
- id: z9.string(),
456
- status: z9.literal("Open" /* Open */),
457
- currency: z9.string(),
396
+ var openOrderSchema = z8.object({
397
+ id: z8.string(),
398
+ status: z8.literal("Open" /* Open */),
399
+ currency: z8.string(),
458
400
  items: openOrderLineItem.array(),
459
401
  couponsApplied: couponSchema.array(),
460
- checkoutUrl: z9.string().optional()
402
+ checkoutUrl: z8.string().optional()
461
403
  });
462
- var orderSchema = z9.discriminatedUnion("status", [
404
+ var orderSchema = z8.discriminatedUnion("status", [
463
405
  openOrderSchema
464
406
  ]);
465
407
 
@@ -492,33 +434,6 @@ var OrderEndpoints = class {
492
434
  }
493
435
  };
494
436
 
495
- // src/products/endpoints.ts
496
- import { z as z10 } from "zod";
497
- var ProductEndpoints = class {
498
- constructor(api) {
499
- this.api = api;
500
- }
501
- async getOwned(nextUrl) {
502
- const response = await this.api.authenticatedFetch(nextUrl || "/api/customer/products");
503
- return paged(productSummarySchema).parse(response.data);
504
- }
505
- async getLicenses(productId, nextUrl) {
506
- const response = await this.api.authenticatedFetch(nextUrl || `/api/customer/products/${productId}/licenses`);
507
- return paged(licenseSchema).parse(response.data);
508
- }
509
- async getActivations(productId, nextUrl) {
510
- const response = await this.api.authenticatedFetch(nextUrl || `/api/customer/products/${productId}/licenses/activations`);
511
- return paged(activationSchema).parse(response.data);
512
- }
513
- async activate(deviceToken, activationMethod) {
514
- const response = await this.api.authenticatedFetch(`/api/customer/products/activate?method=${activationMethod}`, "POST", deviceToken, "text/plain");
515
- return {
516
- license: licenseSchema.parse(response.data),
517
- url: z10.string().parse(response.headers.get("location"))
518
- };
519
- }
520
- };
521
-
522
437
  // src/globalModels.ts
523
438
  function utmToObject(utm) {
524
439
  return Object.entries({
@@ -684,13 +599,13 @@ _TokenStore.storageKey = "moonbase_auth";
684
599
  var TokenStore = _TokenStore;
685
600
 
686
601
  // src/vouchers/schemas.ts
687
- import { z as z11 } from "zod";
688
- var voucherSchema = z11.object({
689
- id: z11.string(),
690
- name: z11.string(),
691
- description: z11.string(),
692
- code: z11.string(),
693
- redeemed: z11.boolean(),
602
+ import { z as z9 } from "zod";
603
+ var voucherSchema = z9.object({
604
+ id: z9.string(),
605
+ name: z9.string(),
606
+ description: z9.string(),
607
+ code: z9.string(),
608
+ redeemed: z9.boolean(),
694
609
  redeemsProducts: quantifiable(storefrontProductSchema).array(),
695
610
  redeemsBundles: quantifiable(storefrontBundleSchema).array()
696
611
  });
@@ -713,6 +628,119 @@ var VoucherEndpoints = class {
713
628
  }
714
629
  };
715
630
 
631
+ // src/inventory/activation/endpoints.ts
632
+ import { z as z11 } from "zod";
633
+
634
+ // src/inventory/licenses/schemas.ts
635
+ import { z as z10 } from "zod";
636
+
637
+ // src/inventory/licenses/models.ts
638
+ var LicenseStatus = /* @__PURE__ */ ((LicenseStatus2) => {
639
+ LicenseStatus2["Active"] = "Active";
640
+ LicenseStatus2["Revoked"] = "Revoked";
641
+ return LicenseStatus2;
642
+ })(LicenseStatus || {});
643
+ var ActivationStatus = /* @__PURE__ */ ((ActivationStatus2) => {
644
+ ActivationStatus2["Active"] = "Active";
645
+ ActivationStatus2["Revoked"] = "Revoked";
646
+ return ActivationStatus2;
647
+ })(ActivationStatus || {});
648
+ var ActivationMethod = /* @__PURE__ */ ((ActivationMethod2) => {
649
+ ActivationMethod2["Online"] = "Online";
650
+ ActivationMethod2["Offline"] = "Offline";
651
+ return ActivationMethod2;
652
+ })(ActivationMethod || {});
653
+
654
+ // src/inventory/licenses/schemas.ts
655
+ var licenseSchema = z10.object({
656
+ id: z10.string(),
657
+ status: z10.nativeEnum(LicenseStatus),
658
+ product: productSummarySchema,
659
+ activeNumberOfActivations: z10.number(),
660
+ maxNumberOfActivations: z10.number(),
661
+ createdAt: z10.coerce.date()
662
+ });
663
+ var activationSchema = z10.object({
664
+ id: z10.string(),
665
+ licenseId: z10.string(),
666
+ name: z10.string(),
667
+ status: z10.nativeEnum(ActivationStatus),
668
+ activationMethod: z10.nativeEnum(ActivationMethod),
669
+ lastValidatedAt: z10.coerce.date().nullable()
670
+ });
671
+
672
+ // src/inventory/activation/endpoints.ts
673
+ var ActivationEndpoints = class {
674
+ constructor(api) {
675
+ this.api = api;
676
+ }
677
+ async activate(deviceToken, activationMethod) {
678
+ const response = await this.api.authenticatedFetch(`/api/customer/inventory/activate?method=${activationMethod}`, "POST", deviceToken, "text/plain");
679
+ return {
680
+ license: licenseSchema.parse(response.data),
681
+ url: z11.string().parse(response.headers.get("location"))
682
+ };
683
+ }
684
+ };
685
+
686
+ // src/inventory/licenses/endpoints.ts
687
+ var LicenseEndpoints = class {
688
+ constructor(api) {
689
+ this.api = api;
690
+ }
691
+ async get(nextUrl) {
692
+ const response = await this.api.authenticatedFetch(nextUrl || "/api/customer/inventory/licenses");
693
+ return paged(licenseSchema).parse(response.data);
694
+ }
695
+ async getActivations(licenseId, nextUrl) {
696
+ const response = await this.api.authenticatedFetch(
697
+ nextUrl || `/api/customer/inventory/licenses/${licenseId}/activations`
698
+ );
699
+ return paged(activationSchema).parse(response.data);
700
+ }
701
+ async revokeActivation(licenseId, activationId) {
702
+ await this.api.authenticatedFetch(`/api/customer/inventory/licenses/${licenseId}/activations/${activationId}/revoke`, "POST");
703
+ }
704
+ };
705
+
706
+ // src/inventory/products/endpoints.ts
707
+ import { z as z12 } from "zod";
708
+ var ProductEndpoints = class {
709
+ constructor(api) {
710
+ this.api = api;
711
+ }
712
+ async getOwned(nextUrl) {
713
+ const response = await this.api.authenticatedFetch(nextUrl || "/api/customer/inventory/products");
714
+ return paged(productSummarySchema).parse(response.data);
715
+ }
716
+ async getLicenses(productId, nextUrl) {
717
+ const response = await this.api.authenticatedFetch(nextUrl || `/api/customer/inventory/products/${productId}/licenses`);
718
+ return paged(licenseSchema).parse(response.data);
719
+ }
720
+ async getActivations(productId, nextUrl) {
721
+ const response = await this.api.authenticatedFetch(nextUrl || `/api/customer/inventory/products/${productId}/licenses/activations`);
722
+ return paged(activationSchema).parse(response.data);
723
+ }
724
+ async getDownloadUrl(path) {
725
+ const url = new URL(path);
726
+ url.searchParams.append("redirect", "false");
727
+ const response = await this.api.authenticatedFetch(url.pathname + url.search);
728
+ const content = z12.object({
729
+ location: z12.string()
730
+ }).parse(response.data);
731
+ return content.location;
732
+ }
733
+ };
734
+
735
+ // src/inventory/index.ts
736
+ var InventoryEndpoints = class {
737
+ constructor(api) {
738
+ this.licenses = new LicenseEndpoints(api);
739
+ this.products = new ProductEndpoints(api);
740
+ this.activation = new ActivationEndpoints(api);
741
+ }
742
+ };
743
+
716
744
  // src/index.ts
717
745
  var MoonbaseClient = class {
718
746
  constructor(configuration) {
@@ -724,9 +752,8 @@ var MoonbaseClient = class {
724
752
  this.identity = new IdentityEndpoints(api, this.tokenStore);
725
753
  this.vouchers = new VoucherEndpoints(api);
726
754
  this.orders = new OrderEndpoints(api);
727
- this.licenses = new LicenseEndpoints(api);
755
+ this.inventory = new InventoryEndpoints(api);
728
756
  this.activationRequests = new ActivationRequestEndpoints(api);
729
- this.products = new ProductEndpoints(api);
730
757
  }
731
758
  };
732
759
  export {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@moonbase.sh/storefront-api",
3
3
  "type": "module",
4
- "version": "0.1.96",
4
+ "version": "0.1.97",
5
5
  "description": "Package to let you build storefronts with Moonbase.sh as payment and delivery provider",
6
6
  "author": "Tobias Lønnerød Madsen <m@dsen.tv>",
7
7
  "license": "MIT",