@sasjs/api 0.24.0 → 0.26.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 (53) hide show
  1. package/README.md +10 -0
  2. package/build/browser.js +703 -94
  3. package/build/cjs/appstream/bundle.js +124 -0
  4. package/build/cjs/appstream/identity.js +69 -0
  5. package/build/cjs/appstream/service.js +226 -0
  6. package/build/cjs/appstream/store.js +69 -0
  7. package/build/cjs/appstream/web.js +248 -0
  8. package/build/cjs/corpus/deploy.js +83 -28
  9. package/build/cjs/corpus/runner.js +30 -18
  10. package/build/cjs/host/dispatch.js +38 -9
  11. package/build/cjs/identity/memory-store.js +51 -1
  12. package/build/cjs/index.js +25 -4
  13. package/build/cjs/routes/generated.js +2 -8
  14. package/build/cjs/routes/overlay.js +2 -2
  15. package/build/esm/appstream/bundle.d.ts +46 -0
  16. package/build/esm/appstream/bundle.d.ts.map +1 -0
  17. package/build/esm/appstream/bundle.js +118 -0
  18. package/build/esm/appstream/identity.d.ts +27 -0
  19. package/build/esm/appstream/identity.d.ts.map +1 -0
  20. package/build/esm/appstream/identity.js +63 -0
  21. package/build/esm/appstream/service.d.ts +96 -0
  22. package/build/esm/appstream/service.d.ts.map +1 -0
  23. package/build/esm/appstream/service.js +218 -0
  24. package/build/esm/appstream/store.d.ts +6 -0
  25. package/build/esm/appstream/store.d.ts.map +1 -0
  26. package/build/esm/appstream/store.js +65 -0
  27. package/build/esm/appstream/web.d.ts +74 -0
  28. package/build/esm/appstream/web.d.ts.map +1 -0
  29. package/build/esm/appstream/web.js +241 -0
  30. package/build/esm/corpus/deploy.d.ts +5 -5
  31. package/build/esm/corpus/deploy.d.ts.map +1 -1
  32. package/build/esm/corpus/deploy.js +83 -28
  33. package/build/esm/corpus/runner.d.ts.map +1 -1
  34. package/build/esm/corpus/runner.js +14 -2
  35. package/build/esm/host/dispatch.d.ts +5 -4
  36. package/build/esm/host/dispatch.d.ts.map +1 -1
  37. package/build/esm/host/dispatch.js +38 -9
  38. package/build/esm/identity/fixture.d.ts +9 -4
  39. package/build/esm/identity/fixture.d.ts.map +1 -1
  40. package/build/esm/identity/memory-store.d.ts +22 -0
  41. package/build/esm/identity/memory-store.d.ts.map +1 -1
  42. package/build/esm/identity/memory-store.js +51 -1
  43. package/build/esm/index.d.ts +8 -2
  44. package/build/esm/index.d.ts.map +1 -1
  45. package/build/esm/index.js +5 -1
  46. package/build/esm/routes/generated.d.ts.map +1 -1
  47. package/build/esm/routes/generated.js +2 -8
  48. package/build/esm/routes/overlay.js +2 -2
  49. package/package.json +5 -4
  50. package/build/cjs/drive/registry.js +0 -38
  51. package/build/esm/drive/registry.d.ts +0 -52
  52. package/build/esm/drive/registry.d.ts.map +0 -1
  53. package/build/esm/drive/registry.js +0 -33
package/build/browser.js CHANGED
@@ -1,4 +1,4 @@
1
- /* @sasjs/api 0.24.0 - the SASjs Server API, for a service worker. https://github.com/sasjs/api */
1
+ /* @sasjs/api 0.26.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,12 +25,15 @@ 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_MANIFEST: () => APP_MANIFEST,
29
+ APP_STREAM_INDEX: () => APP_STREAM_INDEX,
28
30
  AUTH_CONFIG_CORPUS: () => AUTH_CONFIG_CORPUS,
29
31
  ApiError: () => ApiError,
30
32
  BROWSER_INFO: () => BROWSER_INFO,
31
33
  BUNDLE_NAME: () => BUNDLE_NAME,
32
34
  CODE_CORPUS: () => CODE_CORPUS,
33
35
  CODE_DEBUG: () => CODE_DEBUG,
36
+ DEFAULT_APP_PATH: () => DEFAULT_APP_PATH,
34
37
  DEFAULT_GRANTABLE_ROUTES: () => DEFAULT_GRANTABLE_ROUTES,
35
38
  DEFAULT_IDENTITY: () => DEFAULT_IDENTITY,
36
39
  DEFAULT_LOG_LINES: () => DEFAULT_LOG_LINES,
@@ -48,11 +51,12 @@ var SASjsApi = (() => {
48
51
  IDENTITY_FORMAT: () => IDENTITY_FORMAT,
49
52
  INFO_CORPUS: () => INFO_CORPUS,
50
53
  MAX_LOG_LINES: () => MAX_LOG_LINES,
51
- MemoryAppStreamRegistry: () => MemoryAppStreamRegistry,
54
+ MemoryAppStreamStore: () => MemoryAppStreamStore,
52
55
  MemoryDriveStore: () => MemoryDriveStore,
53
56
  MemoryIdentityStore: () => MemoryIdentityStore,
54
57
  MemorySessionHost: () => MemorySessionHost,
55
58
  MemorySessionRunner: () => MemorySessionRunner,
59
+ NO_SUCH_APP: () => NO_SUCH_APP,
56
60
  NO_WEB_BUILD: () => NO_WEB_BUILD,
57
61
  OVERLAY: () => OVERLAY,
58
62
  PROVIDER_MANAGED: () => PROVIDER_MANAGED,
@@ -63,12 +67,18 @@ var SASjsApi = (() => {
63
67
  STATIC_AUTHORIZED_ROUTES: () => STATIC_AUTHORIZED_ROUTES,
64
68
  TAG_CAPABILITIES: () => TAG_CAPABILITIES,
65
69
  TOP_LEVEL_ROUTES: () => TOP_LEVEL_ROUTES,
70
+ appSummary: () => appSummary,
66
71
  basename: () => basename,
72
+ cacheControlFor: () => cacheControlFor,
67
73
  checkDeployTree: () => checkDeployTree,
68
74
  checkLogFileName: () => checkLogFileName,
75
+ contentTypeFor: () => contentTypeFor,
69
76
  createAdminService: () => createAdminService,
77
+ createAppStreamService: () => createAppStreamService,
78
+ createAppStreamWebService: () => createAppStreamWebService,
70
79
  createAuthConfigService: () => createAuthConfigService,
71
80
  createDirectoryService: () => createDirectoryService,
81
+ createDriveAppStreamStore: () => createDriveAppStreamStore,
72
82
  createDriveService: () => createDriveService,
73
83
  createHomeService: () => createHomeService,
74
84
  createIdentityService: () => createIdentityService,
@@ -77,29 +87,36 @@ var SASjsApi = (() => {
77
87
  createRuntimeService: () => createRuntimeService,
78
88
  createSessionService: () => createSessionService,
79
89
  decodeBase64: () => decodeBase64,
90
+ defaultAppName: () => defaultAppName,
80
91
  deployTree: () => deployTree,
81
92
  dirname: () => dirname,
82
93
  dispatch: () => dispatch,
94
+ escapeHtml: () => escapeHtml,
83
95
  findRoute: () => findRoute,
84
96
  hasBlockedExtension: () => hasBlockedExtension,
85
97
  isApiError: () => isApiError,
98
+ isAppId: () => isAppId,
86
99
  isDeployTree: () => isDeployTree,
87
100
  isRoot: () => isRoot,
88
101
  isRouteGranted: () => isRouteGranted,
89
102
  logLines: () => logLines,
90
103
  measureDeployTree: () => measureDeployTree,
104
+ newAppId: () => newAppId,
105
+ normaliseAppLoc: () => normaliseAppLoc,
91
106
  normaliseAuthConfig: () => normaliseAuthConfig,
92
107
  normaliseDiagnostics: () => normaliseDiagnostics,
93
108
  normaliseDrivePath: () => normaliseDrivePath,
94
109
  normaliseInfo: () => normaliseInfo,
95
110
  normaliseLogFiles: () => normaliseLogFiles,
111
+ parseAppManifest: () => parseAppManifest,
96
112
  parseIdentity: () => parseIdentity,
113
+ publishRequestFor: () => publishRequestFor,
97
114
  routeById: () => routeById,
98
115
  runCase: () => runCase,
99
116
  sanitiseDisplayName: () => sanitiseDisplayName,
100
117
  servicesFor: () => servicesFor,
118
+ splitAppBundle: () => splitAppBundle,
101
119
  topLevelRouteFor: () => topLevelRouteFor,
102
- unpublishAppStream: () => unpublishAppStream,
103
120
  withBundleVersion: () => withBundleVersion
104
121
  });
105
122
 
@@ -120,9 +137,9 @@ var SASjsApi = (() => {
120
137
  var BLOCKED_EXTENSION = /\.(exe|sh|htaccess)$/i;
121
138
  var hasBlockedExtension = (path) => BLOCKED_EXTENSION.test(path);
122
139
  var normaliseDrivePath = (input) => {
123
- const given = typeof input === "string" ? input : "";
140
+ const given2 = typeof input === "string" ? input : "";
124
141
  const segments = [];
125
- for (const segment of given.replace(/\\/g, "/").split("/")) {
142
+ for (const segment of given2.replace(/\\/g, "/").split("/")) {
126
143
  if (!segment || segment === ".") continue;
127
144
  if (segment === "..") {
128
145
  if (!segments.length) return null;
@@ -369,9 +386,9 @@ var SASjsApi = (() => {
369
386
  };
370
387
  };
371
388
  return {
372
- async list(given) {
389
+ async list(given2) {
373
390
  const path = folderPath(
374
- given === void 0 ? "" : given,
391
+ given2 === void 0 ? "" : given2,
375
392
  "Can't get folder outside drive."
376
393
  );
377
394
  if (!await store.exists(path))
@@ -384,37 +401,37 @@ var SASjsApi = (() => {
384
401
  folders: [...listing.folders].sort()
385
402
  };
386
403
  },
387
- async read(given) {
388
- const path = filePath(given, "Can't get file outside drive.");
404
+ async read(given2) {
405
+ const path = filePath(given2, "Can't get file outside drive.");
389
406
  if (!await store.exists(path))
390
407
  throw new ApiError(404, `File doesn't exist.`);
391
408
  const contents = await store.read(path);
392
409
  return { contents, binary: typeof contents !== "string" };
393
410
  },
394
- async save(given, contents) {
395
- const path = filePath(given, "Can't put file outside drive.");
411
+ async save(given2, contents) {
412
+ const path = filePath(given2, "Can't put file outside drive.");
396
413
  if (await store.exists(path))
397
414
  throw new ApiError(409, "File already exists.");
398
415
  await store.mkdirp(dirname(path));
399
416
  await store.write(path, contents);
400
417
  return { status: "success" };
401
418
  },
402
- async update(given, contents) {
403
- const path = filePath(given, "Can't modify file outside drive.");
419
+ async update(given2, contents) {
420
+ const path = filePath(given2, "Can't modify file outside drive.");
404
421
  if (!await store.exists(path))
405
422
  throw new ApiError(404, `File doesn't exist.`);
406
423
  await store.write(path, contents);
407
424
  return { status: "success" };
408
425
  },
409
- async remove(given) {
410
- const path = filePath(given, "Can't delete file outside drive.");
426
+ async remove(given2) {
427
+ const path = filePath(given2, "Can't delete file outside drive.");
411
428
  if (!await store.exists(path))
412
429
  throw new ApiError(404, `File doesn't exist.`);
413
430
  await store.remove(path);
414
431
  return { status: "success" };
415
432
  },
416
- async mkdir(given) {
417
- const path = folderPath(given, "Can't put folder outside drive.");
433
+ async mkdir(given2) {
434
+ const path = folderPath(given2, "Can't put folder outside drive.");
418
435
  if (isRoot(path))
419
436
  throw new ApiError(400, "Can't put folder outside drive.");
420
437
  if (await store.exists(path))
@@ -422,8 +439,8 @@ var SASjsApi = (() => {
422
439
  await store.mkdirp(path);
423
440
  return { status: "success" };
424
441
  },
425
- async rmdir(given) {
426
- const path = folderPath(given, "Can't delete folder outside drive.");
442
+ async rmdir(given2) {
443
+ const path = folderPath(given2, "Can't delete folder outside drive.");
427
444
  if (isRoot(path))
428
445
  throw new ApiError(400, "Can't delete folder outside drive.");
429
446
  if (!await store.exists(path) || !(await store.stat(path)).directory)
@@ -455,9 +472,9 @@ var SASjsApi = (() => {
455
472
  }
456
473
  throw new ApiError(404, "No file/folder found for provided path.");
457
474
  },
458
- async tree(given) {
475
+ async tree(given2) {
459
476
  const path = folderPath(
460
- given === void 0 ? "" : given,
477
+ given2 === void 0 ? "" : given2,
461
478
  "Can't get folder outside drive."
462
479
  );
463
480
  if (!await store.exists(path))
@@ -1111,13 +1128,7 @@ var SASjsApi = (() => {
1111
1128
  summary: "Remove an app stream entry",
1112
1129
  params: [
1113
1130
  {
1114
- name: "appLoc",
1115
- in: "body",
1116
- required: true,
1117
- type: "string"
1118
- },
1119
- {
1120
- name: "streamServiceName",
1131
+ name: "id",
1121
1132
  in: "body",
1122
1133
  required: true,
1123
1134
  type: "string"
@@ -1135,7 +1146,7 @@ var SASjsApi = (() => {
1135
1146
  },
1136
1147
  {
1137
1148
  status: 404,
1138
- description: "No app is published at that folder"
1149
+ description: "No app is published with that id"
1139
1150
  }
1140
1151
  ]
1141
1152
  },
@@ -2891,8 +2902,8 @@ var SASjsApi = (() => {
2891
2902
  }
2892
2903
  },
2893
2904
  "POST /SASjsApi/drive/deploy/upload": { implemented: true },
2894
- // `404` is a pair - the registry name and the appLoc it was published from -
2895
- // that matches no entry, and the drive's content is deliberately left alone.
2905
+ // `404` is an id the index does not hold - the id is the app, and its label and
2906
+ // folder are not handles - and the drive's content is deliberately left alone.
2896
2907
  "DELETE /SASjsApi/drive/deploy": { implemented: true },
2897
2908
  // Group - members and the groups themselves
2898
2909
  "GET /SASjsApi/group": { implemented: true },
@@ -3072,24 +3083,273 @@ var SASjsApi = (() => {
3072
3083
  return void 0;
3073
3084
  };
3074
3085
 
3075
- // src/drive/registry.ts
3076
- var unpublishAppStream = async (registry, body) => {
3077
- if (!body?.streamServiceName)
3078
- throw new ApiError(400, '"streamServiceName" is required');
3079
- if (!body.appLoc) throw new ApiError(400, '"appLoc" is required');
3080
- if (!await registry.unpublish(body.appLoc))
3081
- throw new ApiError(404, "No app is published at that folder.");
3082
- return { status: "success" };
3086
+ // src/appstream/identity.ts
3087
+ var normaliseAppLoc = (appLoc) => {
3088
+ if (typeof appLoc !== "string" || appLoc === "")
3089
+ throw new Error(
3090
+ `App location must be a non-empty string, got ${JSON.stringify(appLoc)}.`
3091
+ );
3092
+ const normalised = normaliseDrivePath(appLoc);
3093
+ if (normalised === null)
3094
+ throw new ApiError(400, "appLoc cannot be outside drive.");
3095
+ return normalised;
3096
+ };
3097
+ var newAppId = () => {
3098
+ const webCrypto = globalThis.crypto;
3099
+ if (typeof webCrypto?.randomUUID === "function") return webCrypto.randomUUID();
3100
+ if (typeof webCrypto?.getRandomValues !== "function")
3101
+ throw new Error("No cryptographic source of randomness is available.");
3102
+ const bytes3 = new Uint8Array(16);
3103
+ webCrypto.getRandomValues(bytes3);
3104
+ bytes3[6] = bytes3[6] & 15 | 64;
3105
+ bytes3[8] = bytes3[8] & 63 | 128;
3106
+ const hex = Array.from(bytes3).map((byte) => byte.toString(16).padStart(2, "0")).join("");
3107
+ return [
3108
+ hex.slice(0, 8),
3109
+ hex.slice(8, 12),
3110
+ hex.slice(12, 16),
3111
+ hex.slice(16, 20),
3112
+ hex.slice(20)
3113
+ ].join("-");
3114
+ };
3115
+ var APP_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
3116
+ var isAppId = (value) => typeof value === "string" && APP_ID.test(value);
3117
+
3118
+ // src/appstream/service.ts
3119
+ var appSummary = (entry) => ({
3120
+ id: entry.id,
3121
+ name: entry.name,
3122
+ url: `/app/${entry.id}/`
3123
+ });
3124
+ var webFolderOf = (value) => {
3125
+ if (typeof value !== "string" || value === "")
3126
+ throw new ApiError(400, '"streamWebFolder" is required');
3127
+ if (value === "." || value === ".." || /[\\/]/.test(value))
3128
+ throw new ApiError(400, "streamWebFolder must be a single path segment.");
3129
+ return value;
3130
+ };
3131
+ var defaultAppName = (appLoc) => {
3132
+ const segment = appLoc.split("/").filter(Boolean).pop();
3133
+ return segment ? segment : "app";
3134
+ };
3135
+ var sameAppLoc = (left, right) => {
3136
+ try {
3137
+ return normaliseAppLoc(left) === normaliseAppLoc(right);
3138
+ } catch (_) {
3139
+ return false;
3140
+ }
3141
+ };
3142
+ var appLocOf = (value) => {
3143
+ try {
3144
+ return normaliseAppLoc(value);
3145
+ } catch (error) {
3146
+ throw new ApiError(400, error.message);
3147
+ }
3148
+ };
3149
+ var checkPublishRequest = (request) => {
3150
+ const appLoc = appLocOf(request.appLoc);
3151
+ if (appLoc === "/")
3152
+ throw new ApiError(400, "An app cannot be published at the drive root.");
3153
+ const logo = logoOf(request.logo);
3154
+ const frameAncestors = frameAncestorsOf(request.frameAncestors);
3155
+ return {
3156
+ appLoc,
3157
+ streamWebFolder: webFolderOf(request.streamWebFolder),
3158
+ ...request.name === void 0 ? {} : { name: nameOf(request.name, appLoc) },
3159
+ ...logo === void 0 ? {} : { logo },
3160
+ ...frameAncestors === void 0 ? {} : { frameAncestors },
3161
+ ...request.publishedAt === void 0 ? {} : { publishedAt: request.publishedAt }
3162
+ };
3163
+ };
3164
+ var nameOf = (value, appLoc) => {
3165
+ if (value === void 0) return defaultAppName(appLoc);
3166
+ if (typeof value !== "string" || value.trim() === "")
3167
+ throw new ApiError(400, '"name" must be a non-empty string');
3168
+ return value.trim();
3169
+ };
3170
+ var logoOf = (value) => {
3171
+ if (value === void 0) return void 0;
3172
+ if (typeof value !== "string" || value === "")
3173
+ throw new ApiError(400, '"logo" must be a non-empty string');
3174
+ return value;
3175
+ };
3176
+ var frameAncestorsOf = (value) => {
3177
+ if (value === void 0) return void 0;
3178
+ const list = Array.isArray(value) ? value : [value];
3179
+ if (list.length === 0 || list.some((source) => typeof source !== "string" || source === ""))
3180
+ throw new ApiError(
3181
+ 400,
3182
+ '"frameAncestors" must be a string or a non-empty list of strings'
3183
+ );
3184
+ return [...list];
3185
+ };
3186
+ var createAppStreamService = (store) => {
3187
+ let queue = Promise.resolve();
3188
+ const mutate = (work) => {
3189
+ const run = queue.then(work, work);
3190
+ queue = run.catch(() => void 0);
3191
+ return run;
3192
+ };
3193
+ const readable = (allow) => store.read().then(
3194
+ (entries) => entries.filter((entry) => allow ? allow(entry) : true).map((entry) => ({ ...entry })).sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0)
3195
+ );
3196
+ return {
3197
+ list: readable,
3198
+ async get(id) {
3199
+ const entry = (await store.read()).find(
3200
+ (candidate) => candidate.id === id
3201
+ );
3202
+ if (!entry) throw new ApiError(404, "No app is published with that id.");
3203
+ return { ...entry };
3204
+ },
3205
+ async forAppLoc(appLoc) {
3206
+ let normalised;
3207
+ try {
3208
+ normalised = normaliseAppLoc(appLoc);
3209
+ } catch (_) {
3210
+ return void 0;
3211
+ }
3212
+ const entry = (await store.read()).find(
3213
+ (candidate) => sameAppLoc(candidate.appLoc, normalised)
3214
+ );
3215
+ return entry ? { ...entry } : void 0;
3216
+ },
3217
+ publish(request) {
3218
+ return mutate(async () => {
3219
+ const checked = checkPublishRequest(request);
3220
+ const appLoc = checked.appLoc;
3221
+ const streamWebFolder = checked.streamWebFolder;
3222
+ const entries = await store.read();
3223
+ const existing = entries.find(
3224
+ (entry2) => sameAppLoc(entry2.appLoc, appLoc)
3225
+ );
3226
+ const logo = checked.logo;
3227
+ const frameAncestors = checked.frameAncestors;
3228
+ const entry = {
3229
+ id: existing ? existing.id : newAppId(),
3230
+ // the label is the one field a redeploy inherits: everything else is
3231
+ // what this publish states
3232
+ name: nameOf(checked.name ?? existing?.name, appLoc),
3233
+ appLoc,
3234
+ streamWebFolder,
3235
+ ...logo === void 0 ? {} : { logo },
3236
+ ...frameAncestors === void 0 ? {} : { frameAncestors },
3237
+ publishedAt: checked.publishedAt ?? (/* @__PURE__ */ new Date()).toISOString()
3238
+ };
3239
+ await store.write([
3240
+ ...entries.filter(
3241
+ (candidate) => !sameAppLoc(candidate.appLoc, appLoc)
3242
+ ),
3243
+ entry
3244
+ ]);
3245
+ return { ...entry };
3246
+ });
3247
+ },
3248
+ unpublish(id) {
3249
+ return mutate(async () => {
3250
+ const entries = await store.read();
3251
+ const index = entries.findIndex((entry) => entry.id === id);
3252
+ if (index === -1)
3253
+ throw new ApiError(404, "No app is published with that id.");
3254
+ const [removed] = entries.splice(index, 1);
3255
+ await store.write(entries);
3256
+ return { ...removed };
3257
+ });
3258
+ }
3259
+ };
3083
3260
  };
3084
- var MemoryAppStreamRegistry = class {
3085
- constructor(folders = ["/Public/myApp"]) {
3086
- this.folders = new Set(folders);
3261
+ var MemoryAppStreamStore = class {
3262
+ constructor(entries = []) {
3263
+ this.entries = entries.map((entry) => ({ ...entry }));
3087
3264
  }
3088
- async unpublish(appLoc) {
3089
- return this.folders.delete(appLoc);
3265
+ async read() {
3266
+ return this.entries.map((entry) => ({ ...entry }));
3267
+ }
3268
+ async write(entries) {
3269
+ this.entries = entries.map((entry) => ({ ...entry }));
3090
3270
  }
3091
3271
  };
3092
3272
 
3273
+ // src/appstream/bundle.ts
3274
+ var APP_MANIFEST = "sasjs.app.json";
3275
+ var isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
3276
+ var text = (value, field) => {
3277
+ if (value === void 0) return void 0;
3278
+ if (typeof value !== "string" || value.trim() === "")
3279
+ throw new ApiError(
3280
+ 400,
3281
+ `"${field}" must be a non-empty string in ${APP_MANIFEST}.`
3282
+ );
3283
+ return value.trim();
3284
+ };
3285
+ var parseAppManifest = (value) => {
3286
+ if (!isObject(value))
3287
+ throw new ApiError(400, `${APP_MANIFEST} must be an object.`);
3288
+ const streamWebFolder = text(value.streamWebFolder, "streamWebFolder");
3289
+ if (streamWebFolder === void 0)
3290
+ throw new ApiError(
3291
+ 400,
3292
+ `${APP_MANIFEST} must state "streamWebFolder": the folder under services/ holding the compiled app.`
3293
+ );
3294
+ const name = text(value.name, "name");
3295
+ const logo = text(value.logo, "logo");
3296
+ const frameAncestors = value.frameAncestors;
3297
+ if (frameAncestors !== void 0 && (typeof frameAncestors !== "string" || frameAncestors === "") && !(Array.isArray(frameAncestors) && frameAncestors.length > 0 && frameAncestors.every(
3298
+ (source) => typeof source === "string" && source !== ""
3299
+ )))
3300
+ throw new ApiError(
3301
+ 400,
3302
+ `"frameAncestors" in ${APP_MANIFEST} must be a string or a non-empty list of strings.`
3303
+ );
3304
+ return {
3305
+ ...name === void 0 ? {} : { name },
3306
+ streamWebFolder,
3307
+ ...logo === void 0 ? {} : { logo },
3308
+ ...frameAncestors === void 0 ? {} : { frameAncestors }
3309
+ };
3310
+ };
3311
+ var splitAppBundle = (tree) => {
3312
+ if (!isObject(tree) || !Array.isArray(tree.members))
3313
+ return { tree };
3314
+ const members = tree.members;
3315
+ const at = members.findIndex(
3316
+ (member2) => isObject(member2) && member2.type === "file" && member2.name === APP_MANIFEST
3317
+ );
3318
+ if (at === -1) return { tree };
3319
+ const member = members[at];
3320
+ if (typeof member.code !== "string")
3321
+ throw new ApiError(400, `${APP_MANIFEST} carries no text.`);
3322
+ let parsed;
3323
+ try {
3324
+ parsed = JSON.parse(member.code);
3325
+ } catch (error) {
3326
+ throw new ApiError(
3327
+ 400,
3328
+ `${APP_MANIFEST} is not valid JSON: ${error.message}`
3329
+ );
3330
+ }
3331
+ return {
3332
+ tree: {
3333
+ ...tree,
3334
+ members: members.filter((_, index) => index !== at)
3335
+ },
3336
+ manifest: parseAppManifest(parsed)
3337
+ };
3338
+ };
3339
+ var publishRequestFor = (deploy, manifest) => {
3340
+ const streamWebFolder = deploy.streamWebFolder ?? manifest?.streamWebFolder;
3341
+ if (streamWebFolder === void 0) return void 0;
3342
+ const name = deploy.streamServiceName ?? manifest?.name;
3343
+ const logo = deploy.streamLogo ?? manifest?.logo;
3344
+ return {
3345
+ appLoc: deploy.appLoc,
3346
+ streamWebFolder,
3347
+ ...name === void 0 ? {} : { name },
3348
+ ...logo === void 0 ? {} : { logo },
3349
+ ...manifest?.frameAncestors === void 0 ? {} : { frameAncestors: manifest.frameAncestors }
3350
+ };
3351
+ };
3352
+
3093
3353
  // src/host/dispatch.ts
3094
3354
  var SECONDS_IN_A_DAY = 86400;
3095
3355
  var RUN_ROUTES = [
@@ -3099,15 +3359,16 @@ var SASjsApi = (() => {
3099
3359
  "POST /SASjsApi/code/execute",
3100
3360
  "POST /SASjsApi/code/trigger"
3101
3361
  ];
3362
+ var given = (value) => typeof value === "string" && value !== "" ? value : void 0;
3102
3363
  var validate = (route, request) => {
3103
3364
  for (const param of route.params) {
3104
3365
  if (!param.required || param.in === "formData" || param.in === "header")
3105
3366
  continue;
3106
3367
  if (param.in === "path") continue;
3107
- const given = param.in === "query" ? request.query?.[param.name] : request.body?.[param.name];
3108
- if (given === void 0)
3368
+ const given2 = param.in === "query" ? request.query?.[param.name] : request.body?.[param.name];
3369
+ if (given2 === void 0)
3109
3370
  throw new ApiError(400, `"${param.name}" is required`);
3110
- if (given === "")
3371
+ if (given2 === "")
3111
3372
  throw new ApiError(400, `"${param.name}" is not allowed to be empty`);
3112
3373
  }
3113
3374
  };
@@ -3339,19 +3600,39 @@ var SASjsApi = (() => {
3339
3600
  // expansion, which is why the two share this path rather than reading bytes.
3340
3601
  case "POST /SASjsApi/drive/deploy/upload":
3341
3602
  case "POST /SASjsApi/drive/deploy": {
3342
- await drive.deploy(String(body.appLoc ?? ""), body.fileTree);
3343
- return { status: 200, body: DEPLOY_SUCCESS };
3603
+ const bundle = splitAppBundle(body.fileTree);
3604
+ const appLoc = String(body.appLoc ?? "");
3605
+ const requested = services.appStream ? publishRequestFor(
3606
+ {
3607
+ appLoc,
3608
+ streamWebFolder: given(body.streamWebFolder),
3609
+ streamServiceName: given(body.streamServiceName),
3610
+ streamLogo: given(body.streamLogo)
3611
+ },
3612
+ bundle.manifest
3613
+ ) : void 0;
3614
+ const publish = requested === void 0 ? void 0 : checkPublishRequest(requested);
3615
+ await drive.deploy(appLoc, bundle.tree);
3616
+ if (publish === void 0 || !services.appStream)
3617
+ return { status: 200, body: DEPLOY_SUCCESS };
3618
+ const entry = await services.appStream.publish(publish);
3619
+ return {
3620
+ status: 200,
3621
+ body: { ...DEPLOY_SUCCESS, app: appSummary(entry) }
3622
+ };
3344
3623
  }
3345
- case "DELETE /SASjsApi/drive/deploy":
3346
- if (!services.registry)
3624
+ case "DELETE /SASjsApi/drive/deploy": {
3625
+ if (!services.appStream)
3347
3626
  throw new ApiError(
3348
3627
  501,
3349
- `This host has no app stream registry, so it cannot answer ${routeId}.`
3628
+ `This host has no app stream, so it cannot answer ${routeId}.`
3350
3629
  );
3630
+ const removed = await services.appStream.unpublish(String(body.id ?? ""));
3351
3631
  return {
3352
3632
  status: 200,
3353
- body: await unpublishAppStream(services.registry, body)
3633
+ body: { status: "success", app: appSummary(removed) }
3354
3634
  };
3635
+ }
3355
3636
  case "GET /SASjsApi/drive/filetree":
3356
3637
  return { status: 200, body: await drive.tree(query._folderPath) };
3357
3638
  // ------------------------------------------------------------- run times
@@ -4474,7 +4755,7 @@ var SASjsApi = (() => {
4474
4755
  var BUNDLE_REFERENCE = new RegExp(
4475
4756
  `(^|/)${BUNDLE_NAME.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}$`
4476
4757
  );
4477
- var withBundleVersion = (html, version) => html.replace(FILE_ATTRIBUTE, (match, attribute, value) => {
4758
+ var withBundleVersion = (html2, version) => html2.replace(FILE_ATTRIBUTE, (match, attribute, value) => {
4478
4759
  const quote = value[0] === '"' || value[0] === "'" ? value[0] : "";
4479
4760
  const target = quote ? value.slice(1, -1) : value;
4480
4761
  if (!BUNDLE_REFERENCE.test(target) || target.includes("?")) return match;
@@ -4707,7 +4988,7 @@ var SASjsApi = (() => {
4707
4988
  // src/admin/service.ts
4708
4989
  var DEFAULT_LOG_LINES = 200;
4709
4990
  var MAX_LOG_LINES = 5e3;
4710
- var isObject = (value) => !!value && typeof value === "object" && !Array.isArray(value);
4991
+ var isObject2 = (value) => !!value && typeof value === "object" && !Array.isArray(value);
4711
4992
  var isNumber = (value) => typeof value === "number" && Number.isFinite(value);
4712
4993
  var isString = (value) => typeof value === "string";
4713
4994
  var requireString = (holder, key, where) => {
@@ -4724,14 +5005,14 @@ var SASjsApi = (() => {
4724
5005
  };
4725
5006
  var requireObject = (holder, key, where) => {
4726
5007
  const value = holder[key];
4727
- if (!isObject(value))
5008
+ if (!isObject2(value))
4728
5009
  throw new Error(
4729
5010
  `The ${where} report states \`${key}\` as ${JSON.stringify(value)}; the document states an object.`
4730
5011
  );
4731
5012
  return value;
4732
5013
  };
4733
5014
  var normaliseDiagnostics = (report) => {
4734
- if (!isObject(report))
5015
+ if (!isObject2(report))
4735
5016
  throw new Error("The diagnostics report is not an object.");
4736
5017
  const build = requireObject(
4737
5018
  report,
@@ -4783,7 +5064,7 @@ var SASjsApi = (() => {
4783
5064
  requireNumber(memory, key, "diagnostics memory");
4784
5065
  const filesystem = report.filesystem;
4785
5066
  if (filesystem !== null) {
4786
- if (!isObject(filesystem))
5067
+ if (!isObject2(filesystem))
4787
5068
  throw new Error(
4788
5069
  `The diagnostics report states \`filesystem\` as ${JSON.stringify(filesystem)}; the document states an object or null.`
4789
5070
  );
@@ -4804,7 +5085,7 @@ var SASjsApi = (() => {
4804
5085
  "The diagnostics report states `folders` as something other than an array."
4805
5086
  );
4806
5087
  for (const folder of report.folders) {
4807
- if (!isObject(folder))
5088
+ if (!isObject2(folder))
4808
5089
  throw new Error(
4809
5090
  "The diagnostics report carries a folder that is not an object."
4810
5091
  );
@@ -4837,7 +5118,7 @@ var SASjsApi = (() => {
4837
5118
  if (!Array.isArray(files))
4838
5119
  throw new Error("The log report is not an array of files.");
4839
5120
  return files.map((file) => {
4840
- if (!isObject(file))
5121
+ if (!isObject2(file))
4841
5122
  throw new Error("The log report carries an entry that is not an object.");
4842
5123
  const entry = file;
4843
5124
  requireString(entry, "name", "logs");
@@ -4859,7 +5140,7 @@ var SASjsApi = (() => {
4859
5140
  return Math.min(Math.max(Math.trunc(wanted), 1), MAX_LOG_LINES);
4860
5141
  };
4861
5142
  var normaliseLogTail = (tail) => {
4862
- if (!isObject(tail)) throw new Error("The log tail report is not an object.");
5143
+ if (!isObject2(tail)) throw new Error("The log tail report is not an object.");
4863
5144
  const entry = tail;
4864
5145
  requireString(entry, "fileName", "log tail");
4865
5146
  requireString(entry, "content", "log tail");
@@ -5132,7 +5413,8 @@ var SASjsApi = (() => {
5132
5413
  authProvider: user3.authProvider,
5133
5414
  autoExec: user3.autoExec
5134
5415
  });
5135
- this.passwords.set(user3.uid, user3.password);
5416
+ if (user3.password !== void 0)
5417
+ this.passwords.set(user3.uid, user3.password);
5136
5418
  }
5137
5419
  for (const client of fixture.clients) {
5138
5420
  this.clientMap.set(client.clientId, {
@@ -5416,6 +5698,52 @@ var SASjsApi = (() => {
5416
5698
  });
5417
5699
  return input;
5418
5700
  }
5701
+ /**
5702
+ * The fixture this store would be seeded from now.
5703
+ *
5704
+ * A host that persists the store - the browser build keeps it beside the
5705
+ * drive - writes this object and seeds the next boot from it, so the file a
5706
+ * person reads and the object the store speaks are the same shape. Passwords
5707
+ * are carried because a seed needs them to sign in: the administration
5708
+ * records deliberately leave them out, and a snapshot that did too would be a
5709
+ * fixture no one could log into.
5710
+ *
5711
+ * Tokens and authorization codes are absent on purpose. They are credentials
5712
+ * with a lifetime, minted per session; a persisted one would authenticate a
5713
+ * caller after the pair it names had been rotated or revoked, which is the
5714
+ * failure a token store exists to prevent.
5715
+ *
5716
+ * An account with no local password - one a directory imported, or one
5717
+ * created and never given a password - is stated without one. Writing an
5718
+ * empty string would seed an account the equality check signs in with `''`,
5719
+ * while an absent password refuses every attempt, which is what this store
5720
+ * itself answers for that account.
5721
+ */
5722
+ snapshot() {
5723
+ return {
5724
+ format: IDENTITY_FORMAT,
5725
+ users: this.userList.map((user3) => {
5726
+ const password = this.passwords.get(user3.uid);
5727
+ return {
5728
+ ...user3,
5729
+ ...password === void 0 ? {} : { password }
5730
+ };
5731
+ }),
5732
+ groups: [...this.groupList.values()].map((group) => ({
5733
+ ...group,
5734
+ // the store holds members as uids; the fixture states them by username,
5735
+ // which is what the constructor resolves back - writing uids here would
5736
+ // seed a group whose membership matches no account
5737
+ users: group.users.map(
5738
+ (uid) => this.userList.find((user3) => user3.uid === uid)?.username
5739
+ ).filter((username) => username !== void 0)
5740
+ })),
5741
+ permissions: [...this.permissionList.values()].map((permission) => ({
5742
+ ...permission
5743
+ })),
5744
+ clients: [...this.clientRecords.values()].map((client) => ({ ...client }))
5745
+ };
5746
+ }
5419
5747
  };
5420
5748
 
5421
5749
  // src/corpus/drive.ts
@@ -6121,46 +6449,35 @@ var SASjsApi = (() => {
6121
6449
  {
6122
6450
  id: "deploy-unpublish",
6123
6451
  route: "DELETE /SASjsApi/drive/deploy",
6124
- description: "removes a published app stream and answers the status",
6452
+ description: "removes the app the id names, and says what went",
6125
6453
  request: {
6126
6454
  subject: SUBJECT,
6127
- body: { streamServiceName: "myApp", appLoc: "/Public/myApp" }
6455
+ body: { id: "6f1c1c1e-6a1e-4c4a-9d1a-1b2c3d4e5f60" }
6128
6456
  },
6129
- expect: { status: 200, body: { status: "success" } }
6130
- },
6131
- {
6132
- id: "deploy-unpublish-other-name",
6133
- route: "DELETE /SASjsApi/drive/deploy",
6134
- description: "removes the app by its folder when the name has been renamed",
6135
- request: {
6136
- subject: SUBJECT,
6137
- body: { streamServiceName: "renamed-app", appLoc: "/Public/myApp" }
6138
- },
6139
- expect: { status: 200, body: { status: "success" } }
6140
- },
6141
- {
6142
- id: "deploy-unpublish-no-stream-name",
6143
- route: "DELETE /SASjsApi/drive/deploy",
6144
- description: "refuses a body that does not say which stream to remove",
6145
- request: { subject: SUBJECT, body: { appLoc: "/Public/myApp" } },
6146
- expect: { status: 400, error: '"streamServiceName" is required' }
6457
+ expect: {
6458
+ status: 200,
6459
+ partial: {
6460
+ status: "success",
6461
+ app: { id: "6f1c1c1e-6a1e-4c4a-9d1a-1b2c3d4e5f60", name: "myApp" }
6462
+ }
6463
+ }
6147
6464
  },
6148
6465
  {
6149
- id: "deploy-unpublish-no-app-loc",
6466
+ id: "deploy-unpublish-no-id",
6150
6467
  route: "DELETE /SASjsApi/drive/deploy",
6151
- description: "refuses a body that does not say which folder to remove",
6152
- request: { subject: SUBJECT, body: { streamServiceName: "myApp" } },
6153
- expect: { status: 400, error: '"appLoc" is required' }
6468
+ description: "refuses a body that does not say which app to remove",
6469
+ request: { subject: SUBJECT, body: {} },
6470
+ expect: { status: 400, error: '"id" is required' }
6154
6471
  },
6155
6472
  {
6156
- id: "deploy-unpublish-unknown-folder",
6473
+ id: "deploy-unpublish-unknown-id",
6157
6474
  route: "DELETE /SASjsApi/drive/deploy",
6158
- description: "answers 404 for a folder nothing is published at",
6475
+ description: "answers 404 for an id the index does not hold",
6159
6476
  request: {
6160
6477
  subject: SUBJECT,
6161
- body: { streamServiceName: "myApp", appLoc: "/Public/not-an-app" }
6478
+ body: { id: "11111111-1111-4111-8111-111111111111" }
6162
6479
  },
6163
- expect: { status: 404, error: "No app is published at that folder." }
6480
+ expect: { status: 404, error: "No app is published with that id." }
6164
6481
  },
6165
6482
  // ------------------------------------------- the uploaded-archive route
6166
6483
  // The archive is expanded by the host, so what arrives here is the same tree
@@ -6253,6 +6570,72 @@ var SASjsApi = (() => {
6253
6570
  error: "The file tree exceeds the deploy limit: 10001 entries (maximum 10000)."
6254
6571
  }
6255
6572
  },
6573
+ // ------------------------------------------- a bundle that is an app
6574
+ // One deploy writes the tree and indexes the app, from the manifest at the
6575
+ // root of the archive. The id is minted, so the case pins what can be pinned:
6576
+ // the app exists, under the label the manifest states.
6577
+ {
6578
+ id: "deploy-publishes-an-app",
6579
+ route: "POST /SASjsApi/drive/deploy",
6580
+ description: "indexes a bundle as an app from the manifest it carries, in one request",
6581
+ request: {
6582
+ subject: SUBJECT,
6583
+ body: {
6584
+ appLoc: "/Public/apps/mario",
6585
+ fileTree: {
6586
+ members: [
6587
+ {
6588
+ name: "sasjs.app.json",
6589
+ type: "file",
6590
+ code: JSON.stringify({
6591
+ name: "Mario",
6592
+ streamWebFolder: "web",
6593
+ logo: "logo.png"
6594
+ })
6595
+ },
6596
+ {
6597
+ name: "services",
6598
+ type: "folder",
6599
+ members: [
6600
+ {
6601
+ name: "web",
6602
+ type: "folder",
6603
+ members: [
6604
+ { name: "index.html", type: "file", code: "<h1>Mario</h1>" }
6605
+ ]
6606
+ },
6607
+ { name: "run", type: "service", code: "%put hi;" }
6608
+ ]
6609
+ }
6610
+ ]
6611
+ }
6612
+ }
6613
+ },
6614
+ expect: {
6615
+ status: 200,
6616
+ partial: {
6617
+ status: "success",
6618
+ app: { name: "Mario" }
6619
+ }
6620
+ }
6621
+ },
6622
+ {
6623
+ id: "deploy-refuses-a-bad-manifest",
6624
+ route: "POST /SASjsApi/drive/deploy",
6625
+ description: "refuses a bundle whose manifest is not JSON",
6626
+ request: {
6627
+ subject: SUBJECT,
6628
+ body: {
6629
+ appLoc: "/Public/apps/bad-manifest",
6630
+ fileTree: {
6631
+ members: [{ name: "sasjs.app.json", type: "file", code: "{not json" }]
6632
+ }
6633
+ }
6634
+ },
6635
+ expect: {
6636
+ status: 400
6637
+ }
6638
+ },
6256
6639
  {
6257
6640
  id: "upload-refused-by-store",
6258
6641
  route: "POST /SASjsApi/drive/deploy/upload",
@@ -6553,9 +6936,9 @@ var SASjsApi = (() => {
6553
6936
  if (value === void 0 || value === null || value === "") return void 0;
6554
6937
  if (typeof value === "number")
6555
6938
  return Number.isFinite(value) ? value : void 0;
6556
- const text = String(value).trim();
6557
- if (!text) return void 0;
6558
- return /^[+-]?\d+$/.test(text) ? Number(text) : CODE_DEBUG;
6939
+ const text2 = String(value).trim();
6940
+ if (!text2) return void 0;
6941
+ return /^[+-]?\d+$/.test(text2) ? Number(text2) : CODE_DEBUG;
6559
6942
  };
6560
6943
  var pad = (value) => String(value).padStart(2, "0");
6561
6944
  var timestamp = (now) => [
@@ -8209,6 +8592,13 @@ var SASjsApi = (() => {
8209
8592
  ];
8210
8593
 
8211
8594
  // src/corpus/runner.ts
8595
+ var CORPUS_APP = {
8596
+ id: "6f1c1c1e-6a1e-4c4a-9d1a-1b2c3d4e5f60",
8597
+ name: "myApp",
8598
+ appLoc: "/Public/myApp",
8599
+ streamWebFolder: "web",
8600
+ publishedAt: "2026-01-01T00:00:00.000Z"
8601
+ };
8212
8602
  var servicesFor = (testCase) => {
8213
8603
  const identity = new MemoryIdentityStore(
8214
8604
  testCase.identity || DEFAULT_IDENTITY
@@ -8232,7 +8622,7 @@ var SASjsApi = (() => {
8232
8622
  directory: createDirectoryService(identity, CORPUS_DIRECTORY),
8233
8623
  identity: createIdentityService(identity),
8234
8624
  records: createRecordService(identity),
8235
- registry: new MemoryAppStreamRegistry(),
8625
+ appStream: createAppStreamService(new MemoryAppStreamStore([CORPUS_APP])),
8236
8626
  session: createSessionService(identity, runner),
8237
8627
  // no `runTimes` option: the default is the five the document names, so a
8238
8628
  // case is never refused for a reason that belongs to one host's install
@@ -8264,6 +8654,225 @@ var SASjsApi = (() => {
8264
8654
  throw error;
8265
8655
  }
8266
8656
  };
8657
+
8658
+ // src/appstream/store.ts
8659
+ var APP_STREAM_INDEX = "/.sasjs/apps.json";
8660
+ var isEntry = (value) => {
8661
+ if (typeof value !== "object" || value === null) return false;
8662
+ const entry = value;
8663
+ return typeof entry.id === "string" && typeof entry.name === "string" && typeof entry.appLoc === "string" && typeof entry.streamWebFolder === "string" && typeof entry.publishedAt === "string";
8664
+ };
8665
+ var createDriveAppStreamStore = (drive, filePath2 = APP_STREAM_INDEX) => ({
8666
+ async read() {
8667
+ let contents;
8668
+ try {
8669
+ contents = (await drive.read(filePath2)).contents;
8670
+ } catch (error) {
8671
+ if (error instanceof ApiError && error.status === 404) return [];
8672
+ throw error;
8673
+ }
8674
+ if (typeof contents !== "string")
8675
+ throw new ApiError(
8676
+ 500,
8677
+ `The app index at ${filePath2} is not text, so no app can be read from it.`
8678
+ );
8679
+ let parsed;
8680
+ try {
8681
+ parsed = JSON.parse(contents);
8682
+ } catch (error) {
8683
+ throw new ApiError(
8684
+ 500,
8685
+ `The app index at ${filePath2} is not valid JSON, so no app is registered: ${error.message}`
8686
+ );
8687
+ }
8688
+ if (!Array.isArray(parsed) || !parsed.every(isEntry))
8689
+ throw new ApiError(
8690
+ 500,
8691
+ `The app index at ${filePath2} is not a list of app entries, so no app is registered.`
8692
+ );
8693
+ return parsed;
8694
+ },
8695
+ async write(entries) {
8696
+ const contents = JSON.stringify(entries, null, 2);
8697
+ try {
8698
+ await drive.update(filePath2, contents);
8699
+ } catch (error) {
8700
+ if (error instanceof ApiError && error.status === 404) {
8701
+ await drive.save(filePath2, contents);
8702
+ return;
8703
+ }
8704
+ throw error;
8705
+ }
8706
+ }
8707
+ });
8708
+
8709
+ // src/appstream/web.ts
8710
+ var DEFAULT_APP_PATH = "/app";
8711
+ var NO_SUCH_APP = "There's no App Stream available here.";
8712
+ var ESCAPES = {
8713
+ "&": "&amp;",
8714
+ "<": "&lt;",
8715
+ ">": "&gt;",
8716
+ '"': "&quot;",
8717
+ "'": "&#39;"
8718
+ };
8719
+ var escapeHtml = (value) => value.replace(/[&<>"']/g, (character) => ESCAPES[character]);
8720
+ var CONTENT_TYPES = {
8721
+ html: "text/html; charset=utf-8",
8722
+ htm: "text/html; charset=utf-8",
8723
+ js: "text/javascript; charset=utf-8",
8724
+ mjs: "text/javascript; charset=utf-8",
8725
+ css: "text/css; charset=utf-8",
8726
+ json: "application/json; charset=utf-8",
8727
+ map: "application/json; charset=utf-8",
8728
+ txt: "text/plain; charset=utf-8",
8729
+ svg: "image/svg+xml",
8730
+ png: "image/png",
8731
+ jpg: "image/jpeg",
8732
+ jpeg: "image/jpeg",
8733
+ gif: "image/gif",
8734
+ webp: "image/webp",
8735
+ ico: "image/x-icon",
8736
+ woff: "font/woff",
8737
+ woff2: "font/woff2",
8738
+ ttf: "font/ttf",
8739
+ otf: "font/otf",
8740
+ wasm: "application/wasm",
8741
+ pdf: "application/pdf",
8742
+ zip: "application/zip"
8743
+ };
8744
+ var contentTypeFor = (filePath2) => {
8745
+ const extension = filePath2.slice(filePath2.lastIndexOf(".") + 1).toLowerCase();
8746
+ return CONTENT_TYPES[extension] ?? "application/octet-stream";
8747
+ };
8748
+ var cacheControlFor = (filePath2) => /\.[0-9a-f]{8,}\.[A-Za-z0-9]+$/.test(filePath2) ? "public, max-age=31536000, immutable" : "public, max-age=0, must-revalidate";
8749
+ var html = (status, markup) => ({
8750
+ status,
8751
+ body: markup,
8752
+ contentType: "text/html; charset=utf-8"
8753
+ });
8754
+ var json = (status, body) => ({
8755
+ status,
8756
+ body: JSON.stringify(body),
8757
+ contentType: "application/json; charset=utf-8"
8758
+ });
8759
+ var noSuchApp = () => html(404, `<!doctype html><html><body>${NO_SUCH_APP}</body></html>`);
8760
+ var methodNotAllowed = (allowed) => ({
8761
+ status: 405,
8762
+ body: JSON.stringify({ status: "failure", message: `${allowed} only.` }),
8763
+ contentType: "application/json; charset=utf-8",
8764
+ headers: { allow: allowed }
8765
+ });
8766
+ var decoded = (segment) => {
8767
+ try {
8768
+ return decodeURIComponent(segment);
8769
+ } catch (_) {
8770
+ return void 0;
8771
+ }
8772
+ };
8773
+ var createAppStreamWebService = (appStream, drive, options = {}) => {
8774
+ const base = (options.basePath ?? DEFAULT_APP_PATH).replace(/\/+$/, "");
8775
+ const title = options.title ?? "SASjs App Stream";
8776
+ const urlOf = (entry) => `${base}/${entry.id}/`;
8777
+ const rowOf = (entry) => ({
8778
+ id: entry.id,
8779
+ name: entry.name,
8780
+ appLoc: entry.appLoc,
8781
+ logo: entry.logo === void 0 ? null : `${urlOf(entry)}${entry.logo}`,
8782
+ url: urlOf(entry),
8783
+ publishedAt: entry.publishedAt ?? null
8784
+ });
8785
+ const apps = async (allow) => {
8786
+ const entries = await appStream.list(allow);
8787
+ return { apps: entries.map(rowOf) };
8788
+ };
8789
+ const landing = async (allow) => {
8790
+ const { apps: rows } = await apps(allow);
8791
+ const tiles = rows.length ? `<ul class="apps">${rows.map(
8792
+ (row) => `<li><a href="${escapeHtml(row.url)}">${escapeHtml(row.name)}</a><span class="loc">${escapeHtml(row.appLoc)}</span></li>`
8793
+ ).join("")}</ul>` : '<p class="empty">No apps have been published yet.</p>';
8794
+ return html(
8795
+ 200,
8796
+ [
8797
+ '<!doctype html><html lang="en"><head><meta charset="utf-8">',
8798
+ '<meta name="viewport" content="width=device-width,initial-scale=1">',
8799
+ `<title>${escapeHtml(title)}</title>`,
8800
+ "<style>",
8801
+ "body{font-family:system-ui,sans-serif;margin:2rem;color:#1f2430}",
8802
+ "h1{font-size:1.4rem}",
8803
+ "ul.apps{list-style:none;padding:0;display:grid;gap:.75rem;max-width:40rem}",
8804
+ "ul.apps li{display:flex;flex-direction:column;gap:.15rem;padding:.75rem 1rem;",
8805
+ "border:1px solid #d8dee9;border-radius:.5rem}",
8806
+ "ul.apps a{font-weight:600;text-decoration:none;color:#0b5cad}",
8807
+ ".loc{font-size:.8rem;color:#5b6472;font-family:ui-monospace,monospace}",
8808
+ ".empty{color:#5b6472}",
8809
+ "</style></head><body>",
8810
+ `<h1>${escapeHtml(title)}</h1>`,
8811
+ tiles,
8812
+ "</body></html>"
8813
+ ].join("")
8814
+ );
8815
+ };
8816
+ const resolve = async (segment, allow) => {
8817
+ const entries = await appStream.list(allow);
8818
+ const byId2 = entries.find((entry) => entry.id === segment);
8819
+ if (byId2) return byId2;
8820
+ const byName = entries.filter((entry) => entry.name === segment);
8821
+ return byName.length === 1 ? byName[0] : void 0;
8822
+ };
8823
+ const asset = async (entry, segments) => {
8824
+ const parts = segments.map(decoded);
8825
+ if (parts.some((part) => part === void 0)) return noSuchApp();
8826
+ const relative = parts.join("/") || "index.html";
8827
+ try {
8828
+ const file = await drive.read(
8829
+ `${entry.appLoc}/services/${entry.streamWebFolder}/${relative}`
8830
+ );
8831
+ return {
8832
+ status: 200,
8833
+ body: file.contents,
8834
+ contentType: contentTypeFor(relative),
8835
+ headers: { "cache-control": cacheControlFor(relative) }
8836
+ };
8837
+ } catch (error) {
8838
+ if (error instanceof ApiError && (error.status === 404 || error.status === 400))
8839
+ return noSuchApp();
8840
+ throw error;
8841
+ }
8842
+ };
8843
+ return {
8844
+ apps,
8845
+ landing,
8846
+ async request({ method, path, allow }) {
8847
+ const clean = (path.split(/[?#]/)[0] || "/").replace(/\/{2,}/g, "/");
8848
+ const relative = base === "" ? clean : clean === base ? "/" : clean.startsWith(`${base}/`) ? clean.slice(base.length) : null;
8849
+ if (relative === null) return noSuchApp();
8850
+ if (relative === "" || relative === "/" || relative === "/index.html") {
8851
+ if (method !== "GET") return methodNotAllowed("GET");
8852
+ return landing(allow);
8853
+ }
8854
+ if (relative === "/apps.json") {
8855
+ if (method !== "GET") return methodNotAllowed("GET");
8856
+ return json(200, await apps(allow));
8857
+ }
8858
+ const segments = relative.split("/").filter(Boolean);
8859
+ const key = decoded(segments[0]);
8860
+ if (key === void 0) return noSuchApp();
8861
+ if (method === "DELETE") {
8862
+ const entry2 = await resolve(key, allow);
8863
+ if (!entry2) return noSuchApp();
8864
+ const removed = await appStream.unpublish(entry2.id);
8865
+ return json(200, { status: "success", app: rowOf(removed) });
8866
+ }
8867
+ if (method !== "GET") return methodNotAllowed("GET, DELETE");
8868
+ const entry = await resolve(key, allow);
8869
+ if (!entry) return noSuchApp();
8870
+ if (segments.length === 1 && !relative.endsWith("/"))
8871
+ return { status: 301, location: urlOf(entry) };
8872
+ return asset(entry, segments.slice(1));
8873
+ }
8874
+ };
8875
+ };
8267
8876
  return __toCommonJS(index_exports);
8268
8877
  })();
8269
8878
  if (typeof self !== 'undefined') self.SASjsApi = SASjsApi