@simpleplatform/sdk 2.5.0 → 3.0.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 +386 -44
- package/dist/ai.d.ts +10 -0
- package/dist/ai.js +5 -1
- package/dist/space/actions.d.ts +59 -0
- package/dist/space/actions.js +69 -0
- package/dist/space/browser-transport.d.ts +18 -0
- package/dist/space/browser-transport.js +229 -0
- package/dist/space/core.d.ts +40 -241
- package/dist/space/core.js +69 -499
- package/dist/space/documents.d.ts +25 -0
- package/dist/space/documents.js +72 -0
- package/dist/space/index.d.ts +6 -32
- package/dist/space/index.js +59 -99
- package/dist/space/navigation.d.ts +25 -0
- package/dist/space/navigation.js +32 -0
- package/dist/space/protocol.d.ts +66 -0
- package/dist/space/protocol.js +77 -0
- package/dist/space/record-form.d.ts +94 -0
- package/dist/space/record-form.js +217 -0
- package/dist/space/record.d.ts +137 -0
- package/dist/space/record.js +231 -0
- package/dist/space/status.d.ts +2 -0
- package/dist/space/status.js +7 -0
- package/dist/space/tabs.d.ts +64 -0
- package/dist/space/tabs.js +236 -0
- package/dist/space/tasks.d.ts +84 -0
- package/dist/space/tasks.js +129 -0
- package/dist/space/ui.d.ts +67 -0
- package/dist/space/ui.js +123 -0
- package/dist/tasks.d.ts +18 -0
- package/dist/tasks.js +34 -0
- package/package.json +5 -1
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { invalidRequest, isObjectRecord, PROTOCOL_VERSION, readResponse, requestWithin, SpaceProtocolError, } from './protocol.js';
|
|
2
|
+
import { isJsonValue } from './tasks.js';
|
|
3
|
+
export { requestWithin };
|
|
4
|
+
/** An action's name within its app, as the host checks it before adding the app. */
|
|
5
|
+
const ACTION_NAME = /^[a-z0-9][a-z0-9-]*$/;
|
|
6
|
+
/** The host's timeout for an action run that names none. */
|
|
7
|
+
const DEFAULT_ACTION_TIMEOUT_MS = 60000;
|
|
8
|
+
/** How much longer than the host's timeout the client waits for its answer. */
|
|
9
|
+
const ACTION_ANSWER_GRACE_MS = 5000;
|
|
10
|
+
/** The longest delay `setTimeout` keeps; it runs a longer one at once. */
|
|
11
|
+
const MAX_TIMER_MS = 2147483647;
|
|
12
|
+
/**
|
|
13
|
+
* How long a run waits for the host. The host answers `timeout` itself at the
|
|
14
|
+
* timeout, so this wait only ends a run whose answer never comes, as when the
|
|
15
|
+
* host has closed its port. A timeout the host refuses is answered at once, so
|
|
16
|
+
* it only needs to give a delay a timer can hold.
|
|
17
|
+
*/
|
|
18
|
+
export function actionWaitMs(timeoutMs) {
|
|
19
|
+
const hostTimeoutMs = Math.max(timeoutMs ?? DEFAULT_ACTION_TIMEOUT_MS, 0);
|
|
20
|
+
return Math.min(hostTimeoutMs + ACTION_ANSWER_GRACE_MS, MAX_TIMER_MS);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Checks an action run before it is sent. The timeout's range is the host's to
|
|
24
|
+
* enforce, so only its type is checked here, and it is sent only when given.
|
|
25
|
+
*/
|
|
26
|
+
export function readActionRunPayload(action, input, options) {
|
|
27
|
+
if (typeof action !== 'string' || !ACTION_NAME.test(action))
|
|
28
|
+
throw invalidRequest('An action is named alone, in lowercase letters, digits, and hyphens, such as "document-attach".');
|
|
29
|
+
if (!isJsonValue(input))
|
|
30
|
+
throw invalidRequest('An action input must be a JSON value, and everything in it a JSON value.');
|
|
31
|
+
if (options !== undefined && !isObjectRecord(options))
|
|
32
|
+
throw invalidRequest('Action options must be an object.');
|
|
33
|
+
const timeoutMs = options?.timeoutMs;
|
|
34
|
+
if (timeoutMs !== undefined && (typeof timeoutMs !== 'number' || !Number.isFinite(timeoutMs)))
|
|
35
|
+
throw invalidRequest('An action timeout must be a number of milliseconds.');
|
|
36
|
+
return {
|
|
37
|
+
action,
|
|
38
|
+
input,
|
|
39
|
+
...(timeoutMs === undefined ? {} : { timeoutMs }),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The host binds the Space's own app to every action it runs, so a Space names
|
|
44
|
+
* only the action and cannot reach another app's. Actions are not tied to a
|
|
45
|
+
* page record, so they are available in any Space whose host negotiated the
|
|
46
|
+
* action protocol, standalone or record.
|
|
47
|
+
*/
|
|
48
|
+
export function createActionsClient(transport, nextRequestId) {
|
|
49
|
+
return {
|
|
50
|
+
async run(action, input, options) {
|
|
51
|
+
if (!transport) {
|
|
52
|
+
throw new SpaceProtocolError({
|
|
53
|
+
code: 'unavailable',
|
|
54
|
+
message: 'Actions are unavailable because the Space host did not negotiate the action protocol.',
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
const payload = readActionRunPayload(action, input, options);
|
|
58
|
+
const request = {
|
|
59
|
+
operation: 'action.run',
|
|
60
|
+
payload,
|
|
61
|
+
protocol: PROTOCOL_VERSION,
|
|
62
|
+
requestId: nextRequestId(),
|
|
63
|
+
};
|
|
64
|
+
const response = await requestWithin(transport, request, actionWaitMs(payload.timeoutMs));
|
|
65
|
+
// Any JSON value is a valid result, so it is returned as the host sent it.
|
|
66
|
+
return readResponse(response, request);
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { SpaceDataTransport } from './core.js';
|
|
2
|
+
import type { SpaceNavigationTransport } from './navigation.js';
|
|
3
|
+
import type { SpaceTransport } from './protocol.js';
|
|
4
|
+
import type { RecordFormCapabilities } from './record-form.js';
|
|
5
|
+
import type { SpaceHeaderStatusTransport, SpaceHeaderTransport, SpaceTabsTransport, SpaceToastTransport } from './ui.js';
|
|
6
|
+
export interface MessagePortLike {
|
|
7
|
+
close?: () => void;
|
|
8
|
+
onmessage: null | ((event: {
|
|
9
|
+
data: unknown;
|
|
10
|
+
}) => void);
|
|
11
|
+
postMessage: (message: unknown, transfer?: ArrayBuffer[]) => void;
|
|
12
|
+
start?: () => void;
|
|
13
|
+
}
|
|
14
|
+
export interface BrowserSpaceTransport extends SpaceDataTransport, SpaceHeaderStatusTransport, SpaceHeaderTransport, SpaceNavigationTransport, SpaceTabsTransport, SpaceToastTransport, SpaceTransport {
|
|
15
|
+
capabilities: RecordFormCapabilities;
|
|
16
|
+
subscribeFormModel: (listener: (form: unknown) => void) => () => void;
|
|
17
|
+
}
|
|
18
|
+
export declare function createMessagePortTransport(port: MessagePortLike, targetOrigin: string): BrowserSpaceTransport;
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { SpaceDataError, SpaceProtocolError, } from './protocol.js';
|
|
2
|
+
import { createFormModelSubscriptionManager, createRecordFormCapabilities, } from './record-form.js';
|
|
3
|
+
export function createMessagePortTransport(port, targetOrigin) {
|
|
4
|
+
const headerCallbacks = new Map();
|
|
5
|
+
const formModelManager = createFormModelSubscriptionManager();
|
|
6
|
+
const pendingData = new Map();
|
|
7
|
+
const pending = new Map();
|
|
8
|
+
const pendingCapabilities = new Map();
|
|
9
|
+
const tabListeners = new Set();
|
|
10
|
+
let isPortClosed = false;
|
|
11
|
+
if (typeof port.addEventListener === 'function') {
|
|
12
|
+
port.addEventListener('close', () => {
|
|
13
|
+
isPortClosed = true;
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
port.onmessage = (event) => {
|
|
17
|
+
const message = event.data;
|
|
18
|
+
if (!message || typeof message !== 'object')
|
|
19
|
+
return;
|
|
20
|
+
const envelope = message;
|
|
21
|
+
if (envelope.type === 'SPACE_RECORD_FORM_UPDATE') {
|
|
22
|
+
formModelManager.handleUpdate(envelope.form);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (envelope.type === 'SPACE_PROTOCOL_RESPONSE' && envelope.response) {
|
|
26
|
+
const requestId = envelope.response.requestId;
|
|
27
|
+
const request = pending.get(requestId);
|
|
28
|
+
if (!request)
|
|
29
|
+
return;
|
|
30
|
+
pending.delete(requestId);
|
|
31
|
+
request.resolve(envelope.response);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (typeof envelope.type === 'string' && envelope.type.endsWith('_RESPONSE') && typeof envelope.id === 'string') {
|
|
35
|
+
const request = pendingCapabilities.get(envelope.id);
|
|
36
|
+
if (request && envelope.type === request.responseType) {
|
|
37
|
+
pendingCapabilities.delete(envelope.id);
|
|
38
|
+
if (envelope.error) {
|
|
39
|
+
request.reject(new SpaceProtocolError({
|
|
40
|
+
code: 'request_failed',
|
|
41
|
+
message: typeof envelope.error === 'string' ? envelope.error : 'The private capability request failed.',
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
request.resolve(envelope);
|
|
46
|
+
}
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (envelope.type === 'SPACE_HEADER_ACTION_INVOKE') {
|
|
51
|
+
const invocation = readHeaderActionInvocation(message);
|
|
52
|
+
if (!invocation)
|
|
53
|
+
return;
|
|
54
|
+
const callback = headerCallbacks.get(invocation.actionId);
|
|
55
|
+
if (!callback) {
|
|
56
|
+
port.postMessage({
|
|
57
|
+
actionId: invocation.actionId,
|
|
58
|
+
error: 'The requested header action is no longer registered.',
|
|
59
|
+
invocationId: invocation.invocationId,
|
|
60
|
+
ok: false,
|
|
61
|
+
type: 'SPACE_HEADER_ACTION_RESULT',
|
|
62
|
+
});
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
Promise.resolve()
|
|
66
|
+
.then(callback)
|
|
67
|
+
.then(() => {
|
|
68
|
+
port.postMessage({
|
|
69
|
+
actionId: invocation.actionId,
|
|
70
|
+
invocationId: invocation.invocationId,
|
|
71
|
+
ok: true,
|
|
72
|
+
type: 'SPACE_HEADER_ACTION_RESULT',
|
|
73
|
+
});
|
|
74
|
+
})
|
|
75
|
+
.catch((error) => {
|
|
76
|
+
port.postMessage({
|
|
77
|
+
actionId: invocation.actionId,
|
|
78
|
+
error: error instanceof Error ? error.message : 'The header action failed.',
|
|
79
|
+
invocationId: invocation.invocationId,
|
|
80
|
+
ok: false,
|
|
81
|
+
type: 'SPACE_HEADER_ACTION_RESULT',
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (envelope.type !== 'GRAPHQL_RESPONSE' || typeof envelope.id !== 'string') {
|
|
87
|
+
if (envelope.type === 'SPACE_UI_TABS_SELECTION_CHANGED') {
|
|
88
|
+
const candidate = envelope;
|
|
89
|
+
if (typeof candidate.registrationRequestId === 'string' && typeof candidate.selectedTabId === 'string') {
|
|
90
|
+
const event = {
|
|
91
|
+
registrationRequestId: candidate.registrationRequestId,
|
|
92
|
+
selectedTabId: candidate.selectedTabId,
|
|
93
|
+
};
|
|
94
|
+
for (const listener of tabListeners) {
|
|
95
|
+
try {
|
|
96
|
+
listener(event);
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
// Callback errors must not break transport
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const request = pendingData.get(envelope.id);
|
|
107
|
+
if (!request)
|
|
108
|
+
return;
|
|
109
|
+
pendingData.delete(envelope.id);
|
|
110
|
+
if (envelope.error || envelope.errors) {
|
|
111
|
+
request.reject(new SpaceDataError({
|
|
112
|
+
code: 'request_failed',
|
|
113
|
+
details: envelope.errors,
|
|
114
|
+
message: readGraphQLErrorMessage(envelope.error, envelope.errors),
|
|
115
|
+
}));
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
request.resolve(envelope.data);
|
|
119
|
+
};
|
|
120
|
+
port.start?.();
|
|
121
|
+
const requestCapability = (type, payload, responseType) => {
|
|
122
|
+
return new Promise((resolve, reject) => {
|
|
123
|
+
const id = createDataRequestId();
|
|
124
|
+
pendingCapabilities.set(id, { reject, resolve: value => resolve(value), responseType });
|
|
125
|
+
port.postMessage({ id, payload, type });
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
return {
|
|
129
|
+
capabilities: createRecordFormCapabilities(requestCapability, msg => port.postMessage(msg), targetOrigin),
|
|
130
|
+
execute: (document, variables) => {
|
|
131
|
+
return new Promise((resolve, reject) => {
|
|
132
|
+
const id = createDataRequestId();
|
|
133
|
+
pendingData.set(id, { reject, resolve: result => resolve(result) });
|
|
134
|
+
port.postMessage({
|
|
135
|
+
payload: { id, query: document, variables },
|
|
136
|
+
type: 'GRAPHQL_REQUEST',
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
},
|
|
140
|
+
isClosed: () => isPortClosed || Boolean(port.closed),
|
|
141
|
+
navigate: (url, target) => {
|
|
142
|
+
port.postMessage({
|
|
143
|
+
payload: { target, url },
|
|
144
|
+
type: 'NAVIGATE_REQUEST',
|
|
145
|
+
});
|
|
146
|
+
},
|
|
147
|
+
request: (request, transfer = [], signal) => {
|
|
148
|
+
return new Promise((resolve, reject) => {
|
|
149
|
+
const abort = () => {
|
|
150
|
+
pending.delete(request.requestId);
|
|
151
|
+
reject(signal?.reason);
|
|
152
|
+
};
|
|
153
|
+
pending.set(request.requestId, {
|
|
154
|
+
resolve: (response) => {
|
|
155
|
+
signal?.removeEventListener('abort', abort);
|
|
156
|
+
resolve(response);
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
signal?.addEventListener('abort', abort, { once: true });
|
|
160
|
+
port.postMessage({ request, type: 'SPACE_PROTOCOL_REQUEST' }, transfer);
|
|
161
|
+
});
|
|
162
|
+
},
|
|
163
|
+
setActions: (actions) => {
|
|
164
|
+
headerCallbacks.clear();
|
|
165
|
+
for (const action of actions)
|
|
166
|
+
headerCallbacks.set(action.id, action.onClick);
|
|
167
|
+
port.postMessage({
|
|
168
|
+
actions: actions.map(({ disabled, icon, id, label, loading, type }) => ({
|
|
169
|
+
disabled,
|
|
170
|
+
icon,
|
|
171
|
+
id,
|
|
172
|
+
label,
|
|
173
|
+
loading,
|
|
174
|
+
type,
|
|
175
|
+
})),
|
|
176
|
+
type: 'SPACE_HEADER_ACTIONS_SET',
|
|
177
|
+
});
|
|
178
|
+
},
|
|
179
|
+
setStatus: (status) => {
|
|
180
|
+
port.postMessage({ status, type: 'SPACE_HEADER_STATUS_SET' });
|
|
181
|
+
},
|
|
182
|
+
showToast: (options) => {
|
|
183
|
+
port.postMessage({ options, type: 'SPACE_TOAST_SHOW' });
|
|
184
|
+
},
|
|
185
|
+
subscribeFormModel: (listener) => {
|
|
186
|
+
return formModelManager.subscribeFormModel(listener);
|
|
187
|
+
},
|
|
188
|
+
subscribeTabSelected: (listener) => {
|
|
189
|
+
tabListeners.add(listener);
|
|
190
|
+
return () => {
|
|
191
|
+
tabListeners.delete(listener);
|
|
192
|
+
};
|
|
193
|
+
},
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
function readHeaderActionInvocation(value) {
|
|
197
|
+
if (!value || typeof value !== 'object')
|
|
198
|
+
return null;
|
|
199
|
+
const message = value;
|
|
200
|
+
if (typeof message.actionId !== 'string' || !message.actionId
|
|
201
|
+
|| typeof message.invocationId !== 'string' || !message.invocationId) {
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
return { actionId: message.actionId, invocationId: message.invocationId };
|
|
205
|
+
}
|
|
206
|
+
function createDataRequestId() {
|
|
207
|
+
if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function')
|
|
208
|
+
return crypto.randomUUID();
|
|
209
|
+
return `space-data-${Math.random().toString(36).slice(2)}`;
|
|
210
|
+
}
|
|
211
|
+
function readGraphQLErrorMessage(error, errors) {
|
|
212
|
+
if (typeof error === 'string' && error)
|
|
213
|
+
return error;
|
|
214
|
+
if (Array.isArray(errors)) {
|
|
215
|
+
const firstError = errors[0];
|
|
216
|
+
if (firstError && typeof firstError === 'object') {
|
|
217
|
+
const details = firstError;
|
|
218
|
+
const issue = details.extensions?.issues?.[0]?.message;
|
|
219
|
+
if (typeof issue === 'string' && issue)
|
|
220
|
+
return issue;
|
|
221
|
+
const message = details.extensions?.details?.message;
|
|
222
|
+
if (typeof message === 'string' && message)
|
|
223
|
+
return message;
|
|
224
|
+
if (typeof details.message === 'string' && details.message)
|
|
225
|
+
return details.message;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return 'GraphQL request failed.';
|
|
229
|
+
}
|
package/dist/space/core.d.ts
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { SimpleActionsClient } from './actions.js';
|
|
2
|
+
import type { SimpleDocumentsClient } from './documents.js';
|
|
3
|
+
import type { SimpleNavigationClient, SpaceNavigationTransport } from './navigation.js';
|
|
4
|
+
import type { SpaceTransport } from './protocol.js';
|
|
5
|
+
import type { RecordFormCapabilities, RecordFormModelTransport, UiRuntimeDescriptor } from './record-form.js';
|
|
6
|
+
import type { SimpleRecordsClient } from './record.js';
|
|
7
|
+
import type { SimpleTasksClient } from './tasks.js';
|
|
8
|
+
import type { SimpleHeaderClient, SimpleTabsClient, SimpleToastClient, SpaceHeaderStatusTransport, SpaceHeaderTransport, SpaceTabsTransport, SpaceToastTransport } from './ui.js';
|
|
9
|
+
export type { ActionFailedDetails, ActionRunOptions, SimpleActionsClient, } from './actions.js';
|
|
10
|
+
export type { DocumentStageInput, DocumentStageResult, SimpleDocumentsClient, StagedDocumentHandle, } from './documents.js';
|
|
11
|
+
export type { NavigationOpenOptions, NavigationTarget, SimpleNavigationClient, SpaceNavigationTransport, } from './navigation.js';
|
|
12
|
+
export { PROTOCOL_VERSION, SpaceDataError, SpaceProtocolError } from './protocol.js';
|
|
13
|
+
export type { ProtocolErrorResponse, ProtocolRequest, ProtocolResponse, ProtocolSuccessResponse, SpaceDataErrorPayload, SpaceProtocolErrorPayload, SpaceTransport, } from './protocol.js';
|
|
14
|
+
export { MANAGED_RECORD_FORM_PROTOCOL_VERSION } from './record-form.js';
|
|
15
|
+
export type { ManagedRecordFormField, ManagedRecordFormModel, RecordFormCapabilities, RecordFormModelTransport, UiRuntimeDescriptor, } from './record-form.js';
|
|
16
|
+
export { RECORDS_PROTOCOL_VERSION } from './record.js';
|
|
17
|
+
export type { CurrentRecordRequest, CurrentRecordResult, OpenRecordOptions, RecordErrorSnapshot, RecordFieldSnapshot, RecordFormError, RecordHandle, RecordOpenRequest, RecordOpenResult, RecordReference, RecordSnapshot, RecordSubmitResult, RecordUpdateResult, SimpleRecordsClient, } from './record.js';
|
|
18
|
+
export type { JsonObject, JsonValue, SimpleTasksClient, TaskCreateInput, TaskCreateResult, TaskReplyInput, TaskReplyResult, TaskStatus, } from './tasks.js';
|
|
19
|
+
export { DEFAULT_TABS_TIMEOUT_MS, HEADER_ACTIONS_PROTOCOL_VERSION, HEADER_STATUS_PROTOCOL_VERSION, LUCIDE_ICON_NAME, TAB_ID, TABS_PROTOCOL_VERSION, TOAST_PROTOCOL_VERSION, validateHeaderStatus, validateTabs } from './ui.js';
|
|
20
|
+
export type { HeaderAction, HeaderActionType, SetTabsOptions, SimpleHeaderActionsClient, SimpleHeaderClient, SimpleHeaderStatusClient, SimpleTabsClient, SimpleToastClient, SpaceHeaderStatus, SpaceHeaderStatusTransport, SpaceStatusTone, SpaceTab, SpaceTabsSelectionEvent, SpaceTabsTransport, SpaceToastOptions, SpaceToastVariant, TabsSelectPayload, TabsSelectRequest, TabsSelectResult, TabsSetPayload, TabsSetRequest, TabsSetResult, WireTab, } from './ui.js';
|
|
3
21
|
export type SpaceContext = {
|
|
4
22
|
applicationId: string;
|
|
5
23
|
kind: 'record';
|
|
@@ -8,116 +26,7 @@ export type SpaceContext = {
|
|
|
8
26
|
} | {
|
|
9
27
|
kind: 'standalone';
|
|
10
28
|
};
|
|
11
|
-
export interface RecordFieldSnapshot {
|
|
12
|
-
error: null | string;
|
|
13
|
-
info: null | string;
|
|
14
|
-
readOnly: boolean;
|
|
15
|
-
required: boolean;
|
|
16
|
-
visible: boolean;
|
|
17
|
-
}
|
|
18
|
-
export interface RecordFormError {
|
|
19
|
-
code: string;
|
|
20
|
-
message: string;
|
|
21
|
-
}
|
|
22
|
-
export interface RecordErrorSnapshot {
|
|
23
|
-
fields: Readonly<Record<string, readonly string[]>>;
|
|
24
|
-
form: readonly RecordFormError[];
|
|
25
|
-
}
|
|
26
|
-
export interface RecordSnapshot {
|
|
27
|
-
errors: RecordErrorSnapshot;
|
|
28
|
-
fields: Readonly<Record<string, RecordFieldSnapshot>>;
|
|
29
|
-
revision: number;
|
|
30
|
-
values: Readonly<Record<string, unknown>>;
|
|
31
|
-
}
|
|
32
29
|
export type GraphQLVariables = Readonly<Record<string, unknown>>;
|
|
33
|
-
/** A value that survives a JSON round trip unchanged. */
|
|
34
|
-
export type JsonValue = boolean | JsonObject | null | number | string | readonly JsonValue[];
|
|
35
|
-
/** A JSON object: not `null`, not an array, and not a single value. */
|
|
36
|
-
export interface JsonObject {
|
|
37
|
-
readonly [key: string]: JsonValue;
|
|
38
|
-
}
|
|
39
|
-
/** The platform-standard status of a task. */
|
|
40
|
-
export type TaskStatus = 'cancelled' | 'completed' | 'failed' | 'in_progress' | 'queued' | 'waiting';
|
|
41
|
-
export interface TaskCreateInput {
|
|
42
|
-
/** The user the task is assigned to. Omit it to assign the task to its creator. */
|
|
43
|
-
assignedToId?: string;
|
|
44
|
-
/**
|
|
45
|
-
* The typed input the task type declares for its tasks. It is always a JSON
|
|
46
|
-
* object, even when the task type needs nothing: then it is `{}`.
|
|
47
|
-
*/
|
|
48
|
-
input: JsonObject;
|
|
49
|
-
/** The ID of the task type the task is created from. */
|
|
50
|
-
taskTypeId: string;
|
|
51
|
-
title: string;
|
|
52
|
-
}
|
|
53
|
-
export interface TaskCreateResult {
|
|
54
|
-
task: {
|
|
55
|
-
id: string;
|
|
56
|
-
revision: number;
|
|
57
|
-
status: TaskStatus;
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
export interface TaskReplyInput {
|
|
61
|
-
content: string;
|
|
62
|
-
/** The message this reply answers, when it answers one. */
|
|
63
|
-
inReplyToMessageId?: string;
|
|
64
|
-
taskId: string;
|
|
65
|
-
}
|
|
66
|
-
export interface TaskReplyResult {
|
|
67
|
-
messageId: string;
|
|
68
|
-
/** The task's revision after the reply was recorded. */
|
|
69
|
-
taskRevision: number;
|
|
70
|
-
}
|
|
71
|
-
export interface SimpleTasksClient {
|
|
72
|
-
create: (task: TaskCreateInput) => Promise<TaskCreateResult>;
|
|
73
|
-
reply: (reply: TaskReplyInput) => Promise<TaskReplyResult>;
|
|
74
|
-
}
|
|
75
|
-
/** A stored file that is not yet attached to any record. */
|
|
76
|
-
export interface StagedDocumentHandle extends DocumentHandle {
|
|
77
|
-
scope?: 'ephemeral' | 'record' | 'staged';
|
|
78
|
-
}
|
|
79
|
-
export interface DocumentStageInput {
|
|
80
|
-
/** The file to stage. Its bytes are transferred to the host, not copied. */
|
|
81
|
-
file: Blob | File;
|
|
82
|
-
/** Defaults to the file's own type, then to `application/octet-stream`. */
|
|
83
|
-
mimeType?: string;
|
|
84
|
-
/** Defaults to the name of a `File`. A plain `Blob` has none, so it needs one. */
|
|
85
|
-
name?: string;
|
|
86
|
-
}
|
|
87
|
-
export interface DocumentStageResult {
|
|
88
|
-
handle: StagedDocumentHandle;
|
|
89
|
-
}
|
|
90
|
-
export interface SimpleDocumentsClient {
|
|
91
|
-
stage: (document: DocumentStageInput) => Promise<DocumentStageResult>;
|
|
92
|
-
}
|
|
93
|
-
export interface ActionRunOptions {
|
|
94
|
-
/**
|
|
95
|
-
* How long the host waits for the action before it stops and answers
|
|
96
|
-
* `timeout`, in milliseconds. The host uses 60,000 when it is left out and
|
|
97
|
-
* accepts 1,000 to 1,200,000.
|
|
98
|
-
*/
|
|
99
|
-
timeoutMs?: number;
|
|
100
|
-
}
|
|
101
|
-
/** The `details` of a `SpaceProtocolError` whose code is `action_failed`. */
|
|
102
|
-
export interface ActionFailedDetails {
|
|
103
|
-
/** The action's response body as parsed JSON, or `null` when it was not JSON. */
|
|
104
|
-
body: JsonValue;
|
|
105
|
-
/**
|
|
106
|
-
* The HTTP status the server answered with. An action the host ran in the
|
|
107
|
-
* browser (declared `client` or `both`) carries 200, the status the server
|
|
108
|
-
* gives the same failure, and its `body` has the same `{ error: [...] }` shape.
|
|
109
|
-
*/
|
|
110
|
-
status: number;
|
|
111
|
-
}
|
|
112
|
-
export interface SimpleActionsClient {
|
|
113
|
-
/**
|
|
114
|
-
* Runs an action of this Space's own app where the app declares it runs
|
|
115
|
-
* (on the server, or in the browser for a `client` or `both` action), as
|
|
116
|
-
* the signed-in user, and returns its JSON result as the action returned it. The host
|
|
117
|
-
* adds the app, so `action` is the name alone, such as `document-attach`.
|
|
118
|
-
*/
|
|
119
|
-
run: <TResult = unknown>(action: string, input: unknown, options?: ActionRunOptions) => Promise<TResult>;
|
|
120
|
-
}
|
|
121
30
|
export interface SpaceDataTransport {
|
|
122
31
|
execute: <TResult = unknown>(document: string, variables?: GraphQLVariables) => Promise<TResult>;
|
|
123
32
|
}
|
|
@@ -125,153 +34,43 @@ export interface SimpleDataClient {
|
|
|
125
34
|
mutate: <TResult = unknown>(document: string, variables?: GraphQLVariables) => Promise<TResult>;
|
|
126
35
|
query: <TResult = unknown>(document: string, variables?: GraphQLVariables) => Promise<TResult>;
|
|
127
36
|
}
|
|
128
|
-
export interface RecordHandle {
|
|
129
|
-
readonly id: string;
|
|
130
|
-
snapshot: () => RecordSnapshot;
|
|
131
|
-
submit: () => Promise<RecordSubmitResult>;
|
|
132
|
-
update: (values: Readonly<Record<string, unknown>>) => Promise<RecordUpdateResult>;
|
|
133
|
-
}
|
|
134
37
|
export interface SimpleClient {
|
|
135
38
|
actions: SimpleActionsClient;
|
|
136
39
|
context: SpaceContext;
|
|
137
40
|
data: SimpleDataClient;
|
|
138
41
|
documents: SimpleDocumentsClient;
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
42
|
+
navigation: SimpleNavigationClient;
|
|
43
|
+
/** Record session capabilities for the current Space. */
|
|
44
|
+
records: SimpleRecordsClient;
|
|
142
45
|
tasks: SimpleTasksClient;
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
message: string;
|
|
148
|
-
}
|
|
149
|
-
export declare class SpaceProtocolError extends Error {
|
|
150
|
-
readonly code: string;
|
|
151
|
-
readonly details?: unknown;
|
|
152
|
-
constructor({ code, details, message }: SpaceProtocolErrorPayload);
|
|
153
|
-
}
|
|
154
|
-
export interface SpaceDataErrorPayload {
|
|
155
|
-
code: string;
|
|
156
|
-
details?: unknown;
|
|
157
|
-
message: string;
|
|
158
|
-
}
|
|
159
|
-
export declare class SpaceDataError extends Error {
|
|
160
|
-
readonly code: string;
|
|
161
|
-
readonly details?: unknown;
|
|
162
|
-
constructor({ code, details, message }: SpaceDataErrorPayload);
|
|
163
|
-
}
|
|
164
|
-
export interface CurrentRecordRequest {
|
|
165
|
-
operation: 'record.current';
|
|
166
|
-
payload: Record<string, never>;
|
|
167
|
-
protocol: typeof PROTOCOL_VERSION;
|
|
168
|
-
requestId: string;
|
|
169
|
-
}
|
|
170
|
-
export interface CurrentRecordResult {
|
|
171
|
-
sessionId: string;
|
|
172
|
-
snapshot: RecordSnapshot;
|
|
173
|
-
}
|
|
174
|
-
export interface RecordUpdateRequest {
|
|
175
|
-
operation: 'record.update';
|
|
176
|
-
payload: {
|
|
177
|
-
sessionId: string;
|
|
178
|
-
values: Readonly<Record<string, unknown>>;
|
|
179
|
-
};
|
|
180
|
-
protocol: typeof PROTOCOL_VERSION;
|
|
181
|
-
requestId: string;
|
|
182
|
-
}
|
|
183
|
-
export interface RecordUpdateResult {
|
|
184
|
-
ok: boolean;
|
|
185
|
-
snapshot: RecordSnapshot;
|
|
186
|
-
}
|
|
187
|
-
export interface RecordSubmitRequest {
|
|
188
|
-
operation: 'record.submit';
|
|
189
|
-
payload: {
|
|
190
|
-
sessionId: string;
|
|
46
|
+
ui: {
|
|
47
|
+
header: SimpleHeaderClient;
|
|
48
|
+
tabs: SimpleTabsClient;
|
|
49
|
+
toast: SimpleToastClient;
|
|
191
50
|
};
|
|
192
|
-
protocol: typeof PROTOCOL_VERSION;
|
|
193
|
-
requestId: string;
|
|
194
|
-
}
|
|
195
|
-
export interface RecordSubmitResult {
|
|
196
|
-
ok: boolean;
|
|
197
|
-
snapshot: RecordSnapshot;
|
|
198
|
-
}
|
|
199
|
-
export interface TaskCreateRequest {
|
|
200
|
-
operation: 'task.create';
|
|
201
|
-
payload: TaskCreateInput;
|
|
202
|
-
protocol: typeof PROTOCOL_VERSION;
|
|
203
|
-
requestId: string;
|
|
204
|
-
}
|
|
205
|
-
export interface TaskReplyRequest {
|
|
206
|
-
operation: 'task.reply';
|
|
207
|
-
payload: TaskReplyInput;
|
|
208
|
-
protocol: typeof PROTOCOL_VERSION;
|
|
209
|
-
requestId: string;
|
|
210
|
-
}
|
|
211
|
-
export interface ActionRunRequest {
|
|
212
|
-
operation: 'action.run';
|
|
213
|
-
payload: {
|
|
214
|
-
/** The action's name within the Space's own app; the host adds the app. */
|
|
215
|
-
action: string;
|
|
216
|
-
input: JsonValue;
|
|
217
|
-
timeoutMs?: number;
|
|
218
|
-
};
|
|
219
|
-
protocol: typeof PROTOCOL_VERSION;
|
|
220
|
-
requestId: string;
|
|
221
|
-
}
|
|
222
|
-
export interface DocumentStageRequest {
|
|
223
|
-
operation: 'document.stage';
|
|
224
|
-
payload: {
|
|
225
|
-
/** Transferred with the request, so it is detached in the Space afterwards. */
|
|
226
|
-
bytes: ArrayBuffer;
|
|
227
|
-
mimeType: string;
|
|
228
|
-
name: string;
|
|
229
|
-
};
|
|
230
|
-
protocol: typeof PROTOCOL_VERSION;
|
|
231
|
-
requestId: string;
|
|
232
|
-
}
|
|
233
|
-
export type ProtocolRequest = ActionRunRequest | CurrentRecordRequest | DocumentStageRequest | RecordSubmitRequest | RecordUpdateRequest | TaskCreateRequest | TaskReplyRequest;
|
|
234
|
-
export interface ProtocolSuccessResponse<TResult> {
|
|
235
|
-
ok: true;
|
|
236
|
-
protocol: typeof PROTOCOL_VERSION;
|
|
237
|
-
requestId: string;
|
|
238
|
-
result: TResult;
|
|
239
|
-
}
|
|
240
|
-
export interface ProtocolErrorResponse {
|
|
241
|
-
error: SpaceProtocolErrorPayload;
|
|
242
|
-
ok: false;
|
|
243
|
-
protocol: typeof PROTOCOL_VERSION;
|
|
244
|
-
requestId: string;
|
|
245
|
-
}
|
|
246
|
-
export type ProtocolResponse<TResult> = ProtocolErrorResponse | ProtocolSuccessResponse<TResult>;
|
|
247
|
-
export interface SpaceTransport {
|
|
248
|
-
/**
|
|
249
|
-
* `transfer` names buffers inside the request whose ownership moves to the
|
|
250
|
-
* host with it instead of being copied. A transport that cannot transfer
|
|
251
|
-
* sends them by value. When `signal` aborts, the transport forgets the
|
|
252
|
-
* request, so a late answer is dropped, and rejects with the signal's reason.
|
|
253
|
-
*/
|
|
254
|
-
request: <TResult>(request: ProtocolRequest, transfer?: ArrayBuffer[], signal?: AbortSignal) => Promise<ProtocolResponse<TResult>>;
|
|
255
51
|
}
|
|
256
52
|
export interface SimpleClientOptions {
|
|
257
53
|
/** Present only when the host negotiated the action protocol. */
|
|
258
54
|
actionTransport?: SpaceTransport;
|
|
55
|
+
capabilities?: RecordFormCapabilities;
|
|
259
56
|
context?: SpaceContext;
|
|
260
57
|
dataTransport?: SpaceDataTransport;
|
|
261
58
|
/** Present only when the host negotiated the document protocol. */
|
|
262
59
|
documentTransport?: SpaceTransport;
|
|
60
|
+
formModelTransport?: RecordFormModelTransport;
|
|
61
|
+
hostOrigin?: string;
|
|
62
|
+
headerTransport?: SpaceHeaderTransport;
|
|
63
|
+
headerStatusTransport?: SpaceHeaderStatusTransport;
|
|
64
|
+
navigationTransport?: SpaceNavigationTransport;
|
|
263
65
|
nextRequestId?: () => string;
|
|
264
|
-
/** Present only when the host negotiated the
|
|
66
|
+
/** Present only when the host negotiated the records protocol. */
|
|
67
|
+
recordsTransport?: SpaceTransport;
|
|
68
|
+
runtime?: UiRuntimeDescriptor;
|
|
69
|
+
tabsTransport?: SpaceTabsTransport;
|
|
265
70
|
taskTransport?: SpaceTransport;
|
|
266
|
-
|
|
71
|
+
toastTransport?: SpaceToastTransport;
|
|
267
72
|
transport?: SpaceTransport;
|
|
268
73
|
}
|
|
269
|
-
/**
|
|
270
|
-
|
|
271
|
-
*
|
|
272
|
-
* MessagePort setup is intentionally outside this factory so the same public
|
|
273
|
-
* contract can be exercised in a first-party direct adapter and in any UI
|
|
274
|
-
* framework without importing browser-specific code.
|
|
275
|
-
*/
|
|
276
|
-
export declare function createSimpleClient({ actionTransport, context, dataTransport, documentTransport, nextRequestId, taskTransport, transport, }: SimpleClientOptions): SimpleClient;
|
|
74
|
+
/** Composes Space capabilities around the host transports supplied by `connect`. */
|
|
75
|
+
export declare function createSimpleClient({ actionTransport, capabilities, context, dataTransport, documentTransport, formModelTransport, headerStatusTransport, headerTransport, hostOrigin, navigationTransport, nextRequestId, recordsTransport, runtime, tabsTransport, taskTransport, toastTransport, transport, }: SimpleClientOptions): SimpleClient;
|
|
277
76
|
export declare function isSpaceContext(value: unknown): value is SpaceContext;
|