@supabase/functions-js 1.4.0-next.1 → 1.4.0-next.4

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>;
@@ -15,12 +15,9 @@ export declare class FunctionsClient {
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
18
+ * @param invokeOption.headers - object representing the headers to send with the request
19
+ * @param invokeOptions.body - the body of the request
21
20
  */
22
- invoke(functionName: string, functionArgs: any, { headers, }?: {
23
- headers?: Record<string, string>;
24
- }): Promise<FunctionsResponse>;
21
+ invoke<T = any>(functionName: string, invokeOptions?: FunctionInvokeOptions): Promise<FunctionsResponse<T>>;
25
22
  }
26
23
  //# 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;CA8D9B"}
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;;;;;OAKG;IACG,MAAM,CAAC,CAAC,GAAG,GAAG,EAClB,YAAY,EAAE,MAAM,EACpB,aAAa,GAAE,qBAA0B,GACxC,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;CAwEjC"}
@@ -28,36 +28,40 @@ 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
31
+ * @param invokeOption.headers - object representing the headers to send with the request
32
+ * @param invokeOptions.body - the body of the request
34
33
  */
35
- invoke(functionName, functionArgs, { headers = {}, } = {}) {
34
+ invoke(functionName, invokeOptions = {}) {
36
35
  var _a;
37
36
  return __awaiter(this, void 0, void 0, function* () {
38
37
  try {
38
+ const { headers, body: functionArgs } = invokeOptions;
39
39
  let _headers = {};
40
40
  let body;
41
- if (functionArgs instanceof Blob || functionArgs instanceof ArrayBuffer) {
42
- // will work for File as File inherits Blob
43
- // also works for ArrayBuffer as it is the same underlying structure as a Blob
44
- _headers['Content-Type'] = 'application/octet-stream';
45
- body = functionArgs;
46
- }
47
- else if (typeof functionArgs === 'string') {
48
- // plain string
49
- _headers['Content-Type'] = 'text/plain';
50
- body = functionArgs;
51
- }
52
- else if (functionArgs instanceof FormData) {
53
- // don't set content-type headers
54
- // Request will automatically add the right boundary value
55
- body = functionArgs;
56
- }
57
- else {
58
- // default, assume this is JSON
59
- _headers['Content-Type'] = 'application/json';
60
- body = JSON.stringify(functionArgs);
41
+ if (functionArgs &&
42
+ ((headers && !Object.prototype.hasOwnProperty.call(headers, 'Content-Type')) || !headers)) {
43
+ if ((typeof Blob !== 'undefined' && functionArgs instanceof Blob) ||
44
+ functionArgs instanceof ArrayBuffer) {
45
+ // will work for File as File inherits Blob
46
+ // also works for ArrayBuffer as it is the same underlying structure as a Blob
47
+ _headers['Content-Type'] = 'application/octet-stream';
48
+ body = functionArgs;
49
+ }
50
+ else if (typeof functionArgs === 'string') {
51
+ // plain string
52
+ _headers['Content-Type'] = 'text/plain';
53
+ body = functionArgs;
54
+ }
55
+ else if (typeof FormData !== 'undefined' && functionArgs instanceof FormData) {
56
+ // don't set content-type headers
57
+ // Request will automatically add the right boundary value
58
+ body = functionArgs;
59
+ }
60
+ else {
61
+ // default, assume this is JSON
62
+ _headers['Content-Type'] = 'application/json';
63
+ body = JSON.stringify(functionArgs);
64
+ }
61
65
  }
62
66
  const response = yield this.fetch(`${this.url}/${functionName}`, {
63
67
  method: 'POST',
@@ -1 +1 @@
1
- {"version":3,"file":"FunctionsClient.js","sourceRoot":"","sources":["../../src/FunctionsClient.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAAuC;A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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;AA7GD,0CA6GC"}
@@ -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
+ interface FunctionsResponseSuccess<T> {
7
+ data: T;
8
8
  error: null;
9
9
  }
10
10
  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,11 @@ export declare class FunctionsRelayError extends FunctionsError {
25
25
  export declare class FunctionsHttpError extends FunctionsError {
26
26
  constructor(context: any);
27
27
  }
28
+ export declare type FunctionInvokeOptions = {
29
+ headers?: {
30
+ [key: string]: string;
31
+ };
32
+ body?: File | Blob | ArrayBuffer | FormData | ReadableStream<Uint8Array> | Record<string, any> | string;
33
+ };
28
34
  export {};
29
35
  //# 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,UAAU,wBAAwB,CAAC,CAAC;IAClC,IAAI,EAAE,CAAC,CAAA;IACP,KAAK,EAAE,IAAI,CAAA;CACZ;AACD,UAAU,wBAAwB;IAChC,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,OAAO,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAA;IACnC,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,gBAAg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ACpD,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.1";
1
+ export declare const version = "1.4.0-next.4";
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.1';
4
+ exports.version = '1.4.0-next.4';
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>;
@@ -15,12 +15,9 @@ export declare class FunctionsClient {
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
18
+ * @param invokeOption.headers - object representing the headers to send with the request
19
+ * @param invokeOptions.body - the body of the request
21
20
  */
22
- invoke(functionName: string, functionArgs: any, { headers, }?: {
23
- headers?: Record<string, string>;
24
- }): Promise<FunctionsResponse>;
21
+ invoke<T = any>(functionName: string, invokeOptions?: FunctionInvokeOptions): Promise<FunctionsResponse<T>>;
25
22
  }
26
23
  //# 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;CA8D9B"}
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;;;;;OAKG;IACG,MAAM,CAAC,CAAC,GAAG,GAAG,EAClB,YAAY,EAAE,MAAM,EACpB,aAAa,GAAE,qBAA0B,GACxC,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;CAwEjC"}
@@ -25,36 +25,40 @@ 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
28
+ * @param invokeOption.headers - object representing the headers to send with the request
29
+ * @param invokeOptions.body - the body of the request
31
30
  */
32
- invoke(functionName, functionArgs, { headers = {}, } = {}) {
31
+ invoke(functionName, invokeOptions = {}) {
33
32
  var _a;
34
33
  return __awaiter(this, void 0, void 0, function* () {
35
34
  try {
35
+ const { headers, body: functionArgs } = invokeOptions;
36
36
  let _headers = {};
37
37
  let body;
38
- if (functionArgs instanceof Blob || functionArgs instanceof ArrayBuffer) {
39
- // will work for File as File inherits Blob
40
- // also works for ArrayBuffer as it is the same underlying structure as a Blob
41
- _headers['Content-Type'] = 'application/octet-stream';
42
- body = functionArgs;
43
- }
44
- else if (typeof functionArgs === 'string') {
45
- // plain string
46
- _headers['Content-Type'] = 'text/plain';
47
- body = functionArgs;
48
- }
49
- else if (functionArgs instanceof FormData) {
50
- // don't set content-type headers
51
- // Request will automatically add the right boundary value
52
- body = functionArgs;
53
- }
54
- else {
55
- // default, assume this is JSON
56
- _headers['Content-Type'] = 'application/json';
57
- body = JSON.stringify(functionArgs);
38
+ if (functionArgs &&
39
+ ((headers && !Object.prototype.hasOwnProperty.call(headers, 'Content-Type')) || !headers)) {
40
+ if ((typeof Blob !== 'undefined' && functionArgs instanceof Blob) ||
41
+ functionArgs instanceof ArrayBuffer) {
42
+ // will work for File as File inherits Blob
43
+ // also works for ArrayBuffer as it is the same underlying structure as a Blob
44
+ _headers['Content-Type'] = 'application/octet-stream';
45
+ body = functionArgs;
46
+ }
47
+ else if (typeof functionArgs === 'string') {
48
+ // plain string
49
+ _headers['Content-Type'] = 'text/plain';
50
+ body = functionArgs;
51
+ }
52
+ else if (typeof FormData !== 'undefined' && functionArgs instanceof FormData) {
53
+ // don't set content-type headers
54
+ // Request will automatically add the right boundary value
55
+ body = functionArgs;
56
+ }
57
+ else {
58
+ // default, assume this is JSON
59
+ _headers['Content-Type'] = 'application/json';
60
+ body = JSON.stringify(functionArgs);
61
+ }
58
62
  }
59
63
  const response = yield this.fetch(`${this.url}/${functionName}`, {
60
64
  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,YAAY,CAAC,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,IAAI,YAAY,YAAY,IAAI,IAAI,YAAY,YAAY,WAAW,EAAE;oBACvE,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;iBACp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ess {
7
- data: any;
6
+ interface FunctionsResponseSuccess<T> {
7
+ data: T;
8
8
  error: null;
9
9
  }
10
10
  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,11 @@ export declare class FunctionsRelayError extends FunctionsError {
25
25
  export declare class FunctionsHttpError extends FunctionsError {
26
26
  constructor(context: any);
27
27
  }
28
+ export declare type FunctionInvokeOptions = {
29
+ headers?: {
30
+ [key: string]: string;
31
+ };
32
+ body?: File | Blob | ArrayBuffer | FormData | ReadableStream<Uint8Array> | Record<string, any> | string;
33
+ };
28
34
  export {};
29
35
  //# 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,UAAU,wBAAwB,CAAC,CAAC;IAClC,IAAI,EAAE,CAAC,CAAA;IACP,KAAK,EAAE,IAAI,CAAA;CACZ;AACD,UAAU,wBAAwB;IAChC,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,OAAO,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAA;IACnC,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,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,KAAK,CAAC,IAAI,GAAG,IAAI,CAAA;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;CACF;AAED,MAAM,OAAO,mBAAoB,SAAQ,cAAc;IACrD,YAAY,OAAY;QACtB,KAAK,CAAC,4CAA4C,EAAE,qBAAqB,EAAE,OAAO,CAAC,CAAA;IACrF,CAAC;CACF;AAED,MAAM,OAAO,mBAAoB,SAAQ,cAAc;IACrD,YAAY,OAAY;QACtB,KAAK,CAAC,6CAA6C,EAAE,qBAAqB,EAAE,OAAO,CAAC,CAAA;IACtF,CAAC;CACF;AAED,MAAM,OAAO,kBAAmB,SAAQ,cAAc;IACpD,YAAY,OAAY;QACtB,KAAK,CAAC,8CAA8C,EAAE,oBAAoB,EAAE,OAAO,CAAC,CAAA;IACtF,CAAC;CACF"}
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,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,KAAK,CAAC,IAAI,GAAG,IAAI,CAAA;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;CACF;AAED,MAAM,OAAO,mBAAoB,SAAQ,cAAc;IACrD,YAAY,OAAY;QACtB,KAAK,CAAC,+CAA+C,EAAE,qBAAqB,EAAE,OAAO,CAAC,CAAA;IACxF,CAAC;CACF;AAED,MAAM,OAAO,mBAAoB,SAAQ,cAAc;IACrD,YAAY,OAAY;QACtB,KAAK,CAAC,wCAAwC,EAAE,qBAAqB,EAAE,OAAO,CAAC,CAAA;IACjF,CAAC;CACF;AAED,MAAM,OAAO,kBAAmB,SAAQ,cAAc;IACpD,YAAY,OAAY;QACtB,KAAK,CAAC,8CAA8C,EAAE,oBAAoB,EAAE,OAAO,CAAC,CAAA;IACtF,CAAC;CACF"}
@@ -1,2 +1,2 @@
1
- export declare const version = "1.4.0-next.1";
1
+ export declare const version = "1.4.0-next.4";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -1,2 +1,2 @@
1
- export const version = '1.4.0-next.1';
1
+ export const version = '1.4.0-next.4';
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.1",
3
+ "version": "1.4.0-next.4",
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",
@@ -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 {
@@ -38,39 +39,43 @@ 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
42
+ * @param invokeOption.headers - object representing the headers to send with the request
43
+ * @param invokeOptions.body - the body of the request
44
44
  */
45
- async invoke(
45
+ async invoke<T = any>(
46
46
  functionName: string,
47
- functionArgs: any,
48
- {
49
- headers = {},
50
- }: {
51
- headers?: Record<string, string>
52
- } = {}
53
- ): Promise<FunctionsResponse> {
47
+ invokeOptions: FunctionInvokeOptions = {}
48
+ ): Promise<FunctionsResponse<T>> {
54
49
  try {
50
+ const { headers, body: functionArgs } = invokeOptions
51
+
55
52
  let _headers: Record<string, string> = {}
56
53
  let body: any
57
- if (functionArgs instanceof Blob || functionArgs instanceof ArrayBuffer) {
58
- // will work for File as File inherits Blob
59
- // also works for ArrayBuffer as it is the same underlying structure as a Blob
60
- _headers['Content-Type'] = 'application/octet-stream'
61
- body = functionArgs
62
- } else if (typeof functionArgs === 'string') {
63
- // plain string
64
- _headers['Content-Type'] = 'text/plain'
65
- body = functionArgs
66
- } else if (functionArgs instanceof FormData) {
67
- // don't set content-type headers
68
- // Request will automatically add the right boundary value
69
- body = functionArgs
70
- } else {
71
- // default, assume this is JSON
72
- _headers['Content-Type'] = 'application/json'
73
- body = JSON.stringify(functionArgs)
54
+ if (
55
+ functionArgs &&
56
+ ((headers && !Object.prototype.hasOwnProperty.call(headers, 'Content-Type')) || !headers)
57
+ ) {
58
+ if (
59
+ (typeof Blob !== 'undefined' && functionArgs instanceof Blob) ||
60
+ functionArgs instanceof ArrayBuffer
61
+ ) {
62
+ // will work for File as File inherits Blob
63
+ // also works for ArrayBuffer as it is the same underlying structure as a Blob
64
+ _headers['Content-Type'] = 'application/octet-stream'
65
+ body = functionArgs
66
+ } else if (typeof functionArgs === 'string') {
67
+ // plain string
68
+ _headers['Content-Type'] = 'text/plain'
69
+ body = functionArgs
70
+ } else if (typeof FormData !== 'undefined' && functionArgs instanceof FormData) {
71
+ // don't set content-type headers
72
+ // Request will automatically add the right boundary value
73
+ body = functionArgs
74
+ } else {
75
+ // default, assume this is JSON
76
+ _headers['Content-Type'] = 'application/json'
77
+ body = JSON.stringify(functionArgs)
78
+ }
74
79
  }
75
80
 
76
81
  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
+ interface FunctionsResponseSuccess<T> {
8
+ data: T
9
9
  error: null
10
10
  }
11
11
  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,15 @@ 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
+ headers?: { [key: string]: string }
46
+ body?:
47
+ | File
48
+ | Blob
49
+ | ArrayBuffer
50
+ | FormData
51
+ | ReadableStream<Uint8Array>
52
+ | Record<string, any>
53
+ | string
54
+ }
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '1.4.0-next.1'
1
+ export const version = '1.4.0-next.4'