piper-utils 1.0.58 → 1.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.
- package/bin/main.js +232 -910
- package/bin/main.js.map +1 -1
- package/package.json +10 -10
- package/src/database/dbUtils/queryStringUtils/createFilters.js +6 -3
- package/src/dynamo/dynamoUtils.test.js +39 -0
- package/src/eventManager/handleFile.js +26 -8
- package/src/eventManager/handleFile.test.js +31 -0
- package/src/eventManager/publishEvents.js +8 -3
- package/src/eventManager/publishEvents.test.js +12 -16
- package/src/s3/S3Utils.js/S3Utils.js +1 -1
- package/src/s3/S3Utils.js/S3Utils.test.js +81 -0
- package/src/sns/SNSUtils.test.js +52 -0
package/bin/main.js
CHANGED
|
@@ -1,116 +1,79 @@
|
|
|
1
|
-
/******/
|
|
2
|
-
/******/
|
|
3
|
-
/******/
|
|
4
|
-
|
|
5
|
-
/***/
|
|
6
|
-
|
|
7
|
-
!*** ./src/database/dbSetup/migrations.js ***!
|
|
8
|
-
\********************************************/
|
|
9
|
-
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
10
|
-
|
|
11
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));exports.runMigrations = runMigrations;var _lodash = __webpack_require__(/*! lodash */ "lodash");var _lodash2 = _interopRequireDefault(_lodash);var _umzug = __webpack_require__(/*! umzug */ "umzug");function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };} /**
|
|
1
|
+
/******/(()=>{// webpackBootstrap
|
|
2
|
+
/******/"use strict";
|
|
3
|
+
/******/var __webpack_modules__={
|
|
4
|
+
/***/871:
|
|
5
|
+
/***/(__unused_webpack_module,exports,__webpack_require__)=>{Object.defineProperty(exports,"__esModule",{value:!0}),exports.runMigrations=
|
|
6
|
+
/**
|
|
12
7
|
* Execute database migrations
|
|
13
8
|
* @param {string} databaseName - name of database to create (or verify existence)
|
|
14
9
|
* @param {object} sequelizeInstance - instance of Sequelize (must be initialized)
|
|
15
10
|
* @param {function} initializeModels - function to run to sync Sequelize models with database
|
|
16
11
|
* @param {string} pathToMigrationFolder - pass in the path if using windows. windows and linux PWD will be different
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
migrations: _lodash2.default.chain(pendingMigrations).
|
|
28
|
-
map('file').
|
|
29
|
-
reverse().
|
|
30
|
-
value()
|
|
31
|
-
}).then(() => {
|
|
32
|
-
const msg = 'UTIL Error: Error with migrating up:' + upError;
|
|
33
|
-
console.error(msg);
|
|
34
|
-
throw new Error(msg);
|
|
35
|
-
}, (downError) => {
|
|
36
|
-
const msg = 'UTIL Error: Error with migrating down:' + downError;
|
|
37
|
-
console.error(msg);
|
|
38
|
-
throw new Error(msg);
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
// The following line is needed to sync (create) tables, but not to database updates
|
|
43
|
-
// in the past it worked to leave it in, but now the tags module causes foreign key problems
|
|
44
|
-
// The tables are still initiated by being passed in to run migrations
|
|
45
|
-
await initializeModels();
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/***/ }),
|
|
49
|
-
|
|
50
|
-
/***/ "./src/database/dbUtils/queryStringUtils/accessRightsUtils.js":
|
|
51
|
-
/*!********************************************************************!*\
|
|
52
|
-
!*** ./src/database/dbUtils/queryStringUtils/accessRightsUtils.js ***!
|
|
53
|
-
\********************************************************************/
|
|
54
|
-
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
55
|
-
|
|
56
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));exports.userRoles = undefined;exports.isSystemUser = isSystemUser;exports.accessRightsUtils = accessRightsUtils;exports.userDefaultBid = userDefaultBid;exports.getRequestedBusinessIds = getRequestedBusinessIds;exports.getAccessRightsInfo = getAccessRightsInfo;exports.getDefaultBusinessIDInfo = getDefaultBusinessIDInfo;exports.getBusinessesInfo = getBusinessesInfo;exports.getModuleInfo = getModuleInfo;exports.checkModule = checkModule;exports.checkWriteAccess = checkWriteAccess;var _lodash = __webpack_require__(/*! lodash */ "lodash");var _lodash2 = _interopRequireDefault(_lodash);var _errorCodes = __webpack_require__(/*! ../../../requestResonse/errorCodes.js */ "./src/requestResonse/errorCodes.js");var _requestResponse = __webpack_require__(/*! ../../../requestResonse/requestResponse.js */ "./src/requestResonse/requestResponse.js");function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}function isSystemUser(event) {let jsonToParse = _lodash2.default.get(event, 'requestContext.authorizer.claims.custom:SYSTEM') || _lodash2.default.get(event, 'requestContext.authorizer.custom:SYSTEM') || 'false';let isSys = false;try {isSys = JSON.parse(jsonToParse);return isSys;} catch (e) {console.error('error with system user:', e);return false;}} /**
|
|
57
|
-
* Get the allowed businessIds for a user from the lambda event, compare it to businessIds, return what user has access to.
|
|
58
|
-
*
|
|
59
|
-
* @param {object} event - The lambda event passed in by a validated api request.
|
|
60
|
-
* @param {{useCognitoBid:boolean}} [options] - An object with options, useCognitoBid prefers the businessId set in cognito if set and does not return the local bid of 1 if a bid is in the claim.
|
|
61
|
-
* @returns {array} A list of businessIds that have been requested and are allowed to for some user.
|
|
62
|
-
*/function accessRightsUtils(event, options) {const useCognitoBid = _lodash2.default.get(options, 'useCognitoBid', false);const requestedBusinessIds = getRequestedBusinessIds(event);const allowedBusinessIds = getAllowedBusinessIds(event, useCognitoBid);if (isSystemUser(event)) {return requestedBusinessIds;}if (requestedBusinessIds.length === 0) {return allowedBusinessIds;}return _lodash2.default.intersection(requestedBusinessIds, allowedBusinessIds);} /**
|
|
12
|
+
*/
|
|
13
|
+
async function runMigrations(databaseName,sequelizeInstance,initializeModels,pathToMigrationFolder=`${process.env.PWD}/migrations/*.js`){const umzug=new _umzug.Umzug({migrations:{glob:pathToMigrationFolder},context:sequelizeInstance.getQueryInterface(),storage:new _umzug.SequelizeStorage({sequelize:sequelizeInstance}),logger:console}),pendingMigrations=await umzug.pending();console.log("-------\x3eUTIL Pending Migrations:",pendingMigrations,pathToMigrationFolder),await umzug.up().catch((upError=>(console.error("Migration Error: ",upError),umzug.down({migrations:_lodash2.default.chain(pendingMigrations).map("file").reverse().value()}).then((()=>{const msg="UTIL Error: Error with migrating up:"+upError;throw console.error(msg),new Error(msg)}),(downError=>{const msg="UTIL Error: Error with migrating down:"+downError;throw console.error(msg),new Error(msg)}))))),
|
|
14
|
+
// The following line is needed to sync (create) tables, but not to database updates
|
|
15
|
+
// in the past it worked to leave it in, but now the tags module causes foreign key problems
|
|
16
|
+
// The tables are still initiated by being passed in to run migrations
|
|
17
|
+
await initializeModels()}
|
|
18
|
+
/***/;var _lodash2=function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}(__webpack_require__(825)),_umzug=__webpack_require__(920)},
|
|
19
|
+
/***/673:
|
|
20
|
+
/***/(__unused_webpack_module,exports,__webpack_require__)=>{Object.defineProperty(exports,"__esModule",{value:!0}),exports.userRoles=void 0,exports.isSystemUser=isSystemUser,exports.accessRightsUtils=accessRightsUtils,exports.userDefaultBid=
|
|
21
|
+
/**
|
|
63
22
|
* Get the businessID set in cognito as custom:DBI.
|
|
64
23
|
*
|
|
65
24
|
* @param {object} event - The lambda event passed in by a validated api request.
|
|
66
25
|
* @returns {string} The businessID set in cognito as custom:DBI
|
|
67
|
-
*/
|
|
26
|
+
*/
|
|
27
|
+
function userDefaultBid(event){let jsonToParse=_lodash2.default.get(event,"requestContext.authorizer.claims.custom:DBI")||_lodash2.default.get(event,"requestContext.authorizer.custom:DBI")||"{}";const dbi=JSON.parse(jsonToParse);return _lodash2.default.get(dbi,"defaultBid","")||"1"}
|
|
28
|
+
/**
|
|
68
29
|
* Get requested businessIds from the query string.
|
|
69
30
|
*
|
|
70
31
|
* @param {object} event - The lambda event passed in by a validated api request.
|
|
71
32
|
* @returns {array} The businessID requested by the query string
|
|
72
|
-
|
|
33
|
+
*/,exports.getRequestedBusinessIds=getRequestedBusinessIds,exports.getAccessRightsInfo=function getAccessRightsInfo(event){let jsonToParse=_lodash2.default.get(event,"requestContext.authorizer.claims.custom:AR")||_lodash2.default.get(event,"requestContext.authorizer.custom:AR")||"{}";const accessRights=JSON.parse(jsonToParse);return _lodash2.default.get(accessRights,"businessIds",{})},exports.getDefaultBusinessIDInfo=function getDefaultBusinessIDInfo(event){let jsonToParse=_lodash2.default.get(event,"requestContext.authorizer.claims.custom:DBI")||_lodash2.default.get(event,"requestContext.authorizer.custom:DBI")||"{}";const dbi=JSON.parse(jsonToParse);return _lodash2.default.get(dbi,"defaultBid",{})},exports.getBusinessesInfo=getBusinessesInfo,exports.getModuleInfo=getModuleInfo,exports.checkModule=
|
|
34
|
+
/**
|
|
35
|
+
* Get the modules listed in custom:MOD.
|
|
36
|
+
*
|
|
37
|
+
* @param {string} moduleName - A sting name for a module.
|
|
38
|
+
* @param {object} event - The lambda event passed in by a validated api request.
|
|
39
|
+
* @returns {array} The Module access list
|
|
40
|
+
*/
|
|
41
|
+
function checkModule(moduleName,event){const moduleRights=getModuleInfo(event);let allowAccess=_lodash2.default.get(moduleRights,moduleName,!1);if(isSystemUser(event))return;if("local"===process.env.BUILD_ENV)return;if(!allowAccess)throw _errorCodes.errorList.unauthorized},exports.checkWriteAccess=
|
|
42
|
+
/**
|
|
43
|
+
* @param {{body: string}} event
|
|
44
|
+
* @param {{useCognitoBid:boolean}} [options] - An object with options, useCognitoBid prefers the businessId set in cognito if set and does not return the local bid of 1 if a bid is in the claim.
|
|
45
|
+
* @returns {string} businessId
|
|
46
|
+
*/
|
|
47
|
+
function checkWriteAccess(event,options){const eventBody=(0,_requestResponse.parseBody)(event),businessId=(accessRightsUtils(event,options)||[]).find((id=>id===eventBody.businessId)),userRight=getBusinessesInfo(event)[businessId];if(isSystemUser(event))return eventBody.businessId;if("local"===process.env.BUILD_ENV)return eventBody.businessId;if(userRight!==userRoles.admin&&userRight!==userRoles.write||!userRight)throw _errorCodes.errorList.unauthorized;return businessId}
|
|
48
|
+
/***/;var _lodash=__webpack_require__(825),_lodash2=function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}(_lodash),_errorCodes=__webpack_require__(505),_requestResponse=__webpack_require__(435);function isSystemUser(event){let jsonToParse=_lodash2.default.get(event,"requestContext.authorizer.claims.custom:SYSTEM")||_lodash2.default.get(event,"requestContext.authorizer.custom:SYSTEM")||"false",isSys=!1;try{return isSys=JSON.parse(jsonToParse),isSys}catch(e){return console.error("error with system user:",e),!1}}
|
|
49
|
+
/**
|
|
50
|
+
* Get the allowed businessIds for a user from the lambda event, compare it to businessIds, return what user has access to.
|
|
51
|
+
*
|
|
52
|
+
* @param {object} event - The lambda event passed in by a validated api request.
|
|
53
|
+
* @param {{useCognitoBid:boolean}} [options] - An object with options, useCognitoBid prefers the businessId set in cognito if set and does not return the local bid of 1 if a bid is in the claim.
|
|
54
|
+
* @returns {array} A list of businessIds that have been requested and are allowed to for some user.
|
|
55
|
+
*/function accessRightsUtils(event,options){const useCognitoBid=_lodash2.default.get(options,"useCognitoBid",!1),requestedBusinessIds=getRequestedBusinessIds(event),allowedBusinessIds=
|
|
56
|
+
/**
|
|
73
57
|
* Get the allowed businessIds for a user from cognito custom:AR property.
|
|
74
58
|
*
|
|
75
59
|
* @param {object} event - The lambda event passed in by a validated api request.
|
|
76
60
|
* @param useCognitoBid
|
|
77
61
|
* @returns {array} The businessID requested by the query string
|
|
78
|
-
*/
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
* @param {object} event - The lambda event passed in by a validated api request.
|
|
87
|
-
* @returns {array} The Module access list
|
|
88
|
-
*/function getModuleInfo(event) {let jsonToParse = _lodash2.default.get(event, 'requestContext.authorizer.claims.custom:MOD') || _lodash2.default.get(event, 'requestContext.authorizer.custom:MOD') || _lodash2.default.get(event, 'requestContext.authorizer.claims.custom:AR') || _lodash2.default.get(event, 'requestContext.authorizer.custom:AR') || '{}';const moduleRights = JSON.parse(jsonToParse);return _lodash2.default.get(moduleRights, 'module', {});} /**
|
|
62
|
+
*/
|
|
63
|
+
function getAllowedBusinessIds(event,useCognitoBid){const businesses=getBusinessesInfo(event,useCognitoBid);return Object.keys(businesses)}(event,useCognitoBid);return isSystemUser(event)?requestedBusinessIds:0===requestedBusinessIds.length?allowedBusinessIds:_lodash2.default.intersection(requestedBusinessIds,allowedBusinessIds)}function getRequestedBusinessIds(event){let requestedBusinessIds=_lodash2.default.get(event,"queryStringParameters.businessIds",null);const body=(0,_requestResponse.parseBody)(event),bodyBid=body?.businessId;return requestedBusinessIds?requestedBusinessIds?requestedBusinessIds.split(","):[]:bodyBid?[bodyBid]:[]}function getBusinessesInfo(event,useCognitoBid=!1){const json=_lodash2.default.get(event,"requestContext.authorizer.claims.custom:AR")||_lodash2.default.get(event,"requestContext.authorizer.custom:AR")||"{}";let businessIds=_lodash2.default.get(JSON.parse(json),"businessIds",{});// Local environment tweaks
|
|
64
|
+
if("local"===process.env.BUILD_ENV){let b;try{b=JSON.parse(event?.body)}catch(e){}const bodyBid=b?.businessId;// Always inject the default local BID “1” unless the caller explicitly wants
|
|
65
|
+
// what Cognito says **and** Cognito actually returned something.
|
|
66
|
+
useCognitoBid||(businessIds={...businessIds,1:"A"}),// If Cognito gave no BIDs at all, fall back to the local default.
|
|
67
|
+
(0,_lodash.isEmpty)(businessIds)&&(businessIds={1:"A"}),// a businessId is found on the body for local allow it
|
|
68
|
+
bodyBid&&(businessIds[bodyBid]="A")}return businessIds}
|
|
69
|
+
/**
|
|
89
70
|
* Get the modules listed in custom:MOD.
|
|
90
71
|
*
|
|
91
|
-
* @param {string} moduleName - A sting name for a module.
|
|
92
72
|
* @param {object} event - The lambda event passed in by a validated api request.
|
|
93
73
|
* @returns {array} The Module access list
|
|
94
|
-
*/function
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
* @returns {string} businessId
|
|
98
|
-
*/function checkWriteAccess(event, options) {const eventBody = (0, _requestResponse.parseBody)(event);const businessIds = accessRightsUtils(event, options) || [];const businessId = businessIds.find((id) => id === eventBody.businessId);const raw = getBusinessesInfo(event);const userRight = raw[businessId];if (isSystemUser(event)) {return eventBody.businessId;}if (process.env.BUILD_ENV === 'local') {return eventBody.businessId;}if (userRight !== userRoles.admin && userRight !== userRoles.write || !userRight) {throw _errorCodes.errorList.unauthorized;}return businessId;}
|
|
99
|
-
|
|
100
|
-
/***/ }),
|
|
101
|
-
|
|
102
|
-
/***/ "./src/database/dbUtils/queryStringUtils/createFilters.js":
|
|
103
|
-
/*!****************************************************************!*\
|
|
104
|
-
!*** ./src/database/dbUtils/queryStringUtils/createFilters.js ***!
|
|
105
|
-
\****************************************************************/
|
|
106
|
-
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
107
|
-
|
|
108
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));exports.createFilters = undefined;var _lodash = __webpack_require__(/*! lodash */ "lodash");var _lodash2 = _interopRequireDefault(_lodash);
|
|
109
|
-
var _sequelize = __webpack_require__(/*! sequelize */ "sequelize");var _sequelize2 = _interopRequireDefault(_sequelize);
|
|
110
|
-
var _moment = __webpack_require__(/*! moment/moment.js */ "moment/moment.js");var _moment2 = _interopRequireDefault(_moment);
|
|
111
|
-
var _errorCodes = __webpack_require__(/*! ../../../requestResonse/errorCodes.js */ "./src/requestResonse/errorCodes.js");
|
|
112
|
-
var _accessRightsUtils = __webpack_require__(/*! ./accessRightsUtils.js */ "./src/database/dbUtils/queryStringUtils/accessRightsUtils.js");function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}
|
|
113
|
-
|
|
74
|
+
*/function getModuleInfo(event){let jsonToParse=_lodash2.default.get(event,"requestContext.authorizer.claims.custom:MOD")||_lodash2.default.get(event,"requestContext.authorizer.custom:MOD")||_lodash2.default.get(event,"requestContext.authorizer.claims.custom:AR")||_lodash2.default.get(event,"requestContext.authorizer.custom:AR")||"{}";const moduleRights=JSON.parse(jsonToParse);return _lodash2.default.get(moduleRights,"module",{})}const userRoles=exports.userRoles={admin:"A",read:"R",write:"W"}},
|
|
75
|
+
/***/288:
|
|
76
|
+
/***/(__unused_webpack_module,exports,__webpack_require__)=>{Object.defineProperty(exports,"__esModule",{value:!0}),exports.createFilters=void 0;var _lodash2=_interopRequireDefault(__webpack_require__(825)),_sequelize2=_interopRequireDefault(__webpack_require__(31)),_dayjs2=_interopRequireDefault(__webpack_require__(293)),_utc2=_interopRequireDefault(__webpack_require__(137)),_errorCodes=__webpack_require__(505),_accessRightsUtils=__webpack_require__(673);function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}_dayjs2.default.extend(_utc2.default);
|
|
114
77
|
/**
|
|
115
78
|
* Create sequelize where clause from query string parameters and default sort object
|
|
116
79
|
*
|
|
@@ -118,376 +81,84 @@ var _accessRightsUtils = __webpack_require__(/*! ./accessRightsUtils.js */ "./sr
|
|
|
118
81
|
* @param {object} objectFilters - the default filters object created by createDefaultFilters
|
|
119
82
|
* @returns {object} An sequelize where object
|
|
120
83
|
*/
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
const itemName = item.includes('.') ?
|
|
131
|
-
`$${item}$` :
|
|
132
|
-
item;
|
|
133
|
-
|
|
134
|
-
acc[itemName] = {};
|
|
135
|
-
if (val.filterType === _sequelize2.default.Op.iLike) {
|
|
136
|
-
acc[itemName][val.filterType] = `%${query[item]}%`;
|
|
137
|
-
} else if (val.filterType === _sequelize2.default.Op.or) {
|
|
138
|
-
acc[itemName][val.filterType] = [-1 * +query[item], +query[item]];
|
|
139
|
-
} else if (val.filterType === _sequelize2.default.Op.in) {
|
|
140
|
-
acc[itemName][val.filterType] = query[item].split(',');
|
|
141
|
-
} else if (val.filterType === _sequelize2.default.Op.in) {
|
|
142
|
-
acc[itemName][val.filterType] = query[item].split(',');
|
|
143
|
-
} else {
|
|
144
|
-
let parsedJson;
|
|
145
|
-
try {
|
|
146
|
-
// value is JSON, parse it
|
|
147
|
-
parsedJson = JSON.parse(query[item]);
|
|
148
|
-
} catch (e) {
|
|
149
|
-
// value is not JSON, pass through as a string
|
|
150
|
-
parsedJson = query[item];
|
|
151
|
-
}
|
|
152
|
-
acc[itemName][val.filterType] = parsedJson;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
if (val.type === _sequelize2.default.BOOLEAN) {
|
|
156
|
-
const queryValue = _lodash2.default.get(query, item, '').toLowerCase();
|
|
157
|
-
|
|
158
|
-
const booleanMap = {
|
|
159
|
-
'false': false,
|
|
160
|
-
'null': null,
|
|
161
|
-
'true': true
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
acc[itemName][val.filterType] = booleanMap[queryValue];
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
return acc;
|
|
169
|
-
}, {});
|
|
170
|
-
|
|
171
|
-
if (objectFilters?.active && !where?.active) {
|
|
172
|
-
where.active = true;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
const businessIds = (0, _accessRightsUtils.accessRightsUtils)(event);
|
|
176
|
-
const filterAdds = {
|
|
177
|
-
businessId: businessIds
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
if (startDate && endDate) {
|
|
181
|
-
const s = _moment2.default.utc(startDate);
|
|
182
|
-
const e = _moment2.default.utc(endDate);
|
|
183
|
-
const dates = {
|
|
184
|
-
[_sequelize2.default.Op.between]: [s.toDate(), e.toDate()]
|
|
185
|
-
};
|
|
186
|
-
if (!s.isValid()) {
|
|
187
|
-
throw { ..._errorCodes.errorList.invalidStartDate };
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
if (!e.isValid()) {
|
|
191
|
-
throw { ..._errorCodes.errorList.invalidEndDate };
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
filterAdds.createdAt = dates;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
if (searchString) {
|
|
198
|
-
const adds = Object.keys(objectFilters).reduce((acc, item) => {
|
|
199
|
-
const type = objectFilters[item].filterType;
|
|
200
|
-
const dataType = objectFilters[item].type;
|
|
201
|
-
|
|
202
|
-
if (type === _sequelize2.default.Op.iLike) {
|
|
203
|
-
const newOr = {};
|
|
204
|
-
const itemName = item.includes('.') ?
|
|
205
|
-
`$${item}$` :
|
|
206
|
-
item;
|
|
207
|
-
newOr[itemName] = {
|
|
208
|
-
[_sequelize2.default.Op.iLike]: `%${query['searchString']}%`
|
|
209
|
-
};
|
|
210
|
-
acc.push(newOr);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
if (!_lodash2.default.isNaN(Number(query['searchString'])) && !(dataType instanceof _sequelize2.default.BOOLEAN)) {
|
|
214
|
-
|
|
215
|
-
if (type === _sequelize2.default.Op.eq) {
|
|
216
|
-
const newOr = {};
|
|
217
|
-
const itemName = item.includes('.') ? `$${item}$` : item;
|
|
218
|
-
newOr[itemName] = {
|
|
219
|
-
[_sequelize2.default.Op.eq]: `${query['searchString']}`
|
|
220
|
-
};
|
|
221
|
-
acc.push(newOr);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
return acc;
|
|
226
|
-
}, []);
|
|
227
|
-
|
|
228
|
-
filterAdds[_sequelize2.default.Op.or] = adds;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
const withDate = Object.assign(where, filterAdds);
|
|
232
|
-
|
|
233
|
-
return withDate;
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
/***/ }),
|
|
237
|
-
|
|
238
|
-
/***/ "./src/database/dbUtils/queryStringUtils/createIncludes.js":
|
|
239
|
-
/*!*****************************************************************!*\
|
|
240
|
-
!*** ./src/database/dbUtils/queryStringUtils/createIncludes.js ***!
|
|
241
|
-
\*****************************************************************/
|
|
242
|
-
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
243
|
-
|
|
244
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));exports.createIncludes = createIncludes;exports.includeSubItem = includeSubItem;var _lodash = __webpack_require__(/*! lodash */ "lodash");var _lodash2 = _interopRequireDefault(_lodash);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };} /**
|
|
84
|
+
exports.createFilters=function(event,objectFilters){let query=_lodash2.default.get(event,"queryStringParameters",{})||{};const searchString=_lodash2.default.get(query,"searchString"),startDate=_lodash2.default.get(query,"startDate"),endDate=_lodash2.default.get(query,"endDate"),where=Object.keys(query).reduce(((acc,item)=>{const val=_lodash2.default.get(objectFilters,item,null);if(val){const itemName=item.includes(".")?`$${item}$`:item;if(acc[itemName]={},val.filterType===_sequelize2.default.Op.iLike)acc[itemName][val.filterType]=`%${query[item]}%`;else if(val.filterType===_sequelize2.default.Op.or)acc[itemName][val.filterType]=[-1*+query[item],+query[item]];else if(val.filterType===_sequelize2.default.Op.in)acc[itemName][val.filterType]=query[item].split(",");else if(val.filterType===_sequelize2.default.Op.in)acc[itemName][val.filterType]=query[item].split(",");else{let parsedJson;try{
|
|
85
|
+
// value is JSON, parse it
|
|
86
|
+
parsedJson=JSON.parse(query[item])}catch(e){
|
|
87
|
+
// value is not JSON, pass through as a string
|
|
88
|
+
parsedJson=query[item]}acc[itemName][val.filterType]=parsedJson}if(val.type===_sequelize2.default.BOOLEAN){const queryValue=_lodash2.default.get(query,item,"").toLowerCase(),booleanMap={false:!1,null:null,true:!0};acc[itemName][val.filterType]=booleanMap[queryValue]}}return acc}),{});objectFilters?.active&&!where?.active&&(where.active=!0);const filterAdds={businessId:(0,_accessRightsUtils.accessRightsUtils)(event)};if(startDate&&endDate){const s=_dayjs2.default.utc(startDate),e=_dayjs2.default.utc(endDate),dates={[_sequelize2.default.Op.between]:[s.toDate(),e.toDate()]};if(!s.isValid())throw{..._errorCodes.errorList.invalidStartDate};if(!e.isValid())throw{..._errorCodes.errorList.invalidEndDate};filterAdds.createdAt=dates}if(searchString){const adds=Object.keys(objectFilters).reduce(((acc,item)=>{const type=objectFilters[item].filterType,dataType=objectFilters[item].type;if(type===_sequelize2.default.Op.iLike){const newOr={};newOr[item.includes(".")?`$${item}$`:item]={[_sequelize2.default.Op.iLike]:`%${query.searchString}%`},acc.push(newOr)}if(!(_lodash2.default.isNaN(Number(query.searchString))||dataType instanceof _sequelize2.default.BOOLEAN)&&type===_sequelize2.default.Op.eq){const newOr={};newOr[item.includes(".")?`$${item}$`:item]={[_sequelize2.default.Op.eq]:`${query.searchString}`},acc.push(newOr)}return acc}),[]);filterAdds[_sequelize2.default.Op.or]=adds}return Object.assign(where,filterAdds)};
|
|
89
|
+
/***/},
|
|
90
|
+
/***/982:
|
|
91
|
+
/***/(__unused_webpack_module,exports,__webpack_require__)=>{Object.defineProperty(exports,"__esModule",{value:!0}),exports.createIncludes=
|
|
92
|
+
/**
|
|
245
93
|
* Create sequelize includes array from query string parameters and default sequelize model
|
|
246
94
|
*
|
|
247
95
|
* @param {object} event - the query parameters from the event passed by lambda
|
|
248
96
|
* @param {object} objectFilters - the default filters object created by createDefaultFilters
|
|
249
97
|
* @returns {object} A sequelize includes array
|
|
250
|
-
*/
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
/***/
|
|
254
|
-
|
|
255
|
-
/***/ "./src/database/dbUtils/queryStringUtils/createSort.js":
|
|
256
|
-
/*!*************************************************************!*\
|
|
257
|
-
!*** ./src/database/dbUtils/queryStringUtils/createSort.js ***!
|
|
258
|
-
\*************************************************************/
|
|
259
|
-
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
260
|
-
|
|
261
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));exports.createSort = undefined;var _lodash = __webpack_require__(/*! lodash */ "lodash");var _lodash2 = _interopRequireDefault(_lodash);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}
|
|
262
|
-
|
|
98
|
+
*/
|
|
99
|
+
function createIncludes(event,objectFilters){const query=_lodash2.default.get(event,"queryStringParameters",{})||{},canBeIncluded=Object.keys(objectFilters).reduce(((acc,item)=>acc=includeSubItem(item,acc)),[]),askedForInQuery=Object.keys(query).reduce(((acc,item)=>("sort"===item&&query[item].split(",").forEach((sortItem=>{sortItem=0===sortItem.indexOf("-")?sortItem.substr(1):sortItem,acc=includeSubItem(sortItem,acc)})),acc=includeSubItem(item,acc))),[]);return _lodash2.default.intersection(canBeIncluded,askedForInQuery)},exports.includeSubItem=includeSubItem;var _lodash2=function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}(__webpack_require__(825));function includeSubItem(queryStringItem,acc=[]){const dot=queryStringItem.indexOf(".");return dot>0&&acc.push(queryStringItem.substring(0,dot)),acc}
|
|
100
|
+
/***/},
|
|
101
|
+
/***/835:
|
|
102
|
+
/***/(__unused_webpack_module,exports,__webpack_require__)=>{Object.defineProperty(exports,"__esModule",{value:!0}),exports.createSort=void 0;var _lodash2=function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}
|
|
263
103
|
/**
|
|
264
104
|
* Create sequelize order clause from query string parameters and default sort object
|
|
265
105
|
*
|
|
266
106
|
* @param {object} event - the event created AWS lambda, it will contain queryStringParameters with sort property a comma seperated list of sortable fields * @param {object} objectFilters - the default filters object created by createDefaultFilters
|
|
267
107
|
* @param {object} defaultFilter - A default filter object as built by createDefault Filters, if items are not on the schema they will not be in the order by
|
|
268
108
|
* @returns {object} An sequelize order by object
|
|
269
|
-
*/
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
return sort.split(',').reduce((acc, item) => {
|
|
276
|
-
|
|
277
|
-
const testItem = item.indexOf('-') === 0 ? item.substr(1) : item;
|
|
278
|
-
|
|
279
|
-
if (_lodash2.default.get(copyOfDefaultFilter, testItem, null)) {
|
|
280
|
-
const sortItem = [];
|
|
281
|
-
|
|
282
|
-
testItem.split('.').forEach((parentChildList) => {
|
|
283
|
-
sortItem.push(parentChildList);
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
if (item.indexOf('-') === 0) {
|
|
287
|
-
sortItem.push('DESC');
|
|
288
|
-
} else {
|
|
289
|
-
sortItem.push('ASC');
|
|
290
|
-
}
|
|
291
|
-
acc.push(sortItem);
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
return acc;
|
|
295
|
-
}, []);
|
|
296
|
-
};
|
|
297
|
-
|
|
298
|
-
/***/ }),
|
|
299
|
-
|
|
300
|
-
/***/ "./src/database/dbUtils/queryStringUtils/defaultFilters.js":
|
|
301
|
-
/*!*****************************************************************!*\
|
|
302
|
-
!*** ./src/database/dbUtils/queryStringUtils/defaultFilters.js ***!
|
|
303
|
-
\*****************************************************************/
|
|
304
|
-
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
305
|
-
|
|
306
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));exports.defaultFilters = defaultFilters;exports.addFiltersFromSchema = addFiltersFromSchema;var _lodash = __webpack_require__(/*! lodash */ "lodash");var _lodash2 = _interopRequireDefault(_lodash);var _sequelize = __webpack_require__(/*! sequelize */ "sequelize");var _sequelize2 = _interopRequireDefault(_sequelize);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };} /**
|
|
109
|
+
*/(__webpack_require__(825));exports.createSort=function(event,defaultFilter){let copyOfDefaultFilter=_lodash2.default.clone(defaultFilter),query=_lodash2.default.get(event,"queryStringParameters",{})||{};return(_lodash2.default.get(query,"sort","-updatedAt")||"-updatedAt").split(",").reduce(((acc,item)=>{const testItem=0===item.indexOf("-")?item.substr(1):item;if(_lodash2.default.get(copyOfDefaultFilter,testItem,null)){const sortItem=[];testItem.split(".").forEach((parentChildList=>{sortItem.push(parentChildList)})),0===item.indexOf("-")?sortItem.push("DESC"):sortItem.push("ASC"),acc.push(sortItem)}return acc}),[])};
|
|
110
|
+
/***/},
|
|
111
|
+
/***/207:
|
|
112
|
+
/***/(__unused_webpack_module,exports,__webpack_require__)=>{Object.defineProperty(exports,"__esModule",{value:!0}),exports.defaultFilters=
|
|
113
|
+
/**
|
|
307
114
|
* Create an object with default filters for a given sequeliaze Schema Object, and set of sub schemas
|
|
308
115
|
*
|
|
309
116
|
* @param {object} schema - type is sequelize data type
|
|
310
117
|
* @param {object} subSchemas - An object with alias as the key and sequelize schema as the value http://docs.sequelizejs.com/class/lib/sequelize.js~Sequelize.html#instance-method-define
|
|
311
118
|
* sub schema can be {location: locationSchema} or {location: {as: "asAlias", schema: schema}}
|
|
312
119
|
* @returns {object} An Object with a default filter for each dataType CHAR and TEXT will get a $like operator, INTEGER, DECIMAL and BOOLEAN will get a $eq.
|
|
313
|
-
*/
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
const itemType = schema[item].type;
|
|
328
|
-
|
|
329
|
-
//todo these should be removed, there are just here for sort tests
|
|
330
|
-
switch (itemType) {
|
|
331
|
-
case _sequelize2.default.CHAR:
|
|
332
|
-
case _sequelize2.default.STRING:
|
|
333
|
-
case _sequelize2.default.TEXT:
|
|
334
|
-
acc[key] = { filterType: _sequelize2.default.Op.iLike };
|
|
335
|
-
break;
|
|
336
|
-
|
|
337
|
-
case _sequelize2.default.DECIMAL:
|
|
338
|
-
acc[key] = { filterType: _sequelize2.default.Op.or };
|
|
339
|
-
break;
|
|
340
|
-
|
|
341
|
-
case _sequelize2.default.BOOLEAN:
|
|
342
|
-
case _sequelize2.default.BIGINT:
|
|
343
|
-
case _sequelize2.default.INTEGER:
|
|
344
|
-
acc[key] = { type: itemType, filterType: _sequelize2.default.Op.eq };
|
|
345
|
-
break;
|
|
346
|
-
|
|
347
|
-
case _sequelize2.default.DATE:
|
|
348
|
-
case _sequelize2.default.DATEONLY:
|
|
349
|
-
acc[key] = { filterType: _sequelize2.default.Op.lt };
|
|
350
|
-
break;
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
//new sequelize uses classes instead of objects
|
|
354
|
-
if (itemType instanceof _sequelize2.default.STRING) {
|
|
355
|
-
acc[key] = { filterType: _sequelize2.default.Op.iLike };
|
|
356
|
-
} else if (itemType instanceof _sequelize2.default.DECIMAL) {
|
|
357
|
-
acc[key] = { filterType: _sequelize2.default.Op.or };
|
|
358
|
-
} else if (itemType instanceof _sequelize2.default.INTEGER) {
|
|
359
|
-
acc[key] = { filterType: _sequelize2.default.Op.or };
|
|
360
|
-
} else if (itemType instanceof _sequelize2.default.BIGINT) {
|
|
361
|
-
acc[key] = { filterType: _sequelize2.default.Op.or };
|
|
362
|
-
} else if (itemType instanceof _sequelize2.default.BOOLEAN) {
|
|
363
|
-
acc[key] = { type: itemType, filterType: _sequelize2.default.Op.eq };
|
|
364
|
-
} else if (itemType instanceof _sequelize2.default.JSONB) {
|
|
365
|
-
acc[key] = { type: itemType, filterType: _sequelize2.default.Op.contains };
|
|
366
|
-
} else if (itemType instanceof _sequelize2.default.DATEONLY) {
|
|
367
|
-
acc[key] = { type: itemType, filterType: _sequelize2.default.Op.eq };
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
//these are not part of the models so add them always
|
|
371
|
-
acc['createdAt'] = { type: _sequelize2.default.DATE, filterType: _sequelize2.default.Op.lt };
|
|
372
|
-
acc['updatedAt'] = { type: _sequelize2.default.DATE, filterType: _sequelize2.default.Op.lt };
|
|
373
|
-
acc['id'] = { type: _sequelize2.default.INTEGER, filterType: _sequelize2.default.Op.eq };
|
|
374
|
-
|
|
375
|
-
return acc;
|
|
376
|
-
}, accumulator);
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
/***/ }),
|
|
380
|
-
|
|
381
|
-
/***/ "./src/database/dbUtils/queryStringUtils/findAll.js":
|
|
382
|
-
/*!**********************************************************!*\
|
|
383
|
-
!*** ./src/database/dbUtils/queryStringUtils/findAll.js ***!
|
|
384
|
-
\**********************************************************/
|
|
385
|
-
/***/ ((__unused_webpack_module, exports) => {
|
|
386
|
-
|
|
387
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));exports.getPaginationFromFindAll = getPaginationFromFindAll;exports.findAll = findAll; /**
|
|
120
|
+
*/
|
|
121
|
+
function defaultFilters(schema,subSchemas={}){schema=_lodash2.default.clone(schema);const filters={};return addFiltersFromSchema(schema,filters),Object.keys(subSchemas).forEach((key=>{addFiltersFromSchema(subSchemas[key],filters,key)})),filters},exports.addFiltersFromSchema=addFiltersFromSchema;var _lodash2=_interopRequireDefault(__webpack_require__(825)),_sequelize2=_interopRequireDefault(__webpack_require__(31));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function addFiltersFromSchema(schema,accumulator,keyPrefix=""){const asLinkAlias=_lodash2.default.get(schema,"as",null);return schema=_lodash2.default.get(schema,"schema")||schema,Object.keys(schema).reduce(((acc,item)=>{let key=item;if(asLinkAlias&&(acc[asLinkAlias]={type:_sequelize2.default.STRING,filterType:_sequelize2.default.Op.eq}),keyPrefix&&(key=`${keyPrefix}.${item}`),schema[item].filterType)return acc[key]={filterType:schema[item].filterType},acc;const itemType=schema[item].type;
|
|
122
|
+
//todo these should be removed, there are just here for sort tests
|
|
123
|
+
switch(itemType){case _sequelize2.default.CHAR:case _sequelize2.default.STRING:case _sequelize2.default.TEXT:acc[key]={filterType:_sequelize2.default.Op.iLike};break;case _sequelize2.default.DECIMAL:acc[key]={filterType:_sequelize2.default.Op.or};break;case _sequelize2.default.BOOLEAN:case _sequelize2.default.BIGINT:case _sequelize2.default.INTEGER:acc[key]={type:itemType,filterType:_sequelize2.default.Op.eq};break;case _sequelize2.default.DATE:case _sequelize2.default.DATEONLY:acc[key]={filterType:_sequelize2.default.Op.lt}}
|
|
124
|
+
//new sequelize uses classes instead of objects
|
|
125
|
+
return itemType instanceof _sequelize2.default.STRING?acc[key]={filterType:_sequelize2.default.Op.iLike}:itemType instanceof _sequelize2.default.DECIMAL||itemType instanceof _sequelize2.default.INTEGER||itemType instanceof _sequelize2.default.BIGINT?acc[key]={filterType:_sequelize2.default.Op.or}:itemType instanceof _sequelize2.default.BOOLEAN?acc[key]={type:itemType,filterType:_sequelize2.default.Op.eq}:itemType instanceof _sequelize2.default.JSONB?acc[key]={type:itemType,filterType:_sequelize2.default.Op.contains}:itemType instanceof _sequelize2.default.DATEONLY&&(acc[key]={type:itemType,filterType:_sequelize2.default.Op.eq}),
|
|
126
|
+
//these are not part of the models so add them always
|
|
127
|
+
acc.createdAt={type:_sequelize2.default.DATE,filterType:_sequelize2.default.Op.lt},acc.updatedAt={type:_sequelize2.default.DATE,filterType:_sequelize2.default.Op.lt},acc.id={type:_sequelize2.default.INTEGER,filterType:_sequelize2.default.Op.eq},acc}),accumulator)}
|
|
128
|
+
/***/},
|
|
129
|
+
/***/981:
|
|
130
|
+
/***/(__unused_webpack_module,exports)=>{
|
|
131
|
+
/**
|
|
388
132
|
* create pagination object from Sequelize findAll
|
|
389
133
|
* @param {object} result - sequelize result
|
|
390
134
|
* @param {number} limit - max number of results to return
|
|
391
135
|
* @param {number} offset - page offset
|
|
392
|
-
*/
|
|
136
|
+
*/
|
|
137
|
+
function getPaginationFromFindAll(result,limit,offset){limit=limit||0,offset=offset||0;const hasMore=(result=result||[]).length>limit;hasMore&&result.splice(-1,1);return{offset,limit,rows:result,hasMore}}
|
|
138
|
+
/**
|
|
393
139
|
* wrapper for Sequelize findAll
|
|
394
140
|
* @param {object} model - instance of Sequelize (must be initialized)
|
|
395
141
|
* @param {*&{include: [{model: *}], where: {businessId: Array}, order: [string[]]}} options - instance of Sequelize (must be initialized)
|
|
396
|
-
*/async function findAll(model,
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
/***/ }),
|
|
402
|
-
|
|
403
|
-
/***/ "./src/dynamo/dynamoUtils.js":
|
|
404
|
-
/*!***********************************!*\
|
|
405
|
-
!*** ./src/dynamo/dynamoUtils.js ***!
|
|
406
|
-
\***********************************/
|
|
407
|
-
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
408
|
-
|
|
409
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));var _libDynamodb = __webpack_require__(/*! @aws-sdk/lib-dynamodb */ "@aws-sdk/lib-dynamodb");
|
|
410
|
-
var _clientDynamodb = __webpack_require__(/*! @aws-sdk/client-dynamodb */ "@aws-sdk/client-dynamodb");
|
|
411
|
-
|
|
412
|
-
const dynamoUtil = {
|
|
413
|
-
get: (params) => get(params)
|
|
414
|
-
};
|
|
415
|
-
|
|
416
|
-
/**
|
|
417
|
-
* @param {{TableName:string, Key:{key:string}}} params
|
|
142
|
+
*/async function findAll(model,options){const limit=options.limit||0,includes=options.includes||{all:!0,nested:!0},findArgs=Object.assign({include:includes},options,{limit:limit+1});return getPaginationFromFindAll(await model.findAll(findArgs),limit,options.offset)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.getPaginationFromFindAll=getPaginationFromFindAll,exports.findAll=findAll;const findUtils={findAll};exports.default=findUtils},
|
|
143
|
+
/***/64:
|
|
144
|
+
/***/(__unused_webpack_module,exports,__webpack_require__)=>{Object.defineProperty(exports,"__esModule",{value:!0});var _libDynamodb=__webpack_require__(515),_clientDynamodb=__webpack_require__(929);const dynamoUtil={get:params=>
|
|
145
|
+
/**
|
|
146
|
+
* @param {{TableName:string, Key:{key:string}}} params
|
|
418
147
|
*/
|
|
419
|
-
async function get(params)
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));exports.handleEvents = handleEvents;exports.handleDirectS3WriteEvent = handleDirectS3WriteEvent;var _handleFile = __webpack_require__(/*! ./handleFile.js */ "./src/eventManager/handleFile.js");var _lodash = __webpack_require__(/*! lodash */ "lodash");var _lodash2 = _interopRequireDefault(_lodash);var _bluebird = __webpack_require__(/*! bluebird */ "bluebird");var _bluebird2 = _interopRequireDefault(_bluebird);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}function handleEvents(event, transformer, errorHandlerPerFile, shouldSkipFailedFolders = false, userImportTypes) {if (!event || !event.Records) {return _bluebird2.default.resolve();}let hasErrors = false;return _bluebird2.default.map(event.Records, (record) => {const snsInfo = JSON.parse(_lodash2.default.get(record, 'Sns.Message', '{}'));const s3Bucket = snsInfo.bucket;const files = snsInfo.files || [];return _bluebird2.default.map(files, (file) => {let path = decodeURIComponent(file);if (path) {return (0, _handleFile.handleFile)(path, s3Bucket, transformer, { shouldSkipFailedFolders, userImportTypes }).catch((err) => {if (errorHandlerPerFile && !errorHandlerPerFile(err, path)) {console.error('HANDLE-FILE-CATCH: ', err);hasErrors = true;}});}});}).then(() => {if (hasErrors) {throw 'ERROR: HANDLE-FILE';}});}function handleDirectS3WriteEvent(event, transformer, errorHandlerPerFile, shouldSkipFailedFolders = false, userImportTypes) {
|
|
435
|
-
if (!event || !event.Records) {
|
|
436
|
-
return _bluebird2.default.resolve();
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
let hasErrors = false;
|
|
440
|
-
|
|
441
|
-
return _bluebird2.default.map(event.Records, (record) => {
|
|
442
|
-
const s3Bucket = record.s3.bucket.name;
|
|
443
|
-
const file = record.s3.object.key || [];
|
|
444
|
-
|
|
445
|
-
let path = decodeURIComponent(file);
|
|
446
|
-
if (path) {
|
|
447
|
-
return (0, _handleFile.handleFile)(path, s3Bucket, transformer, { shouldSkipFailedFolders, userImportTypes }).catch((err) => {
|
|
448
|
-
if (errorHandlerPerFile && !errorHandlerPerFile(err, path)) {
|
|
449
|
-
console.error('HANDLE-FILE-CATCH:', err);
|
|
450
|
-
hasErrors = true;
|
|
451
|
-
}
|
|
452
|
-
});
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
}).then(() => {
|
|
456
|
-
if (hasErrors) {
|
|
457
|
-
throw 'ERROR: HANDLE-FILE (DIRECT S3 EVENT)';
|
|
458
|
-
}
|
|
459
|
-
});
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
/***/ }),
|
|
463
|
-
|
|
464
|
-
/***/ "./src/eventManager/handleFile.js":
|
|
465
|
-
/*!****************************************!*\
|
|
466
|
-
!*** ./src/eventManager/handleFile.js ***!
|
|
467
|
-
\****************************************/
|
|
468
|
-
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
469
|
-
|
|
470
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));exports.handleFile = handleFile;exports.containsErrorTwice = containsErrorTwice;var _lodash = __webpack_require__(/*! lodash */ "lodash");var _lodash2 = _interopRequireDefault(_lodash);var _S3Utils = __webpack_require__(/*! ../s3/S3Utils.js/S3Utils.js */ "./src/s3/S3Utils.js/S3Utils.js");var _S3Utils2 = _interopRequireDefault(_S3Utils);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}async function handleFile(path, s3Bucket, transformer, options) {const shouldSkipFailedFolders = _lodash2.default.get(options, 'shouldSkipFailedFolders');const userImportTypes = _lodash2.default.get(options, 'userImportTypes');const params = { Bucket: s3Bucket, Key: path };let body = '{}';try {const s3r = await _S3Utils2.default.getObject(params);body = s3r;const parsedBody = JSON.parse(body);console.log('------->parsedBody-if this is empty body we need to skip transform?', parsedBody);const returnedValue = await transformer(parsedBody);await _S3Utils2.default.deleteObject(params);return returnedValue;} catch (error) {console.error('HANDLE-FILE-ERROR', error);if (error.code === 'NoSuchKey' || !body) {return;}let newPath = '';if (userImportTypes) {console.log('USER IMPORT'); // look for items in the userImportTypes
|
|
471
|
-
const usersImports = Object.values(userImportTypes);const items = path.split('/');const fileName = _lodash2.default.last(items);const folderName = _lodash2.default.first(items);if (usersImports.indexOf(folderName) > -1) {if (shouldSkipFailedFolders) {newPath = `${folderName}/error/${fileName}`;} else if (_lodash2.default.startsWith(path, `${folderName}/failed-once/`)) {newPath = _lodash2.default.replace(path, `${folderName}/failed-once/`, `${folderName}/failed-twice/`);} else if (_lodash2.default.startsWith(path, `${folderName}/failed-twice/`)) {newPath = _lodash2.default.replace(path, `${folderName}/failed-twice/`, `${folderName}/error/`);} else {newPath = `${folderName}/failed-once/${fileName}`;}} else {newPath = `pathAndEventMisMatchError/${path}`;}} else {if (shouldSkipFailedFolders) {newPath = `error/${path}`;} else if (_lodash2.default.startsWith(path, 'failed-once/')) {newPath = _lodash2.default.replace(path, 'failed-once/', 'failed-twice/');} else if (_lodash2.default.startsWith(path, 'failed-twice/')) {newPath = _lodash2.default.replace(path, 'failed-twice/', 'error/');} else {if (_lodash2.default.includes(path, 'delayUntil/')) {path = _lodash2.default.last(path.split('/'));}newPath = `failed-once/${path}`;}}const newParams = { Bucket: s3Bucket, Key: newPath, Body: body };if (containsErrorTwice(newPath, 'failed-once') || containsErrorTwice(newPath, 'failed-twice') || containsErrorTwice(newPath, 'error')) {throw 'NESTING ERROR';}await _S3Utils2.default.putObject(newParams);await _S3Utils2.default.deleteObject(params);throw error;}}function containsErrorTwice(str, val) {const firstIndex = str.toLowerCase().indexOf(val);
|
|
472
|
-
if (firstIndex === -1) return false;
|
|
473
|
-
const secondIndex = str.toLowerCase().indexOf(val, firstIndex + 1);
|
|
474
|
-
return secondIndex !== -1;
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
/***/ }),
|
|
478
|
-
|
|
479
|
-
/***/ "./src/eventManager/publishEvents.js":
|
|
480
|
-
/*!*******************************************!*\
|
|
481
|
-
!*** ./src/eventManager/publishEvents.js ***!
|
|
482
|
-
\*******************************************/
|
|
483
|
-
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
484
|
-
|
|
485
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));exports.loop = loop;exports.publishEvents = publishEvents;var _lodash = __webpack_require__(/*! lodash */ "lodash");var _lodash2 = _interopRequireDefault(_lodash);var _moment = __webpack_require__(/*! moment */ "moment");var _moment2 = _interopRequireDefault(_moment);var _bluebird = __webpack_require__(/*! bluebird */ "bluebird");var _bluebird2 = _interopRequireDefault(_bluebird);var _S3Utils = __webpack_require__(/*! ../s3/S3Utils.js/S3Utils.js */ "./src/s3/S3Utils.js/S3Utils.js");var _S3Utils2 = _interopRequireDefault(_S3Utils);var _SNSUtils = __webpack_require__(/*! ../sns/SNSUtils.js */ "./src/sns/SNSUtils.js");var _SNSUtils2 = _interopRequireDefault(_SNSUtils);var _dynamoUtils = __webpack_require__(/*! ../dynamo/dynamoUtils.js */ "./src/dynamo/dynamoUtils.js");var _dynamoUtils2 = _interopRequireDefault(_dynamoUtils);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };} /**
|
|
486
|
-
* @param {string} bucket
|
|
487
|
-
* @param {number} maxKeys
|
|
488
|
-
* @param {Object} userImportTypes
|
|
489
|
-
*/async function loop(bucket, maxKeys, userImportTypes) {let bucketResult = {};let fileList = [];const currentTime = (0, _moment2.default)();do {bucketResult = await _S3Utils2.default.listObjectsV2({ Bucket: bucket, MaxKeys: maxKeys, ContinuationToken: _lodash2.default.get(bucketResult, 'NextContinuationToken') });let newFiles = _lodash2.default.filter(bucketResult.Contents, (file) => {if (_lodash2.default.startsWith(_lodash2.default.get(file, 'Key'), 'delayUntil/')) {const fileDelayTime = _lodash2.default.get(file, 'Key').split('/')[1];return (0, _moment2.default)(fileDelayTime, 'YYYYMMDDHHmm').isSameOrBefore(currentTime);}if (userImportTypes) {// look for items in the userImportTypes
|
|
490
|
-
const usersImports = Object.values(userImportTypes);const items = file.Key.split('/');const fileName = _lodash2.default.last(items);const folderName = _lodash2.default.first(items);if (_lodash2.default.isEmpty(fileName)) {return false;} else if (usersImports.indexOf(folderName) === -1) {return false;}return !_lodash2.default.startsWith(file.Key, `${folderName}/error`);}return !_lodash2.default.startsWith(file.Key, 'error');});fileList = _lodash2.default.concat(fileList, newFiles);} while (bucketResult.IsTruncated && bucketResult.NextContinuationToken && fileList.length < maxKeys);return fileList;} /**
|
|
148
|
+
async function get(params){return _libDynamodb.DynamoDBDocument.from(new _clientDynamodb.DynamoDB).get(params)}(params)};exports.default=dynamoUtil},
|
|
149
|
+
/***/95:
|
|
150
|
+
/***/(__unused_webpack_module,exports,__webpack_require__)=>{Object.defineProperty(exports,"__esModule",{value:!0}),exports.handleEvents=function handleEvents(event,transformer,errorHandlerPerFile,shouldSkipFailedFolders=!1,userImportTypes){if(!event||!event.Records)return _bluebird2.default.resolve();let hasErrors=!1;return _bluebird2.default.map(event.Records,(record=>{const snsInfo=JSON.parse(_lodash2.default.get(record,"Sns.Message","{}")),s3Bucket=snsInfo.bucket,files=snsInfo.files||[];return _bluebird2.default.map(files,(file=>{let path=decodeURIComponent(file);if(path)return(0,_handleFile.handleFile)(path,s3Bucket,transformer,{shouldSkipFailedFolders,userImportTypes}).catch((err=>{errorHandlerPerFile&&!errorHandlerPerFile(err,path)&&(console.error("HANDLE-FILE-CATCH: ",err),hasErrors=!0)}))}))})).then((()=>{if(hasErrors)throw"ERROR: HANDLE-FILE"}))},exports.handleDirectS3WriteEvent=function handleDirectS3WriteEvent(event,transformer,errorHandlerPerFile,shouldSkipFailedFolders=!1,userImportTypes){if(!event||!event.Records)return _bluebird2.default.resolve();let hasErrors=!1;return _bluebird2.default.map(event.Records,(record=>{const s3Bucket=record.s3.bucket.name,file=record.s3.object.key||[];let path=decodeURIComponent(file);if(path)return(0,_handleFile.handleFile)(path,s3Bucket,transformer,{shouldSkipFailedFolders,userImportTypes}).catch((err=>{errorHandlerPerFile&&!errorHandlerPerFile(err,path)&&(console.error("HANDLE-FILE-CATCH:",err),hasErrors=!0)}))})).then((()=>{if(hasErrors)throw"ERROR: HANDLE-FILE (DIRECT S3 EVENT)"}))}
|
|
151
|
+
/***/;var _handleFile=__webpack_require__(876),_lodash2=_interopRequireDefault(__webpack_require__(825)),_bluebird2=_interopRequireDefault(__webpack_require__(564));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}},
|
|
152
|
+
/***/876:
|
|
153
|
+
/***/(__unused_webpack_module,exports,__webpack_require__)=>{Object.defineProperty(exports,"__esModule",{value:!0}),exports.handleFile=async function handleFile(path,s3Bucket,transformer,options){const shouldSkipFailedFolders=_lodash2.default.get(options,"shouldSkipFailedFolders"),userImportTypes=_lodash2.default.get(options,"userImportTypes"),params={Bucket:s3Bucket,Key:path};let body="{}";try{// exit early for null/undefined or blank string bodies
|
|
154
|
+
if(body=await _S3Utils2.default.getObject(params),_lodash2.default.isNil(body)||_lodash2.default.isString(body)&&_lodash2.default.isEmpty(body.trim()))return void await _S3Utils2.default.deleteObject(params);const parsedBody=JSON.parse(body);// exit early for objects like {} or []
|
|
155
|
+
if(_lodash2.default.isEmpty(parsedBody))return void await _S3Utils2.default.deleteObject(params);const returnedValue=await transformer(parsedBody);return await _S3Utils2.default.deleteObject(params),returnedValue}catch(error){// silently ignore missing-object errors
|
|
156
|
+
if("NoSuchKey"===error.code)return;if(console.error("HANDLE-FILE-ERROR",error),!body)return;let newPath="";if(userImportTypes){console.log("USER IMPORT");// look for items in the userImportTypes
|
|
157
|
+
const usersImports=Object.values(userImportTypes),items=path.split("/"),fileName=_lodash2.default.last(items),folderName=_lodash2.default.first(items);newPath=usersImports.indexOf(folderName)>-1?shouldSkipFailedFolders?`${folderName}/error/${fileName}`:_lodash2.default.startsWith(path,`${folderName}/failed-once/`)?_lodash2.default.replace(path,`${folderName}/failed-once/`,`${folderName}/failed-twice/`):_lodash2.default.startsWith(path,`${folderName}/failed-twice/`)?_lodash2.default.replace(path,`${folderName}/failed-twice/`,`${folderName}/error/`):`${folderName}/failed-once/${fileName}`:`pathAndEventMisMatchError/${path}`}else shouldSkipFailedFolders?newPath=`error/${path}`:_lodash2.default.startsWith(path,"failed-once/")?newPath=_lodash2.default.replace(path,"failed-once/","failed-twice/"):_lodash2.default.startsWith(path,"failed-twice/")?newPath=_lodash2.default.replace(path,"failed-twice/","error/"):(_lodash2.default.includes(path,"delayUntil/")&&(path=_lodash2.default.last(path.split("/"))),newPath=`failed-once/${path}`);const newParams={Bucket:s3Bucket,Key:newPath,Body:body};if(containsErrorTwice(newPath,"failed-once")||containsErrorTwice(newPath,"failed-twice")||containsErrorTwice(newPath,"error"))throw"NESTING ERROR";throw await _S3Utils2.default.putObject(newParams),await _S3Utils2.default.deleteObject(params),error}},exports.containsErrorTwice=containsErrorTwice;var _lodash2=_interopRequireDefault(__webpack_require__(825)),_S3Utils2=_interopRequireDefault(__webpack_require__(591));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function containsErrorTwice(str,val){const firstIndex=str.toLowerCase().indexOf(val);if(-1===firstIndex)return!1;return-1!==str.toLowerCase().indexOf(val,firstIndex+1)}
|
|
158
|
+
/***/},
|
|
159
|
+
/***/864:
|
|
160
|
+
/***/(__unused_webpack_module,exports,__webpack_require__)=>{Object.defineProperty(exports,"__esModule",{value:!0}),exports.loop=loop,exports.publishEvents=
|
|
161
|
+
/**
|
|
491
162
|
* Published SNS events at a steady pace for data in a particular bucket. Should be executed via a cloud watch cron job as a part of a micro service
|
|
492
163
|
*
|
|
493
164
|
* @param {string} configTable - The Dynamo DB table where to get the chunk-size and maxMessage size
|
|
@@ -495,39 +166,19 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));exports.loop = l
|
|
|
495
166
|
* @param {string} bucket - The name of the s3 bucket to watch, when you drop items into this table events will be created
|
|
496
167
|
* @param {string} snsTopic - The name of the snsEvent to publish
|
|
497
168
|
* @param {object} userImportTypes - import types to filter on
|
|
498
|
-
*/
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
return _bluebird2.default.map(messageList, (files) => {
|
|
512
|
-
return _SNSUtils2.default.publish({
|
|
513
|
-
Message: JSON.stringify({
|
|
514
|
-
bucket: bucket,
|
|
515
|
-
files: files
|
|
516
|
-
}),
|
|
517
|
-
TopicArn: topicArn
|
|
518
|
-
});
|
|
519
|
-
});
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
/***/ }),
|
|
523
|
-
|
|
524
|
-
/***/ "./src/eventManager/watchBucket.js":
|
|
525
|
-
/*!*****************************************!*\
|
|
526
|
-
!*** ./src/eventManager/watchBucket.js ***!
|
|
527
|
-
\*****************************************/
|
|
528
|
-
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
529
|
-
|
|
530
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));exports.watchBucket = watchBucket;var _publishEvents = __webpack_require__(/*! ./publishEvents.js */ "./src/eventManager/publishEvents.js");var _handleEvents = __webpack_require__(/*! ./handleEvents.js */ "./src/eventManager/handleEvents.js");var _lodash = __webpack_require__(/*! lodash */ "lodash");var _lodash2 = _interopRequireDefault(_lodash);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };} /**
|
|
169
|
+
*/
|
|
170
|
+
async function publishEvents(configTable,tableKey,bucket,snsTopic,userImportTypes){let result;try{result=await _dynamoUtils2.default.get({TableName:configTable,Key:{key:tableKey}})}catch(e){console.error(`Cannot get config for key: ${tableKey} table: ${configTable} falling back to defaults of 2 and 10`,e)}let chunkSize=_lodash2.default.get(result,"Item.snsChunkSize",2),maxMessages=_lodash2.default.get(result,"Item.snsMaxMessages",10);const topicArn=(await _SNSUtils2.default.createTopic({Name:snsTopic})).TopicArn,maxKeys=chunkSize*maxMessages,fileList=await loop(bucket,maxKeys,userImportTypes),messageList=_lodash2.default.chain(fileList).map("Key").chunk(chunkSize).slice(0,maxMessages).value();return _bluebird2.default.map(messageList,(files=>_SNSUtils2.default.publish({Message:JSON.stringify({bucket,files}),TopicArn:topicArn})))}
|
|
171
|
+
/***/;var _lodash2=_interopRequireDefault(__webpack_require__(825)),_dayjs2=_interopRequireDefault(__webpack_require__(293)),_customParseFormat2=_interopRequireDefault(__webpack_require__(59)),_isSameOrBefore2=_interopRequireDefault(__webpack_require__(394)),_bluebird2=_interopRequireDefault(__webpack_require__(564)),_S3Utils2=_interopRequireDefault(__webpack_require__(591)),_SNSUtils2=_interopRequireDefault(__webpack_require__(306)),_dynamoUtils2=_interopRequireDefault(__webpack_require__(64));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}
|
|
172
|
+
/**
|
|
173
|
+
* @param {string} bucket
|
|
174
|
+
* @param {number} maxKeys
|
|
175
|
+
* @param {Object} userImportTypes
|
|
176
|
+
*/
|
|
177
|
+
async function loop(bucket,maxKeys,userImportTypes){let bucketResult={},fileList=[];const currentTime=(0,_dayjs2.default)();do{bucketResult=await _S3Utils2.default.listObjectsV2({Bucket:bucket,MaxKeys:maxKeys,ContinuationToken:_lodash2.default.get(bucketResult,"NextContinuationToken")});let newFiles=_lodash2.default.filter(bucketResult.Contents,(file=>{if(_lodash2.default.startsWith(_lodash2.default.get(file,"Key"),"delayUntil/")){const fileDelayTime=_lodash2.default.get(file,"Key").split("/")[1];return(0,_dayjs2.default)(fileDelayTime,"YYYYMMDDHHmm").isSameOrBefore(currentTime)}if(userImportTypes){// look for items in the userImportTypes
|
|
178
|
+
const usersImports=Object.values(userImportTypes),items=file.Key.split("/"),fileName=_lodash2.default.last(items),folderName=_lodash2.default.first(items);return!_lodash2.default.isEmpty(fileName)&&(-1!==usersImports.indexOf(folderName)&&!_lodash2.default.startsWith(file.Key,`${folderName}/error`))}return!_lodash2.default.startsWith(file.Key,"error")}));fileList=_lodash2.default.concat(fileList,newFiles)}while(bucketResult.IsTruncated&&bucketResult.NextContinuationToken&&fileList.length<maxKeys);return fileList}_dayjs2.default.extend(_customParseFormat2.default),_dayjs2.default.extend(_isSameOrBefore2.default)},
|
|
179
|
+
/***/183:
|
|
180
|
+
/***/(__unused_webpack_module,exports,__webpack_require__)=>{Object.defineProperty(exports,"__esModule",{value:!0}),exports.watchBucket=
|
|
181
|
+
/**
|
|
531
182
|
* bucket watcher watches a s3 bucket and publishes events to a sns topic, this allows you to process files in s3 with a some transformer function
|
|
532
183
|
* prefix objects with DIRECT to listen to direct s3 events
|
|
533
184
|
*
|
|
@@ -541,488 +192,159 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));exports.watchBuc
|
|
|
541
192
|
* @param {function} [params.errorHandlerPerFile] - the function to run on as a catch on each file
|
|
542
193
|
* @param {boolean} [params.shouldSkipFailedFolders] - whether to use the failed-once, failed-twice, error or just error folders
|
|
543
194
|
* @param {object} [params.userImportTypes] - user import subdirectories object map
|
|
544
|
-
*/
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
// this used to throw, but the throw raised useless alarms, I believed turing throw in to a return was ok
|
|
558
|
-
return;
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
if (startsWithDirect) {
|
|
562
|
-
console.log('------->DIRECT WRITE FIRE');
|
|
563
|
-
return (0, _handleEvents.handleDirectS3WriteEvent)(event, transformer, errorHandlerPerFile, shouldSkipFailedFolders, userImportTypes);
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
} else {
|
|
567
|
-
// the function is being run from the cron job so publish SNS events
|
|
568
|
-
return (0, _publishEvents.publishEvents)(dynamoConfigTable, dynamoConfigKey, s3Bucket, snsTopic, userImportTypes);
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
/***/ }),
|
|
573
|
-
|
|
574
|
-
/***/ "./src/requestResonse/errorCodes.js":
|
|
575
|
-
/*!******************************************!*\
|
|
576
|
-
!*** ./src/requestResonse/errorCodes.js ***!
|
|
577
|
-
\******************************************/
|
|
578
|
-
/***/ ((__unused_webpack_module, exports) => {
|
|
579
|
-
|
|
580
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));const errorList = exports.errorList = {
|
|
581
|
-
invalidInventoryReleaseRequest: {
|
|
582
|
-
message: 'NOT ENOUGH INVENTORY TO FULFILL RELEASE',
|
|
583
|
-
errorCode: '4010',
|
|
584
|
-
statusCode: 400
|
|
585
|
-
},
|
|
586
|
-
alreadyReleased: {
|
|
587
|
-
message: 'ALREADY RELEASED',
|
|
588
|
-
errorCode: '4011',
|
|
589
|
-
statusCode: 400
|
|
590
|
-
},
|
|
591
|
-
alreadyReceived: {
|
|
592
|
-
message: 'RECEIVABLE ALREADY RECEIVED',
|
|
593
|
-
errorCode: '4012',
|
|
594
|
-
statusCode: 400
|
|
595
|
-
},
|
|
596
|
-
invalidItemsRequest: {
|
|
597
|
-
message: 'VALID ITEMS MUST BE INCLUDED',
|
|
598
|
-
errorCode: '4013',
|
|
599
|
-
statusCode: 400
|
|
600
|
-
},
|
|
601
|
-
invalidID: {
|
|
602
|
-
message: 'ID is invalid',
|
|
603
|
-
errorCode: '4014',
|
|
604
|
-
statusCode: 400
|
|
605
|
-
},
|
|
606
|
-
invalidReceivable: {
|
|
607
|
-
message: 'MUST CONTAIN AT LEAST ONE RECEIVABLE',
|
|
608
|
-
errorCode: '4015',
|
|
609
|
-
statusCode: 400
|
|
610
|
-
},
|
|
611
|
-
invalidRequest: {
|
|
612
|
-
message: 'INVALID REQUEST DATA',
|
|
613
|
-
errorCode: '4016',
|
|
614
|
-
statusCode: 400
|
|
615
|
-
},
|
|
616
|
-
invalidAPIKey: {
|
|
617
|
-
message: 'INVALID REQUEST - API MAY KEY INVALID',
|
|
618
|
-
errorCode: '4017',
|
|
619
|
-
statusCode: 400
|
|
620
|
-
},
|
|
621
|
-
qbCreationError: {
|
|
622
|
-
message: 'QUICKBOOKS ERROR - ERROR CREATING OBJECT IN QUICKBOOKS',
|
|
623
|
-
errorCode: '4018',
|
|
624
|
-
statusCode: 400
|
|
625
|
-
},
|
|
626
|
-
cannotReopen: {
|
|
627
|
-
message: 'CANNOT REOPEN - THE ORDER HAS ALREADY BEEN OPENED',
|
|
628
|
-
errorCode: '4018',
|
|
629
|
-
statusCode: 400
|
|
630
|
-
},
|
|
631
|
-
invalidDateFormat: {
|
|
632
|
-
message: 'INVALID DATE FORMAT',
|
|
633
|
-
errorCode: '4019',
|
|
634
|
-
statusCode: 400
|
|
635
|
-
},
|
|
636
|
-
invalidStartDate: {
|
|
637
|
-
message: 'INVALID START DATE',
|
|
638
|
-
errorCode: '4020',
|
|
639
|
-
statusCode: 400
|
|
640
|
-
},
|
|
641
|
-
invalidEndDate: {
|
|
642
|
-
message: 'INVALID END DATE',
|
|
643
|
-
errorCode: '4021',
|
|
644
|
-
statusCode: 400
|
|
645
|
-
},
|
|
646
|
-
invalidOrderStatus: {
|
|
647
|
-
message: 'UNABLE TO EDIT ORDER ITEMS UNLESS THE ORDER IS IN ESTIMATE STATUS',
|
|
648
|
-
errorCode: '4022',
|
|
649
|
-
statusCode: 400
|
|
650
|
-
},
|
|
651
|
-
invalidPaymentStatus: {
|
|
652
|
-
message: 'UNABLE TO UPDATE PAYMENT STATUS PAYMENT MUST BE OPEN',
|
|
653
|
-
errorCode: '4023',
|
|
654
|
-
statusCode: 400
|
|
655
|
-
},
|
|
656
|
-
invalidReleaseStatus: {
|
|
657
|
-
message: 'UNABLE TO UPDATE RELEASE, STATUS RELEASE MUST BE OPEN',
|
|
658
|
-
errorCode: '4024',
|
|
659
|
-
statusCode: 400
|
|
660
|
-
},
|
|
661
|
-
invalidReceivableStatus: {
|
|
662
|
-
message: 'UNABLE TO UPDATE RECEIVABLE, STATUS RECEIVABLE MUST BE OPEN',
|
|
663
|
-
errorCode: '40025',
|
|
664
|
-
statusCode: 400
|
|
665
|
-
},
|
|
666
|
-
invalidJson: {
|
|
667
|
-
message: 'INVALID JSON',
|
|
668
|
-
errorCode: '4005',
|
|
669
|
-
statusCode: 400
|
|
670
|
-
},
|
|
671
|
-
invalidFilter: {
|
|
672
|
-
message: 'INVALID FILTER',
|
|
673
|
-
errorCode: '4026',
|
|
674
|
-
statusCode: 400
|
|
675
|
-
},
|
|
676
|
-
invalidUserNameUpdate: {
|
|
677
|
-
message: 'UNABLE TO UPDATE USERNAME',
|
|
678
|
-
errorCode: '4027',
|
|
679
|
-
statusCode: 400
|
|
680
|
-
},
|
|
681
|
-
imageSizeLimit: {
|
|
682
|
-
message: 'IMAGE SIZE LIMIT 100KB EXCEEDED',
|
|
683
|
-
errorCode: '4028',
|
|
684
|
-
statusCode: 400
|
|
685
|
-
},
|
|
686
|
-
unauthorized: {
|
|
687
|
-
message: 'UNAUTHORIZED',
|
|
688
|
-
errorCode: '4111',
|
|
689
|
-
statusCode: 401
|
|
690
|
-
},
|
|
691
|
-
notFound: {
|
|
692
|
-
message: 'ITEM NOT FOUND',
|
|
693
|
-
errorCode: '4004',
|
|
694
|
-
statusCode: 404
|
|
695
|
-
},
|
|
696
|
-
emailRequired: {
|
|
697
|
-
message: 'NO EMAIL PROVIDED, CHECK CUSTOMER EMAIL',
|
|
698
|
-
errorCode: '4004',
|
|
699
|
-
statusCode: 404
|
|
700
|
-
},
|
|
701
|
-
mobilePhoneRequired: {
|
|
702
|
-
message: 'NO MOBILE PHONE PROVIDED, CHECK CUSTOMER CONTACTS',
|
|
703
|
-
errorCode: '4004',
|
|
704
|
-
statusCode: 404
|
|
705
|
-
},
|
|
706
|
-
invalidCadenceType: {
|
|
707
|
-
message: 'INVALID CADENCE TYPE',
|
|
708
|
-
errorCode: '5001',
|
|
709
|
-
statusCode: 500
|
|
710
|
-
}
|
|
711
|
-
};
|
|
712
|
-
|
|
713
|
-
/***/ }),
|
|
714
|
-
|
|
715
|
-
/***/ "./src/requestResonse/requestResponse.js":
|
|
716
|
-
/*!***********************************************!*\
|
|
717
|
-
!*** ./src/requestResonse/requestResponse.js ***!
|
|
718
|
-
\***********************************************/
|
|
719
|
-
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
720
|
-
|
|
721
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));exports.success = success;exports.successHtml = successHtml;exports.getCurrentUserNameFromCognitoEvent = getCurrentUserNameFromCognitoEvent;exports.getCurrentUser = getCurrentUser;exports.failure = failure;exports.parseBody = parseBody;exports.parseEvent = parseEvent;exports.detectSequelizeError = detectSequelizeError;exports.detectJoyError = detectJoyError;exports.detectDynamooseError = detectDynamooseError;var _lodash = __webpack_require__(/*! lodash */ "lodash");var _lodash2 = _interopRequireDefault(_lodash);var _errorCodes = __webpack_require__(/*! ./errorCodes.js */ "./src/requestResonse/errorCodes.js");function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };} /**
|
|
195
|
+
*/
|
|
196
|
+
function watchBucket({event,dynamoConfigTable,dynamoConfigKey,s3Bucket,snsTopic,transformer,errorHandlerPerFile=_lodash2.default.noop,shouldSkipFailedFolders=!1,userImportTypes}){if(!(event&&dynamoConfigTable&&dynamoConfigKey&&s3Bucket&&snsTopic&&transformer))throw new Error("Missing required parameters. Need event, dynamoConfigTable, dynamoConfigKey, s3Bucket, snsTopic, transformer");const EventSource=_lodash2.default.get(event,"Records[0].eventSource")||_lodash2.default.get(event,"Records[0].EventSource");if(_lodash2.default.isEqual(EventSource,"aws:sns"))return(0,_handleEvents.handleEvents)(event,transformer,errorHandlerPerFile,shouldSkipFailedFolders,userImportTypes);if(!_lodash2.default.isEqual(EventSource,"aws:s3"))
|
|
197
|
+
// the function is being run from the cron job so publish SNS events
|
|
198
|
+
return(0,_publishEvents.publishEvents)(dynamoConfigTable,dynamoConfigKey,s3Bucket,snsTopic,userImportTypes);{const failedOnce="failed-once",failedTwice="failed-twice",error="error",direct="DIRECT",key=_lodash2.default.get(event,"Records[0].s3.object.key")||"",startsWithDirect=_lodash2.default.startsWith(key,direct);if(key.includes(failedOnce)||key.includes(failedTwice)||key.includes(error))
|
|
199
|
+
// this used to throw, but the throw raised useless alarms, I believed turing throw in to a return was ok
|
|
200
|
+
return;if(startsWithDirect)return console.log("-------\x3eDIRECT WRITE FIRE"),(0,_handleEvents.handleDirectS3WriteEvent)(event,transformer,errorHandlerPerFile,shouldSkipFailedFolders,userImportTypes)}}
|
|
201
|
+
/***/;var _publishEvents=__webpack_require__(864),_handleEvents=__webpack_require__(95),_lodash2=function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}(__webpack_require__(825))},
|
|
202
|
+
/***/505:
|
|
203
|
+
/***/(__unused_webpack_module,exports)=>{Object.defineProperty(exports,"__esModule",{value:!0});exports.errorList={invalidInventoryReleaseRequest:{message:"NOT ENOUGH INVENTORY TO FULFILL RELEASE",errorCode:"4010",statusCode:400},alreadyReleased:{message:"ALREADY RELEASED",errorCode:"4011",statusCode:400},alreadyReceived:{message:"RECEIVABLE ALREADY RECEIVED",errorCode:"4012",statusCode:400},invalidItemsRequest:{message:"VALID ITEMS MUST BE INCLUDED",errorCode:"4013",statusCode:400},invalidID:{message:"ID is invalid",errorCode:"4014",statusCode:400},invalidReceivable:{message:"MUST CONTAIN AT LEAST ONE RECEIVABLE",errorCode:"4015",statusCode:400},invalidRequest:{message:"INVALID REQUEST DATA",errorCode:"4016",statusCode:400},invalidAPIKey:{message:"INVALID REQUEST - API MAY KEY INVALID",errorCode:"4017",statusCode:400},qbCreationError:{message:"QUICKBOOKS ERROR - ERROR CREATING OBJECT IN QUICKBOOKS",errorCode:"4018",statusCode:400},cannotReopen:{message:"CANNOT REOPEN - THE ORDER HAS ALREADY BEEN OPENED",errorCode:"4018",statusCode:400},invalidDateFormat:{message:"INVALID DATE FORMAT",errorCode:"4019",statusCode:400},invalidStartDate:{message:"INVALID START DATE",errorCode:"4020",statusCode:400},invalidEndDate:{message:"INVALID END DATE",errorCode:"4021",statusCode:400},invalidOrderStatus:{message:"UNABLE TO EDIT ORDER ITEMS UNLESS THE ORDER IS IN ESTIMATE STATUS",errorCode:"4022",statusCode:400},invalidPaymentStatus:{message:"UNABLE TO UPDATE PAYMENT STATUS PAYMENT MUST BE OPEN",errorCode:"4023",statusCode:400},invalidReleaseStatus:{message:"UNABLE TO UPDATE RELEASE, STATUS RELEASE MUST BE OPEN",errorCode:"4024",statusCode:400},invalidReceivableStatus:{message:"UNABLE TO UPDATE RECEIVABLE, STATUS RECEIVABLE MUST BE OPEN",errorCode:"40025",statusCode:400},invalidJson:{message:"INVALID JSON",errorCode:"4005",statusCode:400},invalidFilter:{message:"INVALID FILTER",errorCode:"4026",statusCode:400},invalidUserNameUpdate:{message:"UNABLE TO UPDATE USERNAME",errorCode:"4027",statusCode:400},imageSizeLimit:{message:"IMAGE SIZE LIMIT 100KB EXCEEDED",errorCode:"4028",statusCode:400},unauthorized:{message:"UNAUTHORIZED",errorCode:"4111",statusCode:401},notFound:{message:"ITEM NOT FOUND",errorCode:"4004",statusCode:404},emailRequired:{message:"NO EMAIL PROVIDED, CHECK CUSTOMER EMAIL",errorCode:"4004",statusCode:404},mobilePhoneRequired:{message:"NO MOBILE PHONE PROVIDED, CHECK CUSTOMER CONTACTS",errorCode:"4004",statusCode:404},invalidCadenceType:{message:"INVALID CADENCE TYPE",errorCode:"5001",statusCode:500}};
|
|
204
|
+
/***/},
|
|
205
|
+
/***/435:
|
|
206
|
+
/***/(__unused_webpack_module,exports,__webpack_require__)=>{Object.defineProperty(exports,"__esModule",{value:!0}),exports.success=
|
|
207
|
+
/**
|
|
722
208
|
* @param {Object} body
|
|
723
209
|
* @param {{dbClose?:function}} [options]
|
|
724
|
-
*/
|
|
210
|
+
*/
|
|
211
|
+
function success(body,options){return _lodash2.default.get(options,"dbClose",_lodash2.default.noop)(),buildResponse(200,body)}
|
|
212
|
+
/**
|
|
725
213
|
* @param {string} html
|
|
726
214
|
* @param {{dbClose:function|undefined}} options
|
|
727
|
-
|
|
215
|
+
*/,exports.successHtml=function successHtml(html,options){return _lodash2.default.get(options,"dbClose",_lodash2.default.noop)(),{statusCode:200,headers:{"Content-Type":"text/html","Access-Control-Allow-Origin":"*","Access-Control-Allow-Credentials":!0},body:html}}
|
|
216
|
+
/**
|
|
728
217
|
* @param {string} event
|
|
729
218
|
* @returns string
|
|
730
|
-
|
|
219
|
+
*/,exports.getCurrentUserNameFromCognitoEvent=function getCurrentUserNameFromCognitoEvent(event){const attributes=_lodash2.default.get(event,"request.userAttributes");return attributes["cognito:email_alias"]||attributes.email||"UNKNOWN USER"}
|
|
220
|
+
/**
|
|
731
221
|
* Get the user information from the event object
|
|
732
222
|
*
|
|
733
223
|
* @param event {Object} an event object
|
|
734
224
|
* @returns {{username: string, id: number}}
|
|
735
|
-
|
|
225
|
+
*/,exports.getCurrentUser=function getCurrentUser(event){let jsonToParse=_lodash2.default.get(event,"requestContext.authorizer.claims.custom:UID")||_lodash2.default.get(event,"requestContext.authorizer.custom:UID")||"0";const id=JSON.parse(jsonToParse);return{username:_lodash2.default.get(event,"requestContext.authorizer.claims.email")||_lodash2.default.get(event,"requestContext.authorizer.email")||"localtestuser@gexample.com",id}}
|
|
226
|
+
/**
|
|
736
227
|
* Create a failure response
|
|
737
228
|
*
|
|
738
229
|
* @param body {Object} an event object
|
|
739
230
|
* @param options {Object} an options object
|
|
740
231
|
* @returns {{statusCode:number, headers:object, body:string}} a response object
|
|
741
|
-
|
|
232
|
+
*/,exports.failure=function failure(body={},options){let cleanedErrorBody;_lodash2.default.get(options,"dbClose",_lodash2.default.noop)(),("LOG_ALL"===process.env.UTIL_LOG||"test"===process.env.BUILD_ENV)&&console.error("-------\x3eUTIL ERROR:",body);cleanedErrorBody=body,_lodash2.default.isUndefined(body.details)?(_lodash2.default.isUndefined(body.errorCode)||_lodash2.default.isUndefined(body.statusCode))&&(cleanedErrorBody=detectSequelizeError(body)):cleanedErrorBody=detectJoyError(body);_lodash2.default.get(body,"response.data.message")&&console.error("-------\x3eUTIL ERROR: "+_lodash2.default.get(body,"response.data.message"));const newBody=_lodash2.default.merge({statusCode:500,errorCode:"5XX",message:"INTERNAL UTIL ERROR"},cleanedErrorBody);return buildResponse(newBody.statusCode,newBody)}
|
|
233
|
+
/**
|
|
742
234
|
* Create a failure response object
|
|
743
235
|
*
|
|
744
236
|
* @param statusCode {Number} a status code
|
|
745
237
|
* @param body {Object} an event object
|
|
746
238
|
* @returns {{statusCode:number, headers:object, body:string}} a response object
|
|
747
|
-
|
|
239
|
+
*/,exports.parseBody=
|
|
240
|
+
/**
|
|
748
241
|
* parse the body of the event object
|
|
749
242
|
*
|
|
750
243
|
* @param requestEvent {{body:string}} an event object
|
|
751
244
|
* @returns event {*} the json object of the body
|
|
752
|
-
*/
|
|
753
|
-
|
|
245
|
+
*/
|
|
246
|
+
function parseBody(requestEvent){let eventBody={};if(_lodash2.default.isString(requestEvent.body))try{eventBody=JSON.parse(requestEvent.body)}catch(e){// Invalid JSON
|
|
247
|
+
throw eventBody=null,_errorCodes.errorList.invalidJson}else _lodash2.default.isObject(requestEvent.body)&&(eventBody=requestEvent.body);return eventBody}
|
|
248
|
+
/**
|
|
754
249
|
* parse the body of the event object
|
|
755
250
|
*
|
|
756
251
|
* @param requestEvent {string|object} an event object
|
|
757
252
|
* @param [callback] {function} undefined a call back function
|
|
758
253
|
* @returns event {*} the json object of the body
|
|
759
|
-
|
|
760
|
-
|
|
254
|
+
*/,exports.parseEvent=function parseEvent(requestEvent,callback){let event={};if(_lodash2.default.isString(requestEvent))try{event=JSON.parse(requestEvent)}catch(e){// Invalid JSON
|
|
255
|
+
event=null,callback&&callback(Error(e))}else _lodash2.default.isObject(requestEvent)&&(event=requestEvent);return event}
|
|
256
|
+
/**
|
|
761
257
|
* parse the body of the event object
|
|
762
258
|
* look for sequelize errors and return a message
|
|
763
259
|
* ERRORS should not be caught here this is a fallback for unknown database errors
|
|
764
260
|
*
|
|
765
261
|
* @param body {object} part of a body response
|
|
766
262
|
* @returns error message object {message:string}
|
|
767
|
-
|
|
263
|
+
*/,exports.detectSequelizeError=detectSequelizeError,exports.detectJoyError=detectJoyError,exports.detectDynamooseError=
|
|
264
|
+
/**
|
|
768
265
|
* Parse the body of a Dynamoose error response.
|
|
769
266
|
* Attempts to extract a human-readable error message from Dynamoose errors.
|
|
770
267
|
* This is a fallback for unknown database errors.
|
|
771
268
|
*
|
|
772
269
|
* @param {object} body - Part of a body response containing error details.
|
|
773
270
|
* @returns {object} - Error message object { message: string }
|
|
774
|
-
*/
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
/***/
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
/***/
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
}
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
/***/
|
|
809
|
-
|
|
810
|
-
/***/
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
/***/
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
const sns = new _clientSns.SNS();
|
|
825
|
-
return await sns.publish(params);
|
|
826
|
-
}
|
|
827
|
-
|
|
828
|
-
async function createTopic(params) {
|
|
829
|
-
const sns = new _clientSns.SNS();
|
|
830
|
-
return await sns.createTopic(params);
|
|
831
|
-
}exports["default"] =
|
|
832
|
-
|
|
833
|
-
SNSUtil;
|
|
834
|
-
|
|
835
|
-
/***/ }),
|
|
836
|
-
|
|
837
|
-
/***/ "@aws-sdk/client-dynamodb":
|
|
838
|
-
/*!*******************************************!*\
|
|
839
|
-
!*** external "@aws-sdk/client-dynamodb" ***!
|
|
840
|
-
\*******************************************/
|
|
841
|
-
/***/ ((module) => {
|
|
842
|
-
|
|
843
|
-
module.exports = require("@aws-sdk/client-dynamodb");
|
|
844
|
-
|
|
845
|
-
/***/ }),
|
|
846
|
-
|
|
847
|
-
/***/ "@aws-sdk/client-s3":
|
|
848
|
-
/*!*************************************!*\
|
|
849
|
-
!*** external "@aws-sdk/client-s3" ***!
|
|
850
|
-
\*************************************/
|
|
851
|
-
/***/ ((module) => {
|
|
852
|
-
|
|
853
|
-
module.exports = require("@aws-sdk/client-s3");
|
|
854
|
-
|
|
855
|
-
/***/ }),
|
|
856
|
-
|
|
857
|
-
/***/ "@aws-sdk/client-sns":
|
|
858
|
-
/*!**************************************!*\
|
|
859
|
-
!*** external "@aws-sdk/client-sns" ***!
|
|
860
|
-
\**************************************/
|
|
861
|
-
/***/ ((module) => {
|
|
862
|
-
|
|
863
|
-
module.exports = require("@aws-sdk/client-sns");
|
|
864
|
-
|
|
865
|
-
/***/ }),
|
|
866
|
-
|
|
867
|
-
/***/ "@aws-sdk/lib-dynamodb":
|
|
868
|
-
/*!****************************************!*\
|
|
869
|
-
!*** external "@aws-sdk/lib-dynamodb" ***!
|
|
870
|
-
\****************************************/
|
|
871
|
-
/***/ ((module) => {
|
|
872
|
-
|
|
873
|
-
module.exports = require("@aws-sdk/lib-dynamodb");
|
|
874
|
-
|
|
875
|
-
/***/ }),
|
|
876
|
-
|
|
877
|
-
/***/ "bluebird":
|
|
878
|
-
/*!***************************!*\
|
|
879
|
-
!*** external "bluebird" ***!
|
|
880
|
-
\***************************/
|
|
881
|
-
/***/ ((module) => {
|
|
882
|
-
|
|
883
|
-
module.exports = require("bluebird");
|
|
884
|
-
|
|
885
|
-
/***/ }),
|
|
886
|
-
|
|
887
|
-
/***/ "lodash":
|
|
888
|
-
/*!*************************!*\
|
|
889
|
-
!*** external "lodash" ***!
|
|
890
|
-
\*************************/
|
|
891
|
-
/***/ ((module) => {
|
|
892
|
-
|
|
893
|
-
module.exports = require("lodash");
|
|
894
|
-
|
|
895
|
-
/***/ }),
|
|
896
|
-
|
|
897
|
-
/***/ "moment":
|
|
898
|
-
/*!*************************!*\
|
|
899
|
-
!*** external "moment" ***!
|
|
900
|
-
\*************************/
|
|
901
|
-
/***/ ((module) => {
|
|
902
|
-
|
|
903
|
-
module.exports = require("moment");
|
|
904
|
-
|
|
905
|
-
/***/ }),
|
|
906
|
-
|
|
907
|
-
/***/ "moment/moment.js":
|
|
908
|
-
/*!***********************************!*\
|
|
909
|
-
!*** external "moment/moment.js" ***!
|
|
910
|
-
\***********************************/
|
|
911
|
-
/***/ ((module) => {
|
|
912
|
-
|
|
913
|
-
module.exports = require("moment/moment.js");
|
|
914
|
-
|
|
915
|
-
/***/ }),
|
|
916
|
-
|
|
917
|
-
/***/ "sequelize":
|
|
918
|
-
/*!****************************!*\
|
|
919
|
-
!*** external "sequelize" ***!
|
|
920
|
-
\****************************/
|
|
921
|
-
/***/ ((module) => {
|
|
922
|
-
|
|
923
|
-
module.exports = require("sequelize");
|
|
924
|
-
|
|
925
|
-
/***/ }),
|
|
926
|
-
|
|
927
|
-
/***/ "umzug":
|
|
928
|
-
/*!************************!*\
|
|
929
|
-
!*** external "umzug" ***!
|
|
930
|
-
\************************/
|
|
931
|
-
/***/ ((module) => {
|
|
932
|
-
|
|
933
|
-
module.exports = require("umzug");
|
|
934
|
-
|
|
935
|
-
/***/ })
|
|
936
|
-
|
|
937
|
-
/******/ });
|
|
938
|
-
/************************************************************************/
|
|
939
|
-
/******/ // The module cache
|
|
940
|
-
/******/ var __webpack_module_cache__ = {};
|
|
941
|
-
/******/
|
|
942
|
-
/******/ // The require function
|
|
943
|
-
/******/ function __webpack_require__(moduleId) {
|
|
944
|
-
/******/ // Check if module is in cache
|
|
945
|
-
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
|
946
|
-
/******/ if (cachedModule !== undefined) {
|
|
947
|
-
/******/ return cachedModule.exports;
|
|
948
|
-
/******/ }
|
|
949
|
-
/******/ // Create a new module (and put it into the cache)
|
|
950
|
-
/******/ var module = __webpack_module_cache__[moduleId] = {
|
|
951
|
-
/******/ // no module.id needed
|
|
952
|
-
/******/ // no module.loaded needed
|
|
953
|
-
/******/ exports: {}
|
|
954
|
-
/******/ };
|
|
955
|
-
/******/
|
|
956
|
-
/******/ // Execute the module function
|
|
957
|
-
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
958
|
-
/******/
|
|
959
|
-
/******/ // Return the exports of the module
|
|
960
|
-
/******/ return module.exports;
|
|
961
|
-
/******/ }
|
|
962
|
-
/******/
|
|
271
|
+
*/
|
|
272
|
+
function detectDynamooseError(body){const errorBody={};// Start with an empty message string.
|
|
273
|
+
let dynamooseError="";// If the error body contains an array of errors, concatenate their messages.
|
|
274
|
+
Array.isArray(body.errors)&&(dynamooseError+=body.errors.reduce(((acc,err)=>acc+" "+(err.message||"")),""));// If there's a top-level message, add it.
|
|
275
|
+
body.message&&(dynamooseError+=" "+body.message);// If there is any additional detail provided, append it.
|
|
276
|
+
body.detail&&(dynamooseError+=" "+body.detail);// Trim the message to remove extra spaces.
|
|
277
|
+
return errorBody.message=dynamooseError.trim(),errorBody}
|
|
278
|
+
/***/;var _lodash2=function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}(__webpack_require__(825)),_errorCodes=__webpack_require__(505);function buildResponse(statusCode,body){return{statusCode,headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Credentials":!0},body:JSON.stringify(body)}}function detectSequelizeError(body){const errorBody={};let sequelizeError=_lodash2.default.get(body,"errors",[]).reduce(((acc,err)=>acc=acc+" "+_lodash2.default.get(err,"message")),"");const parentError=_lodash2.default.get(body,"parent","");return sequelizeError=sequelizeError+_lodash2.default.get(body,"original.detail","")+_lodash2.default.get(body,"TypeError","")+parentError,errorBody.message=sequelizeError.trim(),errorBody}function detectJoyError(body){const errorBody={},joyError=_lodash2.default.get(body,"details[0]",{});return console.error("USER VALIDATION ERROR:",body),errorBody.message=joyError.message,errorBody.statusCode=400,errorBody.errorCode="4000",errorBody}},
|
|
279
|
+
/***/591:
|
|
280
|
+
/***/(__unused_webpack_module,exports,__webpack_require__)=>{Object.defineProperty(exports,"__esModule",{value:!0}),exports.s3Utils=s3Utils;var _clientS=__webpack_require__(43);function s3Utils(action,params){return(new _clientS.S3)[action](params)}const S3Util={getObject:params=>async function getS3(params){const s3=new _clientS.S3,response=await s3.getObject(params);return response?.Body.transformToString("utf-8")}
|
|
281
|
+
/***/(params),deleteObject:params=>s3Utils("deleteObject",params),putObject:params=>s3Utils("putObject",params),listObjectsV2:params=>s3Utils("listObjectsV2",params)};exports.default=S3Util},
|
|
282
|
+
/***/306:
|
|
283
|
+
/***/(__unused_webpack_module,exports,__webpack_require__)=>{Object.defineProperty(exports,"__esModule",{value:!0});var _clientSns=__webpack_require__(793);const SNSUtil={publish:params=>async function publish(params){const sns=new _clientSns.SNS;return await sns.publish(params)}(params),createTopic:params=>async function createTopic(params){const sns=new _clientSns.SNS;return await sns.createTopic(params)}(params)};exports.default=SNSUtil},
|
|
284
|
+
/***/929:
|
|
285
|
+
/***/module=>{module.exports=require("@aws-sdk/client-dynamodb");
|
|
286
|
+
/***/},
|
|
287
|
+
/***/43:
|
|
288
|
+
/***/module=>{module.exports=require("@aws-sdk/client-s3");
|
|
289
|
+
/***/},
|
|
290
|
+
/***/793:
|
|
291
|
+
/***/module=>{module.exports=require("@aws-sdk/client-sns");
|
|
292
|
+
/***/},
|
|
293
|
+
/***/515:
|
|
294
|
+
/***/module=>{module.exports=require("@aws-sdk/lib-dynamodb");
|
|
295
|
+
/***/},
|
|
296
|
+
/***/564:
|
|
297
|
+
/***/module=>{module.exports=require("bluebird");
|
|
298
|
+
/***/},
|
|
299
|
+
/***/293:
|
|
300
|
+
/***/module=>{module.exports=require("dayjs");
|
|
301
|
+
/***/},
|
|
302
|
+
/***/59:
|
|
303
|
+
/***/module=>{module.exports=require("dayjs/plugin/customParseFormat");
|
|
304
|
+
/***/},
|
|
305
|
+
/***/394:
|
|
306
|
+
/***/module=>{module.exports=require("dayjs/plugin/isSameOrBefore");
|
|
307
|
+
/***/},
|
|
308
|
+
/***/137:
|
|
309
|
+
/***/module=>{module.exports=require("dayjs/plugin/utc.js");
|
|
310
|
+
/***/},
|
|
311
|
+
/***/825:
|
|
312
|
+
/***/module=>{module.exports=require("lodash");
|
|
313
|
+
/***/},
|
|
314
|
+
/***/31:
|
|
315
|
+
/***/module=>{module.exports=require("sequelize");
|
|
316
|
+
/***/},
|
|
317
|
+
/***/920:
|
|
318
|
+
/***/module=>{module.exports=require("umzug");
|
|
319
|
+
/***/}
|
|
320
|
+
/******/},__webpack_module_cache__={};
|
|
963
321
|
/************************************************************************/
|
|
964
|
-
|
|
322
|
+
/******/ // The module cache
|
|
323
|
+
/******/
|
|
324
|
+
/******/
|
|
325
|
+
/******/ // The require function
|
|
326
|
+
/******/function __webpack_require__(moduleId){
|
|
327
|
+
/******/ // Check if module is in cache
|
|
328
|
+
/******/var cachedModule=__webpack_module_cache__[moduleId];
|
|
329
|
+
/******/if(void 0!==cachedModule)
|
|
330
|
+
/******/return cachedModule.exports;
|
|
331
|
+
/******/
|
|
332
|
+
/******/ // Create a new module (and put it into the cache)
|
|
333
|
+
/******/var module=__webpack_module_cache__[moduleId]={
|
|
334
|
+
/******/ // no module.id needed
|
|
335
|
+
/******/ // no module.loaded needed
|
|
336
|
+
/******/exports:{}
|
|
337
|
+
/******/};
|
|
338
|
+
/******/
|
|
339
|
+
/******/ // Execute the module function
|
|
340
|
+
/******/
|
|
341
|
+
/******/
|
|
342
|
+
/******/ // Return the exports of the module
|
|
343
|
+
/******/return __webpack_modules__[moduleId](module,module.exports,__webpack_require__),module.exports;
|
|
344
|
+
/******/}
|
|
345
|
+
/******/
|
|
346
|
+
/************************************************************************/var __webpack_exports__={};
|
|
965
347
|
// This entry need to be wrapped in an IIFE because it uses a non-standard name for the exports (exports).
|
|
966
|
-
(()
|
|
967
|
-
|
|
968
|
-
/*!**********************!*\
|
|
969
|
-
!*** ./src/index.js ***!
|
|
970
|
-
\**********************/
|
|
971
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));exports.isSystemUser = exports.checkWriteAccess = exports.userDefaultBid = exports.getBusinessesInfo = exports.parseEvent = exports.parseBody = exports.accessRightsUtils = exports.defaultFilters = exports.getCurrentUserNameFromCognitoEvent = exports.successHtml = exports.getCurrentUser = exports.runMigrations = exports.success = exports.failure = exports.getModuleInfo = exports.getDefaultBusinessIDInfo = exports.getAccessRightsInfo = exports.checkModule = exports.findAll = exports.createSort = exports.createIncludes = exports.createFilters = exports.publishEvents = exports.watchBucket = exports.handleFile = undefined;var _handleFile = __webpack_require__(/*! ./eventManager/handleFile.js */ "./src/eventManager/handleFile.js");
|
|
972
|
-
var _watchBucket = __webpack_require__(/*! ./eventManager/watchBucket.js */ "./src/eventManager/watchBucket.js");
|
|
973
|
-
var _publishEvents = __webpack_require__(/*! ./eventManager/publishEvents.js */ "./src/eventManager/publishEvents.js");
|
|
974
|
-
var _createIncludes = __webpack_require__(/*! ./database/dbUtils/queryStringUtils/createIncludes.js */ "./src/database/dbUtils/queryStringUtils/createIncludes.js");
|
|
975
|
-
var _createFilters = __webpack_require__(/*! ./database/dbUtils/queryStringUtils/createFilters.js */ "./src/database/dbUtils/queryStringUtils/createFilters.js");
|
|
976
|
-
var _createSort = __webpack_require__(/*! ./database/dbUtils/queryStringUtils/createSort.js */ "./src/database/dbUtils/queryStringUtils/createSort.js");
|
|
977
|
-
var _findAll = __webpack_require__(/*! ./database/dbUtils/queryStringUtils/findAll.js */ "./src/database/dbUtils/queryStringUtils/findAll.js");
|
|
978
|
-
var _accessRightsUtils = __webpack_require__(/*! ./database/dbUtils/queryStringUtils/accessRightsUtils.js */ "./src/database/dbUtils/queryStringUtils/accessRightsUtils.js");
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
var _requestResponse = __webpack_require__(/*! ./requestResonse/requestResponse.js */ "./src/requestResonse/requestResponse.js");
|
|
983
|
-
var _migrations = __webpack_require__(/*! ./database/dbSetup/migrations.js */ "./src/database/dbSetup/migrations.js");
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
var _defaultFilters = __webpack_require__(/*! ./database/dbUtils/queryStringUtils/defaultFilters.js */ "./src/database/dbUtils/queryStringUtils/defaultFilters.js");
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
const handleFile = exports.handleFile = _handleFile.handleFile;
|
|
997
|
-
const watchBucket = exports.watchBucket = _watchBucket.watchBucket;
|
|
998
|
-
const publishEvents = exports.publishEvents = _publishEvents.publishEvents;
|
|
999
|
-
const createFilters = exports.createFilters = _createFilters.createFilters;
|
|
1000
|
-
const createIncludes = exports.createIncludes = _createIncludes.createIncludes;
|
|
1001
|
-
const createSort = exports.createSort = _createSort.createSort;
|
|
1002
|
-
const findAll = exports.findAll = _findAll.findAll;
|
|
1003
|
-
const checkModule = exports.checkModule = _accessRightsUtils.checkModule;
|
|
1004
|
-
const getAccessRightsInfo = exports.getAccessRightsInfo = _accessRightsUtils.getAccessRightsInfo;
|
|
1005
|
-
const getDefaultBusinessIDInfo = exports.getDefaultBusinessIDInfo = _accessRightsUtils.getDefaultBusinessIDInfo;
|
|
1006
|
-
const getModuleInfo = exports.getModuleInfo = _accessRightsUtils.getModuleInfo;
|
|
1007
|
-
const failure = exports.failure = _requestResponse.failure;
|
|
1008
|
-
const success = exports.success = _requestResponse.success;
|
|
1009
|
-
const runMigrations = exports.runMigrations = _migrations.runMigrations;
|
|
1010
|
-
const getCurrentUser = exports.getCurrentUser = _requestResponse.getCurrentUser;
|
|
1011
|
-
const successHtml = exports.successHtml = _requestResponse.successHtml;
|
|
1012
|
-
const getCurrentUserNameFromCognitoEvent = exports.getCurrentUserNameFromCognitoEvent = _requestResponse.getCurrentUserNameFromCognitoEvent;
|
|
1013
|
-
const defaultFilters = exports.defaultFilters = _defaultFilters.defaultFilters;
|
|
1014
|
-
const accessRightsUtils = exports.accessRightsUtils = _accessRightsUtils.accessRightsUtils;
|
|
1015
|
-
const parseBody = exports.parseBody = _requestResponse.parseBody;
|
|
1016
|
-
const parseEvent = exports.parseEvent = _requestResponse.parseEvent;
|
|
1017
|
-
const getBusinessesInfo = exports.getBusinessesInfo = _accessRightsUtils.getBusinessesInfo;
|
|
1018
|
-
const userDefaultBid = exports.userDefaultBid = _accessRightsUtils.userDefaultBid;
|
|
1019
|
-
const checkWriteAccess = exports.checkWriteAccess = _accessRightsUtils.checkWriteAccess;
|
|
1020
|
-
const isSystemUser = exports.isSystemUser = _accessRightsUtils.isSystemUser;
|
|
1021
|
-
})();
|
|
1022
|
-
|
|
1023
|
-
var __webpack_export_target__ = exports;
|
|
1024
|
-
for(var i in __webpack_exports__) __webpack_export_target__[i] = __webpack_exports__[i];
|
|
1025
|
-
if(__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, "__esModule", { value: true });
|
|
1026
|
-
/******/ })()
|
|
1027
|
-
;
|
|
348
|
+
(()=>{var exports=__webpack_exports__;Object.defineProperty(exports,"__esModule",{value:!0}),exports.isSystemUser=exports.checkWriteAccess=exports.userDefaultBid=exports.getBusinessesInfo=exports.parseEvent=exports.parseBody=exports.accessRightsUtils=exports.defaultFilters=exports.getCurrentUserNameFromCognitoEvent=exports.successHtml=exports.getCurrentUser=exports.runMigrations=exports.success=exports.failure=exports.getModuleInfo=exports.getDefaultBusinessIDInfo=exports.getAccessRightsInfo=exports.checkModule=exports.findAll=exports.createSort=exports.createIncludes=exports.createFilters=exports.publishEvents=exports.watchBucket=exports.handleFile=void 0;var _handleFile=__webpack_require__(876),_watchBucket=__webpack_require__(183),_publishEvents=__webpack_require__(864),_createIncludes=__webpack_require__(982),_createFilters=__webpack_require__(288),_createSort=__webpack_require__(835),_findAll=__webpack_require__(981),_accessRightsUtils=__webpack_require__(673),_requestResponse=__webpack_require__(435),_migrations=__webpack_require__(871),_defaultFilters=__webpack_require__(207);exports.handleFile=_handleFile.handleFile,exports.watchBucket=_watchBucket.watchBucket,exports.publishEvents=_publishEvents.publishEvents,exports.createFilters=_createFilters.createFilters,exports.createIncludes=_createIncludes.createIncludes,exports.createSort=_createSort.createSort,exports.findAll=_findAll.findAll,exports.checkModule=_accessRightsUtils.checkModule,exports.getAccessRightsInfo=_accessRightsUtils.getAccessRightsInfo,exports.getDefaultBusinessIDInfo=_accessRightsUtils.getDefaultBusinessIDInfo,exports.getModuleInfo=_accessRightsUtils.getModuleInfo,exports.failure=_requestResponse.failure,exports.success=_requestResponse.success,exports.runMigrations=_migrations.runMigrations,exports.getCurrentUser=_requestResponse.getCurrentUser,exports.successHtml=_requestResponse.successHtml,exports.getCurrentUserNameFromCognitoEvent=_requestResponse.getCurrentUserNameFromCognitoEvent,exports.defaultFilters=_defaultFilters.defaultFilters,exports.accessRightsUtils=_accessRightsUtils.accessRightsUtils,exports.parseBody=_requestResponse.parseBody,exports.parseEvent=_requestResponse.parseEvent,exports.getBusinessesInfo=_accessRightsUtils.getBusinessesInfo,exports.userDefaultBid=_accessRightsUtils.userDefaultBid,exports.checkWriteAccess=_accessRightsUtils.checkWriteAccess,exports.isSystemUser=_accessRightsUtils.isSystemUser})();var __webpack_export_target__=exports;for(var i in __webpack_exports__)__webpack_export_target__[i]=__webpack_exports__[i];__webpack_exports__.__esModule&&Object.defineProperty(__webpack_export_target__,"__esModule",{value:!0})
|
|
349
|
+
/******/})();
|
|
1028
350
|
//# sourceMappingURL=main.js.map
|