@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,118 @@
1
+ import type { PluginContext, PluginSession } from '../runtime.js';
2
+ import type { DashboardRange } from '../range.js';
3
+ import type { WidgetSize } from '../manifest/WidgetSize.js';
4
+ import type { ThemeTarget } from './theme.js';
5
+ import type { FocusDirection, FocusInMessage, FrameKind, HostLocale, HostTheme, LocaleMessage, NotifyMessage, PropsMessage, RouteMessage, ThemeMessage } from './protocol.js';
6
+ /** What the host currently says about this frame. A new object on every change, so it suits `useSyncExternalStore`. */
7
+ export interface IsolatedState {
8
+ readonly pluginId: string;
9
+ readonly kind: FrameKind;
10
+ readonly session: PluginSession;
11
+ readonly locale: HostLocale;
12
+ readonly theme: HostTheme;
13
+ /** Widgets only. */
14
+ readonly size?: WidgetSize;
15
+ /** Widgets only, and only when the dashboard has a range. */
16
+ readonly range?: DashboardRange;
17
+ /** Pages only: the current path under the page's route. */
18
+ readonly path?: string;
19
+ }
20
+ /** A change the host pushed after `init`. `state` already reflects it by the time listeners run. */
21
+ export type HostChange = ThemeMessage | LocaleMessage | PropsMessage | RouteMessage | FocusInMessage;
22
+ /** The live link between a plugin frame and the host. */
23
+ export interface HostConnection {
24
+ /** The context to hand a plugin component: the same shape the in-realm host provides. */
25
+ readonly ctx: PluginContext;
26
+ /** The latest state. */
27
+ getState(): IsolatedState;
28
+ /**
29
+ * Listens for changes the host pushes (theme, locale, props, route, focus-in).
30
+ *
31
+ * @returns A function that removes the listener.
32
+ */
33
+ subscribe(listener: (change: HostChange) => void): () => void;
34
+ /** Reports the content height in CSS pixels. Rounded up; repeats of the same height are not sent. */
35
+ reportSize(height: number): void;
36
+ /**
37
+ * Reports the height of `element` now and whenever it changes.
38
+ *
39
+ * Also re-reads the height every {@link SIZE_POLL_MS} ms. Chromium does not run a cross-origin frame's
40
+ * rendering updates while it is off screen, so a `ResizeObserver` alone never fires there and the frame
41
+ * would keep the host's minimum height until scrolled into view. Repeats of a height are not sent, so
42
+ * the poll costs one layout read per tick and no messages.
43
+ *
44
+ * @param element - The element whose height is the frame's content height, usually the app root.
45
+ * @param observer - A `ResizeObserver` constructor; defaults to the global one.
46
+ * @returns A function that stops observing.
47
+ */
48
+ observeSize(element: ObservedElement, observer?: ResizeObserverCtor): () => void;
49
+ /** Tells the host that focus left the frame, past its last (`next`) or before its first (`previous`) focusable element. */
50
+ focusOut(direction: FocusDirection): void;
51
+ /**
52
+ * Sends a notification request. No host implements `notify` yet, so this
53
+ * rejects with code `not_supported` today.
54
+ */
55
+ notify(level: NotifyMessage['level'], message: string): Promise<void>;
56
+ /** Closes the port and rejects every call still waiting with code `disconnected`. */
57
+ dispose(): void;
58
+ }
59
+ /** How often `observeSize` re-reads the height, in milliseconds. */
60
+ export declare const SIZE_POLL_MS = 250;
61
+ /** The part of an element `observeSize` reads. */
62
+ export interface ObservedElement {
63
+ getBoundingClientRect(): {
64
+ readonly height: number;
65
+ };
66
+ }
67
+ /** A `ResizeObserver` constructor, as far as `observeSize` uses it. */
68
+ export type ResizeObserverCtor = new (callback: () => void) => {
69
+ observe(target: ObservedElement): void;
70
+ disconnect(): void;
71
+ };
72
+ /** Options for {@link connectOverPort} and {@link connectToHost}. */
73
+ export interface ConnectOptions {
74
+ /** Where to write the theme. `null` turns automatic theming off. Defaults to `document.documentElement` when there is a `document`. */
75
+ readonly themeRoot?: ThemeTarget | null;
76
+ /** How long to wait for the host, in milliseconds, before rejecting. Defaults to 10 000. */
77
+ readonly timeoutMs?: number;
78
+ }
79
+ /** The slice of `window` the handshake uses. Narrow so a test can supply a stand-in. */
80
+ export interface HandshakeWindow {
81
+ readonly parent: {
82
+ postMessage(message: unknown, targetOrigin: string): void;
83
+ };
84
+ addEventListener(type: 'message', listener: (event: HandshakeEvent) => void): void;
85
+ removeEventListener(type: 'message', listener: (event: HandshakeEvent) => void): void;
86
+ }
87
+ /** The slice of a window `MessageEvent` the handshake reads. */
88
+ export interface HandshakeEvent {
89
+ readonly source: unknown;
90
+ readonly data: unknown;
91
+ readonly ports: readonly MessagePort[];
92
+ }
93
+ /**
94
+ * Connects a plugin frame to its host. Call it once, at the start of the frame.
95
+ *
96
+ * The frame says hello to `window.parent`; the host replies with the protocol
97
+ * version to use and a `MessagePort`; everything after that travels on the
98
+ * port. The reply is accepted only from `window.parent` and only with a port,
99
+ * so another window cannot answer in the host's place.
100
+ *
101
+ * @param options - Theme and timeout options.
102
+ * @param win - The window to use. Defaults to the global `window`.
103
+ * @returns The connection, once the host has sent `init`.
104
+ * @throws {PluginApiError} With code `disconnected` on timeout, or `invalid_request` when the host speaks no protocol version this SDK does.
105
+ */
106
+ export declare function connectToHost(options?: ConnectOptions, win?: HandshakeWindow): Promise<HostConnection>;
107
+ /**
108
+ * The second half of {@link connectToHost}: says `ready` on a port the host
109
+ * gave, waits for `init`, and builds the connection. Public so a test harness
110
+ * can connect over a `MessageChannel` without a window.
111
+ *
112
+ * @param port - The port from the host.
113
+ * @param protocol - The protocol version the host chose.
114
+ * @param options - Theme and timeout options.
115
+ * @returns The connection, once the host has sent `init`.
116
+ */
117
+ export declare function connectOverPort(port: MessagePort, protocol: number, options?: ConnectOptions): Promise<HostConnection>;
118
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/isolated/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAa,aAAa,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC5E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AAI3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAE7C,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,SAAS,EACT,UAAU,EACV,SAAS,EAET,aAAa,EACb,aAAa,EAIb,YAAY,EACZ,YAAY,EACZ,YAAY,EACb,MAAM,eAAe,CAAA;AAGtB,uHAAuH;AACvH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;IACxB,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAA;IAC/B,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAA;IAC3B,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAA;IACzB,oBAAoB;IACpB,QAAQ,CAAC,IAAI,CAAC,EAAE,UAAU,CAAA;IAC1B,6DAA6D;IAC7D,QAAQ,CAAC,KAAK,CAAC,EAAE,cAAc,CAAA;IAC/B,2DAA2D;IAC3D,QAAQ,CAAC,IAAI,CAAC,E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CAAC,SAAS,CAAC,EAAE,WAAW,GAAG,IAAI,CAAA;IACvC,4FAA4F;IAC5F,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAC5B;AAED,wFAAwF;AACxF,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,MAAM,EAAE;QAAE,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAA;IAC9E,gBAAgB,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,GAAG,IAAI,CAAA;IAClF,mBAAmB,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,GAAG,IAAI,CAAA;CACtF;AACD,gEAAgE;AAChE,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAA;IACxB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;IACtB,QAAQ,CAAC,KAAK,EAAE,SAAS,WAAW,EAAE,CAAA;CACvC;AASD;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,OAAO,GAAE,cAAmB,EAAE,GAAG,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC,CAwC1G;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB,GAChE,OAAO,CAAC,cAAc,CAAC,CAyBzB"}
@@ -0,0 +1,275 @@
1
+ import { formatDateIn, formatMoneyIn } from './format.js';
2
+ import { PluginApiError } from './PluginApiError.js';
3
+ import { applyHostTheme } from './theme.js';
4
+ import { ISOLATED_PROTOCOL_VERSION } from './protocol.js';
5
+ import { MAX_PATH_LENGTH, parseHostMessage, parseHostReply } from './validate.js';
6
+ /** How often `observeSize` re-reads the height, in milliseconds. */
7
+ export const SIZE_POLL_MS = 250;
8
+ const DEFAULT_TIMEOUT_MS = 10_000;
9
+ const SUPPORTED_PROTOCOLS = [ISOLATED_PROTOCOL_VERSION];
10
+ function timeoutError(what) {
11
+ return new PluginApiError({ code: 'disconnected', message: `The host did not ${what} in time.` });
12
+ }
13
+ /**
14
+ * Connects a plugin frame to its host. Call it once, at the start of the frame.
15
+ *
16
+ * The frame says hello to `window.parent`; the host replies with the protocol
17
+ * version to use and a `MessagePort`; everything after that travels on the
18
+ * port. The reply is accepted only from `window.parent` and only with a port,
19
+ * so another window cannot answer in the host's place.
20
+ *
21
+ * @param options - Theme and timeout options.
22
+ * @param win - The window to use. Defaults to the global `window`.
23
+ * @returns The connection, once the host has sent `init`.
24
+ * @throws {PluginApiError} With code `disconnected` on timeout, or `invalid_request` when the host speaks no protocol version this SDK does.
25
+ */
26
+ export function connectToHost(options = {}, win) {
27
+ const w = win ?? globalThis.window;
28
+ if (w === undefined)
29
+ return Promise.reject(new TypeError('connectToHost must run inside a browser frame'));
30
+ const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
31
+ return new Promise((resolve, reject) => {
32
+ const finish = () => {
33
+ clearTimeout(timer);
34
+ w.removeEventListener('message', onMessage);
35
+ };
36
+ const timer = setTimeout(() => {
37
+ finish();
38
+ reject(timeoutError('answer the handshake'));
39
+ }, timeoutMs);
40
+ function onMessage(event) {
41
+ if (event.source !== w.parent)
42
+ return;
43
+ const reply = parseHostReply(event.data);
44
+ if (reply === null)
45
+ return;
46
+ finish();
47
+ if (reply.type === 'wm.refuse') {
48
+ reject(new PluginApiError({
49
+ code: 'invalid_request',
50
+ message: `The host speaks protocol ${reply.supported.join(', ')}; this plugin speaks ${SUPPORTED_PROTOCOLS.join(', ')}.`,
51
+ }));
52
+ return;
53
+ }
54
+ const port = event.ports[0];
55
+ if (port === undefined || !SUPPORTED_PROTOCOLS.includes(reply.protocol)) {
56
+ reject(new PluginApiError({ code: 'invalid_request', message: 'The host sent an unusable connection.' }));
57
+ return;
58
+ }
59
+ connectOverPort(port, reply.protocol, options).then(resolve, reject);
60
+ }
61
+ w.addEventListener('message', onMessage);
62
+ // The target origin is '*' because a sandboxed frame cannot know its parent's origin.
63
+ // The hello holds nothing secret; the host's answer is the part that is authenticated.
64
+ w.parent.postMessage({ type: 'wm.hello', protocols: SUPPORTED_PROTOCOLS }, '*');
65
+ });
66
+ }
67
+ /**
68
+ * The second half of {@link connectToHost}: says `ready` on a port the host
69
+ * gave, waits for `init`, and builds the connection. Public so a test harness
70
+ * can connect over a `MessageChannel` without a window.
71
+ *
72
+ * @param port - The port from the host.
73
+ * @param protocol - The protocol version the host chose.
74
+ * @param options - Theme and timeout options.
75
+ * @returns The connection, once the host has sent `init`.
76
+ */
77
+ export function connectOverPort(port, protocol, options = {}) {
78
+ const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
79
+ return new Promise((resolve, reject) => {
80
+ const timer = setTimeout(() => {
81
+ port.close();
82
+ reject(timeoutError('send init'));
83
+ }, timeoutMs);
84
+ const onFirst = (event) => {
85
+ const msg = parseHostMessage(event.data);
86
+ if (msg === null || msg.type !== 'init')
87
+ return;
88
+ clearTimeout(timer);
89
+ port.removeEventListener('message', onFirst);
90
+ if (msg.protocol !== protocol) {
91
+ port.close();
92
+ reject(new PluginApiError({ code: 'invalid_request', message: 'The host changed protocol version mid-handshake.' }));
93
+ return;
94
+ }
95
+ resolve(buildConnection(port, msg, options));
96
+ };
97
+ port.addEventListener('message', onFirst);
98
+ port.start();
99
+ port.postMessage({ type: 'ready', protocol });
100
+ });
101
+ }
102
+ function buildConnection(port, init, options) {
103
+ let state = {
104
+ pluginId: init.pluginId,
105
+ kind: init.kind,
106
+ session: { ...init.session },
107
+ locale: init.locale,
108
+ theme: init.theme,
109
+ ...(init.size !== undefined ? { size: init.size } : {}),
110
+ ...(init.range !== undefined ? { range: init.range } : {}),
111
+ ...(init.path !== undefined ? { path: init.path } : {}),
112
+ };
113
+ const listeners = new Set();
114
+ const pending = new Map();
115
+ let nextId = 1;
116
+ let lastHeight = -1;
117
+ let closed = false;
118
+ const themeRoot = options.themeRoot === undefined
119
+ ? (typeof document === 'undefined' ? null : document.documentElement)
120
+ : options.themeRoot;
121
+ const paint = (theme) => { if (themeRoot !== null)
122
+ applyHostTheme(theme, themeRoot); };
123
+ paint(state.theme);
124
+ const post = (message) => { if (!closed)
125
+ port.postMessage(message); };
126
+ const call = (message, signal) => {
127
+ if (closed)
128
+ return Promise.reject(new PluginApiError({ code: 'disconnected', message: 'The connection to the host is closed.' }));
129
+ if (signal?.aborted === true)
130
+ return Promise.reject(new PluginApiError({ code: 'aborted', message: 'The request was aborted.' }));
131
+ const id = nextId++;
132
+ return new Promise((resolve, reject) => {
133
+ const onAbort = () => {
134
+ pending.delete(id);
135
+ post({ type: 'cancel', id });
136
+ reject(new PluginApiError({ code: 'aborted', message: 'The request was aborted.' }));
137
+ };
138
+ signal?.addEventListener('abort', onAbort, { once: true });
139
+ pending.set(id, {
140
+ resolve: resolve,
141
+ reject,
142
+ cleanup: () => signal?.removeEventListener('abort', onAbort),
143
+ });
144
+ post(message(id));
145
+ });
146
+ };
147
+ const request = (method, path, body, requestInit) => {
148
+ const bad = (message) => Promise.reject(new PluginApiError({ code: 'invalid_request', message }));
149
+ if (typeof path !== 'string' || !path.startsWith('/') || path.startsWith('//') || path.length > MAX_PATH_LENGTH) {
150
+ return bad(`Request path must start with a single '/' and be at most ${MAX_PATH_LENGTH} characters.`);
151
+ }
152
+ if (path.startsWith('/api/')) {
153
+ return bad(`Plugin '${state.pluginId}' requested '${path}'. Paths are relative to the API root — drop the '/api/v1' prefix.`);
154
+ }
155
+ // Only `signal` and `cache` mean anything across the channel. Anything else would be
156
+ // silently dropped, which hides a contract difference, so refuse it.
157
+ const { signal, cache, ...rest } = requestInit ?? {};
158
+ const unsupported = Object.entries(rest).filter(([, v]) => v !== undefined).map(([k]) => k);
159
+ if (unsupported.length > 0) {
160
+ return bad(`RequestInit option(s) not supported in an isolated plugin: ${unsupported.join(', ')}. Only 'signal' and 'cache' are.`);
161
+ }
162
+ if (cache !== undefined && cache !== 'default' && cache !== 'no-store' && cache !== 'reload') {
163
+ return bad(`RequestInit cache '${cache}' is not supported in an isolated plugin.`);
164
+ }
165
+ let cloned;
166
+ try {
167
+ // Same normalisation as the in-realm client, which sends JSON.
168
+ cloned = body === undefined ? undefined : JSON.parse(JSON.stringify(body));
169
+ }
170
+ catch {
171
+ return bad('The request body is not JSON-serialisable.');
172
+ }
173
+ return call((id) => ({
174
+ type: 'request', id, method, path,
175
+ ...(cloned !== undefined ? { body: cloned } : {}),
176
+ ...(cache !== undefined ? { cache: cache } : {}),
177
+ }), signal);
178
+ };
179
+ const api = {
180
+ get: (path, init) => request('GET', path, undefined, init),
181
+ post: (path, body, init) => request('POST', path, body, init),
182
+ put: (path, body, init) => request('PUT', path, body, init),
183
+ del: (path, init) => request('DELETE', path, undefined, init),
184
+ };
185
+ const ctx = {
186
+ get session() { return state.session; },
187
+ api,
188
+ navigate: (path) => { post({ type: 'navigate', path }); },
189
+ formatMoney: (value, currency) => formatMoneyIn(state.locale.locale, value, currency),
190
+ formatDate: (value) => formatDateIn(state.locale.locale, value),
191
+ };
192
+ const emit = (change) => { for (const l of [...listeners])
193
+ l(change); };
194
+ port.addEventListener('message', (event) => {
195
+ const msg = parseHostMessage(event.data);
196
+ if (msg === null)
197
+ return; // unknown or malformed: ignored, so a newer host can add messages
198
+ switch (msg.type) {
199
+ case 'response': {
200
+ const entry = pending.get(msg.id);
201
+ if (entry === undefined)
202
+ return; // answered after an abort
203
+ pending.delete(msg.id);
204
+ entry.cleanup();
205
+ if (msg.ok)
206
+ entry.resolve(msg.value);
207
+ else
208
+ entry.reject(new PluginApiError(msg.error));
209
+ return;
210
+ }
211
+ case 'theme':
212
+ state = { ...state, theme: msg.theme };
213
+ paint(msg.theme);
214
+ return emit(msg);
215
+ case 'locale':
216
+ state = { ...state, locale: msg.locale, session: { ...state.session, timezone: msg.locale.timezone } };
217
+ return emit(msg);
218
+ case 'props':
219
+ state = {
220
+ ...state,
221
+ ...(msg.size !== undefined ? { size: msg.size } : {}),
222
+ ...(msg.range !== undefined ? { range: msg.range } : {}),
223
+ };
224
+ return emit(msg);
225
+ case 'route':
226
+ state = { ...state, path: msg.path };
227
+ return emit(msg);
228
+ case 'focus-in':
229
+ return emit(msg);
230
+ case 'init':
231
+ return; // a second init is ignored; the first one defines the frame
232
+ }
233
+ });
234
+ return {
235
+ ctx,
236
+ getState: () => state,
237
+ subscribe(listener) {
238
+ listeners.add(listener);
239
+ return () => { listeners.delete(listener); };
240
+ },
241
+ reportSize(height) {
242
+ if (!Number.isFinite(height) || height < 0)
243
+ return;
244
+ const rounded = Math.ceil(height);
245
+ if (rounded === lastHeight)
246
+ return;
247
+ lastHeight = rounded;
248
+ post({ type: 'resize', height: rounded });
249
+ },
250
+ observeSize(element, observer) {
251
+ const Ctor = observer ?? globalThis.ResizeObserver;
252
+ const report = () => { this.reportSize(element.getBoundingClientRect().height); };
253
+ const ro = Ctor === undefined ? undefined : new Ctor(report);
254
+ ro?.observe(element);
255
+ report();
256
+ const timer = setInterval(report, SIZE_POLL_MS);
257
+ return () => { clearInterval(timer); ro?.disconnect(); };
258
+ },
259
+ focusOut: (direction) => { post({ type: 'focus-out', direction }); },
260
+ notify: (level, message) => call((id) => ({ type: 'notify', id, level, message })).then(() => undefined),
261
+ dispose() {
262
+ if (closed)
263
+ return;
264
+ closed = true;
265
+ port.close();
266
+ for (const [, entry] of pending) {
267
+ entry.cleanup();
268
+ entry.reject(new PluginApiError({ code: 'disconnected', message: 'The connection to the host was closed.' }));
269
+ }
270
+ pending.clear();
271
+ listeners.clear();
272
+ },
273
+ };
274
+ }
275
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/isolated/client.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM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CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,CAAA;YAC5D,EAAE,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;YACpB,MAAM,EAAE,CAAA;YACR,MAAM,KAAK,GAAG,WAAW,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;YAC/C,OAAO,GAAG,EAAE,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,UAAU,EAAE,CAAA,CAAC,CAAC,CAAA;QACzD,CAAC;QACD,QAAQ,EAAE,CAAC,SAAS,EAAE,EAAE,GAAG,IAAI,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,CAAC,CAAA,CAAC,CAAC;QACnE,MAAM,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,CACzB,IAAI,CAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC;QACpF,OAAO;YACL,IAAI,MAAM;gBAAE,OAAM;YAClB,MAAM,GAAG,IAAI,CAAA;YACb,IAAI,CAAC,KAAK,EAAE,CAAA;YACZ,KAAK,MAAM,CAAC,EAAE,KAAK,CAAC,IAAI,OAAO,EAAE,CAAC;gBAChC,KAAK,CAAC,OAAO,EAAE,CAAA;gBACf,KAAK,CAAC,MAAM,CAAC,IAAI,cAAc,CAAC,EAAE,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,wCAAwC,EAAE,CAAC,CAAC,CAAA;YAC/G,CAAC;YACD,OAAO,CAAC,KAAK,EAAE,CAAA;YACf,SAAS,CAAC,KAAK,EAAE,CAAA;QACnB,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Formats a decimal string as a currency amount in `locale`, exactly.
3
+ *
4
+ * The same algorithm as the host's own `ctx.formatMoney`: the whole part is
5
+ * grouped by `Intl` from a `bigint` and the fraction is taken from the string
6
+ * and rounded half away from zero, so no value passes through a `number`. A
7
+ * value that is not a plain decimal falls back to `Number`.
8
+ *
9
+ * @param locale - A BCP 47 tag, or `undefined` for the runtime's default.
10
+ * @param value - A decimal amount such as `"-12.50"`.
11
+ * @param currency - ISO 4217 code. Defaults to `"USD"`.
12
+ * @returns The formatted amount.
13
+ * @throws {RangeError} When `currency` is not a well-formed currency code.
14
+ */
15
+ export declare function formatMoneyIn(locale: string | undefined, value: string, currency?: string): string;
16
+ /**
17
+ * Formats a date in `locale`. A calendar date (`YYYY-MM-DD`) is shown as that
18
+ * day whatever the time zone, exactly as the host's `ctx.formatDate` does.
19
+ *
20
+ * @param locale - A BCP 47 tag, or `undefined` for the runtime's default.
21
+ * @param value - `YYYY-MM-DD`, or any string `Date` accepts.
22
+ * @returns The locale's short date.
23
+ */
24
+ export declare function formatDateIn(locale: string | undefined, value: string): string;
25
+ //# sourceMappingURL=format.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/isolated/format.ts"],"names":[],"mappings":"AAeA;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,SAAQ,GAAG,MAAM,CAgBjG;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAI9E"}
@@ -0,0 +1,59 @@
1
+ const DECIMAL = /^([+-])?(\d*)(?:\.(\d*))?$/;
2
+ const CALENDAR_DATE = /^(\d{4})-(\d{2})-(\d{2})$/;
3
+ function roundDecimal(whole, fraction, places) {
4
+ const padded = fraction.padEnd(places + 1, '0');
5
+ const kept = padded.slice(0, places);
6
+ const roundUp = padded.charCodeAt(places) >= 53; // '5'
7
+ const scaled = BigInt(`${whole === '' ? '0' : whole}${kept}`) + (roundUp ? 1n : 0n);
8
+ const digits = scaled.toString().padStart(places + 1, '0');
9
+ const split = digits.length - places;
10
+ return { whole: BigInt(digits.slice(0, split)), fraction: digits.slice(split) };
11
+ }
12
+ /**
13
+ * Formats a decimal string as a currency amount in `locale`, exactly.
14
+ *
15
+ * The same algorithm as the host's own `ctx.formatMoney`: the whole part is
16
+ * grouped by `Intl` from a `bigint` and the fraction is taken from the string
17
+ * and rounded half away from zero, so no value passes through a `number`. A
18
+ * value that is not a plain decimal falls back to `Number`.
19
+ *
20
+ * @param locale - A BCP 47 tag, or `undefined` for the runtime's default.
21
+ * @param value - A decimal amount such as `"-12.50"`.
22
+ * @param currency - ISO 4217 code. Defaults to `"USD"`.
23
+ * @returns The formatted amount.
24
+ * @throws {RangeError} When `currency` is not a well-formed currency code.
25
+ */
26
+ export function formatMoneyIn(locale, value, currency = 'USD') {
27
+ const formatter = new Intl.NumberFormat(locale, { style: 'currency', currency });
28
+ const match = DECIMAL.exec(value.trim());
29
+ if (match === null || ((match[2] ?? '') === '' && (match[3] ?? '') === '')) {
30
+ return formatter.format(Number(value));
31
+ }
32
+ const places = formatter.resolvedOptions().maximumFractionDigits ?? 2;
33
+ const rounded = roundDecimal(match[2] ?? '', match[3] ?? '', places);
34
+ const negative = match[1] === '-' && (rounded.whole !== 0n || /[1-9]/.test(rounded.fraction));
35
+ const stand = negative && rounded.whole === 0n ? -1n : negative ? -rounded.whole : rounded.whole;
36
+ const zero = formatter.formatToParts(0n).find((p) => p.type === 'integer')?.value ?? '0';
37
+ return formatter.formatToParts(stand).map((part) => {
38
+ if (part.type === 'fraction')
39
+ return rounded.fraction;
40
+ if (part.type === 'integer' && rounded.whole === 0n)
41
+ return zero;
42
+ return part.value;
43
+ }).join('');
44
+ }
45
+ /**
46
+ * Formats a date in `locale`. A calendar date (`YYYY-MM-DD`) is shown as that
47
+ * day whatever the time zone, exactly as the host's `ctx.formatDate` does.
48
+ *
49
+ * @param locale - A BCP 47 tag, or `undefined` for the runtime's default.
50
+ * @param value - `YYYY-MM-DD`, or any string `Date` accepts.
51
+ * @returns The locale's short date.
52
+ */
53
+ export function formatDateIn(locale, value) {
54
+ const match = CALENDAR_DATE.exec(value);
55
+ if (match === null)
56
+ return new Date(value).toLocaleDateString(locale);
57
+ return new Date(Number(match[1]), Number(match[2]) - 1, Number(match[3])).toLocaleDateString(locale);
58
+ }
59
+ //# sourceMappingURL=format.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format.js","sourceRoot":"","sources":["../../src/isolated/format.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG,4BAA4B,CAAA;AAC5C,MAAM,aAAa,GAAG,2BAA2B,CAAA;AAEjD,SAAS,YAAY,CACnB,KAAa,EAAE,QAAgB,EAAE,MAAc;IAE/C,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,GAAG,CAAC,CAAA;IAC/C,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,CAAA;IACpC,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,EAAE,CAAA,CAAC,MAAM;IACtD,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;IACnF,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,GAAG,CAAC,CAAA;IAC1D,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,GAAG,MAAM,CAAA;IACpC,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CA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CAAC,OAAO,CAAC,KAAK,CAAA;IAChG,MAAM,IAAI,GAAG,SAAS,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,SAAS,CAAC,EAAE,KAAK,IAAI,GAAG,CAAA;IACxF,OAAO,SAAS,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACjD,IAAI,IAAI,CAAC,IAAI,KAAK,UAAU;YAAE,OAAO,OAAO,CAAC,QAAQ,CAAA;QACrD,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,IAAI,OAAO,CAAC,KAAK,KAAK,EAAE;YAAE,OAAO,IAAI,CAAA;QAChE,OAAO,IAAI,CAAC,KAAK,CAAA;IACnB,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;AACb,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAAC,MAA0B,EAAE,KAAa;IACpE,MAAM,KAAK,GAAG,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACvC,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAA;IACrE,OAAO,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAA;AACtG,CAAC"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * @module
3
+ * The runtime contract for **isolated** UI plugins: plugins that run in a
4
+ * sandboxed frame with no access to the host page, its cookies or its tokens,
5
+ * and talk to the host only through the messages defined here.
6
+ *
7
+ * Why a separate contract: `PluginContext` is an object of functions, and a
8
+ * function cannot cross a frame boundary. This entry point replaces it with a
9
+ * serialisable message protocol over a `MessagePort`, plus a small client
10
+ * ({@link connectToHost}) that rebuilds the same `PluginContext` inside the
11
+ * frame, so a component written against `@wickermoney/plugin-sdk/runtime` can
12
+ * run in either place.
13
+ *
14
+ * What is here:
15
+ * - the protocol: message types, error shape, version ({@link ISOLATED_PROTOCOL_VERSION});
16
+ * - validators the host runs on everything a frame sends ({@link parsePluginMessage});
17
+ * - the in-frame client ({@link connectToHost}, {@link connectOverPort}), {@link PluginApiError}
18
+ * and {@link applyHostTheme}.
19
+ *
20
+ * What is not here: the host side (frame element, broker, headers). That ships
21
+ * with the web app, not the SDK.
22
+ *
23
+ * Decisions recorded by this entry point:
24
+ * - **Additive.** Existing manifests and `/runtime` are unchanged, and
25
+ * `SDK_MAJOR_VERSION` stays `0`. A manifest opts in with `isolated: true`.
26
+ * - **No host-rendered dialogs in protocol 1.** A widget frame is small and
27
+ * clips overlays; a widget that needs a dialog should `navigate` to its page,
28
+ * whose frame is full height and can show dialogs itself. Adding a dialog
29
+ * message later is not a protocol bump (unknown messages are ignored).
30
+ * - **`notify` is reserved.** The message exists and a host answers it with
31
+ * `not_supported` until the permission is built.
32
+ * - **`RequestInit` is narrowed** to `signal` and `cache`. Headers and
33
+ * credentials are the host's to set, never the frame's.
34
+ *
35
+ * Stability: `@experimental`. May change in any pre-1.0 minor release until the
36
+ * isolation work has shipped and settled.
37
+ *
38
+ * @experimental
39
+ */
40
+ export { connectOverPort, connectToHost } from './client.js';
41
+ export type { ConnectOptions, HandshakeEvent, HandshakeWindow, HostChange, HostConnection, IsolatedState, ObservedElement, ResizeObserverCtor, } from './client.js';
42
+ export { PluginApiError } from './PluginApiError.js';
43
+ export { ISOLATED_PROTOCOL_VERSION, PLUGIN_ERROR_CODES } from './protocol.js';
44
+ export type { CancelMessage, FocusDirection, FocusInMessage, FocusOutMessage, FrameHello, FrameKind, HostConnect, HostLocale, HostMessage, HostRefuse, HostSession, HostTheme, InitMessage, LocaleMessage, NavigateMessage, NotifyMessage, PluginApiIssue, PluginErrorCode, PluginErrorPayload, PluginMessage, PluginRequestCache, PluginRequestMethod, PropsMessage, ReadyMessage, RequestMessage, ResizeMessage, ResponseMessage, RouteMessage, ThemeMessage, ThemeScheme, } from './protocol.js';
45
+ export { applyHostTheme } from './theme.js';
46
+ export type { ThemeTarget } from './theme.js';
47
+ export { MAX_NOTIFY_LENGTH, MAX_PATH_LENGTH, MAX_REPORTED_HEIGHT, MAX_THEME_TOKENS, parseFrameHello, parseHostMessage, parseHostReply, parsePluginMessage, } from './validate.js';
48
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/isolated/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC5D,YAAY,EACV,cAAc,EACd,cAAc,EACd,eAAe,EACf,UAAU,EACV,cAAc,EACd,aAAa,EACb,eAAe,EACf,kBAAkB,GACnB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,EAAE,yBAAyB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAC7E,YAAY,EACV,aAAa,EACb,cAAc,EACd,cAAc,EACd,eAAe,EACf,UAAU,EACV,SAAS,EACT,WAAW,EACX,UAAU,EACV,WAAW,EACX,UAAU,EACV,WAAW,EACX,SAAS,EACT,WAAW,EACX,aAAa,EACb,eAAe,EACf,aAAa,EACb,cAAc,EACd,eAAe,EACf,kBAAkB,EAClB,aAAa,EACb,kBAAkB,EAClB,mBAAmB,EACnB,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,aAAa,EACb,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,WAAW,GACZ,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAC3C,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAC7C,OAAO,EACL,iBAAiB,EAAE,eAAe,EAAE,mBAAmB,EAAE,gBAAgB,EACzE,eAAe,EAAE,gBAAgB,EAAE,cAAc,EAAE,kBAAkB,GACtE,MAAM,eAAe,CAAA"}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * @module
3
+ * The runtime contract for **isolated** UI plugins: plugins that run in a
4
+ * sandboxed frame with no access to the host page, its cookies or its tokens,
5
+ * and talk to the host only through the messages defined here.
6
+ *
7
+ * Why a separate contract: `PluginContext` is an object of functions, and a
8
+ * function cannot cross a frame boundary. This entry point replaces it with a
9
+ * serialisable message protocol over a `MessagePort`, plus a small client
10
+ * ({@link connectToHost}) that rebuilds the same `PluginContext` inside the
11
+ * frame, so a component written against `@wickermoney/plugin-sdk/runtime` can
12
+ * run in either place.
13
+ *
14
+ * What is here:
15
+ * - the protocol: message types, error shape, version ({@link ISOLATED_PROTOCOL_VERSION});
16
+ * - validators the host runs on everything a frame sends ({@link parsePluginMessage});
17
+ * - the in-frame client ({@link connectToHost}, {@link connectOverPort}), {@link PluginApiError}
18
+ * and {@link applyHostTheme}.
19
+ *
20
+ * What is not here: the host side (frame element, broker, headers). That ships
21
+ * with the web app, not the SDK.
22
+ *
23
+ * Decisions recorded by this entry point:
24
+ * - **Additive.** Existing manifests and `/runtime` are unchanged, and
25
+ * `SDK_MAJOR_VERSION` stays `0`. A manifest opts in with `isolated: true`.
26
+ * - **No host-rendered dialogs in protocol 1.** A widget frame is small and
27
+ * clips overlays; a widget that needs a dialog should `navigate` to its page,
28
+ * whose frame is full height and can show dialogs itself. Adding a dialog
29
+ * message later is not a protocol bump (unknown messages are ignored).
30
+ * - **`notify` is reserved.** The message exists and a host answers it with
31
+ * `not_supported` until the permission is built.
32
+ * - **`RequestInit` is narrowed** to `signal` and `cache`. Headers and
33
+ * credentials are the host's to set, never the frame's.
34
+ *
35
+ * Stability: `@experimental`. May change in any pre-1.0 minor release until the
36
+ * isolation work has shipped and settled.
37
+ *
38
+ * @experimental
39
+ */
40
+ export { connectOverPort, connectToHost } from './client.js';
41
+ export { PluginApiError } from './PluginApiError.js';
42
+ export { ISOLATED_PROTOCOL_VERSION, PLUGIN_ERROR_CODES } from './protocol.js';
43
+ export { applyHostTheme } from './theme.js';
44
+ export { MAX_NOTIFY_LENGTH, MAX_PATH_LENGTH, MAX_REPORTED_HEIGHT, MAX_THEME_TOKENS, parseFrameHello, parseHostMessage, parseHostReply, parsePluginMessage, } from './validate.js';
45
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/isolated/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAW5D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,EAAE,yBAAyB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAiC7E,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAE3C,OAAO,EACL,iBAAiB,EAAE,eAAe,EAAE,mBAAmB,EAAE,gBAAgB,EACzE,eAAe,EAAE,gBAAgB,EAAE,cAAc,EAAE,kBAAkB,GACtE,MAAM,eAAe,CAAA"}