@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
package/build/browser.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* @sasjs/api 0.
|
|
1
|
+
/* @sasjs/api 0.20.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,10 +22,13 @@ 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,
|
|
31
|
+
BUNDLE_NAME: () => BUNDLE_NAME,
|
|
29
32
|
CODE_CORPUS: () => CODE_CORPUS,
|
|
30
33
|
CODE_DEBUG: () => CODE_DEBUG,
|
|
31
34
|
DEFAULT_GRANTABLE_ROUTES: () => DEFAULT_GRANTABLE_ROUTES,
|
|
@@ -35,9 +38,11 @@ var SASjsApi = (() => {
|
|
|
35
38
|
DEPLOY_LIMITS: () => DEPLOY_LIMITS,
|
|
36
39
|
DEPLOY_PAYLOAD_BYTES: () => DEPLOY_PAYLOAD_BYTES,
|
|
37
40
|
DEPLOY_SUCCESS: () => DEPLOY_SUCCESS,
|
|
41
|
+
DIRECTORY_CORPUS: () => DIRECTORY_CORPUS,
|
|
38
42
|
DOCUMENTED_RUN_TIMES: () => DOCUMENTED_RUN_TIMES,
|
|
39
43
|
DRIVE_CORPUS: () => DRIVE_CORPUS,
|
|
40
44
|
HANDLED_ROUTES: () => HANDLED_ROUTES,
|
|
45
|
+
HOME_CORPUS: () => HOME_CORPUS,
|
|
41
46
|
IDENTITY_CORPUS: () => IDENTITY_CORPUS,
|
|
42
47
|
IDENTITY_FORMAT: () => IDENTITY_FORMAT,
|
|
43
48
|
INFO_CORPUS: () => INFO_CORPUS,
|
|
@@ -46,6 +51,7 @@ var SASjsApi = (() => {
|
|
|
46
51
|
MemoryIdentityStore: () => MemoryIdentityStore,
|
|
47
52
|
MemorySessionHost: () => MemorySessionHost,
|
|
48
53
|
MemorySessionRunner: () => MemorySessionRunner,
|
|
54
|
+
NO_WEB_BUILD: () => NO_WEB_BUILD,
|
|
49
55
|
OVERLAY: () => OVERLAY,
|
|
50
56
|
PROVIDER_MANAGED: () => PROVIDER_MANAGED,
|
|
51
57
|
RECORD_CORPUS: () => RECORD_CORPUS,
|
|
@@ -58,6 +64,7 @@ var SASjsApi = (() => {
|
|
|
58
64
|
basename: () => basename,
|
|
59
65
|
checkDeployTree: () => checkDeployTree,
|
|
60
66
|
createDriveService: () => createDriveService,
|
|
67
|
+
createHomeService: () => createHomeService,
|
|
61
68
|
createIdentityService: () => createIdentityService,
|
|
62
69
|
createInfoService: () => createInfoService,
|
|
63
70
|
createRecordService: () => createRecordService,
|
|
@@ -82,7 +89,8 @@ var SASjsApi = (() => {
|
|
|
82
89
|
sanitiseDisplayName: () => sanitiseDisplayName,
|
|
83
90
|
servicesFor: () => servicesFor,
|
|
84
91
|
topLevelRouteFor: () => topLevelRouteFor,
|
|
85
|
-
unpublishAppStream: () => unpublishAppStream
|
|
92
|
+
unpublishAppStream: () => unpublishAppStream,
|
|
93
|
+
withBundleVersion: () => withBundleVersion
|
|
86
94
|
});
|
|
87
95
|
|
|
88
96
|
// src/types.ts
|
|
@@ -590,6 +598,14 @@ var SASjsApi = (() => {
|
|
|
590
598
|
{
|
|
591
599
|
status: 200,
|
|
592
600
|
description: "Ok"
|
|
601
|
+
},
|
|
602
|
+
{
|
|
603
|
+
status: 401,
|
|
604
|
+
description: "Unauthorized, or an administrator account is required. The mount point in routes/api/index.ts applies both checks before this handler runs."
|
|
605
|
+
},
|
|
606
|
+
{
|
|
607
|
+
status: 500,
|
|
608
|
+
description: "The diagnostics could not be read"
|
|
593
609
|
}
|
|
594
610
|
]
|
|
595
611
|
},
|
|
@@ -605,6 +621,14 @@ var SASjsApi = (() => {
|
|
|
605
621
|
{
|
|
606
622
|
status: 200,
|
|
607
623
|
description: "Ok"
|
|
624
|
+
},
|
|
625
|
+
{
|
|
626
|
+
status: 401,
|
|
627
|
+
description: "Unauthorized, or an administrator account is required. The mount point in routes/api/index.ts applies both checks before this handler runs."
|
|
628
|
+
},
|
|
629
|
+
{
|
|
630
|
+
status: 500,
|
|
631
|
+
description: "The log folder could not be listed"
|
|
608
632
|
}
|
|
609
633
|
]
|
|
610
634
|
},
|
|
@@ -633,6 +657,22 @@ var SASjsApi = (() => {
|
|
|
633
657
|
{
|
|
634
658
|
status: 200,
|
|
635
659
|
description: "Ok"
|
|
660
|
+
},
|
|
661
|
+
{
|
|
662
|
+
status: 400,
|
|
663
|
+
description: "Invalid log file name."
|
|
664
|
+
},
|
|
665
|
+
{
|
|
666
|
+
status: 401,
|
|
667
|
+
description: "Unauthorized, or an administrator account is required. The mount point in routes/api/index.ts applies both checks before this handler runs."
|
|
668
|
+
},
|
|
669
|
+
{
|
|
670
|
+
status: 404,
|
|
671
|
+
description: "Log file not found."
|
|
672
|
+
},
|
|
673
|
+
{
|
|
674
|
+
status: 500,
|
|
675
|
+
description: "The log file could not be read"
|
|
636
676
|
}
|
|
637
677
|
]
|
|
638
678
|
},
|
|
@@ -770,6 +810,18 @@ var SASjsApi = (() => {
|
|
|
770
810
|
{
|
|
771
811
|
status: 200,
|
|
772
812
|
description: "Ok"
|
|
813
|
+
},
|
|
814
|
+
{
|
|
815
|
+
status: 401,
|
|
816
|
+
description: "Unauthorized, or an administrator account is required. The mount point in routes/api/index.ts applies both checks before this handler runs."
|
|
817
|
+
},
|
|
818
|
+
{
|
|
819
|
+
status: 403,
|
|
820
|
+
description: "Not Allowed while in Desktop Mode."
|
|
821
|
+
},
|
|
822
|
+
{
|
|
823
|
+
status: 500,
|
|
824
|
+
description: "The provider configuration could not be read"
|
|
773
825
|
}
|
|
774
826
|
]
|
|
775
827
|
},
|
|
@@ -785,6 +837,18 @@ var SASjsApi = (() => {
|
|
|
785
837
|
{
|
|
786
838
|
status: 200,
|
|
787
839
|
description: "Ok"
|
|
840
|
+
},
|
|
841
|
+
{
|
|
842
|
+
status: 401,
|
|
843
|
+
description: "Unauthorized, or an administrator account is required. The mount point in routes/api/index.ts applies both checks before this handler runs."
|
|
844
|
+
},
|
|
845
|
+
{
|
|
846
|
+
status: 403,
|
|
847
|
+
description: "Not Allowed while in Desktop Mode."
|
|
848
|
+
},
|
|
849
|
+
{
|
|
850
|
+
status: 500,
|
|
851
|
+
description: "The directory could not be synchronised"
|
|
788
852
|
}
|
|
789
853
|
]
|
|
790
854
|
},
|
|
@@ -2567,10 +2631,6 @@ var SASjsApi = (() => {
|
|
|
2567
2631
|
Client: ["identity"],
|
|
2568
2632
|
Web: ["identity"]
|
|
2569
2633
|
};
|
|
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
|
-
var WEB_BUNDLE = "The host serves its own web bundle; there is no API decision here for this package to answer.";
|
|
2574
2634
|
var success = { status: "success" };
|
|
2575
2635
|
var user = {
|
|
2576
2636
|
uid: "",
|
|
@@ -2580,8 +2640,17 @@ var SASjsApi = (() => {
|
|
|
2580
2640
|
needsToUpdatePassword: false
|
|
2581
2641
|
};
|
|
2582
2642
|
var OVERLAY = {
|
|
2583
|
-
// Web - the sign-in pages the identity service answers, and the
|
|
2584
|
-
|
|
2643
|
+
// Web - the sign-in pages the identity service answers, and the shell itself.
|
|
2644
|
+
// The page is the host's file; the stamping rule that keeps a cached shell
|
|
2645
|
+
// from pinning an old bundle is the package's.
|
|
2646
|
+
"GET /": {
|
|
2647
|
+
implemented: true,
|
|
2648
|
+
// public: the shell is what an unauthenticated browser asks for first
|
|
2649
|
+
capabilities: [],
|
|
2650
|
+
responses: {
|
|
2651
|
+
200: "<html><head></head><body>Web Build is not present</body></html>"
|
|
2652
|
+
}
|
|
2653
|
+
},
|
|
2585
2654
|
"POST /SASLogon/login": {
|
|
2586
2655
|
implemented: true,
|
|
2587
2656
|
// The lockout and the provider failure are answered before the package is
|
|
@@ -2598,12 +2667,71 @@ var SASjsApi = (() => {
|
|
|
2598
2667
|
hostResponses: [500],
|
|
2599
2668
|
responses: { 200: "OK!" }
|
|
2600
2669
|
},
|
|
2601
|
-
// Admin - the host's own process and files
|
|
2602
|
-
|
|
2603
|
-
|
|
2670
|
+
// Admin - the host's own process and files, over the reports it supplies.
|
|
2671
|
+
// The administrator check is the host's mount point (sasjs/server puts
|
|
2672
|
+
// authenticateAccessToken and verifyAdmin in front of all three), so its 401
|
|
2673
|
+
// - and the 500 a genuine failure answers - are host-only statuses.
|
|
2674
|
+
"GET /SASjsApi/admin/diagnostics": {
|
|
2675
|
+
implemented: true,
|
|
2676
|
+
hostResponses: [401, 500],
|
|
2677
|
+
responses: {
|
|
2678
|
+
200: {
|
|
2679
|
+
build: { version: "", gitHash: "", buildDate: null },
|
|
2680
|
+
server: {
|
|
2681
|
+
mode: "desktop",
|
|
2682
|
+
uptimeSeconds: 0,
|
|
2683
|
+
startedAt: "",
|
|
2684
|
+
pid: 0,
|
|
2685
|
+
nodeVersion: "",
|
|
2686
|
+
platform: "",
|
|
2687
|
+
arch: "",
|
|
2688
|
+
cpuCount: 0,
|
|
2689
|
+
cpuModel: "",
|
|
2690
|
+
loadAverage: [],
|
|
2691
|
+
runTimes: [],
|
|
2692
|
+
sasjsRoot: ""
|
|
2693
|
+
},
|
|
2694
|
+
memory: {
|
|
2695
|
+
rssBytes: 0,
|
|
2696
|
+
heapTotalBytes: 0,
|
|
2697
|
+
heapUsedBytes: 0,
|
|
2698
|
+
externalBytes: 0,
|
|
2699
|
+
systemTotalBytes: 0,
|
|
2700
|
+
systemFreeBytes: 0
|
|
2701
|
+
},
|
|
2702
|
+
filesystem: null,
|
|
2703
|
+
folders: [],
|
|
2704
|
+
logs: {
|
|
2705
|
+
folder: "",
|
|
2706
|
+
fileCount: 0,
|
|
2707
|
+
totalBytes: 0,
|
|
2708
|
+
newestFile: null,
|
|
2709
|
+
newestModified: null
|
|
2710
|
+
}
|
|
2711
|
+
}
|
|
2712
|
+
}
|
|
2713
|
+
},
|
|
2714
|
+
"GET /SASjsApi/admin/logs": {
|
|
2715
|
+
implemented: true,
|
|
2716
|
+
hostResponses: [401, 500],
|
|
2717
|
+
responses: { 200: { files: [] } }
|
|
2718
|
+
},
|
|
2604
2719
|
"GET /SASjsApi/admin/logs/{fileName}": {
|
|
2605
|
-
implemented:
|
|
2606
|
-
|
|
2720
|
+
implemented: true,
|
|
2721
|
+
// 400 and 404 are the name rule's, and this package answers them before the
|
|
2722
|
+
// host is asked for anything
|
|
2723
|
+
hostResponses: [401, 500],
|
|
2724
|
+
responses: {
|
|
2725
|
+
200: {
|
|
2726
|
+
fileName: "",
|
|
2727
|
+
lines: 0,
|
|
2728
|
+
bytesRead: 0,
|
|
2729
|
+
truncated: false,
|
|
2730
|
+
content: ""
|
|
2731
|
+
},
|
|
2732
|
+
400: "Invalid log file name.",
|
|
2733
|
+
404: "Log file not found."
|
|
2734
|
+
}
|
|
2607
2735
|
},
|
|
2608
2736
|
// Auth - the token flow, plus a password change the identity store cannot write
|
|
2609
2737
|
"POST /SASjsApi/auth/token": {
|
|
@@ -2621,11 +2749,29 @@ var SASjsApi = (() => {
|
|
|
2621
2749
|
// has gone, which a host's store can see and this package cannot.
|
|
2622
2750
|
hostResponses: [404]
|
|
2623
2751
|
},
|
|
2624
|
-
// Auth Config - the providers a host was started with, and an LDAP import
|
|
2625
|
-
|
|
2752
|
+
// Auth Config - the providers a host was started with, and an LDAP import.
|
|
2753
|
+
// Both are administrator routes at the host's mount point, so 401 and the
|
|
2754
|
+
// host's own 500 are host-only statuses; the package answers the body, and
|
|
2755
|
+
// refuses a secret that a host tries to hand it.
|
|
2756
|
+
"GET /SASjsApi/authConfig": {
|
|
2757
|
+
implemented: true,
|
|
2758
|
+
hostResponses: [401, 403, 500],
|
|
2759
|
+
responses: {
|
|
2760
|
+
200: {
|
|
2761
|
+
ldap: {
|
|
2762
|
+
LDAP_URL: "",
|
|
2763
|
+
LDAP_BIND_DN: "",
|
|
2764
|
+
LDAP_USERS_BASE_DN: "",
|
|
2765
|
+
LDAP_GROUPS_BASE_DN: "",
|
|
2766
|
+
LDAP_BIND_PASSWORD_SET: true
|
|
2767
|
+
}
|
|
2768
|
+
}
|
|
2769
|
+
}
|
|
2770
|
+
},
|
|
2626
2771
|
"POST /SASjsApi/authConfig/synchroniseWithLDAP": {
|
|
2627
|
-
implemented:
|
|
2628
|
-
|
|
2772
|
+
implemented: true,
|
|
2773
|
+
hostResponses: [401, 403, 500],
|
|
2774
|
+
responses: { 200: { userCount: 0, groupCount: 0 } }
|
|
2629
2775
|
},
|
|
2630
2776
|
// Client - the OAuth clients the identity store already holds for sign-in
|
|
2631
2777
|
"GET /SASjsApi/client": { implemented: true },
|
|
@@ -3042,6 +3188,17 @@ var SASjsApi = (() => {
|
|
|
3042
3188
|
}
|
|
3043
3189
|
}
|
|
3044
3190
|
switch (routeId) {
|
|
3191
|
+
// The shell is a body, not JSON: an HTML page served with the content type
|
|
3192
|
+
// the document states, as it came from the host (stamped, if it references
|
|
3193
|
+
// a bundle).
|
|
3194
|
+
case "GET /": {
|
|
3195
|
+
if (!services.home)
|
|
3196
|
+
throw new ApiError(
|
|
3197
|
+
501,
|
|
3198
|
+
`This host has no home service, so it cannot answer ${routeId}.`
|
|
3199
|
+
);
|
|
3200
|
+
return { status: 200, contents: await services.home.home() };
|
|
3201
|
+
}
|
|
3045
3202
|
// The one answer a host states rather than derives: public, pre-auth, and
|
|
3046
3203
|
// read by the login screen before anything else.
|
|
3047
3204
|
case "GET /SASjsApi/info": {
|
|
@@ -3052,6 +3209,58 @@ var SASjsApi = (() => {
|
|
|
3052
3209
|
);
|
|
3053
3210
|
return { status: 200, body: await services.info.info() };
|
|
3054
3211
|
}
|
|
3212
|
+
// ------------------------------------------------- a host's own reports
|
|
3213
|
+
//
|
|
3214
|
+
// The administrator middleware is the host's (sasjs/server mounts
|
|
3215
|
+
// authenticateAccessToken and verifyAdmin ahead of all of these), which is
|
|
3216
|
+
// why their 401 is marked host-only in the overlay. The package answers a
|
|
3217
|
+
// body, and for a log tail the refusals that belong to the name rule.
|
|
3218
|
+
case "GET /SASjsApi/admin/diagnostics": {
|
|
3219
|
+
if (!services.admin)
|
|
3220
|
+
throw new ApiError(
|
|
3221
|
+
501,
|
|
3222
|
+
`This host has no admin service, so it cannot answer ${routeId}.`
|
|
3223
|
+
);
|
|
3224
|
+
return { status: 200, body: await services.admin.diagnostics() };
|
|
3225
|
+
}
|
|
3226
|
+
case "GET /SASjsApi/admin/logs": {
|
|
3227
|
+
if (!services.admin)
|
|
3228
|
+
throw new ApiError(
|
|
3229
|
+
501,
|
|
3230
|
+
`This host has no admin service, so it cannot answer ${routeId}.`
|
|
3231
|
+
);
|
|
3232
|
+
return { status: 200, body: { files: await services.admin.logs() } };
|
|
3233
|
+
}
|
|
3234
|
+
case "GET /SASjsApi/admin/logs/{fileName}": {
|
|
3235
|
+
if (!services.admin)
|
|
3236
|
+
throw new ApiError(
|
|
3237
|
+
501,
|
|
3238
|
+
`This host has no admin service, so it cannot answer ${routeId}.`
|
|
3239
|
+
);
|
|
3240
|
+
return {
|
|
3241
|
+
status: 200,
|
|
3242
|
+
body: await services.admin.logTail(
|
|
3243
|
+
String(params.fileName ?? ""),
|
|
3244
|
+
query.lines
|
|
3245
|
+
)
|
|
3246
|
+
};
|
|
3247
|
+
}
|
|
3248
|
+
case "GET /SASjsApi/authConfig": {
|
|
3249
|
+
if (!services.authConfig)
|
|
3250
|
+
throw new ApiError(
|
|
3251
|
+
501,
|
|
3252
|
+
`This host has no auth-config service, so it cannot answer ${routeId}.`
|
|
3253
|
+
);
|
|
3254
|
+
return { status: 200, body: await services.authConfig.authConfig() };
|
|
3255
|
+
}
|
|
3256
|
+
case "POST /SASjsApi/authConfig/synchroniseWithLDAP": {
|
|
3257
|
+
if (!services.directory)
|
|
3258
|
+
throw new ApiError(
|
|
3259
|
+
501,
|
|
3260
|
+
`This host has no directory service, so it cannot answer ${routeId}.`
|
|
3261
|
+
);
|
|
3262
|
+
return { status: 200, body: await services.directory.synchronise() };
|
|
3263
|
+
}
|
|
3055
3264
|
case "GET /SASjsApi/drive/file": {
|
|
3056
3265
|
const file = await drive.read(String(query._filePath || ""));
|
|
3057
3266
|
return { status: 200, contents: file.contents };
|
|
@@ -3403,17 +3612,25 @@ var SASjsApi = (() => {
|
|
|
3403
3612
|
newPassword: String(body.newPassword ?? "")
|
|
3404
3613
|
});
|
|
3405
3614
|
return { status: 204 };
|
|
3406
|
-
default:
|
|
3407
|
-
|
|
3408
|
-
throw new ApiError(
|
|
3409
|
-
501,
|
|
3410
|
-
`This package has no handler for ${routeId}.${reason ? ` ${reason}` : ""}`
|
|
3411
|
-
);
|
|
3412
|
-
}
|
|
3615
|
+
default:
|
|
3616
|
+
throw noHandler(routeId);
|
|
3413
3617
|
}
|
|
3414
3618
|
};
|
|
3619
|
+
var noHandler = (routeId) => {
|
|
3620
|
+
const reason = routeById(routeId)?.reason;
|
|
3621
|
+
return new ApiError(
|
|
3622
|
+
501,
|
|
3623
|
+
`This package has no handler for ${routeId}.${reason ? ` ${reason}` : ""}`
|
|
3624
|
+
);
|
|
3625
|
+
};
|
|
3415
3626
|
var HANDLED_ROUTES = [
|
|
3627
|
+
"GET /",
|
|
3416
3628
|
"GET /SASjsApi/info",
|
|
3629
|
+
"GET /SASjsApi/admin/diagnostics",
|
|
3630
|
+
"GET /SASjsApi/admin/logs",
|
|
3631
|
+
"GET /SASjsApi/admin/logs/{fileName}",
|
|
3632
|
+
"GET /SASjsApi/authConfig",
|
|
3633
|
+
"POST /SASjsApi/authConfig/synchroniseWithLDAP",
|
|
3417
3634
|
"POST /SASjsApi/drive/deploy/upload",
|
|
3418
3635
|
"DELETE /SASjsApi/drive/deploy",
|
|
3419
3636
|
"GET /SASjsApi/stp/execute",
|
|
@@ -4050,6 +4267,201 @@ var SASjsApi = (() => {
|
|
|
4050
4267
|
}
|
|
4051
4268
|
];
|
|
4052
4269
|
|
|
4270
|
+
// src/corpus/admin.ts
|
|
4271
|
+
var CORPUS_LOG = {
|
|
4272
|
+
name: "20260101000000.log",
|
|
4273
|
+
sizeBytes: 118,
|
|
4274
|
+
modified: "2026-01-01T00:00:00.000Z"
|
|
4275
|
+
};
|
|
4276
|
+
var CORPUS_LOG_TAIL = {
|
|
4277
|
+
fileName: CORPUS_LOG.name,
|
|
4278
|
+
lines: 1,
|
|
4279
|
+
bytesRead: 118,
|
|
4280
|
+
truncated: false,
|
|
4281
|
+
content: "GET /SASjsApi/info HTTP/1.1 200 118"
|
|
4282
|
+
};
|
|
4283
|
+
var CORPUS_DIAGNOSTICS = {
|
|
4284
|
+
build: { version: "v4.16.2", gitHash: "cda6114", buildDate: null },
|
|
4285
|
+
server: {
|
|
4286
|
+
mode: "desktop",
|
|
4287
|
+
uptimeSeconds: 3600,
|
|
4288
|
+
startedAt: "2026-01-01T00:00:00.000Z",
|
|
4289
|
+
pid: 4242,
|
|
4290
|
+
nodeVersion: "v22.11.0",
|
|
4291
|
+
platform: "linux 5.14.0",
|
|
4292
|
+
arch: "x64",
|
|
4293
|
+
cpuCount: 8,
|
|
4294
|
+
cpuModel: "Intel(R) Xeon(R) CPU",
|
|
4295
|
+
loadAverage: [0.08, 0.11, 0.15],
|
|
4296
|
+
runTimes: ["js"],
|
|
4297
|
+
sasjsRoot: "/sasjs_root"
|
|
4298
|
+
},
|
|
4299
|
+
memory: {
|
|
4300
|
+
rssBytes: 1,
|
|
4301
|
+
heapTotalBytes: 2,
|
|
4302
|
+
heapUsedBytes: 3,
|
|
4303
|
+
externalBytes: 4,
|
|
4304
|
+
systemTotalBytes: 5,
|
|
4305
|
+
systemFreeBytes: 6
|
|
4306
|
+
},
|
|
4307
|
+
filesystem: null,
|
|
4308
|
+
folders: [],
|
|
4309
|
+
logs: {
|
|
4310
|
+
folder: "/sasjs_root/logs",
|
|
4311
|
+
fileCount: 1,
|
|
4312
|
+
totalBytes: 118,
|
|
4313
|
+
newestFile: CORPUS_LOG.name,
|
|
4314
|
+
newestModified: CORPUS_LOG.modified
|
|
4315
|
+
}
|
|
4316
|
+
};
|
|
4317
|
+
var ADMIN_CORPUS = [
|
|
4318
|
+
{
|
|
4319
|
+
id: "admin-diagnostics-answers-the-report",
|
|
4320
|
+
route: "GET /SASjsApi/admin/diagnostics",
|
|
4321
|
+
description: "answers the host diagnostics report field for field",
|
|
4322
|
+
request: {},
|
|
4323
|
+
expect: { status: 200, body: CORPUS_DIAGNOSTICS }
|
|
4324
|
+
},
|
|
4325
|
+
{
|
|
4326
|
+
id: "admin-logs-lists-the-files",
|
|
4327
|
+
route: "GET /SASjsApi/admin/logs",
|
|
4328
|
+
description: "answers the log files the host holds, newest first",
|
|
4329
|
+
request: {},
|
|
4330
|
+
expect: { status: 200, body: { files: [CORPUS_LOG] } }
|
|
4331
|
+
},
|
|
4332
|
+
{
|
|
4333
|
+
id: "admin-log-tail-answers-the-tail",
|
|
4334
|
+
route: "GET /SASjsApi/admin/logs/{fileName}",
|
|
4335
|
+
description: "answers the tail of a log the folder holds",
|
|
4336
|
+
request: { params: { fileName: CORPUS_LOG.name } },
|
|
4337
|
+
expect: { status: 200, body: CORPUS_LOG_TAIL }
|
|
4338
|
+
},
|
|
4339
|
+
{
|
|
4340
|
+
id: "admin-log-tail-refuses-a-traversal",
|
|
4341
|
+
route: "GET /SASjsApi/admin/logs/{fileName}",
|
|
4342
|
+
description: "refuses a name that could resolve outside the log folder, before the host is asked",
|
|
4343
|
+
request: { params: { fileName: "../20260101000000.log" } },
|
|
4344
|
+
expect: { status: 400, error: "Invalid log file name." }
|
|
4345
|
+
},
|
|
4346
|
+
{
|
|
4347
|
+
id: "admin-log-tail-answers-404",
|
|
4348
|
+
route: "GET /SASjsApi/admin/logs/{fileName}",
|
|
4349
|
+
description: "answers 404 for a name the folder does not hold",
|
|
4350
|
+
request: { params: { fileName: "20250101000000.log" } },
|
|
4351
|
+
expect: { status: 404, error: "Log file not found." }
|
|
4352
|
+
}
|
|
4353
|
+
];
|
|
4354
|
+
|
|
4355
|
+
// src/corpus/authconfig.ts
|
|
4356
|
+
var CORPUS_AUTH_CONFIG = {
|
|
4357
|
+
ldap: {
|
|
4358
|
+
url: "ldaps://directory.example:636",
|
|
4359
|
+
bindDn: "cn=admin,dc=example",
|
|
4360
|
+
usersBaseDn: "ou=users,dc=example",
|
|
4361
|
+
groupsBaseDn: "ou=groups,dc=example",
|
|
4362
|
+
bindPasswordSet: true
|
|
4363
|
+
}
|
|
4364
|
+
};
|
|
4365
|
+
var CORPUS_AUTH_CONFIG_BODY = {
|
|
4366
|
+
ldap: {
|
|
4367
|
+
LDAP_URL: "ldaps://directory.example:636",
|
|
4368
|
+
LDAP_BIND_DN: "cn=admin,dc=example",
|
|
4369
|
+
LDAP_USERS_BASE_DN: "ou=users,dc=example",
|
|
4370
|
+
LDAP_GROUPS_BASE_DN: "ou=groups,dc=example",
|
|
4371
|
+
LDAP_BIND_PASSWORD_SET: true
|
|
4372
|
+
}
|
|
4373
|
+
};
|
|
4374
|
+
var AUTH_CONFIG_CORPUS = [
|
|
4375
|
+
{
|
|
4376
|
+
id: "authconfig-answers-the-enabled-provider",
|
|
4377
|
+
route: "GET /SASjsApi/authConfig",
|
|
4378
|
+
description: "answers the enabled provider with the secret reported as a boolean, never as a value",
|
|
4379
|
+
request: {},
|
|
4380
|
+
expect: { status: 200, body: CORPUS_AUTH_CONFIG_BODY }
|
|
4381
|
+
}
|
|
4382
|
+
];
|
|
4383
|
+
|
|
4384
|
+
// src/corpus/directory.ts
|
|
4385
|
+
var CORPUS_DIRECTORY = {
|
|
4386
|
+
users: async () => [{ username: "alice", displayName: "Alice" }],
|
|
4387
|
+
groups: async () => [{ name: "analysts" }]
|
|
4388
|
+
};
|
|
4389
|
+
var DIRECTORY_CORPUS = [
|
|
4390
|
+
{
|
|
4391
|
+
id: "directory-imports-the-missing-accounts",
|
|
4392
|
+
route: "POST /SASjsApi/authConfig/synchroniseWithLDAP",
|
|
4393
|
+
description: "imports the users and groups the store does not hold, and counts them",
|
|
4394
|
+
request: {},
|
|
4395
|
+
expect: { status: 200, body: { userCount: 1, groupCount: 1 } }
|
|
4396
|
+
}
|
|
4397
|
+
];
|
|
4398
|
+
|
|
4399
|
+
// src/corpus/home.ts
|
|
4400
|
+
var CORPUS_WEB_PAGE = {
|
|
4401
|
+
version: "4a26a3d1b2c3",
|
|
4402
|
+
html: [
|
|
4403
|
+
"<!doctype html>",
|
|
4404
|
+
"<html>",
|
|
4405
|
+
"<head>",
|
|
4406
|
+
' <script src="./index.bundle.js"></script>',
|
|
4407
|
+
' <script src="./vendor.js?v=keepme"></script>',
|
|
4408
|
+
' <link rel="stylesheet" href="./index.bundle.css" />',
|
|
4409
|
+
"</head>",
|
|
4410
|
+
"<body>",
|
|
4411
|
+
" <p>The page loads index.bundle.js from the folder beside it.</p>",
|
|
4412
|
+
' <div id="root"></div>',
|
|
4413
|
+
"</body>",
|
|
4414
|
+
"</html>"
|
|
4415
|
+
].join("\n")
|
|
4416
|
+
};
|
|
4417
|
+
var CORPUS_WEB_BODY = CORPUS_WEB_PAGE.html.replace(
|
|
4418
|
+
'./index.bundle.js"',
|
|
4419
|
+
`./index.bundle.js?v=${CORPUS_WEB_PAGE.version}"`
|
|
4420
|
+
);
|
|
4421
|
+
var HOME_CORPUS = [
|
|
4422
|
+
{
|
|
4423
|
+
id: "home-answers-the-stamped-shell",
|
|
4424
|
+
route: "GET /",
|
|
4425
|
+
description: "answers the shell with its bundle reference stamped, leaving prose and an already-versioned reference alone",
|
|
4426
|
+
request: {},
|
|
4427
|
+
expect: { status: 200, contents: CORPUS_WEB_BODY }
|
|
4428
|
+
}
|
|
4429
|
+
];
|
|
4430
|
+
|
|
4431
|
+
// src/home/service.ts
|
|
4432
|
+
var BUNDLE_NAME = "index.bundle.js";
|
|
4433
|
+
var NO_WEB_BUILD = "<html><head></head><body>Web Build is not present</body></html>";
|
|
4434
|
+
var FILE_ATTRIBUTE = /(\s(?:src|href)=)("[^"]*"|'[^']*'|[^\s>]+)/g;
|
|
4435
|
+
var BUNDLE_REFERENCE = new RegExp(
|
|
4436
|
+
`(^|/)${BUNDLE_NAME.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}$`
|
|
4437
|
+
);
|
|
4438
|
+
var withBundleVersion = (html, version) => html.replace(FILE_ATTRIBUTE, (match, attribute, value) => {
|
|
4439
|
+
const quote = value[0] === '"' || value[0] === "'" ? value[0] : "";
|
|
4440
|
+
const target = quote ? value.slice(1, -1) : value;
|
|
4441
|
+
if (!BUNDLE_REFERENCE.test(target) || target.includes("?")) return match;
|
|
4442
|
+
return `${attribute}${quote}${target}?v=${version}${quote}`;
|
|
4443
|
+
});
|
|
4444
|
+
var isNonEmptyString = (value) => typeof value === "string" && value.length > 0;
|
|
4445
|
+
var pageOf = (page) => {
|
|
4446
|
+
if (!page || typeof page !== "object")
|
|
4447
|
+
throw new Error("The web page is not an object.");
|
|
4448
|
+
if (!isNonEmptyString(page.html))
|
|
4449
|
+
throw new Error(
|
|
4450
|
+
"The web page states no html, so there is nothing to serve. Answer `undefined` from the port when the host has no build."
|
|
4451
|
+
);
|
|
4452
|
+
if (!isNonEmptyString(page.version) || !/^[A-Za-z0-9._-]+$/.test(page.version))
|
|
4453
|
+
throw new Error(
|
|
4454
|
+
`The web page states version as ${JSON.stringify(page.version)}; it is the bundle's cache token, so it may contain only letters, digits, ".", "_" and "-" - anything else, a quote above all, would end the attribute it is written into.`
|
|
4455
|
+
);
|
|
4456
|
+
return withBundleVersion(page.html, page.version);
|
|
4457
|
+
};
|
|
4458
|
+
var createHomeService = (page) => ({
|
|
4459
|
+
async home() {
|
|
4460
|
+
const found = await page();
|
|
4461
|
+
return found === void 0 ? NO_WEB_BUILD : pageOf(found);
|
|
4462
|
+
}
|
|
4463
|
+
});
|
|
4464
|
+
|
|
4053
4465
|
// src/info/service.ts
|
|
4054
4466
|
var BROWSER_INFO = {
|
|
4055
4467
|
mode: "desktop",
|
|
@@ -4075,7 +4487,7 @@ var SASjsApi = (() => {
|
|
|
4075
4487
|
var REQUIRED_FIELDS = FIELDS.filter((field) => field !== "oidcProviderName");
|
|
4076
4488
|
var MODES = ["server", "desktop"];
|
|
4077
4489
|
var CORS_VALUES = ["enable", "disable"];
|
|
4078
|
-
var
|
|
4490
|
+
var isNonEmptyString2 = (value) => typeof value === "string" && value.length > 0;
|
|
4079
4491
|
var portOf = (value, name) => {
|
|
4080
4492
|
if (value === null || value === void 0) return null;
|
|
4081
4493
|
if (typeof value !== "number" || !Number.isInteger(value))
|
|
@@ -4094,7 +4506,7 @@ var SASjsApi = (() => {
|
|
|
4094
4506
|
`The info configuration states ${name} as ${JSON.stringify(value)}; the document states an array of strings.`
|
|
4095
4507
|
);
|
|
4096
4508
|
for (const entry of value)
|
|
4097
|
-
if (!
|
|
4509
|
+
if (!isNonEmptyString2(entry))
|
|
4098
4510
|
throw new Error(
|
|
4099
4511
|
`The info configuration states ${name} with an entry that is not a name: ${JSON.stringify(entry)}.`
|
|
4100
4512
|
);
|
|
@@ -4124,14 +4536,14 @@ var SASjsApi = (() => {
|
|
|
4124
4536
|
`The info configuration states cors as ${JSON.stringify(cors)}; the document states the CorsType enum - ${CORS_VALUES.map((value) => `\`${value}\``).join(" or ")}.`
|
|
4125
4537
|
);
|
|
4126
4538
|
const version = config.version;
|
|
4127
|
-
if (!
|
|
4539
|
+
if (!isNonEmptyString2(version) || version.trim() === "")
|
|
4128
4540
|
throw new Error(
|
|
4129
4541
|
`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
4542
|
);
|
|
4131
4543
|
const authProviders = namesOf(config.authProviders, "authProviders");
|
|
4132
4544
|
const runTimes = namesOf(config.runTimes, "runTimes");
|
|
4133
4545
|
const rawName = config.oidcProviderName;
|
|
4134
|
-
if (rawName !== void 0 && !
|
|
4546
|
+
if (rawName !== void 0 && !isNonEmptyString2(rawName))
|
|
4135
4547
|
throw new Error(
|
|
4136
4548
|
`The info configuration states oidcProviderName as ${JSON.stringify(rawName)}; the document states the sign-on button's label, or omits it.`
|
|
4137
4549
|
);
|
|
@@ -4533,7 +4945,8 @@ var SASjsApi = (() => {
|
|
|
4533
4945
|
name: input.name,
|
|
4534
4946
|
description: input.description,
|
|
4535
4947
|
isActive: input.isActive,
|
|
4536
|
-
users: []
|
|
4948
|
+
users: [],
|
|
4949
|
+
...input.authProvider === void 0 ? {} : { authProvider: input.authProvider }
|
|
4537
4950
|
};
|
|
4538
4951
|
this.groupList.set(group.uid, group);
|
|
4539
4952
|
return group;
|
|
@@ -7331,6 +7744,376 @@ var SASjsApi = (() => {
|
|
|
7331
7744
|
}
|
|
7332
7745
|
];
|
|
7333
7746
|
|
|
7747
|
+
// src/authconfig/service.ts
|
|
7748
|
+
var LDAP_FIELDS = [
|
|
7749
|
+
"url",
|
|
7750
|
+
"bindDn",
|
|
7751
|
+
"usersBaseDn",
|
|
7752
|
+
"groupsBaseDn",
|
|
7753
|
+
"bindPasswordSet"
|
|
7754
|
+
];
|
|
7755
|
+
var OIDC_FIELDS = [
|
|
7756
|
+
"providerName",
|
|
7757
|
+
"issuerUrl",
|
|
7758
|
+
"clientId",
|
|
7759
|
+
"redirectUri",
|
|
7760
|
+
"scope",
|
|
7761
|
+
"signingAlg",
|
|
7762
|
+
"usernameClaim",
|
|
7763
|
+
"jitProvision",
|
|
7764
|
+
"clientSecretSet"
|
|
7765
|
+
];
|
|
7766
|
+
var SECRET = /(password|secret|passwd|token)/i;
|
|
7767
|
+
var checkProvider = (name, block, fields, booleans) => {
|
|
7768
|
+
if (!block || typeof block !== "object")
|
|
7769
|
+
throw new Error(
|
|
7770
|
+
`The auth configuration states \`${name}\` as ${JSON.stringify(block)}; a provider is an object, or absent when it is not enabled.`
|
|
7771
|
+
);
|
|
7772
|
+
for (const key of Object.keys(block)) {
|
|
7773
|
+
if (!fields.includes(key))
|
|
7774
|
+
throw new Error(
|
|
7775
|
+
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.`
|
|
7776
|
+
);
|
|
7777
|
+
}
|
|
7778
|
+
for (const key of fields) {
|
|
7779
|
+
if (!(key in block))
|
|
7780
|
+
throw new Error(
|
|
7781
|
+
`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.`
|
|
7782
|
+
);
|
|
7783
|
+
const value = block[key];
|
|
7784
|
+
if (booleans.includes(key)) {
|
|
7785
|
+
if (typeof value !== "boolean")
|
|
7786
|
+
throw new Error(
|
|
7787
|
+
`The auth configuration states \`${name}.${key}\` as ${JSON.stringify(value)}; it says whether the secret is configured, so it is a boolean.`
|
|
7788
|
+
);
|
|
7789
|
+
} else if (typeof value !== "string")
|
|
7790
|
+
throw new Error(
|
|
7791
|
+
`The auth configuration states \`${name}.${key}\` as ${JSON.stringify(value)}; the document states a string.`
|
|
7792
|
+
);
|
|
7793
|
+
}
|
|
7794
|
+
};
|
|
7795
|
+
var normaliseAuthConfig = (config) => {
|
|
7796
|
+
if (!config || typeof config !== "object")
|
|
7797
|
+
throw new Error("The auth configuration is not an object.");
|
|
7798
|
+
for (const key of Object.keys(config))
|
|
7799
|
+
if (key !== "ldap" && key !== "oidc")
|
|
7800
|
+
throw new Error(
|
|
7801
|
+
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\`.`
|
|
7802
|
+
);
|
|
7803
|
+
const answer = {};
|
|
7804
|
+
if (config.ldap !== void 0) {
|
|
7805
|
+
checkProvider("ldap", config.ldap, LDAP_FIELDS, ["bindPasswordSet"]);
|
|
7806
|
+
answer.ldap = {
|
|
7807
|
+
LDAP_URL: config.ldap.url,
|
|
7808
|
+
LDAP_BIND_DN: config.ldap.bindDn,
|
|
7809
|
+
LDAP_USERS_BASE_DN: config.ldap.usersBaseDn,
|
|
7810
|
+
LDAP_GROUPS_BASE_DN: config.ldap.groupsBaseDn,
|
|
7811
|
+
LDAP_BIND_PASSWORD_SET: config.ldap.bindPasswordSet
|
|
7812
|
+
};
|
|
7813
|
+
}
|
|
7814
|
+
if (config.oidc !== void 0) {
|
|
7815
|
+
checkProvider("oidc", config.oidc, OIDC_FIELDS, ["clientSecretSet"]);
|
|
7816
|
+
answer.oidc = {
|
|
7817
|
+
OIDC_PROVIDER_NAME: config.oidc.providerName,
|
|
7818
|
+
OIDC_ISSUER_URL: config.oidc.issuerUrl,
|
|
7819
|
+
OIDC_CLIENT_ID: config.oidc.clientId,
|
|
7820
|
+
OIDC_REDIRECT_URI: config.oidc.redirectUri,
|
|
7821
|
+
OIDC_SCOPE: config.oidc.scope,
|
|
7822
|
+
OIDC_SIGNING_ALG: config.oidc.signingAlg,
|
|
7823
|
+
OIDC_USERNAME_CLAIM: config.oidc.usernameClaim,
|
|
7824
|
+
OIDC_JIT_PROVISION: config.oidc.jitProvision,
|
|
7825
|
+
OIDC_CLIENT_SECRET_SET: config.oidc.clientSecretSet
|
|
7826
|
+
};
|
|
7827
|
+
}
|
|
7828
|
+
return answer;
|
|
7829
|
+
};
|
|
7830
|
+
var createAuthConfigService = (config) => {
|
|
7831
|
+
const read = () => typeof config === "function" ? config() : config;
|
|
7832
|
+
return {
|
|
7833
|
+
async authConfig() {
|
|
7834
|
+
return normaliseAuthConfig(read());
|
|
7835
|
+
}
|
|
7836
|
+
};
|
|
7837
|
+
};
|
|
7838
|
+
|
|
7839
|
+
// src/admin/service.ts
|
|
7840
|
+
var DEFAULT_LOG_LINES = 200;
|
|
7841
|
+
var MAX_LOG_LINES = 5e3;
|
|
7842
|
+
var isObject = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
7843
|
+
var isNumber = (value) => typeof value === "number" && Number.isFinite(value);
|
|
7844
|
+
var isString = (value) => typeof value === "string";
|
|
7845
|
+
var requireString = (holder, key, where) => {
|
|
7846
|
+
if (!isString(holder[key]))
|
|
7847
|
+
throw new Error(
|
|
7848
|
+
`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.`
|
|
7849
|
+
);
|
|
7850
|
+
};
|
|
7851
|
+
var requireNumber = (holder, key, where) => {
|
|
7852
|
+
if (!isNumber(holder[key]))
|
|
7853
|
+
throw new Error(
|
|
7854
|
+
`The ${where} report states \`${key}\` as ${JSON.stringify(holder[key])}; the document states a number, and a client that renders it would print NaN.`
|
|
7855
|
+
);
|
|
7856
|
+
};
|
|
7857
|
+
var requireObject = (holder, key, where) => {
|
|
7858
|
+
const value = holder[key];
|
|
7859
|
+
if (!isObject(value))
|
|
7860
|
+
throw new Error(
|
|
7861
|
+
`The ${where} report states \`${key}\` as ${JSON.stringify(value)}; the document states an object.`
|
|
7862
|
+
);
|
|
7863
|
+
return value;
|
|
7864
|
+
};
|
|
7865
|
+
var normaliseDiagnostics = (report) => {
|
|
7866
|
+
if (!isObject(report))
|
|
7867
|
+
throw new Error("The diagnostics report is not an object.");
|
|
7868
|
+
const build = requireObject(
|
|
7869
|
+
report,
|
|
7870
|
+
"build",
|
|
7871
|
+
"diagnostics"
|
|
7872
|
+
);
|
|
7873
|
+
requireString(build, "version", "diagnostics build");
|
|
7874
|
+
requireString(build, "gitHash", "diagnostics build");
|
|
7875
|
+
if (!(build.buildDate === null || isString(build.buildDate)))
|
|
7876
|
+
throw new Error(
|
|
7877
|
+
`The diagnostics build states \`buildDate\` as ${JSON.stringify(build.buildDate)}; the document states an ISO timestamp or null.`
|
|
7878
|
+
);
|
|
7879
|
+
const server = requireObject(
|
|
7880
|
+
report,
|
|
7881
|
+
"server",
|
|
7882
|
+
"diagnostics"
|
|
7883
|
+
);
|
|
7884
|
+
requireString(server, "mode", "diagnostics server");
|
|
7885
|
+
requireString(server, "startedAt", "diagnostics server");
|
|
7886
|
+
requireString(server, "nodeVersion", "diagnostics server");
|
|
7887
|
+
requireString(server, "platform", "diagnostics server");
|
|
7888
|
+
requireString(server, "arch", "diagnostics server");
|
|
7889
|
+
requireString(server, "cpuModel", "diagnostics server");
|
|
7890
|
+
requireString(server, "sasjsRoot", "diagnostics server");
|
|
7891
|
+
requireNumber(server, "uptimeSeconds", "diagnostics server");
|
|
7892
|
+
requireNumber(server, "pid", "diagnostics server");
|
|
7893
|
+
requireNumber(server, "cpuCount", "diagnostics server");
|
|
7894
|
+
if (!Array.isArray(server.loadAverage) || !server.loadAverage.every(isNumber))
|
|
7895
|
+
throw new Error(
|
|
7896
|
+
"The diagnostics server report states `loadAverage` as something other than an array of numbers."
|
|
7897
|
+
);
|
|
7898
|
+
if (!Array.isArray(server.runTimes) || !server.runTimes.every(isString))
|
|
7899
|
+
throw new Error(
|
|
7900
|
+
"The diagnostics server report states `runTimes` as something other than an array of strings."
|
|
7901
|
+
);
|
|
7902
|
+
const memory = requireObject(
|
|
7903
|
+
report,
|
|
7904
|
+
"memory",
|
|
7905
|
+
"diagnostics"
|
|
7906
|
+
);
|
|
7907
|
+
for (const key of [
|
|
7908
|
+
"rssBytes",
|
|
7909
|
+
"heapTotalBytes",
|
|
7910
|
+
"heapUsedBytes",
|
|
7911
|
+
"externalBytes",
|
|
7912
|
+
"systemTotalBytes",
|
|
7913
|
+
"systemFreeBytes"
|
|
7914
|
+
])
|
|
7915
|
+
requireNumber(memory, key, "diagnostics memory");
|
|
7916
|
+
const filesystem = report.filesystem;
|
|
7917
|
+
if (filesystem !== null) {
|
|
7918
|
+
if (!isObject(filesystem))
|
|
7919
|
+
throw new Error(
|
|
7920
|
+
`The diagnostics report states \`filesystem\` as ${JSON.stringify(filesystem)}; the document states an object or null.`
|
|
7921
|
+
);
|
|
7922
|
+
requireString(
|
|
7923
|
+
filesystem,
|
|
7924
|
+
"path",
|
|
7925
|
+
"diagnostics filesystem"
|
|
7926
|
+
);
|
|
7927
|
+
for (const key of ["totalBytes", "freeBytes", "usedBytes", "usedPercent"])
|
|
7928
|
+
requireNumber(
|
|
7929
|
+
filesystem,
|
|
7930
|
+
key,
|
|
7931
|
+
"diagnostics filesystem"
|
|
7932
|
+
);
|
|
7933
|
+
}
|
|
7934
|
+
if (!Array.isArray(report.folders))
|
|
7935
|
+
throw new Error(
|
|
7936
|
+
"The diagnostics report states `folders` as something other than an array."
|
|
7937
|
+
);
|
|
7938
|
+
for (const folder of report.folders) {
|
|
7939
|
+
if (!isObject(folder))
|
|
7940
|
+
throw new Error(
|
|
7941
|
+
"The diagnostics report carries a folder that is not an object."
|
|
7942
|
+
);
|
|
7943
|
+
const entry = folder;
|
|
7944
|
+
requireString(entry, "label", "diagnostics folder");
|
|
7945
|
+
requireString(entry, "path", "diagnostics folder");
|
|
7946
|
+
requireNumber(entry, "bytes", "diagnostics folder");
|
|
7947
|
+
requireNumber(entry, "files", "diagnostics folder");
|
|
7948
|
+
if (typeof entry.exists !== "boolean" || typeof entry.truncated !== "boolean")
|
|
7949
|
+
throw new Error(
|
|
7950
|
+
"The diagnostics folder report states `exists` or `truncated` as something other than a boolean."
|
|
7951
|
+
);
|
|
7952
|
+
}
|
|
7953
|
+
const logs = requireObject(
|
|
7954
|
+
report,
|
|
7955
|
+
"logs",
|
|
7956
|
+
"diagnostics"
|
|
7957
|
+
);
|
|
7958
|
+
requireString(logs, "folder", "diagnostics logs");
|
|
7959
|
+
requireNumber(logs, "fileCount", "diagnostics logs");
|
|
7960
|
+
requireNumber(logs, "totalBytes", "diagnostics logs");
|
|
7961
|
+
for (const key of ["newestFile", "newestModified"])
|
|
7962
|
+
if (!(logs[key] === null || isString(logs[key])))
|
|
7963
|
+
throw new Error(
|
|
7964
|
+
`The diagnostics logs summary states \`${key}\` as ${JSON.stringify(logs[key])}; the document states a string or null.`
|
|
7965
|
+
);
|
|
7966
|
+
return report;
|
|
7967
|
+
};
|
|
7968
|
+
var normaliseLogFiles = (files) => {
|
|
7969
|
+
if (!Array.isArray(files))
|
|
7970
|
+
throw new Error("The log report is not an array of files.");
|
|
7971
|
+
return files.map((file) => {
|
|
7972
|
+
if (!isObject(file))
|
|
7973
|
+
throw new Error("The log report carries an entry that is not an object.");
|
|
7974
|
+
const entry = file;
|
|
7975
|
+
requireString(entry, "name", "logs");
|
|
7976
|
+
requireString(entry, "modified", "logs");
|
|
7977
|
+
requireNumber(entry, "sizeBytes", "logs");
|
|
7978
|
+
return file;
|
|
7979
|
+
});
|
|
7980
|
+
};
|
|
7981
|
+
var checkLogFileName = (fileName) => {
|
|
7982
|
+
if (!fileName || fileName.includes("/") || fileName.includes("\\") || fileName.split(/[\\/]/).pop() !== fileName || !fileName.toLowerCase().endsWith(".log"))
|
|
7983
|
+
throw new ApiError(400, "Invalid log file name.");
|
|
7984
|
+
return fileName;
|
|
7985
|
+
};
|
|
7986
|
+
var logLines = (lines) => {
|
|
7987
|
+
if (lines === void 0 || lines === null || lines === "")
|
|
7988
|
+
return DEFAULT_LOG_LINES;
|
|
7989
|
+
const wanted = Number(lines);
|
|
7990
|
+
if (!Number.isFinite(wanted)) return DEFAULT_LOG_LINES;
|
|
7991
|
+
return Math.min(Math.max(Math.trunc(wanted), 1), MAX_LOG_LINES);
|
|
7992
|
+
};
|
|
7993
|
+
var normaliseLogTail = (tail) => {
|
|
7994
|
+
if (!isObject(tail)) throw new Error("The log tail report is not an object.");
|
|
7995
|
+
const entry = tail;
|
|
7996
|
+
requireString(entry, "fileName", "log tail");
|
|
7997
|
+
requireString(entry, "content", "log tail");
|
|
7998
|
+
requireNumber(entry, "lines", "log tail");
|
|
7999
|
+
requireNumber(entry, "bytesRead", "log tail");
|
|
8000
|
+
if (typeof entry.truncated !== "boolean")
|
|
8001
|
+
throw new Error(
|
|
8002
|
+
"The log tail report states `truncated` as something other than a boolean."
|
|
8003
|
+
);
|
|
8004
|
+
return tail;
|
|
8005
|
+
};
|
|
8006
|
+
var createAdminService = (reports) => ({
|
|
8007
|
+
async diagnostics() {
|
|
8008
|
+
return normaliseDiagnostics(await reports.diagnostics());
|
|
8009
|
+
},
|
|
8010
|
+
async logs() {
|
|
8011
|
+
return normaliseLogFiles(await reports.logs());
|
|
8012
|
+
},
|
|
8013
|
+
async logTail(fileName, lines) {
|
|
8014
|
+
const name = checkLogFileName(fileName);
|
|
8015
|
+
const tail = await reports.logTail(name, logLines(lines));
|
|
8016
|
+
if (tail === void 0) throw new ApiError(404, "Log file not found.");
|
|
8017
|
+
return normaliseLogTail(tail);
|
|
8018
|
+
}
|
|
8019
|
+
});
|
|
8020
|
+
|
|
8021
|
+
// src/directory/service.ts
|
|
8022
|
+
var isNonEmptyString3 = (value) => typeof value === "string" && value.length > 0;
|
|
8023
|
+
var usersOf = (users) => {
|
|
8024
|
+
if (!Array.isArray(users))
|
|
8025
|
+
throw new Error("The directory answer has no users array.");
|
|
8026
|
+
const seen = /* @__PURE__ */ new Set();
|
|
8027
|
+
for (const user3 of users) {
|
|
8028
|
+
if (!isNonEmptyString3(user3?.username) || !isNonEmptyString3(user3?.displayName))
|
|
8029
|
+
throw new Error(
|
|
8030
|
+
`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.`
|
|
8031
|
+
);
|
|
8032
|
+
if (seen.has(user3.username))
|
|
8033
|
+
throw new Error(
|
|
8034
|
+
`The directory answer names ${user3.username} twice. A directory that returns one account twice is a filter problem, and importing it would hide that.`
|
|
8035
|
+
);
|
|
8036
|
+
seen.add(user3.username);
|
|
8037
|
+
}
|
|
8038
|
+
return users;
|
|
8039
|
+
};
|
|
8040
|
+
var groupsOf = (groups) => {
|
|
8041
|
+
if (!Array.isArray(groups))
|
|
8042
|
+
throw new Error("The directory answer has no groups array.");
|
|
8043
|
+
const seen = /* @__PURE__ */ new Set();
|
|
8044
|
+
for (const group of groups) {
|
|
8045
|
+
if (!isNonEmptyString3(group?.name))
|
|
8046
|
+
throw new Error(
|
|
8047
|
+
`The directory answer carries a group without a name: ${JSON.stringify(group)}.`
|
|
8048
|
+
);
|
|
8049
|
+
if (seen.has(group.name))
|
|
8050
|
+
throw new Error(
|
|
8051
|
+
`The directory answer names the group ${group.name} twice, which would apply its members twice.`
|
|
8052
|
+
);
|
|
8053
|
+
seen.add(group.name);
|
|
8054
|
+
}
|
|
8055
|
+
return groups;
|
|
8056
|
+
};
|
|
8057
|
+
var createDirectoryService = (store, source, options = {}) => {
|
|
8058
|
+
const provider = options.provider || "ldap";
|
|
8059
|
+
return {
|
|
8060
|
+
async synchronise() {
|
|
8061
|
+
const directoryUsers = usersOf(await source.users());
|
|
8062
|
+
const directoryGroups = groupsOf(await source.groups());
|
|
8063
|
+
const existingUsers = await store.users();
|
|
8064
|
+
const existingGroups = await store.groups();
|
|
8065
|
+
const userByName = new Map(
|
|
8066
|
+
existingUsers.map((user3) => [user3.username, user3])
|
|
8067
|
+
);
|
|
8068
|
+
const groupByName = new Map(
|
|
8069
|
+
existingGroups.map((group) => [group.name, group])
|
|
8070
|
+
);
|
|
8071
|
+
const imported = [];
|
|
8072
|
+
for (const user3 of directoryUsers) {
|
|
8073
|
+
if (userByName.has(user3.username)) continue;
|
|
8074
|
+
const created = await store.createUser({
|
|
8075
|
+
username: user3.username,
|
|
8076
|
+
displayName: user3.displayName,
|
|
8077
|
+
isAdmin: false,
|
|
8078
|
+
isActive: true,
|
|
8079
|
+
authProvider: provider
|
|
8080
|
+
});
|
|
8081
|
+
userByName.set(created.username, created);
|
|
8082
|
+
imported.push(created);
|
|
8083
|
+
}
|
|
8084
|
+
const importedGroups = [];
|
|
8085
|
+
for (const group of directoryGroups) {
|
|
8086
|
+
if (groupByName.has(group.name)) continue;
|
|
8087
|
+
const created = await store.createGroup({
|
|
8088
|
+
name: group.name,
|
|
8089
|
+
description: "",
|
|
8090
|
+
isActive: true,
|
|
8091
|
+
authProvider: provider
|
|
8092
|
+
});
|
|
8093
|
+
groupByName.set(created.name, created);
|
|
8094
|
+
importedGroups.push(created);
|
|
8095
|
+
}
|
|
8096
|
+
const membersOf = /* @__PURE__ */ new Map();
|
|
8097
|
+
const note = (groupName, username) => {
|
|
8098
|
+
const members = membersOf.get(groupName) || /* @__PURE__ */ new Set();
|
|
8099
|
+
members.add(username);
|
|
8100
|
+
membersOf.set(groupName, members);
|
|
8101
|
+
};
|
|
8102
|
+
for (const group of directoryGroups)
|
|
8103
|
+
for (const member of group.members || []) note(group.name, member);
|
|
8104
|
+
for (const user3 of directoryUsers)
|
|
8105
|
+
for (const groupName of user3.groups || [])
|
|
8106
|
+
note(groupName, user3.username);
|
|
8107
|
+
for (const group of importedGroups)
|
|
8108
|
+
for (const username of membersOf.get(group.name) || []) {
|
|
8109
|
+
const user3 = userByName.get(username);
|
|
8110
|
+
if (user3) await store.addToGroup(group.uid, user3.uid);
|
|
8111
|
+
}
|
|
8112
|
+
return { userCount: imported.length, groupCount: importedGroups.length };
|
|
8113
|
+
}
|
|
8114
|
+
};
|
|
8115
|
+
};
|
|
8116
|
+
|
|
7334
8117
|
// src/corpus/runner.ts
|
|
7335
8118
|
var servicesFor = (testCase) => {
|
|
7336
8119
|
const identity = new MemoryIdentityStore(
|
|
@@ -7345,6 +8128,14 @@ var SASjsApi = (() => {
|
|
|
7345
8128
|
testCase.unwritable ? new RefusingDriveStore(testCase.seed || {}) : new MemoryDriveStore(testCase.seed || {})
|
|
7346
8129
|
),
|
|
7347
8130
|
info: createInfoService(BROWSER_INFO),
|
|
8131
|
+
home: createHomeService(async () => CORPUS_WEB_PAGE),
|
|
8132
|
+
authConfig: createAuthConfigService(CORPUS_AUTH_CONFIG),
|
|
8133
|
+
admin: createAdminService({
|
|
8134
|
+
diagnostics: async () => CORPUS_DIAGNOSTICS,
|
|
8135
|
+
logs: async () => [CORPUS_LOG],
|
|
8136
|
+
logTail: async (fileName) => fileName === CORPUS_LOG.name ? CORPUS_LOG_TAIL : void 0
|
|
8137
|
+
}),
|
|
8138
|
+
directory: createDirectoryService(identity, CORPUS_DIRECTORY),
|
|
7348
8139
|
identity: createIdentityService(identity),
|
|
7349
8140
|
records: createRecordService(identity),
|
|
7350
8141
|
registry: new MemoryAppStreamRegistry(),
|