@sasjs/api 0.51.0 → 0.51.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 CHANGED
@@ -37,6 +37,8 @@ The operations an application's calls add are declared rather than captured (`sr
37
37
 
38
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
39
 
40
+ **Viya mock compute context.** The list and detail expose one context, `SASjs Mock context`. Configure `contextName: 'SASjs Mock context'` when constructing a SASjs adapter for this mock: the adapter's own default remains `SAS Job Execution compute context` and does not match. Filtered name lookups return an empty collection for other names, not a synthesized context. The emulator supports only `eq(name,"...")` and `eq(name,'...')` with literal unescaped values, and case-sensitive matching; other filters and `sortBy` return 400 rather than silently being ignored. It supports non-negative integer `start` and `limit` (defaults 0 and 10); repeated or non-string values for `filter`, `start`, or `limit` return 400, and any supplied `sortBy` returns 400. `count` is the total matching collection size before pagination. This is a bounded mock contract, not a claim that these are the only valid Viya requests or that Viya uses the same error responses. The emulator does not execute SAS or provide a reusable batch identity.
41
+
40
42
  **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.
41
43
 
42
44
  **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.
package/build/browser.js CHANGED
@@ -1,4 +1,4 @@
1
- /* @sasjs/api 0.51.0 - the SASjs Server API, for a service worker. https://github.com/sasjs/api */
1
+ /* @sasjs/api 0.51.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;
@@ -5780,7 +5780,7 @@ var SASjsApi = (() => {
5780
5780
  };
5781
5781
 
5782
5782
  // src/viya/compute.ts
5783
- var DEFAULT_CONTEXT_NAME = "SAS Job Execution compute context";
5783
+ var DEFAULT_CONTEXT_NAME = "SASjs Mock context";
5784
5784
  var EMULATED_CONTEXT_ID = idFor("emulated-context", "context");
5785
5785
  var relLinks = (type, rels) => rels.map(([rel, href]) => ({ href, uri: href, rel, method: "GET", type }));
5786
5786
  var linksFor = (uri, type, collection2 = false, itemType = false) => [
@@ -5809,9 +5809,16 @@ var SASjsApi = (() => {
5809
5809
  ];
5810
5810
  var estateOf = (services) => estateFor(estateKeyOf(services.viya), seedOf(services.viya));
5811
5811
  var contextNameFrom = (filter) => {
5812
- if (!filter) return DEFAULT_CONTEXT_NAME;
5813
- const match = /name\s*,\s*'([^']*)'|name\s*,\s*"([^"]*)"/i.exec(filter);
5814
- return match?.[1] ?? match?.[2] ?? DEFAULT_CONTEXT_NAME;
5812
+ if (filter === void 0) return DEFAULT_CONTEXT_NAME;
5813
+ const match = typeof filter === "string" ? /^\s*eq\(\s*name\s*,\s*(?:'([^'\\]*)'|"([^"\\]*)")\s*\)\s*$/.exec(
5814
+ filter
5815
+ ) : null;
5816
+ if (!match)
5817
+ throw new ApiError(
5818
+ 400,
5819
+ 'Unsupported compute context filter. Use eq(name, "...").'
5820
+ );
5821
+ return match[1] ?? match[2];
5815
5822
  };
5816
5823
  var contextBody = (name, caller) => ({
5817
5824
  id: EMULATED_CONTEXT_ID,
@@ -5929,22 +5936,30 @@ var SASjsApi = (() => {
5929
5936
  };
5930
5937
  var COMPUTE_HANDLERS = {
5931
5938
  "GET /compute/contexts": async ({ request }) => {
5932
- const limit = Number(request.query?.limit ?? 0) || 0;
5939
+ if (request.query?.sortBy !== void 0)
5940
+ throw new ApiError(400, "Unsupported compute context sortBy.");
5941
+ const limitText = request.query?.limit;
5942
+ const startText = request.query?.start;
5943
+ const limitValue = limitText === void 0 ? "10" : limitText;
5944
+ const startValue = startText === void 0 ? "0" : startText;
5945
+ if (typeof startValue !== "string" || typeof limitValue !== "string" || !/^\d+$/.test(startValue) || !/^\d+$/.test(limitValue) || !Number.isSafeInteger(Number(startValue)) || !Number.isSafeInteger(Number(limitValue)))
5946
+ throw new ApiError(
5947
+ 400,
5948
+ "Unsupported compute context pagination. Use non-negative integers for start and limit."
5949
+ );
5950
+ const start = Number(startValue);
5951
+ const limit = Number(limitValue);
5952
+ const matches = contextNameFrom(request.query?.filter) === DEFAULT_CONTEXT_NAME ? [contextBody(DEFAULT_CONTEXT_NAME, callerId(request.subject))] : [];
5933
5953
  return {
5934
5954
  status: 200,
5935
5955
  body: {
5936
5956
  accept: "application/json",
5937
5957
  name: "contexts",
5938
- start: 0,
5958
+ start,
5939
5959
  limit,
5940
- count: 1,
5960
+ count: matches.length,
5941
5961
  version: 2,
5942
- items: [
5943
- contextBody(
5944
- contextNameFrom(request.query?.filter),
5945
- callerId(request.subject)
5946
- )
5947
- ],
5962
+ items: matches.slice(start, start + limit),
5948
5963
  links: linksFor(
5949
5964
  "/compute/contexts",
5950
5965
  "application/vnd.sas.compute.context",
@@ -6,18 +6,9 @@ const seed_js_1 = require("./seed.js");
6
6
  const sessions_js_1 = require("./sessions.js");
7
7
  const ids_js_1 = require("./ids.js");
8
8
  const overlay_js_1 = require("./overlay.js");
9
- /**
10
- * The name the emulator answers when a client asks for no particular context.
11
- *
12
- * It is the name of the context a Viya estate ships with, because that is the
13
- * name a client carries: `SASViyaApiClient.createSession` lists `/compute/contexts`
14
- * with no filter and picks the entry whose name it was given, so a default of the
15
- * emulator's own choosing fails every caller with a name that is right everywhere
16
- * else. A client may still name any context it likes - see `contextNameFrom` - and
17
- * the estate answers under that name.
18
- */
19
- exports.DEFAULT_CONTEXT_NAME = 'SAS Job Execution compute context';
20
- /** The one context id this estate mints, whatever name it is asked for. */
9
+ /** The one mock context, selected explicitly by clients. */
10
+ exports.DEFAULT_CONTEXT_NAME = 'SASjs Mock context';
11
+ /** The fixed id of the one emulated context. */
21
12
  exports.EMULATED_CONTEXT_ID = (0, ids_js_1.idFor)('emulated-context', 'context');
22
13
  /**
23
14
  * The links a client follows, by rel.
@@ -56,18 +47,19 @@ const linksFor = (uri, type, collection = false, itemType = false) => [
56
47
  ];
57
48
  const estateOf = (services) => (0, sessions_js_1.estateFor)((0, seed_js_1.estateKeyOf)(services.viya), (0, seed_js_1.seedOf)(services.viya));
58
49
  /**
59
- * The context name a client asked for.
60
- *
61
- * The adapter filters by name (`filter=eq(name,'X')`), so the answer is the one
62
- * emulated context under the requested name. A second estate is not something an
63
- * emulator can have, and an empty list would fail a client that has nothing wrong
64
- * with it.
50
+ * Read only the simple equality filter used by the adapter. Single-quoted
51
+ * names are also supported for existing mock clients. Escapes, other operators
52
+ * and compound expressions are refused rather than guessed.
65
53
  */
66
54
  const contextNameFrom = (filter) => {
67
- if (!filter)
55
+ if (filter === undefined)
68
56
  return exports.DEFAULT_CONTEXT_NAME;
69
- const match = /name\s*,\s*'([^']*)'|name\s*,\s*"([^"]*)"/i.exec(filter);
70
- return match?.[1] ?? match?.[2] ?? exports.DEFAULT_CONTEXT_NAME;
57
+ const match = typeof filter === 'string'
58
+ ? /^\s*eq\(\s*name\s*,\s*(?:'([^'\\]*)'|"([^"\\]*)")\s*\)\s*$/.exec(filter)
59
+ : null;
60
+ if (!match)
61
+ throw new types_js_1.ApiError(400, 'Unsupported compute context filter. Use eq(name, "...").');
62
+ return match[1] ?? match[2];
71
63
  };
72
64
  exports.contextNameFrom = contextNameFrom;
73
65
  const contextBody = (name, caller) => ({
@@ -207,19 +199,34 @@ const validCodeLines = (lines) => {
207
199
  };
208
200
  exports.COMPUTE_HANDLERS = {
209
201
  'GET /compute/contexts': async ({ request }) => {
210
- const limit = Number(request.query?.limit ?? 0) || 0;
202
+ if (request.query?.sortBy !== undefined)
203
+ throw new types_js_1.ApiError(400, 'Unsupported compute context sortBy.');
204
+ const limitText = request.query?.limit;
205
+ const startText = request.query?.start;
206
+ const limitValue = limitText === undefined ? '10' : limitText;
207
+ const startValue = startText === undefined ? '0' : startText;
208
+ if (typeof startValue !== 'string' ||
209
+ typeof limitValue !== 'string' ||
210
+ !/^\d+$/.test(startValue) ||
211
+ !/^\d+$/.test(limitValue) ||
212
+ !Number.isSafeInteger(Number(startValue)) ||
213
+ !Number.isSafeInteger(Number(limitValue)))
214
+ throw new types_js_1.ApiError(400, 'Unsupported compute context pagination. Use non-negative integers for start and limit.');
215
+ const start = Number(startValue);
216
+ const limit = Number(limitValue);
217
+ const matches = (0, exports.contextNameFrom)(request.query?.filter) === exports.DEFAULT_CONTEXT_NAME
218
+ ? [contextBody(exports.DEFAULT_CONTEXT_NAME, (0, ids_js_1.callerId)(request.subject))]
219
+ : [];
211
220
  return {
212
221
  status: 200,
213
222
  body: {
214
223
  accept: 'application/json',
215
224
  name: 'contexts',
216
- start: 0,
225
+ start,
217
226
  limit,
218
- count: 1,
227
+ count: matches.length,
219
228
  version: 2,
220
- items: [
221
- contextBody((0, exports.contextNameFrom)(request.query?.filter), (0, ids_js_1.callerId)(request.subject))
222
- ],
229
+ items: matches.slice(start, start + limit),
223
230
  links: linksFor('/compute/contexts', 'application/vnd.sas.compute.context', true)
224
231
  }
225
232
  };
@@ -7,35 +7,21 @@
7
7
  * because there is no SAS engine to reach for in a browser and no reason to reach
8
8
  * for one here.
9
9
  *
10
- * The context is the one place the emulator answers the question it was asked
11
- * rather than one it chose: a client names the context it wants by filter and the
12
- * emulated estate has exactly one, under that name. Its id does not move with the
13
- * name, so a session can be created for the id the list returned.
10
+ * The emulated estate has one context. Its list, detail and session creation
11
+ * share its fixed identity; a filter cannot rename it.
14
12
  */
15
13
  import type { ApiResponse, Services } from '../host/dispatch.js';
16
14
  import type { Subject } from '../identity/types.js';
17
- /**
18
- * The name the emulator answers when a client asks for no particular context.
19
- *
20
- * It is the name of the context a Viya estate ships with, because that is the
21
- * name a client carries: `SASViyaApiClient.createSession` lists `/compute/contexts`
22
- * with no filter and picks the entry whose name it was given, so a default of the
23
- * emulator's own choosing fails every caller with a name that is right everywhere
24
- * else. A client may still name any context it likes - see `contextNameFrom` - and
25
- * the estate answers under that name.
26
- */
27
- export declare const DEFAULT_CONTEXT_NAME = "SAS Job Execution compute context";
28
- /** The one context id this estate mints, whatever name it is asked for. */
15
+ /** The one mock context, selected explicitly by clients. */
16
+ export declare const DEFAULT_CONTEXT_NAME = "SASjs Mock context";
17
+ /** The fixed id of the one emulated context. */
29
18
  export declare const EMULATED_CONTEXT_ID: string;
30
19
  /**
31
- * The context name a client asked for.
32
- *
33
- * The adapter filters by name (`filter=eq(name,'X')`), so the answer is the one
34
- * emulated context under the requested name. A second estate is not something an
35
- * emulator can have, and an empty list would fail a client that has nothing wrong
36
- * with it.
20
+ * Read only the simple equality filter used by the adapter. Single-quoted
21
+ * names are also supported for existing mock clients. Escapes, other operators
22
+ * and compound expressions are refused rather than guessed.
37
23
  */
38
- export declare const contextNameFrom: (filter: string | undefined) => string;
24
+ export declare const contextNameFrom: (filter: unknown) => string;
39
25
  export declare const COMPUTE_HANDLERS: Record<string, (context: {
40
26
  services: Services;
41
27
  request: {
@@ -1 +1 @@
1
- {"version":3,"file":"compute.d.ts","sourceRoot":"","sources":["../../../src/viya/compute.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAChE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAOnD;;;;;;;;;GASG;AACH,eAAO,MAAM,oBAAoB,sCAAsC,CAAA;AAEvE,2EAA2E;AAC3E,eAAO,MAAM,mBAAmB,QAAuC,CAAA;AAgDvE;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,GAAI,QAAQ,MAAM,GAAG,SAAS,KAAG,MAM5D,CAAA;AA0KD,eAAO,MAAM,gBAAgB,EAAE,MAAM,CACnC,MAAM,EACN,CAAC,OAAO,EAAE;IACR,QAAQ,EAAE,QAAQ,CAAA;IAClB,OAAO,EAAE;QACP,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA;QAC1C,IAAI,CAAC,EAAE,OAAO,CAAA;QACd,KAAK,CAAC,EAAE,MAAM,CAAA;QACd,OAAO,CAAC,EAAE,OAAO,CAAA;KAClB,CAAA;IACD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAC/B,KAAK,OAAO,CAAC,WAAW,CAAC,CAwU3B,CAAA"}
1
+ {"version":3,"file":"compute.d.ts","sourceRoot":"","sources":["../../../src/viya/compute.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAChE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAOnD,4DAA4D;AAC5D,eAAO,MAAM,oBAAoB,uBAAuB,CAAA;AAExD,gDAAgD;AAChD,eAAO,MAAM,mBAAmB,QAAuC,CAAA;AAgDvE;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAI,QAAQ,OAAO,KAAG,MAgBjD,CAAA;AA0KD,eAAO,MAAM,gBAAgB,EAAE,MAAM,CACnC,MAAM,EACN,CAAC,OAAO,EAAE;IACR,QAAQ,EAAE,QAAQ,CAAA;IAClB,OAAO,EAAE;QACP,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA;QAC1C,IAAI,CAAC,EAAE,OAAO,CAAA;QACd,KAAK,CAAC,EAAE,MAAM,CAAA;QACd,OAAO,CAAC,EAAE,OAAO,CAAA;KAClB,CAAA;IACD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAC/B,KAAK,OAAO,CAAC,WAAW,CAAC,CA0V3B,CAAA"}
@@ -3,18 +3,9 @@ import { estateKeyOf, normaliseServerUrl, seedOf } from './seed.js';
3
3
  import { estateFor } from './sessions.js';
4
4
  import { idFor, callerId, EMULATED_NOW } from './ids.js';
5
5
  import { SESSION_VARIABLE_REFUSAL } from './overlay.js';
6
- /**
7
- * The name the emulator answers when a client asks for no particular context.
8
- *
9
- * It is the name of the context a Viya estate ships with, because that is the
10
- * name a client carries: `SASViyaApiClient.createSession` lists `/compute/contexts`
11
- * with no filter and picks the entry whose name it was given, so a default of the
12
- * emulator's own choosing fails every caller with a name that is right everywhere
13
- * else. A client may still name any context it likes - see `contextNameFrom` - and
14
- * the estate answers under that name.
15
- */
16
- export const DEFAULT_CONTEXT_NAME = 'SAS Job Execution compute context';
17
- /** The one context id this estate mints, whatever name it is asked for. */
6
+ /** The one mock context, selected explicitly by clients. */
7
+ export const DEFAULT_CONTEXT_NAME = 'SASjs Mock context';
8
+ /** The fixed id of the one emulated context. */
18
9
  export const EMULATED_CONTEXT_ID = idFor('emulated-context', 'context');
19
10
  /**
20
11
  * The links a client follows, by rel.
@@ -53,18 +44,19 @@ const linksFor = (uri, type, collection = false, itemType = false) => [
53
44
  ];
54
45
  const estateOf = (services) => estateFor(estateKeyOf(services.viya), seedOf(services.viya));
55
46
  /**
56
- * The context name a client asked for.
57
- *
58
- * The adapter filters by name (`filter=eq(name,'X')`), so the answer is the one
59
- * emulated context under the requested name. A second estate is not something an
60
- * emulator can have, and an empty list would fail a client that has nothing wrong
61
- * with it.
47
+ * Read only the simple equality filter used by the adapter. Single-quoted
48
+ * names are also supported for existing mock clients. Escapes, other operators
49
+ * and compound expressions are refused rather than guessed.
62
50
  */
63
51
  export const contextNameFrom = (filter) => {
64
- if (!filter)
52
+ if (filter === undefined)
65
53
  return DEFAULT_CONTEXT_NAME;
66
- const match = /name\s*,\s*'([^']*)'|name\s*,\s*"([^"]*)"/i.exec(filter);
67
- return match?.[1] ?? match?.[2] ?? DEFAULT_CONTEXT_NAME;
54
+ const match = typeof filter === 'string'
55
+ ? /^\s*eq\(\s*name\s*,\s*(?:'([^'\\]*)'|"([^"\\]*)")\s*\)\s*$/.exec(filter)
56
+ : null;
57
+ if (!match)
58
+ throw new ApiError(400, 'Unsupported compute context filter. Use eq(name, "...").');
59
+ return match[1] ?? match[2];
68
60
  };
69
61
  const contextBody = (name, caller) => ({
70
62
  id: EMULATED_CONTEXT_ID,
@@ -203,19 +195,34 @@ const validCodeLines = (lines) => {
203
195
  };
204
196
  export const COMPUTE_HANDLERS = {
205
197
  'GET /compute/contexts': async ({ request }) => {
206
- const limit = Number(request.query?.limit ?? 0) || 0;
198
+ if (request.query?.sortBy !== undefined)
199
+ throw new ApiError(400, 'Unsupported compute context sortBy.');
200
+ const limitText = request.query?.limit;
201
+ const startText = request.query?.start;
202
+ const limitValue = limitText === undefined ? '10' : limitText;
203
+ const startValue = startText === undefined ? '0' : startText;
204
+ if (typeof startValue !== 'string' ||
205
+ typeof limitValue !== 'string' ||
206
+ !/^\d+$/.test(startValue) ||
207
+ !/^\d+$/.test(limitValue) ||
208
+ !Number.isSafeInteger(Number(startValue)) ||
209
+ !Number.isSafeInteger(Number(limitValue)))
210
+ throw new ApiError(400, 'Unsupported compute context pagination. Use non-negative integers for start and limit.');
211
+ const start = Number(startValue);
212
+ const limit = Number(limitValue);
213
+ const matches = contextNameFrom(request.query?.filter) === DEFAULT_CONTEXT_NAME
214
+ ? [contextBody(DEFAULT_CONTEXT_NAME, callerId(request.subject))]
215
+ : [];
207
216
  return {
208
217
  status: 200,
209
218
  body: {
210
219
  accept: 'application/json',
211
220
  name: 'contexts',
212
- start: 0,
221
+ start,
213
222
  limit,
214
- count: 1,
223
+ count: matches.length,
215
224
  version: 2,
216
- items: [
217
- contextBody(contextNameFrom(request.query?.filter), callerId(request.subject))
218
- ],
225
+ items: matches.slice(start, start + limit),
219
226
  links: linksFor('/compute/contexts', 'application/vnd.sas.compute.context', true)
220
227
  }
221
228
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sasjs/api",
3
- "version": "0.51.0",
3
+ "version": "0.51.1",
4
4
  "description": "The SASjs Server API, described once - a generated route table, the services behind it, and the conformance corpus both hosts run",
5
5
  "license": "MIT",
6
6
  "author": "SASjs",