@gravity-rail/cli 0.56.0 → 0.57.1
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 +5 -1
- package/dist/{account-verify-phone-IK6O7IQJ.js → account-verify-phone-T7N53V35.js} +3 -3
- package/dist/{chunk-5UCDTTIU.js → chunk-462YYQU5.js} +48 -4
- package/dist/chunk-462YYQU5.js.map +1 -0
- package/dist/{chunk-SSJ7CRGL.js → chunk-HNR2SIJP.js} +2 -2
- package/dist/{cli-client-context-cd5f2JKX.d.ts → cli-client-context-NJgZhyfd.d.ts} +2 -1
- package/dist/cli-utils.d.ts +5 -3
- package/dist/cli-utils.js +1 -1
- package/dist/gr.js +1335 -455
- package/dist/gr.js.map +1 -1
- package/dist/lib.d.ts +35 -5
- package/dist/lib.js +780 -360
- package/dist/lib.js.map +1 -1
- package/package.json +3 -3
- package/dist/chunk-5UCDTTIU.js.map +0 -1
- /package/dist/{account-verify-phone-IK6O7IQJ.js.map → account-verify-phone-T7N53V35.js.map} +0 -0
- /package/dist/{chunk-SSJ7CRGL.js.map → chunk-HNR2SIJP.js.map} +0 -0
package/dist/lib.js
CHANGED
|
@@ -33,7 +33,7 @@ import {
|
|
|
33
33
|
startAccountPhoneVerify,
|
|
34
34
|
stderr,
|
|
35
35
|
unwrapItems
|
|
36
|
-
} from "./chunk-
|
|
36
|
+
} from "./chunk-HNR2SIJP.js";
|
|
37
37
|
import {
|
|
38
38
|
AGUIClient,
|
|
39
39
|
formatTimestamp,
|
|
@@ -42,7 +42,7 @@ import {
|
|
|
42
42
|
isRecord,
|
|
43
43
|
performOAuthFlow,
|
|
44
44
|
selectFromList
|
|
45
|
-
} from "./chunk-
|
|
45
|
+
} from "./chunk-462YYQU5.js";
|
|
46
46
|
import {
|
|
47
47
|
AuthRequiredError,
|
|
48
48
|
CLIError,
|
|
@@ -258,7 +258,7 @@ function commandNeedsJsonBody(cmd, parsedArgs) {
|
|
|
258
258
|
}
|
|
259
259
|
return false;
|
|
260
260
|
}
|
|
261
|
-
if (cmd.acceptsJsonInput === true) {
|
|
261
|
+
if (cmd.acceptsJsonInput === true || cmd.pipesJsonInput !== void 0) {
|
|
262
262
|
return true;
|
|
263
263
|
}
|
|
264
264
|
if (parsedArgs.data !== void 0 || parsedArgs.file !== void 0) {
|
|
@@ -279,7 +279,19 @@ function commandNeedsJsonBody(cmd, parsedArgs) {
|
|
|
279
279
|
}
|
|
280
280
|
return false;
|
|
281
281
|
}
|
|
282
|
-
|
|
282
|
+
var PIPED_INPUT_FIRST_BYTE_WAIT_MS = 6e4;
|
|
283
|
+
function commandAwaitsPipedInput(cmd, parsedArgs) {
|
|
284
|
+
if (parsedArgs.data !== void 0 || parsedArgs.file !== void 0) return false;
|
|
285
|
+
const declared = cmd.pipesJsonInput;
|
|
286
|
+
return typeof declared === "function" ? declared(parsedArgs) : declared === true;
|
|
287
|
+
}
|
|
288
|
+
async function readCommandJsonInput(cmd, parsedArgs) {
|
|
289
|
+
if (!commandNeedsJsonBody(cmd, parsedArgs)) return void 0;
|
|
290
|
+
return readJsonInput(parsedArgs, {
|
|
291
|
+
pipedInputWaitMs: commandAwaitsPipedInput(cmd, parsedArgs) ? PIPED_INPUT_FIRST_BYTE_WAIT_MS : 0
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
async function readJsonInput(args, options = {}) {
|
|
283
295
|
const dataStr = args.data;
|
|
284
296
|
const filePath = args.file;
|
|
285
297
|
if (dataStr) {
|
|
@@ -310,15 +322,17 @@ async function readJsonInput(args) {
|
|
|
310
322
|
if (process.stdin.isTTY === true) {
|
|
311
323
|
return void 0;
|
|
312
324
|
}
|
|
313
|
-
return readStdinIfPiped();
|
|
325
|
+
return readStdinIfPiped(options.pipedInputWaitMs ?? 0);
|
|
314
326
|
}
|
|
315
|
-
function readStdinIfPiped() {
|
|
327
|
+
function readStdinIfPiped(firstByteWaitMs) {
|
|
316
328
|
return new Promise((resolve, reject) => {
|
|
317
329
|
let data = "";
|
|
318
330
|
let settled = false;
|
|
331
|
+
let idleTimer;
|
|
319
332
|
const finish2 = (value) => {
|
|
320
333
|
if (settled) return;
|
|
321
334
|
settled = true;
|
|
335
|
+
if (idleTimer) clearTimeout(idleTimer);
|
|
322
336
|
resolve(value);
|
|
323
337
|
};
|
|
324
338
|
const flush = () => {
|
|
@@ -347,6 +361,15 @@ function readStdinIfPiped() {
|
|
|
347
361
|
flush();
|
|
348
362
|
return;
|
|
349
363
|
}
|
|
364
|
+
if (firstByteWaitMs > 0) {
|
|
365
|
+
idleTimer = setTimeout(() => {
|
|
366
|
+
if (!data) {
|
|
367
|
+
process.stdin.pause();
|
|
368
|
+
finish2(void 0);
|
|
369
|
+
}
|
|
370
|
+
}, firstByteWaitMs);
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
350
373
|
finish2(void 0);
|
|
351
374
|
});
|
|
352
375
|
});
|
|
@@ -1383,9 +1406,9 @@ Optional
|
|
|
1383
1406
|
systemPrompt (string) Base instructions / identity
|
|
1384
1407
|
chatModelConfig (object|null) Chat model overrides (temperature, thinking, \u2026)
|
|
1385
1408
|
realtimeModelId (string|null) Voice/realtime model (see \`gr ai-models realtime\`)
|
|
1386
|
-
e.g. "xai:realtime:voice-agent-
|
|
1387
|
-
|
|
1388
|
-
|
|
1409
|
+
e.g. "xai:realtime:voice-agent-3" (Grok Voice 3, the
|
|
1410
|
+
default; not yet cleared for strict-routing workflows).
|
|
1411
|
+
"xai:realtime:voice-agent-2" is deprecated.
|
|
1389
1412
|
Native models auto-fill tts=native + default voice when
|
|
1390
1413
|
realtimeModelConfig is omitted.
|
|
1391
1414
|
realtimeModelConfig (object|null) Realtime config. Native example:
|
|
@@ -1403,11 +1426,7 @@ Attach an agent\u2019s models/identity to a workflow (draft), then publish:
|
|
|
1403
1426
|
gr workflows update --id <wf> -d '{"copyFromAgentId": <agentId>}'
|
|
1404
1427
|
gr workflows publish --workflow-id <wf>
|
|
1405
1428
|
|
|
1406
|
-
One-shot workflow voice WITHOUT creating an agent (preferred for "use Grok Voice
|
|
1407
|
-
gr workflows update --id <wf> -d '{"realtimeModelId":"xai:realtime:voice-agent-2"}'
|
|
1408
|
-
gr workflows publish --workflow-id <wf>
|
|
1409
|
-
|
|
1410
|
-
Opt a workflow into Grok Voice 3.0 (same xAI voices as 2.0; not the default):
|
|
1429
|
+
One-shot workflow voice WITHOUT creating an agent (preferred for "use Grok Voice 3"):
|
|
1411
1430
|
gr workflows update --id <wf> -d '{"realtimeModelId":"xai:realtime:voice-agent-3"}'
|
|
1412
1431
|
gr workflows publish --workflow-id <wf>
|
|
1413
1432
|
|
|
@@ -1435,11 +1454,10 @@ ${AGENT_FIELD_REFERENCE}`,
|
|
|
1435
1454
|
updateHelp: `Update an agent. All fields optional.
|
|
1436
1455
|
${AGENT_FIELD_REFERENCE}`,
|
|
1437
1456
|
createExamples: [
|
|
1438
|
-
`gr agents create -d '{"name":"Support","chatModelId":"openai:chat:gpt-6-luna","realtimeModelId":"xai:realtime:voice-agent-
|
|
1457
|
+
`gr agents create -d '{"name":"Support","chatModelId":"openai:chat:gpt-6-luna","realtimeModelId":"xai:realtime:voice-agent-3"}'`,
|
|
1439
1458
|
"gr agents create --file agent.json"
|
|
1440
1459
|
],
|
|
1441
1460
|
updateExamples: [
|
|
1442
|
-
`gr agents update --id 42 -d '{"realtimeModelId":"xai:realtime:voice-agent-2"}'`,
|
|
1443
1461
|
`gr agents update --id 42 -d '{"realtimeModelId":"xai:realtime:voice-agent-3"}'`,
|
|
1444
1462
|
"gr agents update --id 42 --file agent.json"
|
|
1445
1463
|
]
|
|
@@ -3164,23 +3182,24 @@ Assistant / models (live on the DRAFT revision \u2014 publish to go live)
|
|
|
3164
3182
|
chatModelId (string) Text chat model (see \`gr ai-models chat\`)
|
|
3165
3183
|
chatModelConfig (object|null) Chat model overrides
|
|
3166
3184
|
realtimeModelId (string|null) Voice/realtime model (see \`gr ai-models realtime\`)
|
|
3167
|
-
create: omit \u2192 xai:realtime:voice-agent-
|
|
3168
|
-
voice xai:voice:cosmo; null = voice off
|
|
3185
|
+
create: omit \u2192 xai:realtime:voice-agent-3 with
|
|
3186
|
+
voice xai:voice:cosmo; null = voice off.
|
|
3187
|
+
routingMode "strict": omit \u2192 no voice (use
|
|
3188
|
+
custom:realtime:composable)
|
|
3169
3189
|
update: null = voice off
|
|
3170
3190
|
One-shot switch (keeps the stored voice and
|
|
3171
3191
|
call settings; resets only a voice the new
|
|
3172
3192
|
model cannot use):
|
|
3173
|
-
{"realtimeModelId":"xai:realtime:voice-agent-2"}
|
|
3174
|
-
Opt in to Grok Voice 3.0 (not the default; not yet
|
|
3175
|
-
cleared for routingMode "strict"; same xAI voices):
|
|
3176
3193
|
{"realtimeModelId":"xai:realtime:voice-agent-3"}
|
|
3194
|
+
Grok Voice 3 is not yet cleared for routingMode
|
|
3195
|
+
"strict". voice-agent-2 is deprecated.
|
|
3177
3196
|
On create, a native model id with no stored or
|
|
3178
3197
|
copied config gets tts=native + that
|
|
3179
3198
|
provider's fallback voice. A composable id
|
|
3180
3199
|
still needs its own config. On update,
|
|
3181
3200
|
omitting the config keeps the stored one.
|
|
3182
3201
|
Explicit config replaces it:
|
|
3183
|
-
{"realtimeModelId":"xai:realtime:voice-agent-
|
|
3202
|
+
{"realtimeModelId":"xai:realtime:voice-agent-3",
|
|
3184
3203
|
"realtimeModelConfig":{"ttsModel":"native",
|
|
3185
3204
|
"voiceModel":"xai:voice:ara"}}
|
|
3186
3205
|
realtimeModelConfig (object|null) Realtime config. Omit on update to keep the
|
|
@@ -8360,7 +8379,7 @@ var bundlesDomain = {
|
|
|
8360
8379
|
},
|
|
8361
8380
|
{
|
|
8362
8381
|
path: ["bundles", "draft", "set"],
|
|
8363
|
-
description: 'Replace draft items from {"items": [...]};
|
|
8382
|
+
description: 'Replace draft items from {"items": [...]}. Journey items require {"key", "kind":"journey", "journeyUuid"}; the server captures the source Journey. An optional "links": [{"label", "url"}] replaces the draft links. Use --expected-generation from draft get to protect edits.',
|
|
8364
8383
|
requiresWorkspace: true,
|
|
8365
8384
|
mutates: true,
|
|
8366
8385
|
args: [BUNDLE_ARG, GENERATION_ARG],
|
|
@@ -9735,9 +9754,9 @@ var REALTIME_AUDIO_USD_PER_MIN = {
|
|
|
9735
9754
|
"xai:realtime:voice-agent": 0.05,
|
|
9736
9755
|
// Grok Voice Think Fast 1
|
|
9737
9756
|
"xai:realtime:voice-agent-2": 0.08,
|
|
9738
|
-
// Grok Voice
|
|
9757
|
+
// Grok Voice 2 (pinned grok-voice-2.0)
|
|
9739
9758
|
"xai:realtime:voice-agent-3": 0.08
|
|
9740
|
-
// Grok Voice 3
|
|
9759
|
+
// Grok Voice 3 — same audio rate as 2.0
|
|
9741
9760
|
};
|
|
9742
9761
|
var DEFAULT_REALTIME_AUDIO_USD_PER_MIN = 0.08;
|
|
9743
9762
|
var EST_AUDIO_MIN_PER_RUN = 3;
|
|
@@ -9816,6 +9835,10 @@ function runToBatchRow(job, workflowId, run, error, batchLabel, pinnedRevisionId
|
|
|
9816
9835
|
...job.realtime ? { realtime_model_id: job.modelId } : {},
|
|
9817
9836
|
...batchLabel ? { batch_label: batchLabel } : {},
|
|
9818
9837
|
run_id: run?.id,
|
|
9838
|
+
lane: run?.lane ?? null,
|
|
9839
|
+
outcome: run?.outcome ?? null,
|
|
9840
|
+
assistant_chat_model_id: run?.assistantChatModelId ?? null,
|
|
9841
|
+
assistant_realtime_model_id: run?.assistantRealtimeModelId ?? null,
|
|
9819
9842
|
error,
|
|
9820
9843
|
failure_reason: run?.failureReason ?? null,
|
|
9821
9844
|
passed: run?.passed ?? null,
|
|
@@ -10110,7 +10133,15 @@ var SCENARIO_COLUMNS = [
|
|
|
10110
10133
|
COL.id(),
|
|
10111
10134
|
COL.name(),
|
|
10112
10135
|
{ header: "PERSONA", getValue: (item) => item.personaName ?? "" },
|
|
10113
|
-
{ header: "CHANNEL", getValue: (item) => item.channel ?? "" }
|
|
10136
|
+
{ header: "CHANNEL", getValue: (item) => item.channel ?? "" },
|
|
10137
|
+
{
|
|
10138
|
+
header: "SEED",
|
|
10139
|
+
getValue: (item) => {
|
|
10140
|
+
const turns = Array.isArray(item.seedTurns) ? item.seedTurns.length : 0;
|
|
10141
|
+
if (turns === 0) return "";
|
|
10142
|
+
return item.singleTurn ? `${turns} turns, single-turn` : `${turns} turns`;
|
|
10143
|
+
}
|
|
10144
|
+
}
|
|
10114
10145
|
];
|
|
10115
10146
|
var RUN_COLUMNS = [
|
|
10116
10147
|
COL.id(),
|
|
@@ -10202,7 +10233,7 @@ var qualificationsDomain = {
|
|
|
10202
10233
|
},
|
|
10203
10234
|
{
|
|
10204
10235
|
path: ["qualifications", "scenarios", "create"],
|
|
10205
|
-
description:
|
|
10236
|
+
description: 'Create a scenario on a qualification (pass JSON via --data). Seed history: "seedTurns": [{"speaker": "member"|"agent", "content": "..."}]; "singleTurn": true grades only the Agent reply to the last seeded member turn',
|
|
10206
10237
|
mutates: true,
|
|
10207
10238
|
requiresWorkspace: true,
|
|
10208
10239
|
args: [{ name: "qualification-id", description: "Qualification ID", required: true }],
|
|
@@ -10217,7 +10248,7 @@ var qualificationsDomain = {
|
|
|
10217
10248
|
},
|
|
10218
10249
|
{
|
|
10219
10250
|
path: ["qualifications", "scenarios", "update"],
|
|
10220
|
-
description:
|
|
10251
|
+
description: 'Update a scenario (pass JSON via --data). "seedTurns": [] clears the seed history; "singleTurn" needs seed turns that end on a member turn',
|
|
10221
10252
|
mutates: true,
|
|
10222
10253
|
requiresWorkspace: true,
|
|
10223
10254
|
args: [{ name: "id", description: "Scenario ID", required: true }],
|
|
@@ -12145,6 +12176,7 @@ function bareLabel(ref) {
|
|
|
12145
12176
|
return `${ref.kind}:${shortUuid(ref.uuid)}`;
|
|
12146
12177
|
}
|
|
12147
12178
|
var MAX_REFS_PER_BATCH = 500;
|
|
12179
|
+
var MAX_WORKSPACES_PER_BATCH = 25;
|
|
12148
12180
|
function batchResolution(ref, entry) {
|
|
12149
12181
|
if (entry.status === "resolved") {
|
|
12150
12182
|
return { label: entry.label || bareLabel(ref), status: "resolved" };
|
|
@@ -12239,28 +12271,40 @@ var ActivityRefResolver = class {
|
|
|
12239
12271
|
/**
|
|
12240
12272
|
* One org call per chunk, each carrying whole workspace groups.
|
|
12241
12273
|
*
|
|
12242
|
-
* The server
|
|
12243
|
-
*
|
|
12244
|
-
*
|
|
12245
|
-
*
|
|
12274
|
+
* The server caps a grouped request at both 500 refs and 25 workspaces, and
|
|
12275
|
+
* accepts each workspace at most once per request. So a group larger than
|
|
12276
|
+
* the ref cap is split across requests, smaller groups ride together until
|
|
12277
|
+
* the next one would not fit either bound, and no request names a workspace
|
|
12278
|
+
* twice.
|
|
12246
12279
|
*/
|
|
12247
12280
|
async primeOrg(orgUuid, groups) {
|
|
12248
12281
|
const chunks = [];
|
|
12249
|
-
let current =
|
|
12250
|
-
let
|
|
12282
|
+
let current = /* @__PURE__ */ new Map();
|
|
12283
|
+
let refsInChunk = 0;
|
|
12284
|
+
const flush = () => {
|
|
12285
|
+
if (current.size === 0) return;
|
|
12286
|
+
chunks.push(
|
|
12287
|
+
[...current].map(
|
|
12288
|
+
([workspaceUuid, refs]) => [workspaceUuid, refs]
|
|
12289
|
+
)
|
|
12290
|
+
);
|
|
12291
|
+
current = /* @__PURE__ */ new Map();
|
|
12292
|
+
refsInChunk = 0;
|
|
12293
|
+
};
|
|
12251
12294
|
for (const [workspaceUuid, refs] of groups) {
|
|
12252
|
-
for (let start = 0; start < refs.length;
|
|
12253
|
-
|
|
12254
|
-
|
|
12255
|
-
chunks.push(current);
|
|
12256
|
-
current = [];
|
|
12257
|
-
size = 0;
|
|
12295
|
+
for (let start = 0; start < refs.length; ) {
|
|
12296
|
+
if (!current.has(workspaceUuid) && current.size === MAX_WORKSPACES_PER_BATCH) {
|
|
12297
|
+
flush();
|
|
12258
12298
|
}
|
|
12259
|
-
|
|
12260
|
-
|
|
12299
|
+
const room = MAX_REFS_PER_BATCH - refsInChunk;
|
|
12300
|
+
const slice = refs.slice(start, start + room);
|
|
12301
|
+
current.set(workspaceUuid, slice);
|
|
12302
|
+
refsInChunk += slice.length;
|
|
12303
|
+
start += slice.length;
|
|
12304
|
+
if (refsInChunk === MAX_REFS_PER_BATCH) flush();
|
|
12261
12305
|
}
|
|
12262
12306
|
}
|
|
12263
|
-
|
|
12307
|
+
flush();
|
|
12264
12308
|
for (const chunk of chunks) {
|
|
12265
12309
|
const key = `org:${orgUuid}|${chunk.map(
|
|
12266
12310
|
([workspaceUuid, refs]) => `${workspaceUuid}:${refs.map((ref) => `${ref.kind}|${ref.uuid}`).sort().join(",")}`
|
|
@@ -12911,7 +12955,7 @@ var COLUMNS15 = [
|
|
|
12911
12955
|
];
|
|
12912
12956
|
var aiModelsDomain = {
|
|
12913
12957
|
name: "ai-models",
|
|
12914
|
-
description: `List available AI models (chat, realtime/voice stacks, speaker voices). Use realtime ids as workflow/agent realtimeModelId; voice ids go in realtimeModelConfig.voiceModel. One-shot workflow voice: gr workflows update -d '{"realtimeModelId":"xai:realtime:voice-agent-
|
|
12958
|
+
description: `List available AI models (chat, realtime/voice stacks, speaker voices). Use realtime ids as workflow/agent realtimeModelId; voice ids go in realtimeModelConfig.voiceModel. One-shot workflow voice: gr workflows update -d '{"realtimeModelId":"xai:realtime:voice-agent-3"}' then publish.`,
|
|
12915
12959
|
commands: [
|
|
12916
12960
|
{
|
|
12917
12961
|
path: ["ai-models", "list"],
|
|
@@ -12933,7 +12977,7 @@ var aiModelsDomain = {
|
|
|
12933
12977
|
},
|
|
12934
12978
|
{
|
|
12935
12979
|
path: ["ai-models", "realtime"],
|
|
12936
|
-
description: "List realtime/voice stacks (use as realtimeModelId). e.g. xai:realtime:voice-agent-
|
|
12980
|
+
description: "List realtime/voice stacks (use as realtimeModelId). e.g. xai:realtime:voice-agent-3 = Grok Voice 3 (default). Deprecated models (xai:realtime:voice-agent-2) are not listed.",
|
|
12937
12981
|
requiresWorkspace: false,
|
|
12938
12982
|
handler: async ({ ctx }) => {
|
|
12939
12983
|
const result2 = await requireAuth(ctx).apiClient.getRealtimeModels();
|
|
@@ -14219,7 +14263,9 @@ var memberMemoriesDomain = {
|
|
|
14219
14263
|
{ name: "key", description: "Memory key", required: true },
|
|
14220
14264
|
{
|
|
14221
14265
|
name: "type",
|
|
14222
|
-
|
|
14266
|
+
// The API refuses preferences and semantic deletes (a Member cannot
|
|
14267
|
+
// be shown to own those AgentCore records), so they are not offered.
|
|
14268
|
+
description: "Memory type (basic, summaries, episodic)"
|
|
14223
14269
|
}
|
|
14224
14270
|
],
|
|
14225
14271
|
handler: async ({ ctx, workspace, args }) => {
|
|
@@ -20280,6 +20326,92 @@ async function streamSyncRun(response, verbose) {
|
|
|
20280
20326
|
console.log(JSON.stringify(lastRun, null, 2));
|
|
20281
20327
|
}
|
|
20282
20328
|
}
|
|
20329
|
+
var SYNC_RUN_OPTION_ARGS = [
|
|
20330
|
+
{ name: "dry-run", description: "Test sync without making changes", isFlag: true },
|
|
20331
|
+
{
|
|
20332
|
+
name: "full-resync",
|
|
20333
|
+
description: "Clear checkpoints and re-sync all records",
|
|
20334
|
+
isFlag: true
|
|
20335
|
+
},
|
|
20336
|
+
{ name: "quiet", description: "Only output final result JSON", isFlag: true },
|
|
20337
|
+
{ name: "entity-type", description: "Scope to entity type: member or record" },
|
|
20338
|
+
{
|
|
20339
|
+
name: "board-id",
|
|
20340
|
+
description: "Scope to a single board mapping (requires --entity-type)"
|
|
20341
|
+
},
|
|
20342
|
+
{
|
|
20343
|
+
name: "record-limit",
|
|
20344
|
+
description: "Cap the run to a preview sample (1..200). Requires --dry-run and --entity-type."
|
|
20345
|
+
}
|
|
20346
|
+
];
|
|
20347
|
+
var VALID_ENTITY_TYPES = ["member", "record"];
|
|
20348
|
+
function parseSyncRunOptions(args) {
|
|
20349
|
+
const dryRun = args["dry-run"] === true;
|
|
20350
|
+
const fullResync = args["full-resync"] === true;
|
|
20351
|
+
const quiet = args["quiet"] === true;
|
|
20352
|
+
const rawEntityType = args["entity-type"];
|
|
20353
|
+
let entityType;
|
|
20354
|
+
if (rawEntityType) {
|
|
20355
|
+
if (!VALID_ENTITY_TYPES.includes(rawEntityType)) {
|
|
20356
|
+
throw new CLIError(
|
|
20357
|
+
`Invalid --entity-type "${rawEntityType}". Allowed values: ${VALID_ENTITY_TYPES.join(", ")}`
|
|
20358
|
+
);
|
|
20359
|
+
}
|
|
20360
|
+
entityType = rawEntityType;
|
|
20361
|
+
}
|
|
20362
|
+
const boardId = args["board-id"];
|
|
20363
|
+
const rawRecordLimit = args["record-limit"];
|
|
20364
|
+
let recordLimit;
|
|
20365
|
+
if (rawRecordLimit !== void 0 && rawRecordLimit !== "") {
|
|
20366
|
+
const parsed = Number(rawRecordLimit);
|
|
20367
|
+
if (!Number.isInteger(parsed) || parsed < 1 || parsed > 200) {
|
|
20368
|
+
throw new CLIError(
|
|
20369
|
+
`Invalid --record-limit "${rawRecordLimit}". Must be an integer between 1 and 200.`
|
|
20370
|
+
);
|
|
20371
|
+
}
|
|
20372
|
+
if (!dryRun) {
|
|
20373
|
+
throw new CLIError("--record-limit requires --dry-run: capped runs are preview-only.");
|
|
20374
|
+
}
|
|
20375
|
+
if (entityType === void 0) {
|
|
20376
|
+
throw new CLIError(
|
|
20377
|
+
"--record-limit requires --entity-type: capped previews must target a single entity type."
|
|
20378
|
+
);
|
|
20379
|
+
}
|
|
20380
|
+
recordLimit = parsed;
|
|
20381
|
+
}
|
|
20382
|
+
if (fullResync && (dryRun || recordLimit !== void 0)) {
|
|
20383
|
+
throw new CLIError(
|
|
20384
|
+
"--full-resync is incompatible with --dry-run / --record-limit: checkpoint reset must happen on a non-preview run."
|
|
20385
|
+
);
|
|
20386
|
+
}
|
|
20387
|
+
return { dryRun, fullResync, quiet, entityType, boardId, recordLimit };
|
|
20388
|
+
}
|
|
20389
|
+
async function runSyncAndStream(ctx, workspace, connectionId, options) {
|
|
20390
|
+
const { dryRun, fullResync, quiet, entityType, boardId, recordLimit } = options;
|
|
20391
|
+
if (!quiet) {
|
|
20392
|
+
const flags = [
|
|
20393
|
+
dryRun && "(dry run)",
|
|
20394
|
+
fullResync && "(full re-sync)",
|
|
20395
|
+
entityType && `(${entityType} only)`,
|
|
20396
|
+
boardId && `(board ${boardId})`,
|
|
20397
|
+
recordLimit !== void 0 && `(limit ${recordLimit})`
|
|
20398
|
+
].filter(Boolean).join(" ");
|
|
20399
|
+
console.error(`Starting sync for connection ${connectionId}${flags ? ` ${flags}` : ""}...`);
|
|
20400
|
+
}
|
|
20401
|
+
const response = await requireAuth(ctx).apiClient.startSyncRun(workspace, connectionId, {
|
|
20402
|
+
dryRun,
|
|
20403
|
+
resetCheckpoints: fullResync,
|
|
20404
|
+
entityType,
|
|
20405
|
+
boardId,
|
|
20406
|
+
recordLimit
|
|
20407
|
+
});
|
|
20408
|
+
if (!response.ok) {
|
|
20409
|
+
const text = await response.text();
|
|
20410
|
+
console.error(`Sync failed: ${response.status} ${text}`);
|
|
20411
|
+
process.exit(1);
|
|
20412
|
+
}
|
|
20413
|
+
await streamSyncRun(response, !quiet);
|
|
20414
|
+
}
|
|
20283
20415
|
var syncDomain = {
|
|
20284
20416
|
name: "sync",
|
|
20285
20417
|
description: "Run and monitor connection syncs",
|
|
@@ -20289,22 +20421,7 @@ var syncDomain = {
|
|
|
20289
20421
|
description: "Start a sync run and stream progress (SSE)",
|
|
20290
20422
|
args: [
|
|
20291
20423
|
{ name: "connection-id", description: "Connection ID", required: true },
|
|
20292
|
-
|
|
20293
|
-
{
|
|
20294
|
-
name: "full-resync",
|
|
20295
|
-
description: "Clear checkpoints and re-sync all records",
|
|
20296
|
-
isFlag: true
|
|
20297
|
-
},
|
|
20298
|
-
{ name: "quiet", description: "Only output final result JSON", isFlag: true },
|
|
20299
|
-
{ name: "entity-type", description: "Scope to entity type: member or record" },
|
|
20300
|
-
{
|
|
20301
|
-
name: "board-id",
|
|
20302
|
-
description: "Scope to a single board mapping (requires --entity-type)"
|
|
20303
|
-
},
|
|
20304
|
-
{
|
|
20305
|
-
name: "record-limit",
|
|
20306
|
-
description: "Cap the run to a preview sample (1..200). Requires --dry-run and --entity-type."
|
|
20307
|
-
}
|
|
20424
|
+
...SYNC_RUN_OPTION_ARGS
|
|
20308
20425
|
],
|
|
20309
20426
|
examples: [
|
|
20310
20427
|
"sync run --connection-id 6",
|
|
@@ -20318,76 +20435,7 @@ var syncDomain = {
|
|
|
20318
20435
|
mutates: true,
|
|
20319
20436
|
handler: async ({ ctx, args, workspace }) => {
|
|
20320
20437
|
const connectionId = requireNumber(args, "connection-id");
|
|
20321
|
-
|
|
20322
|
-
const fullResync = args["full-resync"] === true;
|
|
20323
|
-
const quiet = args["quiet"] === true;
|
|
20324
|
-
const VALID_ENTITY_TYPES = ["member", "record"];
|
|
20325
|
-
const rawEntityType = args["entity-type"];
|
|
20326
|
-
let entityType;
|
|
20327
|
-
if (rawEntityType) {
|
|
20328
|
-
if (!VALID_ENTITY_TYPES.includes(rawEntityType)) {
|
|
20329
|
-
throw new CLIError(
|
|
20330
|
-
`Invalid --entity-type "${rawEntityType}". Allowed values: ${VALID_ENTITY_TYPES.join(", ")}`
|
|
20331
|
-
);
|
|
20332
|
-
}
|
|
20333
|
-
entityType = rawEntityType;
|
|
20334
|
-
}
|
|
20335
|
-
const boardId = args["board-id"];
|
|
20336
|
-
const rawRecordLimit = args["record-limit"];
|
|
20337
|
-
let recordLimit;
|
|
20338
|
-
if (rawRecordLimit !== void 0 && rawRecordLimit !== "") {
|
|
20339
|
-
const parsed = Number(rawRecordLimit);
|
|
20340
|
-
if (!Number.isInteger(parsed) || parsed < 1 || parsed > 200) {
|
|
20341
|
-
throw new CLIError(
|
|
20342
|
-
`Invalid --record-limit "${rawRecordLimit}". Must be an integer between 1 and 200.`
|
|
20343
|
-
);
|
|
20344
|
-
}
|
|
20345
|
-
if (!dryRun) {
|
|
20346
|
-
throw new CLIError(
|
|
20347
|
-
"--record-limit requires --dry-run: capped runs are preview-only."
|
|
20348
|
-
);
|
|
20349
|
-
}
|
|
20350
|
-
if (entityType === void 0) {
|
|
20351
|
-
throw new CLIError(
|
|
20352
|
-
"--record-limit requires --entity-type: capped previews must target a single entity type."
|
|
20353
|
-
);
|
|
20354
|
-
}
|
|
20355
|
-
recordLimit = parsed;
|
|
20356
|
-
}
|
|
20357
|
-
if (fullResync && (dryRun || recordLimit !== void 0)) {
|
|
20358
|
-
throw new CLIError(
|
|
20359
|
-
"--full-resync is incompatible with --dry-run / --record-limit: checkpoint reset must happen on a non-preview run."
|
|
20360
|
-
);
|
|
20361
|
-
}
|
|
20362
|
-
if (!quiet) {
|
|
20363
|
-
const flags = [
|
|
20364
|
-
dryRun && "(dry run)",
|
|
20365
|
-
fullResync && "(full re-sync)",
|
|
20366
|
-
entityType && `(${entityType} only)`,
|
|
20367
|
-
boardId && `(board ${boardId})`,
|
|
20368
|
-
recordLimit !== void 0 && `(limit ${recordLimit})`
|
|
20369
|
-
].filter(Boolean).join(" ");
|
|
20370
|
-
console.error(
|
|
20371
|
-
`Starting sync for connection ${connectionId}${flags ? ` ${flags}` : ""}...`
|
|
20372
|
-
);
|
|
20373
|
-
}
|
|
20374
|
-
const response = await requireAuth(ctx).apiClient.startSyncRun(
|
|
20375
|
-
workspace,
|
|
20376
|
-
connectionId,
|
|
20377
|
-
{
|
|
20378
|
-
dryRun,
|
|
20379
|
-
resetCheckpoints: fullResync,
|
|
20380
|
-
entityType,
|
|
20381
|
-
boardId,
|
|
20382
|
-
recordLimit
|
|
20383
|
-
}
|
|
20384
|
-
);
|
|
20385
|
-
if (!response.ok) {
|
|
20386
|
-
const text = await response.text();
|
|
20387
|
-
console.error(`Sync failed: ${response.status} ${text}`);
|
|
20388
|
-
process.exit(1);
|
|
20389
|
-
}
|
|
20390
|
-
await streamSyncRun(response, !quiet);
|
|
20438
|
+
await runSyncAndStream(ctx, workspace, connectionId, parseSyncRunOptions(args));
|
|
20391
20439
|
}
|
|
20392
20440
|
},
|
|
20393
20441
|
{
|
|
@@ -21147,71 +21195,6 @@ var ENCOUNTER_RUN_COLUMNS = [
|
|
|
21147
21195
|
getValue: (item) => summarizeReasons(item.attribution?.collections, "errorReasonCounts")
|
|
21148
21196
|
}
|
|
21149
21197
|
];
|
|
21150
|
-
var ONBOARDING_START_COLUMNS = [
|
|
21151
|
-
{ header: "MODE", getValue: (item) => item.mode ?? "" },
|
|
21152
|
-
{ header: "WORKFLOW ID", getValue: (item) => item.workflowId ?? "" },
|
|
21153
|
-
{ header: "RUN ID", getValue: (item) => item.runId ?? "" }
|
|
21154
|
-
];
|
|
21155
|
-
var ONBOARDING_PAIR_COLUMNS = [
|
|
21156
|
-
{ header: "DEPARTMENT", getValue: (item) => String(item.departmentId ?? "") },
|
|
21157
|
-
{ header: "PATIENT STATUS", getValue: (item) => item.patientStatus ?? "" },
|
|
21158
|
-
{ header: "STATUS", getValue: (item) => item.status ?? "" },
|
|
21159
|
-
{ header: "STOP REASON", getValue: (item) => item.stopReason ?? "" },
|
|
21160
|
-
{ header: "GEN", getValue: (item) => String(item.generation ?? "") },
|
|
21161
|
-
{ header: "NEXT OFFSET", getValue: (item) => String(item.nextOffset ?? "") },
|
|
21162
|
-
{ header: "PAGES (RUN)", getValue: (item) => String(item.pagesDone ?? 0) },
|
|
21163
|
-
{ header: "~FETCHED", getValue: (item) => String(item.totals?.fetched ?? 0) },
|
|
21164
|
-
{ header: "~APPLIED", getValue: (item) => String(item.totals?.applied ?? 0) },
|
|
21165
|
-
{ header: "~SKIPPED", getValue: (item) => String(item.totals?.skipped ?? 0) },
|
|
21166
|
-
{ header: "~FAILED", getValue: (item) => String(item.totals?.failed ?? 0) },
|
|
21167
|
-
{ header: "RUN ID", getValue: (item) => item.runId ?? "" }
|
|
21168
|
-
];
|
|
21169
|
-
var RESUMABLE_PAIR_STATUSES = /* @__PURE__ */ new Set([
|
|
21170
|
-
"failed",
|
|
21171
|
-
"aborted",
|
|
21172
|
-
"truncated",
|
|
21173
|
-
"pending",
|
|
21174
|
-
"running",
|
|
21175
|
-
"waiting"
|
|
21176
|
-
]);
|
|
21177
|
-
function onboardingStatusLines(status, connectionId) {
|
|
21178
|
-
const lines = [];
|
|
21179
|
-
const execution = status.execution;
|
|
21180
|
-
if (execution) {
|
|
21181
|
-
const failure = execution.failureCode ? ` (failure: ${execution.failureCode})` : "";
|
|
21182
|
-
lines.push(
|
|
21183
|
-
`Temporal execution: ${execution.workflowId} run ${execution.runId ?? "-"} \u2014 ${execution.status}${failure}`
|
|
21184
|
-
);
|
|
21185
|
-
} else {
|
|
21186
|
-
lines.push("Temporal execution: none recorded");
|
|
21187
|
-
}
|
|
21188
|
-
if (status.waitingUntil) {
|
|
21189
|
-
lines.push(
|
|
21190
|
-
`Waiting for the operator window (21:00\u201308:00 America/New_York) until ${status.waitingUntil}`
|
|
21191
|
-
);
|
|
21192
|
-
}
|
|
21193
|
-
if (status.preview) {
|
|
21194
|
-
const previewPairs = status.preview.pairs ?? [];
|
|
21195
|
-
const admitted = previewPairs.reduce((n, p) => n + (p.totals?.admitted ?? 0), 0);
|
|
21196
|
-
const notAdmitted = previewPairs.reduce(
|
|
21197
|
-
(n, p) => n + (p.totals?.notAdmitted ?? 0),
|
|
21198
|
-
0
|
|
21199
|
-
);
|
|
21200
|
-
lines.push(
|
|
21201
|
-
`Latest preview: ${previewPairs.length} pair(s), ~${admitted} admission-eligible (incl. already-linked), ~${notAdmitted} not admitted (read-only)`
|
|
21202
|
-
);
|
|
21203
|
-
}
|
|
21204
|
-
lines.push("Counts are approximate.");
|
|
21205
|
-
const unfinished = (status.pairs ?? []).some(
|
|
21206
|
-
(p) => p.inCurrentCohort && RESUMABLE_PAIR_STATUSES.has(p.status) && p.runId
|
|
21207
|
-
);
|
|
21208
|
-
if (unfinished && execution?.status !== "running") {
|
|
21209
|
-
lines.push(
|
|
21210
|
-
`Unfinished pairs continue only on an explicit resume: gr fhir-connections onboarding-import start --id ${connectionId} --resume --allow-write`
|
|
21211
|
-
);
|
|
21212
|
-
}
|
|
21213
|
-
return lines;
|
|
21214
|
-
}
|
|
21215
21198
|
var fhirConnectionsDomain = {
|
|
21216
21199
|
name: "fhir-connections",
|
|
21217
21200
|
description: "Manage FHIR connections",
|
|
@@ -21269,77 +21252,6 @@ var fhirConnectionsDomain = {
|
|
|
21269
21252
|
);
|
|
21270
21253
|
outputData(runs, ctx, ENCOUNTER_RUN_COLUMNS);
|
|
21271
21254
|
}
|
|
21272
|
-
},
|
|
21273
|
-
{
|
|
21274
|
-
// athenahealth onboarding import (PR-C): one explicit, audited
|
|
21275
|
-
// operator execution per connection, at most 50 pages per pair per
|
|
21276
|
-
// run. Thin over the SDK; the server decides everything.
|
|
21277
|
-
path: ["fhir-connections", "onboarding-import", "start"],
|
|
21278
|
-
description: "Start an athenahealth onboarding import (or --resume / --override / --dry-run preview)",
|
|
21279
|
-
requiresWorkspace: true,
|
|
21280
|
-
mutates: true,
|
|
21281
|
-
args: [
|
|
21282
|
-
{ name: "id", description: "FHIR connection ID", required: true },
|
|
21283
|
-
{
|
|
21284
|
-
name: "dry-run",
|
|
21285
|
-
description: "Preview: read and classify admission only, write no Members",
|
|
21286
|
-
isFlag: true
|
|
21287
|
-
},
|
|
21288
|
-
{
|
|
21289
|
-
name: "resume",
|
|
21290
|
-
description: "Continue unfinished (failed, truncated, aborted) pairs at their stored frontier",
|
|
21291
|
-
isFlag: true
|
|
21292
|
-
},
|
|
21293
|
-
{
|
|
21294
|
-
name: "override",
|
|
21295
|
-
description: "Rescan completed pairs from offset 0 under a new generation",
|
|
21296
|
-
isFlag: true
|
|
21297
|
-
}
|
|
21298
|
-
],
|
|
21299
|
-
examples: [
|
|
21300
|
-
"fhir-connections onboarding-import start --id 12 --dry-run --allow-write",
|
|
21301
|
-
"fhir-connections onboarding-import start --id 12 --allow-write",
|
|
21302
|
-
"fhir-connections onboarding-import start --id 12 --resume --allow-write"
|
|
21303
|
-
],
|
|
21304
|
-
handler: async ({ ctx, workspace, args }) => {
|
|
21305
|
-
const connectionId = requireNumber(args, "id");
|
|
21306
|
-
const started = await requireAuth(ctx).apiClient.fhirStartOnboardingImport(
|
|
21307
|
-
workspace,
|
|
21308
|
-
connectionId,
|
|
21309
|
-
{
|
|
21310
|
-
dryRun: args["dry-run"] === true,
|
|
21311
|
-
resume: args["resume"] === true,
|
|
21312
|
-
override: args["override"] === true
|
|
21313
|
-
}
|
|
21314
|
-
);
|
|
21315
|
-
outputSingle(started, ctx, ONBOARDING_START_COLUMNS);
|
|
21316
|
-
hint(ctx, [
|
|
21317
|
-
`Started. Follow progress with: gr fhir-connections onboarding-import status --id ${connectionId}`
|
|
21318
|
-
]);
|
|
21319
|
-
}
|
|
21320
|
-
},
|
|
21321
|
-
{
|
|
21322
|
-
path: ["fhir-connections", "onboarding-import", "status"],
|
|
21323
|
-
description: "Show athenahealth onboarding-import progress and its Temporal execution (read-only)",
|
|
21324
|
-
requiresWorkspace: true,
|
|
21325
|
-
args: [{ name: "id", description: "FHIR connection ID", required: true }],
|
|
21326
|
-
examples: [
|
|
21327
|
-
"fhir-connections onboarding-import status --id 12",
|
|
21328
|
-
"fhir-connections onboarding-import status --id 12 --output-format json"
|
|
21329
|
-
],
|
|
21330
|
-
handler: async ({ ctx, workspace, args }) => {
|
|
21331
|
-
const connectionId = requireNumber(args, "id");
|
|
21332
|
-
const status = await requireAuth(ctx).apiClient.fhirGetOnboardingImportStatus(
|
|
21333
|
-
workspace,
|
|
21334
|
-
connectionId
|
|
21335
|
-
);
|
|
21336
|
-
if (ctx.jq || (ctx.outputFormat ?? "table") !== "table") {
|
|
21337
|
-
outputSingle(status, ctx);
|
|
21338
|
-
return;
|
|
21339
|
-
}
|
|
21340
|
-
outputData(status.pairs, ctx, ONBOARDING_PAIR_COLUMNS);
|
|
21341
|
-
hint(ctx, onboardingStatusLines(status, connectionId));
|
|
21342
|
-
}
|
|
21343
21255
|
}
|
|
21344
21256
|
]
|
|
21345
21257
|
};
|
|
@@ -21664,7 +21576,312 @@ var documoFaxDomain = {
|
|
|
21664
21576
|
]
|
|
21665
21577
|
};
|
|
21666
21578
|
|
|
21579
|
+
// src/domains/integrations/connection-commands.ts
|
|
21580
|
+
var POLL_INTERVAL_MIN_MINUTES = 15;
|
|
21581
|
+
var POLL_INTERVAL_MAX_MINUTES = 1440;
|
|
21582
|
+
function connectionIdArg(target) {
|
|
21583
|
+
return {
|
|
21584
|
+
name: "connection-id",
|
|
21585
|
+
description: `Connection ID (default: the workspace's ${target.label} connection)`
|
|
21586
|
+
};
|
|
21587
|
+
}
|
|
21588
|
+
async function resolveConnectionId(ctx, workspace, target, args) {
|
|
21589
|
+
const explicit = optionalNumber(args, "connection-id");
|
|
21590
|
+
if (explicit !== void 0) return explicit;
|
|
21591
|
+
const connections = await requireAuth(ctx).apiClient.listAppConnections(workspace);
|
|
21592
|
+
const matches = connections.filter((c) => c.connectionType === target.connectionType);
|
|
21593
|
+
if (matches.length === 0) {
|
|
21594
|
+
throw new CLIError(
|
|
21595
|
+
`No ${target.label} connection in this workspace. Run: gr ${target.command} install`
|
|
21596
|
+
);
|
|
21597
|
+
}
|
|
21598
|
+
if (matches.length > 1) {
|
|
21599
|
+
const ids = matches.map((c) => c.id).join(", ");
|
|
21600
|
+
throw new CLIError(
|
|
21601
|
+
`This workspace has ${matches.length} ${target.label} connections (${ids}). Pass --connection-id.`
|
|
21602
|
+
);
|
|
21603
|
+
}
|
|
21604
|
+
return matches[0].id;
|
|
21605
|
+
}
|
|
21606
|
+
function parsePollInterval(raw) {
|
|
21607
|
+
const minutes = Number(raw);
|
|
21608
|
+
if (!Number.isInteger(minutes) || minutes < POLL_INTERVAL_MIN_MINUTES || minutes > POLL_INTERVAL_MAX_MINUTES) {
|
|
21609
|
+
throw new CLIError(
|
|
21610
|
+
`Invalid --poll-interval "${String(raw)}". Must be a whole number of minutes between ${POLL_INTERVAL_MIN_MINUTES} and ${POLL_INTERVAL_MAX_MINUTES}.`
|
|
21611
|
+
);
|
|
21612
|
+
}
|
|
21613
|
+
return minutes;
|
|
21614
|
+
}
|
|
21615
|
+
function connectionCommands(target) {
|
|
21616
|
+
const c = target.command;
|
|
21617
|
+
const connectionId = connectionIdArg(target);
|
|
21618
|
+
return [
|
|
21619
|
+
{
|
|
21620
|
+
path: [c, "sync-config", "get"],
|
|
21621
|
+
description: `Get the ${target.label} sync configuration`,
|
|
21622
|
+
requiresWorkspace: true,
|
|
21623
|
+
args: [connectionId],
|
|
21624
|
+
handler: async ({ ctx, workspace, args }) => {
|
|
21625
|
+
const id = await resolveConnectionId(ctx, workspace, target, args);
|
|
21626
|
+
const result2 = await requireAuth(ctx).apiClient.getConnectionSyncConfig(workspace, id);
|
|
21627
|
+
outputSingle(result2, ctx);
|
|
21628
|
+
}
|
|
21629
|
+
},
|
|
21630
|
+
{
|
|
21631
|
+
path: [c, "sync-config", "set"],
|
|
21632
|
+
// `sync-config get -o json | … | sync-config set` pipes the whole
|
|
21633
|
+
// configuration; with --poll-interval alone there is no body to wait for.
|
|
21634
|
+
pipesJsonInput: (args) => args["poll-interval"] === void 0,
|
|
21635
|
+
description: `Replace the ${target.label} sync configuration (--data), or change one setting of the saved configuration (--poll-interval)`,
|
|
21636
|
+
mutates: true,
|
|
21637
|
+
requiresWorkspace: true,
|
|
21638
|
+
args: [
|
|
21639
|
+
connectionId,
|
|
21640
|
+
{
|
|
21641
|
+
name: "poll-interval",
|
|
21642
|
+
description: `Inbound poll cadence in minutes (${POLL_INTERVAL_MIN_MINUTES}..${POLL_INTERVAL_MAX_MINUTES}). Without --data, updates the saved configuration.`
|
|
21643
|
+
}
|
|
21644
|
+
],
|
|
21645
|
+
examples: [
|
|
21646
|
+
`gr ${c} sync-config get -w <ws> -o json > sync-config.json`,
|
|
21647
|
+
`gr ${c} sync-config set -w <ws> --allow-write --file sync-config.json`,
|
|
21648
|
+
`gr ${c} sync-config set -w <ws> --allow-write --poll-interval 60`
|
|
21649
|
+
],
|
|
21650
|
+
handler: async ({ ctx, workspace, args, data }) => {
|
|
21651
|
+
const rawInterval = args["poll-interval"];
|
|
21652
|
+
const hasInterval = rawInterval !== void 0 && rawInterval !== "";
|
|
21653
|
+
if (!data && !hasInterval) {
|
|
21654
|
+
throw new CLIError(
|
|
21655
|
+
"Pass the configuration (--data, --file, or stdin) or --poll-interval"
|
|
21656
|
+
);
|
|
21657
|
+
}
|
|
21658
|
+
if (data !== void 0 && (typeof data !== "object" || data === null || Array.isArray(data) || Object.keys(data).length === 0)) {
|
|
21659
|
+
throw new CLIError(
|
|
21660
|
+
"The configuration must be a non-empty JSON object (start from `sync-config get -o json`)"
|
|
21661
|
+
);
|
|
21662
|
+
}
|
|
21663
|
+
const minutes = hasInterval ? parsePollInterval(rawInterval) : void 0;
|
|
21664
|
+
const api = requireAuth(ctx).apiClient;
|
|
21665
|
+
const id = await resolveConnectionId(ctx, workspace, target, args);
|
|
21666
|
+
const base = data ?? await api.getConnectionSyncConfig(workspace, id);
|
|
21667
|
+
const config = minutes === void 0 ? base : { ...base, inboundPollIntervalMinutes: minutes };
|
|
21668
|
+
const result2 = await api.updateConnectionSyncConfig(workspace, id, config);
|
|
21669
|
+
outputSingle(result2, ctx);
|
|
21670
|
+
}
|
|
21671
|
+
},
|
|
21672
|
+
{
|
|
21673
|
+
path: [c, "sync", "capabilities"],
|
|
21674
|
+
description: `What the ${target.label} sync engine supports (entities, directions, modes)`,
|
|
21675
|
+
requiresWorkspace: true,
|
|
21676
|
+
args: [connectionId],
|
|
21677
|
+
handler: async ({ ctx, workspace, args }) => {
|
|
21678
|
+
const id = await resolveConnectionId(ctx, workspace, target, args);
|
|
21679
|
+
const result2 = await requireAuth(ctx).apiClient.getConnectionSyncCapabilities(
|
|
21680
|
+
workspace,
|
|
21681
|
+
id
|
|
21682
|
+
);
|
|
21683
|
+
outputSingle(result2, ctx);
|
|
21684
|
+
}
|
|
21685
|
+
},
|
|
21686
|
+
{
|
|
21687
|
+
path: [c, "sync", "run"],
|
|
21688
|
+
description: `Start a ${target.label} sync run and stream its progress`,
|
|
21689
|
+
mutates: true,
|
|
21690
|
+
requiresWorkspace: true,
|
|
21691
|
+
args: [connectionId, ...SYNC_RUN_OPTION_ARGS],
|
|
21692
|
+
examples: [
|
|
21693
|
+
`gr ${c} sync run -w <ws> --allow-write --dry-run --entity-type member --record-limit 5`,
|
|
21694
|
+
`gr ${c} sync run -w <ws> --allow-write`,
|
|
21695
|
+
`gr ${c} sync run -w <ws> --allow-write --full-resync --quiet`
|
|
21696
|
+
],
|
|
21697
|
+
handler: async ({ ctx, workspace, args }) => {
|
|
21698
|
+
const options = parseSyncRunOptions(args);
|
|
21699
|
+
const id = await resolveConnectionId(ctx, workspace, target, args);
|
|
21700
|
+
await runSyncAndStream(ctx, workspace, id, options);
|
|
21701
|
+
}
|
|
21702
|
+
},
|
|
21703
|
+
{
|
|
21704
|
+
path: [c, "sync", "runs"],
|
|
21705
|
+
description: `List recent ${target.label} sync runs`,
|
|
21706
|
+
requiresWorkspace: true,
|
|
21707
|
+
args: [connectionId, { name: "limit", description: "Max runs to return (default 20)" }],
|
|
21708
|
+
handler: async ({ ctx, workspace, args }) => {
|
|
21709
|
+
const id = await resolveConnectionId(ctx, workspace, target, args);
|
|
21710
|
+
const runs = await requireAuth(ctx).apiClient.getSyncRuns(
|
|
21711
|
+
workspace,
|
|
21712
|
+
id,
|
|
21713
|
+
optionalNumber(args, "limit") ?? 20
|
|
21714
|
+
);
|
|
21715
|
+
outputData(runs, ctx, RUN_COLUMNS2);
|
|
21716
|
+
}
|
|
21717
|
+
},
|
|
21718
|
+
{
|
|
21719
|
+
path: [c, "sync", "run-items"],
|
|
21720
|
+
description: `List the items of one ${target.label} sync run`,
|
|
21721
|
+
requiresWorkspace: true,
|
|
21722
|
+
args: [
|
|
21723
|
+
connectionId,
|
|
21724
|
+
{ name: "run-id", description: "Run ID (from sync runs)", required: true },
|
|
21725
|
+
{ name: "limit", description: "Max items to return (default 500)" }
|
|
21726
|
+
],
|
|
21727
|
+
handler: async ({ ctx, workspace, args }) => {
|
|
21728
|
+
const runId = requireString(args, "run-id");
|
|
21729
|
+
const id = await resolveConnectionId(ctx, workspace, target, args);
|
|
21730
|
+
const items = await requireAuth(ctx).apiClient.getSyncRunItems(
|
|
21731
|
+
workspace,
|
|
21732
|
+
id,
|
|
21733
|
+
runId,
|
|
21734
|
+
optionalNumber(args, "limit") ?? 500
|
|
21735
|
+
);
|
|
21736
|
+
outputData(items, ctx, ITEM_COLUMNS2);
|
|
21737
|
+
}
|
|
21738
|
+
},
|
|
21739
|
+
{
|
|
21740
|
+
path: [c, "sync", "checkpoint"],
|
|
21741
|
+
description: `Show the ${target.label} sync checkpoint (where the next run resumes)`,
|
|
21742
|
+
requiresWorkspace: true,
|
|
21743
|
+
args: [
|
|
21744
|
+
connectionId,
|
|
21745
|
+
{ name: "direction", description: "'inbound' (default) or 'outbound'" },
|
|
21746
|
+
{ name: "sync-key", description: "Sync key (default 'default')" }
|
|
21747
|
+
],
|
|
21748
|
+
handler: async ({ ctx, workspace, args }) => {
|
|
21749
|
+
const direction = args["direction"] ?? "inbound";
|
|
21750
|
+
if (direction !== "inbound" && direction !== "outbound") {
|
|
21751
|
+
throw new CLIError(
|
|
21752
|
+
`--direction must be 'inbound' or 'outbound', got '${direction}'`
|
|
21753
|
+
);
|
|
21754
|
+
}
|
|
21755
|
+
const id = await resolveConnectionId(ctx, workspace, target, args);
|
|
21756
|
+
const result2 = await requireAuth(ctx).apiClient.getConnectionSyncCheckpoint(
|
|
21757
|
+
workspace,
|
|
21758
|
+
id,
|
|
21759
|
+
direction,
|
|
21760
|
+
args["sync-key"] ?? "default"
|
|
21761
|
+
);
|
|
21762
|
+
outputSingle(result2, ctx);
|
|
21763
|
+
}
|
|
21764
|
+
},
|
|
21765
|
+
{
|
|
21766
|
+
path: [c, "sync", "member-summary"],
|
|
21767
|
+
description: `Count members by ${target.label} sync state (linked, failed, never synced)`,
|
|
21768
|
+
requiresWorkspace: true,
|
|
21769
|
+
args: [connectionId],
|
|
21770
|
+
handler: async ({ ctx, workspace, args }) => {
|
|
21771
|
+
const id = await resolveConnectionId(ctx, workspace, target, args);
|
|
21772
|
+
const result2 = await requireAuth(ctx).apiClient.getMemberSyncSummary(workspace, id);
|
|
21773
|
+
outputSingle(result2, ctx);
|
|
21774
|
+
}
|
|
21775
|
+
},
|
|
21776
|
+
{
|
|
21777
|
+
path: [c, "field-keys"],
|
|
21778
|
+
description: `List the Member field keys the ${target.label} connection holds values for`,
|
|
21779
|
+
requiresWorkspace: true,
|
|
21780
|
+
args: [connectionId],
|
|
21781
|
+
handler: async ({ ctx, workspace, args }) => {
|
|
21782
|
+
const id = await resolveConnectionId(ctx, workspace, target, args);
|
|
21783
|
+
const result2 = await requireAuth(ctx).apiClient.listConnectionMemberFieldKeys(
|
|
21784
|
+
workspace,
|
|
21785
|
+
id
|
|
21786
|
+
);
|
|
21787
|
+
outputData(result2.keys, ctx);
|
|
21788
|
+
}
|
|
21789
|
+
},
|
|
21790
|
+
{
|
|
21791
|
+
path: [c, "reconciliation", "relink"],
|
|
21792
|
+
description: `Let sync re-link a member you unlinked from ${target.label} (clears the manual-unlink exclusion). Idempotent: cleared=false when there was none.`,
|
|
21793
|
+
mutates: true,
|
|
21794
|
+
requiresWorkspace: true,
|
|
21795
|
+
args: [connectionId, { name: "member-id", description: "Member ID", required: true }],
|
|
21796
|
+
handler: async ({ ctx, workspace, args }) => {
|
|
21797
|
+
const memberId = requireNumber(args, "member-id");
|
|
21798
|
+
const id = await resolveConnectionId(ctx, workspace, target, args);
|
|
21799
|
+
const result2 = await requireAuth(ctx).apiClient.clearConnectionMemberExclusion(
|
|
21800
|
+
workspace,
|
|
21801
|
+
id,
|
|
21802
|
+
memberId
|
|
21803
|
+
);
|
|
21804
|
+
outputSingle(result2, ctx);
|
|
21805
|
+
}
|
|
21806
|
+
},
|
|
21807
|
+
{
|
|
21808
|
+
path: [c, "reconciliation", "link-by-identity"],
|
|
21809
|
+
description: `Start the background run that links unlinked members to their ${target.label} records by identity, then syncs them. Prints the run's workflowId. Refused (400) when the connector has no identity resolver, and (409) while the connection is disabled or a run is already in flight.`,
|
|
21810
|
+
mutates: true,
|
|
21811
|
+
requiresWorkspace: true,
|
|
21812
|
+
args: [connectionId],
|
|
21813
|
+
examples: [
|
|
21814
|
+
`gr ${c} reconciliation link-by-identity -w <ws> --allow-write`,
|
|
21815
|
+
`gr ${c} reconciliation linked -w <ws> # check the new links afterwards`
|
|
21816
|
+
],
|
|
21817
|
+
handler: async ({ ctx, workspace, args }) => {
|
|
21818
|
+
const id = await resolveConnectionId(ctx, workspace, target, args);
|
|
21819
|
+
const result2 = await requireAuth(ctx).apiClient.linkUnlinkedMembersByIdentity(
|
|
21820
|
+
workspace,
|
|
21821
|
+
id
|
|
21822
|
+
);
|
|
21823
|
+
outputSingle(result2, ctx);
|
|
21824
|
+
}
|
|
21825
|
+
}
|
|
21826
|
+
];
|
|
21827
|
+
}
|
|
21828
|
+
|
|
21667
21829
|
// src/domains/integrations/hubspot.ts
|
|
21830
|
+
var HUBSPOT = {
|
|
21831
|
+
command: "hubspot",
|
|
21832
|
+
label: "HubSpot",
|
|
21833
|
+
connectionType: "hubspot_connection"
|
|
21834
|
+
};
|
|
21835
|
+
var OBJECT_TYPES = ["contacts", "companies", "deals"];
|
|
21836
|
+
var SEARCHABLE_OBJECT_TYPES = ["contacts", "companies"];
|
|
21837
|
+
var SEARCH_COLUMNS = [
|
|
21838
|
+
{ header: "ID", getValue: (item) => item.id ?? "" },
|
|
21839
|
+
{ header: "TYPE", getValue: (item) => item.objectType ?? "" },
|
|
21840
|
+
{ header: "NAME", getValue: (item) => item.name ?? "" },
|
|
21841
|
+
{ header: "EMAIL", getValue: (item) => item.email ?? "" },
|
|
21842
|
+
{
|
|
21843
|
+
header: "MEMBER",
|
|
21844
|
+
getValue: (item) => item.existingMember ? `${item.existingMember.memberId} (${item.existingMember.matchType})` : ""
|
|
21845
|
+
}
|
|
21846
|
+
];
|
|
21847
|
+
var MATCH_COLUMNS2 = [
|
|
21848
|
+
{ header: "MEMBER", getValue: (item) => String(item.memberId ?? "") },
|
|
21849
|
+
{ header: "RECORD", getValue: (item) => item.hubspotRecordId ?? "" },
|
|
21850
|
+
{ header: "MATCH", getValue: (item) => item.matchType ?? "" },
|
|
21851
|
+
{ header: "OBJECT", getValue: (item) => item.objectType ?? "" }
|
|
21852
|
+
];
|
|
21853
|
+
var LINKED_COLUMNS2 = [
|
|
21854
|
+
{ header: "MEMBER", getValue: (item) => String(item.memberId ?? "") },
|
|
21855
|
+
{ header: "RECORD", getValue: (item) => item.hubspotRecordId ?? "" },
|
|
21856
|
+
{ header: "NAME", getValue: (item) => item.memberName ?? "" },
|
|
21857
|
+
{ header: "LAST SYNC", getValue: (item) => item.lastSyncStatus ?? "" }
|
|
21858
|
+
];
|
|
21859
|
+
var IMPORT_COLUMNS = [
|
|
21860
|
+
{ header: "HUBSPOT ID", getValue: (item) => item.hubspotId ?? "" },
|
|
21861
|
+
{ header: "MEMBER", getValue: (item) => String(item.memberId ?? "") },
|
|
21862
|
+
{ header: "OK", getValue: (item) => item.success ? "yes" : "no" },
|
|
21863
|
+
{ header: "ERROR", getValue: (item) => item.error ?? "" }
|
|
21864
|
+
];
|
|
21865
|
+
function importRecordsFrom(data) {
|
|
21866
|
+
const body = data;
|
|
21867
|
+
const rows = Array.isArray(body) ? body : Array.isArray(body?.records) ? body.records : Array.isArray(body?.results) ? body.results : void 0;
|
|
21868
|
+
if (!rows) {
|
|
21869
|
+
throw new CLIError(
|
|
21870
|
+
'JSON input must be {"records":[...]}, a `gr hubspot search -o json` response, or an array'
|
|
21871
|
+
);
|
|
21872
|
+
}
|
|
21873
|
+
return rows.map((row, index) => {
|
|
21874
|
+
const hubspotId = row?.hubspotId ?? row?.id;
|
|
21875
|
+
if (!hubspotId) throw new CLIError(`Record ${index} has no hubspotId (or id)`);
|
|
21876
|
+
return {
|
|
21877
|
+
hubspotId: String(hubspotId),
|
|
21878
|
+
name: row.name ?? null,
|
|
21879
|
+
email: row.email ?? null,
|
|
21880
|
+
phone: row.phone ?? null,
|
|
21881
|
+
objectType: row.objectType ?? "contacts"
|
|
21882
|
+
};
|
|
21883
|
+
});
|
|
21884
|
+
}
|
|
21668
21885
|
var hubspotDomain = {
|
|
21669
21886
|
name: "hubspot",
|
|
21670
21887
|
description: "HubSpot CRM integration",
|
|
@@ -21676,18 +21893,21 @@ var hubspotDomain = {
|
|
|
21676
21893
|
requiresWorkspace: true,
|
|
21677
21894
|
examples: [
|
|
21678
21895
|
"# When the response shows platformAppAvailable=true, the workspace connects through",
|
|
21679
|
-
"# the shared Gravity Rail HubSpot app:
|
|
21680
|
-
"gr hubspot
|
|
21681
|
-
"gr hubspot authorize -w <ws> --allow-write # then open the returned authorizeUrl",
|
|
21896
|
+
"# the shared Gravity Rail HubSpot app: one command, then open the authorizeUrl.",
|
|
21897
|
+
"gr hubspot connect -w <ws> --allow-write",
|
|
21682
21898
|
"",
|
|
21683
21899
|
"# To use your own HubSpot app instead (a Projects-platform app; HubSpot no longer",
|
|
21684
21900
|
"# allows new private or developer apps):",
|
|
21685
21901
|
'# 1. install -> creates the connection; the response includes the OAuth "callbackUrl"',
|
|
21686
21902
|
"# 2. in HubSpot: give your app that callbackUrl as a Redirect URL, with CRM scopes",
|
|
21687
|
-
"# (contacts/companies/deals read+write)
|
|
21903
|
+
"# (contacts/companies/deals read+write), plus crm.lists.read and",
|
|
21904
|
+
"# crm.objects.owners.read, forms, and scheduler.meetings.meeting-link.read",
|
|
21905
|
+
"# as OPTIONAL scopes (HubSpot rejects the authorize",
|
|
21906
|
+
"# request if the app lacks them).",
|
|
21907
|
+
"# Copy the Client ID + Secret.",
|
|
21688
21908
|
"# 3. configure -> save that Client ID / Secret",
|
|
21689
21909
|
'# 4. authorize -> returns an "authorizeUrl"; open it to grant access.',
|
|
21690
|
-
"gr hubspot
|
|
21910
|
+
"gr hubspot install -w <ws> --allow-write",
|
|
21691
21911
|
`gr hubspot configure -w <ws> --allow-write -d '{"clientId":"...","clientSecret":"..."}'`,
|
|
21692
21912
|
"gr hubspot authorize -w <ws> --allow-write # then open the returned authorizeUrl"
|
|
21693
21913
|
],
|
|
@@ -21696,6 +21916,33 @@ var hubspotDomain = {
|
|
|
21696
21916
|
outputSingle(result2, ctx);
|
|
21697
21917
|
}
|
|
21698
21918
|
},
|
|
21919
|
+
{
|
|
21920
|
+
path: ["hubspot", "connect"],
|
|
21921
|
+
description: "Install HubSpot if needed and start OAuth: prints the authorizeUrl to open and the exact callbackUrl the HubSpot app must allow",
|
|
21922
|
+
mutates: true,
|
|
21923
|
+
requiresWorkspace: true,
|
|
21924
|
+
examples: ["gr hubspot connect -w <ws> --allow-write"],
|
|
21925
|
+
handler: async ({ ctx, workspace }) => {
|
|
21926
|
+
const api = requireAuth(ctx).apiClient;
|
|
21927
|
+
const installed = await api.installHubspot(workspace);
|
|
21928
|
+
if (!installed.configured) {
|
|
21929
|
+
outputSingle(installed, ctx);
|
|
21930
|
+
throw new CLIError(
|
|
21931
|
+
"HubSpot is installed but has no app credentials. Register the callbackUrl above on your HubSpot app, then run: gr hubspot configure, then gr hubspot connect"
|
|
21932
|
+
);
|
|
21933
|
+
}
|
|
21934
|
+
const started = await api.startHubspotOAuth(workspace);
|
|
21935
|
+
outputSingle(
|
|
21936
|
+
{
|
|
21937
|
+
connectionId: started.connectionId,
|
|
21938
|
+
usesPlatformApp: started.usesPlatformApp,
|
|
21939
|
+
callbackUrl: started.callbackUrl,
|
|
21940
|
+
authorizeUrl: started.authorizeUrl
|
|
21941
|
+
},
|
|
21942
|
+
ctx
|
|
21943
|
+
);
|
|
21944
|
+
}
|
|
21945
|
+
},
|
|
21699
21946
|
{
|
|
21700
21947
|
path: ["hubspot", "status"],
|
|
21701
21948
|
description: "Get HubSpot connection status (shows configured/connected state + the OAuth callback URL)",
|
|
@@ -21707,6 +21954,8 @@ var hubspotDomain = {
|
|
|
21707
21954
|
},
|
|
21708
21955
|
{
|
|
21709
21956
|
path: ["hubspot", "configure"],
|
|
21957
|
+
// Reads its body from --data, --file or piped stdin.
|
|
21958
|
+
acceptsJsonInput: true,
|
|
21710
21959
|
description: "Configure HubSpot credentials (setup step 3): save the Client ID / Secret",
|
|
21711
21960
|
mutates: true,
|
|
21712
21961
|
requiresWorkspace: true,
|
|
@@ -21734,7 +21983,7 @@ var hubspotDomain = {
|
|
|
21734
21983
|
},
|
|
21735
21984
|
{
|
|
21736
21985
|
path: ["hubspot", "disconnect"],
|
|
21737
|
-
description: "Disconnect HubSpot",
|
|
21986
|
+
description: "Disconnect HubSpot: clear the stored OAuth tokens and return the connection to setup (HubSpot keeps the app install)",
|
|
21738
21987
|
mutates: true,
|
|
21739
21988
|
requiresWorkspace: true,
|
|
21740
21989
|
handler: async ({ ctx, workspace }) => {
|
|
@@ -21773,121 +22022,270 @@ var hubspotDomain = {
|
|
|
21773
22022
|
}
|
|
21774
22023
|
},
|
|
21775
22024
|
{
|
|
21776
|
-
path: ["hubspot", "
|
|
21777
|
-
description: "
|
|
22025
|
+
path: ["hubspot", "search"],
|
|
22026
|
+
description: "Search HubSpot contacts or companies; each result shows the workspace member it matches",
|
|
21778
22027
|
requiresWorkspace: true,
|
|
21779
|
-
|
|
21780
|
-
|
|
21781
|
-
|
|
21782
|
-
|
|
21783
|
-
|
|
21784
|
-
|
|
21785
|
-
|
|
21786
|
-
|
|
21787
|
-
|
|
22028
|
+
args: [
|
|
22029
|
+
{
|
|
22030
|
+
name: "query",
|
|
22031
|
+
description: "Contacts whose email, or companies whose name, contains this text; empty lists all"
|
|
22032
|
+
},
|
|
22033
|
+
{ name: "object-type", description: "'contacts' (default) or 'companies'" },
|
|
22034
|
+
{ name: "limit", description: "Max results (1..100, default 20)" },
|
|
22035
|
+
{
|
|
22036
|
+
name: "after",
|
|
22037
|
+
description: "Cursor from a previous page (nextCursor); only without --query"
|
|
22038
|
+
}
|
|
22039
|
+
],
|
|
22040
|
+
examples: [
|
|
22041
|
+
"gr hubspot search -w <ws> --query smith",
|
|
22042
|
+
"gr hubspot search -w <ws> --object-type companies --limit 50"
|
|
22043
|
+
],
|
|
22044
|
+
handler: async ({ ctx, workspace, args }) => {
|
|
22045
|
+
const objectType = args["object-type"] ?? "contacts";
|
|
22046
|
+
if (!SEARCHABLE_OBJECT_TYPES.includes(objectType)) {
|
|
22047
|
+
throw new CLIError(
|
|
22048
|
+
`--object-type must be one of ${SEARCHABLE_OBJECT_TYPES.join(", ")}, got '${objectType}'`
|
|
22049
|
+
);
|
|
22050
|
+
}
|
|
22051
|
+
if (args["query"] && args["after"]) {
|
|
22052
|
+
throw new CLIError("--after pages only the listing without --query");
|
|
22053
|
+
}
|
|
22054
|
+
const result2 = await requireAuth(ctx).apiClient.searchHubspotRecords(workspace, {
|
|
22055
|
+
query: args["query"] ?? "",
|
|
22056
|
+
objectType,
|
|
22057
|
+
limit: optionalNumber(args, "limit") ?? 20,
|
|
22058
|
+
...args["after"] ? { after: String(args["after"]) } : {}
|
|
22059
|
+
});
|
|
22060
|
+
if (ctx.outputFormat !== "table") {
|
|
22061
|
+
outputSingle(result2, ctx);
|
|
22062
|
+
return;
|
|
22063
|
+
}
|
|
22064
|
+
outputData(result2.results, ctx, SEARCH_COLUMNS);
|
|
22065
|
+
if (result2.hasMore && result2.nextCursor && !args["query"]) {
|
|
22066
|
+
console.error(`More results: --after ${result2.nextCursor}`);
|
|
22067
|
+
}
|
|
21788
22068
|
}
|
|
21789
22069
|
},
|
|
21790
22070
|
{
|
|
21791
|
-
path: ["hubspot", "
|
|
21792
|
-
|
|
22071
|
+
path: ["hubspot", "import-members"],
|
|
22072
|
+
// Its input is usually the previous command's output: wait for the pipe.
|
|
22073
|
+
pipesJsonInput: true,
|
|
22074
|
+
description: "Create (or update and link) workspace members from HubSpot records (max 100 per call)",
|
|
21793
22075
|
mutates: true,
|
|
21794
22076
|
requiresWorkspace: true,
|
|
21795
|
-
|
|
21796
|
-
|
|
21797
|
-
|
|
21798
|
-
|
|
21799
|
-
|
|
21800
|
-
|
|
21801
|
-
|
|
21802
|
-
|
|
21803
|
-
|
|
21804
|
-
|
|
21805
|
-
|
|
22077
|
+
args: [
|
|
22078
|
+
{
|
|
22079
|
+
name: "member-role-id",
|
|
22080
|
+
description: "Member role for new members (overrides memberRoleId in the body)"
|
|
22081
|
+
},
|
|
22082
|
+
{
|
|
22083
|
+
name: "ids",
|
|
22084
|
+
description: "Comma-separated HubSpot IDs: import only these rows of the input"
|
|
22085
|
+
},
|
|
22086
|
+
{ name: "add-to-org", description: "Also add new members to the org", isFlag: true },
|
|
22087
|
+
{
|
|
22088
|
+
name: "org-role",
|
|
22089
|
+
description: "Org role with --add-to-org: 'member' (default), 'admin', 'owner'"
|
|
22090
|
+
}
|
|
22091
|
+
],
|
|
22092
|
+
examples: [
|
|
22093
|
+
"gr hubspot search -w <ws> --query smith -o json \\",
|
|
22094
|
+
" | gr hubspot import-members -w <ws> --member-role-id 3 --allow-write",
|
|
22095
|
+
"gr hubspot search -w <ws> -o json > found.json",
|
|
22096
|
+
"gr hubspot import-members -w <ws> --file found.json --ids 101,102 --member-role-id 3 --allow-write"
|
|
22097
|
+
],
|
|
22098
|
+
handler: async ({ ctx, workspace, args, data }) => {
|
|
22099
|
+
if (!data) {
|
|
22100
|
+
throw new CLIError(
|
|
22101
|
+
"JSON input required (--data, --file, or stdin): pipe `gr hubspot search -o json`"
|
|
22102
|
+
);
|
|
22103
|
+
}
|
|
22104
|
+
let records = importRecordsFrom(data);
|
|
22105
|
+
const rawIds = args["ids"];
|
|
22106
|
+
if (rawIds) {
|
|
22107
|
+
const wanted = new Set(
|
|
22108
|
+
rawIds.split(",").map((id) => id.trim()).filter(Boolean)
|
|
22109
|
+
);
|
|
22110
|
+
records = records.filter((r) => wanted.has(r.hubspotId));
|
|
22111
|
+
const missing = [...wanted].filter((id) => !records.some((r) => r.hubspotId === id));
|
|
22112
|
+
if (missing.length > 0) {
|
|
22113
|
+
throw new CLIError(`--ids not found in the input: ${missing.join(", ")}`);
|
|
22114
|
+
}
|
|
22115
|
+
}
|
|
22116
|
+
if (records.length === 0) throw new CLIError("No records to import");
|
|
22117
|
+
if (records.length > 100) {
|
|
22118
|
+
throw new CLIError(`At most 100 records per import; got ${records.length}`);
|
|
22119
|
+
}
|
|
22120
|
+
const bodyRoleId = data?.memberRoleId;
|
|
22121
|
+
const memberRoleId = optionalNumber(args, "member-role-id") ?? (typeof bodyRoleId === "number" ? bodyRoleId : void 0);
|
|
22122
|
+
if (memberRoleId === void 0) {
|
|
22123
|
+
throw new CLIError("--member-role-id is required (see: gr member-roles list)");
|
|
22124
|
+
}
|
|
22125
|
+
const addToOrg = args["add-to-org"] === true || data?.addToOrg === true;
|
|
22126
|
+
const orgRole = args["org-role"] ?? data?.orgRole;
|
|
22127
|
+
const result2 = await requireAuth(ctx).apiClient.importHubspotMembers(workspace, {
|
|
22128
|
+
records,
|
|
22129
|
+
memberRoleId,
|
|
22130
|
+
addToOrg,
|
|
22131
|
+
...orgRole ? { orgRole } : {}
|
|
22132
|
+
});
|
|
22133
|
+
if (ctx.outputFormat !== "table") {
|
|
22134
|
+
outputSingle(result2, ctx);
|
|
22135
|
+
return;
|
|
22136
|
+
}
|
|
22137
|
+
outputData(result2.results, ctx, IMPORT_COLUMNS);
|
|
22138
|
+
console.error(`Imported ${result2.imported}, failed ${result2.failed}`);
|
|
21806
22139
|
}
|
|
21807
22140
|
},
|
|
21808
22141
|
{
|
|
21809
|
-
path: ["hubspot", "reconciliation"],
|
|
21810
|
-
description: "Find
|
|
22142
|
+
path: ["hubspot", "reconciliation", "matches"],
|
|
22143
|
+
description: "Find unlinked members with a likely HubSpot record (by email/phone); queries HubSpot",
|
|
21811
22144
|
requiresWorkspace: true,
|
|
21812
22145
|
args: [
|
|
21813
|
-
{ name: "offset", description: "
|
|
21814
|
-
{ name: "limit", description: "Max
|
|
22146
|
+
{ name: "offset", description: "Scan offset (default 0)" },
|
|
22147
|
+
{ name: "limit", description: "Max members to scan (default 50, max 200)" }
|
|
21815
22148
|
],
|
|
21816
22149
|
handler: async ({ ctx, workspace, args }) => {
|
|
21817
|
-
const offset = args["offset"] ? Number(args["offset"]) : void 0;
|
|
21818
|
-
const limit = args["limit"] ? Number(args["limit"]) : void 0;
|
|
21819
22150
|
const result2 = await requireAuth(ctx).apiClient.getHubspotReconciliationMatches(
|
|
21820
22151
|
workspace,
|
|
21821
|
-
{
|
|
21822
|
-
offset,
|
|
21823
|
-
limit
|
|
21824
|
-
}
|
|
22152
|
+
{ offset: optionalNumber(args, "offset"), limit: optionalNumber(args, "limit") }
|
|
21825
22153
|
);
|
|
21826
|
-
outputData(result2, ctx);
|
|
22154
|
+
outputData(result2, ctx, MATCH_COLUMNS2);
|
|
21827
22155
|
}
|
|
21828
22156
|
},
|
|
21829
22157
|
{
|
|
21830
|
-
path: ["hubspot", "linked
|
|
21831
|
-
description: "List members linked to HubSpot
|
|
22158
|
+
path: ["hubspot", "reconciliation", "linked"],
|
|
22159
|
+
description: "List members linked to HubSpot records",
|
|
21832
22160
|
requiresWorkspace: true,
|
|
21833
|
-
args:
|
|
22161
|
+
args: [
|
|
22162
|
+
...LIST_PAGINATION_ARGS,
|
|
22163
|
+
{ name: "search", description: "Filter by member name/email/phone or HubSpot ID" }
|
|
22164
|
+
],
|
|
21834
22165
|
handler: async ({ ctx, workspace, args }) => {
|
|
21835
22166
|
const pag = parsePaginationArgs(args);
|
|
22167
|
+
const search = args["search"] ? String(args["search"]) : void 0;
|
|
22168
|
+
const api = requireAuth(ctx).apiClient;
|
|
21836
22169
|
if (pag.all) {
|
|
21837
22170
|
const allItems = await fetchAllPages(
|
|
21838
|
-
({ page, pageSize }) =>
|
|
22171
|
+
({ page, pageSize }) => api.getLinkedHubspotMembers(workspace, { page, pageSize, search })
|
|
21839
22172
|
);
|
|
21840
|
-
outputData(allItems, ctx);
|
|
22173
|
+
outputData(allItems, ctx, LINKED_COLUMNS2);
|
|
21841
22174
|
return;
|
|
21842
22175
|
}
|
|
21843
|
-
const
|
|
21844
|
-
|
|
21845
|
-
|
|
21846
|
-
|
|
21847
|
-
|
|
21848
|
-
|
|
21849
|
-
);
|
|
21850
|
-
outputData(listResult(result2, true), ctx);
|
|
22176
|
+
const result2 = await api.getLinkedHubspotMembers(workspace, {
|
|
22177
|
+
...pag.page ? { page: pag.page } : {},
|
|
22178
|
+
...pag.pageSize ? { pageSize: pag.pageSize } : {},
|
|
22179
|
+
...search ? { search } : {}
|
|
22180
|
+
});
|
|
22181
|
+
outputData(listResult(result2, true), ctx, LINKED_COLUMNS2);
|
|
21851
22182
|
}
|
|
21852
22183
|
},
|
|
21853
22184
|
{
|
|
21854
|
-
path: ["hubspot", "link
|
|
21855
|
-
description: "Link a member to a HubSpot
|
|
22185
|
+
path: ["hubspot", "reconciliation", "link"],
|
|
22186
|
+
description: "Link a member to a HubSpot record",
|
|
21856
22187
|
mutates: true,
|
|
21857
22188
|
requiresWorkspace: true,
|
|
21858
22189
|
args: [
|
|
21859
22190
|
{ name: "member-id", description: "Member ID", required: true },
|
|
21860
|
-
{ name: "
|
|
22191
|
+
{ name: "record-id", description: "HubSpot record ID", required: true },
|
|
22192
|
+
{ name: "object-type", description: "HubSpot object type (default 'contacts')" }
|
|
22193
|
+
],
|
|
22194
|
+
examples: [
|
|
22195
|
+
"gr hubspot reconciliation link -w <ws> --member-id 42 --record-id 101 --allow-write"
|
|
21861
22196
|
],
|
|
21862
22197
|
handler: async ({ ctx, workspace, args }) => {
|
|
22198
|
+
const objectType = args["object-type"] ? String(args["object-type"]) : void 0;
|
|
21863
22199
|
const result2 = await requireAuth(ctx).apiClient.linkMemberToHubspot(workspace, {
|
|
21864
22200
|
memberId: requireNumber(args, "member-id"),
|
|
21865
|
-
hubspotRecordId: requireString(args, "
|
|
22201
|
+
hubspotRecordId: requireString(args, "record-id"),
|
|
22202
|
+
...objectType ? { objectType } : {}
|
|
21866
22203
|
});
|
|
21867
22204
|
outputSingle(result2, ctx);
|
|
21868
22205
|
}
|
|
21869
22206
|
},
|
|
21870
22207
|
{
|
|
21871
|
-
path: ["hubspot", "
|
|
21872
|
-
|
|
22208
|
+
path: ["hubspot", "reconciliation", "link-bulk"],
|
|
22209
|
+
// Its input is usually the previous command's output: wait for the pipe.
|
|
22210
|
+
pipesJsonInput: true,
|
|
22211
|
+
description: 'Link many members at once. Body: {"links":[{"memberId":1,"recordId":"101"}]} (hubspotRecordId is accepted too); `reconciliation matches -o json` pipes in',
|
|
22212
|
+
mutates: true,
|
|
22213
|
+
requiresWorkspace: true,
|
|
22214
|
+
examples: [
|
|
22215
|
+
"gr hubspot reconciliation matches -w <ws> -o json \\",
|
|
22216
|
+
" | gr hubspot reconciliation link-bulk -w <ws> --allow-write"
|
|
22217
|
+
],
|
|
22218
|
+
handler: async ({ ctx, workspace, data }) => {
|
|
22219
|
+
const body = data;
|
|
22220
|
+
const rows = Array.isArray(body) ? body : body?.links;
|
|
22221
|
+
if (!Array.isArray(rows) || rows.length === 0) {
|
|
22222
|
+
throw new CLIError('JSON input must be {"links":[...]} or an array of matches');
|
|
22223
|
+
}
|
|
22224
|
+
const links = rows.map((row, index) => {
|
|
22225
|
+
const memberId = Number(row?.memberId);
|
|
22226
|
+
const recordId = row?.recordId ?? row?.hubspotRecordId;
|
|
22227
|
+
if (!Number.isInteger(memberId) || !recordId) {
|
|
22228
|
+
throw new CLIError(
|
|
22229
|
+
`links[${index}] needs a numeric memberId and a recordId (or hubspotRecordId)`
|
|
22230
|
+
);
|
|
22231
|
+
}
|
|
22232
|
+
return {
|
|
22233
|
+
memberId,
|
|
22234
|
+
hubspotRecordId: String(recordId),
|
|
22235
|
+
...row.objectType ? { objectType: String(row.objectType) } : {}
|
|
22236
|
+
};
|
|
22237
|
+
});
|
|
22238
|
+
const result2 = await requireAuth(ctx).apiClient.bulkLinkMembersToHubspot(workspace, {
|
|
22239
|
+
links
|
|
22240
|
+
});
|
|
22241
|
+
outputSingle(result2, ctx);
|
|
22242
|
+
}
|
|
22243
|
+
},
|
|
22244
|
+
{
|
|
22245
|
+
path: ["hubspot", "reconciliation", "unlink"],
|
|
22246
|
+
description: "Unlink a member from HubSpot (sync will not re-link them until reconciliation relink)",
|
|
21873
22247
|
mutates: true,
|
|
21874
22248
|
requiresWorkspace: true,
|
|
21875
22249
|
args: [{ name: "member-id", description: "Member ID", required: true }],
|
|
21876
22250
|
handler: async ({ ctx, workspace, args }) => {
|
|
21877
|
-
await requireAuth(ctx).apiClient.unlinkMemberFromHubspot(
|
|
22251
|
+
const result2 = await requireAuth(ctx).apiClient.unlinkMemberFromHubspot(
|
|
21878
22252
|
workspace,
|
|
21879
22253
|
requireNumber(args, "member-id")
|
|
21880
22254
|
);
|
|
21881
|
-
|
|
22255
|
+
outputSingle(result2, ctx);
|
|
21882
22256
|
}
|
|
21883
22257
|
},
|
|
21884
22258
|
{
|
|
21885
|
-
path: ["hubspot", "
|
|
21886
|
-
description: "List
|
|
22259
|
+
path: ["hubspot", "properties"],
|
|
22260
|
+
description: "List HubSpot property definitions: the sync-mappable contact properties by default, or every property of --object-type as HubSpot defines it",
|
|
21887
22261
|
requiresWorkspace: true,
|
|
21888
|
-
|
|
21889
|
-
|
|
21890
|
-
|
|
22262
|
+
args: [
|
|
22263
|
+
{
|
|
22264
|
+
name: "object-type",
|
|
22265
|
+
description: "Raw HubSpot schema for 'contacts', 'companies' or 'deals'"
|
|
22266
|
+
}
|
|
22267
|
+
],
|
|
22268
|
+
examples: [
|
|
22269
|
+
"gr hubspot properties -w <ws>",
|
|
22270
|
+
"gr hubspot properties -w <ws> --object-type deals -o json"
|
|
22271
|
+
],
|
|
22272
|
+
handler: async ({ ctx, workspace, args }) => {
|
|
22273
|
+
const objectType = args["object-type"];
|
|
22274
|
+
const api = requireAuth(ctx).apiClient;
|
|
22275
|
+
if (objectType === void 0) {
|
|
22276
|
+
outputData(await api.getHubspotContactProperties(workspace), ctx);
|
|
22277
|
+
return;
|
|
22278
|
+
}
|
|
22279
|
+
if (!OBJECT_TYPES.includes(objectType)) {
|
|
22280
|
+
throw new CLIError(
|
|
22281
|
+
`--object-type must be one of ${OBJECT_TYPES.join(", ")}, got '${objectType}'`
|
|
22282
|
+
);
|
|
22283
|
+
}
|
|
22284
|
+
const result2 = await api.getHubspotObjectProperties(
|
|
22285
|
+
workspace,
|
|
22286
|
+
objectType
|
|
22287
|
+
);
|
|
22288
|
+
outputSingle(result2, ctx);
|
|
21891
22289
|
}
|
|
21892
22290
|
},
|
|
21893
22291
|
{
|
|
@@ -21899,6 +22297,22 @@ var hubspotDomain = {
|
|
|
21899
22297
|
outputData(result2, ctx);
|
|
21900
22298
|
}
|
|
21901
22299
|
},
|
|
22300
|
+
{
|
|
22301
|
+
path: ["hubspot", "sync", "logs"],
|
|
22302
|
+
description: "List HubSpot managed-rule executions (newest first, cursor-paged)",
|
|
22303
|
+
requiresWorkspace: true,
|
|
22304
|
+
args: [
|
|
22305
|
+
{ name: "page-size", description: "Rows per page" },
|
|
22306
|
+
{ name: "cursor", description: "Cursor from a previous page (nextCursor)" }
|
|
22307
|
+
],
|
|
22308
|
+
handler: async ({ ctx, workspace, args }) => {
|
|
22309
|
+
const result2 = await requireAuth(ctx).apiClient.getHubspotSyncLogs(workspace, {
|
|
22310
|
+
pageSize: optionalNumber(args, "page-size"),
|
|
22311
|
+
cursor: args["cursor"] ? String(args["cursor"]) : void 0
|
|
22312
|
+
});
|
|
22313
|
+
outputSingle(result2, ctx);
|
|
22314
|
+
}
|
|
22315
|
+
},
|
|
21902
22316
|
{
|
|
21903
22317
|
path: ["hubspot", "transform-presets"],
|
|
21904
22318
|
description: "List available HubSpot field transform presets",
|
|
@@ -21907,7 +22321,8 @@ var hubspotDomain = {
|
|
|
21907
22321
|
const result2 = await requireAuth(ctx).apiClient.getHubspotTransformPresets(workspace);
|
|
21908
22322
|
outputData(result2, ctx);
|
|
21909
22323
|
}
|
|
21910
|
-
}
|
|
22324
|
+
},
|
|
22325
|
+
...connectionCommands(HUBSPOT)
|
|
21911
22326
|
]
|
|
21912
22327
|
};
|
|
21913
22328
|
|
|
@@ -22183,37 +22598,39 @@ var salesforceDomain = {
|
|
|
22183
22598
|
commands: [
|
|
22184
22599
|
{
|
|
22185
22600
|
path: ["salesforce", "install"],
|
|
22186
|
-
description: "Install Salesforce (setup step 1): create the connection
|
|
22601
|
+
description: "Install Salesforce (setup step 1): create the connection for an environment, then authorize",
|
|
22187
22602
|
mutates: true,
|
|
22188
22603
|
requiresWorkspace: true,
|
|
22189
22604
|
args: [
|
|
22190
22605
|
{
|
|
22191
|
-
name: "
|
|
22192
|
-
description: "Salesforce
|
|
22606
|
+
name: "environment",
|
|
22607
|
+
description: "Salesforce environment: production (default) or sandbox"
|
|
22608
|
+
},
|
|
22609
|
+
{
|
|
22610
|
+
name: "my-domain",
|
|
22611
|
+
description: "The org's My Domain host (e.g. acme.my.salesforce.com), only for an org that blocks login.salesforce.com / test.salesforce.com"
|
|
22193
22612
|
}
|
|
22194
22613
|
],
|
|
22195
22614
|
examples: [
|
|
22196
|
-
"#
|
|
22197
|
-
|
|
22198
|
-
|
|
22199
|
-
"#
|
|
22200
|
-
"#
|
|
22201
|
-
|
|
22202
|
-
'# 4. authorize -> returns an "authorizeUrl"; open it to grant access. status then',
|
|
22203
|
-
"# reports configured=true and connected=true.",
|
|
22615
|
+
"# One-click setup through the shared Gravity Rail Salesforce app:",
|
|
22616
|
+
"# 1. install -> creates the connection for the chosen environment",
|
|
22617
|
+
'# 2. authorize -> returns an "authorizeUrl"; open it, sign in and approve access.',
|
|
22618
|
+
"# status then reports connected=true.",
|
|
22619
|
+
"# Advanced (own app): run configure between install and authorize, with an app whose",
|
|
22620
|
+
'# Callback URL is the status "callbackUrl".',
|
|
22204
22621
|
"",
|
|
22205
22622
|
"gr salesforce install -w <ws> --allow-write",
|
|
22206
|
-
"gr salesforce install -w <ws> --
|
|
22207
|
-
"gr salesforce
|
|
22208
|
-
|
|
22209
|
-
"gr salesforce authorize -w <ws> --allow-write # then open the returned authorizeUrl"
|
|
22623
|
+
"gr salesforce install -w <ws> --environment sandbox --allow-write",
|
|
22624
|
+
"gr salesforce authorize -w <ws> --allow-write # then open the returned authorizeUrl",
|
|
22625
|
+
"gr salesforce status -w <ws>"
|
|
22210
22626
|
],
|
|
22211
22627
|
handler: async ({ ctx, workspace, args }) => {
|
|
22212
|
-
const
|
|
22213
|
-
const
|
|
22214
|
-
|
|
22215
|
-
typeof
|
|
22216
|
-
|
|
22628
|
+
const environment = args["environment"];
|
|
22629
|
+
const myDomain = args["my-domain"];
|
|
22630
|
+
const result2 = await requireAuth(ctx).apiClient.installSalesforce(workspace, {
|
|
22631
|
+
...typeof environment === "string" ? { environment } : {},
|
|
22632
|
+
...typeof myDomain === "string" ? { myDomain } : {}
|
|
22633
|
+
});
|
|
22217
22634
|
outputSingle(result2, ctx);
|
|
22218
22635
|
}
|
|
22219
22636
|
},
|
|
@@ -22228,12 +22645,12 @@ var salesforceDomain = {
|
|
|
22228
22645
|
},
|
|
22229
22646
|
{
|
|
22230
22647
|
path: ["salesforce", "configure"],
|
|
22231
|
-
description: "
|
|
22648
|
+
description: "Advanced: save your own Salesforce app's Client ID / Secret and environment, then open the returned authorizeUrl",
|
|
22232
22649
|
mutates: true,
|
|
22233
22650
|
requiresWorkspace: true,
|
|
22234
22651
|
examples: [
|
|
22235
22652
|
"gr salesforce configure -w <ws> --allow-write \\",
|
|
22236
|
-
` -d '{"clientId":"3MVG9...","clientSecret":"1A2B...","
|
|
22653
|
+
` -d '{"clientId":"3MVG9...","clientSecret":"1A2B...","environment":"production"}'`
|
|
22237
22654
|
],
|
|
22238
22655
|
handler: async ({ ctx, workspace, data }) => {
|
|
22239
22656
|
if (!data) throw new CLIError("JSON data required (--data, --file, or stdin)");
|
|
@@ -22246,7 +22663,7 @@ var salesforceDomain = {
|
|
|
22246
22663
|
},
|
|
22247
22664
|
{
|
|
22248
22665
|
path: ["salesforce", "authorize"],
|
|
22249
|
-
description: "Authorize Salesforce via OAuth (setup step
|
|
22666
|
+
description: "Authorize Salesforce via OAuth (setup step 2): returns an authorizeUrl to open in a browser",
|
|
22250
22667
|
mutates: true,
|
|
22251
22668
|
requiresWorkspace: true,
|
|
22252
22669
|
handler: async ({ ctx, workspace }) => {
|
|
@@ -27193,7 +27610,7 @@ var topLevelCommands = [
|
|
|
27193
27610
|
mutates: true,
|
|
27194
27611
|
args: [{ name: "phone", description: "E.164 phone number (optional; prompts if omitted)" }],
|
|
27195
27612
|
handler: async (hctx) => {
|
|
27196
|
-
const { accountVerifyPhoneCommand } = await import("./account-verify-phone-
|
|
27613
|
+
const { accountVerifyPhoneCommand } = await import("./account-verify-phone-T7N53V35.js");
|
|
27197
27614
|
await accountVerifyPhoneCommand(hctx);
|
|
27198
27615
|
}
|
|
27199
27616
|
},
|
|
@@ -27300,6 +27717,7 @@ export {
|
|
|
27300
27717
|
CommandRegistry,
|
|
27301
27718
|
LIST_PAGINATION_ARGS,
|
|
27302
27719
|
PAGINATION_ARGS,
|
|
27720
|
+
PIPED_INPUT_FIRST_BYTE_WAIT_MS,
|
|
27303
27721
|
WORKSPACE_EXPORT_ZIP,
|
|
27304
27722
|
authBrowserCommand,
|
|
27305
27723
|
authImportDevCommand,
|
|
@@ -27307,6 +27725,7 @@ export {
|
|
|
27307
27725
|
authSwitchCommand,
|
|
27308
27726
|
buildCliConciergeAppContext,
|
|
27309
27727
|
chatCommand,
|
|
27728
|
+
commandAwaitsPipedInput,
|
|
27310
27729
|
commandNeedsJsonBody,
|
|
27311
27730
|
conciergeCommand,
|
|
27312
27731
|
conciergeOutboundCommand,
|
|
@@ -27351,6 +27770,7 @@ export {
|
|
|
27351
27770
|
parseGlobalOptions,
|
|
27352
27771
|
parsePaginationArgs,
|
|
27353
27772
|
profilesFromDevRealms,
|
|
27773
|
+
readCommandJsonInput,
|
|
27354
27774
|
readJsonInput,
|
|
27355
27775
|
registerPublicDomains,
|
|
27356
27776
|
requireAuth,
|