@sasjs/api 0.18.0 → 0.19.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 (52) hide show
  1. package/build/browser.js +717 -18
  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/runner.js +13 -0
  8. package/build/cjs/directory/service.js +116 -0
  9. package/build/cjs/host/dispatch.js +39 -0
  10. package/build/cjs/identity/memory-store.js +4 -1
  11. package/build/cjs/index.js +8 -2
  12. package/build/cjs/info/service.js +13 -8
  13. package/build/cjs/routes/generated.js +56 -0
  14. package/build/cjs/routes/overlay.js +86 -12
  15. package/build/esm/admin/service.d.ts +123 -0
  16. package/build/esm/admin/service.d.ts.map +1 -0
  17. package/build/esm/admin/service.js +201 -0
  18. package/build/esm/authconfig/service.d.ts +92 -0
  19. package/build/esm/authconfig/service.d.ts.map +1 -0
  20. package/build/esm/authconfig/service.js +134 -0
  21. package/build/esm/corpus/admin.d.ts +22 -0
  22. package/build/esm/corpus/admin.d.ts.map +1 -0
  23. package/build/esm/corpus/admin.js +98 -0
  24. package/build/esm/corpus/authconfig.d.ts +31 -0
  25. package/build/esm/corpus/authconfig.d.ts.map +1 -0
  26. package/build/esm/corpus/authconfig.js +44 -0
  27. package/build/esm/corpus/directory.d.ts +20 -0
  28. package/build/esm/corpus/directory.d.ts.map +1 -0
  29. package/build/esm/corpus/directory.js +28 -0
  30. package/build/esm/corpus/runner.d.ts.map +1 -1
  31. package/build/esm/corpus/runner.js +13 -0
  32. package/build/esm/directory/service.d.ts +71 -0
  33. package/build/esm/directory/service.d.ts.map +1 -0
  34. package/build/esm/directory/service.js +112 -0
  35. package/build/esm/host/dispatch.d.ts +18 -0
  36. package/build/esm/host/dispatch.d.ts.map +1 -1
  37. package/build/esm/host/dispatch.js +39 -0
  38. package/build/esm/identity/memory-store.d.ts.map +1 -1
  39. package/build/esm/identity/memory-store.js +4 -1
  40. package/build/esm/identity/types.d.ts +5 -0
  41. package/build/esm/identity/types.d.ts.map +1 -1
  42. package/build/esm/index.d.ts +3 -0
  43. package/build/esm/index.d.ts.map +1 -1
  44. package/build/esm/index.js +3 -0
  45. package/build/esm/info/service.d.ts +14 -6
  46. package/build/esm/info/service.d.ts.map +1 -1
  47. package/build/esm/info/service.js +12 -7
  48. package/build/esm/routes/generated.d.ts.map +1 -1
  49. package/build/esm/routes/generated.js +56 -0
  50. package/build/esm/routes/overlay.d.ts.map +1 -1
  51. package/build/esm/routes/overlay.js +86 -12
  52. package/package.json +1 -1
@@ -0,0 +1,201 @@
1
+ /**
2
+ * The three Admin reports: this host's own process, memory, disk and logs.
3
+ *
4
+ * The values are the host's - a pid, a folder walk, the tail of a file - and a
5
+ * browser build has no equivalent, so the reports are supplied through a port.
6
+ * What this file owns is everything a client keys on:
7
+ *
8
+ * - the body's shape, because a diagnostics page that reads
9
+ * `memory.rssBytes` renders `NaN` when a host omits it, and a report that is
10
+ * missing a field is a host bug rather than an empty reading;
11
+ * - the log file name rule: a bare name ending in `.log`, refused with `400`
12
+ * for anything that could resolve outside the log folder (`..`, a
13
+ * separator, an absolute path). The host resolves the name inside its own
14
+ * folder - this is the same rule sasjs/server applies before it touches the
15
+ * filesystem, and doing it here means both hosts refuse a traversal the same
16
+ * way;
17
+ * - `404` for a name that is not there, `200` with a bounded tail otherwise,
18
+ * and the line count clamped to the documented default and maximum so a
19
+ * caller cannot ask a host to read a gigabyte.
20
+ *
21
+ * `GET /admin/diagnostics`, `GET /admin/logs` and `GET /admin/logs/{fileName}`
22
+ * are mounted behind the host's own administrator middleware (sasjs/server puts
23
+ * `authenticateAccessToken` and `verifyAdmin` in front of all three), so the
24
+ * caller's right to read these is the host's decision and is marked
25
+ * `hostResponses` in the overlay.
26
+ */
27
+ import { ApiError } from '../types.js';
28
+ /** The documented defaults on the route's `lines` parameter. */
29
+ export const DEFAULT_LOG_LINES = 200;
30
+ export const MAX_LOG_LINES = 5000;
31
+ const isObject = (value) => !!value && typeof value === 'object' && !Array.isArray(value);
32
+ const isNumber = (value) => typeof value === 'number' && Number.isFinite(value);
33
+ const isString = (value) => typeof value === 'string';
34
+ const requireString = (holder, key, where) => {
35
+ if (!isString(holder[key]))
36
+ throw new Error(`The ${where} report states \`${key}\` as ${JSON.stringify(holder[key])}; the document states a string, and a client that renders it would print the value as it stands.`);
37
+ };
38
+ const requireNumber = (holder, key, where) => {
39
+ if (!isNumber(holder[key]))
40
+ throw new Error(`The ${where} report states \`${key}\` as ${JSON.stringify(holder[key])}; the document states a number, and a client that renders it would print NaN.`);
41
+ };
42
+ const requireObject = (holder, key, where) => {
43
+ const value = holder[key];
44
+ if (!isObject(value))
45
+ throw new Error(`The ${where} report states \`${key}\` as ${JSON.stringify(value)}; the document states an object.`);
46
+ return value;
47
+ };
48
+ /**
49
+ * The diagnostics body, checked field by field.
50
+ *
51
+ * A host that cannot read its filesystem states `filesystem: null`, which the
52
+ * document allows; a host that cannot read anything at all should refuse the
53
+ * request itself, because an empty object here renders as a page of zeroes.
54
+ */
55
+ export const normaliseDiagnostics = (report) => {
56
+ if (!isObject(report))
57
+ throw new Error('The diagnostics report is not an object.');
58
+ const build = requireObject(report, 'build', 'diagnostics');
59
+ requireString(build, 'version', 'diagnostics build');
60
+ requireString(build, 'gitHash', 'diagnostics build');
61
+ if (!(build.buildDate === null || isString(build.buildDate)))
62
+ throw new Error(`The diagnostics build states \`buildDate\` as ${JSON.stringify(build.buildDate)}; the document states an ISO timestamp or null.`);
63
+ const server = requireObject(report, 'server', 'diagnostics');
64
+ requireString(server, 'mode', 'diagnostics server');
65
+ requireString(server, 'startedAt', 'diagnostics server');
66
+ requireString(server, 'nodeVersion', 'diagnostics server');
67
+ requireString(server, 'platform', 'diagnostics server');
68
+ requireString(server, 'arch', 'diagnostics server');
69
+ requireString(server, 'cpuModel', 'diagnostics server');
70
+ requireString(server, 'sasjsRoot', 'diagnostics server');
71
+ requireNumber(server, 'uptimeSeconds', 'diagnostics server');
72
+ requireNumber(server, 'pid', 'diagnostics server');
73
+ requireNumber(server, 'cpuCount', 'diagnostics server');
74
+ if (!Array.isArray(server.loadAverage) || !server.loadAverage.every(isNumber))
75
+ throw new Error('The diagnostics server report states `loadAverage` as something other than an array of numbers.');
76
+ if (!Array.isArray(server.runTimes) || !server.runTimes.every(isString))
77
+ throw new Error('The diagnostics server report states `runTimes` as something other than an array of strings.');
78
+ const memory = requireObject(report, 'memory', 'diagnostics');
79
+ for (const key of [
80
+ 'rssBytes',
81
+ 'heapTotalBytes',
82
+ 'heapUsedBytes',
83
+ 'externalBytes',
84
+ 'systemTotalBytes',
85
+ 'systemFreeBytes'
86
+ ])
87
+ requireNumber(memory, key, 'diagnostics memory');
88
+ const filesystem = report.filesystem;
89
+ if (filesystem !== null) {
90
+ if (!isObject(filesystem))
91
+ throw new Error(`The diagnostics report states \`filesystem\` as ${JSON.stringify(filesystem)}; the document states an object or null.`);
92
+ requireString(filesystem, 'path', 'diagnostics filesystem');
93
+ for (const key of ['totalBytes', 'freeBytes', 'usedBytes', 'usedPercent'])
94
+ requireNumber(filesystem, key, 'diagnostics filesystem');
95
+ }
96
+ if (!Array.isArray(report.folders))
97
+ throw new Error('The diagnostics report states `folders` as something other than an array.');
98
+ for (const folder of report.folders) {
99
+ if (!isObject(folder))
100
+ throw new Error('The diagnostics report carries a folder that is not an object.');
101
+ const entry = folder;
102
+ requireString(entry, 'label', 'diagnostics folder');
103
+ requireString(entry, 'path', 'diagnostics folder');
104
+ requireNumber(entry, 'bytes', 'diagnostics folder');
105
+ requireNumber(entry, 'files', 'diagnostics folder');
106
+ if (typeof entry.exists !== 'boolean' ||
107
+ typeof entry.truncated !== 'boolean')
108
+ throw new Error('The diagnostics folder report states `exists` or `truncated` as something other than a boolean.');
109
+ }
110
+ const logs = requireObject(report, 'logs', 'diagnostics');
111
+ requireString(logs, 'folder', 'diagnostics logs');
112
+ requireNumber(logs, 'fileCount', 'diagnostics logs');
113
+ requireNumber(logs, 'totalBytes', 'diagnostics logs');
114
+ for (const key of ['newestFile', 'newestModified'])
115
+ if (!(logs[key] === null || isString(logs[key])))
116
+ throw new Error(`The diagnostics logs summary states \`${key}\` as ${JSON.stringify(logs[key])}; the document states a string or null.`);
117
+ return report;
118
+ };
119
+ /** The log listing, checked entry by entry. */
120
+ export const normaliseLogFiles = (files) => {
121
+ if (!Array.isArray(files))
122
+ throw new Error('The log report is not an array of files.');
123
+ return files.map((file) => {
124
+ if (!isObject(file))
125
+ throw new Error('The log report carries an entry that is not an object.');
126
+ const entry = file;
127
+ requireString(entry, 'name', 'logs');
128
+ requireString(entry, 'modified', 'logs');
129
+ requireNumber(entry, 'sizeBytes', 'logs');
130
+ return file;
131
+ });
132
+ };
133
+ /**
134
+ * A log file name the route will hand to a host.
135
+ *
136
+ * The rule is sasjs/server's, applied before the filesystem: a bare name ending
137
+ * in `.log`. `.` and `..` are refused by the basename check, because both have a
138
+ * basename equal to themselves and neither ends in `.log`.
139
+ */
140
+ export const checkLogFileName = (fileName) => {
141
+ if (!fileName ||
142
+ fileName.includes('/') ||
143
+ fileName.includes('\\') ||
144
+ fileName.split(/[\\/]/).pop() !== fileName ||
145
+ !fileName.toLowerCase().endsWith('.log'))
146
+ throw new ApiError(400, 'Invalid log file name.');
147
+ return fileName;
148
+ };
149
+ /**
150
+ * How many trailing lines to return.
151
+ *
152
+ * A caller's `lines` is text on the wire, so an absent or unusable value is the
153
+ * documented default rather than a refusal - the parameter is a preference, not
154
+ * a requirement. The ceiling is the document's maximum, so a host is never asked
155
+ * to read more than it stated it would.
156
+ */
157
+ export const logLines = (lines) => {
158
+ // `?lines=` is absent in every sense that matters: a caller that sent the
159
+ // parameter with no value asked for the default, not for zero lines
160
+ if (lines === undefined || lines === null || lines === '')
161
+ return DEFAULT_LOG_LINES;
162
+ const wanted = Number(lines);
163
+ if (!Number.isFinite(wanted))
164
+ return DEFAULT_LOG_LINES;
165
+ return Math.min(Math.max(Math.trunc(wanted), 1), MAX_LOG_LINES);
166
+ };
167
+ /** The tail, checked against the shape the document states. */
168
+ const normaliseLogTail = (tail) => {
169
+ if (!isObject(tail))
170
+ throw new Error('The log tail report is not an object.');
171
+ const entry = tail;
172
+ requireString(entry, 'fileName', 'log tail');
173
+ requireString(entry, 'content', 'log tail');
174
+ requireNumber(entry, 'lines', 'log tail');
175
+ requireNumber(entry, 'bytesRead', 'log tail');
176
+ if (typeof entry.truncated !== 'boolean')
177
+ throw new Error('The log tail report states `truncated` as something other than a boolean.');
178
+ return tail;
179
+ };
180
+ /**
181
+ * The admin service, over the host's reports.
182
+ *
183
+ * The name rule and the line clamp run here, before the host is asked for
184
+ * anything: a host that resolves an unchecked name is a host that can be talked
185
+ * into reading outside its log folder.
186
+ */
187
+ export const createAdminService = (reports) => ({
188
+ async diagnostics() {
189
+ return normaliseDiagnostics(await reports.diagnostics());
190
+ },
191
+ async logs() {
192
+ return normaliseLogFiles(await reports.logs());
193
+ },
194
+ async logTail(fileName, lines) {
195
+ const name = checkLogFileName(fileName);
196
+ const tail = await reports.logTail(name, logLines(lines));
197
+ if (tail === undefined)
198
+ throw new ApiError(404, 'Log file not found.');
199
+ return normaliseLogTail(tail);
200
+ }
201
+ });
@@ -0,0 +1,92 @@
1
+ /**
2
+ * The provider configuration an administrator is allowed to read.
3
+ *
4
+ * `GET /SASjsApi/authConfig` exists so the administration interface can show
5
+ * which external providers a host was started with. The values are the host's
6
+ * environment; the decision this file owns is what may leave the process:
7
+ *
8
+ * - only providers that are enabled appear, so the interface cannot offer to
9
+ * edit a provider the host does not have;
10
+ * - a secret is never echoed - the answer carries `LDAP_BIND_PASSWORD_SET` and
11
+ * `OIDC_CLIENT_SECRET_SET` (whether one is configured) and not the value.
12
+ * sasjs/server reads the bind password and the client secret from the
13
+ * environment and reports only those booleans, because this response is
14
+ * rendered into the admin page, the browser's state, the cache and any
15
+ * proxy log in the path;
16
+ * - a host that hands this service something shaped like a secret is refused
17
+ * by name rather than served, so a host cannot leak one through the route by
18
+ * naming a field the interface happens to render.
19
+ *
20
+ * The keys are the environment's own names (`LDAP_URL`, `OIDC_CLIENT_SECRET_SET`)
21
+ * because that is what sasjs/server answers and what the admin page reads - a
22
+ * translation here would be a second contract.
23
+ */
24
+ /** What a host passes for LDAP; the booleans stand in for the secrets. */
25
+ export interface LdapProviderConfig {
26
+ url: string;
27
+ bindDn: string;
28
+ usersBaseDn: string;
29
+ groupsBaseDn: string;
30
+ /** Whether a bind password is configured. The value itself must never be passed. */
31
+ bindPasswordSet: boolean;
32
+ }
33
+ export interface OidcProviderConfig {
34
+ providerName: string;
35
+ issuerUrl: string;
36
+ clientId: string;
37
+ redirectUri: string;
38
+ scope: string;
39
+ signingAlg: string;
40
+ usernameClaim: string;
41
+ /** The host passes the variable through, so it stays a string here. */
42
+ jitProvision: string;
43
+ /** Whether a client secret is configured. The value itself must never be passed. */
44
+ clientSecretSet: boolean;
45
+ }
46
+ export interface AuthConfig {
47
+ ldap?: LdapProviderConfig;
48
+ oidc?: OidcProviderConfig;
49
+ }
50
+ /** The body the route sends, with the environment's own key names. */
51
+ export interface AuthConfigResponse {
52
+ ldap?: {
53
+ LDAP_URL: string;
54
+ LDAP_BIND_DN: string;
55
+ LDAP_USERS_BASE_DN: string;
56
+ LDAP_GROUPS_BASE_DN: string;
57
+ LDAP_BIND_PASSWORD_SET: boolean;
58
+ };
59
+ oidc?: {
60
+ OIDC_PROVIDER_NAME: string;
61
+ OIDC_ISSUER_URL: string;
62
+ OIDC_CLIENT_ID: string;
63
+ OIDC_REDIRECT_URI: string;
64
+ OIDC_SCOPE: string;
65
+ OIDC_SIGNING_ALG: string;
66
+ OIDC_USERNAME_CLAIM: string;
67
+ OIDC_JIT_PROVISION: string;
68
+ OIDC_CLIENT_SECRET_SET: boolean;
69
+ };
70
+ }
71
+ export interface AuthConfigService {
72
+ authConfig(): Promise<AuthConfigResponse>;
73
+ }
74
+ /**
75
+ * The configuration, checked and rendered in the document's key names.
76
+ *
77
+ * Refusals are `Error` rather than `ApiError`: a host that passes a secret, or a
78
+ * provider block with no fields, is misconfigured rather than answering a bad
79
+ * request, and a `500` carrying its own configuration problem would blame the
80
+ * caller.
81
+ */
82
+ export declare const normaliseAuthConfig: (config: AuthConfig) => AuthConfigResponse;
83
+ /**
84
+ * The auth-config service, over the host's own environment.
85
+ *
86
+ * A getter is accepted because the values are read from the environment and a
87
+ * host can be reconfigured without a restart in some deployments; reading per
88
+ * request keeps the answer true. The values never leave the process - only the
89
+ * two `*_SET` booleans describe the secrets.
90
+ */
91
+ export declare const createAuthConfigService: (config: AuthConfig | (() => AuthConfig)) => AuthConfigService;
92
+ //# sourceMappingURL=service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/authconfig/service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,0EAA0E;AAC1E,MAAM,WAAW,kBAAkB;IACjC,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,EAAE,MAAM,CAAA;IACd,WAAW,EAAE,MAAM,CAAA;IACnB,YAAY,EAAE,MAAM,CAAA;IACpB,oFAAoF;IACpF,eAAe,EAAE,OAAO,CAAA;CACzB;AAED,MAAM,WAAW,kBAAkB;IACjC,YAAY,EAAE,MAAM,CAAA;IACpB,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;IAChB,WAAW,EAAE,MAAM,CAAA;IACnB,KAAK,EAAE,MAAM,CAAA;IACb,UAAU,EAAE,MAAM,CAAA;IAClB,aAAa,EAAE,MAAM,CAAA;IACrB,uEAAuE;IACvE,YAAY,EAAE,MAAM,CAAA;IACpB,oFAAoF;IACpF,eAAe,EAAE,OAAO,CAAA;CACzB;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,EAAE,kBAAkB,CAAA;IACzB,IAAI,CAAC,EAAE,kBAAkB,CAAA;CAC1B;AAED,sEAAsE;AACtE,MAAM,WAAW,kBAAkB;IACjC,IAAI,CAAC,EAAE;QACL,QAAQ,EAAE,MAAM,CAAA;QAChB,YAAY,EAAE,MAAM,CAAA;QACpB,kBAAkB,EAAE,MAAM,CAAA;QAC1B,mBAAmB,EAAE,MAAM,CAAA;QAC3B,sBAAsB,EAAE,OAAO,CAAA;KAChC,CAAA;IACD,IAAI,CAAC,EAAE;QACL,kBAAkB,EAAE,MAAM,CAAA;QAC1B,eAAe,EAAE,MAAM,CAAA;QACvB,cAAc,EAAE,MAAM,CAAA;QACtB,iBAAiB,EAAE,MAAM,CAAA;QACzB,UAAU,EAAE,MAAM,CAAA;QAClB,gBAAgB,EAAE,MAAM,CAAA;QACxB,mBAAmB,EAAE,MAAM,CAAA;QAC3B,kBAAkB,EAAE,MAAM,CAAA;QAC1B,sBAAsB,EAAE,OAAO,CAAA;KAChC,CAAA;CACF;AAED,MAAM,WAAW,iBAAiB;IAChC,UAAU,IAAI,OAAO,CAAC,kBAAkB,CAAC,CAAA;CAC1C;AAyED;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,GAAI,QAAQ,UAAU,KAAG,kBA4CxD,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,uBAAuB,GAClC,QAAQ,UAAU,GAAG,CAAC,MAAM,UAAU,CAAC,KACtC,iBAQF,CAAA"}
@@ -0,0 +1,134 @@
1
+ /**
2
+ * The provider configuration an administrator is allowed to read.
3
+ *
4
+ * `GET /SASjsApi/authConfig` exists so the administration interface can show
5
+ * which external providers a host was started with. The values are the host's
6
+ * environment; the decision this file owns is what may leave the process:
7
+ *
8
+ * - only providers that are enabled appear, so the interface cannot offer to
9
+ * edit a provider the host does not have;
10
+ * - a secret is never echoed - the answer carries `LDAP_BIND_PASSWORD_SET` and
11
+ * `OIDC_CLIENT_SECRET_SET` (whether one is configured) and not the value.
12
+ * sasjs/server reads the bind password and the client secret from the
13
+ * environment and reports only those booleans, because this response is
14
+ * rendered into the admin page, the browser's state, the cache and any
15
+ * proxy log in the path;
16
+ * - a host that hands this service something shaped like a secret is refused
17
+ * by name rather than served, so a host cannot leak one through the route by
18
+ * naming a field the interface happens to render.
19
+ *
20
+ * The keys are the environment's own names (`LDAP_URL`, `OIDC_CLIENT_SECRET_SET`)
21
+ * because that is what sasjs/server answers and what the admin page reads - a
22
+ * translation here would be a second contract.
23
+ */
24
+ /** The fields each provider block may carry, in the order the interface reads them. */
25
+ const LDAP_FIELDS = [
26
+ 'url',
27
+ 'bindDn',
28
+ 'usersBaseDn',
29
+ 'groupsBaseDn',
30
+ 'bindPasswordSet'
31
+ ];
32
+ const OIDC_FIELDS = [
33
+ 'providerName',
34
+ 'issuerUrl',
35
+ 'clientId',
36
+ 'redirectUri',
37
+ 'scope',
38
+ 'signingAlg',
39
+ 'usernameClaim',
40
+ 'jitProvision',
41
+ 'clientSecretSet'
42
+ ];
43
+ /**
44
+ * Anything with one of these words in its name is a secret.
45
+ *
46
+ * The check is on the name rather than the value because the value is what a
47
+ * host would have to hand over, and a host that hands it over has already lost:
48
+ * this route is readable, logged and cached. `*Set` is the documented way to say
49
+ * that one exists.
50
+ */
51
+ const SECRET = /(password|secret|passwd|token)/i;
52
+ const checkProvider = (name, block, fields, booleans) => {
53
+ if (!block || typeof block !== 'object')
54
+ throw new Error(`The auth configuration states \`${name}\` as ${JSON.stringify(block)}; a provider is an object, or absent when it is not enabled.`);
55
+ for (const key of Object.keys(block)) {
56
+ if (!fields.includes(key))
57
+ throw new Error(SECRET.test(key)
58
+ ? `The auth configuration states \`${name}.${key}\`, which looks like a secret. Secrets are never echoed by this route: pass \`${key}Set: true\` instead, so the answer carries whether one is configured and not the value.`
59
+ : `The auth configuration carries \`${name}.${key}\`, which the document's example does not state. Remove it, or add it to the provider's fields here and to the document.`);
60
+ }
61
+ for (const key of fields) {
62
+ if (!(key in block))
63
+ throw new Error(`The auth configuration does not state \`${name}.${key}\`, which the administration interface reads. State the empty string when the host has no value for it.`);
64
+ const value = block[key];
65
+ if (booleans.includes(key)) {
66
+ if (typeof value !== 'boolean')
67
+ throw new Error(`The auth configuration states \`${name}.${key}\` as ${JSON.stringify(value)}; it says whether the secret is configured, so it is a boolean.`);
68
+ }
69
+ else if (typeof value !== 'string')
70
+ throw new Error(`The auth configuration states \`${name}.${key}\` as ${JSON.stringify(value)}; the document states a string.`);
71
+ }
72
+ };
73
+ /**
74
+ * The configuration, checked and rendered in the document's key names.
75
+ *
76
+ * Refusals are `Error` rather than `ApiError`: a host that passes a secret, or a
77
+ * provider block with no fields, is misconfigured rather than answering a bad
78
+ * request, and a `500` carrying its own configuration problem would blame the
79
+ * caller.
80
+ */
81
+ export const normaliseAuthConfig = (config) => {
82
+ if (!config || typeof config !== 'object')
83
+ throw new Error('The auth configuration is not an object.');
84
+ for (const key of Object.keys(config))
85
+ if (key !== 'ldap' && key !== 'oidc')
86
+ throw new Error(SECRET.test(key)
87
+ ? `The auth configuration states \`${key}\` at the top level, which looks like a secret. Secrets are never echoed by this route; put the provider under \`ldap\` or \`oidc\` and report whether the secret is set.`
88
+ : `The auth configuration carries \`${key}\`, which is not a provider this API has. The document states \`ldap\` and \`oidc\`.`);
89
+ const answer = {};
90
+ if (config.ldap !== undefined) {
91
+ checkProvider('ldap', config.ldap, LDAP_FIELDS, ['bindPasswordSet']);
92
+ answer.ldap = {
93
+ LDAP_URL: config.ldap.url,
94
+ LDAP_BIND_DN: config.ldap.bindDn,
95
+ LDAP_USERS_BASE_DN: config.ldap.usersBaseDn,
96
+ LDAP_GROUPS_BASE_DN: config.ldap.groupsBaseDn,
97
+ LDAP_BIND_PASSWORD_SET: config.ldap.bindPasswordSet
98
+ };
99
+ }
100
+ if (config.oidc !== undefined) {
101
+ checkProvider('oidc', config.oidc, OIDC_FIELDS, ['clientSecretSet']);
102
+ answer.oidc = {
103
+ OIDC_PROVIDER_NAME: config.oidc.providerName,
104
+ OIDC_ISSUER_URL: config.oidc.issuerUrl,
105
+ OIDC_CLIENT_ID: config.oidc.clientId,
106
+ OIDC_REDIRECT_URI: config.oidc.redirectUri,
107
+ OIDC_SCOPE: config.oidc.scope,
108
+ OIDC_SIGNING_ALG: config.oidc.signingAlg,
109
+ OIDC_USERNAME_CLAIM: config.oidc.usernameClaim,
110
+ OIDC_JIT_PROVISION: config.oidc.jitProvision,
111
+ OIDC_CLIENT_SECRET_SET: config.oidc.clientSecretSet
112
+ };
113
+ }
114
+ // an empty object is the documented answer for a host with no external
115
+ // provider, so it is not an error: the login screen then offers only the
116
+ // local form
117
+ return answer;
118
+ };
119
+ /**
120
+ * The auth-config service, over the host's own environment.
121
+ *
122
+ * A getter is accepted because the values are read from the environment and a
123
+ * host can be reconfigured without a restart in some deployments; reading per
124
+ * request keeps the answer true. The values never leave the process - only the
125
+ * two `*_SET` booleans describe the secrets.
126
+ */
127
+ export const createAuthConfigService = (config) => {
128
+ const read = () => (typeof config === 'function' ? config() : config);
129
+ return {
130
+ async authConfig() {
131
+ return normaliseAuthConfig(read());
132
+ }
133
+ };
134
+ };
@@ -0,0 +1,22 @@
1
+ import type { CorpusCase } from './drive.js';
2
+ import type { DiagnosticsResponse, LogFileInfo, LogTail } from '../admin/service.js';
3
+ /**
4
+ * The host reports the corpus answers with.
5
+ *
6
+ * One log file, a diagnostics body with every block the document states, and a
7
+ * tail for that one file. Deterministic, so a case can pin an exact body; a real
8
+ * host's numbers differ, which is why the server's own suite runs the same
9
+ * cases against its API rather than this fixture.
10
+ */
11
+ export declare const CORPUS_LOG: LogFileInfo;
12
+ export declare const CORPUS_LOG_TAIL: LogTail;
13
+ export declare const CORPUS_DIAGNOSTICS: DiagnosticsResponse;
14
+ /**
15
+ * The admin corpus: one case per documented status of each route.
16
+ *
17
+ * `401` and `500` are host-only (the administrator middleware and the host's own
18
+ * failures), so they are not cases; what is pinned is the body, the traversal
19
+ * refusal the package owns, and the `404` for a name the folder does not hold.
20
+ */
21
+ export declare const ADMIN_CORPUS: CorpusCase[];
22
+ //# sourceMappingURL=admin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"admin.d.ts","sourceRoot":"","sources":["../../../src/corpus/admin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAC5C,OAAO,KAAK,EACV,mBAAmB,EACnB,WAAW,EACX,OAAO,EACR,MAAM,qBAAqB,CAAA;AAE5B;;;;;;;GAOG;AACH,eAAO,MAAM,UAAU,EAAE,WAIxB,CAAA;AAED,eAAO,MAAM,eAAe,EAAE,OAM7B,CAAA;AAED,eAAO,MAAM,kBAAkB,EAAE,mBAiChC,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,EAAE,UAAU,EAqCpC,CAAA"}
@@ -0,0 +1,98 @@
1
+ /**
2
+ * The host reports the corpus answers with.
3
+ *
4
+ * One log file, a diagnostics body with every block the document states, and a
5
+ * tail for that one file. Deterministic, so a case can pin an exact body; a real
6
+ * host's numbers differ, which is why the server's own suite runs the same
7
+ * cases against its API rather than this fixture.
8
+ */
9
+ export const CORPUS_LOG = {
10
+ name: '20260101000000.log',
11
+ sizeBytes: 118,
12
+ modified: '2026-01-01T00:00:00.000Z'
13
+ };
14
+ export const CORPUS_LOG_TAIL = {
15
+ fileName: CORPUS_LOG.name,
16
+ lines: 1,
17
+ bytesRead: 118,
18
+ truncated: false,
19
+ content: 'GET /SASjsApi/info HTTP/1.1 200 118'
20
+ };
21
+ export const CORPUS_DIAGNOSTICS = {
22
+ build: { version: 'v4.16.2', gitHash: 'cda6114', buildDate: null },
23
+ server: {
24
+ mode: 'desktop',
25
+ uptimeSeconds: 3600,
26
+ startedAt: '2026-01-01T00:00:00.000Z',
27
+ pid: 4242,
28
+ nodeVersion: 'v22.11.0',
29
+ platform: 'linux 5.14.0',
30
+ arch: 'x64',
31
+ cpuCount: 8,
32
+ cpuModel: 'Intel(R) Xeon(R) CPU',
33
+ loadAverage: [0.08, 0.11, 0.15],
34
+ runTimes: ['js'],
35
+ sasjsRoot: '/sasjs_root'
36
+ },
37
+ memory: {
38
+ rssBytes: 1,
39
+ heapTotalBytes: 2,
40
+ heapUsedBytes: 3,
41
+ externalBytes: 4,
42
+ systemTotalBytes: 5,
43
+ systemFreeBytes: 6
44
+ },
45
+ filesystem: null,
46
+ folders: [],
47
+ logs: {
48
+ folder: '/sasjs_root/logs',
49
+ fileCount: 1,
50
+ totalBytes: 118,
51
+ newestFile: CORPUS_LOG.name,
52
+ newestModified: CORPUS_LOG.modified
53
+ }
54
+ };
55
+ /**
56
+ * The admin corpus: one case per documented status of each route.
57
+ *
58
+ * `401` and `500` are host-only (the administrator middleware and the host's own
59
+ * failures), so they are not cases; what is pinned is the body, the traversal
60
+ * refusal the package owns, and the `404` for a name the folder does not hold.
61
+ */
62
+ export const ADMIN_CORPUS = [
63
+ {
64
+ id: 'admin-diagnostics-answers-the-report',
65
+ route: 'GET /SASjsApi/admin/diagnostics',
66
+ description: 'answers the host diagnostics report field for field',
67
+ request: {},
68
+ expect: { status: 200, body: CORPUS_DIAGNOSTICS }
69
+ },
70
+ {
71
+ id: 'admin-logs-lists-the-files',
72
+ route: 'GET /SASjsApi/admin/logs',
73
+ description: 'answers the log files the host holds, newest first',
74
+ request: {},
75
+ expect: { status: 200, body: { files: [CORPUS_LOG] } }
76
+ },
77
+ {
78
+ id: 'admin-log-tail-answers-the-tail',
79
+ route: 'GET /SASjsApi/admin/logs/{fileName}',
80
+ description: 'answers the tail of a log the folder holds',
81
+ request: { params: { fileName: CORPUS_LOG.name } },
82
+ expect: { status: 200, body: CORPUS_LOG_TAIL }
83
+ },
84
+ {
85
+ id: 'admin-log-tail-refuses-a-traversal',
86
+ route: 'GET /SASjsApi/admin/logs/{fileName}',
87
+ description: 'refuses a name that could resolve outside the log folder, before the host is asked',
88
+ request: { params: { fileName: '../20260101000000.log' } },
89
+ expect: { status: 400, error: 'Invalid log file name.' }
90
+ },
91
+ {
92
+ id: 'admin-log-tail-answers-404',
93
+ route: 'GET /SASjsApi/admin/logs/{fileName}',
94
+ description: 'answers 404 for a name the folder does not hold',
95
+ request: { params: { fileName: '20250101000000.log' } },
96
+ expect: { status: 404, error: 'Log file not found.' }
97
+ }
98
+ ];
@@ -0,0 +1,31 @@
1
+ import type { CorpusCase } from './drive.js';
2
+ import type { AuthConfig } from '../authconfig/service.js';
3
+ /**
4
+ * The provider configuration the corpus host states.
5
+ *
6
+ * A fixture rather than a value read from anywhere: the case asserts that the
7
+ * route answers what the host holds, with the secrets reported as the two `*Set`
8
+ * booleans and never as values.
9
+ */
10
+ export declare const CORPUS_AUTH_CONFIG: AuthConfig;
11
+ /** The body that fixture must answer with, environment key names and all. */
12
+ export declare const CORPUS_AUTH_CONFIG_BODY: {
13
+ ldap: {
14
+ LDAP_URL: string;
15
+ LDAP_BIND_DN: string;
16
+ LDAP_USERS_BASE_DN: string;
17
+ LDAP_GROUPS_BASE_DN: string;
18
+ LDAP_BIND_PASSWORD_SET: boolean;
19
+ };
20
+ };
21
+ /**
22
+ * The auth-config corpus.
23
+ *
24
+ * The document states one status for this route - `200` - because the
25
+ * administrator check is the host's mount point, and the overlay marks the `401`
26
+ * and `500` it answers as host-only. What is pinned here is the body: the
27
+ * environment's key names, the secret as a boolean, and no provider the host
28
+ * did not enable.
29
+ */
30
+ export declare const AUTH_CONFIG_CORPUS: CorpusCase[];
31
+ //# sourceMappingURL=authconfig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authconfig.d.ts","sourceRoot":"","sources":["../../../src/corpus/authconfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAE1D;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,EAAE,UAQhC,CAAA;AAED,6EAA6E;AAC7E,eAAO,MAAM,uBAAuB;;;;;;;;CAQnC,CAAA;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,EAAE,UAAU,EAS1C,CAAA"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * The provider configuration the corpus host states.
3
+ *
4
+ * A fixture rather than a value read from anywhere: the case asserts that the
5
+ * route answers what the host holds, with the secrets reported as the two `*Set`
6
+ * booleans and never as values.
7
+ */
8
+ export const CORPUS_AUTH_CONFIG = {
9
+ ldap: {
10
+ url: 'ldaps://directory.example:636',
11
+ bindDn: 'cn=admin,dc=example',
12
+ usersBaseDn: 'ou=users,dc=example',
13
+ groupsBaseDn: 'ou=groups,dc=example',
14
+ bindPasswordSet: true
15
+ }
16
+ };
17
+ /** The body that fixture must answer with, environment key names and all. */
18
+ export const CORPUS_AUTH_CONFIG_BODY = {
19
+ ldap: {
20
+ LDAP_URL: 'ldaps://directory.example:636',
21
+ LDAP_BIND_DN: 'cn=admin,dc=example',
22
+ LDAP_USERS_BASE_DN: 'ou=users,dc=example',
23
+ LDAP_GROUPS_BASE_DN: 'ou=groups,dc=example',
24
+ LDAP_BIND_PASSWORD_SET: true
25
+ }
26
+ };
27
+ /**
28
+ * The auth-config corpus.
29
+ *
30
+ * The document states one status for this route - `200` - because the
31
+ * administrator check is the host's mount point, and the overlay marks the `401`
32
+ * and `500` it answers as host-only. What is pinned here is the body: the
33
+ * environment's key names, the secret as a boolean, and no provider the host
34
+ * did not enable.
35
+ */
36
+ export const AUTH_CONFIG_CORPUS = [
37
+ {
38
+ id: 'authconfig-answers-the-enabled-provider',
39
+ route: 'GET /SASjsApi/authConfig',
40
+ description: 'answers the enabled provider with the secret reported as a boolean, never as a value',
41
+ request: {},
42
+ expect: { status: 200, body: CORPUS_AUTH_CONFIG_BODY }
43
+ }
44
+ ];
@@ -0,0 +1,20 @@
1
+ import type { CorpusCase } from './drive.js';
2
+ import type { DirectorySource } from '../directory/service.js';
3
+ /**
4
+ * The directory the corpus host answers with.
5
+ *
6
+ * One user and one group that the default identity fixture does not already
7
+ * hold (`admin`/`user2` and `Admins`/`DCGroup` are in it), so the case pins the
8
+ * counts of what an import creates rather than what it found.
9
+ */
10
+ export declare const CORPUS_DIRECTORY: DirectorySource;
11
+ /**
12
+ * The directory corpus.
13
+ *
14
+ * `401` and `500` are host-only - the administrator middleware and the
15
+ * directory's own failures - so the one documented status this package answers
16
+ * is `200`, carrying what it created. The import's own rules (existing accounts
17
+ * untouched, membership, refusals) are pinned in `spec/directory.spec`.
18
+ */
19
+ export declare const DIRECTORY_CORPUS: CorpusCase[];
20
+ //# sourceMappingURL=directory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"directory.d.ts","sourceRoot":"","sources":["../../../src/corpus/directory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAC5C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAE9D;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,EAAE,eAG9B,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,EAAE,UAAU,EASxC,CAAA"}