@sasjs/api 0.29.0 → 0.31.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 +559 -325
- package/build/cjs/appstream/service.js +48 -5
- package/build/cjs/appstream/web.js +7 -3
- package/build/cjs/corpus/app.js +55 -0
- package/build/cjs/corpus/runner.js +7 -6
- package/build/cjs/host/dispatch.js +71 -0
- package/build/cjs/index.js +9 -2
- package/build/cjs/routes/generated.js +34 -0
- package/build/cjs/routes/overlay.js +34 -1
- package/build/cjs/runtime/program.js +85 -0
- package/build/cjs/runtime/runTimes.js +13 -0
- package/build/cjs/runtime/service.js +11 -13
- package/build/esm/appstream/service.d.ts.map +1 -1
- package/build/esm/appstream/service.js +48 -5
- package/build/esm/appstream/web.d.ts.map +1 -1
- package/build/esm/appstream/web.js +7 -3
- package/build/esm/corpus/app.d.ts +17 -0
- package/build/esm/corpus/app.d.ts.map +1 -0
- package/build/esm/corpus/app.js +52 -0
- package/build/esm/corpus/runner.d.ts +13 -0
- package/build/esm/corpus/runner.d.ts.map +1 -1
- package/build/esm/corpus/runner.js +5 -4
- package/build/esm/host/dispatch.d.ts.map +1 -1
- package/build/esm/host/dispatch.js +72 -1
- package/build/esm/index.d.ts +5 -1
- package/build/esm/index.d.ts.map +1 -1
- package/build/esm/index.js +4 -1
- package/build/esm/routes/generated.d.ts.map +1 -1
- package/build/esm/routes/generated.js +34 -0
- package/build/esm/routes/overlay.d.ts.map +1 -1
- package/build/esm/routes/overlay.js +34 -1
- package/build/esm/runtime/program.d.ts +56 -0
- package/build/esm/runtime/program.d.ts.map +1 -0
- package/build/esm/runtime/program.js +79 -0
- package/build/esm/runtime/runTimes.d.ts +11 -0
- package/build/esm/runtime/runTimes.d.ts.map +1 -0
- package/build/esm/runtime/runTimes.js +10 -0
- package/build/esm/runtime/service.d.ts +0 -2
- package/build/esm/runtime/service.d.ts.map +1 -1
- package/build/esm/runtime/service.js +9 -11
- package/package.json +1 -1
|
@@ -7,9 +7,11 @@ exports.MemoryAppStreamStore = exports.createAppStreamService = exports.checkPub
|
|
|
7
7
|
* An app is one deployed folder (`appLoc`), the web assets inside it
|
|
8
8
|
* (`appLoc/services/<streamWebFolder>`) and a UUID assigned when it is first
|
|
9
9
|
* published. The id is the key the routes, the listing and the permission rules
|
|
10
|
-
* point at
|
|
11
|
-
*
|
|
12
|
-
* is
|
|
10
|
+
* point at, and it is what a redeploy keeps. The name is a label a person reads
|
|
11
|
+
* AND - when exactly one app holds it - an address: `/app/<name>` opens the app,
|
|
12
|
+
* so a name the caller states is validated as a URL segment and has to be free.
|
|
13
|
+
* A label derived from the folder carries no such rule, because it was not
|
|
14
|
+
* chosen: two folders may share a leaf name and both stay openable by id.
|
|
13
15
|
*
|
|
14
16
|
* The service is the decisions, and a host supplies the storage. That split is
|
|
15
17
|
* the point of this package: sasjs/server keeps the index in a JSON file beside
|
|
@@ -140,7 +142,34 @@ const nameOf = (value, appLoc) => {
|
|
|
140
142
|
return (0, exports.defaultAppName)(appLoc);
|
|
141
143
|
if (typeof value !== 'string' || value.trim() === '')
|
|
142
144
|
throw new types_js_1.ApiError(400, '"name" must be a non-empty string');
|
|
143
|
-
return value.trim();
|
|
145
|
+
return urlSafeName(value.trim());
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* A stated name is a URL segment, so it has to be spellable in one.
|
|
149
|
+
*
|
|
150
|
+
* `/app/<name>` resolves an app by its name when exactly one holds it, which
|
|
151
|
+
* makes the name an address and not only a label. A name carrying a space, a
|
|
152
|
+
* `#`, a `?` or a `/` is either unopenable or forced through percent-encoding -
|
|
153
|
+
* `/app/Macro%20Dash/` - and a name that collides with the surface's own paths
|
|
154
|
+
* (`apps.json`, the landing page's `index.html`) can never be opened by name at
|
|
155
|
+
* all, because those are answered before any app is looked up.
|
|
156
|
+
*
|
|
157
|
+
* Only a STATED name is held to this. A label derived from the folder stays as
|
|
158
|
+
* the folder spelled it, because a deployment that never chose a name did not
|
|
159
|
+
* choose an address either, and two folders sharing a leaf name are a fact of
|
|
160
|
+
* the drive rather than a naming decision.
|
|
161
|
+
*/
|
|
162
|
+
const NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._~-]*$/;
|
|
163
|
+
const NAME_MAX_LENGTH = 64;
|
|
164
|
+
const RESERVED_NAMES = ['apps.json', 'index.html'];
|
|
165
|
+
const urlSafeName = (name) => {
|
|
166
|
+
if (name.length > NAME_MAX_LENGTH)
|
|
167
|
+
throw new types_js_1.ApiError(400, `"name" must be at most ${NAME_MAX_LENGTH} characters, and "${name}" is ${name.length}.`);
|
|
168
|
+
if (!NAME_PATTERN.test(name))
|
|
169
|
+
throw new types_js_1.ApiError(400, `"name" must be usable as a URL segment - letters, digits, dot, dash, underscore or tilde, starting with a letter or digit - so "/app/${name}" can be opened. "${name}" is not, because it carries a character that has to be percent-encoded, or a space.`);
|
|
170
|
+
if (RESERVED_NAMES.includes(name.toLowerCase()))
|
|
171
|
+
throw new types_js_1.ApiError(400, `"name" cannot be "${name}": the App Stream answers /app/${name} itself, so an app with that name could never be opened by name.`);
|
|
172
|
+
return name;
|
|
144
173
|
};
|
|
145
174
|
const logoOf = (value) => {
|
|
146
175
|
if (value === undefined)
|
|
@@ -211,11 +240,25 @@ const createAppStreamService = (store) => {
|
|
|
211
240
|
const existing = entries.find((entry) => sameAppLoc(entry.appLoc, appLoc));
|
|
212
241
|
const logo = checked.logo;
|
|
213
242
|
const frameAncestors = checked.frameAncestors;
|
|
243
|
+
// A name this publish STATES is an address, so it is validated as a URL
|
|
244
|
+
// segment and has to be free. A name it inherits from the last publish,
|
|
245
|
+
// or one derived from the folder, is a label only: it was not chosen
|
|
246
|
+
// here, it may predate this rule, and two folders may share a leaf name.
|
|
247
|
+
const statedName = checked.name;
|
|
248
|
+
const name = statedName !== undefined
|
|
249
|
+
? nameOf(statedName, appLoc)
|
|
250
|
+
: (existing?.name ?? nameOf(undefined, appLoc));
|
|
251
|
+
if (statedName !== undefined) {
|
|
252
|
+
const clash = entries.find((candidate) => !sameAppLoc(candidate.appLoc, appLoc) &&
|
|
253
|
+
candidate.name.toLowerCase() === name.toLowerCase());
|
|
254
|
+
if (clash)
|
|
255
|
+
throw new types_js_1.ApiError(409, `The name "${name}" is already the address of the app published at ${clash.appLoc}. A stated name is how the app opens (/app/${name}), and two apps holding one name would answer an ambiguous lookup with nothing, so publish this one under a different name.`);
|
|
256
|
+
}
|
|
214
257
|
const entry = {
|
|
215
258
|
id: existing ? existing.id : (0, identity_js_1.newAppId)(),
|
|
216
259
|
// the label is the one field a redeploy inherits: everything else is
|
|
217
260
|
// what this publish states
|
|
218
|
-
name
|
|
261
|
+
name,
|
|
219
262
|
appLoc,
|
|
220
263
|
streamWebFolder,
|
|
221
264
|
...(logo === undefined ? {} : { logo }),
|
|
@@ -156,9 +156,13 @@ const createAppStreamWebService = (appStream, drive, options = {}) => {
|
|
|
156
156
|
].join(''));
|
|
157
157
|
};
|
|
158
158
|
/**
|
|
159
|
-
* The app a URL segment names: its id, or
|
|
160
|
-
*
|
|
161
|
-
*
|
|
159
|
+
* The app a URL segment names: its id, or its label when one app alone holds
|
|
160
|
+
* that label. The label is a real address, not a convenience - `/app/<name>`
|
|
161
|
+
* is the readable form of an app's URL - and the publish side keeps it usable
|
|
162
|
+
* by validating a stated name as a URL segment and refusing one another app
|
|
163
|
+
* holds. An ambiguous label still resolves to nothing, because a label derived
|
|
164
|
+
* from a folder has no uniqueness rule of its own, and guessing which of two
|
|
165
|
+
* same-named apps a URL meant is worse than a 404.
|
|
162
166
|
*/
|
|
163
167
|
const resolve = async (segment, allow) => {
|
|
164
168
|
const entries = await appStream.list(allow);
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.APP_CORPUS = void 0;
|
|
4
|
+
const runner_js_1 = require("./runner.js");
|
|
5
|
+
const SUBJECT = { userId: 'user-admin', clientId: 'web_app' };
|
|
6
|
+
/** Where the app's streamed entry file sits inside its folder. */
|
|
7
|
+
const ENTRY_FILE_PATH = `${runner_js_1.CORPUS_APP.appLoc}/services/${runner_js_1.CORPUS_APP.streamWebFolder}/index.html`;
|
|
8
|
+
exports.APP_CORPUS = [
|
|
9
|
+
{
|
|
10
|
+
id: 'app-detail-published',
|
|
11
|
+
route: 'GET /SASjsApi/app/{id}',
|
|
12
|
+
description: 'describes the app the id names, and the entry file it is served from',
|
|
13
|
+
// the deployment the index entry points at: the entry file is on the drive, so
|
|
14
|
+
// `entryFileExists` is the answer this case is really about
|
|
15
|
+
seed: { [ENTRY_FILE_PATH]: '<!doctype html><title>app</title>' },
|
|
16
|
+
request: { subject: SUBJECT, params: { id: runner_js_1.CORPUS_APP.id } },
|
|
17
|
+
expect: {
|
|
18
|
+
status: 200,
|
|
19
|
+
// the entry as registered, and the file it is served from. `lastModified` is
|
|
20
|
+
// the host's clock and not pinned: a drive with no clock answers `null`, one
|
|
21
|
+
// with a filesystem answers the time the seed was written.
|
|
22
|
+
partial: {
|
|
23
|
+
id: runner_js_1.CORPUS_APP.id,
|
|
24
|
+
name: runner_js_1.CORPUS_APP.name,
|
|
25
|
+
appLoc: runner_js_1.CORPUS_APP.appLoc,
|
|
26
|
+
streamWebFolder: runner_js_1.CORPUS_APP.streamWebFolder,
|
|
27
|
+
publishedAt: runner_js_1.CORPUS_APP.publishedAt,
|
|
28
|
+
entryFile: 'index.html',
|
|
29
|
+
entryFileExists: true,
|
|
30
|
+
url: `/app/${runner_js_1.CORPUS_APP.id}/`
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
id: 'app-detail-entry-file-missing',
|
|
36
|
+
route: 'GET /SASjsApi/app/{id}',
|
|
37
|
+
description: 'answers the entry as registered with no file and no date, for a deployment that is gone',
|
|
38
|
+
// the index entry outlived its folder: no seed, so nothing is deployed
|
|
39
|
+
request: { subject: SUBJECT, params: { id: runner_js_1.CORPUS_APP.id } },
|
|
40
|
+
expect: {
|
|
41
|
+
status: 200,
|
|
42
|
+
partial: { entryFileExists: false, lastModified: null }
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
id: 'app-detail-unknown-id',
|
|
47
|
+
route: 'GET /SASjsApi/app/{id}',
|
|
48
|
+
description: 'refuses an id the index does not hold, in the route’s own wording',
|
|
49
|
+
request: {
|
|
50
|
+
subject: SUBJECT,
|
|
51
|
+
params: { id: '9a9a9a9a-9a9a-4a9a-8a9a-9a9a9a9a9a9a' }
|
|
52
|
+
},
|
|
53
|
+
expect: { status: 404, error: 'No App Stream is registered with that id.' }
|
|
54
|
+
}
|
|
55
|
+
];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.runCase = exports.servicesFor = void 0;
|
|
3
|
+
exports.runCase = exports.servicesFor = exports.CORPUS_APP = void 0;
|
|
4
4
|
const dispatch_js_1 = require("../host/dispatch.js");
|
|
5
5
|
const service_js_1 = require("../drive/service.js");
|
|
6
6
|
const memory_store_js_1 = require("../drive/memory-store.js");
|
|
@@ -23,11 +23,12 @@ const memory_store_js_2 = require("../identity/memory-store.js");
|
|
|
23
23
|
const fixture_js_1 = require("../identity/fixture.js");
|
|
24
24
|
const types_js_1 = require("../types.js");
|
|
25
25
|
/**
|
|
26
|
-
* The app every case starts from: one published app, at the folder the
|
|
27
|
-
* cases name, so a removal has something to remove. Its id is stated
|
|
28
|
-
* minted, because a case that pins "the id that is there" cannot
|
|
26
|
+
* The app every app-stream case starts from: one published app, at the folder the
|
|
27
|
+
* unpublish cases name, so a removal has something to remove. Its id is stated
|
|
28
|
+
* rather than minted, because a case that pins "the id that is there" cannot
|
|
29
|
+
* invent one.
|
|
29
30
|
*/
|
|
30
|
-
|
|
31
|
+
exports.CORPUS_APP = {
|
|
31
32
|
id: '6f1c1c1e-6a1e-4c4a-9d1a-1b2c3d4e5f60',
|
|
32
33
|
name: 'myApp',
|
|
33
34
|
appLoc: '/Public/myApp',
|
|
@@ -69,7 +70,7 @@ const servicesFor = (testCase) => {
|
|
|
69
70
|
directory: (0, service_js_9.createDirectoryService)(identity, directory_js_1.CORPUS_DIRECTORY),
|
|
70
71
|
identity: (0, service_js_3.createIdentityService)(identity),
|
|
71
72
|
records: (0, records_js_1.createRecordService)(identity),
|
|
72
|
-
appStream: (0, service_js_2.createAppStreamService)(new service_js_2.MemoryAppStreamStore([CORPUS_APP])),
|
|
73
|
+
appStream: (0, service_js_2.createAppStreamService)(new service_js_2.MemoryAppStreamStore([exports.CORPUS_APP])),
|
|
73
74
|
session: (0, service_js_4.createSessionService)(identity, runner),
|
|
74
75
|
// no `runTimes` option: the default is the five the document names, so a
|
|
75
76
|
// case is never refused for a reason that belongs to one host's install
|
|
@@ -71,6 +71,20 @@ const validate = (route, request) => {
|
|
|
71
71
|
throw new types_js_1.ApiError(400, `"${param.name}" is not allowed to be empty`);
|
|
72
72
|
}
|
|
73
73
|
};
|
|
74
|
+
/** The file an app is served from for a directory request, as the surface serves it. */
|
|
75
|
+
const APP_ENTRY_FILE = 'index.html';
|
|
76
|
+
/**
|
|
77
|
+
* An app the index does not hold, in the wording the route answers with.
|
|
78
|
+
*
|
|
79
|
+
* The package's own message names the id ("No app is published with that id"); the
|
|
80
|
+
* route names the App Stream, and the corpus is what both hosts answer, so the
|
|
81
|
+
* wording is stated here rather than left to the service's.
|
|
82
|
+
*/
|
|
83
|
+
const APP_NOT_REGISTERED = 'No App Stream is registered with that id.';
|
|
84
|
+
const appNotRegistered = () => new types_js_1.ApiError(404, APP_NOT_REGISTERED, {
|
|
85
|
+
status: 'failure',
|
|
86
|
+
message: APP_NOT_REGISTERED
|
|
87
|
+
});
|
|
74
88
|
/** The drive path a write names: the query parameter wins over the form field. */
|
|
75
89
|
const targetPath = (request) => {
|
|
76
90
|
const fromQuery = request.query?._filePath;
|
|
@@ -357,6 +371,62 @@ const dispatch = async (services, routeId, request = {}) => {
|
|
|
357
371
|
body: { status: 'success', app: (0, service_js_1.appSummary)(removed) }
|
|
358
372
|
};
|
|
359
373
|
}
|
|
374
|
+
// --------------------------------------------------- what an app *is*
|
|
375
|
+
//
|
|
376
|
+
// The surface serves an app's files; this describes the app itself - the entry
|
|
377
|
+
// as registered, and whether the file it is served from is there. Addressed by id,
|
|
378
|
+
// which is what a publish answers with and what the app's URL carries: a label is
|
|
379
|
+
// shared by design, so "the app with this name" is not one app.
|
|
380
|
+
case 'GET /SASjsApi/app/{id}': {
|
|
381
|
+
if (!services.appStream)
|
|
382
|
+
throw new types_js_1.ApiError(501, `This host has no app stream, so it cannot answer ${routeId}.`);
|
|
383
|
+
const entry = await services.appStream
|
|
384
|
+
.get(String(params.id ?? ''))
|
|
385
|
+
.catch((err) => {
|
|
386
|
+
if ((0, types_js_1.isApiError)(err) && err.status === 404)
|
|
387
|
+
throw appNotRegistered();
|
|
388
|
+
throw err;
|
|
389
|
+
});
|
|
390
|
+
const folder = `${entry.appLoc}/services/${entry.streamWebFolder}`;
|
|
391
|
+
// An index entry can outlive its deployment - the folder deleted from under
|
|
392
|
+
// the host - and reporting a file and a date that are not there would be worse
|
|
393
|
+
// than reporting none, so the listing decides both.
|
|
394
|
+
let entryFileExists = false;
|
|
395
|
+
let lastModified = null;
|
|
396
|
+
try {
|
|
397
|
+
const { tree } = await drive.tree(folder);
|
|
398
|
+
const file = tree.children.find((child) => child.name === APP_ENTRY_FILE && !child.isFolder);
|
|
399
|
+
entryFileExists = file !== undefined;
|
|
400
|
+
lastModified = file?.modified ?? null;
|
|
401
|
+
}
|
|
402
|
+
catch (err) {
|
|
403
|
+
// A folder that is gone is the ordinary case - an index entry that outlived
|
|
404
|
+
// its deployment - and the answer is "no entry file". Anything else is not
|
|
405
|
+
// that answer: a `streamWebFolder` that names a file, or a store that failed,
|
|
406
|
+
// would read as a deleted deployment, so it reaches the host's 500.
|
|
407
|
+
if (!(0, types_js_1.isApiError)(err) || err.status !== 404)
|
|
408
|
+
throw err;
|
|
409
|
+
entryFileExists = false;
|
|
410
|
+
}
|
|
411
|
+
const body = {
|
|
412
|
+
id: entry.id,
|
|
413
|
+
name: entry.name,
|
|
414
|
+
appLoc: entry.appLoc,
|
|
415
|
+
streamWebFolder: entry.streamWebFolder,
|
|
416
|
+
publishedAt: entry.publishedAt ?? null,
|
|
417
|
+
entryFile: APP_ENTRY_FILE,
|
|
418
|
+
entryFileExists,
|
|
419
|
+
lastModified,
|
|
420
|
+
url: `/app/${entry.id}/`
|
|
421
|
+
};
|
|
422
|
+
// the two the index may not carry are absent rather than undefined, which is
|
|
423
|
+
// how they reach a JSON client
|
|
424
|
+
if (entry.logo !== undefined)
|
|
425
|
+
body.logo = entry.logo;
|
|
426
|
+
if (entry.frameAncestors !== undefined)
|
|
427
|
+
body.frameAncestors = entry.frameAncestors;
|
|
428
|
+
return { status: 200, body };
|
|
429
|
+
}
|
|
360
430
|
case 'GET /SASjsApi/drive/filetree':
|
|
361
431
|
return { status: 200, body: await drive.tree(query._folderPath) };
|
|
362
432
|
// ------------------------------------------------------------- run times
|
|
@@ -668,6 +738,7 @@ exports.HANDLED_ROUTES = [
|
|
|
668
738
|
'DELETE /SASjsApi/drive/folder',
|
|
669
739
|
'POST /SASjsApi/drive/rename',
|
|
670
740
|
'GET /SASjsApi/drive/filetree',
|
|
741
|
+
'GET /SASjsApi/app/{id}',
|
|
671
742
|
'POST /SASjsApi/drive/deploy',
|
|
672
743
|
'POST /SASjsApi/auth/token',
|
|
673
744
|
'POST /SASjsApi/auth/refresh',
|
package/build/cjs/index.js
CHANGED
|
@@ -15,7 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
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 = 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.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.normaliseAppLoc = exports.newAppId = exports.isAppId = exports.escapeHtml = exports.createAppStreamWebService = exports.contentTypeFor = exports.cacheControlFor = exports.NO_SUCH_APP = exports.DEFAULT_APP_PATH = exports.createDriveAppStreamStore = exports.APP_STREAM_INDEX = exports.splitAppBundle = exports.publishRequestFor = exports.parseAppManifest = exports.APP_MANIFEST = exports.MemoryAppStreamStore = exports.defaultAppName = exports.createAppStreamService = exports.checkPublishRequest = exports.appSummary = exports.servicesFor = exports.runCase = exports.PROVIDER_MANAGED = exports.ADMIN_SIGNED_IN = exports.RECORD_CORPUS = exports.RUNTIME_CORPUS = exports.MemorySessionRunner = exports.
|
|
18
|
+
exports.normaliseAppLoc = exports.newAppId = exports.isAppId = exports.escapeHtml = exports.createAppStreamWebService = exports.contentTypeFor = exports.cacheControlFor = exports.NO_SUCH_APP = exports.DEFAULT_APP_PATH = exports.createDriveAppStreamStore = exports.APP_STREAM_INDEX = exports.splitAppBundle = exports.publishRequestFor = exports.parseAppManifest = exports.APP_MANIFEST = exports.MemoryAppStreamStore = exports.defaultAppName = exports.createAppStreamService = exports.checkPublishRequest = exports.appSummary = 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 = void 0;
|
|
19
19
|
/**
|
|
20
20
|
* `@sasjs/api` - the SASjs Server API described once.
|
|
21
21
|
*
|
|
@@ -114,6 +114,8 @@ var identity_js_1 = require("./corpus/identity.js");
|
|
|
114
114
|
Object.defineProperty(exports, "IDENTITY_CORPUS", { enumerable: true, get: function () { return identity_js_1.IDENTITY_CORPUS; } });
|
|
115
115
|
var deploy_js_2 = require("./corpus/deploy.js");
|
|
116
116
|
Object.defineProperty(exports, "DEPLOY_CORPUS", { enumerable: true, get: function () { return deploy_js_2.DEPLOY_CORPUS; } });
|
|
117
|
+
var app_js_1 = require("./corpus/app.js");
|
|
118
|
+
Object.defineProperty(exports, "APP_CORPUS", { enumerable: true, get: function () { return app_js_1.APP_CORPUS; } });
|
|
117
119
|
var session_js_1 = require("./corpus/session.js");
|
|
118
120
|
Object.defineProperty(exports, "SESSION_CORPUS", { enumerable: true, get: function () { return session_js_1.SESSION_CORPUS; } });
|
|
119
121
|
var service_js_8 = require("./session/service.js");
|
|
@@ -123,8 +125,13 @@ Object.defineProperty(exports, "DEFAULT_SESSIONS", { enumerable: true, get: func
|
|
|
123
125
|
Object.defineProperty(exports, "MemorySessionHost", { enumerable: true, get: function () { return memory_host_js_1.MemorySessionHost; } });
|
|
124
126
|
var service_js_9 = require("./runtime/service.js");
|
|
125
127
|
Object.defineProperty(exports, "CODE_DEBUG", { enumerable: true, get: function () { return service_js_9.CODE_DEBUG; } });
|
|
126
|
-
Object.defineProperty(exports, "DOCUMENTED_RUN_TIMES", { enumerable: true, get: function () { return service_js_9.DOCUMENTED_RUN_TIMES; } });
|
|
127
128
|
Object.defineProperty(exports, "createRuntimeService", { enumerable: true, get: function () { return service_js_9.createRuntimeService; } });
|
|
129
|
+
var runTimes_js_1 = require("./runtime/runTimes.js");
|
|
130
|
+
Object.defineProperty(exports, "DOCUMENTED_RUN_TIMES", { enumerable: true, get: function () { return runTimes_js_1.DOCUMENTED_RUN_TIMES; } });
|
|
131
|
+
var program_js_1 = require("./runtime/program.js");
|
|
132
|
+
Object.defineProperty(exports, "programNotFound", { enumerable: true, get: function () { return program_js_1.programNotFound; } });
|
|
133
|
+
Object.defineProperty(exports, "resolveProgram", { enumerable: true, get: function () { return program_js_1.resolveProgram; } });
|
|
134
|
+
Object.defineProperty(exports, "runTimeOfPath", { enumerable: true, get: function () { return program_js_1.runTimeOfPath; } });
|
|
128
135
|
var memory_runner_js_1 = require("./runtime/memory-runner.js");
|
|
129
136
|
Object.defineProperty(exports, "MemorySessionRunner", { enumerable: true, get: function () { return memory_runner_js_1.MemorySessionRunner; } });
|
|
130
137
|
var runtime_js_1 = require("./corpus/runtime.js");
|
|
@@ -107,6 +107,40 @@ exports.GENERATED_ROUTES = [
|
|
|
107
107
|
}
|
|
108
108
|
]
|
|
109
109
|
},
|
|
110
|
+
{
|
|
111
|
+
id: 'GET /SASjsApi/app/{id}',
|
|
112
|
+
method: 'GET',
|
|
113
|
+
path: '/SASjsApi/app/{id}',
|
|
114
|
+
tag: 'App Stream',
|
|
115
|
+
summary: 'Get a published app by id',
|
|
116
|
+
params: [
|
|
117
|
+
{
|
|
118
|
+
name: 'id',
|
|
119
|
+
in: 'path',
|
|
120
|
+
required: true,
|
|
121
|
+
type: 'string'
|
|
122
|
+
}
|
|
123
|
+
],
|
|
124
|
+
requestBodies: [],
|
|
125
|
+
responses: [
|
|
126
|
+
{
|
|
127
|
+
status: 200,
|
|
128
|
+
description: 'Ok'
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
status: 401,
|
|
132
|
+
description: 'Unauthorized'
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
status: 404,
|
|
136
|
+
description: 'No App Stream is registered with that id.'
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
status: 500,
|
|
140
|
+
description: 'Internal Server Error'
|
|
141
|
+
}
|
|
142
|
+
]
|
|
143
|
+
},
|
|
110
144
|
{
|
|
111
145
|
id: 'POST /SASjsApi/auth/logout',
|
|
112
146
|
method: 'POST',
|
|
@@ -16,7 +16,9 @@ exports.TAG_CAPABILITIES = {
|
|
|
16
16
|
Group: ['identity'],
|
|
17
17
|
Permission: ['identity'],
|
|
18
18
|
Client: ['identity'],
|
|
19
|
-
Web: ['identity']
|
|
19
|
+
Web: ['identity'],
|
|
20
|
+
// an app's entry is indexed, and the file it is served from is read off the drive
|
|
21
|
+
'App Stream': ['storage']
|
|
20
22
|
};
|
|
21
23
|
/**
|
|
22
24
|
* Why a block of operations is not implemented here.
|
|
@@ -254,6 +256,37 @@ exports.OVERLAY = {
|
|
|
254
256
|
// `404` is an id the index does not hold - the id is the app, and its label and
|
|
255
257
|
// folder are not handles - and the drive's content is deliberately left alone.
|
|
256
258
|
'DELETE /SASjsApi/drive/deploy': { implemented: true },
|
|
259
|
+
// App Stream - what is published under one app's id.
|
|
260
|
+
//
|
|
261
|
+
// Carried here: the answer is the app index plus the drive, and `APP_CORPUS` pins
|
|
262
|
+
// its shape. The mock build (`sasjs/cli`) still answers the App Stream surface by
|
|
263
|
+
// hand; consuming this operation from the table is its next step on
|
|
264
|
+
// sasjs/cli#1550, not this package's.
|
|
265
|
+
'GET /SASjsApi/app/{id}': {
|
|
266
|
+
implemented: true,
|
|
267
|
+
// the caller's token is the host's middleware, and a failure that is not the
|
|
268
|
+
// index refusing the id - a drive read that broke - is the host's to answer
|
|
269
|
+
hostResponses: [401, 500],
|
|
270
|
+
// the shape a client reads: the entry as registered, the file it is served from,
|
|
271
|
+
// and whether that file is there
|
|
272
|
+
responses: {
|
|
273
|
+
404: {
|
|
274
|
+
status: 'failure',
|
|
275
|
+
message: 'No App Stream is registered with that id.'
|
|
276
|
+
},
|
|
277
|
+
200: {
|
|
278
|
+
id: '',
|
|
279
|
+
name: '',
|
|
280
|
+
appLoc: '',
|
|
281
|
+
streamWebFolder: '',
|
|
282
|
+
publishedAt: null,
|
|
283
|
+
entryFile: 'index.html',
|
|
284
|
+
entryFileExists: false,
|
|
285
|
+
lastModified: null,
|
|
286
|
+
url: ''
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
},
|
|
257
290
|
// Group - members and the groups themselves
|
|
258
291
|
'GET /SASjsApi/group': { implemented: true },
|
|
259
292
|
'GET /SASjsApi/group/{uid}': { implemented: true },
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveProgram = exports.runTimeOfPath = exports.programNotFound = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Finding the program a request names, once, for every host.
|
|
6
|
+
*
|
|
7
|
+
* `_program` is a path the caller chose, so two things have to be decided the same
|
|
8
|
+
* way in every host that runs one: that the path stays inside the drive, and which
|
|
9
|
+
* file and run time it actually names. The first is the host's - only it knows where
|
|
10
|
+
* its drive starts - and the second is this module's, because "try the extension the
|
|
11
|
+
* name states, otherwise `<path>.<runTime>` for each runtime in turn, otherwise the
|
|
12
|
+
* program does not exist" is the API's rule and not a host's preference.
|
|
13
|
+
*
|
|
14
|
+
* The host supplies three things: how to resolve a caller's path against its drive
|
|
15
|
+
* (answering `null` for a path that leaves it), whether a resolved path exists, and
|
|
16
|
+
* the run times it can offer. The extension vocabulary is not one of them - that is
|
|
17
|
+
* the document's, and `runTimeOfPath` reads it here. Nothing here touches a filesystem, a drive or a clock,
|
|
18
|
+
* so the browser host can answer with the same function over its own store.
|
|
19
|
+
*/
|
|
20
|
+
const types_js_1 = require("../types.js");
|
|
21
|
+
const runTimes_js_1 = require("./runTimes.js");
|
|
22
|
+
/**
|
|
23
|
+
* The detail a refusal carries, naming the path the caller gave.
|
|
24
|
+
*
|
|
25
|
+
* Exported because the runtime service renders the same condition the same way, and
|
|
26
|
+
* two copies of the sentence is how the two drift: the service's envelope states it as
|
|
27
|
+
* `error`, and this module states it as the message a host sends when it does not
|
|
28
|
+
* render an envelope at all.
|
|
29
|
+
*/
|
|
30
|
+
const programNotFound = (given) => `The Program at (${given}) does not exist.`;
|
|
31
|
+
exports.programNotFound = programNotFound;
|
|
32
|
+
/** The refusal, as this module decides it: the status and that detail. */
|
|
33
|
+
const notThere = (given) => new types_js_1.ApiError(400, (0, exports.programNotFound)(given));
|
|
34
|
+
/**
|
|
35
|
+
* The run time a path's own name states, if it states one.
|
|
36
|
+
*
|
|
37
|
+
* The vocabulary is the document's (`DOCUMENTED_RUN_TIMES`), not a host's: a host
|
|
38
|
+
* that cannot run Python still reads `run.py` as Python and answers separately that
|
|
39
|
+
* it has no such run time. `run.sas7bdat` and `run.backup` name none, and are then
|
|
40
|
+
* probed like a path with no extension at all - which is what the server has always
|
|
41
|
+
* done.
|
|
42
|
+
*
|
|
43
|
+
* The extension is read below either separator, because the server runs on Windows
|
|
44
|
+
* too and resolves its paths with backslashes.
|
|
45
|
+
*/
|
|
46
|
+
const runTimeOfPath = (path) => {
|
|
47
|
+
const file = path.split(/[\\/]/).pop() || '';
|
|
48
|
+
const dot = file.lastIndexOf('.');
|
|
49
|
+
// a leading dot names no extension: `.sas` is a file, not a suffix
|
|
50
|
+
const extension = dot > 0 ? file.slice(dot + 1).toLowerCase() : '';
|
|
51
|
+
return runTimes_js_1.DOCUMENTED_RUN_TIMES.includes(extension) ? extension : undefined;
|
|
52
|
+
};
|
|
53
|
+
exports.runTimeOfPath = runTimeOfPath;
|
|
54
|
+
/**
|
|
55
|
+
* The program and run time a request's `_program` names.
|
|
56
|
+
*
|
|
57
|
+
* The refusal is decided here - `400`, and the detail that names the path the caller
|
|
58
|
+
* gave - and *rendered* by whoever called this, because that is where the two hosts
|
|
59
|
+
* already differ: this package's runtime routes wrap it in the failed-run envelope
|
|
60
|
+
* (`{ status, message, error }`, pinned in `spec/runtime.spec.ts`), and a host that
|
|
61
|
+
* sends the message as text keeps sending it as text. Deciding the rendering here
|
|
62
|
+
* would change one host's answer on the way to unifying the rule, which is not what
|
|
63
|
+
* the seam is for.
|
|
64
|
+
*/
|
|
65
|
+
const resolveProgram = async (given, deps) => {
|
|
66
|
+
const resolved = deps.resolve(given);
|
|
67
|
+
if (resolved === null)
|
|
68
|
+
throw notThere(given);
|
|
69
|
+
const extension = (0, exports.runTimeOfPath)(resolved);
|
|
70
|
+
if (extension !== undefined) {
|
|
71
|
+
// the name states its run time: no probing, and a file that is not there is
|
|
72
|
+
// refused even if `<path>.sas` happens to exist
|
|
73
|
+
if (await deps.exists(resolved))
|
|
74
|
+
return { path: resolved, runTime: extension };
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
for (const runTime of deps.runTimes) {
|
|
78
|
+
const candidate = `${resolved}.${runTime}`;
|
|
79
|
+
if (await deps.exists(candidate))
|
|
80
|
+
return { path: candidate, runTime };
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
throw notThere(given);
|
|
84
|
+
};
|
|
85
|
+
exports.resolveProgram = resolveProgram;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DOCUMENTED_RUN_TIMES = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* The run times the published document states.
|
|
6
|
+
*
|
|
7
|
+
* The vocabulary is the document's, not a host's: `_program=/app/run.py` names
|
|
8
|
+
* Python wherever it is read, and a host that cannot run Python says so when it is
|
|
9
|
+
* asked to - it does not get to say the name means something else. Kept in its own
|
|
10
|
+
* module so the runtime service and `resolveProgram` read one list rather than two
|
|
11
|
+
* copies of it.
|
|
12
|
+
*/
|
|
13
|
+
exports.DOCUMENTED_RUN_TIMES = ['sas', 'js', 'py', 'r', 'sasviya'];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createRuntimeService = exports.parseDebugValue = exports.
|
|
3
|
+
exports.createRuntimeService = exports.parseDebugValue = exports.CODE_DEBUG = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* The runtime routes: running a program, and starting one.
|
|
6
6
|
*
|
|
@@ -19,6 +19,8 @@ exports.createRuntimeService = exports.parseDebugValue = exports.DOCUMENTED_RUN_
|
|
|
19
19
|
* that would carry one carries it as optional.
|
|
20
20
|
*/
|
|
21
21
|
const types_js_1 = require("../types.js");
|
|
22
|
+
const runTimes_js_1 = require("./runTimes.js");
|
|
23
|
+
const program_js_1 = require("./program.js");
|
|
22
24
|
const paths_js_1 = require("../drive/paths.js");
|
|
23
25
|
/**
|
|
24
26
|
* The value that asks for the session log.
|
|
@@ -36,8 +38,6 @@ const paths_js_1 = require("../drive/paths.js");
|
|
|
36
38
|
* else.
|
|
37
39
|
*/
|
|
38
40
|
exports.CODE_DEBUG = 131;
|
|
39
|
-
/** The run times the published document states, and a host may hold fewer. */
|
|
40
|
-
exports.DOCUMENTED_RUN_TIMES = ['sas', 'js', 'py', 'r', 'sasviya'];
|
|
41
41
|
/**
|
|
42
42
|
* `_debug`, normalised the way sasjs/server's `parseDebugValue` normalises it.
|
|
43
43
|
*
|
|
@@ -89,7 +89,9 @@ const timestamp = (now) => [
|
|
|
89
89
|
*/
|
|
90
90
|
const newSessionId = (now) => `${timestamp(now)}-${Math.round(Math.random() * 100000)}-${now.getTime()}`;
|
|
91
91
|
/** The refusal a program that cannot be found answers, as the server words it. */
|
|
92
|
-
|
|
92
|
+
// the wording is `resolveProgram`'s, so the module that decides the rule and the
|
|
93
|
+
// route that renders it cannot drift apart
|
|
94
|
+
const notThere = (programPath) => (0, program_js_1.programNotFound)(programPath);
|
|
93
95
|
/**
|
|
94
96
|
* The failure a run that could not be performed answers.
|
|
95
97
|
*
|
|
@@ -117,7 +119,7 @@ const failedRun = (error) => {
|
|
|
117
119
|
* the same directory the session routes read. A host never states a role.
|
|
118
120
|
*/
|
|
119
121
|
const createRuntimeService = (directory, runner, options = {}) => {
|
|
120
|
-
const runTimes = options.runTimes ||
|
|
122
|
+
const runTimes = options.runTimes || runTimes_js_1.DOCUMENTED_RUN_TIMES;
|
|
121
123
|
/** The caller, refused the way the middleware refuses one. */
|
|
122
124
|
const callerOf = async (caller) => {
|
|
123
125
|
if (!caller)
|
|
@@ -173,14 +175,10 @@ const createRuntimeService = (directory, runner, options = {}) => {
|
|
|
173
175
|
* Only the extension vocabulary the document states is read, so `run.sas7bdat`
|
|
174
176
|
* or `run.backup` name no run time and are left to the host.
|
|
175
177
|
*/
|
|
176
|
-
const runTimeForPath = (path, request) =>
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
if (exports.DOCUMENTED_RUN_TIMES.includes(extension))
|
|
181
|
-
return extension;
|
|
182
|
-
return runTimeOf(request);
|
|
183
|
-
};
|
|
178
|
+
const runTimeForPath = (path, request) =>
|
|
179
|
+
// the extension rule is `resolveProgram`'s; this asks it and falls back to what
|
|
180
|
+
// the request stated, which is the part that is this route's
|
|
181
|
+
(0, program_js_1.runTimeOfPath)(path) ?? runTimeOf(request);
|
|
184
182
|
/** The run time, refused when it is absent where the document requires it, or unheld. */
|
|
185
183
|
const runTimeOf = (request) => {
|
|
186
184
|
if (request.runTime === undefined) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/appstream/service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/appstream/service.ts"],"names":[],"mappings":"AA4BA,MAAM,WAAW,cAAc;IAC7B,oFAAoF;IACpF,EAAE,EAAE,MAAM,CAAA;IACV,uEAAuE;IACvE,IAAI,EAAE,MAAM,CAAA;IACZ,wEAAwE;IACxE,MAAM,EAAE,MAAM,CAAA;IACd,wEAAwE;IACxE,eAAe,EAAE,MAAM,CAAA;IACvB,8DAA8D;IAC9D,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,0EAA0E;IAC1E,cAAc,CAAC,EAAE,MAAM,EAAE,CAAA;IACzB,4CAA4C;IAC5C,WAAW,EAAE,MAAM,CAAA;CACpB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC,CAAA;IACjC,KAAK,CAAC,OAAO,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAChD;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAA;IACd,eAAe,EAAE,MAAM,CAAA;IACvB,2DAA2D;IAC3D,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IAClC,8EAA8E;IAC9E,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED,MAAM,WAAW,gBAAgB;IAC/B,gEAAgE;IAChE,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,OAAO,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CAAA;IAC3E,wEAAwE;IACxE,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;IACxC,mEAAmE;IACnE,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC,CAAA;IAC9D;;;;;;;;OAQG;IACH,OAAO,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;IAC5D,kEAAkE;IAClE,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAAA;CAC/C;AAED,0EAA0E;AAC1E,eAAO,MAAM,UAAU,GACrB,OAAO,cAAc,KACpB;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAIxC,CAAA;AAaF,gEAAgE;AAChE,eAAO,MAAM,cAAc,GAAI,QAAQ,MAAM,KAAG,MAI/C,CAAA;AA0BD,wEAAwE;AACxE,MAAM,WAAW,cAAe,SAAQ,IAAI,CAC1C,iBAAiB,EACjB,gBAAgB,CACjB;IACC,cAAc,CAAC,EAAE,MAAM,EAAE,CAAA;CAC1B;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,GAC1B,MAAM,OAAO,EACb,iBAAiB,MAAM,KACtB,OAsBF,CAAA;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,mBAAmB,GAC9B,SAAS,iBAAiB,EAC1B,OAAO,OAAO,EACd,UAAS;IAAE,kBAAkB,CAAC,EAAE,OAAO,CAAA;CAAO,KAC7C,cAsCF,CAAA;AA8ED;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,GACjC,OAAO,cAAc,KACpB,gBAwIF,CAAA;AAED,yFAAyF;AACzF,qBAAa,oBAAqB,YAAW,cAAc;IACzD,OAAO,CAAC,OAAO,CAAkB;gBAErB,OAAO,GAAE,cAAc,EAAO;IAIpC,IAAI,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;IAIjC,KAAK,CAAC,OAAO,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAGtD"}
|