@sasjs/api 0.46.0 → 0.47.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.
package/build/browser.js CHANGED
@@ -1,4 +1,4 @@
1
- /* @sasjs/api 0.46.0 - the SASjs Server API, for a service worker. https://github.com/sasjs/api */
1
+ /* @sasjs/api 0.47.0 - the SASjs Server API, for a service worker. https://github.com/sasjs/api */
2
2
  "use strict";
3
3
  var SASjsApi = (() => {
4
4
  var __defProp = Object.defineProperty;
@@ -5630,6 +5630,7 @@ var SASjsApi = (() => {
5630
5630
  // src/viya/ids.ts
5631
5631
  var EMULATED_NOW = "2026-01-01T00:00:00.000Z";
5632
5632
  var EMULATED_USER = { id: "emulated-user", name: "Emulated User" };
5633
+ var callerId = (subject) => subject?.userId ?? EMULATED_USER.id;
5633
5634
  var idFor = (path, kind = "folder") => {
5634
5635
  const hash2 = (input, seed) => {
5635
5636
  let value = seed;
@@ -5688,23 +5689,23 @@ var SASjsApi = (() => {
5688
5689
  const match = /name\s*,\s*'([^']*)'|name\s*,\s*"([^"]*)"/i.exec(filter);
5689
5690
  return match?.[1] ?? match?.[2] ?? DEFAULT_CONTEXT_NAME;
5690
5691
  };
5691
- var contextBody = (name) => ({
5692
+ var contextBody = (name, caller) => ({
5692
5693
  id: EMULATED_CONTEXT_ID,
5693
5694
  name,
5694
- createdBy: EMULATED_USER.id,
5695
+ createdBy: caller,
5695
5696
  version: 2,
5696
5697
  links: linksFor(
5697
5698
  `/compute/contexts/${EMULATED_CONTEXT_ID}`,
5698
5699
  "application/vnd.sas.compute.context"
5699
5700
  )
5700
5701
  });
5701
- var sessionBody = (services, session, autoExecLines) => {
5702
+ var sessionBody = (services, session, autoExecLines, caller) => {
5702
5703
  const { id } = session;
5703
5704
  const uri = `/compute/sessions/${id}`;
5704
5705
  return {
5705
5706
  id,
5706
5707
  applicationName: "emulated",
5707
- owner: EMULATED_USER.id,
5708
+ owner: caller,
5708
5709
  serverId: idFor(
5709
5710
  normaliseServerUrl(services.viya?.serverUrl) || "emulated",
5710
5711
  "server"
@@ -5783,7 +5784,12 @@ var SASjsApi = (() => {
5783
5784
  limit,
5784
5785
  count: 1,
5785
5786
  version: 2,
5786
- items: [contextBody(contextNameFrom(request.query?.filter))],
5787
+ items: [
5788
+ contextBody(
5789
+ contextNameFrom(request.query?.filter),
5790
+ callerId(request.subject)
5791
+ )
5792
+ ],
5787
5793
  links: linksFor(
5788
5794
  "/compute/contexts",
5789
5795
  "application/vnd.sas.compute.context",
@@ -5806,7 +5812,8 @@ var SASjsApi = (() => {
5806
5812
  body: sessionBody(
5807
5813
  services,
5808
5814
  session,
5809
- body.environment?.autoExecLines ?? []
5815
+ body.environment?.autoExecLines ?? [],
5816
+ callerId(request.subject)
5810
5817
  )
5811
5818
  };
5812
5819
  },
@@ -5922,7 +5929,7 @@ var SASjsApi = (() => {
5922
5929
  if (/\.(jpe?g)$/i.test(name)) return "image/jpeg";
5923
5930
  return "application/octet-stream";
5924
5931
  };
5925
- var fileBody = (file) => {
5932
+ var fileBody = (file, caller) => {
5926
5933
  const id = idFor(file.path, "file");
5927
5934
  const uri = `/files/files/${id}`;
5928
5935
  const contentType = contentTypeOf(file.name);
@@ -5937,8 +5944,8 @@ var SASjsApi = (() => {
5937
5944
  fileVersion: 1,
5938
5945
  version: 2,
5939
5946
  typeDefName: "file",
5940
- createdBy: EMULATED_USER.id,
5941
- modifiedBy: EMULATED_USER.id,
5947
+ createdBy: caller,
5948
+ modifiedBy: caller,
5942
5949
  creationTimeStamp: EMULATED_NOW,
5943
5950
  modifiedTimeStamp: EMULATED_NOW,
5944
5951
  quarantine: false,
@@ -5950,7 +5957,7 @@ var SASjsApi = (() => {
5950
5957
  "content.openInBrowser": "true",
5951
5958
  "content.preview": "false",
5952
5959
  sasIconKey: "file",
5953
- typeRegistrant: EMULATED_USER.id
5960
+ typeRegistrant: caller
5954
5961
  },
5955
5962
  links: [
5956
5963
  {
@@ -6030,12 +6037,18 @@ var SASjsApi = (() => {
6030
6037
  const parent = await parentOf(drive, request.query?.parentFolderUri);
6031
6038
  const path = `${parent}/${upload.name}`.replace(/\/{2,}/g, "/");
6032
6039
  await drive.save(path, upload.contents);
6033
- return { status: 201, body: fileBody(await bodyOf(drive, path)) };
6040
+ return {
6041
+ status: 201,
6042
+ body: fileBody(await bodyOf(drive, path), callerId(request.subject))
6043
+ };
6034
6044
  },
6035
- "GET /files/files/{}": async ({ services, params }) => {
6045
+ "GET /files/files/{}": async ({ services, params, request }) => {
6036
6046
  const drive = requireDrive(services);
6037
6047
  const path = await pathForFileId(drive, params.id);
6038
- return { status: 200, body: fileBody(await bodyOf(drive, path)) };
6048
+ return {
6049
+ status: 200,
6050
+ body: fileBody(await bodyOf(drive, path), callerId(request.subject))
6051
+ };
6039
6052
  },
6040
6053
  "PATCH /files/files/{}": async ({ services, params, request }) => {
6041
6054
  const drive = requireDrive(services);
@@ -6047,7 +6060,10 @@ var SASjsApi = (() => {
6047
6060
  "/"
6048
6061
  );
6049
6062
  if (target !== path) await drive.rename(path, target);
6050
- return { status: 200, body: fileBody(await bodyOf(drive, target)) };
6063
+ return {
6064
+ status: 200,
6065
+ body: fileBody(await bodyOf(drive, target), callerId(request.subject))
6066
+ };
6051
6067
  },
6052
6068
  "GET /files/files/{}/content": async ({ services, params }) => {
6053
6069
  const drive = requireDrive(services);
@@ -6069,7 +6085,10 @@ var SASjsApi = (() => {
6069
6085
  if (contents === void 0 || contents === null)
6070
6086
  throw new ApiError(400, "File content is required.");
6071
6087
  await drive.update(path, contents);
6072
- return { status: 200, body: fileBody(await bodyOf(drive, path)) };
6088
+ return {
6089
+ status: 200,
6090
+ body: fileBody(await bodyOf(drive, path), callerId(request.subject))
6091
+ };
6073
6092
  }
6074
6093
  };
6075
6094
 
@@ -6092,7 +6111,7 @@ var SASjsApi = (() => {
6092
6111
  };
6093
6112
  return collection ? [members, self] : [self, members];
6094
6113
  };
6095
- var folderBody = async (drive, path) => {
6114
+ var folderBody = async (drive, path, caller) => {
6096
6115
  const listing = await drive.list(path);
6097
6116
  const id = idFor(path);
6098
6117
  const name = path.split("/").filter(Boolean).pop() ?? "";
@@ -6103,8 +6122,8 @@ var SASjsApi = (() => {
6103
6122
  description: "",
6104
6123
  type: "folder",
6105
6124
  version: 1,
6106
- createdBy: EMULATED_USER.id,
6107
- modifiedBy: EMULATED_USER.id,
6125
+ createdBy: caller,
6126
+ modifiedBy: caller,
6108
6127
  creationTimeStamp: EMULATED_NOW,
6109
6128
  modifiedTimeStamp: EMULATED_NOW,
6110
6129
  memberCount: listing.files.length + listing.folders.length,
@@ -6112,7 +6131,7 @@ var SASjsApi = (() => {
6112
6131
  links: linksFor2(`/folders/folders/${id}`)
6113
6132
  };
6114
6133
  };
6115
- var recycleBin = () => {
6134
+ var recycleBin = (caller) => {
6116
6135
  const path = "@myRecycleBin";
6117
6136
  const id = idFor(path);
6118
6137
  return {
@@ -6121,8 +6140,8 @@ var SASjsApi = (() => {
6121
6140
  description: "Recycle Bin",
6122
6141
  type: "trashFolder",
6123
6142
  version: 1,
6124
- createdBy: EMULATED_USER.id,
6125
- modifiedBy: EMULATED_USER.id,
6143
+ createdBy: caller,
6144
+ modifiedBy: caller,
6126
6145
  creationTimeStamp: EMULATED_NOW,
6127
6146
  modifiedTimeStamp: EMULATED_NOW,
6128
6147
  memberCount: 0,
@@ -6160,7 +6179,7 @@ var SASjsApi = (() => {
6160
6179
  var VIYA_HANDLERS = {
6161
6180
  "GET /identities/users/@currentUser": async ({ services, request }) => {
6162
6181
  const subject = request.subject ?? await services.identity?.authenticate(request.token);
6163
- const id = subject?.userId ?? EMULATED_USER.id;
6182
+ const id = callerId(subject);
6164
6183
  return {
6165
6184
  status: 200,
6166
6185
  body: {
@@ -6199,19 +6218,27 @@ var SASjsApi = (() => {
6199
6218
  }),
6200
6219
  "GET /folders/folders/@item": async ({ services, request }) => ({
6201
6220
  status: 200,
6202
- body: await folderBody(requireDrive(services), pathFromQuery(request))
6221
+ body: await folderBody(
6222
+ requireDrive(services),
6223
+ pathFromQuery(request),
6224
+ callerId(request.subject)
6225
+ )
6203
6226
  }),
6204
- "GET /folders/folders/@myRecycleBin": async () => ({
6227
+ "GET /folders/folders/@myRecycleBin": async ({ request }) => ({
6205
6228
  status: 200,
6206
- body: recycleBin()
6229
+ body: recycleBin(callerId(request.subject))
6207
6230
  }),
6208
- "GET /folders/folders/{}": async ({ services, params }) => {
6231
+ "GET /folders/folders/{}": async ({ services, params, request }) => {
6209
6232
  if (params.id === idFor("@myRecycleBin"))
6210
- return { status: 200, body: recycleBin() };
6233
+ return { status: 200, body: recycleBin(callerId(request.subject)) };
6211
6234
  const drive = requireDrive(services);
6212
6235
  return {
6213
6236
  status: 200,
6214
- body: await folderBody(drive, await pathForId(drive, params.id))
6237
+ body: await folderBody(
6238
+ drive,
6239
+ await pathForId(drive, params.id),
6240
+ callerId(request.subject)
6241
+ )
6215
6242
  };
6216
6243
  },
6217
6244
  "GET /folders/folders/{}/members": async ({ services, params, request }) => {
@@ -6235,14 +6262,15 @@ var SASjsApi = (() => {
6235
6262
  };
6236
6263
  const path = await pathForId(drive, params.id);
6237
6264
  const listing = await drive.list(path);
6265
+ const caller = callerId(request.subject);
6238
6266
  const items = [
6239
6267
  ...listing.folders.map((name) => ({
6240
6268
  id: idFor(`${path}/${name}`.replace(/\/{2,}/g, "/")),
6241
6269
  name,
6242
6270
  type: "folder",
6243
6271
  version: 1,
6244
- createdBy: EMULATED_USER.id,
6245
- modifiedBy: EMULATED_USER.id,
6272
+ createdBy: caller,
6273
+ modifiedBy: caller,
6246
6274
  creationTimeStamp: EMULATED_NOW,
6247
6275
  modifiedTimeStamp: EMULATED_NOW,
6248
6276
  parentFolderUri: `/folders/folders/${idFor(path)}`,
@@ -6257,8 +6285,8 @@ var SASjsApi = (() => {
6257
6285
  type: "file",
6258
6286
  version: 1,
6259
6287
  contentType: "text/plain",
6260
- createdBy: EMULATED_USER.id,
6261
- modifiedBy: EMULATED_USER.id,
6288
+ createdBy: caller,
6289
+ modifiedBy: caller,
6262
6290
  creationTimeStamp: EMULATED_NOW,
6263
6291
  modifiedTimeStamp: EMULATED_NOW,
6264
6292
  parentFolderUri: `/folders/folders/${idFor(path)}`,
@@ -6292,7 +6320,10 @@ var SASjsApi = (() => {
6292
6320
  const parent = parentUri ? await pathForId(drive, String(parentUri).split("/").pop()) : "/";
6293
6321
  const path = normalisePath(`${parent}/${body.name}`);
6294
6322
  await drive.mkdir(path);
6295
- return { status: 201, body: await folderBody(drive, path) };
6323
+ return {
6324
+ status: 201,
6325
+ body: await folderBody(drive, path, callerId(request.subject))
6326
+ };
6296
6327
  },
6297
6328
  "PATCH /folders/folders/{}": async ({ services, request, params }) => {
6298
6329
  const drive = requireDrive(services);
@@ -6301,7 +6332,7 @@ var SASjsApi = (() => {
6301
6332
  const path = await pathForId(drive, params.id);
6302
6333
  const body = request.body ?? {};
6303
6334
  if (isRecycleBin(body.parentFolderUri)) {
6304
- const removed = await folderBody(drive, path);
6335
+ const removed = await folderBody(drive, path, callerId(request.subject));
6305
6336
  await drive.rmdir(path);
6306
6337
  return {
6307
6338
  status: 200,
@@ -6315,7 +6346,10 @@ var SASjsApi = (() => {
6315
6346
  );
6316
6347
  const target = normalisePath(`${parent}/${name}`);
6317
6348
  if (target !== path) await drive.rename(path, target);
6318
- return { status: 200, body: await folderBody(drive, target) };
6349
+ return {
6350
+ status: 200,
6351
+ body: await folderBody(drive, target, callerId(request.subject))
6352
+ };
6319
6353
  },
6320
6354
  ...COMPUTE_HANDLERS,
6321
6355
  ...FILE_HANDLERS
@@ -70,20 +70,20 @@ const contextNameFrom = (filter) => {
70
70
  return match?.[1] ?? match?.[2] ?? exports.DEFAULT_CONTEXT_NAME;
71
71
  };
72
72
  exports.contextNameFrom = contextNameFrom;
73
- const contextBody = (name) => ({
73
+ const contextBody = (name, caller) => ({
74
74
  id: exports.EMULATED_CONTEXT_ID,
75
75
  name,
76
- createdBy: ids_js_1.EMULATED_USER.id,
76
+ createdBy: caller,
77
77
  version: 2,
78
78
  links: linksFor(`/compute/contexts/${exports.EMULATED_CONTEXT_ID}`, 'application/vnd.sas.compute.context')
79
79
  });
80
- const sessionBody = (services, session, autoExecLines) => {
80
+ const sessionBody = (services, session, autoExecLines, caller) => {
81
81
  const { id } = session;
82
82
  const uri = `/compute/sessions/${id}`;
83
83
  return {
84
84
  id,
85
85
  applicationName: 'emulated',
86
- owner: ids_js_1.EMULATED_USER.id,
86
+ owner: caller,
87
87
  serverId: (0, ids_js_1.idFor)((0, seed_js_1.normaliseServerUrl)(services.viya?.serverUrl) || 'emulated', 'server'),
88
88
  state: 'idle',
89
89
  attributes: {
@@ -169,7 +169,9 @@ exports.COMPUTE_HANDLERS = {
169
169
  limit,
170
170
  count: 1,
171
171
  version: 2,
172
- items: [contextBody((0, exports.contextNameFrom)(request.query?.filter))],
172
+ items: [
173
+ contextBody((0, exports.contextNameFrom)(request.query?.filter), (0, ids_js_1.callerId)(request.subject))
174
+ ],
173
175
  links: linksFor('/compute/contexts', 'application/vnd.sas.compute.context', true)
174
176
  }
175
177
  };
@@ -181,7 +183,7 @@ exports.COMPUTE_HANDLERS = {
181
183
  const session = estateOf(services).create();
182
184
  return {
183
185
  status: 201,
184
- body: sessionBody(services, session, body.environment?.autoExecLines ?? [])
186
+ body: sessionBody(services, session, body.environment?.autoExecLines ?? [], (0, ids_js_1.callerId)(request.subject))
185
187
  };
186
188
  },
187
189
  'GET /compute/sessions/{}/state': async ({ services, params }) => {
@@ -26,7 +26,7 @@ const contentTypeOf = (name) => {
26
26
  * client reads rather than placeholders: the three `content.*` flags say what can
27
27
  * be done with the file, and `typeRegistrant` says who registered the type.
28
28
  */
29
- const fileBody = (file) => {
29
+ const fileBody = (file, caller) => {
30
30
  const id = (0, ids_js_1.idFor)(file.path, 'file');
31
31
  const uri = `/files/files/${id}`;
32
32
  const contentType = contentTypeOf(file.name);
@@ -41,8 +41,8 @@ const fileBody = (file) => {
41
41
  fileVersion: 1,
42
42
  version: 2,
43
43
  typeDefName: 'file',
44
- createdBy: ids_js_1.EMULATED_USER.id,
45
- modifiedBy: ids_js_1.EMULATED_USER.id,
44
+ createdBy: caller,
45
+ modifiedBy: caller,
46
46
  creationTimeStamp: ids_js_1.EMULATED_NOW,
47
47
  modifiedTimeStamp: ids_js_1.EMULATED_NOW,
48
48
  quarantine: false,
@@ -54,7 +54,7 @@ const fileBody = (file) => {
54
54
  'content.openInBrowser': 'true',
55
55
  'content.preview': 'false',
56
56
  sasIconKey: 'file',
57
- typeRegistrant: ids_js_1.EMULATED_USER.id
57
+ typeRegistrant: caller
58
58
  },
59
59
  links: [
60
60
  {
@@ -150,12 +150,18 @@ exports.FILE_HANDLERS = {
150
150
  const parent = await parentOf(drive, request.query?.parentFolderUri);
151
151
  const path = `${parent}/${upload.name}`.replace(/\/{2,}/g, '/');
152
152
  await drive.save(path, upload.contents);
153
- return { status: 201, body: fileBody(await bodyOf(drive, path)) };
153
+ return {
154
+ status: 201,
155
+ body: fileBody(await bodyOf(drive, path), (0, ids_js_1.callerId)(request.subject))
156
+ };
154
157
  },
155
- 'GET /files/files/{}': async ({ services, params }) => {
158
+ 'GET /files/files/{}': async ({ services, params, request }) => {
156
159
  const drive = (0, ports_js_1.requireDrive)(services);
157
160
  const path = await pathForFileId(drive, params.id);
158
- return { status: 200, body: fileBody(await bodyOf(drive, path)) };
161
+ return {
162
+ status: 200,
163
+ body: fileBody(await bodyOf(drive, path), (0, ids_js_1.callerId)(request.subject))
164
+ };
159
165
  },
160
166
  'PATCH /files/files/{}': async ({ services, params, request }) => {
161
167
  const drive = (0, ports_js_1.requireDrive)(services);
@@ -165,7 +171,10 @@ exports.FILE_HANDLERS = {
165
171
  const target = `${path.split('/').slice(0, -1).join('/')}/${name}`.replace(/\/{2,}/g, '/');
166
172
  if (target !== path)
167
173
  await drive.rename(path, target);
168
- return { status: 200, body: fileBody(await bodyOf(drive, target)) };
174
+ return {
175
+ status: 200,
176
+ body: fileBody(await bodyOf(drive, target), (0, ids_js_1.callerId)(request.subject))
177
+ };
169
178
  },
170
179
  'GET /files/files/{}/content': async ({ services, params }) => {
171
180
  const drive = (0, ports_js_1.requireDrive)(services);
@@ -198,6 +207,9 @@ exports.FILE_HANDLERS = {
198
207
  if (contents === undefined || contents === null)
199
208
  throw new types_js_1.ApiError(400, 'File content is required.');
200
209
  await drive.update(path, contents);
201
- return { status: 200, body: fileBody(await bodyOf(drive, path)) };
210
+ return {
211
+ status: 200,
212
+ body: fileBody(await bodyOf(drive, path), (0, ids_js_1.callerId)(request.subject))
213
+ };
202
214
  }
203
215
  };
@@ -8,11 +8,23 @@
8
8
  * would be a cycle.
9
9
  */
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.normalisePath = exports.idFor = exports.EMULATED_USER = exports.EMULATED_NOW = void 0;
11
+ exports.normalisePath = exports.idFor = exports.callerId = exports.EMULATED_USER = exports.EMULATED_NOW = void 0;
12
12
  /** The emulated clock: a fixed instant, so a body is reproducible. */
13
13
  exports.EMULATED_NOW = '2026-01-01T00:00:00.000Z';
14
14
  /** The caller the emulated estate reports when a host does not name one. */
15
15
  exports.EMULATED_USER = { id: 'emulated-user', name: 'Emulated User' };
16
+ /**
17
+ * The id the emulated estate reports as the caller.
18
+ *
19
+ * A host that resolved the caller before dispatching - the server's signed-in
20
+ * account - passes it as `subject`; a host with no identity (the browser worker)
21
+ * passes none, and the fallback names itself, so the answer says on its face that
22
+ * no account was resolved. Bodies that carry `createdBy`, `modifiedBy` or `owner`
23
+ * use this, so an application that reads its own name back is told the account it
24
+ * signed in with.
25
+ */
26
+ const callerId = (subject) => subject?.userId ?? exports.EMULATED_USER.id;
27
+ exports.callerId = callerId;
16
28
  /**
17
29
  * A uuid shape from a string, deterministically.
18
30
  *
@@ -26,7 +26,7 @@ const linksFor = (uri, collection = false) => {
26
26
  // itemType its capture recorded
27
27
  return collection ? [members, self] : [self, members];
28
28
  };
29
- const folderBody = async (drive, path) => {
29
+ const folderBody = async (drive, path, caller) => {
30
30
  const listing = await drive.list(path);
31
31
  const id = (0, ids_js_1.idFor)(path);
32
32
  const name = path.split('/').filter(Boolean).pop() ?? '';
@@ -37,8 +37,8 @@ const folderBody = async (drive, path) => {
37
37
  description: '',
38
38
  type: 'folder',
39
39
  version: 1,
40
- createdBy: ids_js_1.EMULATED_USER.id,
41
- modifiedBy: ids_js_1.EMULATED_USER.id,
40
+ createdBy: caller,
41
+ modifiedBy: caller,
42
42
  creationTimeStamp: ids_js_1.EMULATED_NOW,
43
43
  modifiedTimeStamp: ids_js_1.EMULATED_NOW,
44
44
  memberCount: listing.files.length + listing.folders.length,
@@ -46,7 +46,7 @@ const folderBody = async (drive, path) => {
46
46
  links: linksFor(`/folders/folders/${id}`)
47
47
  };
48
48
  };
49
- const recycleBin = () => {
49
+ const recycleBin = (caller) => {
50
50
  const path = '@myRecycleBin';
51
51
  const id = (0, ids_js_1.idFor)(path);
52
52
  return {
@@ -55,8 +55,8 @@ const recycleBin = () => {
55
55
  description: 'Recycle Bin',
56
56
  type: 'trashFolder',
57
57
  version: 1,
58
- createdBy: ids_js_1.EMULATED_USER.id,
59
- modifiedBy: ids_js_1.EMULATED_USER.id,
58
+ createdBy: caller,
59
+ modifiedBy: caller,
60
60
  creationTimeStamp: ids_js_1.EMULATED_NOW,
61
61
  modifiedTimeStamp: ids_js_1.EMULATED_NOW,
62
62
  memberCount: 0,
@@ -103,9 +103,9 @@ const pathForId = async (drive, id) => {
103
103
  /** The handlers, keyed by the operation id the table states. */
104
104
  exports.VIYA_HANDLERS = {
105
105
  'GET /identities/users/@currentUser': async ({ services, request }) => {
106
- const subject = request.subject ??
107
- (await services.identity?.authenticate(request.token));
108
- const id = subject?.userId ?? ids_js_1.EMULATED_USER.id;
106
+ // the host's resolved caller wins; a token is the second way to name one
107
+ const subject = request.subject ?? (await services.identity?.authenticate(request.token));
108
+ const id = (0, ids_js_1.callerId)(subject);
109
109
  return {
110
110
  status: 200,
111
111
  body: {
@@ -144,20 +144,20 @@ exports.VIYA_HANDLERS = {
144
144
  }),
145
145
  'GET /folders/folders/@item': async ({ services, request }) => ({
146
146
  status: 200,
147
- body: await folderBody((0, ports_js_1.requireDrive)(services), pathFromQuery(request))
147
+ body: await folderBody((0, ports_js_1.requireDrive)(services), pathFromQuery(request), (0, ids_js_1.callerId)(request.subject))
148
148
  }),
149
- 'GET /folders/folders/@myRecycleBin': async () => ({
149
+ 'GET /folders/folders/@myRecycleBin': async ({ request }) => ({
150
150
  status: 200,
151
- body: recycleBin()
151
+ body: recycleBin((0, ids_js_1.callerId)(request.subject))
152
152
  }),
153
- 'GET /folders/folders/{}': async ({ services, params }) => {
153
+ 'GET /folders/folders/{}': async ({ services, params, request }) => {
154
154
  // the bin is addressed by id too, and it is not in the drive's tree
155
155
  if (params.id === (0, ids_js_1.idFor)('@myRecycleBin'))
156
- return { status: 200, body: recycleBin() };
156
+ return { status: 200, body: recycleBin((0, ids_js_1.callerId)(request.subject)) };
157
157
  const drive = (0, ports_js_1.requireDrive)(services);
158
158
  return {
159
159
  status: 200,
160
- body: await folderBody(drive, await pathForId(drive, params.id))
160
+ body: await folderBody(drive, await pathForId(drive, params.id), (0, ids_js_1.callerId)(request.subject))
161
161
  };
162
162
  },
163
163
  'GET /folders/folders/{}/members': async ({ services, params, request }) => {
@@ -183,6 +183,7 @@ exports.VIYA_HANDLERS = {
183
183
  };
184
184
  const path = await pathForId(drive, params.id);
185
185
  const listing = await drive.list(path);
186
+ const caller = (0, ids_js_1.callerId)(request.subject);
186
187
  /**
187
188
  * A member's `uri` is the resource, not its path.
188
189
  *
@@ -198,8 +199,8 @@ exports.VIYA_HANDLERS = {
198
199
  name,
199
200
  type: 'folder',
200
201
  version: 1,
201
- createdBy: ids_js_1.EMULATED_USER.id,
202
- modifiedBy: ids_js_1.EMULATED_USER.id,
202
+ createdBy: caller,
203
+ modifiedBy: caller,
203
204
  creationTimeStamp: ids_js_1.EMULATED_NOW,
204
205
  modifiedTimeStamp: ids_js_1.EMULATED_NOW,
205
206
  parentFolderUri: `/folders/folders/${(0, ids_js_1.idFor)(path)}`,
@@ -212,8 +213,8 @@ exports.VIYA_HANDLERS = {
212
213
  type: 'file',
213
214
  version: 1,
214
215
  contentType: 'text/plain',
215
- createdBy: ids_js_1.EMULATED_USER.id,
216
- modifiedBy: ids_js_1.EMULATED_USER.id,
216
+ createdBy: caller,
217
+ modifiedBy: caller,
217
218
  creationTimeStamp: ids_js_1.EMULATED_NOW,
218
219
  modifiedTimeStamp: ids_js_1.EMULATED_NOW,
219
220
  parentFolderUri: `/folders/folders/${(0, ids_js_1.idFor)(path)}`,
@@ -252,7 +253,10 @@ exports.VIYA_HANDLERS = {
252
253
  : '/';
253
254
  const path = (0, ids_js_1.normalisePath)(`${parent}/${body.name}`);
254
255
  await drive.mkdir(path);
255
- return { status: 201, body: await folderBody(drive, path) };
256
+ return {
257
+ status: 201,
258
+ body: await folderBody(drive, path, (0, ids_js_1.callerId)(request.subject))
259
+ };
256
260
  },
257
261
  'PATCH /folders/folders/{}': async ({ services, request, params }) => {
258
262
  const drive = (0, ports_js_1.requireDrive)(services);
@@ -264,7 +268,7 @@ exports.VIYA_HANDLERS = {
264
268
  // shape the capture recorded for this verb. Both spellings arrive: the bin's
265
269
  // id, and the alias the emulator itself answers with
266
270
  if (isRecycleBin(body.parentFolderUri)) {
267
- const removed = await folderBody(drive, path);
271
+ const removed = await folderBody(drive, path, (0, ids_js_1.callerId)(request.subject));
268
272
  await drive.rmdir(path);
269
273
  // the answer describes the folder that was moved, not the drive root -
270
274
  // a client reads the id and parent from it
@@ -285,7 +289,10 @@ exports.VIYA_HANDLERS = {
285
289
  const target = (0, ids_js_1.normalisePath)(`${parent}/${name}`);
286
290
  if (target !== path)
287
291
  await drive.rename(path, target);
288
- return { status: 200, body: await folderBody(drive, target) };
292
+ return {
293
+ status: 200,
294
+ body: await folderBody(drive, target, (0, ids_js_1.callerId)(request.subject))
295
+ };
289
296
  },
290
297
  ...compute_js_1.COMPUTE_HANDLERS,
291
298
  ...files_js_1.FILE_HANDLERS
@@ -13,6 +13,7 @@
13
13
  * name, so a session can be created for the id the list returned.
14
14
  */
15
15
  import type { ApiResponse, Services } from '../host/dispatch.js';
16
+ import type { Subject } from '../identity/types.js';
16
17
  /**
17
18
  * The name the emulator answers when a client asks for no particular context.
18
19
  *
@@ -41,7 +42,7 @@ export declare const COMPUTE_HANDLERS: Record<string, (context: {
41
42
  query?: Record<string, string | undefined>;
42
43
  body?: unknown;
43
44
  token?: string;
44
- subject?: unknown;
45
+ subject?: Subject;
45
46
  };
46
47
  params: Record<string, string>;
47
48
  }) => Promise<ApiResponse>>;
@@ -1 +1 @@
1
- {"version":3,"file":"compute.d.ts","sourceRoot":"","sources":["../../../src/viya/compute.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAOhE;;;;;;;;;GASG;AACH,eAAO,MAAM,oBAAoB,sCAAsC,CAAA;AAEvE,2EAA2E;AAC3E,eAAO,MAAM,mBAAmB,QAAuC,CAAA;AA+CvE;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,GAAI,QAAQ,MAAM,GAAG,SAAS,KAAG,MAM5D,CAAA;AA+GD,eAAO,MAAM,gBAAgB,EAAE,MAAM,CACnC,MAAM,EACN,CAAC,OAAO,EAAE;IACR,QAAQ,EAAE,QAAQ,CAAA;IAClB,OAAO,EAAE;QACP,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA;QAC1C,IAAI,CAAC,EAAE,OAAO,CAAA;QACd,KAAK,CAAC,EAAE,MAAM,CAAA;QACd,OAAO,CAAC,EAAE,OAAO,CAAA;KAClB,CAAA;IACD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAC/B,KAAK,OAAO,CAAC,WAAW,CAAC,CAmM3B,CAAA"}
1
+ {"version":3,"file":"compute.d.ts","sourceRoot":"","sources":["../../../src/viya/compute.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAChE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAOnD;;;;;;;;;GASG;AACH,eAAO,MAAM,oBAAoB,sCAAsC,CAAA;AAEvE,2EAA2E;AAC3E,eAAO,MAAM,mBAAmB,QAAuC,CAAA;AA+CvE;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,GAAI,QAAQ,MAAM,GAAG,SAAS,KAAG,MAM5D,CAAA;AAgHD,eAAO,MAAM,gBAAgB,EAAE,MAAM,CACnC,MAAM,EACN,CAAC,OAAO,EAAE;IACR,QAAQ,EAAE,QAAQ,CAAA;IAClB,OAAO,EAAE;QACP,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA;QAC1C,IAAI,CAAC,EAAE,OAAO,CAAA;QACd,KAAK,CAAC,EAAE,MAAM,CAAA;QACd,OAAO,CAAC,EAAE,OAAO,CAAA;KAClB,CAAA;IACD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAC/B,KAAK,OAAO,CAAC,WAAW,CAAC,CAyM3B,CAAA"}
@@ -2,7 +2,7 @@ import { ApiError } from '../types.js';
2
2
  import { normaliseServerUrl } from './seed.js';
3
3
  import { seedOf } from './seed.js';
4
4
  import { estateFor } from './sessions.js';
5
- import { EMULATED_USER, idFor } from './ids.js';
5
+ import { idFor, callerId } from './ids.js';
6
6
  /**
7
7
  * The name the emulator answers when a client asks for no particular context.
8
8
  *
@@ -66,20 +66,20 @@ export const contextNameFrom = (filter) => {
66
66
  const match = /name\s*,\s*'([^']*)'|name\s*,\s*"([^"]*)"/i.exec(filter);
67
67
  return match?.[1] ?? match?.[2] ?? DEFAULT_CONTEXT_NAME;
68
68
  };
69
- const contextBody = (name) => ({
69
+ const contextBody = (name, caller) => ({
70
70
  id: EMULATED_CONTEXT_ID,
71
71
  name,
72
- createdBy: EMULATED_USER.id,
72
+ createdBy: caller,
73
73
  version: 2,
74
74
  links: linksFor(`/compute/contexts/${EMULATED_CONTEXT_ID}`, 'application/vnd.sas.compute.context')
75
75
  });
76
- const sessionBody = (services, session, autoExecLines) => {
76
+ const sessionBody = (services, session, autoExecLines, caller) => {
77
77
  const { id } = session;
78
78
  const uri = `/compute/sessions/${id}`;
79
79
  return {
80
80
  id,
81
81
  applicationName: 'emulated',
82
- owner: EMULATED_USER.id,
82
+ owner: caller,
83
83
  serverId: idFor(normaliseServerUrl(services.viya?.serverUrl) || 'emulated', 'server'),
84
84
  state: 'idle',
85
85
  attributes: {
@@ -165,7 +165,9 @@ export const COMPUTE_HANDLERS = {
165
165
  limit,
166
166
  count: 1,
167
167
  version: 2,
168
- items: [contextBody(contextNameFrom(request.query?.filter))],
168
+ items: [
169
+ contextBody(contextNameFrom(request.query?.filter), callerId(request.subject))
170
+ ],
169
171
  links: linksFor('/compute/contexts', 'application/vnd.sas.compute.context', true)
170
172
  }
171
173
  };
@@ -177,7 +179,7 @@ export const COMPUTE_HANDLERS = {
177
179
  const session = estateOf(services).create();
178
180
  return {
179
181
  status: 201,
180
- body: sessionBody(services, session, body.environment?.autoExecLines ?? [])
182
+ body: sessionBody(services, session, body.environment?.autoExecLines ?? [], callerId(request.subject))
181
183
  };
182
184
  },
183
185
  'GET /compute/sessions/{}/state': async ({ services, params }) => {
@@ -8,8 +8,13 @@
8
8
  *
9
9
  * A file id is derived from its path, like a folder id: a client stores the id an
10
10
  * upload answered and asks for it later, so the id cannot move between runs.
11
+ *
12
+ * `createdBy`, `modifiedBy` and `properties.typeRegistrant` name the asking
13
+ * caller, not the account that uploaded the bytes - the drive stores contents,
14
+ * not authorship. See `service.ts` for why that is the honest answer here.
11
15
  */
12
16
  import type { ApiResponse, Services } from '../host/dispatch.js';
17
+ import type { Subject } from '../identity/types.js';
13
18
  /** What an upload answers about itself, whichever operation asked. */
14
19
  export interface EmulatedFile {
15
20
  name: string;
@@ -27,7 +32,7 @@ export declare const FILE_HANDLERS: Record<string, (context: {
27
32
  contents: string | Uint8Array;
28
33
  };
29
34
  token?: string;
30
- subject?: unknown;
35
+ subject?: Subject;
31
36
  };
32
37
  params: Record<string, string>;
33
38
  }) => Promise<ApiResponse>>;
@@ -1 +1 @@
1
- {"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../../src/viya/files.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAOhE,sEAAsE;AACtE,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;CACb;AA4KD,eAAO,MAAM,aAAa,EAAE,MAAM,CAChC,MAAM,EACN,CAAC,OAAO,EAAE;IACR,QAAQ,EAAE,QAAQ,CAAA;IAClB,OAAO,EAAE;QACP,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA;QAC1C,IAAI,CAAC,EAAE,OAAO,CAAA;QACd,QAAQ,CAAC,EAAE,MAAM,GAAG,UAAU,CAAA;QAC9B,IAAI,CAAC,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,QAAQ,EAAE,MAAM,GAAG,UAAU,CAAA;SAAE,CAAA;QACtD,KAAK,CAAC,EAAE,MAAM,CAAA;QACd,OAAO,CAAC,EAAE,OAAO,CAAA;KAClB,CAAA;IACD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAC/B,KAAK,OAAO,CAAC,WAAW,CAAC,CAiF3B,CAAA"}
1
+ {"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../../src/viya/files.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAChE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAOnD,sEAAsE;AACtE,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;CACb;AA4KD,eAAO,MAAM,aAAa,EAAE,MAAM,CAChC,MAAM,EACN,CAAC,OAAO,EAAE;IACR,QAAQ,EAAE,QAAQ,CAAA;IAClB,OAAO,EAAE;QACP,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA;QAC1C,IAAI,CAAC,EAAE,OAAO,CAAA;QACd,QAAQ,CAAC,EAAE,MAAM,GAAG,UAAU,CAAA;QAC9B,IAAI,CAAC,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,QAAQ,EAAE,MAAM,GAAG,UAAU,CAAA;SAAE,CAAA;QACtD,KAAK,CAAC,EAAE,MAAM,CAAA;QACd,OAAO,CAAC,EAAE,OAAO,CAAA;KAClB,CAAA;IACD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAC/B,KAAK,OAAO,CAAC,WAAW,CAAC,CA6F3B,CAAA"}
@@ -1,6 +1,6 @@
1
1
  import { ApiError } from '../types.js';
2
2
  import { requireDrive } from './ports.js';
3
- import { EMULATED_NOW, EMULATED_USER, idFor } from './ids.js';
3
+ import { EMULATED_NOW, idFor, callerId } from './ids.js';
4
4
  const contentTypeOf = (name) => {
5
5
  if (/\.sas$/i.test(name))
6
6
  return 'text/plain';
@@ -23,7 +23,7 @@ const contentTypeOf = (name) => {
23
23
  * client reads rather than placeholders: the three `content.*` flags say what can
24
24
  * be done with the file, and `typeRegistrant` says who registered the type.
25
25
  */
26
- const fileBody = (file) => {
26
+ const fileBody = (file, caller) => {
27
27
  const id = idFor(file.path, 'file');
28
28
  const uri = `/files/files/${id}`;
29
29
  const contentType = contentTypeOf(file.name);
@@ -38,8 +38,8 @@ const fileBody = (file) => {
38
38
  fileVersion: 1,
39
39
  version: 2,
40
40
  typeDefName: 'file',
41
- createdBy: EMULATED_USER.id,
42
- modifiedBy: EMULATED_USER.id,
41
+ createdBy: caller,
42
+ modifiedBy: caller,
43
43
  creationTimeStamp: EMULATED_NOW,
44
44
  modifiedTimeStamp: EMULATED_NOW,
45
45
  quarantine: false,
@@ -51,7 +51,7 @@ const fileBody = (file) => {
51
51
  'content.openInBrowser': 'true',
52
52
  'content.preview': 'false',
53
53
  sasIconKey: 'file',
54
- typeRegistrant: EMULATED_USER.id
54
+ typeRegistrant: caller
55
55
  },
56
56
  links: [
57
57
  {
@@ -147,12 +147,18 @@ export const FILE_HANDLERS = {
147
147
  const parent = await parentOf(drive, request.query?.parentFolderUri);
148
148
  const path = `${parent}/${upload.name}`.replace(/\/{2,}/g, '/');
149
149
  await drive.save(path, upload.contents);
150
- return { status: 201, body: fileBody(await bodyOf(drive, path)) };
150
+ return {
151
+ status: 201,
152
+ body: fileBody(await bodyOf(drive, path), callerId(request.subject))
153
+ };
151
154
  },
152
- 'GET /files/files/{}': async ({ services, params }) => {
155
+ 'GET /files/files/{}': async ({ services, params, request }) => {
153
156
  const drive = requireDrive(services);
154
157
  const path = await pathForFileId(drive, params.id);
155
- return { status: 200, body: fileBody(await bodyOf(drive, path)) };
158
+ return {
159
+ status: 200,
160
+ body: fileBody(await bodyOf(drive, path), callerId(request.subject))
161
+ };
156
162
  },
157
163
  'PATCH /files/files/{}': async ({ services, params, request }) => {
158
164
  const drive = requireDrive(services);
@@ -162,7 +168,10 @@ export const FILE_HANDLERS = {
162
168
  const target = `${path.split('/').slice(0, -1).join('/')}/${name}`.replace(/\/{2,}/g, '/');
163
169
  if (target !== path)
164
170
  await drive.rename(path, target);
165
- return { status: 200, body: fileBody(await bodyOf(drive, target)) };
171
+ return {
172
+ status: 200,
173
+ body: fileBody(await bodyOf(drive, target), callerId(request.subject))
174
+ };
166
175
  },
167
176
  'GET /files/files/{}/content': async ({ services, params }) => {
168
177
  const drive = requireDrive(services);
@@ -195,6 +204,9 @@ export const FILE_HANDLERS = {
195
204
  if (contents === undefined || contents === null)
196
205
  throw new ApiError(400, 'File content is required.');
197
206
  await drive.update(path, contents);
198
- return { status: 200, body: fileBody(await bodyOf(drive, path)) };
207
+ return {
208
+ status: 200,
209
+ body: fileBody(await bodyOf(drive, path), callerId(request.subject))
210
+ };
199
211
  }
200
212
  };
@@ -13,6 +13,18 @@ export declare const EMULATED_USER: {
13
13
  id: string;
14
14
  name: string;
15
15
  };
16
+ import type { Subject } from '../identity/types.js';
17
+ /**
18
+ * The id the emulated estate reports as the caller.
19
+ *
20
+ * A host that resolved the caller before dispatching - the server's signed-in
21
+ * account - passes it as `subject`; a host with no identity (the browser worker)
22
+ * passes none, and the fallback names itself, so the answer says on its face that
23
+ * no account was resolved. Bodies that carry `createdBy`, `modifiedBy` or `owner`
24
+ * use this, so an application that reads its own name back is told the account it
25
+ * signed in with.
26
+ */
27
+ export declare const callerId: (subject?: Subject) => string;
16
28
  /**
17
29
  * A uuid shape from a string, deterministically.
18
30
  *
@@ -1 +1 @@
1
- {"version":3,"file":"ids.d.ts","sourceRoot":"","sources":["../../../src/viya/ids.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,sEAAsE;AACtE,eAAO,MAAM,YAAY,6BAA6B,CAAA;AAEtD,4EAA4E;AAC5E,eAAO,MAAM,aAAa;;;CAAiD,CAAA;AAE3E;;;;;;;GAOG;AACH,eAAO,MAAM,KAAK,GAAI,MAAM,MAAM,EAAE,aAAe,KAAG,MAyBrD,CAAA;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,aAAa,GAAI,MAAM,MAAM,KAAG,MAI5C,CAAA"}
1
+ {"version":3,"file":"ids.d.ts","sourceRoot":"","sources":["../../../src/viya/ids.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,sEAAsE;AACtE,eAAO,MAAM,YAAY,6BAA6B,CAAA;AAEtD,4EAA4E;AAC5E,eAAO,MAAM,aAAa;;;CAAiD,CAAA;AAE3E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAEnD;;;;;;;;;GASG;AACH,eAAO,MAAM,QAAQ,GAAI,UAAU,OAAO,KAAG,MACR,CAAA;AAErC;;;;;;;GAOG;AACH,eAAO,MAAM,KAAK,GAAI,MAAM,MAAM,EAAE,aAAe,KAAG,MAyBrD,CAAA;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,aAAa,GAAI,MAAM,MAAM,KAAG,MAI5C,CAAA"}
@@ -10,6 +10,17 @@
10
10
  export const EMULATED_NOW = '2026-01-01T00:00:00.000Z';
11
11
  /** The caller the emulated estate reports when a host does not name one. */
12
12
  export const EMULATED_USER = { id: 'emulated-user', name: 'Emulated User' };
13
+ /**
14
+ * The id the emulated estate reports as the caller.
15
+ *
16
+ * A host that resolved the caller before dispatching - the server's signed-in
17
+ * account - passes it as `subject`; a host with no identity (the browser worker)
18
+ * passes none, and the fallback names itself, so the answer says on its face that
19
+ * no account was resolved. Bodies that carry `createdBy`, `modifiedBy` or `owner`
20
+ * use this, so an application that reads its own name back is told the account it
21
+ * signed in with.
22
+ */
23
+ export const callerId = (subject) => subject?.userId ?? EMULATED_USER.id;
13
24
  /**
14
25
  * A uuid shape from a string, deterministically.
15
26
  *
@@ -12,8 +12,16 @@
12
12
  * the same id on every host and every run. That is the seed rule applied to the
13
13
  * one thing the emulator cannot invent per request: a client stores a folder id
14
14
  * and asks for it later.
15
+ *
16
+ * Authorship is the ASKING caller, not the object's creator. The drive stores
17
+ * paths and contents, not who wrote them, so `createdBy`, `modifiedBy` and a
18
+ * session's `owner` name whoever made the request - a second caller reading the
19
+ * same folder is told it created it. Persisting the creator would mean the drive
20
+ * carrying an owner, which is a wider change than an emulator should force; the
21
+ * bodies say the one thing they can say honestly, which is who is asking.
15
22
  */
16
23
  import type { ApiResponse, Services } from '../host/dispatch.js';
24
+ import type { Subject } from '../identity/types.js';
17
25
  /** The handlers, keyed by the operation id the table states. */
18
26
  export declare const VIYA_HANDLERS: Record<string, (context: {
19
27
  services: Services;
@@ -21,7 +29,7 @@ export declare const VIYA_HANDLERS: Record<string, (context: {
21
29
  query?: Record<string, string | undefined>;
22
30
  body?: unknown;
23
31
  token?: string;
24
- subject?: unknown;
32
+ subject?: Subject;
25
33
  };
26
34
  params: Record<string, string>;
27
35
  }) => Promise<ApiResponse>>;
@@ -1 +1 @@
1
- {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/viya/service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAmIhE,gEAAgE;AAChE,eAAO,MAAM,aAAa,EAAE,MAAM,CAChC,MAAM,EACN,CAAC,OAAO,EAAE;IACR,QAAQ,EAAE,QAAQ,CAAA;IAClB,OAAO,EAAE;QACP,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA;QAC1C,IAAI,CAAC,EAAE,OAAO,CAAA;QACd,KAAK,CAAC,EAAE,MAAM,CAAA;QACd,OAAO,CAAC,EAAE,OAAO,CAAA;KAClB,CAAA;IACD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAC/B,KAAK,OAAO,CAAC,WAAW,CAAC,CAyO3B,CAAA"}
1
+ {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/viya/service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAChE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AA6InD,gEAAgE;AAChE,eAAO,MAAM,aAAa,EAAE,MAAM,CAChC,MAAM,EACN,CAAC,OAAO,EAAE;IACR,QAAQ,EAAE,QAAQ,CAAA;IAClB,OAAO,EAAE;QACP,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA;QAC1C,IAAI,CAAC,EAAE,OAAO,CAAA;QACd,KAAK,CAAC,EAAE,MAAM,CAAA;QACd,OAAO,CAAC,EAAE,OAAO,CAAA;KAClB,CAAA;IACD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAC/B,KAAK,OAAO,CAAC,WAAW,CAAC,CAwP3B,CAAA"}
@@ -2,7 +2,7 @@ import { ApiError } from '../types.js';
2
2
  import { requireDrive } from './ports.js';
3
3
  import { COMPUTE_HANDLERS } from './compute.js';
4
4
  import { FILE_HANDLERS } from './files.js';
5
- import { idFor, normalisePath, EMULATED_NOW, EMULATED_USER } from './ids.js';
5
+ import { idFor, normalisePath, EMULATED_NOW, EMULATED_USER, callerId } from './ids.js';
6
6
  const linksFor = (uri, collection = false) => {
7
7
  const self = {
8
8
  href: uri,
@@ -23,7 +23,7 @@ const linksFor = (uri, collection = false) => {
23
23
  // itemType its capture recorded
24
24
  return collection ? [members, self] : [self, members];
25
25
  };
26
- const folderBody = async (drive, path) => {
26
+ const folderBody = async (drive, path, caller) => {
27
27
  const listing = await drive.list(path);
28
28
  const id = idFor(path);
29
29
  const name = path.split('/').filter(Boolean).pop() ?? '';
@@ -34,8 +34,8 @@ const folderBody = async (drive, path) => {
34
34
  description: '',
35
35
  type: 'folder',
36
36
  version: 1,
37
- createdBy: EMULATED_USER.id,
38
- modifiedBy: EMULATED_USER.id,
37
+ createdBy: caller,
38
+ modifiedBy: caller,
39
39
  creationTimeStamp: EMULATED_NOW,
40
40
  modifiedTimeStamp: EMULATED_NOW,
41
41
  memberCount: listing.files.length + listing.folders.length,
@@ -43,7 +43,7 @@ const folderBody = async (drive, path) => {
43
43
  links: linksFor(`/folders/folders/${id}`)
44
44
  };
45
45
  };
46
- const recycleBin = () => {
46
+ const recycleBin = (caller) => {
47
47
  const path = '@myRecycleBin';
48
48
  const id = idFor(path);
49
49
  return {
@@ -52,8 +52,8 @@ const recycleBin = () => {
52
52
  description: 'Recycle Bin',
53
53
  type: 'trashFolder',
54
54
  version: 1,
55
- createdBy: EMULATED_USER.id,
56
- modifiedBy: EMULATED_USER.id,
55
+ createdBy: caller,
56
+ modifiedBy: caller,
57
57
  creationTimeStamp: EMULATED_NOW,
58
58
  modifiedTimeStamp: EMULATED_NOW,
59
59
  memberCount: 0,
@@ -100,9 +100,9 @@ const pathForId = async (drive, id) => {
100
100
  /** The handlers, keyed by the operation id the table states. */
101
101
  export const VIYA_HANDLERS = {
102
102
  'GET /identities/users/@currentUser': async ({ services, request }) => {
103
- const subject = request.subject ??
104
- (await services.identity?.authenticate(request.token));
105
- const id = subject?.userId ?? EMULATED_USER.id;
103
+ // the host's resolved caller wins; a token is the second way to name one
104
+ const subject = request.subject ?? (await services.identity?.authenticate(request.token));
105
+ const id = callerId(subject);
106
106
  return {
107
107
  status: 200,
108
108
  body: {
@@ -141,20 +141,20 @@ export const VIYA_HANDLERS = {
141
141
  }),
142
142
  'GET /folders/folders/@item': async ({ services, request }) => ({
143
143
  status: 200,
144
- body: await folderBody(requireDrive(services), pathFromQuery(request))
144
+ body: await folderBody(requireDrive(services), pathFromQuery(request), callerId(request.subject))
145
145
  }),
146
- 'GET /folders/folders/@myRecycleBin': async () => ({
146
+ 'GET /folders/folders/@myRecycleBin': async ({ request }) => ({
147
147
  status: 200,
148
- body: recycleBin()
148
+ body: recycleBin(callerId(request.subject))
149
149
  }),
150
- 'GET /folders/folders/{}': async ({ services, params }) => {
150
+ 'GET /folders/folders/{}': async ({ services, params, request }) => {
151
151
  // the bin is addressed by id too, and it is not in the drive's tree
152
152
  if (params.id === idFor('@myRecycleBin'))
153
- return { status: 200, body: recycleBin() };
153
+ return { status: 200, body: recycleBin(callerId(request.subject)) };
154
154
  const drive = requireDrive(services);
155
155
  return {
156
156
  status: 200,
157
- body: await folderBody(drive, await pathForId(drive, params.id))
157
+ body: await folderBody(drive, await pathForId(drive, params.id), callerId(request.subject))
158
158
  };
159
159
  },
160
160
  'GET /folders/folders/{}/members': async ({ services, params, request }) => {
@@ -180,6 +180,7 @@ export const VIYA_HANDLERS = {
180
180
  };
181
181
  const path = await pathForId(drive, params.id);
182
182
  const listing = await drive.list(path);
183
+ const caller = callerId(request.subject);
183
184
  /**
184
185
  * A member's `uri` is the resource, not its path.
185
186
  *
@@ -195,8 +196,8 @@ export const VIYA_HANDLERS = {
195
196
  name,
196
197
  type: 'folder',
197
198
  version: 1,
198
- createdBy: EMULATED_USER.id,
199
- modifiedBy: EMULATED_USER.id,
199
+ createdBy: caller,
200
+ modifiedBy: caller,
200
201
  creationTimeStamp: EMULATED_NOW,
201
202
  modifiedTimeStamp: EMULATED_NOW,
202
203
  parentFolderUri: `/folders/folders/${idFor(path)}`,
@@ -209,8 +210,8 @@ export const VIYA_HANDLERS = {
209
210
  type: 'file',
210
211
  version: 1,
211
212
  contentType: 'text/plain',
212
- createdBy: EMULATED_USER.id,
213
- modifiedBy: EMULATED_USER.id,
213
+ createdBy: caller,
214
+ modifiedBy: caller,
214
215
  creationTimeStamp: EMULATED_NOW,
215
216
  modifiedTimeStamp: EMULATED_NOW,
216
217
  parentFolderUri: `/folders/folders/${idFor(path)}`,
@@ -249,7 +250,10 @@ export const VIYA_HANDLERS = {
249
250
  : '/';
250
251
  const path = normalisePath(`${parent}/${body.name}`);
251
252
  await drive.mkdir(path);
252
- return { status: 201, body: await folderBody(drive, path) };
253
+ return {
254
+ status: 201,
255
+ body: await folderBody(drive, path, callerId(request.subject))
256
+ };
253
257
  },
254
258
  'PATCH /folders/folders/{}': async ({ services, request, params }) => {
255
259
  const drive = requireDrive(services);
@@ -261,7 +265,7 @@ export const VIYA_HANDLERS = {
261
265
  // shape the capture recorded for this verb. Both spellings arrive: the bin's
262
266
  // id, and the alias the emulator itself answers with
263
267
  if (isRecycleBin(body.parentFolderUri)) {
264
- const removed = await folderBody(drive, path);
268
+ const removed = await folderBody(drive, path, callerId(request.subject));
265
269
  await drive.rmdir(path);
266
270
  // the answer describes the folder that was moved, not the drive root -
267
271
  // a client reads the id and parent from it
@@ -282,7 +286,10 @@ export const VIYA_HANDLERS = {
282
286
  const target = normalisePath(`${parent}/${name}`);
283
287
  if (target !== path)
284
288
  await drive.rename(path, target);
285
- return { status: 200, body: await folderBody(drive, target) };
289
+ return {
290
+ status: 200,
291
+ body: await folderBody(drive, target, callerId(request.subject))
292
+ };
286
293
  },
287
294
  ...COMPUTE_HANDLERS,
288
295
  ...FILE_HANDLERS
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sasjs/api",
3
- "version": "0.46.0",
3
+ "version": "0.47.0",
4
4
  "description": "The SASjs Server API, described once - a generated route table, the services behind it, and the conformance corpus both hosts run",
5
5
  "license": "MIT",
6
6
  "author": "SASjs",