( files: FilesMap, clientOptions: VercelClientOptions, deploymentOptions: DeploymentOptions )
| 16 | } from './types'; |
| 17 | |
| 18 | async function* postDeployment( |
| 19 | files: FilesMap, |
| 20 | clientOptions: VercelClientOptions, |
| 21 | deploymentOptions: DeploymentOptions |
| 22 | ): AsyncIterableIterator<{ |
| 23 | type: DeploymentEventType; |
| 24 | payload: any; |
| 25 | action?: string; |
| 26 | link?: string; |
| 27 | }> { |
| 28 | const debug = createDebug(clientOptions.debug); |
| 29 | const preparedFiles = prepareFiles(files, clientOptions); |
| 30 | const apiDeployments = getApiDeploymentsUrl(); |
| 31 | |
| 32 | if (deploymentOptions?.builds && !deploymentOptions.functions) { |
| 33 | clientOptions.skipAutoDetectionConfirmation = true; |
| 34 | } |
| 35 | |
| 36 | // Preview deployments are the default - no need to set `target` |
| 37 | if (deploymentOptions.target === 'preview') { |
| 38 | deploymentOptions.target = undefined; |
| 39 | } |
| 40 | |
| 41 | // "production" environment need to use `target`, |
| 42 | // otherwise use `customEnvironmentSlugOrId` for a Custom Environment |
| 43 | if (deploymentOptions.target && deploymentOptions.target !== 'production') { |
| 44 | deploymentOptions.customEnvironmentSlugOrId = deploymentOptions.target; |
| 45 | deploymentOptions.target = undefined; |
| 46 | } |
| 47 | |
| 48 | debug('Sending deployment creation API request'); |
| 49 | try { |
| 50 | const response = await fetchApi( |
| 51 | `${apiDeployments}${generateQueryString(clientOptions)}`, |
| 52 | clientOptions.token, |
| 53 | { |
| 54 | method: 'POST', |
| 55 | headers: { |
| 56 | Accept: 'application/json', |
| 57 | 'Content-Type': 'application/json', |
| 58 | }, |
| 59 | body: JSON.stringify({ |
| 60 | ...deploymentOptions, |
| 61 | files: preparedFiles, |
| 62 | }), |
| 63 | apiUrl: clientOptions.apiUrl, |
| 64 | userAgent: clientOptions.userAgent, |
| 65 | agent: clientOptions.agent, |
| 66 | } |
| 67 | ); |
| 68 | |
| 69 | let deployment = undefined; |
| 70 | try { |
| 71 | deployment = await response.json(); |
| 72 | } catch (_error) { |
| 73 | throw new Error('Invalid JSON response'); |
| 74 | } |
| 75 |
no test coverage detected