@evervault/react-native 2.2.0 → 2.3.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/build/Card/schema.d.ts +2 -12
- package/build/Card/schema.d.ts.map +1 -1
- package/build/Card/types.d.ts +7 -1
- package/build/Card/types.d.ts.map +1 -1
- package/build/Card/utils.d.ts.map +1 -1
- package/build/index.cjs.js +43 -29
- package/build/index.cjs.js.map +1 -1
- package/build/index.esm.js +43 -29
- package/package.json +2 -2
- package/src/Card/Root.test.tsx +81 -0
- package/src/Card/schema.ts +25 -35
- package/src/Card/types.ts +7 -0
- package/src/Card/utils.ts +2 -0
package/build/Card/schema.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { CardBrandName } from "./types";
|
|
3
|
-
export declare function getCardFormSchema(acceptedBrands: CardBrandName[]): z.
|
|
3
|
+
export declare function getCardFormSchema(acceptedBrands: CardBrandName[]): z.ZodObject<{
|
|
4
4
|
name: z.ZodString;
|
|
5
|
-
number: z.ZodEffects<z.ZodString, string, string>;
|
|
5
|
+
number: z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
|
6
6
|
expiry: z.ZodEffects<z.ZodString, string, string>;
|
|
7
7
|
cvc: z.ZodEffects<z.ZodString, string, string>;
|
|
8
8
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -15,16 +15,6 @@ export declare function getCardFormSchema(acceptedBrands: CardBrandName[]): z.Zo
|
|
|
15
15
|
name: string;
|
|
16
16
|
expiry: string;
|
|
17
17
|
cvc: string;
|
|
18
|
-
}>, {
|
|
19
|
-
number: string;
|
|
20
|
-
name: string;
|
|
21
|
-
expiry: string;
|
|
22
|
-
cvc: string;
|
|
23
|
-
}, {
|
|
24
|
-
number: string;
|
|
25
|
-
name: string;
|
|
26
|
-
expiry: string;
|
|
27
|
-
cvc: string;
|
|
28
18
|
}>;
|
|
29
19
|
export type CardFormValues = z.infer<ReturnType<typeof getCardFormSchema>>;
|
|
30
20
|
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/Card/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAGxC,wBAAgB,iBAAiB,CAAC,cAAc,EAAE,aAAa,EAAE
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/Card/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAGxC,wBAAgB,iBAAiB,CAAC,cAAc,EAAE,aAAa,EAAE;;;;;;;;;;;;;;;GA6BhE;AAED,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAC,CAAC"}
|
package/build/Card/types.d.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
export declare const CARD_BRAND_NAMES: readonly ["american-express", "visa", "mastercard", "discover", "jcb", "diners-club", "unionpay", "maestro", "mir", "elo", "hipercard", "hiper", "szep", "uatp"];
|
|
1
|
+
export declare const CARD_BRAND_NAMES: readonly ["american-express", "visa", "mastercard", "discover", "jcb", "diners-club", "unionpay", "maestro", "mir", "elo", "hipercard", "hiper", "szep", "uatp", "rupay"];
|
|
2
2
|
export type CardBrandName = (typeof CARD_BRAND_NAMES)[number];
|
|
3
3
|
export interface CardConfig {
|
|
4
|
+
/**
|
|
5
|
+
* The brands that are accepted by the card form.
|
|
6
|
+
* Pass an empty array to accept all brands.
|
|
7
|
+
*
|
|
8
|
+
* @default []
|
|
9
|
+
*/
|
|
4
10
|
acceptedBrands?: CardBrandName[];
|
|
5
11
|
}
|
|
6
12
|
export type CardField = "name" | "number" | "expiry" | "cvc";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/Card/types.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/Card/types.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,2KAgBnB,CAAC;AAEX,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE9D,MAAM,WAAW,UAAU;IACzB;;;;;OAKG;IACH,cAAc,CAAC,EAAE,aAAa,EAAE,CAAC;CAClC;AAED,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,GAAG,KAAK,CAAC;AAE7D,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE;QACJ,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;QACpB,KAAK,EAAE,aAAa,GAAG,IAAI,CAAC;QAC5B,WAAW,EAAE,aAAa,EAAE,CAAC;QAC7B,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;QACtB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;QACxB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;QACnB,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC;QAC1B,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;KACpB,CAAC;IACF,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,OAAO,CAAC;IACpB,MAAM,EAAE;QACN,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,GAAG,CAAC,EAAE,MAAM,CAAC;KACd,CAAC;CACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/Card/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,0BAA0B,EAC3B,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,KAAK,SAAS,EAAO,MAAM,QAAQ,CAAC;AAE7C,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,aAAa,CAAC,cAAc,CAAC,CAAC;IACpC,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;CAC5C;AAED,wBAAsB,aAAa,CACjC,MAAM,EAAE,WAAW,CAAC,cAAc,CAAC,EACnC,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,WAAW,CAAC,CAsDtB;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,WAAW,CAAC,cAAc,CAAC,WAqBpE;AAED,wBAAgB,eAAe,CAC7B,cAAc,EAAE,aAAa,EAAE,GAAG,SAAS,EAC3C,0BAA0B,EAAE,0BAA0B,GACrD,OAAO,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/Card/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,0BAA0B,EAC3B,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,KAAK,SAAS,EAAO,MAAM,QAAQ,CAAC;AAE7C,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,aAAa,CAAC,cAAc,CAAC,CAAC;IACpC,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;CAC5C;AAED,wBAAsB,aAAa,CACjC,MAAM,EAAE,WAAW,CAAC,cAAc,CAAC,EACnC,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,WAAW,CAAC,CAsDtB;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,WAAW,CAAC,cAAc,CAAC,WAqBpE;AAED,wBAAgB,eAAe,CAC7B,cAAc,EAAE,aAAa,EAAE,GAAG,SAAS,EAC3C,0BAA0B,EAAE,0BAA0B,GACrD,OAAO,CAcT;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM;;;SAW1C"}
|
package/build/index.cjs.js
CHANGED
|
@@ -6794,7 +6794,7 @@ const h = [
|
|
|
6794
6794
|
isLocal: false,
|
|
6795
6795
|
numberValidationRules: {
|
|
6796
6796
|
luhnCheck: true,
|
|
6797
|
-
ranges: [[300, 305], 36, 38, 39],
|
|
6797
|
+
ranges: [[300, 305], 3095, 36, 38, 39],
|
|
6798
6798
|
lengths: [14, 16, 19]
|
|
6799
6799
|
},
|
|
6800
6800
|
securityCodeValidationRules: {
|
|
@@ -6806,7 +6806,7 @@ const h = [
|
|
|
6806
6806
|
isLocal: false,
|
|
6807
6807
|
numberValidationRules: {
|
|
6808
6808
|
luhnCheck: true,
|
|
6809
|
-
ranges: [6011, [644, 649],
|
|
6809
|
+
ranges: [6011, [644, 649], [65e4, 651999], [653150, 659999], 622],
|
|
6810
6810
|
lengths: [16, 19]
|
|
6811
6811
|
},
|
|
6812
6812
|
securityCodeValidationRules: {
|
|
@@ -6818,7 +6818,16 @@ const h = [
|
|
|
6818
6818
|
isLocal: false,
|
|
6819
6819
|
numberValidationRules: {
|
|
6820
6820
|
luhnCheck: true,
|
|
6821
|
-
ranges: [
|
|
6821
|
+
ranges: [
|
|
6822
|
+
2131,
|
|
6823
|
+
1800,
|
|
6824
|
+
[3088, 3094],
|
|
6825
|
+
[3096, 3102],
|
|
6826
|
+
[3112, 3120],
|
|
6827
|
+
[3158, 3159],
|
|
6828
|
+
[3337, 3349],
|
|
6829
|
+
[3528, 3589]
|
|
6830
|
+
],
|
|
6822
6831
|
lengths: [16, 17, 18, 19]
|
|
6823
6832
|
},
|
|
6824
6833
|
securityCodeValidationRules: {
|
|
@@ -6866,16 +6875,20 @@ const h = [
|
|
|
6866
6875
|
numberValidationRules: {
|
|
6867
6876
|
luhnCheck: true,
|
|
6868
6877
|
ranges: [
|
|
6878
|
+
5018,
|
|
6879
|
+
5020,
|
|
6880
|
+
5038,
|
|
6881
|
+
5893,
|
|
6882
|
+
6101,
|
|
6883
|
+
6304,
|
|
6884
|
+
6759,
|
|
6885
|
+
6761,
|
|
6886
|
+
6762,
|
|
6887
|
+
6763,
|
|
6869
6888
|
493698,
|
|
6870
6889
|
[5e5, 504174],
|
|
6871
6890
|
[504176, 506698],
|
|
6872
6891
|
[506779, 508999],
|
|
6873
|
-
[56, 59],
|
|
6874
|
-
60,
|
|
6875
|
-
61,
|
|
6876
|
-
63,
|
|
6877
|
-
64,
|
|
6878
|
-
67,
|
|
6879
6892
|
69
|
|
6880
6893
|
],
|
|
6881
6894
|
lengths: [12, 13, 14, 15, 16, 17, 18, 19]
|
|
@@ -6981,6 +6994,18 @@ const h = [
|
|
|
6981
6994
|
securityCodeValidationRules: {
|
|
6982
6995
|
lengths: [0]
|
|
6983
6996
|
}
|
|
6997
|
+
},
|
|
6998
|
+
{
|
|
6999
|
+
name: "rupay",
|
|
7000
|
+
isLocal: false,
|
|
7001
|
+
numberValidationRules: {
|
|
7002
|
+
luhnCheck: true,
|
|
7003
|
+
ranges: [60, 81, 82, 508, [652100, 653149], [817200, 819899]],
|
|
7004
|
+
lengths: [16]
|
|
7005
|
+
},
|
|
7006
|
+
securityCodeValidationRules: {
|
|
7007
|
+
lengths: [3]
|
|
7008
|
+
}
|
|
6984
7009
|
}
|
|
6985
7010
|
];
|
|
6986
7011
|
function g(n, e, t) {
|
|
@@ -7047,7 +7072,7 @@ function C(n, e) {
|
|
|
7047
7072
|
isValid: l
|
|
7048
7073
|
};
|
|
7049
7074
|
}
|
|
7050
|
-
function
|
|
7075
|
+
function R(n) {
|
|
7051
7076
|
var r;
|
|
7052
7077
|
const e = /^(0[1-9]|1[[0-2]).*$/, t = n.match(e), s = t ? parseInt(t[1].toString(), 10) : null, l = /^(0[1-9]|1[[0-2])(\d{2})$/, i = n.match(l), a = i ? parseInt(i[2].toString(), 10) : null;
|
|
7053
7078
|
if (s) {
|
|
@@ -7113,7 +7138,7 @@ function areValuesComplete(values) {
|
|
|
7113
7138
|
if ("number" in values && !f(values.number ?? "").isValid) {
|
|
7114
7139
|
return false;
|
|
7115
7140
|
}
|
|
7116
|
-
if ("expiry" in values && !
|
|
7141
|
+
if ("expiry" in values && !R(values.expiry ?? "").isValid) {
|
|
7117
7142
|
return false;
|
|
7118
7143
|
}
|
|
7119
7144
|
if ("cvc" in values &&
|
|
@@ -7125,6 +7150,8 @@ function areValuesComplete(values) {
|
|
|
7125
7150
|
function isAcceptedBrand(acceptedBrands, cardNumberValidationResult) {
|
|
7126
7151
|
if (!acceptedBrands?.length)
|
|
7127
7152
|
return true;
|
|
7153
|
+
if (!cardNumberValidationResult.isValid)
|
|
7154
|
+
return false;
|
|
7128
7155
|
const { brand, localBrands } = cardNumberValidationResult;
|
|
7129
7156
|
const acceptedBrandsSet = new Set(acceptedBrands);
|
|
7130
7157
|
const isBrandAccepted = brand !== null && acceptedBrandsSet.has(brand);
|
|
@@ -7132,7 +7159,7 @@ function isAcceptedBrand(acceptedBrands, cardNumberValidationResult) {
|
|
|
7132
7159
|
return isBrandAccepted || isLocalBrandAccepted;
|
|
7133
7160
|
}
|
|
7134
7161
|
function formatExpiry(expiry) {
|
|
7135
|
-
const parsedExpiry =
|
|
7162
|
+
const parsedExpiry = R(expiry);
|
|
7136
7163
|
if (!parsedExpiry.isValid) {
|
|
7137
7164
|
return null;
|
|
7138
7165
|
}
|
|
@@ -7143,19 +7170,19 @@ function formatExpiry(expiry) {
|
|
|
7143
7170
|
}
|
|
7144
7171
|
|
|
7145
7172
|
function getCardFormSchema(acceptedBrands) {
|
|
7146
|
-
return z
|
|
7147
|
-
.object({
|
|
7173
|
+
return z.object({
|
|
7148
7174
|
name: z.string().min(1, "Missing name"),
|
|
7149
7175
|
number: z
|
|
7150
7176
|
.string()
|
|
7151
7177
|
.min(1, "Required")
|
|
7152
7178
|
.refine((value) => f(value).isValid, {
|
|
7153
7179
|
message: "Invalid card number",
|
|
7154
|
-
})
|
|
7180
|
+
})
|
|
7181
|
+
.refine((value) => isAcceptedBrand(acceptedBrands, f(value)), { message: "Brand not accepted" }),
|
|
7155
7182
|
expiry: z
|
|
7156
7183
|
.string()
|
|
7157
7184
|
.min(1, "Required")
|
|
7158
|
-
.refine((value) =>
|
|
7185
|
+
.refine((value) => R(value).isValid, {
|
|
7159
7186
|
message: "Invalid expiry",
|
|
7160
7187
|
}),
|
|
7161
7188
|
cvc: z
|
|
@@ -7164,19 +7191,6 @@ function getCardFormSchema(acceptedBrands) {
|
|
|
7164
7191
|
.refine((value) => C(value).isValid, {
|
|
7165
7192
|
message: "Invalid CVC",
|
|
7166
7193
|
}),
|
|
7167
|
-
})
|
|
7168
|
-
.superRefine((value, ctx) => {
|
|
7169
|
-
const validation = f(value.number);
|
|
7170
|
-
if (!validation.isValid)
|
|
7171
|
-
return;
|
|
7172
|
-
const isAccepted = isAcceptedBrand(acceptedBrands, validation);
|
|
7173
|
-
if (!isAccepted) {
|
|
7174
|
-
ctx.addIssue({
|
|
7175
|
-
code: z.ZodIssueCode.custom,
|
|
7176
|
-
message: "Brand not accepted",
|
|
7177
|
-
path: ["number"],
|
|
7178
|
-
});
|
|
7179
|
-
}
|
|
7180
7194
|
});
|
|
7181
7195
|
}
|
|
7182
7196
|
|