@licensespring/node-sdk 1.1.18 → 1.2.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.
Files changed (66) hide show
  1. package/License.key +1 -0
  2. package/dist/package.json +16 -9
  3. package/dist/src/abstract-manager.d.ts +42 -15
  4. package/dist/src/abstract-manager.js +248 -22
  5. package/dist/src/abstract-manager.js.map +1 -1
  6. package/dist/src/api.d.ts +25 -4978
  7. package/dist/src/api.js +1596 -4511
  8. package/dist/src/api.js.map +1 -1
  9. package/dist/src/bundle-file.d.ts +11 -0
  10. package/dist/src/bundle-file.js +110 -0
  11. package/dist/src/bundle-file.js.map +1 -0
  12. package/dist/src/bundle-manager.d.ts +17 -0
  13. package/dist/src/bundle-manager.js +252 -0
  14. package/dist/src/bundle-manager.js.map +1 -0
  15. package/dist/src/common.d.ts +1 -0
  16. package/dist/src/common.js +5 -1
  17. package/dist/src/common.js.map +1 -1
  18. package/dist/src/index.d.ts +2 -1
  19. package/dist/src/index.js +3 -1
  20. package/dist/src/index.js.map +1 -1
  21. package/dist/src/license-data.d.ts +13 -7
  22. package/dist/src/license-data.js +66 -71
  23. package/dist/src/license-data.js.map +1 -1
  24. package/dist/src/license-file.d.ts +8 -19
  25. package/dist/src/license-file.js +38 -315
  26. package/dist/src/license-file.js.map +1 -1
  27. package/dist/src/license-manager.d.ts +23 -32
  28. package/dist/src/license-manager.js +213 -313
  29. package/dist/src/license-manager.js.map +1 -1
  30. package/dist/src/license.d.ts +16 -15
  31. package/dist/src/license.js +145 -142
  32. package/dist/src/license.js.map +1 -1
  33. package/dist/src/logger.d.ts +1 -0
  34. package/dist/src/logger.js +28 -5
  35. package/dist/src/logger.js.map +1 -1
  36. package/dist/src/offline-activation.d.ts +2 -1
  37. package/dist/src/offline-activation.js.map +1 -1
  38. package/dist/src/response-types.d.ts +489 -0
  39. package/dist/src/response-types.js +12 -0
  40. package/dist/src/response-types.js.map +1 -0
  41. package/dist/src/schema.d.ts +4 -2
  42. package/dist/src/schema.js +6 -2
  43. package/dist/src/schema.js.map +1 -1
  44. package/dist/src/storage-file.d.ts +24 -0
  45. package/dist/src/storage-file.js +354 -0
  46. package/dist/src/storage-file.js.map +1 -0
  47. package/dist/src/test/api-response-mock.d.ts +1435 -0
  48. package/dist/src/test/api-response-mock.js +1966 -0
  49. package/dist/src/test/api-response-mock.js.map +1 -0
  50. package/dist/src/test/api.test.d.ts +1 -0
  51. package/dist/src/test/api.test.js +228 -0
  52. package/dist/src/test/api.test.js.map +1 -0
  53. package/dist/src/test/bundle-manager.test.d.ts +0 -0
  54. package/dist/src/test/bundle-manager.test.js +15 -0
  55. package/dist/src/test/bundle-manager.test.js.map +1 -0
  56. package/dist/src/test/jest.setup.d.ts +1 -0
  57. package/dist/src/test/jest.setup.js +17 -0
  58. package/dist/src/test/jest.setup.js.map +1 -0
  59. package/dist/src/test/license-manager.test.d.ts +1 -0
  60. package/dist/src/test/license-manager.test.js +1011 -0
  61. package/dist/src/test/license-manager.test.js.map +1 -0
  62. package/dist/src/types.d.ts +35 -219
  63. package/dist/src/types.js.map +1 -1
  64. package/dist/src/watchdog.js +1 -1
  65. package/dist/src/watchdog.js.map +1 -1
  66. package/package.json +16 -9
@@ -0,0 +1,24 @@
1
+ import { GuardFileData, LicenseSaved, LicensespringConfig } from './types';
2
+ import OfflineActivation from './offline-activation';
3
+ import LicenseData from './license-data';
4
+ export default abstract class StorageFile {
5
+ protected readonly config: LicensespringConfig;
6
+ protected readonly hardwareID: string;
7
+ licenseDataCache: Record<string, LicenseData>;
8
+ protected readonly key: string;
9
+ constructor(config: LicensespringConfig, hardwareID: string);
10
+ abstract saveLicenseFile(): void;
11
+ protected abstract parseLicenseFile(path: string): Record<string, LicenseSaved>;
12
+ protected encrypt(payload: string): string;
13
+ protected decrypt(encryptedPayload: string): string;
14
+ createRequestFile(request: OfflineActivation, offlinePath: string): void;
15
+ saveGuardFile(payload: GuardFileData): void;
16
+ removeGuardFile(): void;
17
+ loadGuardFile(): GuardFileData;
18
+ loadOfflineLicense(path: string): string;
19
+ loadOfflineResponse(path: string): OfflineActivation;
20
+ loadLicenseFile(): Record<string, LicenseSaved>;
21
+ setPath(productCode: string, customPath?: string): string;
22
+ deleteLicenseFile(): void;
23
+ clearStorage(): void;
24
+ }
@@ -0,0 +1,354 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const fs = __importStar(require("node:fs"));
30
+ const path = __importStar(require("node:path"));
31
+ const crypto = __importStar(require("node:crypto"));
32
+ const os = __importStar(require("node:os"));
33
+ const typia_1 = __importDefault(require("typia"));
34
+ const offline_activation_1 = __importDefault(require("./offline-activation"));
35
+ const license_data_1 = __importDefault(require("./license-data"));
36
+ class StorageFile {
37
+ constructor(config, hardwareID) {
38
+ this.config = config;
39
+ this.hardwareID = hardwareID;
40
+ this.licenseDataCache = {};
41
+ (() => { const $guard = typia_1.default.assert.guard; const $io0 = input => "string" === typeof input.apiKey && "string" === typeof input.sharedKey && "string" === typeof input.apiPath && "string" === typeof input.publicKey && "string" === typeof input.productCode && "string" === typeof input.appName && "string" === typeof input.appVersion && "string" === typeof input.filePath && "string" === typeof input.filename && "number" === typeof input.gracePeriod && "string" === typeof input.fileKey && (undefined === input.airGapKey || "string" === typeof input.airGapKey) && "boolean" === typeof input.isGuardFileEnabled && "number" === typeof input.hardwareIDMethod && "string" === typeof input.sdkVersion && (undefined === input.proxy || "object" === typeof input.proxy && null !== input.proxy && $io1(input.proxy)) && (undefined === input.logLevel || "debug" === input.logLevel || "info" === input.logLevel || "warn" === input.logLevel || "error" === input.logLevel || "off" === input.logLevel); const $io1 = input => "string" === typeof input.host && "number" === typeof input.port && (undefined === input.auth || "object" === typeof input.auth && null !== input.auth && $io2(input.auth)) && (undefined === input.protocol || "string" === typeof input.protocol); const $io2 = input => "string" === typeof input.username && "string" === typeof input.password; const $io3 = input => "string" === typeof input.clientID && "string" === typeof input.clientSecret && "string" === typeof input.tokenUrl && "string" === typeof input.apiPath && "string" === typeof input.publicKey && "string" === typeof input.productCode && "string" === typeof input.appName && "string" === typeof input.appVersion && "string" === typeof input.filePath && "string" === typeof input.filename && "number" === typeof input.gracePeriod && "string" === typeof input.fileKey && (undefined === input.airGapKey || "string" === typeof input.airGapKey) && "boolean" === typeof input.isGuardFileEnabled && "number" === typeof input.hardwareIDMethod && "string" === typeof input.sdkVersion && (undefined === input.proxy || "object" === typeof input.proxy && null !== input.proxy && $io1(input.proxy)) && (undefined === input.logLevel || "debug" === input.logLevel || "info" === input.logLevel || "warn" === input.logLevel || "error" === input.logLevel || "off" === input.logLevel); const $iu0 = input => (() => {
42
+ if (undefined !== input.apiKey)
43
+ return $io0(input);
44
+ else if (undefined !== input.clientID)
45
+ return $io3(input);
46
+ else
47
+ return false;
48
+ })(); const $ao0 = (input, _path, _exceptionable = true) => ("string" === typeof input.apiKey || $guard(_exceptionable, {
49
+ path: _path + ".apiKey",
50
+ expected: "string",
51
+ value: input.apiKey
52
+ }, _errorFactory)) && ("string" === typeof input.sharedKey || $guard(_exceptionable, {
53
+ path: _path + ".sharedKey",
54
+ expected: "string",
55
+ value: input.sharedKey
56
+ }, _errorFactory)) && ("string" === typeof input.apiPath || $guard(_exceptionable, {
57
+ path: _path + ".apiPath",
58
+ expected: "string",
59
+ value: input.apiPath
60
+ }, _errorFactory)) && ("string" === typeof input.publicKey || $guard(_exceptionable, {
61
+ path: _path + ".publicKey",
62
+ expected: "string",
63
+ value: input.publicKey
64
+ }, _errorFactory)) && ("string" === typeof input.productCode || $guard(_exceptionable, {
65
+ path: _path + ".productCode",
66
+ expected: "string",
67
+ value: input.productCode
68
+ }, _errorFactory)) && ("string" === typeof input.appName || $guard(_exceptionable, {
69
+ path: _path + ".appName",
70
+ expected: "string",
71
+ value: input.appName
72
+ }, _errorFactory)) && ("string" === typeof input.appVersion || $guard(_exceptionable, {
73
+ path: _path + ".appVersion",
74
+ expected: "string",
75
+ value: input.appVersion
76
+ }, _errorFactory)) && ("string" === typeof input.filePath || $guard(_exceptionable, {
77
+ path: _path + ".filePath",
78
+ expected: "string",
79
+ value: input.filePath
80
+ }, _errorFactory)) && ("string" === typeof input.filename || $guard(_exceptionable, {
81
+ path: _path + ".filename",
82
+ expected: "string",
83
+ value: input.filename
84
+ }, _errorFactory)) && ("number" === typeof input.gracePeriod || $guard(_exceptionable, {
85
+ path: _path + ".gracePeriod",
86
+ expected: "number",
87
+ value: input.gracePeriod
88
+ }, _errorFactory)) && ("string" === typeof input.fileKey || $guard(_exceptionable, {
89
+ path: _path + ".fileKey",
90
+ expected: "string",
91
+ value: input.fileKey
92
+ }, _errorFactory)) && (undefined === input.airGapKey || "string" === typeof input.airGapKey || $guard(_exceptionable, {
93
+ path: _path + ".airGapKey",
94
+ expected: "(string | undefined)",
95
+ value: input.airGapKey
96
+ }, _errorFactory)) && ("boolean" === typeof input.isGuardFileEnabled || $guard(_exceptionable, {
97
+ path: _path + ".isGuardFileEnabled",
98
+ expected: "boolean",
99
+ value: input.isGuardFileEnabled
100
+ }, _errorFactory)) && ("number" === typeof input.hardwareIDMethod || $guard(_exceptionable, {
101
+ path: _path + ".hardwareIDMethod",
102
+ expected: "number",
103
+ value: input.hardwareIDMethod
104
+ }, _errorFactory)) && ("string" === typeof input.sdkVersion || $guard(_exceptionable, {
105
+ path: _path + ".sdkVersion",
106
+ expected: "string",
107
+ value: input.sdkVersion
108
+ }, _errorFactory)) && (undefined === input.proxy || ("object" === typeof input.proxy && null !== input.proxy || $guard(_exceptionable, {
109
+ path: _path + ".proxy",
110
+ expected: "(AxiosProxyConfig | undefined)",
111
+ value: input.proxy
112
+ }, _errorFactory)) && $ao1(input.proxy, _path + ".proxy", true && _exceptionable) || $guard(_exceptionable, {
113
+ path: _path + ".proxy",
114
+ expected: "(AxiosProxyConfig | undefined)",
115
+ value: input.proxy
116
+ }, _errorFactory)) && (undefined === input.logLevel || "debug" === input.logLevel || "info" === input.logLevel || "warn" === input.logLevel || "error" === input.logLevel || "off" === input.logLevel || $guard(_exceptionable, {
117
+ path: _path + ".logLevel",
118
+ expected: "(\"debug\" | \"error\" | \"info\" | \"off\" | \"warn\" | undefined)",
119
+ value: input.logLevel
120
+ }, _errorFactory)); const $ao1 = (input, _path, _exceptionable = true) => ("string" === typeof input.host || $guard(_exceptionable, {
121
+ path: _path + ".host",
122
+ expected: "string",
123
+ value: input.host
124
+ }, _errorFactory)) && ("number" === typeof input.port || $guard(_exceptionable, {
125
+ path: _path + ".port",
126
+ expected: "number",
127
+ value: input.port
128
+ }, _errorFactory)) && (undefined === input.auth || ("object" === typeof input.auth && null !== input.auth || $guard(_exceptionable, {
129
+ path: _path + ".auth",
130
+ expected: "(AxiosBasicCredentials | undefined)",
131
+ value: input.auth
132
+ }, _errorFactory)) && $ao2(input.auth, _path + ".auth", true && _exceptionable) || $guard(_exceptionable, {
133
+ path: _path + ".auth",
134
+ expected: "(AxiosBasicCredentials | undefined)",
135
+ value: input.auth
136
+ }, _errorFactory)) && (undefined === input.protocol || "string" === typeof input.protocol || $guard(_exceptionable, {
137
+ path: _path + ".protocol",
138
+ expected: "(string | undefined)",
139
+ value: input.protocol
140
+ }, _errorFactory)); const $ao2 = (input, _path, _exceptionable = true) => ("string" === typeof input.username || $guard(_exceptionable, {
141
+ path: _path + ".username",
142
+ expected: "string",
143
+ value: input.username
144
+ }, _errorFactory)) && ("string" === typeof input.password || $guard(_exceptionable, {
145
+ path: _path + ".password",
146
+ expected: "string",
147
+ value: input.password
148
+ }, _errorFactory)); const $ao3 = (input, _path, _exceptionable = true) => ("string" === typeof input.clientID || $guard(_exceptionable, {
149
+ path: _path + ".clientID",
150
+ expected: "string",
151
+ value: input.clientID
152
+ }, _errorFactory)) && ("string" === typeof input.clientSecret || $guard(_exceptionable, {
153
+ path: _path + ".clientSecret",
154
+ expected: "string",
155
+ value: input.clientSecret
156
+ }, _errorFactory)) && ("string" === typeof input.tokenUrl || $guard(_exceptionable, {
157
+ path: _path + ".tokenUrl",
158
+ expected: "string",
159
+ value: input.tokenUrl
160
+ }, _errorFactory)) && ("string" === typeof input.apiPath || $guard(_exceptionable, {
161
+ path: _path + ".apiPath",
162
+ expected: "string",
163
+ value: input.apiPath
164
+ }, _errorFactory)) && ("string" === typeof input.publicKey || $guard(_exceptionable, {
165
+ path: _path + ".publicKey",
166
+ expected: "string",
167
+ value: input.publicKey
168
+ }, _errorFactory)) && ("string" === typeof input.productCode || $guard(_exceptionable, {
169
+ path: _path + ".productCode",
170
+ expected: "string",
171
+ value: input.productCode
172
+ }, _errorFactory)) && ("string" === typeof input.appName || $guard(_exceptionable, {
173
+ path: _path + ".appName",
174
+ expected: "string",
175
+ value: input.appName
176
+ }, _errorFactory)) && ("string" === typeof input.appVersion || $guard(_exceptionable, {
177
+ path: _path + ".appVersion",
178
+ expected: "string",
179
+ value: input.appVersion
180
+ }, _errorFactory)) && ("string" === typeof input.filePath || $guard(_exceptionable, {
181
+ path: _path + ".filePath",
182
+ expected: "string",
183
+ value: input.filePath
184
+ }, _errorFactory)) && ("string" === typeof input.filename || $guard(_exceptionable, {
185
+ path: _path + ".filename",
186
+ expected: "string",
187
+ value: input.filename
188
+ }, _errorFactory)) && ("number" === typeof input.gracePeriod || $guard(_exceptionable, {
189
+ path: _path + ".gracePeriod",
190
+ expected: "number",
191
+ value: input.gracePeriod
192
+ }, _errorFactory)) && ("string" === typeof input.fileKey || $guard(_exceptionable, {
193
+ path: _path + ".fileKey",
194
+ expected: "string",
195
+ value: input.fileKey
196
+ }, _errorFactory)) && (undefined === input.airGapKey || "string" === typeof input.airGapKey || $guard(_exceptionable, {
197
+ path: _path + ".airGapKey",
198
+ expected: "(string | undefined)",
199
+ value: input.airGapKey
200
+ }, _errorFactory)) && ("boolean" === typeof input.isGuardFileEnabled || $guard(_exceptionable, {
201
+ path: _path + ".isGuardFileEnabled",
202
+ expected: "boolean",
203
+ value: input.isGuardFileEnabled
204
+ }, _errorFactory)) && ("number" === typeof input.hardwareIDMethod || $guard(_exceptionable, {
205
+ path: _path + ".hardwareIDMethod",
206
+ expected: "number",
207
+ value: input.hardwareIDMethod
208
+ }, _errorFactory)) && ("string" === typeof input.sdkVersion || $guard(_exceptionable, {
209
+ path: _path + ".sdkVersion",
210
+ expected: "string",
211
+ value: input.sdkVersion
212
+ }, _errorFactory)) && (undefined === input.proxy || ("object" === typeof input.proxy && null !== input.proxy || $guard(_exceptionable, {
213
+ path: _path + ".proxy",
214
+ expected: "(AxiosProxyConfig | undefined)",
215
+ value: input.proxy
216
+ }, _errorFactory)) && $ao1(input.proxy, _path + ".proxy", true && _exceptionable) || $guard(_exceptionable, {
217
+ path: _path + ".proxy",
218
+ expected: "(AxiosProxyConfig | undefined)",
219
+ value: input.proxy
220
+ }, _errorFactory)) && (undefined === input.logLevel || "debug" === input.logLevel || "info" === input.logLevel || "warn" === input.logLevel || "error" === input.logLevel || "off" === input.logLevel || $guard(_exceptionable, {
221
+ path: _path + ".logLevel",
222
+ expected: "(\"debug\" | \"error\" | \"info\" | \"off\" | \"warn\" | undefined)",
223
+ value: input.logLevel
224
+ }, _errorFactory)); const $au0 = (input, _path, _exceptionable = true) => (() => {
225
+ if (undefined !== input.apiKey)
226
+ return $ao0(input, _path, true && _exceptionable);
227
+ else if (undefined !== input.clientID)
228
+ return $ao3(input, _path, true && _exceptionable);
229
+ else
230
+ return $guard(_exceptionable, {
231
+ path: _path,
232
+ expected: "({ apiKey: string; sharedKey: string; } & { apiPath: string; publicKey: string; productCode: string; appName: string; appVersion: string; filePath: string; filename: string; gracePeriod: number; ... 6 more ...; logLevel?: LogLevel | undefined; } | { clientID: string; clientSecret: string; tokenUrl: string; } & { apiPath: string; publicKey: string; productCode: string; appName: string; appVersion: string; filePath: string; filename: string; ... 7 more ...; logLevel?: LogLevel | undefined; })",
233
+ value: input
234
+ }, _errorFactory);
235
+ })(); const __is = input => "object" === typeof input && null !== input && $iu0(input); let _errorFactory; return (input, errorFactory) => {
236
+ if (false === __is(input)) {
237
+ _errorFactory = errorFactory;
238
+ ((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || $guard(true, {
239
+ path: _path + "",
240
+ expected: "({ apiKey: string; sharedKey: string; } & { apiPath: string; publicKey: string; productCode: string; appName: string; appVersion: string; filePath: string; filename: string; gracePeriod: number; ... 6 more ...; logLevel?: LogLevel | undefined; } | { clientID: string; clientSecret: string; tokenUrl: string; } & { apiPath: string; publicKey: string; productCode: string; appName: string; appVersion: string; filePath: string; filename: string; ... 7 more ...; logLevel?: LogLevel | undefined; })",
241
+ value: input
242
+ }, _errorFactory)) && $au0(input, _path + "", true) || $guard(true, {
243
+ path: _path + "",
244
+ expected: "({ apiKey: string; sharedKey: string; } & { apiPath: string; publicKey: string; productCode: string; appName: string; appVersion: string; filePath: string; filename: string; gracePeriod: number; ... 6 more ...; logLevel?: LogLevel | undefined; } | { clientID: string; clientSecret: string; tokenUrl: string; } & { apiPath: string; publicKey: string; productCode: string; appName: string; appVersion: string; filePath: string; filename: string; ... 7 more ...; logLevel?: LogLevel | undefined; })",
245
+ value: input
246
+ }, _errorFactory))(input, "$input", true);
247
+ }
248
+ return input;
249
+ }; })()(config);
250
+ this.key = crypto.createHash('sha256').update(this.config.fileKey).digest('base64').slice(0, 32);
251
+ this.licenseDataCache = {
252
+ [config.productCode]: new license_data_1.default(config.productCode, config.gracePeriod, this.hardwareID)
253
+ };
254
+ }
255
+ encrypt(payload) {
256
+ const iv = crypto.randomBytes(16);
257
+ const header = iv.toString('base64').slice(0, 24);
258
+ const cipher = crypto.createCipheriv('aes-256-cbc', this.key, iv);
259
+ let encrypted = cipher.update(payload, 'utf8', 'base64');
260
+ encrypted += cipher.final('base64');
261
+ return header + encrypted;
262
+ }
263
+ decrypt(encryptedPayload) {
264
+ const ivBase64 = encryptedPayload.slice(0, 24);
265
+ const encryptedBase64 = encryptedPayload.slice(24);
266
+ const iv = Buffer.from(ivBase64, 'base64');
267
+ const decipher = crypto.createDecipheriv('aes-256-cbc', this.key, iv);
268
+ let decrypted = decipher.update(encryptedBase64, 'base64', 'utf8');
269
+ decrypted += decipher.final('utf8');
270
+ return decrypted;
271
+ }
272
+ createRequestFile(request, offlinePath) {
273
+ if (!fs.existsSync(offlinePath)) {
274
+ fs.mkdirSync(offlinePath, { recursive: true });
275
+ }
276
+ const filename = request.isActivation ? 'activate_offline.req' : 'deactivate_offline.req';
277
+ const payload = Buffer.from(JSON.stringify(request.data), 'base64').toString();
278
+ fs.writeFileSync(path.join(offlinePath, filename), payload);
279
+ if (request.isActivation) {
280
+ this.saveGuardFile(request.guard);
281
+ }
282
+ }
283
+ saveGuardFile(payload) {
284
+ if (this.config.isGuardFileEnabled) {
285
+ if (!fs.existsSync(this.config.filePath)) {
286
+ fs.mkdirSync(this.config.filePath, { recursive: true });
287
+ }
288
+ const payloadEncrypted = this.encrypt(JSON.stringify(payload));
289
+ fs.writeFileSync(path.join(this.config.filePath, 'OfflineActivation.guard'), payloadEncrypted);
290
+ }
291
+ }
292
+ removeGuardFile() {
293
+ const filepath = path.join(this.config.filePath, 'OfflineActivation.guard');
294
+ if (fs.existsSync(filepath)) {
295
+ fs.unlinkSync(filepath);
296
+ }
297
+ }
298
+ loadGuardFile() {
299
+ const filepath = path.join(this.config.filePath, 'OfflineActivation.guard');
300
+ const encryptedPayload = fs.readFileSync(filepath).toString();
301
+ return JSON.parse(this.decrypt(encryptedPayload));
302
+ }
303
+ loadOfflineLicense(path) {
304
+ return fs.readFileSync(path).toString();
305
+ }
306
+ loadOfflineResponse(path) {
307
+ const offlineData = new offline_activation_1.default();
308
+ offlineData.isActivation = true;
309
+ offlineData.data = this.parseLicenseFile(path)[this.config.productCode];
310
+ offlineData.isGuardFileEnabled = this.config.isGuardFileEnabled;
311
+ if (this.config.isGuardFileEnabled) {
312
+ offlineData.guard = this.loadGuardFile();
313
+ }
314
+ return offlineData;
315
+ }
316
+ loadLicenseFile() {
317
+ const filepath = path.join(this.config.filePath, this.config.filename + '.key');
318
+ return this.parseLicenseFile(filepath);
319
+ }
320
+ setPath(productCode, customPath) {
321
+ if (customPath) {
322
+ return customPath;
323
+ }
324
+ let filepath;
325
+ if (os.platform() == 'win32') {
326
+ filepath = process.env.SYSTEMDRIVE && process.env.USERNAME ? path.join(path.join(process.env.SYSTEMDRIVE, 'Users', process.env.USERNAME), 'AppData', 'Local', 'LicenseSpring', productCode) : null;
327
+ }
328
+ else if (process.env.HOME) {
329
+ filepath = path.join(process.env.HOME, '.LicenseSpring', 'LicenseSpring', productCode);
330
+ }
331
+ else if (os.homedir()) {
332
+ filepath = path.join(os.homedir(), 'Library', 'Application Support', 'LicenseSpring', productCode);
333
+ }
334
+ if (filepath)
335
+ return filepath;
336
+ throw { status: 500, code: 'unsupported_operating_system', message: 'Unsupported operating system' };
337
+ }
338
+ deleteLicenseFile() {
339
+ this.removeGuardFile();
340
+ const filepath = path.join(this.config.filePath, this.config.filename + '.key');
341
+ if (fs.existsSync(filepath)) {
342
+ fs.unlinkSync(filepath);
343
+ }
344
+ }
345
+ clearStorage() {
346
+ this.deleteLicenseFile();
347
+ this.removeGuardFile();
348
+ if (fs.existsSync(this.config.filePath)) {
349
+ fs.rmdirSync(this.config.filePath, { recursive: true });
350
+ }
351
+ }
352
+ }
353
+ exports.default = StorageFile;
354
+ //# sourceMappingURL=storage-file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage-file.js","sourceRoot":"","sources":["../../src/storage-file.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA8B;AAC9B,gDAAkC;AAClC,oDAAsC;AACtC,4CAA8B;AAC9B,kDAA0B;AAE1B,8EAAqD;AACrD,kEAAyC;AAEzC,MAA8B,WAAW;IAKvC,YAA+B,MAA2B,EAAqB,UAAkB;QAAlE,WAAM,GAAN,MAAM,CAAqB;QAAqB,eAAU,GAAV,UAAU,CAAQ;QAH1F,qBAAgB,GAAgC,EAAE,CAAC;QAIxD,wBAAA,eAAK,CAAC,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gBAAsB,MAAM,EAAE;QAC1C,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACjG,IAAI,CAAC,gBAAgB,GAAG;YACtB,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,IAAI,sBAAW,CAAC,MAAM,CA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