@sipgate/integration-bridge 0.22.2 → 0.22.5

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 (67) hide show
  1. package/dist/cache/storage/memory-storage-adapter.d.ts +1 -1
  2. package/dist/cache/storage/memory-storage-adapter.js +2 -2
  3. package/dist/cache/storage/memory-storage-adapter.js.map +1 -1
  4. package/dist/cache/storage-cache.d.ts +12 -0
  5. package/dist/cache/storage-cache.js +67 -19
  6. package/dist/cache/storage-cache.js.map +1 -1
  7. package/dist/index.d.ts +4 -2
  8. package/dist/index.js +11 -10
  9. package/dist/index.js.map +1 -1
  10. package/dist/models/controller.model.js +2 -2
  11. package/dist/models/controller.model.js.map +1 -1
  12. package/dist/models/index.d.ts +1 -0
  13. package/dist/models/index.js +1 -0
  14. package/dist/models/index.js.map +1 -1
  15. package/dist/models/token-cache.model.d.ts +6 -0
  16. package/dist/models/token-cache.model.js +3 -0
  17. package/dist/models/token-cache.model.js.map +1 -0
  18. package/dist/models/token.model.d.ts +7 -0
  19. package/dist/models/token.model.js +3 -0
  20. package/dist/models/token.model.js.map +1 -0
  21. package/dist/util/call-comment.js.map +1 -1
  22. package/dist/util/callEventHelper.d.ts +7 -0
  23. package/dist/util/callEventHelper.js +37 -0
  24. package/dist/util/callEventHelper.js.map +1 -0
  25. package/dist/util/env.d.ts +14 -0
  26. package/dist/util/env.js +73 -1
  27. package/dist/util/env.js.map +1 -1
  28. package/dist/util/gdpr/gdprSlackNotification.d.ts +4 -0
  29. package/dist/util/gdpr/gdprSlackNotification.js +79 -0
  30. package/dist/util/gdpr/gdprSlackNotification.js.map +1 -0
  31. package/dist/util/gdpr/index.d.ts +3 -0
  32. package/dist/util/gdpr/index.js +33 -0
  33. package/dist/util/gdpr/index.js.map +1 -0
  34. package/dist/util/http/index.d.ts +7 -0
  35. package/dist/util/http/index.js +39 -0
  36. package/dist/util/http/index.js.map +1 -0
  37. package/dist/util/http/pagination.d.ts +7 -0
  38. package/dist/util/http/pagination.js +56 -0
  39. package/dist/util/http/pagination.js.map +1 -0
  40. package/dist/util/http/rate-limited-axios.d.ts +13 -0
  41. package/dist/util/http/rate-limited-axios.js +79 -0
  42. package/dist/util/http/rate-limited-axios.js.map +1 -0
  43. package/dist/util/http/url.d.ts +1 -0
  44. package/dist/util/http/url.js +14 -0
  45. package/dist/util/http/url.js.map +1 -0
  46. package/dist/util/index.d.ts +14 -0
  47. package/dist/util/index.js +32 -0
  48. package/dist/util/index.js.map +1 -1
  49. package/dist/util/lang/diff.d.ts +8 -0
  50. package/dist/util/lang/diff.js +80 -0
  51. package/dist/util/lang/diff.js.map +1 -0
  52. package/dist/util/lang/index.d.ts +2 -0
  53. package/dist/util/lang/index.js +6 -0
  54. package/dist/util/lang/index.js.map +1 -0
  55. package/dist/util/oauth.d.ts +32 -0
  56. package/dist/util/oauth.js +167 -0
  57. package/dist/util/oauth.js.map +1 -0
  58. package/dist/util/security/index.d.ts +3 -0
  59. package/dist/util/security/index.js +33 -0
  60. package/dist/util/security/index.js.map +1 -0
  61. package/dist/util/security/nonce.d.ts +5 -0
  62. package/dist/util/security/nonce.js +49 -0
  63. package/dist/util/security/nonce.js.map +1 -0
  64. package/dist/util/token-util.d.ts +6 -0
  65. package/dist/util/token-util.js +66 -0
  66. package/dist/util/token-util.js.map +1 -0
  67. package/package.json +9 -2
@@ -1 +1,15 @@
1
1
  export declare function isProduction(): boolean;
2
+ export interface APIConfig {
3
+ API_URL: string;
4
+ }
5
+ export declare const parseEnvironment: () => APIConfig;
6
+ export interface OAuth2Options {
7
+ APP_ID: string;
8
+ APP_SECRET: string;
9
+ APP_REDIRECT_URL: string;
10
+ NONCE_COOKIE_NAME: string;
11
+ API_URL: string;
12
+ APP_AUTHORIZE_URL: string;
13
+ APP_ACCESSTOKEN_URL: string;
14
+ }
15
+ export declare const parseOAuthOptionFromEnvironment: () => OAuth2Options;
package/dist/util/env.js CHANGED
@@ -1,8 +1,80 @@
1
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
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isProduction = void 0;
26
+ exports.parseOAuthOptionFromEnvironment = exports.parseEnvironment = exports.isProduction = void 0;
27
+ const dotenv = __importStar(require("dotenv"));
4
28
  function isProduction() {
5
29
  return process.env.NODE_ENV === "production";
6
30
  }
7
31
  exports.isProduction = isProduction;
32
+ const parseEnvironment = () => {
33
+ if (process.env.NODE_ENV === "development")
34
+ dotenv.config();
35
+ const { API_URL } = process.env;
36
+ if (!API_URL) {
37
+ throw new Error("Missing API_URL in environment.");
38
+ }
39
+ return {
40
+ API_URL,
41
+ };
42
+ };
43
+ exports.parseEnvironment = parseEnvironment;
44
+ const DEFAULT_COOKIE_NAME = "oauth_nonce";
45
+ const parseOAuthOptionFromEnvironment = () => {
46
+ if (process.env.NODE_ENV === "development")
47
+ dotenv.config();
48
+ const { APP_ID, APP_SECRET, APP_REDIRECT_URL, API_URL, APP_AUTHORIZE_URL, APP_ACCESSTOKEN_URL, NONCE_COOKIE_NAME, } = process.env;
49
+ if (!APP_ID) {
50
+ throw new Error("Missing APP_ID in environment.");
51
+ }
52
+ if (!APP_SECRET) {
53
+ throw new Error("Missing APP_SECRET in environment.");
54
+ }
55
+ if (!APP_REDIRECT_URL) {
56
+ throw new Error("Missing APP_REDIRECT_URL in environment.");
57
+ }
58
+ if (!API_URL) {
59
+ throw new Error("Missing API_URL in environment.");
60
+ }
61
+ if (!APP_AUTHORIZE_URL) {
62
+ throw new Error("Missing APP_AUTHORIZE_URL in environment.");
63
+ }
64
+ if (!APP_ACCESSTOKEN_URL) {
65
+ throw new Error("Missing APP_ACCESSTOKEN_URL in environment.");
66
+ }
67
+ return {
68
+ APP_ID,
69
+ APP_SECRET,
70
+ APP_REDIRECT_URL,
71
+ API_URL,
72
+ APP_AUTHORIZE_URL,
73
+ APP_ACCESSTOKEN_URL,
74
+ NONCE_COOKIE_NAME: NONCE_COOKIE_NAME
75
+ ? NONCE_COOKIE_NAME
76
+ : DEFAULT_COOKIE_NAME,
77
+ };
78
+ };
79
+ exports.parseOAuthOptionFromEnvironment = parseOAuthOptionFromEnvironment;
8
80
  //# sourceMappingURL=env.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"env.js","sourceRoot":"","sources":["../../src/util/env.ts"],"names":[],"mappings":";;;AAAA,SAAgB,YAAY;IAC1B,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAC;AAC/C,CAAC;AAFD,oCAEC"}
1
+ {"version":3,"file":"env.js","sourceRoot":"","sources":["../../src/util/env.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAiC;AAEjC,SAAgB,YAAY;IAC1B,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAC;AAC/C,CAAC;AAFD,oCAEC;AAMM,MAAM,gBAAgB,GAAG,GAAc,EAAE;IAC9C,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,K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C,CAAC,iBAAiB;YACnB,CAAC,CAAC,mBAAmB;KACxB,CAAC;AACJ,CAAC,CAAC;AA1CW,QAAA,+BAA+B,mCA0C1C"}
@@ -0,0 +1,4 @@
1
+ import { Router } from "express";
2
+ import { CustomRouter } from "../../models/custom-router.model";
3
+ export declare function slackNotificationRoute(slackWebhookUrl: string, path: string): Router;
4
+ export declare function getGDPRSlackNotificationRouter(slackWebhookUrl: string): CustomRouter[];
@@ -0,0 +1,79 @@
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
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.getGDPRSlackNotificationRouter = exports.slackNotificationRoute = void 0;
36
+ const express_1 = require("express");
37
+ const util = __importStar(require("util"));
38
+ const webhook_1 = require("@slack/webhook");
39
+ const models_1 = require("../../models");
40
+ function slackNotificationRoute(slackWebhookUrl, path) {
41
+ const route = (0, express_1.Router)();
42
+ route.post(path, (req, res) => __awaiter(this, void 0, void 0, function* () {
43
+ try {
44
+ const payloadStringified = JSON.stringify(req.body, null, 4);
45
+ const host = req.headers.host;
46
+ const message = `GDPR request: host ${host}, path ${path}\nRequest Payload:\n ${payloadStringified}`;
47
+ console.log(message);
48
+ const webhook = new webhook_1.IncomingWebhook(slackWebhookUrl);
49
+ yield webhook.send({ text: message });
50
+ res.send();
51
+ }
52
+ catch (error) {
53
+ const errorMessage = `Error in ${path}: ${util.inspect(error)}`;
54
+ console.error(errorMessage);
55
+ throw new models_1.ServerError(500, errorMessage);
56
+ }
57
+ }));
58
+ return route;
59
+ }
60
+ exports.slackNotificationRoute = slackNotificationRoute;
61
+ function getGDPRSlackNotificationRouter(slackWebhookUrl) {
62
+ const gdprRouter = [
63
+ {
64
+ path: "/gdpr/",
65
+ router: slackNotificationRoute(slackWebhookUrl, "/customers/data_request/"),
66
+ },
67
+ {
68
+ path: "/gdpr/",
69
+ router: slackNotificationRoute(slackWebhookUrl, "/customers/redact/"),
70
+ },
71
+ {
72
+ path: "/gdpr/",
73
+ router: slackNotificationRoute(slackWebhookUrl, "/shop/redact/"),
74
+ },
75
+ ];
76
+ return gdprRouter;
77
+ }
78
+ exports.getGDPRSlackNotificationRouter = getGDPRSlackNotificationRouter;
79
+ //# sourceMappingURL=gdprSlackNotification.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gdprSlackNotification.js","sourceRoot":"","sources":["../../../src/util/gdpr/gdprSlackNotification.ts"],"names":[],"mappings":";;;;;;;;;;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I,EAAE,QAAQ;YACd,MAAM,EAAE,sBAAsB,CAAC,eAAe,EAAE,oBAAoB,CAAC;SACtE;QACD;YACE,IAAI,EAAE,QAAQ;YACd,MAAM,EAAE,sBAAsB,CAAC,eAAe,EAAE,eAAe,CAAC;SACjE;KACF,CAAC;IACF,OAAO,UAAU,CAAC;AACpB,CAAC;AArBD,wEAqBC"}
@@ -0,0 +1,3 @@
1
+ import * as GDPRSlackNotification from "./gdprSlackNotification";
2
+ export { GDPRSlackNotification };
3
+ export * from "./gdprSlackNotification";
@@ -0,0 +1,33 @@
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
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.GDPRSlackNotification = void 0;
30
+ const GDPRSlackNotification = __importStar(require("./gdprSlackNotification"));
31
+ exports.GDPRSlackNotification = GDPRSlackNotification;
32
+ __exportStar(require("./gdprSlackNotification"), exports);
33
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/util/gdpr/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+EAAiE;AAExD,sDAAqB;AAE9B,0DAAwC"}
@@ -0,0 +1,7 @@
1
+ import * as Pagination from "./pagination";
2
+ import { RateLimitedAxios } from "./rate-limited-axios";
3
+ import { getSubdomain } from "./url";
4
+ export { Pagination, RateLimitedAxios, getSubdomain };
5
+ export * from "./pagination";
6
+ export * from "./rate-limited-axios";
7
+ export * from "./url";
@@ -0,0 +1,39 @@
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
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.getSubdomain = exports.RateLimitedAxios = exports.Pagination = void 0;
30
+ const Pagination = __importStar(require("./pagination"));
31
+ exports.Pagination = Pagination;
32
+ const rate_limited_axios_1 = require("./rate-limited-axios");
33
+ Object.defineProperty(exports, "RateLimitedAxios", { enumerable: true, get: function () { return rate_limited_axios_1.RateLimitedAxios; } });
34
+ const url_1 = require("./url");
35
+ Object.defineProperty(exports, "getSubdomain", { enumerable: true, get: function () { return url_1.getSubdomain; } });
36
+ __exportStar(require("./pagination"), exports);
37
+ __exportStar(require("./rate-limited-axios"), exports);
38
+ __exportStar(require("./url"), exports);
39
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/util/http/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yDAA2C;AAIlC,gCAAU;AAHnB,6DAAwD;AAGnC,iGAHZ,qCAAgB,OAGY;AAFrC,+BAAqC;AAEE,6FAF9B,kBAAY,OAE8B;AAEnD,+CAA6B;AAC7B,uDAAqC;AACrC,wCAAsB"}
@@ -0,0 +1,7 @@
1
+ import { AxiosResponse } from "axios";
2
+ export type MergeDataFn<T> = (data: T, newData: T) => T;
3
+ export type ExtractDataFromResponseFn<T> = (response: AxiosResponse) => T;
4
+ export type IsEofFn<T> = (response: AxiosResponse, data: T) => boolean;
5
+ export type RetryOnError = (exception: any) => Promise<boolean>;
6
+ export type InvokeNextRequestFn<T> = (previousResponse: AxiosResponse | undefined, data: T) => Promise<AxiosResponse>;
7
+ export declare function paginate<T>(mergeData: MergeDataFn<T>, extractDataFromResponse: ExtractDataFromResponseFn<T>, isEof: IsEofFn<T>, invokeNextRequest: InvokeNextRequestFn<T>, delayMs: number, initialData: T, retryOnError?: RetryOnError): Promise<T>;
@@ -0,0 +1,56 @@
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.paginate = void 0;
13
+ function sleep(ms) {
14
+ return __awaiter(this, void 0, void 0, function* () {
15
+ return new Promise((resolve, reject) => setTimeout(() => resolve(undefined), ms || 0));
16
+ });
17
+ }
18
+ function paginate(mergeData, extractDataFromResponse, isEof, invokeNextRequest, delayMs, initialData, retryOnError) {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ const paginateId = Math.floor(Math.random() * 100000);
21
+ return new Promise((resolve, reject) => {
22
+ const fetchNextPage = (data, previousResponse) => __awaiter(this, void 0, void 0, function* () {
23
+ try {
24
+ if (previousResponse) {
25
+ yield sleep(delayMs);
26
+ }
27
+ const response = yield invokeNextRequest(previousResponse, data);
28
+ const responseData = extractDataFromResponse(response);
29
+ const allData = mergeData(data, responseData);
30
+ if (!isEof(response, allData)) {
31
+ setImmediate(() => fetchNextPage(allData, response));
32
+ }
33
+ else {
34
+ resolve(allData);
35
+ }
36
+ }
37
+ catch (e) {
38
+ if (retryOnError && (yield retryOnError(e))) {
39
+ setImmediate(() => fetchNextPage(data, previousResponse));
40
+ }
41
+ else {
42
+ console.error("[paginate] Error during pagination", `${e}`);
43
+ reject(e);
44
+ }
45
+ }
46
+ });
47
+ console.log(`[paginate] ${paginateId} start`);
48
+ return fetchNextPage(initialData);
49
+ }).then((resultData) => {
50
+ console.log(`[paginate] ${paginateId} end`);
51
+ return resultData;
52
+ });
53
+ });
54
+ }
55
+ exports.paginate = paginate;
56
+ //# sourceMappingURL=p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AAC,MAAM,YAAY,CAAC,CAAC,CAAC,CAAC,EAAE;wBAC3C,YAAY,CAAC,GAAG,EAAE,CAAC,aAAa,CAAC,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC;qBAC3D;yBAAM;wBACL,OAAO,CAAC,KAAK,CAAC,oCAAoC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;wBAC5D,MAAM,CAAC,CAAC,CAAC,CAAC;qBACX;iBACF;YACH,CAAC,CAAA,CAAC;YAEF,OAAO,CAAC,GAAG,CAAC,cAAc,UAAU,QAAQ,CAAC,CAAC;YAC9C,OAAO,aAAa,CAAC,WAAW,CAAC,CAAC;QACpC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,UAAa,EAAK,EAAE;YAC3B,OAAO,CAAC,GAAG,CAAC,cAAc,UAAU,MAAM,CAAC,CAAC;YAE5C,OAAO,UAAU,CAAC;QACpB,CAAC,CAAC,CAAC;IACL,CAAC;CAAA;AA5CD,4BA4CC"}
@@ -0,0 +1,13 @@
1
+ import { AxiosRequestConfig, AxiosResponse } from "axios";
2
+ import { RateLimiterMemory } from "rate-limiter-flexible";
3
+ export declare class RateLimitedAxios {
4
+ rateLimiter: RateLimiterMemory;
5
+ enableLogging: boolean;
6
+ constructor(allowedCalls: number, intervall: number, enableLogging?: boolean);
7
+ checkRateLimitAndWait(key?: string): Promise<void>;
8
+ get<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>, key?: string): Promise<R>;
9
+ delete<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>, key?: string): Promise<R>;
10
+ post<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>, key?: string): Promise<R>;
11
+ put<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>, key?: string): Promise<R>;
12
+ patch<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>, key?: string): Promise<R>;
13
+ }
@@ -0,0 +1,79 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.RateLimitedAxios = void 0;
16
+ const axios_1 = __importDefault(require("axios"));
17
+ const rate_limiter_flexible_1 = require("rate-limiter-flexible");
18
+ const logger_util_1 = require("../logger.util");
19
+ const DEFAULT_KEY = "DEFAULT_KEY";
20
+ class RateLimitedAxios {
21
+ constructor(allowedCalls, intervall, enableLogging = false) {
22
+ this.rateLimiter = new rate_limiter_flexible_1.RateLimiterMemory({
23
+ points: allowedCalls,
24
+ duration: intervall,
25
+ });
26
+ this.enableLogging = enableLogging;
27
+ }
28
+ checkRateLimitAndWait(key) {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ try {
31
+ if (key)
32
+ yield this.rateLimiter.consume(key, 1);
33
+ else
34
+ yield this.rateLimiter.consume(DEFAULT_KEY, 1);
35
+ }
36
+ catch (rateLimiterRes) {
37
+ if (this.enableLogging) {
38
+ (0, logger_util_1.infoLogger)("checkRateLimitAndWait", `Waiting ${rateLimiterRes.msBeforeNext} to respect rate limit`, key ? key : "");
39
+ }
40
+ yield new Promise((resolve) => {
41
+ setTimeout(resolve, rateLimiterRes.msBeforeNext);
42
+ });
43
+ yield this.checkRateLimitAndWait(key);
44
+ }
45
+ });
46
+ }
47
+ get(url, config, key) {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ yield this.checkRateLimitAndWait(key);
50
+ return axios_1.default.get(url, config);
51
+ });
52
+ }
53
+ delete(url, config, key) {
54
+ return __awaiter(this, void 0, void 0, function* () {
55
+ yield this.checkRateLimitAndWait(key);
56
+ return axios_1.default.delete(url, config);
57
+ });
58
+ }
59
+ post(url, data, config, key) {
60
+ return __awaiter(this, void 0, void 0, function* () {
61
+ yield this.checkRateLimitAndWait(key);
62
+ return axios_1.default.post(url, data, config);
63
+ });
64
+ }
65
+ put(url, data, config, key) {
66
+ return __awaiter(this, void 0, void 0, function* () {
67
+ yield this.checkRateLimitAndWait(key);
68
+ return axios_1.default.put(url, data, config);
69
+ });
70
+ }
71
+ patch(url, data, config, key) {
72
+ return __awaiter(this, void 0, void 0, function* () {
73
+ yield this.checkRateLimitAndWait(key);
74
+ return axios_1.default.patch(url, data, config);
75
+ });
76
+ }
77
+ }
78
+ exports.RateLimitedAxios = RateLimitedAxios;
79
+ //# sourceMappingURL=rate-limited-axios.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rate-limited-axios.js","sourceRoot":"","sources":["../../../src/util/http/rate-limited-axios.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kDAAiE;AACjE,iEAA0D;AAC1D,gDAA4C;AAE5C,MAAM,WAAW,GAAG,aAAa,CAAC;AAElC,MAAa,gBAAgB;IAG3B,YACE,YAAoB,EACpB,SAAiB,EACjB,gBAAyB,KAAK;QAE9B,IAAI,CAAC,WAAW,GAAG,IAAI,yCAAiB,CAAC;YACvC,MAAM,EAAE,YAAY;YACpB,QAAQ,EAAE,SAAS;SACpB,CAAC,CAAC;QACH,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACrC,CAAC;IAEK,qBAAqB,CAAC,GAAY;;YACtC,IAAI;gBACF,IAAI,GAAG;oBAAE,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,GAAG,EAAE,C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,CAAC,GAAG,CAAC,CAAC;YACtC,OAAO,eAAK,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QACtC,CAAC;KAAA;IAEK,KAAK,CACT,GAAW,EACX,IAAQ,EACR,MAA8B,EAC9B,GAAY;;YAEZ,MAAM,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,CAAC;YACtC,OAAO,eAAK,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QACxC,CAAC;KAAA;CACF;AAjFD,4CAiFC"}
@@ -0,0 +1 @@
1
+ export declare function getSubdomain(url: string): string;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSubdomain = void 0;
4
+ function getSubdomain(url) {
5
+ // remove https protocol from url if exists
6
+ url = url.replace(/^(https?:\/\/)/, "");
7
+ const subdomain = url.split(".")[0];
8
+ if (subdomain)
9
+ return subdomain;
10
+ else
11
+ return url;
12
+ }
13
+ exports.getSubdomain = getSubdomain;
14
+ //# sourceMappingURL=url.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url.js","sourceRoot":"","sources":["../../../src/util/http/url.ts"],"names":[],"mappings":";;;AAAA,SAAgB,YAAY,CAAC,GAAW;IACtC,2CAA2C;IAC3C,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,gBAAgB,EAAE,EAAE,CAAC,CAAC;IACxC,MAAM,SAAS,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACpC,IAAI,SAAS;QAAE,OAAO,SAAS,CAAC;;QAC3B,OAAO,GAAG,CAAC;AAClB,CAAC;AAND,oCAMC"}
@@ -1,3 +1,9 @@
1
+ import * as Http from "./http";
2
+ import * as CallEventHelper from "./callEventHelper";
3
+ import * as Security from "./security";
4
+ import * as Lang from "./lang";
5
+ import * as GDPR from "./gdpr";
6
+ import * as OAuth from "./oauth";
1
7
  export * from "./anonymize-key";
2
8
  export * from "./call-comment";
3
9
  export * from "./env";
@@ -5,3 +11,11 @@ export * from "./error";
5
11
  export * from "./integration-entity";
6
12
  export * from "./logger.util";
7
13
  export * from "./phone-number-utils";
14
+ export * from "./http";
15
+ export * from "./callEventHelper";
16
+ export * from "./security";
17
+ export * from "./gdpr";
18
+ export * from "./oauth";
19
+ export * from "./env";
20
+ export { Http, CallEventHelper, Security, Lang, GDPR, OAuth };
21
+ export * from "./token-util";
@@ -10,10 +10,35 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
10
10
  if (k2 === undefined) k2 = k;
11
11
  o[k2] = m[k];
12
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
+ };
13
25
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
26
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
27
  };
16
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.OAuth = exports.GDPR = exports.Lang = exports.Security = exports.CallEventHelper = exports.Http = void 0;
30
+ const Http = __importStar(require("./http"));
31
+ exports.Http = Http;
32
+ const CallEventHelper = __importStar(require("./callEventHelper"));
33
+ exports.CallEventHelper = CallEventHelper;
34
+ const Security = __importStar(require("./security"));
35
+ exports.Security = Security;
36
+ const Lang = __importStar(require("./lang"));
37
+ exports.Lang = Lang;
38
+ const GDPR = __importStar(require("./gdpr"));
39
+ exports.GDPR = GDPR;
40
+ const OAuth = __importStar(require("./oauth"));
41
+ exports.OAuth = OAuth;
17
42
  __exportStar(require("./anonymize-key"), exports);
18
43
  __exportStar(require("./call-comment"), exports);
19
44
  __exportStar(require("./env"), exports);
@@ -21,4 +46,11 @@ __exportStar(require("./error"), exports);
21
46
  __exportStar(require("./integration-entity"), exports);
22
47
  __exportStar(require("./logger.util"), exports);
23
48
  __exportStar(require("./phone-number-utils"), exports);
49
+ __exportStar(require("./http"), exports);
50
+ __exportStar(require("./callEventHelper"), exports);
51
+ __exportStar(require("./security"), exports);
52
+ __exportStar(require("./gdpr"), exports);
53
+ __exportStar(require("./oauth"), exports);
54
+ __exportStar(require("./env"), exports);
55
+ __exportStar(require("./token-util"), exports);
24
56
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/util/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC;AAChC,iDAA+B;AAC/B,wCAAsB;AACtB,0CAAwB;AACxB,uDAAqC;AACrC,gDAA8B;AAC9B,uDAAqC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/util/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA+B;AAqBtB,oBAAI;AApBb,mEAAqD;AAoBtC,0CAAe;AAnB9B,qDAAuC;AAmBP,4BAAQ;AAlBxC,6CAA+B;AAkBW,oBAAI;AAjB9C,6CAA+B;AAiBiB,oBAAI;AAhBpD,+CAAiC;AAgBqB,sBAAK;AAd3D,kDAAgC;AAChC,iDAA+B;AAC/B,wCAAsB;AACtB,0CAAwB;AACxB,uDAAqC;AACrC,gDAA8B;AAC9B,uDAAqC;AACrC,yCAAuB;AACvB,oDAAkC;AAClC,6CAA2B;AAC3B,yCAAuB;AACvB,0CAAwB;AACxB,wCAAsB;AAGtB,+CAA6B"}
@@ -0,0 +1,8 @@
1
+ export type IdOf<T> = (x: T) => string;
2
+ export type Diff<X, Y> = {
3
+ distinctXs: X[];
4
+ distinctYs: Y[];
5
+ commonXs: X[];
6
+ commonYs: Y[];
7
+ };
8
+ export declare function diffArrays<X, Y>(idOfX: IdOf<X>, idOfY: IdOf<Y>, xs: X[], ys: Y[]): Diff<X, Y>;
@@ -0,0 +1,80 @@
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.diffArrays = void 0;
27
+ const fp = __importStar(require("lodash/fp"));
28
+ function byId(idOf, xs) {
29
+ return fp.reduce((byIds, x) => (Object.assign(Object.assign({}, byIds), { [idOf(x)]: x })), {}, xs);
30
+ }
31
+ function diffArrays(idOfX, idOfY, xs, ys) {
32
+ const xsByIds = byId(idOfX, xs);
33
+ const ysByIds = byId(idOfY, ys);
34
+ const xsIds = new Set(Object.keys(xsByIds));
35
+ const ysIds = new Set(Object.keys(ysByIds));
36
+ const allIds = new Set([...xsIds.keys(), ...ysIds.keys()]);
37
+ return fp.reduce(({ distinctXs, distinctYs, commonXs, commonYs }, id) => {
38
+ const inX = xsIds.has(id);
39
+ const inY = ysIds.has(id);
40
+ if (inX && inY) {
41
+ return {
42
+ distinctXs,
43
+ distinctYs,
44
+ commonXs: [...commonXs, xsByIds[id]],
45
+ commonYs: [...commonYs, ysByIds[id]],
46
+ };
47
+ }
48
+ else if (inX && !inY) {
49
+ return {
50
+ distinctXs: [...distinctXs, xsByIds[id]],
51
+ distinctYs,
52
+ commonXs,
53
+ commonYs,
54
+ };
55
+ }
56
+ else if (!inX && inY) {
57
+ return {
58
+ distinctXs,
59
+ distinctYs: [...distinctYs, ysByIds[id]],
60
+ commonXs,
61
+ commonYs,
62
+ };
63
+ }
64
+ else {
65
+ return {
66
+ distinctXs,
67
+ distinctYs,
68
+ commonXs,
69
+ commonYs,
70
+ };
71
+ }
72
+ }, {
73
+ distinctXs: [],
74
+ distinctYs: [],
75
+ commonXs: [],
76
+ commonYs: [],
77
+ }, Array.from(allIds));
78
+ }
79
+ exports.diffArrays = diffArrays;
80
+ //# sourceMappingURL=diff.js.map