cloudflare
Version:
The official TypeScript library for the Cloudflare API
132 lines • 5.1 kB
JavaScript
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from "../../../core/resource.mjs";
import { SinglePage } from "../../../core/pagination.mjs";
import { path } from "../../../internal/utils/path.mjs";
export var BaseSecrets = /* @__PURE__ */ (() => {
class BaseSecrets extends APIResource {
/**
* Add a secret to a Worker script by creating a new version with that secret.
*
* When changing more than one secret at a time, prefer the "Patch multiple script
* secrets" API instead of changing many secrets individually.
*
* @example
* ```ts
* const secret = await client.workers.scripts.secrets.update(
* 'this-is_my_script-01',
* {
* account_id: '023e105f4ecef8ad9ca31a8372d0c353',
* name: 'myBinding',
* text: 'My secret.',
* type: 'secret_text',
* },
* );
* ```
*/
update(scriptName, params, options) {
const { account_id, ...body } = params;
return this._client.put(path `/accounts/${account_id}/workers/scripts/${scriptName}/secrets`, {
body,
...options,
})._thenUnwrap((obj) => obj.result);
}
/**
* List the names of secrets bound to a Worker script.
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const secretListResponse of client.workers.scripts.secrets.list(
* 'this-is_my_script-01',
* { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* )) {
* // ...
* }
* ```
*/
list(scriptName, params, options) {
const { account_id } = params;
return this._client.getAPIList(path `/accounts/${account_id}/workers/scripts/${scriptName}/secrets`, (SinglePage), options);
}
/**
* Remove a secret from a Worker script by creating a new version without that
* secret.
*
* When changing more than one secret at a time, prefer the "Patch multiple script
* secrets" API instead of changing many secrets individually.
*
* @example
* ```ts
* const secret = await client.workers.scripts.secrets.delete(
* 'mySecret',
* {
* account_id: '023e105f4ecef8ad9ca31a8372d0c353',
* script_name: 'this-is_my_script-01',
* },
* );
* ```
*/
delete(secretName, params, options) {
const { account_id, script_name, url_encoded } = params;
return this._client.delete(path `/accounts/${account_id}/workers/scripts/${script_name}/secrets/${secretName}`, { query: { url_encoded }, ...options })._thenUnwrap((obj) => obj.result);
}
/**
* Create, update, or delete multiple secrets on a Worker script in a single
* operation using JSON Merge Patch (RFC 7396). This operation creates a single
* version with all changes included. Prefer this API instead of changing many
* secrets individually.
*
* Usage:
*
* - To create or update a secret, set its value to a secret object.
* - To delete a secret, set its value to `null`.
* - Secrets not included in the request are left unchanged.
*
* @example
* ```ts
* const response =
* await client.workers.scripts.secrets.bulkUpdate(
* 'this-is_my_script-01',
* { account_id: '023e105f4ecef8ad9ca31a8372d0c353' },
* );
* ```
*/
bulkUpdate(scriptName, params, options) {
const { account_id, ...body } = params;
return this._client.patch(path `/accounts/${account_id}/workers/scripts/${scriptName}/secrets-bulk`, {
body,
...options,
})._thenUnwrap((obj) => obj.result);
}
/**
* Get a given secret binding (value omitted) on a Worker script.
*
* @example
* ```ts
* const secret = await client.workers.scripts.secrets.get(
* 'mySecret',
* {
* account_id: '023e105f4ecef8ad9ca31a8372d0c353',
* script_name: 'this-is_my_script-01',
* },
* );
* ```
*/
get(secretName, params, options) {
const { account_id, script_name, ...query } = params;
return this._client.get(path `/accounts/${account_id}/workers/scripts/${script_name}/secrets/${secretName}`, {
query,
...options,
})._thenUnwrap((obj) => obj.result);
}
}
BaseSecrets._key = Object.freeze([
'workers',
'scripts',
'secrets',
]);
return BaseSecrets;
})();
export class Secrets extends BaseSecrets {
}
//# sourceMappingURL=secrets.mjs.map