@evervault/evervault-react-native 1.0.0 → 1.1.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.
Files changed (74) hide show
  1. package/README.md +34 -39
  2. package/dist/commonjs/components/Card/Card.js +13 -13
  3. package/dist/commonjs/components/Card/Card.js.map +1 -1
  4. package/dist/commonjs/components/Card/CardCVC.js +11 -8
  5. package/dist/commonjs/components/Card/CardCVC.js.map +1 -1
  6. package/dist/commonjs/components/Card/CardExpiry.js +10 -7
  7. package/dist/commonjs/components/Card/CardExpiry.js.map +1 -1
  8. package/dist/commonjs/components/Card/CardHolder.js +9 -6
  9. package/dist/commonjs/components/Card/CardHolder.js.map +1 -1
  10. package/dist/commonjs/components/Card/CardNumber.js +10 -7
  11. package/dist/commonjs/components/Card/CardNumber.js.map +1 -1
  12. package/dist/commonjs/components/Card/context.js +5 -5
  13. package/dist/commonjs/components/Card/utilities.js +5 -5
  14. package/dist/commonjs/components/EvervaultProvider.js +62 -0
  15. package/dist/commonjs/components/EvervaultProvider.js.map +1 -0
  16. package/dist/commonjs/index.js +8 -0
  17. package/dist/commonjs/index.js.map +1 -1
  18. package/dist/commonjs/native.js +2 -2
  19. package/dist/commonjs/sdk.js +10 -3
  20. package/dist/commonjs/sdk.js.map +1 -1
  21. package/dist/module/components/Card/Card.js +25 -25
  22. package/dist/module/components/Card/Card.js.map +1 -1
  23. package/dist/module/components/Card/CardCVC.js +16 -13
  24. package/dist/module/components/Card/CardCVC.js.map +1 -1
  25. package/dist/module/components/Card/CardExpiry.js +14 -11
  26. package/dist/module/components/Card/CardExpiry.js.map +1 -1
  27. package/dist/module/components/Card/CardHolder.js +13 -10
  28. package/dist/module/components/Card/CardHolder.js.map +1 -1
  29. package/dist/module/components/Card/CardNumber.js +15 -12
  30. package/dist/module/components/Card/CardNumber.js.map +1 -1
  31. package/dist/module/components/Card/context.js +6 -6
  32. package/dist/module/components/Card/index.js +1 -1
  33. package/dist/module/components/Card/utilities.js +6 -6
  34. package/dist/module/components/EvervaultProvider.js +53 -0
  35. package/dist/module/components/EvervaultProvider.js.map +1 -0
  36. package/dist/module/index.js +3 -2
  37. package/dist/module/index.js.map +1 -1
  38. package/dist/module/native.js +3 -3
  39. package/dist/module/sdk.js +13 -5
  40. package/dist/module/sdk.js.map +1 -1
  41. package/dist/typescript/src/components/Card/Card.d.ts +8 -8
  42. package/dist/typescript/src/components/Card/Card.d.ts.map +1 -1
  43. package/dist/typescript/src/components/Card/CardCVC.d.ts +2 -2
  44. package/dist/typescript/src/components/Card/CardCVC.d.ts.map +1 -1
  45. package/dist/typescript/src/components/Card/CardExpiry.d.ts +2 -2
  46. package/dist/typescript/src/components/Card/CardExpiry.d.ts.map +1 -1
  47. package/dist/typescript/src/components/Card/CardHolder.d.ts +2 -2
  48. package/dist/typescript/src/components/Card/CardHolder.d.ts.map +1 -1
  49. package/dist/typescript/src/components/Card/CardNumber.d.ts +2 -2
  50. package/dist/typescript/src/components/Card/CardNumber.d.ts.map +1 -1
  51. package/dist/typescript/src/components/Card/context.d.ts +4 -4
  52. package/dist/typescript/src/components/Card/index.d.ts +1 -1
  53. package/dist/typescript/src/components/Card/types.d.ts +2 -2
  54. package/dist/typescript/src/components/Card/utilities.d.ts +3 -3
  55. package/dist/typescript/src/components/EvervaultProvider.d.ts +29 -0
  56. package/dist/typescript/src/components/EvervaultProvider.d.ts.map +1 -0
  57. package/dist/typescript/src/index.d.ts +4 -3
  58. package/dist/typescript/src/index.d.ts.map +1 -1
  59. package/dist/typescript/src/sdk.d.ts +7 -0
  60. package/dist/typescript/src/sdk.d.ts.map +1 -1
  61. package/package.json +4 -79
  62. package/src/components/Card/Card.tsx +27 -32
  63. package/src/components/Card/CardCVC.tsx +17 -14
  64. package/src/components/Card/CardExpiry.tsx +15 -12
  65. package/src/components/Card/CardHolder.tsx +14 -11
  66. package/src/components/Card/CardNumber.tsx +16 -13
  67. package/src/components/Card/context.tsx +9 -9
  68. package/src/components/Card/index.ts +1 -1
  69. package/src/components/Card/types.ts +14 -14
  70. package/src/components/Card/utilities.ts +8 -8
  71. package/src/components/EvervaultProvider.tsx +64 -0
  72. package/src/index.tsx +4 -3
  73. package/src/native.ts +4 -4
  74. package/src/sdk.ts +12 -5
@@ -3,9 +3,9 @@ import {
3
3
  validateExpiry,
4
4
  validateCVC,
5
5
  CardNumberValidationResult,
6
- } from '@evervault/card-validator';
7
- import type { CardForm, CardBrandName, CardField, CardPayload } from './types';
8
- import { UseFormReturn } from '../useForm';
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('name')) {
44
+ if (fields.includes("name")) {
45
45
  if (form.values.name.length === 0) return false;
46
46
  }
47
47
 
48
- if (fields.includes('number')) {
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('expiry')) {
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('cvc')) {
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,5 @@
1
- export { type CardProps, Card } from './components/Card';
2
- export { init, encrypt } from './sdk';
1
+ export { type CardProps, Card } from "./components/Card";
2
+ export { init, encrypt } from "./sdk";
3
3
  export type {
4
4
  CardPayload,
5
5
  CardExpiry,
@@ -7,4 +7,5 @@ export type {
7
7
  CardConfig,
8
8
  CardForm,
9
9
  CardField,
10
- } from './components/Card/types';
10
+ } from "./components/Card/types";
11
+ export { default as EvervaultProvider } from "./components/EvervaultProvider";
package/src/native.ts CHANGED
@@ -1,10 +1,10 @@
1
- import { NativeModules, Platform } from 'react-native';
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
- '- You rebuilt the app after installing the package\n' +
7
- '- You are not using Expo Go\n';
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 'react-native';
2
- import { EvervaultSdk } from './native';
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.startsWith('team_')) {
12
+ if (!teamUuid?.startsWith("team_")) {
6
13
  throw new Error("Invalid Evervault Team UUID");
7
14
  }
8
15
 
9
- if (!appUuid.startsWith('app_')) {
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 === 'android' && typeof data !== 'string') {
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