@tenonhq/dovetail-servicenow 0.0.61 → 0.0.63

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 CHANGED
@@ -45,6 +45,23 @@ npm install @tenonhq/dovetail-servicenow
45
45
 
46
46
  Requires Node 20 LTS.
47
47
 
48
+ ## ServiceNow app (install once per instance)
49
+
50
+ Parts of this package call the Dovetail Scripted REST API (`/api/cadso/dovetail_core`,
51
+ `/api/cadso/dovetail_sync`, `/api/cadso/dovetail_promote`). That API is not in npm: it lives
52
+ in the **Dovetail** ServiceNow application, which must be installed on every instance you
53
+ point Dovetail at. [`@tenonhq/dovetail-servicenow-app`](../servicenow-app) carries the app as an
54
+ update-set XML. That package is **not published to npm yet** (it is still private), so
55
+ `npx @tenonhq/dovetail-servicenow-app` does not resolve; until it is released, run its CLI from a
56
+ checkout of this repo, after `npm install` and a build of the workspace:
57
+
58
+ ```bash
59
+ npx dovetail-servicenow-app info # which app version is bundled
60
+ npx dovetail-servicenow-app install # how to import, preview and commit it
61
+ ```
62
+
63
+ Without the app, Table API reads still work, but the update-set-captured writes (`add-choices`, `create-record`, `set-field`, `delete-record` and the other write verbs), `test-flow --execute` (`runFlow`) and `app-dependencies --source server` fail on `dovetail_core`.
64
+
48
65
  ## Configure
49
66
 
50
67
  Reads ServiceNow credentials from env vars in this order of precedence:
@@ -1240,6 +1257,90 @@ failed/timeout. Programmatic: `exportUpdateSet({ updateSet, confirm })`,
1240
1257
  `exportApp({ app, confirm })`, `stripSecrets(xml, rules)`. MCP:
1241
1258
  `update_set_export` (writes when the set is in progress) and `app_export`.
1242
1259
 
1260
+ ### Import an update set (automated, by hand, or mixed)
1261
+
1262
+ Load an `<unload>` XML as a retrieved update set, preview it, and commit it — the
1263
+ headless version of **Retrieved Update Sets → Import Update Set from XML → Preview →
1264
+ Commit**, where any step can also be done by a person. It is how
1265
+ `@tenonhq/dovetail-servicenow-app` (not published to npm yet) installs the Dovetail app.
1266
+
1267
+ ```bash
1268
+ # Where is the set? (not loaded / loaded / previewed with N problems / committed) — reads only
1269
+ npx dove-sn import-update-set --file ./dovetail-app.xml --env <instance> --status
1270
+ npx dove-sn import-update-set --remote-set <sys_id> --env <instance> --status
1271
+
1272
+ # Plan (default): the reads plus the engine each step would use
1273
+ npx dove-sn import-update-set --file ./dovetail-app.xml \
1274
+ --expect-app 5f33b5d433d90b147b18bc534d5c7bf6 --expect-scope global --env <instance>
1275
+
1276
+ # Load + preview; prints the preview problems grouped by type
1277
+ npx dove-sn import-update-set --file ./dovetail-app.xml --env <instance> --confirm
1278
+
1279
+ # Commit — only when no error-level problem is unresolved. Accept named problems first.
1280
+ npx dove-sn import-update-set --file ./dovetail-app.xml --env <instance> --confirm --commit \
1281
+ --accept 9f3ff88647881f10357690d3706d43f3
1282
+
1283
+ # Any step by hand: print the click-level steps, write nothing, verify on the next run
1284
+ npx dove-sn import-update-set --file ./dovetail-app.xml --env <instance> --confirm --commit --manual load
1285
+ npx dove-sn import-update-set --file ./dovetail-app.xml --env <instance> --confirm --commit --manual
1286
+ ```
1287
+
1288
+ **Engines, chosen per step** (`--engine auto`, the default):
1289
+
1290
+ | Step | Tried in order |
1291
+ |---|---|
1292
+ | load | Dovetail op → form-login upload (`sys_upload.do`) → manual |
1293
+ | preview | CI/CD Update Set API → Dovetail op → form replay (`UpdateSetPreviewAjax`) → manual |
1294
+ | commit | CI/CD Update Set API → Dovetail op → form replay (`UpdateSetCommitAjaxProcessor`) → manual |
1295
+ | accept | Dovetail op → Table API (`sys_update_preview_problem.status = ignored`) |
1296
+
1297
+ - **CI/CD** — `POST /api/sn_cicd/update_set/preview|commit/{remote_update_set_id}`, polled through
1298
+ `GET /api/sn_cicd/progress/{id}`. Detected read-only through `v_plugin`
1299
+ (`com.glide.continuousdelivery` active; the plugin is Java-backed, so it never shows in
1300
+ `sys_ws_operation`). The commit sends `{"force_commit": "false"}`, so the set must be previewed.
1301
+ The API cannot load XML. Preview was proven on a dev instance over an API key with plain
1302
+ admin; the commit call follows the documented contract and is not yet proven live. Preview
1303
+ problems are always read from `sys_update_preview_problem`; their handling over this API is
1304
+ unproven beyond an empty set.
1305
+ - **Dovetail op** — `POST /api/cadso/dovetail_core/importUpdateSet`
1306
+ (`servicenow/dovetail/sys_ws_operation/importUpdateSet.js`, admin only). API key works. Only on
1307
+ instances whose Dovetail app carries it.
1308
+ - **Form replay** — needs a username + password the instance accepts for **form login** (not an
1309
+ API key, not SSO-only). The `sys_upload.do` field names are not HAR-confirmed yet.
1310
+ - **Manual** — `--manual` (all steps) or `--manual load,preview,commit` (any subset). The verb
1311
+ prints click-level steps with relative addresses (`/upload.do?…`, `/sys_remote_update_set.do?sys_id=…`,
1312
+ `/sys_update_preview_problem.do?sys_id=…`), writes nothing for that step, and exits **4**. Run the
1313
+ same command again: it reads the set back and carries on from where the person left it. When no
1314
+ automated load path exists, the load becomes manual on its own — exit 4, not a failure.
1315
+
1316
+ An engine that answers 403/404 (or whose form login fails) is noted in the output and the next
1317
+ one is tried. A `--engine <name>` forces that engine for every step it covers.
1318
+
1319
+ **Finding the set.** `--remote-set <sys_id>`, else the file's `<sys_remote_update_set>` sys_id,
1320
+ else the file's name + origin (`remote_sys_id`) — so a set a person uploaded by hand, which may get a
1321
+ new sys_id, is picked up. A set that was not matched by the file's own sys_id only counts as this
1322
+ file's set when its rows on the instance are the file's rows (same count, same `sys_update_xml`
1323
+ names): a name + origin match holding other rows (an older export of the same source set, say) is
1324
+ left alone and the file is treated as not loaded, and `--remote-set` given with a file is refused
1325
+ when that set holds other rows. Without a file, the app check (`--expect-app`) and the data-loss check run
1326
+ on the set's rows as the instance holds them. `--expect-scope` is checked on the file header and on
1327
+ the retrieved set's own `application_scope` on the instance, so it holds with `--remote-set` and no
1328
+ file as well; a set whose scope the instance does not report is refused.
1329
+
1330
+ The file is refused when it is not a single update set — any other record type at the top level
1331
+ (an upload inserts whatever the document holds), a batch, a DOCTYPE/ENTITY, a file over
1332
+ `--max-bytes` (50 MB) — and when `--expect-app` / `--expect-scope` do not match. CDATA payloads are
1333
+ read as text (the platform's own export uses them). A commit that deletes a table or column is
1334
+ refused without `--allow-data-loss`. The preview problems are read in full, page by page, so an
1335
+ unresolved error blocks the commit wherever it sits in the list; a set with 50,000 or more problems
1336
+ fails the run instead of being judged on a partial list. Every write is read back (the set exists, its row count matches
1337
+ the file, its state moved), so a call that changes nothing fails the run.
1338
+
1339
+ Exit codes: `0` status / plan / previewed / committed / already committed, `1` bad args, `2` failed
1340
+ or timed out, `3` refused or blocked by preview problems, `4` waiting on a manual step.
1341
+ Programmatic: `importUpdateSet({ file, remoteSet, confirm, commit, manual, acceptProblemIds })`. MCP:
1342
+ `update_set_import` (plan by default; `status`, `confirm`, `commit`, `manual`, `remoteSet`).
1343
+
1243
1344
  `test-flow` defaults to **validate** — a safe pre-flight (published? inputs match
1244
1345
  declared variables?) that never runs the flow; `--execute --confirm` runs it via
1245
1346
  the Dovetail Core `runFlow` op (`POST /api/cadso/dovetail_core/runFlow`), which
package/dist/cli.d.ts CHANGED
@@ -11,6 +11,8 @@
11
11
  * Every verb's usage is rendered from VERB_USAGE in ./cliUsage — add the entry there
12
12
  * when you add a dispatch site below; cliHelp.test.ts fails on a missing one.
13
13
  */
14
+ import type { ImportStatus, ImportUpdateSetResult } from "./importUpdateSet";
15
+ import type { ManualStep } from "./importManual";
14
16
  interface ParsedArgs {
15
17
  command: string;
16
18
  flags: Record<string, string>;
@@ -38,5 +40,18 @@ export declare function domainFlag(verb: string, flags: Record<string, string>,
38
40
  domain?: string;
39
41
  error?: string;
40
42
  };
43
+ /**
44
+ * Exit code for an import result: 0 ok (status, plan, previewed, committed, already
45
+ * committed), 2 failed/timeout, 3 refused/blocked, 4 waiting on a manual step.
46
+ */
47
+ export declare function importExitCode(status: ImportStatus): number;
48
+ /** --manual (bare = every step) or --manual load,preview,commit. "" on a bad value. */
49
+ export declare function parseManualFlag(raw: string | undefined): Array<ManualStep> | null;
50
+ /** Rebuild a verb's argv from parsed flags (bare flags stay bare). */
51
+ export declare function flagsToArgv(verb: string, flags: Record<string, string>, bare: Record<string, boolean>): Array<string>;
52
+ /** The command a person re-runs after a manual step, quoted for a POSIX shell. */
53
+ export declare function resumeCommandFrom(argv: Array<string>): string;
54
+ /** Human-readable import receipt. */
55
+ export declare function formatImportResult(result: ImportUpdateSetResult): string;
41
56
  export declare function main(argv: Array<string>): Promise<number>;
42
57
  export {};
package/dist/cli.js CHANGED
@@ -48,6 +48,11 @@ var __importStar = (this && this.__importStar) || (function () {
48
48
  Object.defineProperty(exports, "__esModule", { value: true });
49
49
  exports.parseArgs = parseArgs;
50
50
  exports.domainFlag = domainFlag;
51
+ exports.importExitCode = importExitCode;
52
+ exports.parseManualFlag = parseManualFlag;
53
+ exports.flagsToArgv = flagsToArgv;
54
+ exports.resumeCommandFrom = resumeCommandFrom;
55
+ exports.formatImportResult = formatImportResult;
51
56
  exports.main = main;
52
57
  const fs = __importStar(require("fs"));
53
58
  const path = __importStar(require("path"));
@@ -64,6 +69,8 @@ const relatedLists_1 = require("./layout/relatedLists");
64
69
  const formatter_2 = require("./layout/formatter");
65
70
  const server_1 = require("./mcp/server");
66
71
  const exportUpdateSet_1 = require("./exportUpdateSet");
72
+ const importUpdateSet_1 = require("./importUpdateSet");
73
+ const importManual_1 = require("./importManual");
67
74
  const exportApp_1 = require("./exportApp");
68
75
  const appDependencies_1 = require("./appDependencies");
69
76
  const stripSecrets_1 = require("./secrets/stripSecrets");
@@ -2698,6 +2705,180 @@ async function runExportUpdateSet(flags) {
2698
2705
  }
2699
2706
  return 0;
2700
2707
  }
2708
+ /**
2709
+ * Exit code for an import result: 0 ok (status, plan, previewed, committed, already
2710
+ * committed), 2 failed/timeout, 3 refused/blocked, 4 waiting on a manual step.
2711
+ */
2712
+ function importExitCode(status) {
2713
+ if (status === "failed" || status === "timeout")
2714
+ return 2;
2715
+ if (status === "refused" || status === "blocked")
2716
+ return 3;
2717
+ if (status === "awaiting-manual")
2718
+ return 4;
2719
+ return 0;
2720
+ }
2721
+ function positiveIntFlag(raw, name) {
2722
+ if (raw === undefined)
2723
+ return undefined;
2724
+ if (!/^[1-9][0-9]{0,11}$/.test(raw))
2725
+ return "import-update-set: --" + name + " must be a positive integer";
2726
+ return parseInt(raw, 10);
2727
+ }
2728
+ /** --manual (bare = every step) or --manual load,preview,commit. "" on a bad value. */
2729
+ function parseManualFlag(raw) {
2730
+ if (raw === undefined)
2731
+ return [];
2732
+ if (raw === "true" || raw === "all")
2733
+ return importManual_1.MANUAL_STEPS.slice();
2734
+ var out = [];
2735
+ var parts = raw.split(",");
2736
+ for (var i = 0; i < parts.length; i += 1) {
2737
+ var v = parts[i].trim();
2738
+ if (v === "load" || v === "preview" || v === "commit") {
2739
+ if (out.indexOf(v) === -1)
2740
+ out.push(v);
2741
+ }
2742
+ else {
2743
+ return null;
2744
+ }
2745
+ }
2746
+ return out;
2747
+ }
2748
+ /** Rebuild a verb's argv from parsed flags (bare flags stay bare). */
2749
+ function flagsToArgv(verb, flags, bare) {
2750
+ var out = [verb];
2751
+ Object.keys(flags).forEach(function (k) {
2752
+ out.push("--" + k);
2753
+ if (!bare[k])
2754
+ out.push(flags[k]);
2755
+ });
2756
+ return out;
2757
+ }
2758
+ /** The command a person re-runs after a manual step, quoted for a POSIX shell. */
2759
+ function resumeCommandFrom(argv) {
2760
+ return ["dove-sn"]
2761
+ .concat(argv)
2762
+ .map(function (a) {
2763
+ return /^[A-Za-z0-9_@%+=:,./-]+$/.test(a) ? a : "'" + a.replace(/'/g, "'\\''") + "'";
2764
+ })
2765
+ .join(" ");
2766
+ }
2767
+ /**
2768
+ * dove-sn import-update-set — see importUpdateSet.ts. Plan by default; --status reports
2769
+ * where the set is; --confirm loads and previews; --confirm --commit commits; --manual
2770
+ * hands steps to a person. Exit codes: importExitCode.
2771
+ */
2772
+ async function runImportUpdateSet(flags, bare) {
2773
+ var file = flags.file;
2774
+ var remoteSet = flags["remote-set"];
2775
+ if (file === "true" || remoteSet === "true") {
2776
+ process.stderr.write("import-update-set: --file and --remote-set need a value\n");
2777
+ return 1;
2778
+ }
2779
+ if (!file && !remoteSet) {
2780
+ process.stderr.write("import-update-set: pass --file <file.xml>, --remote-set <sys_id>, or both\n");
2781
+ return 1;
2782
+ }
2783
+ if (flags.commit === "true" && flags.confirm !== "true") {
2784
+ process.stderr.write("import-update-set: --commit needs --confirm as well\n");
2785
+ return 1;
2786
+ }
2787
+ var engine = flags.engine || "auto";
2788
+ if (engine !== "auto" && engine !== "cicd" && engine !== "platform" && engine !== "dovetail") {
2789
+ process.stderr.write("import-update-set: --engine must be auto, cicd, dovetail or platform\n");
2790
+ return 1;
2791
+ }
2792
+ var manual = parseManualFlag(flags.manual);
2793
+ if (manual === null) {
2794
+ process.stderr.write("import-update-set: --manual takes load, preview, commit (comma-separated) or nothing for all three\n");
2795
+ return 1;
2796
+ }
2797
+ var maxBytes = positiveIntFlag(flags["max-bytes"], "max-bytes");
2798
+ var timeoutMs = positiveIntFlag(flags["timeout-ms"], "timeout-ms");
2799
+ if (typeof maxBytes === "string" || typeof timeoutMs === "string") {
2800
+ process.stderr.write(String(typeof maxBytes === "string" ? maxBytes : timeoutMs) + "\n");
2801
+ return 1;
2802
+ }
2803
+ var accept = [];
2804
+ if (flags.accept !== undefined) {
2805
+ accept = flags.accept
2806
+ .split(",")
2807
+ .map(function (s) {
2808
+ return s.trim();
2809
+ })
2810
+ .filter(function (s) {
2811
+ return s !== "";
2812
+ });
2813
+ }
2814
+ var result = await (0, importUpdateSet_1.importUpdateSet)({
2815
+ file: file || undefined,
2816
+ remoteSet: remoteSet || undefined,
2817
+ expectApp: flags["expect-app"],
2818
+ expectScope: flags["expect-scope"],
2819
+ statusOnly: flags.status === "true",
2820
+ confirm: flags.confirm === "true",
2821
+ commit: flags.commit === "true",
2822
+ manual: manual,
2823
+ acceptProblemIds: accept,
2824
+ allowDataLoss: flags["allow-data-loss"] === "true",
2825
+ repreview: flags.repreview === "true",
2826
+ engine: engine === "cicd" ? "cicd" : engine === "platform" ? "platform" : engine === "dovetail" ? "dovetail" : "auto",
2827
+ maxBytes: maxBytes,
2828
+ timeoutMs: timeoutMs,
2829
+ resumeCommand: resumeCommandFrom(flagsToArgv("import-update-set", flags, bare)),
2830
+ });
2831
+ if (flags.json === "true") {
2832
+ process.stdout.write(JSON.stringify(result, null, 2) + "\n");
2833
+ }
2834
+ else {
2835
+ process.stdout.write(formatImportResult(result));
2836
+ }
2837
+ return importExitCode(result.status);
2838
+ }
2839
+ /** Human-readable import receipt. */
2840
+ function formatImportResult(result) {
2841
+ var lines = [];
2842
+ lines.push("[" + result.status + "] " + (result.remoteSet.name || result.file.path));
2843
+ if (result.remoteSet.sysId) {
2844
+ lines.push(" retrieved set " + result.remoteSet.sysId + (result.remoteSet.state ? " (" + result.remoteSet.state + ")" : " (not on the instance)"));
2845
+ }
2846
+ lines.push(" stage " + result.stage);
2847
+ lines.push(" engines: load " + result.engines.load + ", preview " + result.engines.preview + ", commit " + result.engines.commit + ", accept " + result.engines.accept);
2848
+ lines.push(" rows in file " + result.counts.inFile + (result.counts.onInstance ? ", on instance " + result.counts.onInstance : ""));
2849
+ result.steps.forEach(function (s) {
2850
+ lines.push(" - " + s);
2851
+ });
2852
+ var groups = [
2853
+ ["error", "errors"],
2854
+ ["warning", "warnings"],
2855
+ ["other", "other problems"],
2856
+ ];
2857
+ groups.forEach(function (g) {
2858
+ var list = result.problems[g[0]];
2859
+ if (list.length === 0)
2860
+ return;
2861
+ lines.push(" " + list.length + " " + g[1] + ":");
2862
+ list.forEach(function (pr) {
2863
+ lines.push(" " + pr.sysId + " " + (pr.status || "UNRESOLVED") + " " + (pr.updateName || pr.remoteUpdateSysId) + " — " + pr.description);
2864
+ });
2865
+ });
2866
+ if (result.localUpdateSet) {
2867
+ lines.push(" local set " + result.localUpdateSet.sysId + " '" + result.localUpdateSet.name + "' (" + result.localUpdateSet.state + "), " + result.counts.inLocalSet + " row(s)");
2868
+ }
2869
+ result.refusals.forEach(function (r) {
2870
+ lines.push(" refused: " + r);
2871
+ });
2872
+ if (result.manualSteps.length > 0) {
2873
+ lines.push("");
2874
+ result.manualSteps.forEach(function (m) {
2875
+ lines.push(m);
2876
+ });
2877
+ lines.push("");
2878
+ }
2879
+ lines.push(result.note);
2880
+ return lines.join("\n") + "\n";
2881
+ }
2701
2882
  /** Shared receipt for both export verbs. */
2702
2883
  function writeExportReceipt(flags, result, outPath) {
2703
2884
  if (flags.json === "true") {
@@ -3041,6 +3222,9 @@ async function dispatch(parsed) {
3041
3222
  if (parsed.command === "export-app") {
3042
3223
  return await runExportApp(parsed.flags);
3043
3224
  }
3225
+ if (parsed.command === "import-update-set") {
3226
+ return await runImportUpdateSet(parsed.flags, parsed.bare);
3227
+ }
3044
3228
  if (parsed.command === "strip-secrets") {
3045
3229
  return await runStripSecrets(parsed.flags);
3046
3230
  }
package/dist/cliUsage.js CHANGED
@@ -876,6 +876,41 @@ exports.VERB_USAGE = {
876
876
  example: "dove-sn export-app --app x_cadso_core --out ./core.xml --confirm",
877
877
  notes: ["Exit 1 when run unconfirmed; 2 on failure/timeout."],
878
878
  },
879
+ "import-update-set": {
880
+ summary: "Load an update-set XML as a retrieved update set, preview it, and commit it only when asked — automated, by hand, or mixed",
881
+ required: [
882
+ { flag: "file | remote-set", value: "<file.xml> | <sys_id>", note: "The XML to load, and/or a retrieved set already on the instance." },
883
+ ],
884
+ optional: [
885
+ { flag: "status", note: "Report where the set is (not loaded / loaded / previewed with N problems / committed). Reads only." },
886
+ { flag: "confirm", note: "Load (unless already loaded) and preview. Commits nothing." },
887
+ { flag: "commit", note: "With --confirm: commit when no error-level preview problem is unresolved." },
888
+ { flag: "manual", value: "[load,preview,commit]", note: "A person does these steps (bare = all three): click-level steps are printed, nothing is written, the next run verifies by read-back." },
889
+ { flag: "accept", value: "<id,id,...>", note: "sys_update_preview_problem sys_ids to accept before the commit." },
890
+ { flag: "allow-data-loss", note: "Commit even when the set deletes a table or a column." },
891
+ { flag: "repreview", note: "Run the preview again on a set that was already previewed." },
892
+ { flag: "engine", value: "auto|cicd|dovetail|platform", note: "Default auto picks per step (see notes). A named engine is used for every step it covers." },
893
+ { flag: "expect-app", value: "<sys_id>", note: "Refuse unless the set belongs to this application." },
894
+ { flag: "expect-scope", value: "<scope>", note: "Refuse unless the set's application_scope matches (e.g. global). Checked on the file header and on the retrieved set on the instance, so it also holds with --remote-set and no file." },
895
+ { flag: "max-bytes", value: "<n>", note: "File size cap. Default 50 MB." },
896
+ { flag: "timeout-ms", value: "<n>", note: "Budget for each of preview and commit. Default 600000." },
897
+ JSON_FLAG,
898
+ ],
899
+ gate: "confirm",
900
+ gateNote: "Without --confirm the instance is only read. --confirm loads and previews; a commit needs --commit as well. A --manual step writes nothing.",
901
+ example: "dove-sn import-update-set --file ./dovetail-app.xml --expect-app <sys_id> --expect-scope global --confirm",
902
+ notes: [
903
+ "auto engine per step — load: Dovetail op, else form upload, else manual. Preview and commit: CI/CD Update Set API (v_plugin com.glide.continuousdelivery active), else Dovetail op, else form replay, else manual. A 403/404 from an engine falls through to the next.",
904
+ "With no automated load path (no op, no form-login identity) the verb prints the manual load steps and exits 4 instead of failing.",
905
+ "A set uploaded by hand is found by --remote-set, by the file's sys_id, or by the file's name + origin (remote_sys_id).",
906
+ "A set not matched by the file's own sys_id must hold the file's rows (same count and names): a name + origin match with other rows is left alone (the file counts as not loaded), and --remote-set with a file is refused on a mismatch.",
907
+ "Preview problems are always read from sys_update_preview_problem; accept goes through the Dovetail op, else the Table API.",
908
+ "Refuses a file that is not a single update set: another record type at the top level, a batch, a DOCTYPE, or a file over the cap.",
909
+ "Every write is read back; a call that changes nothing fails the run. Re-running the same command resumes from the set's state.",
910
+ "Exit 0 status/plan/previewed/committed/already committed, 1 bad args, 2 failed or timed out, 3 refused or blocked by preview problems, 4 waiting on a manual step.",
911
+ ],
912
+ stringFlags: ["file", "remote-set", "expect-app", "expect-scope", "accept", "engine", "max-bytes", "timeout-ms"],
913
+ },
879
914
  "strip-secrets": {
880
915
  summary: "Strip secret values from an unload XML exported elsewhere",
881
916
  required: [{ flag: "in", value: "<file>", note: "An unload XML exported earlier." }],
@@ -0,0 +1,154 @@
1
+ /**
2
+ * The engines `import-update-set` drives an instance with. Each one covers some of the
3
+ * steps — load the document as a retrieved update set, preview it, accept named preview
4
+ * problems, commit — and every step is checked by the same Table API read-backs in
5
+ * importUpdateSet.ts, so a silent no-op cannot pass as success. A person can also do any
6
+ * step by hand (importManual.ts); the verb then verifies it by read-back.
7
+ *
8
+ * CICD — the platform's CI/CD Update Set API (plugin com.glide.continuousdelivery, Java
9
+ * backed, so it never shows in sys_ws_operation; detect it through v_plugin). PREVIEW
10
+ * and COMMIT only — the API has no load from XML.
11
+ * preview POST /api/sn_cicd/update_set/preview/{remote_update_set_id}
12
+ * commit POST /api/sn_cicd/update_set/commit/{remote_update_set_id}
13
+ * body {"force_commit": "false"}: the set must be previewed first
14
+ * progress GET /api/sn_cicd/progress/{result.links.progress.id}
15
+ * result.status 0 Pending, 1 Running, 2 Successful, 3 Failed, 4 Canceled
16
+ * Preview verified on loft 2026-11-19 over an API key with plain admin (the identity
17
+ * did not hold sn_cicd.sys_ci_automation). Commit follows the documented contract
18
+ * and has NOT been called live yet. Preview problems are read from
19
+ * sys_update_preview_problem, never from the progress result.
20
+ *
21
+ * DOVETAIL — POST /api/cadso/dovetail_core/importUpdateSet, the op in
22
+ * servicenow/dovetail/sys_ws_operation/importUpdateSet.js. Load, preview, accept,
23
+ * commit, server-side, over ordinary REST auth (API key included). Exists only once
24
+ * the Dovetail app carrying it is installed.
25
+ *
26
+ * PLATFORM — replays the UI over a form-login session, using the processors the UI's
27
+ * own buttons call (read from the instance's sys_ui_action / sys_script_include rows
28
+ * on 2026-11-18):
29
+ * load POST /sys_upload.do (sysparm_target=sys_remote_update_set) UNVERIFIED *
30
+ * preview POST /xmlhttp.do UpdateSetPreviewAjax, function preview | previewAgain
31
+ * check POST /xmlhttp.do com.glide.update.UpdateSetCommitAjaxProcessor,
32
+ * sysparm_type=validateCommitRemoteUpdateSet ("<id>;<query>;<dropped|NONE>")
33
+ * commit POST /xmlhttp.do same processor, sysparm_type=commitRemoteUpdateSet
34
+ * Needs a username + password the instance accepts for form login.
35
+ * * The upload's field names come from the platform's upload page, not a HAR capture.
36
+ *
37
+ * ACCEPT (not an engine of its own) — the Dovetail op when present, else
38
+ * PUT /api/now/table/sys_update_preview_problem/<id> {status: "ignored"}, which is what
39
+ * the UI's "Accept remote update" leaves behind. Read back afterwards.
40
+ *
41
+ * An engine that the instance turns away (the CI/CD or op endpoint answers 403/404, the
42
+ * form login fails) throws EngineUnavailableError; the orchestrator then moves on to the
43
+ * next engine for that step, and finally to the manual instructions.
44
+ *
45
+ * ES6 only, no optional chaining.
46
+ */
47
+ import type { ServiceNowClient } from "./client";
48
+ import type { FormAuth, FormSession, PostResult } from "./table";
49
+ import type { ParsedUnload } from "./importUnload";
50
+ export type ImportEngine = "cicd" | "dovetail" | "platform";
51
+ /** Path of the Dovetail Core op the dovetail engine calls. */
52
+ export declare var IMPORT_OP_PATH: string;
53
+ /** The CI/CD REST API plugin, as v_plugin lists it. */
54
+ export declare var CICD_PLUGIN_ID: string;
55
+ /** The upload page's target table and referring list (the UI action's own values). */
56
+ export declare var UPLOAD_TARGET: string;
57
+ export declare var UPLOAD_REFERRING_URL: string;
58
+ /** Bytes of row payload per load call to the op (the instance caps a REST body near 10 MB). */
59
+ export declare var LOAD_CHUNK_BYTES: number;
60
+ /** The instance turned this engine away; try the next one for the step. */
61
+ export declare class EngineUnavailableError extends Error {
62
+ engine: ImportEngine;
63
+ constructor(engine: ImportEngine, message: string);
64
+ }
65
+ export interface UploadRequest {
66
+ path: string;
67
+ fields: Record<string, string>;
68
+ fileField: string;
69
+ fileName: string;
70
+ contentType: string;
71
+ content: Buffer;
72
+ }
73
+ /** Injectable transport, so tests never touch the network. */
74
+ export interface ImportTransport {
75
+ openSession?: (auth: FormAuth) => Promise<FormSession>;
76
+ post?: (auth: FormAuth, session: FormSession, path: string, fields: Record<string, string>) => Promise<PostResult>;
77
+ upload?: (auth: FormAuth, session: FormSession, request: UploadRequest) => Promise<PostResult>;
78
+ }
79
+ /**
80
+ * The steps an engine covers. A missing method means the engine cannot do that step.
81
+ * Every method throws an Error on failure, EngineUnavailableError when turned away.
82
+ */
83
+ export interface EngineOps {
84
+ engine: ImportEngine;
85
+ load?: () => Promise<void>;
86
+ preview?: (again: boolean) => Promise<void>;
87
+ /** "" when the commit drops nothing; otherwise the platform's list of what it drops. */
88
+ checkDataLoss?: () => Promise<string>;
89
+ /** The local update set, or "" when the engine does not say (it is read back). */
90
+ commit?: () => Promise<{
91
+ localUpdateSetSysId: string;
92
+ }>;
93
+ }
94
+ /** Multipart POST with the session cookie jar. Never follows a redirect. */
95
+ export declare function uploadWithSession(auth: FormAuth, session: FormSession, request: UploadRequest): Promise<PostResult>;
96
+ /** The `answer` attribute of an xmlhttp.do response, entity-decoded. */
97
+ export declare function xmlAnswer(body: string): string;
98
+ export declare function buildUploadFields(ck: string): Record<string, string>;
99
+ export declare function buildPreviewFields(remoteSysId: string, again: boolean): Record<string, string>;
100
+ export declare function buildCommitFields(type: "validateCommitRemoteUpdateSet" | "commitRemoteUpdateSet", remoteSysId: string): Record<string, string>;
101
+ /** "<id>;<encoded query>;<dropped objects | NONE>" -> the dropped list, "" for NONE. */
102
+ export declare function parseValidateAnswer(answer: string): {
103
+ ok: boolean;
104
+ dropped: string;
105
+ };
106
+ /** "<worker id>,<local set id>,<refresh nav>,<refresh apps>" -> the local set id. */
107
+ export declare function parseCommitAnswer(answer: string): {
108
+ workerId: string;
109
+ localUpdateSetSysId: string;
110
+ };
111
+ /** The platform (form replay) engine: load, preview, data-loss check, commit. */
112
+ export declare function platformEngine(p: {
113
+ auth: FormAuth;
114
+ client: ServiceNowClient;
115
+ remoteSysId: () => string;
116
+ fileName: string;
117
+ content: Buffer | null;
118
+ transport: ImportTransport;
119
+ }): EngineOps;
120
+ interface OpBody {
121
+ ok?: unknown;
122
+ error?: unknown;
123
+ code?: unknown;
124
+ localUpdateSetSysId?: unknown;
125
+ }
126
+ /** Scripted REST wraps a returned object in { result }; unwrap either shape. */
127
+ export declare function unwrapOpBody(body: unknown): OpBody;
128
+ /** Split rows into chunks of at most `maxBytes` of payload each (at least one row per chunk). */
129
+ export declare function chunkRows(rows: Array<Record<string, string>>, maxBytes: number): Array<Array<Record<string, string>>>;
130
+ /** Accept preview problems through the op. */
131
+ export declare function acceptViaOp(client: ServiceNowClient, remoteSysId: string, problemIds: Array<string>): Promise<void>;
132
+ /** Accept preview problems through the Table API (status ignored, as the UI action leaves it). */
133
+ export declare function acceptViaTable(client: ServiceNowClient, problemIds: Array<string>): Promise<void>;
134
+ /** The Dovetail (op) engine: load, preview, commit. */
135
+ export declare function dovetailEngine(p: {
136
+ client: ServiceNowClient;
137
+ unload: ParsedUnload | null;
138
+ remoteSysId: () => string;
139
+ }): EngineOps;
140
+ export interface CicdProgress {
141
+ state: "running" | "succeeded" | "failed" | "unknown";
142
+ message: string;
143
+ percent: number;
144
+ }
145
+ /** Read a CI/CD progress (or start) envelope. Never throws. */
146
+ export declare function parseCicdProgress(body: unknown): CicdProgress;
147
+ /** The CI/CD engine: preview and commit through the platform's Update Set API. */
148
+ export declare function cicdEngine(p: {
149
+ client: ServiceNowClient;
150
+ remoteSysId: () => string;
151
+ timeoutMs: number;
152
+ sleep: (ms: number) => Promise<void>;
153
+ }): EngineOps;
154
+ export {};