import { AuthData } from './APL/index.js'; import { HasAPL } from './saleor-app.js'; import { SaleorSchemaVersion } from './types.js'; type HookCallbackErrorParams = { status?: number; message?: string; }; type CallbackErrorHandler = (params: HookCallbackErrorParams) => never; type GenericCreateAppRegisterHandlerOptions = HasAPL & { /** * Protect app from being registered in Saleor other than specific. * By default, allow everything. * * Provide array of either a full Saleor API URL (eg. my-shop.saleor.cloud/graphql/) * or a function that receives a full Saleor API URL ad returns true/false. */ allowedSaleorUrls?: Array boolean)>; /** * Run right after Saleor calls this endpoint */ onRequestStart?(request: RequestType, context: { authToken?: string; saleorApiUrl?: string; respondWithError: CallbackErrorHandler; }): Promise; /** * Run after all security checks */ onRequestVerified?(request: RequestType, context: { authData: AuthData; respondWithError: CallbackErrorHandler; }): Promise; /** * Run after APL successfully AuthData, assuming that APL.set will reject a Promise in case of error */ onAuthAplSaved?(request: RequestType, context: { authData: AuthData; respondWithError: CallbackErrorHandler; }): Promise; /** * Run after APL fails to set AuthData */ onAplSetFailed?(request: RequestType, context: { authData: AuthData; error: unknown; respondWithError: CallbackErrorHandler; }): Promise; }; declare const HTTPMethod: { readonly GET: "GET"; readonly POST: "POST"; readonly PUT: "PUT"; readonly PATH: "PATCH"; readonly HEAD: "HEAD"; readonly OPTIONS: "OPTIONS"; readonly DELETE: "DELETE"; }; type HTTPMethod = (typeof HTTPMethod)[keyof typeof HTTPMethod]; /** Status code of the result, for most platforms it's mapped to HTTP status code * however when request is not HTTP it can be mapped to something else */ type ResultStatusCodes = number; /** Shape of result that should be returned from use case * that is then translated by adapter to a valid platform response */ type ActionHandlerResult = { status: ResultStatusCodes; body: Body; bodyType: "json"; } | { status: ResultStatusCodes; body: string; bodyType: "string"; }; /** * Interface for adapters that translate specific platform objects (e.g. Web API, Next.js) * into a common interface that can be used in each handler use case * */ interface PlatformAdapterInterface { send(result: ActionHandlerResult): unknown; getHeader(name: string): string | null; getBody(): Promise; getRawBody(): Promise; getBaseUrl(): string; method: HTTPMethod; request: Request; } /** Interfaces for use case handlers that encapsulate business logic * (e.g. validating headers, checking HTTP method, etc. ) */ interface ActionHandlerInterface { handleAction(...params: [unknown]): Promise>; } declare const WebhookErrorCodeMap: Record; type SaleorWebhookError = "OTHER" | "MISSING_HOST_HEADER" | "MISSING_DOMAIN_HEADER" | "MISSING_API_URL_HEADER" | "MISSING_EVENT_HEADER" | "MISSING_PAYLOAD_HEADER" | "MISSING_SIGNATURE_HEADER" | "MISSING_REQUEST_BODY" | "WRONG_EVENT" | "NOT_REGISTERED" | "SIGNATURE_VERIFICATION_FAILED" | "WRONG_METHOD" | "CANT_BE_PARSED" | "CONFIGURATION_ERROR"; declare class WebhookError extends Error { errorType: SaleorWebhookError; constructor(message: string, errorType: SaleorWebhookError); } type WebhookContext = { baseUrl: string; event: string; payload: TPayload; authData: AuthData; /** * Schema version is passed in subscription payload. Webhook must request it, otherwise it will be null. * If subscription contains version, it will be parsed to SaleorSchemaVersion */ schemaVersion: SaleorSchemaVersion | null; }; type FormatWebhookErrorResult = { code: number; body: string; }; export { type ActionHandlerResult as A, type CallbackErrorHandler as C, type FormatWebhookErrorResult as F, type GenericCreateAppRegisterHandlerOptions as G, type HookCallbackErrorParams as H, type PlatformAdapterInterface as P, type ResultStatusCodes as R, type SaleorWebhookError as S, WebhookErrorCodeMap as W, HTTPMethod as a, type ActionHandlerInterface as b, WebhookError as c, type WebhookContext as d };