@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.
Files changed (134) hide show
  1. package/.babelrc +24 -26
  2. package/CHANGELOG.md +7 -0
  3. package/dist/index.js +8 -8
  4. package/dist/index.min.js +8 -8
  5. package/package.json +14 -3
  6. package/project.json +9 -0
  7. package/rollup.config.mjs +21 -26
  8. package/src/data/options-schema/index.js +94 -78
  9. package/src/data/options-schema/schemas/options-schema.js +419 -411
  10. package/src/events/base-event.js +34 -34
  11. package/src/events/events.spec.js +6 -6
  12. package/src/events/index.js +5 -5
  13. package/src/functions/destroy.js +19 -19
  14. package/src/functions/destroy.spec.js +41 -41
  15. package/src/functions/mount/fetch-data.js +200 -193
  16. package/src/functions/mount/fetch-data.spec.js +287 -285
  17. package/src/functions/mount/get-lead-source-data.js +31 -31
  18. package/src/functions/mount/get-lead-source-data.spec.js +19 -19
  19. package/src/functions/mount/index.js +73 -65
  20. package/src/functions/mount/mount.spec.js +77 -66
  21. package/src/functions/mount/setup-element.js +23 -23
  22. package/src/functions/mount/setup-framepay-theme.js +86 -68
  23. package/src/functions/mount/setup-framepay.js +9 -5
  24. package/src/functions/mount/setup-i18n.js +15 -15
  25. package/src/functions/mount/setup-options.js +74 -74
  26. package/src/functions/mount/setup-options.spec.js +323 -287
  27. package/src/functions/mount/setup-storefront.js +15 -20
  28. package/src/functions/mount/setup-styles-vars.js +19 -22
  29. package/src/functions/mount/setup-user-flow.js +51 -47
  30. package/src/functions/on.js +5 -5
  31. package/src/functions/on.spec.js +60 -51
  32. package/src/functions/purchase.js +151 -146
  33. package/src/functions/purchase.spec.js +59 -56
  34. package/src/functions/setup.js +53 -53
  35. package/src/functions/setup.spec.js +88 -75
  36. package/src/functions/show.js +13 -14
  37. package/src/functions/show.spec.js +53 -53
  38. package/src/functions/update.js +30 -28
  39. package/src/functions/update.spec.js +94 -93
  40. package/src/i18n/en.json +32 -32
  41. package/src/i18n/es.json +29 -29
  42. package/src/i18n/i18n.spec.js +18 -18
  43. package/src/i18n/index.js +48 -48
  44. package/src/instance.js +36 -36
  45. package/src/instance.spec.js +29 -27
  46. package/src/loader/index.js +95 -70
  47. package/src/loader/loader.spec.js +63 -63
  48. package/src/state/iframes.js +21 -21
  49. package/src/state/index.js +56 -54
  50. package/src/storefront/account-and-website.js +10 -8
  51. package/src/storefront/account-and-website.spec.js +55 -55
  52. package/src/storefront/deposit-requests.js +6 -6
  53. package/src/storefront/fetch-plans-from-addons-bumpOffer.js +21 -19
  54. package/src/storefront/fetch-products-from-plans.js +52 -51
  55. package/src/storefront/fetch-products-from-plans.spec.js +90 -87
  56. package/src/storefront/index.js +56 -49
  57. package/src/storefront/invoices.js +15 -15
  58. package/src/storefront/invoices.spec.js +69 -65
  59. package/src/storefront/models/account-model.js +29 -32
  60. package/src/storefront/models/base-model.js +6 -9
  61. package/src/storefront/models/deposit-request-model.js +22 -13
  62. package/src/storefront/models/invoice-model.js +16 -16
  63. package/src/storefront/models/payment-metadata.js +4 -4
  64. package/src/storefront/models/plan-model.js +73 -64
  65. package/src/storefront/models/ready-to-pay-model.js +59 -59
  66. package/src/storefront/models/summary-model.js +43 -46
  67. package/src/storefront/models/transaction-model.js +11 -14
  68. package/src/storefront/payment-instruments.js +38 -35
  69. package/src/storefront/payment-instruments.spec.js +81 -62
  70. package/src/storefront/purchase.js +50 -44
  71. package/src/storefront/purchase.spec.js +40 -40
  72. package/src/storefront/ready-to-pay.js +75 -77
  73. package/src/storefront/ready-to-pay.spec.js +59 -54
  74. package/src/storefront/storefront.spec.js +9 -9
  75. package/src/storefront/summary.js +93 -67
  76. package/src/storefront/summary.spec.js +108 -106
  77. package/src/storefront/transactions.js +6 -6
  78. package/src/style/base/default-theme.js +928 -923
  79. package/src/style/base/theme.js +21 -21
  80. package/src/style/base/theme.spec.js +13 -13
  81. package/src/style/index.js +3 -3
  82. package/src/style/utils/border.js +40 -27
  83. package/src/style/utils/color-values.js +18 -18
  84. package/src/style/utils/minifyCss.js +6 -6
  85. package/src/utils/add-dom-element.js +14 -14
  86. package/src/utils/format-currency.js +6 -5
  87. package/src/utils/has-valid-css-selector.js +2 -2
  88. package/src/utils/index.js +6 -6
  89. package/src/utils/is-dom-element.js +1 -1
  90. package/src/utils/process-property-as-dom-element.js +22 -22
  91. package/src/utils/quantity.js +26 -28
  92. package/src/utils/sleep.js +3 -1
  93. package/src/views/amount-selector.js +37 -36
  94. package/src/views/common/iframe/base-iframe.js +53 -52
  95. package/src/views/common/iframe/events/change-iframe-src-handler.js +5 -5
  96. package/src/views/common/iframe/events/dispatch-event-handler.js +4 -4
  97. package/src/views/common/iframe/events/resize-component-handler.js +8 -8
  98. package/src/views/common/iframe/events/show-error-handler.js +2 -2
  99. package/src/views/common/iframe/events/stop-loader-handler.js +8 -8
  100. package/src/views/common/iframe/events/update-addons-handler.js +20 -13
  101. package/src/views/common/iframe/events/update-coupons-handler.js +9 -9
  102. package/src/views/common/iframe/events/update-items-handler.js +26 -22
  103. package/src/views/common/iframe/modal-iframe.js +67 -56
  104. package/src/views/common/iframe/view-iframe.js +11 -11
  105. package/src/views/common/render-utilities.js +2 -2
  106. package/src/views/confirmation.js +33 -30
  107. package/src/views/errors.js +89 -79
  108. package/src/views/form.js +41 -37
  109. package/src/views/method-selector/express-methods.js +46 -46
  110. package/src/views/method-selector/generate-digital-wallet.js +46 -45
  111. package/src/views/method-selector/generate-digital-wallet.spec.js +104 -102
  112. package/src/views/method-selector/generate-framepay-config.js +53 -51
  113. package/src/views/method-selector/generate-framepay-config.spec.js +197 -173
  114. package/src/views/method-selector/get-method-data.js +5 -6
  115. package/src/views/method-selector/get-payment-methods.js +18 -16
  116. package/src/views/method-selector/get-payment-methods.spec.js +29 -27
  117. package/src/views/method-selector/index.js +154 -139
  118. package/src/views/method-selector/method-selector.spec.js +13 -13
  119. package/src/views/method-selector/mount-bump-offer.js +65 -49
  120. package/src/views/method-selector/mount-express-methods.js +89 -85
  121. package/src/views/modal.js +74 -67
  122. package/src/views/result.js +14 -14
  123. package/src/views/summary.js +25 -26
  124. package/tests/async-utilities.js +13 -13
  125. package/tests/mocks/framepay-mock.js +9 -8
  126. package/tests/mocks/rebilly-api-mock.js +5 -3
  127. package/tests/mocks/rebilly-instruments-mock.js +121 -117
  128. package/tests/mocks/storefront-api-mock.js +55 -48
  129. package/tests/mocks/storefront-mock.js +10 -14
  130. package/tests/msw/server.js +6 -6
  131. package/tests/setup-test.js +14 -16
  132. package/vitest.config.js +14 -14
  133. package/.eslintrc.js +0 -34
  134. package/.prettierrc.js +0 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rebilly/instruments",
3
- "version": "4.5.0",
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.9",
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
@@ -17,6 +17,15 @@
17
17
  ]
18
18
  ]
19
19
  }
20
+ },
21
+ "lint:no-fix": {
22
+ "executor": "nx:run-script",
23
+ "options": {
24
+ "script": "lint:no-fix"
25
+ },
26
+ "dependsOn": [
27
+ "^build"
28
+ ]
20
29
  }
21
30
  }
22
31
  }
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 = (process.env.NODE_ENV === 'development');
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: [ '.mjs', '.js', '.jsx', '.json' ],
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
- file: 'dist/index.min.js',
67
- format: 'iife',
68
- name: 'RebillyInstruments',
69
- exports: 'default'
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
- ...buildOutput(),
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
- constructor(message) {
6
- super(message);
7
- this.name = "Rebilly Instruments Configuration Error";
8
- }
5
+ constructor(message) {
6
+ super(message);
7
+ this.name = 'Rebilly Instruments Configuration Error';
8
+ }
9
9
 
10
- trimStack() {
11
- Error.captureStackTrace(this, RebillyInstrumentsConfigError)
12
- return this
13
- }
10
+ trimStack() {
11
+ Error.captureStackTrace(this, RebillyInstrumentsConfigError);
12
+ return this;
13
+ }
14
14
  }
15
15
 
16
16
  const ajv = new AJV({
17
- allErrors: true,
18
- removeAdditional: true,
19
- useDefaults: true
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
- // cast data to be only json object
25
- return JSON.parse(
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
- const sanitizedData = sanitize(data);
32
- const valid = validate(sanitizedData);
33
- if (valid) {
34
- return sanitizedData;
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
- switch(error.keyword) {
48
- case 'if':
49
- case 'false schema':
50
- // ignore keywords
51
- break;
52
- case 'required':
53
- if (error.schemaPath.match(/(oneOf|anyOf)/)) {
54
- // ignore and allow their oneOf or anyOf keywords to handle error message
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
- const schemaPath = error.schemaPath.replace('#/', '').split('/');
66
- let nodes = schema;
67
- schemaPath.forEach(item => nodes = nodes[item]);
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
- console.error(new RebillyInstrumentsConfigError('Configuration is invalid').trimStack());
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
+ }