@nlabs/reaktor 0.1.1 → 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 (57) hide show
  1. package/.DS_Store +0 -0
  2. package/lib/config.js +10 -7
  3. package/lib/data/posts.d.ts +13 -7
  4. package/lib/data/posts.js +77 -39
  5. package/lib/types/posts.d.ts +1 -0
  6. package/package.json +8 -8
  7. package/.vscode/extensions.json +0 -15
  8. package/.vscode/settings.json +0 -82
  9. package/lex.config.js +0 -4
  10. package/src/config.ts +0 -121
  11. package/src/data/conversations.ts +0 -181
  12. package/src/data/dynamodb.ts +0 -157
  13. package/src/data/email.ts +0 -163
  14. package/src/data/files.ts +0 -352
  15. package/src/data/groups.ts +0 -308
  16. package/src/data/images.ts +0 -606
  17. package/src/data/index.ts +0 -23
  18. package/src/data/ios.ts +0 -249
  19. package/src/data/locations.ts +0 -114
  20. package/src/data/messages.ts +0 -237
  21. package/src/data/notifications.ts +0 -48
  22. package/src/data/payments.ts +0 -675
  23. package/src/data/posts.ts +0 -561
  24. package/src/data/reactions.ts +0 -186
  25. package/src/data/s3.ts +0 -117
  26. package/src/data/search.ts +0 -74
  27. package/src/data/sms.ts +0 -60
  28. package/src/data/subscription.ts +0 -228
  29. package/src/data/tags.ts +0 -230
  30. package/src/data/users.ts +0 -254
  31. package/src/index.ts +0 -7
  32. package/src/types/apps.ts +0 -56
  33. package/src/types/arangodb.ts +0 -23
  34. package/src/types/auth.ts +0 -20
  35. package/src/types/conversations.ts +0 -11
  36. package/src/types/email.ts +0 -17
  37. package/src/types/files.ts +0 -31
  38. package/src/types/google.ts +0 -37
  39. package/src/types/groups.ts +0 -27
  40. package/src/types/images.ts +0 -32
  41. package/src/types/index.ts +0 -21
  42. package/src/types/locations.ts +0 -24
  43. package/src/types/messages.ts +0 -16
  44. package/src/types/notifications.ts +0 -26
  45. package/src/types/payments.ts +0 -129
  46. package/src/types/posts.ts +0 -33
  47. package/src/types/reactions.ts +0 -8
  48. package/src/types/tags.ts +0 -13
  49. package/src/types/users.ts +0 -89
  50. package/src/utils/analytics.ts +0 -41
  51. package/src/utils/arangodb.ts +0 -100
  52. package/src/utils/auth.ts +0 -61
  53. package/src/utils/graphql.ts +0 -7
  54. package/src/utils/index.ts +0 -10
  55. package/src/utils/objects.ts +0 -34
  56. package/src/utils/redis.ts +0 -17
  57. package/tsconfig.json +0 -45
@@ -24,4 +24,5 @@ export interface PostOptions {
24
24
  readonly longitude?: number;
25
25
  readonly from?: number;
26
26
  readonly to?: number;
27
+ readonly type?: string;
27
28
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nlabs/reaktor",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Reaktor",
5
5
  "main": "./index.js",
6
6
  "types": "./lib/index.d.js",
@@ -35,13 +35,13 @@
35
35
  "dependencies": {
36
36
  "@nlabs/arkhamjs": "^3.11.11",
37
37
  "@nlabs/rip-hunter": "^2.0.1",
38
- "@nlabs/utils": "^1.2.1",
38
+ "@nlabs/utils": "^1.2.2",
39
39
  "apn": "^2.2.0",
40
40
  "arangojs": "^6.0.0",
41
- "aws-sdk": "^2.420.0",
41
+ "aws-sdk": "^2.423.0",
42
42
  "gm": "^1.23.1",
43
43
  "google-libphonenumber": "^3.0.10",
44
- "googleapis": "^37.2.0",
44
+ "googleapis": "^38.0.0",
45
45
  "graphql": "^14.0.2",
46
46
  "graphql-errors": "^2.1.0",
47
47
  "graphql-fields": "^2.0.3",
@@ -52,9 +52,9 @@
52
52
  "numeral": "^2.0.6",
53
53
  "redis": "^2.8.0",
54
54
  "request-promise": "^4.2.2",
55
- "stripe": "^6.26.0",
55
+ "stripe": "^6.28.0",
56
56
  "to": "^0.2.9",
57
- "twilio": "^3.29.1",
57
+ "twilio": "^3.29.2",
58
58
  "typed-promisify": "^0.4.0",
59
59
  "universal-analytics": "^0.4.16",
60
60
  "update": "^0.7.4"
@@ -64,9 +64,9 @@
64
64
  "@types/history": "^4.6.2",
65
65
  "@types/jest": "^24.0.11",
66
66
  "@types/luxon": "^1.11.0",
67
- "@types/node": "^11.11.2",
67
+ "@types/node": "^11.11.3",
68
68
  "@types/twilio": "^0.0.10",
69
- "eslint": "^5.15.1",
69
+ "eslint": "^5.15.3",
70
70
  "eslint-config-styleguidejs": "^1.0.8",
71
71
  "graphql-tools": "^4.0.0",
72
72
  "source-map-loader": "^0.2.4",
@@ -1,15 +0,0 @@
1
- {
2
- "recommendations": [
3
- "dbaeumer.vscode-eslint",
4
- "streetsidesoftware.code-spell-checker",
5
- "bierner.markdown-preview-github-styles",
6
- "DavidAnson.vscode-markdownlint",
7
- "ricard.postcss",
8
- "shinnn.stylelint",
9
- "jpoissonnier.vscode-styled-components",
10
- "flowtype.flow-for-vscode",
11
- "rbbit.typescript-hero",
12
- "Equinusocio.vsc-material-theme",
13
- "PKief.material-icon-theme"
14
- ]
15
- }
@@ -1,82 +0,0 @@
1
- {
2
- "cSpell.words": [
3
- "arkham",
4
- "arkhamjs",
5
- "nitrogenlabs",
6
- "nlabs",
7
- "polyfill",
8
- "transpiler"
9
- ],
10
- "css.validate": false,
11
- "editor.autoClosingBrackets": "never",
12
- "editor.detectIndentation": false,
13
- "editor.formatOnSave": true,
14
- "editor.rulers": [
15
- 120
16
- ],
17
- "editor.tabCompletion": "on",
18
- "editor.tabSize": 2,
19
- "editor.wordWrap": "off",
20
- "editor.wordWrapColumn": 120,
21
- "editor.wrappingIndent": "indent",
22
- "emmet.includeLanguages": {
23
- "postcss": "css"
24
- },
25
- "emmet.syntaxProfiles": {
26
- "postcss": "css"
27
- },
28
- "eslint.autoFixOnSave": true,
29
- "eslint.alwaysShowStatus": true,
30
- "eslint.enable": true,
31
- "eslint.packageManager": "yarn",
32
- "eslint.validate": [
33
- {
34
- "language": "javascript",
35
- "autoFix": true
36
- },
37
- {
38
- "language": "javascriptreact",
39
- "autoFix": true
40
- },
41
- {
42
- "language": "typescript",
43
- "autoFix": true
44
- },
45
- {
46
- "language": "typescriptreact",
47
- "autoFix": true
48
- }
49
- ],
50
- "explorer.decorations.badges": false,
51
- "files.autoSave": "onFocusChange",
52
- "html.format.indentInnerHtml": true,
53
- "html.format.indentHandlebars": true,
54
- "html.suggest.html5": false,
55
- "explorer.confirmDragAndDrop": false,
56
- "files.trimTrailingWhitespace": true,
57
- "javascript.autoClosingTags": false,
58
- "javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": false,
59
- "javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": false,
60
- "javascript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions": false,
61
- "javascript.format.insertSpaceAfterKeywordsInControlFlowStatements": false,
62
- "javascript.updateImportsOnFileMove.enabled": "never",
63
- "html.autoClosingTags": false,
64
- "html.format.enable": false,
65
- "html.format.endWithNewline": true,
66
- "html.format.extraLiners": "",
67
- "typescript.autoClosingTags": false,
68
- "typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": false,
69
- "typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": false,
70
- "typescript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions": false,
71
- "typescript.format.insertSpaceAfterKeywordsInControlFlowStatements": false,
72
- "typescript.updateImportsOnFileMove.enabled": "never",
73
- "typescriptHero.imports.insertSpaceBeforeAndAfterImportBraces": false,
74
- "typescriptHero.imports.multiLineTrailingComma": false,
75
- "typescriptHero.imports.multiLineWrapThreshold": 120,
76
- "typescriptHero.imports.organizeOnSave": true,
77
- "window.zoomLevel": 0,
78
- "javascript.preferences.importModuleSpecifier": "relative",
79
- "javascript.preferences.quoteStyle": "single",
80
- "typescript.preferences.importModuleSpecifier": "relative",
81
- "typescript.preferences.quoteStyle": "single",
82
- }
package/lex.config.js DELETED
@@ -1,4 +0,0 @@
1
- module.exports = {
2
- outputPath: 'lib',
3
- useTypescript: true
4
- };
package/src/config.ts DELETED
@@ -1,121 +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 get from 'lodash/get';
6
- import merge from 'lodash/merge';
7
-
8
- export interface AppConfig {
9
- readonly app?: object;
10
- readonly arangodb?: object;
11
- readonly aws?: object;
12
- readonly giphy?: object;
13
- readonly google?: object;
14
- readonly image?: object;
15
- readonly redis?: object;
16
- readonly stripe?: object;
17
- readonly twilio?: object;
18
- }
19
-
20
- export interface EnvConfig {
21
- readonly default: AppConfig;
22
- readonly development: AppConfig;
23
- readonly production: AppConfig;
24
- readonly test: AppConfig;
25
- }
26
-
27
- const appPackage: any = require('../package.json');
28
-
29
- const {arangodbDatabase, arangodbPassword, arangodbPort = '8529', arangodbUrl, arangodbUsername} = process.env;
30
-
31
- export class Config {
32
- static values: EnvConfig = {
33
- default: {
34
- app: {
35
- name: 'reaktor',
36
- url: 'reaktor.io',
37
- version: appPackage.version
38
- },
39
- arangodb: {
40
- apiUrl: `http://${arangodbUsername}:${arangodbPassword}@${arangodbUrl}:${arangodbPort}`,
41
- database: arangodbDatabase,
42
- dump: '/Applications/ArangoDB-CLI.app/Contents/MacOS/arangodump',
43
- password: arangodbPassword,
44
- port: arangodbPort,
45
- restore: '/Applications/ArangoDB-CLI.app/Contents/MacOS/arangorestore',
46
- url: arangodbUrl,
47
- username: arangodbUsername
48
- },
49
- aws: {
50
- Bucket: 'dev.reaktor.io',
51
- accessKeyId: 'AKIAJIYDT3EA2ZFMTJNA',
52
- maxRetries: 3,
53
- region: 'us-east-1',
54
- secretAccessKey: 'bUssQRtJTZC7geF9RDH5KCn8CalVnf2VT34yqS+9',
55
- signatureVersion: 'v4'
56
- },
57
- giphy: {
58
- key: 'dc6zaTOxFJmzC'
59
- },
60
- google: {
61
- analytics: {
62
- accountId: '78158717',
63
- trackingId: 'UA-78158717-1'
64
- },
65
- geocode: {
66
- key: 'AIzaSyBwjmpBjWhiJoBCZiYzRurM9m4WnCxslv0',
67
- url: 'https://maps.googleapis.com/maps/api/geocode/json'
68
- },
69
- key: 'AIzaSyC3_f2Us3y0qjbyMJ-4t5ObtCzfq_FHIgQ'
70
- },
71
- image: {
72
- imgQuality: 90,
73
- imgSize: 1500,
74
- thmQuality: 80,
75
- thmSize: 150
76
- },
77
- redis: {
78
- host: '127.0.0.1',
79
- port: 6379
80
- },
81
- stripe: {
82
- token: 'sk_test_LS956be57YUXTB5a4sLGb5BQ'
83
- },
84
- twilio: {
85
- number: '+15005550006',
86
- sid: 'AC6bd7f513cbed2e5134c650be06cc732e',
87
- token: '520ae739e761bab759b147f1ad28278f'
88
- }
89
- },
90
- development: {
91
- },
92
- production: {
93
- arangodb: {
94
- dump: '/usr/bin/arangodump',
95
- restore: '/usr/bin/arangorestore',
96
- },
97
- aws: {
98
- Bucket: 'box.reaktor.io'
99
- },
100
- redis: {
101
- host: 'reaktor-redis.ehcvnt.0001.use1.cache.amazonaws.com'
102
- },
103
- stripe: {
104
- token: 'sk_live_bElZl8RLhMCJy33KG4lyLD4o'
105
- },
106
- twilio: {
107
- number: '+18554165227',
108
- sid: 'AC90b0528a911e652d643329a4d7b4d2c7',
109
- token: 'a7941d173bd4846d0966a186e9865b72'
110
- }
111
- },
112
- test: {
113
- }
114
- };
115
-
116
- static get(path: string | string[]): any {
117
- const environment: string = process.env.stage || 'development';
118
- const configValues: object = merge(this.values.default, this.values[environment], {environment});
119
- return get(configValues, path);
120
- }
121
- }
@@ -1,181 +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} from '@nlabs/utils';
6
- import {aql} from 'arangojs';
7
- import {AqlQuery} from 'arangojs/lib/cjs/aql-query';
8
- import {ArrayCursor} from 'arangojs/lib/cjs/cursor';
9
- import cloneDeep from 'lodash/cloneDeep';
10
- import identity from 'lodash/identity';
11
- import isEmpty from 'lodash/isEmpty';
12
- import pick from 'lodash/pick';
13
- import {ApiContext} from 'types/auth';
14
-
15
- import {ArangoDBLimit, ConversationType, ImageUrlData, UserType} from '../types';
16
- import {getLimit, useDb} from '../utils';
17
- import {logError} from '../utils/analytics';
18
- import {getUrlImages} from './images';
19
- import {getDisplayName} from './users';
20
-
21
- const eventCategory: string = 'conversations';
22
-
23
- export const getConversationList = (context: ApiContext, from: number, to: number): Promise<ConversationType[]> => {
24
- const action: string = 'getList';
25
- const {database, userId: sessionId} = context;
26
- const limit: ArangoDBLimit = getLimit(from, to);
27
- const aqlQry: string = `FOR c IN conversations
28
- FILTER POSITION(c.users, "${sessionId}", false)
29
- LET u = (
30
- FOR g IN c.users
31
- FOR u IN users
32
- FILTER g == u._key
33
- RETURN {_key:u._key, first:u.first, last:u.last, name:u.name, email:u.email, username:u.username, photo:u.photo }
34
- )
35
- FILTER LENGTH(u) > 1
36
- ${limit.aql}
37
- RETURN {_key:c._key, name: c.name, direct: c.direct, users: u}`;
38
-
39
- return useDb(database).query(aqlQry)
40
- .then((cursor: ArrayCursor) => cursor.all())
41
- .catch((error: Error) => logError({
42
- action,
43
- category: eventCategory,
44
- label: 'db_error'
45
- }, error, context).then(() => null));
46
- };
47
-
48
- export const getDirectConversation = (context: ApiContext, userId: string): Promise<ConversationType> => {
49
- const action: string = 'getDirect';
50
- const {database, userId: sessionId} = context;
51
- const formatUserId: string = parseId(userId);
52
-
53
- const aqlQry: AqlQuery = aql`FOR c IN conversations
54
- FILTER LENGTH(c.users) == 2 &&
55
- POSITION(c.users, ${sessionId}, false) &&
56
- POSITION(c.users, ${formatUserId}, false)
57
- LET u = (
58
- FOR g IN c.users
59
- FOR user IN users
60
- FILTER user._key == g
61
- RETURN user
62
- )
63
- LIMIT 1
64
- RETURN MERGE(c, {users: u})`;
65
-
66
- return useDb(database).query(aqlQry)
67
- .then((cursor: ArrayCursor) => cursor.next())
68
- .then((conversation: ConversationType = {}) => {
69
- const {users = []} = conversation;
70
-
71
- if(users.length) {
72
- conversation.users = users.map((user: UserType) => {
73
- const {_key: userKey, imgId} = user;
74
- const thumbUrlData: ImageUrlData = {
75
- directory: 'images',
76
- imgId,
77
- isThumb: true,
78
- type: 'users',
79
- typeId: userKey
80
- };
81
- return {
82
- ...user,
83
- name: getDisplayName(user),
84
- thumb: getUrlImages(thumbUrlData)
85
- };
86
- });
87
- }
88
-
89
- return conversation;
90
- })
91
- .catch((error: Error) => logError({
92
- action,
93
- category: eventCategory,
94
- label: 'db_error'
95
- }, error, context).then(() => null));
96
- };
97
-
98
- export const getConversation = (context: ApiContext, convoId: string): Promise<ConversationType> => {
99
- const action: string = 'getItem';
100
- const {database, userId: sessionId} = context;
101
- const formatConvoId: string = parseId(convoId);
102
-
103
- const aqlQry: AqlQuery = aql`FOR c IN conversations
104
- FILTER ${formatConvoId} == c._key && IS_LIST(c.users) && POSITION(c.users, ${sessionId}, false)
105
- LET u = (
106
- FOR g IN c.users
107
- FOR u IN users
108
- FILTER g == u._key
109
- RETURN {_key:u._key, first:u.first, last:u.last, name:u.name, email:u.email, username:u.username, photo:u.photo }
110
- )
111
- FILTER LENGTH(u) > 1
112
- LIMIT 1
113
- RETURN MERGE(c, {users: u})`;
114
-
115
- return useDb(database).query(aqlQry)
116
- .then((cursor: ArrayCursor) => cursor.next())
117
- .then((conversation: ConversationType = {}) => {
118
- if(!isEmpty(conversation)) {
119
- conversation.users = conversation.users.map((user: UserType) => {
120
- const {_key: userKey, imgId} = user;
121
- const thumbUrlData: ImageUrlData = {
122
- directory: 'images',
123
- imgId,
124
- isThumb: true,
125
- type: 'users',
126
- typeId: userKey
127
- };
128
- return {
129
- ...user,
130
- name: getDisplayName(user),
131
- thumb: getUrlImages(thumbUrlData)
132
- };
133
- });
134
-
135
- return conversation;
136
- }
137
- return {};
138
- })
139
- .catch((error: Error) => logError({
140
- action,
141
- category: eventCategory,
142
- label: 'db_error'
143
- }, error, context).then(() => null));
144
- };
145
-
146
- export const updateConversation = (context: ApiContext, item): Promise<ConversationType> => {
147
- const action: string = 'update';
148
- const {database, userId: sessionId} = context;
149
- const {direct, id, name, users} = pick(item, identity);
150
- const rcpt: UserType[] = users || [];
151
- const formatId: string = item.id || createHash(`convo-${sessionId}-${rcpt.join('')}`);
152
- const now: number = Date.now();
153
- const update: any = {
154
- // Direct message
155
- direct: !!direct ? direct : undefined,
156
- modified: now,
157
- name: !!name ? name : undefined,
158
- // Users
159
- users: !!users ? users : undefined
160
- };
161
-
162
- const insert: any = {
163
- ...cloneDeep(update),
164
- _key: formatId,
165
- added: now
166
- };
167
-
168
- const aqlQry: AqlQuery = aql`UPSERT {_key: ${id}}
169
- INSERT ${insert}
170
- UPDATE ${update}
171
- IN conversations RETURN NEW`;
172
-
173
- return useDb(database).query(aqlQry)
174
- .then((cursor: ArrayCursor) => cursor.next())
175
- .then((conversation: ConversationType = {}) => conversation)
176
- .catch((error: Error) => logError({
177
- action,
178
- category: eventCategory,
179
- label: 'db_error'
180
- }, error, context).then(() => null));
181
- };
@@ -1,157 +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 aws, {DynamoDB} from 'aws-sdk';
6
- import {
7
- BatchWriteItemInput,
8
- BatchWriteItemOutput,
9
- DeleteItemInput,
10
- DeleteItemOutput,
11
- GetItemInput,
12
- GetItemOutput,
13
- PutItemInput,
14
- PutItemOutput,
15
- QueryInput,
16
- QueryOutput,
17
- UpdateItemInput,
18
- UpdateItemOutput
19
- } from 'aws-sdk/clients/dynamodb';
20
-
21
- import {Config} from '../config';
22
-
23
- // const eventCategory: string = 'dynamodb';
24
-
25
- export const dynamoGet = (params: GetItemInput): Promise<GetItemOutput> => {
26
- return new Promise((resolve, reject) => {
27
- aws.config.update(Config.get('aws'));
28
- const dynamodb: DynamoDB = new DynamoDB();
29
- params.ConsistentRead = false;
30
-
31
- dynamodb.getItem(params, (error: Error, results: GetItemOutput) => {
32
- if(error) {
33
- return reject(error);
34
- }
35
-
36
- return resolve(results);
37
- });
38
- });
39
- };
40
-
41
- export const dynamoGetList = (params: QueryInput, index): Promise<GetItemOutput[]> => {
42
- return new Promise((resolve, reject) => {
43
- aws.config.update(Config.get('aws'));
44
- const dynamodb: DynamoDB = new DynamoDB();
45
- const {ConsistentRead: consistentRead} = params;
46
- const updatedParams = {...params};
47
-
48
- if(index) {
49
- updatedParams.ExclusiveStartKey = index;
50
- }
51
-
52
- if(!consistentRead) {
53
- updatedParams.ConsistentRead = false;
54
- }
55
-
56
- dynamodb.query(updatedParams, (error: Error, output: QueryOutput) => {
57
- if(error) {
58
- return reject(error);
59
- }
60
- // Save list of items
61
- const list: any[] = parseDynamo(output);
62
- const {LastEvaluatedKey: lastKey} = output;
63
-
64
- if(lastKey !== undefined) {
65
- // Save last index before looping
66
- return dynamoGetList(params, lastKey);
67
- }
68
-
69
- // Query complete, return final list
70
- return resolve(list);
71
- });
72
- });
73
- };
74
-
75
- export const dynamoPut = (params: PutItemInput): Promise<PutItemOutput> => {
76
- return new Promise((resolve, reject) => {
77
- aws.config.update(Config.get('aws'));
78
- const dynamodb: DynamoDB = new DynamoDB();
79
-
80
- dynamodb.putItem(params, (error, output: PutItemOutput) => {
81
- if(error) {
82
- return reject(error);
83
- }
84
- return resolve(output);
85
- });
86
- });
87
- };
88
-
89
- export const dynamoUpdate = (params: UpdateItemInput): Promise<UpdateItemOutput> => {
90
- return new Promise((resolve, reject) => {
91
- aws.config.update(Config.get('aws'));
92
- const dynamodb: DynamoDB = new DynamoDB();
93
-
94
- dynamodb.updateItem(params, (error: Error, output: UpdateItemOutput) => {
95
- if(error) {
96
- return reject(error);
97
- }
98
- return resolve(output);
99
- });
100
- });
101
- };
102
-
103
- export const dynamoPutList = (params: BatchWriteItemInput): Promise<BatchWriteItemOutput> => {
104
- return new Promise((resolve, reject) => {
105
- aws.config.update(Config.get('aws'));
106
- const dynamodb: DynamoDB = new DynamoDB();
107
-
108
- dynamodb.batchWriteItem(params, (error: Error, output: BatchWriteItemOutput) => {
109
- if(error) {
110
- return reject(error);
111
- }
112
- return resolve(output);
113
- });
114
- });
115
- };
116
-
117
- export const dynamoDel = (params: DeleteItemInput): Promise<DeleteItemOutput> => {
118
- return new Promise((resolve, reject) => {
119
- aws.config.update(Config.get('aws'));
120
- const dynamodb: DynamoDB = new DynamoDB();
121
-
122
- dynamodb.deleteItem(params, (error, output: DeleteItemOutput) => {
123
- if(error) {
124
- return reject(error);
125
- }
126
- return resolve(output);
127
- });
128
- });
129
- };
130
-
131
- export const parseDynamo = (results: QueryOutput): any[] => {
132
- const {Items: items} = results;
133
- const data: any[] = [];
134
-
135
- for(let idx: number = 0, len = items.length; idx < len; idx++) {
136
- const tmp = items[idx];
137
- const obj = {};
138
- let key;
139
-
140
- for(key in tmp) {
141
- if(tmp.hasOwnProperty(key)) {
142
- if(tmp[key].S) {
143
- obj[key] = tmp[key].S.toString();
144
- } else if(tmp[key].N) {
145
- obj[key] = parseFloat(tmp[key].N);
146
- } else {
147
- obj[key] = tmp[key].B;
148
- }
149
- }
150
- }
151
-
152
- data.push(obj);
153
- }
154
-
155
- return data;
156
- };
157
-