@mezo-org/passport 0.4.0-dev.66 → 0.4.0-dev.68
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 +2 -4
- package/dist/src/hooks/useGetAccountByMezoId.d.ts.map +1 -1
- package/dist/src/hooks/useGetAccountByMezoId.js +4 -7
- package/dist/src/hooks/useGetAccountByMezoId.js.map +1 -1
- package/dist/src/hooks/useMezoIdValidation.d.ts +8 -0
- package/dist/src/hooks/useMezoIdValidation.d.ts.map +1 -0
- package/dist/src/hooks/useMezoIdValidation.js +24 -0
- package/dist/src/hooks/useMezoIdValidation.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 +5 -14
- package/src/hooks/useMezoIdValidation.ts +31 -0
- package/src/utils/{validation.ts → mezoId.ts} +12 -4
- package/dist/src/hooks/useIsUsernameValid.d.ts +0 -7
- package/dist/src/hooks/useIsUsernameValid.d.ts.map +0 -1
- package/dist/src/hooks/useIsUsernameValid.js +0 -41
- package/dist/src/hooks/useIsUsernameValid.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/useIsUsernameValid.ts +0 -52
|
@@ -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"}
|
|
@@ -4,8 +4,8 @@ export * from "./useGetAccountByAddress";
|
|
|
4
4
|
export * from "./useGetAccountByMezoId";
|
|
5
5
|
export * from "./useGetCurrentAccount";
|
|
6
6
|
export * from "./useGetSession";
|
|
7
|
-
export * from "./useIsUsernameValid";
|
|
8
7
|
export * from "./useLinkAccount";
|
|
8
|
+
export * from "./useMezoIdValidation";
|
|
9
9
|
export * from "./useRefreshPassport";
|
|
10
10
|
export * from "./useSignInWithDiscord";
|
|
11
11
|
export * from "./useSignInWithWallet";
|
|
@@ -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,
|
|
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,uBAAuB,CAAA;AACrC,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"}
|
package/dist/src/hooks/index.js
CHANGED
|
@@ -4,8 +4,8 @@ export * from "./useGetAccountByAddress";
|
|
|
4
4
|
export * from "./useGetAccountByMezoId";
|
|
5
5
|
export * from "./useGetCurrentAccount";
|
|
6
6
|
export * from "./useGetSession";
|
|
7
|
-
export * from "./useIsUsernameValid";
|
|
8
7
|
export * from "./useLinkAccount";
|
|
8
|
+
export * from "./useMezoIdValidation";
|
|
9
9
|
export * from "./useRefreshPassport";
|
|
10
10
|
export * from "./useSignInWithDiscord";
|
|
11
11
|
export * from "./useSignInWithWallet";
|
|
@@ -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,
|
|
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,uBAAuB,CAAA;AACrC,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"}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
3
|
-
export declare const getAccountByMezoIdQueryKeys: (mezoId?: string) => (string | undefined)[];
|
|
4
|
-
export declare const getAccountByMezoIdQueryFunction: (authApiClient: AuthApiClient, mezoId?: string) => typeof skipToken | (() => Promise<GetAccountByMezoIdOrAddressResponse | null>);
|
|
1
|
+
import { UseBaseQueryOptions } from "@tanstack/react-query";
|
|
2
|
+
import type { GetAccountByMezoIdOrAddressResponse } from "../api";
|
|
5
3
|
export declare function useGetAccountByMezoId(mezoId?: string, queryOptions?: Omit<UseBaseQueryOptions<GetAccountByMezoIdOrAddressResponse | null>, "queryKey" | "queryFn">): import("@tanstack/react-query").UseQueryResult<GetAccountByMezoIdOrAddressResponse | null, Error>;
|
|
6
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,
|
|
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,16 +2,13 @@ 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 getAccountByMezoIdQueryKeys = (mezoId) => [
|
|
6
|
-
QUERY_KEYS.ACCOUNT,
|
|
7
|
-
mezoId,
|
|
8
|
-
];
|
|
9
|
-
export const getAccountByMezoIdQueryFunction = (authApiClient, mezoId) => mezoId ? () => authApiClient.getAccountByMezoIdOrAddress(mezoId) : skipToken;
|
|
10
5
|
export function useGetAccountByMezoId(mezoId, queryOptions = {}) {
|
|
11
6
|
const authApiClient = useAuthApiClient();
|
|
12
7
|
return useQuery({
|
|
13
|
-
queryKey:
|
|
14
|
-
queryFn:
|
|
8
|
+
queryKey: [QUERY_KEYS.ACCOUNT, mezoId],
|
|
9
|
+
queryFn: mezoId
|
|
10
|
+
? () => authApiClient.getAccountByMezoIdOrAddress(mezoId)
|
|
11
|
+
: skipToken,
|
|
15
12
|
staleTime: ONE_MINUTE_MS,
|
|
16
13
|
retry: 1,
|
|
17
14
|
...queryOptions,
|
|
@@ -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 useMezoIdValidation(mezoId: MezoId): UseQueryResult<{
|
|
4
|
+
isValid: boolean;
|
|
5
|
+
isAvailable: boolean;
|
|
6
|
+
errors: string[];
|
|
7
|
+
}>;
|
|
8
|
+
//# sourceMappingURL=useMezoIdValidation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMezoIdValidation.d.ts","sourceRoot":"","sources":["../../../src/hooks/useMezoIdValidation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EAAkB,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAGxD,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAqB1C,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 useMezoIdValidation(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=useMezoIdValidation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMezoIdValidation.js","sourceRoot":"","sources":["../../../src/hooks/useMezoIdValidation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAU,MAAM,iBAAiB,CAAA;AACxD,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;AAE/D,MAAM,UAAU,mBAAmB,CAAC,MAAc;IAChD,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.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D,CAAA;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
package/package.json
CHANGED
package/src/hooks/constants.ts
CHANGED
package/src/hooks/index.ts
CHANGED
|
@@ -11,8 +11,8 @@ export * from "./useGetAccountByAddress"
|
|
|
11
11
|
export * from "./useGetAccountByMezoId"
|
|
12
12
|
export * from "./useGetCurrentAccount"
|
|
13
13
|
export * from "./useGetSession"
|
|
14
|
-
export * from "./useIsUsernameValid"
|
|
15
14
|
export * from "./useLinkAccount"
|
|
15
|
+
export * from "./useMezoIdValidation"
|
|
16
16
|
export * from "./useRefreshPassport"
|
|
17
17
|
export * from "./useSignInWithDiscord"
|
|
18
18
|
export * from "./useSignInWithWallet"
|
|
@@ -2,18 +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 getAccountByMezoIdQueryKeys = (mezoId?: string) => [
|
|
8
|
-
QUERY_KEYS.ACCOUNT,
|
|
9
|
-
mezoId,
|
|
10
|
-
]
|
|
11
|
-
|
|
12
|
-
export const getAccountByMezoIdQueryFunction = (
|
|
13
|
-
authApiClient: AuthApiClient,
|
|
14
|
-
mezoId?: string,
|
|
15
|
-
) =>
|
|
16
|
-
mezoId ? () => authApiClient.getAccountByMezoIdOrAddress(mezoId) : skipToken
|
|
5
|
+
import type { GetAccountByMezoIdOrAddressResponse } from "../api"
|
|
17
6
|
|
|
18
7
|
export function useGetAccountByMezoId(
|
|
19
8
|
mezoId?: string,
|
|
@@ -25,8 +14,10 @@ export function useGetAccountByMezoId(
|
|
|
25
14
|
const authApiClient = useAuthApiClient()
|
|
26
15
|
|
|
27
16
|
return useQuery({
|
|
28
|
-
queryKey:
|
|
29
|
-
queryFn:
|
|
17
|
+
queryKey: [QUERY_KEYS.ACCOUNT, mezoId],
|
|
18
|
+
queryFn: mezoId
|
|
19
|
+
? () => authApiClient.getAccountByMezoIdOrAddress(mezoId)
|
|
20
|
+
: skipToken,
|
|
30
21
|
staleTime: ONE_MINUTE_MS,
|
|
31
22
|
retry: 1,
|
|
32
23
|
...queryOptions,
|
|
@@ -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 useMezoIdValidation(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":"useIsUsernameValid.d.ts","sourceRoot":"","sources":["../../../src/hooks/useIsUsernameValid.ts"],"names":[],"mappings":"AAUA,wBAAgB,kBAAkB;gCAKb,MAAM;;;;EAoC1B"}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { useCallback } from "react";
|
|
2
|
-
import { useQueryClient } from "@tanstack/react-query";
|
|
3
|
-
import { validateUsername } from "../utils/validation";
|
|
4
|
-
import { getAccountByMezoIdQueryFunction, getAccountByMezoIdQueryKeys, } from "./useGetAccountByMezoId";
|
|
5
|
-
import { useAuthApiClient } from "./useAuthApiClient";
|
|
6
|
-
import { ONE_MINUTE_MS } from "../utils/time";
|
|
7
|
-
export function useIsUsernameValid() {
|
|
8
|
-
const queryClient = useQueryClient();
|
|
9
|
-
const authApiClient = useAuthApiClient();
|
|
10
|
-
const isUsernameValid = useCallback(async (username) => {
|
|
11
|
-
const mezoId = `${username}.mezo`;
|
|
12
|
-
let foundUser;
|
|
13
|
-
try {
|
|
14
|
-
foundUser = await queryClient.fetchQuery({
|
|
15
|
-
queryKey: getAccountByMezoIdQueryKeys(mezoId),
|
|
16
|
-
queryFn: getAccountByMezoIdQueryFunction(authApiClient, mezoId),
|
|
17
|
-
staleTime: ONE_MINUTE_MS,
|
|
18
|
-
});
|
|
19
|
-
// eslint-disable-next-line no-empty
|
|
20
|
-
}
|
|
21
|
-
catch (error) { }
|
|
22
|
-
if (foundUser)
|
|
23
|
-
return {
|
|
24
|
-
isValid: false,
|
|
25
|
-
errors: ["Mezo id already exists."],
|
|
26
|
-
};
|
|
27
|
-
const errors = validateUsername(username);
|
|
28
|
-
if (errors.length > 0) {
|
|
29
|
-
return {
|
|
30
|
-
isValid: false,
|
|
31
|
-
errors,
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
return {
|
|
35
|
-
isValid: true,
|
|
36
|
-
errors: [],
|
|
37
|
-
};
|
|
38
|
-
}, [authApiClient, queryClient]);
|
|
39
|
-
return { isUsernameValid };
|
|
40
|
-
}
|
|
41
|
-
//# sourceMappingURL=useIsUsernameValid.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useIsUsernameValid.js","sourceRoot":"","sources":["../../../src/hooks/useIsUsernameValid.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,E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../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,52 +0,0 @@
|
|
|
1
|
-
import { useCallback } from "react"
|
|
2
|
-
import { useQueryClient } from "@tanstack/react-query"
|
|
3
|
-
import { validateUsername } from "../utils/validation"
|
|
4
|
-
import {
|
|
5
|
-
getAccountByMezoIdQueryFunction,
|
|
6
|
-
getAccountByMezoIdQueryKeys,
|
|
7
|
-
} from "./useGetAccountByMezoId"
|
|
8
|
-
import { useAuthApiClient } from "./useAuthApiClient"
|
|
9
|
-
import { ONE_MINUTE_MS } from "../utils/time"
|
|
10
|
-
|
|
11
|
-
export function useIsUsernameValid() {
|
|
12
|
-
const queryClient = useQueryClient()
|
|
13
|
-
const authApiClient = useAuthApiClient()
|
|
14
|
-
|
|
15
|
-
const isUsernameValid = useCallback(
|
|
16
|
-
async (username: string) => {
|
|
17
|
-
const mezoId = `${username}.mezo`
|
|
18
|
-
|
|
19
|
-
let foundUser
|
|
20
|
-
try {
|
|
21
|
-
foundUser = await queryClient.fetchQuery({
|
|
22
|
-
queryKey: getAccountByMezoIdQueryKeys(mezoId),
|
|
23
|
-
queryFn: getAccountByMezoIdQueryFunction(authApiClient, mezoId),
|
|
24
|
-
staleTime: ONE_MINUTE_MS,
|
|
25
|
-
})
|
|
26
|
-
// eslint-disable-next-line no-empty
|
|
27
|
-
} catch (error) {}
|
|
28
|
-
|
|
29
|
-
if (foundUser)
|
|
30
|
-
return {
|
|
31
|
-
isValid: false,
|
|
32
|
-
errors: ["Mezo id already exists."],
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const errors = validateUsername(username)
|
|
36
|
-
if (errors.length > 0) {
|
|
37
|
-
return {
|
|
38
|
-
isValid: false,
|
|
39
|
-
errors,
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return {
|
|
44
|
-
isValid: true,
|
|
45
|
-
errors: [],
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
[authApiClient, queryClient],
|
|
49
|
-
)
|
|
50
|
-
|
|
51
|
-
return { isUsernameValid }
|
|
52
|
-
}
|