cloudflare
Version:
The official TypeScript library for the Cloudflare API
137 lines • 5.36 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Secrets = exports.BaseSecrets = void 0;
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
const resource_1 = require("../../../core/resource.js");
const pagination_1 = require("../../../core/pagination.js");
const path_1 = require("../../../internal/utils/path.js");
var BaseSecrets = /* @__PURE__ */ (() => {
class BaseSecrets extends resource_1.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((0, path_1.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((0, path_1.path) `/accounts/${account_id}/workers/scripts/${scriptName}/secrets`, (pagination_1.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((0, path_1.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((0, path_1.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((0, path_1.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;
})();
exports.BaseSecrets = BaseSecrets;
class Secrets extends BaseSecrets {
}
exports.Secrets = Secrets;
//# sourceMappingURL=secrets.js.map