@evervault/evervault-react-native 1.0.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -39
- package/dist/commonjs/components/3DS/ThreeDSecure.js +34 -0
- package/dist/commonjs/components/3DS/ThreeDSecure.js.map +1 -0
- package/dist/commonjs/components/3DS/ThreeDSecureFrame.js +45 -0
- package/dist/commonjs/components/3DS/ThreeDSecureFrame.js.map +1 -0
- package/dist/commonjs/components/3DS/config.js +9 -0
- package/dist/commonjs/components/3DS/config.js.map +1 -0
- package/dist/commonjs/components/3DS/context.js +9 -0
- package/dist/commonjs/components/3DS/context.js.map +1 -0
- package/dist/commonjs/components/3DS/index.js +20 -0
- package/dist/commonjs/components/3DS/index.js.map +1 -0
- package/dist/commonjs/components/3DS/styles.js +63 -0
- package/dist/commonjs/components/3DS/styles.js.map +1 -0
- package/dist/commonjs/components/3DS/threeDSSession.js +109 -0
- package/dist/commonjs/components/3DS/threeDSSession.js.map +1 -0
- package/dist/commonjs/components/3DS/types.js +2 -0
- package/dist/commonjs/components/3DS/types.js.map +1 -0
- package/dist/commonjs/components/3DS/useThreeDSecure.js +46 -0
- package/dist/commonjs/components/3DS/useThreeDSecure.js.map +1 -0
- package/dist/commonjs/components/Card/Card.js +13 -13
- package/dist/commonjs/components/Card/CardCVC.js +7 -7
- package/dist/commonjs/components/Card/CardExpiry.js +6 -6
- package/dist/commonjs/components/Card/CardHolder.js +5 -5
- package/dist/commonjs/components/Card/CardNumber.js +6 -6
- package/dist/commonjs/components/Card/CardNumber.js.map +1 -1
- package/dist/commonjs/components/Card/context.js +5 -5
- package/dist/commonjs/components/Card/utilities.js +5 -5
- package/dist/commonjs/components/EvervaultProvider.js +62 -0
- package/dist/commonjs/components/EvervaultProvider.js.map +1 -0
- package/dist/commonjs/index.js +21 -0
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/native.js +2 -2
- package/dist/commonjs/sdk.js +10 -3
- package/dist/commonjs/sdk.js.map +1 -1
- package/dist/module/components/3DS/ThreeDSecure.js +28 -0
- package/dist/module/components/3DS/ThreeDSecure.js.map +1 -0
- package/dist/module/components/3DS/ThreeDSecureFrame.js +36 -0
- package/dist/module/components/3DS/ThreeDSecureFrame.js.map +1 -0
- package/dist/module/components/3DS/config.js +3 -0
- package/dist/module/components/3DS/config.js.map +1 -0
- package/dist/module/components/3DS/context.js +3 -0
- package/dist/module/components/3DS/context.js.map +1 -0
- package/dist/module/components/3DS/index.js +3 -0
- package/dist/module/components/3DS/index.js.map +1 -0
- package/dist/module/components/3DS/styles.js +58 -0
- package/dist/module/components/3DS/styles.js.map +1 -0
- package/dist/module/components/3DS/threeDSSession.js +100 -0
- package/dist/module/components/3DS/threeDSSession.js.map +1 -0
- package/dist/module/components/3DS/types.js +2 -0
- package/dist/module/components/3DS/types.js.map +1 -0
- package/dist/module/components/3DS/useThreeDSecure.js +40 -0
- package/dist/module/components/3DS/useThreeDSecure.js.map +1 -0
- package/dist/module/components/Card/Card.js +25 -25
- package/dist/module/components/Card/Card.js.map +1 -1
- package/dist/module/components/Card/CardCVC.js +12 -12
- package/dist/module/components/Card/CardExpiry.js +10 -10
- package/dist/module/components/Card/CardHolder.js +9 -9
- package/dist/module/components/Card/CardNumber.js +11 -11
- package/dist/module/components/Card/CardNumber.js.map +1 -1
- package/dist/module/components/Card/context.js +6 -6
- package/dist/module/components/Card/index.js +1 -1
- package/dist/module/components/Card/utilities.js +6 -6
- package/dist/module/components/EvervaultProvider.js +53 -0
- package/dist/module/components/EvervaultProvider.js.map +1 -0
- package/dist/module/index.js +4 -2
- package/dist/module/index.js.map +1 -1
- package/dist/module/native.js +3 -3
- package/dist/module/sdk.js +13 -5
- package/dist/module/sdk.js.map +1 -1
- package/dist/typescript/src/components/3DS/ThreeDSecure.d.ts +8 -0
- package/dist/typescript/src/components/3DS/ThreeDSecure.d.ts.map +1 -0
- package/dist/typescript/src/components/3DS/ThreeDSecureFrame.d.ts +3 -0
- package/dist/typescript/src/components/3DS/ThreeDSecureFrame.d.ts.map +1 -0
- package/dist/typescript/src/components/3DS/config.d.ts +3 -0
- package/dist/typescript/src/components/3DS/config.d.ts.map +1 -0
- package/dist/typescript/src/components/3DS/context.d.ts +4 -0
- package/dist/typescript/src/components/3DS/context.d.ts.map +1 -0
- package/dist/typescript/src/components/3DS/index.d.ts +3 -0
- package/dist/typescript/src/components/3DS/index.d.ts.map +1 -0
- package/dist/typescript/src/components/3DS/styles.d.ts +57 -0
- package/dist/typescript/src/components/3DS/styles.d.ts.map +1 -0
- package/dist/typescript/src/components/3DS/threeDSSession.d.ts +10 -0
- package/dist/typescript/src/components/3DS/threeDSSession.d.ts.map +1 -0
- package/dist/typescript/src/components/3DS/types.d.ts +42 -0
- package/dist/typescript/src/components/3DS/types.d.ts.map +1 -0
- package/dist/typescript/src/components/3DS/useThreeDSecure.d.ts +3 -0
- package/dist/typescript/src/components/3DS/useThreeDSecure.d.ts.map +1 -0
- package/dist/typescript/src/components/Card/Card.d.ts +8 -8
- package/dist/typescript/src/components/Card/Card.d.ts.map +1 -1
- package/dist/typescript/src/components/Card/CardCVC.d.ts +2 -2
- package/dist/typescript/src/components/Card/CardExpiry.d.ts +2 -2
- package/dist/typescript/src/components/Card/CardHolder.d.ts +2 -2
- package/dist/typescript/src/components/Card/CardNumber.d.ts +2 -2
- package/dist/typescript/src/components/Card/context.d.ts +4 -4
- package/dist/typescript/src/components/Card/index.d.ts +1 -1
- package/dist/typescript/src/components/Card/types.d.ts +2 -2
- package/dist/typescript/src/components/Card/types.d.ts.map +1 -1
- package/dist/typescript/src/components/Card/utilities.d.ts +3 -3
- package/dist/typescript/src/components/EvervaultProvider.d.ts +29 -0
- package/dist/typescript/src/components/EvervaultProvider.d.ts.map +1 -0
- package/dist/typescript/src/index.d.ts +5 -3
- package/dist/typescript/src/index.d.ts.map +1 -1
- package/dist/typescript/src/sdk.d.ts +7 -0
- package/dist/typescript/src/sdk.d.ts.map +1 -1
- package/package.json +6 -80
- package/src/components/3DS/ThreeDSecure.tsx +32 -0
- package/src/components/3DS/ThreeDSecureFrame.tsx +39 -0
- package/src/components/3DS/config.ts +2 -0
- package/src/components/3DS/context.tsx +4 -0
- package/src/components/3DS/index.ts +2 -0
- package/src/components/3DS/styles.tsx +63 -0
- package/src/components/3DS/threeDSSession.ts +132 -0
- package/src/components/3DS/types.ts +46 -0
- package/src/components/3DS/useThreeDSecure.tsx +51 -0
- package/src/components/Card/Card.tsx +27 -27
- package/src/components/Card/CardCVC.tsx +13 -13
- package/src/components/Card/CardExpiry.tsx +11 -11
- package/src/components/Card/CardHolder.tsx +10 -10
- package/src/components/Card/CardNumber.tsx +12 -12
- package/src/components/Card/context.tsx +9 -9
- package/src/components/Card/index.ts +1 -1
- package/src/components/Card/types.ts +15 -14
- package/src/components/Card/utilities.ts +8 -8
- package/src/components/EvervaultProvider.tsx +64 -0
- package/src/index.tsx +5 -3
- package/src/native.ts +4 -4
- package/src/sdk.ts +12 -5
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
|
|
2
|
+
export interface ThreeDSecureCallbacks {
|
|
3
|
+
onError: (error: Error) => void;
|
|
4
|
+
onFailure: (error: Error) => void;
|
|
5
|
+
onSuccess: () => void;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface ThreeDSecureInitialState {
|
|
9
|
+
session: ThreeDSecureSession | null;
|
|
10
|
+
isVisible: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface ThreeDSecureProviderProps {
|
|
14
|
+
children: React.ReactNode;
|
|
15
|
+
state: ThreeDSecureState;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface ThreeDSecureSession {
|
|
19
|
+
cancel: () => Promise<void>;
|
|
20
|
+
get: () => Promise<ThreeDSecureSessionResponse>;
|
|
21
|
+
sessionId: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface ThreeDSecureSessionResponse {
|
|
25
|
+
nextAction: {
|
|
26
|
+
creq?: string;
|
|
27
|
+
type: string;
|
|
28
|
+
url?: string;
|
|
29
|
+
};
|
|
30
|
+
status: SessionStatus;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface ThreeDSecureSessionsParams {
|
|
34
|
+
appId: string;
|
|
35
|
+
callbacks: ThreeDSecureCallbacks;
|
|
36
|
+
intervalRef: React.MutableRefObject<NodeJS.Timeout | null>;
|
|
37
|
+
sessionId: string;
|
|
38
|
+
setIsVisible: (show: boolean) => void;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface ThreeDSecureState extends ThreeDSecureInitialState {
|
|
42
|
+
cancel: () => Promise<void>;
|
|
43
|
+
start: (sessionId: string, callbacks: ThreeDSecureCallbacks) => void;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
type SessionStatus = "action-required" | "failure" | "success";
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import { useRef } from "react";
|
|
3
|
+
import { useEvervault } from "../EvervaultProvider";
|
|
4
|
+
import { startSession, threeDSecureSession } from "./threeDSSession";
|
|
5
|
+
import {
|
|
6
|
+
ThreeDSecureCallbacks,
|
|
7
|
+
ThreeDSecureSession,
|
|
8
|
+
ThreeDSecureState
|
|
9
|
+
} from "./types";
|
|
10
|
+
|
|
11
|
+
export const useThreeDSecure = (): ThreeDSecureState => {
|
|
12
|
+
const { appUuid } = useEvervault();
|
|
13
|
+
const intervalRef = useRef<NodeJS.Timeout | null>(null);
|
|
14
|
+
const [session, setSession] = useState<ThreeDSecureSession | null>(null)
|
|
15
|
+
const [isVisible, setIsVisible] = useState(false);
|
|
16
|
+
|
|
17
|
+
if (!appUuid) {
|
|
18
|
+
throw new Error(
|
|
19
|
+
"useThreeDSecure must be used within an Evervault Provider"
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const start = (sessionId: string, callbacks: ThreeDSecureCallbacks) => {
|
|
24
|
+
const session = threeDSecureSession({
|
|
25
|
+
sessionId,
|
|
26
|
+
appId: appUuid,
|
|
27
|
+
callbacks,
|
|
28
|
+
intervalRef,
|
|
29
|
+
setIsVisible,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
setSession(session);
|
|
33
|
+
|
|
34
|
+
startSession(session, callbacks, intervalRef, setIsVisible);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const cancel = async () => {
|
|
38
|
+
if (session) {
|
|
39
|
+
await session.cancel();
|
|
40
|
+
} else {
|
|
41
|
+
console.warn("No 3DS session to cancel");
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
start,
|
|
47
|
+
cancel,
|
|
48
|
+
session,
|
|
49
|
+
isVisible: isVisible,
|
|
50
|
+
};
|
|
51
|
+
};
|
|
@@ -2,24 +2,24 @@ import {
|
|
|
2
2
|
validateNumber,
|
|
3
3
|
validateCVC,
|
|
4
4
|
validateExpiry,
|
|
5
|
-
} from
|
|
6
|
-
import * as React from
|
|
7
|
-
import { ReactNode,
|
|
8
|
-
import { useForm } from
|
|
9
|
-
import { changePayload, isAcceptedBrand, isComplete } from
|
|
10
|
-
import type { CardForm, CardConfig, CardField, CardPayload } from
|
|
11
|
-
import { CardNumber } from
|
|
12
|
-
import { CardContext } from
|
|
13
|
-
import { encrypt } from
|
|
14
|
-
import { CardCVC } from
|
|
15
|
-
import { CardHolder } from
|
|
16
|
-
import { CardExpiry } from
|
|
17
|
-
import { StyleProp, TextInputProps, TextStyle, View } from
|
|
5
|
+
} from "@evervault/card-validator";
|
|
6
|
+
import * as React from "react";
|
|
7
|
+
import { ReactNode, useState } from "react";
|
|
8
|
+
import { useForm } from "../useForm";
|
|
9
|
+
import { changePayload, isAcceptedBrand, isComplete } from "./utilities";
|
|
10
|
+
import type { CardForm, CardConfig, CardField, CardPayload } from "./types";
|
|
11
|
+
import { CardNumber } from "./CardNumber";
|
|
12
|
+
import { CardContext } from "./context";
|
|
13
|
+
import { encrypt } from "../../sdk";
|
|
14
|
+
import { CardCVC } from "./CardCVC";
|
|
15
|
+
import { CardHolder } from "./CardHolder";
|
|
16
|
+
import { CardExpiry } from "./CardExpiry";
|
|
17
|
+
import { StyleProp, TextInputProps, TextStyle, View } from "react-native";
|
|
18
18
|
|
|
19
19
|
export interface BaseProps
|
|
20
20
|
extends Omit<
|
|
21
21
|
TextInputProps,
|
|
22
|
-
|
|
22
|
+
"onChange" | "onChangeText" | "inputMode" | "autoComplete" | "value"
|
|
23
23
|
> {}
|
|
24
24
|
|
|
25
25
|
export interface CardProps {
|
|
@@ -37,56 +37,56 @@ function Card({ initialValue, config, children, onChange, style }: CardProps) {
|
|
|
37
37
|
|
|
38
38
|
const form = useForm<CardForm>({
|
|
39
39
|
initialValues: initialValue ?? {
|
|
40
|
-
cvc:
|
|
41
|
-
expiry:
|
|
42
|
-
number:
|
|
43
|
-
name:
|
|
40
|
+
cvc: "",
|
|
41
|
+
expiry: "",
|
|
42
|
+
number: "",
|
|
43
|
+
name: "",
|
|
44
44
|
},
|
|
45
45
|
validate: {
|
|
46
46
|
name: (values) => {
|
|
47
|
-
if (!registeredFields.has(
|
|
47
|
+
if (!registeredFields.has("name")) {
|
|
48
48
|
return undefined;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
if (values.name.length === 0) {
|
|
52
|
-
return
|
|
52
|
+
return "invalid";
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
return undefined;
|
|
56
56
|
},
|
|
57
57
|
number: (values) => {
|
|
58
|
-
if (!registeredFields.has(
|
|
58
|
+
if (!registeredFields.has("number")) {
|
|
59
59
|
return undefined;
|
|
60
60
|
}
|
|
61
61
|
const cardValidation = validateNumber(values.number);
|
|
62
62
|
if (!cardValidation.isValid) {
|
|
63
|
-
return
|
|
63
|
+
return "invalid";
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
if (!isAcceptedBrand(config?.acceptedBrands, cardValidation)) {
|
|
67
|
-
return
|
|
67
|
+
return "unsupportedBrand";
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
return undefined;
|
|
71
71
|
},
|
|
72
72
|
expiry: (values) => {
|
|
73
|
-
if (!registeredFields.has(
|
|
73
|
+
if (!registeredFields.has("expiry")) {
|
|
74
74
|
return undefined;
|
|
75
75
|
}
|
|
76
76
|
const expiryValidation = validateExpiry(values.expiry);
|
|
77
77
|
if (!expiryValidation.isValid) {
|
|
78
|
-
return
|
|
78
|
+
return "invalid";
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
return undefined;
|
|
82
82
|
},
|
|
83
83
|
cvc: (values) => {
|
|
84
|
-
if (!registeredFields.has(
|
|
84
|
+
if (!registeredFields.has("cvc")) {
|
|
85
85
|
return undefined;
|
|
86
86
|
}
|
|
87
87
|
const cvcValidation = validateCVC(values.cvc, values.number);
|
|
88
88
|
if (!cvcValidation.isValid) {
|
|
89
|
-
return
|
|
89
|
+
return "invalid";
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
return undefined;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { validateNumber } from
|
|
2
|
-
import * as React from
|
|
3
|
-
import { useEffect, useMemo } from
|
|
4
|
-
import { TextInputMask } from
|
|
5
|
-
import { removeFieldFromSet, useCardContext } from
|
|
6
|
-
import { BaseProps } from
|
|
1
|
+
import { validateNumber } from "@evervault/card-validator";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { useEffect, useMemo } from "react";
|
|
4
|
+
import { TextInputMask } from "react-native-masked-text";
|
|
5
|
+
import { removeFieldFromSet, useCardContext } from "./context";
|
|
6
|
+
import { BaseProps } from "./Card";
|
|
7
7
|
|
|
8
8
|
export interface CVCProps extends BaseProps {}
|
|
9
9
|
|
|
@@ -11,21 +11,21 @@ export const CardCVC = (props: CVCProps) => {
|
|
|
11
11
|
const context = useCardContext();
|
|
12
12
|
const mask = useMemo(() => {
|
|
13
13
|
if (!context.values.number) {
|
|
14
|
-
return
|
|
14
|
+
return "9999";
|
|
15
15
|
}
|
|
16
16
|
const type = validateNumber(context.values.number).brand;
|
|
17
|
-
if (type ===
|
|
18
|
-
return
|
|
17
|
+
if (type === "american-express") {
|
|
18
|
+
return "9999";
|
|
19
19
|
}
|
|
20
|
-
return
|
|
20
|
+
return "999";
|
|
21
21
|
}, [context.values.number]);
|
|
22
22
|
|
|
23
|
-
const { onChange, onBlur } = context.register(
|
|
23
|
+
const { onChange, onBlur } = context.register("cvc");
|
|
24
24
|
|
|
25
25
|
useEffect(() => {
|
|
26
|
-
context.setRegisteredFields((prev) => new Set(prev).add(
|
|
26
|
+
context.setRegisteredFields((prev) => new Set(prev).add("cvc"));
|
|
27
27
|
return () =>
|
|
28
|
-
context.setRegisteredFields((prev) => removeFieldFromSet(prev,
|
|
28
|
+
context.setRegisteredFields((prev) => removeFieldFromSet(prev, "cvc"));
|
|
29
29
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
30
30
|
}, []);
|
|
31
31
|
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { TextInputMask } from
|
|
2
|
-
import { removeFieldFromSet, useCardContext } from
|
|
3
|
-
import * as React from
|
|
4
|
-
import { useEffect } from
|
|
5
|
-
import { BaseProps } from
|
|
1
|
+
import { TextInputMask } from "react-native-masked-text";
|
|
2
|
+
import { removeFieldFromSet, useCardContext } from "./context";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { useEffect } from "react";
|
|
5
|
+
import { BaseProps } from "./Card";
|
|
6
6
|
|
|
7
7
|
export interface CardExpiryProps extends BaseProps {}
|
|
8
8
|
|
|
9
9
|
export function CardExpiry(props: CardExpiryProps) {
|
|
10
10
|
const context = useCardContext();
|
|
11
11
|
|
|
12
|
-
const { onBlur, onChange } = context.register(
|
|
12
|
+
const { onBlur, onChange } = context.register("expiry");
|
|
13
13
|
|
|
14
14
|
useEffect(() => {
|
|
15
|
-
context.setRegisteredFields((prev) => new Set(prev).add(
|
|
15
|
+
context.setRegisteredFields((prev) => new Set(prev).add("expiry"));
|
|
16
16
|
return () =>
|
|
17
|
-
context.setRegisteredFields((prev) => removeFieldFromSet(prev,
|
|
17
|
+
context.setRegisteredFields((prev) => removeFieldFromSet(prev, "expiry"));
|
|
18
18
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
19
19
|
}, []);
|
|
20
20
|
|
|
@@ -24,16 +24,16 @@ export function CardExpiry(props: CardExpiryProps) {
|
|
|
24
24
|
type="datetime"
|
|
25
25
|
value={context.values.expiry}
|
|
26
26
|
// store the expiry as MMYY not MM / YY
|
|
27
|
-
onChangeText={(rawExpiry) => onChange(rawExpiry.replace(
|
|
27
|
+
onChangeText={(rawExpiry) => onChange(rawExpiry.replace(" / ", ""))}
|
|
28
28
|
options={{
|
|
29
|
-
format:
|
|
29
|
+
format: "99 / 99",
|
|
30
30
|
}}
|
|
31
31
|
id="expiry"
|
|
32
32
|
onBlur={(e) => {
|
|
33
33
|
onBlur(e);
|
|
34
34
|
props.onBlur?.(e);
|
|
35
35
|
}}
|
|
36
|
-
placeholder={props.placeholder ??
|
|
36
|
+
placeholder={props.placeholder ?? "MM / YY"}
|
|
37
37
|
inputMode="numeric"
|
|
38
38
|
autoComplete="cc-exp"
|
|
39
39
|
/>
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { useEffect } from
|
|
2
|
-
import * as React from
|
|
3
|
-
import { Platform, TextInput } from
|
|
4
|
-
import { removeFieldFromSet, useCardContext } from
|
|
5
|
-
import { BaseProps } from
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { Platform, TextInput } from "react-native";
|
|
4
|
+
import { removeFieldFromSet, useCardContext } from "./context";
|
|
5
|
+
import { BaseProps } from "./Card";
|
|
6
6
|
|
|
7
7
|
export interface CardHolderProps extends BaseProps {}
|
|
8
8
|
|
|
9
9
|
export function CardHolder(props: CardHolderProps) {
|
|
10
10
|
const context = useCardContext();
|
|
11
11
|
|
|
12
|
-
const { onBlur, onChange } = context.register(
|
|
12
|
+
const { onBlur, onChange } = context.register("name");
|
|
13
13
|
|
|
14
14
|
useEffect(() => {
|
|
15
|
-
context.setRegisteredFields((prev) => new Set(prev).add(
|
|
15
|
+
context.setRegisteredFields((prev) => new Set(prev).add("name"));
|
|
16
16
|
return () =>
|
|
17
|
-
context.setRegisteredFields((prev) => removeFieldFromSet(prev,
|
|
17
|
+
context.setRegisteredFields((prev) => removeFieldFromSet(prev, "name"));
|
|
18
18
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
19
19
|
}, []);
|
|
20
20
|
|
|
@@ -28,8 +28,8 @@ export function CardHolder(props: CardHolderProps) {
|
|
|
28
28
|
props.onBlur?.(e);
|
|
29
29
|
}}
|
|
30
30
|
autoComplete={Platform.select({
|
|
31
|
-
ios:
|
|
32
|
-
android:
|
|
31
|
+
ios: "cc-name",
|
|
32
|
+
android: "name",
|
|
33
33
|
})}
|
|
34
34
|
onChangeText={(v) => onChange(v)}
|
|
35
35
|
/>
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { validateNumber } from
|
|
2
|
-
import * as React from
|
|
3
|
-
import { useEffect, useMemo, useRef } from
|
|
4
|
-
import { TextInputMask } from
|
|
5
|
-
import { removeFieldFromSet, useCardContext } from
|
|
6
|
-
import { BaseProps } from
|
|
1
|
+
import { validateNumber } from "@evervault/card-validator";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { useEffect, useMemo, useRef } from "react";
|
|
4
|
+
import { TextInputMask } from "react-native-masked-text";
|
|
5
|
+
import { removeFieldFromSet, useCardContext } from "./context";
|
|
6
|
+
import { BaseProps } from "./Card";
|
|
7
7
|
|
|
8
8
|
interface CardNumberProps extends BaseProps {}
|
|
9
9
|
|
|
@@ -17,9 +17,9 @@ export function CardNumber(props: CardNumberProps) {
|
|
|
17
17
|
const { brand } = validateNumber(value);
|
|
18
18
|
|
|
19
19
|
const masks = {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
default: "9999 9999 9999 9999",
|
|
21
|
+
unionpay: "9999 9999 9999 9999 999",
|
|
22
|
+
"american-express": "9999 999999 99999",
|
|
23
23
|
} as Record<string, string>;
|
|
24
24
|
|
|
25
25
|
if (brand && !!masks[brand]) {
|
|
@@ -28,13 +28,13 @@ export function CardNumber(props: CardNumberProps) {
|
|
|
28
28
|
return [value, masks.default];
|
|
29
29
|
}, [context.values.number]);
|
|
30
30
|
|
|
31
|
-
const { onBlur, onChange } = context.register(
|
|
31
|
+
const { onBlur, onChange } = context.register("number");
|
|
32
32
|
|
|
33
33
|
useEffect(() => {
|
|
34
|
-
context.setRegisteredFields((prev) => new Set(prev).add(
|
|
34
|
+
context.setRegisteredFields((prev) => new Set(prev).add("number"));
|
|
35
35
|
|
|
36
36
|
return () =>
|
|
37
|
-
context.setRegisteredFields((prev) => removeFieldFromSet(prev,
|
|
37
|
+
context.setRegisteredFields((prev) => removeFieldFromSet(prev, "number"));
|
|
38
38
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
39
39
|
}, []);
|
|
40
40
|
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { UseFormReturn } from
|
|
2
|
-
import { Dispatch, SetStateAction, createContext, useContext } from
|
|
3
|
-
import { CardForm, CardField } from
|
|
1
|
+
import { UseFormReturn } from "../useForm";
|
|
2
|
+
import { Dispatch, SetStateAction, createContext, useContext } from "react";
|
|
3
|
+
import { CardForm, CardField } from "./types";
|
|
4
4
|
|
|
5
5
|
type Context<T> = {
|
|
6
6
|
values: CardForm;
|
|
7
|
-
register: UseFormReturn<T>[
|
|
7
|
+
register: UseFormReturn<T>["register"];
|
|
8
8
|
setRegisteredFields: Dispatch<SetStateAction<Set<CardField>>>;
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
export const removeFieldFromSet = (prev: Set<CardField>, field: CardField) => {
|
|
12
12
|
const next = new Set(prev);
|
|
13
|
-
next.delete(
|
|
13
|
+
next.delete("name");
|
|
14
14
|
return next;
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
export const CardContext = createContext<Context<CardForm>>({
|
|
18
18
|
values: {
|
|
19
|
-
name:
|
|
20
|
-
number:
|
|
21
|
-
cvc:
|
|
22
|
-
expiry:
|
|
19
|
+
name: "",
|
|
20
|
+
number: "",
|
|
21
|
+
cvc: "",
|
|
22
|
+
expiry: "",
|
|
23
23
|
},
|
|
24
24
|
register: () => ({
|
|
25
25
|
onChange: () => {},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { Card, type CardProps } from
|
|
1
|
+
export { Card, type CardProps } from "./Card";
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
export type CardBrandName =
|
|
2
|
-
|
|
|
3
|
-
|
|
|
4
|
-
|
|
|
5
|
-
|
|
|
6
|
-
|
|
|
7
|
-
|
|
|
8
|
-
|
|
|
9
|
-
|
|
|
10
|
-
|
|
|
11
|
-
|
|
|
12
|
-
|
|
|
13
|
-
|
|
|
14
|
-
|
|
|
2
|
+
| "american-express"
|
|
3
|
+
| "visa"
|
|
4
|
+
| "mastercard"
|
|
5
|
+
| "discover"
|
|
6
|
+
| "jcb"
|
|
7
|
+
| "diners-club"
|
|
8
|
+
| "unionpay"
|
|
9
|
+
| "maestro"
|
|
10
|
+
| "mir"
|
|
11
|
+
| "elo"
|
|
12
|
+
| "hipercard"
|
|
13
|
+
| "hiper"
|
|
14
|
+
| "szep"
|
|
15
|
+
| "uatp";
|
|
15
16
|
|
|
16
17
|
export interface CardConfig {
|
|
17
18
|
acceptedBrands?: CardBrandName[];
|
|
@@ -24,7 +25,7 @@ export interface CardForm {
|
|
|
24
25
|
expiry: string;
|
|
25
26
|
}
|
|
26
27
|
|
|
27
|
-
export type CardField =
|
|
28
|
+
export type CardField = "name" | "number" | "expiry" | "cvc";
|
|
28
29
|
|
|
29
30
|
export interface CardExpiry {
|
|
30
31
|
month: string | null;
|
|
@@ -3,9 +3,9 @@ import {
|
|
|
3
3
|
validateExpiry,
|
|
4
4
|
validateCVC,
|
|
5
5
|
CardNumberValidationResult,
|
|
6
|
-
} from
|
|
7
|
-
import type { CardForm, CardBrandName, CardField, CardPayload } from
|
|
8
|
-
import { UseFormReturn } from
|
|
6
|
+
} from "@evervault/card-validator";
|
|
7
|
+
import type { CardForm, CardBrandName, CardField, CardPayload } from "./types";
|
|
8
|
+
import { UseFormReturn } from "../useForm";
|
|
9
9
|
|
|
10
10
|
export async function changePayload(
|
|
11
11
|
encrypt: (value: string) => Promise<string>,
|
|
@@ -14,7 +14,7 @@ export async function changePayload(
|
|
|
14
14
|
): Promise<CardPayload> {
|
|
15
15
|
const { name, number: rawNumber, expiry, cvc } = form.values;
|
|
16
16
|
|
|
17
|
-
const number = rawNumber.replace(/\s/g,
|
|
17
|
+
const number = rawNumber.replace(/\s/g, "");
|
|
18
18
|
|
|
19
19
|
const {
|
|
20
20
|
brand,
|
|
@@ -41,21 +41,21 @@ export async function changePayload(
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
export function isComplete(form: UseFormReturn<CardForm>, fields: CardField[]) {
|
|
44
|
-
if (fields.includes(
|
|
44
|
+
if (fields.includes("name")) {
|
|
45
45
|
if (form.values.name.length === 0) return false;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
if (fields.includes(
|
|
48
|
+
if (fields.includes("number")) {
|
|
49
49
|
const cardValidation = validateNumber(form.values.number);
|
|
50
50
|
if (!cardValidation.isValid) return false;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
if (fields.includes(
|
|
53
|
+
if (fields.includes("expiry")) {
|
|
54
54
|
const expiryValidation = validateExpiry(form.values.expiry);
|
|
55
55
|
if (!expiryValidation.isValid) return false;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
if (fields.includes(
|
|
58
|
+
if (fields.includes("cvc")) {
|
|
59
59
|
const cvcValidation = validateCVC(form.values.cvc, form.values.number);
|
|
60
60
|
if (!cvcValidation.isValid) return false;
|
|
61
61
|
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { ReactNode, createContext, useContext, useEffect } from "react";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { EvervaultSdk } from "../native";
|
|
4
|
+
|
|
5
|
+
export interface EvervaultContext {
|
|
6
|
+
teamUuid?: string;
|
|
7
|
+
appUuid?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const Ctx = createContext<EvervaultContext>({
|
|
11
|
+
teamUuid: undefined,
|
|
12
|
+
appUuid: undefined,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
// this isn't publicly exposed
|
|
16
|
+
export const useEvervault = () => useContext(Ctx);
|
|
17
|
+
|
|
18
|
+
interface EvervaultProps {
|
|
19
|
+
appId: string;
|
|
20
|
+
teamId: string;
|
|
21
|
+
children: ReactNode;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @example
|
|
26
|
+
* ```tsx
|
|
27
|
+
* function App() {
|
|
28
|
+
* return (
|
|
29
|
+
* <EvervaultProvider teamId="team_123" appId="app_123">
|
|
30
|
+
* <Card onChange={(card) => console.log(card)}>
|
|
31
|
+
* <Card.Number />
|
|
32
|
+
* </Card>
|
|
33
|
+
* </EvervaultProvider>
|
|
34
|
+
* );
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
const EvervaultProvider = ({ teamId, appId, children }: EvervaultProps) => {
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
async function initEvervault() {
|
|
41
|
+
try {
|
|
42
|
+
if (!teamId || !appId) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return EvervaultSdk.initialize(teamId, appId);
|
|
47
|
+
} catch (error) {
|
|
48
|
+
throw new Error(`Failed to initialize the Evervault SDK ${error}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (teamId || appId) {
|
|
53
|
+
initEvervault();
|
|
54
|
+
}
|
|
55
|
+
}, [teamId, appId]);
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<Ctx.Provider value={{ teamUuid: teamId, appUuid: appId }}>
|
|
59
|
+
{children}
|
|
60
|
+
</Ctx.Provider>
|
|
61
|
+
);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export default EvervaultProvider;
|
package/src/index.tsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export { type CardProps, Card } from
|
|
2
|
-
export {
|
|
1
|
+
export { type CardProps, Card } from "./components/Card";
|
|
2
|
+
export { ThreeDSecure, useThreeDSecure } from "./components/3DS";
|
|
3
|
+
export { init, encrypt } from "./sdk";
|
|
3
4
|
export type {
|
|
4
5
|
CardPayload,
|
|
5
6
|
CardExpiry,
|
|
@@ -7,4 +8,5 @@ export type {
|
|
|
7
8
|
CardConfig,
|
|
8
9
|
CardForm,
|
|
9
10
|
CardField,
|
|
10
|
-
} from
|
|
11
|
+
} from "./components/Card/types";
|
|
12
|
+
export { default as EvervaultProvider } from "./components/EvervaultProvider";
|
package/src/native.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { NativeModules, Platform } from
|
|
1
|
+
import { NativeModules, Platform } from "react-native";
|
|
2
2
|
|
|
3
3
|
const LINKING_ERROR =
|
|
4
4
|
`The package '@evervault/evervault-react-native' doesn't seem to be linked. Make sure: \n\n` +
|
|
5
|
-
Platform.select({ ios: "- You have run 'pod install'\n", default:
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
Platform.select({ ios: "- You have run 'pod install'\n", default: "" }) +
|
|
6
|
+
"- You rebuilt the app after installing the package\n" +
|
|
7
|
+
"- You are not using Expo Go\n";
|
|
8
8
|
|
|
9
9
|
export const EvervaultSdk = NativeModules.EvervaultSdk
|
|
10
10
|
? NativeModules.EvervaultSdk
|
package/src/sdk.ts
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
|
-
import { Platform } from
|
|
2
|
-
import { EvervaultSdk } from
|
|
1
|
+
import { Platform } from "react-native";
|
|
2
|
+
import { EvervaultSdk } from "./native";
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated Deprecated since version 1.1.0. Use `EvervaultProvider` instead.
|
|
6
|
+
* @see `EvervaultProvider` instead
|
|
7
|
+
* ```tsx
|
|
8
|
+
* import { EvervaultProvider } from "@evervault/evervault-react-native";
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
4
11
|
export async function init(teamUuid: string, appUuid: string): Promise<void> {
|
|
5
|
-
if (!teamUuid
|
|
12
|
+
if (!teamUuid?.startsWith("team_")) {
|
|
6
13
|
throw new Error("Invalid Evervault Team UUID");
|
|
7
14
|
}
|
|
8
15
|
|
|
9
|
-
if (!appUuid
|
|
16
|
+
if (!appUuid?.startsWith("app_")) {
|
|
10
17
|
throw new Error("Invalid Evervault App UUID");
|
|
11
18
|
}
|
|
12
19
|
|
|
@@ -14,7 +21,7 @@ export async function init(teamUuid: string, appUuid: string): Promise<void> {
|
|
|
14
21
|
}
|
|
15
22
|
|
|
16
23
|
export async function encrypt(data: any): Promise<string> {
|
|
17
|
-
if (Platform.OS ===
|
|
24
|
+
if (Platform.OS === "android" && typeof data !== "string") {
|
|
18
25
|
throw new Error(`The Evervault SDK does not currently support encrypting non-string data on Android.
|
|
19
26
|
If this is required for your use case, please get in touch with us at support@evervault.com. Please do not
|
|
20
27
|
serialize other data types to strings and pass them to this method as this will result in the data
|