@simpleplatform/sdk 3.0.4 → 3.1.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 +12 -2
- package/dist/space/core.d.ts +9 -0
- package/dist/space/core.js +16 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -345,11 +345,21 @@ switch (simple.context.kind) {
|
|
|
345
345
|
}
|
|
346
346
|
```
|
|
347
347
|
|
|
348
|
-
The two
|
|
349
|
-
`{ kind: 'record', applicationId, tableName, recordId }`. There is no
|
|
348
|
+
The two context forms are `{ kind: 'standalone', user?, tenant? }` and
|
|
349
|
+
`{ kind: 'record', applicationId, tableName, recordId, user?, tenant? }`. There is no
|
|
350
350
|
`unknown` context variant. A missing or malformed context rejects
|
|
351
351
|
`connect({ targetOrigin })` with `SpaceProtocolError` code `invalid_response`.
|
|
352
352
|
|
|
353
|
+
`simple.context.user` and `simple.context.tenant` name the signed-in user and
|
|
354
|
+
the tenant exactly as an action's context names them, with the SDK's own `User`
|
|
355
|
+
and `Tenant` types: `user.id`, and `tenant.id`, `tenant.name` and `tenant.host`.
|
|
356
|
+
They are present from the host version that adds them to initialization
|
|
357
|
+
context. Older hosts omit them, so a Space handles `undefined` explicitly before
|
|
358
|
+
using `user.id`, for example to filter the tasks assigned to the viewer. The
|
|
359
|
+
SDK never invents them or derives them from `recordId`. Supplied text must be
|
|
360
|
+
non-blank; otherwise the context is malformed. This is descriptive identity,
|
|
361
|
+
not an authorization grant: the host and server still enforce access.
|
|
362
|
+
|
|
353
363
|
`connect({ targetOrigin })` works in any embedded Space, including standalone dashboards
|
|
354
364
|
and tools. In a non-record Space, `simple.data` remains available and
|
|
355
365
|
`simple.records.open()` succeeds whenever the records capability was negotiated,
|
package/dist/space/core.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Tenant, User } from '../types.js';
|
|
1
2
|
import type { SimpleActionsClient } from './actions.js';
|
|
2
3
|
import type { SimpleDocumentsClient } from './documents.js';
|
|
3
4
|
import type { SimpleNavigationClient, SpaceNavigationTransport } from './navigation.js';
|
|
@@ -23,8 +24,16 @@ export type SpaceContext = {
|
|
|
23
24
|
kind: 'record';
|
|
24
25
|
recordId: string;
|
|
25
26
|
tableName: string;
|
|
27
|
+
/** The tenant the Space runs in, named as an action's context names it. Absent on older hosts. */
|
|
28
|
+
tenant?: Tenant;
|
|
29
|
+
/** The signed-in user, named as an action's context names it. Absent on older hosts. */
|
|
30
|
+
user?: User;
|
|
26
31
|
} | {
|
|
27
32
|
kind: 'standalone';
|
|
33
|
+
/** The tenant the Space runs in, named as an action's context names it. Absent on older hosts. */
|
|
34
|
+
tenant?: Tenant;
|
|
35
|
+
/** The signed-in user, named as an action's context names it. Absent on older hosts. */
|
|
36
|
+
user?: User;
|
|
28
37
|
};
|
|
29
38
|
export type GraphQLVariables = Readonly<Record<string, unknown>>;
|
|
30
39
|
export interface SpaceDataTransport {
|
package/dist/space/core.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createActionsClient } from './actions.js';
|
|
2
2
|
import { createDocumentsClient } from './documents.js';
|
|
3
3
|
import { createNavigationClient } from './navigation.js';
|
|
4
|
-
import { deepFreeze, invalidResponse, isObjectRecord, PROTOCOL_VERSION, readResponse, SpaceDataError, SpaceProtocolError } from './protocol.js';
|
|
4
|
+
import { deepFreeze, invalidResponse, isNonBlankString, isObjectRecord, PROTOCOL_VERSION, readResponse, SpaceDataError, SpaceProtocolError } from './protocol.js';
|
|
5
5
|
import { createRecordsClient, isCurrentRecordResult, ProtocolRecordHandle } from './record.js';
|
|
6
6
|
import { createTasksClient } from './tasks.js';
|
|
7
7
|
import { createHeaderClient, createTabsClient, createToastClient, validateSpaceToastOptions } from './ui.js';
|
|
@@ -69,9 +69,24 @@ export function createSimpleClient({ actionTransport, capabilities, context = {
|
|
|
69
69
|
},
|
|
70
70
|
};
|
|
71
71
|
}
|
|
72
|
+
/** An action's context names the user by an optional ID; a supplied ID is non-blank. */
|
|
73
|
+
function isContextUser(value) {
|
|
74
|
+
return isObjectRecord(value) && (value.id === undefined || isNonBlankString(value.id));
|
|
75
|
+
}
|
|
76
|
+
/** An action's context names the tenant, with an optional ID and host; supplied text is non-blank. */
|
|
77
|
+
function isContextTenant(value) {
|
|
78
|
+
return isObjectRecord(value)
|
|
79
|
+
&& isNonBlankString(value.name)
|
|
80
|
+
&& (value.id === undefined || isNonBlankString(value.id))
|
|
81
|
+
&& (value.host === undefined || isNonBlankString(value.host));
|
|
82
|
+
}
|
|
72
83
|
export function isSpaceContext(value) {
|
|
73
84
|
if (!isObjectRecord(value))
|
|
74
85
|
return false;
|
|
86
|
+
if (value.user !== undefined && !isContextUser(value.user))
|
|
87
|
+
return false;
|
|
88
|
+
if (value.tenant !== undefined && !isContextTenant(value.tenant))
|
|
89
|
+
return false;
|
|
75
90
|
if (value.kind === 'standalone')
|
|
76
91
|
return true;
|
|
77
92
|
return value.kind === 'record'
|