@sasjs/api 0.46.0 → 0.48.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 +70 -38
- package/build/cjs/viya/compute.js +8 -6
- package/build/cjs/viya/files.js +21 -9
- package/build/cjs/viya/ids.js +13 -1
- package/build/cjs/viya/seed.js +9 -13
- package/build/cjs/viya/service.js +29 -22
- package/build/esm/host/dispatch.d.ts +4 -4
- package/build/esm/viya/compute.d.ts +2 -1
- package/build/esm/viya/compute.d.ts.map +1 -1
- package/build/esm/viya/compute.js +9 -7
- package/build/esm/viya/files.d.ts +6 -1
- package/build/esm/viya/files.d.ts.map +1 -1
- package/build/esm/viya/files.js +22 -10
- package/build/esm/viya/ids.d.ts +12 -0
- package/build/esm/viya/ids.d.ts.map +1 -1
- package/build/esm/viya/ids.js +11 -0
- package/build/esm/viya/seed.d.ts +10 -14
- package/build/esm/viya/seed.d.ts.map +1 -1
- package/build/esm/viya/seed.js +9 -13
- package/build/esm/viya/service.d.ts +9 -1
- package/build/esm/viya/service.d.ts.map +1 -1
- package/build/esm/viya/service.js +30 -23
- package/package.json +1 -1
package/build/browser.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* @sasjs/api 0.
|
|
1
|
+
/* @sasjs/api 0.48.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;
|
|
@@ -5536,8 +5536,6 @@ var SASjsApi = (() => {
|
|
|
5536
5536
|
return value >>> 0;
|
|
5537
5537
|
};
|
|
5538
5538
|
var seedOf = (settings = {}) => {
|
|
5539
|
-
if (settings.seed !== void 0 && settings.seed !== "")
|
|
5540
|
-
return hash(`seed:${settings.seed}`);
|
|
5541
5539
|
const address = normaliseServerUrl(settings.serverUrl);
|
|
5542
5540
|
return hash(`url:${address || DEFAULT_SEED}`);
|
|
5543
5541
|
};
|
|
@@ -5630,6 +5628,7 @@ var SASjsApi = (() => {
|
|
|
5630
5628
|
// src/viya/ids.ts
|
|
5631
5629
|
var EMULATED_NOW = "2026-01-01T00:00:00.000Z";
|
|
5632
5630
|
var EMULATED_USER = { id: "emulated-user", name: "Emulated User" };
|
|
5631
|
+
var callerId = (subject) => subject?.userId ?? EMULATED_USER.id;
|
|
5633
5632
|
var idFor = (path, kind = "folder") => {
|
|
5634
5633
|
const hash2 = (input, seed) => {
|
|
5635
5634
|
let value = seed;
|
|
@@ -5688,23 +5687,23 @@ var SASjsApi = (() => {
|
|
|
5688
5687
|
const match = /name\s*,\s*'([^']*)'|name\s*,\s*"([^"]*)"/i.exec(filter);
|
|
5689
5688
|
return match?.[1] ?? match?.[2] ?? DEFAULT_CONTEXT_NAME;
|
|
5690
5689
|
};
|
|
5691
|
-
var contextBody = (name) => ({
|
|
5690
|
+
var contextBody = (name, caller) => ({
|
|
5692
5691
|
id: EMULATED_CONTEXT_ID,
|
|
5693
5692
|
name,
|
|
5694
|
-
createdBy:
|
|
5693
|
+
createdBy: caller,
|
|
5695
5694
|
version: 2,
|
|
5696
5695
|
links: linksFor(
|
|
5697
5696
|
`/compute/contexts/${EMULATED_CONTEXT_ID}`,
|
|
5698
5697
|
"application/vnd.sas.compute.context"
|
|
5699
5698
|
)
|
|
5700
5699
|
});
|
|
5701
|
-
var sessionBody = (services, session, autoExecLines) => {
|
|
5700
|
+
var sessionBody = (services, session, autoExecLines, caller) => {
|
|
5702
5701
|
const { id } = session;
|
|
5703
5702
|
const uri = `/compute/sessions/${id}`;
|
|
5704
5703
|
return {
|
|
5705
5704
|
id,
|
|
5706
5705
|
applicationName: "emulated",
|
|
5707
|
-
owner:
|
|
5706
|
+
owner: caller,
|
|
5708
5707
|
serverId: idFor(
|
|
5709
5708
|
normaliseServerUrl(services.viya?.serverUrl) || "emulated",
|
|
5710
5709
|
"server"
|
|
@@ -5783,7 +5782,12 @@ var SASjsApi = (() => {
|
|
|
5783
5782
|
limit,
|
|
5784
5783
|
count: 1,
|
|
5785
5784
|
version: 2,
|
|
5786
|
-
items: [
|
|
5785
|
+
items: [
|
|
5786
|
+
contextBody(
|
|
5787
|
+
contextNameFrom(request.query?.filter),
|
|
5788
|
+
callerId(request.subject)
|
|
5789
|
+
)
|
|
5790
|
+
],
|
|
5787
5791
|
links: linksFor(
|
|
5788
5792
|
"/compute/contexts",
|
|
5789
5793
|
"application/vnd.sas.compute.context",
|
|
@@ -5806,7 +5810,8 @@ var SASjsApi = (() => {
|
|
|
5806
5810
|
body: sessionBody(
|
|
5807
5811
|
services,
|
|
5808
5812
|
session,
|
|
5809
|
-
body.environment?.autoExecLines ?? []
|
|
5813
|
+
body.environment?.autoExecLines ?? [],
|
|
5814
|
+
callerId(request.subject)
|
|
5810
5815
|
)
|
|
5811
5816
|
};
|
|
5812
5817
|
},
|
|
@@ -5922,7 +5927,7 @@ var SASjsApi = (() => {
|
|
|
5922
5927
|
if (/\.(jpe?g)$/i.test(name)) return "image/jpeg";
|
|
5923
5928
|
return "application/octet-stream";
|
|
5924
5929
|
};
|
|
5925
|
-
var fileBody = (file) => {
|
|
5930
|
+
var fileBody = (file, caller) => {
|
|
5926
5931
|
const id = idFor(file.path, "file");
|
|
5927
5932
|
const uri = `/files/files/${id}`;
|
|
5928
5933
|
const contentType = contentTypeOf(file.name);
|
|
@@ -5937,8 +5942,8 @@ var SASjsApi = (() => {
|
|
|
5937
5942
|
fileVersion: 1,
|
|
5938
5943
|
version: 2,
|
|
5939
5944
|
typeDefName: "file",
|
|
5940
|
-
createdBy:
|
|
5941
|
-
modifiedBy:
|
|
5945
|
+
createdBy: caller,
|
|
5946
|
+
modifiedBy: caller,
|
|
5942
5947
|
creationTimeStamp: EMULATED_NOW,
|
|
5943
5948
|
modifiedTimeStamp: EMULATED_NOW,
|
|
5944
5949
|
quarantine: false,
|
|
@@ -5950,7 +5955,7 @@ var SASjsApi = (() => {
|
|
|
5950
5955
|
"content.openInBrowser": "true",
|
|
5951
5956
|
"content.preview": "false",
|
|
5952
5957
|
sasIconKey: "file",
|
|
5953
|
-
typeRegistrant:
|
|
5958
|
+
typeRegistrant: caller
|
|
5954
5959
|
},
|
|
5955
5960
|
links: [
|
|
5956
5961
|
{
|
|
@@ -6030,12 +6035,18 @@ var SASjsApi = (() => {
|
|
|
6030
6035
|
const parent = await parentOf(drive, request.query?.parentFolderUri);
|
|
6031
6036
|
const path = `${parent}/${upload.name}`.replace(/\/{2,}/g, "/");
|
|
6032
6037
|
await drive.save(path, upload.contents);
|
|
6033
|
-
return {
|
|
6038
|
+
return {
|
|
6039
|
+
status: 201,
|
|
6040
|
+
body: fileBody(await bodyOf(drive, path), callerId(request.subject))
|
|
6041
|
+
};
|
|
6034
6042
|
},
|
|
6035
|
-
"GET /files/files/{}": async ({ services, params }) => {
|
|
6043
|
+
"GET /files/files/{}": async ({ services, params, request }) => {
|
|
6036
6044
|
const drive = requireDrive(services);
|
|
6037
6045
|
const path = await pathForFileId(drive, params.id);
|
|
6038
|
-
return {
|
|
6046
|
+
return {
|
|
6047
|
+
status: 200,
|
|
6048
|
+
body: fileBody(await bodyOf(drive, path), callerId(request.subject))
|
|
6049
|
+
};
|
|
6039
6050
|
},
|
|
6040
6051
|
"PATCH /files/files/{}": async ({ services, params, request }) => {
|
|
6041
6052
|
const drive = requireDrive(services);
|
|
@@ -6047,7 +6058,10 @@ var SASjsApi = (() => {
|
|
|
6047
6058
|
"/"
|
|
6048
6059
|
);
|
|
6049
6060
|
if (target !== path) await drive.rename(path, target);
|
|
6050
|
-
return {
|
|
6061
|
+
return {
|
|
6062
|
+
status: 200,
|
|
6063
|
+
body: fileBody(await bodyOf(drive, target), callerId(request.subject))
|
|
6064
|
+
};
|
|
6051
6065
|
},
|
|
6052
6066
|
"GET /files/files/{}/content": async ({ services, params }) => {
|
|
6053
6067
|
const drive = requireDrive(services);
|
|
@@ -6069,7 +6083,10 @@ var SASjsApi = (() => {
|
|
|
6069
6083
|
if (contents === void 0 || contents === null)
|
|
6070
6084
|
throw new ApiError(400, "File content is required.");
|
|
6071
6085
|
await drive.update(path, contents);
|
|
6072
|
-
return {
|
|
6086
|
+
return {
|
|
6087
|
+
status: 200,
|
|
6088
|
+
body: fileBody(await bodyOf(drive, path), callerId(request.subject))
|
|
6089
|
+
};
|
|
6073
6090
|
}
|
|
6074
6091
|
};
|
|
6075
6092
|
|
|
@@ -6092,7 +6109,7 @@ var SASjsApi = (() => {
|
|
|
6092
6109
|
};
|
|
6093
6110
|
return collection ? [members, self] : [self, members];
|
|
6094
6111
|
};
|
|
6095
|
-
var folderBody = async (drive, path) => {
|
|
6112
|
+
var folderBody = async (drive, path, caller) => {
|
|
6096
6113
|
const listing = await drive.list(path);
|
|
6097
6114
|
const id = idFor(path);
|
|
6098
6115
|
const name = path.split("/").filter(Boolean).pop() ?? "";
|
|
@@ -6103,8 +6120,8 @@ var SASjsApi = (() => {
|
|
|
6103
6120
|
description: "",
|
|
6104
6121
|
type: "folder",
|
|
6105
6122
|
version: 1,
|
|
6106
|
-
createdBy:
|
|
6107
|
-
modifiedBy:
|
|
6123
|
+
createdBy: caller,
|
|
6124
|
+
modifiedBy: caller,
|
|
6108
6125
|
creationTimeStamp: EMULATED_NOW,
|
|
6109
6126
|
modifiedTimeStamp: EMULATED_NOW,
|
|
6110
6127
|
memberCount: listing.files.length + listing.folders.length,
|
|
@@ -6112,7 +6129,7 @@ var SASjsApi = (() => {
|
|
|
6112
6129
|
links: linksFor2(`/folders/folders/${id}`)
|
|
6113
6130
|
};
|
|
6114
6131
|
};
|
|
6115
|
-
var recycleBin = () => {
|
|
6132
|
+
var recycleBin = (caller) => {
|
|
6116
6133
|
const path = "@myRecycleBin";
|
|
6117
6134
|
const id = idFor(path);
|
|
6118
6135
|
return {
|
|
@@ -6121,8 +6138,8 @@ var SASjsApi = (() => {
|
|
|
6121
6138
|
description: "Recycle Bin",
|
|
6122
6139
|
type: "trashFolder",
|
|
6123
6140
|
version: 1,
|
|
6124
|
-
createdBy:
|
|
6125
|
-
modifiedBy:
|
|
6141
|
+
createdBy: caller,
|
|
6142
|
+
modifiedBy: caller,
|
|
6126
6143
|
creationTimeStamp: EMULATED_NOW,
|
|
6127
6144
|
modifiedTimeStamp: EMULATED_NOW,
|
|
6128
6145
|
memberCount: 0,
|
|
@@ -6160,7 +6177,7 @@ var SASjsApi = (() => {
|
|
|
6160
6177
|
var VIYA_HANDLERS = {
|
|
6161
6178
|
"GET /identities/users/@currentUser": async ({ services, request }) => {
|
|
6162
6179
|
const subject = request.subject ?? await services.identity?.authenticate(request.token);
|
|
6163
|
-
const id = subject
|
|
6180
|
+
const id = callerId(subject);
|
|
6164
6181
|
return {
|
|
6165
6182
|
status: 200,
|
|
6166
6183
|
body: {
|
|
@@ -6199,19 +6216,27 @@ var SASjsApi = (() => {
|
|
|
6199
6216
|
}),
|
|
6200
6217
|
"GET /folders/folders/@item": async ({ services, request }) => ({
|
|
6201
6218
|
status: 200,
|
|
6202
|
-
body: await folderBody(
|
|
6219
|
+
body: await folderBody(
|
|
6220
|
+
requireDrive(services),
|
|
6221
|
+
pathFromQuery(request),
|
|
6222
|
+
callerId(request.subject)
|
|
6223
|
+
)
|
|
6203
6224
|
}),
|
|
6204
|
-
"GET /folders/folders/@myRecycleBin": async () => ({
|
|
6225
|
+
"GET /folders/folders/@myRecycleBin": async ({ request }) => ({
|
|
6205
6226
|
status: 200,
|
|
6206
|
-
body: recycleBin()
|
|
6227
|
+
body: recycleBin(callerId(request.subject))
|
|
6207
6228
|
}),
|
|
6208
|
-
"GET /folders/folders/{}": async ({ services, params }) => {
|
|
6229
|
+
"GET /folders/folders/{}": async ({ services, params, request }) => {
|
|
6209
6230
|
if (params.id === idFor("@myRecycleBin"))
|
|
6210
|
-
return { status: 200, body: recycleBin() };
|
|
6231
|
+
return { status: 200, body: recycleBin(callerId(request.subject)) };
|
|
6211
6232
|
const drive = requireDrive(services);
|
|
6212
6233
|
return {
|
|
6213
6234
|
status: 200,
|
|
6214
|
-
body: await folderBody(
|
|
6235
|
+
body: await folderBody(
|
|
6236
|
+
drive,
|
|
6237
|
+
await pathForId(drive, params.id),
|
|
6238
|
+
callerId(request.subject)
|
|
6239
|
+
)
|
|
6215
6240
|
};
|
|
6216
6241
|
},
|
|
6217
6242
|
"GET /folders/folders/{}/members": async ({ services, params, request }) => {
|
|
@@ -6235,14 +6260,15 @@ var SASjsApi = (() => {
|
|
|
6235
6260
|
};
|
|
6236
6261
|
const path = await pathForId(drive, params.id);
|
|
6237
6262
|
const listing = await drive.list(path);
|
|
6263
|
+
const caller = callerId(request.subject);
|
|
6238
6264
|
const items = [
|
|
6239
6265
|
...listing.folders.map((name) => ({
|
|
6240
6266
|
id: idFor(`${path}/${name}`.replace(/\/{2,}/g, "/")),
|
|
6241
6267
|
name,
|
|
6242
6268
|
type: "folder",
|
|
6243
6269
|
version: 1,
|
|
6244
|
-
createdBy:
|
|
6245
|
-
modifiedBy:
|
|
6270
|
+
createdBy: caller,
|
|
6271
|
+
modifiedBy: caller,
|
|
6246
6272
|
creationTimeStamp: EMULATED_NOW,
|
|
6247
6273
|
modifiedTimeStamp: EMULATED_NOW,
|
|
6248
6274
|
parentFolderUri: `/folders/folders/${idFor(path)}`,
|
|
@@ -6257,8 +6283,8 @@ var SASjsApi = (() => {
|
|
|
6257
6283
|
type: "file",
|
|
6258
6284
|
version: 1,
|
|
6259
6285
|
contentType: "text/plain",
|
|
6260
|
-
createdBy:
|
|
6261
|
-
modifiedBy:
|
|
6286
|
+
createdBy: caller,
|
|
6287
|
+
modifiedBy: caller,
|
|
6262
6288
|
creationTimeStamp: EMULATED_NOW,
|
|
6263
6289
|
modifiedTimeStamp: EMULATED_NOW,
|
|
6264
6290
|
parentFolderUri: `/folders/folders/${idFor(path)}`,
|
|
@@ -6292,7 +6318,10 @@ var SASjsApi = (() => {
|
|
|
6292
6318
|
const parent = parentUri ? await pathForId(drive, String(parentUri).split("/").pop()) : "/";
|
|
6293
6319
|
const path = normalisePath(`${parent}/${body.name}`);
|
|
6294
6320
|
await drive.mkdir(path);
|
|
6295
|
-
return {
|
|
6321
|
+
return {
|
|
6322
|
+
status: 201,
|
|
6323
|
+
body: await folderBody(drive, path, callerId(request.subject))
|
|
6324
|
+
};
|
|
6296
6325
|
},
|
|
6297
6326
|
"PATCH /folders/folders/{}": async ({ services, request, params }) => {
|
|
6298
6327
|
const drive = requireDrive(services);
|
|
@@ -6301,7 +6330,7 @@ var SASjsApi = (() => {
|
|
|
6301
6330
|
const path = await pathForId(drive, params.id);
|
|
6302
6331
|
const body = request.body ?? {};
|
|
6303
6332
|
if (isRecycleBin(body.parentFolderUri)) {
|
|
6304
|
-
const removed = await folderBody(drive, path);
|
|
6333
|
+
const removed = await folderBody(drive, path, callerId(request.subject));
|
|
6305
6334
|
await drive.rmdir(path);
|
|
6306
6335
|
return {
|
|
6307
6336
|
status: 200,
|
|
@@ -6315,7 +6344,10 @@ var SASjsApi = (() => {
|
|
|
6315
6344
|
);
|
|
6316
6345
|
const target = normalisePath(`${parent}/${name}`);
|
|
6317
6346
|
if (target !== path) await drive.rename(path, target);
|
|
6318
|
-
return {
|
|
6347
|
+
return {
|
|
6348
|
+
status: 200,
|
|
6349
|
+
body: await folderBody(drive, target, callerId(request.subject))
|
|
6350
|
+
};
|
|
6319
6351
|
},
|
|
6320
6352
|
...COMPUTE_HANDLERS,
|
|
6321
6353
|
...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:
|
|
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:
|
|
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: [
|
|
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 }) => {
|
package/build/cjs/viya/files.js
CHANGED
|
@@ -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:
|
|
45
|
-
modifiedBy:
|
|
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:
|
|
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 {
|
|
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 {
|
|
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 {
|
|
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 {
|
|
210
|
+
return {
|
|
211
|
+
status: 200,
|
|
212
|
+
body: fileBody(await bodyOf(drive, path), (0, ids_js_1.callerId)(request.subject))
|
|
213
|
+
};
|
|
202
214
|
}
|
|
203
215
|
};
|
package/build/cjs/viya/ids.js
CHANGED
|
@@ -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
|
*
|
package/build/cjs/viya/seed.js
CHANGED
|
@@ -9,15 +9,14 @@
|
|
|
9
9
|
* tomorrow.
|
|
10
10
|
*
|
|
11
11
|
* The seed is therefore the identity of the estate, and the identity of an estate
|
|
12
|
-
* is the address clients already use to reach it
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* address), and the port that moves between runs (CI picks an ephemeral one).
|
|
12
|
+
* is the address clients already use to reach it, normalised so that one estate
|
|
13
|
+
* spelled two ways is one string. There is no override: an address that differs is
|
|
14
|
+
* a different estate with different data, by design. Anything that reads this
|
|
15
|
+
* data - a fixture, a screenshot, a test - has to work whatever the address is,
|
|
16
|
+
* because the address is all the identity there is.
|
|
18
17
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
18
|
+
* An emulator with no address has not said which estate it is, so every such
|
|
19
|
+
* estate shares one seed. That is the only honest default.
|
|
21
20
|
*/
|
|
22
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
22
|
exports.drawFrom = exports.drawInt = exports.generator = exports.seedOf = exports.hash = exports.normaliseServerUrl = exports.DEFAULT_SEED = void 0;
|
|
@@ -83,13 +82,10 @@ exports.hash = hash;
|
|
|
83
82
|
/**
|
|
84
83
|
* The number that makes this estate's generated data reproducible.
|
|
85
84
|
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
* the address gets to overrule.
|
|
85
|
+
* The address is the only input: the same estate answers the same way every time,
|
|
86
|
+
* and a different address is a different estate.
|
|
89
87
|
*/
|
|
90
88
|
const seedOf = (settings = {}) => {
|
|
91
|
-
if (settings.seed !== undefined && settings.seed !== '')
|
|
92
|
-
return (0, exports.hash)(`seed:${settings.seed}`);
|
|
93
89
|
const address = (0, exports.normaliseServerUrl)(settings.serverUrl);
|
|
94
90
|
return (0, exports.hash)(`url:${address || exports.DEFAULT_SEED}`);
|
|
95
91
|
};
|
|
@@ -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:
|
|
41
|
-
modifiedBy:
|
|
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:
|
|
59
|
-
modifiedBy:
|
|
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
|
-
|
|
107
|
-
|
|
108
|
-
const 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:
|
|
202
|
-
modifiedBy:
|
|
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:
|
|
216
|
-
modifiedBy:
|
|
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 {
|
|
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 {
|
|
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
|
|
@@ -117,10 +117,10 @@ export interface Services {
|
|
|
117
117
|
/**
|
|
118
118
|
* The emulated Viya estate this host mounts, when it mounts one.
|
|
119
119
|
*
|
|
120
|
-
* Absent, the emulated answers fall back to one shared seed. The
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
120
|
+
* Absent, the emulated answers fall back to one shared seed. The normalised
|
|
121
|
+
* `serverUrl` is the whole identity: one address is one estate, a different
|
|
122
|
+
* address - a moved port, a second hostname - is a different estate with its own
|
|
123
|
+
* data, and there is no setting that makes two addresses one.
|
|
124
124
|
*/
|
|
125
125
|
viya?: ViyaSeedSettings;
|
|
126
126
|
/**
|
|
@@ -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?:
|
|
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;
|
|
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 {
|
|
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:
|
|
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:
|
|
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: [
|
|
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?:
|
|
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
|
|
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"}
|
package/build/esm/viya/files.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ApiError } from '../types.js';
|
|
2
2
|
import { requireDrive } from './ports.js';
|
|
3
|
-
import { EMULATED_NOW,
|
|
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:
|
|
42
|
-
modifiedBy:
|
|
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:
|
|
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 {
|
|
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 {
|
|
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 {
|
|
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 {
|
|
207
|
+
return {
|
|
208
|
+
status: 200,
|
|
209
|
+
body: fileBody(await bodyOf(drive, path), callerId(request.subject))
|
|
210
|
+
};
|
|
199
211
|
}
|
|
200
212
|
};
|
package/build/esm/viya/ids.d.ts
CHANGED
|
@@ -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"}
|
package/build/esm/viya/ids.js
CHANGED
|
@@ -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
|
*
|
package/build/esm/viya/seed.d.ts
CHANGED
|
@@ -8,15 +8,14 @@
|
|
|
8
8
|
* tomorrow.
|
|
9
9
|
*
|
|
10
10
|
* The seed is therefore the identity of the estate, and the identity of an estate
|
|
11
|
-
* is the address clients already use to reach it
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* address), and the port that moves between runs (CI picks an ephemeral one).
|
|
11
|
+
* is the address clients already use to reach it, normalised so that one estate
|
|
12
|
+
* spelled two ways is one string. There is no override: an address that differs is
|
|
13
|
+
* a different estate with different data, by design. Anything that reads this
|
|
14
|
+
* data - a fixture, a screenshot, a test - has to work whatever the address is,
|
|
15
|
+
* because the address is all the identity there is.
|
|
17
16
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
17
|
+
* An emulator with no address has not said which estate it is, so every such
|
|
18
|
+
* estate shares one seed. That is the only honest default.
|
|
20
19
|
*/
|
|
21
20
|
/** The seed every emulated estate falls back to. */
|
|
22
21
|
export declare const DEFAULT_SEED = "emulated";
|
|
@@ -56,10 +55,8 @@ export interface ViyaRun {
|
|
|
56
55
|
state?: 'completed' | 'failed';
|
|
57
56
|
}
|
|
58
57
|
export interface ViyaSeedSettings {
|
|
59
|
-
/** The address this estate answers at. */
|
|
58
|
+
/** The address this estate answers at, which is what seeds it. */
|
|
60
59
|
serverUrl?: string;
|
|
61
|
-
/** Pins the generated data when the address is not the identity. */
|
|
62
|
-
seed?: string | number;
|
|
63
60
|
/** Runs a submitted program, when the host has an engine. */
|
|
64
61
|
execute?: ViyaExecutor['execute'];
|
|
65
62
|
}
|
|
@@ -77,9 +74,8 @@ export declare const hash: (input: string) => number;
|
|
|
77
74
|
/**
|
|
78
75
|
* The number that makes this estate's generated data reproducible.
|
|
79
76
|
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
* the address gets to overrule.
|
|
77
|
+
* The address is the only input: the same estate answers the same way every time,
|
|
78
|
+
* and a different address is a different estate.
|
|
83
79
|
*/
|
|
84
80
|
export declare const seedOf: (settings?: ViyaSeedSettings) => number;
|
|
85
81
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"seed.d.ts","sourceRoot":"","sources":["../../../src/viya/seed.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"seed.d.ts","sourceRoot":"","sources":["../../../src/viya/seed.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,oDAAoD;AACpD,eAAO,MAAM,YAAY,aAAa,CAAA;AAEtC;;;;;;;GAOG;AACH,MAAM,WAAW,YAAY;IAC3B,OAAO,CAAC,OAAO,EAAE;QACf,2DAA2D;QAC3D,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;QAC1B,4DAA4D;QAC5D,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QAClC,kEAAkE;QAClE,IAAI,CAAC,EAAE,MAAM,CAAA;QACb,sCAAsC;QACtC,SAAS,EAAE,MAAM,CAAA;KAClB,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;CACrB;AAED,8CAA8C;AAC9C,MAAM,WAAW,OAAO;IACtB,6DAA6D;IAC7D,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,gFAAgF;IAChF,GAAG,EAAE,MAAM,CAAA;IACX;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,WAAW,GAAG,QAAQ,CAAA;CAC/B;AAED,MAAM,WAAW,gBAAgB;IAC/B,kEAAkE;IAClE,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,6DAA6D;IAC7D,OAAO,CAAC,EAAE,YAAY,CAAC,SAAS,CAAC,CAAA;CAClC;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,GAAI,KAAK,MAAM,GAAG,SAAS,KAAG,MA+C5D,CAAA;AAED,8DAA8D;AAC9D,eAAO,MAAM,IAAI,GAAI,OAAO,MAAM,KAAG,MASpC,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,MAAM,GAAI,WAAU,gBAAqB,KAAG,MAIxD,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,GAAI,MAAM,MAAM,KAAG,CAAC,MAAM,MAAM,CAarD,CAAA;AAED,4DAA4D;AAC5D,eAAO,MAAM,OAAO,GAAI,MAAM,MAAM,MAAM,EAAE,OAAO,MAAM,KAAG,MAChC,CAAA;AAE5B,oDAAoD;AACpD,eAAO,MAAM,QAAQ,GAAI,CAAC,EAAE,MAAM,MAAM,MAAM,EAAE,QAAQ,CAAC,EAAE,KAAG,CACxB,CAAA"}
|
package/build/esm/viya/seed.js
CHANGED
|
@@ -8,15 +8,14 @@
|
|
|
8
8
|
* tomorrow.
|
|
9
9
|
*
|
|
10
10
|
* The seed is therefore the identity of the estate, and the identity of an estate
|
|
11
|
-
* is the address clients already use to reach it
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* address), and the port that moves between runs (CI picks an ephemeral one).
|
|
11
|
+
* is the address clients already use to reach it, normalised so that one estate
|
|
12
|
+
* spelled two ways is one string. There is no override: an address that differs is
|
|
13
|
+
* a different estate with different data, by design. Anything that reads this
|
|
14
|
+
* data - a fixture, a screenshot, a test - has to work whatever the address is,
|
|
15
|
+
* because the address is all the identity there is.
|
|
17
16
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
17
|
+
* An emulator with no address has not said which estate it is, so every such
|
|
18
|
+
* estate shares one seed. That is the only honest default.
|
|
20
19
|
*/
|
|
21
20
|
/** The seed every emulated estate falls back to. */
|
|
22
21
|
export const DEFAULT_SEED = 'emulated';
|
|
@@ -78,13 +77,10 @@ export const hash = (input) => {
|
|
|
78
77
|
/**
|
|
79
78
|
* The number that makes this estate's generated data reproducible.
|
|
80
79
|
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
* the address gets to overrule.
|
|
80
|
+
* The address is the only input: the same estate answers the same way every time,
|
|
81
|
+
* and a different address is a different estate.
|
|
84
82
|
*/
|
|
85
83
|
export const seedOf = (settings = {}) => {
|
|
86
|
-
if (settings.seed !== undefined && settings.seed !== '')
|
|
87
|
-
return hash(`seed:${settings.seed}`);
|
|
88
84
|
const address = normaliseServerUrl(settings.serverUrl);
|
|
89
85
|
return hash(`url:${address || DEFAULT_SEED}`);
|
|
90
86
|
};
|
|
@@ -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?:
|
|
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
|
|
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:
|
|
38
|
-
modifiedBy:
|
|
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:
|
|
56
|
-
modifiedBy:
|
|
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
|
-
|
|
104
|
-
|
|
105
|
-
const id = subject
|
|
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:
|
|
199
|
-
modifiedBy:
|
|
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:
|
|
213
|
-
modifiedBy:
|
|
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 {
|
|
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 {
|
|
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