piper-utils 1.0.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 (38) hide show
  1. package/.babelrc +12 -0
  2. package/README.md +119 -0
  3. package/bin/main.js +1003 -0
  4. package/bin/main.js.LICENSE.txt +151 -0
  5. package/bin/main.js.map +1 -0
  6. package/bitbucket-pipelines.yml +14 -0
  7. package/jasmine.json +7 -0
  8. package/package.json +62 -0
  9. package/src/database/dbSetUp/migrations.js +45 -0
  10. package/src/database/dbUtils/queryStringUtils/accessRightsUtils.js +149 -0
  11. package/src/database/dbUtils/queryStringUtils/accessRightsUtils.test.js +177 -0
  12. package/src/database/dbUtils/queryStringUtils/createFilters.js +92 -0
  13. package/src/database/dbUtils/queryStringUtils/createFilters.test.js +37 -0
  14. package/src/database/dbUtils/queryStringUtils/createIncludes.js +45 -0
  15. package/src/database/dbUtils/queryStringUtils/createIncludes.test.js +20 -0
  16. package/src/database/dbUtils/queryStringUtils/createSort.js +36 -0
  17. package/src/database/dbUtils/queryStringUtils/createSort.test.js +60 -0
  18. package/src/database/dbUtils/queryStringUtils/defaultFilters.js +108 -0
  19. package/src/database/dbUtils/queryStringUtils/defaultFilters.test.js +50 -0
  20. package/src/database/dbUtils/queryStringUtils/findAll.js +42 -0
  21. package/src/database/dbUtils/queryStringUtils/findAll.test.js +79 -0
  22. package/src/database/dbUtils/queryStringUtils/mocks/mocks.js +127 -0
  23. package/src/dynamo/dynamoUtils.js +16 -0
  24. package/src/eventManager/handleEvents.js +32 -0
  25. package/src/eventManager/handleEvents.test.js +92 -0
  26. package/src/eventManager/handleFile.js +76 -0
  27. package/src/eventManager/handleFile.test.js +352 -0
  28. package/src/eventManager/publishEvents.js +99 -0
  29. package/src/eventManager/publishEvents.test.js +161 -0
  30. package/src/eventManager/watchBucket.js +41 -0
  31. package/src/eventManager/watchBucket.test.js +137 -0
  32. package/src/index.js +40 -0
  33. package/src/requestResonse/errorCodes.js +132 -0
  34. package/src/requestResonse/requestResponse.js +198 -0
  35. package/src/requestResonse/requestResponse.test.js +241 -0
  36. package/src/s3/S3Utils.js/S3Utils.js +20 -0
  37. package/src/sns/SNSUtils.js +18 -0
  38. package/webpack.config.js +50 -0
package/.babelrc ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "presets": [
3
+ [
4
+ "env",
5
+ {
6
+ "targets": {
7
+ "node": "16"
8
+ }
9
+ }
10
+ ]
11
+ ]
12
+ }
package/README.md ADDED
@@ -0,0 +1,119 @@
1
+ ### Piper-Utils
2
+
3
+ This repository contains a collection of utilities for working with Cognito Lambda Sequelize and AWS
4
+
5
+ ### Installation
6
+ Import items using npm bitbucket link in package.json
7
+
8
+ ```
9
+ "piper-utils":"git+ssh://git@bitbucket.org/kevinlbatchelor/piper-utils.git",
10
+ ```
11
+
12
+ Add ssh key to repo to allow npm install to work
13
+
14
+
15
+ ### Publish
16
+
17
+ ```npm run build```
18
+ - Tag and Commit
19
+
20
+ ### TEST
21
+ ```npm run test```
22
+
23
+ #### accessRightsUtils
24
+
25
+ - Takes an event object and returns a intersection list of requested businessIds and allowed businessIds
26
+
27
+ ```
28
+ const businessIds = accessRightsUtils(event);
29
+ ```
30
+ #### parseBody
31
+ - Takes the event and returns the post body as a JSON object
32
+
33
+ ```
34
+ const eventBody = parseBody(event);
35
+ ```
36
+ #### getCurrentUser
37
+ - Takes the event and returns an object with the current user's id and email
38
+
39
+ ```
40
+ const user = getCurrentUser(event);
41
+ user = {id: '123', email: 'test@test.com'}
42
+ ```
43
+ #### checkWriteAccess
44
+ - Takes the event, looks for a businessId property in the event body, and returns the businessId if the user has write access to it. If the user does not have write access, it will throw an error.
45
+
46
+ ```
47
+ const businessId = checkWriteAccess(event);
48
+ ```
49
+ #### createFilters
50
+ - Takes the event and Sequelize object filter and creates a Sequelize where with applied filters
51
+
52
+ ```
53
+ const where = createFilters(event, partFilter);
54
+ ```
55
+ #### createSort
56
+ - Takes the event and sequelize object sort and creates a Sequelize order with applied sort
57
+
58
+ ```
59
+ const order = createSort(event, partSort);
60
+ ```
61
+ #### createIncludes
62
+ - Takes the event and sequelize object includes and creates a Sequelize includes from query string params
63
+
64
+ ```
65
+ const includes = createIncludes(event, partSort);
66
+ ```
67
+ #### findAll
68
+ - Takes a Sequelize object and options, wraps sequelize findAll in a try/catch, and returns the results with pagination and applies default options. Applies accessRightsUtils
69
+
70
+ ```
71
+ const part = await findAll(Part, {
72
+ where,
73
+ order,
74
+ offset,
75
+ limit
76
+ }
77
+ );
78
+ ```
79
+ #### success
80
+ - Takes json object and options. Returns a json object with the status code and the json object. Closes the database connection if it is open. Creates correct http response object and status code.
81
+
82
+ ```
83
+ const response = success(part, { dbClose });
84
+ return success(part, { dbClose });
85
+
86
+ //response
87
+ {
88
+ statusCode: 200,
89
+ headers: {
90
+ 'Access-Control-Allow-Origin': '*',
91
+ 'Access-Control-Allow-Credentials': true
92
+ },
93
+ body: //JSON BODY
94
+ }
95
+
96
+ ```
97
+ #### failure
98
+ - Takes error object and options. Returns a json object with the status code and the error object. Closes the database connection if it is open. Creates correct http response object and status code. Logs error to console. Reads out Sequelize errors, Axios and others to readable format. setts correct error message and error status code
99
+
100
+ ```
101
+ const response = failure(part, { dbClose });
102
+ return failure(error, { dbClose });
103
+
104
+ //error
105
+ {
106
+ statusCode: 500, errorCode: '5XX', message: ''
107
+ }
108
+
109
+ //response
110
+ {
111
+ statusCode: 500, headers: {
112
+ 'Access-Control-Allow-Origin': '*',
113
+ 'Access-Control-Allow-Credentials': true
114
+ }, body: '{"statusCode":500,"errorCode":"5XX","message":""}'
115
+ }
116
+
117
+ ```
118
+
119
+