@moonbase.sh/storefront-api 0.1.94 → 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
 
@@ -472,9 +414,16 @@ var OrderEndpoints = class {
472
414
  const response = await this.api.fetch(`/api/customer/orders/${orderId}`);
473
415
  return orderSchema.parse(response.data);
474
416
  }
475
- async pushContent(order, checkout) {
417
+ async pushContent(order, checkout, utm) {
418
+ const query = {
419
+ ...utmToObject(utm)
420
+ };
421
+ if (checkout) {
422
+ query.checkout = "true";
423
+ query.returnUrl = checkout.returnUrl;
424
+ }
476
425
  const response = await this.api.fetch(
477
- `/api/customer/orders/${order.id}${checkout ? `?checkout=true&returnUrl=${encodeURIComponent(checkout.returnUrl)}` : ""}`,
426
+ `/api/customer/orders/${order.id}?${new URLSearchParams(query).toString()}`,
478
427
  "PATCH",
479
428
  {
480
429
  currency: order.currency,
@@ -485,40 +434,29 @@ var OrderEndpoints = class {
485
434
  }
486
435
  };
487
436
 
488
- // src/products/endpoints.ts
489
- import { z as z10 } from "zod";
490
- var ProductEndpoints = class {
491
- constructor(api) {
492
- this.api = api;
493
- }
494
- async getOwned(nextUrl) {
495
- const response = await this.api.authenticatedFetch(nextUrl || "/api/customer/products");
496
- return paged(productSummarySchema).parse(response.data);
497
- }
498
- async getLicenses(productId, nextUrl) {
499
- const response = await this.api.authenticatedFetch(nextUrl || `/api/customer/products/${productId}/licenses`);
500
- return paged(licenseSchema).parse(response.data);
501
- }
502
- async getActivations(productId, nextUrl) {
503
- const response = await this.api.authenticatedFetch(nextUrl || `/api/customer/products/${productId}/licenses/activations`);
504
- return paged(activationSchema).parse(response.data);
505
- }
506
- async activate(deviceToken, activationMethod) {
507
- const response = await this.api.authenticatedFetch(`/api/customer/products/activate?method=${activationMethod}`, "POST", deviceToken, "text/plain");
508
- return {
509
- license: licenseSchema.parse(response.data),
510
- url: z10.string().parse(response.headers.get("location"))
511
- };
512
- }
513
- };
437
+ // src/globalModels.ts
438
+ function utmToObject(utm) {
439
+ return Object.entries({
440
+ utm_source: utm == null ? void 0 : utm.source,
441
+ utm_medium: utm == null ? void 0 : utm.medium,
442
+ utm_campaign: utm == null ? void 0 : utm.campaign,
443
+ utm_term: utm == null ? void 0 : utm.term,
444
+ utm_content: utm == null ? void 0 : utm.content,
445
+ utm_referrer: utm == null ? void 0 : utm.referrer
446
+ }).filter(([_, value]) => value !== void 0).reduce((obj, [key, value]) => ({
447
+ ...obj,
448
+ [key]: value
449
+ }), {});
450
+ }
514
451
 
515
452
  // src/storefront/endpoints.ts
516
453
  var StorefrontEndpoints = class {
517
454
  constructor(api) {
518
455
  this.api = api;
519
456
  }
520
- async get() {
521
- const response = await this.api.fetch("/api/customer/storefront");
457
+ async get(utm) {
458
+ const query = new URLSearchParams(utmToObject(utm));
459
+ const response = await this.api.fetch(`/api/customer/storefront?${query.toString()}`);
522
460
  return storefrontSchema.parse(response.data);
523
461
  }
524
462
  };
@@ -661,13 +599,13 @@ _TokenStore.storageKey = "moonbase_auth";
661
599
  var TokenStore = _TokenStore;
662
600
 
663
601
  // src/vouchers/schemas.ts
664
- import { z as z11 } from "zod";
665
- var voucherSchema = z11.object({
666
- id: z11.string(),
667
- name: z11.string(),
668
- description: z11.string(),
669
- code: z11.string(),
670
- 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(),
671
609
  redeemsProducts: quantifiable(storefrontProductSchema).array(),
672
610
  redeemsBundles: quantifiable(storefrontBundleSchema).array()
673
611
  });
@@ -690,6 +628,119 @@ var VoucherEndpoints = class {
690
628
  }
691
629
  };
692
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
+
693
744
  // src/index.ts
694
745
  var MoonbaseClient = class {
695
746
  constructor(configuration) {
@@ -701,9 +752,8 @@ var MoonbaseClient = class {
701
752
  this.identity = new IdentityEndpoints(api, this.tokenStore);
702
753
  this.vouchers = new VoucherEndpoints(api);
703
754
  this.orders = new OrderEndpoints(api);
704
- this.licenses = new LicenseEndpoints(api);
755
+ this.inventory = new InventoryEndpoints(api);
705
756
  this.activationRequests = new ActivationRequestEndpoints(api);
706
- this.products = new ProductEndpoints(api);
707
757
  }
708
758
  };
709
759
  export {
@@ -717,5 +767,6 @@ export {
717
767
  NotAuthorizedError,
718
768
  NotFoundError,
719
769
  OrderStatus,
720
- Platform
770
+ Platform,
771
+ utmToObject
721
772
  };
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.94",
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",