@sasjs/api 0.39.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 +1 -1
|
@@ -244,6 +244,75 @@ exports.DEPLOY_CORPUS = [
|
|
|
244
244
|
}
|
|
245
245
|
}
|
|
246
246
|
},
|
|
247
|
+
{
|
|
248
|
+
id: 'deploy-publishes-a-package',
|
|
249
|
+
route: 'POST /SASjsApi/drive/deploy',
|
|
250
|
+
description: 'publishes a frontend to apps/<name> and writes the backend it carries to appLoc',
|
|
251
|
+
request: {
|
|
252
|
+
subject: SUBJECT,
|
|
253
|
+
body: {
|
|
254
|
+
fileTree: {
|
|
255
|
+
members: [
|
|
256
|
+
{
|
|
257
|
+
name: 'sasjs.app.json',
|
|
258
|
+
type: 'file',
|
|
259
|
+
code: JSON.stringify({
|
|
260
|
+
name: 'macrodash',
|
|
261
|
+
appLoc: '/Public/app/md'
|
|
262
|
+
})
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
name: 'web',
|
|
266
|
+
type: 'folder',
|
|
267
|
+
members: [
|
|
268
|
+
{ name: 'index.html', type: 'file', code: '<h1>Dash</h1>' }
|
|
269
|
+
]
|
|
270
|
+
},
|
|
271
|
+
{
|
|
272
|
+
name: 'backend',
|
|
273
|
+
type: 'folder',
|
|
274
|
+
members: [
|
|
275
|
+
{
|
|
276
|
+
name: 'services',
|
|
277
|
+
type: 'folder',
|
|
278
|
+
members: [{ name: 'run', type: 'service', code: '%put hi;' }]
|
|
279
|
+
}
|
|
280
|
+
]
|
|
281
|
+
}
|
|
282
|
+
]
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
},
|
|
286
|
+
// the halves are named, so a host has to write them to two folders rather
|
|
287
|
+
// than deploy the container: a status alone cannot see that
|
|
288
|
+
expectDrive: {
|
|
289
|
+
present: ['/apps/macrodash/index.html', '/Public/app/md/services/run.sas']
|
|
290
|
+
},
|
|
291
|
+
expect: {
|
|
292
|
+
status: 200,
|
|
293
|
+
partial: {
|
|
294
|
+
status: 'success',
|
|
295
|
+
app: { name: 'macrodash' }
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
id: 'deploy-refuses-a-bundle-that-names-no-folder',
|
|
301
|
+
route: 'POST /SASjsApi/drive/deploy',
|
|
302
|
+
description: 'refuses a tree with no app named and no folder to deploy to, naming the field',
|
|
303
|
+
request: {
|
|
304
|
+
subject: SUBJECT,
|
|
305
|
+
body: {
|
|
306
|
+
fileTree: {
|
|
307
|
+
members: [{ name: 'run', type: 'service', code: '%put hi;' }]
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
},
|
|
311
|
+
expect: {
|
|
312
|
+
status: 400,
|
|
313
|
+
error: '"appLoc" is required to deploy files that do not name an app.'
|
|
314
|
+
}
|
|
315
|
+
},
|
|
247
316
|
{
|
|
248
317
|
id: 'deploy-refuses-a-bad-manifest',
|
|
249
318
|
route: 'POST /SASjsApi/drive/deploy',
|
|
@@ -313,10 +313,13 @@ const dispatch = async (services, routeId, request = {}) => {
|
|
|
313
313
|
// expansion, which is why the two share this path rather than reading bytes.
|
|
314
314
|
case 'POST /SASjsApi/drive/deploy/upload':
|
|
315
315
|
case 'POST /SASjsApi/drive/deploy': {
|
|
316
|
-
// A bundle is one archive:
|
|
317
|
-
// statement that this
|
|
318
|
-
//
|
|
316
|
+
// A bundle is one archive: a deployment, and - when it carries one - the
|
|
317
|
+
// statement that this is an app. A current bundle names its halves, `web/`
|
|
318
|
+
// and `backend/`; the older shape is one tree with the web assets inside the
|
|
319
|
+
// backend's folder. The manifest is metadata either way, so it is taken out
|
|
320
|
+
// of the tree before anything is written.
|
|
319
321
|
const bundle = (0, bundle_js_1.splitAppBundle)(body.fileTree);
|
|
322
|
+
const packaged = bundle.frontend !== undefined;
|
|
320
323
|
const isUpload = routeId === 'POST /SASjsApi/drive/deploy/upload';
|
|
321
324
|
// The query is read on the upload route only: that is where the document
|
|
322
325
|
// states these, because the archive is the body. There the body is still the
|
|
@@ -324,20 +327,25 @@ const dispatch = async (services, routeId, request = {}) => {
|
|
|
324
327
|
// JSON route the document states them in the body, and a stray `?appLoc=`
|
|
325
328
|
// beside a body that names one would silently deploy to another folder.
|
|
326
329
|
const setting = (name) => isUpload ? (given(query[name]) ?? body?.[name]) : body?.[name];
|
|
327
|
-
|
|
330
|
+
// a setting the caller omitted is ABSENT, not an empty string: `''` names no
|
|
331
|
+
// folder, and handing it on turns "not stated" into a refusal about how the
|
|
332
|
+
// folder is spelled
|
|
333
|
+
const statedAppLoc = given(setting('appLoc'));
|
|
334
|
+
const appLoc = typeof statedAppLoc === 'string' ? statedAppLoc : undefined;
|
|
328
335
|
const requested = services.appStream
|
|
329
336
|
? (0, bundle_js_1.publishRequestFor)({
|
|
337
|
+
name: given(setting('name')),
|
|
330
338
|
appLoc,
|
|
331
339
|
streamWebFolder: given(setting('streamWebFolder')),
|
|
332
340
|
streamServiceName: given(setting('streamServiceName')),
|
|
333
341
|
streamLogo: given(setting('streamLogo'))
|
|
334
|
-
}, bundle.manifest)
|
|
342
|
+
}, bundle.manifest, { packaged })
|
|
335
343
|
: undefined;
|
|
336
344
|
// the index's own checks run BEFORE the drive is written: a tree the index
|
|
337
345
|
// would refuse must not leave its files behind, which is what happened when
|
|
338
346
|
// the deploy came first - a request answered `400` had already deployed.
|
|
339
|
-
// The tree goes in, so a
|
|
340
|
-
//
|
|
347
|
+
// The tree goes in, so what a browser would open is judged: a package's
|
|
348
|
+
// frontend, or the whole tree of a legacy bundle.
|
|
341
349
|
// the folder the refusal should tell the caller to fix: the bundle's, when
|
|
342
350
|
// the request did not state one and the manifest did
|
|
343
351
|
const folderFromManifest = requested?.streamWebFolder !== undefined &&
|
|
@@ -345,11 +353,31 @@ const dispatch = async (services, routeId, request = {}) => {
|
|
|
345
353
|
bundle.manifest?.streamWebFolder !== undefined;
|
|
346
354
|
const publish = requested === undefined
|
|
347
355
|
? undefined
|
|
348
|
-
: (0, service_js_1.checkPublishRequest)(requested, bundle.tree, { folderFromManifest });
|
|
356
|
+
: (0, service_js_1.checkPublishRequest)(requested, packaged ? bundle.frontend : bundle.tree, { folderFromManifest });
|
|
357
|
+
// a package has nowhere to go without an index: its frontend is `apps/<name>`,
|
|
358
|
+
// which only a published app has
|
|
359
|
+
if (packaged && publish === undefined)
|
|
360
|
+
throw new types_js_1.ApiError(501, `This host has no app stream, so it cannot publish the frontend this bundle carries.`);
|
|
361
|
+
if (publish !== undefined && publish.streamWebFolder === undefined) {
|
|
362
|
+
// check, backend, frontend, index - the backend first so a frontend is
|
|
363
|
+
// never live against services that are not deployed yet, and additively
|
|
364
|
+
// because several frontends may name one backend
|
|
365
|
+
if (bundle.backend !== undefined && publish.appLoc !== undefined)
|
|
366
|
+
await drive.deploy(publish.appLoc, bundle.backend, { replace: false });
|
|
367
|
+
// publishing a frontend means the folder is what this bundle says it is
|
|
368
|
+
await drive.deploy((0, service_js_1.frontendFolderOf)(publish.name), (packaged ? bundle.frontend : bundle.tree), { replace: true });
|
|
369
|
+
const entry = await services.appStream.publish(publish);
|
|
370
|
+
return {
|
|
371
|
+
status: 200,
|
|
372
|
+
body: { ...deploy_js_1.DEPLOY_SUCCESS, app: (0, service_js_1.appSummary)(entry) }
|
|
373
|
+
};
|
|
374
|
+
}
|
|
349
375
|
// an archive upload replaces by default - publishing a folder means the
|
|
350
376
|
// folder is what the archive says it is - while the JSON route writes over
|
|
351
377
|
// what is there unless it is told otherwise
|
|
352
378
|
const replace = replaceOf(setting('replace')) ?? isUpload;
|
|
379
|
+
if (appLoc === undefined)
|
|
380
|
+
throw new types_js_1.ApiError(400, '"appLoc" is required to deploy files that do not name an app.');
|
|
353
381
|
await drive.deploy(appLoc, bundle.tree, { replace });
|
|
354
382
|
// a deploy of something that is not an app writes files and says so; an app
|
|
355
383
|
// is indexed in the same request, so the two cannot disagree
|
package/build/cjs/index.js
CHANGED
|
@@ -15,8 +15,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.BROWSER_INFO = exports.withBundleVersion = exports.createHomeService = exports.NO_WEB_BUILD = exports.BUNDLE_NAME = exports.HOME_CORPUS = exports.DIRECTORY_CORPUS = exports.AUTH_CONFIG_CORPUS = exports.ADMIN_CORPUS = exports.INFO_CORPUS = exports.CODE_CORPUS = exports.sanitiseDisplayName = exports.createRecordService = exports.createIdentityService = exports.HANDLED_ROUTES = exports.dispatch = exports.VIYA_CORPUS = exports.VIYA_HANDLERS = exports.VIYA_OVERLAY = exports.findViyaOperation = exports.dispatchViya = exports.emulatedHeaders = exports.VIYA_TARGET_VERSION = exports.VIYA_CAPTURED_AT = exports.EMULATED_HEADER_VALUE = exports.EMULATED_HEADER = exports.UNRECORDED = exports.VIYA_TABLE = exports.SURFACE_ADAPTER_VERSION = exports.SURFACE = exports.TAG_CAPABILITIES = exports.OVERLAY = exports.findRoute = exports.routeById = exports.ROUTES = exports.MemoryDriveStore = exports.measureDeployTree = exports.isDeployTree = exports.deployTree = exports.decodeBase64 = exports.checkDeployTree = exports.DEPLOY_SUCCESS = exports.DEPLOY_PAYLOAD_BYTES = exports.DEPLOY_LIMITS = exports.createDriveService = exports.isRoot = exports.basename = exports.dirname = exports.hasBlockedExtension = exports.normaliseDrivePath = void 0;
|
|
18
|
-
exports.
|
|
19
|
-
exports.normaliseAppLoc = exports.newAppId = exports.isAppId = exports.escapeHtml = exports.createAppStreamWebService = exports.contentTypeFor = exports.cacheControlFor = void 0;
|
|
18
|
+
exports.publishRequestFor = exports.parseAppManifest = exports.FRONTEND_FOLDER = exports.BACKEND_FOLDER = exports.APP_MANIFEST = exports.MemoryAppStreamStore = exports.hasFrontendRoot = exports.frontendFolderOf = exports.defaultAppName = exports.createAppStreamService = exports.checkPublishRequest = exports.appSummary = exports.APP_FOLDERS_ROOT = exports.servicesFor = exports.runCase = exports.PROVIDER_MANAGED = exports.ADMIN_SIGNED_IN = exports.RECORD_CORPUS = exports.RUNTIME_CORPUS = exports.MemorySessionRunner = exports.runTimeOfPath = exports.resolveProgram = exports.programNotFound = exports.DOCUMENTED_RUN_TIMES = exports.createRuntimeService = exports.CODE_DEBUG = exports.MemorySessionHost = exports.DEFAULT_SESSIONS = exports.createSessionService = exports.SESSION_CORPUS = exports.APP_CORPUS = exports.DEPLOY_CORPUS = exports.IDENTITY_CORPUS = exports.DRIVE_CORPUS = exports.parseIdentity = exports.IDENTITY_FORMAT = exports.DEFAULT_IDENTITY = exports.MemoryIdentityStore = exports.createDirectoryService = exports.normaliseLogFiles = exports.normaliseDiagnostics = exports.logLines = exports.createAdminService = exports.checkLogFileName = exports.MAX_LOG_LINES = exports.DEFAULT_LOG_LINES = exports.normaliseAuthConfig = exports.createAuthConfigService = exports.normaliseInfo = exports.createInfoService = void 0;
|
|
19
|
+
exports.normaliseAppLoc = exports.newAppId = exports.isAppId = exports.escapeHtml = exports.createAppStreamWebService = exports.contentTypeFor = exports.cacheControlFor = exports.appRootOf = exports.NO_SUCH_APP = exports.DEFAULT_APP_PATH = exports.createDriveAppStreamStore = exports.APP_STREAM_INDEX = exports.splitAppBundle = void 0;
|
|
20
20
|
/**
|
|
21
21
|
* `@sasjs/api` - the SASjs Server API described once.
|
|
22
22
|
*
|
|
@@ -169,13 +169,18 @@ var runner_js_1 = require("./corpus/runner.js");
|
|
|
169
169
|
Object.defineProperty(exports, "runCase", { enumerable: true, get: function () { return runner_js_1.runCase; } });
|
|
170
170
|
Object.defineProperty(exports, "servicesFor", { enumerable: true, get: function () { return runner_js_1.servicesFor; } });
|
|
171
171
|
var service_js_11 = require("./appstream/service.js");
|
|
172
|
+
Object.defineProperty(exports, "APP_FOLDERS_ROOT", { enumerable: true, get: function () { return service_js_11.APP_FOLDERS_ROOT; } });
|
|
172
173
|
Object.defineProperty(exports, "appSummary", { enumerable: true, get: function () { return service_js_11.appSummary; } });
|
|
173
174
|
Object.defineProperty(exports, "checkPublishRequest", { enumerable: true, get: function () { return service_js_11.checkPublishRequest; } });
|
|
174
175
|
Object.defineProperty(exports, "createAppStreamService", { enumerable: true, get: function () { return service_js_11.createAppStreamService; } });
|
|
175
176
|
Object.defineProperty(exports, "defaultAppName", { enumerable: true, get: function () { return service_js_11.defaultAppName; } });
|
|
177
|
+
Object.defineProperty(exports, "frontendFolderOf", { enumerable: true, get: function () { return service_js_11.frontendFolderOf; } });
|
|
178
|
+
Object.defineProperty(exports, "hasFrontendRoot", { enumerable: true, get: function () { return service_js_11.hasFrontendRoot; } });
|
|
176
179
|
Object.defineProperty(exports, "MemoryAppStreamStore", { enumerable: true, get: function () { return service_js_11.MemoryAppStreamStore; } });
|
|
177
180
|
var bundle_js_1 = require("./appstream/bundle.js");
|
|
178
181
|
Object.defineProperty(exports, "APP_MANIFEST", { enumerable: true, get: function () { return bundle_js_1.APP_MANIFEST; } });
|
|
182
|
+
Object.defineProperty(exports, "BACKEND_FOLDER", { enumerable: true, get: function () { return bundle_js_1.BACKEND_FOLDER; } });
|
|
183
|
+
Object.defineProperty(exports, "FRONTEND_FOLDER", { enumerable: true, get: function () { return bundle_js_1.FRONTEND_FOLDER; } });
|
|
179
184
|
Object.defineProperty(exports, "parseAppManifest", { enumerable: true, get: function () { return bundle_js_1.parseAppManifest; } });
|
|
180
185
|
Object.defineProperty(exports, "publishRequestFor", { enumerable: true, get: function () { return bundle_js_1.publishRequestFor; } });
|
|
181
186
|
Object.defineProperty(exports, "splitAppBundle", { enumerable: true, get: function () { return bundle_js_1.splitAppBundle; } });
|
|
@@ -185,6 +190,7 @@ Object.defineProperty(exports, "createDriveAppStreamStore", { enumerable: true,
|
|
|
185
190
|
var web_js_1 = require("./appstream/web.js");
|
|
186
191
|
Object.defineProperty(exports, "DEFAULT_APP_PATH", { enumerable: true, get: function () { return web_js_1.DEFAULT_APP_PATH; } });
|
|
187
192
|
Object.defineProperty(exports, "NO_SUCH_APP", { enumerable: true, get: function () { return web_js_1.NO_SUCH_APP; } });
|
|
193
|
+
Object.defineProperty(exports, "appRootOf", { enumerable: true, get: function () { return web_js_1.appRootOf; } });
|
|
188
194
|
Object.defineProperty(exports, "cacheControlFor", { enumerable: true, get: function () { return web_js_1.cacheControlFor; } });
|
|
189
195
|
Object.defineProperty(exports, "contentTypeFor", { enumerable: true, get: function () { return web_js_1.contentTypeFor; } });
|
|
190
196
|
Object.defineProperty(exports, "createAppStreamWebService", { enumerable: true, get: function () { return web_js_1.createAppStreamWebService; } });
|
|
@@ -574,7 +574,13 @@ exports.GENERATED_ROUTES = [
|
|
|
574
574
|
{
|
|
575
575
|
name: 'appLoc',
|
|
576
576
|
in: 'body',
|
|
577
|
-
required:
|
|
577
|
+
required: false,
|
|
578
|
+
type: 'string'
|
|
579
|
+
},
|
|
580
|
+
{
|
|
581
|
+
name: 'name',
|
|
582
|
+
in: 'body',
|
|
583
|
+
required: false,
|
|
578
584
|
type: 'string'
|
|
579
585
|
},
|
|
580
586
|
{
|
|
@@ -635,6 +641,12 @@ exports.GENERATED_ROUTES = [
|
|
|
635
641
|
tag: 'Drive',
|
|
636
642
|
summary: 'Deploy an uploaded file to SASjs Drive',
|
|
637
643
|
params: [
|
|
644
|
+
{
|
|
645
|
+
name: 'name',
|
|
646
|
+
in: 'query',
|
|
647
|
+
required: false,
|
|
648
|
+
type: 'string'
|
|
649
|
+
},
|
|
638
650
|
{
|
|
639
651
|
name: 'appLoc',
|
|
640
652
|
in: 'query',
|
|
@@ -2,45 +2,89 @@ import type { DeployTree } from '../drive/deploy.js';
|
|
|
2
2
|
import type { PublishAppRequest } from './service.js';
|
|
3
3
|
/** The file, at the root of an app bundle, that says the bundle is an app. */
|
|
4
4
|
export declare const APP_MANIFEST = "sasjs.app.json";
|
|
5
|
+
/** The folder in a package holding the compiled frontend. */
|
|
6
|
+
export declare const FRONTEND_FOLDER = "web";
|
|
7
|
+
/** The folder in a package holding the services the frontend calls. */
|
|
8
|
+
export declare const BACKEND_FOLDER = "backend";
|
|
5
9
|
export interface AppManifest {
|
|
6
|
-
/** The
|
|
10
|
+
/** The app's name: its folder under `apps/`, and its address. */
|
|
7
11
|
name?: string;
|
|
8
|
-
/** The
|
|
9
|
-
|
|
12
|
+
/** The backend this frontend calls. Metadata, and optional. */
|
|
13
|
+
appLoc?: string;
|
|
14
|
+
/** Legacy only: the folder under `<appLoc>/services` holding the web assets. */
|
|
15
|
+
streamWebFolder?: string;
|
|
10
16
|
/** An asset inside the app, used as its tile image. */
|
|
11
17
|
logo?: string;
|
|
12
18
|
/** Origins allowed to frame the app, as CSP `frame-ancestors` sources. */
|
|
13
19
|
frameAncestors?: string | string[];
|
|
14
20
|
}
|
|
15
21
|
export interface AppBundle {
|
|
16
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* The tree the bundle's body describes - what a legacy deploy writes to
|
|
24
|
+
* `appLoc`. When `frontend` is present this is the container of the two halves
|
|
25
|
+
* and is NOT deployed as it stands.
|
|
26
|
+
*/
|
|
17
27
|
tree: DeployTree;
|
|
28
|
+
/** The compiled frontend, when the bundle carries one at `web/`. */
|
|
29
|
+
frontend?: DeployTree;
|
|
30
|
+
/** The backend tree, when the bundle carries services at `backend/`. */
|
|
31
|
+
backend?: DeployTree;
|
|
18
32
|
manifest?: AppManifest;
|
|
19
33
|
}
|
|
20
|
-
/**
|
|
34
|
+
/**
|
|
35
|
+
* A manifest, checked field by field, naming the field that is wrong.
|
|
36
|
+
*
|
|
37
|
+
* Nothing is required: a package states its name, a legacy bundle states its
|
|
38
|
+
* stream folder, and a deploy that states neither in the manifest states them in
|
|
39
|
+
* its payload. What the manifest states has to be usable, which is what is checked
|
|
40
|
+
* here; whether the request as a whole can publish is `checkPublishRequest`'s
|
|
41
|
+
* question, asked once against the request the two have been composed into.
|
|
42
|
+
*/
|
|
21
43
|
export declare const parseAppManifest: (value: unknown) => AppManifest;
|
|
22
44
|
/**
|
|
23
|
-
* The deploy tree split from its manifest.
|
|
45
|
+
* The deploy tree split from its manifest, and from the halves a package names.
|
|
24
46
|
*
|
|
25
47
|
* A tree that is not a tree is passed through untouched: the deploy is the thing
|
|
26
48
|
* that refuses a malformed tree, with the message its own cases pin, and saying
|
|
27
49
|
* it here as well would be two wordings of one refusal.
|
|
50
|
+
*
|
|
51
|
+
* A bundle is a package when it holds a `web/` folder or a manifest at its root.
|
|
52
|
+
* The frontend is then that folder's contents - which is why a compiled app is
|
|
53
|
+
* zipped as the folder's contents rather than the folder itself - and a `backend/`
|
|
54
|
+
* folder beside it is the tree to write to `appLoc`.
|
|
28
55
|
*/
|
|
29
56
|
export declare const splitAppBundle: (tree: unknown) => AppBundle;
|
|
30
57
|
/** What a deploy request says about the app it publishes. */
|
|
31
58
|
export interface DeployPublish {
|
|
32
|
-
|
|
59
|
+
/** The app's name, when the request states one. */
|
|
60
|
+
name?: string;
|
|
61
|
+
/** The backend folder. Metadata for a frontend publish. */
|
|
62
|
+
appLoc?: string;
|
|
63
|
+
/** Legacy: the folder under `<appLoc>/services` holding the web assets. */
|
|
33
64
|
streamWebFolder?: string;
|
|
65
|
+
/** The app's name, under the field name an older payload uses. */
|
|
34
66
|
streamServiceName?: string;
|
|
35
67
|
streamLogo?: string;
|
|
36
68
|
}
|
|
37
69
|
/**
|
|
38
70
|
* The publish a deploy asks for, or `undefined` when it publishes nothing.
|
|
39
71
|
*
|
|
40
|
-
* The request wins over the bundle where both speak - a caller naming a folder
|
|
41
|
-
* a label is correcting the archive, not repeating it - and the bundle
|
|
42
|
-
* the request leaves out
|
|
43
|
-
*
|
|
72
|
+
* The request wins over the bundle where both speak - a caller naming a folder, a
|
|
73
|
+
* name or a label is correcting the archive, not repeating it - and the bundle
|
|
74
|
+
* fills what the request leaves out.
|
|
75
|
+
*
|
|
76
|
+
* A bundle is published as a **legacy** app when either half states a
|
|
77
|
+
* `streamWebFolder`: that field is what puts the web assets inside the backend's
|
|
78
|
+
* folder, and a request that keeps it is asking for the shape it describes. A
|
|
79
|
+
* package publishes as a **frontend** instead, which needs only a name - the
|
|
80
|
+
* folder follows from it.
|
|
81
|
+
*
|
|
82
|
+
* `packaged` says the bundle carries a `web/` folder, so a request that names
|
|
83
|
+
* neither a stream folder nor a name is an app with nothing to call it: the
|
|
84
|
+
* request comes back without a name and `checkPublishRequest` refuses it by name,
|
|
85
|
+
* rather than the deploy writing the frontend nowhere.
|
|
44
86
|
*/
|
|
45
|
-
export declare const publishRequestFor: (deploy: DeployPublish, manifest?: AppManifest
|
|
87
|
+
export declare const publishRequestFor: (deploy: DeployPublish, manifest?: AppManifest, options?: {
|
|
88
|
+
packaged?: boolean;
|
|
89
|
+
}) => PublishAppRequest | undefined;
|
|
46
90
|
//# sourceMappingURL=bundle.d.ts.map
|
|
@@ -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;
|
|
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,SAoE9C,CAAA;AAED,6DAA6D;AAC7D,MAAM,WAAW,aAAa;IAC5B,mDAAmD;IACnD,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,2DAA2D;IAC3D,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,2EAA2E;IAC3E,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,kEAAkE;IAClE,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,iBAAiB,GAC5B,QAAQ,aAAa,EACrB,WAAW,WAAW,EACtB,UAAS;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAO,KACnC,iBAAiB,GAAG,SAwBtB,CAAA"}
|
|
@@ -1,32 +1,36 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* An app as one bundle: the deployment and the statement of what it publishes.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* everything the app is - its services under `services/`, the compiled web assets
|
|
6
|
-
* under `services/<streamWebFolder>`, and whatever jobs and data files it was
|
|
7
|
-
* built with. What a tree cannot say is that the folder IS an app: which of its
|
|
8
|
-
* folders holds the web build, what it should be called, and whether it may be
|
|
9
|
-
* framed. That statement is a small file at the root of the archive:
|
|
4
|
+
* Two shapes travel through here, and the difference is where the frontend sits.
|
|
10
5
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* web/ the compiled app: index.html, main.<hash>.js, assets/
|
|
14
|
-
* build.sas the services the app calls
|
|
15
|
-
* jobs/
|
|
6
|
+
* **A package** is what a current `sasjs build` emits for a server: a frontend, an
|
|
7
|
+
* optional backend, and a manifest saying which app the frontend is.
|
|
16
8
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* so it is stripped from the tree before the tree is written and never appears in
|
|
21
|
-
* the app's served files.
|
|
9
|
+
* sasjs.app.json {"name": "macrodash", "appLoc": "/Public/app/macrodash"}
|
|
10
|
+
* web/ the compiled app: index.html, assets/
|
|
11
|
+
* backend/ optional: the services the app calls, written to appLoc
|
|
22
12
|
*
|
|
23
|
-
* The
|
|
24
|
-
*
|
|
25
|
-
*
|
|
13
|
+
* The halves are named, not inferred from a path: `web/` becomes `apps/<name>` and
|
|
14
|
+
* `backend/` becomes `appLoc`, and neither is guessed at from a member's name.
|
|
15
|
+
* One zip therefore deploys a backend and publishes a frontend in a single
|
|
16
|
+
* request, and the frontend can be republished alone by leaving `backend/` out.
|
|
17
|
+
*
|
|
18
|
+
* **A legacy bundle** is the shape before that: one tree deployed to `appLoc`,
|
|
19
|
+
* with the web assets carried at `services/<streamWebFolder>`. It is what every
|
|
20
|
+
* released CLI emits, and it keeps working unchanged - the manifest is optional
|
|
21
|
+
* there because the deploy payload states the stream fields instead.
|
|
22
|
+
*
|
|
23
|
+
* The manifest is metadata, not an asset: it is taken out of the tree before the
|
|
24
|
+
* tree is written and never appears in the app's served files.
|
|
26
25
|
*/
|
|
27
26
|
import { ApiError } from '../types.js';
|
|
27
|
+
import { decodeBase64 } from '../drive/deploy.js';
|
|
28
28
|
/** The file, at the root of an app bundle, that says the bundle is an app. */
|
|
29
29
|
export const APP_MANIFEST = 'sasjs.app.json';
|
|
30
|
+
/** The folder in a package holding the compiled frontend. */
|
|
31
|
+
export const FRONTEND_FOLDER = 'web';
|
|
32
|
+
/** The folder in a package holding the services the frontend calls. */
|
|
33
|
+
export const BACKEND_FOLDER = 'backend';
|
|
30
34
|
const isObject = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
31
35
|
const text = (value, field) => {
|
|
32
36
|
if (value === undefined)
|
|
@@ -35,15 +39,24 @@ const text = (value, field) => {
|
|
|
35
39
|
throw new ApiError(400, `"${field}" must be a non-empty string in ${APP_MANIFEST}.`);
|
|
36
40
|
return value.trim();
|
|
37
41
|
};
|
|
38
|
-
/**
|
|
42
|
+
/**
|
|
43
|
+
* A manifest, checked field by field, naming the field that is wrong.
|
|
44
|
+
*
|
|
45
|
+
* Nothing is required: a package states its name, a legacy bundle states its
|
|
46
|
+
* stream folder, and a deploy that states neither in the manifest states them in
|
|
47
|
+
* its payload. What the manifest states has to be usable, which is what is checked
|
|
48
|
+
* here; whether the request as a whole can publish is `checkPublishRequest`'s
|
|
49
|
+
* question, asked once against the request the two have been composed into.
|
|
50
|
+
*/
|
|
39
51
|
export const parseAppManifest = (value) => {
|
|
40
52
|
if (!isObject(value))
|
|
41
53
|
throw new ApiError(400, `${APP_MANIFEST} must be an object.`);
|
|
42
|
-
const streamWebFolder = text(value.streamWebFolder, 'streamWebFolder');
|
|
43
|
-
if (streamWebFolder === undefined)
|
|
44
|
-
throw new ApiError(400, `${APP_MANIFEST} must state "streamWebFolder": the folder under services/ holding the compiled app.`);
|
|
45
54
|
const name = text(value.name, 'name');
|
|
55
|
+
const appLoc = text(value.appLoc, 'appLoc');
|
|
56
|
+
const streamWebFolder = text(value.streamWebFolder, 'streamWebFolder');
|
|
46
57
|
const logo = text(value.logo, 'logo');
|
|
58
|
+
if (streamWebFolder !== undefined && /[\\/]/.test(streamWebFolder))
|
|
59
|
+
throw new ApiError(400, `"streamWebFolder" in ${APP_MANIFEST} must be a single path segment.`);
|
|
47
60
|
const frameAncestors = value.frameAncestors;
|
|
48
61
|
if (frameAncestors !== undefined &&
|
|
49
62
|
(typeof frameAncestors !== 'string' || frameAncestors === '') &&
|
|
@@ -53,66 +66,118 @@ export const parseAppManifest = (value) => {
|
|
|
53
66
|
throw new ApiError(400, `"frameAncestors" in ${APP_MANIFEST} must be a string or a non-empty list of strings.`);
|
|
54
67
|
return {
|
|
55
68
|
...(name === undefined ? {} : { name }),
|
|
56
|
-
|
|
69
|
+
...(appLoc === undefined ? {} : { appLoc }),
|
|
70
|
+
...(streamWebFolder === undefined ? {} : { streamWebFolder }),
|
|
57
71
|
...(logo === undefined ? {} : { logo }),
|
|
58
72
|
...(frameAncestors === undefined
|
|
59
73
|
? {}
|
|
60
74
|
: { frameAncestors: frameAncestors })
|
|
61
75
|
};
|
|
62
76
|
};
|
|
77
|
+
/** A member that is a folder, by name. */
|
|
78
|
+
const folderNamed = (members, name) => members.find((member) => isObject(member) && member.type === 'folder' && member.name === name);
|
|
79
|
+
/** A folder's own members, as a tree of its contents. */
|
|
80
|
+
const contentsOf = (member) => {
|
|
81
|
+
const members = member?.members;
|
|
82
|
+
return Array.isArray(members)
|
|
83
|
+
? { members: members }
|
|
84
|
+
: undefined;
|
|
85
|
+
};
|
|
63
86
|
/**
|
|
64
|
-
* The deploy tree split from its manifest.
|
|
87
|
+
* The deploy tree split from its manifest, and from the halves a package names.
|
|
65
88
|
*
|
|
66
89
|
* A tree that is not a tree is passed through untouched: the deploy is the thing
|
|
67
90
|
* that refuses a malformed tree, with the message its own cases pin, and saying
|
|
68
91
|
* it here as well would be two wordings of one refusal.
|
|
92
|
+
*
|
|
93
|
+
* A bundle is a package when it holds a `web/` folder or a manifest at its root.
|
|
94
|
+
* The frontend is then that folder's contents - which is why a compiled app is
|
|
95
|
+
* zipped as the folder's contents rather than the folder itself - and a `backend/`
|
|
96
|
+
* folder beside it is the tree to write to `appLoc`.
|
|
69
97
|
*/
|
|
70
98
|
export const splitAppBundle = (tree) => {
|
|
71
99
|
if (!isObject(tree) || !Array.isArray(tree.members))
|
|
72
100
|
return { tree: tree };
|
|
73
101
|
const members = tree.members;
|
|
74
102
|
const at = members.findIndex((member) => isObject(member) && member.type === 'file' && member.name === APP_MANIFEST);
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
103
|
+
const withoutManifest = at === -1 ? members : members.filter((_, index) => index !== at);
|
|
104
|
+
let manifest;
|
|
105
|
+
if (at !== -1) {
|
|
106
|
+
const member = members[at];
|
|
107
|
+
if (typeof member.code !== 'string')
|
|
108
|
+
throw new ApiError(400, `${APP_MANIFEST} carries no text.`);
|
|
109
|
+
// a manifest read out of a zip is bytes: an archive records no text/binary
|
|
110
|
+
// distinction, so the tree builder marks every member `base64` and the
|
|
111
|
+
// manifest has to be decoded before it can be parsed
|
|
112
|
+
const source = member.encoding === 'base64'
|
|
113
|
+
? new TextDecoder().decode(decodeBase64(member.code))
|
|
114
|
+
: member.code;
|
|
115
|
+
let parsed;
|
|
116
|
+
try {
|
|
117
|
+
parsed = JSON.parse(source);
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
throw new ApiError(400, `${APP_MANIFEST} is not valid JSON: ${error.message}`);
|
|
121
|
+
}
|
|
122
|
+
manifest = parseAppManifest(parsed);
|
|
86
123
|
}
|
|
124
|
+
const rest = { ...tree, members: withoutManifest };
|
|
125
|
+
const web = folderNamed(withoutManifest, FRONTEND_FOLDER);
|
|
126
|
+
// nothing says this is an app: pass the tree through untouched, so a caller that
|
|
127
|
+
// keeps its own copy sees no change and the deploy is the thing that judges it.
|
|
128
|
+
// A manifest is the only other way out of this branch, so there is none here.
|
|
129
|
+
if (web === undefined && manifest === undefined)
|
|
130
|
+
return { tree: tree };
|
|
131
|
+
// a `web/` folder is the frontend; without one, a manifest still says the tree
|
|
132
|
+
// is an app, and the whole tree is then the app's own files
|
|
133
|
+
const backend = contentsOf(folderNamed(withoutManifest, BACKEND_FOLDER));
|
|
87
134
|
return {
|
|
88
|
-
tree:
|
|
89
|
-
|
|
90
|
-
members:
|
|
135
|
+
tree: rest,
|
|
136
|
+
frontend: contentsOf(web) ?? {
|
|
137
|
+
members: withoutManifest.filter((member) => member !== folderNamed(withoutManifest, BACKEND_FOLDER))
|
|
91
138
|
},
|
|
92
|
-
|
|
139
|
+
...(backend === undefined ? {} : { backend }),
|
|
140
|
+
manifest: manifest
|
|
93
141
|
};
|
|
94
142
|
};
|
|
95
143
|
/**
|
|
96
144
|
* The publish a deploy asks for, or `undefined` when it publishes nothing.
|
|
97
145
|
*
|
|
98
|
-
* The request wins over the bundle where both speak - a caller naming a folder
|
|
99
|
-
* a label is correcting the archive, not repeating it - and the bundle
|
|
100
|
-
* the request leaves out
|
|
101
|
-
*
|
|
146
|
+
* The request wins over the bundle where both speak - a caller naming a folder, a
|
|
147
|
+
* name or a label is correcting the archive, not repeating it - and the bundle
|
|
148
|
+
* fills what the request leaves out.
|
|
149
|
+
*
|
|
150
|
+
* A bundle is published as a **legacy** app when either half states a
|
|
151
|
+
* `streamWebFolder`: that field is what puts the web assets inside the backend's
|
|
152
|
+
* folder, and a request that keeps it is asking for the shape it describes. A
|
|
153
|
+
* package publishes as a **frontend** instead, which needs only a name - the
|
|
154
|
+
* folder follows from it.
|
|
155
|
+
*
|
|
156
|
+
* `packaged` says the bundle carries a `web/` folder, so a request that names
|
|
157
|
+
* neither a stream folder nor a name is an app with nothing to call it: the
|
|
158
|
+
* request comes back without a name and `checkPublishRequest` refuses it by name,
|
|
159
|
+
* rather than the deploy writing the frontend nowhere.
|
|
102
160
|
*/
|
|
103
|
-
export const publishRequestFor = (deploy, manifest) => {
|
|
161
|
+
export const publishRequestFor = (deploy, manifest, options = {}) => {
|
|
104
162
|
const streamWebFolder = deploy.streamWebFolder ?? manifest?.streamWebFolder;
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
const name = deploy.streamServiceName ?? manifest?.name;
|
|
163
|
+
const appLoc = deploy.appLoc ?? manifest?.appLoc;
|
|
164
|
+
const name = deploy.name ?? deploy.streamServiceName ?? manifest?.name;
|
|
108
165
|
const logo = deploy.streamLogo ?? manifest?.logo;
|
|
166
|
+
const frameAncestors = manifest?.frameAncestors;
|
|
167
|
+
if (streamWebFolder !== undefined)
|
|
168
|
+
return {
|
|
169
|
+
...(appLoc === undefined ? {} : { appLoc }),
|
|
170
|
+
streamWebFolder,
|
|
171
|
+
...(name === undefined ? {} : { name }),
|
|
172
|
+
...(logo === undefined ? {} : { logo }),
|
|
173
|
+
...(frameAncestors === undefined ? {} : { frameAncestors })
|
|
174
|
+
};
|
|
175
|
+
if (name === undefined && !options.packaged)
|
|
176
|
+
return undefined;
|
|
109
177
|
return {
|
|
110
|
-
appLoc: deploy.appLoc,
|
|
111
|
-
streamWebFolder,
|
|
112
178
|
...(name === undefined ? {} : { name }),
|
|
179
|
+
...(appLoc === undefined ? {} : { appLoc }),
|
|
113
180
|
...(logo === undefined ? {} : { logo }),
|
|
114
|
-
...(
|
|
115
|
-
? {}
|
|
116
|
-
: { frameAncestors: manifest.frameAncestors })
|
|
181
|
+
...(frameAncestors === undefined ? {} : { frameAncestors })
|
|
117
182
|
};
|
|
118
183
|
};
|