@sf-explorer/agentforce-service 1.0.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/README.md +173 -0
- package/bin/cli.js +43 -0
- package/dist/client/assets/index-4BXb_5Lv.css +1 -0
- package/dist/client/assets/index-CCE64qe5.js +43 -0
- package/dist/client/index.html +13 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +54 -0
- package/dist/openapi.d.ts +644 -0
- package/dist/openapi.js +475 -0
- package/dist/org.d.ts +21 -0
- package/dist/org.js +45 -0
- package/dist/routes/agents.d.ts +3 -0
- package/dist/routes/agents.js +181 -0
- package/dist/routes/context.d.ts +15 -0
- package/dist/routes/context.js +11 -0
- package/dist/routes/index.d.ts +5 -0
- package/dist/routes/index.js +13 -0
- package/dist/routes/session.d.ts +3 -0
- package/dist/routes/session.js +195 -0
- package/dist/routes/tests.d.ts +3 -0
- package/dist/routes/tests.js +211 -0
- package/dist/routes.d.ts +14 -0
- package/dist/routes.js +534 -0
- package/package.json +52 -0
package/dist/openapi.js
ADDED
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAPI 3.0 specification for Agentforce service API
|
|
3
|
+
*/
|
|
4
|
+
export const openApiSpec = {
|
|
5
|
+
openapi: "3.0.3",
|
|
6
|
+
info: {
|
|
7
|
+
title: "Agentforce Service API",
|
|
8
|
+
description: `Express API for Salesforce Agentforce agents - preview sessions, compile, and agent CRUD (disk-based).
|
|
9
|
+
|
|
10
|
+
## Session flow (prerequisite order)
|
|
11
|
+
|
|
12
|
+
To chat with an agent and inspect traces, call endpoints in this order:
|
|
13
|
+
|
|
14
|
+
1. **POST /api/startSession** – Start a preview session. Returns \`sessionId\`.
|
|
15
|
+
2. **POST /api/sendmessage** – Send user messages. Call repeatedly to converse. Response includes \`messages[].planId\` per turn.
|
|
16
|
+
3. **POST /api/trace** – (Optional) Get the plan trace for a given \`planId\` from a sendmessage response. Use after sendmessage.
|
|
17
|
+
4. **POST /api/endSession** – End the session when done.
|
|
18
|
+
|
|
19
|
+
## Standalone endpoints
|
|
20
|
+
|
|
21
|
+
- **POST /api/compile** – Compile an AgentScript bundle (no session needed).
|
|
22
|
+
- **GET /api/agents** – List agents (local, remote, or all).
|
|
23
|
+
- **GET/PUT/POST /api/agent** – Read, update, or create agent bundles on disk.
|
|
24
|
+
|
|
25
|
+
## Testing endpoints
|
|
26
|
+
|
|
27
|
+
- **GET /api/tests** – List test definitions (local JSON files).
|
|
28
|
+
- **GET /api/tests/:filename** – Retrieve test content by filename.
|
|
29
|
+
- **POST /api/tests/run** – Run tests (Salesforce AI Evaluation or local JSON).
|
|
30
|
+
- **GET /api/tests/runs/:runId** – Retrieve test run status or results.`,
|
|
31
|
+
version: "1.0.0",
|
|
32
|
+
},
|
|
33
|
+
servers: [
|
|
34
|
+
{ url: "http://localhost:3847", description: "Local development" },
|
|
35
|
+
],
|
|
36
|
+
tags: [
|
|
37
|
+
{ name: "Health", description: "Server health and status" },
|
|
38
|
+
{ name: "Session", description: "Agent preview session lifecycle (start, send, trace, end)" },
|
|
39
|
+
{ name: "Compile", description: "AgentScript compilation" },
|
|
40
|
+
{ name: "Agents", description: "Agent bundle CRUD (list, get, create, update)" },
|
|
41
|
+
{ name: "Tests", description: "Test definitions and execution" },
|
|
42
|
+
],
|
|
43
|
+
paths: {
|
|
44
|
+
"/health": {
|
|
45
|
+
get: {
|
|
46
|
+
tags: ["Health"],
|
|
47
|
+
summary: "Health check",
|
|
48
|
+
description: "Returns server status and project info",
|
|
49
|
+
responses: {
|
|
50
|
+
200: {
|
|
51
|
+
description: "OK",
|
|
52
|
+
content: {
|
|
53
|
+
"application/json": {
|
|
54
|
+
schema: {
|
|
55
|
+
type: "object",
|
|
56
|
+
properties: {
|
|
57
|
+
status: { type: "string" },
|
|
58
|
+
projectDir: { type: "string" },
|
|
59
|
+
orgAlias: { type: "string" },
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
"/api/startSession": {
|
|
69
|
+
post: {
|
|
70
|
+
tags: ["Session"],
|
|
71
|
+
summary: "Start agent preview session",
|
|
72
|
+
description: "Creates a new preview session for an agent. **Required first step** before sendmessage, trace, or endSession. Provide either `agentBundleName` (script agent in your project) or `apiNameOrId` (published agent in the org). Returns `sessionId` for subsequent calls.",
|
|
73
|
+
requestBody: {
|
|
74
|
+
required: true,
|
|
75
|
+
content: {
|
|
76
|
+
"application/json": {
|
|
77
|
+
schema: {
|
|
78
|
+
type: "object",
|
|
79
|
+
properties: {
|
|
80
|
+
agentBundleName: {
|
|
81
|
+
type: "string",
|
|
82
|
+
description: "Developer name of the agent bundle (folder under force-app/main/default/aiAuthoringBundles/). Use for script agents in development.",
|
|
83
|
+
},
|
|
84
|
+
aabName: {
|
|
85
|
+
type: "string",
|
|
86
|
+
description: "Deprecated. Use agentBundleName instead. Accepted for backward compatibility.",
|
|
87
|
+
deprecated: true,
|
|
88
|
+
},
|
|
89
|
+
apiNameOrId: {
|
|
90
|
+
type: "string",
|
|
91
|
+
description: "API name or Salesforce ID of a published agent in the org. Use for production agents.",
|
|
92
|
+
},
|
|
93
|
+
useMock: {
|
|
94
|
+
type: "boolean",
|
|
95
|
+
description: "Script agents only. true = simulated mode (mock actions, default). false = live mode (real Apex, flows). Ignored for published agents.",
|
|
96
|
+
default: true,
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
responses: {
|
|
104
|
+
200: {
|
|
105
|
+
description: "Session started. Response includes sessionId.",
|
|
106
|
+
content: { "application/json": { schema: { type: "object", properties: { sessionId: { type: "string" } } } } },
|
|
107
|
+
},
|
|
108
|
+
400: { description: "Missing agentBundleName (or aabName) or apiNameOrId" },
|
|
109
|
+
500: { description: "Start session failed" },
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
"/api/sendmessage": {
|
|
114
|
+
post: {
|
|
115
|
+
tags: ["Session"],
|
|
116
|
+
summary: "Send message to agent",
|
|
117
|
+
description: "Sends a user message to the agent and returns the agent's response. **Requires** an active session from startSession. Response includes `messages` with agent replies and `messages[].planId` for each turn; use planId with the trace endpoint to inspect execution steps.",
|
|
118
|
+
requestBody: {
|
|
119
|
+
required: true,
|
|
120
|
+
content: {
|
|
121
|
+
"application/json": {
|
|
122
|
+
schema: {
|
|
123
|
+
type: "object",
|
|
124
|
+
required: ["sessionId", "message"],
|
|
125
|
+
properties: {
|
|
126
|
+
sessionId: { type: "string", description: "Session ID from startSession response" },
|
|
127
|
+
message: { type: "string", description: "User message to send to the agent" },
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
responses: {
|
|
134
|
+
200: {
|
|
135
|
+
description: "Agent response. messages[] contains replies; each message has planId for trace lookup.",
|
|
136
|
+
content: { "application/json": { schema: { type: "object" } } },
|
|
137
|
+
},
|
|
138
|
+
400: { description: "Missing sessionId or message" },
|
|
139
|
+
404: { description: "Session not found. Call startSession first." },
|
|
140
|
+
500: { description: "Send message failed" },
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
"/api/trace": {
|
|
145
|
+
post: {
|
|
146
|
+
tags: ["Session"],
|
|
147
|
+
summary: "Get plan trace",
|
|
148
|
+
description: "Returns the execution trace (plan steps) for a given turn. **Requires** an active session and a planId from a prior sendmessage response. Use to debug agent behavior: inspect LLM calls, function invocations, topic changes, and reasoning steps.",
|
|
149
|
+
requestBody: {
|
|
150
|
+
required: true,
|
|
151
|
+
content: {
|
|
152
|
+
"application/json": {
|
|
153
|
+
schema: {
|
|
154
|
+
type: "object",
|
|
155
|
+
required: ["sessionId", "planId"],
|
|
156
|
+
properties: {
|
|
157
|
+
sessionId: { type: "string", description: "Session ID from startSession" },
|
|
158
|
+
planId: { type: "string", description: "Plan ID from sendmessage response messages[].planId" },
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
responses: {
|
|
165
|
+
200: {
|
|
166
|
+
description: "Plan trace with intent, topic, and plan steps (UserInputStep, LLMExecutionStep, FunctionStep, etc.)",
|
|
167
|
+
content: { "application/json": { schema: { type: "object" } } },
|
|
168
|
+
},
|
|
169
|
+
400: { description: "Missing sessionId or planId" },
|
|
170
|
+
404: { description: "Session not found. Call startSession first." },
|
|
171
|
+
500: { description: "Get trace failed" },
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
"/api/endSession": {
|
|
176
|
+
post: {
|
|
177
|
+
tags: ["Session"],
|
|
178
|
+
summary: "End agent preview session",
|
|
179
|
+
description: "Ends the preview session and releases resources. Call when done chatting. Session cannot be used for sendmessage or trace after this.",
|
|
180
|
+
requestBody: {
|
|
181
|
+
required: true,
|
|
182
|
+
content: {
|
|
183
|
+
"application/json": {
|
|
184
|
+
schema: {
|
|
185
|
+
type: "object",
|
|
186
|
+
required: ["sessionId"],
|
|
187
|
+
properties: { sessionId: { type: "string", description: "Session ID from startSession" } },
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
responses: {
|
|
193
|
+
200: { description: "Session ended" },
|
|
194
|
+
400: { description: "Missing sessionId" },
|
|
195
|
+
404: { description: "Session not found" },
|
|
196
|
+
500: { description: "End session failed" },
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
"/api/compile": {
|
|
201
|
+
post: {
|
|
202
|
+
tags: ["Compile"],
|
|
203
|
+
summary: "Compile AgentScript",
|
|
204
|
+
description: "Compiles an AgentScript bundle to agent JSON. Validates syntax and resolves references. No session required. Only works for script agents (agentBundleName), not published agents.",
|
|
205
|
+
requestBody: {
|
|
206
|
+
required: true,
|
|
207
|
+
content: {
|
|
208
|
+
"application/json": {
|
|
209
|
+
schema: {
|
|
210
|
+
type: "object",
|
|
211
|
+
required: ["agentBundleName"],
|
|
212
|
+
properties: {
|
|
213
|
+
agentBundleName: {
|
|
214
|
+
type: "string",
|
|
215
|
+
description: "Developer name of the agent bundle under aiAuthoringBundles/",
|
|
216
|
+
},
|
|
217
|
+
aabName: {
|
|
218
|
+
type: "string",
|
|
219
|
+
description: "Deprecated. Use agentBundleName instead.",
|
|
220
|
+
deprecated: true,
|
|
221
|
+
},
|
|
222
|
+
},
|
|
223
|
+
},
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
responses: {
|
|
228
|
+
200: {
|
|
229
|
+
description: "Compile result (success: compiledArtifact; failure: errors)",
|
|
230
|
+
content: { "application/json": { schema: { type: "object" } } },
|
|
231
|
+
},
|
|
232
|
+
400: { description: "Missing agentBundleName (or aabName) or not a ScriptAgent" },
|
|
233
|
+
500: { description: "Compile failed" },
|
|
234
|
+
},
|
|
235
|
+
},
|
|
236
|
+
},
|
|
237
|
+
"/api/agents": {
|
|
238
|
+
get: {
|
|
239
|
+
tags: ["Agents"],
|
|
240
|
+
summary: "List agents",
|
|
241
|
+
description: "Returns available agents. Use source=local for script bundles in the project, source=remote for published agents in the org, or source=all (default) for both. No session required.",
|
|
242
|
+
parameters: [
|
|
243
|
+
{
|
|
244
|
+
name: "source",
|
|
245
|
+
in: "query",
|
|
246
|
+
schema: { type: "string", enum: ["local", "remote", "all"], default: "all" },
|
|
247
|
+
},
|
|
248
|
+
],
|
|
249
|
+
responses: {
|
|
250
|
+
200: {
|
|
251
|
+
description: "List of agents",
|
|
252
|
+
content: {
|
|
253
|
+
"application/json": {
|
|
254
|
+
schema: {
|
|
255
|
+
type: "object",
|
|
256
|
+
properties: {
|
|
257
|
+
agents: { type: "array", items: { type: "string" } },
|
|
258
|
+
source: { type: "string" },
|
|
259
|
+
},
|
|
260
|
+
},
|
|
261
|
+
},
|
|
262
|
+
},
|
|
263
|
+
},
|
|
264
|
+
500: { description: "Retrieve agents failed" },
|
|
265
|
+
},
|
|
266
|
+
},
|
|
267
|
+
},
|
|
268
|
+
"/api/agent": {
|
|
269
|
+
post: {
|
|
270
|
+
tags: ["Agents"],
|
|
271
|
+
summary: "Create agent",
|
|
272
|
+
description: "Create a new agent by writing files to disk under force-app/main/default/aiAuthoringBundles/{developerName}/",
|
|
273
|
+
requestBody: {
|
|
274
|
+
required: true,
|
|
275
|
+
content: {
|
|
276
|
+
"application/json": {
|
|
277
|
+
schema: {
|
|
278
|
+
type: "object",
|
|
279
|
+
required: ["developerName", "agentContent"],
|
|
280
|
+
properties: {
|
|
281
|
+
developerName: { type: "string" },
|
|
282
|
+
agentContent: { type: "string", description: "Content of the .agent file" },
|
|
283
|
+
bundleMetaContent: { type: "string", description: "Optional .bundle-meta.xml content" },
|
|
284
|
+
},
|
|
285
|
+
},
|
|
286
|
+
},
|
|
287
|
+
},
|
|
288
|
+
},
|
|
289
|
+
responses: {
|
|
290
|
+
201: { description: "Agent created" },
|
|
291
|
+
400: { description: "Missing developerName or agentContent" },
|
|
292
|
+
409: { description: "Agent already exists" },
|
|
293
|
+
500: { description: "Create agent failed" },
|
|
294
|
+
},
|
|
295
|
+
},
|
|
296
|
+
},
|
|
297
|
+
"/api/agent/{developerName}": {
|
|
298
|
+
get: {
|
|
299
|
+
tags: ["Agents"],
|
|
300
|
+
summary: "Get agent",
|
|
301
|
+
description: "Read agent metadata directly from disk. Path: force-app/main/default/aiAuthoringBundles/{developerName}/",
|
|
302
|
+
parameters: [
|
|
303
|
+
{ name: "developerName", in: "path", required: true, schema: { type: "string" } },
|
|
304
|
+
],
|
|
305
|
+
responses: {
|
|
306
|
+
200: {
|
|
307
|
+
description: "Agent files (keyed by path)",
|
|
308
|
+
content: {
|
|
309
|
+
"application/json": {
|
|
310
|
+
schema: {
|
|
311
|
+
type: "object",
|
|
312
|
+
additionalProperties: { type: "string" },
|
|
313
|
+
},
|
|
314
|
+
},
|
|
315
|
+
},
|
|
316
|
+
},
|
|
317
|
+
404: { description: "Agent not found" },
|
|
318
|
+
500: { description: "Get agent failed" },
|
|
319
|
+
},
|
|
320
|
+
},
|
|
321
|
+
put: {
|
|
322
|
+
tags: ["Agents"],
|
|
323
|
+
summary: "Update agent",
|
|
324
|
+
description: "Update agent by writing files directly to disk. Path: force-app/main/default/aiAuthoringBundles/{developerName}/",
|
|
325
|
+
parameters: [
|
|
326
|
+
{ name: "developerName", in: "path", required: true, schema: { type: "string" } },
|
|
327
|
+
],
|
|
328
|
+
requestBody: {
|
|
329
|
+
required: true,
|
|
330
|
+
content: {
|
|
331
|
+
"application/json": {
|
|
332
|
+
schema: {
|
|
333
|
+
type: "object",
|
|
334
|
+
required: ["agentContent"],
|
|
335
|
+
properties: {
|
|
336
|
+
agentContent: { type: "string" },
|
|
337
|
+
bundleMetaContent: { type: "string" },
|
|
338
|
+
},
|
|
339
|
+
},
|
|
340
|
+
},
|
|
341
|
+
},
|
|
342
|
+
},
|
|
343
|
+
responses: {
|
|
344
|
+
200: { description: "Agent updated" },
|
|
345
|
+
400: { description: "Missing agentContent" },
|
|
346
|
+
404: { description: "Agent not found" },
|
|
347
|
+
500: { description: "Update agent failed" },
|
|
348
|
+
},
|
|
349
|
+
},
|
|
350
|
+
},
|
|
351
|
+
"/api/tests": {
|
|
352
|
+
get: {
|
|
353
|
+
tags: ["Tests"],
|
|
354
|
+
summary: "List tests",
|
|
355
|
+
description: "Returns available test definitions (local JSON files with 'test' in the filename). Scans project root and example/ by default.",
|
|
356
|
+
parameters: [
|
|
357
|
+
{
|
|
358
|
+
name: "dir",
|
|
359
|
+
in: "query",
|
|
360
|
+
schema: { type: "string", enum: ["root", "example", "all"], default: "all" },
|
|
361
|
+
description: "Which directories to scan for test files",
|
|
362
|
+
},
|
|
363
|
+
],
|
|
364
|
+
responses: {
|
|
365
|
+
200: {
|
|
366
|
+
description: "List of test files",
|
|
367
|
+
content: {
|
|
368
|
+
"application/json": {
|
|
369
|
+
schema: {
|
|
370
|
+
type: "object",
|
|
371
|
+
properties: {
|
|
372
|
+
tests: {
|
|
373
|
+
type: "array",
|
|
374
|
+
items: {
|
|
375
|
+
type: "object",
|
|
376
|
+
properties: { name: { type: "string" }, path: { type: "string" } },
|
|
377
|
+
},
|
|
378
|
+
},
|
|
379
|
+
},
|
|
380
|
+
},
|
|
381
|
+
},
|
|
382
|
+
},
|
|
383
|
+
},
|
|
384
|
+
500: { description: "List tests failed" },
|
|
385
|
+
},
|
|
386
|
+
},
|
|
387
|
+
},
|
|
388
|
+
"/api/tests/{filename}": {
|
|
389
|
+
get: {
|
|
390
|
+
tags: ["Tests"],
|
|
391
|
+
summary: "Retrieve test",
|
|
392
|
+
description: "Returns the content of a test definition file by filename.",
|
|
393
|
+
parameters: [
|
|
394
|
+
{ name: "filename", in: "path", required: true, schema: { type: "string" } },
|
|
395
|
+
],
|
|
396
|
+
responses: {
|
|
397
|
+
200: {
|
|
398
|
+
description: "Test definition content (JSON)",
|
|
399
|
+
content: { "application/json": { schema: { type: "object" } } },
|
|
400
|
+
},
|
|
401
|
+
400: { description: "Invalid filename" },
|
|
402
|
+
404: { description: "Test not found" },
|
|
403
|
+
500: { description: "Retrieve test failed" },
|
|
404
|
+
},
|
|
405
|
+
},
|
|
406
|
+
},
|
|
407
|
+
"/api/tests/run": {
|
|
408
|
+
post: {
|
|
409
|
+
tags: ["Tests"],
|
|
410
|
+
summary: "Run test",
|
|
411
|
+
description: "Runs a test. For Salesforce AI Evaluation: provide `aiEvaluationDefinitionName` (or `aiEvaluationDefinitionId`). Returns `runId` to poll status/results. For local run: provide `testFile` and `agentBundleName` to execute test cases via preview session.",
|
|
412
|
+
requestBody: {
|
|
413
|
+
required: true,
|
|
414
|
+
content: {
|
|
415
|
+
"application/json": {
|
|
416
|
+
schema: {
|
|
417
|
+
type: "object",
|
|
418
|
+
properties: {
|
|
419
|
+
aiEvaluationDefinitionName: {
|
|
420
|
+
type: "string",
|
|
421
|
+
description: "Developer name of AI Evaluation definition (Salesforce run)",
|
|
422
|
+
},
|
|
423
|
+
aiEvaluationDefinitionId: {
|
|
424
|
+
type: "string",
|
|
425
|
+
description: "Salesforce ID of AI Evaluation definition",
|
|
426
|
+
},
|
|
427
|
+
testFile: {
|
|
428
|
+
type: "string",
|
|
429
|
+
description: "Filename of local test JSON (e.g. energy-test-case.json)",
|
|
430
|
+
},
|
|
431
|
+
agentBundleName: {
|
|
432
|
+
type: "string",
|
|
433
|
+
description: "Agent bundle name for local run",
|
|
434
|
+
},
|
|
435
|
+
},
|
|
436
|
+
},
|
|
437
|
+
},
|
|
438
|
+
},
|
|
439
|
+
},
|
|
440
|
+
responses: {
|
|
441
|
+
200: {
|
|
442
|
+
description: "For SF run: { runId }. For local run: { total, passed, failed, results }",
|
|
443
|
+
content: { "application/json": { schema: { type: "object" } } },
|
|
444
|
+
},
|
|
445
|
+
400: { description: "Missing or invalid parameters" },
|
|
446
|
+
404: { description: "Test file not found" },
|
|
447
|
+
500: { description: "Run test failed" },
|
|
448
|
+
},
|
|
449
|
+
},
|
|
450
|
+
},
|
|
451
|
+
"/api/tests/runs/{runId}": {
|
|
452
|
+
get: {
|
|
453
|
+
tags: ["Tests"],
|
|
454
|
+
summary: "Retrieve test run",
|
|
455
|
+
description: "Returns test run status. Add ?results=true for full results including test cases and metrics.",
|
|
456
|
+
parameters: [
|
|
457
|
+
{ name: "runId", in: "path", required: true, schema: { type: "string" } },
|
|
458
|
+
{
|
|
459
|
+
name: "results",
|
|
460
|
+
in: "query",
|
|
461
|
+
schema: { type: "string", enum: ["true", "false"] },
|
|
462
|
+
description: "Include full results (test cases, metrics)",
|
|
463
|
+
},
|
|
464
|
+
],
|
|
465
|
+
responses: {
|
|
466
|
+
200: {
|
|
467
|
+
description: "Test run status and optionally full results",
|
|
468
|
+
content: { "application/json": { schema: { type: "object" } } },
|
|
469
|
+
},
|
|
470
|
+
500: { description: "Retrieve test run failed" },
|
|
471
|
+
},
|
|
472
|
+
},
|
|
473
|
+
},
|
|
474
|
+
},
|
|
475
|
+
};
|
package/dist/org.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Connection as JSForceConnection } from "jsforce";
|
|
2
|
+
import { Connection } from "@salesforce/core";
|
|
3
|
+
export interface OrgInfo {
|
|
4
|
+
accessToken: string;
|
|
5
|
+
instanceUrl: string;
|
|
6
|
+
username?: string;
|
|
7
|
+
orgId?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Get org info by running sf force:org:display --json [orgAlias]
|
|
11
|
+
* Runs from projectDir so sf finds the project config (sfdx-project.json).
|
|
12
|
+
*/
|
|
13
|
+
export declare function getOrgInfoFromCli(orgAlias?: string, projectDir?: string): OrgInfo;
|
|
14
|
+
/**
|
|
15
|
+
* Create jsforce Connection from org display result
|
|
16
|
+
*/
|
|
17
|
+
export declare function createJsforceConnection(orgInfo: OrgInfo): JSForceConnection;
|
|
18
|
+
/**
|
|
19
|
+
* Create @salesforce/core Connection from org display result (for @salesforce/agents)
|
|
20
|
+
*/
|
|
21
|
+
export declare function createSfConnection(orgInfo: OrgInfo): Promise<Connection>;
|
package/dist/org.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { command } from "@polycuber/script.cli";
|
|
2
|
+
import jsforce from "jsforce";
|
|
3
|
+
import { AuthInfo, Connection } from "@salesforce/core";
|
|
4
|
+
/**
|
|
5
|
+
* Get org info by running sf force:org:display --json [orgAlias]
|
|
6
|
+
* Runs from projectDir so sf finds the project config (sfdx-project.json).
|
|
7
|
+
*/
|
|
8
|
+
export function getOrgInfoFromCli(orgAlias, projectDir) {
|
|
9
|
+
const cmd = orgAlias
|
|
10
|
+
? `sf force:org:display --json ${orgAlias}`
|
|
11
|
+
: "sf force:org:display --json";
|
|
12
|
+
const output = command.read.exec(cmd, { cwd: projectDir });
|
|
13
|
+
if (output instanceof Error)
|
|
14
|
+
throw output;
|
|
15
|
+
const parsed = JSON.parse(output);
|
|
16
|
+
if (parsed.status !== 0 || !parsed.result) {
|
|
17
|
+
throw new Error(`sf force:org:display failed: ${JSON.stringify(parsed)}`);
|
|
18
|
+
}
|
|
19
|
+
const result = parsed.result;
|
|
20
|
+
if (!result.accessToken || !result.instanceUrl) {
|
|
21
|
+
throw new Error("Org display result missing accessToken or instanceUrl");
|
|
22
|
+
}
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Create jsforce Connection from org display result
|
|
27
|
+
*/
|
|
28
|
+
export function createJsforceConnection(orgInfo) {
|
|
29
|
+
return new jsforce.Connection({
|
|
30
|
+
accessToken: orgInfo.accessToken,
|
|
31
|
+
instanceUrl: orgInfo.instanceUrl,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Create @salesforce/core Connection from org display result (for @salesforce/agents)
|
|
36
|
+
*/
|
|
37
|
+
export async function createSfConnection(orgInfo) {
|
|
38
|
+
const authInfo = await AuthInfo.create({
|
|
39
|
+
accessTokenOptions: {
|
|
40
|
+
accessToken: orgInfo.accessToken,
|
|
41
|
+
instanceUrl: orgInfo.instanceUrl,
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
return Connection.create({ authInfo });
|
|
45
|
+
}
|