@botonic/core 0.25.0-alpha.1 → 0.25.0-alpha.2
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/lib/cjs/core-bot.js +76 -99
- package/lib/cjs/core-bot.js.map +1 -1
- package/lib/cjs/data-provider/dynamodb-data-provider.js +69 -52
- package/lib/cjs/data-provider/dynamodb-data-provider.js.map +1 -1
- package/lib/cjs/data-provider/dynamodb-utils.js +2 -15
- package/lib/cjs/data-provider/dynamodb-utils.js.map +1 -1
- package/lib/cjs/data-provider/local-data-provider.js +7 -8
- package/lib/cjs/data-provider/local-data-provider.js.map +1 -1
- package/lib/cjs/debug/inspector.js +0 -3
- package/lib/cjs/debug/inspector.js.map +1 -1
- package/lib/cjs/handoff.js +124 -120
- package/lib/cjs/handoff.js.map +1 -1
- package/lib/cjs/hubtype-service.js +37 -47
- package/lib/cjs/hubtype-service.js.map +1 -1
- package/lib/cjs/output-parser/botonic-output-parser.js +7 -8
- package/lib/cjs/output-parser/botonic-output-parser.js.map +1 -1
- package/lib/cjs/output-parser/parsers.js +17 -60
- package/lib/cjs/output-parser/parsers.js.map +1 -1
- package/lib/cjs/plugins.js +23 -20
- package/lib/cjs/plugins.js.map +1 -1
- package/lib/cjs/routing/router-utils.js +15 -13
- package/lib/cjs/routing/router-utils.js.map +1 -1
- package/lib/cjs/routing/router.js +16 -22
- package/lib/cjs/routing/router.js.map +1 -1
- package/lib/cjs/utils.js +3 -2
- package/lib/cjs/utils.js.map +1 -1
- package/lib/esm/constants.js +4 -7
- package/lib/esm/constants.js.map +1 -1
- package/lib/esm/core-bot.js +88 -115
- package/lib/esm/core-bot.js.map +1 -1
- package/lib/esm/data-provider/dynamodb-data-provider.js +76 -63
- package/lib/esm/data-provider/dynamodb-data-provider.js.map +1 -1
- package/lib/esm/data-provider/dynamodb-utils.js +40 -60
- package/lib/esm/data-provider/dynamodb-utils.js.map +1 -1
- package/lib/esm/data-provider/factory.js +10 -14
- package/lib/esm/data-provider/factory.js.map +1 -1
- package/lib/esm/data-provider/index.js +4 -20
- package/lib/esm/data-provider/index.js.map +1 -1
- package/lib/esm/data-provider/local-data-provider.js +11 -16
- package/lib/esm/data-provider/local-data-provider.js.map +1 -1
- package/lib/esm/debug/index.js +1 -17
- package/lib/esm/debug/index.js.map +1 -1
- package/lib/esm/debug/inspector.js +4 -14
- package/lib/esm/debug/inspector.js.map +1 -1
- package/lib/esm/handoff.js +131 -141
- package/lib/esm/handoff.js.map +1 -1
- package/lib/esm/hubtype-service.js +43 -59
- package/lib/esm/hubtype-service.js.map +1 -1
- package/lib/esm/i18n.js +1 -5
- package/lib/esm/i18n.js.map +1 -1
- package/lib/esm/index.js +11 -27
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/models/events/base-event.js +2 -5
- package/lib/esm/models/events/base-event.js.map +1 -1
- package/lib/esm/models/events/botonic-event.js +1 -2
- package/lib/esm/models/events/connections/connection-event.js +2 -5
- package/lib/esm/models/events/connections/connection-event.js.map +1 -1
- package/lib/esm/models/events/connections/index.js +1 -17
- package/lib/esm/models/events/connections/index.js.map +1 -1
- package/lib/esm/models/events/index.js +4 -20
- package/lib/esm/models/events/index.js.map +1 -1
- package/lib/esm/models/events/message/buttons.js +1 -2
- package/lib/esm/models/events/message/carousel.js +1 -2
- package/lib/esm/models/events/message/contact.js +1 -2
- package/lib/esm/models/events/message/custom.js +1 -2
- package/lib/esm/models/events/message/form.js +1 -2
- package/lib/esm/models/events/message/index.js +11 -27
- package/lib/esm/models/events/message/index.js.map +1 -1
- package/lib/esm/models/events/message/location.js +1 -2
- package/lib/esm/models/events/message/media.js +6 -9
- package/lib/esm/models/events/message/media.js.map +1 -1
- package/lib/esm/models/events/message/message-event.js +6 -9
- package/lib/esm/models/events/message/message-event.js.map +1 -1
- package/lib/esm/models/events/message/missed.js +1 -2
- package/lib/esm/models/events/message/postback.js +1 -2
- package/lib/esm/models/events/message/replies.js +1 -2
- package/lib/esm/models/events/message/text.js +1 -2
- package/lib/esm/models/index.js +3 -19
- package/lib/esm/models/index.js.map +1 -1
- package/lib/esm/models/legacy-types.js +9 -12
- package/lib/esm/models/legacy-types.js.map +1 -1
- package/lib/esm/models/user.js +1 -2
- package/lib/esm/output-parser/botonic-output-parser.js +14 -19
- package/lib/esm/output-parser/botonic-output-parser.js.map +1 -1
- package/lib/esm/output-parser/factory.js +22 -26
- package/lib/esm/output-parser/factory.js.map +1 -1
- package/lib/esm/output-parser/index.js +3 -19
- package/lib/esm/output-parser/index.js.map +1 -1
- package/lib/esm/output-parser/parsers.js +41 -104
- package/lib/esm/output-parser/parsers.js.map +1 -1
- package/lib/esm/plugins.js +24 -26
- package/lib/esm/plugins.js.map +1 -1
- package/lib/esm/pusher-utils.js +3 -7
- package/lib/esm/pusher-utils.js.map +1 -1
- package/lib/esm/routing/index.js +2 -18
- package/lib/esm/routing/index.js.map +1 -1
- package/lib/esm/routing/router-utils.js +28 -36
- package/lib/esm/routing/router-utils.js.map +1 -1
- package/lib/esm/routing/router.js +37 -47
- package/lib/esm/routing/router.js.map +1 -1
- package/lib/esm/utils.js +12 -22
- package/lib/esm/utils.js.map +1 -1
- package/package.json +2 -2
package/lib/esm/core-bot.js
CHANGED
|
@@ -1,32 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const routing_1 = require("./routing");
|
|
11
|
-
class CoreBot {
|
|
12
|
-
appId;
|
|
13
|
-
defaultDelay;
|
|
14
|
-
defaultRoutes;
|
|
15
|
-
defaultTyping;
|
|
16
|
-
inspector;
|
|
17
|
-
locales;
|
|
18
|
-
plugins;
|
|
19
|
-
renderer;
|
|
20
|
-
rootElement;
|
|
21
|
-
router;
|
|
22
|
-
routes;
|
|
23
|
-
theme;
|
|
24
|
-
botonicOutputParser = new output_parser_1.BotonicOutputParser();
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { ulid } from 'ulid';
|
|
3
|
+
import { Inspector } from './debug';
|
|
4
|
+
import { getString } from './i18n';
|
|
5
|
+
import { INPUT, MessageEventAck, MessageEventFrom, } from './models';
|
|
6
|
+
import { BotonicOutputParser } from './output-parser';
|
|
7
|
+
import { loadPlugins, runPlugins } from './plugins';
|
|
8
|
+
import { getComputedRoutes, Router } from './routing';
|
|
9
|
+
export class CoreBot {
|
|
25
10
|
constructor({
|
|
26
11
|
// TODO: Receives dataProvider
|
|
27
12
|
renderer, routes, locales, theme, plugins, appId, defaultTyping, defaultDelay, defaultRoutes, inspector, }) {
|
|
13
|
+
this.botonicOutputParser = new BotonicOutputParser();
|
|
28
14
|
this.renderer = renderer;
|
|
29
|
-
this.plugins =
|
|
15
|
+
this.plugins = loadPlugins(plugins);
|
|
30
16
|
this.theme = theme || {};
|
|
31
17
|
this.defaultTyping =
|
|
32
18
|
typeof defaultTyping !== 'undefined' ? defaultTyping : 0.6;
|
|
@@ -37,115 +23,102 @@ class CoreBot {
|
|
|
37
23
|
return;
|
|
38
24
|
}
|
|
39
25
|
this.rootElement = null;
|
|
40
|
-
this.inspector = inspector || new
|
|
26
|
+
this.inspector = inspector || new Inspector();
|
|
41
27
|
this.routes = routes;
|
|
42
28
|
this.defaultRoutes = defaultRoutes || [];
|
|
43
29
|
this.router =
|
|
44
30
|
this.routes instanceof Function
|
|
45
31
|
? null
|
|
46
|
-
: new
|
|
32
|
+
: new Router([...this.routes, ...this.defaultRoutes], this.inspector.routeInspector);
|
|
47
33
|
}
|
|
48
34
|
getString(id, session) {
|
|
49
35
|
// @ts-ignore
|
|
50
|
-
return
|
|
36
|
+
return getString(this.locales, session.__locale, id);
|
|
51
37
|
}
|
|
52
38
|
setLocale(locale, session) {
|
|
53
39
|
session.__locale = locale;
|
|
54
40
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
session.__locale
|
|
59
|
-
|
|
41
|
+
input({ input, session, lastRoutePath, dataProvider, }) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
session = session || {};
|
|
44
|
+
if (!session.__locale)
|
|
45
|
+
session.__locale = 'en';
|
|
46
|
+
if (input.type === INPUT.CHAT_EVENT) {
|
|
47
|
+
return {
|
|
48
|
+
input,
|
|
49
|
+
session,
|
|
50
|
+
lastRoutePath,
|
|
51
|
+
dataProvider,
|
|
52
|
+
response: [],
|
|
53
|
+
messageEvents: null,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
const parsedUserEvent = this.botonicOutputParser.parseFromUserInput(input);
|
|
57
|
+
const userId = session.user.id;
|
|
58
|
+
if (dataProvider) {
|
|
59
|
+
// TODO: Next iterations. Review cycle of commited events to DB when messages change their ACK
|
|
60
|
+
// @ts-ignore
|
|
61
|
+
const userEvent = yield dataProvider.saveEvent(Object.assign(Object.assign({}, parsedUserEvent), { userId, eventId: ulid(), createdAt: new Date().toISOString(), from: MessageEventFrom.USER, ack: MessageEventAck.RECEIVED }));
|
|
62
|
+
}
|
|
63
|
+
if (this.plugins) {
|
|
64
|
+
yield runPlugins(this.plugins, 'pre', input, session, lastRoutePath, undefined, undefined, dataProvider);
|
|
65
|
+
}
|
|
66
|
+
if (this.routes instanceof Function) {
|
|
67
|
+
this.router = new Router([
|
|
68
|
+
...(yield getComputedRoutes(this.routes, {
|
|
69
|
+
input,
|
|
70
|
+
session,
|
|
71
|
+
lastRoutePath,
|
|
72
|
+
})),
|
|
73
|
+
...this.defaultRoutes,
|
|
74
|
+
], this.inspector.routeInspector);
|
|
75
|
+
}
|
|
76
|
+
const output = this.router.processInput(input, session, lastRoutePath);
|
|
77
|
+
const request = {
|
|
78
|
+
getString: stringId => this.getString(stringId, session),
|
|
79
|
+
setLocale: locale => this.setLocale(locale, session),
|
|
80
|
+
session: session || {},
|
|
81
|
+
params: output.params || {},
|
|
82
|
+
input: input,
|
|
83
|
+
plugins: this.plugins,
|
|
84
|
+
defaultTyping: this.defaultTyping,
|
|
85
|
+
defaultDelay: this.defaultDelay,
|
|
86
|
+
lastRoutePath,
|
|
87
|
+
dataProvider,
|
|
88
|
+
};
|
|
89
|
+
const response = yield this.renderer({
|
|
90
|
+
request,
|
|
91
|
+
actions: [output.fallbackAction, output.action, output.emptyAction],
|
|
92
|
+
});
|
|
93
|
+
let messageEvents = [];
|
|
94
|
+
try {
|
|
95
|
+
messageEvents = this.botonicOutputParser.xmlToMessageEvents(response);
|
|
96
|
+
}
|
|
97
|
+
catch (e) {
|
|
98
|
+
// Disabling Botonic 1.0 error log for LTS version:
|
|
99
|
+
// console.error(e)
|
|
100
|
+
}
|
|
101
|
+
lastRoutePath = output.lastRoutePath;
|
|
102
|
+
if (this.plugins) {
|
|
103
|
+
yield runPlugins(this.plugins, 'post', input, session, lastRoutePath, response, messageEvents, dataProvider);
|
|
104
|
+
}
|
|
105
|
+
if (dataProvider) {
|
|
106
|
+
// TODO: save bot responses to db and update user with new session and new params
|
|
107
|
+
for (const messageEvent of messageEvents) {
|
|
108
|
+
// @ts-ignore
|
|
109
|
+
const botEvent = yield dataProvider.saveEvent(Object.assign(Object.assign({}, messageEvent), { userId, eventId: ulid(), createdAt: new Date().toISOString(), from: MessageEventFrom.BOT, ack: MessageEventAck.SENT }));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
session.is_first_interaction = false;
|
|
60
113
|
return {
|
|
61
114
|
input,
|
|
115
|
+
response,
|
|
116
|
+
messageEvents,
|
|
62
117
|
session,
|
|
63
118
|
lastRoutePath,
|
|
64
119
|
dataProvider,
|
|
65
|
-
response: [],
|
|
66
|
-
messageEvents: null,
|
|
67
120
|
};
|
|
68
|
-
}
|
|
69
|
-
const parsedUserEvent = this.botonicOutputParser.parseFromUserInput(input);
|
|
70
|
-
const userId = session.user.id;
|
|
71
|
-
if (dataProvider) {
|
|
72
|
-
// TODO: Next iterations. Review cycle of commited events to DB when messages change their ACK
|
|
73
|
-
// @ts-ignore
|
|
74
|
-
const userEvent = await dataProvider.saveEvent({
|
|
75
|
-
...parsedUserEvent,
|
|
76
|
-
userId,
|
|
77
|
-
eventId: (0, ulid_1.ulid)(),
|
|
78
|
-
createdAt: new Date().toISOString(),
|
|
79
|
-
from: models_1.MessageEventFrom.USER,
|
|
80
|
-
ack: models_1.MessageEventAck.RECEIVED,
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
if (this.plugins) {
|
|
84
|
-
await (0, plugins_1.runPlugins)(this.plugins, 'pre', input, session, lastRoutePath, undefined, undefined, dataProvider);
|
|
85
|
-
}
|
|
86
|
-
if (this.routes instanceof Function) {
|
|
87
|
-
this.router = new routing_1.Router([
|
|
88
|
-
...(await (0, routing_1.getComputedRoutes)(this.routes, {
|
|
89
|
-
input,
|
|
90
|
-
session,
|
|
91
|
-
lastRoutePath,
|
|
92
|
-
})),
|
|
93
|
-
...this.defaultRoutes,
|
|
94
|
-
], this.inspector.routeInspector);
|
|
95
|
-
}
|
|
96
|
-
const output = this.router.processInput(input, session, lastRoutePath);
|
|
97
|
-
const request = {
|
|
98
|
-
getString: stringId => this.getString(stringId, session),
|
|
99
|
-
setLocale: locale => this.setLocale(locale, session),
|
|
100
|
-
session: session || {},
|
|
101
|
-
params: output.params || {},
|
|
102
|
-
input: input,
|
|
103
|
-
plugins: this.plugins,
|
|
104
|
-
defaultTyping: this.defaultTyping,
|
|
105
|
-
defaultDelay: this.defaultDelay,
|
|
106
|
-
lastRoutePath,
|
|
107
|
-
dataProvider,
|
|
108
|
-
};
|
|
109
|
-
const response = await this.renderer({
|
|
110
|
-
request,
|
|
111
|
-
actions: [output.fallbackAction, output.action, output.emptyAction],
|
|
112
121
|
});
|
|
113
|
-
let messageEvents = [];
|
|
114
|
-
try {
|
|
115
|
-
messageEvents = this.botonicOutputParser.xmlToMessageEvents(response);
|
|
116
|
-
}
|
|
117
|
-
catch (e) {
|
|
118
|
-
// Disabling Botonic 1.0 error log for LTS version:
|
|
119
|
-
// console.error(e)
|
|
120
|
-
}
|
|
121
|
-
lastRoutePath = output.lastRoutePath;
|
|
122
|
-
if (this.plugins) {
|
|
123
|
-
await (0, plugins_1.runPlugins)(this.plugins, 'post', input, session, lastRoutePath, response, messageEvents, dataProvider);
|
|
124
|
-
}
|
|
125
|
-
if (dataProvider) {
|
|
126
|
-
// TODO: save bot responses to db and update user with new session and new params
|
|
127
|
-
for (const messageEvent of messageEvents) {
|
|
128
|
-
// @ts-ignore
|
|
129
|
-
const botEvent = await dataProvider.saveEvent({
|
|
130
|
-
...messageEvent,
|
|
131
|
-
userId,
|
|
132
|
-
eventId: (0, ulid_1.ulid)(),
|
|
133
|
-
createdAt: new Date().toISOString(),
|
|
134
|
-
from: models_1.MessageEventFrom.BOT,
|
|
135
|
-
ack: models_1.MessageEventAck.SENT,
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
session.is_first_interaction = false;
|
|
140
|
-
return {
|
|
141
|
-
input,
|
|
142
|
-
response,
|
|
143
|
-
messageEvents,
|
|
144
|
-
session,
|
|
145
|
-
lastRoutePath,
|
|
146
|
-
dataProvider,
|
|
147
|
-
};
|
|
148
122
|
}
|
|
149
123
|
}
|
|
150
|
-
exports.CoreBot = CoreBot;
|
|
151
124
|
//# sourceMappingURL=core-bot.js.map
|
package/lib/esm/core-bot.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-bot.js","sourceRoot":"","sources":["../../src/core-bot.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"core-bot.js","sourceRoot":"","sources":["../../src/core-bot.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAE3B,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AAClC,OAAO,EAIL,KAAK,EAEL,eAAe,EACf,gBAAgB,GAKjB,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,mBAAm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,CAAC,mBAAmB,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAA;aACtE;YAAC,OAAO,CAAC,EAAE;gBACV,mDAAmD;gBACnD,mBAAmB;aACpB;YAED,aAAa,GAAG,MAAM,CAAC,aAAa,CAAA;YACpC,IAAI,IAAI,CAAC,OAAO,EAAE;gBAChB,MAAM,UAAU,CACd,IAAI,CAAC,OAAO,EACZ,MAAM,EACN,KAAK,EACL,OAAO,EACP,aAAa,EACb,QAAQ,EACR,aAAa,EACb,YAAY,CACb,CAAA;aACF;YAED,IAAI,YAAY,EAAE;gBAChB,iFAAiF;gBACjF,KAAK,MAAM,YAAY,IAAI,aAAa,EAAE;oBACxC,aAAa;oBACb,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,SAAS,iCACxC,YAAY,KACf,MAAM,EACN,OAAO,EAAE,IAAI,EAAE,EACf,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EACnC,IAAI,EAAE,gBAAgB,CAAC,GAAG,EAC1B,GAAG,EAAE,eAAe,CAAC,IAAI,IACzB,CAAA;iBACH;aACF;YAED,OAAO,CAAC,oBAAoB,GAAG,KAAK,CAAA;YACpC,OAAO;gBACL,KAAK;gBACL,QAAQ;gBACR,aAAa;gBACb,OAAO;gBACP,aAAa;gBACb,YAAY;aACb,CAAA;QACH,CAAC;KAAA;CACF"}
|
|
@@ -1,89 +1,102 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const dynamodb_utils_1 = require("./dynamodb-utils");
|
|
6
|
-
class DynamoDBDataProvider {
|
|
7
|
-
region;
|
|
8
|
-
tableName;
|
|
9
|
-
userEventsTable;
|
|
10
|
-
userEntity;
|
|
11
|
-
eventEntity;
|
|
12
|
-
messageEventEntities;
|
|
13
|
-
textMessageEventEntity;
|
|
14
|
-
connectionEventEntity;
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { EventTypes } from '../models';
|
|
3
|
+
import { getConnectionEventEntity, getMessageEventEntities, getUserEntity, getUserEventsTable, GLOBAL_SECONDARY_INDEX_NAME, SORT_KEY_NAME, USER_PREFIX, } from './dynamodb-utils';
|
|
4
|
+
export class DynamoDBDataProvider {
|
|
15
5
|
constructor(url) {
|
|
16
6
|
try {
|
|
17
7
|
;
|
|
18
8
|
[this.tableName, this.region] = url.split('://')[1].split('.');
|
|
19
|
-
this.userEventsTable =
|
|
20
|
-
this.userEntity =
|
|
21
|
-
this.connectionEventEntity =
|
|
22
|
-
this.messageEventEntities =
|
|
9
|
+
this.userEventsTable = getUserEventsTable(this.tableName, this.region);
|
|
10
|
+
this.userEntity = getUserEntity(this.userEventsTable);
|
|
11
|
+
this.connectionEventEntity = getConnectionEventEntity(this.userEventsTable);
|
|
12
|
+
this.messageEventEntities = getMessageEventEntities(this.userEventsTable);
|
|
23
13
|
}
|
|
24
14
|
catch (e) {
|
|
25
15
|
console.log({ e });
|
|
26
16
|
}
|
|
27
17
|
}
|
|
28
18
|
// @ts-ignore
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
19
|
+
getUsers(limit = 10, offset = 0) {
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
// TODO: finish to implement with offset
|
|
22
|
+
const result = yield this.userEventsTable.scan({
|
|
23
|
+
filters: { attr: SORT_KEY_NAME, beginsWith: USER_PREFIX },
|
|
24
|
+
limit,
|
|
25
|
+
});
|
|
26
|
+
return result.Items;
|
|
34
27
|
});
|
|
35
|
-
return result.Items;
|
|
36
28
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
29
|
+
getUser(id) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
const userById = {
|
|
32
|
+
id: id,
|
|
33
|
+
SK: id,
|
|
34
|
+
};
|
|
35
|
+
const result = yield this.userEntity.get(userById);
|
|
36
|
+
if (Object.keys(result).length === 0)
|
|
37
|
+
return undefined;
|
|
38
|
+
return result.Item;
|
|
39
|
+
});
|
|
46
40
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
41
|
+
getUserByWebsocketId(websocketId) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
const result = yield this.userEventsTable.query(websocketId, {
|
|
44
|
+
index: GLOBAL_SECONDARY_INDEX_NAME,
|
|
45
|
+
});
|
|
46
|
+
if (result.Count === 0)
|
|
47
|
+
return undefined;
|
|
48
|
+
return result.Items[0];
|
|
50
49
|
});
|
|
51
|
-
if (result.Count === 0)
|
|
52
|
-
return undefined;
|
|
53
|
-
return result.Items[0];
|
|
54
50
|
}
|
|
55
51
|
// @ts-ignore
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return
|
|
52
|
+
getUserByField(field, value) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () { });
|
|
54
|
+
} //TODO: Implement
|
|
55
|
+
saveUser(user) {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
const putUser = Object.assign(Object.assign({}, user), { id: user.id, userId: user.id });
|
|
58
|
+
yield this.userEntity.put(putUser);
|
|
59
|
+
return user;
|
|
60
|
+
});
|
|
61
61
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
updateUser(user) {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
const updateUser = Object.assign(Object.assign({}, user), { id: user.id, userId: user.id });
|
|
65
|
+
const res = yield this.userEntity.update(updateUser);
|
|
66
|
+
return user;
|
|
67
|
+
});
|
|
66
68
|
}
|
|
67
69
|
// @ts-ignore
|
|
68
|
-
|
|
70
|
+
deleteUser(id) {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function* () { });
|
|
72
|
+
} // TODO: Implement
|
|
69
73
|
// @ts-ignore
|
|
70
|
-
|
|
74
|
+
getEvents(limit = 10, offset = 0) {
|
|
75
|
+
return __awaiter(this, void 0, void 0, function* () { });
|
|
76
|
+
} // TODO: Implement
|
|
71
77
|
// @ts-ignore
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
78
|
+
getEvent(id) {
|
|
79
|
+
return __awaiter(this, void 0, void 0, function* () { });
|
|
80
|
+
} // TODO: Implement
|
|
81
|
+
saveEvent(event) {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
if (event.eventType === EventTypes.CONNECTION) {
|
|
84
|
+
yield this.connectionEventEntity.put(event);
|
|
85
|
+
}
|
|
86
|
+
if (event.eventType === EventTypes.MESSAGE) {
|
|
87
|
+
yield this.messageEventEntities[event.type].put(event);
|
|
88
|
+
}
|
|
89
|
+
// TODO: Implementation of other event types
|
|
90
|
+
return event;
|
|
91
|
+
});
|
|
82
92
|
}
|
|
83
93
|
// @ts-ignore
|
|
84
|
-
|
|
94
|
+
updateEvent(event) {
|
|
95
|
+
return __awaiter(this, void 0, void 0, function* () { });
|
|
96
|
+
} // TODO: Implement
|
|
85
97
|
// @ts-ignore
|
|
86
|
-
|
|
98
|
+
deleteEvent(id) {
|
|
99
|
+
return __awaiter(this, void 0, void 0, function* () { });
|
|
100
|
+
} // TODO: Implement
|
|
87
101
|
}
|
|
88
|
-
exports.DynamoDBDataProvider = DynamoDBDataProvider;
|
|
89
102
|
//# sourceMappingURL=dynamodb-data-provider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamodb-data-provider.js","sourceRoot":"","sources":["../../../src/data-provider/dynamodb-data-provider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dynamodb-data-provider.js","sourceRoot":"","sources":["../../../src/data-provider/dynamodb-data-prov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AAC,kBAAkB;IAE7E,aAAa;IACP,SAAS,CAAC,KAAK,GAAG,EAAE,EAAE,MAAM,GAAG,CAAC;8DAA4B,CAAC;KAAA,CAAC,kBAAkB;IAEtF,aAAa;IACP,QAAQ,CAAC,EAAU;8DAAsC,CAAC;KAAA,CAAC,kBAAkB;IAE7E,SAAS,CAAC,KAAmB;;YACjC,IAAI,KAAK,CAAC,SAAS,KAAK,UAAU,CAAC,UAAU,EAAE;gBAC7C,MAAM,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;aAC5C;YACD,IAAI,KAAK,CAAC,SAAS,KAAK,UAAU,CAAC,OAAO,EAAE;gBAC1C,MAAM,IAAI,CAAC,oBAAoB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;aACvD;YACD,4CAA4C;YAC5C,OAAO,KAAK,CAAA;QACd,CAAC;KAAA;IAED,aAAa;IACP,WAAW,CAAC,KAAmB;8DAA0B,CAAC;KAAA,CAAC,kBAAkB;IAEnF,aAAa;IACP,WAAW,CAAC,EAAU;8DAAsC,CAAC;KAAA,CAAC,kBAAkB;CACvF"}
|
|
@@ -1,50 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const aws_sdk_1 = require("aws-sdk");
|
|
5
|
-
const dynamodb_toolbox_1 = require("dynamodb-toolbox");
|
|
6
|
-
const models_1 = require("../models");
|
|
1
|
+
import { DynamoDB } from 'aws-sdk';
|
|
2
|
+
import { Entity, Table } from 'dynamodb-toolbox';
|
|
3
|
+
import { MessageEventTypes } from '../models';
|
|
7
4
|
// Table Definitions
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
export const GLOBAL_SECONDARY_INDEX_NAME = 'GSI1';
|
|
6
|
+
export const GLOBAL_SECONDARY_INDEX_ATTR = 'websocketId';
|
|
7
|
+
export const PARTITION_KEY_NAME = 'PK';
|
|
8
|
+
export const SORT_KEY_NAME = 'SK';
|
|
12
9
|
// Entities Definitions
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
export const USER_PREFIX = 'USR#';
|
|
11
|
+
export const EVENT_PREFIX = 'EVT#';
|
|
15
12
|
function capitalize(string) {
|
|
16
13
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
17
14
|
}
|
|
18
|
-
function getUserEventsTable(tableName, region) {
|
|
19
|
-
const documentClient = new
|
|
15
|
+
export function getUserEventsTable(tableName, region) {
|
|
16
|
+
const documentClient = new DynamoDB.DocumentClient({
|
|
20
17
|
apiVersion: '2012-08-10',
|
|
21
18
|
region: region,
|
|
22
19
|
});
|
|
23
|
-
return new
|
|
20
|
+
return new Table({
|
|
24
21
|
name: tableName,
|
|
25
|
-
partitionKey:
|
|
26
|
-
sortKey:
|
|
22
|
+
partitionKey: PARTITION_KEY_NAME,
|
|
23
|
+
sortKey: SORT_KEY_NAME,
|
|
27
24
|
entityField: true,
|
|
28
25
|
indexes: {
|
|
29
26
|
GSI1: {
|
|
30
|
-
partitionKey:
|
|
27
|
+
partitionKey: GLOBAL_SECONDARY_INDEX_ATTR,
|
|
31
28
|
},
|
|
32
29
|
},
|
|
33
30
|
DocumentClient: documentClient,
|
|
34
31
|
});
|
|
35
32
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return new dynamodb_toolbox_1.Entity({
|
|
33
|
+
export function getUserEntity(table) {
|
|
34
|
+
return new Entity({
|
|
39
35
|
name: 'User',
|
|
40
36
|
attributes: {
|
|
41
|
-
id: { partitionKey: true, prefix:
|
|
42
|
-
[`${
|
|
37
|
+
id: { partitionKey: true, prefix: USER_PREFIX },
|
|
38
|
+
[`${SORT_KEY_NAME}`]: {
|
|
43
39
|
hidden: true,
|
|
44
40
|
sortKey: true,
|
|
45
|
-
prefix:
|
|
41
|
+
prefix: USER_PREFIX,
|
|
46
42
|
},
|
|
47
|
-
userId: [
|
|
43
|
+
userId: [SORT_KEY_NAME, 0],
|
|
48
44
|
websocketId: 'string',
|
|
49
45
|
isOnline: 'boolean',
|
|
50
46
|
route: 'string',
|
|
@@ -53,18 +49,17 @@ function getUserEntity(table) {
|
|
|
53
49
|
table,
|
|
54
50
|
});
|
|
55
51
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
return new dynamodb_toolbox_1.Entity({
|
|
52
|
+
export function getConnectionEventEntity(table) {
|
|
53
|
+
return new Entity({
|
|
59
54
|
name: 'Connection Event',
|
|
60
55
|
attributes: {
|
|
61
|
-
userId: { partitionKey: true, prefix:
|
|
62
|
-
[`${
|
|
56
|
+
userId: { partitionKey: true, prefix: USER_PREFIX },
|
|
57
|
+
[`${SORT_KEY_NAME}`]: {
|
|
63
58
|
hidden: true,
|
|
64
59
|
sortKey: true,
|
|
65
|
-
prefix:
|
|
60
|
+
prefix: EVENT_PREFIX,
|
|
66
61
|
},
|
|
67
|
-
eventId: [
|
|
62
|
+
eventId: [SORT_KEY_NAME, 0],
|
|
68
63
|
eventType: 'string',
|
|
69
64
|
createdAt: 'string',
|
|
70
65
|
modifiedAt: 'string',
|
|
@@ -73,8 +68,7 @@ function getConnectionEventEntity(table) {
|
|
|
73
68
|
table,
|
|
74
69
|
});
|
|
75
70
|
}
|
|
76
|
-
|
|
77
|
-
function getMessageEventEntities(table) {
|
|
71
|
+
export function getMessageEventEntities(table) {
|
|
78
72
|
const textAttributes = {
|
|
79
73
|
text: 'string',
|
|
80
74
|
markdown: 'boolean',
|
|
@@ -96,38 +90,24 @@ function getMessageEventEntities(table) {
|
|
|
96
90
|
json: 'map',
|
|
97
91
|
replies: 'list',
|
|
98
92
|
};
|
|
99
|
-
const entityWithAttributes = (type, attributes) => new
|
|
93
|
+
const entityWithAttributes = (type, attributes) => new Entity({
|
|
100
94
|
name: `${capitalize(type)} Message Event`,
|
|
101
|
-
attributes: {
|
|
102
|
-
userId: { partitionKey: true, prefix: exports.USER_PREFIX },
|
|
103
|
-
[`${exports.SORT_KEY_NAME}`]: {
|
|
95
|
+
attributes: Object.assign({ userId: { partitionKey: true, prefix: USER_PREFIX }, [`${SORT_KEY_NAME}`]: {
|
|
104
96
|
hidden: true,
|
|
105
97
|
sortKey: true,
|
|
106
|
-
prefix:
|
|
107
|
-
},
|
|
108
|
-
eventId: [exports.SORT_KEY_NAME, 0],
|
|
109
|
-
eventType: 'string',
|
|
110
|
-
createdAt: 'string',
|
|
111
|
-
modifiedAt: 'string',
|
|
112
|
-
from: 'string',
|
|
113
|
-
ack: 'string',
|
|
114
|
-
typing: 'number',
|
|
115
|
-
delay: 'number',
|
|
116
|
-
type: 'string',
|
|
117
|
-
...attributes,
|
|
118
|
-
},
|
|
98
|
+
prefix: EVENT_PREFIX,
|
|
99
|
+
}, eventId: [SORT_KEY_NAME, 0], eventType: 'string', createdAt: 'string', modifiedAt: 'string', from: 'string', ack: 'string', typing: 'number', delay: 'number', type: 'string' }, attributes),
|
|
119
100
|
table,
|
|
120
101
|
});
|
|
121
102
|
return {
|
|
122
|
-
text: entityWithAttributes(
|
|
123
|
-
audio: entityWithAttributes(
|
|
124
|
-
image: entityWithAttributes(
|
|
125
|
-
document: entityWithAttributes(
|
|
126
|
-
video: entityWithAttributes(
|
|
127
|
-
location: entityWithAttributes(
|
|
128
|
-
carousel: entityWithAttributes(
|
|
129
|
-
custom: entityWithAttributes(
|
|
103
|
+
text: entityWithAttributes(MessageEventTypes.TEXT, textAttributes),
|
|
104
|
+
audio: entityWithAttributes(MessageEventTypes.AUDIO, mediaAttributes),
|
|
105
|
+
image: entityWithAttributes(MessageEventTypes.IMAGE, mediaAttributes),
|
|
106
|
+
document: entityWithAttributes(MessageEventTypes.DOCUMENT, mediaAttributes),
|
|
107
|
+
video: entityWithAttributes(MessageEventTypes.VIDEO, mediaAttributes),
|
|
108
|
+
location: entityWithAttributes(MessageEventTypes.LOCATION, locationAttributes),
|
|
109
|
+
carousel: entityWithAttributes(MessageEventTypes.CAROUSEL, carouselAttributes),
|
|
110
|
+
custom: entityWithAttributes(MessageEventTypes.CUSTOM, customAttributes),
|
|
130
111
|
};
|
|
131
112
|
}
|
|
132
|
-
exports.getMessageEventEntities = getMessageEventEntities;
|
|
133
113
|
//# sourceMappingURL=dynamodb-utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamodb-utils.js","sourceRoot":"","sources":["../../../src/data-provider/dynamodb-utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dynamodb-utils.js","sourceRoot":"","sources":["../../../src/data-provider/dynamodb-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAClC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AAGhD,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAE7C,oBAAoB;AACpB,MAAM,CAAC,MAAM,2BAA2B,GAAG,MAAM,CAAA;AACjD,MAAM,CAAC,MAAM,2BAA2B,GAAG,aAAa,CAAA;AACxD,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,CAAA;AACtC,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,CAAA;AAEjC,uBAAuB;AACvB,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAA;AACjC,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAA;AAElC,SAAS,UAAU,CAAC,MAAc;IAChC,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;AACzD,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,SAAiB,EAAE,MAAc;IAClE,MAAM,cAAc,GAAG,IAAI,QAAQ,CAAC,cAAc,CAAC;QACjD,UAAU,EAAE,YAAY;QACxB,MAAM,EAAE,MAAM;KACf,CAAC,CAAA;IACF,OAAO,IAAI,KAAK,CAAC;QACf,IAAI,EAAE,SAAS;QACf,YAAY,EAAE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