chainflow 0.1.7 → 0.1.9
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.
- package/README.md +113 -56
- package/dist/core/chainflow.d.ts +13 -12
- package/dist/core/chainflow.js +15 -15
- package/dist/core/chainflow.js.map +1 -1
- package/dist/core/store.d.ts +1 -2
- package/dist/core/store.js +1 -1
- package/dist/core/store.js.map +1 -1
- package/dist/core/utils/link.d.ts +1 -1
- package/dist/http/endpoint.d.ts +9 -20
- package/dist/http/endpoint.js +31 -56
- package/dist/http/endpoint.js.map +1 -1
- package/dist/http/errors.d.ts +9 -4
- package/dist/http/errors.js +18 -9
- package/dist/http/errors.js.map +1 -1
- package/dist/http/logger.js.map +1 -1
- package/dist/http/{originServer.d.ts → origin.d.ts} +7 -6
- package/dist/http/{originServer.js → origin.js} +14 -12
- package/dist/http/origin.js.map +1 -0
- package/dist/http/utils/client.d.ts +26 -16
- package/dist/http/utils/client.js +68 -20
- package/dist/http/utils/client.js.map +1 -1
- package/dist/http/utils/id.d.ts +2 -2
- package/dist/http/utils/id.js +2 -2
- package/dist/http/utils/id.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/http/originServer.js.map +0 -1
package/dist/http/endpoint.js
CHANGED
|
@@ -22,13 +22,13 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
22
22
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
23
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
24
|
};
|
|
25
|
-
var _Endpoint_instances,
|
|
25
|
+
var _Endpoint_instances, _Endpoint_req, _Endpoint_resp, _Endpoint_config, _Endpoint_store, _Endpoint_extractPathParams, _Endpoint_insertPathParams, _Endpoint_insertQueryParams, _Endpoint_validateResp, _Endpoint_findMissingValues;
|
|
26
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
exports.Endpoint =
|
|
27
|
+
exports.Endpoint = void 0;
|
|
28
28
|
const id_1 = require("./utils/id");
|
|
29
29
|
const inputNode_1 = require("../core/inputNode");
|
|
30
30
|
const reqBuilder_1 = require("./reqBuilder");
|
|
31
|
-
const client_1 =
|
|
31
|
+
const client_1 = require("./utils/client");
|
|
32
32
|
const errors_1 = require("./errors");
|
|
33
33
|
const deepmerge_1 = __importDefault(require("@fastify/deepmerge"));
|
|
34
34
|
const sourceNode_1 = require("../core/sourceNode");
|
|
@@ -36,46 +36,28 @@ const symbols_1 = require("../core/utils/symbols");
|
|
|
36
36
|
const initializers_1 = require("../core/utils/initializers");
|
|
37
37
|
const store_1 = require("../core/store");
|
|
38
38
|
const logger_1 = require("./logger");
|
|
39
|
-
const constants_1 = require("./utils/constants");
|
|
40
39
|
const deepmerge = (0, deepmerge_1.default)();
|
|
41
40
|
const PATH_PARAM_REGEX = /\/(\{[^{}]+\})/g;
|
|
42
|
-
/** Formats to parse the response body. */
|
|
43
|
-
var RESP_PARSER;
|
|
44
|
-
(function (RESP_PARSER) {
|
|
45
|
-
RESP_PARSER["ARRAY_BUFFER"] = "arrayBuffer";
|
|
46
|
-
RESP_PARSER["BLOB"] = "blob";
|
|
47
|
-
RESP_PARSER["JSON"] = "json";
|
|
48
|
-
RESP_PARSER["TEXT"] = "text";
|
|
49
|
-
})(RESP_PARSER || (exports.RESP_PARSER = RESP_PARSER = {}));
|
|
50
41
|
/**
|
|
51
42
|
* Manages request and response nodes,
|
|
52
43
|
* as well as calls to that endpoint
|
|
53
44
|
*/
|
|
54
45
|
class Endpoint {
|
|
55
|
-
constructor({
|
|
46
|
+
constructor({ url, method }) {
|
|
56
47
|
_Endpoint_instances.add(this);
|
|
57
|
-
_Endpoint_addr.set(this, '127.0.0.1');
|
|
58
|
-
_Endpoint_path.set(this, void 0);
|
|
59
|
-
_Endpoint_method.set(this, void 0);
|
|
60
48
|
_Endpoint_req.set(this, void 0);
|
|
61
49
|
_Endpoint_resp.set(this, void 0);
|
|
62
50
|
_Endpoint_config.set(this, {});
|
|
63
51
|
_Endpoint_store.set(this, new store_1.Store());
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
__classPrivateFieldSet(this, _Endpoint_path, path, "f");
|
|
70
|
-
__classPrivateFieldSet(this, _Endpoint_method, method, "f");
|
|
71
|
-
this.id = (0, id_1.getEndpointId)({ method: __classPrivateFieldGet(this, _Endpoint_method, "f"), route: __classPrivateFieldGet(this, _Endpoint_path, "f") });
|
|
52
|
+
/** @todo consider validating url */
|
|
53
|
+
!(url.startsWith('http://') || url.startsWith('https://')) && (url = `http://${url}`);
|
|
54
|
+
this.url = url;
|
|
55
|
+
this.method = method;
|
|
56
|
+
this.id = (0, id_1.getEndpointId)({ method, url });
|
|
72
57
|
__classPrivateFieldSet(this, _Endpoint_req, new reqBuilder_1.ReqBuilder(), "f");
|
|
73
58
|
__classPrivateFieldGet(this, _Endpoint_instances, "m", _Endpoint_extractPathParams).call(this);
|
|
74
59
|
__classPrivateFieldSet(this, _Endpoint_resp, (0, sourceNode_1.sourceNode)(this.id), "f");
|
|
75
60
|
}
|
|
76
|
-
get method() {
|
|
77
|
-
return __classPrivateFieldGet(this, _Endpoint_method, "f");
|
|
78
|
-
}
|
|
79
61
|
/** @todo Update this when there is a better implementation of id. */
|
|
80
62
|
get details() {
|
|
81
63
|
return this.id;
|
|
@@ -127,12 +109,11 @@ class Endpoint {
|
|
|
127
109
|
call(responses, opts) {
|
|
128
110
|
var _a, _b, _c;
|
|
129
111
|
return __awaiter(this, void 0, void 0, function* () {
|
|
130
|
-
const method =
|
|
112
|
+
const method = this.method.toUpperCase();
|
|
131
113
|
let body;
|
|
132
114
|
const missingValues = []; // contains path of missing required values
|
|
133
115
|
if (method !== 'GET')
|
|
134
116
|
body = __classPrivateFieldGet(this, _Endpoint_req, "f").body[symbols_1.getNodeValue](responses, missingValues, ['body']);
|
|
135
|
-
let callPath = __classPrivateFieldGet(this, _Endpoint_path, "f");
|
|
136
117
|
let pathParams = {};
|
|
137
118
|
if (Object.keys(__classPrivateFieldGet(this, _Endpoint_req, "f").pathParams).length > 0) {
|
|
138
119
|
pathParams = __classPrivateFieldGet(this, _Endpoint_req, "f").pathParams[symbols_1.getNodeValue](responses, missingValues, ['pathParams']);
|
|
@@ -155,22 +136,30 @@ class Endpoint {
|
|
|
155
136
|
queryParams = deepmerge(queryParams, opts.query);
|
|
156
137
|
if (opts === null || opts === void 0 ? void 0 : opts.headers)
|
|
157
138
|
headers = deepmerge(headers, opts.headers);
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
method:
|
|
139
|
+
let url = this.url;
|
|
140
|
+
url = __classPrivateFieldGet(this, _Endpoint_instances, "m", _Endpoint_insertPathParams).call(this, url, pathParams);
|
|
141
|
+
url = __classPrivateFieldGet(this, _Endpoint_instances, "m", _Endpoint_insertQueryParams).call(this, url, queryParams);
|
|
142
|
+
const resp = yield client_1.httpClient.request({
|
|
143
|
+
url,
|
|
144
|
+
method: this.method.toUpperCase(),
|
|
164
145
|
body,
|
|
165
146
|
headers,
|
|
147
|
+
respParser: __classPrivateFieldGet(this, _Endpoint_config, "f").respParser,
|
|
166
148
|
});
|
|
167
|
-
|
|
168
|
-
throw new errors_1.InvalidResponseError('No response received.');
|
|
169
|
-
const parsedResp = Object.assign(Object.assign({}, resp), { body: resp.body.body && (yield __classPrivateFieldGet(this, _Endpoint_instances, "m", _Endpoint_parseResponse).call(this, resp.body)) });
|
|
170
|
-
const results = (_c = (_b = (_a = __classPrivateFieldGet(this, _Endpoint_config, "f")).respValidator) === null || _b === void 0 ? void 0 : _b.call(_a, parsedResp)) !== null && _c !== void 0 ? _c : __classPrivateFieldGet(this, _Endpoint_instances, "m", _Endpoint_validateResp).call(this, parsedResp);
|
|
149
|
+
const results = (_c = (_b = (_a = __classPrivateFieldGet(this, _Endpoint_config, "f")).respValidator) === null || _b === void 0 ? void 0 : _b.call(_a, resp)) !== null && _c !== void 0 ? _c : __classPrivateFieldGet(this, _Endpoint_instances, "m", _Endpoint_validateResp).call(this, resp);
|
|
171
150
|
if (!results.valid)
|
|
172
151
|
throw new errors_1.InvalidResponseError(results.msg);
|
|
173
|
-
return
|
|
152
|
+
return {
|
|
153
|
+
req: {
|
|
154
|
+
method,
|
|
155
|
+
url,
|
|
156
|
+
body,
|
|
157
|
+
headers,
|
|
158
|
+
respParser: __classPrivateFieldGet(this, _Endpoint_config, "f").respParser,
|
|
159
|
+
},
|
|
160
|
+
resp,
|
|
161
|
+
store: __classPrivateFieldGet(this, _Endpoint_store, "f").storeValues(resp),
|
|
162
|
+
};
|
|
174
163
|
});
|
|
175
164
|
}
|
|
176
165
|
/** Passes the request input nodes of this endpoint to a callback. */
|
|
@@ -185,11 +174,11 @@ class Endpoint {
|
|
|
185
174
|
}
|
|
186
175
|
}
|
|
187
176
|
exports.Endpoint = Endpoint;
|
|
188
|
-
|
|
177
|
+
_Endpoint_req = new WeakMap(), _Endpoint_resp = new WeakMap(), _Endpoint_config = new WeakMap(), _Endpoint_store = new WeakMap(), _Endpoint_instances = new WeakSet(), _Endpoint_extractPathParams = function _Endpoint_extractPathParams() {
|
|
189
178
|
const pathParamRegex = new RegExp(PATH_PARAM_REGEX);
|
|
190
179
|
let param;
|
|
191
180
|
const params = {};
|
|
192
|
-
while ((param = pathParamRegex.exec(
|
|
181
|
+
while ((param = pathParamRegex.exec(this.url)) !== null && typeof param[1] === 'string') {
|
|
193
182
|
const paramName = param[1].replace('{', '').replace('}', '');
|
|
194
183
|
params[paramName] = (0, initializers_1.required)();
|
|
195
184
|
}
|
|
@@ -229,19 +218,5 @@ _Endpoint_addr = new WeakMap(), _Endpoint_path = new WeakMap(), _Endpoint_method
|
|
|
229
218
|
}
|
|
230
219
|
}
|
|
231
220
|
return finalMissingValues;
|
|
232
|
-
}, _Endpoint_parseResponse = function _Endpoint_parseResponse(body) {
|
|
233
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
234
|
-
switch (__classPrivateFieldGet(this, _Endpoint_config, "f").respParser) {
|
|
235
|
-
case RESP_PARSER.ARRAY_BUFFER:
|
|
236
|
-
return yield body.arrayBuffer();
|
|
237
|
-
case RESP_PARSER.BLOB:
|
|
238
|
-
return yield body.blob();
|
|
239
|
-
case RESP_PARSER.TEXT:
|
|
240
|
-
return yield body.text();
|
|
241
|
-
case RESP_PARSER.JSON:
|
|
242
|
-
default:
|
|
243
|
-
return yield body.json();
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
221
|
};
|
|
247
222
|
//# sourceMappingURL=endpoint.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"endpoint.js","sourceRoot":"","sources":["../../src/http/endpoint.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAA2C;AAC3C,iDAAwE;AACxE,6CAA0C;AAC1C,
|
|
1
|
+
{"version":3,"file":"endpoint.js","sourceRoot":"","sources":["../../src/http/endpoint.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAA2C;AAC3C,iDAAwE;AACxE,6CAA0C;AAC1C,2CAMwB;AACxB,qCAA6E;AAE7E,mEAAgD;AAChD,mDAA4D;AAC5D,mDAA0E;AAC1E,6DAAsD;AACtD,yCAA8C;AAC9C,qCAAgC;AAIhC,MAAM,SAAS,GAAG,IAAA,mBAAc,GAAE,CAAC;AAEnC,MAAM,gBAAgB,GAAG,iBAAiB,CAAC;AA+B3C;;;GAGG;AACH,MAAa,QAAQ;IASnB,YAAY,EAAE,GAAG,EAAE,MAAM,EAA6C;;QALtE,gCAAiB;QACjB,iCAAkB;QAClB,2BAA0B,EAAE,EAAC;QAC7B,0BAAgB,IAAI,aAAK,EAAE,EAAC;QAG1B,oCAAoC;QACpC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,GAAG,CAAC,UAAU,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,CAAC,CAAC;gBACxC,MAAM;YACR,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,kBAAkB,CAAC;AAC5B,CAAC"}
|
package/dist/http/errors.d.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
/** When an unsupported method is passed into an `Endpoint`. */
|
|
2
|
-
export declare class UnsupportedMethodError extends Error {
|
|
3
|
-
constructor(unsupportedMethod: string);
|
|
4
|
-
}
|
|
5
1
|
/** When there is no value available for a required input node. */
|
|
6
2
|
export declare class RequiredValuesNotFoundError extends Error {
|
|
7
3
|
constructor(id: string, missingValues: string[]);
|
|
8
4
|
}
|
|
5
|
+
/** When a request to an endpoint fails to execute or receive a response. */
|
|
6
|
+
export declare class RequestFailedError extends Error {
|
|
7
|
+
constructor(msg?: string);
|
|
8
|
+
}
|
|
9
|
+
/** When a response fails a validation check. */
|
|
9
10
|
export declare class InvalidResponseError extends Error {
|
|
10
11
|
constructor(msg?: string);
|
|
11
12
|
}
|
|
13
|
+
/** When the client fails to parse a response body. */
|
|
14
|
+
export declare class ParseResponseError extends Error {
|
|
15
|
+
constructor(msg?: string);
|
|
16
|
+
}
|
package/dist/http/errors.js
CHANGED
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.InvalidResponseError = exports.
|
|
4
|
-
/** When an unsupported method is passed into an `Endpoint`. */
|
|
5
|
-
class UnsupportedMethodError extends Error {
|
|
6
|
-
constructor(unsupportedMethod) {
|
|
7
|
-
super(`Method "${unsupportedMethod}" is not supported.`);
|
|
8
|
-
this.name = 'UnsupportedMethodError';
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
exports.UnsupportedMethodError = UnsupportedMethodError;
|
|
3
|
+
exports.ParseResponseError = exports.InvalidResponseError = exports.RequestFailedError = exports.RequiredValuesNotFoundError = void 0;
|
|
12
4
|
/** When there is no value available for a required input node. */
|
|
13
5
|
class RequiredValuesNotFoundError extends Error {
|
|
14
6
|
constructor(id, missingValues) {
|
|
@@ -17,6 +9,15 @@ class RequiredValuesNotFoundError extends Error {
|
|
|
17
9
|
}
|
|
18
10
|
}
|
|
19
11
|
exports.RequiredValuesNotFoundError = RequiredValuesNotFoundError;
|
|
12
|
+
/** When a request to an endpoint fails to execute or receive a response. */
|
|
13
|
+
class RequestFailedError extends Error {
|
|
14
|
+
constructor(msg) {
|
|
15
|
+
super(`Request failed: ${msg}`);
|
|
16
|
+
this.name = 'RequestFailedError';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.RequestFailedError = RequestFailedError;
|
|
20
|
+
/** When a response fails a validation check. */
|
|
20
21
|
class InvalidResponseError extends Error {
|
|
21
22
|
constructor(msg) {
|
|
22
23
|
super(`Response is invalid: ${msg !== null && msg !== void 0 ? msg : '[No error message is configured for this validation error]'}`);
|
|
@@ -24,4 +25,12 @@ class InvalidResponseError extends Error {
|
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
27
|
exports.InvalidResponseError = InvalidResponseError;
|
|
28
|
+
/** When the client fails to parse a response body. */
|
|
29
|
+
class ParseResponseError extends Error {
|
|
30
|
+
constructor(msg) {
|
|
31
|
+
super(`Failed to parse response: ${msg}`);
|
|
32
|
+
this.name = 'ParseResponseError';
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.ParseResponseError = ParseResponseError;
|
|
27
36
|
//# sourceMappingURL=errors.js.map
|
package/dist/http/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/http/errors.ts"],"names":[],"mappings":";;;AAAA
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/http/errors.ts"],"names":[],"mappings":";;;AAAA,kEAAkE;AAClE,MAAa,2BAA4B,SAAQ,KAAK;IACpD,YAAY,EAAU,EAAE,aAAuB;QAC7C,KAAK,CACH,qBAAqB,EAAE,kDAAkD,aAAa,CAAC,IAAI,CACzF,IAAI,CACL,EAAE,CACJ,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,6BAA6B,CAAC;IAC5C,CAAC;CACF;AATD,kEASC;AAED,4EAA4E;AAC5E,MAAa,kBAAmB,SAAQ,KAAK;IAC3C,YAAY,GAAY;QACtB,KAAK,CAAC,mBAAmB,GAAG,EAAE,CAAC,CAAC;QAChC,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,CAAC;CACF;AALD,gDAKC;AAED,gDAAgD;AAChD,MAAa,oBAAqB,SAAQ,KAAK;IAC7C,YAAY,GAAY;QACtB,KAAK,CACH,wBAAwB,GAAG,aAAH,GAAG,cAAH,GAAG,GAAI,4DAA4D,EAAE,CAC9F,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACrC,CAAC;CACF;AAPD,oDAOC;AACD,sDAAsD;AACtD,MAAa,kBAAmB,SAAQ,KAAK;IAC3C,YAAY,GAAY;QACtB,KAAK,CAAC,6BAA6B,GAAG,EAAE,CAAC,CAAC;QAC1C,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,CAAC;CACF;AALD,gDAKC"}
|
package/dist/http/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/http/logger.ts"],"names":[],"mappings":";;;;;;AAAA,0BAA0B;AAC1B,kDAA0B;AAC1B,
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/http/logger.ts"],"names":[],"mappings":";;;;;;AAAA,0BAA0B;AAC1B,kDAA0B;AAC1B,2CAA8D;AAEjD,QAAA,GAAG,GAAG,IAAA,eAAK,EAAC,gBAAgB,CAAC,CAAC;AAC9B,QAAA,IAAI,GAAG,IAAA,eAAK,EAAC,sBAAsB,CAAC,CAAC;AAE3C,MAAM,UAAU,GAAG,GAAG,EAAE;IAC7B,WAAG,CAAC,OAAO,GAAG,IAAI,CAAC;IACnB,YAAI,CAAC,OAAO,GAAG,IAAI,CAAC;IACpB,IAAA,mBAAc,GAAE,CAAC;AACnB,CAAC,CAAC;AAJW,QAAA,UAAU,cAIrB;AAEF,IAAI,OAAO,CAAC,GAAG,CAAC,qBAAqB,KAAK,MAAM,EAAE,CAAC;IACjD,IAAA,kBAAU,GAAE,CAAC;AACf,CAAC"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Endpoint, EndpointConfig, INodeWithValue } from './endpoint';
|
|
2
2
|
import { InputNode } from '../core/inputNode';
|
|
3
|
-
/** Convenience function for creating an endpoint builder
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
/** Convenience function for creating an endpoint builder
|
|
4
|
+
* with supported HTTP methods defined on it. */
|
|
5
|
+
export declare const origin: (origin?: string) => Origin;
|
|
6
|
+
/** Function for defining a new endpoint. */
|
|
6
7
|
type MakeEndpoint = (path: string) => Endpoint;
|
|
7
|
-
export type
|
|
8
|
+
export type Origin = OriginBase & {
|
|
8
9
|
get: MakeEndpoint;
|
|
9
10
|
post: MakeEndpoint;
|
|
10
11
|
put: MakeEndpoint;
|
|
@@ -12,7 +13,7 @@ export type OriginServer = OriginBase & {
|
|
|
12
13
|
patch: MakeEndpoint;
|
|
13
14
|
options: MakeEndpoint;
|
|
14
15
|
};
|
|
15
|
-
/** Stores the base
|
|
16
|
+
/** Stores the base url and defines methods to build endpoints with methods. */
|
|
16
17
|
declare class OriginBase {
|
|
17
18
|
#private;
|
|
18
19
|
/** Sets configuration for all endpoints made by this origin. */
|
|
@@ -23,6 +24,6 @@ declare class OriginBase {
|
|
|
23
24
|
set(setter: ({ headers }: {
|
|
24
25
|
headers: InputNode;
|
|
25
26
|
}) => void): this;
|
|
26
|
-
constructor(
|
|
27
|
+
constructor(origin?: string);
|
|
27
28
|
}
|
|
28
29
|
export {};
|
|
@@ -10,16 +10,17 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
12
|
};
|
|
13
|
-
var
|
|
13
|
+
var _OriginBase_origin, _OriginBase_headers, _OriginBase_config;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
15
|
+
exports.origin = void 0;
|
|
16
16
|
const endpoint_1 = require("./endpoint");
|
|
17
17
|
const inputNode_1 = require("../core/inputNode");
|
|
18
18
|
const constants_1 = require("./utils/constants");
|
|
19
|
-
/** Convenience function for creating an endpoint builder
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
/** Convenience function for creating an endpoint builder
|
|
20
|
+
* with supported HTTP methods defined on it. */
|
|
21
|
+
const origin = (origin) => new OriginBase(origin);
|
|
22
|
+
exports.origin = origin;
|
|
23
|
+
/** Stores the base url and defines methods to build endpoints with methods. */
|
|
23
24
|
class OriginBase {
|
|
24
25
|
/** Sets configuration for all endpoints made by this origin. */
|
|
25
26
|
config(config) {
|
|
@@ -38,17 +39,18 @@ class OriginBase {
|
|
|
38
39
|
});
|
|
39
40
|
return this;
|
|
40
41
|
}
|
|
41
|
-
constructor(
|
|
42
|
-
|
|
42
|
+
constructor(origin) {
|
|
43
|
+
_OriginBase_origin.set(this, void 0);
|
|
43
44
|
_OriginBase_headers.set(this, void 0);
|
|
44
45
|
_OriginBase_config.set(this, {});
|
|
45
|
-
__classPrivateFieldSet(this,
|
|
46
|
+
__classPrivateFieldSet(this, _OriginBase_origin, origin, "f");
|
|
46
47
|
__classPrivateFieldSet(this, _OriginBase_headers, new inputNode_1.InputNode(undefined), "f");
|
|
47
48
|
constants_1.SUPPORTED_METHODS.forEach((method) => {
|
|
48
49
|
// define methods to create endpoints from HTTP methods
|
|
49
50
|
Reflect.defineProperty(this, method, {
|
|
50
51
|
value: (path) => {
|
|
51
|
-
|
|
52
|
+
var _a;
|
|
53
|
+
return new endpoint_1.Endpoint({ url: `${(_a = __classPrivateFieldGet(this, _OriginBase_origin, "f")) !== null && _a !== void 0 ? _a : ''}${path}`, method })
|
|
52
54
|
.baseHeaders(__classPrivateFieldGet(this, _OriginBase_headers, "f"))
|
|
53
55
|
.config(__classPrivateFieldGet(this, _OriginBase_config, "f"));
|
|
54
56
|
},
|
|
@@ -56,5 +58,5 @@ class OriginBase {
|
|
|
56
58
|
});
|
|
57
59
|
}
|
|
58
60
|
}
|
|
59
|
-
|
|
60
|
-
//# sourceMappingURL=
|
|
61
|
+
_OriginBase_origin = new WeakMap(), _OriginBase_headers = new WeakMap(), _OriginBase_config = new WeakMap();
|
|
62
|
+
//# sourceMappingURL=origin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"origin.js","sourceRoot":"","sources":["../../src/http/origin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,yCAAsE;AACtE,iDAA8C;AAC9C,iDAAsD;AAEtD;gDACgD;AACzC,MAAM,MAAM,GAAG,CAAC,MAAe,EAAE,EAAE,CAAC,IAAI,UAAU,CAAC,MAAM,CAAW,CAAC;AAA/D,QAAA,MAAM,UAAyD;AAc5E,+EAA+E;AAC/E,MAAM,UAAU;IAKd,gEAAgE;IAChE,MAAM,CAAC,MAAsB;QAC3B,uBAAA,IAAI,sBAAW,MAAM,MAAA,CAAC;QACtB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,mEAAmE;IACnE,OAAO,CAAC,MAA2D;QACjE,uBAAA,IAAI,uBAAY,IAAI,qBAAS,CAAC,MAAM,CAAC,MAAA,CAAC;QACtC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,mDAAmD;IACnD,GAAG,CAAC,MAAqD;QACvD,MAAM,CAAC;YACL,OAAO,EAAE,uBAAA,IAAI,2BAAS;SACvB,CAAC,CAAC;QACH,OAAO,IAAI,CAAC;IACd,CAAC;IAED,YAAY,MAAe;QAxB3B,qCAAiB;QACjB,sCAAoB;QACpB,6BAA0B,EAAE,EAAC;QAuB3B,uBAAA,IAAI,sBAAW,MAAM,MAAA,CAAC;QACtB,uBAAA,IAAI,uBAAY,IAAI,qBAAS,CAAC,SAAS,CAAC,MAAA,CAAC;QACzC,6BAAiB,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;YACnC,uDAAuD;YACvD,OAAO,CAAC,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE;gBACnC,KAAK,EAAE,CAAC,IAAY,EAAE,EAAE;;oBACtB,OAAO,IAAI,mBAAQ,CAAC,EAAE,GAAG,EAAE,GAAG,MAAA,uBAAA,IAAI,0BAAQ,mCAAI,EAAE,GAAG,IAAI,EAAE,EAAE,MAAM,EAAE,CAAC;yBACjE,WAAW,CAAC,uBAAA,IAAI,2BAAS,CAAC;yBAC1B,MAAM,CAAC,uBAAA,IAAI,0BAAQ,CAAC,CAAC;gBAC1B,CAAC;aACF,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -1,17 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { Dispatcher } from 'undici';
|
|
2
|
+
import { SUPPORTED_METHOD } from './constants';
|
|
3
|
+
export type SUPPORTED_METHOD_UPPERCASE = Uppercase<SUPPORTED_METHOD>;
|
|
4
|
+
/** Formats to parse the response body. */
|
|
5
|
+
export declare enum RESP_PARSER {
|
|
6
|
+
ARRAY_BUFFER = "arrayBuffer",
|
|
7
|
+
BLOB = "blob",
|
|
8
|
+
JSON = "json",
|
|
9
|
+
TEXT = "text"
|
|
10
|
+
}
|
|
11
|
+
/** A utility to modify the default headers sent in every endpoint call. */
|
|
12
|
+
export declare const defaultHeaders: (headers?: Record<string, string>, replace?: boolean) => void;
|
|
13
|
+
/** @todo explore allowing the client to be swapped out. */
|
|
14
|
+
export interface IHttpClient<Resp> {
|
|
15
|
+
request: (params: IHttpReq) => Promise<Resp>;
|
|
16
|
+
}
|
|
17
|
+
export interface IHttpReq {
|
|
18
|
+
url: string;
|
|
19
|
+
method: SUPPORTED_METHOD_UPPERCASE;
|
|
20
|
+
body?: any;
|
|
21
|
+
headers?: Record<string, string>;
|
|
22
|
+
respParser?: `${RESP_PARSER}`;
|
|
23
|
+
}
|
|
24
|
+
export type ParsedHttpResp = Omit<Dispatcher.ResponseData, 'body'> & {
|
|
25
|
+
body: unknown;
|
|
7
26
|
};
|
|
8
|
-
declare const
|
|
9
|
-
request: ({ addr, path, method, body, headers, }: {
|
|
10
|
-
addr: string;
|
|
11
|
-
path: string;
|
|
12
|
-
method: SUPPORTED_METHOD_UPPERCASE;
|
|
13
|
-
body?: any;
|
|
14
|
-
headers?: Record<string, string> | undefined;
|
|
15
|
-
}) => Promise<import("undici/types/dispatcher").default.ResponseData | null>;
|
|
16
|
-
};
|
|
17
|
-
export default _default;
|
|
27
|
+
export declare const httpClient: IHttpClient<ParsedHttpResp>;
|
|
@@ -9,32 +9,80 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.defaultHeaders = void 0;
|
|
12
|
+
exports.httpClient = exports.defaultHeaders = exports.RESP_PARSER = void 0;
|
|
13
13
|
const undici_1 = require("undici");
|
|
14
14
|
const logger_1 = require("../logger");
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
const errors_1 = require("../errors");
|
|
16
|
+
/** Formats to parse the response body. */
|
|
17
|
+
var RESP_PARSER;
|
|
18
|
+
(function (RESP_PARSER) {
|
|
19
|
+
RESP_PARSER["ARRAY_BUFFER"] = "arrayBuffer";
|
|
20
|
+
RESP_PARSER["BLOB"] = "blob";
|
|
21
|
+
RESP_PARSER["JSON"] = "json";
|
|
22
|
+
RESP_PARSER["TEXT"] = "text";
|
|
23
|
+
})(RESP_PARSER || (exports.RESP_PARSER = RESP_PARSER = {}));
|
|
24
|
+
let _defaultHeaders = {
|
|
19
25
|
'content-type': 'application/json',
|
|
20
|
-
|
|
26
|
+
'User-Agent': 'Chainflow/0.1',
|
|
21
27
|
};
|
|
22
|
-
/**
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
/** A utility to modify the default headers sent in every endpoint call. */
|
|
29
|
+
const defaultHeaders = (headers, replace) => {
|
|
30
|
+
replace
|
|
31
|
+
? (_defaultHeaders = headers)
|
|
32
|
+
: (_defaultHeaders = Object.assign(Object.assign({}, _defaultHeaders), headers));
|
|
33
|
+
};
|
|
34
|
+
exports.defaultHeaders = defaultHeaders;
|
|
35
|
+
/** Executes sending a HTTP request. */
|
|
36
|
+
const request = ({ url, method, body, headers, respParser }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
+
const finalHeaders = Object.assign(Object.assign({}, _defaultHeaders), headers);
|
|
38
|
+
if (logger_1.log.enabled) {
|
|
39
|
+
(0, logger_1.log)(`[${method}] [${url}]`);
|
|
40
|
+
(0, logger_1.log)('headers: %O', finalHeaders);
|
|
41
|
+
body != null && (0, logger_1.log)('body: %O', body);
|
|
42
|
+
}
|
|
43
|
+
const resp = yield (0, undici_1.request)(url, {
|
|
44
|
+
method,
|
|
45
|
+
body: body ? JSON.stringify(body) : null /** @todo consider using buffer */,
|
|
46
|
+
headers: Object.keys(finalHeaders).length > 0 ? finalHeaders : null,
|
|
47
|
+
}).catch((err) => {
|
|
48
|
+
throw new errors_1.RequestFailedError(`${err}`);
|
|
49
|
+
});
|
|
50
|
+
const parsedResp = Object.assign(Object.assign({}, resp), { body: yield parseResponse(resp, respParser).catch((err) => {
|
|
51
|
+
throw new errors_1.ParseResponseError(err);
|
|
52
|
+
}) });
|
|
53
|
+
if (logger_1.log.enabled) {
|
|
54
|
+
(0, logger_1.log)('response: %O', {
|
|
55
|
+
statusCode: parsedResp.statusCode,
|
|
56
|
+
body: parsedResp.body,
|
|
31
57
|
});
|
|
32
|
-
return resp;
|
|
33
58
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
59
|
+
return parsedResp;
|
|
60
|
+
});
|
|
61
|
+
/** Parses a response body according to the specified parser. */
|
|
62
|
+
const parseResponse = (resp, respParser) => __awaiter(void 0, void 0, void 0, function* () {
|
|
63
|
+
switch (respParser) {
|
|
64
|
+
case RESP_PARSER.ARRAY_BUFFER:
|
|
65
|
+
return yield resp.body.arrayBuffer();
|
|
66
|
+
case RESP_PARSER.BLOB:
|
|
67
|
+
return yield resp.body.blob();
|
|
68
|
+
case RESP_PARSER.TEXT:
|
|
69
|
+
return yield resp.body.text();
|
|
70
|
+
case RESP_PARSER.JSON:
|
|
71
|
+
return yield resp.body.json();
|
|
72
|
+
default:
|
|
73
|
+
if (checkJsonSafe(resp))
|
|
74
|
+
return yield resp.body.json();
|
|
75
|
+
return yield resp.body.text();
|
|
37
76
|
}
|
|
38
77
|
});
|
|
39
|
-
|
|
78
|
+
/**
|
|
79
|
+
* Check required to avoid errors when attempting `json()` on an empty body.
|
|
80
|
+
* Refer to section under `ResponseData` at
|
|
81
|
+
* https://github.com/nodejs/undici/blob/main/docs/docs/api/Dispatcher.md
|
|
82
|
+
*/
|
|
83
|
+
const checkJsonSafe = (resp) => {
|
|
84
|
+
var _a;
|
|
85
|
+
return Boolean(resp.statusCode !== 204 && ((_a = resp.headers['content-type']) === null || _a === void 0 ? void 0 : _a.includes('application/json')));
|
|
86
|
+
};
|
|
87
|
+
exports.httpClient = { request };
|
|
40
88
|
//# sourceMappingURL=client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/http/utils/client.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"client.js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MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;YACvD,OAAO,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;IAClC,CAAC;AACH,CAAC,CAAA,CAAC;AAEF;;;;GAIG;AACH,MAAM,aAAa,GAAG,CAAC,IAA6B,EAAW,EAAE;;IAC/D,OAAO,OAAO,CACZ,IAAI,CAAC,UAAU,KAAK,GAAG,KAAI,MAAA,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,0CAAE,QAAQ,CAAC,kBAAkB,CAAC,CAAA,CACtF,CAAC;AACJ,CAAC,CAAC;AAEW,QAAA,UAAU,GAAgC,EAAE,OAAO,EAAE,CAAC"}
|
package/dist/http/utils/id.d.ts
CHANGED
package/dist/http/utils/id.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getEndpointId = void 0;
|
|
4
4
|
/** @todo explore improving this */
|
|
5
|
-
const getEndpointId = ({
|
|
6
|
-
return `[${method.toUpperCase()}] ${
|
|
5
|
+
const getEndpointId = ({ url, method }) => {
|
|
6
|
+
return `[${method.toUpperCase()}] ${url}`;
|
|
7
7
|
};
|
|
8
8
|
exports.getEndpointId = getEndpointId;
|
|
9
9
|
//# sourceMappingURL=id.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"id.js","sourceRoot":"","sources":["../../../src/http/utils/id.ts"],"names":[],"mappings":";;;AAAA,mCAAmC;AAC5B,MAAM,aAAa,GAAG,CAAC,EAAE,
|
|
1
|
+
{"version":3,"file":"id.js","sourceRoot":"","sources":["../../../src/http/utils/id.ts"],"names":[],"mappings":";;;AAAA,mCAAmC;AAC5B,MAAM,aAAa,GAAG,CAAC,EAAE,GAAG,EAAE,MAAM,EAAmC,EAAU,EAAE;IACxF,OAAO,IAAI,MAAM,CAAC,WAAW,EAAE,KAAK,GAAG,EAAE,CAAC;AAC5C,CAAC,CAAC;AAFW,QAAA,aAAa,iBAExB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,5 +5,6 @@ export * from './core/utils/link';
|
|
|
5
5
|
export * from './core/utils/config';
|
|
6
6
|
export * from './http/endpoint';
|
|
7
7
|
export * from './http/reqBuilder';
|
|
8
|
-
export * from './http/
|
|
8
|
+
export * from './http/origin';
|
|
9
9
|
export { enableLogs } from './http/logger';
|
|
10
|
+
export { defaultHeaders } from './http/utils/client';
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.enableLogs = void 0;
|
|
17
|
+
exports.defaultHeaders = exports.enableLogs = void 0;
|
|
18
18
|
__exportStar(require("./core/chainflow"), exports);
|
|
19
19
|
__exportStar(require("./core/utils/initializers"), exports);
|
|
20
20
|
__exportStar(require("./core/inputNode"), exports);
|
|
@@ -22,7 +22,9 @@ __exportStar(require("./core/utils/link"), exports);
|
|
|
22
22
|
__exportStar(require("./core/utils/config"), exports);
|
|
23
23
|
__exportStar(require("./http/endpoint"), exports);
|
|
24
24
|
__exportStar(require("./http/reqBuilder"), exports);
|
|
25
|
-
__exportStar(require("./http/
|
|
25
|
+
__exportStar(require("./http/origin"), exports);
|
|
26
26
|
var logger_1 = require("./http/logger");
|
|
27
27
|
Object.defineProperty(exports, "enableLogs", { enumerable: true, get: function () { return logger_1.enableLogs; } });
|
|
28
|
+
var client_1 = require("./http/utils/client");
|
|
29
|
+
Object.defineProperty(exports, "defaultHeaders", { enumerable: true, get: function () { return client_1.defaultHeaders; } });
|
|
28
30
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,mDAAiC;AACjC,4DAA0C;AAC1C,mDAAiC;AACjC,oDAAkC;AAClC,sDAAoC;AACpC,kDAAgC;AAChC,oDAAkC;AAClC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,mDAAiC;AACjC,4DAA0C;AAC1C,mDAAiC;AACjC,oDAAkC;AAClC,sDAAoC;AACpC,kDAAgC;AAChC,oDAAkC;AAClC,gDAA8B;AAC9B,wCAA2C;AAAlC,oGAAA,UAAU,OAAA;AACnB,8CAAqD;AAA5C,wGAAA,cAAc,OAAA"}
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"originServer.js","sourceRoot":"","sources":["../../src/http/originServer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,yCAAsE;AACtE,iDAA8C;AAC9C,iDAAsD;AAEtD,kGAAkG;AAC3F,MAAM,YAAY,GAAG,CAAC,IAAa,EAAE,EAAE,CAAC,IAAI,UAAU,CAAC,IAAI,CAAiB,CAAC;AAAvE,QAAA,YAAY,gBAA2D;AAcpF,mFAAmF;AACnF,MAAM,UAAU;IAKd,gEAAgE;IAChE,MAAM,CAAC,MAAsB;QAC3B,uBAAA,IAAI,sBAAW,MAAM,MAAA,CAAC;QACtB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,mEAAmE;IACnE,OAAO,CAAC,MAA2D;QACjE,uBAAA,IAAI,uBAAY,IAAI,qBAAS,CAAC,MAAM,CAAC,MAAA,CAAC;QACtC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,mDAAmD;IACnD,GAAG,CAAC,MAAqD;QACvD,MAAM,CAAC;YACL,OAAO,EAAE,uBAAA,IAAI,2BAAS;SACvB,CAAC,CAAC;QACH,OAAO,IAAI,CAAC;IACd,CAAC;IAED,YAAY,OAAe,kBAAkB;QAxB7C,m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