@sipgate/integration-bridge 1.0.35 → 1.0.38
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/dist/cache/contact-cache-storage.js +79 -97
- package/dist/cache/contact-cache-storage.js.map +1 -1
- package/dist/cache/storage/memory-storage-adapter.js +8 -22
- package/dist/cache/storage/memory-storage-adapter.js.map +1 -1
- package/dist/cache/storage/redis-storage-adapter.js +16 -30
- package/dist/cache/storage/redis-storage-adapter.js.map +1 -1
- package/dist/cache/token-cache-storage.js +30 -43
- package/dist/cache/token-cache-storage.js.map +1 -1
- package/dist/controllers/call-log.controller.js +63 -78
- package/dist/controllers/call-log.controller.js.map +1 -1
- package/dist/controllers/task.controller.js +60 -75
- package/dist/controllers/task.controller.js.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.js +38 -21
- package/dist/index.js.map +1 -1
- package/dist/middlewares/error-handler.middleware.js +1 -2
- package/dist/middlewares/error-handler.middleware.js.map +1 -1
- package/dist/middlewares/extract-header.middleware.d.ts +0 -1
- package/dist/middlewares/extract-header.middleware.js +2 -2
- package/dist/middlewares/extract-header.middleware.js.map +1 -1
- package/dist/models/cache-item-state.model.js +1 -1
- package/dist/models/cache-item-state.model.js.map +1 -1
- package/dist/models/call-direction.enum.js +1 -1
- package/dist/models/call-direction.enum.js.map +1 -1
- package/dist/models/call-event.model.js +2 -2
- package/dist/models/call-event.model.js.map +1 -1
- package/dist/models/contact.model.js +3 -3
- package/dist/models/contact.model.js.map +1 -1
- package/dist/models/controller.model.js +579 -622
- package/dist/models/controller.model.js.map +1 -1
- package/dist/models/integration-entity.model.js +1 -1
- package/dist/models/integration-entity.model.js.map +1 -1
- package/dist/models/integration-error.model.js +1 -1
- package/dist/models/integration-error.model.js.map +1 -1
- package/dist/models/integrations-event.model.js +1 -1
- package/dist/models/integrations-event.model.js.map +1 -1
- package/dist/models/pubsub/pubsub-client.model.js +16 -25
- package/dist/models/pubsub/pubsub-client.model.js.map +1 -1
- package/dist/models/pubsub/pubsub-contacts-message.model.js +1 -1
- package/dist/models/pubsub/pubsub-contacts-message.model.js.map +1 -1
- package/dist/models/server-error.model.js +1 -0
- package/dist/models/server-error.model.js.map +1 -1
- package/dist/swagger/openapi-spec.d.ts +972 -0
- package/dist/swagger/openapi-spec.js +787 -0
- package/dist/swagger/openapi-spec.js.map +1 -0
- package/dist/util/anonymize-key.js +1 -2
- package/dist/util/anonymize-key.js.map +1 -1
- package/dist/util/call-comment.js +5 -6
- package/dist/util/call-comment.js.map +1 -1
- package/dist/util/call-event.util.js +1 -2
- package/dist/util/call-event.util.js.map +1 -1
- package/dist/util/callEventHelper.js +4 -4
- package/dist/util/callEventHelper.js.map +1 -1
- package/dist/util/contact.util.js +10 -8
- package/dist/util/contact.util.js.map +1 -1
- package/dist/util/env.js +19 -9
- package/dist/util/env.js.map +1 -1
- package/dist/util/error/delegate-to-frontend.error.d.ts +5 -0
- package/dist/util/error/delegate-to-frontend.error.js +14 -0
- package/dist/util/error/delegate-to-frontend.error.js.map +1 -0
- package/dist/util/error/error.d.ts +12 -0
- package/dist/util/error/error.js +93 -0
- package/dist/util/error/error.js.map +1 -0
- package/dist/util/gdpr/gdprSlackNotification.js +22 -22
- package/dist/util/gdpr/gdprSlackNotification.js.map +1 -1
- package/dist/util/gdpr/index.js +17 -7
- package/dist/util/gdpr/index.js.map +1 -1
- package/dist/util/get-contact-cache.js +1 -2
- package/dist/util/get-contact-cache.js.map +1 -1
- package/dist/util/http/default-axios.js +1 -2
- package/dist/util/http/default-axios.js.map +1 -1
- package/dist/util/http/index.js +17 -7
- package/dist/util/http/index.js.map +1 -1
- package/dist/util/http/pagination.js +32 -85
- package/dist/util/http/pagination.js.map +1 -1
- package/dist/util/http/rate-limited-axios.js +42 -61
- package/dist/util/http/rate-limited-axios.js.map +1 -1
- package/dist/util/http/retrying-axios.js +11 -23
- package/dist/util/http/retrying-axios.js.map +1 -1
- package/dist/util/http/url.js +1 -2
- package/dist/util/http/url.js.map +1 -1
- package/dist/util/index.d.ts +2 -1
- package/dist/util/index.js +21 -9
- package/dist/util/index.js.map +1 -1
- package/dist/util/lang/delay.js +1 -2
- package/dist/util/lang/delay.js.map +1 -1
- package/dist/util/lang/diff.js +19 -10
- package/dist/util/lang/diff.js.map +1 -1
- package/dist/util/logger.util.js +7 -2
- package/dist/util/logger.util.js.map +1 -1
- package/dist/util/oauth.js +131 -134
- package/dist/util/oauth.js.map +1 -1
- package/dist/util/phone-number-utils.js +4 -5
- package/dist/util/phone-number-utils.js.map +1 -1
- package/dist/util/security/index.js +17 -7
- package/dist/util/security/index.js.map +1 -1
- package/dist/util/security/nonce.js +5 -6
- package/dist/util/security/nonce.js.map +1 -1
- package/dist/util/size-of.js +1 -1
- package/dist/util/size-of.js.map +1 -1
- package/dist/util/token-util.js +46 -62
- package/dist/util/token-util.js.map +1 -1
- package/dist/util/validate.js +1 -2
- package/dist/util/validate.js.map +1 -1
- package/package.json +25 -38
- package/README.md +0 -117
- package/dist/util/error.d.ts +0 -7
- package/dist/util/error.js +0 -76
- package/dist/util/error.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"token-util.js","sourceRoot":"","sources":["../../src/util/token-util.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"token-util.js","sourceRoot":"","sources":["../../src/util/token-util.ts"],"names":[],"mappings":";;;;;AAsBA,sCAoCC;AA6BD,kDA+BC;AAED,8CA8BC;AAtJD,0BAA0D;AAC1D,oCAA6C;AAC7C,8CAA6E;AAC7E,sCAAgD;AAEhD,8DAAiC;AAEjC,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAC7B,MAAM,WAAW,GAAG,IAAI,CAAC;AAEzB,MAAM,KAAK,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAIhF,SAAS,g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UAAU,iBAAiB,CACrC,MAAc,EACd,WAAmB,EACnB,WAAmB;IAEnB,IAAI,CAAC,cAAU,EAAE,CAAC;QAChB,MAAM,IAAI,oBAAW,CACnB,GAAG,EACH,2DAA2D,CAC5D,CAAC;IACJ,CAAC;IAED,MAAM,QAAQ,GAAG,EAAE,WAAW,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;IACnD,MAAM,cAAU,CAAC,GAAG,CAAC,WAAW,EAAE,QAAQ,EAAE,gBAAgB,EAAE,CAAC,CAAC;IAEhE,MAAM,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;IACzC,IAAA,qBAAM,EAAC,gBAAgB,EAAE,iCAAiC,CAAC,CAAC;IAE5D,MAAM,EAAE,qCAAqC,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;IAC9D,IAAA,qBAAM,EACJ,qCAAqC,EACrC,sDAAsD,CACvD,CAAC;IAEF,MAAM,YAAY,GAAG,IAAI,gBAAY,CAAC,qCAAqC,CAAC,CAAC;IAC7E,MAAM,YAAY,CAAC,cAAc,CAAC;QAChC,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,eAAe,EAAE,gBAAgB;QACjC,WAAW;KACZ,CAAC,CAAC;AACL,CAAC"}
|
package/dist/util/validate.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validate =
|
|
3
|
+
exports.validate = validate;
|
|
4
4
|
const models_1 = require("../models");
|
|
5
5
|
const logger_util_1 = require("./logger.util");
|
|
6
6
|
function validate(schema, data, config, errorMessage) {
|
|
@@ -11,5 +11,4 @@ function validate(schema, data, config, errorMessage) {
|
|
|
11
11
|
}
|
|
12
12
|
return parseResult.data;
|
|
13
13
|
}
|
|
14
|
-
exports.validate = validate;
|
|
15
14
|
//# sourceMappingURL=validate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../src/util/validate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../src/util/validate.ts"],"names":[],"mappings":";;AAIA,4BAcC;AAjBD,sCAAgD;AAChD,+CAA4C;AAE5C,SAAgB,QAAQ,CACtB,MAAiB,EACjB,IAAa,EACb,MAAc,EACd,YAAoB;IAEpB,MAAM,WAAW,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAE3C,IAAI,WAAW,CAAC,KAAK,EAAE,CAAC;QACtB,IAAA,yBAAW,EAAC,UAAU,EAAE,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;QAClE,MAAM,IAAI,oBAAW,CAAC,GAAG,EAAE,GAAG,YAAY,KAAK,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IAC9E,CAAC;IAED,OAAO,WAAW,CAAC,IAAI,CAAC;AAC1B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,39 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sipgate/integration-bridge",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.38",
|
|
4
4
|
"description": "sipgate Integration Bridge Framework",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"files": [
|
|
8
8
|
"dist"
|
|
9
9
|
],
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./dist/*": "./dist/*"
|
|
13
16
|
},
|
|
17
|
+
"repository": "github:sipgate/integration-bridge",
|
|
14
18
|
"keywords": [
|
|
15
19
|
"integration",
|
|
16
20
|
"express",
|
|
17
21
|
"framework"
|
|
18
22
|
],
|
|
19
23
|
"license": "UNLICENSED",
|
|
20
|
-
"scripts": {
|
|
21
|
-
"dev": "npm run build && npm link && tsc --watch",
|
|
22
|
-
"watch": "tsc --watch",
|
|
23
|
-
"prepare": "husky install",
|
|
24
|
-
"test": "jest",
|
|
25
|
-
"compile": "tsc",
|
|
26
|
-
"lint": "eslint '**/*.ts'",
|
|
27
|
-
"build": "npm test && rimraf dist && npm run compile",
|
|
28
|
-
"precommit": "lint-staged",
|
|
29
|
-
"prepublishOnly": "npm run build",
|
|
30
|
-
"format": "prettier --write '**/*.ts'"
|
|
31
|
-
},
|
|
32
|
-
"lint-staged": {
|
|
33
|
-
"*.ts": [
|
|
34
|
-
"prettier --write"
|
|
35
|
-
]
|
|
36
|
-
},
|
|
37
24
|
"jest": {
|
|
38
25
|
"transform": {
|
|
39
26
|
"^.+\\.ts?$": "ts-jest"
|
|
@@ -51,52 +38,52 @@
|
|
|
51
38
|
]
|
|
52
39
|
},
|
|
53
40
|
"devDependencies": {
|
|
54
|
-
"@eslint/js": "^9.39.3",
|
|
55
41
|
"@types/body-parser": "1.19.2",
|
|
56
42
|
"@types/compression": "1.7.2",
|
|
57
43
|
"@types/cookies": "^0.7.7",
|
|
58
44
|
"@types/cors": "2.8.13",
|
|
59
|
-
"@types/express": "4.17.17",
|
|
60
45
|
"@types/jest": "^29.4.0",
|
|
61
46
|
"@types/lodash": "^4.14.191",
|
|
62
47
|
"@types/lru-cache": "7.10.9",
|
|
63
|
-
"@types/node": "18.16.5",
|
|
64
48
|
"@types/redis": "4.0.10",
|
|
65
|
-
"
|
|
66
|
-
"eslint-plugin-import": "^2.29.0",
|
|
67
|
-
"globals": "^14.0.0",
|
|
68
|
-
"husky": "8.0.3",
|
|
49
|
+
"@types/swagger-ui-express": "^4.1.8",
|
|
69
50
|
"jest": "^29.4.0",
|
|
70
|
-
"lint-staged": "13.2.2",
|
|
71
51
|
"node-mocks-http": "1.12.2",
|
|
72
|
-
"
|
|
73
|
-
"rimraf": "3.0.2",
|
|
74
|
-
"ts-jest": "^29.0.5",
|
|
75
|
-
"typescript": "4.9.5",
|
|
76
|
-
"typescript-eslint": "8.56.1"
|
|
52
|
+
"ts-jest": "^29.0.5"
|
|
77
53
|
},
|
|
78
54
|
"dependencies": {
|
|
79
55
|
"@google-cloud/pubsub": "^3.7.1",
|
|
80
56
|
"@opentelemetry/api": "^1.9.0",
|
|
81
57
|
"@opentelemetry/auto-instrumentations-node": "^0.70.0",
|
|
82
58
|
"@opentelemetry/exporter-trace-otlp-http": "^0.212.0",
|
|
59
|
+
"@opentelemetry/instrumentation-express": "^0.46.0",
|
|
60
|
+
"@opentelemetry/instrumentation-http": "^0.57.0",
|
|
83
61
|
"@opentelemetry/sdk-node": "^0.212.0",
|
|
84
62
|
"@opentelemetry/sdk-trace-base": "^2.0.0",
|
|
85
63
|
"@slack/webhook": "^6.1.0",
|
|
86
64
|
"awesome-phonenumber": "^3.2.0",
|
|
87
|
-
"axios": "^1.
|
|
65
|
+
"axios": "^1.4.0",
|
|
88
66
|
"body-parser": "^1.20.0",
|
|
89
67
|
"compression": "^1.7.4",
|
|
90
68
|
"cookies": "^0.8.0",
|
|
91
69
|
"cors": "^2.8.5",
|
|
92
|
-
"dotenv": "^16.
|
|
93
|
-
"express": "^4.18.
|
|
70
|
+
"dotenv": "^16.1.4",
|
|
71
|
+
"express": "^4.18.2",
|
|
94
72
|
"lodash": "^4.17.21",
|
|
95
73
|
"lru-cache": "^7.13.1",
|
|
96
74
|
"moment": "^2.29.4",
|
|
97
75
|
"opentelemetry-instrumentation-pubsub": "^2.1.0",
|
|
98
76
|
"rate-limiter-flexible": "^2.3.11",
|
|
99
77
|
"redis": "^4.2.0",
|
|
78
|
+
"swagger-ui-express": "^5.0.1",
|
|
100
79
|
"zod": "^3.23.8"
|
|
80
|
+
},
|
|
81
|
+
"scripts": {
|
|
82
|
+
"build": "rimraf dist && tsc",
|
|
83
|
+
"test": "jest",
|
|
84
|
+
"dev": "tsc --watch",
|
|
85
|
+
"lint": "eslint 'src/**/*.ts'",
|
|
86
|
+
"format": "prettier --write 'src/**/*.ts'",
|
|
87
|
+
"release": "npm version patch && git tag v$(node -p \"require('./package.json').version\") && git push && git push origin v$(node -p \"require('./package.json').version\")"
|
|
101
88
|
}
|
|
102
|
-
}
|
|
89
|
+
}
|
package/README.md
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
# sipgate Integration Bridge Framework
|
|
2
|
-
|
|
3
|
-
This is the sipgate Integration Bridge framework to integrate sipgate apps with external services. It provides a unified
|
|
4
|
-
way to connect apps to any provider of external data management, like contacts or calendar events.
|
|
5
|
-
|
|
6
|
-
## Developing locally
|
|
7
|
-
|
|
8
|
-
To test your changes to the integration-bridge framework locally, follow these steps:
|
|
9
|
-
|
|
10
|
-
- Run `npm run dev` in sipgate-integration-bridge repo
|
|
11
|
-
- Run `npm link @sipgate/integration-bridge` in \*-integration-bridge-repo
|
|
12
|
-
- Add the following to your `tsconfig.json`:
|
|
13
|
-
```json
|
|
14
|
-
{
|
|
15
|
-
"compilerOptions": {
|
|
16
|
-
"paths": {
|
|
17
|
-
"@sipgate/integration-bridge": [
|
|
18
|
-
"node_modules/@sipgate/integration-bridge/src"
|
|
19
|
-
]
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
## Publishing a version
|
|
26
|
-
|
|
27
|
-
To publish a new framework version, simply create a new tag and push it:
|
|
28
|
-
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
npm version <minor|patch>
|
|
32
|
-
git push --follow-tags
|
|
33
|
-
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
This will automatically publish the package in the npm registry via the CI pipeline.
|
|
37
|
-
|
|
38
|
-
## Bootstrapping a new bridge
|
|
39
|
-
|
|
40
|
-
If you want to bootstrap a new sipgate Integration Bridge you can use this repository: [integration-bridge-boilerplate](https://github.com/sipgate/integration-bridge-boilerplate)
|
|
41
|
-
|
|
42
|
-
## Installation
|
|
43
|
-
|
|
44
|
-
```shell
|
|
45
|
-
npm install @sipgate/integration-bridge
|
|
46
|
-
# or
|
|
47
|
-
yarn add @sipgate/integration-bridge
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
## Quick Start
|
|
51
|
-
|
|
52
|
-
The minimum adapter implements the `getContacts` method:
|
|
53
|
-
|
|
54
|
-
```js
|
|
55
|
-
const bridge = require('@sipgate/integration-bridge');
|
|
56
|
-
const fetch = require('node-fetch');
|
|
57
|
-
|
|
58
|
-
const { ServerError } = bridge;
|
|
59
|
-
|
|
60
|
-
const adapter = {
|
|
61
|
-
getContacts: async ({ apiKey, apiUrl }) => {
|
|
62
|
-
// Fetch contacts using apiUrl and apiKey
|
|
63
|
-
const response = await fetch(`${apiUrl}/api/contacts`, {
|
|
64
|
-
headers: { Authorization: `Bearer ${apiKey}` },
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
if (response.status === 401) {
|
|
68
|
-
throw new ServerError(401, 'Unauthorized');
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (!response.ok) {
|
|
72
|
-
throw new ServerError(500, 'Could not fetch contacts');
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// TODO: Convert contacts to the structure below
|
|
76
|
-
const contacts = await response.json();
|
|
77
|
-
return contacts;
|
|
78
|
-
},
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
bridge.start(adapter);
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
Contacts are accepted in this format:
|
|
85
|
-
|
|
86
|
-
```js
|
|
87
|
-
{
|
|
88
|
-
id: "abc123",
|
|
89
|
-
|
|
90
|
-
// Provide either the full name or first and last name, not both
|
|
91
|
-
name: null, // or null
|
|
92
|
-
firstName: "Walter", // or null
|
|
93
|
-
lastName: "Geoffrey", // or null
|
|
94
|
-
|
|
95
|
-
organization: "Rocket Science Inc.", // or null
|
|
96
|
-
contactUrl: "http://myapp.com/contacts/abc123", // or null
|
|
97
|
-
avatarUrl: "http://myapp.com/avatar/abc123.png", // or null
|
|
98
|
-
email: "walter@example.com", // or null
|
|
99
|
-
phoneNumbers: [
|
|
100
|
-
{
|
|
101
|
-
label: "MOBILE", // or "WORK" or "HOME" ...
|
|
102
|
-
phoneNumber: "+4915799912345"
|
|
103
|
-
}
|
|
104
|
-
]
|
|
105
|
-
}
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
## Configuration
|
|
109
|
-
|
|
110
|
-
The sipgate Integration Bridge supports configuration through the following environment variables:
|
|
111
|
-
|
|
112
|
-
- `OAUTH2_REDIRECT_URL`: URL to redirect the user at the end of the OAuth2 flow
|
|
113
|
-
- `OAUTH2_IDENTIFIER`: Name of the Integration to identify credentials in uppercase e. g. "MY_CRM"
|
|
114
|
-
- `REDIS_URL`: URL of a Redis instance to cache responses, otherwise memory cache will be used
|
|
115
|
-
- `CACHE_DISABLED`: Disable caching
|
|
116
|
-
- `CACHE_REFRESH_INTERVAL`: Time a contact in cache is not refreshed (in seconds), only used if redis or memory cache is
|
|
117
|
-
active
|
package/dist/util/error.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { AxiosError } from 'axios';
|
|
2
|
-
import { IntegrationErrorType, ServerError } from '../models';
|
|
3
|
-
export declare const throwAndDelegateError: (error: AxiosError | DelegateToFrontedError | ServerError | Error, source: string, apiKey: string | undefined, logMessage?: string) => never;
|
|
4
|
-
export declare class DelegateToFrontedError extends ServerError {
|
|
5
|
-
errorType: IntegrationErrorType;
|
|
6
|
-
constructor(errorType: IntegrationErrorType);
|
|
7
|
-
}
|
package/dist/util/error.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DelegateToFrontedError = exports.throwAndDelegateError = void 0;
|
|
4
|
-
const axios_1 = require("axios");
|
|
5
|
-
const models_1 = require("../models");
|
|
6
|
-
const logger_util_1 = require("./logger.util");
|
|
7
|
-
const throwAndDelegateError = (error, source, apiKey, logMessage) => {
|
|
8
|
-
var _a, _b, _c, _d;
|
|
9
|
-
const errorMessage = (0, axios_1.isAxiosError)(error)
|
|
10
|
-
? ((_a = error.response) === null || _a === void 0 ? void 0 : _a.data)
|
|
11
|
-
? JSON.stringify((_b = error.response) === null || _b === void 0 ? void 0 : _b.data)
|
|
12
|
-
: error.message
|
|
13
|
-
: error.message;
|
|
14
|
-
if (logMessage) {
|
|
15
|
-
(0, logger_util_1.errorLogger)(source, logMessage, apiKey, {
|
|
16
|
-
message: errorMessage,
|
|
17
|
-
error,
|
|
18
|
-
stackTrace: error.stack,
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
(0, logger_util_1.errorLogger)(source, errorMessage, apiKey, {
|
|
23
|
-
error,
|
|
24
|
-
stackTrace: error.stack,
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
const err = error;
|
|
28
|
-
let errorType = undefined;
|
|
29
|
-
if (error instanceof DelegateToFrontedError) {
|
|
30
|
-
const delegateToFrontedError = error;
|
|
31
|
-
errorType = delegateToFrontedError.errorType;
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
if (err.code || err.status || ((_c = err.response) === null || _c === void 0 ? void 0 : _c.status)) {
|
|
35
|
-
const status = err.status ||
|
|
36
|
-
((_d = err.response) === null || _d === void 0 ? void 0 : _d.status) ||
|
|
37
|
-
(err.code ? parseInt(err.code) : 500);
|
|
38
|
-
switch (status) {
|
|
39
|
-
case 401:
|
|
40
|
-
errorType = models_1.IntegrationErrorType.INTEGRATION_REFRESH_ERROR;
|
|
41
|
-
break;
|
|
42
|
-
case 403:
|
|
43
|
-
errorType = models_1.IntegrationErrorType.INTEGRATION_ERROR_FORBIDDEN;
|
|
44
|
-
break;
|
|
45
|
-
case 404:
|
|
46
|
-
errorType = models_1.IntegrationErrorType.ENTITY_NOT_FOUND;
|
|
47
|
-
break;
|
|
48
|
-
case 409:
|
|
49
|
-
errorType = models_1.IntegrationErrorType.ENTITY_ERROR_CONFLICT;
|
|
50
|
-
break;
|
|
51
|
-
case 502:
|
|
52
|
-
case 503:
|
|
53
|
-
case 504:
|
|
54
|
-
errorType = models_1.IntegrationErrorType.INTEGRATION_ERROR_UNAVAILABLE;
|
|
55
|
-
break;
|
|
56
|
-
default:
|
|
57
|
-
throw new models_1.ServerError(status, `${source} (${errorMessage})`);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
if (errorType !== undefined) {
|
|
62
|
-
(0, logger_util_1.warnLogger)('throwAndDelegateError', `Delegating crm error to frontend with code ${models_1.DELEGATE_TO_FRONTEND_CODE} and type ${errorType}`, apiKey, logMessage);
|
|
63
|
-
throw new models_1.ServerError(models_1.DELEGATE_TO_FRONTEND_CODE, errorType);
|
|
64
|
-
}
|
|
65
|
-
throw new models_1.ServerError(500, `An internal error occurred: ${JSON.stringify(error)}.`);
|
|
66
|
-
};
|
|
67
|
-
exports.throwAndDelegateError = throwAndDelegateError;
|
|
68
|
-
class DelegateToFrontedError extends models_1.ServerError {
|
|
69
|
-
constructor(errorType) {
|
|
70
|
-
super(models_1.DELEGATE_TO_FRONTEND_CODE, errorType);
|
|
71
|
-
this.errorType = errorType;
|
|
72
|
-
this.name = 'DelegateToFrontedError';
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
exports.DelegateToFrontedError = DelegateToFrontedError;
|
|
76
|
-
//# sourceMappingURL=error.js.map
|
package/dist/util/error.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/util/error.ts"],"names":[],"mappings":";;;AAAA,iCAAiD;AACjD,sCAImB;AACnB,+CAAwD;AAEjD,MAAM,qBAAqB,GAAG,CACnC,KAAgE,EAChE,MAAc,EACd,MAA0B,EAC1B,UAAmB,EACnB,EAAE;;IACF,MAAM,YAAY,GAAG,IAAA,oBAAY,EAAC,KAAK,CAAC;QACt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