@sasjs/api 0.18.0 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/browser.js +717 -18
- 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/runner.js +13 -0
- package/build/cjs/directory/service.js +116 -0
- package/build/cjs/host/dispatch.js +39 -0
- package/build/cjs/identity/memory-store.js +4 -1
- package/build/cjs/index.js +8 -2
- package/build/cjs/info/service.js +13 -8
- package/build/cjs/routes/generated.js +56 -0
- package/build/cjs/routes/overlay.js +86 -12
- 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/runner.d.ts.map +1 -1
- package/build/esm/corpus/runner.js +13 -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/host/dispatch.d.ts +18 -0
- package/build/esm/host/dispatch.d.ts.map +1 -1
- package/build/esm/host/dispatch.js +39 -0
- 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 +3 -0
- package/build/esm/index.d.ts.map +1 -1
- package/build/esm/index.js +3 -0
- package/build/esm/info/service.d.ts +14 -6
- package/build/esm/info/service.d.ts.map +1 -1
- package/build/esm/info/service.js +12 -7
- 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 +86 -12
- package/package.json +1 -1
package/build/browser.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* @sasjs/api 0.
|
|
1
|
+
/* @sasjs/api 0.19.0 - 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;
|
|
@@ -22,8 +22,10 @@ var SASjsApi = (() => {
|
|
|
22
22
|
// src/index.ts
|
|
23
23
|
var index_exports = {};
|
|
24
24
|
__export(index_exports, {
|
|
25
|
+
ADMIN_CORPUS: () => ADMIN_CORPUS,
|
|
25
26
|
ADMIN_SIGNED_IN: () => ADMIN_SIGNED_IN,
|
|
26
27
|
ALWAYS_VISIBLE_ROUTES: () => ALWAYS_VISIBLE_ROUTES,
|
|
28
|
+
AUTH_CONFIG_CORPUS: () => AUTH_CONFIG_CORPUS,
|
|
27
29
|
ApiError: () => ApiError,
|
|
28
30
|
BROWSER_INFO: () => BROWSER_INFO,
|
|
29
31
|
CODE_CORPUS: () => CODE_CORPUS,
|
|
@@ -35,6 +37,7 @@ var SASjsApi = (() => {
|
|
|
35
37
|
DEPLOY_LIMITS: () => DEPLOY_LIMITS,
|
|
36
38
|
DEPLOY_PAYLOAD_BYTES: () => DEPLOY_PAYLOAD_BYTES,
|
|
37
39
|
DEPLOY_SUCCESS: () => DEPLOY_SUCCESS,
|
|
40
|
+
DIRECTORY_CORPUS: () => DIRECTORY_CORPUS,
|
|
38
41
|
DOCUMENTED_RUN_TIMES: () => DOCUMENTED_RUN_TIMES,
|
|
39
42
|
DRIVE_CORPUS: () => DRIVE_CORPUS,
|
|
40
43
|
HANDLED_ROUTES: () => HANDLED_ROUTES,
|
|
@@ -590,6 +593,14 @@ var SASjsApi = (() => {
|
|
|
590
593
|
{
|
|
591
594
|
status: 200,
|
|
592
595
|
description: "Ok"
|
|
596
|
+
},
|
|
597
|
+
{
|
|
598
|
+
status: 401,
|
|
599
|
+
description: "Unauthorized, or an administrator account is required. The mount point in routes/api/index.ts applies both checks before this handler runs."
|
|
600
|
+
},
|
|
601
|
+
{
|
|
602
|
+
status: 500,
|
|
603
|
+
description: "The diagnostics could not be read"
|
|
593
604
|
}
|
|
594
605
|
]
|
|
595
606
|
},
|
|
@@ -605,6 +616,14 @@ var SASjsApi = (() => {
|
|
|
605
616
|
{
|
|
606
617
|
status: 200,
|
|
607
618
|
description: "Ok"
|
|
619
|
+
},
|
|
620
|
+
{
|
|
621
|
+
status: 401,
|
|
622
|
+
description: "Unauthorized, or an administrator account is required. The mount point in routes/api/index.ts applies both checks before this handler runs."
|
|
623
|
+
},
|
|
624
|
+
{
|
|
625
|
+
status: 500,
|
|
626
|
+
description: "The log folder could not be listed"
|
|
608
627
|
}
|
|
609
628
|
]
|
|
610
629
|
},
|
|
@@ -633,6 +652,22 @@ var SASjsApi = (() => {
|
|
|
633
652
|
{
|
|
634
653
|
status: 200,
|
|
635
654
|
description: "Ok"
|
|
655
|
+
},
|
|
656
|
+
{
|
|
657
|
+
status: 400,
|
|
658
|
+
description: "Invalid log file name."
|
|
659
|
+
},
|
|
660
|
+
{
|
|
661
|
+
status: 401,
|
|
662
|
+
description: "Unauthorized, or an administrator account is required. The mount point in routes/api/index.ts applies both checks before this handler runs."
|
|
663
|
+
},
|
|
664
|
+
{
|
|
665
|
+
status: 404,
|
|
666
|
+
description: "Log file not found."
|
|
667
|
+
},
|
|
668
|
+
{
|
|
669
|
+
status: 500,
|
|
670
|
+
description: "The log file could not be read"
|
|
636
671
|
}
|
|
637
672
|
]
|
|
638
673
|
},
|
|
@@ -770,6 +805,18 @@ var SASjsApi = (() => {
|
|
|
770
805
|
{
|
|
771
806
|
status: 200,
|
|
772
807
|
description: "Ok"
|
|
808
|
+
},
|
|
809
|
+
{
|
|
810
|
+
status: 401,
|
|
811
|
+
description: "Unauthorized, or an administrator account is required. The mount point in routes/api/index.ts applies both checks before this handler runs."
|
|
812
|
+
},
|
|
813
|
+
{
|
|
814
|
+
status: 403,
|
|
815
|
+
description: "Not Allowed while in Desktop Mode."
|
|
816
|
+
},
|
|
817
|
+
{
|
|
818
|
+
status: 500,
|
|
819
|
+
description: "The provider configuration could not be read"
|
|
773
820
|
}
|
|
774
821
|
]
|
|
775
822
|
},
|
|
@@ -785,6 +832,18 @@ var SASjsApi = (() => {
|
|
|
785
832
|
{
|
|
786
833
|
status: 200,
|
|
787
834
|
description: "Ok"
|
|
835
|
+
},
|
|
836
|
+
{
|
|
837
|
+
status: 401,
|
|
838
|
+
description: "Unauthorized, or an administrator account is required. The mount point in routes/api/index.ts applies both checks before this handler runs."
|
|
839
|
+
},
|
|
840
|
+
{
|
|
841
|
+
status: 403,
|
|
842
|
+
description: "Not Allowed while in Desktop Mode."
|
|
843
|
+
},
|
|
844
|
+
{
|
|
845
|
+
status: 500,
|
|
846
|
+
description: "The directory could not be synchronised"
|
|
788
847
|
}
|
|
789
848
|
]
|
|
790
849
|
},
|
|
@@ -2567,9 +2626,6 @@ var SASjsApi = (() => {
|
|
|
2567
2626
|
Client: ["identity"],
|
|
2568
2627
|
Web: ["identity"]
|
|
2569
2628
|
};
|
|
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.";
|
|
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.";
|
|
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.";
|
|
2573
2629
|
var WEB_BUNDLE = "The host serves its own web bundle; there is no API decision here for this package to answer.";
|
|
2574
2630
|
var success = { status: "success" };
|
|
2575
2631
|
var user = {
|
|
@@ -2598,12 +2654,71 @@ var SASjsApi = (() => {
|
|
|
2598
2654
|
hostResponses: [500],
|
|
2599
2655
|
responses: { 200: "OK!" }
|
|
2600
2656
|
},
|
|
2601
|
-
// Admin - the host's own process and files
|
|
2602
|
-
|
|
2603
|
-
|
|
2657
|
+
// Admin - the host's own process and files, over the reports it supplies.
|
|
2658
|
+
// The administrator check is the host's mount point (sasjs/server puts
|
|
2659
|
+
// authenticateAccessToken and verifyAdmin in front of all three), so its 401
|
|
2660
|
+
// - and the 500 a genuine failure answers - are host-only statuses.
|
|
2661
|
+
"GET /SASjsApi/admin/diagnostics": {
|
|
2662
|
+
implemented: true,
|
|
2663
|
+
hostResponses: [401, 500],
|
|
2664
|
+
responses: {
|
|
2665
|
+
200: {
|
|
2666
|
+
build: { version: "", gitHash: "", buildDate: null },
|
|
2667
|
+
server: {
|
|
2668
|
+
mode: "desktop",
|
|
2669
|
+
uptimeSeconds: 0,
|
|
2670
|
+
startedAt: "",
|
|
2671
|
+
pid: 0,
|
|
2672
|
+
nodeVersion: "",
|
|
2673
|
+
platform: "",
|
|
2674
|
+
arch: "",
|
|
2675
|
+
cpuCount: 0,
|
|
2676
|
+
cpuModel: "",
|
|
2677
|
+
loadAverage: [],
|
|
2678
|
+
runTimes: [],
|
|
2679
|
+
sasjsRoot: ""
|
|
2680
|
+
},
|
|
2681
|
+
memory: {
|
|
2682
|
+
rssBytes: 0,
|
|
2683
|
+
heapTotalBytes: 0,
|
|
2684
|
+
heapUsedBytes: 0,
|
|
2685
|
+
externalBytes: 0,
|
|
2686
|
+
systemTotalBytes: 0,
|
|
2687
|
+
systemFreeBytes: 0
|
|
2688
|
+
},
|
|
2689
|
+
filesystem: null,
|
|
2690
|
+
folders: [],
|
|
2691
|
+
logs: {
|
|
2692
|
+
folder: "",
|
|
2693
|
+
fileCount: 0,
|
|
2694
|
+
totalBytes: 0,
|
|
2695
|
+
newestFile: null,
|
|
2696
|
+
newestModified: null
|
|
2697
|
+
}
|
|
2698
|
+
}
|
|
2699
|
+
}
|
|
2700
|
+
},
|
|
2701
|
+
"GET /SASjsApi/admin/logs": {
|
|
2702
|
+
implemented: true,
|
|
2703
|
+
hostResponses: [401, 500],
|
|
2704
|
+
responses: { 200: { files: [] } }
|
|
2705
|
+
},
|
|
2604
2706
|
"GET /SASjsApi/admin/logs/{fileName}": {
|
|
2605
|
-
implemented:
|
|
2606
|
-
|
|
2707
|
+
implemented: true,
|
|
2708
|
+
// 400 and 404 are the name rule's, and this package answers them before the
|
|
2709
|
+
// host is asked for anything
|
|
2710
|
+
hostResponses: [401, 500],
|
|
2711
|
+
responses: {
|
|
2712
|
+
200: {
|
|
2713
|
+
fileName: "",
|
|
2714
|
+
lines: 0,
|
|
2715
|
+
bytesRead: 0,
|
|
2716
|
+
truncated: false,
|
|
2717
|
+
content: ""
|
|
2718
|
+
},
|
|
2719
|
+
400: "Invalid log file name.",
|
|
2720
|
+
404: "Log file not found."
|
|
2721
|
+
}
|
|
2607
2722
|
},
|
|
2608
2723
|
// Auth - the token flow, plus a password change the identity store cannot write
|
|
2609
2724
|
"POST /SASjsApi/auth/token": {
|
|
@@ -2621,11 +2736,29 @@ var SASjsApi = (() => {
|
|
|
2621
2736
|
// has gone, which a host's store can see and this package cannot.
|
|
2622
2737
|
hostResponses: [404]
|
|
2623
2738
|
},
|
|
2624
|
-
// Auth Config - the providers a host was started with, and an LDAP import
|
|
2625
|
-
|
|
2739
|
+
// Auth Config - the providers a host was started with, and an LDAP import.
|
|
2740
|
+
// Both are administrator routes at the host's mount point, so 401 and the
|
|
2741
|
+
// host's own 500 are host-only statuses; the package answers the body, and
|
|
2742
|
+
// refuses a secret that a host tries to hand it.
|
|
2743
|
+
"GET /SASjsApi/authConfig": {
|
|
2744
|
+
implemented: true,
|
|
2745
|
+
hostResponses: [401, 403, 500],
|
|
2746
|
+
responses: {
|
|
2747
|
+
200: {
|
|
2748
|
+
ldap: {
|
|
2749
|
+
LDAP_URL: "",
|
|
2750
|
+
LDAP_BIND_DN: "",
|
|
2751
|
+
LDAP_USERS_BASE_DN: "",
|
|
2752
|
+
LDAP_GROUPS_BASE_DN: "",
|
|
2753
|
+
LDAP_BIND_PASSWORD_SET: true
|
|
2754
|
+
}
|
|
2755
|
+
}
|
|
2756
|
+
}
|
|
2757
|
+
},
|
|
2626
2758
|
"POST /SASjsApi/authConfig/synchroniseWithLDAP": {
|
|
2627
|
-
implemented:
|
|
2628
|
-
|
|
2759
|
+
implemented: true,
|
|
2760
|
+
hostResponses: [401, 403, 500],
|
|
2761
|
+
responses: { 200: { userCount: 0, groupCount: 0 } }
|
|
2629
2762
|
},
|
|
2630
2763
|
// Client - the OAuth clients the identity store already holds for sign-in
|
|
2631
2764
|
"GET /SASjsApi/client": { implemented: true },
|
|
@@ -3052,6 +3185,58 @@ var SASjsApi = (() => {
|
|
|
3052
3185
|
);
|
|
3053
3186
|
return { status: 200, body: await services.info.info() };
|
|
3054
3187
|
}
|
|
3188
|
+
// ------------------------------------------------- a host's own reports
|
|
3189
|
+
//
|
|
3190
|
+
// The administrator middleware is the host's (sasjs/server mounts
|
|
3191
|
+
// authenticateAccessToken and verifyAdmin ahead of all of these), which is
|
|
3192
|
+
// why their 401 is marked host-only in the overlay. The package answers a
|
|
3193
|
+
// body, and for a log tail the refusals that belong to the name rule.
|
|
3194
|
+
case "GET /SASjsApi/admin/diagnostics": {
|
|
3195
|
+
if (!services.admin)
|
|
3196
|
+
throw new ApiError(
|
|
3197
|
+
501,
|
|
3198
|
+
`This host has no admin service, so it cannot answer ${routeId}.`
|
|
3199
|
+
);
|
|
3200
|
+
return { status: 200, body: await services.admin.diagnostics() };
|
|
3201
|
+
}
|
|
3202
|
+
case "GET /SASjsApi/admin/logs": {
|
|
3203
|
+
if (!services.admin)
|
|
3204
|
+
throw new ApiError(
|
|
3205
|
+
501,
|
|
3206
|
+
`This host has no admin service, so it cannot answer ${routeId}.`
|
|
3207
|
+
);
|
|
3208
|
+
return { status: 200, body: { files: await services.admin.logs() } };
|
|
3209
|
+
}
|
|
3210
|
+
case "GET /SASjsApi/admin/logs/{fileName}": {
|
|
3211
|
+
if (!services.admin)
|
|
3212
|
+
throw new ApiError(
|
|
3213
|
+
501,
|
|
3214
|
+
`This host has no admin service, so it cannot answer ${routeId}.`
|
|
3215
|
+
);
|
|
3216
|
+
return {
|
|
3217
|
+
status: 200,
|
|
3218
|
+
body: await services.admin.logTail(
|
|
3219
|
+
String(params.fileName ?? ""),
|
|
3220
|
+
query.lines
|
|
3221
|
+
)
|
|
3222
|
+
};
|
|
3223
|
+
}
|
|
3224
|
+
case "GET /SASjsApi/authConfig": {
|
|
3225
|
+
if (!services.authConfig)
|
|
3226
|
+
throw new ApiError(
|
|
3227
|
+
501,
|
|
3228
|
+
`This host has no auth-config service, so it cannot answer ${routeId}.`
|
|
3229
|
+
);
|
|
3230
|
+
return { status: 200, body: await services.authConfig.authConfig() };
|
|
3231
|
+
}
|
|
3232
|
+
case "POST /SASjsApi/authConfig/synchroniseWithLDAP": {
|
|
3233
|
+
if (!services.directory)
|
|
3234
|
+
throw new ApiError(
|
|
3235
|
+
501,
|
|
3236
|
+
`This host has no directory service, so it cannot answer ${routeId}.`
|
|
3237
|
+
);
|
|
3238
|
+
return { status: 200, body: await services.directory.synchronise() };
|
|
3239
|
+
}
|
|
3055
3240
|
case "GET /SASjsApi/drive/file": {
|
|
3056
3241
|
const file = await drive.read(String(query._filePath || ""));
|
|
3057
3242
|
return { status: 200, contents: file.contents };
|
|
@@ -3414,6 +3599,11 @@ var SASjsApi = (() => {
|
|
|
3414
3599
|
};
|
|
3415
3600
|
var HANDLED_ROUTES = [
|
|
3416
3601
|
"GET /SASjsApi/info",
|
|
3602
|
+
"GET /SASjsApi/admin/diagnostics",
|
|
3603
|
+
"GET /SASjsApi/admin/logs",
|
|
3604
|
+
"GET /SASjsApi/admin/logs/{fileName}",
|
|
3605
|
+
"GET /SASjsApi/authConfig",
|
|
3606
|
+
"POST /SASjsApi/authConfig/synchroniseWithLDAP",
|
|
3417
3607
|
"POST /SASjsApi/drive/deploy/upload",
|
|
3418
3608
|
"DELETE /SASjsApi/drive/deploy",
|
|
3419
3609
|
"GET /SASjsApi/stp/execute",
|
|
@@ -4050,6 +4240,135 @@ var SASjsApi = (() => {
|
|
|
4050
4240
|
}
|
|
4051
4241
|
];
|
|
4052
4242
|
|
|
4243
|
+
// src/corpus/admin.ts
|
|
4244
|
+
var CORPUS_LOG = {
|
|
4245
|
+
name: "20260101000000.log",
|
|
4246
|
+
sizeBytes: 118,
|
|
4247
|
+
modified: "2026-01-01T00:00:00.000Z"
|
|
4248
|
+
};
|
|
4249
|
+
var CORPUS_LOG_TAIL = {
|
|
4250
|
+
fileName: CORPUS_LOG.name,
|
|
4251
|
+
lines: 1,
|
|
4252
|
+
bytesRead: 118,
|
|
4253
|
+
truncated: false,
|
|
4254
|
+
content: "GET /SASjsApi/info HTTP/1.1 200 118"
|
|
4255
|
+
};
|
|
4256
|
+
var CORPUS_DIAGNOSTICS = {
|
|
4257
|
+
build: { version: "v4.16.2", gitHash: "cda6114", buildDate: null },
|
|
4258
|
+
server: {
|
|
4259
|
+
mode: "desktop",
|
|
4260
|
+
uptimeSeconds: 3600,
|
|
4261
|
+
startedAt: "2026-01-01T00:00:00.000Z",
|
|
4262
|
+
pid: 4242,
|
|
4263
|
+
nodeVersion: "v22.11.0",
|
|
4264
|
+
platform: "linux 5.14.0",
|
|
4265
|
+
arch: "x64",
|
|
4266
|
+
cpuCount: 8,
|
|
4267
|
+
cpuModel: "Intel(R) Xeon(R) CPU",
|
|
4268
|
+
loadAverage: [0.08, 0.11, 0.15],
|
|
4269
|
+
runTimes: ["js"],
|
|
4270
|
+
sasjsRoot: "/sasjs_root"
|
|
4271
|
+
},
|
|
4272
|
+
memory: {
|
|
4273
|
+
rssBytes: 1,
|
|
4274
|
+
heapTotalBytes: 2,
|
|
4275
|
+
heapUsedBytes: 3,
|
|
4276
|
+
externalBytes: 4,
|
|
4277
|
+
systemTotalBytes: 5,
|
|
4278
|
+
systemFreeBytes: 6
|
|
4279
|
+
},
|
|
4280
|
+
filesystem: null,
|
|
4281
|
+
folders: [],
|
|
4282
|
+
logs: {
|
|
4283
|
+
folder: "/sasjs_root/logs",
|
|
4284
|
+
fileCount: 1,
|
|
4285
|
+
totalBytes: 118,
|
|
4286
|
+
newestFile: CORPUS_LOG.name,
|
|
4287
|
+
newestModified: CORPUS_LOG.modified
|
|
4288
|
+
}
|
|
4289
|
+
};
|
|
4290
|
+
var ADMIN_CORPUS = [
|
|
4291
|
+
{
|
|
4292
|
+
id: "admin-diagnostics-answers-the-report",
|
|
4293
|
+
route: "GET /SASjsApi/admin/diagnostics",
|
|
4294
|
+
description: "answers the host diagnostics report field for field",
|
|
4295
|
+
request: {},
|
|
4296
|
+
expect: { status: 200, body: CORPUS_DIAGNOSTICS }
|
|
4297
|
+
},
|
|
4298
|
+
{
|
|
4299
|
+
id: "admin-logs-lists-the-files",
|
|
4300
|
+
route: "GET /SASjsApi/admin/logs",
|
|
4301
|
+
description: "answers the log files the host holds, newest first",
|
|
4302
|
+
request: {},
|
|
4303
|
+
expect: { status: 200, body: { files: [CORPUS_LOG] } }
|
|
4304
|
+
},
|
|
4305
|
+
{
|
|
4306
|
+
id: "admin-log-tail-answers-the-tail",
|
|
4307
|
+
route: "GET /SASjsApi/admin/logs/{fileName}",
|
|
4308
|
+
description: "answers the tail of a log the folder holds",
|
|
4309
|
+
request: { params: { fileName: CORPUS_LOG.name } },
|
|
4310
|
+
expect: { status: 200, body: CORPUS_LOG_TAIL }
|
|
4311
|
+
},
|
|
4312
|
+
{
|
|
4313
|
+
id: "admin-log-tail-refuses-a-traversal",
|
|
4314
|
+
route: "GET /SASjsApi/admin/logs/{fileName}",
|
|
4315
|
+
description: "refuses a name that could resolve outside the log folder, before the host is asked",
|
|
4316
|
+
request: { params: { fileName: "../20260101000000.log" } },
|
|
4317
|
+
expect: { status: 400, error: "Invalid log file name." }
|
|
4318
|
+
},
|
|
4319
|
+
{
|
|
4320
|
+
id: "admin-log-tail-answers-404",
|
|
4321
|
+
route: "GET /SASjsApi/admin/logs/{fileName}",
|
|
4322
|
+
description: "answers 404 for a name the folder does not hold",
|
|
4323
|
+
request: { params: { fileName: "20250101000000.log" } },
|
|
4324
|
+
expect: { status: 404, error: "Log file not found." }
|
|
4325
|
+
}
|
|
4326
|
+
];
|
|
4327
|
+
|
|
4328
|
+
// src/corpus/authconfig.ts
|
|
4329
|
+
var CORPUS_AUTH_CONFIG = {
|
|
4330
|
+
ldap: {
|
|
4331
|
+
url: "ldaps://directory.example:636",
|
|
4332
|
+
bindDn: "cn=admin,dc=example",
|
|
4333
|
+
usersBaseDn: "ou=users,dc=example",
|
|
4334
|
+
groupsBaseDn: "ou=groups,dc=example",
|
|
4335
|
+
bindPasswordSet: true
|
|
4336
|
+
}
|
|
4337
|
+
};
|
|
4338
|
+
var CORPUS_AUTH_CONFIG_BODY = {
|
|
4339
|
+
ldap: {
|
|
4340
|
+
LDAP_URL: "ldaps://directory.example:636",
|
|
4341
|
+
LDAP_BIND_DN: "cn=admin,dc=example",
|
|
4342
|
+
LDAP_USERS_BASE_DN: "ou=users,dc=example",
|
|
4343
|
+
LDAP_GROUPS_BASE_DN: "ou=groups,dc=example",
|
|
4344
|
+
LDAP_BIND_PASSWORD_SET: true
|
|
4345
|
+
}
|
|
4346
|
+
};
|
|
4347
|
+
var AUTH_CONFIG_CORPUS = [
|
|
4348
|
+
{
|
|
4349
|
+
id: "authconfig-answers-the-enabled-provider",
|
|
4350
|
+
route: "GET /SASjsApi/authConfig",
|
|
4351
|
+
description: "answers the enabled provider with the secret reported as a boolean, never as a value",
|
|
4352
|
+
request: {},
|
|
4353
|
+
expect: { status: 200, body: CORPUS_AUTH_CONFIG_BODY }
|
|
4354
|
+
}
|
|
4355
|
+
];
|
|
4356
|
+
|
|
4357
|
+
// src/corpus/directory.ts
|
|
4358
|
+
var CORPUS_DIRECTORY = {
|
|
4359
|
+
users: async () => [{ username: "alice", displayName: "Alice" }],
|
|
4360
|
+
groups: async () => [{ name: "analysts" }]
|
|
4361
|
+
};
|
|
4362
|
+
var DIRECTORY_CORPUS = [
|
|
4363
|
+
{
|
|
4364
|
+
id: "directory-imports-the-missing-accounts",
|
|
4365
|
+
route: "POST /SASjsApi/authConfig/synchroniseWithLDAP",
|
|
4366
|
+
description: "imports the users and groups the store does not hold, and counts them",
|
|
4367
|
+
request: {},
|
|
4368
|
+
expect: { status: 200, body: { userCount: 1, groupCount: 1 } }
|
|
4369
|
+
}
|
|
4370
|
+
];
|
|
4371
|
+
|
|
4053
4372
|
// src/info/service.ts
|
|
4054
4373
|
var BROWSER_INFO = {
|
|
4055
4374
|
mode: "desktop",
|
|
@@ -4073,6 +4392,8 @@ var SASjsApi = (() => {
|
|
|
4073
4392
|
"version"
|
|
4074
4393
|
];
|
|
4075
4394
|
var REQUIRED_FIELDS = FIELDS.filter((field) => field !== "oidcProviderName");
|
|
4395
|
+
var MODES = ["server", "desktop"];
|
|
4396
|
+
var CORS_VALUES = ["enable", "disable"];
|
|
4076
4397
|
var isNonEmptyString = (value) => typeof value === "string" && value.length > 0;
|
|
4077
4398
|
var portOf = (value, name) => {
|
|
4078
4399
|
if (value === null || value === void 0) return null;
|
|
@@ -4112,14 +4433,14 @@ var SASjsApi = (() => {
|
|
|
4112
4433
|
`The info configuration does not state \`${key}\`, which the document requires. A client validating the response refuses an answer that omits it.`
|
|
4113
4434
|
);
|
|
4114
4435
|
const mode = config.mode;
|
|
4115
|
-
if (!
|
|
4436
|
+
if (!MODES.includes(mode))
|
|
4116
4437
|
throw new Error(
|
|
4117
|
-
`The info configuration states mode as ${JSON.stringify(mode)}; the document states
|
|
4438
|
+
`The info configuration states mode as ${JSON.stringify(mode)}; the document states the ModeType enum - ${MODES.map((value) => `\`${value}\``).join(" or ")}.`
|
|
4118
4439
|
);
|
|
4119
4440
|
const cors = config.cors;
|
|
4120
|
-
if (!
|
|
4441
|
+
if (!CORS_VALUES.includes(cors))
|
|
4121
4442
|
throw new Error(
|
|
4122
|
-
`The info configuration states cors as ${JSON.stringify(cors)}; the document states the
|
|
4443
|
+
`The info configuration states cors as ${JSON.stringify(cors)}; the document states the CorsType enum - ${CORS_VALUES.map((value) => `\`${value}\``).join(" or ")}.`
|
|
4123
4444
|
);
|
|
4124
4445
|
const version = config.version;
|
|
4125
4446
|
if (!isNonEmptyString(version) || version.trim() === "")
|
|
@@ -4531,7 +4852,8 @@ var SASjsApi = (() => {
|
|
|
4531
4852
|
name: input.name,
|
|
4532
4853
|
description: input.description,
|
|
4533
4854
|
isActive: input.isActive,
|
|
4534
|
-
users: []
|
|
4855
|
+
users: [],
|
|
4856
|
+
...input.authProvider === void 0 ? {} : { authProvider: input.authProvider }
|
|
4535
4857
|
};
|
|
4536
4858
|
this.groupList.set(group.uid, group);
|
|
4537
4859
|
return group;
|
|
@@ -7329,6 +7651,376 @@ var SASjsApi = (() => {
|
|
|
7329
7651
|
}
|
|
7330
7652
|
];
|
|
7331
7653
|
|
|
7654
|
+
// src/authconfig/service.ts
|
|
7655
|
+
var LDAP_FIELDS = [
|
|
7656
|
+
"url",
|
|
7657
|
+
"bindDn",
|
|
7658
|
+
"usersBaseDn",
|
|
7659
|
+
"groupsBaseDn",
|
|
7660
|
+
"bindPasswordSet"
|
|
7661
|
+
];
|
|
7662
|
+
var OIDC_FIELDS = [
|
|
7663
|
+
"providerName",
|
|
7664
|
+
"issuerUrl",
|
|
7665
|
+
"clientId",
|
|
7666
|
+
"redirectUri",
|
|
7667
|
+
"scope",
|
|
7668
|
+
"signingAlg",
|
|
7669
|
+
"usernameClaim",
|
|
7670
|
+
"jitProvision",
|
|
7671
|
+
"clientSecretSet"
|
|
7672
|
+
];
|
|
7673
|
+
var SECRET = /(password|secret|passwd|token)/i;
|
|
7674
|
+
var checkProvider = (name, block, fields, booleans) => {
|
|
7675
|
+
if (!block || typeof block !== "object")
|
|
7676
|
+
throw new Error(
|
|
7677
|
+
`The auth configuration states \`${name}\` as ${JSON.stringify(block)}; a provider is an object, or absent when it is not enabled.`
|
|
7678
|
+
);
|
|
7679
|
+
for (const key of Object.keys(block)) {
|
|
7680
|
+
if (!fields.includes(key))
|
|
7681
|
+
throw new Error(
|
|
7682
|
+
SECRET.test(key) ? `The auth configuration states \`${name}.${key}\`, which looks like a secret. Secrets are never echoed by this route: pass \`${key}Set: true\` instead, so the answer carries whether one is configured and not the value.` : `The auth configuration carries \`${name}.${key}\`, which the document's example does not state. Remove it, or add it to the provider's fields here and to the document.`
|
|
7683
|
+
);
|
|
7684
|
+
}
|
|
7685
|
+
for (const key of fields) {
|
|
7686
|
+
if (!(key in block))
|
|
7687
|
+
throw new Error(
|
|
7688
|
+
`The auth configuration does not state \`${name}.${key}\`, which the administration interface reads. State the empty string when the host has no value for it.`
|
|
7689
|
+
);
|
|
7690
|
+
const value = block[key];
|
|
7691
|
+
if (booleans.includes(key)) {
|
|
7692
|
+
if (typeof value !== "boolean")
|
|
7693
|
+
throw new Error(
|
|
7694
|
+
`The auth configuration states \`${name}.${key}\` as ${JSON.stringify(value)}; it says whether the secret is configured, so it is a boolean.`
|
|
7695
|
+
);
|
|
7696
|
+
} else if (typeof value !== "string")
|
|
7697
|
+
throw new Error(
|
|
7698
|
+
`The auth configuration states \`${name}.${key}\` as ${JSON.stringify(value)}; the document states a string.`
|
|
7699
|
+
);
|
|
7700
|
+
}
|
|
7701
|
+
};
|
|
7702
|
+
var normaliseAuthConfig = (config) => {
|
|
7703
|
+
if (!config || typeof config !== "object")
|
|
7704
|
+
throw new Error("The auth configuration is not an object.");
|
|
7705
|
+
for (const key of Object.keys(config))
|
|
7706
|
+
if (key !== "ldap" && key !== "oidc")
|
|
7707
|
+
throw new Error(
|
|
7708
|
+
SECRET.test(key) ? `The auth configuration states \`${key}\` at the top level, which looks like a secret. Secrets are never echoed by this route; put the provider under \`ldap\` or \`oidc\` and report whether the secret is set.` : `The auth configuration carries \`${key}\`, which is not a provider this API has. The document states \`ldap\` and \`oidc\`.`
|
|
7709
|
+
);
|
|
7710
|
+
const answer = {};
|
|
7711
|
+
if (config.ldap !== void 0) {
|
|
7712
|
+
checkProvider("ldap", config.ldap, LDAP_FIELDS, ["bindPasswordSet"]);
|
|
7713
|
+
answer.ldap = {
|
|
7714
|
+
LDAP_URL: config.ldap.url,
|
|
7715
|
+
LDAP_BIND_DN: config.ldap.bindDn,
|
|
7716
|
+
LDAP_USERS_BASE_DN: config.ldap.usersBaseDn,
|
|
7717
|
+
LDAP_GROUPS_BASE_DN: config.ldap.groupsBaseDn,
|
|
7718
|
+
LDAP_BIND_PASSWORD_SET: config.ldap.bindPasswordSet
|
|
7719
|
+
};
|
|
7720
|
+
}
|
|
7721
|
+
if (config.oidc !== void 0) {
|
|
7722
|
+
checkProvider("oidc", config.oidc, OIDC_FIELDS, ["clientSecretSet"]);
|
|
7723
|
+
answer.oidc = {
|
|
7724
|
+
OIDC_PROVIDER_NAME: config.oidc.providerName,
|
|
7725
|
+
OIDC_ISSUER_URL: config.oidc.issuerUrl,
|
|
7726
|
+
OIDC_CLIENT_ID: config.oidc.clientId,
|
|
7727
|
+
OIDC_REDIRECT_URI: config.oidc.redirectUri,
|
|
7728
|
+
OIDC_SCOPE: config.oidc.scope,
|
|
7729
|
+
OIDC_SIGNING_ALG: config.oidc.signingAlg,
|
|
7730
|
+
OIDC_USERNAME_CLAIM: config.oidc.usernameClaim,
|
|
7731
|
+
OIDC_JIT_PROVISION: config.oidc.jitProvision,
|
|
7732
|
+
OIDC_CLIENT_SECRET_SET: config.oidc.clientSecretSet
|
|
7733
|
+
};
|
|
7734
|
+
}
|
|
7735
|
+
return answer;
|
|
7736
|
+
};
|
|
7737
|
+
var createAuthConfigService = (config) => {
|
|
7738
|
+
const read = () => typeof config === "function" ? config() : config;
|
|
7739
|
+
return {
|
|
7740
|
+
async authConfig() {
|
|
7741
|
+
return normaliseAuthConfig(read());
|
|
7742
|
+
}
|
|
7743
|
+
};
|
|
7744
|
+
};
|
|
7745
|
+
|
|
7746
|
+
// src/admin/service.ts
|
|
7747
|
+
var DEFAULT_LOG_LINES = 200;
|
|
7748
|
+
var MAX_LOG_LINES = 5e3;
|
|
7749
|
+
var isObject = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
7750
|
+
var isNumber = (value) => typeof value === "number" && Number.isFinite(value);
|
|
7751
|
+
var isString = (value) => typeof value === "string";
|
|
7752
|
+
var requireString = (holder, key, where) => {
|
|
7753
|
+
if (!isString(holder[key]))
|
|
7754
|
+
throw new Error(
|
|
7755
|
+
`The ${where} report states \`${key}\` as ${JSON.stringify(holder[key])}; the document states a string, and a client that renders it would print the value as it stands.`
|
|
7756
|
+
);
|
|
7757
|
+
};
|
|
7758
|
+
var requireNumber = (holder, key, where) => {
|
|
7759
|
+
if (!isNumber(holder[key]))
|
|
7760
|
+
throw new Error(
|
|
7761
|
+
`The ${where} report states \`${key}\` as ${JSON.stringify(holder[key])}; the document states a number, and a client that renders it would print NaN.`
|
|
7762
|
+
);
|
|
7763
|
+
};
|
|
7764
|
+
var requireObject = (holder, key, where) => {
|
|
7765
|
+
const value = holder[key];
|
|
7766
|
+
if (!isObject(value))
|
|
7767
|
+
throw new Error(
|
|
7768
|
+
`The ${where} report states \`${key}\` as ${JSON.stringify(value)}; the document states an object.`
|
|
7769
|
+
);
|
|
7770
|
+
return value;
|
|
7771
|
+
};
|
|
7772
|
+
var normaliseDiagnostics = (report) => {
|
|
7773
|
+
if (!isObject(report))
|
|
7774
|
+
throw new Error("The diagnostics report is not an object.");
|
|
7775
|
+
const build = requireObject(
|
|
7776
|
+
report,
|
|
7777
|
+
"build",
|
|
7778
|
+
"diagnostics"
|
|
7779
|
+
);
|
|
7780
|
+
requireString(build, "version", "diagnostics build");
|
|
7781
|
+
requireString(build, "gitHash", "diagnostics build");
|
|
7782
|
+
if (!(build.buildDate === null || isString(build.buildDate)))
|
|
7783
|
+
throw new Error(
|
|
7784
|
+
`The diagnostics build states \`buildDate\` as ${JSON.stringify(build.buildDate)}; the document states an ISO timestamp or null.`
|
|
7785
|
+
);
|
|
7786
|
+
const server = requireObject(
|
|
7787
|
+
report,
|
|
7788
|
+
"server",
|
|
7789
|
+
"diagnostics"
|
|
7790
|
+
);
|
|
7791
|
+
requireString(server, "mode", "diagnostics server");
|
|
7792
|
+
requireString(server, "startedAt", "diagnostics server");
|
|
7793
|
+
requireString(server, "nodeVersion", "diagnostics server");
|
|
7794
|
+
requireString(server, "platform", "diagnostics server");
|
|
7795
|
+
requireString(server, "arch", "diagnostics server");
|
|
7796
|
+
requireString(server, "cpuModel", "diagnostics server");
|
|
7797
|
+
requireString(server, "sasjsRoot", "diagnostics server");
|
|
7798
|
+
requireNumber(server, "uptimeSeconds", "diagnostics server");
|
|
7799
|
+
requireNumber(server, "pid", "diagnostics server");
|
|
7800
|
+
requireNumber(server, "cpuCount", "diagnostics server");
|
|
7801
|
+
if (!Array.isArray(server.loadAverage) || !server.loadAverage.every(isNumber))
|
|
7802
|
+
throw new Error(
|
|
7803
|
+
"The diagnostics server report states `loadAverage` as something other than an array of numbers."
|
|
7804
|
+
);
|
|
7805
|
+
if (!Array.isArray(server.runTimes) || !server.runTimes.every(isString))
|
|
7806
|
+
throw new Error(
|
|
7807
|
+
"The diagnostics server report states `runTimes` as something other than an array of strings."
|
|
7808
|
+
);
|
|
7809
|
+
const memory = requireObject(
|
|
7810
|
+
report,
|
|
7811
|
+
"memory",
|
|
7812
|
+
"diagnostics"
|
|
7813
|
+
);
|
|
7814
|
+
for (const key of [
|
|
7815
|
+
"rssBytes",
|
|
7816
|
+
"heapTotalBytes",
|
|
7817
|
+
"heapUsedBytes",
|
|
7818
|
+
"externalBytes",
|
|
7819
|
+
"systemTotalBytes",
|
|
7820
|
+
"systemFreeBytes"
|
|
7821
|
+
])
|
|
7822
|
+
requireNumber(memory, key, "diagnostics memory");
|
|
7823
|
+
const filesystem = report.filesystem;
|
|
7824
|
+
if (filesystem !== null) {
|
|
7825
|
+
if (!isObject(filesystem))
|
|
7826
|
+
throw new Error(
|
|
7827
|
+
`The diagnostics report states \`filesystem\` as ${JSON.stringify(filesystem)}; the document states an object or null.`
|
|
7828
|
+
);
|
|
7829
|
+
requireString(
|
|
7830
|
+
filesystem,
|
|
7831
|
+
"path",
|
|
7832
|
+
"diagnostics filesystem"
|
|
7833
|
+
);
|
|
7834
|
+
for (const key of ["totalBytes", "freeBytes", "usedBytes", "usedPercent"])
|
|
7835
|
+
requireNumber(
|
|
7836
|
+
filesystem,
|
|
7837
|
+
key,
|
|
7838
|
+
"diagnostics filesystem"
|
|
7839
|
+
);
|
|
7840
|
+
}
|
|
7841
|
+
if (!Array.isArray(report.folders))
|
|
7842
|
+
throw new Error(
|
|
7843
|
+
"The diagnostics report states `folders` as something other than an array."
|
|
7844
|
+
);
|
|
7845
|
+
for (const folder of report.folders) {
|
|
7846
|
+
if (!isObject(folder))
|
|
7847
|
+
throw new Error(
|
|
7848
|
+
"The diagnostics report carries a folder that is not an object."
|
|
7849
|
+
);
|
|
7850
|
+
const entry = folder;
|
|
7851
|
+
requireString(entry, "label", "diagnostics folder");
|
|
7852
|
+
requireString(entry, "path", "diagnostics folder");
|
|
7853
|
+
requireNumber(entry, "bytes", "diagnostics folder");
|
|
7854
|
+
requireNumber(entry, "files", "diagnostics folder");
|
|
7855
|
+
if (typeof entry.exists !== "boolean" || typeof entry.truncated !== "boolean")
|
|
7856
|
+
throw new Error(
|
|
7857
|
+
"The diagnostics folder report states `exists` or `truncated` as something other than a boolean."
|
|
7858
|
+
);
|
|
7859
|
+
}
|
|
7860
|
+
const logs = requireObject(
|
|
7861
|
+
report,
|
|
7862
|
+
"logs",
|
|
7863
|
+
"diagnostics"
|
|
7864
|
+
);
|
|
7865
|
+
requireString(logs, "folder", "diagnostics logs");
|
|
7866
|
+
requireNumber(logs, "fileCount", "diagnostics logs");
|
|
7867
|
+
requireNumber(logs, "totalBytes", "diagnostics logs");
|
|
7868
|
+
for (const key of ["newestFile", "newestModified"])
|
|
7869
|
+
if (!(logs[key] === null || isString(logs[key])))
|
|
7870
|
+
throw new Error(
|
|
7871
|
+
`The diagnostics logs summary states \`${key}\` as ${JSON.stringify(logs[key])}; the document states a string or null.`
|
|
7872
|
+
);
|
|
7873
|
+
return report;
|
|
7874
|
+
};
|
|
7875
|
+
var normaliseLogFiles = (files) => {
|
|
7876
|
+
if (!Array.isArray(files))
|
|
7877
|
+
throw new Error("The log report is not an array of files.");
|
|
7878
|
+
return files.map((file) => {
|
|
7879
|
+
if (!isObject(file))
|
|
7880
|
+
throw new Error("The log report carries an entry that is not an object.");
|
|
7881
|
+
const entry = file;
|
|
7882
|
+
requireString(entry, "name", "logs");
|
|
7883
|
+
requireString(entry, "modified", "logs");
|
|
7884
|
+
requireNumber(entry, "sizeBytes", "logs");
|
|
7885
|
+
return file;
|
|
7886
|
+
});
|
|
7887
|
+
};
|
|
7888
|
+
var checkLogFileName = (fileName) => {
|
|
7889
|
+
if (!fileName || fileName.includes("/") || fileName.includes("\\") || fileName.split(/[\\/]/).pop() !== fileName || !fileName.toLowerCase().endsWith(".log"))
|
|
7890
|
+
throw new ApiError(400, "Invalid log file name.");
|
|
7891
|
+
return fileName;
|
|
7892
|
+
};
|
|
7893
|
+
var logLines = (lines) => {
|
|
7894
|
+
if (lines === void 0 || lines === null || lines === "")
|
|
7895
|
+
return DEFAULT_LOG_LINES;
|
|
7896
|
+
const wanted = Number(lines);
|
|
7897
|
+
if (!Number.isFinite(wanted)) return DEFAULT_LOG_LINES;
|
|
7898
|
+
return Math.min(Math.max(Math.trunc(wanted), 1), MAX_LOG_LINES);
|
|
7899
|
+
};
|
|
7900
|
+
var normaliseLogTail = (tail) => {
|
|
7901
|
+
if (!isObject(tail)) throw new Error("The log tail report is not an object.");
|
|
7902
|
+
const entry = tail;
|
|
7903
|
+
requireString(entry, "fileName", "log tail");
|
|
7904
|
+
requireString(entry, "content", "log tail");
|
|
7905
|
+
requireNumber(entry, "lines", "log tail");
|
|
7906
|
+
requireNumber(entry, "bytesRead", "log tail");
|
|
7907
|
+
if (typeof entry.truncated !== "boolean")
|
|
7908
|
+
throw new Error(
|
|
7909
|
+
"The log tail report states `truncated` as something other than a boolean."
|
|
7910
|
+
);
|
|
7911
|
+
return tail;
|
|
7912
|
+
};
|
|
7913
|
+
var createAdminService = (reports) => ({
|
|
7914
|
+
async diagnostics() {
|
|
7915
|
+
return normaliseDiagnostics(await reports.diagnostics());
|
|
7916
|
+
},
|
|
7917
|
+
async logs() {
|
|
7918
|
+
return normaliseLogFiles(await reports.logs());
|
|
7919
|
+
},
|
|
7920
|
+
async logTail(fileName, lines) {
|
|
7921
|
+
const name = checkLogFileName(fileName);
|
|
7922
|
+
const tail = await reports.logTail(name, logLines(lines));
|
|
7923
|
+
if (tail === void 0) throw new ApiError(404, "Log file not found.");
|
|
7924
|
+
return normaliseLogTail(tail);
|
|
7925
|
+
}
|
|
7926
|
+
});
|
|
7927
|
+
|
|
7928
|
+
// src/directory/service.ts
|
|
7929
|
+
var isNonEmptyString2 = (value) => typeof value === "string" && value.length > 0;
|
|
7930
|
+
var usersOf = (users) => {
|
|
7931
|
+
if (!Array.isArray(users))
|
|
7932
|
+
throw new Error("The directory answer has no users array.");
|
|
7933
|
+
const seen = /* @__PURE__ */ new Set();
|
|
7934
|
+
for (const user3 of users) {
|
|
7935
|
+
if (!isNonEmptyString2(user3?.username) || !isNonEmptyString2(user3?.displayName))
|
|
7936
|
+
throw new Error(
|
|
7937
|
+
`The directory answer carries a user without a username or displayName: ${JSON.stringify(user3)}. Both are what the API keys an account on, so the import cannot guess them.`
|
|
7938
|
+
);
|
|
7939
|
+
if (seen.has(user3.username))
|
|
7940
|
+
throw new Error(
|
|
7941
|
+
`The directory answer names ${user3.username} twice. A directory that returns one account twice is a filter problem, and importing it would hide that.`
|
|
7942
|
+
);
|
|
7943
|
+
seen.add(user3.username);
|
|
7944
|
+
}
|
|
7945
|
+
return users;
|
|
7946
|
+
};
|
|
7947
|
+
var groupsOf = (groups) => {
|
|
7948
|
+
if (!Array.isArray(groups))
|
|
7949
|
+
throw new Error("The directory answer has no groups array.");
|
|
7950
|
+
const seen = /* @__PURE__ */ new Set();
|
|
7951
|
+
for (const group of groups) {
|
|
7952
|
+
if (!isNonEmptyString2(group?.name))
|
|
7953
|
+
throw new Error(
|
|
7954
|
+
`The directory answer carries a group without a name: ${JSON.stringify(group)}.`
|
|
7955
|
+
);
|
|
7956
|
+
if (seen.has(group.name))
|
|
7957
|
+
throw new Error(
|
|
7958
|
+
`The directory answer names the group ${group.name} twice, which would apply its members twice.`
|
|
7959
|
+
);
|
|
7960
|
+
seen.add(group.name);
|
|
7961
|
+
}
|
|
7962
|
+
return groups;
|
|
7963
|
+
};
|
|
7964
|
+
var createDirectoryService = (store, source, options = {}) => {
|
|
7965
|
+
const provider = options.provider || "ldap";
|
|
7966
|
+
return {
|
|
7967
|
+
async synchronise() {
|
|
7968
|
+
const directoryUsers = usersOf(await source.users());
|
|
7969
|
+
const directoryGroups = groupsOf(await source.groups());
|
|
7970
|
+
const existingUsers = await store.users();
|
|
7971
|
+
const existingGroups = await store.groups();
|
|
7972
|
+
const userByName = new Map(
|
|
7973
|
+
existingUsers.map((user3) => [user3.username, user3])
|
|
7974
|
+
);
|
|
7975
|
+
const groupByName = new Map(
|
|
7976
|
+
existingGroups.map((group) => [group.name, group])
|
|
7977
|
+
);
|
|
7978
|
+
const imported = [];
|
|
7979
|
+
for (const user3 of directoryUsers) {
|
|
7980
|
+
if (userByName.has(user3.username)) continue;
|
|
7981
|
+
const created = await store.createUser({
|
|
7982
|
+
username: user3.username,
|
|
7983
|
+
displayName: user3.displayName,
|
|
7984
|
+
isAdmin: false,
|
|
7985
|
+
isActive: true,
|
|
7986
|
+
authProvider: provider
|
|
7987
|
+
});
|
|
7988
|
+
userByName.set(created.username, created);
|
|
7989
|
+
imported.push(created);
|
|
7990
|
+
}
|
|
7991
|
+
const importedGroups = [];
|
|
7992
|
+
for (const group of directoryGroups) {
|
|
7993
|
+
if (groupByName.has(group.name)) continue;
|
|
7994
|
+
const created = await store.createGroup({
|
|
7995
|
+
name: group.name,
|
|
7996
|
+
description: "",
|
|
7997
|
+
isActive: true,
|
|
7998
|
+
authProvider: provider
|
|
7999
|
+
});
|
|
8000
|
+
groupByName.set(created.name, created);
|
|
8001
|
+
importedGroups.push(created);
|
|
8002
|
+
}
|
|
8003
|
+
const membersOf = /* @__PURE__ */ new Map();
|
|
8004
|
+
const note = (groupName, username) => {
|
|
8005
|
+
const members = membersOf.get(groupName) || /* @__PURE__ */ new Set();
|
|
8006
|
+
members.add(username);
|
|
8007
|
+
membersOf.set(groupName, members);
|
|
8008
|
+
};
|
|
8009
|
+
for (const group of directoryGroups)
|
|
8010
|
+
for (const member of group.members || []) note(group.name, member);
|
|
8011
|
+
for (const user3 of directoryUsers)
|
|
8012
|
+
for (const groupName of user3.groups || [])
|
|
8013
|
+
note(groupName, user3.username);
|
|
8014
|
+
for (const group of importedGroups)
|
|
8015
|
+
for (const username of membersOf.get(group.name) || []) {
|
|
8016
|
+
const user3 = userByName.get(username);
|
|
8017
|
+
if (user3) await store.addToGroup(group.uid, user3.uid);
|
|
8018
|
+
}
|
|
8019
|
+
return { userCount: imported.length, groupCount: importedGroups.length };
|
|
8020
|
+
}
|
|
8021
|
+
};
|
|
8022
|
+
};
|
|
8023
|
+
|
|
7332
8024
|
// src/corpus/runner.ts
|
|
7333
8025
|
var servicesFor = (testCase) => {
|
|
7334
8026
|
const identity = new MemoryIdentityStore(
|
|
@@ -7343,6 +8035,13 @@ var SASjsApi = (() => {
|
|
|
7343
8035
|
testCase.unwritable ? new RefusingDriveStore(testCase.seed || {}) : new MemoryDriveStore(testCase.seed || {})
|
|
7344
8036
|
),
|
|
7345
8037
|
info: createInfoService(BROWSER_INFO),
|
|
8038
|
+
authConfig: createAuthConfigService(CORPUS_AUTH_CONFIG),
|
|
8039
|
+
admin: createAdminService({
|
|
8040
|
+
diagnostics: async () => CORPUS_DIAGNOSTICS,
|
|
8041
|
+
logs: async () => [CORPUS_LOG],
|
|
8042
|
+
logTail: async (fileName) => fileName === CORPUS_LOG.name ? CORPUS_LOG_TAIL : void 0
|
|
8043
|
+
}),
|
|
8044
|
+
directory: createDirectoryService(identity, CORPUS_DIRECTORY),
|
|
7346
8045
|
identity: createIdentityService(identity),
|
|
7347
8046
|
records: createRecordService(identity),
|
|
7348
8047
|
registry: new MemoryAppStreamRegistry(),
|