cloudflare
Version:
The official TypeScript library for the Cloudflare API
90 lines • 3.23 kB
JavaScript
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from "../../../resource.mjs";
export class Deployments extends APIResource {
/**
* Deployments configure how
* [Worker Versions](https://developers.cloudflare.com/api/operations/worker-versions-list-versions)
* are deployed to traffic. A deployment can consist of one or two versions of a
* Worker.
*
* @example
* ```ts
* const deployment =
* await client.workers.scripts.deployments.create(
* 'this-is_my_script-01',
* {
* account_id: '023e105f4ecef8ad9ca31a8372d0c353',
* strategy: 'percentage',
* versions: [
* {
* percentage: 100,
* version_id:
* '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
* },
* ],
* },
* );
* ```
*/
create(scriptName, params, options) {
const { account_id, force, ...body } = params;
return this._client.post(`/accounts/${account_id}/workers/scripts/${scriptName}/deployments`, {
query: { force },
body,
...options,
})._thenUnwrap((obj) => obj.result);
}
/**
* List of Worker Deployments. The first deployment in the list is the latest
* deployment actively serving traffic.
*
* @example
* ```ts
* const deployments =
* await client.workers.scripts.deployments.list(
* 'this-is_my_script-01',
* { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* );
* ```
*/
list(scriptName, params, options) {
const { account_id } = params;
return this._client.get(`/accounts/${account_id}/workers/scripts/${scriptName}/deployments`, options)._thenUnwrap((obj) => obj.result);
}
/**
* Delete a Worker Deployment. The latest deployment, which is actively serving
* traffic, cannot be deleted. All other deployments can be deleted.
*
* @example
* ```ts
* const deployment =
* await client.workers.scripts.deployments.delete(
* 'this-is_my_script-01',
* '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
* { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* );
* ```
*/
delete(scriptName, deploymentId, params, options) {
const { account_id } = params;
return this._client.delete(`/accounts/${account_id}/workers/scripts/${scriptName}/deployments/${deploymentId}`, options);
}
/**
* Get information about a Worker Deployment.
*
* @example
* ```ts
* const deployment =
* await client.workers.scripts.deployments.get(
* 'this-is_my_script-01',
* '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
* { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* );
* ```
*/
get(scriptName, deploymentId, params, options) {
const { account_id } = params;
return this._client.get(`/accounts/${account_id}/workers/scripts/${scriptName}/deployments/${deploymentId}`, options)._thenUnwrap((obj) => obj.result);
}
}
//# sourceMappingURL=deployments.mjs.map