@almaviacx/gge-toolkit-service 1.0.0

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.
@@ -0,0 +1 @@
1
+ export * as callReason from "./utils/callreason";
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.callReason = void 0;
4
+ exports.callReason = require("./utils/callreason");
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mDAAiD"}
@@ -0,0 +1,5 @@
1
+ import { Context as AlmContext } from "@almaviacx/twilio-toolkit-service";
2
+ export declare type Context = AlmContext & {
3
+ SYNCSERVICE_SID: string;
4
+ SYNC_CALL_MAP_SID: string;
5
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=Context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Context.js","sourceRoot":"","sources":["../../src/models/Context.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ export * from "./Context";
@@ -0,0 +1,18 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./Context"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B"}
@@ -0,0 +1,12 @@
1
+ import { Context } from "../models";
2
+ export declare const saveCallReason: (context: Context, attributes: {
3
+ request?: string | undefined;
4
+ from?: string | undefined;
5
+ to?: string | undefined;
6
+ }, from: string, to: string, callReason: string) => Promise<{
7
+ request?: string | undefined;
8
+ from?: string | undefined;
9
+ to?: string | undefined;
10
+ callReason: string;
11
+ }>;
12
+ export declare const getCallReason: (context: Context, from: string, to: string) => Promise<any>;
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (_) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ Object.defineProperty(exports, "__esModule", { value: true });
50
+ exports.getCallReason = exports.saveCallReason = void 0;
51
+ var getMapKey = function (from, to) {
52
+ return "".concat(from, "|").concat(to);
53
+ };
54
+ var saveCallReason = function (context, attributes, from, to, callReason) { return __awaiter(void 0, void 0, void 0, function () {
55
+ var logger, client, key, data, error_1;
56
+ return __generator(this, function (_a) {
57
+ switch (_a.label) {
58
+ case 0:
59
+ logger = context.logger;
60
+ client = context.getTwilioClient();
61
+ key = getMapKey(from, to);
62
+ data = __assign({ callReason: callReason }, attributes);
63
+ if (data.request) {
64
+ delete data.request;
65
+ }
66
+ if (data.from) {
67
+ delete data.from;
68
+ }
69
+ if (data.to) {
70
+ delete data.to;
71
+ }
72
+ logger.info("Save call reason for ".concat(key, " : ").concat(callReason));
73
+ _a.label = 1;
74
+ case 1:
75
+ _a.trys.push([1, 3, , 5]);
76
+ return [4 /*yield*/, client.sync.services(context.SYNCSERVICE_SID).syncMaps(context.SYNC_CALL_MAP_SID).syncMapItems(key).update({ data: data })];
77
+ case 2:
78
+ _a.sent();
79
+ return [3 /*break*/, 5];
80
+ case 3:
81
+ error_1 = _a.sent();
82
+ return [4 /*yield*/, client.sync.services(context.SYNCSERVICE_SID).syncMaps(context.SYNC_CALL_MAP_SID).syncMapItems.create({ key: key, data: data, ttl: 30 })];
83
+ case 4:
84
+ _a.sent();
85
+ return [3 /*break*/, 5];
86
+ case 5: return [2 /*return*/, data];
87
+ }
88
+ });
89
+ }); };
90
+ exports.saveCallReason = saveCallReason;
91
+ var getCallReason = function (context, from, to) { return __awaiter(void 0, void 0, void 0, function () {
92
+ var logger, client, key, result, error_2;
93
+ return __generator(this, function (_a) {
94
+ switch (_a.label) {
95
+ case 0:
96
+ logger = context.logger;
97
+ client = context.getTwilioClient();
98
+ key = getMapKey(from, to);
99
+ logger.info("Get call reason for ".concat(key));
100
+ _a.label = 1;
101
+ case 1:
102
+ _a.trys.push([1, 4, , 5]);
103
+ return [4 /*yield*/, client.sync.services(context.SYNCSERVICE_SID).syncMaps(context.SYNC_CALL_MAP_SID).syncMapItems(key).fetch()];
104
+ case 2:
105
+ result = _a.sent();
106
+ return [4 /*yield*/, client.sync.services(context.SYNCSERVICE_SID).syncMaps(context.SYNC_CALL_MAP_SID).syncMapItems(key).remove()];
107
+ case 3:
108
+ _a.sent();
109
+ logger.info(" => ", result.data);
110
+ return [2 /*return*/, result.data];
111
+ case 4:
112
+ error_2 = _a.sent();
113
+ logger.info(" => first");
114
+ return [2 /*return*/, { callReason: "first" }];
115
+ case 5: return [2 /*return*/];
116
+ }
117
+ });
118
+ }); };
119
+ exports.getCallReason = getCallReason;
120
+ //# sourceMappingURL=callreason.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"callreason.js","sourceRoot":"","sources":["../../src/utils/callreason.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,IAAM,SAAS,GAAG,UAAC,IAAY,EAAE,EAAU;IACzC,OAAO,UAAG,IAAI,cAAI,EAAE,CAAE,CAAC;AACzB,CAAC,CAAC;AAEK,IAAM,cAAc,GAAG,UAC5B,OAAgB,EAChB,UAA4D,EAC5D,IAAY,EACZ,EAAU,EACV,UAAkB;;;;;gBAEV,MAAM,GAAK,OAAO,OAAZ,CAAa;gBACrB,MAAM,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;gBACnC,GAAG,GAAG,SAAS,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;gBAC1B,IAAI,cAAK,UAAU,YAAA,IAAK,UAAU,CAAE,CAAC;gBAE3C,IAAI,IAAI,CAAC,OAAO,EAAE;oBAChB,OAAO,IAAI,CAAC,OAAO,CAAC;iBACrB;gBACD,IAAI,IAAI,CAAC,IAAI,EAAE;oBACb,OAAO,IAAI,CAAC,IAAI,CAAC;iBAClB;gBACD,IAAI,IAAI,CAAC,EAAE,EAAE;oBACX,OAAO,IAAI,CAAC,EAAE,CAAC;iBAChB;gBAED,MAAM,CAAC,IAAI,CAAC,+BAAwB,GAAG,gBAAM,UAAU,CAAE,CAAC,CAAC;;;;gBAGzD,qBAAM,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,MAAA,EAAE,CAAC,EAAA;;gBAA1H,SAA0H,CAAC;;;;gBAE3H,qBAAM,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,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
+ "name": "@almaviacx/gge-toolkit-service",
3
+ "version": "1.0.0",
4
+ "scripts": {
5
+ "prebuild": "rimraf dist",
6
+ "build": "tsc"
7
+ },
8
+ "devDependencies": {
9
+ "@types/randomstring": "^1.1.8",
10
+ "rimraf": "^3.0.2",
11
+ "typescript": "^4.7.4"
12
+ },
13
+ "description": "GGE Toolkit service",
14
+ "main": "dist/index.js",
15
+ "types": "dist/index.d.ts",
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "author": "Paulo De Carvalho <paulo.decarvalho@almaviacx.com> (https://www.almaviacx.com/)",
20
+ "license": "MIT",
21
+ "dependencies": {
22
+ "@almaviacx/twilio-toolkit-service": "file:../../almaviacx/twilio-toolkit-service",
23
+ "randomstring": "^1.2.2",
24
+ "winston": "^3.7.2"
25
+ }
26
+ }