@simpleplatform/sdk 4.1.0 → 4.2.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 +29 -4
- package/dist/space/core.d.ts +1 -1
- package/dist/space/index.d.ts +1 -1
- package/dist/space/navigation.d.ts +12 -1
- package/dist/space/navigation.js +29 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -17,6 +17,13 @@ Version 4.1 removes the `temperature` and `reasoningBudget` options from
|
|
|
17
17
|
the result. Where your code sets or reads either one, remove it; results stay
|
|
18
18
|
the same.
|
|
19
19
|
|
|
20
|
+
**A test that builds the client by hand** adds what the client gained, or it
|
|
21
|
+
stops type checking: `navigation`, `ui`, and `open` beside `current` under
|
|
22
|
+
`records` (for example `records: { current: vi.fn(), open: vi.fn() }`). Its
|
|
23
|
+
`navigation.open` must accept both `NavigationOpenOptions` and
|
|
24
|
+
`NavigationOpenUrlOptions`; one typed for only `NavigationOpenOptions` no
|
|
25
|
+
longer type checks.
|
|
26
|
+
|
|
20
27
|
## Upgrading from 2.x to 3
|
|
21
28
|
|
|
22
29
|
Version 3 is the first release that carries the Space calls added after 2.5.0.
|
|
@@ -32,10 +39,6 @@ One of those changes renamed how a Space connects, which is why this is a major.
|
|
|
32
39
|
| `ConnectSpaceOptions` | `ConnectOptions` |
|
|
33
40
|
| `SpaceWindowLike`, `SpaceMessageEvent` | No longer exported. A test declares its own. |
|
|
34
41
|
|
|
35
|
-
**A test that builds the client by hand** adds what the client gained, or it
|
|
36
|
-
stops type checking: `navigation`, `ui`, and `open` beside `current` under
|
|
37
|
-
`records` (for example `records: { current: vi.fn(), open: vi.fn() }`).
|
|
38
|
-
|
|
39
42
|
**Two behaviours change with no change in your code:**
|
|
40
43
|
|
|
41
44
|
- `connect()` sets `overscroll-behavior-y: none` on the Space's root element,
|
|
@@ -317,6 +320,28 @@ for platform targets a browser has no name for.
|
|
|
317
320
|
`open()` returns `void` as soon as the request is posted. The host gives no
|
|
318
321
|
confirmation, and a host without the navigation handler ignores the message.
|
|
319
322
|
|
|
323
|
+
To open an address outside the platform, pass an absolute HTTPS `url` in place
|
|
324
|
+
of the `path`. It opens only in a new tab, so `target: 'new-tab'` is required.
|
|
325
|
+
`open()` takes `NavigationOpenOptions` (`{ path, target? }`) or
|
|
326
|
+
`NavigationOpenUrlOptions` (`{ url, target: 'new-tab' }`):
|
|
327
|
+
|
|
328
|
+
```ts
|
|
329
|
+
simple.navigation.open({ target: 'new-tab', url: 'https://example.com/help' })
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
The platform opens it with `noopener` and `noreferrer`, so the new tab has no
|
|
333
|
+
handle back to the platform tab. `open()` first answers `'unavailable'` when
|
|
334
|
+
the host is not HTTPS or has no navigation bridge. Only then does it check the
|
|
335
|
+
`url`, and throw `SpaceProtocolError` with code `'invalid_request'` for a `url` with
|
|
336
|
+
`'same-tab'` or with no target, a `url` that is not HTTPS, a `url` that
|
|
337
|
+
carries a username or a password, and options that hold both a `path` and a
|
|
338
|
+
`url`, or neither. The SDK sends the address as the browser parses it. A
|
|
339
|
+
platform that opens only its own pages does not open it, and sends no reply.
|
|
340
|
+
|
|
341
|
+
The platform opens an outside address only when the Space lists its origin
|
|
342
|
+
under `permissions.links` in its manifest, for example `https://*.example.com`.
|
|
343
|
+
An unlisted address does not open.
|
|
344
|
+
|
|
320
345
|
### Space context
|
|
321
346
|
|
|
322
347
|
`simple.context` is explicit host-provided page context. It is never inferred
|
package/dist/space/core.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ import type { SimpleTasksClient } from './tasks.js';
|
|
|
10
10
|
import type { SimpleHeaderClient, SimpleTabsClient, SimpleToastClient, SpaceHeaderTransport, SpaceTabsTransport, SpaceToastTransport } from './ui.js';
|
|
11
11
|
export type { ActionFailedDetails, ActionRunOptions, SimpleActionsClient, } from './actions.js';
|
|
12
12
|
export type { DocumentStageInput, DocumentStageResult, SimpleDocumentsClient, StagedDocumentHandle, } from './documents.js';
|
|
13
|
-
export type { NavigationOpenOptions, NavigationTarget, SimpleNavigationClient, SpaceNavigationTransport, } from './navigation.js';
|
|
13
|
+
export type { NavigationOpenOptions, NavigationOpenUrlOptions, NavigationTarget, SimpleNavigationClient, SpaceNavigationTransport, } from './navigation.js';
|
|
14
14
|
export { PROTOCOL_VERSION, SpaceDataError, SpaceProtocolError } from './protocol.js';
|
|
15
15
|
export type { ProtocolErrorResponse, ProtocolRequest, ProtocolResponse, ProtocolSuccessResponse, SpaceDataErrorPayload, SpaceProtocolErrorPayload, SpaceTransport, } from './protocol.js';
|
|
16
16
|
export { MANAGED_RECORD_FORM_PROTOCOL_VERSION } from './record-form.js';
|
package/dist/space/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { SimpleClient } from './core.js';
|
|
2
2
|
import { HEADER_ACTIONS_PROTOCOL_VERSION, PROTOCOL_VERSION, RECORDS_PROTOCOL_VERSION, SpaceDataError, SpaceProtocolError, TABS_PROTOCOL_VERSION, TOAST_PROTOCOL_VERSION } from './core.js';
|
|
3
|
-
export type { ActionFailedDetails, ActionRunOptions, DocumentStageInput, DocumentStageResult, GraphQLVariables, HeaderAction, HeaderActionType, JsonObject, JsonValue, NavigationOpenOptions, NavigationTarget, OpenRecordOptions, RecordErrorSnapshot, RecordFieldSnapshot, RecordFormError, RecordHandle, RecordOpenRequest, RecordOpenResult, RecordReference, RecordSnapshot, RecordSubmitResult, RecordUpdateResult, SetTabsOptions, SimpleActionsClient, SimpleClient, SimpleDataClient, SimpleDocumentsClient, SimpleHeaderActionsClient, SimpleHeaderClient, SimpleNavigationClient, SimpleRecordsClient, SimpleTabsClient, SimpleTasksClient, SimpleToastClient, SpaceContext, SpaceDataErrorPayload, SpaceNavigationTransport, SpaceProtocolErrorPayload, SpaceTab, SpaceTabsSelectionEvent, SpaceTabsTransport, SpaceToastOptions, SpaceToastVariant, StagedDocumentHandle, TaskCreateInput, TaskCreateResult, TaskReplyInput, TaskReplyResult, TaskStatus, } from './core.js';
|
|
3
|
+
export type { ActionFailedDetails, ActionRunOptions, DocumentStageInput, DocumentStageResult, GraphQLVariables, HeaderAction, HeaderActionType, JsonObject, JsonValue, NavigationOpenOptions, NavigationOpenUrlOptions, NavigationTarget, OpenRecordOptions, RecordErrorSnapshot, RecordFieldSnapshot, RecordFormError, RecordHandle, RecordOpenRequest, RecordOpenResult, RecordReference, RecordSnapshot, RecordSubmitResult, RecordUpdateResult, SetTabsOptions, SimpleActionsClient, SimpleClient, SimpleDataClient, SimpleDocumentsClient, SimpleHeaderActionsClient, SimpleHeaderClient, SimpleNavigationClient, SimpleRecordsClient, SimpleTabsClient, SimpleTasksClient, SimpleToastClient, SpaceContext, SpaceDataErrorPayload, SpaceNavigationTransport, SpaceProtocolErrorPayload, SpaceTab, SpaceTabsSelectionEvent, SpaceTabsTransport, SpaceToastOptions, SpaceToastVariant, StagedDocumentHandle, TaskCreateInput, TaskCreateResult, TaskReplyInput, TaskReplyResult, TaskStatus, } from './core.js';
|
|
4
4
|
export { HOST_UI_PROTOCOL_VERSION } from './host-ui.js';
|
|
5
5
|
export { HEADER_ACTIONS_PROTOCOL_VERSION, PROTOCOL_VERSION, RECORDS_PROTOCOL_VERSION, SpaceDataError, SpaceProtocolError, TABS_PROTOCOL_VERSION, TOAST_PROTOCOL_VERSION };
|
|
6
6
|
export type { CreateRecordOptions, NewRecordOptions, PanelContent, SimpleCreateRecordClient, SimpleNewRecordClient, SimplePanelClient } from './host-ui.js';
|
|
@@ -15,9 +15,20 @@ export type NavigationTarget = 'same-tab' | 'new-tab';
|
|
|
15
15
|
export interface NavigationOpenOptions {
|
|
16
16
|
path: string;
|
|
17
17
|
target?: NavigationTarget;
|
|
18
|
+
url?: never;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Opens an absolute HTTPS `url` outside the platform. It opens only in a new
|
|
22
|
+
* tab, so `target` must be `new-tab`, and it may not carry a username or a
|
|
23
|
+
* password. Options hold a `path` or a `url`, never both.
|
|
24
|
+
*/
|
|
25
|
+
export interface NavigationOpenUrlOptions {
|
|
26
|
+
url: string;
|
|
27
|
+
target: 'new-tab';
|
|
28
|
+
path?: never;
|
|
18
29
|
}
|
|
19
30
|
export interface SimpleNavigationClient {
|
|
20
|
-
open: (options: NavigationOpenOptions) => void;
|
|
31
|
+
open: (options: NavigationOpenOptions | NavigationOpenUrlOptions) => void;
|
|
21
32
|
}
|
|
22
33
|
export interface SpaceNavigationTransport {
|
|
23
34
|
navigate: (url: string, target: NavigationTarget) => void;
|
package/dist/space/navigation.js
CHANGED
|
@@ -4,12 +4,16 @@ export function createNavigationClient(hostOrigin, transport) {
|
|
|
4
4
|
open(options) {
|
|
5
5
|
if (!isObjectRecord(options))
|
|
6
6
|
throw invalidRequest('Navigation options must be an object.');
|
|
7
|
-
const { path, target } = options;
|
|
8
|
-
if (
|
|
7
|
+
const { path, target, url: address } = options;
|
|
8
|
+
if ((path === undefined) === (address === undefined))
|
|
9
|
+
throw invalidRequest('Navigation options must hold either a path or a url, not both.');
|
|
10
|
+
if (address === undefined && (typeof path !== 'string' || path.length === 0 || !path.startsWith('/') || path.startsWith('//') || path.includes('\\')))
|
|
9
11
|
throw invalidRequest('Navigation path must be a host-relative path starting with one slash, with no backslash.');
|
|
10
12
|
const resolvedTarget = target === undefined ? 'same-tab' : target;
|
|
11
13
|
if (resolvedTarget !== 'same-tab' && resolvedTarget !== 'new-tab')
|
|
12
14
|
throw invalidRequest('Navigation target must be "same-tab" or "new-tab".');
|
|
15
|
+
if (address !== undefined && resolvedTarget !== 'new-tab')
|
|
16
|
+
throw invalidRequest('A navigation url opens only in a new tab: set target to "new-tab".');
|
|
13
17
|
if (!hostOrigin || new URL(hostOrigin).protocol !== 'https:') {
|
|
14
18
|
throw new SpaceProtocolError({
|
|
15
19
|
code: 'unavailable',
|
|
@@ -22,6 +26,10 @@ export function createNavigationClient(hostOrigin, transport) {
|
|
|
22
26
|
message: 'The platform-navigation bridge is unavailable for this Space.',
|
|
23
27
|
});
|
|
24
28
|
}
|
|
29
|
+
if (address !== undefined) {
|
|
30
|
+
transport.navigate(outsideAddress(address), resolvedTarget);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
25
33
|
// URL parsing drops a tab or a newline, which can turn a path into another host's address.
|
|
26
34
|
const url = new URL(path, hostOrigin);
|
|
27
35
|
if (url.origin !== new URL(hostOrigin).origin)
|
|
@@ -30,3 +38,22 @@ export function createNavigationClient(hostOrigin, transport) {
|
|
|
30
38
|
},
|
|
31
39
|
};
|
|
32
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Checks an address outside the platform and returns it as the browser parses
|
|
43
|
+
* it, so the address sent is the one checked. The platform opens such an
|
|
44
|
+
* address only over HTTPS and never with a username or a password in it.
|
|
45
|
+
*/
|
|
46
|
+
function outsideAddress(address) {
|
|
47
|
+
let url;
|
|
48
|
+
try {
|
|
49
|
+
url = typeof address === 'string' ? new URL(address) : undefined;
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
url = undefined;
|
|
53
|
+
}
|
|
54
|
+
if (url?.protocol !== 'https:')
|
|
55
|
+
throw invalidRequest('Navigation url must be an absolute HTTPS address.');
|
|
56
|
+
if (url.username !== '' || url.password !== '')
|
|
57
|
+
throw invalidRequest('Navigation url must not carry a username or a password.');
|
|
58
|
+
return url.href;
|
|
59
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simpleplatform/sdk",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "Simple Platform Typescript SDK",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://docs.simple.dev",
|
|
@@ -82,6 +82,6 @@
|
|
|
82
82
|
"scripts": {
|
|
83
83
|
"build": "rm -rf dist && tsc && cp src/worker-override.js dist/ && cp cli/build.js dist/ && cp src/space/package.json dist/space/",
|
|
84
84
|
"test": "pnpm run build && node --test test/*.test.mjs",
|
|
85
|
-
"typecheck": "tsc --noEmit"
|
|
85
|
+
"typecheck": "tsc --noEmit && tsc -p tsconfig.types.json"
|
|
86
86
|
}
|
|
87
87
|
}
|