@sasjs/api 0.38.0 → 0.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/browser.js +259 -67
- package/build/cjs/appstream/bundle.js +119 -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/deploy.js +69 -0
- package/build/cjs/host/dispatch.js +36 -8
- 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 +118 -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/deploy.d.ts.map +1 -1
- package/build/esm/corpus/deploy.js +69 -0
- package/build/esm/host/dispatch.d.ts.map +1 -1
- package/build/esm/host/dispatch.js +37 -9
- 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 +2 -2
package/build/browser.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* @sasjs/api 0.
|
|
1
|
+
/* @sasjs/api 0.40.0 - the SASjs Server API, for a service worker. https://github.com/sasjs/api */
|
|
2
2
|
"use strict";
|
|
3
3
|
var SASjsApi = (() => {
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
@@ -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)
|
|
6162
|
+
throw new ApiError(
|
|
6163
|
+
400,
|
|
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))
|
|
6113
6171
|
throw new ApiError(
|
|
6114
6172
|
400,
|
|
6115
|
-
`The deployed tree has no "
|
|
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 };
|
|
@@ -6267,6 +6318,8 @@ var SASjsApi = (() => {
|
|
|
6267
6318
|
|
|
6268
6319
|
// src/appstream/bundle.ts
|
|
6269
6320
|
var APP_MANIFEST = "sasjs.app.json";
|
|
6321
|
+
var FRONTEND_FOLDER = "web";
|
|
6322
|
+
var BACKEND_FOLDER = "backend";
|
|
6270
6323
|
var isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
6271
6324
|
var text = (value, field) => {
|
|
6272
6325
|
if (value === void 0) return void 0;
|
|
@@ -6280,14 +6333,15 @@ var SASjsApi = (() => {
|
|
|
6280
6333
|
var parseAppManifest = (value) => {
|
|
6281
6334
|
if (!isObject(value))
|
|
6282
6335
|
throw new ApiError(400, `${APP_MANIFEST} must be an object.`);
|
|
6336
|
+
const name = text(value.name, "name");
|
|
6337
|
+
const appLoc = text(value.appLoc, "appLoc");
|
|
6283
6338
|
const streamWebFolder = text(value.streamWebFolder, "streamWebFolder");
|
|
6284
|
-
|
|
6339
|
+
const logo = text(value.logo, "logo");
|
|
6340
|
+
if (streamWebFolder !== void 0 && /[\\/]/.test(streamWebFolder))
|
|
6285
6341
|
throw new ApiError(
|
|
6286
6342
|
400,
|
|
6287
|
-
|
|
6343
|
+
`"streamWebFolder" in ${APP_MANIFEST} must be a single path segment.`
|
|
6288
6344
|
);
|
|
6289
|
-
const name = text(value.name, "name");
|
|
6290
|
-
const logo = text(value.logo, "logo");
|
|
6291
6345
|
const frameAncestors = value.frameAncestors;
|
|
6292
6346
|
if (frameAncestors !== void 0 && (typeof frameAncestors !== "string" || frameAncestors === "") && !(Array.isArray(frameAncestors) && frameAncestors.length > 0 && frameAncestors.every(
|
|
6293
6347
|
(source) => typeof source === "string" && source !== ""
|
|
@@ -6298,50 +6352,80 @@ var SASjsApi = (() => {
|
|
|
6298
6352
|
);
|
|
6299
6353
|
return {
|
|
6300
6354
|
...name === void 0 ? {} : { name },
|
|
6301
|
-
|
|
6355
|
+
...appLoc === void 0 ? {} : { appLoc },
|
|
6356
|
+
...streamWebFolder === void 0 ? {} : { streamWebFolder },
|
|
6302
6357
|
...logo === void 0 ? {} : { logo },
|
|
6303
6358
|
...frameAncestors === void 0 ? {} : { frameAncestors }
|
|
6304
6359
|
};
|
|
6305
6360
|
};
|
|
6361
|
+
var folderNamed = (members, name) => members.find(
|
|
6362
|
+
(member) => isObject(member) && member.type === "folder" && member.name === name
|
|
6363
|
+
);
|
|
6364
|
+
var contentsOf = (member) => {
|
|
6365
|
+
const members = member?.members;
|
|
6366
|
+
return Array.isArray(members) ? { members } : void 0;
|
|
6367
|
+
};
|
|
6306
6368
|
var splitAppBundle = (tree) => {
|
|
6307
6369
|
if (!isObject(tree) || !Array.isArray(tree.members))
|
|
6308
6370
|
return { tree };
|
|
6309
6371
|
const members = tree.members;
|
|
6310
6372
|
const at = members.findIndex(
|
|
6311
|
-
(
|
|
6373
|
+
(member) => isObject(member) && member.type === "file" && member.name === APP_MANIFEST
|
|
6312
6374
|
);
|
|
6313
|
-
|
|
6314
|
-
|
|
6315
|
-
if (
|
|
6316
|
-
|
|
6317
|
-
|
|
6318
|
-
|
|
6319
|
-
|
|
6320
|
-
|
|
6321
|
-
|
|
6322
|
-
|
|
6323
|
-
|
|
6324
|
-
|
|
6375
|
+
const withoutManifest = at === -1 ? members : members.filter((_, index) => index !== at);
|
|
6376
|
+
let manifest;
|
|
6377
|
+
if (at !== -1) {
|
|
6378
|
+
const member = members[at];
|
|
6379
|
+
if (typeof member.code !== "string")
|
|
6380
|
+
throw new ApiError(400, `${APP_MANIFEST} carries no text.`);
|
|
6381
|
+
const source = member.encoding === "base64" ? new TextDecoder().decode(decodeBase64(member.code)) : member.code;
|
|
6382
|
+
let parsed;
|
|
6383
|
+
try {
|
|
6384
|
+
parsed = JSON.parse(source);
|
|
6385
|
+
} catch (error) {
|
|
6386
|
+
throw new ApiError(
|
|
6387
|
+
400,
|
|
6388
|
+
`${APP_MANIFEST} is not valid JSON: ${error.message}`
|
|
6389
|
+
);
|
|
6390
|
+
}
|
|
6391
|
+
manifest = parseAppManifest(parsed);
|
|
6325
6392
|
}
|
|
6393
|
+
const rest = { ...tree, members: withoutManifest };
|
|
6394
|
+
const web = folderNamed(withoutManifest, FRONTEND_FOLDER);
|
|
6395
|
+
if (web === void 0 && manifest === void 0)
|
|
6396
|
+
return { tree };
|
|
6397
|
+
const backend = contentsOf(folderNamed(withoutManifest, BACKEND_FOLDER));
|
|
6326
6398
|
return {
|
|
6327
|
-
tree:
|
|
6328
|
-
|
|
6329
|
-
members:
|
|
6399
|
+
tree: rest,
|
|
6400
|
+
frontend: contentsOf(web) ?? {
|
|
6401
|
+
members: withoutManifest.filter(
|
|
6402
|
+
(member) => member !== folderNamed(withoutManifest, BACKEND_FOLDER)
|
|
6403
|
+
)
|
|
6330
6404
|
},
|
|
6331
|
-
|
|
6405
|
+
...backend === void 0 ? {} : { backend },
|
|
6406
|
+
manifest
|
|
6332
6407
|
};
|
|
6333
6408
|
};
|
|
6334
|
-
var publishRequestFor = (deploy, manifest) => {
|
|
6409
|
+
var publishRequestFor = (deploy, manifest, options = {}) => {
|
|
6335
6410
|
const streamWebFolder = deploy.streamWebFolder ?? manifest?.streamWebFolder;
|
|
6336
|
-
|
|
6337
|
-
const name = deploy.streamServiceName ?? manifest?.name;
|
|
6411
|
+
const appLoc = deploy.appLoc ?? manifest?.appLoc;
|
|
6412
|
+
const name = deploy.name ?? deploy.streamServiceName ?? manifest?.name;
|
|
6338
6413
|
const logo = deploy.streamLogo ?? manifest?.logo;
|
|
6414
|
+
const frameAncestors = manifest?.frameAncestors;
|
|
6415
|
+
if (streamWebFolder !== void 0)
|
|
6416
|
+
return {
|
|
6417
|
+
...appLoc === void 0 ? {} : { appLoc },
|
|
6418
|
+
streamWebFolder,
|
|
6419
|
+
...name === void 0 ? {} : { name },
|
|
6420
|
+
...logo === void 0 ? {} : { logo },
|
|
6421
|
+
...frameAncestors === void 0 ? {} : { frameAncestors }
|
|
6422
|
+
};
|
|
6423
|
+
if (name === void 0 && !options.packaged) return void 0;
|
|
6339
6424
|
return {
|
|
6340
|
-
appLoc: deploy.appLoc,
|
|
6341
|
-
streamWebFolder,
|
|
6342
6425
|
...name === void 0 ? {} : { name },
|
|
6426
|
+
...appLoc === void 0 ? {} : { appLoc },
|
|
6343
6427
|
...logo === void 0 ? {} : { logo },
|
|
6344
|
-
...
|
|
6428
|
+
...frameAncestors === void 0 ? {} : { frameAncestors }
|
|
6345
6429
|
};
|
|
6346
6430
|
};
|
|
6347
6431
|
|
|
@@ -6610,21 +6694,53 @@ var SASjsApi = (() => {
|
|
|
6610
6694
|
case "POST /SASjsApi/drive/deploy/upload":
|
|
6611
6695
|
case "POST /SASjsApi/drive/deploy": {
|
|
6612
6696
|
const bundle = splitAppBundle(body.fileTree);
|
|
6697
|
+
const packaged = bundle.frontend !== void 0;
|
|
6613
6698
|
const isUpload = routeId === "POST /SASjsApi/drive/deploy/upload";
|
|
6614
6699
|
const setting = (name) => isUpload ? given(query[name]) ?? body?.[name] : body?.[name];
|
|
6615
|
-
const
|
|
6700
|
+
const statedAppLoc = given(setting("appLoc"));
|
|
6701
|
+
const appLoc = typeof statedAppLoc === "string" ? statedAppLoc : void 0;
|
|
6616
6702
|
const requested = services.appStream ? publishRequestFor(
|
|
6617
6703
|
{
|
|
6704
|
+
name: given(setting("name")),
|
|
6618
6705
|
appLoc,
|
|
6619
6706
|
streamWebFolder: given(setting("streamWebFolder")),
|
|
6620
6707
|
streamServiceName: given(setting("streamServiceName")),
|
|
6621
6708
|
streamLogo: given(setting("streamLogo"))
|
|
6622
6709
|
},
|
|
6623
|
-
bundle.manifest
|
|
6710
|
+
bundle.manifest,
|
|
6711
|
+
{ packaged }
|
|
6624
6712
|
) : void 0;
|
|
6625
6713
|
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(
|
|
6714
|
+
const publish = requested === void 0 ? void 0 : checkPublishRequest(
|
|
6715
|
+
requested,
|
|
6716
|
+
packaged ? bundle.frontend : bundle.tree,
|
|
6717
|
+
{ folderFromManifest }
|
|
6718
|
+
);
|
|
6719
|
+
if (packaged && publish === void 0)
|
|
6720
|
+
throw new ApiError(
|
|
6721
|
+
501,
|
|
6722
|
+
`This host has no app stream, so it cannot publish the frontend this bundle carries.`
|
|
6723
|
+
);
|
|
6724
|
+
if (publish !== void 0 && publish.streamWebFolder === void 0) {
|
|
6725
|
+
if (bundle.backend !== void 0 && publish.appLoc !== void 0)
|
|
6726
|
+
await drive.deploy(publish.appLoc, bundle.backend, { replace: false });
|
|
6727
|
+
await drive.deploy(
|
|
6728
|
+
frontendFolderOf(publish.name),
|
|
6729
|
+
packaged ? bundle.frontend : bundle.tree,
|
|
6730
|
+
{ replace: true }
|
|
6731
|
+
);
|
|
6732
|
+
const entry2 = await services.appStream.publish(publish);
|
|
6733
|
+
return {
|
|
6734
|
+
status: 200,
|
|
6735
|
+
body: { ...DEPLOY_SUCCESS, app: appSummary(entry2) }
|
|
6736
|
+
};
|
|
6737
|
+
}
|
|
6627
6738
|
const replace = replaceOf(setting("replace")) ?? isUpload;
|
|
6739
|
+
if (appLoc === void 0)
|
|
6740
|
+
throw new ApiError(
|
|
6741
|
+
400,
|
|
6742
|
+
'"appLoc" is required to deploy files that do not name an app.'
|
|
6743
|
+
);
|
|
6628
6744
|
await drive.deploy(appLoc, bundle.tree, { replace });
|
|
6629
6745
|
if (publish === void 0 || !services.appStream)
|
|
6630
6746
|
return { status: 200, body: DEPLOY_SUCCESS };
|
|
@@ -9741,6 +9857,75 @@ var SASjsApi = (() => {
|
|
|
9741
9857
|
}
|
|
9742
9858
|
}
|
|
9743
9859
|
},
|
|
9860
|
+
{
|
|
9861
|
+
id: "deploy-publishes-a-package",
|
|
9862
|
+
route: "POST /SASjsApi/drive/deploy",
|
|
9863
|
+
description: "publishes a frontend to apps/<name> and writes the backend it carries to appLoc",
|
|
9864
|
+
request: {
|
|
9865
|
+
subject: SUBJECT,
|
|
9866
|
+
body: {
|
|
9867
|
+
fileTree: {
|
|
9868
|
+
members: [
|
|
9869
|
+
{
|
|
9870
|
+
name: "sasjs.app.json",
|
|
9871
|
+
type: "file",
|
|
9872
|
+
code: JSON.stringify({
|
|
9873
|
+
name: "macrodash",
|
|
9874
|
+
appLoc: "/Public/app/md"
|
|
9875
|
+
})
|
|
9876
|
+
},
|
|
9877
|
+
{
|
|
9878
|
+
name: "web",
|
|
9879
|
+
type: "folder",
|
|
9880
|
+
members: [
|
|
9881
|
+
{ name: "index.html", type: "file", code: "<h1>Dash</h1>" }
|
|
9882
|
+
]
|
|
9883
|
+
},
|
|
9884
|
+
{
|
|
9885
|
+
name: "backend",
|
|
9886
|
+
type: "folder",
|
|
9887
|
+
members: [
|
|
9888
|
+
{
|
|
9889
|
+
name: "services",
|
|
9890
|
+
type: "folder",
|
|
9891
|
+
members: [{ name: "run", type: "service", code: "%put hi;" }]
|
|
9892
|
+
}
|
|
9893
|
+
]
|
|
9894
|
+
}
|
|
9895
|
+
]
|
|
9896
|
+
}
|
|
9897
|
+
}
|
|
9898
|
+
},
|
|
9899
|
+
// the halves are named, so a host has to write them to two folders rather
|
|
9900
|
+
// than deploy the container: a status alone cannot see that
|
|
9901
|
+
expectDrive: {
|
|
9902
|
+
present: ["/apps/macrodash/index.html", "/Public/app/md/services/run.sas"]
|
|
9903
|
+
},
|
|
9904
|
+
expect: {
|
|
9905
|
+
status: 200,
|
|
9906
|
+
partial: {
|
|
9907
|
+
status: "success",
|
|
9908
|
+
app: { name: "macrodash" }
|
|
9909
|
+
}
|
|
9910
|
+
}
|
|
9911
|
+
},
|
|
9912
|
+
{
|
|
9913
|
+
id: "deploy-refuses-a-bundle-that-names-no-folder",
|
|
9914
|
+
route: "POST /SASjsApi/drive/deploy",
|
|
9915
|
+
description: "refuses a tree with no app named and no folder to deploy to, naming the field",
|
|
9916
|
+
request: {
|
|
9917
|
+
subject: SUBJECT,
|
|
9918
|
+
body: {
|
|
9919
|
+
fileTree: {
|
|
9920
|
+
members: [{ name: "run", type: "service", code: "%put hi;" }]
|
|
9921
|
+
}
|
|
9922
|
+
}
|
|
9923
|
+
},
|
|
9924
|
+
expect: {
|
|
9925
|
+
status: 400,
|
|
9926
|
+
error: '"appLoc" is required to deploy files that do not name an app.'
|
|
9927
|
+
}
|
|
9928
|
+
},
|
|
9744
9929
|
{
|
|
9745
9930
|
id: "deploy-refuses-a-bad-manifest",
|
|
9746
9931
|
route: "POST /SASjsApi/drive/deploy",
|
|
@@ -11941,7 +12126,13 @@ var SASjsApi = (() => {
|
|
|
11941
12126
|
var isEntry = (value) => {
|
|
11942
12127
|
if (typeof value !== "object" || value === null) return false;
|
|
11943
12128
|
const entry = value;
|
|
11944
|
-
|
|
12129
|
+
if (typeof entry.id !== "string" || typeof entry.name !== "string" || typeof entry.publishedAt !== "string")
|
|
12130
|
+
return false;
|
|
12131
|
+
if (entry.appLoc !== void 0 && typeof entry.appLoc !== "string")
|
|
12132
|
+
return false;
|
|
12133
|
+
if (entry.streamWebFolder !== void 0 && typeof entry.streamWebFolder !== "string")
|
|
12134
|
+
return false;
|
|
12135
|
+
return !(entry.streamWebFolder !== void 0 && entry.appLoc === void 0);
|
|
11945
12136
|
};
|
|
11946
12137
|
var createDriveAppStreamStore = (drive, filePath2 = APP_STREAM_INDEX) => ({
|
|
11947
12138
|
async read() {
|
|
@@ -12051,6 +12242,7 @@ var SASjsApi = (() => {
|
|
|
12051
12242
|
return void 0;
|
|
12052
12243
|
}
|
|
12053
12244
|
};
|
|
12245
|
+
var appRootOf = (entry) => entry.streamWebFolder !== void 0 && entry.appLoc !== void 0 ? `${entry.appLoc}/services/${entry.streamWebFolder}` : frontendFolderOf(entry.name);
|
|
12054
12246
|
var createAppStreamWebService = (appStream, drive, options = {}) => {
|
|
12055
12247
|
const base = (options.basePath ?? DEFAULT_APP_PATH).replace(/\/+$/, "");
|
|
12056
12248
|
const title = options.title ?? "SASjs App Stream";
|
|
@@ -12058,7 +12250,7 @@ var SASjsApi = (() => {
|
|
|
12058
12250
|
const rowOf = (entry) => ({
|
|
12059
12251
|
id: entry.id,
|
|
12060
12252
|
name: entry.name,
|
|
12061
|
-
appLoc: entry.appLoc,
|
|
12253
|
+
appLoc: entry.appLoc ?? null,
|
|
12062
12254
|
logo: entry.logo === void 0 ? null : `${urlOf(entry)}${entry.logo}`,
|
|
12063
12255
|
url: urlOf(entry),
|
|
12064
12256
|
publishedAt: entry.publishedAt ?? null
|
|
@@ -12070,7 +12262,9 @@ var SASjsApi = (() => {
|
|
|
12070
12262
|
const landing = async (allow) => {
|
|
12071
12263
|
const { apps: rows } = await apps(allow);
|
|
12072
12264
|
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(
|
|
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>`
|
|
12074
12268
|
).join("")}</ul>` : '<p class="empty">No apps have been published yet.</p>';
|
|
12075
12269
|
return html(
|
|
12076
12270
|
200,
|
|
@@ -12106,9 +12300,7 @@ var SASjsApi = (() => {
|
|
|
12106
12300
|
if (parts.some((part) => part === void 0)) return noSuchApp();
|
|
12107
12301
|
const relative = parts.join("/") || "index.html";
|
|
12108
12302
|
try {
|
|
12109
|
-
const file = await drive.read(
|
|
12110
|
-
`${entry.appLoc}/services/${entry.streamWebFolder}/${relative}`
|
|
12111
|
-
);
|
|
12303
|
+
const file = await drive.read(`${appRootOf(entry)}/${relative}`);
|
|
12112
12304
|
return {
|
|
12113
12305
|
status: 200,
|
|
12114
12306
|
body: file.contents,
|