@sasjs/api 0.49.0 → 0.50.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.
Files changed (45) hide show
  1. package/README.md +11 -0
  2. package/build/browser.js +407 -47
  3. package/build/cjs/appstream/identity.js +2 -31
  4. package/build/cjs/uuid.js +30 -0
  5. package/build/cjs/viya/appSurface.js +241 -0
  6. package/build/cjs/viya/compute.js +71 -20
  7. package/build/cjs/viya/declared.js +96 -0
  8. package/build/cjs/viya/dispatch.js +10 -0
  9. package/build/cjs/viya/identity.js +191 -0
  10. package/build/cjs/viya/overlay.js +10 -0
  11. package/build/cjs/viya/seed.js +34 -8
  12. package/build/cjs/viya/service.js +3 -1
  13. package/build/cjs/viya/sessions.js +24 -10
  14. package/build/esm/appstream/identity.d.ts +1 -9
  15. package/build/esm/appstream/identity.d.ts.map +1 -1
  16. package/build/esm/appstream/identity.js +1 -30
  17. package/build/esm/identity/types.d.ts +2 -0
  18. package/build/esm/identity/types.d.ts.map +1 -1
  19. package/build/esm/uuid.d.ts +6 -0
  20. package/build/esm/uuid.d.ts.map +1 -0
  21. package/build/esm/uuid.js +26 -0
  22. package/build/esm/viya/appSurface.d.ts +51 -0
  23. package/build/esm/viya/appSurface.d.ts.map +1 -0
  24. package/build/esm/viya/appSurface.js +238 -0
  25. package/build/esm/viya/compute.d.ts.map +1 -1
  26. package/build/esm/viya/compute.js +73 -22
  27. package/build/esm/viya/declared.d.ts.map +1 -1
  28. package/build/esm/viya/declared.js +96 -0
  29. package/build/esm/viya/dispatch.d.ts +3 -0
  30. package/build/esm/viya/dispatch.d.ts.map +1 -1
  31. package/build/esm/viya/dispatch.js +11 -1
  32. package/build/esm/viya/identity.d.ts +34 -0
  33. package/build/esm/viya/identity.d.ts.map +1 -0
  34. package/build/esm/viya/identity.js +187 -0
  35. package/build/esm/viya/overlay.d.ts.map +1 -1
  36. package/build/esm/viya/overlay.js +10 -0
  37. package/build/esm/viya/seed.d.ts +29 -7
  38. package/build/esm/viya/seed.d.ts.map +1 -1
  39. package/build/esm/viya/seed.js +32 -7
  40. package/build/esm/viya/service.d.ts.map +1 -1
  41. package/build/esm/viya/service.js +3 -1
  42. package/build/esm/viya/sessions.d.ts +24 -6
  43. package/build/esm/viya/sessions.d.ts.map +1 -1
  44. package/build/esm/viya/sessions.js +24 -10
  45. package/package.json +3 -1
@@ -0,0 +1,187 @@
1
+ import { ApiError } from '../types.js';
2
+ import { EMULATED_NOW } from './ids.js';
3
+ /** The port these handlers read, or the capability the host did not supply. */
4
+ export const requireRecords = (services) => {
5
+ if (!services.records)
6
+ throw new ApiError(501, 'The emulated identity answers from the records service, which this host does not supply.');
7
+ return services.records;
8
+ };
9
+ /**
10
+ * The caller, from the subject a host resolved or from the token it forwarded.
11
+ *
12
+ * A host that already knows its caller passes `subject`; one that hands the
13
+ * emulator a bearer token (the server's Viya router does) gets the token read
14
+ * here, exactly as `GET /identities/users/@currentUser` reads it. Neither is
15
+ * optional in effect: an unauthenticated caller has no identity to answer about.
16
+ */
17
+ const callerOf = async (services, request) => request.subject ?? (await services.identity?.authenticate(request.token));
18
+ /**
19
+ * The `{}` a membership or avatar read was addressed to, as a uid.
20
+ *
21
+ * `@currentUser` is where Viya puts the caller's own account, and a client asks
22
+ * for it by that spelling. It is resolved here rather than given its own row so
23
+ * the handler has one shape to answer.
24
+ */
25
+ const userIdFrom = (segment, caller) => {
26
+ if (segment.toLowerCase() !== '@currentuser')
27
+ return segment;
28
+ const id = caller?.userId;
29
+ if (!id)
30
+ throw new ApiError(401, 'No caller is signed in.');
31
+ return id;
32
+ };
33
+ /** The paging fields every collection answer carries, as the captured ones do. */
34
+ const collection = (name, items, limit, uri, type) => {
35
+ const page = limit > 0 ? items.slice(0, limit) : items;
36
+ return {
37
+ accept: 'application/json',
38
+ name,
39
+ start: 0,
40
+ // the value asked for is echoed, as the folder answers echo it: a caller
41
+ // that asked for five and is told zero cannot tell what happened
42
+ limit: limit || page.length,
43
+ count: page.length,
44
+ version: 2,
45
+ items: page,
46
+ links: [
47
+ {
48
+ href: uri,
49
+ uri,
50
+ rel: 'self',
51
+ method: 'GET',
52
+ type: 'application/vnd.sas.collection',
53
+ itemType: type
54
+ }
55
+ ]
56
+ };
57
+ };
58
+ const identityLinks = (uri, type) => [
59
+ { href: uri, uri, rel: 'self', method: 'GET', type }
60
+ ];
61
+ const GROUP_TYPE = 'application/vnd.sas.identity.group';
62
+ const USER_TYPE = 'application/vnd.sas.identity.user';
63
+ /** A group as Viya represents one, from the store's record. */
64
+ const groupBody = (group, memberCount) => ({
65
+ id: group.uid,
66
+ name: group.name,
67
+ description: group.description,
68
+ providerId: 'sas',
69
+ state: 'active',
70
+ memberCount,
71
+ creationTimeStamp: EMULATED_NOW,
72
+ modifiedTimeStamp: EMULATED_NOW,
73
+ version: 1,
74
+ links: identityLinks(`/identities/groups/${group.uid}`, GROUP_TYPE)
75
+ });
76
+ /** A user as Viya represents one. */
77
+ const userBody = (user) => ({
78
+ id: user.uid,
79
+ // Viya's `name` is the identifier a person signs in with; the display name is
80
+ // a separate field, and this is the one a member list shows
81
+ name: user.username,
82
+ displayName: user.displayName,
83
+ providerId: 'sas',
84
+ state: 'active',
85
+ version: 1,
86
+ links: identityLinks(`/identities/users/${user.uid}`, USER_TYPE)
87
+ });
88
+ /** The groups a user is a member of, as Viya's memberships route answers them. */
89
+ const membershipsOf = async (records, caller, uid) => {
90
+ const users = await records.listUsers(caller);
91
+ // Viya clients may address a user by login name; prefer an exact uid when a
92
+ // login happens to equal another user's uid.
93
+ const user = users.find((item) => item.uid === uid) ??
94
+ users.find((item) => item.username === uid);
95
+ const resolvedUid = user?.uid ?? uid;
96
+ const groups = await records.listGroups(caller);
97
+ const found = [];
98
+ for (const group of groups) {
99
+ const details = await records.getGroup(caller, { uid: group.uid });
100
+ if (details.users.some((member) => member.uid === resolvedUid))
101
+ found.push(groupBody(group, details.users.length));
102
+ }
103
+ return found;
104
+ };
105
+ export const IDENTITY_HANDLERS = {
106
+ 'GET /identities/groups': async ({ services, request }) => {
107
+ const records = requireRecords(services);
108
+ const caller = await callerOf(services, request);
109
+ const limit = Number(request.query?.limit ?? 0) || 0;
110
+ const sortBy = request.query?.sortBy;
111
+ const groups = await records.listGroups(caller);
112
+ const items = [];
113
+ for (const group of groups) {
114
+ const details = await records.getGroup(caller, { uid: group.uid });
115
+ items.push(groupBody(group, details.users.length));
116
+ }
117
+ // `sortBy=name` is what the application asks for, and the store's order is
118
+ // not one: a screen that lists groups alphabetically asks the service for it
119
+ const ordered = sortBy && sortBy.toLowerCase() === 'name'
120
+ ? [...items].sort((left, right) => left.name.localeCompare(right.name))
121
+ : items;
122
+ return {
123
+ status: 200,
124
+ body: collection('groups', ordered, limit, '/identities/groups', GROUP_TYPE)
125
+ };
126
+ },
127
+ 'GET /identities/groups/{}/members': async ({ services, request, params }) => {
128
+ const records = requireRecords(services);
129
+ const caller = await callerOf(services, request);
130
+ const limit = Number(request.query?.limit ?? 0) || 0;
131
+ const details = await records.getGroup(caller, { uid: params.id });
132
+ const items = details.users.map((user) => userBody(user));
133
+ return {
134
+ status: 200,
135
+ body: collection('members', items, limit, `/identities/groups/${details.uid}/members`, USER_TYPE)
136
+ };
137
+ },
138
+ 'GET /identities/users': async ({ services, request }) => {
139
+ const records = requireRecords(services);
140
+ const caller = await callerOf(services, request);
141
+ const limit = Number(request.query?.limit ?? 0) || 0;
142
+ const users = await records.listUsers(caller);
143
+ return {
144
+ status: 200,
145
+ body: collection('users', users.map((user) => userBody(user)), limit, '/identities/users', USER_TYPE)
146
+ };
147
+ },
148
+ 'GET /identities/users/{}': async ({ services, request, params }) => {
149
+ const records = requireRecords(services);
150
+ const caller = await callerOf(services, request);
151
+ const uid = userIdFrom(params.id, caller);
152
+ const user = await records.getUser(caller, { uid });
153
+ return { status: 200, body: userBody(user) };
154
+ },
155
+ 'GET /identities/users/@currentUser/memberships': async ({ services, request }) => {
156
+ const records = requireRecords(services);
157
+ const caller = await callerOf(services, request);
158
+ const limit = Number(request.query?.limit ?? 0) || 0;
159
+ const uid = userIdFrom('@currentUser', caller);
160
+ const items = await membershipsOf(records, caller, uid);
161
+ return {
162
+ status: 200,
163
+ body: collection('memberships', items, limit, '/identities/users/@currentUser/memberships', GROUP_TYPE)
164
+ };
165
+ },
166
+ 'GET /identities/users/{}/memberships': async ({ services, request, params }) => {
167
+ const records = requireRecords(services);
168
+ const caller = await callerOf(services, request);
169
+ const limit = Number(request.query?.limit ?? 0) || 0;
170
+ const uid = userIdFrom(params.id, caller);
171
+ // the address the client used is the address echoed back, as the other
172
+ // answers do: a client that followed a rel is never told about another one
173
+ const items = await membershipsOf(records, caller, uid);
174
+ return {
175
+ status: 200,
176
+ body: collection('memberships', items, limit, `/identities/users/${params.id}/memberships`, GROUP_TYPE)
177
+ };
178
+ },
179
+ 'GET /identities/users/{}/avatar/content': async ({ services, request, params }) => {
180
+ const caller = await callerOf(services, request);
181
+ const uid = userIdFrom(params.id, caller);
182
+ // the estate's identity carries no avatar, and Viya answers a 404 for an
183
+ // account that has none - so a client's fallback image is what a real
184
+ // estate with none would show it
185
+ throw new ApiError(404, `No avatar is recorded for the user ${uid}.`);
186
+ }
187
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"overlay.d.ts","sourceRoot":"","sources":["../../../src/viya/overlay.ts"],"names":[],"mappings":"AAeA,MAAM,WAAW,gBAAgB;IAC/B,WAAW,EAAE,OAAO,CAAA;IACpB,6DAA6D;IAC7D,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAuBD,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAgEzD,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,oBAAoB,GAC/B,SAAS,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,EACzC,aAAY,KAAK,CAAC;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,CAAmB,KAClD,IAcF,CAAA"}
1
+ {"version":3,"file":"overlay.d.ts","sourceRoot":"","sources":["../../../src/viya/overlay.ts"],"names":[],"mappings":"AAeA,MAAM,WAAW,gBAAgB;IAC/B,WAAW,EAAE,OAAO,CAAA;IACpB,6DAA6D;IAC7D,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAuBD,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CA4EzD,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,oBAAoB,GAC/B,SAAS,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,EACzC,aAAY,KAAK,CAAC;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,CAAmB,KAClD,IAcF,CAAA"}
@@ -38,9 +38,19 @@ export const VIYA_OVERLAY = {
38
38
  'GET /folders/folders/@item': { implemented: true },
39
39
  'GET /folders/folders/@myRecycleBin': { implemented: true },
40
40
  'GET /identities/users/@currentUser': { implemented: true },
41
+ // answered here: the application's own identity reads, declared rather than
42
+ // captured - see src/viya/appSurface.ts for the scope they belong to
43
+ 'GET /identities/groups': { implemented: true },
44
+ 'GET /identities/groups/{}/members': { implemented: true },
45
+ 'GET /identities/users': { implemented: true },
46
+ 'GET /identities/users/{}': { implemented: true },
47
+ 'GET /identities/users/@currentUser/memberships': { implemented: true },
48
+ 'GET /identities/users/{}/memberships': { implemented: true },
49
+ 'GET /identities/users/{}/avatar/content': { implemented: true },
41
50
  'GET /types/types': { implemented: true },
42
51
  // answered here: compute
43
52
  'GET /compute/contexts': { implemented: true },
53
+ 'GET /compute/contexts/{}': { implemented: true },
44
54
  'POST /compute/contexts/{}/sessions': { implemented: true },
45
55
  'DELETE /compute/sessions/{}': { implemented: true },
46
56
  'POST /compute/sessions/{}/jobs': { implemented: true },
@@ -7,12 +7,21 @@
7
7
  * true after the next one, and a fixture committed today must match the answer
8
8
  * tomorrow.
9
9
  *
10
- * The seed is therefore the identity of the estate, and the identity of an estate
11
- * is the address clients already use to reach it, normalised so that one estate
12
- * spelled two ways is one string. There is no override: an address that differs is
13
- * a different estate with different data, by design. Anything that reads this
14
- * data - a fixture, a screenshot, a test - has to work whatever the address is,
15
- * because the address is all the identity there is.
10
+ * The seed is therefore what the estate's *generated data* draws from, and the
11
+ * identity of an estate is the address clients already use to reach it,
12
+ * normalised so that one estate spelled two ways is one string. There is no
13
+ * override: an address that differs is a different estate with different data,
14
+ * by design. Anything that reads this data - a fixture, a screenshot, a test -
15
+ * has to work whatever the address is, because the address is all the identity
16
+ * there is.
17
+ *
18
+ * The seed is a 32-bit digest of that address, which is wide enough to vary the
19
+ * generated numbers and narrow enough that two distinct addresses collide on it
20
+ * - by birthday, roughly one pair per few-billion addresses, and a search finds
21
+ * one in minutes. A collision makes two estates answer with the same numbers,
22
+ * which is cosmetic; anything that *stores* state per estate - the live session
23
+ * registry - must therefore key by the full address, never by the seed, and
24
+ * `estateKeyOf` is that key.
16
25
  *
17
26
  * An emulator with no address has not said which estate it is, so every such
18
27
  * estate shares one seed. That is the only honest default.
@@ -75,9 +84,22 @@ export declare const hash: (input: string) => number;
75
84
  * The number that makes this estate's generated data reproducible.
76
85
  *
77
86
  * The address is the only input: the same estate answers the same way every time,
78
- * and a different address is a different estate.
87
+ * and a different address is a different estate. A 32-bit digest, so it varies
88
+ * the numbers - it is not the estate's identity for anything that stores state
89
+ * (see `estateKeyOf`).
79
90
  */
80
91
  export declare const seedOf: (settings?: ViyaSeedSettings) => number;
92
+ /**
93
+ * The key a per-estate store is held under: the full normalised address.
94
+ *
95
+ * The seed is a 32-bit digest of this key, and two distinct addresses collide
96
+ * on it - a pair exists for any such digest, and a search finds one in
97
+ * minutes. A registry keyed by the seed would then hand two addresses one
98
+ * shared store, so state is keyed by the address itself: distinct addresses
99
+ * are distinct stores even when their seeds are one number, and two spellings
100
+ * of one address (which normalise to one string) remain one store.
101
+ */
102
+ export declare const estateKeyOf: (settings?: ViyaSeedSettings) => string;
81
103
  /**
82
104
  * A uniform generator over one seed (mulberry32).
83
105
  *
@@ -1 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AI,GAAI,OAAO,MAAM,KAAG,MASpC,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,MAAM,GAAI,WAAU,gBAAqB,KAAG,MAIxD,CAAA;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,WAAW,GAAI,WAAU,gBAAqB,KAAG,MAI7D,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,GAAI,MAAM,MAAM,KAAG,CAAC,MAAM,MAAM,CAarD,CAAA;AAED,4DAA4D;AAC5D,eAAO,MAAM,OAAO,GAAI,MAAM,MAAM,MAAM,EAAE,OAAO,MAAM,KAAG,MAChC,CAAA;AAE5B,oDAAoD;AACpD,eAAO,MAAM,QAAQ,GAAI,CAAC,EAAE,MAAM,MAAM,MAAM,EAAE,QAAQ,CAAC,EAAE,KAAG,CACxB,CAAA"}
@@ -7,12 +7,21 @@
7
7
  * true after the next one, and a fixture committed today must match the answer
8
8
  * tomorrow.
9
9
  *
10
- * The seed is therefore the identity of the estate, and the identity of an estate
11
- * is the address clients already use to reach it, normalised so that one estate
12
- * spelled two ways is one string. There is no override: an address that differs is
13
- * a different estate with different data, by design. Anything that reads this
14
- * data - a fixture, a screenshot, a test - has to work whatever the address is,
15
- * because the address is all the identity there is.
10
+ * The seed is therefore what the estate's *generated data* draws from, and the
11
+ * identity of an estate is the address clients already use to reach it,
12
+ * normalised so that one estate spelled two ways is one string. There is no
13
+ * override: an address that differs is a different estate with different data,
14
+ * by design. Anything that reads this data - a fixture, a screenshot, a test -
15
+ * has to work whatever the address is, because the address is all the identity
16
+ * there is.
17
+ *
18
+ * The seed is a 32-bit digest of that address, which is wide enough to vary the
19
+ * generated numbers and narrow enough that two distinct addresses collide on it
20
+ * - by birthday, roughly one pair per few-billion addresses, and a search finds
21
+ * one in minutes. A collision makes two estates answer with the same numbers,
22
+ * which is cosmetic; anything that *stores* state per estate - the live session
23
+ * registry - must therefore key by the full address, never by the seed, and
24
+ * `estateKeyOf` is that key.
16
25
  *
17
26
  * An emulator with no address has not said which estate it is, so every such
18
27
  * estate shares one seed. That is the only honest default.
@@ -78,12 +87,28 @@ export const hash = (input) => {
78
87
  * The number that makes this estate's generated data reproducible.
79
88
  *
80
89
  * The address is the only input: the same estate answers the same way every time,
81
- * and a different address is a different estate.
90
+ * and a different address is a different estate. A 32-bit digest, so it varies
91
+ * the numbers - it is not the estate's identity for anything that stores state
92
+ * (see `estateKeyOf`).
82
93
  */
83
94
  export const seedOf = (settings = {}) => {
84
95
  const address = normaliseServerUrl(settings.serverUrl);
85
96
  return hash(`url:${address || DEFAULT_SEED}`);
86
97
  };
98
+ /**
99
+ * The key a per-estate store is held under: the full normalised address.
100
+ *
101
+ * The seed is a 32-bit digest of this key, and two distinct addresses collide
102
+ * on it - a pair exists for any such digest, and a search finds one in
103
+ * minutes. A registry keyed by the seed would then hand two addresses one
104
+ * shared store, so state is keyed by the address itself: distinct addresses
105
+ * are distinct stores even when their seeds are one number, and two spellings
106
+ * of one address (which normalise to one string) remain one store.
107
+ */
108
+ export const estateKeyOf = (settings = {}) => {
109
+ const address = normaliseServerUrl(settings.serverUrl);
110
+ return address || DEFAULT_SEED;
111
+ };
87
112
  /**
88
113
  * A uniform generator over one seed (mulberry32).
89
114
  *
@@ -1 +1 @@
1
- {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/viya/service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAChE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAiJnD,gEAAgE;AAChE,eAAO,MAAM,aAAa,EAAE,MAAM,CAChC,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,CAkS3B,CAAA"}
1
+ {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/viya/service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAChE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAkJnD,gEAAgE;AAChE,eAAO,MAAM,aAAa,EAAE,MAAM,CAChC,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,CAoS3B,CAAA"}
@@ -2,6 +2,7 @@ import { ApiError } from '../types.js';
2
2
  import { requireDrive } from './ports.js';
3
3
  import { COMPUTE_HANDLERS } from './compute.js';
4
4
  import { FILE_HANDLERS } from './files.js';
5
+ import { IDENTITY_HANDLERS } from './identity.js';
5
6
  import { idFor, normalisePath, EMULATED_NOW, EMULATED_USER, callerId } from './ids.js';
6
7
  const linksFor = (uri, collection = false) => {
7
8
  const self = {
@@ -336,5 +337,6 @@ export const VIYA_HANDLERS = {
336
337
  };
337
338
  },
338
339
  ...COMPUTE_HANDLERS,
339
- ...FILE_HANDLERS
340
+ ...FILE_HANDLERS,
341
+ ...IDENTITY_HANDLERS
340
342
  };
@@ -25,8 +25,17 @@ export interface EmulatedJob {
25
25
  completedTimeStamp?: string;
26
26
  sessionId: string;
27
27
  }
28
+ export type SessionOwner = {
29
+ kind: 'account' | 'user';
30
+ key: string;
31
+ } | {
32
+ kind: 'anonymous';
33
+ key?: never;
34
+ };
28
35
  export interface EmulatedSession {
29
36
  id: string;
37
+ /** Internal authorization principal, not a wire field. */
38
+ owner: SessionOwner;
30
39
  /** When it was created, on the real clock: a client expires sessions by age. */
31
40
  createdAt: string;
32
41
  jobs: Map<string, EmulatedJob>;
@@ -59,20 +68,29 @@ export declare const logFor: (seed: number, program: string | string[]) => strin
59
68
  /**
60
69
  * The sessions one estate holds.
61
70
  *
62
- * Keyed by seed, so two emulated estates in one process - a test that runs two
63
- * targets - do not share a session namespace.
71
+ * Keyed by the estate's key - the full normalised address, not the seed it
72
+ * digests to - so two emulated estates in one process (a test that runs two
73
+ * targets, or two addresses whose 32-bit seeds collide) do not share a session
74
+ * namespace. See `estateKeyOf`.
64
75
  */
65
76
  export declare class EmulatedEstate {
66
77
  private readonly seed;
67
78
  private readonly sessions;
68
- private created;
69
79
  constructor(seed: number);
70
- /** A new session: deterministic id, no jobs. */
71
- create(): EmulatedSession;
80
+ /** A new session: opaque UUID v4, no jobs. */
81
+ create(owner: SessionOwner): EmulatedSession;
72
82
  session(id: string): EmulatedSession | undefined;
73
83
  remove(id: string): boolean;
74
84
  /** A job accepted into a session, with the log the emulator generated for it. */
75
85
  submit(session: EmulatedSession, job: SubmittedJob): EmulatedJob;
76
86
  }
77
- export declare const estateFor: (seed: number) => EmulatedEstate;
87
+ /**
88
+ * The estate one address holds, minting it on first use.
89
+ *
90
+ * Keyed by the estate's key - the full normalised address - never by the seed:
91
+ * the seed is a 32-bit digest of the address, two distinct addresses collide on
92
+ * it, and a collision must not give them one shared session store. The estate
93
+ * still uses the seed for its generated logs.
94
+ */
95
+ export declare const estateFor: (key: string, seed: number) => EmulatedEstate;
78
96
  //# sourceMappingURL=sessions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sessions.d.ts","sourceRoot":"","sources":["../../../src/viya/sessions.ts"],"names":[],"mappings":"AAiBA,gEAAgE;AAChE,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,oDAAoD;IACpD,GAAG,EAAE,MAAM,EAAE,CAAA;IACb,sEAAsE;IACtE,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;;;;;;OAOG;IACH,KAAK,EAAE,SAAS,GAAG,WAAW,GAAG,QAAQ,CAAA;IACzC,iBAAiB,EAAE,MAAM,CAAA;IACzB;;;;;OAKG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAA;IACV,gFAAgF;IAChF,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAA;IAC9B,8EAA8E;IAC9E,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,kFAAkF;AAClF,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;CACzB;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,MAAM,GAAI,MAAM,MAAM,EAAE,SAAS,MAAM,GAAG,MAAM,EAAE,KAAG,MAAM,EAuBvE,CAAA;AAED;;;;;GAKG;AACH,qBAAa,cAAc;IAKb,OAAO,CAAC,QAAQ,CAAC,IAAI;IAJjC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAqC;IAE9D,OAAO,CAAC,OAAO,CA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AS,EAAE,MAAM,CAAA;CAClB;AAED,kFAAkF;AAClF,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;CACzB;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,MAAM,GAAI,MAAM,MAAM,EAAE,SAAS,MAAM,GAAG,MAAM,EAAE,KAAG,MAAM,EAuBvE,CAAA;AAED;;;;;;;GAOG;AACH,qBAAa,cAAc;IAGb,OAAO,CAAC,QAAQ,CAAC,IAAI;IAFjC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAqC;gBAEjC,IAAI,EAAE,MAAM;IAEzC,8CAA8C;IAC9C,MAAM,CAAC,KAAK,EAAE,YAAY,GAAG,eAAe;IAiB5C,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS;IAIhD,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAI3B,iFAAiF;IACjF,MAAM,CAAC,OAAO,EAAE,eAAe,EAAE,GAAG,EAAE,YAAY,GAAG,WAAW;CAwBjE;AAKD;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,GAAI,KAAK,MAAM,EAAE,MAAM,MAAM,KAAG,cAUrD,CAAA"}
@@ -13,6 +13,7 @@
13
13
  * that parses for NOTEs still gets a well-formed log, and a person reading it is
14
14
  * not misled about what ran.
15
15
  */
16
+ import { newUuidV4 } from '../uuid.js';
16
17
  import { drawFrom, drawInt, generator, hash } from './seed.js';
17
18
  /**
18
19
  * The generated log for one program.
@@ -48,19 +49,24 @@ export const logFor = (seed, program) => {
48
49
  /**
49
50
  * The sessions one estate holds.
50
51
  *
51
- * Keyed by seed, so two emulated estates in one process - a test that runs two
52
- * targets - do not share a session namespace.
52
+ * Keyed by the estate's key - the full normalised address, not the seed it
53
+ * digests to - so two emulated estates in one process (a test that runs two
54
+ * targets, or two addresses whose 32-bit seeds collide) do not share a session
55
+ * namespace. See `estateKeyOf`.
53
56
  */
54
57
  export class EmulatedEstate {
55
58
  constructor(seed) {
56
59
  this.seed = seed;
57
60
  this.sessions = new Map();
58
- this.created = 0;
59
61
  }
60
- /** A new session: deterministic id, no jobs. */
61
- create() {
62
+ /** A new session: opaque UUID v4, no jobs. */
63
+ create(owner) {
64
+ const id = newUuidV4();
65
+ if (this.sessions.has(id))
66
+ throw new Error('Duplicate compute session ID.');
62
67
  const session = {
63
- id: `emulated-${this.seed.toString(16)}-ses${String(this.created++).padStart(4, '0')}`,
68
+ id,
69
+ owner,
64
70
  createdAt: new Date().toISOString(),
65
71
  jobs: new Map(),
66
72
  submitted: 0
@@ -97,13 +103,21 @@ export class EmulatedEstate {
97
103
  return submitted;
98
104
  }
99
105
  }
100
- /** One estate per seed, for the life of the process. */
106
+ /** One estate per address, for the life of the process. */
101
107
  const estates = new Map();
102
- export const estateFor = (seed) => {
103
- const existing = estates.get(seed);
108
+ /**
109
+ * The estate one address holds, minting it on first use.
110
+ *
111
+ * Keyed by the estate's key - the full normalised address - never by the seed:
112
+ * the seed is a 32-bit digest of the address, two distinct addresses collide on
113
+ * it, and a collision must not give them one shared session store. The estate
114
+ * still uses the seed for its generated logs.
115
+ */
116
+ export const estateFor = (key, seed) => {
117
+ const existing = estates.get(key);
104
118
  if (existing)
105
119
  return existing;
106
120
  const estate = new EmulatedEstate(seed);
107
- estates.set(seed, estate);
121
+ estates.set(key, estate);
108
122
  return estate;
109
123
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sasjs/api",
3
- "version": "0.49.0",
3
+ "version": "0.50.0",
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",
@@ -45,6 +45,8 @@
45
45
  "check:routes": "node scripts/sync-routes.mjs --check",
46
46
  "sync:scope": "node scripts/viya-scope.mjs",
47
47
  "check:scope": "node scripts/viya-scope.mjs --check",
48
+ "sync:app-scope": "node scripts/viya-app-scope.mjs",
49
+ "check:app-scope": "node scripts/viya-app-scope.mjs --check",
48
50
  "sync:viya": "node scripts/viya-generate.mjs",
49
51
  "check:viya": "node scripts/viya-generate.mjs --check",
50
52
  "check:builds": "node scripts/check-builds.mjs",