@replohq/canopy-sdk 2.0.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/_vendor/replo-utils/lib/log.d.ts +11 -0
  2. package/_vendor/replo-utils/lib/misc.mjs +1 -1
  3. package/_vendor/replo-utils/react/use-iframe-rpc-channel.d.ts +14 -0
  4. package/_vendor/replo-utils/react/use-iframe-rpc-channel.mjs +14 -0
  5. package/_vendor/schemas/errors.d.ts +36 -15
  6. package/_vendor/schemas/generated/selectMode.d.ts +0 -85
  7. package/_vendor/schemas/generated/selectModeIframeRpc.d.ts +100 -0
  8. package/_vendor/schemas/generated/selectModeIframeRpc.mjs +1 -0
  9. package/_vendor/schemas/iframeRpcChannel.d.ts +82 -0
  10. package/_vendor/schemas/iframeRpcChannel.mjs +361 -0
  11. package/_vendor/schemas/money.mjs +2 -113
  12. package/_vendor/schemas/selectMode.d.ts +0 -496
  13. package/_vendor/schemas/selectMode.mjs +3 -312
  14. package/_vendor/schemas/selectModeIframeRpc.d.ts +900 -0
  15. package/_vendor/schemas/selectModeIframeRpc.mjs +225 -0
  16. package/cart/buy-now-action.js +4 -4
  17. package/cart/buy-now-action.js.map +2 -2
  18. package/chunk-7GWIUERW.mjs +197 -0
  19. package/{chunk-UWHM3FKU.mjs → chunk-H36NDYLG.mjs} +3 -3
  20. package/chunk-OFU2QEDR.mjs +163 -0
  21. package/editor/annotations/annotationController.js +1 -1
  22. package/editor/annotations/annotationController.js.map +2 -2
  23. package/editor/select-mode/EditorSelection.js +3 -15
  24. package/editor/select-mode/EditorSelection.js.map +2 -2
  25. package/editor/select-mode/fast-refresh-relay.js +2 -4
  26. package/editor/select-mode/fast-refresh-relay.js.map +2 -2
  27. package/editor/select-mode/hooks/useEditModeStateMachine.d.ts +0 -4
  28. package/editor/select-mode/hooks/useEditModeStateMachine.js +76 -67
  29. package/editor/select-mode/hooks/useEditModeStateMachine.js.map +2 -2
  30. package/editor/select-mode/hooks/useParentMessaging.d.ts +6 -10
  31. package/editor/select-mode/hooks/useParentMessaging.js +43 -68
  32. package/editor/select-mode/hooks/useParentMessaging.js.map +2 -2
  33. package/editor/select-mode/hooks/useSelectModeController.js +5 -8
  34. package/editor/select-mode/hooks/useSelectModeController.js.map +2 -2
  35. package/editor/select-mode/hooks/useSelectionHover.js +4 -7
  36. package/editor/select-mode/hooks/useSelectionHover.js.map +2 -2
  37. package/editor/select-mode/hooks/useSelectionInteractions.js +14 -31
  38. package/editor/select-mode/hooks/useSelectionInteractions.js.map +2 -2
  39. package/editor/select-mode/hooks/useSelectionScrollSync.js +11 -18
  40. package/editor/select-mode/hooks/useSelectionScrollSync.js.map +2 -2
  41. package/editor/select-mode/iframeRpcChannel.d.ts +356 -0
  42. package/editor/select-mode/iframeRpcChannel.js +92 -0
  43. package/editor/select-mode/iframeRpcChannel.js.map +7 -0
  44. package/lib/canopy-error.js +1 -1
  45. package/lib/canopy-error.js.map +2 -2
  46. package/orders/order-status-schema.d.ts +161 -0
  47. package/orders/order-status-schema.js +83 -0
  48. package/orders/order-status-schema.js.map +7 -0
  49. package/orders/order-status.d.ts +11 -0
  50. package/orders/order-status.js +41 -0
  51. package/orders/order-status.js.map +7 -0
  52. package/package.json +9 -1
@@ -0,0 +1,11 @@
1
+ export type Logger = {
2
+ info: Console["log"];
3
+ debug: Console["debug"];
4
+ error: Console["error"];
5
+ };
6
+ export declare const defaultLogger: Logger;
7
+ /**
8
+ * Silent logger, mostly useful for testing cases where you may not want
9
+ * a service logging out errors that you're expecting.
10
+ */
11
+ export declare const noOpLogger: Logger;
@@ -1,3 +1,3 @@
1
- export { coerceNumberToString, deepCloneAndMergeReplacingArrays, errorMessage, exhaustiveSwitch, formatFileSize, getFromRecordOrNull, hasOwnProperty, invariant, isEmpty, isFunction_default as isFunction, isNotNullish, isNullish, isPrimitive, mergeReplacingArrays, mergeReplacingObjects, noop, preventDefault, sleep, warning } from '../../../chunk-UWHM3FKU.mjs';
1
+ export { coerceNumberToString, deepCloneAndMergeReplacingArrays, errorMessage, exhaustiveSwitch, formatFileSize, getFromRecordOrNull, hasOwnProperty, invariant, isEmpty, isFunction_default as isFunction, isNotNullish, isNullish, isPrimitive, mergeReplacingArrays, mergeReplacingObjects, noop, preventDefault, sleep, warning } from '../../../chunk-H36NDYLG.mjs';
2
2
  export { isNumber_default as isNumber, isString_default as isString } from '../../../chunk-ILGEM42C.mjs';
3
3
  import '../../../chunk-FNTGY7I5.mjs';
@@ -0,0 +1,14 @@
1
+ type SubscribableChannel = {
2
+ subscribe: () => () => void;
3
+ };
4
+ /**
5
+ * Subscribes an iframe RPC channel for the lifetime of the calling component.
6
+ * Returns the same channel so callers can keep a stable handle for `call`.
7
+ *
8
+ * Typed structurally so this hook can live in `replo-utils` without importing
9
+ * the channel implementation from `schemas` (which would close a workspace
10
+ * cycle: schemas → replo-utils).
11
+ */
12
+ export declare function useIframeRpcChannel<ChannelType extends SubscribableChannel>(channel: ChannelType): ChannelType;
13
+ export declare function useIframeRpcChannel<ChannelType extends SubscribableChannel>(channel: ChannelType | null): ChannelType | null;
14
+ export {};
@@ -0,0 +1,14 @@
1
+ import * as React from 'react';
2
+
3
+ // ../replo-utils/react/use-iframe-rpc-channel.ts
4
+ function useIframeRpcChannel(channel) {
5
+ React.useEffect(() => {
6
+ if (!channel) {
7
+ return;
8
+ }
9
+ return channel.subscribe();
10
+ }, [channel]);
11
+ return channel;
12
+ }
13
+
14
+ export { useIframeRpcChannel };
@@ -1,5 +1,5 @@
1
1
  import type { ErrorUserFacingDetails, ErrorUserFacingDetailsWithMessage } from "./generated/errors";
2
- import { z } from "zod";
2
+ import { z, ZodError } from "zod";
3
3
  /**
4
4
  * Config to use for any standard error we throw in Replo
5
5
  */
@@ -417,22 +417,43 @@ export declare class CloudflareAgentCoordinatorRpcError extends ReploError {
417
417
  constructor(error: unknown);
418
418
  }
419
419
  /**
420
- * Errors thrown by the postMessage RPC layer between bedrock miniapp iframes
421
- * and their agent-ui parent (see `packages/schemas/miniappRpc.ts` for the
422
- * protocol). Both sides reject pending request promises with these so
423
- * `instanceof` checks work regardless of which side surfaced the failure.
420
+ * Failures on the shared iframe RPC channel (miniapp ↔ parent, canopy ↔ WB).
421
+ * Live next to other domain errors so callers get ReploError reporting without
422
+ * a `replo-utils → schemas` workspace cycle (schemas already depends on
423
+ * replo-utils; the channel implementation lives in `schemas/iframeRpcChannel`).
424
424
  */
425
- export declare abstract class MiniappRpcError extends ReploError {
425
+ export declare abstract class IframeRpcChannelError extends ReploError {
426
426
  }
427
- /** Pending request exceeded `RPC_TIMEOUT_MS` without a response. */
428
- export declare class MiniappRpcTimeoutError extends MiniappRpcError {
427
+ export declare class IframeRpcChannelTimeoutError extends IframeRpcChannelError {
428
+ constructor({ method, timeoutMs }: {
429
+ method: string;
430
+ timeoutMs: number;
431
+ });
429
432
  }
430
- /**
431
- * Other side posted a `kind: "error"` envelope; `config.message` carries the
432
- * remote-supplied detail.
433
- */
434
- export declare class MiniappRpcRemoteError extends MiniappRpcError {
433
+ export declare class IframeRpcChannelRemoteError extends IframeRpcChannelError {
434
+ constructor({ method, message }: {
435
+ method: string;
436
+ message: string;
437
+ });
438
+ }
439
+ export declare class IframeRpcChannelUnsubscribedError extends IframeRpcChannelError {
440
+ constructor({ method }: {
441
+ method: string;
442
+ });
435
443
  }
436
- /** Parent-side hook unmounted while a request was in flight. */
437
- export declare class MiniappRpcUnmountedError extends MiniappRpcError {
444
+ export declare class IframeRpcChannelUnknownMethodError extends IframeRpcChannelError {
445
+ constructor({ method }: {
446
+ method: string;
447
+ });
448
+ }
449
+ export declare class IframeRpcChannelConfigurationError extends IframeRpcChannelError {
450
+ constructor({ message }: {
451
+ message: string;
452
+ });
453
+ }
454
+ export declare class IframeRpcChannelInvalidInputError extends IframeRpcChannelError {
455
+ constructor({ method, cause }: {
456
+ method: string;
457
+ cause: ZodError;
458
+ });
438
459
  }
@@ -117,88 +117,3 @@ export type SelectModeSelection = {
117
117
  dragRect: SelectModeBoundingRect;
118
118
  selectionRects: SelectModeSelectionRect[];
119
119
  };
120
- export type SelectModeParentMessage = {
121
- type: "replo:select:setDisplayMode";
122
- displayMode: DisplayMode;
123
- } | {
124
- type: "replo:select:setSelectionType";
125
- selectionType: SelectModeSelectionType;
126
- } | {
127
- type: "replo:select:applyOptimisticUpdate";
128
- editId: string;
129
- payload: SelectModeOptimisticUpdatePayload;
130
- targetSelector: string;
131
- targetMode: "primary" | "group";
132
- } | {
133
- type: "replo:select:markCommitted";
134
- editId: string;
135
- sessionId: string;
136
- } | {
137
- type: "replo:select:resolveSessionOverrides";
138
- sessionId: string;
139
- outcome: "persisted" | "failed";
140
- } | {
141
- type: "replo:select:revertOverride";
142
- editId: string;
143
- } | {
144
- type: "replo:select:enterEditMode";
145
- } | {
146
- type: "replo:select:exitEditMode";
147
- } | {
148
- type: "replo:select:formatCommand";
149
- command: SelectModeFormatCommand;
150
- } | {
151
- type: "replo:select:resolveEditRequest";
152
- editId: string;
153
- allowed: boolean;
154
- } | {
155
- type: "replo:select:requestSymbolicate";
156
- requestId: string;
157
- element: SelectedElement;
158
- };
159
- export type SelectModeIframeMessage = {
160
- type: "replo:select:elementSelected";
161
- data: SelectableData;
162
- } | {
163
- type: "replo:select:hoverElement";
164
- rect: SelectModeBoundingRect | null;
165
- } | {
166
- type: "replo:select:iframeReady";
167
- } | {
168
- type: "replo:select:selectedElementRectUpdate";
169
- rect: SelectModeBoundingRect;
170
- clickPosition: SelectModeClickPosition;
171
- } | {
172
- type: "replo:select:selectedAreaRectUpdate";
173
- rect: SelectModeBoundingRect;
174
- } | {
175
- type: "replo:select:dragRectUpdated";
176
- dragRect: SelectModeBoundingRect | null;
177
- selectionRects: SelectModeSelectionRect[];
178
- } | {
179
- type: "replo:select:areaSelected";
180
- rect: SelectModeBoundingRect;
181
- items: SelectableData[];
182
- } | {
183
- type: "replo:select:doubleClicked";
184
- editId: string;
185
- element: SelectedElement;
186
- } | {
187
- type: "replo:select:textCommitted";
188
- editId: string;
189
- html: string;
190
- json: {
191
- [x: string]: unknown;
192
- };
193
- originalInnerHTML: string;
194
- } | {
195
- type: "replo:select:editorStateUpdate";
196
- activeMarks: SelectModeTiptapActiveMarks;
197
- isEditing: boolean;
198
- } | {
199
- type: "replo:select:fastRefreshComplete";
200
- } | {
201
- type: "replo:select:symbolicateResult";
202
- requestId: string;
203
- element: SelectedElement;
204
- };
@@ -0,0 +1,100 @@
1
+ import type { DisplayMode, SelectModeSelectionType, SelectModeOptimisticUpdatePayload, SelectModeFormatCommand, SelectableData, SelectModeBoundingRect, SelectModeClickPosition, SelectModeSelectionRect, SelectModeTiptapActiveMarks } from "./selectMode.ts";
2
+ export type SelectModeParentMessage = {
3
+ method: "setDisplayMode";
4
+ data: {
5
+ displayMode: DisplayMode;
6
+ };
7
+ } | {
8
+ method: "setSelectionType";
9
+ data: {
10
+ selectionType: SelectModeSelectionType;
11
+ };
12
+ } | {
13
+ method: "applyOptimisticUpdate";
14
+ data: {
15
+ editId: string;
16
+ payload: SelectModeOptimisticUpdatePayload;
17
+ targetSelector: string;
18
+ targetMode: "primary" | "group";
19
+ };
20
+ } | {
21
+ method: "markCommitted";
22
+ data: {
23
+ editId: string;
24
+ sessionId: string;
25
+ };
26
+ } | {
27
+ method: "resolveSessionOverrides";
28
+ data: {
29
+ sessionId: string;
30
+ outcome: "persisted" | "failed";
31
+ };
32
+ } | {
33
+ method: "revertOverride";
34
+ data: {
35
+ editId: string;
36
+ };
37
+ } | {
38
+ method: "enterEditMode";
39
+ } | {
40
+ method: "exitEditMode";
41
+ } | {
42
+ method: "formatCommand";
43
+ data: {
44
+ command: SelectModeFormatCommand;
45
+ };
46
+ };
47
+ export type SelectModeIframeMessage = {
48
+ method: "iframeReady";
49
+ } | {
50
+ method: "elementSelected";
51
+ data: {
52
+ data: SelectableData;
53
+ };
54
+ } | {
55
+ method: "hoverElement";
56
+ data: {
57
+ rect: SelectModeBoundingRect | null;
58
+ };
59
+ } | {
60
+ method: "selectedElementRectUpdate";
61
+ data: {
62
+ rect: SelectModeBoundingRect;
63
+ clickPosition: SelectModeClickPosition;
64
+ };
65
+ } | {
66
+ method: "selectedAreaRectUpdate";
67
+ data: {
68
+ rect: SelectModeBoundingRect;
69
+ };
70
+ } | {
71
+ method: "dragRectUpdated";
72
+ data: {
73
+ dragRect: SelectModeBoundingRect | null;
74
+ selectionRects: SelectModeSelectionRect[];
75
+ };
76
+ } | {
77
+ method: "areaSelected";
78
+ data: {
79
+ rect: SelectModeBoundingRect;
80
+ items: SelectableData[];
81
+ };
82
+ } | {
83
+ method: "textCommitted";
84
+ data: {
85
+ editId: string;
86
+ html: string;
87
+ json: {
88
+ [x: string]: unknown;
89
+ };
90
+ originalInnerHTML: string;
91
+ };
92
+ } | {
93
+ method: "editorStateUpdate";
94
+ data: {
95
+ activeMarks: SelectModeTiptapActiveMarks;
96
+ isEditing: boolean;
97
+ };
98
+ } | {
99
+ method: "fastRefreshComplete";
100
+ };
@@ -0,0 +1,82 @@
1
+ import { z } from "zod";
2
+ export type IframeRpcChannelMethodConfig = Record<string, {
3
+ inputSchema: z.ZodType;
4
+ outputSchema: z.ZodType;
5
+ timeoutMs?: number;
6
+ }>;
7
+ type MethodInput<Config extends IframeRpcChannelMethodConfig, Method extends keyof Config> = z.input<Config[Method]["inputSchema"]>;
8
+ type MethodOutput<Config extends IframeRpcChannelMethodConfig, Method extends keyof Config> = z.output<Config[Method]["outputSchema"]>;
9
+ type IsVoidMethod<Config extends IframeRpcChannelMethodConfig, Method extends keyof Config> = MethodOutput<Config, Method> extends void ? true : false;
10
+ type CallResult<Config extends IframeRpcChannelMethodConfig, Method extends keyof Config> = IsVoidMethod<Config, Method> extends true ? void : Promise<MethodOutput<Config, Method>>;
11
+ type MethodArgs<Config extends IframeRpcChannelMethodConfig, Method extends keyof Config> = undefined extends MethodInput<Config, Method> ? [input?: MethodInput<Config, Method>] : [input: MethodInput<Config, Method>];
12
+ export type IframeRpcChannelRemote<Config extends IframeRpcChannelMethodConfig> = {
13
+ [Method in keyof Config]: (...args: MethodArgs<Config, Method>) => CallResult<Config, Method>;
14
+ };
15
+ export type IframeRpcChannelHandlerMeta<OutgoingMethods extends IframeRpcChannelMethodConfig> = {
16
+ channel: IframeRpcChannelRemote<OutgoingMethods>;
17
+ };
18
+ export type IframeRpcChannelHandlers<IncomingMethods extends IframeRpcChannelMethodConfig, OutgoingMethods extends IframeRpcChannelMethodConfig = IframeRpcChannelMethodConfig> = {
19
+ [Method in keyof IncomingMethods]: (input: z.output<IncomingMethods[Method]["inputSchema"]>, meta: IframeRpcChannelHandlerMeta<OutgoingMethods>) => IsVoidMethod<IncomingMethods, Method> extends true ? void : // Valued handlers stay `unknown` so callers can return domain/generated
20
+ unknown | Promise<unknown>;
21
+ };
22
+ export type IframeRpcChannelInputHandlers<IncomingMethods extends IframeRpcChannelMethodConfig> = {
23
+ [Method in keyof IncomingMethods]: (input: z.output<IncomingMethods[Method]["inputSchema"]>) => IsVoidMethod<IncomingMethods, Method> extends true ? void : unknown | Promise<unknown>;
24
+ };
25
+ export declare const iframeRpcCallSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
26
+ type: z.ZodLiteral<"notify">;
27
+ method: z.ZodString;
28
+ data: z.ZodOptional<z.ZodUnknown>;
29
+ }, z.core.$strip>, z.ZodObject<{
30
+ type: z.ZodLiteral<"request">;
31
+ id: z.ZodUUID;
32
+ method: z.ZodString;
33
+ data: z.ZodOptional<z.ZodUnknown>;
34
+ }, z.core.$strip>, z.ZodObject<{
35
+ type: z.ZodLiteral<"response">;
36
+ id: z.ZodUUID;
37
+ result: z.ZodDiscriminatedUnion<[z.ZodObject<{
38
+ type: z.ZodLiteral<"success">;
39
+ data: z.ZodUnknown;
40
+ }, z.core.$strip>, z.ZodObject<{
41
+ type: z.ZodLiteral<"error">;
42
+ errorMessage: z.ZodString;
43
+ }, z.core.$strip>], "type">;
44
+ }, z.core.$strip>], "type">;
45
+ export type IframeRpcCall = z.infer<typeof iframeRpcCallSchema>;
46
+ type SubscriberWindow = {
47
+ addEventListener: (type: "message", listener: (event: MessageEvent) => void) => void;
48
+ removeEventListener: (type: "message", listener: (event: MessageEvent) => void) => void;
49
+ };
50
+ type TargetIframeWindow = {
51
+ postMessage: (message: unknown, targetOrigin: string) => void;
52
+ };
53
+ type IframeRpcChannelOptions<OutgoingMethods extends IframeRpcChannelMethodConfig, IncomingMethods extends IframeRpcChannelMethodConfig> = {
54
+ subscriberWindow: SubscriberWindow;
55
+ channelIdentifier: string;
56
+ version: number;
57
+ getTargetWindow: () => TargetIframeWindow | null;
58
+ targetOrigin: string;
59
+ isExpectedMessage: (event: MessageEvent) => boolean;
60
+ outgoingMethods: OutgoingMethods;
61
+ incomingMethods: IncomingMethods;
62
+ handlers: IframeRpcChannelHandlers<IncomingMethods, OutgoingMethods>;
63
+ };
64
+ export type IframeRpcChannel<OutgoingMethods extends IframeRpcChannelMethodConfig = IframeRpcChannelMethodConfig> = {
65
+ subscribe: () => () => void;
66
+ call: <Method extends keyof OutgoingMethods & string>(input: {
67
+ method: Method;
68
+ input: MethodInput<OutgoingMethods, Method>;
69
+ }) => CallResult<OutgoingMethods, Method>;
70
+ outgoingMethods: OutgoingMethods;
71
+ };
72
+ /**
73
+ * Flat method-per-key facade over `channel.call`. Prefer this at call sites
74
+ * over hand-writing `useMemo(() => ({ foo: (input) => channel.call(...) }))`.
75
+ *
76
+ * Pass a channel directly, or a getter (plus its method config) when the
77
+ * channel is created lazily / may be unavailable (e.g. SSR).
78
+ */
79
+ export declare function createIframeRpcRemote<OutgoingMethods extends IframeRpcChannelMethodConfig>(channel: IframeRpcChannel<OutgoingMethods>): IframeRpcChannelRemote<OutgoingMethods>;
80
+ export declare function createIframeRpcRemote<OutgoingMethods extends IframeRpcChannelMethodConfig>(getChannel: () => IframeRpcChannel<OutgoingMethods> | null, methods: OutgoingMethods): IframeRpcChannelRemote<OutgoingMethods>;
81
+ export declare function createIframeRpcChannel<OutgoingMethods extends IframeRpcChannelMethodConfig, IncomingMethods extends IframeRpcChannelMethodConfig>(options: IframeRpcChannelOptions<OutgoingMethods, IncomingMethods>): IframeRpcChannel<OutgoingMethods>;
82
+ export {};