@data-loom/functions-js 0.0.2-alpha.1 → 0.0.2

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.
Files changed (41) hide show
  1. package/dist/main/FunctionsClient.d.ts +24 -0
  2. package/dist/main/FunctionsClient.d.ts.map +1 -0
  3. package/dist/main/FunctionsClient.js +118 -0
  4. package/dist/main/FunctionsClient.js.map +1 -0
  5. package/dist/main/helper.d.ts +3 -0
  6. package/dist/main/helper.d.ts.map +1 -0
  7. package/dist/main/helper.js +41 -0
  8. package/dist/main/helper.js.map +1 -0
  9. package/dist/main/index.d.ts +3 -0
  10. package/dist/main/index.d.ts.map +1 -0
  11. package/dist/main/index.js +12 -0
  12. package/dist/main/index.js.map +1 -0
  13. package/dist/main/types.d.ts +65 -0
  14. package/dist/main/types.d.ts.map +1 -0
  15. package/dist/main/types.js +49 -0
  16. package/dist/main/types.js.map +1 -0
  17. package/dist/main/version.d.ts +2 -0
  18. package/dist/main/version.d.ts.map +1 -0
  19. package/dist/main/version.js +5 -0
  20. package/dist/main/version.js.map +1 -0
  21. package/dist/module/FunctionsClient.d.ts +24 -0
  22. package/dist/module/FunctionsClient.d.ts.map +1 -0
  23. package/dist/module/FunctionsClient.js +114 -0
  24. package/dist/module/FunctionsClient.js.map +1 -0
  25. package/dist/module/helper.d.ts +3 -0
  26. package/dist/module/helper.d.ts.map +1 -0
  27. package/dist/module/helper.js +14 -0
  28. package/dist/module/helper.js.map +1 -0
  29. package/dist/module/index.d.ts +3 -0
  30. package/dist/module/index.d.ts.map +1 -0
  31. package/dist/module/index.js +3 -0
  32. package/dist/module/index.js.map +1 -0
  33. package/dist/module/types.d.ts +65 -0
  34. package/dist/module/types.d.ts.map +1 -0
  35. package/dist/module/types.js +42 -0
  36. package/dist/module/types.js.map +1 -0
  37. package/dist/module/version.d.ts +2 -0
  38. package/dist/module/version.d.ts.map +1 -0
  39. package/dist/module/version.js +2 -0
  40. package/dist/module/version.js.map +1 -0
  41. package/package.json +2 -2
@@ -0,0 +1,24 @@
1
+ import { Fetch, FunctionsResponse, FunctionInvokeOptions, FunctionRegion } from './types';
2
+ export declare class FunctionsClient {
3
+ protected url: string;
4
+ protected headers: Record<string, string>;
5
+ protected region: FunctionRegion;
6
+ protected fetch: Fetch;
7
+ constructor(url: string, { headers, customFetch, region, }?: {
8
+ headers?: Record<string, string>;
9
+ customFetch?: Fetch;
10
+ region?: FunctionRegion;
11
+ });
12
+ /**
13
+ * Updates the authorization header
14
+ * @param token - the new jwt token sent in the authorisation header
15
+ */
16
+ setAuth(token: string): void;
17
+ /**
18
+ * Invokes a function
19
+ * @param functionName - The name of the Function to invoke.
20
+ * @param options - Options for invoking the Function.
21
+ */
22
+ invoke<T = any>(functionName: string, options?: FunctionInvokeOptions): Promise<FunctionsResponse<T>>;
23
+ }
24
+ //# sourceMappingURL=FunctionsClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FunctionsClient.d.ts","sourceRoot":"","sources":["../../src/FunctionsClient.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,EAIL,iBAAiB,EACjB,qBAAqB,EACrB,cAAc,EACf,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,MAAM,EAAE,cAAc,CAAA;IAChC,SAAS,CAAC,KAAK,EAAE,KAAK,CAAA;gBAGpB,GAAG,EAAE,MAAM,EACX,EACE,OAAY,EACZ,WAAW,EACX,MAA2B,GAC5B,GAAE;QACD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QAChC,WAAW,CAAC,EAAE,KAAK,CAAA;QACnB,MAAM,CAAC,EAAE,cAAc,CAAA;KACnB;IAQR;;;OAGG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM;IAIrB;;;;OAIG;IACG,MAAM,CAAC,CAAC,GAAG,GAAG,EAClB,YAAY,EAAE,MAAM,EACpB,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;CAgFjC"}
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.FunctionsClient = void 0;
13
+ const helper_1 = require("./helper");
14
+ const types_1 = require("./types");
15
+ class FunctionsClient {
16
+ constructor(url, { headers = {}, customFetch, region = types_1.FunctionRegion.Any, } = {}) {
17
+ this.url = url;
18
+ this.headers = headers;
19
+ this.region = region;
20
+ this.fetch = (0, helper_1.resolveFetch)(customFetch);
21
+ }
22
+ /**
23
+ * Updates the authorization header
24
+ * @param token - the new jwt token sent in the authorisation header
25
+ */
26
+ setAuth(token) {
27
+ this.headers.Authorization = `Bearer ${token}`;
28
+ }
29
+ /**
30
+ * Invokes a function
31
+ * @param functionName - The name of the Function to invoke.
32
+ * @param options - Options for invoking the Function.
33
+ */
34
+ invoke(functionName, options = {}) {
35
+ var _a;
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ try {
38
+ const { headers, method, body: functionArgs } = options;
39
+ let _headers = {};
40
+ let { region } = options;
41
+ if (!region) {
42
+ region = this.region;
43
+ }
44
+ if (region && region !== 'any') {
45
+ _headers['x-region'] = region;
46
+ }
47
+ let body;
48
+ if (functionArgs &&
49
+ ((headers && !Object.prototype.hasOwnProperty.call(headers, 'Content-Type')) || !headers)) {
50
+ if ((typeof Blob !== 'undefined' && functionArgs instanceof Blob) ||
51
+ functionArgs instanceof ArrayBuffer) {
52
+ // will work for File as File inherits Blob
53
+ // also works for ArrayBuffer as it is the same underlying structure as a Blob
54
+ _headers['Content-Type'] = 'application/octet-stream';
55
+ body = functionArgs;
56
+ }
57
+ else if (typeof functionArgs === 'string') {
58
+ // plain string
59
+ _headers['Content-Type'] = 'text/plain';
60
+ body = functionArgs;
61
+ }
62
+ else if (typeof FormData !== 'undefined' && functionArgs instanceof FormData) {
63
+ // don't set content-type headers
64
+ // Request will automatically add the right boundary value
65
+ body = functionArgs;
66
+ }
67
+ else {
68
+ // default, assume this is JSON
69
+ _headers['Content-Type'] = 'application/json';
70
+ body = JSON.stringify(functionArgs);
71
+ }
72
+ }
73
+ const response = yield this.fetch(`${this.url}/${functionName}`, {
74
+ method: method || 'POST',
75
+ // headers priority is (high to low):
76
+ // 1. invoke-level headers
77
+ // 2. client-level headers
78
+ // 3. default Content-Type header
79
+ headers: Object.assign(Object.assign(Object.assign({}, _headers), this.headers), headers),
80
+ body,
81
+ }).catch((fetchError) => {
82
+ throw new types_1.FunctionsFetchError(fetchError);
83
+ });
84
+ const isRelayError = response.headers.get('x-relay-error');
85
+ if (isRelayError && isRelayError === 'true') {
86
+ throw new types_1.FunctionsRelayError(response);
87
+ }
88
+ if (!response.ok) {
89
+ throw new types_1.FunctionsHttpError(response);
90
+ }
91
+ let responseType = ((_a = response.headers.get('Content-Type')) !== null && _a !== void 0 ? _a : 'text/plain').split(';')[0].trim();
92
+ let data;
93
+ if (responseType === 'application/json') {
94
+ data = yield response.json();
95
+ }
96
+ else if (responseType === 'application/octet-stream') {
97
+ data = yield response.blob();
98
+ }
99
+ else if (responseType === 'text/event-stream') {
100
+ data = response;
101
+ }
102
+ else if (responseType === 'multipart/form-data') {
103
+ data = yield response.formData();
104
+ }
105
+ else {
106
+ // default to text
107
+ data = yield response.text();
108
+ }
109
+ return { data, error: null };
110
+ }
111
+ catch (error) {
112
+ return { data: null, error };
113
+ }
114
+ });
115
+ }
116
+ }
117
+ exports.FunctionsClient = FunctionsClient;
118
+ //# sourceMappingURL=FunctionsClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FunctionsClient.js","sourceRoot":"","sources":["../../src/FunctionsClient.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAAuC;AACvC,mCAQgB;AAEhB,MAAa,eAAe;IAM1B,YACE,GAAW,EACX,EACE,OAAO,GAAG,EAAE,EACZ,WAAW,EACX,MAAM,GAAG,sBAAc,CAAC,GAAG,MAKzB,EAAE;QAEN,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;QACd,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,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;;;;OAIG;IACG,MAAM,CACV,YAAoB,EACpB,UAAiC,EAAE;;;YAEnC,IAAI;gBACF,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,OAAO,CAAA;gBACvD,IAAI,QAAQ,GAA2B,EAAE,CAAA;gBACzC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAA;gBACxB,IAAI,CAAC,MAAM,EAAE;oBACX,MAAM,GAAG,IAAI,CAAC,MAAM,CAAA;iBACrB;gBACD,IAAI,MAAM,IAAI,MAAM,KAAK,KAAK,EAAE;oBAC9B,QAAQ,CAAC,UAAU,CAAC,GAAG,MAAM,CAAA;iBAC9B;gBACD,IAAI,IAAS,CAAA;gBACb,IACE,YAAY;oBACZ,CAAC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fetch;
3
+ //# sourceMappingURL=helper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../../src/helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAE/B,eAAO,MAAM,YAAY,iBAAkB,KAAK,KAAG,KAWlD,CAAA"}
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.resolveFetch = void 0;
27
+ const resolveFetch = (customFetch) => {
28
+ let _fetch;
29
+ if (customFetch) {
30
+ _fetch = customFetch;
31
+ }
32
+ else if (typeof fetch === 'undefined') {
33
+ _fetch = (...args) => { var _a; return (_a = '@data-loom/node-fetch', Promise.resolve().then(() => __importStar(require(_a)))).then(({ default: fetch }) => fetch(...args)); };
34
+ }
35
+ else {
36
+ _fetch = fetch;
37
+ }
38
+ return (...args) => _fetch(...args);
39
+ };
40
+ exports.resolveFetch = resolveFetch;
41
+ //# sourceMappingURL=helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helper.js","sourceRoot":"","sources":["../../src/helper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAEO,MAAM,YAAY,GAAG,CAAC,WAAmB,EAAS,EAAE;IACzD,IAAI,MAAa,CAAA;IACjB,IAAI,WAAW,EAAE;QACf,MAAM,GAAG,WAAW,CAAA;KACrB;SAAM,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE;QACvC,MAAM,GAAG,CAAC,GAAG,IAAI,EAAE,EAAE,WACnB,OAAA,MAAO,uBAA8B,2DAAE,IAAI,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC,CAAA,EAAA,CAAA;KACtF;SAAM;QACL,MAAM,GAAG,KAAK,CAAA;KACf;IACD,OAAO,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAA;AACrC,CAAC,CAAA;AAXY,QAAA,YAAY,gBAWxB"}
@@ -0,0 +1,3 @@
1
+ export { FunctionsClient } from './FunctionsClient';
2
+ export { type FunctionInvokeOptions, FunctionsError, FunctionsFetchError, FunctionsHttpError, FunctionsRelayError, FunctionRegion, type FunctionsResponse, } from './types';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EACL,KAAK,qBAAqB,EAC1B,cAAc,EACd,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACnB,cAAc,EACd,KAAK,iBAAiB,GACvB,MAAM,SAAS,CAAA"}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FunctionRegion = exports.FunctionsRelayError = exports.FunctionsHttpError = exports.FunctionsFetchError = exports.FunctionsError = exports.FunctionsClient = void 0;
4
+ var FunctionsClient_1 = require("./FunctionsClient");
5
+ Object.defineProperty(exports, "FunctionsClient", { enumerable: true, get: function () { return FunctionsClient_1.FunctionsClient; } });
6
+ var types_1 = require("./types");
7
+ Object.defineProperty(exports, "FunctionsError", { enumerable: true, get: function () { return types_1.FunctionsError; } });
8
+ Object.defineProperty(exports, "FunctionsFetchError", { enumerable: true, get: function () { return types_1.FunctionsFetchError; } });
9
+ Object.defineProperty(exports, "FunctionsHttpError", { enumerable: true, get: function () { return types_1.FunctionsHttpError; } });
10
+ Object.defineProperty(exports, "FunctionsRelayError", { enumerable: true, get: function () { return types_1.FunctionsRelayError; } });
11
+ Object.defineProperty(exports, "FunctionRegion", { enumerable: true, get: function () { return types_1.FunctionRegion; } });
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,qDAAmD;AAA1C,kHAAA,eAAe,OAAA;AACxB,iCAQgB;AANd,uGAAA,cAAc,OAAA;AACd,4GAAA,mBAAmB,OAAA;AACnB,2GAAA,kBAAkB,OAAA;AAClB,4GAAA,mBAAmB,OAAA;AACnB,uGAAA,cAAc,OAAA"}
@@ -0,0 +1,65 @@
1
+ export type Fetch = typeof fetch;
2
+ /**
3
+ * Response format
4
+ *
5
+ */
6
+ export interface FunctionsResponseSuccess<T> {
7
+ data: T;
8
+ error: null;
9
+ }
10
+ export interface FunctionsResponseFailure {
11
+ data: null;
12
+ error: any;
13
+ }
14
+ export type FunctionsResponse<T> = FunctionsResponseSuccess<T> | FunctionsResponseFailure;
15
+ export declare class FunctionsError extends Error {
16
+ context: any;
17
+ constructor(message: string, name?: string, context?: any);
18
+ }
19
+ export declare class FunctionsFetchError extends FunctionsError {
20
+ constructor(context: any);
21
+ }
22
+ export declare class FunctionsRelayError extends FunctionsError {
23
+ constructor(context: any);
24
+ }
25
+ export declare class FunctionsHttpError extends FunctionsError {
26
+ constructor(context: any);
27
+ }
28
+ export declare enum FunctionRegion {
29
+ Any = "any",
30
+ ApNortheast1 = "ap-northeast-1",
31
+ ApNortheast2 = "ap-northeast-2",
32
+ ApSouth1 = "ap-south-1",
33
+ ApSoutheast1 = "ap-southeast-1",
34
+ ApSoutheast2 = "ap-southeast-2",
35
+ CaCentral1 = "ca-central-1",
36
+ EuCentral1 = "eu-central-1",
37
+ EuWest1 = "eu-west-1",
38
+ EuWest2 = "eu-west-2",
39
+ EuWest3 = "eu-west-3",
40
+ SaEast1 = "sa-east-1",
41
+ UsEast1 = "us-east-1",
42
+ UsWest1 = "us-west-1",
43
+ UsWest2 = "us-west-2"
44
+ }
45
+ export type FunctionInvokeOptions = {
46
+ /**
47
+ * Object representing the headers to send with the request.
48
+ * */
49
+ headers?: {
50
+ [key: string]: string;
51
+ };
52
+ /**
53
+ * The HTTP verb of the request
54
+ */
55
+ method?: 'POST' | 'GET' | 'PUT' | 'PATCH' | 'DELETE';
56
+ /**
57
+ * The Region to invoke the function in.
58
+ */
59
+ region?: FunctionRegion;
60
+ /**
61
+ * The body of the request.
62
+ */
63
+ body?: File | Blob | ArrayBuffer | FormData | ReadableStream<Uint8Array> | Record<string, any> | string;
64
+ };
65
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,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,MAAM,MAAM,iBAAiB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__esModule", { value: true });
3
+ exports.FunctionRegion = exports.FunctionsHttpError = exports.FunctionsRelayError = exports.FunctionsFetchError = exports.FunctionsError = void 0;
4
+ class FunctionsError extends Error {
5
+ constructor(message, name = 'FunctionsError', context) {
6
+ super(message);
7
+ this.name = name;
8
+ this.context = context;
9
+ }
10
+ }
11
+ exports.FunctionsError = FunctionsError;
12
+ class FunctionsFetchError extends FunctionsError {
13
+ constructor(context) {
14
+ super('Failed to send a request to the Edge Function', 'FunctionsFetchError', context);
15
+ }
16
+ }
17
+ exports.FunctionsFetchError = FunctionsFetchError;
18
+ class FunctionsRelayError extends FunctionsError {
19
+ constructor(context) {
20
+ super('Relay Error invoking the Edge Function', 'FunctionsRelayError', context);
21
+ }
22
+ }
23
+ exports.FunctionsRelayError = FunctionsRelayError;
24
+ class FunctionsHttpError extends FunctionsError {
25
+ constructor(context) {
26
+ super('Edge Function returned a non-2xx status code', 'FunctionsHttpError', context);
27
+ }
28
+ }
29
+ exports.FunctionsHttpError = FunctionsHttpError;
30
+ // Define the enum for the 'region' property
31
+ var FunctionRegion;
32
+ (function (FunctionRegion) {
33
+ FunctionRegion["Any"] = "any";
34
+ FunctionRegion["ApNortheast1"] = "ap-northeast-1";
35
+ FunctionRegion["ApNortheast2"] = "ap-northeast-2";
36
+ FunctionRegion["ApSouth1"] = "ap-south-1";
37
+ FunctionRegion["ApSoutheast1"] = "ap-southeast-1";
38
+ FunctionRegion["ApSoutheast2"] = "ap-southeast-2";
39
+ FunctionRegion["CaCentral1"] = "ca-central-1";
40
+ FunctionRegion["EuCentral1"] = "eu-central-1";
41
+ FunctionRegion["EuWest1"] = "eu-west-1";
42
+ FunctionRegion["EuWest2"] = "eu-west-2";
43
+ FunctionRegion["EuWest3"] = "eu-west-3";
44
+ FunctionRegion["SaEast1"] = "sa-east-1";
45
+ FunctionRegion["UsEast1"] = "us-east-1";
46
+ FunctionRegion["UsWest1"] = "us-west-1";
47
+ FunctionRegion["UsWest2"] = "us-west-2";
48
+ })(FunctionRegion = exports.FunctionRegion || (exports.FunctionRegion = {}));
49
+ //# sourceMappingURL=types.js.map
@@ -0,0 +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,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,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;AACD,4CAA4C;AAC5C,IAAY,cAgBX;AAhBD,WAAY,cAAc;IACxB,6BAAW,CAAA;IACX,iDAA+B,CAAA;IAC/B,iDAA+B,CAAA;IAC/B,yCAAuB,CAAA;IACvB,iDAA+B,CAAA;IAC/B,iDAA+B,CAAA;IAC/B,6CAA2B,CAAA;IAC3B,6CAA2B,CAAA;IAC3B,uCAAqB,CAAA;IACrB,uCAAqB,CAAA;IACrB,uCAAqB,CAAA;IACrB,uCAAqB,CAAA;IACrB,uCAAqB,CAAA;IACrB,uCAAqB,CAAA;IACrB,uCAAqB,CAAA;AACvB,CAAC,EAhBW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAgBzB"}
@@ -0,0 +1,2 @@
1
+ export declare const version = "0.0.0-automated";
2
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,oBAAoB,CAAA"}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.version = void 0;
4
+ exports.version = '0.0.0-automated';
5
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AAAa,QAAA,OAAO,GAAG,iBAAiB,CAAA"}
@@ -0,0 +1,24 @@
1
+ import { Fetch, FunctionsResponse, FunctionInvokeOptions, FunctionRegion } from './types';
2
+ export declare class FunctionsClient {
3
+ protected url: string;
4
+ protected headers: Record<string, string>;
5
+ protected region: FunctionRegion;
6
+ protected fetch: Fetch;
7
+ constructor(url: string, { headers, customFetch, region, }?: {
8
+ headers?: Record<string, string>;
9
+ customFetch?: Fetch;
10
+ region?: FunctionRegion;
11
+ });
12
+ /**
13
+ * Updates the authorization header
14
+ * @param token - the new jwt token sent in the authorisation header
15
+ */
16
+ setAuth(token: string): void;
17
+ /**
18
+ * Invokes a function
19
+ * @param functionName - The name of the Function to invoke.
20
+ * @param options - Options for invoking the Function.
21
+ */
22
+ invoke<T = any>(functionName: string, options?: FunctionInvokeOptions): Promise<FunctionsResponse<T>>;
23
+ }
24
+ //# sourceMappingURL=FunctionsClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FunctionsClient.d.ts","sourceRoot":"","sources":["../../src/FunctionsClient.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,EAIL,iBAAiB,EACjB,qBAAqB,EACrB,cAAc,EACf,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,MAAM,EAAE,cAAc,CAAA;IAChC,SAAS,CAAC,KAAK,EAAE,KAAK,CAAA;gBAGpB,GAAG,EAAE,MAAM,EACX,EACE,OAAY,EACZ,WAAW,EACX,MAA2B,GAC5B,GAAE;QACD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QAChC,WAAW,CAAC,EAAE,KAAK,CAAA;QACnB,MAAM,CAAC,EAAE,cAAc,CAAA;KACnB;IAQR;;;OAGG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM;IAIrB;;;;OAIG;IACG,MAAM,CAAC,CAAC,GAAG,GAAG,EAClB,YAAY,EAAE,MAAM,EACpB,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;CAgFjC"}
@@ -0,0 +1,114 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { resolveFetch } from './helper';
11
+ import { FunctionsFetchError, FunctionsHttpError, FunctionsRelayError, FunctionRegion, } from './types';
12
+ export class FunctionsClient {
13
+ constructor(url, { headers = {}, customFetch, region = FunctionRegion.Any, } = {}) {
14
+ this.url = url;
15
+ this.headers = headers;
16
+ this.region = region;
17
+ this.fetch = resolveFetch(customFetch);
18
+ }
19
+ /**
20
+ * Updates the authorization header
21
+ * @param token - the new jwt token sent in the authorisation header
22
+ */
23
+ setAuth(token) {
24
+ this.headers.Authorization = `Bearer ${token}`;
25
+ }
26
+ /**
27
+ * Invokes a function
28
+ * @param functionName - The name of the Function to invoke.
29
+ * @param options - Options for invoking the Function.
30
+ */
31
+ invoke(functionName, options = {}) {
32
+ var _a;
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ try {
35
+ const { headers, method, body: functionArgs } = options;
36
+ let _headers = {};
37
+ let { region } = options;
38
+ if (!region) {
39
+ region = this.region;
40
+ }
41
+ if (region && region !== 'any') {
42
+ _headers['x-region'] = region;
43
+ }
44
+ let body;
45
+ if (functionArgs &&
46
+ ((headers && !Object.prototype.hasOwnProperty.call(headers, 'Content-Type')) || !headers)) {
47
+ if ((typeof Blob !== 'undefined' && functionArgs instanceof Blob) ||
48
+ functionArgs instanceof ArrayBuffer) {
49
+ // will work for File as File inherits Blob
50
+ // also works for ArrayBuffer as it is the same underlying structure as a Blob
51
+ _headers['Content-Type'] = 'application/octet-stream';
52
+ body = functionArgs;
53
+ }
54
+ else if (typeof functionArgs === 'string') {
55
+ // plain string
56
+ _headers['Content-Type'] = 'text/plain';
57
+ body = functionArgs;
58
+ }
59
+ else if (typeof FormData !== 'undefined' && functionArgs instanceof FormData) {
60
+ // don't set content-type headers
61
+ // Request will automatically add the right boundary value
62
+ body = functionArgs;
63
+ }
64
+ else {
65
+ // default, assume this is JSON
66
+ _headers['Content-Type'] = 'application/json';
67
+ body = JSON.stringify(functionArgs);
68
+ }
69
+ }
70
+ const response = yield this.fetch(`${this.url}/${functionName}`, {
71
+ method: method || 'POST',
72
+ // headers priority is (high to low):
73
+ // 1. invoke-level headers
74
+ // 2. client-level headers
75
+ // 3. default Content-Type header
76
+ headers: Object.assign(Object.assign(Object.assign({}, _headers), this.headers), headers),
77
+ body,
78
+ }).catch((fetchError) => {
79
+ throw new FunctionsFetchError(fetchError);
80
+ });
81
+ const isRelayError = response.headers.get('x-relay-error');
82
+ if (isRelayError && isRelayError === 'true') {
83
+ throw new FunctionsRelayError(response);
84
+ }
85
+ if (!response.ok) {
86
+ throw new FunctionsHttpError(response);
87
+ }
88
+ let responseType = ((_a = response.headers.get('Content-Type')) !== null && _a !== void 0 ? _a : 'text/plain').split(';')[0].trim();
89
+ let data;
90
+ if (responseType === 'application/json') {
91
+ data = yield response.json();
92
+ }
93
+ else if (responseType === 'application/octet-stream') {
94
+ data = yield response.blob();
95
+ }
96
+ else if (responseType === 'text/event-stream') {
97
+ data = response;
98
+ }
99
+ else if (responseType === 'multipart/form-data') {
100
+ data = yield response.formData();
101
+ }
102
+ else {
103
+ // default to text
104
+ data = yield response.text();
105
+ }
106
+ return { data, error: null };
107
+ }
108
+ catch (error) {
109
+ return { data: null, error };
110
+ }
111
+ });
112
+ }
113
+ }
114
+ //# sourceMappingURL=FunctionsClient.js.map
@@ -0,0 +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,EAGnB,cAAc,GACf,MAAM,SAAS,CAAA;AAEhB,MAAM,OAAO,eAAe;IAM1B,YACE,GAAW,EACX,EACE,OAAO,GAAG,EAAE,EACZ,WAAW,EACX,MAAM,GAAG,cAAc,CAAC,GAAG,MAKzB,EAAE;QAEN,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;QACd,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,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;;;;OAIG;IAC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AQ,CAAA;iBAChB;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"}
@@ -0,0 +1,3 @@
1
+ import { Fetch } from './types';
2
+ export declare const resolveFetch: (customFetch?: Fetch) => Fetch;
3
+ //# sourceMappingURL=helper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../../src/helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAE/B,eAAO,MAAM,YAAY,iBAAkB,KAAK,KAAG,KAWlD,CAAA"}
@@ -0,0 +1,14 @@
1
+ export const resolveFetch = (customFetch) => {
2
+ let _fetch;
3
+ if (customFetch) {
4
+ _fetch = customFetch;
5
+ }
6
+ else if (typeof fetch === 'undefined') {
7
+ _fetch = (...args) => import('@data-loom/node-fetch').then(({ default: fetch }) => fetch(...args));
8
+ }
9
+ else {
10
+ _fetch = fetch;
11
+ }
12
+ return (...args) => _fetch(...args);
13
+ };
14
+ //# sourceMappingURL=helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helper.js","sourceRoot":"","sources":["../../src/helper.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,WAAmB,EAAS,EAAE;IACzD,IAAI,MAAa,CAAA;IACjB,IAAI,WAAW,EAAE;QACf,MAAM,GAAG,WAAW,CAAA;KACrB;SAAM,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE;QACvC,MAAM,GAAG,CAAC,GAAG,IAAI,EAAE,EAAE,CACnB,MAAM,CAAC,uBAA8B,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC,CAAA;KACtF;SAAM;QACL,MAAM,GAAG,KAAK,CAAA;KACf;IACD,OAAO,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAA;AACrC,CAAC,CAAA"}
@@ -0,0 +1,3 @@
1
+ export { FunctionsClient } from './FunctionsClient';
2
+ export { type FunctionInvokeOptions, FunctionsError, FunctionsFetchError, FunctionsHttpError, FunctionsRelayError, FunctionRegion, type FunctionsResponse, } from './types';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EACL,KAAK,qBAAqB,EAC1B,cAAc,EACd,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACnB,cAAc,EACd,KAAK,iBAAiB,GACvB,MAAM,SAAS,CAAA"}
@@ -0,0 +1,3 @@
1
+ export { FunctionsClient } from './FunctionsClient';
2
+ export { FunctionsError, FunctionsFetchError, FunctionsHttpError, FunctionsRelayError, FunctionRegion, } from './types';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAEL,cAAc,EACd,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACnB,cAAc,GAEf,MAAM,SAAS,CAAA"}
@@ -0,0 +1,65 @@
1
+ export type Fetch = typeof fetch;
2
+ /**
3
+ * Response format
4
+ *
5
+ */
6
+ export interface FunctionsResponseSuccess<T> {
7
+ data: T;
8
+ error: null;
9
+ }
10
+ export interface FunctionsResponseFailure {
11
+ data: null;
12
+ error: any;
13
+ }
14
+ export type FunctionsResponse<T> = FunctionsResponseSuccess<T> | FunctionsResponseFailure;
15
+ export declare class FunctionsError extends Error {
16
+ context: any;
17
+ constructor(message: string, name?: string, context?: any);
18
+ }
19
+ export declare class FunctionsFetchError extends FunctionsError {
20
+ constructor(context: any);
21
+ }
22
+ export declare class FunctionsRelayError extends FunctionsError {
23
+ constructor(context: any);
24
+ }
25
+ export declare class FunctionsHttpError extends FunctionsError {
26
+ constructor(context: any);
27
+ }
28
+ export declare enum FunctionRegion {
29
+ Any = "any",
30
+ ApNortheast1 = "ap-northeast-1",
31
+ ApNortheast2 = "ap-northeast-2",
32
+ ApSouth1 = "ap-south-1",
33
+ ApSoutheast1 = "ap-southeast-1",
34
+ ApSoutheast2 = "ap-southeast-2",
35
+ CaCentral1 = "ca-central-1",
36
+ EuCentral1 = "eu-central-1",
37
+ EuWest1 = "eu-west-1",
38
+ EuWest2 = "eu-west-2",
39
+ EuWest3 = "eu-west-3",
40
+ SaEast1 = "sa-east-1",
41
+ UsEast1 = "us-east-1",
42
+ UsWest1 = "us-west-1",
43
+ UsWest2 = "us-west-2"
44
+ }
45
+ export type FunctionInvokeOptions = {
46
+ /**
47
+ * Object representing the headers to send with the request.
48
+ * */
49
+ headers?: {
50
+ [key: string]: string;
51
+ };
52
+ /**
53
+ * The HTTP verb of the request
54
+ */
55
+ method?: 'POST' | 'GET' | 'PUT' | 'PATCH' | 'DELETE';
56
+ /**
57
+ * The Region to invoke the function in.
58
+ */
59
+ region?: FunctionRegion;
60
+ /**
61
+ * The body of the request.
62
+ */
63
+ body?: File | Blob | ArrayBuffer | FormData | ReadableStream<Uint8Array> | Record<string, any> | string;
64
+ };
65
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.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AAG,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAA;IACpD;;OAEG;IACH,MAAM,CAAC,EAAE,cAAc,CAAA;IACvB;;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"}
@@ -0,0 +1,42 @@
1
+ export class FunctionsError extends Error {
2
+ constructor(message, name = 'FunctionsError', context) {
3
+ super(message);
4
+ this.name = name;
5
+ this.context = context;
6
+ }
7
+ }
8
+ export class FunctionsFetchError extends FunctionsError {
9
+ constructor(context) {
10
+ super('Failed to send a request to the Edge Function', 'FunctionsFetchError', context);
11
+ }
12
+ }
13
+ export class FunctionsRelayError extends FunctionsError {
14
+ constructor(context) {
15
+ super('Relay Error invoking the Edge Function', 'FunctionsRelayError', context);
16
+ }
17
+ }
18
+ export class FunctionsHttpError extends FunctionsError {
19
+ constructor(context) {
20
+ super('Edge Function returned a non-2xx status code', 'FunctionsHttpError', context);
21
+ }
22
+ }
23
+ // Define the enum for the 'region' property
24
+ export var FunctionRegion;
25
+ (function (FunctionRegion) {
26
+ FunctionRegion["Any"] = "any";
27
+ FunctionRegion["ApNortheast1"] = "ap-northeast-1";
28
+ FunctionRegion["ApNortheast2"] = "ap-northeast-2";
29
+ FunctionRegion["ApSouth1"] = "ap-south-1";
30
+ FunctionRegion["ApSoutheast1"] = "ap-southeast-1";
31
+ FunctionRegion["ApSoutheast2"] = "ap-southeast-2";
32
+ FunctionRegion["CaCentral1"] = "ca-central-1";
33
+ FunctionRegion["EuCentral1"] = "eu-central-1";
34
+ FunctionRegion["EuWest1"] = "eu-west-1";
35
+ FunctionRegion["EuWest2"] = "eu-west-2";
36
+ FunctionRegion["EuWest3"] = "eu-west-3";
37
+ FunctionRegion["SaEast1"] = "sa-east-1";
38
+ FunctionRegion["UsEast1"] = "us-east-1";
39
+ FunctionRegion["UsWest1"] = "us-west-1";
40
+ FunctionRegion["UsWest2"] = "us-west-2";
41
+ })(FunctionRegion || (FunctionRegion = {}));
42
+ //# sourceMappingURL=types.js.map
@@ -0,0 +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,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,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;AACD,4CAA4C;AAC5C,MAAM,CAAN,IAAY,cAgBX;AAhBD,WAAY,cAAc;IACxB,6BAAW,CAAA;IACX,iDAA+B,CAAA;IAC/B,iDAA+B,CAAA;IAC/B,yCAAuB,CAAA;IACvB,iDAA+B,CAAA;IAC/B,iDAA+B,CAAA;IAC/B,6CAA2B,CAAA;IAC3B,6CAA2B,CAAA;IAC3B,uCAAqB,CAAA;IACrB,uCAAqB,CAAA;IACrB,uCAAqB,CAAA;IACrB,uCAAqB,CAAA;IACrB,uCAAqB,CAAA;IACrB,uCAAqB,CAAA;IACrB,uCAAqB,CAAA;AACvB,CAAC,EAhBW,cAAc,KAAd,cAAc,QAgBzB"}
@@ -0,0 +1,2 @@
1
+ export declare const version = "0.0.0-automated";
2
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,oBAAoB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export const version = '0.0.0-automated';
2
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,iBAAiB,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@data-loom/functions-js",
3
- "version": "0.0.2-alpha.1",
3
+ "version": "0.0.2",
4
4
  "description": "JS Client library to interact with Dataloom Functions.",
5
5
  "main": "dist/main/index.js",
6
6
  "module": "dist/module/index.js",
@@ -28,7 +28,7 @@
28
28
  ],
29
29
  "license": "MIT",
30
30
  "dependencies": {
31
- "@data-loom/node-fetch": "0.0.2-alpha.1"
31
+ "@data-loom/node-fetch": "0.0.2"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@sebbo2002/semantic-release-jsr": "^1.0.0",