@moonbase.sh/storefront-api 0.1.82 → 0.1.84

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
@@ -1,8 +1,176 @@
1
+ // src/activationsRequests/endpoints.ts
2
+ import { z as z5 } from "zod";
3
+
4
+ // src/activationsRequests/schemas.ts
5
+ import { z as z4 } from "zod";
6
+
7
+ // src/storefront/schemas.ts
8
+ import { z as z3 } from "zod";
9
+
10
+ // src/globalSchemas.ts
11
+ import { z } from "zod";
12
+ var priceCollectionSchema = z.record(z.number());
13
+ var percentageOffDiscountSchema = z.object({
14
+ type: z.literal("PercentageOffDiscount"),
15
+ name: z.string(),
16
+ description: z.string().optional(),
17
+ percentage: z.number(),
18
+ total: priceCollectionSchema
19
+ });
20
+ var flatAmountOffDiscountSchema = z.object({
21
+ type: z.literal("FlatAmountOffDiscount"),
22
+ name: z.string(),
23
+ description: z.string().optional(),
24
+ total: priceCollectionSchema
25
+ });
26
+ var discountSchema = z.discriminatedUnion("type", [
27
+ percentageOffDiscountSchema,
28
+ flatAmountOffDiscountSchema
29
+ ]);
30
+ var pricingVariationSchema = z.object({
31
+ id: z.string(),
32
+ name: z.string(),
33
+ originalPrice: priceCollectionSchema,
34
+ price: priceCollectionSchema,
35
+ hasDiscount: z.boolean(),
36
+ discount: discountSchema.optional()
37
+ });
38
+ function paged(itemSchema) {
39
+ return z.object({
40
+ items: z.array(itemSchema),
41
+ hasMore: z.boolean(),
42
+ next: z.string().nullable()
43
+ });
44
+ }
45
+ function quantifiable(itemSchema) {
46
+ return z.object({
47
+ value: itemSchema,
48
+ quantity: z.number()
49
+ });
50
+ }
51
+
52
+ // src/products/schemas.ts
53
+ import { z as z2 } from "zod";
54
+
55
+ // src/products/models.ts
56
+ var Platform = /* @__PURE__ */ ((Platform2) => {
57
+ Platform2["Universal"] = "Universal";
58
+ Platform2["Windows"] = "Windows";
59
+ Platform2["Linux"] = "Linux";
60
+ Platform2["Mac"] = "Mac";
61
+ return Platform2;
62
+ })(Platform || {});
63
+
64
+ // src/products/schemas.ts
65
+ var downloadSchema = z2.object({
66
+ name: z2.string(),
67
+ key: z2.string(),
68
+ platform: z2.nativeEnum(Platform),
69
+ size: z2.number(),
70
+ path: z2.string().nullable()
71
+ });
72
+ var productSummarySchema = z2.object({
73
+ id: z2.string(),
74
+ name: z2.string(),
75
+ tagline: z2.string(),
76
+ website: z2.string().optional(),
77
+ iconUrl: z2.string().optional(),
78
+ numberOfLicenses: z2.number().optional(),
79
+ numberOfTrials: z2.number().optional(),
80
+ currentActivations: z2.number().optional(),
81
+ maxActivations: z2.number().optional(),
82
+ currentVersion: z2.string().nullable(),
83
+ downloadsNeedsUser: z2.boolean(),
84
+ downloadsNeedsOwnership: z2.boolean(),
85
+ downloads: z2.array(downloadSchema).optional()
86
+ });
87
+
88
+ // src/storefront/schemas.ts
89
+ var storefrontProductSchema = z3.object({
90
+ id: z3.string(),
91
+ name: z3.string(),
92
+ tagline: z3.string(),
93
+ iconUrl: z3.string().nullable(),
94
+ owned: z3.boolean(),
95
+ currentVersion: z3.string().optional(),
96
+ downloads: downloadSchema.array().optional(),
97
+ defaultVariation: pricingVariationSchema.optional(),
98
+ variations: pricingVariationSchema.array().optional(),
99
+ type: z3.void().transform(() => "product").pipe(z3.literal("product"))
100
+ });
101
+ var storefrontBundleSchema = z3.object({
102
+ id: z3.string(),
103
+ name: z3.string(),
104
+ tagline: z3.string(),
105
+ iconUrl: z3.string().nullable(),
106
+ owned: z3.boolean(),
107
+ partial: z3.boolean(),
108
+ products: storefrontProductSchema.and(z3.object({
109
+ included: z3.boolean()
110
+ })).array(),
111
+ defaultVariation: pricingVariationSchema.optional(),
112
+ variations: pricingVariationSchema.array().optional(),
113
+ type: z3.void().transform(() => "bundle").pipe(z3.literal("bundle"))
114
+ });
115
+ var storefrontSchema = z3.object({
116
+ suggestedCurrency: z3.string(),
117
+ products: storefrontProductSchema.array(),
118
+ bundles: storefrontBundleSchema.array()
119
+ });
120
+
121
+ // src/activationsRequests/models.ts
122
+ var ActivationRequestStatus = /* @__PURE__ */ ((ActivationRequestStatus2) => {
123
+ ActivationRequestStatus2["Requested"] = "Requested";
124
+ ActivationRequestStatus2["Fulfilled"] = "Fulfilled";
125
+ ActivationRequestStatus2["Completed"] = "Completed";
126
+ return ActivationRequestStatus2;
127
+ })(ActivationRequestStatus || {});
128
+
129
+ // src/activationsRequests/schemas.ts
130
+ var activationRequestSchema = z4.object({
131
+ id: z4.string(),
132
+ status: z4.nativeEnum(ActivationRequestStatus),
133
+ product: storefrontProductSchema,
134
+ trialEligibility: z4.object({
135
+ eligible: z4.boolean(),
136
+ existing: z4.boolean(),
137
+ requiresAccount: z4.boolean(),
138
+ numberOfDaysPerProduct: z4.number(),
139
+ numberOfDaysRemaining: z4.number()
140
+ }).optional(),
141
+ licenseEligibility: z4.object({
142
+ eligible: z4.boolean()
143
+ }).optional()
144
+ });
145
+
146
+ // src/activationsRequests/endpoints.ts
147
+ var ActivationRequestEndpoints = class {
148
+ constructor(api) {
149
+ this.api = api;
150
+ }
151
+ async get(requestId) {
152
+ const response = await this.api.fetch(`/api/customer/activations/${requestId}`);
153
+ return activationRequestSchema.parse(response);
154
+ }
155
+ async isCompleted(requestId) {
156
+ const response = await this.api.fetch(`/api/customer/activations/${requestId}/completed`);
157
+ return z5.boolean().parse(response.data);
158
+ }
159
+ async fulfillLicense(requestId) {
160
+ const response = await this.api.authenticatedFetch(`/api/customer/activations/${requestId}/license`, "POST");
161
+ return activationRequestSchema.parse(response.data);
162
+ }
163
+ async fulfillTrial(requestId) {
164
+ const response = await this.api.fetch(`/api/customer/activations/${requestId}/trial`, "POST");
165
+ return activationRequestSchema.parse(response.data);
166
+ }
167
+ };
168
+
1
169
  // src/identity/endpoints.ts
2
170
  import fetch from "cross-fetch";
3
171
 
4
172
  // src/utils/problemHandler.ts
5
- import { z } from "zod";
173
+ import { z as z6 } from "zod";
6
174
 
7
175
  // src/utils/errors.ts
8
176
  var NotAuthorizedError = class extends Error {
@@ -25,11 +193,11 @@ var NotFoundError = class extends Error {
25
193
  };
26
194
 
27
195
  // src/utils/problemHandler.ts
28
- var problemDetailsSchema = z.object({
29
- type: z.string(),
30
- title: z.string(),
31
- detail: z.string().optional(),
32
- status: z.number()
196
+ var problemDetailsSchema = z6.object({
197
+ type: z6.string(),
198
+ title: z6.string(),
199
+ detail: z6.string().optional(),
200
+ status: z6.number()
33
201
  });
34
202
  async function handleResponseProblem(response) {
35
203
  if (response.status === 404)
@@ -53,30 +221,30 @@ async function handleResponseProblem(response) {
53
221
  }
54
222
 
55
223
  // src/identity/schemas.ts
56
- import { z as z2 } from "zod";
57
- var addressSchema = z2.object({
58
- countryCode: z2.string(),
59
- streetAddress1: z2.string(),
60
- streetAddress2: z2.string().nullable(),
61
- locality: z2.string().nullable(),
62
- region: z2.string().nullable(),
63
- postCode: z2.string()
224
+ import { z as z7 } from "zod";
225
+ var addressSchema = z7.object({
226
+ countryCode: z7.string(),
227
+ streetAddress1: z7.string(),
228
+ streetAddress2: z7.string().nullable(),
229
+ locality: z7.string().nullable(),
230
+ region: z7.string().nullable(),
231
+ postCode: z7.string()
64
232
  });
65
- var communicationPreferencesSchema = z2.object({
66
- newsletterOptIn: z2.boolean()
233
+ var communicationPreferencesSchema = z7.object({
234
+ newsletterOptIn: z7.boolean()
67
235
  // productUpdatesOptIn: z.boolean(), // TODO: Enable when relevant
68
236
  });
69
- var userSchema = z2.object({
70
- id: z2.string(),
71
- email: z2.string(),
72
- name: z2.string(),
73
- tenantId: z2.string(),
237
+ var userSchema = z7.object({
238
+ id: z7.string(),
239
+ email: z7.string(),
240
+ name: z7.string(),
241
+ tenantId: z7.string(),
74
242
  address: addressSchema.optional(),
75
243
  communicationPreferences: communicationPreferencesSchema
76
244
  });
77
- var identityUserSchema = userSchema.and(z2.object({
78
- accessToken: z2.string(),
79
- refreshToken: z2.string()
245
+ var identityUserSchema = userSchema.and(z7.object({
246
+ accessToken: z7.string(),
247
+ refreshToken: z7.string()
80
248
  }));
81
249
 
82
250
  // src/identity/endpoints.ts
@@ -154,86 +322,8 @@ var IdentityEndpoints = class {
154
322
  }
155
323
  };
156
324
 
157
- // src/globalSchemas.ts
158
- import { z as z3 } from "zod";
159
- var priceCollectionSchema = z3.record(z3.number());
160
- var percentageOffDiscountSchema = z3.object({
161
- type: z3.literal("PercentageOffDiscount"),
162
- name: z3.string(),
163
- description: z3.string().optional(),
164
- percentage: z3.number(),
165
- total: priceCollectionSchema
166
- });
167
- var flatAmountOffDiscountSchema = z3.object({
168
- type: z3.literal("FlatAmountOffDiscount"),
169
- name: z3.string(),
170
- description: z3.string().optional(),
171
- total: priceCollectionSchema
172
- });
173
- var discountSchema = z3.discriminatedUnion("type", [
174
- percentageOffDiscountSchema,
175
- flatAmountOffDiscountSchema
176
- ]);
177
- var pricingVariationSchema = z3.object({
178
- id: z3.string(),
179
- name: z3.string(),
180
- originalPrice: priceCollectionSchema,
181
- price: priceCollectionSchema,
182
- hasDiscount: z3.boolean(),
183
- discount: discountSchema.optional()
184
- });
185
- function paged(itemSchema) {
186
- return z3.object({
187
- items: z3.array(itemSchema),
188
- hasMore: z3.boolean(),
189
- next: z3.string().nullable()
190
- });
191
- }
192
- function quantifiable(itemSchema) {
193
- return z3.object({
194
- value: itemSchema,
195
- quantity: z3.number()
196
- });
197
- }
198
-
199
325
  // src/licenses/schemas.ts
200
- import { z as z5 } from "zod";
201
-
202
- // src/products/schemas.ts
203
- import { z as z4 } from "zod";
204
-
205
- // src/products/models.ts
206
- var Platform = /* @__PURE__ */ ((Platform2) => {
207
- Platform2["Universal"] = "Universal";
208
- Platform2["Windows"] = "Windows";
209
- Platform2["Linux"] = "Linux";
210
- Platform2["Mac"] = "Mac";
211
- return Platform2;
212
- })(Platform || {});
213
-
214
- // src/products/schemas.ts
215
- var downloadSchema = z4.object({
216
- name: z4.string(),
217
- key: z4.string(),
218
- platform: z4.nativeEnum(Platform),
219
- size: z4.number(),
220
- path: z4.string().nullable()
221
- });
222
- var productSummarySchema = z4.object({
223
- id: z4.string(),
224
- name: z4.string(),
225
- tagline: z4.string(),
226
- website: z4.string().optional(),
227
- iconUrl: z4.string().optional(),
228
- numberOfLicenses: z4.number().optional(),
229
- numberOfTrials: z4.number().optional(),
230
- currentActivations: z4.number().optional(),
231
- maxActivations: z4.number().optional(),
232
- currentVersion: z4.string().nullable(),
233
- downloadsNeedsUser: z4.boolean(),
234
- downloadsNeedsOwnership: z4.boolean(),
235
- downloads: z4.array(downloadSchema).optional()
236
- });
326
+ import { z as z8 } from "zod";
237
327
 
238
328
  // src/licenses/models.ts
239
329
  var LicenseStatus = /* @__PURE__ */ ((LicenseStatus2) => {
@@ -253,21 +343,21 @@ var ActivationMethod = /* @__PURE__ */ ((ActivationMethod2) => {
253
343
  })(ActivationMethod || {});
254
344
 
255
345
  // src/licenses/schemas.ts
256
- var licenseSchema = z5.object({
257
- id: z5.string(),
258
- status: z5.nativeEnum(LicenseStatus),
346
+ var licenseSchema = z8.object({
347
+ id: z8.string(),
348
+ status: z8.nativeEnum(LicenseStatus),
259
349
  product: productSummarySchema.optional(),
260
- activeNumberOfActivations: z5.number(),
261
- maxNumberOfActivations: z5.number(),
262
- createdAt: z5.coerce.date()
350
+ activeNumberOfActivations: z8.number(),
351
+ maxNumberOfActivations: z8.number(),
352
+ createdAt: z8.coerce.date()
263
353
  });
264
- var activationSchema = z5.object({
265
- id: z5.string(),
266
- licenseId: z5.string(),
267
- name: z5.string(),
268
- status: z5.nativeEnum(ActivationStatus),
269
- activationMethod: z5.nativeEnum(ActivationMethod),
270
- lastValidatedAt: z5.coerce.date().nullable()
354
+ var activationSchema = z8.object({
355
+ id: z8.string(),
356
+ licenseId: z8.string(),
357
+ name: z8.string(),
358
+ status: z8.nativeEnum(ActivationStatus),
359
+ activationMethod: z8.nativeEnum(ActivationMethod),
360
+ lastValidatedAt: z8.coerce.date().nullable()
271
361
  });
272
362
 
273
363
  // src/licenses/endpoints.ts
@@ -291,39 +381,7 @@ var LicenseEndpoints = class {
291
381
  };
292
382
 
293
383
  // src/orders/schemas.ts
294
- import { z as z7 } from "zod";
295
-
296
- // src/storefront/schemas.ts
297
- import { z as z6 } from "zod";
298
- var storefrontProductSchema = z6.object({
299
- id: z6.string(),
300
- name: z6.string(),
301
- tagline: z6.string(),
302
- iconUrl: z6.string().nullable(),
303
- owned: z6.boolean(),
304
- defaultVariation: pricingVariationSchema.optional(),
305
- variations: pricingVariationSchema.array().optional(),
306
- type: z6.void().transform(() => "product").pipe(z6.literal("product"))
307
- });
308
- var storefrontBundleSchema = z6.object({
309
- id: z6.string(),
310
- name: z6.string(),
311
- tagline: z6.string(),
312
- iconUrl: z6.string().nullable(),
313
- owned: z6.boolean(),
314
- partial: z6.boolean(),
315
- products: storefrontProductSchema.and(z6.object({
316
- included: z6.boolean()
317
- })).array(),
318
- defaultVariation: pricingVariationSchema.optional(),
319
- variations: pricingVariationSchema.array().optional(),
320
- type: z6.void().transform(() => "bundle").pipe(z6.literal("bundle"))
321
- });
322
- var storefrontSchema = z6.object({
323
- suggestedCurrency: z6.string(),
324
- products: storefrontProductSchema.array(),
325
- bundles: storefrontBundleSchema.array()
326
- });
384
+ import { z as z9 } from "zod";
327
385
 
328
386
  // src/orders/models.ts
329
387
  var OrderStatus = /* @__PURE__ */ ((OrderStatus2) => {
@@ -337,65 +395,65 @@ var OrderStatus = /* @__PURE__ */ ((OrderStatus2) => {
337
395
  })(OrderStatus || {});
338
396
 
339
397
  // src/orders/schemas.ts
340
- var couponSchema = z7.object({
341
- code: z7.string(),
342
- name: z7.string(),
343
- description: z7.string()
398
+ var couponSchema = z9.object({
399
+ code: z9.string(),
400
+ name: z9.string(),
401
+ description: z9.string()
344
402
  });
345
- var percentageOffDiscountSchema2 = z7.object({
346
- type: z7.literal("PercentageOffDiscount"),
347
- name: z7.string(),
348
- description: z7.string().optional(),
349
- percentage: z7.number(),
403
+ var percentageOffDiscountSchema2 = z9.object({
404
+ type: z9.literal("PercentageOffDiscount"),
405
+ name: z9.string(),
406
+ description: z9.string().optional(),
407
+ percentage: z9.number(),
350
408
  total: priceCollectionSchema.optional(),
351
- isExclusive: z7.boolean()
409
+ isExclusive: z9.boolean()
352
410
  });
353
- var flatAmountOffDiscountSchema2 = z7.object({
354
- type: z7.literal("FlatAmountOffDiscount"),
355
- name: z7.string(),
356
- description: z7.string().optional(),
411
+ var flatAmountOffDiscountSchema2 = z9.object({
412
+ type: z9.literal("FlatAmountOffDiscount"),
413
+ name: z9.string(),
414
+ description: z9.string().optional(),
357
415
  total: priceCollectionSchema.optional(),
358
- isExclusive: z7.boolean()
416
+ isExclusive: z9.boolean()
359
417
  });
360
- var discountSchema2 = z7.discriminatedUnion("type", [
418
+ var discountSchema2 = z9.discriminatedUnion("type", [
361
419
  percentageOffDiscountSchema2,
362
420
  flatAmountOffDiscountSchema2
363
421
  ]);
364
- var openProductLineItem = z7.object({
365
- id: z7.string(),
366
- type: z7.literal("Product"),
367
- productId: z7.string(),
368
- quantity: z7.number(),
369
- variationId: z7.string(),
422
+ var openProductLineItem = z9.object({
423
+ id: z9.string(),
424
+ type: z9.literal("Product"),
425
+ productId: z9.string(),
426
+ quantity: z9.number(),
427
+ variationId: z9.string(),
370
428
  price: priceCollectionSchema.optional(),
371
429
  variation: pricingVariationSchema.optional(),
372
430
  product: storefrontProductSchema.optional(),
373
431
  appliedDiscount: discountSchema2.optional()
374
432
  });
375
- var openBundleLineItem = z7.object({
376
- id: z7.string(),
377
- type: z7.literal("Bundle"),
378
- bundleId: z7.string(),
379
- quantity: z7.number(),
380
- variationId: z7.string(),
433
+ var openBundleLineItem = z9.object({
434
+ id: z9.string(),
435
+ type: z9.literal("Bundle"),
436
+ bundleId: z9.string(),
437
+ quantity: z9.number(),
438
+ variationId: z9.string(),
381
439
  price: priceCollectionSchema.optional(),
382
440
  variation: pricingVariationSchema.optional(),
383
441
  bundle: storefrontBundleSchema.optional(),
384
442
  appliedDiscount: discountSchema2.optional()
385
443
  });
386
- var openOrderLineItem = z7.discriminatedUnion("type", [
444
+ var openOrderLineItem = z9.discriminatedUnion("type", [
387
445
  openProductLineItem,
388
446
  openBundleLineItem
389
447
  ]);
390
- var openOrderSchema = z7.object({
391
- id: z7.string(),
392
- status: z7.literal("Open" /* Open */),
393
- currency: z7.string(),
448
+ var openOrderSchema = z9.object({
449
+ id: z9.string(),
450
+ status: z9.literal("Open" /* Open */),
451
+ currency: z9.string(),
394
452
  items: openOrderLineItem.array(),
395
453
  couponsApplied: couponSchema.array(),
396
- checkoutUrl: z7.string().optional()
454
+ checkoutUrl: z9.string().optional()
397
455
  });
398
- var orderSchema = z7.discriminatedUnion("status", [
456
+ var orderSchema = z9.discriminatedUnion("status", [
399
457
  openOrderSchema
400
458
  ]);
401
459
 
@@ -583,13 +641,13 @@ _TokenStore.storageKey = "moonbase_auth";
583
641
  var TokenStore = _TokenStore;
584
642
 
585
643
  // src/vouchers/schemas.ts
586
- import { z as z8 } from "zod";
587
- var voucherSchema = z8.object({
588
- id: z8.string(),
589
- name: z8.string(),
590
- description: z8.string(),
591
- code: z8.string(),
592
- redeemed: z8.boolean(),
644
+ import { z as z10 } from "zod";
645
+ var voucherSchema = z10.object({
646
+ id: z10.string(),
647
+ name: z10.string(),
648
+ description: z10.string(),
649
+ code: z10.string(),
650
+ redeemed: z10.boolean(),
593
651
  redeemsProducts: quantifiable(storefrontProductSchema).array(),
594
652
  redeemsBundles: quantifiable(storefrontBundleSchema).array()
595
653
  });
@@ -624,11 +682,13 @@ var MoonbaseClient = class {
624
682
  this.vouchers = new VoucherEndpoints(api);
625
683
  this.orders = new OrderEndpoints(api);
626
684
  this.licenses = new LicenseEndpoints(api);
685
+ this.activationRequests = new ActivationRequestEndpoints(api);
627
686
  this.products = new ProductEndpoints(api);
628
687
  }
629
688
  };
630
689
  export {
631
690
  ActivationMethod,
691
+ ActivationRequestStatus,
632
692
  ActivationStatus,
633
693
  LicenseStatus,
634
694
  MoonbaseClient,
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.82",
4
+ "version": "0.1.84",
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",