@sasjs/api 0.49.0 → 0.50.0

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 (45) hide show
  1. package/README.md +11 -0
  2. package/build/browser.js +407 -47
  3. package/build/cjs/appstream/identity.js +2 -31
  4. package/build/cjs/uuid.js +30 -0
  5. package/build/cjs/viya/appSurface.js +241 -0
  6. package/build/cjs/viya/compute.js +71 -20
  7. package/build/cjs/viya/declared.js +96 -0
  8. package/build/cjs/viya/dispatch.js +10 -0
  9. package/build/cjs/viya/identity.js +191 -0
  10. package/build/cjs/viya/overlay.js +10 -0
  11. package/build/cjs/viya/seed.js +34 -8
  12. package/build/cjs/viya/service.js +3 -1
  13. package/build/cjs/viya/sessions.js +24 -10
  14. package/build/esm/appstream/identity.d.ts +1 -9
  15. package/build/esm/appstream/identity.d.ts.map +1 -1
  16. package/build/esm/appstream/identity.js +1 -30
  17. package/build/esm/identity/types.d.ts +2 -0
  18. package/build/esm/identity/types.d.ts.map +1 -1
  19. package/build/esm/uuid.d.ts +6 -0
  20. package/build/esm/uuid.d.ts.map +1 -0
  21. package/build/esm/uuid.js +26 -0
  22. package/build/esm/viya/appSurface.d.ts +51 -0
  23. package/build/esm/viya/appSurface.d.ts.map +1 -0
  24. package/build/esm/viya/appSurface.js +238 -0
  25. package/build/esm/viya/compute.d.ts.map +1 -1
  26. package/build/esm/viya/compute.js +73 -22
  27. package/build/esm/viya/declared.d.ts.map +1 -1
  28. package/build/esm/viya/declared.js +96 -0
  29. package/build/esm/viya/dispatch.d.ts +3 -0
  30. package/build/esm/viya/dispatch.d.ts.map +1 -1
  31. package/build/esm/viya/dispatch.js +11 -1
  32. package/build/esm/viya/identity.d.ts +34 -0
  33. package/build/esm/viya/identity.d.ts.map +1 -0
  34. package/build/esm/viya/identity.js +187 -0
  35. package/build/esm/viya/overlay.d.ts.map +1 -1
  36. package/build/esm/viya/overlay.js +10 -0
  37. package/build/esm/viya/seed.d.ts +29 -7
  38. package/build/esm/viya/seed.d.ts.map +1 -1
  39. package/build/esm/viya/seed.js +32 -7
  40. package/build/esm/viya/service.d.ts.map +1 -1
  41. package/build/esm/viya/service.js +3 -1
  42. package/build/esm/viya/sessions.d.ts +24 -6
  43. package/build/esm/viya/sessions.d.ts.map +1 -1
  44. package/build/esm/viya/sessions.js +24 -10
  45. package/package.json +3 -1
@@ -30,37 +30,8 @@ const normaliseAppLoc = (appLoc) => {
30
30
  return normalised;
31
31
  };
32
32
  exports.normaliseAppLoc = normaliseAppLoc;
33
- /**
34
- * A new id: a version 4 UUID.
35
- *
36
- * `crypto.randomUUID` exists in Node and in a browser worker on https or localhost,
37
- * which is where the mock drive runs. The fallback builds the same thing from
38
- * `getRandomValues` rather than from `Math.random`, so a weaker environment does not
39
- * quietly produce a weaker id.
40
- */
41
- const newAppId = () => {
42
- const webCrypto = globalThis.crypto;
43
- if (typeof webCrypto?.randomUUID === 'function')
44
- return webCrypto.randomUUID();
45
- if (typeof webCrypto?.getRandomValues !== 'function')
46
- throw new Error('No cryptographic source of randomness is available.');
47
- const bytes = new Uint8Array(16);
48
- webCrypto.getRandomValues(bytes);
49
- // version 4, variant 10xx
50
- bytes[6] = (bytes[6] & 0x0f) | 0x40;
51
- bytes[8] = (bytes[8] & 0x3f) | 0x80;
52
- const hex = Array.from(bytes)
53
- .map((byte) => byte.toString(16).padStart(2, '0'))
54
- .join('');
55
- return [
56
- hex.slice(0, 8),
57
- hex.slice(8, 12),
58
- hex.slice(12, 16),
59
- hex.slice(16, 20),
60
- hex.slice(20)
61
- ].join('-');
62
- };
63
- exports.newAppId = newAppId;
33
+ var uuid_js_1 = require("../uuid.js");
34
+ Object.defineProperty(exports, "newAppId", { enumerable: true, get: function () { return uuid_js_1.newUuidV4; } });
64
35
  // no `i` flag: `newAppId` mints lower case and every lookup compares exactly, so
65
36
  // a guard that accepts upper case would vouch for an id no lookup can find
66
37
  const APP_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.newUuidV4 = void 0;
4
+ /**
5
+ * A UUID v4 for Node and browser workers. Where `randomUUID` is unavailable,
6
+ * build it from `getRandomValues`; do not fall back to weaker randomness.
7
+ */
8
+ const newUuidV4 = () => {
9
+ const webCrypto = globalThis.crypto;
10
+ if (typeof webCrypto?.randomUUID === 'function')
11
+ return webCrypto.randomUUID();
12
+ if (typeof webCrypto?.getRandomValues !== 'function')
13
+ throw new Error('No cryptographic source of randomness is available.');
14
+ const bytes = new Uint8Array(16);
15
+ webCrypto.getRandomValues(bytes);
16
+ // version 4, variant 10xx
17
+ bytes[6] = (bytes[6] & 0x0f) | 0x40;
18
+ bytes[8] = (bytes[8] & 0x3f) | 0x80;
19
+ const hex = Array.from(bytes)
20
+ .map((byte) => byte.toString(16).padStart(2, '0'))
21
+ .join('');
22
+ return [
23
+ hex.slice(0, 8),
24
+ hex.slice(8, 12),
25
+ hex.slice(12, 16),
26
+ hex.slice(16, 20),
27
+ hex.slice(20)
28
+ ].join('-');
29
+ };
30
+ exports.newUuidV4 = newUuidV4;
@@ -0,0 +1,241 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.APP_SURFACE = exports.APP_SURFACE_APPLICATION = void 0;
4
+ /**
5
+ * The application the inventory was measured from.
6
+ *
7
+ * Named rather than assumed: the inventory describes one application's calls,
8
+ * and a second application running on an emulated estate is a second inventory -
9
+ * not an edit to this one, whose rows would then be a claim about a client
10
+ * nobody measured.
11
+ */
12
+ exports.APP_SURFACE_APPLICATION = {
13
+ name: 'Data Controller for SAS',
14
+ repository: 'https://git.datacontroller.io/dc/dc',
15
+ measuredFrom: 'client/src'
16
+ };
17
+ /** Why a namespace the API-explorer page lists is not an answered operation. */
18
+ const EXPLORER_ONLY = 'The application names this namespace in its Viya API map, which its API-explorer page reads; no product screen calls it, so the emulated estate does not answer it.';
19
+ exports.APP_SURFACE = [
20
+ // the auth flow the client shares with the adapter
21
+ {
22
+ path: '/SASLogon',
23
+ family: 'viya-auth',
24
+ decision: 'in',
25
+ reason: 'the auth flow, named by the application as well as the adapter, and the reason the emulated paths cannot be renamed'
26
+ },
27
+ // compute: the list, and the read of one context a deploy screen makes
28
+ {
29
+ path: '/compute/contexts',
30
+ family: 'viya-compute',
31
+ decision: 'in',
32
+ reason: 'the deploy screen lists the contexts it may run a session in, and picks the one the wizard will use'
33
+ },
34
+ {
35
+ path: '/compute/contexts/{}',
36
+ family: 'viya-compute',
37
+ decision: 'in',
38
+ reason: 'the deploy screen reads each context in full for its batch identity and reuse setting, which the list view does not carry'
39
+ },
40
+ // folders: the two reads an application makes of a deployment folder
41
+ {
42
+ path: '/folders/folders/@item',
43
+ family: 'viya-folders',
44
+ decision: 'in',
45
+ reason: 'the application resolves its own appLoc by path to find the services it will run'
46
+ },
47
+ {
48
+ path: '/folders/folders/{}/members',
49
+ family: 'viya-folders',
50
+ decision: 'in',
51
+ reason: 'the application lists the members of the folder it resolved, to find a deployed service'
52
+ },
53
+ // identities: the family the adapter asks one question of and an app asks six
54
+ {
55
+ path: '/identities/groups',
56
+ family: 'viya-identity',
57
+ decision: 'in',
58
+ reason: 'the deploy screen fetches the group list to offer the admin-group dropdown, and its failure aborts the wizard'
59
+ },
60
+ {
61
+ path: '/identities/groups/{}',
62
+ family: 'viya-identity',
63
+ decision: 'in',
64
+ reason: 'the group screen appends the group id and a member list to this fragment, to show who holds a group'
65
+ },
66
+ {
67
+ path: '/identities/users',
68
+ family: 'viya-identity',
69
+ decision: 'in',
70
+ reason: 'the user screen lists the accounts the estate holds'
71
+ },
72
+ {
73
+ path: '/identities/users/@currentUser',
74
+ family: 'viya-identity',
75
+ decision: 'in',
76
+ reason: 'the caller, which the application reads for its own profile as the adapter does'
77
+ },
78
+ {
79
+ path: '/identities/users/@currentUser/memberships',
80
+ family: 'viya-identity',
81
+ decision: 'in',
82
+ reason: 'the deploy screen filters the group list to the caller own groups, and falls back to all groups when this read fails'
83
+ },
84
+ {
85
+ path: '/identities/users/{}',
86
+ family: 'viya-identity',
87
+ decision: 'in',
88
+ reason: 'the user screen appends an account id to this fragment for a profile and its memberships'
89
+ },
90
+ {
91
+ path: '/identities/users/{}/avatar/content',
92
+ family: 'viya-identity',
93
+ decision: 'in',
94
+ reason: 'the header renders the caller avatar from this URL, and an account with none answers the 404 an estate would'
95
+ },
96
+ // the API roots and the explorer-only namespaces: named, never called
97
+ {
98
+ path: '/identities',
99
+ family: 'viya-identity',
100
+ decision: 'declined',
101
+ reason: 'the service root the application API map lists for its explorer page, not an endpoint any screen calls'
102
+ },
103
+ {
104
+ path: '/folders',
105
+ family: 'viya-folders',
106
+ decision: 'declined',
107
+ reason: 'the service root the application API map lists for its explorer page, not an endpoint any screen calls'
108
+ },
109
+ {
110
+ path: '/files',
111
+ family: 'viya-files',
112
+ decision: 'declined',
113
+ reason: 'the service root the application API map lists for its explorer page, not an endpoint any screen calls'
114
+ },
115
+ {
116
+ path: '/jobDefinitions',
117
+ family: 'viya-jobs',
118
+ decision: 'declined',
119
+ reason: 'the service root the application API map lists for its explorer page, not an endpoint any screen calls'
120
+ },
121
+ {
122
+ path: '/jobExecution',
123
+ family: 'viya-jobs',
124
+ decision: 'declined',
125
+ reason: 'the service root the application API map lists for its explorer page, not an endpoint any screen calls'
126
+ },
127
+ {
128
+ path: '/annotations',
129
+ family: 'viya-files',
130
+ decision: 'declined',
131
+ reason: EXPLORER_ONLY
132
+ },
133
+ {
134
+ path: '/authorization',
135
+ family: 'viya-identity',
136
+ decision: 'declined',
137
+ reason: EXPLORER_ONLY
138
+ },
139
+ {
140
+ path: '/businessRules',
141
+ family: 'viya-jobs',
142
+ decision: 'declined',
143
+ reason: EXPLORER_ONLY
144
+ },
145
+ {
146
+ path: '/dataMining',
147
+ family: 'viya-jobs',
148
+ decision: 'declined',
149
+ reason: EXPLORER_ONLY
150
+ },
151
+ {
152
+ path: '/decisionsRuntimeBuilder',
153
+ family: 'viya-jobs',
154
+ decision: 'declined',
155
+ reason: EXPLORER_ONLY
156
+ },
157
+ {
158
+ path: '/insights',
159
+ family: 'viya-jobs',
160
+ decision: 'declined',
161
+ reason: EXPLORER_ONLY
162
+ },
163
+ {
164
+ path: '/microanalyticScore',
165
+ family: 'viya-jobs',
166
+ decision: 'declined',
167
+ reason: EXPLORER_ONLY
168
+ },
169
+ {
170
+ path: '/mlPipelineAutomation',
171
+ family: 'viya-jobs',
172
+ decision: 'declined',
173
+ reason: EXPLORER_ONLY
174
+ },
175
+ {
176
+ path: '/modelManagement',
177
+ family: 'viya-jobs',
178
+ decision: 'declined',
179
+ reason: EXPLORER_ONLY
180
+ },
181
+ {
182
+ path: '/modelPublish',
183
+ family: 'viya-jobs',
184
+ decision: 'declined',
185
+ reason: EXPLORER_ONLY
186
+ },
187
+ {
188
+ path: '/modelRepository',
189
+ family: 'viya-jobs',
190
+ decision: 'declined',
191
+ reason: EXPLORER_ONLY
192
+ },
193
+ {
194
+ path: '/referenceData',
195
+ family: 'viya-jobs',
196
+ decision: 'declined',
197
+ reason: EXPLORER_ONLY
198
+ },
199
+ {
200
+ path: '/relationships',
201
+ family: 'viya-folders',
202
+ decision: 'declined',
203
+ reason: EXPLORER_ONLY
204
+ },
205
+ {
206
+ path: '/reportImages',
207
+ family: 'viya-jobs',
208
+ decision: 'declined',
209
+ reason: EXPLORER_ONLY
210
+ },
211
+ {
212
+ path: '/reportTransforms',
213
+ family: 'viya-jobs',
214
+ decision: 'declined',
215
+ reason: EXPLORER_ONLY
216
+ },
217
+ {
218
+ path: '/reports',
219
+ family: 'viya-jobs',
220
+ decision: 'declined',
221
+ reason: EXPLORER_ONLY
222
+ },
223
+ {
224
+ path: '/subjectContacts',
225
+ family: 'viya-jobs',
226
+ decision: 'declined',
227
+ reason: EXPLORER_ONLY
228
+ },
229
+ {
230
+ path: '/treatmentDefinitions',
231
+ family: 'viya-jobs',
232
+ decision: 'declined',
233
+ reason: EXPLORER_ONLY
234
+ },
235
+ {
236
+ path: '/visualAnalytics',
237
+ family: 'viya-jobs',
238
+ decision: 'declined',
239
+ reason: EXPLORER_ONLY
240
+ }
241
+ ];
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.COMPUTE_HANDLERS = exports.contextNameFrom = exports.EMULATED_CONTEXT_ID = exports.DEFAULT_CONTEXT_NAME = void 0;
4
4
  const types_js_1 = require("../types.js");
5
5
  const seed_js_1 = require("./seed.js");
6
- const seed_js_2 = require("./seed.js");
7
6
  const sessions_js_1 = require("./sessions.js");
8
7
  const ids_js_1 = require("./ids.js");
9
8
  /**
@@ -54,7 +53,7 @@ const linksFor = (uri, type, collection = false, itemType = false) => [
54
53
  ...(itemType ? { itemType: type } : {})
55
54
  }
56
55
  ];
57
- const estateOf = (services) => (0, sessions_js_1.estateFor)((0, seed_js_2.seedOf)(services.viya));
56
+ const estateOf = (services) => (0, sessions_js_1.estateFor)((0, seed_js_1.estateKeyOf)(services.viya), (0, seed_js_1.seedOf)(services.viya));
58
57
  /**
59
58
  * The context name a client asked for.
60
59
  *
@@ -77,6 +76,31 @@ const contextBody = (name, caller) => ({
77
76
  version: 2,
78
77
  links: linksFor(`/compute/contexts/${exports.EMULATED_CONTEXT_ID}`, 'application/vnd.sas.compute.context')
79
78
  });
79
+ /**
80
+ * The context in full, for the read a client makes of one it already holds.
81
+ *
82
+ * The list view Viya answers is deliberately minimal, so a client that needs a
83
+ * context's attributes reads the context itself - Data Controller's deploy
84
+ * screen fetches each one to pick up its batch identity. The attributes are the
85
+ * ones an emulated estate truthfully has: nothing runs as a batch identity here,
86
+ * and `reuseServerProcesses` is `false` for the same reason, which is what leaves
87
+ * a client's batch-id list empty rather than inventing an account to run as.
88
+ */
89
+ const contextDetailsBody = (caller) => ({
90
+ ...contextBody(exports.DEFAULT_CONTEXT_NAME, caller),
91
+ description: 'The compute context an emulated estate answers for',
92
+ creationTimeStamp: ids_js_1.EMULATED_NOW,
93
+ modifiedTimeStamp: ids_js_1.EMULATED_NOW,
94
+ modifiedBy: caller,
95
+ launchType: 'service',
96
+ launchContext: { contextId: exports.EMULATED_CONTEXT_ID },
97
+ environment: { autoExecLines: [] },
98
+ attributes: {
99
+ reuseServerProcesses: 'false',
100
+ allowXCMD: 'false',
101
+ serverMinAvailable: '1'
102
+ }
103
+ });
80
104
  const sessionBody = (services, session, autoExecLines, caller) => {
81
105
  const { id } = session;
82
106
  const uri = `/compute/sessions/${id}`;
@@ -137,15 +161,31 @@ const jobBody = (job) => {
137
161
  ])
138
162
  };
139
163
  };
140
- /** The session the request names, or the 404 a client that lost it expects. */
141
- const sessionOf = (services, id) => {
164
+ /** The browser mock has an anonymous principal distinct from every named user. */
165
+ const ownerOf = (subject) => {
166
+ if (subject === undefined)
167
+ return { kind: 'anonymous' };
168
+ if (!subject || typeof subject.userId !== 'string' || !subject.userId.trim())
169
+ throw new types_js_1.ApiError(401, 'A valid caller is required.');
170
+ if (subject.ownerId === undefined)
171
+ return { kind: 'user', key: subject.userId };
172
+ if (typeof subject.ownerId !== 'string' || !subject.ownerId.trim())
173
+ throw new types_js_1.ApiError(401, 'A valid caller is required.');
174
+ return { kind: 'account', key: subject.ownerId };
175
+ };
176
+ /** Ownerless records cannot be attributed and are deliberately inaccessible. */
177
+ const sessionOf = (services, id, subject) => {
178
+ const owner = ownerOf(subject);
142
179
  const session = estateOf(services).session(id);
143
- if (!session)
180
+ if (!session ||
181
+ !session.owner ||
182
+ session.owner.kind !== owner.kind ||
183
+ session.owner.key !== owner.key)
144
184
  throw new types_js_1.ApiError(404, `Session with ID '${id}' was not found.`);
145
185
  return session;
146
186
  };
147
- const jobOf = (services, sessionId, jobId) => {
148
- const job = sessionOf(services, sessionId).jobs.get(jobId);
187
+ const jobOf = (services, sessionId, jobId, subject) => {
188
+ const job = sessionOf(services, sessionId, subject).jobs.get(jobId);
149
189
  if (!job)
150
190
  throw new types_js_1.ApiError(404, `Job with ID '${jobId}' was not found.`);
151
191
  return job;
@@ -176,29 +216,37 @@ exports.COMPUTE_HANDLERS = {
176
216
  }
177
217
  };
178
218
  },
219
+ 'GET /compute/contexts/{}': async ({ request, params }) => {
220
+ // the estate has one context and its id does not move, so an id it is not is
221
+ // an id no context here ever had - the same refusal the drive makes for an
222
+ // unknown folder rather than a body about some other context
223
+ if (params.id !== exports.EMULATED_CONTEXT_ID)
224
+ throw new types_js_1.ApiError(404, `No compute context matches the id ${params.id}. The emulated estate answers one context, and this is not its id.`);
225
+ return { status: 200, body: contextDetailsBody((0, ids_js_1.callerId)(request.subject)) };
226
+ },
179
227
  'POST /compute/contexts/{}/sessions': async ({ services, params, request }) => {
180
228
  if (params.id !== exports.EMULATED_CONTEXT_ID)
181
229
  throw new types_js_1.ApiError(404, `Context with ID '${params.id}' was not found.`);
182
230
  const body = (request.body ?? {});
183
- const session = estateOf(services).create();
231
+ const session = estateOf(services).create(ownerOf(request.subject));
184
232
  return {
185
233
  status: 201,
186
234
  body: sessionBody(services, session, body.environment?.autoExecLines ?? [], (0, ids_js_1.callerId)(request.subject))
187
235
  };
188
236
  },
189
- 'GET /compute/sessions/{}/state': async ({ services, params }) => {
190
- sessionOf(services, params.id);
237
+ 'GET /compute/sessions/{}/state': async ({ services, params, request }) => {
238
+ sessionOf(services, params.id, request.subject);
191
239
  // a bare enum, not an object: the adapter calls `.trim()` on the answer, and
192
240
  // the capture recorded no shape here because there is no JSON body
193
241
  return { status: 200, body: 'idle' };
194
242
  },
195
- 'DELETE /compute/sessions/{}': async ({ services, params }) => {
196
- sessionOf(services, params.id);
243
+ 'DELETE /compute/sessions/{}': async ({ services, params, request }) => {
244
+ sessionOf(services, params.id, request.subject);
197
245
  estateOf(services).remove(params.id);
198
246
  return { status: 204, body: undefined };
199
247
  },
200
248
  'POST /compute/sessions/{}/jobs': async ({ services, params, request }) => {
201
- const session = sessionOf(services, params.id);
249
+ const session = sessionOf(services, params.id, request.subject);
202
250
  const body = (request.body ?? {});
203
251
  const job = estateOf(services).submit(session, body);
204
252
  const execute = services.viya?.execute;
@@ -237,8 +285,8 @@ exports.COMPUTE_HANDLERS = {
237
285
  });
238
286
  return { status: 201, body: jobBody(job) };
239
287
  },
240
- 'GET /compute/sessions/{}/filerefs/_webout/content': async ({ services, params }) => {
241
- const session = sessionOf(services, params.id);
288
+ 'GET /compute/sessions/{}/filerefs/_webout/content': async ({ services, params, request }) => {
289
+ const session = sessionOf(services, params.id, request.subject);
242
290
  const last = [...session.jobs.values()].pop();
243
291
  if (!last)
244
292
  throw new types_js_1.ApiError(404, 'This session has no `_webout` yet: nothing has run in it.');
@@ -257,20 +305,23 @@ exports.COMPUTE_HANDLERS = {
257
305
  headers: { 'content-type': 'text/plain' }
258
306
  };
259
307
  },
260
- 'GET /compute/sessions/{}/jobs/{}': async ({ services, params }) => {
308
+ 'GET /compute/sessions/{}/jobs/{}': async ({ services, params, request }) => {
261
309
  const [sessionId, jobId] = segmentsOf(params);
262
- return { status: 200, body: jobBody(jobOf(services, sessionId, jobId)) };
310
+ return {
311
+ status: 200,
312
+ body: jobBody(jobOf(services, sessionId, jobId, request.subject))
313
+ };
263
314
  },
264
- 'GET /compute/sessions/{}/jobs/{}/state': async ({ services, params }) => {
315
+ 'GET /compute/sessions/{}/jobs/{}/state': async ({ services, params, request }) => {
265
316
  const [sessionId, jobId] = segmentsOf(params);
266
317
  return {
267
318
  status: 200,
268
- body: jobOf(services, sessionId, jobId).state
319
+ body: jobOf(services, sessionId, jobId, request.subject).state
269
320
  };
270
321
  },
271
322
  'GET /compute/sessions/{}/jobs/{}/log/content': async ({ services, params, request }) => {
272
323
  const [sessionId, jobId] = segmentsOf(params);
273
- const job = jobOf(services, sessionId, jobId);
324
+ const job = jobOf(services, sessionId, jobId, request.subject);
274
325
  const start = Number(request.query?.start ?? 0) || 0;
275
326
  const limit = Number(request.query?.limit ?? 0) || 0;
276
327
  const lines = job.log.slice(start, limit ? start + limit : undefined);
@@ -32,6 +32,102 @@ exports.DECLARED = [
32
32
  // there is no JSON shape to record
33
33
  shape: undefined,
34
34
  declared: 'The adapter fetches this only when a run expects a webout (`expectWebout`), and the recording pass submits a `%put` and reads the log instead. Without it an application cannot receive the data its service returns, so the emulator answers it from the job it just ran.'
35
+ },
36
+ // The application's own identity reads. No capture describes these at all: the
37
+ // recorder drives the client the adapter is, and Data Controller's group, user
38
+ // and deploy screens call the identity service from the browser instead. That
39
+ // is why they are declared rather than recorded, and why the scope they belong
40
+ // to is stated in `src/viya/appSurface.ts`.
41
+ {
42
+ id: 'GET /identities/groups',
43
+ method: 'GET',
44
+ path: '/identities/groups',
45
+ steps: [],
46
+ statuses: [200],
47
+ queries: ['sortBy', 'limit', 'start'],
48
+ request: { queries: ['sortBy', 'limit', 'start'], body: undefined },
49
+ // a collection of groups, whose own shape Viya publishes rather than an
50
+ // estate recording supplying it
51
+ shape: undefined,
52
+ declared: 'The application fetches the group list twice on its deploy screen - for the admin-group dropdown and, filtered, for the caller own groups - and aborts the wizard when that read fails. The adapter never calls it, so no recording pass reaches it.'
53
+ },
54
+ {
55
+ id: 'GET /identities/groups/{}/members',
56
+ method: 'GET',
57
+ path: '/identities/groups/{}/members',
58
+ steps: [],
59
+ statuses: [200, 404],
60
+ queries: ['limit'],
61
+ request: { queries: ['limit'], body: undefined },
62
+ shape: undefined,
63
+ declared: 'The group screen lists the accounts that hold a group, following the members link the group list advertises. The adapter has no identity route beyond the caller, so a capture driven by it cannot reach this one.'
64
+ },
65
+ {
66
+ id: 'GET /identities/users',
67
+ method: 'GET',
68
+ path: '/identities/users',
69
+ steps: [],
70
+ statuses: [200],
71
+ queries: ['limit', 'start'],
72
+ request: { queries: ['limit', 'start'], body: undefined },
73
+ shape: undefined,
74
+ declared: 'The user screen lists the estate accounts. The adapter does not offer an account list and never requests one, so the recording pass has no way to observe it.'
75
+ },
76
+ {
77
+ id: 'GET /identities/users/{}',
78
+ method: 'GET',
79
+ path: '/identities/users/{}',
80
+ steps: [],
81
+ statuses: [200, 404],
82
+ queries: [],
83
+ request: { queries: [], body: undefined },
84
+ shape: undefined,
85
+ declared: 'The user screen reads one account from the id the list returned, for the profile above the memberships. The adapter asks only about the caller, which is a different operation with its own row.'
86
+ },
87
+ {
88
+ id: 'GET /identities/users/@currentUser/memberships',
89
+ method: 'GET',
90
+ path: '/identities/users/@currentUser/memberships',
91
+ steps: [],
92
+ statuses: [200],
93
+ queries: ['limit', 'start'],
94
+ request: { queries: ['limit', 'start'], body: undefined },
95
+ shape: undefined,
96
+ declared: 'The deploy screen filters the admin-group list to the groups the caller belongs to, and shows every group when this read fails. The adapter reads the caller itself but never the caller memberships.'
97
+ },
98
+ {
99
+ id: 'GET /identities/users/{}/memberships',
100
+ method: 'GET',
101
+ path: '/identities/users/{}/memberships',
102
+ steps: [],
103
+ statuses: [200, 401],
104
+ queries: ['limit', 'start'],
105
+ request: { queries: ['limit', 'start'], body: undefined },
106
+ shape: undefined,
107
+ declared: 'The user screen lists the groups any account holds, addressed by the id the list returned. It is the same answer as the caller own memberships for one id, and the adapter asks for neither.'
108
+ },
109
+ {
110
+ id: 'GET /identities/users/{}/avatar/content',
111
+ method: 'GET',
112
+ path: '/identities/users/{}/avatar/content',
113
+ steps: [],
114
+ statuses: [404],
115
+ queries: [],
116
+ request: { queries: [], body: undefined },
117
+ // the body is an image when an estate holds one: there is no JSON shape
118
+ shape: undefined,
119
+ declared: 'The header renders the caller avatar from this URL, and an estate whose identity carries no avatar answers 404 so the client falls back to its own image. The adapter has no avatar read.'
120
+ },
121
+ {
122
+ id: 'GET /compute/contexts/{}',
123
+ method: 'GET',
124
+ path: '/compute/contexts/{}',
125
+ steps: [],
126
+ statuses: [200, 404],
127
+ queries: [],
128
+ request: { queries: [], body: undefined },
129
+ shape: undefined,
130
+ declared: 'The deploy screen reads each context in full, because the list view carries neither the batch identity nor the reuse setting it filters on. The capture recorded the list only, so the read it follows with is stated here.'
35
131
  }
36
132
  ];
37
133
  /** Every operation the emulator answers: what an estate did, plus what it must. */
@@ -56,6 +56,9 @@ exports.findViyaOperation = findViyaOperation;
56
56
  *
57
57
  * `request` is the same shape the SASjs dispatch takes, so a host that already
58
58
  * resolves a caller - a session cookie - passes `subject` rather than a token.
59
+ * For compute sessions a host with credentials must pass the authenticated
60
+ * subject on every request: a token alone is refused. No subject and no token
61
+ * is the anonymous browser mock, not an authentication boundary.
59
62
  */
60
63
  const dispatchViya = async (services, method, path, request = {}) => {
61
64
  const headers = (0, version_js_1.emulatedHeaders)();
@@ -98,6 +101,13 @@ const dispatchViya = async (services, method, path, request = {}) => {
98
101
  }
99
102
  };
100
103
  try {
104
+ // A host must resolve credentials before compute dispatch. A missing subject
105
+ // is the anonymous mock only when no credential was supplied.
106
+ if (request.subject === undefined &&
107
+ request.token !== undefined &&
108
+ (found.operation.id === 'POST /compute/contexts/{}/sessions' ||
109
+ found.operation.path.startsWith('/compute/sessions/')))
110
+ throw new types_js_1.ApiError(401, 'A valid caller is required.');
101
111
  const answer = await handler({
102
112
  services,
103
113
  request,