@jacebenson/jsn 5.5.10-dev.237.1 → 5.5.10-dev.239.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jacebenson/jsn",
3
- "version": "5.5.10-dev.237.1",
3
+ "version": "5.5.10-dev.239.1",
4
4
  "description": "A command-line interface for ServiceNow that follows the Unix philosophy: simple, composable, and scriptable.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -69,8 +69,8 @@ function warnPlaintext() {
69
69
  function refusal(classification = 'secure_storage_unavailable') {
70
70
  const repair = process.platform === 'win32'
71
71
  ? 'Windows Credential Manager requires Windows PowerShell 5.1 or PowerShell 7+ with FullLanguage/Add-Type and native API access allowed by policy.'
72
- : 'Unlock/install secret-tool and retry.';
73
- return storageError(`Secure credential storage unavailable or readback failed. ${repair} Existing plaintext credentials are preserved. No plaintext fallback is enabled automatically.`, classification);
72
+ : 'Unlock/install secret-tool and retry. On Debian/Ubuntu (including WSL), run: sudo apt install libsecret-tools gnome-keyring. If already installed, ensure a running, unlocked keyring is available in your D-Bus session.';
73
+ return storageError(`Secure credential storage unavailable or readback failed. ${repair} Existing plaintext credentials are preserved. No plaintext fallback is enabled automatically. To explicitly allow unencrypted credential files, set ${PLAINTEXT_ENV}=1 in the environment of each jsn process that needs them. Only do this if your security policy permits it; backups can expose credentials.`, classification);
74
74
  }
75
75
 
76
76
  /**
@@ -88,7 +88,7 @@ function plaintextBlocked() {
88
88
  }
89
89
  function readbackFailure() {
90
90
  return storageError(
91
- 'Secure credential storage unavailable or readback failed. The secure entry could not be verified after writing. Existing plaintext credentials are preserved. No plaintext fallback is enabled automatically.',
91
+ `Secure credential storage unavailable or readback failed. The secure entry could not be verified after writing. Existing plaintext credentials are preserved. No plaintext fallback is enabled automatically. To explicitly allow unencrypted credential files, set ${PLAINTEXT_ENV}=1 in the environment of each jsn process that needs them. Only do this if your security policy permits it; backups can expose credentials.`,
92
92
  'secure_readback_failed',
93
93
  );
94
94
  }
package/src/context.js CHANGED
@@ -122,6 +122,25 @@ export async function readEffectiveUpdateSet(sdk) {
122
122
  };
123
123
  }
124
124
 
125
+ /**
126
+ * Read the application this authenticated session has selected.
127
+ *
128
+ * The platform stores the Global selection as the *absence* of the
129
+ * `apps.current_app` preference, so that preference alone can never prove
130
+ * Global. This endpoint reports the session's effective picker selection; a
131
+ * response without a readable `result.current` proves nothing and must never
132
+ * be interpreted as Global.
133
+ */
134
+ export async function readEffectiveApplication(sdk) {
135
+ const endpoint = `${sdk.baseURL}/api/now/ui/concoursepicker/application`;
136
+ const response = await sdk.request(endpoint, { method: 'GET', readOnly: true });
137
+ const current = response?.result?.current;
138
+ if (typeof current !== 'string' || !current) {
139
+ throw new Error('Invalid application picker response: expected result.current.');
140
+ }
141
+ return { sys_id: current };
142
+ }
143
+
125
144
  /** Verify capture consistency without ever changing the session. */
126
145
  export async function alignUpdateSetCapture(sdk, intended) {
127
146
  const effective = await readEffectiveUpdateSet(sdk);
@@ -1,13 +1,35 @@
1
1
  // Intent comes from the task, never from the current provider preferences.
2
2
  import { assertSafeExactMatch, getStringField } from './helpers.js';
3
3
  import { errUsageHint } from './errors.js';
4
- import { readEffectiveUpdateSet } from './context.js';
4
+ import { readEffectiveApplication, readEffectiveUpdateSet } from './context.js';
5
5
 
6
6
  const CONTEXT_HINT = 'Supply --expect-scope and --expect-update-set from the task. Select context explicitly with scopes set / updatesets set, then retry. --force never overrides missing or mismatched intent.';
7
+ const GLOBAL_APPLICATION = 'global';
7
8
 
8
9
  export function contextFailure(message, hint = CONTEXT_HINT) {
9
10
  return errUsageHint(message, hint);
10
11
  }
12
+
13
+ /**
14
+ * Prove Global from the live session when `apps.current_app` is absent.
15
+ *
16
+ * ServiceNow represents the Global application selection as the absence of the
17
+ * preference row, so a missing row is only *evidence* of Global when a fresh
18
+ * read of the session application picker says so. Anything else — a picker
19
+ * reporting another application, or a picker that cannot be read — is reported
20
+ * back as a `note` so the caller refuses instead of silently assuming Global
21
+ * and capturing the write into the wrong application.
22
+ */
23
+ async function globalFromSession(sdk) {
24
+ try {
25
+ const effective = await readEffectiveApplication(sdk);
26
+ if (effective.sys_id === GLOBAL_APPLICATION) return { value: GLOBAL_APPLICATION };
27
+ return { note: `\nThe session application picker reports ${effective.sys_id}, not Global, and no apps.current_app preference is persisted for this user — the selection cannot be treated as Global.` };
28
+ } catch (error) {
29
+ return { note: `\nThe session application picker could not be read (${error.message}), so Global cannot be confirmed.` };
30
+ }
31
+ }
32
+
11
33
  const raw = (record, key) => record?.[key]?.value ?? record?.[key];
12
34
  export async function exactContextRecord(sdk, table, field, identifier) {
13
35
  if (typeof identifier !== 'string' || !identifier.trim()) throw contextFailure(`Missing intended ${table} identifier.`);
@@ -40,7 +62,7 @@ export async function readWriteContext(sdk) {
40
62
  * branch below says what is actually wrong and names the command that fixes
41
63
  * it.
42
64
  */
43
- async function preference({ key, label, remediation, sessionTruth }) {
65
+ async function preference({ key, label, remediation, sessionTruth, sessionFallback }) {
44
66
  let rows;
45
67
  try {
46
68
  rows = await sdk.list('sys_user_preference', new URLSearchParams({
@@ -53,8 +75,12 @@ export async function readWriteContext(sdk) {
53
75
  );
54
76
  }
55
77
  if (rows.length === 0) {
78
+ // Only the documented Global representation (absent row + session picker
79
+ // reporting Global) may recover here; an unproven scope still fails.
80
+ const fallback = sessionFallback ? await sessionFallback() : null;
81
+ if (fallback?.value) return fallback.value;
56
82
  throw contextFailure(
57
- `No ${label} is selected for ${user.user_name}, so there is no capture context to verify this write against.${await sessionNote(sessionTruth)}`,
83
+ `No ${label} is selected for ${user.user_name}, so there is no capture context to verify this write against.${fallback?.note || ''}${await sessionNote(sessionTruth)}`,
58
84
  `Select one first, then rerun the same command: ${remediation}. --expect-scope and --expect-update-set assert an existing selection; they cannot create one.`,
59
85
  );
60
86
  }
@@ -89,6 +115,7 @@ export async function readWriteContext(sdk) {
89
115
  preference({
90
116
  key: 'apps.current_app', label: 'application scope',
91
117
  remediation: 'jsn scopes set "<scope value or name>"',
118
+ sessionFallback: () => globalFromSession(sdk),
92
119
  }),
93
120
  preference({
94
121
  key: 'sys_update_set', label: 'update set',