@supabase/functions-js
Advanced tools
Comparing version 1.3.4 to 1.4.0-next.1
@@ -1,4 +0,3 @@ | ||
declare type Fetch = typeof fetch; | ||
import { Fetch } from './types'; | ||
export declare const resolveFetch: (customFetch?: typeof fetch | undefined) => Fetch; | ||
export {}; | ||
//# sourceMappingURL=helper.d.ts.map |
@@ -1,31 +0,3 @@ | ||
import { Fetch, FunctionInvokeOptions } from './types'; | ||
export declare class FunctionsClient { | ||
protected url: string; | ||
protected headers: Record<string, string>; | ||
protected fetch: Fetch; | ||
constructor(url: string, { headers, customFetch, }?: { | ||
headers?: Record<string, string>; | ||
customFetch?: Fetch; | ||
}); | ||
/** | ||
* Updates the authorization header | ||
* @params token - the new jwt token sent in the authorisation header | ||
*/ | ||
setAuth(token: string): void; | ||
/** | ||
* Invokes a function | ||
* @param functionName - the name of the function to invoke | ||
* @param invokeOptions - object with the following properties | ||
* `headers`: object representing the headers to send with the request | ||
* `body`: the body of the request | ||
* `responseType`: how the response should be parsed. The default is `json` | ||
*/ | ||
invoke<T = any>(functionName: string, invokeOptions?: FunctionInvokeOptions): Promise<{ | ||
data: T; | ||
error: null; | ||
} | { | ||
data: null; | ||
error: Error; | ||
}>; | ||
} | ||
export { FunctionsClient } from './FunctionsClient'; | ||
export { FunctionsError, FunctionsFetchError, FunctionsHttpError, FunctionsRelayError, FunctionsResponse, } from './types'; | ||
//# sourceMappingURL=index.d.ts.map |
"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"); | ||
class FunctionsClient { | ||
constructor(url, { headers = {}, customFetch, } = {}) { | ||
this.url = url; | ||
this.headers = headers; | ||
this.fetch = (0, helper_1.resolveFetch)(customFetch); | ||
} | ||
/** | ||
* Updates the authorization header | ||
* @params 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 invokeOptions - object with the following properties | ||
* `headers`: object representing the headers to send with the request | ||
* `body`: the body of the request | ||
* `responseType`: how the response should be parsed. The default is `json` | ||
*/ | ||
invoke(functionName, invokeOptions) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
const { headers, body } = invokeOptions !== null && invokeOptions !== void 0 ? invokeOptions : {}; | ||
const response = yield this.fetch(`${this.url}/${functionName}`, { | ||
method: 'POST', | ||
headers: Object.assign({}, this.headers, headers), | ||
body, | ||
}); | ||
const isRelayError = response.headers.get('x-relay-error'); | ||
if (isRelayError && isRelayError === 'true') { | ||
return { data: null, error: new Error(yield response.text()) }; | ||
} | ||
let data; | ||
const { responseType } = invokeOptions !== null && invokeOptions !== void 0 ? invokeOptions : {}; | ||
if (!responseType || responseType === 'json') { | ||
data = yield response.json(); | ||
} | ||
else if (responseType === 'arrayBuffer') { | ||
data = yield response.arrayBuffer(); | ||
} | ||
else if (responseType === 'blob') { | ||
data = yield response.blob(); | ||
} | ||
else { | ||
data = yield response.text(); | ||
} | ||
return { data, error: null }; | ||
} | ||
catch (error) { | ||
return { data: null, error }; | ||
} | ||
}); | ||
} | ||
} | ||
exports.FunctionsClient = FunctionsClient; | ||
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; } }); | ||
//# sourceMappingURL=index.js.map |
export declare type Fetch = typeof fetch; | ||
export declare enum ResponseType { | ||
json = 0, | ||
text = 1, | ||
arrayBuffer = 2, | ||
blob = 3 | ||
/** | ||
* Response format | ||
* | ||
*/ | ||
interface FunctionsResponseSuccess { | ||
data: any; | ||
error: null; | ||
} | ||
export declare type FunctionInvokeOptions = { | ||
headers?: { | ||
[key: string]: string; | ||
}; | ||
body?: Blob | BufferSource | FormData | URLSearchParams | ReadableStream<Uint8Array> | string; | ||
responseType?: keyof typeof ResponseType; | ||
}; | ||
interface FunctionsResponseFailure { | ||
data: null; | ||
error: any; | ||
} | ||
export declare type FunctionsResponse = FunctionsResponseSuccess | FunctionsResponseFailure; | ||
export declare class FunctionsError extends Error { | ||
context: any; | ||
constructor(message: string, name?: string, context?: any); | ||
} | ||
export declare class FunctionsFetchError extends FunctionsError { | ||
constructor(context: any); | ||
} | ||
export declare class FunctionsRelayError extends FunctionsError { | ||
constructor(context: any); | ||
} | ||
export declare class FunctionsHttpError extends FunctionsError { | ||
constructor(context: any); | ||
} | ||
export {}; | ||
//# sourceMappingURL=types.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ResponseType = void 0; | ||
var ResponseType; | ||
(function (ResponseType) { | ||
ResponseType[ResponseType["json"] = 0] = "json"; | ||
ResponseType[ResponseType["text"] = 1] = "text"; | ||
ResponseType[ResponseType["arrayBuffer"] = 2] = "arrayBuffer"; | ||
ResponseType[ResponseType["blob"] = 3] = "blob"; | ||
})(ResponseType = exports.ResponseType || (exports.ResponseType = {})); | ||
exports.FunctionsHttpError = exports.FunctionsRelayError = exports.FunctionsFetchError = exports.FunctionsError = void 0; | ||
class FunctionsError extends Error { | ||
constructor(message, name = 'FunctionsError', context) { | ||
super(message); | ||
super.name = name; | ||
this.context = context; | ||
} | ||
} | ||
exports.FunctionsError = FunctionsError; | ||
class FunctionsFetchError extends FunctionsError { | ||
constructor(context) { | ||
super('Failed to perform request to Edge Function', 'FunctionsFetchError', context); | ||
} | ||
} | ||
exports.FunctionsFetchError = FunctionsFetchError; | ||
class FunctionsRelayError extends FunctionsError { | ||
constructor(context) { | ||
super('Relay error communicating with deno backend', '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; | ||
//# sourceMappingURL=types.js.map |
@@ -1,2 +0,2 @@ | ||
export declare const version = "1.3.4"; | ||
export declare const version = "1.4.0-next.1"; | ||
//# sourceMappingURL=version.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.version = void 0; | ||
exports.version = '1.3.4'; | ||
exports.version = '1.4.0-next.1'; | ||
//# sourceMappingURL=version.js.map |
@@ -1,4 +0,3 @@ | ||
declare type Fetch = typeof fetch; | ||
import { Fetch } from './types'; | ||
export declare const resolveFetch: (customFetch?: typeof fetch | undefined) => Fetch; | ||
export {}; | ||
//# sourceMappingURL=helper.d.ts.map |
@@ -1,31 +0,3 @@ | ||
import { Fetch, FunctionInvokeOptions } from './types'; | ||
export declare class FunctionsClient { | ||
protected url: string; | ||
protected headers: Record<string, string>; | ||
protected fetch: Fetch; | ||
constructor(url: string, { headers, customFetch, }?: { | ||
headers?: Record<string, string>; | ||
customFetch?: Fetch; | ||
}); | ||
/** | ||
* Updates the authorization header | ||
* @params token - the new jwt token sent in the authorisation header | ||
*/ | ||
setAuth(token: string): void; | ||
/** | ||
* Invokes a function | ||
* @param functionName - the name of the function to invoke | ||
* @param invokeOptions - object with the following properties | ||
* `headers`: object representing the headers to send with the request | ||
* `body`: the body of the request | ||
* `responseType`: how the response should be parsed. The default is `json` | ||
*/ | ||
invoke<T = any>(functionName: string, invokeOptions?: FunctionInvokeOptions): Promise<{ | ||
data: T; | ||
error: null; | ||
} | { | ||
data: null; | ||
error: Error; | ||
}>; | ||
} | ||
export { FunctionsClient } from './FunctionsClient'; | ||
export { FunctionsError, FunctionsFetchError, FunctionsHttpError, FunctionsRelayError, FunctionsResponse, } from './types'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,67 +0,3 @@ | ||
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()); | ||
}); | ||
}; | ||
import { resolveFetch } from './helper'; | ||
export class FunctionsClient { | ||
constructor(url, { headers = {}, customFetch, } = {}) { | ||
this.url = url; | ||
this.headers = headers; | ||
this.fetch = resolveFetch(customFetch); | ||
} | ||
/** | ||
* Updates the authorization header | ||
* @params 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 invokeOptions - object with the following properties | ||
* `headers`: object representing the headers to send with the request | ||
* `body`: the body of the request | ||
* `responseType`: how the response should be parsed. The default is `json` | ||
*/ | ||
invoke(functionName, invokeOptions) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
const { headers, body } = invokeOptions !== null && invokeOptions !== void 0 ? invokeOptions : {}; | ||
const response = yield this.fetch(`${this.url}/${functionName}`, { | ||
method: 'POST', | ||
headers: Object.assign({}, this.headers, headers), | ||
body, | ||
}); | ||
const isRelayError = response.headers.get('x-relay-error'); | ||
if (isRelayError && isRelayError === 'true') { | ||
return { data: null, error: new Error(yield response.text()) }; | ||
} | ||
let data; | ||
const { responseType } = invokeOptions !== null && invokeOptions !== void 0 ? invokeOptions : {}; | ||
if (!responseType || responseType === 'json') { | ||
data = yield response.json(); | ||
} | ||
else if (responseType === 'arrayBuffer') { | ||
data = yield response.arrayBuffer(); | ||
} | ||
else if (responseType === 'blob') { | ||
data = yield response.blob(); | ||
} | ||
else { | ||
data = yield response.text(); | ||
} | ||
return { data, error: null }; | ||
} | ||
catch (error) { | ||
return { data: null, error }; | ||
} | ||
}); | ||
} | ||
} | ||
export { FunctionsClient } from './FunctionsClient'; | ||
export { FunctionsError, FunctionsFetchError, FunctionsHttpError, FunctionsRelayError, } from './types'; | ||
//# sourceMappingURL=index.js.map |
export declare type Fetch = typeof fetch; | ||
export declare enum ResponseType { | ||
json = 0, | ||
text = 1, | ||
arrayBuffer = 2, | ||
blob = 3 | ||
/** | ||
* Response format | ||
* | ||
*/ | ||
interface FunctionsResponseSuccess { | ||
data: any; | ||
error: null; | ||
} | ||
export declare type FunctionInvokeOptions = { | ||
headers?: { | ||
[key: string]: string; | ||
}; | ||
body?: Blob | BufferSource | FormData | URLSearchParams | ReadableStream<Uint8Array> | string; | ||
responseType?: keyof typeof ResponseType; | ||
}; | ||
interface FunctionsResponseFailure { | ||
data: null; | ||
error: any; | ||
} | ||
export declare type FunctionsResponse = FunctionsResponseSuccess | FunctionsResponseFailure; | ||
export declare class FunctionsError extends Error { | ||
context: any; | ||
constructor(message: string, name?: string, context?: any); | ||
} | ||
export declare class FunctionsFetchError extends FunctionsError { | ||
constructor(context: any); | ||
} | ||
export declare class FunctionsRelayError extends FunctionsError { | ||
constructor(context: any); | ||
} | ||
export declare class FunctionsHttpError extends FunctionsError { | ||
constructor(context: any); | ||
} | ||
export {}; | ||
//# sourceMappingURL=types.d.ts.map |
@@ -1,8 +0,23 @@ | ||
export var ResponseType; | ||
(function (ResponseType) { | ||
ResponseType[ResponseType["json"] = 0] = "json"; | ||
ResponseType[ResponseType["text"] = 1] = "text"; | ||
ResponseType[ResponseType["arrayBuffer"] = 2] = "arrayBuffer"; | ||
ResponseType[ResponseType["blob"] = 3] = "blob"; | ||
})(ResponseType || (ResponseType = {})); | ||
export class FunctionsError extends Error { | ||
constructor(message, name = 'FunctionsError', context) { | ||
super(message); | ||
super.name = name; | ||
this.context = context; | ||
} | ||
} | ||
export class FunctionsFetchError extends FunctionsError { | ||
constructor(context) { | ||
super('Failed to perform request to Edge Function', 'FunctionsFetchError', context); | ||
} | ||
} | ||
export class FunctionsRelayError extends FunctionsError { | ||
constructor(context) { | ||
super('Relay error communicating with deno backend', 'FunctionsRelayError', context); | ||
} | ||
} | ||
export class FunctionsHttpError extends FunctionsError { | ||
constructor(context) { | ||
super('Edge Function returned a non-2xx status code', 'FunctionsHttpError', context); | ||
} | ||
} | ||
//# sourceMappingURL=types.js.map |
@@ -1,2 +0,2 @@ | ||
export declare const version = "1.3.4"; | ||
export declare const version = "1.4.0-next.1"; | ||
//# sourceMappingURL=version.d.ts.map |
@@ -1,2 +0,2 @@ | ||
export const version = '1.3.4'; | ||
export const version = '1.4.0-next.1'; | ||
//# sourceMappingURL=version.js.map |
{ | ||
"name": "@supabase/functions-js", | ||
"version": "1.3.4", | ||
"version": "1.4.0-next.1", | ||
"description": "JS Client library to interact with Supabase Functions.", | ||
@@ -15,4 +15,4 @@ "main": "dist/main/index.js", | ||
"build:module": "tsc -p tsconfig.module.json", | ||
"docs": "typedoc src/index.ts", | ||
"docs:json": "typedoc --json docs/spec.json --excludeExternals src/index.ts", | ||
"docs": "typedoc src/index.ts src/types.ts --excludePrivate --excludeProtected", | ||
"docs:json": "typedoc --json docs/spec.json --excludeExternals src/index.ts src/types.ts", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
@@ -47,3 +47,3 @@ }, | ||
"semantic-release-plugin-update-version-in-files": "^1.1.0", | ||
"typedoc": "^0.22.13", | ||
"typedoc": "^0.23.10", | ||
"typescript": "^4.6.2" | ||
@@ -50,0 +50,0 @@ }, |
# `functions-js` | ||
JS Client library to interact with Supabase Functions. | ||
## Docs | ||
https://supabase.github.io/functions-js/index.html |
@@ -1,2 +0,2 @@ | ||
type Fetch = typeof fetch | ||
import { Fetch } from './types' | ||
@@ -3,0 +3,0 @@ export const resolveFetch = (customFetch?: Fetch): Fetch => { |
@@ -1,74 +0,8 @@ | ||
import { resolveFetch } from './helper' | ||
import { Fetch, FunctionInvokeOptions } from './types' | ||
export class FunctionsClient { | ||
protected url: string | ||
protected headers: Record<string, string> | ||
protected fetch: Fetch | ||
constructor( | ||
url: string, | ||
{ | ||
headers = {}, | ||
customFetch, | ||
}: { | ||
headers?: Record<string, string> | ||
customFetch?: Fetch | ||
} = {} | ||
) { | ||
this.url = url | ||
this.headers = headers | ||
this.fetch = resolveFetch(customFetch) | ||
} | ||
/** | ||
* Updates the authorization header | ||
* @params token - the new jwt token sent in the authorisation header | ||
*/ | ||
setAuth(token: string) { | ||
this.headers.Authorization = `Bearer ${token}` | ||
} | ||
/** | ||
* Invokes a function | ||
* @param functionName - the name of the function to invoke | ||
* @param invokeOptions - object with the following properties | ||
* `headers`: object representing the headers to send with the request | ||
* `body`: the body of the request | ||
* `responseType`: how the response should be parsed. The default is `json` | ||
*/ | ||
async invoke<T = any>( | ||
functionName: string, | ||
invokeOptions?: FunctionInvokeOptions | ||
): Promise<{ data: T; error: null } | { data: null; error: Error }> { | ||
try { | ||
const { headers, body } = invokeOptions ?? {} | ||
const response = await this.fetch(`${this.url}/${functionName}`, { | ||
method: 'POST', | ||
headers: Object.assign({}, this.headers, headers), | ||
body, | ||
}) | ||
const isRelayError = response.headers.get('x-relay-error') | ||
if (isRelayError && isRelayError === 'true') { | ||
return { data: null, error: new Error(await response.text()) } | ||
} | ||
let data | ||
const { responseType } = invokeOptions ?? {} | ||
if (!responseType || responseType === 'json') { | ||
data = await response.json() | ||
} else if (responseType === 'arrayBuffer') { | ||
data = await response.arrayBuffer() | ||
} else if (responseType === 'blob') { | ||
data = await response.blob() | ||
} else { | ||
data = await response.text() | ||
} | ||
return { data, error: null } | ||
} catch (error: any) { | ||
return { data: null, error } | ||
} | ||
} | ||
} | ||
export { FunctionsClient } from './FunctionsClient' | ||
export { | ||
FunctionsError, | ||
FunctionsFetchError, | ||
FunctionsHttpError, | ||
FunctionsRelayError, | ||
FunctionsResponse, | ||
} from './types' |
export type Fetch = typeof fetch | ||
export enum ResponseType { | ||
json, | ||
text, | ||
arrayBuffer, | ||
blob, | ||
/** | ||
* Response format | ||
* | ||
*/ | ||
interface FunctionsResponseSuccess { | ||
data: any | ||
error: null | ||
} | ||
interface FunctionsResponseFailure { | ||
data: null | ||
error: any | ||
} | ||
export type FunctionsResponse = FunctionsResponseSuccess | FunctionsResponseFailure | ||
export type FunctionInvokeOptions = { | ||
headers?: { [key: string]: string } | ||
body?: Blob | BufferSource | FormData | URLSearchParams | ReadableStream<Uint8Array> | string | ||
responseType?: keyof typeof ResponseType | ||
export class FunctionsError extends Error { | ||
context: any | ||
constructor(message: string, name = 'FunctionsError', context?: any) { | ||
super(message) | ||
super.name = name | ||
this.context = context | ||
} | ||
} | ||
export class FunctionsFetchError extends FunctionsError { | ||
constructor(context: any) { | ||
super('Failed to perform request to Edge Function', 'FunctionsFetchError', context) | ||
} | ||
} | ||
export class FunctionsRelayError extends FunctionsError { | ||
constructor(context: any) { | ||
super('Relay error communicating with deno backend', 'FunctionsRelayError', context) | ||
} | ||
} | ||
export class FunctionsHttpError extends FunctionsError { | ||
constructor(context: any) { | ||
super('Edge Function returned a non-2xx status code', 'FunctionsHttpError', context) | ||
} | ||
} |
@@ -1,1 +0,1 @@ | ||
export const version = '1.3.4' | ||
export const version = '1.4.0-next.1' |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
40201
48
621
7
2
5