first build
This commit is contained in:
-127
@@ -1,127 +0,0 @@
|
||||
"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 helper_1 = require("./helper");
|
||||
const types_1 = require("./types");
|
||||
class FunctionsClient {
|
||||
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
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
invoke(functionName, options = {}) {
|
||||
var _a;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
const { headers, method, body: functionArgs } = 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;
|
||||
if (functionArgs &&
|
||||
((headers && !Object.prototype.hasOwnProperty.call(headers, 'Content-Type')) || !headers)) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
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,
|
||||
}).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);
|
||||
}
|
||||
let responseType = ((_a = response.headers.get('Content-Type')) !== null && _a !== void 0 ? _a : 'text/plain').split(';')[0].trim();
|
||||
let data;
|
||||
if (responseType === 'application/json') {
|
||||
data = yield response.json();
|
||||
}
|
||||
else if (responseType === 'application/octet-stream') {
|
||||
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,
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.FunctionsClient = FunctionsClient;
|
||||
//# sourceMappingURL=FunctionsClient.js.map
|
||||
-41
@@ -1,41 +0,0 @@
|
||||
"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;
|
||||
}
|
||||
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);
|
||||
};
|
||||
exports.resolveFetch = resolveFetch;
|
||||
//# sourceMappingURL=helper.js.map
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
"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
|
||||
-49
@@ -1,49 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.FunctionRegion = exports.FunctionsHttpError = exports.FunctionsRelayError = exports.FunctionsFetchError = exports.FunctionsError = void 0;
|
||||
class FunctionsError extends Error {
|
||||
constructor(message, name = 'FunctionsError', context) {
|
||||
super(message);
|
||||
this.name = name;
|
||||
this.context = context;
|
||||
}
|
||||
}
|
||||
exports.FunctionsError = FunctionsError;
|
||||
class FunctionsFetchError extends FunctionsError {
|
||||
constructor(context) {
|
||||
super('Failed to send a request to the Edge Function', 'FunctionsFetchError', context);
|
||||
}
|
||||
}
|
||||
exports.FunctionsFetchError = FunctionsFetchError;
|
||||
class FunctionsRelayError extends FunctionsError {
|
||||
constructor(context) {
|
||||
super('Relay Error invoking the Edge Function', 'FunctionsRelayError', context);
|
||||
}
|
||||
}
|
||||
exports.FunctionsRelayError = FunctionsRelayError;
|
||||
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 || (exports.FunctionRegion = {}));
|
||||
//# sourceMappingURL=types.js.map
|
||||
-65
@@ -1,65 +0,0 @@
|
||||
{
|
||||
"name": "@supabase/functions-js",
|
||||
"version": "2.4.5",
|
||||
"description": "JS Client library 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: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"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/supabase/functions-js.git"
|
||||
},
|
||||
"keywords": [
|
||||
"functions",
|
||||
"supabase"
|
||||
],
|
||||
"author": "Supabase",
|
||||
"files": [
|
||||
"dist",
|
||||
"src"
|
||||
],
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/supabase/functions-js/issues"
|
||||
},
|
||||
"homepage": "https://github.com/supabase/functions-js#readme",
|
||||
"dependencies": {
|
||||
"@supabase/node-fetch": "^2.6.14"
|
||||
},
|
||||
"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",
|
||||
"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"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user