export type StoreId = string; export type EventCallbackError = {errorCode?: ('CANCELLED' | 'UNKNOWN' | 'INVALID_ARGUMENT' | 'FAILED_PRECONDITION' | 'DEADLINE_EXCEEDED' | 'NOT_FOUND' | 'PERMISSION_DENIED' | 'ALREADY_EXISTS' | 'RESOURCE_EXHAUSTED' | 'ABORTED' | 'OUT_OF_RANGE' | 'UNIMPLEMENTED' | 'INTERNAL' | 'UNAVAILABLE' | 'DATA_LOSS' | 'UNAUTHENTICATED') | undefined, errorMessage?: (string | null) | undefined}; export type CreateApiV1CallbackErrorArgs = {'X-Store-Id': StoreId, 'X-Event-Id': string, body: EventCallbackError}; export type CreateApiV1CallbackErrorOptions = {baseUrl?: string | undefined, OAuth20?: string | undefined, fetch?: typeof fetch | undefined}; /** * Publish callback error * * POST /v1/callback/error */ export const createApiV1CallbackError = async (args: CreateApiV1CallbackErrorArgs, options?: CreateApiV1CallbackErrorOptions) => { const {baseUrl = "https://partners.tryotter.com", fetch: fetchFn = fetch, OAuth20} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (args['X-Store-Id'] != null) headers.set("X-Store-Id", String(args['X-Store-Id'])) if (args['X-Event-Id'] != null) headers.set("X-Event-Id", String(args['X-Event-Id'])) if (OAuth20 !== undefined) headers.set('authorization', `Bearer ${OAuth20}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/callback/error${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };