@jacebenson/jsn 5.4.0-dev.142.1 → 5.4.0-dev.143.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/package.json +1 -1
- package/src/commands/store.js +4 -2
- package/src/errors.js +4 -0
- package/src/flow-safe-edit.js +7 -5
- package/src/sdk.js +6 -3
- package/src/session-recovery.js +2 -2
- package/src/store.js +5 -3
- package/src/update-set-apply.js +4 -1
- package/src/workflow-steps.js +5 -3
package/package.json
CHANGED
package/src/commands/store.js
CHANGED
|
@@ -145,6 +145,10 @@ function emitList(app, argv, page) {
|
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
async function runLifecycle(argv, app, operation) {
|
|
148
|
+
// Validate wait controls before any submission. A usage error after dispatch
|
|
149
|
+
// hides an operation that may already be changing the instance.
|
|
150
|
+
const timeoutMs = argv.wait ? boundedTimeout(argv.timeout) * 1000 : undefined;
|
|
151
|
+
const pollIntervalMs = argv.wait ? boundedPoll(argv.pollInterval) * 1000 : undefined;
|
|
148
152
|
const prepare = operation === 'install' ? prepareInstall : prepareUpdate;
|
|
149
153
|
const plan = await prepare(app.sdk, argv.application, operation === 'install'
|
|
150
154
|
? { version: argv.version, demoData: argv.demoData === true }
|
|
@@ -177,8 +181,6 @@ async function runLifecycle(argv, app, operation) {
|
|
|
177
181
|
});
|
|
178
182
|
return;
|
|
179
183
|
}
|
|
180
|
-
const timeoutMs = boundedTimeout(argv.timeout) * 1000;
|
|
181
|
-
const pollIntervalMs = boundedPoll(argv.pollInterval) * 1000;
|
|
182
184
|
let progress;
|
|
183
185
|
try {
|
|
184
186
|
progress = await waitForOperation(app.sdk, started.tracker_id, { pollIntervalMs, timeoutMs });
|
package/src/errors.js
CHANGED
|
@@ -309,6 +309,10 @@ export function renderAppError(err, { app = null, argv = null, identifier = '' }
|
|
|
309
309
|
return { stream: 'stderr', text, exitCode: 2 };
|
|
310
310
|
}
|
|
311
311
|
|
|
312
|
+
if (code === CodeAPI && resolveJsonMode(app, argv) && app) {
|
|
313
|
+
return { stream: 'stdout', text: null, exitCode: 1, appErr: true };
|
|
314
|
+
}
|
|
315
|
+
|
|
312
316
|
if (code === 'system_error') {
|
|
313
317
|
return { stream: 'stderr', text: `Error (system): ${err.message}\n`, exitCode: 3 };
|
|
314
318
|
}
|
package/src/flow-safe-edit.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { AppError, CodeAPI } from './errors.js';
|
|
2
|
+
|
|
1
3
|
// Flow Designer's safeEdit lease is separate from publishing and artifact deletion.
|
|
2
4
|
// The provider exposes a user-level lock, not an operation token: refuse even a
|
|
3
5
|
// same-user existing lease so this CLI cannot release an open designer session.
|
|
@@ -7,15 +9,15 @@ export async function flowSafeEditRequest(sdk, instance, flowId, operation, last
|
|
|
7
9
|
const selection = operation === 'delete' ? 'deleteResult{deleteSuccess id}' : `status{canUserEdit currentEditor${operation === 'upsert' ? ' clientFlowStale' : ''}}`;
|
|
8
10
|
const query = `${operation === 'read' ? 'query' : 'mutation'} {global {snFlowDesigner {safeEdit(safeEditInput:{${input}}){${selection}}}}}`;
|
|
9
11
|
const response = await sdk.request(`${instance}/api/now/graphql`, { method: 'POST', body: JSON.stringify({ query, variables: {} }) });
|
|
10
|
-
if (response.errors?.length) throw new
|
|
12
|
+
if (response.errors?.length) throw new AppError(CodeAPI, `Flow safe edit ${operation}: ${response.errors.map(error => error.message).join('; ')}`);
|
|
11
13
|
const result = response.data?.global?.snFlowDesigner?.safeEdit;
|
|
12
|
-
if (!result) throw new
|
|
14
|
+
if (!result) throw new AppError(CodeAPI, `Flow safe edit ${operation} returned no result`);
|
|
13
15
|
return result;
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
export async function readFlowSafeEditStatus(sdk, instance, flowId) {
|
|
17
19
|
const { status } = await flowSafeEditRequest(sdk, instance, flowId, 'read');
|
|
18
|
-
if (!status || typeof status.canUserEdit !== 'boolean' || !(status.currentEditor == null || typeof status.currentEditor === 'string')) throw new
|
|
20
|
+
if (!status || typeof status.canUserEdit !== 'boolean' || !(status.currentEditor == null || typeof status.currentEditor === 'string')) throw new AppError(CodeAPI, 'Unreadable safe edit status');
|
|
19
21
|
return status;
|
|
20
22
|
}
|
|
21
23
|
|
|
@@ -28,10 +30,10 @@ export async function releaseOwnFlowSafeEdit(sdk, instance, flowId) {
|
|
|
28
30
|
if (!before.canUserEdit && !before.currentEditor) return { released: false, before, after: before };
|
|
29
31
|
const { deleteResult } = await flowSafeEditRequest(sdk, instance, flowId, 'delete');
|
|
30
32
|
if (deleteResult?.deleteSuccess !== true || deleteResult.id !== flowId) {
|
|
31
|
-
throw new
|
|
33
|
+
throw new AppError(CodeAPI, `Flow ${flowId} safe edit release was not confirmed by the provider (deleteSuccess=${JSON.stringify(deleteResult?.deleteSuccess ?? null)}, id=${JSON.stringify(deleteResult?.id ?? null)}); no retry attempted. Status before release: ${describe(before)}.`);
|
|
32
34
|
}
|
|
33
35
|
const after = await readFlowSafeEditStatus(sdk, instance, flowId);
|
|
34
|
-
if (after.canUserEdit || after.currentEditor) throw new
|
|
36
|
+
if (after.canUserEdit || after.currentEditor) throw new AppError(CodeAPI, `Flow ${flowId} release was acknowledged, but readback still reports an edit session (${describe(after)}). Inspect the exact flow and Flow Designer session before retrying.`);
|
|
35
37
|
return { released: true, before, after };
|
|
36
38
|
}
|
|
37
39
|
|
package/src/sdk.js
CHANGED
|
@@ -164,7 +164,7 @@ export class SDKClient {
|
|
|
164
164
|
|
|
165
165
|
async _performAuthenticatedRequest(endpoint, opts, {
|
|
166
166
|
timeout = this.timeout, prepare, skipOAuthSession = false, normalizeErrors = false,
|
|
167
|
-
allowMutationReplay = false,
|
|
167
|
+
allowMutationReplay = false, stateful = false,
|
|
168
168
|
}, consume = (response) => response) {
|
|
169
169
|
const method = String(opts.method || 'GET').toUpperCase();
|
|
170
170
|
for (let attempt = 0; attempt <= MAX_SESSION_REPLAYS; attempt++) {
|
|
@@ -201,7 +201,7 @@ export class SDKClient {
|
|
|
201
201
|
if (attempt >= MAX_SESSION_REPLAYS) throw this._authFailure(rejection);
|
|
202
202
|
// A write or stateful processor is only replayed when the rejection
|
|
203
203
|
// provably happened before execution.
|
|
204
|
-
if (!canReplayAfterRecovery(rejection, { method, allowMutationReplay })) {
|
|
204
|
+
if (!canReplayAfterRecovery(rejection, { method, stateful, allowMutationReplay })) {
|
|
205
205
|
throw this._unsafeReplayError(rejection, endpoint, method);
|
|
206
206
|
}
|
|
207
207
|
// Browser renewal has its own existing hard timeout. Never leave a
|
|
@@ -310,10 +310,13 @@ export class SDKClient {
|
|
|
310
310
|
}
|
|
311
311
|
|
|
312
312
|
async request(endpoint, opts = {}) {
|
|
313
|
-
|
|
313
|
+
// Some provider mutations are GET-shaped. Keep this local replay policy
|
|
314
|
+
// out of fetch options rather than treating their HTTP method as read-only.
|
|
315
|
+
const { timeout = this.timeout, readOnly = false, stateful = false, touchLastSeen, domain = this.domain, ...requestOptions } = opts;
|
|
314
316
|
if (readOnly && (requestOptions.method || 'GET').toUpperCase() !== 'GET') throw new Error('Read-only SDK requests require GET');
|
|
315
317
|
return this._withAuthenticatedRequest(endpoint, requestOptions, {
|
|
316
318
|
timeout,
|
|
319
|
+
stateful,
|
|
317
320
|
normalizeErrors: true,
|
|
318
321
|
prepare: (req) => {
|
|
319
322
|
req.headers.set('Accept', 'application/json');
|
package/src/session-recovery.js
CHANGED
|
@@ -71,10 +71,10 @@ export function classifyAuthRejection(response, { bodyText = '' } = {}) {
|
|
|
71
71
|
* login pages are strong evidence for reads; a write is replayed only when the
|
|
72
72
|
* caller opted in explicitly (none of JSN's own write paths do).
|
|
73
73
|
*/
|
|
74
|
-
export function canReplayAfterRecovery(rejection, { method = 'GET', allowMutationReplay = false } = {}) {
|
|
74
|
+
export function canReplayAfterRecovery(rejection, { method = 'GET', stateful = false, allowMutationReplay = false } = {}) {
|
|
75
75
|
if (!rejection) return false;
|
|
76
76
|
if (rejection.kind === 'http_401') return true;
|
|
77
|
-
return isSafeMethod(method) || allowMutationReplay === true;
|
|
77
|
+
return (!stateful && isSafeMethod(method)) || allowMutationReplay === true;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
/**
|
package/src/store.js
CHANGED
|
@@ -475,7 +475,7 @@ export async function dispatchOperation(sdk, plan) {
|
|
|
475
475
|
const path = plan.operation === 'update' ? UPDATE_PATH : INSTALL_PATH;
|
|
476
476
|
const params = new URLSearchParams({ app_id: plan.app.sys_id, version: plan.requested_version });
|
|
477
477
|
if (plan.operation === 'install') params.set('load_demo_data', String(Boolean(plan.demo_data)));
|
|
478
|
-
const response = await sdk.request(`${sdk.baseURL}${path}?${params}`, { method: 'GET' });
|
|
478
|
+
const response = await sdk.request(`${sdk.baseURL}${path}?${params}`, { method: 'GET', stateful: true });
|
|
479
479
|
const result = response?.result;
|
|
480
480
|
if (!result || typeof result !== 'object') {
|
|
481
481
|
throw errAPI(200, `The ${plan.operation} request returned no result, so the application state is unknown. Inspect the application before retrying.`);
|
|
@@ -513,7 +513,9 @@ export async function operationStatus(sdk, trackerId) {
|
|
|
513
513
|
// version it acted on; it is the only place a failed submission says what it
|
|
514
514
|
// tried to do.
|
|
515
515
|
const detail = storeText(result, 'status_detail');
|
|
516
|
-
|
|
516
|
+
// CICD states are pending=0, running=1, successful=2, failed=3,
|
|
517
|
+
// canceled=4. Percentage is progress, not an operation verdict.
|
|
518
|
+
const terminal = ['2', '3', '4'].includes(status) || Boolean(error);
|
|
517
519
|
return {
|
|
518
520
|
tracker_id: id,
|
|
519
521
|
status,
|
|
@@ -523,7 +525,7 @@ export async function operationStatus(sdk, trackerId) {
|
|
|
523
525
|
percent_complete: Number.isFinite(percent) ? percent : null,
|
|
524
526
|
error: error || null,
|
|
525
527
|
terminal,
|
|
526
|
-
succeeded:
|
|
528
|
+
succeeded: status === '2' && !error,
|
|
527
529
|
};
|
|
528
530
|
}
|
|
529
531
|
|
package/src/update-set-apply.js
CHANGED
|
@@ -270,7 +270,10 @@ export async function listPreviewProblems(sdk, sysID, { limit = 500 } = {}) {
|
|
|
270
270
|
* Refuse to continue while the platform still considers preview problems
|
|
271
271
|
* unresolved. jsn never accepts, skips, or ignores one on the operator's behalf.
|
|
272
272
|
*/
|
|
273
|
-
export function assertNoUnresolvedProblems({ problems, unresolved }) {
|
|
273
|
+
export function assertNoUnresolvedProblems({ problems, unresolved, truncated }) {
|
|
274
|
+
if (truncated) {
|
|
275
|
+
throw errUsage('Refusing to commit: the preview problem list is truncated. Unread problems may remain unresolved. Review and commit this set in ServiceNow; jsn cannot establish that every problem is resolved.');
|
|
276
|
+
}
|
|
274
277
|
if (!unresolved.length) return;
|
|
275
278
|
const lines = unresolved.slice(0, 10).map((problem) => {
|
|
276
279
|
const target = problem.missing_item_table
|
package/src/workflow-steps.js
CHANGED
|
@@ -46,10 +46,12 @@ export function numberWorkflowSteps(activities, transitions, startId, components
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
for (const activity of stable) if (!visited.has(activity.sys_id)) add(activity, false);
|
|
49
|
-
//
|
|
49
|
+
// Keep the observed traversal ahead of the stable detached appendix.
|
|
50
|
+
// Only reached terminal activities move behind other reached activities.
|
|
50
51
|
if (!fallback_reason) {
|
|
51
|
-
steps.sort((a, b) => Number(
|
|
52
|
-
|
|
52
|
+
steps.sort((a, b) => Number(b.reached_from_start) - Number(a.reached_from_start)
|
|
53
|
+
|| (a.reached_from_start ? Number(outgoing.get(a.sys_id).length === 0)
|
|
54
|
+
- Number(outgoing.get(b.sys_id).length === 0) : 0));
|
|
53
55
|
steps.forEach((step, index) => { step.number = index + 1; });
|
|
54
56
|
}
|
|
55
57
|
const byId = new Map(steps.map(step => [step.sys_id, step]));
|