fix price and modular
This commit is contained in:
+69
-14
@@ -1,18 +1,26 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
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
|
||||
* ```ts
|
||||
* import { FunctionsClient, FunctionRegion } from '@supabase/functions-js'
|
||||
*
|
||||
* const functions = new FunctionsClient('https://xyzcompany.supabase.co/functions/v1', {
|
||||
* headers: { apikey: 'public-anon-key' },
|
||||
* region: FunctionRegion.UsEast1,
|
||||
* })
|
||||
* ```
|
||||
*/
|
||||
constructor(url, { headers = {}, customFetch, region = types_1.FunctionRegion.Any, } = {}) {
|
||||
this.url = url;
|
||||
this.headers = headers;
|
||||
@@ -22,6 +30,10 @@ class FunctionsClient {
|
||||
/**
|
||||
* Updates the authorization header
|
||||
* @param token - the new jwt token sent in the authorisation header
|
||||
* @example
|
||||
* ```ts
|
||||
* functions.setAuth(session.access_token)
|
||||
* ```
|
||||
*/
|
||||
setAuth(token) {
|
||||
this.headers.Authorization = `Bearer ${token}`;
|
||||
@@ -30,12 +42,20 @@ class FunctionsClient {
|
||||
* 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' },
|
||||
* })
|
||||
* ```
|
||||
*/
|
||||
invoke(functionName, options = {}) {
|
||||
var _a;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
invoke(functionName_1) {
|
||||
return tslib_1.__awaiter(this, arguments, void 0, function* (functionName, options = {}) {
|
||||
var _a;
|
||||
let timeoutId;
|
||||
let timeoutController;
|
||||
try {
|
||||
const { headers, method, body: functionArgs } = options;
|
||||
const { headers, method, body: functionArgs, signal, timeout } = options;
|
||||
let _headers = {};
|
||||
let { region } = options;
|
||||
if (!region) {
|
||||
@@ -73,6 +93,33 @@ class FunctionsClient {
|
||||
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
|
||||
signal.addEventListener('abort', () => timeoutController.abort());
|
||||
}
|
||||
else {
|
||||
effectiveSignal = timeoutController.signal;
|
||||
}
|
||||
}
|
||||
const response = yield this.fetch(url.toString(), {
|
||||
method: method || 'POST',
|
||||
// headers priority is (high to low):
|
||||
@@ -81,6 +128,7 @@ class FunctionsClient {
|
||||
// 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);
|
||||
});
|
||||
@@ -96,7 +144,8 @@ class FunctionsClient {
|
||||
if (responseType === 'application/json') {
|
||||
data = yield response.json();
|
||||
}
|
||||
else if (responseType === 'application/octet-stream') {
|
||||
else if (responseType === 'application/octet-stream' ||
|
||||
responseType === 'application/pdf') {
|
||||
data = yield response.blob();
|
||||
}
|
||||
else if (responseType === 'text/event-stream') {
|
||||
@@ -120,6 +169,12 @@ class FunctionsClient {
|
||||
: undefined,
|
||||
};
|
||||
}
|
||||
finally {
|
||||
// Clear the timeout if it was set
|
||||
if (timeoutId) {
|
||||
clearTimeout(timeoutId);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
+2
-32
@@ -1,41 +1,11 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.resolveFetch = void 0;
|
||||
const resolveFetch = (customFetch) => {
|
||||
let _fetch;
|
||||
if (customFetch) {
|
||||
_fetch = customFetch;
|
||||
return (...args) => customFetch(...args);
|
||||
}
|
||||
else if (typeof fetch === 'undefined') {
|
||||
_fetch = (...args) => Promise.resolve().then(() => __importStar(require('@supabase/node-fetch'))).then(({ default: fetch }) => fetch(...args));
|
||||
}
|
||||
else {
|
||||
_fetch = fetch;
|
||||
}
|
||||
return (...args) => _fetch(...args);
|
||||
return (...args) => fetch(...args);
|
||||
};
|
||||
exports.resolveFetch = resolveFetch;
|
||||
//# sourceMappingURL=helper.js.map
|
||||
+43
-1
@@ -1,6 +1,18 @@
|
||||
"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);
|
||||
@@ -9,18 +21,48 @@ class FunctionsError extends Error {
|
||||
}
|
||||
}
|
||||
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);
|
||||
@@ -45,5 +87,5 @@ var FunctionRegion;
|
||||
FunctionRegion["UsEast1"] = "us-east-1";
|
||||
FunctionRegion["UsWest1"] = "us-west-1";
|
||||
FunctionRegion["UsWest2"] = "us-west-2";
|
||||
})(FunctionRegion = exports.FunctionRegion || (exports.FunctionRegion = {}));
|
||||
})(FunctionRegion || (exports.FunctionRegion = FunctionRegion = {}));
|
||||
//# sourceMappingURL=types.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
../../../.nitro/tslib@2.8.1
|
||||
+14
-27
@@ -1,25 +1,24 @@
|
||||
{
|
||||
"name": "@supabase/functions-js",
|
||||
"version": "2.4.5",
|
||||
"description": "JS Client library to interact with Supabase Functions.",
|
||||
"version": "2.93.3",
|
||||
"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,
|
||||
"scripts": {
|
||||
"clean": "rimraf dist docs/v2",
|
||||
"format": "prettier --write \"{src,test}/**/*.ts\"",
|
||||
"build": "run-s clean format build:*",
|
||||
"build": "npm run build:main && npm run build:module",
|
||||
"build:main": "tsc -p tsconfig.json",
|
||||
"build:module": "tsc -p tsconfig.module.json",
|
||||
"docs": "typedoc src/index.ts --out docs/v2",
|
||||
"docs:json": "typedoc --json docs/v2/spec.json --excludeExternals src/index.ts",
|
||||
"test": "jest",
|
||||
"test:coverage": "jest --coverage"
|
||||
"test:ci": "jest --coverage"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/supabase/functions-js.git"
|
||||
"url": "https://github.com/supabase/supabase-js.git",
|
||||
"directory": "packages/core/functions-js"
|
||||
},
|
||||
"keywords": [
|
||||
"functions",
|
||||
@@ -32,34 +31,22 @@
|
||||
],
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/supabase/functions-js/issues"
|
||||
"url": "https://github.com/supabase/supabase-js/issues"
|
||||
},
|
||||
"homepage": "https://github.com/supabase/functions-js#readme",
|
||||
"homepage": "https://github.com/supabase/supabase-js/tree/master/packages/core/functions-js",
|
||||
"dependencies": {
|
||||
"@supabase/node-fetch": "^2.6.14"
|
||||
"tslib": "2.8.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@sebbo2002/semantic-release-jsr": "^1.0.0",
|
||||
"@types/jest": "^28.1.0",
|
||||
"@types/jsonwebtoken": "^8.5.8",
|
||||
"@types/node": "^18.7.0",
|
||||
"genversion": "^3.0.2",
|
||||
"jest": "^28.1.0",
|
||||
"jsonwebtoken": "^9.0.0",
|
||||
"bs-logger": "^0.2.6",
|
||||
"nanoid": "^3.3.1",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"openai": "^4.52.5",
|
||||
"prettier": "^2.6.0",
|
||||
"rimraf": "^3.0.2",
|
||||
"semantic-release-plugin-update-version-in-files": "^1.1.0",
|
||||
"testcontainers": "^8.5.1",
|
||||
"ts-jest": "^28.0.0",
|
||||
"ts-node": "^10.9.0",
|
||||
"ts-test-decorators": "^0.0.6",
|
||||
"typedoc": "^0.22.13",
|
||||
"typescript": "^4.6.2"
|
||||
"testcontainers": "^8.5.1"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20.0.0"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user