@sasjs/api 0.24.0 → 0.25.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.
Files changed (47) hide show
  1. package/README.md +10 -0
  2. package/build/browser.js +655 -93
  3. package/build/cjs/appstream/bundle.js +124 -0
  4. package/build/cjs/appstream/identity.js +69 -0
  5. package/build/cjs/appstream/service.js +226 -0
  6. package/build/cjs/appstream/store.js +69 -0
  7. package/build/cjs/appstream/web.js +248 -0
  8. package/build/cjs/corpus/deploy.js +83 -28
  9. package/build/cjs/corpus/runner.js +30 -18
  10. package/build/cjs/host/dispatch.js +38 -9
  11. package/build/cjs/index.js +25 -4
  12. package/build/cjs/routes/generated.js +2 -8
  13. package/build/cjs/routes/overlay.js +2 -2
  14. package/build/esm/appstream/bundle.d.ts +46 -0
  15. package/build/esm/appstream/bundle.d.ts.map +1 -0
  16. package/build/esm/appstream/bundle.js +118 -0
  17. package/build/esm/appstream/identity.d.ts +27 -0
  18. package/build/esm/appstream/identity.d.ts.map +1 -0
  19. package/build/esm/appstream/identity.js +63 -0
  20. package/build/esm/appstream/service.d.ts +96 -0
  21. package/build/esm/appstream/service.d.ts.map +1 -0
  22. package/build/esm/appstream/service.js +218 -0
  23. package/build/esm/appstream/store.d.ts +6 -0
  24. package/build/esm/appstream/store.d.ts.map +1 -0
  25. package/build/esm/appstream/store.js +65 -0
  26. package/build/esm/appstream/web.d.ts +74 -0
  27. package/build/esm/appstream/web.d.ts.map +1 -0
  28. package/build/esm/appstream/web.js +241 -0
  29. package/build/esm/corpus/deploy.d.ts +5 -5
  30. package/build/esm/corpus/deploy.d.ts.map +1 -1
  31. package/build/esm/corpus/deploy.js +83 -28
  32. package/build/esm/corpus/runner.d.ts.map +1 -1
  33. package/build/esm/corpus/runner.js +14 -2
  34. package/build/esm/host/dispatch.d.ts +5 -4
  35. package/build/esm/host/dispatch.d.ts.map +1 -1
  36. package/build/esm/host/dispatch.js +38 -9
  37. package/build/esm/index.d.ts +8 -2
  38. package/build/esm/index.d.ts.map +1 -1
  39. package/build/esm/index.js +5 -1
  40. package/build/esm/routes/generated.d.ts.map +1 -1
  41. package/build/esm/routes/generated.js +2 -8
  42. package/build/esm/routes/overlay.js +2 -2
  43. package/package.json +5 -4
  44. package/build/cjs/drive/registry.js +0 -38
  45. package/build/esm/drive/registry.d.ts +0 -52
  46. package/build/esm/drive/registry.d.ts.map +0 -1
  47. package/build/esm/drive/registry.js +0 -33
@@ -0,0 +1,248 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createAppStreamWebService = exports.cacheControlFor = exports.contentTypeFor = exports.escapeHtml = exports.NO_SUCH_APP = exports.DEFAULT_APP_PATH = void 0;
4
+ /**
5
+ * The app stream as a web surface: the listing, the landing page, the apps, and
6
+ * the removal of one - decided once for every host.
7
+ *
8
+ * This is not part of the REST API document, because it is not a JSON API: a
9
+ * browser opens these URLs, and an app's own files are served from them
10
+ * (`GET /app/<id>/main.js`). What the hosts must agree on is the part that was
11
+ * written twice before: what the listing says, what a missing app answers, how an
12
+ * asset is found inside a deployment, and what is cacheable. So it lives here,
13
+ * and a host mounts it:
14
+ *
15
+ * - sasjs/server mounts it behind its own authentication and permission rules,
16
+ * passing `allow` so a caller sees only the apps it holds a grant on;
17
+ * - the browser build answers it from the drive it already has, so a mock site
18
+ * publishes, lists and serves its apps exactly as the server does.
19
+ *
20
+ * The base path is `/app`. An app is addressed by its id - `/app/<id>/` - which is
21
+ * the whole reason the id is a UUID and not a label: two apps may share a name,
22
+ * and neither the URL nor the lookup has to care.
23
+ */
24
+ const types_js_1 = require("../types.js");
25
+ /** Where the surface lives unless a host mounts it elsewhere. */
26
+ exports.DEFAULT_APP_PATH = '/app';
27
+ /** The words a caller sees when there is nothing at the address it asked for. */
28
+ exports.NO_SUCH_APP = "There's no App Stream available here.";
29
+ const ESCAPES = {
30
+ '&': '&amp;',
31
+ '<': '&lt;',
32
+ '>': '&gt;',
33
+ '"': '&quot;',
34
+ "'": '&#39;'
35
+ };
36
+ /**
37
+ * Text made safe for an attribute or a text node.
38
+ *
39
+ * An app's name and folder are its author's strings, not ours: the previous
40
+ * implementation interpolated them straight into markup, so a folder named
41
+ * `"><script>` was a landing page that ran it.
42
+ */
43
+ const escapeHtml = (value) => value.replace(/[&<>"']/g, (character) => ESCAPES[character]);
44
+ exports.escapeHtml = escapeHtml;
45
+ const CONTENT_TYPES = {
46
+ html: 'text/html; charset=utf-8',
47
+ htm: 'text/html; charset=utf-8',
48
+ js: 'text/javascript; charset=utf-8',
49
+ mjs: 'text/javascript; charset=utf-8',
50
+ css: 'text/css; charset=utf-8',
51
+ json: 'application/json; charset=utf-8',
52
+ map: 'application/json; charset=utf-8',
53
+ txt: 'text/plain; charset=utf-8',
54
+ svg: 'image/svg+xml',
55
+ png: 'image/png',
56
+ jpg: 'image/jpeg',
57
+ jpeg: 'image/jpeg',
58
+ gif: 'image/gif',
59
+ webp: 'image/webp',
60
+ ico: 'image/x-icon',
61
+ woff: 'font/woff',
62
+ woff2: 'font/woff2',
63
+ ttf: 'font/ttf',
64
+ otf: 'font/otf',
65
+ wasm: 'application/wasm',
66
+ pdf: 'application/pdf',
67
+ zip: 'application/zip'
68
+ };
69
+ /** The type of a file, by extension; bytes when nothing names it. */
70
+ const contentTypeFor = (filePath) => {
71
+ const extension = filePath.slice(filePath.lastIndexOf('.') + 1).toLowerCase();
72
+ return CONTENT_TYPES[extension] ?? 'application/octet-stream';
73
+ };
74
+ exports.contentTypeFor = contentTypeFor;
75
+ /**
76
+ * Caching for an app's own build output.
77
+ *
78
+ * A bundle names its files after their contents (`main.<hash>.js`), so a hashed
79
+ * name is immutable - a deployment ships a new name, never a new body. Everything
80
+ * else, `index.html` above all, has to be revalidated, or a browser keeps opening
81
+ * the previous deployment's shell against the new bundle.
82
+ */
83
+ const cacheControlFor = (filePath) => /\.[0-9a-f]{8,}\.[A-Za-z0-9]+$/.test(filePath)
84
+ ? 'public, max-age=31536000, immutable'
85
+ : 'public, max-age=0, must-revalidate';
86
+ exports.cacheControlFor = cacheControlFor;
87
+ const html = (status, markup) => ({
88
+ status,
89
+ body: markup,
90
+ contentType: 'text/html; charset=utf-8'
91
+ });
92
+ const json = (status, body) => ({
93
+ status,
94
+ body: JSON.stringify(body),
95
+ contentType: 'application/json; charset=utf-8'
96
+ });
97
+ // our own words, not a caller's: no escaping, and a browser shows the same
98
+ // sentence the server has always answered with
99
+ const noSuchApp = () => html(404, `<!doctype html><html><body>${exports.NO_SUCH_APP}</body></html>`);
100
+ const methodNotAllowed = (allowed) => ({
101
+ status: 405,
102
+ body: JSON.stringify({ status: 'failure', message: `${allowed} only.` }),
103
+ contentType: 'application/json; charset=utf-8',
104
+ headers: { allow: allowed }
105
+ });
106
+ /** A path segment as the caller spelled it, or `undefined` when it cannot be read. */
107
+ const decoded = (segment) => {
108
+ try {
109
+ return decodeURIComponent(segment);
110
+ }
111
+ catch (_) {
112
+ return undefined;
113
+ }
114
+ };
115
+ const createAppStreamWebService = (appStream, drive, options = {}) => {
116
+ const base = (options.basePath ?? exports.DEFAULT_APP_PATH).replace(/\/+$/, '');
117
+ const title = options.title ?? 'SASjs App Stream';
118
+ const urlOf = (entry) => `${base}/${entry.id}/`;
119
+ const rowOf = (entry) => ({
120
+ id: entry.id,
121
+ name: entry.name,
122
+ appLoc: entry.appLoc,
123
+ logo: entry.logo === undefined ? null : `${urlOf(entry)}${entry.logo}`,
124
+ url: urlOf(entry),
125
+ publishedAt: entry.publishedAt ?? null
126
+ });
127
+ const apps = async (allow) => {
128
+ const entries = await appStream.list(allow);
129
+ return { apps: entries.map(rowOf) };
130
+ };
131
+ const landing = async (allow) => {
132
+ const { apps: rows } = await apps(allow);
133
+ const tiles = rows.length
134
+ ? `<ul class="apps">${rows
135
+ .map((row) => `<li><a href="${(0, exports.escapeHtml)(row.url)}">${(0, exports.escapeHtml)(row.name)}</a>` +
136
+ `<span class="loc">${(0, exports.escapeHtml)(row.appLoc)}</span></li>`)
137
+ .join('')}</ul>`
138
+ : '<p class="empty">No apps have been published yet.</p>';
139
+ return html(200, [
140
+ '<!doctype html><html lang="en"><head><meta charset="utf-8">',
141
+ '<meta name="viewport" content="width=device-width,initial-scale=1">',
142
+ `<title>${(0, exports.escapeHtml)(title)}</title>`,
143
+ '<style>',
144
+ 'body{font-family:system-ui,sans-serif;margin:2rem;color:#1f2430}',
145
+ 'h1{font-size:1.4rem}',
146
+ 'ul.apps{list-style:none;padding:0;display:grid;gap:.75rem;max-width:40rem}',
147
+ 'ul.apps li{display:flex;flex-direction:column;gap:.15rem;padding:.75rem 1rem;',
148
+ 'border:1px solid #d8dee9;border-radius:.5rem}',
149
+ 'ul.apps a{font-weight:600;text-decoration:none;color:#0b5cad}',
150
+ '.loc{font-size:.8rem;color:#5b6472;font-family:ui-monospace,monospace}',
151
+ '.empty{color:#5b6472}',
152
+ '</style></head><body>',
153
+ `<h1>${(0, exports.escapeHtml)(title)}</h1>`,
154
+ tiles,
155
+ '</body></html>'
156
+ ].join(''));
157
+ };
158
+ /**
159
+ * The app a URL segment names: its id, or - as a courtesy - its label when one
160
+ * app alone holds that label. An ambiguous label resolves to nothing, because
161
+ * guessing which of two same-named apps a URL meant is worse than a 404.
162
+ */
163
+ const resolve = async (segment, allow) => {
164
+ const entries = await appStream.list(allow);
165
+ const byId = entries.find((entry) => entry.id === segment);
166
+ if (byId)
167
+ return byId;
168
+ const byName = entries.filter((entry) => entry.name === segment);
169
+ return byName.length === 1 ? byName[0] : undefined;
170
+ };
171
+ const asset = async (entry, segments) => {
172
+ const parts = segments.map(decoded);
173
+ if (parts.some((part) => part === undefined))
174
+ return noSuchApp();
175
+ const relative = parts.join('/') || 'index.html';
176
+ try {
177
+ const file = await drive.read(`${entry.appLoc}/services/${entry.streamWebFolder}/${relative}`);
178
+ return {
179
+ status: 200,
180
+ body: file.contents,
181
+ contentType: (0, exports.contentTypeFor)(relative),
182
+ headers: { 'cache-control': (0, exports.cacheControlFor)(relative) }
183
+ };
184
+ }
185
+ catch (error) {
186
+ // a missing file, a path that climbs out of the folder and a folder named
187
+ // where a file belongs are one answer to a browser: nothing is here. A
188
+ // fault is not: reporting a drive that went away as a wrong URL would send
189
+ // the caller looking for a typo that is not there.
190
+ if (error instanceof types_js_1.ApiError &&
191
+ (error.status === 404 || error.status === 400))
192
+ return noSuchApp();
193
+ throw error;
194
+ }
195
+ };
196
+ return {
197
+ apps,
198
+ landing,
199
+ async request({ method, path, allow }) {
200
+ const clean = (path.split(/[?#]/)[0] || '/').replace(/\/{2,}/g, '/');
201
+ const relative = base === ''
202
+ ? clean
203
+ : clean === base
204
+ ? '/'
205
+ : clean.startsWith(`${base}/`)
206
+ ? clean.slice(base.length)
207
+ : null;
208
+ // a host mounted this at a path it does not own: not an app, not a 404
209
+ // about apps either, so it is the same "nothing here" a wrong name earns
210
+ if (relative === null)
211
+ return noSuchApp();
212
+ if (relative === '' || relative === '/' || relative === '/index.html') {
213
+ if (method !== 'GET')
214
+ return methodNotAllowed('GET');
215
+ return landing(allow);
216
+ }
217
+ if (relative === '/apps.json') {
218
+ if (method !== 'GET')
219
+ return methodNotAllowed('GET');
220
+ return json(200, await apps(allow));
221
+ }
222
+ const segments = relative.split('/').filter(Boolean);
223
+ const key = decoded(segments[0]);
224
+ if (key === undefined)
225
+ return noSuchApp();
226
+ if (method === 'DELETE') {
227
+ const entry = await resolve(key, allow);
228
+ // the id is what a removal names; a label is accepted only because it
229
+ // resolves to exactly one app
230
+ if (!entry)
231
+ return noSuchApp();
232
+ const removed = await appStream.unpublish(entry.id);
233
+ return json(200, { status: 'success', app: rowOf(removed) });
234
+ }
235
+ if (method !== 'GET')
236
+ return methodNotAllowed('GET, DELETE');
237
+ const entry = await resolve(key, allow);
238
+ if (!entry)
239
+ return noSuchApp();
240
+ // `/app/<id>` is a folder, and a folder's files resolve under a trailing
241
+ // slash: a relative URL in the page would otherwise resolve one level up
242
+ if (segments.length === 1 && !relative.endsWith('/'))
243
+ return { status: 301, location: urlOf(entry) };
244
+ return asset(entry, segments.slice(1));
245
+ }
246
+ };
247
+ };
248
+ exports.createAppStreamWebService = createAppStreamWebService;
@@ -12,46 +12,35 @@ exports.DEPLOY_CORPUS = [
12
12
  {
13
13
  id: 'deploy-unpublish',
14
14
  route: 'DELETE /SASjsApi/drive/deploy',
15
- description: 'removes a published app stream and answers the status',
15
+ description: 'removes the app the id names, and says what went',
16
16
  request: {
17
17
  subject: SUBJECT,
18
- body: { streamServiceName: 'myApp', appLoc: '/Public/myApp' }
18
+ body: { id: '6f1c1c1e-6a1e-4c4a-9d1a-1b2c3d4e5f60' }
19
19
  },
20
- expect: { status: 200, body: { status: 'success' } }
21
- },
22
- {
23
- id: 'deploy-unpublish-other-name',
24
- route: 'DELETE /SASjsApi/drive/deploy',
25
- description: 'removes the app by its folder when the name has been renamed',
26
- request: {
27
- subject: SUBJECT,
28
- body: { streamServiceName: 'renamed-app', appLoc: '/Public/myApp' }
29
- },
30
- expect: { status: 200, body: { status: 'success' } }
31
- },
32
- {
33
- id: 'deploy-unpublish-no-stream-name',
34
- route: 'DELETE /SASjsApi/drive/deploy',
35
- description: 'refuses a body that does not say which stream to remove',
36
- request: { subject: SUBJECT, body: { appLoc: '/Public/myApp' } },
37
- expect: { status: 400, error: '"streamServiceName" is required' }
20
+ expect: {
21
+ status: 200,
22
+ partial: {
23
+ status: 'success',
24
+ app: { id: '6f1c1c1e-6a1e-4c4a-9d1a-1b2c3d4e5f60', name: 'myApp' }
25
+ }
26
+ }
38
27
  },
39
28
  {
40
- id: 'deploy-unpublish-no-app-loc',
29
+ id: 'deploy-unpublish-no-id',
41
30
  route: 'DELETE /SASjsApi/drive/deploy',
42
- description: 'refuses a body that does not say which folder to remove',
43
- request: { subject: SUBJECT, body: { streamServiceName: 'myApp' } },
44
- expect: { status: 400, error: '"appLoc" is required' }
31
+ description: 'refuses a body that does not say which app to remove',
32
+ request: { subject: SUBJECT, body: {} },
33
+ expect: { status: 400, error: '"id" is required' }
45
34
  },
46
35
  {
47
- id: 'deploy-unpublish-unknown-folder',
36
+ id: 'deploy-unpublish-unknown-id',
48
37
  route: 'DELETE /SASjsApi/drive/deploy',
49
- description: 'answers 404 for a folder nothing is published at',
38
+ description: 'answers 404 for an id the index does not hold',
50
39
  request: {
51
40
  subject: SUBJECT,
52
- body: { streamServiceName: 'myApp', appLoc: '/Public/not-an-app' }
41
+ body: { id: '11111111-1111-4111-8111-111111111111' }
53
42
  },
54
- expect: { status: 404, error: 'No app is published at that folder.' }
43
+ expect: { status: 404, error: 'No app is published with that id.' }
55
44
  },
56
45
  // ------------------------------------------- the uploaded-archive route
57
46
  // The archive is expanded by the host, so what arrives here is the same tree
@@ -144,6 +133,72 @@ exports.DEPLOY_CORPUS = [
144
133
  error: 'The file tree exceeds the deploy limit: 10001 entries (maximum 10000).'
145
134
  }
146
135
  },
136
+ // ------------------------------------------- a bundle that is an app
137
+ // One deploy writes the tree and indexes the app, from the manifest at the
138
+ // root of the archive. The id is minted, so the case pins what can be pinned:
139
+ // the app exists, under the label the manifest states.
140
+ {
141
+ id: 'deploy-publishes-an-app',
142
+ route: 'POST /SASjsApi/drive/deploy',
143
+ description: 'indexes a bundle as an app from the manifest it carries, in one request',
144
+ request: {
145
+ subject: SUBJECT,
146
+ body: {
147
+ appLoc: '/Public/apps/mario',
148
+ fileTree: {
149
+ members: [
150
+ {
151
+ name: 'sasjs.app.json',
152
+ type: 'file',
153
+ code: JSON.stringify({
154
+ name: 'Mario',
155
+ streamWebFolder: 'web',
156
+ logo: 'logo.png'
157
+ })
158
+ },
159
+ {
160
+ name: 'services',
161
+ type: 'folder',
162
+ members: [
163
+ {
164
+ name: 'web',
165
+ type: 'folder',
166
+ members: [
167
+ { name: 'index.html', type: 'file', code: '<h1>Mario</h1>' }
168
+ ]
169
+ },
170
+ { name: 'run', type: 'service', code: '%put hi;' }
171
+ ]
172
+ }
173
+ ]
174
+ }
175
+ }
176
+ },
177
+ expect: {
178
+ status: 200,
179
+ partial: {
180
+ status: 'success',
181
+ app: { name: 'Mario' }
182
+ }
183
+ }
184
+ },
185
+ {
186
+ id: 'deploy-refuses-a-bad-manifest',
187
+ route: 'POST /SASjsApi/drive/deploy',
188
+ description: 'refuses a bundle whose manifest is not JSON',
189
+ request: {
190
+ subject: SUBJECT,
191
+ body: {
192
+ appLoc: '/Public/apps/bad-manifest',
193
+ fileTree: {
194
+ members: [{ name: 'sasjs.app.json', type: 'file', code: '{not json' }]
195
+ }
196
+ }
197
+ },
198
+ expect: {
199
+ status: 400
200
+ }
201
+ },
147
202
  {
148
203
  id: 'upload-refused-by-store',
149
204
  route: 'POST /SASjsApi/drive/deploy/upload',
@@ -4,24 +4,36 @@ exports.runCase = exports.servicesFor = 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");
7
- const registry_js_1 = require("../drive/registry.js");
8
- const service_js_2 = require("../identity/service.js");
7
+ const service_js_2 = require("../appstream/service.js");
8
+ const service_js_3 = require("../identity/service.js");
9
9
  const records_js_1 = require("../identity/records.js");
10
- const service_js_3 = require("../session/service.js");
11
- const service_js_4 = require("../runtime/service.js");
10
+ const service_js_4 = require("../session/service.js");
11
+ const service_js_5 = require("../runtime/service.js");
12
12
  const memory_runner_js_1 = require("../runtime/memory-runner.js");
13
- const service_js_5 = require("../info/service.js");
14
- const service_js_6 = require("../authconfig/service.js");
15
- const service_js_7 = require("../admin/service.js");
16
- const service_js_8 = require("../directory/service.js");
13
+ const service_js_6 = require("../info/service.js");
14
+ const service_js_7 = require("../authconfig/service.js");
15
+ const service_js_8 = require("../admin/service.js");
16
+ const service_js_9 = require("../directory/service.js");
17
17
  const authconfig_js_1 = require("./authconfig.js");
18
18
  const admin_js_1 = require("./admin.js");
19
19
  const directory_js_1 = require("./directory.js");
20
- const service_js_9 = require("../home/service.js");
20
+ const service_js_10 = require("../home/service.js");
21
21
  const home_js_1 = require("./home.js");
22
22
  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
+ /**
26
+ * The app every case starts from: one published app, at the folder the unpublish
27
+ * cases name, so a removal has something to remove. Its id is stated rather than
28
+ * minted, because a case that pins "the id that is there" cannot invent one.
29
+ */
30
+ const CORPUS_APP = {
31
+ id: '6f1c1c1e-6a1e-4c4a-9d1a-1b2c3d4e5f60',
32
+ name: 'myApp',
33
+ appLoc: '/Public/myApp',
34
+ streamWebFolder: 'web',
35
+ publishedAt: '2026-01-01T00:00:00.000Z'
36
+ };
25
37
  /**
26
38
  * Services over fresh stores, seeded with the case's files and identity.
27
39
  *
@@ -46,22 +58,22 @@ const servicesFor = (testCase) => {
46
58
  drive: (0, service_js_1.createDriveService)(testCase.unwritable
47
59
  ? new RefusingDriveStore(testCase.seed || {})
48
60
  : new memory_store_js_1.MemoryDriveStore(testCase.seed || {})),
49
- info: (0, service_js_5.createInfoService)(service_js_5.BROWSER_INFO),
50
- home: (0, service_js_9.createHomeService)(async () => home_js_1.CORPUS_WEB_PAGE),
51
- authConfig: (0, service_js_6.createAuthConfigService)(authconfig_js_1.CORPUS_AUTH_CONFIG),
52
- admin: (0, service_js_7.createAdminService)({
61
+ info: (0, service_js_6.createInfoService)(service_js_6.BROWSER_INFO),
62
+ home: (0, service_js_10.createHomeService)(async () => home_js_1.CORPUS_WEB_PAGE),
63
+ authConfig: (0, service_js_7.createAuthConfigService)(authconfig_js_1.CORPUS_AUTH_CONFIG),
64
+ admin: (0, service_js_8.createAdminService)({
53
65
  diagnostics: async () => admin_js_1.CORPUS_DIAGNOSTICS,
54
66
  logs: async () => [admin_js_1.CORPUS_LOG],
55
67
  logTail: async (fileName) => fileName === admin_js_1.CORPUS_LOG.name ? admin_js_1.CORPUS_LOG_TAIL : undefined
56
68
  }),
57
- directory: (0, service_js_8.createDirectoryService)(identity, directory_js_1.CORPUS_DIRECTORY),
58
- identity: (0, service_js_2.createIdentityService)(identity),
69
+ directory: (0, service_js_9.createDirectoryService)(identity, directory_js_1.CORPUS_DIRECTORY),
70
+ identity: (0, service_js_3.createIdentityService)(identity),
59
71
  records: (0, records_js_1.createRecordService)(identity),
60
- registry: new registry_js_1.MemoryAppStreamRegistry(),
61
- session: (0, service_js_3.createSessionService)(identity, runner),
72
+ appStream: (0, service_js_2.createAppStreamService)(new service_js_2.MemoryAppStreamStore([CORPUS_APP])),
73
+ session: (0, service_js_4.createSessionService)(identity, runner),
62
74
  // no `runTimes` option: the default is the five the document names, so a
63
75
  // case is never refused for a reason that belongs to one host's install
64
- runtime: (0, service_js_4.createRuntimeService)(identity, runner)
76
+ runtime: (0, service_js_5.createRuntimeService)(identity, runner)
65
77
  };
66
78
  };
67
79
  exports.servicesFor = servicesFor;
@@ -2,7 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HANDLED_ROUTES = exports.noHandler = exports.dispatch = void 0;
4
4
  const index_js_1 = require("../routes/index.js");
5
- const registry_js_1 = require("../drive/registry.js");
5
+ const service_js_1 = require("../appstream/service.js");
6
+ const bundle_js_1 = require("../appstream/bundle.js");
6
7
  const types_js_1 = require("../types.js");
7
8
  const deploy_js_1 = require("../drive/deploy.js");
8
9
  /** The defaults sasjs/server's Client schema applies to an omitted lifetime. */
@@ -23,6 +24,8 @@ const RUN_ROUTES = [
23
24
  'POST /SASjsApi/code/execute',
24
25
  'POST /SASjsApi/code/trigger'
25
26
  ];
27
+ /** A payload value, when the caller actually stated one. */
28
+ const given = (value) => typeof value === 'string' && value !== '' ? value : undefined;
26
29
  /**
27
30
  * The parameters the table marks required, checked before the handler runs.
28
31
  *
@@ -278,18 +281,44 @@ const dispatch = async (services, routeId, request = {}) => {
278
281
  // expansion, which is why the two share this path rather than reading bytes.
279
282
  case 'POST /SASjsApi/drive/deploy/upload':
280
283
  case 'POST /SASjsApi/drive/deploy': {
281
- // `streamWebFolder` is the host's: publishing an app stream is not a drive
282
- // operation, and a host that has no app stream ignores it.
283
- await drive.deploy(String(body.appLoc ?? ''), body.fileTree);
284
- return { status: 200, body: deploy_js_1.DEPLOY_SUCCESS };
284
+ // A bundle is one archive: the deployment and - when it carries one - the
285
+ // statement that this folder is an app. The manifest is metadata, so it is
286
+ // taken out of the tree before anything is written.
287
+ const bundle = (0, bundle_js_1.splitAppBundle)(body.fileTree);
288
+ const appLoc = String(body.appLoc ?? '');
289
+ const requested = services.appStream
290
+ ? (0, bundle_js_1.publishRequestFor)({
291
+ appLoc,
292
+ streamWebFolder: given(body.streamWebFolder),
293
+ streamServiceName: given(body.streamServiceName),
294
+ streamLogo: given(body.streamLogo)
295
+ }, bundle.manifest)
296
+ : undefined;
297
+ // the index's own checks run BEFORE the drive is written: a tree the index
298
+ // would refuse must not leave its files behind, which is what happened when
299
+ // the deploy came first - a request answered `400` had already deployed
300
+ const publish = requested === undefined ? undefined : (0, service_js_1.checkPublishRequest)(requested);
301
+ await drive.deploy(appLoc, bundle.tree);
302
+ // a deploy of something that is not an app writes files and says so; an app
303
+ // is indexed in the same request, so the two cannot disagree
304
+ if (publish === undefined || !services.appStream)
305
+ return { status: 200, body: deploy_js_1.DEPLOY_SUCCESS };
306
+ const entry = await services.appStream.publish(publish);
307
+ return {
308
+ status: 200,
309
+ body: { ...deploy_js_1.DEPLOY_SUCCESS, app: (0, service_js_1.appSummary)(entry) }
310
+ };
285
311
  }
286
- case 'DELETE /SASjsApi/drive/deploy':
287
- if (!services.registry)
288
- throw new types_js_1.ApiError(501, `This host has no app stream registry, so it cannot answer ${routeId}.`);
312
+ case 'DELETE /SASjsApi/drive/deploy': {
313
+ if (!services.appStream)
314
+ throw new types_js_1.ApiError(501, `This host has no app stream, so it cannot answer ${routeId}.`);
315
+ // the id is the app: a label is not unique and a folder is not a handle
316
+ const removed = await services.appStream.unpublish(String(body.id ?? ''));
289
317
  return {
290
318
  status: 200,
291
- body: await (0, registry_js_1.unpublishAppStream)(services.registry, body)
319
+ body: { status: 'success', app: (0, service_js_1.appSummary)(removed) }
292
320
  };
321
+ }
293
322
  case 'GET /SASjsApi/drive/filetree':
294
323
  return { status: 200, body: await drive.tree(query._folderPath) };
295
324
  // ------------------------------------------------------------- run times
@@ -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.servicesFor = exports.runCase = exports.PROVIDER_MANAGED = exports.ADMIN_SIGNED_IN = exports.RECORD_CORPUS = exports.unpublishAppStream = exports.MemoryAppStreamRegistry = exports.RUNTIME_CORPUS = exports.MemorySessionRunner = exports.createRuntimeService = exports.DOCUMENTED_RUN_TIMES = exports.CODE_DEBUG = exports.MemorySessionHost = exports.DEFAULT_SESSIONS = exports.createSessionService = exports.SESSION_CORPUS = exports.DEPLOY_CORPUS = exports.IDENTITY_CORPUS = exports.DRIVE_CORPUS = exports.parseIdentity = exports.IDENTITY_FORMAT = 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.appSummary = exports.servicesFor = exports.runCase = exports.PROVIDER_MANAGED = exports.ADMIN_SIGNED_IN = exports.RECORD_CORPUS = exports.RUNTIME_CORPUS = exports.MemorySessionRunner = exports.createRuntimeService = exports.DOCUMENTED_RUN_TIMES = exports.CODE_DEBUG = exports.MemorySessionHost = exports.DEFAULT_SESSIONS = exports.createSessionService = exports.SESSION_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
  *
@@ -129,9 +129,6 @@ var memory_runner_js_1 = require("./runtime/memory-runner.js");
129
129
  Object.defineProperty(exports, "MemorySessionRunner", { enumerable: true, get: function () { return memory_runner_js_1.MemorySessionRunner; } });
130
130
  var runtime_js_1 = require("./corpus/runtime.js");
131
131
  Object.defineProperty(exports, "RUNTIME_CORPUS", { enumerable: true, get: function () { return runtime_js_1.RUNTIME_CORPUS; } });
132
- var registry_js_1 = require("./drive/registry.js");
133
- Object.defineProperty(exports, "MemoryAppStreamRegistry", { enumerable: true, get: function () { return registry_js_1.MemoryAppStreamRegistry; } });
134
- Object.defineProperty(exports, "unpublishAppStream", { enumerable: true, get: function () { return registry_js_1.unpublishAppStream; } });
135
132
  var records_js_2 = require("./corpus/records.js");
136
133
  Object.defineProperty(exports, "RECORD_CORPUS", { enumerable: true, get: function () { return records_js_2.RECORD_CORPUS; } });
137
134
  Object.defineProperty(exports, "ADMIN_SIGNED_IN", { enumerable: true, get: function () { return records_js_2.ADMIN_SIGNED_IN; } });
@@ -139,3 +136,27 @@ Object.defineProperty(exports, "PROVIDER_MANAGED", { enumerable: true, get: func
139
136
  var runner_js_1 = require("./corpus/runner.js");
140
137
  Object.defineProperty(exports, "runCase", { enumerable: true, get: function () { return runner_js_1.runCase; } });
141
138
  Object.defineProperty(exports, "servicesFor", { enumerable: true, get: function () { return runner_js_1.servicesFor; } });
139
+ var service_js_10 = require("./appstream/service.js");
140
+ Object.defineProperty(exports, "appSummary", { enumerable: true, get: function () { return service_js_10.appSummary; } });
141
+ Object.defineProperty(exports, "createAppStreamService", { enumerable: true, get: function () { return service_js_10.createAppStreamService; } });
142
+ Object.defineProperty(exports, "defaultAppName", { enumerable: true, get: function () { return service_js_10.defaultAppName; } });
143
+ Object.defineProperty(exports, "MemoryAppStreamStore", { enumerable: true, get: function () { return service_js_10.MemoryAppStreamStore; } });
144
+ var bundle_js_1 = require("./appstream/bundle.js");
145
+ Object.defineProperty(exports, "APP_MANIFEST", { enumerable: true, get: function () { return bundle_js_1.APP_MANIFEST; } });
146
+ Object.defineProperty(exports, "parseAppManifest", { enumerable: true, get: function () { return bundle_js_1.parseAppManifest; } });
147
+ Object.defineProperty(exports, "publishRequestFor", { enumerable: true, get: function () { return bundle_js_1.publishRequestFor; } });
148
+ Object.defineProperty(exports, "splitAppBundle", { enumerable: true, get: function () { return bundle_js_1.splitAppBundle; } });
149
+ var store_js_1 = require("./appstream/store.js");
150
+ Object.defineProperty(exports, "APP_STREAM_INDEX", { enumerable: true, get: function () { return store_js_1.APP_STREAM_INDEX; } });
151
+ Object.defineProperty(exports, "createDriveAppStreamStore", { enumerable: true, get: function () { return store_js_1.createDriveAppStreamStore; } });
152
+ var web_js_1 = require("./appstream/web.js");
153
+ Object.defineProperty(exports, "DEFAULT_APP_PATH", { enumerable: true, get: function () { return web_js_1.DEFAULT_APP_PATH; } });
154
+ Object.defineProperty(exports, "NO_SUCH_APP", { enumerable: true, get: function () { return web_js_1.NO_SUCH_APP; } });
155
+ Object.defineProperty(exports, "cacheControlFor", { enumerable: true, get: function () { return web_js_1.cacheControlFor; } });
156
+ Object.defineProperty(exports, "contentTypeFor", { enumerable: true, get: function () { return web_js_1.contentTypeFor; } });
157
+ Object.defineProperty(exports, "createAppStreamWebService", { enumerable: true, get: function () { return web_js_1.createAppStreamWebService; } });
158
+ Object.defineProperty(exports, "escapeHtml", { enumerable: true, get: function () { return web_js_1.escapeHtml; } });
159
+ var identity_js_2 = require("./appstream/identity.js");
160
+ Object.defineProperty(exports, "isAppId", { enumerable: true, get: function () { return identity_js_2.isAppId; } });
161
+ Object.defineProperty(exports, "newAppId", { enumerable: true, get: function () { return identity_js_2.newAppId; } });
162
+ Object.defineProperty(exports, "normaliseAppLoc", { enumerable: true, get: function () { return identity_js_2.normaliseAppLoc; } });
@@ -508,13 +508,7 @@ exports.GENERATED_ROUTES = [
508
508
  summary: 'Remove an app stream entry',
509
509
  params: [
510
510
  {
511
- name: 'appLoc',
512
- in: 'body',
513
- required: true,
514
- type: 'string'
515
- },
516
- {
517
- name: 'streamServiceName',
511
+ name: 'id',
518
512
  in: 'body',
519
513
  required: true,
520
514
  type: 'string'
@@ -532,7 +526,7 @@ exports.GENERATED_ROUTES = [
532
526
  },
533
527
  {
534
528
  status: 404,
535
- description: 'No app is published at that folder'
529
+ description: 'No app is published with that id'
536
530
  }
537
531
  ]
538
532
  },
@@ -251,8 +251,8 @@ exports.OVERLAY = {
251
251
  }
252
252
  },
253
253
  'POST /SASjsApi/drive/deploy/upload': { implemented: true },
254
- // `404` is a pair - the registry name and the appLoc it was published from -
255
- // that matches no entry, and the drive's content is deliberately left alone.
254
+ // `404` is an id the index does not hold - the id is the app, and its label and
255
+ // folder are not handles - and the drive's content is deliberately left alone.
256
256
  'DELETE /SASjsApi/drive/deploy': { implemented: true },
257
257
  // Group - members and the groups themselves
258
258
  'GET /SASjsApi/group': { implemented: true },