@moonbase.sh/licensing 3.5.1 → 3.5.2

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 CHANGED
@@ -526,6 +526,11 @@ What runs in the background:
526
526
  before locking. An add-on that runs out changes the state, and so does a day going by on a countdown.
527
527
  - **Online checks** are at most every `checkInterval` (5 minutes), and instances sharing the license file take turns,
528
528
  so a later one picks up the license an earlier one just refreshed.
529
+ - **A revoked license is removed.** When an online check hears that the license was revoked (by hand, or with a
530
+ refund) or that this device's activation was, the app locks as `invalid` and the stored license is deleted, so a
531
+ later launch without a connection can't fall back to it within the grace period. Other instances sharing the file
532
+ lock as `deactivated`. Any other refusal leaves the file for the next launch to check: a lapsed subscription
533
+ (`expired`) unlocks again once it is renewed.
529
534
 
530
535
  Every result is gated by a generation counter: a cancel, a new activation or a deactivation supersedes whatever was
531
536
  in flight, so a slow response never overwrites a newer state or writes back a license the customer just removed.
package/dist/index.cjs CHANGED
@@ -75,7 +75,7 @@ __export(index_exports, {
75
75
  module.exports = __toCommonJS(index_exports);
76
76
 
77
77
  // package.json
78
- var version = "3.5.1";
78
+ var version = "3.5.2";
79
79
 
80
80
  // src/activation/controller.ts
81
81
  var import_promises4 = __toESM(require("fs/promises"), 1);
@@ -1863,6 +1863,9 @@ function isLicenseInvalid(error) {
1863
1863
  function isLicenseRejection(error) {
1864
1864
  return isLicenseInvalid(error) || error instanceof MoonbaseError && (error.type === "LicenseExpired" /* LicenseExpired */ || error.type === "NoEligibleLicense" /* NoEligibleLicense */);
1865
1865
  }
1866
+ function isRevocation(error) {
1867
+ return isType(error, "LicenseRevoked" /* LicenseRevoked */) || isType(error, "LicenseActivationRevoked" /* LicenseActivationRevoked */);
1868
+ }
1866
1869
  function isType(error, type) {
1867
1870
  return error instanceof MoonbaseError && error.type === type;
1868
1871
  }
@@ -2163,7 +2166,10 @@ var ActivationController = class {
2163
2166
  setLicense(license) {
2164
2167
  this.setStanding({ kind: "licensed", license });
2165
2168
  }
2166
- /** Drop the license and say why. The file stays, so the next launch checks it again. */
2169
+ /**
2170
+ * Drop the license and say why. The file stays, so the next launch checks it
2171
+ * again, unless Moonbase revoked it (see {@link forgetRevoked}).
2172
+ */
2167
2173
  lock(reason) {
2168
2174
  this.setStanding({ kind: "unlicensed", reason });
2169
2175
  }
@@ -2250,6 +2256,25 @@ var ActivationController = class {
2250
2256
  }
2251
2257
  this.fileStamp = kept ? null : await this.stampFile();
2252
2258
  }
2259
+ /**
2260
+ * Delete the stored license when Moonbase answered that it, or this device's
2261
+ * activation, was revoked. Left on disk, it would unlock every launch that can't
2262
+ * reach Moonbase until the grace period ran out, since a refusal stores nothing
2263
+ * newer to measure that from. Call under the store's lock: `shouldPersist` says
2264
+ * whether the file still holds the activation that was refused, so a license
2265
+ * another instance stored in its place is kept.
2266
+ */
2267
+ async forgetRevoked(error, shouldPersist) {
2268
+ if (!isRevocation(error) || !await shouldPersist())
2269
+ return;
2270
+ this.log.info(`moonbase: Moonbase revoked the stored license; removing it: ${errorText(error)}`);
2271
+ try {
2272
+ await this.store.deleteLocalLicense();
2273
+ } catch (err) {
2274
+ this.log.warn(`moonbase: couldn't delete the revoked license: ${errorText(err)}`);
2275
+ }
2276
+ this.fileStamp = await this.stampFile();
2277
+ }
2253
2278
  /** In-process turns for a re-check and an add-on call, so their answers land in the order they reached the store. */
2254
2279
  onlineTurn(action) {
2255
2280
  const run = this.onlineQueue.then(action, action);
@@ -2335,8 +2360,10 @@ var ActivationController = class {
2335
2360
  await this.store.storeLocalLicense(err.license).catch(noop);
2336
2361
  throw err;
2337
2362
  }
2338
- if (isLicenseRejection(err))
2363
+ if (isLicenseRejection(err)) {
2364
+ await this.forgetRevoked(err, shouldPersist);
2339
2365
  throw err;
2366
+ }
2340
2367
  if (since <= this.gracePeriod) {
2341
2368
  this.log.debug(`moonbase: couldn't reach Moonbase, the license is within its grace period: ${errorText(err)}`);
2342
2369
  this.ensureCoversAppVersion(freshest);
@@ -2437,10 +2464,15 @@ var ActivationController = class {
2437
2464
  try {
2438
2465
  if (peek.expiresAt && peek.expiresAt <= /* @__PURE__ */ new Date()) {
2439
2466
  const refreshed = await this.withStoreLock(async () => {
2440
- const answer = await this.licensing.client.validateLicense(peek);
2441
- if (await stillCurrent())
2442
- await this.store.storeLocalLicense(answer).catch(noop);
2443
- return answer;
2467
+ try {
2468
+ const answer = await this.licensing.client.validateLicense(peek);
2469
+ if (await stillCurrent())
2470
+ await this.store.storeLocalLicense(answer).catch(noop);
2471
+ return answer;
2472
+ } catch (err) {
2473
+ await this.forgetRevoked(err, stillCurrent);
2474
+ throw err;
2475
+ }
2444
2476
  });
2445
2477
  return { license: refreshed, reason: null };
2446
2478
  }
@@ -2611,6 +2643,7 @@ var ActivationController = class {
2611
2643
  } catch (err2) {
2612
2644
  if (err2 instanceof ReleaseNotCoveredError && err2.license && await stillCurrent())
2613
2645
  await this.store.storeLocalLicense(err2.license).catch(noop);
2646
+ await this.forgetRevoked(err2, stillCurrent);
2614
2647
  return { error: err2 };
2615
2648
  }
2616
2649
  });
package/dist/index.d.cts CHANGED
@@ -2241,7 +2241,10 @@ declare class ActivationController {
2241
2241
  private resetAddOns;
2242
2242
  private setStanding;
2243
2243
  private setLicense;
2244
- /** Drop the license and say why. The file stays, so the next launch checks it again. */
2244
+ /**
2245
+ * Drop the license and say why. The file stays, so the next launch checks it
2246
+ * again, unless Moonbase revoked it (see {@link forgetRevoked}).
2247
+ */
2245
2248
  private lock;
2246
2249
  private showTrialExpired;
2247
2250
  /** Lock like an ended trial, but keep the license stored: it still covers the versions it did. */
@@ -2267,6 +2270,15 @@ declare class ActivationController {
2267
2270
  * license it picks out: another instance may have stored a new one since.
2268
2271
  */
2269
2272
  private deleteStored;
2273
+ /**
2274
+ * Delete the stored license when Moonbase answered that it, or this device's
2275
+ * activation, was revoked. Left on disk, it would unlock every launch that can't
2276
+ * reach Moonbase until the grace period ran out, since a refusal stores nothing
2277
+ * newer to measure that from. Call under the store's lock: `shouldPersist` says
2278
+ * whether the file still holds the activation that was refused, so a license
2279
+ * another instance stored in its place is kept.
2280
+ */
2281
+ private forgetRevoked;
2270
2282
  /** In-process turns for a re-check and an add-on call, so their answers land in the order they reached the store. */
2271
2283
  private onlineTurn;
2272
2284
  private ensureCoversAppVersion;
package/dist/index.d.ts CHANGED
@@ -2241,7 +2241,10 @@ declare class ActivationController {
2241
2241
  private resetAddOns;
2242
2242
  private setStanding;
2243
2243
  private setLicense;
2244
- /** Drop the license and say why. The file stays, so the next launch checks it again. */
2244
+ /**
2245
+ * Drop the license and say why. The file stays, so the next launch checks it
2246
+ * again, unless Moonbase revoked it (see {@link forgetRevoked}).
2247
+ */
2245
2248
  private lock;
2246
2249
  private showTrialExpired;
2247
2250
  /** Lock like an ended trial, but keep the license stored: it still covers the versions it did. */
@@ -2267,6 +2270,15 @@ declare class ActivationController {
2267
2270
  * license it picks out: another instance may have stored a new one since.
2268
2271
  */
2269
2272
  private deleteStored;
2273
+ /**
2274
+ * Delete the stored license when Moonbase answered that it, or this device's
2275
+ * activation, was revoked. Left on disk, it would unlock every launch that can't
2276
+ * reach Moonbase until the grace period ran out, since a refusal stores nothing
2277
+ * newer to measure that from. Call under the store's lock: `shouldPersist` says
2278
+ * whether the file still holds the activation that was refused, so a license
2279
+ * another instance stored in its place is kept.
2280
+ */
2281
+ private forgetRevoked;
2270
2282
  /** In-process turns for a re-check and an add-on call, so their answers land in the order they reached the store. */
2271
2283
  private onlineTurn;
2272
2284
  private ensureCoversAppVersion;
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // package.json
2
- var version = "3.5.1";
2
+ var version = "3.5.2";
3
3
 
4
4
  // src/activation/controller.ts
5
5
  import fs4 from "fs/promises";
@@ -1787,6 +1787,9 @@ function isLicenseInvalid(error) {
1787
1787
  function isLicenseRejection(error) {
1788
1788
  return isLicenseInvalid(error) || error instanceof MoonbaseError && (error.type === "LicenseExpired" /* LicenseExpired */ || error.type === "NoEligibleLicense" /* NoEligibleLicense */);
1789
1789
  }
1790
+ function isRevocation(error) {
1791
+ return isType(error, "LicenseRevoked" /* LicenseRevoked */) || isType(error, "LicenseActivationRevoked" /* LicenseActivationRevoked */);
1792
+ }
1790
1793
  function isType(error, type) {
1791
1794
  return error instanceof MoonbaseError && error.type === type;
1792
1795
  }
@@ -2087,7 +2090,10 @@ var ActivationController = class {
2087
2090
  setLicense(license) {
2088
2091
  this.setStanding({ kind: "licensed", license });
2089
2092
  }
2090
- /** Drop the license and say why. The file stays, so the next launch checks it again. */
2093
+ /**
2094
+ * Drop the license and say why. The file stays, so the next launch checks it
2095
+ * again, unless Moonbase revoked it (see {@link forgetRevoked}).
2096
+ */
2091
2097
  lock(reason) {
2092
2098
  this.setStanding({ kind: "unlicensed", reason });
2093
2099
  }
@@ -2174,6 +2180,25 @@ var ActivationController = class {
2174
2180
  }
2175
2181
  this.fileStamp = kept ? null : await this.stampFile();
2176
2182
  }
2183
+ /**
2184
+ * Delete the stored license when Moonbase answered that it, or this device's
2185
+ * activation, was revoked. Left on disk, it would unlock every launch that can't
2186
+ * reach Moonbase until the grace period ran out, since a refusal stores nothing
2187
+ * newer to measure that from. Call under the store's lock: `shouldPersist` says
2188
+ * whether the file still holds the activation that was refused, so a license
2189
+ * another instance stored in its place is kept.
2190
+ */
2191
+ async forgetRevoked(error, shouldPersist) {
2192
+ if (!isRevocation(error) || !await shouldPersist())
2193
+ return;
2194
+ this.log.info(`moonbase: Moonbase revoked the stored license; removing it: ${errorText(error)}`);
2195
+ try {
2196
+ await this.store.deleteLocalLicense();
2197
+ } catch (err) {
2198
+ this.log.warn(`moonbase: couldn't delete the revoked license: ${errorText(err)}`);
2199
+ }
2200
+ this.fileStamp = await this.stampFile();
2201
+ }
2177
2202
  /** In-process turns for a re-check and an add-on call, so their answers land in the order they reached the store. */
2178
2203
  onlineTurn(action) {
2179
2204
  const run = this.onlineQueue.then(action, action);
@@ -2259,8 +2284,10 @@ var ActivationController = class {
2259
2284
  await this.store.storeLocalLicense(err.license).catch(noop);
2260
2285
  throw err;
2261
2286
  }
2262
- if (isLicenseRejection(err))
2287
+ if (isLicenseRejection(err)) {
2288
+ await this.forgetRevoked(err, shouldPersist);
2263
2289
  throw err;
2290
+ }
2264
2291
  if (since <= this.gracePeriod) {
2265
2292
  this.log.debug(`moonbase: couldn't reach Moonbase, the license is within its grace period: ${errorText(err)}`);
2266
2293
  this.ensureCoversAppVersion(freshest);
@@ -2361,10 +2388,15 @@ var ActivationController = class {
2361
2388
  try {
2362
2389
  if (peek.expiresAt && peek.expiresAt <= /* @__PURE__ */ new Date()) {
2363
2390
  const refreshed = await this.withStoreLock(async () => {
2364
- const answer = await this.licensing.client.validateLicense(peek);
2365
- if (await stillCurrent())
2366
- await this.store.storeLocalLicense(answer).catch(noop);
2367
- return answer;
2391
+ try {
2392
+ const answer = await this.licensing.client.validateLicense(peek);
2393
+ if (await stillCurrent())
2394
+ await this.store.storeLocalLicense(answer).catch(noop);
2395
+ return answer;
2396
+ } catch (err) {
2397
+ await this.forgetRevoked(err, stillCurrent);
2398
+ throw err;
2399
+ }
2368
2400
  });
2369
2401
  return { license: refreshed, reason: null };
2370
2402
  }
@@ -2535,6 +2567,7 @@ var ActivationController = class {
2535
2567
  } catch (err2) {
2536
2568
  if (err2 instanceof ReleaseNotCoveredError && err2.license && await stillCurrent())
2537
2569
  await this.store.storeLocalLicense(err2.license).catch(noop);
2570
+ await this.forgetRevoked(err2, stillCurrent);
2538
2571
  return { error: err2 };
2539
2572
  }
2540
2573
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@moonbase.sh/licensing",
3
3
  "type": "module",
4
- "version": "3.5.1",
4
+ "version": "3.5.2",
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",