@nlabs/reaktor 0.1.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 (154) hide show
  1. package/.vscode/extensions.json +15 -0
  2. package/.vscode/settings.json +82 -0
  3. package/README.md +211 -0
  4. package/index.d.ts +1 -0
  5. package/index.js +5 -0
  6. package/lex.config.js +4 -0
  7. package/lib/config.d.ts +21 -0
  8. package/lib/config.js +127 -0
  9. package/lib/data/conversations.d.ts +6 -0
  10. package/lib/data/conversations.js +201 -0
  11. package/lib/data/dynamodb.d.ts +8 -0
  12. package/lib/data/dynamodb.js +139 -0
  13. package/lib/data/email.d.ts +7 -0
  14. package/lib/data/email.js +164 -0
  15. package/lib/data/files.d.ts +16 -0
  16. package/lib/data/files.js +407 -0
  17. package/lib/data/groups.d.ts +13 -0
  18. package/lib/data/groups.js +354 -0
  19. package/lib/data/images.d.ts +12 -0
  20. package/lib/data/images.js +668 -0
  21. package/lib/data/index.d.ts +19 -0
  22. package/lib/data/index.js +24 -0
  23. package/lib/data/ios.d.ts +6 -0
  24. package/lib/data/ios.js +302 -0
  25. package/lib/data/locations.d.ts +3 -0
  26. package/lib/data/locations.js +132 -0
  27. package/lib/data/messages.d.ts +9 -0
  28. package/lib/data/messages.js +248 -0
  29. package/lib/data/notifications.d.ts +5 -0
  30. package/lib/data/notifications.js +42 -0
  31. package/lib/data/payments.d.ts +11 -0
  32. package/lib/data/payments.js +748 -0
  33. package/lib/data/posts.d.ts +14 -0
  34. package/lib/data/posts.js +458 -0
  35. package/lib/data/reactions.d.ts +6 -0
  36. package/lib/data/reactions.js +218 -0
  37. package/lib/data/s3.d.ts +6 -0
  38. package/lib/data/s3.js +103 -0
  39. package/lib/data/search.d.ts +3 -0
  40. package/lib/data/search.js +98 -0
  41. package/lib/data/sms.d.ts +3 -0
  42. package/lib/data/sms.js +59 -0
  43. package/lib/data/subscription.d.ts +7 -0
  44. package/lib/data/subscription.js +284 -0
  45. package/lib/data/tags.d.ts +14 -0
  46. package/lib/data/tags.js +304 -0
  47. package/lib/data/users.d.ts +12 -0
  48. package/lib/data/users.js +312 -0
  49. package/lib/index.d.ts +3 -0
  50. package/lib/index.js +8 -0
  51. package/lib/types/apps.d.ts +44 -0
  52. package/lib/types/apps.js +2 -0
  53. package/lib/types/arangodb.d.ts +17 -0
  54. package/lib/types/arangodb.js +2 -0
  55. package/lib/types/auth.d.ts +9 -0
  56. package/lib/types/auth.js +2 -0
  57. package/lib/types/conversations.d.ts +6 -0
  58. package/lib/types/conversations.js +2 -0
  59. package/lib/types/email.d.ts +12 -0
  60. package/lib/types/email.js +2 -0
  61. package/lib/types/files.d.ts +28 -0
  62. package/lib/types/files.js +2 -0
  63. package/lib/types/google.d.ts +27 -0
  64. package/lib/types/google.js +2 -0
  65. package/lib/types/groups.d.ts +22 -0
  66. package/lib/types/groups.js +2 -0
  67. package/lib/types/images.d.ts +25 -0
  68. package/lib/types/images.js +2 -0
  69. package/lib/types/index.d.ts +17 -0
  70. package/lib/types/index.js +22 -0
  71. package/lib/types/locations.d.ts +21 -0
  72. package/lib/types/locations.js +2 -0
  73. package/lib/types/messages.d.ts +12 -0
  74. package/lib/types/messages.js +2 -0
  75. package/lib/types/notifications.d.ts +19 -0
  76. package/lib/types/notifications.js +2 -0
  77. package/lib/types/payments.d.ts +119 -0
  78. package/lib/types/payments.js +2 -0
  79. package/lib/types/posts.d.ts +20 -0
  80. package/lib/types/posts.js +2 -0
  81. package/lib/types/reactions.d.ts +4 -0
  82. package/lib/types/reactions.js +2 -0
  83. package/lib/types/tags.d.ts +10 -0
  84. package/lib/types/tags.js +2 -0
  85. package/lib/types/users.d.ts +78 -0
  86. package/lib/types/users.js +2 -0
  87. package/lib/utils/analytics.d.ts +3 -0
  88. package/lib/utils/analytics.js +47 -0
  89. package/lib/utils/arangodb.d.ts +9 -0
  90. package/lib/utils/arangodb.js +98 -0
  91. package/lib/utils/auth.d.ts +2 -0
  92. package/lib/utils/auth.js +43 -0
  93. package/lib/utils/index.d.ts +5 -0
  94. package/lib/utils/index.js +10 -0
  95. package/lib/utils/objects.d.ts +3 -0
  96. package/lib/utils/objects.js +34 -0
  97. package/lib/utils/redis.d.ts +1 -0
  98. package/lib/utils/redis.js +15 -0
  99. package/package.json +75 -0
  100. package/src/config.ts +121 -0
  101. package/src/data/conversations.ts +183 -0
  102. package/src/data/dynamodb.ts +157 -0
  103. package/src/data/email.ts +164 -0
  104. package/src/data/files.ts +352 -0
  105. package/src/data/groups.ts +308 -0
  106. package/src/data/images.ts +606 -0
  107. package/src/data/index.ts +23 -0
  108. package/src/data/ios.ts +249 -0
  109. package/src/data/locations.ts +114 -0
  110. package/src/data/messages.ts +237 -0
  111. package/src/data/notifications.ts +48 -0
  112. package/src/data/payments.ts +675 -0
  113. package/src/data/posts.ts +508 -0
  114. package/src/data/reactions.ts +186 -0
  115. package/src/data/s3.ts +117 -0
  116. package/src/data/search.ts +74 -0
  117. package/src/data/sms.ts +60 -0
  118. package/src/data/subscription.ts +228 -0
  119. package/src/data/tags.ts +230 -0
  120. package/src/data/users.ts +256 -0
  121. package/src/index.ts +7 -0
  122. package/src/types/apps.ts +57 -0
  123. package/src/types/arangodb.ts +23 -0
  124. package/src/types/auth.ts +19 -0
  125. package/src/types/conversations.ts +11 -0
  126. package/src/types/email.ts +17 -0
  127. package/src/types/files.ts +33 -0
  128. package/src/types/google.ts +37 -0
  129. package/src/types/groups.ts +28 -0
  130. package/src/types/images.ts +33 -0
  131. package/src/types/index.ts +21 -0
  132. package/src/types/locations.ts +25 -0
  133. package/src/types/messages.ts +16 -0
  134. package/src/types/notifications.ts +26 -0
  135. package/src/types/payments.ts +134 -0
  136. package/src/types/posts.ts +25 -0
  137. package/src/types/reactions.ts +8 -0
  138. package/src/types/tags.ts +14 -0
  139. package/src/types/users.ts +89 -0
  140. package/src/utils/analytics.ts +41 -0
  141. package/src/utils/arangodb.ts +100 -0
  142. package/src/utils/auth.ts +28 -0
  143. package/src/utils/index.ts +9 -0
  144. package/src/utils/objects.ts +34 -0
  145. package/src/utils/redis.ts +17 -0
  146. package/templates/email/layout.html +279 -0
  147. package/templates/email/passwordForgot.html +15 -0
  148. package/templates/email/passwordRecovery.html +12 -0
  149. package/templates/email/verifyEmail.html +15 -0
  150. package/templates/sms/passwordForgot.txt +1 -0
  151. package/templates/sms/passwordRecovery.txt +1 -0
  152. package/templates/sms/verifyEmail.txt +1 -0
  153. package/templates/sms/verifyPhone.txt +1 -0
  154. package/tsconfig.json +45 -0
@@ -0,0 +1,28 @@
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 GroupType {
6
+ readonly _key?: string;
7
+ readonly added?: number;
8
+ readonly appId?: string;
9
+ readonly description?: string;
10
+ readonly groupId?: string;
11
+ readonly id?: string;
12
+ readonly modified?: number;
13
+ readonly name?: string;
14
+ readonly privacy?: string;
15
+ readonly type?: string;
16
+ }
17
+
18
+ export interface GroupUserType {
19
+ readonly groupId?: string;
20
+ readonly isValid?: boolean;
21
+ readonly userId?: string;
22
+ }
23
+
24
+ export interface GroupEdgeType {
25
+ readonly groupId?: string;
26
+ readonly isValid?: boolean;
27
+ readonly userId?: string;
28
+ }
@@ -0,0 +1,33 @@
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 {FileType} from './files';
6
+
7
+ export interface ImageType extends FileType {
8
+ color?: string;
9
+ readonly height?: number;
10
+ readonly id?: string;
11
+ readonly model?: string;
12
+ readonly make?: string;
13
+ readonly taken?: number;
14
+ readonly width?: number;
15
+ }
16
+
17
+ export interface ImageIdentifyType {
18
+ readonly datetimeoriginal?: number;
19
+ readonly model?: string;
20
+ readonly make?: string;
21
+ }
22
+
23
+ export type ImageUrlTypes = 'app' | 'events' | 'groups' | 'users';
24
+
25
+ export interface ImageUrlData {
26
+ readonly appId?: string;
27
+ readonly directory?: string;
28
+ readonly imgId?: string;
29
+ readonly imgType?: string;
30
+ readonly isThumb?: boolean;
31
+ readonly type?: ImageUrlTypes;
32
+ readonly typeId?: string;
33
+ }
@@ -0,0 +1,21 @@
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 './apps';
6
+ export * from './arangodb';
7
+ export * from './auth';
8
+ export * from './conversations';
9
+ export * from './email';
10
+ export * from './files';
11
+ export * from './google';
12
+ export * from './groups';
13
+ export * from './images';
14
+ export * from './locations';
15
+ export * from './messages';
16
+ export * from './notifications';
17
+ export * from './payments';
18
+ export * from './posts';
19
+ export * from './reactions';
20
+ export * from './tags';
21
+ export * from './users';
@@ -0,0 +1,25 @@
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 LocationType {
6
+ readonly _key?: string;
7
+ readonly address?: string;
8
+ readonly added?: number;
9
+ readonly appId?: string;
10
+ readonly city?: string;
11
+ readonly country?: string;
12
+ readonly description?: string;
13
+ readonly formatted?: string;
14
+ readonly googleId?: string;
15
+ readonly id?: string;
16
+ readonly itemId?: string;
17
+ readonly itemType?: string;
18
+ readonly latitude?: string;
19
+ readonly longitude?: string;
20
+ readonly modified?: number;
21
+ readonly state?: string;
22
+ readonly street?: string;
23
+ readonly userId?: string;
24
+ readonly zip?: string;
25
+ }
@@ -0,0 +1,16 @@
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 MessageType {
6
+ readonly _key?: string;
7
+ readonly added?: number;
8
+ readonly content?: string;
9
+ readonly files?: string[];
10
+ readonly fromId?: string;
11
+ readonly id?: string;
12
+ readonly modified?: number;
13
+ readonly read?: boolean;
14
+ readonly saved?: boolean;
15
+ readonly toId?: string;
16
+ }
@@ -0,0 +1,26 @@
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 NotificationType {
9
+ readonly badge?: number;
10
+ readonly data?: any;
11
+ readonly message?: string;
12
+ readonly title?: string;
13
+ }
14
+
15
+ export interface SMSParamsType {
16
+ readonly app?: AppType;
17
+ readonly content?: string;
18
+ readonly user?: UserType;
19
+ readonly vars?: any;
20
+ }
21
+
22
+ export interface TwilioOptionsType {
23
+ readonly body?: string;
24
+ readonly from?: string;
25
+ readonly to?: string;
26
+ }
@@ -0,0 +1,134 @@
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 PaymentCardType {
7
+ readonly _id?: string;
8
+ readonly _key?: string;
9
+ readonly acceptedTerms?: boolean;
10
+ readonly accountNumber?: string;
11
+ readonly added?: number;
12
+ readonly appId?: string;
13
+ readonly brand?: string;
14
+ city?: string;
15
+ country?: string;
16
+ readonly cvc?: string;
17
+ expMonth?: number;
18
+ expYear?: number;
19
+ fullName?: string;
20
+ readonly id?: string;
21
+ readonly modified?: number;
22
+ state?: string;
23
+ street1?: string;
24
+ readonly stripeId?: string;
25
+ readonly userId?: string;
26
+ zip?: string;
27
+ }
28
+
29
+ export interface PaymentBankAccount {
30
+ readonly accountNumber?: string;
31
+ readonly fullName?: string;
32
+ readonly routing?: string;
33
+ }
34
+
35
+ export interface PaymentCharge {
36
+ readonly added?: number;
37
+ readonly amount?: number;
38
+ readonly appId?: string;
39
+ readonly capture?: boolean;
40
+ readonly cardId?: string;
41
+ readonly chargeFailCode?: string;
42
+ readonly chargeFailMsg?: string;
43
+ readonly chargeId?: string;
44
+ readonly chargeStatus?: string;
45
+ readonly currency?: string;
46
+ readonly description?: string;
47
+ readonly modified?: number;
48
+ readonly userId?: string;
49
+ }
50
+
51
+ export interface PaymentTransfer {
52
+ readonly added?: number;
53
+ readonly amount?: number;
54
+ readonly appId?: string;
55
+ readonly currency?: string;
56
+ readonly description?: string;
57
+ readonly modified?: number;
58
+ readonly userId?: string;
59
+ }
60
+
61
+ export type PaymentInterval = 'day' | 'week' | 'month' | 'year';
62
+
63
+ export interface PaymentPlan {
64
+ readonly _key?: string;
65
+ readonly added?: number;
66
+ readonly amount?: number;
67
+ readonly appId?: string;
68
+ readonly currency?: string;
69
+ readonly description?: string;
70
+ readonly id?: string;
71
+ readonly interval?: PaymentInterval;
72
+ readonly intervalCount?: number;
73
+ readonly modified?: number;
74
+ readonly name?: string;
75
+ }
76
+
77
+ export interface PaymentSubscription {
78
+ readonly _key?: string;
79
+ readonly added?: number;
80
+ readonly appId?: string;
81
+ readonly cancelDate?: number;
82
+ readonly expires?: number;
83
+ readonly id?: string;
84
+ readonly isProduction?: boolean;
85
+ readonly isTrial?: boolean;
86
+ readonly isValid?: boolean;
87
+ readonly modified?: number;
88
+ readonly plan?: PaymentPlan;
89
+ readonly planId?: string;
90
+ readonly receipt?: string;
91
+ readonly status?: string;
92
+ readonly transactionId?: string;
93
+ readonly tax?: number;
94
+ readonly trialEnd?: number;
95
+ readonly type?: string;
96
+ readonly userId?: string;
97
+ }
98
+
99
+ export interface PaymentIOSSubscriptionUpdate {
100
+ readonly environment?: 'SANDBOX' | 'PROD';
101
+ readonly notification_type?: 'INITIAL_BUY' | 'CANCEL' | 'RENEWAL' | 'INTERACTIVE_RENEWAL'
102
+ | 'DID_CHANGE_RENEWAL_PREFERENCE';
103
+ readonly password?: string;
104
+ readonly original_transaction_id?: string;
105
+ readonly cancellation_date?: number;
106
+ readonly web_order_line_item_id?: string;
107
+ readonly latest_receipt?: string;
108
+ readonly latest_receipt_info?: PaymentIOSSubscriptionInfo[];
109
+ readonly latest_expired_receipt?: string;
110
+ readonly latest_expired_receipt_info?: PaymentIOSSubscriptionInfo[];
111
+ readonly auto_renew_status?: string;
112
+ readonly auto_renew_adam_id?: string;
113
+ readonly auto_renew_product_id?: string;
114
+ readonly expiration_intent?: string;
115
+ }
116
+
117
+ export interface PaymentIOSSubscriptionInfo {
118
+ readonly expires_date_ms?: number;
119
+ readonly is_trial_period?: string;
120
+ readonly latest_receipt?: string;
121
+ readonly latest_receipt_info?: string;
122
+ readonly original_purchase_date_ms?: number;
123
+ readonly product_id?: string;
124
+ readonly receipt_creation_date_ms?: number;
125
+ readonly status?: string;
126
+ readonly transaction_id?: string;
127
+ }
128
+
129
+ export interface PaymentIOSInAppError {
130
+ readonly error?: boolean;
131
+ readonly id?: string;
132
+ readonly message?: string;
133
+ readonly valid?: boolean;
134
+ }
@@ -0,0 +1,25 @@
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 {FileType} from './files';
6
+ import {TagType} from './tags';
7
+
8
+ export interface PostType {
9
+ readonly _id?: string;
10
+ readonly _key?: string;
11
+ readonly added?: number;
12
+ readonly appId?: string;
13
+ files?: FileType[];
14
+ readonly groupId?: string;
15
+ readonly id?: string;
16
+ readonly modified?: number;
17
+ name?: string;
18
+ parentId?: string;
19
+ privacy?: string;
20
+ tags?: TagType[];
21
+ text?: string;
22
+ title?: string;
23
+ type?: string;
24
+ readonly userId?: string;
25
+ }
@@ -0,0 +1,8 @@
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 ReactionType {
6
+ readonly _key?: string;
7
+ readonly id?: string;
8
+ }
@@ -0,0 +1,14 @@
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 TagType {
6
+ readonly _id?: string;
7
+ readonly _key?: string;
8
+ readonly added?: number;
9
+ readonly appId?: string;
10
+ readonly description?: string;
11
+ readonly id?: string;
12
+ readonly modified?: number;
13
+ readonly name?: string;
14
+ }
@@ -0,0 +1,89 @@
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 {QueryFilter} from './apps';
6
+
7
+ export interface UserType {
8
+ readonly _id?: string;
9
+ readonly _key?: string;
10
+ readonly active?: boolean;
11
+ readonly added?: number;
12
+ readonly bankAccount?: string;
13
+ readonly bankFullName?: string;
14
+ readonly bankId?: string;
15
+ readonly bankRouting?: string;
16
+ readonly city?: string;
17
+ readonly country?: string;
18
+ readonly currency?: string;
19
+ readonly deviceToken?: string;
20
+ readonly dob?: number;
21
+ readonly email?: string;
22
+ readonly first?: string;
23
+ readonly gender?: string;
24
+ readonly id?: string;
25
+ readonly imgId?: string;
26
+ readonly last?: string;
27
+ readonly lastActive?: number;
28
+ readonly locale?: string;
29
+ readonly mailing?: boolean;
30
+ readonly modified?: number;
31
+ readonly name?: string;
32
+ readonly phone?: string;
33
+ readonly state?: string;
34
+ readonly street1?: string;
35
+ readonly street2?: string;
36
+ readonly stripeAccountId?: string;
37
+ readonly stripeCustomerId?: string;
38
+ readonly sub?: string;
39
+ readonly timezone?: string;
40
+ readonly type?: string;
41
+ readonly userType?: number;
42
+ readonly username?: string;
43
+ readonly zip?: string;
44
+ }
45
+
46
+ export interface UserPaymentType extends UserType {
47
+ readonly ssn?: string;
48
+ }
49
+
50
+ export interface AddUserType {
51
+ readonly confirm?: string;
52
+ readonly country?: string;
53
+ readonly deviceToken?: string;
54
+ readonly email?: string;
55
+ readonly first?: string;
56
+ readonly ip?: string;
57
+ readonly last?: string;
58
+ readonly mailing?: boolean;
59
+ readonly password?: string;
60
+ readonly phone?: string;
61
+ readonly name?: string;
62
+ readonly recaptcha?: string;
63
+ readonly timezone?: string;
64
+ readonly userType?: string;
65
+ readonly username?: string;
66
+ }
67
+
68
+ export interface UserRelationType {
69
+ readonly _key?: string;
70
+ }
71
+
72
+ export interface UserReactionType {
73
+ readonly _key?: string;
74
+ readonly added?: number;
75
+ readonly appId?: string;
76
+ readonly id?: string;
77
+ readonly type?: string;
78
+ readonly value?: string;
79
+ }
80
+
81
+ export interface UserReactionQuery extends UserReactionType {
82
+ readonly filters?: QueryFilter[];
83
+ }
84
+
85
+ export interface PasscodeType {
86
+ readonly passAttempt?: number;
87
+ readonly passExpires?: number;
88
+ readonly passcode?: string;
89
+ }
@@ -0,0 +1,41 @@
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 {UserError} from 'graphql-errors';
6
+
7
+ export const logError = (params, error, session): Promise<any> => {
8
+ const {
9
+ column = null,
10
+ isInternal = false,
11
+ label = '',
12
+ line = null,
13
+ message = '',
14
+ source = ''
15
+ } = error || {};
16
+
17
+ const updatedParams = {
18
+ ...params,
19
+ column,
20
+ line,
21
+ message,
22
+ source,
23
+ type: 'error'
24
+ };
25
+
26
+ console.log('Reaktor Error:', {...updatedParams, ...session});
27
+ console.log(error);
28
+ return Promise.reject(isInternal ? error : new UserError(label));
29
+ };
30
+
31
+ export const logException = (params, session): Promise<any> => {
32
+ params.type = 'exception';
33
+ const {label} = params;
34
+ console.log('Reaktor Exception:', {...params, ...session});
35
+ return Promise.reject(new UserError(label));
36
+ };
37
+
38
+ export const logInfo = (params, session): void => {
39
+ params.type = 'log';
40
+ console.log('Reaktor Log:', {...params, ...session});
41
+ };
@@ -0,0 +1,100 @@
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 {parseNum} from '@nlabs/utils';
6
+ import {Database} from 'arangojs';
7
+
8
+ import {Config} from '../config';
9
+ import {ArangoDBLimit, ArangoDBPathObject, RangeType} from '../types/arangodb';
10
+
11
+ // Create database
12
+ const database: Database = new Database({
13
+ url: Config.get('arangodb.apiUrl')
14
+ });
15
+ database.useDatabase(Config.get('arangodb.database'));
16
+ database.useBasicAuth(Config.get('arangodb.username'), Config.get('arangodb.password'));
17
+
18
+ // ArangoDB Utils
19
+ export const db: Database = database;
20
+
21
+ export const useDb = (database: string): Database => {
22
+ const db = new Database({url: Config.get('arangodb.apiUrl')});
23
+
24
+ db.useDatabase(database);
25
+ db.useBasicAuth(Config.get('arangodb.username'), Config.get('arangodb.password'));
26
+
27
+ return db;
28
+ };
29
+
30
+ export const dbPathObjItem = (pathSet): ArangoDBPathObject => {
31
+ const routeKey: string = pathSet[0];
32
+ const collection: string = routeKey.replace('ById', '');
33
+ const keys: string[] = pathSet[1];
34
+ const props: any = pathSet[2];
35
+
36
+ return {
37
+ collection,
38
+ keys,
39
+ props,
40
+ routeKey
41
+ };
42
+ };
43
+
44
+ export const dbPathObjJSON = (json): ArangoDBPathObject => {
45
+ const collectionKeys: string[] = Object.keys(json);
46
+ const routeKey: string = collectionKeys[0];
47
+ const collection: string = routeKey.replace('ById', '');
48
+ const itemObj: any = json[routeKey];
49
+ const keys: string[] = Object.keys(itemObj);
50
+
51
+ return {
52
+ collection,
53
+ itemObj,
54
+ keys,
55
+ routeKey
56
+ };
57
+ };
58
+
59
+ export const dbPathObjList = (pathSet): ArangoDBPathObject => {
60
+ const routeKey: string = pathSet[0];
61
+ const ranges: any = pathSet[1];
62
+ const props: any = pathSet[2];
63
+
64
+ return {
65
+ props,
66
+ ranges,
67
+ routeKey
68
+ };
69
+ };
70
+
71
+ export const getLimit = (start: number = 0, to: number = 30): ArangoDBLimit => {
72
+ let num = parseNum(to) - parseNum(start);
73
+
74
+ if(num > 50) {
75
+ num = 50;
76
+ }
77
+
78
+ return {aql: `LIMIT ${start}, ${num}`, num, start};
79
+ };
80
+
81
+ export const getRange = (from: number, to: number): RangeType => {
82
+ let updatedFrom: number = from || 0;
83
+ let updatedTo: number = to || 15;
84
+ updatedTo = updatedTo - 1;
85
+
86
+ if(updatedTo < 0) {
87
+ updatedTo = 0;
88
+ } else if(to > 50) {
89
+ updatedTo = 50;
90
+ }
91
+
92
+ if(updatedFrom < 0) {
93
+ updatedFrom = 0;
94
+ }
95
+ if(updatedFrom > updatedTo) {
96
+ updatedFrom = updatedTo;
97
+ }
98
+
99
+ return {from: updatedFrom, to: updatedTo};
100
+ };
@@ -0,0 +1,28 @@
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 {ApiContext} from '../types/auth';
6
+
7
+ export const parseContext = (data: any): ApiContext => {
8
+ const {appId, authorizer = {}, identity, isOffline} = data;
9
+ const {claims} = authorizer;
10
+
11
+ if(claims) {
12
+ const {['cognito:username']: username, email, sub: userId, userType = 'default'} = claims;
13
+ const {sourceIp: ipAddress} = identity;
14
+ return {appId, database: appId, email, ipAddress, userId, userType, username};
15
+ } else if(isOffline) {
16
+ return {
17
+ appId,
18
+ database: appId,
19
+ email: 'test@nitrogenlabs.com',
20
+ ipAddress: '1.1.1.1',
21
+ userId: 'testerId123',
22
+ userType: 1,
23
+ username: 'tester'
24
+ };
25
+ }
26
+
27
+ return null;
28
+ };
@@ -0,0 +1,9 @@
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 './analytics';
6
+ export * from './auth';
7
+ export * from './arangodb';
8
+ export * from './objects';
9
+ export * from './redis';
@@ -0,0 +1,34 @@
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 cloneDeep from 'lodash/cloneDeep';
6
+ import isPlainObject from 'lodash/isPlainObject';
7
+ import mapValues from 'lodash/mapValues';
8
+
9
+ export const defaultObject = (item: object): any => item || {};
10
+
11
+ export const lowerCaseKeys = (obj = {}): object => {
12
+ const newObj = cloneDeep(obj);
13
+
14
+ mapValues(obj, (value: any, key: string = '') => {
15
+ let updatedValue: any;
16
+
17
+ if(isPlainObject(value)) {
18
+ updatedValue = lowerCaseKeys(value);
19
+ } else {
20
+ updatedValue = value;
21
+ }
22
+
23
+ newObj[key.toLowerCase()] = updatedValue;
24
+ });
25
+
26
+ return newObj;
27
+ };
28
+
29
+ export const toQueryString = (json: any = {}): string => {
30
+ return Object
31
+ .keys(json)
32
+ .map((key: string) => `${encodeURIComponent(key)}=${encodeURIComponent(json[key])}`)
33
+ .join('&');
34
+ };
@@ -0,0 +1,17 @@
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 * as redis from 'redis';
6
+ import * as tp from 'typed-promisify';
7
+
8
+ import {Config} from '../config';
9
+
10
+ // Promisify redis module
11
+ tp.promisify(redis.RedisClient.prototype);
12
+
13
+ export const redisClient = redis.createClient({
14
+ host: Config.get('redis.host'),
15
+ port: Config.get('redis.port'),
16
+ string_numbers: false
17
+ });