@salesforce/b2c-cli 2.0.0 → 2.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.
- package/dist/commands/ecdn/mtls/create.d.ts +21 -5
- package/dist/commands/ecdn/mtls/create.js +104 -33
- package/dist/commands/ecdn/mtls/create.js.map +1 -1
- package/dist/commands/ecdn/mtls/issue.d.ts +46 -0
- package/dist/commands/ecdn/mtls/issue.js +95 -0
- package/dist/commands/ecdn/mtls/issue.js.map +1 -0
- package/dist/commands/ecdn/mtls/setup.d.ts +55 -0
- package/dist/commands/ecdn/mtls/setup.js +166 -0
- package/dist/commands/ecdn/mtls/setup.js.map +1 -0
- package/dist/commands/job/export.d.ts +1 -0
- package/dist/commands/job/export.js +17 -4
- package/dist/commands/job/export.js.map +1 -1
- package/dist/commands/job/import.d.ts +22 -2
- package/dist/commands/job/import.js +116 -11
- package/dist/commands/job/import.js.map +1 -1
- package/dist/commands/mrt/bundle/delete.js +8 -12
- package/dist/commands/mrt/bundle/delete.js.map +1 -1
- package/dist/commands/mrt/bundle/deploy.d.ts +33 -9
- package/dist/commands/mrt/bundle/deploy.js +141 -94
- package/dist/commands/mrt/bundle/deploy.js.map +1 -1
- package/dist/commands/mrt/bundle/download.js +7 -11
- package/dist/commands/mrt/bundle/download.js.map +1 -1
- package/dist/commands/mrt/bundle/history.js +4 -6
- package/dist/commands/mrt/bundle/history.js.map +1 -1
- package/dist/commands/mrt/bundle/list.d.ts +6 -2
- package/dist/commands/mrt/bundle/list.js +28 -7
- package/dist/commands/mrt/bundle/list.js.map +1 -1
- package/dist/commands/mrt/bundle/save.js +1 -3
- package/dist/commands/mrt/bundle/save.js.map +1 -1
- package/dist/commands/mrt/bundle/upload-v2.d.ts +4 -0
- package/dist/commands/mrt/bundle/upload-v2.js +16 -13
- package/dist/commands/mrt/bundle/upload-v2.js.map +1 -1
- package/dist/commands/mrt/env/clone.js +4 -6
- package/dist/commands/mrt/env/clone.js.map +1 -1
- package/dist/commands/mrt/env/create.js +4 -6
- package/dist/commands/mrt/env/create.js.map +1 -1
- package/dist/commands/mrt/env/delete.js +5 -9
- package/dist/commands/mrt/env/delete.js.map +1 -1
- package/dist/commands/mrt/env/invalidate.js +2 -4
- package/dist/commands/mrt/env/invalidate.js.map +1 -1
- package/dist/commands/mrt/env/redirect/clone.js +5 -7
- package/dist/commands/mrt/env/redirect/clone.js.map +1 -1
- package/dist/commands/mrt/env/redirect/create.js +5 -7
- package/dist/commands/mrt/env/redirect/create.js.map +1 -1
- package/dist/commands/mrt/env/redirect/delete.js +1 -3
- package/dist/commands/mrt/env/redirect/delete.js.map +1 -1
- package/dist/commands/mrt/env/var/delete.d.ts +3 -2
- package/dist/commands/mrt/env/var/delete.js +27 -10
- package/dist/commands/mrt/env/var/delete.js.map +1 -1
- package/dist/commands/mrt/env/var/list.d.ts +5 -4
- package/dist/commands/mrt/env/var/list.js +30 -11
- package/dist/commands/mrt/env/var/list.js.map +1 -1
- package/dist/commands/mrt/env/var/push.d.ts +5 -4
- package/dist/commands/mrt/env/var/push.js +77 -31
- package/dist/commands/mrt/env/var/push.js.map +1 -1
- package/dist/commands/mrt/env/var/set.d.ts +3 -2
- package/dist/commands/mrt/env/var/set.js +35 -18
- package/dist/commands/mrt/env/var/set.js.map +1 -1
- package/dist/commands/mrt/org/cert/create.js +6 -8
- package/dist/commands/mrt/org/cert/create.js.map +1 -1
- package/dist/commands/mrt/org/cert/delete.js +1 -3
- package/dist/commands/mrt/org/cert/delete.js.map +1 -1
- package/dist/commands/mrt/org/cert/restart-validation.js +6 -8
- package/dist/commands/mrt/org/cert/restart-validation.js.map +1 -1
- package/dist/commands/mrt/org/member/add.js +5 -7
- package/dist/commands/mrt/org/member/add.js.map +1 -1
- package/dist/commands/mrt/org/member/remove.js +1 -3
- package/dist/commands/mrt/org/member/remove.js.map +1 -1
- package/dist/commands/mrt/org/member/update.js +1 -3
- package/dist/commands/mrt/org/member/update.js.map +1 -1
- package/dist/commands/mrt/project/delete.js +1 -3
- package/dist/commands/mrt/project/delete.js.map +1 -1
- package/dist/commands/mrt/project/member/add.js +4 -6
- package/dist/commands/mrt/project/member/add.js.map +1 -1
- package/dist/commands/mrt/project/member/remove.js +1 -3
- package/dist/commands/mrt/project/member/remove.js.map +1 -1
- package/dist/commands/mrt/project/member/update.js +4 -6
- package/dist/commands/mrt/project/member/update.js.map +1 -1
- package/dist/commands/mrt/project/notification/create.js +9 -11
- package/dist/commands/mrt/project/notification/create.js.map +1 -1
- package/dist/commands/mrt/project/notification/delete.js +1 -3
- package/dist/commands/mrt/project/notification/delete.js.map +1 -1
- package/dist/commands/mrt/project/notification/update.js +1 -3
- package/dist/commands/mrt/project/notification/update.js.map +1 -1
- package/dist/commands/mrt/tail-logs.js +15 -21
- package/dist/commands/mrt/tail-logs.js.map +1 -1
- package/dist/commands/mrt/user/api-key.js +3 -5
- package/dist/commands/mrt/user/api-key.js.map +1 -1
- package/dist/commands/setup/inspect.d.ts +7 -0
- package/dist/commands/setup/inspect.js +122 -5
- package/dist/commands/setup/inspect.js.map +1 -1
- package/dist/script-types/node_modules/@salesforce/b2c-script-types/package.json +15 -2
- package/dist/script-types/node_modules/@salesforce/b2c-script-types/plugin/index.js +24 -7
- package/dist/utils/ecdn/mtls.d.ts +80 -0
- package/dist/utils/ecdn/mtls.js +161 -0
- package/dist/utils/ecdn/mtls.js.map +1 -0
- package/oclif.manifest.json +11800 -11205
- package/package.json +2 -2
|
@@ -37,8 +37,9 @@ const SFRA_AMBIENT_MODULES = new Set([
|
|
|
37
37
|
]);
|
|
38
38
|
// Candidate suffixes appended when resolving a SFCC-style relative require to
|
|
39
39
|
// a cartridge file. SFRA convention is to omit the .js extension, so .js wins
|
|
40
|
-
// first; .json captures the occasional resource bundle import.
|
|
41
|
-
|
|
40
|
+
// first; .json captures the occasional resource bundle import; .ds covers
|
|
41
|
+
// legacy pipeline-era scripts, which the platform also resolves after .js.
|
|
42
|
+
const CANDIDATE_EXTENSIONS = ['.js', '.json', '.ds', '/index.js', '/index.ds'];
|
|
42
43
|
// Cartridges that conventionally sit at the bottom of the cartridge path when
|
|
43
44
|
// the user hasn't told us otherwise (no `cartridges` in dw.json/SFCC_CARTRIDGES).
|
|
44
45
|
// Higher rank = lower in the cartridge path. SFRA's runtime path ends with
|
|
@@ -77,7 +78,12 @@ function init({ typescript: ts }) {
|
|
|
77
78
|
const setCartridges = (list) => {
|
|
78
79
|
cartridges = list.map(({ name, src }) => {
|
|
79
80
|
const n = normalize(src);
|
|
80
|
-
|
|
81
|
+
const raw = src.replace(/\\/g, '/');
|
|
82
|
+
return {
|
|
83
|
+
name,
|
|
84
|
+
root: n.endsWith('/') ? n : n + '/',
|
|
85
|
+
srcRoot: raw.endsWith('/') ? raw : raw + '/',
|
|
86
|
+
};
|
|
81
87
|
});
|
|
82
88
|
};
|
|
83
89
|
const applyConfig = (config) => {
|
|
@@ -275,7 +281,7 @@ function init({ typescript: ts }) {
|
|
|
275
281
|
if (!subpath)
|
|
276
282
|
return undefined;
|
|
277
283
|
for (const c of order) {
|
|
278
|
-
const baseAbs = c.
|
|
284
|
+
const baseAbs = c.srcRoot + subpath;
|
|
279
285
|
for (const ext of CANDIDATE_EXTENSIONS) {
|
|
280
286
|
const candidate = baseAbs + ext;
|
|
281
287
|
if (fileExists(candidate)) {
|
|
@@ -307,7 +313,7 @@ function init({ typescript: ts }) {
|
|
|
307
313
|
const modulesCart = cartridges.find((c) => c.name === 'modules');
|
|
308
314
|
if (!modulesCart)
|
|
309
315
|
return undefined;
|
|
310
|
-
const baseAbs = modulesCart.
|
|
316
|
+
const baseAbs = modulesCart.srcRoot + moduleName;
|
|
311
317
|
for (const ext of CANDIDATE_EXTENSIONS) {
|
|
312
318
|
const candidate = baseAbs + ext;
|
|
313
319
|
if (fileExists(candidate)) {
|
|
@@ -322,7 +328,7 @@ function init({ typescript: ts }) {
|
|
|
322
328
|
if (content) {
|
|
323
329
|
const main = JSON.parse(content).main;
|
|
324
330
|
if (typeof main === 'string' && main.length > 0) {
|
|
325
|
-
const resolved = (modulesCart.
|
|
331
|
+
const resolved = (modulesCart.srcRoot + moduleName + '/' + main.replace(/^\.\//, '')).replace(/\\/g, '/');
|
|
326
332
|
if (fileExists(resolved)) {
|
|
327
333
|
return { resolved, source: modulesCart.name };
|
|
328
334
|
}
|
|
@@ -430,6 +436,17 @@ function init({ typescript: ts }) {
|
|
|
430
436
|
}
|
|
431
437
|
return additions.length > 0 ? [...list, ...additions] : list;
|
|
432
438
|
};
|
|
439
|
+
// TS derives a file's ScriptKind from its extension and falls back to TS
|
|
440
|
+
// for anything it doesn't recognize, which would parse legacy .ds scripts
|
|
441
|
+
// as TypeScript. Report JS so they get the same JavaScript semantics
|
|
442
|
+
// (allowJs/checkJs, JSDoc types) as their .js siblings. Returning Unknown
|
|
443
|
+
// for everything else lets TS fall back to its own extension mapping.
|
|
444
|
+
const origGetScriptKind = host.getScriptKind?.bind(host);
|
|
445
|
+
host.getScriptKind = (fileName) => {
|
|
446
|
+
if (enabled && fileName.endsWith('.ds'))
|
|
447
|
+
return ts.ScriptKind.JS;
|
|
448
|
+
return origGetScriptKind ? origGetScriptKind(fileName) : ts.ScriptKind.Unknown;
|
|
449
|
+
};
|
|
433
450
|
const origResolveModuleNameLiterals = host.resolveModuleNameLiterals?.bind(host);
|
|
434
451
|
if (origResolveModuleNameLiterals) {
|
|
435
452
|
host.resolveModuleNameLiterals = (moduleLiterals, containingFile, redirectedReference, options, containingSourceFile, reusedNames) => {
|
|
@@ -538,7 +555,7 @@ function init({ typescript: ts }) {
|
|
|
538
555
|
const moduleName = sfraModuleAtOffset(def.textSpan.start);
|
|
539
556
|
if (!moduleName)
|
|
540
557
|
return def;
|
|
541
|
-
const candidates = [modulesCart.
|
|
558
|
+
const candidates = [modulesCart.srcRoot + moduleName + '.js', modulesCart.srcRoot + moduleName + '/index.js'];
|
|
542
559
|
for (const candidate of candidates) {
|
|
543
560
|
if (fileExists(candidate)) {
|
|
544
561
|
return { ...def, fileName: candidate, textSpan: { start: 0, length: 0 } };
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { type CdnZonesClient } from '@salesforce/b2c-tooling-sdk/clients';
|
|
2
|
+
import { type MtlsCertificate } from '@salesforce/b2c-tooling-sdk/operations/mtls';
|
|
3
|
+
/** Paths of the files written when generating code upload certificates. */
|
|
4
|
+
export interface CodeUploadCertificateFiles {
|
|
5
|
+
/** CA certificate (PEM) — uploaded to eCDN */
|
|
6
|
+
caCertificate: string;
|
|
7
|
+
/** CA private key (PEM) — needed to issue more client certificates */
|
|
8
|
+
caPrivateKey: string;
|
|
9
|
+
/** Client certificate bundle (PKCS12) — used for WebDAV code upload */
|
|
10
|
+
clientCertificate: string;
|
|
11
|
+
}
|
|
12
|
+
/** Options for {@link generateAndUploadCodeUploadCertificate}. */
|
|
13
|
+
export interface GenerateAndUploadOptions {
|
|
14
|
+
caCommonName?: string;
|
|
15
|
+
caValidityDays?: number;
|
|
16
|
+
client: CdnZonesClient;
|
|
17
|
+
clientName: string;
|
|
18
|
+
clientValidityDays?: number;
|
|
19
|
+
force?: boolean;
|
|
20
|
+
name: string;
|
|
21
|
+
onProgress?: (message: string) => void;
|
|
22
|
+
organizationId: string;
|
|
23
|
+
outDir: string;
|
|
24
|
+
passphrase?: string;
|
|
25
|
+
}
|
|
26
|
+
/** Result of {@link generateAndUploadCodeUploadCertificate}. */
|
|
27
|
+
export interface GenerateAndUploadResult {
|
|
28
|
+
/** Expiry of the generated CA (ISO 8601) */
|
|
29
|
+
caExpiresOn: string;
|
|
30
|
+
certificate: MtlsCertificate;
|
|
31
|
+
clientPassphrase: string;
|
|
32
|
+
files: CodeUploadCertificateFiles;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Converts a name into a safe file name stem.
|
|
36
|
+
*/
|
|
37
|
+
export declare function toFileStem(name: string): string;
|
|
38
|
+
/**
|
|
39
|
+
* Throws if any of the given files exist and `force` is not set.
|
|
40
|
+
*/
|
|
41
|
+
export declare function assertFilesWritable(files: string[], force?: boolean): void;
|
|
42
|
+
/**
|
|
43
|
+
* Writes a file readable only by the current user, creating parent directories.
|
|
44
|
+
*/
|
|
45
|
+
export declare function writePrivateFile(file: string, data: Buffer | string): void;
|
|
46
|
+
/**
|
|
47
|
+
* Writes a `.gitignore` ignoring everything in a directory of generated secrets,
|
|
48
|
+
* unless the directory already has one.
|
|
49
|
+
*/
|
|
50
|
+
export declare function ensureGitIgnored(dir: string): void;
|
|
51
|
+
/**
|
|
52
|
+
* Resolves the default CA common name. Salesforce recommends the staging
|
|
53
|
+
* Business Manager hostname (`staging-<realm>-<customer>.demandware.net`).
|
|
54
|
+
*/
|
|
55
|
+
export declare function defaultCaCommonName(name: string, hostname?: string): string;
|
|
56
|
+
/**
|
|
57
|
+
* Returns a warning if the organization is not a staging organization;
|
|
58
|
+
* eCDN only accepts code upload certificates for `_stg` organizations.
|
|
59
|
+
*/
|
|
60
|
+
export declare function stagingOrganizationWarning(organizationId: string): string | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* Human-readable security guidance for a generated CA private key.
|
|
63
|
+
*/
|
|
64
|
+
export declare function caKeySecurityNotice(caPrivateKey: string, caExpiresOn?: string): string;
|
|
65
|
+
/**
|
|
66
|
+
* Human-readable guidance for an issued client certificate.
|
|
67
|
+
*/
|
|
68
|
+
export declare function clientCertificateNotice(options: {
|
|
69
|
+
file: string;
|
|
70
|
+
hostname?: string;
|
|
71
|
+
passphrase: string;
|
|
72
|
+
}): string;
|
|
73
|
+
/**
|
|
74
|
+
* Generates a CA, uploads it to eCDN, and issues a first client certificate.
|
|
75
|
+
*
|
|
76
|
+
* CA files are written before the upload so the CA key is never lost: if the
|
|
77
|
+
* upload fails, the files can be uploaded later with `--certificate-file` and
|
|
78
|
+
* `--private-key-file`.
|
|
79
|
+
*/
|
|
80
|
+
export declare function generateAndUploadCodeUploadCertificate(options: GenerateAndUploadOptions): Promise<GenerateAndUploadResult>;
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025, Salesforce, Inc.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2
|
|
4
|
+
* For full license text, see the license.txt file in the repo root or http://www.apache.org/licenses/LICENSE-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { ux } from '@oclif/core';
|
|
7
|
+
import * as fs from 'node:fs';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import { normalizeTenantId } from '@salesforce/b2c-tooling-sdk/clients';
|
|
10
|
+
import { createCodeUploadCertificate, generateCaCertificate, issueClientCertificate, } from '@salesforce/b2c-tooling-sdk/operations/mtls';
|
|
11
|
+
/**
|
|
12
|
+
* Converts a name into a safe file name stem.
|
|
13
|
+
*/
|
|
14
|
+
export function toFileStem(name) {
|
|
15
|
+
return (name
|
|
16
|
+
.trim()
|
|
17
|
+
.replaceAll(/[^\w.-]+/g, '-')
|
|
18
|
+
.replaceAll(/^-+|-+$/g, '') || 'client');
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Throws if any of the given files exist and `force` is not set.
|
|
22
|
+
*/
|
|
23
|
+
export function assertFilesWritable(files, force = false) {
|
|
24
|
+
if (force)
|
|
25
|
+
return;
|
|
26
|
+
const existing = files.filter((f) => fs.existsSync(f));
|
|
27
|
+
if (existing.length > 0) {
|
|
28
|
+
throw new Error(`Refusing to overwrite existing file(s): ${existing.join(', ')}. Use --force to overwrite.`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Writes a file readable only by the current user, creating parent directories.
|
|
33
|
+
*/
|
|
34
|
+
export function writePrivateFile(file, data) {
|
|
35
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
36
|
+
fs.writeFileSync(file, data, { mode: 0o600 });
|
|
37
|
+
// writeFileSync only applies mode to new files
|
|
38
|
+
fs.chmodSync(file, 0o600);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Writes a `.gitignore` ignoring everything in a directory of generated secrets,
|
|
42
|
+
* unless the directory already has one.
|
|
43
|
+
*/
|
|
44
|
+
export function ensureGitIgnored(dir) {
|
|
45
|
+
const gitignore = path.resolve(dir, '.gitignore');
|
|
46
|
+
if (fs.existsSync(gitignore))
|
|
47
|
+
return;
|
|
48
|
+
fs.mkdirSync(path.dirname(gitignore), { recursive: true });
|
|
49
|
+
fs.writeFileSync(gitignore, '# Generated mTLS certificates and keys: never commit these\n*\n');
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Resolves the default CA common name. Salesforce recommends the staging
|
|
53
|
+
* Business Manager hostname (`staging-<realm>-<customer>.demandware.net`).
|
|
54
|
+
*/
|
|
55
|
+
export function defaultCaCommonName(name, hostname) {
|
|
56
|
+
return hostname?.startsWith('staging-') ? hostname : `${name} CA`;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Returns a warning if the organization is not a staging organization;
|
|
60
|
+
* eCDN only accepts code upload certificates for `_stg` organizations.
|
|
61
|
+
*/
|
|
62
|
+
export function stagingOrganizationWarning(organizationId) {
|
|
63
|
+
if (organizationId.endsWith('_stg'))
|
|
64
|
+
return undefined;
|
|
65
|
+
return `Code upload certificates are only supported for staging organizations (tenant ID ending in "_stg"); "${organizationId}" may be rejected.`;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Human-readable security guidance for a generated CA private key.
|
|
69
|
+
*/
|
|
70
|
+
export function caKeySecurityNotice(caPrivateKey, caExpiresOn) {
|
|
71
|
+
const lines = [
|
|
72
|
+
ux.colorize('yellow', 'IMPORTANT: protect the CA private key'),
|
|
73
|
+
` ${caPrivateKey}`,
|
|
74
|
+
' Anyone with this key can issue client certificates that are trusted for code upload',
|
|
75
|
+
' to your staging instance. Treat it like a password:',
|
|
76
|
+
' - Move it (and ca.pem) to a secure location such as a password manager or secrets vault.',
|
|
77
|
+
' It is only needed to issue new client certificates ("b2c ecdn mtls issue").',
|
|
78
|
+
' - Never commit it to a source repository or share it. The output directory',
|
|
79
|
+
' contains a .gitignore to help prevent this.',
|
|
80
|
+
' - Give each user or pipeline its own client certificate (.p12) instead of sharing the CA.',
|
|
81
|
+
];
|
|
82
|
+
if (caExpiresOn) {
|
|
83
|
+
lines.push('', ` The CA expires on ${caExpiresOn}. The CA certificate bundle is allowed a maximum expiry`, ' of 1 year; renew it before it expires to avoid disruption with code uploads. Create a', ' new CA, re-issue client certificates from it, verify uploads, then delete the old CA.');
|
|
84
|
+
}
|
|
85
|
+
return lines.join('\n');
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Human-readable guidance for an issued client certificate.
|
|
89
|
+
*/
|
|
90
|
+
export function clientCertificateNotice(options) {
|
|
91
|
+
// On Hyperforce the code upload hostname is the standard staging hostname, so a
|
|
92
|
+
// separate webdav-hostname isn't needed.
|
|
93
|
+
const config = {};
|
|
94
|
+
if (options.hostname)
|
|
95
|
+
config.hostname = options.hostname;
|
|
96
|
+
config.certificate = options.file;
|
|
97
|
+
config['certificate-passphrase'] = options.passphrase;
|
|
98
|
+
const snippet = JSON.stringify(config, null, 2)
|
|
99
|
+
.split('\n')
|
|
100
|
+
.map((line) => ` ${line}`)
|
|
101
|
+
.join('\n');
|
|
102
|
+
return [
|
|
103
|
+
'Client certificate (use this for code upload, not the CA):',
|
|
104
|
+
` File: ${options.file}`,
|
|
105
|
+
` Passphrase: ${options.passphrase}`,
|
|
106
|
+
' The .p12 and its passphrase are credentials: store them securely, keep the',
|
|
107
|
+
' passphrase separate from the file, and never commit either to a repository.',
|
|
108
|
+
'',
|
|
109
|
+
' To upload code, add these settings to your instance in dw.json',
|
|
110
|
+
' (or use --server, --certificate and --passphrase):',
|
|
111
|
+
snippet,
|
|
112
|
+
].join('\n');
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Generates a CA, uploads it to eCDN, and issues a first client certificate.
|
|
116
|
+
*
|
|
117
|
+
* CA files are written before the upload so the CA key is never lost: if the
|
|
118
|
+
* upload fails, the files can be uploaded later with `--certificate-file` and
|
|
119
|
+
* `--private-key-file`.
|
|
120
|
+
*/
|
|
121
|
+
export async function generateAndUploadCodeUploadCertificate(options) {
|
|
122
|
+
const progress = options.onProgress ?? (() => { });
|
|
123
|
+
const files = {
|
|
124
|
+
caCertificate: path.resolve(options.outDir, 'ca.pem'),
|
|
125
|
+
caPrivateKey: path.resolve(options.outDir, 'ca.key'),
|
|
126
|
+
clientCertificate: path.resolve(options.outDir, `${toFileStem(options.clientName)}.p12`),
|
|
127
|
+
};
|
|
128
|
+
assertFilesWritable(Object.values(files), options.force);
|
|
129
|
+
ensureGitIgnored(options.outDir);
|
|
130
|
+
progress(`Generating CA certificate for tenant ${normalizeTenantId(options.organizationId)}...`);
|
|
131
|
+
const ca = generateCaCertificate({
|
|
132
|
+
commonName: options.caCommonName ?? `${options.name} CA`,
|
|
133
|
+
validityDays: options.caValidityDays,
|
|
134
|
+
});
|
|
135
|
+
writePrivateFile(files.caCertificate, ca.certificatePem);
|
|
136
|
+
writePrivateFile(files.caPrivateKey, ca.privateKeyPem);
|
|
137
|
+
progress('Uploading CA certificate to eCDN...');
|
|
138
|
+
let certificate;
|
|
139
|
+
try {
|
|
140
|
+
certificate = await createCodeUploadCertificate(options.client, options.organizationId, {
|
|
141
|
+
name: options.name,
|
|
142
|
+
certificatePem: ca.certificatePem,
|
|
143
|
+
privateKeyPem: ca.privateKeyPem,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
148
|
+
throw new Error(`${message}\nThe generated CA was saved to ${files.caCertificate} and ${files.caPrivateKey}; ` +
|
|
149
|
+
'retry the upload with --certificate-file and --private-key-file.', { cause: error });
|
|
150
|
+
}
|
|
151
|
+
progress('Issuing client certificate...');
|
|
152
|
+
const clientCert = issueClientCertificate({
|
|
153
|
+
ca,
|
|
154
|
+
commonName: options.clientName,
|
|
155
|
+
validityDays: options.clientValidityDays,
|
|
156
|
+
passphrase: options.passphrase,
|
|
157
|
+
});
|
|
158
|
+
writePrivateFile(files.clientCertificate, clientCert.pkcs12);
|
|
159
|
+
return { caExpiresOn: ca.notAfter.toISOString(), certificate, clientPassphrase: clientCert.passphrase, files };
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=mtls.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mtls.js","sourceRoot":"","sources":["../../../src/utils/ecdn/mtls.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAC,EAAE,EAAC,MAAM,aAAa,CAAC;AAC/B,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAC,iBAAiB,EAAsB,MAAM,qCAAqC,CAAC;AAC3F,OAAO,EACL,2BAA2B,EAC3B,qBAAqB,EACrB,sBAAsB,GAEvB,MAAM,6CAA6C,CAAC;AAoCrD;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,OAAO,CACL,IAAI;SACD,IAAI,EAAE;SACN,UAAU,CAAC,WAAW,EAAE,GAAG,CAAC;SAC5B,UAAU,CAAC,UAAU,EAAE,EAAE,CAAC,IAAI,QAAQ,CAC1C,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAe,EAAE,KAAK,GAAG,KAAK;IAChE,IAAI,KAAK;QAAE,OAAO;IAClB,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;IACvD,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,2CAA2C,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC;IAC/G,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,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