@jini-ai/agent-plugins 0.7.3-next.2 → 0.7.3-next.3

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 (231) hide show
  1. package/README.md +22 -4
  2. package/calendly/README.md +29 -0
  3. package/calendly/mcp.json +1 -1
  4. package/cloudflare/lib/assets.mjs +1 -1
  5. package/cloudflare/lib/cms-forms.mjs +1 -1
  6. package/core/persistent-state.d.ts +4 -1
  7. package/core/persistent-state.js +55 -21
  8. package/dist/admin-surfaces/callback-field-inbox.d.ts +1 -6
  9. package/dist/admin-surfaces/connections/connections.d.ts +2 -6
  10. package/dist/admin-surfaces/connections/index.d.ts +3 -2
  11. package/dist/admin-surfaces/index.d.ts +3 -1
  12. package/dist/connect/access-token-tool.d.ts +1 -1
  13. package/dist/connect/access-token-tool.js +1 -1
  14. package/dist/connect/catalog.d.ts +26 -0
  15. package/dist/connect/catalog.js +42 -0
  16. package/dist/connect/connect-tool.d.ts +2 -294
  17. package/dist/connect/connect-tool.js +2 -53
  18. package/dist/connect/contracts.d.ts +257 -0
  19. package/dist/connect/contracts.js +2 -0
  20. package/dist/connect/credential-cards.d.ts +2 -0
  21. package/dist/connect/credential-cards.js +7 -4
  22. package/dist/connect/grant-signed-in-defaults.js +1 -1
  23. package/dist/connect/host-deps.d.ts +32 -0
  24. package/dist/connect/host-deps.js +35 -0
  25. package/dist/connect/import-access-token.js +1 -1
  26. package/dist/connect/index.d.ts +7 -2
  27. package/dist/connect/index.js +5 -2
  28. package/dist/connect/installed-plugin.d.ts +28 -0
  29. package/dist/connect/installed-plugin.js +19 -0
  30. package/dist/connect/new-site-agent-plugin-tokens.d.ts +88 -0
  31. package/dist/connect/new-site-agent-plugin-tokens.js +107 -0
  32. package/dist/connect/plugin-host/index.d.ts +1 -2
  33. package/dist/connect/plugin-host/index.js +18 -9
  34. package/dist/connect/token-sign-in.d.ts +1 -14
  35. package/dist/connect/token-sign-in.js +4 -23
  36. package/dist/core/export-props.d.ts +10 -0
  37. package/dist/core/export-props.js +31 -0
  38. package/dist/core/folder-zip-error.d.ts +5 -0
  39. package/dist/core/folder-zip-error.js +8 -0
  40. package/dist/core/host-incompatible-error.d.ts +8 -0
  41. package/dist/core/host-incompatible-error.js +9 -0
  42. package/dist/core/identity-namespace.d.ts +27 -16
  43. package/dist/core/identity-namespace.js +25 -22
  44. package/dist/core/plugin-display-name.d.ts +7 -0
  45. package/dist/core/plugin-display-name.js +11 -0
  46. package/dist/core/provider-plugin-link.d.ts +7 -0
  47. package/dist/core/provider-plugin-link.js +5 -0
  48. package/dist/{connect → core}/token-map.d.ts +11 -1
  49. package/dist/{connect → core}/token-map.js +15 -0
  50. package/dist/core/token-sign-in-list.d.ts +18 -0
  51. package/dist/core/token-sign-in-list.js +23 -0
  52. package/dist/core/update-error.d.ts +8 -0
  53. package/dist/core/update-error.js +9 -0
  54. package/dist/{lifecycle → core}/update-plan.d.ts +1 -1
  55. package/dist/ffmpeg-transcode/adapter.d.ts +74 -0
  56. package/dist/ffmpeg-transcode/adapter.js +155 -0
  57. package/dist/folder-zip-node.d.ts +2 -1
  58. package/dist/folder-zip-node.js +6 -5
  59. package/dist/folder-zip.d.ts +0 -4
  60. package/dist/folder-zip.js +1 -7
  61. package/dist/index.d.ts +3 -1
  62. package/dist/lifecycle/activation.d.ts +39 -3
  63. package/dist/lifecycle/activation.js +467 -418
  64. package/dist/lifecycle/automatic-use-offer.d.ts +62 -0
  65. package/dist/lifecycle/automatic-use-offer.js +52 -0
  66. package/dist/lifecycle/automatic-use.d.ts +33 -1
  67. package/dist/lifecycle/automatic-use.js +157 -38
  68. package/dist/lifecycle/bundled-source-archive.d.ts +1 -1
  69. package/dist/lifecycle/capability-projection.d.ts +0 -1
  70. package/dist/lifecycle/capability-projection.js +92 -23
  71. package/dist/lifecycle/compatibility-metadata.d.ts +1 -0
  72. package/dist/lifecycle/compatibility-metadata.js +6 -1
  73. package/dist/lifecycle/compatibility.d.ts +1 -8
  74. package/dist/lifecycle/compatibility.js +1 -8
  75. package/dist/lifecycle/credential-card-metadata.d.ts +2 -2
  76. package/dist/lifecycle/exports.d.ts +2 -45
  77. package/dist/lifecycle/exports.js +1 -30
  78. package/dist/lifecycle/host-tools/identity.d.ts +5 -4
  79. package/dist/lifecycle/host-tools/identity.js +5 -5
  80. package/dist/lifecycle/host-tools/ports.d.ts +10 -1
  81. package/dist/lifecycle/host-tools/search-tool.js +18 -8
  82. package/dist/lifecycle/host-tools/skill-tool.js +1 -1
  83. package/dist/lifecycle/index.d.ts +20 -17
  84. package/dist/lifecycle/index.js +5 -4
  85. package/dist/lifecycle/install-from-url.d.ts +1 -2
  86. package/dist/lifecycle/install.d.ts +4 -34
  87. package/dist/lifecycle/install.js +3 -3
  88. package/dist/lifecycle/installed-package-index.d.ts +1 -1
  89. package/dist/lifecycle/installed-package-index.js +4 -4
  90. package/dist/lifecycle/layout.d.ts +21 -25
  91. package/dist/lifecycle/layout.js +79 -0
  92. package/dist/lifecycle/manifest.d.ts +10 -7
  93. package/dist/lifecycle/manifest.js +20 -15
  94. package/dist/lifecycle/mcp-provisioning.d.ts +1 -1
  95. package/dist/lifecycle/metadata.d.ts +6 -3
  96. package/dist/lifecycle/metadata.js +2 -1
  97. package/dist/lifecycle/package-paths.js +59 -56
  98. package/dist/lifecycle/persistent-state.d.ts +10 -1
  99. package/dist/lifecycle/persistent-state.js +4 -2
  100. package/dist/lifecycle/ports.d.ts +18 -6
  101. package/dist/lifecycle/resolve-agent-plugin-refs.d.ts +2 -14
  102. package/dist/lifecycle/retire-bundled.d.ts +1 -1
  103. package/dist/lifecycle/search-projection.d.ts +3 -1
  104. package/dist/lifecycle/search-projection.js +7 -3
  105. package/dist/lifecycle/search.d.ts +1 -0
  106. package/dist/lifecycle/seed-bundled.d.ts +86 -1
  107. package/dist/lifecycle/seed-bundled.js +48 -84
  108. package/dist/lifecycle/set-enabled.d.ts +1 -13
  109. package/dist/lifecycle/set-enabled.js +11 -7
  110. package/dist/lifecycle/trusted-plugin-files.d.ts +1 -1
  111. package/dist/lifecycle/trusted-plugin-files.js +33 -30
  112. package/dist/lifecycle/types.d.ts +13 -34
  113. package/dist/lifecycle/uninstall.d.ts +1 -33
  114. package/dist/lifecycle/update-store.d.ts +0 -7
  115. package/dist/lifecycle/update-store.js +1 -8
  116. package/dist/lifecycle/update.d.ts +1 -1
  117. package/dist/lifecycle/update.js +60 -10
  118. package/dist/lifecycle/yauzl-archive-reader.d.ts +7 -2
  119. package/dist/lifecycle/yauzl-archive-reader.js +11 -6
  120. package/dist/manifest.d.ts +4 -8
  121. package/dist/react/AgentPluginDetailsModal.d.ts +187 -0
  122. package/dist/react/AgentPluginDetailsModal.js +29 -0
  123. package/dist/react/agent-plugin-install-port.d.ts +24 -0
  124. package/dist/react/agent-plugin-install-port.js +15 -0
  125. package/dist/react/installed-skills-composer-source.d.ts +60 -0
  126. package/dist/react/installed-skills-composer-source.js +111 -0
  127. package/dist/react/use-agent-plugins.hooks.d.ts +211 -0
  128. package/dist/react/use-agent-plugins.hooks.js +128 -0
  129. package/dist/site/activation-effects.d.ts +17 -0
  130. package/dist/site/activation-effects.js +31 -0
  131. package/dist/site/admin-surfaces/capabilities.d.ts +29 -0
  132. package/dist/site/admin-surfaces/capabilities.js +30 -0
  133. package/dist/site/admin-surfaces/delivery-bindings.d.ts +81 -0
  134. package/dist/site/admin-surfaces/delivery-bindings.js +161 -0
  135. package/dist/site/admin-surfaces/forms.d.ts +28 -0
  136. package/dist/site/admin-surfaces/forms.js +29 -0
  137. package/dist/site/admin-surfaces/handlers.d.ts +61 -0
  138. package/dist/site/admin-surfaces/handlers.js +35 -0
  139. package/dist/site/admin-surfaces/public-config.d.ts +12 -0
  140. package/dist/site/admin-surfaces/public-config.js +28 -0
  141. package/dist/site/analytics-provider-registry.d.ts +87 -0
  142. package/dist/site/analytics-provider-registry.js +87 -0
  143. package/dist/site/archive-reader-abi.d.ts +35 -0
  144. package/dist/site/archive-reader-abi.js +25 -0
  145. package/dist/site/auth-schemes.d.ts +110 -0
  146. package/dist/site/auth-schemes.js +119 -0
  147. package/dist/site/automatic-agent-plugins.d.ts +200 -0
  148. package/dist/site/automatic-agent-plugins.js +277 -0
  149. package/dist/site/bundled-contribution-sources.d.ts +24 -0
  150. package/dist/site/bundled-contribution-sources.js +17 -0
  151. package/dist/site/bundled-id-upgrade.d.ts +115 -0
  152. package/dist/site/bundled-id-upgrade.js +169 -0
  153. package/dist/site/customize-tool.d.ts +39 -0
  154. package/dist/site/customize-tool.js +31 -0
  155. package/dist/site/deploy-split-activation.d.ts +28 -0
  156. package/dist/site/deploy-split-activation.js +21 -0
  157. package/dist/site/exports/diagnostics.d.ts +37 -0
  158. package/dist/site/exports/diagnostics.js +55 -0
  159. package/dist/site/exports/runtime.d.ts +54 -0
  160. package/dist/site/exports/runtime.js +196 -0
  161. package/dist/site/exports/source.d.ts +42 -0
  162. package/dist/site/exports/source.js +58 -0
  163. package/dist/site/host-plugin-guidance.d.ts +137 -0
  164. package/dist/site/host-plugin-guidance.js +223 -0
  165. package/dist/site/host-signals.d.ts +78 -0
  166. package/dist/site/host-signals.js +83 -0
  167. package/dist/site/install-tool.d.ts +69 -0
  168. package/dist/site/install-tool.js +192 -0
  169. package/dist/site/install-upload.d.ts +175 -0
  170. package/dist/site/install-upload.js +324 -0
  171. package/dist/site/memory-i18n.d.ts +5 -0
  172. package/dist/site/memory-i18n.js +176 -0
  173. package/dist/site/memory.d.ts +80 -0
  174. package/dist/site/memory.js +83 -0
  175. package/dist/site/plugin-memory.d.ts +80 -0
  176. package/dist/site/plugin-memory.js +86 -0
  177. package/dist/site/provider-plugin-link.d.ts +112 -0
  178. package/dist/site/provider-plugin-link.js +100 -0
  179. package/dist/site/retired-plugin-tool-aliases.d.ts +40 -0
  180. package/dist/site/retired-plugin-tool-aliases.js +41 -0
  181. package/dist/site/service-ports.d.ts +108 -0
  182. package/dist/site/service-ports.js +2 -0
  183. package/dist/site/set-enabled.d.ts +80 -0
  184. package/dist/site/set-enabled.js +42 -0
  185. package/dist/site/soon-lock.d.ts +83 -0
  186. package/dist/site/soon-lock.js +78 -0
  187. package/dist/site/supersession.d.ts +61 -0
  188. package/dist/site/supersession.js +122 -0
  189. package/dist/site/uninstall-tool.d.ts +136 -0
  190. package/dist/site/uninstall-tool.js +203 -0
  191. package/dist/site/update-effects.d.ts +47 -0
  192. package/dist/site/update-effects.js +49 -0
  193. package/ffmpeg-transcode/plugin.json +16 -0
  194. package/github/source-control/backup-push.mjs +66 -46
  195. package/github/source-control/commit-site.mjs +112 -65
  196. package/github/source-control/write-files.mjs +86 -53
  197. package/github-pages/targets/github-pages.mjs +294 -233
  198. package/google-workspace/form-destinations/mapping.mjs +15 -7
  199. package/google-workspace/form-destinations/sheets.mjs +4 -2
  200. package/google-workspace/plugin.json +1 -0
  201. package/kuinetic/CHANGELOG.md +4 -0
  202. package/kuinetic/plugin.json +4 -1
  203. package/kuinetic/skills/kuinetic/SKILL.md +1 -2
  204. package/package.json +295 -18
  205. package/persistent-state.d.ts +4 -1
  206. package/resend/adapters/resend.mjs +5 -2
  207. package/resend/plugin.json +1 -1
  208. package/s3-compatible/jini-deploy-targets.json +1 -1
  209. package/s3-compatible/object-stores/s3-compatible.mjs +27 -4
  210. package/s3-compatible/targets/s3-compatible.mjs +3 -3
  211. package/site-import/plugin.json +3 -3
  212. package/site-import/skills/site-import/SKILL.md +62 -54
  213. package/site-import/skills/site-import/references/content-mapping.md +26 -20
  214. package/slide-design/plugin.json +1 -1
  215. package/slide-design/skills/slide-design/SKILL.md +8 -2
  216. package/ui-ux-design/CHANGELOG.md +6 -0
  217. package/ui-ux-design/plugin.json +1 -1
  218. package/ui-ux-design/skills/gstack-design/SKILL.md +6 -6
  219. package/ui-ux-design/skills/ui-ux-design/SKILL.md +3 -2
  220. package/ui-ux-design/skills/ui-ux-design/references/chrome-mobile-test-matrix.md +14 -12
  221. package/ui-ux-design/skills/ui-ux-design/references/ui-loop.md +16 -17
  222. package/vercel/NOTES.md +2 -1
  223. package/vercel/object-stores/vercel-blob.mjs +3 -4
  224. package/vercel/targets/vercel.mjs +425 -351
  225. package/core/commerce-server.d.ts +0 -2
  226. package/core/commerce-server.mjs +0 -2
  227. package/dist/admin-surfaces/connections/ports.d.ts +0 -110
  228. package/dist/admin-surfaces/connections/ports.js +0 -2
  229. /package/dist/{lifecycle → core}/install-errors.d.ts +0 -0
  230. /package/dist/{lifecycle → core}/install-errors.js +0 -0
  231. /package/dist/{lifecycle → core}/update-plan.js +0 -0
@@ -76,131 +76,172 @@ function vercelFileManifest(files) {
76
76
  return { refs, blobs };
77
77
  }
78
78
 
79
+ const VERCEL_API = 'https://api.vercel.com';
80
+ const VERCEL_PROTECTED_MESSAGE = 'Deployment is protected by Vercel. Disable Deployment Protection or use a custom domain to make this link public.';
81
+
82
+ /** Preserve accepted deployment facts on verification failures; known build errors still reject.
83
+ * @complexity O(message bytes), no I/O; reuses the confirmed progress snapshot.
84
+ */
85
+ function publishFailure({ progress, name, error, token, DeployError }, _options = {}) {
86
+ // An existing deployment remains a real provider fact even if polling/reachability fails.
87
+ if (progress.deploymentCreated === true && progress.providerStatus !== 'ERROR') return unfinishedDeployment({ progress, name, error, token });
88
+ const detail = safeFailureMessage({ error, token });
89
+ throw new DeployError(`${detail} ${publishFacts({ progress })} ${retryGuidance({ progress, name })}`, error?.status ?? 502);
90
+ }
91
+
92
+ /** Map a verified public link without changing the provider's deployment identity. */
93
+ function publishedResult({ link, ready, initialUrl, deploymentId }, _options = {}) {
94
+ return { targetId: VERCEL_TARGET_ID, url: link.url || deploymentUrl(ready) || initialUrl,
95
+ ...(deploymentId ? { deploymentId } : {}), status: link.status, statusMessage: link.statusMessage,
96
+ ...(link.reachableAt !== undefined ? { reachableAt: link.reachableAt } : {}) };
97
+ }
98
+
99
+ /** Only confirmed, value-free facts cross the failure boundary; no raw upstream body.
100
+ * @complexity O(1) formatting, independent of export bytes.
101
+ */
102
+ function publishFacts({ progress }, _options = {}) {
103
+ const created = progress.deploymentCreated === true ? 'created' : progress.deploymentCreated === false ? 'not created' : 'unknown';
104
+ return `Deployment: ${created}. ${progress.uploadedFiles} of ${progress.totalFiles} distinct files uploaded this attempt; ${progress.reusedFiles} already stored. Deployment ID: ${progress.deploymentId ?? 'unknown'}; URL: ${progress.url || 'unknown'}; provider status: ${progress.providerStatus ?? 'unknown'}.`;
105
+ }
106
+
107
+ function retryGuidance({ progress, name }, _options = {}) {
108
+ if (progress.deploymentCreated !== false) return `Check deployment ${progress.deploymentId ?? ''} in the Vercel dashboard for project '${name}' before publishing again. A public site's 200 can belong to the previous deployment.`;
109
+ return 'Retry the publish to upload only missing hashes; acknowledged files are reused.';
110
+ }
111
+
112
+ function safeFailureMessage({ error, token }, _options = {}) {
113
+ return String(error?.message ?? 'Vercel did not finish the request.').split(token).join('[redacted]');
114
+ }
115
+
116
+ /** Accepted deployment with incomplete verification: retain its own URL, never prove it with
117
+ * an old production alias. Known provider errors remain failed rather than becoming a timeout.
118
+ */
119
+ function unfinishedDeployment({ progress, name, error, token }, _options = {}) {
120
+ const fallback = progress.providerStatus === 'ERROR' ? 'Vercel deployment failed.' : 'Vercel has not confirmed this deployment is ready yet.';
121
+ const detail = error ? safeFailureMessage({ error, token }) : fallback;
122
+ return { targetId: VERCEL_TARGET_ID, url: progress.url || '', deploymentId: progress.deploymentId,
123
+ status: progress.providerStatus === 'ERROR' ? 'failed' : 'link-delayed',
124
+ statusMessage: `${detail} ${publishFacts({ progress })} ${retryGuidance({ progress, name })}` };
125
+ }
126
+
127
+ function vercelTeamQuery(config) {
128
+ const params = new URLSearchParams();
129
+ if (config.teamId)
130
+ params.set('teamId', config.teamId);
131
+ else if (config.teamSlug)
132
+ params.set('slug', config.teamSlug);
133
+ else {
134
+ // Personal deployments need no team query parameter.
135
+ }
136
+ const s = params.toString();
137
+ return s ? `?${s}` : '';
138
+ }
139
+
79
140
  /**
80
- * Binds the ported Vercel code to one host kit.
81
- *
82
- * @param {{ fetch(url: string, init: RequestInit, options: { timeoutMs: number }): Promise<Response>,
83
- * timeouts: { QUICK: number, DEPLOY: number, UPLOAD: number }, sleep(ms: number): Promise<void> } & Record<string, any>} kit
84
- * The host's deploy kit in the positional ABI installed modules are written against (devops'
85
- * `DeployHostKit` helpers, called positionally; `DeployError` is `new (message, status?, details?)`).
86
- * @returns The target class (constructed with `{ token, teamId?, teamSlug? }`, as in devops) and the
87
- * protected-response detector.
141
+ * Derives a Vercel-safe project name from a caller-supplied label, falling
142
+ * back to a random id if the label sanitizes to nothing. Replaces the OD
143
+ * origin's hardcoded `od-${projectId}` convention.
88
144
  */
89
- export function bindVercel(kit, _optional = {}) {
90
- const { fetch: fetchWithTimeout, timeouts: FETCH_TIMEOUT_MS, sleep, DeployError, checkDeploymentUrl, normalizeDeploymentUrl, waitForReachableDeploymentUrl, safeProjectLabel, assertNotRedirected, redirectGuardInit } = kit;
91
- const VERCEL_TARGET_ID = 'vercel';
92
- const VERCEL_API = 'https://api.vercel.com';
93
- const VERCEL_PROTECTED_MESSAGE = 'Deployment is protected by Vercel. Disable Deployment Protection or use a custom domain to make this link public.';
94
- /**
95
- * Heuristically detects Vercel's own Deployment Protection auth wall from a
96
- * 401 response, so `checkReachability` can report `status: 'protected'`
97
- * (an actionable, non-error outcome) instead of `reachable: false` with a
98
- * generic message.
99
- *
100
- * @param resp - The HTTP response received from probing a deployment URL.
101
- * @param body - The response body (only read for 401s by the caller).
102
- * @returns `true` if the response looks like Vercel's SSO/auth gate.
103
- * @complexity O(1) — a handful of regex tests over already-fetched strings.
104
- * @overallScore 100/100
105
- */
106
- function isVercelProtectedResponse(resp, body = '') {
107
- const { server, setCookie } = protectionHeaders({ resp });
108
- const text = String(body || '');
109
- if (/vercel/i.test(server) || /_vercel_sso_nonce/i.test(setCookie)) return true;
110
- return /Authentication Required|Vercel Authentication|vercel\.com\/sso-api/i.test(text);
111
- }
112
- function protectionHeaders({ resp }, _options = {}) {
113
- return { server: resp.headers?.get?.('server') || '', setCookie: resp.headers?.get?.('set-cookie') || '' };
114
- }
115
- /**
116
- * `DeployTarget` adapter for Vercel's v13 deployments API. Publishes a
117
- * caller-supplied file set as a single deployment, polls until Vercel
118
- * reports a terminal `readyState`, then waits for the resulting URL to
119
- * become publicly reachable.
120
- *
121
- * Genericized from the origin product's daemon deploy module's
122
- * `deployToVercel`: the origin's product-specific deployment-name
123
- * convention is replaced by `input.projectName` (sanitized the same way);
124
- * token/team config is supplied by the caller instead of being read from a
125
- * product-owned local config file — persistence of that config is now the
126
- * caller's concern, not this package's.
127
- */
128
- class VercelDeployTarget {
129
- config;
130
- id = VERCEL_TARGET_ID;
131
- resolvedProjectName;
132
- resolvedPublicUrl;
133
- constructor(config) {
134
- this.config = config;
135
- }
136
- /** Resolve the host-assigned production domain before rendering. A first publish creates
137
- * the same project publish() would create, then reads its actual alias (names may collide).
138
- * @complexity At most three bounded API calls, at most 100 domain records; no file uploads.
139
- * @throws DeployError for refused/ambiguous inventories; never fabricates a public URL.
140
- */
141
- async resolvePublicUrl({ projectName }, _options = {}) {
142
- this.resolvedProjectName = safeVercelProjectName(projectName);
143
- this.resolvedPublicUrl = await resolveVercelPublicUrl({ config: this.config, name: this.resolvedProjectName });
144
- return this.resolvedPublicUrl;
145
- }
146
- /**
147
- * Publishes `input.files`, asking Vercel for missing hashes before uploading. The optional
148
- * synchronous `input.onProgress` receives credential-free counts and deployment facts.
149
- *
150
- * @param input - File set, project name, optional security headers and progress observer.
151
- * @returns The verified URL/status, or a partial result retaining the accepted deployment's
152
- * ID/URL and next steps when readiness cannot be confirmed.
153
- * @throws {DeployError} For a failed build or before a deployment is known to exist; includes confirmed
154
- * upload counts, whether creation is false/unknown, and how to safely continue.
155
- * @complexity O(files) to hash and upload them, plus a bounded poll loop
156
- * (`pollVercelDeployment`) and the reachability wait's own bound.
157
- * @overallScore 100/100
158
- */
159
- async publish(input) {
160
- if (!this.config.token) {
161
- throw new DeployError('Vercel token is required.', 400);
162
- }
163
- const { refs, blobs } = vercelFileManifest(withVercelConfigFile(input.files, input.responseHeaders));
164
- const name = this.resolvedProjectName ?? safeVercelProjectName(input.projectName);
165
- const progress = { phase: 'creating', totalFiles: blobs.size, uploadedFiles: 0, reusedFiles: 0, deploymentCreated: false };
166
- const report = patch => { Object.assign(progress, patch); input.onProgress?.({ ...progress }); };
167
- try {
168
- const created = await createUploadedVercelDeployment({ config: this.config, name, refs, blobs, report });
169
- const deploymentId = typeof created.id === 'string' ? created.id : created.uid;
170
- const initialUrl = deploymentUrl(created);
171
- report({ phase: 'polling', deploymentCreated: true, deploymentId, url: initialUrl, providerStatus: created.readyState ?? 'unknown' });
172
- const ready = await readyVercelDeployment({ config: this.config, deploymentId, created, report });
173
- if (ready?.readyState !== 'READY') return unfinishedDeployment({ progress, name });
174
- report({ phase: 'checking', providerStatus: 'READY' });
175
- const link = await publicVercelLink({ name, ready, created, initialUrl, publicUrl: this.resolvedPublicUrl });
176
- return publishedResult({ link, ready, initialUrl, deploymentId });
177
- } catch (error) {
178
- return publishFailure({ progress, name, error, token: this.config.token });
179
- }
145
+ function safeVercelProjectName(projectName, safeProjectLabel) {
146
+ return safeProjectLabel(projectName, 80) || `deploy-${randomInt(36 ** 8).toString(36).padStart(8, '0')}`;
147
+ }
148
+
149
+ function vercelErrorField({ json, field }, _options = {}) {
150
+ return json?.error && typeof json.error === 'object' ? json.error[field] : undefined;
151
+ }
152
+
153
+ function deploymentUrl(json) {
154
+ const url = json?.url || json?.alias?.[0] || '';
155
+ if (!url)
156
+ return '';
157
+ return /^https?:\/\//i.test(url) ? url : `https://${url}`;
158
+ }
159
+
160
+ function appendDeploymentAlias({ alias, urls }, _options = {}) {
161
+ if (typeof alias === 'string') {
162
+ urls.push(alias);
163
+ return;
164
+ }
165
+ if (alias && typeof alias === 'object') {
166
+ const a = alias;
167
+ if (typeof a.domain === 'string')
168
+ urls.push(a.domain);
169
+ else if (typeof a.url === 'string')
170
+ urls.push(a.url);
171
+ else {
172
+ // Objects without a domain or URL are not deployment aliases.
173
+ }
174
+ }
175
+ }
176
+
177
+ function appendDeploymentAliases({ json, urls }, _options = {}) {
178
+ for (const alias of json.alias ?? []) {
179
+ if (typeof alias === 'string')
180
+ urls.push(alias);
181
+ }
182
+ for (const alias of json.aliases ?? []) {
183
+ appendDeploymentAlias({ alias, urls });
184
+ }
185
+ }
186
+
187
+ /**
188
+ * `if (!json) continue` skips a response that is not there. Of this file's one call site,
189
+ * `deploymentUrlCandidates(normalizeDeploymentUrl, publicHost, ready, created)` in `publish()`, `created` is always a parsed
190
+ * `JsonObject` (`readVercelJson` returns one or throws), but `ready` is `null` when every one of
191
+ * `pollVercelDeployment`'s 30 status reads was unparseable (each such read is skipped with
192
+ * `continue`, so `last` is never assigned) — then only `created` supplies candidates. Same guard
193
+ * `netlify.ts`'s own `netlifyUrlCandidates` keeps for the same reason.
194
+ */
195
+ function deploymentUrlCandidates(normalizeDeploymentUrl, publicHost, ...responses) {
196
+ // Aliases (the production `<project>.vercel.app` among them) are tried before `url`: `url` is the
197
+ // per-deployment address, which Deployment Protection puts behind Vercel's login by default.
198
+ const urls = [];
199
+ const deploymentUrls = [];
200
+ for (const json of responses) {
201
+ if (!json)
202
+ continue;
203
+ if (typeof json.url === 'string')
204
+ deploymentUrls.push(json.url);
205
+ appendDeploymentAliases({ json, urls });
206
+ }
207
+ const candidates = [...new Set([...urls, ...deploymentUrls].map(normalizeDeploymentUrl).filter(Boolean))];
208
+ // The public `<project>.vercel.app` alias goes first when Vercel lists it. Vercel orders aliases
209
+ // its own way, so the team-scoped `<project>-<team>.vercel.app` (behind Deployment Protection)
210
+ // can come first, and the reachability wait stops at the first `protected` answer: a publish
211
+ // whose public alias served 200 was reported `protected` (2026-10-11).
212
+ const publicUrl = normalizeDeploymentUrl(publicHost);
213
+ return candidates.includes(publicUrl) ? [publicUrl, ...candidates.filter((url) => url !== publicUrl)] : candidates;
214
+ }
215
+
216
+ function protectionHeaders({ resp }, _options = {}) {
217
+ return { server: resp.headers?.get?.('server') || '', setCookie: resp.headers?.get?.('set-cookie') || '' };
218
+ }
219
+
220
+ function createVercelResponseReaders(DeployError) {
221
+ async function readVercelJson(resp) {
222
+ try {
223
+ return (await resp.json());
180
224
  }
181
- /** Probes `url`, recognizing Vercel's own Deployment Protection auth wall. */
182
- async checkReachability(url) {
183
- return checkDeploymentUrl(url, {
184
- detectProtected: isVercelProtectedResponse,
185
- protectedMessage: VERCEL_PROTECTED_MESSAGE,
186
- });
225
+ catch {
226
+ throw new DeployError('Vercel returned a non-JSON response.', resp.status || 502);
187
227
  }
188
228
  }
189
- /** Preserve accepted deployment facts on verification failures; known build errors still reject.
190
- * @complexity O(message bytes), no I/O; reuses the confirmed progress snapshot.
191
- */
192
- function publishFailure({ progress, name, error, token }, _options = {}) {
193
- // An existing deployment remains a real provider fact even if polling/reachability fails.
194
- if (progress.deploymentCreated === true && progress.providerStatus !== 'ERROR') return unfinishedDeployment({ progress, name, error, token });
195
- const detail = safeFailureMessage({ error, token });
196
- throw new DeployError(`${detail} ${publishFacts({ progress })} ${retryGuidance({ progress, name })}`, error?.status ?? 502);
197
- }
198
- /** Map a verified public link without changing the provider's deployment identity. */
199
- function publishedResult({ link, ready, initialUrl, deploymentId }, _options = {}) {
200
- return { targetId: VERCEL_TARGET_ID, url: link.url || deploymentUrl(ready) || initialUrl,
201
- ...(deploymentId ? { deploymentId } : {}), status: link.status, statusMessage: link.statusMessage,
202
- ...(link.reachableAt !== undefined ? { reachableAt: link.reachableAt } : {}) };
229
+
230
+ function vercelError(json, status) {
231
+ const code = vercelErrorField({ json, field: 'code' });
232
+ const message = vercelErrorField({ json, field: 'message' }) ||
233
+ json?.message ||
234
+ `Vercel request failed (${status}).`;
235
+ if (code === 'forbidden' || /permission/i.test(String(message))) {
236
+ return new DeployError("You don't have permission to create a project.", status, json);
237
+ }
238
+ return new DeployError(String(message), status, json);
203
239
  }
240
+
241
+ return { readVercelJson, vercelError };
242
+ }
243
+
244
+ function createVercelDomainResolver({ fetchWithTimeout, FETCH_TIMEOUT_MS, assertNotRedirected, redirectGuardInit, DeployError, readVercelJson, vercelError }) {
204
245
  /** Read the provider's production-only, verified, nonredirecting domains. Refuse a partial
205
246
  * inventory rather than select a different canonical URL on different pages of the result.
206
247
  * @complexity One bounded request; response limited to 100 records by the provider.
@@ -210,6 +251,7 @@ export function bindVercel(kit, _optional = {}) {
210
251
  for (const [key, value] of Object.entries({ production: 'true', redirects: 'false', verified: 'true', limit: '100' })) url.searchParams.set(key, value);
211
252
  return fetchWithTimeout(url.href, redirectGuardInit({ method: 'GET', headers: { Authorization: `Bearer ${config.token}` } }), { timeoutMs: FETCH_TIMEOUT_MS.QUICK });
212
253
  }
254
+
213
255
  /** Provision only after an authoritative not-found response; permission/network failures never create.
214
256
  * @complexity One POST with the same project name and framework as the existing publish request.
215
257
  */
@@ -221,6 +263,7 @@ export function bindVercel(kit, _optional = {}) {
221
263
  const body = await readVercelJson(response);
222
264
  if (!response.ok) throw vercelError(body, response.status);
223
265
  }
266
+
224
267
  /** Actual domain evidence, never a name-derived hostname; preparation stays inside this provider.
225
268
  * @complexity At most three API requests and O(domains), capped at 100; errors propagate.
226
269
  */
@@ -237,6 +280,7 @@ export function bindVercel(kit, _optional = {}) {
237
280
  if (!response.ok) throw vercelError(body, response.status);
238
281
  return publicDomainUrl({ body, name });
239
282
  }
283
+
240
284
  /** Select a complete, bounded inventory. Missing evidence is a refusal, never a guessed alias.
241
285
  * @complexity O(domains), capped at 100 records; pure, throws DeployError for missing evidence.
242
286
  */
@@ -245,154 +289,14 @@ export function bindVercel(kit, _optional = {}) {
245
289
  if (body.pagination?.next != null || entries.length > 100) throw new DeployError('Public domain inventory exceeds 100 domains; choose a smaller destination.', 400);
246
290
  const domains = entries.filter(domain => domain.verified === true && !domain.redirect && !domain.gitBranch && typeof domain.name === 'string');
247
291
  const domain = domains.find(domain => domain.name === `${name}.vercel.app`) ?? domains[0];
248
- if (!domain) throw new DeployError('Vercel did not report a verified public domain for this project.', 400);
249
- return `https://${domain.name}`;
250
- }
251
- /** Let the provider's content store select missing hashes before sending bytes. A retry on
252
- * another target/process reuses provider acknowledgements, including a prior partial upload.
253
- * @complexity At most two O(file references) create requests plus one upload per missing hash.
254
- */
255
- async function createUploadedVercelDeployment({ config, name, refs, blobs, report }, _options = {}) {
256
- // `target: "production"`: without it Vercel makes a preview deployment, and only a project's
257
- // FIRST deployment takes the production alias, so every later publish never reached the
258
- // public address (2026-10-11). A publish is meant to update the live site.
259
- const body = JSON.stringify({ name, files: refs, target: 'production', projectSettings: { framework: null } });
260
- report({ phase: 'creating', deploymentCreated: 'unknown' });
261
- let createResp = await createVercelDeployment(config, body);
262
- let created = await readVercelJson(createResp);
263
- const missing = created?.error?.code === 'missing_files' ? created.error.missing : undefined;
264
- if (!createResp.ok && Array.isArray(missing)) {
265
- const shas = [...new Set(missing.filter(sha => blobs.has(sha)))];
266
- report({ phase: 'uploading', deploymentCreated: false, reusedFiles: blobs.size - shas.length });
267
- // Vercel did not keep (or never got) some uploads: send exactly what it names, then create
268
- // once more. A second `missing_files` is reported like any other create failure.
269
- let uploadedFiles = 0;
270
- await uploadVercelFiles(config, blobs, shas, () => report({ uploadedFiles: ++uploadedFiles }));
271
- report({ phase: 'creating', deploymentCreated: 'unknown' });
272
- createResp = await createVercelDeployment(config, body);
273
- created = await readVercelJson(createResp);
274
- } else if (createResp.ok) {
275
- report({ reusedFiles: blobs.size });
276
- }
277
- if (!createResp.ok) {
278
- report({ deploymentCreated: false });
279
- throw vercelError(created, createResp.status);
280
- }
281
- return created;
282
- }
283
- /** Only confirmed, value-free facts cross the failure boundary; no raw upstream body.
284
- * @complexity O(1) formatting, independent of export bytes.
285
- */
286
- function publishFacts({ progress }, _options = {}) {
287
- const created = progress.deploymentCreated === true ? 'created' : progress.deploymentCreated === false ? 'not created' : 'unknown';
288
- return `Deployment: ${created}. ${progress.uploadedFiles} of ${progress.totalFiles} distinct files uploaded this attempt; ${progress.reusedFiles} already stored. Deployment ID: ${progress.deploymentId ?? 'unknown'}; URL: ${progress.url || 'unknown'}; provider status: ${progress.providerStatus ?? 'unknown'}.`;
289
- }
290
- function retryGuidance({ progress, name }, _options = {}) {
291
- if (progress.deploymentCreated !== false) return `Check deployment ${progress.deploymentId ?? ''} in the Vercel dashboard for project '${name}' before publishing again. A public site's 200 can belong to the previous deployment.`;
292
- return 'Retry the publish to upload only missing hashes; acknowledged files are reused.';
293
- }
294
- function safeFailureMessage({ error, token }, _options = {}) {
295
- return String(error?.message ?? 'Vercel did not finish the request.').split(token).join('[redacted]');
296
- }
297
- /** Accepted deployment with incomplete verification: retain its own URL, never prove it with
298
- * an old production alias. Known provider errors remain failed rather than becoming a timeout.
299
- */
300
- function unfinishedDeployment({ progress, name, error, token }, _options = {}) {
301
- const fallback = progress.providerStatus === 'ERROR' ? 'Vercel deployment failed.' : 'Vercel has not confirmed this deployment is ready yet.';
302
- const detail = error ? safeFailureMessage({ error, token }) : fallback;
303
- return { targetId: VERCEL_TARGET_ID, url: progress.url || '', deploymentId: progress.deploymentId,
304
- status: progress.providerStatus === 'ERROR' ? 'failed' : 'link-delayed',
305
- statusMessage: `${detail} ${publishFacts({ progress })} ${retryGuidance({ progress, name })}` };
306
- }
307
- async function readyVercelDeployment({ config, deploymentId, created, report }, _options = {}) {
308
- const ready = deploymentId ? await pollVercelDeployment(config, deploymentId, report) : created;
309
- if (ready?.readyState === 'ERROR') {
310
- const readyError = ready.error;
311
- // `ready ?? undefined` — the `undefined` side is unreachable: this line
312
- // only runs when `ready?.readyState === 'ERROR'` just matched, which
313
- // requires `ready` itself to already be a real object (optional
314
- // chaining on a null/undefined `ready` would make the whole comparison
315
- // `undefined === 'ERROR'`, i.e. false, skipping this block entirely).
316
- // So by the time `ready ?? undefined` evaluates, `ready` is always
317
- // truthy and the `??` is a no-op at runtime. Kept (not simplified to
318
- // just `ready`) purely for type-level reasons: `ready`'s static type is
319
- // `JsonObject | null` (from `pollVercelDeployment`'s return type /
320
- // `created`'s), and `DeployError`'s `details` parameter accepts
321
- // `JsonObject | string | undefined` — not `null` — so this coalesce is
322
- // a compile-time-required null-to-undefined conversion that TypeScript's
323
- // control-flow analysis cannot narrow away just from the optional-chained
324
- // comparison above. See packages/devops/source-map.md's 2026-07-22
325
- // addition for the full re-derivation.
326
- throw new DeployError(readyError?.message || 'Vercel deployment failed.', 502, ready ?? undefined);
327
- }
328
- return ready;
329
- }
330
- async function publicVercelLink({ name, ready, created, initialUrl, publicUrl }, _options = {}) {
331
- const aliases = deploymentUrlCandidates(`${name}.vercel.app`, ready, created);
332
- const candidates = publicUrl ? [publicUrl, ...aliases.filter(alias => alias !== publicUrl)] : aliases;
333
- let link = await waitForReachableDeploymentUrl(candidates.length ? candidates : [initialUrl], {
334
- providerLabel: 'Vercel',
335
- detectProtected: isVercelProtectedResponse,
336
- protectedMessage: VERCEL_PROTECTED_MESSAGE,
337
- });
338
- // The kit counts any 3xx as reachable, but Deployment Protection answers a per-deployment
339
- // URL with a redirect to Vercel's login, which is not a public link.
340
- if (link.status === 'ready' && await redirectsToVercelLogin(link.url)) {
341
- link = { status: 'protected', url: link.url, statusMessage: VERCEL_PROTECTED_MESSAGE };
342
- }
343
- return link;
344
- }
345
- /** One HEAD, redirects not followed: does `url` send visitors to Vercel's SSO/login wall? Any
346
- * failure answers `false`, leaving the reachability result as it was. */
347
- async function redirectsToVercelLogin(url) {
348
- try {
349
- const resp = await fetchWithTimeout(url, { method: 'HEAD', redirect: 'manual' }, { timeoutMs: FETCH_TIMEOUT_MS.QUICK });
350
- await resp.arrayBuffer().catch(() => undefined);
351
- return resp.status >= 300 && resp.status < 400 && /vercel\.com\/(sso-api|login)/i.test(resp.headers.get('location') || '');
352
- }
353
- catch {
354
- return false;
355
- }
356
- }
357
- async function createVercelDeployment(config, body) {
358
- const resp = await fetchWithTimeout(`${VERCEL_API}/v13/deployments${vercelTeamQuery(config)}`, redirectGuardInit({
359
- method: 'POST',
360
- headers: {
361
- Authorization: `Bearer ${config.token}`,
362
- 'Content-Type': 'application/json',
363
- },
364
- body,
365
- }), { timeoutMs: FETCH_TIMEOUT_MS.UPLOAD });
366
- assertNotRedirected(resp, 'Vercel deployment creation');
367
- return resp;
368
- }
369
- /**
370
- * Uploads `shas` (keys of `blobs`) to `POST /v2/files`, {@link VERCEL_UPLOAD_CONCURRENCY} at a
371
- * time. The first failure stops the remaining queue; active sends drain before rejection.
372
- *
373
- * @complexity O(n) requests, plus at most `VERCEL_UPLOAD_ATTEMPTS - 1` retries each.
374
- */
375
- async function uploadVercelFiles(config, blobs, shas, onUploaded) {
376
- let cursor = 0;
377
- let stopped = false;
378
- const worker = async () => {
379
- while (!stopped && cursor < shas.length) {
380
- const sha = shas[cursor++];
381
- try {
382
- await uploadVercelFile(config, sha, blobs.get(sha));
383
- onUploaded();
384
- } catch (err) {
385
- stopped = true;
386
- throw err;
387
- }
388
- }
389
- };
390
- // Drain already-started sends before reporting a failure, so acknowledged counts are final
391
- // and no upload from this attempt can race a retry and charge the same bytes twice.
392
- const results = await Promise.allSettled(Array.from({ length: Math.min(VERCEL_UPLOAD_CONCURRENCY, shas.length) }, worker));
393
- const failure = results.find(result => result.status === 'rejected');
394
- if (failure) throw failure.reason;
292
+ if (!domain) throw new DeployError('Vercel did not report a verified public domain for this project.', 400);
293
+ return `https://${domain.name}`;
395
294
  }
295
+
296
+ return resolveVercelPublicUrl;
297
+ }
298
+
299
+ function createVercelUploadAttempt({ fetchWithTimeout, FETCH_TIMEOUT_MS, redirectGuardInit, DeployError, sleep }) {
396
300
  function vercelUploadTransportError({ err }, _options = {}) {
397
301
  // Node's fetch reports every transport failure as a bare "fetch failed"; the cause (a
398
302
  // reset socket, a TLS or DNS error) is the only part that says what happened.
@@ -400,6 +304,7 @@ export function bindVercel(kit, _optional = {}) {
400
304
  const detail = cause ? ` (${cause})` : '';
401
305
  return new DeployError(`Vercel file upload failed: ${err?.message ?? err}${detail}`, 502);
402
306
  }
307
+
403
308
  async function tryVercelFileUpload({ config, sha, data, attempt }, _options = {}) {
404
309
  try {
405
310
  return await fetchWithTimeout(`${VERCEL_API}/v2/files${vercelTeamQuery(config)}`, redirectGuardInit({
@@ -423,6 +328,39 @@ export function bindVercel(kit, _optional = {}) {
423
328
  throw vercelUploadTransportError({ err });
424
329
  }
425
330
  }
331
+
332
+ return tryVercelFileUpload;
333
+ }
334
+
335
+ function createVercelFileUploader({ tryVercelFileUpload, assertNotRedirected, sleep, readVercelJson, vercelError }) {
336
+ /**
337
+ * Uploads `shas` (keys of `blobs`) to `POST /v2/files`, {@link VERCEL_UPLOAD_CONCURRENCY} at a
338
+ * time. The first failure stops the remaining queue; active sends drain before rejection.
339
+ *
340
+ * @complexity O(n) requests, plus at most `VERCEL_UPLOAD_ATTEMPTS - 1` retries each.
341
+ */
342
+ async function uploadVercelFiles(config, blobs, shas, onUploaded) {
343
+ let cursor = 0;
344
+ let stopped = false;
345
+ const worker = async () => {
346
+ while (!stopped && cursor < shas.length) {
347
+ const sha = shas[cursor++];
348
+ try {
349
+ await uploadVercelFile(config, sha, blobs.get(sha));
350
+ onUploaded();
351
+ } catch (err) {
352
+ stopped = true;
353
+ throw err;
354
+ }
355
+ }
356
+ };
357
+ // Drain already-started sends before reporting a failure, so acknowledged counts are final
358
+ // and no upload from this attempt can race a retry and charge the same bytes twice.
359
+ const results = await Promise.allSettled(Array.from({ length: Math.min(VERCEL_UPLOAD_CONCURRENCY, shas.length) }, worker));
360
+ const failure = results.find(result => result.status === 'rejected');
361
+ if (failure) throw failure.reason;
362
+ }
363
+
426
364
  async function uploadVercelFile(config, sha, data) {
427
365
  for (let attempt = 1; ; attempt += 1) {
428
366
  const resp = await tryVercelFileUpload({ config, sha, data, attempt });
@@ -441,6 +379,85 @@ export function bindVercel(kit, _optional = {}) {
441
379
  }
442
380
  }
443
381
  }
382
+
383
+ return uploadVercelFiles;
384
+ }
385
+
386
+ function createVercelDeploymentCreator({ fetchWithTimeout, FETCH_TIMEOUT_MS, assertNotRedirected, redirectGuardInit, uploadVercelFiles, readVercelJson, vercelError }) {
387
+ /** Let the provider's content store select missing hashes before sending bytes. A retry on
388
+ * another target/process reuses provider acknowledgements, including a prior partial upload.
389
+ * @complexity At most two O(file references) create requests plus one upload per missing hash.
390
+ */
391
+ async function createUploadedVercelDeployment({ config, name, refs, blobs, report }, _options = {}) {
392
+ // `target: "production"`: without it Vercel makes a preview deployment, and only a project's
393
+ // FIRST deployment takes the production alias, so every later publish never reached the
394
+ // public address (2026-10-11). A publish is meant to update the live site.
395
+ const body = JSON.stringify({ name, files: refs, target: 'production', projectSettings: { framework: null } });
396
+ report({ phase: 'creating', deploymentCreated: 'unknown' });
397
+ let createResp = await createVercelDeployment(config, body);
398
+ let created = await readVercelJson(createResp);
399
+ const missing = created?.error?.code === 'missing_files' ? created.error.missing : undefined;
400
+ if (!createResp.ok && Array.isArray(missing)) {
401
+ const shas = [...new Set(missing.filter(sha => blobs.has(sha)))];
402
+ report({ phase: 'uploading', deploymentCreated: false, reusedFiles: blobs.size - shas.length });
403
+ // Vercel did not keep (or never got) some uploads: send exactly what it names, then create
404
+ // once more. A second `missing_files` is reported like any other create failure.
405
+ let uploadedFiles = 0;
406
+ await uploadVercelFiles(config, blobs, shas, () => report({ uploadedFiles: ++uploadedFiles }));
407
+ report({ phase: 'creating', deploymentCreated: 'unknown' });
408
+ createResp = await createVercelDeployment(config, body);
409
+ created = await readVercelJson(createResp);
410
+ } else if (createResp.ok) {
411
+ report({ reusedFiles: blobs.size });
412
+ }
413
+ if (!createResp.ok) {
414
+ report({ deploymentCreated: false });
415
+ throw vercelError(created, createResp.status);
416
+ }
417
+ return created;
418
+ }
419
+
420
+ async function createVercelDeployment(config, body) {
421
+ const resp = await fetchWithTimeout(`${VERCEL_API}/v13/deployments${vercelTeamQuery(config)}`, redirectGuardInit({
422
+ method: 'POST',
423
+ headers: {
424
+ Authorization: `Bearer ${config.token}`,
425
+ 'Content-Type': 'application/json',
426
+ },
427
+ body,
428
+ }), { timeoutMs: FETCH_TIMEOUT_MS.UPLOAD });
429
+ assertNotRedirected(resp, 'Vercel deployment creation');
430
+ return resp;
431
+ }
432
+
433
+ return createUploadedVercelDeployment;
434
+ }
435
+
436
+ function createVercelDeploymentWaiter({ fetchWithTimeout, FETCH_TIMEOUT_MS, assertNotRedirected, redirectGuardInit, DeployError, sleep, readVercelJson, vercelError }) {
437
+ async function readyVercelDeployment({ config, deploymentId, created, report }, _options = {}) {
438
+ const ready = deploymentId ? await pollVercelDeployment(config, deploymentId, report) : created;
439
+ if (ready?.readyState === 'ERROR') {
440
+ const readyError = ready.error;
441
+ // `ready ?? undefined` — the `undefined` side is unreachable: this line
442
+ // only runs when `ready?.readyState === 'ERROR'` just matched, which
443
+ // requires `ready` itself to already be a real object (optional
444
+ // chaining on a null/undefined `ready` would make the whole comparison
445
+ // `undefined === 'ERROR'`, i.e. false, skipping this block entirely).
446
+ // So by the time `ready ?? undefined` evaluates, `ready` is always
447
+ // truthy and the `??` is a no-op at runtime. Kept (not simplified to
448
+ // just `ready`) purely for type-level reasons: `ready`'s static type is
449
+ // `JsonObject | null` (from `pollVercelDeployment`'s return type /
450
+ // `created`'s), and `DeployError`'s `details` parameter accepts
451
+ // `JsonObject | string | undefined` — not `null` — so this coalesce is
452
+ // a compile-time-required null-to-undefined conversion that TypeScript's
453
+ // control-flow analysis cannot narrow away just from the optional-chained
454
+ // comparison above. See packages/devops/source-map.md's 2026-07-22
455
+ // addition for the full re-derivation.
456
+ throw new DeployError(readyError?.message || 'Vercel deployment failed.', 502, ready ?? undefined);
457
+ }
458
+ return ready;
459
+ }
460
+
444
461
  /**
445
462
  * Polls a just-created Vercel deployment until it reaches a terminal
446
463
  * `readyState` (`READY`/`ERROR`) or the fixed 30-attempt budget is spent
@@ -486,107 +503,164 @@ export function bindVercel(kit, _optional = {}) {
486
503
  }
487
504
  return last;
488
505
  }
489
- function vercelTeamQuery(config) {
490
- const params = new URLSearchParams();
491
- if (config.teamId)
492
- params.set('teamId', config.teamId);
493
- else if (config.teamSlug)
494
- params.set('slug', config.teamSlug);
495
- else {
496
- // Personal deployments need no team query parameter.
506
+
507
+ return readyVercelDeployment;
508
+ }
509
+
510
+ function createVercelPublicLinkResolver({ fetchWithTimeout, FETCH_TIMEOUT_MS, waitForReachableDeploymentUrl, normalizeDeploymentUrl, isVercelProtectedResponse }) {
511
+ async function publicVercelLink({ name, ready, created, initialUrl, publicUrl }, _options = {}) {
512
+ const aliases = deploymentUrlCandidates(normalizeDeploymentUrl, `${name}.vercel.app`, ready, created);
513
+ const candidates = publicUrl ? [publicUrl, ...aliases.filter(alias => alias !== publicUrl)] : aliases;
514
+ let link = await waitForReachableDeploymentUrl(candidates.length ? candidates : [initialUrl], {
515
+ providerLabel: 'Vercel',
516
+ detectProtected: isVercelProtectedResponse,
517
+ protectedMessage: VERCEL_PROTECTED_MESSAGE,
518
+ });
519
+ // The kit counts any 3xx as reachable, but Deployment Protection answers a per-deployment
520
+ // URL with a redirect to Vercel's login, which is not a public link.
521
+ if (link.status === 'ready' && await redirectsToVercelLogin(link.url)) {
522
+ link = { status: 'protected', url: link.url, statusMessage: VERCEL_PROTECTED_MESSAGE };
497
523
  }
498
- const s = params.toString();
499
- return s ? `?${s}` : '';
500
- }
501
- /**
502
- * Derives a Vercel-safe project name from a caller-supplied label, falling
503
- * back to a random id if the label sanitizes to nothing. Replaces the OD
504
- * origin's hardcoded `od-${projectId}` convention.
505
- */
506
- function safeVercelProjectName(projectName) {
507
- return safeProjectLabel(projectName, 80) || `deploy-${randomInt(36 ** 8).toString(36).padStart(8, '0')}`;
524
+ return link;
508
525
  }
509
- async function readVercelJson(resp) {
526
+
527
+ /** One HEAD, redirects not followed: does `url` send visitors to Vercel's SSO/login wall? Any
528
+ * failure answers `false`, leaving the reachability result as it was. */
529
+ async function redirectsToVercelLogin(url) {
510
530
  try {
511
- return (await resp.json());
531
+ const resp = await fetchWithTimeout(url, { method: 'HEAD', redirect: 'manual' }, { timeoutMs: FETCH_TIMEOUT_MS.QUICK });
532
+ await resp.arrayBuffer().catch(() => undefined);
533
+ return resp.status >= 300 && resp.status < 400 && /vercel\.com\/(sso-api|login)/i.test(resp.headers.get('location') || '');
512
534
  }
513
535
  catch {
514
- throw new DeployError('Vercel returned a non-JSON response.', resp.status || 502);
536
+ return false;
515
537
  }
516
538
  }
517
- function vercelErrorField({ json, field }, _options = {}) {
518
- return json?.error && typeof json.error === 'object' ? json.error[field] : undefined;
519
- }
520
- function vercelError(json, status) {
521
- const code = vercelErrorField({ json, field: 'code' });
522
- const message = vercelErrorField({ json, field: 'message' }) ||
523
- json?.message ||
524
- `Vercel request failed (${status}).`;
525
- if (code === 'forbidden' || /permission/i.test(String(message))) {
526
- return new DeployError("You don't have permission to create a project.", status, json);
539
+
540
+ return publicVercelLink;
541
+ }
542
+
543
+ function createVercelTarget({ DeployError, checkDeploymentUrl, safeProjectLabel, isVercelProtectedResponse,
544
+ resolveVercelPublicUrl, createUploadedVercelDeployment, readyVercelDeployment, publicVercelLink }) {
545
+ /**
546
+ * `DeployTarget` adapter for Vercel's v13 deployments API. Publishes a
547
+ * caller-supplied file set as a single deployment, polls until Vercel
548
+ * reports a terminal `readyState`, then waits for the resulting URL to
549
+ * become publicly reachable.
550
+ *
551
+ * Genericized from the origin product's daemon deploy module's
552
+ * `deployToVercel`: the origin's product-specific deployment-name
553
+ * convention is replaced by `input.projectName` (sanitized the same way);
554
+ * token/team config is supplied by the caller instead of being read from a
555
+ * product-owned local config file — persistence of that config is now the
556
+ * caller's concern, not this package's.
557
+ */
558
+ class VercelDeployTarget {
559
+ config;
560
+ id = VERCEL_TARGET_ID;
561
+ resolvedProjectName;
562
+ resolvedPublicUrl;
563
+ constructor(config) {
564
+ this.config = config;
527
565
  }
528
- return new DeployError(String(message), status, json);
529
- }
530
- function deploymentUrl(json) {
531
- const url = json?.url || json?.alias?.[0] || '';
532
- if (!url)
533
- return '';
534
- return /^https?:\/\//i.test(url) ? url : `https://${url}`;
535
- }
536
- function appendDeploymentAlias({ alias, urls }, _options = {}) {
537
- if (typeof alias === 'string') {
538
- urls.push(alias);
539
- return;
566
+ /** Resolve the host-assigned production domain before rendering. A first publish creates
567
+ * the same project publish() would create, then reads its actual alias (names may collide).
568
+ * @complexity At most three bounded API calls, at most 100 domain records; no file uploads.
569
+ * @throws DeployError for refused/ambiguous inventories; never fabricates a public URL.
570
+ */
571
+ async resolvePublicUrl({ projectName }, _options = {}) {
572
+ this.resolvedProjectName = safeVercelProjectName(projectName, safeProjectLabel);
573
+ this.resolvedPublicUrl = await resolveVercelPublicUrl({ config: this.config, name: this.resolvedProjectName });
574
+ return this.resolvedPublicUrl;
540
575
  }
541
- if (alias && typeof alias === 'object') {
542
- const a = alias;
543
- if (typeof a.domain === 'string')
544
- urls.push(a.domain);
545
- else if (typeof a.url === 'string')
546
- urls.push(a.url);
547
- else {
548
- // Objects without a domain or URL are not deployment aliases.
576
+ /**
577
+ * Publishes `input.files`, asking Vercel for missing hashes before uploading. The optional
578
+ * synchronous `input.onProgress` receives credential-free counts and deployment facts.
579
+ *
580
+ * @param input - File set, project name, optional security headers and progress observer.
581
+ * @returns The verified URL/status, or a partial result retaining the accepted deployment's
582
+ * ID/URL and next steps when readiness cannot be confirmed.
583
+ * @throws {DeployError} For a failed build or before a deployment is known to exist; includes confirmed
584
+ * upload counts, whether creation is false/unknown, and how to safely continue.
585
+ * @complexity O(files) to hash and upload them, plus a bounded poll loop
586
+ * (`pollVercelDeployment`) and the reachability wait's own bound.
587
+ * @overallScore 100/100
588
+ */
589
+ async publish(input) {
590
+ if (!this.config.token) {
591
+ throw new DeployError('Vercel token is required.', 400);
592
+ }
593
+ const { refs, blobs } = vercelFileManifest(withVercelConfigFile(input.files, input.responseHeaders));
594
+ const name = this.resolvedProjectName ?? safeVercelProjectName(input.projectName, safeProjectLabel);
595
+ const progress = { phase: 'creating', totalFiles: blobs.size, uploadedFiles: 0, reusedFiles: 0, deploymentCreated: false };
596
+ const report = patch => { Object.assign(progress, patch); input.onProgress?.({ ...progress }); };
597
+ try {
598
+ const created = await createUploadedVercelDeployment({ config: this.config, name, refs, blobs, report });
599
+ const deploymentId = typeof created.id === 'string' ? created.id : created.uid;
600
+ const initialUrl = deploymentUrl(created);
601
+ report({ phase: 'polling', deploymentCreated: true, deploymentId, url: initialUrl, providerStatus: created.readyState ?? 'unknown' });
602
+ const ready = await readyVercelDeployment({ config: this.config, deploymentId, created, report });
603
+ if (ready?.readyState !== 'READY') return unfinishedDeployment({ progress, name });
604
+ report({ phase: 'checking', providerStatus: 'READY' });
605
+ const link = await publicVercelLink({ name, ready, created, initialUrl, publicUrl: this.resolvedPublicUrl });
606
+ return publishedResult({ link, ready, initialUrl, deploymentId });
607
+ } catch (error) {
608
+ return publishFailure({ progress, name, error, token: this.config.token, DeployError });
549
609
  }
550
610
  }
551
- }
552
- function appendDeploymentAliases({ json, urls }, _options = {}) {
553
- for (const alias of json.alias ?? []) {
554
- if (typeof alias === 'string')
555
- urls.push(alias);
556
- }
557
- for (const alias of json.aliases ?? []) {
558
- appendDeploymentAlias({ alias, urls });
611
+ /** Probes `url`, recognizing Vercel's own Deployment Protection auth wall. */
612
+ async checkReachability(url) {
613
+ return checkDeploymentUrl(url, {
614
+ detectProtected: isVercelProtectedResponse,
615
+ protectedMessage: VERCEL_PROTECTED_MESSAGE,
616
+ });
559
617
  }
560
618
  }
619
+
620
+ return VercelDeployTarget;
621
+ }
622
+
623
+ /**
624
+ * Binds the ported Vercel code to one host kit.
625
+ *
626
+ * @param {{ fetch(url: string, init: RequestInit, options: { timeoutMs: number }): Promise<Response>,
627
+ * timeouts: { QUICK: number, DEPLOY: number, UPLOAD: number }, sleep(ms: number): Promise<void> } & Record<string, any>} kit
628
+ * The host's deploy kit in the positional ABI installed modules are written against (devops'
629
+ * `DeployHostKit` helpers, called positionally; `DeployError` is `new (message, status?, details?)`).
630
+ * @returns The target class (constructed with `{ token, teamId?, teamSlug? }`, as in devops) and the
631
+ * protected-response detector.
632
+ */
633
+ export function bindVercel(kit, _optional = {}) {
634
+ const { fetch: fetchWithTimeout, timeouts: FETCH_TIMEOUT_MS, sleep, DeployError, checkDeploymentUrl, normalizeDeploymentUrl, waitForReachableDeploymentUrl, safeProjectLabel, assertNotRedirected, redirectGuardInit } = kit;
635
+ const transport = { fetchWithTimeout, FETCH_TIMEOUT_MS, assertNotRedirected, redirectGuardInit };
636
+ const responses = createVercelResponseReaders(DeployError);
637
+ const resolveVercelPublicUrl = createVercelDomainResolver({ ...transport, ...responses, DeployError });
638
+ const tryVercelFileUpload = createVercelUploadAttempt({ ...transport, DeployError, sleep });
639
+ const uploadVercelFiles = createVercelFileUploader({ ...responses, tryVercelFileUpload, assertNotRedirected, sleep });
640
+ const createUploadedVercelDeployment = createVercelDeploymentCreator({ ...transport, ...responses, uploadVercelFiles });
641
+ const readyVercelDeployment = createVercelDeploymentWaiter({ ...transport, ...responses, DeployError, sleep });
642
+ const publicVercelLink = createVercelPublicLinkResolver({ fetchWithTimeout, FETCH_TIMEOUT_MS, waitForReachableDeploymentUrl, normalizeDeploymentUrl, isVercelProtectedResponse });
643
+ const VercelDeployTarget = createVercelTarget({ DeployError, checkDeploymentUrl, safeProjectLabel, isVercelProtectedResponse,
644
+ resolveVercelPublicUrl, createUploadedVercelDeployment, readyVercelDeployment, publicVercelLink });
645
+
561
646
  /**
562
- * `if (!json) continue` skips a response that is not there. Of this file's one call site,
563
- * `deploymentUrlCandidates(publicHost, ready, created)` in `publish()`, `created` is always a parsed
564
- * `JsonObject` (`readVercelJson` returns one or throws), but `ready` is `null` when every one of
565
- * `pollVercelDeployment`'s 30 status reads was unparseable (each such read is skipped with
566
- * `continue`, so `last` is never assigned) — then only `created` supplies candidates. Same guard
567
- * `netlify.ts`'s own `netlifyUrlCandidates` keeps for the same reason.
647
+ * Heuristically detects Vercel's own Deployment Protection auth wall from a
648
+ * 401 response, so `checkReachability` can report `status: 'protected'`
649
+ * (an actionable, non-error outcome) instead of `reachable: false` with a
650
+ * generic message.
651
+ *
652
+ * @param resp - The HTTP response received from probing a deployment URL.
653
+ * @param body - The response body (only read for 401s by the caller).
654
+ * @returns `true` if the response looks like Vercel's SSO/auth gate.
655
+ * @complexity O(1) — a handful of regex tests over already-fetched strings.
656
+ * @overallScore 100/100
568
657
  */
569
- function deploymentUrlCandidates(publicHost, ...responses) {
570
- // Aliases (the production `<project>.vercel.app` among them) are tried before `url`: `url` is the
571
- // per-deployment address, which Deployment Protection puts behind Vercel's login by default.
572
- const urls = [];
573
- const deploymentUrls = [];
574
- for (const json of responses) {
575
- if (!json)
576
- continue;
577
- if (typeof json.url === 'string')
578
- deploymentUrls.push(json.url);
579
- appendDeploymentAliases({ json, urls });
580
- }
581
- const candidates = [...new Set([...urls, ...deploymentUrls].map(normalizeDeploymentUrl).filter(Boolean))];
582
- // The public `<project>.vercel.app` alias goes first when Vercel lists it. Vercel orders aliases
583
- // its own way, so the team-scoped `<project>-<team>.vercel.app` (behind Deployment Protection)
584
- // can come first, and the reachability wait stops at the first `protected` answer: a publish
585
- // whose public alias served 200 was reported `protected` (2026-10-11).
586
- const publicUrl = normalizeDeploymentUrl(publicHost);
587
- return candidates.includes(publicUrl) ? [publicUrl, ...candidates.filter((url) => url !== publicUrl)] : candidates;
658
+ function isVercelProtectedResponse(resp, body = '') {
659
+ const { server, setCookie } = protectionHeaders({ resp });
660
+ const text = String(body || '');
661
+ if (/vercel/i.test(server) || /_vercel_sso_nonce/i.test(setCookie)) return true;
662
+ return /Authentication Required|Vercel Authentication|vercel\.com\/sso-api/i.test(text);
588
663
  }
589
-
590
664
  return { VercelDeployTarget, isVercelProtectedResponse };
591
665
  }
592
666