piper-utils 1.1.69 → 1.1.70
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 +27 -17
- package/bin/main.js.map +1 -1
- package/package.json +1 -1
- package/src/database/dbUtils/partnerAccess/accessScope.js +128 -99
- package/src/database/dbUtils/partnerAccess/createAccessHelpers.js +3 -3
- package/src/database/dbUtils/queryStringUtils/createFilters.js +311 -311
- package/src/database/dbUtils/queryStringUtils/createFilters.test.js +682 -682
- package/src/requestResponse/requestResponse.test.js +58 -0
package/bin/main.js
CHANGED
|
@@ -516,46 +516,56 @@ let parsed;try{parsed=JSON.parse(query[qKey])}catch(e){return}if(parsed&&"object
|
|
|
516
516
|
* Scope to the union of partnerBusinessId + businessIds.
|
|
517
517
|
* Use for tickets — partner sees own tickets + portfolio merchants' tickets.
|
|
518
518
|
*
|
|
519
|
-
* global → deletes where.businessId
|
|
520
|
-
* partner →
|
|
521
|
-
*
|
|
519
|
+
* global → requested ? where.businessId = requested : deletes where.businessId
|
|
520
|
+
* partner → allowed = uniq([partnerBusinessId, ...businessIds]);
|
|
521
|
+
* requested ? allowed ∩ requested : where.businessId = allowed
|
|
522
|
+
* standard → allowed = businessIds;
|
|
523
|
+
* requested ? allowed ∩ requested : where.businessId = allowed
|
|
522
524
|
* (explicitly handled here because ticket routes may not call
|
|
523
525
|
* createFilters before scoping, e.g. delete/resolve handlers)
|
|
524
526
|
*
|
|
525
|
-
* @param {object} where
|
|
526
|
-
* @param {object} access
|
|
527
|
+
* @param {object} where - Sequelize WHERE clause to mutate.
|
|
528
|
+
* @param {object} access - Access object from resolveAccess.
|
|
529
|
+
* @param {string[]} [requested] - Explicit businessIds from the query string.
|
|
527
530
|
* @param {{ getPartnerById: Function }} deps
|
|
528
531
|
*/
|
|
529
|
-
async function scopeToBookUnionOwn(where,access,{getPartnerById}={}){if(!access)throw _errorCodes.errorList.unauthorized;if("global"===access.level)return void
|
|
532
|
+
async function scopeToBookUnionOwn(where,access,requested=[],{getPartnerById}={}){if(!access)throw _errorCodes.errorList.unauthorized;if("global"===access.level)return void(requested.length?where.businessId=requested:delete where.businessId);if("partner"===access.level){await(0,_accessContext.ensurePartnerScope)(access,{getPartnerById});const allowed=_lodash.default.uniq([access.partnerBusinessId,...access.businessIds||[]].filter(Boolean));return void(where.businessId=requested.length?_lodash.default.intersection(allowed,requested):allowed)}if("standard"===access.level){const allowed=access.businessIds||[];return void(where.businessId=requested.length?_lodash.default.intersection(allowed,requested):allowed)}}
|
|
530
533
|
/***/,exports.scopeToOwnBusiness=
|
|
534
|
+
// `requested` is the caller-supplied businessIds array (what the route extracts via
|
|
535
|
+
// getRequestedBusinessIds(event)). Empty array = no explicit filter (back-compat path).
|
|
536
|
+
// When non-empty it is intersected against the role's allowed set so a user can never
|
|
537
|
+
// widen their scope past what their role permits by passing a query-string businessId.
|
|
531
538
|
/**
|
|
532
539
|
* Scope a WHERE clause to the partner's own business (partnerBusinessId).
|
|
533
540
|
* Use for "mine" resources: deal, activity, application, template.
|
|
534
541
|
*
|
|
535
|
-
* global →
|
|
536
|
-
* partner →
|
|
542
|
+
* global → requested ? where.businessId = requested : deletes where.businessId
|
|
543
|
+
* partner → requested ? [partnerBusinessId] ∩ requested : where.businessId = partnerBusinessId
|
|
537
544
|
* throws partnerNotConfigured if partnerBusinessId is missing
|
|
538
545
|
* standard → no-op (createFilters already handled)
|
|
539
546
|
*
|
|
540
|
-
* @param {object} where
|
|
541
|
-
* @param {object} access
|
|
547
|
+
* @param {object} where - Sequelize WHERE clause to mutate.
|
|
548
|
+
* @param {object} access - Access object from resolveAccess.
|
|
549
|
+
* @param {string[]} [requested] - Explicit businessIds from the query string.
|
|
542
550
|
* @param {{ getPartnerById: Function }} deps
|
|
543
551
|
*/
|
|
544
|
-
async function scopeToOwnBusiness(where,access,{getPartnerById}={}){if(!access)throw _errorCodes.errorList.unauthorized;if("global"===access.level)return void
|
|
552
|
+
async function scopeToOwnBusiness(where,access,requested=[],{getPartnerById}={}){if(!access)throw _errorCodes.errorList.unauthorized;if("global"===access.level)return void(requested.length?where.businessId=requested:delete where.businessId);if("partner"===access.level){if(await(0,_accessContext.ensurePartnerScope)(access,{getPartnerById}),!access.partnerBusinessId)throw _errorCodes.errorList.partnerNotConfigured;return void(requested.length?where.businessId=_lodash.default.intersection([access.partnerBusinessId],requested):where.businessId=access.partnerBusinessId)}
|
|
545
553
|
// standard → no-op (createFilters already injected from JWT)
|
|
546
554
|
}
|
|
547
555
|
/**
|
|
548
556
|
* Scope a WHERE clause to the partner's portfolio (businessIds array).
|
|
549
557
|
* Use for "book" resources (future transaction lists, merchant inbox views).
|
|
550
558
|
*
|
|
551
|
-
* global → deletes where.businessId
|
|
552
|
-
* partner →
|
|
559
|
+
* global → requested ? where.businessId = requested : deletes where.businessId
|
|
560
|
+
* partner → requested ? businessIds ∩ requested : where.businessId = businessIds[]
|
|
561
|
+
* (own business is intentionally excluded — book is portfolio only)
|
|
553
562
|
* standard → no-op
|
|
554
563
|
*
|
|
555
|
-
* @param {object} where
|
|
556
|
-
* @param {object} access
|
|
564
|
+
* @param {object} where - Sequelize WHERE clause to mutate.
|
|
565
|
+
* @param {object} access - Access object from resolveAccess.
|
|
566
|
+
* @param {string[]} [requested] - Explicit businessIds from the query string.
|
|
557
567
|
* @param {{ getPartnerById: Function }} deps
|
|
558
|
-
*/,exports.scopeToPartnerBook=async function scopeToPartnerBook(where,access,{getPartnerById}={}){if(!access)throw _errorCodes.errorList.unauthorized;if("global"===access.level)return void
|
|
568
|
+
*/,exports.scopeToPartnerBook=async function scopeToPartnerBook(where,access,requested=[],{getPartnerById}={}){if(!access)throw _errorCodes.errorList.unauthorized;if("global"===access.level)return void(requested.length?where.businessId=requested:delete where.businessId);if("partner"===access.level){await(0,_accessContext.ensurePartnerScope)(access,{getPartnerById});const allowed=access.businessIds||[];return void(where.businessId=requested.length?_lodash.default.intersection(allowed,requested):allowed)}
|
|
559
569
|
// standard → no-op
|
|
560
570
|
};var _lodash=function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}(__webpack_require__(825)),_accessContext=__webpack_require__(62),_errorCodes=__webpack_require__(953)},
|
|
561
571
|
/***/515(module){module.exports=require("@aws-sdk/lib-dynamodb");
|
|
@@ -577,7 +587,7 @@ async function scopeToOwnBusiness(where,access,{getPartnerById}={}){if(!access)t
|
|
|
577
587
|
* @param {{ getPartnerById: Function }} deps
|
|
578
588
|
* @returns {object} Pre-bound helpers.
|
|
579
589
|
*/
|
|
580
|
-
function createAccessHelpers({getPartnerById}){const deps={getPartnerById};return{ensurePartnerScope:access=>(0,_accessContext.ensurePartnerScope)(access,deps),scopeToOwnBusiness:(where,access)=>(0,_accessScope.scopeToOwnBusiness)(where,access,deps),scopeToPartnerBook:(where,access)=>(0,_accessScope.scopeToPartnerBook)(where,access,deps),scopeToBookUnionOwn:(where,access)=>(0,_accessScope.scopeToBookUnionOwn)(where,access,deps),assertCanWriteOwnBusiness:(access,businessId)=>(0,_accessWrites.assertCanWriteOwnBusiness)(access,businessId,deps),assertCanWriteBookBusiness:(access,businessId)=>(0,_accessWrites.assertCanWriteBookBusiness)(access,businessId,deps),assertCanWriteBookUnionOwn:(access,businessId)=>(0,_accessWrites.assertCanWriteBookUnionOwn)(access,businessId,deps),stampOwnBusinessId:(access,body)=>(0,_accessWrites.stampOwnBusinessId)(access,body,deps)}}
|
|
590
|
+
function createAccessHelpers({getPartnerById}){const deps={getPartnerById};return{ensurePartnerScope:access=>(0,_accessContext.ensurePartnerScope)(access,deps),scopeToOwnBusiness:(where,access,requested)=>(0,_accessScope.scopeToOwnBusiness)(where,access,requested,deps),scopeToPartnerBook:(where,access,requested)=>(0,_accessScope.scopeToPartnerBook)(where,access,requested,deps),scopeToBookUnionOwn:(where,access,requested)=>(0,_accessScope.scopeToBookUnionOwn)(where,access,requested,deps),assertCanWriteOwnBusiness:(access,businessId)=>(0,_accessWrites.assertCanWriteOwnBusiness)(access,businessId,deps),assertCanWriteBookBusiness:(access,businessId)=>(0,_accessWrites.assertCanWriteBookBusiness)(access,businessId,deps),assertCanWriteBookUnionOwn:(access,businessId)=>(0,_accessWrites.assertCanWriteBookUnionOwn)(access,businessId,deps),stampOwnBusinessId:(access,body)=>(0,_accessWrites.stampOwnBusinessId)(access,body,deps)}}
|
|
581
591
|
/***/;var _accessContext=__webpack_require__(62),_accessScope=__webpack_require__(513),_accessWrites=__webpack_require__(165)},
|
|
582
592
|
/***/564(module){module.exports=require("bluebird");
|
|
583
593
|
/***/},
|