@tiangong-lca/cli 0.1.6 → 0.1.7
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 +3 -13
- package/dist/src/cli.js +20 -36
- package/dist/src/cli.js.map +1 -1
- package/dist/src/lib/auth-identity-receipt.d.ts +1 -2
- package/dist/src/lib/auth-identity-receipt.js +3 -20
- package/dist/src/lib/auth-identity-receipt.js.map +1 -1
- package/dist/src/lib/credential-safety.d.ts +7 -0
- package/dist/src/lib/credential-safety.js +28 -0
- package/dist/src/lib/credential-safety.js.map +1 -0
- package/dist/src/lib/dataset-save-draft-run.js +3 -1
- package/dist/src/lib/dataset-save-draft-run.js.map +1 -1
- package/dist/src/lib/env.d.ts +0 -2
- package/dist/src/lib/env.js +11 -19
- package/dist/src/lib/env.js.map +1 -1
- package/dist/src/lib/flow-publish-reviewed-data.js +1 -1
- package/dist/src/lib/flow-publish-reviewed-data.js.map +1 -1
- package/dist/src/lib/lifecyclemodel-resulting-process.js +2 -6
- package/dist/src/lib/lifecyclemodel-resulting-process.js.map +1 -1
- package/dist/src/lib/process-refresh-references.js +1 -1
- package/dist/src/lib/process-refresh-references.js.map +1 -1
- package/dist/src/lib/process-scope-statistics.js +1 -1
- package/dist/src/lib/process-scope-statistics.js.map +1 -1
- package/dist/src/lib/supabase-client.d.ts +1 -3
- package/dist/src/lib/supabase-client.js +5 -15
- package/dist/src/lib/supabase-client.js.map +1 -1
- package/dist/src/lib/supabase-session.d.ts +5 -14
- package/dist/src/lib/supabase-session.js +34 -113
- package/dist/src/lib/supabase-session.js.map +1 -1
- package/package.json +1 -2
- package/dist/src/lib/user-api-key.d.ts +0 -16
- package/dist/src/lib/user-api-key.js +0 -75
- package/dist/src/lib/user-api-key.js.map +0 -1
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { createHash } from 'node:crypto';
|
|
2
|
-
import { CliError } from './errors.js';
|
|
3
|
-
function normalizeToken(value) {
|
|
4
|
-
return typeof value === 'string' ? value.trim() : '';
|
|
5
|
-
}
|
|
6
|
-
function normalizeCredentialValue(value) {
|
|
7
|
-
return typeof value === 'string' ? value.trim() : '';
|
|
8
|
-
}
|
|
9
|
-
function isRecord(value) {
|
|
10
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
11
|
-
}
|
|
12
|
-
export function decodeUserApiKey(apiKey) {
|
|
13
|
-
const normalizedApiKey = normalizeToken(apiKey);
|
|
14
|
-
if (!normalizedApiKey) {
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
try {
|
|
18
|
-
const jsonText = Buffer.from(normalizedApiKey, 'base64').toString('utf8');
|
|
19
|
-
const parsed = JSON.parse(jsonText);
|
|
20
|
-
if (!isRecord(parsed)) {
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
const email = normalizeCredentialValue(parsed.email);
|
|
24
|
-
const password = normalizeCredentialValue(parsed.password);
|
|
25
|
-
if (!email || !password) {
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
return {
|
|
29
|
-
email,
|
|
30
|
-
password,
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
catch {
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
export function requireUserApiKeyCredentials(apiKey) {
|
|
38
|
-
const credentials = decodeUserApiKey(apiKey);
|
|
39
|
-
if (!credentials) {
|
|
40
|
-
throw new CliError('TIANGONG_LCA_API_KEY is invalid. Generate a new user API key from the TianGong user API key page.', {
|
|
41
|
-
code: 'USER_API_KEY_INVALID',
|
|
42
|
-
exitCode: 2,
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
return credentials;
|
|
46
|
-
}
|
|
47
|
-
export function fingerprintSecret(value) {
|
|
48
|
-
const normalized = normalizeToken(value);
|
|
49
|
-
if (!normalized) {
|
|
50
|
-
throw new CliError('Cannot fingerprint an empty secret value.', {
|
|
51
|
-
code: 'SECRET_FINGERPRINT_VALUE_REQUIRED',
|
|
52
|
-
exitCode: 2,
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
return `sha256:${createHash('sha256').update(normalized).digest('hex')}`;
|
|
56
|
-
}
|
|
57
|
-
export function fingerprintUserApiKey(apiKey) {
|
|
58
|
-
return fingerprintSecret(apiKey);
|
|
59
|
-
}
|
|
60
|
-
export function redactEmail(email) {
|
|
61
|
-
const normalized = normalizeCredentialValue(email);
|
|
62
|
-
const [localPart, domainPart] = normalized.split('@');
|
|
63
|
-
if (!localPart || !domainPart) {
|
|
64
|
-
return '****';
|
|
65
|
-
}
|
|
66
|
-
if (localPart.length <= 2) {
|
|
67
|
-
return `****@${domainPart}`;
|
|
68
|
-
}
|
|
69
|
-
return `${localPart.slice(0, 2)}****@${domainPart}`;
|
|
70
|
-
}
|
|
71
|
-
export const __testInternals = {
|
|
72
|
-
normalizeCredentialValue,
|
|
73
|
-
normalizeToken,
|
|
74
|
-
};
|
|
75
|
-
//# sourceMappingURL=user-api-key.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"user-api-key.js","sourceRoot":"","sources":["../../../src/lib/user-api-key.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAOvC,SAAS,cAAc,CAAC,KAAc;IACpC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;AACvD,CAAC;AAED,SAAS,wBAAwB,CAAC,KAAc;IAC9C,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;AACvD,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI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AC,KAAK,CAAC,CAAC;IACzC,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,QAAQ,CAAC,2CAA2C,EAAE;YAC9D,IAAI,EAAE,mCAAmC;YACzC,QAAQ,EAAE,CAAC;SACZ,CAAC,CAAC;IACL,CAAC;IAED,OAAO,UAAU,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;AAC3E,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,MAAc;IAClD,OAAO,iBAAiB,CAAC,MAAM,CAAC,CAAC;AACnC,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAAa;IACvC,MAAM,UAAU,GAAG,wBAAwB,CAAC,KAAK,CAAC,CAAC;IACnD,MAAM,CAAC,SAAS,EAAE,UAAU,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACtD,IAAI,CAAC,SAAS,IAAI,CAAC,UAAU,EAAE,CAAC;QAC9B,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,IAAI,SAAS,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;QAC1B,OAAO,QAAQ,UAAU,EAAE,CAAC;IAC9B,CAAC;IAED,OAAO,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,QAAQ,UAAU,EAAE,CAAC;AACtD,CAAC;AAED,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,wBAAwB;IACxB,cAAc;CACf,CAAC","sourcesContent":["import { createHash } from 'node:crypto';\nimport { CliError } from './errors.js';\n\nexport type UserApiKeyCredentials = {\n email: string;\n password: string;\n};\n\nfunction normalizeToken(value: unknown): string {\n return typeof value === 'string' ? value.trim() : '';\n}\n\nfunction normalizeCredentialValue(value: unknown): string {\n return typeof value === 'string' ? value.trim() : '';\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nexport function decodeUserApiKey(apiKey: string): UserApiKeyCredentials | null {\n const normalizedApiKey = normalizeToken(apiKey);\n if (!normalizedApiKey) {\n return null;\n }\n\n try {\n const jsonText = Buffer.from(normalizedApiKey, 'base64').toString('utf8');\n const parsed = JSON.parse(jsonText);\n if (!isRecord(parsed)) {\n return null;\n }\n\n const email = normalizeCredentialValue(parsed.email);\n const password = normalizeCredentialValue(parsed.password);\n if (!email || !password) {\n return null;\n }\n\n return {\n email,\n password,\n };\n } catch {\n return null;\n }\n}\n\nexport function requireUserApiKeyCredentials(apiKey: string): UserApiKeyCredentials {\n const credentials = decodeUserApiKey(apiKey);\n if (!credentials) {\n throw new CliError(\n 'TIANGONG_LCA_API_KEY is invalid. Generate a new user API key from the TianGong user API key page.',\n {\n code: 'USER_API_KEY_INVALID',\n exitCode: 2,\n },\n );\n }\n\n return credentials;\n}\n\nexport function fingerprintSecret(value: string): string {\n const normalized = normalizeToken(value);\n if (!normalized) {\n throw new CliError('Cannot fingerprint an empty secret value.', {\n code: 'SECRET_FINGERPRINT_VALUE_REQUIRED',\n exitCode: 2,\n });\n }\n\n return `sha256:${createHash('sha256').update(normalized).digest('hex')}`;\n}\n\nexport function fingerprintUserApiKey(apiKey: string): string {\n return fingerprintSecret(apiKey);\n}\n\nexport function redactEmail(email: string): string {\n const normalized = normalizeCredentialValue(email);\n const [localPart, domainPart] = normalized.split('@');\n if (!localPart || !domainPart) {\n return '****';\n }\n\n if (localPart.length <= 2) {\n return `****@${domainPart}`;\n }\n\n return `${localPart.slice(0, 2)}****@${domainPart}`;\n}\n\nexport const __testInternals = {\n normalizeCredentialValue,\n normalizeToken,\n};\n"]}
|