@rebilly/instruments 4.8.1 → 4.8.2
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/CHANGELOG.md +7 -0
- package/dist/index.js +1 -1
- package/dist/index.min.js +1 -1
- package/package.json +5 -1
- package/.babelrc +0 -26
- package/project.json +0 -31
- package/rollup.config.mjs +0 -79
- package/src/data/options-schema/index.js +0 -112
- package/src/data/options-schema/schemas/options-schema.js +0 -448
- package/src/events/base-event.js +0 -47
- package/src/events/events.spec.js +0 -11
- package/src/events/index.js +0 -15
- package/src/functions/destroy.js +0 -29
- package/src/functions/destroy.spec.js +0 -63
- package/src/functions/mount/fetch-data.js +0 -236
- package/src/functions/mount/fetch-data.spec.js +0 -317
- package/src/functions/mount/get-lead-source-data.js +0 -46
- package/src/functions/mount/get-lead-source-data.spec.js +0 -38
- package/src/functions/mount/index.js +0 -105
- package/src/functions/mount/mount.spec.js +0 -96
- package/src/functions/mount/setup-element.js +0 -29
- package/src/functions/mount/setup-framepay-theme.js +0 -104
- package/src/functions/mount/setup-framepay.js +0 -26
- package/src/functions/mount/setup-i18n.js +0 -21
- package/src/functions/mount/setup-options.js +0 -100
- package/src/functions/mount/setup-options.spec.js +0 -353
- package/src/functions/mount/setup-storefront.js +0 -23
- package/src/functions/mount/setup-styles-vars.js +0 -30
- package/src/functions/mount/setup-user-flow.js +0 -60
- package/src/functions/on.js +0 -22
- package/src/functions/on.spec.js +0 -75
- package/src/functions/purchase.js +0 -173
- package/src/functions/purchase.spec.js +0 -80
- package/src/functions/setup.js +0 -66
- package/src/functions/setup.spec.js +0 -111
- package/src/functions/show.js +0 -30
- package/src/functions/show.spec.js +0 -62
- package/src/functions/update.js +0 -40
- package/src/functions/update.spec.js +0 -104
- package/src/i18n/en.json +0 -35
- package/src/i18n/es.json +0 -32
- package/src/i18n/i18n.spec.js +0 -27
- package/src/i18n/index.js +0 -59
- package/src/index.js +0 -3
- package/src/instance.js +0 -48
- package/src/instance.spec.js +0 -44
- package/src/loader/index.js +0 -145
- package/src/loader/loader.spec.js +0 -74
- package/src/state/iframes.js +0 -23
- package/src/state/index.js +0 -64
- package/src/storefront/account-and-website.js +0 -18
- package/src/storefront/account-and-website.spec.js +0 -73
- package/src/storefront/deposit-requests.js +0 -12
- package/src/storefront/fetch-plans-from-addons-bumpOffer.js +0 -30
- package/src/storefront/fetch-products-from-plans.js +0 -59
- package/src/storefront/fetch-products-from-plans.spec.js +0 -113
- package/src/storefront/index.js +0 -78
- package/src/storefront/invoices.js +0 -23
- package/src/storefront/invoices.spec.js +0 -92
- package/src/storefront/models/account-model.js +0 -36
- package/src/storefront/models/base-model.js +0 -7
- package/src/storefront/models/deposit-request-model.js +0 -24
- package/src/storefront/models/invoice-model.js +0 -20
- package/src/storefront/models/payment-metadata.js +0 -7
- package/src/storefront/models/plan-model.js +0 -94
- package/src/storefront/models/product-model.js +0 -3
- package/src/storefront/models/ready-to-pay-model.js +0 -76
- package/src/storefront/models/summary-model.js +0 -56
- package/src/storefront/models/transaction-model.js +0 -16
- package/src/storefront/models/website-model.js +0 -3
- package/src/storefront/payment-instruments.js +0 -47
- package/src/storefront/payment-instruments.spec.js +0 -88
- package/src/storefront/purchase.js +0 -60
- package/src/storefront/purchase.spec.js +0 -53
- package/src/storefront/ready-to-pay.js +0 -96
- package/src/storefront/ready-to-pay.spec.js +0 -76
- package/src/storefront/storefront.spec.js +0 -14
- package/src/storefront/summary.js +0 -114
- package/src/storefront/summary.spec.js +0 -136
- package/src/storefront/transactions.js +0 -12
- package/src/style/base/__snapshots__/theme.spec.js.snap +0 -143
- package/src/style/base/default-theme.js +0 -955
- package/src/style/base/index.js +0 -688
- package/src/style/base/theme.js +0 -30
- package/src/style/base/theme.spec.js +0 -19
- package/src/style/index.js +0 -11
- package/src/style/utils/border.js +0 -47
- package/src/style/utils/color-values.js +0 -35
- package/src/style/utils/minifyCss.js +0 -14
- package/src/utils/add-dom-element.js +0 -17
- package/src/utils/format-currency.js +0 -8
- package/src/utils/has-valid-css-selector.js +0 -4
- package/src/utils/index.js +0 -15
- package/src/utils/is-dom-element.js +0 -3
- package/src/utils/process-property-as-dom-element.js +0 -31
- package/src/utils/quantity.js +0 -47
- package/src/utils/sleep.js +0 -5
- package/src/views/amount-selector.js +0 -46
- package/src/views/common/iframe/base-iframe.js +0 -66
- package/src/views/common/iframe/events/change-iframe-src-handler.js +0 -6
- package/src/views/common/iframe/events/dispatch-event-handler.js +0 -8
- package/src/views/common/iframe/events/resize-component-handler.js +0 -9
- package/src/views/common/iframe/events/show-error-handler.js +0 -5
- package/src/views/common/iframe/events/stop-loader-handler.js +0 -9
- package/src/views/common/iframe/events/update-addons-handler.js +0 -23
- package/src/views/common/iframe/events/update-coupons-handler.js +0 -12
- package/src/views/common/iframe/events/update-items-handler.js +0 -34
- package/src/views/common/iframe/index.js +0 -5
- package/src/views/common/iframe/modal-iframe.js +0 -82
- package/src/views/common/iframe/view-iframe.js +0 -23
- package/src/views/common/render-utilities.js +0 -4
- package/src/views/confirmation.js +0 -45
- package/src/views/errors.js +0 -115
- package/src/views/form.js +0 -61
- package/src/views/method-selector/__snapshots__/method-selector.spec.js.snap +0 -135
- package/src/views/method-selector/express-methods.js +0 -52
- package/src/views/method-selector/generate-digital-wallet.js +0 -53
- package/src/views/method-selector/generate-digital-wallet.spec.js +0 -121
- package/src/views/method-selector/generate-framepay-config.js +0 -56
- package/src/views/method-selector/generate-framepay-config.spec.js +0 -216
- package/src/views/method-selector/get-method-data.js +0 -11
- package/src/views/method-selector/get-payment-methods.js +0 -25
- package/src/views/method-selector/get-payment-methods.spec.js +0 -41
- package/src/views/method-selector/index.js +0 -223
- package/src/views/method-selector/method-selector.spec.js +0 -20
- package/src/views/method-selector/mount-bump-offer.js +0 -120
- package/src/views/method-selector/mount-express-methods.js +0 -107
- package/src/views/modal.js +0 -103
- package/src/views/result.js +0 -24
- package/src/views/summary.js +0 -38
- package/tests/async-utilities.js +0 -22
- package/tests/mocks/framepay-mock.js +0 -15
- package/tests/mocks/rebilly-api-mock.js +0 -11
- package/tests/mocks/rebilly-instruments-mock.js +0 -141
- package/tests/mocks/storefront-api-mock.js +0 -62
- package/tests/mocks/storefront-mock.js +0 -20
- package/tests/msw/server.js +0 -14
- package/tests/setup-test.js +0 -30
- package/vitest.config.js +0 -18
package/src/i18n/en.json
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"en": {
|
|
3
|
-
"summary": {
|
|
4
|
-
"subTotal": "Sub Total",
|
|
5
|
-
"discounts": "Discounts",
|
|
6
|
-
"taxes": "Taxes",
|
|
7
|
-
"shipping": "Shipping",
|
|
8
|
-
"total": "Total"
|
|
9
|
-
},
|
|
10
|
-
"deposit": {
|
|
11
|
-
"goBack": "Choose another amount"
|
|
12
|
-
},
|
|
13
|
-
"form": {
|
|
14
|
-
"expressCheckout": "Express checkout",
|
|
15
|
-
"or": "Or",
|
|
16
|
-
"popupOverlayText": "Click here to show popup window",
|
|
17
|
-
"andMore": "and more",
|
|
18
|
-
"error": {
|
|
19
|
-
"noPaymentMethods": "No payment methods available for this transaction, please contact support.",
|
|
20
|
-
"invoiceIsPaid": "The invoice has been fully paid."
|
|
21
|
-
},
|
|
22
|
-
"loaderMessages": {
|
|
23
|
-
"processingPayment": "Processing payment instrument."
|
|
24
|
-
},
|
|
25
|
-
"bumpOffer": {
|
|
26
|
-
"title": "Yes, I want to upgrade!",
|
|
27
|
-
"startingAt": "Starting at {basePrice}"
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
"paymentMethods": {
|
|
31
|
-
"payment-card": "Payment card",
|
|
32
|
-
"ach": "Bank account"
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
package/src/i18n/es.json
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"es": {
|
|
3
|
-
"summary": {
|
|
4
|
-
"subTotal": "Sub Total",
|
|
5
|
-
"discounts": "Descuentos",
|
|
6
|
-
"taxes": "Impuestos",
|
|
7
|
-
"shipping": "Envío",
|
|
8
|
-
"total": "Total"
|
|
9
|
-
},
|
|
10
|
-
"deposit": {
|
|
11
|
-
"goBack": "Elija otro monto a depositar"
|
|
12
|
-
},
|
|
13
|
-
"form": {
|
|
14
|
-
"expressCheckout": "Chequeo rápido",
|
|
15
|
-
"or": "O pague con",
|
|
16
|
-
"andMore": "y más",
|
|
17
|
-
"popupOverlayText": "Haga clic aquí para mostrar la ventana emergente",
|
|
18
|
-
"error": {
|
|
19
|
-
"noPaymentMethods": "No hay métodos de pago disponibles para esta transacción, por favor, póngase en contacto con el servicio de asistencia.",
|
|
20
|
-
"invoiceIsPaid": "La factura ha sido completamente pagada."
|
|
21
|
-
},
|
|
22
|
-
"bumpOffer": {
|
|
23
|
-
"title": "¡Sí, me gustaría actualizar!",
|
|
24
|
-
"startingAt": "A partir de {basePrice}"
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
|
-
"paymentMethods": {
|
|
28
|
-
"payment-card": "Tarjeta de crédito",
|
|
29
|
-
"ach": "Cuenta bancaria"
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
package/src/i18n/i18n.spec.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { Translate } from './index';
|
|
2
|
-
|
|
3
|
-
describe('i18n Class', () => {
|
|
4
|
-
const canTranslate = document.createElement('div');
|
|
5
|
-
canTranslate.innerHTML = 'Discounts';
|
|
6
|
-
canTranslate.setAttribute('data-rebilly-i18n', 'summary.discounts');
|
|
7
|
-
|
|
8
|
-
const canNotTranslate = document.createElement('div');
|
|
9
|
-
canNotTranslate.innerHTML = 'Untouched';
|
|
10
|
-
canNotTranslate.setAttribute('data-rebilly-i18n', 'does.not.exist');
|
|
11
|
-
|
|
12
|
-
document.body.append(canTranslate);
|
|
13
|
-
document.body.append(canNotTranslate);
|
|
14
|
-
|
|
15
|
-
it('can translate element with proper data attribute and skip wrong translation path or languages', () => {
|
|
16
|
-
const translate = new Translate();
|
|
17
|
-
translate.init('es-US');
|
|
18
|
-
translate.translateItems();
|
|
19
|
-
|
|
20
|
-
const [translated, untouched] = document.querySelectorAll(
|
|
21
|
-
'[data-rebilly-i18n]',
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
expect(translated.innerHTML).toEqual('Descuentos');
|
|
25
|
-
expect(untouched.innerHTML).toEqual('Untouched');
|
|
26
|
-
});
|
|
27
|
-
});
|
package/src/i18n/index.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import merge from 'lodash.merge';
|
|
2
|
-
import en from './en.json';
|
|
3
|
-
import es from './es.json';
|
|
4
|
-
|
|
5
|
-
export class Translate {
|
|
6
|
-
constructor() {
|
|
7
|
-
this.locale = '';
|
|
8
|
-
this.items = [];
|
|
9
|
-
this.languages = {};
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
init(locale, messages) {
|
|
13
|
-
this.items = document.querySelectorAll('[data-rebilly-i18n]');
|
|
14
|
-
this.locale = this.getLocale(locale);
|
|
15
|
-
this.languages = merge({}, { ...en, ...es }, messages);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
translateItems() {
|
|
19
|
-
this.items = document.querySelectorAll('[data-rebilly-i18n]');
|
|
20
|
-
|
|
21
|
-
if (this.locale in this.languages) {
|
|
22
|
-
return this.items.forEach((item) => {
|
|
23
|
-
const translate = this.getTranslation(
|
|
24
|
-
item.dataset.rebillyI18n,
|
|
25
|
-
this.languages[this.locale],
|
|
26
|
-
);
|
|
27
|
-
if (translate) {
|
|
28
|
-
item.innerHTML = translate;
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
updateTranslationsToNewLocale(newLocale) {
|
|
36
|
-
this.locale = newLocale;
|
|
37
|
-
this.translateItems();
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
getLocale(locale = this.locale) {
|
|
41
|
-
if (!locale.includes('-') || locale in this.languages) {
|
|
42
|
-
return locale;
|
|
43
|
-
}
|
|
44
|
-
locale = locale.replace(/[-._]\w+$/gi, '');
|
|
45
|
-
return this.getLocale(locale);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
translateItem(item) {
|
|
49
|
-
const locale = this.getLocale();
|
|
50
|
-
return this.getTranslation(
|
|
51
|
-
item.dataset.rebillyI18n,
|
|
52
|
-
this.languages[locale],
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
getTranslation(prop, lan = this.languages[this.locale]) {
|
|
57
|
-
return prop.split('.').reduce((acc, val) => acc?.[val], lan);
|
|
58
|
-
}
|
|
59
|
-
}
|
package/src/index.js
DELETED
package/src/instance.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import state from './state';
|
|
2
|
-
import iframes from './state/iframes';
|
|
3
|
-
import { mount } from './functions/mount';
|
|
4
|
-
import { purchase } from './functions/purchase';
|
|
5
|
-
import { setup } from './functions/setup';
|
|
6
|
-
import { on } from './functions/on';
|
|
7
|
-
import { update } from './functions/update';
|
|
8
|
-
import { destroy } from './functions/destroy';
|
|
9
|
-
import { show } from './functions/show';
|
|
10
|
-
|
|
11
|
-
export class RebillyInstrumentsInstance {
|
|
12
|
-
constructor() {
|
|
13
|
-
this.state = state;
|
|
14
|
-
this.iframes = iframes;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
async mount(options) {
|
|
18
|
-
await mount(options);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
async destroy() {
|
|
22
|
-
await destroy();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
async update(newOptions) {
|
|
26
|
-
await update({ newOptions });
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
async purchase(payload) {
|
|
30
|
-
await purchase({ payload });
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
async setup(payload) {
|
|
34
|
-
await setup({ payload });
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
async show(componentName, payload) {
|
|
38
|
-
await show({ componentName, payload });
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
get version() {
|
|
42
|
-
return 'RebillyInstruments Ver.[VI]{version}[/VI]';
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
on(eventName, callback) {
|
|
46
|
-
on({ eventName, callback });
|
|
47
|
-
}
|
|
48
|
-
}
|
package/src/instance.spec.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { avoidUnhandledPromises } from 'tests/async-utilities';
|
|
2
|
-
import { setupFramepayMock } from 'tests/mocks/rebilly-instruments-mock';
|
|
3
|
-
import RebillyInstruments from './index';
|
|
4
|
-
import { RebillyInstrumentsInstance } from './instance';
|
|
5
|
-
|
|
6
|
-
describe('RebillyInstruments instance', () => {
|
|
7
|
-
let rebillyInstruments;
|
|
8
|
-
|
|
9
|
-
beforeEach(() => {
|
|
10
|
-
rebillyInstruments = RebillyInstruments;
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
it('should have default export as instance of class', () => {
|
|
14
|
-
expect(RebillyInstruments).toBeInstanceOf(RebillyInstrumentsInstance);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('should be mountable', async () => {
|
|
18
|
-
vi.spyOn(rebillyInstruments, 'mount');
|
|
19
|
-
|
|
20
|
-
document.body.innerHTML = `
|
|
21
|
-
<div class="form-selector"></div>
|
|
22
|
-
<div class="summary-selector"></div>
|
|
23
|
-
`;
|
|
24
|
-
|
|
25
|
-
const options = {
|
|
26
|
-
form: '.form-selector',
|
|
27
|
-
summary: '.summary-selector',
|
|
28
|
-
apiMode: 'sandbox',
|
|
29
|
-
items: [
|
|
30
|
-
{
|
|
31
|
-
planId: 'test-plan-id',
|
|
32
|
-
quantity: 1,
|
|
33
|
-
},
|
|
34
|
-
],
|
|
35
|
-
setupFramepay: setupFramepayMock,
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
await rebillyInstruments.mount(options);
|
|
39
|
-
|
|
40
|
-
expect(rebillyInstruments.mount).toHaveBeenCalledTimes(1);
|
|
41
|
-
expect(rebillyInstruments.mount).toHaveBeenCalledWith(options);
|
|
42
|
-
await avoidUnhandledPromises();
|
|
43
|
-
});
|
|
44
|
-
});
|
package/src/loader/index.js
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import isDOMElement from '../utils/is-dom-element';
|
|
2
|
-
|
|
3
|
-
export const summaryLoaderHTML = `
|
|
4
|
-
<div class="rebilly-instruments-summary-loader-total rebilly-instruments-loader-display-flex rebilly-instruments-loader-align-center rebilly-instruments-loader-justify-space-between">
|
|
5
|
-
<div><p class="is-el-loading">Total</p></div>
|
|
6
|
-
<p class="total is-el-loading">$99.99</p>
|
|
7
|
-
</div>
|
|
8
|
-
`;
|
|
9
|
-
|
|
10
|
-
export const methodsLoaderHTML = `
|
|
11
|
-
<div class="rebilly-instruments-methods-loader">
|
|
12
|
-
<div class="rebilly-instruments-loader-form-el is-el-loading"></div>
|
|
13
|
-
<div class="rebilly-instruments-divider">
|
|
14
|
-
<span class="rebilly-instruments-divider-label"><span class="is-el-loading">Divi</span></span>
|
|
15
|
-
</div>
|
|
16
|
-
<div class="rebilly-instruments-loader-display-flex rebilly-instruments-loader-justify-end">
|
|
17
|
-
<div class="rebilly-instruments-methods-loader-card-icon is-el-loading"></div>
|
|
18
|
-
<div class="rebilly-instruments-methods-loader-card-icon is-el-loading"></div>
|
|
19
|
-
</div>
|
|
20
|
-
<div class="rebilly-instruments-loader-form-el is-el-loading"></div>
|
|
21
|
-
<div class="rebilly-instruments-methods-loader-form-fields">
|
|
22
|
-
<div class="rebilly-instruments-loader-form-label"><small class="is-el-loading">Card holder name</small></div>
|
|
23
|
-
<div class="rebilly-instruments-loader-form-el is-el-loading"></div>
|
|
24
|
-
</div>
|
|
25
|
-
<div class="rebilly-instruments-loader-form-el is-button">Continue</div>
|
|
26
|
-
</div>
|
|
27
|
-
`;
|
|
28
|
-
|
|
29
|
-
const loaderContainer = (padding = '0px') => `
|
|
30
|
-
<div class="rebilly-instruments-loader is-active" style="padding: ${padding}"></div>
|
|
31
|
-
`;
|
|
32
|
-
|
|
33
|
-
export const basicLoaderHTML = `
|
|
34
|
-
<div class="rebilly-instruments-loader-spinner"></div>
|
|
35
|
-
`;
|
|
36
|
-
|
|
37
|
-
export class Loader {
|
|
38
|
-
constructor() {
|
|
39
|
-
this.summary = [];
|
|
40
|
-
this.form = [];
|
|
41
|
-
this.modal = [];
|
|
42
|
-
this.DOM = {
|
|
43
|
-
loaderContainer,
|
|
44
|
-
summaryLoaderHTML,
|
|
45
|
-
methodsLoaderHTML,
|
|
46
|
-
basicLoaderHTML,
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
addDOMElement({ section = 'form', el = null } = {}) {
|
|
51
|
-
if (isDOMElement(el)) {
|
|
52
|
-
el.style.position = 'relative';
|
|
53
|
-
this.DOM[section] = el;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
startLoading({ section = 'form', id = '' } = {}) {
|
|
58
|
-
this[section].push(id);
|
|
59
|
-
|
|
60
|
-
const rootEl = document.querySelector(':root');
|
|
61
|
-
const contentPadding = 2;
|
|
62
|
-
let minHeight = '240px';
|
|
63
|
-
|
|
64
|
-
if (this.DOM?.[section]) {
|
|
65
|
-
let loaderEl = this.DOM[section].querySelector(
|
|
66
|
-
'.rebilly-instruments-loader',
|
|
67
|
-
);
|
|
68
|
-
const { padding, paddingTop, paddingBottom } = getComputedStyle(
|
|
69
|
-
this.DOM?.[section],
|
|
70
|
-
);
|
|
71
|
-
if (!loaderEl) {
|
|
72
|
-
this.DOM[section].innerHTML = loaderContainer(
|
|
73
|
-
`${parseFloat(padding) + contentPadding}px`,
|
|
74
|
-
);
|
|
75
|
-
loaderEl = this.DOM[section].querySelector(
|
|
76
|
-
'.rebilly-instruments-loader',
|
|
77
|
-
);
|
|
78
|
-
if (section === 'form') {
|
|
79
|
-
loaderEl.insertAdjacentHTML(
|
|
80
|
-
'afterbegin',
|
|
81
|
-
this.DOM.methodsLoaderHTML,
|
|
82
|
-
);
|
|
83
|
-
minHeight = getComputedStyle(rootEl).getPropertyValue(
|
|
84
|
-
'--rebilly-methodLoaderMinHeight',
|
|
85
|
-
);
|
|
86
|
-
} else if (section === 'summary') {
|
|
87
|
-
loaderEl.insertAdjacentHTML(
|
|
88
|
-
'afterbegin',
|
|
89
|
-
this.DOM.summaryLoaderHTML,
|
|
90
|
-
);
|
|
91
|
-
minHeight = getComputedStyle(rootEl).getPropertyValue(
|
|
92
|
-
'--rebilly-summaryLoaderMinHeight',
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
} else {
|
|
96
|
-
if (
|
|
97
|
-
id.includes('confirmation') ||
|
|
98
|
-
id.includes('result') ||
|
|
99
|
-
id.includes('modal')
|
|
100
|
-
) {
|
|
101
|
-
loaderEl.innerHTML = this.DOM.basicLoaderHTML;
|
|
102
|
-
}
|
|
103
|
-
loaderEl.classList.add('is-active');
|
|
104
|
-
}
|
|
105
|
-
this.DOM[
|
|
106
|
-
section
|
|
107
|
-
].style.minHeight = `calc(${minHeight} + ${paddingTop} + ${paddingBottom} + ${
|
|
108
|
-
contentPadding * 2
|
|
109
|
-
}px)`;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
stopLoading({ section = 'form', id = '' } = {}) {
|
|
114
|
-
const idIndex = this[section].indexOf(id);
|
|
115
|
-
|
|
116
|
-
if (idIndex !== -1) {
|
|
117
|
-
this[section].splice(idIndex, 1);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
if (
|
|
121
|
-
this.DOM[section] &&
|
|
122
|
-
!this[section].length &&
|
|
123
|
-
this.DOM[section].querySelector('.rebilly-instruments-loader')
|
|
124
|
-
) {
|
|
125
|
-
this.DOM[section]
|
|
126
|
-
.querySelector('.rebilly-instruments-loader')
|
|
127
|
-
.classList.remove('is-active');
|
|
128
|
-
this.DOM[section].style.minHeight = '';
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
clearAll() {
|
|
133
|
-
this.form.forEach((id) => {
|
|
134
|
-
this.stopLoading({ id });
|
|
135
|
-
});
|
|
136
|
-
if (this.summary) {
|
|
137
|
-
this.summary.forEach((id) => {
|
|
138
|
-
this.stopLoading({ section: 'summary', id });
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
this.modal.forEach((id) => {
|
|
142
|
-
this.stopLoading({ section: 'modal', id });
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { Loader } from './index';
|
|
2
|
-
|
|
3
|
-
describe('Loader Class', () => {
|
|
4
|
-
let loader;
|
|
5
|
-
|
|
6
|
-
beforeEach(() => {
|
|
7
|
-
loader = new Loader();
|
|
8
|
-
|
|
9
|
-
document.body.innerHTML = `
|
|
10
|
-
<div class="form-selector"></div>
|
|
11
|
-
<div class="summary-selector"></div>
|
|
12
|
-
`;
|
|
13
|
-
|
|
14
|
-
loader.addDOMElement({ el: document.querySelector('.form-selector') });
|
|
15
|
-
loader.addDOMElement({
|
|
16
|
-
section: 'summary',
|
|
17
|
-
el: document.querySelector('.summary-selector'),
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it('manage state of loading ids', () => {
|
|
22
|
-
loader.startLoading({ id: 'loadForm' });
|
|
23
|
-
loader.startLoading({ id: 'updateForm' });
|
|
24
|
-
|
|
25
|
-
// Start loading state
|
|
26
|
-
loader.startLoading({ section: 'summary', id: 'loadSummary' });
|
|
27
|
-
loader.startLoading({ section: 'summary', id: 'updateSummary' });
|
|
28
|
-
|
|
29
|
-
// Stop one loading state
|
|
30
|
-
loader.stopLoading({ id: 'loadForm' });
|
|
31
|
-
|
|
32
|
-
expect(loader.form.length).toEqual(1);
|
|
33
|
-
expect(loader.summary.length).toEqual(2);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('adds the loader HTML on element and removes the active class when stoped', () => {
|
|
37
|
-
loader.startLoading({ id: 'loadForm' });
|
|
38
|
-
|
|
39
|
-
expect(loader.DOM.form.innerHTML).toMatch('rebilly-instruments-loader');
|
|
40
|
-
expect(
|
|
41
|
-
loader.DOM.form
|
|
42
|
-
.querySelector('.rebilly-instruments-loader')
|
|
43
|
-
.classList.contains('is-active'),
|
|
44
|
-
).toEqual(true);
|
|
45
|
-
|
|
46
|
-
loader.stopLoading({ id: 'loadForm' });
|
|
47
|
-
|
|
48
|
-
expect(
|
|
49
|
-
loader.DOM.form
|
|
50
|
-
.querySelector('.rebilly-instruments-loader')
|
|
51
|
-
.classList.contains('is-active'),
|
|
52
|
-
).toEqual(false);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('keeps loading when there are Ids on the element array', () => {
|
|
56
|
-
loader.startLoading({ id: 'loadForm' });
|
|
57
|
-
loader.startLoading({ id: 'updateForm' });
|
|
58
|
-
|
|
59
|
-
expect(loader.DOM.form.innerHTML).toMatch('rebilly-instruments-loader');
|
|
60
|
-
expect(
|
|
61
|
-
loader.DOM.form
|
|
62
|
-
.querySelector('.rebilly-instruments-loader')
|
|
63
|
-
.classList.contains('is-active'),
|
|
64
|
-
).toEqual(true);
|
|
65
|
-
|
|
66
|
-
loader.stopLoading({ id: 'loadForm' });
|
|
67
|
-
|
|
68
|
-
expect(
|
|
69
|
-
loader.DOM.form
|
|
70
|
-
.querySelector('.rebilly-instruments-loader')
|
|
71
|
-
.classList.contains('is-active'),
|
|
72
|
-
).toEqual(true);
|
|
73
|
-
});
|
|
74
|
-
});
|
package/src/state/iframes.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export default (() => {
|
|
2
|
-
let state = null;
|
|
3
|
-
return {
|
|
4
|
-
getInstance() {
|
|
5
|
-
if (state === null) {
|
|
6
|
-
state = {
|
|
7
|
-
form: null,
|
|
8
|
-
summary: null,
|
|
9
|
-
hasFrame(name) {
|
|
10
|
-
if (state[name] && !name.match(/^has.*/)) {
|
|
11
|
-
return !!state[name];
|
|
12
|
-
}
|
|
13
|
-
return false;
|
|
14
|
-
},
|
|
15
|
-
hasComponent(name) {
|
|
16
|
-
return !!state[name]?.component;
|
|
17
|
-
},
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
return state;
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
})().getInstance();
|
package/src/state/index.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { reactive } from 'vue';
|
|
2
|
-
import { Loader } from '../loader';
|
|
3
|
-
import { Translate } from '../i18n';
|
|
4
|
-
import iframes from './iframes';
|
|
5
|
-
|
|
6
|
-
export default (() => {
|
|
7
|
-
let state = null;
|
|
8
|
-
const defaultState = {
|
|
9
|
-
options: null,
|
|
10
|
-
data: {},
|
|
11
|
-
mountingPoints: null,
|
|
12
|
-
storefront: null,
|
|
13
|
-
form: null,
|
|
14
|
-
summary: null,
|
|
15
|
-
loader: new Loader(),
|
|
16
|
-
translate: new Translate(),
|
|
17
|
-
hasMounted: false,
|
|
18
|
-
toModel() {
|
|
19
|
-
const model = {
|
|
20
|
-
...state,
|
|
21
|
-
data: state.data.toPostmatesModel
|
|
22
|
-
? state.data.toPostmatesModel()
|
|
23
|
-
: {},
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
// remove functions from model
|
|
27
|
-
delete model.toModel;
|
|
28
|
-
delete model.updateModel;
|
|
29
|
-
delete model.reset;
|
|
30
|
-
|
|
31
|
-
return JSON.parse(JSON.stringify(model));
|
|
32
|
-
},
|
|
33
|
-
updateModel() {
|
|
34
|
-
const modelSafeState = state?.toModel();
|
|
35
|
-
if (modelSafeState) {
|
|
36
|
-
const updateModel = {
|
|
37
|
-
data: modelSafeState.data,
|
|
38
|
-
options: modelSafeState.options,
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
if (iframes.hasComponent('summary')) {
|
|
42
|
-
iframes.summary.component.call('update', updateModel);
|
|
43
|
-
}
|
|
44
|
-
if (iframes.hasComponent('form')) {
|
|
45
|
-
iframes.form.component.call('update', updateModel);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
reset() {
|
|
50
|
-
if (state !== null) {
|
|
51
|
-
state = reactive({ ...defaultState });
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
return {
|
|
57
|
-
getInstance() {
|
|
58
|
-
if (state === null) {
|
|
59
|
-
state = reactive({ ...defaultState });
|
|
60
|
-
}
|
|
61
|
-
return state;
|
|
62
|
-
},
|
|
63
|
-
};
|
|
64
|
-
})().getInstance();
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import AccountModel from './models/account-model';
|
|
2
|
-
import WebsiteModel from './models/website-model';
|
|
3
|
-
import { Endpoint } from './index';
|
|
4
|
-
import state from '../state';
|
|
5
|
-
|
|
6
|
-
export async function fetchAccountAndWebsite() {
|
|
7
|
-
return Endpoint(async () => {
|
|
8
|
-
state.storefront.setSessionToken(state.options.jwt);
|
|
9
|
-
const { fields } = await state.storefront.account.get({
|
|
10
|
-
expand: 'website',
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
return {
|
|
14
|
-
website: new WebsiteModel(fields._embedded?.website),
|
|
15
|
-
account: new AccountModel(fields),
|
|
16
|
-
};
|
|
17
|
-
});
|
|
18
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { StorefontTestingInstance } from 'tests/mocks/storefront-mock';
|
|
2
|
-
import { ok, get } from 'msw-when-then';
|
|
3
|
-
import { when } from 'tests/msw/server';
|
|
4
|
-
import { storefrontURL } from 'tests/mocks/storefront-api-mock';
|
|
5
|
-
import { fetchAccountAndWebsite } from './account-and-website';
|
|
6
|
-
import AccountModel, { AddressModel } from './models/account-model';
|
|
7
|
-
import WebsiteModel from './models/website-model';
|
|
8
|
-
|
|
9
|
-
describe('Storefront API Account', () => {
|
|
10
|
-
it('should handle fetch a customer with a null primary address', async () => {
|
|
11
|
-
const options = {
|
|
12
|
-
jwt: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIzYjBkNTRkOS0xNmM4LTRlZDAtYjljMy01ODAyZmQ4YzE2ZTIiLCJleHAiOjE2ODY2OTc0MTQuODQxMjUsImlhdCI6MTY1NTE2MTQxNC44Nzk4OTEsImFjbCI6W3sic2NvcGUiOnsib3JnYW5pemF0aW9uSWQiOlsiMzY0NEFGTEFKMUciXSwicGF5bWVudE1ldGhvZHMiOlsicGF5bWVudC1jYXJkIl19LCJwZXJtaXNzaW9ucyI6WzI4NCwyODYsNDE0LDQxNSw0MzQsNDExLDQxMiw0MTMsNDI0LDQyNSw0MjYsNDI3LDQyOCw0MjksNDA5LDQxMCw0MDEsNDAyLDQzMyw0ODgsNDg3XX1dLCJjbGFpbXMiOnsid2Vic2l0ZUlkIjoiZGVtby13ZWJzaXRlIiwidHJhbnNhY3Rpb25JZCI6IjRiZDE3N2NmLTFlY2EtNDA2Yy04OWI0LTEzYzMzODk5NzlmMCIsInBheW1lbnRNZXRob2RzIjpbInBheW1lbnQtY2FyZCJdfSwibWVyY2hhbnQiOiIzNjQ0QUZMQUoxRyIsImN1c3RvbWVyIjp7ImlkIjoidGVzdC1jdXN0b21lci1pZCIsIm5hbWUiOiJUZXN0IEN1c3RvbWVyIE5hbWUiLCJjcmVhdGVkVGltZSI6IjIwMjItMDctMTRUMDA6MDA6MDArMDA6MDAifX0.VPue9QBhRGe3vvncaD47w84N8Bv2hEeShUl6SlNqoOQ',
|
|
13
|
-
items: [
|
|
14
|
-
{
|
|
15
|
-
planId: 'test-plan-id',
|
|
16
|
-
quantity: 1,
|
|
17
|
-
},
|
|
18
|
-
],
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
when(get(`${storefrontURL}/acount`)).thenReturn(
|
|
22
|
-
ok({
|
|
23
|
-
defaultPaymentInstrument: null,
|
|
24
|
-
id: 'test-customer-id',
|
|
25
|
-
primaryAddress: null,
|
|
26
|
-
websiteId: 'test-website-id',
|
|
27
|
-
}),
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
const instance = StorefontTestingInstance({
|
|
31
|
-
options,
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
vi.spyOn(instance.storefront.account, 'get');
|
|
35
|
-
|
|
36
|
-
const response = await fetchAccountAndWebsite({ state: instance });
|
|
37
|
-
expect(response.account.address).toEqual(new AddressModel({}));
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('should return an object with account and website', async () => {
|
|
41
|
-
const options = {
|
|
42
|
-
jwt: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIzYjBkNTRkOS0xNmM4LTRlZDAtYjljMy01ODAyZmQ4YzE2ZTIiLCJleHAiOjE2ODY2OTc0MTQuODQxMjUsImlhdCI6MTY1NTE2MTQxNC44Nzk4OTEsImFjbCI6W3sic2NvcGUiOnsib3JnYW5pemF0aW9uSWQiOlsiMzY0NEFGTEFKMUciXSwicGF5bWVudE1ldGhvZHMiOlsicGF5bWVudC1jYXJkIl19LCJwZXJtaXNzaW9ucyI6WzI4NCwyODYsNDE0LDQxNSw0MzQsNDExLDQxMiw0MTMsNDI0LDQyNSw0MjYsNDI3LDQyOCw0MjksNDA5LDQxMCw0MDEsNDAyLDQzMyw0ODgsNDg3XX1dLCJjbGFpbXMiOnsid2Vic2l0ZUlkIjoiZGVtby13ZWJzaXRlIiwidHJhbnNhY3Rpb25JZCI6IjRiZDE3N2NmLTFlY2EtNDA2Yy04OWI0LTEzYzMzODk5NzlmMCIsInBheW1lbnRNZXRob2RzIjpbInBheW1lbnQtY2FyZCJdfSwibWVyY2hhbnQiOiIzNjQ0QUZMQUoxRyIsImN1c3RvbWVyIjp7ImlkIjoidGVzdC1jdXN0b21lci1pZCIsIm5hbWUiOiJUZXN0IEN1c3RvbWVyIE5hbWUiLCJjcmVhdGVkVGltZSI6IjIwMjItMDctMTRUMDA6MDA6MDArMDA6MDAifX0.VPue9QBhRGe3vvncaD47w84N8Bv2hEeShUl6SlNqoOQ',
|
|
43
|
-
items: [
|
|
44
|
-
{
|
|
45
|
-
planId: 'test-plan-id',
|
|
46
|
-
quantity: 1,
|
|
47
|
-
},
|
|
48
|
-
],
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
when(get(`${storefrontURL}/acount`)).thenReturn(
|
|
52
|
-
ok({
|
|
53
|
-
defaultPaymentInstrument: null,
|
|
54
|
-
id: 'test-customer-id',
|
|
55
|
-
primaryAddress: null,
|
|
56
|
-
websiteId: 'test-website-id',
|
|
57
|
-
_embedded: {
|
|
58
|
-
website: {},
|
|
59
|
-
},
|
|
60
|
-
}),
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
const instance = StorefontTestingInstance({
|
|
64
|
-
options,
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
vi.spyOn(instance.storefront.account, 'get');
|
|
68
|
-
|
|
69
|
-
const response = await fetchAccountAndWebsite({ state: instance });
|
|
70
|
-
expect(response.account instanceof AccountModel).toBe(true);
|
|
71
|
-
expect(response.website instanceof WebsiteModel).toBe(true);
|
|
72
|
-
});
|
|
73
|
-
});
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Endpoint } from './index';
|
|
2
|
-
import state from '../state';
|
|
3
|
-
import DepositRequestModel from './models/deposit-request-model';
|
|
4
|
-
|
|
5
|
-
export async function fetchDepositRequest({ data = null }) {
|
|
6
|
-
return Endpoint(async () => {
|
|
7
|
-
state.storefront.setSessionToken(state.options.jwt);
|
|
8
|
-
const { fields } = await state.storefront.cashierRequests.get(data);
|
|
9
|
-
|
|
10
|
-
return new DepositRequestModel(fields);
|
|
11
|
-
});
|
|
12
|
-
}
|