@wickermoney/plugin-sdk 0.4.2 → 0.6.0-rc.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.
Files changed (140) hide show
  1. package/README.md +265 -12
  2. package/dist/{recurrence → date}/calendar.d.ts +30 -2
  3. package/dist/date/calendar.d.ts.map +1 -0
  4. package/dist/{recurrence → date}/calendar.js +42 -3
  5. package/dist/date/calendar.js.map +1 -0
  6. package/dist/date/index.d.ts +17 -0
  7. package/dist/date/index.d.ts.map +1 -0
  8. package/dist/date/index.js +17 -0
  9. package/dist/date/index.js.map +1 -0
  10. package/dist/index.d.ts +15 -1
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +14 -1
  13. package/dist/index.js.map +1 -1
  14. package/dist/isolated/PluginApiError.d.ts +20 -0
  15. package/dist/isolated/PluginApiError.d.ts.map +1 -0
  16. package/dist/isolated/PluginApiError.js +25 -0
  17. package/dist/isolated/PluginApiError.js.map +1 -0
  18. package/dist/isolated/client.d.ts +118 -0
  19. package/dist/isolated/client.d.ts.map +1 -0
  20. package/dist/isolated/client.js +275 -0
  21. package/dist/isolated/client.js.map +1 -0
  22. package/dist/isolated/format.d.ts +25 -0
  23. package/dist/isolated/format.d.ts.map +1 -0
  24. package/dist/isolated/format.js +59 -0
  25. package/dist/isolated/format.js.map +1 -0
  26. package/dist/isolated/index.d.ts +48 -0
  27. package/dist/isolated/index.d.ts.map +1 -0
  28. package/dist/isolated/index.js +45 -0
  29. package/dist/isolated/index.js.map +1 -0
  30. package/dist/isolated/protocol.d.ts +217 -0
  31. package/dist/isolated/protocol.d.ts.map +1 -0
  32. package/dist/isolated/protocol.js +31 -0
  33. package/dist/isolated/protocol.js.map +1 -0
  34. package/dist/isolated/theme.d.ts +24 -0
  35. package/dist/isolated/theme.d.ts.map +1 -0
  36. package/dist/isolated/theme.js +32 -0
  37. package/dist/isolated/theme.js.map +1 -0
  38. package/dist/isolated/validate.d.ts +47 -0
  39. package/dist/isolated/validate.d.ts.map +1 -0
  40. package/dist/isolated/validate.js +260 -0
  41. package/dist/isolated/validate.js.map +1 -0
  42. package/dist/manifest/PERMISSIONS.d.ts +5 -0
  43. package/dist/manifest/PERMISSIONS.d.ts.map +1 -1
  44. package/dist/manifest/PERMISSIONS.js +5 -0
  45. package/dist/manifest/PERMISSIONS.js.map +1 -1
  46. package/dist/manifest/checkRemoteEntry.d.ts +2 -1
  47. package/dist/manifest/checkRemoteEntry.d.ts.map +1 -1
  48. package/dist/manifest/checkRemoteEntry.js +2 -1
  49. package/dist/manifest/checkRemoteEntry.js.map +1 -1
  50. package/dist/manifest/checkRemoteEntryIntegrity.d.ts +27 -0
  51. package/dist/manifest/checkRemoteEntryIntegrity.d.ts.map +1 -0
  52. package/dist/manifest/checkRemoteEntryIntegrity.js +47 -0
  53. package/dist/manifest/checkRemoteEntryIntegrity.js.map +1 -0
  54. package/dist/manifest/index.d.ts +2 -5
  55. package/dist/manifest/index.d.ts.map +1 -1
  56. package/dist/manifest/index.js +2 -5
  57. package/dist/manifest/index.js.map +1 -1
  58. package/dist/manifest/integritySchema.d.ts +28 -0
  59. package/dist/manifest/integritySchema.d.ts.map +1 -0
  60. package/dist/manifest/integritySchema.js +30 -0
  61. package/dist/manifest/integritySchema.js.map +1 -0
  62. package/dist/manifest/parseIntegrity.d.ts +14 -0
  63. package/dist/manifest/parseIntegrity.d.ts.map +1 -0
  64. package/dist/manifest/parseIntegrity.js +16 -0
  65. package/dist/manifest/parseIntegrity.js.map +1 -0
  66. package/dist/manifest/pluginManifestSchema.d.ts +2 -0
  67. package/dist/manifest/pluginManifestSchema.d.ts.map +1 -1
  68. package/dist/manifest/pluginManifestSchema.js +48 -1
  69. package/dist/manifest/pluginManifestSchema.js.map +1 -1
  70. package/dist/manifest/tableGrantSchema.d.ts +6 -1
  71. package/dist/manifest/tableGrantSchema.d.ts.map +1 -1
  72. package/dist/manifest/tableGrantSchema.js +6 -1
  73. package/dist/manifest/tableGrantSchema.js.map +1 -1
  74. package/dist/money/index.d.ts +4 -0
  75. package/dist/money/index.d.ts.map +1 -1
  76. package/dist/money/index.js.map +1 -1
  77. package/dist/recurrence/index.d.ts +8 -0
  78. package/dist/recurrence/index.d.ts.map +1 -1
  79. package/dist/recurrence/index.js +10 -0
  80. package/dist/recurrence/index.js.map +1 -1
  81. package/dist/recurrence/projection.js +1 -1
  82. package/dist/recurrence/projection.js.map +1 -1
  83. package/dist/recurrence/schedule.js +1 -1
  84. package/dist/recurrence/schedule.js.map +1 -1
  85. package/dist/recurrence/scheduled.js +1 -1
  86. package/dist/recurrence/scheduled.js.map +1 -1
  87. package/dist/runtime.d.ts +26 -3
  88. package/dist/runtime.d.ts.map +1 -1
  89. package/dist/runtime.js.map +1 -1
  90. package/dist/server/ConditionForMatching.d.ts +18 -0
  91. package/dist/server/ConditionForMatching.d.ts.map +1 -0
  92. package/dist/server/ConditionForMatching.js +2 -0
  93. package/dist/server/ConditionForMatching.js.map +1 -0
  94. package/dist/server/PluginRouteError.d.ts +27 -0
  95. package/dist/server/PluginRouteError.d.ts.map +1 -0
  96. package/dist/server/PluginRouteError.js +32 -0
  97. package/dist/server/PluginRouteError.js.map +1 -0
  98. package/dist/server/PluginRouteIssue.d.ts +8 -0
  99. package/dist/server/PluginRouteIssue.d.ts.map +1 -0
  100. package/dist/server/PluginRouteIssue.js +2 -0
  101. package/dist/server/PluginRouteIssue.js.map +1 -0
  102. package/dist/server/Query.d.ts +11 -0
  103. package/dist/server/Query.d.ts.map +1 -0
  104. package/dist/server/Query.js +2 -0
  105. package/dist/server/Query.js.map +1 -0
  106. package/dist/server/RegisterRoute.d.ts +24 -0
  107. package/dist/server/RegisterRoute.d.ts.map +1 -0
  108. package/dist/server/RegisterRoute.js +2 -0
  109. package/dist/server/RegisterRoute.js.map +1 -0
  110. package/dist/server/RouteContext.d.ts +12 -0
  111. package/dist/server/RouteContext.d.ts.map +1 -0
  112. package/dist/server/RouteContext.js +2 -0
  113. package/dist/server/RouteContext.js.map +1 -0
  114. package/dist/server/RouteMethod.d.ts +3 -0
  115. package/dist/server/RouteMethod.d.ts.map +1 -0
  116. package/dist/server/RouteMethod.js +2 -0
  117. package/dist/server/RouteMethod.js.map +1 -0
  118. package/dist/server/RuleForMatching.d.ts +16 -0
  119. package/dist/server/RuleForMatching.d.ts.map +1 -0
  120. package/dist/server/RuleForMatching.js +2 -0
  121. package/dist/server/RuleForMatching.js.map +1 -0
  122. package/dist/server/RuleSubject.d.ts +10 -0
  123. package/dist/server/RuleSubject.d.ts.map +1 -0
  124. package/dist/server/RuleSubject.js +2 -0
  125. package/dist/server/RuleSubject.js.map +1 -0
  126. package/dist/server/RunAsPlugin.d.ts +9 -0
  127. package/dist/server/RunAsPlugin.d.ts.map +1 -0
  128. package/dist/server/RunAsPlugin.js +2 -0
  129. package/dist/server/RunAsPlugin.js.map +1 -0
  130. package/dist/server/index.d.ts +30 -0
  131. package/dist/server/index.d.ts.map +1 -0
  132. package/dist/server/index.js +3 -0
  133. package/dist/server/index.js.map +1 -0
  134. package/dist/server/isUuid.d.ts +18 -0
  135. package/dist/server/isUuid.d.ts.map +1 -0
  136. package/dist/server/isUuid.js +26 -0
  137. package/dist/server/isUuid.js.map +1 -0
  138. package/package.json +13 -1
  139. package/dist/recurrence/calendar.d.ts.map +0 -1
  140. package/dist/recurrence/calendar.js.map +0 -1
@@ -0,0 +1,217 @@
1
+ import type { WidgetSize } from '../manifest/index.js';
2
+ import type { DashboardRange } from '../range.js';
3
+ /**
4
+ * Version of the message protocol between the host and a plugin frame.
5
+ *
6
+ * Bumped only for a change an older peer cannot ignore (a changed field, a
7
+ * removed message). Adding a message type is not a bump: each side ignores
8
+ * message types it does not know, so a newer host can talk to an older plugin.
9
+ */
10
+ export declare const ISOLATED_PROTOCOL_VERSION: 1;
11
+ /**
12
+ * The error codes the host is expected to use. A host may send others (the
13
+ * API's own codes pass through), so `PluginApiError.code` is a plain string;
14
+ * these are the ones a plugin can rely on.
15
+ *
16
+ * - `grant_denied` - the manifest does not grant the table or path.
17
+ * - `invalid_request` - the request was malformed or used an unsupported option.
18
+ * - `not_supported` - the host does not implement the message (for example `notify`).
19
+ * - `network_error` - the host could not reach the API.
20
+ * - `aborted` - the caller aborted the request.
21
+ * - `disconnected` - the connection to the host was closed before an answer came.
22
+ * - `request_failed` - the API answered with an error that carried no code of its own.
23
+ */
24
+ export declare const PLUGIN_ERROR_CODES: readonly ["grant_denied", "invalid_request", "not_supported", "network_error", "aborted", "disconnected", "request_failed"];
25
+ /** One of the error codes in {@link PLUGIN_ERROR_CODES}. */
26
+ export type PluginErrorCode = (typeof PLUGIN_ERROR_CODES)[number];
27
+ /** One problem with a request, tied to the body field it is about. Same shape as the API's `validation_failed` issues. */
28
+ export interface PluginApiIssue {
29
+ /** The field, as the request body spells it; empty for the request as a whole. */
30
+ readonly path: readonly (string | number)[];
31
+ /** A sentence about that field that does not repeat its name. */
32
+ readonly message: string;
33
+ }
34
+ /** The plugin-visible error, as it crosses the channel. The client turns it into a `PluginApiError`. */
35
+ export interface PluginErrorPayload {
36
+ /** A code the plugin can branch on; see {@link PLUGIN_ERROR_CODES}. */
37
+ readonly code: string;
38
+ /** A sentence safe to show the person. */
39
+ readonly message: string;
40
+ /** The HTTP status when the failure came from an API response. */
41
+ readonly status?: number;
42
+ /** Field-by-field problems, from a `validation_failed` or a plugin's own 400. */
43
+ readonly issues?: readonly PluginApiIssue[];
44
+ }
45
+ /** HTTP methods a plugin can ask the host to send. */
46
+ export type PluginRequestMethod = 'GET' | 'POST' | 'PUT' | 'DELETE';
47
+ /** The `RequestInit.cache` values the protocol carries. Everything else in `RequestInit` stays in the frame. */
48
+ export type PluginRequestCache = 'default' | 'no-store' | 'reload';
49
+ /** Which way focus leaves or enters the frame. */
50
+ export type FocusDirection = 'next' | 'previous';
51
+ /** The colour scheme the host is showing. */
52
+ export type ThemeScheme = 'light' | 'dark';
53
+ /**
54
+ * The theme the host applies to the frame: the scheme and the design tokens
55
+ * (CSS custom properties, keys starting `--`) the host's stylesheet defines.
56
+ * A frame cannot inherit custom properties from the host page, so the host
57
+ * sends them.
58
+ */
59
+ export interface HostTheme {
60
+ /** The active scheme; applied as `data-theme` on the frame's root element. */
61
+ readonly scheme: ThemeScheme;
62
+ /** Custom property name (with the leading `--`) to value. */
63
+ readonly tokens: Readonly<Record<string, string>>;
64
+ }
65
+ /** The signed-in user, as the plugin may see them. The same three fields as `PluginSession`. */
66
+ export interface HostSession {
67
+ readonly userId: string;
68
+ readonly email: string;
69
+ readonly timezone: string;
70
+ }
71
+ /** How the host formats numbers and dates for this person. */
72
+ export interface HostLocale {
73
+ /** A BCP 47 tag such as `en-US`. */
74
+ readonly locale: string;
75
+ /** An IANA time zone name such as `Europe/London`. */
76
+ readonly timezone: string;
77
+ }
78
+ /**
79
+ * Frame to host, via `window.parent.postMessage`: "I am loaded; these are the
80
+ * protocol versions I speak." Carries nothing secret. The host identifies the
81
+ * sender by `event.source` (the frame's `contentWindow`), never by
82
+ * `event.origin`, which is `"null"` for a sandboxed frame.
83
+ */
84
+ export interface FrameHello {
85
+ readonly type: 'wm.hello';
86
+ readonly protocols: readonly number[];
87
+ }
88
+ /**
89
+ * Host to frame, via `frame.contentWindow.postMessage` with one `MessagePort`
90
+ * transferred: "use this version, over this port." All later traffic is on that
91
+ * port, which only this frame and the host hold.
92
+ */
93
+ export interface HostConnect {
94
+ readonly type: 'wm.connect';
95
+ readonly protocol: number;
96
+ }
97
+ /** Host to frame: no common protocol version. The frame should show an error and stop. */
98
+ export interface HostRefuse {
99
+ readonly type: 'wm.refuse';
100
+ readonly supported: readonly number[];
101
+ }
102
+ /** The frame has the port and is listening; the host answers with {@link InitMessage}. */
103
+ export interface ReadyMessage {
104
+ readonly type: 'ready';
105
+ readonly protocol: number;
106
+ }
107
+ /**
108
+ * An API call. `path` is relative to the API root, exactly as for `ctx.api`.
109
+ * The host checks it against the manifest's grants and performs it with its own
110
+ * credentials; the frame never holds a token. `id` is chosen by the frame and
111
+ * echoed in the response.
112
+ */
113
+ export interface RequestMessage {
114
+ readonly type: 'request';
115
+ readonly id: number;
116
+ readonly method: PluginRequestMethod;
117
+ readonly path: string;
118
+ /** JSON body for `POST` and `PUT`. */
119
+ readonly body?: unknown;
120
+ readonly cache?: PluginRequestCache;
121
+ }
122
+ /** The caller aborted request `id`. The host drops the answer and may abort the call. */
123
+ export interface CancelMessage {
124
+ readonly type: 'cancel';
125
+ readonly id: number;
126
+ }
127
+ /** Navigate the shell to an in-app path. For a page frame this also keeps the address bar in step. */
128
+ export interface NavigateMessage {
129
+ readonly type: 'navigate';
130
+ readonly path: string;
131
+ }
132
+ /**
133
+ * The frame's content height in CSS pixels. The host owns width. It sets the
134
+ * frame height from this, within its own minimum and maximum.
135
+ */
136
+ export interface ResizeMessage {
137
+ readonly type: 'resize';
138
+ readonly height: number;
139
+ }
140
+ /** Focus has left the frame's last (`next`) or first (`previous`) focusable element; the host moves it on. */
141
+ export interface FocusOutMessage {
142
+ readonly type: 'focus-out';
143
+ readonly direction: FocusDirection;
144
+ }
145
+ /**
146
+ * Reserved for the `notify` permission, which no host implements yet. A host
147
+ * answers with a `not_supported` error response. The message exists so the
148
+ * protocol does not change when `notify` is built.
149
+ */
150
+ export interface NotifyMessage {
151
+ readonly type: 'notify';
152
+ readonly id: number;
153
+ readonly level: 'info' | 'success' | 'warning' | 'error';
154
+ readonly message: string;
155
+ }
156
+ /** Every message a plugin frame may send on the port. */
157
+ export type PluginMessage = ReadyMessage | RequestMessage | CancelMessage | NavigateMessage | ResizeMessage | FocusOutMessage | NotifyMessage;
158
+ /** What the frame is: a dashboard widget or a full page. */
159
+ export type FrameKind = 'widget' | 'page';
160
+ /** First message from the host; everything the frame needs to render. */
161
+ export interface InitMessage {
162
+ readonly type: 'init';
163
+ readonly protocol: number;
164
+ /** The plugin's manifest id. */
165
+ readonly pluginId: string;
166
+ readonly kind: FrameKind;
167
+ readonly session: HostSession;
168
+ readonly locale: HostLocale;
169
+ readonly theme: HostTheme;
170
+ /** Widgets only: the size the widget is rendered at. */
171
+ readonly size?: WidgetSize;
172
+ /** Widgets only: the dashboard's current range, when there is one. */
173
+ readonly range?: DashboardRange;
174
+ /** Pages only: the path under the page's own route to render first. Starts with `/`. */
175
+ readonly path?: string;
176
+ }
177
+ /** The answer to a {@link RequestMessage} or {@link NotifyMessage}. */
178
+ export type ResponseMessage = {
179
+ readonly type: 'response';
180
+ readonly id: number;
181
+ readonly ok: true;
182
+ readonly value: unknown;
183
+ } | {
184
+ readonly type: 'response';
185
+ readonly id: number;
186
+ readonly ok: false;
187
+ readonly error: PluginErrorPayload;
188
+ };
189
+ /** The scheme or tokens changed (the person switched theme, or the system did). */
190
+ export interface ThemeMessage {
191
+ readonly type: 'theme';
192
+ readonly theme: HostTheme;
193
+ }
194
+ /** The locale or time zone changed. */
195
+ export interface LocaleMessage {
196
+ readonly type: 'locale';
197
+ readonly locale: HostLocale;
198
+ }
199
+ /** A widget's size or the dashboard range changed. Either field may be absent when it did not change. */
200
+ export interface PropsMessage {
201
+ readonly type: 'props';
202
+ readonly size?: WidgetSize;
203
+ readonly range?: DashboardRange;
204
+ }
205
+ /** Pages only: the route under the page changed from outside (browser back, a link). */
206
+ export interface RouteMessage {
207
+ readonly type: 'route';
208
+ readonly path: string;
209
+ }
210
+ /** Move focus into the frame, to its first or last focusable element. */
211
+ export interface FocusInMessage {
212
+ readonly type: 'focus-in';
213
+ readonly direction: 'first' | 'last';
214
+ }
215
+ /** Every message the host may send on the port. */
216
+ export type HostMessage = InitMessage | ResponseMessage | ThemeMessage | LocaleMessage | PropsMessage | RouteMessage | FocusInMessage;
217
+ //# sourceMappingURL=protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../src/isolated/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAE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,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CACtB;AAED,yEAAyE;AACzE,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAA;IACzB,QAAQ,CAAC,SAAS,EAAE,OAAO,GAAG,MAAM,CAAA;CACrC;AAED,mDAAmD;AACnD,MAAM,MAAM,WAAW,GACnB,WAAW,GACX,eAAe,GACf,YAAY,GACZ,aAAa,GACb,YAAY,GACZ,YAAY,GACZ,cAAc,CAAA"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Version of the message protocol between the host and a plugin frame.
3
+ *
4
+ * Bumped only for a change an older peer cannot ignore (a changed field, a
5
+ * removed message). Adding a message type is not a bump: each side ignores
6
+ * message types it does not know, so a newer host can talk to an older plugin.
7
+ */
8
+ export const ISOLATED_PROTOCOL_VERSION = 1;
9
+ /**
10
+ * The error codes the host is expected to use. A host may send others (the
11
+ * API's own codes pass through), so `PluginApiError.code` is a plain string;
12
+ * these are the ones a plugin can rely on.
13
+ *
14
+ * - `grant_denied` - the manifest does not grant the table or path.
15
+ * - `invalid_request` - the request was malformed or used an unsupported option.
16
+ * - `not_supported` - the host does not implement the message (for example `notify`).
17
+ * - `network_error` - the host could not reach the API.
18
+ * - `aborted` - the caller aborted the request.
19
+ * - `disconnected` - the connection to the host was closed before an answer came.
20
+ * - `request_failed` - the API answered with an error that carried no code of its own.
21
+ */
22
+ export const PLUGIN_ERROR_CODES = [
23
+ 'grant_denied',
24
+ 'invalid_request',
25
+ 'not_supported',
26
+ 'network_error',
27
+ 'aborted',
28
+ 'disconnected',
29
+ 'request_failed',
30
+ ];
31
+ //# sourceMappingURL=protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../src/isolated/protocol.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAU,CAAA;AAEnD;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,cAAc;IACd,iBAAiB;IACjB,eAAe;IACf,eAAe;IACf,SAAS;IACT,cAAc;IACd,gBAAgB;CACR,CAAA"}
@@ -0,0 +1,24 @@
1
+ import type { HostTheme } from './protocol.js';
2
+ /** The part of an element `applyHostTheme` writes to. An `HTMLElement` satisfies it. */
3
+ export interface ThemeTarget {
4
+ setAttribute(name: string, value: string): void;
5
+ readonly style: {
6
+ setProperty(name: string, value: string): void;
7
+ removeProperty(name: string): unknown;
8
+ };
9
+ }
10
+ /**
11
+ * Applies the host's theme to a frame's root element: sets `data-theme` to the
12
+ * scheme and each design token as a CSS custom property. Tokens a previous call
13
+ * set that the new theme no longer has are removed.
14
+ *
15
+ * A frame cannot inherit custom properties from the host page, so the host
16
+ * sends them and this writes them. `connectToHost` calls it for you on `init`
17
+ * and on every theme change; call it yourself only if you opted out.
18
+ *
19
+ * @param theme - The theme from the host.
20
+ * @param root - The element to style. Defaults to `document.documentElement`.
21
+ * @throws {TypeError} When there is no `root` and no `document`.
22
+ */
23
+ export declare function applyHostTheme(theme: HostTheme, root?: ThemeTarget): void;
24
+ //# sourceMappingURL=theme.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../src/isolated/theme.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAE9C,wFAAwF;AACxF,MAAM,WAAW,WAAW;IAC1B,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IAC/C,QAAQ,CAAC,KAAK,EAAE;QACd,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;QAC9C,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAA;KACtC,CAAA;CACF;AAKD;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,IAAI,CAYzE"}
@@ -0,0 +1,32 @@
1
+ /** Tokens written per target, so a later theme can remove the ones it no longer defines. */
2
+ const applied = new WeakMap();
3
+ /**
4
+ * Applies the host's theme to a frame's root element: sets `data-theme` to the
5
+ * scheme and each design token as a CSS custom property. Tokens a previous call
6
+ * set that the new theme no longer has are removed.
7
+ *
8
+ * A frame cannot inherit custom properties from the host page, so the host
9
+ * sends them and this writes them. `connectToHost` calls it for you on `init`
10
+ * and on every theme change; call it yourself only if you opted out.
11
+ *
12
+ * @param theme - The theme from the host.
13
+ * @param root - The element to style. Defaults to `document.documentElement`.
14
+ * @throws {TypeError} When there is no `root` and no `document`.
15
+ */
16
+ export function applyHostTheme(theme, root) {
17
+ const target = root ?? (typeof document === 'undefined' ? undefined : document.documentElement);
18
+ if (target === undefined)
19
+ throw new TypeError('applyHostTheme needs a root element outside a browser');
20
+ const before = applied.get(target) ?? new Set();
21
+ const now = new Set();
22
+ target.setAttribute('data-theme', theme.scheme);
23
+ for (const [name, value] of Object.entries(theme.tokens)) {
24
+ target.style.setProperty(name, value);
25
+ now.add(name);
26
+ }
27
+ for (const name of before)
28
+ if (!now.has(name))
29
+ target.style.removeProperty(name);
30
+ applied.set(target, now);
31
+ }
32
+ //# sourceMappingURL=theme.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"theme.js","sourceRoot":"","sources":["../../src/isolated/theme.ts"],"names":[],"mappings":"AAWA,4FAA4F;AAC5F,MAAM,OAAO,GAAG,IAAI,OAAO,EAAuB,CAAA;AAElD;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,cAAc,CAAC,KAAgB,EAAE,IAAkB;IACjE,MAAM,MAAM,GAAG,IAAI,IAAI,CAAC,OAAO,QAAQ,KAAK,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAA;IAC/F,IAAI,MAAM,KAAK,SAAS;QAAE,MAAM,IAAI,SAAS,CAAC,uDAAuD,CAAC,CAAA;IACtG,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,IAAI,GAAG,EAAU,CAAA;IACvD,MAAM,GAAG,GAAG,IAAI,GAAG,EAAU,CAAA;IAC7B,MAAM,CAAC,YAAY,CAAC,YAAY,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;IAC/C,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;QACzD,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;QACrC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IACf,CAAC;IACD,KAAK,MAAM,IAAI,IAAI,MAAM;QAAE,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,CAAA;IAChF,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;AAC1B,CAAC"}
@@ -0,0 +1,47 @@
1
+ import type { FrameHello, HostConnect, HostMessage, HostRefuse, PluginMessage } from './protocol.js';
2
+ /** Longest request path accepted, in characters. */
3
+ export declare const MAX_PATH_LENGTH = 2048;
4
+ /** Largest content height accepted from a frame, in CSS pixels. */
5
+ export declare const MAX_REPORTED_HEIGHT = 100000;
6
+ /** Most theme tokens accepted in one message. */
7
+ export declare const MAX_THEME_TOKENS = 512;
8
+ /** Longest notification text accepted, in characters. */
9
+ export declare const MAX_NOTIFY_LENGTH = 500;
10
+ /**
11
+ * Validates a message a plugin frame sent on the port.
12
+ *
13
+ * The host must call this on every message: the frame is untrusted, and
14
+ * `MessagePort` delivers whatever structured-clonable value it was given.
15
+ *
16
+ * @param data - The `event.data` of a port message.
17
+ * @returns The typed message, or `null` when it is malformed or of a type this
18
+ * SDK does not know. Callers ignore `null`; an unknown type is not an error,
19
+ * because a newer plugin may send messages an older host has not heard of.
20
+ */
21
+ export declare function parsePluginMessage(data: unknown): PluginMessage | null;
22
+ /**
23
+ * Validates a message the host sent on the port.
24
+ *
25
+ * A plugin frame treats the host as trusted, but a wrong shape would otherwise
26
+ * surface as an obscure error deep in a component, so the client checks too.
27
+ *
28
+ * @param data - The `event.data` of a port message.
29
+ * @returns The typed message, or `null` when malformed or of an unknown type.
30
+ */
31
+ export declare function parseHostMessage(data: unknown): HostMessage | null;
32
+ /**
33
+ * Validates the frame's opening `wm.hello` window message.
34
+ *
35
+ * @param data - The `event.data` of a window message from the frame.
36
+ * @returns The hello, or `null` when it is not one.
37
+ */
38
+ export declare function parseFrameHello(data: unknown): FrameHello | null;
39
+ /**
40
+ * Validates the host's reply to a hello: a connect (sent with a transferred
41
+ * port) or a refusal.
42
+ *
43
+ * @param data - The `event.data` of a window message from the host.
44
+ * @returns The connect or refuse message, or `null` when it is neither.
45
+ */
46
+ export declare function parseHostReply(data: unknown): HostConnect | HostRefuse | null;
47
+ //# sourceMappingURL=validate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/isolated/validate.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,UAAU,EACV,WAAW,EAEX,WAAW,EACX,UAAU,EAKV,aAAa,EACd,MAAM,eAAe,CAAA;AAEtB,oDAAoD;AACpD,eAAO,MAAM,eAAe,OAAO,CAAA;AACnC,mEAAmE;AACnE,eAAO,MAAM,mBAAmB,SAAU,CAAA;AAC1C,iDAAiD;AACjD,eAAO,MAAM,gBAAgB,MAAM,CAAA;AACnC,yDAAyD;AACzD,eAAO,MAAM,iBAAiB,MAAM,CAAA;AA8EpC;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,OAAO,GAAG,aAAa,GAAG,IAAI,CAuCtE;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,OAAO,GAAG,WAAW,GAAG,IAAI,CA0DlE;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,OAAO,GAAG,UAAU,GAAG,IAAI,CAKhE;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,OAAO,GAAG,WAAW,GAAG,UAAU,GAAG,IAAI,CAS7E"}
@@ -0,0 +1,260 @@
1
+ import { WIDGET_SIZES } from '../manifest/WIDGET_SIZES.js';
2
+ import { RANGE_KEYS } from '../range.js';
3
+ /** Longest request path accepted, in characters. */
4
+ export const MAX_PATH_LENGTH = 2048;
5
+ /** Largest content height accepted from a frame, in CSS pixels. */
6
+ export const MAX_REPORTED_HEIGHT = 100_000;
7
+ /** Most theme tokens accepted in one message. */
8
+ export const MAX_THEME_TOKENS = 512;
9
+ /** Longest notification text accepted, in characters. */
10
+ export const MAX_NOTIFY_LENGTH = 500;
11
+ const isObj = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
12
+ const isId = (v) => typeof v === 'number' && Number.isSafeInteger(v) && v >= 0;
13
+ const isStr = (v) => typeof v === 'string';
14
+ const isSize = (v) => WIDGET_SIZES.includes(v);
15
+ /** A path the shell or API can address: starts with `/`, bounded, no control characters, not protocol-relative. */
16
+ function isPath(v) {
17
+ return (isStr(v) && v.length <= MAX_PATH_LENGTH && v.startsWith('/') && !v.startsWith('//') &&
18
+ // eslint-disable-next-line no-control-regex
19
+ !/[\u0000-\u001f\u007f\\]/.test(v));
20
+ }
21
+ function parseRange(v) {
22
+ if (!isObj(v))
23
+ return null;
24
+ const { key, label, months, from, to } = v;
25
+ if (!RANGE_KEYS.includes(key) || !isStr(label))
26
+ return null;
27
+ if (typeof months !== 'number' || !Number.isInteger(months) || months < 1 || months > 1200)
28
+ return null;
29
+ if (!isStr(from) || !isStr(to) || !/^\d{4}-\d{2}-\d{2}$/.test(from) || !/^\d{4}-\d{2}-\d{2}$/.test(to))
30
+ return null;
31
+ return { key: key, label, months, from, to };
32
+ }
33
+ function parseTheme(v) {
34
+ if (!isObj(v) || (v['scheme'] !== 'light' && v['scheme'] !== 'dark') || !isObj(v['tokens']))
35
+ return null;
36
+ const entries = Object.entries(v['tokens']);
37
+ if (entries.length > MAX_THEME_TOKENS)
38
+ return null;
39
+ const tokens = Object.create(null);
40
+ for (const [name, value] of entries) {
41
+ if (!/^--[A-Za-z0-9_-]{1,100}$/.test(name) || !isStr(value) || value.length > 512)
42
+ return null;
43
+ tokens[name] = value;
44
+ }
45
+ return { scheme: v['scheme'], tokens };
46
+ }
47
+ function parseLocale(v) {
48
+ if (!isObj(v) || !isStr(v['locale']) || !isStr(v['timezone']))
49
+ return null;
50
+ // A bad tag or zone would make every later Intl call throw, so refuse it here.
51
+ try {
52
+ new Intl.DateTimeFormat(v['locale'], { timeZone: v['timezone'] });
53
+ }
54
+ catch {
55
+ return null;
56
+ }
57
+ return { locale: v['locale'], timezone: v['timezone'] };
58
+ }
59
+ function parseSession(v) {
60
+ if (!isObj(v) || !isStr(v['userId']) || !isStr(v['email']) || !isStr(v['timezone']))
61
+ return null;
62
+ return { userId: v['userId'], email: v['email'], timezone: v['timezone'] };
63
+ }
64
+ function parseError(v) {
65
+ if (!isObj(v) || !isStr(v['code']) || !isStr(v['message']))
66
+ return null;
67
+ const status = v['status'];
68
+ if (status !== undefined && (typeof status !== 'number' || !Number.isInteger(status)))
69
+ return null;
70
+ let issues;
71
+ if (v['issues'] !== undefined) {
72
+ if (!Array.isArray(v['issues']))
73
+ return null;
74
+ issues = [];
75
+ for (const raw of v['issues']) {
76
+ if (!isObj(raw) || !Array.isArray(raw['path']) || !isStr(raw['message']))
77
+ return null;
78
+ const path = raw['path'];
79
+ if (!path.every((p) => isStr(p) || (typeof p === 'number' && Number.isInteger(p))))
80
+ return null;
81
+ issues.push({ path: path, message: raw['message'] });
82
+ }
83
+ }
84
+ return {
85
+ code: v['code'],
86
+ message: v['message'],
87
+ ...(status !== undefined ? { status: status } : {}),
88
+ ...(issues !== undefined ? { issues } : {}),
89
+ };
90
+ }
91
+ /**
92
+ * Validates a message a plugin frame sent on the port.
93
+ *
94
+ * The host must call this on every message: the frame is untrusted, and
95
+ * `MessagePort` delivers whatever structured-clonable value it was given.
96
+ *
97
+ * @param data - The `event.data` of a port message.
98
+ * @returns The typed message, or `null` when it is malformed or of a type this
99
+ * SDK does not know. Callers ignore `null`; an unknown type is not an error,
100
+ * because a newer plugin may send messages an older host has not heard of.
101
+ */
102
+ export function parsePluginMessage(data) {
103
+ if (!isObj(data))
104
+ return null;
105
+ switch (data['type']) {
106
+ case 'ready':
107
+ return isId(data['protocol']) ? { type: 'ready', protocol: data['protocol'] } : null;
108
+ case 'request': {
109
+ const { id, method, path, body, cache } = data;
110
+ if (!isId(id) || !isPath(path))
111
+ return null;
112
+ if (method !== 'GET' && method !== 'POST' && method !== 'PUT' && method !== 'DELETE')
113
+ return null;
114
+ if (cache !== undefined && cache !== 'default' && cache !== 'no-store' && cache !== 'reload')
115
+ return null;
116
+ if ((method === 'GET' || method === 'DELETE') && body !== undefined)
117
+ return null;
118
+ return {
119
+ type: 'request', id, method, path,
120
+ ...(body !== undefined ? { body } : {}),
121
+ ...(cache !== undefined ? { cache } : {}),
122
+ };
123
+ }
124
+ case 'cancel':
125
+ return isId(data['id']) ? { type: 'cancel', id: data['id'] } : null;
126
+ case 'navigate':
127
+ return isPath(data['path']) ? { type: 'navigate', path: data['path'] } : null;
128
+ case 'resize': {
129
+ const h = data['height'];
130
+ return typeof h === 'number' && Number.isFinite(h) && h >= 0 && h <= MAX_REPORTED_HEIGHT
131
+ ? { type: 'resize', height: h } : null;
132
+ }
133
+ case 'focus-out': {
134
+ const d = data['direction'];
135
+ return d === 'next' || d === 'previous' ? { type: 'focus-out', direction: d } : null;
136
+ }
137
+ case 'notify': {
138
+ const { id, level, message } = data;
139
+ if (!isId(id) || !isStr(message) || message.length > MAX_NOTIFY_LENGTH)
140
+ return null;
141
+ if (level !== 'info' && level !== 'success' && level !== 'warning' && level !== 'error')
142
+ return null;
143
+ return { type: 'notify', id, level, message };
144
+ }
145
+ default:
146
+ return null;
147
+ }
148
+ }
149
+ /**
150
+ * Validates a message the host sent on the port.
151
+ *
152
+ * A plugin frame treats the host as trusted, but a wrong shape would otherwise
153
+ * surface as an obscure error deep in a component, so the client checks too.
154
+ *
155
+ * @param data - The `event.data` of a port message.
156
+ * @returns The typed message, or `null` when malformed or of an unknown type.
157
+ */
158
+ export function parseHostMessage(data) {
159
+ if (!isObj(data))
160
+ return null;
161
+ switch (data['type']) {
162
+ case 'init': {
163
+ const { protocol, pluginId, kind, size, range, path } = data;
164
+ const session = parseSession(data['session']);
165
+ const locale = parseLocale(data['locale']);
166
+ const theme = parseTheme(data['theme']);
167
+ if (!isId(protocol) || !isStr(pluginId) || (kind !== 'widget' && kind !== 'page'))
168
+ return null;
169
+ if (session === null || locale === null || theme === null)
170
+ return null;
171
+ if (size !== undefined && !isSize(size))
172
+ return null;
173
+ const parsedRange = range === undefined ? undefined : parseRange(range);
174
+ if (parsedRange === null)
175
+ return null;
176
+ if (path !== undefined && !isPath(path))
177
+ return null;
178
+ return {
179
+ type: 'init', protocol, pluginId, kind, session, locale, theme,
180
+ ...(size !== undefined ? { size } : {}),
181
+ ...(parsedRange !== undefined ? { range: parsedRange } : {}),
182
+ ...(path !== undefined ? { path } : {}),
183
+ };
184
+ }
185
+ case 'response': {
186
+ if (!isId(data['id']))
187
+ return null;
188
+ if (data['ok'] === true)
189
+ return { type: 'response', id: data['id'], ok: true, value: data['value'] };
190
+ if (data['ok'] === false) {
191
+ const error = parseError(data['error']);
192
+ return error === null ? null : { type: 'response', id: data['id'], ok: false, error };
193
+ }
194
+ return null;
195
+ }
196
+ case 'theme': {
197
+ const theme = parseTheme(data['theme']);
198
+ return theme === null ? null : { type: 'theme', theme };
199
+ }
200
+ case 'locale': {
201
+ const locale = parseLocale(data['locale']);
202
+ return locale === null ? null : { type: 'locale', locale };
203
+ }
204
+ case 'props': {
205
+ const { size, range } = data;
206
+ if (size !== undefined && !isSize(size))
207
+ return null;
208
+ const parsedRange = range === undefined ? undefined : parseRange(range);
209
+ if (parsedRange === null)
210
+ return null;
211
+ return {
212
+ type: 'props',
213
+ ...(size !== undefined ? { size } : {}),
214
+ ...(parsedRange !== undefined ? { range: parsedRange } : {}),
215
+ };
216
+ }
217
+ case 'route':
218
+ return isPath(data['path']) ? { type: 'route', path: data['path'] } : null;
219
+ case 'focus-in': {
220
+ const d = data['direction'];
221
+ return d === 'first' || d === 'last' ? { type: 'focus-in', direction: d } : null;
222
+ }
223
+ default:
224
+ return null;
225
+ }
226
+ }
227
+ /**
228
+ * Validates the frame's opening `wm.hello` window message.
229
+ *
230
+ * @param data - The `event.data` of a window message from the frame.
231
+ * @returns The hello, or `null` when it is not one.
232
+ */
233
+ export function parseFrameHello(data) {
234
+ if (!isObj(data) || data['type'] !== 'wm.hello' || !Array.isArray(data['protocols']))
235
+ return null;
236
+ const protocols = data['protocols'];
237
+ if (protocols.length === 0 || protocols.length > 16 || !protocols.every(isId))
238
+ return null;
239
+ return { type: 'wm.hello', protocols: protocols };
240
+ }
241
+ /**
242
+ * Validates the host's reply to a hello: a connect (sent with a transferred
243
+ * port) or a refusal.
244
+ *
245
+ * @param data - The `event.data` of a window message from the host.
246
+ * @returns The connect or refuse message, or `null` when it is neither.
247
+ */
248
+ export function parseHostReply(data) {
249
+ if (!isObj(data))
250
+ return null;
251
+ if (data['type'] === 'wm.connect')
252
+ return isId(data['protocol']) ? { type: 'wm.connect', protocol: data['protocol'] } : null;
253
+ if (data['type'] === 'wm.refuse') {
254
+ const s = data['supported'];
255
+ return Array.isArray(s) && s.every(isId)
256
+ ? { type: 'wm.refuse', supported: s } : null;
257
+ }
258
+ return null;
259
+ }
260
+ //# sourceMappingURL=validate.js.map