@sasjs/api 0.15.0 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/README.md +3 -2
  2. package/build/browser.js +677 -95
  3. package/build/cjs/corpus/runner.js +19 -2
  4. package/build/cjs/corpus/runtime.js +238 -0
  5. package/build/cjs/corpus/session.js +1 -1
  6. package/build/cjs/host/dispatch.js +119 -5
  7. package/build/cjs/index.js +9 -1
  8. package/build/cjs/routes/generated.js +40 -0
  9. package/build/cjs/routes/overlay.js +18 -6
  10. package/build/cjs/runtime/memory-runner.js +59 -0
  11. package/build/cjs/runtime/service.js +303 -0
  12. package/build/cjs/session/memory-host.js +28 -8
  13. package/build/esm/corpus/drive.d.ts +13 -0
  14. package/build/esm/corpus/drive.d.ts.map +1 -1
  15. package/build/esm/corpus/runner.d.ts.map +1 -1
  16. package/build/esm/corpus/runner.js +19 -2
  17. package/build/esm/corpus/runtime.d.ts +17 -0
  18. package/build/esm/corpus/runtime.d.ts.map +1 -0
  19. package/build/esm/corpus/runtime.js +235 -0
  20. package/build/esm/corpus/session.js +1 -1
  21. package/build/esm/host/dispatch.d.ts +15 -0
  22. package/build/esm/host/dispatch.d.ts.map +1 -1
  23. package/build/esm/host/dispatch.js +119 -5
  24. package/build/esm/index.d.ts +5 -0
  25. package/build/esm/index.d.ts.map +1 -1
  26. package/build/esm/index.js +3 -0
  27. package/build/esm/routes/generated.d.ts.map +1 -1
  28. package/build/esm/routes/generated.js +40 -0
  29. package/build/esm/routes/overlay.d.ts.map +1 -1
  30. package/build/esm/routes/overlay.js +18 -6
  31. package/build/esm/runtime/memory-runner.d.ts +38 -0
  32. package/build/esm/runtime/memory-runner.d.ts.map +1 -0
  33. package/build/esm/runtime/memory-runner.js +55 -0
  34. package/build/esm/runtime/service.d.ts +185 -0
  35. package/build/esm/runtime/service.d.ts.map +1 -0
  36. package/build/esm/runtime/service.js +298 -0
  37. package/build/esm/session/memory-host.d.ts +15 -4
  38. package/build/esm/session/memory-host.d.ts.map +1 -1
  39. package/build/esm/session/memory-host.js +28 -8
  40. package/build/esm/session/service.d.ts +25 -3
  41. package/build/esm/session/service.d.ts.map +1 -1
  42. package/package.json +1 -1
package/build/browser.js CHANGED
@@ -1,4 +1,4 @@
1
- /* @sasjs/api 0.15.0 - the SASjs Server API, for a service worker. https://github.com/sasjs/api */
1
+ /* @sasjs/api 0.17.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;
@@ -26,6 +26,7 @@ var SASjsApi = (() => {
26
26
  ALWAYS_VISIBLE_ROUTES: () => ALWAYS_VISIBLE_ROUTES,
27
27
  ApiError: () => ApiError,
28
28
  CODE_CORPUS: () => CODE_CORPUS,
29
+ CODE_DEBUG: () => CODE_DEBUG,
29
30
  DEFAULT_GRANTABLE_ROUTES: () => DEFAULT_GRANTABLE_ROUTES,
30
31
  DEFAULT_IDENTITY: () => DEFAULT_IDENTITY,
31
32
  DEFAULT_SESSIONS: () => DEFAULT_SESSIONS,
@@ -33,6 +34,7 @@ var SASjsApi = (() => {
33
34
  DEPLOY_LIMITS: () => DEPLOY_LIMITS,
34
35
  DEPLOY_PAYLOAD_BYTES: () => DEPLOY_PAYLOAD_BYTES,
35
36
  DEPLOY_SUCCESS: () => DEPLOY_SUCCESS,
37
+ DOCUMENTED_RUN_TIMES: () => DOCUMENTED_RUN_TIMES,
36
38
  DRIVE_CORPUS: () => DRIVE_CORPUS,
37
39
  HANDLED_ROUTES: () => HANDLED_ROUTES,
38
40
  IDENTITY_CORPUS: () => IDENTITY_CORPUS,
@@ -41,10 +43,12 @@ var SASjsApi = (() => {
41
43
  MemoryDriveStore: () => MemoryDriveStore,
42
44
  MemoryIdentityStore: () => MemoryIdentityStore,
43
45
  MemorySessionHost: () => MemorySessionHost,
46
+ MemorySessionRunner: () => MemorySessionRunner,
44
47
  OVERLAY: () => OVERLAY,
45
48
  PROVIDER_MANAGED: () => PROVIDER_MANAGED,
46
49
  RECORD_CORPUS: () => RECORD_CORPUS,
47
50
  ROUTES: () => ROUTES,
51
+ RUNTIME_CORPUS: () => RUNTIME_CORPUS,
48
52
  SESSION_CORPUS: () => SESSION_CORPUS,
49
53
  STATIC_AUTHORIZED_ROUTES: () => STATIC_AUTHORIZED_ROUTES,
50
54
  TAG_CAPABILITIES: () => TAG_CAPABILITIES,
@@ -54,6 +58,7 @@ var SASjsApi = (() => {
54
58
  createDriveService: () => createDriveService,
55
59
  createIdentityService: () => createIdentityService,
56
60
  createRecordService: () => createRecordService,
61
+ createRuntimeService: () => createRuntimeService,
57
62
  createSessionService: () => createSessionService,
58
63
  decodeBase64: () => decodeBase64,
59
64
  deployTree: () => deployTree,
@@ -136,7 +141,7 @@ var SASjsApi = (() => {
136
141
  var base64Length = (value) => Math.floor(base64Body(value).length * 3 / 4);
137
142
  var decodeBase64 = (value) => {
138
143
  const body = base64Body(value);
139
- const bytes2 = new Uint8Array(Math.floor(body.length * 3 / 4));
144
+ const bytes3 = new Uint8Array(Math.floor(body.length * 3 / 4));
140
145
  let buffer = 0;
141
146
  let bits = 0;
142
147
  let at = 0;
@@ -145,29 +150,29 @@ var SASjsApi = (() => {
145
150
  bits += 6;
146
151
  if (bits >= 8) {
147
152
  bits -= 8;
148
- bytes2[at++] = buffer >> bits & 255;
153
+ bytes3[at++] = buffer >> bits & 255;
149
154
  }
150
155
  }
151
- return bytes2.subarray(0, at);
156
+ return bytes3.subarray(0, at);
152
157
  };
153
158
  var utf8Length = (value) => {
154
- let bytes2 = 0;
159
+ let bytes3 = 0;
155
160
  for (let at = 0; at < value.length; at++) {
156
161
  const code = value.charCodeAt(at);
157
- if (code < 128) bytes2 += 1;
158
- else if (code < 2048) bytes2 += 2;
162
+ if (code < 128) bytes3 += 1;
163
+ else if (code < 2048) bytes3 += 2;
159
164
  else if (code >= 55296 && code <= 56319 && at + 1 < value.length) {
160
- bytes2 += 4;
165
+ bytes3 += 4;
161
166
  at++;
162
- } else bytes2 += 3;
167
+ } else bytes3 += 3;
163
168
  }
164
- return bytes2;
169
+ return bytes3;
165
170
  };
166
171
  var memberName = (member) => member.type === "service" ? `${member.name}.sas` : member.name;
167
172
  var memberBytes = (member) => member.type === "file" ? base64Length(member.code) : utf8Length(member.code);
168
173
  var MEGABYTE = 1024 * 1024;
169
- var describeSize = (bytes2) => bytes2 < MEGABYTE ? `${bytes2} bytes` : `${Math.ceil(bytes2 / MEGABYTE * 10) / 10} MB`;
170
- var describeLimit = (bytes2) => bytes2 < MEGABYTE ? `${bytes2} bytes` : `${Math.round(bytes2 / MEGABYTE * 10) / 10} MB`;
174
+ var describeSize = (bytes3) => bytes3 < MEGABYTE ? `${bytes3} bytes` : `${Math.ceil(bytes3 / MEGABYTE * 10) / 10} MB`;
175
+ var describeLimit = (bytes3) => bytes3 < MEGABYTE ? `${bytes3} bytes` : `${Math.round(bytes3 / MEGABYTE * 10) / 10} MB`;
171
176
  var emptyWalk = () => ({
172
177
  entries: 0,
173
178
  totalBytes: 0,
@@ -194,9 +199,9 @@ var SASjsApi = (() => {
194
199
  walk(member.members, memberPath, acc, depth + 1);
195
200
  continue;
196
201
  }
197
- const bytes2 = memberBytes(member);
198
- acc.totalBytes += bytes2;
199
- if (bytes2 > acc.largest.bytes) acc.largest = { path: memberPath, bytes: bytes2 };
202
+ const bytes3 = memberBytes(member);
203
+ acc.totalBytes += bytes3;
204
+ if (bytes3 > acc.largest.bytes) acc.largest = { path: memberPath, bytes: bytes3 };
200
205
  }
201
206
  };
202
207
  var measureDeployTree = (members) => {
@@ -871,6 +876,14 @@ var SASjsApi = (() => {
871
876
  {
872
877
  status: 200,
873
878
  description: "Ok"
879
+ },
880
+ {
881
+ status: 400,
882
+ description: "Invalid request: the payload is invalid, or the program could not be run"
883
+ },
884
+ {
885
+ status: 401,
886
+ description: "Unauthorized"
874
887
  }
875
888
  ]
876
889
  },
@@ -977,6 +990,14 @@ var SASjsApi = (() => {
977
990
  {
978
991
  status: 200,
979
992
  description: "Ok"
993
+ },
994
+ {
995
+ status: 400,
996
+ description: "Invalid request: the payload is invalid, or the program could not be run"
997
+ },
998
+ {
999
+ status: 401,
1000
+ description: "Unauthorized"
980
1001
  }
981
1002
  ]
982
1003
  },
@@ -1983,6 +2004,14 @@ var SASjsApi = (() => {
1983
2004
  {
1984
2005
  status: 200,
1985
2006
  description: "Ok"
2007
+ },
2008
+ {
2009
+ status: 400,
2010
+ description: "Invalid request: the query parameters are invalid, or the program could not be run"
2011
+ },
2012
+ {
2013
+ status: 401,
2014
+ description: "Unauthorized"
1986
2015
  }
1987
2016
  ]
1988
2017
  },
@@ -2011,6 +2040,14 @@ var SASjsApi = (() => {
2011
2040
  {
2012
2041
  status: 200,
2013
2042
  description: "Ok"
2043
+ },
2044
+ {
2045
+ status: 400,
2046
+ description: "Invalid request: the payload is invalid, or the program could not be run"
2047
+ },
2048
+ {
2049
+ status: 401,
2050
+ description: "Unauthorized"
2014
2051
  }
2015
2052
  ]
2016
2053
  },
@@ -2045,6 +2082,14 @@ var SASjsApi = (() => {
2045
2082
  {
2046
2083
  status: 200,
2047
2084
  description: "Ok"
2085
+ },
2086
+ {
2087
+ status: 400,
2088
+ description: "Invalid request: the payload is invalid, or the program could not be run"
2089
+ },
2090
+ {
2091
+ status: 401,
2092
+ description: "Unauthorized"
2048
2093
  }
2049
2094
  ]
2050
2095
  },
@@ -2519,7 +2564,6 @@ var SASjsApi = (() => {
2519
2564
  Web: ["identity"]
2520
2565
  };
2521
2566
  var DIRECTORY = "Synchronising with an external auth provider needs a directory port, which this package does not have: a host decides which directory it holds accounts in, and answers this itself.";
2522
- var RUNTIME = "Starting a program needs a runtime port, which this package does not have: a host decides which languages it holds, and answers this itself until then.";
2523
2567
  var HOST_CONFIG = "The body is the host's own configuration - ports, run times and providers - which a mock states for itself and this package cannot know.";
2524
2568
  var HOST_OWNED = "The host owns this report: it describes the host's own process and files, which a browser build has no equivalent of.";
2525
2569
  var WEB_BUNDLE = "The host serves its own web bundle; there is no API decision here for this package to answer.";
@@ -2583,8 +2627,18 @@ var SASjsApi = (() => {
2583
2627
  "GET /SASjsApi/client": { implemented: true },
2584
2628
  "POST /SASjsApi/client": { implemented: true },
2585
2629
  // Code - the editor's three calls, and the runtime one
2586
- "POST /SASjsApi/code/execute": { implemented: false, reason: RUNTIME },
2587
- "POST /SASjsApi/code/trigger": { implemented: false, reason: RUNTIME },
2630
+ //
2631
+ // The runtime routes are carried over a `SessionRunner` port: the document's
2632
+ // `RunTimeType` is validated here, the id, the record and the refusals are
2633
+ // decided here, and performing the work is the host's. The response body is
2634
+ // the program's own output - the log included when `_debug` asks for it - so
2635
+ // there is no body to annotate.
2636
+ "POST /SASjsApi/code/execute": { implemented: true },
2637
+ "POST /SASjsApi/code/trigger": {
2638
+ implemented: true,
2639
+ // `pid` is the host's, and a run time without a local process omits it
2640
+ responses: { 200: { sessionId: "" } }
2641
+ },
2588
2642
  "POST /SASjsApi/code/lint": {
2589
2643
  implemented: true,
2590
2644
  capabilities: ["identity"]
@@ -2697,9 +2751,12 @@ var SASjsApi = (() => {
2697
2751
  "GET /SASjsApi/session/{sessionId}/output": { implemented: true },
2698
2752
  "GET /SASjsApi/session/{sessionId}/state": { implemented: true },
2699
2753
  // STP - a stored program, on the runtime port
2700
- "GET /SASjsApi/stp/execute": { implemented: false, reason: RUNTIME },
2701
- "POST /SASjsApi/stp/execute": { implemented: false, reason: RUNTIME },
2702
- "POST /SASjsApi/stp/trigger": { implemented: false, reason: RUNTIME },
2754
+ "GET /SASjsApi/stp/execute": { implemented: true },
2755
+ "POST /SASjsApi/stp/execute": { implemented: true },
2756
+ "POST /SASjsApi/stp/trigger": {
2757
+ implemented: true,
2758
+ responses: { 200: { sessionId: "" } }
2759
+ },
2703
2760
  // User - the accounts the identity store already holds for sign-in
2704
2761
  // Reading accounts is open to any authenticated caller, which is what
2705
2762
  // sasjs/server's routes do (`authenticateAccessToken` only): the document once
@@ -2831,6 +2888,13 @@ var SASjsApi = (() => {
2831
2888
 
2832
2889
  // src/host/dispatch.ts
2833
2890
  var SECONDS_IN_A_DAY = 86400;
2891
+ var RUN_ROUTES = [
2892
+ "GET /SASjsApi/stp/execute",
2893
+ "POST /SASjsApi/stp/execute",
2894
+ "POST /SASjsApi/stp/trigger",
2895
+ "POST /SASjsApi/code/execute",
2896
+ "POST /SASjsApi/code/trigger"
2897
+ ];
2834
2898
  var validate = (route, request) => {
2835
2899
  for (const param of route.params) {
2836
2900
  if (!param.required || param.in === "formData" || param.in === "header")
@@ -2855,7 +2919,8 @@ var SASjsApi = (() => {
2855
2919
  if (!route) throw new ApiError(404, `No such operation: ${routeId}`);
2856
2920
  const { drive, identity, records, code } = services;
2857
2921
  const identityScoped = ["User", "Group", "Permission", "Client"].includes(route.tag) || routeId === "PATCH /SASjsApi/auth/updatePassword";
2858
- if (identityScoped && records) {
2922
+ const runtimeScoped = RUN_ROUTES.includes(routeId);
2923
+ if (identityScoped && records || runtimeScoped && services.runtime) {
2859
2924
  const subject = request.subject ?? (identity ? await identity.authenticate(request.token) : void 0);
2860
2925
  if (!subject) {
2861
2926
  if (!identity)
@@ -2878,6 +2943,26 @@ var SASjsApi = (() => {
2878
2943
  );
2879
2944
  return services.session;
2880
2945
  };
2946
+ const runtimeRequired = () => {
2947
+ if (!services.runtime)
2948
+ throw new ApiError(
2949
+ 501,
2950
+ `This host has no runtime service, so it cannot answer ${routeId}.`
2951
+ );
2952
+ return services.runtime;
2953
+ };
2954
+ const uploaded = () => {
2955
+ const files = request.files || (request.file ? [request.file] : []);
2956
+ if (!files.length) return void 0;
2957
+ return files.reduce((byName, file) => {
2958
+ byName[file.name] = file.contents;
2959
+ return byName;
2960
+ }, {});
2961
+ };
2962
+ const artifact = (output) => ({
2963
+ status: 200,
2964
+ contents: output.contents
2965
+ });
2881
2966
  const required = () => {
2882
2967
  if (!records)
2883
2968
  throw new ApiError(
@@ -2992,6 +3077,60 @@ var SASjsApi = (() => {
2992
3077
  };
2993
3078
  case "GET /SASjsApi/drive/filetree":
2994
3079
  return { status: 200, body: await drive.tree(query._folderPath) };
3080
+ // ------------------------------------------------------------- run times
3081
+ //
3082
+ // A stored program is named by a drive path and a code buffer travels in the
3083
+ // body; either way the package decides everything about the request and the
3084
+ // host's runner does the work.
3085
+ case "GET /SASjsApi/stp/execute": {
3086
+ const output = await runtimeRequired().execute(await caller(), {
3087
+ source: "program",
3088
+ program: query._program,
3089
+ vars: { ...query },
3090
+ files: uploaded()
3091
+ });
3092
+ return artifact(output);
3093
+ }
3094
+ case "POST /SASjsApi/stp/execute": {
3095
+ const output = await runtimeRequired().execute(await caller(), {
3096
+ source: "program",
3097
+ program: query._program || body._program,
3098
+ vars: { ...query, ...body },
3099
+ files: uploaded()
3100
+ });
3101
+ return artifact(output);
3102
+ }
3103
+ case "POST /SASjsApi/stp/trigger":
3104
+ return {
3105
+ status: 200,
3106
+ body: await runtimeRequired().trigger(await caller(), {
3107
+ source: "program",
3108
+ program: query._program,
3109
+ vars: { ...query },
3110
+ expiresAfterMins: query.expiresAfterMins
3111
+ })
3112
+ };
3113
+ case "POST /SASjsApi/code/execute": {
3114
+ const output = await runtimeRequired().execute(await caller(), {
3115
+ source: "code",
3116
+ code: body.code,
3117
+ runTime: body.runTime,
3118
+ vars: { ...query, ...body },
3119
+ files: uploaded()
3120
+ });
3121
+ return artifact(output);
3122
+ }
3123
+ case "POST /SASjsApi/code/trigger":
3124
+ return {
3125
+ status: 200,
3126
+ body: await runtimeRequired().trigger(await caller(), {
3127
+ source: "code",
3128
+ code: body.code,
3129
+ runTime: body.runTime,
3130
+ vars: { ...query, ...body },
3131
+ expiresAfterMins: body.expiresAfterMins
3132
+ })
3133
+ };
2995
3134
  // ------------------------------------------------------------- sessions
2996
3135
  case "GET /SASjsApi/session/{sessionId}": {
2997
3136
  return {
@@ -3012,13 +3151,11 @@ var SASjsApi = (() => {
3012
3151
  };
3013
3152
  }
3014
3153
  case "GET /SASjsApi/session/{sessionId}/output": {
3015
- return {
3016
- status: 200,
3017
- contents: await sessionRequired().output(
3018
- await caller(),
3019
- String(params.sessionId ?? "")
3020
- )
3021
- };
3154
+ const artifact2 = await sessionRequired().output(
3155
+ await caller(),
3156
+ String(params.sessionId ?? "")
3157
+ );
3158
+ return { status: 200, contents: artifact2.contents };
3022
3159
  }
3023
3160
  case "GET /SASjsApi/session/{sessionId}/state": {
3024
3161
  return {
@@ -3246,6 +3383,11 @@ var SASjsApi = (() => {
3246
3383
  var HANDLED_ROUTES = [
3247
3384
  "POST /SASjsApi/drive/deploy/upload",
3248
3385
  "DELETE /SASjsApi/drive/deploy",
3386
+ "GET /SASjsApi/stp/execute",
3387
+ "POST /SASjsApi/stp/execute",
3388
+ "POST /SASjsApi/stp/trigger",
3389
+ "POST /SASjsApi/code/execute",
3390
+ "POST /SASjsApi/code/trigger",
3249
3391
  "GET /SASjsApi/session/{sessionId}",
3250
3392
  "GET /SASjsApi/session/{sessionId}/log",
3251
3393
  "GET /SASjsApi/session/{sessionId}/output",
@@ -3954,14 +4096,14 @@ var SASjsApi = (() => {
3954
4096
 
3955
4097
  // src/identity/memory-store.ts
3956
4098
  var keyOf = (subject) => `${subject.userId}|${subject.clientId}`;
3957
- var randomHex = (bytes2) => {
4099
+ var randomHex = (bytes3) => {
3958
4100
  const source = globalThis.crypto;
3959
4101
  if (!source)
3960
4102
  throw new ApiError(
3961
4103
  500,
3962
4104
  "This host has no Web Crypto (`globalThis.crypto`), so it cannot mint an unguessable identity string."
3963
4105
  );
3964
- const buffer = new Uint8Array(bytes2);
4106
+ const buffer = new Uint8Array(bytes3);
3965
4107
  source.getRandomValues(buffer);
3966
4108
  return Array.from(buffer, (byte) => byte.toString(16).padStart(2, "0")).join(
3967
4109
  ""
@@ -5125,7 +5267,7 @@ var SASjsApi = (() => {
5125
5267
  pid: 4242,
5126
5268
  creationTimeStamp: "2026-11-07T09:00:00.000Z",
5127
5269
  deathTimeStamp: "2026-11-07T09:00:04.000Z",
5128
- expiresAfterMins: 60
5270
+ expiresAfterMins: { mins: 60, used: false }
5129
5271
  }
5130
5272
  }
5131
5273
  },
@@ -5298,7 +5440,7 @@ var SASjsApi = (() => {
5298
5440
  pid: 4242,
5299
5441
  creationTimeStamp: "2026-11-07T09:00:00.000Z",
5300
5442
  deathTimeStamp: "2026-11-07T09:00:04.000Z",
5301
- expiresAfterMins: 60
5443
+ expiresAfterMins: { mins: 60, used: false }
5302
5444
  }
5303
5445
  },
5304
5446
  "sess-restricted": {
@@ -5330,28 +5472,458 @@ var SASjsApi = (() => {
5330
5472
  "sess-silent": ""
5331
5473
  };
5332
5474
  var OUTPUTS = {
5333
- "sess-admin": "<html><body>42</body></html>",
5334
- "sess-restricted": "",
5335
- "sess-silent": ""
5475
+ "sess-admin": {
5476
+ contents: "<html><body>42</body></html>",
5477
+ contentType: "text/html"
5478
+ },
5479
+ "sess-restricted": { contents: "" },
5480
+ "sess-silent": { contents: "" }
5336
5481
  };
5337
5482
  var MemorySessionHost = class {
5338
- constructor(sessions = DEFAULT_SESSIONS) {
5483
+ constructor(sessions = {
5484
+ ...DEFAULT_SESSIONS
5485
+ }, states = {
5486
+ ...STATES
5487
+ }, logs = { ...LOGS }, outputs = {
5488
+ ...OUTPUTS
5489
+ }) {
5339
5490
  this.sessions = sessions;
5491
+ this.states = states;
5492
+ this.logs = logs;
5493
+ this.outputs = outputs;
5340
5494
  }
5341
5495
  async session(id) {
5342
5496
  return this.sessions[id];
5343
5497
  }
5344
5498
  async state(id) {
5345
- return STATES[id];
5499
+ return this.states[id];
5346
5500
  }
5347
5501
  async log(id) {
5348
- return LOGS[id];
5502
+ return this.logs[id];
5349
5503
  }
5350
5504
  async output(id) {
5351
- return OUTPUTS[id];
5505
+ return this.outputs[id];
5506
+ }
5507
+ };
5508
+
5509
+ // src/runtime/service.ts
5510
+ var CODE_DEBUG = 131;
5511
+ var DOCUMENTED_RUN_TIMES = ["sas", "js", "py", "r", "sasviya"];
5512
+ var parseDebugValue = (value) => {
5513
+ if (value === void 0 || value === null || value === "") return void 0;
5514
+ if (typeof value === "number")
5515
+ return Number.isFinite(value) ? value : void 0;
5516
+ const text = String(value).trim();
5517
+ if (!text) return void 0;
5518
+ return /^[+-]?\d+$/.test(text) ? Number(text) : CODE_DEBUG;
5519
+ };
5520
+ var pad = (value) => String(value).padStart(2, "0");
5521
+ var timestamp = (now) => [
5522
+ now.getFullYear(),
5523
+ pad(now.getMonth() + 1),
5524
+ pad(now.getDate()),
5525
+ pad(now.getHours()),
5526
+ pad(now.getMinutes()),
5527
+ pad(now.getSeconds())
5528
+ ].join("");
5529
+ var newSessionId = (now) => `${timestamp(now)}-${Math.round(Math.random() * 1e5)}-${now.getTime()}`;
5530
+ var notThere = (programPath) => `The Program at (${programPath}) does not exist.`;
5531
+ var failedRun = (error) => {
5532
+ const message = "Job execution failed.";
5533
+ throw new ApiError(400, message, {
5534
+ status: "failure",
5535
+ message,
5536
+ error: String(error)
5537
+ });
5538
+ };
5539
+ var createRuntimeService = (directory, runner, options = {}) => {
5540
+ const runTimes = options.runTimes || DOCUMENTED_RUN_TIMES;
5541
+ const callerOf = async (caller) => {
5542
+ if (!caller) throw new ApiError(401, "Unauthorized");
5543
+ const reader = await directory.userById(caller.userId);
5544
+ if (!reader || !reader.isActive) throw new ApiError(401, "Unauthorized");
5545
+ return reader;
5546
+ };
5547
+ const programOf2 = (request) => {
5548
+ if (request.source === "code") {
5549
+ if (request.code === void 0)
5550
+ throw new ApiError(400, '"code" is required');
5551
+ if (typeof request.code !== "string")
5552
+ throw new ApiError(400, '"code" must be a string');
5553
+ if (request.code === "")
5554
+ throw new ApiError(400, '"code" is not allowed to be empty');
5555
+ return { code: request.code };
5556
+ }
5557
+ if (request.program === void 0)
5558
+ throw new ApiError(400, '"_program" is required');
5559
+ if (typeof request.program !== "string")
5560
+ throw new ApiError(400, '"_program" must be a string');
5561
+ if (request.program === "")
5562
+ throw new ApiError(400, '"_program" is not allowed to be empty');
5563
+ const resolved = normaliseDrivePath(request.program);
5564
+ if (resolved === null) return failedRun(notThere(request.program));
5565
+ return { path: resolved };
5566
+ };
5567
+ const runTimeForPath = (path, request) => {
5568
+ const file = path.split("/").pop() || "";
5569
+ const dot = file.lastIndexOf(".");
5570
+ const extension = dot > 0 ? file.slice(dot + 1).toLowerCase() : "";
5571
+ if (DOCUMENTED_RUN_TIMES.includes(extension)) return extension;
5572
+ return runTimeOf(request);
5573
+ };
5574
+ const runTimeOf = (request) => {
5575
+ if (request.runTime === void 0) {
5576
+ if (request.source === "code")
5577
+ throw new ApiError(400, '"runTime" is required');
5578
+ return void 0;
5579
+ }
5580
+ if (typeof request.runTime !== "string")
5581
+ throw new ApiError(400, '"runTime" must be a string');
5582
+ if (!runTimes.includes(request.runTime))
5583
+ throw new ApiError(
5584
+ 400,
5585
+ `"runTime" must be one of [${runTimes.join(", ")}]`
5586
+ );
5587
+ return request.runTime;
5588
+ };
5589
+ const expiryOf = (request) => {
5590
+ const value = request.expiresAfterMins;
5591
+ if (value === void 0) return void 0;
5592
+ const minutes = typeof value === "number" ? value : typeof value === "string" && /^\s*[+-]?\d+(\.\d+)?\s*$/.test(value) ? Number(value) : NaN;
5593
+ if (Number.isNaN(minutes))
5594
+ throw new ApiError(400, '"expiresAfterMins" must be a number');
5595
+ if (minutes <= 0)
5596
+ throw new ApiError(400, '"expiresAfterMins" must be greater than 0');
5597
+ return minutes;
5598
+ };
5599
+ const prepare = async (caller, request) => {
5600
+ const reader = await callerOf(caller);
5601
+ const program = programOf2(request);
5602
+ const vars = { ...request.vars || {} };
5603
+ const debug = "code" in program ? CODE_DEBUG : parseDebugValue(vars._debug);
5604
+ if (debug === void 0) delete vars._debug;
5605
+ else vars._debug = debug;
5606
+ return {
5607
+ reader,
5608
+ program,
5609
+ vars,
5610
+ // a code route's run time is the one it named; a stored program's is the
5611
+ // one its extension names, when it names one at all
5612
+ runTime: "code" in program ? runTimeOf(request) : runTimeForPath(program.path, request)
5613
+ };
5614
+ };
5615
+ return {
5616
+ async execute(caller, request) {
5617
+ const prepared = await prepare(caller, request);
5618
+ let outcome;
5619
+ try {
5620
+ outcome = await runner.run({
5621
+ program: prepared.program,
5622
+ vars: prepared.vars,
5623
+ runTime: prepared.runTime,
5624
+ files: request.files
5625
+ });
5626
+ } catch (error) {
5627
+ return failedRun(error);
5628
+ }
5629
+ return outcome.output || { contents: "" };
5630
+ },
5631
+ async trigger(caller, request) {
5632
+ const prepared = await prepare(caller, request);
5633
+ const expiresAfterMins = expiryOf(request);
5634
+ const session = {
5635
+ sessionId: newSessionId(/* @__PURE__ */ new Date()),
5636
+ owner: prepared.reader.uid,
5637
+ ...prepared.runTime === void 0 ? {} : { runTime: prepared.runTime },
5638
+ ...expiresAfterMins === void 0 ? {} : { expiresAfterMins }
5639
+ };
5640
+ let outcome;
5641
+ try {
5642
+ outcome = await runner.run({
5643
+ program: prepared.program,
5644
+ vars: prepared.vars,
5645
+ runTime: prepared.runTime,
5646
+ session,
5647
+ files: request.files
5648
+ });
5649
+ } catch (error) {
5650
+ return failedRun(error);
5651
+ }
5652
+ return outcome.pid === void 0 ? { sessionId: session.sessionId } : { sessionId: session.sessionId, pid: outcome.pid };
5653
+ }
5654
+ };
5655
+ };
5656
+
5657
+ // src/runtime/memory-runner.ts
5658
+ var MemorySessionRunner = class extends MemorySessionHost {
5659
+ constructor(options = {}) {
5660
+ super();
5661
+ this.options = options;
5662
+ }
5663
+ async run(request) {
5664
+ if (this.options.fail) throw new Error("the mock run failed");
5665
+ const key = "code" in request.program ? request.program.code : request.program.path;
5666
+ const output = this.options.outputs?.[key] || { contents: "" };
5667
+ const pid = this.options.pid;
5668
+ if (request.session) {
5669
+ const { sessionId, owner, expiresAfterMins } = request.session;
5670
+ const started = (/* @__PURE__ */ new Date()).toISOString();
5671
+ const summary = {
5672
+ sessionId,
5673
+ // the work is finished by the time this returns: a memory runner has
5674
+ // nothing to wait for, and the session routes report what it did
5675
+ state: "completed",
5676
+ creationTimeStamp: started,
5677
+ deathTimeStamp: started
5678
+ };
5679
+ if (pid !== void 0) summary.pid = pid;
5680
+ if (expiresAfterMins !== void 0)
5681
+ summary.expiresAfterMins = { mins: expiresAfterMins, used: false };
5682
+ this.sessions[sessionId] = { owner, summary };
5683
+ this.states[sessionId] = pid === void 0 ? { state: "completed" } : { state: "completed", pid };
5684
+ this.logs[sessionId] = "";
5685
+ this.outputs[sessionId] = output;
5686
+ }
5687
+ return pid === void 0 ? { output } : { output, pid };
5352
5688
  }
5353
5689
  };
5354
5690
 
5691
+ // src/corpus/runtime.ts
5692
+ var ADMIN2 = { userId: "user-admin", clientId: "web_app" };
5693
+ var PROGRAM = "/Public/apps/demo/run.sas";
5694
+ var CODE = 'data _null_;\n put "hello";\nrun;';
5695
+ var UNAUTHORIZED2 = "Unauthorized";
5696
+ var FAILED = "Job execution failed.";
5697
+ var bytes2 = (...values) => Uint8Array.from(values);
5698
+ var RUNTIME_CORPUS = [
5699
+ // ------------------------------------------------- GET /stp/execute
5700
+ {
5701
+ id: "stp-execute-get-answers-output",
5702
+ route: "GET /SASjsApi/stp/execute",
5703
+ description: "answers the output the program produced",
5704
+ request: { subject: ADMIN2, query: { _program: PROGRAM } },
5705
+ runOutput: { contents: "hello from the program" },
5706
+ expect: { status: 200, contents: "hello from the program" }
5707
+ },
5708
+ {
5709
+ id: "stp-execute-get-answers-bytes",
5710
+ route: "GET /SASjsApi/stp/execute",
5711
+ description: "answers an output that is bytes as bytes",
5712
+ request: { subject: ADMIN2, query: { _program: PROGRAM } },
5713
+ runOutput: { contents: bytes2(1, 2, 3) },
5714
+ expect: { status: 200, contents: bytes2(1, 2, 3) }
5715
+ },
5716
+ {
5717
+ id: "stp-execute-get-missing-program",
5718
+ route: "GET /SASjsApi/stp/execute",
5719
+ description: "refuses a request that names no program",
5720
+ request: { subject: ADMIN2, query: {} },
5721
+ expect: { status: 400, error: '"_program" is required' }
5722
+ },
5723
+ {
5724
+ id: "stp-execute-get-failed-run",
5725
+ route: "GET /SASjsApi/stp/execute",
5726
+ description: "answers 400 when the program could not be run",
5727
+ request: { subject: ADMIN2, query: { _program: PROGRAM } },
5728
+ failingRun: true,
5729
+ expect: { status: 400, error: FAILED }
5730
+ },
5731
+ {
5732
+ id: "stp-execute-get-unauthenticated",
5733
+ route: "GET /SASjsApi/stp/execute",
5734
+ description: "refuses a caller with no token",
5735
+ request: { query: { _program: PROGRAM } },
5736
+ expect: { status: 401, error: UNAUTHORIZED2 }
5737
+ },
5738
+ // ------------------------------------------------ POST /stp/execute
5739
+ {
5740
+ id: "stp-execute-post-body-program",
5741
+ route: "POST /SASjsApi/stp/execute",
5742
+ description: "runs the program the body names",
5743
+ request: { subject: ADMIN2, body: { _program: PROGRAM } },
5744
+ runOutput: { contents: "hello from the body" },
5745
+ expect: { status: 200, contents: "hello from the body" }
5746
+ },
5747
+ {
5748
+ id: "stp-execute-post-query-program",
5749
+ route: "POST /SASjsApi/stp/execute",
5750
+ description: "runs the program the query names, with no body",
5751
+ request: { subject: ADMIN2, query: { _program: PROGRAM }, body: {} },
5752
+ runOutput: { contents: "hello from the query" },
5753
+ expect: { status: 200, contents: "hello from the query" }
5754
+ },
5755
+ {
5756
+ id: "stp-execute-post-no-program",
5757
+ route: "POST /SASjsApi/stp/execute",
5758
+ description: "refuses a request with no program in the query or the body",
5759
+ request: { subject: ADMIN2, body: {} },
5760
+ expect: { status: 400, error: '"_program" is required' }
5761
+ },
5762
+ {
5763
+ id: "stp-execute-post-failed-run",
5764
+ route: "POST /SASjsApi/stp/execute",
5765
+ description: "answers 400 when the program could not be run",
5766
+ request: { subject: ADMIN2, body: { _program: PROGRAM } },
5767
+ failingRun: true,
5768
+ expect: { status: 400, error: FAILED }
5769
+ },
5770
+ {
5771
+ id: "stp-execute-post-unauthenticated",
5772
+ route: "POST /SASjsApi/stp/execute",
5773
+ description: "refuses a caller with no token, before it reads the payload",
5774
+ request: { body: {} },
5775
+ expect: { status: 401, error: UNAUTHORIZED2 }
5776
+ },
5777
+ // ------------------------------------------------ POST /stp/trigger
5778
+ {
5779
+ id: "stp-trigger-answers-session",
5780
+ route: "POST /SASjsApi/stp/trigger",
5781
+ description: "answers the session a caller polls, and no pid from a mock",
5782
+ request: { subject: ADMIN2, query: { _program: PROGRAM } },
5783
+ expect: { status: 200, keys: ["sessionId"] }
5784
+ },
5785
+ {
5786
+ id: "stp-trigger-retention",
5787
+ route: "POST /SASjsApi/stp/trigger",
5788
+ description: "accepts a retention in minutes, as the query carries it",
5789
+ request: {
5790
+ subject: ADMIN2,
5791
+ query: { _program: PROGRAM, expiresAfterMins: "15" }
5792
+ },
5793
+ expect: { status: 200, keys: ["sessionId"] }
5794
+ },
5795
+ {
5796
+ id: "stp-trigger-retention-not-positive",
5797
+ route: "POST /SASjsApi/stp/trigger",
5798
+ description: "refuses a retention that is not a positive number of minutes",
5799
+ request: {
5800
+ subject: ADMIN2,
5801
+ query: { _program: PROGRAM, expiresAfterMins: "0" }
5802
+ },
5803
+ expect: { status: 400, error: '"expiresAfterMins" must be greater than 0' }
5804
+ },
5805
+ {
5806
+ id: "stp-trigger-missing-program",
5807
+ route: "POST /SASjsApi/stp/trigger",
5808
+ description: "refuses a request that names no program",
5809
+ request: { subject: ADMIN2, query: {} },
5810
+ expect: { status: 400, error: '"_program" is required' }
5811
+ },
5812
+ {
5813
+ id: "stp-trigger-failed-run",
5814
+ route: "POST /SASjsApi/stp/trigger",
5815
+ description: "answers 400 when the program could not be started",
5816
+ request: { subject: ADMIN2, query: { _program: PROGRAM } },
5817
+ failingRun: true,
5818
+ expect: { status: 400, error: FAILED }
5819
+ },
5820
+ {
5821
+ id: "stp-trigger-unauthenticated",
5822
+ route: "POST /SASjsApi/stp/trigger",
5823
+ description: "refuses a caller with no token",
5824
+ request: { query: { _program: PROGRAM } },
5825
+ expect: { status: 401, error: UNAUTHORIZED2 }
5826
+ },
5827
+ // ----------------------------------------------- POST /code/execute
5828
+ {
5829
+ id: "code-execute-answers-output",
5830
+ route: "POST /SASjsApi/code/execute",
5831
+ description: "runs the code in the body and answers its output",
5832
+ request: { subject: ADMIN2, body: { code: CODE, runTime: "sas" } },
5833
+ runOutput: { contents: "NOTE: mock run" },
5834
+ expect: { status: 200, contents: "NOTE: mock run" }
5835
+ },
5836
+ {
5837
+ // The refusal's *message* is not pinned here: it names the run times the
5838
+ // host holds, which is deployment data - `r` is a valid request where R is
5839
+ // configured and a 400 where it is not - so a corpus that stated a list
5840
+ // would be asserting one host's install. `spec/runtime.spec.ts` pins the
5841
+ // wording against an explicit list; this states the status every host sends
5842
+ // for a name no host holds.
5843
+ id: "code-execute-unknown-runtime",
5844
+ route: "POST /SASjsApi/code/execute",
5845
+ description: "refuses a run time the document does not name",
5846
+ request: { subject: ADMIN2, body: { code: CODE, runTime: "cobol" } },
5847
+ expect: { status: 400 }
5848
+ },
5849
+ {
5850
+ id: "code-execute-missing-code",
5851
+ route: "POST /SASjsApi/code/execute",
5852
+ description: "refuses a payload with no code",
5853
+ request: { subject: ADMIN2, body: { runTime: "sas" } },
5854
+ expect: { status: 400, error: '"code" is required' }
5855
+ },
5856
+ {
5857
+ id: "code-execute-empty-code",
5858
+ route: "POST /SASjsApi/code/execute",
5859
+ description: "refuses code that is present but empty",
5860
+ request: { subject: ADMIN2, body: { code: "", runTime: "sas" } },
5861
+ expect: { status: 400, error: '"code" is not allowed to be empty' }
5862
+ },
5863
+ {
5864
+ id: "code-execute-non-string-code",
5865
+ route: "POST /SASjsApi/code/execute",
5866
+ description: "refuses code that is not a string rather than running its text",
5867
+ request: { subject: ADMIN2, body: { code: 123, runTime: "sas" } },
5868
+ expect: { status: 400, error: '"code" must be a string' }
5869
+ },
5870
+ {
5871
+ id: "code-execute-failed-run",
5872
+ route: "POST /SASjsApi/code/execute",
5873
+ description: "answers 400 when the code could not be run",
5874
+ request: { subject: ADMIN2, body: { code: CODE, runTime: "sas" } },
5875
+ failingRun: true,
5876
+ expect: { status: 400, error: FAILED }
5877
+ },
5878
+ {
5879
+ id: "code-execute-unauthenticated",
5880
+ route: "POST /SASjsApi/code/execute",
5881
+ description: "refuses a caller with no token, before it reads the payload",
5882
+ request: { body: {} },
5883
+ expect: { status: 401, error: UNAUTHORIZED2 }
5884
+ },
5885
+ // ----------------------------------------------- POST /code/trigger
5886
+ {
5887
+ id: "code-trigger-answers-session",
5888
+ route: "POST /SASjsApi/code/trigger",
5889
+ description: "answers the session a caller polls, and no pid from a mock",
5890
+ request: { subject: ADMIN2, body: { code: CODE, runTime: "sas" } },
5891
+ expect: { status: 200, keys: ["sessionId"] }
5892
+ },
5893
+ {
5894
+ id: "code-trigger-missing-runtime",
5895
+ route: "POST /SASjsApi/code/trigger",
5896
+ description: "refuses a payload with no run time, which the document requires",
5897
+ request: { subject: ADMIN2, body: { code: CODE } },
5898
+ expect: { status: 400, error: '"runTime" is required' }
5899
+ },
5900
+ {
5901
+ id: "code-trigger-retention-not-positive",
5902
+ route: "POST /SASjsApi/code/trigger",
5903
+ description: "refuses a retention that is not a positive number of minutes",
5904
+ request: {
5905
+ subject: ADMIN2,
5906
+ body: { code: CODE, runTime: "sas", expiresAfterMins: 0 }
5907
+ },
5908
+ expect: { status: 400, error: '"expiresAfterMins" must be greater than 0' }
5909
+ },
5910
+ {
5911
+ id: "code-trigger-failed-run",
5912
+ route: "POST /SASjsApi/code/trigger",
5913
+ description: "answers 400 when the code could not be started",
5914
+ request: { subject: ADMIN2, body: { code: CODE, runTime: "sas" } },
5915
+ failingRun: true,
5916
+ expect: { status: 400, error: FAILED }
5917
+ },
5918
+ {
5919
+ id: "code-trigger-unauthenticated",
5920
+ route: "POST /SASjsApi/code/trigger",
5921
+ description: "refuses a caller with no token",
5922
+ request: { body: { code: CODE, runTime: "sas" } },
5923
+ expect: { status: 401, error: UNAUTHORIZED2 }
5924
+ }
5925
+ ];
5926
+
5355
5927
  // src/corpus/records.ts
5356
5928
  var SIGNED_IN_TOKENS = [
5357
5929
  {
@@ -5414,7 +5986,7 @@ var SASjsApi = (() => {
5414
5986
  }
5415
5987
  ]
5416
5988
  };
5417
- var ADMIN2 = "admin-access";
5989
+ var ADMIN3 = "admin-access";
5418
5990
  var RESTRICTED2 = "user-access";
5419
5991
  var RESTRICTED_UID = "user-restricted";
5420
5992
  var ADMIN_UID = "user-admin";
@@ -5425,7 +5997,7 @@ var SASjsApi = (() => {
5425
5997
  route: "GET /SASjsApi/user",
5426
5998
  description: "lists the accounts any signed-in caller may see",
5427
5999
  identity: ADMIN_SIGNED_IN,
5428
- request: { token: ADMIN2 },
6000
+ request: { token: ADMIN3 },
5429
6001
  expect: {
5430
6002
  status: 200,
5431
6003
  body: [
@@ -5474,7 +6046,7 @@ var SASjsApi = (() => {
5474
6046
  route: "GET /SASjsApi/user/{uid}",
5475
6047
  description: "answers 404 for an identifier no account has",
5476
6048
  identity: ADMIN_SIGNED_IN,
5477
- request: { token: ADMIN2, params: { uid: "user-none" } },
6049
+ request: { token: ADMIN3, params: { uid: "user-none" } },
5478
6050
  expect: { status: 404, error: "User is not found." }
5479
6051
  },
5480
6052
  {
@@ -5482,7 +6054,7 @@ var SASjsApi = (() => {
5482
6054
  route: "GET /SASjsApi/user/by/username/{username}",
5483
6055
  description: "finds an account by username",
5484
6056
  identity: ADMIN_SIGNED_IN,
5485
- request: { token: ADMIN2, params: { username: "user2" } },
6057
+ request: { token: ADMIN3, params: { username: "user2" } },
5486
6058
  expect: {
5487
6059
  status: 200,
5488
6060
  partial: { uid: RESTRICTED_UID, username: "user2", isAdmin: false }
@@ -5501,7 +6073,7 @@ var SASjsApi = (() => {
5501
6073
  route: "GET /SASjsApi/user/by/username/{username}",
5502
6074
  description: "answers 404 for a username no account has",
5503
6075
  identity: ADMIN_SIGNED_IN,
5504
- request: { token: ADMIN2, params: { username: "nobody" } },
6076
+ request: { token: ADMIN3, params: { username: "nobody" } },
5505
6077
  expect: { status: 404, error: "User is not found." }
5506
6078
  },
5507
6079
  {
@@ -5510,7 +6082,7 @@ var SASjsApi = (() => {
5510
6082
  description: "creates an account, sanitised, and reports it",
5511
6083
  identity: ADMIN_SIGNED_IN,
5512
6084
  request: {
5513
- token: ADMIN2,
6085
+ token: ADMIN3,
5514
6086
  body: {
5515
6087
  username: "newuser",
5516
6088
  displayName: " New User ",
@@ -5558,7 +6130,7 @@ var SASjsApi = (() => {
5558
6130
  description: "refuses a username that is taken",
5559
6131
  identity: ADMIN_SIGNED_IN,
5560
6132
  request: {
5561
- token: ADMIN2,
6133
+ token: ADMIN3,
5562
6134
  body: { username: "user2", displayName: "Another", password: "newpass" }
5563
6135
  },
5564
6136
  expect: { status: 409, error: "Username already exists." }
@@ -5569,7 +6141,7 @@ var SASjsApi = (() => {
5569
6141
  description: "changes an account's display name",
5570
6142
  identity: ADMIN_SIGNED_IN,
5571
6143
  request: {
5572
- token: ADMIN2,
6144
+ token: ADMIN3,
5573
6145
  params: { uid: RESTRICTED_UID },
5574
6146
  body: {
5575
6147
  displayName: "Renamed User",
@@ -5600,7 +6172,7 @@ var SASjsApi = (() => {
5600
6172
  description: "answers 404 with the identifier it looked up",
5601
6173
  identity: ADMIN_SIGNED_IN,
5602
6174
  request: {
5603
- token: ADMIN2,
6175
+ token: ADMIN3,
5604
6176
  params: { uid: "user-none" },
5605
6177
  body: { displayName: "Nobody", username: "nobody", password: "none123" }
5606
6178
  },
@@ -5612,7 +6184,7 @@ var SASjsApi = (() => {
5612
6184
  description: "refuses a username change on a provider-managed account",
5613
6185
  identity: PROVIDER_MANAGED,
5614
6186
  request: {
5615
- token: ADMIN2,
6187
+ token: ADMIN3,
5616
6188
  params: { uid: "user-directory" },
5617
6189
  body: {
5618
6190
  username: "renamed",
@@ -5631,7 +6203,7 @@ var SASjsApi = (() => {
5631
6203
  description: "refuses a username another account already has",
5632
6204
  identity: ADMIN_SIGNED_IN,
5633
6205
  request: {
5634
- token: ADMIN2,
6206
+ token: ADMIN3,
5635
6207
  params: { uid: RESTRICTED_UID },
5636
6208
  body: { username: "admin", displayName: "Demo User", password: "user123" }
5637
6209
  },
@@ -5643,7 +6215,7 @@ var SASjsApi = (() => {
5643
6215
  description: "changes an account looked up by username",
5644
6216
  identity: ADMIN_SIGNED_IN,
5645
6217
  request: {
5646
- token: ADMIN2,
6218
+ token: ADMIN3,
5647
6219
  params: { username: "user2" },
5648
6220
  body: {
5649
6221
  isActive: false,
@@ -5672,7 +6244,7 @@ var SASjsApi = (() => {
5672
6244
  description: "answers 404 with the username it looked up",
5673
6245
  identity: ADMIN_SIGNED_IN,
5674
6246
  request: {
5675
- token: ADMIN2,
6247
+ token: ADMIN3,
5676
6248
  params: { username: "nobody" },
5677
6249
  body: { displayName: "Nobody", username: "nobody", password: "none123" }
5678
6250
  },
@@ -5684,7 +6256,7 @@ var SASjsApi = (() => {
5684
6256
  description: "refuses a display-name change on a provider-managed account",
5685
6257
  identity: PROVIDER_MANAGED,
5686
6258
  request: {
5687
- token: ADMIN2,
6259
+ token: ADMIN3,
5688
6260
  params: { username: "diruser" },
5689
6261
  body: { displayName: "Renamed", username: "diruser", password: "dir123" }
5690
6262
  },
@@ -5699,7 +6271,7 @@ var SASjsApi = (() => {
5699
6271
  description: "refuses a username another account already has",
5700
6272
  identity: ADMIN_SIGNED_IN,
5701
6273
  request: {
5702
- token: ADMIN2,
6274
+ token: ADMIN3,
5703
6275
  params: { username: "user2" },
5704
6276
  body: { username: "admin", displayName: "Demo User", password: "user123" }
5705
6277
  },
@@ -5710,7 +6282,7 @@ var SASjsApi = (() => {
5710
6282
  route: "DELETE /SASjsApi/user/{uid}",
5711
6283
  description: "deletes an account as an administrator, without a password",
5712
6284
  identity: ADMIN_SIGNED_IN,
5713
- request: { token: ADMIN2, params: { uid: RESTRICTED_UID }, body: {} },
6285
+ request: { token: ADMIN3, params: { uid: RESTRICTED_UID }, body: {} },
5714
6286
  expect: { status: 200, body: "Account Deleted!" }
5715
6287
  },
5716
6288
  {
@@ -5726,7 +6298,7 @@ var SASjsApi = (() => {
5726
6298
  route: "DELETE /SASjsApi/user/{uid}",
5727
6299
  description: "answers 404 for an identifier no account has",
5728
6300
  identity: ADMIN_SIGNED_IN,
5729
- request: { token: ADMIN2, params: { uid: "user-none" }, body: {} },
6301
+ request: { token: ADMIN3, params: { uid: "user-none" }, body: {} },
5730
6302
  expect: { status: 404, error: "User is not found." }
5731
6303
  },
5732
6304
  {
@@ -5735,7 +6307,7 @@ var SASjsApi = (() => {
5735
6307
  description: "deletes an account looked up by username",
5736
6308
  identity: ADMIN_SIGNED_IN,
5737
6309
  request: {
5738
- token: ADMIN2,
6310
+ token: ADMIN3,
5739
6311
  params: { username: "user2" },
5740
6312
  body: {}
5741
6313
  },
@@ -5758,7 +6330,7 @@ var SASjsApi = (() => {
5758
6330
  route: "DELETE /SASjsApi/user/by/username/{username}",
5759
6331
  description: "answers 404 for a username no account has",
5760
6332
  identity: ADMIN_SIGNED_IN,
5761
- request: { token: ADMIN2, params: { username: "nobody" }, body: {} },
6333
+ request: { token: ADMIN3, params: { username: "nobody" }, body: {} },
5762
6334
  expect: { status: 404, error: "User is not found." }
5763
6335
  },
5764
6336
  // ----------------------------------------------------------------- groups
@@ -5812,7 +6384,7 @@ var SASjsApi = (() => {
5812
6384
  route: "GET /SASjsApi/group/{uid}",
5813
6385
  description: "answers 404 for an identifier no group has",
5814
6386
  identity: ADMIN_SIGNED_IN,
5815
- request: { token: ADMIN2, params: { uid: "group-none" } },
6387
+ request: { token: ADMIN3, params: { uid: "group-none" } },
5816
6388
  expect: { status: 404, error: "Group not found." }
5817
6389
  },
5818
6390
  {
@@ -5820,7 +6392,7 @@ var SASjsApi = (() => {
5820
6392
  route: "GET /SASjsApi/group/by/groupname/{name}",
5821
6393
  description: "finds a group by name",
5822
6394
  identity: ADMIN_SIGNED_IN,
5823
- request: { token: ADMIN2, params: { name: "DCGroup" } },
6395
+ request: { token: ADMIN3, params: { name: "DCGroup" } },
5824
6396
  expect: {
5825
6397
  status: 200,
5826
6398
  partial: { uid: "group-data-controller", name: "DCGroup" }
@@ -5831,7 +6403,7 @@ var SASjsApi = (() => {
5831
6403
  route: "GET /SASjsApi/group/by/groupname/{name}",
5832
6404
  description: "answers 404 for a name no group has",
5833
6405
  identity: ADMIN_SIGNED_IN,
5834
- request: { token: ADMIN2, params: { name: "nope" } },
6406
+ request: { token: ADMIN3, params: { name: "nope" } },
5835
6407
  expect: { status: 404, error: "Group not found." }
5836
6408
  },
5837
6409
  {
@@ -5840,7 +6412,7 @@ var SASjsApi = (() => {
5840
6412
  description: "creates a group with no members",
5841
6413
  identity: ADMIN_SIGNED_IN,
5842
6414
  request: {
5843
- token: ADMIN2,
6415
+ token: ADMIN3,
5844
6416
  body: { name: "NewGroup", description: "A new group", isActive: true }
5845
6417
  },
5846
6418
  expect: {
@@ -5869,7 +6441,7 @@ var SASjsApi = (() => {
5869
6441
  route: "POST /SASjsApi/group",
5870
6442
  description: "refuses a name that is taken",
5871
6443
  identity: ADMIN_SIGNED_IN,
5872
- request: { token: ADMIN2, body: { name: "DCGroup", description: "again" } },
6444
+ request: { token: ADMIN3, body: { name: "DCGroup", description: "again" } },
5873
6445
  expect: { status: 409, error: "Group name already exists." }
5874
6446
  },
5875
6447
  {
@@ -5878,7 +6450,7 @@ var SASjsApi = (() => {
5878
6450
  description: "adds a member and returns the group",
5879
6451
  identity: ADMIN_SIGNED_IN,
5880
6452
  request: {
5881
- token: ADMIN2,
6453
+ token: ADMIN3,
5882
6454
  params: { groupUid: "group-admins", userUid: RESTRICTED_UID }
5883
6455
  },
5884
6456
  expect: {
@@ -5892,7 +6464,7 @@ var SASjsApi = (() => {
5892
6464
  description: "refuses a change to the reserved public group",
5893
6465
  identity: PROVIDER_MANAGED,
5894
6466
  request: {
5895
- token: ADMIN2,
6467
+ token: ADMIN3,
5896
6468
  params: { groupUid: "group-public", userUid: RESTRICTED_UID }
5897
6469
  },
5898
6470
  expect: { status: 400, error: "Can't add/remove user to 'public' group." }
@@ -5914,7 +6486,7 @@ var SASjsApi = (() => {
5914
6486
  description: "answers 404 for a group that does not exist",
5915
6487
  identity: ADMIN_SIGNED_IN,
5916
6488
  request: {
5917
- token: ADMIN2,
6489
+ token: ADMIN3,
5918
6490
  params: { groupUid: "group-none", userUid: RESTRICTED_UID }
5919
6491
  },
5920
6492
  expect: { status: 404, error: "Group not found." }
@@ -5925,7 +6497,7 @@ var SASjsApi = (() => {
5925
6497
  description: "refuses a membership change on a provider-managed group",
5926
6498
  identity: PROVIDER_MANAGED,
5927
6499
  request: {
5928
- token: ADMIN2,
6500
+ token: ADMIN3,
5929
6501
  params: { groupUid: "group-directory", userUid: RESTRICTED_UID }
5930
6502
  },
5931
6503
  expect: {
@@ -5939,7 +6511,7 @@ var SASjsApi = (() => {
5939
6511
  description: "removes a member and returns the group",
5940
6512
  identity: ADMIN_SIGNED_IN,
5941
6513
  request: {
5942
- token: ADMIN2,
6514
+ token: ADMIN3,
5943
6515
  params: { groupUid: "group-data-controller", userUid: RESTRICTED_UID }
5944
6516
  },
5945
6517
  expect: {
@@ -5953,7 +6525,7 @@ var SASjsApi = (() => {
5953
6525
  description: "refuses a membership change for a provider-managed user",
5954
6526
  identity: PROVIDER_MANAGED,
5955
6527
  request: {
5956
- token: ADMIN2,
6528
+ token: ADMIN3,
5957
6529
  params: { groupUid: "group-admins", userUid: "user-directory" }
5958
6530
  },
5959
6531
  expect: {
@@ -5967,7 +6539,7 @@ var SASjsApi = (() => {
5967
6539
  description: "refuses a membership change for a provider-managed user",
5968
6540
  identity: PROVIDER_MANAGED,
5969
6541
  request: {
5970
- token: ADMIN2,
6542
+ token: ADMIN3,
5971
6543
  params: { groupUid: "group-admins", userUid: "user-directory" }
5972
6544
  },
5973
6545
  expect: {
@@ -5981,7 +6553,7 @@ var SASjsApi = (() => {
5981
6553
  description: "refuses a change to the reserved public group",
5982
6554
  identity: PROVIDER_MANAGED,
5983
6555
  request: {
5984
- token: ADMIN2,
6556
+ token: ADMIN3,
5985
6557
  params: { groupUid: "group-public", userUid: RESTRICTED_UID }
5986
6558
  },
5987
6559
  expect: { status: 400, error: "Can't add/remove user to 'public' group." }
@@ -6003,7 +6575,7 @@ var SASjsApi = (() => {
6003
6575
  description: "answers 404 for a member that does not exist",
6004
6576
  identity: ADMIN_SIGNED_IN,
6005
6577
  request: {
6006
- token: ADMIN2,
6578
+ token: ADMIN3,
6007
6579
  params: { groupUid: "group-admins", userUid: "user-none" }
6008
6580
  },
6009
6581
  expect: { status: 404, error: "User not found." }
@@ -6014,7 +6586,7 @@ var SASjsApi = (() => {
6014
6586
  description: "refuses a membership change on a provider-managed group",
6015
6587
  identity: PROVIDER_MANAGED,
6016
6588
  request: {
6017
- token: ADMIN2,
6589
+ token: ADMIN3,
6018
6590
  params: { groupUid: "group-directory", userUid: RESTRICTED_UID }
6019
6591
  },
6020
6592
  expect: {
@@ -6027,7 +6599,7 @@ var SASjsApi = (() => {
6027
6599
  route: "DELETE /SASjsApi/group/{uid}",
6028
6600
  description: "deletes a group",
6029
6601
  identity: ADMIN_SIGNED_IN,
6030
- request: { token: ADMIN2, params: { uid: "group-data-controller" } },
6602
+ request: { token: ADMIN3, params: { uid: "group-data-controller" } },
6031
6603
  expect: { status: 200 }
6032
6604
  },
6033
6605
  {
@@ -6043,7 +6615,7 @@ var SASjsApi = (() => {
6043
6615
  route: "DELETE /SASjsApi/group/{uid}",
6044
6616
  description: "answers 404 for an identifier no group has",
6045
6617
  identity: ADMIN_SIGNED_IN,
6046
- request: { token: ADMIN2, params: { uid: "group-none" } },
6618
+ request: { token: ADMIN3, params: { uid: "group-none" } },
6047
6619
  expect: { status: 404, error: "Group not found." }
6048
6620
  },
6049
6621
  // ------------------------------------------------------------ permissions
@@ -6052,7 +6624,7 @@ var SASjsApi = (() => {
6052
6624
  route: "GET /SASjsApi/info/authorizedRoutes",
6053
6625
  description: "answers the route inventory to an administrator",
6054
6626
  identity: ADMIN_SIGNED_IN,
6055
- request: { token: ADMIN2 },
6627
+ request: { token: ADMIN3 },
6056
6628
  expect: {
6057
6629
  status: 200,
6058
6630
  body: {
@@ -6084,7 +6656,7 @@ var SASjsApi = (() => {
6084
6656
  route: "GET /SASjsApi/info/myAuthorizedRoutes",
6085
6657
  description: "answers every route to an administrator",
6086
6658
  identity: ADMIN_SIGNED_IN,
6087
- request: { token: ADMIN2 },
6659
+ request: { token: ADMIN3 },
6088
6660
  expect: {
6089
6661
  status: 200,
6090
6662
  body: {
@@ -6124,7 +6696,7 @@ var SASjsApi = (() => {
6124
6696
  route: "GET /SASjsApi/permission",
6125
6697
  description: "returns every rule to an administrator",
6126
6698
  identity: ADMIN_SIGNED_IN,
6127
- request: { token: ADMIN2 },
6699
+ request: { token: ADMIN3 },
6128
6700
  expect: {
6129
6701
  status: 200,
6130
6702
  body: [
@@ -6199,7 +6771,7 @@ var SASjsApi = (() => {
6199
6771
  description: "creates a rule for a user",
6200
6772
  identity: ADMIN_SIGNED_IN,
6201
6773
  request: {
6202
- token: ADMIN2,
6774
+ token: ADMIN3,
6203
6775
  body: {
6204
6776
  path: "/SASjsApi/drive/folder",
6205
6777
  type: "Route",
@@ -6219,7 +6791,7 @@ var SASjsApi = (() => {
6219
6791
  description: "creates a rule for a group",
6220
6792
  identity: ADMIN_SIGNED_IN,
6221
6793
  request: {
6222
- token: ADMIN2,
6794
+ token: ADMIN3,
6223
6795
  body: {
6224
6796
  path: "/SASjsApi/drive/rename",
6225
6797
  type: "Route",
@@ -6243,7 +6815,7 @@ var SASjsApi = (() => {
6243
6815
  description: "refuses a principal type that is neither a user nor a group",
6244
6816
  identity: ADMIN_SIGNED_IN,
6245
6817
  request: {
6246
- token: ADMIN2,
6818
+ token: ADMIN3,
6247
6819
  body: {
6248
6820
  path: "/SASjsApi/drive/deploy",
6249
6821
  type: "Route",
@@ -6263,7 +6835,7 @@ var SASjsApi = (() => {
6263
6835
  description: "refuses a rule assigned to an administrator",
6264
6836
  identity: ADMIN_SIGNED_IN,
6265
6837
  request: {
6266
- token: ADMIN2,
6838
+ token: ADMIN3,
6267
6839
  body: {
6268
6840
  path: "/SASjsApi/drive/folder",
6269
6841
  type: "Route",
@@ -6300,7 +6872,7 @@ var SASjsApi = (() => {
6300
6872
  description: "answers 404 for a principal that does not exist",
6301
6873
  identity: ADMIN_SIGNED_IN,
6302
6874
  request: {
6303
- token: ADMIN2,
6875
+ token: ADMIN3,
6304
6876
  body: {
6305
6877
  path: "/SASjsApi/drive/rename",
6306
6878
  type: "Route",
@@ -6317,7 +6889,7 @@ var SASjsApi = (() => {
6317
6889
  description: "refuses a group rule that already exists",
6318
6890
  identity: ADMIN_SIGNED_IN,
6319
6891
  request: {
6320
- token: ADMIN2,
6892
+ token: ADMIN3,
6321
6893
  body: {
6322
6894
  path: "/SASjsApi/drive/file",
6323
6895
  type: "Route",
@@ -6337,7 +6909,7 @@ var SASjsApi = (() => {
6337
6909
  description: "refuses a rule that already exists",
6338
6910
  identity: ADMIN_SIGNED_IN,
6339
6911
  request: {
6340
- token: ADMIN2,
6912
+ token: ADMIN3,
6341
6913
  body: {
6342
6914
  path: "/SASjsApi/code/execute",
6343
6915
  type: "Route",
@@ -6357,7 +6929,7 @@ var SASjsApi = (() => {
6357
6929
  description: "flips a rule from Deny to Grant",
6358
6930
  identity: ADMIN_SIGNED_IN,
6359
6931
  request: {
6360
- token: ADMIN2,
6932
+ token: ADMIN3,
6361
6933
  params: { uid: "rule-code" },
6362
6934
  body: { setting: "Grant" }
6363
6935
  },
@@ -6381,7 +6953,7 @@ var SASjsApi = (() => {
6381
6953
  description: "answers 404 for a rule that does not exist",
6382
6954
  identity: ADMIN_SIGNED_IN,
6383
6955
  request: {
6384
- token: ADMIN2,
6956
+ token: ADMIN3,
6385
6957
  params: { uid: "rule-none" },
6386
6958
  body: { setting: "Grant" }
6387
6959
  },
@@ -6392,7 +6964,7 @@ var SASjsApi = (() => {
6392
6964
  route: "DELETE /SASjsApi/permission/{uid}",
6393
6965
  description: "deletes a rule",
6394
6966
  identity: ADMIN_SIGNED_IN,
6395
- request: { token: ADMIN2, params: { uid: "rule-code" } },
6967
+ request: { token: ADMIN3, params: { uid: "rule-code" } },
6396
6968
  expect: { status: 200, body: "Permission Deleted!" }
6397
6969
  },
6398
6970
  {
@@ -6408,7 +6980,7 @@ var SASjsApi = (() => {
6408
6980
  route: "DELETE /SASjsApi/permission/{uid}",
6409
6981
  description: "answers 404 for a rule that does not exist",
6410
6982
  identity: ADMIN_SIGNED_IN,
6411
- request: { token: ADMIN2, params: { uid: "rule-none" } },
6983
+ request: { token: ADMIN3, params: { uid: "rule-none" } },
6412
6984
  expect: { status: 404, error: "Permission not found." }
6413
6985
  },
6414
6986
  // --------------------------------------------------------------- clients
@@ -6417,7 +6989,7 @@ var SASjsApi = (() => {
6417
6989
  route: "GET /SASjsApi/client",
6418
6990
  description: "lists the registered clients",
6419
6991
  identity: ADMIN_SIGNED_IN,
6420
- request: { token: ADMIN2 },
6992
+ request: { token: ADMIN3 },
6421
6993
  expect: {
6422
6994
  status: 200,
6423
6995
  body: [
@@ -6450,7 +7022,7 @@ var SASjsApi = (() => {
6450
7022
  description: "registers a client",
6451
7023
  identity: ADMIN_SIGNED_IN,
6452
7024
  request: {
6453
- token: ADMIN2,
7025
+ token: ADMIN3,
6454
7026
  body: {
6455
7027
  clientId: "new_app",
6456
7028
  clientSecret: "new_secret",
@@ -6474,7 +7046,7 @@ var SASjsApi = (() => {
6474
7046
  description: "applies the schema defaults when the lifetimes are omitted",
6475
7047
  identity: ADMIN_SIGNED_IN,
6476
7048
  request: {
6477
- token: ADMIN2,
7049
+ token: ADMIN3,
6478
7050
  body: { clientId: "default_app", clientSecret: "default_secret" }
6479
7051
  },
6480
7052
  expect: {
@@ -6509,7 +7081,7 @@ var SASjsApi = (() => {
6509
7081
  description: "refuses a client id that is registered, with the 403 the server sends",
6510
7082
  identity: ADMIN_SIGNED_IN,
6511
7083
  request: {
6512
- token: ADMIN2,
7084
+ token: ADMIN3,
6513
7085
  body: {
6514
7086
  clientId: "web_app",
6515
7087
  clientSecret: "other",
@@ -6581,6 +7153,10 @@ var SASjsApi = (() => {
6581
7153
  const identity = new MemoryIdentityStore(
6582
7154
  testCase.identity || DEFAULT_IDENTITY
6583
7155
  );
7156
+ const runner = new MemorySessionRunner({
7157
+ fail: testCase.failingRun,
7158
+ outputs: testCase.runOutput ? { [programOf(testCase)]: testCase.runOutput } : void 0
7159
+ });
6584
7160
  return {
6585
7161
  drive: createDriveService(
6586
7162
  testCase.unwritable ? new RefusingDriveStore(testCase.seed || {}) : new MemoryDriveStore(testCase.seed || {})
@@ -6588,9 +7164,15 @@ var SASjsApi = (() => {
6588
7164
  identity: createIdentityService(identity),
6589
7165
  records: createRecordService(identity),
6590
7166
  registry: new MemoryAppStreamRegistry(),
6591
- session: createSessionService(identity, new MemorySessionHost())
7167
+ session: createSessionService(identity, runner),
7168
+ // no `runTimes` option: the default is the five the document names, so a
7169
+ // case is never refused for a reason that belongs to one host's install
7170
+ runtime: createRuntimeService(identity, runner)
6592
7171
  };
6593
7172
  };
7173
+ var programOf = (testCase) => String(
7174
+ testCase.request.query?._program ?? testCase.request.body?._program ?? testCase.request.body?.code ?? ""
7175
+ );
6594
7176
  var RefusingDriveStore = class extends MemoryDriveStore {
6595
7177
  async write() {
6596
7178
  throw new Error("the store refused the write");