project-shield 1.0.2 → 1.1.1
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 +87 -9
- package/dist/index.js +62 -20
- package/dist/index.js.map +1 -1
- package/dist/license/commands.d.ts +17 -0
- package/dist/license/commands.d.ts.map +1 -0
- package/dist/license/commands.js +154 -0
- package/dist/license/commands.js.map +1 -0
- package/dist/license/gate.d.ts +14 -0
- package/dist/license/gate.d.ts.map +1 -0
- package/dist/license/gate.js +35 -0
- package/dist/license/gate.js.map +1 -0
- package/dist/license/http.d.ts +7 -0
- package/dist/license/http.d.ts.map +1 -0
- package/dist/license/http.js +89 -0
- package/dist/license/http.js.map +1 -0
- package/dist/license/index.d.ts +6 -0
- package/dist/license/index.d.ts.map +1 -0
- package/dist/license/index.js +20 -0
- package/dist/license/index.js.map +1 -0
- package/dist/license/storage.d.ts +31 -0
- package/dist/license/storage.d.ts.map +1 -0
- package/dist/license/storage.js +138 -0
- package/dist/license/storage.js.map +1 -0
- package/dist/license/types.d.ts +55 -0
- package/dist/license/types.d.ts.map +1 -0
- package/dist/license/types.js +4 -0
- package/dist/license/types.js.map +1 -0
- package/dist/license/usage.d.ts +22 -0
- package/dist/license/usage.d.ts.map +1 -0
- package/dist/license/usage.js +60 -0
- package/dist/license/usage.js.map +1 -0
- package/dist/license/validator.d.ts +28 -0
- package/dist/license/validator.d.ts.map +1 -0
- package/dist/license/validator.js +108 -0
- package/dist/license/validator.js.map +1 -0
- package/dist/output/terminal.d.ts +8 -2
- package/dist/output/terminal.d.ts.map +1 -1
- package/dist/output/terminal.js +21 -2
- package/dist/output/terminal.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,89 @@
|
|
|
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 () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.postJSON = postJSON;
|
|
37
|
+
const https = __importStar(require("node:https"));
|
|
38
|
+
const http = __importStar(require("node:http"));
|
|
39
|
+
const TIMEOUT_MS = 5000;
|
|
40
|
+
/**
|
|
41
|
+
* POST JSON to a URL and parse the JSON response.
|
|
42
|
+
* Uses node:https (no external dependencies).
|
|
43
|
+
* Timeout: 5 seconds.
|
|
44
|
+
*/
|
|
45
|
+
function postJSON(url, body) {
|
|
46
|
+
return new Promise((resolve, reject) => {
|
|
47
|
+
const data = JSON.stringify(body);
|
|
48
|
+
const parsed = new URL(url);
|
|
49
|
+
const isHttps = parsed.protocol === 'https:';
|
|
50
|
+
const options = {
|
|
51
|
+
hostname: parsed.hostname,
|
|
52
|
+
port: parsed.port || (isHttps ? 443 : 80),
|
|
53
|
+
path: parsed.pathname + parsed.search,
|
|
54
|
+
method: 'POST',
|
|
55
|
+
headers: {
|
|
56
|
+
'Content-Type': 'application/json',
|
|
57
|
+
'Content-Length': Buffer.byteLength(data),
|
|
58
|
+
'User-Agent': 'project-shield-cli/1.0.0',
|
|
59
|
+
},
|
|
60
|
+
timeout: TIMEOUT_MS,
|
|
61
|
+
};
|
|
62
|
+
const transport = isHttps ? https : http;
|
|
63
|
+
const req = transport.request(options, (res) => {
|
|
64
|
+
let responseBody = '';
|
|
65
|
+
res.setEncoding('utf-8');
|
|
66
|
+
res.on('data', (chunk) => {
|
|
67
|
+
responseBody += chunk;
|
|
68
|
+
});
|
|
69
|
+
res.on('end', () => {
|
|
70
|
+
try {
|
|
71
|
+
resolve(JSON.parse(responseBody));
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
reject(new Error(`Invalid JSON response: ${responseBody.substring(0, 200)}`));
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
req.on('timeout', () => {
|
|
79
|
+
req.destroy();
|
|
80
|
+
reject(new Error('Request timed out'));
|
|
81
|
+
});
|
|
82
|
+
req.on('error', (err) => {
|
|
83
|
+
reject(err);
|
|
84
|
+
});
|
|
85
|
+
req.write(data);
|
|
86
|
+
req.end();
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=http.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/license/http.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AK,EAAE,GAAG,EAAE;gBACjB,IAAI,CAAC;oBACH,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC;gBACpC,CAAC;gBAAC,MAAM,CAAC;oBACP,MAAM,CAAC,IAAI,KAAK,CAAC,0BAA0B,YAAY,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;gBAChF,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,GAAG,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE;YACrB,GAAG,CAAC,OAAO,EAAE,CAAC;YACd,MAAM,CAAC,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC,CAAC;QACzC,CAAC,CAAC,CAAC;QAEH,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAU,EAAE,EAAE;YAC7B,MAAM,CAAC,GAAG,CAAC,CAAC;QACd,CAAC,CAAC,CAAC;QAEH,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAChB,GAAG,CAAC,GAAG,EAAE,CAAC;IACZ,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { validateLicense, isValidKeyFormat, isCacheValid, isInGracePeriod } from './validator.js';
|
|
2
|
+
export { canScan, recordScan, getCurrentMonthKey, getUsageForMonth } from './usage.js';
|
|
3
|
+
export { getFeatureGate } from './gate.js';
|
|
4
|
+
export { activateCommand, deactivateCommand, statusCommand } from './commands.js';
|
|
5
|
+
export type { TierStatus, FeatureGate, LicenseInfo, LicenseCache, UsageData } from './types.js';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/license/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAClG,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACvF,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAClF,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.statusCommand = exports.deactivateCommand = exports.activateCommand = exports.getFeatureGate = exports.getUsageForMonth = exports.getCurrentMonthKey = exports.recordScan = exports.canScan = exports.isInGracePeriod = exports.isCacheValid = exports.isValidKeyFormat = exports.validateLicense = void 0;
|
|
4
|
+
var validator_js_1 = require("./validator.js");
|
|
5
|
+
Object.defineProperty(exports, "validateLicense", { enumerable: true, get: function () { return validator_js_1.validateLicense; } });
|
|
6
|
+
Object.defineProperty(exports, "isValidKeyFormat", { enumerable: true, get: function () { return validator_js_1.isValidKeyFormat; } });
|
|
7
|
+
Object.defineProperty(exports, "isCacheValid", { enumerable: true, get: function () { return validator_js_1.isCacheValid; } });
|
|
8
|
+
Object.defineProperty(exports, "isInGracePeriod", { enumerable: true, get: function () { return validator_js_1.isInGracePeriod; } });
|
|
9
|
+
var usage_js_1 = require("./usage.js");
|
|
10
|
+
Object.defineProperty(exports, "canScan", { enumerable: true, get: function () { return usage_js_1.canScan; } });
|
|
11
|
+
Object.defineProperty(exports, "recordScan", { enumerable: true, get: function () { return usage_js_1.recordScan; } });
|
|
12
|
+
Object.defineProperty(exports, "getCurrentMonthKey", { enumerable: true, get: function () { return usage_js_1.getCurrentMonthKey; } });
|
|
13
|
+
Object.defineProperty(exports, "getUsageForMonth", { enumerable: true, get: function () { return usage_js_1.getUsageForMonth; } });
|
|
14
|
+
var gate_js_1 = require("./gate.js");
|
|
15
|
+
Object.defineProperty(exports, "getFeatureGate", { enumerable: true, get: function () { return gate_js_1.getFeatureGate; } });
|
|
16
|
+
var commands_js_1 = require("./commands.js");
|
|
17
|
+
Object.defineProperty(exports, "activateCommand", { enumerable: true, get: function () { return commands_js_1.activateCommand; } });
|
|
18
|
+
Object.defineProperty(exports, "deactivateCommand", { enumerable: true, get: function () { return commands_js_1.deactivateCommand; } });
|
|
19
|
+
Object.defineProperty(exports, "statusCommand", { enumerable: true, get: function () { return commands_js_1.statusCommand; } });
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/license/index.ts"],"names":[],"mappings":";;;AAAA,+CAAkG;AAAzF,+GAAA,eAAe,OAAA;AAAE,gHAAA,gBAAgB,OAAA;AAAE,4GAAA,YAAY,OAAA;AAAE,+GAAA,eAAe,OAAA;AACzE,uCAAuF;AAA9E,mGAAA,OAAO,OAAA;AAAE,sGAAA,UAAU,OAAA;AAAE,8GAAA,kBAAkB,OAAA;AAAE,4GAAA,gBAAgB,OAAA;AAClE,qCAA2C;AAAlC,yGAAA,cAAc,OAAA;AACvB,6CAAkF;AAAzE,8GAAA,eAAe,OAAA;AAAE,gHAAA,iBAAiB,OAAA;AAAE,4GAAA,aAAa,OAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { LicenseFile, UsageFile } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Get the config directory path.
|
|
4
|
+
* Uses PROJECT_SHIELD_CONFIG_DIR env var for testing, otherwise ~/.project-shield/
|
|
5
|
+
*/
|
|
6
|
+
export declare function getConfigDir(): string;
|
|
7
|
+
/**
|
|
8
|
+
* Ensure the config directory exists.
|
|
9
|
+
*/
|
|
10
|
+
export declare function ensureConfigDir(): void;
|
|
11
|
+
/**
|
|
12
|
+
* Read the license file. Returns null if not found or corrupted.
|
|
13
|
+
*/
|
|
14
|
+
export declare function readLicenseFile(): LicenseFile | null;
|
|
15
|
+
/**
|
|
16
|
+
* Write the license file.
|
|
17
|
+
*/
|
|
18
|
+
export declare function writeLicenseFile(data: LicenseFile): void;
|
|
19
|
+
/**
|
|
20
|
+
* Delete the license file.
|
|
21
|
+
*/
|
|
22
|
+
export declare function deleteLicenseFile(): void;
|
|
23
|
+
/**
|
|
24
|
+
* Read the usage file. Returns default if not found or corrupted.
|
|
25
|
+
*/
|
|
26
|
+
export declare function readUsageFile(): UsageFile;
|
|
27
|
+
/**
|
|
28
|
+
* Write the usage file.
|
|
29
|
+
*/
|
|
30
|
+
export declare function writeUsageFile(data: UsageFile): void;
|
|
31
|
+
//# sourceMappingURL=storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../src/license/storage.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAIzD;;;GAGG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAErC;AAED;;GAEG;AACH,wBAAgB,eAAe,IAAI,IAAI,CAKtC;AAED;;GAEG;AACH,wBAAgB,eAAe,IAAI,WAAW,GAAG,IAAI,CAcpD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI,CAIxD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,IAAI,CAKxC;AAcD;;GAEG;AACH,wBAAgB,aAAa,IAAI,SAAS,CAazC;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI,CAIpD"}
|
|
@@ -0,0 +1,138 @@
|
|
|
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 () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.getConfigDir = getConfigDir;
|
|
37
|
+
exports.ensureConfigDir = ensureConfigDir;
|
|
38
|
+
exports.readLicenseFile = readLicenseFile;
|
|
39
|
+
exports.writeLicenseFile = writeLicenseFile;
|
|
40
|
+
exports.deleteLicenseFile = deleteLicenseFile;
|
|
41
|
+
exports.readUsageFile = readUsageFile;
|
|
42
|
+
exports.writeUsageFile = writeUsageFile;
|
|
43
|
+
const fs = __importStar(require("node:fs"));
|
|
44
|
+
const path = __importStar(require("node:path"));
|
|
45
|
+
const os = __importStar(require("node:os"));
|
|
46
|
+
const DIR_NAME = '.project-shield';
|
|
47
|
+
/**
|
|
48
|
+
* Get the config directory path.
|
|
49
|
+
* Uses PROJECT_SHIELD_CONFIG_DIR env var for testing, otherwise ~/.project-shield/
|
|
50
|
+
*/
|
|
51
|
+
function getConfigDir() {
|
|
52
|
+
return process.env.PROJECT_SHIELD_CONFIG_DIR ?? path.join(os.homedir(), DIR_NAME);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Ensure the config directory exists.
|
|
56
|
+
*/
|
|
57
|
+
function ensureConfigDir() {
|
|
58
|
+
const dir = getConfigDir();
|
|
59
|
+
if (!fs.existsSync(dir)) {
|
|
60
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Read the license file. Returns null if not found or corrupted.
|
|
65
|
+
*/
|
|
66
|
+
function readLicenseFile() {
|
|
67
|
+
try {
|
|
68
|
+
const filePath = path.join(getConfigDir(), 'license.json');
|
|
69
|
+
if (!fs.existsSync(filePath))
|
|
70
|
+
return null;
|
|
71
|
+
const raw = fs.readFileSync(filePath, 'utf-8');
|
|
72
|
+
const data = JSON.parse(raw);
|
|
73
|
+
// Basic shape validation
|
|
74
|
+
if (!data.cache?.license?.key || !data.cache?.validatedAt || !data.cache?.validUntil) {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
return data;
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Write the license file.
|
|
85
|
+
*/
|
|
86
|
+
function writeLicenseFile(data) {
|
|
87
|
+
ensureConfigDir();
|
|
88
|
+
const filePath = path.join(getConfigDir(), 'license.json');
|
|
89
|
+
fs.writeFileSync(filePath, JSON.stringify(data, null, 2), 'utf-8');
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Delete the license file.
|
|
93
|
+
*/
|
|
94
|
+
function deleteLicenseFile() {
|
|
95
|
+
const filePath = path.join(getConfigDir(), 'license.json');
|
|
96
|
+
if (fs.existsSync(filePath)) {
|
|
97
|
+
fs.unlinkSync(filePath);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function defaultUsage() {
|
|
101
|
+
const now = new Date();
|
|
102
|
+
const monthKey = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}`;
|
|
103
|
+
return {
|
|
104
|
+
usage: {
|
|
105
|
+
monthKey,
|
|
106
|
+
scanCount: 0,
|
|
107
|
+
lastScanAt: '',
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Read the usage file. Returns default if not found or corrupted.
|
|
113
|
+
*/
|
|
114
|
+
function readUsageFile() {
|
|
115
|
+
try {
|
|
116
|
+
const filePath = path.join(getConfigDir(), 'usage.json');
|
|
117
|
+
if (!fs.existsSync(filePath))
|
|
118
|
+
return defaultUsage();
|
|
119
|
+
const raw = fs.readFileSync(filePath, 'utf-8');
|
|
120
|
+
const data = JSON.parse(raw);
|
|
121
|
+
if (!data.usage?.monthKey || typeof data.usage?.scanCount !== 'number') {
|
|
122
|
+
return defaultUsage();
|
|
123
|
+
}
|
|
124
|
+
return data;
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
return defaultUsage();
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Write the usage file.
|
|
132
|
+
*/
|
|
133
|
+
function writeUsageFile(data) {
|
|
134
|
+
ensureConfigDir();
|
|
135
|
+
const filePath = path.join(getConfigDir(), 'usage.json');
|
|
136
|
+
fs.writeFileSync(filePath, JSON.stringify(data, null, 2), 'utf-8');
|
|
137
|
+
}
|
|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C,CAAC;QACzD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC;YAAE,OAAO,YAAY,EAAE,CAAC;QACpD,MAAM,GAAG,GAAG,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QAC/C,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAc,CAAC;QAC1C,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,IAAI,OAAO,IAAI,CAAC,KAAK,EAAE,SAAS,KAAK,QAAQ,EAAE,CAAC;YACvE,OAAO,YAAY,EAAE,CAAC;QACxB,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,YAAY,EAAE,CAAC;IACxB,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAgB,cAAc,CAAC,IAAe;IAC5C,eAAe,EAAE,CAAC;IAClB,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE,YAAY,CAAC,CAAC;IACzD,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;AACrE,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export interface LicenseInfo {
|
|
2
|
+
key: string;
|
|
3
|
+
tier: 'free' | 'pro';
|
|
4
|
+
email: string;
|
|
5
|
+
activatedAt: string;
|
|
6
|
+
expiresAt: string;
|
|
7
|
+
maxScansPerMonth: number;
|
|
8
|
+
}
|
|
9
|
+
export interface LicenseCache {
|
|
10
|
+
license: LicenseInfo;
|
|
11
|
+
validatedAt: string;
|
|
12
|
+
validUntil: string;
|
|
13
|
+
}
|
|
14
|
+
export interface LicenseFile {
|
|
15
|
+
cache: LicenseCache;
|
|
16
|
+
}
|
|
17
|
+
export interface UsageData {
|
|
18
|
+
monthKey: string;
|
|
19
|
+
scanCount: number;
|
|
20
|
+
lastScanAt: string;
|
|
21
|
+
}
|
|
22
|
+
export interface UsageFile {
|
|
23
|
+
usage: UsageData;
|
|
24
|
+
}
|
|
25
|
+
export type TierStatus = {
|
|
26
|
+
tier: 'free' | 'pro';
|
|
27
|
+
isPro: boolean;
|
|
28
|
+
scansRemaining: number;
|
|
29
|
+
scansUsed: number;
|
|
30
|
+
maxScans: number;
|
|
31
|
+
source: 'license' | 'default';
|
|
32
|
+
};
|
|
33
|
+
export interface FeatureGate {
|
|
34
|
+
isPro: boolean;
|
|
35
|
+
canGenerateEvidence: boolean;
|
|
36
|
+
canSeePiiDetails: boolean;
|
|
37
|
+
canSeeCleanBadge: boolean;
|
|
38
|
+
canSeeFullFixit: boolean;
|
|
39
|
+
canGenerateSealUUID: boolean;
|
|
40
|
+
}
|
|
41
|
+
export interface ValidateResponse {
|
|
42
|
+
valid: boolean;
|
|
43
|
+
license?: LicenseInfo;
|
|
44
|
+
error?: string;
|
|
45
|
+
}
|
|
46
|
+
export interface ActivateResponse {
|
|
47
|
+
success: boolean;
|
|
48
|
+
license?: LicenseInfo;
|
|
49
|
+
error?: string;
|
|
50
|
+
}
|
|
51
|
+
export interface DeactivateResponse {
|
|
52
|
+
success: boolean;
|
|
53
|
+
error?: string;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/license/types.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,GAAG,KAAK,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,WAAW,CAAC;IACrB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appings":";AAAA,gEAAgE"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { UsageData, TierStatus } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Get current month key in "YYYY-MM" format.
|
|
4
|
+
*/
|
|
5
|
+
export declare function getCurrentMonthKey(): string;
|
|
6
|
+
/**
|
|
7
|
+
* Get usage data for a given month. Resets if month changed.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getUsageForMonth(monthKey?: string): UsageData;
|
|
10
|
+
/**
|
|
11
|
+
* Record a scan. Increments count for current month.
|
|
12
|
+
*/
|
|
13
|
+
export declare function recordScan(): void;
|
|
14
|
+
/**
|
|
15
|
+
* Check if a scan is allowed based on tier limits.
|
|
16
|
+
* free: 5/month, pro: 50/month
|
|
17
|
+
*/
|
|
18
|
+
export declare function canScan(tier: TierStatus): {
|
|
19
|
+
allowed: boolean;
|
|
20
|
+
reason?: string;
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=usage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage.d.ts","sourceRoot":"","sources":["../../src/license/usage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExD;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAG3C;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAc7D;AAED;;GAEG;AACH,wBAAgB,UAAU,IAAI,IAAI,CAWjC;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,UAAU,GAAG;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAY/E"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCurrentMonthKey = getCurrentMonthKey;
|
|
4
|
+
exports.getUsageForMonth = getUsageForMonth;
|
|
5
|
+
exports.recordScan = recordScan;
|
|
6
|
+
exports.canScan = canScan;
|
|
7
|
+
const storage_js_1 = require("./storage.js");
|
|
8
|
+
/**
|
|
9
|
+
* Get current month key in "YYYY-MM" format.
|
|
10
|
+
*/
|
|
11
|
+
function getCurrentMonthKey() {
|
|
12
|
+
const now = new Date();
|
|
13
|
+
return `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}`;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Get usage data for a given month. Resets if month changed.
|
|
17
|
+
*/
|
|
18
|
+
function getUsageForMonth(monthKey) {
|
|
19
|
+
const key = monthKey ?? getCurrentMonthKey();
|
|
20
|
+
const file = (0, storage_js_1.readUsageFile)();
|
|
21
|
+
// Month rollover → reset
|
|
22
|
+
if (file.usage.monthKey !== key) {
|
|
23
|
+
return {
|
|
24
|
+
monthKey: key,
|
|
25
|
+
scanCount: 0,
|
|
26
|
+
lastScanAt: '',
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
return file.usage;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Record a scan. Increments count for current month.
|
|
33
|
+
*/
|
|
34
|
+
function recordScan() {
|
|
35
|
+
const monthKey = getCurrentMonthKey();
|
|
36
|
+
const current = getUsageForMonth(monthKey);
|
|
37
|
+
(0, storage_js_1.writeUsageFile)({
|
|
38
|
+
usage: {
|
|
39
|
+
monthKey,
|
|
40
|
+
scanCount: current.scanCount + 1,
|
|
41
|
+
lastScanAt: new Date().toISOString(),
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Check if a scan is allowed based on tier limits.
|
|
47
|
+
* free: 5/month, pro: 50/month
|
|
48
|
+
*/
|
|
49
|
+
function canScan(tier) {
|
|
50
|
+
if (tier.scansRemaining <= 0) {
|
|
51
|
+
return {
|
|
52
|
+
allowed: false,
|
|
53
|
+
reason: `Monthly scan limit reached (${tier.maxScans}/${tier.maxScans}). ${tier.isPro
|
|
54
|
+
? 'Your Pro plan allows 50 scans/month. Resets next month.'
|
|
55
|
+
: 'Upgrade to Pro for 50 scans/month: https://project-shield.dev/pro'}`,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
return { allowed: true };
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=usage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage.js","sourceRoot":"","sources":["../../src/license/usage.ts"],"names":[],"mappings":";;AAMA,gDAGC;AAKD,4CAcC;AAKD,gCAWC;AAMD,0BAYC;AA9DD,6CAA6D;AAG7D;;GAEG;AACH,SAAgB,kBAAkB;IAChC,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;IACvB,OAAO,GAAG,GAAG,CAAC,WAAW,EAAE,IAAI,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;AAC/E,CAAC;AAED;;GAEG;AACH,SAAgB,gBAAgB,CAAC,QAAiB;IAChD,MAAM,GAAG,GAAG,QAAQ,IAAI,kBAAkB,EAAE,CAAC;IAC7C,MAAM,IAAI,GAAG,IAAA,0BAAa,GAAE,CAAC;IAE7B,yBAAyB;IACzB,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,KAAK,GAAG,EAAE,CAAC;QAChC,OAAO;YACL,QAAQ,EAAE,GAAG;YACb,SAAS,EAAE,CAAC;YACZ,UAAU,EAAE,EAAE;SACf,CAAC;IACJ,CAAC;IAED,OAAO,IAAI,CAAC,KAAK,CAAC;AACpB,CAAC;AAED;;GAEG;AACH,SAAgB,UAAU;IACxB,MAAM,QAAQ,GAAG,kBAAkB,EAAE,CAAC;IACtC,MAAM,OAAO,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IAE3C,IAAA,2BAAc,EAAC;QACb,KAAK,EAAE;YACL,QAAQ;YACR,SAAS,EAAE,OAAO,CAAC,SAAS,GAAG,CAAC;YAChC,UAAU,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;SACrC;KACF,CAAC,CAAC;AACL,CAAC;AAED;;;GAGG;AACH,SAAgB,OAAO,CAAC,IAAgB;IACtC,IAAI,IAAI,CAAC,cAAc,IAAI,CAAC,EAAE,CAAC;QAC7B,OAAO;YACL,OAAO,EAAE,KAAK;YACd,MAAM,EAAE,+BAA+B,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,MACnE,IAAI,CAAC,KAAK;gBACR,CAAC,CAAC,yDAAyD;gBAC3D,CAAC,CAAC,mEACN,EAAE;SACH,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { LicenseCache, TierStatus, ValidateResponse } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Validate key format: PSH-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{4}
|
|
4
|
+
*/
|
|
5
|
+
export declare function isValidKeyFormat(key: string): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Validate license with server.
|
|
8
|
+
*/
|
|
9
|
+
export declare function validateWithServer(key: string): Promise<ValidateResponse>;
|
|
10
|
+
/**
|
|
11
|
+
* Check if cache is within the 7-day validity window.
|
|
12
|
+
*/
|
|
13
|
+
export declare function isCacheValid(cache: LicenseCache): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Check if still within the grace period (3 extra days after cache expires).
|
|
16
|
+
*/
|
|
17
|
+
export declare function isInGracePeriod(cache: LicenseCache): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Main license validation flow:
|
|
20
|
+
* 1. No license.json → free (default)
|
|
21
|
+
* 2. Cache valid (7 days) → return cached tier
|
|
22
|
+
* 3. Cache expired → try server re-validation
|
|
23
|
+
* 4. Server success → update cache, return tier
|
|
24
|
+
* 5. Server fail + grace period → cached tier + warning
|
|
25
|
+
* 6. Grace expired → downgrade to free
|
|
26
|
+
*/
|
|
27
|
+
export declare function validateLicense(): Promise<TierStatus>;
|
|
28
|
+
//# sourceMappingURL=validator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/license/validator.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAO7E;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAErD;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAG/E;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAIzD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAK5D;AAkBD;;;;;;;;GAQG;AACH,wBAAsB,eAAe,IAAI,OAAO,CAAC,UAAU,CAAC,CA6C3D"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isValidKeyFormat = isValidKeyFormat;
|
|
4
|
+
exports.validateWithServer = validateWithServer;
|
|
5
|
+
exports.isCacheValid = isCacheValid;
|
|
6
|
+
exports.isInGracePeriod = isInGracePeriod;
|
|
7
|
+
exports.validateLicense = validateLicense;
|
|
8
|
+
const storage_js_1 = require("./storage.js");
|
|
9
|
+
const usage_js_1 = require("./usage.js");
|
|
10
|
+
const http_js_1 = require("./http.js");
|
|
11
|
+
const API_BASE = 'https://project-shield-license-api.vnddns999.workers.dev/api/v1';
|
|
12
|
+
const KEY_PATTERN = /^PSH-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{4}$/;
|
|
13
|
+
const CACHE_DAYS = 7;
|
|
14
|
+
const GRACE_DAYS = 3;
|
|
15
|
+
/**
|
|
16
|
+
* Validate key format: PSH-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{4}
|
|
17
|
+
*/
|
|
18
|
+
function isValidKeyFormat(key) {
|
|
19
|
+
return KEY_PATTERN.test(key);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Validate license with server.
|
|
23
|
+
*/
|
|
24
|
+
async function validateWithServer(key) {
|
|
25
|
+
const response = await (0, http_js_1.postJSON)(`${API_BASE}/validate`, { key });
|
|
26
|
+
return response;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Check if cache is within the 7-day validity window.
|
|
30
|
+
*/
|
|
31
|
+
function isCacheValid(cache) {
|
|
32
|
+
const now = Date.now();
|
|
33
|
+
const validUntil = new Date(cache.validUntil).getTime();
|
|
34
|
+
return now < validUntil;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Check if still within the grace period (3 extra days after cache expires).
|
|
38
|
+
*/
|
|
39
|
+
function isInGracePeriod(cache) {
|
|
40
|
+
const now = Date.now();
|
|
41
|
+
const validUntil = new Date(cache.validUntil).getTime();
|
|
42
|
+
const graceEnd = validUntil + GRACE_DAYS * 24 * 60 * 60 * 1000;
|
|
43
|
+
return now >= validUntil && now < graceEnd;
|
|
44
|
+
}
|
|
45
|
+
function makeTierStatus(tier, maxScans, source) {
|
|
46
|
+
const usage = (0, usage_js_1.getUsageForMonth)((0, usage_js_1.getCurrentMonthKey)());
|
|
47
|
+
return {
|
|
48
|
+
tier,
|
|
49
|
+
isPro: tier === 'pro',
|
|
50
|
+
scansRemaining: Math.max(0, maxScans - usage.scanCount),
|
|
51
|
+
scansUsed: usage.scanCount,
|
|
52
|
+
maxScans,
|
|
53
|
+
source,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Main license validation flow:
|
|
58
|
+
* 1. No license.json → free (default)
|
|
59
|
+
* 2. Cache valid (7 days) → return cached tier
|
|
60
|
+
* 3. Cache expired → try server re-validation
|
|
61
|
+
* 4. Server success → update cache, return tier
|
|
62
|
+
* 5. Server fail + grace period → cached tier + warning
|
|
63
|
+
* 6. Grace expired → downgrade to free
|
|
64
|
+
*/
|
|
65
|
+
async function validateLicense() {
|
|
66
|
+
const file = (0, storage_js_1.readLicenseFile)();
|
|
67
|
+
// 1. No license file → free
|
|
68
|
+
if (!file) {
|
|
69
|
+
return makeTierStatus('free', 5, 'default');
|
|
70
|
+
}
|
|
71
|
+
const cache = file.cache;
|
|
72
|
+
// 2. Cache valid
|
|
73
|
+
if (isCacheValid(cache)) {
|
|
74
|
+
const max = cache.license.tier === 'pro' ? 50 : 5;
|
|
75
|
+
return makeTierStatus(cache.license.tier, max, 'license');
|
|
76
|
+
}
|
|
77
|
+
// 3. Cache expired → try server
|
|
78
|
+
try {
|
|
79
|
+
const response = await validateWithServer(cache.license.key);
|
|
80
|
+
if (response.valid && response.license) {
|
|
81
|
+
// 4. Server success → update cache
|
|
82
|
+
const now = new Date();
|
|
83
|
+
const validUntil = new Date(now.getTime() + CACHE_DAYS * 24 * 60 * 60 * 1000);
|
|
84
|
+
(0, storage_js_1.writeLicenseFile)({
|
|
85
|
+
cache: {
|
|
86
|
+
license: response.license,
|
|
87
|
+
validatedAt: now.toISOString(),
|
|
88
|
+
validUntil: validUntil.toISOString(),
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
const max = response.license.tier === 'pro' ? 50 : 5;
|
|
92
|
+
return makeTierStatus(response.license.tier, max, 'license');
|
|
93
|
+
}
|
|
94
|
+
// Server says invalid → downgrade
|
|
95
|
+
return makeTierStatus('free', 5, 'default');
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
// 5. Server unreachable
|
|
99
|
+
if (isInGracePeriod(cache)) {
|
|
100
|
+
// Grace period → use cached tier with warning
|
|
101
|
+
const max = cache.license.tier === 'pro' ? 50 : 5;
|
|
102
|
+
return makeTierStatus(cache.license.tier, max, 'license');
|
|
103
|
+
}
|
|
104
|
+
// 6. Grace expired → downgrade
|
|
105
|
+
return makeTierStatus('free', 5, 'default');
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.js","sourceRoot":"","sources":["../../src/license/validator.ts"],"names":[],"mappings":";;AAaA,4CAEC;AAKD,gDAGC;AAKD,oCAIC;AAKD,0CAKC;AA2BD,0CA6CC;AAlHD,6CAAiE;AACjE,yCAAkE;AAClE,uCAAqC;AAGrC,MAAM,QAAQ,GAAG,iEAAiE,CAAC;AACnF,MAAM,WAAW,GAAG,uDAAuD,CAAC;AAC5E,MAAM,UAAU,GAAG,CAAC,CAAC;AACrB,MAAM,UAAU,GAAG,CAAC,CAAC;AAErB;;GAEG;AACH,SAAgB,gBAAgB,CAAC,GAAW;IAC1C,OAAO,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC/B,CAAC;AAED;;GAEG;AACI,KAAK,UAAU,kBAAkB,CAAC,GAAW;IAClD,MAAM,QAAQ,GAAG,MAAM,IAAA,kBAAQ,EAAC,GAAG,QAAQ,WAAW,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;IACjE,OAAO,QAA4B,CAAC;AACtC,CAAC;AAED;;GAEG;AACH,SAAgB,YAAY,CAAC,KAAmB;IAC9C,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACvB,MAAM,UAAU,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,OAAO,EAAE,CAAC;IACxD,OAAO,GAAG,GAAG,UAAU,CAAC;AAC1B,CAAC;AAED;;GAEG;AACH,SAAg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AC,CAAC;QAC5D,CAAC;QACD,+BAA+B;QAC/B,OAAO,cAAc,CAAC,MAAM,EAAE,CAAC,EAAE,SAAS,CAAC,CAAC;IAC9C,CAAC;AACH,CAAC"}
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import type { ScanResult, ScanScore, LockStatus, SealedResult } from '../types/index.js';
|
|
2
2
|
/**
|
|
3
3
|
* Format scan results for terminal output.
|
|
4
|
+
* @param options.isPro - If false, PII section shows summary only (no file:line details).
|
|
4
5
|
*/
|
|
5
|
-
export declare function formatTerminalOutput(result: ScanResult, rulesetVersion: string, rulesetHash: string, score?: ScanScore, lockStatus?: LockStatus
|
|
6
|
+
export declare function formatTerminalOutput(result: ScanResult, rulesetVersion: string, rulesetHash: string, score?: ScanScore, lockStatus?: LockStatus, options?: {
|
|
7
|
+
isPro?: boolean;
|
|
8
|
+
}): string;
|
|
6
9
|
/**
|
|
7
10
|
* Format scan results as JSON.
|
|
11
|
+
* @param options.isPro - If false, PII array is replaced with a summary object.
|
|
8
12
|
*/
|
|
9
|
-
export declare function formatJsonOutput(result: ScanResult, score?: ScanScore, seal?: SealedResult
|
|
13
|
+
export declare function formatJsonOutput(result: ScanResult, score?: ScanScore, seal?: SealedResult, options?: {
|
|
14
|
+
isPro?: boolean;
|
|
15
|
+
}): string;
|
|
10
16
|
//# sourceMappingURL=terminal.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"terminal.d.ts","sourceRoot":"","sources":["../../src/output/terminal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EAKV,SAAS,EACT,UAAU,EACV,YAAY,EACb,MAAM,mBAAmB,CAAC;AAiG3B
|
|
1
|
+
{"version":3,"file":"terminal.d.ts","sourceRoot":"","sources":["../../src/output/terminal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EAKV,SAAS,EACT,UAAU,EACV,YAAY,EACb,MAAM,mBAAmB,CAAC;AAiG3B;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,UAAU,EAClB,cAAc,EAAE,MAAM,EACtB,WAAW,EAAE,MAAM,EACnB,KAAK,CAAC,EAAE,SAAS,EACjB,UAAU,CAAC,EAAE,UAAU,EACvB,OAAO,CAAC,EAAE;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,GAC5B,MAAM,CAqGR;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,UAAU,EAClB,KAAK,CAAC,EAAE,SAAS,EACjB,IAAI,CAAC,EAAE,YAAY,EACnB,OAAO,CAAC,EAAE;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,GAC5B,MAAM,CAmBR"}
|