piper-utils 1.1.70 → 1.1.71
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 +52 -3
- package/bin/main.js.map +1 -1
- package/package.json +62 -62
- package/src/contract/contract.js +42 -0
- package/src/contract/contract.test.js +36 -0
- package/src/database/dbUtils/partnerAccess/accessScope.test.js +287 -287
- package/src/eventManager/handleFile.js +129 -115
- package/src/eventManager/handleFile.test.js +463 -460
- package/src/index.js +4 -0
package/bin/main.js
CHANGED
|
@@ -409,6 +409,37 @@ return itemType instanceof _sequelize.default.STRING||itemType instanceof _seque
|
|
|
409
409
|
//these are automatically part of the models, so add them always
|
|
410
410
|
acc.createdAt={type:_sequelize.default.DATE,filterType:_sequelize.default.Op.between},acc.updatedAt={type:_sequelize.default.DATE,filterType:_sequelize.default.Op.between},acc.id={type:_sequelize.default.INTEGER,filterType:_sequelize.default.Op.eq},acc},filters)}
|
|
411
411
|
/***/},
|
|
412
|
+
/***/269(__unused_webpack_module,exports){Object.defineProperty(exports,"__esModule",{value:!0}),exports.contractStatuses=exports.contractChoices=void 0,exports.isContractChoice=
|
|
413
|
+
/*
|
|
414
|
+
* True when value is a choice the signing page is allowed to send. The gateway
|
|
415
|
+
* gates on this before selecting which of the two server-side amounts to charge,
|
|
416
|
+
* so an unrecognized choice is a 400 rather than a wrong amount.
|
|
417
|
+
*
|
|
418
|
+
* @param {string} value
|
|
419
|
+
* @returns {boolean}
|
|
420
|
+
*/
|
|
421
|
+
function isContractChoice(value){return Object.values(contractChoices).includes(value)}
|
|
422
|
+
/***/;
|
|
423
|
+
/*
|
|
424
|
+
* Financing contract constants shared by the ERP (piper) and the payment
|
|
425
|
+
* gateway (piper-gateway). Both sides put these strings on the wire — the ERP
|
|
426
|
+
* writes them onto the order and the prepare payload, the gateway reads them
|
|
427
|
+
* back off the checkout page and echoes them home on the webhook — so they must
|
|
428
|
+
* agree exactly. Keeping them here is what stops a 'down' / 'Down' drift from
|
|
429
|
+
* becoming a silent mischarge.
|
|
430
|
+
*/
|
|
431
|
+
/*
|
|
432
|
+
* What the customer chose on the signing page.
|
|
433
|
+
* - full: pay the whole order total now; no financing, so no contract to sign
|
|
434
|
+
* - down: pay the down payment now and sign the financing contract for the rest
|
|
435
|
+
*/
|
|
436
|
+
const contractChoices=exports.contractChoices={full:"full",down:"down"};
|
|
437
|
+
/*
|
|
438
|
+
* Lifecycle of the contract attached to an order.
|
|
439
|
+
* - draft: order is still an estimate; nothing rendered yet
|
|
440
|
+
* - sent: contract body frozen and hashed, link is out with the customer
|
|
441
|
+
* - signed: customer consented and signed; signature + audit trail persisted
|
|
442
|
+
*/exports.contractStatuses={draft:"Draft",sent:"Sent",signed:"Signed"}},
|
|
412
443
|
/***/288(__unused_webpack_module,exports,__webpack_require__){Object.defineProperty(exports,"__esModule",{value:!0}),exports.createFilters=void 0;var _lodash=_interopRequireDefault(__webpack_require__(825)),_sequelize=_interopRequireDefault(__webpack_require__(31)),_dayjs=_interopRequireDefault(__webpack_require__(293)),_utc=_interopRequireDefault(__webpack_require__(137)),_errorCodes=__webpack_require__(953),_accessRightsUtils=__webpack_require__(673);function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}_dayjs.default.extend(_utc.default);exports.createFilters=function(event,objectFilters){let query=_lodash.default.get(event,"queryStringParameters",{})||{};
|
|
413
444
|
// Extract the three convenience params before iterating.
|
|
414
445
|
// These are handled separately from the per-field filter logic below.
|
|
@@ -829,13 +860,31 @@ async function runMigrations(databaseName,sequelizeInstance,initializeModels,pat
|
|
|
829
860
|
// The tables are still initiated by being passed in to run migrations
|
|
830
861
|
await initializeModels()}
|
|
831
862
|
/***/;var _lodash=function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}(__webpack_require__(825)),_umzug=__webpack_require__(920)},
|
|
832
|
-
/***/876(__unused_webpack_module,exports,__webpack_require__){Object.defineProperty(exports,"__esModule",{value:!0}),exports.
|
|
863
|
+
/***/876(__unused_webpack_module,exports,__webpack_require__){Object.defineProperty(exports,"__esModule",{value:!0}),exports.handleFile=async function handleFile(path,s3Bucket,transformer,options){const shouldSkipFailedFolders=_lodash.default.get(options,"shouldSkipFailedFolders"),userImportTypes=_lodash.default.get(options,"userImportTypes"),params={Bucket:s3Bucket,Key:path};let body;try{body=await _S3Utils.default.getObject(params)}catch(e){if("NoSuchKey"===e.Code||"NoSuchKey"===e.code||"NoSuchKey"===e.name)return;throw console.error("S3 getObject error:",e),e}try{
|
|
833
864
|
// exit early for null/undefined or blank string bodies
|
|
834
865
|
if(_lodash.default.isNil(body)||_lodash.default.isString(body)&&_lodash.default.isEmpty(body.trim()))return void await _S3Utils.default.deleteObject(params);const parsedBody=JSON.parse(body);
|
|
835
866
|
// exit early for objects like {} or []
|
|
836
867
|
if(_lodash.default.isEmpty(parsedBody))return void await _S3Utils.default.deleteObject(params);const returnedValue=await transformer(parsedBody);return await _S3Utils.default.deleteObject(params),returnedValue}catch(error){if(console.error("HANDLE-FILE-ERROR",error),!body)return;let newPath="";if(userImportTypes){console.log("USER IMPORT");
|
|
837
868
|
// look for items in the userImportTypes
|
|
838
|
-
const usersImports=Object.values(userImportTypes),items=path.split("/"),fileName=_lodash.default.last(items),folderName=_lodash.default.first(items);newPath=usersImports.indexOf(folderName)>-1?shouldSkipFailedFolders?`${folderName}/error/${fileName}`:_lodash.default.startsWith(path,`${folderName}/failed-once/`)?_lodash.default.replace(path,`${folderName}/failed-once/`,`${folderName}/failed-twice/`):_lodash.default.startsWith(path,`${folderName}/failed-twice/`)?_lodash.default.replace(path,`${folderName}/failed-twice/`,`${folderName}/error/`):`${folderName}/failed-once/${fileName}`:`pathAndEventMisMatchError/${path}`}else shouldSkipFailedFolders?newPath=`error/${path}`:_lodash.default.startsWith(path,"failed-once/")?newPath=_lodash.default.replace(path,"failed-once/","failed-twice/"):_lodash.default.startsWith(path,"failed-twice/")?newPath=_lodash.default.replace(path,"failed-twice/","error/"):(_lodash.default.includes(path,"delayUntil/")&&(path=_lodash.default.last(path.split("/"))),newPath=`failed-once/${path}`);const newParams={Bucket:s3Bucket,Key:newPath,Body:body};
|
|
869
|
+
const usersImports=Object.values(userImportTypes),items=path.split("/"),fileName=_lodash.default.last(items),folderName=_lodash.default.first(items);newPath=usersImports.indexOf(folderName)>-1?shouldSkipFailedFolders?`${folderName}/error/${fileName}`:_lodash.default.startsWith(path,`${folderName}/failed-once/`)?_lodash.default.replace(path,`${folderName}/failed-once/`,`${folderName}/failed-twice/`):_lodash.default.startsWith(path,`${folderName}/failed-twice/`)?_lodash.default.replace(path,`${folderName}/failed-twice/`,`${folderName}/error/`):`${folderName}/failed-once/${fileName}`:`pathAndEventMisMatchError/${path}`}else shouldSkipFailedFolders?newPath=`error/${path}`:_lodash.default.startsWith(path,"failed-once/")?newPath=_lodash.default.replace(path,"failed-once/","failed-twice/"):_lodash.default.startsWith(path,"failed-twice/")?newPath=_lodash.default.replace(path,"failed-twice/","error/"):(_lodash.default.includes(path,"delayUntil/")&&(path=_lodash.default.last(path.split("/"))),newPath=`failed-once/${path}`);const newParams={Bucket:s3Bucket,Key:newPath,Body:body};
|
|
870
|
+
// Guard against genuine prefix nesting (e.g. `failed-once/error/<file>`) — a file that has
|
|
871
|
+
// already traversed the failure ladder. Detect this on the FOLDER SEGMENTS only, never the
|
|
872
|
+
// filename, so a user-uploaded file named e.g. `errors.csv` or `failed-once-list.csv` is
|
|
873
|
+
// not mistaken for a nested path. The previous check counted the token anywhere in the key
|
|
874
|
+
// (including the filename) and threw BEFORE the move/delete below, so the file was neither
|
|
875
|
+
// dead-lettered nor removed — publishEvents.loop() then re-listed it every tick, an
|
|
876
|
+
// infinite reprocess loop. If the destination really is nested, still DELETE the source so
|
|
877
|
+
// it dead-letters instead of looping forever. See audit finding #8.
|
|
878
|
+
if(isNestedFailurePath(newPath))throw await _S3Utils.default.deleteObject(params),new Error("NESTING ERROR");throw await _S3Utils.default.putObject(newParams),await _S3Utils.default.deleteObject(params),error}}
|
|
879
|
+
/**
|
|
880
|
+
* True when a key has already traversed the failure ladder more than once, i.e. its FOLDER
|
|
881
|
+
* portion contains more than one of the ladder stages (failed-once / failed-twice / error).
|
|
882
|
+
* Only whole path SEGMENTS are considered, never the filename, so a file literally named
|
|
883
|
+
* `errors.csv` is not treated as nested.
|
|
884
|
+
*
|
|
885
|
+
* @param {string} key - The destination S3 key
|
|
886
|
+
* @returns {boolean}
|
|
887
|
+
*/,exports.isNestedFailurePath=isNestedFailurePath;var _lodash=_interopRequireDefault(__webpack_require__(825)),_S3Utils=_interopRequireDefault(__webpack_require__(908));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function isNestedFailurePath(key){const ladderStages=["failed-once","failed-twice","error"];return String(key).split("/").slice(0,-1).filter(segment=>ladderStages.includes(segment)).length>1}
|
|
839
888
|
/***/},
|
|
840
889
|
/***/908(__unused_webpack_module,exports,__webpack_require__){Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 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")}
|
|
841
890
|
/***/(params),deleteObject:params=>s3Utils("deleteObject",params),putObject:params=>s3Utils("putObject",params),listObjectsV2:params=>s3Utils("listObjectsV2",params)};exports.default=S3Util},
|
|
@@ -897,6 +946,6 @@ function createIncludes(event,objectFilters){const query=_lodash.default.get(eve
|
|
|
897
946
|
/******/
|
|
898
947
|
/************************************************************************/var __webpack_exports__={};
|
|
899
948
|
// This entry needs to be wrapped in an IIFE because it uses a non-standard name for the exports (exports).
|
|
900
|
-
(()=>{var exports=__webpack_exports__;Object.defineProperty(exports,"__esModule",{value:!0}),exports.watchBucket=exports.userDefaultBid=exports.successHtml=exports.success=exports.stampOwnBusinessId=exports.scopeToPartnerBook=exports.scopeToOwnBusiness=exports.scopeToBookUnionOwn=exports.runMigrations=exports.resolveAccess=exports.requireTicketAccess=exports.requireSuper=exports.requireCrmAccess=exports.publishEvents=exports.parseEvent=exports.parseBody=exports.isSystemUser=exports.isSuperUser=exports.isPartnerUser=exports.incrementWithAudit=exports.handleFile=exports.getModuleInfo=exports.getEffectivePartnerId=exports.getDefaultBusinessIDInfo=exports.getCurrentUserNameFromCognitoEvent=exports.getCurrentUser=exports.getCompanySettings=exports.getBusinessesInfo=exports.getBelongsToPartnerId=exports.getAuditModel=exports.getAuditFilter=exports.getAccessRightsInfo=exports.findAll=exports.failure=exports.ensurePartnerScope=exports.enrichEventWithPartnerAccess=exports.defaultFilters=exports.decrementWithAudit=exports.createSort=exports.createIncludes=exports.createFilters=exports.createAccessHelpers=exports.checkWriteAccess=exports.checkModule=exports.checkIsSuper=exports.bindAuditRequestForUser=exports.bindAuditRequest=exports.attachAudit=exports.assertCanWriteOwnBusiness=exports.assertCanWriteBookUnionOwn=exports.assertCanWriteBookBusiness=exports.accessRightsUtils=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__(859),_migrations=__webpack_require__(871),_defaultFilters=__webpack_require__(207),_accessContext=__webpack_require__(62),_accessGates=__webpack_require__(189),_accessScope=__webpack_require__(513),_accessWrites=__webpack_require__(165),_createAccessHelpers=__webpack_require__(539),_audit=__webpack_require__(179);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.checkIsSuper=_accessRightsUtils.checkIsSuper,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,exports.isSuperUser=_accessRightsUtils.isSuperUser,exports.isPartnerUser=_accessRightsUtils.isPartnerUser,exports.getBelongsToPartnerId=_accessRightsUtils.getBelongsToPartnerId,exports.getEffectivePartnerId=_accessRightsUtils.getEffectivePartnerId,exports.enrichEventWithPartnerAccess=_accessRightsUtils.enrichEventWithPartnerAccess,exports.getCompanySettings=_accessRightsUtils.getCompanySettings,exports.resolveAccess=_accessContext.resolveAccess,exports.ensurePartnerScope=_accessContext.ensurePartnerScope,exports.requireCrmAccess=_accessGates.requireCrmAccess,exports.requireTicketAccess=_accessGates.requireTicketAccess,exports.requireSuper=_accessGates.requireSuper,exports.scopeToOwnBusiness=_accessScope.scopeToOwnBusiness,exports.scopeToPartnerBook=_accessScope.scopeToPartnerBook,exports.scopeToBookUnionOwn=_accessScope.scopeToBookUnionOwn,exports.assertCanWriteOwnBusiness=_accessWrites.assertCanWriteOwnBusiness,exports.assertCanWriteBookBusiness=_accessWrites.assertCanWriteBookBusiness,exports.assertCanWriteBookUnionOwn=_accessWrites.assertCanWriteBookUnionOwn,exports.stampOwnBusinessId=_accessWrites.stampOwnBusinessId,exports.createAccessHelpers=_createAccessHelpers.createAccessHelpers,exports.attachAudit=_audit.attachAudit,exports.bindAuditRequest=_audit.bindAuditRequest,exports.bindAuditRequestForUser=_audit.bindAuditRequestForUser,exports.decrementWithAudit=_audit.decrementWithAudit,exports.getAuditFilter=_audit.getAuditFilter,exports.getAuditModel=_audit.getAuditModel,exports.incrementWithAudit=_audit.incrementWithAudit})();var __webpack_export_target__=exports;for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__]=__webpack_exports__[__webpack_i__];__webpack_exports__.__esModule&&Object.defineProperty(__webpack_export_target__,"__esModule",{value:!0})
|
|
949
|
+
(()=>{var exports=__webpack_exports__;Object.defineProperty(exports,"__esModule",{value:!0}),exports.watchBucket=exports.userDefaultBid=exports.successHtml=exports.success=exports.stampOwnBusinessId=exports.scopeToPartnerBook=exports.scopeToOwnBusiness=exports.scopeToBookUnionOwn=exports.runMigrations=exports.resolveAccess=exports.requireTicketAccess=exports.requireSuper=exports.requireCrmAccess=exports.publishEvents=exports.parseEvent=exports.parseBody=exports.isSystemUser=exports.isSuperUser=exports.isPartnerUser=exports.isContractChoice=exports.incrementWithAudit=exports.handleFile=exports.getModuleInfo=exports.getEffectivePartnerId=exports.getDefaultBusinessIDInfo=exports.getCurrentUserNameFromCognitoEvent=exports.getCurrentUser=exports.getCompanySettings=exports.getBusinessesInfo=exports.getBelongsToPartnerId=exports.getAuditModel=exports.getAuditFilter=exports.getAccessRightsInfo=exports.findAll=exports.failure=exports.ensurePartnerScope=exports.enrichEventWithPartnerAccess=exports.defaultFilters=exports.decrementWithAudit=exports.createSort=exports.createIncludes=exports.createFilters=exports.createAccessHelpers=exports.contractStatuses=exports.contractChoices=exports.checkWriteAccess=exports.checkModule=exports.checkIsSuper=exports.bindAuditRequestForUser=exports.bindAuditRequest=exports.attachAudit=exports.assertCanWriteOwnBusiness=exports.assertCanWriteBookUnionOwn=exports.assertCanWriteBookBusiness=exports.accessRightsUtils=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__(859),_migrations=__webpack_require__(871),_defaultFilters=__webpack_require__(207),_accessContext=__webpack_require__(62),_accessGates=__webpack_require__(189),_accessScope=__webpack_require__(513),_accessWrites=__webpack_require__(165),_createAccessHelpers=__webpack_require__(539),_contract=__webpack_require__(269),_audit=__webpack_require__(179);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.checkIsSuper=_accessRightsUtils.checkIsSuper,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,exports.isSuperUser=_accessRightsUtils.isSuperUser,exports.isPartnerUser=_accessRightsUtils.isPartnerUser,exports.getBelongsToPartnerId=_accessRightsUtils.getBelongsToPartnerId,exports.getEffectivePartnerId=_accessRightsUtils.getEffectivePartnerId,exports.enrichEventWithPartnerAccess=_accessRightsUtils.enrichEventWithPartnerAccess,exports.getCompanySettings=_accessRightsUtils.getCompanySettings,exports.resolveAccess=_accessContext.resolveAccess,exports.ensurePartnerScope=_accessContext.ensurePartnerScope,exports.requireCrmAccess=_accessGates.requireCrmAccess,exports.requireTicketAccess=_accessGates.requireTicketAccess,exports.requireSuper=_accessGates.requireSuper,exports.scopeToOwnBusiness=_accessScope.scopeToOwnBusiness,exports.scopeToPartnerBook=_accessScope.scopeToPartnerBook,exports.scopeToBookUnionOwn=_accessScope.scopeToBookUnionOwn,exports.assertCanWriteOwnBusiness=_accessWrites.assertCanWriteOwnBusiness,exports.assertCanWriteBookBusiness=_accessWrites.assertCanWriteBookBusiness,exports.assertCanWriteBookUnionOwn=_accessWrites.assertCanWriteBookUnionOwn,exports.stampOwnBusinessId=_accessWrites.stampOwnBusinessId,exports.createAccessHelpers=_createAccessHelpers.createAccessHelpers,exports.attachAudit=_audit.attachAudit,exports.bindAuditRequest=_audit.bindAuditRequest,exports.bindAuditRequestForUser=_audit.bindAuditRequestForUser,exports.decrementWithAudit=_audit.decrementWithAudit,exports.getAuditFilter=_audit.getAuditFilter,exports.getAuditModel=_audit.getAuditModel,exports.incrementWithAudit=_audit.incrementWithAudit,exports.contractChoices=_contract.contractChoices,exports.contractStatuses=_contract.contractStatuses,exports.isContractChoice=_contract.isContractChoice})();var __webpack_export_target__=exports;for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__]=__webpack_exports__[__webpack_i__];__webpack_exports__.__esModule&&Object.defineProperty(__webpack_export_target__,"__esModule",{value:!0})
|
|
901
950
|
/******/})();
|
|
902
951
|
//# sourceMappingURL=main.js.map
|