@salesforce/b2c-tooling-sdk 1.1.0 → 1.3.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.
Files changed (59) hide show
  1. package/dist/cjs/operations/code/watch.js +98 -75
  2. package/dist/cjs/operations/code/watch.js.map +1 -1
  3. package/dist/cjs/operations/debug/dap-adapter.d.ts +72 -0
  4. package/dist/cjs/operations/debug/dap-adapter.js +505 -0
  5. package/dist/cjs/operations/debug/dap-adapter.js.map +1 -0
  6. package/dist/cjs/operations/debug/debug-session.d.ts +51 -0
  7. package/dist/cjs/operations/debug/debug-session.js +219 -0
  8. package/dist/cjs/operations/debug/debug-session.js.map +1 -0
  9. package/dist/cjs/operations/debug/index.d.ts +17 -0
  10. package/dist/cjs/operations/debug/index.js +19 -0
  11. package/dist/cjs/operations/debug/index.js.map +1 -0
  12. package/dist/cjs/operations/debug/sdapi-client.d.ts +44 -0
  13. package/dist/cjs/operations/debug/sdapi-client.js +169 -0
  14. package/dist/cjs/operations/debug/sdapi-client.js.map +1 -0
  15. package/dist/cjs/operations/debug/source-mapping.d.ts +13 -0
  16. package/dist/cjs/operations/debug/source-mapping.js +57 -0
  17. package/dist/cjs/operations/debug/source-mapping.js.map +1 -0
  18. package/dist/cjs/operations/debug/types.d.ts +95 -0
  19. package/dist/cjs/operations/debug/types.js +2 -0
  20. package/dist/cjs/operations/debug/types.js.map +1 -0
  21. package/dist/cjs/operations/debug/variable-store.d.ts +35 -0
  22. package/dist/cjs/operations/debug/variable-store.js +52 -0
  23. package/dist/cjs/operations/debug/variable-store.js.map +1 -0
  24. package/dist/cjs/skills/agents.d.ts +1 -0
  25. package/dist/cjs/skills/agents.js +45 -4
  26. package/dist/cjs/skills/agents.js.map +1 -1
  27. package/dist/cjs/skills/installer.js +1 -0
  28. package/dist/cjs/skills/installer.js.map +1 -1
  29. package/dist/cjs/skills/types.d.ts +3 -1
  30. package/dist/esm/operations/code/watch.js +98 -75
  31. package/dist/esm/operations/code/watch.js.map +1 -1
  32. package/dist/esm/operations/debug/dap-adapter.d.ts +72 -0
  33. package/dist/esm/operations/debug/dap-adapter.js +505 -0
  34. package/dist/esm/operations/debug/dap-adapter.js.map +1 -0
  35. package/dist/esm/operations/debug/debug-session.d.ts +51 -0
  36. package/dist/esm/operations/debug/debug-session.js +219 -0
  37. package/dist/esm/operations/debug/debug-session.js.map +1 -0
  38. package/dist/esm/operations/debug/index.d.ts +17 -0
  39. package/dist/esm/operations/debug/index.js +19 -0
  40. package/dist/esm/operations/debug/index.js.map +1 -0
  41. package/dist/esm/operations/debug/sdapi-client.d.ts +44 -0
  42. package/dist/esm/operations/debug/sdapi-client.js +169 -0
  43. package/dist/esm/operations/debug/sdapi-client.js.map +1 -0
  44. package/dist/esm/operations/debug/source-mapping.d.ts +13 -0
  45. package/dist/esm/operations/debug/source-mapping.js +57 -0
  46. package/dist/esm/operations/debug/source-mapping.js.map +1 -0
  47. package/dist/esm/operations/debug/types.d.ts +95 -0
  48. package/dist/esm/operations/debug/types.js +2 -0
  49. package/dist/esm/operations/debug/types.js.map +1 -0
  50. package/dist/esm/operations/debug/variable-store.d.ts +35 -0
  51. package/dist/esm/operations/debug/variable-store.js +52 -0
  52. package/dist/esm/operations/debug/variable-store.js.map +1 -0
  53. package/dist/esm/skills/agents.d.ts +1 -0
  54. package/dist/esm/skills/agents.js +45 -4
  55. package/dist/esm/skills/agents.js.map +1 -1
  56. package/dist/esm/skills/installer.js +1 -0
  57. package/dist/esm/skills/installer.js.map +1 -1
  58. package/dist/esm/skills/types.d.ts +3 -1
  59. package/package.json +14 -3
@@ -0,0 +1,219 @@
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
+ * Debug session manager for the SDAPI.
8
+ *
9
+ * Manages the debugger lifecycle, polls for halted threads, and sends periodic
10
+ * keepalive resets to prevent the 60-second halt timeout. State changes are
11
+ * communicated via callbacks.
12
+ *
13
+ * @module operations/debug/debug-session
14
+ */
15
+ import { getLogger } from '../../logging/logger.js';
16
+ import { SdapiClient, SdapiError } from './sdapi-client.js';
17
+ const DEFAULT_POLL_INTERVAL = 500;
18
+ const DEFAULT_KEEPALIVE_INTERVAL = 15_000;
19
+ export class DebugSessionManager {
20
+ client;
21
+ config;
22
+ callbacks;
23
+ logger = getLogger();
24
+ pollTimer;
25
+ keepaliveTimer;
26
+ /** Last known thread states keyed by thread id */
27
+ knownThreads = new Map();
28
+ connected = false;
29
+ constructor(config, callbacks = {}) {
30
+ this.config = config;
31
+ this.callbacks = callbacks;
32
+ this.client = new SdapiClient({
33
+ hostname: config.hostname,
34
+ username: config.username,
35
+ password: config.password,
36
+ clientId: config.clientId,
37
+ });
38
+ }
39
+ /**
40
+ * Connect to the debugger: enable the client, start polling and keepalive.
41
+ */
42
+ async connect() {
43
+ this.logger.debug({ hostname: this.config.hostname }, 'Connecting to script debugger');
44
+ // Take over any existing session (same pattern as Python reference)
45
+ try {
46
+ await this.client.deleteClient();
47
+ }
48
+ catch {
49
+ // Ignore — client may not exist yet
50
+ }
51
+ await this.client.createClient();
52
+ this.connected = true;
53
+ // Start keepalive timer
54
+ const keepaliveInterval = this.config.keepaliveInterval ?? DEFAULT_KEEPALIVE_INTERVAL;
55
+ this.keepaliveTimer = setInterval(() => void this.keepalive(), keepaliveInterval);
56
+ // Start thread poller
57
+ const pollInterval = this.config.pollInterval ?? DEFAULT_POLL_INTERVAL;
58
+ this.pollTimer = setInterval(() => void this.pollThreads(), pollInterval);
59
+ this.logger.debug('Script debugger connected');
60
+ this.callbacks.onConnected?.(this.config.hostname);
61
+ }
62
+ /**
63
+ * Disconnect: stop timers, delete client.
64
+ */
65
+ async disconnect() {
66
+ this.stopTimers();
67
+ if (this.connected) {
68
+ try {
69
+ await this.client.deleteClient();
70
+ }
71
+ catch (error) {
72
+ this.logger.warn({ error }, 'Error deleting debugger client during disconnect');
73
+ }
74
+ this.connected = false;
75
+ }
76
+ this.knownThreads.clear();
77
+ this.logger.debug('Script debugger disconnected');
78
+ this.callbacks.onDisconnected?.();
79
+ }
80
+ /**
81
+ * Set breakpoints (replaces all current breakpoints).
82
+ */
83
+ async setBreakpoints(breakpoints) {
84
+ await this.client.deleteBreakpoints();
85
+ if (breakpoints.length === 0)
86
+ return [];
87
+ return this.client.setBreakpoints(breakpoints);
88
+ }
89
+ /**
90
+ * Resume a halted thread.
91
+ */
92
+ async resume(threadId) {
93
+ await this.client.resume(threadId);
94
+ }
95
+ /**
96
+ * Step over (next line).
97
+ */
98
+ async stepOver(threadId) {
99
+ await this.client.stepOver(threadId);
100
+ }
101
+ /**
102
+ * Step into function.
103
+ */
104
+ async stepInto(threadId) {
105
+ await this.client.stepInto(threadId);
106
+ }
107
+ /**
108
+ * Step out of function.
109
+ */
110
+ async stepOut(threadId) {
111
+ await this.client.stepOut(threadId);
112
+ }
113
+ /**
114
+ * Get the current list of known threads (from last poll).
115
+ */
116
+ getKnownThreads() {
117
+ return [...this.knownThreads.values()];
118
+ }
119
+ // -----------------------------------------------------------------------
120
+ // Internal
121
+ // -----------------------------------------------------------------------
122
+ stopTimers() {
123
+ if (this.pollTimer) {
124
+ clearInterval(this.pollTimer);
125
+ this.pollTimer = undefined;
126
+ }
127
+ if (this.keepaliveTimer) {
128
+ clearInterval(this.keepaliveTimer);
129
+ this.keepaliveTimer = undefined;
130
+ }
131
+ }
132
+ async keepalive() {
133
+ try {
134
+ await this.client.resetThreads();
135
+ }
136
+ catch (error) {
137
+ this.logger.debug({ error }, 'Keepalive reset failed');
138
+ }
139
+ }
140
+ haltLocationChanged(prev, curr) {
141
+ const prevLoc = prev.call_stack?.[0]?.location;
142
+ const currLoc = curr.call_stack?.[0]?.location;
143
+ if (!prevLoc || !currLoc)
144
+ return prevLoc !== currLoc;
145
+ return prevLoc.script_path !== currLoc.script_path || prevLoc.line_number !== currLoc.line_number;
146
+ }
147
+ logThreadHalted(thread) {
148
+ const topFrame = thread.call_stack?.[0];
149
+ if (topFrame) {
150
+ const loc = topFrame.location;
151
+ const fn = loc.function_name || '<anonymous>';
152
+ this.logger.debug(`Thread ${thread.id} halted at ${loc.script_path}:${loc.line_number} (${fn})`);
153
+ }
154
+ else {
155
+ this.logger.debug(`Thread ${thread.id} halted`);
156
+ }
157
+ }
158
+ async pollThreads() {
159
+ try {
160
+ const threads = await this.client.getThreads();
161
+ const currentIds = new Set();
162
+ for (const thread of threads) {
163
+ currentIds.add(thread.id);
164
+ const previous = this.knownThreads.get(thread.id);
165
+ if (!previous) {
166
+ // New thread appeared
167
+ this.knownThreads.set(thread.id, thread);
168
+ if (thread.status === 'halted') {
169
+ this.logThreadHalted(thread);
170
+ this.callbacks.onThreadStopped?.(thread);
171
+ }
172
+ }
173
+ else if (previous.status !== thread.status) {
174
+ // State changed
175
+ this.knownThreads.set(thread.id, thread);
176
+ if (thread.status === 'halted') {
177
+ this.logThreadHalted(thread);
178
+ this.callbacks.onThreadStopped?.(thread);
179
+ }
180
+ else {
181
+ this.logger.debug(`Thread ${thread.id} resumed`);
182
+ this.callbacks.onThreadContinued?.(thread.id);
183
+ }
184
+ }
185
+ else if (thread.status === 'halted' && this.haltLocationChanged(previous, thread)) {
186
+ // Still halted but at a different location (hit another breakpoint or stepped)
187
+ this.knownThreads.set(thread.id, thread);
188
+ this.logThreadHalted(thread);
189
+ this.callbacks.onThreadStopped?.(thread);
190
+ }
191
+ else {
192
+ this.knownThreads.set(thread.id, thread);
193
+ }
194
+ }
195
+ // Detect threads that disappeared
196
+ for (const [id] of this.knownThreads) {
197
+ if (!currentIds.has(id)) {
198
+ this.knownThreads.delete(id);
199
+ this.logger.debug(`Thread ${id} exited`);
200
+ this.callbacks.onThreadExited?.(id);
201
+ }
202
+ }
203
+ }
204
+ catch (error) {
205
+ if (error instanceof SdapiError && error.status === 412) {
206
+ // Debugger disabled — stop polling
207
+ this.logger.warn('Debugger was disabled externally');
208
+ this.stopTimers();
209
+ this.connected = false;
210
+ this.callbacks.onDebuggerDisabled?.();
211
+ }
212
+ else {
213
+ this.logger.debug({ error }, 'Thread poll error');
214
+ this.callbacks.onError?.(error instanceof Error ? error : new Error(String(error)));
215
+ }
216
+ }
217
+ }
218
+ }
219
+ //# sourceMappingURL=debug-session.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug-session.js","sourceRoot":"","sources":["../../../../src/operations/debug/debug-session.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH;;;;;;;;GAQG;AACH,OAAO,EAAC,SAAS,EAAC,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAC,WAAW,EAAE,UAAU,EAAC,MAAM,mBAAmB,CAAC;AAS1D,MAAM,qBAAqB,GAAG,GAAG,CAAC;AAClC,MAAM,0BAA0B,GAAG,MAAM,CAAC;AAE1C,MAAM,OAAO,mBAAmB;IACrB,MAAM,CAAc;IACZ,MAAM,CAAqB;IAC3B,SAAS,CAAwB;IACjC,MAAM,GAAG,SAAS,EAAE,CAAC;IAE9B,SAAS,CAAkC;IAC3C,cAAc,CAAkC;IAExD,kDAAkD;IAC1C,YAAY,GAAG,IAAI,GAAG,EAA6B,CAAC;IACpD,SAAS,GAAG,KAAK,CAAC;IAE1B,YAAY,MAA0B,EAAE,YAAmC,EAAE;QAC3E,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,IAAI,WAAW,CAAC;YAC5B,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,QAAQ,EAAE,MAAM,CAAC,QAAQ;SAC1B,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,OAAO;QACX,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAC,QAAQ,EA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,CAAC;gBACrD,IAAI,CAAC,UAAU,EAAE,CAAC;gBAClB,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;gBACvB,IAAI,CAAC,SAAS,CAAC,kBAAkB,EAAE,EAAE,CAAC;YACxC,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAC,KAAK,EAAC,EAAE,mBAAmB,CAAC,CAAC;gBAChD,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACtF,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * B2C Commerce Script Debugger operations.
3
+ *
4
+ * Provides the SDAPI client, debug session manager, DAP adapter, and supporting
5
+ * utilities for source mapping and variable reference management.
6
+ *
7
+ * @module operations/debug
8
+ */
9
+ export { SdapiClient, SdapiError, createSdapiClient } from './sdapi-client.js';
10
+ export type { SdapiClientConfig } from './sdapi-client.js';
11
+ export { DebugSessionManager } from './debug-session.js';
12
+ export { B2CScriptDebugAdapter } from './dap-adapter.js';
13
+ export { createSourceMapper } from './source-mapping.js';
14
+ export type { SourceMapper } from './source-mapping.js';
15
+ export { VariableStore } from './variable-store.js';
16
+ export type { VariableRef } from './variable-store.js';
17
+ export type { SdapiLocation, SdapiStackFrame, SdapiScriptThread, SdapiBreakpoint, SdapiBreakpoints, SdapiObjectMember, SdapiObjectMembers, SdapiEvalResult, SdapiFault, BreakpointInput, DebugSessionConfig, DebugSessionCallbacks, } from './types.js';
@@ -0,0 +1,19 @@
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
+ * B2C Commerce Script Debugger operations.
8
+ *
9
+ * Provides the SDAPI client, debug session manager, DAP adapter, and supporting
10
+ * utilities for source mapping and variable reference management.
11
+ *
12
+ * @module operations/debug
13
+ */
14
+ export { SdapiClient, SdapiError, createSdapiClient } from './sdapi-client.js';
15
+ export { DebugSessionManager } from './debug-session.js';
16
+ export { B2CScriptDebugAdapter } from './dap-adapter.js';
17
+ export { createSourceMapper } from './source-mapping.js';
18
+ export { VariableStore } from './variable-store.js';
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/operations/debug/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH;;;;;;;GAOG;AACH,OAAO,EAAC,WAAW,EAAE,UAAU,EAAE,iBAAiB,EAAC,MAAM,mBAAmB,CAAC;AAE7E,OAAO,EAAC,mBAAmB,EAAC,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAC,qBAAqB,EAAC,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAC,kBAAkB,EAAC,MAAM,qBAAqB,CAAC;AAEvD,OAAO,EAAC,aAAa,EAAC,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,44 @@
1
+ import type { SdapiBreakpoint, SdapiEvalResult, SdapiFault, SdapiObjectMembers, SdapiScriptThread, BreakpointInput } from './types.js';
2
+ /**
3
+ * Error thrown when the SDAPI returns a fault response.
4
+ */
5
+ export declare class SdapiError extends Error {
6
+ readonly fault: SdapiFault;
7
+ readonly status: number;
8
+ constructor(fault: SdapiFault, status: number);
9
+ }
10
+ export interface SdapiClientConfig {
11
+ hostname: string;
12
+ username: string;
13
+ password: string;
14
+ clientId?: string;
15
+ }
16
+ /**
17
+ * Creates a new SDAPI client.
18
+ */
19
+ export declare function createSdapiClient(config: SdapiClientConfig): SdapiClient;
20
+ export declare class SdapiClient {
21
+ private readonly baseUrl;
22
+ private readonly headers;
23
+ private readonly logger;
24
+ constructor(config: SdapiClientConfig);
25
+ createClient(): Promise<void>;
26
+ deleteClient(): Promise<void>;
27
+ getBreakpoints(): Promise<SdapiBreakpoint[]>;
28
+ setBreakpoints(breakpoints: BreakpointInput[]): Promise<SdapiBreakpoint[]>;
29
+ deleteBreakpoints(): Promise<void>;
30
+ deleteBreakpoint(id: number): Promise<void>;
31
+ getThreads(): Promise<SdapiScriptThread[]>;
32
+ getThread(threadId: number): Promise<SdapiScriptThread>;
33
+ resetThreads(): Promise<void>;
34
+ resume(threadId: number): Promise<SdapiScriptThread>;
35
+ stepOver(threadId: number): Promise<SdapiScriptThread>;
36
+ stepInto(threadId: number): Promise<SdapiScriptThread>;
37
+ stepOut(threadId: number): Promise<SdapiScriptThread>;
38
+ stopThread(threadId: number): Promise<void>;
39
+ getVariables(threadId: number, frameIndex: number): Promise<SdapiObjectMembers>;
40
+ getMembers(threadId: number, frameIndex: number, objectPath?: string, start?: number, count?: number): Promise<SdapiObjectMembers>;
41
+ evaluate(threadId: number, frameIndex: number, expr: string): Promise<SdapiEvalResult>;
42
+ private request;
43
+ private throwSdapiError;
44
+ }
@@ -0,0 +1,169 @@
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
+ * Stateless HTTP client for the B2C Commerce Script Debugger API (SDAPI 2.0).
8
+ *
9
+ * All methods use global `fetch()` with Basic auth and the required
10
+ * `x-dw-client-id` header. The client is stateless — callers are responsible
11
+ * for session lifecycle (create/delete client, polling, keepalive).
12
+ *
13
+ * @module operations/debug/sdapi-client
14
+ */
15
+ import { getLogger } from '../../logging/logger.js';
16
+ /**
17
+ * Error thrown when the SDAPI returns a fault response.
18
+ */
19
+ export class SdapiError extends Error {
20
+ fault;
21
+ status;
22
+ constructor(fault, status) {
23
+ super(`${fault.type}: ${fault.message}`);
24
+ this.name = 'SdapiError';
25
+ this.fault = fault;
26
+ this.status = status;
27
+ }
28
+ }
29
+ /**
30
+ * Creates a new SDAPI client.
31
+ */
32
+ export function createSdapiClient(config) {
33
+ return new SdapiClient(config);
34
+ }
35
+ export class SdapiClient {
36
+ baseUrl;
37
+ headers;
38
+ logger = getLogger();
39
+ constructor(config) {
40
+ this.baseUrl = `https://${config.hostname}/s/-/dw/debugger/v2_0`;
41
+ const credentials = btoa(`${config.username}:${config.password}`);
42
+ this.headers = {
43
+ Authorization: `Basic ${credentials}`,
44
+ 'x-dw-client-id': config.clientId ?? 'b2c-cli',
45
+ 'Content-Type': 'application/json',
46
+ };
47
+ }
48
+ // -----------------------------------------------------------------------
49
+ // Client resource (debugger lifecycle)
50
+ // -----------------------------------------------------------------------
51
+ async createClient() {
52
+ await this.request('POST', '/client', { expect204: true });
53
+ }
54
+ async deleteClient() {
55
+ await this.request('DELETE', '/client', { expect204: true });
56
+ }
57
+ // -----------------------------------------------------------------------
58
+ // Breakpoints
59
+ // -----------------------------------------------------------------------
60
+ async getBreakpoints() {
61
+ const data = await this.request('GET', '/breakpoints');
62
+ return data.breakpoints ?? [];
63
+ }
64
+ async setBreakpoints(breakpoints) {
65
+ const data = await this.request('POST', '/breakpoints', {
66
+ body: { breakpoints },
67
+ });
68
+ return data.breakpoints ?? [];
69
+ }
70
+ async deleteBreakpoints() {
71
+ await this.request('DELETE', '/breakpoints', { expect204: true });
72
+ }
73
+ async deleteBreakpoint(id) {
74
+ await this.request('DELETE', `/breakpoints/${id}`, { expect204: true });
75
+ }
76
+ // -----------------------------------------------------------------------
77
+ // Threads
78
+ // -----------------------------------------------------------------------
79
+ async getThreads() {
80
+ const data = await this.request('GET', '/threads');
81
+ return data.script_threads ?? [];
82
+ }
83
+ async getThread(threadId) {
84
+ return this.request('GET', `/threads/${threadId}`);
85
+ }
86
+ async resetThreads() {
87
+ await this.request('POST', '/threads/reset', { expect204: true });
88
+ }
89
+ // -----------------------------------------------------------------------
90
+ // Execution control
91
+ // -----------------------------------------------------------------------
92
+ async resume(threadId) {
93
+ return this.request('POST', `/threads/${threadId}/resume`);
94
+ }
95
+ async stepOver(threadId) {
96
+ return this.request('POST', `/threads/${threadId}/over`);
97
+ }
98
+ async stepInto(threadId) {
99
+ return this.request('POST', `/threads/${threadId}/into`);
100
+ }
101
+ async stepOut(threadId) {
102
+ return this.request('POST', `/threads/${threadId}/out`);
103
+ }
104
+ async stopThread(threadId) {
105
+ await this.request('DELETE', `/threads/${threadId}/stop`, { expect204: true });
106
+ }
107
+ // -----------------------------------------------------------------------
108
+ // Variables & evaluation
109
+ // -----------------------------------------------------------------------
110
+ async getVariables(threadId, frameIndex) {
111
+ return this.request('GET', `/threads/${threadId}/frames/${frameIndex}/variables`);
112
+ }
113
+ async getMembers(threadId, frameIndex, objectPath, start, count) {
114
+ const params = new URLSearchParams();
115
+ if (objectPath)
116
+ params.set('object_path', objectPath);
117
+ if (start !== undefined)
118
+ params.set('start', String(start));
119
+ if (count !== undefined)
120
+ params.set('count', String(count));
121
+ const qs = params.toString();
122
+ const suffix = qs ? `?${qs}` : '';
123
+ return this.request('GET', `/threads/${threadId}/frames/${frameIndex}/members${suffix}`);
124
+ }
125
+ async evaluate(threadId, frameIndex, expr) {
126
+ const params = new URLSearchParams({ expr });
127
+ return this.request('GET', `/threads/${threadId}/frames/${frameIndex}/eval?${params.toString()}`);
128
+ }
129
+ // -----------------------------------------------------------------------
130
+ // Internal
131
+ // -----------------------------------------------------------------------
132
+ async request(method, path, options) {
133
+ const url = `${this.baseUrl}${path}`;
134
+ this.logger.trace({ method, path }, 'SDAPI request');
135
+ const response = await fetch(url, {
136
+ method,
137
+ headers: this.headers,
138
+ body: options?.body ? JSON.stringify(options.body) : undefined,
139
+ });
140
+ if (options?.expect204) {
141
+ if (!response.ok) {
142
+ await this.throwSdapiError(response);
143
+ }
144
+ return undefined;
145
+ }
146
+ if (!response.ok) {
147
+ await this.throwSdapiError(response);
148
+ }
149
+ return (await response.json());
150
+ }
151
+ async throwSdapiError(response) {
152
+ let fault;
153
+ try {
154
+ const body = (await response.json());
155
+ // SDAPI may return fault at top level or nested under a "fault" property
156
+ const faultData = body.fault ?? body;
157
+ fault = {
158
+ _v: String(faultData._v ?? body._v ?? '2.0'),
159
+ type: String(faultData.type ?? 'UnknownError'),
160
+ message: String(faultData.message ?? `HTTP ${response.status} ${response.statusText}`),
161
+ };
162
+ }
163
+ catch {
164
+ fault = { _v: '2.0', type: 'UnknownError', message: `HTTP ${response.status} ${response.statusText}` };
165
+ }
166
+ throw new SdapiError(fault, response.status);
167
+ }
168
+ }
169
+ //# sourceMappingURL=sdapi-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sdapi-client.js","sourceRoot":"","sources":["../../../../src/operations/debug/sdapi-client.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH;;;;;;;;GAQG;AACH,OAAO,EAAC,SAAS,EAAC,MAAM,yBAAyB,CAAC;AAYlD;;GAEG;AACH,MAAM,OAAO,UAAW,SAAQ,KAAK;IAC1B,KAAK,CAAa;IAClB,MAAM,CAAS;IAExB,YAAY,KAAiB,EAAE,MAAc;QAC3C,KAAK,CAAC,GAAG,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QACzC,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AASD;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAyB;IACzD,OAAO,IAAI,WAAW,CAAC,MAAM,CAAC,CAAC;AACjC,CAAC;AAED,MAAM,OAAO,WAAW;IACL,OAAO,CAAS;IAChB,OAAO,CAAyB;IAChC,MAAM,GAAG,SAAS,EAAE,CAAC;IAEtC,YAAY,MAAyB;QACnC,IAAI,CAAC,OAAO,GAAG,WAAW,MAAM,CAAC,QAAQ,uBAAuB,CAAC;QACjE,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,MAAM,CAAC,QAAQ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AI,EAAE,MAAM,CAAC,SAAS,CAAC,IAAI,IAAI,cAAc,CAAC;gBAC9C,OAAO,EAAE,MAAM,CAAC,SAAS,CAAC,OAAO,IAAI,QAAQ,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,EAAE,CAAC;aACvF,CAAC;QACJ,CAAC;QAAC,MAAM,CAAC;YACP,KAAK,GAAG,EAAC,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,QAAQ,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,EAAE,EAAC,CAAC;QACvG,CAAC;QACD,MAAM,IAAI,UAAU,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC/C,CAAC;CACF"}
@@ -0,0 +1,13 @@
1
+ import type { CartridgeMapping } from '../code/cartridges.js';
2
+ export interface SourceMapper {
3
+ /** Convert a local filesystem path to an SDAPI script_path. */
4
+ toServerPath(localPath: string): string | undefined;
5
+ /** Convert an SDAPI script_path to a local filesystem path. */
6
+ toLocalPath(scriptPath: string): string | undefined;
7
+ }
8
+ /**
9
+ * Creates a SourceMapper from discovered cartridge mappings.
10
+ *
11
+ * @param cartridges - Array of cartridge mappings from `findCartridges()`
12
+ */
13
+ export declare function createSourceMapper(cartridges: CartridgeMapping[]): SourceMapper;
@@ -0,0 +1,57 @@
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
+ * Maps local filesystem paths to SDAPI server script paths and vice-versa.
8
+ *
9
+ * SDAPI script paths are cartridge-relative, e.g. `/app_storefront/cartridge/controllers/Cart.js`.
10
+ * Local paths are absolute filesystem paths resolved from discovered cartridge directories.
11
+ *
12
+ * @module operations/debug/source-mapping
13
+ */
14
+ import path from 'node:path';
15
+ /**
16
+ * Creates a SourceMapper from discovered cartridge mappings.
17
+ *
18
+ * @param cartridges - Array of cartridge mappings from `findCartridges()`
19
+ */
20
+ export function createSourceMapper(cartridges) {
21
+ // Pre-compute normalized cartridge source paths for fast comparison
22
+ const mappings = cartridges.map((c) => ({
23
+ name: c.name,
24
+ // Normalize and ensure trailing separator for prefix matching
25
+ srcPrefix: path.resolve(c.src) + path.sep,
26
+ src: path.resolve(c.src),
27
+ }));
28
+ // Index by cartridge name for fast server→local lookup
29
+ const byName = new Map(mappings.map((m) => [m.name, m]));
30
+ return {
31
+ toServerPath(localPath) {
32
+ const resolved = path.resolve(localPath);
33
+ for (const m of mappings) {
34
+ if (resolved.startsWith(m.srcPrefix) || resolved === m.src) {
35
+ const relative = resolved.slice(m.srcPrefix.length);
36
+ // SDAPI paths use forward slashes
37
+ return `/${m.name}/${relative.split(path.sep).join('/')}`;
38
+ }
39
+ }
40
+ return undefined;
41
+ },
42
+ toLocalPath(scriptPath) {
43
+ // scriptPath format: /cartridge_name/rest/of/path.js
44
+ const withoutLeadingSlash = scriptPath.startsWith('/') ? scriptPath.slice(1) : scriptPath;
45
+ const slashIndex = withoutLeadingSlash.indexOf('/');
46
+ if (slashIndex === -1)
47
+ return undefined;
48
+ const cartridgeName = withoutLeadingSlash.slice(0, slashIndex);
49
+ const rest = withoutLeadingSlash.slice(slashIndex + 1);
50
+ const mapping = byName.get(cartridgeName);
51
+ if (!mapping)
52
+ return undefined;
53
+ return path.join(mapping.src, rest);
54
+ },
55
+ };
56
+ }
57
+ //# sourceMappingURL=source-mapping.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source-mapping.js","sourceRoot":"","sources":["../../../../src/operations/debug/source-mapping.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH;;;;;;;GAOG;AACH,OAAO,IAAI,MAAM,WAAW,CAAC;AAU7B;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,UAA8B;IAC/D,oEAAoE;IACpE,MAAM,QAAQ,GAAG,UAAU,CAAC,GAAG,CAAC,CA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