@sasjs/api 0.16.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 +668 -87
  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 +115 -1
  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 +22 -5
  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 +115 -1
  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 +13 -2
  38. package/build/esm/session/memory-host.d.ts.map +1 -1
  39. package/build/esm/session/memory-host.js +22 -5
  40. package/build/esm/session/service.d.ts +12 -1
  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.16.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,11 +3151,11 @@ var SASjsApi = (() => {
3012
3151
  };
3013
3152
  }
3014
3153
  case "GET /SASjsApi/session/{sessionId}/output": {
3015
- const artifact = await sessionRequired().output(
3154
+ const artifact2 = await sessionRequired().output(
3016
3155
  await caller(),
3017
3156
  String(params.sessionId ?? "")
3018
3157
  );
3019
- return { status: 200, contents: artifact.contents };
3158
+ return { status: 200, contents: artifact2.contents };
3020
3159
  }
3021
3160
  case "GET /SASjsApi/session/{sessionId}/state": {
3022
3161
  return {
@@ -3244,6 +3383,11 @@ var SASjsApi = (() => {
3244
3383
  var HANDLED_ROUTES = [
3245
3384
  "POST /SASjsApi/drive/deploy/upload",
3246
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",
3247
3391
  "GET /SASjsApi/session/{sessionId}",
3248
3392
  "GET /SASjsApi/session/{sessionId}/log",
3249
3393
  "GET /SASjsApi/session/{sessionId}/output",
@@ -3952,14 +4096,14 @@ var SASjsApi = (() => {
3952
4096
 
3953
4097
  // src/identity/memory-store.ts
3954
4098
  var keyOf = (subject) => `${subject.userId}|${subject.clientId}`;
3955
- var randomHex = (bytes2) => {
4099
+ var randomHex = (bytes3) => {
3956
4100
  const source = globalThis.crypto;
3957
4101
  if (!source)
3958
4102
  throw new ApiError(
3959
4103
  500,
3960
4104
  "This host has no Web Crypto (`globalThis.crypto`), so it cannot mint an unguessable identity string."
3961
4105
  );
3962
- const buffer = new Uint8Array(bytes2);
4106
+ const buffer = new Uint8Array(bytes3);
3963
4107
  source.getRandomValues(buffer);
3964
4108
  return Array.from(buffer, (byte) => byte.toString(16).padStart(2, "0")).join(
3965
4109
  ""
@@ -5123,7 +5267,7 @@ var SASjsApi = (() => {
5123
5267
  pid: 4242,
5124
5268
  creationTimeStamp: "2026-11-07T09:00:00.000Z",
5125
5269
  deathTimeStamp: "2026-11-07T09:00:04.000Z",
5126
- expiresAfterMins: 60
5270
+ expiresAfterMins: { mins: 60, used: false }
5127
5271
  }
5128
5272
  }
5129
5273
  },
@@ -5296,7 +5440,7 @@ var SASjsApi = (() => {
5296
5440
  pid: 4242,
5297
5441
  creationTimeStamp: "2026-11-07T09:00:00.000Z",
5298
5442
  deathTimeStamp: "2026-11-07T09:00:04.000Z",
5299
- expiresAfterMins: 60
5443
+ expiresAfterMins: { mins: 60, used: false }
5300
5444
  }
5301
5445
  },
5302
5446
  "sess-restricted": {
@@ -5336,23 +5480,450 @@ var SASjsApi = (() => {
5336
5480
  "sess-silent": { contents: "" }
5337
5481
  };
5338
5482
  var MemorySessionHost = class {
5339
- constructor(sessions = DEFAULT_SESSIONS) {
5483
+ constructor(sessions = {
5484
+ ...DEFAULT_SESSIONS
5485
+ }, states = {
5486
+ ...STATES
5487
+ }, logs = { ...LOGS }, outputs = {
5488
+ ...OUTPUTS
5489
+ }) {
5340
5490
  this.sessions = sessions;
5491
+ this.states = states;
5492
+ this.logs = logs;
5493
+ this.outputs = outputs;
5341
5494
  }
5342
5495
  async session(id) {
5343
5496
  return this.sessions[id];
5344
5497
  }
5345
5498
  async state(id) {
5346
- return STATES[id];
5499
+ return this.states[id];
5347
5500
  }
5348
5501
  async log(id) {
5349
- return LOGS[id];
5502
+ return this.logs[id];
5350
5503
  }
5351
5504
  async output(id) {
5352
- 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 };
5353
5688
  }
5354
5689
  };
5355
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
+
5356
5927
  // src/corpus/records.ts
5357
5928
  var SIGNED_IN_TOKENS = [
5358
5929
  {
@@ -5415,7 +5986,7 @@ var SASjsApi = (() => {
5415
5986
  }
5416
5987
  ]
5417
5988
  };
5418
- var ADMIN2 = "admin-access";
5989
+ var ADMIN3 = "admin-access";
5419
5990
  var RESTRICTED2 = "user-access";
5420
5991
  var RESTRICTED_UID = "user-restricted";
5421
5992
  var ADMIN_UID = "user-admin";
@@ -5426,7 +5997,7 @@ var SASjsApi = (() => {
5426
5997
  route: "GET /SASjsApi/user",
5427
5998
  description: "lists the accounts any signed-in caller may see",
5428
5999
  identity: ADMIN_SIGNED_IN,
5429
- request: { token: ADMIN2 },
6000
+ request: { token: ADMIN3 },
5430
6001
  expect: {
5431
6002
  status: 200,
5432
6003
  body: [
@@ -5475,7 +6046,7 @@ var SASjsApi = (() => {
5475
6046
  route: "GET /SASjsApi/user/{uid}",
5476
6047
  description: "answers 404 for an identifier no account has",
5477
6048
  identity: ADMIN_SIGNED_IN,
5478
- request: { token: ADMIN2, params: { uid: "user-none" } },
6049
+ request: { token: ADMIN3, params: { uid: "user-none" } },
5479
6050
  expect: { status: 404, error: "User is not found." }
5480
6051
  },
5481
6052
  {
@@ -5483,7 +6054,7 @@ var SASjsApi = (() => {
5483
6054
  route: "GET /SASjsApi/user/by/username/{username}",
5484
6055
  description: "finds an account by username",
5485
6056
  identity: ADMIN_SIGNED_IN,
5486
- request: { token: ADMIN2, params: { username: "user2" } },
6057
+ request: { token: ADMIN3, params: { username: "user2" } },
5487
6058
  expect: {
5488
6059
  status: 200,
5489
6060
  partial: { uid: RESTRICTED_UID, username: "user2", isAdmin: false }
@@ -5502,7 +6073,7 @@ var SASjsApi = (() => {
5502
6073
  route: "GET /SASjsApi/user/by/username/{username}",
5503
6074
  description: "answers 404 for a username no account has",
5504
6075
  identity: ADMIN_SIGNED_IN,
5505
- request: { token: ADMIN2, params: { username: "nobody" } },
6076
+ request: { token: ADMIN3, params: { username: "nobody" } },
5506
6077
  expect: { status: 404, error: "User is not found." }
5507
6078
  },
5508
6079
  {
@@ -5511,7 +6082,7 @@ var SASjsApi = (() => {
5511
6082
  description: "creates an account, sanitised, and reports it",
5512
6083
  identity: ADMIN_SIGNED_IN,
5513
6084
  request: {
5514
- token: ADMIN2,
6085
+ token: ADMIN3,
5515
6086
  body: {
5516
6087
  username: "newuser",
5517
6088
  displayName: " New User ",
@@ -5559,7 +6130,7 @@ var SASjsApi = (() => {
5559
6130
  description: "refuses a username that is taken",
5560
6131
  identity: ADMIN_SIGNED_IN,
5561
6132
  request: {
5562
- token: ADMIN2,
6133
+ token: ADMIN3,
5563
6134
  body: { username: "user2", displayName: "Another", password: "newpass" }
5564
6135
  },
5565
6136
  expect: { status: 409, error: "Username already exists." }
@@ -5570,7 +6141,7 @@ var SASjsApi = (() => {
5570
6141
  description: "changes an account's display name",
5571
6142
  identity: ADMIN_SIGNED_IN,
5572
6143
  request: {
5573
- token: ADMIN2,
6144
+ token: ADMIN3,
5574
6145
  params: { uid: RESTRICTED_UID },
5575
6146
  body: {
5576
6147
  displayName: "Renamed User",
@@ -5601,7 +6172,7 @@ var SASjsApi = (() => {
5601
6172
  description: "answers 404 with the identifier it looked up",
5602
6173
  identity: ADMIN_SIGNED_IN,
5603
6174
  request: {
5604
- token: ADMIN2,
6175
+ token: ADMIN3,
5605
6176
  params: { uid: "user-none" },
5606
6177
  body: { displayName: "Nobody", username: "nobody", password: "none123" }
5607
6178
  },
@@ -5613,7 +6184,7 @@ var SASjsApi = (() => {
5613
6184
  description: "refuses a username change on a provider-managed account",
5614
6185
  identity: PROVIDER_MANAGED,
5615
6186
  request: {
5616
- token: ADMIN2,
6187
+ token: ADMIN3,
5617
6188
  params: { uid: "user-directory" },
5618
6189
  body: {
5619
6190
  username: "renamed",
@@ -5632,7 +6203,7 @@ var SASjsApi = (() => {
5632
6203
  description: "refuses a username another account already has",
5633
6204
  identity: ADMIN_SIGNED_IN,
5634
6205
  request: {
5635
- token: ADMIN2,
6206
+ token: ADMIN3,
5636
6207
  params: { uid: RESTRICTED_UID },
5637
6208
  body: { username: "admin", displayName: "Demo User", password: "user123" }
5638
6209
  },
@@ -5644,7 +6215,7 @@ var SASjsApi = (() => {
5644
6215
  description: "changes an account looked up by username",
5645
6216
  identity: ADMIN_SIGNED_IN,
5646
6217
  request: {
5647
- token: ADMIN2,
6218
+ token: ADMIN3,
5648
6219
  params: { username: "user2" },
5649
6220
  body: {
5650
6221
  isActive: false,
@@ -5673,7 +6244,7 @@ var SASjsApi = (() => {
5673
6244
  description: "answers 404 with the username it looked up",
5674
6245
  identity: ADMIN_SIGNED_IN,
5675
6246
  request: {
5676
- token: ADMIN2,
6247
+ token: ADMIN3,
5677
6248
  params: { username: "nobody" },
5678
6249
  body: { displayName: "Nobody", username: "nobody", password: "none123" }
5679
6250
  },
@@ -5685,7 +6256,7 @@ var SASjsApi = (() => {
5685
6256
  description: "refuses a display-name change on a provider-managed account",
5686
6257
  identity: PROVIDER_MANAGED,
5687
6258
  request: {
5688
- token: ADMIN2,
6259
+ token: ADMIN3,
5689
6260
  params: { username: "diruser" },
5690
6261
  body: { displayName: "Renamed", username: "diruser", password: "dir123" }
5691
6262
  },
@@ -5700,7 +6271,7 @@ var SASjsApi = (() => {
5700
6271
  description: "refuses a username another account already has",
5701
6272
  identity: ADMIN_SIGNED_IN,
5702
6273
  request: {
5703
- token: ADMIN2,
6274
+ token: ADMIN3,
5704
6275
  params: { username: "user2" },
5705
6276
  body: { username: "admin", displayName: "Demo User", password: "user123" }
5706
6277
  },
@@ -5711,7 +6282,7 @@ var SASjsApi = (() => {
5711
6282
  route: "DELETE /SASjsApi/user/{uid}",
5712
6283
  description: "deletes an account as an administrator, without a password",
5713
6284
  identity: ADMIN_SIGNED_IN,
5714
- request: { token: ADMIN2, params: { uid: RESTRICTED_UID }, body: {} },
6285
+ request: { token: ADMIN3, params: { uid: RESTRICTED_UID }, body: {} },
5715
6286
  expect: { status: 200, body: "Account Deleted!" }
5716
6287
  },
5717
6288
  {
@@ -5727,7 +6298,7 @@ var SASjsApi = (() => {
5727
6298
  route: "DELETE /SASjsApi/user/{uid}",
5728
6299
  description: "answers 404 for an identifier no account has",
5729
6300
  identity: ADMIN_SIGNED_IN,
5730
- request: { token: ADMIN2, params: { uid: "user-none" }, body: {} },
6301
+ request: { token: ADMIN3, params: { uid: "user-none" }, body: {} },
5731
6302
  expect: { status: 404, error: "User is not found." }
5732
6303
  },
5733
6304
  {
@@ -5736,7 +6307,7 @@ var SASjsApi = (() => {
5736
6307
  description: "deletes an account looked up by username",
5737
6308
  identity: ADMIN_SIGNED_IN,
5738
6309
  request: {
5739
- token: ADMIN2,
6310
+ token: ADMIN3,
5740
6311
  params: { username: "user2" },
5741
6312
  body: {}
5742
6313
  },
@@ -5759,7 +6330,7 @@ var SASjsApi = (() => {
5759
6330
  route: "DELETE /SASjsApi/user/by/username/{username}",
5760
6331
  description: "answers 404 for a username no account has",
5761
6332
  identity: ADMIN_SIGNED_IN,
5762
- request: { token: ADMIN2, params: { username: "nobody" }, body: {} },
6333
+ request: { token: ADMIN3, params: { username: "nobody" }, body: {} },
5763
6334
  expect: { status: 404, error: "User is not found." }
5764
6335
  },
5765
6336
  // ----------------------------------------------------------------- groups
@@ -5813,7 +6384,7 @@ var SASjsApi = (() => {
5813
6384
  route: "GET /SASjsApi/group/{uid}",
5814
6385
  description: "answers 404 for an identifier no group has",
5815
6386
  identity: ADMIN_SIGNED_IN,
5816
- request: { token: ADMIN2, params: { uid: "group-none" } },
6387
+ request: { token: ADMIN3, params: { uid: "group-none" } },
5817
6388
  expect: { status: 404, error: "Group not found." }
5818
6389
  },
5819
6390
  {
@@ -5821,7 +6392,7 @@ var SASjsApi = (() => {
5821
6392
  route: "GET /SASjsApi/group/by/groupname/{name}",
5822
6393
  description: "finds a group by name",
5823
6394
  identity: ADMIN_SIGNED_IN,
5824
- request: { token: ADMIN2, params: { name: "DCGroup" } },
6395
+ request: { token: ADMIN3, params: { name: "DCGroup" } },
5825
6396
  expect: {
5826
6397
  status: 200,
5827
6398
  partial: { uid: "group-data-controller", name: "DCGroup" }
@@ -5832,7 +6403,7 @@ var SASjsApi = (() => {
5832
6403
  route: "GET /SASjsApi/group/by/groupname/{name}",
5833
6404
  description: "answers 404 for a name no group has",
5834
6405
  identity: ADMIN_SIGNED_IN,
5835
- request: { token: ADMIN2, params: { name: "nope" } },
6406
+ request: { token: ADMIN3, params: { name: "nope" } },
5836
6407
  expect: { status: 404, error: "Group not found." }
5837
6408
  },
5838
6409
  {
@@ -5841,7 +6412,7 @@ var SASjsApi = (() => {
5841
6412
  description: "creates a group with no members",
5842
6413
  identity: ADMIN_SIGNED_IN,
5843
6414
  request: {
5844
- token: ADMIN2,
6415
+ token: ADMIN3,
5845
6416
  body: { name: "NewGroup", description: "A new group", isActive: true }
5846
6417
  },
5847
6418
  expect: {
@@ -5870,7 +6441,7 @@ var SASjsApi = (() => {
5870
6441
  route: "POST /SASjsApi/group",
5871
6442
  description: "refuses a name that is taken",
5872
6443
  identity: ADMIN_SIGNED_IN,
5873
- request: { token: ADMIN2, body: { name: "DCGroup", description: "again" } },
6444
+ request: { token: ADMIN3, body: { name: "DCGroup", description: "again" } },
5874
6445
  expect: { status: 409, error: "Group name already exists." }
5875
6446
  },
5876
6447
  {
@@ -5879,7 +6450,7 @@ var SASjsApi = (() => {
5879
6450
  description: "adds a member and returns the group",
5880
6451
  identity: ADMIN_SIGNED_IN,
5881
6452
  request: {
5882
- token: ADMIN2,
6453
+ token: ADMIN3,
5883
6454
  params: { groupUid: "group-admins", userUid: RESTRICTED_UID }
5884
6455
  },
5885
6456
  expect: {
@@ -5893,7 +6464,7 @@ var SASjsApi = (() => {
5893
6464
  description: "refuses a change to the reserved public group",
5894
6465
  identity: PROVIDER_MANAGED,
5895
6466
  request: {
5896
- token: ADMIN2,
6467
+ token: ADMIN3,
5897
6468
  params: { groupUid: "group-public", userUid: RESTRICTED_UID }
5898
6469
  },
5899
6470
  expect: { status: 400, error: "Can't add/remove user to 'public' group." }
@@ -5915,7 +6486,7 @@ var SASjsApi = (() => {
5915
6486
  description: "answers 404 for a group that does not exist",
5916
6487
  identity: ADMIN_SIGNED_IN,
5917
6488
  request: {
5918
- token: ADMIN2,
6489
+ token: ADMIN3,
5919
6490
  params: { groupUid: "group-none", userUid: RESTRICTED_UID }
5920
6491
  },
5921
6492
  expect: { status: 404, error: "Group not found." }
@@ -5926,7 +6497,7 @@ var SASjsApi = (() => {
5926
6497
  description: "refuses a membership change on a provider-managed group",
5927
6498
  identity: PROVIDER_MANAGED,
5928
6499
  request: {
5929
- token: ADMIN2,
6500
+ token: ADMIN3,
5930
6501
  params: { groupUid: "group-directory", userUid: RESTRICTED_UID }
5931
6502
  },
5932
6503
  expect: {
@@ -5940,7 +6511,7 @@ var SASjsApi = (() => {
5940
6511
  description: "removes a member and returns the group",
5941
6512
  identity: ADMIN_SIGNED_IN,
5942
6513
  request: {
5943
- token: ADMIN2,
6514
+ token: ADMIN3,
5944
6515
  params: { groupUid: "group-data-controller", userUid: RESTRICTED_UID }
5945
6516
  },
5946
6517
  expect: {
@@ -5954,7 +6525,7 @@ var SASjsApi = (() => {
5954
6525
  description: "refuses a membership change for a provider-managed user",
5955
6526
  identity: PROVIDER_MANAGED,
5956
6527
  request: {
5957
- token: ADMIN2,
6528
+ token: ADMIN3,
5958
6529
  params: { groupUid: "group-admins", userUid: "user-directory" }
5959
6530
  },
5960
6531
  expect: {
@@ -5968,7 +6539,7 @@ var SASjsApi = (() => {
5968
6539
  description: "refuses a membership change for a provider-managed user",
5969
6540
  identity: PROVIDER_MANAGED,
5970
6541
  request: {
5971
- token: ADMIN2,
6542
+ token: ADMIN3,
5972
6543
  params: { groupUid: "group-admins", userUid: "user-directory" }
5973
6544
  },
5974
6545
  expect: {
@@ -5982,7 +6553,7 @@ var SASjsApi = (() => {
5982
6553
  description: "refuses a change to the reserved public group",
5983
6554
  identity: PROVIDER_MANAGED,
5984
6555
  request: {
5985
- token: ADMIN2,
6556
+ token: ADMIN3,
5986
6557
  params: { groupUid: "group-public", userUid: RESTRICTED_UID }
5987
6558
  },
5988
6559
  expect: { status: 400, error: "Can't add/remove user to 'public' group." }
@@ -6004,7 +6575,7 @@ var SASjsApi = (() => {
6004
6575
  description: "answers 404 for a member that does not exist",
6005
6576
  identity: ADMIN_SIGNED_IN,
6006
6577
  request: {
6007
- token: ADMIN2,
6578
+ token: ADMIN3,
6008
6579
  params: { groupUid: "group-admins", userUid: "user-none" }
6009
6580
  },
6010
6581
  expect: { status: 404, error: "User not found." }
@@ -6015,7 +6586,7 @@ var SASjsApi = (() => {
6015
6586
  description: "refuses a membership change on a provider-managed group",
6016
6587
  identity: PROVIDER_MANAGED,
6017
6588
  request: {
6018
- token: ADMIN2,
6589
+ token: ADMIN3,
6019
6590
  params: { groupUid: "group-directory", userUid: RESTRICTED_UID }
6020
6591
  },
6021
6592
  expect: {
@@ -6028,7 +6599,7 @@ var SASjsApi = (() => {
6028
6599
  route: "DELETE /SASjsApi/group/{uid}",
6029
6600
  description: "deletes a group",
6030
6601
  identity: ADMIN_SIGNED_IN,
6031
- request: { token: ADMIN2, params: { uid: "group-data-controller" } },
6602
+ request: { token: ADMIN3, params: { uid: "group-data-controller" } },
6032
6603
  expect: { status: 200 }
6033
6604
  },
6034
6605
  {
@@ -6044,7 +6615,7 @@ var SASjsApi = (() => {
6044
6615
  route: "DELETE /SASjsApi/group/{uid}",
6045
6616
  description: "answers 404 for an identifier no group has",
6046
6617
  identity: ADMIN_SIGNED_IN,
6047
- request: { token: ADMIN2, params: { uid: "group-none" } },
6618
+ request: { token: ADMIN3, params: { uid: "group-none" } },
6048
6619
  expect: { status: 404, error: "Group not found." }
6049
6620
  },
6050
6621
  // ------------------------------------------------------------ permissions
@@ -6053,7 +6624,7 @@ var SASjsApi = (() => {
6053
6624
  route: "GET /SASjsApi/info/authorizedRoutes",
6054
6625
  description: "answers the route inventory to an administrator",
6055
6626
  identity: ADMIN_SIGNED_IN,
6056
- request: { token: ADMIN2 },
6627
+ request: { token: ADMIN3 },
6057
6628
  expect: {
6058
6629
  status: 200,
6059
6630
  body: {
@@ -6085,7 +6656,7 @@ var SASjsApi = (() => {
6085
6656
  route: "GET /SASjsApi/info/myAuthorizedRoutes",
6086
6657
  description: "answers every route to an administrator",
6087
6658
  identity: ADMIN_SIGNED_IN,
6088
- request: { token: ADMIN2 },
6659
+ request: { token: ADMIN3 },
6089
6660
  expect: {
6090
6661
  status: 200,
6091
6662
  body: {
@@ -6125,7 +6696,7 @@ var SASjsApi = (() => {
6125
6696
  route: "GET /SASjsApi/permission",
6126
6697
  description: "returns every rule to an administrator",
6127
6698
  identity: ADMIN_SIGNED_IN,
6128
- request: { token: ADMIN2 },
6699
+ request: { token: ADMIN3 },
6129
6700
  expect: {
6130
6701
  status: 200,
6131
6702
  body: [
@@ -6200,7 +6771,7 @@ var SASjsApi = (() => {
6200
6771
  description: "creates a rule for a user",
6201
6772
  identity: ADMIN_SIGNED_IN,
6202
6773
  request: {
6203
- token: ADMIN2,
6774
+ token: ADMIN3,
6204
6775
  body: {
6205
6776
  path: "/SASjsApi/drive/folder",
6206
6777
  type: "Route",
@@ -6220,7 +6791,7 @@ var SASjsApi = (() => {
6220
6791
  description: "creates a rule for a group",
6221
6792
  identity: ADMIN_SIGNED_IN,
6222
6793
  request: {
6223
- token: ADMIN2,
6794
+ token: ADMIN3,
6224
6795
  body: {
6225
6796
  path: "/SASjsApi/drive/rename",
6226
6797
  type: "Route",
@@ -6244,7 +6815,7 @@ var SASjsApi = (() => {
6244
6815
  description: "refuses a principal type that is neither a user nor a group",
6245
6816
  identity: ADMIN_SIGNED_IN,
6246
6817
  request: {
6247
- token: ADMIN2,
6818
+ token: ADMIN3,
6248
6819
  body: {
6249
6820
  path: "/SASjsApi/drive/deploy",
6250
6821
  type: "Route",
@@ -6264,7 +6835,7 @@ var SASjsApi = (() => {
6264
6835
  description: "refuses a rule assigned to an administrator",
6265
6836
  identity: ADMIN_SIGNED_IN,
6266
6837
  request: {
6267
- token: ADMIN2,
6838
+ token: ADMIN3,
6268
6839
  body: {
6269
6840
  path: "/SASjsApi/drive/folder",
6270
6841
  type: "Route",
@@ -6301,7 +6872,7 @@ var SASjsApi = (() => {
6301
6872
  description: "answers 404 for a principal that does not exist",
6302
6873
  identity: ADMIN_SIGNED_IN,
6303
6874
  request: {
6304
- token: ADMIN2,
6875
+ token: ADMIN3,
6305
6876
  body: {
6306
6877
  path: "/SASjsApi/drive/rename",
6307
6878
  type: "Route",
@@ -6318,7 +6889,7 @@ var SASjsApi = (() => {
6318
6889
  description: "refuses a group rule that already exists",
6319
6890
  identity: ADMIN_SIGNED_IN,
6320
6891
  request: {
6321
- token: ADMIN2,
6892
+ token: ADMIN3,
6322
6893
  body: {
6323
6894
  path: "/SASjsApi/drive/file",
6324
6895
  type: "Route",
@@ -6338,7 +6909,7 @@ var SASjsApi = (() => {
6338
6909
  description: "refuses a rule that already exists",
6339
6910
  identity: ADMIN_SIGNED_IN,
6340
6911
  request: {
6341
- token: ADMIN2,
6912
+ token: ADMIN3,
6342
6913
  body: {
6343
6914
  path: "/SASjsApi/code/execute",
6344
6915
  type: "Route",
@@ -6358,7 +6929,7 @@ var SASjsApi = (() => {
6358
6929
  description: "flips a rule from Deny to Grant",
6359
6930
  identity: ADMIN_SIGNED_IN,
6360
6931
  request: {
6361
- token: ADMIN2,
6932
+ token: ADMIN3,
6362
6933
  params: { uid: "rule-code" },
6363
6934
  body: { setting: "Grant" }
6364
6935
  },
@@ -6382,7 +6953,7 @@ var SASjsApi = (() => {
6382
6953
  description: "answers 404 for a rule that does not exist",
6383
6954
  identity: ADMIN_SIGNED_IN,
6384
6955
  request: {
6385
- token: ADMIN2,
6956
+ token: ADMIN3,
6386
6957
  params: { uid: "rule-none" },
6387
6958
  body: { setting: "Grant" }
6388
6959
  },
@@ -6393,7 +6964,7 @@ var SASjsApi = (() => {
6393
6964
  route: "DELETE /SASjsApi/permission/{uid}",
6394
6965
  description: "deletes a rule",
6395
6966
  identity: ADMIN_SIGNED_IN,
6396
- request: { token: ADMIN2, params: { uid: "rule-code" } },
6967
+ request: { token: ADMIN3, params: { uid: "rule-code" } },
6397
6968
  expect: { status: 200, body: "Permission Deleted!" }
6398
6969
  },
6399
6970
  {
@@ -6409,7 +6980,7 @@ var SASjsApi = (() => {
6409
6980
  route: "DELETE /SASjsApi/permission/{uid}",
6410
6981
  description: "answers 404 for a rule that does not exist",
6411
6982
  identity: ADMIN_SIGNED_IN,
6412
- request: { token: ADMIN2, params: { uid: "rule-none" } },
6983
+ request: { token: ADMIN3, params: { uid: "rule-none" } },
6413
6984
  expect: { status: 404, error: "Permission not found." }
6414
6985
  },
6415
6986
  // --------------------------------------------------------------- clients
@@ -6418,7 +6989,7 @@ var SASjsApi = (() => {
6418
6989
  route: "GET /SASjsApi/client",
6419
6990
  description: "lists the registered clients",
6420
6991
  identity: ADMIN_SIGNED_IN,
6421
- request: { token: ADMIN2 },
6992
+ request: { token: ADMIN3 },
6422
6993
  expect: {
6423
6994
  status: 200,
6424
6995
  body: [
@@ -6451,7 +7022,7 @@ var SASjsApi = (() => {
6451
7022
  description: "registers a client",
6452
7023
  identity: ADMIN_SIGNED_IN,
6453
7024
  request: {
6454
- token: ADMIN2,
7025
+ token: ADMIN3,
6455
7026
  body: {
6456
7027
  clientId: "new_app",
6457
7028
  clientSecret: "new_secret",
@@ -6475,7 +7046,7 @@ var SASjsApi = (() => {
6475
7046
  description: "applies the schema defaults when the lifetimes are omitted",
6476
7047
  identity: ADMIN_SIGNED_IN,
6477
7048
  request: {
6478
- token: ADMIN2,
7049
+ token: ADMIN3,
6479
7050
  body: { clientId: "default_app", clientSecret: "default_secret" }
6480
7051
  },
6481
7052
  expect: {
@@ -6510,7 +7081,7 @@ var SASjsApi = (() => {
6510
7081
  description: "refuses a client id that is registered, with the 403 the server sends",
6511
7082
  identity: ADMIN_SIGNED_IN,
6512
7083
  request: {
6513
- token: ADMIN2,
7084
+ token: ADMIN3,
6514
7085
  body: {
6515
7086
  clientId: "web_app",
6516
7087
  clientSecret: "other",
@@ -6582,6 +7153,10 @@ var SASjsApi = (() => {
6582
7153
  const identity = new MemoryIdentityStore(
6583
7154
  testCase.identity || DEFAULT_IDENTITY
6584
7155
  );
7156
+ const runner = new MemorySessionRunner({
7157
+ fail: testCase.failingRun,
7158
+ outputs: testCase.runOutput ? { [programOf(testCase)]: testCase.runOutput } : void 0
7159
+ });
6585
7160
  return {
6586
7161
  drive: createDriveService(
6587
7162
  testCase.unwritable ? new RefusingDriveStore(testCase.seed || {}) : new MemoryDriveStore(testCase.seed || {})
@@ -6589,9 +7164,15 @@ var SASjsApi = (() => {
6589
7164
  identity: createIdentityService(identity),
6590
7165
  records: createRecordService(identity),
6591
7166
  registry: new MemoryAppStreamRegistry(),
6592
- 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)
6593
7171
  };
6594
7172
  };
7173
+ var programOf = (testCase) => String(
7174
+ testCase.request.query?._program ?? testCase.request.body?._program ?? testCase.request.body?.code ?? ""
7175
+ );
6595
7176
  var RefusingDriveStore = class extends MemoryDriveStore {
6596
7177
  async write() {
6597
7178
  throw new Error("the store refused the write");