@supabase/functions-js 1.4.0-next.2 → 1.4.0-next.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { Fetch, FunctionsResponse } from './types';
1
+ import { Fetch, FunctionsResponse, FunctionInvokeOptions } from './types';
2
2
  export declare class FunctionsClient {
3
3
  protected url: string;
4
4
  protected headers: Record<string, string>;
@@ -9,18 +9,13 @@ export declare class FunctionsClient {
9
9
  });
10
10
  /**
11
11
  * Updates the authorization header
12
- * @params token - the new jwt token sent in the authorisation header
12
+ * @param token - the new jwt token sent in the authorisation header
13
13
  */
14
14
  setAuth(token: string): void;
15
15
  /**
16
16
  * Invokes a function
17
17
  * @param functionName - the name of the function to invoke
18
- * @param functionArgs - the arguments to the function
19
- * @param options - function invoke options
20
- * @param options.headers - headers to send with the request
21
18
  */
22
- invoke(functionName: string, functionArgs: any, { headers, }?: {
23
- headers?: Record<string, string>;
24
- }): Promise<FunctionsResponse>;
19
+ invoke<T = any>(functionName: string, invokeOptions?: FunctionInvokeOptions): Promise<FunctionsResponse<T>>;
25
20
  }
26
21
  //# sourceMappingURL=FunctionsClient.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FunctionsClient.d.ts","sourceRoot":"","sources":["../../src/FunctionsClient.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,EAIL,iBAAiB,EAClB,MAAM,SAAS,CAAA;AAEhB,qBAAa,eAAe;IAC1B,SAAS,CAAC,GAAG,EAAE,MAAM,CAAA;IACrB,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACzC,SAAS,CAAC,KAAK,EAAE,KAAK,CAAA;gBAGpB,GAAG,EAAE,MAAM,EACX,EACE,OAAY,EACZ,WAAW,GACZ,GAAE;QACD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QAChC,WAAW,CAAC,EAAE,KAAK,CAAA;KACf;IAOR;;;OAGG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM;IAIrB;;;;;;OAMG;IACG,MAAM,CACV,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,GAAG,EACjB,EACE,OAAY,GACb,GAAE;QACD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAC5B,GACL,OAAO,CAAC,iBAAiB,CAAC;CAiE9B"}
1
+ {"version":3,"file":"FunctionsClient.d.ts","sourceRoot":"","sources":["../../src/FunctionsClient.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,EAIL,iBAAiB,EACjB,qBAAqB,EACtB,MAAM,SAAS,CAAA;AAEhB,qBAAa,eAAe;IAC1B,SAAS,CAAC,GAAG,EAAE,MAAM,CAAA;IACrB,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACzC,SAAS,CAAC,KAAK,EAAE,KAAK,CAAA;gBAGpB,GAAG,EAAE,MAAM,EACX,EACE,OAAY,EACZ,WAAW,GACZ,GAAE;QACD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QAChC,WAAW,CAAC,EAAE,KAAK,CAAA;KACf;IAOR;;;OAGG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM;IAIrB;;;OAGG;IACG,MAAM,CAAC,CAAC,GAAG,GAAG,EAClB,YAAY,EAAE,MAAM,EACpB,aAAa,GAAE,qBAA0B,GACxC,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;CAwEjC"}
@@ -20,7 +20,7 @@ class FunctionsClient {
20
20
  }
21
21
  /**
22
22
  * Updates the authorization header
23
- * @params token - the new jwt token sent in the authorisation header
23
+ * @param token - the new jwt token sent in the authorisation header
24
24
  */
25
25
  setAuth(token) {
26
26
  this.headers.Authorization = `Bearer ${token}`;
@@ -28,37 +28,38 @@ class FunctionsClient {
28
28
  /**
29
29
  * Invokes a function
30
30
  * @param functionName - the name of the function to invoke
31
- * @param functionArgs - the arguments to the function
32
- * @param options - function invoke options
33
- * @param options.headers - headers to send with the request
34
31
  */
35
- invoke(functionName, functionArgs, { headers = {}, } = {}) {
32
+ invoke(functionName, invokeOptions = {}) {
36
33
  var _a;
37
34
  return __awaiter(this, void 0, void 0, function* () {
38
35
  try {
36
+ const { headers, body: functionArgs } = invokeOptions;
39
37
  let _headers = {};
40
38
  let body;
41
- if ((typeof Blob !== 'undefined' && functionArgs instanceof Blob) ||
42
- functionArgs instanceof ArrayBuffer) {
43
- // will work for File as File inherits Blob
44
- // also works for ArrayBuffer as it is the same underlying structure as a Blob
45
- _headers['Content-Type'] = 'application/octet-stream';
46
- body = functionArgs;
47
- }
48
- else if (typeof functionArgs === 'string') {
49
- // plain string
50
- _headers['Content-Type'] = 'text/plain';
51
- body = functionArgs;
52
- }
53
- else if (typeof FormData !== 'undefined' && functionArgs instanceof FormData) {
54
- // don't set content-type headers
55
- // Request will automatically add the right boundary value
56
- body = functionArgs;
57
- }
58
- else {
59
- // default, assume this is JSON
60
- _headers['Content-Type'] = 'application/json';
61
- body = JSON.stringify(functionArgs);
39
+ if (functionArgs &&
40
+ ((headers && !Object.prototype.hasOwnProperty.call(headers, 'Content-Type')) || !headers)) {
41
+ if ((typeof Blob !== 'undefined' && functionArgs instanceof Blob) ||
42
+ functionArgs instanceof ArrayBuffer) {
43
+ // will work for File as File inherits Blob
44
+ // also works for ArrayBuffer as it is the same underlying structure as a Blob
45
+ _headers['Content-Type'] = 'application/octet-stream';
46
+ body = functionArgs;
47
+ }
48
+ else if (typeof functionArgs === 'string') {
49
+ // plain string
50
+ _headers['Content-Type'] = 'text/plain';
51
+ body = functionArgs;
52
+ }
53
+ else if (typeof FormData !== 'undefined' && functionArgs instanceof FormData) {
54
+ // don't set content-type headers
55
+ // Request will automatically add the right boundary value
56
+ body = functionArgs;
57
+ }
58
+ else {
59
+ // default, assume this is JSON
60
+ _headers['Content-Type'] = 'application/json';
61
+ body = JSON.stringify(functionArgs);
62
+ }
62
63
  }
63
64
  const response = yield this.fetch(`${this.url}/${functionName}`, {
64
65
  method: 'POST',
@@ -1 +1 @@
1
- {"version":3,"file":"FunctionsClient.js","sourceRoot":"","sources":["../../src/FunctionsClient.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAAuC;AACvC,mCAMgB;AAEhB,MAAa,eAAe;IAK1B,YACE,GAAW,EACX,EACE,OAAO,GAAG,EAAE,EACZ,WAAW,MAIT,EAAE;QAEN,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;QACd,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,KAAK,GAAG,IAAA,qBAAY,EAAC,WAAW,CAAC,CAAA;IACxC,CAAC;IAED;;;OAGG;IACH,OAAO,CAAC,KAAa;QACnB,IAAI,CAAC,OAAO,CAAC,aAAa,GAAG,UAAU,KAAK,EAAE,CAAA;IAChD,CAAC;IAED;;;;;;OAMG;IACG,MAAM,CACV,YAAoB,EACpB,YAAiB,EACjB,EACE,OAAO,GAAG,EAAE,MAGV,EAAE;;;YAEN,IAAI;gBACF,IAAI,QAAQ,GAA2B,EAAE,CAAA;gBACzC,IAAI,IAAS,CAAA;gBACb,IACE,CAAC,OAAO,IAAI,KAAK,WAAW,IAAI,YAAY,YAAY,IAAI,CAAC;oBAC7D,YAAY,YAAY,WAAW,EACnC;oBACA,2CAA2C;oBAC3C,8EAA8E;oBAC9E,QAAQ,CAAC,cAAc,CAAC,GAAG,0BAA0B,CAAA;oBACrD,IAAI,GAAG,YAAY,CAAA;iBACpB;qBAAM,IAAI,OAAO,YAAY,KAAK,QAAQ,EAAE;oBAC3C,eAAe;oBACf,QAAQ,CAAC,cAAc,CAAC,GAAG,YAAY,CAAA;oBACvC,IAAI,GAAG,YAAY,CAAA;iBACpB;qBAAM,IAAI,OAAO,QAAQ,KAAK,WAAW,IAAI,YAAY,YAAY,QAAQ,EAAE;oBAC9E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CAAC,eAAe,CAAC,CAAA;gBAC1D,IAAI,YAAY,IAAI,YAAY,KAAK,MAAM,EAAE;oBAC3C,MAAM,IAAI,2BAAmB,CAAC,QAAQ,CAAC,CAAA;iBACxC;gBAED,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE;oBAChB,MAAM,IAAI,0BAAkB,CAAC,QAAQ,CAAC,CAAA;iBACvC;gBAED,IAAI,YAAY,GAAG,CAAC,MAAA,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,mCAAI,YAAY,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAA;gBAC9F,IAAI,IAAS,CAAA;gBACb,IAAI,YAAY,KAAK,kBAAkB,EAAE;oBACvC,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;iBAC7B;qBAAM,IAAI,YAAY,KAAK,0BAA0B,EAAE;oBACtD,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;iBAC7B;qBAAM,IAAI,YAAY,KAAK,qBAAqB,EAAE;oBACjD,IAAI,GAAG,MAAM,QAAQ,CAAC,QAAQ,EAAE,CAAA;iBACjC;qBAAM;oBACL,kBAAkB;oBAClB,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;iBAC7B;gBAED,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAA;aAC7B;YAAC,OAAO,KAAK,EAAE;gBACd,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAA;aAC7B;;KACF;CACF;AA3GD,0CA2GC"}
@@ -3,15 +3,15 @@ export declare type Fetch = typeof fetch;
3
3
  * Response format
4
4
  *
5
5
  */
6
- interface FunctionsResponseSuccess {
7
- data: any;
6
+ export interface FunctionsResponseSuccess<T> {
7
+ data: T;
8
8
  error: null;
9
9
  }
10
- interface FunctionsResponseFailure {
10
+ export interface FunctionsResponseFailure {
11
11
  data: null;
12
12
  error: any;
13
13
  }
14
- export declare type FunctionsResponse = FunctionsResponseSuccess | FunctionsResponseFailure;
14
+ export declare type FunctionsResponse<T> = FunctionsResponseSuccess<T> | FunctionsResponseFailure;
15
15
  export declare class FunctionsError extends Error {
16
16
  context: any;
17
17
  constructor(message: string, name?: string, context?: any);
@@ -25,5 +25,16 @@ export declare class FunctionsRelayError extends FunctionsError {
25
25
  export declare class FunctionsHttpError extends FunctionsError {
26
26
  constructor(context: any);
27
27
  }
28
- export {};
28
+ export declare type FunctionInvokeOptions = {
29
+ /**
30
+ * object representing the headers to send with the request
31
+ * */
32
+ headers?: {
33
+ [key: string]: string;
34
+ };
35
+ /**
36
+ * the body of the request
37
+ */
38
+ body?: File | Blob | ArrayBuffer | FormData | ReadableStream<Uint8Array> | Record<string, any> | string;
39
+ };
29
40
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,oBAAY,KAAK,GAAG,OAAO,KAAK,CAAA;AAEhC;;;GAGG;AACH,UAAU,wBAAwB;IAChC,IAAI,EAAE,GAAG,CAAA;IACT,KAAK,EAAE,IAAI,CAAA;CACZ;AACD,UAAU,wBAAwB;IAChC,IAAI,EAAE,IAAI,CAAA;IACV,KAAK,EAAE,GAAG,CAAA;CACX;AACD,oBAAY,iBAAiB,GAAG,wBAAwB,GAAG,wBAAwB,CAAA;AAEnF,qBAAa,cAAe,SAAQ,KAAK;IACvC,OAAO,EAAE,GAAG,CAAA;gBACA,OAAO,EAAE,MAAM,EAAE,IAAI,SAAmB,EAAE,OAAO,CAAC,EAAE,GAAG;CAKpE;AAED,qBAAa,mBAAoB,SAAQ,cAAc;gBACzC,OAAO,EAAE,GAAG;CAGzB;AAED,qBAAa,mBAAoB,SAAQ,cAAc;gBACzC,OAAO,EAAE,GAAG;CAGzB;AAED,qBAAa,kBAAmB,SAAQ,cAAc;gBACxC,OAAO,EAAE,GAAG;CAGzB"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,oBAAY,KAAK,GAAG,OAAO,KAAK,CAAA;AAEhC;;;GAGG;AACH,MAAM,WAAW,wBAAwB,CAAC,CAAC;IACzC,IAAI,EAAE,CAAC,CAAA;IACP,KAAK,EAAE,IAAI,CAAA;CACZ;AACD,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,IAAI,CAAA;IACV,KAAK,EAAE,GAAG,CAAA;CACX;AACD,oBAAY,iBAAiB,CAAC,CAAC,IAAI,wBAAwB,CAAC,CAAC,CAAC,GAAG,wBAAwB,CAAA;AAEzF,qBAAa,cAAe,SAAQ,KAAK;IACvC,OAAO,EAAE,GAAG,CAAA;gBACA,OAAO,EAAE,MAAM,EAAE,IAAI,SAAmB,EAAE,OAAO,CAAC,EAAE,GAAG;CAKpE;AAED,qBAAa,mBAAoB,SAAQ,cAAc;gBACzC,OAAO,EAAE,GAAG;CAGzB;AAED,qBAAa,mBAAoB,SAAQ,cAAc;gBACzC,OAAO,EAAE,GAAG;CAGzB;AAED,qBAAa,kBAAmB,SAAQ,cAAc;gBACxC,OAAO,EAAE,GAAG;CAGzB;AAED,oBAAY,qBAAqB,GAAG;IAClC;;SAEK;IACL,OAAO,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAA;IACnC;;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;CACX,CAAA"}
@@ -11,13 +11,13 @@ class FunctionsError extends Error {
11
11
  exports.FunctionsError = FunctionsError;
12
12
  class FunctionsFetchError extends FunctionsError {
13
13
  constructor(context) {
14
- super('Failed to perform request to Edge Function', 'FunctionsFetchError', context);
14
+ super('Failed to send a request to the Edge Function', 'FunctionsFetchError', context);
15
15
  }
16
16
  }
17
17
  exports.FunctionsFetchError = FunctionsFetchError;
18
18
  class FunctionsRelayError extends FunctionsError {
19
19
  constructor(context) {
20
- super('Relay error communicating with deno backend', 'FunctionsRelayError', context);
20
+ super('Relay Error invoking the Edge Function', 'FunctionsRelayError', context);
21
21
  }
22
22
  }
23
23
  exports.FunctionsRelayError = FunctionsRelayError;
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";;;AAgBA,MAAa,cAAe,SAAQ,KAAK;IAEvC,YAAY,OAAe,EAAE,IAAI,GAAG,gBAAgB,EAAE,OAAa;QACjE,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,KAAK,CAAC,IAAI,GAAG,IAAI,CAAA;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;CACF;AAPD,wCAOC;AAED,MAAa,mBAAoB,SAAQ,cAAc;IACrD,YAAY,OAAY;QACtB,KAAK,CAAC,4CAA4C,EAAE,qBAAqB,EAAE,OAAO,CAAC,CAAA;IACrF,CAAC;CACF;AAJD,kDAIC;AAED,MAAa,mBAAoB,SAAQ,cAAc;IACrD,YAAY,OAAY;QACtB,KAAK,CAAC,6CAA6C,EAAE,qBAAqB,EAAE,OAAO,CAAC,CAAA;IACtF,CAAC;CACF;AAJD,kDAIC;AAED,MAAa,kBAAmB,SAAQ,cAAc;IACpD,YAAY,OAAY;QACtB,KAAK,CAAC,8CAA8C,EAAE,oBAAoB,EAAE,OAAO,CAAC,CAAA;IACtF,CAAC;CACF;AAJD,gDAIC"}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";;;AAgBA,MAAa,cAAe,SAAQ,KAAK;IAEvC,YAAY,OAAe,EAAE,IAAI,GAAG,gBAAgB,EAAE,OAAa;QACjE,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,KAAK,CAAC,IAAI,GAAG,IAAI,CAAA;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;CACF;AAPD,wCAOC;AAED,MAAa,mBAAoB,SAAQ,cAAc;IACrD,YAAY,OAAY;QACtB,KAAK,CAAC,+CAA+C,EAAE,qBAAqB,EAAE,OAAO,CAAC,CAAA;IACxF,CAAC;CACF;AAJD,kDAIC;AAED,MAAa,mBAAoB,SAAQ,cAAc;IACrD,YAAY,OAAY;QACtB,KAAK,CAAC,wCAAwC,EAAE,qBAAqB,EAAE,OAAO,CAAC,CAAA;IACjF,CAAC;CACF;AAJD,kDAIC;AAED,MAAa,kBAAmB,SAAQ,cAAc;IACpD,YAAY,OAAY;QACtB,KAAK,CAAC,8CAA8C,EAAE,oBAAoB,EAAE,OAAO,CAAC,CAAA;IACtF,CAAC;CACF;AAJD,gDAIC"}
@@ -1,2 +1,2 @@
1
- export declare const version = "1.4.0-next.2";
1
+ export declare const version = "1.4.0-next.5";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.version = void 0;
4
- exports.version = '1.4.0-next.2';
4
+ exports.version = '1.4.0-next.5';
5
5
  //# sourceMappingURL=version.js.map
@@ -1,4 +1,4 @@
1
- import { Fetch, FunctionsResponse } from './types';
1
+ import { Fetch, FunctionsResponse, FunctionInvokeOptions } from './types';
2
2
  export declare class FunctionsClient {
3
3
  protected url: string;
4
4
  protected headers: Record<string, string>;
@@ -9,18 +9,13 @@ export declare class FunctionsClient {
9
9
  });
10
10
  /**
11
11
  * Updates the authorization header
12
- * @params token - the new jwt token sent in the authorisation header
12
+ * @param token - the new jwt token sent in the authorisation header
13
13
  */
14
14
  setAuth(token: string): void;
15
15
  /**
16
16
  * Invokes a function
17
17
  * @param functionName - the name of the function to invoke
18
- * @param functionArgs - the arguments to the function
19
- * @param options - function invoke options
20
- * @param options.headers - headers to send with the request
21
18
  */
22
- invoke(functionName: string, functionArgs: any, { headers, }?: {
23
- headers?: Record<string, string>;
24
- }): Promise<FunctionsResponse>;
19
+ invoke<T = any>(functionName: string, invokeOptions?: FunctionInvokeOptions): Promise<FunctionsResponse<T>>;
25
20
  }
26
21
  //# sourceMappingURL=FunctionsClient.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FunctionsClient.d.ts","sourceRoot":"","sources":["../../src/FunctionsClient.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,EAIL,iBAAiB,EAClB,MAAM,SAAS,CAAA;AAEhB,qBAAa,eAAe;IAC1B,SAAS,CAAC,GAAG,EAAE,MAAM,CAAA;IACrB,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACzC,SAAS,CAAC,KAAK,EAAE,KAAK,CAAA;gBAGpB,GAAG,EAAE,MAAM,EACX,EACE,OAAY,EACZ,WAAW,GACZ,GAAE;QACD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QAChC,WAAW,CAAC,EAAE,KAAK,CAAA;KACf;IAOR;;;OAGG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM;IAIrB;;;;;;OAMG;IACG,MAAM,CACV,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,GAAG,EACjB,EACE,OAAY,GACb,GAAE;QACD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAC5B,GACL,OAAO,CAAC,iBAAiB,CAAC;CAiE9B"}
1
+ {"version":3,"file":"FunctionsClient.d.ts","sourceRoot":"","sources":["../../src/FunctionsClient.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,EAIL,iBAAiB,EACjB,qBAAqB,EACtB,MAAM,SAAS,CAAA;AAEhB,qBAAa,eAAe;IAC1B,SAAS,CAAC,GAAG,EAAE,MAAM,CAAA;IACrB,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACzC,SAAS,CAAC,KAAK,EAAE,KAAK,CAAA;gBAGpB,GAAG,EAAE,MAAM,EACX,EACE,OAAY,EACZ,WAAW,GACZ,GAAE;QACD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QAChC,WAAW,CAAC,EAAE,KAAK,CAAA;KACf;IAOR;;;OAGG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM;IAIrB;;;OAGG;IACG,MAAM,CAAC,CAAC,GAAG,GAAG,EAClB,YAAY,EAAE,MAAM,EACpB,aAAa,GAAE,qBAA0B,GACxC,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;CAwEjC"}
@@ -17,7 +17,7 @@ export class FunctionsClient {
17
17
  }
18
18
  /**
19
19
  * Updates the authorization header
20
- * @params token - the new jwt token sent in the authorisation header
20
+ * @param token - the new jwt token sent in the authorisation header
21
21
  */
22
22
  setAuth(token) {
23
23
  this.headers.Authorization = `Bearer ${token}`;
@@ -25,37 +25,38 @@ export class FunctionsClient {
25
25
  /**
26
26
  * Invokes a function
27
27
  * @param functionName - the name of the function to invoke
28
- * @param functionArgs - the arguments to the function
29
- * @param options - function invoke options
30
- * @param options.headers - headers to send with the request
31
28
  */
32
- invoke(functionName, functionArgs, { headers = {}, } = {}) {
29
+ invoke(functionName, invokeOptions = {}) {
33
30
  var _a;
34
31
  return __awaiter(this, void 0, void 0, function* () {
35
32
  try {
33
+ const { headers, body: functionArgs } = invokeOptions;
36
34
  let _headers = {};
37
35
  let body;
38
- if ((typeof Blob !== 'undefined' && functionArgs instanceof Blob) ||
39
- functionArgs instanceof ArrayBuffer) {
40
- // will work for File as File inherits Blob
41
- // also works for ArrayBuffer as it is the same underlying structure as a Blob
42
- _headers['Content-Type'] = 'application/octet-stream';
43
- body = functionArgs;
44
- }
45
- else if (typeof functionArgs === 'string') {
46
- // plain string
47
- _headers['Content-Type'] = 'text/plain';
48
- body = functionArgs;
49
- }
50
- else if (typeof FormData !== 'undefined' && functionArgs instanceof FormData) {
51
- // don't set content-type headers
52
- // Request will automatically add the right boundary value
53
- body = functionArgs;
54
- }
55
- else {
56
- // default, assume this is JSON
57
- _headers['Content-Type'] = 'application/json';
58
- body = JSON.stringify(functionArgs);
36
+ if (functionArgs &&
37
+ ((headers && !Object.prototype.hasOwnProperty.call(headers, 'Content-Type')) || !headers)) {
38
+ if ((typeof Blob !== 'undefined' && functionArgs instanceof Blob) ||
39
+ functionArgs instanceof ArrayBuffer) {
40
+ // will work for File as File inherits Blob
41
+ // also works for ArrayBuffer as it is the same underlying structure as a Blob
42
+ _headers['Content-Type'] = 'application/octet-stream';
43
+ body = functionArgs;
44
+ }
45
+ else if (typeof functionArgs === 'string') {
46
+ // plain string
47
+ _headers['Content-Type'] = 'text/plain';
48
+ body = functionArgs;
49
+ }
50
+ else if (typeof FormData !== 'undefined' && functionArgs instanceof FormData) {
51
+ // don't set content-type headers
52
+ // Request will automatically add the right boundary value
53
+ body = functionArgs;
54
+ }
55
+ else {
56
+ // default, assume this is JSON
57
+ _headers['Content-Type'] = 'application/json';
58
+ body = JSON.stringify(functionArgs);
59
+ }
59
60
  }
60
61
  const response = yield this.fetch(`${this.url}/${functionName}`, {
61
62
  method: 'POST',
@@ -1 +1 @@
1
- {"version":3,"file":"FunctionsClient.js","sourceRoot":"","sources":["../../src/FunctionsClient.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AACvC,OAAO,EAEL,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,GAEpB,MAAM,SAAS,CAAA;AAEhB,MAAM,OAAO,eAAe;IAK1B,YACE,GAAW,EACX,EACE,OAAO,GAAG,EAAE,EACZ,WAAW,MAIT,EAAE;QAEN,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;QACd,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,KAAK,GAAG,YAA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AC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAA;gBAC9F,IAAI,IAAS,CAAA;gBACb,IAAI,YAAY,KAAK,kBAAkB,EAAE;oBACvC,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;iBAC7B;qBAAM,IAAI,YAAY,KAAK,0BAA0B,EAAE;oBACtD,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;iBAC7B;qBAAM,IAAI,YAAY,KAAK,qBAAqB,EAAE;oBACjD,IAAI,GAAG,MAAM,QAAQ,CAAC,QAAQ,EAAE,CAAA;iBACjC;qBAAM;oBACL,kBAAkB;oBAClB,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;iBAC7B;gBAED,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAA;aAC7B;YAAC,OAAO,KAAK,EAAE;gBACd,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAA;aAC7B;;KACF;CACF"}
@@ -3,15 +3,15 @@ export declare type Fetch = typeof fetch;
3
3
  * Response format
4
4
  *
5
5
  */
6
- interface FunctionsResponseSuccess {
7
- data: any;
6
+ export interface FunctionsResponseSuccess<T> {
7
+ data: T;
8
8
  error: null;
9
9
  }
10
- interface FunctionsResponseFailure {
10
+ export interface FunctionsResponseFailure {
11
11
  data: null;
12
12
  error: any;
13
13
  }
14
- export declare type FunctionsResponse = FunctionsResponseSuccess | FunctionsResponseFailure;
14
+ export declare type FunctionsResponse<T> = FunctionsResponseSuccess<T> | FunctionsResponseFailure;
15
15
  export declare class FunctionsError extends Error {
16
16
  context: any;
17
17
  constructor(message: string, name?: string, context?: any);
@@ -25,5 +25,16 @@ export declare class FunctionsRelayError extends FunctionsError {
25
25
  export declare class FunctionsHttpError extends FunctionsError {
26
26
  constructor(context: any);
27
27
  }
28
- export {};
28
+ export declare type FunctionInvokeOptions = {
29
+ /**
30
+ * object representing the headers to send with the request
31
+ * */
32
+ headers?: {
33
+ [key: string]: string;
34
+ };
35
+ /**
36
+ * the body of the request
37
+ */
38
+ body?: File | Blob | ArrayBuffer | FormData | ReadableStream<Uint8Array> | Record<string, any> | string;
39
+ };
29
40
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,oBAAY,KAAK,GAAG,OAAO,KAAK,CAAA;AAEhC;;;GAGG;AACH,UAAU,wBAAwB;IAChC,IAAI,EAAE,GAAG,CAAA;IACT,KAAK,EAAE,IAAI,CAAA;CACZ;AACD,UAAU,wBAAwB;IAChC,IAAI,EAAE,IAAI,CAAA;IACV,KAAK,EAAE,GAAG,CAAA;CACX;AACD,oBAAY,iBAAiB,GAAG,wBAAwB,GAAG,wBAAwB,CAAA;AAEnF,qBAAa,cAAe,SAAQ,KAAK;IACvC,OAAO,EAAE,GAAG,CAAA;gBACA,OAAO,EAAE,MAAM,EAAE,IAAI,SAAmB,EAAE,OAAO,CAAC,EAAE,GAAG;CAKpE;AAED,qBAAa,mBAAoB,SAAQ,cAAc;gBACzC,OAAO,EAAE,GAAG;CAGzB;AAED,qBAAa,mBAAoB,SAAQ,cAAc;gBACzC,OAAO,EAAE,GAAG;CAGzB;AAED,qBAAa,kBAAmB,SAAQ,cAAc;gBACxC,OAAO,EAAE,GAAG;CAGzB"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,oBAAY,KAAK,GAAG,OAAO,KAAK,CAAA;AAEhC;;;GAGG;AACH,MAAM,WAAW,wBAAwB,CAAC,CAAC;IACzC,IAAI,EAAE,CAAC,CAAA;IACP,KAAK,EAAE,IAAI,CAAA;CACZ;AACD,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,IAAI,CAAA;IACV,KAAK,EAAE,GAAG,CAAA;CACX;AACD,oBAAY,iBAAiB,CAAC,CAAC,IAAI,wBAAwB,CAAC,CAAC,CAAC,GAAG,wBAAwB,CAAA;AAEzF,qBAAa,cAAe,SAAQ,KAAK;IACvC,OAAO,EAAE,GAAG,CAAA;gBACA,OAAO,EAAE,MAAM,EAAE,IAAI,SAAmB,EAAE,OAAO,CAAC,EAAE,GAAG;CAKpE;AAED,qBAAa,mBAAoB,SAAQ,cAAc;gBACzC,OAAO,EAAE,GAAG;CAGzB;AAED,qBAAa,mBAAoB,SAAQ,cAAc;gBACzC,OAAO,EAAE,GAAG;CAGzB;AAED,qBAAa,kBAAmB,SAAQ,cAAc;gBACxC,OAAO,EAAE,GAAG;CAGzB;AAED,oBAAY,qBAAqB,GAAG;IAClC;;SAEK;IACL,OAAO,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAA;IACnC;;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;CACX,CAAA"}
@@ -7,12 +7,12 @@ export class FunctionsError extends Error {
7
7
  }
8
8
  export class FunctionsFetchError extends FunctionsError {
9
9
  constructor(context) {
10
- super('Failed to perform request to Edge Function', 'FunctionsFetchError', context);
10
+ super('Failed to send a request to the Edge Function', 'FunctionsFetchError', context);
11
11
  }
12
12
  }
13
13
  export class FunctionsRelayError extends FunctionsError {
14
14
  constructor(context) {
15
- super('Relay error communicating with deno backend', 'FunctionsRelayError', context);
15
+ super('Relay Error invoking the Edge Function', 'FunctionsRelayError', context);
16
16
  }
17
17
  }
18
18
  export class FunctionsHttpError extends FunctionsError {
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAgBA,MAAM,OAAO,cAAe,SAAQ,KAAK;IAEvC,YAAY,OAAe,EAAE,IAAI,GAAG,gBAAgB,EAAE,OAAa;QACjE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AC,CAAA;IACtF,CAAC;CACF"}
@@ -1,2 +1,2 @@
1
- export declare const version = "1.4.0-next.2";
1
+ export declare const version = "1.4.0-next.5";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -1,2 +1,2 @@
1
- export const version = '1.4.0-next.2';
1
+ export const version = '1.4.0-next.5';
2
2
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supabase/functions-js",
3
- "version": "1.4.0-next.2",
3
+ "version": "1.4.0-next.5",
4
4
  "description": "JS Client library to interact with Supabase Functions.",
5
5
  "main": "dist/main/index.js",
6
6
  "module": "dist/module/index.js",
@@ -43,7 +43,7 @@
43
43
  "rimraf": "^3.0.2",
44
44
  "semantic-release": "^19.0.2",
45
45
  "semantic-release-plugin-update-version-in-files": "^1.1.0",
46
- "typedoc": "^0.23.10",
46
+ "typedoc": "^0.22.16",
47
47
  "typescript": "^4.6.2"
48
48
  },
49
49
  "publishConfig": {
@@ -5,6 +5,7 @@ import {
5
5
  FunctionsHttpError,
6
6
  FunctionsRelayError,
7
7
  FunctionsResponse,
8
+ FunctionInvokeOptions,
8
9
  } from './types'
9
10
 
10
11
  export class FunctionsClient {
@@ -29,7 +30,7 @@ export class FunctionsClient {
29
30
 
30
31
  /**
31
32
  * Updates the authorization header
32
- * @params token - the new jwt token sent in the authorisation header
33
+ * @param token - the new jwt token sent in the authorisation header
33
34
  */
34
35
  setAuth(token: string) {
35
36
  this.headers.Authorization = `Bearer ${token}`
@@ -38,42 +39,41 @@ export class FunctionsClient {
38
39
  /**
39
40
  * Invokes a function
40
41
  * @param functionName - the name of the function to invoke
41
- * @param functionArgs - the arguments to the function
42
- * @param options - function invoke options
43
- * @param options.headers - headers to send with the request
44
42
  */
45
- async invoke(
43
+ async invoke<T = any>(
46
44
  functionName: string,
47
- functionArgs: any,
48
- {
49
- headers = {},
50
- }: {
51
- headers?: Record<string, string>
52
- } = {}
53
- ): Promise<FunctionsResponse> {
45
+ invokeOptions: FunctionInvokeOptions = {}
46
+ ): Promise<FunctionsResponse<T>> {
54
47
  try {
48
+ const { headers, body: functionArgs } = invokeOptions
49
+
55
50
  let _headers: Record<string, string> = {}
56
51
  let body: any
57
52
  if (
58
- (typeof Blob !== 'undefined' && functionArgs instanceof Blob) ||
59
- functionArgs instanceof ArrayBuffer
53
+ functionArgs &&
54
+ ((headers && !Object.prototype.hasOwnProperty.call(headers, 'Content-Type')) || !headers)
60
55
  ) {
61
- // will work for File as File inherits Blob
62
- // also works for ArrayBuffer as it is the same underlying structure as a Blob
63
- _headers['Content-Type'] = 'application/octet-stream'
64
- body = functionArgs
65
- } else if (typeof functionArgs === 'string') {
66
- // plain string
67
- _headers['Content-Type'] = 'text/plain'
68
- body = functionArgs
69
- } else if (typeof FormData !== 'undefined' && functionArgs instanceof FormData) {
70
- // don't set content-type headers
71
- // Request will automatically add the right boundary value
72
- body = functionArgs
73
- } else {
74
- // default, assume this is JSON
75
- _headers['Content-Type'] = 'application/json'
76
- body = JSON.stringify(functionArgs)
56
+ if (
57
+ (typeof Blob !== 'undefined' && functionArgs instanceof Blob) ||
58
+ functionArgs instanceof ArrayBuffer
59
+ ) {
60
+ // will work for File as File inherits Blob
61
+ // also works for ArrayBuffer as it is the same underlying structure as a Blob
62
+ _headers['Content-Type'] = 'application/octet-stream'
63
+ body = functionArgs
64
+ } else if (typeof functionArgs === 'string') {
65
+ // plain string
66
+ _headers['Content-Type'] = 'text/plain'
67
+ body = functionArgs
68
+ } else if (typeof FormData !== 'undefined' && functionArgs instanceof FormData) {
69
+ // don't set content-type headers
70
+ // Request will automatically add the right boundary value
71
+ body = functionArgs
72
+ } else {
73
+ // default, assume this is JSON
74
+ _headers['Content-Type'] = 'application/json'
75
+ body = JSON.stringify(functionArgs)
76
+ }
77
77
  }
78
78
 
79
79
  const response = await this.fetch(`${this.url}/${functionName}`, {
package/src/types.ts CHANGED
@@ -4,15 +4,15 @@ export type Fetch = typeof fetch
4
4
  * Response format
5
5
  *
6
6
  */
7
- interface FunctionsResponseSuccess {
8
- data: any
7
+ export interface FunctionsResponseSuccess<T> {
8
+ data: T
9
9
  error: null
10
10
  }
11
- interface FunctionsResponseFailure {
11
+ export interface FunctionsResponseFailure {
12
12
  data: null
13
13
  error: any
14
14
  }
15
- export type FunctionsResponse = FunctionsResponseSuccess | FunctionsResponseFailure
15
+ export type FunctionsResponse<T> = FunctionsResponseSuccess<T> | FunctionsResponseFailure
16
16
 
17
17
  export class FunctionsError extends Error {
18
18
  context: any
@@ -25,13 +25,13 @@ export class FunctionsError extends Error {
25
25
 
26
26
  export class FunctionsFetchError extends FunctionsError {
27
27
  constructor(context: any) {
28
- super('Failed to perform request to Edge Function', 'FunctionsFetchError', context)
28
+ super('Failed to send a request to the Edge Function', 'FunctionsFetchError', context)
29
29
  }
30
30
  }
31
31
 
32
32
  export class FunctionsRelayError extends FunctionsError {
33
33
  constructor(context: any) {
34
- super('Relay error communicating with deno backend', 'FunctionsRelayError', context)
34
+ super('Relay Error invoking the Edge Function', 'FunctionsRelayError', context)
35
35
  }
36
36
  }
37
37
 
@@ -40,3 +40,21 @@ export class FunctionsHttpError extends FunctionsError {
40
40
  super('Edge Function returned a non-2xx status code', 'FunctionsHttpError', context)
41
41
  }
42
42
  }
43
+
44
+ export type FunctionInvokeOptions = {
45
+ /**
46
+ * object representing the headers to send with the request
47
+ * */
48
+ headers?: { [key: string]: string }
49
+ /**
50
+ * the body of the request
51
+ */
52
+ body?:
53
+ | File
54
+ | Blob
55
+ | ArrayBuffer
56
+ | FormData
57
+ | ReadableStream<Uint8Array>
58
+ | Record<string, any>
59
+ | string
60
+ }
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '1.4.0-next.2'
1
+ export const version = '1.4.0-next.5'