@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.cjs +191 -139
- package/dist/index.d.cts +621 -600
- package/dist/index.d.ts +621 -600
- package/dist/index.js +189 -138
- package/package.json +1 -1
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
|
|
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 =
|
|
405
|
-
code:
|
|
406
|
-
name:
|
|
407
|
-
description:
|
|
346
|
+
var couponSchema = z8.object({
|
|
347
|
+
code: z8.string(),
|
|
348
|
+
name: z8.string(),
|
|
349
|
+
description: z8.string()
|
|
408
350
|
});
|
|
409
|
-
var percentageOffDiscountSchema2 =
|
|
410
|
-
type:
|
|
411
|
-
name:
|
|
412
|
-
description:
|
|
413
|
-
percentage:
|
|
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:
|
|
357
|
+
isExclusive: z8.boolean()
|
|
416
358
|
});
|
|
417
|
-
var flatAmountOffDiscountSchema2 =
|
|
418
|
-
type:
|
|
419
|
-
name:
|
|
420
|
-
description:
|
|
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:
|
|
364
|
+
isExclusive: z8.boolean()
|
|
423
365
|
});
|
|
424
|
-
var discountSchema2 =
|
|
366
|
+
var discountSchema2 = z8.discriminatedUnion("type", [
|
|
425
367
|
percentageOffDiscountSchema2,
|
|
426
368
|
flatAmountOffDiscountSchema2
|
|
427
369
|
]);
|
|
428
|
-
var openProductLineItem =
|
|
429
|
-
id:
|
|
430
|
-
type:
|
|
431
|
-
productId:
|
|
432
|
-
quantity:
|
|
433
|
-
variationId:
|
|
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 =
|
|
440
|
-
id:
|
|
441
|
-
type:
|
|
442
|
-
bundleId:
|
|
443
|
-
quantity:
|
|
444
|
-
variationId:
|
|
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 =
|
|
392
|
+
var openOrderLineItem = z8.discriminatedUnion("type", [
|
|
451
393
|
openProductLineItem,
|
|
452
394
|
openBundleLineItem
|
|
453
395
|
]);
|
|
454
|
-
var openOrderSchema =
|
|
455
|
-
id:
|
|
456
|
-
status:
|
|
457
|
-
currency:
|
|
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:
|
|
402
|
+
checkoutUrl: z8.string().optional()
|
|
461
403
|
});
|
|
462
|
-
var orderSchema =
|
|
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}
|
|
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/
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
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
|
|
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
|
|
665
|
-
var voucherSchema =
|
|
666
|
-
id:
|
|
667
|
-
name:
|
|
668
|
-
description:
|
|
669
|
-
code:
|
|
670
|
-
redeemed:
|
|
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.
|
|
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.
|
|
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",
|