@test-glide/payment-react-native 0.1.3 → 0.1.5
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/README.md +1 -1
- package/lib/module/components/BivoCVCInput.js +4 -4
- package/lib/module/components/BivoCVCInput.js.map +1 -1
- package/lib/module/components/BivoCardInput.js +4 -4
- package/lib/module/components/BivoCardInput.js.map +1 -1
- package/lib/module/components/BivoTextInput.js +4 -4
- package/lib/module/components/BivoTextInput.js.map +1 -1
- package/lib/module/core/{Collector.js → BivoSecureStore.js} +50 -31
- package/lib/module/core/BivoSecureStore.js.map +1 -0
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/components/BivoCVCInput.d.ts +2 -2
- package/lib/typescript/src/components/BivoCVCInput.d.ts.map +1 -1
- package/lib/typescript/src/components/BivoCardInput.d.ts +2 -2
- package/lib/typescript/src/components/BivoCardInput.d.ts.map +1 -1
- package/lib/typescript/src/components/BivoTextInput.d.ts +2 -2
- package/lib/typescript/src/components/BivoTextInput.d.ts.map +1 -1
- package/lib/typescript/src/core/{Collector.d.ts → BivoSecureStore.d.ts} +5 -13
- package/lib/typescript/src/core/BivoSecureStore.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/BivoCVCInput.tsx +6 -6
- package/src/components/BivoCardInput.tsx +6 -6
- package/src/components/BivoTextInput.tsx +6 -6
- package/src/core/BivoSecureStore.ts +175 -0
- package/src/index.ts +1 -1
- package/lib/module/core/Collector.js.map +0 -1
- package/lib/module/utils/fetch.js +0 -47
- package/lib/module/utils/fetch.js.map +0 -1
- package/lib/typescript/src/core/Collector.d.ts.map +0 -1
- package/lib/typescript/src/utils/fetch.d.ts +0 -13
- package/lib/typescript/src/utils/fetch.d.ts.map +0 -1
- package/src/core/Collector.ts +0 -131
- package/src/utils/fetch.ts +0 -58
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ npm install @bivo/payment-react-native
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
```js
|
|
17
|
-
import {
|
|
17
|
+
import { BivoSecureStore, BivoTextInput, BivoCardInput, BivoCVCInput } from '@bivo/payment-react-native';
|
|
18
18
|
|
|
19
19
|
```
|
|
20
20
|
|
|
@@ -5,7 +5,7 @@ import { View, TextInput, Text, StyleSheet, Image } from 'react-native';
|
|
|
5
5
|
import { Icons } from "../assets/index.js";
|
|
6
6
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
7
7
|
export const BivoCVCInput = ({
|
|
8
|
-
|
|
8
|
+
bivoStore,
|
|
9
9
|
fieldName,
|
|
10
10
|
placeholder,
|
|
11
11
|
onStateChange,
|
|
@@ -18,12 +18,12 @@ export const BivoCVCInput = ({
|
|
|
18
18
|
const [value, setValue] = useState('');
|
|
19
19
|
const handleChange = text => {
|
|
20
20
|
setValue(text);
|
|
21
|
-
|
|
21
|
+
bivoStore.setField(fieldName, text, onStateChange, required, regex, errorMsg);
|
|
22
22
|
};
|
|
23
23
|
const handleBlur = () => {
|
|
24
|
-
|
|
24
|
+
bivoStore.setField(fieldName, value, onStateChange, required, regex, errorMsg);
|
|
25
25
|
};
|
|
26
|
-
const error =
|
|
26
|
+
const error = bivoStore.errors[fieldName];
|
|
27
27
|
return /*#__PURE__*/_jsxs(View, {
|
|
28
28
|
style: [styles.container, containerStyle],
|
|
29
29
|
children: [/*#__PURE__*/_jsx(TextInput, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","useState","View","TextInput","Text","StyleSheet","Image","Icons","jsx","_jsx","jsxs","_jsxs","BivoCVCInput","
|
|
1
|
+
{"version":3,"names":["React","useState","View","TextInput","Text","StyleSheet","Image","Icons","jsx","_jsx","jsxs","_jsxs","BivoCVCInput","bivoStore","fieldName","placeholder","onStateChange","required","regex","errorMsg","containerStyle","textStyle","value","setValue","handleChange","text","setField","handleBlur","error","errors","style","styles","container","children","onChangeText","onBlur","secureTextEntry","keyboardType","input","borderColor","errorContainer","source","alert","errorIcon","create","marginVertical","borderWidth","borderRadius","padding","flexDirection","alignItems","marginTop","minHeight","width","height","marginRight","color","fontSize"],"sourceRoot":"../../../src","sources":["components/BivoCVCInput.tsx"],"mappings":";;AAAA,OAAOA,KAAK,IAAIC,QAAQ,QAAQ,OAAO;AACvC,SAASC,IAAI,EAAEC,SAAS,EAAEC,IAAI,EAAEC,UAAU,EAAEC,KAAK,QAAQ,cAAc;AAGvE,SAASC,KAAK,QAAQ,oBAAW;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAclC,OAAO,MAAMC,YAA6B,GAAGA,CAAC;EAC5CC,SAAS;EACTC,SAAS;EACTC,WAAW;EACXC,aAAa;EACbC,QAAQ;EACRC,KAAK;EACLC,QAAQ;EACRC,cAAc;EACdC;AACF,CAAC,KAAK;EACJ,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAGtB,QAAQ,CAAC,EAAE,CAAC;EAEtC,MAAMuB,YAAY,GAAIC,IAAY,IAAK;IACrCF,QAAQ,CAACE,IAAI,CAAC;IACdZ,SAAS,CAACa,QAAQ,CAChBZ,SAAS,EACTW,IAAI,EACJT,aAAa,EACbC,QAAQ,EACRC,KAAK,EACLC,QACF,CAAC;EACH,CAAC;EAED,MAAMQ,UAAU,GAAGA,CAAA,KAAM;IACvBd,SAAS,CAACa,QAAQ,CAChBZ,SAAS,EACTQ,KAAK,EACLN,aAAa,EACbC,QAAQ,EACRC,KAAK,EACLC,QACF,CAAC;EACH,CAAC;EAED,MAAMS,KAAK,GAAGf,SAAS,CAACgB,MAAM,CAACf,SAAS,CAAC;EAEzC,oBACEH,KAAA,CAACT,IAAI;IAAC4B,KAAK,EAAE,CAACC,MAAM,CAACC,SAAS,EAAEZ,cAAc,CAAE;IAAAa,QAAA,gBAC9CxB,IAAA,CAACN,SAAS;MACRmB,KAAK,EA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|
|
13
13
|
unknown: Icons.card
|
|
14
14
|
};
|
|
15
15
|
export const BivoCardInput = ({
|
|
16
|
-
|
|
16
|
+
bivoStore,
|
|
17
17
|
fieldName,
|
|
18
18
|
placeholder,
|
|
19
19
|
onStateChange,
|
|
@@ -31,12 +31,12 @@ export const BivoCardInput = ({
|
|
|
31
31
|
setValue(formatted);
|
|
32
32
|
const cleaned = text.replace(/\D/g, '');
|
|
33
33
|
if (/^4/.test(cleaned)) setCardType('visa');else if (/^5[1-5]/.test(cleaned)) setCardType('mastercard');else if (/^3[47]/.test(cleaned)) setCardType('amex');else if (/^6(?:011|5)/.test(cleaned)) setCardType('discover');else setCardType('unknown');
|
|
34
|
-
|
|
34
|
+
bivoStore.setField(fieldName, text, onStateChange, required, regex, errorMsg);
|
|
35
35
|
};
|
|
36
36
|
const handleBlur = () => {
|
|
37
|
-
|
|
37
|
+
bivoStore.setField(fieldName, value, onStateChange, required, regex, errorMsg);
|
|
38
38
|
};
|
|
39
|
-
const error =
|
|
39
|
+
const error = bivoStore.errors[fieldName];
|
|
40
40
|
return /*#__PURE__*/_jsxs(View, {
|
|
41
41
|
style: [styles.container, containerStyle],
|
|
42
42
|
children: [/*#__PURE__*/_jsxs(View, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","useState","View","TextInput","Image","Text","StyleSheet","Icons","formatCardNumber","jsx","_jsx","jsxs","_jsxs","cardIcons","visa","mastercard","amex","discover","unknown","card","BivoCardInput","
|
|
1
|
+
{"version":3,"names":["React","useState","View","TextInput","Image","Text","StyleSheet","Icons","formatCardNumber","jsx","_jsx","jsxs","_jsxs","cardIcons","visa","mastercard","amex","discover","unknown","card","BivoCardInput","bivoStore","fieldName","placeholder","onStateChange","required","regex","errorMsg","containerStyle","textStyle","value","setValue","cardType","setCardType","handleChange","text","formatted","cleaned","replace","test","setField","handleBlur","error","errors","style","styles","container","children","row","source","icon","onChangeText","onBlur","keyboardType","input","borderColor","errorContainer","alert","errorIcon","create","marginVertical","flexDirection","alignItems","flex","borderWidth","borderRadius","padding","width","height","resizeMode","marginRight","marginLeft","marginTop","minHeight","color","fontSize"],"sourceRoot":"../../../src","sources":["components/BivoCardInput.tsx"],"mappings":";;AAAA,OAAOA,KAAK,IAAIC,QAAQ,QAAQ,OAAO;AACvC,SAASC,IAAI,EAAEC,SAAS,EAAEC,KAAK,EAAEC,IAAI,EAAEC,UAAU,QAAQ,cAAc;AAGvE,SAASC,KAAK,QAAQ,oBAAW;AACjC,SAASC,gBAAgB,QAAQ,mBAAgB;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAclD,MAAMC,SAAc,GAAG;EACrBC,IAAI,EAAEP,KAAK,CAACO,IAAI;EAChBC,UAAU,EAAER,KAAK,CAACQ,UAAU;EAC5BC,IAAI,EAAET,KAAK,CAACS,IAAI;EAChBC,QAAQ,EAAEV,KAAK,CAACU,QAAQ;EACxBC,OAAO,EAAEX,KAAK,CAACY;AACjB,CAAC;AAED,OAAO,MAAMC,aAA8B,GAAGA,CAAC;EAC7CC,SAAS;EACTC,SAAS;EACTC,WAAW;EACXC,aAAa;EACbC,QAAQ;EACRC,KAAK;EACLC,QAAQ;EACRC,cAAc;EACdC;AACF,CAAC,KAAK;EACJ,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAG9B,QAAQ,CAAC,EAAE,CAAC;EACtC,MAAM,CAAC+B,QAAQ,EAAEC,WAAW,CAAC,GAAGhC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC;;EAErD,MAAMiC,YAAY,GAAIC,IAAY,IAAK;IACrC,MAAMC,SAAS,GAAG5B,gBAAgB,CAAC2B,IAAI,CAAC;IACxCJ,QAAQ,CAACK,SAAS,CAAC;IACnB,MAAMC,OAAO,GAAGF,IAAI,CAACG,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;IACvC,IAAI,IAAI,CAACC,IAAI,CAACF,OAAO,CAAC,EAAEJ,WAAW,CAAC,M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
|
|
@@ -6,7 +6,7 @@ import { Icons } from "../assets/index.js";
|
|
|
6
6
|
import { formatExpiry } from "../utils/utils.js";
|
|
7
7
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
8
8
|
export const BivoTextInput = ({
|
|
9
|
-
|
|
9
|
+
bivoStore,
|
|
10
10
|
fieldName,
|
|
11
11
|
placeholder,
|
|
12
12
|
onStateChange,
|
|
@@ -25,12 +25,12 @@ export const BivoTextInput = ({
|
|
|
25
25
|
updatedValue = text;
|
|
26
26
|
}
|
|
27
27
|
setValue(updatedValue);
|
|
28
|
-
|
|
28
|
+
bivoStore.setField(fieldName, updatedValue, onStateChange, required, regex, errorMsg);
|
|
29
29
|
};
|
|
30
30
|
const handleBlur = () => {
|
|
31
|
-
|
|
31
|
+
bivoStore.setField(fieldName, value, onStateChange, required, regex, errorMsg);
|
|
32
32
|
};
|
|
33
|
-
const error =
|
|
33
|
+
const error = bivoStore.errors[fieldName];
|
|
34
34
|
return /*#__PURE__*/_jsxs(View, {
|
|
35
35
|
style: [styles.container, containerStyle],
|
|
36
36
|
children: [/*#__PURE__*/_jsx(TextInput, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","useState","View","TextInput","Text","StyleSheet","Image","Icons","formatExpiry","jsx","_jsx","jsxs","_jsxs","BivoTextInput","
|
|
1
|
+
{"version":3,"names":["React","useState","View","TextInput","Text","StyleSheet","Image","Icons","formatExpiry","jsx","_jsx","jsxs","_jsxs","BivoTextInput","bivoStore","fieldName","placeholder","onStateChange","required","regex","errorMsg","containerStyle","textStyle","value","setValue","handleChange","text","updatedValue","setField","handleBlur","error","errors","style","styles","container","children","onChangeText","onBlur","input","borderColor","errorContainer","source","alert","errorIcon","create","marginVertical","borderWidth","borderRadius","padding","flexDirection","alignItems","marginTop","minHeight","width","height","marginRight","color","fontSize"],"sourceRoot":"../../../src","sources":["components/BivoTextInput.tsx"],"mappings":";;AAAA,OAAOA,KAAK,IAAIC,Q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} from "../utils/utils.js";
|
|
5
|
-
|
|
4
|
+
async function fetchData(url, options = {}) {
|
|
5
|
+
const response = await fetch(url, {
|
|
6
|
+
method: options.method || 'GET',
|
|
7
|
+
headers: {
|
|
8
|
+
'Content-Type': 'application/json',
|
|
9
|
+
...(options.headers || {})
|
|
10
|
+
},
|
|
11
|
+
body: options.body ? JSON.stringify(options.body) : undefined
|
|
12
|
+
});
|
|
13
|
+
return response.json();
|
|
14
|
+
}
|
|
15
|
+
export class BivoSecureStore {
|
|
6
16
|
form = {};
|
|
7
17
|
errors = {};
|
|
8
18
|
fieldConfig = {};
|
|
@@ -12,13 +22,24 @@ export class BivoCollect {
|
|
|
12
22
|
}
|
|
13
23
|
setField(fieldName, value, onStateChange, required = false, regex, errorMsg) {
|
|
14
24
|
this.form[fieldName] = value;
|
|
25
|
+
// convert string regex to RegExp
|
|
26
|
+
let parsedRegex = undefined;
|
|
27
|
+
if (typeof regex === 'string') {
|
|
28
|
+
try {
|
|
29
|
+
parsedRegex = new RegExp(regex);
|
|
30
|
+
} catch (e) {
|
|
31
|
+
console.error('Invalid regex:', regex, e);
|
|
32
|
+
}
|
|
33
|
+
} else {
|
|
34
|
+
parsedRegex = regex;
|
|
35
|
+
}
|
|
15
36
|
this.fieldConfig[fieldName] = {
|
|
16
37
|
required,
|
|
17
|
-
regex,
|
|
38
|
+
regex: parsedRegex,
|
|
18
39
|
errorMsg
|
|
19
40
|
};
|
|
20
|
-
const error = this.validateField(fieldName, value, required,
|
|
21
|
-
this.errors[fieldName] = error ||
|
|
41
|
+
const error = this.validateField(fieldName, value, required, parsedRegex, errorMsg);
|
|
42
|
+
this.errors[fieldName] = error || '';
|
|
22
43
|
onStateChange?.({
|
|
23
44
|
value,
|
|
24
45
|
error
|
|
@@ -28,45 +49,45 @@ export class BivoCollect {
|
|
|
28
49
|
const trimmedValue = value?.trim();
|
|
29
50
|
|
|
30
51
|
// Required check
|
|
31
|
-
if (!trimmedValue && required) return
|
|
52
|
+
if (!trimmedValue && required) return 'Required';
|
|
32
53
|
|
|
33
54
|
// If custom regex is provided → use it first
|
|
34
55
|
if (regex && trimmedValue) {
|
|
35
56
|
if (!regex.test(trimmedValue)) {
|
|
36
|
-
return errorMsg ||
|
|
57
|
+
return errorMsg || 'Invalid value';
|
|
37
58
|
}
|
|
38
|
-
return
|
|
59
|
+
return '';
|
|
39
60
|
}
|
|
40
61
|
|
|
41
62
|
// Default validations
|
|
42
63
|
switch (fieldName) {
|
|
43
|
-
case
|
|
64
|
+
case 'card':
|
|
44
65
|
{
|
|
45
|
-
const digits = trimmedValue.replace(/\D/g,
|
|
46
|
-
if (digits.length < 12) return
|
|
66
|
+
const digits = trimmedValue.replace(/\D/g, '');
|
|
67
|
+
if (digits.length < 12) return 'Invalid card number';
|
|
47
68
|
break;
|
|
48
69
|
}
|
|
49
|
-
case
|
|
70
|
+
case 'cvv':
|
|
50
71
|
{
|
|
51
72
|
if (!/^\d{3,4}$/.test(trimmedValue)) {
|
|
52
|
-
return
|
|
73
|
+
return 'Invalid CVV';
|
|
53
74
|
}
|
|
54
75
|
break;
|
|
55
76
|
}
|
|
56
|
-
case
|
|
77
|
+
case 'exp':
|
|
57
78
|
{
|
|
58
79
|
// Format check MM/YY
|
|
59
80
|
if (!/^\d{2}\/\d{2}$/.test(trimmedValue)) {
|
|
60
|
-
return
|
|
81
|
+
return 'Invalid expiry';
|
|
61
82
|
}
|
|
62
|
-
const [monthStr, yearStr] = trimmedValue.split(
|
|
83
|
+
const [monthStr, yearStr] = trimmedValue.split('/');
|
|
63
84
|
if (!monthStr || !yearStr) {
|
|
64
|
-
return
|
|
85
|
+
return 'Invalid expiry';
|
|
65
86
|
}
|
|
66
87
|
const month = parseInt(monthStr, 10);
|
|
67
88
|
const year = parseInt(yearStr, 10);
|
|
68
89
|
if (month < 1 || month > 12) {
|
|
69
|
-
return
|
|
90
|
+
return 'Invalid month';
|
|
70
91
|
}
|
|
71
92
|
|
|
72
93
|
// Convert YY → YYYY (assume 2000-2099)
|
|
@@ -77,51 +98,49 @@ export class BivoCollect {
|
|
|
77
98
|
|
|
78
99
|
// Expiry check
|
|
79
100
|
if (fullYear < currentYear || fullYear === currentYear && month < currentMonth) {
|
|
80
|
-
return
|
|
101
|
+
return 'Card expired';
|
|
81
102
|
}
|
|
82
103
|
break;
|
|
83
104
|
}
|
|
84
105
|
}
|
|
85
|
-
return
|
|
106
|
+
return '';
|
|
86
107
|
}
|
|
87
108
|
isSubmitDisabled(fieldNames) {
|
|
88
109
|
return fieldNames.some(fieldName => {
|
|
89
|
-
const value = this.form[fieldName]?.trim() ??
|
|
110
|
+
const value = this.form[fieldName]?.trim() ?? '';
|
|
90
111
|
const error = this.errors[fieldName];
|
|
91
112
|
return !value || !!error;
|
|
92
113
|
});
|
|
93
114
|
}
|
|
94
115
|
async submit(endpoint, token) {
|
|
95
116
|
// console.log("Submitting form:", this.form, this.errors);
|
|
96
|
-
const expiry = this.form.expiryDate?.split(
|
|
117
|
+
const expiry = this.form.expiryDate?.split('/') || [];
|
|
97
118
|
|
|
98
119
|
// Replace fetchData with your API call
|
|
99
120
|
const response = await fetchData(endpoint, {
|
|
100
|
-
method:
|
|
121
|
+
method: 'POST',
|
|
101
122
|
body: {
|
|
102
123
|
token,
|
|
103
|
-
pan: formatString(this.form.cardNumber ||
|
|
124
|
+
pan: formatString(this.form.cardNumber || ''),
|
|
104
125
|
expiry_month: Number(expiry[0] || 0) || null,
|
|
105
|
-
expiry_year: formatCardYear(expiry[1] ||
|
|
126
|
+
expiry_year: formatCardYear(expiry[1] || '') || null,
|
|
106
127
|
cvv: this.form.cvc ? formatString(this.form.cvc) : null,
|
|
107
128
|
address: {
|
|
108
129
|
postal_code: this.form.zipCode ? formatString(this.form.zipCode) : null
|
|
109
130
|
}
|
|
110
131
|
}
|
|
111
132
|
});
|
|
112
|
-
|
|
113
|
-
if (response.error) {
|
|
133
|
+
if (response.status === "ERROR") {
|
|
114
134
|
return {
|
|
115
135
|
success: false,
|
|
116
|
-
error: response
|
|
136
|
+
error: response
|
|
117
137
|
};
|
|
118
138
|
} else {
|
|
119
139
|
return {
|
|
120
140
|
success: true,
|
|
121
|
-
data: response
|
|
141
|
+
data: response
|
|
122
142
|
};
|
|
123
143
|
}
|
|
124
|
-
// return response.json();
|
|
125
144
|
}
|
|
126
145
|
}
|
|
127
|
-
//# sourceMappingURL=
|
|
146
|
+
//# sourceMappingURL=BivoSecureStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["formatCardYear","formatString","fetchData","url","options","response","fetch","method","headers","body","JSON","stringify","undefined","json","BivoSecureStore","form","errors","fieldConfig","constructor","vaultId","environment","setField","fieldName","value","onStateChange","required","regex","errorMsg","parsedRegex","RegExp","e","console","error","validateField","trimmedValue","trim","test","digits","replace","length","monthStr","yearStr","split","month","parseInt","year","fullYear","now","Date","currentMonth","getMonth","currentYear","getFullYear","isSubmitDisabled","fieldNames","some","submit","endpoint","token","expiry","expiryDate","pan","cardNumber","expiry_month","Number","expiry_year","cvv","cvc","address","postal_code","zipCode","status","success","data"],"sourceRoot":"../../../src","sources":["core/BivoSecureStore.ts"],"mappings":";;AAAA,SAASA,cAAc,EAAEC,YAAY,QAAQ,mBAAgB;AAI7D,eAAeC,SAASA,CAACC,GAAW,EAAEC,OAAY,GAAG,CAAC,CAAC,EAAgB;EACrE,MAAMC,QAAQ,GAAG,MAAMC,KAAK,CAACH,GAAG,EAAE;IAChCI,MAAM,EAAEH,OAAO,CAACG,MAAM,IAAI,KAAK;IAC/BC,OAAO,EAAE;MACP,cAAc,EAAE,kBAAkB;MAClC,IAAIJ,OAAO,CAACI,OAAO,IAAI,CAAC,CAAC;IAC3B,CAAC;IACDC,IAAI,EAAEL,OAAO,CAACK,IAAI,GAAGC,IAAI,CAACC,SAAS,CAACP,OAAO,CAACK,IAAI,CAAC,GAAGG;EACtD,CAAC,CAAC;EAEF,OAAOP,QAAQ,CAACQ,IAAI,CAAC,CAAC;AACxB;AAEA,OAAO,MAAMC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D,OAAO,GAC1BrE,YAAY,CAAC,IAAI,CAACc,IAAI,CAACuD,OAAO,CAAC,GAC/B;QACN;MACF;IACF,CAAC,CAAC;IAEF,IAAIjE,QAAQ,CAACkE,MAAM,KAAK,OAAO,EAAE;MAC7B,OAAO;QAAEC,OAAO,EAAE,KAAK;QAAExC,KAAK,EAAE3B;MAAS,CAAC;IAC5C,CAAC,MAAM;MACL,OAAO;QAAEmE,OAAO,EAAE,IAAI;QAAEC,IAAI,EAAEpE;MAAS,CAAC;IAC1C;EACJ;AACF","ignoreList":[]}
|
package/lib/module/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
export {
|
|
3
|
+
export { BivoSecureStore } from "./core/BivoSecureStore.js";
|
|
4
4
|
export { BivoTextInput } from "./components/BivoTextInput.js";
|
|
5
5
|
export { BivoCardInput } from "./components/BivoCardInput.js";
|
|
6
6
|
export { BivoCVCInput } from "./components/BivoCVCInput.js";
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["BivoSecureStore","BivoTextInput","BivoCardInput","BivoCVCInput"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,SAASA,eAAe,QAAQ,2BAAwB;AAExD,SAASC,aAAa,QAAQ,+BAA4B;AAC1D,SAASC,aAAa,QAAQ,+BAA4B;AAC1D,SAASC,YAAY,QAAQ,8BAA2B","ignoreList":[]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { ViewStyle, TextStyle } from 'react-native';
|
|
3
|
-
import {
|
|
3
|
+
import { BivoSecureStore } from '../core/BivoSecureStore';
|
|
4
4
|
interface Props {
|
|
5
|
-
|
|
5
|
+
bivoStore: BivoSecureStore;
|
|
6
6
|
fieldName: string;
|
|
7
7
|
placeholder?: string;
|
|
8
8
|
onStateChange?: (state: any) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BivoCVCInput.d.ts","sourceRoot":"","sources":["../../../../src/components/BivoCVCInput.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAExC,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"BivoCVCInput.d.ts","sourceRoot":"","sources":["../../../../src/components/BivoCVCInput.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAExC,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAG1D,UAAU,KAAK;IACb,SAAS,EAAE,eAAe,CAAC;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;IACrC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,SAAS,CAAC;IAC3B,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB;AAED,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAyDxC,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { ViewStyle, TextStyle } from 'react-native';
|
|
3
|
-
import {
|
|
3
|
+
import { BivoSecureStore } from '../core/BivoSecureStore';
|
|
4
4
|
interface Props {
|
|
5
|
-
|
|
5
|
+
bivoStore: BivoSecureStore;
|
|
6
6
|
fieldName: string;
|
|
7
7
|
placeholder?: string;
|
|
8
8
|
onStateChange?: (state: any) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BivoCardInput.d.ts","sourceRoot":"","sources":["../../../../src/components/BivoCardInput.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAExC,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"BivoCardInput.d.ts","sourceRoot":"","sources":["../../../../src/components/BivoCardInput.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAExC,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAI1D,UAAU,KAAK;IACb,SAAS,EAAE,eAAe,CAAC;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;IACrC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,SAAS,CAAC;IAC3B,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB;AAUD,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAoEzC,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { ViewStyle, TextStyle } from 'react-native';
|
|
3
|
-
import type {
|
|
3
|
+
import type { BivoSecureStore } from '../core/BivoSecureStore';
|
|
4
4
|
interface Props {
|
|
5
|
-
|
|
5
|
+
bivoStore: BivoSecureStore;
|
|
6
6
|
fieldName: string;
|
|
7
7
|
placeholder?: string;
|
|
8
8
|
onStateChange?: (state: any) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BivoTextInput.d.ts","sourceRoot":"","sources":["../../../../src/components/BivoTextInput.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAExC,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"BivoTextInput.d.ts","sourceRoot":"","sources":["../../../../src/components/BivoTextInput.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAExC,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAI/D,UAAU,KAAK;IACb,SAAS,EAAE,eAAe,CAAC;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;IACrC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,SAAS,CAAC;IAC3B,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB;AAED,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CA6DzC,CAAC"}
|
|
@@ -2,9 +2,9 @@ type FieldState = {
|
|
|
2
2
|
value: string;
|
|
3
3
|
error?: string;
|
|
4
4
|
};
|
|
5
|
-
export declare class
|
|
5
|
+
export declare class BivoSecureStore {
|
|
6
6
|
vaultId: string;
|
|
7
|
-
environment:
|
|
7
|
+
environment: 'sandbox' | 'live';
|
|
8
8
|
form: Record<string, string>;
|
|
9
9
|
errors: Record<string, string>;
|
|
10
10
|
fieldConfig: Record<string, {
|
|
@@ -12,19 +12,11 @@ export declare class BivoCollect {
|
|
|
12
12
|
regex?: RegExp;
|
|
13
13
|
errorMsg?: string;
|
|
14
14
|
}>;
|
|
15
|
-
constructor(vaultId: string, environment:
|
|
15
|
+
constructor(vaultId: string, environment: 'sandbox' | 'live');
|
|
16
16
|
setField(fieldName: string, value: string, onStateChange?: (state: FieldState) => void, required?: boolean, regex?: RegExp, errorMsg?: string): void;
|
|
17
17
|
validateField(fieldName: string, value: string, required?: boolean, regex?: RegExp, errorMsg?: string): string;
|
|
18
18
|
isSubmitDisabled(fieldNames: string[]): boolean;
|
|
19
|
-
submit(endpoint: string, token: string): Promise<
|
|
20
|
-
success: boolean;
|
|
21
|
-
error: string;
|
|
22
|
-
data?: undefined;
|
|
23
|
-
} | {
|
|
24
|
-
success: boolean;
|
|
25
|
-
data: unknown;
|
|
26
|
-
error?: undefined;
|
|
27
|
-
}>;
|
|
19
|
+
submit(endpoint: string, token: string): Promise<any>;
|
|
28
20
|
}
|
|
29
21
|
export {};
|
|
30
|
-
//# sourceMappingURL=
|
|
22
|
+
//# sourceMappingURL=BivoSecureStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BivoSecureStore.d.ts","sourceRoot":"","sources":["../../../../src/core/BivoSecureStore.ts"],"names":[],"mappings":"AAEA,KAAK,UAAU,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAepD,qBAAa,eAAe;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,SAAS,GAAG,MAAM,CAAC;IAChC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAM;IAClC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAM;IACpC,WAAW,EAAE,MAAM,CACjB,MAAM,EACN;QAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,CAC1D,CAAM;gBAEK,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,GAAG,MAAM;IAK5D,QAAQ,CACN,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,EACb,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,EAC3C,QAAQ,GAAE,OAAe,EACzB,KAAK,CAAC,EAAE,MAAM,EACd,QAAQ,CAAC,EAAE,MAAM;IA2BnB,aAAa,CACX,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,EACb,QAAQ,CAAC,EAAE,OAAO,EAClB,KAAK,CAAC,EAAE,MAAM,EACd,QAAQ,CAAC,EAAE,MAAM;IAqEnB,gBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE;IAQ/B,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;CA2B5D"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { BivoSecureStore } from "./core/BivoSecureStore";
|
|
2
2
|
export { BivoTextInput } from "./components/BivoTextInput";
|
|
3
3
|
export { BivoCardInput } from "./components/BivoCardInput";
|
|
4
4
|
export { BivoCVCInput } from "./components/BivoCVCInput";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import React, { useState } from 'react';
|
|
2
2
|
import { View, TextInput, Text, StyleSheet, Image } from 'react-native';
|
|
3
3
|
import type { ViewStyle, TextStyle } from 'react-native';
|
|
4
|
-
import {
|
|
4
|
+
import { BivoSecureStore } from '../core/BivoSecureStore';
|
|
5
5
|
import { Icons } from '../assets';
|
|
6
6
|
|
|
7
7
|
interface Props {
|
|
8
|
-
|
|
8
|
+
bivoStore: BivoSecureStore;
|
|
9
9
|
fieldName: string;
|
|
10
10
|
placeholder?: string;
|
|
11
11
|
onStateChange?: (state: any) => void;
|
|
@@ -17,7 +17,7 @@ interface Props {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export const BivoCVCInput: React.FC<Props> = ({
|
|
20
|
-
|
|
20
|
+
bivoStore,
|
|
21
21
|
fieldName,
|
|
22
22
|
placeholder,
|
|
23
23
|
onStateChange,
|
|
@@ -31,7 +31,7 @@ export const BivoCVCInput: React.FC<Props> = ({
|
|
|
31
31
|
|
|
32
32
|
const handleChange = (text: string) => {
|
|
33
33
|
setValue(text);
|
|
34
|
-
|
|
34
|
+
bivoStore.setField(
|
|
35
35
|
fieldName,
|
|
36
36
|
text,
|
|
37
37
|
onStateChange,
|
|
@@ -42,7 +42,7 @@ export const BivoCVCInput: React.FC<Props> = ({
|
|
|
42
42
|
};
|
|
43
43
|
|
|
44
44
|
const handleBlur = () => {
|
|
45
|
-
|
|
45
|
+
bivoStore.setField(
|
|
46
46
|
fieldName,
|
|
47
47
|
value,
|
|
48
48
|
onStateChange,
|
|
@@ -52,7 +52,7 @@ export const BivoCVCInput: React.FC<Props> = ({
|
|
|
52
52
|
);
|
|
53
53
|
};
|
|
54
54
|
|
|
55
|
-
const error =
|
|
55
|
+
const error = bivoStore.errors[fieldName];
|
|
56
56
|
|
|
57
57
|
return (
|
|
58
58
|
<View style={[styles.container, containerStyle]}>
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import React, { useState } from 'react';
|
|
2
2
|
import { View, TextInput, Image, Text, StyleSheet } from 'react-native';
|
|
3
3
|
import type { ViewStyle, TextStyle } from 'react-native';
|
|
4
|
-
import {
|
|
4
|
+
import { BivoSecureStore } from '../core/BivoSecureStore';
|
|
5
5
|
import { Icons } from '../assets';
|
|
6
6
|
import { formatCardNumber } from '../utils/utils';
|
|
7
7
|
|
|
8
8
|
interface Props {
|
|
9
|
-
|
|
9
|
+
bivoStore: BivoSecureStore;
|
|
10
10
|
fieldName: string;
|
|
11
11
|
placeholder?: string;
|
|
12
12
|
onStateChange?: (state: any) => void;
|
|
@@ -26,7 +26,7 @@ const cardIcons: any = {
|
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
export const BivoCardInput: React.FC<Props> = ({
|
|
29
|
-
|
|
29
|
+
bivoStore,
|
|
30
30
|
fieldName,
|
|
31
31
|
placeholder,
|
|
32
32
|
onStateChange,
|
|
@@ -49,7 +49,7 @@ export const BivoCardInput: React.FC<Props> = ({
|
|
|
49
49
|
else if (/^6(?:011|5)/.test(cleaned)) setCardType('discover');
|
|
50
50
|
else setCardType('unknown');
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
bivoStore.setField(
|
|
53
53
|
fieldName,
|
|
54
54
|
text,
|
|
55
55
|
onStateChange,
|
|
@@ -60,7 +60,7 @@ export const BivoCardInput: React.FC<Props> = ({
|
|
|
60
60
|
};
|
|
61
61
|
|
|
62
62
|
const handleBlur = () => {
|
|
63
|
-
|
|
63
|
+
bivoStore.setField(
|
|
64
64
|
fieldName,
|
|
65
65
|
value,
|
|
66
66
|
onStateChange,
|
|
@@ -70,7 +70,7 @@ export const BivoCardInput: React.FC<Props> = ({
|
|
|
70
70
|
);
|
|
71
71
|
};
|
|
72
72
|
|
|
73
|
-
const error =
|
|
73
|
+
const error = bivoStore.errors[fieldName];
|
|
74
74
|
|
|
75
75
|
return (
|
|
76
76
|
<View style={[styles.container, containerStyle]}>
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import React, { useState } from 'react';
|
|
2
2
|
import { View, TextInput, Text, StyleSheet, Image } from 'react-native';
|
|
3
3
|
import type { ViewStyle, TextStyle } from 'react-native';
|
|
4
|
-
import type {
|
|
4
|
+
import type { BivoSecureStore } from '../core/BivoSecureStore';
|
|
5
5
|
import { Icons } from '../assets';
|
|
6
6
|
import { formatExpiry } from '../utils/utils';
|
|
7
7
|
|
|
8
8
|
interface Props {
|
|
9
|
-
|
|
9
|
+
bivoStore: BivoSecureStore;
|
|
10
10
|
fieldName: string;
|
|
11
11
|
placeholder?: string;
|
|
12
12
|
onStateChange?: (state: any) => void;
|
|
@@ -18,7 +18,7 @@ interface Props {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
export const BivoTextInput: React.FC<Props> = ({
|
|
21
|
-
|
|
21
|
+
bivoStore,
|
|
22
22
|
fieldName,
|
|
23
23
|
placeholder,
|
|
24
24
|
onStateChange,
|
|
@@ -38,7 +38,7 @@ export const BivoTextInput: React.FC<Props> = ({
|
|
|
38
38
|
updatedValue = text;
|
|
39
39
|
}
|
|
40
40
|
setValue(updatedValue);
|
|
41
|
-
|
|
41
|
+
bivoStore.setField(
|
|
42
42
|
fieldName,
|
|
43
43
|
updatedValue,
|
|
44
44
|
onStateChange,
|
|
@@ -49,7 +49,7 @@ export const BivoTextInput: React.FC<Props> = ({
|
|
|
49
49
|
};
|
|
50
50
|
|
|
51
51
|
const handleBlur = () => {
|
|
52
|
-
|
|
52
|
+
bivoStore.setField(
|
|
53
53
|
fieldName,
|
|
54
54
|
value,
|
|
55
55
|
onStateChange,
|
|
@@ -59,7 +59,7 @@ export const BivoTextInput: React.FC<Props> = ({
|
|
|
59
59
|
);
|
|
60
60
|
};
|
|
61
61
|
|
|
62
|
-
const error =
|
|
62
|
+
const error = bivoStore.errors[fieldName];
|
|
63
63
|
|
|
64
64
|
return (
|
|
65
65
|
<View style={[styles.container, containerStyle]}>
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { formatCardYear, formatString } from '../utils/utils';
|
|
2
|
+
|
|
3
|
+
type FieldState = { value: string; error?: string };
|
|
4
|
+
|
|
5
|
+
async function fetchData(url: string, options: any = {}): Promise<any> {
|
|
6
|
+
const response = await fetch(url, {
|
|
7
|
+
method: options.method || 'GET',
|
|
8
|
+
headers: {
|
|
9
|
+
'Content-Type': 'application/json',
|
|
10
|
+
...(options.headers || {}),
|
|
11
|
+
},
|
|
12
|
+
body: options.body ? JSON.stringify(options.body) : undefined,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
return response.json();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export class BivoSecureStore {
|
|
19
|
+
vaultId: string;
|
|
20
|
+
environment: 'sandbox' | 'live';
|
|
21
|
+
form: Record<string, string> = {};
|
|
22
|
+
errors: Record<string, string> = {};
|
|
23
|
+
fieldConfig: Record<
|
|
24
|
+
string,
|
|
25
|
+
{ required?: boolean; regex?: RegExp; errorMsg?: string }
|
|
26
|
+
> = {};
|
|
27
|
+
|
|
28
|
+
constructor(vaultId: string, environment: 'sandbox' | 'live') {
|
|
29
|
+
this.vaultId = vaultId;
|
|
30
|
+
this.environment = environment;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
setField(
|
|
34
|
+
fieldName: string,
|
|
35
|
+
value: string,
|
|
36
|
+
onStateChange?: (state: FieldState) => void,
|
|
37
|
+
required: boolean = false,
|
|
38
|
+
regex?: RegExp,
|
|
39
|
+
errorMsg?: string
|
|
40
|
+
) {
|
|
41
|
+
this.form[fieldName] = value;
|
|
42
|
+
// convert string regex to RegExp
|
|
43
|
+
let parsedRegex: RegExp | undefined = undefined;
|
|
44
|
+
|
|
45
|
+
if (typeof regex === 'string') {
|
|
46
|
+
try {
|
|
47
|
+
parsedRegex = new RegExp(regex);
|
|
48
|
+
} catch (e) {
|
|
49
|
+
console.error('Invalid regex:', regex, e);
|
|
50
|
+
}
|
|
51
|
+
} else {
|
|
52
|
+
parsedRegex = regex;
|
|
53
|
+
}
|
|
54
|
+
this.fieldConfig[fieldName] = { required, regex: parsedRegex, errorMsg };
|
|
55
|
+
const error = this.validateField(
|
|
56
|
+
fieldName,
|
|
57
|
+
value,
|
|
58
|
+
required,
|
|
59
|
+
parsedRegex,
|
|
60
|
+
errorMsg
|
|
61
|
+
);
|
|
62
|
+
this.errors[fieldName] = error || '';
|
|
63
|
+
onStateChange?.({ value, error });
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
validateField(
|
|
67
|
+
fieldName: string,
|
|
68
|
+
value: string,
|
|
69
|
+
required?: boolean,
|
|
70
|
+
regex?: RegExp,
|
|
71
|
+
errorMsg?: string
|
|
72
|
+
) {
|
|
73
|
+
const trimmedValue = value?.trim();
|
|
74
|
+
|
|
75
|
+
// Required check
|
|
76
|
+
if (!trimmedValue && required) return 'Required';
|
|
77
|
+
|
|
78
|
+
// If custom regex is provided → use it first
|
|
79
|
+
if (regex && trimmedValue) {
|
|
80
|
+
if (!regex.test(trimmedValue)) {
|
|
81
|
+
return errorMsg || 'Invalid value';
|
|
82
|
+
}
|
|
83
|
+
return '';
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Default validations
|
|
87
|
+
switch (fieldName) {
|
|
88
|
+
case 'card': {
|
|
89
|
+
const digits = trimmedValue.replace(/\D/g, '');
|
|
90
|
+
if (digits.length < 12) return 'Invalid card number';
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
case 'cvv': {
|
|
95
|
+
if (!/^\d{3,4}$/.test(trimmedValue)) {
|
|
96
|
+
return 'Invalid CVV';
|
|
97
|
+
}
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
case 'exp': {
|
|
102
|
+
// Format check MM/YY
|
|
103
|
+
if (!/^\d{2}\/\d{2}$/.test(trimmedValue)) {
|
|
104
|
+
return 'Invalid expiry';
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const [monthStr, yearStr] = trimmedValue.split('/');
|
|
108
|
+
if (!monthStr || !yearStr) {
|
|
109
|
+
return 'Invalid expiry';
|
|
110
|
+
}
|
|
111
|
+
const month = parseInt(monthStr, 10);
|
|
112
|
+
const year = parseInt(yearStr, 10);
|
|
113
|
+
|
|
114
|
+
if (month < 1 || month > 12) {
|
|
115
|
+
return 'Invalid month';
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Convert YY → YYYY (assume 2000-2099)
|
|
119
|
+
const fullYear = 2000 + year;
|
|
120
|
+
|
|
121
|
+
const now = new Date();
|
|
122
|
+
const currentMonth = now.getMonth() + 1;
|
|
123
|
+
const currentYear = now.getFullYear();
|
|
124
|
+
|
|
125
|
+
// Expiry check
|
|
126
|
+
if (
|
|
127
|
+
fullYear < currentYear ||
|
|
128
|
+
(fullYear === currentYear && month < currentMonth)
|
|
129
|
+
) {
|
|
130
|
+
return 'Card expired';
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return '';
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
isSubmitDisabled(fieldNames: string[]) {
|
|
141
|
+
return fieldNames.some((fieldName) => {
|
|
142
|
+
const value = this.form[fieldName]?.trim() ?? '';
|
|
143
|
+
const error = this.errors[fieldName];
|
|
144
|
+
return !value || !!error;
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
async submit(endpoint: string, token: string): Promise<any> {
|
|
149
|
+
// console.log("Submitting form:", this.form, this.errors);
|
|
150
|
+
const expiry = this.form.expiryDate?.split('/') || [];
|
|
151
|
+
|
|
152
|
+
// Replace fetchData with your API call
|
|
153
|
+
const response = await fetchData(endpoint, {
|
|
154
|
+
method: 'POST',
|
|
155
|
+
body: {
|
|
156
|
+
token,
|
|
157
|
+
pan: formatString(this.form.cardNumber || ''),
|
|
158
|
+
expiry_month: Number(expiry[0] || 0) || null,
|
|
159
|
+
expiry_year: formatCardYear(expiry[1] || '') || null,
|
|
160
|
+
cvv: this.form.cvc ? formatString(this.form.cvc) : null,
|
|
161
|
+
address: {
|
|
162
|
+
postal_code: this.form.zipCode
|
|
163
|
+
? formatString(this.form.zipCode)
|
|
164
|
+
: null,
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
if (response.status === "ERROR") {
|
|
170
|
+
return { success: false, error: response };
|
|
171
|
+
} else {
|
|
172
|
+
return { success: true, data: response };
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["fetchData","formatCardYear","formatString","BivoCollect","form","errors","fieldConfig","constructor","vaultId","environment","setField","fieldName","value","onStateChange","required","regex","errorMsg","error","validateField","trimmedValue","trim","test","digits","replace","length","monthStr","yearStr","split","month","parseInt","year","fullYear","now","Date","currentMonth","getMonth","currentYear","getFullYear","isSubmitDisabled","fieldNames","some","submit","endpoint","token","expiry","expiryDate","response","method","body","pan","cardNumber","expiry_month","Number","expiry_year","cvv","cvc","address","postal_code","zipCode","console","log","success","data"],"sourceRoot":"../../../src","sources":["core/Collector.ts"],"mappings":";;AAAA,SAASA,SAAS,QAAQ,mBAAgB;AAC1C,SAASC,cAAc,EAAEC,YAAY,QAAQ,mBAAgB;AAK7D,OAAO,MAAMC,WAAW,CAAC;EAGvBC,IAAI,GAA2B,CAAC,CAAC;EACjCC,MAAM,GAA2B,CAAC,CAAC;EACnCC,WAAW,GAA8E,CAAC,CAAC;EAE3FC,WAAWA,CAACC,OAAe,EAAEC,WAA+B,EAAE;IAC5D,IAAI,CAACD,OAAO,GAAGA,OAAO;IACtB,IAAI,CAACC,WAAW,GAAGA,WAAW;EAChC;EAEAC,QAAQA,CAACC,SAAiB,EAAEC,KAAa,EAAEC,aAA2C,EAAEC,QAAiB,GAAG,KAAK,EAAEC,KAAc,EAAEC,QAAiB,EAAE;IACpJ,IAAI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MAAMmB,QAAQ,GAAG,MAAM9C,SAAS,CAAC0C,QAAQ,EAAE;MACzCK,MAAM,EAAE,MAAM;MACdC,IAAI,EAAE;QACJL,KAAK;QACLM,GAAG,EAAC/C,YAAY,CAAC,IAAI,CAACE,IAAI,CAAC8C,UAAU,IAAI,EAAE,CAAC;QAC5CC,YAAY,EAAEC,MAAM,CAACR,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI;QAC5CS,WAAW,EAAEpD,cAAc,CAAC2C,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,IAAI,IAAI;QACpDU,GAAG,EAAE,IAAI,CAAClD,IAAI,CAACmD,GAAG,GAAGrD,YAAY,CAAC,IAAI,CAACE,IAAI,CAACmD,GAAG,CAAC,GAAG,IAAI;QACvDC,OAAO,EAAE;UACPC,WAAW,EAAE,IAAI,CAACrD,IAAI,CAACsD,OAAO,GAAGxD,YAAY,CAAC,IAAI,CAACE,IAAI,CAACsD,OAAO,CAAC,GAAG;QACrE;MACF;IACF,CAAC,CAAC;IACDC,OAAO,CAACC,GAAG,CAAC,uCAAuC,EAAEd,QAAQ,EAACJ,QAAQ,EAACC,KAAK,CAAC;IAC7E,IAAIG,QAAQ,CAAC7B,KAAK,EAAE;MACnB,OAAM;QAAE4C,OAAO,EAAE,KAAK;QAAE5C,KAAK,EAAE6B,QAAQ,CAAC7B;MAAM,CAAC;IACjD,CAAC,MAAM;MACL,OAAM;QAAE4C,OAAO,EAAE,IAAI;QAAEC,IAAI,EAAEhB,QAAQ,CAACgB;MAAK,CAAC;IAC9C;IACA;EACF;AACF","ignoreList":[]}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
export const fetchData = async (url, payload = {}) => {
|
|
4
|
-
const {
|
|
5
|
-
method = "GET",
|
|
6
|
-
headers = {},
|
|
7
|
-
body = null,
|
|
8
|
-
...options
|
|
9
|
-
} = payload;
|
|
10
|
-
try {
|
|
11
|
-
const config = {
|
|
12
|
-
method,
|
|
13
|
-
headers: {
|
|
14
|
-
Accept: "*/*",
|
|
15
|
-
"Content-Type": "application/json",
|
|
16
|
-
...headers
|
|
17
|
-
},
|
|
18
|
-
...options
|
|
19
|
-
};
|
|
20
|
-
if (body && ["POST", "PUT", "PATCH", "DELETE"].includes(method.toUpperCase())) {
|
|
21
|
-
config.body = typeof body === "string" ? body : JSON.stringify(body);
|
|
22
|
-
}
|
|
23
|
-
const response = await fetch(url, config);
|
|
24
|
-
const contentType = response.headers.get("content-type");
|
|
25
|
-
let responseData;
|
|
26
|
-
if (contentType?.includes("application/json")) {
|
|
27
|
-
responseData = await response.json();
|
|
28
|
-
} else {
|
|
29
|
-
responseData = await response.text();
|
|
30
|
-
}
|
|
31
|
-
if (!response.ok) {
|
|
32
|
-
const errData = responseData;
|
|
33
|
-
throw new Error(errData?.message || `HTTP error! status: ${response.status}`);
|
|
34
|
-
}
|
|
35
|
-
return {
|
|
36
|
-
data: responseData,
|
|
37
|
-
error: null
|
|
38
|
-
};
|
|
39
|
-
} catch (err) {
|
|
40
|
-
const errorMessage = err instanceof Error ? err.message : "An error occurred";
|
|
41
|
-
return {
|
|
42
|
-
data: null,
|
|
43
|
-
error: errorMessage
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
//# sourceMappingURL=fetch.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["fetchData","url","payload","method","headers","body","options","config","Accept","includes","toUpperCase","JSON","stringify","response","fetch","contentType","get","responseData","json","text","ok","errData","Error","message","status","data","error","err","errorMessage"],"sourceRoot":"../../../src","sources":["utils/fetch.ts"],"mappings":";;AAaA,OAAO,MAAMA,SAAS,GAAG,MAAAA,CACvBC,GAAW,EACXC,OAAqB,GAAG,CAAC,CAAC,KACE;EAC5B,MAAM;IAAEC,MAAM,GAAG,KAAK;IAAEC,OAAO,GAAG,CAAC,CAAC;IAAEC,IAAI,GAAG,IAA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CA0B7C"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
2
|
-
interface FetchPayload extends Omit<RequestInit, "method" | "headers" | "body"> {
|
|
3
|
-
method?: HttpMethod;
|
|
4
|
-
headers?: Record<string, string>;
|
|
5
|
-
body?: Record<string, unknown> | string | null;
|
|
6
|
-
}
|
|
7
|
-
interface FetchResult<T> {
|
|
8
|
-
data: T | null;
|
|
9
|
-
error: string | null;
|
|
10
|
-
}
|
|
11
|
-
export declare const fetchData: <T = unknown>(url: string, payload?: FetchPayload) => Promise<FetchResult<T>>;
|
|
12
|
-
export {};
|
|
13
|
-
//# sourceMappingURL=fetch.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../../../src/utils/fetch.ts"],"names":[],"mappings":"AAAA,KAAK,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAC;AAE9D,UAAU,YAAa,SAAQ,IAAI,CAAC,WAAW,EAAE,QAAQ,GAAG,SAAS,GAAG,MAAM,CAAC;IAC7E,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,GAAG,IAAI,CAAC;CAChD;AAED,UAAU,WAAW,CAAC,CAAC;IACrB,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC;IACf,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB;AAED,eAAO,MAAM,SAAS,GAAU,CAAC,GAAG,OAAO,EACzC,KAAK,MAAM,EACX,UAAS,YAAiB,KACzB,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAyCxB,CAAC"}
|
package/src/core/Collector.ts
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import { fetchData } from "../utils/fetch";
|
|
2
|
-
import { formatCardYear, formatString } from "../utils/utils";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
type FieldState = { value: string; error?: string };
|
|
6
|
-
|
|
7
|
-
export class BivoCollect {
|
|
8
|
-
vaultId: string;
|
|
9
|
-
environment: "sandbox" | "live";
|
|
10
|
-
form: Record<string, string> = {};
|
|
11
|
-
errors: Record<string, string> = {};
|
|
12
|
-
fieldConfig: Record<string, { required?: boolean; regex?: RegExp; errorMsg?: string }> = {};
|
|
13
|
-
|
|
14
|
-
constructor(vaultId: string, environment: "sandbox" | "live") {
|
|
15
|
-
this.vaultId = vaultId;
|
|
16
|
-
this.environment = environment;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
setField(fieldName: string, value: string, onStateChange?: (state: FieldState) => void, required: boolean = false, regex?: RegExp, errorMsg?: string) {
|
|
20
|
-
this.form[fieldName] = value;
|
|
21
|
-
this.fieldConfig[fieldName] = { required, regex, errorMsg };
|
|
22
|
-
const error = this.validateField(fieldName, value, required, regex, errorMsg);
|
|
23
|
-
this.errors[fieldName] = error || "";
|
|
24
|
-
onStateChange?.({ value, error });
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
validateField(fieldName: string, value: string, required?: boolean, regex?: RegExp, errorMsg?: string) {
|
|
30
|
-
const trimmedValue = value?.trim();
|
|
31
|
-
|
|
32
|
-
// Required check
|
|
33
|
-
if (!trimmedValue && required) return "Required";
|
|
34
|
-
|
|
35
|
-
// If custom regex is provided → use it first
|
|
36
|
-
if (regex && trimmedValue) {
|
|
37
|
-
if (!regex.test(trimmedValue)) {
|
|
38
|
-
return errorMsg || "Invalid value";
|
|
39
|
-
}
|
|
40
|
-
return "";
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Default validations
|
|
44
|
-
switch (fieldName) {
|
|
45
|
-
case "card": {
|
|
46
|
-
const digits = trimmedValue.replace(/\D/g, "");
|
|
47
|
-
if (digits.length < 12) return "Invalid card number";
|
|
48
|
-
break;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
case "cvv": {
|
|
52
|
-
if (!/^\d{3,4}$/.test(trimmedValue)) {
|
|
53
|
-
return "Invalid CVV";
|
|
54
|
-
}
|
|
55
|
-
break;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
case "exp": {
|
|
59
|
-
// Format check MM/YY
|
|
60
|
-
if (!/^\d{2}\/\d{2}$/.test(trimmedValue)) {
|
|
61
|
-
return "Invalid expiry";
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const [monthStr, yearStr] = trimmedValue.split("/");
|
|
65
|
-
if (!monthStr || !yearStr) {
|
|
66
|
-
return "Invalid expiry";
|
|
67
|
-
}
|
|
68
|
-
const month = parseInt(monthStr, 10);
|
|
69
|
-
const year = parseInt(yearStr, 10);
|
|
70
|
-
|
|
71
|
-
if (month < 1 || month > 12) {
|
|
72
|
-
return "Invalid month";
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// Convert YY → YYYY (assume 2000-2099)
|
|
76
|
-
const fullYear = 2000 + year;
|
|
77
|
-
|
|
78
|
-
const now = new Date();
|
|
79
|
-
const currentMonth = now.getMonth() + 1;
|
|
80
|
-
const currentYear = now.getFullYear();
|
|
81
|
-
|
|
82
|
-
// Expiry check
|
|
83
|
-
if (
|
|
84
|
-
fullYear < currentYear ||
|
|
85
|
-
(fullYear === currentYear && month < currentMonth)
|
|
86
|
-
) {
|
|
87
|
-
return "Card expired";
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
break;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return "";
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
isSubmitDisabled(fieldNames: string[]) {
|
|
98
|
-
return fieldNames.some((fieldName) => {
|
|
99
|
-
const value = this.form[fieldName]?.trim() ?? "";
|
|
100
|
-
const error = this.errors[fieldName];
|
|
101
|
-
return !value || !!error;
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
async submit(endpoint: string, token: string) {
|
|
106
|
-
// console.log("Submitting form:", this.form, this.errors);
|
|
107
|
-
const expiry = this.form.expiryDate?.split("/") || [];
|
|
108
|
-
|
|
109
|
-
// Replace fetchData with your API call
|
|
110
|
-
const response = await fetchData(endpoint, {
|
|
111
|
-
method: "POST",
|
|
112
|
-
body: {
|
|
113
|
-
token,
|
|
114
|
-
pan:formatString(this.form.cardNumber || ""),
|
|
115
|
-
expiry_month: Number(expiry[0] || 0) || null,
|
|
116
|
-
expiry_year: formatCardYear(expiry[1] || "") || null,
|
|
117
|
-
cvv: this.form.cvc ? formatString(this.form.cvc) : null,
|
|
118
|
-
address: {
|
|
119
|
-
postal_code: this.form.zipCode ? formatString(this.form.zipCode) : null,
|
|
120
|
-
},
|
|
121
|
-
},
|
|
122
|
-
});
|
|
123
|
-
console.log("🚀 ~ BivoCollect ~ submit ~ response:", response,endpoint,token)
|
|
124
|
-
if (response.error) {
|
|
125
|
-
return{ success: false, error: response.error };
|
|
126
|
-
} else {
|
|
127
|
-
return{ success: true, data: response.data };
|
|
128
|
-
}
|
|
129
|
-
// return response.json();
|
|
130
|
-
}
|
|
131
|
-
}
|
package/src/utils/fetch.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
2
|
-
|
|
3
|
-
interface FetchPayload extends Omit<RequestInit, "method" | "headers" | "body"> {
|
|
4
|
-
method?: HttpMethod;
|
|
5
|
-
headers?: Record<string, string>;
|
|
6
|
-
body?: Record<string, unknown> | string | null;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
interface FetchResult<T> {
|
|
10
|
-
data: T | null;
|
|
11
|
-
error: string | null;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export const fetchData = async <T = unknown>(
|
|
15
|
-
url: string,
|
|
16
|
-
payload: FetchPayload = {}
|
|
17
|
-
): Promise<FetchResult<T>> => {
|
|
18
|
-
const { method = "GET", headers = {}, body = null, ...options } = payload;
|
|
19
|
-
|
|
20
|
-
try {
|
|
21
|
-
const config: RequestInit = {
|
|
22
|
-
method,
|
|
23
|
-
headers: {
|
|
24
|
-
Accept: "*/*",
|
|
25
|
-
"Content-Type": "application/json",
|
|
26
|
-
...headers,
|
|
27
|
-
},
|
|
28
|
-
...options,
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
if (body && ["POST", "PUT", "PATCH", "DELETE"].includes(method.toUpperCase())) {
|
|
32
|
-
config.body = typeof body === "string" ? body : JSON.stringify(body);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const response = await fetch(url, config);
|
|
36
|
-
|
|
37
|
-
const contentType = response.headers.get("content-type");
|
|
38
|
-
let responseData: T;
|
|
39
|
-
|
|
40
|
-
if (contentType?.includes("application/json")) {
|
|
41
|
-
responseData = await response.json() as T;
|
|
42
|
-
} else {
|
|
43
|
-
responseData = await response.text() as T;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (!response.ok) {
|
|
47
|
-
const errData = responseData as Record<string, unknown>;
|
|
48
|
-
throw new Error(
|
|
49
|
-
(errData?.message as string) || `HTTP error! status: ${response.status}`
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return { data: responseData, error: null };
|
|
54
|
-
} catch (err) {
|
|
55
|
-
const errorMessage = err instanceof Error ? err.message : "An error occurred";
|
|
56
|
-
return { data: null, error: errorMessage };
|
|
57
|
-
}
|
|
58
|
-
};
|