@sasjs/api 0.39.0 → 0.40.1
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.
- package/build/browser.js +513 -234
- package/build/cjs/appstream/bundle.js +125 -54
- package/build/cjs/appstream/service.js +140 -65
- package/build/cjs/appstream/store.js +12 -5
- package/build/cjs/appstream/web.js +17 -4
- package/build/cjs/corpus/app.js +37 -0
- package/build/cjs/corpus/deploy.js +113 -0
- package/build/cjs/corpus/runner.js +1 -1
- package/build/cjs/host/dispatch.js +59 -11
- package/build/cjs/index.js +8 -2
- package/build/cjs/routes/generated.js +13 -1
- package/build/esm/appstream/bundle.d.ts +56 -12
- package/build/esm/appstream/bundle.d.ts.map +1 -1
- package/build/esm/appstream/bundle.js +124 -53
- package/build/esm/appstream/service.d.ts +51 -11
- package/build/esm/appstream/service.d.ts.map +1 -1
- package/build/esm/appstream/service.js +137 -64
- package/build/esm/appstream/store.d.ts.map +1 -1
- package/build/esm/appstream/store.js +12 -5
- package/build/esm/appstream/web.d.ts +11 -1
- package/build/esm/appstream/web.d.ts.map +1 -1
- package/build/esm/appstream/web.js +15 -3
- package/build/esm/corpus/app.d.ts.map +1 -1
- package/build/esm/corpus/app.js +37 -0
- package/build/esm/corpus/deploy.d.ts.map +1 -1
- package/build/esm/corpus/deploy.js +113 -0
- package/build/esm/corpus/drive.d.ts +9 -0
- package/build/esm/corpus/drive.d.ts.map +1 -1
- package/build/esm/corpus/runner.d.ts.map +1 -1
- package/build/esm/corpus/runner.js +1 -1
- package/build/esm/host/dispatch.d.ts.map +1 -1
- package/build/esm/host/dispatch.js +60 -12
- package/build/esm/index.d.ts +3 -3
- package/build/esm/index.d.ts.map +1 -1
- package/build/esm/index.js +3 -3
- package/build/esm/routes/generated.d.ts.map +1 -1
- package/build/esm/routes/generated.js +13 -1
- package/package.json +1 -1
package/build/browser.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* @sasjs/api 0.
|
|
1
|
+
/* @sasjs/api 0.40.1 - the SASjs Server API, for a service worker. https://github.com/sasjs/api */
|
|
2
2
|
"use strict";
|
|
3
3
|
var SASjsApi = (() => {
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
@@ -26,10 +26,12 @@ var SASjsApi = (() => {
|
|
|
26
26
|
ADMIN_SIGNED_IN: () => ADMIN_SIGNED_IN,
|
|
27
27
|
ALWAYS_VISIBLE_ROUTES: () => ALWAYS_VISIBLE_ROUTES,
|
|
28
28
|
APP_CORPUS: () => APP_CORPUS,
|
|
29
|
+
APP_FOLDERS_ROOT: () => APP_FOLDERS_ROOT,
|
|
29
30
|
APP_MANIFEST: () => APP_MANIFEST,
|
|
30
31
|
APP_STREAM_INDEX: () => APP_STREAM_INDEX,
|
|
31
32
|
AUTH_CONFIG_CORPUS: () => AUTH_CONFIG_CORPUS,
|
|
32
33
|
ApiError: () => ApiError,
|
|
34
|
+
BACKEND_FOLDER: () => BACKEND_FOLDER,
|
|
33
35
|
BROWSER_INFO: () => BROWSER_INFO,
|
|
34
36
|
BUNDLE_NAME: () => BUNDLE_NAME,
|
|
35
37
|
CODE_CORPUS: () => CODE_CORPUS,
|
|
@@ -48,6 +50,7 @@ var SASjsApi = (() => {
|
|
|
48
50
|
DRIVE_CORPUS: () => DRIVE_CORPUS,
|
|
49
51
|
EMULATED_HEADER: () => EMULATED_HEADER,
|
|
50
52
|
EMULATED_HEADER_VALUE: () => EMULATED_HEADER_VALUE,
|
|
53
|
+
FRONTEND_FOLDER: () => FRONTEND_FOLDER,
|
|
51
54
|
HANDLED_ROUTES: () => HANDLED_ROUTES,
|
|
52
55
|
HOME_CORPUS: () => HOME_CORPUS,
|
|
53
56
|
IDENTITY_CORPUS: () => IDENTITY_CORPUS,
|
|
@@ -79,6 +82,7 @@ var SASjsApi = (() => {
|
|
|
79
82
|
VIYA_OVERLAY: () => VIYA_OVERLAY,
|
|
80
83
|
VIYA_TABLE: () => VIYA_TABLE,
|
|
81
84
|
VIYA_TARGET_VERSION: () => VIYA_TARGET_VERSION,
|
|
85
|
+
appRootOf: () => appRootOf,
|
|
82
86
|
appSummary: () => appSummary,
|
|
83
87
|
basename: () => basename,
|
|
84
88
|
cacheControlFor: () => cacheControlFor,
|
|
@@ -109,7 +113,9 @@ var SASjsApi = (() => {
|
|
|
109
113
|
escapeHtml: () => escapeHtml,
|
|
110
114
|
findRoute: () => findRoute,
|
|
111
115
|
findViyaOperation: () => findViyaOperation,
|
|
116
|
+
frontendFolderOf: () => frontendFolderOf,
|
|
112
117
|
hasBlockedExtension: () => hasBlockedExtension,
|
|
118
|
+
hasFrontendRoot: () => hasFrontendRoot,
|
|
113
119
|
isApiError: () => isApiError,
|
|
114
120
|
isAppId: () => isAppId,
|
|
115
121
|
isDeployTree: () => isDeployTree,
|
|
@@ -1213,7 +1219,13 @@ var SASjsApi = (() => {
|
|
|
1213
1219
|
{
|
|
1214
1220
|
name: "appLoc",
|
|
1215
1221
|
in: "body",
|
|
1216
|
-
required:
|
|
1222
|
+
required: false,
|
|
1223
|
+
type: "string"
|
|
1224
|
+
},
|
|
1225
|
+
{
|
|
1226
|
+
name: "name",
|
|
1227
|
+
in: "body",
|
|
1228
|
+
required: false,
|
|
1217
1229
|
type: "string"
|
|
1218
1230
|
},
|
|
1219
1231
|
{
|
|
@@ -1274,6 +1286,12 @@ var SASjsApi = (() => {
|
|
|
1274
1286
|
tag: "Drive",
|
|
1275
1287
|
summary: "Deploy an uploaded file to SASjs Drive",
|
|
1276
1288
|
params: [
|
|
1289
|
+
{
|
|
1290
|
+
name: "name",
|
|
1291
|
+
in: "query",
|
|
1292
|
+
required: false,
|
|
1293
|
+
type: "string"
|
|
1294
|
+
},
|
|
1277
1295
|
{
|
|
1278
1296
|
name: "appLoc",
|
|
1279
1297
|
in: "query",
|
|
@@ -6061,6 +6079,8 @@ var SASjsApi = (() => {
|
|
|
6061
6079
|
var isAppId = (value) => typeof value === "string" && APP_ID.test(value);
|
|
6062
6080
|
|
|
6063
6081
|
// src/appstream/service.ts
|
|
6082
|
+
var APP_FOLDERS_ROOT = "apps";
|
|
6083
|
+
var frontendFolderOf = (name) => `/${APP_FOLDERS_ROOT}/${name}`;
|
|
6064
6084
|
var appSummary = (entry) => ({
|
|
6065
6085
|
id: entry.id,
|
|
6066
6086
|
name: entry.name,
|
|
@@ -6102,29 +6122,65 @@ var SASjsApi = (() => {
|
|
|
6102
6122
|
const children = services?.members;
|
|
6103
6123
|
return Array.isArray(children) && children.some((member) => isFolder(member, streamWebFolder));
|
|
6104
6124
|
};
|
|
6125
|
+
var hasFrontendRoot = (tree) => {
|
|
6126
|
+
const members = tree?.members;
|
|
6127
|
+
if (!Array.isArray(members)) return false;
|
|
6128
|
+
return members.some((member) => {
|
|
6129
|
+
const entry = member;
|
|
6130
|
+
return entry?.type === "file" && entry?.name === "index.html";
|
|
6131
|
+
});
|
|
6132
|
+
};
|
|
6105
6133
|
var checkPublishRequest = (request, tree, options = {}) => {
|
|
6106
|
-
const appLoc = appLocOf(request.appLoc);
|
|
6107
|
-
if (appLoc === "/")
|
|
6108
|
-
throw new ApiError(400, "An app cannot be published at the drive root.");
|
|
6109
6134
|
const logo = logoOf(request.logo);
|
|
6110
6135
|
const frameAncestors = frameAncestorsOf(request.frameAncestors);
|
|
6111
|
-
const
|
|
6112
|
-
if (
|
|
6136
|
+
const timing = request.publishedAt === void 0 ? {} : { publishedAt: request.publishedAt };
|
|
6137
|
+
if (request.streamWebFolder !== void 0) {
|
|
6138
|
+
if (request.appLoc === void 0)
|
|
6139
|
+
throw new ApiError(
|
|
6140
|
+
400,
|
|
6141
|
+
'"appLoc" is required when "streamWebFolder" is stated: the entry keeps its web assets at <appLoc>/services/<streamWebFolder>, so both halves are needed to say where they are.'
|
|
6142
|
+
);
|
|
6143
|
+
const appLoc2 = appLocOf(request.appLoc);
|
|
6144
|
+
if (appLoc2 === "/")
|
|
6145
|
+
throw new ApiError(400, "An app cannot be published at the drive root.");
|
|
6146
|
+
const streamWebFolder = webFolderOf(request.streamWebFolder);
|
|
6147
|
+
if (tree !== void 0 && !hasStreamFolder(tree, streamWebFolder))
|
|
6148
|
+
throw new ApiError(
|
|
6149
|
+
400,
|
|
6150
|
+
`The deployed tree has no "services/${streamWebFolder}" folder, so nothing would be published at ${appLoc2}. Deploy the web assets under services/${streamWebFolder}, or ${options.folderFromManifest ? "correct the folder sasjs.app.json names." : "omit streamWebFolder."}`
|
|
6151
|
+
);
|
|
6152
|
+
return {
|
|
6153
|
+
appLoc: appLoc2,
|
|
6154
|
+
streamWebFolder,
|
|
6155
|
+
...request.name === void 0 ? {} : { name: nameOf(request.name) },
|
|
6156
|
+
...logo === void 0 ? {} : { logo },
|
|
6157
|
+
...frameAncestors === void 0 ? {} : { frameAncestors },
|
|
6158
|
+
...timing
|
|
6159
|
+
};
|
|
6160
|
+
}
|
|
6161
|
+
if (request.name === void 0)
|
|
6113
6162
|
throw new ApiError(
|
|
6114
6163
|
400,
|
|
6115
|
-
|
|
6164
|
+
'"name" is required: an app is published at apps/<name>, so the publish has to say what it is called.'
|
|
6165
|
+
);
|
|
6166
|
+
const name = nameOf(request.name);
|
|
6167
|
+
const appLoc = request.appLoc === void 0 ? void 0 : appLocOf(request.appLoc);
|
|
6168
|
+
if (appLoc === "/")
|
|
6169
|
+
throw new ApiError(400, "An app cannot name the drive root as its backend.");
|
|
6170
|
+
if (tree !== void 0 && !hasFrontendRoot(tree))
|
|
6171
|
+
throw new ApiError(
|
|
6172
|
+
400,
|
|
6173
|
+
`The deployed tree has no "index.html" at its root, so nothing would be published at apps/${name}. Publish the compiled web folder itself, not the folder that holds it.`
|
|
6116
6174
|
);
|
|
6117
6175
|
return {
|
|
6118
|
-
|
|
6119
|
-
|
|
6120
|
-
...request.name === void 0 ? {} : { name: nameOf(request.name, appLoc) },
|
|
6176
|
+
name,
|
|
6177
|
+
...appLoc === void 0 ? {} : { appLoc },
|
|
6121
6178
|
...logo === void 0 ? {} : { logo },
|
|
6122
6179
|
...frameAncestors === void 0 ? {} : { frameAncestors },
|
|
6123
|
-
...
|
|
6180
|
+
...timing
|
|
6124
6181
|
};
|
|
6125
6182
|
};
|
|
6126
|
-
var nameOf = (value
|
|
6127
|
-
if (value === void 0) return defaultAppName(appLoc);
|
|
6183
|
+
var nameOf = (value) => {
|
|
6128
6184
|
if (typeof value !== "string" || value.trim() === "")
|
|
6129
6185
|
throw new ApiError(400, '"name" must be a non-empty string');
|
|
6130
6186
|
return urlSafeName(value.trim());
|
|
@@ -6193,31 +6249,28 @@ var SASjsApi = (() => {
|
|
|
6193
6249
|
return void 0;
|
|
6194
6250
|
}
|
|
6195
6251
|
const entry = (await store.read()).find(
|
|
6196
|
-
(candidate) => sameAppLoc(candidate.appLoc, normalised)
|
|
6252
|
+
(candidate) => candidate.streamWebFolder !== void 0 && candidate.appLoc !== void 0 && sameAppLoc(candidate.appLoc, normalised)
|
|
6197
6253
|
);
|
|
6198
6254
|
return entry ? { ...entry } : void 0;
|
|
6199
6255
|
},
|
|
6200
6256
|
publish(request) {
|
|
6201
6257
|
return mutate(async () => {
|
|
6202
6258
|
const checked = checkPublishRequest(request);
|
|
6203
|
-
const appLoc = checked.appLoc;
|
|
6204
|
-
const streamWebFolder = checked.streamWebFolder;
|
|
6205
6259
|
const entries = await store.read();
|
|
6206
|
-
const
|
|
6207
|
-
|
|
6208
|
-
);
|
|
6260
|
+
const legacy = checked.streamWebFolder !== void 0;
|
|
6261
|
+
const sameTarget = (candidate) => legacy ? candidate.streamWebFolder !== void 0 && candidate.appLoc !== void 0 && sameAppLoc(candidate.appLoc, checked.appLoc) : candidate.streamWebFolder === void 0 && candidate.name === checked.name;
|
|
6262
|
+
const existing = entries.find(sameTarget);
|
|
6209
6263
|
const logo = checked.logo;
|
|
6210
6264
|
const frameAncestors = checked.frameAncestors;
|
|
6211
|
-
const
|
|
6212
|
-
|
|
6213
|
-
if (statedName !== void 0) {
|
|
6265
|
+
const name = legacy ? checked.name ?? existing?.name ?? defaultAppName(checked.appLoc) : checked.name;
|
|
6266
|
+
if (!legacy || checked.name !== void 0) {
|
|
6214
6267
|
const clash = entries.find(
|
|
6215
|
-
(candidate) =>
|
|
6268
|
+
(candidate) => candidate !== existing && candidate.name.toLowerCase() === name.toLowerCase()
|
|
6216
6269
|
);
|
|
6217
6270
|
if (clash)
|
|
6218
6271
|
throw new ApiError(
|
|
6219
6272
|
409,
|
|
6220
|
-
`The name "${name}" is already the address of the app
|
|
6273
|
+
`The name "${name}" is already the address of the app at ${clash.appLoc ?? frontendFolderOf(clash.name)}. An app's name is how it opens (/app/${name}), and two apps holding one name would answer an ambiguous lookup with nothing, so publish this one under a different name.`
|
|
6221
6274
|
);
|
|
6222
6275
|
}
|
|
6223
6276
|
const entry = {
|
|
@@ -6225,16 +6278,14 @@ var SASjsApi = (() => {
|
|
|
6225
6278
|
// the label is the one field a redeploy inherits: everything else is
|
|
6226
6279
|
// what this publish states
|
|
6227
6280
|
name,
|
|
6228
|
-
appLoc,
|
|
6229
|
-
streamWebFolder,
|
|
6281
|
+
...checked.appLoc === void 0 ? {} : { appLoc: checked.appLoc },
|
|
6282
|
+
...checked.streamWebFolder === void 0 ? {} : { streamWebFolder: checked.streamWebFolder },
|
|
6230
6283
|
...logo === void 0 ? {} : { logo },
|
|
6231
6284
|
...frameAncestors === void 0 ? {} : { frameAncestors },
|
|
6232
6285
|
publishedAt: checked.publishedAt ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
6233
6286
|
};
|
|
6234
6287
|
await store.write([
|
|
6235
|
-
...entries.filter(
|
|
6236
|
-
(candidate) => !sameAppLoc(candidate.appLoc, appLoc)
|
|
6237
|
-
),
|
|
6288
|
+
...entries.filter((candidate) => !sameTarget(candidate)),
|
|
6238
6289
|
entry
|
|
6239
6290
|
]);
|
|
6240
6291
|
return { ...entry };
|
|
@@ -6265,8 +6316,179 @@ var SASjsApi = (() => {
|
|
|
6265
6316
|
}
|
|
6266
6317
|
};
|
|
6267
6318
|
|
|
6319
|
+
// src/appstream/web.ts
|
|
6320
|
+
var DEFAULT_APP_PATH = "/app";
|
|
6321
|
+
var NO_SUCH_APP = "There's no App Stream available here.";
|
|
6322
|
+
var ESCAPES = {
|
|
6323
|
+
"&": "&",
|
|
6324
|
+
"<": "<",
|
|
6325
|
+
">": ">",
|
|
6326
|
+
'"': """,
|
|
6327
|
+
"'": "'"
|
|
6328
|
+
};
|
|
6329
|
+
var escapeHtml = (value) => value.replace(/[&<>"']/g, (character) => ESCAPES[character]);
|
|
6330
|
+
var CONTENT_TYPES = {
|
|
6331
|
+
html: "text/html; charset=utf-8",
|
|
6332
|
+
htm: "text/html; charset=utf-8",
|
|
6333
|
+
js: "text/javascript; charset=utf-8",
|
|
6334
|
+
mjs: "text/javascript; charset=utf-8",
|
|
6335
|
+
css: "text/css; charset=utf-8",
|
|
6336
|
+
json: "application/json; charset=utf-8",
|
|
6337
|
+
map: "application/json; charset=utf-8",
|
|
6338
|
+
txt: "text/plain; charset=utf-8",
|
|
6339
|
+
svg: "image/svg+xml",
|
|
6340
|
+
png: "image/png",
|
|
6341
|
+
jpg: "image/jpeg",
|
|
6342
|
+
jpeg: "image/jpeg",
|
|
6343
|
+
gif: "image/gif",
|
|
6344
|
+
webp: "image/webp",
|
|
6345
|
+
ico: "image/x-icon",
|
|
6346
|
+
woff: "font/woff",
|
|
6347
|
+
woff2: "font/woff2",
|
|
6348
|
+
ttf: "font/ttf",
|
|
6349
|
+
otf: "font/otf",
|
|
6350
|
+
wasm: "application/wasm",
|
|
6351
|
+
pdf: "application/pdf",
|
|
6352
|
+
zip: "application/zip"
|
|
6353
|
+
};
|
|
6354
|
+
var contentTypeFor = (filePath2) => {
|
|
6355
|
+
const extension = filePath2.slice(filePath2.lastIndexOf(".") + 1).toLowerCase();
|
|
6356
|
+
return CONTENT_TYPES[extension] ?? "application/octet-stream";
|
|
6357
|
+
};
|
|
6358
|
+
var cacheControlFor = (filePath2) => /\.[0-9a-f]{8,}\.[A-Za-z0-9]+$/.test(filePath2) ? "public, max-age=31536000, immutable" : "public, max-age=0, must-revalidate";
|
|
6359
|
+
var html = (status, markup) => ({
|
|
6360
|
+
status,
|
|
6361
|
+
body: markup,
|
|
6362
|
+
contentType: "text/html; charset=utf-8"
|
|
6363
|
+
});
|
|
6364
|
+
var json = (status, body) => ({
|
|
6365
|
+
status,
|
|
6366
|
+
body: JSON.stringify(body),
|
|
6367
|
+
contentType: "application/json; charset=utf-8"
|
|
6368
|
+
});
|
|
6369
|
+
var noSuchApp = () => html(404, `<!doctype html><html><body>${NO_SUCH_APP}</body></html>`);
|
|
6370
|
+
var methodNotAllowed = (allowed) => ({
|
|
6371
|
+
status: 405,
|
|
6372
|
+
body: JSON.stringify({ status: "failure", message: `${allowed} only.` }),
|
|
6373
|
+
contentType: "application/json; charset=utf-8",
|
|
6374
|
+
headers: { allow: allowed }
|
|
6375
|
+
});
|
|
6376
|
+
var decoded = (segment) => {
|
|
6377
|
+
try {
|
|
6378
|
+
return decodeURIComponent(segment);
|
|
6379
|
+
} catch (_) {
|
|
6380
|
+
return void 0;
|
|
6381
|
+
}
|
|
6382
|
+
};
|
|
6383
|
+
var appRootOf = (entry) => entry.streamWebFolder !== void 0 && entry.appLoc !== void 0 ? `${entry.appLoc}/services/${entry.streamWebFolder}` : frontendFolderOf(entry.name);
|
|
6384
|
+
var createAppStreamWebService = (appStream, drive, options = {}) => {
|
|
6385
|
+
const base = (options.basePath ?? DEFAULT_APP_PATH).replace(/\/+$/, "");
|
|
6386
|
+
const title = options.title ?? "SASjs App Stream";
|
|
6387
|
+
const urlOf = (entry) => `${base}/${entry.id}/`;
|
|
6388
|
+
const rowOf = (entry) => ({
|
|
6389
|
+
id: entry.id,
|
|
6390
|
+
name: entry.name,
|
|
6391
|
+
appLoc: entry.appLoc ?? null,
|
|
6392
|
+
logo: entry.logo === void 0 ? null : `${urlOf(entry)}${entry.logo}`,
|
|
6393
|
+
url: urlOf(entry),
|
|
6394
|
+
publishedAt: entry.publishedAt ?? null
|
|
6395
|
+
});
|
|
6396
|
+
const apps = async (allow) => {
|
|
6397
|
+
const entries = await appStream.list(allow);
|
|
6398
|
+
return { apps: entries.map(rowOf) };
|
|
6399
|
+
};
|
|
6400
|
+
const landing = async (allow) => {
|
|
6401
|
+
const { apps: rows } = await apps(allow);
|
|
6402
|
+
const tiles = rows.length ? `<ul class="apps">${rows.map(
|
|
6403
|
+
(row) => `<li><a href="${escapeHtml(row.url)}">${escapeHtml(row.name)}</a><span class="loc">${escapeHtml(
|
|
6404
|
+
row.appLoc ?? frontendFolderOf(row.name)
|
|
6405
|
+
)}</span></li>`
|
|
6406
|
+
).join("")}</ul>` : '<p class="empty">No apps have been published yet.</p>';
|
|
6407
|
+
return html(
|
|
6408
|
+
200,
|
|
6409
|
+
[
|
|
6410
|
+
'<!doctype html><html lang="en"><head><meta charset="utf-8">',
|
|
6411
|
+
'<meta name="viewport" content="width=device-width,initial-scale=1">',
|
|
6412
|
+
`<title>${escapeHtml(title)}</title>`,
|
|
6413
|
+
"<style>",
|
|
6414
|
+
"body{font-family:system-ui,sans-serif;margin:2rem;color:#1f2430}",
|
|
6415
|
+
"h1{font-size:1.4rem}",
|
|
6416
|
+
"ul.apps{list-style:none;padding:0;display:grid;gap:.75rem;max-width:40rem}",
|
|
6417
|
+
"ul.apps li{display:flex;flex-direction:column;gap:.15rem;padding:.75rem 1rem;",
|
|
6418
|
+
"border:1px solid #d8dee9;border-radius:.5rem}",
|
|
6419
|
+
"ul.apps a{font-weight:600;text-decoration:none;color:#0b5cad}",
|
|
6420
|
+
".loc{font-size:.8rem;color:#5b6472;font-family:ui-monospace,monospace}",
|
|
6421
|
+
".empty{color:#5b6472}",
|
|
6422
|
+
"</style></head><body>",
|
|
6423
|
+
`<h1>${escapeHtml(title)}</h1>`,
|
|
6424
|
+
tiles,
|
|
6425
|
+
"</body></html>"
|
|
6426
|
+
].join("")
|
|
6427
|
+
);
|
|
6428
|
+
};
|
|
6429
|
+
const resolve = async (segment, allow) => {
|
|
6430
|
+
const entries = await appStream.list(allow);
|
|
6431
|
+
const byId2 = entries.find((entry) => entry.id === segment);
|
|
6432
|
+
if (byId2) return byId2;
|
|
6433
|
+
const byName = entries.filter((entry) => entry.name === segment);
|
|
6434
|
+
return byName.length === 1 ? byName[0] : void 0;
|
|
6435
|
+
};
|
|
6436
|
+
const asset = async (entry, segments) => {
|
|
6437
|
+
const parts = segments.map(decoded);
|
|
6438
|
+
if (parts.some((part) => part === void 0)) return noSuchApp();
|
|
6439
|
+
const relative = parts.join("/") || "index.html";
|
|
6440
|
+
try {
|
|
6441
|
+
const file = await drive.read(`${appRootOf(entry)}/${relative}`);
|
|
6442
|
+
return {
|
|
6443
|
+
status: 200,
|
|
6444
|
+
body: file.contents,
|
|
6445
|
+
contentType: contentTypeFor(relative),
|
|
6446
|
+
headers: { "cache-control": cacheControlFor(relative) }
|
|
6447
|
+
};
|
|
6448
|
+
} catch (error) {
|
|
6449
|
+
if (error instanceof ApiError && (error.status === 404 || error.status === 400))
|
|
6450
|
+
return noSuchApp();
|
|
6451
|
+
throw error;
|
|
6452
|
+
}
|
|
6453
|
+
};
|
|
6454
|
+
return {
|
|
6455
|
+
apps,
|
|
6456
|
+
landing,
|
|
6457
|
+
async request({ method, path, allow }) {
|
|
6458
|
+
const clean = (path.split(/[?#]/)[0] || "/").replace(/\/{2,}/g, "/");
|
|
6459
|
+
const relative = base === "" ? clean : clean === base ? "/" : clean.startsWith(`${base}/`) ? clean.slice(base.length) : null;
|
|
6460
|
+
if (relative === null) return noSuchApp();
|
|
6461
|
+
if (relative === "" || relative === "/" || relative === "/index.html") {
|
|
6462
|
+
if (method !== "GET") return methodNotAllowed("GET");
|
|
6463
|
+
return landing(allow);
|
|
6464
|
+
}
|
|
6465
|
+
if (relative === "/apps.json") {
|
|
6466
|
+
if (method !== "GET") return methodNotAllowed("GET");
|
|
6467
|
+
return json(200, await apps(allow));
|
|
6468
|
+
}
|
|
6469
|
+
const segments = relative.split("/").filter(Boolean);
|
|
6470
|
+
const key = decoded(segments[0]);
|
|
6471
|
+
if (key === void 0) return noSuchApp();
|
|
6472
|
+
if (method === "DELETE") {
|
|
6473
|
+
const entry2 = await resolve(key, allow);
|
|
6474
|
+
if (!entry2) return noSuchApp();
|
|
6475
|
+
const removed = await appStream.unpublish(entry2.id);
|
|
6476
|
+
return json(200, { status: "success", app: rowOf(removed) });
|
|
6477
|
+
}
|
|
6478
|
+
if (method !== "GET") return methodNotAllowed("GET, DELETE");
|
|
6479
|
+
const entry = await resolve(key, allow);
|
|
6480
|
+
if (!entry) return noSuchApp();
|
|
6481
|
+
if (segments.length === 1 && !relative.endsWith("/"))
|
|
6482
|
+
return { status: 301, location: urlOf(entry) };
|
|
6483
|
+
return asset(entry, segments.slice(1));
|
|
6484
|
+
}
|
|
6485
|
+
};
|
|
6486
|
+
};
|
|
6487
|
+
|
|
6268
6488
|
// src/appstream/bundle.ts
|
|
6269
6489
|
var APP_MANIFEST = "sasjs.app.json";
|
|
6490
|
+
var FRONTEND_FOLDER = "web";
|
|
6491
|
+
var BACKEND_FOLDER = "backend";
|
|
6270
6492
|
var isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
6271
6493
|
var text = (value, field) => {
|
|
6272
6494
|
if (value === void 0) return void 0;
|
|
@@ -6280,14 +6502,15 @@ var SASjsApi = (() => {
|
|
|
6280
6502
|
var parseAppManifest = (value) => {
|
|
6281
6503
|
if (!isObject(value))
|
|
6282
6504
|
throw new ApiError(400, `${APP_MANIFEST} must be an object.`);
|
|
6505
|
+
const name = text(value.name, "name");
|
|
6506
|
+
const appLoc = text(value.appLoc, "appLoc");
|
|
6283
6507
|
const streamWebFolder = text(value.streamWebFolder, "streamWebFolder");
|
|
6284
|
-
|
|
6508
|
+
const logo = text(value.logo, "logo");
|
|
6509
|
+
if (streamWebFolder !== void 0 && /[\\/]/.test(streamWebFolder))
|
|
6285
6510
|
throw new ApiError(
|
|
6286
6511
|
400,
|
|
6287
|
-
|
|
6512
|
+
`"streamWebFolder" in ${APP_MANIFEST} must be a single path segment.`
|
|
6288
6513
|
);
|
|
6289
|
-
const name = text(value.name, "name");
|
|
6290
|
-
const logo = text(value.logo, "logo");
|
|
6291
6514
|
const frameAncestors = value.frameAncestors;
|
|
6292
6515
|
if (frameAncestors !== void 0 && (typeof frameAncestors !== "string" || frameAncestors === "") && !(Array.isArray(frameAncestors) && frameAncestors.length > 0 && frameAncestors.every(
|
|
6293
6516
|
(source) => typeof source === "string" && source !== ""
|
|
@@ -6298,50 +6521,81 @@ var SASjsApi = (() => {
|
|
|
6298
6521
|
);
|
|
6299
6522
|
return {
|
|
6300
6523
|
...name === void 0 ? {} : { name },
|
|
6301
|
-
|
|
6524
|
+
...appLoc === void 0 ? {} : { appLoc },
|
|
6525
|
+
...streamWebFolder === void 0 ? {} : { streamWebFolder },
|
|
6302
6526
|
...logo === void 0 ? {} : { logo },
|
|
6303
6527
|
...frameAncestors === void 0 ? {} : { frameAncestors }
|
|
6304
6528
|
};
|
|
6305
6529
|
};
|
|
6530
|
+
var folderNamed = (members, name) => members.find(
|
|
6531
|
+
(member) => isObject(member) && member.type === "folder" && member.name === name
|
|
6532
|
+
);
|
|
6533
|
+
var contentsOf = (member) => {
|
|
6534
|
+
const members = member?.members;
|
|
6535
|
+
return Array.isArray(members) ? { members } : void 0;
|
|
6536
|
+
};
|
|
6306
6537
|
var splitAppBundle = (tree) => {
|
|
6307
6538
|
if (!isObject(tree) || !Array.isArray(tree.members))
|
|
6308
6539
|
return { tree };
|
|
6309
6540
|
const members = tree.members;
|
|
6310
6541
|
const at = members.findIndex(
|
|
6311
|
-
(
|
|
6542
|
+
(member) => isObject(member) && member.type === "file" && member.name === APP_MANIFEST
|
|
6312
6543
|
);
|
|
6313
|
-
|
|
6314
|
-
|
|
6315
|
-
if (
|
|
6316
|
-
|
|
6317
|
-
|
|
6318
|
-
|
|
6319
|
-
|
|
6320
|
-
|
|
6321
|
-
|
|
6322
|
-
|
|
6323
|
-
|
|
6324
|
-
|
|
6544
|
+
const withoutManifest = at === -1 ? members : members.filter((_, index) => index !== at);
|
|
6545
|
+
let manifest;
|
|
6546
|
+
if (at !== -1) {
|
|
6547
|
+
const member = members[at];
|
|
6548
|
+
if (typeof member.code !== "string")
|
|
6549
|
+
throw new ApiError(400, `${APP_MANIFEST} carries no text.`);
|
|
6550
|
+
const source = member.encoding === "base64" ? new TextDecoder().decode(decodeBase64(member.code)) : member.code;
|
|
6551
|
+
let parsed;
|
|
6552
|
+
try {
|
|
6553
|
+
parsed = JSON.parse(source);
|
|
6554
|
+
} catch (error) {
|
|
6555
|
+
throw new ApiError(
|
|
6556
|
+
400,
|
|
6557
|
+
`${APP_MANIFEST} is not valid JSON: ${error.message}`
|
|
6558
|
+
);
|
|
6559
|
+
}
|
|
6560
|
+
manifest = parseAppManifest(parsed);
|
|
6325
6561
|
}
|
|
6562
|
+
const rest = { ...tree, members: withoutManifest };
|
|
6563
|
+
const web = folderNamed(withoutManifest, FRONTEND_FOLDER);
|
|
6564
|
+
if (web === void 0 && manifest === void 0)
|
|
6565
|
+
return { tree };
|
|
6566
|
+
if (manifest?.streamWebFolder !== void 0) return { tree: rest, manifest };
|
|
6567
|
+
const backend = contentsOf(folderNamed(withoutManifest, BACKEND_FOLDER));
|
|
6326
6568
|
return {
|
|
6327
|
-
tree:
|
|
6328
|
-
|
|
6329
|
-
members:
|
|
6569
|
+
tree: rest,
|
|
6570
|
+
frontend: contentsOf(web) ?? {
|
|
6571
|
+
members: withoutManifest.filter(
|
|
6572
|
+
(member) => member !== folderNamed(withoutManifest, BACKEND_FOLDER)
|
|
6573
|
+
)
|
|
6330
6574
|
},
|
|
6331
|
-
|
|
6575
|
+
...backend === void 0 ? {} : { backend },
|
|
6576
|
+
manifest
|
|
6332
6577
|
};
|
|
6333
6578
|
};
|
|
6334
|
-
var publishRequestFor = (deploy, manifest) => {
|
|
6579
|
+
var publishRequestFor = (deploy, manifest, options = {}) => {
|
|
6335
6580
|
const streamWebFolder = deploy.streamWebFolder ?? manifest?.streamWebFolder;
|
|
6336
|
-
|
|
6337
|
-
const name = deploy.streamServiceName ?? manifest?.name;
|
|
6581
|
+
const appLoc = deploy.appLoc ?? manifest?.appLoc;
|
|
6582
|
+
const name = deploy.name ?? deploy.streamServiceName ?? manifest?.name;
|
|
6338
6583
|
const logo = deploy.streamLogo ?? manifest?.logo;
|
|
6584
|
+
const frameAncestors = manifest?.frameAncestors;
|
|
6585
|
+
if (streamWebFolder !== void 0)
|
|
6586
|
+
return {
|
|
6587
|
+
...appLoc === void 0 ? {} : { appLoc },
|
|
6588
|
+
streamWebFolder,
|
|
6589
|
+
...name === void 0 ? {} : { name },
|
|
6590
|
+
...logo === void 0 ? {} : { logo },
|
|
6591
|
+
...frameAncestors === void 0 ? {} : { frameAncestors }
|
|
6592
|
+
};
|
|
6593
|
+
if (name === void 0 && !options.packaged) return void 0;
|
|
6339
6594
|
return {
|
|
6340
|
-
appLoc: deploy.appLoc,
|
|
6341
|
-
streamWebFolder,
|
|
6342
6595
|
...name === void 0 ? {} : { name },
|
|
6596
|
+
...appLoc === void 0 ? {} : { appLoc },
|
|
6343
6597
|
...logo === void 0 ? {} : { logo },
|
|
6344
|
-
...
|
|
6598
|
+
...frameAncestors === void 0 ? {} : { frameAncestors }
|
|
6345
6599
|
};
|
|
6346
6600
|
};
|
|
6347
6601
|
|
|
@@ -6610,21 +6864,60 @@ var SASjsApi = (() => {
|
|
|
6610
6864
|
case "POST /SASjsApi/drive/deploy/upload":
|
|
6611
6865
|
case "POST /SASjsApi/drive/deploy": {
|
|
6612
6866
|
const bundle = splitAppBundle(body.fileTree);
|
|
6867
|
+
const packaged = bundle.frontend !== void 0;
|
|
6613
6868
|
const isUpload = routeId === "POST /SASjsApi/drive/deploy/upload";
|
|
6614
6869
|
const setting = (name) => isUpload ? given(query[name]) ?? body?.[name] : body?.[name];
|
|
6615
|
-
const
|
|
6870
|
+
const statedAppLoc = given(setting("appLoc"));
|
|
6871
|
+
const appLoc = typeof statedAppLoc === "string" ? statedAppLoc : void 0;
|
|
6616
6872
|
const requested = services.appStream ? publishRequestFor(
|
|
6617
6873
|
{
|
|
6874
|
+
name: given(setting("name")),
|
|
6618
6875
|
appLoc,
|
|
6619
6876
|
streamWebFolder: given(setting("streamWebFolder")),
|
|
6620
6877
|
streamServiceName: given(setting("streamServiceName")),
|
|
6621
6878
|
streamLogo: given(setting("streamLogo"))
|
|
6622
6879
|
},
|
|
6623
|
-
bundle.manifest
|
|
6880
|
+
bundle.manifest,
|
|
6881
|
+
{ packaged }
|
|
6624
6882
|
) : void 0;
|
|
6625
6883
|
const folderFromManifest = requested?.streamWebFolder !== void 0 && given(setting("streamWebFolder")) === void 0 && bundle.manifest?.streamWebFolder !== void 0;
|
|
6626
|
-
const publish = requested === void 0 ? void 0 : checkPublishRequest(
|
|
6884
|
+
const publish = requested === void 0 ? void 0 : checkPublishRequest(
|
|
6885
|
+
requested,
|
|
6886
|
+
packaged ? bundle.frontend : bundle.tree,
|
|
6887
|
+
{ folderFromManifest }
|
|
6888
|
+
);
|
|
6889
|
+
if (packaged && publish === void 0)
|
|
6890
|
+
throw new ApiError(
|
|
6891
|
+
501,
|
|
6892
|
+
`This host has no app stream, so it cannot publish the frontend this bundle carries.`
|
|
6893
|
+
);
|
|
6894
|
+
if (publish !== void 0 && publish.streamWebFolder === void 0) {
|
|
6895
|
+
if (bundle.backend !== void 0 && publish.appLoc === void 0)
|
|
6896
|
+
throw new ApiError(
|
|
6897
|
+
400,
|
|
6898
|
+
'This bundle carries a "backend" folder but names no "appLoc" for it: state the backend folder in sasjs.app.json, or in the request.'
|
|
6899
|
+
);
|
|
6900
|
+
if (bundle.backend !== void 0)
|
|
6901
|
+
await drive.deploy(publish.appLoc, bundle.backend, {
|
|
6902
|
+
replace: false
|
|
6903
|
+
});
|
|
6904
|
+
await drive.deploy(
|
|
6905
|
+
frontendFolderOf(publish.name),
|
|
6906
|
+
packaged ? bundle.frontend : bundle.tree,
|
|
6907
|
+
{ replace: true }
|
|
6908
|
+
);
|
|
6909
|
+
const entry2 = await services.appStream.publish(publish);
|
|
6910
|
+
return {
|
|
6911
|
+
status: 200,
|
|
6912
|
+
body: { ...DEPLOY_SUCCESS, app: appSummary(entry2) }
|
|
6913
|
+
};
|
|
6914
|
+
}
|
|
6627
6915
|
const replace = replaceOf(setting("replace")) ?? isUpload;
|
|
6916
|
+
if (appLoc === void 0)
|
|
6917
|
+
throw new ApiError(
|
|
6918
|
+
400,
|
|
6919
|
+
'"appLoc" is required to deploy files that do not name an app.'
|
|
6920
|
+
);
|
|
6628
6921
|
await drive.deploy(appLoc, bundle.tree, { replace });
|
|
6629
6922
|
if (publish === void 0 || !services.appStream)
|
|
6630
6923
|
return { status: 200, body: DEPLOY_SUCCESS };
|
|
@@ -6662,7 +6955,7 @@ var SASjsApi = (() => {
|
|
|
6662
6955
|
if (isApiError(err) && err.status === 404) throw appNotRegistered();
|
|
6663
6956
|
throw err;
|
|
6664
6957
|
});
|
|
6665
|
-
const folder =
|
|
6958
|
+
const folder = appRootOf(entry);
|
|
6666
6959
|
let entryFileExists = false;
|
|
6667
6960
|
let lastModified = null;
|
|
6668
6961
|
try {
|
|
@@ -6679,8 +6972,13 @@ var SASjsApi = (() => {
|
|
|
6679
6972
|
const body2 = {
|
|
6680
6973
|
id: entry.id,
|
|
6681
6974
|
name: entry.name,
|
|
6682
|
-
|
|
6683
|
-
|
|
6975
|
+
// the folder the entry is read from, which is what this route describes:
|
|
6976
|
+
// `apps/<name>` for a frontend, and the legacy deployment's own folder for
|
|
6977
|
+
// the older shape. A host that answered one and not the other would leave
|
|
6978
|
+
// a client reading a path out of fields the entry may not carry.
|
|
6979
|
+
frontendFolder: folder,
|
|
6980
|
+
...entry.appLoc === void 0 ? {} : { appLoc: entry.appLoc },
|
|
6981
|
+
...entry.streamWebFolder === void 0 ? {} : { streamWebFolder: entry.streamWebFolder },
|
|
6684
6982
|
publishedAt: entry.publishedAt ?? null,
|
|
6685
6983
|
entryFile: APP_ENTRY_FILE,
|
|
6686
6984
|
entryFileExists,
|
|
@@ -9741,6 +10039,119 @@ var SASjsApi = (() => {
|
|
|
9741
10039
|
}
|
|
9742
10040
|
}
|
|
9743
10041
|
},
|
|
10042
|
+
{
|
|
10043
|
+
id: "deploy-publishes-a-package",
|
|
10044
|
+
route: "POST /SASjsApi/drive/deploy",
|
|
10045
|
+
description: "publishes a frontend to apps/<name> and writes the backend it carries to appLoc",
|
|
10046
|
+
request: {
|
|
10047
|
+
subject: SUBJECT,
|
|
10048
|
+
body: {
|
|
10049
|
+
fileTree: {
|
|
10050
|
+
members: [
|
|
10051
|
+
{
|
|
10052
|
+
name: "sasjs.app.json",
|
|
10053
|
+
type: "file",
|
|
10054
|
+
code: JSON.stringify({
|
|
10055
|
+
name: "macrodash",
|
|
10056
|
+
appLoc: "/Public/app/md"
|
|
10057
|
+
})
|
|
10058
|
+
},
|
|
10059
|
+
{
|
|
10060
|
+
name: "web",
|
|
10061
|
+
type: "folder",
|
|
10062
|
+
members: [
|
|
10063
|
+
{ name: "index.html", type: "file", code: "<h1>Dash</h1>" }
|
|
10064
|
+
]
|
|
10065
|
+
},
|
|
10066
|
+
{
|
|
10067
|
+
name: "backend",
|
|
10068
|
+
type: "folder",
|
|
10069
|
+
members: [
|
|
10070
|
+
{
|
|
10071
|
+
name: "services",
|
|
10072
|
+
type: "folder",
|
|
10073
|
+
members: [{ name: "run", type: "service", code: "%put hi;" }]
|
|
10074
|
+
}
|
|
10075
|
+
]
|
|
10076
|
+
}
|
|
10077
|
+
]
|
|
10078
|
+
}
|
|
10079
|
+
}
|
|
10080
|
+
},
|
|
10081
|
+
// the halves are named, so a host has to write them to two folders rather
|
|
10082
|
+
// than deploy the container: a status alone cannot see that
|
|
10083
|
+
expectDrive: {
|
|
10084
|
+
present: ["/apps/macrodash/index.html", "/Public/app/md/services/run.sas"]
|
|
10085
|
+
},
|
|
10086
|
+
expect: {
|
|
10087
|
+
status: 200,
|
|
10088
|
+
partial: {
|
|
10089
|
+
status: "success",
|
|
10090
|
+
app: { name: "macrodash" }
|
|
10091
|
+
}
|
|
10092
|
+
}
|
|
10093
|
+
},
|
|
10094
|
+
{
|
|
10095
|
+
id: "deploy-refuses-a-backend-with-no-apploc",
|
|
10096
|
+
route: "POST /SASjsApi/drive/deploy",
|
|
10097
|
+
description: "refuses a bundle carrying services that names no folder to deploy them to",
|
|
10098
|
+
request: {
|
|
10099
|
+
subject: SUBJECT,
|
|
10100
|
+
body: {
|
|
10101
|
+
fileTree: {
|
|
10102
|
+
members: [
|
|
10103
|
+
{
|
|
10104
|
+
name: "sasjs.app.json",
|
|
10105
|
+
type: "file",
|
|
10106
|
+
code: JSON.stringify({ name: "orphan-backend" })
|
|
10107
|
+
},
|
|
10108
|
+
{
|
|
10109
|
+
name: "web",
|
|
10110
|
+
type: "folder",
|
|
10111
|
+
members: [
|
|
10112
|
+
{ name: "index.html", type: "file", code: "<h1>orphan</h1>" }
|
|
10113
|
+
]
|
|
10114
|
+
},
|
|
10115
|
+
{
|
|
10116
|
+
name: "backend",
|
|
10117
|
+
type: "folder",
|
|
10118
|
+
members: [
|
|
10119
|
+
{
|
|
10120
|
+
name: "services",
|
|
10121
|
+
type: "folder",
|
|
10122
|
+
members: [{ name: "run", type: "service", code: "" }]
|
|
10123
|
+
}
|
|
10124
|
+
]
|
|
10125
|
+
}
|
|
10126
|
+
]
|
|
10127
|
+
}
|
|
10128
|
+
}
|
|
10129
|
+
},
|
|
10130
|
+
// both hosts refuse this the same way, and neither writes the frontend it
|
|
10131
|
+
// could have deployed: half a deployment is worse than none
|
|
10132
|
+
expectDrive: { missing: ["/apps/orphan-backend/index.html"] },
|
|
10133
|
+
expect: {
|
|
10134
|
+
status: 400,
|
|
10135
|
+
error: 'This bundle carries a "backend" folder but names no "appLoc" for it: state the backend folder in sasjs.app.json, or in the request.'
|
|
10136
|
+
}
|
|
10137
|
+
},
|
|
10138
|
+
{
|
|
10139
|
+
id: "deploy-refuses-a-bundle-that-names-no-folder",
|
|
10140
|
+
route: "POST /SASjsApi/drive/deploy",
|
|
10141
|
+
description: "refuses a tree with no app named and no folder to deploy to, naming the field",
|
|
10142
|
+
request: {
|
|
10143
|
+
subject: SUBJECT,
|
|
10144
|
+
body: {
|
|
10145
|
+
fileTree: {
|
|
10146
|
+
members: [{ name: "run", type: "service", code: "%put hi;" }]
|
|
10147
|
+
}
|
|
10148
|
+
}
|
|
10149
|
+
},
|
|
10150
|
+
expect: {
|
|
10151
|
+
status: 400,
|
|
10152
|
+
error: '"appLoc" is required to deploy files that do not name an app.'
|
|
10153
|
+
}
|
|
10154
|
+
},
|
|
9744
10155
|
{
|
|
9745
10156
|
id: "deploy-refuses-a-bad-manifest",
|
|
9746
10157
|
route: "POST /SASjsApi/drive/deploy",
|
|
@@ -10205,7 +10616,9 @@ var SASjsApi = (() => {
|
|
|
10205
10616
|
directory: createDirectoryService(identity, CORPUS_DIRECTORY),
|
|
10206
10617
|
identity: createIdentityService(identity),
|
|
10207
10618
|
records: createRecordService(identity),
|
|
10208
|
-
appStream: createAppStreamService(
|
|
10619
|
+
appStream: createAppStreamService(
|
|
10620
|
+
new MemoryAppStreamStore(testCase.appStream ?? [CORPUS_APP])
|
|
10621
|
+
),
|
|
10209
10622
|
session: createSessionService(identity, runner),
|
|
10210
10623
|
// no `runTimes` option: the default is the five the document names, so a
|
|
10211
10624
|
// case is never refused for a reason that belongs to one host's install
|
|
@@ -10262,6 +10675,12 @@ var SASjsApi = (() => {
|
|
|
10262
10675
|
|
|
10263
10676
|
// src/corpus/app.ts
|
|
10264
10677
|
var SUBJECT2 = { userId: "user-admin", clientId: "web_app" };
|
|
10678
|
+
var FRONTEND_APP = {
|
|
10679
|
+
id: "9d8c7b6a-5f4e-4d3c-8b2a-1f0e9d8c7b6a",
|
|
10680
|
+
name: "frontend-only",
|
|
10681
|
+
publishedAt: "2026-02-02T00:00:00.000Z"
|
|
10682
|
+
};
|
|
10683
|
+
var FRONTEND_ENTRY_FILE = `/apps/${FRONTEND_APP.name}/index.html`;
|
|
10265
10684
|
var ENTRY_FILE_PATH = `${CORPUS_APP.appLoc}/services/${CORPUS_APP.streamWebFolder}/index.html`;
|
|
10266
10685
|
var APP_CORPUS = [
|
|
10267
10686
|
{
|
|
@@ -10289,6 +10708,28 @@ var SASjsApi = (() => {
|
|
|
10289
10708
|
}
|
|
10290
10709
|
}
|
|
10291
10710
|
},
|
|
10711
|
+
{
|
|
10712
|
+
id: "app-detail-frontend",
|
|
10713
|
+
route: "GET /SASjsApi/app/{id}",
|
|
10714
|
+
description: "describes an app published as a frontend, from the folder its name derives",
|
|
10715
|
+
// the two shapes an index can hold, and the folder each is read from: this
|
|
10716
|
+
// entry names no `appLoc` and no `streamWebFolder`, so the folder has to come
|
|
10717
|
+
// from the name
|
|
10718
|
+
appStream: [FRONTEND_APP],
|
|
10719
|
+
seed: { [FRONTEND_ENTRY_FILE]: "<!doctype html><title>frontend</title>" },
|
|
10720
|
+
request: { subject: SUBJECT2, params: { id: FRONTEND_APP.id } },
|
|
10721
|
+
expect: {
|
|
10722
|
+
status: 200,
|
|
10723
|
+
partial: {
|
|
10724
|
+
id: FRONTEND_APP.id,
|
|
10725
|
+
name: FRONTEND_APP.name,
|
|
10726
|
+
frontendFolder: `/apps/${FRONTEND_APP.name}`,
|
|
10727
|
+
entryFile: "index.html",
|
|
10728
|
+
entryFileExists: true,
|
|
10729
|
+
url: `/app/${FRONTEND_APP.id}/`
|
|
10730
|
+
}
|
|
10731
|
+
}
|
|
10732
|
+
},
|
|
10292
10733
|
{
|
|
10293
10734
|
id: "app-detail-entry-file-missing",
|
|
10294
10735
|
route: "GET /SASjsApi/app/{id}",
|
|
@@ -11941,7 +12382,13 @@ var SASjsApi = (() => {
|
|
|
11941
12382
|
var isEntry = (value) => {
|
|
11942
12383
|
if (typeof value !== "object" || value === null) return false;
|
|
11943
12384
|
const entry = value;
|
|
11944
|
-
|
|
12385
|
+
if (typeof entry.id !== "string" || typeof entry.name !== "string" || typeof entry.publishedAt !== "string")
|
|
12386
|
+
return false;
|
|
12387
|
+
if (entry.appLoc !== void 0 && typeof entry.appLoc !== "string")
|
|
12388
|
+
return false;
|
|
12389
|
+
if (entry.streamWebFolder !== void 0 && typeof entry.streamWebFolder !== "string")
|
|
12390
|
+
return false;
|
|
12391
|
+
return !(entry.streamWebFolder !== void 0 && entry.appLoc === void 0);
|
|
11945
12392
|
};
|
|
11946
12393
|
var createDriveAppStreamStore = (drive, filePath2 = APP_STREAM_INDEX) => ({
|
|
11947
12394
|
async read() {
|
|
@@ -11986,174 +12433,6 @@ var SASjsApi = (() => {
|
|
|
11986
12433
|
}
|
|
11987
12434
|
}
|
|
11988
12435
|
});
|
|
11989
|
-
|
|
11990
|
-
// src/appstream/web.ts
|
|
11991
|
-
var DEFAULT_APP_PATH = "/app";
|
|
11992
|
-
var NO_SUCH_APP = "There's no App Stream available here.";
|
|
11993
|
-
var ESCAPES = {
|
|
11994
|
-
"&": "&",
|
|
11995
|
-
"<": "<",
|
|
11996
|
-
">": ">",
|
|
11997
|
-
'"': """,
|
|
11998
|
-
"'": "'"
|
|
11999
|
-
};
|
|
12000
|
-
var escapeHtml = (value) => value.replace(/[&<>"']/g, (character) => ESCAPES[character]);
|
|
12001
|
-
var CONTENT_TYPES = {
|
|
12002
|
-
html: "text/html; charset=utf-8",
|
|
12003
|
-
htm: "text/html; charset=utf-8",
|
|
12004
|
-
js: "text/javascript; charset=utf-8",
|
|
12005
|
-
mjs: "text/javascript; charset=utf-8",
|
|
12006
|
-
css: "text/css; charset=utf-8",
|
|
12007
|
-
json: "application/json; charset=utf-8",
|
|
12008
|
-
map: "application/json; charset=utf-8",
|
|
12009
|
-
txt: "text/plain; charset=utf-8",
|
|
12010
|
-
svg: "image/svg+xml",
|
|
12011
|
-
png: "image/png",
|
|
12012
|
-
jpg: "image/jpeg",
|
|
12013
|
-
jpeg: "image/jpeg",
|
|
12014
|
-
gif: "image/gif",
|
|
12015
|
-
webp: "image/webp",
|
|
12016
|
-
ico: "image/x-icon",
|
|
12017
|
-
woff: "font/woff",
|
|
12018
|
-
woff2: "font/woff2",
|
|
12019
|
-
ttf: "font/ttf",
|
|
12020
|
-
otf: "font/otf",
|
|
12021
|
-
wasm: "application/wasm",
|
|
12022
|
-
pdf: "application/pdf",
|
|
12023
|
-
zip: "application/zip"
|
|
12024
|
-
};
|
|
12025
|
-
var contentTypeFor = (filePath2) => {
|
|
12026
|
-
const extension = filePath2.slice(filePath2.lastIndexOf(".") + 1).toLowerCase();
|
|
12027
|
-
return CONTENT_TYPES[extension] ?? "application/octet-stream";
|
|
12028
|
-
};
|
|
12029
|
-
var cacheControlFor = (filePath2) => /\.[0-9a-f]{8,}\.[A-Za-z0-9]+$/.test(filePath2) ? "public, max-age=31536000, immutable" : "public, max-age=0, must-revalidate";
|
|
12030
|
-
var html = (status, markup) => ({
|
|
12031
|
-
status,
|
|
12032
|
-
body: markup,
|
|
12033
|
-
contentType: "text/html; charset=utf-8"
|
|
12034
|
-
});
|
|
12035
|
-
var json = (status, body) => ({
|
|
12036
|
-
status,
|
|
12037
|
-
body: JSON.stringify(body),
|
|
12038
|
-
contentType: "application/json; charset=utf-8"
|
|
12039
|
-
});
|
|
12040
|
-
var noSuchApp = () => html(404, `<!doctype html><html><body>${NO_SUCH_APP}</body></html>`);
|
|
12041
|
-
var methodNotAllowed = (allowed) => ({
|
|
12042
|
-
status: 405,
|
|
12043
|
-
body: JSON.stringify({ status: "failure", message: `${allowed} only.` }),
|
|
12044
|
-
contentType: "application/json; charset=utf-8",
|
|
12045
|
-
headers: { allow: allowed }
|
|
12046
|
-
});
|
|
12047
|
-
var decoded = (segment) => {
|
|
12048
|
-
try {
|
|
12049
|
-
return decodeURIComponent(segment);
|
|
12050
|
-
} catch (_) {
|
|
12051
|
-
return void 0;
|
|
12052
|
-
}
|
|
12053
|
-
};
|
|
12054
|
-
var createAppStreamWebService = (appStream, drive, options = {}) => {
|
|
12055
|
-
const base = (options.basePath ?? DEFAULT_APP_PATH).replace(/\/+$/, "");
|
|
12056
|
-
const title = options.title ?? "SASjs App Stream";
|
|
12057
|
-
const urlOf = (entry) => `${base}/${entry.id}/`;
|
|
12058
|
-
const rowOf = (entry) => ({
|
|
12059
|
-
id: entry.id,
|
|
12060
|
-
name: entry.name,
|
|
12061
|
-
appLoc: entry.appLoc,
|
|
12062
|
-
logo: entry.logo === void 0 ? null : `${urlOf(entry)}${entry.logo}`,
|
|
12063
|
-
url: urlOf(entry),
|
|
12064
|
-
publishedAt: entry.publishedAt ?? null
|
|
12065
|
-
});
|
|
12066
|
-
const apps = async (allow) => {
|
|
12067
|
-
const entries = await appStream.list(allow);
|
|
12068
|
-
return { apps: entries.map(rowOf) };
|
|
12069
|
-
};
|
|
12070
|
-
const landing = async (allow) => {
|
|
12071
|
-
const { apps: rows } = await apps(allow);
|
|
12072
|
-
const tiles = rows.length ? `<ul class="apps">${rows.map(
|
|
12073
|
-
(row) => `<li><a href="${escapeHtml(row.url)}">${escapeHtml(row.name)}</a><span class="loc">${escapeHtml(row.appLoc)}</span></li>`
|
|
12074
|
-
).join("")}</ul>` : '<p class="empty">No apps have been published yet.</p>';
|
|
12075
|
-
return html(
|
|
12076
|
-
200,
|
|
12077
|
-
[
|
|
12078
|
-
'<!doctype html><html lang="en"><head><meta charset="utf-8">',
|
|
12079
|
-
'<meta name="viewport" content="width=device-width,initial-scale=1">',
|
|
12080
|
-
`<title>${escapeHtml(title)}</title>`,
|
|
12081
|
-
"<style>",
|
|
12082
|
-
"body{font-family:system-ui,sans-serif;margin:2rem;color:#1f2430}",
|
|
12083
|
-
"h1{font-size:1.4rem}",
|
|
12084
|
-
"ul.apps{list-style:none;padding:0;display:grid;gap:.75rem;max-width:40rem}",
|
|
12085
|
-
"ul.apps li{display:flex;flex-direction:column;gap:.15rem;padding:.75rem 1rem;",
|
|
12086
|
-
"border:1px solid #d8dee9;border-radius:.5rem}",
|
|
12087
|
-
"ul.apps a{font-weight:600;text-decoration:none;color:#0b5cad}",
|
|
12088
|
-
".loc{font-size:.8rem;color:#5b6472;font-family:ui-monospace,monospace}",
|
|
12089
|
-
".empty{color:#5b6472}",
|
|
12090
|
-
"</style></head><body>",
|
|
12091
|
-
`<h1>${escapeHtml(title)}</h1>`,
|
|
12092
|
-
tiles,
|
|
12093
|
-
"</body></html>"
|
|
12094
|
-
].join("")
|
|
12095
|
-
);
|
|
12096
|
-
};
|
|
12097
|
-
const resolve = async (segment, allow) => {
|
|
12098
|
-
const entries = await appStream.list(allow);
|
|
12099
|
-
const byId2 = entries.find((entry) => entry.id === segment);
|
|
12100
|
-
if (byId2) return byId2;
|
|
12101
|
-
const byName = entries.filter((entry) => entry.name === segment);
|
|
12102
|
-
return byName.length === 1 ? byName[0] : void 0;
|
|
12103
|
-
};
|
|
12104
|
-
const asset = async (entry, segments) => {
|
|
12105
|
-
const parts = segments.map(decoded);
|
|
12106
|
-
if (parts.some((part) => part === void 0)) return noSuchApp();
|
|
12107
|
-
const relative = parts.join("/") || "index.html";
|
|
12108
|
-
try {
|
|
12109
|
-
const file = await drive.read(
|
|
12110
|
-
`${entry.appLoc}/services/${entry.streamWebFolder}/${relative}`
|
|
12111
|
-
);
|
|
12112
|
-
return {
|
|
12113
|
-
status: 200,
|
|
12114
|
-
body: file.contents,
|
|
12115
|
-
contentType: contentTypeFor(relative),
|
|
12116
|
-
headers: { "cache-control": cacheControlFor(relative) }
|
|
12117
|
-
};
|
|
12118
|
-
} catch (error) {
|
|
12119
|
-
if (error instanceof ApiError && (error.status === 404 || error.status === 400))
|
|
12120
|
-
return noSuchApp();
|
|
12121
|
-
throw error;
|
|
12122
|
-
}
|
|
12123
|
-
};
|
|
12124
|
-
return {
|
|
12125
|
-
apps,
|
|
12126
|
-
landing,
|
|
12127
|
-
async request({ method, path, allow }) {
|
|
12128
|
-
const clean = (path.split(/[?#]/)[0] || "/").replace(/\/{2,}/g, "/");
|
|
12129
|
-
const relative = base === "" ? clean : clean === base ? "/" : clean.startsWith(`${base}/`) ? clean.slice(base.length) : null;
|
|
12130
|
-
if (relative === null) return noSuchApp();
|
|
12131
|
-
if (relative === "" || relative === "/" || relative === "/index.html") {
|
|
12132
|
-
if (method !== "GET") return methodNotAllowed("GET");
|
|
12133
|
-
return landing(allow);
|
|
12134
|
-
}
|
|
12135
|
-
if (relative === "/apps.json") {
|
|
12136
|
-
if (method !== "GET") return methodNotAllowed("GET");
|
|
12137
|
-
return json(200, await apps(allow));
|
|
12138
|
-
}
|
|
12139
|
-
const segments = relative.split("/").filter(Boolean);
|
|
12140
|
-
const key = decoded(segments[0]);
|
|
12141
|
-
if (key === void 0) return noSuchApp();
|
|
12142
|
-
if (method === "DELETE") {
|
|
12143
|
-
const entry2 = await resolve(key, allow);
|
|
12144
|
-
if (!entry2) return noSuchApp();
|
|
12145
|
-
const removed = await appStream.unpublish(entry2.id);
|
|
12146
|
-
return json(200, { status: "success", app: rowOf(removed) });
|
|
12147
|
-
}
|
|
12148
|
-
if (method !== "GET") return methodNotAllowed("GET, DELETE");
|
|
12149
|
-
const entry = await resolve(key, allow);
|
|
12150
|
-
if (!entry) return noSuchApp();
|
|
12151
|
-
if (segments.length === 1 && !relative.endsWith("/"))
|
|
12152
|
-
return { status: 301, location: urlOf(entry) };
|
|
12153
|
-
return asset(entry, segments.slice(1));
|
|
12154
|
-
}
|
|
12155
|
-
};
|
|
12156
|
-
};
|
|
12157
12436
|
return __toCommonJS(index_exports);
|
|
12158
12437
|
})();
|
|
12159
12438
|
if (typeof self !== 'undefined') self.SASjsApi = SASjsApi
|