@evervault/react-native 2.6.0 → 2.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -2
- package/src/Card/Cvc.test.tsx +41 -0
- package/src/Card/Cvc.tsx +58 -0
- package/src/Card/Expiry.tsx +26 -0
- package/src/Card/Holder.tsx +27 -0
- package/src/Card/Number.test.tsx +76 -0
- package/src/Card/Number.tsx +54 -0
- package/src/Card/Root.test.tsx +341 -0
- package/src/Card/Root.tsx +150 -0
- package/src/Card/index.ts +28 -0
- package/src/Card/schema.ts +41 -0
- package/src/Card/types.ts +57 -0
- package/src/Card/utils.test.ts +271 -0
- package/src/Card/utils.ts +129 -0
- package/src/EvervaultProvider.test.tsx +24 -0
- package/src/EvervaultProvider.tsx +43 -0
- package/src/Input.test.tsx +420 -0
- package/src/Input.tsx +182 -0
- package/src/ThreeDSecure/Frame.test.tsx +87 -0
- package/src/ThreeDSecure/Frame.tsx +50 -0
- package/src/ThreeDSecure/Root.test.tsx +67 -0
- package/src/ThreeDSecure/Root.tsx +23 -0
- package/src/ThreeDSecure/config.ts +3 -0
- package/src/ThreeDSecure/context.ts +6 -0
- package/src/ThreeDSecure/event.ts +19 -0
- package/src/ThreeDSecure/index.ts +17 -0
- package/src/ThreeDSecure/session.test.ts +524 -0
- package/src/ThreeDSecure/session.ts +184 -0
- package/src/ThreeDSecure/types.ts +80 -0
- package/src/ThreeDSecure/useThreeDSecure.test.tsx +244 -0
- package/src/ThreeDSecure/useThreeDSecure.ts +64 -0
- package/src/__mocks__/NativeEvervault.ts +13 -0
- package/src/__mocks__/react-native-webview.tsx +6 -0
- package/src/context.ts +14 -0
- package/src/index.ts +21 -0
- package/src/sdk.test.ts +122 -0
- package/src/sdk.ts +71 -0
- package/src/specs/NativeEvervault.ts +67 -0
- package/src/useEvervault.test.tsx +31 -0
- package/src/useEvervault.ts +14 -0
- package/src/utils.ts +41 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { TurboModule, TurboModuleRegistry } from "react-native";
|
|
2
|
+
|
|
3
|
+
export interface Spec extends TurboModule {
|
|
4
|
+
/**
|
|
5
|
+
* Initialize the Evervault SDK.
|
|
6
|
+
*
|
|
7
|
+
* @param teamId - The team ID.
|
|
8
|
+
* @param appId - The app ID.
|
|
9
|
+
*
|
|
10
|
+
* @returns A unique identifier for the SDK instance.
|
|
11
|
+
*/
|
|
12
|
+
initialize(teamId: string, appId: string): string;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Encrypt a string.
|
|
16
|
+
*
|
|
17
|
+
* @param instanceId - The unique identifier for the SDK instance.
|
|
18
|
+
* @param data - The string to encrypt.
|
|
19
|
+
*
|
|
20
|
+
* @returns The encrypted string.
|
|
21
|
+
*/
|
|
22
|
+
encryptString(instanceId: string, data: string): Promise<string>;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Encrypt a number.
|
|
26
|
+
*
|
|
27
|
+
* @param instanceId - The unique identifier for the SDK instance.
|
|
28
|
+
* @param data - The number to encrypt.
|
|
29
|
+
*
|
|
30
|
+
* @returns The encrypted number.
|
|
31
|
+
*/
|
|
32
|
+
encryptNumber(instanceId: string, data: number): Promise<string>;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Encrypt a boolean.
|
|
36
|
+
*
|
|
37
|
+
* @param instanceId - The unique identifier for the SDK instance.
|
|
38
|
+
* @param data - The boolean to encrypt.
|
|
39
|
+
*
|
|
40
|
+
* @returns The encrypted boolean.
|
|
41
|
+
*/
|
|
42
|
+
encryptBoolean(instanceId: string, data: boolean): Promise<string>;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Encrypt an object.
|
|
46
|
+
*
|
|
47
|
+
* @param instanceId - The unique identifier for the SDK instance.
|
|
48
|
+
* @param data - The object to encrypt.
|
|
49
|
+
*
|
|
50
|
+
* @returns The encrypted object.
|
|
51
|
+
*/
|
|
52
|
+
encryptObject(instanceId: string, data: Object): Promise<Object>;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Encrypt an array.
|
|
56
|
+
*
|
|
57
|
+
* @param instanceId - The unique identifier for the SDK instance.
|
|
58
|
+
* @param data - The array to encrypt.
|
|
59
|
+
*
|
|
60
|
+
* @returns The encrypted array.
|
|
61
|
+
*/
|
|
62
|
+
encryptArray(instanceId: string, data: Array<any>): Promise<Array<any>>;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export const NativeEvervault = TurboModuleRegistry.get<Spec>(
|
|
66
|
+
"NativeEvervault"
|
|
67
|
+
) as Spec | null;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { renderHook } from "@testing-library/react-native";
|
|
2
|
+
import { useEvervault } from "./useEvervault";
|
|
3
|
+
import { EvervaultProvider } from "./EvervaultProvider";
|
|
4
|
+
import { PropsWithChildren } from "react";
|
|
5
|
+
import { ErrorBoundary } from "./utils";
|
|
6
|
+
|
|
7
|
+
it("throws an error if used outside of EvervaultProvider", () => {
|
|
8
|
+
const onError = vi.fn();
|
|
9
|
+
const wrapper = ({ children }: PropsWithChildren) => (
|
|
10
|
+
<ErrorBoundary onError={onError}>{children}</ErrorBoundary>
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
renderHook(() => useEvervault(), { wrapper });
|
|
14
|
+
expect(onError).toHaveBeenCalledWith(
|
|
15
|
+
new Error("`useEvervault` must be used within an `EvervaultProvider`.")
|
|
16
|
+
);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("returns the config when used within EvervaultProvider", () => {
|
|
20
|
+
const wrapper = ({ children }: PropsWithChildren) => (
|
|
21
|
+
<EvervaultProvider teamId="team_123" appId="app_123">
|
|
22
|
+
{children}
|
|
23
|
+
</EvervaultProvider>
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
const { result } = renderHook(() => useEvervault(), { wrapper });
|
|
27
|
+
|
|
28
|
+
expect(result.current.appId).toBe("app_123");
|
|
29
|
+
expect(result.current.teamId).toBe("team_123");
|
|
30
|
+
expect(result.current.encrypt).toStrictEqual(expect.any(Function));
|
|
31
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { EvervaultContext } from "./context";
|
|
3
|
+
|
|
4
|
+
export function useEvervault() {
|
|
5
|
+
const context = useContext(EvervaultContext);
|
|
6
|
+
|
|
7
|
+
if (!context) {
|
|
8
|
+
throw new Error(
|
|
9
|
+
"`useEvervault` must be used within an `EvervaultProvider`."
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return context;
|
|
14
|
+
}
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Component,
|
|
3
|
+
LegacyRef,
|
|
4
|
+
MutableRefObject,
|
|
5
|
+
PropsWithChildren,
|
|
6
|
+
RefCallback,
|
|
7
|
+
} from "react";
|
|
8
|
+
|
|
9
|
+
// Taken from https://github.com/gregberge/react-merge-refs
|
|
10
|
+
export function mergeRefs<T = any>(
|
|
11
|
+
...refs: Array<MutableRefObject<T> | LegacyRef<T> | undefined | null>
|
|
12
|
+
): RefCallback<T> {
|
|
13
|
+
return (value) => {
|
|
14
|
+
refs.forEach((ref) => {
|
|
15
|
+
if (typeof ref === "function") {
|
|
16
|
+
ref(value);
|
|
17
|
+
} else if (ref != null) {
|
|
18
|
+
(ref as MutableRefObject<T | null>).current = value;
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export class ErrorBoundary extends Component<
|
|
25
|
+
PropsWithChildren<{ onError?(error: Error): void }>
|
|
26
|
+
> {
|
|
27
|
+
state = { hasError: false };
|
|
28
|
+
|
|
29
|
+
static getDerivedStateFromError() {
|
|
30
|
+
return { hasError: true };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
componentDidCatch(error: Error) {
|
|
34
|
+
this.props.onError?.(error);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
render() {
|
|
38
|
+
if (this.state.hasError) return null;
|
|
39
|
+
return this.props.children;
|
|
40
|
+
}
|
|
41
|
+
}
|