@rebilly/instruments 4.5.0 → 4.6.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/.babelrc +24 -26
- package/CHANGELOG.md +7 -0
- package/dist/index.js +8 -8
- package/dist/index.min.js +8 -8
- package/package.json +14 -3
- package/project.json +9 -0
- package/rollup.config.mjs +21 -26
- package/src/data/options-schema/index.js +94 -78
- package/src/data/options-schema/schemas/options-schema.js +419 -411
- package/src/events/base-event.js +34 -34
- package/src/events/events.spec.js +6 -6
- package/src/events/index.js +5 -5
- package/src/functions/destroy.js +19 -19
- package/src/functions/destroy.spec.js +41 -41
- package/src/functions/mount/fetch-data.js +200 -193
- package/src/functions/mount/fetch-data.spec.js +287 -285
- package/src/functions/mount/get-lead-source-data.js +31 -31
- package/src/functions/mount/get-lead-source-data.spec.js +19 -19
- package/src/functions/mount/index.js +73 -65
- package/src/functions/mount/mount.spec.js +77 -66
- package/src/functions/mount/setup-element.js +23 -23
- package/src/functions/mount/setup-framepay-theme.js +86 -68
- package/src/functions/mount/setup-framepay.js +9 -5
- package/src/functions/mount/setup-i18n.js +15 -15
- package/src/functions/mount/setup-options.js +74 -74
- package/src/functions/mount/setup-options.spec.js +323 -287
- package/src/functions/mount/setup-storefront.js +15 -20
- package/src/functions/mount/setup-styles-vars.js +19 -22
- package/src/functions/mount/setup-user-flow.js +51 -47
- package/src/functions/on.js +5 -5
- package/src/functions/on.spec.js +60 -51
- package/src/functions/purchase.js +151 -146
- package/src/functions/purchase.spec.js +59 -56
- package/src/functions/setup.js +53 -53
- package/src/functions/setup.spec.js +88 -75
- package/src/functions/show.js +13 -14
- package/src/functions/show.spec.js +53 -53
- package/src/functions/update.js +30 -28
- package/src/functions/update.spec.js +94 -93
- package/src/i18n/en.json +32 -32
- package/src/i18n/es.json +29 -29
- package/src/i18n/i18n.spec.js +18 -18
- package/src/i18n/index.js +48 -48
- package/src/instance.js +36 -36
- package/src/instance.spec.js +29 -27
- package/src/loader/index.js +95 -70
- package/src/loader/loader.spec.js +63 -63
- package/src/state/iframes.js +21 -21
- package/src/state/index.js +56 -54
- package/src/storefront/account-and-website.js +10 -8
- package/src/storefront/account-and-website.spec.js +55 -55
- package/src/storefront/deposit-requests.js +6 -6
- package/src/storefront/fetch-plans-from-addons-bumpOffer.js +21 -19
- package/src/storefront/fetch-products-from-plans.js +52 -51
- package/src/storefront/fetch-products-from-plans.spec.js +90 -87
- package/src/storefront/index.js +56 -49
- package/src/storefront/invoices.js +15 -15
- package/src/storefront/invoices.spec.js +69 -65
- package/src/storefront/models/account-model.js +29 -32
- package/src/storefront/models/base-model.js +6 -9
- package/src/storefront/models/deposit-request-model.js +22 -13
- package/src/storefront/models/invoice-model.js +16 -16
- package/src/storefront/models/payment-metadata.js +4 -4
- package/src/storefront/models/plan-model.js +73 -64
- package/src/storefront/models/ready-to-pay-model.js +59 -59
- package/src/storefront/models/summary-model.js +43 -46
- package/src/storefront/models/transaction-model.js +11 -14
- package/src/storefront/payment-instruments.js +38 -35
- package/src/storefront/payment-instruments.spec.js +81 -62
- package/src/storefront/purchase.js +50 -44
- package/src/storefront/purchase.spec.js +40 -40
- package/src/storefront/ready-to-pay.js +75 -77
- package/src/storefront/ready-to-pay.spec.js +59 -54
- package/src/storefront/storefront.spec.js +9 -9
- package/src/storefront/summary.js +93 -67
- package/src/storefront/summary.spec.js +108 -106
- package/src/storefront/transactions.js +6 -6
- package/src/style/base/default-theme.js +928 -923
- package/src/style/base/theme.js +21 -21
- package/src/style/base/theme.spec.js +13 -13
- package/src/style/index.js +3 -3
- package/src/style/utils/border.js +40 -27
- package/src/style/utils/color-values.js +18 -18
- package/src/style/utils/minifyCss.js +6 -6
- package/src/utils/add-dom-element.js +14 -14
- package/src/utils/format-currency.js +6 -5
- package/src/utils/has-valid-css-selector.js +2 -2
- package/src/utils/index.js +6 -6
- package/src/utils/is-dom-element.js +1 -1
- package/src/utils/process-property-as-dom-element.js +22 -22
- package/src/utils/quantity.js +26 -28
- package/src/utils/sleep.js +3 -1
- package/src/views/amount-selector.js +37 -36
- package/src/views/common/iframe/base-iframe.js +53 -52
- package/src/views/common/iframe/events/change-iframe-src-handler.js +5 -5
- package/src/views/common/iframe/events/dispatch-event-handler.js +4 -4
- package/src/views/common/iframe/events/resize-component-handler.js +8 -8
- package/src/views/common/iframe/events/show-error-handler.js +2 -2
- package/src/views/common/iframe/events/stop-loader-handler.js +8 -8
- package/src/views/common/iframe/events/update-addons-handler.js +20 -13
- package/src/views/common/iframe/events/update-coupons-handler.js +9 -9
- package/src/views/common/iframe/events/update-items-handler.js +26 -22
- package/src/views/common/iframe/modal-iframe.js +67 -56
- package/src/views/common/iframe/view-iframe.js +11 -11
- package/src/views/common/render-utilities.js +2 -2
- package/src/views/confirmation.js +33 -30
- package/src/views/errors.js +89 -79
- package/src/views/form.js +41 -37
- package/src/views/method-selector/express-methods.js +46 -46
- package/src/views/method-selector/generate-digital-wallet.js +46 -45
- package/src/views/method-selector/generate-digital-wallet.spec.js +104 -102
- package/src/views/method-selector/generate-framepay-config.js +53 -51
- package/src/views/method-selector/generate-framepay-config.spec.js +197 -173
- package/src/views/method-selector/get-method-data.js +5 -6
- package/src/views/method-selector/get-payment-methods.js +18 -16
- package/src/views/method-selector/get-payment-methods.spec.js +29 -27
- package/src/views/method-selector/index.js +154 -139
- package/src/views/method-selector/method-selector.spec.js +13 -13
- package/src/views/method-selector/mount-bump-offer.js +65 -49
- package/src/views/method-selector/mount-express-methods.js +89 -85
- package/src/views/modal.js +74 -67
- package/src/views/result.js +14 -14
- package/src/views/summary.js +25 -26
- package/tests/async-utilities.js +13 -13
- package/tests/mocks/framepay-mock.js +9 -8
- package/tests/mocks/rebilly-api-mock.js +5 -3
- package/tests/mocks/rebilly-instruments-mock.js +121 -117
- package/tests/mocks/storefront-api-mock.js +55 -48
- package/tests/mocks/storefront-mock.js +10 -14
- package/tests/msw/server.js +6 -6
- package/tests/setup-test.js +14 -16
- package/vitest.config.js +14 -14
- package/.eslintrc.js +0 -34
- package/.prettierrc.js +0 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rebilly/instruments",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.6.0",
|
|
4
4
|
"author": "Rebilly",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -8,17 +8,26 @@
|
|
|
8
8
|
"scripts": {
|
|
9
9
|
"build": "yarn rollup -c --environment NODE_ENV:production",
|
|
10
10
|
"dev": "yarn rollup -c --watch --environment NODE_ENV:development",
|
|
11
|
+
"format": "prettier --write . --config ../.prettierrc --ignore-path ../.prettierignore",
|
|
12
|
+
"format:check": "prettier --check . --config ../.prettierrc --ignore-path ../.prettierignore",
|
|
13
|
+
"lint": "yarn format && eslint --ext .ts,.js,.vue --ignore-path ../.eslintignore --config ../.eslintrc.js --fix src",
|
|
14
|
+
"lint:no-fix": "yarn lint --no-fix",
|
|
11
15
|
"test:unit": "vitest run",
|
|
12
16
|
"test:unit:watch": "vitest"
|
|
13
17
|
},
|
|
14
18
|
"dependencies": {
|
|
15
19
|
"@babel/cli": "^7.21.5",
|
|
16
20
|
"@babel/core": "^7.22.9",
|
|
17
|
-
"@babel/preset-env": "^7.22.
|
|
21
|
+
"@babel/preset-env": "^7.22.14",
|
|
18
22
|
"@rebilly/api-metadata": "*",
|
|
19
23
|
"@rebilly/risk-data-collector": "*",
|
|
20
24
|
"@vue/reactivity": "^3.2.39",
|
|
21
25
|
"ajv": "^8.12.0",
|
|
26
|
+
"eslint": "^8.38.0",
|
|
27
|
+
"eslint-config-prettier": "^8.8.0",
|
|
28
|
+
"eslint-plugin-no-only-tests": "^2.6.0",
|
|
29
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
30
|
+
"eslint-plugin-vue": "^9.12.0",
|
|
22
31
|
"jwt-decode": "^3.1.2",
|
|
23
32
|
"lodash.camelcase": "^4.3.0",
|
|
24
33
|
"lodash.clonedeep": "^4.5.0",
|
|
@@ -26,8 +35,10 @@
|
|
|
26
35
|
"lodash.kebabcase": "^4.1.1",
|
|
27
36
|
"lodash.merge": "^4.6.2",
|
|
28
37
|
"popostmate": "2.0.0",
|
|
38
|
+
"prettier": "^2.8.8",
|
|
29
39
|
"rebilly-js-sdk": "*",
|
|
30
|
-
"values.js": "^2.0.0"
|
|
40
|
+
"values.js": "^2.0.0",
|
|
41
|
+
"vue-eslint-parser": "^9.3.1"
|
|
31
42
|
},
|
|
32
43
|
"devDependencies": {
|
|
33
44
|
"@rollup/plugin-babel": "^6.0.3",
|
package/project.json
CHANGED
package/rollup.config.mjs
CHANGED
|
@@ -6,18 +6,18 @@ import replace from '@rollup/plugin-replace';
|
|
|
6
6
|
import nodePolyfills from 'rollup-plugin-polyfill-node';
|
|
7
7
|
import ignore from 'rollup-plugin-ignore';
|
|
8
8
|
import versionInjector from 'rollup-plugin-version-injector';
|
|
9
|
-
import { builtinModules } from 'module'
|
|
9
|
+
import { builtinModules } from 'module';
|
|
10
10
|
import { terser } from 'rollup-plugin-terser';
|
|
11
11
|
|
|
12
|
-
const isDevMode =
|
|
12
|
+
const isDevMode = process.env.NODE_ENV === 'development';
|
|
13
13
|
|
|
14
14
|
const buildOptions = () => {
|
|
15
15
|
const options = [
|
|
16
16
|
// Locates a module in the project's node_modules
|
|
17
|
-
resolve({
|
|
18
|
-
extensions: [
|
|
17
|
+
resolve({
|
|
18
|
+
extensions: ['.mjs', '.js', '.jsx', '.json'],
|
|
19
19
|
preferBuiltins: true,
|
|
20
|
-
mainFields: ['browser', 'jsnext:main', 'module', 'main']
|
|
20
|
+
mainFields: ['browser', 'jsnext:main', 'module', 'main'],
|
|
21
21
|
}),
|
|
22
22
|
// Converts CommonJS to ES6 modules
|
|
23
23
|
commonjs(),
|
|
@@ -29,7 +29,7 @@ const buildOptions = () => {
|
|
|
29
29
|
// Replace values at bundle time
|
|
30
30
|
replace({
|
|
31
31
|
preventAssignment: true,
|
|
32
|
-
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
|
|
32
|
+
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
|
|
33
33
|
}),
|
|
34
34
|
// Allows the use of named imports in addition to the default import on node modules
|
|
35
35
|
nodePolyfills(),
|
|
@@ -37,20 +37,21 @@ const buildOptions = () => {
|
|
|
37
37
|
babel({
|
|
38
38
|
exclude: 'node_modules/**',
|
|
39
39
|
babelHelpers: 'runtime',
|
|
40
|
-
skipPreflightCheck: true
|
|
40
|
+
skipPreflightCheck: true,
|
|
41
41
|
}),
|
|
42
42
|
// Converts .json files to ES6 modules
|
|
43
43
|
json(),
|
|
44
|
-
]
|
|
44
|
+
];
|
|
45
45
|
if (!isDevMode) {
|
|
46
46
|
options.push(
|
|
47
47
|
// Inject version from package.json (RebillyInstruments.version)
|
|
48
48
|
versionInjector(),
|
|
49
49
|
// Minify and reduce bundle file sizes
|
|
50
|
-
terser()
|
|
50
|
+
terser(),
|
|
51
|
+
);
|
|
51
52
|
}
|
|
52
53
|
return options;
|
|
53
|
-
}
|
|
54
|
+
};
|
|
54
55
|
|
|
55
56
|
const buildOutput = () => {
|
|
56
57
|
const output = [
|
|
@@ -59,26 +60,20 @@ const buildOutput = () => {
|
|
|
59
60
|
format: 'es',
|
|
60
61
|
sourcemap: isDevMode ? 'inline' : false,
|
|
61
62
|
},
|
|
62
|
-
]
|
|
63
|
+
];
|
|
63
64
|
if (!isDevMode) {
|
|
64
|
-
output.push(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
},
|
|
71
|
-
)
|
|
65
|
+
output.push({
|
|
66
|
+
file: 'dist/index.min.js',
|
|
67
|
+
format: 'iife',
|
|
68
|
+
name: 'RebillyInstruments',
|
|
69
|
+
exports: 'default',
|
|
70
|
+
});
|
|
72
71
|
}
|
|
73
72
|
return output;
|
|
74
|
-
}
|
|
73
|
+
};
|
|
75
74
|
|
|
76
75
|
export default {
|
|
77
76
|
input: 'src/index.js',
|
|
78
|
-
output: [
|
|
79
|
-
|
|
80
|
-
],
|
|
81
|
-
plugins: [
|
|
82
|
-
...buildOptions(),
|
|
83
|
-
],
|
|
77
|
+
output: [...buildOutput()],
|
|
78
|
+
plugins: [...buildOptions()],
|
|
84
79
|
};
|
|
@@ -1,96 +1,112 @@
|
|
|
1
|
-
import schema from './schemas/options-schema';
|
|
2
1
|
import AJV from 'ajv/dist/2019';
|
|
2
|
+
import schema from './schemas/options-schema';
|
|
3
3
|
|
|
4
4
|
export class RebillyInstrumentsConfigError extends Error {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = 'Rebilly Instruments Configuration Error';
|
|
8
|
+
}
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
trimStack() {
|
|
11
|
+
Error.captureStackTrace(this, RebillyInstrumentsConfigError);
|
|
12
|
+
return this;
|
|
13
|
+
}
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
const ajv = new AJV({
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
allErrors: true,
|
|
18
|
+
removeAdditional: true,
|
|
19
|
+
useDefaults: true,
|
|
20
20
|
});
|
|
21
21
|
const validate = ajv.compile(schema);
|
|
22
22
|
|
|
23
23
|
export function sanitize(data) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
JSON.stringify(data)
|
|
27
|
-
)
|
|
24
|
+
// cast data to be only json object
|
|
25
|
+
return JSON.parse(JSON.stringify(data));
|
|
28
26
|
}
|
|
29
27
|
|
|
30
28
|
export function validateOptions(data) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
validate.errors.forEach(error => {
|
|
38
|
-
let errorMessage = ``;
|
|
39
|
-
let instancePathReadable = error.instancePath.substring(1).replace(/\//gi, '.');
|
|
40
|
-
instancePathReadable = instancePathReadable.replace(/\.\d+/ig, (match) => {
|
|
41
|
-
return `[${match.replace('.', '')}]`;
|
|
42
|
-
});
|
|
43
|
-
if (!instancePathReadable.length) {
|
|
44
|
-
instancePathReadable = 'options'
|
|
29
|
+
const sanitizedData = sanitize(data);
|
|
30
|
+
const valid = validate(sanitizedData);
|
|
31
|
+
if (valid) {
|
|
32
|
+
return sanitizedData;
|
|
45
33
|
}
|
|
46
34
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
break;
|
|
56
|
-
}
|
|
57
|
-
errorMessage = `${instancePathReadable} ${error.message}`;
|
|
58
|
-
break;
|
|
59
|
-
case 'oneOf':
|
|
60
|
-
case 'anyOf':
|
|
61
|
-
console.error(
|
|
62
|
-
new RebillyInstrumentsConfigError(`${instancePathReadable} ${error.message}, see schemas below.`)
|
|
63
|
-
.trimStack()
|
|
35
|
+
validate.errors.forEach((error) => {
|
|
36
|
+
let errorMessage = ``;
|
|
37
|
+
let instancePathReadable = error.instancePath
|
|
38
|
+
.substring(1)
|
|
39
|
+
.replace(/\//gi, '.');
|
|
40
|
+
instancePathReadable = instancePathReadable.replace(
|
|
41
|
+
/\.\d+/gi,
|
|
42
|
+
(match) => `[${match.replace('.', '')}]`,
|
|
64
43
|
);
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
nodes.forEach(node => {
|
|
69
|
-
const displayNode = JSON.stringify(node, null, 2);
|
|
70
|
-
console.error(`${instancePathReadable} ${error.keyword} schema.\n${displayNode}`, );
|
|
71
|
-
});
|
|
72
|
-
break;
|
|
73
|
-
case 'enum':
|
|
74
|
-
let value = instancePathReadable.split('.').reduce((acc, key) => {
|
|
75
|
-
return acc[key];
|
|
76
|
-
}, data);
|
|
77
|
-
errorMessage = `${instancePathReadable} ${error.message}: ${error.params.allowedValues}. received: ${value}`
|
|
78
|
-
break;
|
|
79
|
-
case 'dependentRequired':
|
|
80
|
-
case 'maxLength':
|
|
81
|
-
case 'minItems':
|
|
82
|
-
case 'pattern':
|
|
83
|
-
errorMessage = `${instancePathReadable} ${error.message}`;
|
|
84
|
-
break;
|
|
85
|
-
default:
|
|
86
|
-
errorMessage = `Error with ${instancePathReadable} - See error message`;
|
|
87
|
-
console.error(error);
|
|
88
|
-
break;
|
|
89
|
-
}
|
|
90
|
-
if (errorMessage) {
|
|
91
|
-
console.error(new RebillyInstrumentsConfigError(errorMessage).trimStack());
|
|
92
|
-
}
|
|
93
|
-
});
|
|
44
|
+
if (!instancePathReadable.length) {
|
|
45
|
+
instancePathReadable = 'options';
|
|
46
|
+
}
|
|
94
47
|
|
|
95
|
-
|
|
96
|
-
|
|
48
|
+
let nodes;
|
|
49
|
+
let schemaPath;
|
|
50
|
+
let value;
|
|
51
|
+
switch (error.keyword) {
|
|
52
|
+
case 'if':
|
|
53
|
+
case 'false schema':
|
|
54
|
+
// ignore keywords
|
|
55
|
+
break;
|
|
56
|
+
case 'required':
|
|
57
|
+
if (error.schemaPath.match(/(oneOf|anyOf)/)) {
|
|
58
|
+
// ignore and allow their oneOf or anyOf keywords to handle error message
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
errorMessage = `${instancePathReadable} ${error.message}`;
|
|
62
|
+
break;
|
|
63
|
+
case 'oneOf':
|
|
64
|
+
case 'anyOf':
|
|
65
|
+
console.error(
|
|
66
|
+
new RebillyInstrumentsConfigError(
|
|
67
|
+
`${instancePathReadable} ${error.message}, see schemas below.`,
|
|
68
|
+
).trimStack(),
|
|
69
|
+
);
|
|
70
|
+
schemaPath = error.schemaPath.replace('#/', '').split('/');
|
|
71
|
+
nodes = schema;
|
|
72
|
+
schemaPath.forEach((item) => {
|
|
73
|
+
nodes = nodes[item];
|
|
74
|
+
});
|
|
75
|
+
nodes.forEach((node) => {
|
|
76
|
+
const displayNode = JSON.stringify(node, null, 2);
|
|
77
|
+
console.error(
|
|
78
|
+
`${instancePathReadable} ${error.keyword} schema.\n${displayNode}`,
|
|
79
|
+
);
|
|
80
|
+
});
|
|
81
|
+
break;
|
|
82
|
+
case 'enum':
|
|
83
|
+
value = instancePathReadable
|
|
84
|
+
.split('.')
|
|
85
|
+
.reduce((acc, key) => acc[key], data);
|
|
86
|
+
errorMessage = `${instancePathReadable} ${error.message}: ${error.params.allowedValues}. received: ${value}`;
|
|
87
|
+
break;
|
|
88
|
+
case 'dependentRequired':
|
|
89
|
+
case 'maxLength':
|
|
90
|
+
case 'minItems':
|
|
91
|
+
case 'pattern':
|
|
92
|
+
errorMessage = `${instancePathReadable} ${error.message}`;
|
|
93
|
+
break;
|
|
94
|
+
default:
|
|
95
|
+
errorMessage = `Error with ${instancePathReadable} - See error message`;
|
|
96
|
+
console.error(error);
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
if (errorMessage) {
|
|
100
|
+
console.error(
|
|
101
|
+
new RebillyInstrumentsConfigError(errorMessage).trimStack(),
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
console.error(
|
|
107
|
+
new RebillyInstrumentsConfigError(
|
|
108
|
+
'Configuration is invalid',
|
|
109
|
+
).trimStack(),
|
|
110
|
+
);
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|