@vita-mojo/integration-hub 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.
package/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # integration-hub
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Running unit tests
6
+
7
+ Run `nx test integration-hub` to execute the unit tests via [Jest](https://jestjs.io).
8
+
9
+ ## Running lint
10
+
11
+ Run `nx lint integration-hub` to execute the lint via [ESLint](https://eslint.org/).
package/package.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "@vita-mojo/integration-hub",
3
+ "version": "0.0.2",
4
+ "main": "./src/index.js",
5
+ "types": "./src/index.d.ts",
6
+ "dependencies": {},
7
+ "peerDependencies": {
8
+ "ramda": "0.28.0",
9
+ "axios": "1.2.2",
10
+ "fast-safe-stringify": "2.1.1",
11
+ "tslib": "2.4.1"
12
+ }
13
+ }
@@ -0,0 +1,13 @@
1
+ export declare enum IntegrationStatuses {
2
+ WARNING = "warning",
3
+ SUCCESS = "success",
4
+ ERROR = "error"
5
+ }
6
+ export declare enum Epos2EventTypes {
7
+ NEW_ORDER = "New Order",
8
+ ORDER_STATUS = "Order Status"
9
+ }
10
+ export declare enum Epos2IntegrationTypes {
11
+ OUTBOUND = "outbound",
12
+ INBOUND = "inbound"
13
+ }
@@ -0,0 +1,17 @@
1
+ export var IntegrationStatuses;
2
+ (function (IntegrationStatuses) {
3
+ IntegrationStatuses["WARNING"] = "warning";
4
+ IntegrationStatuses["SUCCESS"] = "success";
5
+ IntegrationStatuses["ERROR"] = "error";
6
+ })(IntegrationStatuses || (IntegrationStatuses = {}));
7
+ export var Epos2EventTypes;
8
+ (function (Epos2EventTypes) {
9
+ Epos2EventTypes["NEW_ORDER"] = "New Order";
10
+ Epos2EventTypes["ORDER_STATUS"] = "Order Status";
11
+ })(Epos2EventTypes || (Epos2EventTypes = {}));
12
+ export var Epos2IntegrationTypes;
13
+ (function (Epos2IntegrationTypes) {
14
+ Epos2IntegrationTypes["OUTBOUND"] = "outbound";
15
+ Epos2IntegrationTypes["INBOUND"] = "inbound";
16
+ })(Epos2IntegrationTypes || (Epos2IntegrationTypes = {}));
17
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../packages/integration-hub/src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,mBAIX;AAJD,WAAY,mBAAmB;IAC7B,0CAAmB,CAAA;IACnB,0CAAmB,CAAA;IACnB,sCAAe,CAAA;AACjB,CAAC,EAJW,mBAAmB,KAAnB,mBAAmB,QAI9B;AACD,MAAM,CAAN,IAAY,eAGX;AAHD,WAAY,eAAe;IACzB,0CAAuB,CAAA;IACvB,gDAA6B,CAAA;AAC/B,CAAC,EAHW,eAAe,KAAf,eAAe,QAG1B;AACD,MAAM,CAAN,IAAY,qBAGX;AAHD,WAAY,qBAAqB;IAC/B,8CAAqB,CAAA;IACrB,4CAAmB,CAAA;AACrB,CAAC,EAHW,qBAAqB,KAArB,qBAAqB,QAGhC"}
package/src/index.d.ts ADDED
File without changes
package/src/index.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/integration-hub/src/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,18 @@
1
+ import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
2
+ interface CaptureApiCallOptions {
3
+ parseResponse?: (fulfilled: any) => any;
4
+ parseRequest?: (requestConfig: AxiosRequestConfig<any>) => any;
5
+ parseError?: (error: any) => any;
6
+ }
7
+ export declare class LogsAggregator {
8
+ private aggregatedLogs;
9
+ private readonly initialState;
10
+ constructor(initialState?: {});
11
+ captureApiCall(httpClientRequestCallback: AxiosInstance, { parseRequest, parseResponse, parseError }?: CaptureApiCallOptions): (requestConfig: AxiosRequestConfig) => Promise<AxiosResponse>;
12
+ updateBy(prop: string, updater: (prop: any) => any): void;
13
+ mergeWith(logToMerge: object): void;
14
+ dispatchLogs(logFor: string): void;
15
+ resetAggregatedLogs(): void;
16
+ private createIntegrationStatus;
17
+ }
18
+ export {};
@@ -0,0 +1,66 @@
1
+ import { __awaiter } from "tslib";
2
+ import * as R from 'ramda';
3
+ import { IntegrationStatuses } from './constants';
4
+ import { safeStringify } from './safe-stringify';
5
+ export class LogsAggregator {
6
+ constructor(initialState = {}) {
7
+ this.initialState = Object.assign({ apiCalls: [] }, initialState);
8
+ this.aggregatedLogs = Object.assign({}, this.initialState);
9
+ }
10
+ captureApiCall(httpClientRequestCallback, { parseRequest, parseResponse, parseError } = {}) {
11
+ return (requestConfig) => __awaiter(this, void 0, void 0, function* () {
12
+ let error;
13
+ let response;
14
+ try {
15
+ response = yield httpClientRequestCallback(requestConfig);
16
+ }
17
+ catch (e) {
18
+ error = e;
19
+ throw e;
20
+ }
21
+ finally {
22
+ const fulfilled = response && {
23
+ body: response.data,
24
+ status: response.status,
25
+ };
26
+ this.aggregatedLogs['apiCalls'] = [
27
+ ...this.aggregatedLogs['apiCalls'],
28
+ {
29
+ request: parseRequest ? parseRequest(requestConfig) : requestConfig,
30
+ fulfilled: parseResponse && fulfilled ? parseResponse(fulfilled) : fulfilled,
31
+ rejected: parseError && error ? parseError(error) : error,
32
+ },
33
+ ];
34
+ }
35
+ return response;
36
+ });
37
+ }
38
+ updateBy(prop, updater) {
39
+ this.aggregatedLogs[prop] = updater(this.aggregatedLogs[prop]);
40
+ }
41
+ mergeWith(logToMerge) {
42
+ this.aggregatedLogs = Object.assign(Object.assign({}, this.aggregatedLogs), logToMerge);
43
+ }
44
+ dispatchLogs(logFor) {
45
+ console.log(safeStringify({
46
+ log: Object.assign(Object.assign({}, this.aggregatedLogs), { integrationStatus: this.createIntegrationStatus() }),
47
+ logFor,
48
+ }));
49
+ }
50
+ resetAggregatedLogs() {
51
+ this.aggregatedLogs = Object.assign({}, this.initialState);
52
+ }
53
+ createIntegrationStatus() {
54
+ const notNilOrEmpty = R.complement(R.either(R.isNil, R.isEmpty));
55
+ let status;
56
+ if (notNilOrEmpty(R.path(['aggregatedLogs', 'error'], this)))
57
+ status = IntegrationStatuses.ERROR;
58
+ else if (notNilOrEmpty(R.path(['aggregatedLogs', 'warnings'], this)) ||
59
+ notNilOrEmpty(R.path(['aggregatedLogs', 'mappingErrors'], this)))
60
+ status = IntegrationStatuses.WARNING;
61
+ else
62
+ status = IntegrationStatuses.SUCCESS;
63
+ return status;
64
+ }
65
+ }
66
+ //# sourceMappingURL=logs-aggregator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logs-aggregator.js","sourceRoot":"","sources":["../../../../packages/integration-hub/src/logs-aggregator.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,CAAC,MAAM,OAAO,CAAC;AAE3B,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAQjD,MAAM,OAAO,cAAc;IAIzB,YAAY,YAAY,GAAG,EAAE;QAC3B,IAAI,CAAC,YAAY,mBAAK,QAAQ,EAAE,EAAE,IAAK,YAAY,CAAE,CAAC;QACtD,IAAI,CAAC,cAAc,qBAAQ,IAAI,CAAC,YAAY,CAAE,CAAC;IACjD,CAAC;IAED,cAAc,CACZ,yBAAwC,EACxC,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,KAA4B,EAAE;QAEvE,OAAO,CACL,aAAiC,EACT,EAAE;YAC1B,IAAI,KAAU,CAAC;YACf,IAAI,QAAa,CAAC;YAElB,IAAI;gBACF,QAAQ,GAAG,MAAM,yBAAyB,CAAC,aAAa,CAAC,CAAC;aAC3D;YAAC,OAAO,CAAC,EAAE;gBACV,KAAK,GAAG,CAAC,CAAC;gBACV,MAAM,CAAC,CAAC;aACT;oBAAS;gBACR,MAAM,SAAS,GAAG,QAAQ,IAAI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AC,KAAK,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;QAEjE,IAAI,MAAM,CAAC;QAEX,IAAI,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,gBAAgB,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,CAAC;YAC1D,MAAM,GAAG,mBAAmB,CAAC,KAAK,CAAC;aAChC,IACH,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,gBAAgB,EAAE,UAAU,CAAC,EAAE,IAAI,CAAC,CAAC;YAC3D,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,gBAAgB,EAAE,eAAe,CAAC,EAAE,IAAI,CAAC,CAAC;YAEhE,MAAM,GAAG,mBAAmB,CAAC,OAAO,CAAC;;YAClC,MAAM,GAAG,mBAAmB,CAAC,OAAO,CAAC;QAE1C,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
@@ -0,0 +1 @@
1
+ export declare const safeStringify: (value: any) => string;
@@ -0,0 +1,10 @@
1
+ import stringify from 'fast-safe-stringify';
2
+ export const safeStringify = (value) => {
3
+ try {
4
+ return JSON.stringify(value);
5
+ }
6
+ catch (_a) {
7
+ return stringify(value);
8
+ }
9
+ };
10
+ //# sourceMappingURL=safe-stringify.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"safe-stringify.js","sourceRoot":"","sources":["../../../../packages/integration-hub/src/safe-stringify.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,qBAAqB,CAAC;AAE5C,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,KAAU,EAAU,EAAE;IAClD,IAAI;QACF,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;KAC9B;IAAC,WAAM;QACN,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC;KACzB;AACH,CAAC,CAAC"}