@sasjs/api 0.48.1 → 0.49.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/build/browser.js +204 -56
- package/build/cjs/appstream/identity.js +2 -31
- package/build/cjs/corpus/viya/replay.js +117 -0
- package/build/cjs/index.js +6 -3
- package/build/cjs/uuid.js +30 -0
- package/build/cjs/viya/compute.js +38 -20
- package/build/cjs/viya/dispatch.js +10 -0
- package/build/cjs/viya/seed.js +34 -8
- package/build/cjs/viya/service.js +55 -11
- package/build/cjs/viya/sessions.js +24 -10
- package/build/esm/appstream/identity.d.ts +1 -9
- package/build/esm/appstream/identity.d.ts.map +1 -1
- package/build/esm/appstream/identity.js +1 -30
- package/build/esm/corpus/viya/replay.d.ts +53 -0
- package/build/esm/corpus/viya/replay.d.ts.map +1 -0
- package/build/esm/corpus/viya/replay.js +112 -0
- package/build/esm/identity/types.d.ts +2 -0
- package/build/esm/identity/types.d.ts.map +1 -1
- package/build/esm/index.d.ts +2 -0
- package/build/esm/index.d.ts.map +1 -1
- package/build/esm/index.js +1 -0
- package/build/esm/uuid.d.ts +6 -0
- package/build/esm/uuid.d.ts.map +1 -0
- package/build/esm/uuid.js +26 -0
- package/build/esm/viya/compute.d.ts.map +1 -1
- package/build/esm/viya/compute.js +39 -21
- package/build/esm/viya/dispatch.d.ts +3 -0
- package/build/esm/viya/dispatch.d.ts.map +1 -1
- package/build/esm/viya/dispatch.js +11 -1
- package/build/esm/viya/seed.d.ts +29 -7
- package/build/esm/viya/seed.d.ts.map +1 -1
- package/build/esm/viya/seed.js +32 -7
- package/build/esm/viya/service.d.ts.map +1 -1
- package/build/esm/viya/service.js +55 -11
- package/build/esm/viya/sessions.d.ts +24 -6
- package/build/esm/viya/sessions.d.ts.map +1 -1
- package/build/esm/viya/sessions.js +24 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -26,6 +26,10 @@ Where the document is wrong, it is corrected in `sasjs/server` and re-vendored h
|
|
|
26
26
|
`createAdminService` carries the three Admin reports over the host's `AdminReports`, owning the diagnostics shape, the log-name rule and the `lines` bounds; `createDirectoryService` imports a directory over a five-method `DirectoryStore`, creating what is missing and leaving what exists; `createHomeService` stamps the interface's shell with a token derived from its bundle, so a cached page cannot pin an old build.
|
|
27
27
|
They are `async`, take a `DriveStore`, and import nothing - so the same code runs under Express and inside a service worker.
|
|
28
28
|
|
|
29
|
+
**Viya compute ownership.** A multi-user host must authenticate its caller and pass the resolved `subject` to `dispatchViya` on every compute session request. Set `subject.ownerId` to the immutable account ID from the host's identity store, never from request data. `subject.userId` still controls the username on the wire. Hosts that omit `ownerId` use `userId` as before, in a separate namespace; switching an existing host to stable IDs requires recreating any live username-scoped sessions. Ownership spans client IDs, and another owner gets the same 404 as for a missing session. Ownerless records are refused. A token without a resolved subject is refused; no subject and no token selects a shared anonymous browser mock, not an authentication boundary. Session stores are keyed by the full normalised `serverUrl`, not the 32-bit seed.
|
|
30
|
+
|
|
31
|
+
New emulated session IDs are opaque UUID v4 strings (Web Crypto is required). Job IDs still derive from their session ID and therefore change with it; clients should use the returned IDs or links rather than parse their format. This does not change externally issued Viya IDs or the emulator's seeded folder IDs and generated logs.
|
|
32
|
+
|
|
29
33
|
**The app stream** (`createAppStreamService`, `createAppStreamWebService`, `splitAppBundle`) is what a deployed folder becomes when it is an app.
|
|
30
34
|
An app is one folder, the web assets inside it (`<appLoc>/services/<streamWebFolder>`) and a UUID assigned the first time it is published; the readable name is a label with no uniqueness rule, because nothing is looked up by name - the URL is `/app/<id>/`, so two apps may be called the same thing without colliding.
|
|
31
35
|
Publishing a folder that is already published is the same app published again: it keeps its id, which is what makes a redeploy keep its URL.
|
package/build/browser.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* @sasjs/api 0.
|
|
1
|
+
/* @sasjs/api 0.49.1 - the SASjs Server API, for a service worker. https://github.com/sasjs/api */
|
|
2
2
|
"use strict";
|
|
3
3
|
var SASjsApi = (() => {
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
@@ -128,7 +128,7 @@ var SASjsApi = (() => {
|
|
|
128
128
|
isRouteGranted: () => isRouteGranted,
|
|
129
129
|
logLines: () => logLines,
|
|
130
130
|
measureDeployTree: () => measureDeployTree,
|
|
131
|
-
newAppId: () =>
|
|
131
|
+
newAppId: () => newUuidV4,
|
|
132
132
|
normaliseAppLoc: () => normaliseAppLoc,
|
|
133
133
|
normaliseAuthConfig: () => normaliseAuthConfig,
|
|
134
134
|
normaliseDiagnostics: () => normaliseDiagnostics,
|
|
@@ -139,12 +139,14 @@ var SASjsApi = (() => {
|
|
|
139
139
|
parseIdentity: () => parseIdentity,
|
|
140
140
|
programNotFound: () => programNotFound,
|
|
141
141
|
publishRequestFor: () => publishRequestFor,
|
|
142
|
+
requestFor: () => requestFor,
|
|
142
143
|
resolveProgram: () => resolveProgram,
|
|
143
144
|
routeById: () => routeById,
|
|
144
145
|
runCase: () => runCase,
|
|
145
146
|
runTimeOfPath: () => runTimeOfPath,
|
|
146
147
|
sanitiseDisplayName: () => sanitiseDisplayName,
|
|
147
148
|
servicesFor: () => servicesFor,
|
|
149
|
+
shapeMismatches: () => shapeMismatches,
|
|
148
150
|
splitAppBundle: () => splitAppBundle,
|
|
149
151
|
topLevelRouteFor: () => topLevelRouteFor,
|
|
150
152
|
withBundleVersion: () => withBundleVersion
|
|
@@ -520,18 +522,8 @@ var SASjsApi = (() => {
|
|
|
520
522
|
};
|
|
521
523
|
};
|
|
522
524
|
|
|
523
|
-
// src/
|
|
524
|
-
var
|
|
525
|
-
if (typeof appLoc !== "string" || appLoc === "")
|
|
526
|
-
throw new Error(
|
|
527
|
-
`App location must be a non-empty string, got ${JSON.stringify(appLoc)}.`
|
|
528
|
-
);
|
|
529
|
-
const normalised = normaliseDrivePath(appLoc);
|
|
530
|
-
if (normalised === null)
|
|
531
|
-
throw new ApiError(400, "appLoc cannot be outside drive.");
|
|
532
|
-
return normalised;
|
|
533
|
-
};
|
|
534
|
-
var newAppId = () => {
|
|
525
|
+
// src/uuid.ts
|
|
526
|
+
var newUuidV4 = () => {
|
|
535
527
|
const webCrypto = globalThis.crypto;
|
|
536
528
|
if (typeof webCrypto?.randomUUID === "function") return webCrypto.randomUUID();
|
|
537
529
|
if (typeof webCrypto?.getRandomValues !== "function")
|
|
@@ -549,6 +541,18 @@ var SASjsApi = (() => {
|
|
|
549
541
|
hex.slice(20)
|
|
550
542
|
].join("-");
|
|
551
543
|
};
|
|
544
|
+
|
|
545
|
+
// src/appstream/identity.ts
|
|
546
|
+
var normaliseAppLoc = (appLoc) => {
|
|
547
|
+
if (typeof appLoc !== "string" || appLoc === "")
|
|
548
|
+
throw new Error(
|
|
549
|
+
`App location must be a non-empty string, got ${JSON.stringify(appLoc)}.`
|
|
550
|
+
);
|
|
551
|
+
const normalised = normaliseDrivePath(appLoc);
|
|
552
|
+
if (normalised === null)
|
|
553
|
+
throw new ApiError(400, "appLoc cannot be outside drive.");
|
|
554
|
+
return normalised;
|
|
555
|
+
};
|
|
552
556
|
var APP_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
553
557
|
var isAppId = (value) => typeof value === "string" && APP_ID.test(value);
|
|
554
558
|
|
|
@@ -748,7 +752,7 @@ var SASjsApi = (() => {
|
|
|
748
752
|
);
|
|
749
753
|
}
|
|
750
754
|
const entry = {
|
|
751
|
-
id: existing ? existing.id :
|
|
755
|
+
id: existing ? existing.id : newUuidV4(),
|
|
752
756
|
// the label is the one field a redeploy inherits: everything else is
|
|
753
757
|
// what this publish states
|
|
754
758
|
name,
|
|
@@ -5539,6 +5543,10 @@ var SASjsApi = (() => {
|
|
|
5539
5543
|
const address = normaliseServerUrl(settings.serverUrl);
|
|
5540
5544
|
return hash(`url:${address || DEFAULT_SEED}`);
|
|
5541
5545
|
};
|
|
5546
|
+
var estateKeyOf = (settings = {}) => {
|
|
5547
|
+
const address = normaliseServerUrl(settings.serverUrl);
|
|
5548
|
+
return address || DEFAULT_SEED;
|
|
5549
|
+
};
|
|
5542
5550
|
var generator = (seed) => {
|
|
5543
5551
|
let state = seed >>> 0;
|
|
5544
5552
|
return () => {
|
|
@@ -5574,12 +5582,14 @@ var SASjsApi = (() => {
|
|
|
5574
5582
|
constructor(seed) {
|
|
5575
5583
|
this.seed = seed;
|
|
5576
5584
|
this.sessions = /* @__PURE__ */ new Map();
|
|
5577
|
-
this.created = 0;
|
|
5578
5585
|
}
|
|
5579
|
-
/** A new session:
|
|
5580
|
-
create() {
|
|
5586
|
+
/** A new session: opaque UUID v4, no jobs. */
|
|
5587
|
+
create(owner) {
|
|
5588
|
+
const id = newUuidV4();
|
|
5589
|
+
if (this.sessions.has(id)) throw new Error("Duplicate compute session ID.");
|
|
5581
5590
|
const session = {
|
|
5582
|
-
id
|
|
5591
|
+
id,
|
|
5592
|
+
owner,
|
|
5583
5593
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
5584
5594
|
jobs: /* @__PURE__ */ new Map(),
|
|
5585
5595
|
submitted: 0
|
|
@@ -5617,11 +5627,11 @@ var SASjsApi = (() => {
|
|
|
5617
5627
|
}
|
|
5618
5628
|
};
|
|
5619
5629
|
var estates = /* @__PURE__ */ new Map();
|
|
5620
|
-
var estateFor = (seed) => {
|
|
5621
|
-
const existing = estates.get(
|
|
5630
|
+
var estateFor = (key, seed) => {
|
|
5631
|
+
const existing = estates.get(key);
|
|
5622
5632
|
if (existing) return existing;
|
|
5623
5633
|
const estate = new EmulatedEstate(seed);
|
|
5624
|
-
estates.set(
|
|
5634
|
+
estates.set(key, estate);
|
|
5625
5635
|
return estate;
|
|
5626
5636
|
};
|
|
5627
5637
|
|
|
@@ -5681,7 +5691,7 @@ var SASjsApi = (() => {
|
|
|
5681
5691
|
...itemType ? { itemType: type } : {}
|
|
5682
5692
|
}
|
|
5683
5693
|
];
|
|
5684
|
-
var estateOf = (services) => estateFor(seedOf(services.viya));
|
|
5694
|
+
var estateOf = (services) => estateFor(estateKeyOf(services.viya), seedOf(services.viya));
|
|
5685
5695
|
var contextNameFrom = (filter) => {
|
|
5686
5696
|
if (!filter) return DEFAULT_CONTEXT_NAME;
|
|
5687
5697
|
const match = /name\s*,\s*'([^']*)'|name\s*,\s*"([^"]*)"/i.exec(filter);
|
|
@@ -5758,14 +5768,25 @@ var SASjsApi = (() => {
|
|
|
5758
5768
|
])
|
|
5759
5769
|
};
|
|
5760
5770
|
};
|
|
5761
|
-
var
|
|
5771
|
+
var ownerOf = (subject) => {
|
|
5772
|
+
if (subject === void 0) return { kind: "anonymous" };
|
|
5773
|
+
if (!subject || typeof subject.userId !== "string" || !subject.userId.trim())
|
|
5774
|
+
throw new ApiError(401, "A valid caller is required.");
|
|
5775
|
+
if (subject.ownerId === void 0)
|
|
5776
|
+
return { kind: "user", key: subject.userId };
|
|
5777
|
+
if (typeof subject.ownerId !== "string" || !subject.ownerId.trim())
|
|
5778
|
+
throw new ApiError(401, "A valid caller is required.");
|
|
5779
|
+
return { kind: "account", key: subject.ownerId };
|
|
5780
|
+
};
|
|
5781
|
+
var sessionOf = (services, id, subject) => {
|
|
5782
|
+
const owner = ownerOf(subject);
|
|
5762
5783
|
const session = estateOf(services).session(id);
|
|
5763
|
-
if (!session)
|
|
5784
|
+
if (!session || !session.owner || session.owner.kind !== owner.kind || session.owner.key !== owner.key)
|
|
5764
5785
|
throw new ApiError(404, `Session with ID '${id}' was not found.`);
|
|
5765
5786
|
return session;
|
|
5766
5787
|
};
|
|
5767
|
-
var jobOf = (services, sessionId, jobId) => {
|
|
5768
|
-
const job = sessionOf(services, sessionId).jobs.get(jobId);
|
|
5788
|
+
var jobOf = (services, sessionId, jobId, subject) => {
|
|
5789
|
+
const job = sessionOf(services, sessionId, subject).jobs.get(jobId);
|
|
5769
5790
|
if (!job) throw new ApiError(404, `Job with ID '${jobId}' was not found.`);
|
|
5770
5791
|
return job;
|
|
5771
5792
|
};
|
|
@@ -5804,7 +5825,7 @@ var SASjsApi = (() => {
|
|
|
5804
5825
|
if (params.id !== EMULATED_CONTEXT_ID)
|
|
5805
5826
|
throw new ApiError(404, `Context with ID '${params.id}' was not found.`);
|
|
5806
5827
|
const body = request.body ?? {};
|
|
5807
|
-
const session = estateOf(services).create();
|
|
5828
|
+
const session = estateOf(services).create(ownerOf(request.subject));
|
|
5808
5829
|
return {
|
|
5809
5830
|
status: 201,
|
|
5810
5831
|
body: sessionBody(
|
|
@@ -5815,17 +5836,17 @@ var SASjsApi = (() => {
|
|
|
5815
5836
|
)
|
|
5816
5837
|
};
|
|
5817
5838
|
},
|
|
5818
|
-
"GET /compute/sessions/{}/state": async ({ services, params }) => {
|
|
5819
|
-
sessionOf(services, params.id);
|
|
5839
|
+
"GET /compute/sessions/{}/state": async ({ services, params, request }) => {
|
|
5840
|
+
sessionOf(services, params.id, request.subject);
|
|
5820
5841
|
return { status: 200, body: "idle" };
|
|
5821
5842
|
},
|
|
5822
|
-
"DELETE /compute/sessions/{}": async ({ services, params }) => {
|
|
5823
|
-
sessionOf(services, params.id);
|
|
5843
|
+
"DELETE /compute/sessions/{}": async ({ services, params, request }) => {
|
|
5844
|
+
sessionOf(services, params.id, request.subject);
|
|
5824
5845
|
estateOf(services).remove(params.id);
|
|
5825
5846
|
return { status: 204, body: void 0 };
|
|
5826
5847
|
},
|
|
5827
5848
|
"POST /compute/sessions/{}/jobs": async ({ services, params, request }) => {
|
|
5828
|
-
const session = sessionOf(services, params.id);
|
|
5849
|
+
const session = sessionOf(services, params.id, request.subject);
|
|
5829
5850
|
const body = request.body ?? {};
|
|
5830
5851
|
const job = estateOf(services).submit(session, body);
|
|
5831
5852
|
const execute = services.viya?.execute;
|
|
@@ -5855,9 +5876,10 @@ var SASjsApi = (() => {
|
|
|
5855
5876
|
},
|
|
5856
5877
|
"GET /compute/sessions/{}/filerefs/_webout/content": async ({
|
|
5857
5878
|
services,
|
|
5858
|
-
params
|
|
5879
|
+
params,
|
|
5880
|
+
request
|
|
5859
5881
|
}) => {
|
|
5860
|
-
const session = sessionOf(services, params.id);
|
|
5882
|
+
const session = sessionOf(services, params.id, request.subject);
|
|
5861
5883
|
const last = [...session.jobs.values()].pop();
|
|
5862
5884
|
if (!last)
|
|
5863
5885
|
throw new ApiError(
|
|
@@ -5875,15 +5897,22 @@ var SASjsApi = (() => {
|
|
|
5875
5897
|
headers: { "content-type": "text/plain" }
|
|
5876
5898
|
};
|
|
5877
5899
|
},
|
|
5878
|
-
"GET /compute/sessions/{}/jobs/{}": async ({ services, params }) => {
|
|
5900
|
+
"GET /compute/sessions/{}/jobs/{}": async ({ services, params, request }) => {
|
|
5879
5901
|
const [sessionId, jobId] = segmentsOf(params);
|
|
5880
|
-
return {
|
|
5902
|
+
return {
|
|
5903
|
+
status: 200,
|
|
5904
|
+
body: jobBody(jobOf(services, sessionId, jobId, request.subject))
|
|
5905
|
+
};
|
|
5881
5906
|
},
|
|
5882
|
-
"GET /compute/sessions/{}/jobs/{}/state": async ({
|
|
5907
|
+
"GET /compute/sessions/{}/jobs/{}/state": async ({
|
|
5908
|
+
services,
|
|
5909
|
+
params,
|
|
5910
|
+
request
|
|
5911
|
+
}) => {
|
|
5883
5912
|
const [sessionId, jobId] = segmentsOf(params);
|
|
5884
5913
|
return {
|
|
5885
5914
|
status: 200,
|
|
5886
|
-
body: jobOf(services, sessionId, jobId).state
|
|
5915
|
+
body: jobOf(services, sessionId, jobId, request.subject).state
|
|
5887
5916
|
};
|
|
5888
5917
|
},
|
|
5889
5918
|
"GET /compute/sessions/{}/jobs/{}/log/content": async ({
|
|
@@ -5892,7 +5921,7 @@ var SASjsApi = (() => {
|
|
|
5892
5921
|
request
|
|
5893
5922
|
}) => {
|
|
5894
5923
|
const [sessionId, jobId] = segmentsOf(params);
|
|
5895
|
-
const job = jobOf(services, sessionId, jobId);
|
|
5924
|
+
const job = jobOf(services, sessionId, jobId, request.subject);
|
|
5896
5925
|
const start = Number(request.query?.start ?? 0) || 0;
|
|
5897
5926
|
const limit = Number(request.query?.limit ?? 0) || 0;
|
|
5898
5927
|
const lines = job.log.slice(start, limit ? start + limit : void 0);
|
|
@@ -6126,6 +6155,10 @@ var SASjsApi = (() => {
|
|
|
6126
6155
|
modifiedTimeStamp: EMULATED_NOW,
|
|
6127
6156
|
memberCount: listing.files.length + listing.folders.length,
|
|
6128
6157
|
parentFolderUri: `/folders/folders/${idFor(parent)}`,
|
|
6158
|
+
// the capture's folder shape carries `properties`, and this body is the one a
|
|
6159
|
+
// real folder is read through: answering only the recycle bin with it left a
|
|
6160
|
+
// client reading `folder.properties` against nothing
|
|
6161
|
+
properties: { allowMove: "true" },
|
|
6129
6162
|
links: linksFor2(`/folders/folders/${id}`)
|
|
6130
6163
|
};
|
|
6131
6164
|
};
|
|
@@ -6200,20 +6233,57 @@ var SASjsApi = (() => {
|
|
|
6200
6233
|
}
|
|
6201
6234
|
};
|
|
6202
6235
|
},
|
|
6203
|
-
"GET /types/types": async () =>
|
|
6204
|
-
|
|
6205
|
-
|
|
6206
|
-
|
|
6207
|
-
|
|
6236
|
+
"GET /types/types": async ({ request }) => {
|
|
6237
|
+
const limit = Number(request.query?.limit ?? 0) || 0;
|
|
6238
|
+
const item = {
|
|
6239
|
+
name: "file",
|
|
6240
|
+
label: "File",
|
|
6241
|
+
description: "A file type",
|
|
6242
|
+
mediaType: "application/octet-stream",
|
|
6243
|
+
resourceUri: "/types/types/file",
|
|
6244
|
+
iconUri: "/types/types/file/icon",
|
|
6245
|
+
tags: ["file"],
|
|
6246
|
+
version: 1,
|
|
6247
|
+
links: [
|
|
6208
6248
|
{
|
|
6209
|
-
|
|
6210
|
-
|
|
6211
|
-
|
|
6212
|
-
|
|
6249
|
+
href: "/types/types/file",
|
|
6250
|
+
uri: "/types/types/file",
|
|
6251
|
+
rel: "self",
|
|
6252
|
+
method: "GET",
|
|
6253
|
+
type: "application/vnd.sas.type.definition"
|
|
6213
6254
|
}
|
|
6214
6255
|
]
|
|
6215
|
-
}
|
|
6216
|
-
|
|
6256
|
+
};
|
|
6257
|
+
return {
|
|
6258
|
+
status: 200,
|
|
6259
|
+
body: {
|
|
6260
|
+
accept: "application/json",
|
|
6261
|
+
name: "types",
|
|
6262
|
+
start: 0,
|
|
6263
|
+
limit,
|
|
6264
|
+
count: 1,
|
|
6265
|
+
version: 2,
|
|
6266
|
+
items: [item],
|
|
6267
|
+
links: [
|
|
6268
|
+
{
|
|
6269
|
+
href: "/types/types",
|
|
6270
|
+
uri: "/types/types",
|
|
6271
|
+
rel: "collection",
|
|
6272
|
+
method: "GET",
|
|
6273
|
+
type: "application/vnd.sas.collection",
|
|
6274
|
+
itemType: "typeDef"
|
|
6275
|
+
},
|
|
6276
|
+
{
|
|
6277
|
+
href: "/types/types",
|
|
6278
|
+
uri: "/types/types",
|
|
6279
|
+
rel: "self",
|
|
6280
|
+
method: "GET",
|
|
6281
|
+
type: "application/vnd.sas.collection"
|
|
6282
|
+
}
|
|
6283
|
+
]
|
|
6284
|
+
}
|
|
6285
|
+
};
|
|
6286
|
+
},
|
|
6217
6287
|
"GET /folders/folders/@item": async ({ services, request }) => ({
|
|
6218
6288
|
status: 200,
|
|
6219
6289
|
body: await folderBody(
|
|
@@ -6430,6 +6500,8 @@ var SASjsApi = (() => {
|
|
|
6430
6500
|
}
|
|
6431
6501
|
};
|
|
6432
6502
|
try {
|
|
6503
|
+
if (request.subject === void 0 && request.token !== void 0 && (found.operation.id === "POST /compute/contexts/{}/sessions" || found.operation.path.startsWith("/compute/sessions/")))
|
|
6504
|
+
throw new ApiError(401, "A valid caller is required.");
|
|
6433
6505
|
const answer = await handler({
|
|
6434
6506
|
services,
|
|
6435
6507
|
request,
|
|
@@ -7422,6 +7494,82 @@ var SASjsApi = (() => {
|
|
|
7422
7494
|
}
|
|
7423
7495
|
];
|
|
7424
7496
|
|
|
7497
|
+
// src/corpus/viya/replay.ts
|
|
7498
|
+
var KEY_BY_SEGMENT = {
|
|
7499
|
+
contexts: "context",
|
|
7500
|
+
sessions: "session",
|
|
7501
|
+
jobs: "job",
|
|
7502
|
+
folders: "folder",
|
|
7503
|
+
files: "file",
|
|
7504
|
+
definitions: "definition",
|
|
7505
|
+
variables: "variable"
|
|
7506
|
+
};
|
|
7507
|
+
var requestFor = (viyaCase, state = {}, queryValues = {}) => {
|
|
7508
|
+
const [method, template] = viyaCase.route.split(" ");
|
|
7509
|
+
const unresolved = [];
|
|
7510
|
+
return build(
|
|
7511
|
+
method,
|
|
7512
|
+
template.split("/"),
|
|
7513
|
+
viyaCase,
|
|
7514
|
+
state,
|
|
7515
|
+
queryValues,
|
|
7516
|
+
unresolved
|
|
7517
|
+
);
|
|
7518
|
+
};
|
|
7519
|
+
var build = (method, segments, viyaCase, state, queryValues, unresolved) => {
|
|
7520
|
+
let previousSegment = "";
|
|
7521
|
+
const filled = segments.map((segment) => {
|
|
7522
|
+
if (segment !== "{}") {
|
|
7523
|
+
previousSegment = segment;
|
|
7524
|
+
return segment;
|
|
7525
|
+
}
|
|
7526
|
+
const key = KEY_BY_SEGMENT[previousSegment] ?? previousSegment;
|
|
7527
|
+
const id = state[key];
|
|
7528
|
+
if (id === void 0) {
|
|
7529
|
+
unresolved.push(key);
|
|
7530
|
+
return "{}";
|
|
7531
|
+
}
|
|
7532
|
+
return id;
|
|
7533
|
+
});
|
|
7534
|
+
let path = filled.join("/");
|
|
7535
|
+
const omittedQueries = [];
|
|
7536
|
+
const params = [];
|
|
7537
|
+
for (const name of viyaCase.queries) {
|
|
7538
|
+
const value = queryValues[name];
|
|
7539
|
+
if (value === void 0) omittedQueries.push(name);
|
|
7540
|
+
else params.push(`${encodeURIComponent(name)}=${encodeURIComponent(value)}`);
|
|
7541
|
+
}
|
|
7542
|
+
if (params.length) path += (path.includes("?") ? "&" : "?") + params.join("&");
|
|
7543
|
+
return { method, path, unresolved, omittedQueries };
|
|
7544
|
+
};
|
|
7545
|
+
var shapeMismatches = (shape, body, where = "body") => {
|
|
7546
|
+
if (shape === "object")
|
|
7547
|
+
return isRecord(body) ? [] : [`${where}: expected an object, got ${typeName(body)}`];
|
|
7548
|
+
if (shape === "array")
|
|
7549
|
+
return Array.isArray(body) ? [] : [`${where}: expected an array, got ${typeName(body)}`];
|
|
7550
|
+
if (Array.isArray(shape)) {
|
|
7551
|
+
if (!Array.isArray(body))
|
|
7552
|
+
return [`${where}: expected an array, got ${typeName(body)}`];
|
|
7553
|
+
const first = body[0];
|
|
7554
|
+
return first === void 0 || shape.length === 0 ? [] : shapeMismatches(shape[0], first, `${where}[0]`);
|
|
7555
|
+
}
|
|
7556
|
+
if (shape && typeof shape === "object") {
|
|
7557
|
+
if (!isRecord(body))
|
|
7558
|
+
return [`${where}: expected an object, got ${typeName(body)}`];
|
|
7559
|
+
const record = body;
|
|
7560
|
+
return Object.keys(shape).flatMap(
|
|
7561
|
+
(key) => key in record ? shapeMismatches(
|
|
7562
|
+
shape[key],
|
|
7563
|
+
record[key],
|
|
7564
|
+
`${where}.${key}`
|
|
7565
|
+
) : [`${where}.${key}: missing from the answer`]
|
|
7566
|
+
);
|
|
7567
|
+
}
|
|
7568
|
+
return typeof body === String(shape) ? [] : [`${where}: expected ${String(shape)}, got ${typeName(body)}`];
|
|
7569
|
+
};
|
|
7570
|
+
var typeName = (value) => value === null ? "null" : Array.isArray(value) ? "array" : typeof value;
|
|
7571
|
+
var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
7572
|
+
|
|
7425
7573
|
// src/appstream/bundle.ts
|
|
7426
7574
|
var APP_MANIFEST = "sasjs.app.json";
|
|
7427
7575
|
var FRONTEND_FOLDER = "web";
|
|
@@ -9667,16 +9815,16 @@ var SASjsApi = (() => {
|
|
|
9667
9815
|
var normaliseDiagnostics = (report) => {
|
|
9668
9816
|
if (!isObject2(report))
|
|
9669
9817
|
throw new Error("The diagnostics report is not an object.");
|
|
9670
|
-
const
|
|
9818
|
+
const build2 = requireObject(
|
|
9671
9819
|
report,
|
|
9672
9820
|
"build",
|
|
9673
9821
|
"diagnostics"
|
|
9674
9822
|
);
|
|
9675
|
-
requireString(
|
|
9676
|
-
requireString(
|
|
9677
|
-
if (!(
|
|
9823
|
+
requireString(build2, "version", "diagnostics build");
|
|
9824
|
+
requireString(build2, "gitHash", "diagnostics build");
|
|
9825
|
+
if (!(build2.buildDate === null || isString(build2.buildDate)))
|
|
9678
9826
|
throw new Error(
|
|
9679
|
-
`The diagnostics build states \`buildDate\` as ${JSON.stringify(
|
|
9827
|
+
`The diagnostics build states \`buildDate\` as ${JSON.stringify(build2.buildDate)}; the document states an ISO timestamp or null.`
|
|
9680
9828
|
);
|
|
9681
9829
|
const server = requireObject(
|
|
9682
9830
|
report,
|
|
@@ -30,37 +30,8 @@ const normaliseAppLoc = (appLoc) => {
|
|
|
30
30
|
return normalised;
|
|
31
31
|
};
|
|
32
32
|
exports.normaliseAppLoc = normaliseAppLoc;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
*
|
|
36
|
-
* `crypto.randomUUID` exists in Node and in a browser worker on https or localhost,
|
|
37
|
-
* which is where the mock drive runs. The fallback builds the same thing from
|
|
38
|
-
* `getRandomValues` rather than from `Math.random`, so a weaker environment does not
|
|
39
|
-
* quietly produce a weaker id.
|
|
40
|
-
*/
|
|
41
|
-
const newAppId = () => {
|
|
42
|
-
const webCrypto = globalThis.crypto;
|
|
43
|
-
if (typeof webCrypto?.randomUUID === 'function')
|
|
44
|
-
return webCrypto.randomUUID();
|
|
45
|
-
if (typeof webCrypto?.getRandomValues !== 'function')
|
|
46
|
-
throw new Error('No cryptographic source of randomness is available.');
|
|
47
|
-
const bytes = new Uint8Array(16);
|
|
48
|
-
webCrypto.getRandomValues(bytes);
|
|
49
|
-
// version 4, variant 10xx
|
|
50
|
-
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
|
51
|
-
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
52
|
-
const hex = Array.from(bytes)
|
|
53
|
-
.map((byte) => byte.toString(16).padStart(2, '0'))
|
|
54
|
-
.join('');
|
|
55
|
-
return [
|
|
56
|
-
hex.slice(0, 8),
|
|
57
|
-
hex.slice(8, 12),
|
|
58
|
-
hex.slice(12, 16),
|
|
59
|
-
hex.slice(16, 20),
|
|
60
|
-
hex.slice(20)
|
|
61
|
-
].join('-');
|
|
62
|
-
};
|
|
63
|
-
exports.newAppId = newAppId;
|
|
33
|
+
var uuid_js_1 = require("../uuid.js");
|
|
34
|
+
Object.defineProperty(exports, "newAppId", { enumerable: true, get: function () { return uuid_js_1.newUuidV4; } });
|
|
64
35
|
// no `i` flag: `newAppId` mints lower case and every lookup compares exactly, so
|
|
65
36
|
// a guard that accepts upper case would vouch for an id no lookup can find
|
|
66
37
|
const APP_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.shapeMismatches = exports.requestFor = void 0;
|
|
4
|
+
/** The segment a hole sits in, which is what names the id it takes. */
|
|
5
|
+
const KEY_BY_SEGMENT = {
|
|
6
|
+
contexts: 'context',
|
|
7
|
+
sessions: 'session',
|
|
8
|
+
jobs: 'job',
|
|
9
|
+
folders: 'folder',
|
|
10
|
+
files: 'file',
|
|
11
|
+
definitions: 'definition',
|
|
12
|
+
variables: 'variable'
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* The request a captured case stands for, with `{}` filled from the ids a replay
|
|
16
|
+
* has collected so far.
|
|
17
|
+
*
|
|
18
|
+
* A hole takes the id named by the segment before it (`/folders/folders/{}` is a
|
|
19
|
+
* folder). A hole the state cannot fill is reported, not guessed: a path built
|
|
20
|
+
* from a placeholder would answer a 404 that says nothing about the contract.
|
|
21
|
+
*/
|
|
22
|
+
const requestFor = (viyaCase, state = {}, queryValues = {}) => {
|
|
23
|
+
const [method, template] = viyaCase.route.split(' ');
|
|
24
|
+
const unresolved = [];
|
|
25
|
+
return build(method, template.split('/'), viyaCase, state, queryValues, unresolved);
|
|
26
|
+
};
|
|
27
|
+
exports.requestFor = requestFor;
|
|
28
|
+
/** Segments back into the path, filling each hole from the state. */
|
|
29
|
+
const build = (method, segments, viyaCase, state, queryValues, unresolved) => {
|
|
30
|
+
let previousSegment = '';
|
|
31
|
+
const filled = segments.map((segment) => {
|
|
32
|
+
if (segment !== '{}') {
|
|
33
|
+
previousSegment = segment;
|
|
34
|
+
return segment;
|
|
35
|
+
}
|
|
36
|
+
const key = KEY_BY_SEGMENT[previousSegment] ?? previousSegment;
|
|
37
|
+
const id = state[key];
|
|
38
|
+
if (id === undefined) {
|
|
39
|
+
unresolved.push(key);
|
|
40
|
+
return '{}';
|
|
41
|
+
}
|
|
42
|
+
return id;
|
|
43
|
+
});
|
|
44
|
+
let path = filled.join('/');
|
|
45
|
+
const omittedQueries = [];
|
|
46
|
+
const params = [];
|
|
47
|
+
// encoded by hand rather than with `URLSearchParams`: this module is compiled
|
|
48
|
+
// for the browser host as well as for node, and the package's build does not
|
|
49
|
+
// carry the DOM types that class needs
|
|
50
|
+
for (const name of viyaCase.queries) {
|
|
51
|
+
const value = queryValues[name];
|
|
52
|
+
if (value === undefined)
|
|
53
|
+
omittedQueries.push(name);
|
|
54
|
+
else
|
|
55
|
+
params.push(`${encodeURIComponent(name)}=${encodeURIComponent(value)}`);
|
|
56
|
+
}
|
|
57
|
+
if (params.length)
|
|
58
|
+
path += (path.includes('?') ? '&' : '?') + params.join('&');
|
|
59
|
+
return { method, path, unresolved, omittedQueries };
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Every place a captured shape and a body disagree, as readable strings.
|
|
63
|
+
*
|
|
64
|
+
* A shape's leaves are type names, so the comparison is on `typeof`; `'object'` is
|
|
65
|
+
* the depth cap and means "an object, contents not recorded". Unlike an
|
|
66
|
+
* assertion, this collects, so a host can report all the drift in one run instead
|
|
67
|
+
* of stopping at the first key - and a body with an element shows its element's
|
|
68
|
+
* shape, because an empty array proves nothing about it.
|
|
69
|
+
*/
|
|
70
|
+
const shapeMismatches = (shape, body, where = 'body') => {
|
|
71
|
+
if (shape === 'object')
|
|
72
|
+
return isRecord(body)
|
|
73
|
+
? []
|
|
74
|
+
: [`${where}: expected an object, got ${typeName(body)}`];
|
|
75
|
+
// `array` is a leaf the corpus really records (`properties: 'array'` on a job
|
|
76
|
+
// definition), and `typeof` never yields it: an array is `object`. Without this
|
|
77
|
+
// branch the comparison could never pass, and the message it produced -
|
|
78
|
+
// "expected array, got array" - contradicted itself
|
|
79
|
+
if (shape === 'array')
|
|
80
|
+
return Array.isArray(body)
|
|
81
|
+
? []
|
|
82
|
+
: [`${where}: expected an array, got ${typeName(body)}`];
|
|
83
|
+
if (Array.isArray(shape)) {
|
|
84
|
+
if (!Array.isArray(body))
|
|
85
|
+
return [`${where}: expected an array, got ${typeName(body)}`];
|
|
86
|
+
const first = body[0];
|
|
87
|
+
// Neither side can say anything when the shape is empty: an empty answer
|
|
88
|
+
// cannot demonstrate its element's shape, and an element shape the capture
|
|
89
|
+
// recorded as `[]` is the absence of one. Comparing a real element against
|
|
90
|
+
// `undefined` invents a drift - "expected undefined, got object" - that no
|
|
91
|
+
// host could act on.
|
|
92
|
+
return first === undefined || shape.length === 0
|
|
93
|
+
? []
|
|
94
|
+
: (0, exports.shapeMismatches)(shape[0], first, `${where}[0]`);
|
|
95
|
+
}
|
|
96
|
+
if (shape && typeof shape === 'object') {
|
|
97
|
+
if (!isRecord(body))
|
|
98
|
+
return [`${where}: expected an object, got ${typeName(body)}`];
|
|
99
|
+
const record = body;
|
|
100
|
+
return Object.keys(shape).flatMap((key) => key in record
|
|
101
|
+
? (0, exports.shapeMismatches)(shape[key], record[key], `${where}.${key}`)
|
|
102
|
+
: [`${where}.${key}: missing from the answer`]);
|
|
103
|
+
}
|
|
104
|
+
return typeof body === String(shape)
|
|
105
|
+
? []
|
|
106
|
+
: [`${where}: expected ${String(shape)}, got ${typeName(body)}`];
|
|
107
|
+
};
|
|
108
|
+
exports.shapeMismatches = shapeMismatches;
|
|
109
|
+
const typeName = (value) => value === null ? 'null' : Array.isArray(value) ? 'array' : typeof value;
|
|
110
|
+
/**
|
|
111
|
+
* An object with named fields, which is what every captured shape describes.
|
|
112
|
+
*
|
|
113
|
+
* An array is `typeof object` in JavaScript, so a body of `[]` would otherwise be
|
|
114
|
+
* compared as an object with no keys and reported as "missing every field" rather
|
|
115
|
+
* than as the array it is.
|
|
116
|
+
*/
|
|
117
|
+
const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
package/build/cjs/index.js
CHANGED
|
@@ -14,9 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.
|
|
18
|
-
exports.
|
|
19
|
-
exports.normaliseAppLoc = exports.newAppId = exports.isAppId = exports.escapeHtml = exports.createAppStreamWebService = exports.contentTypeFor = exports.cacheControlFor = exports.appRootOf = exports.NO_SUCH_APP = exports.DEFAULT_APP_PATH = exports.createDriveAppStreamStore = exports.APP_STREAM_INDEX = exports.splitAppBundle = exports.publishRequestFor = exports.parseAppManifest = exports.FRONTEND_FOLDER = exports.BACKEND_FOLDER = exports.APP_MANIFEST = void 0;
|
|
17
|
+
exports.AUTH_CONFIG_CORPUS = exports.ADMIN_CORPUS = exports.INFO_CORPUS = exports.CODE_CORPUS = exports.sanitiseDisplayName = exports.createRecordService = exports.createIdentityService = exports.HANDLED_ROUTES = exports.dispatch = exports.shapeMismatches = exports.requestFor = exports.VIYA_CORPUS = exports.VIYA_HANDLERS = exports.VIYA_OVERLAY = exports.findViyaOperation = exports.dispatchViya = exports.emulatedHeaders = exports.VIYA_TARGET_VERSION = exports.VIYA_CAPTURED_AT = exports.EMULATED_HEADER_VALUE = exports.EMULATED_HEADER = exports.UNRECORDED = exports.VIYA_TABLE = exports.SURFACE_CLI_VERSION = exports.SURFACE_ADAPTER_VERSION = exports.SURFACE = exports.TAG_CAPABILITIES = exports.OVERLAY = exports.findRoute = exports.routeById = exports.ROUTES = exports.MemoryDriveStore = exports.measureDeployTree = exports.isDeployTree = exports.deployTree = exports.decodeBase64 = exports.checkDeployTree = exports.DEPLOY_SUCCESS = exports.DEPLOY_PAYLOAD_BYTES = exports.DEPLOY_LIMITS = exports.ONE_NAME_ONLY = exports.DEPLOYMENT_FILE_ERROR = exports.createDeploymentFileService = exports.assertOneFileName = exports.createDriveService = exports.isRoot = exports.basename = exports.dirname = exports.hasBlockedExtension = exports.normaliseDrivePath = void 0;
|
|
18
|
+
exports.frontendFolderOf = exports.defaultAppName = exports.createAppStreamService = exports.checkPublishRequest = exports.appSummary = exports.APP_FOLDERS_ROOT = exports.servicesFor = exports.runCase = exports.PROVIDER_MANAGED = exports.ADMIN_SIGNED_IN = exports.RECORD_CORPUS = exports.RUNTIME_CORPUS = exports.MemorySessionRunner = exports.runTimeOfPath = exports.resolveProgram = exports.programNotFound = exports.DOCUMENTED_RUN_TIMES = exports.createRuntimeService = exports.CODE_DEBUG = exports.MemorySessionHost = exports.DEFAULT_SESSIONS = exports.createSessionService = exports.SESSION_CORPUS = exports.APP_CORPUS = exports.DEPLOY_CORPUS = exports.IDENTITY_CORPUS = exports.DRIVE_CORPUS = exports.parseIdentity = exports.IDENTITY_FORMAT = exports.DEFAULT_IDENTITY = exports.MemoryIdentityStore = exports.createDirectoryService = exports.normaliseLogFiles = exports.normaliseDiagnostics = exports.logLines = exports.createAdminService = exports.checkLogFileName = exports.MAX_LOG_LINES = exports.DEFAULT_LOG_LINES = exports.normaliseAuthConfig = exports.createAuthConfigService = exports.normaliseInfo = exports.createInfoService = exports.BROWSER_INFO = exports.withBundleVersion = exports.createHomeService = exports.NO_WEB_BUILD = exports.BUNDLE_NAME = exports.HOME_CORPUS = exports.DIRECTORY_CORPUS = void 0;
|
|
19
|
+
exports.normaliseAppLoc = exports.newAppId = exports.isAppId = exports.escapeHtml = exports.createAppStreamWebService = exports.contentTypeFor = exports.cacheControlFor = exports.appRootOf = exports.NO_SUCH_APP = exports.DEFAULT_APP_PATH = exports.createDriveAppStreamStore = exports.APP_STREAM_INDEX = exports.splitAppBundle = exports.publishRequestFor = exports.parseAppManifest = exports.FRONTEND_FOLDER = exports.BACKEND_FOLDER = exports.APP_MANIFEST = exports.MemoryAppStreamStore = exports.hasFrontendRoot = void 0;
|
|
20
20
|
/**
|
|
21
21
|
* `@sasjs/api` - the SASjs Server API described once.
|
|
22
22
|
*
|
|
@@ -89,6 +89,9 @@ var service_js_2 = require("./viya/service.js");
|
|
|
89
89
|
Object.defineProperty(exports, "VIYA_HANDLERS", { enumerable: true, get: function () { return service_js_2.VIYA_HANDLERS; } });
|
|
90
90
|
var operations_js_1 = require("./corpus/viya/operations.js");
|
|
91
91
|
Object.defineProperty(exports, "VIYA_CORPUS", { enumerable: true, get: function () { return operations_js_1.VIYA_CORPUS; } });
|
|
92
|
+
var replay_js_1 = require("./corpus/viya/replay.js");
|
|
93
|
+
Object.defineProperty(exports, "requestFor", { enumerable: true, get: function () { return replay_js_1.requestFor; } });
|
|
94
|
+
Object.defineProperty(exports, "shapeMismatches", { enumerable: true, get: function () { return replay_js_1.shapeMismatches; } });
|
|
92
95
|
var dispatch_js_2 = require("./host/dispatch.js");
|
|
93
96
|
Object.defineProperty(exports, "dispatch", { enumerable: true, get: function () { return dispatch_js_2.dispatch; } });
|
|
94
97
|
Object.defineProperty(exports, "HANDLED_ROUTES", { enumerable: true, get: function () { return dispatch_js_2.HANDLED_ROUTES; } });
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.newUuidV4 = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* A UUID v4 for Node and browser workers. Where `randomUUID` is unavailable,
|
|
6
|
+
* build it from `getRandomValues`; do not fall back to weaker randomness.
|
|
7
|
+
*/
|
|
8
|
+
const newUuidV4 = () => {
|
|
9
|
+
const webCrypto = globalThis.crypto;
|
|
10
|
+
if (typeof webCrypto?.randomUUID === 'function')
|
|
11
|
+
return webCrypto.randomUUID();
|
|
12
|
+
if (typeof webCrypto?.getRandomValues !== 'function')
|
|
13
|
+
throw new Error('No cryptographic source of randomness is available.');
|
|
14
|
+
const bytes = new Uint8Array(16);
|
|
15
|
+
webCrypto.getRandomValues(bytes);
|
|
16
|
+
// version 4, variant 10xx
|
|
17
|
+
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
|
18
|
+
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
19
|
+
const hex = Array.from(bytes)
|
|
20
|
+
.map((byte) => byte.toString(16).padStart(2, '0'))
|
|
21
|
+
.join('');
|
|
22
|
+
return [
|
|
23
|
+
hex.slice(0, 8),
|
|
24
|
+
hex.slice(8, 12),
|
|
25
|
+
hex.slice(12, 16),
|
|
26
|
+
hex.slice(16, 20),
|
|
27
|
+
hex.slice(20)
|
|
28
|
+
].join('-');
|
|
29
|
+
};
|
|
30
|
+
exports.newUuidV4 = newUuidV4;
|