import type { Adapter } from "../../index.js"; import { FilesError } from "../../internal/errors.js"; import type { EventFormat, FileEvent } from "../../internal/events.js"; import type { JsonObject, JsonValue } from "../../internal/json.js"; export type { EventFormat } from "../../internal/events.js"; /** * One delivery: a decoded JSON object (arrays arrive split into one delivery * per element), plus the HTTP headers when it came in as a request. */ export interface Delivery { body: JsonObject; headers?: Headers; } /** A parsed event before the plugin maps it onto the instance. */ export type RawEvent = Omit & { /** The bucket / container the notification is for, when the delivery says. */ bucket?: string; }; /** What a parser may read about the instance: the adapter, for formats whose keys depend on its config (Box's root folder, Cloudinary's resource type). */ export interface ParseContext { adapter: Adapter; } /** A webhook delivery to check against a provider signature. */ export interface SignatureCheck { /** The raw body, exactly as received. */ body: string; headers: Headers; secret: string; /** Box's secondary signature key. */ secondarySecret?: string; /** Appwrite signs the webhook URL as configured, so the verifier needs it. */ url?: string; /** ms since the epoch, for timestamp freshness checks. */ now: number; } export interface EventParser { readonly format: EventFormat; /** Normalize one delivery. Events the format reports that aren't a create or delete parse to nothing. */ parse: (delivery: Delivery, context: ParseContext) => RawEvent[]; /** * Check the provider's own delivery signature (`verify: { secret }`), * throwing `Unauthorized` when it doesn't match. Formats without one take a * shared `token` instead. */ verifySignature?: (check: SignatureCheck) => Promise; /** * A webhook handshake the format requires before it delivers (Event Grid's * subscription validation, the CloudEvents `OPTIONS` abuse-protection check). * Returns the response to send, or `undefined` for an ordinary delivery. */ handshake?: (req: Request, deliveries: readonly Delivery[]) => Response | undefined; } /** A delivery that isn't the shape the format documents. `Invalid`: redelivering it won't help. */ export declare const malformed: (format: EventFormat, detail: string) => FilesError; /** * The text of a Google Pub/Sub message's `data`: base64 on the wire, a Buffer * from the Node client library. `undefined` when the message carries none. */ export declare const pubsubText: (data: JsonValue | Uint8Array | undefined, format: EventFormat) => string | undefined; /** A delivery whose credential or signature doesn't check out. */ export declare const unauthorized: (detail: string) => FilesError; /** Parse a timestamp the way providers send them (ISO 8601 or epoch ms), else `fallback`. */ export declare const toTime: (value: JsonValue | undefined, fallback: number) => number; /** A size providers send as a number or a decimal string. */ export declare const toSize: (value: JsonValue | undefined) => number | undefined; /** * The part of an event id that tells one change to a key from another, for a * record with no id of its own: the `stamps` it carries (a sequencer, a * version, its own timestamp, an ETag — exactly as sent), joined, else a hash * of the whole record. Never the clock, which would give every redelivery a * new id and defeat `dedupe`. */ export declare const stampOf: (record: JsonValue, ...stamps: (JsonValue | undefined)[]) => string; /** An ETag without its surrounding quotes (the SDK reports them bare). */ export declare const bareEtag: (value: JsonValue | undefined) => string | undefined; //# sourceMappingURL=types.d.ts.map