@mezo-org/passport 0.4.0-dev.67 → 0.4.0-dev.69
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/dist/src/hooks/constants.d.ts +0 -1
- package/dist/src/hooks/constants.d.ts.map +1 -1
- package/dist/src/hooks/constants.js +0 -1
- package/dist/src/hooks/constants.js.map +1 -1
- package/dist/src/hooks/index.d.ts +1 -1
- package/dist/src/hooks/index.d.ts.map +1 -1
- package/dist/src/hooks/index.js +1 -1
- package/dist/src/hooks/index.js.map +1 -1
- package/dist/src/hooks/useGetAccountByMezoId.d.ts +1 -6
- package/dist/src/hooks/useGetAccountByMezoId.d.ts.map +1 -1
- package/dist/src/hooks/useGetAccountByMezoId.js +9 -12
- package/dist/src/hooks/useGetAccountByMezoId.js.map +1 -1
- package/dist/src/hooks/useValidateMezoId.d.ts +8 -0
- package/dist/src/hooks/useValidateMezoId.d.ts.map +1 -0
- package/dist/src/hooks/useValidateMezoId.js +24 -0
- package/dist/src/hooks/useValidateMezoId.js.map +1 -0
- package/dist/src/utils/mezoId.d.ts +3 -0
- package/dist/src/utils/mezoId.d.ts.map +1 -0
- package/dist/src/utils/{validation.js → mezoId.js} +8 -4
- package/dist/src/utils/mezoId.js.map +1 -0
- package/package.json +1 -1
- package/src/hooks/constants.ts +0 -1
- package/src/hooks/index.ts +1 -1
- package/src/hooks/useGetAccountByMezoId.ts +10 -27
- package/src/hooks/useValidateMezoId.ts +31 -0
- package/src/utils/{validation.ts → mezoId.ts} +12 -4
- package/dist/src/hooks/useUsernameValidation.d.ts +0 -7
- package/dist/src/hooks/useUsernameValidation.d.ts.map +0 -1
- package/dist/src/hooks/useUsernameValidation.js +0 -48
- package/dist/src/hooks/useUsernameValidation.js.map +0 -1
- package/dist/src/utils/validation.d.ts +0 -2
- package/dist/src/utils/validation.d.ts.map +0 -1
- package/dist/src/utils/validation.js.map +0 -1
- package/src/hooks/useUsernameValidation.ts +0 -58
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/hooks/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/hooks/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU;;;;;CAKtB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/hooks/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,OAAO,EAAE,SAAS;IAClB,OAAO,EAAE,SAAS;IAClB,OAAO,EAAE,SAAS;IAClB,qBAAqB,EAAE,qBAAqB;
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/hooks/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,OAAO,EAAE,SAAS;IAClB,OAAO,EAAE,SAAS;IAClB,OAAO,EAAE,SAAS;IAClB,qBAAqB,EAAE,qBAAqB;CAC7C,CAAA"}
|
|
@@ -12,5 +12,5 @@ export * from "./useSignOut";
|
|
|
12
12
|
export * from "./useSignUpWithWallet";
|
|
13
13
|
export { useInvalidateTokensBalances, useResetTokensBalances, } from "./useTokensBalances";
|
|
14
14
|
export * from "./useUpdateMezoId";
|
|
15
|
-
export * from "./
|
|
15
|
+
export * from "./useValidateMezoId";
|
|
16
16
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,kBAAkB,EAClB,kDAAkD,EAClD,4BAA4B,EAC5B,oDAAoD,GACrD,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAC7E,cAAc,0BAA0B,CAAA;AACxC,cAAc,yBAAyB,CAAA;AACvC,cAAc,wBAAwB,CAAA;AACtC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA;AAChC,cAAc,sBAAsB,CAAA;AACpC,cAAc,wBAAwB,CAAA;AACtC,cAAc,uBAAuB,CAAA;AACrC,cAAc,cAAc,CAAA;AAC5B,cAAc,uBAAuB,CAAA;AACrC,OAAO,EACL,2BAA2B,EAC3B,sBAAsB,GACvB,MAAM,qBAAqB,CAAA;AAC5B,cAAc,mBAAmB,CAAA;AACjC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,kBAAkB,EAClB,kDAAkD,EAClD,4BAA4B,EAC5B,oDAAoD,GACrD,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAC7E,cAAc,0BAA0B,CAAA;AACxC,cAAc,yBAAyB,CAAA;AACvC,cAAc,wBAAwB,CAAA;AACtC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA;AAChC,cAAc,sBAAsB,CAAA;AACpC,cAAc,wBAAwB,CAAA;AACtC,cAAc,uBAAuB,CAAA;AACrC,cAAc,cAAc,CAAA;AAC5B,cAAc,uBAAuB,CAAA;AACrC,OAAO,EACL,2BAA2B,EAC3B,sBAAsB,GACvB,MAAM,qBAAqB,CAAA;AAC5B,cAAc,mBAAmB,CAAA;AACjC,cAAc,qBAAqB,CAAA"}
|
package/dist/src/hooks/index.js
CHANGED
|
@@ -12,5 +12,5 @@ export * from "./useSignOut";
|
|
|
12
12
|
export * from "./useSignUpWithWallet";
|
|
13
13
|
export { useInvalidateTokensBalances, useResetTokensBalances, } from "./useTokensBalances";
|
|
14
14
|
export * from "./useUpdateMezoId";
|
|
15
|
-
export * from "./
|
|
15
|
+
export * from "./useValidateMezoId";
|
|
16
16
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,kBAAkB,EAClB,kDAAkD,EAClD,4BAA4B,EAC5B,oDAAoD,GACrD,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAC7E,cAAc,0BAA0B,CAAA;AACxC,cAAc,yBAAyB,CAAA;AACvC,cAAc,wBAAwB,CAAA;AACtC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA;AAChC,cAAc,sBAAsB,CAAA;AACpC,cAAc,wBAAwB,CAAA;AACtC,cAAc,uBAAuB,CAAA;AACrC,cAAc,cAAc,CAAA;AAC5B,cAAc,uBAAuB,CAAA;AACrC,OAAO,EACL,2BAA2B,EAC3B,sBAAsB,GACvB,MAAM,qBAAqB,CAAA;AAC5B,cAAc,mBAAmB,CAAA;AACjC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,kBAAkB,EAClB,kDAAkD,EAClD,4BAA4B,EAC5B,oDAAoD,GACrD,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAC7E,cAAc,0BAA0B,CAAA;AACxC,cAAc,yBAAyB,CAAA;AACvC,cAAc,wBAAwB,CAAA;AACtC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA;AAChC,cAAc,sBAAsB,CAAA;AACpC,cAAc,wBAAwB,CAAA;AACtC,cAAc,uBAAuB,CAAA;AACrC,cAAc,cAAc,CAAA;AAC5B,cAAc,uBAAuB,CAAA;AACrC,OAAO,EACL,2BAA2B,EAC3B,sBAAsB,GACvB,MAAM,qBAAqB,CAAA;AAC5B,cAAc,mBAAmB,CAAA;AACjC,cAAc,qBAAqB,CAAA"}
|
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
import { UseBaseQueryOptions } from "@tanstack/react-query";
|
|
2
|
-
import type {
|
|
3
|
-
export declare const getAccountByMezoIdQueryOptions: ({ authApiClient, mezoId, queryOptions, }: {
|
|
4
|
-
authApiClient: AuthApiClient;
|
|
5
|
-
mezoId?: string;
|
|
6
|
-
queryOptions?: Omit<UseBaseQueryOptions<GetAccountByMezoIdOrAddressResponse | null>, "queryKey" | "queryFn">;
|
|
7
|
-
}) => UseBaseQueryOptions<GetAccountByMezoIdOrAddressResponse | null>;
|
|
2
|
+
import type { GetAccountByMezoIdOrAddressResponse } from "../api";
|
|
8
3
|
export declare function useGetAccountByMezoId(mezoId?: string, queryOptions?: Omit<UseBaseQueryOptions<GetAccountByMezoIdOrAddressResponse | null>, "queryKey" | "queryFn">): import("@tanstack/react-query").UseQueryResult<GetAccountByMezoIdOrAddressResponse | null, Error>;
|
|
9
4
|
//# sourceMappingURL=useGetAccountByMezoId.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetAccountByMezoId.d.ts","sourceRoot":"","sources":["../../../src/hooks/useGetAccountByMezoId.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAIhF,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"useGetAccountByMezoId.d.ts","sourceRoot":"","sources":["../../../src/hooks/useGetAccountByMezoId.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAIhF,OAAO,KAAK,EAAE,mCAAmC,EAAE,MAAM,QAAQ,CAAA;AAEjE,wBAAgB,qBAAqB,CACnC,MAAM,CAAC,EAAE,MAAM,EACf,YAAY,GAAE,IAAI,CAChB,mBAAmB,CAAC,mCAAmC,GAAG,IAAI,CAAC,EAC/D,UAAU,GAAG,SAAS,CAClB,qGAaP"}
|
|
@@ -2,19 +2,16 @@ import { useQuery, skipToken } from "@tanstack/react-query";
|
|
|
2
2
|
import { useAuthApiClient } from "./useAuthApiClient";
|
|
3
3
|
import { QUERY_KEYS } from "./constants";
|
|
4
4
|
import { ONE_MINUTE_MS } from "../utils/time";
|
|
5
|
-
export const getAccountByMezoIdQueryOptions = ({ authApiClient, mezoId, queryOptions = {}, }) => ({
|
|
6
|
-
queryKey: [QUERY_KEYS.ACCOUNT, mezoId],
|
|
7
|
-
queryFn: mezoId
|
|
8
|
-
? () => authApiClient.getAccountByMezoIdOrAddress(mezoId)
|
|
9
|
-
: skipToken,
|
|
10
|
-
...queryOptions,
|
|
11
|
-
});
|
|
12
5
|
export function useGetAccountByMezoId(mezoId, queryOptions = {}) {
|
|
13
6
|
const authApiClient = useAuthApiClient();
|
|
14
|
-
return useQuery(
|
|
15
|
-
|
|
16
|
-
mezoId
|
|
17
|
-
|
|
18
|
-
|
|
7
|
+
return useQuery({
|
|
8
|
+
queryKey: [QUERY_KEYS.ACCOUNT, mezoId],
|
|
9
|
+
queryFn: mezoId
|
|
10
|
+
? () => authApiClient.getAccountByMezoIdOrAddress(mezoId)
|
|
11
|
+
: skipToken,
|
|
12
|
+
staleTime: ONE_MINUTE_MS,
|
|
13
|
+
retry: 1,
|
|
14
|
+
...queryOptions,
|
|
15
|
+
});
|
|
19
16
|
}
|
|
20
17
|
//# sourceMappingURL=useGetAccountByMezoId.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGetAccountByMezoId.js","sourceRoot":"","sources":["../../../src/hooks/useGetAccountByMezoId.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAuB,MAAM,uBAAuB,CAAA;AAChF,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAG7C,MAAM,
|
|
1
|
+
{"version":3,"file":"useGetAccountByMezoId.js","sourceRoot":"","sources":["../../../src/hooks/useGetAccountByMezoId.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAuB,MAAM,uBAAuB,CAAA;AAChF,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAG7C,MAAM,UAAU,qBAAqB,CACnC,MAAe,EACf,eAGI,EAAE;IAEN,MAAM,aAAa,GAAG,gBAAgB,EAAE,CAAA;IAExC,OAAO,QAAQ,CAAC;QACd,QAAQ,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC;QACtC,OAAO,EAAE,MAAM;YACb,CAAC,CAAC,GAAG,EAAE,CAAC,aAAa,CAAC,2BAA2B,CAAC,MAAM,CAAC;YACzD,CAAC,CAAC,SAAS;QACb,SAAS,EAAE,aAAa;QACxB,KAAK,EAAE,CAAC;QACR,GAAG,YAAY;KAChB,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { UseQueryResult } from "@tanstack/react-query";
|
|
2
|
+
import { MezoId } from "../utils/mezoId";
|
|
3
|
+
export declare function useValidateMezoId(mezoId: MezoId): UseQueryResult<{
|
|
4
|
+
isValid: boolean;
|
|
5
|
+
isAvailable: boolean;
|
|
6
|
+
errors: string[];
|
|
7
|
+
}>;
|
|
8
|
+
//# sourceMappingURL=useValidateMezoId.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useValidateMezoId.d.ts","sourceRoot":"","sources":["../../../src/hooks/useValidateMezoId.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EAAkB,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAGxD,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAqBxC,cAAc,CAAC;IACnB,OAAO,EAAE,OAAO,CAAA;IAChB,WAAW,EAAE,OAAO,CAAA;IACpB,MAAM,EAAE,MAAM,EAAE,CAAA;CACjB,CAAC,CACH"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { validateMezoId } from "../utils/mezoId";
|
|
2
|
+
import { useGetAccountByMezoId } from "./useGetAccountByMezoId";
|
|
3
|
+
export function useValidateMezoId(mezoId) {
|
|
4
|
+
const validationErrors = validateMezoId(mezoId);
|
|
5
|
+
return useGetAccountByMezoId(mezoId, {
|
|
6
|
+
placeholderData: {
|
|
7
|
+
// @ts-expect-error TODO: Couldn't fix type for placeholderData which for
|
|
8
|
+
// some reason should return the same data as the data returned in
|
|
9
|
+
// queryFn.
|
|
10
|
+
isValid: validationErrors.length === 0,
|
|
11
|
+
isAvailable: validationErrors.length === 0,
|
|
12
|
+
errors: validationErrors,
|
|
13
|
+
},
|
|
14
|
+
enabled: validationErrors.length === 0,
|
|
15
|
+
// @ts-expect-error TODO: Couldn't fix type for select which for some reason
|
|
16
|
+
// should return the same data as the data returned in queryFn.
|
|
17
|
+
select: (data) => {
|
|
18
|
+
const isValid = validationErrors.length === 0;
|
|
19
|
+
const isAvailable = isValid ? !data : false;
|
|
20
|
+
return { isValid, isAvailable, errors: validationErrors };
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=useValidateMezoId.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useValidateMezoId.js","sourceRoot":"","sources":["../../../src/hooks/useValidateMezoId.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAU,MAAM,iBAAiB,CAAA;AACxD,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;AAE/D,MAAM,UAAU,iBAAiB,CAAC,MAAc;IAC9C,MAAM,gBAAgB,GAAG,cAAc,CAAC,MAAM,CAAC,CAAA;IAE/C,OAAO,qBAAqB,CAAC,MAAM,EAAE;QACnC,eAAe,EAAE;YACf,yEAAyE;YACzE,kEAAkE;YAClE,WAAW;YACX,OAAO,EAAE,gBAAgB,CAAC,MAAM,KAAK,CAAC;YACtC,WAAW,EAAE,gBAAgB,CAAC,MAAM,KAAK,CAAC;YAC1C,MAAM,EAAE,gBAAgB;SACzB;QACD,OAAO,EAAE,gBAAgB,CAAC,MAAM,KAAK,CAAC;QACtC,4EAA4E;QAC5E,+DAA+D;QAC/D,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;YACf,MAAM,OAAO,GAAG,gBAAgB,CAAC,MAAM,KAAK,CAAC,CAAA;YAC7C,MAAM,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAA;YAE3C,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,gBAAgB,EAAE,CAAA;QAC3D,CAAC;KACF,CAIC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mezoId.d.ts","sourceRoot":"","sources":["../../../src/utils/mezoId.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,MAAM,GAAG,GAAG,MAAM,OAAO,CAAA;AAqCrC,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAYvD"}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
//
|
|
7
7
|
// A few addenda are made to ensure that nothing can sneak through that could
|
|
8
8
|
// look like an Ethereum or Bitcoin address.
|
|
9
|
-
const
|
|
9
|
+
const DISALLOWED_MEZO_ID_PATTERNS = [
|
|
10
10
|
// RFC1034.
|
|
11
11
|
{ pattern: /^$/, error: "Must not be empty." },
|
|
12
12
|
{ pattern: /^.{16,}$/, error: "Must have 15 characters or fewer." },
|
|
@@ -30,8 +30,12 @@ const DISALLOWED_USERNAME_PATTERNS = [
|
|
|
30
30
|
error: 'No "m" + "numeric string" prefixes.',
|
|
31
31
|
},
|
|
32
32
|
];
|
|
33
|
-
export function
|
|
34
|
-
|
|
33
|
+
export function validateMezoId(mezoId) {
|
|
34
|
+
if (!/\.mezo$/.test(mezoId)) {
|
|
35
|
+
return ["Must end with '.mezo'."];
|
|
36
|
+
}
|
|
37
|
+
const mezoIdWithoutSuffix = mezoId.replace(/\.mezo$/, "");
|
|
38
|
+
const errors = DISALLOWED_MEZO_ID_PATTERNS.flatMap(({ pattern, error }) => pattern.test(mezoIdWithoutSuffix) ? [error] : []);
|
|
35
39
|
return errors;
|
|
36
40
|
}
|
|
37
|
-
//# sourceMappingURL=
|
|
41
|
+
//# sourceMappingURL=mezoId.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mezoId.js","sourceRoot":"","sources":["../../../src/utils/mezoId.ts"],"names":[],"mappings":"AAEA,6EAA6E;AAC7E,8CAA8C;AAE9C,2EAA2E;AAC3E,8DAA8D;AAC9D,4CAA4C;AAC5C,EAAE;AACF,6EAA6E;AAC7E,4CAA4C;AAC5C,MAAM,2BAA2B,GAAyC;IACxE,WAAW;IACX,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,oBAAoB,EAAE;IAC9C,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,mCAAmC,EAAE;IACnE;QACE,OAAO,EAAE,YAAY;QACrB,KAAK,EAAE,kDAAkD;KAC1D;IACD;QACE,OAAO,EAAE,eAAe;QACxB,KAAK,EACH,qEAAqE;KACxE;IACD,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,+BAA+B,EAAE;IACzD,iCAAiC;IACjC,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,sBAAsB,EAAE;IACjD;QACE,OAAO,EAAE,kCAAkC;QAC3C,KAAK,EAAE,6CAA6C;KACrD;IACD;QACE,OAAO,EAAE,YAAY;QACrB,KAAK,EAAE,qCAAqC;KAC7C;CACF,CAAA;AAED,MAAM,UAAU,cAAc,CAAC,MAAc;IAC3C,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QAC5B,OAAO,CAAC,wBAAwB,CAAC,CAAA;IACnC,CAAC;IAED,MAAM,mBAAmB,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAA;IAEzD,MAAM,MAAM,GAAG,2BAA2B,CAAC,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,CACxE,OAAO,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CACjD,CAAA;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
package/package.json
CHANGED
package/src/hooks/constants.ts
CHANGED
package/src/hooks/index.ts
CHANGED
|
@@ -2,26 +2,7 @@ import { useQuery, skipToken, UseBaseQueryOptions } from "@tanstack/react-query"
|
|
|
2
2
|
import { useAuthApiClient } from "./useAuthApiClient"
|
|
3
3
|
import { QUERY_KEYS } from "./constants"
|
|
4
4
|
import { ONE_MINUTE_MS } from "../utils/time"
|
|
5
|
-
import type {
|
|
6
|
-
|
|
7
|
-
export const getAccountByMezoIdQueryOptions = ({
|
|
8
|
-
authApiClient,
|
|
9
|
-
mezoId,
|
|
10
|
-
queryOptions = {},
|
|
11
|
-
}: {
|
|
12
|
-
authApiClient: AuthApiClient
|
|
13
|
-
mezoId?: string
|
|
14
|
-
queryOptions?: Omit<
|
|
15
|
-
UseBaseQueryOptions<GetAccountByMezoIdOrAddressResponse | null>,
|
|
16
|
-
"queryKey" | "queryFn"
|
|
17
|
-
>
|
|
18
|
-
}): UseBaseQueryOptions<GetAccountByMezoIdOrAddressResponse | null> => ({
|
|
19
|
-
queryKey: [QUERY_KEYS.ACCOUNT, mezoId],
|
|
20
|
-
queryFn: mezoId
|
|
21
|
-
? () => authApiClient.getAccountByMezoIdOrAddress(mezoId)
|
|
22
|
-
: skipToken,
|
|
23
|
-
...queryOptions,
|
|
24
|
-
})
|
|
5
|
+
import type { GetAccountByMezoIdOrAddressResponse } from "../api"
|
|
25
6
|
|
|
26
7
|
export function useGetAccountByMezoId(
|
|
27
8
|
mezoId?: string,
|
|
@@ -32,11 +13,13 @@ export function useGetAccountByMezoId(
|
|
|
32
13
|
) {
|
|
33
14
|
const authApiClient = useAuthApiClient()
|
|
34
15
|
|
|
35
|
-
return useQuery(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
mezoId
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
16
|
+
return useQuery({
|
|
17
|
+
queryKey: [QUERY_KEYS.ACCOUNT, mezoId],
|
|
18
|
+
queryFn: mezoId
|
|
19
|
+
? () => authApiClient.getAccountByMezoIdOrAddress(mezoId)
|
|
20
|
+
: skipToken,
|
|
21
|
+
staleTime: ONE_MINUTE_MS,
|
|
22
|
+
retry: 1,
|
|
23
|
+
...queryOptions,
|
|
24
|
+
})
|
|
42
25
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { UseQueryResult } from "@tanstack/react-query"
|
|
2
|
+
import { validateMezoId, MezoId } from "../utils/mezoId"
|
|
3
|
+
import { useGetAccountByMezoId } from "./useGetAccountByMezoId"
|
|
4
|
+
|
|
5
|
+
export function useValidateMezoId(mezoId: MezoId) {
|
|
6
|
+
const validationErrors = validateMezoId(mezoId)
|
|
7
|
+
|
|
8
|
+
return useGetAccountByMezoId(mezoId, {
|
|
9
|
+
placeholderData: {
|
|
10
|
+
// @ts-expect-error TODO: Couldn't fix type for placeholderData which for
|
|
11
|
+
// some reason should return the same data as the data returned in
|
|
12
|
+
// queryFn.
|
|
13
|
+
isValid: validationErrors.length === 0,
|
|
14
|
+
isAvailable: validationErrors.length === 0,
|
|
15
|
+
errors: validationErrors,
|
|
16
|
+
},
|
|
17
|
+
enabled: validationErrors.length === 0,
|
|
18
|
+
// @ts-expect-error TODO: Couldn't fix type for select which for some reason
|
|
19
|
+
// should return the same data as the data returned in queryFn.
|
|
20
|
+
select: (data) => {
|
|
21
|
+
const isValid = validationErrors.length === 0
|
|
22
|
+
const isAvailable = isValid ? !data : false
|
|
23
|
+
|
|
24
|
+
return { isValid, isAvailable, errors: validationErrors }
|
|
25
|
+
},
|
|
26
|
+
}) as UseQueryResult<{
|
|
27
|
+
isValid: boolean
|
|
28
|
+
isAvailable: boolean
|
|
29
|
+
errors: string[]
|
|
30
|
+
}>
|
|
31
|
+
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export type MezoId = `${string}.mezo`
|
|
2
|
+
|
|
1
3
|
// NOTE: This was copied from mezo-portal and is based on the validation from
|
|
2
4
|
// workers/passport-auth/src/utils/mezo-id.ts.
|
|
3
5
|
|
|
@@ -7,7 +9,7 @@
|
|
|
7
9
|
//
|
|
8
10
|
// A few addenda are made to ensure that nothing can sneak through that could
|
|
9
11
|
// look like an Ethereum or Bitcoin address.
|
|
10
|
-
const
|
|
12
|
+
const DISALLOWED_MEZO_ID_PATTERNS: { pattern: RegExp; error: string }[] = [
|
|
11
13
|
// RFC1034.
|
|
12
14
|
{ pattern: /^$/, error: "Must not be empty." },
|
|
13
15
|
{ pattern: /^.{16,}$/, error: "Must have 15 characters or fewer." },
|
|
@@ -33,9 +35,15 @@ const DISALLOWED_USERNAME_PATTERNS: { pattern: RegExp; error: string }[] = [
|
|
|
33
35
|
},
|
|
34
36
|
]
|
|
35
37
|
|
|
36
|
-
export function
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
export function validateMezoId(mezoId: string): string[] {
|
|
39
|
+
if (!/\.mezo$/.test(mezoId)) {
|
|
40
|
+
return ["Must end with '.mezo'."]
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const mezoIdWithoutSuffix = mezoId.replace(/\.mezo$/, "")
|
|
44
|
+
|
|
45
|
+
const errors = DISALLOWED_MEZO_ID_PATTERNS.flatMap(({ pattern, error }) =>
|
|
46
|
+
pattern.test(mezoIdWithoutSuffix) ? [error] : [],
|
|
39
47
|
)
|
|
40
48
|
|
|
41
49
|
return errors
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useUsernameValidation.d.ts","sourceRoot":"","sources":["../../../src/hooks/useUsernameValidation.ts"],"names":[],"mappings":"AAOA,wBAAgB,qBAAqB;iCAKhB,MAAM;;;;EA6C1B"}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { useCallback } from "react";
|
|
2
|
-
import { useQueryClient } from "@tanstack/react-query";
|
|
3
|
-
import { validateUsername } from "../utils/validation";
|
|
4
|
-
import { useAuthApiClient } from "./useAuthApiClient";
|
|
5
|
-
import { ONE_MINUTE_MS } from "../utils/time";
|
|
6
|
-
import { getAccountByMezoIdQueryOptions } from "./useGetAccountByMezoId";
|
|
7
|
-
export function useUsernameValidation() {
|
|
8
|
-
const queryClient = useQueryClient();
|
|
9
|
-
const authApiClient = useAuthApiClient();
|
|
10
|
-
const validateUsernameCallback = useCallback(async (username) => {
|
|
11
|
-
// Validate if username is correct
|
|
12
|
-
const errors = validateUsername(username);
|
|
13
|
-
if (errors.length > 0) {
|
|
14
|
-
return {
|
|
15
|
-
isValid: false,
|
|
16
|
-
errors,
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
const mezoId = `${username}.mezo`;
|
|
20
|
-
let foundUser;
|
|
21
|
-
// Find if user with given mezoId already exists in DB
|
|
22
|
-
try {
|
|
23
|
-
// Thanks to fetchQuery we know the data is up-to-date and also we use
|
|
24
|
-
// the cached value if the `getAccountByMezoId` hook was already called
|
|
25
|
-
// with the given mezoId.
|
|
26
|
-
foundUser = await queryClient.fetchQuery(getAccountByMezoIdQueryOptions({
|
|
27
|
-
authApiClient,
|
|
28
|
-
mezoId,
|
|
29
|
-
queryOptions: { staleTime: ONE_MINUTE_MS, retry: 1 },
|
|
30
|
-
}));
|
|
31
|
-
// By default fetchQuery throws an error if it's not resolved with the
|
|
32
|
-
// data, but we don't want to do that thus the empty catch.
|
|
33
|
-
// eslint-disable-next-line no-empty
|
|
34
|
-
}
|
|
35
|
-
catch (error) { }
|
|
36
|
-
if (foundUser)
|
|
37
|
-
return {
|
|
38
|
-
isValid: false,
|
|
39
|
-
errors: ["Mezo id already exists."],
|
|
40
|
-
};
|
|
41
|
-
return {
|
|
42
|
-
isValid: true,
|
|
43
|
-
errors: [],
|
|
44
|
-
};
|
|
45
|
-
}, [authApiClient, queryClient]);
|
|
46
|
-
return { validateUsername: validateUsernameCallback };
|
|
47
|
-
}
|
|
48
|
-
//# sourceMappingURL=useUsernameValidation.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useUsernameValidation.js","sourceRoot":"","sources":["../../../src/hooks/useUsernameValidation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAA;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAE,8BAA8B,EAAE,MAAM,yBAAyB,CAAA;AAExE,MAAM,UAAU,qBAAqB;IACnC,MAAM,WAAW,GAAG,cAAc,EAAE,CAAA;IACpC,MAAM,aAAa,GAAG,gBAAgB,EAAE,CAAA;IAExC,MAAM,wBAAwB,GAAG,WAAW,CAC1C,KAAK,EAAE,QAAgB,EAAE,EAAE;QACzB,kCAAkC;QAClC,MAAM,MAAM,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAAA;QACzC,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACtB,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,MAAM;aACP,CAAA;QACH,CAAC;QAED,MAAM,MAAM,GAAG,GAAG,QAAQ,OAAO,CAAA;QAEjC,IAAI,SAAS,CAAA;QACb,sDAAsD;QACtD,IAAI,CAAC;YACH,sEAAsE;YACtE,uEAAuE;YACvE,yBAAyB;YACzB,SAAS,GAAG,MAAM,WAAW,CAAC,UAAU,CACtC,8BAA8B,CAAC;gBAC7B,aAAa;gBACb,MAAM;gBACN,YAAY,EAAE,EAAE,SAAS,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC,EAAE;aACrD,CAAC,CACH,CAAA;YACD,sEAAsE;YACtE,2DAA2D;YAC3D,oCAAoC;QACtC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC,CAAA,CAAC;QAElB,IAAI,SAAS;YACX,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,MAAM,EAAE,CAAC,yBAAyB,CAAC;aACpC,CAAA;QAEH,OAAO;YACL,OAAO,EAAE,IAAI;YACb,MAAM,EAAE,EAAE;SACX,CAAA;IACH,CAAC,EACD,CAAC,aAAa,EAAE,WAAW,CAAC,CAC7B,CAAA;IAED,OAAO,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,CAAA;AACvD,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../../src/utils/validation.ts"],"names":[],"mappings":"AAmCA,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAM3D"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../../src/utils/validation.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,8CAA8C;AAE9C,2EAA2E;AAC3E,8DAA8D;AAC9D,4CAA4C;AAC5C,EAAE;AACF,6EAA6E;AAC7E,4CAA4C;AAC5C,MAAM,4BAA4B,GAAyC;IACzE,WAAW;IACX,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,oBAAoB,EAAE;IAC9C,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,mCAAmC,EAAE;IACnE;QACE,OAAO,EAAE,YAAY;QACrB,KAAK,EAAE,kDAAkD;KAC1D;IACD;QACE,OAAO,EAAE,eAAe;QACxB,KAAK,EACH,qEAAqE;KACxE;IACD,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,+BAA+B,EAAE;IACzD,iCAAiC;IACjC,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,sBAAsB,EAAE;IACjD;QACE,OAAO,EAAE,kCAAkC;QAC3C,KAAK,EAAE,6CAA6C;KACrD;IACD;QACE,OAAO,EAAE,YAAY;QACrB,KAAK,EAAE,qCAAqC;KAC7C;CACF,CAAA;AAED,MAAM,UAAU,gBAAgB,CAAC,QAAgB;IAC/C,MAAM,MAAM,GAAG,4BAA4B,CAAC,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,CACzE,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CACtC,CAAA;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { useCallback } from "react"
|
|
2
|
-
import { useQueryClient } from "@tanstack/react-query"
|
|
3
|
-
import { validateUsername } from "../utils/validation"
|
|
4
|
-
import { useAuthApiClient } from "./useAuthApiClient"
|
|
5
|
-
import { ONE_MINUTE_MS } from "../utils/time"
|
|
6
|
-
import { getAccountByMezoIdQueryOptions } from "./useGetAccountByMezoId"
|
|
7
|
-
|
|
8
|
-
export function useUsernameValidation() {
|
|
9
|
-
const queryClient = useQueryClient()
|
|
10
|
-
const authApiClient = useAuthApiClient()
|
|
11
|
-
|
|
12
|
-
const validateUsernameCallback = useCallback(
|
|
13
|
-
async (username: string) => {
|
|
14
|
-
// Validate if username is correct
|
|
15
|
-
const errors = validateUsername(username)
|
|
16
|
-
if (errors.length > 0) {
|
|
17
|
-
return {
|
|
18
|
-
isValid: false,
|
|
19
|
-
errors,
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const mezoId = `${username}.mezo`
|
|
24
|
-
|
|
25
|
-
let foundUser
|
|
26
|
-
// Find if user with given mezoId already exists in DB
|
|
27
|
-
try {
|
|
28
|
-
// Thanks to fetchQuery we know the data is up-to-date and also we use
|
|
29
|
-
// the cached value if the `getAccountByMezoId` hook was already called
|
|
30
|
-
// with the given mezoId.
|
|
31
|
-
foundUser = await queryClient.fetchQuery(
|
|
32
|
-
getAccountByMezoIdQueryOptions({
|
|
33
|
-
authApiClient,
|
|
34
|
-
mezoId,
|
|
35
|
-
queryOptions: { staleTime: ONE_MINUTE_MS, retry: 1 },
|
|
36
|
-
}),
|
|
37
|
-
)
|
|
38
|
-
// By default fetchQuery throws an error if it's not resolved with the
|
|
39
|
-
// data, but we don't want to do that thus the empty catch.
|
|
40
|
-
// eslint-disable-next-line no-empty
|
|
41
|
-
} catch (error) {}
|
|
42
|
-
|
|
43
|
-
if (foundUser)
|
|
44
|
-
return {
|
|
45
|
-
isValid: false,
|
|
46
|
-
errors: ["Mezo id already exists."],
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return {
|
|
50
|
-
isValid: true,
|
|
51
|
-
errors: [],
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
[authApiClient, queryClient],
|
|
55
|
-
)
|
|
56
|
-
|
|
57
|
-
return { validateUsername: validateUsernameCallback }
|
|
58
|
-
}
|