cloudflare
Version:
The official TypeScript library for the Cloudflare API
933 lines (787 loc) • 21.7 kB
text/typescript
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from '../../../../../core/resource';
import { PagePromise, SinglePage } from '../../../../../core/pagination';
import { RequestOptions } from '../../../../../internal/request-options';
import { path } from '../../../../../internal/utils/path';
export class BaseBindings extends APIResource {
static override readonly _key: readonly [
'workersForPlatforms',
'dispatch',
'namespaces',
'scripts',
'bindings',
] = Object.freeze(['workersForPlatforms', 'dispatch', 'namespaces', 'scripts', 'bindings'] as const);
/**
* Fetch bindings from a script uploaded to a Workers for Platforms dispatch
* namespace.
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const bindingGetResponse of client.workersForPlatforms.dispatch.namespaces.scripts.bindings.get(
* 'this-is_my_script-01',
* {
* account_id: '023e105f4ecef8ad9ca31a8372d0c353',
* dispatch_namespace: 'my-dispatch-namespace',
* },
* )) {
* // ...
* }
* ```
*/
get(
scriptName: string,
params: BindingGetParams,
options?: RequestOptions,
): PagePromise<BindingGetResponsesSinglePage, BindingGetResponse> {
const { account_id, dispatch_namespace } = params;
return this._client.getAPIList(
path`/accounts/${account_id}/workers/dispatch/namespaces/${dispatch_namespace}/scripts/${scriptName}/bindings`,
SinglePage<BindingGetResponse>,
options,
);
}
}
export class Bindings extends BaseBindings {}
export type BindingGetResponsesSinglePage = SinglePage<BindingGetResponse>;
/**
* A binding to allow the Worker to communicate with resources.
*/
export type BindingGetResponse =
| BindingGetResponse.WorkersBindingKindAI
| BindingGetResponse.WorkersBindingKindAISearch
| BindingGetResponse.WorkersBindingKindAISearchNamespace
| BindingGetResponse.WorkersBindingKindMessaging
| BindingGetResponse.WorkersBindingKindAnalyticsEngine
| BindingGetResponse.WorkersBindingKindArtifacts
| BindingGetResponse.WorkersBindingKindAssets
| BindingGetResponse.WorkersBindingKindBrowser
| BindingGetResponse.WorkersBindingKindD1
| BindingGetResponse.WorkersBindingKindDataBlob
| BindingGetResponse.WorkersBindingKindDispatchNamespace
| BindingGetResponse.WorkersBindingKindDurableObjectNamespace
| BindingGetResponse.WorkersBindingKindHyperdrive
| BindingGetResponse.WorkersBindingKindInherit
| BindingGetResponse.WorkersBindingKindImages
| BindingGetResponse.WorkersBindingKindJson
| BindingGetResponse.WorkersBindingKindKVNamespace
| BindingGetResponse.WorkersBindingKindMedia
| BindingGetResponse.WorkersBindingKindMTLSCertificate
| BindingGetResponse.WorkersBindingKindPlainText
| BindingGetResponse.WorkersBindingKindPipelines
| BindingGetResponse.WorkersBindingKindK2
| BindingGetResponse.WorkersBindingKindQueue
| BindingGetResponse.WorkersBindingKindRatelimit
| BindingGetResponse.WorkersBindingKindR2Bucket
| BindingGetResponse.WorkersBindingKindSecretText
| BindingGetResponse.WorkersBindingKindSendEmail
| BindingGetResponse.WorkersBindingKindService
| BindingGetResponse.WorkersBindingKindTextBlob
| BindingGetResponse.WorkersBindingKindVectorize
| BindingGetResponse.WorkersBindingKindVersionMetadata
| BindingGetResponse.WorkersBindingKindSecretsStoreSecret
| BindingGetResponse.WorkersBindingKindFlagship
| BindingGetResponse.WorkersBindingKindSecretKey
| BindingGetResponse.WorkersBindingKindWorkflow
| BindingGetResponse.WorkersBindingKindWasmModule
| BindingGetResponse.WorkersBindingKindVPCService
| BindingGetResponse.WorkersBindingKindVPCNetwork;
export namespace BindingGetResponse {
export interface WorkersBindingKindAI {
/**
* A JavaScript variable name for the binding.
*/
name: string;
/**
* The kind of resource that the binding provides.
*/
type: 'ai';
}
export interface WorkersBindingKindAISearch {
/**
* The user-chosen instance name. Must exist at deploy time. The worker can search,
* chat, update, and manage items/jobs on this instance.
*/
instance_name: string;
/**
* A JavaScript variable name for the binding.
*/
name: string;
/**
* The kind of resource that the binding provides.
*/
type: 'ai_search';
/**
* The namespace the instance belongs to. Defaults to "default" if omitted.
* Customers who don't use namespaces can simply omit this field.
*/
namespace?: string;
}
export interface WorkersBindingKindAISearchNamespace {
/**
* A JavaScript variable name for the binding.
*/
name: string;
/**
* The user-chosen namespace name. Must exist before deploy -- Wrangler handles
* auto-creation on deploy failure (R2 bucket pattern). The "default" namespace is
* auto-created by config-api for new accounts. Grants full access (CRUD + search +
* chat) to all instances within the namespace.
*/
namespace: string;
/**
* The kind of resource that the binding provides.
*/
type: 'ai_search_namespace';
}
export interface WorkersBindingKindMessaging {
/**
* A JavaScript variable name for the binding.
*/
name: string;
/**
* The Messaging namespace to bind to.
*/
namespace: string;
/**
* The kind of resource that the binding provides.
*/
type: 'messaging';
}
export interface WorkersBindingKindAnalyticsEngine {
/**
* The name of the dataset to bind to.
*/
dataset: string;
/**
* A JavaScript variable name for the binding.
*/
name: string;
/**
* The kind of resource that the binding provides.
*/
type: 'analytics_engine';
}
export interface WorkersBindingKindArtifacts {
/**
* A JavaScript variable name for the binding.
*/
name: string;
/**
* The Artifacts namespace exposed to the Worker in the Worker's account. Must be
* 2-63 characters, start with an ASCII alphanumeric character, contain only ASCII
* alphanumeric characters, dots, underscores, and hyphens, and must not end with a
* hyphen. The namespace does not need to be created before binding it.
*/
namespace: string;
/**
* The kind of resource that the binding provides.
*/
type: 'artifacts';
}
export interface WorkersBindingKindAssets {
/**
* A JavaScript variable name for the binding.
*/
name: string;
/**
* The kind of resource that the binding provides.
*/
type: 'assets';
}
export interface WorkersBindingKindBrowser {
/**
* A JavaScript variable name for the binding.
*/
name: string;
/**
* The kind of resource that the binding provides.
*/
type: 'browser';
}
export interface WorkersBindingKindD1 {
/**
* Identifier of the D1 database to bind to.
*/
database_id: string;
/**
* A JavaScript variable name for the binding.
*/
name: string;
/**
* The kind of resource that the binding provides.
*/
type: 'd1';
/**
* @deprecated This property has been renamed to `database_id`.
*/
id?: string;
}
export interface WorkersBindingKindDataBlob {
/**
* A JavaScript variable name for the binding.
*/
name: string;
/**
* The name of the file containing the data content. Only accepted for
* `service worker syntax` Workers.
*/
part: string;
/**
* @deprecated The kind of resource that the binding provides.
*/
type: 'data_blob';
}
export interface WorkersBindingKindDispatchNamespace {
/**
* A JavaScript variable name for the binding.
*/
name: string;
/**
* The name of the dispatch namespace.
*/
namespace: string;
/**
* The kind of resource that the binding provides.
*/
type: 'dispatch_namespace';
/**
* Outbound worker.
*/
outbound?: WorkersBindingKindDispatchNamespace.Outbound;
}
export namespace WorkersBindingKindDispatchNamespace {
/**
* Outbound worker.
*/
export interface Outbound {
/**
* Pass information from the Dispatch Worker to the Outbound Worker through the
* parameters.
*/
params?: Array<Outbound.Param>;
/**
* Outbound worker.
*/
worker?: Outbound.Worker;
}
export namespace Outbound {
export interface Param {
/**
* Name of the parameter.
*/
name: string;
}
/**
* Outbound worker.
*/
export interface Worker {
/**
* Entrypoint to invoke on the outbound worker.
*/
entrypoint?: string;
/**
* Environment of the outbound worker.
*/
environment?: string;
/**
* Name of the outbound worker.
*/
service?: string;
}
}
}
export interface WorkersBindingKindDurableObjectNamespace {
/**
* A JavaScript variable name for the binding.
*/
name: string;
/**
* The kind of resource that the binding provides.
*/
type: 'durable_object_namespace';
/**
* The exported class name of the Durable Object.
*/
class_name?: string;
/**
* The dispatch namespace the Durable Object script belongs to.
*/
dispatch_namespace?: string;
/**
* The environment of the script_name to bind to.
*/
environment?: string;
/**
* Namespace identifier tag.
*/
namespace_id?: string;
/**
* The script where the Durable Object is defined, if it is external to this
* Worker.
*/
script_name?: string;
}
export interface WorkersBindingKindHyperdrive {
/**
* Identifier of the Hyperdrive connection to bind to.
*/
id: string;
/**
* A JavaScript variable name for the binding.
*/
name: string;
/**
* The kind of resource that the binding provides.
*/
type: 'hyperdrive';
}
export interface WorkersBindingKindInherit {
/**
* The name of the inherited binding.
*/
name: string;
/**
* The kind of resource that the binding provides.
*/
type: 'inherit';
/**
* The old name of the inherited binding. If set, the binding will be renamed from
* `old_name` to `name` in the new version. If not set, the binding will keep the
* same name between versions.
*/
old_name?: string;
/**
* Identifier for the version to inherit the binding from, which can be the version
* ID or the literal "latest" to inherit from the latest version. Defaults to
* inheriting the binding from the latest version.
*/
version_id?: string;
}
export interface WorkersBindingKindImages {
/**
* A JavaScript variable name for the binding.
*/
name: string;
/**
* The kind of resource that the binding provides.
*/
type: 'images';
}
export interface WorkersBindingKindJson {
/**
* JSON data to use.
*/
json: unknown;
/**
* A JavaScript variable name for the binding.
*/
name: string;
/**
* The kind of resource that the binding provides.
*/
type: 'json';
}
export interface WorkersBindingKindKVNamespace {
/**
* A JavaScript variable name for the binding.
*/
name: string;
/**
* Namespace identifier tag.
*/
namespace_id: string;
/**
* The kind of resource that the binding provides.
*/
type: 'kv_namespace';
}
export interface WorkersBindingKindMedia {
/**
* A JavaScript variable name for the binding.
*/
name: string;
/**
* The kind of resource that the binding provides.
*/
type: 'media';
}
export interface WorkersBindingKindMTLSCertificate {
/**
* Identifier of the certificate to bind to.
*/
certificate_id: string;
/**
* A JavaScript variable name for the binding.
*/
name: string;
/**
* The kind of resource that the binding provides.
*/
type: 'mtls_certificate';
}
export interface WorkersBindingKindPlainText {
/**
* A JavaScript variable name for the binding.
*/
name: string;
/**
* The text value to use.
*/
text: string;
/**
* The kind of resource that the binding provides.
*/
type: 'plain_text';
}
export interface WorkersBindingKindPipelines {
/**
* A JavaScript variable name for the binding.
*/
name: string;
/**
* Name of the Pipeline to bind to.
*/
pipeline: string;
/**
* The kind of resource that the binding provides.
*/
type: 'pipelines';
}
/**
* A K2 stream binding. Available only to accounts enabled for K2.
*/
export interface WorkersBindingKindK2 {
/**
* A JavaScript variable name for the binding.
*/
name: string;
/**
* ID of a K2 stream owned by the account deploying the Worker.
*/
stream: string;
/**
* The kind of resource that the binding provides.
*/
type: 'k2';
}
export interface WorkersBindingKindQueue {
/**
* A JavaScript variable name for the binding.
*/
name: string;
/**
* Name of the Queue to bind to.
*/
queue_name: string;
/**
* The kind of resource that the binding provides.
*/
type: 'queue';
}
export interface WorkersBindingKindRatelimit {
/**
* A JavaScript variable name for the binding.
*/
name: string;
/**
* Identifier of the rate limit namespace to bind to.
*/
namespace_id: string;
/**
* The rate limit configuration.
*/
simple: WorkersBindingKindRatelimit.Simple;
/**
* The kind of resource that the binding provides.
*/
type: 'ratelimit';
}
export namespace WorkersBindingKindRatelimit {
/**
* The rate limit configuration.
*/
export interface Simple {
/**
* The limit (requests per period).
*/
limit: number;
/**
* The period in seconds.
*/
period: number;
/**
* Duration in seconds to apply the mitigation action after the rate limit is
* exceeded. Valid values are 0 (disabled), 10, or multiples of 60 up to 86400.
* Must be greater than or equal to the period when non-zero.
*/
mitigation_timeout?: number;
}
}
export interface WorkersBindingKindR2Bucket {
/**
* R2 bucket to bind to.
*/
bucket_name: string;
/**
* A JavaScript variable name for the binding.
*/
name: string;
/**
* The kind of resource that the binding provides.
*/
type: 'r2_bucket';
/**
* The
* [jurisdiction](https://developers.cloudflare.com/r2/reference/data-location/#jurisdictional-restrictions)
* of the R2 bucket.
*/
jurisdiction?: 'eu' | 'fedramp' | 'fedramp-high' | 'us';
}
export interface WorkersBindingKindSecretText {
/**
* A JavaScript variable name for the binding.
*/
name: string;
/**
* The kind of resource that the binding provides.
*/
type: 'secret_text';
}
export interface WorkersBindingKindSendEmail {
/**
* A JavaScript variable name for the binding.
*/
name: string;
/**
* The kind of resource that the binding provides.
*/
type: 'send_email';
/**
* List of allowed destination addresses.
*/
allowed_destination_addresses?: Array<string>;
/**
* List of allowed sender addresses.
*/
allowed_sender_addresses?: Array<string>;
/**
* Destination address for the email.
*/
destination_address?: string;
}
export interface WorkersBindingKindService {
/**
* A JavaScript variable name for the binding.
*/
name: string;
/**
* Name of Worker to bind to.
*/
service: string;
/**
* The kind of resource that the binding provides.
*/
type: 'service';
/**
* Entrypoint to invoke on the target Worker.
*/
entrypoint?: string;
/**
* Optional environment if the Worker utilizes one.
*/
environment?: string;
}
export interface WorkersBindingKindTextBlob {
/**
* A JavaScript variable name for the binding.
*/
name: string;
/**
* The name of the file containing the text content. Only accepted for
* `service worker syntax` Workers.
*/
part: string;
/**
* @deprecated The kind of resource that the binding provides.
*/
type: 'text_blob';
}
export interface WorkersBindingKindVectorize {
/**
* Name of the Vectorize index to bind to.
*/
index_name: string;
/**
* A JavaScript variable name for the binding.
*/
name: string;
/**
* The kind of resource that the binding provides.
*/
type: 'vectorize';
}
export interface WorkersBindingKindVersionMetadata {
/**
* A JavaScript variable name for the binding.
*/
name: string;
/**
* The kind of resource that the binding provides.
*/
type: 'version_metadata';
}
export interface WorkersBindingKindSecretsStoreSecret {
/**
* A JavaScript variable name for the binding.
*/
name: string;
/**
* Name of the secret in the store.
*/
secret_name: string;
/**
* ID of the store containing the secret.
*/
store_id: string;
/**
* The kind of resource that the binding provides.
*/
type: 'secrets_store_secret';
}
export interface WorkersBindingKindFlagship {
/**
* ID of the Flagship app to bind to for feature flag evaluation.
*/
app_id: string;
/**
* A JavaScript variable name for the binding.
*/
name: string;
/**
* The kind of resource that the binding provides.
*/
type: 'flagship';
}
export interface WorkersBindingKindSecretKey {
/**
* Algorithm-specific key parameters.
* [Learn more](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey#algorithm).
*/
algorithm: unknown;
/**
* Data format of the key.
* [Learn more](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey#format).
*/
format: 'raw' | 'pkcs8' | 'spki' | 'jwk';
/**
* A JavaScript variable name for the binding.
*/
name: string;
/**
* The kind of resource that the binding provides.
*/
type: 'secret_key';
/**
* Allowed operations with the key.
* [Learn more](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey#keyUsages).
*/
usages: Array<
'encrypt' | 'decrypt' | 'sign' | 'verify' | 'deriveKey' | 'deriveBits' | 'wrapKey' | 'unwrapKey'
>;
}
export interface WorkersBindingKindWorkflow {
/**
* A JavaScript variable name for the binding.
*/
name: string;
/**
* The kind of resource that the binding provides.
*/
type: 'workflow';
/**
* Name of the Workflow to bind to.
*/
workflow_name: string;
/**
* Class name of the Workflow. Should only be provided if the Workflow belongs to
* this script.
*/
class_name?: string;
/**
* Script name that contains the Workflow. If not provided, defaults to this script
* name.
*/
script_name?: string;
}
export interface WorkersBindingKindWasmModule {
/**
* A JavaScript variable name for the binding.
*/
name: string;
/**
* The name of the file containing the WebAssembly module content. Only accepted
* for `service worker syntax` Workers.
*/
part: string;
/**
* @deprecated The kind of resource that the binding provides.
*/
type: 'wasm_module';
}
export interface WorkersBindingKindVPCService {
/**
* A JavaScript variable name for the binding.
*/
name: string;
/**
* Identifier of the VPC service to bind to.
*/
service_id: string;
/**
* The kind of resource that the binding provides.
*/
type: 'vpc_service';
}
export interface WorkersBindingKindVPCNetwork {
/**
* A JavaScript variable name for the binding.
*/
name: string;
/**
* The kind of resource that the binding provides.
*/
type: 'vpc_network';
/**
* Enables Gateway identity for the binding. Requires network_id to be
* "cf1:network" and cannot be combined with tunnel_id.
*/
identity?: 'runtime-email-alpha';
/**
* Identifier of the network to bind to. Only "cf1:network" is currently supported.
* Mutually exclusive with tunnel_id.
*/
network_id?: string;
/**
* UUID of the Cloudflare Tunnel to bind to. Mutually exclusive with network_id.
*/
tunnel_id?: string;
}
}
export interface BindingGetParams {
/**
* Identifier.
*/
account_id: string;
/**
* Name of the Workers for Platforms dispatch namespace.
*/
dispatch_namespace: string;
}
export declare namespace Bindings {
export {
type BindingGetResponse as BindingGetResponse,
type BindingGetResponsesSinglePage as BindingGetResponsesSinglePage,
type BindingGetParams as BindingGetParams,
};
}