@uipath/vertical-solutions-tool 1.204.0 → 1.205.0-preview.258

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/README.md +80 -0
  2. package/dist/THIRD-PARTY-NOTICES.md +1617 -369
  3. package/dist/createSdk-2f9x47em.js +12 -0
  4. package/dist/deploy-jobs-3k87fkwz.js +23 -0
  5. package/dist/deploy-service-qaykt7er.js +1779 -0
  6. package/dist/deployment-search-arbm2z06.js +2649 -0
  7. package/dist/embedded-file-reader-r66242ey.js +114 -0
  8. package/dist/first-party-service-srxaftkn.js +27 -0
  9. package/dist/index-7a3eqtxv.js +3174 -0
  10. package/dist/index-8s9dxpj4.js +18812 -0
  11. package/dist/index-fyc0k5dd.js +51405 -0
  12. package/dist/index-h43sj8at.js +23075 -0
  13. package/dist/index-kmp9fmhb.js +25 -0
  14. package/dist/index-ngs0a2he.js +15 -0
  15. package/dist/index.js +14 -3
  16. package/dist/index.umd.min-fqefd9kn.js +7814 -0
  17. package/dist/job-commands-azgbrbdb.js +23 -0
  18. package/dist/job-output-t43hzj1f.js +36 -0
  19. package/dist/prompts-dtgt183n.js +260 -0
  20. package/dist/resume-service-mqfnnzb5.js +344 -0
  21. package/dist/seed-service-2d1f7zaz.js +2014 -0
  22. package/dist/seed-templates-sqqqratr.js +14 -0
  23. package/dist/service-errors-jzbq3z7p.js +22 -0
  24. package/dist/solution-auth-zq6gyxsv.js +11 -0
  25. package/dist/solution-deployments-m44fyb88.js +33 -0
  26. package/dist/templates-85yrztpk.js +15 -0
  27. package/dist/tool-342sz3hm.js +439 -0
  28. package/dist/tool-38ad77wd.js +1472 -0
  29. package/dist/tool-4z1dy1rn.js +260 -0
  30. package/dist/tool-53w8skv5.js +262 -0
  31. package/dist/tool-67587985.js +554 -0
  32. package/dist/tool-87e2ps7f.js +13 -0
  33. package/dist/tool-cag2z2d6.js +30 -0
  34. package/dist/tool-e4qgwf9h.js +2281 -0
  35. package/dist/tool-gdtpsdn7.js +342 -0
  36. package/dist/tool-gvmshnq9.js +555 -0
  37. package/dist/tool-h4f967yd.js +73 -0
  38. package/dist/tool-hdxtgckw.js +249 -0
  39. package/dist/tool-jjxbj28g.js +17067 -0
  40. package/dist/tool-keqjsxdx.js +28 -0
  41. package/dist/tool-maw0g02p.js +24 -0
  42. package/dist/tool-mn1wkbhw.js +113 -0
  43. package/dist/tool-n35nrs32.js +4949 -0
  44. package/dist/tool-p589v2r5.js +114 -0
  45. package/dist/tool-pz9qm3dv.js +6723 -0
  46. package/dist/tool-r1ewa0tf.js +5645 -0
  47. package/dist/tool-r2epw08s.js +164 -0
  48. package/dist/tool-rr9fensp.js +12 -0
  49. package/dist/tool-s04z9t80.js +19 -0
  50. package/dist/tool-s9qbxa2g.js +638 -0
  51. package/dist/tool-tjhwq0ez.js +261 -0
  52. package/dist/tool-v15vxc4x.js +183 -0
  53. package/dist/tool-vf2mgth0.js +14286 -0
  54. package/dist/tool-vp7rjr2q.js +22083 -0
  55. package/dist/tool-xd2ejt3h.js +103 -0
  56. package/dist/tool-yx29vb63.js +672 -0
  57. package/dist/tool.js +12 -2
  58. package/dist/watch-job-wh6m7xzq.js +31 -0
  59. package/package.json +3 -3
  60. package/dist/tool-xymb3dsq.js +0 -45085
@@ -0,0 +1,555 @@
1
+ import {
2
+ failedStepsOf,
3
+ logLineText,
4
+ runningStepOf,
5
+ writeJobLogLine,
6
+ writeProgress,
7
+ writeStepSummary,
8
+ writeWarning
9
+ } from "./tool-v15vxc4x.js";
10
+ import {
11
+ createVssConfig
12
+ } from "./tool-xd2ejt3h.js";
13
+ import {
14
+ finishedJobConflict,
15
+ knownJobStatus
16
+ } from "./tool-r2epw08s.js";
17
+ import {
18
+ cancelDeployJob,
19
+ getDeployJob,
20
+ getDeployJobLogs,
21
+ resumeDeployJob
22
+ } from "./tool-mn1wkbhw.js";
23
+ import {
24
+ isCapacityError,
25
+ isTransientError
26
+ } from "./tool-4z1dy1rn.js";
27
+ import {
28
+ TERMINAL_JOB_STATUSES
29
+ } from "./tool-s04z9t80.js";
30
+ import {
31
+ ErrorDecision,
32
+ PollOutcome,
33
+ canPrompt,
34
+ catchError,
35
+ pollUntil
36
+ } from "./tool-pz9qm3dv.js";
37
+
38
+ // src/services/watch/state.ts
39
+ function startDeadline(timeoutMs) {
40
+ if (!timeoutMs || timeoutMs <= 0)
41
+ return;
42
+ const controller = new AbortController;
43
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
44
+ return { signal: controller.signal, stop: () => clearTimeout(timer) };
45
+ }
46
+ function noteDeadline(state, options) {
47
+ if (!deadlineCut(state, options))
48
+ return false;
49
+ state.timedOut = true;
50
+ return true;
51
+ }
52
+ function deadlineCut(state, options) {
53
+ return !options.signal?.aborted && state.deadlineSignal?.aborted === true;
54
+ }
55
+ function eitherSignal(first, second) {
56
+ if (!first)
57
+ return second;
58
+ if (!second)
59
+ return first;
60
+ return AbortSignal.any([first, second]);
61
+ }
62
+ async function withinWatchDeadline(state, options, start) {
63
+ const remaining = state.deadlineMs === undefined ? undefined : state.deadlineMs - Date.now();
64
+ if (remaining !== undefined && remaining <= 0) {
65
+ state.timedOut = true;
66
+ return [undefined, undefined];
67
+ }
68
+ const deadline = remaining === undefined ? undefined : AbortSignal.timeout(remaining);
69
+ const stops = [deadline, options.signal].filter((signal) => signal !== undefined);
70
+ const work = catchError(start());
71
+ if (stops.length === 0)
72
+ return await work;
73
+ const giveUp = stops.length === 1 ? stops[0] : AbortSignal.any(stops);
74
+ const gaveUp = [undefined, undefined];
75
+ const raced = await Promise.race([
76
+ work,
77
+ whenAborted(giveUp).then(() => gaveUp)
78
+ ]);
79
+ if (raced[0] !== undefined || raced[1] !== undefined)
80
+ return raced;
81
+ if (options.signal?.aborted === true)
82
+ state.resumeInterrupted = true;
83
+ else if (deadline?.aborted === true)
84
+ state.timedOut = true;
85
+ return [undefined, undefined];
86
+ }
87
+ function whenAborted(signal) {
88
+ if (signal.aborted)
89
+ return Promise.resolve();
90
+ return new Promise((resolve) => {
91
+ signal.addEventListener("abort", () => resolve(), { once: true });
92
+ });
93
+ }
94
+ async function beforeDeadline(state, run, interrupt) {
95
+ if (interrupt?.aborted) {
96
+ state.resumeInterrupted = true;
97
+ return { timedOut: true };
98
+ }
99
+ if (state.deadlineMs !== undefined && Date.now() >= state.deadlineMs) {
100
+ state.timedOut = true;
101
+ return { timedOut: true };
102
+ }
103
+ const deadline = state.deadlineMs === undefined ? undefined : new AbortController;
104
+ const timer = deadline && state.deadlineMs !== undefined ? setTimeout(() => deadline.abort(), Math.max(0, state.deadlineMs - Date.now())) : undefined;
105
+ const [error, value] = await catchError(run(eitherSignal(deadline?.signal, interrupt)));
106
+ clearTimeout(timer);
107
+ if (interrupt?.aborted) {
108
+ state.resumeInterrupted = true;
109
+ return { timedOut: true };
110
+ }
111
+ if (deadline?.signal.aborted) {
112
+ state.timedOut = true;
113
+ return { timedOut: true };
114
+ }
115
+ if (error)
116
+ throw error;
117
+ return { timedOut: false, value };
118
+ }
119
+
120
+ // src/services/watch/logs.ts
121
+ async function advanceLogs(state, holder, options, signal, jobFinished) {
122
+ const [logError, drained] = await catchError(drainLogs(holder.current, options, state.afterSeq, signal));
123
+ if (!logError) {
124
+ state.afterSeq = drained.cursor;
125
+ state.lastLogMessage = drained.lastMessage ?? state.lastLogMessage;
126
+ return;
127
+ }
128
+ if (options.signal?.aborted === true) {
129
+ throw logError;
130
+ }
131
+ if (deadlineCut(state, options)) {
132
+ if (!jobFinished)
133
+ state.timedOut = true;
134
+ return;
135
+ }
136
+ if (state.warnedAboutLogs)
137
+ return;
138
+ writeWarning(`Could not read the job log (${logError.message}). The deploy is still ` + "being watched; follow it in the service's own log.");
139
+ state.warnedAboutLogs = true;
140
+ }
141
+ async function drainLogs(config, options, afterSeq, signal) {
142
+ const lines = await getDeployJobLogs(config, options.jobId, afterSeq, signal);
143
+ let cursor = afterSeq;
144
+ let lastMessage;
145
+ for (const line of lines) {
146
+ writeJobLogLine(line);
147
+ lastMessage = logLineText(line.message).trim();
148
+ const seq = Number(line.seq);
149
+ if (Number.isFinite(seq))
150
+ cursor = Math.max(cursor, seq);
151
+ }
152
+ return { cursor, lastMessage };
153
+ }
154
+
155
+ // src/services/capacity-retry.ts
156
+ var CAPACITY_RETRY_ATTEMPTS = 3;
157
+ var CAPACITY_RETRY_DELAY_MS = 5000;
158
+ async function withCapacityRetry(operation, description, sleep = defaultSleep, signal) {
159
+ for (let attempt = 1;attempt <= CAPACITY_RETRY_ATTEMPTS; attempt += 1) {
160
+ signal?.throwIfAborted();
161
+ const [error, value] = await catchError(operation());
162
+ if (!error)
163
+ return value;
164
+ const lastAttempt = attempt === CAPACITY_RETRY_ATTEMPTS;
165
+ if (!isCapacityError(error) || lastAttempt)
166
+ throw error;
167
+ writeWarning(`Service at capacity — retrying ${description} in ` + `${CAPACITY_RETRY_DELAY_MS / 1000}s ` + `(${attempt}/${CAPACITY_RETRY_ATTEMPTS}).`);
168
+ await sleep(CAPACITY_RETRY_DELAY_MS, signal);
169
+ }
170
+ throw new Error(`Failed to ${description}.`);
171
+ }
172
+ function defaultSleep(ms, signal) {
173
+ return new Promise((resolve, reject) => {
174
+ if (signal?.aborted) {
175
+ reject(signal.reason);
176
+ return;
177
+ }
178
+ const onAbort = () => {
179
+ clearTimeout(timer);
180
+ reject(signal?.reason);
181
+ };
182
+ const timer = setTimeout(() => {
183
+ signal?.removeEventListener("abort", onAbort);
184
+ resolve();
185
+ }, ms);
186
+ signal?.addEventListener("abort", onAbort, { once: true });
187
+ });
188
+ }
189
+
190
+ // src/services/watch/recovery.ts
191
+ var CONFIG_REFRESH_INTERVAL_MS = 5 * 60000;
192
+ var TOKEN_REFRESH_ATTEMPTS = 3;
193
+ function reauthenticate(options) {
194
+ return createVssConfig({
195
+ tenant: options.tenant,
196
+ loginValidity: options.loginValidity,
197
+ serviceUrl: options.serviceUrl
198
+ });
199
+ }
200
+ async function refreshConfigIfStale(state, holder, options) {
201
+ if (Date.now() - holder.builtAtMs < CONFIG_REFRESH_INTERVAL_MS)
202
+ return;
203
+ const [, refreshed] = await withinWatchDeadline(state, options, () => reauthenticate(options));
204
+ if (!refreshed)
205
+ return;
206
+ holder.current = refreshed;
207
+ holder.builtAtMs = Date.now();
208
+ }
209
+ async function handleActionRequired(job, holder, options, state, canRefreshToken) {
210
+ const required = job.actionRequired;
211
+ const kind = required?.kind ?? "configuration_setup";
212
+ const url = required?.url;
213
+ if (kind === "token_expired") {
214
+ return refreshTokenAndResume(job, holder, options, state, canRefreshToken);
215
+ }
216
+ if (kind === "configuration_setup" && options.sentResourceConfigurations) {
217
+ writeWarning("The deployment paused for configuration although per-resource values were submitted. " + "If the job log above names a rejected value — a routing name already in use, for " + "example — fix it in deploy-config.json (or the file passed with --resource-config), or " + "complete the portal wizard, then resume. If no value is named, the service may " + "predate the per-resource configuration " + "contract and dropped the field.");
218
+ }
219
+ const prompt = options.prompt;
220
+ if (!canPrompt() || !prompt) {
221
+ return job;
222
+ }
223
+ writeProgress(`
224
+ ${describePause(kind)}`);
225
+ if (url) {
226
+ const page = pageNameFor(kind);
227
+ writeProgress(` ${page} page: ${url}`);
228
+ const open = await beforeDeadline(state, (signal) => options.openBrowser ? prompt.confirmOpenBrowser(page, signal) : Promise.resolve(false), options.signal);
229
+ if (open.timedOut)
230
+ return job;
231
+ if (open.value)
232
+ await openInBrowser(prompt, url);
233
+ }
234
+ const done = await beforeDeadline(state, (signal) => prompt.waitForActionRequired(kind, url, signal), options.signal);
235
+ if (done.timedOut)
236
+ return job;
237
+ return resumeWithCapacityRetry(holder, options, state, job);
238
+ }
239
+ async function refreshTokenAndResume(job, holder, options, state, canRefreshToken) {
240
+ if (!canRefreshToken) {
241
+ writeWarning(`The job asked for a fresh token ${TOKEN_REFRESH_ATTEMPTS} times and the one this ` + "login hands out is not lasting. Run 'uip login' again, then resume the job.");
242
+ return job;
243
+ }
244
+ const [refreshError, refreshed] = await withinWatchDeadline(state, options, () => reauthenticate(options));
245
+ if (!refreshed) {
246
+ if (!state.resumeInterrupted) {
247
+ writeWarning(`The job's token expired and re-authenticating failed${refreshError ? ` (${refreshError.message})` : ""}. Run 'uip login', then resume the job.`);
248
+ }
249
+ return job;
250
+ }
251
+ if (options.signal?.aborted) {
252
+ state.resumeInterrupted = true;
253
+ return job;
254
+ }
255
+ if (holder.sealedToken !== undefined && refreshed.accessToken === holder.sealedToken) {
256
+ writeWarning("The job's token expired, and this login cannot renew it (a client-credentials " + "or environment login). Run 'uip login', then resume the job.");
257
+ return job;
258
+ }
259
+ holder.current = refreshed;
260
+ holder.builtAtMs = Date.now();
261
+ writeProgress(" Token refreshed — resuming.");
262
+ return resumeWithCapacityRetry(holder, options, state, job);
263
+ }
264
+ async function openInBrowser(prompt, url) {
265
+ const [openError] = await catchError(prompt.openUrl(url));
266
+ if (openError) {
267
+ writeWarning(`Could not open a browser (${openError.message}) — use the URL above.`);
268
+ }
269
+ }
270
+ function pageNameFor(kind) {
271
+ switch (kind) {
272
+ case "activation_setup":
273
+ return "Setup";
274
+ case "connection_setup":
275
+ return "Connections";
276
+ case "configuration_setup":
277
+ return "Configuration";
278
+ default:
279
+ return "Action";
280
+ }
281
+ }
282
+ function describePause(kind) {
283
+ switch (kind) {
284
+ case "activation_setup":
285
+ return "The deployment needs activation setup before it can continue.";
286
+ case "connection_setup":
287
+ return "The deployment needs its connections authorized before it can continue.";
288
+ case "configuration_setup":
289
+ return "The deployment is waiting on the portal's configuration wizard.";
290
+ default:
291
+ return "The deployment is paused and needs attention.";
292
+ }
293
+ }
294
+ async function handleFailure(job, holder, options, state) {
295
+ const step = job.error?.step ? ` at step ${job.error.step}` : "";
296
+ writeWarning(`Deployment failed${step}: ${job.error?.message ?? "unknown error"}`);
297
+ writeStepSummary(job);
298
+ const prompt = options.prompt;
299
+ if (!canPrompt() || !prompt)
300
+ return job;
301
+ if (state.deadlineSignal?.aborted)
302
+ return job;
303
+ const retry = await beforeDeadline(state, (signal) => prompt.confirmResume(job, signal), options.signal);
304
+ if (retry.timedOut || !retry.value)
305
+ return job;
306
+ return resumeWithCapacityRetry(holder, options, state, job);
307
+ }
308
+ async function resumeWithCapacityRetry(holder, options, state, job) {
309
+ const [error, attempt] = await catchError(beforeDeadline(state, (deadline) => {
310
+ const signal = eitherSignal(options.signal, deadline);
311
+ return withCapacityRetry(() => resumeDeployJob(holder.current, options.jobId, undefined, signal), "the resume", undefined, signal);
312
+ }));
313
+ if (attempt?.timedOut) {
314
+ state.resumeUnconfirmed = true;
315
+ return job;
316
+ }
317
+ if (options.signal?.aborted) {
318
+ state.resumeInterrupted = true;
319
+ state.resumeUnconfirmed = true;
320
+ writeProgress(" The resume was sent; its answer did not arrive before you let go. " + "The job may already be running again.");
321
+ return job;
322
+ }
323
+ if (error || !attempt?.value) {
324
+ const moved = finishedJobConflict(error, "resume");
325
+ if (moved) {
326
+ return followMovedJob(holder, options, state, job, error, moved);
327
+ }
328
+ state.resumeError = error ?? new Error("The resume returned no job.");
329
+ throw state.resumeError;
330
+ }
331
+ holder.sealedToken = holder.current.accessToken;
332
+ writeProgress(" Resumed from the last checkpoint.");
333
+ return attempt.value;
334
+ }
335
+ async function followMovedJob(holder, options, state, job, error, moved) {
336
+ const status = knownJobStatus(moved.status);
337
+ writeProgress(` The resume was refused: the job is ${status ?? moved.status}. Reading it back.`);
338
+ const moveOn = (next) => {
339
+ if (next.status === "running" || next.status === "queued") {
340
+ holder.sealedToken = undefined;
341
+ }
342
+ state.lastJob = next;
343
+ return next;
344
+ };
345
+ const withNamedStatus = () => status ? moveOn({ ...job, status }) : job;
346
+ if (status === "running" || status === "queued") {
347
+ return moveOn({ ...job, status });
348
+ }
349
+ const [readError, read] = await catchError(beforeDeadline(state, (deadline) => getDeployJob(holder.current, options.jobId, eitherSignal(options.signal, deadline))));
350
+ if (read?.timedOut)
351
+ return withNamedStatus();
352
+ if (options.signal?.aborted) {
353
+ state.resumeInterrupted = true;
354
+ return withNamedStatus();
355
+ }
356
+ const fresh = readError ? undefined : read?.value;
357
+ if (fresh)
358
+ return moveOn(fresh);
359
+ if (!status) {
360
+ state.resumeError = error ?? new Error("The resume failed.");
361
+ throw state.resumeError;
362
+ }
363
+ return moveOn({ ...job, status });
364
+ }
365
+
366
+ // src/services/watch-job.ts
367
+ var DEFAULT_POLL_INTERVAL_MS = 3000;
368
+ var POLL_FAILURE_TOLERANCE = 5;
369
+ var QUIET_POLLS_PER_HEARTBEAT = 10;
370
+ function watchOptionsFrom(flags, job) {
371
+ return {
372
+ ...job,
373
+ tenant: flags.tenant,
374
+ loginValidity: flags.loginValidity,
375
+ pollIntervalMs: flags.pollInterval,
376
+ timeoutMs: (flags.timeout ?? 0) * 1000,
377
+ signal: flags.signal,
378
+ openBrowser: flags.browser !== false
379
+ };
380
+ }
381
+ async function watchDeployJob(options) {
382
+ const holder = {
383
+ current: options.config,
384
+ builtAtMs: Date.now(),
385
+ sealedToken: options.attached ? undefined : options.config.accessToken
386
+ };
387
+ const deadline = startDeadline(options.timeoutMs);
388
+ const state = {
389
+ afterSeq: options.initialAfterSeq ?? 0,
390
+ lastLogMessage: undefined,
391
+ quietPolls: 0,
392
+ warnedAboutLogs: false,
393
+ tokenRefreshes: 0,
394
+ lastError: undefined,
395
+ deadlineMs: options.timeoutMs && options.timeoutMs > 0 ? Date.now() + options.timeoutMs : undefined,
396
+ deadlineSignal: deadline?.signal,
397
+ timedOut: false,
398
+ lastJob: undefined,
399
+ resumeInterrupted: false,
400
+ resumeUnconfirmed: false,
401
+ resumeError: undefined
402
+ };
403
+ const result = await pollUntil({
404
+ fn: () => pollOnce(state, holder, options),
405
+ until: (job) => TERMINAL_JOB_STATUSES.has(job.status) || job.status === "action_required",
406
+ getStatus: (job) => job.status,
407
+ intervalMs: options.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS,
408
+ timeoutMs: options.timeoutMs ?? 0,
409
+ maxConsecutiveErrors: POLL_FAILURE_TOLERANCE,
410
+ signal: options.signal,
411
+ beforePoll: async () => {
412
+ await refreshConfigIfStale(state, holder, options);
413
+ },
414
+ onError: (error, consecutiveCount) => {
415
+ state.lastError = error;
416
+ if (state.timedOut)
417
+ return ErrorDecision.Abort;
418
+ if (isPromptInterrupt(error))
419
+ return ErrorDecision.Abort;
420
+ if (state.resumeError)
421
+ return ErrorDecision.Abort;
422
+ if (!isTransientError(error))
423
+ return ErrorDecision.Abort;
424
+ if (options.signal?.aborted)
425
+ return;
426
+ writeWarning(`Poll failed (${consecutiveCount}/${POLL_FAILURE_TOLERANCE}) — retrying.`);
427
+ return;
428
+ }
429
+ });
430
+ deadline?.stop();
431
+ if (state.timedOut) {
432
+ return {
433
+ kind: "timeout",
434
+ ...state.resumeUnconfirmed ? {} : { job: result.data },
435
+ elapsedMs: result.elapsedMs
436
+ };
437
+ }
438
+ if (state.resumeInterrupted) {
439
+ return state.resumeUnconfirmed ? { kind: "detached" } : { kind: "detached", job: state.lastJob ?? result.data };
440
+ }
441
+ if (state.resumeError) {
442
+ return {
443
+ kind: "rejected",
444
+ job: result.data,
445
+ error: state.resumeError,
446
+ attempting: "resume"
447
+ };
448
+ }
449
+ const outcome = toOutcome(result.outcome, state.lastJob ?? result.data, result.elapsedMs, state.lastError);
450
+ return outcome.kind === "succeeded" ? {
451
+ ...outcome,
452
+ lastLogMessage: state.lastLogMessage,
453
+ config: holder.current
454
+ } : outcome;
455
+ }
456
+ async function pollOnce(state, holder, options) {
457
+ const signal = eitherSignal(options.signal, state.deadlineSignal);
458
+ const [jobError, job] = await catchError(getDeployJob(holder.current, options.jobId, signal));
459
+ if (jobError) {
460
+ noteDeadline(state, options);
461
+ throw jobError;
462
+ }
463
+ state.lastJob = job;
464
+ const previousSeq = state.afterSeq;
465
+ const finished = TERMINAL_JOB_STATUSES.has(job.status);
466
+ await advanceLogs(state, holder, options, signal, finished);
467
+ if (state.timedOut)
468
+ return job;
469
+ if (options.signal?.aborted) {
470
+ throw options.signal.reason instanceof Error ? options.signal.reason : new Error("The watch was interrupted.");
471
+ }
472
+ if (job.status === "queued" || job.status === "running") {
473
+ heartbeat(state, job, previousSeq);
474
+ return job;
475
+ }
476
+ state.quietPolls = 0;
477
+ if (job.status === "action_required") {
478
+ const canRefresh = state.tokenRefreshes < TOKEN_REFRESH_ATTEMPTS;
479
+ if (job.actionRequired?.kind === "token_expired" && canRefresh) {
480
+ state.tokenRefreshes += 1;
481
+ }
482
+ return latest(state, await handleActionRequired(job, holder, options, state, canRefresh));
483
+ }
484
+ if (job.status === "failed") {
485
+ return latest(state, await handleFailure(job, holder, options, state));
486
+ }
487
+ return job;
488
+ }
489
+ function latest(state, job) {
490
+ if (!state.resumeInterrupted)
491
+ state.lastJob = job;
492
+ return job;
493
+ }
494
+ function heartbeat(state, job, previousSeq) {
495
+ state.quietPolls = state.afterSeq === previousSeq ? state.quietPolls + 1 : 0;
496
+ if (state.quietPolls > 0 && state.quietPolls % QUIET_POLLS_PER_HEARTBEAT === 0) {
497
+ const step = runningStepOf(job);
498
+ const where = step ? ` (${step})` : "";
499
+ writeProgress(` … still working${where}`);
500
+ }
501
+ }
502
+ function isPromptInterrupt(error) {
503
+ return error instanceof Error && (error.name === "ExitPromptError" || /force closed the prompt/i.test(error.message));
504
+ }
505
+ function toOutcome(outcome, job, elapsedMs, lastError) {
506
+ if (outcome === PollOutcome.Interrupted) {
507
+ return { kind: "detached", job };
508
+ }
509
+ if (lastError !== undefined && isPromptInterrupt(lastError)) {
510
+ return { kind: "detached", job };
511
+ }
512
+ if (outcome === PollOutcome.Timeout) {
513
+ return { kind: "timeout", job, elapsedMs };
514
+ }
515
+ if (outcome === PollOutcome.Aborted || outcome === PollOutcome.Failed || job === undefined) {
516
+ return stoppedOutcome(job, lastError);
517
+ }
518
+ if (job.status === "succeeded") {
519
+ return {
520
+ kind: "succeeded",
521
+ job,
522
+ failedSteps: failedStepsOf(job)
523
+ };
524
+ }
525
+ if (job.status === "canceled") {
526
+ return { kind: "canceled", job };
527
+ }
528
+ if (job.status === "action_required") {
529
+ const required = job.actionRequired;
530
+ return {
531
+ kind: "paused",
532
+ job,
533
+ actionKind: required?.kind ?? "configuration_setup",
534
+ url: required?.url
535
+ };
536
+ }
537
+ return { kind: "failed", job };
538
+ }
539
+ function stoppedOutcome(job, lastError) {
540
+ if (lastError !== undefined && !isTransientError(lastError)) {
541
+ return { kind: "rejected", job, error: lastError };
542
+ }
543
+ return {
544
+ kind: "lost-contact",
545
+ job,
546
+ error: lastError ?? new Error("Lost contact with the deploy job.")
547
+ };
548
+ }
549
+ async function requestCancel(config, jobId, signal) {
550
+ return cancelDeployJob(config, jobId, signal);
551
+ }
552
+
553
+ export { withCapacityRetry, DEFAULT_POLL_INTERVAL_MS, watchOptionsFrom, watchDeployJob, isPromptInterrupt, requestCancel };
554
+
555
+ //# debugId=7CAE2AF0F0CAEDE264756E2164756E21
@@ -0,0 +1,73 @@
1
+ import {
2
+ forDisplay,
3
+ forDisplayIfSet
4
+ } from "./tool-rr9fensp.js";
5
+ import {
6
+ EXIT_CODES,
7
+ RESULTS
8
+ } from "./tool-pz9qm3dv.js";
9
+
10
+ // src/services/results.ts
11
+ var REASON_ENVELOPE = {
12
+ "missing-option": v("invalid_argument"),
13
+ "invalid-option": v("invalid_argument"),
14
+ "unknown-package": v("not_found"),
15
+ "unknown-version": v("not_found"),
16
+ "unknown-job": v("not_found"),
17
+ "blocked-major-upgrade": v("invalid_argument"),
18
+ "ambiguous-deployment": v("invalid_argument"),
19
+ "name-conflict": v("invalid_argument"),
20
+ "tenant-resources-declared": f("invalid_argument"),
21
+ declined: f("unknown_error"),
22
+ "not-entitled": f("permission_denied"),
23
+ "entitlement-check-failed": f("server_error", "RetryLater"),
24
+ capacity: f("rate_limited", "RetryLater"),
25
+ "service-error": f("unknown_error"),
26
+ "job-failed": f("unknown_error"),
27
+ "job-paused": f("unknown_error"),
28
+ "job-canceled": f("unknown_error"),
29
+ "poll-timeout": {
30
+ result: RESULTS.TimeoutError,
31
+ errorCode: "timeout",
32
+ retry: "RetryWillNotFix"
33
+ },
34
+ "lost-contact": f("network_error")
35
+ };
36
+ function v(errorCode) {
37
+ return {
38
+ result: RESULTS.ValidationError,
39
+ errorCode,
40
+ retry: "RetryWillNotFix"
41
+ };
42
+ }
43
+ function f(errorCode, retry = "RetryWillNotFix") {
44
+ return { result: RESULTS.Failure, errorCode, retry };
45
+ }
46
+ function failure(reason, message, instructions, options = {}) {
47
+ const envelope = REASON_ENVELOPE[reason];
48
+ const result = options.result ?? envelope.result;
49
+ return {
50
+ ok: false,
51
+ reason,
52
+ message: forDisplay(message),
53
+ instructions: forDisplay(instructions),
54
+ result,
55
+ exitCode: options.exitCode ?? EXIT_CODES[result] ?? 1,
56
+ correlationId: forDisplayIfSet(options.correlationId),
57
+ errorCode: options.errorCode ?? envelope.errorCode,
58
+ retry: options.retry ?? envelope.retry
59
+ };
60
+ }
61
+ function missingOption(what, flag) {
62
+ return failure("missing-option", `${what} is required.`, `Pass ${flag}, or run from an interactive terminal to be asked for it.`, { result: RESULTS.ValidationError, errorCode: "invalid_argument" });
63
+ }
64
+ function invalidOption(message, instructions) {
65
+ return failure("invalid-option", message, instructions, {
66
+ result: RESULTS.ValidationError,
67
+ errorCode: "invalid_argument"
68
+ });
69
+ }
70
+
71
+ export { failure, missingOption, invalidOption };
72
+
73
+ //# debugId=176414467BA54D3A64756E2164756E21