Init
This commit is contained in:
+11
@@ -0,0 +1,11 @@
|
||||
# Agent instructions for `@supabase/functions-js`
|
||||
|
||||
JavaScript SDK for invoking Supabase Edge Functions.
|
||||
|
||||
When helping a user work with this package:
|
||||
|
||||
- **Usage and quick start**: [`README.md`](./README.md)
|
||||
- **Full API reference**: [`src/`](./src/) — every public method and type has TSDoc with `@example` blocks. Read the source for the canonical, version-pinned answer.
|
||||
- **Migration notes**: [`migrations/`](./migrations/) — per-theme markdown files for changes that need caller action.
|
||||
|
||||
For broader Supabase guidance (docs site, MCP tools, schema and project workflows), use the centralized [Supabase agent skills](https://github.com/supabase/agent-skills): `npx skills add supabase/agent-skills`. Or pair with the Supabase MCP server via the [Supabase Plugin for AI Coding Agents](https://supabase.com/docs/guides/getting-started/plugins).
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020 Supabase
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
<br />
|
||||
<p align="center">
|
||||
<a href="https://supabase.io">
|
||||
<picture>
|
||||
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/supabase/supabase/master/packages/common/assets/images/supabase-logo-wordmark--dark.svg">
|
||||
<source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/supabase/supabase/master/packages/common/assets/images/supabase-logo-wordmark--light.svg">
|
||||
<img alt="Supabase Logo" width="300" src="https://raw.githubusercontent.com/supabase/supabase/master/packages/common/assets/images/logo-preview.jpg">
|
||||
</picture>
|
||||
</a>
|
||||
|
||||
<h1 align="center">Supabase Functions JS SDK</h1>
|
||||
|
||||
<h3 align="center">JavaScript SDK to interact with Supabase Edge Functions.</h3>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://supabase.com/docs/guides/functions">Guides</a>
|
||||
·
|
||||
<a href="https://supabase.com/docs/reference/javascript/functions-invoke">Reference Docs</a>
|
||||
·
|
||||
<a href="https://supabase.github.io/supabase-js/functions-js/v2/spec.json">TypeDoc</a>
|
||||
</p>
|
||||
</p>
|
||||
|
||||
<div align="center">
|
||||
|
||||
[](https://github.com/supabase/supabase-js/actions?query=branch%3Amaster)
|
||||
[](https://www.npmjs.com/package/@supabase/functions-js)
|
||||
[](#license)
|
||||
[](https://pkg.pr.new/~/supabase/functions-js)
|
||||
|
||||
</div>
|
||||
|
||||
## Requirements
|
||||
|
||||
- **Node.js 22 or later** (Node.js 20 support dropped in v2.110.0)
|
||||
- For browser support, all modern browsers are supported
|
||||
|
||||
> ⚠️ **Node.js 18 Deprecation Notice**
|
||||
>
|
||||
> Node.js 18 reached end-of-life on April 30, 2025. As announced in [our deprecation notice](https://github.com/orgs/supabase/discussions/37217), support for Node.js 18 was dropped on October 31, 2025.
|
||||
|
||||
> ⚠️ **Node.js 20 Deprecation Notice**
|
||||
>
|
||||
> Node.js 20 reached end-of-life on April 30, 2026. As announced in [our deprecation notice](https://github.com/orgs/supabase/discussions/45715), support for Node.js 20 was dropped in v2.110.0.
|
||||
|
||||
## Quick Start
|
||||
|
||||
### Installation
|
||||
|
||||
```bash
|
||||
npm install @supabase/functions-js
|
||||
```
|
||||
|
||||
### Usage
|
||||
|
||||
```js
|
||||
import { FunctionsClient } from '@supabase/functions-js'
|
||||
|
||||
const functionsUrl = 'https://<project_ref>.supabase.co/functions/v1'
|
||||
const publishableKey = '<publishable_key>'
|
||||
|
||||
const functions = new FunctionsClient(functionsUrl, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${publishableKey}`,
|
||||
},
|
||||
})
|
||||
|
||||
// Invoke a function
|
||||
const { data, error } = await functions.invoke('hello-world', {
|
||||
body: { name: 'Functions' },
|
||||
})
|
||||
```
|
||||
|
||||
## Development
|
||||
|
||||
This package is part of the [Supabase JavaScript monorepo](https://github.com/supabase/supabase-js). To work on this package:
|
||||
|
||||
### Building
|
||||
|
||||
```bash
|
||||
# Complete build (from monorepo root)
|
||||
pnpm nx build functions-js
|
||||
|
||||
# Build with watch mode for development
|
||||
pnpm nx build functions-js --watch
|
||||
|
||||
# Individual build targets
|
||||
pnpm nx build:main functions-js # CommonJS build (dist/main/)
|
||||
pnpm nx build:module functions-js # ES Modules build (dist/module/)
|
||||
|
||||
# Other useful commands
|
||||
pnpm nx clean functions-js # Clean build artifacts
|
||||
pnpm nx typecheck functions-js # TypeScript type checking
|
||||
pnpm nx docs functions-js # Generate documentation
|
||||
```
|
||||
|
||||
#### Build Outputs
|
||||
|
||||
- **CommonJS (`dist/main/`)** - For Node.js environments
|
||||
- **ES Modules (`dist/module/`)** - For modern bundlers (Webpack, Vite, Rollup)
|
||||
- **TypeScript definitions (`dist/module/index.d.ts`)** - Type definitions for TypeScript projects
|
||||
|
||||
### Testing
|
||||
|
||||
**Docker Required** for relay tests. The functions-js tests use testcontainers to spin up a Deno relay server for testing Edge Function invocations.
|
||||
|
||||
```bash
|
||||
# Run all tests (from monorepo root)
|
||||
pnpm nx test functions-js
|
||||
|
||||
# Run tests with coverage report
|
||||
pnpm nx test functions-js --coverage
|
||||
|
||||
# Run tests in watch mode during development
|
||||
pnpm nx test functions-js --watch
|
||||
|
||||
# CI test command (runs with coverage)
|
||||
pnpm nx test:ci functions-js
|
||||
```
|
||||
|
||||
#### Test Requirements
|
||||
|
||||
- **Node.js 22+** - Required for testcontainers
|
||||
- **Docker** - Must be installed and running for relay tests
|
||||
- No Supabase instance needed - Tests use mocked services and testcontainers
|
||||
|
||||
#### What Gets Tested
|
||||
|
||||
- **Function invocation** - Testing the `invoke()` method with various options
|
||||
- **Relay functionality** - Using a containerized Deno relay to test real Edge Function scenarios
|
||||
- **Error handling** - Ensuring proper error responses and retries
|
||||
- **Request/response models** - Validating headers, body, and response formats
|
||||
|
||||
### Contributing
|
||||
|
||||
We welcome contributions! Please see our [Contributing Guide](../../../CONTRIBUTING.md) for details on how to get started.
|
||||
|
||||
For major changes or if you're unsure about something, please open an issue first to discuss your proposed changes.
|
||||
+179
@@ -0,0 +1,179 @@
|
||||
import { Fetch, FunctionInvokeOptions, FunctionRegion, FunctionsResponse } from './types';
|
||||
/**
|
||||
* Client for invoking Supabase Edge Functions.
|
||||
*/
|
||||
export declare class FunctionsClient {
|
||||
protected url: string;
|
||||
protected headers: Record<string, string>;
|
||||
protected region: FunctionRegion;
|
||||
protected fetch: Fetch;
|
||||
/**
|
||||
* Creates a new Functions client bound to an Edge Functions URL.
|
||||
*
|
||||
* @example Using supabase-js (recommended)
|
||||
* ```ts
|
||||
* import { createClient } from '@supabase/supabase-js'
|
||||
*
|
||||
* const supabase = createClient('https://xyzcompany.supabase.co', 'your-publishable-key')
|
||||
* const { data, error } = await supabase.functions.invoke('hello-world')
|
||||
* ```
|
||||
*
|
||||
* @category Edge Functions
|
||||
*
|
||||
* @example Standalone import for bundle-sensitive environments
|
||||
* ```ts
|
||||
* import { FunctionsClient, FunctionRegion } from '@supabase/functions-js'
|
||||
*
|
||||
* const functions = new FunctionsClient('https://xyzcompany.supabase.co/functions/v1', {
|
||||
* headers: { apikey: 'your-publishable-key' },
|
||||
* region: FunctionRegion.UsEast1,
|
||||
* })
|
||||
* ```
|
||||
*/
|
||||
constructor(url: string, { headers, customFetch, region, }?: {
|
||||
headers?: Record<string, string>;
|
||||
customFetch?: Fetch;
|
||||
region?: FunctionRegion;
|
||||
});
|
||||
/**
|
||||
* Updates the authorization header
|
||||
* @param token - the new jwt token sent in the authorisation header
|
||||
*
|
||||
* @category Edge Functions
|
||||
*
|
||||
* @example Setting the authorization header
|
||||
* ```ts
|
||||
* functions.setAuth(session.access_token)
|
||||
* ```
|
||||
*/
|
||||
setAuth(token: string): void;
|
||||
/**
|
||||
* Invokes a function
|
||||
* @param functionName - The name of the Function to invoke.
|
||||
* @param options - Options for invoking the Function.
|
||||
* @example
|
||||
* ```ts
|
||||
* const { data, error } = await functions.invoke('hello-world', {
|
||||
* body: { name: 'Ada' },
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* @category Edge Functions
|
||||
*
|
||||
* @remarks
|
||||
* - The API key is sent in the `apikey` header. The `Authorization` header is reserved
|
||||
* for the signed-in user's JWT (or a custom auth token) — when there is no session, a
|
||||
* new-format API key (`sb_publishable_…` / `sb_secret_…`) is not sent as a Bearer token.
|
||||
* - Invoke params generally match the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) spec.
|
||||
* - 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.
|
||||
* - 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.
|
||||
*
|
||||
* @example Basic invocation
|
||||
* ```js
|
||||
* const { data, error } = await supabase.functions.invoke('hello', {
|
||||
* body: { foo: 'bar' }
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* @exampleDescription Error handling
|
||||
* 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. Log the full error object so fields like `name`, `context`, and any structured body aren't hidden.
|
||||
*
|
||||
* @example Error handling
|
||||
* ```js
|
||||
* import { FunctionsHttpError, FunctionsRelayError, FunctionsFetchError } from "@supabase/supabase-js";
|
||||
*
|
||||
* const { data, error } = await supabase.functions.invoke('hello', {
|
||||
* headers: {
|
||||
* "my-custom-header": 'my-custom-header-value'
|
||||
* },
|
||||
* body: { foo: 'bar' }
|
||||
* })
|
||||
*
|
||||
* if (error instanceof FunctionsHttpError) {
|
||||
* const errorMessage = await error.context.json()
|
||||
* console.error('Function returned an error', errorMessage)
|
||||
* } else if (error instanceof FunctionsRelayError) {
|
||||
* console.error('Relay error:', error)
|
||||
* } else if (error instanceof FunctionsFetchError) {
|
||||
* console.error('Fetch error:', error)
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @exampleDescription Passing custom headers
|
||||
* You can pass custom headers to your function. Note: supabase-js automatically passes the `Authorization` header with the signed in user's JWT.
|
||||
*
|
||||
* @example Passing custom headers
|
||||
* ```js
|
||||
* const { data, error } = await supabase.functions.invoke('hello', {
|
||||
* headers: {
|
||||
* "my-custom-header": 'my-custom-header-value'
|
||||
* },
|
||||
* body: { foo: 'bar' }
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* @exampleDescription Calling with DELETE HTTP verb
|
||||
* You can also set the HTTP verb to `DELETE` when calling your Edge Function.
|
||||
*
|
||||
* @example Calling with DELETE HTTP verb
|
||||
* ```js
|
||||
* const { data, error } = await supabase.functions.invoke('hello', {
|
||||
* headers: {
|
||||
* "my-custom-header": 'my-custom-header-value'
|
||||
* },
|
||||
* body: { foo: 'bar' },
|
||||
* method: 'DELETE'
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* @exampleDescription Invoking a Function in the UsEast1 region
|
||||
* Here are the available regions:
|
||||
* - `FunctionRegion.Any`
|
||||
* - `FunctionRegion.ApNortheast1`
|
||||
* - `FunctionRegion.ApNortheast2`
|
||||
* - `FunctionRegion.ApSouth1`
|
||||
* - `FunctionRegion.ApSoutheast1`
|
||||
* - `FunctionRegion.ApSoutheast2`
|
||||
* - `FunctionRegion.CaCentral1`
|
||||
* - `FunctionRegion.EuCentral1`
|
||||
* - `FunctionRegion.EuWest1`
|
||||
* - `FunctionRegion.EuWest2`
|
||||
* - `FunctionRegion.EuWest3`
|
||||
* - `FunctionRegion.SaEast1`
|
||||
* - `FunctionRegion.UsEast1`
|
||||
* - `FunctionRegion.UsWest1`
|
||||
* - `FunctionRegion.UsWest2`
|
||||
*
|
||||
* @example Invoking a Function in the UsEast1 region
|
||||
* ```js
|
||||
* import { createClient, FunctionRegion } from '@supabase/supabase-js'
|
||||
*
|
||||
* const { data, error } = await supabase.functions.invoke('hello', {
|
||||
* body: { foo: 'bar' },
|
||||
* region: FunctionRegion.UsEast1
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* @exampleDescription Calling with GET HTTP verb
|
||||
* You can also set the HTTP verb to `GET` when calling your Edge Function.
|
||||
*
|
||||
* @example Calling with GET HTTP verb
|
||||
* ```js
|
||||
* const { data, error } = await supabase.functions.invoke('hello', {
|
||||
* headers: {
|
||||
* "my-custom-header": 'my-custom-header-value'
|
||||
* },
|
||||
* method: 'GET'
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* @example Standalone client invoke
|
||||
* ```ts
|
||||
* const { data, error } = await functions.invoke('hello-world', {
|
||||
* body: { name: 'Ada' },
|
||||
* })
|
||||
* ```
|
||||
*/
|
||||
invoke<T = any>(functionName: string, options?: FunctionInvokeOptions): Promise<FunctionsResponse<T>>;
|
||||
}
|
||||
//# sourceMappingURL=FunctionsClient.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"FunctionsClient.d.ts","sourceRoot":"","sources":["../../src/FunctionsClient.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,EACL,qBAAqB,EACrB,cAAc,EAId,iBAAiB,EAClB,MAAM,SAAS,CAAA;AAEhB;;GAEG;AACH,qBAAa,eAAe;IAC1B,SAAS,CAAC,GAAG,EAAE,MAAM,CAAA;IACrB,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACzC,SAAS,CAAC,MAAM,EAAE,cAAc,CAAA;IAChC,SAAS,CAAC,KAAK,EAAE,KAAK,CAAA;IAEtB;;;;;;;;;;;;;;;;;;;;;;OAsBG;gBAED,GAAG,EAAE,MAAM,EACX,EACE,OAAY,EACZ,WAAW,EACX,MAA2B,GAC5B,GAAE;QACD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QAChC,WAAW,CAAC,EAAE,KAAK,CAAA;QACnB,MAAM,CAAC,EAAE,cAAc,CAAA;KACnB;IAQR;;;;;;;;;;OAUG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM;IAIrB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8HG;IACG,MAAM,CAAC,CAAC,GAAG,GAAG,EAClB,YAAY,EAAE,MAAM,EACpB,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;CAgJjC"}
|
||||
+326
@@ -0,0 +1,326 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.FunctionsClient = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
const helper_1 = require("./helper");
|
||||
const types_1 = require("./types");
|
||||
/**
|
||||
* Client for invoking Supabase Edge Functions.
|
||||
*/
|
||||
class FunctionsClient {
|
||||
/**
|
||||
* Creates a new Functions client bound to an Edge Functions URL.
|
||||
*
|
||||
* @example Using supabase-js (recommended)
|
||||
* ```ts
|
||||
* import { createClient } from '@supabase/supabase-js'
|
||||
*
|
||||
* const supabase = createClient('https://xyzcompany.supabase.co', 'your-publishable-key')
|
||||
* const { data, error } = await supabase.functions.invoke('hello-world')
|
||||
* ```
|
||||
*
|
||||
* @category Edge Functions
|
||||
*
|
||||
* @example Standalone import for bundle-sensitive environments
|
||||
* ```ts
|
||||
* import { FunctionsClient, FunctionRegion } from '@supabase/functions-js'
|
||||
*
|
||||
* const functions = new FunctionsClient('https://xyzcompany.supabase.co/functions/v1', {
|
||||
* headers: { apikey: 'your-publishable-key' },
|
||||
* region: FunctionRegion.UsEast1,
|
||||
* })
|
||||
* ```
|
||||
*/
|
||||
constructor(url, { headers = {}, customFetch, region = types_1.FunctionRegion.Any, } = {}) {
|
||||
this.url = url;
|
||||
this.headers = headers;
|
||||
this.region = region;
|
||||
this.fetch = (0, helper_1.resolveFetch)(customFetch);
|
||||
}
|
||||
/**
|
||||
* Updates the authorization header
|
||||
* @param token - the new jwt token sent in the authorisation header
|
||||
*
|
||||
* @category Edge Functions
|
||||
*
|
||||
* @example Setting the authorization header
|
||||
* ```ts
|
||||
* functions.setAuth(session.access_token)
|
||||
* ```
|
||||
*/
|
||||
setAuth(token) {
|
||||
this.headers.Authorization = `Bearer ${token}`;
|
||||
}
|
||||
/**
|
||||
* Invokes a function
|
||||
* @param functionName - The name of the Function to invoke.
|
||||
* @param options - Options for invoking the Function.
|
||||
* @example
|
||||
* ```ts
|
||||
* const { data, error } = await functions.invoke('hello-world', {
|
||||
* body: { name: 'Ada' },
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* @category Edge Functions
|
||||
*
|
||||
* @remarks
|
||||
* - The API key is sent in the `apikey` header. The `Authorization` header is reserved
|
||||
* for the signed-in user's JWT (or a custom auth token) — when there is no session, a
|
||||
* new-format API key (`sb_publishable_…` / `sb_secret_…`) is not sent as a Bearer token.
|
||||
* - Invoke params generally match the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) spec.
|
||||
* - 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.
|
||||
* - 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.
|
||||
*
|
||||
* @example Basic invocation
|
||||
* ```js
|
||||
* const { data, error } = await supabase.functions.invoke('hello', {
|
||||
* body: { foo: 'bar' }
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* @exampleDescription Error handling
|
||||
* 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. Log the full error object so fields like `name`, `context`, and any structured body aren't hidden.
|
||||
*
|
||||
* @example Error handling
|
||||
* ```js
|
||||
* import { FunctionsHttpError, FunctionsRelayError, FunctionsFetchError } from "@supabase/supabase-js";
|
||||
*
|
||||
* const { data, error } = await supabase.functions.invoke('hello', {
|
||||
* headers: {
|
||||
* "my-custom-header": 'my-custom-header-value'
|
||||
* },
|
||||
* body: { foo: 'bar' }
|
||||
* })
|
||||
*
|
||||
* if (error instanceof FunctionsHttpError) {
|
||||
* const errorMessage = await error.context.json()
|
||||
* console.error('Function returned an error', errorMessage)
|
||||
* } else if (error instanceof FunctionsRelayError) {
|
||||
* console.error('Relay error:', error)
|
||||
* } else if (error instanceof FunctionsFetchError) {
|
||||
* console.error('Fetch error:', error)
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @exampleDescription Passing custom headers
|
||||
* You can pass custom headers to your function. Note: supabase-js automatically passes the `Authorization` header with the signed in user's JWT.
|
||||
*
|
||||
* @example Passing custom headers
|
||||
* ```js
|
||||
* const { data, error } = await supabase.functions.invoke('hello', {
|
||||
* headers: {
|
||||
* "my-custom-header": 'my-custom-header-value'
|
||||
* },
|
||||
* body: { foo: 'bar' }
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* @exampleDescription Calling with DELETE HTTP verb
|
||||
* You can also set the HTTP verb to `DELETE` when calling your Edge Function.
|
||||
*
|
||||
* @example Calling with DELETE HTTP verb
|
||||
* ```js
|
||||
* const { data, error } = await supabase.functions.invoke('hello', {
|
||||
* headers: {
|
||||
* "my-custom-header": 'my-custom-header-value'
|
||||
* },
|
||||
* body: { foo: 'bar' },
|
||||
* method: 'DELETE'
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* @exampleDescription Invoking a Function in the UsEast1 region
|
||||
* Here are the available regions:
|
||||
* - `FunctionRegion.Any`
|
||||
* - `FunctionRegion.ApNortheast1`
|
||||
* - `FunctionRegion.ApNortheast2`
|
||||
* - `FunctionRegion.ApSouth1`
|
||||
* - `FunctionRegion.ApSoutheast1`
|
||||
* - `FunctionRegion.ApSoutheast2`
|
||||
* - `FunctionRegion.CaCentral1`
|
||||
* - `FunctionRegion.EuCentral1`
|
||||
* - `FunctionRegion.EuWest1`
|
||||
* - `FunctionRegion.EuWest2`
|
||||
* - `FunctionRegion.EuWest3`
|
||||
* - `FunctionRegion.SaEast1`
|
||||
* - `FunctionRegion.UsEast1`
|
||||
* - `FunctionRegion.UsWest1`
|
||||
* - `FunctionRegion.UsWest2`
|
||||
*
|
||||
* @example Invoking a Function in the UsEast1 region
|
||||
* ```js
|
||||
* import { createClient, FunctionRegion } from '@supabase/supabase-js'
|
||||
*
|
||||
* const { data, error } = await supabase.functions.invoke('hello', {
|
||||
* body: { foo: 'bar' },
|
||||
* region: FunctionRegion.UsEast1
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* @exampleDescription Calling with GET HTTP verb
|
||||
* You can also set the HTTP verb to `GET` when calling your Edge Function.
|
||||
*
|
||||
* @example Calling with GET HTTP verb
|
||||
* ```js
|
||||
* const { data, error } = await supabase.functions.invoke('hello', {
|
||||
* headers: {
|
||||
* "my-custom-header": 'my-custom-header-value'
|
||||
* },
|
||||
* method: 'GET'
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* @example Standalone client invoke
|
||||
* ```ts
|
||||
* const { data, error } = await functions.invoke('hello-world', {
|
||||
* body: { name: 'Ada' },
|
||||
* })
|
||||
* ```
|
||||
*/
|
||||
invoke(functionName_1) {
|
||||
return tslib_1.__awaiter(this, arguments, void 0, function* (functionName, options = {}) {
|
||||
var _a, _b;
|
||||
let timeoutId;
|
||||
let timeoutController;
|
||||
let onAbort;
|
||||
try {
|
||||
const { headers, method, body: functionArgs, signal, timeout } = options;
|
||||
let _headers = {};
|
||||
let { region } = options;
|
||||
if (!region) {
|
||||
region = this.region;
|
||||
}
|
||||
// Add region as query parameter using URL API
|
||||
const url = new URL(`${this.url}/${functionName}`);
|
||||
if (region && region !== 'any') {
|
||||
_headers['x-region'] = region;
|
||||
url.searchParams.set('forceFunctionRegion', region);
|
||||
}
|
||||
let body;
|
||||
// HTTP header names are case-insensitive, so detect a caller-supplied Content-Type
|
||||
// regardless of casing — otherwise the SDK injects a second, conflicting Content-Type.
|
||||
const hasContentTypeHeader = !!headers && Object.keys(headers).some((key) => key.toLowerCase() === 'content-type');
|
||||
if (functionArgs && !hasContentTypeHeader) {
|
||||
if ((typeof Blob !== 'undefined' && functionArgs instanceof Blob) ||
|
||||
functionArgs instanceof ArrayBuffer) {
|
||||
// will work for File as File inherits Blob
|
||||
// also works for ArrayBuffer as it is the same underlying structure as a Blob
|
||||
_headers['Content-Type'] = 'application/octet-stream';
|
||||
body = functionArgs;
|
||||
}
|
||||
else if (typeof functionArgs === 'string') {
|
||||
// plain string
|
||||
_headers['Content-Type'] = 'text/plain';
|
||||
body = functionArgs;
|
||||
}
|
||||
else if (typeof FormData !== 'undefined' && functionArgs instanceof FormData) {
|
||||
// don't set content-type headers
|
||||
// Request will automatically add the right boundary value
|
||||
body = functionArgs;
|
||||
}
|
||||
else {
|
||||
// default, assume this is JSON
|
||||
_headers['Content-Type'] = 'application/json';
|
||||
body = JSON.stringify(functionArgs);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (functionArgs &&
|
||||
typeof functionArgs !== 'string' &&
|
||||
!(typeof Blob !== 'undefined' && functionArgs instanceof Blob) &&
|
||||
!(functionArgs instanceof ArrayBuffer) &&
|
||||
!(typeof FormData !== 'undefined' && functionArgs instanceof FormData)) {
|
||||
body = JSON.stringify(functionArgs);
|
||||
}
|
||||
else {
|
||||
body = functionArgs;
|
||||
}
|
||||
}
|
||||
// Handle timeout by creating an AbortController
|
||||
let effectiveSignal = signal;
|
||||
if (timeout) {
|
||||
timeoutController = new AbortController();
|
||||
timeoutId = setTimeout(() => timeoutController.abort(), timeout);
|
||||
// If user provided their own signal, we need to respect both
|
||||
if (signal) {
|
||||
effectiveSignal = timeoutController.signal;
|
||||
// If the user's signal is aborted, abort our timeout controller too.
|
||||
// Store the listener so we can clean it up in finally.
|
||||
onAbort = () => timeoutController.abort();
|
||||
signal.addEventListener('abort', onAbort);
|
||||
}
|
||||
else {
|
||||
effectiveSignal = timeoutController.signal;
|
||||
}
|
||||
}
|
||||
const response = yield this.fetch(url.toString(), {
|
||||
method: method || 'POST',
|
||||
// headers priority is (high to low):
|
||||
// 1. invoke-level headers
|
||||
// 2. client-level headers
|
||||
// 3. default Content-Type header
|
||||
headers: Object.assign(Object.assign(Object.assign({}, _headers), this.headers), headers),
|
||||
body,
|
||||
signal: effectiveSignal,
|
||||
}).catch((fetchError) => {
|
||||
throw new types_1.FunctionsFetchError(fetchError);
|
||||
});
|
||||
const isRelayError = response.headers.get('x-relay-error');
|
||||
if (isRelayError && isRelayError === 'true') {
|
||||
throw new types_1.FunctionsRelayError(response);
|
||||
}
|
||||
if (!response.ok) {
|
||||
throw new types_1.FunctionsHttpError(response);
|
||||
}
|
||||
// HTTP media types are case-insensitive (RFC 9110), so normalize before
|
||||
// matching — otherwise an "Application/JSON" response falls through to text.
|
||||
let responseType = ((_a = response.headers.get('Content-Type')) !== null && _a !== void 0 ? _a : 'text/plain')
|
||||
.split(';')[0]
|
||||
.trim()
|
||||
.toLowerCase();
|
||||
let data;
|
||||
if (responseType === 'application/json') {
|
||||
data = yield response.json();
|
||||
}
|
||||
else if (responseType === 'application/octet-stream' ||
|
||||
responseType === 'application/pdf') {
|
||||
data = yield response.blob();
|
||||
}
|
||||
else if (responseType === 'text/event-stream') {
|
||||
data = response;
|
||||
}
|
||||
else if (responseType === 'multipart/form-data') {
|
||||
data = yield response.formData();
|
||||
}
|
||||
else {
|
||||
// default to text
|
||||
data = yield response.text();
|
||||
}
|
||||
return { data, error: null, response };
|
||||
}
|
||||
catch (error) {
|
||||
return {
|
||||
data: null,
|
||||
error,
|
||||
response: error instanceof types_1.FunctionsHttpError || error instanceof types_1.FunctionsRelayError
|
||||
? error.context
|
||||
: undefined,
|
||||
};
|
||||
}
|
||||
finally {
|
||||
// Clear the timeout if it was set
|
||||
if (timeoutId) {
|
||||
clearTimeout(timeoutId);
|
||||
}
|
||||
// Remove the cross-signal listener to prevent memory leaks when the caller
|
||||
// reuses the same AbortSignal across multiple invocations.
|
||||
if (onAbort) {
|
||||
(_b = options.signal) === null || _b === void 0 ? void 0 : _b.removeEventListener('abort', onAbort);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.FunctionsClient = FunctionsClient;
|
||||
//# sourceMappingURL=FunctionsClient.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"FunctionsClient.js","sourceRoot":"","sources":["../../src/FunctionsClient.ts"],"names":[],"mappings":";;;;AAAA,qCAAuC;AACvC,mCAQgB;AAEhB;;GAEG;AACH,MAAa,eAAe;IAM1B;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,YACE,GAAW,EACX,EACE,OAAO,GAAG,EAAE,EACZ,WAAW,EACX,MAAM,GAAG,sBAAc,CAAC,GAAG,MAKzB,EAAE;QAEN,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;QACd,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,MA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AAY,2BAAmB;wBACzE,CAAC,CAAC,KAAK,CAAC,OAAO;wBACf,CAAC,CAAC,SAAS;iBAChB,CAAA;YACH,CAAC;oBAAS,CAAC;gBACT,kCAAkC;gBAClC,IAAI,SAAS,EAAE,CAAC;oBACd,YAAY,CAAC,SAAS,CAAC,CAAA;gBACzB,CAAC;gBACD,2EAA2E;gBAC3E,2DAA2D;gBAC3D,IAAI,OAAO,EAAE,CAAC;oBACZ,MAAA,OAAO,CAAC,MAAM,0CAAE,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;gBACvD,CAAC;YACH,CAAC;QACH,CAAC;KAAA;CACF;AAhVD,0CAgVC"}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
import { Fetch } from './types';
|
||||
export declare const resolveFetch: (customFetch?: Fetch) => Fetch;
|
||||
//# sourceMappingURL=helper.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../../src/helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAE/B,eAAO,MAAM,YAAY,GAAI,cAAc,KAAK,KAAG,KAKlD,CAAA"}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.resolveFetch = void 0;
|
||||
const resolveFetch = (customFetch) => {
|
||||
if (customFetch) {
|
||||
return (...args) => customFetch(...args);
|
||||
}
|
||||
return (...args) => fetch(...args);
|
||||
};
|
||||
exports.resolveFetch = resolveFetch;
|
||||
//# sourceMappingURL=helper.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../../src/helper.ts"],"names":[],"mappings":";;;AAEO,MAAM,YAAY,GAAG,CAAC,WAAmB,EAAS,EAAE;IACzD,IAAI,WAAW,EAAE,CAAC;QAChB,OAAO,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC,CAAA;IAC1C,CAAC;IACD,OAAO,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAA;AACpC,CAAC,CAAA;AALY,QAAA,YAAY,gBAKxB"}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
export { FunctionsClient } from './FunctionsClient';
|
||||
export { type FunctionInvokeOptions, FunctionsError, FunctionsFetchError, FunctionsHttpError, FunctionsRelayError, FunctionRegion, type FunctionsResponse, } from './types';
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EACL,KAAK,qBAAqB,EAC1B,cAAc,EACd,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACnB,cAAc,EACd,KAAK,iBAAiB,GACvB,MAAM,SAAS,CAAA"}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.FunctionRegion = exports.FunctionsRelayError = exports.FunctionsHttpError = exports.FunctionsFetchError = exports.FunctionsError = exports.FunctionsClient = void 0;
|
||||
var FunctionsClient_1 = require("./FunctionsClient");
|
||||
Object.defineProperty(exports, "FunctionsClient", { enumerable: true, get: function () { return FunctionsClient_1.FunctionsClient; } });
|
||||
var types_1 = require("./types");
|
||||
Object.defineProperty(exports, "FunctionsError", { enumerable: true, get: function () { return types_1.FunctionsError; } });
|
||||
Object.defineProperty(exports, "FunctionsFetchError", { enumerable: true, get: function () { return types_1.FunctionsFetchError; } });
|
||||
Object.defineProperty(exports, "FunctionsHttpError", { enumerable: true, get: function () { return types_1.FunctionsHttpError; } });
|
||||
Object.defineProperty(exports, "FunctionsRelayError", { enumerable: true, get: function () { return types_1.FunctionsRelayError; } });
|
||||
Object.defineProperty(exports, "FunctionRegion", { enumerable: true, get: function () { return types_1.FunctionRegion; } });
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,qDAAmD;AAA1C,kHAAA,eAAe,OAAA;AACxB,iCAQgB;AANd,uGAAA,cAAc,OAAA;AACd,4GAAA,mBAAmB,OAAA;AACnB,2GAAA,kBAAkB,OAAA;AAClB,4GAAA,mBAAmB,OAAA;AACnB,uGAAA,cAAc,OAAA"}
|
||||
+122
@@ -0,0 +1,122 @@
|
||||
export type Fetch = typeof fetch;
|
||||
/**
|
||||
* Response format
|
||||
*/
|
||||
export interface FunctionsResponseSuccess<T> {
|
||||
data: T;
|
||||
error: null;
|
||||
response?: Response;
|
||||
}
|
||||
export interface FunctionsResponseFailure {
|
||||
data: null;
|
||||
error: any;
|
||||
response?: Response;
|
||||
}
|
||||
export type FunctionsResponse<T> = FunctionsResponseSuccess<T> | FunctionsResponseFailure;
|
||||
/**
|
||||
* Base error for Supabase Edge Function invocations.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { FunctionsError } from '@supabase/functions-js'
|
||||
*
|
||||
* throw new FunctionsError('Unexpected error invoking function', 'FunctionsError', {
|
||||
* requestId: 'abc123',
|
||||
* })
|
||||
* ```
|
||||
*/
|
||||
export declare class FunctionsError extends Error {
|
||||
context: any;
|
||||
constructor(message: string, name?: string, context?: any);
|
||||
toJSON(): {
|
||||
name: string;
|
||||
message: string;
|
||||
context: any;
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Error thrown when the network request to an Edge Function fails.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { FunctionsFetchError } from '@supabase/functions-js'
|
||||
*
|
||||
* throw new FunctionsFetchError({ requestId: 'abc123' })
|
||||
* ```
|
||||
*/
|
||||
export declare class FunctionsFetchError extends FunctionsError {
|
||||
constructor(context: any);
|
||||
}
|
||||
/**
|
||||
* Error thrown when the Supabase relay cannot reach the Edge Function.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { FunctionsRelayError } from '@supabase/functions-js'
|
||||
*
|
||||
* throw new FunctionsRelayError({ region: 'us-east-1' })
|
||||
* ```
|
||||
*/
|
||||
export declare class FunctionsRelayError extends FunctionsError {
|
||||
constructor(context: any);
|
||||
}
|
||||
/**
|
||||
* Error thrown when the Edge Function returns a non-2xx status code.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { FunctionsHttpError } from '@supabase/functions-js'
|
||||
*
|
||||
* throw new FunctionsHttpError({ status: 500 })
|
||||
* ```
|
||||
*/
|
||||
export declare class FunctionsHttpError extends FunctionsError {
|
||||
constructor(context: any);
|
||||
}
|
||||
export declare enum FunctionRegion {
|
||||
Any = "any",
|
||||
ApNortheast1 = "ap-northeast-1",
|
||||
ApNortheast2 = "ap-northeast-2",
|
||||
ApSouth1 = "ap-south-1",
|
||||
ApSoutheast1 = "ap-southeast-1",
|
||||
ApSoutheast2 = "ap-southeast-2",
|
||||
CaCentral1 = "ca-central-1",
|
||||
EuCentral1 = "eu-central-1",
|
||||
EuWest1 = "eu-west-1",
|
||||
EuWest2 = "eu-west-2",
|
||||
EuWest3 = "eu-west-3",
|
||||
SaEast1 = "sa-east-1",
|
||||
UsEast1 = "us-east-1",
|
||||
UsWest1 = "us-west-1",
|
||||
UsWest2 = "us-west-2"
|
||||
}
|
||||
export type FunctionInvokeOptions = {
|
||||
/**
|
||||
* Object representing the headers to send with the request.
|
||||
*/
|
||||
headers?: {
|
||||
[key: string]: string;
|
||||
};
|
||||
/**
|
||||
* The HTTP verb of the request
|
||||
*/
|
||||
method?: 'POST' | 'GET' | 'PUT' | 'PATCH' | 'DELETE';
|
||||
/**
|
||||
* The Region to invoke the function in.
|
||||
*/
|
||||
region?: FunctionRegion;
|
||||
/**
|
||||
* The body of the request.
|
||||
*/
|
||||
body?: File | Blob | ArrayBuffer | FormData | ReadableStream<Uint8Array> | Record<string, any> | string;
|
||||
/**
|
||||
* The AbortSignal to use for the request.
|
||||
* */
|
||||
signal?: AbortSignal;
|
||||
/**
|
||||
* The timeout for the request in milliseconds.
|
||||
* If the function takes longer than this, the request will be aborted.
|
||||
* */
|
||||
timeout?: number;
|
||||
};
|
||||
//# sourceMappingURL=types.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,KAAK,GAAG,OAAO,KAAK,CAAA;AAEhC;;GAEG;AACH,MAAM,WAAW,wBAAwB,CAAC,CAAC;IACzC,IAAI,EAAE,CAAC,CAAA;IACP,KAAK,EAAE,IAAI,CAAA;IACX,QAAQ,CAAC,EAAE,QAAQ,CAAA;CACpB;AACD,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,IAAI,CAAA;IACV,KAAK,EAAE,GAAG,CAAA;IACV,QAAQ,CAAC,EAAE,QAAQ,CAAA;CACpB;AACD,MAAM,MAAM,iBAAiB,CAAC,CAAC,IAAI,wBAAwB,CAAC,CAAC,CAAC,GAAG,wBAAwB,CAAA;AAEzF;;;;;;;;;;;GAWG;AACH,qBAAa,cAAe,SAAQ,KAAK;IACvC,OAAO,EAAE,GAAG,CAAA;gBACA,OAAO,EAAE,MAAM,EAAE,IAAI,SAAmB,EAAE,OAAO,CAAC,EAAE,GAAG;IAMnE,MAAM,IAAI;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,GAAG,CAAA;KAAE;CAO1D;AAED;;;;;;;;;GASG;AACH,qBAAa,mBAAoB,SAAQ,cAAc;gBACzC,OAAO,EAAE,GAAG;CAGzB;AAED;;;;;;;;;GASG;AACH,qBAAa,mBAAoB,SAAQ,cAAc;gBACzC,OAAO,EAAE,GAAG;CAGzB;AAED;;;;;;;;;GASG;AACH,qBAAa,kBAAmB,SAAQ,cAAc;gBACxC,OAAO,EAAE,GAAG;CAGzB;AAED,oBAAY,cAAc;IACxB,GAAG,QAAQ;IACX,YAAY,mBAAmB;IAC/B,YAAY,mBAAmB;IAC/B,QAAQ,eAAe;IACvB,YAAY,mBAAmB;IAC/B,YAAY,mBAAmB;IAC/B,UAAU,iBAAiB;IAC3B,UAAU,iBAAiB;IAC3B,OAAO,cAAc;IACrB,OAAO,cAAc;IACrB,OAAO,cAAc;IACrB,OAAO,cAAc;IACrB,OAAO,cAAc;IACrB,OAAO,cAAc;IACrB,OAAO,cAAc;CACtB;AAED,MAAM,MAAM,qBAAqB,GAAG;IAClC;;OAEG;IACH,OAAO,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAA;IACnC;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAA;IACpD;;OAEG;IACH,MAAM,CAAC,EAAE,cAAc,CAAA;IACvB;;OAEG;IACH,IAAI,CAAC,EACD,IAAI,GACJ,IAAI,GACJ,WAAW,GACX,QAAQ,GACR,cAAc,CAAC,UAAU,CAAC,GAC1B,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACnB,MAAM,CAAA;IACV;;SAEK;IACL,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB;;;SAGK;IACL,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA"}
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.FunctionRegion = exports.FunctionsHttpError = exports.FunctionsRelayError = exports.FunctionsFetchError = exports.FunctionsError = void 0;
|
||||
/**
|
||||
* Base error for Supabase Edge Function invocations.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { FunctionsError } from '@supabase/functions-js'
|
||||
*
|
||||
* throw new FunctionsError('Unexpected error invoking function', 'FunctionsError', {
|
||||
* requestId: 'abc123',
|
||||
* })
|
||||
* ```
|
||||
*/
|
||||
class FunctionsError extends Error {
|
||||
constructor(message, name = 'FunctionsError', context) {
|
||||
super(message);
|
||||
this.name = name;
|
||||
this.context = context;
|
||||
}
|
||||
toJSON() {
|
||||
return {
|
||||
name: this.name,
|
||||
message: this.message,
|
||||
context: this.context,
|
||||
};
|
||||
}
|
||||
}
|
||||
exports.FunctionsError = FunctionsError;
|
||||
/**
|
||||
* Error thrown when the network request to an Edge Function fails.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { FunctionsFetchError } from '@supabase/functions-js'
|
||||
*
|
||||
* throw new FunctionsFetchError({ requestId: 'abc123' })
|
||||
* ```
|
||||
*/
|
||||
class FunctionsFetchError extends FunctionsError {
|
||||
constructor(context) {
|
||||
super('Failed to send a request to the Edge Function', 'FunctionsFetchError', context);
|
||||
}
|
||||
}
|
||||
exports.FunctionsFetchError = FunctionsFetchError;
|
||||
/**
|
||||
* Error thrown when the Supabase relay cannot reach the Edge Function.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { FunctionsRelayError } from '@supabase/functions-js'
|
||||
*
|
||||
* throw new FunctionsRelayError({ region: 'us-east-1' })
|
||||
* ```
|
||||
*/
|
||||
class FunctionsRelayError extends FunctionsError {
|
||||
constructor(context) {
|
||||
super('Relay Error invoking the Edge Function', 'FunctionsRelayError', context);
|
||||
}
|
||||
}
|
||||
exports.FunctionsRelayError = FunctionsRelayError;
|
||||
/**
|
||||
* Error thrown when the Edge Function returns a non-2xx status code.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { FunctionsHttpError } from '@supabase/functions-js'
|
||||
*
|
||||
* throw new FunctionsHttpError({ status: 500 })
|
||||
* ```
|
||||
*/
|
||||
class FunctionsHttpError extends FunctionsError {
|
||||
constructor(context) {
|
||||
super('Edge Function returned a non-2xx status code', 'FunctionsHttpError', context);
|
||||
}
|
||||
}
|
||||
exports.FunctionsHttpError = FunctionsHttpError;
|
||||
// Define the enum for the 'region' property
|
||||
var FunctionRegion;
|
||||
(function (FunctionRegion) {
|
||||
FunctionRegion["Any"] = "any";
|
||||
FunctionRegion["ApNortheast1"] = "ap-northeast-1";
|
||||
FunctionRegion["ApNortheast2"] = "ap-northeast-2";
|
||||
FunctionRegion["ApSouth1"] = "ap-south-1";
|
||||
FunctionRegion["ApSoutheast1"] = "ap-southeast-1";
|
||||
FunctionRegion["ApSoutheast2"] = "ap-southeast-2";
|
||||
FunctionRegion["CaCentral1"] = "ca-central-1";
|
||||
FunctionRegion["EuCentral1"] = "eu-central-1";
|
||||
FunctionRegion["EuWest1"] = "eu-west-1";
|
||||
FunctionRegion["EuWest2"] = "eu-west-2";
|
||||
FunctionRegion["EuWest3"] = "eu-west-3";
|
||||
FunctionRegion["SaEast1"] = "sa-east-1";
|
||||
FunctionRegion["UsEast1"] = "us-east-1";
|
||||
FunctionRegion["UsWest1"] = "us-west-1";
|
||||
FunctionRegion["UsWest2"] = "us-west-2";
|
||||
})(FunctionRegion || (exports.FunctionRegion = FunctionRegion = {}));
|
||||
//# sourceMappingURL=types.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";;;AAiBA;;;;;;;;;;;GAWG;AACH,MAAa,cAAe,SAAQ,KAAK;IAEvC,YAAY,OAAe,EAAE,IAAI,GAAG,gBAAgB,EAAE,OAAa;QACjE,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAED,MAAM;QACJ,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAA;IACH,CAAC;CACF;AAfD,wCAeC;AAED;;;;;;;;;GASG;AACH,MAAa,mBAAoB,SAAQ,cAAc;IACrD,YAAY,OAAY;QACtB,KAAK,CAAC,+CAA+C,EAAE,qBAAqB,EAAE,OAAO,CAAC,CAAA;IACxF,CAAC;CACF;AAJD,kDAIC;AAED;;;;;;;;;GASG;AACH,MAAa,mBAAoB,SAAQ,cAAc;IACrD,YAAY,OAAY;QACtB,KAAK,CAAC,wCAAwC,EAAE,qBAAqB,EAAE,OAAO,CAAC,CAAA;IACjF,CAAC;CACF;AAJD,kDAIC;AAED;;;;;;;;;GASG;AACH,MAAa,kBAAmB,SAAQ,cAAc;IACpD,YAAY,OAAY;QACtB,KAAK,CAAC,8CAA8C,EAAE,oBAAoB,EAAE,OAAO,CAAC,CAAA;IACtF,CAAC;CACF;AAJD,gDAIC;AACD,4CAA4C;AAC5C,IAAY,cAgBX;AAhBD,WAAY,cAAc;IACxB,6BAAW,CAAA;IACX,iDAA+B,CAAA;IAC/B,iDAA+B,CAAA;IAC/B,yCAAuB,CAAA;IACvB,iDAA+B,CAAA;IAC/B,iDAA+B,CAAA;IAC/B,6CAA2B,CAAA;IAC3B,6CAA2B,CAAA;IAC3B,uCAAqB,CAAA;IACrB,uCAAqB,CAAA;IACrB,uCAAqB,CAAA;IACrB,uCAAqB,CAAA;IACrB,uCAAqB,CAAA;IACrB,uCAAqB,CAAA;IACrB,uCAAqB,CAAA;AACvB,CAAC,EAhBW,cAAc,8BAAd,cAAc,QAgBzB"}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
export declare const version = "2.110.8";
|
||||
//# sourceMappingURL=version.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,OAAO,YAAY,CAAA"}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.version = void 0;
|
||||
// Generated automatically during releases by scripts/update-version-files.ts
|
||||
// This file provides runtime access to the package version for:
|
||||
// - HTTP request headers (e.g., X-Client-Info header for API requests)
|
||||
// - Debugging and support (identifying which version is running)
|
||||
// - Telemetry and logging (version reporting in errors/analytics)
|
||||
// - Ensuring build artifacts match the published package version
|
||||
exports.version = '2.110.8';
|
||||
//# sourceMappingURL=version.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AAAA,6EAA6E;AAC7E,gEAAgE;AAChE,uEAAuE;AACvE,iEAAiE;AACjE,kEAAkE;AAClE,iEAAiE;AACpD,QAAA,OAAO,GAAG,SAAS,CAAA"}
|
||||
+179
@@ -0,0 +1,179 @@
|
||||
import { Fetch, FunctionInvokeOptions, FunctionRegion, FunctionsResponse } from './types';
|
||||
/**
|
||||
* Client for invoking Supabase Edge Functions.
|
||||
*/
|
||||
export declare class FunctionsClient {
|
||||
protected url: string;
|
||||
protected headers: Record<string, string>;
|
||||
protected region: FunctionRegion;
|
||||
protected fetch: Fetch;
|
||||
/**
|
||||
* Creates a new Functions client bound to an Edge Functions URL.
|
||||
*
|
||||
* @example Using supabase-js (recommended)
|
||||
* ```ts
|
||||
* import { createClient } from '@supabase/supabase-js'
|
||||
*
|
||||
* const supabase = createClient('https://xyzcompany.supabase.co', 'your-publishable-key')
|
||||
* const { data, error } = await supabase.functions.invoke('hello-world')
|
||||
* ```
|
||||
*
|
||||
* @category Edge Functions
|
||||
*
|
||||
* @example Standalone import for bundle-sensitive environments
|
||||
* ```ts
|
||||
* import { FunctionsClient, FunctionRegion } from '@supabase/functions-js'
|
||||
*
|
||||
* const functions = new FunctionsClient('https://xyzcompany.supabase.co/functions/v1', {
|
||||
* headers: { apikey: 'your-publishable-key' },
|
||||
* region: FunctionRegion.UsEast1,
|
||||
* })
|
||||
* ```
|
||||
*/
|
||||
constructor(url: string, { headers, customFetch, region, }?: {
|
||||
headers?: Record<string, string>;
|
||||
customFetch?: Fetch;
|
||||
region?: FunctionRegion;
|
||||
});
|
||||
/**
|
||||
* Updates the authorization header
|
||||
* @param token - the new jwt token sent in the authorisation header
|
||||
*
|
||||
* @category Edge Functions
|
||||
*
|
||||
* @example Setting the authorization header
|
||||
* ```ts
|
||||
* functions.setAuth(session.access_token)
|
||||
* ```
|
||||
*/
|
||||
setAuth(token: string): void;
|
||||
/**
|
||||
* Invokes a function
|
||||
* @param functionName - The name of the Function to invoke.
|
||||
* @param options - Options for invoking the Function.
|
||||
* @example
|
||||
* ```ts
|
||||
* const { data, error } = await functions.invoke('hello-world', {
|
||||
* body: { name: 'Ada' },
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* @category Edge Functions
|
||||
*
|
||||
* @remarks
|
||||
* - The API key is sent in the `apikey` header. The `Authorization` header is reserved
|
||||
* for the signed-in user's JWT (or a custom auth token) — when there is no session, a
|
||||
* new-format API key (`sb_publishable_…` / `sb_secret_…`) is not sent as a Bearer token.
|
||||
* - Invoke params generally match the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) spec.
|
||||
* - 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.
|
||||
* - 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.
|
||||
*
|
||||
* @example Basic invocation
|
||||
* ```js
|
||||
* const { data, error } = await supabase.functions.invoke('hello', {
|
||||
* body: { foo: 'bar' }
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* @exampleDescription Error handling
|
||||
* 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. Log the full error object so fields like `name`, `context`, and any structured body aren't hidden.
|
||||
*
|
||||
* @example Error handling
|
||||
* ```js
|
||||
* import { FunctionsHttpError, FunctionsRelayError, FunctionsFetchError } from "@supabase/supabase-js";
|
||||
*
|
||||
* const { data, error } = await supabase.functions.invoke('hello', {
|
||||
* headers: {
|
||||
* "my-custom-header": 'my-custom-header-value'
|
||||
* },
|
||||
* body: { foo: 'bar' }
|
||||
* })
|
||||
*
|
||||
* if (error instanceof FunctionsHttpError) {
|
||||
* const errorMessage = await error.context.json()
|
||||
* console.error('Function returned an error', errorMessage)
|
||||
* } else if (error instanceof FunctionsRelayError) {
|
||||
* console.error('Relay error:', error)
|
||||
* } else if (error instanceof FunctionsFetchError) {
|
||||
* console.error('Fetch error:', error)
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @exampleDescription Passing custom headers
|
||||
* You can pass custom headers to your function. Note: supabase-js automatically passes the `Authorization` header with the signed in user's JWT.
|
||||
*
|
||||
* @example Passing custom headers
|
||||
* ```js
|
||||
* const { data, error } = await supabase.functions.invoke('hello', {
|
||||
* headers: {
|
||||
* "my-custom-header": 'my-custom-header-value'
|
||||
* },
|
||||
* body: { foo: 'bar' }
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* @exampleDescription Calling with DELETE HTTP verb
|
||||
* You can also set the HTTP verb to `DELETE` when calling your Edge Function.
|
||||
*
|
||||
* @example Calling with DELETE HTTP verb
|
||||
* ```js
|
||||
* const { data, error } = await supabase.functions.invoke('hello', {
|
||||
* headers: {
|
||||
* "my-custom-header": 'my-custom-header-value'
|
||||
* },
|
||||
* body: { foo: 'bar' },
|
||||
* method: 'DELETE'
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* @exampleDescription Invoking a Function in the UsEast1 region
|
||||
* Here are the available regions:
|
||||
* - `FunctionRegion.Any`
|
||||
* - `FunctionRegion.ApNortheast1`
|
||||
* - `FunctionRegion.ApNortheast2`
|
||||
* - `FunctionRegion.ApSouth1`
|
||||
* - `FunctionRegion.ApSoutheast1`
|
||||
* - `FunctionRegion.ApSoutheast2`
|
||||
* - `FunctionRegion.CaCentral1`
|
||||
* - `FunctionRegion.EuCentral1`
|
||||
* - `FunctionRegion.EuWest1`
|
||||
* - `FunctionRegion.EuWest2`
|
||||
* - `FunctionRegion.EuWest3`
|
||||
* - `FunctionRegion.SaEast1`
|
||||
* - `FunctionRegion.UsEast1`
|
||||
* - `FunctionRegion.UsWest1`
|
||||
* - `FunctionRegion.UsWest2`
|
||||
*
|
||||
* @example Invoking a Function in the UsEast1 region
|
||||
* ```js
|
||||
* import { createClient, FunctionRegion } from '@supabase/supabase-js'
|
||||
*
|
||||
* const { data, error } = await supabase.functions.invoke('hello', {
|
||||
* body: { foo: 'bar' },
|
||||
* region: FunctionRegion.UsEast1
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* @exampleDescription Calling with GET HTTP verb
|
||||
* You can also set the HTTP verb to `GET` when calling your Edge Function.
|
||||
*
|
||||
* @example Calling with GET HTTP verb
|
||||
* ```js
|
||||
* const { data, error } = await supabase.functions.invoke('hello', {
|
||||
* headers: {
|
||||
* "my-custom-header": 'my-custom-header-value'
|
||||
* },
|
||||
* method: 'GET'
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* @example Standalone client invoke
|
||||
* ```ts
|
||||
* const { data, error } = await functions.invoke('hello-world', {
|
||||
* body: { name: 'Ada' },
|
||||
* })
|
||||
* ```
|
||||
*/
|
||||
invoke<T = any>(functionName: string, options?: FunctionInvokeOptions): Promise<FunctionsResponse<T>>;
|
||||
}
|
||||
//# sourceMappingURL=FunctionsClient.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"FunctionsClient.d.ts","sourceRoot":"","sources":["../../src/FunctionsClient.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,EACL,qBAAqB,EACrB,cAAc,EAId,iBAAiB,EAClB,MAAM,SAAS,CAAA;AAEhB;;GAEG;AACH,qBAAa,eAAe;IAC1B,SAAS,CAAC,GAAG,EAAE,MAAM,CAAA;IACrB,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACzC,SAAS,CAAC,MAAM,EAAE,cAAc,CAAA;IAChC,SAAS,CAAC,KAAK,EAAE,KAAK,CAAA;IAEtB;;;;;;;;;;;;;;;;;;;;;;OAsBG;gBAED,GAAG,EAAE,MAAM,EACX,EACE,OAAY,EACZ,WAAW,EACX,MAA2B,GAC5B,GAAE;QACD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QAChC,WAAW,CAAC,EAAE,KAAK,CAAA;QACnB,MAAM,CAAC,EAAE,cAAc,CAAA;KACnB;IAQR;;;;;;;;;;OAUG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM;IAIrB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8HG;IACG,MAAM,CAAC,CAAC,GAAG,GAAG,EAClB,YAAY,EAAE,MAAM,EACpB,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;CAgJjC"}
|
||||
+322
@@ -0,0 +1,322 @@
|
||||
import { __awaiter } from "tslib";
|
||||
import { resolveFetch } from './helper';
|
||||
import { FunctionRegion, FunctionsFetchError, FunctionsHttpError, FunctionsRelayError, } from './types';
|
||||
/**
|
||||
* Client for invoking Supabase Edge Functions.
|
||||
*/
|
||||
export class FunctionsClient {
|
||||
/**
|
||||
* Creates a new Functions client bound to an Edge Functions URL.
|
||||
*
|
||||
* @example Using supabase-js (recommended)
|
||||
* ```ts
|
||||
* import { createClient } from '@supabase/supabase-js'
|
||||
*
|
||||
* const supabase = createClient('https://xyzcompany.supabase.co', 'your-publishable-key')
|
||||
* const { data, error } = await supabase.functions.invoke('hello-world')
|
||||
* ```
|
||||
*
|
||||
* @category Edge Functions
|
||||
*
|
||||
* @example Standalone import for bundle-sensitive environments
|
||||
* ```ts
|
||||
* import { FunctionsClient, FunctionRegion } from '@supabase/functions-js'
|
||||
*
|
||||
* const functions = new FunctionsClient('https://xyzcompany.supabase.co/functions/v1', {
|
||||
* headers: { apikey: 'your-publishable-key' },
|
||||
* region: FunctionRegion.UsEast1,
|
||||
* })
|
||||
* ```
|
||||
*/
|
||||
constructor(url, { headers = {}, customFetch, region = FunctionRegion.Any, } = {}) {
|
||||
this.url = url;
|
||||
this.headers = headers;
|
||||
this.region = region;
|
||||
this.fetch = resolveFetch(customFetch);
|
||||
}
|
||||
/**
|
||||
* Updates the authorization header
|
||||
* @param token - the new jwt token sent in the authorisation header
|
||||
*
|
||||
* @category Edge Functions
|
||||
*
|
||||
* @example Setting the authorization header
|
||||
* ```ts
|
||||
* functions.setAuth(session.access_token)
|
||||
* ```
|
||||
*/
|
||||
setAuth(token) {
|
||||
this.headers.Authorization = `Bearer ${token}`;
|
||||
}
|
||||
/**
|
||||
* Invokes a function
|
||||
* @param functionName - The name of the Function to invoke.
|
||||
* @param options - Options for invoking the Function.
|
||||
* @example
|
||||
* ```ts
|
||||
* const { data, error } = await functions.invoke('hello-world', {
|
||||
* body: { name: 'Ada' },
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* @category Edge Functions
|
||||
*
|
||||
* @remarks
|
||||
* - The API key is sent in the `apikey` header. The `Authorization` header is reserved
|
||||
* for the signed-in user's JWT (or a custom auth token) — when there is no session, a
|
||||
* new-format API key (`sb_publishable_…` / `sb_secret_…`) is not sent as a Bearer token.
|
||||
* - Invoke params generally match the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) spec.
|
||||
* - 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.
|
||||
* - 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.
|
||||
*
|
||||
* @example Basic invocation
|
||||
* ```js
|
||||
* const { data, error } = await supabase.functions.invoke('hello', {
|
||||
* body: { foo: 'bar' }
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* @exampleDescription Error handling
|
||||
* 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. Log the full error object so fields like `name`, `context`, and any structured body aren't hidden.
|
||||
*
|
||||
* @example Error handling
|
||||
* ```js
|
||||
* import { FunctionsHttpError, FunctionsRelayError, FunctionsFetchError } from "@supabase/supabase-js";
|
||||
*
|
||||
* const { data, error } = await supabase.functions.invoke('hello', {
|
||||
* headers: {
|
||||
* "my-custom-header": 'my-custom-header-value'
|
||||
* },
|
||||
* body: { foo: 'bar' }
|
||||
* })
|
||||
*
|
||||
* if (error instanceof FunctionsHttpError) {
|
||||
* const errorMessage = await error.context.json()
|
||||
* console.error('Function returned an error', errorMessage)
|
||||
* } else if (error instanceof FunctionsRelayError) {
|
||||
* console.error('Relay error:', error)
|
||||
* } else if (error instanceof FunctionsFetchError) {
|
||||
* console.error('Fetch error:', error)
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @exampleDescription Passing custom headers
|
||||
* You can pass custom headers to your function. Note: supabase-js automatically passes the `Authorization` header with the signed in user's JWT.
|
||||
*
|
||||
* @example Passing custom headers
|
||||
* ```js
|
||||
* const { data, error } = await supabase.functions.invoke('hello', {
|
||||
* headers: {
|
||||
* "my-custom-header": 'my-custom-header-value'
|
||||
* },
|
||||
* body: { foo: 'bar' }
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* @exampleDescription Calling with DELETE HTTP verb
|
||||
* You can also set the HTTP verb to `DELETE` when calling your Edge Function.
|
||||
*
|
||||
* @example Calling with DELETE HTTP verb
|
||||
* ```js
|
||||
* const { data, error } = await supabase.functions.invoke('hello', {
|
||||
* headers: {
|
||||
* "my-custom-header": 'my-custom-header-value'
|
||||
* },
|
||||
* body: { foo: 'bar' },
|
||||
* method: 'DELETE'
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* @exampleDescription Invoking a Function in the UsEast1 region
|
||||
* Here are the available regions:
|
||||
* - `FunctionRegion.Any`
|
||||
* - `FunctionRegion.ApNortheast1`
|
||||
* - `FunctionRegion.ApNortheast2`
|
||||
* - `FunctionRegion.ApSouth1`
|
||||
* - `FunctionRegion.ApSoutheast1`
|
||||
* - `FunctionRegion.ApSoutheast2`
|
||||
* - `FunctionRegion.CaCentral1`
|
||||
* - `FunctionRegion.EuCentral1`
|
||||
* - `FunctionRegion.EuWest1`
|
||||
* - `FunctionRegion.EuWest2`
|
||||
* - `FunctionRegion.EuWest3`
|
||||
* - `FunctionRegion.SaEast1`
|
||||
* - `FunctionRegion.UsEast1`
|
||||
* - `FunctionRegion.UsWest1`
|
||||
* - `FunctionRegion.UsWest2`
|
||||
*
|
||||
* @example Invoking a Function in the UsEast1 region
|
||||
* ```js
|
||||
* import { createClient, FunctionRegion } from '@supabase/supabase-js'
|
||||
*
|
||||
* const { data, error } = await supabase.functions.invoke('hello', {
|
||||
* body: { foo: 'bar' },
|
||||
* region: FunctionRegion.UsEast1
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* @exampleDescription Calling with GET HTTP verb
|
||||
* You can also set the HTTP verb to `GET` when calling your Edge Function.
|
||||
*
|
||||
* @example Calling with GET HTTP verb
|
||||
* ```js
|
||||
* const { data, error } = await supabase.functions.invoke('hello', {
|
||||
* headers: {
|
||||
* "my-custom-header": 'my-custom-header-value'
|
||||
* },
|
||||
* method: 'GET'
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* @example Standalone client invoke
|
||||
* ```ts
|
||||
* const { data, error } = await functions.invoke('hello-world', {
|
||||
* body: { name: 'Ada' },
|
||||
* })
|
||||
* ```
|
||||
*/
|
||||
invoke(functionName_1) {
|
||||
return __awaiter(this, arguments, void 0, function* (functionName, options = {}) {
|
||||
var _a, _b;
|
||||
let timeoutId;
|
||||
let timeoutController;
|
||||
let onAbort;
|
||||
try {
|
||||
const { headers, method, body: functionArgs, signal, timeout } = options;
|
||||
let _headers = {};
|
||||
let { region } = options;
|
||||
if (!region) {
|
||||
region = this.region;
|
||||
}
|
||||
// Add region as query parameter using URL API
|
||||
const url = new URL(`${this.url}/${functionName}`);
|
||||
if (region && region !== 'any') {
|
||||
_headers['x-region'] = region;
|
||||
url.searchParams.set('forceFunctionRegion', region);
|
||||
}
|
||||
let body;
|
||||
// HTTP header names are case-insensitive, so detect a caller-supplied Content-Type
|
||||
// regardless of casing — otherwise the SDK injects a second, conflicting Content-Type.
|
||||
const hasContentTypeHeader = !!headers && Object.keys(headers).some((key) => key.toLowerCase() === 'content-type');
|
||||
if (functionArgs && !hasContentTypeHeader) {
|
||||
if ((typeof Blob !== 'undefined' && functionArgs instanceof Blob) ||
|
||||
functionArgs instanceof ArrayBuffer) {
|
||||
// will work for File as File inherits Blob
|
||||
// also works for ArrayBuffer as it is the same underlying structure as a Blob
|
||||
_headers['Content-Type'] = 'application/octet-stream';
|
||||
body = functionArgs;
|
||||
}
|
||||
else if (typeof functionArgs === 'string') {
|
||||
// plain string
|
||||
_headers['Content-Type'] = 'text/plain';
|
||||
body = functionArgs;
|
||||
}
|
||||
else if (typeof FormData !== 'undefined' && functionArgs instanceof FormData) {
|
||||
// don't set content-type headers
|
||||
// Request will automatically add the right boundary value
|
||||
body = functionArgs;
|
||||
}
|
||||
else {
|
||||
// default, assume this is JSON
|
||||
_headers['Content-Type'] = 'application/json';
|
||||
body = JSON.stringify(functionArgs);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (functionArgs &&
|
||||
typeof functionArgs !== 'string' &&
|
||||
!(typeof Blob !== 'undefined' && functionArgs instanceof Blob) &&
|
||||
!(functionArgs instanceof ArrayBuffer) &&
|
||||
!(typeof FormData !== 'undefined' && functionArgs instanceof FormData)) {
|
||||
body = JSON.stringify(functionArgs);
|
||||
}
|
||||
else {
|
||||
body = functionArgs;
|
||||
}
|
||||
}
|
||||
// Handle timeout by creating an AbortController
|
||||
let effectiveSignal = signal;
|
||||
if (timeout) {
|
||||
timeoutController = new AbortController();
|
||||
timeoutId = setTimeout(() => timeoutController.abort(), timeout);
|
||||
// If user provided their own signal, we need to respect both
|
||||
if (signal) {
|
||||
effectiveSignal = timeoutController.signal;
|
||||
// If the user's signal is aborted, abort our timeout controller too.
|
||||
// Store the listener so we can clean it up in finally.
|
||||
onAbort = () => timeoutController.abort();
|
||||
signal.addEventListener('abort', onAbort);
|
||||
}
|
||||
else {
|
||||
effectiveSignal = timeoutController.signal;
|
||||
}
|
||||
}
|
||||
const response = yield this.fetch(url.toString(), {
|
||||
method: method || 'POST',
|
||||
// headers priority is (high to low):
|
||||
// 1. invoke-level headers
|
||||
// 2. client-level headers
|
||||
// 3. default Content-Type header
|
||||
headers: Object.assign(Object.assign(Object.assign({}, _headers), this.headers), headers),
|
||||
body,
|
||||
signal: effectiveSignal,
|
||||
}).catch((fetchError) => {
|
||||
throw new FunctionsFetchError(fetchError);
|
||||
});
|
||||
const isRelayError = response.headers.get('x-relay-error');
|
||||
if (isRelayError && isRelayError === 'true') {
|
||||
throw new FunctionsRelayError(response);
|
||||
}
|
||||
if (!response.ok) {
|
||||
throw new FunctionsHttpError(response);
|
||||
}
|
||||
// HTTP media types are case-insensitive (RFC 9110), so normalize before
|
||||
// matching — otherwise an "Application/JSON" response falls through to text.
|
||||
let responseType = ((_a = response.headers.get('Content-Type')) !== null && _a !== void 0 ? _a : 'text/plain')
|
||||
.split(';')[0]
|
||||
.trim()
|
||||
.toLowerCase();
|
||||
let data;
|
||||
if (responseType === 'application/json') {
|
||||
data = yield response.json();
|
||||
}
|
||||
else if (responseType === 'application/octet-stream' ||
|
||||
responseType === 'application/pdf') {
|
||||
data = yield response.blob();
|
||||
}
|
||||
else if (responseType === 'text/event-stream') {
|
||||
data = response;
|
||||
}
|
||||
else if (responseType === 'multipart/form-data') {
|
||||
data = yield response.formData();
|
||||
}
|
||||
else {
|
||||
// default to text
|
||||
data = yield response.text();
|
||||
}
|
||||
return { data, error: null, response };
|
||||
}
|
||||
catch (error) {
|
||||
return {
|
||||
data: null,
|
||||
error,
|
||||
response: error instanceof FunctionsHttpError || error instanceof FunctionsRelayError
|
||||
? error.context
|
||||
: undefined,
|
||||
};
|
||||
}
|
||||
finally {
|
||||
// Clear the timeout if it was set
|
||||
if (timeoutId) {
|
||||
clearTimeout(timeoutId);
|
||||
}
|
||||
// Remove the cross-signal listener to prevent memory leaks when the caller
|
||||
// reuses the same AbortSignal across multiple invocations.
|
||||
if (onAbort) {
|
||||
(_b = options.signal) === null || _b === void 0 ? void 0 : _b.removeEventListener('abort', onAbort);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=FunctionsClient.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"FunctionsClient.js","sourceRoot":"","sources":["../../src/FunctionsClient.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AACvC,OAAO,EAGL,cAAc,EACd,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,GAEpB,MAAM,SAAS,CAAA;AAEhB;;GAEG;AACH,MAAM,OAAO,eAAe;IAM1B;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,YACE,GAAW,EACX,EACE,OAAO,GAAG,EAAE,EACZ,WAAW,EACX,MAAM,GAAG,cAAc,CAAC,GAAG,MAKzB,EAAE;QAEN,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;QACd,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,KAAK,GAAG,YAAY,CAAC,WAAW,CAAC,CAAA;IACxC,CAAC;IAED;;;;;;;;;;OAUG;IACH,OAAO,CAAC,KAAa;QACnB,IAAI,CAAC,OAAO,CAAC,aAAa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,CAAC,CAAA;gBACzB,CAAC;gBACD,2EAA2E;gBAC3E,2DAA2D;gBAC3D,IAAI,OAAO,EAAE,CAAC;oBACZ,MAAA,OAAO,CAAC,MAAM,0CAAE,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;gBACvD,CAAC;YACH,CAAC;QACH,CAAC;KAAA;CACF"}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
import { Fetch } from './types';
|
||||
export declare const resolveFetch: (customFetch?: Fetch) => Fetch;
|
||||
//# sourceMappingURL=helper.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../../src/helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAE/B,eAAO,MAAM,YAAY,GAAI,cAAc,KAAK,KAAG,KAKlD,CAAA"}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
export const resolveFetch = (customFetch) => {
|
||||
if (customFetch) {
|
||||
return (...args) => customFetch(...args);
|
||||
}
|
||||
return (...args) => fetch(...args);
|
||||
};
|
||||
//# sourceMappingURL=helper.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../../src/helper.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,WAAmB,EAAS,EAAE;IACzD,IAAI,WAAW,EAAE,CAAC;QAChB,OAAO,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC,CAAA;IAC1C,CAAC;IACD,OAAO,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAA;AACpC,CAAC,CAAA"}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
export { FunctionsClient } from './FunctionsClient';
|
||||
export { type FunctionInvokeOptions, FunctionsError, FunctionsFetchError, FunctionsHttpError, FunctionsRelayError, FunctionRegion, type FunctionsResponse, } from './types';
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EACL,KAAK,qBAAqB,EAC1B,cAAc,EACd,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACnB,cAAc,EACd,KAAK,iBAAiB,GACvB,MAAM,SAAS,CAAA"}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
export { FunctionsClient } from './FunctionsClient';
|
||||
export { FunctionsError, FunctionsFetchError, FunctionsHttpError, FunctionsRelayError, FunctionRegion, } from './types';
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAEL,cAAc,EACd,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACnB,cAAc,GAEf,MAAM,SAAS,CAAA"}
|
||||
+122
@@ -0,0 +1,122 @@
|
||||
export type Fetch = typeof fetch;
|
||||
/**
|
||||
* Response format
|
||||
*/
|
||||
export interface FunctionsResponseSuccess<T> {
|
||||
data: T;
|
||||
error: null;
|
||||
response?: Response;
|
||||
}
|
||||
export interface FunctionsResponseFailure {
|
||||
data: null;
|
||||
error: any;
|
||||
response?: Response;
|
||||
}
|
||||
export type FunctionsResponse<T> = FunctionsResponseSuccess<T> | FunctionsResponseFailure;
|
||||
/**
|
||||
* Base error for Supabase Edge Function invocations.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { FunctionsError } from '@supabase/functions-js'
|
||||
*
|
||||
* throw new FunctionsError('Unexpected error invoking function', 'FunctionsError', {
|
||||
* requestId: 'abc123',
|
||||
* })
|
||||
* ```
|
||||
*/
|
||||
export declare class FunctionsError extends Error {
|
||||
context: any;
|
||||
constructor(message: string, name?: string, context?: any);
|
||||
toJSON(): {
|
||||
name: string;
|
||||
message: string;
|
||||
context: any;
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Error thrown when the network request to an Edge Function fails.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { FunctionsFetchError } from '@supabase/functions-js'
|
||||
*
|
||||
* throw new FunctionsFetchError({ requestId: 'abc123' })
|
||||
* ```
|
||||
*/
|
||||
export declare class FunctionsFetchError extends FunctionsError {
|
||||
constructor(context: any);
|
||||
}
|
||||
/**
|
||||
* Error thrown when the Supabase relay cannot reach the Edge Function.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { FunctionsRelayError } from '@supabase/functions-js'
|
||||
*
|
||||
* throw new FunctionsRelayError({ region: 'us-east-1' })
|
||||
* ```
|
||||
*/
|
||||
export declare class FunctionsRelayError extends FunctionsError {
|
||||
constructor(context: any);
|
||||
}
|
||||
/**
|
||||
* Error thrown when the Edge Function returns a non-2xx status code.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { FunctionsHttpError } from '@supabase/functions-js'
|
||||
*
|
||||
* throw new FunctionsHttpError({ status: 500 })
|
||||
* ```
|
||||
*/
|
||||
export declare class FunctionsHttpError extends FunctionsError {
|
||||
constructor(context: any);
|
||||
}
|
||||
export declare enum FunctionRegion {
|
||||
Any = "any",
|
||||
ApNortheast1 = "ap-northeast-1",
|
||||
ApNortheast2 = "ap-northeast-2",
|
||||
ApSouth1 = "ap-south-1",
|
||||
ApSoutheast1 = "ap-southeast-1",
|
||||
ApSoutheast2 = "ap-southeast-2",
|
||||
CaCentral1 = "ca-central-1",
|
||||
EuCentral1 = "eu-central-1",
|
||||
EuWest1 = "eu-west-1",
|
||||
EuWest2 = "eu-west-2",
|
||||
EuWest3 = "eu-west-3",
|
||||
SaEast1 = "sa-east-1",
|
||||
UsEast1 = "us-east-1",
|
||||
UsWest1 = "us-west-1",
|
||||
UsWest2 = "us-west-2"
|
||||
}
|
||||
export type FunctionInvokeOptions = {
|
||||
/**
|
||||
* Object representing the headers to send with the request.
|
||||
*/
|
||||
headers?: {
|
||||
[key: string]: string;
|
||||
};
|
||||
/**
|
||||
* The HTTP verb of the request
|
||||
*/
|
||||
method?: 'POST' | 'GET' | 'PUT' | 'PATCH' | 'DELETE';
|
||||
/**
|
||||
* The Region to invoke the function in.
|
||||
*/
|
||||
region?: FunctionRegion;
|
||||
/**
|
||||
* The body of the request.
|
||||
*/
|
||||
body?: File | Blob | ArrayBuffer | FormData | ReadableStream<Uint8Array> | Record<string, any> | string;
|
||||
/**
|
||||
* The AbortSignal to use for the request.
|
||||
* */
|
||||
signal?: AbortSignal;
|
||||
/**
|
||||
* The timeout for the request in milliseconds.
|
||||
* If the function takes longer than this, the request will be aborted.
|
||||
* */
|
||||
timeout?: number;
|
||||
};
|
||||
//# sourceMappingURL=types.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,KAAK,GAAG,OAAO,KAAK,CAAA;AAEhC;;GAEG;AACH,MAAM,WAAW,wBAAwB,CAAC,CAAC;IACzC,IAAI,EAAE,CAAC,CAAA;IACP,KAAK,EAAE,IAAI,CAAA;IACX,QAAQ,CAAC,EAAE,QAAQ,CAAA;CACpB;AACD,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,IAAI,CAAA;IACV,KAAK,EAAE,GAAG,CAAA;IACV,QAAQ,CAAC,EAAE,QAAQ,CAAA;CACpB;AACD,MAAM,MAAM,iBAAiB,CAAC,CAAC,IAAI,wBAAwB,CAAC,CAAC,CAAC,GAAG,wBAAwB,CAAA;AAEzF;;;;;;;;;;;GAWG;AACH,qBAAa,cAAe,SAAQ,KAAK;IACvC,OAAO,EAAE,GAAG,CAAA;gBACA,OAAO,EAAE,MAA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AA;IACpB;;;SAGK;IACL,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA"}
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
/**
|
||||
* Base error for Supabase Edge Function invocations.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { FunctionsError } from '@supabase/functions-js'
|
||||
*
|
||||
* throw new FunctionsError('Unexpected error invoking function', 'FunctionsError', {
|
||||
* requestId: 'abc123',
|
||||
* })
|
||||
* ```
|
||||
*/
|
||||
export class FunctionsError extends Error {
|
||||
constructor(message, name = 'FunctionsError', context) {
|
||||
super(message);
|
||||
this.name = name;
|
||||
this.context = context;
|
||||
}
|
||||
toJSON() {
|
||||
return {
|
||||
name: this.name,
|
||||
message: this.message,
|
||||
context: this.context,
|
||||
};
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Error thrown when the network request to an Edge Function fails.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { FunctionsFetchError } from '@supabase/functions-js'
|
||||
*
|
||||
* throw new FunctionsFetchError({ requestId: 'abc123' })
|
||||
* ```
|
||||
*/
|
||||
export class FunctionsFetchError extends FunctionsError {
|
||||
constructor(context) {
|
||||
super('Failed to send a request to the Edge Function', 'FunctionsFetchError', context);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Error thrown when the Supabase relay cannot reach the Edge Function.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { FunctionsRelayError } from '@supabase/functions-js'
|
||||
*
|
||||
* throw new FunctionsRelayError({ region: 'us-east-1' })
|
||||
* ```
|
||||
*/
|
||||
export class FunctionsRelayError extends FunctionsError {
|
||||
constructor(context) {
|
||||
super('Relay Error invoking the Edge Function', 'FunctionsRelayError', context);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Error thrown when the Edge Function returns a non-2xx status code.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { FunctionsHttpError } from '@supabase/functions-js'
|
||||
*
|
||||
* throw new FunctionsHttpError({ status: 500 })
|
||||
* ```
|
||||
*/
|
||||
export class FunctionsHttpError extends FunctionsError {
|
||||
constructor(context) {
|
||||
super('Edge Function returned a non-2xx status code', 'FunctionsHttpError', context);
|
||||
}
|
||||
}
|
||||
// Define the enum for the 'region' property
|
||||
export var FunctionRegion;
|
||||
(function (FunctionRegion) {
|
||||
FunctionRegion["Any"] = "any";
|
||||
FunctionRegion["ApNortheast1"] = "ap-northeast-1";
|
||||
FunctionRegion["ApNortheast2"] = "ap-northeast-2";
|
||||
FunctionRegion["ApSouth1"] = "ap-south-1";
|
||||
FunctionRegion["ApSoutheast1"] = "ap-southeast-1";
|
||||
FunctionRegion["ApSoutheast2"] = "ap-southeast-2";
|
||||
FunctionRegion["CaCentral1"] = "ca-central-1";
|
||||
FunctionRegion["EuCentral1"] = "eu-central-1";
|
||||
FunctionRegion["EuWest1"] = "eu-west-1";
|
||||
FunctionRegion["EuWest2"] = "eu-west-2";
|
||||
FunctionRegion["EuWest3"] = "eu-west-3";
|
||||
FunctionRegion["SaEast1"] = "sa-east-1";
|
||||
FunctionRegion["UsEast1"] = "us-east-1";
|
||||
FunctionRegion["UsWest1"] = "us-west-1";
|
||||
FunctionRegion["UsWest2"] = "us-west-2";
|
||||
})(FunctionRegion || (FunctionRegion = {}));
|
||||
//# sourceMappingURL=types.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAiBA;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,cAAe,SAAQ,KAAK;IAEvC,YAAY,OAAe,EAAE,IAAI,GAAG,gBAAgB,EAAE,OAAa;QACjE,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAED,MAAM;QACJ,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAA;IACH,CAAC;CACF;AAED;;;;;;;;;GASG;AACH,MAAM,OAAO,mBAAoB,SAAQ,cAAc;IACrD,YAAY,OAAY;QACtB,KAAK,CAAC,+CAA+C,EAAE,qBAAqB,EAAE,OAAO,CAAC,CAAA;IACxF,CAAC;CACF;AAED;;;;;;;;;GASG;AACH,MAAM,OAAO,mBAAoB,SAAQ,cAAc;IACrD,YAAY,OAAY;QACtB,KAAK,CAAC,wCAAwC,EAAE,qBAAqB,EAAE,OAAO,CAAC,CAAA;IACjF,CAAC;CACF;AAED;;;;;;;;;GASG;AACH,MAAM,OAAO,kBAAmB,SAAQ,cAAc;IACpD,YAAY,OAAY;QACtB,KAAK,CAAC,8CAA8C,EAAE,oBAAoB,EAAE,OAAO,CAAC,CAAA;IACtF,CAAC;CACF;AACD,4CAA4C;AAC5C,MAAM,CAAN,IAAY,cAgBX;AAhBD,WAAY,cAAc;IACxB,6BAAW,CAAA;IACX,iDAA+B,CAAA;IAC/B,iDAA+B,CAAA;IAC/B,yCAAuB,CAAA;IACvB,iDAA+B,CAAA;IAC/B,iDAA+B,CAAA;IAC/B,6CAA2B,CAAA;IAC3B,6CAA2B,CAAA;IAC3B,uCAAqB,CAAA;IACrB,uCAAqB,CAAA;IACrB,uCAAqB,CAAA;IACrB,uCAAqB,CAAA;IACrB,uCAAqB,CAAA;IACrB,uCAAqB,CAAA;IACrB,uCAAqB,CAAA;AACvB,CAAC,EAhBW,cAAc,KAAd,cAAc,QAgBzB"}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
export declare const version = "2.110.8";
|
||||
//# sourceMappingURL=version.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,OAAO,YAAY,CAAA"}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// Generated automatically during releases by scripts/update-version-files.ts
|
||||
// This file provides runtime access to the package version for:
|
||||
// - HTTP request headers (e.g., X-Client-Info header for API requests)
|
||||
// - Debugging and support (identifying which version is running)
|
||||
// - Telemetry and logging (version reporting in errors/analytics)
|
||||
// - Ensuring build artifacts match the published package version
|
||||
export const version = '2.110.8';
|
||||
//# sourceMappingURL=version.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,gEAAgE;AAChE,uEAAuE;AACvE,iEAAiE;AACjE,kEAAkE;AAClE,iEAAiE;AACjE,MAAM,CAAC,MAAM,OAAO,GAAG,SAAS,CAAA"}
|
||||
+1
File diff suppressed because one or more lines are too long
+1
File diff suppressed because one or more lines are too long
+25
@@ -0,0 +1,25 @@
|
||||
# Migration notes for `@supabase/functions-js`
|
||||
|
||||
Each file in this directory describes one migration theme — what changed in `@supabase/functions-js`, who is affected, and what callers need to do.
|
||||
|
||||
Files are shipped with the npm package, so the migration notes you see here are pinned to the version of `@supabase/functions-js` you have installed. Upgrading the package brings the relevant migration notes along with it.
|
||||
|
||||
## How agents should use this directory
|
||||
|
||||
When helping a developer upgrade `@supabase/functions-js`:
|
||||
|
||||
1. Read the migration files in `node_modules/@supabase/functions-js/migrations/` for the version they have installed.
|
||||
2. Cross-reference against the version they are upgrading to.
|
||||
3. Apply the migration steps described in each relevant file.
|
||||
|
||||
## How humans should use this directory
|
||||
|
||||
Browse the files for the migration theme you care about. Each file is self-contained and explains its own scope, audience, and steps.
|
||||
|
||||
## File naming
|
||||
|
||||
One file per migration theme, named by topic rather than version (e.g. `<theme>.md`, kebab-case). A single version can ship multiple theme files; a single theme can span multiple versions. Each file documents its own `Since` / `Will require action by` version range internally.
|
||||
|
||||
## Cross-cutting migration notes
|
||||
|
||||
Migrations that span multiple Supabase packages (e.g. Node.js version drops, monorepo restructures) live in [`docs/MIGRATION.md`](../../../../docs/MIGRATION.md) at the repository root, not here. This directory is scoped to `@supabase/functions-js` only.
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
{
|
||||
"name": "@supabase/functions-js",
|
||||
"version": "2.110.8",
|
||||
"description": "JS SDK to interact with Supabase Functions.",
|
||||
"main": "dist/main/index.js",
|
||||
"module": "dist/module/index.js",
|
||||
"types": "dist/module/index.d.ts",
|
||||
"sideEffects": false,
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/supabase/supabase-js.git",
|
||||
"directory": "packages/core/functions-js"
|
||||
},
|
||||
"keywords": [
|
||||
"functions",
|
||||
"supabase"
|
||||
],
|
||||
"author": "Supabase",
|
||||
"files": [
|
||||
"dist",
|
||||
"src",
|
||||
"migrations",
|
||||
"AGENTS.md"
|
||||
],
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/supabase/supabase-js/issues"
|
||||
},
|
||||
"homepage": "https://github.com/supabase/supabase-js/tree/master/packages/core/functions-js",
|
||||
"dependencies": {
|
||||
"tslib": "2.8.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@jest/types": "^30.0.0",
|
||||
"@types/jest": "30.0.0",
|
||||
"@types/jsonwebtoken": "^8.5.8",
|
||||
"@types/node": "20.19.9",
|
||||
"jest": "30.4.2",
|
||||
"jsonwebtoken": "^9.0.0",
|
||||
"nanoid": "^3.3.1",
|
||||
"openai": "^4.52.5",
|
||||
"testcontainers": "^8.5.1",
|
||||
"ts-jest": "^29.4.9",
|
||||
"typedoc": "^0.27.9",
|
||||
"typescript": "~5.8.3"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=22.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "npm run build:main && npm run build:module",
|
||||
"build:main": "tsc -p tsconfig.json",
|
||||
"build:module": "tsc -p tsconfig.module.json",
|
||||
"docs": "typedoc --options ../../../typedoc.base.mjs src/index.ts --out docs/v2",
|
||||
"docs:json": "typedoc --options ../../../typedoc.base.mjs --json docs/v2/spec.json --excludeExternals src/index.ts",
|
||||
"test": "jest",
|
||||
"test:ci": "jest --coverage"
|
||||
}
|
||||
}
|
||||
+351
@@ -0,0 +1,351 @@
|
||||
import { resolveFetch } from './helper'
|
||||
import {
|
||||
Fetch,
|
||||
FunctionInvokeOptions,
|
||||
FunctionRegion,
|
||||
FunctionsFetchError,
|
||||
FunctionsHttpError,
|
||||
FunctionsRelayError,
|
||||
FunctionsResponse,
|
||||
} from './types'
|
||||
|
||||
/**
|
||||
* Client for invoking Supabase Edge Functions.
|
||||
*/
|
||||
export class FunctionsClient {
|
||||
protected url: string
|
||||
protected headers: Record<string, string>
|
||||
protected region: FunctionRegion
|
||||
protected fetch: Fetch
|
||||
|
||||
/**
|
||||
* Creates a new Functions client bound to an Edge Functions URL.
|
||||
*
|
||||
* @example Using supabase-js (recommended)
|
||||
* ```ts
|
||||
* import { createClient } from '@supabase/supabase-js'
|
||||
*
|
||||
* const supabase = createClient('https://xyzcompany.supabase.co', 'your-publishable-key')
|
||||
* const { data, error } = await supabase.functions.invoke('hello-world')
|
||||
* ```
|
||||
*
|
||||
* @category Edge Functions
|
||||
*
|
||||
* @example Standalone import for bundle-sensitive environments
|
||||
* ```ts
|
||||
* import { FunctionsClient, FunctionRegion } from '@supabase/functions-js'
|
||||
*
|
||||
* const functions = new FunctionsClient('https://xyzcompany.supabase.co/functions/v1', {
|
||||
* headers: { apikey: 'your-publishable-key' },
|
||||
* region: FunctionRegion.UsEast1,
|
||||
* })
|
||||
* ```
|
||||
*/
|
||||
constructor(
|
||||
url: string,
|
||||
{
|
||||
headers = {},
|
||||
customFetch,
|
||||
region = FunctionRegion.Any,
|
||||
}: {
|
||||
headers?: Record<string, string>
|
||||
customFetch?: Fetch
|
||||
region?: FunctionRegion
|
||||
} = {}
|
||||
) {
|
||||
this.url = url
|
||||
this.headers = headers
|
||||
this.region = region
|
||||
this.fetch = resolveFetch(customFetch)
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the authorization header
|
||||
* @param token - the new jwt token sent in the authorisation header
|
||||
*
|
||||
* @category Edge Functions
|
||||
*
|
||||
* @example Setting the authorization header
|
||||
* ```ts
|
||||
* functions.setAuth(session.access_token)
|
||||
* ```
|
||||
*/
|
||||
setAuth(token: string) {
|
||||
this.headers.Authorization = `Bearer ${token}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes a function
|
||||
* @param functionName - The name of the Function to invoke.
|
||||
* @param options - Options for invoking the Function.
|
||||
* @example
|
||||
* ```ts
|
||||
* const { data, error } = await functions.invoke('hello-world', {
|
||||
* body: { name: 'Ada' },
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* @category Edge Functions
|
||||
*
|
||||
* @remarks
|
||||
* - The API key is sent in the `apikey` header. The `Authorization` header is reserved
|
||||
* for the signed-in user's JWT (or a custom auth token) — when there is no session, a
|
||||
* new-format API key (`sb_publishable_…` / `sb_secret_…`) is not sent as a Bearer token.
|
||||
* - Invoke params generally match the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) spec.
|
||||
* - 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.
|
||||
* - 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.
|
||||
*
|
||||
* @example Basic invocation
|
||||
* ```js
|
||||
* const { data, error } = await supabase.functions.invoke('hello', {
|
||||
* body: { foo: 'bar' }
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* @exampleDescription Error handling
|
||||
* 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. Log the full error object so fields like `name`, `context`, and any structured body aren't hidden.
|
||||
*
|
||||
* @example Error handling
|
||||
* ```js
|
||||
* import { FunctionsHttpError, FunctionsRelayError, FunctionsFetchError } from "@supabase/supabase-js";
|
||||
*
|
||||
* const { data, error } = await supabase.functions.invoke('hello', {
|
||||
* headers: {
|
||||
* "my-custom-header": 'my-custom-header-value'
|
||||
* },
|
||||
* body: { foo: 'bar' }
|
||||
* })
|
||||
*
|
||||
* if (error instanceof FunctionsHttpError) {
|
||||
* const errorMessage = await error.context.json()
|
||||
* console.error('Function returned an error', errorMessage)
|
||||
* } else if (error instanceof FunctionsRelayError) {
|
||||
* console.error('Relay error:', error)
|
||||
* } else if (error instanceof FunctionsFetchError) {
|
||||
* console.error('Fetch error:', error)
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @exampleDescription Passing custom headers
|
||||
* You can pass custom headers to your function. Note: supabase-js automatically passes the `Authorization` header with the signed in user's JWT.
|
||||
*
|
||||
* @example Passing custom headers
|
||||
* ```js
|
||||
* const { data, error } = await supabase.functions.invoke('hello', {
|
||||
* headers: {
|
||||
* "my-custom-header": 'my-custom-header-value'
|
||||
* },
|
||||
* body: { foo: 'bar' }
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* @exampleDescription Calling with DELETE HTTP verb
|
||||
* You can also set the HTTP verb to `DELETE` when calling your Edge Function.
|
||||
*
|
||||
* @example Calling with DELETE HTTP verb
|
||||
* ```js
|
||||
* const { data, error } = await supabase.functions.invoke('hello', {
|
||||
* headers: {
|
||||
* "my-custom-header": 'my-custom-header-value'
|
||||
* },
|
||||
* body: { foo: 'bar' },
|
||||
* method: 'DELETE'
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* @exampleDescription Invoking a Function in the UsEast1 region
|
||||
* Here are the available regions:
|
||||
* - `FunctionRegion.Any`
|
||||
* - `FunctionRegion.ApNortheast1`
|
||||
* - `FunctionRegion.ApNortheast2`
|
||||
* - `FunctionRegion.ApSouth1`
|
||||
* - `FunctionRegion.ApSoutheast1`
|
||||
* - `FunctionRegion.ApSoutheast2`
|
||||
* - `FunctionRegion.CaCentral1`
|
||||
* - `FunctionRegion.EuCentral1`
|
||||
* - `FunctionRegion.EuWest1`
|
||||
* - `FunctionRegion.EuWest2`
|
||||
* - `FunctionRegion.EuWest3`
|
||||
* - `FunctionRegion.SaEast1`
|
||||
* - `FunctionRegion.UsEast1`
|
||||
* - `FunctionRegion.UsWest1`
|
||||
* - `FunctionRegion.UsWest2`
|
||||
*
|
||||
* @example Invoking a Function in the UsEast1 region
|
||||
* ```js
|
||||
* import { createClient, FunctionRegion } from '@supabase/supabase-js'
|
||||
*
|
||||
* const { data, error } = await supabase.functions.invoke('hello', {
|
||||
* body: { foo: 'bar' },
|
||||
* region: FunctionRegion.UsEast1
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* @exampleDescription Calling with GET HTTP verb
|
||||
* You can also set the HTTP verb to `GET` when calling your Edge Function.
|
||||
*
|
||||
* @example Calling with GET HTTP verb
|
||||
* ```js
|
||||
* const { data, error } = await supabase.functions.invoke('hello', {
|
||||
* headers: {
|
||||
* "my-custom-header": 'my-custom-header-value'
|
||||
* },
|
||||
* method: 'GET'
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* @example Standalone client invoke
|
||||
* ```ts
|
||||
* const { data, error } = await functions.invoke('hello-world', {
|
||||
* body: { name: 'Ada' },
|
||||
* })
|
||||
* ```
|
||||
*/
|
||||
async invoke<T = any>(
|
||||
functionName: string,
|
||||
options: FunctionInvokeOptions = {}
|
||||
): Promise<FunctionsResponse<T>> {
|
||||
let timeoutId: ReturnType<typeof setTimeout> | undefined
|
||||
let timeoutController: AbortController | undefined
|
||||
let onAbort: (() => void) | undefined
|
||||
|
||||
try {
|
||||
const { headers, method, body: functionArgs, signal, timeout } = options
|
||||
let _headers: Record<string, string> = {}
|
||||
let { region } = options
|
||||
if (!region) {
|
||||
region = this.region
|
||||
}
|
||||
// Add region as query parameter using URL API
|
||||
const url = new URL(`${this.url}/${functionName}`)
|
||||
if (region && region !== 'any') {
|
||||
_headers['x-region'] = region
|
||||
url.searchParams.set('forceFunctionRegion', region)
|
||||
}
|
||||
let body: any
|
||||
// HTTP header names are case-insensitive, so detect a caller-supplied Content-Type
|
||||
// regardless of casing — otherwise the SDK injects a second, conflicting Content-Type.
|
||||
const hasContentTypeHeader =
|
||||
!!headers && Object.keys(headers).some((key) => key.toLowerCase() === 'content-type')
|
||||
if (functionArgs && !hasContentTypeHeader) {
|
||||
if (
|
||||
(typeof Blob !== 'undefined' && functionArgs instanceof Blob) ||
|
||||
functionArgs instanceof ArrayBuffer
|
||||
) {
|
||||
// will work for File as File inherits Blob
|
||||
// also works for ArrayBuffer as it is the same underlying structure as a Blob
|
||||
_headers['Content-Type'] = 'application/octet-stream'
|
||||
body = functionArgs
|
||||
} else if (typeof functionArgs === 'string') {
|
||||
// plain string
|
||||
_headers['Content-Type'] = 'text/plain'
|
||||
body = functionArgs
|
||||
} else if (typeof FormData !== 'undefined' && functionArgs instanceof FormData) {
|
||||
// don't set content-type headers
|
||||
// Request will automatically add the right boundary value
|
||||
body = functionArgs
|
||||
} else {
|
||||
// default, assume this is JSON
|
||||
_headers['Content-Type'] = 'application/json'
|
||||
body = JSON.stringify(functionArgs)
|
||||
}
|
||||
} else {
|
||||
if (
|
||||
functionArgs &&
|
||||
typeof functionArgs !== 'string' &&
|
||||
!(typeof Blob !== 'undefined' && functionArgs instanceof Blob) &&
|
||||
!(functionArgs instanceof ArrayBuffer) &&
|
||||
!(typeof FormData !== 'undefined' && functionArgs instanceof FormData)
|
||||
) {
|
||||
body = JSON.stringify(functionArgs)
|
||||
} else {
|
||||
body = functionArgs
|
||||
}
|
||||
}
|
||||
|
||||
// Handle timeout by creating an AbortController
|
||||
let effectiveSignal = signal
|
||||
if (timeout) {
|
||||
timeoutController = new AbortController()
|
||||
timeoutId = setTimeout(() => timeoutController!.abort(), timeout)
|
||||
|
||||
// If user provided their own signal, we need to respect both
|
||||
if (signal) {
|
||||
effectiveSignal = timeoutController.signal
|
||||
// If the user's signal is aborted, abort our timeout controller too.
|
||||
// Store the listener so we can clean it up in finally.
|
||||
onAbort = () => timeoutController!.abort()
|
||||
signal.addEventListener('abort', onAbort)
|
||||
} else {
|
||||
effectiveSignal = timeoutController.signal
|
||||
}
|
||||
}
|
||||
|
||||
const response = await this.fetch(url.toString(), {
|
||||
method: method || 'POST',
|
||||
// headers priority is (high to low):
|
||||
// 1. invoke-level headers
|
||||
// 2. client-level headers
|
||||
// 3. default Content-Type header
|
||||
headers: { ..._headers, ...this.headers, ...headers },
|
||||
body,
|
||||
signal: effectiveSignal,
|
||||
}).catch((fetchError) => {
|
||||
throw new FunctionsFetchError(fetchError)
|
||||
})
|
||||
|
||||
const isRelayError = response.headers.get('x-relay-error')
|
||||
if (isRelayError && isRelayError === 'true') {
|
||||
throw new FunctionsRelayError(response)
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
throw new FunctionsHttpError(response)
|
||||
}
|
||||
|
||||
// HTTP media types are case-insensitive (RFC 9110), so normalize before
|
||||
// matching — otherwise an "Application/JSON" response falls through to text.
|
||||
let responseType = (response.headers.get('Content-Type') ?? 'text/plain')
|
||||
.split(';')[0]
|
||||
.trim()
|
||||
.toLowerCase()
|
||||
let data: any
|
||||
if (responseType === 'application/json') {
|
||||
data = await response.json()
|
||||
} else if (
|
||||
responseType === 'application/octet-stream' ||
|
||||
responseType === 'application/pdf'
|
||||
) {
|
||||
data = await response.blob()
|
||||
} else if (responseType === 'text/event-stream') {
|
||||
data = response
|
||||
} else if (responseType === 'multipart/form-data') {
|
||||
data = await response.formData()
|
||||
} else {
|
||||
// default to text
|
||||
data = await response.text()
|
||||
}
|
||||
|
||||
return { data, error: null, response }
|
||||
} catch (error) {
|
||||
return {
|
||||
data: null,
|
||||
error,
|
||||
response:
|
||||
error instanceof FunctionsHttpError || error instanceof FunctionsRelayError
|
||||
? error.context
|
||||
: undefined,
|
||||
}
|
||||
} finally {
|
||||
// Clear the timeout if it was set
|
||||
if (timeoutId) {
|
||||
clearTimeout(timeoutId)
|
||||
}
|
||||
// Remove the cross-signal listener to prevent memory leaks when the caller
|
||||
// reuses the same AbortSignal across multiple invocations.
|
||||
if (onAbort) {
|
||||
options.signal?.removeEventListener('abort', onAbort)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+214
@@ -0,0 +1,214 @@
|
||||
declare type BeforeunloadReason =
|
||||
| 'cpu'
|
||||
| 'memory'
|
||||
| 'wall_clock'
|
||||
| 'early_drop'
|
||||
| 'termination'
|
||||
| (string & {})
|
||||
|
||||
declare interface WindowEventMap {
|
||||
load: Event
|
||||
unload: Event
|
||||
beforeunload: CustomEvent<BeforeunloadReason>
|
||||
drain: Event
|
||||
}
|
||||
|
||||
// TODO(Nyannyacha): These two type defs will be provided later.
|
||||
|
||||
// deno-lint-ignore no-explicit-any
|
||||
type S3FsConfig = any
|
||||
|
||||
// deno-lint-ignore no-explicit-any
|
||||
type TmpFsConfig = any
|
||||
|
||||
type OtelPropagators = 'TraceContext' | 'Baggage'
|
||||
type OtelConsoleConfig = 'Ignore' | 'Capture' | 'Replace'
|
||||
type OtelConfig = {
|
||||
tracing_enabled?: boolean
|
||||
metrics_enabled?: boolean
|
||||
console?: OtelConsoleConfig
|
||||
propagators?: OtelPropagators[]
|
||||
}
|
||||
|
||||
interface UserWorkerFetchOptions {
|
||||
signal?: AbortSignal
|
||||
}
|
||||
|
||||
interface PermissionsOptions {
|
||||
allow_all?: boolean | null
|
||||
allow_env?: string[] | null
|
||||
deny_env?: string[] | null
|
||||
allow_net?: string[] | null
|
||||
deny_net?: string[] | null
|
||||
allow_ffi?: string[] | null
|
||||
deny_ffi?: string[] | null
|
||||
allow_read?: string[] | null
|
||||
deny_read?: string[] | null
|
||||
allow_run?: string[] | null
|
||||
deny_run?: string[] | null
|
||||
allow_sys?: string[] | null
|
||||
deny_sys?: string[] | null
|
||||
allow_write?: string[] | null
|
||||
deny_write?: string[] | null
|
||||
allow_import?: string[] | null
|
||||
}
|
||||
|
||||
interface UserWorkerCreateContext {
|
||||
sourceMap?: boolean | null
|
||||
importMapPath?: string | null
|
||||
shouldBootstrapMockFnThrowError?: boolean | null
|
||||
suppressEszipMigrationWarning?: boolean | null
|
||||
useReadSyncFileAPI?: boolean | null
|
||||
supervisor?: {
|
||||
requestAbsentTimeoutMs?: number | null
|
||||
}
|
||||
otel?: {
|
||||
[attribute: string]: string
|
||||
}
|
||||
}
|
||||
|
||||
interface UserWorkerCreateOptions {
|
||||
servicePath?: string | null
|
||||
envVars?: string[][] | [string, string][] | null
|
||||
noModuleCache?: boolean | null
|
||||
|
||||
forceCreate?: boolean | null
|
||||
allowRemoteModules?: boolean | null
|
||||
customModuleRoot?: string | null
|
||||
permissions?: PermissionsOptions | null
|
||||
|
||||
maybeEszip?: Uint8Array | null
|
||||
maybeEntrypoint?: string | null
|
||||
maybeModuleCode?: string | null
|
||||
|
||||
memoryLimitMb?: number | null
|
||||
lowMemoryMultiplier?: number | null
|
||||
workerTimeoutMs?: number | null
|
||||
cpuTimeSoftLimitMs?: number | null
|
||||
cpuTimeHardLimitMs?: number | null
|
||||
staticPatterns?: string[] | null
|
||||
|
||||
s3FsConfig?: S3FsConfig | null
|
||||
tmpFsConfig?: TmpFsConfig | null
|
||||
otelConfig?: OtelConfig | null
|
||||
|
||||
context?: UserWorkerCreateContext | null
|
||||
}
|
||||
|
||||
interface HeapStatistics {
|
||||
totalHeapSize: number
|
||||
totalHeapSizeExecutable: number
|
||||
totalPhysicalSize: number
|
||||
totalAvailableSize: number
|
||||
totalGlobalHandlesSize: number
|
||||
usedGlobalHandlesSize: number
|
||||
usedHeapSize: number
|
||||
mallocedMemory: number
|
||||
externalMemory: number
|
||||
peakMallocedMemory: number
|
||||
}
|
||||
|
||||
interface RuntimeMetrics {
|
||||
mainWorkerHeapStats: HeapStatistics
|
||||
eventWorkerHeapStats?: HeapStatistics
|
||||
}
|
||||
|
||||
interface MemInfo {
|
||||
total: number
|
||||
free: number
|
||||
available: number
|
||||
buffers: number
|
||||
cached: number
|
||||
swapTotal: number
|
||||
swapFree: number
|
||||
}
|
||||
|
||||
declare namespace EdgeRuntime {
|
||||
export namespace ai {
|
||||
function tryCleanupUnusedSession(): Promise<number>
|
||||
}
|
||||
|
||||
class UserWorker {
|
||||
constructor(key: string)
|
||||
|
||||
fetch(request: Request, options?: UserWorkerFetchOptions): Promise<Response>
|
||||
|
||||
static create(opts: UserWorkerCreateOptions): Promise<UserWorker>
|
||||
static tryCleanupIdleWorkers(timeoutMs: number): Promise<number>
|
||||
}
|
||||
|
||||
export function scheduleTermination(): void
|
||||
export function waitUntil<T>(promise: Promise<T>): Promise<T>
|
||||
export function getRuntimeMetrics(): Promise<RuntimeMetrics>
|
||||
export function applySupabaseTag(src: Request, dest: Request): void
|
||||
export function systemMemoryInfo(): MemInfo
|
||||
export function raiseSegfault(): void
|
||||
|
||||
export { UserWorker as userWorkers }
|
||||
}
|
||||
|
||||
declare namespace Supabase {
|
||||
export namespace ai {
|
||||
interface ModelOptions {
|
||||
/**
|
||||
* Pool embeddings by taking their mean. Applies only for `gte-small` model
|
||||
*/
|
||||
mean_pool?: boolean
|
||||
|
||||
/**
|
||||
* Normalize the embeddings result. Applies only for `gte-small` model
|
||||
*/
|
||||
normalize?: boolean
|
||||
|
||||
/**
|
||||
* Stream response from model. Applies only for LLMs like `mistral` (default: false)
|
||||
*/
|
||||
stream?: boolean
|
||||
|
||||
/**
|
||||
* Automatically abort the request to the model after specified time (in seconds). Applies only for LLMs like `mistral` (default: 60)
|
||||
*/
|
||||
timeout?: number
|
||||
|
||||
/**
|
||||
* Mode for the inference API host. (default: 'ollama')
|
||||
*/
|
||||
mode?: 'ollama' | 'openaicompatible'
|
||||
signal?: AbortSignal
|
||||
}
|
||||
|
||||
export class Session {
|
||||
/**
|
||||
* Create a new model session using given model
|
||||
*/
|
||||
constructor(model: string)
|
||||
|
||||
/**
|
||||
* Execute the given prompt in model session
|
||||
*/
|
||||
run(
|
||||
prompt:
|
||||
| string
|
||||
| Omit<import('openai').OpenAI.Chat.ChatCompletionCreateParams, 'model' | 'stream'>,
|
||||
modelOptions?: ModelOptions
|
||||
): unknown
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
declare namespace Deno {
|
||||
export namespace errors {
|
||||
class WorkerRequestCancelled extends Error {}
|
||||
class WorkerAlreadyRetired extends Error {}
|
||||
|
||||
/** Thrown when an outbound HTTP request is blocked by the rate limiter. */
|
||||
class RateLimitError extends Error {
|
||||
/**
|
||||
* Number of milliseconds until the rate-limit window resets.
|
||||
* `null` if the reset time could not be determined.
|
||||
*/
|
||||
retryAfterMs: number | null
|
||||
constructor(message: string, retryAfterMs?: number)
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
import { Fetch } from './types'
|
||||
|
||||
export const resolveFetch = (customFetch?: Fetch): Fetch => {
|
||||
if (customFetch) {
|
||||
return (...args) => customFetch(...args)
|
||||
}
|
||||
return (...args) => fetch(...args)
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
export { FunctionsClient } from './FunctionsClient'
|
||||
export {
|
||||
type FunctionInvokeOptions,
|
||||
FunctionsError,
|
||||
FunctionsFetchError,
|
||||
FunctionsHttpError,
|
||||
FunctionsRelayError,
|
||||
FunctionRegion,
|
||||
type FunctionsResponse,
|
||||
} from './types'
|
||||
+146
@@ -0,0 +1,146 @@
|
||||
export type Fetch = typeof fetch
|
||||
|
||||
/**
|
||||
* Response format
|
||||
*/
|
||||
export interface FunctionsResponseSuccess<T> {
|
||||
data: T
|
||||
error: null
|
||||
response?: Response
|
||||
}
|
||||
export interface FunctionsResponseFailure {
|
||||
data: null
|
||||
error: any
|
||||
response?: Response
|
||||
}
|
||||
export type FunctionsResponse<T> = FunctionsResponseSuccess<T> | FunctionsResponseFailure
|
||||
|
||||
/**
|
||||
* Base error for Supabase Edge Function invocations.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { FunctionsError } from '@supabase/functions-js'
|
||||
*
|
||||
* throw new FunctionsError('Unexpected error invoking function', 'FunctionsError', {
|
||||
* requestId: 'abc123',
|
||||
* })
|
||||
* ```
|
||||
*/
|
||||
export class FunctionsError extends Error {
|
||||
context: any
|
||||
constructor(message: string, name = 'FunctionsError', context?: any) {
|
||||
super(message)
|
||||
this.name = name
|
||||
this.context = context
|
||||
}
|
||||
|
||||
toJSON(): { name: string; message: string; context: any } {
|
||||
return {
|
||||
name: this.name,
|
||||
message: this.message,
|
||||
context: this.context,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Error thrown when the network request to an Edge Function fails.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { FunctionsFetchError } from '@supabase/functions-js'
|
||||
*
|
||||
* throw new FunctionsFetchError({ requestId: 'abc123' })
|
||||
* ```
|
||||
*/
|
||||
export class FunctionsFetchError extends FunctionsError {
|
||||
constructor(context: any) {
|
||||
super('Failed to send a request to the Edge Function', 'FunctionsFetchError', context)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Error thrown when the Supabase relay cannot reach the Edge Function.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { FunctionsRelayError } from '@supabase/functions-js'
|
||||
*
|
||||
* throw new FunctionsRelayError({ region: 'us-east-1' })
|
||||
* ```
|
||||
*/
|
||||
export class FunctionsRelayError extends FunctionsError {
|
||||
constructor(context: any) {
|
||||
super('Relay Error invoking the Edge Function', 'FunctionsRelayError', context)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Error thrown when the Edge Function returns a non-2xx status code.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* import { FunctionsHttpError } from '@supabase/functions-js'
|
||||
*
|
||||
* throw new FunctionsHttpError({ status: 500 })
|
||||
* ```
|
||||
*/
|
||||
export class FunctionsHttpError extends FunctionsError {
|
||||
constructor(context: any) {
|
||||
super('Edge Function returned a non-2xx status code', 'FunctionsHttpError', context)
|
||||
}
|
||||
}
|
||||
// Define the enum for the 'region' property
|
||||
export enum FunctionRegion {
|
||||
Any = 'any',
|
||||
ApNortheast1 = 'ap-northeast-1',
|
||||
ApNortheast2 = 'ap-northeast-2',
|
||||
ApSouth1 = 'ap-south-1',
|
||||
ApSoutheast1 = 'ap-southeast-1',
|
||||
ApSoutheast2 = 'ap-southeast-2',
|
||||
CaCentral1 = 'ca-central-1',
|
||||
EuCentral1 = 'eu-central-1',
|
||||
EuWest1 = 'eu-west-1',
|
||||
EuWest2 = 'eu-west-2',
|
||||
EuWest3 = 'eu-west-3',
|
||||
SaEast1 = 'sa-east-1',
|
||||
UsEast1 = 'us-east-1',
|
||||
UsWest1 = 'us-west-1',
|
||||
UsWest2 = 'us-west-2',
|
||||
}
|
||||
|
||||
export type FunctionInvokeOptions = {
|
||||
/**
|
||||
* Object representing the headers to send with the request.
|
||||
*/
|
||||
headers?: { [key: string]: string }
|
||||
/**
|
||||
* The HTTP verb of the request
|
||||
*/
|
||||
method?: 'POST' | 'GET' | 'PUT' | 'PATCH' | 'DELETE'
|
||||
/**
|
||||
* The Region to invoke the function in.
|
||||
*/
|
||||
region?: FunctionRegion
|
||||
/**
|
||||
* The body of the request.
|
||||
*/
|
||||
body?:
|
||||
| File
|
||||
| Blob
|
||||
| ArrayBuffer
|
||||
| FormData
|
||||
| ReadableStream<Uint8Array>
|
||||
| Record<string, any>
|
||||
| string
|
||||
/**
|
||||
* The AbortSignal to use for the request.
|
||||
* */
|
||||
signal?: AbortSignal
|
||||
/**
|
||||
* The timeout for the request in milliseconds.
|
||||
* If the function takes longer than this, the request will be aborted.
|
||||
* */
|
||||
timeout?: number
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// Generated automatically during releases by scripts/update-version-files.ts
|
||||
// This file provides runtime access to the package version for:
|
||||
// - HTTP request headers (e.g., X-Client-Info header for API requests)
|
||||
// - Debugging and support (identifying which version is running)
|
||||
// - Telemetry and logging (version reporting in errors/analytics)
|
||||
// - Ensuring build artifacts match the published package version
|
||||
export const version = '2.110.8'
|
||||
Reference in New Issue
Block a user