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CAChD,OAAQY,GAAU,OAKlB,QAAO,OAAA,OAAA,OAAA,OAAA,OAAA,OAAA,CAAA,EAAOI,CAAQ,EAAK,KAAK,OAAO,EAAKf,CAAO,EACnD,KAAAgB,EACA,OAAQC,EACT,EAAE,MAAOE,GAAc,CACtB,MAAM,IAAIC,EAAoBD,CAAU,CAC1C,CAAC,EAEKE,EAAeH,EAAS,QAAQ,IAAI,eAAe,EACzD,GAAIG,GAAgBA,IAAiB,OACnC,MAAM,IAAIC,EAAoBJ,CAAQ,EAGxC,GAAI,CAACA,EAAS,GACZ,MAAM,IAAIK,EAAmBL,CAAQ,EAGvC,IAAIM,IAAgBC,EAAAP,EAAS,QAAQ,IAAI,cAAc,KAAC,MAAAO,IAAA,OAAAA,EAAI,cAAc,MAAM,GAAG,EAAE,CAAC,EAAE,KAAI,EACxFC,EACJ,OAAIF,IAAiB,mBACnBE,EAAO,MAAMR,EAAS,KAAI,EAE1BM,IAAiB,4BACjBA,IAAiB,kBAEjBE,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,KAAM,SAAAR,CAAQ,CACtC,OAASS,EAAO,CACd,MAAO,CACL,KAAM,KACN,MAAAA,EACA,SACEA,aAAiBJ,GAAsBI,aAAiBL,EACpDK,EAAM,QACN,OAEV,SAEMlB,GACF,aAAaA,CAAS,CAE1B,CACF,CAAC","names":["resolveFetch","customFetch","args","FunctionsError","message","name","context","FunctionsFetchError","FunctionsRelayError","FunctionsHttpError","FunctionRegion","FunctionsClient","url","headers","customFetch","region","FunctionRegion","resolveFetch","token","functionName_1","functionName","options","timeoutId","timeoutController","method","functionArgs","signal","timeout","_headers","body","effectiveSignal","response","fetchError","FunctionsFetchError","isRelayError","FunctionsRelayError","FunctionsHttpError","responseType","_a","data","error"],"sources":["../esm/npm/@supabase/functions-js@2.105.4/node_modules/@supabase/functions-js/src/helper.ts","../esm/npm/@supabase/functions-js@2.105.4/node_modules/@supabase/functions-js/src/types.ts","../esm/npm/@supabase/functions-js@2.105.4/node_modules/@supabase/functions-js/src/FunctionsClient.ts"],"sourcesContent":["import { Fetch } from './types'\n\nexport const resolveFetch = (customFetch?: Fetch): Fetch =\u003e {\n  if (customFetch) {\n    return (...args) =\u003e customFetch(...args)\n  }\n  return (...args) =\u003e fetch(...args)\n}\n","export type Fetch = typeof fetch\n\n/**\n * Response format\n */\nexport interface FunctionsResponseSuccess\u003cT\u003e {\n  data: T\n  error: null\n  response?: Response\n}\nexport interface FunctionsResponseFailure {\n  data: null\n  error: any\n  response?: Response\n}\nexport type FunctionsResponse\u003cT\u003e = FunctionsResponseSuccess\u003cT\u003e | FunctionsResponseFailure\n\n/**\n * Base error for Supabase Edge Function invocations.\n *\n * @example\n * ```ts\n * import { FunctionsError } from '@supabase/functions-js'\n *\n * throw new FunctionsError('Unexpected error invoking function', 'FunctionsError', {\n *   requestId: 'abc123',\n * })\n * ```\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  toJSON(): { name: string; message: string; context: any } {\n    return {\n      name: this.name,\n      message: this.message,\n      context: this.context,\n    }\n  }\n}\n\n/**\n * Error thrown when the network request to an Edge Function fails.\n *\n * @example\n * ```ts\n * import { FunctionsFetchError } from '@supabase/functions-js'\n *\n * throw new FunctionsFetchError({ requestId: 'abc123' })\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\n/**\n * Error thrown when the Supabase relay cannot reach the Edge Function.\n *\n * @example\n * ```ts\n * import { FunctionsRelayError } from '@supabase/functions-js'\n *\n * throw new FunctionsRelayError({ region: 'us-east-1' })\n * ```\n */\nexport class FunctionsRelayError extends FunctionsError {\n  constructor(context: any) {\n    super('Relay Error invoking the Edge Function', 'FunctionsRelayError', context)\n  }\n}\n\n/**\n * Error thrown when the Edge Function returns a non-2xx status code.\n *\n * @example\n * ```ts\n * import { FunctionsHttpError } from '@supabase/functions-js'\n *\n * throw new FunctionsHttpError({ status: 500 })\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   * The AbortSignal to use for the request.\n   * */\n  signal?: AbortSignal\n  /**\n   * The timeout for the request in milliseconds.\n   * If the function takes longer than this, the request will be aborted.\n   * */\n  timeout?: number\n}\n","import { resolveFetch } from './helper'\nimport {\n  Fetch,\n  FunctionInvokeOptions,\n  FunctionRegion,\n  FunctionsFetchError,\n  FunctionsHttpError,\n  FunctionsRelayError,\n  FunctionsResponse,\n} from './types'\n\n/**\n * Client for invoking Supabase Edge Functions.\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  /**\n   * Creates a new Functions client bound to an Edge Functions URL.\n   *\n   * @example Using supabase-js (recommended)\n   * ```ts\n   * import { createClient } from '@supabase/supabase-js'\n   *\n   * const supabase = createClient('https://xyzcompany.supabase.co', 'your-publishable-key')\n   * const { data, error } = await supabase.functions.invoke('hello-world')\n   * ```\n   *\n   * @category Edge Functions\n   *\n   * @example Standalone import for bundle-sensitive environments\n   * ```ts\n   * import { FunctionsClient, FunctionRegion } from '@supabase/functions-js'\n   *\n   * const functions = new FunctionsClient('https://xyzcompany.supabase.co/functions/v1', {\n   *   headers: { apikey: 'your-publishable-key' },\n   *   region: FunctionRegion.UsEast1,\n   * })\n   * ```\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   * @category Edge Functions\n   *\n   * @example Setting the authorization header\n   * ```ts\n   * functions.setAuth(session.access_token)\n   * ```\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   * @example\n   * ```ts\n   * const { data, error } = await functions.invoke('hello-world', {\n   *   body: { name: 'Ada' },\n   * })\n   * ```\n   *\n   * @category Edge Functions\n   *\n   * @remarks\n   * - Requires an Authorization header.\n   * - Invoke params generally match the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) spec.\n   * - When you pass in a body to your function, we automatically attach the Content-Type header for `Blob`, `ArrayBuffer`, `File`, `FormData` and `String`. If it doesn't match any of these types we assume the payload is `json`, serialize it and attach the `Content-Type` header as `application/json`. You can override this behavior by passing in a `Content-Type` header of your own.\n   * - Responses are automatically parsed as `json`, `blob` and `form-data` depending on the `Content-Type` header sent by your function. Responses are parsed as `text` by default.\n   *\n   * @example Basic invocation\n   * ```js\n   * const { data, error } = await supabase.functions.invoke('hello', {\n   *   body: { foo: 'bar' }\n   * })\n   * ```\n   *\n   * @exampleDescription Error handling\n   * A `FunctionsHttpError` error is returned if your function throws an error, `FunctionsRelayError` if the Supabase Relay has an error processing your function and `FunctionsFetchError` if there is a network error in calling your function.\n   *\n   * @example Error handling\n   * ```js\n   * import { FunctionsHttpError, FunctionsRelayError, FunctionsFetchError } from \"@supabase/supabase-js\";\n   *\n   * const { data, error } = await supabase.functions.invoke('hello', {\n   *   headers: {\n   *     \"my-custom-header\": 'my-custom-header-value'\n   *   },\n   *   body: { foo: 'bar' }\n   * })\n   *\n   * if (error instanceof FunctionsHttpError) {\n   *   const errorMessage = await error.context.json()\n   *   console.log('Function returned an error', errorMessage)\n   * } else if (error instanceof FunctionsRelayError) {\n   *   console.log('Relay error:', error.message)\n   * } else if (error instanceof FunctionsFetchError) {\n   *   console.log('Fetch error:', error.message)\n   * }\n   * ```\n   *\n   * @exampleDescription Passing custom headers\n   * You can pass custom headers to your function. Note: supabase-js automatically passes the `Authorization` header with the signed in user's JWT.\n   *\n   * @example Passing custom headers\n   * ```js\n   * const { data, error } = await supabase.functions.invoke('hello', {\n   *   headers: {\n   *     \"my-custom-header\": 'my-custom-header-value'\n   *   },\n   *   body: { foo: 'bar' }\n   * })\n   * ```\n   *\n   * @exampleDescription Calling with DELETE HTTP verb\n   * You can also set the HTTP verb to `DELETE` when calling your Edge Function.\n   *\n   * @example Calling with DELETE HTTP verb\n   * ```js\n   * const { data, error } = await supabase.functions.invoke('hello', {\n   *   headers: {\n   *     \"my-custom-header\": 'my-custom-header-value'\n   *   },\n   *   body: { foo: 'bar' },\n   *   method: 'DELETE'\n   * })\n   * ```\n   *\n   * @exampleDescription Invoking a Function in the UsEast1 region\n   * Here are the available regions:\n   * - `FunctionRegion.Any`\n   * - `FunctionRegion.ApNortheast1`\n   * - `FunctionRegion.ApNortheast2`\n   * - `FunctionRegion.ApSouth1`\n   * - `FunctionRegion.ApSoutheast1`\n   * - `FunctionRegion.ApSoutheast2`\n   * - `FunctionRegion.CaCentral1`\n   * - `FunctionRegion.EuCentral1`\n   * - `FunctionRegion.EuWest1`\n   * - `FunctionRegion.EuWest2`\n   * - `FunctionRegion.EuWest3`\n   * - `FunctionRegion.SaEast1`\n   * - `FunctionRegion.UsEast1`\n   * - `FunctionRegion.UsWest1`\n   * - `FunctionRegion.UsWest2`\n   *\n   * @example Invoking a Function in the UsEast1 region\n   * ```js\n   * import { createClient, FunctionRegion } from '@supabase/supabase-js'\n   *\n   * const { data, error } = await supabase.functions.invoke('hello', {\n   *   body: { foo: 'bar' },\n   *   region: FunctionRegion.UsEast1\n   * })\n   * ```\n   *\n   * @exampleDescription Calling with GET HTTP verb\n   * You can also set the HTTP verb to `GET` when calling your Edge Function.\n   *\n   * @example Calling with GET HTTP verb\n   * ```js\n   * const { data, error } = await supabase.functions.invoke('hello', {\n   *   headers: {\n   *     \"my-custom-header\": 'my-custom-header-value'\n   *   },\n   *   method: 'GET'\n   * })\n   * ```\n   *\n   * @example Standalone client invoke\n   * ```ts\n   * const { data, error } = await functions.invoke('hello-world', {\n   *   body: { name: 'Ada' },\n   * })\n   * ```\n   */\n  async invoke\u003cT = any\u003e(\n    functionName: string,\n    options: FunctionInvokeOptions = {}\n  ): Promise\u003cFunctionsResponse\u003cT\u003e\u003e {\n    let timeoutId: ReturnType\u003ctypeof setTimeout\u003e | undefined\n    let timeoutController: AbortController | undefined\n\n    try {\n      const { headers, method, body: functionArgs, signal, timeout } = options\n      let _headers: Record\u003cstring, string\u003e = {}\n      let { region } = options\n      if (!region) {\n        region = this.region\n      }\n      // Add region as query parameter using URL API\n      const url = new URL(`${this.url}/${functionName}`)\n      if (region \u0026\u0026 region !== 'any') {\n        _headers['x-region'] = region\n        url.searchParams.set('forceFunctionRegion', 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      } else {\n        if (\n          functionArgs \u0026\u0026\n          typeof functionArgs !== 'string' \u0026\u0026\n          !(typeof Blob !== 'undefined' \u0026\u0026 functionArgs instanceof Blob) \u0026\u0026\n          !(functionArgs instanceof ArrayBuffer) \u0026\u0026\n          !(typeof FormData !== 'undefined' \u0026\u0026 functionArgs instanceof FormData)\n        ) {\n          body = JSON.stringify(functionArgs)\n        } else {\n          body = functionArgs\n        }\n      }\n\n      // Handle timeout by creating an AbortController\n      let effectiveSignal = signal\n      if (timeout) {\n        timeoutController = new AbortController()\n        timeoutId = setTimeout(() =\u003e timeoutController!.abort(), timeout)\n\n        // If user provided their own signal, we need to respect both\n        if (signal) {\n          effectiveSignal = timeoutController.signal\n          // If the user's signal is aborted, abort our timeout controller too\n          signal.addEventListener('abort', () =\u003e timeoutController!.abort())\n        } else {\n          effectiveSignal = timeoutController.signal\n        }\n      }\n\n      const response = await this.fetch(url.toString(), {\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        signal: effectiveSignal,\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 (\n        responseType === 'application/octet-stream' ||\n        responseType === 'application/pdf'\n      ) {\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, response }\n    } catch (error) {\n      return {\n        data: null,\n        error,\n        response:\n          error instanceof FunctionsHttpError || error instanceof FunctionsRelayError\n            ? error.context\n            : undefined,\n      }\n    } finally {\n      // Clear the timeout if it was set\n      if (timeoutId) {\n        clearTimeout(timeoutId)\n      }\n    }\n  }\n}\n"],"version":3}
