@nlabs/reaktor 0.1.2 → 0.1.4

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 (145) hide show
  1. package/.DS_Store +0 -0
  2. package/.eslintrc +18 -0
  3. package/lib/config.d.ts +21 -0
  4. package/lib/config.js +130 -0
  5. package/lib/data/conversations.d.ts +6 -0
  6. package/lib/data/conversations.js +197 -0
  7. package/lib/data/dynamodb.d.ts +8 -0
  8. package/lib/data/dynamodb.js +139 -0
  9. package/lib/data/email.d.ts +7 -0
  10. package/lib/data/email.js +163 -0
  11. package/lib/data/files.d.ts +16 -0
  12. package/lib/data/files.js +406 -0
  13. package/lib/data/groups.d.ts +13 -0
  14. package/lib/data/groups.js +354 -0
  15. package/lib/data/images.d.ts +12 -0
  16. package/lib/data/images.js +667 -0
  17. package/{src/data/index.ts → lib/data/index.d.ts} +1 -5
  18. package/lib/data/index.js +24 -0
  19. package/lib/data/ios.d.ts +6 -0
  20. package/lib/data/ios.js +302 -0
  21. package/lib/data/locations.d.ts +3 -0
  22. package/lib/data/locations.js +132 -0
  23. package/lib/data/messages.d.ts +9 -0
  24. package/lib/data/messages.js +248 -0
  25. package/lib/data/notifications.d.ts +5 -0
  26. package/lib/data/notifications.js +42 -0
  27. package/lib/data/payments.d.ts +11 -0
  28. package/lib/data/payments.js +748 -0
  29. package/lib/data/posts.d.ts +22 -0
  30. package/lib/data/posts.js +579 -0
  31. package/lib/data/reactions.d.ts +6 -0
  32. package/lib/data/reactions.js +218 -0
  33. package/lib/data/s3.d.ts +6 -0
  34. package/lib/data/s3.js +103 -0
  35. package/lib/data/search.d.ts +3 -0
  36. package/lib/data/search.js +98 -0
  37. package/lib/data/sms.d.ts +3 -0
  38. package/lib/data/sms.js +59 -0
  39. package/lib/data/subscription.d.ts +7 -0
  40. package/lib/data/subscription.js +284 -0
  41. package/lib/data/tags.d.ts +14 -0
  42. package/lib/data/tags.js +304 -0
  43. package/lib/data/users.d.ts +12 -0
  44. package/lib/data/users.js +310 -0
  45. package/lib/index.d.ts +3 -0
  46. package/lib/index.js +8 -0
  47. package/lib/types/apps.d.ts +43 -0
  48. package/lib/types/apps.js +2 -0
  49. package/lib/types/arangodb.d.ts +17 -0
  50. package/lib/types/arangodb.js +2 -0
  51. package/lib/types/auth.d.ts +10 -0
  52. package/lib/types/auth.js +2 -0
  53. package/lib/types/conversations.d.ts +6 -0
  54. package/lib/types/conversations.js +2 -0
  55. package/lib/types/email.d.ts +12 -0
  56. package/lib/types/email.js +2 -0
  57. package/lib/types/files.d.ts +26 -0
  58. package/lib/types/files.js +2 -0
  59. package/lib/types/google.d.ts +27 -0
  60. package/lib/types/google.js +2 -0
  61. package/lib/types/groups.d.ts +21 -0
  62. package/lib/types/groups.js +2 -0
  63. package/lib/types/images.d.ts +24 -0
  64. package/lib/types/images.js +2 -0
  65. package/{src/types/index.ts → lib/types/index.d.ts} +0 -4
  66. package/lib/types/index.js +22 -0
  67. package/lib/types/locations.d.ts +20 -0
  68. package/lib/types/locations.js +2 -0
  69. package/lib/types/messages.d.ts +12 -0
  70. package/lib/types/messages.js +2 -0
  71. package/lib/types/notifications.d.ts +19 -0
  72. package/lib/types/notifications.js +2 -0
  73. package/lib/types/payments.d.ts +114 -0
  74. package/lib/types/payments.js +2 -0
  75. package/lib/types/posts.d.ts +28 -0
  76. package/lib/types/posts.js +2 -0
  77. package/lib/types/reactions.d.ts +4 -0
  78. package/lib/types/reactions.js +2 -0
  79. package/lib/types/tags.d.ts +9 -0
  80. package/lib/types/tags.js +2 -0
  81. package/lib/types/users.d.ts +78 -0
  82. package/lib/types/users.js +2 -0
  83. package/lib/utils/analytics.d.ts +3 -0
  84. package/lib/utils/analytics.js +47 -0
  85. package/lib/utils/arangodb.d.ts +9 -0
  86. package/lib/utils/arangodb.js +98 -0
  87. package/lib/utils/auth.d.ts +7 -0
  88. package/lib/utils/auth.js +80 -0
  89. package/lib/utils/graphql.d.ts +1 -0
  90. package/lib/utils/graphql.js +7 -0
  91. package/{src/utils/index.ts → lib/utils/index.d.ts} +0 -4
  92. package/lib/utils/index.js +11 -0
  93. package/lib/utils/objects.d.ts +3 -0
  94. package/lib/utils/objects.js +34 -0
  95. package/lib/utils/redis.d.ts +1 -0
  96. package/lib/utils/redis.js +15 -0
  97. package/package.json +8 -7
  98. package/.vscode/extensions.json +0 -15
  99. package/.vscode/settings.json +0 -82
  100. package/lex.config.js +0 -4
  101. package/src/config.ts +0 -127
  102. package/src/data/conversations.ts +0 -181
  103. package/src/data/dynamodb.ts +0 -157
  104. package/src/data/email.ts +0 -163
  105. package/src/data/files.ts +0 -352
  106. package/src/data/groups.ts +0 -308
  107. package/src/data/images.ts +0 -606
  108. package/src/data/ios.ts +0 -249
  109. package/src/data/locations.ts +0 -114
  110. package/src/data/messages.ts +0 -237
  111. package/src/data/notifications.ts +0 -48
  112. package/src/data/payments.ts +0 -675
  113. package/src/data/posts.ts +0 -580
  114. package/src/data/reactions.ts +0 -186
  115. package/src/data/s3.ts +0 -117
  116. package/src/data/search.ts +0 -74
  117. package/src/data/sms.ts +0 -60
  118. package/src/data/subscription.ts +0 -228
  119. package/src/data/tags.ts +0 -230
  120. package/src/data/users.ts +0 -254
  121. package/src/index.ts +0 -7
  122. package/src/types/apps.ts +0 -56
  123. package/src/types/arangodb.ts +0 -23
  124. package/src/types/auth.ts +0 -20
  125. package/src/types/conversations.ts +0 -11
  126. package/src/types/email.ts +0 -17
  127. package/src/types/files.ts +0 -31
  128. package/src/types/google.ts +0 -37
  129. package/src/types/groups.ts +0 -27
  130. package/src/types/images.ts +0 -32
  131. package/src/types/locations.ts +0 -24
  132. package/src/types/messages.ts +0 -16
  133. package/src/types/notifications.ts +0 -26
  134. package/src/types/payments.ts +0 -129
  135. package/src/types/posts.ts +0 -34
  136. package/src/types/reactions.ts +0 -8
  137. package/src/types/tags.ts +0 -13
  138. package/src/types/users.ts +0 -89
  139. package/src/utils/analytics.ts +0 -41
  140. package/src/utils/arangodb.ts +0 -100
  141. package/src/utils/auth.ts +0 -61
  142. package/src/utils/graphql.ts +0 -7
  143. package/src/utils/objects.ts +0 -34
  144. package/src/utils/redis.ts +0 -17
  145. package/tsconfig.json +0 -45
package/src/data/tags.ts DELETED
@@ -1,230 +0,0 @@
1
- /**
2
- * Copyright (c) 2019-Present, Nitrogen Labs, Inc.
3
- * Copyrights licensed under the MIT License. See the accompanying LICENSE file for terms.
4
- */
5
- import {createHash, parseId, parseVarChar} from '@nlabs/utils';
6
- import {aql, Database, EdgeCollection} from 'arangojs';
7
- import {AqlQuery} from 'arangojs/lib/cjs/aql-query';
8
- import {ArrayCursor} from 'arangojs/lib/cjs/cursor';
9
- import words from 'lodash/words';
10
-
11
- import {ArangoDBLimit} from '../types/arangodb';
12
- import {ApiContext} from '../types/auth';
13
- import {PostType} from '../types/posts';
14
- import {TagType} from '../types/tags';
15
- import {getLimit, logError, useDb} from '../utils';
16
-
17
- const eventCategory: string = 'tags';
18
-
19
- export const getTagList = (context: ApiContext, from: number = 0, to: number = 30): Promise<TagType[]> => {
20
- const action: string = 'getList';
21
- const {database, userId: sessionId} = context;
22
- const limit: ArangoDBLimit = getLimit(from, to);
23
- const aqlQry: string = `FOR t IN tagList
24
- FILTER t.userId == "${sessionId}"
25
- ${limit.aql}
26
- SORT t.added
27
- RETURN t`;
28
-
29
- return useDb(database).query(aqlQry)
30
- .then((cursor: ArrayCursor) => cursor.all())
31
- .then((list = []) => list)
32
- .catch((error: Error) => logError({
33
- action,
34
- category: eventCategory,
35
- label: 'db_error'
36
- }, error, {}).then(() => null).catch((error) => Promise.reject(error)));
37
- };
38
-
39
- export const getTag = (context: ApiContext, tagId: string): Promise<TagType> => {
40
- const action: string = 'getItem';
41
- const {database} = context;
42
- const formatId: string = JSON.stringify(parseId(tagId));
43
- const aqlQry: string = `FOR t IN tags
44
- FILTER t._key == ${formatId}
45
- LIMIT 1
46
- RETURN t`;
47
-
48
- return useDb(database).query(aqlQry)
49
- .then((cursor: ArrayCursor) => cursor.next())
50
- .then((tag = {}) => tag)
51
- .catch((error: Error) => logError({
52
- action,
53
- category: eventCategory,
54
- label: 'db_error'
55
- }, error, {}).then(() => null).catch((error) => Promise.reject(error)));
56
- };
57
-
58
- export const addTag = (context: ApiContext, tag: TagType): Promise<TagType> => {
59
- const action: string = 'add';
60
- const {database, userId: sessionId} = context;
61
- const now: number = Date.now();
62
- const formatId: string = createHash(`tag-${sessionId}`);
63
- const {description, name} = tag;
64
-
65
- const insert: any = {
66
- _key: formatId,
67
- added: now,
68
- description: parseVarChar(description, 64),
69
- modified: now,
70
- name: parseVarChar(name, 32)
71
- };
72
-
73
- const aqlQry: AqlQuery = aql`INSERT ${insert} IN tags RETURN NEW`;
74
-
75
- return useDb(database).query(aqlQry)
76
- .then((cursor: ArrayCursor) => cursor.next())
77
- .then((tag: TagType = {}) => tag)
78
- .catch((error: Error) => logError({
79
- action,
80
- category: eventCategory,
81
- label: 'db_error'
82
- }, error, {}).then(() => null).catch((error) => Promise.reject(error)));
83
- };
84
-
85
- export const tagPost = (context: ApiContext, tagId, postId): Promise<PostType> => {
86
- const action: string = 'tagPost';
87
- const {database, userId: sessionId} = context;
88
- const added: number = Date.now();
89
- const edgeId: string = createHash(`tagPost-${sessionId}`);
90
- const edgeCollection: EdgeCollection = useDb(database).edgeCollection('isTagged');
91
- const edge: any = {_key: edgeId, added};
92
-
93
- return edgeCollection.save(edge, `tags/${tagId}`, `posts/${postId}`)
94
- .then((post: PostType = {}) => post)
95
- .catch((error: Error) => logError({
96
- action,
97
- category: eventCategory,
98
- label: 'db_error'
99
- }, error, {}).then(() => null).catch((error) => Promise.reject(error)));
100
- };
101
-
102
- export const updateTag = (context: ApiContext, item: TagType = {}): Promise<TagType> => {
103
- const action: string = 'update';
104
- const {database} = context;
105
- const now: number = Date.now();
106
- const {description, id, name} = item;
107
- const formatName: string = parseVarChar(name, 32);
108
-
109
- const update: TagType = {
110
- description: parseVarChar(description, 64),
111
- modified: now,
112
- name: formatName
113
- };
114
-
115
- const formatId: string = parseId(id);
116
- const tagId: string = !formatId ? createHash(`tag-${formatName.toLowerCase()}`, null) : formatId;
117
-
118
- const insert: TagType = {
119
- ...update,
120
- _key: tagId,
121
- added: now
122
- };
123
- const aqlQry: AqlQuery = aql`UPSERT {_key: ${tagId}}
124
- INSERT ${insert}
125
- UPDATE ${update}
126
- IN tags RETURN NEW`;
127
-
128
- return useDb(database).query(aqlQry)
129
- .then((cursor: ArrayCursor) => cursor.next())
130
- .then((tag = {}) => tag)
131
- .catch((error: Error) => logError({
132
- action,
133
- category: eventCategory,
134
- label: 'db_error'
135
- }, error, {}).then(() => null).catch((error) => Promise.reject(error)));
136
- };
137
-
138
- export const deleteTag = (context: ApiContext, tagId: string): Promise<TagType> => {
139
- const action: string = 'delete';
140
- const {database} = context;
141
- const formatTagId: string = parseId(tagId);
142
- const aqlQry: AqlQuery = aql`FOR t IN tags
143
- FILTER t._key == ${formatTagId}
144
- REMOVE t IN tags
145
- RETURN OLD`;
146
-
147
- return useDb(database).query(aqlQry)
148
- .then((cursor: ArrayCursor) => cursor.next())
149
- .then((tag: TagType = {}) => tag)
150
- .catch((error: Error) => logError({
151
- action,
152
- category: eventCategory,
153
- label: 'db_error'
154
- }, error, {}).then(() => null).catch((error) => Promise.reject(error)));
155
- };
156
-
157
- export const extractTags = (db: Database, itemType: string, itemId, content): Promise<TagType[]> => {
158
- const tags: string[] = words(content, /#[a-zA-Z\d-]+/g).map((tag: string) => parseId(tag));
159
- const edgeCollection = db.edgeCollection('isTagged');
160
-
161
- return edgeCollection.inEdges(itemId)
162
- .then((edges) => {
163
- if(edges.length) {
164
- // Remove linked edges
165
- return Promise.all(
166
- edges.map((edge) => {
167
- const {_key: edgeKey} = edge;
168
- const aqlQry = aql`REMOVE {_key:${edgeKey}} IN isTagged`;
169
- return db.query(aqlQry).catch((error: Error) => {
170
- throw error;
171
- });
172
- }))
173
- .then(() => {
174
- if(tags.length) {
175
- // Create tags
176
- return linkTags(db, tags, itemType, itemId);
177
- }
178
- return [];
179
- });
180
- } else if(tags.length) {
181
- // Create tags
182
- return linkTags(db, tags, itemType, itemId);
183
- }
184
- return [];
185
- })
186
- .catch((error: Error) => {
187
- throw error;
188
- });
189
- };
190
-
191
- export const createTag = (db: Database, tagName: string): Promise<TagType> => {
192
- const tagId: string = createHash(`tag-${tagName}`);
193
- const insert: TagType = {
194
- _key: tagId,
195
- added: Date.now(),
196
- name: tagName
197
- };
198
-
199
- const aqlQry = aql`UPSERT {_key: ${tagId}}
200
- INSERT ${insert}
201
- UPDATE {}
202
- IN tags RETURN NEW`;
203
-
204
- return db.query(aqlQry)
205
- .then((cursor: ArrayCursor) => cursor.next())
206
- .then((tag = {}) => tag)
207
- .catch((error: Error) => {
208
- throw error;
209
- });
210
- };
211
-
212
- export const createTagEdge = (db: Database, tag: TagType, itemType: string, itemId: string): Promise<TagType> => {
213
- const edgeCollection = db.edgeCollection('isTagged');
214
- const {_id: tagId, _key: tagKey} = tag;
215
- const edgeId = createHash(`tag-${itemType}-${tagKey}-${itemId}`);
216
- const edge: any = {
217
- _key: edgeId,
218
- added: Date.now(),
219
- type: itemType
220
- };
221
-
222
- return edgeCollection.save(edge, tagId, `${itemType}/${itemId}`).then(() => tag);
223
- };
224
-
225
- export const linkTags = (db: Database, tagNames: string[], itemType: string, itemId: string): Promise<TagType[]> => {
226
- return Promise.all(
227
- tagNames.map((tagId: string) => createTag(db, tagId)
228
- .then((tag: TagType) => createTagEdge(db, tag, itemType, itemId)))
229
- );
230
- };
package/src/data/users.ts DELETED
@@ -1,254 +0,0 @@
1
- /**
2
- * Copyright (c) 2019-Present, Nitrogen Labs, Inc.
3
- * Copyrights licensed under the MIT License. See the accompanying LICENSE file for terms.
4
- */
5
- import {createHash, parseChar, parseEmail, parseId, parseUsername, parseVarChar} from '@nlabs/utils';
6
- import {aql, Database, EdgeCollection} from 'arangojs';
7
- import {AqlQuery} from 'arangojs/lib/cjs/aql-query';
8
- import {ArrayCursor} from 'arangojs/lib/cjs/cursor';
9
- import isEmpty from 'lodash/isEmpty';
10
- import * as stripe from 'stripe';
11
-
12
- import {ApiContext} from '../types/auth';
13
- import {UserRelationType, UserType} from '../types/users';
14
- import {getLimit, logError, logException, useDb} from '../utils';
15
-
16
- const eventCategory: string = 'users';
17
-
18
- export const addUser = (context: ApiContext, user: UserType): Promise<UserType> => {
19
- const {database} = context;
20
- const {email, phone, sub, username} = user;
21
-
22
- // Add new user properties
23
- const insert: UserType = {
24
- _key: createHash(sub, null),
25
- added: Date.now(),
26
- email: email !== undefined ? parseEmail(email) : undefined,
27
- modified: Date.now(),
28
- phone: phone !== undefined ? parseVarChar(phone, 15) : undefined,
29
- sub: parseVarChar(sub, 32),
30
- username: parseUsername(username)
31
- };
32
-
33
- // Add new user in ArangoDB
34
- const aqlQry: AqlQuery = aql`INSERT ${insert} IN users RETURN NEW`;
35
- return useDb(database).query(aqlQry).then((cursor: ArrayCursor) => cursor.next());
36
- };
37
-
38
- export const deleteUser = (context: ApiContext, userId: string): Promise<UserType> => {
39
- const action: string = 'delete';
40
- const {database, userId: sessionId, userType: sessionType} = context;
41
- const isAdmin: boolean = sessionType > 2;
42
-
43
- if(!isAdmin && (sessionId !== userId)) {
44
- logException({
45
- action,
46
- category: eventCategory,
47
- label: 'unauthorized',
48
- value: 'invalid_session'
49
- }, context);
50
- return null;
51
- }
52
-
53
- const aqlQry: AqlQuery = aql`FOR u IN users
54
- FILTER u._key == ${userId}
55
- LIMIT 1
56
- REMOVE u IN users
57
- RETURN OLD`;
58
-
59
- return useDb(database).query(aqlQry)
60
- .then((cursor: ArrayCursor) => cursor.next())
61
- .then((user: UserType = {}) => stripe.customers.del(user.stripeCustomerId)
62
- .then(() => stripe.accounts.del(user.stripeAccountId))
63
- .then(() => user))
64
- .catch((error: Error) => {
65
- throw error;
66
- });
67
- };
68
-
69
- export const deactivateUser = (context: ApiContext, userId: string): Promise<UserType> => {
70
- const action: string = 'delete';
71
- const {database, userId: sessionId, userType: sessionType} = context;
72
- const isAdmin: boolean = sessionType > 2;
73
-
74
- if(!isAdmin && (sessionId !== userId)) {
75
- logException({
76
- action,
77
- category: eventCategory,
78
- label: 'unauthorized',
79
- value: 'invalid_session'
80
- }, context);
81
- return null;
82
- }
83
-
84
- const updated: UserType = {
85
- userType: 0
86
- };
87
- const aqlQry: AqlQuery = aql`UPDATE ${userId} WITH ${updated} IN users LIMIT 1 RETURN NEW`;
88
-
89
- return useDb(database).query(aqlQry)
90
- .then((cursor: ArrayCursor) => cursor.next())
91
- .catch((error: Error) => {
92
- throw error;
93
- });
94
- };
95
-
96
- export const getUser = (context: ApiContext, userId): Promise<UserType> => {
97
- const action: string = 'getItem';
98
- const formatUserId: string = parseId(userId);
99
- const {database} = context;
100
-
101
- // Get data from database
102
- const aqlQry = aql`FOR u IN users
103
- FILTER u._key == ${formatUserId}
104
- LIMIT 1
105
- RETURN u`;
106
-
107
- return useDb(database).query(aqlQry)
108
- .then((cursor: ArrayCursor) => cursor.next())
109
- .then((user = {}) => user)
110
- .catch((error: Error) => logError({
111
- action,
112
- category: eventCategory,
113
- label: 'db_error'
114
- }, error, context).then(() => {}));
115
- };
116
-
117
- export const getUserList = (context: ApiContext, from: number = 0, to: number = 15): Promise<UserType> => {
118
- const action: string = 'getItem';
119
- const {database} = context;
120
- const limit = getLimit(from, to);
121
-
122
- // Get data from database
123
- const aqlQry: string = `FOR u IN users
124
- ${limit.aql}
125
- SORT u.username
126
- RETURN u`;
127
-
128
- return useDb(database).query(aqlQry)
129
- .then((cursor: ArrayCursor) => cursor.all())
130
- .catch((error: Error) => logError({
131
- action,
132
- category: eventCategory,
133
- label: 'db_error'
134
- }, error, context).then(() => []));
135
- };
136
-
137
- export const addUserRelation = (context: ApiContext, userId, value): Promise<UserRelationType> => {
138
- const action: string = 'addRelation';
139
- const {database, userId: sessionId} = context;
140
- const formatUserId: string = parseId(userId);
141
- const formatValue: string = parseChar(value, 32);
142
- const db: Database = useDb(database);
143
- const aqlQry = aql`FOR r IN hasRelation
144
- FILTER r.value == ${formatValue} && r._from == ${sessionId} && r._to == ${formatUserId}
145
- LIMIT 1
146
- RETURN r`;
147
-
148
- return db.query(aqlQry)
149
- .then((cursor: ArrayCursor) => cursor.next())
150
- .then((relation: UserRelationType) => {
151
- // If a relationship between two users with the value exists, just return
152
- if(relation) {
153
- return relation;
154
- }
155
-
156
- // Otherwise, create the new relationship
157
- const edgeId = createHash(`relation-${sessionId}-${formatUserId}-${formatValue}`);
158
- const edge = {
159
- _key: edgeId,
160
- added: Date.now(),
161
- value: formatValue
162
- };
163
- const edgeCollection: EdgeCollection = db.edgeCollection('hasRelation') as any;
164
-
165
- return edgeCollection.save(edge, `users/${sessionId}`, `users/${formatUserId}`)
166
- .then(() => edgeCollection.edge(edgeId))
167
- .catch((error: Error) => {
168
- throw error;
169
- });
170
- })
171
- .catch((error: Error) => logError({
172
- action,
173
- category: eventCategory,
174
- label: 'db_error'
175
- }, error, context).then(() => null));
176
- };
177
-
178
- export const deleteUserRelation = (context: ApiContext, userId: string, value: string): Promise<UserRelationType> => {
179
- const action: string = 'getRelationsByUser';
180
- const {database, userId: sessionId} = context;
181
- const formatUserId: string = parseId(userId);
182
- const formatValue: string = parseChar(value, 32);
183
- const aqlQry = `FOR u, r IN INBOUND "${`users/${formatUserId}`}" hasRelation
184
- FILTER r._from == "${`users/${sessionId}`}" && r.value == "${formatValue}"
185
- REMOVE r IN hasRelation
186
- RETURN OLD`;
187
-
188
- return useDb(database).query(aqlQry)
189
- .then((cursor: ArrayCursor) => cursor.next())
190
- .then((relation = {}) => relation)
191
- .catch((error: Error) => logError({
192
- action,
193
- category: eventCategory,
194
- label: 'db_error'
195
- }, error, context).then(() => null));
196
- };
197
-
198
- export const getUsersByRelations = (
199
- context: ApiContext,
200
- userId: string,
201
- type: string,
202
- from: number,
203
- to: number
204
- ): Promise<UserType[]> => {
205
- const action: string = 'getUsersByRelations';
206
- const {database} = context;
207
- const formatUserId: string = parseId(userId);
208
- const formatType: string = parseChar(type, 32);
209
- const limit = getLimit(from, to);
210
- const aqlQry: string = `FOR u, r IN INBOUND "${`users/${formatUserId}`}" hasRelation
211
- FILTER r.type == "${formatType}"
212
- ${limit.aql}
213
- RETURN u`;
214
-
215
- return useDb(database).query(aqlQry)
216
- .then((cursor: ArrayCursor) => cursor.all())
217
- .catch((error: Error) => logError({
218
- action,
219
- category: eventCategory,
220
- label: 'db_error'
221
- }, error, context).then(() => null));
222
- };
223
-
224
- export const getRelationsByUser = (context: ApiContext, userId: string): Promise<UserRelationType[]> => {
225
- const action: string = 'getRelationsByUser';
226
- const {database, userId: sessionId} = context;
227
- const formatUserId: string = parseId(userId);
228
- const aqlQry: AqlQuery = aql`FOR u, r IN INBOUND ${`users/${formatUserId}`} hasRelation
229
- FILTER r._from == ${`users/${sessionId}`}
230
- RETURN r`;
231
-
232
- return useDb(database).query(aqlQry)
233
- .then((cursor: ArrayCursor) => cursor.all())
234
- .catch((error: Error) => logError({
235
- action,
236
- category: eventCategory,
237
- label: 'db_error'
238
- }, error, context).then(() => null));
239
- };
240
-
241
- export const getDisplayName = (user: UserType = {}): string => {
242
- const {first, last, name = '', username = ''} = user;
243
- const fullname: string = ([first, last]).join(' ').trim();
244
-
245
- if(!isEmpty(name)) {
246
- return name;
247
- } else if(fullname !== '') {
248
- return fullname;
249
- } else if(!isEmpty(username)) {
250
- return username;
251
- }
252
-
253
- return 'Unknown';
254
- };
package/src/index.ts DELETED
@@ -1,7 +0,0 @@
1
- /**
2
- * Copyright (c) 2019-Present, Nitrogen Labs, Inc.
3
- * Copyrights licensed under the MIT License. See the accompanying LICENSE file for terms.
4
- */
5
- export * from './data';
6
- export * from './utils';
7
- export * from './types';
package/src/types/apps.ts DELETED
@@ -1,56 +0,0 @@
1
- /**
2
- * Copyright (c) 2019-Present, Nitrogen Labs, Inc.
3
- * Copyrights licensed under the MIT License. See the accompanying LICENSE file for terms.
4
- */
5
- import {UserType} from './users';
6
-
7
- export interface TestType {
8
-
9
- }
10
-
11
- export interface AppSessionType {
12
- readonly active?: boolean;
13
- readonly added?: number;
14
- readonly exp?: number;
15
- readonly modified?: number;
16
- readonly name?: string;
17
- }
18
-
19
- export interface AppType {
20
- readonly _id?: string;
21
- readonly _key?: string;
22
- readonly active?: boolean;
23
- readonly currency?: string;
24
- readonly displayName?: string;
25
- readonly email?: string;
26
- readonly hasCustomEmail?: boolean;
27
- readonly iap?: string;
28
- readonly id?: string;
29
- readonly key?: string;
30
- readonly name?: string;
31
- readonly photo?: string;
32
- readonly secret?: string;
33
- readonly supportName?: string;
34
- readonly url?: string;
35
- readonly urlFacebook?: string;
36
- readonly urlTwitter?: string;
37
- }
38
-
39
- export interface AppStatsType {
40
- readonly numUsers?: number;
41
- }
42
-
43
- export interface EmailParamsType {
44
- readonly type?: string;
45
- readonly user?: UserType;
46
- }
47
-
48
- export interface QueryFilter {
49
- readonly conditional?: string;
50
- readonly name?: string;
51
- readonly value?: string;
52
- }
53
-
54
- export interface AccessTokenType {
55
-
56
- }
@@ -1,23 +0,0 @@
1
- /**
2
- * Copyright (c) 2019-Present, Nitrogen Labs, Inc.
3
- * Copyrights licensed under the MIT License. See the accompanying LICENSE file for terms.
4
- */
5
- export interface RangeType {
6
- readonly from: number;
7
- readonly to: number;
8
- }
9
-
10
- export interface ArangoDBPathObject {
11
- readonly collection?: string;
12
- readonly itemObj?: any;
13
- readonly keys?: string[];
14
- readonly props?: any;
15
- readonly ranges?: any;
16
- readonly routeKey: string;
17
- }
18
-
19
- export interface ArangoDBLimit {
20
- readonly aql: string;
21
- readonly start: number;
22
- readonly num: number;
23
- }
package/src/types/auth.ts DELETED
@@ -1,20 +0,0 @@
1
- /**
2
- * Copyright (c) 2019-Present, Nitrogen Labs, Inc.
3
- * Copyrights licensed under the MIT License. See the accompanying LICENSE file for terms.
4
- */
5
- export interface ApiContext {
6
- readonly appId: string;
7
- readonly database: string;
8
- readonly email: string;
9
- readonly fields?: string[];
10
- readonly ipAddress: string;
11
- readonly userId: string;
12
- readonly username: string;
13
- readonly userType: number;
14
- // User types
15
- // 0- Deactivated
16
- // 1- Active
17
- // 2 - Premium
18
- // 3 - Admin
19
- // 4 - Super Admin
20
- }
@@ -1,11 +0,0 @@
1
- /**
2
- * Copyright (c) 2019-Present, Nitrogen Labs, Inc.
3
- * Copyrights licensed under the MIT License. See the accompanying LICENSE file for terms.
4
- */
5
- import {UserType} from './users';
6
-
7
- export interface ConversationType {
8
- readonly _key?: string;
9
- readonly id?: string;
10
- users?: UserType[];
11
- }
@@ -1,17 +0,0 @@
1
- /**
2
- * Copyright (c) 2019-Present, Nitrogen Labs, Inc.
3
- * Copyrights licensed under the MIT License. See the accompanying LICENSE file for terms.
4
- */
5
- import {AppType} from './apps';
6
- import {UserType} from './users';
7
-
8
- export interface EmailType {
9
- readonly app?: AppType;
10
- readonly html?: string;
11
- readonly subject?: string;
12
- readonly subTitle?: string;
13
- readonly text?: string;
14
- readonly title?: string;
15
- readonly user?: UserType;
16
- readonly vars?: any;
17
- }
@@ -1,31 +0,0 @@
1
- /**
2
- * Copyright (c) 2019-Present, Nitrogen Labs, Inc.
3
- * Copyrights licensed under the MIT License. See the accompanying LICENSE file for terms.
4
- */
5
- export interface FileType {
6
- readonly _key?: string;
7
- readonly added?: number;
8
- readonly base64?: string;
9
- readonly buffer?: Buffer;
10
- readonly description?: string;
11
- fileSize?: number;
12
- readonly fileType?: string;
13
- readonly id?: string;
14
- readonly itemId?: string;
15
- readonly itemType?: string;
16
- readonly modified?: number;
17
- readonly name?: string;
18
- readonly url?: string;
19
- readonly userId?: string;
20
- }
21
-
22
- export interface FileDecodedType {
23
- data?: Buffer;
24
- type?: string;
25
- }
26
-
27
- export interface FileEdgeType {
28
- readonly imgId?: string;
29
- readonly itemId?: string;
30
- readonly itemType?: string;
31
- }
@@ -1,37 +0,0 @@
1
- /**
2
- * Copyright (c) 2019-Present, Nitrogen Labs, Inc.
3
- * Copyrights licensed under the MIT License. See the accompanying LICENSE file for terms.
4
- */
5
- /* eslint camelcase: 0 */
6
- export interface GoogleMapsType {
7
- results: GoogleMapsResultType[];
8
- status: string;
9
- }
10
-
11
- export interface GoogleMapsAddressType {
12
- long_name: string;
13
- short_name: string;
14
- types: string[];
15
- }
16
-
17
- export interface GoogleTimezoneType {
18
- dstOffset: string;
19
- rawOffset: string;
20
- status: string;
21
- timeZoneId: string;
22
- timeZoneName: string;
23
- }
24
-
25
- export interface GoogleLatLngType {
26
- lat: number;
27
- lng: number;
28
- }
29
-
30
- export interface GoogleMapsLocationType {
31
- location: GoogleLatLngType;
32
- }
33
-
34
- export interface GoogleMapsResultType {
35
- address_components: GoogleMapsAddressType[];
36
- geometry: GoogleMapsLocationType;
37
- }