@moonbase.sh/licensing 3.2.3 → 3.3.0
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/README.md +152 -4
- package/dist/index.cjs +383 -10
- package/dist/index.d.cts +1151 -8
- package/dist/index.d.ts +1151 -8
- package/dist/index.js +379 -10
- package/package.json +3 -2
- package/release-access-vectors.json +150 -0
package/dist/index.cjs
CHANGED
|
@@ -47,13 +47,17 @@ __export(index_exports, {
|
|
|
47
47
|
MoonbaseDeviceIdResolver: () => MoonbaseDeviceIdResolver,
|
|
48
48
|
MoonbaseError: () => MoonbaseError,
|
|
49
49
|
MoonbaseLicensing: () => MoonbaseLicensing,
|
|
50
|
+
ReleaseNotCoveredError: () => ReleaseNotCoveredError,
|
|
50
51
|
buildFingerprintMaterial: () => buildFingerprintMaterial,
|
|
51
52
|
canonicalizeParams: () => canonicalizeParams,
|
|
52
53
|
canonicalizeValue: () => canonicalizeValue,
|
|
54
|
+
coversVersion: () => coversVersion,
|
|
53
55
|
defaultDeviceIdentityReader: () => defaultDeviceIdentityReader,
|
|
54
56
|
fingerprintDeviceId: () => fingerprintDeviceId,
|
|
55
57
|
fingerprintDigest: () => fingerprintDigest,
|
|
58
|
+
hasSubProduct: () => hasSubProduct,
|
|
56
59
|
identitySource: () => identitySource,
|
|
60
|
+
parseAppVersion: () => parseAppVersion,
|
|
57
61
|
parseDeviceIdStamp: () => parseDeviceIdStamp,
|
|
58
62
|
parseIoregPlatformUuid: () => parseIoregPlatformUuid,
|
|
59
63
|
parseSmbiosParams: () => parseSmbiosParams,
|
|
@@ -69,7 +73,7 @@ var import_node_process3 = __toESM(require("process"), 1);
|
|
|
69
73
|
var import_cross_fetch = __toESM(require("cross-fetch"), 1);
|
|
70
74
|
|
|
71
75
|
// package.json
|
|
72
|
-
var version = "3.
|
|
76
|
+
var version = "3.3.0";
|
|
73
77
|
|
|
74
78
|
// src/errors.ts
|
|
75
79
|
var ErrorType = /* @__PURE__ */ ((ErrorType2) => {
|
|
@@ -83,6 +87,7 @@ var ErrorType = /* @__PURE__ */ ((ErrorType2) => {
|
|
|
83
87
|
ErrorType2["LicenseDeviceMismatch"] = "LicenseDeviceMismatch";
|
|
84
88
|
ErrorType2["DeviceIdentityUnavailable"] = "DeviceIdentityUnavailable";
|
|
85
89
|
ErrorType2["StoreClosed"] = "StoreClosed";
|
|
90
|
+
ErrorType2["ReleaseNotCovered"] = "ReleaseNotCovered";
|
|
86
91
|
return ErrorType2;
|
|
87
92
|
})(ErrorType || {});
|
|
88
93
|
var MoonbaseError = class extends Error {
|
|
@@ -107,6 +112,17 @@ var InsufficientDeviceIdentityError = class extends MoonbaseError {
|
|
|
107
112
|
this.name = "InsufficientDeviceIdentityError";
|
|
108
113
|
}
|
|
109
114
|
};
|
|
115
|
+
var ReleaseNotCoveredError = class extends MoonbaseError {
|
|
116
|
+
constructor(title, detail, details = {}) {
|
|
117
|
+
var _a, _b;
|
|
118
|
+
super(title, detail, "ReleaseNotCovered" /* ReleaseNotCovered */);
|
|
119
|
+
this.name = "ReleaseNotCoveredError";
|
|
120
|
+
this.license = details.license;
|
|
121
|
+
this.appVersion = details.appVersion;
|
|
122
|
+
this.upgradeUrl = details.upgradeUrl;
|
|
123
|
+
this.releaseAccess = (_b = details.releaseAccess) != null ? _b : (_a = details.license) == null ? void 0 : _a.releaseAccess;
|
|
124
|
+
}
|
|
125
|
+
};
|
|
110
126
|
|
|
111
127
|
// src/schemas.ts
|
|
112
128
|
var import_zod = require("zod");
|
|
@@ -141,20 +157,168 @@ var userSchema = import_zod.z.object({
|
|
|
141
157
|
email: import_zod.z.string(),
|
|
142
158
|
properties: import_zod.z.record(import_zod.z.unknown()).nullish()
|
|
143
159
|
});
|
|
160
|
+
var subProductSchema = import_zod.z.object({
|
|
161
|
+
/** The sub-product's own part of its product ID: `addon` for `product.addon`. */
|
|
162
|
+
id: import_zod.z.string(),
|
|
163
|
+
/**
|
|
164
|
+
* Whether it may be unlocked on this device, as of when the license was
|
|
165
|
+
* issued: the device holds a seat of it, or its trial has not run out. A
|
|
166
|
+
* sub-product the customer owns, but with every seat taken elsewhere, is
|
|
167
|
+
* listed and not active.
|
|
168
|
+
*/
|
|
169
|
+
active: import_zod.z.boolean(),
|
|
170
|
+
/** Whether a trial backs it rather than a license the customer owns. */
|
|
171
|
+
trial: import_zod.z.boolean(),
|
|
172
|
+
/**
|
|
173
|
+
* Its seat on this device was revoked, by the customer or the merchant, so
|
|
174
|
+
* validating does not take it back: offer to activate it again with
|
|
175
|
+
* `client.activateSubProduct`.
|
|
176
|
+
*/
|
|
177
|
+
revoked: import_zod.z.boolean().default(false),
|
|
178
|
+
/** When it ends. Absent when it never does. */
|
|
179
|
+
expiresAt: import_zod.z.coerce.date().nullish(),
|
|
180
|
+
/** Seats across the customer's licenses for it. Absent in offline licenses and for trials. */
|
|
181
|
+
seats: import_zod.z.object({
|
|
182
|
+
total: import_zod.z.number(),
|
|
183
|
+
used: import_zod.z.number(),
|
|
184
|
+
remaining: import_zod.z.number()
|
|
185
|
+
}).nullish()
|
|
186
|
+
});
|
|
187
|
+
var subProductPricingSchema = import_zod.z.object({
|
|
188
|
+
id: import_zod.z.string(),
|
|
189
|
+
name: import_zod.z.string(),
|
|
190
|
+
/** What it costs before discounts, by currency code. */
|
|
191
|
+
originalPrice: import_zod.z.record(import_zod.z.number()),
|
|
192
|
+
/** What it costs now, by currency code, after any discount. */
|
|
193
|
+
price: import_zod.z.record(import_zod.z.number()),
|
|
194
|
+
hasDiscount: import_zod.z.boolean(),
|
|
195
|
+
/** `OneOff`, or `Recurring` for a subscription, with how often it renews. */
|
|
196
|
+
recurrence: import_zod.z.object({
|
|
197
|
+
type: import_zod.z.string(),
|
|
198
|
+
cycleLength: import_zod.z.string().nullish()
|
|
199
|
+
}).nullish()
|
|
200
|
+
});
|
|
201
|
+
var subProductCatalogEntrySchema = import_zod.z.object({
|
|
202
|
+
/** The sub-product's own part of its product ID, as {@link License.subProducts} names it. */
|
|
203
|
+
id: import_zod.z.string(),
|
|
204
|
+
/** The sub-product, with its prices when it is for sale, and whether the customer has it. */
|
|
205
|
+
product: import_zod.z.object({
|
|
206
|
+
/** The sub-product's whole product ID. */
|
|
207
|
+
id: import_zod.z.string(),
|
|
208
|
+
name: import_zod.z.string(),
|
|
209
|
+
tagline: import_zod.z.string().nullish(),
|
|
210
|
+
description: import_zod.z.string().nullish(),
|
|
211
|
+
website: import_zod.z.string().nullish(),
|
|
212
|
+
iconUrl: import_zod.z.string().nullish(),
|
|
213
|
+
owned: import_zod.z.boolean(),
|
|
214
|
+
subscribed: import_zod.z.boolean(),
|
|
215
|
+
/** The price to show first. Absent when it is not for sale. */
|
|
216
|
+
defaultVariation: subProductPricingSchema.nullish(),
|
|
217
|
+
/** Every way it is sold. Absent when it is not for sale. */
|
|
218
|
+
variations: import_zod.z.array(subProductPricingSchema).nullish()
|
|
219
|
+
}),
|
|
220
|
+
/** Whether it is included in the product's license, so the license reports it. */
|
|
221
|
+
includedInLicense: import_zod.z.boolean(),
|
|
222
|
+
/**
|
|
223
|
+
* Whether to unlock it on this device. For a sub-product included in the
|
|
224
|
+
* license, as {@link hasSubProduct} would say. For any other, whether the
|
|
225
|
+
* customer owns or subscribes to it.
|
|
226
|
+
*/
|
|
227
|
+
active: import_zod.z.boolean(),
|
|
228
|
+
/**
|
|
229
|
+
* Its seat on this device was revoked, so validating does not take it back:
|
|
230
|
+
* offer to activate it again with `client.activateSubProduct`.
|
|
231
|
+
*/
|
|
232
|
+
revoked: import_zod.z.boolean().catch(false),
|
|
233
|
+
/** When the license or trial behind it ends, for one included in the license. */
|
|
234
|
+
expiresAt: import_zod.z.coerce.date().nullish(),
|
|
235
|
+
/** Seats across the customer's licenses for it, for one included in the license that they own. */
|
|
236
|
+
seats: import_zod.z.object({
|
|
237
|
+
total: import_zod.z.number(),
|
|
238
|
+
used: import_zod.z.number(),
|
|
239
|
+
remaining: import_zod.z.number()
|
|
240
|
+
}).nullish(),
|
|
241
|
+
/** Its trial on this device, or whether one can be started. Absent when it offers none. */
|
|
242
|
+
trial: import_zod.z.object({
|
|
243
|
+
/**
|
|
244
|
+
* `Available`: `requestSubProductTrial` can start one now. `Active`: the
|
|
245
|
+
* device's trial is running. `Expired`: it has ended. `Unavailable`: not
|
|
246
|
+
* for this device now (not included in the license, owned, a trial or
|
|
247
|
+
* offline license, or a newsletter opt-in is missing), which is also what
|
|
248
|
+
* a status this version does not know reads as.
|
|
249
|
+
*/
|
|
250
|
+
status: import_zod.z.enum(["Available", "Unavailable", "Active", "Expired"]).catch("Unavailable"),
|
|
251
|
+
/** How long a trial lasts. Absent when its trials never expire. */
|
|
252
|
+
numberOfDays: import_zod.z.number().nullish(),
|
|
253
|
+
/** When the device's trial ends. Absent when it has none, or one that never expires. */
|
|
254
|
+
expiresAt: import_zod.z.coerce.date().nullish(),
|
|
255
|
+
/** The trial needs the customer to opt in to the newsletter, which they have not. */
|
|
256
|
+
requiresNewsletterOptIn: import_zod.z.boolean().catch(false)
|
|
257
|
+
}).nullish(),
|
|
258
|
+
/** Where the customer buys it, when it is for sale. Add `?variation={id}` for one of its variations. */
|
|
259
|
+
buyUrl: import_zod.z.string().nullish()
|
|
260
|
+
});
|
|
261
|
+
var subProductCatalogSchema = import_zod.z.object({
|
|
262
|
+
/** The currency to show prices in, as the store suggests it for the customer. */
|
|
263
|
+
currency: import_zod.z.string(),
|
|
264
|
+
/**
|
|
265
|
+
* The sub-products the customer can do something with: those they own or
|
|
266
|
+
* subscribe to, those on sale, and those whose trial can be started or is
|
|
267
|
+
* running on this device.
|
|
268
|
+
*/
|
|
269
|
+
subProducts: import_zod.z.array(subProductCatalogEntrySchema)
|
|
270
|
+
});
|
|
271
|
+
var releaseAccessSchema = import_zod.z.object({
|
|
272
|
+
/**
|
|
273
|
+
* Releases published until then are covered, and every version while it has
|
|
274
|
+
* not passed: "12 months of updates".
|
|
275
|
+
*/
|
|
276
|
+
updatesUntil: import_zod.z.coerce.date().optional(),
|
|
277
|
+
/** Every version whose major is at most this is covered: "up to 2.x". */
|
|
278
|
+
upToMajor: import_zod.z.number().optional(),
|
|
279
|
+
/**
|
|
280
|
+
* Once `updatesUntil` has passed, the last version published before it
|
|
281
|
+
* (`MAJOR.MINOR.PATCH`), which is covered along with every older one. Absent
|
|
282
|
+
* while updates last, and when nothing was published before they ended.
|
|
283
|
+
*/
|
|
284
|
+
upToVersion: import_zod.z.string().optional()
|
|
285
|
+
});
|
|
144
286
|
var licenseSchema = import_zod.z.object({
|
|
145
287
|
id: import_zod.z.string(),
|
|
146
288
|
trial: import_zod.z.boolean(),
|
|
147
289
|
activationMethod: import_zod.z.nativeEnum(ActivationMethod),
|
|
148
290
|
product: productSchema,
|
|
149
291
|
ownedSubProductIds: import_zod.z.array(import_zod.z.string()).default([]),
|
|
292
|
+
/**
|
|
293
|
+
* The sub-products included in the product's license that the customer owns
|
|
294
|
+
* or trials, each with whether it may be unlocked on this device. Empty for a
|
|
295
|
+
* trial license and for products without such sub-products.
|
|
296
|
+
*/
|
|
297
|
+
subProducts: import_zod.z.array(subProductSchema).optional(),
|
|
150
298
|
subscriptionId: import_zod.z.string().nullish(),
|
|
151
299
|
issuedAt: import_zod.z.coerce.date(),
|
|
152
300
|
issuedTo: userSchema,
|
|
153
301
|
expiresAt: import_zod.z.coerce.date().nullish(),
|
|
154
302
|
validatedAt: import_zod.z.coerce.date(),
|
|
303
|
+
/** Which versions of the app the license covers. Absent when it covers every version. */
|
|
304
|
+
releaseAccess: releaseAccessSchema.optional(),
|
|
155
305
|
properties: import_zod.z.record(import_zod.z.unknown()).nullish(),
|
|
156
306
|
token: import_zod.z.string()
|
|
157
307
|
});
|
|
308
|
+
var apiDateSchema = import_zod.z.string().transform((value) => new Date(/T[^Z+-]*$/i.test(value) ? `${value}Z` : value)).pipe(import_zod.z.date());
|
|
309
|
+
var releaseNotCoveredProblemSchema = import_zod.z.object({
|
|
310
|
+
/** On validation, the license freshly issued, for the app to keep. */
|
|
311
|
+
license: import_zod.z.string().nullish().catch(void 0),
|
|
312
|
+
/** The version the app said it runs, as Moonbase read it. */
|
|
313
|
+
appVersion: import_zod.z.string().nullish().catch(void 0),
|
|
314
|
+
/** Where the customer buys the upgrade. */
|
|
315
|
+
upgradeUrl: import_zod.z.string().nullish().catch(void 0),
|
|
316
|
+
releaseAccess: import_zod.z.object({
|
|
317
|
+
updatesUntil: apiDateSchema.nullish().catch(void 0),
|
|
318
|
+
upToMajor: import_zod.z.number().nullish().catch(void 0),
|
|
319
|
+
upToVersion: import_zod.z.string().nullish().catch(void 0)
|
|
320
|
+
}).nullish().catch(void 0)
|
|
321
|
+
});
|
|
158
322
|
|
|
159
323
|
// src/client.ts
|
|
160
324
|
var defaultFetchOptions = {
|
|
@@ -183,7 +347,7 @@ var LicenseClient = class {
|
|
|
183
347
|
body: JSON.stringify(content)
|
|
184
348
|
});
|
|
185
349
|
if (response.status >= 400) {
|
|
186
|
-
throw await errorFromResponse(response);
|
|
350
|
+
throw await errorFromResponse(response, this.licenseValidator);
|
|
187
351
|
}
|
|
188
352
|
try {
|
|
189
353
|
return activationRequestResponseSchema.parse(await response.json());
|
|
@@ -219,6 +383,55 @@ var LicenseClient = class {
|
|
|
219
383
|
});
|
|
220
384
|
return await this.handleLicenseResponse(response);
|
|
221
385
|
}
|
|
386
|
+
async activateSubProduct(license, subProductId) {
|
|
387
|
+
const response = await (0, import_cross_fetch.default)(`${this.configuration.endpoint}/api/client/licenses/${this.configuration.productId}/sub-products/${encodeURIComponent(subProductId)}/activate${this.buildQueryString()}`, {
|
|
388
|
+
...defaultFetchOptions,
|
|
389
|
+
method: "POST",
|
|
390
|
+
headers: {
|
|
391
|
+
...defaultFetchOptions.headers,
|
|
392
|
+
"Content-Type": "text/plain"
|
|
393
|
+
},
|
|
394
|
+
body: license.token
|
|
395
|
+
});
|
|
396
|
+
return await this.handleLicenseResponse(response);
|
|
397
|
+
}
|
|
398
|
+
async requestSubProductTrial(license, subProductId) {
|
|
399
|
+
const response = await (0, import_cross_fetch.default)(`${this.configuration.endpoint}/api/client/licenses/${this.configuration.productId}/sub-products/${encodeURIComponent(subProductId)}/trial${this.buildQueryString()}`, {
|
|
400
|
+
...defaultFetchOptions,
|
|
401
|
+
method: "POST",
|
|
402
|
+
headers: {
|
|
403
|
+
...defaultFetchOptions.headers,
|
|
404
|
+
"Content-Type": "text/plain"
|
|
405
|
+
},
|
|
406
|
+
body: license.token
|
|
407
|
+
});
|
|
408
|
+
return await this.handleLicenseResponse(response);
|
|
409
|
+
}
|
|
410
|
+
async listSubProducts(license) {
|
|
411
|
+
const response = await (0, import_cross_fetch.default)(`${this.configuration.endpoint}/api/client/licenses/${this.configuration.productId}/sub-products`, {
|
|
412
|
+
...defaultFetchOptions,
|
|
413
|
+
method: "POST",
|
|
414
|
+
headers: {
|
|
415
|
+
...defaultFetchOptions.headers,
|
|
416
|
+
"Content-Type": "text/plain"
|
|
417
|
+
},
|
|
418
|
+
body: license.token
|
|
419
|
+
});
|
|
420
|
+
if (response.status >= 400) {
|
|
421
|
+
throw await errorFromResponse(response, this.licenseValidator);
|
|
422
|
+
}
|
|
423
|
+
try {
|
|
424
|
+
return subProductCatalogSchema.parse(await response.json());
|
|
425
|
+
} catch (err) {
|
|
426
|
+
const error = err;
|
|
427
|
+
throw new MoonbaseError(
|
|
428
|
+
"Could not list sub-products",
|
|
429
|
+
error.message,
|
|
430
|
+
"ApiError" /* ApiError */,
|
|
431
|
+
error
|
|
432
|
+
);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
222
435
|
async validateLicense(license) {
|
|
223
436
|
const response = await (0, import_cross_fetch.default)(`${this.configuration.endpoint}/api/client/licenses/${this.configuration.productId}/validate${this.buildQueryString()}`, {
|
|
224
437
|
...defaultFetchOptions,
|
|
@@ -232,9 +445,10 @@ var LicenseClient = class {
|
|
|
232
445
|
return await this.handleLicenseResponse(response);
|
|
233
446
|
}
|
|
234
447
|
async validateRawLicense(rawLicense) {
|
|
235
|
-
const
|
|
448
|
+
const token = rawLicense.toString("utf8");
|
|
449
|
+
const license = await this.licenseValidator.validateLicense(token, { enforceReleaseAccess: false });
|
|
236
450
|
if (license.activationMethod === "Offline" /* Offline */)
|
|
237
|
-
return
|
|
451
|
+
return await this.licenseValidator.validateLicense(token);
|
|
238
452
|
return await this.validateLicense(license);
|
|
239
453
|
}
|
|
240
454
|
async revokeLicense(license) {
|
|
@@ -248,12 +462,12 @@ var LicenseClient = class {
|
|
|
248
462
|
body: license.token
|
|
249
463
|
});
|
|
250
464
|
if (response.status >= 400) {
|
|
251
|
-
throw await errorFromResponse(response);
|
|
465
|
+
throw await errorFromResponse(response, this.licenseValidator);
|
|
252
466
|
}
|
|
253
467
|
}
|
|
254
468
|
async handleLicenseResponse(response) {
|
|
255
469
|
if (response.status >= 400) {
|
|
256
|
-
throw await errorFromResponse(response);
|
|
470
|
+
throw await errorFromResponse(response, this.licenseValidator);
|
|
257
471
|
}
|
|
258
472
|
return await this.licenseValidator.validateLicense(await response.text());
|
|
259
473
|
}
|
|
@@ -271,6 +485,8 @@ var LicenseClient = class {
|
|
|
271
485
|
parts.push(`meta[${encodeURIComponent(key)}]=${encodeURIComponent(value)}`);
|
|
272
486
|
}
|
|
273
487
|
}
|
|
488
|
+
if (this.configuration.autoActivateSubProducts === false)
|
|
489
|
+
parts.push("autoActivateSubProducts=false");
|
|
274
490
|
return `?${parts.join("&")}`;
|
|
275
491
|
}
|
|
276
492
|
};
|
|
@@ -280,9 +496,10 @@ var licenseErrorTypes = /* @__PURE__ */ new Set([
|
|
|
280
496
|
"LicenseRevoked" /* LicenseRevoked */,
|
|
281
497
|
"LicenseActivationRevoked" /* LicenseActivationRevoked */,
|
|
282
498
|
"LicenseExpired" /* LicenseExpired */,
|
|
283
|
-
"StoreClosed" /* StoreClosed
|
|
499
|
+
"StoreClosed" /* StoreClosed */,
|
|
500
|
+
"ReleaseNotCovered" /* ReleaseNotCovered */
|
|
284
501
|
]);
|
|
285
|
-
async function errorFromResponse(response) {
|
|
502
|
+
async function errorFromResponse(response, licenseValidator) {
|
|
286
503
|
const fallback = new MoonbaseError(
|
|
287
504
|
"Request not successful",
|
|
288
505
|
`The API responded with a ${response.status} ${response.statusText} response`,
|
|
@@ -298,12 +515,41 @@ async function errorFromResponse(response) {
|
|
|
298
515
|
if (!problem.success)
|
|
299
516
|
return fallback;
|
|
300
517
|
const { title, detail, errorType } = problem.data;
|
|
518
|
+
if (errorType === "ReleaseNotCovered" /* ReleaseNotCovered */)
|
|
519
|
+
return await releaseNotCoveredError(body, title != null ? title : "Version not covered", detail != null ? detail : fallback.detail, licenseValidator);
|
|
301
520
|
return new MoonbaseError(
|
|
302
521
|
title != null ? title : fallback.title,
|
|
303
522
|
detail != null ? detail : fallback.detail,
|
|
304
523
|
errorType && licenseErrorTypes.has(errorType) ? errorType : "ApiError" /* ApiError */
|
|
305
524
|
);
|
|
306
525
|
}
|
|
526
|
+
async function releaseNotCoveredError(body, title, detail, licenseValidator) {
|
|
527
|
+
const problem = releaseNotCoveredProblemSchema.safeParse(body);
|
|
528
|
+
const { license: token, appVersion, upgradeUrl, releaseAccess } = problem.success ? problem.data : {};
|
|
529
|
+
let license;
|
|
530
|
+
if (token) {
|
|
531
|
+
try {
|
|
532
|
+
license = await licenseValidator.validateLicense(token, { enforceReleaseAccess: false });
|
|
533
|
+
} catch (e) {
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
return new ReleaseNotCoveredError(title, detail, {
|
|
537
|
+
license,
|
|
538
|
+
appVersion: appVersion != null ? appVersion : void 0,
|
|
539
|
+
upgradeUrl: upgradeUrl != null ? upgradeUrl : void 0,
|
|
540
|
+
releaseAccess: releaseAccessFrom(releaseAccess)
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
function releaseAccessFrom(problem) {
|
|
544
|
+
const releaseAccess = {};
|
|
545
|
+
if (problem == null ? void 0 : problem.updatesUntil)
|
|
546
|
+
releaseAccess.updatesUntil = problem.updatesUntil;
|
|
547
|
+
if (typeof (problem == null ? void 0 : problem.upToMajor) === "number")
|
|
548
|
+
releaseAccess.upToMajor = problem.upToMajor;
|
|
549
|
+
if (problem == null ? void 0 : problem.upToVersion)
|
|
550
|
+
releaseAccess.upToVersion = problem.upToVersion;
|
|
551
|
+
return Object.keys(releaseAccess).length > 0 ? releaseAccess : void 0;
|
|
552
|
+
}
|
|
307
553
|
|
|
308
554
|
// src/deviceIdResolver.ts
|
|
309
555
|
var import_node_child_process2 = __toESM(require("child_process"), 1);
|
|
@@ -814,6 +1060,59 @@ var FileLicenseStore = class {
|
|
|
814
1060
|
// src/validator.ts
|
|
815
1061
|
var import_jsonwebtoken = __toESM(require("jsonwebtoken"), 1);
|
|
816
1062
|
var import_zod2 = require("zod");
|
|
1063
|
+
|
|
1064
|
+
// src/releaseAccess.ts
|
|
1065
|
+
var maxVersionPart = 9999999;
|
|
1066
|
+
function parseAppVersion(version2) {
|
|
1067
|
+
let text = version2 == null ? void 0 : version2.trim();
|
|
1068
|
+
if (!text)
|
|
1069
|
+
return null;
|
|
1070
|
+
if (text.startsWith("v") || text.startsWith("V"))
|
|
1071
|
+
text = text.slice(1);
|
|
1072
|
+
const suffix = text.search(/[-+ ]/);
|
|
1073
|
+
if (suffix >= 0)
|
|
1074
|
+
text = text.slice(0, suffix);
|
|
1075
|
+
const parts = text.split(".");
|
|
1076
|
+
if (parts.length < 2 || parts.length > 4)
|
|
1077
|
+
return null;
|
|
1078
|
+
const numbers = [0, 0, 0];
|
|
1079
|
+
for (const [index, part] of parts.entries()) {
|
|
1080
|
+
if (!/^\d+$/.test(part))
|
|
1081
|
+
return null;
|
|
1082
|
+
const number = Number(part);
|
|
1083
|
+
if (number > maxVersionPart)
|
|
1084
|
+
return null;
|
|
1085
|
+
if (index < 3)
|
|
1086
|
+
numbers[index] = number;
|
|
1087
|
+
}
|
|
1088
|
+
return { major: numbers[0], minor: numbers[1], patch: numbers[2] };
|
|
1089
|
+
}
|
|
1090
|
+
function compareVersions(a, b) {
|
|
1091
|
+
return a.major - b.major || a.minor - b.minor || a.patch - b.patch;
|
|
1092
|
+
}
|
|
1093
|
+
function coversVersion(license, version2, now = /* @__PURE__ */ new Date()) {
|
|
1094
|
+
var _a;
|
|
1095
|
+
const { updatesUntil, upToMajor, upToVersion } = (_a = license.releaseAccess) != null ? _a : {};
|
|
1096
|
+
if (updatesUntil === void 0 && upToMajor === void 0)
|
|
1097
|
+
return true;
|
|
1098
|
+
const appVersion = parseAppVersion(version2);
|
|
1099
|
+
if (!appVersion)
|
|
1100
|
+
return true;
|
|
1101
|
+
if (upToMajor !== void 0 && appVersion.major <= upToMajor)
|
|
1102
|
+
return true;
|
|
1103
|
+
if (updatesUntil === void 0)
|
|
1104
|
+
return false;
|
|
1105
|
+
if (now.getTime() <= updatesUntil.getTime())
|
|
1106
|
+
return true;
|
|
1107
|
+
const lastCovered = parseAppVersion(upToVersion);
|
|
1108
|
+
return !lastCovered || compareVersions(appVersion, lastCovered) <= 0;
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
// src/validator.ts
|
|
1112
|
+
var integerClaimSchema = import_zod2.z.union([
|
|
1113
|
+
import_zod2.z.number().int(),
|
|
1114
|
+
import_zod2.z.string().regex(/^-?\d+$/).transform(Number)
|
|
1115
|
+
]).nullish().catch(void 0);
|
|
817
1116
|
var licenseClaimsSchema = import_zod2.z.object({
|
|
818
1117
|
["l:id" /* LicenseId */]: import_zod2.z.string(),
|
|
819
1118
|
["trial" /* Trial */]: import_zod2.z.string().or(import_zod2.z.boolean()).transform((v) => v === true || v === "true").pipe(import_zod2.z.boolean()),
|
|
@@ -826,6 +1125,7 @@ var licenseClaimsSchema = import_zod2.z.object({
|
|
|
826
1125
|
["p:name" /* ProductName */]: import_zod2.z.string(),
|
|
827
1126
|
["p:rel" /* ProductReleaseVersion */]: import_zod2.z.string().nullish(),
|
|
828
1127
|
["sp:owned" /* OwnedSubProducts */]: import_zod2.z.string().nullish().transform((v) => v ? v.split(",") : []),
|
|
1128
|
+
["sp" /* SubProducts */]: import_zod2.z.array(import_zod2.z.unknown()).nullish().transform(readSubProducts),
|
|
829
1129
|
["s:id" /* SubscriptionId */]: import_zod2.z.string().nullish(),
|
|
830
1130
|
["u:id" /* UserId */]: import_zod2.z.string(),
|
|
831
1131
|
["u:name" /* UserName */]: import_zod2.z.string(),
|
|
@@ -833,14 +1133,18 @@ var licenseClaimsSchema = import_zod2.z.object({
|
|
|
833
1133
|
["p:properties" /* ProductProperties */]: import_zod2.z.record(import_zod2.z.unknown()).nullish(),
|
|
834
1134
|
["u:properties" /* UserProperties */]: import_zod2.z.record(import_zod2.z.unknown()).nullish(),
|
|
835
1135
|
["l:properties" /* LicenseProperties */]: import_zod2.z.record(import_zod2.z.unknown()).nullish(),
|
|
836
|
-
["t:properties" /* TrialProperties */]: import_zod2.z.record(import_zod2.z.unknown()).nullish()
|
|
1136
|
+
["t:properties" /* TrialProperties */]: import_zod2.z.record(import_zod2.z.unknown()).nullish(),
|
|
1137
|
+
["l:rel:until" /* ReleaseAccessUpdatesUntil */]: integerClaimSchema,
|
|
1138
|
+
["l:rel:major" /* ReleaseAccessUpToMajor */]: integerClaimSchema,
|
|
1139
|
+
["l:rel:upto" /* ReleaseAccessUpToVersion */]: import_zod2.z.string().nullish().catch(void 0)
|
|
837
1140
|
});
|
|
838
1141
|
var LicenseValidator = class {
|
|
839
1142
|
constructor(configuration, deviceIdResolver) {
|
|
840
1143
|
this.configuration = configuration;
|
|
841
1144
|
this.deviceIdResolver = deviceIdResolver;
|
|
842
1145
|
}
|
|
843
|
-
async validateLicense(token) {
|
|
1146
|
+
async validateLicense(token, options) {
|
|
1147
|
+
var _a, _b;
|
|
844
1148
|
const [license, claims] = await this.parseLicenseToken(token);
|
|
845
1149
|
if (license.expiresAt && license.expiresAt < /* @__PURE__ */ new Date()) {
|
|
846
1150
|
throw new MoonbaseError(
|
|
@@ -853,6 +1157,15 @@ var LicenseValidator = class {
|
|
|
853
1157
|
const boundSignature = claims["sig" /* ComputerSignature */];
|
|
854
1158
|
if (expectedSignature !== boundSignature && !await this.acceptsHistoricalDeviceId(boundSignature))
|
|
855
1159
|
throw deviceMismatchError(expectedSignature, boundSignature);
|
|
1160
|
+
const { appVersion } = this.configuration;
|
|
1161
|
+
const enforceReleaseAccess = (_b = (_a = options == null ? void 0 : options.enforceReleaseAccess) != null ? _a : this.configuration.enforceReleaseAccess) != null ? _b : true;
|
|
1162
|
+
if (enforceReleaseAccess && appVersion && !coversVersion(license, appVersion)) {
|
|
1163
|
+
throw new ReleaseNotCoveredError(
|
|
1164
|
+
"Version not covered",
|
|
1165
|
+
`The license doesn't cover version ${appVersion}`,
|
|
1166
|
+
{ license, appVersion }
|
|
1167
|
+
);
|
|
1168
|
+
}
|
|
856
1169
|
return license;
|
|
857
1170
|
}
|
|
858
1171
|
/**
|
|
@@ -891,6 +1204,7 @@ var LicenseValidator = class {
|
|
|
891
1204
|
}
|
|
892
1205
|
try {
|
|
893
1206
|
const claims = licenseClaimsSchema.parse(decoded);
|
|
1207
|
+
const releaseAccess = readReleaseAccess(claims);
|
|
894
1208
|
resolve([{
|
|
895
1209
|
id: claims["l:id" /* LicenseId */],
|
|
896
1210
|
trial: claims["trial" /* Trial */],
|
|
@@ -902,6 +1216,7 @@ var LicenseValidator = class {
|
|
|
902
1216
|
properties: (_b = claims["p:properties" /* ProductProperties */]) != null ? _b : void 0
|
|
903
1217
|
},
|
|
904
1218
|
ownedSubProductIds: claims["sp:owned" /* OwnedSubProducts */],
|
|
1219
|
+
subProducts: claims["sp" /* SubProducts */],
|
|
905
1220
|
subscriptionId: (_c = claims["s:id" /* SubscriptionId */]) != null ? _c : void 0,
|
|
906
1221
|
issuedTo: {
|
|
907
1222
|
id: claims["u:id" /* UserId */],
|
|
@@ -912,6 +1227,7 @@ var LicenseValidator = class {
|
|
|
912
1227
|
expiresAt: claims["exp" /* ExpiresAt */] || void 0,
|
|
913
1228
|
issuedAt: claims["iat" /* IssuedAt */],
|
|
914
1229
|
validatedAt: claims["validated" /* ValidatedAt */],
|
|
1230
|
+
...releaseAccess && { releaseAccess },
|
|
915
1231
|
properties: (_e = claims["trial" /* Trial */] ? claims["t:properties" /* TrialProperties */] : claims["l:properties" /* LicenseProperties */]) != null ? _e : void 0,
|
|
916
1232
|
token
|
|
917
1233
|
}, claims]);
|
|
@@ -928,6 +1244,50 @@ var LicenseValidator = class {
|
|
|
928
1244
|
});
|
|
929
1245
|
}
|
|
930
1246
|
};
|
|
1247
|
+
var subProductClaimSchema = import_zod2.z.object({
|
|
1248
|
+
id: import_zod2.z.string(),
|
|
1249
|
+
active: import_zod2.z.boolean().catch(false),
|
|
1250
|
+
trial: import_zod2.z.boolean().catch(false),
|
|
1251
|
+
revoked: import_zod2.z.boolean().catch(false),
|
|
1252
|
+
exp: import_zod2.z.number().nullish().catch(void 0),
|
|
1253
|
+
seats: import_zod2.z.object({
|
|
1254
|
+
total: import_zod2.z.number(),
|
|
1255
|
+
used: import_zod2.z.number(),
|
|
1256
|
+
remaining: import_zod2.z.number()
|
|
1257
|
+
}).nullish().catch(void 0)
|
|
1258
|
+
});
|
|
1259
|
+
function readSubProducts(entries) {
|
|
1260
|
+
return (entries != null ? entries : []).flatMap((entry) => {
|
|
1261
|
+
const parsed = subProductClaimSchema.safeParse(entry);
|
|
1262
|
+
if (!parsed.success)
|
|
1263
|
+
return [];
|
|
1264
|
+
const { id, active, trial, revoked, exp, seats } = parsed.data;
|
|
1265
|
+
return [{
|
|
1266
|
+
id,
|
|
1267
|
+
active,
|
|
1268
|
+
trial,
|
|
1269
|
+
revoked,
|
|
1270
|
+
expiresAt: exp ? new Date(exp * 1e3) : void 0,
|
|
1271
|
+
seats: seats != null ? seats : void 0
|
|
1272
|
+
}];
|
|
1273
|
+
});
|
|
1274
|
+
}
|
|
1275
|
+
function readReleaseAccess(claims) {
|
|
1276
|
+
var _a, _b;
|
|
1277
|
+
const updatesUntil = (_a = claims["l:rel:until" /* ReleaseAccessUpdatesUntil */]) != null ? _a : void 0;
|
|
1278
|
+
const upToMajor = (_b = claims["l:rel:major" /* ReleaseAccessUpToMajor */]) != null ? _b : void 0;
|
|
1279
|
+
if (updatesUntil === void 0 && upToMajor === void 0)
|
|
1280
|
+
return void 0;
|
|
1281
|
+
const releaseAccess = {};
|
|
1282
|
+
if (updatesUntil !== void 0)
|
|
1283
|
+
releaseAccess.updatesUntil = new Date(updatesUntil * 1e3);
|
|
1284
|
+
if (upToMajor !== void 0)
|
|
1285
|
+
releaseAccess.upToMajor = upToMajor;
|
|
1286
|
+
const upToVersion = claims["l:rel:upto" /* ReleaseAccessUpToVersion */];
|
|
1287
|
+
if (upToVersion)
|
|
1288
|
+
releaseAccess.upToVersion = upToVersion;
|
|
1289
|
+
return releaseAccess;
|
|
1290
|
+
}
|
|
931
1291
|
function deviceMismatchError(expected, bound) {
|
|
932
1292
|
const detail = "This license is not for this device";
|
|
933
1293
|
const stampNote = describeStampDifference(expected, bound);
|
|
@@ -974,6 +1334,15 @@ function describeSourceDifference(expected, bound) {
|
|
|
974
1334
|
return "The binding was created from hardware identity, while this SDK has fallen back to the host name \u2014 check why hardware identity cannot be read here rather than re-activating, which would rebind the device to the weaker id.";
|
|
975
1335
|
}
|
|
976
1336
|
|
|
1337
|
+
// src/subProducts.ts
|
|
1338
|
+
function hasSubProduct(license, subProductId) {
|
|
1339
|
+
var _a;
|
|
1340
|
+
const parentPrefix = `${license.product.id}.`;
|
|
1341
|
+
const id = subProductId.startsWith(parentPrefix) ? subProductId.slice(parentPrefix.length) : subProductId;
|
|
1342
|
+
const now = /* @__PURE__ */ new Date();
|
|
1343
|
+
return ((_a = license.subProducts) != null ? _a : []).some((subProduct) => subProduct.id === id && subProduct.active && (!subProduct.expiresAt || subProduct.expiresAt > now));
|
|
1344
|
+
}
|
|
1345
|
+
|
|
977
1346
|
// src/index.ts
|
|
978
1347
|
function detectPlatform() {
|
|
979
1348
|
if (typeof import_node_process3.default === "undefined")
|
|
@@ -1035,13 +1404,17 @@ var MoonbaseLicensing = class {
|
|
|
1035
1404
|
MoonbaseDeviceIdResolver,
|
|
1036
1405
|
MoonbaseError,
|
|
1037
1406
|
MoonbaseLicensing,
|
|
1407
|
+
ReleaseNotCoveredError,
|
|
1038
1408
|
buildFingerprintMaterial,
|
|
1039
1409
|
canonicalizeParams,
|
|
1040
1410
|
canonicalizeValue,
|
|
1411
|
+
coversVersion,
|
|
1041
1412
|
defaultDeviceIdentityReader,
|
|
1042
1413
|
fingerprintDeviceId,
|
|
1043
1414
|
fingerprintDigest,
|
|
1415
|
+
hasSubProduct,
|
|
1044
1416
|
identitySource,
|
|
1417
|
+
parseAppVersion,
|
|
1045
1418
|
parseDeviceIdStamp,
|
|
1046
1419
|
parseIoregPlatformUuid,
|
|
1047
1420
|
parseSmbiosParams,
|