piper-utils 1.1.70 → 1.1.72
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 +73 -3
- package/bin/main.js.map +1 -1
- package/nul +82 -0
- package/package.json +1 -1
- 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/database/dbUtils/queryStringUtils/getPagination.js +29 -0
- package/src/database/dbUtils/queryStringUtils/getPagination.test.js +83 -0
- package/src/eventManager/handleFile.js +129 -115
- package/src/eventManager/handleFile.test.js +463 -460
- package/src/index.js +8 -0
package/nul
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
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.getRequestedBusinessIds = exports.getPagination = 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;
|
|
7
|
+
var _handleFile = require("./eventManager/handleFile.js");
|
|
8
|
+
var _watchBucket = require("./eventManager/watchBucket.js");
|
|
9
|
+
var _publishEvents = require("./eventManager/publishEvents.js");
|
|
10
|
+
var _createIncludes = require("./database/dbUtils/queryStringUtils/createIncludes.js");
|
|
11
|
+
var _createFilters = require("./database/dbUtils/queryStringUtils/createFilters.js");
|
|
12
|
+
var _createSort = require("./database/dbUtils/queryStringUtils/createSort.js");
|
|
13
|
+
var _findAll = require("./database/dbUtils/queryStringUtils/findAll.js");
|
|
14
|
+
var _accessRightsUtils = require("./database/dbUtils/queryStringUtils/accessRightsUtils.js");
|
|
15
|
+
var _requestResponse = require("./requestResponse/requestResponse.js");
|
|
16
|
+
var _migrations = require("./database/dbSetup/migrations.js");
|
|
17
|
+
var _defaultFilters = require("./database/dbUtils/queryStringUtils/defaultFilters.js");
|
|
18
|
+
var _getPagination = require("./database/dbUtils/queryStringUtils/getPagination.js");
|
|
19
|
+
var _accessContext = require("./database/dbUtils/partnerAccess/accessContext.js");
|
|
20
|
+
var _accessGates = require("./database/dbUtils/partnerAccess/accessGates.js");
|
|
21
|
+
var _accessScope = require("./database/dbUtils/partnerAccess/accessScope.js");
|
|
22
|
+
var _accessWrites = require("./database/dbUtils/partnerAccess/accessWrites.js");
|
|
23
|
+
var _createAccessHelpers = require("./database/dbUtils/partnerAccess/createAccessHelpers.js");
|
|
24
|
+
var _contract = require("./contract/contract.js");
|
|
25
|
+
var _audit = require("./audit/audit.js");
|
|
26
|
+
const handleFile = exports.handleFile = _handleFile.handleFile;
|
|
27
|
+
const watchBucket = exports.watchBucket = _watchBucket.watchBucket;
|
|
28
|
+
const publishEvents = exports.publishEvents = _publishEvents.publishEvents;
|
|
29
|
+
const createFilters = exports.createFilters = _createFilters.createFilters;
|
|
30
|
+
const createIncludes = exports.createIncludes = _createIncludes.createIncludes;
|
|
31
|
+
const createSort = exports.createSort = _createSort.createSort;
|
|
32
|
+
const findAll = exports.findAll = _findAll.findAll;
|
|
33
|
+
const getPagination = exports.getPagination = _getPagination.getPagination;
|
|
34
|
+
const getRequestedBusinessIds = exports.getRequestedBusinessIds = _accessRightsUtils.getRequestedBusinessIds;
|
|
35
|
+
const checkModule = exports.checkModule = _accessRightsUtils.checkModule;
|
|
36
|
+
const checkIsSuper = exports.checkIsSuper = _accessRightsUtils.checkIsSuper;
|
|
37
|
+
const getAccessRightsInfo = exports.getAccessRightsInfo = _accessRightsUtils.getAccessRightsInfo;
|
|
38
|
+
const getDefaultBusinessIDInfo = exports.getDefaultBusinessIDInfo = _accessRightsUtils.getDefaultBusinessIDInfo;
|
|
39
|
+
const getModuleInfo = exports.getModuleInfo = _accessRightsUtils.getModuleInfo;
|
|
40
|
+
const failure = exports.failure = _requestResponse.failure;
|
|
41
|
+
const success = exports.success = _requestResponse.success;
|
|
42
|
+
const runMigrations = exports.runMigrations = _migrations.runMigrations;
|
|
43
|
+
const getCurrentUser = exports.getCurrentUser = _requestResponse.getCurrentUser;
|
|
44
|
+
const successHtml = exports.successHtml = _requestResponse.successHtml;
|
|
45
|
+
const getCurrentUserNameFromCognitoEvent = exports.getCurrentUserNameFromCognitoEvent = _requestResponse.getCurrentUserNameFromCognitoEvent;
|
|
46
|
+
const defaultFilters = exports.defaultFilters = _defaultFilters.defaultFilters;
|
|
47
|
+
const accessRightsUtils = exports.accessRightsUtils = _accessRightsUtils.accessRightsUtils;
|
|
48
|
+
const parseBody = exports.parseBody = _requestResponse.parseBody;
|
|
49
|
+
const parseEvent = exports.parseEvent = _requestResponse.parseEvent;
|
|
50
|
+
const getBusinessesInfo = exports.getBusinessesInfo = _accessRightsUtils.getBusinessesInfo;
|
|
51
|
+
const userDefaultBid = exports.userDefaultBid = _accessRightsUtils.userDefaultBid;
|
|
52
|
+
const checkWriteAccess = exports.checkWriteAccess = _accessRightsUtils.checkWriteAccess;
|
|
53
|
+
const isSystemUser = exports.isSystemUser = _accessRightsUtils.isSystemUser;
|
|
54
|
+
const isSuperUser = exports.isSuperUser = _accessRightsUtils.isSuperUser;
|
|
55
|
+
const isPartnerUser = exports.isPartnerUser = _accessRightsUtils.isPartnerUser;
|
|
56
|
+
const getBelongsToPartnerId = exports.getBelongsToPartnerId = _accessRightsUtils.getBelongsToPartnerId;
|
|
57
|
+
const getEffectivePartnerId = exports.getEffectivePartnerId = _accessRightsUtils.getEffectivePartnerId;
|
|
58
|
+
const enrichEventWithPartnerAccess = exports.enrichEventWithPartnerAccess = _accessRightsUtils.enrichEventWithPartnerAccess;
|
|
59
|
+
const getCompanySettings = exports.getCompanySettings = _accessRightsUtils.getCompanySettings;
|
|
60
|
+
const resolveAccess = exports.resolveAccess = _accessContext.resolveAccess;
|
|
61
|
+
const ensurePartnerScope = exports.ensurePartnerScope = _accessContext.ensurePartnerScope;
|
|
62
|
+
const requireCrmAccess = exports.requireCrmAccess = _accessGates.requireCrmAccess;
|
|
63
|
+
const requireTicketAccess = exports.requireTicketAccess = _accessGates.requireTicketAccess;
|
|
64
|
+
const requireSuper = exports.requireSuper = _accessGates.requireSuper;
|
|
65
|
+
const scopeToOwnBusiness = exports.scopeToOwnBusiness = _accessScope.scopeToOwnBusiness;
|
|
66
|
+
const scopeToPartnerBook = exports.scopeToPartnerBook = _accessScope.scopeToPartnerBook;
|
|
67
|
+
const scopeToBookUnionOwn = exports.scopeToBookUnionOwn = _accessScope.scopeToBookUnionOwn;
|
|
68
|
+
const assertCanWriteOwnBusiness = exports.assertCanWriteOwnBusiness = _accessWrites.assertCanWriteOwnBusiness;
|
|
69
|
+
const assertCanWriteBookBusiness = exports.assertCanWriteBookBusiness = _accessWrites.assertCanWriteBookBusiness;
|
|
70
|
+
const assertCanWriteBookUnionOwn = exports.assertCanWriteBookUnionOwn = _accessWrites.assertCanWriteBookUnionOwn;
|
|
71
|
+
const stampOwnBusinessId = exports.stampOwnBusinessId = _accessWrites.stampOwnBusinessId;
|
|
72
|
+
const createAccessHelpers = exports.createAccessHelpers = _createAccessHelpers.createAccessHelpers;
|
|
73
|
+
const attachAudit = exports.attachAudit = _audit.attachAudit;
|
|
74
|
+
const bindAuditRequest = exports.bindAuditRequest = _audit.bindAuditRequest;
|
|
75
|
+
const bindAuditRequestForUser = exports.bindAuditRequestForUser = _audit.bindAuditRequestForUser;
|
|
76
|
+
const decrementWithAudit = exports.decrementWithAudit = _audit.decrementWithAudit;
|
|
77
|
+
const getAuditFilter = exports.getAuditFilter = _audit.getAuditFilter;
|
|
78
|
+
const getAuditModel = exports.getAuditModel = _audit.getAuditModel;
|
|
79
|
+
const incrementWithAudit = exports.incrementWithAudit = _audit.incrementWithAudit;
|
|
80
|
+
const contractChoices = exports.contractChoices = _contract.contractChoices;
|
|
81
|
+
const contractStatuses = exports.contractStatuses = _contract.contractStatuses;
|
|
82
|
+
const isContractChoice = exports.isContractChoice = _contract.isContractChoice;
|
package/package.json
CHANGED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Financing contract constants shared by the ERP (piper) and the payment
|
|
3
|
+
* gateway (piper-gateway). Both sides put these strings on the wire — the ERP
|
|
4
|
+
* writes them onto the order and the prepare payload, the gateway reads them
|
|
5
|
+
* back off the checkout page and echoes them home on the webhook — so they must
|
|
6
|
+
* agree exactly. Keeping them here is what stops a 'down' / 'Down' drift from
|
|
7
|
+
* becoming a silent mischarge.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/*
|
|
11
|
+
* What the customer chose on the signing page.
|
|
12
|
+
* - full: pay the whole order total now; no financing, so no contract to sign
|
|
13
|
+
* - down: pay the down payment now and sign the financing contract for the rest
|
|
14
|
+
*/
|
|
15
|
+
export const contractChoices = {
|
|
16
|
+
full: 'full',
|
|
17
|
+
down: 'down'
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/*
|
|
21
|
+
* Lifecycle of the contract attached to an order.
|
|
22
|
+
* - draft: order is still an estimate; nothing rendered yet
|
|
23
|
+
* - sent: contract body frozen and hashed, link is out with the customer
|
|
24
|
+
* - signed: customer consented and signed; signature + audit trail persisted
|
|
25
|
+
*/
|
|
26
|
+
export const contractStatuses = {
|
|
27
|
+
draft: 'Draft',
|
|
28
|
+
sent: 'Sent',
|
|
29
|
+
signed: 'Signed'
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/*
|
|
33
|
+
* True when value is a choice the signing page is allowed to send. The gateway
|
|
34
|
+
* gates on this before selecting which of the two server-side amounts to charge,
|
|
35
|
+
* so an unrecognized choice is a 400 rather than a wrong amount.
|
|
36
|
+
*
|
|
37
|
+
* @param {string} value
|
|
38
|
+
* @returns {boolean}
|
|
39
|
+
*/
|
|
40
|
+
export function isContractChoice(value) {
|
|
41
|
+
return Object.values(contractChoices).includes(value);
|
|
42
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { contractChoices, contractStatuses, isContractChoice } from './contract.js';
|
|
2
|
+
|
|
3
|
+
describe('contract constants', () => {
|
|
4
|
+
it('should expose the two payment choices the signing page can send', () => {
|
|
5
|
+
expect(contractChoices.full).toBe('full');
|
|
6
|
+
expect(contractChoices.down).toBe('down');
|
|
7
|
+
expect(Object.keys(contractChoices).length).toBe(2);
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it('should expose the contract lifecycle statuses', () => {
|
|
11
|
+
expect(contractStatuses.draft).toBe('Draft');
|
|
12
|
+
expect(contractStatuses.sent).toBe('Sent');
|
|
13
|
+
expect(contractStatuses.signed).toBe('Signed');
|
|
14
|
+
expect(Object.keys(contractStatuses).length).toBe(3);
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe('isContractChoice', () => {
|
|
19
|
+
it('should accept every known choice', () => {
|
|
20
|
+
expect(isContractChoice(contractChoices.full)).toBe(true);
|
|
21
|
+
expect(isContractChoice(contractChoices.down)).toBe(true);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('should reject a case-mismatched choice so a drift becomes a 400 not a mischarge', () => {
|
|
25
|
+
expect(isContractChoice('Down')).toBe(false);
|
|
26
|
+
expect(isContractChoice('FULL')).toBe(false);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('should reject unknown, empty and non-string values', () => {
|
|
30
|
+
expect(isContractChoice('partial')).toBe(false);
|
|
31
|
+
expect(isContractChoice('')).toBe(false);
|
|
32
|
+
expect(isContractChoice(null)).toBe(false);
|
|
33
|
+
expect(isContractChoice(undefined)).toBe(false);
|
|
34
|
+
expect(isContractChoice(0)).toBe(false);
|
|
35
|
+
});
|
|
36
|
+
});
|