@agent-native/core 0.101.7 → 0.101.10

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 (153) hide show
  1. package/corpus/README.md +1 -1
  2. package/corpus/core/CHANGELOG.md +22 -0
  3. package/corpus/core/docs/content/deployment.mdx +9 -7
  4. package/corpus/core/docs/content/locales/ar-SA/deployment.mdx +9 -7
  5. package/corpus/core/docs/content/locales/de-DE/deployment.mdx +9 -7
  6. package/corpus/core/docs/content/locales/es-ES/deployment.mdx +9 -7
  7. package/corpus/core/docs/content/locales/fr-FR/deployment.mdx +9 -7
  8. package/corpus/core/docs/content/locales/hi-IN/deployment.mdx +9 -7
  9. package/corpus/core/docs/content/locales/ja-JP/deployment.mdx +9 -7
  10. package/corpus/core/docs/content/locales/ko-KR/deployment.mdx +9 -7
  11. package/corpus/core/docs/content/locales/pt-BR/deployment.mdx +9 -7
  12. package/corpus/core/docs/content/locales/zh-CN/deployment.mdx +9 -7
  13. package/corpus/core/docs/content/locales/zh-TW/deployment.mdx +9 -7
  14. package/corpus/core/package.json +1 -1
  15. package/corpus/core/src/client/review/ReviewCommentComposer.tsx +9 -1
  16. package/corpus/core/src/client/review/ReviewThreadPanel.tsx +17 -2
  17. package/corpus/core/src/client/settings/SettingsPanel.tsx +41 -21
  18. package/corpus/core/src/client/settings/useBuilderStatus.ts +28 -9
  19. package/corpus/core/src/client/setup-connections/BuilderConnectCard.tsx +2 -7
  20. package/corpus/core/src/server/auth.ts +25 -1
  21. package/corpus/core/src/server/builder-browser.ts +353 -1
  22. package/corpus/core/src/server/core-routes-plugin.ts +601 -223
  23. package/corpus/templates/calendar/app/components/calendar/DayView.tsx +80 -1
  24. package/corpus/templates/calendar/app/components/calendar/EventCard.tsx +28 -3
  25. package/corpus/templates/calendar/app/components/calendar/EventDetailPanel.tsx +5 -1
  26. package/corpus/templates/calendar/app/components/calendar/EventDetailPopover.tsx +30 -3
  27. package/corpus/templates/calendar/app/components/calendar/OutOfOfficeEvent.tsx +196 -0
  28. package/corpus/templates/calendar/app/components/calendar/WeekView.tsx +115 -1
  29. package/corpus/templates/calendar/app/lib/out-of-office.ts +45 -0
  30. package/corpus/templates/calendar/changelog/2026-07-14-out-of-office-blocks-now-sit-behind-meetings-and-event-stack.md +6 -0
  31. package/corpus/templates/content/AGENTS.md +3 -2
  32. package/corpus/templates/content/actions/_builder-cms-intent-lookup.ts +87 -0
  33. package/corpus/templates/content/actions/_builder-cms-read-client.ts +173 -25
  34. package/corpus/templates/content/actions/_builder-cms-source-adapter.ts +1 -0
  35. package/corpus/templates/content/actions/_builder-cms-write-adapter.ts +427 -18
  36. package/corpus/templates/content/actions/_builder-cms-write-client.ts +17 -73
  37. package/corpus/templates/content/actions/_builder-cms-write-settings.ts +27 -7
  38. package/corpus/templates/content/actions/_builder-source-execution-claim.ts +124 -0
  39. package/corpus/templates/content/actions/_builder-source-execution-preservation.ts +21 -0
  40. package/corpus/templates/content/actions/_builder-source-timings.ts +57 -0
  41. package/corpus/templates/content/actions/_database-source-utils.ts +1041 -154
  42. package/corpus/templates/content/actions/_database-utils.ts +89 -12
  43. package/corpus/templates/content/actions/_preview-document-draft.ts +31 -0
  44. package/corpus/templates/content/actions/cancel-prepared-builder-source-update.ts +309 -0
  45. package/corpus/templates/content/actions/execute-builder-source-batch.ts +120 -49
  46. package/corpus/templates/content/actions/execute-builder-source-execution.ts +608 -264
  47. package/corpus/templates/content/actions/get-preview-document-draft.ts +26 -0
  48. package/corpus/templates/content/actions/materialize-builder-required-fields.ts +550 -0
  49. package/corpus/templates/content/actions/prepare-builder-source-execution.ts +112 -65
  50. package/corpus/templates/content/actions/prepare-builder-source-review.ts +463 -170
  51. package/corpus/templates/content/actions/preview-builder-source-review.ts +99 -0
  52. package/corpus/templates/content/actions/set-content-database-source-write-mode.ts +2 -2
  53. package/corpus/templates/content/actions/update-preview-document-draft.ts +153 -0
  54. package/corpus/templates/content/app/components/editor/DocumentProperties.tsx +27 -15
  55. package/corpus/templates/content/app/components/editor/VisualEditor.tsx +57 -5
  56. package/corpus/templates/content/app/components/editor/body-hydration.ts +27 -0
  57. package/corpus/templates/content/app/components/editor/database/DatabaseView.tsx +2353 -576
  58. package/corpus/templates/content/app/components/editor/database/settings.tsx +13 -10
  59. package/corpus/templates/content/app/components/editor/database-sources/BuilderSourceReviewDialog.tsx +358 -75
  60. package/corpus/templates/content/app/components/editor/previewDocumentSaveController.ts +124 -29
  61. package/corpus/templates/content/app/components/editor/previewDocumentSaveRegistry.ts +2 -0
  62. package/corpus/templates/content/app/global.css +18 -1
  63. package/corpus/templates/content/app/hooks/use-content-database.ts +68 -0
  64. package/corpus/templates/content/app/hooks/use-documents.ts +53 -4
  65. package/corpus/templates/content/app/i18n/zh-TW.ts +25 -0
  66. package/corpus/templates/content/app/i18n-data.ts +287 -0
  67. package/corpus/templates/content/changelog/2026-07-10-builder-backed-preview-edits-are-preserved-when-article-bodi.md +6 -0
  68. package/corpus/templates/content/changelog/2026-07-10-builder-cms-sources-can-now-be-enabled-for-guarded-staged-or.md +6 -0
  69. package/corpus/templates/content/changelog/2026-07-13-builder-connection-setup-is-now-available-directly-from-conn.md +6 -0
  70. package/corpus/templates/content/changelog/2026-07-13-builder-reviews-now-hide-already-applied-writes-detect-nativ.md +6 -0
  71. package/corpus/templates/content/changelog/2026-07-13-required-builder-publishing-fields-can-now-be-added-directly.md +6 -0
  72. package/corpus/templates/content/changelog/2026-07-13-you-can-now-cancel-a-prepared-builder-update-safely-before-i.md +6 -0
  73. package/corpus/templates/content/changelog/2026-07-14-builder-account-connection-now-remains-available-when-branch.md +6 -0
  74. package/corpus/templates/content/changelog/2026-07-14-builder-backed-articles-now-preserve-fifth-and-sixth-level-h.md +6 -0
  75. package/corpus/templates/content/changelog/2026-07-14-builder-sources-now-review-and-publish-rich-article-updates-.md +6 -0
  76. package/corpus/templates/content/changelog/2026-07-14-builder-writes-now-stop-retries-when-reconciliation-is-needed.md +6 -0
  77. package/corpus/templates/content/changelog/2026-07-14-file-and-media-links-now-validate-before-saving.md +6 -0
  78. package/corpus/templates/content/parity/matrix.md +27 -25
  79. package/corpus/templates/content/parity/matrix.ts +50 -2
  80. package/corpus/templates/content/server/db/schema.ts +47 -0
  81. package/corpus/templates/content/server/plugins/auth.ts +1 -0
  82. package/corpus/templates/content/server/plugins/db.ts +53 -0
  83. package/corpus/templates/content/shared/api.ts +70 -1
  84. package/corpus/templates/content/shared/builder-mdx.ts +705 -15
  85. package/corpus/templates/content/shared/nfm.ts +3 -3
  86. package/corpus/templates/design/app/components/design/ReadOnlyDesignBanner.tsx +52 -7
  87. package/corpus/templates/design/app/components/design/ReviewCommentsPanel.tsx +36 -4
  88. package/corpus/templates/design/app/components/visual-editor/ReviewCanvasPins.tsx +4 -1
  89. package/corpus/templates/design/app/i18n/ar-SA.ts +1 -0
  90. package/corpus/templates/design/app/i18n/de-DE.ts +1 -0
  91. package/corpus/templates/design/app/i18n/en-US.ts +1 -0
  92. package/corpus/templates/design/app/i18n/es-ES.ts +1 -0
  93. package/corpus/templates/design/app/i18n/fr-FR.ts +1 -0
  94. package/corpus/templates/design/app/i18n/hi-IN.ts +1 -0
  95. package/corpus/templates/design/app/i18n/ja-JP.ts +1 -0
  96. package/corpus/templates/design/app/i18n/ko-KR.ts +1 -0
  97. package/corpus/templates/design/app/i18n/pt-BR.ts +1 -0
  98. package/corpus/templates/design/app/i18n/zh-CN.ts +1 -0
  99. package/corpus/templates/design/app/i18n/zh-TW.ts +1 -0
  100. package/corpus/templates/design/app/pages/design-editor/selection-state.ts +8 -0
  101. package/corpus/templates/design/app/pages/design-editor/tool-state.ts +11 -0
  102. package/corpus/templates/design/changelog/2026-07-14-reviewers-can-now-pin-comments-from-the-canvas-toolbar-targe.md +6 -0
  103. package/corpus/templates/design/changelog/2026-07-15-viewer-comment-controls-now-sit-inside-the-read-only-notice-.md +6 -0
  104. package/corpus/templates/design/shared/review-anchor.ts +48 -0
  105. package/corpus/templates/plan/server/plan-mdx.ts +53 -7
  106. package/dist/client/review/ReviewCommentComposer.d.ts +2 -1
  107. package/dist/client/review/ReviewCommentComposer.d.ts.map +1 -1
  108. package/dist/client/review/ReviewCommentComposer.js +3 -3
  109. package/dist/client/review/ReviewCommentComposer.js.map +1 -1
  110. package/dist/client/review/ReviewThreadPanel.d.ts +9 -1
  111. package/dist/client/review/ReviewThreadPanel.d.ts.map +1 -1
  112. package/dist/client/review/ReviewThreadPanel.js +6 -4
  113. package/dist/client/review/ReviewThreadPanel.js.map +1 -1
  114. package/dist/client/settings/SettingsPanel.d.ts +3 -0
  115. package/dist/client/settings/SettingsPanel.d.ts.map +1 -1
  116. package/dist/client/settings/SettingsPanel.js +11 -4
  117. package/dist/client/settings/SettingsPanel.js.map +1 -1
  118. package/dist/client/settings/useBuilderStatus.d.ts +8 -4
  119. package/dist/client/settings/useBuilderStatus.d.ts.map +1 -1
  120. package/dist/client/settings/useBuilderStatus.js +19 -6
  121. package/dist/client/settings/useBuilderStatus.js.map +1 -1
  122. package/dist/client/setup-connections/BuilderConnectCard.d.ts.map +1 -1
  123. package/dist/client/setup-connections/BuilderConnectCard.js +2 -5
  124. package/dist/client/setup-connections/BuilderConnectCard.js.map +1 -1
  125. package/dist/collab/awareness.d.ts +2 -2
  126. package/dist/collab/awareness.d.ts.map +1 -1
  127. package/dist/observability/routes.d.ts +5 -5
  128. package/dist/resources/handlers.d.ts +1 -1
  129. package/dist/secrets/routes.d.ts +9 -9
  130. package/dist/server/auth.d.ts +1 -0
  131. package/dist/server/auth.d.ts.map +1 -1
  132. package/dist/server/auth.js +19 -2
  133. package/dist/server/auth.js.map +1 -1
  134. package/dist/server/builder-browser.d.ts +78 -0
  135. package/dist/server/builder-browser.d.ts.map +1 -1
  136. package/dist/server/builder-browser.js +246 -1
  137. package/dist/server/builder-browser.js.map +1 -1
  138. package/dist/server/core-routes-plugin.d.ts +41 -0
  139. package/dist/server/core-routes-plugin.d.ts.map +1 -1
  140. package/dist/server/core-routes-plugin.js +260 -14
  141. package/dist/server/core-routes-plugin.js.map +1 -1
  142. package/docs/content/deployment.mdx +9 -7
  143. package/docs/content/locales/ar-SA/deployment.mdx +9 -7
  144. package/docs/content/locales/de-DE/deployment.mdx +9 -7
  145. package/docs/content/locales/es-ES/deployment.mdx +9 -7
  146. package/docs/content/locales/fr-FR/deployment.mdx +9 -7
  147. package/docs/content/locales/hi-IN/deployment.mdx +9 -7
  148. package/docs/content/locales/ja-JP/deployment.mdx +9 -7
  149. package/docs/content/locales/ko-KR/deployment.mdx +9 -7
  150. package/docs/content/locales/pt-BR/deployment.mdx +9 -7
  151. package/docs/content/locales/zh-CN/deployment.mdx +9 -7
  152. package/docs/content/locales/zh-TW/deployment.mdx +9 -7
  153. package/package.json +2 -2
@@ -1,5 +1,81 @@
1
1
  import type { H3Event } from "h3";
2
2
  export declare const BUILDER_CALLBACK_PATH = "/_agent-native/builder/callback";
3
+ export declare const BUILDER_RELAY_PATH = "/_agent-native/builder/relay";
4
+ export declare const BUILDER_RELAY_STATE_PARAM = "_an_relay";
5
+ export declare const BUILDER_RELAY_SECRET_ENV = "AGENT_NATIVE_BUILDER_RELAY_SECRET";
6
+ export declare const BUILDER_RELAY_TARGET_ORIGINS_ENV = "AGENT_NATIVE_BUILDER_RELAY_TARGET_ORIGINS";
7
+ export declare const BUILDER_RELAY_TIMESTAMP_HEADER = "x-agent-native-relay-timestamp";
8
+ export declare const BUILDER_RELAY_FLOW_HEADER = "x-agent-native-relay-flow";
9
+ export declare const BUILDER_RELAY_SIGNATURE_HEADER = "x-agent-native-relay-signature";
10
+ declare const BUILDER_RELAY_PURPOSE = "builder-preview-callback-relay";
11
+ export interface BuilderPreviewRelayState {
12
+ v: 1;
13
+ purpose: typeof BUILDER_RELAY_PURPOSE;
14
+ flowId: string;
15
+ ownerEmail: string;
16
+ targetOrigin: string;
17
+ basePath: string;
18
+ iat: number;
19
+ exp: number;
20
+ }
21
+ export interface BuilderRelayCredentials {
22
+ privateKey: string;
23
+ publicKey: string;
24
+ userId: string | null;
25
+ orgName: string | null;
26
+ orgKind: string | null;
27
+ subscription: string | null;
28
+ subscriptionLevel: string | null;
29
+ subscriptionName: string | null;
30
+ isEnterprise: boolean | null;
31
+ isFreeAccount: boolean | null;
32
+ }
33
+ export interface BuilderRelayRequestBody {
34
+ relayState: string;
35
+ credentials: BuilderRelayCredentials;
36
+ }
37
+ export declare function isSafeBuilderRelayTargetOrigin(value: string): boolean;
38
+ export declare function isTrustedBuilderRelayTargetOrigin(value: string): boolean;
39
+ export declare function signBuilderPreviewRelayState(input: {
40
+ ownerEmail: string;
41
+ targetOrigin: string;
42
+ basePath?: string;
43
+ flowId?: string;
44
+ now?: number;
45
+ }): {
46
+ state: string;
47
+ payload: BuilderPreviewRelayState;
48
+ };
49
+ export declare function verifyBuilderPreviewRelayState(state: string | null | undefined, options?: {
50
+ now?: number;
51
+ }): BuilderPreviewRelayState | null;
52
+ /**
53
+ * Corporate callback trust check. Preview-side state verification and relay
54
+ * receipt deliberately do not require this callback-only allowlist.
55
+ */
56
+ export declare function verifyBuilderPreviewRelayStateForCallback(state: string | null | undefined, options?: {
57
+ now?: number;
58
+ }): BuilderPreviewRelayState | null;
59
+ export declare function getBuilderPreviewRelayUrl(payload: BuilderPreviewRelayState): string;
60
+ export declare function createBuilderRelayRequest(relayState: string, credentials: BuilderRelayCredentials, options?: {
61
+ now?: number;
62
+ }): {
63
+ body: string;
64
+ headers: Record<string, string>;
65
+ url: string;
66
+ };
67
+ export declare function verifyBuilderRelayRequest(input: {
68
+ body: string;
69
+ timestamp: string | null | undefined;
70
+ flowId: string | null | undefined;
71
+ signature: string | null | undefined;
72
+ requestOrigin: string;
73
+ requestBasePath: string;
74
+ now?: number;
75
+ }): {
76
+ payload: BuilderPreviewRelayState;
77
+ body: BuilderRelayRequestBody;
78
+ } | null;
3
79
  /**
4
80
  * Query-param name carrying the signed CSRF state on the connect→callback
5
81
  * round-trip. Prefixed with `_an_` to avoid collisions if Builder ever
@@ -144,6 +220,7 @@ export declare const BUILDER_OPENER_PARAM = "_an_opener";
144
220
  */
145
221
  export declare function buildBuilderCliAuthUrl(callbackOrigin: string, state?: string | null, options?: {
146
222
  previewOrigin?: string;
223
+ relayState?: string;
147
224
  tracking?: BuilderConnectTrackingParams;
148
225
  }): string;
149
226
  /**
@@ -246,4 +323,5 @@ export interface RunBuilderAgentResult {
246
323
  */
247
324
  export declare function runBuilderAgent(args: RunBuilderAgentArgs): Promise<RunBuilderAgentResult>;
248
325
  export declare function requestBuilderBrowserConnection(args: BrowserConnectionArgs): Promise<Record<string, unknown>>;
326
+ export {};
249
327
  //# sourceMappingURL=builder-browser.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"builder-browser.d.ts","sourceRoot":"","sources":["../../src/server/builder-browser.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAclC,eAAO,MAAM,qBAAqB,oCAAoC,CAAC;AAmBvE;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,cAAc,CAAC;AAC/C,eAAO,MAAM,qBAAqB,gBAAgB,CAAC;AACnD,eAAO,MAAM,4BAA4B,6BAA6B,CAAC;AACvE,eAAO,MAAM,2BAA2B,iBAAiB,CAAC;AAC1D,eAAO,MAAM,+BAA+B,oBAAoB,CAAC;AACjE,eAAO,MAAM,yCAAyC,6BAC1B,CAAC;AAC7B,eAAO,MAAM,8BAA8B,mBAAmB,CAAC;AAC/D,eAAO,MAAM,mCAAmC,wBAAwB,CAAC;AAKzE,MAAM,WAAW,4BAA4B;IAC3C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAQD,wBAAgB,+BAA+B,CAC7C,MAAM,EAAE,eAAe,GACtB,4BAA4B,CAkB9B;AAED,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AAC;CAClB,GACL,MAAM,CA8DR;AAED,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;CAChB;AAiCD;;;;;;GAMG;AACH,wBAAsB,eAAe,CACnC,IAAI,EAAE,mBAAmB,GACxB,OAAO,CAAC,qBAAqB,CAAC,CAkEhC;AAED,wBAAsB,+BAA+B,CACnD,IAAI,EAAE,qBAAqB,GAC1B,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAgDlC"}
@@ -1,4 +1,4 @@
1
- import { createHmac, randomBytes, timingSafeEqual } from "node:crypto";
1
+ import { createHash, createHmac, randomBytes, timingSafeEqual, } from "node:crypto";
2
2
  import { getHeader } from "h3";
3
3
  import { getAuthSecret, resolveSignupTrackingIdentity, } from "./better-auth-instance.js";
4
4
  import { getAppBasePath, getOrigin } from "./google-oauth.js";
@@ -7,6 +7,248 @@ const DEFAULT_BUILDER_API_HOST = "https://api.builder.io";
7
7
  const BUILDER_BROWSER_HOST = "agent-native-browser";
8
8
  const BUILDER_BROWSER_CLIENT_ID = "Agent Native Browser";
9
9
  export const BUILDER_CALLBACK_PATH = "/_agent-native/builder/callback";
10
+ export const BUILDER_RELAY_PATH = "/_agent-native/builder/relay";
11
+ export const BUILDER_RELAY_STATE_PARAM = "_an_relay";
12
+ export const BUILDER_RELAY_SECRET_ENV = "AGENT_NATIVE_BUILDER_RELAY_SECRET";
13
+ export const BUILDER_RELAY_TARGET_ORIGINS_ENV = "AGENT_NATIVE_BUILDER_RELAY_TARGET_ORIGINS";
14
+ export const BUILDER_RELAY_TIMESTAMP_HEADER = "x-agent-native-relay-timestamp";
15
+ export const BUILDER_RELAY_FLOW_HEADER = "x-agent-native-relay-flow";
16
+ export const BUILDER_RELAY_SIGNATURE_HEADER = "x-agent-native-relay-signature";
17
+ const BUILDER_RELAY_PURPOSE = "builder-preview-callback-relay";
18
+ const BUILDER_RELAY_STATE_VERSION = 1;
19
+ const BUILDER_RELAY_TTL_MS = 10 * 60 * 1000;
20
+ const BUILDER_RELAY_REQUEST_SKEW_MS = 2 * 60 * 1000;
21
+ function builderRelaySecret() {
22
+ const secret = process.env[BUILDER_RELAY_SECRET_ENV]?.trim();
23
+ if (!secret) {
24
+ throw new Error(`${BUILDER_RELAY_SECRET_ENV} is required for Builder preview authorization relay.`);
25
+ }
26
+ if (secret.length < 32) {
27
+ throw new Error(`${BUILDER_RELAY_SECRET_ENV} must be at least 32 characters long.`);
28
+ }
29
+ return secret;
30
+ }
31
+ function builderRelayMac(value) {
32
+ return createHmac("sha256", builderRelaySecret())
33
+ .update(value)
34
+ .digest("base64url");
35
+ }
36
+ function safeEqualText(expected, actual) {
37
+ const expectedBuffer = Buffer.from(expected);
38
+ const actualBuffer = Buffer.from(actual);
39
+ return (expectedBuffer.length === actualBuffer.length &&
40
+ timingSafeEqual(expectedBuffer, actualBuffer));
41
+ }
42
+ function normalizeBuilderRelayBasePath(value) {
43
+ if (!value)
44
+ return "";
45
+ if (!value.startsWith("/") || value.includes("?") || value.includes("#")) {
46
+ return null;
47
+ }
48
+ const normalized = value.replace(/\/+$/, "");
49
+ if (normalized.split("/").some((part) => part === "." || part === "..")) {
50
+ return null;
51
+ }
52
+ return normalized;
53
+ }
54
+ export function isSafeBuilderRelayTargetOrigin(value) {
55
+ try {
56
+ const url = new URL(value);
57
+ if (url.origin !== value ||
58
+ url.username ||
59
+ url.password ||
60
+ url.hostname.includes("*"))
61
+ return false;
62
+ const hostname = url.hostname.toLowerCase();
63
+ const loopback = hostname === "localhost" ||
64
+ hostname === "127.0.0.1" ||
65
+ hostname === "::1" ||
66
+ hostname === "[::1]";
67
+ if (loopback)
68
+ return url.protocol === "http:" && process.env.NODE_ENV !== "production";
69
+ if (url.protocol !== "https:")
70
+ return false;
71
+ return (hostname.endsWith(".netlify.app") ||
72
+ hostname.endsWith(".vercel.app") ||
73
+ hostname === "agent-native.com" ||
74
+ hostname.endsWith(".agent-native.com") ||
75
+ hostname.endsWith(".builder.io") ||
76
+ hostname.endsWith(".builderio.xyz") ||
77
+ hostname.endsWith(".builderio.dev") ||
78
+ hostname.endsWith(".builder.codes"));
79
+ }
80
+ catch {
81
+ return false;
82
+ }
83
+ }
84
+ export function isTrustedBuilderRelayTargetOrigin(value) {
85
+ if (!isSafeBuilderRelayTargetOrigin(value))
86
+ return false;
87
+ const hostname = new URL(value).hostname.toLowerCase();
88
+ if (hostname.endsWith(".netlify.app") &&
89
+ !/^[a-f0-9]{24}--[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.netlify\.app$/.test(hostname)) {
90
+ return false;
91
+ }
92
+ const configured = process.env[BUILDER_RELAY_TARGET_ORIGINS_ENV];
93
+ if (!configured)
94
+ return false;
95
+ return configured
96
+ .split(",")
97
+ .map((origin) => origin.trim())
98
+ .filter(Boolean)
99
+ .some((origin) => origin === value && !origin.includes("*"));
100
+ }
101
+ export function signBuilderPreviewRelayState(input) {
102
+ if (!isSafeBuilderRelayTargetOrigin(input.targetOrigin)) {
103
+ throw new Error("Builder relay target origin is not an approved preview origin.");
104
+ }
105
+ const basePath = normalizeBuilderRelayBasePath(input.basePath ?? "");
106
+ if (basePath === null)
107
+ throw new Error("Builder relay base path is invalid.");
108
+ const now = input.now ?? Date.now();
109
+ const payload = {
110
+ v: BUILDER_RELAY_STATE_VERSION,
111
+ purpose: BUILDER_RELAY_PURPOSE,
112
+ flowId: input.flowId ?? randomBytes(24).toString("base64url"),
113
+ ownerEmail: input.ownerEmail,
114
+ targetOrigin: input.targetOrigin,
115
+ basePath,
116
+ iat: now,
117
+ exp: now + BUILDER_RELAY_TTL_MS,
118
+ };
119
+ const encoded = Buffer.from(JSON.stringify(payload), "utf8").toString("base64url");
120
+ return { state: `${encoded}.${builderRelayMac(encoded)}`, payload };
121
+ }
122
+ export function verifyBuilderPreviewRelayState(state, options = {}) {
123
+ if (!state)
124
+ return null;
125
+ const parts = state.split(".");
126
+ if (parts.length !== 2 || !parts[0] || !parts[1])
127
+ return null;
128
+ if (!safeEqualText(builderRelayMac(parts[0]), parts[1]))
129
+ return null;
130
+ let value;
131
+ try {
132
+ value = JSON.parse(Buffer.from(parts[0], "base64url").toString("utf8"));
133
+ }
134
+ catch {
135
+ return null;
136
+ }
137
+ if (!value || typeof value !== "object")
138
+ return null;
139
+ const payload = value;
140
+ const now = options.now ?? Date.now();
141
+ if (payload.v !== BUILDER_RELAY_STATE_VERSION ||
142
+ payload.purpose !== BUILDER_RELAY_PURPOSE ||
143
+ typeof payload.flowId !== "string" ||
144
+ !/^[A-Za-z0-9_-]{24,128}$/.test(payload.flowId) ||
145
+ typeof payload.ownerEmail !== "string" ||
146
+ !payload.ownerEmail.includes("@") ||
147
+ typeof payload.targetOrigin !== "string" ||
148
+ !isSafeBuilderRelayTargetOrigin(payload.targetOrigin) ||
149
+ typeof payload.basePath !== "string" ||
150
+ normalizeBuilderRelayBasePath(payload.basePath) !== payload.basePath ||
151
+ typeof payload.iat !== "number" ||
152
+ typeof payload.exp !== "number" ||
153
+ payload.exp <= payload.iat ||
154
+ payload.exp - payload.iat > BUILDER_RELAY_TTL_MS ||
155
+ payload.iat > now + BUILDER_RELAY_REQUEST_SKEW_MS ||
156
+ payload.exp < now) {
157
+ return null;
158
+ }
159
+ return payload;
160
+ }
161
+ /**
162
+ * Corporate callback trust check. Preview-side state verification and relay
163
+ * receipt deliberately do not require this callback-only allowlist.
164
+ */
165
+ export function verifyBuilderPreviewRelayStateForCallback(state, options = {}) {
166
+ const payload = verifyBuilderPreviewRelayState(state, options);
167
+ return payload && isTrustedBuilderRelayTargetOrigin(payload.targetOrigin)
168
+ ? payload
169
+ : null;
170
+ }
171
+ export function getBuilderPreviewRelayUrl(payload) {
172
+ return `${payload.targetOrigin}${payload.basePath}${BUILDER_RELAY_PATH}`;
173
+ }
174
+ function builderRelayBodyDigest(body) {
175
+ return createHash("sha256").update(body).digest("base64url");
176
+ }
177
+ function builderRelayRequestSignature(timestamp, flowId, body) {
178
+ return builderRelayMac(`v1.${timestamp}.${flowId}.${builderRelayBodyDigest(body)}`);
179
+ }
180
+ export function createBuilderRelayRequest(relayState, credentials, options = {}) {
181
+ const payload = verifyBuilderPreviewRelayState(relayState, options);
182
+ if (!payload)
183
+ throw new Error("Builder relay state is invalid or expired.");
184
+ const body = JSON.stringify({
185
+ relayState,
186
+ credentials,
187
+ });
188
+ const timestamp = options.now ?? Date.now();
189
+ return {
190
+ body,
191
+ url: getBuilderPreviewRelayUrl(payload),
192
+ headers: {
193
+ "content-type": "application/json",
194
+ [BUILDER_RELAY_TIMESTAMP_HEADER]: String(timestamp),
195
+ [BUILDER_RELAY_FLOW_HEADER]: payload.flowId,
196
+ [BUILDER_RELAY_SIGNATURE_HEADER]: builderRelayRequestSignature(timestamp, payload.flowId, body),
197
+ },
198
+ };
199
+ }
200
+ export function verifyBuilderRelayRequest(input) {
201
+ const timestamp = Number(input.timestamp);
202
+ const now = input.now ?? Date.now();
203
+ if (!Number.isFinite(timestamp) ||
204
+ Math.abs(now - timestamp) > BUILDER_RELAY_REQUEST_SKEW_MS ||
205
+ !input.flowId ||
206
+ !input.signature ||
207
+ !safeEqualText(builderRelayRequestSignature(timestamp, input.flowId, input.body), input.signature)) {
208
+ return null;
209
+ }
210
+ let body;
211
+ try {
212
+ body = JSON.parse(input.body);
213
+ }
214
+ catch {
215
+ return null;
216
+ }
217
+ const payload = verifyBuilderPreviewRelayState(body.relayState, { now });
218
+ if (!payload ||
219
+ payload.flowId !== input.flowId ||
220
+ payload.targetOrigin !== input.requestOrigin ||
221
+ payload.basePath !== input.requestBasePath ||
222
+ !body.credentials ||
223
+ typeof body.credentials.privateKey !== "string" ||
224
+ typeof body.credentials.publicKey !== "string" ||
225
+ !body.credentials.privateKey ||
226
+ !body.credentials.publicKey) {
227
+ return null;
228
+ }
229
+ const nullableString = (value) => typeof value === "string" ? value : null;
230
+ const nullableBoolean = (value) => typeof value === "boolean" ? value : null;
231
+ return {
232
+ payload,
233
+ body: {
234
+ relayState: body.relayState,
235
+ // Explicitly rebuild the credential payload. Extra fields such as an
236
+ // attacker-supplied ownerEmail/orgId never reach the credential writer.
237
+ credentials: {
238
+ privateKey: body.credentials.privateKey,
239
+ publicKey: body.credentials.publicKey,
240
+ userId: nullableString(body.credentials.userId),
241
+ orgName: nullableString(body.credentials.orgName),
242
+ orgKind: nullableString(body.credentials.orgKind),
243
+ subscription: nullableString(body.credentials.subscription),
244
+ subscriptionLevel: nullableString(body.credentials.subscriptionLevel),
245
+ subscriptionName: nullableString(body.credentials.subscriptionName),
246
+ isEnterprise: nullableBoolean(body.credentials.isEnterprise),
247
+ isFreeAccount: nullableBoolean(body.credentials.isFreeAccount),
248
+ },
249
+ },
250
+ };
251
+ }
10
252
  function escapeHtml(value) {
11
253
  return value.replace(/[&<>"']/g, (ch) => {
12
254
  switch (ch) {
@@ -377,6 +619,9 @@ export function buildBuilderCliAuthUrl(callbackOrigin, state = null, options = {
377
619
  if (state) {
378
620
  callbackUrl.searchParams.set(BUILDER_STATE_PARAM, state);
379
621
  }
622
+ if (options.relayState) {
623
+ callbackUrl.searchParams.set(BUILDER_RELAY_STATE_PARAM, options.relayState);
624
+ }
380
625
  // When the cli-auth allow-list forces preview_url onto the gateway origin,
381
626
  // the callback would otherwise lose the real opener origin and post its
382
627
  // success message to the gateway instead of the preview tab. Embed the