@salesforce/b2c-tooling-sdk 1.7.0 → 1.8.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/cjs/config/dw-json.d.ts +2 -0
- package/dist/cjs/config/dw-json.js.map +1 -1
- package/dist/cjs/config/mapping.js +5 -0
- package/dist/cjs/config/mapping.js.map +1 -1
- package/dist/cjs/config/types.d.ts +2 -0
- package/dist/cjs/operations/code/download.d.ts +17 -6
- package/dist/cjs/operations/code/download.js +189 -87
- package/dist/cjs/operations/code/download.js.map +1 -1
- package/dist/cjs/operations/code/index.d.ts +3 -1
- package/dist/cjs/operations/code/index.js +3 -1
- package/dist/cjs/operations/code/index.js.map +1 -1
- package/dist/cjs/operations/code/upload-files.d.ts +47 -0
- package/dist/cjs/operations/code/upload-files.js +116 -0
- package/dist/cjs/operations/code/upload-files.js.map +1 -0
- package/dist/cjs/operations/code/watch.js +18 -92
- package/dist/cjs/operations/code/watch.js.map +1 -1
- package/dist/esm/config/dw-json.d.ts +2 -0
- package/dist/esm/config/dw-json.js.map +1 -1
- package/dist/esm/config/mapping.js +5 -0
- package/dist/esm/config/mapping.js.map +1 -1
- package/dist/esm/config/types.d.ts +2 -0
- package/dist/esm/operations/code/download.d.ts +17 -6
- package/dist/esm/operations/code/download.js +189 -87
- package/dist/esm/operations/code/download.js.map +1 -1
- package/dist/esm/operations/code/index.d.ts +3 -1
- package/dist/esm/operations/code/index.js +3 -1
- package/dist/esm/operations/code/index.js.map +1 -1
- package/dist/esm/operations/code/upload-files.d.ts +47 -0
- package/dist/esm/operations/code/upload-files.js +116 -0
- package/dist/esm/operations/code/upload-files.js.map +1 -0
- package/dist/esm/operations/code/watch.js +18 -92
- package/dist/esm/operations/code/watch.js.map +1 -1
- package/package.json +1 -1
|
@@ -11,14 +11,169 @@ import { getActiveCodeVersion } from './versions.js';
|
|
|
11
11
|
const ZIP_BODY = new URLSearchParams({ method: 'ZIP' }).toString();
|
|
12
12
|
// 10 minutes — server-side zipping and large downloads can take a long time
|
|
13
13
|
const LONG_OPERATION_TIMEOUT_MS = 600_000;
|
|
14
|
+
// Progress helper: fires immediately (0s) then every 5s until stopped
|
|
15
|
+
const PROGRESS_INTERVAL_MS = 5_000;
|
|
16
|
+
function startProgress(phase, onProgress) {
|
|
17
|
+
const start = Date.now();
|
|
18
|
+
onProgress?.({ phase, elapsedSeconds: 0 });
|
|
19
|
+
if (!onProgress)
|
|
20
|
+
return () => { };
|
|
21
|
+
const interval = setInterval(() => {
|
|
22
|
+
onProgress({ phase, elapsedSeconds: Math.round((Date.now() - start) / 1000) });
|
|
23
|
+
}, PROGRESS_INTERVAL_MS);
|
|
24
|
+
return () => clearInterval(interval);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Resolves code version from instance config or OCAPI auto-discovery.
|
|
28
|
+
*/
|
|
29
|
+
async function resolveCodeVersion(instance) {
|
|
30
|
+
const logger = getLogger();
|
|
31
|
+
let codeVersion = instance.config.codeVersion;
|
|
32
|
+
if (!codeVersion) {
|
|
33
|
+
logger.debug('No code version configured, attempting to discover active version...');
|
|
34
|
+
try {
|
|
35
|
+
const activeVersion = await getActiveCodeVersion(instance);
|
|
36
|
+
if (activeVersion?.id) {
|
|
37
|
+
codeVersion = activeVersion.id;
|
|
38
|
+
instance.config.codeVersion = codeVersion;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
logger.debug({ error }, 'Failed to discover active code version');
|
|
43
|
+
}
|
|
44
|
+
if (!codeVersion) {
|
|
45
|
+
throw new Error('Code version required for download. Configure --code-version or ensure OAuth credentials are available for auto-discovery.');
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return codeVersion;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Extracts files from a ZIP archive to disk.
|
|
52
|
+
*
|
|
53
|
+
* @param zip - Loaded JSZip instance
|
|
54
|
+
* @param options - Extraction options
|
|
55
|
+
* @param options.stripPrefix - Number of path segments to strip from ZIP entry paths (e.g. 1 to remove codeVersion, 2 to remove codeVersion + cartridgeName)
|
|
56
|
+
* @param options.outputDirectory - Base output directory
|
|
57
|
+
* @param options.mirror - Map of cartridge names to local paths for mirror extraction
|
|
58
|
+
* @param options.include - Cartridge names to include
|
|
59
|
+
* @param options.exclude - Cartridge names to exclude
|
|
60
|
+
* @returns Set of extracted cartridge names
|
|
61
|
+
*/
|
|
62
|
+
async function extractZip(zip, options) {
|
|
63
|
+
const extractedCartridges = new Set();
|
|
64
|
+
const entries = Object.values(zip.files).filter((entry) => !entry.dir);
|
|
65
|
+
for (const entry of entries) {
|
|
66
|
+
const parts = entry.name.split('/');
|
|
67
|
+
if (parts.length < options.stripPrefix + 1) {
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
// Strip the prefix segments
|
|
71
|
+
for (let i = 0; i < options.stripPrefix; i++) {
|
|
72
|
+
parts.shift();
|
|
73
|
+
}
|
|
74
|
+
// Determine cartridge name: either from the next segment or from the option
|
|
75
|
+
const cartridgeName = options.cartridgeName ?? parts.shift();
|
|
76
|
+
const relativePath = options.cartridgeName ? parts.join('/') : parts.join('/');
|
|
77
|
+
// Apply filters
|
|
78
|
+
if (options.include?.length && !options.include.includes(cartridgeName)) {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (options.exclude?.length && options.exclude.includes(cartridgeName)) {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
let targetPath;
|
|
85
|
+
if (options.mirror?.has(cartridgeName)) {
|
|
86
|
+
targetPath = path.join(options.mirror.get(cartridgeName), relativePath);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
targetPath = path.join(options.outputDirectory, cartridgeName, relativePath);
|
|
90
|
+
}
|
|
91
|
+
// Preserve existing file permissions
|
|
92
|
+
let existingMode = null;
|
|
93
|
+
try {
|
|
94
|
+
const stat = await fs.promises.stat(targetPath);
|
|
95
|
+
existingMode = stat.mode;
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
// File doesn't exist yet
|
|
99
|
+
}
|
|
100
|
+
await fs.promises.mkdir(path.dirname(targetPath), { recursive: true });
|
|
101
|
+
const content = await entry.async('nodebuffer');
|
|
102
|
+
await fs.promises.writeFile(targetPath, content);
|
|
103
|
+
if (existingMode !== null) {
|
|
104
|
+
await fs.promises.chmod(targetPath, existingMode);
|
|
105
|
+
}
|
|
106
|
+
extractedCartridges.add(cartridgeName);
|
|
107
|
+
}
|
|
108
|
+
return extractedCartridges;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Downloads a single cartridge from an instance via WebDAV.
|
|
112
|
+
*
|
|
113
|
+
* This is more efficient than downloading the entire code version when only
|
|
114
|
+
* one cartridge is needed, as it ZIPs only the cartridge subdirectory on the server.
|
|
115
|
+
*
|
|
116
|
+
* @param instance - B2C instance to download from
|
|
117
|
+
* @param codeVersion - Code version containing the cartridge
|
|
118
|
+
* @param cartridgeName - Name of the cartridge to download
|
|
119
|
+
* @param outputPath - Local path to extract the cartridge into
|
|
120
|
+
* @param onProgress - Optional progress callback
|
|
121
|
+
*/
|
|
122
|
+
export async function downloadSingleCartridge(instance, codeVersion, cartridgeName, outputPath, onProgress) {
|
|
123
|
+
const logger = getLogger();
|
|
124
|
+
const webdav = instance.webdav;
|
|
125
|
+
const cartridgePath = `Cartridges/${codeVersion}/${cartridgeName}`;
|
|
126
|
+
const zipPath = `${cartridgePath}.zip`;
|
|
127
|
+
let stopProgress = startProgress('zipping', onProgress);
|
|
128
|
+
logger.debug({ cartridgeName, codeVersion }, 'Requesting server-side zip for single cartridge...');
|
|
129
|
+
const zipResponse = await webdav.request(cartridgePath, {
|
|
130
|
+
method: 'POST',
|
|
131
|
+
body: ZIP_BODY,
|
|
132
|
+
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
133
|
+
signal: AbortSignal.timeout(LONG_OPERATION_TIMEOUT_MS),
|
|
134
|
+
});
|
|
135
|
+
stopProgress();
|
|
136
|
+
if (!zipResponse.ok) {
|
|
137
|
+
const text = await zipResponse.text();
|
|
138
|
+
throw new Error(`Failed to create server-side zip: ${zipResponse.status} ${zipResponse.statusText} - ${text}`);
|
|
139
|
+
}
|
|
140
|
+
stopProgress = startProgress('downloading', onProgress);
|
|
141
|
+
const dlResponse = await webdav.request(zipPath, {
|
|
142
|
+
method: 'GET',
|
|
143
|
+
signal: AbortSignal.timeout(LONG_OPERATION_TIMEOUT_MS),
|
|
144
|
+
});
|
|
145
|
+
if (!dlResponse.ok) {
|
|
146
|
+
stopProgress();
|
|
147
|
+
throw new Error(`Failed to download zip: ${dlResponse.status} ${dlResponse.statusText}`);
|
|
148
|
+
}
|
|
149
|
+
const buffer = await dlResponse.arrayBuffer();
|
|
150
|
+
stopProgress();
|
|
151
|
+
logger.debug({ size: buffer.byteLength }, `Archive downloaded: ${buffer.byteLength} bytes`);
|
|
152
|
+
// Cleanup server-side zip (best effort)
|
|
153
|
+
onProgress?.({ phase: 'cleanup', elapsedSeconds: 0 });
|
|
154
|
+
try {
|
|
155
|
+
await webdav.delete(zipPath);
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
logger.warn({ error, zipPath }, 'Failed to clean up server-side zip (non-fatal)');
|
|
159
|
+
}
|
|
160
|
+
// Extract
|
|
161
|
+
onProgress?.({ phase: 'extracting', elapsedSeconds: 0 });
|
|
162
|
+
const zip = await JSZip.loadAsync(buffer);
|
|
163
|
+
// Single cartridge ZIP contains: cartridgeName/relative/path...
|
|
164
|
+
await extractZip(zip, {
|
|
165
|
+
stripPrefix: 1,
|
|
166
|
+
outputDirectory: path.dirname(outputPath),
|
|
167
|
+
cartridgeName,
|
|
168
|
+
});
|
|
169
|
+
logger.debug({ cartridgeName, codeVersion }, `Downloaded cartridge ${cartridgeName}`);
|
|
170
|
+
}
|
|
14
171
|
/**
|
|
15
172
|
* Downloads cartridges from an instance via WebDAV.
|
|
16
173
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* 3. Cleans up the server-side zip (best-effort)
|
|
21
|
-
* 4. Extracts cartridges locally with optional filtering
|
|
174
|
+
* When `include` specifies cartridges, each is downloaded individually using
|
|
175
|
+
* per-cartridge server-side zipping for efficiency. When downloading all
|
|
176
|
+
* cartridges (no include filter), the entire code version is zipped at once.
|
|
22
177
|
*
|
|
23
178
|
* If `instance.config.codeVersion` is not set, attempts to discover the active
|
|
24
179
|
* code version via OCAPI. If that also fails, throws an error.
|
|
@@ -34,7 +189,7 @@ const LONG_OPERATION_TIMEOUT_MS = 600_000;
|
|
|
34
189
|
* // Download all cartridges
|
|
35
190
|
* const result = await downloadCartridges(instance, './output');
|
|
36
191
|
*
|
|
37
|
-
* // Download specific cartridges
|
|
192
|
+
* // Download specific cartridges (efficient per-cartridge download)
|
|
38
193
|
* const result = await downloadCartridges(instance, './output', {
|
|
39
194
|
* include: ['app_storefront_base'],
|
|
40
195
|
* });
|
|
@@ -46,41 +201,28 @@ const LONG_OPERATION_TIMEOUT_MS = 600_000;
|
|
|
46
201
|
*/
|
|
47
202
|
export async function downloadCartridges(instance, outputDirectory, options = {}) {
|
|
48
203
|
const logger = getLogger();
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
throw new Error('Code version required for download. Configure --code-version or ensure OAuth credentials are available for auto-discovery.');
|
|
204
|
+
const codeVersion = await resolveCodeVersion(instance);
|
|
205
|
+
const resolvedOutput = path.resolve(outputDirectory);
|
|
206
|
+
const { include, exclude, mirror, onProgress } = options;
|
|
207
|
+
// When specific cartridges are requested, download each individually
|
|
208
|
+
if (include?.length) {
|
|
209
|
+
const allExtracted = new Set();
|
|
210
|
+
for (const cartridgeName of include) {
|
|
211
|
+
if (exclude?.length && exclude.includes(cartridgeName))
|
|
212
|
+
continue;
|
|
213
|
+
const outputPath = mirror?.has(cartridgeName)
|
|
214
|
+
? mirror.get(cartridgeName)
|
|
215
|
+
: path.join(resolvedOutput, cartridgeName);
|
|
216
|
+
await downloadSingleCartridge(instance, codeVersion, cartridgeName, outputPath, onProgress);
|
|
217
|
+
allExtracted.add(cartridgeName);
|
|
64
218
|
}
|
|
219
|
+
const cartridgeList = [...allExtracted].sort();
|
|
220
|
+
return { cartridges: cartridgeList, codeVersion, outputDirectory: resolvedOutput };
|
|
65
221
|
}
|
|
222
|
+
// Full code version download
|
|
66
223
|
const webdav = instance.webdav;
|
|
67
224
|
const zipPath = `Cartridges/${codeVersion}.zip`;
|
|
68
|
-
|
|
69
|
-
const { onProgress } = options;
|
|
70
|
-
// Progress helper: fires immediately (0s) then every 5s until stopped
|
|
71
|
-
const PROGRESS_INTERVAL_MS = 5_000;
|
|
72
|
-
function startProgress(phase) {
|
|
73
|
-
const start = Date.now();
|
|
74
|
-
onProgress?.({ phase, elapsedSeconds: 0 });
|
|
75
|
-
if (!onProgress)
|
|
76
|
-
return () => { };
|
|
77
|
-
const interval = setInterval(() => {
|
|
78
|
-
onProgress({ phase, elapsedSeconds: Math.round((Date.now() - start) / 1000) });
|
|
79
|
-
}, PROGRESS_INTERVAL_MS);
|
|
80
|
-
return () => clearInterval(interval);
|
|
81
|
-
}
|
|
82
|
-
// Step 1: Trigger server-side zip (can take several minutes for large code versions)
|
|
83
|
-
let stopProgress = startProgress('zipping');
|
|
225
|
+
let stopProgress = startProgress('zipping', onProgress);
|
|
84
226
|
logger.debug({ codeVersion }, 'Requesting server-side zip...');
|
|
85
227
|
const zipResponse = await webdav.request(`Cartridges/${codeVersion}`, {
|
|
86
228
|
method: 'POST',
|
|
@@ -96,8 +238,7 @@ export async function downloadCartridges(instance, outputDirectory, options = {}
|
|
|
96
238
|
throw new Error(`Failed to create server-side zip: ${zipResponse.status} ${zipResponse.statusText} - ${text}`);
|
|
97
239
|
}
|
|
98
240
|
logger.debug('Server-side zip created');
|
|
99
|
-
|
|
100
|
-
stopProgress = startProgress('downloading');
|
|
241
|
+
stopProgress = startProgress('downloading', onProgress);
|
|
101
242
|
logger.debug({ zipPath }, 'Downloading zip archive...');
|
|
102
243
|
const downloadResponse = await webdav.request(zipPath, {
|
|
103
244
|
method: 'GET',
|
|
@@ -110,7 +251,7 @@ export async function downloadCartridges(instance, outputDirectory, options = {}
|
|
|
110
251
|
const buffer = await downloadResponse.arrayBuffer();
|
|
111
252
|
stopProgress();
|
|
112
253
|
logger.debug({ size: buffer.byteLength }, `Archive downloaded: ${buffer.byteLength} bytes`);
|
|
113
|
-
//
|
|
254
|
+
// Cleanup server-side zip (best-effort)
|
|
114
255
|
onProgress?.({ phase: 'cleanup', elapsedSeconds: 0 });
|
|
115
256
|
try {
|
|
116
257
|
await webdav.delete(zipPath);
|
|
@@ -119,56 +260,17 @@ export async function downloadCartridges(instance, outputDirectory, options = {}
|
|
|
119
260
|
catch (error) {
|
|
120
261
|
logger.warn({ error, zipPath }, 'Failed to clean up server-side zip (non-fatal)');
|
|
121
262
|
}
|
|
122
|
-
//
|
|
263
|
+
// Extract
|
|
123
264
|
onProgress?.({ phase: 'extracting', elapsedSeconds: 0 });
|
|
124
265
|
logger.debug('Extracting archive...');
|
|
125
266
|
const zip = await JSZip.loadAsync(buffer);
|
|
126
|
-
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
// Format: {codeVersion}/{cartridgeName}/{relativePath...}
|
|
135
|
-
parts.shift(); // remove codeVersion
|
|
136
|
-
const cartridgeName = parts.shift();
|
|
137
|
-
const relativePath = parts.join('/');
|
|
138
|
-
// Apply filters
|
|
139
|
-
if (include?.length && !include.includes(cartridgeName)) {
|
|
140
|
-
continue;
|
|
141
|
-
}
|
|
142
|
-
if (exclude?.length && exclude.includes(cartridgeName)) {
|
|
143
|
-
continue;
|
|
144
|
-
}
|
|
145
|
-
let targetPath;
|
|
146
|
-
if (mirror?.has(cartridgeName)) {
|
|
147
|
-
targetPath = path.join(mirror.get(cartridgeName), relativePath);
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
targetPath = path.join(resolvedOutput, cartridgeName, relativePath);
|
|
151
|
-
}
|
|
152
|
-
// Preserve existing file permissions
|
|
153
|
-
let existingMode = null;
|
|
154
|
-
try {
|
|
155
|
-
const stat = await fs.promises.stat(targetPath);
|
|
156
|
-
existingMode = stat.mode;
|
|
157
|
-
}
|
|
158
|
-
catch {
|
|
159
|
-
// File doesn't exist yet
|
|
160
|
-
}
|
|
161
|
-
// Ensure parent directory exists
|
|
162
|
-
await fs.promises.mkdir(path.dirname(targetPath), { recursive: true });
|
|
163
|
-
// Write file
|
|
164
|
-
const content = await entry.async('nodebuffer');
|
|
165
|
-
await fs.promises.writeFile(targetPath, content);
|
|
166
|
-
// Restore permissions if file existed
|
|
167
|
-
if (existingMode !== null) {
|
|
168
|
-
await fs.promises.chmod(targetPath, existingMode);
|
|
169
|
-
}
|
|
170
|
-
extractedCartridges.add(cartridgeName);
|
|
171
|
-
}
|
|
267
|
+
// Full code version ZIP: {codeVersion}/{cartridgeName}/{relativePath...}
|
|
268
|
+
const extractedCartridges = await extractZip(zip, {
|
|
269
|
+
stripPrefix: 1,
|
|
270
|
+
outputDirectory: resolvedOutput,
|
|
271
|
+
mirror,
|
|
272
|
+
exclude,
|
|
273
|
+
});
|
|
172
274
|
const cartridgeList = [...extractedCartridges].sort();
|
|
173
275
|
logger.debug({ server: instance.config.hostname, codeVersion, cartridgeCount: cartridgeList.length }, `Downloaded ${cartridgeList.length} cartridge(s) from ${instance.config.hostname}`);
|
|
174
276
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"download.js","sourceRoot":"","sources":["../../../../src/operations/code/download.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,IAAI,MA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E,gDAAgD,CAAC,CAAC;IAClF,CAAC;IAED,UAAU;IACV,UAAU,EAAE,CAAC,EAAC,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,CAAC,EAAC,CAAC,CAAC;IACvD,MAAM,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;IACtC,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAE1C,yEAAyE;IACzE,MAAM,mBAAmB,GAAG,MAAM,UAAU,CAAC,GAAG,EAAE;QAChD,WAAW,EAAE,CAAC;QACd,eAAe,EAAE,cAAc;QAC/B,MAAM;QACN,OAAO;KACR,CAAC,CAAC;IAEH,MAAM,aAAa,GAAG,CAAC,GAAG,mBAAmB,CAAC,CAAC,IAAI,EAAE,CAAC;IACtD,MAAM,CAAC,KAAK,CACV,EAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,WAAW,EAAE,cAAc,EAAE,aAAa,CAAC,MAAM,EAAC,EACrF,cAAc,aAAa,CAAC,MAAM,sBAAsB,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,CACnF,CAAC;IAEF,OAAO;QACL,UAAU,EAAE,aAAa;QACzB,WAAW;QACX,eAAe,EAAE,cAAc;KAChC,CAAC;AACJ,CAAC"}
|
|
@@ -66,7 +66,9 @@ export { listCodeVersions, getActiveCodeVersion, activateCodeVersion, reloadCode
|
|
|
66
66
|
export type { CodeVersion, CodeVersionResult } from './versions.js';
|
|
67
67
|
export { findAndDeployCartridges, uploadCartridges, deleteCartridges } from './deploy.js';
|
|
68
68
|
export type { DeployOptions, DeployResult, UploadOptions, UploadProgressInfo } from './deploy.js';
|
|
69
|
-
export { downloadCartridges } from './download.js';
|
|
69
|
+
export { downloadCartridges, downloadSingleCartridge } from './download.js';
|
|
70
70
|
export type { DownloadOptions, DownloadProgressInfo, DownloadResult } from './download.js';
|
|
71
|
+
export { uploadFiles, fileToCartridgePath } from './upload-files.js';
|
|
72
|
+
export type { FileChange, UploadFilesOptions } from './upload-files.js';
|
|
71
73
|
export { watchCartridges } from './watch.js';
|
|
72
74
|
export type { WatchOptions, WatchResult } from './watch.js';
|
|
@@ -72,7 +72,9 @@ export { listCodeVersions, getActiveCodeVersion, activateCodeVersion, reloadCode
|
|
|
72
72
|
// Deployment
|
|
73
73
|
export { findAndDeployCartridges, uploadCartridges, deleteCartridges } from './deploy.js';
|
|
74
74
|
// Download
|
|
75
|
-
export { downloadCartridges } from './download.js';
|
|
75
|
+
export { downloadCartridges, downloadSingleCartridge } from './download.js';
|
|
76
|
+
// File upload pipeline
|
|
77
|
+
export { uploadFiles, fileToCartridgePath } from './upload-files.js';
|
|
76
78
|
// Watch
|
|
77
79
|
export { watchCartridges } from './watch.js';
|
|
78
80
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/operations/code/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AAEH,sBAAsB;AACtB,OAAO,EAAC,cAAc,EAAC,MAAM,iBAAiB,CAAC;AAG/C,0BAA0B;AAC1B,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,eAAe,CAAC;AAGvB,aAAa;AACb,OAAO,EAAC,uBAAuB,EAAE,gBAAgB,EAAE,gBAAgB,EAAC,MAAM,aAAa,CAAC;AAGxF,WAAW;AACX,OAAO,EAAC,kBAAkB,EAAC,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/operations/code/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AAEH,sBAAsB;AACtB,OAAO,EAAC,cAAc,EAAC,MAAM,iBAAiB,CAAC;AAG/C,0BAA0B;AAC1B,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,eAAe,CAAC;AAGvB,aAAa;AACb,OAAO,EAAC,uBAAuB,EAAE,gBAAgB,EAAE,gBAAgB,EAAC,MAAM,aAAa,CAAC;AAGxF,WAAW;AACX,OAAO,EAAC,kBAAkB,EAAE,uBAAuB,EAAC,MAAM,eAAe,CAAC;AAG1E,uBAAuB;AACvB,OAAO,EAAC,WAAW,EAAE,mBAAmB,EAAC,MAAM,mBAAmB,CAAC;AAGnE,QAAQ;AACR,OAAO,EAAC,eAAe,EAAC,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { B2CInstance } from '../../instance/index.js';
|
|
2
|
+
import type { CartridgeMapping } from './cartridges.js';
|
|
3
|
+
/**
|
|
4
|
+
* Represents a file to upload or delete, with source and destination paths.
|
|
5
|
+
*/
|
|
6
|
+
export interface FileChange {
|
|
7
|
+
/** Absolute path to the file on disk */
|
|
8
|
+
src: string;
|
|
9
|
+
/** Cartridge-relative destination path (e.g. "cartridgeName/path/to/file.js") */
|
|
10
|
+
dest: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Callbacks for file upload/delete operations.
|
|
14
|
+
*/
|
|
15
|
+
export interface UploadFilesOptions {
|
|
16
|
+
/** Called after files are successfully uploaded */
|
|
17
|
+
onUpload?: (files: string[]) => void;
|
|
18
|
+
/** Called after files are successfully deleted */
|
|
19
|
+
onDelete?: (files: string[]) => void;
|
|
20
|
+
/** Called when an error occurs */
|
|
21
|
+
onError?: (error: Error) => void;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Maps an absolute file path to its cartridge-relative destination.
|
|
25
|
+
*
|
|
26
|
+
* @param absolutePath - The absolute path to a file
|
|
27
|
+
* @param cartridges - The list of discovered cartridge mappings
|
|
28
|
+
* @returns The file change with src and dest, or undefined if the path is not inside any cartridge
|
|
29
|
+
*/
|
|
30
|
+
export declare function fileToCartridgePath(absolutePath: string, cartridges: CartridgeMapping[]): FileChange | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Uploads and deletes files on an instance via WebDAV.
|
|
33
|
+
*
|
|
34
|
+
* This is the core batch-upload pipeline used by both `watchCartridges` and
|
|
35
|
+
* the VS Code extension. It:
|
|
36
|
+
* 1. Filters out non-existent upload files
|
|
37
|
+
* 2. Creates a ZIP archive of upload files
|
|
38
|
+
* 3. Uploads via WebDAV PUT and unzips on server
|
|
39
|
+
* 4. Deletes files (skipping any that were also uploaded in the same batch)
|
|
40
|
+
*
|
|
41
|
+
* @param instance - B2C instance to sync to
|
|
42
|
+
* @param codeVersion - Code version to deploy to
|
|
43
|
+
* @param uploads - Files to upload
|
|
44
|
+
* @param deletes - Files to delete
|
|
45
|
+
* @param options - Callbacks for upload/delete/error events
|
|
46
|
+
*/
|
|
47
|
+
export declare function uploadFiles(instance: B2CInstance, codeVersion: string, uploads: FileChange[], deletes: FileChange[], options?: UploadFilesOptions): Promise<void>;
|
|
@@ -0,0 +1,116 @@
|
|
|
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 path from 'node:path';
|
|
7
|
+
import fs from 'node:fs';
|
|
8
|
+
import JSZip from 'jszip';
|
|
9
|
+
import { getLogger } from '../../logging/logger.js';
|
|
10
|
+
const UNZIP_BODY = new URLSearchParams({ method: 'UNZIP' }).toString();
|
|
11
|
+
/**
|
|
12
|
+
* Maps an absolute file path to its cartridge-relative destination.
|
|
13
|
+
*
|
|
14
|
+
* @param absolutePath - The absolute path to a file
|
|
15
|
+
* @param cartridges - The list of discovered cartridge mappings
|
|
16
|
+
* @returns The file change with src and dest, or undefined if the path is not inside any cartridge
|
|
17
|
+
*/
|
|
18
|
+
export function fileToCartridgePath(absolutePath, cartridges) {
|
|
19
|
+
const cartridge = cartridges.find((c) => absolutePath.startsWith(c.src));
|
|
20
|
+
if (!cartridge) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
const relativePath = absolutePath.substring(cartridge.src.length);
|
|
24
|
+
const destPath = path.join(cartridge.dest, relativePath);
|
|
25
|
+
return {
|
|
26
|
+
src: absolutePath,
|
|
27
|
+
dest: destPath,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Uploads and deletes files on an instance via WebDAV.
|
|
32
|
+
*
|
|
33
|
+
* This is the core batch-upload pipeline used by both `watchCartridges` and
|
|
34
|
+
* the VS Code extension. It:
|
|
35
|
+
* 1. Filters out non-existent upload files
|
|
36
|
+
* 2. Creates a ZIP archive of upload files
|
|
37
|
+
* 3. Uploads via WebDAV PUT and unzips on server
|
|
38
|
+
* 4. Deletes files (skipping any that were also uploaded in the same batch)
|
|
39
|
+
*
|
|
40
|
+
* @param instance - B2C instance to sync to
|
|
41
|
+
* @param codeVersion - Code version to deploy to
|
|
42
|
+
* @param uploads - Files to upload
|
|
43
|
+
* @param deletes - Files to delete
|
|
44
|
+
* @param options - Callbacks for upload/delete/error events
|
|
45
|
+
*/
|
|
46
|
+
export async function uploadFiles(instance, codeVersion, uploads, deletes, options) {
|
|
47
|
+
const logger = getLogger();
|
|
48
|
+
const webdav = instance.webdav;
|
|
49
|
+
const webdavLocation = `Cartridges/${codeVersion}`;
|
|
50
|
+
const validUploadFiles = uploads.filter((f) => {
|
|
51
|
+
if (!fs.existsSync(f.src)) {
|
|
52
|
+
logger.debug({ file: f.src }, 'Skipping missing file');
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
return true;
|
|
56
|
+
});
|
|
57
|
+
if (validUploadFiles.length > 0) {
|
|
58
|
+
const uploadPath = `${webdavLocation}/_upload-${Date.now()}.zip`;
|
|
59
|
+
try {
|
|
60
|
+
const zip = new JSZip();
|
|
61
|
+
for (const f of validUploadFiles) {
|
|
62
|
+
try {
|
|
63
|
+
const content = await fs.promises.readFile(f.src);
|
|
64
|
+
zip.file(f.dest, content);
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
logger.warn({ file: f.src, error }, 'Failed to add file to archive');
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const buffer = await zip.generateAsync({
|
|
71
|
+
type: 'nodebuffer',
|
|
72
|
+
compression: 'DEFLATE',
|
|
73
|
+
compressionOptions: { level: 5 },
|
|
74
|
+
});
|
|
75
|
+
await webdav.put(uploadPath, buffer, 'application/zip');
|
|
76
|
+
logger.debug({ uploadPath }, 'Archive uploaded');
|
|
77
|
+
const response = await webdav.request(uploadPath, {
|
|
78
|
+
method: 'POST',
|
|
79
|
+
body: UNZIP_BODY,
|
|
80
|
+
headers: {
|
|
81
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
if (!response.ok) {
|
|
85
|
+
throw new Error(`Unzip failed: ${response.status}`);
|
|
86
|
+
}
|
|
87
|
+
await webdav.delete(uploadPath);
|
|
88
|
+
logger.debug({ fileCount: validUploadFiles.length, server: instance.config.hostname }, `Uploaded ${validUploadFiles.length} file(s)`);
|
|
89
|
+
options?.onUpload?.(validUploadFiles.map((f) => f.dest));
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
93
|
+
logger.error({ error: err }, `Upload error: ${err.message}`);
|
|
94
|
+
options?.onError?.(err);
|
|
95
|
+
throw err;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
// Skip deletes for any file that was also uploaded in this batch (disk state wins)
|
|
99
|
+
const uploadedPaths = new Set(validUploadFiles.map((f) => f.dest));
|
|
100
|
+
const filesToDeleteFiltered = deletes.filter((f) => !uploadedPaths.has(f.dest));
|
|
101
|
+
if (filesToDeleteFiltered.length > 0) {
|
|
102
|
+
logger.debug({ fileCount: filesToDeleteFiltered.length }, `Deleting ${filesToDeleteFiltered.length} file(s)`);
|
|
103
|
+
for (const f of filesToDeleteFiltered) {
|
|
104
|
+
const deletePath = `${webdavLocation}/${f.dest}`;
|
|
105
|
+
try {
|
|
106
|
+
await webdav.delete(deletePath);
|
|
107
|
+
logger.info({ path: deletePath }, `Deleted: ${deletePath}`);
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
logger.debug({ path: deletePath, error }, `Failed to delete ${deletePath}`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
options?.onDelete?.(filesToDeleteFiltered.map((f) => f.dest));
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=upload-files.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upload-files.js","sourceRoot":"","sources":["../../../../src/operations/code/upload-files.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAC,SAAS,EAAC,MAAM,yBAAyB,CAAC;AAGlD,MAAM,UAAU,GAAG,IAAI,eAAe,CAAC,EAAC,MAAM,EAAE,OAAO,EAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;AAwBrE;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAAC,YAAoB,EAAE,UAA8B;IACtF,MAAM,SAAS,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAEzE,IAAI,CAAC,SAAS,EAAE,CA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