@sasjs/api 0.18.1 → 0.20.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 (56) hide show
  1. package/build/browser.js +820 -29
  2. package/build/cjs/admin/service.js +209 -0
  3. package/build/cjs/authconfig/service.js +139 -0
  4. package/build/cjs/corpus/admin.js +101 -0
  5. package/build/cjs/corpus/authconfig.js +47 -0
  6. package/build/cjs/corpus/directory.js +31 -0
  7. package/build/cjs/corpus/home.js +51 -0
  8. package/build/cjs/corpus/runner.js +16 -0
  9. package/build/cjs/directory/service.js +116 -0
  10. package/build/cjs/home/service.js +103 -0
  11. package/build/cjs/host/dispatch.js +67 -8
  12. package/build/cjs/identity/memory-store.js +4 -1
  13. package/build/cjs/index.js +25 -12
  14. package/build/cjs/routes/generated.js +56 -0
  15. package/build/cjs/routes/overlay.js +97 -15
  16. package/build/esm/admin/service.d.ts +123 -0
  17. package/build/esm/admin/service.d.ts.map +1 -0
  18. package/build/esm/admin/service.js +201 -0
  19. package/build/esm/authconfig/service.d.ts +92 -0
  20. package/build/esm/authconfig/service.d.ts.map +1 -0
  21. package/build/esm/authconfig/service.js +134 -0
  22. package/build/esm/corpus/admin.d.ts +22 -0
  23. package/build/esm/corpus/admin.d.ts.map +1 -0
  24. package/build/esm/corpus/admin.js +98 -0
  25. package/build/esm/corpus/authconfig.d.ts +31 -0
  26. package/build/esm/corpus/authconfig.d.ts.map +1 -0
  27. package/build/esm/corpus/authconfig.js +44 -0
  28. package/build/esm/corpus/directory.d.ts +20 -0
  29. package/build/esm/corpus/directory.d.ts.map +1 -0
  30. package/build/esm/corpus/directory.js +28 -0
  31. package/build/esm/corpus/home.d.ts +27 -0
  32. package/build/esm/corpus/home.d.ts.map +1 -0
  33. package/build/esm/corpus/home.js +48 -0
  34. package/build/esm/corpus/runner.d.ts.map +1 -1
  35. package/build/esm/corpus/runner.js +16 -0
  36. package/build/esm/directory/service.d.ts +71 -0
  37. package/build/esm/directory/service.d.ts.map +1 -0
  38. package/build/esm/directory/service.js +112 -0
  39. package/build/esm/home/service.d.ts +69 -0
  40. package/build/esm/home/service.d.ts.map +1 -0
  41. package/build/esm/home/service.js +98 -0
  42. package/build/esm/host/dispatch.d.ts +37 -0
  43. package/build/esm/host/dispatch.d.ts.map +1 -1
  44. package/build/esm/host/dispatch.js +65 -7
  45. package/build/esm/identity/memory-store.d.ts.map +1 -1
  46. package/build/esm/identity/memory-store.js +4 -1
  47. package/build/esm/identity/types.d.ts +5 -0
  48. package/build/esm/identity/types.d.ts.map +1 -1
  49. package/build/esm/index.d.ts +6 -0
  50. package/build/esm/index.d.ts.map +1 -1
  51. package/build/esm/index.js +5 -0
  52. package/build/esm/routes/generated.d.ts.map +1 -1
  53. package/build/esm/routes/generated.js +56 -0
  54. package/build/esm/routes/overlay.d.ts.map +1 -1
  55. package/build/esm/routes/overlay.js +97 -15
  56. package/package.json +1 -1
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createDirectoryService = void 0;
4
+ const isNonEmptyString = (value) => typeof value === 'string' && value.length > 0;
5
+ /**
6
+ * The users, checked before anything is written.
7
+ *
8
+ * A duplicate or nameless entry is refused before the first write, so a bad
9
+ * directory answer cannot leave the store half-imported.
10
+ */
11
+ const usersOf = (users) => {
12
+ if (!Array.isArray(users))
13
+ throw new Error('The directory answer has no users array.');
14
+ const seen = new Set();
15
+ for (const user of users) {
16
+ if (!isNonEmptyString(user?.username) ||
17
+ !isNonEmptyString(user?.displayName))
18
+ throw new Error(`The directory answer carries a user without a username or displayName: ${JSON.stringify(user)}. Both are what the API keys an account on, so the import cannot guess them.`);
19
+ if (seen.has(user.username))
20
+ throw new Error(`The directory answer names ${user.username} twice. A directory that returns one account twice is a filter problem, and importing it would hide that.`);
21
+ seen.add(user.username);
22
+ }
23
+ return users;
24
+ };
25
+ const groupsOf = (groups) => {
26
+ if (!Array.isArray(groups))
27
+ throw new Error('The directory answer has no groups array.');
28
+ const seen = new Set();
29
+ for (const group of groups) {
30
+ if (!isNonEmptyString(group?.name))
31
+ throw new Error(`The directory answer carries a group without a name: ${JSON.stringify(group)}.`);
32
+ if (seen.has(group.name))
33
+ throw new Error(`The directory answer names the group ${group.name} twice, which would apply its members twice.`);
34
+ seen.add(group.name);
35
+ }
36
+ return groups;
37
+ };
38
+ /**
39
+ * The import, over the host's store.
40
+ *
41
+ * `IdentityStore` is the port rather than `RecordService`, because the records
42
+ * routes require a password (a local account has one to set) and a
43
+ * provider-managed account does not: the host's directory is where it
44
+ * authenticates, and `passwordMatches` answers for it.
45
+ */
46
+ const createDirectoryService = (store, source, options = {}) => {
47
+ const provider = options.provider || 'ldap';
48
+ return {
49
+ async synchronise() {
50
+ const directoryUsers = usersOf(await source.users());
51
+ const directoryGroups = groupsOf(await source.groups());
52
+ const existingUsers = await store.users();
53
+ const existingGroups = await store.groups();
54
+ const userByName = new Map(existingUsers.map((user) => [user.username, user]));
55
+ const groupByName = new Map(existingGroups.map((group) => [group.name, group]));
56
+ // ------------------------------------------------------------- users
57
+ const imported = [];
58
+ for (const user of directoryUsers) {
59
+ if (userByName.has(user.username))
60
+ continue;
61
+ const created = await store.createUser({
62
+ username: user.username,
63
+ displayName: user.displayName,
64
+ isAdmin: false,
65
+ isActive: true,
66
+ authProvider: provider
67
+ });
68
+ userByName.set(created.username, created);
69
+ imported.push(created);
70
+ }
71
+ // ------------------------------------------------------------ groups
72
+ const importedGroups = [];
73
+ for (const group of directoryGroups) {
74
+ if (groupByName.has(group.name))
75
+ continue;
76
+ const created = await store.createGroup({
77
+ name: group.name,
78
+ description: '',
79
+ isActive: true,
80
+ authProvider: provider
81
+ });
82
+ groupByName.set(created.name, created);
83
+ importedGroups.push(created);
84
+ }
85
+ // -------------------------------------------------------- membership
86
+ //
87
+ // Only the groups this call created are touched, so a second run is a
88
+ // no-op and an existing group keeps whatever its administrator set. The
89
+ // union of both directions: a group lists members, and a user lists the
90
+ // groups it belongs to.
91
+ const membersOf = new Map();
92
+ const note = (groupName, username) => {
93
+ const members = membersOf.get(groupName) || new Set();
94
+ members.add(username);
95
+ membersOf.set(groupName, members);
96
+ };
97
+ for (const group of directoryGroups)
98
+ for (const member of group.members || [])
99
+ note(group.name, member);
100
+ for (const user of directoryUsers)
101
+ for (const groupName of user.groups || [])
102
+ note(groupName, user.username);
103
+ for (const group of importedGroups)
104
+ for (const username of membersOf.get(group.name) || []) {
105
+ const user = userByName.get(username);
106
+ // a member the store does not know is not an error: the directory may
107
+ // hold accounts this API was never asked to import, and inventing them
108
+ // would be importing a user the directory did not name
109
+ if (user)
110
+ await store.addToGroup(group.uid, user.uid);
111
+ }
112
+ return { userCount: imported.length, groupCount: importedGroups.length };
113
+ }
114
+ };
115
+ };
116
+ exports.createDirectoryService = createDirectoryService;
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ /**
3
+ * The web interface's shell - the one page every host serves at `/`.
4
+ *
5
+ * The document states what the route is for: "Serves the web interface's
6
+ * `index.html`, with the current bundle version appended so a returning browser
7
+ * loads the updated bundle." That is the whole decision, and it is the same one
8
+ * on every host:
9
+ *
10
+ * - the SPA bundle has a fixed name (`index.bundle.js`), so a browser that
11
+ * keeps the previous build cached goes on rendering the previous interface
12
+ * after an update. A login screen once kept offering a password form the new
13
+ * server refused, and only a cache-disabled reload showed the new screen. The
14
+ * token is derived from the bundle's contents, so it changes with every build
15
+ * and is stable within one;
16
+ * - only an attribute naming the bundle is rewritten, so the same words in
17
+ * prose are left as prose;
18
+ * - a reference that already carries a query string is left alone, so applying
19
+ * this twice cannot produce a second `?v=`;
20
+ * - a host with no build answers a page saying so, rather than an error: a
21
+ * missing bundle costs a stale page at worst, and must never be the reason a
22
+ * deployment cannot render its own app.
23
+ *
24
+ * The host still reads the file and computes the digest - a hash of a megabyte
25
+ * bundle is the host's to make, and the package compiles with no node built-ins
26
+ * and no DOM `crypto`. What it cannot be left to each host is the rule that
27
+ * turns the two into the page, which is why it lives here.
28
+ */
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ exports.createHomeService = exports.withBundleVersion = exports.NO_WEB_BUILD = exports.BUNDLE_NAME = void 0;
31
+ /** The entry bundle the served page references. */
32
+ exports.BUNDLE_NAME = 'index.bundle.js';
33
+ /**
34
+ * What a host with no web build answers.
35
+ *
36
+ * A page rather than a `404`: the route is the interface, and an operator whose
37
+ * build did not land needs to see that from the browser rather than from a JSON
38
+ * error. The wording is sasjs/server's, so an adopting host changes nothing a
39
+ * user or a smoke test already reads.
40
+ */
41
+ exports.NO_WEB_BUILD = '<html><head></head><body>Web Build is not present</body></html>';
42
+ /** An attribute whose value names a file; quoted or not, both are valid. */
43
+ const FILE_ATTRIBUTE = /(\s(?:src|href)=)("[^"]*"|'[^']*'|[^\s>]+)/g;
44
+ /**
45
+ * A reference that names the bundle file itself.
46
+ *
47
+ * Anchored at the end (and at a path boundary) rather than `includes`, so an
48
+ * asset whose name merely begins with the bundle's - `index.bundle.js.css` - is
49
+ * left alone: it is a different file, and stamping it would suggest the token
50
+ * described something it did not.
51
+ */
52
+ const BUNDLE_REFERENCE = new RegExp(`(^|/)${exports.BUNDLE_NAME.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}$`);
53
+ /**
54
+ * The page with its bundle reference carrying that token.
55
+ *
56
+ * Only an attribute naming the bundle is rewritten. A reference that already
57
+ * carries a query string is left alone, so applying this twice is the same as
58
+ * applying it once.
59
+ */
60
+ const withBundleVersion = (html, version) => html.replace(FILE_ATTRIBUTE, (match, attribute, value) => {
61
+ const quote = value[0] === '"' || value[0] === "'" ? value[0] : '';
62
+ const target = quote ? value.slice(1, -1) : value;
63
+ if (!BUNDLE_REFERENCE.test(target) || target.includes('?'))
64
+ return match;
65
+ return `${attribute}${quote}${target}?v=${version}${quote}`;
66
+ });
67
+ exports.withBundleVersion = withBundleVersion;
68
+ const isNonEmptyString = (value) => typeof value === 'string' && value.length > 0;
69
+ /**
70
+ * The page, checked and stamped.
71
+ *
72
+ * A version is a query-string token: whitespace or a `?`/`#` would produce a URL
73
+ * that does not resolve, and a host that computed one from the wrong input would
74
+ * otherwise serve a broken reference rather than noticing.
75
+ */
76
+ const pageOf = (page) => {
77
+ if (!page || typeof page !== 'object')
78
+ throw new Error('The web page is not an object.');
79
+ if (!isNonEmptyString(page.html))
80
+ throw new Error('The web page states no html, so there is nothing to serve. Answer `undefined` from the port when the host has no build.');
81
+ // a token, not text: the value is written into a quoted attribute, so a
82
+ // quote closes it early and serves a broken reference - the failure this
83
+ // check exists to stop. A digest is `[0-9a-f]`, so the set below is strict
84
+ // enough to be safe and wide enough for any host's chosen encoding
85
+ if (!isNonEmptyString(page.version) ||
86
+ !/^[A-Za-z0-9._-]+$/.test(page.version))
87
+ throw new Error(`The web page states version as ${JSON.stringify(page.version)}; it is the bundle's cache token, so it may contain only letters, digits, ".", "_" and "-" - anything else, a quote above all, would end the attribute it is written into.`);
88
+ return (0, exports.withBundleVersion)(page.html, page.version);
89
+ };
90
+ /**
91
+ * The home service, over the host's own page.
92
+ *
93
+ * The port answers `undefined` when this host has no web build - a packaged
94
+ * server whose build folder is absent, a host that only answers the API - and
95
+ * the service answers the documented page rather than an error.
96
+ */
97
+ const createHomeService = (page) => ({
98
+ async home() {
99
+ const found = await page();
100
+ return found === undefined ? exports.NO_WEB_BUILD : pageOf(found);
101
+ }
102
+ });
103
+ exports.createHomeService = createHomeService;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HANDLED_ROUTES = exports.dispatch = void 0;
3
+ exports.HANDLED_ROUTES = exports.noHandler = exports.dispatch = void 0;
4
4
  const index_js_1 = require("../routes/index.js");
5
5
  const registry_js_1 = require("../drive/registry.js");
6
6
  const types_js_1 = require("../types.js");
@@ -187,6 +187,14 @@ const dispatch = async (services, routeId, request = {}) => {
187
187
  }
188
188
  }
189
189
  switch (routeId) {
190
+ // The shell is a body, not JSON: an HTML page served with the content type
191
+ // the document states, as it came from the host (stamped, if it references
192
+ // a bundle).
193
+ case 'GET /': {
194
+ if (!services.home)
195
+ throw new types_js_1.ApiError(501, `This host has no home service, so it cannot answer ${routeId}.`);
196
+ return { status: 200, contents: await services.home.home() };
197
+ }
190
198
  // The one answer a host states rather than derives: public, pre-auth, and
191
199
  // read by the login screen before anything else.
192
200
  case 'GET /SASjsApi/info': {
@@ -194,6 +202,40 @@ const dispatch = async (services, routeId, request = {}) => {
194
202
  throw new types_js_1.ApiError(501, `This host has no info service, so it cannot answer ${routeId}.`);
195
203
  return { status: 200, body: await services.info.info() };
196
204
  }
205
+ // ------------------------------------------------- a host's own reports
206
+ //
207
+ // The administrator middleware is the host's (sasjs/server mounts
208
+ // authenticateAccessToken and verifyAdmin ahead of all of these), which is
209
+ // why their 401 is marked host-only in the overlay. The package answers a
210
+ // body, and for a log tail the refusals that belong to the name rule.
211
+ case 'GET /SASjsApi/admin/diagnostics': {
212
+ if (!services.admin)
213
+ throw new types_js_1.ApiError(501, `This host has no admin service, so it cannot answer ${routeId}.`);
214
+ return { status: 200, body: await services.admin.diagnostics() };
215
+ }
216
+ case 'GET /SASjsApi/admin/logs': {
217
+ if (!services.admin)
218
+ throw new types_js_1.ApiError(501, `This host has no admin service, so it cannot answer ${routeId}.`);
219
+ return { status: 200, body: { files: await services.admin.logs() } };
220
+ }
221
+ case 'GET /SASjsApi/admin/logs/{fileName}': {
222
+ if (!services.admin)
223
+ throw new types_js_1.ApiError(501, `This host has no admin service, so it cannot answer ${routeId}.`);
224
+ return {
225
+ status: 200,
226
+ body: await services.admin.logTail(String(params.fileName ?? ''), query.lines)
227
+ };
228
+ }
229
+ case 'GET /SASjsApi/authConfig': {
230
+ if (!services.authConfig)
231
+ throw new types_js_1.ApiError(501, `This host has no auth-config service, so it cannot answer ${routeId}.`);
232
+ return { status: 200, body: await services.authConfig.authConfig() };
233
+ }
234
+ case 'POST /SASjsApi/authConfig/synchroniseWithLDAP': {
235
+ if (!services.directory)
236
+ throw new types_js_1.ApiError(501, `This host has no directory service, so it cannot answer ${routeId}.`);
237
+ return { status: 200, body: await services.directory.synchronise() };
238
+ }
197
239
  case 'GET /SASjsApi/drive/file': {
198
240
  const file = await drive.read(String(query._filePath || ''));
199
241
  return { status: 200, contents: file.contents };
@@ -505,19 +547,36 @@ const dispatch = async (services, routeId, request = {}) => {
505
547
  newPassword: String(body.newPassword ?? '')
506
548
  });
507
549
  return { status: 204 };
508
- default: {
509
- // The reason the table carries travels with the refusal: a host developer
510
- // reading a 501 wants to know what the operation waits on, not only that
511
- // it is missing.
512
- const reason = (0, index_js_1.routeById)(routeId)?.reason;
513
- throw new types_js_1.ApiError(501, `This package has no handler for ${routeId}.${reason ? ` ${reason}` : ''}`);
514
- }
550
+ default:
551
+ throw (0, exports.noHandler)(routeId);
515
552
  }
516
553
  };
517
554
  exports.dispatch = dispatch;
555
+ /**
556
+ * The refusal for an operation the table states and this file does not answer.
557
+ *
558
+ * Unreachable while every operation has a handler - `spec/routes.spec` asserts
559
+ * that the table's `implemented` set and `HANDLED_ROUTES` are the same list - but
560
+ * it is kept as the answer a future operation gets if it reaches the document
561
+ * before it reaches the dispatcher, rather than a promise that resolves
562
+ * `undefined`. The reason the table carries travels with it: a host developer
563
+ * reading a 501 wants to know what the operation waits on, not only that it is
564
+ * missing.
565
+ */
566
+ const noHandler = (routeId) => {
567
+ const reason = (0, index_js_1.routeById)(routeId)?.reason;
568
+ return new types_js_1.ApiError(501, `This package has no handler for ${routeId}.${reason ? ` ${reason}` : ''}`);
569
+ };
570
+ exports.noHandler = noHandler;
518
571
  /** Whether a route is one `dispatch` can answer today. */
519
572
  exports.HANDLED_ROUTES = [
573
+ 'GET /',
520
574
  'GET /SASjsApi/info',
575
+ 'GET /SASjsApi/admin/diagnostics',
576
+ 'GET /SASjsApi/admin/logs',
577
+ 'GET /SASjsApi/admin/logs/{fileName}',
578
+ 'GET /SASjsApi/authConfig',
579
+ 'POST /SASjsApi/authConfig/synchroniseWithLDAP',
521
580
  'POST /SASjsApi/drive/deploy/upload',
522
581
  'DELETE /SASjsApi/drive/deploy',
523
582
  'GET /SASjsApi/stp/execute',
@@ -310,7 +310,10 @@ class MemoryIdentityStore {
310
310
  name: input.name,
311
311
  description: input.description,
312
312
  isActive: input.isActive,
313
- users: []
313
+ users: [],
314
+ ...(input.authProvider === undefined
315
+ ? {}
316
+ : { authProvider: input.authProvider })
314
317
  };
315
318
  this.groupList.set(group.uid, group);
316
319
  return group;
@@ -14,8 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- 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 = exports.DEFAULT_IDENTITY = exports.MemoryIdentityStore = exports.normaliseInfo = exports.createInfoService = exports.BROWSER_INFO = 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 = void 0;
17
+ 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 = exports.DEFAULT_IDENTITY = exports.MemoryIdentityStore = 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 = void 0;
19
19
  /**
20
20
  * `@sasjs/api` - the SASjs Server API described once.
21
21
  *
@@ -72,10 +72,23 @@ var code_js_1 = require("./corpus/code.js");
72
72
  Object.defineProperty(exports, "CODE_CORPUS", { enumerable: true, get: function () { return code_js_1.CODE_CORPUS; } });
73
73
  var info_js_1 = require("./corpus/info.js");
74
74
  Object.defineProperty(exports, "INFO_CORPUS", { enumerable: true, get: function () { return info_js_1.INFO_CORPUS; } });
75
- var service_js_3 = require("./info/service.js");
76
- Object.defineProperty(exports, "BROWSER_INFO", { enumerable: true, get: function () { return service_js_3.BROWSER_INFO; } });
77
- Object.defineProperty(exports, "createInfoService", { enumerable: true, get: function () { return service_js_3.createInfoService; } });
78
- Object.defineProperty(exports, "normaliseInfo", { enumerable: true, get: function () { return service_js_3.normaliseInfo; } });
75
+ var admin_js_1 = require("./corpus/admin.js");
76
+ Object.defineProperty(exports, "ADMIN_CORPUS", { enumerable: true, get: function () { return admin_js_1.ADMIN_CORPUS; } });
77
+ var authconfig_js_1 = require("./corpus/authconfig.js");
78
+ Object.defineProperty(exports, "AUTH_CONFIG_CORPUS", { enumerable: true, get: function () { return authconfig_js_1.AUTH_CONFIG_CORPUS; } });
79
+ var directory_js_1 = require("./corpus/directory.js");
80
+ Object.defineProperty(exports, "DIRECTORY_CORPUS", { enumerable: true, get: function () { return directory_js_1.DIRECTORY_CORPUS; } });
81
+ var home_js_1 = require("./corpus/home.js");
82
+ Object.defineProperty(exports, "HOME_CORPUS", { enumerable: true, get: function () { return home_js_1.HOME_CORPUS; } });
83
+ var service_js_3 = require("./home/service.js");
84
+ Object.defineProperty(exports, "BUNDLE_NAME", { enumerable: true, get: function () { return service_js_3.BUNDLE_NAME; } });
85
+ Object.defineProperty(exports, "NO_WEB_BUILD", { enumerable: true, get: function () { return service_js_3.NO_WEB_BUILD; } });
86
+ Object.defineProperty(exports, "createHomeService", { enumerable: true, get: function () { return service_js_3.createHomeService; } });
87
+ Object.defineProperty(exports, "withBundleVersion", { enumerable: true, get: function () { return service_js_3.withBundleVersion; } });
88
+ var service_js_4 = require("./info/service.js");
89
+ Object.defineProperty(exports, "BROWSER_INFO", { enumerable: true, get: function () { return service_js_4.BROWSER_INFO; } });
90
+ Object.defineProperty(exports, "createInfoService", { enumerable: true, get: function () { return service_js_4.createInfoService; } });
91
+ Object.defineProperty(exports, "normaliseInfo", { enumerable: true, get: function () { return service_js_4.normaliseInfo; } });
79
92
  var memory_store_js_2 = require("./identity/memory-store.js");
80
93
  Object.defineProperty(exports, "MemoryIdentityStore", { enumerable: true, get: function () { return memory_store_js_2.MemoryIdentityStore; } });
81
94
  var fixture_js_1 = require("./identity/fixture.js");
@@ -90,15 +103,15 @@ var deploy_js_2 = require("./corpus/deploy.js");
90
103
  Object.defineProperty(exports, "DEPLOY_CORPUS", { enumerable: true, get: function () { return deploy_js_2.DEPLOY_CORPUS; } });
91
104
  var session_js_1 = require("./corpus/session.js");
92
105
  Object.defineProperty(exports, "SESSION_CORPUS", { enumerable: true, get: function () { return session_js_1.SESSION_CORPUS; } });
93
- var service_js_4 = require("./session/service.js");
94
- Object.defineProperty(exports, "createSessionService", { enumerable: true, get: function () { return service_js_4.createSessionService; } });
106
+ var service_js_5 = require("./session/service.js");
107
+ Object.defineProperty(exports, "createSessionService", { enumerable: true, get: function () { return service_js_5.createSessionService; } });
95
108
  var memory_host_js_1 = require("./session/memory-host.js");
96
109
  Object.defineProperty(exports, "DEFAULT_SESSIONS", { enumerable: true, get: function () { return memory_host_js_1.DEFAULT_SESSIONS; } });
97
110
  Object.defineProperty(exports, "MemorySessionHost", { enumerable: true, get: function () { return memory_host_js_1.MemorySessionHost; } });
98
- var service_js_5 = require("./runtime/service.js");
99
- Object.defineProperty(exports, "CODE_DEBUG", { enumerable: true, get: function () { return service_js_5.CODE_DEBUG; } });
100
- Object.defineProperty(exports, "DOCUMENTED_RUN_TIMES", { enumerable: true, get: function () { return service_js_5.DOCUMENTED_RUN_TIMES; } });
101
- Object.defineProperty(exports, "createRuntimeService", { enumerable: true, get: function () { return service_js_5.createRuntimeService; } });
111
+ var service_js_6 = require("./runtime/service.js");
112
+ Object.defineProperty(exports, "CODE_DEBUG", { enumerable: true, get: function () { return service_js_6.CODE_DEBUG; } });
113
+ Object.defineProperty(exports, "DOCUMENTED_RUN_TIMES", { enumerable: true, get: function () { return service_js_6.DOCUMENTED_RUN_TIMES; } });
114
+ Object.defineProperty(exports, "createRuntimeService", { enumerable: true, get: function () { return service_js_6.createRuntimeService; } });
102
115
  var memory_runner_js_1 = require("./runtime/memory-runner.js");
103
116
  Object.defineProperty(exports, "MemorySessionRunner", { enumerable: true, get: function () { return memory_runner_js_1.MemorySessionRunner; } });
104
117
  var runtime_js_1 = require("./corpus/runtime.js");
@@ -29,6 +29,14 @@ exports.GENERATED_ROUTES = [
29
29
  {
30
30
  status: 200,
31
31
  description: 'Ok'
32
+ },
33
+ {
34
+ status: 401,
35
+ description: 'Unauthorized, or an administrator account is required. The mount point in routes/api/index.ts applies both checks before this handler runs.'
36
+ },
37
+ {
38
+ status: 500,
39
+ description: 'The diagnostics could not be read'
32
40
  }
33
41
  ]
34
42
  },
@@ -44,6 +52,14 @@ exports.GENERATED_ROUTES = [
44
52
  {
45
53
  status: 200,
46
54
  description: 'Ok'
55
+ },
56
+ {
57
+ status: 401,
58
+ description: 'Unauthorized, or an administrator account is required. The mount point in routes/api/index.ts applies both checks before this handler runs.'
59
+ },
60
+ {
61
+ status: 500,
62
+ description: 'The log folder could not be listed'
47
63
  }
48
64
  ]
49
65
  },
@@ -72,6 +88,22 @@ exports.GENERATED_ROUTES = [
72
88
  {
73
89
  status: 200,
74
90
  description: 'Ok'
91
+ },
92
+ {
93
+ status: 400,
94
+ description: 'Invalid log file name.'
95
+ },
96
+ {
97
+ status: 401,
98
+ description: 'Unauthorized, or an administrator account is required. The mount point in routes/api/index.ts applies both checks before this handler runs.'
99
+ },
100
+ {
101
+ status: 404,
102
+ description: 'Log file not found.'
103
+ },
104
+ {
105
+ status: 500,
106
+ description: 'The log file could not be read'
75
107
  }
76
108
  ]
77
109
  },
@@ -209,6 +241,18 @@ exports.GENERATED_ROUTES = [
209
241
  {
210
242
  status: 200,
211
243
  description: 'Ok'
244
+ },
245
+ {
246
+ status: 401,
247
+ description: 'Unauthorized, or an administrator account is required. The mount point in routes/api/index.ts applies both checks before this handler runs.'
248
+ },
249
+ {
250
+ status: 403,
251
+ description: 'Not Allowed while in Desktop Mode.'
252
+ },
253
+ {
254
+ status: 500,
255
+ description: 'The provider configuration could not be read'
212
256
  }
213
257
  ]
214
258
  },
@@ -224,6 +268,18 @@ exports.GENERATED_ROUTES = [
224
268
  {
225
269
  status: 200,
226
270
  description: 'Ok'
271
+ },
272
+ {
273
+ status: 401,
274
+ description: 'Unauthorized, or an administrator account is required. The mount point in routes/api/index.ts applies both checks before this handler runs.'
275
+ },
276
+ {
277
+ status: 403,
278
+ description: 'Not Allowed while in Desktop Mode.'
279
+ },
280
+ {
281
+ status: 500,
282
+ description: 'The directory could not be synchronised'
227
283
  }
228
284
  ]
229
285
  },
@@ -25,10 +25,6 @@ exports.TAG_CAPABILITIES = {
25
25
  * operation waits on, and thirty copies of the same sentence would say the same
26
26
  * thing thirty times.
27
27
  */
28
- const DIRECTORY = 'Synchronising with an external auth provider needs a directory port, which this package does not have: a host decides which directory it holds accounts in, and answers this itself.';
29
- const HOST_CONFIG = "The body is the host's own provider configuration - the directory URL, bind DN and which secrets are set - which a mock states for itself and this package cannot know.";
30
- const HOST_OWNED = "The host owns this report: it describes the host's own process and files, which a browser build has no equivalent of.";
31
- const WEB_BUNDLE = 'The host serves its own web bundle; there is no API decision here for this package to answer.';
32
28
  const success = { status: 'success' };
33
29
  const user = {
34
30
  uid: '',
@@ -38,8 +34,17 @@ const user = {
38
34
  needsToUpdatePassword: false
39
35
  };
40
36
  exports.OVERLAY = {
41
- // Web - the sign-in pages the identity service answers, and the bundle itself
42
- 'GET /': { implemented: false, reason: WEB_BUNDLE },
37
+ // Web - the sign-in pages the identity service answers, and the shell itself.
38
+ // The page is the host's file; the stamping rule that keeps a cached shell
39
+ // from pinning an old bundle is the package's.
40
+ 'GET /': {
41
+ implemented: true,
42
+ // public: the shell is what an unauthenticated browser asks for first
43
+ capabilities: [],
44
+ responses: {
45
+ 200: '<html><head></head><body>Web Build is not present</body></html>'
46
+ }
47
+ },
43
48
  'POST /SASLogon/login': {
44
49
  implemented: true,
45
50
  // The lockout and the provider failure are answered before the package is
@@ -56,12 +61,71 @@ exports.OVERLAY = {
56
61
  hostResponses: [500],
57
62
  responses: { 200: 'OK!' }
58
63
  },
59
- // Admin - the host's own process and files
60
- 'GET /SASjsApi/admin/diagnostics': { implemented: false, reason: HOST_OWNED },
61
- 'GET /SASjsApi/admin/logs': { implemented: false, reason: HOST_OWNED },
64
+ // Admin - the host's own process and files, over the reports it supplies.
65
+ // The administrator check is the host's mount point (sasjs/server puts
66
+ // authenticateAccessToken and verifyAdmin in front of all three), so its 401
67
+ // - and the 500 a genuine failure answers - are host-only statuses.
68
+ 'GET /SASjsApi/admin/diagnostics': {
69
+ implemented: true,
70
+ hostResponses: [401, 500],
71
+ responses: {
72
+ 200: {
73
+ build: { version: '', gitHash: '', buildDate: null },
74
+ server: {
75
+ mode: 'desktop',
76
+ uptimeSeconds: 0,
77
+ startedAt: '',
78
+ pid: 0,
79
+ nodeVersion: '',
80
+ platform: '',
81
+ arch: '',
82
+ cpuCount: 0,
83
+ cpuModel: '',
84
+ loadAverage: [],
85
+ runTimes: [],
86
+ sasjsRoot: ''
87
+ },
88
+ memory: {
89
+ rssBytes: 0,
90
+ heapTotalBytes: 0,
91
+ heapUsedBytes: 0,
92
+ externalBytes: 0,
93
+ systemTotalBytes: 0,
94
+ systemFreeBytes: 0
95
+ },
96
+ filesystem: null,
97
+ folders: [],
98
+ logs: {
99
+ folder: '',
100
+ fileCount: 0,
101
+ totalBytes: 0,
102
+ newestFile: null,
103
+ newestModified: null
104
+ }
105
+ }
106
+ }
107
+ },
108
+ 'GET /SASjsApi/admin/logs': {
109
+ implemented: true,
110
+ hostResponses: [401, 500],
111
+ responses: { 200: { files: [] } }
112
+ },
62
113
  'GET /SASjsApi/admin/logs/{fileName}': {
63
- implemented: false,
64
- reason: HOST_OWNED
114
+ implemented: true,
115
+ // 400 and 404 are the name rule's, and this package answers them before the
116
+ // host is asked for anything
117
+ hostResponses: [401, 500],
118
+ responses: {
119
+ 200: {
120
+ fileName: '',
121
+ lines: 0,
122
+ bytesRead: 0,
123
+ truncated: false,
124
+ content: ''
125
+ },
126
+ 400: 'Invalid log file name.',
127
+ 404: 'Log file not found.'
128
+ }
65
129
  },
66
130
  // Auth - the token flow, plus a password change the identity store cannot write
67
131
  'POST /SASjsApi/auth/token': {
@@ -79,11 +143,29 @@ exports.OVERLAY = {
79
143
  // has gone, which a host's store can see and this package cannot.
80
144
  hostResponses: [404]
81
145
  },
82
- // Auth Config - the providers a host was started with, and an LDAP import
83
- 'GET /SASjsApi/authConfig': { implemented: false, reason: HOST_CONFIG },
146
+ // Auth Config - the providers a host was started with, and an LDAP import.
147
+ // Both are administrator routes at the host's mount point, so 401 and the
148
+ // host's own 500 are host-only statuses; the package answers the body, and
149
+ // refuses a secret that a host tries to hand it.
150
+ 'GET /SASjsApi/authConfig': {
151
+ implemented: true,
152
+ hostResponses: [401, 403, 500],
153
+ responses: {
154
+ 200: {
155
+ ldap: {
156
+ LDAP_URL: '',
157
+ LDAP_BIND_DN: '',
158
+ LDAP_USERS_BASE_DN: '',
159
+ LDAP_GROUPS_BASE_DN: '',
160
+ LDAP_BIND_PASSWORD_SET: true
161
+ }
162
+ }
163
+ }
164
+ },
84
165
  'POST /SASjsApi/authConfig/synchroniseWithLDAP': {
85
- implemented: false,
86
- reason: DIRECTORY
166
+ implemented: true,
167
+ hostResponses: [401, 403, 500],
168
+ responses: { 200: { userCount: 0, groupCount: 0 } }
87
169
  },
88
170
  // Client - the OAuth clients the identity store already holds for sign-in
89
171
  'GET /SASjsApi/client': { implemented: true },