@carchalabs/licensekit-quickstart 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +25 -2
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +11 -0
- package/dist/bin.js.map +1 -0
- package/dist/cli.d.ts +14 -0
- package/dist/cli.js +103 -0
- package/dist/cli.js.map +1 -0
- package/package.json +20 -4
- package/public-keys/current.pem +3 -0
- package/public-keys/next.pem +3 -0
- package/src/bin.ts +12 -0
- package/src/cli.ts +105 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Bugra Omer Aydemir
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,26 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @carchalabs/licensekit-quickstart
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Try [LicenseKit](https://licensekit.carchalabs.com) from a terminal.
|
|
4
|
+
|
|
5
|
+
1. Get a trial key at [licensekit.carchalabs.com](https://licensekit.carchalabs.com/#try).
|
|
6
|
+
2. Activate this computer:
|
|
7
|
+
|
|
8
|
+
```
|
|
9
|
+
npx @carchalabs/licensekit-quickstart activate LK-XXXX-XXXX-XXXX-XXXX
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
3. Turn off the network and check the license. It is verified offline from the signed lease:
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
npx @carchalabs/licensekit-quickstart status
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
4. Release the seat:
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
npx @carchalabs/licensekit-quickstart deactivate
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
The quickstart sends the license key, a hash of this computer's machine ID, the device name "LicenseKit quickstart" and the platform. It saves the lease without encryption in the per-user application data folder, because a terminal has no system keychain. See the [privacy notice](https://licensekit.carchalabs.com/privacy/).
|
|
25
|
+
|
|
26
|
+
Requires Node 22.13 or later. MIT License.
|
package/dist/bin.d.ts
ADDED
package/dist/bin.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const cli_1 = require("./cli");
|
|
5
|
+
(0, cli_1.run)(process.argv.slice(2), { out: (line) => console.log(line) }).then((code) => {
|
|
6
|
+
process.exitCode = code;
|
|
7
|
+
}, (error) => {
|
|
8
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
9
|
+
process.exitCode = 1;
|
|
10
|
+
});
|
|
11
|
+
//# sourceMappingURL=bin.js.map
|
package/dist/bin.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";;;AACA,+BAA4B;AAE5B,IAAA,SAAG,EAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,CACnE,CAAC,IAAI,EAAE,EAAE;IACP,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;AAC1B,CAAC,EACD,CAAC,KAAK,EAAE,EAAE;IACR,OAAO,CAAC,KAAK,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IACtE,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;AACvB,CAAC,CACF,CAAC"}
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const PRODUCT = "licensekit-demo";
|
|
2
|
+
export declare const DEFAULT_SERVER_URL = "https://licensekit.carchalabs.com";
|
|
3
|
+
export declare const DEVICE_NAME = "LicenseKit quickstart";
|
|
4
|
+
export interface RunOptions {
|
|
5
|
+
out: (line: string) => void;
|
|
6
|
+
storageDir?: string;
|
|
7
|
+
serverUrl?: string;
|
|
8
|
+
publicKeys?: string[];
|
|
9
|
+
fetchImpl?: typeof fetch;
|
|
10
|
+
machineId?: () => Promise<string>;
|
|
11
|
+
}
|
|
12
|
+
export declare function bundledPublicKeys(): string[];
|
|
13
|
+
export declare function defaultStorageDir(os: string, env: Record<string, string | undefined>, home: string): string;
|
|
14
|
+
export declare function run(args: string[], options: RunOptions): Promise<number>;
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEVICE_NAME = exports.DEFAULT_SERVER_URL = exports.PRODUCT = void 0;
|
|
4
|
+
exports.bundledPublicKeys = bundledPublicKeys;
|
|
5
|
+
exports.defaultStorageDir = defaultStorageDir;
|
|
6
|
+
exports.run = run;
|
|
7
|
+
const node_fs_1 = require("node:fs");
|
|
8
|
+
const node_os_1 = require("node:os");
|
|
9
|
+
const node_path_1 = require("node:path");
|
|
10
|
+
const licensekit_electron_1 = require("@carchalabs/licensekit-electron");
|
|
11
|
+
exports.PRODUCT = 'licensekit-demo';
|
|
12
|
+
exports.DEFAULT_SERVER_URL = 'https://licensekit.carchalabs.com';
|
|
13
|
+
exports.DEVICE_NAME = 'LicenseKit quickstart';
|
|
14
|
+
const COMMAND = 'npx @carchalabs/licensekit-quickstart';
|
|
15
|
+
const USAGE = [
|
|
16
|
+
`Usage: ${COMMAND} <command>`,
|
|
17
|
+
'',
|
|
18
|
+
'Commands:',
|
|
19
|
+
' activate <license-key> Activate this computer and save a signed lease',
|
|
20
|
+
' status Check the license. Works offline from the saved lease',
|
|
21
|
+
" deactivate Release this computer's seat",
|
|
22
|
+
'',
|
|
23
|
+
'Get a trial key at https://licensekit.carchalabs.com/#try',
|
|
24
|
+
];
|
|
25
|
+
function bundledPublicKeys() {
|
|
26
|
+
return ['current.pem', 'next.pem'].map((file) => (0, node_fs_1.readFileSync)((0, node_path_1.join)(__dirname, '..', 'public-keys', file), 'utf8'));
|
|
27
|
+
}
|
|
28
|
+
function defaultStorageDir(os, env, home) {
|
|
29
|
+
if (os === 'darwin')
|
|
30
|
+
return (0, node_path_1.join)(home, 'Library', 'Application Support', 'licensekit-quickstart');
|
|
31
|
+
if (os === 'win32')
|
|
32
|
+
return (0, node_path_1.join)(env.APPDATA ?? (0, node_path_1.join)(home, 'AppData', 'Roaming'), 'licensekit-quickstart');
|
|
33
|
+
return (0, node_path_1.join)(env.XDG_CONFIG_HOME || (0, node_path_1.join)(home, '.config'), 'licensekit-quickstart');
|
|
34
|
+
}
|
|
35
|
+
const minute = (iso) => `${iso.slice(0, 10)} ${iso.slice(11, 16)} UTC`;
|
|
36
|
+
function report(state, out) {
|
|
37
|
+
out(`Status: ${state.status}`);
|
|
38
|
+
if (state.message)
|
|
39
|
+
out(state.message);
|
|
40
|
+
if (state.customer)
|
|
41
|
+
out(`Licensed to: ${state.customer}`);
|
|
42
|
+
if (state.status === 'valid' || state.status === 'grace') {
|
|
43
|
+
out(`Features: ${state.features.length ? state.features.join(', ') : 'none'}`);
|
|
44
|
+
out(`Expires: ${state.expiresAt ? minute(state.expiresAt) : 'never'}`);
|
|
45
|
+
if (state.revalidateBy)
|
|
46
|
+
out(`${state.status === 'valid' ? 'Check in by' : 'Works offline until'}: ${minute(state.revalidateBy)}`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async function run(args, options) {
|
|
50
|
+
const { out } = options;
|
|
51
|
+
const [command, key] = args;
|
|
52
|
+
if (command === 'help' || command === '--help' || command === '-h') {
|
|
53
|
+
USAGE.forEach((line) => out(line));
|
|
54
|
+
return 0;
|
|
55
|
+
}
|
|
56
|
+
if (!['activate', 'status', 'deactivate'].includes(command ?? '') || (command === 'activate' && !key)) {
|
|
57
|
+
USAGE.forEach((line) => out(line));
|
|
58
|
+
return 2;
|
|
59
|
+
}
|
|
60
|
+
const kit = new licensekit_electron_1.LicenseKit({
|
|
61
|
+
serverUrl: options.serverUrl ?? exports.DEFAULT_SERVER_URL,
|
|
62
|
+
product: exports.PRODUCT,
|
|
63
|
+
publicKey: options.publicKeys ?? bundledPublicKeys(),
|
|
64
|
+
storageDir: options.storageDir ?? defaultStorageDir((0, node_os_1.platform)(), process.env, (0, node_os_1.homedir)()),
|
|
65
|
+
appVersion: '0.1.0',
|
|
66
|
+
fetchImpl: options.fetchImpl,
|
|
67
|
+
machineId: options.machineId,
|
|
68
|
+
});
|
|
69
|
+
if (command === 'activate') {
|
|
70
|
+
try {
|
|
71
|
+
const state = await kit.activate(key, exports.DEVICE_NAME);
|
|
72
|
+
report(state, out);
|
|
73
|
+
out('Saved lease: not encrypted. A terminal has no system keychain; an Electron app uses safeStorage.');
|
|
74
|
+
out(`Turn off the network and run "${COMMAND} status" to check it offline.`);
|
|
75
|
+
return 0;
|
|
76
|
+
}
|
|
77
|
+
catch (e) {
|
|
78
|
+
out(`Activation failed: ${e instanceof licensekit_electron_1.LicenseError ? e.message : String(e)}`);
|
|
79
|
+
return 1;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (command === 'deactivate') {
|
|
83
|
+
try {
|
|
84
|
+
await kit.deactivate();
|
|
85
|
+
out("This computer's seat is released.");
|
|
86
|
+
return 0;
|
|
87
|
+
}
|
|
88
|
+
catch (e) {
|
|
89
|
+
out(`Deactivation failed: ${e instanceof licensekit_electron_1.LicenseError ? e.message : String(e)}`);
|
|
90
|
+
return 1;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
const state = await kit.check();
|
|
94
|
+
if (state.status === 'unlicensed') {
|
|
95
|
+
out('Status: unlicensed');
|
|
96
|
+
out(`Run "${COMMAND} activate <license-key>" first.`);
|
|
97
|
+
return 1;
|
|
98
|
+
}
|
|
99
|
+
report(state, out);
|
|
100
|
+
out(`Checked: ${state.offline ? 'offline, from the signed lease saved on this computer' : 'online'}`);
|
|
101
|
+
return state.status === 'valid' || state.status === 'grace' ? 0 : 1;
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;AA8BA,8CAEC;AAED,8CAIC;AAeD,kBAmDC;AAxGD,qCAAuC;AACvC,qCAA4C;AAC5C,yCAAiC;AACjC,yEAAyF;AAE5E,QAAA,OAAO,GAAG,iBAAiB,CAAC;AA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AAC;IACH,CAAC;IACD,IAAI,OAAO,KAAK,YAAY,EAAE,CAAC;QAC7B,IAAI,CAAC;YACH,MAAM,GAAG,CAAC,UAAU,EAAE,CAAC;YACvB,GAAG,CAAC,mCAAmC,CAAC,CAAC;YACzC,OAAO,CAAC,CAAC;QACX,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,GAAG,CAAC,wBAAwB,CAAC,YAAY,kCAAY,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;YACjF,OAAO,CAAC,CAAC;QACX,CAAC;IACH,CAAC;IACD,MAAM,KAAK,GAAG,MAAM,GAAG,CAAC,KAAK,EAAE,CAAC;IAChC,IAAI,KAAK,CAAC,MAAM,KAAK,YAAY,EAAE,CAAC;QAClC,GAAG,CAAC,oBAAoB,CAAC,CAAC;QAC1B,GAAG,CAAC,QAAQ,OAAO,iCAAiC,CAAC,CAAC;QACtD,OAAO,CAAC,CAAC;IACX,CAAC;IACD,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACnB,GAAG,CAAC,YAAY,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,uDAAuD,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;IACtG,OAAO,KAAK,CAAC,MAAM,KAAK,OAAO,IAAI,KAAK,CAAC,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACtE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@carchalabs/licensekit-quickstart",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
}
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Try LicenseKit from a terminal: activate a trial key, then check the license offline",
|
|
5
|
+
"homepage": "https://licensekit.carchalabs.com/docs/",
|
|
6
|
+
"repository": { "type": "git", "url": "git+https://github.com/carcha-labs/licensekit-sdk.git", "directory": "packages/quickstart" },
|
|
7
|
+
"bugs": { "url": "https://github.com/carcha-labs/licensekit-sdk/issues" },
|
|
8
|
+
"main": "dist/cli.js",
|
|
9
|
+
"types": "dist/cli.d.ts",
|
|
10
|
+
"bin": { "licensekit-quickstart": "dist/bin.js" },
|
|
11
|
+
"files": ["dist", "src", "public-keys"],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsc -p tsconfig.json",
|
|
14
|
+
"prepublishOnly": "npm run build"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@carchalabs/licensekit-electron": "0.1.0"
|
|
18
|
+
},
|
|
19
|
+
"engines": { "node": ">=22.13" },
|
|
20
|
+
"publishConfig": { "access": "public" },
|
|
21
|
+
"license": "MIT"
|
|
22
|
+
}
|
package/src/bin.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { run } from './cli';
|
|
3
|
+
|
|
4
|
+
run(process.argv.slice(2), { out: (line) => console.log(line) }).then(
|
|
5
|
+
(code) => {
|
|
6
|
+
process.exitCode = code;
|
|
7
|
+
},
|
|
8
|
+
(error) => {
|
|
9
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
10
|
+
process.exitCode = 1;
|
|
11
|
+
},
|
|
12
|
+
);
|
package/src/cli.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { homedir, platform } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { LicenseError, LicenseKit, LicenseState } from '@carchalabs/licensekit-electron';
|
|
5
|
+
|
|
6
|
+
export const PRODUCT = 'licensekit-demo';
|
|
7
|
+
export const DEFAULT_SERVER_URL = 'https://licensekit.carchalabs.com';
|
|
8
|
+
export const DEVICE_NAME = 'LicenseKit quickstart';
|
|
9
|
+
const COMMAND = 'npx @carchalabs/licensekit-quickstart';
|
|
10
|
+
|
|
11
|
+
export interface RunOptions {
|
|
12
|
+
out: (line: string) => void;
|
|
13
|
+
storageDir?: string;
|
|
14
|
+
serverUrl?: string;
|
|
15
|
+
publicKeys?: string[];
|
|
16
|
+
fetchImpl?: typeof fetch;
|
|
17
|
+
machineId?: () => Promise<string>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const USAGE = [
|
|
21
|
+
`Usage: ${COMMAND} <command>`,
|
|
22
|
+
'',
|
|
23
|
+
'Commands:',
|
|
24
|
+
' activate <license-key> Activate this computer and save a signed lease',
|
|
25
|
+
' status Check the license. Works offline from the saved lease',
|
|
26
|
+
" deactivate Release this computer's seat",
|
|
27
|
+
'',
|
|
28
|
+
'Get a trial key at https://licensekit.carchalabs.com/#try',
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
export function bundledPublicKeys(): string[] {
|
|
32
|
+
return ['current.pem', 'next.pem'].map((file) => readFileSync(join(__dirname, '..', 'public-keys', file), 'utf8'));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function defaultStorageDir(os: string, env: Record<string, string | undefined>, home: string): string {
|
|
36
|
+
if (os === 'darwin') return join(home, 'Library', 'Application Support', 'licensekit-quickstart');
|
|
37
|
+
if (os === 'win32') return join(env.APPDATA ?? join(home, 'AppData', 'Roaming'), 'licensekit-quickstart');
|
|
38
|
+
return join(env.XDG_CONFIG_HOME || join(home, '.config'), 'licensekit-quickstart');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const minute = (iso: string) => `${iso.slice(0, 10)} ${iso.slice(11, 16)} UTC`;
|
|
42
|
+
|
|
43
|
+
function report(state: LicenseState, out: (line: string) => void) {
|
|
44
|
+
out(`Status: ${state.status}`);
|
|
45
|
+
if (state.message) out(state.message);
|
|
46
|
+
if (state.customer) out(`Licensed to: ${state.customer}`);
|
|
47
|
+
if (state.status === 'valid' || state.status === 'grace') {
|
|
48
|
+
out(`Features: ${state.features.length ? state.features.join(', ') : 'none'}`);
|
|
49
|
+
out(`Expires: ${state.expiresAt ? minute(state.expiresAt) : 'never'}`);
|
|
50
|
+
if (state.revalidateBy) out(`${state.status === 'valid' ? 'Check in by' : 'Works offline until'}: ${minute(state.revalidateBy)}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export async function run(args: string[], options: RunOptions): Promise<number> {
|
|
55
|
+
const { out } = options;
|
|
56
|
+
const [command, key] = args;
|
|
57
|
+
if (command === 'help' || command === '--help' || command === '-h') {
|
|
58
|
+
USAGE.forEach((line) => out(line));
|
|
59
|
+
return 0;
|
|
60
|
+
}
|
|
61
|
+
if (!['activate', 'status', 'deactivate'].includes(command ?? '') || (command === 'activate' && !key)) {
|
|
62
|
+
USAGE.forEach((line) => out(line));
|
|
63
|
+
return 2;
|
|
64
|
+
}
|
|
65
|
+
const kit = new LicenseKit({
|
|
66
|
+
serverUrl: options.serverUrl ?? DEFAULT_SERVER_URL,
|
|
67
|
+
product: PRODUCT,
|
|
68
|
+
publicKey: options.publicKeys ?? bundledPublicKeys(),
|
|
69
|
+
storageDir: options.storageDir ?? defaultStorageDir(platform(), process.env, homedir()),
|
|
70
|
+
appVersion: '0.1.0',
|
|
71
|
+
fetchImpl: options.fetchImpl,
|
|
72
|
+
machineId: options.machineId,
|
|
73
|
+
});
|
|
74
|
+
if (command === 'activate') {
|
|
75
|
+
try {
|
|
76
|
+
const state = await kit.activate(key, DEVICE_NAME);
|
|
77
|
+
report(state, out);
|
|
78
|
+
out('Saved lease: not encrypted. A terminal has no system keychain; an Electron app uses safeStorage.');
|
|
79
|
+
out(`Turn off the network and run "${COMMAND} status" to check it offline.`);
|
|
80
|
+
return 0;
|
|
81
|
+
} catch (e) {
|
|
82
|
+
out(`Activation failed: ${e instanceof LicenseError ? e.message : String(e)}`);
|
|
83
|
+
return 1;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (command === 'deactivate') {
|
|
87
|
+
try {
|
|
88
|
+
await kit.deactivate();
|
|
89
|
+
out("This computer's seat is released.");
|
|
90
|
+
return 0;
|
|
91
|
+
} catch (e) {
|
|
92
|
+
out(`Deactivation failed: ${e instanceof LicenseError ? e.message : String(e)}`);
|
|
93
|
+
return 1;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const state = await kit.check();
|
|
97
|
+
if (state.status === 'unlicensed') {
|
|
98
|
+
out('Status: unlicensed');
|
|
99
|
+
out(`Run "${COMMAND} activate <license-key>" first.`);
|
|
100
|
+
return 1;
|
|
101
|
+
}
|
|
102
|
+
report(state, out);
|
|
103
|
+
out(`Checked: ${state.offline ? 'offline, from the signed lease saved on this computer' : 'online'}`);
|
|
104
|
+
return state.status === 'valid' || state.status === 'grace' ? 0 : 1;
|
|
105
|
+
}
|