@sasjs/api 0.40.0 → 0.40.2
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 +269 -183
- package/build/cjs/appstream/bundle.js +28 -7
- package/build/cjs/corpus/app.js +37 -0
- package/build/cjs/corpus/deploy.js +44 -0
- package/build/cjs/corpus/runner.js +1 -1
- package/build/cjs/host/dispatch.js +25 -5
- package/build/esm/appstream/bundle.d.ts.map +1 -1
- package/build/esm/appstream/bundle.js +28 -7
- 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 +44 -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 +25 -5
- package/package.json +1 -1
package/build/browser.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* @sasjs/api 0.40.
|
|
1
|
+
/* @sasjs/api 0.40.2 - 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;
|
|
@@ -6316,6 +6316,175 @@ var SASjsApi = (() => {
|
|
|
6316
6316
|
}
|
|
6317
6317
|
};
|
|
6318
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
|
+
|
|
6319
6488
|
// src/appstream/bundle.ts
|
|
6320
6489
|
var APP_MANIFEST = "sasjs.app.json";
|
|
6321
6490
|
var FRONTEND_FOLDER = "web";
|
|
@@ -6392,16 +6561,16 @@ var SASjsApi = (() => {
|
|
|
6392
6561
|
}
|
|
6393
6562
|
const rest = { ...tree, members: withoutManifest };
|
|
6394
6563
|
const web = folderNamed(withoutManifest, FRONTEND_FOLDER);
|
|
6395
|
-
|
|
6564
|
+
const backendFolder = folderNamed(withoutManifest, BACKEND_FOLDER);
|
|
6565
|
+
if (web === void 0 && backendFolder === void 0 && manifest === void 0)
|
|
6396
6566
|
return { tree };
|
|
6397
|
-
|
|
6567
|
+
if (manifest?.streamWebFolder !== void 0) return { tree: rest, manifest };
|
|
6568
|
+
const backend = contentsOf(backendFolder);
|
|
6569
|
+
const ownFiles = withoutManifest.filter((member) => member !== backendFolder);
|
|
6570
|
+
const frontend = contentsOf(web) ?? (ownFiles.length === 0 ? void 0 : { members: ownFiles });
|
|
6398
6571
|
return {
|
|
6399
6572
|
tree: rest,
|
|
6400
|
-
frontend:
|
|
6401
|
-
members: withoutManifest.filter(
|
|
6402
|
-
(member) => member !== folderNamed(withoutManifest, BACKEND_FOLDER)
|
|
6403
|
-
)
|
|
6404
|
-
},
|
|
6573
|
+
...frontend === void 0 ? {} : { frontend },
|
|
6405
6574
|
...backend === void 0 ? {} : { backend },
|
|
6406
6575
|
manifest
|
|
6407
6576
|
};
|
|
@@ -6722,8 +6891,15 @@ var SASjsApi = (() => {
|
|
|
6722
6891
|
`This host has no app stream, so it cannot publish the frontend this bundle carries.`
|
|
6723
6892
|
);
|
|
6724
6893
|
if (publish !== void 0 && publish.streamWebFolder === void 0) {
|
|
6725
|
-
if (bundle.backend !== void 0 && publish.appLoc
|
|
6726
|
-
|
|
6894
|
+
if (bundle.backend !== void 0 && publish.appLoc === void 0)
|
|
6895
|
+
throw new ApiError(
|
|
6896
|
+
400,
|
|
6897
|
+
'This bundle carries a "backend" folder but names no "appLoc" for it: state the backend folder in sasjs.app.json, or in the request.'
|
|
6898
|
+
);
|
|
6899
|
+
if (bundle.backend !== void 0)
|
|
6900
|
+
await drive.deploy(publish.appLoc, bundle.backend, {
|
|
6901
|
+
replace: false
|
|
6902
|
+
});
|
|
6727
6903
|
await drive.deploy(
|
|
6728
6904
|
frontendFolderOf(publish.name),
|
|
6729
6905
|
packaged ? bundle.frontend : bundle.tree,
|
|
@@ -6778,7 +6954,7 @@ var SASjsApi = (() => {
|
|
|
6778
6954
|
if (isApiError(err) && err.status === 404) throw appNotRegistered();
|
|
6779
6955
|
throw err;
|
|
6780
6956
|
});
|
|
6781
|
-
const folder =
|
|
6957
|
+
const folder = appRootOf(entry);
|
|
6782
6958
|
let entryFileExists = false;
|
|
6783
6959
|
let lastModified = null;
|
|
6784
6960
|
try {
|
|
@@ -6795,8 +6971,13 @@ var SASjsApi = (() => {
|
|
|
6795
6971
|
const body2 = {
|
|
6796
6972
|
id: entry.id,
|
|
6797
6973
|
name: entry.name,
|
|
6798
|
-
|
|
6799
|
-
|
|
6974
|
+
// the folder the entry is read from, which is what this route describes:
|
|
6975
|
+
// `apps/<name>` for a frontend, and the legacy deployment's own folder for
|
|
6976
|
+
// the older shape. A host that answered one and not the other would leave
|
|
6977
|
+
// a client reading a path out of fields the entry may not carry.
|
|
6978
|
+
frontendFolder: folder,
|
|
6979
|
+
...entry.appLoc === void 0 ? {} : { appLoc: entry.appLoc },
|
|
6980
|
+
...entry.streamWebFolder === void 0 ? {} : { streamWebFolder: entry.streamWebFolder },
|
|
6800
6981
|
publishedAt: entry.publishedAt ?? null,
|
|
6801
6982
|
entryFile: APP_ENTRY_FILE,
|
|
6802
6983
|
entryFileExists,
|
|
@@ -9909,6 +10090,50 @@ var SASjsApi = (() => {
|
|
|
9909
10090
|
}
|
|
9910
10091
|
}
|
|
9911
10092
|
},
|
|
10093
|
+
{
|
|
10094
|
+
id: "deploy-refuses-a-backend-with-no-apploc",
|
|
10095
|
+
route: "POST /SASjsApi/drive/deploy",
|
|
10096
|
+
description: "refuses a bundle carrying services that names no folder to deploy them to",
|
|
10097
|
+
request: {
|
|
10098
|
+
subject: SUBJECT,
|
|
10099
|
+
body: {
|
|
10100
|
+
fileTree: {
|
|
10101
|
+
members: [
|
|
10102
|
+
{
|
|
10103
|
+
name: "sasjs.app.json",
|
|
10104
|
+
type: "file",
|
|
10105
|
+
code: JSON.stringify({ name: "orphan-backend" })
|
|
10106
|
+
},
|
|
10107
|
+
{
|
|
10108
|
+
name: "web",
|
|
10109
|
+
type: "folder",
|
|
10110
|
+
members: [
|
|
10111
|
+
{ name: "index.html", type: "file", code: "<h1>orphan</h1>" }
|
|
10112
|
+
]
|
|
10113
|
+
},
|
|
10114
|
+
{
|
|
10115
|
+
name: "backend",
|
|
10116
|
+
type: "folder",
|
|
10117
|
+
members: [
|
|
10118
|
+
{
|
|
10119
|
+
name: "services",
|
|
10120
|
+
type: "folder",
|
|
10121
|
+
members: [{ name: "run", type: "service", code: "" }]
|
|
10122
|
+
}
|
|
10123
|
+
]
|
|
10124
|
+
}
|
|
10125
|
+
]
|
|
10126
|
+
}
|
|
10127
|
+
}
|
|
10128
|
+
},
|
|
10129
|
+
// both hosts refuse this the same way, and neither writes the frontend it
|
|
10130
|
+
// could have deployed: half a deployment is worse than none
|
|
10131
|
+
expectDrive: { missing: ["/apps/orphan-backend/index.html"] },
|
|
10132
|
+
expect: {
|
|
10133
|
+
status: 400,
|
|
10134
|
+
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.'
|
|
10135
|
+
}
|
|
10136
|
+
},
|
|
9912
10137
|
{
|
|
9913
10138
|
id: "deploy-refuses-a-bundle-that-names-no-folder",
|
|
9914
10139
|
route: "POST /SASjsApi/drive/deploy",
|
|
@@ -10390,7 +10615,9 @@ var SASjsApi = (() => {
|
|
|
10390
10615
|
directory: createDirectoryService(identity, CORPUS_DIRECTORY),
|
|
10391
10616
|
identity: createIdentityService(identity),
|
|
10392
10617
|
records: createRecordService(identity),
|
|
10393
|
-
appStream: createAppStreamService(
|
|
10618
|
+
appStream: createAppStreamService(
|
|
10619
|
+
new MemoryAppStreamStore(testCase.appStream ?? [CORPUS_APP])
|
|
10620
|
+
),
|
|
10394
10621
|
session: createSessionService(identity, runner),
|
|
10395
10622
|
// no `runTimes` option: the default is the five the document names, so a
|
|
10396
10623
|
// case is never refused for a reason that belongs to one host's install
|
|
@@ -10447,6 +10674,12 @@ var SASjsApi = (() => {
|
|
|
10447
10674
|
|
|
10448
10675
|
// src/corpus/app.ts
|
|
10449
10676
|
var SUBJECT2 = { userId: "user-admin", clientId: "web_app" };
|
|
10677
|
+
var FRONTEND_APP = {
|
|
10678
|
+
id: "9d8c7b6a-5f4e-4d3c-8b2a-1f0e9d8c7b6a",
|
|
10679
|
+
name: "frontend-only",
|
|
10680
|
+
publishedAt: "2026-02-02T00:00:00.000Z"
|
|
10681
|
+
};
|
|
10682
|
+
var FRONTEND_ENTRY_FILE = `/apps/${FRONTEND_APP.name}/index.html`;
|
|
10450
10683
|
var ENTRY_FILE_PATH = `${CORPUS_APP.appLoc}/services/${CORPUS_APP.streamWebFolder}/index.html`;
|
|
10451
10684
|
var APP_CORPUS = [
|
|
10452
10685
|
{
|
|
@@ -10474,6 +10707,28 @@ var SASjsApi = (() => {
|
|
|
10474
10707
|
}
|
|
10475
10708
|
}
|
|
10476
10709
|
},
|
|
10710
|
+
{
|
|
10711
|
+
id: "app-detail-frontend",
|
|
10712
|
+
route: "GET /SASjsApi/app/{id}",
|
|
10713
|
+
description: "describes an app published as a frontend, from the folder its name derives",
|
|
10714
|
+
// the two shapes an index can hold, and the folder each is read from: this
|
|
10715
|
+
// entry names no `appLoc` and no `streamWebFolder`, so the folder has to come
|
|
10716
|
+
// from the name
|
|
10717
|
+
appStream: [FRONTEND_APP],
|
|
10718
|
+
seed: { [FRONTEND_ENTRY_FILE]: "<!doctype html><title>frontend</title>" },
|
|
10719
|
+
request: { subject: SUBJECT2, params: { id: FRONTEND_APP.id } },
|
|
10720
|
+
expect: {
|
|
10721
|
+
status: 200,
|
|
10722
|
+
partial: {
|
|
10723
|
+
id: FRONTEND_APP.id,
|
|
10724
|
+
name: FRONTEND_APP.name,
|
|
10725
|
+
frontendFolder: `/apps/${FRONTEND_APP.name}`,
|
|
10726
|
+
entryFile: "index.html",
|
|
10727
|
+
entryFileExists: true,
|
|
10728
|
+
url: `/app/${FRONTEND_APP.id}/`
|
|
10729
|
+
}
|
|
10730
|
+
}
|
|
10731
|
+
},
|
|
10477
10732
|
{
|
|
10478
10733
|
id: "app-detail-entry-file-missing",
|
|
10479
10734
|
route: "GET /SASjsApi/app/{id}",
|
|
@@ -12177,175 +12432,6 @@ var SASjsApi = (() => {
|
|
|
12177
12432
|
}
|
|
12178
12433
|
}
|
|
12179
12434
|
});
|
|
12180
|
-
|
|
12181
|
-
// src/appstream/web.ts
|
|
12182
|
-
var DEFAULT_APP_PATH = "/app";
|
|
12183
|
-
var NO_SUCH_APP = "There's no App Stream available here.";
|
|
12184
|
-
var ESCAPES = {
|
|
12185
|
-
"&": "&",
|
|
12186
|
-
"<": "<",
|
|
12187
|
-
">": ">",
|
|
12188
|
-
'"': """,
|
|
12189
|
-
"'": "'"
|
|
12190
|
-
};
|
|
12191
|
-
var escapeHtml = (value) => value.replace(/[&<>"']/g, (character) => ESCAPES[character]);
|
|
12192
|
-
var CONTENT_TYPES = {
|
|
12193
|
-
html: "text/html; charset=utf-8",
|
|
12194
|
-
htm: "text/html; charset=utf-8",
|
|
12195
|
-
js: "text/javascript; charset=utf-8",
|
|
12196
|
-
mjs: "text/javascript; charset=utf-8",
|
|
12197
|
-
css: "text/css; charset=utf-8",
|
|
12198
|
-
json: "application/json; charset=utf-8",
|
|
12199
|
-
map: "application/json; charset=utf-8",
|
|
12200
|
-
txt: "text/plain; charset=utf-8",
|
|
12201
|
-
svg: "image/svg+xml",
|
|
12202
|
-
png: "image/png",
|
|
12203
|
-
jpg: "image/jpeg",
|
|
12204
|
-
jpeg: "image/jpeg",
|
|
12205
|
-
gif: "image/gif",
|
|
12206
|
-
webp: "image/webp",
|
|
12207
|
-
ico: "image/x-icon",
|
|
12208
|
-
woff: "font/woff",
|
|
12209
|
-
woff2: "font/woff2",
|
|
12210
|
-
ttf: "font/ttf",
|
|
12211
|
-
otf: "font/otf",
|
|
12212
|
-
wasm: "application/wasm",
|
|
12213
|
-
pdf: "application/pdf",
|
|
12214
|
-
zip: "application/zip"
|
|
12215
|
-
};
|
|
12216
|
-
var contentTypeFor = (filePath2) => {
|
|
12217
|
-
const extension = filePath2.slice(filePath2.lastIndexOf(".") + 1).toLowerCase();
|
|
12218
|
-
return CONTENT_TYPES[extension] ?? "application/octet-stream";
|
|
12219
|
-
};
|
|
12220
|
-
var cacheControlFor = (filePath2) => /\.[0-9a-f]{8,}\.[A-Za-z0-9]+$/.test(filePath2) ? "public, max-age=31536000, immutable" : "public, max-age=0, must-revalidate";
|
|
12221
|
-
var html = (status, markup) => ({
|
|
12222
|
-
status,
|
|
12223
|
-
body: markup,
|
|
12224
|
-
contentType: "text/html; charset=utf-8"
|
|
12225
|
-
});
|
|
12226
|
-
var json = (status, body) => ({
|
|
12227
|
-
status,
|
|
12228
|
-
body: JSON.stringify(body),
|
|
12229
|
-
contentType: "application/json; charset=utf-8"
|
|
12230
|
-
});
|
|
12231
|
-
var noSuchApp = () => html(404, `<!doctype html><html><body>${NO_SUCH_APP}</body></html>`);
|
|
12232
|
-
var methodNotAllowed = (allowed) => ({
|
|
12233
|
-
status: 405,
|
|
12234
|
-
body: JSON.stringify({ status: "failure", message: `${allowed} only.` }),
|
|
12235
|
-
contentType: "application/json; charset=utf-8",
|
|
12236
|
-
headers: { allow: allowed }
|
|
12237
|
-
});
|
|
12238
|
-
var decoded = (segment) => {
|
|
12239
|
-
try {
|
|
12240
|
-
return decodeURIComponent(segment);
|
|
12241
|
-
} catch (_) {
|
|
12242
|
-
return void 0;
|
|
12243
|
-
}
|
|
12244
|
-
};
|
|
12245
|
-
var appRootOf = (entry) => entry.streamWebFolder !== void 0 && entry.appLoc !== void 0 ? `${entry.appLoc}/services/${entry.streamWebFolder}` : frontendFolderOf(entry.name);
|
|
12246
|
-
var createAppStreamWebService = (appStream, drive, options = {}) => {
|
|
12247
|
-
const base = (options.basePath ?? DEFAULT_APP_PATH).replace(/\/+$/, "");
|
|
12248
|
-
const title = options.title ?? "SASjs App Stream";
|
|
12249
|
-
const urlOf = (entry) => `${base}/${entry.id}/`;
|
|
12250
|
-
const rowOf = (entry) => ({
|
|
12251
|
-
id: entry.id,
|
|
12252
|
-
name: entry.name,
|
|
12253
|
-
appLoc: entry.appLoc ?? null,
|
|
12254
|
-
logo: entry.logo === void 0 ? null : `${urlOf(entry)}${entry.logo}`,
|
|
12255
|
-
url: urlOf(entry),
|
|
12256
|
-
publishedAt: entry.publishedAt ?? null
|
|
12257
|
-
});
|
|
12258
|
-
const apps = async (allow) => {
|
|
12259
|
-
const entries = await appStream.list(allow);
|
|
12260
|
-
return { apps: entries.map(rowOf) };
|
|
12261
|
-
};
|
|
12262
|
-
const landing = async (allow) => {
|
|
12263
|
-
const { apps: rows } = await apps(allow);
|
|
12264
|
-
const tiles = rows.length ? `<ul class="apps">${rows.map(
|
|
12265
|
-
(row) => `<li><a href="${escapeHtml(row.url)}">${escapeHtml(row.name)}</a><span class="loc">${escapeHtml(
|
|
12266
|
-
row.appLoc ?? frontendFolderOf(row.name)
|
|
12267
|
-
)}</span></li>`
|
|
12268
|
-
).join("")}</ul>` : '<p class="empty">No apps have been published yet.</p>';
|
|
12269
|
-
return html(
|
|
12270
|
-
200,
|
|
12271
|
-
[
|
|
12272
|
-
'<!doctype html><html lang="en"><head><meta charset="utf-8">',
|
|
12273
|
-
'<meta name="viewport" content="width=device-width,initial-scale=1">',
|
|
12274
|
-
`<title>${escapeHtml(title)}</title>`,
|
|
12275
|
-
"<style>",
|
|
12276
|
-
"body{font-family:system-ui,sans-serif;margin:2rem;color:#1f2430}",
|
|
12277
|
-
"h1{font-size:1.4rem}",
|
|
12278
|
-
"ul.apps{list-style:none;padding:0;display:grid;gap:.75rem;max-width:40rem}",
|
|
12279
|
-
"ul.apps li{display:flex;flex-direction:column;gap:.15rem;padding:.75rem 1rem;",
|
|
12280
|
-
"border:1px solid #d8dee9;border-radius:.5rem}",
|
|
12281
|
-
"ul.apps a{font-weight:600;text-decoration:none;color:#0b5cad}",
|
|
12282
|
-
".loc{font-size:.8rem;color:#5b6472;font-family:ui-monospace,monospace}",
|
|
12283
|
-
".empty{color:#5b6472}",
|
|
12284
|
-
"</style></head><body>",
|
|
12285
|
-
`<h1>${escapeHtml(title)}</h1>`,
|
|
12286
|
-
tiles,
|
|
12287
|
-
"</body></html>"
|
|
12288
|
-
].join("")
|
|
12289
|
-
);
|
|
12290
|
-
};
|
|
12291
|
-
const resolve = async (segment, allow) => {
|
|
12292
|
-
const entries = await appStream.list(allow);
|
|
12293
|
-
const byId2 = entries.find((entry) => entry.id === segment);
|
|
12294
|
-
if (byId2) return byId2;
|
|
12295
|
-
const byName = entries.filter((entry) => entry.name === segment);
|
|
12296
|
-
return byName.length === 1 ? byName[0] : void 0;
|
|
12297
|
-
};
|
|
12298
|
-
const asset = async (entry, segments) => {
|
|
12299
|
-
const parts = segments.map(decoded);
|
|
12300
|
-
if (parts.some((part) => part === void 0)) return noSuchApp();
|
|
12301
|
-
const relative = parts.join("/") || "index.html";
|
|
12302
|
-
try {
|
|
12303
|
-
const file = await drive.read(`${appRootOf(entry)}/${relative}`);
|
|
12304
|
-
return {
|
|
12305
|
-
status: 200,
|
|
12306
|
-
body: file.contents,
|
|
12307
|
-
contentType: contentTypeFor(relative),
|
|
12308
|
-
headers: { "cache-control": cacheControlFor(relative) }
|
|
12309
|
-
};
|
|
12310
|
-
} catch (error) {
|
|
12311
|
-
if (error instanceof ApiError && (error.status === 404 || error.status === 400))
|
|
12312
|
-
return noSuchApp();
|
|
12313
|
-
throw error;
|
|
12314
|
-
}
|
|
12315
|
-
};
|
|
12316
|
-
return {
|
|
12317
|
-
apps,
|
|
12318
|
-
landing,
|
|
12319
|
-
async request({ method, path, allow }) {
|
|
12320
|
-
const clean = (path.split(/[?#]/)[0] || "/").replace(/\/{2,}/g, "/");
|
|
12321
|
-
const relative = base === "" ? clean : clean === base ? "/" : clean.startsWith(`${base}/`) ? clean.slice(base.length) : null;
|
|
12322
|
-
if (relative === null) return noSuchApp();
|
|
12323
|
-
if (relative === "" || relative === "/" || relative === "/index.html") {
|
|
12324
|
-
if (method !== "GET") return methodNotAllowed("GET");
|
|
12325
|
-
return landing(allow);
|
|
12326
|
-
}
|
|
12327
|
-
if (relative === "/apps.json") {
|
|
12328
|
-
if (method !== "GET") return methodNotAllowed("GET");
|
|
12329
|
-
return json(200, await apps(allow));
|
|
12330
|
-
}
|
|
12331
|
-
const segments = relative.split("/").filter(Boolean);
|
|
12332
|
-
const key = decoded(segments[0]);
|
|
12333
|
-
if (key === void 0) return noSuchApp();
|
|
12334
|
-
if (method === "DELETE") {
|
|
12335
|
-
const entry2 = await resolve(key, allow);
|
|
12336
|
-
if (!entry2) return noSuchApp();
|
|
12337
|
-
const removed = await appStream.unpublish(entry2.id);
|
|
12338
|
-
return json(200, { status: "success", app: rowOf(removed) });
|
|
12339
|
-
}
|
|
12340
|
-
if (method !== "GET") return methodNotAllowed("GET, DELETE");
|
|
12341
|
-
const entry = await resolve(key, allow);
|
|
12342
|
-
if (!entry) return noSuchApp();
|
|
12343
|
-
if (segments.length === 1 && !relative.endsWith("/"))
|
|
12344
|
-
return { status: 301, location: urlOf(entry) };
|
|
12345
|
-
return asset(entry, segments.slice(1));
|
|
12346
|
-
}
|
|
12347
|
-
};
|
|
12348
|
-
};
|
|
12349
12435
|
return __toCommonJS(index_exports);
|
|
12350
12436
|
})();
|
|
12351
12437
|
if (typeof self !== 'undefined') self.SASjsApi = SASjsApi
|
|
@@ -127,19 +127,40 @@ const splitAppBundle = (tree) => {
|
|
|
127
127
|
}
|
|
128
128
|
const rest = { ...tree, members: withoutManifest };
|
|
129
129
|
const web = folderNamed(withoutManifest, exports.FRONTEND_FOLDER);
|
|
130
|
+
const backendFolder = folderNamed(withoutManifest, exports.BACKEND_FOLDER);
|
|
130
131
|
// nothing says this is an app: pass the tree through untouched, so a caller that
|
|
131
132
|
// keeps its own copy sees no change and the deploy is the thing that judges it.
|
|
132
|
-
//
|
|
133
|
-
|
|
133
|
+
// The two folder names are what a package is made of, so either of them - or a
|
|
134
|
+
// manifest - is the bundle saying it is one.
|
|
135
|
+
if (web === undefined &&
|
|
136
|
+
backendFolder === undefined &&
|
|
137
|
+
manifest === undefined)
|
|
134
138
|
return { tree: tree };
|
|
139
|
+
// `streamWebFolder` names the older shape, where the web assets sit inside the
|
|
140
|
+
// backend's folder and one tree is deployed to `appLoc`. It decides on its own:
|
|
141
|
+
// a folder called `web` is a folder a deployment may simply contain, and reading
|
|
142
|
+
// it as a package would deploy half a tree and publish the other half.
|
|
143
|
+
if (manifest?.streamWebFolder !== undefined)
|
|
144
|
+
return { tree: rest, manifest };
|
|
135
145
|
// a `web/` folder is the frontend; without one, a manifest still says the tree
|
|
136
|
-
// is an app, and the
|
|
137
|
-
|
|
146
|
+
// is an app, and what is left once the backend is taken out is then the app's
|
|
147
|
+
// own files.
|
|
148
|
+
const backend = contentsOf(backendFolder);
|
|
149
|
+
const ownFiles = withoutManifest.filter((member) => member !== backendFolder);
|
|
150
|
+
/**
|
|
151
|
+
* Nothing left is not a frontend.
|
|
152
|
+
*
|
|
153
|
+
* A bundle that carries only `backend/` and a manifest has no files to serve: the
|
|
154
|
+
* remaining tree is EMPTY, and reading that as a frontend publishes an app whose
|
|
155
|
+
* folder holds nothing, then refuses it for having no name. Such a bundle deploys
|
|
156
|
+
* its backend and publishes nothing - the halves are independent, which is what
|
|
157
|
+
* makes a backend shareable between frontends.
|
|
158
|
+
*/
|
|
159
|
+
const frontend = contentsOf(web) ??
|
|
160
|
+
(ownFiles.length === 0 ? undefined : { members: ownFiles });
|
|
138
161
|
return {
|
|
139
162
|
tree: rest,
|
|
140
|
-
frontend:
|
|
141
|
-
members: withoutManifest.filter((member) => member !== folderNamed(withoutManifest, exports.BACKEND_FOLDER))
|
|
142
|
-
},
|
|
163
|
+
...(frontend === undefined ? {} : { frontend }),
|
|
143
164
|
...(backend === undefined ? {} : { backend }),
|
|
144
165
|
manifest: manifest
|
|
145
166
|
};
|
package/build/cjs/corpus/app.js
CHANGED
|
@@ -3,6 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.APP_CORPUS = void 0;
|
|
4
4
|
const runner_js_1 = require("./runner.js");
|
|
5
5
|
const SUBJECT = { userId: 'user-admin', clientId: 'web_app' };
|
|
6
|
+
/**
|
|
7
|
+
* An app published as a frontend with no backend named.
|
|
8
|
+
*
|
|
9
|
+
* `streamWebFolder` is what tells the two shapes apart: an entry carrying it is
|
|
10
|
+
* served from `<appLoc>/services/<streamWebFolder>`, and every other entry from
|
|
11
|
+
* `apps/<name>`. `appLoc` is the backend a frontend calls, so it is absent here
|
|
12
|
+
* because this app calls none.
|
|
13
|
+
*/
|
|
14
|
+
const FRONTEND_APP = {
|
|
15
|
+
id: '9d8c7b6a-5f4e-4d3c-8b2a-1f0e9d8c7b6a',
|
|
16
|
+
name: 'frontend-only',
|
|
17
|
+
publishedAt: '2026-02-02T00:00:00.000Z'
|
|
18
|
+
};
|
|
19
|
+
/** Where that app's files are read from, which nothing on the entry records. */
|
|
20
|
+
const FRONTEND_ENTRY_FILE = `/apps/${FRONTEND_APP.name}/index.html`;
|
|
6
21
|
/** Where the app's streamed entry file sits inside its folder. */
|
|
7
22
|
const ENTRY_FILE_PATH = `${runner_js_1.CORPUS_APP.appLoc}/services/${runner_js_1.CORPUS_APP.streamWebFolder}/index.html`;
|
|
8
23
|
exports.APP_CORPUS = [
|
|
@@ -31,6 +46,28 @@ exports.APP_CORPUS = [
|
|
|
31
46
|
}
|
|
32
47
|
}
|
|
33
48
|
},
|
|
49
|
+
{
|
|
50
|
+
id: 'app-detail-frontend',
|
|
51
|
+
route: 'GET /SASjsApi/app/{id}',
|
|
52
|
+
description: 'describes an app published as a frontend, from the folder its name derives',
|
|
53
|
+
// the two shapes an index can hold, and the folder each is read from: this
|
|
54
|
+
// entry names no `appLoc` and no `streamWebFolder`, so the folder has to come
|
|
55
|
+
// from the name
|
|
56
|
+
appStream: [FRONTEND_APP],
|
|
57
|
+
seed: { [FRONTEND_ENTRY_FILE]: '<!doctype html><title>frontend</title>' },
|
|
58
|
+
request: { subject: SUBJECT, params: { id: FRONTEND_APP.id } },
|
|
59
|
+
expect: {
|
|
60
|
+
status: 200,
|
|
61
|
+
partial: {
|
|
62
|
+
id: FRONTEND_APP.id,
|
|
63
|
+
name: FRONTEND_APP.name,
|
|
64
|
+
frontendFolder: `/apps/${FRONTEND_APP.name}`,
|
|
65
|
+
entryFile: 'index.html',
|
|
66
|
+
entryFileExists: true,
|
|
67
|
+
url: `/app/${FRONTEND_APP.id}/`
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
},
|
|
34
71
|
{
|
|
35
72
|
id: 'app-detail-entry-file-missing',
|
|
36
73
|
route: 'GET /SASjsApi/app/{id}',
|
|
@@ -296,6 +296,50 @@ exports.DEPLOY_CORPUS = [
|
|
|
296
296
|
}
|
|
297
297
|
}
|
|
298
298
|
},
|
|
299
|
+
{
|
|
300
|
+
id: 'deploy-refuses-a-backend-with-no-apploc',
|
|
301
|
+
route: 'POST /SASjsApi/drive/deploy',
|
|
302
|
+
description: 'refuses a bundle carrying services that names no folder to deploy them to',
|
|
303
|
+
request: {
|
|
304
|
+
subject: SUBJECT,
|
|
305
|
+
body: {
|
|
306
|
+
fileTree: {
|
|
307
|
+
members: [
|
|
308
|
+
{
|
|
309
|
+
name: 'sasjs.app.json',
|
|
310
|
+
type: 'file',
|
|
311
|
+
code: JSON.stringify({ name: 'orphan-backend' })
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
name: 'web',
|
|
315
|
+
type: 'folder',
|
|
316
|
+
members: [
|
|
317
|
+
{ name: 'index.html', type: 'file', code: '<h1>orphan</h1>' }
|
|
318
|
+
]
|
|
319
|
+
},
|
|
320
|
+
{
|
|
321
|
+
name: 'backend',
|
|
322
|
+
type: 'folder',
|
|
323
|
+
members: [
|
|
324
|
+
{
|
|
325
|
+
name: 'services',
|
|
326
|
+
type: 'folder',
|
|
327
|
+
members: [{ name: 'run', type: 'service', code: '' }]
|
|
328
|
+
}
|
|
329
|
+
]
|
|
330
|
+
}
|
|
331
|
+
]
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
},
|
|
335
|
+
// both hosts refuse this the same way, and neither writes the frontend it
|
|
336
|
+
// could have deployed: half a deployment is worse than none
|
|
337
|
+
expectDrive: { missing: ['/apps/orphan-backend/index.html'] },
|
|
338
|
+
expect: {
|
|
339
|
+
status: 400,
|
|
340
|
+
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.'
|
|
341
|
+
}
|
|
342
|
+
},
|
|
299
343
|
{
|
|
300
344
|
id: 'deploy-refuses-a-bundle-that-names-no-folder',
|
|
301
345
|
route: 'POST /SASjsApi/drive/deploy',
|
|
@@ -70,7 +70,7 @@ const servicesFor = (testCase) => {
|
|
|
70
70
|
directory: (0, service_js_9.createDirectoryService)(identity, directory_js_1.CORPUS_DIRECTORY),
|
|
71
71
|
identity: (0, service_js_3.createIdentityService)(identity),
|
|
72
72
|
records: (0, records_js_1.createRecordService)(identity),
|
|
73
|
-
appStream: (0, service_js_2.createAppStreamService)(new service_js_2.MemoryAppStreamStore([exports.CORPUS_APP])),
|
|
73
|
+
appStream: (0, service_js_2.createAppStreamService)(new service_js_2.MemoryAppStreamStore(testCase.appStream ?? [exports.CORPUS_APP])),
|
|
74
74
|
session: (0, service_js_4.createSessionService)(identity, runner),
|
|
75
75
|
// no `runTimes` option: the default is the five the document names, so a
|
|
76
76
|
// case is never refused for a reason that belongs to one host's install
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.HANDLED_ROUTES = exports.noHandler = exports.dispatch = void 0;
|
|
4
4
|
const index_js_1 = require("../routes/index.js");
|
|
5
5
|
const service_js_1 = require("../appstream/service.js");
|
|
6
|
+
const web_js_1 = require("../appstream/web.js");
|
|
6
7
|
const bundle_js_1 = require("../appstream/bundle.js");
|
|
7
8
|
const types_js_1 = require("../types.js");
|
|
8
9
|
const deploy_js_1 = require("../drive/deploy.js");
|
|
@@ -359,11 +360,18 @@ const dispatch = async (services, routeId, request = {}) => {
|
|
|
359
360
|
if (packaged && publish === undefined)
|
|
360
361
|
throw new types_js_1.ApiError(501, `This host has no app stream, so it cannot publish the frontend this bundle carries.`);
|
|
361
362
|
if (publish !== undefined && publish.streamWebFolder === undefined) {
|
|
363
|
+
// a bundle that carries services has to say where they go: skipping the
|
|
364
|
+
// write would answer `200` for a deployment whose backend is missing, and
|
|
365
|
+
// the response is the only place a caller could have seen it
|
|
366
|
+
if (bundle.backend !== undefined && publish.appLoc === undefined)
|
|
367
|
+
throw new types_js_1.ApiError(400, 'This bundle carries a "backend" folder but names no "appLoc" for it: state the backend folder in sasjs.app.json, or in the request.');
|
|
362
368
|
// check, backend, frontend, index - the backend first so a frontend is
|
|
363
369
|
// never live against services that are not deployed yet, and additively
|
|
364
370
|
// because several frontends may name one backend
|
|
365
|
-
if (bundle.backend !== undefined
|
|
366
|
-
await drive.deploy(publish.appLoc, bundle.backend, {
|
|
371
|
+
if (bundle.backend !== undefined)
|
|
372
|
+
await drive.deploy(publish.appLoc, bundle.backend, {
|
|
373
|
+
replace: false
|
|
374
|
+
});
|
|
367
375
|
// publishing a frontend means the folder is what this bundle says it is
|
|
368
376
|
await drive.deploy((0, service_js_1.frontendFolderOf)(publish.name), (packaged ? bundle.frontend : bundle.tree), { replace: true });
|
|
369
377
|
const entry = await services.appStream.publish(publish);
|
|
@@ -415,7 +423,12 @@ const dispatch = async (services, routeId, request = {}) => {
|
|
|
415
423
|
throw appNotRegistered();
|
|
416
424
|
throw err;
|
|
417
425
|
});
|
|
418
|
-
|
|
426
|
+
// the entry's own folder, whichever shape it was published in: `streamWebFolder`
|
|
427
|
+
// is the field that separates them - an entry carrying it is served from
|
|
428
|
+
// `<appLoc>/services/<streamWebFolder>`, every other entry from `apps/<name>` -
|
|
429
|
+
// so the folder is derived rather than reconstructed from fields an entry may
|
|
430
|
+
// not carry
|
|
431
|
+
const folder = (0, web_js_1.appRootOf)(entry);
|
|
419
432
|
// An index entry can outlive its deployment - the folder deleted from under
|
|
420
433
|
// the host - and reporting a file and a date that are not there would be worse
|
|
421
434
|
// than reporting none, so the listing decides both.
|
|
@@ -439,8 +452,15 @@ const dispatch = async (services, routeId, request = {}) => {
|
|
|
439
452
|
const body = {
|
|
440
453
|
id: entry.id,
|
|
441
454
|
name: entry.name,
|
|
442
|
-
|
|
443
|
-
|
|
455
|
+
// the folder the entry is read from, which is what this route describes:
|
|
456
|
+
// `apps/<name>` for a frontend, and the legacy deployment's own folder for
|
|
457
|
+
// the older shape. A host that answered one and not the other would leave
|
|
458
|
+
// a client reading a path out of fields the entry may not carry.
|
|
459
|
+
frontendFolder: folder,
|
|
460
|
+
...(entry.appLoc === undefined ? {} : { appLoc: entry.appLoc }),
|
|
461
|
+
...(entry.streamWebFolder === undefined
|
|
462
|
+
? {}
|
|
463
|
+
: { streamWebFolder: entry.streamWebFolder }),
|
|
444
464
|
publishedAt: entry.publishedAt ?? null,
|
|
445
465
|
entryFile: APP_ENTRY_FILE,
|
|
446
466
|
entryFileExists,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../../../src/appstream/bundle.ts"],"names":[],"mappings":"AA2BA,OAAO,KAAK,EAAgB,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAClE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAErD,8EAA8E;AAC9E,eAAO,MAAM,YAAY,mBAAmB,CAAA;AAS5C,6DAA6D;AAC7D,eAAO,MAAM,eAAe,QAAQ,CAAA;AAEpC,uEAAuE;AACvE,eAAO,MAAM,cAAc,YAAY,CAAA;AAEvC,MAAM,WAAW,WAAW;IAC1B,iEAAiE;IACjE,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,+DAA+D;IAC/D,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,gFAAgF;IAChF,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,uDAAuD;IACvD,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,0EAA0E;IAC1E,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;CACnC;AAED,MAAM,WAAW,SAAS;IACxB;;;;OAIG;IACH,IAAI,EAAE,UAAU,CAAA;IAChB,oEAAoE;IACpE,QAAQ,CAAC,EAAE,UAAU,CAAA;IACrB,wEAAwE;IACxE,OAAO,CAAC,EAAE,UAAU,CAAA;IACpB,QAAQ,CAAC,EAAE,WAAW,CAAA;CACvB;AAiBD;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,GAAI,OAAO,OAAO,KAAG,WA0CjD,CAAA;AAuBD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,cAAc,GAAI,MAAM,OAAO,KAAG,
|
|
1
|
+
{"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../../../src/appstream/bundle.ts"],"names":[],"mappings":"AA2BA,OAAO,KAAK,EAAgB,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAClE,OAAO,KAAK,EAAE,iBAAiB,EAAE,M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B,WAAW,WAAW,EACtB,UAAS;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAO,KACnC,iBAAiB,GAAG,SAwBtB,CAAA"}
|
|
@@ -123,19 +123,40 @@ export const splitAppBundle = (tree) => {
|
|
|
123
123
|
}
|
|
124
124
|
const rest = { ...tree, members: withoutManifest };
|
|
125
125
|
const web = folderNamed(withoutManifest, FRONTEND_FOLDER);
|
|
126
|
+
const backendFolder = folderNamed(withoutManifest, BACKEND_FOLDER);
|
|
126
127
|
// nothing says this is an app: pass the tree through untouched, so a caller that
|
|
127
128
|
// keeps its own copy sees no change and the deploy is the thing that judges it.
|
|
128
|
-
//
|
|
129
|
-
|
|
129
|
+
// The two folder names are what a package is made of, so either of them - or a
|
|
130
|
+
// manifest - is the bundle saying it is one.
|
|
131
|
+
if (web === undefined &&
|
|
132
|
+
backendFolder === undefined &&
|
|
133
|
+
manifest === undefined)
|
|
130
134
|
return { tree: tree };
|
|
135
|
+
// `streamWebFolder` names the older shape, where the web assets sit inside the
|
|
136
|
+
// backend's folder and one tree is deployed to `appLoc`. It decides on its own:
|
|
137
|
+
// a folder called `web` is a folder a deployment may simply contain, and reading
|
|
138
|
+
// it as a package would deploy half a tree and publish the other half.
|
|
139
|
+
if (manifest?.streamWebFolder !== undefined)
|
|
140
|
+
return { tree: rest, manifest };
|
|
131
141
|
// a `web/` folder is the frontend; without one, a manifest still says the tree
|
|
132
|
-
// is an app, and the
|
|
133
|
-
|
|
142
|
+
// is an app, and what is left once the backend is taken out is then the app's
|
|
143
|
+
// own files.
|
|
144
|
+
const backend = contentsOf(backendFolder);
|
|
145
|
+
const ownFiles = withoutManifest.filter((member) => member !== backendFolder);
|
|
146
|
+
/**
|
|
147
|
+
* Nothing left is not a frontend.
|
|
148
|
+
*
|
|
149
|
+
* A bundle that carries only `backend/` and a manifest has no files to serve: the
|
|
150
|
+
* remaining tree is EMPTY, and reading that as a frontend publishes an app whose
|
|
151
|
+
* folder holds nothing, then refuses it for having no name. Such a bundle deploys
|
|
152
|
+
* its backend and publishes nothing - the halves are independent, which is what
|
|
153
|
+
* makes a backend shareable between frontends.
|
|
154
|
+
*/
|
|
155
|
+
const frontend = contentsOf(web) ??
|
|
156
|
+
(ownFiles.length === 0 ? undefined : { members: ownFiles });
|
|
134
157
|
return {
|
|
135
158
|
tree: rest,
|
|
136
|
-
frontend:
|
|
137
|
-
members: withoutManifest.filter((member) => member !== folderNamed(withoutManifest, BACKEND_FOLDER))
|
|
138
|
-
},
|
|
159
|
+
...(frontend === undefined ? {} : { frontend }),
|
|
139
160
|
...(backend === undefined ? {} : { backend }),
|
|
140
161
|
manifest: manifest
|
|
141
162
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../../src/corpus/app.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../../src/corpus/app.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAyB5C,eAAO,MAAM,UAAU,EAAE,UAAU,EAyElC,CAAA"}
|
package/build/esm/corpus/app.js
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
import { CORPUS_APP } from './runner.js';
|
|
2
2
|
const SUBJECT = { userId: 'user-admin', clientId: 'web_app' };
|
|
3
|
+
/**
|
|
4
|
+
* An app published as a frontend with no backend named.
|
|
5
|
+
*
|
|
6
|
+
* `streamWebFolder` is what tells the two shapes apart: an entry carrying it is
|
|
7
|
+
* served from `<appLoc>/services/<streamWebFolder>`, and every other entry from
|
|
8
|
+
* `apps/<name>`. `appLoc` is the backend a frontend calls, so it is absent here
|
|
9
|
+
* because this app calls none.
|
|
10
|
+
*/
|
|
11
|
+
const FRONTEND_APP = {
|
|
12
|
+
id: '9d8c7b6a-5f4e-4d3c-8b2a-1f0e9d8c7b6a',
|
|
13
|
+
name: 'frontend-only',
|
|
14
|
+
publishedAt: '2026-02-02T00:00:00.000Z'
|
|
15
|
+
};
|
|
16
|
+
/** Where that app's files are read from, which nothing on the entry records. */
|
|
17
|
+
const FRONTEND_ENTRY_FILE = `/apps/${FRONTEND_APP.name}/index.html`;
|
|
3
18
|
/** Where the app's streamed entry file sits inside its folder. */
|
|
4
19
|
const ENTRY_FILE_PATH = `${CORPUS_APP.appLoc}/services/${CORPUS_APP.streamWebFolder}/index.html`;
|
|
5
20
|
export const APP_CORPUS = [
|
|
@@ -28,6 +43,28 @@ export const APP_CORPUS = [
|
|
|
28
43
|
}
|
|
29
44
|
}
|
|
30
45
|
},
|
|
46
|
+
{
|
|
47
|
+
id: 'app-detail-frontend',
|
|
48
|
+
route: 'GET /SASjsApi/app/{id}',
|
|
49
|
+
description: 'describes an app published as a frontend, from the folder its name derives',
|
|
50
|
+
// the two shapes an index can hold, and the folder each is read from: this
|
|
51
|
+
// entry names no `appLoc` and no `streamWebFolder`, so the folder has to come
|
|
52
|
+
// from the name
|
|
53
|
+
appStream: [FRONTEND_APP],
|
|
54
|
+
seed: { [FRONTEND_ENTRY_FILE]: '<!doctype html><title>frontend</title>' },
|
|
55
|
+
request: { subject: SUBJECT, params: { id: FRONTEND_APP.id } },
|
|
56
|
+
expect: {
|
|
57
|
+
status: 200,
|
|
58
|
+
partial: {
|
|
59
|
+
id: FRONTEND_APP.id,
|
|
60
|
+
name: FRONTEND_APP.name,
|
|
61
|
+
frontendFolder: `/apps/${FRONTEND_APP.name}`,
|
|
62
|
+
entryFile: 'index.html',
|
|
63
|
+
entryFileExists: true,
|
|
64
|
+
url: `/app/${FRONTEND_APP.id}/`
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
},
|
|
31
68
|
{
|
|
32
69
|
id: 'app-detail-entry-file-missing',
|
|
33
70
|
route: 'GET /SASjsApi/app/{id}',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../../src/corpus/deploy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAW5C,eAAO,MAAM,aAAa,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../../src/corpus/deploy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAW5C,eAAO,MAAM,aAAa,EAAE,UAAU,EA6crC,CAAA"}
|
|
@@ -293,6 +293,50 @@ export const DEPLOY_CORPUS = [
|
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
295
|
},
|
|
296
|
+
{
|
|
297
|
+
id: 'deploy-refuses-a-backend-with-no-apploc',
|
|
298
|
+
route: 'POST /SASjsApi/drive/deploy',
|
|
299
|
+
description: 'refuses a bundle carrying services that names no folder to deploy them to',
|
|
300
|
+
request: {
|
|
301
|
+
subject: SUBJECT,
|
|
302
|
+
body: {
|
|
303
|
+
fileTree: {
|
|
304
|
+
members: [
|
|
305
|
+
{
|
|
306
|
+
name: 'sasjs.app.json',
|
|
307
|
+
type: 'file',
|
|
308
|
+
code: JSON.stringify({ name: 'orphan-backend' })
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
name: 'web',
|
|
312
|
+
type: 'folder',
|
|
313
|
+
members: [
|
|
314
|
+
{ name: 'index.html', type: 'file', code: '<h1>orphan</h1>' }
|
|
315
|
+
]
|
|
316
|
+
},
|
|
317
|
+
{
|
|
318
|
+
name: 'backend',
|
|
319
|
+
type: 'folder',
|
|
320
|
+
members: [
|
|
321
|
+
{
|
|
322
|
+
name: 'services',
|
|
323
|
+
type: 'folder',
|
|
324
|
+
members: [{ name: 'run', type: 'service', code: '' }]
|
|
325
|
+
}
|
|
326
|
+
]
|
|
327
|
+
}
|
|
328
|
+
]
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
},
|
|
332
|
+
// both hosts refuse this the same way, and neither writes the frontend it
|
|
333
|
+
// could have deployed: half a deployment is worse than none
|
|
334
|
+
expectDrive: { missing: ['/apps/orphan-backend/index.html'] },
|
|
335
|
+
expect: {
|
|
336
|
+
status: 400,
|
|
337
|
+
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.'
|
|
338
|
+
}
|
|
339
|
+
},
|
|
296
340
|
{
|
|
297
341
|
id: 'deploy-refuses-a-bundle-that-names-no-folder',
|
|
298
342
|
route: 'POST /SASjsApi/drive/deploy',
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import type { ApiRequest } from '../host/dispatch.js';
|
|
15
15
|
import type { IdentityFixture } from '../identity/fixture.js';
|
|
16
|
+
import type { AppStreamEntry } from '../appstream/service.js';
|
|
16
17
|
export interface CorpusCase {
|
|
17
18
|
/** Stable name, used as the test's title. */
|
|
18
19
|
id: string;
|
|
@@ -23,6 +24,14 @@ export interface CorpusCase {
|
|
|
23
24
|
seed?: Record<string, string | Uint8Array>;
|
|
24
25
|
/** The identity the case starts from; the default fixture when omitted. */
|
|
25
26
|
identity?: IdentityFixture;
|
|
27
|
+
/**
|
|
28
|
+
* The apps the case starts from; the default fixture when omitted.
|
|
29
|
+
*
|
|
30
|
+
* An index holds two shapes - an app published as a frontend at `apps/<name>`,
|
|
31
|
+
* and the older one served out of a folder's `services/` - and a case that only
|
|
32
|
+
* ever starts from one of them cannot see a route that reads the other wrong.
|
|
33
|
+
*/
|
|
34
|
+
appStream?: AppStreamEntry[];
|
|
26
35
|
/**
|
|
27
36
|
* The drive refuses every write, so a case can pin the refusal a route answers
|
|
28
37
|
* when storing fails - `POST /drive/deploy` documents a `500`, and a mock drive
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"drive.d.ts","sourceRo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AA;IAC9B,wDAAwD;IACxD,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAI,UAAU,UAAU,KAAG,
|
|
1
|
+
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../../../src/corpus/runner.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAE5C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAyBnD;;;;;GAKG;AACH,eAAO,MAAM,UAAU;;;;;;CAMtB,CAAA;AAED,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,QAAQ,CAAC,EAAE,MAAM,GAAG,UAAU,CAAA;IAC9B,wDAAwD;IACxD,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAI,UAAU,UAAU,KAAG,QA4ClD,CAAA;AA8DD;;;;GAIG;AACH,eAAO,MAAM,OAAO,GAClB,UAAU,UAAU,EACpB,WAAU,QAAgC,KACzC,OAAO,CAAC,UAAU,CAgBpB,CAAA"}
|
|
@@ -67,7 +67,7 @@ export const servicesFor = (testCase) => {
|
|
|
67
67
|
directory: createDirectoryService(identity, CORPUS_DIRECTORY),
|
|
68
68
|
identity: createIdentityService(identity),
|
|
69
69
|
records: createRecordService(identity),
|
|
70
|
-
appStream: createAppStreamService(new MemoryAppStreamStore([CORPUS_APP])),
|
|
70
|
+
appStream: createAppStreamService(new MemoryAppStreamStore(testCase.appStream ?? [CORPUS_APP])),
|
|
71
71
|
session: createSessionService(identity, runner),
|
|
72
72
|
// no `runTimes` option: the default is the five the document names, so a
|
|
73
73
|
// case is never refused for a reason that belongs to one host's install
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dispatch.d.ts","sourceRoot":"","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AAA;IAC5B;;;OAGG;IACH,IAAI,CAAC,EAAE,WAAW,CAAA;IAClB,KAAK,EAAE,YAAY,CAAA;IACnB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,eAAe,CAAA;IAC1B,yFAAyF;IACzF,OAAO,CAAC,EAAE,aAAa,CAAA;IACvB;;;OAGG;IACH,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB;;;;;;;OAOG;IACH,IAAI,CAAC,EAAE,gBAAgB,CAAA;IACvB;;;OAGG;IACH,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB;;;;OAIG;IACH,SAAS,CAAC,EAAE,gBAAgB,CAAA;CAC7B;AAmFD,eAAO,MAAM,QAAQ,GACnB,UAAU,QAAQ,EAClB,SAAS,MAAM,EACf,UAAS,UAAe,KACvB,OAAO,CAAC,WAAW,CAw1BrB,CAAA;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,SAAS,GAAI,SAAS,MAAM,KAAG,QAO3C,CAAA;AAED,0DAA0D;AAC1D,eAAO,MAAM,cAAc,EAAE,MAAM,EA+DlC,CAAA"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { routeById } from '../routes/index.js';
|
|
2
2
|
import { appSummary, checkPublishRequest, frontendFolderOf } from '../appstream/service.js';
|
|
3
|
+
import { appRootOf } from '../appstream/web.js';
|
|
3
4
|
import { publishRequestFor, splitAppBundle } from '../appstream/bundle.js';
|
|
4
5
|
import { ApiError, isApiError } from '../types.js';
|
|
5
6
|
import { DEPLOY_SUCCESS } from '../drive/deploy.js';
|
|
@@ -356,11 +357,18 @@ export const dispatch = async (services, routeId, request = {}) => {
|
|
|
356
357
|
if (packaged && publish === undefined)
|
|
357
358
|
throw new ApiError(501, `This host has no app stream, so it cannot publish the frontend this bundle carries.`);
|
|
358
359
|
if (publish !== undefined && publish.streamWebFolder === undefined) {
|
|
360
|
+
// a bundle that carries services has to say where they go: skipping the
|
|
361
|
+
// write would answer `200` for a deployment whose backend is missing, and
|
|
362
|
+
// the response is the only place a caller could have seen it
|
|
363
|
+
if (bundle.backend !== undefined && publish.appLoc === undefined)
|
|
364
|
+
throw new ApiError(400, 'This bundle carries a "backend" folder but names no "appLoc" for it: state the backend folder in sasjs.app.json, or in the request.');
|
|
359
365
|
// check, backend, frontend, index - the backend first so a frontend is
|
|
360
366
|
// never live against services that are not deployed yet, and additively
|
|
361
367
|
// because several frontends may name one backend
|
|
362
|
-
if (bundle.backend !== undefined
|
|
363
|
-
await drive.deploy(publish.appLoc, bundle.backend, {
|
|
368
|
+
if (bundle.backend !== undefined)
|
|
369
|
+
await drive.deploy(publish.appLoc, bundle.backend, {
|
|
370
|
+
replace: false
|
|
371
|
+
});
|
|
364
372
|
// publishing a frontend means the folder is what this bundle says it is
|
|
365
373
|
await drive.deploy(frontendFolderOf(publish.name), (packaged ? bundle.frontend : bundle.tree), { replace: true });
|
|
366
374
|
const entry = await services.appStream.publish(publish);
|
|
@@ -412,7 +420,12 @@ export const dispatch = async (services, routeId, request = {}) => {
|
|
|
412
420
|
throw appNotRegistered();
|
|
413
421
|
throw err;
|
|
414
422
|
});
|
|
415
|
-
|
|
423
|
+
// the entry's own folder, whichever shape it was published in: `streamWebFolder`
|
|
424
|
+
// is the field that separates them - an entry carrying it is served from
|
|
425
|
+
// `<appLoc>/services/<streamWebFolder>`, every other entry from `apps/<name>` -
|
|
426
|
+
// so the folder is derived rather than reconstructed from fields an entry may
|
|
427
|
+
// not carry
|
|
428
|
+
const folder = appRootOf(entry);
|
|
416
429
|
// An index entry can outlive its deployment - the folder deleted from under
|
|
417
430
|
// the host - and reporting a file and a date that are not there would be worse
|
|
418
431
|
// than reporting none, so the listing decides both.
|
|
@@ -436,8 +449,15 @@ export const dispatch = async (services, routeId, request = {}) => {
|
|
|
436
449
|
const body = {
|
|
437
450
|
id: entry.id,
|
|
438
451
|
name: entry.name,
|
|
439
|
-
|
|
440
|
-
|
|
452
|
+
// the folder the entry is read from, which is what this route describes:
|
|
453
|
+
// `apps/<name>` for a frontend, and the legacy deployment's own folder for
|
|
454
|
+
// the older shape. A host that answered one and not the other would leave
|
|
455
|
+
// a client reading a path out of fields the entry may not carry.
|
|
456
|
+
frontendFolder: folder,
|
|
457
|
+
...(entry.appLoc === undefined ? {} : { appLoc: entry.appLoc }),
|
|
458
|
+
...(entry.streamWebFolder === undefined
|
|
459
|
+
? {}
|
|
460
|
+
: { streamWebFolder: entry.streamWebFolder }),
|
|
441
461
|
publishedAt: entry.publishedAt ?? null,
|
|
442
462
|
entryFile: APP_ENTRY_FILE,
|
|
443
463
|
entryFileExists,
|
package/package.json
CHANGED