@moonbase.sh/api 0.4.32 → 0.4.34

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,47 +1,116 @@
1
1
  // src/activationRequests/schemas.ts
2
- import { z as z5 } from "zod";
2
+ import { z as z6 } from "zod";
3
3
 
4
4
  // src/licenses/schemas.ts
5
- import { z as z2 } from "zod";
5
+ import { z as z3 } from "zod";
6
6
 
7
7
  // src/customers/schemas.ts
8
+ import { z as z2 } from "zod";
9
+
10
+ // src/globalSchemas.ts
8
11
  import { z } from "zod";
9
- var addressSchema = z.object({
10
- countryCode: z.string(),
11
- streetAddress1: z.string(),
12
- streetAddress2: z.string().nullable(),
13
- locality: z.string().nullable(),
14
- region: z.string().nullable(),
15
- postCode: z.string().nullable()
16
- });
17
- var communicationPreferencesSchema = z.object({
18
- newsletterOptIn: z.boolean()
19
- // productUpdatesOptIn: z.boolean(), // TODO: Enable when relevant
12
+ var userSchema = z.object({
13
+ id: z.string(),
14
+ name: z.string(),
15
+ email: z.string()
16
+ });
17
+ var entityChangeSchema = z.object({
18
+ at: z.coerce.date(),
19
+ by: userSchema
20
+ });
21
+ var moneySchema = z.object({
22
+ currency: z.string(),
23
+ amount: z.number()
24
+ });
25
+ var priceCollectionSchema = z.record(z.number());
26
+ var percentageOffDiscountSchema = z.object({
27
+ type: z.literal("PercentageOffDiscount"),
28
+ percentage: z.number()
29
+ });
30
+ var flatAmountOffDiscountSchema = z.object({
31
+ type: z.literal("FlatAmountOffDiscount"),
32
+ total: priceCollectionSchema
20
33
  });
21
- var customerSchema = z.object({
34
+ var discountSchema = z.discriminatedUnion("type", [
35
+ percentageOffDiscountSchema,
36
+ flatAmountOffDiscountSchema
37
+ ]);
38
+ var dateTimeSpanSchema = z.object({
39
+ from: z.coerce.date().nullable(),
40
+ to: z.coerce.date().nullable()
41
+ });
42
+ var pricingDiscountSchema = z.object({
43
+ name: z.string(),
44
+ description: z.string().nullable(),
45
+ discount: discountSchema,
46
+ applicableVariationIds: z.string().array().nullable(),
47
+ validity: dateTimeSpanSchema.nullable()
48
+ });
49
+ var pricingVariationSchema = z.object({
22
50
  id: z.string(),
23
- externalId: z.string().optional(),
24
51
  name: z.string(),
25
- businessName: z.string().nullable(),
26
- taxId: z.string().nullable(),
27
- email: z.string(),
28
- numberOfLicenses: z.number(),
29
- numberOfTrials: z.number(),
30
- emailConfirmed: z.boolean(),
31
- hasPassword: z.boolean(),
32
- isDeleted: z.boolean(),
33
- ownedProducts: z.string().array().transform((arr) => arr.sort()),
34
- subscribedProducts: z.string().array().transform((arr) => arr.sort()),
52
+ price: priceCollectionSchema
53
+ });
54
+ function paged(itemSchema, api) {
55
+ return z.object({
56
+ items: z.array(itemSchema),
57
+ hasMore: z.boolean(),
58
+ next: z.string().nullable()
59
+ }).transform((page) => ({
60
+ ...page,
61
+ getNext: () => {
62
+ if (!page.hasMore || !page.next)
63
+ throw new Error("Response indicates no more results");
64
+ return api.fetch(page.next).then((response) => paged(itemSchema, api).parse(response.data));
65
+ }
66
+ }));
67
+ }
68
+ function quantifiable(itemSchema) {
69
+ return z.object({
70
+ value: itemSchema,
71
+ quantity: z.number()
72
+ });
73
+ }
74
+
75
+ // src/customers/schemas.ts
76
+ var addressSchema = z2.object({
77
+ countryCode: z2.string(),
78
+ streetAddress1: z2.string(),
79
+ streetAddress2: z2.string().nullable(),
80
+ locality: z2.string().nullable(),
81
+ region: z2.string().nullable(),
82
+ postCode: z2.string().nullable()
83
+ });
84
+ var communicationPreferencesSchema = z2.object({
85
+ newsletterOptIn: z2.boolean()
86
+ // productUpdatesOptIn: z.boolean(), // TODO: Enable when relevant
87
+ });
88
+ var customerSchema = z2.object({
89
+ id: z2.string(),
90
+ externalId: z2.string().optional(),
91
+ name: z2.string(),
92
+ businessName: z2.string().nullable(),
93
+ taxId: z2.string().nullable(),
94
+ email: z2.string(),
95
+ numberOfLicenses: z2.number(),
96
+ numberOfTrials: z2.number(),
97
+ emailConfirmed: z2.boolean(),
98
+ hasPassword: z2.boolean(),
99
+ isDeleted: z2.boolean(),
100
+ ownedProducts: z2.string().array().transform((arr) => arr.sort()),
101
+ subscribedProducts: z2.string().array().transform((arr) => arr.sort()),
35
102
  address: addressSchema.nullable(),
36
- communicationPreferences: communicationPreferencesSchema
103
+ communicationPreferences: communicationPreferencesSchema,
104
+ lastUpdated: entityChangeSchema,
105
+ created: entityChangeSchema
37
106
  });
38
- var importCustomerRequestSchema = z.object({
39
- name: z.string(),
40
- email: z.string(),
41
- externalId: z.string().optional(),
42
- password: z.string().optional(),
107
+ var importCustomerRequestSchema = z2.object({
108
+ name: z2.string(),
109
+ email: z2.string(),
110
+ externalId: z2.string().optional(),
111
+ password: z2.string().optional(),
43
112
  address: addressSchema.optional(),
44
- createdAt: z.date().optional()
113
+ createdAt: z2.date().optional()
45
114
  });
46
115
 
47
116
  // src/licenses/models.ts
@@ -63,61 +132,86 @@ var ActivationMethod = /* @__PURE__ */ ((ActivationMethod2) => {
63
132
  })(ActivationMethod || {});
64
133
 
65
134
  // src/licenses/schemas.ts
66
- var licenseSchema = z2.object({
67
- id: z2.string(),
68
- externalId: z2.string().optional(),
69
- productId: z2.string(),
70
- ownerId: z2.string(),
71
- status: z2.nativeEnum(LicenseStatus),
72
- activeNumberOfActivations: z2.number(),
73
- maxNumberOfActivations: z2.number(),
74
- offlineActivationsAllowed: z2.boolean()
75
- });
76
- var licenseActivationSchema = z2.object({
77
- id: z2.string(),
78
- name: z2.string(),
79
- signature: z2.string(),
80
- status: z2.nativeEnum(ActivationStatus),
81
- activationMethod: z2.nativeEnum(ActivationMethod),
82
- lastValidatedAt: z2.coerce.date(),
135
+ var licenseSourceSchema = z3.discriminatedUnion("type", [
136
+ z3.object({
137
+ type: z3.literal("Order"),
138
+ orderId: z3.string()
139
+ }),
140
+ z3.object({
141
+ type: z3.literal("Subscription"),
142
+ subscriptionId: z3.string()
143
+ }),
144
+ z3.object({
145
+ type: z3.literal("Voucher"),
146
+ voucherId: z3.string(),
147
+ code: z3.string()
148
+ }),
149
+ z3.object({
150
+ type: z3.literal("Fastspring"),
151
+ reference: z3.string(),
152
+ testMode: z3.boolean()
153
+ })
154
+ ]);
155
+ var licenseSchema = z3.object({
156
+ id: z3.string(),
157
+ externalId: z3.string().optional(),
158
+ productId: z3.string(),
159
+ ownerId: z3.string(),
160
+ status: z3.nativeEnum(LicenseStatus),
161
+ activeNumberOfActivations: z3.number(),
162
+ maxNumberOfActivations: z3.number(),
163
+ offlineActivationsAllowed: z3.boolean(),
164
+ source: licenseSourceSchema.nullable(),
165
+ lastUpdated: entityChangeSchema,
166
+ created: entityChangeSchema
167
+ });
168
+ var licenseActivationSchema = z3.object({
169
+ id: z3.string(),
170
+ name: z3.string(),
171
+ signature: z3.string(),
172
+ status: z3.nativeEnum(ActivationStatus),
173
+ activationMethod: z3.nativeEnum(ActivationMethod),
174
+ lastValidatedAt: z3.coerce.date(),
83
175
  license: licenseSchema,
84
- customer: customerSchema.optional()
176
+ customer: customerSchema.optional(),
177
+ lastUpdated: entityChangeSchema,
178
+ created: entityChangeSchema
85
179
  });
86
- var importLicenseRequestSchema = z2.object({
87
- ownerId: z2.string(),
88
- productId: z2.string(),
89
- externalId: z2.string().optional(),
90
- createdAt: z2.date().optional(),
91
- maxNumberOfActivations: z2.number().optional(),
92
- offlineActivationsAllowed: z2.boolean().optional(),
93
- activations: z2.object({
94
- activationMethod: z2.nativeEnum(ActivationMethod),
95
- deviceName: z2.string(),
96
- deviceSignature: z2.string(),
97
- lastValidation: z2.date().optional()
180
+ var importLicenseRequestSchema = z3.object({
181
+ ownerId: z3.string(),
182
+ productId: z3.string(),
183
+ externalId: z3.string().optional(),
184
+ createdAt: z3.date().optional(),
185
+ maxNumberOfActivations: z3.number().optional(),
186
+ offlineActivationsAllowed: z3.boolean().optional(),
187
+ activations: z3.object({
188
+ activationMethod: z3.nativeEnum(ActivationMethod),
189
+ deviceName: z3.string(),
190
+ deviceSignature: z3.string(),
191
+ lastValidation: z3.date().optional()
98
192
  }).array().optional()
99
193
  });
100
- var provisionLicensesRequestRequestSchema = z2.object({
101
- productId: z2.string(),
102
- quantity: z2.number().optional(),
103
- limitPerCustomer: z2.number().optional()
194
+ var provisionLicensesRequestRequestSchema = z3.object({
195
+ productId: z3.string(),
196
+ quantity: z3.number().optional(),
197
+ limitPerCustomer: z3.number().optional()
104
198
  }).array();
105
- var provisionLicensesRequestSchema = z2.union([
106
- z2.object({
107
- ownerId: z2.string(),
199
+ var provisionLicensesRequestSchema = z3.union([
200
+ z3.object({
201
+ ownerId: z3.string(),
108
202
  requests: provisionLicensesRequestRequestSchema
109
203
  }),
110
- z2.object({
111
- customer: z2.object({
112
- name: z2.string(),
113
- email: z2.string()
204
+ z3.object({
205
+ customer: z3.object({
206
+ name: z3.string(),
207
+ email: z3.string()
114
208
  }),
115
209
  requests: provisionLicensesRequestRequestSchema
116
210
  })
117
211
  ]);
118
212
 
119
213
  // src/products/schemas.ts
120
- import { z as z3 } from "zod";
214
+ import { z as z4 } from "zod";
121
215
 
122
216
  // src/products/models.ts
123
217
  var Platform = /* @__PURE__ */ ((Platform2) => {
@@ -136,36 +230,36 @@ var ProductStatus = /* @__PURE__ */ ((ProductStatus2) => {
136
230
  })(ProductStatus || {});
137
231
 
138
232
  // src/products/schemas.ts
139
- var productSchema = z3.object({
140
- id: z3.string(),
141
- name: z3.string(),
142
- tagline: z3.string(),
143
- description: z3.string(),
144
- website: z3.string().nullable(),
145
- iconUrl: z3.string().nullable(),
146
- status: z3.nativeEnum(ProductStatus),
147
- purchasable: z3.boolean(),
148
- currentReleaseVersion: z3.string().nullable()
149
- });
150
- var productReleaseSchema = z3.object({
151
- version: z3.string(),
152
- description: z3.string().nullable(),
153
- publishedAt: z3.coerce.date().nullable(),
154
- downloadUrl: z3.string(),
155
- hostedDownloadUrl: z3.string(),
156
- downloads: z3.object({
157
- name: z3.string(),
158
- key: z3.string(),
159
- platform: z3.nativeEnum(Platform),
160
- size: z3.number(),
161
- downloadUrl: z3.string(),
162
- hostedDownloadUrl: z3.string(),
163
- directUrl: z3.string()
233
+ var productSchema = z4.object({
234
+ id: z4.string(),
235
+ name: z4.string(),
236
+ tagline: z4.string(),
237
+ description: z4.string(),
238
+ website: z4.string().nullable(),
239
+ iconUrl: z4.string().nullable(),
240
+ status: z4.nativeEnum(ProductStatus),
241
+ purchasable: z4.boolean(),
242
+ currentReleaseVersion: z4.string().nullable()
243
+ });
244
+ var productReleaseSchema = z4.object({
245
+ version: z4.string(),
246
+ description: z4.string().nullable(),
247
+ publishedAt: z4.coerce.date().nullable(),
248
+ downloadUrl: z4.string(),
249
+ hostedDownloadUrl: z4.string(),
250
+ downloads: z4.object({
251
+ name: z4.string(),
252
+ key: z4.string(),
253
+ platform: z4.nativeEnum(Platform),
254
+ size: z4.number(),
255
+ downloadUrl: z4.string(),
256
+ hostedDownloadUrl: z4.string(),
257
+ directUrl: z4.string()
164
258
  }).array()
165
259
  });
166
260
 
167
261
  // src/trials/schemas.ts
168
- import { z as z4 } from "zod";
262
+ import { z as z5 } from "zod";
169
263
 
170
264
  // src/trials/models.ts
171
265
  var TrialStatus = /* @__PURE__ */ ((TrialStatus2) => {
@@ -175,26 +269,28 @@ var TrialStatus = /* @__PURE__ */ ((TrialStatus2) => {
175
269
  })(TrialStatus || {});
176
270
 
177
271
  // src/trials/schemas.ts
178
- var trialSchema = z4.object({
179
- id: z4.string(),
180
- externalId: z4.string().optional(),
181
- productId: z4.string(),
182
- deviceName: z4.string(),
183
- deviceSignature: z4.string(),
184
- status: z4.nativeEnum(TrialStatus),
185
- expiresAt: z4.coerce.date(),
186
- lastValidatedAt: z4.coerce.date(),
187
- customer: customerSchema.optional()
188
- });
189
- var importTrialRequestSchema = z4.object({
190
- productId: z4.string(),
191
- externalId: z4.string().optional(),
192
- deviceName: z4.string(),
193
- deviceSignature: z4.string(),
194
- expiresAt: z4.date(),
195
- ownerId: z4.string().optional(),
196
- lastValidation: z4.date().optional(),
197
- createdAt: z4.date().optional()
272
+ var trialSchema = z5.object({
273
+ id: z5.string(),
274
+ externalId: z5.string().optional(),
275
+ productId: z5.string(),
276
+ deviceName: z5.string(),
277
+ deviceSignature: z5.string(),
278
+ status: z5.nativeEnum(TrialStatus),
279
+ expiresAt: z5.coerce.date(),
280
+ lastValidatedAt: z5.coerce.date(),
281
+ customer: customerSchema.optional(),
282
+ lastUpdated: entityChangeSchema,
283
+ created: entityChangeSchema
284
+ });
285
+ var importTrialRequestSchema = z5.object({
286
+ productId: z5.string(),
287
+ externalId: z5.string().optional(),
288
+ deviceName: z5.string(),
289
+ deviceSignature: z5.string(),
290
+ expiresAt: z5.date(),
291
+ ownerId: z5.string().optional(),
292
+ lastValidation: z5.date().optional(),
293
+ createdAt: z5.date().optional()
198
294
  });
199
295
 
200
296
  // src/activationRequests/models.ts
@@ -206,11 +302,11 @@ var ActivationRequestStatus = /* @__PURE__ */ ((ActivationRequestStatus2) => {
206
302
  })(ActivationRequestStatus || {});
207
303
 
208
304
  // src/activationRequests/schemas.ts
209
- var activationRequestSchema = z5.object({
210
- id: z5.string(),
211
- deviceName: z5.string(),
212
- deviceSignature: z5.string(),
213
- status: z5.nativeEnum(ActivationRequestStatus),
305
+ var activationRequestSchema = z6.object({
306
+ id: z6.string(),
307
+ deviceName: z6.string(),
308
+ deviceSignature: z6.string(),
309
+ status: z6.nativeEnum(ActivationRequestStatus),
214
310
  product: productSchema,
215
311
  activation: licenseActivationSchema.optional(),
216
312
  trial: trialSchema.optional()
@@ -231,71 +327,6 @@ var ActivationRequestEndpoints = class {
231
327
  }
232
328
  };
233
329
 
234
- // src/globalSchemas.ts
235
- import { z as z6 } from "zod";
236
- var userSchema = z6.object({
237
- id: z6.string(),
238
- name: z6.string(),
239
- email: z6.string()
240
- });
241
- var entityChangeSchema = z6.object({
242
- at: z6.coerce.date(),
243
- by: userSchema
244
- });
245
- var moneySchema = z6.object({
246
- currency: z6.string(),
247
- amount: z6.number()
248
- });
249
- var priceCollectionSchema = z6.record(z6.number());
250
- var percentageOffDiscountSchema = z6.object({
251
- type: z6.literal("PercentageOffDiscount"),
252
- percentage: z6.number()
253
- });
254
- var flatAmountOffDiscountSchema = z6.object({
255
- type: z6.literal("FlatAmountOffDiscount"),
256
- total: priceCollectionSchema
257
- });
258
- var discountSchema = z6.discriminatedUnion("type", [
259
- percentageOffDiscountSchema,
260
- flatAmountOffDiscountSchema
261
- ]);
262
- var dateTimeSpanSchema = z6.object({
263
- from: z6.coerce.date().nullable(),
264
- to: z6.coerce.date().nullable()
265
- });
266
- var pricingDiscountSchema = z6.object({
267
- name: z6.string(),
268
- description: z6.string().nullable(),
269
- discount: discountSchema,
270
- applicableVariationIds: z6.string().array().nullable(),
271
- validity: dateTimeSpanSchema.nullable()
272
- });
273
- var pricingVariationSchema = z6.object({
274
- id: z6.string(),
275
- name: z6.string(),
276
- price: priceCollectionSchema
277
- });
278
- function paged(itemSchema, api) {
279
- return z6.object({
280
- items: z6.array(itemSchema),
281
- hasMore: z6.boolean(),
282
- next: z6.string().nullable()
283
- }).transform((page) => ({
284
- ...page,
285
- getNext: () => {
286
- if (!page.hasMore || !page.next)
287
- throw new Error("Response indicates no more results");
288
- return api.fetch(page.next).then((response) => paged(itemSchema, api).parse(response.data));
289
- }
290
- }));
291
- }
292
- function quantifiable(itemSchema) {
293
- return z6.object({
294
- value: itemSchema,
295
- quantity: z6.number()
296
- });
297
- }
298
-
299
330
  // src/utils/api.ts
300
331
  import fetch from "cross-fetch";
301
332
 
@@ -455,8 +486,12 @@ var LicenseEndpoints = class {
455
486
  const response = await this.api.fetch(`/api/licenses/${licenseId}/revoke`, "POST");
456
487
  return licenseSchema.parse(response.data);
457
488
  }
458
- async queryActivations(licenseId, opts) {
459
- const response = await this.api.fetch(`/api/licenses/${licenseId}/activations?${objectToQuery(opts)}`);
489
+ async queryActivations(licenseIdOrOpt, opts) {
490
+ if (licenseIdOrOpt && typeof licenseIdOrOpt === "string") {
491
+ const response2 = await this.api.fetch(`/api/licenses/${licenseIdOrOpt}/activations?${objectToQuery(opts)}`);
492
+ return paged(licenseActivationSchema, this.api).parse(response2.data);
493
+ }
494
+ const response = await this.api.fetch(`/api/license-activations?${objectToQuery(opts)}`);
460
495
  return paged(licenseActivationSchema, this.api).parse(response.data);
461
496
  }
462
497
  async getActivation(licenseId, activationId) {
@@ -695,7 +730,9 @@ var voucherSchema = z10.object({
695
730
  numberOfCodes: z10.number(),
696
731
  numberOfRedemptions: z10.number(),
697
732
  redeemsProducts: quantifiable(productSchema).array(),
698
- redeemsBundles: quantifiable(bundleSchema).array()
733
+ redeemsBundles: quantifiable(bundleSchema).array(),
734
+ lastUpdated: entityChangeSchema,
735
+ created: entityChangeSchema
699
736
  });
700
737
  var createVoucherRequestSchema = z10.object({
701
738
  name: z10.string(),
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@moonbase.sh/api",
3
3
  "type": "module",
4
- "version": "0.4.32",
4
+ "version": "0.4.34",
5
5
  "description": "Package to let you integrate backends with Moonbase.sh as payment and delivery provider",
6
6
  "author": "Tobias Lønnerød Madsen <m@dsen.tv>",
7
7
  "license": "MIT",