@sipgate/integration-bridge 0.1.0 → 0.1.3
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/LICENSE +1 -1
- package/README.md +10 -10
- package/dist/cache/storage/redis-storage-adapter.js +5 -5
- package/dist/cache/storage/redis-storage-adapter.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/util/phone-number-utils.js +4 -4
- package/dist/util/phone-number-utils.js.map +1 -1
- package/package.json +2 -4
package/LICENSE
CHANGED
|
@@ -186,7 +186,7 @@
|
|
|
186
186
|
same "printed page" as the copyright notice for easier
|
|
187
187
|
identification within third-party archives.
|
|
188
188
|
|
|
189
|
-
Copyright
|
|
189
|
+
Copyright 2022 sipgate GmbH
|
|
190
190
|
|
|
191
191
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
192
|
you may not use this file except in compliance with the License.
|
package/README.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
# sipgate Integration Bridge Framework
|
|
2
2
|
|
|
3
|
-
This is the sipgate Integration Bridge framework to integrate with external services.
|
|
3
|
+
This is the sipgate Integration Bridge framework to integrate sipgate apps with external services.
|
|
4
4
|
It provides a unified way to connect apps to any provider of external data management, like contacts or calendar events.
|
|
5
5
|
|
|
6
6
|
## Bootstrapping a new bridge
|
|
7
7
|
|
|
8
|
-
If you want to bootstrap a new sipgate Integration Bridge you can use this repository: [
|
|
8
|
+
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)
|
|
9
9
|
|
|
10
10
|
## Installation
|
|
11
11
|
|
|
@@ -27,7 +27,7 @@ const { ServerError } = bridge;
|
|
|
27
27
|
|
|
28
28
|
const adapter = {
|
|
29
29
|
getContacts: async ({ apiKey, apiUrl }) => {
|
|
30
|
-
// Fetch contacts using
|
|
30
|
+
// Fetch contacts using apiUrl and apiKey
|
|
31
31
|
const response = await fetch(`${apiUrl}/api/contacts`, {
|
|
32
32
|
headers: { Authorization: `Bearer ${apiKey}` },
|
|
33
33
|
});
|
|
@@ -36,13 +36,13 @@ const adapter = {
|
|
|
36
36
|
throw new ServerError(401, "Unauthorized");
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
if (response.ok) {
|
|
40
|
-
const contacts = await response.json();
|
|
41
|
-
// TODO: Convert contact to the structure above
|
|
42
|
-
return contacts;
|
|
43
|
-
} else {
|
|
39
|
+
if (!response.ok) {
|
|
44
40
|
throw new ServerError(500, "Could not fetch contacts");
|
|
45
41
|
}
|
|
42
|
+
|
|
43
|
+
// TODO: Convert contacts to the structure below
|
|
44
|
+
const contacts = await response.json();
|
|
45
|
+
return contacts;
|
|
46
46
|
},
|
|
47
47
|
};
|
|
48
48
|
|
|
@@ -75,8 +75,8 @@ Contacts are accepted in this format:
|
|
|
75
75
|
|
|
76
76
|
The sipgate Integration Bridge supports configuration through the following environment variables:
|
|
77
77
|
|
|
78
|
-
- `OAUTH2_REDIRECT_URL`: URL
|
|
79
|
-
- `OAUTH2_IDENTIFIER`: Name of the Integration to
|
|
78
|
+
- `OAUTH2_REDIRECT_URL`: URL to redirect the user at the end of the OAuth2 flow
|
|
79
|
+
- `OAUTH2_IDENTIFIER`: Name of the Integration to identify credentials in uppercase e. g. "MY_CRM"
|
|
80
80
|
- `REDIS_URL`: URL of a Redis instance to cache responses, otherwise memory cache will be used
|
|
81
81
|
- `CACHE_DISABLED`: Disable caching
|
|
82
82
|
- `CACHE_REFRESH_INTERVAL`: Time a contact in cache is not refreshed (in seconds), only used if redis or memory cache is active
|
|
@@ -8,12 +8,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
12
|
exports.RedisStorageAdapter = void 0;
|
|
16
|
-
const redis_1 =
|
|
13
|
+
const redis_1 = require("redis");
|
|
17
14
|
const util_1 = require("util");
|
|
18
15
|
const zlib_1 = require("zlib");
|
|
19
16
|
const inflate = (0, util_1.promisify)(zlib_1.inflate);
|
|
@@ -21,11 +18,14 @@ const deflate = (0, util_1.promisify)(zlib_1.deflate);
|
|
|
21
18
|
const CACHE_TTL = 60 * 60 * 24 * 30; // 30 days
|
|
22
19
|
class RedisStorageAdapter {
|
|
23
20
|
constructor(url) {
|
|
24
|
-
this.client = redis_1.
|
|
21
|
+
this.client = (0, redis_1.createClient)({ url });
|
|
25
22
|
console.log(`Initialized Redis storage with URL ${url}`);
|
|
26
23
|
this.client.on("error", (error) => {
|
|
27
24
|
console.warn("Redis error: ", error.message);
|
|
28
25
|
});
|
|
26
|
+
this.client.connect().catch((error) => {
|
|
27
|
+
console.warn("Redis connection error: ", error.message);
|
|
28
|
+
});
|
|
29
29
|
}
|
|
30
30
|
get(key) {
|
|
31
31
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redis-storage-adapter.js","sourceRoot":"","sources":["../../../src/cache/storage/redis-storage-adapter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"redis-storage-adapter.js","sourceRoot":"","sources":["../../../src/cache/storage/redis-storage-adapter.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iCAAsD;AACtD,+BAAiC;AACjC,+BAIc;AAGd,MAAM,OAAO,GAAG,IAAA,gBAAS,EAAoB,cAAW,CAAC,CAAC;AAC1D,MAAM,OAAO,GAAG,IAAA,gBAAS,EAAoB,cAAW,CAAC,CAAC;AAE1D,MAAM,SAAS,GAAW,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,UAAU;AAEvD,MAAa,mBAAmB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E;gBACxD,EAAE,EAAE,SAAS;aACd,CAAC,CAAC;QACL,CAAC;KAAA;IAEY,MAAM,CAAC,GAAW;;YAC7B,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC7B,CAAC;KAAA;CACF;AAzCD,kDAyCC"}
|
package/dist/index.js
CHANGED
|
@@ -49,9 +49,9 @@ function start(adapter, port = settingsPort) {
|
|
|
49
49
|
app.post("/events/connected", controller.handleConnectedEvent);
|
|
50
50
|
app.get("/health", controller.getHealth);
|
|
51
51
|
app.get("/oauth2/redirect", controller.oAuth2Redirect);
|
|
52
|
-
app.get("/oauth2/callback",
|
|
52
|
+
app.get("/oauth2/callback", controller.oAuth2Callback);
|
|
53
53
|
app.use(middlewares_1.errorHandlerMiddleware);
|
|
54
|
-
return app.listen(port, () => console.log(`Listening on port ${port}`));
|
|
54
|
+
return app.listen(port, () => console.log(`Listening on port ${port}`));
|
|
55
55
|
}
|
|
56
56
|
exports.start = start;
|
|
57
57
|
__exportStar(require("./models"), exports);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,8DAAqC;AACrC,8DAAsC;AACtC,gDAAwB;AACxB,sDAA8B;AAE9B,+CAAgF;AAChF,qCAA+C;AAC/C,gEAA2D;AAE3D,MAAM,YAAY,GAAW,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC;AAE9D,MAAM,GAAG,GAAwB,IAAA,iBAAO,GAAE,CAAC;AAE3C,GAAG,CAAC,GAAG,CAAC,IAAA,qBAAW,GAAE,CAAC,CAAC;AACvB,GAAG,CAAC,GAAG,CACL,IAAA,cAAI,EAAC;IACH,WAAW,EAAE,IAAI;IACjB,MAAM,EAAE,IAAI;CACb,CAAC,CACH,CAAC;AACF,GAAG,CAAC,GAAG,CA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CAAC,GAAG,CAAC,eAAe,EAAE,UAAU,CAAC,mBAAmB,CAAC,CAAC;IACzD,GAAG,CAAC,MAAM,CAAC,eAAe,EAAE,UAAU,CAAC,mBAAmB,CAAC,CAAC;IAC5D,GAAG,CAAC,IAAI,CAAC,eAAe,EAAE,UAAU,CAAC,eAAe,CAAC,CAAC;IACtD,GAAG,CAAC,IAAI,CAAC,mBAAmB,EAAE,UAAU,CAAC,oBAAoB,CAAC,CAAC;IAC/D,GAAG,CAAC,GAAG,CAAC,SAAS,EAAE,UAAU,CAAC,SAAS,CAAC,CAAC;IACzC,GAAG,CAAC,GAAG,CAAC,kBAAkB,EAAE,UAAU,CAAC,cAAc,CAAC,CAAC;IACvD,GAAG,CAAC,GAAG,CAAC,kBAAkB,EAAE,UAAU,CAAC,cAAc,CAAC,CAAC;IAEvD,GAAG,CAAC,GAAG,CAAC,oCAAsB,CAAC,CAAC;IAEhC,OAAO,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,qBAAqB,IAAI,EAAE,CAAC,CAAC,CAAC;AAC1E,CAAC;AAtBD,sBAsBC;AAED,2CAAyB"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.convertPhoneNumberToE164 = void 0;
|
|
4
|
-
const
|
|
5
|
-
const phoneUtil = google_libphonenumber_1.PhoneNumberUtil.getInstance();
|
|
4
|
+
const awesome_phonenumber_1 = require("awesome-phonenumber");
|
|
6
5
|
function convertPhoneNumberToE164(phoneNumber, locale) {
|
|
7
6
|
const region = locale.replace(/.+_/, "").toUpperCase();
|
|
8
7
|
try {
|
|
9
|
-
const parsedPhoneNumber =
|
|
10
|
-
|
|
8
|
+
const parsedPhoneNumber = (0, awesome_phonenumber_1.parsePhoneNumber)(phoneNumber, region);
|
|
9
|
+
const e164 = parsedPhoneNumber.getNumber("e164");
|
|
10
|
+
return e164 !== null && e164 !== void 0 ? e164 : phoneNumber;
|
|
11
11
|
}
|
|
12
12
|
catch (_a) {
|
|
13
13
|
return phoneNumber;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"phone-number-utils.js","sourceRoot":"","sources":["../../src/util/phone-number-utils.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"phone-number-utils.js","sourceRoot":"","sources":["../../src/util/phone-number-utils.ts"],"names":[],"mappings":";;;AAAA,6DAAuD;AAEvD,SAAgB,wBAAwB,CACtC,WAAmB,EACnB,MAAc;IAEd,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;IAEvD,IAAI;QACF,MAAM,iBAAiB,GAAG,IAAA,sCAAgB,EAAC,WAAW,EAAE,MAAM,CAAC,CAAC;QAChE,MAAM,IAAI,GAAG,iBAAiB,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACjD,OAAO,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,WAAW,CAAC;KAC5B;IAAC,WAAM;QACN,OAAO,WAAW,CAAC;KACpB;AACH,CAAC;AAbD,4DAaC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sipgate/integration-bridge",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "sipgate Integration Bridge Framework",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -60,8 +60,6 @@
|
|
|
60
60
|
"@types/compression": "1.7.2",
|
|
61
61
|
"@types/cors": "2.8.12",
|
|
62
62
|
"@types/express": "4.17.13",
|
|
63
|
-
"@types/get-port": "4.2.0",
|
|
64
|
-
"@types/google-libphonenumber": "7.4.23",
|
|
65
63
|
"@types/jest": "28.1.6",
|
|
66
64
|
"@types/lru-cache": "7.10.9",
|
|
67
65
|
"@types/node": "18.0.6",
|
|
@@ -77,12 +75,12 @@
|
|
|
77
75
|
},
|
|
78
76
|
"dependencies": {
|
|
79
77
|
"ajv": "^8.11.0",
|
|
78
|
+
"awesome-phonenumber": "^3.2.0",
|
|
80
79
|
"axios": "^0.27.2",
|
|
81
80
|
"body-parser": "^1.20.0",
|
|
82
81
|
"compression": "^1.7.4",
|
|
83
82
|
"cors": "^2.8.5",
|
|
84
83
|
"express": "^4.18.1",
|
|
85
|
-
"google-libphonenumber": "^3.2.29",
|
|
86
84
|
"lru-cache": "^7.13.1",
|
|
87
85
|
"redis": "^4.2.0"
|
|
88
86
|
}
|