@moonbase.sh/licensing 1.0.6 → 1.0.11
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 +23 -1
- package/dist/index.d.cts +16 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +23 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -74,6 +74,8 @@ var licenseSchema = import_zod.z.object({
|
|
|
74
74
|
trial: import_zod.z.boolean(),
|
|
75
75
|
activationMethod: import_zod.z.nativeEnum(ActivationMethod),
|
|
76
76
|
product: productSchema,
|
|
77
|
+
ownedSubProductIds: import_zod.z.array(import_zod.z.string()).default([]),
|
|
78
|
+
subscriptionId: import_zod.z.string().nullish(),
|
|
77
79
|
issuedAt: import_zod.z.coerce.date(),
|
|
78
80
|
issuedTo: userSchema,
|
|
79
81
|
expiresAt: import_zod.z.coerce.date().nullish(),
|
|
@@ -127,6 +129,22 @@ var LicenseClient = class {
|
|
|
127
129
|
if (response.status === 204 || response.status === 404) return null;
|
|
128
130
|
return await this.handleLicenseResponse(response);
|
|
129
131
|
}
|
|
132
|
+
async requestTrial() {
|
|
133
|
+
const content = {
|
|
134
|
+
deviceName: await this.deviceIdResolver.resolveDeviceName(),
|
|
135
|
+
deviceSignature: await this.deviceIdResolver.resolveDeviceId()
|
|
136
|
+
};
|
|
137
|
+
const response = await (0, import_cross_fetch.default)(this.configuration.endpoint + `/api/client/trials/${this.configuration.productId}/request?format=JWT`, {
|
|
138
|
+
...defaultFetchOptions,
|
|
139
|
+
method: "POST",
|
|
140
|
+
headers: {
|
|
141
|
+
...defaultFetchOptions.headers,
|
|
142
|
+
"Content-Type": "application/json"
|
|
143
|
+
},
|
|
144
|
+
body: JSON.stringify(content)
|
|
145
|
+
});
|
|
146
|
+
return await this.handleLicenseResponse(response);
|
|
147
|
+
}
|
|
130
148
|
async validateLicense(license) {
|
|
131
149
|
const response = await (0, import_cross_fetch.default)(this.configuration.endpoint + `/api/client/licenses/${this.configuration.productId}/validate?format=JWT`, {
|
|
132
150
|
...defaultFetchOptions,
|
|
@@ -291,6 +309,8 @@ var licenseClaimsSchema = import_zod2.z.object({
|
|
|
291
309
|
["p:id" /* ProductId */]: import_zod2.z.string(),
|
|
292
310
|
["p:name" /* ProductName */]: import_zod2.z.string(),
|
|
293
311
|
["p:rel" /* ProductReleaseVersion */]: import_zod2.z.string().nullish(),
|
|
312
|
+
["sp:owned" /* OwnedSubProducts */]: import_zod2.z.string().nullish().transform((v) => v ? v.split(",") : []),
|
|
313
|
+
["s:id" /* SubscriptionId */]: import_zod2.z.string().nullish(),
|
|
294
314
|
["u:id" /* UserId */]: import_zod2.z.string(),
|
|
295
315
|
["u:name" /* UserName */]: import_zod2.z.string(),
|
|
296
316
|
["u:email" /* UserEmail */]: import_zod2.z.string()
|
|
@@ -326,7 +346,7 @@ var LicenseValidator = class {
|
|
|
326
346
|
issuer: this.configuration.accountId,
|
|
327
347
|
audience: this.configuration.productId
|
|
328
348
|
}, (err, decoded) => {
|
|
329
|
-
var _a;
|
|
349
|
+
var _a, _b;
|
|
330
350
|
if (err) {
|
|
331
351
|
reject(new MoonbaseError(
|
|
332
352
|
"Could not validate license",
|
|
@@ -355,6 +375,8 @@ var LicenseValidator = class {
|
|
|
355
375
|
name: claims["p:name" /* ProductName */],
|
|
356
376
|
currentReleaseVersion: (_a = claims["p:rel" /* ProductReleaseVersion */]) != null ? _a : void 0
|
|
357
377
|
},
|
|
378
|
+
ownedSubProductIds: claims["sp:owned" /* OwnedSubProducts */],
|
|
379
|
+
subscriptionId: (_b = claims["s:id" /* SubscriptionId */]) != null ? _b : void 0,
|
|
358
380
|
issuedTo: {
|
|
359
381
|
id: claims["u:id" /* UserId */],
|
|
360
382
|
name: claims["u:name" /* UserName */],
|
package/dist/index.d.cts
CHANGED
|
@@ -65,6 +65,8 @@ declare const licenseSchema: z.ZodObject<{
|
|
|
65
65
|
name: string;
|
|
66
66
|
currentReleaseVersion?: string | null | undefined;
|
|
67
67
|
}>;
|
|
68
|
+
ownedSubProductIds: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
69
|
+
subscriptionId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
68
70
|
issuedAt: z.ZodDate;
|
|
69
71
|
issuedTo: z.ZodObject<{
|
|
70
72
|
id: z.ZodString;
|
|
@@ -91,6 +93,7 @@ declare const licenseSchema: z.ZodObject<{
|
|
|
91
93
|
name: string;
|
|
92
94
|
currentReleaseVersion?: string | null | undefined;
|
|
93
95
|
};
|
|
96
|
+
ownedSubProductIds: string[];
|
|
94
97
|
issuedAt: Date;
|
|
95
98
|
issuedTo: {
|
|
96
99
|
id: string;
|
|
@@ -99,6 +102,7 @@ declare const licenseSchema: z.ZodObject<{
|
|
|
99
102
|
};
|
|
100
103
|
validatedAt: Date;
|
|
101
104
|
token: string;
|
|
105
|
+
subscriptionId?: string | null | undefined;
|
|
102
106
|
expiresAt?: Date | null | undefined;
|
|
103
107
|
}, {
|
|
104
108
|
id: string;
|
|
@@ -117,6 +121,8 @@ declare const licenseSchema: z.ZodObject<{
|
|
|
117
121
|
};
|
|
118
122
|
validatedAt: Date;
|
|
119
123
|
token: string;
|
|
124
|
+
ownedSubProductIds?: string[] | undefined;
|
|
125
|
+
subscriptionId?: string | null | undefined;
|
|
120
126
|
expiresAt?: Date | null | undefined;
|
|
121
127
|
}>;
|
|
122
128
|
|
|
@@ -159,6 +165,15 @@ interface ILicenseClient {
|
|
|
159
165
|
* @returns A license if the request has been fulfilled, else null
|
|
160
166
|
*/
|
|
161
167
|
getRequestedActivation(request: ActivationRequestResponse): Promise<License | null>;
|
|
168
|
+
/**
|
|
169
|
+
* Requests a trial license for the product.
|
|
170
|
+
* This can only be done once per product per device, and skips
|
|
171
|
+
* the browser activation process. This currently requires that
|
|
172
|
+
* the product allows anonymous trials, since there is no authentication.
|
|
173
|
+
*
|
|
174
|
+
* @returns The allocated trial license, throws if the trial license cannot be allocated (e.g. user already had a trial) or if the request failed
|
|
175
|
+
*/
|
|
176
|
+
requestTrial(): Promise<License>;
|
|
162
177
|
/**
|
|
163
178
|
* Checks if the given license is still valid, not revoked
|
|
164
179
|
* and returns an updated license if still active.
|
|
@@ -194,6 +209,7 @@ declare class LicenseClient implements ILicenseClient {
|
|
|
194
209
|
constructor(configuration: MoonbaseConfiguration, deviceIdResolver: IDeviceIdResolver, licenseValidator: ILicenseValidator);
|
|
195
210
|
requestActivation(): Promise<ActivationRequestResponse>;
|
|
196
211
|
getRequestedActivation(request: ActivationRequestResponse): Promise<License | null>;
|
|
212
|
+
requestTrial(): Promise<License>;
|
|
197
213
|
validateLicense(license: License): Promise<License>;
|
|
198
214
|
validateRawLicense(rawLicense: Buffer): Promise<License>;
|
|
199
215
|
revokeLicense(license: License): Promise<void>;
|
package/dist/index.d.ts
CHANGED
|
@@ -65,6 +65,8 @@ declare const licenseSchema: z.ZodObject<{
|
|
|
65
65
|
name: string;
|
|
66
66
|
currentReleaseVersion?: string | null | undefined;
|
|
67
67
|
}>;
|
|
68
|
+
ownedSubProductIds: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
69
|
+
subscriptionId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
68
70
|
issuedAt: z.ZodDate;
|
|
69
71
|
issuedTo: z.ZodObject<{
|
|
70
72
|
id: z.ZodString;
|
|
@@ -91,6 +93,7 @@ declare const licenseSchema: z.ZodObject<{
|
|
|
91
93
|
name: string;
|
|
92
94
|
currentReleaseVersion?: string | null | undefined;
|
|
93
95
|
};
|
|
96
|
+
ownedSubProductIds: string[];
|
|
94
97
|
issuedAt: Date;
|
|
95
98
|
issuedTo: {
|
|
96
99
|
id: string;
|
|
@@ -99,6 +102,7 @@ declare const licenseSchema: z.ZodObject<{
|
|
|
99
102
|
};
|
|
100
103
|
validatedAt: Date;
|
|
101
104
|
token: string;
|
|
105
|
+
subscriptionId?: string | null | undefined;
|
|
102
106
|
expiresAt?: Date | null | undefined;
|
|
103
107
|
}, {
|
|
104
108
|
id: string;
|
|
@@ -117,6 +121,8 @@ declare const licenseSchema: z.ZodObject<{
|
|
|
117
121
|
};
|
|
118
122
|
validatedAt: Date;
|
|
119
123
|
token: string;
|
|
124
|
+
ownedSubProductIds?: string[] | undefined;
|
|
125
|
+
subscriptionId?: string | null | undefined;
|
|
120
126
|
expiresAt?: Date | null | undefined;
|
|
121
127
|
}>;
|
|
122
128
|
|
|
@@ -159,6 +165,15 @@ interface ILicenseClient {
|
|
|
159
165
|
* @returns A license if the request has been fulfilled, else null
|
|
160
166
|
*/
|
|
161
167
|
getRequestedActivation(request: ActivationRequestResponse): Promise<License | null>;
|
|
168
|
+
/**
|
|
169
|
+
* Requests a trial license for the product.
|
|
170
|
+
* This can only be done once per product per device, and skips
|
|
171
|
+
* the browser activation process. This currently requires that
|
|
172
|
+
* the product allows anonymous trials, since there is no authentication.
|
|
173
|
+
*
|
|
174
|
+
* @returns The allocated trial license, throws if the trial license cannot be allocated (e.g. user already had a trial) or if the request failed
|
|
175
|
+
*/
|
|
176
|
+
requestTrial(): Promise<License>;
|
|
162
177
|
/**
|
|
163
178
|
* Checks if the given license is still valid, not revoked
|
|
164
179
|
* and returns an updated license if still active.
|
|
@@ -194,6 +209,7 @@ declare class LicenseClient implements ILicenseClient {
|
|
|
194
209
|
constructor(configuration: MoonbaseConfiguration, deviceIdResolver: IDeviceIdResolver, licenseValidator: ILicenseValidator);
|
|
195
210
|
requestActivation(): Promise<ActivationRequestResponse>;
|
|
196
211
|
getRequestedActivation(request: ActivationRequestResponse): Promise<License | null>;
|
|
212
|
+
requestTrial(): Promise<License>;
|
|
197
213
|
validateLicense(license: License): Promise<License>;
|
|
198
214
|
validateRawLicense(rawLicense: Buffer): Promise<License>;
|
|
199
215
|
revokeLicense(license: License): Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -30,6 +30,8 @@ var licenseSchema = z.object({
|
|
|
30
30
|
trial: z.boolean(),
|
|
31
31
|
activationMethod: z.nativeEnum(ActivationMethod),
|
|
32
32
|
product: productSchema,
|
|
33
|
+
ownedSubProductIds: z.array(z.string()).default([]),
|
|
34
|
+
subscriptionId: z.string().nullish(),
|
|
33
35
|
issuedAt: z.coerce.date(),
|
|
34
36
|
issuedTo: userSchema,
|
|
35
37
|
expiresAt: z.coerce.date().nullish(),
|
|
@@ -83,6 +85,22 @@ var LicenseClient = class {
|
|
|
83
85
|
if (response.status === 204 || response.status === 404) return null;
|
|
84
86
|
return await this.handleLicenseResponse(response);
|
|
85
87
|
}
|
|
88
|
+
async requestTrial() {
|
|
89
|
+
const content = {
|
|
90
|
+
deviceName: await this.deviceIdResolver.resolveDeviceName(),
|
|
91
|
+
deviceSignature: await this.deviceIdResolver.resolveDeviceId()
|
|
92
|
+
};
|
|
93
|
+
const response = await fetch(this.configuration.endpoint + `/api/client/trials/${this.configuration.productId}/request?format=JWT`, {
|
|
94
|
+
...defaultFetchOptions,
|
|
95
|
+
method: "POST",
|
|
96
|
+
headers: {
|
|
97
|
+
...defaultFetchOptions.headers,
|
|
98
|
+
"Content-Type": "application/json"
|
|
99
|
+
},
|
|
100
|
+
body: JSON.stringify(content)
|
|
101
|
+
});
|
|
102
|
+
return await this.handleLicenseResponse(response);
|
|
103
|
+
}
|
|
86
104
|
async validateLicense(license) {
|
|
87
105
|
const response = await fetch(this.configuration.endpoint + `/api/client/licenses/${this.configuration.productId}/validate?format=JWT`, {
|
|
88
106
|
...defaultFetchOptions,
|
|
@@ -247,6 +265,8 @@ var licenseClaimsSchema = z2.object({
|
|
|
247
265
|
["p:id" /* ProductId */]: z2.string(),
|
|
248
266
|
["p:name" /* ProductName */]: z2.string(),
|
|
249
267
|
["p:rel" /* ProductReleaseVersion */]: z2.string().nullish(),
|
|
268
|
+
["sp:owned" /* OwnedSubProducts */]: z2.string().nullish().transform((v) => v ? v.split(",") : []),
|
|
269
|
+
["s:id" /* SubscriptionId */]: z2.string().nullish(),
|
|
250
270
|
["u:id" /* UserId */]: z2.string(),
|
|
251
271
|
["u:name" /* UserName */]: z2.string(),
|
|
252
272
|
["u:email" /* UserEmail */]: z2.string()
|
|
@@ -282,7 +302,7 @@ var LicenseValidator = class {
|
|
|
282
302
|
issuer: this.configuration.accountId,
|
|
283
303
|
audience: this.configuration.productId
|
|
284
304
|
}, (err, decoded) => {
|
|
285
|
-
var _a;
|
|
305
|
+
var _a, _b;
|
|
286
306
|
if (err) {
|
|
287
307
|
reject(new MoonbaseError(
|
|
288
308
|
"Could not validate license",
|
|
@@ -311,6 +331,8 @@ var LicenseValidator = class {
|
|
|
311
331
|
name: claims["p:name" /* ProductName */],
|
|
312
332
|
currentReleaseVersion: (_a = claims["p:rel" /* ProductReleaseVersion */]) != null ? _a : void 0
|
|
313
333
|
},
|
|
334
|
+
ownedSubProductIds: claims["sp:owned" /* OwnedSubProducts */],
|
|
335
|
+
subscriptionId: (_b = claims["s:id" /* SubscriptionId */]) != null ? _b : void 0,
|
|
314
336
|
issuedTo: {
|
|
315
337
|
id: claims["u:id" /* UserId */],
|
|
316
338
|
name: claims["u:name" /* UserName */],
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moonbase.sh/licensing",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.11",
|
|
5
5
|
"description": "Package to add sotftware licensing using Moonbase.sh to your node.js apps",
|
|
6
6
|
"author": "Tobias Lønnerød Madsen <m@dsen.tv>",
|
|
7
7
|
"license": "MIT",
|