@licers/sdk 1.0.1 → 1.0.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 +231 -31
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,54 +8,254 @@ Every answer from the license server is **Ed25519-signed** with your account key
|
|
|
8
8
|
npm install @licers/sdk
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
Your public key and product id are on the dashboard’s [Integration](https://app.licers.com/developers/integration) page. The public key is safe to ship inside your app. Each example below is a complete file.
|
|
12
|
+
|
|
13
|
+
## Check a key
|
|
14
|
+
|
|
15
|
+
Run this when your app starts. The first check binds the device to the key; past the key’s device limit a new device is refused.
|
|
16
|
+
|
|
17
|
+
In the dashboard: create a product, then a license key for it.
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
import { LicenseClient, NetworkError } from '@licers/sdk';
|
|
21
|
+
|
|
22
|
+
const client = new LicenseClient('YOUR_PUBLIC_KEY', { // safe to ship inside your app
|
|
23
|
+
productId: 'YOUR_PRODUCT_ID', // your product: refuses keys for your other products
|
|
24
|
+
appVersion: '2.4.1', // shows in Analytics -> App versions
|
|
25
|
+
});
|
|
26
|
+
const key = 'XXXX-XXXX-XXXX-XXXX'; // the customer's license key
|
|
27
|
+
|
|
28
|
+
let result;
|
|
29
|
+
try {
|
|
30
|
+
result = await client.validate(key);
|
|
31
|
+
} catch (err) {
|
|
32
|
+
if (err instanceof NetworkError) {
|
|
33
|
+
// Offline, or the server is down. That is not "unlicensed": try again, or
|
|
34
|
+
// allow a few days since the last good check.
|
|
35
|
+
console.error('Could not reach the license server. Please try again.');
|
|
36
|
+
} else {
|
|
37
|
+
// A forged or replayed answer, or a key for another of your products.
|
|
38
|
+
console.error('License check failed:', err.message);
|
|
39
|
+
}
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (!result.valid) {
|
|
44
|
+
// Expired, revoked, device limit reached... the server says which.
|
|
45
|
+
console.error('Not licensed:', result.error);
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
console.log('Licensed. Expires:', result.expiresAt ?? 'never');
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
- A refused key is a normal answer with a message. An unreachable server is an error: never treat it as “unlicensed”.
|
|
53
|
+
|
|
54
|
+
`validate()` resolves to `{ valid: false, error }` when the server refuses the key. It **throws** for a forged answer or an unreachable server, so being offline is never mistaken for being unlicensed. CommonJS works too: `const { LicenseClient } = require('@licers/sdk')`.
|
|
55
|
+
|
|
56
|
+
## Entitlements
|
|
57
|
+
|
|
58
|
+
Switch features on per key: true/false, numbers or text. They come from the signed answer.
|
|
59
|
+
|
|
60
|
+
In the dashboard: set Entitlements (JSON) on the key or on its plan, for example {"pro": true, "seats": 5}.
|
|
61
|
+
|
|
62
|
+
```js
|
|
63
|
+
import { LicenseClient } from '@licers/sdk';
|
|
64
|
+
|
|
65
|
+
const client = new LicenseClient('YOUR_PUBLIC_KEY', { // safe to ship inside your app
|
|
66
|
+
productId: 'YOUR_PRODUCT_ID', // your product: refuses keys for your other products
|
|
67
|
+
appVersion: '2.4.1', // shows in Analytics -> App versions
|
|
68
|
+
});
|
|
69
|
+
const key = 'XXXX-XXXX-XXXX-XXXX'; // the customer's license key
|
|
70
|
+
|
|
71
|
+
const result = await client.validate(key);
|
|
72
|
+
if (!result.valid) {
|
|
73
|
+
console.error('Not licensed:', result.error);
|
|
74
|
+
process.exit(1);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Entitlements of this key, for example { pro: true, seats: 5, tier: 'gold' }.
|
|
78
|
+
// They are read from the signed copy, so nobody can edit them on the way.
|
|
79
|
+
if (result.features.pro === true) console.log('Pro features unlocked');
|
|
80
|
+
|
|
81
|
+
const seats = result.features.seats ?? 1; // 1 when the key has no "seats"
|
|
82
|
+
const tier = result.features.tier ?? 'basic';
|
|
83
|
+
console.log('Seats:', seats, 'Tier:', tier, 'All:', result.features);
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
- Compare with true exactly. The text "false" is not the same as false.
|
|
87
|
+
|
|
88
|
+
## Offline file
|
|
89
|
+
|
|
90
|
+
Check a signed .lic file with no internet at all, for air-gapped machines. Signature, product, expiry, device and operating system are all checked on the computer.
|
|
91
|
+
|
|
92
|
+
1. Your app shows its device id, and the customer sends it to you.
|
|
93
|
+
2. License keys → ⋯ → Offline license file: paste the device id, set how many days it lasts, download the .lic file.
|
|
94
|
+
3. Send it to the customer. Your app reads it from disk.
|
|
95
|
+
|
|
96
|
+
```js
|
|
97
|
+
import { SignatureError, getHwid, verifyOfflineLicense } from '@licers/sdk';
|
|
98
|
+
|
|
99
|
+
// 1. Show this to the customer. They send it to you, and you create the file
|
|
100
|
+
// for that device: License keys -> ... -> Offline license file.
|
|
101
|
+
console.log('Device id:', getHwid());
|
|
102
|
+
|
|
103
|
+
// 2. The customer saves the file next to your app. No network is used here.
|
|
104
|
+
let lic;
|
|
105
|
+
try {
|
|
106
|
+
lic = verifyOfflineLicense('YOUR_PUBLIC_KEY', 'license.lic', {
|
|
107
|
+
expectedProductId: 'YOUR_PRODUCT_ID', // your product
|
|
108
|
+
});
|
|
109
|
+
} catch (err) {
|
|
110
|
+
if (err instanceof SignatureError) console.error('The license file is missing, damaged or was edited.');
|
|
111
|
+
else console.error('License file refused:', err.message); // expired, other device, OS or product
|
|
112
|
+
process.exit(1);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// 3. Use it. It never returns an invalid license: it throws instead.
|
|
116
|
+
console.log('Licensed to:', lic.customer, 'Expires (unix time):', lic.expires_at ?? 'never');
|
|
117
|
+
if (lic.features?.pro === true) console.log('Pro features unlocked');
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
- Revoking a key can’t reach a file you already sent, so give files a short life.
|
|
121
|
+
- The expiry uses the computer’s own clock.
|
|
122
|
+
- A blank device id makes a file that works on any computer.
|
|
123
|
+
|
|
124
|
+
## Usage credits
|
|
125
|
+
|
|
126
|
+
Meter what the customer does: “100 exports”, “5,000 AI calls a month”. Spending is all or nothing.
|
|
127
|
+
|
|
128
|
+
In the dashboard: give the key a credit limit, and a daily or monthly refill if you want one.
|
|
129
|
+
|
|
130
|
+
```js
|
|
131
|
+
import { LicenseClient, UsageExceeded } from '@licers/sdk';
|
|
132
|
+
|
|
133
|
+
const client = new LicenseClient('YOUR_PUBLIC_KEY', { // safe to ship inside your app
|
|
134
|
+
productId: 'YOUR_PRODUCT_ID', // your product: refuses keys for your other products
|
|
135
|
+
appVersion: '2.4.1', // shows in Analytics -> App versions
|
|
136
|
+
});
|
|
137
|
+
const key = 'XXXX-XXXX-XXXX-XXXX'; // the customer's license key
|
|
138
|
+
|
|
139
|
+
const result = await client.validate(key); // first: this activates the device on the key
|
|
140
|
+
if (!result.valid) {
|
|
141
|
+
console.error('Not licensed:', result.error);
|
|
142
|
+
process.exit(1);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
console.log('Left:', (await client.getUsage(key)).remaining); // reads only; null = no limit
|
|
146
|
+
|
|
147
|
+
try {
|
|
148
|
+
const usage = await client.recordUsage(key, 1); // spend 1 credit, all or nothing
|
|
149
|
+
console.log('Done.', usage.remaining, 'credits left');
|
|
150
|
+
} catch (err) {
|
|
151
|
+
if (!(err instanceof UsageExceeded)) throw err;
|
|
152
|
+
console.log('Out of credits. Refill:', err.usage.resets_at ?? 'buy more');
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
- Check the key on this device first.
|
|
157
|
+
- After a network error the credits may already be spent: read the balance before trying again.
|
|
158
|
+
|
|
159
|
+
## Remote variables
|
|
160
|
+
|
|
161
|
+
Values you change in the dashboard without shipping an update: a link, a message, a switch.
|
|
162
|
+
|
|
163
|
+
In the dashboard: add them on the Remote Variables page.
|
|
12
164
|
|
|
13
165
|
```js
|
|
14
|
-
import { LicenseClient } from '@licers/sdk';
|
|
166
|
+
import { LicenseClient } from '@licers/sdk';
|
|
15
167
|
|
|
16
|
-
const client = new LicenseClient('YOUR_PUBLIC_KEY', {
|
|
17
|
-
productId: 'YOUR_PRODUCT_ID', //
|
|
18
|
-
appVersion: '2.4.1',
|
|
168
|
+
const client = new LicenseClient('YOUR_PUBLIC_KEY', { // safe to ship inside your app
|
|
169
|
+
productId: 'YOUR_PRODUCT_ID', // your product: refuses keys for your other products
|
|
170
|
+
appVersion: '2.4.1', // shows in Analytics -> App versions
|
|
19
171
|
});
|
|
172
|
+
const key = 'XXXX-XXXX-XXXX-XXXX'; // the customer's license key
|
|
20
173
|
|
|
21
|
-
const result = await client.validate(
|
|
174
|
+
const result = await client.validate(key); // first: this activates the device on the key
|
|
22
175
|
if (!result.valid) {
|
|
23
176
|
console.error('Not licensed:', result.error);
|
|
24
177
|
process.exit(1);
|
|
25
178
|
}
|
|
26
|
-
|
|
179
|
+
|
|
180
|
+
// Values you set on the Remote Variables page. Signed, and only for valid keys.
|
|
181
|
+
const url = await client.getVariable(key, 'download_url'); // null when it isn't set
|
|
182
|
+
const theme = await client.getVariable(key, 'theme', 'dark'); // or your own default
|
|
183
|
+
const everything = await client.getVariables(key); // all this key may see
|
|
184
|
+
|
|
185
|
+
console.log(url, theme, everything);
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
- Check the key on this device first.
|
|
189
|
+
- Values are text. A product’s value wins over one for all products.
|
|
190
|
+
|
|
191
|
+
## Floating seats
|
|
192
|
+
|
|
193
|
+
Let only N people run the app at the same time, on any computers.
|
|
194
|
+
|
|
195
|
+
In the dashboard: set Max concurrent sessions on the key.
|
|
196
|
+
|
|
197
|
+
```js
|
|
198
|
+
import { LicenseClient, SeatUnavailable } from '@licers/sdk';
|
|
199
|
+
|
|
200
|
+
const client = new LicenseClient('YOUR_PUBLIC_KEY', { // safe to ship inside your app
|
|
201
|
+
productId: 'YOUR_PRODUCT_ID', // your product: refuses keys for your other products
|
|
202
|
+
appVersion: '2.4.1', // shows in Analytics -> App versions
|
|
203
|
+
});
|
|
204
|
+
const key = 'XXXX-XXXX-XXXX-XXXX'; // the customer's license key
|
|
205
|
+
|
|
206
|
+
try {
|
|
207
|
+
// Takes a seat and keeps it with heartbeats in the background.
|
|
208
|
+
const seat = await client.session(key, {
|
|
209
|
+
onLost: reason => console.error('Seat lost:', reason), // save the user's work
|
|
210
|
+
});
|
|
211
|
+
console.log('Seat taken:', seat.seats); // { used: 1, max: 5 }
|
|
212
|
+
|
|
213
|
+
try {
|
|
214
|
+
// ... your app runs here. Call this at safe points (before a save, between
|
|
215
|
+
// jobs). It throws SeatUnavailable once the seat is gone.
|
|
216
|
+
seat.ensureActive();
|
|
217
|
+
} finally {
|
|
218
|
+
await seat.stop(); // frees the seat for someone else
|
|
219
|
+
}
|
|
220
|
+
} catch (err) {
|
|
221
|
+
if (!(err instanceof SeatUnavailable)) throw err;
|
|
222
|
+
console.error('No seat:', err.message);
|
|
223
|
+
}
|
|
27
224
|
```
|
|
28
225
|
|
|
29
|
-
|
|
226
|
+
- If the server can’t be reached, the seat is kept until its last signed expiry and then given up.
|
|
227
|
+
- A crashed app frees its seat by itself after the session timeout.
|
|
228
|
+
|
|
229
|
+
## Updates
|
|
30
230
|
|
|
31
|
-
|
|
231
|
+
Tell the customer about a new version. Only a valid, active key is given the download link.
|
|
32
232
|
|
|
33
|
-
|
|
233
|
+
In the dashboard: add the version and its download link on the Releases page.
|
|
34
234
|
|
|
35
235
|
```js
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
//
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
import { verifyOfflineLicense } from '@licers/sdk';
|
|
56
|
-
const lic = verifyOfflineLicense('YOUR_PUBLIC_KEY', 'license.lic', { expectedProductId: 'YOUR_PRODUCT_ID' });
|
|
236
|
+
import { LicenseClient } from '@licers/sdk';
|
|
237
|
+
|
|
238
|
+
const client = new LicenseClient('YOUR_PUBLIC_KEY', { // safe to ship inside your app
|
|
239
|
+
productId: 'YOUR_PRODUCT_ID', // your product: refuses keys for your other products
|
|
240
|
+
appVersion: '2.4.1', // shows in Analytics -> App versions
|
|
241
|
+
});
|
|
242
|
+
const key = 'XXXX-XXXX-XXXX-XXXX'; // the customer's license key
|
|
243
|
+
|
|
244
|
+
const update = await client.checkUpdate(key, '2.4.1', 'stable'); // or 'beta'
|
|
245
|
+
|
|
246
|
+
if (update.updateAvailable) {
|
|
247
|
+
console.log('New version:', update.version);
|
|
248
|
+
console.log("What's new:", update.notes);
|
|
249
|
+
// The answer is signed, but downloadUrl and notes are not: check the URL is
|
|
250
|
+
// on your own host, and verify the file against a hash you publish.
|
|
251
|
+
console.log('Download:', update.downloadUrl);
|
|
252
|
+
} else {
|
|
253
|
+
console.log('You have the latest version.');
|
|
254
|
+
}
|
|
57
255
|
```
|
|
58
256
|
|
|
257
|
+
- The answer is signed, including “no update”. The download link is not: check its host and the file’s hash.
|
|
258
|
+
|
|
59
259
|
## Electron
|
|
60
260
|
|
|
61
261
|
Use the SDK in the **main process** (it needs Node's `crypto`, `fetch` and the OS machine id). Expose the result to your windows through IPC — never ship license logic only in the renderer.
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* import { LicenseClient } from '@licers/sdk';
|
|
6
6
|
* const client = new LicenseClient('YOUR_PUBLIC_KEY', { productId: 'YOUR_PRODUCT_ID' });
|
|
7
|
-
* const result = await client.validate('
|
|
7
|
+
* const result = await client.validate('XXXX-XXXX-XXXX-XXXX');
|
|
8
8
|
* if (!result.valid) quit(result.error);
|
|
9
9
|
*/
|
|
10
10
|
export { LicenseClient, FloatingSession, DEFAULT_API } from './client.js';
|
package/dist/cjs/index.js
CHANGED
|
@@ -7,7 +7,7 @@ exports.SeatUnavailable = exports.ProtocolError = exports.SignatureError = expor
|
|
|
7
7
|
*
|
|
8
8
|
* import { LicenseClient } from '@licers/sdk';
|
|
9
9
|
* const client = new LicenseClient('YOUR_PUBLIC_KEY', { productId: 'YOUR_PRODUCT_ID' });
|
|
10
|
-
* const result = await client.validate('
|
|
10
|
+
* const result = await client.validate('XXXX-XXXX-XXXX-XXXX');
|
|
11
11
|
* if (!result.valid) quit(result.error);
|
|
12
12
|
*/
|
|
13
13
|
var client_js_1 = require("./client.js");
|
package/dist/cjs/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "1.0.
|
|
1
|
+
export declare const SDK_VERSION = "1.0.2";
|
package/dist/cjs/version.js
CHANGED
package/dist/esm/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* import { LicenseClient } from '@licers/sdk';
|
|
6
6
|
* const client = new LicenseClient('YOUR_PUBLIC_KEY', { productId: 'YOUR_PRODUCT_ID' });
|
|
7
|
-
* const result = await client.validate('
|
|
7
|
+
* const result = await client.validate('XXXX-XXXX-XXXX-XXXX');
|
|
8
8
|
* if (!result.valid) quit(result.error);
|
|
9
9
|
*/
|
|
10
10
|
export { LicenseClient, FloatingSession, DEFAULT_API } from './client.js';
|
package/dist/esm/index.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* import { LicenseClient } from '@licers/sdk';
|
|
6
6
|
* const client = new LicenseClient('YOUR_PUBLIC_KEY', { productId: 'YOUR_PRODUCT_ID' });
|
|
7
|
-
* const result = await client.validate('
|
|
7
|
+
* const result = await client.validate('XXXX-XXXX-XXXX-XXXX');
|
|
8
8
|
* if (!result.valid) quit(result.error);
|
|
9
9
|
*/
|
|
10
10
|
export { LicenseClient, FloatingSession, DEFAULT_API } from './client.js';
|
package/dist/esm/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "1.0.
|
|
1
|
+
export declare const SDK_VERSION = "1.0.2";
|
package/dist/esm/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = '1.0.
|
|
1
|
+
export const SDK_VERSION = '1.0.2';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@licers/sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Licers license-key verification for Node.js and Electron: Ed25519-signed responses, floating seats, usage credits, remote variables, offline licenses.",
|
|
5
5
|
"keywords": ["license", "license-key", "licensing", "electron", "software-licensing", "drm", "ed25519", "hwid", "licers"],
|
|
6
6
|
"homepage": "https://licers.com/docs",
|