@sasjs/api 0.30.0 → 0.31.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 (35) hide show
  1. package/build/browser.js +534 -333
  2. package/build/cjs/corpus/app.js +55 -0
  3. package/build/cjs/corpus/runner.js +7 -6
  4. package/build/cjs/host/dispatch.js +71 -0
  5. package/build/cjs/index.js +9 -2
  6. package/build/cjs/routes/generated.js +34 -0
  7. package/build/cjs/routes/overlay.js +34 -1
  8. package/build/cjs/runtime/program.js +85 -0
  9. package/build/cjs/runtime/runTimes.js +13 -0
  10. package/build/cjs/runtime/service.js +11 -13
  11. package/build/esm/corpus/app.d.ts +17 -0
  12. package/build/esm/corpus/app.d.ts.map +1 -0
  13. package/build/esm/corpus/app.js +52 -0
  14. package/build/esm/corpus/runner.d.ts +13 -0
  15. package/build/esm/corpus/runner.d.ts.map +1 -1
  16. package/build/esm/corpus/runner.js +5 -4
  17. package/build/esm/host/dispatch.d.ts.map +1 -1
  18. package/build/esm/host/dispatch.js +72 -1
  19. package/build/esm/index.d.ts +5 -1
  20. package/build/esm/index.d.ts.map +1 -1
  21. package/build/esm/index.js +4 -1
  22. package/build/esm/routes/generated.d.ts.map +1 -1
  23. package/build/esm/routes/generated.js +34 -0
  24. package/build/esm/routes/overlay.d.ts.map +1 -1
  25. package/build/esm/routes/overlay.js +34 -1
  26. package/build/esm/runtime/program.d.ts +56 -0
  27. package/build/esm/runtime/program.d.ts.map +1 -0
  28. package/build/esm/runtime/program.js +79 -0
  29. package/build/esm/runtime/runTimes.d.ts +11 -0
  30. package/build/esm/runtime/runTimes.d.ts.map +1 -0
  31. package/build/esm/runtime/runTimes.js +10 -0
  32. package/build/esm/runtime/service.d.ts +0 -2
  33. package/build/esm/runtime/service.d.ts.map +1 -1
  34. package/build/esm/runtime/service.js +9 -11
  35. package/package.json +1 -1
package/build/browser.js CHANGED
@@ -1,4 +1,4 @@
1
- /* @sasjs/api 0.30.0 - the SASjs Server API, for a service worker. https://github.com/sasjs/api */
1
+ /* @sasjs/api 0.31.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;
@@ -25,6 +25,7 @@ var SASjsApi = (() => {
25
25
  ADMIN_CORPUS: () => ADMIN_CORPUS,
26
26
  ADMIN_SIGNED_IN: () => ADMIN_SIGNED_IN,
27
27
  ALWAYS_VISIBLE_ROUTES: () => ALWAYS_VISIBLE_ROUTES,
28
+ APP_CORPUS: () => APP_CORPUS,
28
29
  APP_MANIFEST: () => APP_MANIFEST,
29
30
  APP_STREAM_INDEX: () => APP_STREAM_INDEX,
30
31
  AUTH_CONFIG_CORPUS: () => AUTH_CONFIG_CORPUS,
@@ -111,9 +112,12 @@ var SASjsApi = (() => {
111
112
  normaliseLogFiles: () => normaliseLogFiles,
112
113
  parseAppManifest: () => parseAppManifest,
113
114
  parseIdentity: () => parseIdentity,
115
+ programNotFound: () => programNotFound,
114
116
  publishRequestFor: () => publishRequestFor,
117
+ resolveProgram: () => resolveProgram,
115
118
  routeById: () => routeById,
116
119
  runCase: () => runCase,
120
+ runTimeOfPath: () => runTimeOfPath,
117
121
  sanitiseDisplayName: () => sanitiseDisplayName,
118
122
  servicesFor: () => servicesFor,
119
123
  splitAppBundle: () => splitAppBundle,
@@ -728,6 +732,40 @@ var SASjsApi = (() => {
728
732
  }
729
733
  ]
730
734
  },
735
+ {
736
+ id: "GET /SASjsApi/app/{id}",
737
+ method: "GET",
738
+ path: "/SASjsApi/app/{id}",
739
+ tag: "App Stream",
740
+ summary: "Get a published app by id",
741
+ params: [
742
+ {
743
+ name: "id",
744
+ in: "path",
745
+ required: true,
746
+ type: "string"
747
+ }
748
+ ],
749
+ requestBodies: [],
750
+ responses: [
751
+ {
752
+ status: 200,
753
+ description: "Ok"
754
+ },
755
+ {
756
+ status: 401,
757
+ description: "Unauthorized"
758
+ },
759
+ {
760
+ status: 404,
761
+ description: "No App Stream is registered with that id."
762
+ },
763
+ {
764
+ status: 500,
765
+ description: "Internal Server Error"
766
+ }
767
+ ]
768
+ },
731
769
  {
732
770
  id: "POST /SASjsApi/auth/logout",
733
771
  method: "POST",
@@ -2723,7 +2761,9 @@ var SASjsApi = (() => {
2723
2761
  Group: ["identity"],
2724
2762
  Permission: ["identity"],
2725
2763
  Client: ["identity"],
2726
- Web: ["identity"]
2764
+ Web: ["identity"],
2765
+ // an app's entry is indexed, and the file it is served from is read off the drive
2766
+ "App Stream": ["storage"]
2727
2767
  };
2728
2768
  var success = { status: "success" };
2729
2769
  var user = {
@@ -2954,6 +2994,37 @@ var SASjsApi = (() => {
2954
2994
  // `404` is an id the index does not hold - the id is the app, and its label and
2955
2995
  // folder are not handles - and the drive's content is deliberately left alone.
2956
2996
  "DELETE /SASjsApi/drive/deploy": { implemented: true },
2997
+ // App Stream - what is published under one app's id.
2998
+ //
2999
+ // Carried here: the answer is the app index plus the drive, and `APP_CORPUS` pins
3000
+ // its shape. The mock build (`sasjs/cli`) still answers the App Stream surface by
3001
+ // hand; consuming this operation from the table is its next step on
3002
+ // sasjs/cli#1550, not this package's.
3003
+ "GET /SASjsApi/app/{id}": {
3004
+ implemented: true,
3005
+ // the caller's token is the host's middleware, and a failure that is not the
3006
+ // index refusing the id - a drive read that broke - is the host's to answer
3007
+ hostResponses: [401, 500],
3008
+ // the shape a client reads: the entry as registered, the file it is served from,
3009
+ // and whether that file is there
3010
+ responses: {
3011
+ 404: {
3012
+ status: "failure",
3013
+ message: "No App Stream is registered with that id."
3014
+ },
3015
+ 200: {
3016
+ id: "",
3017
+ name: "",
3018
+ appLoc: "",
3019
+ streamWebFolder: "",
3020
+ publishedAt: null,
3021
+ entryFile: "index.html",
3022
+ entryFileExists: false,
3023
+ lastModified: null,
3024
+ url: ""
3025
+ }
3026
+ }
3027
+ },
2957
3028
  // Group - members and the groups themselves
2958
3029
  "GET /SASjsApi/group": { implemented: true },
2959
3030
  "GET /SASjsApi/group/{uid}": { implemented: true },
@@ -3479,6 +3550,12 @@ var SASjsApi = (() => {
3479
3550
  throw new ApiError(400, `"${param.name}" is not allowed to be empty`);
3480
3551
  }
3481
3552
  };
3553
+ var APP_ENTRY_FILE = "index.html";
3554
+ var APP_NOT_REGISTERED = "No App Stream is registered with that id.";
3555
+ var appNotRegistered = () => new ApiError(404, APP_NOT_REGISTERED, {
3556
+ status: "failure",
3557
+ message: APP_NOT_REGISTERED
3558
+ });
3482
3559
  var targetPath = (request) => {
3483
3560
  const fromQuery = request.query?._filePath;
3484
3561
  const fromBody = request.body?.filePath;
@@ -3744,6 +3821,52 @@ var SASjsApi = (() => {
3744
3821
  body: { status: "success", app: appSummary(removed) }
3745
3822
  };
3746
3823
  }
3824
+ // --------------------------------------------------- what an app *is*
3825
+ //
3826
+ // The surface serves an app's files; this describes the app itself - the entry
3827
+ // as registered, and whether the file it is served from is there. Addressed by id,
3828
+ // which is what a publish answers with and what the app's URL carries: a label is
3829
+ // shared by design, so "the app with this name" is not one app.
3830
+ case "GET /SASjsApi/app/{id}": {
3831
+ if (!services.appStream)
3832
+ throw new ApiError(
3833
+ 501,
3834
+ `This host has no app stream, so it cannot answer ${routeId}.`
3835
+ );
3836
+ const entry = await services.appStream.get(String(params.id ?? "")).catch((err) => {
3837
+ if (isApiError(err) && err.status === 404) throw appNotRegistered();
3838
+ throw err;
3839
+ });
3840
+ const folder = `${entry.appLoc}/services/${entry.streamWebFolder}`;
3841
+ let entryFileExists = false;
3842
+ let lastModified = null;
3843
+ try {
3844
+ const { tree } = await drive.tree(folder);
3845
+ const file = tree.children.find(
3846
+ (child) => child.name === APP_ENTRY_FILE && !child.isFolder
3847
+ );
3848
+ entryFileExists = file !== void 0;
3849
+ lastModified = file?.modified ?? null;
3850
+ } catch (err) {
3851
+ if (!isApiError(err) || err.status !== 404) throw err;
3852
+ entryFileExists = false;
3853
+ }
3854
+ const body2 = {
3855
+ id: entry.id,
3856
+ name: entry.name,
3857
+ appLoc: entry.appLoc,
3858
+ streamWebFolder: entry.streamWebFolder,
3859
+ publishedAt: entry.publishedAt ?? null,
3860
+ entryFile: APP_ENTRY_FILE,
3861
+ entryFileExists,
3862
+ lastModified,
3863
+ url: `/app/${entry.id}/`
3864
+ };
3865
+ if (entry.logo !== void 0) body2.logo = entry.logo;
3866
+ if (entry.frameAncestors !== void 0)
3867
+ body2.frameAncestors = entry.frameAncestors;
3868
+ return { status: 200, body: body2 };
3869
+ }
3747
3870
  case "GET /SASjsApi/drive/filetree":
3748
3871
  return { status: 200, body: await drive.tree(query._folderPath) };
3749
3872
  // ------------------------------------------------------------- run times
@@ -4083,6 +4206,7 @@ var SASjsApi = (() => {
4083
4206
  "DELETE /SASjsApi/drive/folder",
4084
4207
  "POST /SASjsApi/drive/rename",
4085
4208
  "GET /SASjsApi/drive/filetree",
4209
+ "GET /SASjsApi/app/{id}",
4086
4210
  "POST /SASjsApi/drive/deploy",
4087
4211
  "POST /SASjsApi/auth/token",
4088
4212
  "POST /SASjsApi/auth/refresh",
@@ -6891,150 +7015,6 @@ var SASjsApi = (() => {
6891
7015
  }
6892
7016
  ];
6893
7017
 
6894
- // src/corpus/session.ts
6895
- var ADMIN = { userId: "user-admin", clientId: "web_app" };
6896
- var RESTRICTED = { userId: "user-restricted", clientId: "web_app" };
6897
- var notFound = (id) => `Session with ID '${id}' was not found.`;
6898
- var UNAUTHORIZED = "Unauthorized";
6899
- var SESSION_CORPUS = [
6900
- // ---------------------------------------------------------------- summary
6901
- {
6902
- id: "session-summary-own",
6903
- route: "GET /SASjsApi/session/{sessionId}",
6904
- description: "answers the owner the summary of their own session",
6905
- request: { subject: ADMIN, params: { sessionId: "sess-admin" } },
6906
- expect: {
6907
- status: 200,
6908
- body: {
6909
- sessionId: "sess-admin",
6910
- state: "completed",
6911
- pid: 4242,
6912
- creationTimeStamp: "2026-11-07T09:00:00.000Z",
6913
- deathTimeStamp: "2026-11-07T09:00:04.000Z",
6914
- expiresAfterMins: { mins: 60, used: false }
6915
- }
6916
- }
6917
- },
6918
- {
6919
- id: "session-summary-as-admin",
6920
- route: "GET /SASjsApi/session/{sessionId}",
6921
- description: "answers an administrator another account's session",
6922
- request: { subject: ADMIN, params: { sessionId: "sess-restricted" } },
6923
- // both stamps: the document requires them, and this host stamps a session's
6924
- // death time at creation rather than at completion - a running session
6925
- // answers with the moment it is due to be destroyed
6926
- expect: {
6927
- status: 200,
6928
- body: {
6929
- sessionId: "sess-restricted",
6930
- state: "running",
6931
- pid: 4243,
6932
- creationTimeStamp: "2026-11-07T09:05:00.000Z",
6933
- deathTimeStamp: "2026-11-07T09:20:00.000Z"
6934
- }
6935
- }
6936
- },
6937
- {
6938
- id: "session-summary-unauthenticated",
6939
- route: "GET /SASjsApi/session/{sessionId}",
6940
- description: "refuses a caller with no token",
6941
- request: { params: { sessionId: "sess-admin" } },
6942
- expect: { status: 401, error: UNAUTHORIZED }
6943
- },
6944
- {
6945
- id: "session-summary-foreign",
6946
- route: "GET /SASjsApi/session/{sessionId}",
6947
- description: "answers 404 for another account's session, not 403",
6948
- request: { subject: RESTRICTED, params: { sessionId: "sess-admin" } },
6949
- expect: { status: 404, error: notFound("sess-admin") }
6950
- },
6951
- {
6952
- id: "session-summary-unknown",
6953
- route: "GET /SASjsApi/session/{sessionId}",
6954
- description: "answers the same 404 for a session that does not exist",
6955
- request: { subject: ADMIN, params: { sessionId: "sess-nope" } },
6956
- expect: { status: 404, error: notFound("sess-nope") }
6957
- },
6958
- // -------------------------------------------------------------------- log
6959
- {
6960
- id: "session-log-own",
6961
- route: "GET /SASjsApi/session/{sessionId}/log",
6962
- description: "answers the log this session wrote",
6963
- request: { subject: ADMIN, params: { sessionId: "sess-admin" } },
6964
- expect: {
6965
- status: 200,
6966
- contents: "NOTE: session started\nNOTE: session completed\n"
6967
- }
6968
- },
6969
- {
6970
- id: "session-log-nothing-written",
6971
- route: "GET /SASjsApi/session/{sessionId}/log",
6972
- description: "answers an empty body for a session that has written nothing",
6973
- request: { subject: ADMIN, params: { sessionId: "sess-silent" } },
6974
- expect: { status: 200, contents: "" }
6975
- },
6976
- {
6977
- id: "session-log-unauthenticated",
6978
- route: "GET /SASjsApi/session/{sessionId}/log",
6979
- description: "refuses a caller with no token",
6980
- request: { params: { sessionId: "sess-admin" } },
6981
- expect: { status: 401, error: UNAUTHORIZED }
6982
- },
6983
- {
6984
- id: "session-log-foreign",
6985
- route: "GET /SASjsApi/session/{sessionId}/log",
6986
- description: "will not read another account's log",
6987
- request: { subject: RESTRICTED, params: { sessionId: "sess-admin" } },
6988
- expect: { status: 404, error: notFound("sess-admin") }
6989
- },
6990
- // ----------------------------------------------------------------- output
6991
- {
6992
- id: "session-output-own",
6993
- route: "GET /SASjsApi/session/{sessionId}/output",
6994
- description: "answers the webout this session produced",
6995
- request: { subject: ADMIN, params: { sessionId: "sess-admin" } },
6996
- expect: { status: 200, contents: "<html><body>42</body></html>" }
6997
- },
6998
- {
6999
- id: "session-output-unauthenticated",
7000
- route: "GET /SASjsApi/session/{sessionId}/output",
7001
- description: "refuses a caller with no token",
7002
- request: { params: { sessionId: "sess-admin" } },
7003
- expect: { status: 401, error: UNAUTHORIZED }
7004
- },
7005
- {
7006
- id: "session-output-foreign",
7007
- route: "GET /SASjsApi/session/{sessionId}/output",
7008
- description: "will not read another account's webout",
7009
- request: { subject: RESTRICTED, params: { sessionId: "sess-admin" } },
7010
- expect: { status: 404, error: notFound("sess-admin") }
7011
- },
7012
- // ------------------------------------------------------------------ state
7013
- {
7014
- id: "session-state-own",
7015
- route: "GET /SASjsApi/session/{sessionId}/state",
7016
- description: "answers the run time's state for this session",
7017
- request: { subject: RESTRICTED, params: { sessionId: "sess-restricted" } },
7018
- // the state alone: the document's SessionStateResponse permits no other
7019
- // property, and `sasjs/server` answers exactly this object
7020
- expect: { status: 200, body: { state: "running" } }
7021
- },
7022
- {
7023
- id: "session-state-unauthenticated",
7024
- route: "GET /SASjsApi/session/{sessionId}/state",
7025
- description: "refuses a caller with no token",
7026
- request: { params: { sessionId: "sess-restricted" } },
7027
- expect: { status: 401, error: UNAUTHORIZED }
7028
- },
7029
- {
7030
- id: "session-state-foreign",
7031
- route: "GET /SASjsApi/session/{sessionId}/state",
7032
- description: "will not report another account's session state",
7033
- request: { subject: RESTRICTED, params: { sessionId: "sess-admin" } },
7034
- expect: { status: 404, error: notFound("sess-admin") }
7035
- }
7036
- ];
7037
-
7038
7018
  // src/session/service.ts
7039
7019
  var createSessionService = (directory, host) => {
7040
7020
  const notFound2 = (id) => `Session with ID '${id}' was not found.`;
@@ -7077,101 +7057,43 @@ var SASjsApi = (() => {
7077
7057
  };
7078
7058
  };
7079
7059
 
7080
- // src/session/memory-host.ts
7081
- var DEFAULT_SESSIONS = {
7082
- "sess-admin": {
7083
- owner: "user-admin",
7084
- summary: {
7085
- sessionId: "sess-admin",
7086
- state: "completed",
7087
- pid: 4242,
7088
- creationTimeStamp: "2026-11-07T09:00:00.000Z",
7089
- deathTimeStamp: "2026-11-07T09:00:04.000Z",
7090
- expiresAfterMins: { mins: 60, used: false }
7091
- }
7092
- },
7093
- "sess-restricted": {
7094
- owner: "user-restricted",
7095
- summary: {
7096
- sessionId: "sess-restricted",
7097
- state: "running",
7098
- pid: 4243,
7099
- creationTimeStamp: "2026-11-07T09:05:00.000Z",
7100
- // the document makes both stamps required, and a real session carries
7101
- // the death stamp from the moment it is created: sasjs/server writes
7102
- // creation + its default lifetime, which is what a poller reads to know
7103
- // when the folder will be gone. A running session without one is a shape
7104
- // no host produces.
7105
- deathTimeStamp: "2026-11-07T09:20:00.000Z"
7106
- }
7107
- },
7108
- "sess-silent": {
7109
- owner: "user-admin",
7110
- summary: {
7111
- sessionId: "sess-silent",
7112
- state: "running",
7113
- pid: 4244,
7114
- creationTimeStamp: "2026-11-07T09:10:00.000Z"
7060
+ // src/runtime/runTimes.ts
7061
+ var DOCUMENTED_RUN_TIMES = ["sas", "js", "py", "r", "sasviya"];
7062
+
7063
+ // src/runtime/program.ts
7064
+ var programNotFound = (given2) => `The Program at (${given2}) does not exist.`;
7065
+ var notThere = (given2) => new ApiError(400, programNotFound(given2));
7066
+ var runTimeOfPath = (path) => {
7067
+ const file = path.split(/[\\/]/).pop() || "";
7068
+ const dot = file.lastIndexOf(".");
7069
+ const extension = dot > 0 ? file.slice(dot + 1).toLowerCase() : "";
7070
+ return DOCUMENTED_RUN_TIMES.includes(extension) ? extension : void 0;
7071
+ };
7072
+ var resolveProgram = async (given2, deps) => {
7073
+ const resolved = deps.resolve(given2);
7074
+ if (resolved === null) throw notThere(given2);
7075
+ const extension = runTimeOfPath(resolved);
7076
+ if (extension !== void 0) {
7077
+ if (await deps.exists(resolved))
7078
+ return { path: resolved, runTime: extension };
7079
+ } else {
7080
+ for (const runTime of deps.runTimes) {
7081
+ const candidate = `${resolved}.${runTime}`;
7082
+ if (await deps.exists(candidate)) return { path: candidate, runTime };
7115
7083
  }
7116
7084
  }
7085
+ throw notThere(given2);
7117
7086
  };
7118
- var STATES = {
7119
- // `state` alone: the document's SessionStateResponse allows no other property,
7120
- // and a mock that answered `pid` or a line count would let a case pass here
7121
- // and fail against a server that answers the shape the document states
7122
- "sess-admin": { state: "completed" },
7123
- "sess-restricted": { state: "running" }
7124
- };
7125
- var LOGS = {
7126
- "sess-admin": "NOTE: session started\nNOTE: session completed\n",
7127
- "sess-restricted": "NOTE: session started\n",
7128
- "sess-silent": ""
7129
- };
7130
- var OUTPUTS = {
7131
- "sess-admin": {
7132
- contents: "<html><body>42</body></html>",
7133
- contentType: "text/html"
7134
- },
7135
- "sess-restricted": { contents: "" },
7136
- "sess-silent": { contents: "" }
7137
- };
7138
- var MemorySessionHost = class {
7139
- constructor(sessions = {
7140
- ...DEFAULT_SESSIONS
7141
- }, states = {
7142
- ...STATES
7143
- }, logs = { ...LOGS }, outputs = {
7144
- ...OUTPUTS
7145
- }) {
7146
- this.sessions = sessions;
7147
- this.states = states;
7148
- this.logs = logs;
7149
- this.outputs = outputs;
7150
- }
7151
- async session(id) {
7152
- return this.sessions[id];
7153
- }
7154
- async state(id) {
7155
- return this.states[id];
7156
- }
7157
- async log(id) {
7158
- return this.logs[id];
7159
- }
7160
- async output(id) {
7161
- return this.outputs[id];
7162
- }
7163
- };
7164
-
7165
- // src/runtime/service.ts
7166
- var CODE_DEBUG = 131;
7167
- var DOCUMENTED_RUN_TIMES = ["sas", "js", "py", "r", "sasviya"];
7168
- var parseDebugValue = (value) => {
7169
- if (value === void 0 || value === null || value === "") return void 0;
7170
- if (typeof value === "number")
7171
- return Number.isFinite(value) ? value : void 0;
7172
- const text2 = String(value).trim();
7173
- if (!text2) return void 0;
7174
- return /^[+-]?\d+$/.test(text2) ? Number(text2) : CODE_DEBUG;
7087
+
7088
+ // src/runtime/service.ts
7089
+ var CODE_DEBUG = 131;
7090
+ var parseDebugValue = (value) => {
7091
+ if (value === void 0 || value === null || value === "") return void 0;
7092
+ if (typeof value === "number")
7093
+ return Number.isFinite(value) ? value : void 0;
7094
+ const text2 = String(value).trim();
7095
+ if (!text2) return void 0;
7096
+ return /^[+-]?\d+$/.test(text2) ? Number(text2) : CODE_DEBUG;
7175
7097
  };
7176
7098
  var pad = (value) => String(value).padStart(2, "0");
7177
7099
  var timestamp = (now) => [
@@ -7183,7 +7105,7 @@ var SASjsApi = (() => {
7183
7105
  pad(now.getSeconds())
7184
7106
  ].join("");
7185
7107
  var newSessionId = (now) => `${timestamp(now)}-${Math.round(Math.random() * 1e5)}-${now.getTime()}`;
7186
- var notThere = (programPath) => `The Program at (${programPath}) does not exist.`;
7108
+ var notThere2 = (programPath) => programNotFound(programPath);
7187
7109
  var failedRun = (error) => {
7188
7110
  const message = "Job execution failed.";
7189
7111
  throw new ApiError(400, message, {
@@ -7217,16 +7139,14 @@ var SASjsApi = (() => {
7217
7139
  if (request.program === "")
7218
7140
  throw new ApiError(400, '"_program" is not allowed to be empty');
7219
7141
  const resolved = normaliseDrivePath(request.program);
7220
- if (resolved === null) return failedRun(notThere(request.program));
7142
+ if (resolved === null) return failedRun(notThere2(request.program));
7221
7143
  return { path: resolved };
7222
7144
  };
7223
- const runTimeForPath = (path, request) => {
7224
- const file = path.split("/").pop() || "";
7225
- const dot = file.lastIndexOf(".");
7226
- const extension = dot > 0 ? file.slice(dot + 1).toLowerCase() : "";
7227
- if (DOCUMENTED_RUN_TIMES.includes(extension)) return extension;
7228
- return runTimeOf(request);
7229
- };
7145
+ const runTimeForPath = (path, request) => (
7146
+ // the extension rule is `resolveProgram`'s; this asks it and falls back to what
7147
+ // the request stated, which is the part that is this route's
7148
+ runTimeOfPath(path) ?? runTimeOf(request)
7149
+ );
7230
7150
  const runTimeOf = (request) => {
7231
7151
  if (request.runTime === void 0) {
7232
7152
  if (request.source === "code")
@@ -7310,6 +7230,91 @@ var SASjsApi = (() => {
7310
7230
  };
7311
7231
  };
7312
7232
 
7233
+ // src/session/memory-host.ts
7234
+ var DEFAULT_SESSIONS = {
7235
+ "sess-admin": {
7236
+ owner: "user-admin",
7237
+ summary: {
7238
+ sessionId: "sess-admin",
7239
+ state: "completed",
7240
+ pid: 4242,
7241
+ creationTimeStamp: "2026-11-07T09:00:00.000Z",
7242
+ deathTimeStamp: "2026-11-07T09:00:04.000Z",
7243
+ expiresAfterMins: { mins: 60, used: false }
7244
+ }
7245
+ },
7246
+ "sess-restricted": {
7247
+ owner: "user-restricted",
7248
+ summary: {
7249
+ sessionId: "sess-restricted",
7250
+ state: "running",
7251
+ pid: 4243,
7252
+ creationTimeStamp: "2026-11-07T09:05:00.000Z",
7253
+ // the document makes both stamps required, and a real session carries
7254
+ // the death stamp from the moment it is created: sasjs/server writes
7255
+ // creation + its default lifetime, which is what a poller reads to know
7256
+ // when the folder will be gone. A running session without one is a shape
7257
+ // no host produces.
7258
+ deathTimeStamp: "2026-11-07T09:20:00.000Z"
7259
+ }
7260
+ },
7261
+ "sess-silent": {
7262
+ owner: "user-admin",
7263
+ summary: {
7264
+ sessionId: "sess-silent",
7265
+ state: "running",
7266
+ pid: 4244,
7267
+ creationTimeStamp: "2026-11-07T09:10:00.000Z"
7268
+ }
7269
+ }
7270
+ };
7271
+ var STATES = {
7272
+ // `state` alone: the document's SessionStateResponse allows no other property,
7273
+ // and a mock that answered `pid` or a line count would let a case pass here
7274
+ // and fail against a server that answers the shape the document states
7275
+ "sess-admin": { state: "completed" },
7276
+ "sess-restricted": { state: "running" }
7277
+ };
7278
+ var LOGS = {
7279
+ "sess-admin": "NOTE: session started\nNOTE: session completed\n",
7280
+ "sess-restricted": "NOTE: session started\n",
7281
+ "sess-silent": ""
7282
+ };
7283
+ var OUTPUTS = {
7284
+ "sess-admin": {
7285
+ contents: "<html><body>42</body></html>",
7286
+ contentType: "text/html"
7287
+ },
7288
+ "sess-restricted": { contents: "" },
7289
+ "sess-silent": { contents: "" }
7290
+ };
7291
+ var MemorySessionHost = class {
7292
+ constructor(sessions = {
7293
+ ...DEFAULT_SESSIONS
7294
+ }, states = {
7295
+ ...STATES
7296
+ }, logs = { ...LOGS }, outputs = {
7297
+ ...OUTPUTS
7298
+ }) {
7299
+ this.sessions = sessions;
7300
+ this.states = states;
7301
+ this.logs = logs;
7302
+ this.outputs = outputs;
7303
+ }
7304
+ async session(id) {
7305
+ return this.sessions[id];
7306
+ }
7307
+ async state(id) {
7308
+ return this.states[id];
7309
+ }
7310
+ async log(id) {
7311
+ return this.logs[id];
7312
+ }
7313
+ async output(id) {
7314
+ return this.outputs[id];
7315
+ }
7316
+ };
7317
+
7313
7318
  // src/runtime/memory-runner.ts
7314
7319
  var MemorySessionRunner = class extends MemorySessionHost {
7315
7320
  constructor(options = {}) {
@@ -7344,6 +7349,288 @@ var SASjsApi = (() => {
7344
7349
  }
7345
7350
  };
7346
7351
 
7352
+ // src/corpus/runner.ts
7353
+ var CORPUS_APP = {
7354
+ id: "6f1c1c1e-6a1e-4c4a-9d1a-1b2c3d4e5f60",
7355
+ name: "myApp",
7356
+ appLoc: "/Public/myApp",
7357
+ streamWebFolder: "web",
7358
+ publishedAt: "2026-01-01T00:00:00.000Z"
7359
+ };
7360
+ var servicesFor = (testCase) => {
7361
+ const identity = new MemoryIdentityStore(
7362
+ testCase.identity || DEFAULT_IDENTITY
7363
+ );
7364
+ const runner = new MemorySessionRunner({
7365
+ fail: testCase.failingRun,
7366
+ outputs: testCase.runOutput ? { [programOf(testCase)]: testCase.runOutput } : void 0
7367
+ });
7368
+ return {
7369
+ drive: createDriveService(
7370
+ testCase.unwritable ? new RefusingDriveStore(testCase.seed || {}) : new MemoryDriveStore(testCase.seed || {})
7371
+ ),
7372
+ info: createInfoService(BROWSER_INFO),
7373
+ home: createHomeService(async () => CORPUS_WEB_PAGE),
7374
+ authConfig: createAuthConfigService(CORPUS_AUTH_CONFIG),
7375
+ admin: createAdminService({
7376
+ diagnostics: async () => CORPUS_DIAGNOSTICS,
7377
+ logs: async () => [CORPUS_LOG],
7378
+ logTail: async (fileName) => fileName === CORPUS_LOG.name ? CORPUS_LOG_TAIL : void 0
7379
+ }),
7380
+ directory: createDirectoryService(identity, CORPUS_DIRECTORY),
7381
+ identity: createIdentityService(identity),
7382
+ records: createRecordService(identity),
7383
+ appStream: createAppStreamService(new MemoryAppStreamStore([CORPUS_APP])),
7384
+ session: createSessionService(identity, runner),
7385
+ // no `runTimes` option: the default is the five the document names, so a
7386
+ // case is never refused for a reason that belongs to one host's install
7387
+ runtime: createRuntimeService(identity, runner)
7388
+ };
7389
+ };
7390
+ var programOf = (testCase) => String(
7391
+ testCase.request.query?._program ?? testCase.request.body?._program ?? testCase.request.body?.code ?? ""
7392
+ );
7393
+ var RefusingDriveStore = class extends MemoryDriveStore {
7394
+ async write() {
7395
+ throw new Error("the store refused the write");
7396
+ }
7397
+ async mkdirp() {
7398
+ throw new Error("the store refused the write");
7399
+ }
7400
+ };
7401
+ var checkDrive = async (testCase, services) => {
7402
+ if (!testCase.expectDrive || !services.drive) return;
7403
+ const holds = async (path) => {
7404
+ try {
7405
+ await services.drive.read(path);
7406
+ return true;
7407
+ } catch (e) {
7408
+ return false;
7409
+ }
7410
+ };
7411
+ for (const path of testCase.expectDrive.present || [])
7412
+ if (!await holds(path))
7413
+ throw new Error(
7414
+ `${testCase.id}: expected a file at ${path}, and the drive has none`
7415
+ );
7416
+ for (const path of testCase.expectDrive.missing || [])
7417
+ if (await holds(path))
7418
+ throw new Error(
7419
+ `${testCase.id}: expected no file at ${path}, and the drive still holds one`
7420
+ );
7421
+ };
7422
+ var runCase = async (testCase, services = servicesFor(testCase)) => {
7423
+ try {
7424
+ const response = await dispatch(services, testCase.route, testCase.request);
7425
+ await checkDrive(testCase, services);
7426
+ return {
7427
+ status: response.status,
7428
+ body: response.body,
7429
+ contents: response.contents
7430
+ };
7431
+ } catch (error) {
7432
+ if (isApiError(error))
7433
+ return { status: error.status, body: error.body, error: error.message };
7434
+ throw error;
7435
+ }
7436
+ };
7437
+
7438
+ // src/corpus/app.ts
7439
+ var SUBJECT2 = { userId: "user-admin", clientId: "web_app" };
7440
+ var ENTRY_FILE_PATH = `${CORPUS_APP.appLoc}/services/${CORPUS_APP.streamWebFolder}/index.html`;
7441
+ var APP_CORPUS = [
7442
+ {
7443
+ id: "app-detail-published",
7444
+ route: "GET /SASjsApi/app/{id}",
7445
+ description: "describes the app the id names, and the entry file it is served from",
7446
+ // the deployment the index entry points at: the entry file is on the drive, so
7447
+ // `entryFileExists` is the answer this case is really about
7448
+ seed: { [ENTRY_FILE_PATH]: "<!doctype html><title>app</title>" },
7449
+ request: { subject: SUBJECT2, params: { id: CORPUS_APP.id } },
7450
+ expect: {
7451
+ status: 200,
7452
+ // the entry as registered, and the file it is served from. `lastModified` is
7453
+ // the host's clock and not pinned: a drive with no clock answers `null`, one
7454
+ // with a filesystem answers the time the seed was written.
7455
+ partial: {
7456
+ id: CORPUS_APP.id,
7457
+ name: CORPUS_APP.name,
7458
+ appLoc: CORPUS_APP.appLoc,
7459
+ streamWebFolder: CORPUS_APP.streamWebFolder,
7460
+ publishedAt: CORPUS_APP.publishedAt,
7461
+ entryFile: "index.html",
7462
+ entryFileExists: true,
7463
+ url: `/app/${CORPUS_APP.id}/`
7464
+ }
7465
+ }
7466
+ },
7467
+ {
7468
+ id: "app-detail-entry-file-missing",
7469
+ route: "GET /SASjsApi/app/{id}",
7470
+ description: "answers the entry as registered with no file and no date, for a deployment that is gone",
7471
+ // the index entry outlived its folder: no seed, so nothing is deployed
7472
+ request: { subject: SUBJECT2, params: { id: CORPUS_APP.id } },
7473
+ expect: {
7474
+ status: 200,
7475
+ partial: { entryFileExists: false, lastModified: null }
7476
+ }
7477
+ },
7478
+ {
7479
+ id: "app-detail-unknown-id",
7480
+ route: "GET /SASjsApi/app/{id}",
7481
+ description: "refuses an id the index does not hold, in the route’s own wording",
7482
+ request: {
7483
+ subject: SUBJECT2,
7484
+ params: { id: "9a9a9a9a-9a9a-4a9a-8a9a-9a9a9a9a9a9a" }
7485
+ },
7486
+ expect: { status: 404, error: "No App Stream is registered with that id." }
7487
+ }
7488
+ ];
7489
+
7490
+ // src/corpus/session.ts
7491
+ var ADMIN = { userId: "user-admin", clientId: "web_app" };
7492
+ var RESTRICTED = { userId: "user-restricted", clientId: "web_app" };
7493
+ var notFound = (id) => `Session with ID '${id}' was not found.`;
7494
+ var UNAUTHORIZED = "Unauthorized";
7495
+ var SESSION_CORPUS = [
7496
+ // ---------------------------------------------------------------- summary
7497
+ {
7498
+ id: "session-summary-own",
7499
+ route: "GET /SASjsApi/session/{sessionId}",
7500
+ description: "answers the owner the summary of their own session",
7501
+ request: { subject: ADMIN, params: { sessionId: "sess-admin" } },
7502
+ expect: {
7503
+ status: 200,
7504
+ body: {
7505
+ sessionId: "sess-admin",
7506
+ state: "completed",
7507
+ pid: 4242,
7508
+ creationTimeStamp: "2026-11-07T09:00:00.000Z",
7509
+ deathTimeStamp: "2026-11-07T09:00:04.000Z",
7510
+ expiresAfterMins: { mins: 60, used: false }
7511
+ }
7512
+ }
7513
+ },
7514
+ {
7515
+ id: "session-summary-as-admin",
7516
+ route: "GET /SASjsApi/session/{sessionId}",
7517
+ description: "answers an administrator another account's session",
7518
+ request: { subject: ADMIN, params: { sessionId: "sess-restricted" } },
7519
+ // both stamps: the document requires them, and this host stamps a session's
7520
+ // death time at creation rather than at completion - a running session
7521
+ // answers with the moment it is due to be destroyed
7522
+ expect: {
7523
+ status: 200,
7524
+ body: {
7525
+ sessionId: "sess-restricted",
7526
+ state: "running",
7527
+ pid: 4243,
7528
+ creationTimeStamp: "2026-11-07T09:05:00.000Z",
7529
+ deathTimeStamp: "2026-11-07T09:20:00.000Z"
7530
+ }
7531
+ }
7532
+ },
7533
+ {
7534
+ id: "session-summary-unauthenticated",
7535
+ route: "GET /SASjsApi/session/{sessionId}",
7536
+ description: "refuses a caller with no token",
7537
+ request: { params: { sessionId: "sess-admin" } },
7538
+ expect: { status: 401, error: UNAUTHORIZED }
7539
+ },
7540
+ {
7541
+ id: "session-summary-foreign",
7542
+ route: "GET /SASjsApi/session/{sessionId}",
7543
+ description: "answers 404 for another account's session, not 403",
7544
+ request: { subject: RESTRICTED, params: { sessionId: "sess-admin" } },
7545
+ expect: { status: 404, error: notFound("sess-admin") }
7546
+ },
7547
+ {
7548
+ id: "session-summary-unknown",
7549
+ route: "GET /SASjsApi/session/{sessionId}",
7550
+ description: "answers the same 404 for a session that does not exist",
7551
+ request: { subject: ADMIN, params: { sessionId: "sess-nope" } },
7552
+ expect: { status: 404, error: notFound("sess-nope") }
7553
+ },
7554
+ // -------------------------------------------------------------------- log
7555
+ {
7556
+ id: "session-log-own",
7557
+ route: "GET /SASjsApi/session/{sessionId}/log",
7558
+ description: "answers the log this session wrote",
7559
+ request: { subject: ADMIN, params: { sessionId: "sess-admin" } },
7560
+ expect: {
7561
+ status: 200,
7562
+ contents: "NOTE: session started\nNOTE: session completed\n"
7563
+ }
7564
+ },
7565
+ {
7566
+ id: "session-log-nothing-written",
7567
+ route: "GET /SASjsApi/session/{sessionId}/log",
7568
+ description: "answers an empty body for a session that has written nothing",
7569
+ request: { subject: ADMIN, params: { sessionId: "sess-silent" } },
7570
+ expect: { status: 200, contents: "" }
7571
+ },
7572
+ {
7573
+ id: "session-log-unauthenticated",
7574
+ route: "GET /SASjsApi/session/{sessionId}/log",
7575
+ description: "refuses a caller with no token",
7576
+ request: { params: { sessionId: "sess-admin" } },
7577
+ expect: { status: 401, error: UNAUTHORIZED }
7578
+ },
7579
+ {
7580
+ id: "session-log-foreign",
7581
+ route: "GET /SASjsApi/session/{sessionId}/log",
7582
+ description: "will not read another account's log",
7583
+ request: { subject: RESTRICTED, params: { sessionId: "sess-admin" } },
7584
+ expect: { status: 404, error: notFound("sess-admin") }
7585
+ },
7586
+ // ----------------------------------------------------------------- output
7587
+ {
7588
+ id: "session-output-own",
7589
+ route: "GET /SASjsApi/session/{sessionId}/output",
7590
+ description: "answers the webout this session produced",
7591
+ request: { subject: ADMIN, params: { sessionId: "sess-admin" } },
7592
+ expect: { status: 200, contents: "<html><body>42</body></html>" }
7593
+ },
7594
+ {
7595
+ id: "session-output-unauthenticated",
7596
+ route: "GET /SASjsApi/session/{sessionId}/output",
7597
+ description: "refuses a caller with no token",
7598
+ request: { params: { sessionId: "sess-admin" } },
7599
+ expect: { status: 401, error: UNAUTHORIZED }
7600
+ },
7601
+ {
7602
+ id: "session-output-foreign",
7603
+ route: "GET /SASjsApi/session/{sessionId}/output",
7604
+ description: "will not read another account's webout",
7605
+ request: { subject: RESTRICTED, params: { sessionId: "sess-admin" } },
7606
+ expect: { status: 404, error: notFound("sess-admin") }
7607
+ },
7608
+ // ------------------------------------------------------------------ state
7609
+ {
7610
+ id: "session-state-own",
7611
+ route: "GET /SASjsApi/session/{sessionId}/state",
7612
+ description: "answers the run time's state for this session",
7613
+ request: { subject: RESTRICTED, params: { sessionId: "sess-restricted" } },
7614
+ // the state alone: the document's SessionStateResponse permits no other
7615
+ // property, and `sasjs/server` answers exactly this object
7616
+ expect: { status: 200, body: { state: "running" } }
7617
+ },
7618
+ {
7619
+ id: "session-state-unauthenticated",
7620
+ route: "GET /SASjsApi/session/{sessionId}/state",
7621
+ description: "refuses a caller with no token",
7622
+ request: { params: { sessionId: "sess-restricted" } },
7623
+ expect: { status: 401, error: UNAUTHORIZED }
7624
+ },
7625
+ {
7626
+ id: "session-state-foreign",
7627
+ route: "GET /SASjsApi/session/{sessionId}/state",
7628
+ description: "will not report another account's session state",
7629
+ request: { subject: RESTRICTED, params: { sessionId: "sess-admin" } },
7630
+ expect: { status: 404, error: notFound("sess-admin") }
7631
+ }
7632
+ ];
7633
+
7347
7634
  // src/corpus/runtime.ts
7348
7635
  var ADMIN2 = { userId: "user-admin", clientId: "web_app" };
7349
7636
  var PROGRAM = "/Public/apps/demo/run.sas";
@@ -8824,92 +9111,6 @@ var SASjsApi = (() => {
8824
9111
  }
8825
9112
  ];
8826
9113
 
8827
- // src/corpus/runner.ts
8828
- var CORPUS_APP = {
8829
- id: "6f1c1c1e-6a1e-4c4a-9d1a-1b2c3d4e5f60",
8830
- name: "myApp",
8831
- appLoc: "/Public/myApp",
8832
- streamWebFolder: "web",
8833
- publishedAt: "2026-01-01T00:00:00.000Z"
8834
- };
8835
- var servicesFor = (testCase) => {
8836
- const identity = new MemoryIdentityStore(
8837
- testCase.identity || DEFAULT_IDENTITY
8838
- );
8839
- const runner = new MemorySessionRunner({
8840
- fail: testCase.failingRun,
8841
- outputs: testCase.runOutput ? { [programOf(testCase)]: testCase.runOutput } : void 0
8842
- });
8843
- return {
8844
- drive: createDriveService(
8845
- testCase.unwritable ? new RefusingDriveStore(testCase.seed || {}) : new MemoryDriveStore(testCase.seed || {})
8846
- ),
8847
- info: createInfoService(BROWSER_INFO),
8848
- home: createHomeService(async () => CORPUS_WEB_PAGE),
8849
- authConfig: createAuthConfigService(CORPUS_AUTH_CONFIG),
8850
- admin: createAdminService({
8851
- diagnostics: async () => CORPUS_DIAGNOSTICS,
8852
- logs: async () => [CORPUS_LOG],
8853
- logTail: async (fileName) => fileName === CORPUS_LOG.name ? CORPUS_LOG_TAIL : void 0
8854
- }),
8855
- directory: createDirectoryService(identity, CORPUS_DIRECTORY),
8856
- identity: createIdentityService(identity),
8857
- records: createRecordService(identity),
8858
- appStream: createAppStreamService(new MemoryAppStreamStore([CORPUS_APP])),
8859
- session: createSessionService(identity, runner),
8860
- // no `runTimes` option: the default is the five the document names, so a
8861
- // case is never refused for a reason that belongs to one host's install
8862
- runtime: createRuntimeService(identity, runner)
8863
- };
8864
- };
8865
- var programOf = (testCase) => String(
8866
- testCase.request.query?._program ?? testCase.request.body?._program ?? testCase.request.body?.code ?? ""
8867
- );
8868
- var RefusingDriveStore = class extends MemoryDriveStore {
8869
- async write() {
8870
- throw new Error("the store refused the write");
8871
- }
8872
- async mkdirp() {
8873
- throw new Error("the store refused the write");
8874
- }
8875
- };
8876
- var checkDrive = async (testCase, services) => {
8877
- if (!testCase.expectDrive || !services.drive) return;
8878
- const holds = async (path) => {
8879
- try {
8880
- await services.drive.read(path);
8881
- return true;
8882
- } catch (e) {
8883
- return false;
8884
- }
8885
- };
8886
- for (const path of testCase.expectDrive.present || [])
8887
- if (!await holds(path))
8888
- throw new Error(
8889
- `${testCase.id}: expected a file at ${path}, and the drive has none`
8890
- );
8891
- for (const path of testCase.expectDrive.missing || [])
8892
- if (await holds(path))
8893
- throw new Error(
8894
- `${testCase.id}: expected no file at ${path}, and the drive still holds one`
8895
- );
8896
- };
8897
- var runCase = async (testCase, services = servicesFor(testCase)) => {
8898
- try {
8899
- const response = await dispatch(services, testCase.route, testCase.request);
8900
- await checkDrive(testCase, services);
8901
- return {
8902
- status: response.status,
8903
- body: response.body,
8904
- contents: response.contents
8905
- };
8906
- } catch (error) {
8907
- if (isApiError(error))
8908
- return { status: error.status, body: error.body, error: error.message };
8909
- throw error;
8910
- }
8911
- };
8912
-
8913
9114
  // src/appstream/store.ts
8914
9115
  var APP_STREAM_INDEX = "/.sasjs/apps.json";
8915
9116
  var isEntry = (value) => {