@dawntech/dwntbots-services 0.0.16

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
+ # services
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Building
6
+
7
+ Run `nx build services` to build the library.
8
+
9
+ ## Running unit tests
10
+
11
+ Run `nx test services` to execute the unit tests via [Jest](https://jestjs.io).
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@dawntech/dwntbots-services",
3
+ "version": "0.0.16",
4
+ "type": "commonjs",
5
+ "exports": {
6
+ ".": {
7
+ "import": "./src/index.js",
8
+ "require": "./src/index.js",
9
+ "types": "./src/index.d.ts"
10
+ },
11
+ "./blip": {
12
+ "types": "./src/lib/blip/index.d.ts",
13
+ "import": "./src/lib/blip/index.js",
14
+ "require": "./src/lib/blip/index.js"
15
+ }
16
+ },
17
+ "main": "./src/index.js",
18
+ "types": "./src/index.d.ts",
19
+ "dependencies": {},
20
+ "peerDependencies": {
21
+ "rxjs": "7.6.0",
22
+ "@dwntbots/models": "0.0.1",
23
+ "lodash": "4.17.21",
24
+ "@dwntbots/utils": "0.0.1",
25
+ "@dwntbots/logger": "0.0.1",
26
+ "pino": "8.7.0",
27
+ "micromatch": "4.0.5",
28
+ "axios": "1.2.1",
29
+ "uuid": "9.0.0",
30
+ "tslib": "2.4.1"
31
+ }
32
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./lib/blip/";
package/src/index.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./lib/blip/"), exports);
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/services/src/index.ts"],"names":[],"mappings":";;;AAAA,sDAA4B"}
@@ -0,0 +1,19 @@
1
+ import { Subject } from "rxjs";
2
+ import { Vnd } from "@dwntbots/models/vnd";
3
+ import { PartiallyOptional } from "@dwntbots/utils/types";
4
+ import { BlipTransport, BlipTransportConfig } from "./BlipTransport";
5
+ export declare class BlipService {
6
+ private transport;
7
+ constructor(transport: BlipTransport);
8
+ static withHttp(BOT_URL: string, BOT_KEY: string, config?: Partial<BlipTransportConfig>): BlipService;
9
+ static withWs(ws$: Subject<Vnd.Lime.Transport.WS.Payload>, config?: Partial<BlipTransportConfig>): BlipService;
10
+ with(config?: Partial<BlipTransportConfig>): BlipService;
11
+ updateContact(contact: Partial<Vnd.Iris.Contact>, method: Vnd.Lime.Method): Promise<void>;
12
+ getBucket<T = any>(id: string): Promise<T>;
13
+ updateBucket<T extends Object>(id: string, resource: T): Promise<boolean>;
14
+ changeContactBot(contactIdentity: string, botIdentity: string): Promise<boolean>;
15
+ changeContactBotState(contactIdentity: string, botFlowId: string, botStateId?: string): Promise<boolean>;
16
+ sendMessage<T>(message: PartiallyOptional<Vnd.Lime.Message<T>, "id" | "to" | "from">): Promise<Vnd.Lime.Transport.Payload.Notification>;
17
+ sendMessageTemplate(contactIdentity: string, templateNamespace: string, templateName: string, templateParameters: any[]): Promise<boolean>;
18
+ }
19
+ export default BlipService;
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BlipService = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const vnd_1 = require("@dwntbots/models/vnd");
6
+ const logger_1 = require("@dwntbots/logger");
7
+ const BlipTransport_1 = require("./BlipTransport");
8
+ const logger = (0, logger_1.getLogger)("services/blip-service");
9
+ class BlipService {
10
+ constructor(transport) {
11
+ this.transport = transport;
12
+ }
13
+ static withHttp(BOT_URL, BOT_KEY, config) {
14
+ const transport = new BlipTransport_1.HttpTransport(BOT_URL, BOT_KEY, config);
15
+ return new BlipService(transport);
16
+ }
17
+ static withWs(ws$, config) {
18
+ const transport = new BlipTransport_1.WsTransport(ws$, config);
19
+ return new BlipService(transport);
20
+ }
21
+ with(config) {
22
+ return new BlipService(this.transport.with(config));
23
+ }
24
+ updateContact(contact, method) {
25
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
26
+ const request = {
27
+ method,
28
+ uri: "/contacts",
29
+ type: "application/vnd.lime.contact+json",
30
+ resource: Object.assign({}, contact),
31
+ };
32
+ return this.transport
33
+ .sendCommand(request)
34
+ .then((r) => r.resource)
35
+ .then((r) => console.log("contact-update", r, request));
36
+ });
37
+ }
38
+ getBucket(id) {
39
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
40
+ const request = {
41
+ method: vnd_1.Vnd.Lime.Method.GET,
42
+ uri: `/buckets/${id}`,
43
+ };
44
+ return this.transport.sendCommand(request).then((r) => {
45
+ return r.resource;
46
+ });
47
+ });
48
+ }
49
+ updateBucket(id, resource) {
50
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
51
+ const request = {
52
+ method: vnd_1.Vnd.Lime.Method.SET,
53
+ type: "application/json",
54
+ uri: `/buckets/${id}`,
55
+ resource,
56
+ };
57
+ return this.transport.sendCommand(request).then((r) => r.status === vnd_1.Vnd.Lime.Status.SUCCESS);
58
+ });
59
+ }
60
+ changeContactBot(contactIdentity, botIdentity) {
61
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
62
+ const request = {
63
+ method: vnd_1.Vnd.Lime.Method.SET,
64
+ uri: `/contexts/${contactIdentity}/master-state`,
65
+ resource: botIdentity,
66
+ type: "text/plain",
67
+ };
68
+ return this.transport
69
+ .sendCommand(request)
70
+ .then((r) => r.status === vnd_1.Vnd.Lime.Status.SUCCESS);
71
+ });
72
+ }
73
+ changeContactBotState(contactIdentity, botFlowId, botStateId = "onboarding") {
74
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
75
+ const request = {
76
+ method: vnd_1.Vnd.Lime.Method.SET,
77
+ uri: `/contexts/${contactIdentity}/stateid@${botFlowId}`,
78
+ resource: botStateId,
79
+ type: "text/plain",
80
+ };
81
+ return this.transport
82
+ .sendCommand(request)
83
+ .then((r) => r.status === vnd_1.Vnd.Lime.Status.SUCCESS);
84
+ });
85
+ }
86
+ sendMessage(message) {
87
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
88
+ return this.transport.sendMessage(message);
89
+ });
90
+ }
91
+ sendMessageTemplate(contactIdentity, templateNamespace, templateName, templateParameters) {
92
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
93
+ const wp = this.with({
94
+ to: contactIdentity,
95
+ });
96
+ const payload = {
97
+ type: "application/json",
98
+ content: {
99
+ type: "template",
100
+ template: {
101
+ namespace: templateNamespace,
102
+ name: templateName,
103
+ language: {
104
+ code: "pt_BR",
105
+ policy: "deterministic",
106
+ },
107
+ components: [
108
+ {
109
+ type: "body",
110
+ parameters: templateParameters,
111
+ },
112
+ ],
113
+ },
114
+ },
115
+ };
116
+ try {
117
+ const notification = yield wp.sendMessage(payload);
118
+ console.log({ notification });
119
+ return [vnd_1.Vnd.Lime.Event.RECEIVED, vnd_1.Vnd.Lime.Event.CONSUMED].includes(notification.event);
120
+ }
121
+ catch (error) {
122
+ logger.error(`Blip-service sendMessageTemplate error. Description: ${error.message}`);
123
+ return false;
124
+ }
125
+ });
126
+ }
127
+ }
128
+ exports.BlipService = BlipService;
129
+ exports.default = BlipService;
130
+ //# sourceMappingURL=BlipService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BlipService.js","sourceRoot":"","sources":["../../../../../../libs/services/src/lib/blip/BlipService.ts"],"names":[],"mappings":";;;;AACA,8CAA2C;AAC3C,6CAA6C;AAE7C,mDAKyB;AAEzB,MAAM,MAAM,GAAG,IAAA,kBAAS,EAAC,uBAAuB,CAAC,CAAC;AAElD,MAAa,WAAW;IACvB,YAAoB,SAAwB;QAAxB,cAAS,GAAT,SAAS,CAAe;IAAG,CAAC;IAEhD,MAAM,CAAC,QAAQ,CACd,OAAe,EACf,OAAe,EACf,MAAqC;QAEr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CAqJC;AAED,kBAAe,WAAW,CAAC"}
@@ -0,0 +1,59 @@
1
+ import { Subject } from "rxjs";
2
+ import { Vnd } from "@dwntbots/models/vnd";
3
+ export interface BlipTransportConfig {
4
+ to: string | null;
5
+ from: string | null;
6
+ base_uri: string;
7
+ echo: string | null;
8
+ }
9
+ export declare abstract class BlipTransport {
10
+ protected config: BlipTransportConfig;
11
+ constructor(config: BlipTransportConfig);
12
+ abstract with(config?: Partial<BlipTransportConfig>): BlipTransport;
13
+ abstract sendCommand<R = any, S = any>(command: Vnd.Lime.Transport.Payload.Request<S>): Promise<Vnd.Lime.Transport.Payload.Response<R>>;
14
+ abstract sendMessage<T = string>(message: Vnd.Lime.Transport.Payload.Message<T>): Promise<Vnd.Lime.Transport.Payload.Notification>;
15
+ abstract sendNotification(notification: Vnd.Lime.Transport.Payload.Notification): Promise<Vnd.Lime.Transport.Payload.Notification>;
16
+ }
17
+ export declare class HttpTransport extends BlipTransport {
18
+ private BOT_URL;
19
+ private BOT_KEY;
20
+ private http;
21
+ constructor(BOT_URL: string, BOT_KEY: string, _config?: Partial<BlipTransportConfig>);
22
+ static createRequest<R>(cmd: Vnd.Lime.Transport.Payload.Request<R>): Vnd.Lime.Command.Request<any>;
23
+ static createError<S>(cmd: Vnd.Lime.Command.Response<S>): {
24
+ reason: Vnd.Lime.Reason;
25
+ info: Error;
26
+ } | null;
27
+ with(config?: BlipTransportConfig): HttpTransport;
28
+ sendCommand<R = any, S = any>(command: Vnd.Lime.Transport.Payload.Request<S>): Promise<Vnd.Lime.Command.Response<R>>;
29
+ static createErrorMessage<T>(msg: Vnd.Lime.Transport.HTTP.Message<T>): Vnd.Lime.Transport.HTTP.Notification;
30
+ getMessageNotification<T>(message: Vnd.Lime.Transport.HTTP.Message<T>, state?: Vnd.Lime.Event, interval?: number, timeout?: number): import("rxjs").Observable<{
31
+ message: Vnd.Lime.Transport.HTTP.Message<T>;
32
+ notification: Vnd.Lime.Transport.HTTP.Notification;
33
+ }>;
34
+ sendMessage<T = string>(message: Vnd.Lime.Transport.Payload.Message<T>): Promise<Vnd.Lime.Transport.Payload.Notification>;
35
+ sendNotification(notification: Vnd.Lime.Transport.Payload.Notification): Promise<Vnd.Lime.Transport.HTTP.Notification>;
36
+ }
37
+ export declare class WsTransport extends BlipTransport {
38
+ private ws$;
39
+ constructor(ws$: Subject<Vnd.Lime.Transport.WS.Payload>, _config?: Partial<BlipTransportConfig>);
40
+ static transposeChannel(channel: Vnd.Lime.Transport.WS.Channel): Vnd.Lime.Transport.WS.Channel;
41
+ static createErrorRequest(cmd: Vnd.Lime.Transport.WS.Request): Vnd.Lime.Transport.WS.Response;
42
+ static createErrorMessage<T>(msg: Vnd.Lime.Transport.WS.Message<T>): Vnd.Lime.Transport.WS.Notification;
43
+ static createEchoMessage<T>(msg: Vnd.Lime.Transport.WS.Message<T>): Vnd.Lime.Transport.WS.Message<T>;
44
+ static createNotification<T>(msg: Vnd.Lime.Transport.WS.Message<T>): Vnd.Lime.Transport.WS.Notification;
45
+ static matchRequest(ws$: Subject<Vnd.Lime.Transport.WS.Payload>, request: Vnd.Lime.Transport.WS.Request, timeout?: number): import("rxjs").Observable<{
46
+ request: Vnd.Lime.Transport.WS.Request<any>;
47
+ response: Vnd.Lime.Transport.WS.Response<any>;
48
+ }>;
49
+ static matchMessage<T>(ws$: Subject<Vnd.Lime.Transport.WS.Payload>, message: Vnd.Lime.Transport.WS.Message<T>, state?: Vnd.Lime.Event, timeout?: number): import("rxjs").Observable<{
50
+ message: Vnd.Lime.Transport.WS.Message<T>;
51
+ notification: Vnd.Lime.Transport.WS.Notification;
52
+ }>;
53
+ static filterByRequestUri(payload: Vnd.Lime.Transport.WS.Payload, uriPattern: string): boolean;
54
+ static filterByResponseUri(payload: Vnd.Lime.Transport.WS.Payload, uriPattern: string): boolean;
55
+ with(config?: BlipTransportConfig): WsTransport;
56
+ sendCommand<R = any, S = any>(command: Vnd.Lime.Transport.Payload.Request<S>): Promise<Vnd.Lime.Transport.Payload.Response<R>>;
57
+ sendMessage<T = string>(message: Vnd.Lime.Transport.Payload.Message<T>): Promise<Vnd.Lime.Transport.Payload.Notification>;
58
+ sendNotification(notification: Vnd.Lime.Transport.Payload.Notification): Promise<Vnd.Lime.Transport.Payload.Notification>;
59
+ }
@@ -0,0 +1,254 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WsTransport = exports.HttpTransport = exports.BlipTransport = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const axios_1 = require("axios");
6
+ const uuid_1 = require("uuid");
7
+ const rxjs_1 = require("rxjs");
8
+ const vnd_1 = require("@dwntbots/models/vnd");
9
+ const lodash_1 = require("lodash");
10
+ class BlipTransport {
11
+ constructor(config) {
12
+ this.config = config;
13
+ }
14
+ }
15
+ exports.BlipTransport = BlipTransport;
16
+ class HttpTransport extends BlipTransport {
17
+ constructor(BOT_URL, BOT_KEY, _config) {
18
+ const config = {
19
+ to: (0, lodash_1.get)(_config, "to", "postmaster@msging.net"),
20
+ from: (0, lodash_1.get)(_config, "from", null),
21
+ base_uri: (0, lodash_1.get)(_config, "base_uri", ""),
22
+ echo: (0, lodash_1.get)(_config, "echo", null),
23
+ };
24
+ super(config);
25
+ this.BOT_URL = BOT_URL;
26
+ this.BOT_KEY = BOT_KEY;
27
+ this.http = axios_1.default.create({
28
+ baseURL: BOT_URL,
29
+ headers: { Authorization: BOT_KEY },
30
+ });
31
+ this.http.interceptors.response.use((resp) => {
32
+ let { data } = resp;
33
+ const error = HttpTransport.createError(data);
34
+ return error ? Promise.reject(error) : resp;
35
+ }, (error) => Promise.reject(error));
36
+ }
37
+ static createRequest(cmd) {
38
+ cmd.id = cmd.id || (0, uuid_1.v4)();
39
+ return cmd;
40
+ }
41
+ static createError(cmd) {
42
+ let error = null;
43
+ if (cmd.status === vnd_1.Vnd.Lime.Status.FAILURE) {
44
+ const reason = cmd.reason || {
45
+ code: -1,
46
+ description: "Error not identied",
47
+ };
48
+ error = {
49
+ reason,
50
+ info: new Error(`Failed to process blip-http-request (${reason.code}) error: ${reason.description}`),
51
+ };
52
+ }
53
+ return error;
54
+ }
55
+ with(config) {
56
+ return new HttpTransport(this.BOT_URL, this.BOT_KEY, config);
57
+ }
58
+ sendCommand(command) {
59
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
60
+ const payload = Object.assign(Object.assign({}, command), { id: command.id || (0, uuid_1.v4)(), to: command.to || this.config.to || undefined, from: command.from || this.config.from || undefined, uri: [this.config.base_uri, command.uri].join("") });
61
+ return this.http
62
+ .post("/commands", payload)
63
+ .then((resp) => resp.data);
64
+ });
65
+ }
66
+ static createErrorMessage(msg) {
67
+ return {
68
+ id: msg.id,
69
+ to: msg.from || "",
70
+ from: msg.to,
71
+ event: vnd_1.Vnd.Lime.Event.FAILED,
72
+ reason: { code: 0, description: "Timeout" },
73
+ };
74
+ }
75
+ getMessageNotification(message, state = vnd_1.Vnd.Lime.Event.RECEIVED, interval = 2000, timeout = 20000) {
76
+ const notificationsPayload = {
77
+ id: (0, uuid_1.v4)(),
78
+ method: vnd_1.Vnd.Lime.Method.GET,
79
+ uri: `/notifications?id=${message.id}`,
80
+ };
81
+ const notification$ = (0, rxjs_1.defer)(() => this.http.post("/commands", notificationsPayload)).pipe((0, rxjs_1.map)((response) => {
82
+ var _a;
83
+ return (_a = response.data.resource) === null || _a === void 0 ? void 0 : _a.items;
84
+ }), (0, rxjs_1.tap)((items) => {
85
+ if (!items.some((n) => [vnd_1.Vnd.Lime.Event.FAILED, state].includes(n.event))) {
86
+ throw new Error("No final state found for message.");
87
+ }
88
+ }), (0, rxjs_1.retry)({ delay: interval }), (0, rxjs_1.map)((items) => items.find((n) => [vnd_1.Vnd.Lime.Event.FAILED, state].includes(n.event))));
89
+ const timeout$ = (0, rxjs_1.timer)(timeout).pipe((0, rxjs_1.map)(() => HttpTransport.createErrorMessage(message)));
90
+ return (0, rxjs_1.race)(timeout$, notification$).pipe((0, rxjs_1.map)((notification) => ({
91
+ message,
92
+ notification,
93
+ })), (0, rxjs_1.take)(1));
94
+ }
95
+ sendMessage(message) {
96
+ var _a;
97
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
98
+ const messageId = message.id || (0, uuid_1.v4)();
99
+ const to = message.to || this.config.to || undefined;
100
+ const messagePayload = Object.assign(Object.assign({}, message), { id: messageId, to: to, from: message.from || this.config.from || undefined });
101
+ yield this.http.post("/messages", messagePayload);
102
+ const notification$ = this.getMessageNotification(messagePayload);
103
+ const { notification } = yield (0, rxjs_1.firstValueFrom)(notification$);
104
+ if (notification.event === vnd_1.Vnd.Lime.Event.FAILED) {
105
+ throw new Error(`Blip-message failed. Error: ${(_a = notification.reason) === null || _a === void 0 ? void 0 : _a.description}`);
106
+ }
107
+ return notification;
108
+ });
109
+ }
110
+ sendNotification(notification) {
111
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
112
+ const payload = Object.assign(Object.assign({}, notification), { id: notification.id || (0, uuid_1.v4)(), to: notification.to || this.config.to || undefined, from: notification.from || this.config.from || undefined });
113
+ return this.http
114
+ .post("/notifications", payload)
115
+ .then(() => payload);
116
+ });
117
+ }
118
+ }
119
+ exports.HttpTransport = HttpTransport;
120
+ class WsTransport extends BlipTransport {
121
+ constructor(ws$, _config) {
122
+ const config = {
123
+ to: (0, lodash_1.get)(_config, "to", "postmaster@msging.net"),
124
+ from: (0, lodash_1.get)(_config, "from", null),
125
+ base_uri: (0, lodash_1.get)(_config, "base_uri", ""),
126
+ echo: (0, lodash_1.get)(_config, "echo", null),
127
+ };
128
+ super(config);
129
+ this.ws$ = ws$;
130
+ }
131
+ static transposeChannel(channel) {
132
+ return channel === vnd_1.Vnd.Lime.Transport.WS.Channel.PULL
133
+ ? vnd_1.Vnd.Lime.Transport.WS.Channel.PUSH
134
+ : vnd_1.Vnd.Lime.Transport.WS.Channel.PULL;
135
+ }
136
+ static createErrorRequest(cmd) {
137
+ return {
138
+ id: cmd.id,
139
+ to: cmd.from || "",
140
+ from: cmd.to,
141
+ method: cmd.method,
142
+ channel: WsTransport.transposeChannel(cmd.channel),
143
+ status: vnd_1.Vnd.Lime.Status.FAILURE,
144
+ reason: { code: 0, description: "timeout" },
145
+ metadata: {
146
+ "#command.uri": cmd.uri,
147
+ },
148
+ };
149
+ }
150
+ static createErrorMessage(msg) {
151
+ return {
152
+ id: msg.id,
153
+ to: msg.from || "",
154
+ from: msg.to,
155
+ channel: WsTransport.transposeChannel(msg.channel),
156
+ event: vnd_1.Vnd.Lime.Event.FAILED,
157
+ reason: { code: 0, description: "timeout" },
158
+ metadata: {},
159
+ };
160
+ }
161
+ static createEchoMessage(msg) {
162
+ if (!(0, lodash_1.has)(msg, "from")) {
163
+ throw new Error("Echo message must have 'from'");
164
+ }
165
+ return Object.assign(Object.assign({}, msg), { to: msg.from, from: msg.to, channel: WsTransport.transposeChannel(msg.channel), metadata: Object.assign(Object.assign({}, msg.metadata), { "#message.echo": "true", date_created: String(new Date().getTime()) }) });
166
+ }
167
+ static createNotification(msg) {
168
+ return {
169
+ id: msg.id,
170
+ to: msg.from || "",
171
+ from: msg.to,
172
+ channel: WsTransport.transposeChannel(msg.channel),
173
+ event: vnd_1.Vnd.Lime.Event.RECEIVED,
174
+ reason: { code: 0, description: "timeout" },
175
+ metadata: {},
176
+ };
177
+ }
178
+ static matchRequest(ws$, request, timeout = 5000) {
179
+ const timeout$ = (0, rxjs_1.timer)(timeout).pipe((0, rxjs_1.map)(() => WsTransport.createErrorRequest(request)));
180
+ const response$ = ws$.pipe((0, rxjs_1.filter)((c) => c.id === request.id && vnd_1.Vnd.Lime.Transport.WS.isResponse(c)), (0, rxjs_1.map)((c) => c));
181
+ return (0, rxjs_1.race)(timeout$, response$).pipe((0, rxjs_1.map)((response) => ({
182
+ request,
183
+ response,
184
+ })), (0, rxjs_1.take)(1));
185
+ }
186
+ static matchMessage(ws$, message, state = vnd_1.Vnd.Lime.Event.RECEIVED, timeout = 5000) {
187
+ ws$.pipe((0, rxjs_1.filter)((c) => c.id === message.id &&
188
+ vnd_1.Vnd.Lime.Transport.WS.isNotification(c)), (0, rxjs_1.map)((c) => c), (0, rxjs_1.filter)((c) => c.event === vnd_1.Vnd.Lime.Event.ACCEPTED), (0, rxjs_1.take)(1)).subscribe((notification) => {
189
+ const timestamp = (0, lodash_1.get)(notification.metadata, "#envelope.timestamp");
190
+ if (timestamp) {
191
+ (0, lodash_1.set)(message, ["metadata", "date_created"], timestamp);
192
+ }
193
+ });
194
+ const timeout$ = (0, rxjs_1.timer)(timeout).pipe((0, rxjs_1.map)(() => WsTransport.createErrorMessage(message)));
195
+ const state$ = ws$.pipe((0, rxjs_1.filter)((c) => c.id === message.id &&
196
+ vnd_1.Vnd.Lime.Transport.WS.isNotification(c)), (0, rxjs_1.map)((c) => c), (0, rxjs_1.filter)((c) => c.event === vnd_1.Vnd.Lime.Event.FAILED || c.event === state));
197
+ return (0, rxjs_1.race)(timeout$, state$).pipe((0, rxjs_1.map)((notification) => ({
198
+ message,
199
+ notification,
200
+ })), (0, rxjs_1.take)(1));
201
+ }
202
+ static filterByRequestUri(payload, uriPattern) {
203
+ return Boolean(vnd_1.Vnd.Lime.Transport.WS.isRequest(payload) &&
204
+ payload.uri &&
205
+ new RegExp(uriPattern).test(payload.uri));
206
+ }
207
+ static filterByResponseUri(payload, uriPattern) {
208
+ return Boolean(vnd_1.Vnd.Lime.Transport.WS.isResponse(payload) &&
209
+ (0, lodash_1.has)(payload.metadata, "#command.uri") &&
210
+ new RegExp(`lime:\/\/.*${uriPattern}`).test(payload.metadata["#command.uri"]));
211
+ }
212
+ with(config) {
213
+ return new WsTransport(this.ws$, config);
214
+ }
215
+ sendCommand(command) {
216
+ var _a;
217
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
218
+ const payload = Object.assign(Object.assign({}, command), { id: command.id || (0, uuid_1.v4)(), to: command.to || this.config.to || undefined, from: command.from || this.config.from || undefined, uri: [this.config.base_uri, command.uri].join(""), channel: vnd_1.Vnd.Lime.Transport.WS.Channel.PUSH });
219
+ const req_resp$ = WsTransport.matchRequest(this.ws$, payload);
220
+ this.ws$.next(payload);
221
+ const { response } = yield (0, rxjs_1.firstValueFrom)(req_resp$);
222
+ if (response.status !== vnd_1.Vnd.Lime.Status.SUCCESS) {
223
+ throw Error(`Blip-command failed error: ${(_a = response.reason) === null || _a === void 0 ? void 0 : _a.description}`);
224
+ }
225
+ return response;
226
+ });
227
+ }
228
+ sendMessage(message) {
229
+ var _a;
230
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
231
+ const payload = Object.assign(Object.assign({}, message), { id: message.id || (0, uuid_1.v4)(), to: message.to || this.config.to || undefined, from: message.from || this.config.from || undefined, channel: vnd_1.Vnd.Lime.Transport.WS.Channel.PUSH });
232
+ const req_resp$ = WsTransport.matchMessage(this.ws$, payload);
233
+ this.ws$.next(payload);
234
+ const { notification } = yield (0, rxjs_1.firstValueFrom)(req_resp$);
235
+ if (notification.event === vnd_1.Vnd.Lime.Event.FAILED) {
236
+ throw Error(`Blip-message failed. Error: ${(_a = notification.reason) === null || _a === void 0 ? void 0 : _a.description}`);
237
+ }
238
+ if (this.config.echo) {
239
+ const echo = WsTransport.createEchoMessage(Object.assign(Object.assign({}, payload), { from: this.config.echo }));
240
+ this.ws$.next(echo);
241
+ }
242
+ return notification;
243
+ });
244
+ }
245
+ sendNotification(notification) {
246
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
247
+ const payload = Object.assign(Object.assign({}, notification), { id: notification.id || (0, uuid_1.v4)(), to: notification.to || this.config.to || undefined, from: notification.from || this.config.from || undefined, channel: vnd_1.Vnd.Lime.Transport.WS.Channel.PUSH });
248
+ this.ws$.next(payload);
249
+ return payload;
250
+ });
251
+ }
252
+ }
253
+ exports.WsTransport = WsTransport;
254
+ //# sourceMappingURL=BlipTransport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BlipTransport.js","sourceRoot":"","sources":["../../../../../../libs/services/src/lib/blip/BlipTransport.ts"],"names":[],"mappings":";;;;AAAA,iCAAoD;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AAqD;;YAErD,MAAM,OAAO,mCACT,YAAY,KACf,EAAE,EAAE,YAAY,CAAC,EAAE,IAAI,IAAA,SAAI,GAAE,EAC7B,EAAE,EAAE,YAAY,CAAC,EAAE,IAAI,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,SAAS,EAClD,IAAI,EAAE,YAAY,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,IAAI,SAAS,EACxD,OAAO,EAAE,SAAG,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,GAC3C,CAAC;YACF,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACvB,OAAO,OAAO,CAAC;QAChB,CAAC;KAAA;CACD;AAzPD,kCAyPC"}
@@ -0,0 +1,11 @@
1
+ import { Dwnt } from "@dwntbots/models";
2
+ export declare class ExtensionService {
3
+ private tenantId;
4
+ private botKey;
5
+ private extensionId;
6
+ private service;
7
+ constructor(tenantId: string, botKey: string, extensionId: string);
8
+ loadData(): Promise<Dwnt.Extension.Data>;
9
+ saveConfiguration(configuration: Dwnt.Extension.Configuration): Promise<Dwnt.Extension.Data>;
10
+ private getBotURL;
11
+ }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExtensionService = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const BlipService_1 = require("./BlipService");
6
+ class ExtensionService {
7
+ constructor(tenantId, botKey, extensionId) {
8
+ this.tenantId = tenantId;
9
+ this.botKey = botKey;
10
+ this.extensionId = extensionId;
11
+ this.getBotURL = (tenantId) => `https://${tenantId}.http.msging.net/`;
12
+ this.service = BlipService_1.default.withHttp(this.getBotURL(this.tenantId), this.botKey);
13
+ }
14
+ loadData() {
15
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
16
+ return (yield this.service.getBucket(this.extensionId)).data;
17
+ });
18
+ }
19
+ saveConfiguration(configuration) {
20
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
21
+ const data = {
22
+ client: {
23
+ tenantId: this.tenantId,
24
+ botKey: this.botKey,
25
+ },
26
+ configuration,
27
+ };
28
+ yield this.service.updateBucket(this.extensionId, {
29
+ data: data
30
+ });
31
+ return data;
32
+ });
33
+ }
34
+ }
35
+ exports.ExtensionService = ExtensionService;
36
+ //# sourceMappingURL=ExtensionService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExtensionService.js","sourceRoot":"","sources":["../../../../../../libs/services/src/lib/blip/ExtensionService.ts"],"names":[],"mappings":";;;;AACA,+CAAwC;AAMxC,MAAa,gBAAgB;IAG5B,YACS,QAAgB,EAChB,MAAc,EACd,WAAmB;QAFnB,aAAQ,GAAR,QAAQ,CAAQ;QAChB,WAAM,GAAN,MAAM,CAAQ;QACd,gBAAW,GAAX,WAAW,CAAQ;QA8BpB,cAAS,GAAG,CAAC,QAAgB,EAAE,EAAE,CACxC,WAAW,QAAQ,mBAAmB,CAAC;QA7BvC,IAAI,CAAC,OAAO,GAAG,qBAAW,CAAC,QAAQ,CAClC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,EAC7B,IAAI,CAAC,MAAM,CACX,CAAC;IACH,CAAC;IAEK,QAAQ;;YACb,OAAQ,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,CAAgB,CAAC,IAAI,CAAC;QAC9E,CAAC;KAAA;IAEK,iBAAiB,CACtB,aAA2C;;YAE3C,MAAM,IAAI,GAAwB;gBACjC,MAAM,EAAE;oBACP,QAAQ,EAAE,IAAI,CAAC,QAAQ;oBACvB,MAAM,EAAE,IAAI,CAAC,MAAM;iBACnB;gBACD,aAAa;aACb,CAAC;YAEF,MAAM,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,WAAW,EAAE;gBACjD,IAAI,EAAE,IAAI;aACV,CAAC,CAAC;YAEH,OAAO,IAAI,CAAC;QACb,CAAC;KAAA;CAID;AAtCD,4CAsCC"}
@@ -0,0 +1,3 @@
1
+ export * from "./BlipService";
2
+ export * from "./BlipTransport";
3
+ export * from "./ExtensionService";
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./BlipService"), exports);
5
+ tslib_1.__exportStar(require("./BlipTransport"), exports);
6
+ tslib_1.__exportStar(require("./ExtensionService"), exports);
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../libs/services/src/lib/blip/index.ts"],"names":[],"mappings":";;;AAAA,wDAA8B;AAC9B,0DAAgC;AAChC,6DAAmC"}
@@ -0,0 +1 @@
1
+ export * from "./blip/";
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./blip/"), exports);
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/services/src/lib/index.ts"],"names":[],"mappings":";;;AAAA,kDAAwB"}