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ACxFC,EACJ,OAAIF,IAAiB,mBACnBE,EAAO,MAAMR,EAAS,KAAI,EACjBM,IAAiB,2BAC1BE,EAAO,MAAMR,EAAS,KAAI,EACjBM,IAAiB,oBAC1BE,EAAOR,EACEM,IAAiB,sBAC1BE,EAAO,MAAMR,EAAS,SAAQ,EAG9BQ,EAAO,MAAMR,EAAS,KAAI,EAGrB,CAAE,KAAAQ,EAAM,MAAO,IAAI,QACnBC,EAAO,CACd,MAAO,CAAE,KAAM,KAAM,MAAAA,CAAK","names":["resolveFetch","customFetch","_fetch","args","fetch","FunctionsError","message","name","context","FunctionsFetchError","FunctionsRelayError","FunctionsHttpError","FunctionRegion","FunctionsClient","url","headers","customFetch","region","FunctionRegion","resolveFetch","token","functionName","options","method","functionArgs","_headers","body","response","fetchError","FunctionsFetchError","isRelayError","FunctionsRelayError","FunctionsHttpError","responseType","_a","data","error"],"sources":["../esm/npm/@supabase/functions-js@2.4.1/node_modules/@supabase/functions-js/src/helper.ts","../esm/npm/@supabase/functions-js@2.4.1/node_modules/@supabase/functions-js/src/types.ts","../esm/npm/@supabase/functions-js@2.4.1/node_modules/@supabase/functions-js/src/FunctionsClient.ts"],"sourcesContent":["import { Fetch } from './types'\n\nexport const resolveFetch = (customFetch?: Fetch): Fetch =\u003e {\n  let _fetch: Fetch\n  if (customFetch) {\n    _fetch = customFetch\n  } else if (typeof fetch === 'undefined') {\n    _fetch = (...args) =\u003e\n      import('@supabase/node-fetch' as any).then(({ default: fetch }) =\u003e fetch(...args))\n  } else {\n    _fetch = fetch\n  }\n  return (...args) =\u003e _fetch(...args)\n}\n","export type Fetch = typeof fetch\n\n/**\n * Response format\n *\n */\nexport interface FunctionsResponseSuccess\u003cT\u003e {\n  data: T\n  error: null\n}\nexport interface FunctionsResponseFailure {\n  data: null\n  error: any\n}\nexport type FunctionsResponse\u003cT\u003e = FunctionsResponseSuccess\u003cT\u003e | FunctionsResponseFailure\n\nexport class FunctionsError extends Error {\n  context: any\n  constructor(message: string, name = 'FunctionsError', context?: any) {\n    super(message)\n    this.name = name\n    this.context = context\n  }\n}\n\nexport class FunctionsFetchError extends FunctionsError {\n  constructor(context: any) {\n    super('Failed to send a request to the Edge Function', 'FunctionsFetchError', context)\n  }\n}\n\nexport class FunctionsRelayError extends FunctionsError {\n  constructor(context: any) {\n    super('Relay Error invoking the Edge Function', 'FunctionsRelayError', context)\n  }\n}\n\nexport class FunctionsHttpError extends FunctionsError {\n  constructor(context: any) {\n    super('Edge Function returned a non-2xx status code', 'FunctionsHttpError', context)\n  }\n}\n// Define the enum for the 'region' property\nexport enum FunctionRegion {\n  Any = 'any',\n  ApNortheast1 = 'ap-northeast-1',\n  ApNortheast2 = 'ap-northeast-2',\n  ApSouth1 = 'ap-south-1',\n  ApSoutheast1 = 'ap-southeast-1',\n  ApSoutheast2 = 'ap-southeast-2',\n  CaCentral1 = 'ca-central-1',\n  EuCentral1 = 'eu-central-1',\n  EuWest1 = 'eu-west-1',\n  EuWest2 = 'eu-west-2',\n  EuWest3 = 'eu-west-3',\n  SaEast1 = 'sa-east-1',\n  UsEast1 = 'us-east-1',\n  UsWest1 = 'us-west-1',\n  UsWest2 = 'us-west-2',\n}\n\nexport type FunctionInvokeOptions = {\n  /**\n   * Object representing the headers to send with the request.\n   * */\n  headers?: { [key: string]: string }\n  /**\n   * The HTTP verb of the request\n   */\n  method?: 'POST' | 'GET' | 'PUT' | 'PATCH' | 'DELETE'\n  /**\n   * The Region to invoke the function in.\n   */\n  region?: FunctionRegion\n  /**\n   * The body of the request.\n   */\n  body?:\n    | File\n    | Blob\n    | ArrayBuffer\n    | FormData\n    | ReadableStream\u003cUint8Array\u003e\n    | Record\u003cstring, any\u003e\n    | string\n}\n","import { resolveFetch } from './helper'\nimport {\n  Fetch,\n  FunctionsFetchError,\n  FunctionsHttpError,\n  FunctionsRelayError,\n  FunctionsResponse,\n  FunctionInvokeOptions,\n  FunctionRegion,\n} from './types'\n\nexport class FunctionsClient {\n  protected url: string\n  protected headers: Record\u003cstring, string\u003e\n  protected region: FunctionRegion\n  protected fetch: Fetch\n\n  constructor(\n    url: string,\n    {\n      headers = {},\n      customFetch,\n      region = FunctionRegion.Any,\n    }: {\n      headers?: Record\u003cstring, string\u003e\n      customFetch?: Fetch\n      region?: FunctionRegion\n    } = {}\n  ) {\n    this.url = url\n    this.headers = headers\n    this.region = region\n    this.fetch = resolveFetch(customFetch)\n  }\n\n  /**\n   * Updates the authorization header\n   * @param token - the new jwt token sent in the authorisation header\n   */\n  setAuth(token: string) {\n    this.headers.Authorization = `Bearer ${token}`\n  }\n\n  /**\n   * Invokes a function\n   * @param functionName - The name of the Function to invoke.\n   * @param options - Options for invoking the Function.\n   */\n  async invoke\u003cT = any\u003e(\n    functionName: string,\n    options: FunctionInvokeOptions = {}\n  ): Promise\u003cFunctionsResponse\u003cT\u003e\u003e {\n    try {\n      const { headers, method, body: functionArgs } = options\n      let _headers: Record\u003cstring, string\u003e = {}\n      let { region } = options\n      if (!region) {\n        region = this.region\n      }\n      if (region \u0026\u0026 region !== 'any') {\n        _headers['x-region'] = region\n      }\n      let body: any\n      if (\n        functionArgs \u0026\u0026\n        ((headers \u0026\u0026 !Object.prototype.hasOwnProperty.call(headers, 'Content-Type')) || !headers)\n      ) {\n        if (\n          (typeof Blob !== 'undefined' \u0026\u0026 functionArgs instanceof Blob) ||\n          functionArgs instanceof ArrayBuffer\n        ) {\n          // will work for File as File inherits Blob\n          // also works for ArrayBuffer as it is the same underlying structure as a Blob\n          _headers['Content-Type'] = 'application/octet-stream'\n          body = functionArgs\n        } else if (typeof functionArgs === 'string') {\n          // plain string\n          _headers['Content-Type'] = 'text/plain'\n          body = functionArgs\n        } else if (typeof FormData !== 'undefined' \u0026\u0026 functionArgs instanceof FormData) {\n          // don't set content-type headers\n          // Request will automatically add the right boundary value\n          body = functionArgs\n        } else {\n          // default, assume this is JSON\n          _headers['Content-Type'] = 'application/json'\n          body = JSON.stringify(functionArgs)\n        }\n      }\n\n      const response = await this.fetch(`${this.url}/${functionName}`, {\n        method: method || 'POST',\n        // headers priority is (high to low):\n        // 1. invoke-level headers\n        // 2. client-level headers\n        // 3. default Content-Type header\n        headers: { ..._headers, ...this.headers, ...headers },\n        body,\n      }).catch((fetchError) =\u003e {\n        throw new FunctionsFetchError(fetchError)\n      })\n\n      const isRelayError = response.headers.get('x-relay-error')\n      if (isRelayError \u0026\u0026 isRelayError === 'true') {\n        throw new FunctionsRelayError(response)\n      }\n\n      if (!response.ok) {\n        throw new FunctionsHttpError(response)\n      }\n\n      let responseType = (response.headers.get('Content-Type') ?? 'text/plain').split(';')[0].trim()\n      let data: any\n      if (responseType === 'application/json') {\n        data = await response.json()\n      } else if (responseType === 'application/octet-stream') {\n        data = await response.blob()\n      } else if (responseType === 'text/event-stream') {\n        data = response\n      } else if (responseType === 'multipart/form-data') {\n        data = await response.formData()\n      } else {\n        // default to text\n        data = await response.text()\n      }\n\n      return { data, error: null }\n    } catch (error) {\n      return { data: null, error }\n    }\n  }\n}\n"],"version":3}
