@nlabs/reaktor 0.1.2 → 0.1.3

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 (144) hide show
  1. package/.DS_Store +0 -0
  2. package/lib/config.d.ts +21 -0
  3. package/lib/config.js +130 -0
  4. package/lib/data/conversations.d.ts +6 -0
  5. package/lib/data/conversations.js +197 -0
  6. package/lib/data/dynamodb.d.ts +8 -0
  7. package/lib/data/dynamodb.js +139 -0
  8. package/lib/data/email.d.ts +7 -0
  9. package/lib/data/email.js +163 -0
  10. package/lib/data/files.d.ts +16 -0
  11. package/lib/data/files.js +406 -0
  12. package/lib/data/groups.d.ts +13 -0
  13. package/lib/data/groups.js +354 -0
  14. package/lib/data/images.d.ts +12 -0
  15. package/lib/data/images.js +667 -0
  16. package/{src/data/index.ts → lib/data/index.d.ts} +1 -5
  17. package/lib/data/index.js +24 -0
  18. package/lib/data/ios.d.ts +6 -0
  19. package/lib/data/ios.js +302 -0
  20. package/lib/data/locations.d.ts +3 -0
  21. package/lib/data/locations.js +132 -0
  22. package/lib/data/messages.d.ts +9 -0
  23. package/lib/data/messages.js +248 -0
  24. package/lib/data/notifications.d.ts +5 -0
  25. package/lib/data/notifications.js +42 -0
  26. package/lib/data/payments.d.ts +11 -0
  27. package/lib/data/payments.js +748 -0
  28. package/lib/data/posts.d.ts +22 -0
  29. package/lib/data/posts.js +578 -0
  30. package/lib/data/reactions.d.ts +6 -0
  31. package/lib/data/reactions.js +218 -0
  32. package/lib/data/s3.d.ts +6 -0
  33. package/lib/data/s3.js +103 -0
  34. package/lib/data/search.d.ts +3 -0
  35. package/lib/data/search.js +98 -0
  36. package/lib/data/sms.d.ts +3 -0
  37. package/lib/data/sms.js +59 -0
  38. package/lib/data/subscription.d.ts +7 -0
  39. package/lib/data/subscription.js +284 -0
  40. package/lib/data/tags.d.ts +14 -0
  41. package/lib/data/tags.js +304 -0
  42. package/lib/data/users.d.ts +12 -0
  43. package/lib/data/users.js +310 -0
  44. package/lib/index.d.ts +3 -0
  45. package/lib/index.js +8 -0
  46. package/lib/types/apps.d.ts +43 -0
  47. package/lib/types/apps.js +2 -0
  48. package/lib/types/arangodb.d.ts +17 -0
  49. package/lib/types/arangodb.js +2 -0
  50. package/lib/types/auth.d.ts +10 -0
  51. package/lib/types/auth.js +2 -0
  52. package/lib/types/conversations.d.ts +6 -0
  53. package/lib/types/conversations.js +2 -0
  54. package/lib/types/email.d.ts +12 -0
  55. package/lib/types/email.js +2 -0
  56. package/lib/types/files.d.ts +26 -0
  57. package/lib/types/files.js +2 -0
  58. package/lib/types/google.d.ts +27 -0
  59. package/lib/types/google.js +2 -0
  60. package/lib/types/groups.d.ts +21 -0
  61. package/lib/types/groups.js +2 -0
  62. package/lib/types/images.d.ts +24 -0
  63. package/lib/types/images.js +2 -0
  64. package/{src/types/index.ts → lib/types/index.d.ts} +0 -4
  65. package/lib/types/index.js +22 -0
  66. package/lib/types/locations.d.ts +20 -0
  67. package/lib/types/locations.js +2 -0
  68. package/lib/types/messages.d.ts +12 -0
  69. package/lib/types/messages.js +2 -0
  70. package/lib/types/notifications.d.ts +19 -0
  71. package/lib/types/notifications.js +2 -0
  72. package/lib/types/payments.d.ts +114 -0
  73. package/lib/types/payments.js +2 -0
  74. package/lib/types/posts.d.ts +28 -0
  75. package/lib/types/posts.js +2 -0
  76. package/lib/types/reactions.d.ts +4 -0
  77. package/lib/types/reactions.js +2 -0
  78. package/lib/types/tags.d.ts +9 -0
  79. package/lib/types/tags.js +2 -0
  80. package/lib/types/users.d.ts +78 -0
  81. package/lib/types/users.js +2 -0
  82. package/lib/utils/analytics.d.ts +3 -0
  83. package/lib/utils/analytics.js +47 -0
  84. package/lib/utils/arangodb.d.ts +9 -0
  85. package/lib/utils/arangodb.js +98 -0
  86. package/lib/utils/auth.d.ts +7 -0
  87. package/lib/utils/auth.js +80 -0
  88. package/lib/utils/graphql.d.ts +1 -0
  89. package/lib/utils/graphql.js +7 -0
  90. package/{src/utils/index.ts → lib/utils/index.d.ts} +0 -4
  91. package/lib/utils/index.js +11 -0
  92. package/lib/utils/objects.d.ts +3 -0
  93. package/lib/utils/objects.js +34 -0
  94. package/lib/utils/redis.d.ts +1 -0
  95. package/lib/utils/redis.js +15 -0
  96. package/package.json +5 -5
  97. package/.vscode/extensions.json +0 -15
  98. package/.vscode/settings.json +0 -82
  99. package/lex.config.js +0 -4
  100. package/src/config.ts +0 -127
  101. package/src/data/conversations.ts +0 -181
  102. package/src/data/dynamodb.ts +0 -157
  103. package/src/data/email.ts +0 -163
  104. package/src/data/files.ts +0 -352
  105. package/src/data/groups.ts +0 -308
  106. package/src/data/images.ts +0 -606
  107. package/src/data/ios.ts +0 -249
  108. package/src/data/locations.ts +0 -114
  109. package/src/data/messages.ts +0 -237
  110. package/src/data/notifications.ts +0 -48
  111. package/src/data/payments.ts +0 -675
  112. package/src/data/posts.ts +0 -580
  113. package/src/data/reactions.ts +0 -186
  114. package/src/data/s3.ts +0 -117
  115. package/src/data/search.ts +0 -74
  116. package/src/data/sms.ts +0 -60
  117. package/src/data/subscription.ts +0 -228
  118. package/src/data/tags.ts +0 -230
  119. package/src/data/users.ts +0 -254
  120. package/src/index.ts +0 -7
  121. package/src/types/apps.ts +0 -56
  122. package/src/types/arangodb.ts +0 -23
  123. package/src/types/auth.ts +0 -20
  124. package/src/types/conversations.ts +0 -11
  125. package/src/types/email.ts +0 -17
  126. package/src/types/files.ts +0 -31
  127. package/src/types/google.ts +0 -37
  128. package/src/types/groups.ts +0 -27
  129. package/src/types/images.ts +0 -32
  130. package/src/types/locations.ts +0 -24
  131. package/src/types/messages.ts +0 -16
  132. package/src/types/notifications.ts +0 -26
  133. package/src/types/payments.ts +0 -129
  134. package/src/types/posts.ts +0 -34
  135. package/src/types/reactions.ts +0 -8
  136. package/src/types/tags.ts +0 -13
  137. package/src/types/users.ts +0 -89
  138. package/src/utils/analytics.ts +0 -41
  139. package/src/utils/arangodb.ts +0 -100
  140. package/src/utils/auth.ts +0 -61
  141. package/src/utils/graphql.ts +0 -7
  142. package/src/utils/objects.ts +0 -34
  143. package/src/utils/redis.ts +0 -17
  144. package/tsconfig.json +0 -45
@@ -1,308 +0,0 @@
1
- import {createHash, parseChar, parseId} from '@nlabs/utils';
2
- import {aql, Database} from 'arangojs';
3
- import {AqlQuery} from 'arangojs/lib/cjs/aql-query';
4
- import {ArrayCursor} from 'arangojs/lib/cjs/cursor';
5
- import flatten from 'lodash/flatten';
6
- import uniqBy from 'lodash/uniqBy';
7
-
8
- import {ArangoDBLimit} from '../types/arangodb';
9
- import {ApiContext} from '../types/auth';
10
- import {GroupEdgeType, GroupType, GroupUserType} from '../types/groups';
11
- import {getLimit, logError, useDb} from '../utils';
12
- import {extractTags} from './tags';
13
-
14
- /**
15
- * Copyright (c) 2019-Present, Nitrogen Labs, Inc.
16
- * Copyrights licensed under the MIT License. See the accompanying LICENSE file for terms.
17
- */
18
-
19
- const eventCategory: string = 'groups';
20
-
21
- export const getGroupList = (context: ApiContext, from: number, to: number): Promise<GroupType[]> => {
22
- const action: string = 'getListByApp';
23
- const {database} = context;
24
- const limit: ArangoDBLimit = getLimit(from, to);
25
- const aqlQry: string = `FOR g in groups
26
- LET users = (
27
- FOR u, l IN OUTBOUND g._id isGrouped
28
- RETURN MERGE (u, {type:l.type})
29
- )
30
- ${limit.aql}
31
- SORT g.added
32
- RETURN DISTINCT MERGE(g, {users:users})`;
33
-
34
- return useDb(database).query(aqlQry)
35
- .then((cursor: ArrayCursor) => cursor.all())
36
- .catch((error: Error) => logError({
37
- action,
38
- category: eventCategory,
39
- label: 'db_error'
40
- }, error, context).then(() => null));
41
- };
42
-
43
- export const getGroupListByUser = (context: ApiContext, from: number, to: number): Promise<GroupType[]> => {
44
- // const action: string = 'getListByUser';
45
- const {database, userId: sessionId} = context;
46
- const limit: ArangoDBLimit = getLimit(from, to);
47
- const aqlQry: string = `FOR g, e IN INBOUND "${`users/${sessionId}`}" isGrouped
48
- LET users = (
49
- FOR u, l IN OUTBOUND g._id isGrouped
50
- RETURN MERGE (u, {type:l.type})
51
- )
52
- ${limit.aql}
53
- SORT g.added
54
- RETURN DISTINCT MERGE(g, {users:users})`;
55
-
56
- return useDb(database).query(aqlQry)
57
- .then((cursor: ArrayCursor) => cursor.all())
58
- .catch((error: Error) => {
59
- throw error;
60
- });
61
- };
62
-
63
- export const getGroupListByTags = (context: ApiContext, tags: string[], from: number, to: number): Promise<GroupType[]> => {
64
- const action: string = 'getListByTags';
65
- const {database} = context;
66
-
67
- return Promise.all(
68
- (tags || []).map((tagName: string) => {
69
- const formatTagName: string = parseId(tagName);
70
- const limit: ArangoDBLimit = getLimit(from, to);
71
- const aqlQry: string = `FOR p, e IN OUTBOUND "${`tags/${formatTagName}`}" isTagged
72
- FOR u IN users
73
- LET likes = (
74
- FOR post, like IN INBOUND p._id likes
75
- FILTER like.value == 'like'
76
- RETURN like
77
- )
78
- LET dislikes = (
79
- FOR post, like IN INBOUND p._id likes
80
- FILTER like.value == 'dislike'
81
- RETURN like
82
- )
83
- FILTER e.type == 'post' && p.userId == u._key
84
- ${limit.aql}
85
- SORT p.added
86
- RETURN DISTINCT MERGE(p, {user:u, likes:LENGTH(likes), dislikes:LENGTH(dislikes)})`;
87
-
88
- return useDb(database).query(aqlQry).then((cursor: ArrayCursor) => cursor.all());
89
- })
90
- )
91
- .then((results) => uniqBy(flatten(results), '_key'))
92
- .catch((error: Error) => logError({
93
- action,
94
- category: eventCategory,
95
- label: 'db_error'
96
- }, error, context).then(() => null));
97
- };
98
-
99
- export const getGroup = (context: ApiContext, itemId: string): Promise<GroupType> => {
100
- const action: string = 'getItem';
101
- const {database, userId: sessionId} = context;
102
- const formatItemId: string = parseId(itemId);
103
-
104
- const aqlQry: AqlQuery = aql`FOR g, e IN INBOUND ${`users/${sessionId}`} isGrouped
105
- FILTER g._key == ${formatItemId}
106
- LET users = (
107
- FOR u, l IN OUTBOUND g._id isGrouped
108
- RETURN MERGE (u, {type:l.type})
109
- )
110
- LIMIT 1
111
- RETURN DISTINCT MERGE(g, {users:users})`;
112
-
113
- return useDb(database).query(aqlQry)
114
- .then((cursor: ArrayCursor) => cursor.next())
115
- .then((group: GroupType = {}) => group)
116
- .catch((error: Error) => logError({
117
- action,
118
- category: eventCategory,
119
- label: 'db_error'
120
- }, error, context).then(() => null));
121
- };
122
-
123
- export const getGroupDetails = (context: ApiContext, groupId: string): Promise<GroupType> => {
124
- const action: string = 'getDetails';
125
- const {database} = context;
126
- const formatGroupId: string = parseId(groupId);
127
- const aqlQry: AqlQuery = aql`FOR g IN groups
128
- FILTER g._key == ${formatGroupId}
129
- LIMIT 1
130
- RETURN g`;
131
-
132
- return useDb(database).query(aqlQry)
133
- .then((cursor: ArrayCursor) => cursor.next())
134
- .then((group: GroupType = {}) => group)
135
- .catch((error: Error) => logError({
136
- action,
137
- category: eventCategory,
138
- label: 'db_error'
139
- }, error, context).then(() => null));
140
- };
141
-
142
- export const addGroup = (context: ApiContext, item: GroupType = {}): Promise<GroupType> => {
143
- const action: string = 'add';
144
- const {database, userId: sessionId} = context;
145
- const now: number = Date.now();
146
- const {
147
- description = '',
148
- name = 'Untitled',
149
- type
150
- }: GroupType = item;
151
- const id: string = createHash(`group-${sessionId}`);
152
- const formatDesc: string = description.substr(0, 640);
153
- const formatType: string = parseChar(type, 16) || 'private';
154
- const insert: GroupType = {
155
- _key: id,
156
- added: now,
157
- description: formatDesc,
158
- modified: now,
159
- name,
160
- type: formatType
161
- };
162
- const db: Database = useDb(database);
163
- const aqlQry: AqlQuery = aql`INSERT ${insert} IN groups RETURN NEW`;
164
-
165
- return db.query(aqlQry)
166
- .then((cursor: ArrayCursor) => cursor.next())
167
- .then((group: GroupType = {}) => {
168
- const itemType: string = 'groups';
169
-
170
- // Update linked tags
171
- const {_key: groupId}: GroupType = group;
172
- return extractTags(db, itemType, groupId, formatDesc)
173
- .then(() => createGroupEdge(database, sessionId, groupId, 'admin').then(() => group));
174
- })
175
- .catch((error: Error) => logError({
176
- action,
177
- category: eventCategory,
178
- label: 'db_error'
179
- }, error, context).then(() => null));
180
- };
181
-
182
- export const updateGroup = (context: ApiContext, item: GroupType = {}): Promise<GroupType> => {
183
- const action: string = 'update';
184
- const {database} = context;
185
- const {
186
- description = '',
187
- id,
188
- name = 'Untitled'
189
- }: GroupType = item;
190
- const itemId: string = parseId(id);
191
- const now: number = Date.now();
192
- const formatDesc: string = description.substr(0, 640);
193
- const update: any = {
194
- description: formatDesc,
195
- modified: now,
196
- name
197
- };
198
- const db: Database = useDb(database);
199
- const aqlQry: AqlQuery = aql`UPDATE ${itemId} WITH ${update} IN groups RETURN NEW`;
200
-
201
- return db.query(aqlQry)
202
- .then((cursor: ArrayCursor) => cursor.next())
203
- .then((group: GroupType = {}) => {
204
- const {_key: groupKey} = group;
205
- const itemType: string = 'groups';
206
-
207
- // Update linked tags
208
- return extractTags(db, itemType, groupKey, description).then(() => group);
209
- })
210
- .catch((error: Error) => logError({
211
- action,
212
- category: eventCategory,
213
- label: 'db_error'
214
- }, error, context).then(() => null));
215
- };
216
-
217
- export const deleteGroup = (context: ApiContext, itemId: string): Promise<GroupType> => {
218
- const action: string = 'delete';
219
- const {database} = context;
220
- const formatItemId: string = parseId(itemId);
221
- const aqlQry: AqlQuery = aql`FOR g IN groups
222
- FILTER g._key == ${formatItemId}
223
- REMOVE g IN groups
224
- RETURN OLD`;
225
-
226
- return useDb(database).query(aqlQry)
227
- .then((cursor: ArrayCursor) => cursor.next())
228
- .then((group: GroupType = {}) => group)
229
- .catch((error: Error) => logError({
230
- action,
231
- category: eventCategory,
232
- label: 'db_error'
233
- }, error, context).then(() => null));
234
- };
235
-
236
- export const getGroupsByReaction = (context: ApiContext, reaction: string): Promise<GroupType[]> => {
237
- const action: string = 'getGroupsByReaction';
238
- const {database, userId: sessionId} = context;
239
- const formatReaction: string = parseChar(reaction, 32);
240
- const userDocId: string = `users/${sessionId}`;
241
-
242
- // Query
243
- const aqlQry: AqlQuery = aql`FOR u, r IN OUTBOUND ${userDocId} hasReaction
244
- FILTER r.value == ${formatReaction}
245
- COLLECT reactionName = r.value INTO reactionItems
246
- RETURN {value: reactionName, count: LENGTH(reactionItems[*].r.value)}`;
247
-
248
- return useDb(database).query(aqlQry)
249
- .then((cursor: ArrayCursor) => cursor.all())
250
- .catch((error: Error) => logError({
251
- action,
252
- category: eventCategory,
253
- label: 'db_error'
254
- }, error, context).then(() => null));
255
- };
256
-
257
- export const isGrouped = (database: string, userId: string, groupId: string): Promise<GroupUserType> => {
258
- const action: string = 'isGrouped';
259
- const formatUserId: string = parseId(userId);
260
- const formatGroupId: string = parseId(groupId);
261
- const aqlQry: AqlQuery = aql`FOR g IN groups
262
- FILTER g._key == ${formatGroupId}
263
- FOR u IN INBOUND g._id isGrouped
264
- FILTER u._key == ${formatUserId}
265
- LIMIT 1
266
- RETURN u`;
267
-
268
- return useDb(database).query(aqlQry)
269
- .then((cursor: ArrayCursor) => cursor.all())
270
- .then((results = []) => {
271
- const isValid = !!results.length;
272
-
273
- return {
274
- groupId,
275
- isValid,
276
- userId
277
- };
278
- })
279
- .catch((error: Error) => logError({
280
- action,
281
- category: eventCategory,
282
- label: 'db_error'
283
- }, error, {id: userId}).then(() => null));
284
- };
285
-
286
- export const createGroupEdge = (database: string, userId: string, groupId: string, type: string): Promise<GroupEdgeType> => {
287
- const action: string = 'createGroupEdge';
288
- const formatUserId: string = parseId(userId);
289
- const formatGroupId: string = parseId(groupId);
290
- const formatType: string = parseChar(type, 16);
291
-
292
- const now: number = Date.now();
293
- const edgeCollection = useDb(database).edgeCollection('isGrouped');
294
- const edgeId: string = createHash(`group-${formatUserId}-${formatGroupId}`);
295
-
296
- const edge: any = {
297
- _key: edgeId,
298
- added: now,
299
- type: formatType
300
- };
301
-
302
- return edgeCollection.save(edge, `users/${formatUserId}`, `groups/${formatGroupId}`)
303
- .catch((error: Error) => logError({
304
- action,
305
- category: eventCategory,
306
- label: 'db_error'
307
- }, error, {id: formatUserId}).then(() => null));
308
- };