@moonbase.sh/licensing 3.3.0 → 3.4.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 +73 -0
- package/dist/index.cjs +2051 -91
- package/dist/index.d.cts +804 -83
- package/dist/index.d.ts +804 -83
- package/dist/index.js +2045 -93
- package/package.json +15 -1
package/README.md
CHANGED
|
@@ -4,6 +4,14 @@ Node.js licensing SDK for Moonbase products.
|
|
|
4
4
|
|
|
5
5
|
Use it to request activation, validate licenses locally and online, persist licenses, and revoke activations.
|
|
6
6
|
|
|
7
|
+
For an Electron app or a Gorilla Engine plugin, use
|
|
8
|
+
[`@moonbase.sh/electron`](https://www.npmjs.com/package/@moonbase.sh/electron) or
|
|
9
|
+
[`@moonbase.sh/gorilla-engine`](https://www.npmjs.com/package/@moonbase.sh/gorilla-engine)
|
|
10
|
+
on top of this package: a finished activation flow, the same one moonbase-cpp's JUCE module and
|
|
11
|
+
tauri-plugin-moonbase have, that validates the stored license at startup, runs browser and offline activation,
|
|
12
|
+
trials, deactivation, add-ons and update downloads, and presents a themeable activation UI whenever the app is
|
|
13
|
+
locked. The state machine underneath both is here, for a UI of your own: see [A UI of your own](#a-ui-of-your-own).
|
|
14
|
+
|
|
7
15
|
Learn more in our official documentation here: https://moonbase.sh/docs/licensing/sdks/node/
|
|
8
16
|
|
|
9
17
|
## Install
|
|
@@ -467,3 +475,68 @@ invalidates its license) and get no cross-SDK compatibility. Use this only as a
|
|
|
467
475
|
You can inject your own `ILicenseStore` and `IDeviceIdResolver` implementations via the
|
|
468
476
|
`licenseStore` and `deviceIdResolver` configuration options. A custom resolver's id is compared
|
|
469
477
|
literally, so it does not need to follow the `mbd2_` stamp format.
|
|
478
|
+
|
|
479
|
+
## A UI of your own
|
|
480
|
+
|
|
481
|
+
Under `@moonbase.sh/electron` and `@moonbase.sh/gorilla-engine` is `ActivationController`,
|
|
482
|
+
the activation state machine, which you can drive yourself from any Node.js app:
|
|
483
|
+
|
|
484
|
+
```ts
|
|
485
|
+
import { ActivationController } from '@moonbase.sh/licensing'
|
|
486
|
+
|
|
487
|
+
const controller = new ActivationController({
|
|
488
|
+
endpoint: 'https://your-store.moonbase.sh',
|
|
489
|
+
productId: 'your-product',
|
|
490
|
+
publicKey: MOONBASE_PUBLIC_KEY,
|
|
491
|
+
appVersion: '1.2.0',
|
|
492
|
+
licenseFile: '/path/to/license.mb',
|
|
493
|
+
openUrl: url => open(url),
|
|
494
|
+
})
|
|
495
|
+
controller.subscribe(render)
|
|
496
|
+
controller.start()
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
Render whatever `state.status` says:
|
|
500
|
+
|
|
501
|
+
| `status` | Meaning | A typical screen |
|
|
502
|
+
| --- | --- | --- |
|
|
503
|
+
| `loading` | Validating the stored license at startup | A spinner |
|
|
504
|
+
| `unlicensed` | No license; `lockReason` says why, when there was one | Welcome: activate online or offline |
|
|
505
|
+
| `activating` | A browser activation is in progress; `activation.browserUrl` is the link | "Finish in your browser", copy link, cancel |
|
|
506
|
+
| `licensed` | A full license | License details, deactivate |
|
|
507
|
+
| `trial` | A trial; `license.daysRemaining` counts down | Days left, unlock full version |
|
|
508
|
+
| `trialExpired` | The trial ended; `expiredTrial` has it | Buy or activate |
|
|
509
|
+
| `notCovered` | The license doesn't cover this version of the app; `notCovered` has it, what it covers and where to upgrade | Upgrade, or check again |
|
|
510
|
+
|
|
511
|
+
`licensed` says whether there is a valid license right now: a trial being unlocked keeps its license while
|
|
512
|
+
`activating`, so check it rather than the status. `lockReason` is `deactivated`, `expired`, `invalid`, `unverified`
|
|
513
|
+
or `notCovered`. `error` is the last failed operation, with `message` worded for the customer and `detail`, the
|
|
514
|
+
SDK's message, for logs. `update` is a newer release than the app, from the license alone, and `addOns` the add-on
|
|
515
|
+
list once `loadAddOns()` has run. The license in the state carries no token.
|
|
516
|
+
|
|
517
|
+
What runs in the background:
|
|
518
|
+
|
|
519
|
+
- **At startup** the stored license is validated, online when it is due. An expired offline license is removed; an
|
|
520
|
+
ended trial shows as `trialExpired`; a license that doesn't cover this version shows as `notCovered`; a license
|
|
521
|
+
bound to another device locks as `invalid`; one that cannot be checked past the grace period (`gracePeriod`, 7
|
|
522
|
+
days) locks as `unverified`. A network failure inside the grace period keeps it.
|
|
523
|
+
- **While activating** the request is polled every 2 seconds until it lands, fails for good, or is cancelled.
|
|
524
|
+
- **Every 2 seconds**, with no network, the license file is checked for changes made by another instance or process,
|
|
525
|
+
and the license's deadlines are checked: a passed expiry or a grace period that ran out gets one more online check
|
|
526
|
+
before locking. An add-on that runs out changes the state, and so does a day going by on a countdown.
|
|
527
|
+
- **Online checks** are at most every `checkInterval` (5 minutes), and instances sharing the license file take turns,
|
|
528
|
+
so a later one picks up the license an earlier one just refreshed.
|
|
529
|
+
|
|
530
|
+
Every result is gated by a generation counter: a cancel, a new activation or a deactivation supersedes whatever was
|
|
531
|
+
in flight, so a slow response never overwrites a newer state or writes back a license the customer just removed.
|
|
532
|
+
Call `dispose()` to stop watching and polling.
|
|
533
|
+
|
|
534
|
+
Its calls: `activate`, `cancelActivation`, `refresh`, `deactivate`, `forget`, `deviceToken`, `activateOffline`,
|
|
535
|
+
`dismissError`, `device`, `checkUpdate`, `updateDownloadUrl`, `downloadInstaller`, `skipUpdate`, `upgradeLicense`,
|
|
536
|
+
`loadAddOns`, `refreshAddOns`, `activateSubProduct`, `requestSubProductTrial` and `buySubProduct`, with
|
|
537
|
+
`isLicensed()`, `license()` and `hasSubProduct(id)` for gating. A refused call rejects with an `ActivationError`
|
|
538
|
+
whose `kind` is `notLicensed`, `busy` or `internal`, or with the SDK's own `MoonbaseError`. Call `onFocusChanged`
|
|
539
|
+
when the app gains or loses focus, so an add-on bought in the browser unlocks when the customer comes back.
|
|
540
|
+
|
|
541
|
+
`checkUpdate()` uses the SDK's `inventory` client, which reads a release's notes and finds the installer for a
|
|
542
|
+
platform, and `isNewerVersion(current, latest)` compares versions the same way.
|