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/package.json CHANGED
@@ -1,62 +1,62 @@
1
- {
2
- "name": "piper-utils",
3
- "version": "1.1.70",
4
- "description": "Utility library for Piper",
5
- "main": "bin/main.js",
6
- "scripts": {
7
- "test": "cross-env BUILD_ENV='test' nyc jasmine JASMINE_CONFIG_PATH=jasmine.json",
8
- "itest": "cross-env BUILD_ENV='development' nyc jasmine JASMINE_CONFIG_PATH=jasmine.json",
9
- "build": "webpack --config webpack.config.js",
10
- "build-prod": "cross-env BUILD_ENV='production' webpack --config webpack.config.js"
11
- },
12
- "repository": {
13
- "type": "git"
14
- },
15
- "author": "Kevin Batchelor",
16
- "license": "PVT",
17
- "devDependencies": {
18
- "@babel/cli": "7.11.6",
19
- "@babel/core": "7.23.2",
20
- "@babel/preset-env": "^7.29.0",
21
- "@babel/register": "^7.28.6",
22
- "@babel/runtime": "8.0.0-alpha.17",
23
- "aws-sdk-client-mock": "^3.0.1",
24
- "babel-loader": "9.1.3",
25
- "babel-preset-env": "1.7.0",
26
- "cross-env": "7.0.3",
27
- "jasmine": "5.1.0",
28
- "nyc": "14.1.1",
29
- "terser-webpack-plugin": "^5.3.10",
30
- "webpack": "5.104.1",
31
- "webpack-cli": "^5.1.4",
32
- "webpack-node-externals": "3.0.0"
33
- },
34
- "dependencies": {
35
- "@aws-sdk/client-dynamodb": "^3.507.0",
36
- "@aws-sdk/client-s3": "^3.507.0",
37
- "@aws-sdk/client-sns": "^3.507.0",
38
- "@aws-sdk/lib-dynamodb": "^3.507.0",
39
- "babel-runtime": "6.26.0"
40
- },
41
- "peerDependencies": {
42
- "bluebird": ">=3.7.0",
43
- "dayjs": "^1.11.13",
44
- "lodash": ">=4.17.15",
45
- "sequelize": ">=6.6.2",
46
- "umzug": ">=3.2.1"
47
- },
48
- "nyc": {
49
- "require": [
50
- "@babel/register"
51
- ],
52
- "reporter": [
53
- "lcov",
54
- "text-summary"
55
- ],
56
- "check-coverage": true,
57
- "branches": 70,
58
- "lines": 80,
59
- "functions": 70,
60
- "statements": 85
61
- }
62
- }
1
+ {
2
+ "name": "piper-utils",
3
+ "version": "1.1.71",
4
+ "description": "Utility library for Piper",
5
+ "main": "bin/main.js",
6
+ "scripts": {
7
+ "test": "cross-env BUILD_ENV='test' nyc jasmine JASMINE_CONFIG_PATH=jasmine.json",
8
+ "itest": "cross-env BUILD_ENV='development' nyc jasmine JASMINE_CONFIG_PATH=jasmine.json",
9
+ "build": "webpack --config webpack.config.js",
10
+ "build-prod": "cross-env BUILD_ENV='production' webpack --config webpack.config.js"
11
+ },
12
+ "repository": {
13
+ "type": "git"
14
+ },
15
+ "author": "Kevin Batchelor",
16
+ "license": "PVT",
17
+ "devDependencies": {
18
+ "@babel/cli": "7.11.6",
19
+ "@babel/core": "7.23.2",
20
+ "@babel/preset-env": "^7.29.0",
21
+ "@babel/register": "^7.28.6",
22
+ "@babel/runtime": "8.0.0-alpha.17",
23
+ "aws-sdk-client-mock": "^3.0.1",
24
+ "babel-loader": "9.1.3",
25
+ "babel-preset-env": "1.7.0",
26
+ "cross-env": "7.0.3",
27
+ "jasmine": "5.1.0",
28
+ "nyc": "14.1.1",
29
+ "terser-webpack-plugin": "^5.3.10",
30
+ "webpack": "5.104.1",
31
+ "webpack-cli": "^5.1.4",
32
+ "webpack-node-externals": "3.0.0"
33
+ },
34
+ "dependencies": {
35
+ "@aws-sdk/client-dynamodb": "^3.507.0",
36
+ "@aws-sdk/client-s3": "^3.507.0",
37
+ "@aws-sdk/client-sns": "^3.507.0",
38
+ "@aws-sdk/lib-dynamodb": "^3.507.0",
39
+ "babel-runtime": "6.26.0"
40
+ },
41
+ "peerDependencies": {
42
+ "bluebird": ">=3.7.0",
43
+ "dayjs": "^1.11.13",
44
+ "lodash": ">=4.17.15",
45
+ "sequelize": ">=6.6.2",
46
+ "umzug": ">=3.2.1"
47
+ },
48
+ "nyc": {
49
+ "require": [
50
+ "@babel/register"
51
+ ],
52
+ "reporter": [
53
+ "lcov",
54
+ "text-summary"
55
+ ],
56
+ "check-coverage": true,
57
+ "branches": 70,
58
+ "lines": 80,
59
+ "functions": 70,
60
+ "statements": 85
61
+ }
62
+ }
@@ -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
+ });