@nullplatform/ui-plugin-sdk 0.18.0 → 0.20.0-beta.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/dist/bridge.d.ts +37 -1
- package/dist/bridge.js +44 -0
- package/dist/catalog.js +1 -0
- package/dist/components.d.ts +2 -0
- package/dist/components.generated.js +1 -1
- package/dist/context.d.ts +6 -0
- package/dist/contract/allowlist.d.ts +8 -1
- package/dist/contract/allowlist.js +26 -0
- package/dist/contract/index.d.ts +3 -2
- package/dist/contract/index.js +2 -1
- package/dist/contract/manifest.d.ts +13 -0
- package/dist/contract/manifest.js +14 -0
- package/dist/contract/pageTemplate.d.ts +36 -0
- package/dist/contract/pageTemplate.js +125 -0
- package/dist/contract/when.d.ts +1 -1
- package/dist/contract/when.js +1 -1
- package/dist/contract-cjs/allowlist.js +27 -0
- package/dist/contract-cjs/index.js +8 -1
- package/dist/contract-cjs/manifest.js +14 -0
- package/dist/contract-cjs/pageTemplate.js +130 -0
- package/dist/contract-cjs/when.js +1 -1
- package/dist/contracts.generated.js +1 -1
- package/dist/host.d.ts +8 -0
- package/dist/host.js +12 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/protocol.d.ts +108 -1
- package/dist/protocol.js +14 -0
- package/dist/worker.js +2 -1
- package/package.json +2 -2
package/dist/bridge.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Plugin-side client of the host bridge. The only way out of the sandbox.
|
|
3
3
|
*/
|
|
4
|
-
import { type ConfirmOptions, type ApiRequest, type BridgeMethodName, type BridgeMethods, type HostMessage, type HttpRequest, type HttpResponse, type NavigationTarget, type PluginContext, type SnackbarOptions, type WorkerMessage } from './protocol.js';
|
|
4
|
+
import { type ConfirmOptions, type FilePickOptions, type FileUpload, type PickedFile, type ApiRequest, type BridgeMethodName, type BridgeMethods, type HostMessage, type HttpRequest, type HttpResponse, type NavigationTarget, type PluginContext, type ProgressPanel, type SnackbarOptions, type WorkerMessage } from './protocol.js';
|
|
5
5
|
import { topics as topicsApi } from './topics.js';
|
|
6
6
|
export declare class BridgeClient {
|
|
7
7
|
private readonly timeoutMs;
|
|
@@ -42,6 +42,42 @@ export declare const nullplatform: {
|
|
|
42
42
|
* time per plugin (a second one rejects with `BUSY`). A host older than the call rejects with `UNKNOWN_METHOD`.
|
|
43
43
|
*/
|
|
44
44
|
confirm(options: ConfirmOptions): Promise<boolean>;
|
|
45
|
+
/**
|
|
46
|
+
* Shows work that takes a while in the host's progress panel, in a corner of the page: a title and one line per
|
|
47
|
+
* item, each `waiting`, `running`, `done` or `failed`. Every call replaces the plugin's panel; `null` removes
|
|
48
|
+
* it. The person can fold it, and close it once nothing is waiting or running; it goes when the plugin stops.
|
|
49
|
+
* A host older than the call rejects with `UNKNOWN_METHOD`.
|
|
50
|
+
*/
|
|
51
|
+
progress(panel: ProgressPanel | null): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Shows an approval request in the host's own modal, with its checklist when it has one: the person reads it and
|
|
54
|
+
* acts on it there, without leaving the page. Resolves once they close it. It says nothing about what they did,
|
|
55
|
+
* so read again whatever the approval decides. `approvalId` is the request's id, its digits as a string
|
|
56
|
+
* (`BAD_REQUEST` otherwise). Waits up to 30 minutes; one at a time per plugin (a second one rejects with `BUSY`).
|
|
57
|
+
* Offer it only when `hostSupports('ui.approval')`: a host older than the call rejects with `UNKNOWN_METHOD`, one
|
|
58
|
+
* that shows no approvals with `APPROVALS_NOT_SUPPORTED`.
|
|
59
|
+
*/
|
|
60
|
+
approval(approvalId: string): Promise<void>;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Files from the person's computer. A plugin cannot open a file picker or read a file: the host does both, and
|
|
64
|
+
* hands back only the file's name, size and type. A host older than these calls rejects with `UNKNOWN_METHOD`;
|
|
65
|
+
* one that offers no file picker or upload, with `FILES_NOT_SUPPORTED`.
|
|
66
|
+
*/
|
|
67
|
+
files: {
|
|
68
|
+
/**
|
|
69
|
+
* Opens the host's file picker. Resolves the picked files: none when the person cancels, one unless `multiple`.
|
|
70
|
+
* Call it from a press: browsers only open a file picker shortly after one. Waits up to 10 minutes; one picker
|
|
71
|
+
* at a time per plugin (a second one rejects with `BUSY`). More files than `FILE_LIMITS.picked` in one pick
|
|
72
|
+
* rejects with `TOO_MANY_FILES`.
|
|
73
|
+
*/
|
|
74
|
+
pick(options?: FilePickOptions): Promise<PickedFile[]>;
|
|
75
|
+
/**
|
|
76
|
+
* Sends a picked file as a form POST to a host declared in `permissions.upload` (an S3 presigned POST, for
|
|
77
|
+
* example). Resolves when the form was sent; the host cannot read the answer, so check that the file arrived.
|
|
78
|
+
* Rejects with `PERMISSION_DENIED` for an undeclared host and `UNKNOWN_FILE` for an id it does not hold.
|
|
79
|
+
*/
|
|
80
|
+
upload(upload: FileUpload): Promise<void>;
|
|
45
81
|
};
|
|
46
82
|
context: {
|
|
47
83
|
get(): Promise<PluginContext>;
|
package/dist/bridge.js
CHANGED
|
@@ -111,6 +111,50 @@ export const nullplatform = {
|
|
|
111
111
|
confirm(options) {
|
|
112
112
|
return bridge.call('ui.confirm', options);
|
|
113
113
|
},
|
|
114
|
+
/**
|
|
115
|
+
* Shows work that takes a while in the host's progress panel, in a corner of the page: a title and one line per
|
|
116
|
+
* item, each `waiting`, `running`, `done` or `failed`. Every call replaces the plugin's panel; `null` removes
|
|
117
|
+
* it. The person can fold it, and close it once nothing is waiting or running; it goes when the plugin stops.
|
|
118
|
+
* A host older than the call rejects with `UNKNOWN_METHOD`.
|
|
119
|
+
*/
|
|
120
|
+
progress(panel) {
|
|
121
|
+
return bridge.call('ui.progress', panel);
|
|
122
|
+
},
|
|
123
|
+
/**
|
|
124
|
+
* Shows an approval request in the host's own modal, with its checklist when it has one: the person reads it and
|
|
125
|
+
* acts on it there, without leaving the page. Resolves once they close it. It says nothing about what they did,
|
|
126
|
+
* so read again whatever the approval decides. `approvalId` is the request's id, its digits as a string
|
|
127
|
+
* (`BAD_REQUEST` otherwise). Waits up to 30 minutes; one at a time per plugin (a second one rejects with `BUSY`).
|
|
128
|
+
* Offer it only when `hostSupports('ui.approval')`: a host older than the call rejects with `UNKNOWN_METHOD`, one
|
|
129
|
+
* that shows no approvals with `APPROVALS_NOT_SUPPORTED`.
|
|
130
|
+
*/
|
|
131
|
+
approval(approvalId) {
|
|
132
|
+
return bridge.call('ui.approval', approvalId);
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
/**
|
|
136
|
+
* Files from the person's computer. A plugin cannot open a file picker or read a file: the host does both, and
|
|
137
|
+
* hands back only the file's name, size and type. A host older than these calls rejects with `UNKNOWN_METHOD`;
|
|
138
|
+
* one that offers no file picker or upload, with `FILES_NOT_SUPPORTED`.
|
|
139
|
+
*/
|
|
140
|
+
files: {
|
|
141
|
+
/**
|
|
142
|
+
* Opens the host's file picker. Resolves the picked files: none when the person cancels, one unless `multiple`.
|
|
143
|
+
* Call it from a press: browsers only open a file picker shortly after one. Waits up to 10 minutes; one picker
|
|
144
|
+
* at a time per plugin (a second one rejects with `BUSY`). More files than `FILE_LIMITS.picked` in one pick
|
|
145
|
+
* rejects with `TOO_MANY_FILES`.
|
|
146
|
+
*/
|
|
147
|
+
pick(options) {
|
|
148
|
+
return bridge.call('files.pick', options);
|
|
149
|
+
},
|
|
150
|
+
/**
|
|
151
|
+
* Sends a picked file as a form POST to a host declared in `permissions.upload` (an S3 presigned POST, for
|
|
152
|
+
* example). Resolves when the form was sent; the host cannot read the answer, so check that the file arrived.
|
|
153
|
+
* Rejects with `PERMISSION_DENIED` for an undeclared host and `UNKNOWN_FILE` for an id it does not hold.
|
|
154
|
+
*/
|
|
155
|
+
upload(upload) {
|
|
156
|
+
return bridge.call('files.upload', upload);
|
|
157
|
+
},
|
|
114
158
|
},
|
|
115
159
|
context: {
|
|
116
160
|
get() {
|
package/dist/catalog.js
CHANGED
package/dist/components.d.ts
CHANGED
|
@@ -137,6 +137,8 @@ export declare const Link: import("react").ComponentType<{
|
|
|
137
137
|
color?: LinkColor;
|
|
138
138
|
/** Unset, the theme's: underlined on hover. */
|
|
139
139
|
underline?: LinkUnderline;
|
|
140
|
+
/** Opens a `to` page in a new tab and leaves this one where it is. An `href` always opens in a new tab. */
|
|
141
|
+
newTab?: boolean;
|
|
140
142
|
onPress?: () => void;
|
|
141
143
|
} & {
|
|
142
144
|
children?: ReactNode;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Generated by scripts/sync-contracts.mjs from @nullplatform/react-ui-components@0.16.
|
|
1
|
+
// Generated by scripts/sync-contracts.mjs from @nullplatform/react-ui-components@0.16.10. Don't edit: change the contract in
|
|
2
2
|
// react-ui-components, bump `uiComponentsContracts` in package.json and run `pnpm sync:contracts`.
|
|
3
3
|
import { component } from "./component.js";
|
|
4
4
|
export const Badge = component("np-badge");
|
package/dist/context.d.ts
CHANGED
|
@@ -33,6 +33,12 @@ export declare function useNullplatform(): {
|
|
|
33
33
|
ui: {
|
|
34
34
|
snackbar(options: import("./protocol").SnackbarOptions): Promise<void>;
|
|
35
35
|
confirm(options: import("./protocol").ConfirmOptions): Promise<boolean>;
|
|
36
|
+
progress(panel: import("./protocol").ProgressPanel | null): Promise<void>;
|
|
37
|
+
approval(approvalId: string): Promise<void>;
|
|
38
|
+
};
|
|
39
|
+
files: {
|
|
40
|
+
pick(options?: import("./protocol").FilePickOptions): Promise<import("./protocol").PickedFile[]>;
|
|
41
|
+
upload(upload: import("./protocol").FileUpload): Promise<void>;
|
|
36
42
|
};
|
|
37
43
|
context: {
|
|
38
44
|
get(): Promise<PluginContext>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ApiPermission, HttpPermission } from './manifest.js';
|
|
1
|
+
import type { ApiPermission, HttpPermission, UploadPermission } from './manifest.js';
|
|
2
2
|
/** Splits a path into segments; rejects traversal, empty segments and query/hash fragments. */
|
|
3
3
|
export declare function normalizePath(path: string): string[] | null;
|
|
4
4
|
/**
|
|
@@ -22,3 +22,10 @@ export declare const isRequestAllowed: typeof isApiRequestAllowed;
|
|
|
22
22
|
* declared method and path pattern.
|
|
23
23
|
*/
|
|
24
24
|
export declare function isHttpRequestAllowed(permissions: HttpPermission[] | undefined, method: string, url: string): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Decides whether a file may be uploaded to `url` under `permissions.upload`: https only, no credentials in the URL,
|
|
27
|
+
* and a declared host. An exact host matches itself (port included when declared); `*.example.com` matches every
|
|
28
|
+
* host under `example.com` on the default port, never `example.com` itself. The path and the query are the
|
|
29
|
+
* upload's own business: a presigned POST goes to `/`.
|
|
30
|
+
*/
|
|
31
|
+
export declare function isUploadAllowed(permissions: UploadPermission[] | undefined, url: string): boolean;
|
|
@@ -82,3 +82,29 @@ export function isHttpRequestAllowed(permissions, method, url) {
|
|
|
82
82
|
(permission.method === '*' || permission.method === requestMethod) &&
|
|
83
83
|
pathMatches(permission.path, requestSegments));
|
|
84
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Decides whether a file may be uploaded to `url` under `permissions.upload`: https only, no credentials in the URL,
|
|
87
|
+
* and a declared host. An exact host matches itself (port included when declared); `*.example.com` matches every
|
|
88
|
+
* host under `example.com` on the default port, never `example.com` itself. The path and the query are the
|
|
89
|
+
* upload's own business: a presigned POST goes to `/`.
|
|
90
|
+
*/
|
|
91
|
+
export function isUploadAllowed(permissions, url) {
|
|
92
|
+
if (!permissions?.length)
|
|
93
|
+
return false;
|
|
94
|
+
let parsed;
|
|
95
|
+
try {
|
|
96
|
+
parsed = new URL(url);
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
if (parsed.protocol !== 'https:' || parsed.username || parsed.password)
|
|
102
|
+
return false;
|
|
103
|
+
const host = parsed.host.toLowerCase();
|
|
104
|
+
return permissions.some((permission) => {
|
|
105
|
+
const declared = permission.host.toLowerCase();
|
|
106
|
+
if (!declared.startsWith('*.'))
|
|
107
|
+
return declared === host;
|
|
108
|
+
return !parsed.port && host.endsWith(declared.slice(1));
|
|
109
|
+
});
|
|
110
|
+
}
|
package/dist/contract/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
export { PROTOCOL_VERSION, validateManifest, validatePublishableManifest, unnamedContributions, contributionId, RESERVED_PLUGIN_ID, isSectionSlot, ManifestError, type PluginManifest, type Contribution, type ApiPermission, type HttpPermission, type HttpMethod, } from './manifest.js';
|
|
1
|
+
export { PROTOCOL_VERSION, validateManifest, validatePublishableManifest, unnamedContributions, contributionId, RESERVED_PLUGIN_ID, isSectionSlot, ManifestError, type PluginManifest, type Contribution, type ApiPermission, type HttpPermission, type UploadPermission, type HttpMethod, } from './manifest.js';
|
|
2
2
|
export { PLACE_ROOTS, missingContext, contextSatisfies, readPlaceRoots, type PlaceRoot } from './context.js';
|
|
3
3
|
export { pageOf, layoutConflicts, type LayoutConflict } from './layout.js';
|
|
4
|
-
export {
|
|
4
|
+
export { PAGE_AREAS, REQUIRED_PAGE_AREA, MIN_PAGE_AREA_WIDTH, pageTemplateProblems, isPageTemplateDefinition, type PageArea, type PageTemplateBreakpoint, type PageTemplateDefinition, type PageTemplateResponsive, type PageTemplateTracks, } from './pageTemplate.js';
|
|
5
|
+
export { isApiRequestAllowed, isHttpRequestAllowed, isUploadAllowed, isRequestAllowed, normalizePath, canonicalizePath } from './allowlist.js';
|
|
5
6
|
export { matchFixture, type Fixtures, type FixtureMatch } from './fixtures.js';
|
|
6
7
|
export { CONTEXT_ROOTS, extractRoots, validateWhen, evaluateWhen, rolloutIncludes, WhenError, type WhenQuery, type ContextRoot, type Rollout, } from './when.js';
|
|
7
8
|
export { PLUGIN_STORAGE_ORIGIN, validateStorageUrl, resolveAssetUrl } from './storage.js';
|
package/dist/contract/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export { PROTOCOL_VERSION, validateManifest, validatePublishableManifest, unnamedContributions, contributionId, RESERVED_PLUGIN_ID, isSectionSlot, ManifestError, } from './manifest.js';
|
|
2
2
|
export { PLACE_ROOTS, missingContext, contextSatisfies, readPlaceRoots } from './context.js';
|
|
3
3
|
export { pageOf, layoutConflicts } from './layout.js';
|
|
4
|
-
export {
|
|
4
|
+
export { PAGE_AREAS, REQUIRED_PAGE_AREA, MIN_PAGE_AREA_WIDTH, pageTemplateProblems, isPageTemplateDefinition, } from './pageTemplate.js';
|
|
5
|
+
export { isApiRequestAllowed, isHttpRequestAllowed, isUploadAllowed, isRequestAllowed, normalizePath, canonicalizePath } from './allowlist.js';
|
|
5
6
|
export { matchFixture } from './fixtures.js';
|
|
6
7
|
export { CONTEXT_ROOTS, extractRoots, validateWhen, evaluateWhen, rolloutIncludes, WhenError, } from './when.js';
|
|
7
8
|
export { PLUGIN_STORAGE_ORIGIN, validateStorageUrl, resolveAssetUrl } from './storage.js';
|
|
@@ -15,6 +15,14 @@ export interface HttpPermission {
|
|
|
15
15
|
/** Path pattern on that host, `{param}` placeholders allowed. */
|
|
16
16
|
path: string;
|
|
17
17
|
}
|
|
18
|
+
export interface UploadPermission {
|
|
19
|
+
/**
|
|
20
|
+
* A host a picked file may be uploaded to with `files.upload`: exact (`uploads.example.com`), or every host under a
|
|
21
|
+
* domain (`*.amazonaws.com`). A wildcard is allowed here, unlike in `permissions.http`, because a presigned upload
|
|
22
|
+
* names its bucket in the host. Only https is ever allowed.
|
|
23
|
+
*/
|
|
24
|
+
host: string;
|
|
25
|
+
}
|
|
18
26
|
export interface Contribution {
|
|
19
27
|
slot: string;
|
|
20
28
|
/** Widget id exported by the plugin through `defineUI`. */
|
|
@@ -42,6 +50,11 @@ export interface PluginManifest {
|
|
|
42
50
|
permissions?: {
|
|
43
51
|
api?: ApiPermission[];
|
|
44
52
|
http?: HttpPermission[];
|
|
53
|
+
/**
|
|
54
|
+
* Hosts the plugin may send a file to. Shown at install: the file is one the person picks in the host's own file
|
|
55
|
+
* picker, and the plugin never reads it, but it does choose where it goes.
|
|
56
|
+
*/
|
|
57
|
+
upload?: UploadPermission[];
|
|
45
58
|
topics?: TopicPermissions;
|
|
46
59
|
/**
|
|
47
60
|
* Draws its own pixels with `Canvas`. Shown at install: inside its rectangle the plugin can paint anything,
|
|
@@ -11,6 +11,8 @@ export class ManifestError extends Error {
|
|
|
11
11
|
const ID_PATTERN = /^[a-z0-9][a-z0-9-]{1,63}$/;
|
|
12
12
|
const SLOT_PATTERN = /^[a-z][a-z0-9]*(\.[a-z][a-z0-9]*)+$/;
|
|
13
13
|
const HOST_PATTERN = /^[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)+(:[0-9]{1,5})?$/;
|
|
14
|
+
/** `*.` and a domain of two labels or more: `*.amazonaws.com`, never `*.com`. No port. */
|
|
15
|
+
const WILDCARD_HOST_PATTERN = /^\*(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?){2,}$/;
|
|
14
16
|
const METHODS = new Set(['GET', 'POST', 'PUT', 'PATCH', 'DELETE', '*']);
|
|
15
17
|
export function isSectionSlot(slot) {
|
|
16
18
|
return slot.endsWith('.section');
|
|
@@ -108,6 +110,18 @@ export function validateManifest(input) {
|
|
|
108
110
|
return { host, method: readMethod(p.method, where), path: readPath(p.path, where) };
|
|
109
111
|
});
|
|
110
112
|
}
|
|
113
|
+
if (rawPermissions.upload !== undefined) {
|
|
114
|
+
if (!Array.isArray(rawPermissions.upload))
|
|
115
|
+
throw new ManifestError('permissions.upload must be an array');
|
|
116
|
+
permissions.upload = rawPermissions.upload.map((raw, index) => {
|
|
117
|
+
const p = (raw ?? {});
|
|
118
|
+
const host = typeof p.host === 'string' ? p.host.toLowerCase() : '';
|
|
119
|
+
if (!HOST_PATTERN.test(host) && !WILDCARD_HOST_PATTERN.test(host)) {
|
|
120
|
+
throw new ManifestError(`permissions.upload[${index}].host must be a hostname (optional port) or "*." and a domain of two labels or more, no scheme`);
|
|
121
|
+
}
|
|
122
|
+
return { host };
|
|
123
|
+
});
|
|
124
|
+
}
|
|
111
125
|
if (rawPermissions.topics !== undefined) {
|
|
112
126
|
permissions.topics = readTopicPermissions(rawPermissions.topics, m.id);
|
|
113
127
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Page templates an organization saves (proposal P-1): a grid of named areas, in the grammar of `GridLayout` of
|
|
3
|
+
* react-ui-components (`columns` and `areas`, each a value or one per breakpoint). Each area of a page is a region
|
|
4
|
+
* named `<page>.<area>`, so the areas a template may name are the regions a page can have. Shared by the API, which
|
|
5
|
+
* refuses an invalid definition at write, and the host, which drops one it reads.
|
|
6
|
+
*/
|
|
7
|
+
/** The areas of a page, each the last segment of a region's name (`application.overview.sidebar`). */
|
|
8
|
+
export declare const PAGE_AREAS: readonly ["top", "main", "sidebar", "bottom"];
|
|
9
|
+
export type PageArea = (typeof PAGE_AREAS)[number];
|
|
10
|
+
/** The area every template has: the page's blocks need somewhere to go. */
|
|
11
|
+
export declare const REQUIRED_PAGE_AREA: PageArea;
|
|
12
|
+
/**
|
|
13
|
+
* The narrowest an area of a page is drawn, in px. An editor that resizes a page's columns stacks the side column below
|
|
14
|
+
* `main` rather than draw either one under it, so a plugin can rely on at least this width wherever it lands.
|
|
15
|
+
*/
|
|
16
|
+
export declare const MIN_PAGE_AREA_WIDTH = 240;
|
|
17
|
+
declare const BREAKPOINTS: readonly ["xs", "sm", "md", "lg", "xl"];
|
|
18
|
+
export type PageTemplateBreakpoint = (typeof BREAKPOINTS)[number];
|
|
19
|
+
/** A value, or one per breakpoint (`{ xs: 1, lg: 12 }`): a value holds from its breakpoint up. */
|
|
20
|
+
export type PageTemplateResponsive<T> = T | Partial<Record<PageTemplateBreakpoint, T>>;
|
|
21
|
+
/** A column count (1 to 12, equal columns), or a track list (`['2fr', '1fr']`). */
|
|
22
|
+
export type PageTemplateTracks = number | readonly string[];
|
|
23
|
+
/** A saved template's definition: `GridLayout`'s `columns` and `areas`, and nothing else. */
|
|
24
|
+
export interface PageTemplateDefinition {
|
|
25
|
+
columns?: PageTemplateResponsive<PageTemplateTracks>;
|
|
26
|
+
areas: PageTemplateResponsive<readonly string[]>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* What makes a template definition invalid, or nothing. GridLayout's own checks (shapes, one cell per column in
|
|
30
|
+
* effect, rectangles, every area at every breakpoint from `xs` up), plus the page's: only the page's areas, `main`
|
|
31
|
+
* among them, and no option but `columns` and `areas`.
|
|
32
|
+
*/
|
|
33
|
+
export declare function pageTemplateProblems(definition: unknown): string[];
|
|
34
|
+
/** Whether a definition is valid: what a host checks before drawing a saved template. */
|
|
35
|
+
export declare function isPageTemplateDefinition(definition: unknown): definition is PageTemplateDefinition;
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Page templates an organization saves (proposal P-1): a grid of named areas, in the grammar of `GridLayout` of
|
|
3
|
+
* react-ui-components (`columns` and `areas`, each a value or one per breakpoint). Each area of a page is a region
|
|
4
|
+
* named `<page>.<area>`, so the areas a template may name are the regions a page can have. Shared by the API, which
|
|
5
|
+
* refuses an invalid definition at write, and the host, which drops one it reads.
|
|
6
|
+
*/
|
|
7
|
+
/** The areas of a page, each the last segment of a region's name (`application.overview.sidebar`). */
|
|
8
|
+
export const PAGE_AREAS = ['top', 'main', 'sidebar', 'bottom'];
|
|
9
|
+
/** The area every template has: the page's blocks need somewhere to go. */
|
|
10
|
+
export const REQUIRED_PAGE_AREA = 'main';
|
|
11
|
+
/**
|
|
12
|
+
* The narrowest an area of a page is drawn, in px. An editor that resizes a page's columns stacks the side column below
|
|
13
|
+
* `main` rather than draw either one under it, so a plugin can rely on at least this width wherever it lands.
|
|
14
|
+
*/
|
|
15
|
+
export const MIN_PAGE_AREA_WIDTH = 240;
|
|
16
|
+
const BREAKPOINTS = ['xs', 'sm', 'md', 'lg', 'xl'];
|
|
17
|
+
/** GridLayout's limits (sdui-spec): 12 columns, tracks and rows at most; 12 equal columns where none are set. */
|
|
18
|
+
const MAX = 12;
|
|
19
|
+
const DEFAULT_COLUMNS = 12;
|
|
20
|
+
/** 12 cells of a name of up to 20 characters: far over the page's areas, and short enough to check cheaply. */
|
|
21
|
+
const MAX_ROW_LENGTH = 12 * 21;
|
|
22
|
+
// sdui-spec's `gridTrack` and `gridAreasRow`, verbatim.
|
|
23
|
+
const TRACK_PATTERN = /^(?:\d+(?:\.\d+)?(?:fr|px|%|rem)|auto|min-content|max-content)$/;
|
|
24
|
+
const AREAS_ROW_PATTERN = /^(?:[a-z][a-z0-9_-]*|\.)(?: (?:[a-z][a-z0-9_-]*|\.))*$/;
|
|
25
|
+
const EMPTY_CELL = '.';
|
|
26
|
+
const OPTIONS = ['columns', 'areas'];
|
|
27
|
+
const isPlainObject = (value) => typeof value === 'object' && value !== null && Object.getPrototypeOf(value) === Object.prototype;
|
|
28
|
+
const isTracks = (value) => (Number.isInteger(value) && value >= 1 && value <= MAX) ||
|
|
29
|
+
(Array.isArray(value) &&
|
|
30
|
+
value.length >= 1 &&
|
|
31
|
+
value.length <= MAX &&
|
|
32
|
+
value.every((track) => typeof track === 'string' && TRACK_PATTERN.test(track)));
|
|
33
|
+
const isRows = (value) => Array.isArray(value) &&
|
|
34
|
+
value.length >= 1 &&
|
|
35
|
+
value.length <= MAX &&
|
|
36
|
+
value.every((row) => typeof row === 'string' && row.length <= MAX_ROW_LENGTH && AREAS_ROW_PATTERN.test(row));
|
|
37
|
+
/** A responsive value as one entry per breakpoint it names; `undefined` when it is not one. */
|
|
38
|
+
function perBreakpoint(value, isValue) {
|
|
39
|
+
if (isValue(value))
|
|
40
|
+
return { xs: value };
|
|
41
|
+
if (!isPlainObject(value))
|
|
42
|
+
return undefined;
|
|
43
|
+
const valid = Object.entries(value).every(([breakpoint, entry]) => BREAKPOINTS.includes(breakpoint) && isValue(entry));
|
|
44
|
+
return valid ? value : undefined;
|
|
45
|
+
}
|
|
46
|
+
const namesIn = (rows) => rows.flatMap((row) => row.split(' ')).filter((name) => name !== EMPTY_CELL);
|
|
47
|
+
const columnCount = (tracks) => (typeof tracks === 'number' ? tracks : tracks.length);
|
|
48
|
+
/**
|
|
49
|
+
* What a template of rows breaks at one breakpoint: a row with the wrong cell count, an area that is no rectangle,
|
|
50
|
+
* or one another breakpoint names and this one leaves out (its region would land outside the grid).
|
|
51
|
+
*/
|
|
52
|
+
function rowProblems(rows, columns, breakpoint, allNames) {
|
|
53
|
+
// A row with the wrong cell count is the problem to fix first: the shapes are read only when every row fits.
|
|
54
|
+
const misfit = rows.map((row) => [row, row.split(' ').length]).filter(([, cells]) => cells !== columns);
|
|
55
|
+
if (misfit.length)
|
|
56
|
+
return misfit.map(([row, cells]) => `areas at ${breakpoint}: the row "${row}" has ${cells} cells for ${columns} columns`);
|
|
57
|
+
const problems = [];
|
|
58
|
+
const cells = new Map();
|
|
59
|
+
rows.forEach((row, rowIndex) => {
|
|
60
|
+
row.split(' ').forEach((name, column) => {
|
|
61
|
+
if (name === EMPTY_CELL)
|
|
62
|
+
return;
|
|
63
|
+
if (!cells.has(name))
|
|
64
|
+
cells.set(name, []);
|
|
65
|
+
cells.get(name).push([rowIndex, column]);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
for (const [name, at] of cells) {
|
|
69
|
+
const rowsOf = at.map(([row]) => row);
|
|
70
|
+
const columnsOf = at.map(([, column]) => column);
|
|
71
|
+
const height = Math.max(...rowsOf) - Math.min(...rowsOf) + 1;
|
|
72
|
+
const width = Math.max(...columnsOf) - Math.min(...columnsOf) + 1;
|
|
73
|
+
if (height * width !== at.length)
|
|
74
|
+
problems.push(`areas at ${breakpoint}: "${name}" is not a rectangle`);
|
|
75
|
+
}
|
|
76
|
+
for (const name of allNames)
|
|
77
|
+
if (!cells.has(name))
|
|
78
|
+
problems.push(`areas at ${breakpoint}: "${name}" is missing, though another breakpoint has it`);
|
|
79
|
+
return problems;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* What makes a template definition invalid, or nothing. GridLayout's own checks (shapes, one cell per column in
|
|
83
|
+
* effect, rectangles, every area at every breakpoint from `xs` up), plus the page's: only the page's areas, `main`
|
|
84
|
+
* among them, and no option but `columns` and `areas`.
|
|
85
|
+
*/
|
|
86
|
+
export function pageTemplateProblems(definition) {
|
|
87
|
+
if (!isPlainObject(definition))
|
|
88
|
+
return ['a template definition is a plain object'];
|
|
89
|
+
const problems = Object.keys(definition)
|
|
90
|
+
.filter((name) => !OPTIONS.includes(name))
|
|
91
|
+
.map((name) => `"${name}" is no template option: a template has columns and areas`);
|
|
92
|
+
const columns = definition.columns === undefined ? {} : perBreakpoint(definition.columns, isTracks);
|
|
93
|
+
if (!columns)
|
|
94
|
+
problems.push(`columns is a count (1 to ${MAX}) or 1 to ${MAX} tracks, or one per breakpoint`);
|
|
95
|
+
const areas = perBreakpoint(definition.areas, isRows);
|
|
96
|
+
if (!areas)
|
|
97
|
+
problems.push(`areas is 1 to ${MAX} rows of area names, or one per breakpoint`);
|
|
98
|
+
if (!columns || !areas)
|
|
99
|
+
return problems;
|
|
100
|
+
const allNames = new Set(namesIn(BREAKPOINTS.flatMap((breakpoint) => areas[breakpoint] ?? [])));
|
|
101
|
+
const unknown = [...allNames].filter((name) => !PAGE_AREAS.includes(name));
|
|
102
|
+
if (unknown.length)
|
|
103
|
+
problems.push(`areas name ${unknown.map((name) => `"${name}"`).join(', ')}: a page's areas are ${PAGE_AREAS.join(', ')}`);
|
|
104
|
+
if (!allNames.has(REQUIRED_PAGE_AREA))
|
|
105
|
+
problems.push(`areas have no "${REQUIRED_PAGE_AREA}": every template has it`);
|
|
106
|
+
if (areas.xs === undefined)
|
|
107
|
+
problems.push('areas start above xs: below their first breakpoint nothing places the areas');
|
|
108
|
+
// Each in effect from its breakpoint up: a row is held to the columns in effect where either changes.
|
|
109
|
+
let count = DEFAULT_COLUMNS;
|
|
110
|
+
let rows;
|
|
111
|
+
for (const breakpoint of BREAKPOINTS) {
|
|
112
|
+
const tracks = columns[breakpoint];
|
|
113
|
+
if (tracks !== undefined)
|
|
114
|
+
count = columnCount(tracks);
|
|
115
|
+
if (areas[breakpoint] !== undefined)
|
|
116
|
+
rows = areas[breakpoint];
|
|
117
|
+
if (rows && (tracks !== undefined || areas[breakpoint] !== undefined))
|
|
118
|
+
problems.push(...rowProblems(rows, count, breakpoint, allNames));
|
|
119
|
+
}
|
|
120
|
+
return problems;
|
|
121
|
+
}
|
|
122
|
+
/** Whether a definition is valid: what a host checks before drawing a saved template. */
|
|
123
|
+
export function isPageTemplateDefinition(definition) {
|
|
124
|
+
return pageTemplateProblems(definition).length === 0;
|
|
125
|
+
}
|
package/dist/contract/when.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export type WhenQuery = Record<string, unknown>;
|
|
|
10
10
|
* built-in scope has none (its `provider` is not a specification): `scope.type` tells those apart. Anywhere else
|
|
11
11
|
* `scope` is `undefined`, so a condition on it does not match.
|
|
12
12
|
*/
|
|
13
|
-
export declare const CONTEXT_ROOTS: readonly ["nrn", "organization", "account", "namespace", "application", "scope", "user"];
|
|
13
|
+
export declare const CONTEXT_ROOTS: readonly ["nrn", "organization", "account", "namespace", "application", "scope", "service", "user"];
|
|
14
14
|
export type ContextRoot = (typeof CONTEXT_ROOTS)[number];
|
|
15
15
|
export declare const WHEN_LIMITS: {
|
|
16
16
|
readonly depth: 16;
|
package/dist/contract/when.js
CHANGED
|
@@ -15,7 +15,7 @@ import sift from 'sift';
|
|
|
15
15
|
* built-in scope has none (its `provider` is not a specification): `scope.type` tells those apart. Anywhere else
|
|
16
16
|
* `scope` is `undefined`, so a condition on it does not match.
|
|
17
17
|
*/
|
|
18
|
-
export const CONTEXT_ROOTS = ['nrn', 'organization', 'account', 'namespace', 'application', 'scope', 'user'];
|
|
18
|
+
export const CONTEXT_ROOTS = ['nrn', 'organization', 'account', 'namespace', 'application', 'scope', 'service', 'user'];
|
|
19
19
|
/**
|
|
20
20
|
* In the plugin context, but not usable in a condition yet. Installations resolve for the application's NRN (or the
|
|
21
21
|
* scope's), so the platform never loads a deployment or a build and a condition on either would silently never match.
|
|
@@ -6,6 +6,7 @@ exports.canonicalizePath = canonicalizePath;
|
|
|
6
6
|
exports.pathMatches = pathMatches;
|
|
7
7
|
exports.isApiRequestAllowed = isApiRequestAllowed;
|
|
8
8
|
exports.isHttpRequestAllowed = isHttpRequestAllowed;
|
|
9
|
+
exports.isUploadAllowed = isUploadAllowed;
|
|
9
10
|
/** Splits a path into segments; rejects traversal, empty segments and query/hash fragments. */
|
|
10
11
|
function normalizePath(path) {
|
|
11
12
|
if (typeof path !== 'string' || !path.startsWith('/'))
|
|
@@ -90,3 +91,29 @@ function isHttpRequestAllowed(permissions, method, url) {
|
|
|
90
91
|
(permission.method === '*' || permission.method === requestMethod) &&
|
|
91
92
|
pathMatches(permission.path, requestSegments));
|
|
92
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* Decides whether a file may be uploaded to `url` under `permissions.upload`: https only, no credentials in the URL,
|
|
96
|
+
* and a declared host. An exact host matches itself (port included when declared); `*.example.com` matches every
|
|
97
|
+
* host under `example.com` on the default port, never `example.com` itself. The path and the query are the
|
|
98
|
+
* upload's own business: a presigned POST goes to `/`.
|
|
99
|
+
*/
|
|
100
|
+
function isUploadAllowed(permissions, url) {
|
|
101
|
+
if (!permissions?.length)
|
|
102
|
+
return false;
|
|
103
|
+
let parsed;
|
|
104
|
+
try {
|
|
105
|
+
parsed = new URL(url);
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
if (parsed.protocol !== 'https:' || parsed.username || parsed.password)
|
|
111
|
+
return false;
|
|
112
|
+
const host = parsed.host.toLowerCase();
|
|
113
|
+
return permissions.some((permission) => {
|
|
114
|
+
const declared = permission.host.toLowerCase();
|
|
115
|
+
if (!declared.startsWith('*.'))
|
|
116
|
+
return declared === host;
|
|
117
|
+
return !parsed.port && host.endsWith(declared.slice(1));
|
|
118
|
+
});
|
|
119
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.assertTopicValue = exports.redactBySchema = exports.projectFields = exports.canProvideTopic = exports.consumeGrant = exports.isFieldPath = exports.topicOwner = exports.isHostTopic = exports.isTopicName = exports.TOPIC_VALUE_MAX_CHARS = exports.resolveAssetUrl = exports.validateStorageUrl = exports.PLUGIN_STORAGE_ORIGIN = exports.WhenError = exports.rolloutIncludes = exports.evaluateWhen = exports.validateWhen = exports.extractRoots = exports.CONTEXT_ROOTS = exports.matchFixture = exports.canonicalizePath = exports.normalizePath = exports.isRequestAllowed = exports.isHttpRequestAllowed = exports.isApiRequestAllowed = exports.layoutConflicts = exports.pageOf = exports.readPlaceRoots = exports.contextSatisfies = exports.missingContext = exports.PLACE_ROOTS = exports.ManifestError = exports.isSectionSlot = exports.RESERVED_PLUGIN_ID = exports.contributionId = exports.unnamedContributions = exports.validatePublishableManifest = exports.validateManifest = exports.PROTOCOL_VERSION = void 0;
|
|
3
|
+
exports.assertTopicValue = exports.redactBySchema = exports.projectFields = exports.canProvideTopic = exports.consumeGrant = exports.isFieldPath = exports.topicOwner = exports.isHostTopic = exports.isTopicName = exports.TOPIC_VALUE_MAX_CHARS = exports.resolveAssetUrl = exports.validateStorageUrl = exports.PLUGIN_STORAGE_ORIGIN = exports.WhenError = exports.rolloutIncludes = exports.evaluateWhen = exports.validateWhen = exports.extractRoots = exports.CONTEXT_ROOTS = exports.matchFixture = exports.canonicalizePath = exports.normalizePath = exports.isRequestAllowed = exports.isUploadAllowed = exports.isHttpRequestAllowed = exports.isApiRequestAllowed = exports.isPageTemplateDefinition = exports.pageTemplateProblems = exports.MIN_PAGE_AREA_WIDTH = exports.REQUIRED_PAGE_AREA = exports.PAGE_AREAS = exports.layoutConflicts = exports.pageOf = exports.readPlaceRoots = exports.contextSatisfies = exports.missingContext = exports.PLACE_ROOTS = exports.ManifestError = exports.isSectionSlot = exports.RESERVED_PLUGIN_ID = exports.contributionId = exports.unnamedContributions = exports.validatePublishableManifest = exports.validateManifest = exports.PROTOCOL_VERSION = void 0;
|
|
4
4
|
var manifest_1 = require("./manifest");
|
|
5
5
|
Object.defineProperty(exports, "PROTOCOL_VERSION", { enumerable: true, get: function () { return manifest_1.PROTOCOL_VERSION; } });
|
|
6
6
|
Object.defineProperty(exports, "validateManifest", { enumerable: true, get: function () { return manifest_1.validateManifest; } });
|
|
@@ -18,9 +18,16 @@ Object.defineProperty(exports, "readPlaceRoots", { enumerable: true, get: functi
|
|
|
18
18
|
var layout_1 = require("./layout");
|
|
19
19
|
Object.defineProperty(exports, "pageOf", { enumerable: true, get: function () { return layout_1.pageOf; } });
|
|
20
20
|
Object.defineProperty(exports, "layoutConflicts", { enumerable: true, get: function () { return layout_1.layoutConflicts; } });
|
|
21
|
+
var pageTemplate_1 = require("./pageTemplate");
|
|
22
|
+
Object.defineProperty(exports, "PAGE_AREAS", { enumerable: true, get: function () { return pageTemplate_1.PAGE_AREAS; } });
|
|
23
|
+
Object.defineProperty(exports, "REQUIRED_PAGE_AREA", { enumerable: true, get: function () { return pageTemplate_1.REQUIRED_PAGE_AREA; } });
|
|
24
|
+
Object.defineProperty(exports, "MIN_PAGE_AREA_WIDTH", { enumerable: true, get: function () { return pageTemplate_1.MIN_PAGE_AREA_WIDTH; } });
|
|
25
|
+
Object.defineProperty(exports, "pageTemplateProblems", { enumerable: true, get: function () { return pageTemplate_1.pageTemplateProblems; } });
|
|
26
|
+
Object.defineProperty(exports, "isPageTemplateDefinition", { enumerable: true, get: function () { return pageTemplate_1.isPageTemplateDefinition; } });
|
|
21
27
|
var allowlist_1 = require("./allowlist");
|
|
22
28
|
Object.defineProperty(exports, "isApiRequestAllowed", { enumerable: true, get: function () { return allowlist_1.isApiRequestAllowed; } });
|
|
23
29
|
Object.defineProperty(exports, "isHttpRequestAllowed", { enumerable: true, get: function () { return allowlist_1.isHttpRequestAllowed; } });
|
|
30
|
+
Object.defineProperty(exports, "isUploadAllowed", { enumerable: true, get: function () { return allowlist_1.isUploadAllowed; } });
|
|
24
31
|
Object.defineProperty(exports, "isRequestAllowed", { enumerable: true, get: function () { return allowlist_1.isRequestAllowed; } });
|
|
25
32
|
Object.defineProperty(exports, "normalizePath", { enumerable: true, get: function () { return allowlist_1.normalizePath; } });
|
|
26
33
|
Object.defineProperty(exports, "canonicalizePath", { enumerable: true, get: function () { return allowlist_1.canonicalizePath; } });
|
|
@@ -20,6 +20,8 @@ exports.ManifestError = ManifestError;
|
|
|
20
20
|
const ID_PATTERN = /^[a-z0-9][a-z0-9-]{1,63}$/;
|
|
21
21
|
const SLOT_PATTERN = /^[a-z][a-z0-9]*(\.[a-z][a-z0-9]*)+$/;
|
|
22
22
|
const HOST_PATTERN = /^[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)+(:[0-9]{1,5})?$/;
|
|
23
|
+
/** `*.` and a domain of two labels or more: `*.amazonaws.com`, never `*.com`. No port. */
|
|
24
|
+
const WILDCARD_HOST_PATTERN = /^\*(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?){2,}$/;
|
|
23
25
|
const METHODS = new Set(['GET', 'POST', 'PUT', 'PATCH', 'DELETE', '*']);
|
|
24
26
|
function isSectionSlot(slot) {
|
|
25
27
|
return slot.endsWith('.section');
|
|
@@ -117,6 +119,18 @@ function validateManifest(input) {
|
|
|
117
119
|
return { host, method: readMethod(p.method, where), path: readPath(p.path, where) };
|
|
118
120
|
});
|
|
119
121
|
}
|
|
122
|
+
if (rawPermissions.upload !== undefined) {
|
|
123
|
+
if (!Array.isArray(rawPermissions.upload))
|
|
124
|
+
throw new ManifestError('permissions.upload must be an array');
|
|
125
|
+
permissions.upload = rawPermissions.upload.map((raw, index) => {
|
|
126
|
+
const p = (raw ?? {});
|
|
127
|
+
const host = typeof p.host === 'string' ? p.host.toLowerCase() : '';
|
|
128
|
+
if (!HOST_PATTERN.test(host) && !WILDCARD_HOST_PATTERN.test(host)) {
|
|
129
|
+
throw new ManifestError(`permissions.upload[${index}].host must be a hostname (optional port) or "*." and a domain of two labels or more, no scheme`);
|
|
130
|
+
}
|
|
131
|
+
return { host };
|
|
132
|
+
});
|
|
133
|
+
}
|
|
120
134
|
if (rawPermissions.topics !== undefined) {
|
|
121
135
|
permissions.topics = readTopicPermissions(rawPermissions.topics, m.id);
|
|
122
136
|
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Page templates an organization saves (proposal P-1): a grid of named areas, in the grammar of `GridLayout` of
|
|
4
|
+
* react-ui-components (`columns` and `areas`, each a value or one per breakpoint). Each area of a page is a region
|
|
5
|
+
* named `<page>.<area>`, so the areas a template may name are the regions a page can have. Shared by the API, which
|
|
6
|
+
* refuses an invalid definition at write, and the host, which drops one it reads.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.MIN_PAGE_AREA_WIDTH = exports.REQUIRED_PAGE_AREA = exports.PAGE_AREAS = void 0;
|
|
10
|
+
exports.pageTemplateProblems = pageTemplateProblems;
|
|
11
|
+
exports.isPageTemplateDefinition = isPageTemplateDefinition;
|
|
12
|
+
/** The areas of a page, each the last segment of a region's name (`application.overview.sidebar`). */
|
|
13
|
+
exports.PAGE_AREAS = ['top', 'main', 'sidebar', 'bottom'];
|
|
14
|
+
/** The area every template has: the page's blocks need somewhere to go. */
|
|
15
|
+
exports.REQUIRED_PAGE_AREA = 'main';
|
|
16
|
+
/**
|
|
17
|
+
* The narrowest an area of a page is drawn, in px. An editor that resizes a page's columns stacks the side column below
|
|
18
|
+
* `main` rather than draw either one under it, so a plugin can rely on at least this width wherever it lands.
|
|
19
|
+
*/
|
|
20
|
+
exports.MIN_PAGE_AREA_WIDTH = 240;
|
|
21
|
+
const BREAKPOINTS = ['xs', 'sm', 'md', 'lg', 'xl'];
|
|
22
|
+
/** GridLayout's limits (sdui-spec): 12 columns, tracks and rows at most; 12 equal columns where none are set. */
|
|
23
|
+
const MAX = 12;
|
|
24
|
+
const DEFAULT_COLUMNS = 12;
|
|
25
|
+
/** 12 cells of a name of up to 20 characters: far over the page's areas, and short enough to check cheaply. */
|
|
26
|
+
const MAX_ROW_LENGTH = 12 * 21;
|
|
27
|
+
// sdui-spec's `gridTrack` and `gridAreasRow`, verbatim.
|
|
28
|
+
const TRACK_PATTERN = /^(?:\d+(?:\.\d+)?(?:fr|px|%|rem)|auto|min-content|max-content)$/;
|
|
29
|
+
const AREAS_ROW_PATTERN = /^(?:[a-z][a-z0-9_-]*|\.)(?: (?:[a-z][a-z0-9_-]*|\.))*$/;
|
|
30
|
+
const EMPTY_CELL = '.';
|
|
31
|
+
const OPTIONS = ['columns', 'areas'];
|
|
32
|
+
const isPlainObject = (value) => typeof value === 'object' && value !== null && Object.getPrototypeOf(value) === Object.prototype;
|
|
33
|
+
const isTracks = (value) => (Number.isInteger(value) && value >= 1 && value <= MAX) ||
|
|
34
|
+
(Array.isArray(value) &&
|
|
35
|
+
value.length >= 1 &&
|
|
36
|
+
value.length <= MAX &&
|
|
37
|
+
value.every((track) => typeof track === 'string' && TRACK_PATTERN.test(track)));
|
|
38
|
+
const isRows = (value) => Array.isArray(value) &&
|
|
39
|
+
value.length >= 1 &&
|
|
40
|
+
value.length <= MAX &&
|
|
41
|
+
value.every((row) => typeof row === 'string' && row.length <= MAX_ROW_LENGTH && AREAS_ROW_PATTERN.test(row));
|
|
42
|
+
/** A responsive value as one entry per breakpoint it names; `undefined` when it is not one. */
|
|
43
|
+
function perBreakpoint(value, isValue) {
|
|
44
|
+
if (isValue(value))
|
|
45
|
+
return { xs: value };
|
|
46
|
+
if (!isPlainObject(value))
|
|
47
|
+
return undefined;
|
|
48
|
+
const valid = Object.entries(value).every(([breakpoint, entry]) => BREAKPOINTS.includes(breakpoint) && isValue(entry));
|
|
49
|
+
return valid ? value : undefined;
|
|
50
|
+
}
|
|
51
|
+
const namesIn = (rows) => rows.flatMap((row) => row.split(' ')).filter((name) => name !== EMPTY_CELL);
|
|
52
|
+
const columnCount = (tracks) => (typeof tracks === 'number' ? tracks : tracks.length);
|
|
53
|
+
/**
|
|
54
|
+
* What a template of rows breaks at one breakpoint: a row with the wrong cell count, an area that is no rectangle,
|
|
55
|
+
* or one another breakpoint names and this one leaves out (its region would land outside the grid).
|
|
56
|
+
*/
|
|
57
|
+
function rowProblems(rows, columns, breakpoint, allNames) {
|
|
58
|
+
// A row with the wrong cell count is the problem to fix first: the shapes are read only when every row fits.
|
|
59
|
+
const misfit = rows.map((row) => [row, row.split(' ').length]).filter(([, cells]) => cells !== columns);
|
|
60
|
+
if (misfit.length)
|
|
61
|
+
return misfit.map(([row, cells]) => `areas at ${breakpoint}: the row "${row}" has ${cells} cells for ${columns} columns`);
|
|
62
|
+
const problems = [];
|
|
63
|
+
const cells = new Map();
|
|
64
|
+
rows.forEach((row, rowIndex) => {
|
|
65
|
+
row.split(' ').forEach((name, column) => {
|
|
66
|
+
if (name === EMPTY_CELL)
|
|
67
|
+
return;
|
|
68
|
+
if (!cells.has(name))
|
|
69
|
+
cells.set(name, []);
|
|
70
|
+
cells.get(name).push([rowIndex, column]);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
for (const [name, at] of cells) {
|
|
74
|
+
const rowsOf = at.map(([row]) => row);
|
|
75
|
+
const columnsOf = at.map(([, column]) => column);
|
|
76
|
+
const height = Math.max(...rowsOf) - Math.min(...rowsOf) + 1;
|
|
77
|
+
const width = Math.max(...columnsOf) - Math.min(...columnsOf) + 1;
|
|
78
|
+
if (height * width !== at.length)
|
|
79
|
+
problems.push(`areas at ${breakpoint}: "${name}" is not a rectangle`);
|
|
80
|
+
}
|
|
81
|
+
for (const name of allNames)
|
|
82
|
+
if (!cells.has(name))
|
|
83
|
+
problems.push(`areas at ${breakpoint}: "${name}" is missing, though another breakpoint has it`);
|
|
84
|
+
return problems;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* What makes a template definition invalid, or nothing. GridLayout's own checks (shapes, one cell per column in
|
|
88
|
+
* effect, rectangles, every area at every breakpoint from `xs` up), plus the page's: only the page's areas, `main`
|
|
89
|
+
* among them, and no option but `columns` and `areas`.
|
|
90
|
+
*/
|
|
91
|
+
function pageTemplateProblems(definition) {
|
|
92
|
+
if (!isPlainObject(definition))
|
|
93
|
+
return ['a template definition is a plain object'];
|
|
94
|
+
const problems = Object.keys(definition)
|
|
95
|
+
.filter((name) => !OPTIONS.includes(name))
|
|
96
|
+
.map((name) => `"${name}" is no template option: a template has columns and areas`);
|
|
97
|
+
const columns = definition.columns === undefined ? {} : perBreakpoint(definition.columns, isTracks);
|
|
98
|
+
if (!columns)
|
|
99
|
+
problems.push(`columns is a count (1 to ${MAX}) or 1 to ${MAX} tracks, or one per breakpoint`);
|
|
100
|
+
const areas = perBreakpoint(definition.areas, isRows);
|
|
101
|
+
if (!areas)
|
|
102
|
+
problems.push(`areas is 1 to ${MAX} rows of area names, or one per breakpoint`);
|
|
103
|
+
if (!columns || !areas)
|
|
104
|
+
return problems;
|
|
105
|
+
const allNames = new Set(namesIn(BREAKPOINTS.flatMap((breakpoint) => areas[breakpoint] ?? [])));
|
|
106
|
+
const unknown = [...allNames].filter((name) => !exports.PAGE_AREAS.includes(name));
|
|
107
|
+
if (unknown.length)
|
|
108
|
+
problems.push(`areas name ${unknown.map((name) => `"${name}"`).join(', ')}: a page's areas are ${exports.PAGE_AREAS.join(', ')}`);
|
|
109
|
+
if (!allNames.has(exports.REQUIRED_PAGE_AREA))
|
|
110
|
+
problems.push(`areas have no "${exports.REQUIRED_PAGE_AREA}": every template has it`);
|
|
111
|
+
if (areas.xs === undefined)
|
|
112
|
+
problems.push('areas start above xs: below their first breakpoint nothing places the areas');
|
|
113
|
+
// Each in effect from its breakpoint up: a row is held to the columns in effect where either changes.
|
|
114
|
+
let count = DEFAULT_COLUMNS;
|
|
115
|
+
let rows;
|
|
116
|
+
for (const breakpoint of BREAKPOINTS) {
|
|
117
|
+
const tracks = columns[breakpoint];
|
|
118
|
+
if (tracks !== undefined)
|
|
119
|
+
count = columnCount(tracks);
|
|
120
|
+
if (areas[breakpoint] !== undefined)
|
|
121
|
+
rows = areas[breakpoint];
|
|
122
|
+
if (rows && (tracks !== undefined || areas[breakpoint] !== undefined))
|
|
123
|
+
problems.push(...rowProblems(rows, count, breakpoint, allNames));
|
|
124
|
+
}
|
|
125
|
+
return problems;
|
|
126
|
+
}
|
|
127
|
+
/** Whether a definition is valid: what a host checks before drawing a saved template. */
|
|
128
|
+
function isPageTemplateDefinition(definition) {
|
|
129
|
+
return pageTemplateProblems(definition).length === 0;
|
|
130
|
+
}
|
|
@@ -25,7 +25,7 @@ const sift_1 = __importDefault(require("sift"));
|
|
|
25
25
|
* built-in scope has none (its `provider` is not a specification): `scope.type` tells those apart. Anywhere else
|
|
26
26
|
* `scope` is `undefined`, so a condition on it does not match.
|
|
27
27
|
*/
|
|
28
|
-
exports.CONTEXT_ROOTS = ['nrn', 'organization', 'account', 'namespace', 'application', 'scope', 'user'];
|
|
28
|
+
exports.CONTEXT_ROOTS = ['nrn', 'organization', 'account', 'namespace', 'application', 'scope', 'service', 'user'];
|
|
29
29
|
/**
|
|
30
30
|
* In the plugin context, but not usable in a condition yet. Installations resolve for the application's NRN (or the
|
|
31
31
|
* scope's), so the platform never loads a deployment or a build and a condition on either would silently never match.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Generated by scripts/sync-contracts.mjs from @nullplatform/react-ui-components@0.16.
|
|
1
|
+
// Generated by scripts/sync-contracts.mjs from @nullplatform/react-ui-components@0.16.10. Don't edit: change the contract in
|
|
2
2
|
// react-ui-components, bump `uiComponentsContracts` in package.json and run `pnpm sync:contracts`.
|
|
3
3
|
export const UI_COMPONENTS_CONTRACTS = [
|
|
4
4
|
{
|
package/dist/host.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ComponentType } from "react";
|
|
2
|
+
import type { AnnouncedCall } from "./protocol.js";
|
|
2
3
|
export declare function registerTag(component: object, tag: string): void;
|
|
3
4
|
/** Called by the worker runtime with the elements the host announced on `init`. */
|
|
4
5
|
export declare function setHostElements(elements: unknown): void;
|
|
@@ -8,3 +9,10 @@ export declare function setHostElements(elements: unknown): void;
|
|
|
8
9
|
* predate every element that needs the check.
|
|
9
10
|
*/
|
|
10
11
|
export declare function hostRenders(component: ComponentType<any>): boolean;
|
|
12
|
+
/** Called by the worker runtime with the calls the host announced on `init`. */
|
|
13
|
+
export declare function setHostCalls(calls: unknown): void;
|
|
14
|
+
/**
|
|
15
|
+
* Whether this host serves `call`, one a host may lack: an older host, or one whose app cannot do it, refuses it. Offer
|
|
16
|
+
* what the call does only when this is true. False on hosts that announce no calls, which predate every call here.
|
|
17
|
+
*/
|
|
18
|
+
export declare function hostSupports(call: AnnouncedCall): boolean;
|
package/dist/host.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// The tag each catalog component renders, filled in by `component()`.
|
|
2
2
|
const TAGS = new WeakMap();
|
|
3
3
|
let hostElements = new Set();
|
|
4
|
+
let hostCalls = new Set();
|
|
4
5
|
export function registerTag(component, tag) {
|
|
5
6
|
TAGS.set(component, tag);
|
|
6
7
|
}
|
|
@@ -17,3 +18,14 @@ export function hostRenders(component) {
|
|
|
17
18
|
const tag = TAGS.get(component);
|
|
18
19
|
return tag !== undefined && hostElements.has(tag);
|
|
19
20
|
}
|
|
21
|
+
/** Called by the worker runtime with the calls the host announced on `init`. */
|
|
22
|
+
export function setHostCalls(calls) {
|
|
23
|
+
hostCalls = new Set(Array.isArray(calls) ? calls.filter((call) => typeof call === "string") : []);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Whether this host serves `call`, one a host may lack: an older host, or one whose app cannot do it, refuses it. Offer
|
|
27
|
+
* what the call does only when this is true. False on hosts that announce no calls, which predate every call here.
|
|
28
|
+
*/
|
|
29
|
+
export function hostSupports(call) {
|
|
30
|
+
return hostCalls.has(call);
|
|
31
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export { usePluginContext, useNullplatform, useQuery, type WidgetProps, type Que
|
|
|
4
4
|
export { nullplatform, type NullplatformBridge } from './bridge.js';
|
|
5
5
|
export { useTopic, useSetTopic, type UseTopicOptions, type UseTopicResult, type UseSetTopicOptions, type SetTopicState, type TopicMap, type ServiceDraftV1, } from './topics.js';
|
|
6
6
|
export * from './components.js';
|
|
7
|
-
export { hostRenders } from './host.js';
|
|
7
|
+
export { hostRenders, hostSupports } from './host.js';
|
|
8
8
|
export { Canvas, useCanvas, canDrawCanvas, type CanvasProps, type CanvasHandle, type CanvasOptions, type CanvasFrame, type CanvasItem, type CanvasInput, type CanvasTheme, type CanvasTooltip, } from './canvas.js';
|
|
9
|
-
export type { PluginContext, ApiRequest, HttpRequest, HttpResponse, NavigationTarget, SnackbarOptions, ConfirmOptions, TopicSnapshot, TopicStatus } from './protocol.js';
|
|
9
|
+
export type { PluginContext, ApiRequest, HttpRequest, HttpResponse, NavigationTarget, SnackbarOptions, ConfirmOptions, ProgressItem, ProgressPanel, FilePickOptions, PickedFile, FileUpload, TopicSnapshot, TopicStatus, AnnouncedCall } from './protocol.js';
|
|
10
10
|
export { BridgeError } from './protocol.js';
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,6 @@ export { usePluginContext, useNullplatform, useQuery } from './context.js';
|
|
|
4
4
|
export { nullplatform } from './bridge.js';
|
|
5
5
|
export { useTopic, useSetTopic, } from './topics.js';
|
|
6
6
|
export * from './components.js';
|
|
7
|
-
export { hostRenders } from './host.js';
|
|
7
|
+
export { hostRenders, hostSupports } from './host.js';
|
|
8
8
|
export { Canvas, useCanvas, canDrawCanvas, } from './canvas.js';
|
|
9
9
|
export { BridgeError } from './protocol.js';
|
package/dist/protocol.d.ts
CHANGED
|
@@ -49,6 +49,20 @@ export interface PluginContext {
|
|
|
49
49
|
name?: string;
|
|
50
50
|
};
|
|
51
51
|
};
|
|
52
|
+
/**
|
|
53
|
+
* Set on a service's own pages, and for each service of a list when the host asks which of a plugin's sections
|
|
54
|
+
* apply to it. `specification` is the kind of service it is, the same a `when` reads as `service.specification.*`.
|
|
55
|
+
*/
|
|
56
|
+
service?: {
|
|
57
|
+
id: number | string;
|
|
58
|
+
slug?: string;
|
|
59
|
+
name?: string;
|
|
60
|
+
specification?: {
|
|
61
|
+
id: string;
|
|
62
|
+
slug?: string;
|
|
63
|
+
name?: string;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
52
66
|
/** Set on deployment pages. Not usable in `when` yet (see `CONTEXT_ROOTS`). */
|
|
53
67
|
deployment?: {
|
|
54
68
|
id: number | string;
|
|
@@ -122,6 +136,87 @@ export declare const CONFIRM_LIMITS: {
|
|
|
122
136
|
readonly label: 40;
|
|
123
137
|
readonly confirmationToken: 100;
|
|
124
138
|
};
|
|
139
|
+
/**
|
|
140
|
+
* One line of the host's progress panel: one of the things a longer piece of work is made of (a file of an upload).
|
|
141
|
+
* `waiting` has not started, `running` is in flight, `done` and `failed` are over.
|
|
142
|
+
*/
|
|
143
|
+
export interface ProgressItem {
|
|
144
|
+
/** Names the line across updates of the same panel. */
|
|
145
|
+
id: string;
|
|
146
|
+
label: string;
|
|
147
|
+
/** A short note under the label: a size, or why it failed. */
|
|
148
|
+
detail?: string;
|
|
149
|
+
status: 'waiting' | 'running' | 'done' | 'failed';
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Work that takes a while, as the host draws it in a corner of the page: a plugin cannot draw over the page. The
|
|
153
|
+
* host counts how many items are over out of `items`; it rejects a panel over a cap (see `PROGRESS_LIMITS`) rather
|
|
154
|
+
* than cutting what the person reads.
|
|
155
|
+
*/
|
|
156
|
+
export interface ProgressPanel {
|
|
157
|
+
title: string;
|
|
158
|
+
items: ProgressItem[];
|
|
159
|
+
}
|
|
160
|
+
/** Caps of a `ProgressPanel`: how many items, and the length of each string. */
|
|
161
|
+
export declare const PROGRESS_LIMITS: {
|
|
162
|
+
readonly title: 120;
|
|
163
|
+
readonly items: 100;
|
|
164
|
+
readonly id: 64;
|
|
165
|
+
readonly label: 200;
|
|
166
|
+
readonly detail: 200;
|
|
167
|
+
};
|
|
168
|
+
/** What `files.pick` asks the host's file picker for. */
|
|
169
|
+
export interface FilePickOptions {
|
|
170
|
+
/** The kinds of file the picker offers, as an `<input accept>` list: extensions (`.csv`) or media types (`image/*`). */
|
|
171
|
+
accept?: string[];
|
|
172
|
+
/** Lets the person pick several files at once (`FILE_LIMITS.picked` at most); one file otherwise. */
|
|
173
|
+
multiple?: boolean;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* A file the person picked in the host's file picker. Its bytes stay in the host: a plugin never reads them. `id`
|
|
177
|
+
* names the file for `files.upload`, for as long as the plugin runs.
|
|
178
|
+
*/
|
|
179
|
+
export interface PickedFile {
|
|
180
|
+
id: string;
|
|
181
|
+
name: string;
|
|
182
|
+
/** Size in bytes. */
|
|
183
|
+
size: number;
|
|
184
|
+
/** The media type the browser reports for the file; empty when it knows none. */
|
|
185
|
+
type: string;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Sends a picked file with an HTML form POST (`multipart/form-data`): every field in `fields`, then the file as
|
|
189
|
+
* `file`. This is the shape of an S3 presigned POST. The host sends it without the person's session and cannot read
|
|
190
|
+
* the answer (the upload's host need not allow the dashboard's origin), so check afterwards that the file arrived.
|
|
191
|
+
*/
|
|
192
|
+
export interface FileUpload {
|
|
193
|
+
/** The `id` of a `PickedFile`. */
|
|
194
|
+
file: string;
|
|
195
|
+
/** An https URL whose host is declared in `permissions.upload`. */
|
|
196
|
+
url: string;
|
|
197
|
+
/** Form fields sent before the file. */
|
|
198
|
+
fields?: Record<string, string>;
|
|
199
|
+
}
|
|
200
|
+
/** Caps of `FilePickOptions` and `FileUpload`: counts and string lengths. `picked` is how many files one pick hands back. */
|
|
201
|
+
export declare const FILE_LIMITS: {
|
|
202
|
+
readonly accept: 20;
|
|
203
|
+
readonly acceptEntry: 100;
|
|
204
|
+
readonly picked: 100;
|
|
205
|
+
readonly url: 2048;
|
|
206
|
+
readonly fields: 50;
|
|
207
|
+
readonly fieldName: 200;
|
|
208
|
+
readonly fieldValue: 8192;
|
|
209
|
+
};
|
|
210
|
+
/**
|
|
211
|
+
* An approval request's id, as the approvals API routes it (`/approval/:id([0-9]{1,})`): digits only. At most 19, a
|
|
212
|
+
* 64-bit integer, which holds any id it stores; the host rejects anything else.
|
|
213
|
+
*/
|
|
214
|
+
export declare const APPROVAL_ID: RegExp;
|
|
215
|
+
/**
|
|
216
|
+
* Bridge calls a host may lack: one older than the call, or whose app leaves its adapter out, refuses it. A host
|
|
217
|
+
* that serves one announces it on `init` (see `hostSupports`). Only calls added since that announcement are here.
|
|
218
|
+
*/
|
|
219
|
+
export type AnnouncedCall = 'ui.approval';
|
|
125
220
|
/** Methods a plugin can call on the host. */
|
|
126
221
|
export interface BridgeMethods {
|
|
127
222
|
'assets.url': (path: string) => Promise<string>;
|
|
@@ -131,6 +226,14 @@ export interface BridgeMethods {
|
|
|
131
226
|
'ui.snackbar': (options: SnackbarOptions) => Promise<void>;
|
|
132
227
|
/** Resolves `true` only when the person confirms; `false` when they cancel or the host draws no dialog. */
|
|
133
228
|
'ui.confirm': (options: ConfirmOptions) => Promise<boolean>;
|
|
229
|
+
/** Draws, replaces or (with `null`) removes the plugin's progress panel. */
|
|
230
|
+
'ui.progress': (panel: ProgressPanel | null) => Promise<void>;
|
|
231
|
+
/** Shows an approval request in the host's modal; resolves once the person closes it, saying nothing of what they did. */
|
|
232
|
+
'ui.approval': (approvalId: string) => Promise<void>;
|
|
233
|
+
/** Resolves the files the person picked: none when they cancel, one unless `multiple`. */
|
|
234
|
+
'files.pick': (options?: FilePickOptions) => Promise<PickedFile[]>;
|
|
235
|
+
/** Resolves once the form was sent; it does not say whether the upload's host accepted it. */
|
|
236
|
+
'files.upload': (upload: FileUpload) => Promise<void>;
|
|
134
237
|
'context.get': () => Promise<PluginContext>;
|
|
135
238
|
'topics.get': (topic: string) => Promise<TopicSnapshot>;
|
|
136
239
|
'topics.subscribe': (topic: string) => Promise<TopicSnapshot>;
|
|
@@ -258,12 +361,16 @@ export type WorkerMessage = {
|
|
|
258
361
|
error: SerializedError;
|
|
259
362
|
};
|
|
260
363
|
export type HostMessage =
|
|
261
|
-
/**
|
|
364
|
+
/**
|
|
365
|
+
* `elements`: the catalog tags this host draws. Hosts before it fail a widget that renders a tag they lack.
|
|
366
|
+
* `calls`: the `AnnouncedCall`s this host serves; hosts before it serve none of them.
|
|
367
|
+
*/
|
|
262
368
|
{
|
|
263
369
|
type: 'init';
|
|
264
370
|
pluginId: string;
|
|
265
371
|
context: PluginContext;
|
|
266
372
|
elements?: string[];
|
|
373
|
+
calls?: string[];
|
|
267
374
|
} | {
|
|
268
375
|
type: 'mount';
|
|
269
376
|
mountId: string;
|
package/dist/protocol.js
CHANGED
|
@@ -9,11 +9,25 @@
|
|
|
9
9
|
export const PROTOCOL_VERSION = 1;
|
|
10
10
|
/** Maximum length of each `ConfirmOptions` string. */
|
|
11
11
|
export const CONFIRM_LIMITS = { title: 200, message: 1000, label: 40, confirmationToken: 100 };
|
|
12
|
+
/** Caps of a `ProgressPanel`: how many items, and the length of each string. */
|
|
13
|
+
export const PROGRESS_LIMITS = { title: 120, items: 100, id: 64, label: 200, detail: 200 };
|
|
14
|
+
/** Caps of `FilePickOptions` and `FileUpload`: counts and string lengths. `picked` is how many files one pick hands back. */
|
|
15
|
+
export const FILE_LIMITS = { accept: 20, acceptEntry: 100, picked: 100, url: 2048, fields: 50, fieldName: 200, fieldValue: 8192 };
|
|
16
|
+
/**
|
|
17
|
+
* An approval request's id, as the approvals API routes it (`/approval/:id([0-9]{1,})`): digits only. At most 19, a
|
|
18
|
+
* 64-bit integer, which holds any id it stores; the host rejects anything else.
|
|
19
|
+
*/
|
|
20
|
+
export const APPROVAL_ID = /^[0-9]{1,19}$/;
|
|
12
21
|
/** How long the host gives a bridge call before it answers `TIMEOUT`. */
|
|
13
22
|
export const BRIDGE_CALL_DEADLINE_MS = 30000;
|
|
14
23
|
/** Calls that wait for a person, not a machine, and so get longer than `BRIDGE_CALL_DEADLINE_MS`. */
|
|
15
24
|
export const BRIDGE_CALL_DEADLINES_MS = {
|
|
16
25
|
'ui.confirm': 10 * 60 * 1000,
|
|
26
|
+
// Reading an approval and completing its checklist takes longer than a yes or no.
|
|
27
|
+
'ui.approval': 30 * 60 * 1000,
|
|
28
|
+
'files.pick': 10 * 60 * 1000,
|
|
29
|
+
// Not a person, but a file on a slow connection: the same ten minutes.
|
|
30
|
+
'files.upload': 10 * 60 * 1000,
|
|
17
31
|
};
|
|
18
32
|
/** The host's deadline for one call. */
|
|
19
33
|
export function bridgeCallDeadline(method) {
|
package/dist/worker.js
CHANGED
|
@@ -9,7 +9,7 @@ import { BatchingRemoteConnection } from '@remote-dom/core/elements';
|
|
|
9
9
|
import { defineCatalogElements, ROOT_TAG } from './elements.js';
|
|
10
10
|
import { bridge } from './bridge.js';
|
|
11
11
|
import { PluginContextProvider, broadcastContext } from './context.js';
|
|
12
|
-
import { setHostElements } from './host.js';
|
|
12
|
+
import { setHostCalls, setHostElements } from './host.js';
|
|
13
13
|
import { receiveTopic } from './topics.js';
|
|
14
14
|
import { attachCanvasPort, receiveCanvas } from './canvas.js';
|
|
15
15
|
import { PROTOCOL_VERSION, createIdGenerator, serializeError, serializeFunctions, } from './protocol.js';
|
|
@@ -89,6 +89,7 @@ function handle(port, message) {
|
|
|
89
89
|
case 'init':
|
|
90
90
|
pluginId = message.pluginId;
|
|
91
91
|
setHostElements(message.elements);
|
|
92
|
+
setHostCalls(message.calls);
|
|
92
93
|
broadcastContext(message.context);
|
|
93
94
|
break;
|
|
94
95
|
case 'mount':
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nullplatform/ui-plugin-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.0-beta.0",
|
|
4
4
|
"description": "SDK for nullplatform UI plugins: catalog components, bridge client and defineUI",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"test": "vitest run --passWithNoTests",
|
|
43
43
|
"sync:contracts": "node scripts/sync-contracts.mjs"
|
|
44
44
|
},
|
|
45
|
-
"uiComponentsContracts": "0.16.
|
|
45
|
+
"uiComponentsContracts": "0.16.10",
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@remote-dom/core": "^1.11.1",
|
|
48
48
|
"@remote-dom/react": "^1.2.2",
|