@botonic/core 0.26.0 → 0.27.0-alpha.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.
Files changed (106) hide show
  1. package/lib/cjs/core-bot.d.ts +1 -3
  2. package/lib/cjs/core-bot.js +3 -33
  3. package/lib/cjs/core-bot.js.map +1 -1
  4. package/lib/cjs/handoff.d.ts +16 -16
  5. package/lib/cjs/handoff.js +9 -2
  6. package/lib/cjs/handoff.js.map +1 -1
  7. package/lib/cjs/index.d.ts +0 -1
  8. package/lib/cjs/index.js +0 -3
  9. package/lib/cjs/index.js.map +1 -1
  10. package/lib/cjs/models/legacy-types.d.ts +44 -39
  11. package/lib/cjs/models/legacy-types.js +15 -32
  12. package/lib/cjs/models/legacy-types.js.map +1 -1
  13. package/lib/cjs/plugins.d.ts +2 -3
  14. package/lib/cjs/plugins.js +2 -4
  15. package/lib/cjs/plugins.js.map +1 -1
  16. package/lib/cjs/utils.d.ts +8 -0
  17. package/lib/cjs/utils.js +32 -1
  18. package/lib/cjs/utils.js.map +1 -1
  19. package/lib/esm/core-bot.d.ts +1 -3
  20. package/lib/esm/core-bot.js +4 -34
  21. package/lib/esm/core-bot.js.map +1 -1
  22. package/lib/esm/handoff.d.ts +16 -16
  23. package/lib/esm/handoff.js +9 -2
  24. package/lib/esm/handoff.js.map +1 -1
  25. package/lib/esm/index.d.ts +0 -1
  26. package/lib/esm/index.js +0 -3
  27. package/lib/esm/index.js.map +1 -1
  28. package/lib/esm/models/legacy-types.d.ts +44 -39
  29. package/lib/esm/models/legacy-types.js +14 -31
  30. package/lib/esm/models/legacy-types.js.map +1 -1
  31. package/lib/esm/plugins.d.ts +2 -3
  32. package/lib/esm/plugins.js +2 -4
  33. package/lib/esm/plugins.js.map +1 -1
  34. package/lib/esm/utils.d.ts +8 -0
  35. package/lib/esm/utils.js +24 -0
  36. package/lib/esm/utils.js.map +1 -1
  37. package/package.json +1 -6
  38. package/src/core-bot.ts +2 -56
  39. package/src/handoff.ts +29 -19
  40. package/src/index.ts +0 -3
  41. package/src/models/legacy-types.ts +78 -76
  42. package/src/plugins.ts +2 -8
  43. package/src/utils.ts +32 -0
  44. package/lib/cjs/data-provider/dynamodb-data-provider.d.ts +0 -26
  45. package/lib/cjs/data-provider/dynamodb-data-provider.js +0 -107
  46. package/lib/cjs/data-provider/dynamodb-data-provider.js.map +0 -1
  47. package/lib/cjs/data-provider/dynamodb-utils.d.ts +0 -11
  48. package/lib/cjs/data-provider/dynamodb-utils.js +0 -121
  49. package/lib/cjs/data-provider/dynamodb-utils.js.map +0 -1
  50. package/lib/cjs/data-provider/factory.d.ts +0 -25
  51. package/lib/cjs/data-provider/factory.js +0 -31
  52. package/lib/cjs/data-provider/factory.js.map +0 -1
  53. package/lib/cjs/data-provider/index.d.ts +0 -4
  54. package/lib/cjs/data-provider/index.js +0 -8
  55. package/lib/cjs/data-provider/index.js.map +0 -1
  56. package/lib/cjs/data-provider/local-data-provider.d.ts +0 -26
  57. package/lib/cjs/data-provider/local-data-provider.js +0 -137
  58. package/lib/cjs/data-provider/local-data-provider.js.map +0 -1
  59. package/lib/cjs/output-parser/botonic-output-parser.d.ts +0 -16
  60. package/lib/cjs/output-parser/botonic-output-parser.js +0 -37
  61. package/lib/cjs/output-parser/botonic-output-parser.js.map +0 -1
  62. package/lib/cjs/output-parser/factory.d.ts +0 -4
  63. package/lib/cjs/output-parser/factory.js +0 -36
  64. package/lib/cjs/output-parser/factory.js.map +0 -1
  65. package/lib/cjs/output-parser/index.d.ts +0 -3
  66. package/lib/cjs/output-parser/index.js +0 -7
  67. package/lib/cjs/output-parser/index.js.map +0 -1
  68. package/lib/cjs/output-parser/parsers.d.ts +0 -26
  69. package/lib/cjs/output-parser/parsers.js +0 -171
  70. package/lib/cjs/output-parser/parsers.js.map +0 -1
  71. package/lib/esm/data-provider/dynamodb-data-provider.d.ts +0 -26
  72. package/lib/esm/data-provider/dynamodb-data-provider.js +0 -103
  73. package/lib/esm/data-provider/dynamodb-data-provider.js.map +0 -1
  74. package/lib/esm/data-provider/dynamodb-utils.d.ts +0 -11
  75. package/lib/esm/data-provider/dynamodb-utils.js +0 -113
  76. package/lib/esm/data-provider/dynamodb-utils.js.map +0 -1
  77. package/lib/esm/data-provider/factory.d.ts +0 -25
  78. package/lib/esm/data-provider/factory.js +0 -27
  79. package/lib/esm/data-provider/factory.js.map +0 -1
  80. package/lib/esm/data-provider/index.d.ts +0 -4
  81. package/lib/esm/data-provider/index.js +0 -5
  82. package/lib/esm/data-provider/index.js.map +0 -1
  83. package/lib/esm/data-provider/local-data-provider.d.ts +0 -26
  84. package/lib/esm/data-provider/local-data-provider.js +0 -133
  85. package/lib/esm/data-provider/local-data-provider.js.map +0 -1
  86. package/lib/esm/output-parser/botonic-output-parser.d.ts +0 -16
  87. package/lib/esm/output-parser/botonic-output-parser.js +0 -33
  88. package/lib/esm/output-parser/botonic-output-parser.js.map +0 -1
  89. package/lib/esm/output-parser/factory.d.ts +0 -4
  90. package/lib/esm/output-parser/factory.js +0 -32
  91. package/lib/esm/output-parser/factory.js.map +0 -1
  92. package/lib/esm/output-parser/index.d.ts +0 -3
  93. package/lib/esm/output-parser/index.js +0 -4
  94. package/lib/esm/output-parser/index.js.map +0 -1
  95. package/lib/esm/output-parser/parsers.d.ts +0 -26
  96. package/lib/esm/output-parser/parsers.js +0 -151
  97. package/lib/esm/output-parser/parsers.js.map +0 -1
  98. package/src/data-provider/dynamodb-data-provider.ts +0 -105
  99. package/src/data-provider/dynamodb-utils.ts +0 -149
  100. package/src/data-provider/factory.ts +0 -60
  101. package/src/data-provider/index.ts +0 -4
  102. package/src/data-provider/local-data-provider.ts +0 -154
  103. package/src/output-parser/botonic-output-parser.ts +0 -38
  104. package/src/output-parser/factory.ts +0 -45
  105. package/src/output-parser/index.ts +0 -3
  106. package/src/output-parser/parsers.ts +0 -237
@@ -1,26 +0,0 @@
1
- import { AudioMessageEvent, BotonicMessageEvent, Button, CarouselElement, CarouselMessageEvent, CustomMessageEvent, DocumentMessageEvent, FormMessageEvent, ImageMessageEvent, LocationMessageEvent, MissedMessageEvent, PostbackMessageEvent, Reply, TextMessageEvent, VideoMessageEvent, WithButtons, WithReplies } from '../models';
2
- import { ContactMessageEvent } from '../models/events/message/contact';
3
- export declare function parseNumber(strNumber: string): number;
4
- export declare function parseBoolean(strNumber: string): boolean;
5
- export type ParseFunction<Out> = (args: {
6
- toParse: any;
7
- parsed?: any;
8
- }) => {
9
- toParse: any;
10
- parsed: Partial<Out>;
11
- };
12
- export declare const parseMessage: ParseFunction<BotonicMessageEvent>;
13
- export declare const parseButton: (button: any) => Button;
14
- export declare const parseButtons: ParseFunction<WithButtons>;
15
- export declare const parseReply: (reply: any) => Reply;
16
- export declare const parseReplies: ParseFunction<WithReplies>;
17
- export declare const parseText: ParseFunction<TextMessageEvent>;
18
- export declare const parsePostback: ParseFunction<PostbackMessageEvent>;
19
- export declare const parseMedia: ParseFunction<AudioMessageEvent | DocumentMessageEvent | ImageMessageEvent | VideoMessageEvent>;
20
- export declare const parseLocation: ParseFunction<LocationMessageEvent>;
21
- export declare const parseElement: (element: any) => CarouselElement;
22
- export declare const parseCarousel: ParseFunction<CarouselMessageEvent>;
23
- export declare const parseCustom: ParseFunction<CustomMessageEvent>;
24
- export declare const parseMissed: ParseFunction<MissedMessageEvent>;
25
- export declare const parseForm: ParseFunction<FormMessageEvent>;
26
- export declare const parseContact: ParseFunction<ContactMessageEvent>;
@@ -1,171 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseContact = exports.parseForm = exports.parseMissed = exports.parseCustom = exports.parseCarousel = exports.parseElement = exports.parseLocation = exports.parseMedia = exports.parsePostback = exports.parseText = exports.parseReplies = exports.parseReply = exports.parseButtons = exports.parseButton = exports.parseMessage = exports.parseBoolean = exports.parseNumber = void 0;
4
- const models_1 = require("../models");
5
- const botonic_output_parser_1 = require("./botonic-output-parser");
6
- function parseNumber(strNumber) {
7
- return parseInt(strNumber);
8
- }
9
- exports.parseNumber = parseNumber;
10
- function parseBoolean(strNumber) {
11
- if (strNumber === '0')
12
- return false;
13
- return true;
14
- }
15
- exports.parseBoolean = parseBoolean;
16
- // COMMON
17
- const parseMessage = args => {
18
- const typingAndDelay = {};
19
- if (args.toParse.delay !== undefined) {
20
- typingAndDelay['delay'] = parseNumber(args.toParse.delay);
21
- }
22
- if (args.toParse.typing !== undefined) {
23
- typingAndDelay['typing'] = parseNumber(args.toParse.typing);
24
- }
25
- return {
26
- toParse: args.toParse,
27
- parsed: Object.assign({
28
- // Following properties added later before saving event: eventId, userId, createdAt, from, ack
29
- eventType: models_1.EventTypes.MESSAGE, type: args.toParse.type, ack: args.toParse.ack, from: args.toParse.from }, typingAndDelay),
30
- };
31
- };
32
- exports.parseMessage = parseMessage;
33
- // BUTTONS
34
- const parseButton = (button) => {
35
- const title = button[botonic_output_parser_1.TEXT_NODE_NAME];
36
- if ('payload' in button) {
37
- return { title, payload: button.payload };
38
- }
39
- if ('url' in button) {
40
- const b = { title, url: button.url, target: button.target };
41
- if (button.target)
42
- b.target = button.target;
43
- return b;
44
- }
45
- if ('webview' in button) {
46
- return {
47
- title,
48
- webview: button.webview,
49
- params: button.params,
50
- };
51
- }
52
- throw new Error('Invalid parsed Button');
53
- };
54
- exports.parseButton = parseButton;
55
- const parseButtons = args => {
56
- var _a, _b;
57
- const hasButtons = ((_b = (_a = args.toParse) === null || _a === void 0 ? void 0 : _a.button) === null || _b === void 0 ? void 0 : _b.length) > 0;
58
- let buttons = [];
59
- if (hasButtons) {
60
- buttons = args.toParse.button.map(button => (0, exports.parseButton)(button));
61
- }
62
- return {
63
- toParse: args.toParse,
64
- parsed: Object.assign(Object.assign({}, args.parsed), { buttons }),
65
- };
66
- };
67
- exports.parseButtons = parseButtons;
68
- // REPLIES
69
- const parseReply = (reply) => ({
70
- title: reply[botonic_output_parser_1.TEXT_NODE_NAME],
71
- payload: reply.payload,
72
- });
73
- exports.parseReply = parseReply;
74
- const parseReplies = args => {
75
- var _a, _b;
76
- const hasReplies = ((_b = (_a = args.toParse) === null || _a === void 0 ? void 0 : _a.reply) === null || _b === void 0 ? void 0 : _b.length) > 0;
77
- let replies = [];
78
- if (hasReplies) {
79
- replies = args.toParse.reply.map(reply => (0, exports.parseReply)(reply));
80
- }
81
- return {
82
- toParse: args.toParse,
83
- parsed: Object.assign(Object.assign({}, args.parsed), { replies }),
84
- };
85
- };
86
- exports.parseReplies = parseReplies;
87
- // TEXT
88
- const parseText = args => {
89
- return {
90
- toParse: args.toParse,
91
- parsed: Object.assign(Object.assign({}, args.parsed), { text: args.toParse[botonic_output_parser_1.TEXT_NODE_NAME], markdown: parseBoolean(args.toParse.markdown) }),
92
- };
93
- };
94
- exports.parseText = parseText;
95
- // POSTBACK
96
- const parsePostback = args => {
97
- return {
98
- toParse: args.toParse,
99
- parsed: Object.assign(Object.assign({}, args.parsed), { payload: args.toParse.payload }),
100
- };
101
- };
102
- exports.parsePostback = parsePostback;
103
- // MEDIA
104
- const parseMedia = args => {
105
- return {
106
- toParse: args.toParse,
107
- parsed: Object.assign(Object.assign({}, args.parsed), { src: args.toParse.src }),
108
- };
109
- };
110
- exports.parseMedia = parseMedia;
111
- // LOCATION
112
- const parseLocation = args => {
113
- return {
114
- toParse: args.toParse,
115
- parsed: Object.assign(Object.assign({}, args.parsed), { lat: args.toParse.lat, long: args.toParse.long }),
116
- };
117
- };
118
- exports.parseLocation = parseLocation;
119
- // CAROUSEL
120
- const parseElement = (element) => {
121
- const e = {
122
- pic: element.pic,
123
- title: element.title,
124
- subtitle: element.desc,
125
- };
126
- const hasButtons = element.button !== undefined;
127
- if (hasButtons)
128
- e.buttons = element.button.map(b => (0, exports.parseButton)(b));
129
- return e;
130
- };
131
- exports.parseElement = parseElement;
132
- const parseCarousel = args => {
133
- return {
134
- toParse: args.toParse,
135
- parsed: Object.assign(Object.assign({}, args.parsed), { elements: args.toParse.element.map(element => (0, exports.parseElement)(element)) }),
136
- };
137
- };
138
- exports.parseCarousel = parseCarousel;
139
- // CUSTOM
140
- const parseCustom = args => {
141
- return {
142
- toParse: args.toParse,
143
- parsed: Object.assign(Object.assign({}, args.parsed), { json: JSON.parse(args.toParse.json) }),
144
- };
145
- };
146
- exports.parseCustom = parseCustom;
147
- // MISSED
148
- const parseMissed = args => {
149
- return {
150
- toParse: args.toParse,
151
- parsed: Object.assign(Object.assign({}, args.parsed), { reason: args.toParse.reason, media_type: args.toParse.media_type }),
152
- };
153
- };
154
- exports.parseMissed = parseMissed;
155
- // FORM
156
- const parseForm = args => {
157
- return {
158
- toParse: args.toParse,
159
- parsed: Object.assign(Object.assign({}, args.parsed), { form_title: args.toParse.form_title, form_answers: args.toParse.form_answers }),
160
- };
161
- };
162
- exports.parseForm = parseForm;
163
- // CONTACT
164
- const parseContact = args => {
165
- return {
166
- toParse: args.toParse,
167
- parsed: Object.assign(Object.assign({}, args.parsed), { phone_number: args.toParse.phone_number, first_name: args.toParse.first_name, last_name: args.toParse.last_name, vcard: args.toParse.vcard }),
168
- };
169
- };
170
- exports.parseContact = parseContact;
171
- //# sourceMappingURL=parsers.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parsers.js","sourceRoot":"","sources":["../../../src/output-parser/parsers.ts"],"names":[],"mappings":";;;AAAA,sCAmBkB;AAElB,mEAAwD;AAExD,SAAgB,WAAW,CAAC,SAAiB;IAC3C,OAAO,QAAQ,CAAC,SAAS,CAAC,CAAA;AAC5B,CAAC;AAFD,kCAEC;AAED,SAAgB,YAAY,CAAC,SAAiB;IAC5C,IAAI,SAAS,KAAK,GAAG;QAAE,OAAO,KAAK,CAAA;IACnC,OAAO,IAAI,CAAA;AACb,CAAC;AAHD,oCAGC;AAOD,SAAS;AACF,MAAM,YAAY,GAAuC,IAAI,CAAC,EAAE;IACrE,MAAM,cAAc,GAAG,EAAE,CAAA;IACzB,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,KAAK,SAAS,EAAE;QACpC,cAAc,CAAC,OAAO,CAA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QAAA,WAAW,eASvB;AAED,OAAO;AACA,MAAM,SAAS,GAAoC,IAAI,CAAC,EAAE;IAC/D,OAAO;QACL,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,MAAM,kCACD,IAAI,CAAC,MAAM,KACd,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU,EACnC,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,YAAY,GACxC;KACF,CAAA;AACH,CAAC,CAAA;AATY,QAAA,SAAS,aASrB;AAED,UAAU;AACH,MAAM,YAAY,GAAuC,IAAI,CAAC,EAAE;IACrE,OAAO;QACL,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,MAAM,kCACD,IAAI,CAAC,MAAM,KACd,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,YAAY,EACvC,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU,EACnC,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS,EACjC,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,GAC1B;KACF,CAAA;AACH,CAAC,CAAA;AAXY,QAAA,YAAY,gBAWxB"}
@@ -1,26 +0,0 @@
1
- import { Entity, Table } from 'dynamodb-toolbox';
2
- import { BotonicEvent, User } from '../models';
3
- import { DataProvider } from './factory';
4
- export declare class DynamoDBDataProvider implements DataProvider {
5
- region: string;
6
- tableName: string;
7
- userEventsTable: Table;
8
- userEntity: Entity<any>;
9
- eventEntity: Entity<any>;
10
- messageEventEntities: Record<string, Entity<any>>;
11
- textMessageEventEntity: Entity<any>;
12
- connectionEventEntity: Entity<any>;
13
- constructor(url: string);
14
- getUsers(limit?: number, offset?: number): Promise<User[]>;
15
- getUser(id: string): Promise<User | undefined>;
16
- getUserByWebsocketId(websocketId: string): Promise<User | undefined>;
17
- getUserByField(field: string, value: any): Promise<User | undefined>;
18
- saveUser(user: User): Promise<User>;
19
- updateUser(user: User): Promise<User>;
20
- deleteUser(id: string): Promise<User | undefined>;
21
- getEvents(limit?: number, offset?: number): Promise<BotonicEvent[]>;
22
- getEvent(id: string): Promise<BotonicEvent | undefined>;
23
- saveEvent(event: BotonicEvent): Promise<BotonicEvent>;
24
- updateEvent(event: BotonicEvent): Promise<BotonicEvent>;
25
- deleteEvent(id: string): Promise<BotonicEvent | undefined>;
26
- }
@@ -1,103 +0,0 @@
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 {
5
- constructor(url) {
6
- try {
7
- const urlParts = url.split('://')[1].split('.');
8
- this.tableName = urlParts[0];
9
- this.region = urlParts[1];
10
- this.userEventsTable = getUserEventsTable(this.tableName, this.region);
11
- this.userEntity = getUserEntity(this.userEventsTable);
12
- this.connectionEventEntity = getConnectionEventEntity(this.userEventsTable);
13
- this.messageEventEntities = getMessageEventEntities(this.userEventsTable);
14
- }
15
- catch (e) {
16
- console.log({ e });
17
- }
18
- }
19
- // @ts-ignore
20
- getUsers(limit = 10, offset = 0) {
21
- return __awaiter(this, void 0, void 0, function* () {
22
- // TODO: finish to implement with offset
23
- const result = yield this.userEventsTable.scan({
24
- filters: { attr: SORT_KEY_NAME, beginsWith: USER_PREFIX },
25
- limit,
26
- });
27
- return result.Items;
28
- });
29
- }
30
- getUser(id) {
31
- return __awaiter(this, void 0, void 0, function* () {
32
- const userById = {
33
- id: id,
34
- SK: id,
35
- };
36
- const result = yield this.userEntity.get(userById);
37
- if (Object.keys(result).length === 0)
38
- return undefined;
39
- return result.Item;
40
- });
41
- }
42
- getUserByWebsocketId(websocketId) {
43
- return __awaiter(this, void 0, void 0, function* () {
44
- const result = yield this.userEventsTable.query(websocketId, {
45
- index: GLOBAL_SECONDARY_INDEX_NAME,
46
- });
47
- if (result.Count === 0)
48
- return undefined;
49
- return result.Items[0];
50
- });
51
- }
52
- // @ts-ignore
53
- getUserByField(field, value) {
54
- return __awaiter(this, void 0, void 0, function* () { });
55
- } //TODO: Implement
56
- saveUser(user) {
57
- return __awaiter(this, void 0, void 0, function* () {
58
- const putUser = Object.assign(Object.assign({}, user), { id: user.id, userId: user.id });
59
- yield this.userEntity.put(putUser);
60
- return user;
61
- });
62
- }
63
- updateUser(user) {
64
- return __awaiter(this, void 0, void 0, function* () {
65
- const updateUser = Object.assign(Object.assign({}, user), { id: user.id, userId: user.id });
66
- const res = yield this.userEntity.update(updateUser);
67
- return user;
68
- });
69
- }
70
- // @ts-ignore
71
- deleteUser(id) {
72
- return __awaiter(this, void 0, void 0, function* () { });
73
- } // TODO: Implement
74
- // @ts-ignore
75
- getEvents(limit = 10, offset = 0) {
76
- return __awaiter(this, void 0, void 0, function* () { });
77
- } // TODO: Implement
78
- // @ts-ignore
79
- getEvent(id) {
80
- return __awaiter(this, void 0, void 0, function* () { });
81
- } // TODO: Implement
82
- saveEvent(event) {
83
- return __awaiter(this, void 0, void 0, function* () {
84
- if (event.eventType === EventTypes.CONNECTION) {
85
- yield this.connectionEventEntity.put(event);
86
- }
87
- if (event.eventType === EventTypes.MESSAGE) {
88
- yield this.messageEventEntities[event.type].put(event);
89
- }
90
- // TODO: Implementation of other event types
91
- return event;
92
- });
93
- }
94
- // @ts-ignore
95
- updateEvent(event) {
96
- return __awaiter(this, void 0, void 0, function* () { });
97
- } // TODO: Implement
98
- // @ts-ignore
99
- deleteEvent(id) {
100
- return __awaiter(this, void 0, void 0, function* () { });
101
- } // TODO: Implement
102
- }
103
- //# sourceMappingURL=dynamodb-data-provider.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dynamodb-data-provider.js","sourceRoot":"","sources":["../../../src/data-provider/dynamodb-data-provider.ts"],"names":[],"mappings":";AAEA,OAAO,EAAgB,UAAU,EAAQ,MAAM,WAAW,CAAA;AAC1D,OAAO,EACL,wBAAwB,EACxB,uBAAuB,EACvB,aAAa,EACb,kBAAkB,EAClB,2BAA2B,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AAC;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,11 +0,0 @@
1
- import { Entity, Table } from 'dynamodb-toolbox';
2
- export declare const GLOBAL_SECONDARY_INDEX_NAME = "GSI1";
3
- export declare const GLOBAL_SECONDARY_INDEX_ATTR = "websocketId";
4
- export declare const PARTITION_KEY_NAME = "PK";
5
- export declare const SORT_KEY_NAME = "SK";
6
- export declare const USER_PREFIX = "USR#";
7
- export declare const EVENT_PREFIX = "EVT#";
8
- export declare function getUserEventsTable(tableName: string, region: string): Table;
9
- export declare function getUserEntity(table: Table): Entity<any>;
10
- export declare function getConnectionEventEntity(table: Table): Entity<any>;
11
- export declare function getMessageEventEntities(table: Table): Record<string, Entity<any>>;
@@ -1,113 +0,0 @@
1
- import DynamoDB from 'aws-sdk/clients/dynamodb';
2
- import { Entity, Table } from 'dynamodb-toolbox';
3
- import { MessageEventTypes } from '../models';
4
- // Table Definitions
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';
9
- // Entities Definitions
10
- export const USER_PREFIX = 'USR#';
11
- export const EVENT_PREFIX = 'EVT#';
12
- function capitalize(string) {
13
- return string.charAt(0).toUpperCase() + string.slice(1);
14
- }
15
- export function getUserEventsTable(tableName, region) {
16
- const documentClient = new DynamoDB.DocumentClient({
17
- apiVersion: '2012-08-10',
18
- region: region,
19
- });
20
- return new Table({
21
- name: tableName,
22
- partitionKey: PARTITION_KEY_NAME,
23
- sortKey: SORT_KEY_NAME,
24
- entityField: true,
25
- indexes: {
26
- GSI1: {
27
- partitionKey: GLOBAL_SECONDARY_INDEX_ATTR,
28
- },
29
- },
30
- DocumentClient: documentClient,
31
- });
32
- }
33
- export function getUserEntity(table) {
34
- return new Entity({
35
- name: 'User',
36
- attributes: {
37
- id: { partitionKey: true, prefix: USER_PREFIX },
38
- [`${SORT_KEY_NAME}`]: {
39
- hidden: true,
40
- sortKey: true,
41
- prefix: USER_PREFIX,
42
- },
43
- userId: [SORT_KEY_NAME, 0],
44
- websocketId: 'string',
45
- isOnline: 'boolean',
46
- route: 'string',
47
- session: 'string',
48
- },
49
- table,
50
- });
51
- }
52
- export function getConnectionEventEntity(table) {
53
- return new Entity({
54
- name: 'Connection Event',
55
- attributes: {
56
- userId: { partitionKey: true, prefix: USER_PREFIX },
57
- [`${SORT_KEY_NAME}`]: {
58
- hidden: true,
59
- sortKey: true,
60
- prefix: EVENT_PREFIX,
61
- },
62
- eventId: [SORT_KEY_NAME, 0],
63
- eventType: 'string',
64
- createdAt: 'string',
65
- modifiedAt: 'string',
66
- status: 'string',
67
- },
68
- table,
69
- });
70
- }
71
- export function getMessageEventEntities(table) {
72
- const textAttributes = {
73
- text: 'string',
74
- markdown: 'boolean',
75
- buttons: 'list',
76
- replies: 'list',
77
- };
78
- const mediaAttributes = {
79
- src: 'string',
80
- buttons: 'list',
81
- };
82
- const locationAttributes = {
83
- lat: 'number',
84
- long: 'number',
85
- };
86
- const carouselAttributes = {
87
- elements: 'list',
88
- };
89
- const customAttributes = {
90
- json: 'map',
91
- replies: 'list',
92
- };
93
- const entityWithAttributes = (type, attributes) => new Entity({
94
- name: `${capitalize(type)} Message Event`,
95
- attributes: Object.assign({ userId: { partitionKey: true, prefix: USER_PREFIX }, [`${SORT_KEY_NAME}`]: {
96
- hidden: true,
97
- sortKey: true,
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),
100
- table,
101
- });
102
- return {
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),
111
- };
112
- }
113
- //# sourceMappingURL=dynamodb-utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dynamodb-utils.js","sourceRoot":"","sources":["../../../src/data-provider/dynamodb-utils.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,0BAA0B,CAAA;AAC/C,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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AAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,EACnD,CAAC,GAAG,aAAa,EAAE,CAAC,EAAE;gBACpB,MAAM,EAAE,IAAI;gBACZ,OAAO,EAAE,IAAI;gBACb,MAAM,EAAE,YAAY;aACrB,EACD,OAAO,EAAE,CAAC,aAAa,EAAE,CAAC,CAAC,EAC3B,SAAS,EAAE,QAAQ,EACnB,SAAS,EAAE,QAAQ,EACnB,UAAU,EAAE,QAAQ,EACpB,IAAI,EAAE,QAAQ,EACd,GAAG,EAAE,QAAQ,EACb,MAAM,EAAE,QAAQ,EAChB,KAAK,EAAE,QAAQ,EACf,IAAI,EAAE,QAAQ,IACX,UAAU,CACd;QACD,KAAK;KACN,CAAC,CAAA;IAEJ,OAAO;QACL,IAAI,EAAE,oBAAoB,CAAC,iBAAiB,CAAC,IAAI,EAAE,cAAc,CAAC;QAClE,KAAK,EAAE,oBAAoB,CAAC,iBAAiB,CAAC,KAAK,EAAE,eAAe,CAAC;QACrE,KAAK,EAAE,oBAAoB,CAAC,iBAAiB,CAAC,KAAK,EAAE,eAAe,CAAC;QACrE,QAAQ,EAAE,oBAAoB,CAAC,iBAAiB,CAAC,QAAQ,EAAE,eAAe,CAAC;QAC3E,KAAK,EAAE,oBAAoB,CAAC,iBAAiB,CAAC,KAAK,EAAE,eAAe,CAAC;QACrE,QAAQ,EAAE,oBAAoB,CAC5B,iBAAiB,CAAC,QAAQ,EAC1B,kBAAkB,CACnB;QACD,QAAQ,EAAE,oBAAoB,CAC5B,iBAAiB,CAAC,QAAQ,EAC1B,kBAAkB,CACnB;QACD,MAAM,EAAE,oBAAoB,CAAC,iBAAiB,CAAC,MAAM,EAAE,gBAAgB,CAAC;KACzE,CAAA;AACH,CAAC"}
@@ -1,25 +0,0 @@
1
- import { BotonicEvent, User } from '../models';
2
- export declare const dataProviderProtocols: {
3
- DYNAMO_DB: string;
4
- FILE: string;
5
- };
6
- export interface DataProvider {
7
- getUsers(limit?: number, offset?: number): User[] | Promise<User[]>;
8
- getUser(id: string): User | Promise<User | undefined> | undefined;
9
- getUserByWebsocketId(websocketId: string): User | Promise<User | undefined> | undefined;
10
- getUserByField(field: string, value: any): User | Promise<User | undefined> | undefined;
11
- saveUser(user: User): User | Promise<User>;
12
- updateUser(user: User): User | Promise<User>;
13
- deleteUser(id: string): User | Promise<User | undefined> | undefined;
14
- getEvents(limit?: number, offset?: number): BotonicEvent[] | Promise<BotonicEvent[]>;
15
- getEvent(id: string): BotonicEvent | Promise<BotonicEvent | undefined> | undefined;
16
- saveEvent(event: BotonicEvent): BotonicEvent | Promise<BotonicEvent>;
17
- updateEvent(event: BotonicEvent): BotonicEvent | Promise<BotonicEvent>;
18
- deleteEvent(id: string): BotonicEvent | Promise<BotonicEvent | undefined> | undefined;
19
- }
20
- /** URL examples:
21
- * dynamodb://my-table.my-region.aws.com
22
- * postgresql://my-database.my-db-provider.com
23
- * file://path/to/local/db.json
24
- */
25
- export declare function dataProviderFactory(url?: string): DataProvider;
@@ -1,27 +0,0 @@
1
- import { DynamoDBDataProvider } from './dynamodb-data-provider';
2
- import { LocalDevDataProvider } from './local-data-provider';
3
- export const dataProviderProtocols = {
4
- DYNAMO_DB: 'dynamodb',
5
- FILE: 'file',
6
- };
7
- /** URL examples:
8
- * dynamodb://my-table.my-region.aws.com
9
- * postgresql://my-database.my-db-provider.com
10
- * file://path/to/local/db.json
11
- */
12
- export function dataProviderFactory(url) {
13
- if (!url) {
14
- return new LocalDevDataProvider();
15
- }
16
- const protocol = url.split('://')[0];
17
- switch (protocol) {
18
- case dataProviderProtocols.DYNAMO_DB:
19
- return new DynamoDBDataProvider(url);
20
- case dataProviderProtocols.FILE:
21
- return new LocalDevDataProvider(url);
22
- default:
23
- console.error(`Protocol ${protocol} not implemented, using local DB instead.`);
24
- return new LocalDevDataProvider();
25
- }
26
- }
27
- //# sourceMappingURL=factory.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../src/data-provider/factory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAA;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAA;AAE5D,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,SAAS,EAAE,UAAU;IACrB,IAAI,EAAE,MAAM;CACb,CAAA;AA8BD;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,GAAY;IAC9C,IAAI,CAAC,GAAG,EAAE;QACR,OAAO,IAAI,oBAAoB,EAAE,CAAA;KAClC;IAED,MAAM,QAAQ,GAAG,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;IACpC,QAAQ,QAAQ,EAAE;QAChB,KAAK,qBAAqB,CAAC,SAAS;YAClC,OAAO,IAAI,oBAAoB,CAAC,GAAG,CAAC,CAAA;QACtC,KAAK,qBAAqB,CAAC,IAAI;YAC7B,OAAO,IAAI,oBAAoB,CAAC,GAAG,CAAC,CAAA;QACtC;YACE,OAAO,CAAC,KAAK,CACX,YAAY,QAAQ,2CAA2C,CAChE,CAAA;YACD,OAAO,IAAI,oBAAoB,EAAE,CAAA;KACpC;AACH,CAAC"}
@@ -1,4 +0,0 @@
1
- export * from './dynamodb-data-provider';
2
- export * from './dynamodb-utils';
3
- export * from './factory';
4
- export * from './local-data-provider';
@@ -1,5 +0,0 @@
1
- export * from './dynamodb-data-provider';
2
- export * from './dynamodb-utils';
3
- export * from './factory';
4
- export * from './local-data-provider';
5
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/data-provider/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAA;AACxC,cAAc,kBAAkB,CAAA;AAChC,cAAc,WAAW,CAAA;AACzB,cAAc,uBAAuB,CAAA"}
@@ -1,26 +0,0 @@
1
- import { JsonDB } from 'node-json-db';
2
- import { BotonicEvent, User } from '../models';
3
- import { DataProvider } from './factory';
4
- export declare class LocalDevDataProvider implements DataProvider {
5
- private readonly DB_PATH;
6
- private readonly SEPARATOR;
7
- private readonly paths;
8
- db: JsonDB;
9
- constructor(url?: string);
10
- getUsers(limit?: number, offset?: number): User[];
11
- getUser(userId: string): User | undefined;
12
- getUserByWebsocketId(websocketId: string): User | undefined;
13
- getUserByField(field: string, value: any): User | undefined;
14
- saveUser(user: User): User;
15
- updateUser(user: User): User;
16
- deleteUser(id: string): User | undefined;
17
- getEvents(limit?: number, offset?: number): BotonicEvent[];
18
- getEvent(id: string): BotonicEvent | undefined;
19
- saveEvent(event: BotonicEvent): BotonicEvent;
20
- updateEvent(event: BotonicEvent): BotonicEvent;
21
- deleteEvent(id: string): BotonicEvent | undefined;
22
- addConnection(websocketId: string): void;
23
- updateConnection(websocketId: string, userId: string): void;
24
- deleteConnection(websocketId: string): void;
25
- private createPath;
26
- }