@sasjs/api 0.17.5 → 0.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -112,6 +112,16 @@ Refreshing the API surface: regenerate `api/public/swagger.yaml` in `sasjs/serve
112
112
 
113
113
  Re-vendoring is a two-repository change and the server half merges first: the document is only true once the controllers it is generated from answer what it states, so a copy taken from an unmerged server branch describes a server that does not exist yet. Take the copy from a released tag of `sasjs/server` rather than from its `main`, and the document and the code a host runs cannot disagree.
114
114
 
115
+ ### The coverage ratchet
116
+
117
+ `jest.config.js` carries a floor, and a floor only moves when somebody remembers to move it - so it passes a pull request that drops two points as long as it stays above the number. The ratchet is the other half:
118
+
119
+ - `.github/workflows/coverage-baseline.yml` publishes `coverage/coverage-summary.json` for every push to `main` (90-day artifact);
120
+ - a pull request downloads the summary published for its base commit - or for the newest commit the base commit descends from, named in the comment - and `.github/scripts/coverage-ratchet.mjs` fails when any of statements / branches / functions / lines is more than 0.05pt below it;
121
+ - the same comparison is appended to the coverage comment, so "did this go backwards" is answered on the pull request rather than inferred from a total.
122
+
123
+ A deliberate drop is a change to `coverageThreshold` in `jest.config.js` in that same pull request, where a reviewer sees it. The script's own cases run with `node --test .github/scripts/coverage-ratchet.test.mjs`; prove it locally by pointing `--head` and `--base` at the same summary (exit 0) and then at a copy with its totals raised a point (exit 1).
124
+
115
125
  ## Licence
116
126
 
117
127
  MIT. See `LICENCE.md`.
package/build/browser.js CHANGED
@@ -1,4 +1,4 @@
1
- /* @sasjs/api 0.17.5 - the SASjs Server API, for a service worker. https://github.com/sasjs/api */
1
+ /* @sasjs/api 0.18.1 - the SASjs Server API, for a service worker. https://github.com/sasjs/api */
2
2
  "use strict";
3
3
  var SASjsApi = (() => {
4
4
  var __defProp = Object.defineProperty;
@@ -25,6 +25,7 @@ var SASjsApi = (() => {
25
25
  ADMIN_SIGNED_IN: () => ADMIN_SIGNED_IN,
26
26
  ALWAYS_VISIBLE_ROUTES: () => ALWAYS_VISIBLE_ROUTES,
27
27
  ApiError: () => ApiError,
28
+ BROWSER_INFO: () => BROWSER_INFO,
28
29
  CODE_CORPUS: () => CODE_CORPUS,
29
30
  CODE_DEBUG: () => CODE_DEBUG,
30
31
  DEFAULT_GRANTABLE_ROUTES: () => DEFAULT_GRANTABLE_ROUTES,
@@ -39,6 +40,7 @@ var SASjsApi = (() => {
39
40
  HANDLED_ROUTES: () => HANDLED_ROUTES,
40
41
  IDENTITY_CORPUS: () => IDENTITY_CORPUS,
41
42
  IDENTITY_FORMAT: () => IDENTITY_FORMAT,
43
+ INFO_CORPUS: () => INFO_CORPUS,
42
44
  MemoryAppStreamRegistry: () => MemoryAppStreamRegistry,
43
45
  MemoryDriveStore: () => MemoryDriveStore,
44
46
  MemoryIdentityStore: () => MemoryIdentityStore,
@@ -57,6 +59,7 @@ var SASjsApi = (() => {
57
59
  checkDeployTree: () => checkDeployTree,
58
60
  createDriveService: () => createDriveService,
59
61
  createIdentityService: () => createIdentityService,
62
+ createInfoService: () => createInfoService,
60
63
  createRecordService: () => createRecordService,
61
64
  createRuntimeService: () => createRuntimeService,
62
65
  createSessionService: () => createSessionService,
@@ -72,6 +75,7 @@ var SASjsApi = (() => {
72
75
  isRouteGranted: () => isRouteGranted,
73
76
  measureDeployTree: () => measureDeployTree,
74
77
  normaliseDrivePath: () => normaliseDrivePath,
78
+ normaliseInfo: () => normaliseInfo,
75
79
  parseIdentity: () => parseIdentity,
76
80
  routeById: () => routeById,
77
81
  runCase: () => runCase,
@@ -2564,7 +2568,7 @@ var SASjsApi = (() => {
2564
2568
  Web: ["identity"]
2565
2569
  };
2566
2570
  var 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.";
2567
- var HOST_CONFIG = "The body is the host's own configuration - ports, run times and providers - which a mock states for itself and this package cannot know.";
2571
+ var 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.";
2568
2572
  var HOST_OWNED = "The host owns this report: it describes the host's own process and files, which a browser build has no equivalent of.";
2569
2573
  var WEB_BUNDLE = "The host serves its own web bundle; there is no API decision here for this package to answer.";
2570
2574
  var success = { status: "success" };
@@ -2717,7 +2721,25 @@ var SASjsApi = (() => {
2717
2721
  "DELETE /SASjsApi/group/{groupUid}/{userUid}": { implemented: true },
2718
2722
  "DELETE /SASjsApi/group/{uid}": { implemented: true },
2719
2723
  // Info - what the host is, and what this caller may use
2720
- "GET /SASjsApi/info": { implemented: false, reason: HOST_CONFIG },
2724
+ "GET /SASjsApi/info": {
2725
+ implemented: true,
2726
+ // The values are the host's; the shape is the document's, and the service
2727
+ // refuses a configuration that adds a property it does not state (the
2728
+ // browser build used to answer `whiteList` and `protocol`) or omits one it
2729
+ // requires (`httpPort`, `httpsPort`, `localLoginEnabled`).
2730
+ responses: {
2731
+ 200: {
2732
+ mode: "server",
2733
+ cors: "disable",
2734
+ httpPort: 5e3,
2735
+ httpsPort: 443,
2736
+ runTimes: ["sas", "js"],
2737
+ authProviders: [],
2738
+ localLoginEnabled: true,
2739
+ version: "v3.2.2 (4a26a3d)"
2740
+ }
2741
+ }
2742
+ },
2721
2743
  "GET /SASjsApi/info/authorizedRoutes": {
2722
2744
  implemented: true,
2723
2745
  capabilities: ["identity"]
@@ -3020,6 +3042,16 @@ var SASjsApi = (() => {
3020
3042
  }
3021
3043
  }
3022
3044
  switch (routeId) {
3045
+ // The one answer a host states rather than derives: public, pre-auth, and
3046
+ // read by the login screen before anything else.
3047
+ case "GET /SASjsApi/info": {
3048
+ if (!services.info)
3049
+ throw new ApiError(
3050
+ 501,
3051
+ `This host has no info service, so it cannot answer ${routeId}.`
3052
+ );
3053
+ return { status: 200, body: await services.info.info() };
3054
+ }
3023
3055
  case "GET /SASjsApi/drive/file": {
3024
3056
  const file = await drive.read(String(query._filePath || ""));
3025
3057
  return { status: 200, contents: file.contents };
@@ -3381,6 +3413,7 @@ var SASjsApi = (() => {
3381
3413
  }
3382
3414
  };
3383
3415
  var HANDLED_ROUTES = [
3416
+ "GET /SASjsApi/info",
3384
3417
  "POST /SASjsApi/drive/deploy/upload",
3385
3418
  "DELETE /SASjsApi/drive/deploy",
3386
3419
  "GET /SASjsApi/stp/execute",
@@ -3990,6 +4023,144 @@ var SASjsApi = (() => {
3990
4023
  }
3991
4024
  ];
3992
4025
 
4026
+ // src/corpus/info.ts
4027
+ var INFO_CORPUS = [
4028
+ {
4029
+ id: "info-answers-the-documented-shape",
4030
+ route: "GET /SASjsApi/info",
4031
+ description: "answers the host configuration in the shape the document states, and no property it forbids",
4032
+ request: {},
4033
+ expect: {
4034
+ status: 200,
4035
+ shape: {
4036
+ required: [
4037
+ "mode",
4038
+ "cors",
4039
+ "httpPort",
4040
+ "httpsPort",
4041
+ "runTimes",
4042
+ "authProviders",
4043
+ "localLoginEnabled",
4044
+ "version"
4045
+ ],
4046
+ // present only while oidc is a configured provider
4047
+ optional: ["oidcProviderName"]
4048
+ }
4049
+ }
4050
+ }
4051
+ ];
4052
+
4053
+ // src/info/service.ts
4054
+ var BROWSER_INFO = {
4055
+ mode: "desktop",
4056
+ cors: "disable",
4057
+ httpPort: null,
4058
+ httpsPort: null,
4059
+ runTimes: ["js"],
4060
+ authProviders: [],
4061
+ localLoginEnabled: false,
4062
+ version: "dev"
4063
+ };
4064
+ var FIELDS = [
4065
+ "mode",
4066
+ "cors",
4067
+ "httpPort",
4068
+ "httpsPort",
4069
+ "runTimes",
4070
+ "authProviders",
4071
+ "oidcProviderName",
4072
+ "localLoginEnabled",
4073
+ "version"
4074
+ ];
4075
+ var REQUIRED_FIELDS = FIELDS.filter((field) => field !== "oidcProviderName");
4076
+ var MODES = ["server", "desktop"];
4077
+ var CORS_VALUES = ["enable", "disable"];
4078
+ var isNonEmptyString = (value) => typeof value === "string" && value.length > 0;
4079
+ var portOf = (value, name) => {
4080
+ if (value === null || value === void 0) return null;
4081
+ if (typeof value !== "number" || !Number.isInteger(value))
4082
+ throw new Error(
4083
+ `The info configuration states ${name} as ${JSON.stringify(value)}; a port is an integer, or null when the listener is disabled.`
4084
+ );
4085
+ if (value < 1 || value > 65535)
4086
+ throw new Error(
4087
+ `The info configuration states ${name} as ${value}; a port is between 1 and 65535, or null when the listener is disabled.`
4088
+ );
4089
+ return value;
4090
+ };
4091
+ var namesOf = (value, name) => {
4092
+ if (!Array.isArray(value))
4093
+ throw new Error(
4094
+ `The info configuration states ${name} as ${JSON.stringify(value)}; the document states an array of strings.`
4095
+ );
4096
+ for (const entry of value)
4097
+ if (!isNonEmptyString(entry))
4098
+ throw new Error(
4099
+ `The info configuration states ${name} with an entry that is not a name: ${JSON.stringify(entry)}.`
4100
+ );
4101
+ return [...new Set(value)];
4102
+ };
4103
+ var normaliseInfo = (config) => {
4104
+ if (!config || typeof config !== "object")
4105
+ throw new Error("The info configuration is not an object.");
4106
+ for (const key of Object.keys(config))
4107
+ if (!FIELDS.includes(key))
4108
+ throw new Error(
4109
+ `The info configuration carries \`${key}\`, which the document's InfoResponse does not state. Remove it: this route is public, so anything else a host puts here is served to an anonymous caller.`
4110
+ );
4111
+ for (const key of REQUIRED_FIELDS)
4112
+ if (!Object.prototype.hasOwnProperty.call(config, key))
4113
+ throw new Error(
4114
+ `The info configuration does not state \`${key}\`, which the document requires. A client validating the response refuses an answer that omits it.`
4115
+ );
4116
+ const mode = config.mode;
4117
+ if (!MODES.includes(mode))
4118
+ throw new Error(
4119
+ `The info configuration states mode as ${JSON.stringify(mode)}; the document states the ModeType enum - ${MODES.map((value) => `\`${value}\``).join(" or ")}.`
4120
+ );
4121
+ const cors = config.cors;
4122
+ if (!CORS_VALUES.includes(cors))
4123
+ throw new Error(
4124
+ `The info configuration states cors as ${JSON.stringify(cors)}; the document states the CorsType enum - ${CORS_VALUES.map((value) => `\`${value}\``).join(" or ")}.`
4125
+ );
4126
+ const version = config.version;
4127
+ if (!isNonEmptyString(version) || version.trim() === "")
4128
+ throw new Error(
4129
+ `The info configuration states version as ${JSON.stringify(version)}; the document states the release that produced the build, such as \`v3.2.2 (4a26a3d)\`.`
4130
+ );
4131
+ const authProviders = namesOf(config.authProviders, "authProviders");
4132
+ const runTimes = namesOf(config.runTimes, "runTimes");
4133
+ const rawName = config.oidcProviderName;
4134
+ if (rawName !== void 0 && !isNonEmptyString(rawName))
4135
+ throw new Error(
4136
+ `The info configuration states oidcProviderName as ${JSON.stringify(rawName)}; the document states the sign-on button's label, or omits it.`
4137
+ );
4138
+ if (typeof config.localLoginEnabled !== "boolean")
4139
+ throw new Error(
4140
+ `The info configuration states localLoginEnabled as ${JSON.stringify(config.localLoginEnabled)}; the document states a boolean.`
4141
+ );
4142
+ const oidcProviderName = rawName !== void 0 && authProviders.includes("oidc") ? rawName : void 0;
4143
+ return {
4144
+ mode,
4145
+ cors,
4146
+ httpPort: portOf(config.httpPort, "httpPort"),
4147
+ httpsPort: portOf(config.httpsPort, "httpsPort"),
4148
+ runTimes,
4149
+ authProviders,
4150
+ ...oidcProviderName === void 0 ? {} : { oidcProviderName },
4151
+ localLoginEnabled: config.localLoginEnabled,
4152
+ version
4153
+ };
4154
+ };
4155
+ var createInfoService = (config) => {
4156
+ const read = () => typeof config === "function" ? config() : config;
4157
+ return {
4158
+ async info() {
4159
+ return normaliseInfo(read());
4160
+ }
4161
+ };
4162
+ };
4163
+
3993
4164
  // src/identity/fixture.ts
3994
4165
  var IDENTITY_FORMAT = 1;
3995
4166
  var SECONDS_IN_A_DAY2 = 86400;
@@ -7173,6 +7344,7 @@ var SASjsApi = (() => {
7173
7344
  drive: createDriveService(
7174
7345
  testCase.unwritable ? new RefusingDriveStore(testCase.seed || {}) : new MemoryDriveStore(testCase.seed || {})
7175
7346
  ),
7347
+ info: createInfoService(BROWSER_INFO),
7176
7348
  identity: createIdentityService(identity),
7177
7349
  records: createRecordService(identity),
7178
7350
  registry: new MemoryAppStreamRegistry(),
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.INFO_CORPUS = void 0;
4
+ /**
5
+ * The info corpus: the answer the login screen reads before it has a caller.
6
+ *
7
+ * The case pins the shape rather than the values, because the values belong to
8
+ * the host: sasjs/server answers its mode, its real ports and its own build
9
+ * version, and a browser build answers `null` ports and `js`. The members this
10
+ * package ships are pinned in `spec/info.spec`, which drives a configuration;
11
+ * what has to hold on every host is that the eight required properties are
12
+ * present, `oidcProviderName` is there only when a provider is configured, and
13
+ * nothing the document does not state travels with them - the browser build's
14
+ * `whiteList` and `protocol` were exactly that, on a public route.
15
+ */
16
+ exports.INFO_CORPUS = [
17
+ {
18
+ id: 'info-answers-the-documented-shape',
19
+ route: 'GET /SASjsApi/info',
20
+ description: 'answers the host configuration in the shape the document states, and no property it forbids',
21
+ request: {},
22
+ expect: {
23
+ status: 200,
24
+ shape: {
25
+ required: [
26
+ 'mode',
27
+ 'cors',
28
+ 'httpPort',
29
+ 'httpsPort',
30
+ 'runTimes',
31
+ 'authProviders',
32
+ 'localLoginEnabled',
33
+ 'version'
34
+ ],
35
+ // present only while oidc is a configured provider
36
+ optional: ['oidcProviderName']
37
+ }
38
+ }
39
+ }
40
+ ];
@@ -10,6 +10,7 @@ const records_js_1 = require("../identity/records.js");
10
10
  const service_js_3 = require("../session/service.js");
11
11
  const service_js_4 = 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");
13
14
  const memory_store_js_2 = require("../identity/memory-store.js");
14
15
  const fixture_js_1 = require("../identity/fixture.js");
15
16
  const types_js_1 = require("../types.js");
@@ -37,6 +38,7 @@ const servicesFor = (testCase) => {
37
38
  drive: (0, service_js_1.createDriveService)(testCase.unwritable
38
39
  ? new RefusingDriveStore(testCase.seed || {})
39
40
  : new memory_store_js_1.MemoryDriveStore(testCase.seed || {})),
41
+ info: (0, service_js_5.createInfoService)(service_js_5.BROWSER_INFO),
40
42
  identity: (0, service_js_2.createIdentityService)(identity),
41
43
  records: (0, records_js_1.createRecordService)(identity),
42
44
  registry: new registry_js_1.MemoryAppStreamRegistry(),
@@ -187,6 +187,13 @@ const dispatch = async (services, routeId, request = {}) => {
187
187
  }
188
188
  }
189
189
  switch (routeId) {
190
+ // The one answer a host states rather than derives: public, pre-auth, and
191
+ // read by the login screen before anything else.
192
+ case 'GET /SASjsApi/info': {
193
+ if (!services.info)
194
+ throw new types_js_1.ApiError(501, `This host has no info service, so it cannot answer ${routeId}.`);
195
+ return { status: 200, body: await services.info.info() };
196
+ }
190
197
  case 'GET /SASjsApi/drive/file': {
191
198
  const file = await drive.read(String(query._filePath || ''));
192
199
  return { status: 200, contents: file.contents };
@@ -510,6 +517,7 @@ const dispatch = async (services, routeId, request = {}) => {
510
517
  exports.dispatch = dispatch;
511
518
  /** Whether a route is one `dispatch` can answer today. */
512
519
  exports.HANDLED_ROUTES = [
520
+ 'GET /SASjsApi/info',
513
521
  'POST /SASjsApi/drive/deploy/upload',
514
522
  'DELETE /SASjsApi/drive/deploy',
515
523
  'GET /SASjsApi/stp/execute',
@@ -14,7 +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.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 = exports.DEFAULT_IDENTITY = exports.MemoryIdentityStore = 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;
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;
18
19
  /**
19
20
  * `@sasjs/api` - the SASjs Server API described once.
20
21
  *
@@ -69,6 +70,12 @@ Object.defineProperty(exports, "createRecordService", { enumerable: true, get: f
69
70
  Object.defineProperty(exports, "sanitiseDisplayName", { enumerable: true, get: function () { return records_js_1.sanitiseDisplayName; } });
70
71
  var code_js_1 = require("./corpus/code.js");
71
72
  Object.defineProperty(exports, "CODE_CORPUS", { enumerable: true, get: function () { return code_js_1.CODE_CORPUS; } });
73
+ var info_js_1 = require("./corpus/info.js");
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; } });
72
79
  var memory_store_js_2 = require("./identity/memory-store.js");
73
80
  Object.defineProperty(exports, "MemoryIdentityStore", { enumerable: true, get: function () { return memory_store_js_2.MemoryIdentityStore; } });
74
81
  var fixture_js_1 = require("./identity/fixture.js");
@@ -83,15 +90,15 @@ var deploy_js_2 = require("./corpus/deploy.js");
83
90
  Object.defineProperty(exports, "DEPLOY_CORPUS", { enumerable: true, get: function () { return deploy_js_2.DEPLOY_CORPUS; } });
84
91
  var session_js_1 = require("./corpus/session.js");
85
92
  Object.defineProperty(exports, "SESSION_CORPUS", { enumerable: true, get: function () { return session_js_1.SESSION_CORPUS; } });
86
- var service_js_3 = require("./session/service.js");
87
- Object.defineProperty(exports, "createSessionService", { enumerable: true, get: function () { return service_js_3.createSessionService; } });
93
+ var service_js_4 = require("./session/service.js");
94
+ Object.defineProperty(exports, "createSessionService", { enumerable: true, get: function () { return service_js_4.createSessionService; } });
88
95
  var memory_host_js_1 = require("./session/memory-host.js");
89
96
  Object.defineProperty(exports, "DEFAULT_SESSIONS", { enumerable: true, get: function () { return memory_host_js_1.DEFAULT_SESSIONS; } });
90
97
  Object.defineProperty(exports, "MemorySessionHost", { enumerable: true, get: function () { return memory_host_js_1.MemorySessionHost; } });
91
- var service_js_4 = require("./runtime/service.js");
92
- Object.defineProperty(exports, "CODE_DEBUG", { enumerable: true, get: function () { return service_js_4.CODE_DEBUG; } });
93
- Object.defineProperty(exports, "DOCUMENTED_RUN_TIMES", { enumerable: true, get: function () { return service_js_4.DOCUMENTED_RUN_TIMES; } });
94
- Object.defineProperty(exports, "createRuntimeService", { enumerable: true, get: function () { return service_js_4.createRuntimeService; } });
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; } });
95
102
  var memory_runner_js_1 = require("./runtime/memory-runner.js");
96
103
  Object.defineProperty(exports, "MemorySessionRunner", { enumerable: true, get: function () { return memory_runner_js_1.MemorySessionRunner; } });
97
104
  var runtime_js_1 = require("./corpus/runtime.js");
@@ -0,0 +1,167 @@
1
+ "use strict";
2
+ /**
3
+ * What a host is, answered once.
4
+ *
5
+ * `GET /SASjsApi/info` is public and pre-auth: the login screen reads it to
6
+ * decide whether to offer a password form and a single sign-on button, so an
7
+ * answer that omits `localLoginEnabled` locks a user out of a form the server
8
+ * would have accepted. It is also the route both hosts answered differently:
9
+ * sasjs/server sends `mode, cors, httpPort, httpsPort, runTimes, authProviders,
10
+ * oidcProviderName?, localLoginEnabled, version`, while the browser build's service
11
+ * worker sent `mode, cors, whiteList, protocol, runTimes` - missing four
12
+ * fields the document requires and carrying two it forbids. A client written
13
+ * against the document could read neither answer portably.
14
+ *
15
+ * The values are the host's - a port, a mode, the run times it installed - and
16
+ * this file cannot know them. What it owns is the shape: the fields the
17
+ * document states, in one order, with the two derivations the server performs -
18
+ * `oidcProviderName` only while `oidc` is a configured provider, and a disabled
19
+ * listener stated as `null` rather than `0`.
20
+ *
21
+ * A host states its configuration once (or as a getter, when a listener or a
22
+ * run time can change without a restart) and answers the route with
23
+ * `createInfoService(...)`. A host configuration the document cannot describe
24
+ * is refused by name at the call rather than served to a client that validates
25
+ * the response and finds an unexpected property.
26
+ */
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ exports.createInfoService = exports.normaliseInfo = exports.CORS_VALUES = exports.MODES = exports.BROWSER_INFO = void 0;
29
+ /**
30
+ * What the browser build answers, and the case the corpus runs.
31
+ *
32
+ * A service worker is a static origin with no listener of its own, no accounts
33
+ * to sign in with, and one run time - the JavaScript one that compiles SAS. The
34
+ * answer says so rather than leaving the login screen to guess: `cors` is
35
+ * `disable` because every request is same-origin, `localLoginEnabled` is false
36
+ * because there is nothing to sign in to, and both ports are `null` because the
37
+ * site is served by whoever serves the site.
38
+ */
39
+ exports.BROWSER_INFO = {
40
+ mode: 'desktop',
41
+ cors: 'disable',
42
+ httpPort: null,
43
+ httpsPort: null,
44
+ runTimes: ['js'],
45
+ authProviders: [],
46
+ localLoginEnabled: false,
47
+ version: 'dev'
48
+ };
49
+ /** The properties the document gives `InfoResponse`, and no others. */
50
+ const FIELDS = [
51
+ 'mode',
52
+ 'cors',
53
+ 'httpPort',
54
+ 'httpsPort',
55
+ 'runTimes',
56
+ 'authProviders',
57
+ 'oidcProviderName',
58
+ 'localLoginEnabled',
59
+ 'version'
60
+ ];
61
+ /** The properties the document makes required; `oidcProviderName` is not one. */
62
+ const REQUIRED_FIELDS = FIELDS.filter((field) => field !== 'oidcProviderName');
63
+ /**
64
+ * The two enums the document states for this body, from the `ModeType` and
65
+ * `CorsType` schemas sasjs/server publishes (v4.16.2). `spec/info.spec.ts`
66
+ * reads them back out of `spec/swagger.yaml` and fails if these lists and the
67
+ * document disagree in either direction.
68
+ */
69
+ exports.MODES = ['server', 'desktop'];
70
+ exports.CORS_VALUES = ['enable', 'disable'];
71
+ const isNonEmptyString = (value) => typeof value === 'string' && value.length > 0;
72
+ /**
73
+ * A port the document can carry: an integer in range, or `null`.
74
+ *
75
+ * `0` is refused rather than read as "disabled": the server answers `null` for
76
+ * a listener it did not start, so a host that states `0` has a different bug
77
+ * from one that states nothing, and collapsing the two is how a client ends up
78
+ * printing port 0.
79
+ */
80
+ const portOf = (value, name) => {
81
+ if (value === null || value === undefined)
82
+ return null;
83
+ if (typeof value !== 'number' || !Number.isInteger(value))
84
+ throw new Error(`The info configuration states ${name} as ${JSON.stringify(value)}; a port is an integer, or null when the listener is disabled.`);
85
+ if (value < 1 || value > 65535)
86
+ throw new Error(`The info configuration states ${name} as ${value}; a port is between 1 and 65535, or null when the listener is disabled.`);
87
+ return value;
88
+ };
89
+ /** A list of names, with a repeated entry dropped rather than served twice. */
90
+ const namesOf = (value, name) => {
91
+ if (!Array.isArray(value))
92
+ throw new Error(`The info configuration states ${name} as ${JSON.stringify(value)}; the document states an array of strings.`);
93
+ for (const entry of value)
94
+ if (!isNonEmptyString(entry))
95
+ throw new Error(`The info configuration states ${name} with an entry that is not a name: ${JSON.stringify(entry)}.`);
96
+ return [...new Set(value)];
97
+ };
98
+ /**
99
+ * The configuration, checked and put in the document's order.
100
+ *
101
+ * Refusals are `Error` rather than `ApiError`: a host that states an
102
+ * impossible configuration is a broken deployment, not a request the API
103
+ * refused, and answering `500` with a message about its own config would blame
104
+ * the caller for it. The messages name the property, because a host developer
105
+ * reading a stack trace wants the line rather than the type.
106
+ */
107
+ const normaliseInfo = (config) => {
108
+ if (!config || typeof config !== 'object')
109
+ throw new Error('The info configuration is not an object.');
110
+ for (const key of Object.keys(config))
111
+ if (!FIELDS.includes(key))
112
+ throw new Error(`The info configuration carries \`${key}\`, which the document's InfoResponse does not state. Remove it: this route is public, so anything else a host puts here is served to an anonymous caller.`);
113
+ for (const key of REQUIRED_FIELDS)
114
+ if (!Object.prototype.hasOwnProperty.call(config, key))
115
+ throw new Error(`The info configuration does not state \`${key}\`, which the document requires. A client validating the response refuses an answer that omits it.`);
116
+ const mode = config.mode;
117
+ if (!exports.MODES.includes(mode))
118
+ throw new Error(`The info configuration states mode as ${JSON.stringify(mode)}; the document states the ModeType enum - ${exports.MODES.map((value) => `\`${value}\``).join(' or ')}.`);
119
+ const cors = config.cors;
120
+ if (!exports.CORS_VALUES.includes(cors))
121
+ throw new Error(`The info configuration states cors as ${JSON.stringify(cors)}; the document states the CorsType enum - ${exports.CORS_VALUES.map((value) => `\`${value}\``).join(' or ')}.`);
122
+ const version = config.version;
123
+ if (!isNonEmptyString(version) || version.trim() === '')
124
+ throw new Error(`The info configuration states version as ${JSON.stringify(version)}; the document states the release that produced the build, such as \`v3.2.2 (4a26a3d)\`.`);
125
+ const authProviders = namesOf(config.authProviders, 'authProviders');
126
+ const runTimes = namesOf(config.runTimes, 'runTimes');
127
+ const rawName = config.oidcProviderName;
128
+ if (rawName !== undefined && !isNonEmptyString(rawName))
129
+ throw new Error(`The info configuration states oidcProviderName as ${JSON.stringify(rawName)}; the document states the sign-on button's label, or omits it.`);
130
+ if (typeof config.localLoginEnabled !== 'boolean')
131
+ throw new Error(`The info configuration states localLoginEnabled as ${JSON.stringify(config.localLoginEnabled)}; the document states a boolean.`);
132
+ // the server includes the label only while the provider is configured, and a
133
+ // login screen that offers a button for a provider the server does not have
134
+ // sends the user to a refusal - so the name follows the provider, not the
135
+ // environment variable that set it
136
+ const oidcProviderName = rawName !== undefined && authProviders.includes('oidc')
137
+ ? rawName
138
+ : undefined;
139
+ return {
140
+ mode,
141
+ cors,
142
+ httpPort: portOf(config.httpPort, 'httpPort'),
143
+ httpsPort: portOf(config.httpsPort, 'httpsPort'),
144
+ runTimes,
145
+ authProviders,
146
+ ...(oidcProviderName === undefined ? {} : { oidcProviderName }),
147
+ localLoginEnabled: config.localLoginEnabled,
148
+ version
149
+ };
150
+ };
151
+ exports.normaliseInfo = normaliseInfo;
152
+ /**
153
+ * The info service, over the host's own configuration.
154
+ *
155
+ * A function is accepted because the answer can change while the process runs -
156
+ * sasjs/server reads `process.runTimes`, which a desktop install can extend -
157
+ * and reading it per request is what keeps a started host's answer true.
158
+ */
159
+ const createInfoService = (config) => {
160
+ const read = () => (typeof config === 'function' ? config() : config);
161
+ return {
162
+ async info() {
163
+ return (0, exports.normaliseInfo)(read());
164
+ }
165
+ };
166
+ };
167
+ exports.createInfoService = createInfoService;
@@ -26,7 +26,7 @@ exports.TAG_CAPABILITIES = {
26
26
  * thing thirty times.
27
27
  */
28
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 configuration - ports, run times and providers - which a mock states for itself and this package cannot know.";
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
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
31
  const WEB_BUNDLE = 'The host serves its own web bundle; there is no API decision here for this package to answer.';
32
32
  const success = { status: 'success' };
@@ -179,7 +179,25 @@ exports.OVERLAY = {
179
179
  'DELETE /SASjsApi/group/{groupUid}/{userUid}': { implemented: true },
180
180
  'DELETE /SASjsApi/group/{uid}': { implemented: true },
181
181
  // Info - what the host is, and what this caller may use
182
- 'GET /SASjsApi/info': { implemented: false, reason: HOST_CONFIG },
182
+ 'GET /SASjsApi/info': {
183
+ implemented: true,
184
+ // The values are the host's; the shape is the document's, and the service
185
+ // refuses a configuration that adds a property it does not state (the
186
+ // browser build used to answer `whiteList` and `protocol`) or omits one it
187
+ // requires (`httpPort`, `httpsPort`, `localLoginEnabled`).
188
+ responses: {
189
+ 200: {
190
+ mode: 'server',
191
+ cors: 'disable',
192
+ httpPort: 5000,
193
+ httpsPort: 443,
194
+ runTimes: ['sas', 'js'],
195
+ authProviders: [],
196
+ localLoginEnabled: true,
197
+ version: 'v3.2.2 (4a26a3d)'
198
+ }
199
+ }
200
+ },
183
201
  'GET /SASjsApi/info/authorizedRoutes': {
184
202
  implemented: true,
185
203
  capabilities: ['identity']
@@ -60,6 +60,20 @@ export interface CorpusCase {
60
60
  * minted token is not a value a case can state.
61
61
  */
62
62
  keys?: string[];
63
+ /**
64
+ * The body's shape, where every value is the host's.
65
+ *
66
+ * `required` must all be present and every property the body carries must be
67
+ * named in `required` or `optional` - the document's `additionalProperties:
68
+ * false` stated as an assertion. A case that pins `body` or `keys` on such a
69
+ * route pins one host's values into the contract, which the live server then
70
+ * fails: `GET /SASjsApi/info` answers a mode, ports and a version that differ
71
+ * per host while every host answers the same shape.
72
+ */
73
+ shape?: {
74
+ required: string[];
75
+ optional?: string[];
76
+ };
63
77
  /**
64
78
  * How the body travels, where a string could be either. `json` is a JSON
65
79
  * string on the wire - what tsoa emits for `Promise<string>` and what the
@@ -1 +1 @@
1
- {"version":3,"file":"drive.d.ts","sourceRoot":"","sources":["../../../src/corpus/drive.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAE7D,MAAM,WAAW,UAAU;IACzB,6CAA6C;IAC7C,EAAE,EAAE,MAAM,CAAA;IACV,kEAAkE;IAClE,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,MAAM,CAAA;IACnB,kCAAkC;IAClC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAAC,CAAA;IAC1C,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,eAAe,CAAA;IAC1B;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB;;;;;;OAMG;IACH,SAAS,CAAC,EAAE;QAAE,QAAQ,EAAE,MAAM,GAAG,UAAU,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;IACnE,uEAAuE;IACvE,UA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AE,OAAO,CAAA;IACpB,OAAO,EAAE,UAAU,CAAA;IACnB,MAAM,EAAE;QACN,MAAM,EAAE,MAAM,CAAA;QACd,IAAI,CAAC,EAAE,OAAO,CAAA;QACd,QAAQ,CAAC,EAAE,MAAM,GAAG,UAAU,CAAA;QAC9B,yDAAyD;QACzD,KAAK,CAAC,EAAE,MAAM,CAAA;QACd;;;;WAIG;QACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QACjC;;;WAGG;QACH,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;QACf;;;;;;;;;WASG;QACH,KAAK,CAAC,EAAE;YACN,QAAQ,EAAE,MAAM,EAAE,CAAA;YAClB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;SACpB,CAAA;QACD;;;;;;;WAOG;QACH,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAC3B,CAAA;CACF;AAmBD,eAAO,MAAM,YAAY,EAAE,UAAU,EAqapC,CAAA"}
@@ -0,0 +1,15 @@
1
+ import type { CorpusCase } from './drive.js';
2
+ /**
3
+ * The info corpus: the answer the login screen reads before it has a caller.
4
+ *
5
+ * The case pins the shape rather than the values, because the values belong to
6
+ * the host: sasjs/server answers its mode, its real ports and its own build
7
+ * version, and a browser build answers `null` ports and `js`. The members this
8
+ * package ships are pinned in `spec/info.spec`, which drives a configuration;
9
+ * what has to hold on every host is that the eight required properties are
10
+ * present, `oidcProviderName` is there only when a provider is configured, and
11
+ * nothing the document does not state travels with them - the browser build's
12
+ * `whiteList` and `protocol` were exactly that, on a public route.
13
+ */
14
+ export declare const INFO_CORPUS: CorpusCase[];
15
+ //# sourceMappingURL=info.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"info.d.ts","sourceRoot":"","sources":["../../../src/corpus/info.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAE5C;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,WAAW,EAAE,UAAU,EAyBnC,CAAA"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * The info corpus: the answer the login screen reads before it has a caller.
3
+ *
4
+ * The case pins the shape rather than the values, because the values belong to
5
+ * the host: sasjs/server answers its mode, its real ports and its own build
6
+ * version, and a browser build answers `null` ports and `js`. The members this
7
+ * package ships are pinned in `spec/info.spec`, which drives a configuration;
8
+ * what has to hold on every host is that the eight required properties are
9
+ * present, `oidcProviderName` is there only when a provider is configured, and
10
+ * nothing the document does not state travels with them - the browser build's
11
+ * `whiteList` and `protocol` were exactly that, on a public route.
12
+ */
13
+ export const INFO_CORPUS = [
14
+ {
15
+ id: 'info-answers-the-documented-shape',
16
+ route: 'GET /SASjsApi/info',
17
+ description: 'answers the host configuration in the shape the document states, and no property it forbids',
18
+ request: {},
19
+ expect: {
20
+ status: 200,
21
+ shape: {
22
+ required: [
23
+ 'mode',
24
+ 'cors',
25
+ 'httpPort',
26
+ 'httpsPort',
27
+ 'runTimes',
28
+ 'authProviders',
29
+ 'localLoginEnabled',
30
+ 'version'
31
+ ],
32
+ // present only while oidc is a configured provider
33
+ optional: ['oidcProviderName']
34
+ }
35
+ }
36
+ }
37
+ ];
@@ -1 +1 @@
1
- {"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../../../src/corpus/runner.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAE5C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAanD,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,QAAQ,CAAC,EAAE,MAAM,GAAG,UAAU,CAAA;IAC9B,wDAAwD;IACxD,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAI,UAAU,UAAU,KAAG,QAgClD,CAAA;AA2BD;;;;GAIG;AACH,eAAO,MAAM,OAAO,GAClB,UAAU,UAAU,EACpB,WAAU,QAAgC,KACzC,OAAO,CAAC,UAAU,CAepB,CAAA"}
1
+ {"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../../../src/corpus/runner.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAE5C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAcnD,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,QAAQ,CAAC,EAAE,MAAM,GAAG,UAAU,CAAA;IAC9B,wDAAwD;IACxD,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAI,UAAU,UAAU,KAAG,QAiClD,CAAA;AA2BD;;;;GAIG;AACH,eAAO,MAAM,OAAO,GAClB,UAAU,UAAU,EACpB,WAAU,QAAgC,KACzC,OAAO,CAAC,UAAU,CAepB,CAAA"}
@@ -7,6 +7,7 @@ import { createRecordService } from '../identity/records.js';
7
7
  import { createSessionService } from '../session/service.js';
8
8
  import { createRuntimeService } from '../runtime/service.js';
9
9
  import { MemorySessionRunner } from '../runtime/memory-runner.js';
10
+ import { BROWSER_INFO, createInfoService } from '../info/service.js';
10
11
  import { MemoryIdentityStore } from '../identity/memory-store.js';
11
12
  import { DEFAULT_IDENTITY } from '../identity/fixture.js';
12
13
  import { isApiError } from '../types.js';
@@ -34,6 +35,7 @@ export const servicesFor = (testCase) => {
34
35
  drive: createDriveService(testCase.unwritable
35
36
  ? new RefusingDriveStore(testCase.seed || {})
36
37
  : new MemoryDriveStore(testCase.seed || {})),
38
+ info: createInfoService(BROWSER_INFO),
37
39
  identity: createIdentityService(identity),
38
40
  records: createRecordService(identity),
39
41
  registry: new MemoryAppStreamRegistry(),
@@ -5,6 +5,7 @@ import type { SessionService } from '../session/service.js';
5
5
  import type { RuntimeService } from '../runtime/service.js';
6
6
  import type { AppStreamRegistry } from '../drive/registry.js';
7
7
  import type { CodeService } from '../code/service.js';
8
+ import type { InfoService } from '../info/service.js';
8
9
  import type { Subject } from '../identity/types.js';
9
10
  export interface ApiRequest {
10
11
  query?: Record<string, string | undefined>;
@@ -48,6 +49,12 @@ export interface ApiResponse {
48
49
  export interface Services {
49
50
  /** The editor routes, where the host supplies a linter. */
50
51
  code?: CodeService;
52
+ /**
53
+ * What this host is - mode, listeners, run times, providers. Absent, `GET
54
+ * /SASjsApi/info` answers 501: the package knows the shape of the answer and
55
+ * the host is the only one that knows its values.
56
+ */
57
+ info?: InfoService;
51
58
  drive: DriveService;
52
59
  /**
53
60
  * Users, clients and tokens. A host without one answers 501 for the identity
@@ -1 +1 @@
1
- {"version":3,"file":"dispatch.d.ts","sourceRoot":"","sources":["../../../src/host/dispatch.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAC3D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAE7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAwBnD,MAAM,WAAW,UAAU;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA;IAC1C,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EA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,EAAE,MAAM,CAAA;IACd,mBAAmB;IACnB,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,uEAAuE;IACvE,QAAQ,CAAC,EAAE,MAAM,GAAG,UAAU,CAAA;CAC/B;AAED,MAAM,WAAW,QAAQ;IACvB,2DAA2D;IAC3D,IAAI,CAAC,EAAE,WAAW,CAAA;IAClB;;;;OAIG;IACH,IAAI,CAAC,EAAE,WAAW,CAAA;IAClB,KAAK,EAAE,YAAY,CAAA;IACnB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,eAAe,CAAA;IAC1B,yFAAyF;IACzF,OAAO,CAAC,EAAE,aAAa,CAAA;IACvB;;;OAGG;IACH,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB;;;OAGG;IACH,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB;;;OAGG;IACH,QAAQ,CAAC,EAAE,iBAAiB,CAAA;CAC7B;AA2CD,eAAO,MAAM,QAAQ,GACnB,UAAU,QAAQ,EAClB,SAAS,MAAM,EACf,UAAS,UAAe,KACvB,OAAO,CAAC,WAAW,CA0kBrB,CAAA;AAED,0DAA0D;AAC1D,eAAO,MAAM,cAAc,EAAE,MAAM,EAwDlC,CAAA"}
@@ -184,6 +184,13 @@ export const dispatch = async (services, routeId, request = {}) => {
184
184
  }
185
185
  }
186
186
  switch (routeId) {
187
+ // The one answer a host states rather than derives: public, pre-auth, and
188
+ // read by the login screen before anything else.
189
+ case 'GET /SASjsApi/info': {
190
+ if (!services.info)
191
+ throw new ApiError(501, `This host has no info service, so it cannot answer ${routeId}.`);
192
+ return { status: 200, body: await services.info.info() };
193
+ }
187
194
  case 'GET /SASjsApi/drive/file': {
188
195
  const file = await drive.read(String(query._filePath || ''));
189
196
  return { status: 200, contents: file.contents };
@@ -506,6 +513,7 @@ export const dispatch = async (services, routeId, request = {}) => {
506
513
  };
507
514
  /** Whether a route is one `dispatch` can answer today. */
508
515
  export const HANDLED_ROUTES = [
516
+ 'GET /SASjsApi/info',
509
517
  'POST /SASjsApi/drive/deploy/upload',
510
518
  'DELETE /SASjsApi/drive/deploy',
511
519
  'GET /SASjsApi/stp/execute',
@@ -30,6 +30,9 @@ export type { ApiRequest, ApiResponse, Services } from './host/dispatch.js';
30
30
  export { createIdentityService } from './identity/service.js';
31
31
  export { createRecordService, sanitiseDisplayName } from './identity/records.js';
32
32
  export { CODE_CORPUS } from './corpus/code.js';
33
+ export { INFO_CORPUS } from './corpus/info.js';
34
+ export { BROWSER_INFO, createInfoService, normaliseInfo } from './info/service.js';
35
+ export type { InfoResponse, InfoService } from './info/service.js';
33
36
  export type { AuthorizedRoutesResponse, GroupDetailsResponse, GroupResponse, PermissionResponse, RecordServiceOptions, RecordService, UserDetailsResponse, UserResponse } from './identity/records.js';
34
37
  export type { IdentityService, LoginResult, SessionResult } from './identity/service.js';
35
38
  export { MemoryIdentityStore } from './identity/memory-store.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,cAAc,YAAY,CAAA;AAC1B,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,OAAO,EACP,QAAQ,EACR,MAAM,EACP,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AACvD,OAAO,EACL,aAAa,EACb,oBAAoB,EACpB,cAAc,EACd,eAAe,EACf,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,iBAAiB,EAClB,MAAM,mBAAmB,CAAA;AAC1B,YAAY,EACV,YAAY,EACZ,kBAAkB,EAClB,YAAY,EACZ,aAAa,EACb,UAAU,EACX,MAAM,mBAAmB,CAAA;AAC1B,YAAY,EACV,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,SAAS,EACT,SAAS,EACV,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EAAE,MAA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A;AAC7B,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAC9E,OAAO,EACL,UAAU,EACV,oBAAoB,EACpB,oBAAoB,EACrB,MAAM,sBAAsB,CAAA;AAC7B,YAAY,EACV,aAAa,EACb,UAAU,EACV,UAAU,EACV,aAAa,EACb,cAAc,EACd,cAAc,EACd,qBAAqB,EACrB,aAAa,EACb,eAAe,EAChB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAA;AAChE,YAAY,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAA;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,EACL,uBAAuB,EACvB,kBAAkB,EACnB,MAAM,qBAAqB,CAAA;AAC5B,YAAY,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAC3E,OAAO,EACL,aAAa,EACb,eAAe,EACf,gBAAgB,EACjB,MAAM,qBAAqB,CAAA;AAC5B,YAAY,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AACzD,YAAY,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA"}
@@ -26,6 +26,8 @@ export * from './identity/routeAccess.js';
26
26
  export { createIdentityService } from './identity/service.js';
27
27
  export { createRecordService, sanitiseDisplayName } from './identity/records.js';
28
28
  export { CODE_CORPUS } from './corpus/code.js';
29
+ export { INFO_CORPUS } from './corpus/info.js';
30
+ export { BROWSER_INFO, createInfoService, normaliseInfo } from './info/service.js';
29
31
  export { MemoryIdentityStore } from './identity/memory-store.js';
30
32
  export { DEFAULT_IDENTITY, IDENTITY_FORMAT, parseIdentity } from './identity/fixture.js';
31
33
  export { DRIVE_CORPUS } from './corpus/drive.js';
@@ -0,0 +1,110 @@
1
+ /**
2
+ * What a host is, answered once.
3
+ *
4
+ * `GET /SASjsApi/info` is public and pre-auth: the login screen reads it to
5
+ * decide whether to offer a password form and a single sign-on button, so an
6
+ * answer that omits `localLoginEnabled` locks a user out of a form the server
7
+ * would have accepted. It is also the route both hosts answered differently:
8
+ * sasjs/server sends `mode, cors, httpPort, httpsPort, runTimes, authProviders,
9
+ * oidcProviderName?, localLoginEnabled, version`, while the browser build's service
10
+ * worker sent `mode, cors, whiteList, protocol, runTimes` - missing four
11
+ * fields the document requires and carrying two it forbids. A client written
12
+ * against the document could read neither answer portably.
13
+ *
14
+ * The values are the host's - a port, a mode, the run times it installed - and
15
+ * this file cannot know them. What it owns is the shape: the fields the
16
+ * document states, in one order, with the two derivations the server performs -
17
+ * `oidcProviderName` only while `oidc` is a configured provider, and a disabled
18
+ * listener stated as `null` rather than `0`.
19
+ *
20
+ * A host states its configuration once (or as a getter, when a listener or a
21
+ * run time can change without a restart) and answers the route with
22
+ * `createInfoService(...)`. A host configuration the document cannot describe
23
+ * is refused by name at the call rather than served to a client that validates
24
+ * the response and finds an unexpected property.
25
+ */
26
+ /**
27
+ * The document's `InfoResponse`, field for field.
28
+ *
29
+ * `additionalProperties: false` is why the type is closed: a host that adds
30
+ * `whiteList` - the CORS whitelist, which sasjs/server deliberately keeps out
31
+ * of a public answer - would be served to every anonymous caller.
32
+ */
33
+ export interface InfoResponse {
34
+ /**
35
+ * Which mode the host runs in, from `MODE` - and the two words the document
36
+ * states, `ModeType` (`server`, `desktop`). Typed as a string because that is
37
+ * the JSON type; the service refuses anything outside the enum, and a spec
38
+ * reads the enum out of `spec/swagger.yaml` so the two cannot drift.
39
+ */
40
+ mode: string;
41
+ /**
42
+ * The host's CORS setting, from `CORS` - the document's `CorsType` (`enable`,
43
+ * `disable`), enforced the same way.
44
+ */
45
+ cors: string;
46
+ /** The plain HTTP listener's port, or `null` when it is disabled. */
47
+ httpPort: number | null;
48
+ /** The TLS listener's port, or `null` when it is disabled. */
49
+ httpsPort: number | null;
50
+ /** The run times this host installed, as the execute routes name them. */
51
+ runTimes: string[];
52
+ /** External providers that are configured: `ldap`, `oidc`. */
53
+ authProviders: string[];
54
+ /** The sign-on button's label; absent unless `oidc` is configured. */
55
+ oidcProviderName?: string;
56
+ /** Whether password sign-in for local accounts is switched on. */
57
+ localLoginEnabled: boolean;
58
+ /**
59
+ * What produced the running build, as `v3.2.2 (4a26a3d)`.
60
+ *
61
+ * The browser build's answer names whatever built the site; this package's
62
+ * own fixture says `dev`, the same fallback `sasjs/server` uses when it has no
63
+ * build stamp. Not optional: the document requires it, and a client that
64
+ * stamps the version in a corner of every screen - the login screen included -
65
+ * reads it before anyone has signed in.
66
+ */
67
+ version: string;
68
+ }
69
+ export interface InfoService {
70
+ /** The answer `GET /SASjsApi/info` sends. */
71
+ info(): Promise<InfoResponse>;
72
+ }
73
+ /**
74
+ * What the browser build answers, and the case the corpus runs.
75
+ *
76
+ * A service worker is a static origin with no listener of its own, no accounts
77
+ * to sign in with, and one run time - the JavaScript one that compiles SAS. The
78
+ * answer says so rather than leaving the login screen to guess: `cors` is
79
+ * `disable` because every request is same-origin, `localLoginEnabled` is false
80
+ * because there is nothing to sign in to, and both ports are `null` because the
81
+ * site is served by whoever serves the site.
82
+ */
83
+ export declare const BROWSER_INFO: InfoResponse;
84
+ /**
85
+ * The two enums the document states for this body, from the `ModeType` and
86
+ * `CorsType` schemas sasjs/server publishes (v4.16.2). `spec/info.spec.ts`
87
+ * reads them back out of `spec/swagger.yaml` and fails if these lists and the
88
+ * document disagree in either direction.
89
+ */
90
+ export declare const MODES: string[];
91
+ export declare const CORS_VALUES: string[];
92
+ /**
93
+ * The configuration, checked and put in the document's order.
94
+ *
95
+ * Refusals are `Error` rather than `ApiError`: a host that states an
96
+ * impossible configuration is a broken deployment, not a request the API
97
+ * refused, and answering `500` with a message about its own config would blame
98
+ * the caller for it. The messages name the property, because a host developer
99
+ * reading a stack trace wants the line rather than the type.
100
+ */
101
+ export declare const normaliseInfo: (config: InfoResponse) => InfoResponse;
102
+ /**
103
+ * The info service, over the host's own configuration.
104
+ *
105
+ * A function is accepted because the answer can change while the process runs -
106
+ * sasjs/server reads `process.runTimes`, which a desktop install can extend -
107
+ * and reading it per request is what keeps a started host's answer true.
108
+ */
109
+ export declare const createInfoService: (config: InfoResponse | (() => InfoResponse)) => InfoService;
110
+ //# sourceMappingURL=service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/info/service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH;;;;;;GAMG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;;OAKG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ,qEAAqE;IACrE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,8DAA8D;IAC9D,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,0EAA0E;IAC1E,QAAQ,EAAE,MAAM,EAAE,CAAA;IAClB,8DAA8D;IAC9D,aAAa,EAAE,MAAM,EAAE,CAAA;IACvB,sEAAsE;IACtE,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,kEAAkE;IAClE,iBAAiB,EAAE,OAAO,CAAA;IAC1B;;;;;;;;OAQG;IACH,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,WAAW;IAC1B,6CAA6C;IAC7C,IAAI,IAAI,OAAO,CAAC,YAAY,CAAC,CAAA;CAC9B;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,YAAY,EAAE,YAS1B,CAAA;AAkBD;;;;;GAKG;AACH,eAAO,MAAM,KAAK,UAAwB,CAAA;AAC1C,eAAO,MAAM,WAAW,UAAwB,CAAA;AA6ChD;;;;;;;;GAQG;AACH,eAAO,MAAM,aAAa,GAAI,QAAQ,YAAY,KAAG,YAoEpD,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,GAC5B,QAAQ,YAAY,GAAG,CAAC,MAAM,YAAY,CAAC,KAC1C,WAQF,CAAA"}
@@ -0,0 +1,162 @@
1
+ /**
2
+ * What a host is, answered once.
3
+ *
4
+ * `GET /SASjsApi/info` is public and pre-auth: the login screen reads it to
5
+ * decide whether to offer a password form and a single sign-on button, so an
6
+ * answer that omits `localLoginEnabled` locks a user out of a form the server
7
+ * would have accepted. It is also the route both hosts answered differently:
8
+ * sasjs/server sends `mode, cors, httpPort, httpsPort, runTimes, authProviders,
9
+ * oidcProviderName?, localLoginEnabled, version`, while the browser build's service
10
+ * worker sent `mode, cors, whiteList, protocol, runTimes` - missing four
11
+ * fields the document requires and carrying two it forbids. A client written
12
+ * against the document could read neither answer portably.
13
+ *
14
+ * The values are the host's - a port, a mode, the run times it installed - and
15
+ * this file cannot know them. What it owns is the shape: the fields the
16
+ * document states, in one order, with the two derivations the server performs -
17
+ * `oidcProviderName` only while `oidc` is a configured provider, and a disabled
18
+ * listener stated as `null` rather than `0`.
19
+ *
20
+ * A host states its configuration once (or as a getter, when a listener or a
21
+ * run time can change without a restart) and answers the route with
22
+ * `createInfoService(...)`. A host configuration the document cannot describe
23
+ * is refused by name at the call rather than served to a client that validates
24
+ * the response and finds an unexpected property.
25
+ */
26
+ /**
27
+ * What the browser build answers, and the case the corpus runs.
28
+ *
29
+ * A service worker is a static origin with no listener of its own, no accounts
30
+ * to sign in with, and one run time - the JavaScript one that compiles SAS. The
31
+ * answer says so rather than leaving the login screen to guess: `cors` is
32
+ * `disable` because every request is same-origin, `localLoginEnabled` is false
33
+ * because there is nothing to sign in to, and both ports are `null` because the
34
+ * site is served by whoever serves the site.
35
+ */
36
+ export const BROWSER_INFO = {
37
+ mode: 'desktop',
38
+ cors: 'disable',
39
+ httpPort: null,
40
+ httpsPort: null,
41
+ runTimes: ['js'],
42
+ authProviders: [],
43
+ localLoginEnabled: false,
44
+ version: 'dev'
45
+ };
46
+ /** The properties the document gives `InfoResponse`, and no others. */
47
+ const FIELDS = [
48
+ 'mode',
49
+ 'cors',
50
+ 'httpPort',
51
+ 'httpsPort',
52
+ 'runTimes',
53
+ 'authProviders',
54
+ 'oidcProviderName',
55
+ 'localLoginEnabled',
56
+ 'version'
57
+ ];
58
+ /** The properties the document makes required; `oidcProviderName` is not one. */
59
+ const REQUIRED_FIELDS = FIELDS.filter((field) => field !== 'oidcProviderName');
60
+ /**
61
+ * The two enums the document states for this body, from the `ModeType` and
62
+ * `CorsType` schemas sasjs/server publishes (v4.16.2). `spec/info.spec.ts`
63
+ * reads them back out of `spec/swagger.yaml` and fails if these lists and the
64
+ * document disagree in either direction.
65
+ */
66
+ export const MODES = ['server', 'desktop'];
67
+ export const CORS_VALUES = ['enable', 'disable'];
68
+ const isNonEmptyString = (value) => typeof value === 'string' && value.length > 0;
69
+ /**
70
+ * A port the document can carry: an integer in range, or `null`.
71
+ *
72
+ * `0` is refused rather than read as "disabled": the server answers `null` for
73
+ * a listener it did not start, so a host that states `0` has a different bug
74
+ * from one that states nothing, and collapsing the two is how a client ends up
75
+ * printing port 0.
76
+ */
77
+ const portOf = (value, name) => {
78
+ if (value === null || value === undefined)
79
+ return null;
80
+ if (typeof value !== 'number' || !Number.isInteger(value))
81
+ throw new Error(`The info configuration states ${name} as ${JSON.stringify(value)}; a port is an integer, or null when the listener is disabled.`);
82
+ if (value < 1 || value > 65535)
83
+ throw new Error(`The info configuration states ${name} as ${value}; a port is between 1 and 65535, or null when the listener is disabled.`);
84
+ return value;
85
+ };
86
+ /** A list of names, with a repeated entry dropped rather than served twice. */
87
+ const namesOf = (value, name) => {
88
+ if (!Array.isArray(value))
89
+ throw new Error(`The info configuration states ${name} as ${JSON.stringify(value)}; the document states an array of strings.`);
90
+ for (const entry of value)
91
+ if (!isNonEmptyString(entry))
92
+ throw new Error(`The info configuration states ${name} with an entry that is not a name: ${JSON.stringify(entry)}.`);
93
+ return [...new Set(value)];
94
+ };
95
+ /**
96
+ * The configuration, checked and put in the document's order.
97
+ *
98
+ * Refusals are `Error` rather than `ApiError`: a host that states an
99
+ * impossible configuration is a broken deployment, not a request the API
100
+ * refused, and answering `500` with a message about its own config would blame
101
+ * the caller for it. The messages name the property, because a host developer
102
+ * reading a stack trace wants the line rather than the type.
103
+ */
104
+ export const normaliseInfo = (config) => {
105
+ if (!config || typeof config !== 'object')
106
+ throw new Error('The info configuration is not an object.');
107
+ for (const key of Object.keys(config))
108
+ if (!FIELDS.includes(key))
109
+ throw new Error(`The info configuration carries \`${key}\`, which the document's InfoResponse does not state. Remove it: this route is public, so anything else a host puts here is served to an anonymous caller.`);
110
+ for (const key of REQUIRED_FIELDS)
111
+ if (!Object.prototype.hasOwnProperty.call(config, key))
112
+ throw new Error(`The info configuration does not state \`${key}\`, which the document requires. A client validating the response refuses an answer that omits it.`);
113
+ const mode = config.mode;
114
+ if (!MODES.includes(mode))
115
+ throw new Error(`The info configuration states mode as ${JSON.stringify(mode)}; the document states the ModeType enum - ${MODES.map((value) => `\`${value}\``).join(' or ')}.`);
116
+ const cors = config.cors;
117
+ if (!CORS_VALUES.includes(cors))
118
+ throw new Error(`The info configuration states cors as ${JSON.stringify(cors)}; the document states the CorsType enum - ${CORS_VALUES.map((value) => `\`${value}\``).join(' or ')}.`);
119
+ const version = config.version;
120
+ if (!isNonEmptyString(version) || version.trim() === '')
121
+ throw new Error(`The info configuration states version as ${JSON.stringify(version)}; the document states the release that produced the build, such as \`v3.2.2 (4a26a3d)\`.`);
122
+ const authProviders = namesOf(config.authProviders, 'authProviders');
123
+ const runTimes = namesOf(config.runTimes, 'runTimes');
124
+ const rawName = config.oidcProviderName;
125
+ if (rawName !== undefined && !isNonEmptyString(rawName))
126
+ throw new Error(`The info configuration states oidcProviderName as ${JSON.stringify(rawName)}; the document states the sign-on button's label, or omits it.`);
127
+ if (typeof config.localLoginEnabled !== 'boolean')
128
+ throw new Error(`The info configuration states localLoginEnabled as ${JSON.stringify(config.localLoginEnabled)}; the document states a boolean.`);
129
+ // the server includes the label only while the provider is configured, and a
130
+ // login screen that offers a button for a provider the server does not have
131
+ // sends the user to a refusal - so the name follows the provider, not the
132
+ // environment variable that set it
133
+ const oidcProviderName = rawName !== undefined && authProviders.includes('oidc')
134
+ ? rawName
135
+ : undefined;
136
+ return {
137
+ mode,
138
+ cors,
139
+ httpPort: portOf(config.httpPort, 'httpPort'),
140
+ httpsPort: portOf(config.httpsPort, 'httpsPort'),
141
+ runTimes,
142
+ authProviders,
143
+ ...(oidcProviderName === undefined ? {} : { oidcProviderName }),
144
+ localLoginEnabled: config.localLoginEnabled,
145
+ version
146
+ };
147
+ };
148
+ /**
149
+ * The info service, over the host's own configuration.
150
+ *
151
+ * A function is accepted because the answer can change while the process runs -
152
+ * sasjs/server reads `process.runTimes`, which a desktop install can extend -
153
+ * and reading it per request is what keeps a started host's answer true.
154
+ */
155
+ export const createInfoService = (config) => {
156
+ const read = () => (typeof config === 'function' ? config() : config);
157
+ return {
158
+ async info() {
159
+ return normaliseInfo(read());
160
+ }
161
+ };
162
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"overlay.d.ts","sourceRoot":"","sources":["../../../src/routes/overlay.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAGzD,yDAAyD;AACzD,UAAU,aAAa;IACrB,YAAY,CAAC,EAAE,UAAU,EAAE,CAAA;IAC3B;;;;;;;OAOG;IACH,aAAa,CAAC,EAAE,MAAM,EAAE,CAAA;IACxB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACpC;AAED;;;;;;GAMG;AACH,MAAM,MAAM,YAAY,GAAG,aAAa,GACtC,CAAC;IAAE,WAAW,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,WAAW,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAAA;AAElE,kFAAkF;AAClF,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,EAAE,CAczD,CAAA;AA+BD,eAAO,MAAM,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAuNhD,CAAA;AAED,wEAAwE;AACxE,eAAO,MAAM,OAAO,EAAE,UAAU,EAA8C,CAAA"}
1
+ {"version":3,"file":"overlay.d.ts","sourceRoot":"","sources":["../../../src/routes/overlay.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAGzD,yDAAyD;AACzD,UAAU,aAAa;IACrB,YAAY,CAAC,EAAE,UAAU,EAAE,CAAA;IAC3B;;;;;;;OAOG;IACH,aAAa,CAAC,EAAE,MAAM,EAAE,CAAA;IACxB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACpC;AAED;;;;;;GAMG;AACH,MAAM,MAAM,YAAY,GAAG,aAAa,GACtC,CAAC;IAAE,WAAW,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,WAAW,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAAA;AAElE,kFAAkF;AAClF,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,EAAE,CAczD,CAAA;AA+BD,eAAO,MAAM,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAyOhD,CAAA;AAED,wEAAwE;AACxE,eAAO,MAAM,OAAO,EAAE,UAAU,EAA8C,CAAA"}
@@ -23,7 +23,7 @@ export const TAG_CAPABILITIES = {
23
23
  * thing thirty times.
24
24
  */
25
25
  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.';
26
- const HOST_CONFIG = "The body is the host's own configuration - ports, run times and providers - which a mock states for itself and this package cannot know.";
26
+ 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.";
27
27
  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.";
28
28
  const WEB_BUNDLE = 'The host serves its own web bundle; there is no API decision here for this package to answer.';
29
29
  const success = { status: 'success' };
@@ -176,7 +176,25 @@ export const OVERLAY = {
176
176
  'DELETE /SASjsApi/group/{groupUid}/{userUid}': { implemented: true },
177
177
  'DELETE /SASjsApi/group/{uid}': { implemented: true },
178
178
  // Info - what the host is, and what this caller may use
179
- 'GET /SASjsApi/info': { implemented: false, reason: HOST_CONFIG },
179
+ 'GET /SASjsApi/info': {
180
+ implemented: true,
181
+ // The values are the host's; the shape is the document's, and the service
182
+ // refuses a configuration that adds a property it does not state (the
183
+ // browser build used to answer `whiteList` and `protocol`) or omits one it
184
+ // requires (`httpPort`, `httpsPort`, `localLoginEnabled`).
185
+ responses: {
186
+ 200: {
187
+ mode: 'server',
188
+ cors: 'disable',
189
+ httpPort: 5000,
190
+ httpsPort: 443,
191
+ runTimes: ['sas', 'js'],
192
+ authProviders: [],
193
+ localLoginEnabled: true,
194
+ version: 'v3.2.2 (4a26a3d)'
195
+ }
196
+ }
197
+ },
180
198
  'GET /SASjsApi/info/authorizedRoutes': {
181
199
  implemented: true,
182
200
  capabilities: ['identity']
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sasjs/api",
3
- "version": "0.17.5",
3
+ "version": "0.18.1",
4
4
  "description": "The SASjs Server API, described once - a generated route table, the services behind it, and the conformance corpus both hosts run",
5
5
  "license": "MIT",
6
6
  "author": "SASjs",