@sasjs/api 0.18.1 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/browser.js +820 -29
- package/build/cjs/admin/service.js +209 -0
- package/build/cjs/authconfig/service.js +139 -0
- package/build/cjs/corpus/admin.js +101 -0
- package/build/cjs/corpus/authconfig.js +47 -0
- package/build/cjs/corpus/directory.js +31 -0
- package/build/cjs/corpus/home.js +51 -0
- package/build/cjs/corpus/runner.js +16 -0
- package/build/cjs/directory/service.js +116 -0
- package/build/cjs/home/service.js +103 -0
- package/build/cjs/host/dispatch.js +67 -8
- package/build/cjs/identity/memory-store.js +4 -1
- package/build/cjs/index.js +25 -12
- package/build/cjs/routes/generated.js +56 -0
- package/build/cjs/routes/overlay.js +97 -15
- package/build/esm/admin/service.d.ts +123 -0
- package/build/esm/admin/service.d.ts.map +1 -0
- package/build/esm/admin/service.js +201 -0
- package/build/esm/authconfig/service.d.ts +92 -0
- package/build/esm/authconfig/service.d.ts.map +1 -0
- package/build/esm/authconfig/service.js +134 -0
- package/build/esm/corpus/admin.d.ts +22 -0
- package/build/esm/corpus/admin.d.ts.map +1 -0
- package/build/esm/corpus/admin.js +98 -0
- package/build/esm/corpus/authconfig.d.ts +31 -0
- package/build/esm/corpus/authconfig.d.ts.map +1 -0
- package/build/esm/corpus/authconfig.js +44 -0
- package/build/esm/corpus/directory.d.ts +20 -0
- package/build/esm/corpus/directory.d.ts.map +1 -0
- package/build/esm/corpus/directory.js +28 -0
- package/build/esm/corpus/home.d.ts +27 -0
- package/build/esm/corpus/home.d.ts.map +1 -0
- package/build/esm/corpus/home.js +48 -0
- package/build/esm/corpus/runner.d.ts.map +1 -1
- package/build/esm/corpus/runner.js +16 -0
- package/build/esm/directory/service.d.ts +71 -0
- package/build/esm/directory/service.d.ts.map +1 -0
- package/build/esm/directory/service.js +112 -0
- package/build/esm/home/service.d.ts +69 -0
- package/build/esm/home/service.d.ts.map +1 -0
- package/build/esm/home/service.js +98 -0
- package/build/esm/host/dispatch.d.ts +37 -0
- package/build/esm/host/dispatch.d.ts.map +1 -1
- package/build/esm/host/dispatch.js +65 -7
- package/build/esm/identity/memory-store.d.ts.map +1 -1
- package/build/esm/identity/memory-store.js +4 -1
- package/build/esm/identity/types.d.ts +5 -0
- package/build/esm/identity/types.d.ts.map +1 -1
- package/build/esm/index.d.ts +6 -0
- package/build/esm/index.d.ts.map +1 -1
- package/build/esm/index.js +5 -0
- package/build/esm/routes/generated.d.ts.map +1 -1
- package/build/esm/routes/generated.js +56 -0
- package/build/esm/routes/overlay.d.ts.map +1 -1
- package/build/esm/routes/overlay.js +97 -15
- package/package.json +1 -1
|
@@ -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"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The directory the corpus host answers with.
|
|
3
|
+
*
|
|
4
|
+
* One user and one group that the default identity fixture does not already
|
|
5
|
+
* hold (`admin`/`user2` and `Admins`/`DCGroup` are in it), so the case pins the
|
|
6
|
+
* counts of what an import creates rather than what it found.
|
|
7
|
+
*/
|
|
8
|
+
export const CORPUS_DIRECTORY = {
|
|
9
|
+
users: async () => [{ username: 'alice', displayName: 'Alice' }],
|
|
10
|
+
groups: async () => [{ name: 'analysts' }]
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* The directory corpus.
|
|
14
|
+
*
|
|
15
|
+
* `401` and `500` are host-only - the administrator middleware and the
|
|
16
|
+
* directory's own failures - so the one documented status this package answers
|
|
17
|
+
* is `200`, carrying what it created. The import's own rules (existing accounts
|
|
18
|
+
* untouched, membership, refusals) are pinned in `spec/directory.spec`.
|
|
19
|
+
*/
|
|
20
|
+
export const DIRECTORY_CORPUS = [
|
|
21
|
+
{
|
|
22
|
+
id: 'directory-imports-the-missing-accounts',
|
|
23
|
+
route: 'POST /SASjsApi/authConfig/synchroniseWithLDAP',
|
|
24
|
+
description: 'imports the users and groups the store does not hold, and counts them',
|
|
25
|
+
request: {},
|
|
26
|
+
expect: { status: 200, body: { userCount: 1, groupCount: 1 } }
|
|
27
|
+
}
|
|
28
|
+
];
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { CorpusCase } from './drive.js';
|
|
2
|
+
import type { WebPage } from '../home/service.js';
|
|
3
|
+
/**
|
|
4
|
+
* The shell the corpus host serves.
|
|
5
|
+
*
|
|
6
|
+
* A bundle reference the stamping rule must rewrite, a second reference that
|
|
7
|
+
* already carries a query string (left alone, which is what makes the transform
|
|
8
|
+
* idempotent), and the bundle's name in prose (left as prose). The page a real
|
|
9
|
+
* host reads looks like this; the values are a fixture so a case can pin the
|
|
10
|
+
* exact bytes.
|
|
11
|
+
*/
|
|
12
|
+
export declare const CORPUS_WEB_PAGE: WebPage;
|
|
13
|
+
/**
|
|
14
|
+
* The body that page must answer with: the bundle reference stamped, the
|
|
15
|
+
* already-versioned one and the prose untouched.
|
|
16
|
+
*/
|
|
17
|
+
export declare const CORPUS_WEB_BODY: string;
|
|
18
|
+
/**
|
|
19
|
+
* The home corpus.
|
|
20
|
+
*
|
|
21
|
+
* The document states one status, `200` as `text/html`; what a client cannot see
|
|
22
|
+
* is that the page's bundle reference carries the build's token. That is what the
|
|
23
|
+
* case pins, because a browser holding the previous build is the failure this
|
|
24
|
+
* route exists to prevent.
|
|
25
|
+
*/
|
|
26
|
+
export declare const HOME_CORPUS: CorpusCase[];
|
|
27
|
+
//# sourceMappingURL=home.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"home.d.ts","sourceRoot":"","sources":["../../../src/corpus/home.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAC5C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAEjD;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe,EAAE,OAgB7B,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,eAAe,QAG3B,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,EAAE,UAAU,EASnC,CAAA"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shell the corpus host serves.
|
|
3
|
+
*
|
|
4
|
+
* A bundle reference the stamping rule must rewrite, a second reference that
|
|
5
|
+
* already carries a query string (left alone, which is what makes the transform
|
|
6
|
+
* idempotent), and the bundle's name in prose (left as prose). The page a real
|
|
7
|
+
* host reads looks like this; the values are a fixture so a case can pin the
|
|
8
|
+
* exact bytes.
|
|
9
|
+
*/
|
|
10
|
+
export const CORPUS_WEB_PAGE = {
|
|
11
|
+
version: '4a26a3d1b2c3',
|
|
12
|
+
html: [
|
|
13
|
+
'<!doctype html>',
|
|
14
|
+
'<html>',
|
|
15
|
+
'<head>',
|
|
16
|
+
' <script src="./index.bundle.js"></script>',
|
|
17
|
+
' <script src="./vendor.js?v=keepme"></script>',
|
|
18
|
+
' <link rel="stylesheet" href="./index.bundle.css" />',
|
|
19
|
+
'</head>',
|
|
20
|
+
'<body>',
|
|
21
|
+
' <p>The page loads index.bundle.js from the folder beside it.</p>',
|
|
22
|
+
' <div id="root"></div>',
|
|
23
|
+
'</body>',
|
|
24
|
+
'</html>'
|
|
25
|
+
].join('\n')
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* The body that page must answer with: the bundle reference stamped, the
|
|
29
|
+
* already-versioned one and the prose untouched.
|
|
30
|
+
*/
|
|
31
|
+
export const CORPUS_WEB_BODY = CORPUS_WEB_PAGE.html.replace('./index.bundle.js"', `./index.bundle.js?v=${CORPUS_WEB_PAGE.version}"`);
|
|
32
|
+
/**
|
|
33
|
+
* The home corpus.
|
|
34
|
+
*
|
|
35
|
+
* The document states one status, `200` as `text/html`; what a client cannot see
|
|
36
|
+
* is that the page's bundle reference carries the build's token. That is what the
|
|
37
|
+
* case pins, because a browser holding the previous build is the failure this
|
|
38
|
+
* route exists to prevent.
|
|
39
|
+
*/
|
|
40
|
+
export const HOME_CORPUS = [
|
|
41
|
+
{
|
|
42
|
+
id: 'home-answers-the-stamped-shell',
|
|
43
|
+
route: 'GET /',
|
|
44
|
+
description: 'answers the shell with its bundle reference stamped, leaving prose and an already-versioned reference alone',
|
|
45
|
+
request: {},
|
|
46
|
+
expect: { status: 200, contents: CORPUS_WEB_BODY }
|
|
47
|
+
}
|
|
48
|
+
];
|
|
@@ -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;
|
|
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;AAsBnD,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,QA0ClD,CAAA;AA2BD;;;;GAIG;AACH,eAAO,MAAM,OAAO,GAClB,UAAU,UAAU,EACpB,WAAU,QAAgC,KACzC,OAAO,CAAC,UAAU,CAepB,CAAA"}
|
|
@@ -8,6 +8,14 @@ import { createSessionService } from '../session/service.js';
|
|
|
8
8
|
import { createRuntimeService } from '../runtime/service.js';
|
|
9
9
|
import { MemorySessionRunner } from '../runtime/memory-runner.js';
|
|
10
10
|
import { BROWSER_INFO, createInfoService } from '../info/service.js';
|
|
11
|
+
import { createAuthConfigService } from '../authconfig/service.js';
|
|
12
|
+
import { createAdminService } from '../admin/service.js';
|
|
13
|
+
import { createDirectoryService } from '../directory/service.js';
|
|
14
|
+
import { CORPUS_AUTH_CONFIG } from './authconfig.js';
|
|
15
|
+
import { CORPUS_DIAGNOSTICS, CORPUS_LOG, CORPUS_LOG_TAIL } from './admin.js';
|
|
16
|
+
import { CORPUS_DIRECTORY } from './directory.js';
|
|
17
|
+
import { createHomeService } from '../home/service.js';
|
|
18
|
+
import { CORPUS_WEB_PAGE } from './home.js';
|
|
11
19
|
import { MemoryIdentityStore } from '../identity/memory-store.js';
|
|
12
20
|
import { DEFAULT_IDENTITY } from '../identity/fixture.js';
|
|
13
21
|
import { isApiError } from '../types.js';
|
|
@@ -36,6 +44,14 @@ export const servicesFor = (testCase) => {
|
|
|
36
44
|
? new RefusingDriveStore(testCase.seed || {})
|
|
37
45
|
: new MemoryDriveStore(testCase.seed || {})),
|
|
38
46
|
info: createInfoService(BROWSER_INFO),
|
|
47
|
+
home: createHomeService(async () => CORPUS_WEB_PAGE),
|
|
48
|
+
authConfig: createAuthConfigService(CORPUS_AUTH_CONFIG),
|
|
49
|
+
admin: createAdminService({
|
|
50
|
+
diagnostics: async () => CORPUS_DIAGNOSTICS,
|
|
51
|
+
logs: async () => [CORPUS_LOG],
|
|
52
|
+
logTail: async (fileName) => fileName === CORPUS_LOG.name ? CORPUS_LOG_TAIL : undefined
|
|
53
|
+
}),
|
|
54
|
+
directory: createDirectoryService(identity, CORPUS_DIRECTORY),
|
|
39
55
|
identity: createIdentityService(identity),
|
|
40
56
|
records: createRecordService(identity),
|
|
41
57
|
registry: new MemoryAppStreamRegistry(),
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The directory import: what a host's LDAP answer means for its records.
|
|
3
|
+
*
|
|
4
|
+
* `POST /SASjsApi/authConfig/synchroniseWithLDAP` asks a host to pull its
|
|
5
|
+
* directory into the accounts the API knows. The directory connection is the
|
|
6
|
+
* host's - an LDAP client, a bind, a set of base DNs - and this file cannot
|
|
7
|
+
* have one. What it owns is the import:
|
|
8
|
+
*
|
|
9
|
+
* - a user or group that already exists is left untouched, matched by the
|
|
10
|
+
* name the API keys on (`username`, group `name`), which is what the
|
|
11
|
+
* document states and what makes the call repeatable: a second run imports
|
|
12
|
+
* nothing rather than duplicating the directory;
|
|
13
|
+
* - what it creates is marked with the provider (`ldap` by default), so a
|
|
14
|
+
* host can tell a directory-managed account from a local one - including
|
|
15
|
+
* the groups, which is why `NewGroup` carries the field;
|
|
16
|
+
* - membership travels both ways in a directory answer (a group lists its
|
|
17
|
+
* members, and a user lists its groups), so both are read and the union is
|
|
18
|
+
* applied to the groups this call created. An existing group is not
|
|
19
|
+
* touched: importing is not reconciling, and a caller who expects a
|
|
20
|
+
* deprovisioning sync has asked for a different operation;
|
|
21
|
+
* - a directory answer that names the same username twice, or a user with no
|
|
22
|
+
* username, is refused rather than half-imported.
|
|
23
|
+
*
|
|
24
|
+
* sasjs/server's own implementation deletes every provider-managed account and
|
|
25
|
+
* re-imports; that is its store's policy and it is deliberately not generalised
|
|
26
|
+
* here. The document's description - "Users and groups that already exist are
|
|
27
|
+
* left untouched" - is what this service implements.
|
|
28
|
+
*/
|
|
29
|
+
import type { IdentityStore } from '../identity/types.js';
|
|
30
|
+
export interface DirectoryUser {
|
|
31
|
+
username: string;
|
|
32
|
+
displayName: string;
|
|
33
|
+
/** Groups the directory says this user belongs to, by group name. */
|
|
34
|
+
groups?: string[];
|
|
35
|
+
}
|
|
36
|
+
export interface DirectoryGroup {
|
|
37
|
+
name: string;
|
|
38
|
+
/** Members the directory says this group holds, by username. */
|
|
39
|
+
members?: string[];
|
|
40
|
+
}
|
|
41
|
+
/** One look at the directory, as the host read it. */
|
|
42
|
+
export interface DirectorySource {
|
|
43
|
+
users(): Promise<DirectoryUser[]>;
|
|
44
|
+
groups(): Promise<DirectoryGroup[]>;
|
|
45
|
+
}
|
|
46
|
+
export interface DirectorySyncResult {
|
|
47
|
+
/** How many accounts this call created; existing ones are not counted. */
|
|
48
|
+
userCount: number;
|
|
49
|
+
/** How many groups this call created. */
|
|
50
|
+
groupCount: number;
|
|
51
|
+
}
|
|
52
|
+
export interface DirectoryService {
|
|
53
|
+
synchronise(): Promise<DirectorySyncResult>;
|
|
54
|
+
}
|
|
55
|
+
export interface DirectoryServiceOptions {
|
|
56
|
+
/**
|
|
57
|
+
* The `authProvider` stamped on what the import creates. `ldap` is the
|
|
58
|
+
* provider this route names; a host with a second directory can state its own.
|
|
59
|
+
*/
|
|
60
|
+
provider?: string;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The import, over the host's store.
|
|
64
|
+
*
|
|
65
|
+
* `IdentityStore` is the port rather than `RecordService`, because the records
|
|
66
|
+
* routes require a password (a local account has one to set) and a
|
|
67
|
+
* provider-managed account does not: the host's directory is where it
|
|
68
|
+
* authenticates, and `passwordMatches` answers for it.
|
|
69
|
+
*/
|
|
70
|
+
export declare const createDirectoryService: (store: IdentityStore, source: DirectorySource, options?: DirectoryServiceOptions) => DirectoryService;
|
|
71
|
+
//# sourceMappingURL=service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/directory/service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,OAAO,KAAK,EAEV,aAAa,EAEd,MAAM,sBAAsB,CAAA;AAE7B,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,MAAM,CAAA;IAChB,WAAW,EAAE,MAAM,CAAA;IACnB,qEAAqE;IACrE,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;CAClB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,gEAAgE;IAChE,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;CACnB;AAED,sDAAsD;AACtD,MAAM,WAAW,eAAe;IAC9B,KAAK,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC,CAAA;IACjC,MAAM,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC,CAAA;CACpC;AAED,MAAM,WAAW,mBAAmB;IAClC,0EAA0E;IAC1E,SAAS,EAAE,MAAM,CAAA;IACjB,yCAAyC;IACzC,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,gBAAgB;IAC/B,WAAW,IAAI,OAAO,CAAC,mBAAmB,CAAC,CAAA;CAC5C;AAED,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AA4DD;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,GACjC,OAAO,aAAa,EACpB,QAAQ,eAAe,EACvB,UAAS,uBAA4B,KACpC,gBAsFF,CAAA"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
const isNonEmptyString = (value) => typeof value === 'string' && value.length > 0;
|
|
2
|
+
/**
|
|
3
|
+
* The users, checked before anything is written.
|
|
4
|
+
*
|
|
5
|
+
* A duplicate or nameless entry is refused before the first write, so a bad
|
|
6
|
+
* directory answer cannot leave the store half-imported.
|
|
7
|
+
*/
|
|
8
|
+
const usersOf = (users) => {
|
|
9
|
+
if (!Array.isArray(users))
|
|
10
|
+
throw new Error('The directory answer has no users array.');
|
|
11
|
+
const seen = new Set();
|
|
12
|
+
for (const user of users) {
|
|
13
|
+
if (!isNonEmptyString(user?.username) ||
|
|
14
|
+
!isNonEmptyString(user?.displayName))
|
|
15
|
+
throw new Error(`The directory answer carries a user without a username or displayName: ${JSON.stringify(user)}. Both are what the API keys an account on, so the import cannot guess them.`);
|
|
16
|
+
if (seen.has(user.username))
|
|
17
|
+
throw new Error(`The directory answer names ${user.username} twice. A directory that returns one account twice is a filter problem, and importing it would hide that.`);
|
|
18
|
+
seen.add(user.username);
|
|
19
|
+
}
|
|
20
|
+
return users;
|
|
21
|
+
};
|
|
22
|
+
const groupsOf = (groups) => {
|
|
23
|
+
if (!Array.isArray(groups))
|
|
24
|
+
throw new Error('The directory answer has no groups array.');
|
|
25
|
+
const seen = new Set();
|
|
26
|
+
for (const group of groups) {
|
|
27
|
+
if (!isNonEmptyString(group?.name))
|
|
28
|
+
throw new Error(`The directory answer carries a group without a name: ${JSON.stringify(group)}.`);
|
|
29
|
+
if (seen.has(group.name))
|
|
30
|
+
throw new Error(`The directory answer names the group ${group.name} twice, which would apply its members twice.`);
|
|
31
|
+
seen.add(group.name);
|
|
32
|
+
}
|
|
33
|
+
return groups;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* The import, over the host's store.
|
|
37
|
+
*
|
|
38
|
+
* `IdentityStore` is the port rather than `RecordService`, because the records
|
|
39
|
+
* routes require a password (a local account has one to set) and a
|
|
40
|
+
* provider-managed account does not: the host's directory is where it
|
|
41
|
+
* authenticates, and `passwordMatches` answers for it.
|
|
42
|
+
*/
|
|
43
|
+
export const createDirectoryService = (store, source, options = {}) => {
|
|
44
|
+
const provider = options.provider || 'ldap';
|
|
45
|
+
return {
|
|
46
|
+
async synchronise() {
|
|
47
|
+
const directoryUsers = usersOf(await source.users());
|
|
48
|
+
const directoryGroups = groupsOf(await source.groups());
|
|
49
|
+
const existingUsers = await store.users();
|
|
50
|
+
const existingGroups = await store.groups();
|
|
51
|
+
const userByName = new Map(existingUsers.map((user) => [user.username, user]));
|
|
52
|
+
const groupByName = new Map(existingGroups.map((group) => [group.name, group]));
|
|
53
|
+
// ------------------------------------------------------------- users
|
|
54
|
+
const imported = [];
|
|
55
|
+
for (const user of directoryUsers) {
|
|
56
|
+
if (userByName.has(user.username))
|
|
57
|
+
continue;
|
|
58
|
+
const created = await store.createUser({
|
|
59
|
+
username: user.username,
|
|
60
|
+
displayName: user.displayName,
|
|
61
|
+
isAdmin: false,
|
|
62
|
+
isActive: true,
|
|
63
|
+
authProvider: provider
|
|
64
|
+
});
|
|
65
|
+
userByName.set(created.username, created);
|
|
66
|
+
imported.push(created);
|
|
67
|
+
}
|
|
68
|
+
// ------------------------------------------------------------ groups
|
|
69
|
+
const importedGroups = [];
|
|
70
|
+
for (const group of directoryGroups) {
|
|
71
|
+
if (groupByName.has(group.name))
|
|
72
|
+
continue;
|
|
73
|
+
const created = await store.createGroup({
|
|
74
|
+
name: group.name,
|
|
75
|
+
description: '',
|
|
76
|
+
isActive: true,
|
|
77
|
+
authProvider: provider
|
|
78
|
+
});
|
|
79
|
+
groupByName.set(created.name, created);
|
|
80
|
+
importedGroups.push(created);
|
|
81
|
+
}
|
|
82
|
+
// -------------------------------------------------------- membership
|
|
83
|
+
//
|
|
84
|
+
// Only the groups this call created are touched, so a second run is a
|
|
85
|
+
// no-op and an existing group keeps whatever its administrator set. The
|
|
86
|
+
// union of both directions: a group lists members, and a user lists the
|
|
87
|
+
// groups it belongs to.
|
|
88
|
+
const membersOf = new Map();
|
|
89
|
+
const note = (groupName, username) => {
|
|
90
|
+
const members = membersOf.get(groupName) || new Set();
|
|
91
|
+
members.add(username);
|
|
92
|
+
membersOf.set(groupName, members);
|
|
93
|
+
};
|
|
94
|
+
for (const group of directoryGroups)
|
|
95
|
+
for (const member of group.members || [])
|
|
96
|
+
note(group.name, member);
|
|
97
|
+
for (const user of directoryUsers)
|
|
98
|
+
for (const groupName of user.groups || [])
|
|
99
|
+
note(groupName, user.username);
|
|
100
|
+
for (const group of importedGroups)
|
|
101
|
+
for (const username of membersOf.get(group.name) || []) {
|
|
102
|
+
const user = userByName.get(username);
|
|
103
|
+
// a member the store does not know is not an error: the directory may
|
|
104
|
+
// hold accounts this API was never asked to import, and inventing them
|
|
105
|
+
// would be importing a user the directory did not name
|
|
106
|
+
if (user)
|
|
107
|
+
await store.addToGroup(group.uid, user.uid);
|
|
108
|
+
}
|
|
109
|
+
return { userCount: imported.length, groupCount: importedGroups.length };
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The web interface's shell - the one page every host serves at `/`.
|
|
3
|
+
*
|
|
4
|
+
* The document states what the route is for: "Serves the web interface's
|
|
5
|
+
* `index.html`, with the current bundle version appended so a returning browser
|
|
6
|
+
* loads the updated bundle." That is the whole decision, and it is the same one
|
|
7
|
+
* on every host:
|
|
8
|
+
*
|
|
9
|
+
* - the SPA bundle has a fixed name (`index.bundle.js`), so a browser that
|
|
10
|
+
* keeps the previous build cached goes on rendering the previous interface
|
|
11
|
+
* after an update. A login screen once kept offering a password form the new
|
|
12
|
+
* server refused, and only a cache-disabled reload showed the new screen. The
|
|
13
|
+
* token is derived from the bundle's contents, so it changes with every build
|
|
14
|
+
* and is stable within one;
|
|
15
|
+
* - only an attribute naming the bundle is rewritten, so the same words in
|
|
16
|
+
* prose are left as prose;
|
|
17
|
+
* - a reference that already carries a query string is left alone, so applying
|
|
18
|
+
* this twice cannot produce a second `?v=`;
|
|
19
|
+
* - a host with no build answers a page saying so, rather than an error: a
|
|
20
|
+
* missing bundle costs a stale page at worst, and must never be the reason a
|
|
21
|
+
* deployment cannot render its own app.
|
|
22
|
+
*
|
|
23
|
+
* The host still reads the file and computes the digest - a hash of a megabyte
|
|
24
|
+
* bundle is the host's to make, and the package compiles with no node built-ins
|
|
25
|
+
* and no DOM `crypto`. What it cannot be left to each host is the rule that
|
|
26
|
+
* turns the two into the page, which is why it lives here.
|
|
27
|
+
*/
|
|
28
|
+
/** The entry bundle the served page references. */
|
|
29
|
+
export declare const BUNDLE_NAME = "index.bundle.js";
|
|
30
|
+
/**
|
|
31
|
+
* What a host with no web build answers.
|
|
32
|
+
*
|
|
33
|
+
* A page rather than a `404`: the route is the interface, and an operator whose
|
|
34
|
+
* build did not land needs to see that from the browser rather than from a JSON
|
|
35
|
+
* error. The wording is sasjs/server's, so an adopting host changes nothing a
|
|
36
|
+
* user or a smoke test already reads.
|
|
37
|
+
*/
|
|
38
|
+
export declare const NO_WEB_BUILD = "<html><head></head><body>Web Build is not present</body></html>";
|
|
39
|
+
/** What the host hands over: the page it read, and the token it computed. */
|
|
40
|
+
export interface WebPage {
|
|
41
|
+
/** The shell document, as it was read. */
|
|
42
|
+
html: string;
|
|
43
|
+
/**
|
|
44
|
+
* The cache-busting token for the bundle the page references - a digest of the
|
|
45
|
+
* bundle's contents, twelve characters in sasjs/server's implementation.
|
|
46
|
+
*/
|
|
47
|
+
version: string;
|
|
48
|
+
}
|
|
49
|
+
export interface HomeService {
|
|
50
|
+
/** The page to send with a `200`, as `text/html`. */
|
|
51
|
+
home(): Promise<string>;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The page with its bundle reference carrying that token.
|
|
55
|
+
*
|
|
56
|
+
* Only an attribute naming the bundle is rewritten. A reference that already
|
|
57
|
+
* carries a query string is left alone, so applying this twice is the same as
|
|
58
|
+
* applying it once.
|
|
59
|
+
*/
|
|
60
|
+
export declare const withBundleVersion: (html: string, version: string) => string;
|
|
61
|
+
/**
|
|
62
|
+
* The home service, over the host's own page.
|
|
63
|
+
*
|
|
64
|
+
* The port answers `undefined` when this host has no web build - a packaged
|
|
65
|
+
* server whose build folder is absent, a host that only answers the API - and
|
|
66
|
+
* the service answers the documented page rather than an error.
|
|
67
|
+
*/
|
|
68
|
+
export declare const createHomeService: (page: () => Promise<WebPage | undefined>) => HomeService;
|
|
69
|
+
//# sourceMappingURL=service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/home/service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,mDAAmD;AACnD,eAAO,MAAM,WAAW,oBAAoB,CAAA;AAE5C;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY,oEAC0C,CAAA;AAEnE,6EAA6E;AAC7E,MAAM,WAAW,OAAO;IACtB,0CAA0C;IAC1C,IAAI,EAAE,MAAM,CAAA;IACZ;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,WAAW;IAC1B,qDAAqD;IACrD,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAAA;CACxB;AAiBD;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,GAAI,MAAM,MAAM,EAAE,SAAS,MAAM,KAAG,MAQ9D,CAAA;AAoCJ;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,GAC5B,MAAM,MAAM,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,KACvC,WAKD,CAAA"}
|