UNPKG

cloudflare

Version:

The official TypeScript library for the Cloudflare API

176 lines • 7.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Scripts = exports.BaseScripts = void 0; const tslib_1 = require("../../../internal/tslib.js"); // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. const resource_1 = require("../../../core/resource.js"); const ContentAPI = tslib_1.__importStar(require("./content.js")); const content_1 = require("./content.js"); const DeploymentsAPI = tslib_1.__importStar(require("./deployments.js")); const deployments_1 = require("./deployments.js"); const SchedulesAPI = tslib_1.__importStar(require("./schedules.js")); const schedules_1 = require("./schedules.js"); const ScriptAndVersionSettingsAPI = tslib_1.__importStar(require("./script-and-version-settings.js")); const script_and_version_settings_1 = require("./script-and-version-settings.js"); const SecretsAPI = tslib_1.__importStar(require("./secrets.js")); const secrets_1 = require("./secrets.js"); const SettingsAPI = tslib_1.__importStar(require("./settings.js")); const settings_1 = require("./settings.js"); const SubdomainAPI = tslib_1.__importStar(require("./subdomain.js")); const subdomain_1 = require("./subdomain.js"); const TailAPI = tslib_1.__importStar(require("./tail.js")); const tail_1 = require("./tail.js"); const VersionsAPI = tslib_1.__importStar(require("./versions.js")); const versions_1 = require("./versions.js"); const AssetsAPI = tslib_1.__importStar(require("./assets/assets.js")); const assets_1 = require("./assets/assets.js"); const pagination_1 = require("../../../core/pagination.js"); const headers_1 = require("../../../internal/headers.js"); const uploads_1 = require("../../../internal/uploads.js"); const path_1 = require("../../../internal/utils/path.js"); var BaseScripts = /* @__PURE__ */ (() => { class BaseScripts extends resource_1.APIResource { /** * Upload a worker module. You can find more about the multipart metadata on our * docs: * https://developers.cloudflare.com/workers/configuration/multipart-upload-metadata/. * * @example * ```ts * const script = await client.workers.scripts.update( * 'this-is_my_script-01', * { * account_id: '023e105f4ecef8ad9ca31a8372d0c353', * metadata: {}, * }, * ); * ``` */ update(scriptName, params, options) { const { account_id, bindings_inherit, ...body } = params; return this._client.put((0, path_1.path) `/accounts/${account_id}/workers/scripts/${scriptName}`, (0, uploads_1.maybeMultipartFormRequestOptions)({ query: { bindings_inherit }, body, ...options, headers: (0, headers_1.buildHeaders)([{ 'Content-Type': 'application/javascript' }, options?.headers]), }, this._client))._thenUnwrap((obj) => obj.result); } /** * Fetch a list of uploaded Worker scripts. * * @example * ```ts * // Automatically fetches more pages as needed. * for await (const scriptListResponse of client.workers.scripts.list( * { account_id: '023e105f4ecef8ad9ca31a8372d0c353' }, * )) { * // ... * } * ``` */ list(params, options) { const { account_id, ...query } = params; return this._client.getAPIList((0, path_1.path) `/accounts/${account_id}/workers/scripts`, (pagination_1.SinglePage), { query, ...options }); } /** * Delete your worker. This call has no response body on a successful delete. * * @example * ```ts * const script = await client.workers.scripts.delete( * 'this-is_my_script-01', * { account_id: '023e105f4ecef8ad9ca31a8372d0c353' }, * ); * ``` */ delete(scriptName, params, options) { const { account_id, force } = params; return this._client.delete((0, path_1.path) `/accounts/${account_id}/workers/scripts/${scriptName}`, { query: { force }, ...options, })._thenUnwrap((obj) => obj.result); } /** * Fetch raw content for a Worker script. Note this is the original script content, * not JSON encoded. * * @example * ```ts * const script = await client.workers.scripts.get( * 'this-is_my_script-01', * { account_id: '023e105f4ecef8ad9ca31a8372d0c353' }, * ); * ``` */ get(scriptName, params, options) { const { account_id } = params; return this._client.get((0, path_1.path) `/accounts/${account_id}/workers/scripts/${scriptName}`, { ...options, headers: (0, headers_1.buildHeaders)([{ Accept: 'application/javascript' }, options?.headers]), }); } /** * Search for Worker scripts in an account. * * @example * ```ts * const response = await client.workers.scripts.search({ * account_id: '023e105f4ecef8ad9ca31a8372d0c353', * }); * ``` */ search(params, options) { const { account_id, ...query } = params; return this._client.get((0, path_1.path) `/accounts/${account_id}/workers/scripts-search`, { query, ...options, })._thenUnwrap((obj) => obj.result); } } BaseScripts._key = Object.freeze([ 'workers', 'scripts', ]); return BaseScripts; })(); exports.BaseScripts = BaseScripts; var Scripts = /* @__PURE__ */ (() => { class Scripts extends BaseScripts { constructor() { super(...arguments); this.assets = new AssetsAPI.Assets(this._client); this.subdomain = new SubdomainAPI.Subdomain(this._client); this.schedules = new SchedulesAPI.Schedules(this._client); this.tail = new TailAPI.Tail(this._client); this.content = new ContentAPI.Content(this._client); this.settings = new SettingsAPI.Settings(this._client); this.deployments = new DeploymentsAPI.Deployments(this._client); this.versions = new VersionsAPI.Versions(this._client); this.secrets = new SecretsAPI.Secrets(this._client); this.scriptAndVersionSettings = new ScriptAndVersionSettingsAPI.ScriptAndVersionSettings(this._client); } } Scripts.Assets = assets_1.Assets; Scripts.BaseAssets = assets_1.BaseAssets; Scripts.Subdomain = subdomain_1.Subdomain; Scripts.BaseSubdomain = subdomain_1.BaseSubdomain; Scripts.Schedules = schedules_1.Schedules; Scripts.BaseSchedules = schedules_1.BaseSchedules; Scripts.Tail = tail_1.Tail; Scripts.BaseTail = tail_1.BaseTail; Scripts.Content = content_1.Content; Scripts.BaseContent = content_1.BaseContent; Scripts.Settings = settings_1.Settings; Scripts.BaseSettings = settings_1.BaseSettings; Scripts.Deployments = deployments_1.Deployments; Scripts.BaseDeployments = deployments_1.BaseDeployments; Scripts.Versions = versions_1.Versions; Scripts.BaseVersions = versions_1.BaseVersions; Scripts.Secrets = secrets_1.Secrets; Scripts.BaseSecrets = secrets_1.BaseSecrets; Scripts.ScriptAndVersionSettings = script_and_version_settings_1.ScriptAndVersionSettings; Scripts.BaseScriptAndVersionSettings = script_and_version_settings_1.BaseScriptAndVersionSettings; return Scripts; })(); exports.Scripts = Scripts; //# sourceMappingURL=scripts.js.map