@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,361 @@
1
+ import { IframeRpcChannelConfigurationError, IframeRpcChannelUnsubscribedError, IframeRpcChannelUnknownMethodError, IframeRpcChannelInvalidInputError, randomUUID, IframeRpcChannelTimeoutError, IframeRpcChannelRemoteError } from '../../chunk-OFU2QEDR.mjs';
2
+ import { isNullish } from '../../chunk-H36NDYLG.mjs';
3
+ import '../../chunk-ILGEM42C.mjs';
4
+ import '../../chunk-FNTGY7I5.mjs';
5
+ import { z } from 'zod';
6
+
7
+ // ../replo-utils/lib/log.ts
8
+ var defaultLogger = {
9
+ info: console.log,
10
+ debug: console.debug,
11
+ error: console.error
12
+ };
13
+ var iframeRpcCallResultSchema = z.discriminatedUnion("type", [
14
+ z.object({
15
+ type: z.literal("success"),
16
+ data: z.unknown()
17
+ }),
18
+ z.object({
19
+ type: z.literal("error"),
20
+ errorMessage: z.string()
21
+ })
22
+ ]);
23
+ var iframeRpcCallSchema = z.discriminatedUnion("type", [
24
+ z.object({
25
+ type: z.literal("notify"),
26
+ method: z.string(),
27
+ data: z.unknown().optional()
28
+ }),
29
+ z.object({
30
+ type: z.literal("request"),
31
+ id: z.uuid(),
32
+ method: z.string(),
33
+ data: z.unknown().optional()
34
+ }),
35
+ z.object({
36
+ type: z.literal("response"),
37
+ id: z.uuid(),
38
+ result: iframeRpcCallResultSchema
39
+ })
40
+ ]);
41
+ function isFireAndForgetOutputSchema(outputSchema) {
42
+ return outputSchema.type === "void" || outputSchema instanceof z.ZodVoid;
43
+ }
44
+ function isUndefinedInputSchema(inputSchema) {
45
+ return inputSchema.type === "undefined" || inputSchema instanceof z.ZodUndefined;
46
+ }
47
+ function coerceEmptyRpcInput({
48
+ input,
49
+ inputSchema
50
+ }) {
51
+ if (isNullish(input) && isUndefinedInputSchema(inputSchema)) {
52
+ return void 0;
53
+ }
54
+ return input;
55
+ }
56
+ function createIframeRpcRemote(channelOrGetChannel, methods) {
57
+ const getChannel = typeof channelOrGetChannel === "function" ? channelOrGetChannel : () => channelOrGetChannel;
58
+ const outgoingMethods = methods ?? getChannel()?.outgoingMethods ?? null;
59
+ if (!outgoingMethods) {
60
+ throw new IframeRpcChannelConfigurationError({
61
+ message: "createIframeRpcRemote requires methods when the channel may be null"
62
+ });
63
+ }
64
+ return Object.fromEntries(
65
+ Object.keys(outgoingMethods).map(
66
+ (method) => {
67
+ return [
68
+ method,
69
+ (input) => {
70
+ const definition = outgoingMethods[method];
71
+ const channel = getChannel();
72
+ if (!channel) {
73
+ if (definition && isFireAndForgetOutputSchema(definition.outputSchema)) {
74
+ return void 0;
75
+ }
76
+ return Promise.reject(
77
+ new IframeRpcChannelUnsubscribedError({ method })
78
+ );
79
+ }
80
+ return channel.call({
81
+ method,
82
+ input
83
+ });
84
+ }
85
+ ];
86
+ }
87
+ )
88
+ );
89
+ }
90
+ function createIframeRpcChannel(options) {
91
+ const {
92
+ subscriberWindow,
93
+ channelIdentifier,
94
+ version,
95
+ getTargetWindow,
96
+ targetOrigin,
97
+ isExpectedMessage,
98
+ outgoingMethods,
99
+ incomingMethods,
100
+ handlers
101
+ } = options;
102
+ const pendingRequests = /* @__PURE__ */ new Map();
103
+ let subscriberCount = 0;
104
+ let handlerMeta;
105
+ const postMessage = (call2) => {
106
+ getTargetWindow()?.postMessage(
107
+ {
108
+ channelIdentifier,
109
+ version,
110
+ ...call2
111
+ },
112
+ targetOrigin
113
+ );
114
+ };
115
+ const respondWithError = ({
116
+ id,
117
+ errorMessage
118
+ }) => {
119
+ postMessage({
120
+ type: "response",
121
+ id,
122
+ result: { type: "error", errorMessage }
123
+ });
124
+ };
125
+ const handleRequest = async (message) => {
126
+ const definition = incomingMethods[message.method];
127
+ if (!definition || isFireAndForgetOutputSchema(definition.outputSchema)) {
128
+ respondWithError({
129
+ id: message.id,
130
+ errorMessage: `Unknown RPC method '${message.method}'`
131
+ });
132
+ return;
133
+ }
134
+ const parsedInput = definition.inputSchema.safeParse(
135
+ coerceEmptyRpcInput({
136
+ input: message.data,
137
+ inputSchema: definition.inputSchema
138
+ })
139
+ );
140
+ if (!parsedInput.success) {
141
+ respondWithError({
142
+ id: message.id,
143
+ errorMessage: `Invalid request payload for '${message.method}': ${parsedInput.error.message}`
144
+ });
145
+ return;
146
+ }
147
+ try {
148
+ const handler = handlers[
149
+ // eslint-disable-next-line replo/no-as-cast -- NOTE (Noah, 2026-07-25): The method existence check above narrows this dynamic wire string to the configured handler keys.
150
+ message.method
151
+ ];
152
+ const result = await handler(parsedInput.data, handlerMeta);
153
+ const parsedOutput = definition.outputSchema.safeParse(result);
154
+ if (!parsedOutput.success) {
155
+ respondWithError({
156
+ id: message.id,
157
+ errorMessage: `Invalid response payload for '${message.method}': ${parsedOutput.error.message}`
158
+ });
159
+ return;
160
+ }
161
+ postMessage({
162
+ type: "response",
163
+ id: message.id,
164
+ result: { type: "success", data: parsedOutput.data }
165
+ });
166
+ } catch (error) {
167
+ respondWithError({
168
+ id: message.id,
169
+ errorMessage: error instanceof Error ? error.message : String(error)
170
+ });
171
+ }
172
+ };
173
+ const handleNotification = (message) => {
174
+ const definition = incomingMethods[message.method];
175
+ if (!definition || !isFireAndForgetOutputSchema(definition.outputSchema)) {
176
+ return;
177
+ }
178
+ const parsedInput = definition.inputSchema.safeParse(
179
+ coerceEmptyRpcInput({
180
+ input: message.data,
181
+ inputSchema: definition.inputSchema
182
+ })
183
+ );
184
+ if (!parsedInput.success) {
185
+ defaultLogger.error(
186
+ `[iframeRpcChannel] Dropping invalid notify for '${message.method}': ${parsedInput.error.message}`
187
+ );
188
+ return;
189
+ }
190
+ const handler = handlers[
191
+ // eslint-disable-next-line replo/no-as-cast -- NOTE (Noah, 2026-08-07): Method existence check narrows this wire string to configured handler keys.
192
+ message.method
193
+ ];
194
+ handler(parsedInput.data, handlerMeta);
195
+ };
196
+ const handleResponse = (message) => {
197
+ const pendingRequest = pendingRequests.get(message.id);
198
+ if (!pendingRequest) {
199
+ return;
200
+ }
201
+ clearTimeout(pendingRequest.timeoutId);
202
+ pendingRequests.delete(message.id);
203
+ if (message.result.type === "error") {
204
+ pendingRequest.reject(
205
+ new IframeRpcChannelRemoteError({
206
+ method: pendingRequest.method,
207
+ message: message.result.errorMessage
208
+ })
209
+ );
210
+ return;
211
+ }
212
+ const definition = outgoingMethods[pendingRequest.method];
213
+ const parsedOutput = definition?.outputSchema.safeParse(
214
+ message.result.data
215
+ );
216
+ if (!parsedOutput?.success) {
217
+ pendingRequest.reject(
218
+ new IframeRpcChannelRemoteError({
219
+ method: pendingRequest.method,
220
+ message: `Invalid response payload: ${parsedOutput?.error.message ?? "unknown method"}`
221
+ })
222
+ );
223
+ return;
224
+ }
225
+ pendingRequest.resolve(parsedOutput.data);
226
+ };
227
+ const handleMessage = (event) => {
228
+ if (!isExpectedMessage(event)) {
229
+ return;
230
+ }
231
+ const parsedMetadata = z.object({
232
+ channelIdentifier: z.literal(channelIdentifier),
233
+ version: z.literal(version)
234
+ }).safeParse(event.data);
235
+ if (!parsedMetadata.success) {
236
+ return;
237
+ }
238
+ const parsedCall = iframeRpcCallSchema.safeParse(event.data);
239
+ if (!parsedCall.success) {
240
+ return;
241
+ }
242
+ const message = parsedCall.data;
243
+ if (message.type === "notify") {
244
+ handleNotification(message);
245
+ return;
246
+ }
247
+ if (message.type === "request") {
248
+ void handleRequest(message);
249
+ return;
250
+ }
251
+ handleResponse(message);
252
+ };
253
+ const rejectPendingRequests = () => {
254
+ for (const pendingRequest of pendingRequests.values()) {
255
+ clearTimeout(pendingRequest.timeoutId);
256
+ pendingRequest.reject(
257
+ new IframeRpcChannelUnsubscribedError({
258
+ method: pendingRequest.method
259
+ })
260
+ );
261
+ }
262
+ pendingRequests.clear();
263
+ };
264
+ const subscribe = () => {
265
+ subscriberCount += 1;
266
+ if (subscriberCount === 1) {
267
+ subscriberWindow.addEventListener("message", handleMessage);
268
+ }
269
+ let isActive = true;
270
+ return () => {
271
+ if (!isActive) {
272
+ return;
273
+ }
274
+ isActive = false;
275
+ subscriberCount -= 1;
276
+ if (subscriberCount === 0) {
277
+ subscriberWindow.removeEventListener("message", handleMessage);
278
+ rejectPendingRequests();
279
+ }
280
+ };
281
+ };
282
+ const call = ({
283
+ method,
284
+ input
285
+ }) => {
286
+ const definition = outgoingMethods[method];
287
+ if (!definition) {
288
+ return Promise.reject(
289
+ new IframeRpcChannelUnknownMethodError({ method })
290
+ );
291
+ }
292
+ const isFireAndForget = isFireAndForgetOutputSchema(
293
+ definition.outputSchema
294
+ );
295
+ const parsedInput = definition.inputSchema.safeParse(
296
+ coerceEmptyRpcInput({
297
+ input,
298
+ inputSchema: definition.inputSchema
299
+ })
300
+ );
301
+ if (!parsedInput.success) {
302
+ const error = new IframeRpcChannelInvalidInputError({
303
+ method,
304
+ cause: parsedInput.error
305
+ });
306
+ if (isFireAndForget) {
307
+ throw error;
308
+ }
309
+ return Promise.reject(error);
310
+ }
311
+ if (isFireAndForget) {
312
+ postMessage({
313
+ type: "notify",
314
+ method,
315
+ data: parsedInput.data
316
+ });
317
+ return void 0;
318
+ }
319
+ if (subscriberCount === 0) {
320
+ return Promise.reject(
321
+ new IframeRpcChannelUnsubscribedError({ method })
322
+ );
323
+ }
324
+ const id = randomUUID();
325
+ const timeoutMs = definition.timeoutMs ?? 3e4;
326
+ return new Promise(
327
+ (resolve, reject) => {
328
+ const timeoutId = setTimeout(() => {
329
+ pendingRequests.delete(id);
330
+ reject(new IframeRpcChannelTimeoutError({ method, timeoutMs }));
331
+ }, timeoutMs);
332
+ pendingRequests.set(id, {
333
+ method,
334
+ // PendingRequest is shared across methods, so resolve is typed as
335
+ // unknown; handleResponse already validated against this method's
336
+ // outputSchema before calling it.
337
+ resolve: (value) => {
338
+ resolve(value);
339
+ },
340
+ reject,
341
+ timeoutId
342
+ });
343
+ postMessage({
344
+ type: "request",
345
+ id,
346
+ method,
347
+ data: parsedInput.data
348
+ });
349
+ }
350
+ );
351
+ };
352
+ const channel = {
353
+ subscribe,
354
+ call,
355
+ outgoingMethods
356
+ };
357
+ handlerMeta = { channel: createIframeRpcRemote(channel) };
358
+ return channel;
359
+ }
360
+
361
+ export { createIframeRpcChannel, createIframeRpcRemote, iframeRpcCallSchema };
@@ -1,121 +1,10 @@
1
- import '../../chunk-UWHM3FKU.mjs';
1
+ import { ReploError } from '../../chunk-OFU2QEDR.mjs';
2
+ import '../../chunk-H36NDYLG.mjs';
2
3
  import '../../chunk-ILGEM42C.mjs';
3
4
  import '../../chunk-FNTGY7I5.mjs';
4
5
  import { code } from 'currency-codes';
5
6
  import { z } from 'zod';
6
- import { v4 } from 'uuid';
7
7
 
8
- function randomUUID() {
9
- return v4();
10
- }
11
- var ReploError = class _ReploError extends Error {
12
- config;
13
- id;
14
- constructor(config) {
15
- super(config.message);
16
- this.message = config.message ?? this.constructor.name;
17
- this.config = config;
18
- this.id = randomUUID();
19
- const { cause } = config;
20
- if (cause) {
21
- this.cause = cause;
22
- if (cause instanceof _ReploError) {
23
- this.config.additionalData = {
24
- ...this.config.additionalData,
25
- ...cause.config.additionalData
26
- };
27
- }
28
- }
29
- }
30
- };
31
- var errorUserFacingDetailsMessageSchema = z.object({
32
- type: z.enum([
33
- "toast",
34
- "fullPageModal",
35
- "shopifyStorePassword",
36
- "billing.addPublishedElements",
37
- "billing.addShopifyThemeProject",
38
- "billing.addReploSite",
39
- // Agent Billing ONLY
40
- "agentBilling.shopifyThemeBuilder.publishedElements.exceeded",
41
- "agentBilling.shopifyThemeBuilder.projects.exceeded",
42
- "agentBilling.sites.exceeded",
43
- "agentBilling.credits.exceeded",
44
- "agentBilling.upgradeRequired"
45
- ]),
46
- message: z.string(),
47
- isRecoverable: z.boolean().optional(),
48
- // NOTE (Matt 2024-03-22): We support detail being an array of strings
49
- // in FullPageModal only.
50
- detail: z.array(z.string()).or(z.string()).optional(),
51
- key: z.string(),
52
- usage: z.object({
53
- current: z.number(),
54
- maximum: z.number()
55
- }).optional(),
56
- plan: z.string().optional(),
57
- callToAction: z.discriminatedUnion("type", [
58
- z.object({ type: z.literal("reload") }),
59
- z.object({ type: z.literal("installApp") }),
60
- z.object({ type: z.literal("goToHomepage") }),
61
- z.object({ type: z.literal("navigateToProjectEditor") }),
62
- z.object({ type: z.literal("closeModal") }),
63
- z.object({
64
- type: z.literal("navigateToLink"),
65
- link: z.discriminatedUnion("type", [
66
- z.object({ type: z.literal("errors.wrongJsonExtension") }),
67
- z.object({ type: z.literal("errors.chunkingError") }),
68
- z.object({ type: z.literal("errors.indexBackupError") }),
69
- z.object({
70
- type: z.literal("errors.shopifyIntegrationAlreadyAssigned")
71
- }),
72
- z.object({
73
- type: z.literal("errors.shopifyIntegrationMissingAccessScopes"),
74
- url: z.string()
75
- }),
76
- z.object({
77
- type: z.literal("customLink"),
78
- url: z.string()
79
- }),
80
- z.object({
81
- type: z.literal(
82
- "errors.projectConnectedToBillingIntegrationForShopifyWorkspace"
83
- )
84
- }),
85
- z.object({ type: z.literal("errors.themeAssetSizeLimitExceeded") }),
86
- z.object({ type: z.literal("errors.themeTotalSizeLimitExceeded") }),
87
- z.object({
88
- type: z.literal("errors.pageMetafieldDefinitionsChanged")
89
- }),
90
- z.object({ type: z.literal("settings.billing") })
91
- ])
92
- })
93
- ]).optional()
94
- }).describe("ErrorUserFacingDetailsWithMessage");
95
- z.discriminatedUnion("type", [
96
- /**
97
- * Normal errors, show error UI depending on the type
98
- */
99
- errorUserFacingDetailsMessageSchema,
100
- /**
101
- * Errors which should be ignored by the frontend. This is uncommon, usually
102
- * you want to show an error in the UI, and if you don't want to then you catch
103
- * the error in your route.
104
- */
105
- z.object({
106
- type: z.literal("uncommon_none"),
107
- key: z.string(),
108
- usage: z.object({
109
- current: z.number(),
110
- maximum: z.number()
111
- }).optional(),
112
- message: z.string().optional(),
113
- isRecoverable: z.boolean().optional(),
114
- detail: z.array(z.string()).or(z.string()).optional()
115
- })
116
- ]).describe("ErrorUserFacingDetails");
117
-
118
- // ../schemas/money.ts
119
8
  var InvalidAmountError = class extends ReploError {
120
9
  };
121
10
  var UnsupportedCurrencyError = class extends ReploError {