@sasjs/api 0.49.1 → 0.51.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/README.md +15 -0
- package/build/browser.js +453 -17
- package/build/cjs/viya/appSurface.js +241 -0
- package/build/cjs/viya/compute.js +127 -4
- package/build/cjs/viya/declared.js +107 -0
- package/build/cjs/viya/dispatch.js +3 -0
- package/build/cjs/viya/identity.js +191 -0
- package/build/cjs/viya/overlay.js +15 -6
- package/build/cjs/viya/service.js +3 -1
- package/build/esm/viya/appSurface.d.ts +51 -0
- package/build/esm/viya/appSurface.d.ts.map +1 -0
- package/build/esm/viya/appSurface.js +238 -0
- package/build/esm/viya/compute.d.ts.map +1 -1
- package/build/esm/viya/compute.js +128 -5
- package/build/esm/viya/declared.d.ts.map +1 -1
- package/build/esm/viya/declared.js +107 -0
- package/build/esm/viya/dispatch.d.ts.map +1 -1
- package/build/esm/viya/dispatch.js +4 -1
- package/build/esm/viya/identity.d.ts +34 -0
- package/build/esm/viya/identity.d.ts.map +1 -0
- package/build/esm/viya/identity.js +187 -0
- package/build/esm/viya/overlay.d.ts +1 -0
- package/build/esm/viya/overlay.d.ts.map +1 -1
- package/build/esm/viya/overlay.js +14 -5
- package/build/esm/viya/seed.d.ts +8 -4
- package/build/esm/viya/seed.d.ts.map +1 -1
- package/build/esm/viya/service.d.ts.map +1 -1
- package/build/esm/viya/service.js +3 -1
- package/build/esm/viya/sessions.d.ts +3 -1
- package/build/esm/viya/sessions.d.ts.map +1 -1
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -26,8 +26,23 @@ 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
|
+
**The emulated Viya estate's scope** is two measurements, not one.
|
|
30
|
+
`src/viya/surface.ts` classifies every path `@sasjs/adapter` was measured to build (`spec/viya/adapter-paths.json`, re-derived by `npm run check:scope` from the pinned adapter).
|
|
31
|
+
`src/viya/appSurface.ts` does the same for an application's own calls to the platform (`spec/viya/app-paths.json`, re-derived by `npm run check:app-scope -- <checkout>`), because an application can speak Viya REST directly where the adapter has no method: Data Controller's group, user and deploy screens do, and a scope measured from the adapter alone left those paths answering the emulator's 404.
|
|
32
|
+
Both lists are held against their inventory in both directions by `spec/viyaAppScope.spec.ts` and `spec/viyaTable.spec.ts`, and an in-scope path with no operation answering it fails the app spec - which is the failure the adapter-only scope could not see.
|
|
33
|
+
`check:app-scope` is not a CI step: it needs a checkout of the application, so it runs where that checkout exists and states so when it is not given one.
|
|
34
|
+
The operations an application's calls add are declared rather than captured (`src/viya/declared.ts`), since no recording pass driven by the adapter can observe them.
|
|
35
|
+
|
|
36
|
+
**Viya job log collection.** The CLI follows a job's `log` link and pages the returned line objects. The emulator supports non-negative decimal `start` and `limit` (default 0 and 10; maximum limit 2147483647, maximum start JavaScript's safe integer), with `count` equal to the total stored lines. Malformed or repeated values are refused with 400; `type` filtering and `timeout` are not implemented and are refused. Every stored string is labelled `NOTE`, without classifying its content; `/log/content` retains its existing behavior. Defaults, validation, link details and line types are mock choices, not verified Viya behavior. A successful collection read is not evidence of SAS execution; its lines come from the configured host or the mock generator.
|
|
37
|
+
|
|
38
|
+
**Viya mock SYSJOBID.** By default every session-variable lookup retains the 501 refusal. A trusted host may set `services.viya.mockSysjobid: true` in host configuration, never from HTTP data, to enable only the exact case-sensitive name `SYSJOBID` after normal subject, estate and session ownership checks. The value is `mock-<session UUID>`, stable only for that mock session and unmistakably synthetic: it is not a process ID, a SAS value or evidence of execution. The adapter's `printPid` nevertheless labels it `PID`; do not interpret it as a real one. Unknown variables remain 501 for an authorized live session; foreign, missing, deleted or ownerless sessions return 404, and unresolved credentials return 401. No subject and no token is the shared anonymous mock identity described below, not authentication. The [SAS getVariable documentation](https://developer.sas.com/rest-apis/compute/getVariable/index.md) specifies name, value, scope and representation version 1; the committed capture records link field types, not their values. `AUTOMATIC` and the single self link and its media type are mock-specific choices, not observed Viya values. The dispatch request carries no Accept header: this mock only returns a JSON-shaped resource and does not implement or negotiate SAS's documented `text/plain` or other Accept representations. Hosts must not enable it for clients relying on content negotiation.
|
|
39
|
+
|
|
29
40
|
**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
41
|
|
|
42
|
+
**Viya mock job submissions.** After resolving the session owner, the mock accepts an omitted request body or an object whose optional `code` is a string or an array of strings (including empty strings and arrays); omitted `code` becomes an empty string. Explicit null, non-object or array bodies, a null or non-string/non-array `code`, and arrays with non-string or sparse elements return 400 before job allocation, generated logging or executor invocation. This is a mock safety contract, not a verified Viya validation response. Valid code is still handed to any trusted host-configured executor, so hosts must enforce their own execution policy; the emulator alone does not execute SAS.
|
|
43
|
+
|
|
44
|
+
**Viya compute outcomes.** A trusted host's `services.viya.execute` may return `state: 'completed' | 'warning' | 'error' | 'failed'` and an optional integer `jobConditionCode`. These are host results, not request fields: never infer either from code, log text or webout. `warning` and `error` model explicit Compute outcomes; `failed` and thrown executor errors retain the existing mock infrastructure-failure behavior. Omitted state means `completed`; omitted condition code retains the historical `0` response, including while running, and does **not** prove SYSCC was zero. The host is responsible for supplying a valid integer and its meaning; the mock does not calculate or validate SYSCC. SAS documents SYSCC as the job condition code once a job completes; the mock does not emulate all Compute states or a SAS engine. Adapter 6.2.0 stops polling on warning, and treats error and failed as execution errors; web requests expecting webout have separate output-handling semantics.
|
|
45
|
+
|
|
31
46
|
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
47
|
|
|
33
48
|
**The app stream** (`createAppStreamService`, `createAppStreamWebService`, `splitAppBundle`) is what a deployed folder becomes when it is an app.
|
package/build/browser.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* @sasjs/api 0.
|
|
1
|
+
/* @sasjs/api 0.51.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;
|
|
@@ -5406,6 +5406,17 @@ var SASjsApi = (() => {
|
|
|
5406
5406
|
|
|
5407
5407
|
// src/viya/declared.ts
|
|
5408
5408
|
var DECLARED = [
|
|
5409
|
+
{
|
|
5410
|
+
id: "GET /compute/sessions/{}/jobs/{}/log",
|
|
5411
|
+
method: "GET",
|
|
5412
|
+
path: "/compute/sessions/{}/jobs/{}/log",
|
|
5413
|
+
steps: [],
|
|
5414
|
+
statuses: [200, 400, 404],
|
|
5415
|
+
queries: ["start", "limit"],
|
|
5416
|
+
request: { queries: ["start", "limit"], body: void 0 },
|
|
5417
|
+
shape: void 0,
|
|
5418
|
+
declared: "The CLI follows the job log link directly and pages it; the adapter capture reads the different /log/content operation. SAS Compute documents this as a collection of log line objects."
|
|
5419
|
+
},
|
|
5409
5420
|
{
|
|
5410
5421
|
id: "GET /compute/sessions/{}/filerefs/_webout/content",
|
|
5411
5422
|
method: "GET",
|
|
@@ -5420,6 +5431,102 @@ var SASjsApi = (() => {
|
|
|
5420
5431
|
// there is no JSON shape to record
|
|
5421
5432
|
shape: void 0,
|
|
5422
5433
|
declared: "The adapter fetches this only when a run expects a webout (`expectWebout`), and the recording pass submits a `%put` and reads the log instead. Without it an application cannot receive the data its service returns, so the emulator answers it from the job it just ran."
|
|
5434
|
+
},
|
|
5435
|
+
// The application's own identity reads. No capture describes these at all: the
|
|
5436
|
+
// recorder drives the client the adapter is, and Data Controller's group, user
|
|
5437
|
+
// and deploy screens call the identity service from the browser instead. That
|
|
5438
|
+
// is why they are declared rather than recorded, and why the scope they belong
|
|
5439
|
+
// to is stated in `src/viya/appSurface.ts`.
|
|
5440
|
+
{
|
|
5441
|
+
id: "GET /identities/groups",
|
|
5442
|
+
method: "GET",
|
|
5443
|
+
path: "/identities/groups",
|
|
5444
|
+
steps: [],
|
|
5445
|
+
statuses: [200],
|
|
5446
|
+
queries: ["sortBy", "limit", "start"],
|
|
5447
|
+
request: { queries: ["sortBy", "limit", "start"], body: void 0 },
|
|
5448
|
+
// a collection of groups, whose own shape Viya publishes rather than an
|
|
5449
|
+
// estate recording supplying it
|
|
5450
|
+
shape: void 0,
|
|
5451
|
+
declared: "The application fetches the group list twice on its deploy screen - for the admin-group dropdown and, filtered, for the caller own groups - and aborts the wizard when that read fails. The adapter never calls it, so no recording pass reaches it."
|
|
5452
|
+
},
|
|
5453
|
+
{
|
|
5454
|
+
id: "GET /identities/groups/{}/members",
|
|
5455
|
+
method: "GET",
|
|
5456
|
+
path: "/identities/groups/{}/members",
|
|
5457
|
+
steps: [],
|
|
5458
|
+
statuses: [200, 404],
|
|
5459
|
+
queries: ["limit"],
|
|
5460
|
+
request: { queries: ["limit"], body: void 0 },
|
|
5461
|
+
shape: void 0,
|
|
5462
|
+
declared: "The group screen lists the accounts that hold a group, following the members link the group list advertises. The adapter has no identity route beyond the caller, so a capture driven by it cannot reach this one."
|
|
5463
|
+
},
|
|
5464
|
+
{
|
|
5465
|
+
id: "GET /identities/users",
|
|
5466
|
+
method: "GET",
|
|
5467
|
+
path: "/identities/users",
|
|
5468
|
+
steps: [],
|
|
5469
|
+
statuses: [200],
|
|
5470
|
+
queries: ["limit", "start"],
|
|
5471
|
+
request: { queries: ["limit", "start"], body: void 0 },
|
|
5472
|
+
shape: void 0,
|
|
5473
|
+
declared: "The user screen lists the estate accounts. The adapter does not offer an account list and never requests one, so the recording pass has no way to observe it."
|
|
5474
|
+
},
|
|
5475
|
+
{
|
|
5476
|
+
id: "GET /identities/users/{}",
|
|
5477
|
+
method: "GET",
|
|
5478
|
+
path: "/identities/users/{}",
|
|
5479
|
+
steps: [],
|
|
5480
|
+
statuses: [200, 404],
|
|
5481
|
+
queries: [],
|
|
5482
|
+
request: { queries: [], body: void 0 },
|
|
5483
|
+
shape: void 0,
|
|
5484
|
+
declared: "The user screen reads one account from the id the list returned, for the profile above the memberships. The adapter asks only about the caller, which is a different operation with its own row."
|
|
5485
|
+
},
|
|
5486
|
+
{
|
|
5487
|
+
id: "GET /identities/users/@currentUser/memberships",
|
|
5488
|
+
method: "GET",
|
|
5489
|
+
path: "/identities/users/@currentUser/memberships",
|
|
5490
|
+
steps: [],
|
|
5491
|
+
statuses: [200],
|
|
5492
|
+
queries: ["limit", "start"],
|
|
5493
|
+
request: { queries: ["limit", "start"], body: void 0 },
|
|
5494
|
+
shape: void 0,
|
|
5495
|
+
declared: "The deploy screen filters the admin-group list to the groups the caller belongs to, and shows every group when this read fails. The adapter reads the caller itself but never the caller memberships."
|
|
5496
|
+
},
|
|
5497
|
+
{
|
|
5498
|
+
id: "GET /identities/users/{}/memberships",
|
|
5499
|
+
method: "GET",
|
|
5500
|
+
path: "/identities/users/{}/memberships",
|
|
5501
|
+
steps: [],
|
|
5502
|
+
statuses: [200, 401],
|
|
5503
|
+
queries: ["limit", "start"],
|
|
5504
|
+
request: { queries: ["limit", "start"], body: void 0 },
|
|
5505
|
+
shape: void 0,
|
|
5506
|
+
declared: "The user screen lists the groups any account holds, addressed by the id the list returned. It is the same answer as the caller own memberships for one id, and the adapter asks for neither."
|
|
5507
|
+
},
|
|
5508
|
+
{
|
|
5509
|
+
id: "GET /identities/users/{}/avatar/content",
|
|
5510
|
+
method: "GET",
|
|
5511
|
+
path: "/identities/users/{}/avatar/content",
|
|
5512
|
+
steps: [],
|
|
5513
|
+
statuses: [404],
|
|
5514
|
+
queries: [],
|
|
5515
|
+
request: { queries: [], body: void 0 },
|
|
5516
|
+
// the body is an image when an estate holds one: there is no JSON shape
|
|
5517
|
+
shape: void 0,
|
|
5518
|
+
declared: "The header renders the caller avatar from this URL, and an estate whose identity carries no avatar answers 404 so the client falls back to its own image. The adapter has no avatar read."
|
|
5519
|
+
},
|
|
5520
|
+
{
|
|
5521
|
+
id: "GET /compute/contexts/{}",
|
|
5522
|
+
method: "GET",
|
|
5523
|
+
path: "/compute/contexts/{}",
|
|
5524
|
+
steps: [],
|
|
5525
|
+
statuses: [200, 404],
|
|
5526
|
+
queries: [],
|
|
5527
|
+
request: { queries: [], body: void 0 },
|
|
5528
|
+
shape: void 0,
|
|
5529
|
+
declared: "The deploy screen reads each context in full, because the list view carries neither the batch identity nor the reuse setting it filters on. The capture recorded the list only, so the read it follows with is stated here."
|
|
5423
5530
|
}
|
|
5424
5531
|
];
|
|
5425
5532
|
var VIYA_OPERATIONS = [...VIYA_TABLE, ...DECLARED];
|
|
@@ -5427,6 +5534,7 @@ var SASjsApi = (() => {
|
|
|
5427
5534
|
// src/viya/overlay.ts
|
|
5428
5535
|
var NEEDS_AUTH = "The token endpoint is answered by the host that mounts the emulator, which owns the token port.";
|
|
5429
5536
|
var NEEDS_JOBS = "The emulator answers the compute and content families; the job definitions a deploy creates and the executions a run submits are not modelled yet.";
|
|
5537
|
+
var SESSION_VARIABLE_REFUSAL = "GET /compute/sessions/{}/variables/{} is not emulated. The emulator does not model session variables; the client reads these only to log the pid of a job it is about to submit (SYSJOBID), and any name it asks for is refused here rather than answered with a value the emulator did not run.";
|
|
5430
5538
|
var VIYA_OVERLAY = {
|
|
5431
5539
|
// answered here
|
|
5432
5540
|
"POST /folders/folders": { implemented: true },
|
|
@@ -5436,13 +5544,24 @@ var SASjsApi = (() => {
|
|
|
5436
5544
|
"GET /folders/folders/@item": { implemented: true },
|
|
5437
5545
|
"GET /folders/folders/@myRecycleBin": { implemented: true },
|
|
5438
5546
|
"GET /identities/users/@currentUser": { implemented: true },
|
|
5547
|
+
// answered here: the application's own identity reads, declared rather than
|
|
5548
|
+
// captured - see src/viya/appSurface.ts for the scope they belong to
|
|
5549
|
+
"GET /identities/groups": { implemented: true },
|
|
5550
|
+
"GET /identities/groups/{}/members": { implemented: true },
|
|
5551
|
+
"GET /identities/users": { implemented: true },
|
|
5552
|
+
"GET /identities/users/{}": { implemented: true },
|
|
5553
|
+
"GET /identities/users/@currentUser/memberships": { implemented: true },
|
|
5554
|
+
"GET /identities/users/{}/memberships": { implemented: true },
|
|
5555
|
+
"GET /identities/users/{}/avatar/content": { implemented: true },
|
|
5439
5556
|
"GET /types/types": { implemented: true },
|
|
5440
5557
|
// answered here: compute
|
|
5441
5558
|
"GET /compute/contexts": { implemented: true },
|
|
5559
|
+
"GET /compute/contexts/{}": { implemented: true },
|
|
5442
5560
|
"POST /compute/contexts/{}/sessions": { implemented: true },
|
|
5443
5561
|
"DELETE /compute/sessions/{}": { implemented: true },
|
|
5444
5562
|
"POST /compute/sessions/{}/jobs": { implemented: true },
|
|
5445
5563
|
"GET /compute/sessions/{}/jobs/{}": { implemented: true },
|
|
5564
|
+
"GET /compute/sessions/{}/jobs/{}/log": { implemented: true },
|
|
5446
5565
|
"GET /compute/sessions/{}/jobs/{}/log/content": { implemented: true },
|
|
5447
5566
|
"GET /compute/sessions/{}/jobs/{}/state": { implemented: true },
|
|
5448
5567
|
"GET /compute/sessions/{}/state": { implemented: true },
|
|
@@ -5473,11 +5592,8 @@ var SASjsApi = (() => {
|
|
|
5473
5592
|
implemented: false,
|
|
5474
5593
|
reason: "The emulator answers compute contexts from its seed; the launcher list a client falls back to is not modelled, and nothing on the emulated path asks for it."
|
|
5475
5594
|
},
|
|
5476
|
-
//
|
|
5477
|
-
"GET /compute/sessions/{}/variables/{}": {
|
|
5478
|
-
implemented: false,
|
|
5479
|
-
reason: "The emulator does not model session variables; the client reads these only to log the pid of a job it is about to submit (SYSJOBID), and any name it asks for is refused here rather than answered with a value the emulator did not run."
|
|
5480
|
-
},
|
|
5595
|
+
// Default refusal, with an explicit host opt-in for a synthetic SYSJOBID.
|
|
5596
|
+
"GET /compute/sessions/{}/variables/{}": { implemented: true },
|
|
5481
5597
|
// declined: the host owns the token port
|
|
5482
5598
|
"POST /SASLogon/oauth/token": { implemented: false, reason: NEEDS_AUTH },
|
|
5483
5599
|
// declared, not captured: the webout an application's service returns
|
|
@@ -5667,10 +5783,10 @@ var SASjsApi = (() => {
|
|
|
5667
5783
|
var DEFAULT_CONTEXT_NAME = "SAS Job Execution compute context";
|
|
5668
5784
|
var EMULATED_CONTEXT_ID = idFor("emulated-context", "context");
|
|
5669
5785
|
var relLinks = (type, rels) => rels.map(([rel, href]) => ({ href, uri: href, rel, method: "GET", type }));
|
|
5670
|
-
var linksFor = (uri, type,
|
|
5786
|
+
var linksFor = (uri, type, collection2 = false, itemType = false) => [
|
|
5671
5787
|
// the collection link comes first, because that is the order the capture
|
|
5672
5788
|
// recorded and the item shape assertion walks the first element
|
|
5673
|
-
...
|
|
5789
|
+
...collection2 ? [
|
|
5674
5790
|
{
|
|
5675
5791
|
href: `${uri}/members`,
|
|
5676
5792
|
uri: `${uri}/members`,
|
|
@@ -5707,6 +5823,21 @@ var SASjsApi = (() => {
|
|
|
5707
5823
|
"application/vnd.sas.compute.context"
|
|
5708
5824
|
)
|
|
5709
5825
|
});
|
|
5826
|
+
var contextDetailsBody = (caller) => ({
|
|
5827
|
+
...contextBody(DEFAULT_CONTEXT_NAME, caller),
|
|
5828
|
+
description: "The compute context an emulated estate answers for",
|
|
5829
|
+
creationTimeStamp: EMULATED_NOW,
|
|
5830
|
+
modifiedTimeStamp: EMULATED_NOW,
|
|
5831
|
+
modifiedBy: caller,
|
|
5832
|
+
launchType: "service",
|
|
5833
|
+
launchContext: { contextId: EMULATED_CONTEXT_ID },
|
|
5834
|
+
environment: { autoExecLines: [] },
|
|
5835
|
+
attributes: {
|
|
5836
|
+
reuseServerProcesses: "false",
|
|
5837
|
+
allowXCMD: "false",
|
|
5838
|
+
serverMinAvailable: "1"
|
|
5839
|
+
}
|
|
5840
|
+
});
|
|
5710
5841
|
var sessionBody = (services, session, autoExecLines, caller) => {
|
|
5711
5842
|
const { id } = session;
|
|
5712
5843
|
const uri = `/compute/sessions/${id}`;
|
|
@@ -5748,7 +5879,7 @@ var SASjsApi = (() => {
|
|
|
5748
5879
|
state: job.state,
|
|
5749
5880
|
creationTimeStamp: job.creationTimeStamp,
|
|
5750
5881
|
...job.completedTimeStamp ? { completedTimeStamp: job.completedTimeStamp } : {},
|
|
5751
|
-
jobConditionCode: 0,
|
|
5882
|
+
jobConditionCode: job.jobConditionCode ?? 0,
|
|
5752
5883
|
stateElapsedTime: 1,
|
|
5753
5884
|
listingStatistics: {
|
|
5754
5885
|
lineCount: job.log.length,
|
|
@@ -5791,6 +5922,11 @@ var SASjsApi = (() => {
|
|
|
5791
5922
|
return job;
|
|
5792
5923
|
};
|
|
5793
5924
|
var segmentsOf = (params) => params.segments;
|
|
5925
|
+
var validCodeLines = (lines) => {
|
|
5926
|
+
for (let i = 0; i < lines.length; i++)
|
|
5927
|
+
if (typeof lines[i] !== "string") return false;
|
|
5928
|
+
return true;
|
|
5929
|
+
};
|
|
5794
5930
|
var COMPUTE_HANDLERS = {
|
|
5795
5931
|
"GET /compute/contexts": async ({ request }) => {
|
|
5796
5932
|
const limit = Number(request.query?.limit ?? 0) || 0;
|
|
@@ -5817,6 +5953,14 @@ var SASjsApi = (() => {
|
|
|
5817
5953
|
}
|
|
5818
5954
|
};
|
|
5819
5955
|
},
|
|
5956
|
+
"GET /compute/contexts/{}": async ({ request, params }) => {
|
|
5957
|
+
if (params.id !== EMULATED_CONTEXT_ID)
|
|
5958
|
+
throw new ApiError(
|
|
5959
|
+
404,
|
|
5960
|
+
`No compute context matches the id ${params.id}. The emulated estate answers one context, and this is not its id.`
|
|
5961
|
+
);
|
|
5962
|
+
return { status: 200, body: contextDetailsBody(callerId(request.subject)) };
|
|
5963
|
+
},
|
|
5820
5964
|
"POST /compute/contexts/{}/sessions": async ({
|
|
5821
5965
|
services,
|
|
5822
5966
|
params,
|
|
@@ -5836,6 +5980,35 @@ var SASjsApi = (() => {
|
|
|
5836
5980
|
)
|
|
5837
5981
|
};
|
|
5838
5982
|
},
|
|
5983
|
+
"GET /compute/sessions/{}/variables/{}": async ({
|
|
5984
|
+
services,
|
|
5985
|
+
params,
|
|
5986
|
+
request
|
|
5987
|
+
}) => {
|
|
5988
|
+
if (services.viya?.mockSysjobid !== true)
|
|
5989
|
+
throw new ApiError(501, SESSION_VARIABLE_REFUSAL, {
|
|
5990
|
+
message: SESSION_VARIABLE_REFUSAL
|
|
5991
|
+
});
|
|
5992
|
+
if (request.subject === void 0 && request.token !== void 0)
|
|
5993
|
+
throw new ApiError(401, "A valid caller is required.");
|
|
5994
|
+
const [sessionId, name] = segmentsOf(params);
|
|
5995
|
+
const session = sessionOf(services, sessionId, request.subject);
|
|
5996
|
+
if (name !== "SYSJOBID")
|
|
5997
|
+
throw new ApiError(501, SESSION_VARIABLE_REFUSAL, {
|
|
5998
|
+
message: SESSION_VARIABLE_REFUSAL
|
|
5999
|
+
});
|
|
6000
|
+
const uri = `/compute/sessions/${encodeURIComponent(session.id)}/variables/SYSJOBID`;
|
|
6001
|
+
return {
|
|
6002
|
+
status: 200,
|
|
6003
|
+
body: {
|
|
6004
|
+
name: "SYSJOBID",
|
|
6005
|
+
value: `mock-${session.id}`,
|
|
6006
|
+
scope: "AUTOMATIC",
|
|
6007
|
+
version: 1,
|
|
6008
|
+
links: linksFor(uri, "application/vnd.sas.compute.session.variable")
|
|
6009
|
+
}
|
|
6010
|
+
};
|
|
6011
|
+
},
|
|
5839
6012
|
"GET /compute/sessions/{}/state": async ({ services, params, request }) => {
|
|
5840
6013
|
sessionOf(services, params.id, request.subject);
|
|
5841
6014
|
return { status: 200, body: "idle" };
|
|
@@ -5847,8 +6020,21 @@ var SASjsApi = (() => {
|
|
|
5847
6020
|
},
|
|
5848
6021
|
"POST /compute/sessions/{}/jobs": async ({ services, params, request }) => {
|
|
5849
6022
|
const session = sessionOf(services, params.id, request.subject);
|
|
5850
|
-
const
|
|
5851
|
-
|
|
6023
|
+
const input = request.body === void 0 ? {} : request.body;
|
|
6024
|
+
if (!input || typeof input !== "object" || Array.isArray(input))
|
|
6025
|
+
throw new ApiError(
|
|
6026
|
+
400,
|
|
6027
|
+
"Compute job code must be a string or an array of strings."
|
|
6028
|
+
);
|
|
6029
|
+
const body = input;
|
|
6030
|
+
const code = body.code;
|
|
6031
|
+
if (code !== void 0 && typeof code !== "string" && (!Array.isArray(code) || !validCodeLines(code)))
|
|
6032
|
+
throw new ApiError(
|
|
6033
|
+
400,
|
|
6034
|
+
"Compute job code must be a string or an array of strings."
|
|
6035
|
+
);
|
|
6036
|
+
const program = code ?? "";
|
|
6037
|
+
const job = estateOf(services).submit(session, { ...body, code: program });
|
|
5852
6038
|
const execute = services.viya?.execute;
|
|
5853
6039
|
if (!execute) {
|
|
5854
6040
|
job.state = "completed";
|
|
@@ -5858,13 +6044,14 @@ var SASjsApi = (() => {
|
|
|
5858
6044
|
job.state = "running";
|
|
5859
6045
|
job.log = [];
|
|
5860
6046
|
void execute({
|
|
5861
|
-
program
|
|
6047
|
+
program,
|
|
5862
6048
|
variables: body.variables,
|
|
5863
6049
|
name: body.name,
|
|
5864
6050
|
sessionId: session.id
|
|
5865
6051
|
}).then((ran) => {
|
|
5866
6052
|
job.log = ran.log.split("\n");
|
|
5867
6053
|
job.state = ran.state ?? "completed";
|
|
6054
|
+
job.jobConditionCode = ran.jobConditionCode;
|
|
5868
6055
|
if (ran.webout !== void 0) job.webout = ran.webout;
|
|
5869
6056
|
job.completedTimeStamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
5870
6057
|
}).catch((error) => {
|
|
@@ -5915,6 +6102,51 @@ var SASjsApi = (() => {
|
|
|
5915
6102
|
body: jobOf(services, sessionId, jobId, request.subject).state
|
|
5916
6103
|
};
|
|
5917
6104
|
},
|
|
6105
|
+
// The collection is a separate CLI call from the adapter's /log/content.
|
|
6106
|
+
"GET /compute/sessions/{}/jobs/{}/log": async ({
|
|
6107
|
+
services,
|
|
6108
|
+
params,
|
|
6109
|
+
request
|
|
6110
|
+
}) => {
|
|
6111
|
+
const [sessionId, jobId] = segmentsOf(params);
|
|
6112
|
+
const job = jobOf(services, sessionId, jobId, request.subject);
|
|
6113
|
+
const start = request.query?.start;
|
|
6114
|
+
const limit = request.query?.limit;
|
|
6115
|
+
const startValue = start === void 0 ? "0" : start;
|
|
6116
|
+
const limitValue = limit === void 0 ? "10" : limit;
|
|
6117
|
+
if (typeof startValue !== "string" || typeof limitValue !== "string" || !/^\d+$/.test(startValue) || !/^\d+$/.test(limitValue) || !Number.isSafeInteger(Number(startValue)) || !Number.isSafeInteger(Number(limitValue)) || Number(limitValue) > 2147483647)
|
|
6118
|
+
throw new ApiError(400, "Unsupported job log pagination.");
|
|
6119
|
+
if (request.query?.type !== void 0 || request.query?.timeout !== void 0)
|
|
6120
|
+
throw new ApiError(
|
|
6121
|
+
400,
|
|
6122
|
+
"Job log type and timeout are not supported by the emulator."
|
|
6123
|
+
);
|
|
6124
|
+
const offset = Number(startValue);
|
|
6125
|
+
const pageSize = Number(limitValue);
|
|
6126
|
+
const uri = `/compute/sessions/${job.sessionId}/jobs/${job.id}/log`;
|
|
6127
|
+
return {
|
|
6128
|
+
status: 200,
|
|
6129
|
+
body: {
|
|
6130
|
+
accept: "application/json",
|
|
6131
|
+
name: "log",
|
|
6132
|
+
start: offset,
|
|
6133
|
+
limit: pageSize,
|
|
6134
|
+
count: job.log.length,
|
|
6135
|
+
version: 2,
|
|
6136
|
+
items: job.log.slice(offset, offset + pageSize).map((line) => ({ line, type: "NOTE", version: 2 })),
|
|
6137
|
+
links: [
|
|
6138
|
+
{
|
|
6139
|
+
href: uri,
|
|
6140
|
+
uri,
|
|
6141
|
+
rel: "self",
|
|
6142
|
+
method: "GET",
|
|
6143
|
+
type: "application/vnd.sas.collection",
|
|
6144
|
+
itemType: "application/vnd.sas.compute.log.line"
|
|
6145
|
+
}
|
|
6146
|
+
]
|
|
6147
|
+
}
|
|
6148
|
+
};
|
|
6149
|
+
},
|
|
5918
6150
|
"GET /compute/sessions/{}/jobs/{}/log/content": async ({
|
|
5919
6151
|
services,
|
|
5920
6152
|
params,
|
|
@@ -6119,8 +6351,209 @@ var SASjsApi = (() => {
|
|
|
6119
6351
|
}
|
|
6120
6352
|
};
|
|
6121
6353
|
|
|
6354
|
+
// src/viya/identity.ts
|
|
6355
|
+
var requireRecords = (services) => {
|
|
6356
|
+
if (!services.records)
|
|
6357
|
+
throw new ApiError(
|
|
6358
|
+
501,
|
|
6359
|
+
"The emulated identity answers from the records service, which this host does not supply."
|
|
6360
|
+
);
|
|
6361
|
+
return services.records;
|
|
6362
|
+
};
|
|
6363
|
+
var callerOf = async (services, request) => request.subject ?? await services.identity?.authenticate(request.token);
|
|
6364
|
+
var userIdFrom = (segment, caller) => {
|
|
6365
|
+
if (segment.toLowerCase() !== "@currentuser") return segment;
|
|
6366
|
+
const id = caller?.userId;
|
|
6367
|
+
if (!id) throw new ApiError(401, "No caller is signed in.");
|
|
6368
|
+
return id;
|
|
6369
|
+
};
|
|
6370
|
+
var collection = (name, items, limit, uri, type) => {
|
|
6371
|
+
const page = limit > 0 ? items.slice(0, limit) : items;
|
|
6372
|
+
return {
|
|
6373
|
+
accept: "application/json",
|
|
6374
|
+
name,
|
|
6375
|
+
start: 0,
|
|
6376
|
+
// the value asked for is echoed, as the folder answers echo it: a caller
|
|
6377
|
+
// that asked for five and is told zero cannot tell what happened
|
|
6378
|
+
limit: limit || page.length,
|
|
6379
|
+
count: page.length,
|
|
6380
|
+
version: 2,
|
|
6381
|
+
items: page,
|
|
6382
|
+
links: [
|
|
6383
|
+
{
|
|
6384
|
+
href: uri,
|
|
6385
|
+
uri,
|
|
6386
|
+
rel: "self",
|
|
6387
|
+
method: "GET",
|
|
6388
|
+
type: "application/vnd.sas.collection",
|
|
6389
|
+
itemType: type
|
|
6390
|
+
}
|
|
6391
|
+
]
|
|
6392
|
+
};
|
|
6393
|
+
};
|
|
6394
|
+
var identityLinks = (uri, type) => [
|
|
6395
|
+
{ href: uri, uri, rel: "self", method: "GET", type }
|
|
6396
|
+
];
|
|
6397
|
+
var GROUP_TYPE = "application/vnd.sas.identity.group";
|
|
6398
|
+
var USER_TYPE = "application/vnd.sas.identity.user";
|
|
6399
|
+
var groupBody = (group, memberCount) => ({
|
|
6400
|
+
id: group.uid,
|
|
6401
|
+
name: group.name,
|
|
6402
|
+
description: group.description,
|
|
6403
|
+
providerId: "sas",
|
|
6404
|
+
state: "active",
|
|
6405
|
+
memberCount,
|
|
6406
|
+
creationTimeStamp: EMULATED_NOW,
|
|
6407
|
+
modifiedTimeStamp: EMULATED_NOW,
|
|
6408
|
+
version: 1,
|
|
6409
|
+
links: identityLinks(`/identities/groups/${group.uid}`, GROUP_TYPE)
|
|
6410
|
+
});
|
|
6411
|
+
var userBody = (user3) => ({
|
|
6412
|
+
id: user3.uid,
|
|
6413
|
+
// Viya's `name` is the identifier a person signs in with; the display name is
|
|
6414
|
+
// a separate field, and this is the one a member list shows
|
|
6415
|
+
name: user3.username,
|
|
6416
|
+
displayName: user3.displayName,
|
|
6417
|
+
providerId: "sas",
|
|
6418
|
+
state: "active",
|
|
6419
|
+
version: 1,
|
|
6420
|
+
links: identityLinks(`/identities/users/${user3.uid}`, USER_TYPE)
|
|
6421
|
+
});
|
|
6422
|
+
var membershipsOf = async (records, caller, uid) => {
|
|
6423
|
+
const users = await records.listUsers(caller);
|
|
6424
|
+
const user3 = users.find((item) => item.uid === uid) ?? users.find((item) => item.username === uid);
|
|
6425
|
+
const resolvedUid = user3?.uid ?? uid;
|
|
6426
|
+
const groups = await records.listGroups(caller);
|
|
6427
|
+
const found = [];
|
|
6428
|
+
for (const group of groups) {
|
|
6429
|
+
const details = await records.getGroup(caller, { uid: group.uid });
|
|
6430
|
+
if (details.users.some((member) => member.uid === resolvedUid))
|
|
6431
|
+
found.push(groupBody(group, details.users.length));
|
|
6432
|
+
}
|
|
6433
|
+
return found;
|
|
6434
|
+
};
|
|
6435
|
+
var IDENTITY_HANDLERS = {
|
|
6436
|
+
"GET /identities/groups": async ({ services, request }) => {
|
|
6437
|
+
const records = requireRecords(services);
|
|
6438
|
+
const caller = await callerOf(services, request);
|
|
6439
|
+
const limit = Number(request.query?.limit ?? 0) || 0;
|
|
6440
|
+
const sortBy = request.query?.sortBy;
|
|
6441
|
+
const groups = await records.listGroups(caller);
|
|
6442
|
+
const items = [];
|
|
6443
|
+
for (const group of groups) {
|
|
6444
|
+
const details = await records.getGroup(caller, { uid: group.uid });
|
|
6445
|
+
items.push(groupBody(group, details.users.length));
|
|
6446
|
+
}
|
|
6447
|
+
const ordered = sortBy && sortBy.toLowerCase() === "name" ? [...items].sort((left, right) => left.name.localeCompare(right.name)) : items;
|
|
6448
|
+
return {
|
|
6449
|
+
status: 200,
|
|
6450
|
+
body: collection(
|
|
6451
|
+
"groups",
|
|
6452
|
+
ordered,
|
|
6453
|
+
limit,
|
|
6454
|
+
"/identities/groups",
|
|
6455
|
+
GROUP_TYPE
|
|
6456
|
+
)
|
|
6457
|
+
};
|
|
6458
|
+
},
|
|
6459
|
+
"GET /identities/groups/{}/members": async ({
|
|
6460
|
+
services,
|
|
6461
|
+
request,
|
|
6462
|
+
params
|
|
6463
|
+
}) => {
|
|
6464
|
+
const records = requireRecords(services);
|
|
6465
|
+
const caller = await callerOf(services, request);
|
|
6466
|
+
const limit = Number(request.query?.limit ?? 0) || 0;
|
|
6467
|
+
const details = await records.getGroup(caller, { uid: params.id });
|
|
6468
|
+
const items = details.users.map((user3) => userBody(user3));
|
|
6469
|
+
return {
|
|
6470
|
+
status: 200,
|
|
6471
|
+
body: collection(
|
|
6472
|
+
"members",
|
|
6473
|
+
items,
|
|
6474
|
+
limit,
|
|
6475
|
+
`/identities/groups/${details.uid}/members`,
|
|
6476
|
+
USER_TYPE
|
|
6477
|
+
)
|
|
6478
|
+
};
|
|
6479
|
+
},
|
|
6480
|
+
"GET /identities/users": async ({ services, request }) => {
|
|
6481
|
+
const records = requireRecords(services);
|
|
6482
|
+
const caller = await callerOf(services, request);
|
|
6483
|
+
const limit = Number(request.query?.limit ?? 0) || 0;
|
|
6484
|
+
const users = await records.listUsers(caller);
|
|
6485
|
+
return {
|
|
6486
|
+
status: 200,
|
|
6487
|
+
body: collection(
|
|
6488
|
+
"users",
|
|
6489
|
+
users.map((user3) => userBody(user3)),
|
|
6490
|
+
limit,
|
|
6491
|
+
"/identities/users",
|
|
6492
|
+
USER_TYPE
|
|
6493
|
+
)
|
|
6494
|
+
};
|
|
6495
|
+
},
|
|
6496
|
+
"GET /identities/users/{}": async ({ services, request, params }) => {
|
|
6497
|
+
const records = requireRecords(services);
|
|
6498
|
+
const caller = await callerOf(services, request);
|
|
6499
|
+
const uid = userIdFrom(params.id, caller);
|
|
6500
|
+
const user3 = await records.getUser(caller, { uid });
|
|
6501
|
+
return { status: 200, body: userBody(user3) };
|
|
6502
|
+
},
|
|
6503
|
+
"GET /identities/users/@currentUser/memberships": async ({
|
|
6504
|
+
services,
|
|
6505
|
+
request
|
|
6506
|
+
}) => {
|
|
6507
|
+
const records = requireRecords(services);
|
|
6508
|
+
const caller = await callerOf(services, request);
|
|
6509
|
+
const limit = Number(request.query?.limit ?? 0) || 0;
|
|
6510
|
+
const uid = userIdFrom("@currentUser", caller);
|
|
6511
|
+
const items = await membershipsOf(records, caller, uid);
|
|
6512
|
+
return {
|
|
6513
|
+
status: 200,
|
|
6514
|
+
body: collection(
|
|
6515
|
+
"memberships",
|
|
6516
|
+
items,
|
|
6517
|
+
limit,
|
|
6518
|
+
"/identities/users/@currentUser/memberships",
|
|
6519
|
+
GROUP_TYPE
|
|
6520
|
+
)
|
|
6521
|
+
};
|
|
6522
|
+
},
|
|
6523
|
+
"GET /identities/users/{}/memberships": async ({
|
|
6524
|
+
services,
|
|
6525
|
+
request,
|
|
6526
|
+
params
|
|
6527
|
+
}) => {
|
|
6528
|
+
const records = requireRecords(services);
|
|
6529
|
+
const caller = await callerOf(services, request);
|
|
6530
|
+
const limit = Number(request.query?.limit ?? 0) || 0;
|
|
6531
|
+
const uid = userIdFrom(params.id, caller);
|
|
6532
|
+
const items = await membershipsOf(records, caller, uid);
|
|
6533
|
+
return {
|
|
6534
|
+
status: 200,
|
|
6535
|
+
body: collection(
|
|
6536
|
+
"memberships",
|
|
6537
|
+
items,
|
|
6538
|
+
limit,
|
|
6539
|
+
`/identities/users/${params.id}/memberships`,
|
|
6540
|
+
GROUP_TYPE
|
|
6541
|
+
)
|
|
6542
|
+
};
|
|
6543
|
+
},
|
|
6544
|
+
"GET /identities/users/{}/avatar/content": async ({
|
|
6545
|
+
services,
|
|
6546
|
+
request,
|
|
6547
|
+
params
|
|
6548
|
+
}) => {
|
|
6549
|
+
const caller = await callerOf(services, request);
|
|
6550
|
+
const uid = userIdFrom(params.id, caller);
|
|
6551
|
+
throw new ApiError(404, `No avatar is recorded for the user ${uid}.`);
|
|
6552
|
+
}
|
|
6553
|
+
};
|
|
6554
|
+
|
|
6122
6555
|
// src/viya/service.ts
|
|
6123
|
-
var linksFor2 = (uri,
|
|
6556
|
+
var linksFor2 = (uri, collection2 = false) => {
|
|
6124
6557
|
const self = {
|
|
6125
6558
|
href: uri,
|
|
6126
6559
|
uri,
|
|
@@ -6136,7 +6569,7 @@ var SASjsApi = (() => {
|
|
|
6136
6569
|
type: "application/vnd.sas.collection",
|
|
6137
6570
|
itemType: "folder"
|
|
6138
6571
|
};
|
|
6139
|
-
return
|
|
6572
|
+
return collection2 ? [members, self] : [self, members];
|
|
6140
6573
|
};
|
|
6141
6574
|
var folderBody = async (drive, path, caller) => {
|
|
6142
6575
|
const listing = await drive.list(path);
|
|
@@ -6420,7 +6853,8 @@ var SASjsApi = (() => {
|
|
|
6420
6853
|
};
|
|
6421
6854
|
},
|
|
6422
6855
|
...COMPUTE_HANDLERS,
|
|
6423
|
-
...FILE_HANDLERS
|
|
6856
|
+
...FILE_HANDLERS,
|
|
6857
|
+
...IDENTITY_HANDLERS
|
|
6424
6858
|
};
|
|
6425
6859
|
|
|
6426
6860
|
// src/viya/dispatch.ts
|
|
@@ -6490,6 +6924,8 @@ var SASjsApi = (() => {
|
|
|
6490
6924
|
message: `${found.operation.id} is not emulated. ${entry.reason ?? ""}`.trim()
|
|
6491
6925
|
}
|
|
6492
6926
|
};
|
|
6927
|
+
if (found.operation.id === "GET /compute/sessions/{}/variables/{}" && services.viya?.mockSysjobid !== true)
|
|
6928
|
+
return { status: 501, headers, body: { message: SESSION_VARIABLE_REFUSAL } };
|
|
6493
6929
|
const handler = VIYA_HANDLERS[found.operation.id];
|
|
6494
6930
|
if (!handler)
|
|
6495
6931
|
return {
|
|
@@ -12110,7 +12546,7 @@ var SASjsApi = (() => {
|
|
|
12110
12546
|
};
|
|
12111
12547
|
var createRuntimeService = (directory, runner, options = {}) => {
|
|
12112
12548
|
const runTimes = options.runTimes || DOCUMENTED_RUN_TIMES;
|
|
12113
|
-
const
|
|
12549
|
+
const callerOf2 = async (caller) => {
|
|
12114
12550
|
if (!caller) throw new ApiError(401, "Unauthorized");
|
|
12115
12551
|
const reader = await directory.userById(caller.userId);
|
|
12116
12552
|
if (!reader || !reader.isActive) throw new ApiError(401, "Unauthorized");
|
|
@@ -12167,7 +12603,7 @@ var SASjsApi = (() => {
|
|
|
12167
12603
|
return minutes;
|
|
12168
12604
|
};
|
|
12169
12605
|
const prepare = async (caller, request) => {
|
|
12170
|
-
const reader = await
|
|
12606
|
+
const reader = await callerOf2(caller);
|
|
12171
12607
|
const program = programOf2(request);
|
|
12172
12608
|
const vars = { ...request.vars || {} };
|
|
12173
12609
|
const debug = "code" in program ? CODE_DEBUG : parseDebugValue(vars._debug);
|