cloudflare
Version:
The official TypeScript library for the Cloudflare API
139 lines • 6.33 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 Workers for Platforms 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.workersForPlatforms.dispatch.namespaces.scripts.secrets.update(
* 'this-is_my_script-01',
* {
* account_id: '023e105f4ecef8ad9ca31a8372d0c353',
* dispatch_namespace: 'my-dispatch-namespace',
* name: 'myBinding',
* text: 'My secret.',
* type: 'secret_text',
* },
* );
* ```
*/
update(scriptName, params, options) {
const { account_id, dispatch_namespace, ...body } = params;
return this._client.put((0, path_1.path) `/accounts/${account_id}/workers/dispatch/namespaces/${dispatch_namespace}/scripts/${scriptName}/secrets`, { body, ...options })._thenUnwrap((obj) => obj.result);
}
/**
* List secrets bound to a script uploaded to a Workers for Platforms dispatch
* namespace.
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const secretListResponse of client.workersForPlatforms.dispatch.namespaces.scripts.secrets.list(
* 'this-is_my_script-01',
* {
* account_id: '023e105f4ecef8ad9ca31a8372d0c353',
* dispatch_namespace: 'my-dispatch-namespace',
* },
* )) {
* // ...
* }
* ```
*/
list(scriptName, params, options) {
const { account_id, dispatch_namespace } = params;
return this._client.getAPIList((0, path_1.path) `/accounts/${account_id}/workers/dispatch/namespaces/${dispatch_namespace}/scripts/${scriptName}/secrets`, (pagination_1.SinglePage), options);
}
/**
* Remove a secret from a Workers for Platforms 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.workersForPlatforms.dispatch.namespaces.scripts.secrets.delete(
* 'mySecret',
* {
* account_id: '023e105f4ecef8ad9ca31a8372d0c353',
* dispatch_namespace: 'my-dispatch-namespace',
* script_name: 'this-is_my_script-01',
* },
* );
* ```
*/
delete(secretName, params, options) {
const { account_id, dispatch_namespace, script_name, url_encoded } = params;
return this._client.delete((0, path_1.path) `/accounts/${account_id}/workers/dispatch/namespaces/${dispatch_namespace}/scripts/${script_name}/secrets/${secretName}`, { query: { url_encoded }, ...options })._thenUnwrap((obj) => obj.result);
}
/**
* Create, update, or delete multiple secrets on a Workers for Platforms 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.workersForPlatforms.dispatch.namespaces.scripts.secrets.bulkUpdate(
* 'this-is_my_script-01',
* {
* account_id: '023e105f4ecef8ad9ca31a8372d0c353',
* dispatch_namespace: 'my-dispatch-namespace',
* },
* );
* ```
*/
bulkUpdate(scriptName, params, options) {
const { account_id, dispatch_namespace, ...body } = params;
return this._client.patch((0, path_1.path) `/accounts/${account_id}/workers/dispatch/namespaces/${dispatch_namespace}/scripts/${scriptName}/secrets-bulk`, { body, ...options })._thenUnwrap((obj) => obj.result);
}
/**
* Get a given secret binding (value omitted) on a script uploaded to a Workers for
* Platforms dispatch namespace.
*
* @example
* ```ts
* const secret =
* await client.workersForPlatforms.dispatch.namespaces.scripts.secrets.get(
* 'mySecret',
* {
* account_id: '023e105f4ecef8ad9ca31a8372d0c353',
* dispatch_namespace: 'my-dispatch-namespace',
* script_name: 'this-is_my_script-01',
* },
* );
* ```
*/
get(secretName, params, options) {
const { account_id, dispatch_namespace, script_name, ...query } = params;
return this._client.get((0, path_1.path) `/accounts/${account_id}/workers/dispatch/namespaces/${dispatch_namespace}/scripts/${script_name}/secrets/${secretName}`, { query, ...options })._thenUnwrap((obj) => obj.result);
}
}
BaseSecrets._key = Object.freeze(['workersForPlatforms', 'dispatch', 'namespaces', 'scripts', 'secrets']);
return BaseSecrets;
})();
exports.BaseSecrets = BaseSecrets;
class Secrets extends BaseSecrets {
}
exports.Secrets = Secrets;
//# sourceMappingURL=secrets.js.map