// AUTO-GENERATED by scripts/generate.ts from .generated-specs. Do not edit. import * as S from "@distilled.cloud/core/schema"; import * as API from "@distilled.cloud/core/api"; import * as T from "../traits.ts"; import { CloudflareProtocol, CloudflarePaginatedProtocol, type CloudflareOpError, type CloudflareOpContext, } from "../protocol.ts"; import { cloudflarePaginate, ResultInfo } from "../pagination.ts"; import { CloudflareError, CloudflareRateLimited } from "../errors.ts"; import * as Retry from "../retry.ts"; export type { CloudflareOpError, CloudflareOpContext }; /** Fallback camelCase→wire mapping for opaque content (mined from the distilled SDK). */ const KEY_DICTIONARY: Record> = { createdOn: "created_on", mainModule: "main_module", modifiedOn: "modified_on", perPage: "per_page", resultInfo: "result_info", snippetName: "snippet_name", totalCount: "total_count", }; export class Forbidden extends /*@__PURE__*/ T.applyErrorMatchers( /*@__PURE__*/ S.TaggedError()("Forbidden", { code: S.Number, message: S.String, }), [{ status: 403 }], ) {} export class SnippetInUse extends /*@__PURE__*/ T.applyErrorMatchers( /*@__PURE__*/ S.TaggedError()("SnippetInUse", { code: S.Number, message: S.String, }), [ { status: 400, message: { includes: "still used" } }, { status: 409, message: { includes: "still used" } }, ], ) {} export class SnippetNotFound extends /*@__PURE__*/ T.applyErrorMatchers( /*@__PURE__*/ S.TaggedError()("SnippetNotFound", { code: S.Number, message: S.String, }), [ { status: 400, message: { includes: "snippet not found" } }, { status: 404 }, ], ) {} export class SnippetRulesNotFound extends /*@__PURE__*/ T.applyErrorMatchers( /*@__PURE__*/ S.TaggedError()( "SnippetRulesNotFound", { code: S.Number, message: S.String, }, ), [{ status: 404 }], ) {} export interface DeleteRuleRequest { /** Use this field to specify the unique ID of the zone. */ zoneId: string; } export const DeleteRuleRequest = /*@__PURE__*/ S.suspend(() => S.Struct({ zoneId: S.String.pipe(T.Label("zone_id")), }) .pipe( T.Http({ method: "DELETE", uri: "/zones/{zone_id}/snippets/snippet_rules", code: 200, }), ) .pipe(T.KeyDictionary(KEY_DICTIONARY)), ).annotate({ identifier: "DeleteRuleRequest", }) as any as S.Schema; export type DeleteRuleResponse = unknown; export const DeleteRuleResponse = /*@__PURE__*/ S.suspend(() => S.Unknown.pipe(T.EnvelopePayloadRoot(), T.KeyDictionary(KEY_DICTIONARY)), ).annotate({ identifier: "DeleteRuleResponse", }) as any as S.Schema; export interface DeleteSnippetRequest { /** Use this field to specify the unique ID of the zone. */ zoneId: string; /** Identify the snippet. */ snippetName: string; } export const DeleteSnippetRequest = /*@__PURE__*/ S.suspend(() => S.Struct({ zoneId: S.String.pipe(T.Label("zone_id")), snippetName: S.String.pipe(T.Label("snippet_name")), }) .pipe( T.Http({ method: "DELETE", uri: "/zones/{zone_id}/snippets/{snippet_name}", code: 200, }), ) .pipe(T.KeyDictionary(KEY_DICTIONARY)), ).annotate({ identifier: "DeleteSnippetRequest", }) as any as S.Schema; export type DeleteSnippetResponse = unknown; export const DeleteSnippetResponse = /*@__PURE__*/ S.suspend(() => S.Unknown.pipe(T.EnvelopePayloadRoot(), T.KeyDictionary(KEY_DICTIONARY)), ).annotate({ identifier: "DeleteSnippetResponse", }) as any as S.Schema; export interface GetContentRequest { /** Use this field to specify the unique ID of the zone. */ zoneId: string; /** Identify the snippet. */ snippetName: string; } export const GetContentRequest = /*@__PURE__*/ S.suspend(() => S.Struct({ zoneId: S.String.pipe(T.Label("zone_id")), snippetName: S.String.pipe(T.Label("snippet_name")), }) .pipe( T.Http({ method: "GET", uri: "/zones/{zone_id}/snippets/{snippet_name}/content", code: 200, }), ) .pipe(T.KeyDictionary(KEY_DICTIONARY)), ).annotate({ identifier: "GetContentRequest", }) as any as S.Schema; export interface GetContentResponse {} export const GetContentResponse = /*@__PURE__*/ S.suspend(() => S.Struct({}).pipe(T.KeyDictionary(KEY_DICTIONARY)), ).annotate({ identifier: "GetContentResponse", }) as any as S.Schema; export interface GetSnippetRequest { /** Use this field to specify the unique ID of the zone. */ zoneId: string; /** Identify the snippet. */ snippetName: string; } export const GetSnippetRequest = /*@__PURE__*/ S.suspend(() => S.Struct({ zoneId: S.String.pipe(T.Label("zone_id")), snippetName: S.String.pipe(T.Label("snippet_name")), }) .pipe( T.Http({ method: "GET", uri: "/zones/{zone_id}/snippets/{snippet_name}", code: 200, }), ) .pipe(T.KeyDictionary(KEY_DICTIONARY)), ).annotate({ identifier: "GetSnippetRequest", }) as any as S.Schema; /** Unwrapped `result` payload of the Cloudflare v4 response envelope. */ export interface GetSnippetResponse { /** Indicates when the snippet was created. */ createdOn: string; /** Identify the snippet. */ snippetName: string; /** Indicates when the snippet was last modified. */ modifiedOn?: string | null; } export const GetSnippetResponse = /*@__PURE__*/ S.suspend(() => S.Struct({ createdOn: S.String.pipe(T.Body("created_on")), snippetName: S.String.pipe(T.Body("snippet_name")), modifiedOn: S.optional(S.NullOr(S.String).pipe(T.Body("modified_on"))), }).pipe(T.KeyDictionary(KEY_DICTIONARY)), ).annotate({ identifier: "GetSnippetResponse", }) as any as S.Schema; export interface ListRulesRequest { /** Use this field to specify the unique ID of the zone. */ zoneId: string; } export const ListRulesRequest = /*@__PURE__*/ S.suspend(() => S.Struct({ zoneId: S.String.pipe(T.Label("zone_id")), }) .pipe( T.Http({ method: "GET", uri: "/zones/{zone_id}/snippets/snippet_rules", code: 200, }), ) .pipe(T.KeyDictionary(KEY_DICTIONARY)), ).annotate({ identifier: "ListRulesRequest", }) as any as S.Schema; export type ListRulesResponse = unknown; export const ListRulesResponse = /*@__PURE__*/ S.suspend(() => S.Unknown.pipe(T.EnvelopePayloadRoot(), T.KeyDictionary(KEY_DICTIONARY)), ).annotate({ identifier: "ListRulesResponse", }) as any as S.Schema; export interface ListSnippetsRequest { /** Use this field to specify the unique ID of the zone. */ zoneId: string; /** Specifies the current page number. */ page?: number; /** Specifies how many results to return per page. */ perPage?: number; } export const ListSnippetsRequest = /*@__PURE__*/ S.suspend(() => S.Struct({ zoneId: S.String.pipe(T.Label("zone_id")), page: S.optional(S.Number.pipe(T.Query())), perPage: S.optional(S.Number.pipe(T.Query("per_page"))), }) .pipe( T.Http({ method: "GET", uri: "/zones/{zone_id}/snippets", code: 200 }), ) .pipe(T.KeyDictionary(KEY_DICTIONARY)), ).annotate({ identifier: "ListSnippetsRequest", }) as any as S.Schema; export interface ListResultItem { /** Indicates when the snippet was created. */ createdOn: string; /** Identify the snippet. */ snippetName: string; /** Indicates when the snippet was last modified. */ modifiedOn?: string | null; } export const ListResultItem = /*@__PURE__*/ S.suspend(() => S.Struct({ createdOn: S.String.pipe(T.Body("created_on")), snippetName: S.String.pipe(T.Body("snippet_name")), modifiedOn: S.optional(S.NullOr(S.String).pipe(T.Body("modified_on"))), }), ).annotate({ identifier: "ListResultItem" }) as any as S.Schema; export type ListResultList = Array; export const ListResultList = /*@__PURE__*/ S.Array( ListResultItem, ) as any as S.Schema; export interface ListSnippetsResponse { /** The unwrapped `result` payload of the v4 response envelope. */ result: ListResultList; /** Pagination info from the envelope's `result_info`. */ resultInfo?: ResultInfo | null; } export const ListSnippetsResponse = /*@__PURE__*/ S.suspend(() => S.Struct({ result: ListResultList.pipe(T.EnvelopePayload()), resultInfo: S.optional(S.NullOr(ResultInfo).pipe(T.ResultInfo())), }).pipe(T.KeyDictionary(KEY_DICTIONARY)), ).annotate({ identifier: "ListSnippetsResponse", }) as any as S.Schema; export interface RulesUpdateRequestRulesItem { /** Define the expression that determines which traffic matches the rule. */ expression: string; /** Identify the snippet. */ snippetName: string; /** Provide an informative description of the rule. */ description?: string; /** Indicate whether to execute the rule. */ enabled?: boolean; } export const RulesUpdateRequestRulesItem = /*@__PURE__*/ S.suspend(() => S.Struct({ expression: S.String, snippetName: S.String.pipe(T.Body("snippet_name")), description: S.optional(S.String), enabled: S.optional(S.Boolean), }), ).annotate({ identifier: "RulesUpdateRequestRulesItem", }) as any as S.Schema; export type RulesUpdateRequestRulesList = Array; export const RulesUpdateRequestRulesList = /*@__PURE__*/ S.Array( RulesUpdateRequestRulesItem, ) as any as S.Schema; export interface PutRuleRequest { /** Use this field to specify the unique ID of the zone. */ zoneId: string; /** Lists snippet rules. */ rules: RulesUpdateRequestRulesList; } export const PutRuleRequest = /*@__PURE__*/ S.suspend(() => S.Struct({ zoneId: S.String.pipe(T.Label("zone_id")), rules: RulesUpdateRequestRulesList, }) .pipe( T.Http({ method: "PUT", uri: "/zones/{zone_id}/snippets/snippet_rules", code: 200, }), ) .pipe(T.KeyDictionary(KEY_DICTIONARY)), ).annotate({ identifier: "PutRuleRequest" }) as any as S.Schema; export type PutRuleResponse = unknown; export const PutRuleResponse = /*@__PURE__*/ S.suspend(() => S.Unknown.pipe(T.EnvelopePayloadRoot(), T.KeyDictionary(KEY_DICTIONARY)), ).annotate({ identifier: "PutRuleResponse", }) as any as S.Schema; export interface PutSnippetRequest { /** Use this field to specify the unique ID of the zone. */ zoneId: string; /** Identify the snippet. */ snippetName: string; /** Snippet metadata ({ mainModule }), JSON-encoded as the multipart `metadata` part. */ metadata: unknown; /** Snippet module file(s), appended under their own filenames. */ files?: File | Blob | (File | Blob)[]; } export const PutSnippetRequest = /*@__PURE__*/ S.suspend(() => S.Struct({ zoneId: S.String.pipe(T.Label("zone_id")), snippetName: S.String.pipe(T.Label("snippet_name")), metadata: S.Unknown, files: S.optional(S.Unknown.pipe(T.FormDataFile())), }) .pipe( T.Http({ method: "PUT", uri: "/zones/{zone_id}/snippets/{snippet_name}", code: 200, contentType: "multipart", }), ) .pipe(T.KeyDictionary(KEY_DICTIONARY)), ).annotate({ identifier: "PutSnippetRequest", }) as any as S.Schema; /** Unwrapped `result` payload of the Cloudflare v4 response envelope. */ export interface PutSnippetResponse { /** Indicates when the snippet was created. */ createdOn: string; /** Identify the snippet. */ snippetName: string; /** Indicates when the snippet was last modified. */ modifiedOn?: string | null; } export const PutSnippetResponse = /*@__PURE__*/ S.suspend(() => S.Struct({ createdOn: S.String.pipe(T.Body("created_on")), snippetName: S.String.pipe(T.Body("snippet_name")), modifiedOn: S.optional(S.NullOr(S.String).pipe(T.Body("modified_on"))), }).pipe(T.KeyDictionary(KEY_DICTIONARY)), ).annotate({ identifier: "PutSnippetResponse", }) as any as S.Schema; export type DeleteRuleError = | SnippetRulesNotFound | Forbidden | CloudflareOpError; /** Deletes all snippet rules belonging to the zone. */ export const deleteRule: API.OperationMethod< DeleteRuleRequest, DeleteRuleResponse, DeleteRuleError, CloudflareOpContext > = /*@__PURE__*/ API.make(() => ({ input: DeleteRuleRequest, output: DeleteRuleResponse, errors: [ SnippetRulesNotFound, Forbidden, CloudflareRateLimited, CloudflareError, ], protocol: CloudflareProtocol, retry: Retry.Retry, })); export type DeleteSnippetError = | SnippetNotFound | SnippetInUse | CloudflareOpError; /** Deletes a snippet belonging to the zone. */ export const deleteSnippet: API.OperationMethod< DeleteSnippetRequest, DeleteSnippetResponse, DeleteSnippetError, CloudflareOpContext > = /*@__PURE__*/ API.make(() => ({ input: DeleteSnippetRequest, output: DeleteSnippetResponse, errors: [ SnippetNotFound, SnippetInUse, CloudflareRateLimited, CloudflareError, ], protocol: CloudflareProtocol, retry: Retry.Retry, })); export type GetContentError = CloudflareOpError; /** Fetches the content of a snippet belonging to the zone. */ export const getContent: API.OperationMethod< GetContentRequest, GetContentResponse, GetContentError, CloudflareOpContext > = /*@__PURE__*/ API.make(() => ({ input: GetContentRequest, output: GetContentResponse, errors: [CloudflareRateLimited, CloudflareError], protocol: CloudflareProtocol, retry: Retry.Retry, })); export type GetSnippetError = SnippetNotFound | CloudflareOpError; /** Fetches a snippet belonging to the zone. */ export const getSnippet: API.OperationMethod< GetSnippetRequest, GetSnippetResponse, GetSnippetError, CloudflareOpContext > = /*@__PURE__*/ API.make(() => ({ input: GetSnippetRequest, output: GetSnippetResponse, errors: [SnippetNotFound, CloudflareRateLimited, CloudflareError], protocol: CloudflareProtocol, retry: Retry.Retry, })); export type ListRulesError = | SnippetRulesNotFound | Forbidden | CloudflareOpError; /** Fetches all snippet rules belonging to the zone. */ export const listRules: API.OperationMethod< ListRulesRequest, ListRulesResponse, ListRulesError, CloudflareOpContext > = /*@__PURE__*/ API.make(() => ({ input: ListRulesRequest, output: ListRulesResponse, errors: [ SnippetRulesNotFound, Forbidden, CloudflareRateLimited, CloudflareError, ], protocol: CloudflareProtocol, retry: Retry.Retry, })); export type ListSnippetsError = Forbidden | CloudflareOpError; /** Fetches all snippets belonging to the zone. */ export const listSnippets: API.PaginatedOperationMethod< ListSnippetsRequest, ListSnippetsResponse, ListSnippetsError, CloudflareOpContext, ListResultItem > = /*@__PURE__*/ API.makePaginated( () => ({ input: ListSnippetsRequest, output: ListSnippetsResponse, errors: [Forbidden, CloudflareRateLimited, CloudflareError], protocol: CloudflarePaginatedProtocol, retry: Retry.Retry, pagination: { mode: "page", inputToken: "page", outputToken: "resultInfo.page", items: "result", pageSize: "perPage", } as const, }), cloudflarePaginate, ) as any; export type PutRuleError = CloudflareOpError; /** Updates all snippet rules belonging to the zone. */ export const putRule: API.OperationMethod< PutRuleRequest, PutRuleResponse, PutRuleError, CloudflareOpContext > = /*@__PURE__*/ API.make(() => ({ input: PutRuleRequest, output: PutRuleResponse, errors: [CloudflareRateLimited, CloudflareError], protocol: CloudflareProtocol, retry: Retry.Retry, })); export type PutSnippetError = CloudflareOpError; /** Creates or updates a snippet belonging to the zone. */ export const putSnippet: API.OperationMethod< PutSnippetRequest, PutSnippetResponse, PutSnippetError, CloudflareOpContext > = /*@__PURE__*/ API.make(() => ({ input: PutSnippetRequest, output: PutSnippetResponse, errors: [CloudflareRateLimited, CloudflareError], protocol: CloudflareProtocol, retry: Retry.Retry, }));