@ozura/elements 1.0.1-next.7 → 1.0.2-next.8
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/dist/frame/element-frame.js +31 -4
- package/dist/frame/element-frame.js.map +1 -1
- package/dist/frame/tokenizer-frame.js +14 -1
- package/dist/frame/tokenizer-frame.js.map +1 -1
- package/dist/oz-elements.esm.js +24 -0
- package/dist/oz-elements.esm.js.map +1 -1
- package/dist/oz-elements.umd.js +24 -0
- package/dist/oz-elements.umd.js.map +1 -1
- package/dist/react/frame/elementFrame.d.ts +59 -1
- package/dist/react/frame/protocol.d.ts +12 -0
- package/dist/react/index.cjs.js +117 -104
- package/dist/react/index.cjs.js.map +1 -1
- package/dist/react/index.esm.js +118 -105
- package/dist/react/index.esm.js.map +1 -1
- package/dist/react/types/index.d.ts +2 -0
- package/dist/server/frame/elementFrame.d.ts +59 -1
- package/dist/server/frame/protocol.d.ts +12 -0
- package/dist/server/types/index.d.ts +2 -0
- package/dist/types/frame/elementFrame.d.ts +59 -1
- package/dist/types/frame/protocol.d.ts +12 -0
- package/dist/types/types/index.d.ts +2 -0
- package/package.json +1 -1
package/dist/react/index.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
|
-
import { createContext, useContext, useRef,
|
|
2
|
+
import { createContext, useContext, useRef, useCallback, useState, useMemo, useEffect } from 'react';
|
|
3
3
|
|
|
4
4
|
const THEME_DEFAULT = {
|
|
5
5
|
base: {
|
|
@@ -819,6 +819,19 @@ function validateBilling(billing) {
|
|
|
819
819
|
return { valid: errors.length === 0, errors, normalized };
|
|
820
820
|
}
|
|
821
821
|
|
|
822
|
+
/**
|
|
823
|
+
* Shared postMessage protocol constants.
|
|
824
|
+
*
|
|
825
|
+
* PROTOCOL_VERSION must be incremented any time a breaking change is made to
|
|
826
|
+
* the postMessage message shape (new required fields, renamed types, removed
|
|
827
|
+
* fields, changed semantics). The SDK reads this value from OZ_FRAME_READY
|
|
828
|
+
* messages and warns when the frame and SDK are out of sync.
|
|
829
|
+
*
|
|
830
|
+
* Non-breaking additions (new optional fields, new message types that old
|
|
831
|
+
* frames can safely ignore) do NOT require a version bump.
|
|
832
|
+
*/
|
|
833
|
+
const PROTOCOL_VERSION = 1;
|
|
834
|
+
|
|
822
835
|
function isCardMetadata(v) {
|
|
823
836
|
return !!v && typeof v === 'object' && typeof v.last4 === 'string';
|
|
824
837
|
}
|
|
@@ -1391,6 +1404,11 @@ class OzVault {
|
|
|
1391
1404
|
// the previous session and justCompleted never fires, breaking auto-advance.
|
|
1392
1405
|
if (msg.type === 'OZ_FRAME_READY') {
|
|
1393
1406
|
this.completionState.set(frameId, false);
|
|
1407
|
+
if (msg.__ozVersion !== PROTOCOL_VERSION) {
|
|
1408
|
+
console.warn(`[OzVault] Protocol version mismatch on element frame "${frameId}" — ` +
|
|
1409
|
+
`SDK expects v${PROTOCOL_VERSION}, frame reported v${typeof msg.__ozVersion === 'number' ? msg.__ozVersion : '(none)'}. ` +
|
|
1410
|
+
'Deploy the matching frame assets to elements.ozura.com and purge the Azure CDN cache.');
|
|
1411
|
+
}
|
|
1394
1412
|
}
|
|
1395
1413
|
// Intercept OZ_CHANGE before forwarding — handle auto-advance and CVV sync
|
|
1396
1414
|
if (msg.type === 'OZ_CHANGE') {
|
|
@@ -1436,6 +1454,12 @@ class OzVault {
|
|
|
1436
1454
|
var _a, _b, _c;
|
|
1437
1455
|
switch (msg.type) {
|
|
1438
1456
|
case 'OZ_FRAME_READY':
|
|
1457
|
+
if (msg.__ozVersion !== PROTOCOL_VERSION) {
|
|
1458
|
+
console.warn(`[OzVault] Protocol version mismatch — SDK expects v${PROTOCOL_VERSION}, ` +
|
|
1459
|
+
`tokenizer frame reported v${typeof msg.__ozVersion === 'number' ? msg.__ozVersion : '(none)'}. ` +
|
|
1460
|
+
'This usually means the deployed frame files are stale. ' +
|
|
1461
|
+
'Deploy the matching frame assets to elements.ozura.com and purge the Azure CDN cache.');
|
|
1462
|
+
}
|
|
1439
1463
|
this.tokenizerReady = true;
|
|
1440
1464
|
if (this.loadErrorTimeoutId != null) {
|
|
1441
1465
|
clearTimeout(this.loadErrorTimeoutId);
|
|
@@ -2018,6 +2042,71 @@ const OzCardNumber = (props) => jsx(OzFieldBase, Object.assign({ type: "cardNumb
|
|
|
2018
2042
|
const OzExpiry = (props) => jsx(OzFieldBase, Object.assign({ type: "expirationDate", variant: "card" }, props));
|
|
2019
2043
|
/** Renders a PCI-isolated CVV input inside an Ozura iframe. */
|
|
2020
2044
|
const OzCvv = (props) => jsx(OzFieldBase, Object.assign({ type: "cvv", variant: "card" }, props));
|
|
2045
|
+
// ─── Shared composite-component hook ─────────────────────────────────────────
|
|
2046
|
+
/**
|
|
2047
|
+
* Shared plumbing for OzCard and OzBankCard.
|
|
2048
|
+
*
|
|
2049
|
+
* Manages:
|
|
2050
|
+
* - Callback refs (onChange, onReady, onFocus, onBlur) kept in sync on every render
|
|
2051
|
+
* - Vault-change detection: resets `readyFieldTypes` and `onReadyFiredRef` when the
|
|
2052
|
+
* vault instance is replaced (e.g. after fetchWaxKey changes or the provider remounts)
|
|
2053
|
+
* - Per-field ready tracking: creates one stable handler per named field; fires the
|
|
2054
|
+
* `onReady` callback once all `fieldNames.length` fields have reported ready
|
|
2055
|
+
* - Error state
|
|
2056
|
+
* - Layout helpers: `gapStr`, `resolvedLabelStyle`, `renderLabel`
|
|
2057
|
+
*
|
|
2058
|
+
* @internal — not exported; used only by OzCard and OzBankCard.
|
|
2059
|
+
*/
|
|
2060
|
+
function useCardBase({ vault, fieldNames, onChange, onReady, onFocus, onBlur, gap = 8, labelStyle, labelClassName, }) {
|
|
2061
|
+
const totalFields = fieldNames.length;
|
|
2062
|
+
const readyFieldTypes = useRef(new Set());
|
|
2063
|
+
const onReadyFiredRef = useRef(false);
|
|
2064
|
+
const vaultRef = useRef(vault);
|
|
2065
|
+
const onChangeRef = useRef(onChange);
|
|
2066
|
+
const onReadyRef = useRef(onReady);
|
|
2067
|
+
const onFocusRef = useRef(onFocus);
|
|
2068
|
+
const onBlurRef = useRef(onBlur);
|
|
2069
|
+
useEffect(() => { onChangeRef.current = onChange; }, [onChange]);
|
|
2070
|
+
useEffect(() => { onReadyRef.current = onReady; }, [onReady]);
|
|
2071
|
+
useEffect(() => { onFocusRef.current = onFocus; }, [onFocus]);
|
|
2072
|
+
useEffect(() => { onBlurRef.current = onBlur; }, [onBlur]);
|
|
2073
|
+
useEffect(() => {
|
|
2074
|
+
if (vault !== vaultRef.current) {
|
|
2075
|
+
vaultRef.current = vault;
|
|
2076
|
+
readyFieldTypes.current = new Set();
|
|
2077
|
+
onReadyFiredRef.current = false;
|
|
2078
|
+
}
|
|
2079
|
+
return () => {
|
|
2080
|
+
readyFieldTypes.current = new Set();
|
|
2081
|
+
onReadyFiredRef.current = false;
|
|
2082
|
+
};
|
|
2083
|
+
}, [vault]);
|
|
2084
|
+
// One stable handler per named field — recreated only when total field count changes.
|
|
2085
|
+
// Field names are static (card = 3 fields, bank = 2 fields) so `totalFields` alone
|
|
2086
|
+
// is a sufficient dependency; a JSON dep would create a new map on every render.
|
|
2087
|
+
// CONTRACT: `fieldNames` must be a static literal — callers must not pass a dynamic
|
|
2088
|
+
// array that changes length without also changing field count.
|
|
2089
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2090
|
+
const readyHandlers = useMemo(() => {
|
|
2091
|
+
const handlers = {};
|
|
2092
|
+
for (const name of fieldNames) {
|
|
2093
|
+
handlers[name] = () => {
|
|
2094
|
+
var _a;
|
|
2095
|
+
readyFieldTypes.current.add(name);
|
|
2096
|
+
if (readyFieldTypes.current.size >= totalFields && !onReadyFiredRef.current) {
|
|
2097
|
+
onReadyFiredRef.current = true;
|
|
2098
|
+
(_a = onReadyRef.current) === null || _a === void 0 ? void 0 : _a.call(onReadyRef);
|
|
2099
|
+
}
|
|
2100
|
+
};
|
|
2101
|
+
}
|
|
2102
|
+
return handlers;
|
|
2103
|
+
}, [totalFields]); // totalFields captures fieldNames.length; field names are static
|
|
2104
|
+
const [error, setError] = useState();
|
|
2105
|
+
const gapStr = typeof gap === 'string' ? gap : `${gap}px`;
|
|
2106
|
+
const resolvedLabelStyle = useMemo(() => (labelStyle ? Object.assign(Object.assign({}, DEFAULT_LABEL_STYLE), labelStyle) : DEFAULT_LABEL_STYLE), [labelStyle]);
|
|
2107
|
+
const renderLabel = useCallback((text) => renderFieldLabel(text, labelClassName, resolvedLabelStyle), [labelClassName, resolvedLabelStyle]);
|
|
2108
|
+
return { onChangeRef, onFocusRef, onBlurRef, readyHandlers, error, setError, gapStr, resolvedLabelStyle, renderLabel };
|
|
2109
|
+
}
|
|
2021
2110
|
const DEFAULT_ERROR_STYLE = {
|
|
2022
2111
|
color: '#dc2626',
|
|
2023
2112
|
fontSize: 13,
|
|
@@ -2060,62 +2149,22 @@ function mergeStyles(base, override) {
|
|
|
2060
2149
|
function OzCard({ style, styles, classNames, labels, labelStyle, labelClassName, layout = 'default', gap = 8, hideErrors = false, errorStyle, errorClassName, renderError, onChange, onReady, onFocus, onBlur, disabled, className, placeholders, }) {
|
|
2061
2150
|
var _a, _b, _c;
|
|
2062
2151
|
const { vault } = useContext(OzContext);
|
|
2152
|
+
const { onChangeRef, onFocusRef, onBlurRef, readyHandlers, error, setError, gapStr, renderLabel, } = useCardBase({
|
|
2153
|
+
vault,
|
|
2154
|
+
fieldNames: ['cardNumber', 'expiry', 'cvv'],
|
|
2155
|
+
onChange,
|
|
2156
|
+
onReady,
|
|
2157
|
+
onFocus,
|
|
2158
|
+
onBlur,
|
|
2159
|
+
gap,
|
|
2160
|
+
labelStyle,
|
|
2161
|
+
labelClassName,
|
|
2162
|
+
});
|
|
2063
2163
|
const fieldState = useRef({
|
|
2064
2164
|
cardNumber: null,
|
|
2065
2165
|
expiry: null,
|
|
2066
2166
|
cvv: null,
|
|
2067
2167
|
});
|
|
2068
|
-
const readyFieldTypes = useRef(new Set());
|
|
2069
|
-
const onReadyFiredRef = useRef(false);
|
|
2070
|
-
const vaultRef = useRef(vault);
|
|
2071
|
-
const onChangeRef = useRef(onChange);
|
|
2072
|
-
const onReadyRef = useRef(onReady);
|
|
2073
|
-
const onFocusRef = useRef(onFocus);
|
|
2074
|
-
const onBlurRef = useRef(onBlur);
|
|
2075
|
-
useEffect(() => { onChangeRef.current = onChange; }, [onChange]);
|
|
2076
|
-
useEffect(() => { onReadyRef.current = onReady; }, [onReady]);
|
|
2077
|
-
useEffect(() => { onFocusRef.current = onFocus; }, [onFocus]);
|
|
2078
|
-
useEffect(() => { onBlurRef.current = onBlur; }, [onBlur]);
|
|
2079
|
-
// When the vault is recreated (e.g. appearance/fonts props change on OzElements),
|
|
2080
|
-
// context readyCount is reset but this ref is not. Reset so onReady fires once when all 3 are ready.
|
|
2081
|
-
// The cleanup resets readyFieldTypes when the component unmounts (covers React StrictMode double-invoke
|
|
2082
|
-
// and SPA scenarios where the parent re-mounts this component).
|
|
2083
|
-
useEffect(() => {
|
|
2084
|
-
if (vault !== vaultRef.current) {
|
|
2085
|
-
vaultRef.current = vault;
|
|
2086
|
-
readyFieldTypes.current = new Set();
|
|
2087
|
-
onReadyFiredRef.current = false;
|
|
2088
|
-
}
|
|
2089
|
-
return () => {
|
|
2090
|
-
readyFieldTypes.current = new Set();
|
|
2091
|
-
onReadyFiredRef.current = false;
|
|
2092
|
-
};
|
|
2093
|
-
}, [vault]);
|
|
2094
|
-
const [error, setError] = useState();
|
|
2095
|
-
const handleCardNumberReady = useCallback(() => {
|
|
2096
|
-
var _a;
|
|
2097
|
-
readyFieldTypes.current.add('cardNumber');
|
|
2098
|
-
if (readyFieldTypes.current.size >= 3 && !onReadyFiredRef.current) {
|
|
2099
|
-
onReadyFiredRef.current = true;
|
|
2100
|
-
(_a = onReadyRef.current) === null || _a === void 0 ? void 0 : _a.call(onReadyRef);
|
|
2101
|
-
}
|
|
2102
|
-
}, []);
|
|
2103
|
-
const handleExpiryReady = useCallback(() => {
|
|
2104
|
-
var _a;
|
|
2105
|
-
readyFieldTypes.current.add('expiry');
|
|
2106
|
-
if (readyFieldTypes.current.size >= 3 && !onReadyFiredRef.current) {
|
|
2107
|
-
onReadyFiredRef.current = true;
|
|
2108
|
-
(_a = onReadyRef.current) === null || _a === void 0 ? void 0 : _a.call(onReadyRef);
|
|
2109
|
-
}
|
|
2110
|
-
}, []);
|
|
2111
|
-
const handleCvvReady = useCallback(() => {
|
|
2112
|
-
var _a;
|
|
2113
|
-
readyFieldTypes.current.add('cvv');
|
|
2114
|
-
if (readyFieldTypes.current.size >= 3 && !onReadyFiredRef.current) {
|
|
2115
|
-
onReadyFiredRef.current = true;
|
|
2116
|
-
(_a = onReadyRef.current) === null || _a === void 0 ? void 0 : _a.call(onReadyRef);
|
|
2117
|
-
}
|
|
2118
|
-
}, []);
|
|
2119
2168
|
const emitChange = useCallback(() => {
|
|
2120
2169
|
var _a;
|
|
2121
2170
|
const { cardNumber, expiry, cvv } = fieldState.current;
|
|
@@ -2130,20 +2179,16 @@ function OzCard({ style, styles, classNames, labels, labelStyle, labelClassName,
|
|
|
2130
2179
|
error: err,
|
|
2131
2180
|
fields: Object.assign({}, fieldState.current),
|
|
2132
2181
|
});
|
|
2133
|
-
}, []);
|
|
2134
|
-
const gapStr = typeof gap === 'string' ? gap : `${gap}px`;
|
|
2135
|
-
const resolvedLabelStyle = labelStyle
|
|
2136
|
-
? Object.assign(Object.assign({}, DEFAULT_LABEL_STYLE), labelStyle) : DEFAULT_LABEL_STYLE;
|
|
2137
|
-
const renderLabel = (text) => renderFieldLabel(text, labelClassName, resolvedLabelStyle);
|
|
2182
|
+
}, [setError, onChangeRef]);
|
|
2138
2183
|
const showError = !hideErrors && error;
|
|
2139
2184
|
const errorNode = showError
|
|
2140
2185
|
? renderError
|
|
2141
2186
|
? renderError(error)
|
|
2142
2187
|
: (jsx("div", { role: "alert", className: errorClassName, style: errorStyle ? Object.assign(Object.assign({}, DEFAULT_ERROR_STYLE), errorStyle) : DEFAULT_ERROR_STYLE, children: error }))
|
|
2143
2188
|
: null;
|
|
2144
|
-
const cardNumberField = (jsxs("div", { children: [renderLabel(labels === null || labels === void 0 ? void 0 : labels.cardNumber), jsx(OzCardNumber, { style: mergeStyles(style, styles === null || styles === void 0 ? void 0 : styles.cardNumber), className: classNames === null || classNames === void 0 ? void 0 : classNames.cardNumber, placeholder: (_a = placeholders === null || placeholders === void 0 ? void 0 : placeholders.cardNumber) !== null && _a !== void 0 ? _a : 'Card number', disabled: disabled, onChange: (e) => { fieldState.current.cardNumber = e; emitChange(); }, onFocus: () => { var _a; return (_a = onFocusRef.current) === null || _a === void 0 ? void 0 : _a.call(onFocusRef, 'cardNumber'); }, onBlur: () => { var _a; return (_a = onBlurRef.current) === null || _a === void 0 ? void 0 : _a.call(onBlurRef, 'cardNumber'); }, onReady:
|
|
2145
|
-
const expiryField = (jsxs("div", { style: layout === 'default' ? { flex: 1 } : undefined, children: [renderLabel(labels === null || labels === void 0 ? void 0 : labels.expiry), jsx(OzExpiry, { style: mergeStyles(style, styles === null || styles === void 0 ? void 0 : styles.expiry), className: classNames === null || classNames === void 0 ? void 0 : classNames.expiry, placeholder: (_b = placeholders === null || placeholders === void 0 ? void 0 : placeholders.expiry) !== null && _b !== void 0 ? _b : 'MM / YY', disabled: disabled, onChange: (e) => { fieldState.current.expiry = e; emitChange(); }, onFocus: () => { var _a; return (_a = onFocusRef.current) === null || _a === void 0 ? void 0 : _a.call(onFocusRef, 'expiry'); }, onBlur: () => { var _a; return (_a = onBlurRef.current) === null || _a === void 0 ? void 0 : _a.call(onBlurRef, 'expiry'); }, onReady:
|
|
2146
|
-
const cvvField = (jsxs("div", { style: layout === 'default' ? { flex: 1 } : undefined, children: [renderLabel(labels === null || labels === void 0 ? void 0 : labels.cvv), jsx(OzCvv, { style: mergeStyles(style, styles === null || styles === void 0 ? void 0 : styles.cvv), className: classNames === null || classNames === void 0 ? void 0 : classNames.cvv, placeholder: (_c = placeholders === null || placeholders === void 0 ? void 0 : placeholders.cvv) !== null && _c !== void 0 ? _c : 'CVV', disabled: disabled, onChange: (e) => { fieldState.current.cvv = e; emitChange(); }, onFocus: () => { var _a; return (_a = onFocusRef.current) === null || _a === void 0 ? void 0 : _a.call(onFocusRef, 'cvv'); }, onBlur: () => { var _a; return (_a = onBlurRef.current) === null || _a === void 0 ? void 0 : _a.call(onBlurRef, 'cvv'); }, onReady:
|
|
2189
|
+
const cardNumberField = (jsxs("div", { children: [renderLabel(labels === null || labels === void 0 ? void 0 : labels.cardNumber), jsx(OzCardNumber, { style: mergeStyles(style, styles === null || styles === void 0 ? void 0 : styles.cardNumber), className: classNames === null || classNames === void 0 ? void 0 : classNames.cardNumber, placeholder: (_a = placeholders === null || placeholders === void 0 ? void 0 : placeholders.cardNumber) !== null && _a !== void 0 ? _a : 'Card number', disabled: disabled, onChange: (e) => { fieldState.current.cardNumber = e; emitChange(); }, onFocus: () => { var _a; return (_a = onFocusRef.current) === null || _a === void 0 ? void 0 : _a.call(onFocusRef, 'cardNumber'); }, onBlur: () => { var _a; return (_a = onBlurRef.current) === null || _a === void 0 ? void 0 : _a.call(onBlurRef, 'cardNumber'); }, onReady: readyHandlers['cardNumber'] })] }));
|
|
2190
|
+
const expiryField = (jsxs("div", { style: layout === 'default' ? { flex: 1 } : undefined, children: [renderLabel(labels === null || labels === void 0 ? void 0 : labels.expiry), jsx(OzExpiry, { style: mergeStyles(style, styles === null || styles === void 0 ? void 0 : styles.expiry), className: classNames === null || classNames === void 0 ? void 0 : classNames.expiry, placeholder: (_b = placeholders === null || placeholders === void 0 ? void 0 : placeholders.expiry) !== null && _b !== void 0 ? _b : 'MM / YY', disabled: disabled, onChange: (e) => { fieldState.current.expiry = e; emitChange(); }, onFocus: () => { var _a; return (_a = onFocusRef.current) === null || _a === void 0 ? void 0 : _a.call(onFocusRef, 'expiry'); }, onBlur: () => { var _a; return (_a = onBlurRef.current) === null || _a === void 0 ? void 0 : _a.call(onBlurRef, 'expiry'); }, onReady: readyHandlers['expiry'] })] }));
|
|
2191
|
+
const cvvField = (jsxs("div", { style: layout === 'default' ? { flex: 1 } : undefined, children: [renderLabel(labels === null || labels === void 0 ? void 0 : labels.cvv), jsx(OzCvv, { style: mergeStyles(style, styles === null || styles === void 0 ? void 0 : styles.cvv), className: classNames === null || classNames === void 0 ? void 0 : classNames.cvv, placeholder: (_c = placeholders === null || placeholders === void 0 ? void 0 : placeholders.cvv) !== null && _c !== void 0 ? _c : 'CVV', disabled: disabled, onChange: (e) => { fieldState.current.cvv = e; emitChange(); }, onFocus: () => { var _a; return (_a = onFocusRef.current) === null || _a === void 0 ? void 0 : _a.call(onFocusRef, 'cvv'); }, onBlur: () => { var _a; return (_a = onBlurRef.current) === null || _a === void 0 ? void 0 : _a.call(onBlurRef, 'cvv'); }, onReady: readyHandlers['cvv'] })] }));
|
|
2147
2192
|
if (layout === 'rows') {
|
|
2148
2193
|
return (jsxs("div", { className: className, style: { width: '100%', display: 'flex', flexDirection: 'column', gap: gapStr }, children: [cardNumberField, expiryField, cvvField, errorNode] }));
|
|
2149
2194
|
}
|
|
@@ -2164,49 +2209,21 @@ const OzBankRoutingNumber = (props) => jsx(OzFieldBase, Object.assign({ type: "r
|
|
|
2164
2209
|
function OzBankCard({ style, styles, classNames, labels, labelStyle, labelClassName, gap = 8, hideErrors = false, errorStyle, errorClassName, renderError, onChange, onReady, onFocus, onBlur, disabled, className, placeholders, }) {
|
|
2165
2210
|
var _a, _b;
|
|
2166
2211
|
const { vault } = useContext(OzContext);
|
|
2212
|
+
const { onChangeRef, onFocusRef, onBlurRef, readyHandlers, error, setError, gapStr, renderLabel, } = useCardBase({
|
|
2213
|
+
vault,
|
|
2214
|
+
fieldNames: ['accountNumber', 'routingNumber'],
|
|
2215
|
+
onChange,
|
|
2216
|
+
onReady,
|
|
2217
|
+
onFocus,
|
|
2218
|
+
onBlur,
|
|
2219
|
+
gap,
|
|
2220
|
+
labelStyle,
|
|
2221
|
+
labelClassName,
|
|
2222
|
+
});
|
|
2167
2223
|
const fieldState = useRef({
|
|
2168
2224
|
accountNumber: null,
|
|
2169
2225
|
routingNumber: null,
|
|
2170
2226
|
});
|
|
2171
|
-
const readyFieldTypes = useRef(new Set());
|
|
2172
|
-
const onReadyFiredRef = useRef(false);
|
|
2173
|
-
const vaultRef = useRef(vault);
|
|
2174
|
-
const onChangeRef = useRef(onChange);
|
|
2175
|
-
const onReadyRef = useRef(onReady);
|
|
2176
|
-
const onFocusRef = useRef(onFocus);
|
|
2177
|
-
const onBlurRef = useRef(onBlur);
|
|
2178
|
-
useEffect(() => { onChangeRef.current = onChange; }, [onChange]);
|
|
2179
|
-
useEffect(() => { onReadyRef.current = onReady; }, [onReady]);
|
|
2180
|
-
useEffect(() => { onFocusRef.current = onFocus; }, [onFocus]);
|
|
2181
|
-
useEffect(() => { onBlurRef.current = onBlur; }, [onBlur]);
|
|
2182
|
-
useEffect(() => {
|
|
2183
|
-
if (vault !== vaultRef.current) {
|
|
2184
|
-
vaultRef.current = vault;
|
|
2185
|
-
readyFieldTypes.current = new Set();
|
|
2186
|
-
onReadyFiredRef.current = false;
|
|
2187
|
-
}
|
|
2188
|
-
return () => {
|
|
2189
|
-
readyFieldTypes.current = new Set();
|
|
2190
|
-
onReadyFiredRef.current = false;
|
|
2191
|
-
};
|
|
2192
|
-
}, [vault]);
|
|
2193
|
-
const [error, setError] = useState();
|
|
2194
|
-
const handleAccountReady = useCallback(() => {
|
|
2195
|
-
var _a;
|
|
2196
|
-
readyFieldTypes.current.add('accountNumber');
|
|
2197
|
-
if (readyFieldTypes.current.size >= 2 && !onReadyFiredRef.current) {
|
|
2198
|
-
onReadyFiredRef.current = true;
|
|
2199
|
-
(_a = onReadyRef.current) === null || _a === void 0 ? void 0 : _a.call(onReadyRef);
|
|
2200
|
-
}
|
|
2201
|
-
}, []);
|
|
2202
|
-
const handleRoutingReady = useCallback(() => {
|
|
2203
|
-
var _a;
|
|
2204
|
-
readyFieldTypes.current.add('routingNumber');
|
|
2205
|
-
if (readyFieldTypes.current.size >= 2 && !onReadyFiredRef.current) {
|
|
2206
|
-
onReadyFiredRef.current = true;
|
|
2207
|
-
(_a = onReadyRef.current) === null || _a === void 0 ? void 0 : _a.call(onReadyRef);
|
|
2208
|
-
}
|
|
2209
|
-
}, []);
|
|
2210
2227
|
const emitChange = useCallback(() => {
|
|
2211
2228
|
var _a;
|
|
2212
2229
|
const { accountNumber, routingNumber } = fieldState.current;
|
|
@@ -2219,18 +2236,14 @@ function OzBankCard({ style, styles, classNames, labels, labelStyle, labelClassN
|
|
|
2219
2236
|
error: err,
|
|
2220
2237
|
fields: Object.assign({}, fieldState.current),
|
|
2221
2238
|
});
|
|
2222
|
-
}, []);
|
|
2223
|
-
const gapStr = typeof gap === 'string' ? gap : `${gap}px`;
|
|
2224
|
-
const resolvedLabelStyle = labelStyle
|
|
2225
|
-
? Object.assign(Object.assign({}, DEFAULT_LABEL_STYLE), labelStyle) : DEFAULT_LABEL_STYLE;
|
|
2226
|
-
const renderLabel = (text) => renderFieldLabel(text, labelClassName, resolvedLabelStyle);
|
|
2239
|
+
}, [setError, onChangeRef]);
|
|
2227
2240
|
const showError = !hideErrors && error;
|
|
2228
2241
|
const errorNode = showError
|
|
2229
2242
|
? renderError
|
|
2230
2243
|
? renderError(error)
|
|
2231
2244
|
: (jsx("div", { role: "alert", className: errorClassName, style: errorStyle ? Object.assign(Object.assign({}, DEFAULT_ERROR_STYLE), errorStyle) : DEFAULT_ERROR_STYLE, children: error }))
|
|
2232
2245
|
: null;
|
|
2233
|
-
return (jsxs("div", { className: className, style: { width: '100%', display: 'flex', flexDirection: 'column', gap: gapStr }, children: [jsxs("div", { children: [renderLabel(labels === null || labels === void 0 ? void 0 : labels.accountNumber), jsx(OzBankAccountNumber, { style: mergeStyles(style, styles === null || styles === void 0 ? void 0 : styles.accountNumber), className: classNames === null || classNames === void 0 ? void 0 : classNames.accountNumber, placeholder: (_a = placeholders === null || placeholders === void 0 ? void 0 : placeholders.accountNumber) !== null && _a !== void 0 ? _a : 'Account number', disabled: disabled, onChange: (e) => { fieldState.current.accountNumber = e; emitChange(); }, onFocus: () => { var _a; return (_a = onFocusRef.current) === null || _a === void 0 ? void 0 : _a.call(onFocusRef, 'accountNumber'); }, onBlur: () => { var _a; return (_a = onBlurRef.current) === null || _a === void 0 ? void 0 : _a.call(onBlurRef, 'accountNumber'); }, onReady:
|
|
2246
|
+
return (jsxs("div", { className: className, style: { width: '100%', display: 'flex', flexDirection: 'column', gap: gapStr }, children: [jsxs("div", { children: [renderLabel(labels === null || labels === void 0 ? void 0 : labels.accountNumber), jsx(OzBankAccountNumber, { style: mergeStyles(style, styles === null || styles === void 0 ? void 0 : styles.accountNumber), className: classNames === null || classNames === void 0 ? void 0 : classNames.accountNumber, placeholder: (_a = placeholders === null || placeholders === void 0 ? void 0 : placeholders.accountNumber) !== null && _a !== void 0 ? _a : 'Account number', disabled: disabled, onChange: (e) => { fieldState.current.accountNumber = e; emitChange(); }, onFocus: () => { var _a; return (_a = onFocusRef.current) === null || _a === void 0 ? void 0 : _a.call(onFocusRef, 'accountNumber'); }, onBlur: () => { var _a; return (_a = onBlurRef.current) === null || _a === void 0 ? void 0 : _a.call(onBlurRef, 'accountNumber'); }, onReady: readyHandlers['accountNumber'] })] }), jsxs("div", { children: [renderLabel(labels === null || labels === void 0 ? void 0 : labels.routingNumber), jsx(OzBankRoutingNumber, { style: mergeStyles(style, styles === null || styles === void 0 ? void 0 : styles.routingNumber), className: classNames === null || classNames === void 0 ? void 0 : classNames.routingNumber, placeholder: (_b = placeholders === null || placeholders === void 0 ? void 0 : placeholders.routingNumber) !== null && _b !== void 0 ? _b : 'Routing number', disabled: disabled, onChange: (e) => { fieldState.current.routingNumber = e; emitChange(); }, onFocus: () => { var _a; return (_a = onFocusRef.current) === null || _a === void 0 ? void 0 : _a.call(onFocusRef, 'routingNumber'); }, onBlur: () => { var _a; return (_a = onBlurRef.current) === null || _a === void 0 ? void 0 : _a.call(onBlurRef, 'routingNumber'); }, onReady: readyHandlers['routingNumber'] })] }), errorNode] }));
|
|
2234
2247
|
}
|
|
2235
2248
|
|
|
2236
2249
|
export { OzBankAccountNumber, OzBankCard, OzBankRoutingNumber, OzCard, OzCardNumber, OzCvv, OzElements, OzExpiry, createFetchWaxKey, useOzElements };
|