@sasjs/api 0.29.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 (41) hide show
  1. package/build/browser.js +559 -325
  2. package/build/cjs/appstream/service.js +48 -5
  3. package/build/cjs/appstream/web.js +7 -3
  4. package/build/cjs/corpus/app.js +55 -0
  5. package/build/cjs/corpus/runner.js +7 -6
  6. package/build/cjs/host/dispatch.js +71 -0
  7. package/build/cjs/index.js +9 -2
  8. package/build/cjs/routes/generated.js +34 -0
  9. package/build/cjs/routes/overlay.js +34 -1
  10. package/build/cjs/runtime/program.js +85 -0
  11. package/build/cjs/runtime/runTimes.js +13 -0
  12. package/build/cjs/runtime/service.js +11 -13
  13. package/build/esm/appstream/service.d.ts.map +1 -1
  14. package/build/esm/appstream/service.js +48 -5
  15. package/build/esm/appstream/web.d.ts.map +1 -1
  16. package/build/esm/appstream/web.js +7 -3
  17. package/build/esm/corpus/app.d.ts +17 -0
  18. package/build/esm/corpus/app.d.ts.map +1 -0
  19. package/build/esm/corpus/app.js +52 -0
  20. package/build/esm/corpus/runner.d.ts +13 -0
  21. package/build/esm/corpus/runner.d.ts.map +1 -1
  22. package/build/esm/corpus/runner.js +5 -4
  23. package/build/esm/host/dispatch.d.ts.map +1 -1
  24. package/build/esm/host/dispatch.js +72 -1
  25. package/build/esm/index.d.ts +5 -1
  26. package/build/esm/index.d.ts.map +1 -1
  27. package/build/esm/index.js +4 -1
  28. package/build/esm/routes/generated.d.ts.map +1 -1
  29. package/build/esm/routes/generated.js +34 -0
  30. package/build/esm/routes/overlay.d.ts.map +1 -1
  31. package/build/esm/routes/overlay.js +34 -1
  32. package/build/esm/runtime/program.d.ts +56 -0
  33. package/build/esm/runtime/program.d.ts.map +1 -0
  34. package/build/esm/runtime/program.js +79 -0
  35. package/build/esm/runtime/runTimes.d.ts +11 -0
  36. package/build/esm/runtime/runTimes.d.ts.map +1 -0
  37. package/build/esm/runtime/runTimes.js +10 -0
  38. package/build/esm/runtime/service.d.ts +0 -2
  39. package/build/esm/runtime/service.d.ts.map +1 -1
  40. package/build/esm/runtime/service.js +9 -11
  41. package/package.json +1 -1
package/build/browser.js CHANGED
@@ -1,4 +1,4 @@
1
- /* @sasjs/api 0.29.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 },
@@ -3231,7 +3302,28 @@ var SASjsApi = (() => {
3231
3302
  if (value === void 0) return defaultAppName(appLoc);
3232
3303
  if (typeof value !== "string" || value.trim() === "")
3233
3304
  throw new ApiError(400, '"name" must be a non-empty string');
3234
- return value.trim();
3305
+ return urlSafeName(value.trim());
3306
+ };
3307
+ var NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._~-]*$/;
3308
+ var NAME_MAX_LENGTH = 64;
3309
+ var RESERVED_NAMES = ["apps.json", "index.html"];
3310
+ var urlSafeName = (name) => {
3311
+ if (name.length > NAME_MAX_LENGTH)
3312
+ throw new ApiError(
3313
+ 400,
3314
+ `"name" must be at most ${NAME_MAX_LENGTH} characters, and "${name}" is ${name.length}.`
3315
+ );
3316
+ if (!NAME_PATTERN.test(name))
3317
+ throw new ApiError(
3318
+ 400,
3319
+ `"name" must be usable as a URL segment - letters, digits, dot, dash, underscore or tilde, starting with a letter or digit - so "/app/${name}" can be opened. "${name}" is not, because it carries a character that has to be percent-encoded, or a space.`
3320
+ );
3321
+ if (RESERVED_NAMES.includes(name.toLowerCase()))
3322
+ throw new ApiError(
3323
+ 400,
3324
+ `"name" cannot be "${name}": the App Stream answers /app/${name} itself, so an app with that name could never be opened by name.`
3325
+ );
3326
+ return name;
3235
3327
  };
3236
3328
  var logoOf = (value) => {
3237
3329
  if (value === void 0) return void 0;
@@ -3291,11 +3383,23 @@ var SASjsApi = (() => {
3291
3383
  );
3292
3384
  const logo = checked.logo;
3293
3385
  const frameAncestors = checked.frameAncestors;
3386
+ const statedName = checked.name;
3387
+ const name = statedName !== void 0 ? nameOf(statedName, appLoc) : existing?.name ?? nameOf(void 0, appLoc);
3388
+ if (statedName !== void 0) {
3389
+ const clash = entries.find(
3390
+ (candidate) => !sameAppLoc(candidate.appLoc, appLoc) && candidate.name.toLowerCase() === name.toLowerCase()
3391
+ );
3392
+ if (clash)
3393
+ throw new ApiError(
3394
+ 409,
3395
+ `The name "${name}" is already the address of the app published at ${clash.appLoc}. A stated name is how the app opens (/app/${name}), and two apps holding one name would answer an ambiguous lookup with nothing, so publish this one under a different name.`
3396
+ );
3397
+ }
3294
3398
  const entry = {
3295
3399
  id: existing ? existing.id : newAppId(),
3296
3400
  // the label is the one field a redeploy inherits: everything else is
3297
3401
  // what this publish states
3298
- name: nameOf(checked.name ?? existing?.name, appLoc),
3402
+ name,
3299
3403
  appLoc,
3300
3404
  streamWebFolder,
3301
3405
  ...logo === void 0 ? {} : { logo },
@@ -3446,6 +3550,12 @@ var SASjsApi = (() => {
3446
3550
  throw new ApiError(400, `"${param.name}" is not allowed to be empty`);
3447
3551
  }
3448
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
+ });
3449
3559
  var targetPath = (request) => {
3450
3560
  const fromQuery = request.query?._filePath;
3451
3561
  const fromBody = request.body?.filePath;
@@ -3711,6 +3821,52 @@ var SASjsApi = (() => {
3711
3821
  body: { status: "success", app: appSummary(removed) }
3712
3822
  };
3713
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
+ }
3714
3870
  case "GET /SASjsApi/drive/filetree":
3715
3871
  return { status: 200, body: await drive.tree(query._folderPath) };
3716
3872
  // ------------------------------------------------------------- run times
@@ -4050,6 +4206,7 @@ var SASjsApi = (() => {
4050
4206
  "DELETE /SASjsApi/drive/folder",
4051
4207
  "POST /SASjsApi/drive/rename",
4052
4208
  "GET /SASjsApi/drive/filetree",
4209
+ "GET /SASjsApi/app/{id}",
4053
4210
  "POST /SASjsApi/drive/deploy",
4054
4211
  "POST /SASjsApi/auth/token",
4055
4212
  "POST /SASjsApi/auth/refresh",
@@ -6858,150 +7015,6 @@ var SASjsApi = (() => {
6858
7015
  }
6859
7016
  ];
6860
7017
 
6861
- // src/corpus/session.ts
6862
- var ADMIN = { userId: "user-admin", clientId: "web_app" };
6863
- var RESTRICTED = { userId: "user-restricted", clientId: "web_app" };
6864
- var notFound = (id) => `Session with ID '${id}' was not found.`;
6865
- var UNAUTHORIZED = "Unauthorized";
6866
- var SESSION_CORPUS = [
6867
- // ---------------------------------------------------------------- summary
6868
- {
6869
- id: "session-summary-own",
6870
- route: "GET /SASjsApi/session/{sessionId}",
6871
- description: "answers the owner the summary of their own session",
6872
- request: { subject: ADMIN, params: { sessionId: "sess-admin" } },
6873
- expect: {
6874
- status: 200,
6875
- body: {
6876
- sessionId: "sess-admin",
6877
- state: "completed",
6878
- pid: 4242,
6879
- creationTimeStamp: "2026-11-07T09:00:00.000Z",
6880
- deathTimeStamp: "2026-11-07T09:00:04.000Z",
6881
- expiresAfterMins: { mins: 60, used: false }
6882
- }
6883
- }
6884
- },
6885
- {
6886
- id: "session-summary-as-admin",
6887
- route: "GET /SASjsApi/session/{sessionId}",
6888
- description: "answers an administrator another account's session",
6889
- request: { subject: ADMIN, params: { sessionId: "sess-restricted" } },
6890
- // both stamps: the document requires them, and this host stamps a session's
6891
- // death time at creation rather than at completion - a running session
6892
- // answers with the moment it is due to be destroyed
6893
- expect: {
6894
- status: 200,
6895
- body: {
6896
- sessionId: "sess-restricted",
6897
- state: "running",
6898
- pid: 4243,
6899
- creationTimeStamp: "2026-11-07T09:05:00.000Z",
6900
- deathTimeStamp: "2026-11-07T09:20:00.000Z"
6901
- }
6902
- }
6903
- },
6904
- {
6905
- id: "session-summary-unauthenticated",
6906
- route: "GET /SASjsApi/session/{sessionId}",
6907
- description: "refuses a caller with no token",
6908
- request: { params: { sessionId: "sess-admin" } },
6909
- expect: { status: 401, error: UNAUTHORIZED }
6910
- },
6911
- {
6912
- id: "session-summary-foreign",
6913
- route: "GET /SASjsApi/session/{sessionId}",
6914
- description: "answers 404 for another account's session, not 403",
6915
- request: { subject: RESTRICTED, params: { sessionId: "sess-admin" } },
6916
- expect: { status: 404, error: notFound("sess-admin") }
6917
- },
6918
- {
6919
- id: "session-summary-unknown",
6920
- route: "GET /SASjsApi/session/{sessionId}",
6921
- description: "answers the same 404 for a session that does not exist",
6922
- request: { subject: ADMIN, params: { sessionId: "sess-nope" } },
6923
- expect: { status: 404, error: notFound("sess-nope") }
6924
- },
6925
- // -------------------------------------------------------------------- log
6926
- {
6927
- id: "session-log-own",
6928
- route: "GET /SASjsApi/session/{sessionId}/log",
6929
- description: "answers the log this session wrote",
6930
- request: { subject: ADMIN, params: { sessionId: "sess-admin" } },
6931
- expect: {
6932
- status: 200,
6933
- contents: "NOTE: session started\nNOTE: session completed\n"
6934
- }
6935
- },
6936
- {
6937
- id: "session-log-nothing-written",
6938
- route: "GET /SASjsApi/session/{sessionId}/log",
6939
- description: "answers an empty body for a session that has written nothing",
6940
- request: { subject: ADMIN, params: { sessionId: "sess-silent" } },
6941
- expect: { status: 200, contents: "" }
6942
- },
6943
- {
6944
- id: "session-log-unauthenticated",
6945
- route: "GET /SASjsApi/session/{sessionId}/log",
6946
- description: "refuses a caller with no token",
6947
- request: { params: { sessionId: "sess-admin" } },
6948
- expect: { status: 401, error: UNAUTHORIZED }
6949
- },
6950
- {
6951
- id: "session-log-foreign",
6952
- route: "GET /SASjsApi/session/{sessionId}/log",
6953
- description: "will not read another account's log",
6954
- request: { subject: RESTRICTED, params: { sessionId: "sess-admin" } },
6955
- expect: { status: 404, error: notFound("sess-admin") }
6956
- },
6957
- // ----------------------------------------------------------------- output
6958
- {
6959
- id: "session-output-own",
6960
- route: "GET /SASjsApi/session/{sessionId}/output",
6961
- description: "answers the webout this session produced",
6962
- request: { subject: ADMIN, params: { sessionId: "sess-admin" } },
6963
- expect: { status: 200, contents: "<html><body>42</body></html>" }
6964
- },
6965
- {
6966
- id: "session-output-unauthenticated",
6967
- route: "GET /SASjsApi/session/{sessionId}/output",
6968
- description: "refuses a caller with no token",
6969
- request: { params: { sessionId: "sess-admin" } },
6970
- expect: { status: 401, error: UNAUTHORIZED }
6971
- },
6972
- {
6973
- id: "session-output-foreign",
6974
- route: "GET /SASjsApi/session/{sessionId}/output",
6975
- description: "will not read another account's webout",
6976
- request: { subject: RESTRICTED, params: { sessionId: "sess-admin" } },
6977
- expect: { status: 404, error: notFound("sess-admin") }
6978
- },
6979
- // ------------------------------------------------------------------ state
6980
- {
6981
- id: "session-state-own",
6982
- route: "GET /SASjsApi/session/{sessionId}/state",
6983
- description: "answers the run time's state for this session",
6984
- request: { subject: RESTRICTED, params: { sessionId: "sess-restricted" } },
6985
- // the state alone: the document's SessionStateResponse permits no other
6986
- // property, and `sasjs/server` answers exactly this object
6987
- expect: { status: 200, body: { state: "running" } }
6988
- },
6989
- {
6990
- id: "session-state-unauthenticated",
6991
- route: "GET /SASjsApi/session/{sessionId}/state",
6992
- description: "refuses a caller with no token",
6993
- request: { params: { sessionId: "sess-restricted" } },
6994
- expect: { status: 401, error: UNAUTHORIZED }
6995
- },
6996
- {
6997
- id: "session-state-foreign",
6998
- route: "GET /SASjsApi/session/{sessionId}/state",
6999
- description: "will not report another account's session state",
7000
- request: { subject: RESTRICTED, params: { sessionId: "sess-admin" } },
7001
- expect: { status: 404, error: notFound("sess-admin") }
7002
- }
7003
- ];
7004
-
7005
7018
  // src/session/service.ts
7006
7019
  var createSessionService = (directory, host) => {
7007
7020
  const notFound2 = (id) => `Session with ID '${id}' was not found.`;
@@ -7044,94 +7057,36 @@ var SASjsApi = (() => {
7044
7057
  };
7045
7058
  };
7046
7059
 
7047
- // src/session/memory-host.ts
7048
- var DEFAULT_SESSIONS = {
7049
- "sess-admin": {
7050
- owner: "user-admin",
7051
- summary: {
7052
- sessionId: "sess-admin",
7053
- state: "completed",
7054
- pid: 4242,
7055
- creationTimeStamp: "2026-11-07T09:00:00.000Z",
7056
- deathTimeStamp: "2026-11-07T09:00:04.000Z",
7057
- expiresAfterMins: { mins: 60, used: false }
7058
- }
7059
- },
7060
- "sess-restricted": {
7061
- owner: "user-restricted",
7062
- summary: {
7063
- sessionId: "sess-restricted",
7064
- state: "running",
7065
- pid: 4243,
7066
- creationTimeStamp: "2026-11-07T09:05:00.000Z",
7067
- // the document makes both stamps required, and a real session carries
7068
- // the death stamp from the moment it is created: sasjs/server writes
7069
- // creation + its default lifetime, which is what a poller reads to know
7070
- // when the folder will be gone. A running session without one is a shape
7071
- // no host produces.
7072
- deathTimeStamp: "2026-11-07T09:20:00.000Z"
7073
- }
7074
- },
7075
- "sess-silent": {
7076
- owner: "user-admin",
7077
- summary: {
7078
- sessionId: "sess-silent",
7079
- state: "running",
7080
- pid: 4244,
7081
- 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 };
7082
7083
  }
7083
7084
  }
7084
- };
7085
- var STATES = {
7086
- // `state` alone: the document's SessionStateResponse allows no other property,
7087
- // and a mock that answered `pid` or a line count would let a case pass here
7088
- // and fail against a server that answers the shape the document states
7089
- "sess-admin": { state: "completed" },
7090
- "sess-restricted": { state: "running" }
7091
- };
7092
- var LOGS = {
7093
- "sess-admin": "NOTE: session started\nNOTE: session completed\n",
7094
- "sess-restricted": "NOTE: session started\n",
7095
- "sess-silent": ""
7096
- };
7097
- var OUTPUTS = {
7098
- "sess-admin": {
7099
- contents: "<html><body>42</body></html>",
7100
- contentType: "text/html"
7101
- },
7102
- "sess-restricted": { contents: "" },
7103
- "sess-silent": { contents: "" }
7104
- };
7105
- var MemorySessionHost = class {
7106
- constructor(sessions = {
7107
- ...DEFAULT_SESSIONS
7108
- }, states = {
7109
- ...STATES
7110
- }, logs = { ...LOGS }, outputs = {
7111
- ...OUTPUTS
7112
- }) {
7113
- this.sessions = sessions;
7114
- this.states = states;
7115
- this.logs = logs;
7116
- this.outputs = outputs;
7117
- }
7118
- async session(id) {
7119
- return this.sessions[id];
7120
- }
7121
- async state(id) {
7122
- return this.states[id];
7123
- }
7124
- async log(id) {
7125
- return this.logs[id];
7126
- }
7127
- async output(id) {
7128
- return this.outputs[id];
7129
- }
7085
+ throw notThere(given2);
7130
7086
  };
7131
7087
 
7132
7088
  // src/runtime/service.ts
7133
7089
  var CODE_DEBUG = 131;
7134
- var DOCUMENTED_RUN_TIMES = ["sas", "js", "py", "r", "sasviya"];
7135
7090
  var parseDebugValue = (value) => {
7136
7091
  if (value === void 0 || value === null || value === "") return void 0;
7137
7092
  if (typeof value === "number")
@@ -7150,7 +7105,7 @@ var SASjsApi = (() => {
7150
7105
  pad(now.getSeconds())
7151
7106
  ].join("");
7152
7107
  var newSessionId = (now) => `${timestamp(now)}-${Math.round(Math.random() * 1e5)}-${now.getTime()}`;
7153
- var notThere = (programPath) => `The Program at (${programPath}) does not exist.`;
7108
+ var notThere2 = (programPath) => programNotFound(programPath);
7154
7109
  var failedRun = (error) => {
7155
7110
  const message = "Job execution failed.";
7156
7111
  throw new ApiError(400, message, {
@@ -7184,16 +7139,14 @@ var SASjsApi = (() => {
7184
7139
  if (request.program === "")
7185
7140
  throw new ApiError(400, '"_program" is not allowed to be empty');
7186
7141
  const resolved = normaliseDrivePath(request.program);
7187
- if (resolved === null) return failedRun(notThere(request.program));
7142
+ if (resolved === null) return failedRun(notThere2(request.program));
7188
7143
  return { path: resolved };
7189
7144
  };
7190
- const runTimeForPath = (path, request) => {
7191
- const file = path.split("/").pop() || "";
7192
- const dot = file.lastIndexOf(".");
7193
- const extension = dot > 0 ? file.slice(dot + 1).toLowerCase() : "";
7194
- if (DOCUMENTED_RUN_TIMES.includes(extension)) return extension;
7195
- return runTimeOf(request);
7196
- };
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
+ );
7197
7150
  const runTimeOf = (request) => {
7198
7151
  if (request.runTime === void 0) {
7199
7152
  if (request.source === "code")
@@ -7277,6 +7230,91 @@ var SASjsApi = (() => {
7277
7230
  };
7278
7231
  };
7279
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
+
7280
7318
  // src/runtime/memory-runner.ts
7281
7319
  var MemorySessionRunner = class extends MemorySessionHost {
7282
7320
  constructor(options = {}) {
@@ -7311,6 +7349,288 @@ var SASjsApi = (() => {
7311
7349
  }
7312
7350
  };
7313
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
+
7314
7634
  // src/corpus/runtime.ts
7315
7635
  var ADMIN2 = { userId: "user-admin", clientId: "web_app" };
7316
7636
  var PROGRAM = "/Public/apps/demo/run.sas";
@@ -8791,92 +9111,6 @@ var SASjsApi = (() => {
8791
9111
  }
8792
9112
  ];
8793
9113
 
8794
- // src/corpus/runner.ts
8795
- var CORPUS_APP = {
8796
- id: "6f1c1c1e-6a1e-4c4a-9d1a-1b2c3d4e5f60",
8797
- name: "myApp",
8798
- appLoc: "/Public/myApp",
8799
- streamWebFolder: "web",
8800
- publishedAt: "2026-01-01T00:00:00.000Z"
8801
- };
8802
- var servicesFor = (testCase) => {
8803
- const identity = new MemoryIdentityStore(
8804
- testCase.identity || DEFAULT_IDENTITY
8805
- );
8806
- const runner = new MemorySessionRunner({
8807
- fail: testCase.failingRun,
8808
- outputs: testCase.runOutput ? { [programOf(testCase)]: testCase.runOutput } : void 0
8809
- });
8810
- return {
8811
- drive: createDriveService(
8812
- testCase.unwritable ? new RefusingDriveStore(testCase.seed || {}) : new MemoryDriveStore(testCase.seed || {})
8813
- ),
8814
- info: createInfoService(BROWSER_INFO),
8815
- home: createHomeService(async () => CORPUS_WEB_PAGE),
8816
- authConfig: createAuthConfigService(CORPUS_AUTH_CONFIG),
8817
- admin: createAdminService({
8818
- diagnostics: async () => CORPUS_DIAGNOSTICS,
8819
- logs: async () => [CORPUS_LOG],
8820
- logTail: async (fileName) => fileName === CORPUS_LOG.name ? CORPUS_LOG_TAIL : void 0
8821
- }),
8822
- directory: createDirectoryService(identity, CORPUS_DIRECTORY),
8823
- identity: createIdentityService(identity),
8824
- records: createRecordService(identity),
8825
- appStream: createAppStreamService(new MemoryAppStreamStore([CORPUS_APP])),
8826
- session: createSessionService(identity, runner),
8827
- // no `runTimes` option: the default is the five the document names, so a
8828
- // case is never refused for a reason that belongs to one host's install
8829
- runtime: createRuntimeService(identity, runner)
8830
- };
8831
- };
8832
- var programOf = (testCase) => String(
8833
- testCase.request.query?._program ?? testCase.request.body?._program ?? testCase.request.body?.code ?? ""
8834
- );
8835
- var RefusingDriveStore = class extends MemoryDriveStore {
8836
- async write() {
8837
- throw new Error("the store refused the write");
8838
- }
8839
- async mkdirp() {
8840
- throw new Error("the store refused the write");
8841
- }
8842
- };
8843
- var checkDrive = async (testCase, services) => {
8844
- if (!testCase.expectDrive || !services.drive) return;
8845
- const holds = async (path) => {
8846
- try {
8847
- await services.drive.read(path);
8848
- return true;
8849
- } catch (e) {
8850
- return false;
8851
- }
8852
- };
8853
- for (const path of testCase.expectDrive.present || [])
8854
- if (!await holds(path))
8855
- throw new Error(
8856
- `${testCase.id}: expected a file at ${path}, and the drive has none`
8857
- );
8858
- for (const path of testCase.expectDrive.missing || [])
8859
- if (await holds(path))
8860
- throw new Error(
8861
- `${testCase.id}: expected no file at ${path}, and the drive still holds one`
8862
- );
8863
- };
8864
- var runCase = async (testCase, services = servicesFor(testCase)) => {
8865
- try {
8866
- const response = await dispatch(services, testCase.route, testCase.request);
8867
- await checkDrive(testCase, services);
8868
- return {
8869
- status: response.status,
8870
- body: response.body,
8871
- contents: response.contents
8872
- };
8873
- } catch (error) {
8874
- if (isApiError(error))
8875
- return { status: error.status, body: error.body, error: error.message };
8876
- throw error;
8877
- }
8878
- };
8879
-
8880
9114
  // src/appstream/store.ts
8881
9115
  var APP_STREAM_INDEX = "/.sasjs/apps.json";
8882
9116
  var isEntry = (value) => {