@salesforce/b2c-tooling-sdk 1.21.3 → 1.23.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/data/guides/enrichment.json +294 -0
- package/data/guides/index.json +434 -27
- package/data/help/index.json +6 -1
- package/data/job-steps/index.json +1 -1
- package/data/job-steps/job-steps.json +1 -1
- package/data/script-api/index.json +49 -5
- package/data/tooling/index.json +432 -9
- package/data/xsd/commercefeaturestate.xsd +1 -0
- package/data/xsd/index.json +2 -1
- package/data/xsd/redirecturl.xsd +2 -0
- package/dist/esm/auth/index.d.ts +6 -3
- package/dist/esm/auth/index.js +4 -2
- package/dist/esm/auth/index.js.map +1 -1
- package/dist/esm/auth/oauth-implicit.d.ts +19 -0
- package/dist/esm/auth/oauth-implicit.js +103 -10
- package/dist/esm/auth/oauth-implicit.js.map +1 -1
- package/dist/esm/auth/oauth-pkce-fallback.d.ts +68 -0
- package/dist/esm/auth/oauth-pkce-fallback.js +128 -0
- package/dist/esm/auth/oauth-pkce-fallback.js.map +1 -0
- package/dist/esm/auth/oauth-pkce.d.ts +94 -0
- package/dist/esm/auth/oauth-pkce.js +579 -0
- package/dist/esm/auth/oauth-pkce.js.map +1 -0
- package/dist/esm/auth/resolve.d.ts +4 -3
- package/dist/esm/auth/resolve.js +17 -2
- package/dist/esm/auth/resolve.js.map +1 -1
- package/dist/esm/auth/session-store.d.ts +99 -0
- package/dist/esm/auth/session-store.js +242 -0
- package/dist/esm/auth/session-store.js.map +1 -0
- package/dist/esm/auth/stateful-oauth-strategy.d.ts +20 -24
- package/dist/esm/auth/stateful-oauth-strategy.js +16 -114
- package/dist/esm/auth/stateful-oauth-strategy.js.map +1 -1
- package/dist/esm/auth/types.d.ts +20 -4
- package/dist/esm/auth/types.js +1 -1
- package/dist/esm/auth/types.js.map +1 -1
- package/dist/esm/cli/am-command.d.ts +2 -2
- package/dist/esm/cli/am-command.js +13 -4
- package/dist/esm/cli/am-command.js.map +1 -1
- package/dist/esm/cli/base-command.js +3 -3
- package/dist/esm/cli/base-command.js.map +1 -1
- package/dist/esm/cli/config.js +3 -1
- package/dist/esm/cli/config.js.map +1 -1
- package/dist/esm/cli/lifecycle.d.ts +1 -1
- package/dist/esm/cli/lifecycle.js.map +1 -1
- package/dist/esm/cli/oauth-command.d.ts +12 -11
- package/dist/esm/cli/oauth-command.js +73 -41
- package/dist/esm/cli/oauth-command.js.map +1 -1
- package/dist/esm/cli/ods-command.d.ts +1 -1
- package/dist/esm/cli/ods-command.js +5 -3
- package/dist/esm/cli/ods-command.js.map +1 -1
- package/dist/esm/clients/ods.generated.d.ts +16 -0
- package/dist/esm/config/dw-json.d.ts +10 -0
- package/dist/esm/config/dw-json.js.map +1 -1
- package/dist/esm/config/index.d.ts +1 -0
- package/dist/esm/config/index.js +2 -0
- package/dist/esm/config/index.js.map +1 -1
- package/dist/esm/config/mapping.d.ts +13 -0
- package/dist/esm/config/mapping.js +66 -3
- package/dist/esm/config/mapping.js.map +1 -1
- package/dist/esm/config/redaction.d.ts +39 -0
- package/dist/esm/config/redaction.js +51 -0
- package/dist/esm/config/redaction.js.map +1 -0
- package/dist/esm/config/resolver.js +1 -0
- package/dist/esm/config/resolver.js.map +1 -1
- package/dist/esm/config/sources/env-source.d.ts +1 -1
- package/dist/esm/config/sources/env-source.js +14 -7
- package/dist/esm/config/sources/env-source.js.map +1 -1
- package/dist/esm/config/sources/package-json-source.js +3 -1
- package/dist/esm/config/sources/package-json-source.js.map +1 -1
- package/dist/esm/config/types.d.ts +14 -4
- package/dist/esm/defaults.d.ts +23 -4
- package/dist/esm/defaults.js +36 -4
- package/dist/esm/defaults.js.map +1 -1
- package/dist/esm/docs/content-cache.d.ts +1 -1
- package/dist/esm/docs/content-cache.js +1 -1
- package/dist/esm/docs/index.d.ts +1 -1
- package/dist/esm/docs/index.js.map +1 -1
- package/dist/esm/docs/types.d.ts +29 -0
- package/dist/esm/index.d.ts +6 -4
- package/dist/esm/index.js +3 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/instance/index.js +3 -3
- package/dist/esm/instance/index.js.map +1 -1
- package/dist/esm/operations/cap/index.d.ts +2 -2
- package/dist/esm/operations/cap/index.js +1 -1
- package/dist/esm/operations/cap/index.js.map +1 -1
- package/dist/esm/operations/cap/install.d.ts +17 -0
- package/dist/esm/operations/cap/install.js +29 -0
- package/dist/esm/operations/cap/install.js.map +1 -1
- package/dist/esm/operations/cap/package.js +36 -0
- package/dist/esm/operations/cap/package.js.map +1 -1
- package/dist/esm/operations/cap/validate.d.ts +9 -0
- package/dist/esm/operations/cap/validate.js +29 -0
- package/dist/esm/operations/cap/validate.js.map +1 -1
- package/dist/esm/operations/content/export.js +7 -3
- package/dist/esm/operations/content/export.js.map +1 -1
- package/dist/esm/operations/content/library.d.ts +26 -0
- package/dist/esm/operations/content/library.js +83 -2
- package/dist/esm/operations/content/library.js.map +1 -1
- package/dist/esm/operations/content/types.d.ts +10 -1
- package/dist/esm/operations/jobs/import-set.d.ts +170 -0
- package/dist/esm/operations/jobs/import-set.js +538 -0
- package/dist/esm/operations/jobs/import-set.js.map +1 -0
- package/dist/esm/operations/jobs/index.d.ts +3 -0
- package/dist/esm/operations/jobs/index.js +3 -0
- package/dist/esm/operations/jobs/index.js.map +1 -1
- package/dist/esm/operations/jobs/run.js +0 -11
- package/dist/esm/operations/jobs/run.js.map +1 -1
- package/dist/esm/operations/jobs/site-archive.js +13 -75
- package/dist/esm/operations/jobs/site-archive.js.map +1 -1
- package/dist/esm/operations/ods/index.d.ts +4 -0
- package/dist/esm/operations/ods/index.js +2 -0
- package/dist/esm/operations/ods/index.js.map +1 -1
- package/dist/esm/operations/ods/sandbox-settings.d.ts +51 -0
- package/dist/esm/operations/ods/sandbox-settings.js +63 -0
- package/dist/esm/operations/ods/sandbox-settings.js.map +1 -0
- package/dist/esm/operations/ods/wait-for-clones.d.ts +97 -0
- package/dist/esm/operations/ods/wait-for-clones.js +145 -0
- package/dist/esm/operations/ods/wait-for-clones.js.map +1 -0
- package/package.json +2 -1
- package/specs/ods-api-v1.json +43 -0
- package/dist/esm/auth/stateful-store.d.ts +0 -49
- package/dist/esm/auth/stateful-store.js +0 -166
- package/dist/esm/auth/stateful-store.js.map +0 -1
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { OdsClient } from '../../clients/ods.js';
|
|
2
|
+
import type { CloneState } from './wait-for-clone.js';
|
|
3
|
+
/**
|
|
4
|
+
* Status of a single clone within a batch, as observed on one poll tick.
|
|
5
|
+
*/
|
|
6
|
+
export interface CloneBatchMemberStatus {
|
|
7
|
+
cloneId: string;
|
|
8
|
+
status: CloneState;
|
|
9
|
+
progressPercentage?: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Error thrown when a batch of sandbox clones does not all reach a terminal
|
|
13
|
+
* state (`COMPLETED` or `FAILED`) within the configured timeout while polling.
|
|
14
|
+
*
|
|
15
|
+
* @param sandboxId - ID of the source sandbox
|
|
16
|
+
* @param cloneIds - IDs of the clone operations being monitored
|
|
17
|
+
* @param timeoutSeconds - Timeout duration in seconds
|
|
18
|
+
* @param lastStatuses - Last observed status for each clone before the timeout occurred
|
|
19
|
+
*/
|
|
20
|
+
export declare class CloneBatchPollingTimeoutError extends Error {
|
|
21
|
+
readonly sandboxId: string;
|
|
22
|
+
readonly cloneIds: string[];
|
|
23
|
+
readonly timeoutSeconds: number;
|
|
24
|
+
readonly lastStatuses: CloneBatchMemberStatus[];
|
|
25
|
+
constructor(sandboxId: string, cloneIds: string[], timeoutSeconds: number, lastStatuses: CloneBatchMemberStatus[]);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Error thrown when an API request to fetch the status of a clone in a batch fails.
|
|
29
|
+
*
|
|
30
|
+
* @param sandboxId - ID of the source sandbox
|
|
31
|
+
* @param cloneId - ID of the clone operation whose status request failed
|
|
32
|
+
* @param message - Underlying error message from the API call
|
|
33
|
+
*/
|
|
34
|
+
export declare class CloneBatchPollingError extends Error {
|
|
35
|
+
readonly sandboxId: string;
|
|
36
|
+
readonly cloneId: string;
|
|
37
|
+
constructor(sandboxId: string, cloneId: string, message: string);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Error thrown when one or more clones in a batch enter the `FAILED` state.
|
|
41
|
+
*
|
|
42
|
+
* All clones in the batch reached a terminal state, but at least one of them failed.
|
|
43
|
+
*
|
|
44
|
+
* @param sandboxId - ID of the source sandbox
|
|
45
|
+
* @param failedCloneIds - IDs of the clones that reached the `FAILED` state
|
|
46
|
+
* @param statuses - Final status for every clone in the batch
|
|
47
|
+
*/
|
|
48
|
+
export declare class CloneBatchFailedError extends Error {
|
|
49
|
+
readonly sandboxId: string;
|
|
50
|
+
readonly failedCloneIds: string[];
|
|
51
|
+
readonly statuses: CloneBatchMemberStatus[];
|
|
52
|
+
constructor(sandboxId: string, failedCloneIds: string[], statuses: CloneBatchMemberStatus[]);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Information passed to the `onPoll` callback on each poll tick while waiting for a batch of clones.
|
|
56
|
+
*/
|
|
57
|
+
export interface WaitForClonesPollInfo {
|
|
58
|
+
sandboxId: string;
|
|
59
|
+
elapsedSeconds: number;
|
|
60
|
+
completed: number;
|
|
61
|
+
total: number;
|
|
62
|
+
clones: CloneBatchMemberStatus[];
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Configuration options for {@link waitForClones} batch polling behavior.
|
|
66
|
+
*/
|
|
67
|
+
export interface WaitForClonesOptions {
|
|
68
|
+
sandboxId: string;
|
|
69
|
+
cloneIds: string[];
|
|
70
|
+
pollIntervalSeconds: number;
|
|
71
|
+
timeoutSeconds: number;
|
|
72
|
+
onPoll?: (info: WaitForClonesPollInfo) => void;
|
|
73
|
+
sleep?: (ms: number) => Promise<void>;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Waits for a batch of sandbox clones (created via 1 to many cloning) to all reach a
|
|
77
|
+
* terminal state by polling each clone's status against the ODS API.
|
|
78
|
+
*
|
|
79
|
+
* Polls at `pollIntervalSeconds` until every clone in `cloneIds` reaches
|
|
80
|
+
* `COMPLETED` or `FAILED`, or the configured timeout is exceeded. An initial
|
|
81
|
+
* poll delay equal to `pollIntervalSeconds` is applied before the first status
|
|
82
|
+
* check.
|
|
83
|
+
*
|
|
84
|
+
* @param client - ODS client for API calls
|
|
85
|
+
* @param options - Polling configuration options
|
|
86
|
+
* @param options.sandboxId - ID of the source sandbox
|
|
87
|
+
* @param options.cloneIds - IDs of the clone operations to monitor (e.g. `siblingCloneIds`)
|
|
88
|
+
* @param options.pollIntervalSeconds - Seconds between status checks
|
|
89
|
+
* @param options.timeoutSeconds - Maximum seconds to wait (`0` disables the timeout)
|
|
90
|
+
* @param options.onPoll - Optional callback invoked after each status poll with aggregate progress
|
|
91
|
+
* @param options.sleep - Optional custom sleep function (primarily for testing)
|
|
92
|
+
* @returns Promise that resolves with the final status of every clone once all reach `COMPLETED`
|
|
93
|
+
* @throws {CloneBatchPollingTimeoutError} If the timeout is exceeded before all clones complete
|
|
94
|
+
* @throws {CloneBatchPollingError} If an API request fails
|
|
95
|
+
* @throws {CloneBatchFailedError} If one or more clones enter the `FAILED` state
|
|
96
|
+
*/
|
|
97
|
+
export declare function waitForClones(client: OdsClient, options: WaitForClonesOptions): Promise<CloneBatchMemberStatus[]>;
|
|
@@ -0,0 +1,145 @@
|
|
|
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 { getLogger } from '../../logging/logger.js';
|
|
7
|
+
/**
|
|
8
|
+
* Error thrown when a batch of sandbox clones does not all reach a terminal
|
|
9
|
+
* state (`COMPLETED` or `FAILED`) within the configured timeout while polling.
|
|
10
|
+
*
|
|
11
|
+
* @param sandboxId - ID of the source sandbox
|
|
12
|
+
* @param cloneIds - IDs of the clone operations being monitored
|
|
13
|
+
* @param timeoutSeconds - Timeout duration in seconds
|
|
14
|
+
* @param lastStatuses - Last observed status for each clone before the timeout occurred
|
|
15
|
+
*/
|
|
16
|
+
export class CloneBatchPollingTimeoutError extends Error {
|
|
17
|
+
sandboxId;
|
|
18
|
+
cloneIds;
|
|
19
|
+
timeoutSeconds;
|
|
20
|
+
lastStatuses;
|
|
21
|
+
constructor(sandboxId, cloneIds, timeoutSeconds, lastStatuses) {
|
|
22
|
+
const pending = lastStatuses.filter((s) => s.status !== 'COMPLETED' && s.status !== 'FAILED');
|
|
23
|
+
super(`Timeout waiting for ${cloneIds.length} clone(s) of sandbox ${sandboxId} after ${timeoutSeconds} seconds ` +
|
|
24
|
+
`(${pending.length} of ${cloneIds.length} still pending)`);
|
|
25
|
+
this.sandboxId = sandboxId;
|
|
26
|
+
this.cloneIds = cloneIds;
|
|
27
|
+
this.timeoutSeconds = timeoutSeconds;
|
|
28
|
+
this.lastStatuses = lastStatuses;
|
|
29
|
+
this.name = 'CloneBatchPollingTimeoutError';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Error thrown when an API request to fetch the status of a clone in a batch fails.
|
|
34
|
+
*
|
|
35
|
+
* @param sandboxId - ID of the source sandbox
|
|
36
|
+
* @param cloneId - ID of the clone operation whose status request failed
|
|
37
|
+
* @param message - Underlying error message from the API call
|
|
38
|
+
*/
|
|
39
|
+
export class CloneBatchPollingError extends Error {
|
|
40
|
+
sandboxId;
|
|
41
|
+
cloneId;
|
|
42
|
+
constructor(sandboxId, cloneId, message) {
|
|
43
|
+
super(`Failed to fetch clone status for ${cloneId} of sandbox ${sandboxId}: ${message}`);
|
|
44
|
+
this.sandboxId = sandboxId;
|
|
45
|
+
this.cloneId = cloneId;
|
|
46
|
+
this.name = 'CloneBatchPollingError';
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Error thrown when one or more clones in a batch enter the `FAILED` state.
|
|
51
|
+
*
|
|
52
|
+
* All clones in the batch reached a terminal state, but at least one of them failed.
|
|
53
|
+
*
|
|
54
|
+
* @param sandboxId - ID of the source sandbox
|
|
55
|
+
* @param failedCloneIds - IDs of the clones that reached the `FAILED` state
|
|
56
|
+
* @param statuses - Final status for every clone in the batch
|
|
57
|
+
*/
|
|
58
|
+
export class CloneBatchFailedError extends Error {
|
|
59
|
+
sandboxId;
|
|
60
|
+
failedCloneIds;
|
|
61
|
+
statuses;
|
|
62
|
+
constructor(sandboxId, failedCloneIds, statuses) {
|
|
63
|
+
super(`${failedCloneIds.length} of ${statuses.length} clone(s) failed for sandbox ${sandboxId}`);
|
|
64
|
+
this.sandboxId = sandboxId;
|
|
65
|
+
this.failedCloneIds = failedCloneIds;
|
|
66
|
+
this.statuses = statuses;
|
|
67
|
+
this.name = 'CloneBatchFailedError';
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
async function defaultSleep(ms) {
|
|
71
|
+
await new Promise((resolve) => {
|
|
72
|
+
setTimeout(resolve, ms);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
function isTerminal(status) {
|
|
76
|
+
return status === 'COMPLETED' || status === 'FAILED';
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Waits for a batch of sandbox clones (created via 1 to many cloning) to all reach a
|
|
80
|
+
* terminal state by polling each clone's status against the ODS API.
|
|
81
|
+
*
|
|
82
|
+
* Polls at `pollIntervalSeconds` until every clone in `cloneIds` reaches
|
|
83
|
+
* `COMPLETED` or `FAILED`, or the configured timeout is exceeded. An initial
|
|
84
|
+
* poll delay equal to `pollIntervalSeconds` is applied before the first status
|
|
85
|
+
* check.
|
|
86
|
+
*
|
|
87
|
+
* @param client - ODS client for API calls
|
|
88
|
+
* @param options - Polling configuration options
|
|
89
|
+
* @param options.sandboxId - ID of the source sandbox
|
|
90
|
+
* @param options.cloneIds - IDs of the clone operations to monitor (e.g. `siblingCloneIds`)
|
|
91
|
+
* @param options.pollIntervalSeconds - Seconds between status checks
|
|
92
|
+
* @param options.timeoutSeconds - Maximum seconds to wait (`0` disables the timeout)
|
|
93
|
+
* @param options.onPoll - Optional callback invoked after each status poll with aggregate progress
|
|
94
|
+
* @param options.sleep - Optional custom sleep function (primarily for testing)
|
|
95
|
+
* @returns Promise that resolves with the final status of every clone once all reach `COMPLETED`
|
|
96
|
+
* @throws {CloneBatchPollingTimeoutError} If the timeout is exceeded before all clones complete
|
|
97
|
+
* @throws {CloneBatchPollingError} If an API request fails
|
|
98
|
+
* @throws {CloneBatchFailedError} If one or more clones enter the `FAILED` state
|
|
99
|
+
*/
|
|
100
|
+
export async function waitForClones(client, options) {
|
|
101
|
+
const logger = getLogger();
|
|
102
|
+
const { sandboxId, cloneIds, pollIntervalSeconds, timeoutSeconds } = options;
|
|
103
|
+
const sleepFn = options.sleep ?? defaultSleep;
|
|
104
|
+
const startTime = Date.now();
|
|
105
|
+
const pollIntervalMs = pollIntervalSeconds * 1000;
|
|
106
|
+
const timeoutMs = timeoutSeconds * 1000;
|
|
107
|
+
await sleepFn(pollIntervalMs);
|
|
108
|
+
const statusByCloneId = new Map(cloneIds.map((cloneId) => [cloneId, { cloneId, status: 'PENDING' }]));
|
|
109
|
+
while (true) {
|
|
110
|
+
const elapsedSeconds = Math.round((Date.now() - startTime) / 1000);
|
|
111
|
+
if (timeoutSeconds > 0 && Date.now() - startTime > timeoutMs) {
|
|
112
|
+
throw new CloneBatchPollingTimeoutError(sandboxId, cloneIds, timeoutSeconds, [...statusByCloneId.values()]);
|
|
113
|
+
}
|
|
114
|
+
const pendingCloneIds = cloneIds.filter((cloneId) => !isTerminal(statusByCloneId.get(cloneId).status));
|
|
115
|
+
await Promise.all(pendingCloneIds.map(async (cloneId) => {
|
|
116
|
+
const result = await client.GET('/sandboxes/{sandboxId}/clones/{cloneId}', {
|
|
117
|
+
params: {
|
|
118
|
+
path: { sandboxId, cloneId },
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
if (!result.data?.data) {
|
|
122
|
+
throw new CloneBatchPollingError(sandboxId, cloneId, result.response?.statusText || 'Unknown error');
|
|
123
|
+
}
|
|
124
|
+
const clone = result.data.data;
|
|
125
|
+
statusByCloneId.set(cloneId, {
|
|
126
|
+
cloneId,
|
|
127
|
+
status: clone.status || 'PENDING',
|
|
128
|
+
progressPercentage: clone.progressPercentage,
|
|
129
|
+
});
|
|
130
|
+
}));
|
|
131
|
+
const lastStatuses = cloneIds.map((cloneId) => statusByCloneId.get(cloneId));
|
|
132
|
+
const completed = lastStatuses.filter((s) => isTerminal(s.status)).length;
|
|
133
|
+
logger.trace({ sandboxId, cloneIds, elapsedSeconds, statuses: lastStatuses }, '[ODS] Clone batch poll');
|
|
134
|
+
options.onPoll?.({ sandboxId, elapsedSeconds, completed, total: cloneIds.length, clones: lastStatuses });
|
|
135
|
+
if (completed === cloneIds.length) {
|
|
136
|
+
const failedCloneIds = lastStatuses.filter((s) => s.status === 'FAILED').map((s) => s.cloneId);
|
|
137
|
+
if (failedCloneIds.length > 0) {
|
|
138
|
+
throw new CloneBatchFailedError(sandboxId, failedCloneIds, lastStatuses);
|
|
139
|
+
}
|
|
140
|
+
return lastStatuses;
|
|
141
|
+
}
|
|
142
|
+
await sleepFn(pollIntervalMs);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=wait-for-clones.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wait-for-clones.js","sourceRoot":"","sources":["../../../../src/operations/ods/wait-for-clones.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAC,SAAS,EAAC,MAAM,yBAAyB,CAAC;AAYlD;;;;;;;;GAQG;AACH,MAAM,OAAO,6BAA8B,SAAQ,KAAK;IAEpC;IACA;IACA;IACA;IAJlB,YACkB,SAAiB,EACjB,QAAkB,EAClB,cAAsB,EACtB,YAAsC;QAEtD,MAAM,OAAO,GAAG,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E,cAAc,EAAE,QAAQ,EAAE,YAAY,EAAC,EAAE,wBAAwB,CAAC,CAAC;QACtG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAC,SAAS,EAAE,cAAc,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAC,CAAC,CAAC;QAEvG,IAAI,SAAS,KAAK,QAAQ,CAAC,MAAM,EAAE,CAAC;YAClC,MAAM,cAAc,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;YAC/F,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAC9B,MAAM,IAAI,qBAAqB,CAAC,SAAS,EAAE,cAAc,EAAE,YAAY,CAAC,CAAC;YAC3E,CAAC;YACD,OAAO,YAAY,CAAC;QACtB,CAAC;QAED,MAAM,OAAO,CAAC,cAAc,CAAC,CAAC;IAChC,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforce/b2c-tooling-sdk",
|
|
3
3
|
"description": "Core tooling library for Salesforce B2C Commerce CLI",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.23.0",
|
|
5
5
|
"author": "Charles Lavery",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"repository": "SalesforceCommerceCloud/b2c-developer-tooling",
|
|
@@ -266,6 +266,7 @@
|
|
|
266
266
|
"generate:guides-index": "tsx scripts/generate-guides-index.ts",
|
|
267
267
|
"check:guides-links": "tsx scripts/check-guides-links.ts",
|
|
268
268
|
"generate:tooling-index": "tsx scripts/generate-tooling-index.ts",
|
|
269
|
+
"check:tooling-index": "tsx scripts/generate-tooling-index.ts --check",
|
|
269
270
|
"generate:help-corpus": "tsx scripts/generate-help-corpus.ts",
|
|
270
271
|
"enrich:docs": "tsx scripts/enrich-docs.ts"
|
|
271
272
|
}
|
package/specs/ods-api-v1.json
CHANGED
|
@@ -1251,6 +1251,15 @@
|
|
|
1251
1251
|
"Completed"
|
|
1252
1252
|
]
|
|
1253
1253
|
}
|
|
1254
|
+
},
|
|
1255
|
+
{
|
|
1256
|
+
"name": "batchId",
|
|
1257
|
+
"in": "query",
|
|
1258
|
+
"description": "Filter clones by their 1 to many batch identifier. When provided, returns only clones belonging to that batch. Optional.",
|
|
1259
|
+
"required": false,
|
|
1260
|
+
"schema": {
|
|
1261
|
+
"type": "string"
|
|
1262
|
+
}
|
|
1254
1263
|
}
|
|
1255
1264
|
],
|
|
1256
1265
|
"responses": {
|
|
@@ -2916,6 +2925,19 @@
|
|
|
2916
2925
|
"databaseTransferSize": {
|
|
2917
2926
|
"type": "integer",
|
|
2918
2927
|
"format": "int64"
|
|
2928
|
+
},
|
|
2929
|
+
"batchId": {
|
|
2930
|
+
"type": "string",
|
|
2931
|
+
"nullable": true,
|
|
2932
|
+
"description": "Shared batch identifier for clones created together via 1 to many cloning. Absent for single (1:1) clones."
|
|
2933
|
+
},
|
|
2934
|
+
"siblingCloneIds": {
|
|
2935
|
+
"type": "array",
|
|
2936
|
+
"nullable": true,
|
|
2937
|
+
"items": {
|
|
2938
|
+
"type": "string"
|
|
2939
|
+
},
|
|
2940
|
+
"description": "cloneIds of all clones in the same 1 to many batch, in target-index order (element i = cloneId of target index i). Includes this clone. Absent for single (1:1) clones."
|
|
2919
2941
|
}
|
|
2920
2942
|
}
|
|
2921
2943
|
},
|
|
@@ -2925,6 +2947,19 @@
|
|
|
2925
2947
|
"cloneId": {
|
|
2926
2948
|
"type": "string",
|
|
2927
2949
|
"example": "zyom-002-017-180620251331"
|
|
2950
|
+
},
|
|
2951
|
+
"batchId": {
|
|
2952
|
+
"type": "string",
|
|
2953
|
+
"nullable": true,
|
|
2954
|
+
"description": "Shared batch identifier when this create fanned out to multiple clones (1 to many). Absent for single (1:1) clones."
|
|
2955
|
+
},
|
|
2956
|
+
"siblingCloneIds": {
|
|
2957
|
+
"type": "array",
|
|
2958
|
+
"nullable": true,
|
|
2959
|
+
"items": {
|
|
2960
|
+
"type": "string"
|
|
2961
|
+
},
|
|
2962
|
+
"description": "cloneIds of all clones created by this 1 to many request. Absent for single (1:1) clones."
|
|
2928
2963
|
}
|
|
2929
2964
|
}
|
|
2930
2965
|
},
|
|
@@ -2934,6 +2969,14 @@
|
|
|
2934
2969
|
"targetProfile": {
|
|
2935
2970
|
"$ref": "#/components/schemas/SandboxResourceProfile"
|
|
2936
2971
|
},
|
|
2972
|
+
"targetCount": {
|
|
2973
|
+
"type": "integer",
|
|
2974
|
+
"format": "int32",
|
|
2975
|
+
"minimum": 1,
|
|
2976
|
+
"maximum": 5,
|
|
2977
|
+
"default": 1,
|
|
2978
|
+
"description": "Number of sandbox clones to create from this source (1 to many cloning). Valid values are 1 to 5. Defaults to 1 (a single 1:1 clone). When greater than 1, the clones fan out as a batch sharing a batchId."
|
|
2979
|
+
},
|
|
2937
2980
|
"emails": {
|
|
2938
2981
|
"type": "array",
|
|
2939
2982
|
"items": {
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Initialize the stateful store with the oclif data directory.
|
|
3
|
-
* Call this from BaseCommand.init() with this.config.dataDir so the session
|
|
4
|
-
* file is stored alongside other CLI data (e.g. ~/Library/Application Support/@salesforce/b2c-cli).
|
|
5
|
-
*/
|
|
6
|
-
export declare function initializeStatefulStore(dataDir: string): void;
|
|
7
|
-
/**
|
|
8
|
-
* Stored session persisted by stateful auth commands.
|
|
9
|
-
*/
|
|
10
|
-
export interface StatefulSession {
|
|
11
|
-
clientId: string;
|
|
12
|
-
accessToken: string;
|
|
13
|
-
refreshToken?: string | null;
|
|
14
|
-
/** Base64-encoded "clientId:clientSecret" for token renewal. */
|
|
15
|
-
renewBase?: string | null;
|
|
16
|
-
user?: string | null;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Reads the current stateful session from the JSON file.
|
|
20
|
-
* Returns null if no session file exists or the file is invalid.
|
|
21
|
-
*/
|
|
22
|
-
export declare function getStoredSession(): StatefulSession | null;
|
|
23
|
-
/**
|
|
24
|
-
* Writes a session to the JSON file, creating the directory if needed.
|
|
25
|
-
*/
|
|
26
|
-
export declare function setStoredSession(session: StatefulSession): void;
|
|
27
|
-
/**
|
|
28
|
-
* Clears the stored session by removing the session file.
|
|
29
|
-
*/
|
|
30
|
-
export declare function clearStoredSession(): void;
|
|
31
|
-
/**
|
|
32
|
-
* Checks whether the stored access token is present and valid: not expired
|
|
33
|
-
* (with a small buffer), optionally satisfies required scopes, and optionally
|
|
34
|
-
* matches the expected client ID.
|
|
35
|
-
* Does not perform network calls.
|
|
36
|
-
*
|
|
37
|
-
* @param session - Session from getStoredSession()
|
|
38
|
-
* @param requiredScopes - If provided, token must include all of these scopes
|
|
39
|
-
* @param expiryBufferSec - Seconds before exp to treat token as expired (default 60)
|
|
40
|
-
* @param requiredClientId - If provided, session clientId must match
|
|
41
|
-
* @returns true if token is present and valid for use
|
|
42
|
-
*/
|
|
43
|
-
export declare function isStatefulTokenValid(session: StatefulSession, requiredScopes?: string[], expiryBufferSec?: number, requiredClientId?: string): boolean;
|
|
44
|
-
/**
|
|
45
|
-
* Resets the store path (for tests). After calling this, the next operation
|
|
46
|
-
* will use the default data directory unless initializeStatefulStore() is called again.
|
|
47
|
-
* @internal
|
|
48
|
-
*/
|
|
49
|
-
export declare function resetStatefulStoreForTesting(): void;
|
|
@@ -1,166 +0,0 @@
|
|
|
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
|
-
/**
|
|
7
|
-
* Stateful auth store backed by a JSON file in the oclif data directory
|
|
8
|
-
* (e.g. ~/Library/Application Support/@salesforce/b2c-cli/auth-session.json on macOS).
|
|
9
|
-
*
|
|
10
|
-
* Initialize via initializeStatefulStore(dataDir) from BaseCommand.init() so the
|
|
11
|
-
* session file is co-located with other CLI data. Falls back to an OS-appropriate
|
|
12
|
-
* default path when used standalone (outside a CLI command).
|
|
13
|
-
*
|
|
14
|
-
* The stateful auth workflow (b2c auth client / b2c auth login / b2c auth logout)
|
|
15
|
-
* is compatible with sfcc-ci command patterns. Session data is stored internally
|
|
16
|
-
* in the CLI data directory, not in the sfcc-ci config store.
|
|
17
|
-
*
|
|
18
|
-
* @module auth/stateful-store
|
|
19
|
-
*/
|
|
20
|
-
import { existsSync, mkdirSync, readFileSync, renameSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
21
|
-
import { join } from 'node:path';
|
|
22
|
-
import { homedir, platform } from 'node:os';
|
|
23
|
-
import { DEFAULT_EXPIRY_BUFFER_SEC, decodeJwtTokenInfo } from './jwt-utils.js';
|
|
24
|
-
import { getLogger } from '../logging/logger.js';
|
|
25
|
-
const STATEFUL_AUTH_SESSION_STORE = 'auth-session.json';
|
|
26
|
-
let storePath = null;
|
|
27
|
-
/**
|
|
28
|
-
* Computes the oclif-compatible data directory for @salesforce/b2c-cli.
|
|
29
|
-
* Used as a fallback when initializeStatefulStore() has not been called.
|
|
30
|
-
*/
|
|
31
|
-
function getDefaultDataDir() {
|
|
32
|
-
const home = homedir();
|
|
33
|
-
const name = '@salesforce/b2c-cli';
|
|
34
|
-
switch (platform()) {
|
|
35
|
-
case 'darwin':
|
|
36
|
-
return join(home, 'Library', 'Application Support', name);
|
|
37
|
-
case 'win32':
|
|
38
|
-
return join(process.env.LOCALAPPDATA ?? join(home, 'AppData', 'Local'), name);
|
|
39
|
-
default:
|
|
40
|
-
return join(process.env.XDG_DATA_HOME ?? join(home, '.local', 'share'), name);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
function getSessionFilePath() {
|
|
44
|
-
return join(storePath ?? getDefaultDataDir(), STATEFUL_AUTH_SESSION_STORE);
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Initialize the stateful store with the oclif data directory.
|
|
48
|
-
* Call this from BaseCommand.init() with this.config.dataDir so the session
|
|
49
|
-
* file is stored alongside other CLI data (e.g. ~/Library/Application Support/@salesforce/b2c-cli).
|
|
50
|
-
*/
|
|
51
|
-
export function initializeStatefulStore(dataDir) {
|
|
52
|
-
storePath = dataDir;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Reads the current stateful session from the JSON file.
|
|
56
|
-
* Returns null if no session file exists or the file is invalid.
|
|
57
|
-
*/
|
|
58
|
-
export function getStoredSession() {
|
|
59
|
-
const filePath = getSessionFilePath();
|
|
60
|
-
if (!existsSync(filePath)) {
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
try {
|
|
64
|
-
const data = JSON.parse(readFileSync(filePath, 'utf8'));
|
|
65
|
-
if (!data.clientId || !data.accessToken) {
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
return {
|
|
69
|
-
clientId: data.clientId,
|
|
70
|
-
accessToken: data.accessToken,
|
|
71
|
-
refreshToken: data.refreshToken ?? null,
|
|
72
|
-
renewBase: data.renewBase ?? null,
|
|
73
|
-
user: data.user ?? null,
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
catch {
|
|
77
|
-
return null;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Writes a session to the JSON file, creating the directory if needed.
|
|
82
|
-
*/
|
|
83
|
-
export function setStoredSession(session) {
|
|
84
|
-
const filePath = getSessionFilePath();
|
|
85
|
-
const dir = join(filePath, '..');
|
|
86
|
-
if (!existsSync(dir)) {
|
|
87
|
-
mkdirSync(dir, { recursive: true });
|
|
88
|
-
}
|
|
89
|
-
const data = {
|
|
90
|
-
clientId: session.clientId,
|
|
91
|
-
accessToken: session.accessToken,
|
|
92
|
-
refreshToken: session.refreshToken ?? null,
|
|
93
|
-
renewBase: session.renewBase ?? null,
|
|
94
|
-
user: session.user ?? null,
|
|
95
|
-
};
|
|
96
|
-
// Atomic write: write to temp file then rename so a concurrent reader (or a
|
|
97
|
-
// crashed writer) never observes a partially written JSON document.
|
|
98
|
-
const tmpPath = `${filePath}.${process.pid}.${Date.now()}.tmp`;
|
|
99
|
-
writeFileSync(tmpPath, JSON.stringify(data, null, 2), 'utf8');
|
|
100
|
-
renameSync(tmpPath, filePath);
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Clears the stored session by removing the session file.
|
|
104
|
-
*/
|
|
105
|
-
export function clearStoredSession() {
|
|
106
|
-
const filePath = getSessionFilePath();
|
|
107
|
-
if (existsSync(filePath)) {
|
|
108
|
-
try {
|
|
109
|
-
unlinkSync(filePath);
|
|
110
|
-
}
|
|
111
|
-
catch (err) {
|
|
112
|
-
getLogger().debug({ err, filePath }, '[StatefulAuth] Failed to remove session file');
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Checks whether the stored access token is present and valid: not expired
|
|
118
|
-
* (with a small buffer), optionally satisfies required scopes, and optionally
|
|
119
|
-
* matches the expected client ID.
|
|
120
|
-
* Does not perform network calls.
|
|
121
|
-
*
|
|
122
|
-
* @param session - Session from getStoredSession()
|
|
123
|
-
* @param requiredScopes - If provided, token must include all of these scopes
|
|
124
|
-
* @param expiryBufferSec - Seconds before exp to treat token as expired (default 60)
|
|
125
|
-
* @param requiredClientId - If provided, session clientId must match
|
|
126
|
-
* @returns true if token is present and valid for use
|
|
127
|
-
*/
|
|
128
|
-
export function isStatefulTokenValid(session, requiredScopes = [], expiryBufferSec = DEFAULT_EXPIRY_BUFFER_SEC, requiredClientId) {
|
|
129
|
-
const logger = getLogger();
|
|
130
|
-
if (requiredClientId && session.clientId !== requiredClientId) {
|
|
131
|
-
logger.debug({ storedClientId: session.clientId, requiredClientId }, '[StatefulAuth] Token client ID mismatch');
|
|
132
|
-
return false;
|
|
133
|
-
}
|
|
134
|
-
let info;
|
|
135
|
-
try {
|
|
136
|
-
info = decodeJwtTokenInfo(session.accessToken);
|
|
137
|
-
}
|
|
138
|
-
catch (error) {
|
|
139
|
-
logger.debug({ err: error }, '[StatefulAuth] Token invalid (e.g. not a JWT)');
|
|
140
|
-
return false;
|
|
141
|
-
}
|
|
142
|
-
if (info.expires.getTime() === 0) {
|
|
143
|
-
logger.debug('[StatefulAuth] Token has no exp claim; treating as invalid');
|
|
144
|
-
return false;
|
|
145
|
-
}
|
|
146
|
-
const nowSec = Math.floor(Date.now() / 1000);
|
|
147
|
-
const expSec = Math.floor(info.expires.getTime() / 1000);
|
|
148
|
-
if (nowSec >= expSec - expiryBufferSec) {
|
|
149
|
-
logger.debug('[StatefulAuth] Token missing or expired');
|
|
150
|
-
return false;
|
|
151
|
-
}
|
|
152
|
-
if (requiredScopes.length > 0 && !requiredScopes.every((s) => info.scopes.includes(s))) {
|
|
153
|
-
logger.debug({ requiredScopes, tokenScopes: info.scopes }, '[StatefulAuth] Token missing required scopes');
|
|
154
|
-
return false;
|
|
155
|
-
}
|
|
156
|
-
return true;
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Resets the store path (for tests). After calling this, the next operation
|
|
160
|
-
* will use the default data directory unless initializeStatefulStore() is called again.
|
|
161
|
-
* @internal
|
|
162
|
-
*/
|
|
163
|
-
export function resetStatefulStoreForTesting() {
|
|
164
|
-
storePath = null;
|
|
165
|
-
}
|
|
166
|
-
//# sourceMappingURL=stateful-store.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stateful-store.js","sourceRoot":"","sources":["../../../src/auth/stateful-store.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAC,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,aAAa,E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