@oxyhq/services 5.16.29 → 5.16.30
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/lib/commonjs/index.js +64 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/ui/hooks/auth/index.js +37 -0
- package/lib/commonjs/ui/hooks/auth/index.js.map +1 -0
- package/lib/commonjs/ui/hooks/auth/useUsernameValidation.js +171 -0
- package/lib/commonjs/ui/hooks/auth/useUsernameValidation.js.map +1 -0
- package/lib/commonjs/ui/hooks/index.js +20 -0
- package/lib/commonjs/ui/hooks/index.js.map +1 -1
- package/lib/commonjs/ui/hooks/mutations/index.js +12 -0
- package/lib/commonjs/ui/hooks/mutations/index.js.map +1 -1
- package/lib/commonjs/ui/hooks/mutations/useAccountMutations.js +45 -1
- package/lib/commonjs/ui/hooks/mutations/useAccountMutations.js.map +1 -1
- package/lib/commonjs/ui/hooks/queries/index.js +12 -0
- package/lib/commonjs/ui/hooks/queries/index.js.map +1 -1
- package/lib/commonjs/ui/hooks/queries/queryKeys.js +3 -1
- package/lib/commonjs/ui/hooks/queries/queryKeys.js.map +1 -1
- package/lib/commonjs/ui/hooks/queries/useAccountQueries.js +43 -1
- package/lib/commonjs/ui/hooks/queries/useAccountQueries.js.map +1 -1
- package/lib/commonjs/ui/screens/PrivacySettingsScreen.js +76 -97
- package/lib/commonjs/ui/screens/PrivacySettingsScreen.js.map +1 -1
- package/lib/module/index.js +3 -3
- package/lib/module/index.js.map +1 -1
- package/lib/module/ui/hooks/auth/index.js +7 -0
- package/lib/module/ui/hooks/auth/index.js.map +1 -0
- package/lib/module/ui/hooks/auth/useUsernameValidation.js +167 -0
- package/lib/module/ui/hooks/auth/useUsernameValidation.js.map +1 -0
- package/lib/module/ui/hooks/index.js +1 -0
- package/lib/module/ui/hooks/index.js.map +1 -1
- package/lib/module/ui/hooks/mutations/index.js +1 -1
- package/lib/module/ui/hooks/mutations/index.js.map +1 -1
- package/lib/module/ui/hooks/mutations/useAccountMutations.js +42 -0
- package/lib/module/ui/hooks/mutations/useAccountMutations.js.map +1 -1
- package/lib/module/ui/hooks/queries/index.js +1 -1
- package/lib/module/ui/hooks/queries/index.js.map +1 -1
- package/lib/module/ui/hooks/queries/queryKeys.js +3 -1
- package/lib/module/ui/hooks/queries/queryKeys.js.map +1 -1
- package/lib/module/ui/hooks/queries/useAccountQueries.js +40 -0
- package/lib/module/ui/hooks/queries/useAccountQueries.js.map +1 -1
- package/lib/module/ui/screens/PrivacySettingsScreen.js +77 -98
- package/lib/module/ui/screens/PrivacySettingsScreen.js.map +1 -1
- package/lib/typescript/index.d.ts +4 -2
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/ui/hooks/auth/index.d.ts +6 -0
- package/lib/typescript/ui/hooks/auth/index.d.ts.map +1 -0
- package/lib/typescript/ui/hooks/auth/useUsernameValidation.d.ts +32 -0
- package/lib/typescript/ui/hooks/auth/useUsernameValidation.d.ts.map +1 -0
- package/lib/typescript/ui/hooks/index.d.ts +1 -0
- package/lib/typescript/ui/hooks/index.d.ts.map +1 -1
- package/lib/typescript/ui/hooks/mutations/index.d.ts +1 -1
- package/lib/typescript/ui/hooks/mutations/index.d.ts.map +1 -1
- package/lib/typescript/ui/hooks/mutations/useAccountMutations.d.ts +12 -0
- package/lib/typescript/ui/hooks/mutations/useAccountMutations.d.ts.map +1 -1
- package/lib/typescript/ui/hooks/queries/index.d.ts +1 -1
- package/lib/typescript/ui/hooks/queries/index.d.ts.map +1 -1
- package/lib/typescript/ui/hooks/queries/queryKeys.d.ts +2 -0
- package/lib/typescript/ui/hooks/queries/queryKeys.d.ts.map +1 -1
- package/lib/typescript/ui/hooks/queries/useAccountQueries.d.ts +12 -0
- package/lib/typescript/ui/hooks/queries/useAccountQueries.d.ts.map +1 -1
- package/lib/typescript/ui/screens/PrivacySettingsScreen.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +6 -0
- package/src/ui/hooks/auth/index.ts +6 -0
- package/src/ui/hooks/auth/useUsernameValidation.ts +177 -0
- package/src/ui/hooks/index.ts +2 -1
- package/src/ui/hooks/mutations/index.ts +2 -0
- package/src/ui/hooks/mutations/useAccountMutations.ts +36 -0
- package/src/ui/hooks/queries/index.ts +2 -0
- package/src/ui/hooks/queries/queryKeys.ts +2 -0
- package/src/ui/hooks/queries/useAccountQueries.ts +34 -0
- package/src/ui/screens/PrivacySettingsScreen.tsx +67 -101
- package/lib/commonjs/ui/context/hooks/useSessionManagement.js +0 -281
- package/lib/commonjs/ui/context/hooks/useSessionManagement.js.map +0 -1
- package/lib/commonjs/ui/context/hooks/useStorage.js +0 -79
- package/lib/commonjs/ui/context/hooks/useStorage.js.map +0 -1
- package/lib/module/ui/context/hooks/useSessionManagement.js +0 -276
- package/lib/module/ui/context/hooks/useSessionManagement.js.map +0 -1
- package/lib/module/ui/context/hooks/useStorage.js +0 -74
- package/lib/module/ui/context/hooks/useStorage.js.map +0 -1
- package/lib/typescript/ui/context/hooks/useSessionManagement.d.ts +0 -41
- package/lib/typescript/ui/context/hooks/useSessionManagement.d.ts.map +0 -1
- package/lib/typescript/ui/context/hooks/useStorage.d.ts +0 -22
- package/lib/typescript/ui/context/hooks/useStorage.d.ts.map +0 -1
- package/src/ui/context/hooks/useSessionManagement.ts +0 -401
- package/src/ui/context/hooks/useStorage.ts +0 -104
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,mBAAmB,CAAC;AAG3B,OAAO,EACL,UAAU,EACV,gBAAgB,EACjB,MAAM,UAAU,CAAC;AAGlB,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAE,6BAA6B,EAAE,MAAM,QAAQ,CAAC;AAC5F,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAClD,YAAY,EACV,OAAO,EACP,aAAa,EACb,aAAa,EAC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
+
*/
|
|
4
|
+
export { useUsernameValidation, USERNAME_MIN_LENGTH, USERNAME_REGEX, USERNAME_FORMAT_ERROR, USERNAME_DEBOUNCE_MS } from './useUsernameValidation';
|
|
5
|
+
export type { UsernameValidationResult } from './useUsernameValidation';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/ui/hooks/auth/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,cAAc,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAClJ,YAAY,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { OxyServices } from '../../../core';
|
|
2
|
+
/**
|
|
3
|
+
* Username validation constants
|
|
4
|
+
*/
|
|
5
|
+
export declare const USERNAME_MIN_LENGTH = 4;
|
|
6
|
+
export declare const USERNAME_REGEX: RegExp;
|
|
7
|
+
export declare const USERNAME_FORMAT_ERROR = "You can use a-z, 0-9. Minimum length is 4 characters.";
|
|
8
|
+
export declare const USERNAME_DEBOUNCE_MS = 500;
|
|
9
|
+
/**
|
|
10
|
+
* Username validation result interface
|
|
11
|
+
*/
|
|
12
|
+
export interface UsernameValidationResult {
|
|
13
|
+
isValid: boolean;
|
|
14
|
+
isAvailable: boolean | null;
|
|
15
|
+
error: string | null;
|
|
16
|
+
isChecking: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Hook for username validation with debouncing and availability checking
|
|
20
|
+
*
|
|
21
|
+
* Uses TanStack Query for efficient API calls with:
|
|
22
|
+
* - Automatic request cancellation when username changes
|
|
23
|
+
* - Built-in caching (same username checked multiple times = cached result)
|
|
24
|
+
* - Request deduplication (multiple components checking same username = single request)
|
|
25
|
+
* - Proper error handling
|
|
26
|
+
*
|
|
27
|
+
* @param username - The username to validate
|
|
28
|
+
* @param oxyServices - OxyServices instance for API calls
|
|
29
|
+
* @returns Username validation state and result
|
|
30
|
+
*/
|
|
31
|
+
export declare function useUsernameValidation(username: string, oxyServices: OxyServices | null): UsernameValidationResult;
|
|
32
|
+
//# sourceMappingURL=useUsernameValidation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useUsernameValidation.d.ts","sourceRoot":"","sources":["../../../../../src/ui/hooks/auth/useUsernameValidation.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAIjD;;GAEG;AACH,eAAO,MAAM,mBAAmB,IAAI,CAAC;AACrC,eAAO,MAAM,cAAc,QAAiB,CAAC;AAC7C,eAAO,MAAM,qBAAqB,0DAA0D,CAAC;AAC7F,eAAO,MAAM,oBAAoB,MAAM,CAAC;AAExC;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,OAAO,GAAG,IAAI,CAAC;IAC5B,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,UAAU,EAAE,OAAO,CAAC;CACrB;AA8BD;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,WAAW,GAAG,IAAI,GAC9B,wBAAwB,CA2G1B"}
|
|
@@ -2,4 +2,5 @@ export { useFollow, useFollowerCounts } from './useFollow';
|
|
|
2
2
|
export { useFileDownloadUrl, setOxyFileUrlInstance } from './useFileDownloadUrl';
|
|
3
3
|
export { useThemeStyles } from './useThemeStyles';
|
|
4
4
|
export { useThemeColors } from './useThemeColors';
|
|
5
|
+
export * from './auth';
|
|
5
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/ui/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AACjF,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/ui/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AACjF,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,cAAc,QAAQ,CAAC"}
|
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
* TanStack Query mutation hooks for updating Oxy services data.
|
|
5
5
|
* All mutations handle authentication, error handling, and query invalidation.
|
|
6
6
|
*/
|
|
7
|
-
export { useUpdateProfile, useUploadAvatar, useUpdateAccountSettings, useUpdatePrivacySettings, useUploadFile, } from './useAccountMutations';
|
|
7
|
+
export { useUpdateProfile, useUploadAvatar, useUpdateAccountSettings, useUpdatePrivacySettings, useUploadFile, useUnblockUser, useUnrestrictUser, } from './useAccountMutations';
|
|
8
8
|
export { useSwitchSession, useLogoutSession, useLogoutAll, useUpdateDeviceName, useRemoveDevice, } from './useServicesMutations';
|
|
9
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/ui/hooks/mutations/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,wBAAwB,EACxB,wBAAwB,EACxB,aAAa,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/ui/hooks/mutations/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,wBAAwB,EACxB,wBAAwB,EACxB,aAAa,EACb,cAAc,EACd,iBAAiB,GAClB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,YAAY,EACZ,mBAAmB,EACnB,eAAe,GAChB,MAAM,wBAAwB,CAAC"}
|
|
@@ -41,4 +41,16 @@ export declare const useUploadFile: () => import("@tanstack/react-query").UseMut
|
|
|
41
41
|
metadata?: Record<string, any>;
|
|
42
42
|
onProgress?: (progress: number) => void;
|
|
43
43
|
}, unknown>;
|
|
44
|
+
/**
|
|
45
|
+
* Unblock a user with query invalidation
|
|
46
|
+
*/
|
|
47
|
+
export declare const useUnblockUser: () => import("@tanstack/react-query").UseMutationResult<{
|
|
48
|
+
message: string;
|
|
49
|
+
}, Error, string, unknown>;
|
|
50
|
+
/**
|
|
51
|
+
* Unrestrict a user with query invalidation
|
|
52
|
+
*/
|
|
53
|
+
export declare const useUnrestrictUser: () => import("@tanstack/react-query").UseMutationResult<{
|
|
54
|
+
message: string;
|
|
55
|
+
}, Error, string, unknown>;
|
|
44
56
|
//# sourceMappingURL=useAccountMutations.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAccountMutations.d.ts","sourceRoot":"","sources":["../../../../../src/ui/hooks/mutations/useAccountMutations.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAOvD;;GAEG;AACH,eAAO,MAAM,gBAAgB;;EAgH5B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,eAAe;SAKQ,MAAM;WAAS,MAAM;WAAS,MAAM;WAAS,MAAM;;;EA2GtF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,wBAAwB;;EA2CpC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,wBAAwB;cAKoB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;aAAW,MAAM;;;;cAmI5F,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,aAAa;UAUd,IAAI;iBACG,SAAS,GAAG,QAAQ,GAAG,UAAU;eACnC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;iBACjB,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI;WAoD5C,CAAC"}
|
|
1
|
+
{"version":3,"file":"useAccountMutations.d.ts","sourceRoot":"","sources":["../../../../../src/ui/hooks/mutations/useAccountMutations.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAOvD;;GAEG;AACH,eAAO,MAAM,gBAAgB;;EAgH5B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,eAAe;SAKQ,MAAM;WAAS,MAAM;WAAS,MAAM;WAAS,MAAM;;;EA2GtF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,wBAAwB;;EA2CpC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,wBAAwB;cAKoB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;aAAW,MAAM;;;;cAmI5F,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,aAAa;UAUd,IAAI;iBACG,SAAS,GAAG,QAAQ,GAAG,UAAU;eACnC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;iBACjB,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI;WAoD5C,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc;;0BAa1B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB;;0BAa7B,CAAC"}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* TanStack Query hooks for fetching Oxy services data.
|
|
5
5
|
* All hooks follow the same pattern with optional `enabled` parameter.
|
|
6
6
|
*/
|
|
7
|
-
export { useUserProfile, useUserProfiles, useCurrentUser, useUserById, useUserByUsername, useUsersBySessions, usePrivacySettings, } from './useAccountQueries';
|
|
7
|
+
export { useUserProfile, useUserProfiles, useCurrentUser, useUserById, useUserByUsername, useUsersBySessions, usePrivacySettings, useBlockedUsers, useRestrictedUsers, } from './useAccountQueries';
|
|
8
8
|
export { useSessions, useSession, useDeviceSessions, useUserDevices, useSecurityInfo, } from './useServicesQueries';
|
|
9
9
|
export { useSecurityActivity, useRecentSecurityActivity, } from './useSecurityQueries';
|
|
10
10
|
export { queryKeys, invalidateAccountQueries, invalidateUserQueries, invalidateSessionQueries } from './queryKeys';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/ui/hooks/queries/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EACL,cAAc,EACd,eAAe,EACf,cAAc,EACd,WAAW,EACX,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EACL,WAAW,EACX,UAAU,EACV,iBAAiB,EACjB,cAAc,EACd,eAAe,GAChB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EACL,mBAAmB,EACnB,yBAAyB,GAC1B,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EAAE,SAAS,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/ui/hooks/queries/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EACL,cAAc,EACd,eAAe,EACf,cAAc,EACd,WAAW,EACX,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,eAAe,EACf,kBAAkB,GACnB,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EACL,WAAW,EACX,UAAU,EACV,iBAAiB,EACjB,cAAc,EACd,eAAe,GAChB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EACL,mBAAmB,EACnB,yBAAyB,GAC1B,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EAAE,SAAS,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -43,6 +43,8 @@ export declare const queryKeys: {
|
|
|
43
43
|
readonly privacy: {
|
|
44
44
|
readonly all: readonly ["privacy"];
|
|
45
45
|
readonly settings: (userId?: string) => readonly ["privacy", "settings", string];
|
|
46
|
+
readonly blocked: () => readonly ["privacy", "blocked"];
|
|
47
|
+
readonly restricted: () => readonly ["privacy", "restricted"];
|
|
46
48
|
};
|
|
47
49
|
readonly security: {
|
|
48
50
|
readonly all: readonly ["security"];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queryKeys.d.ts","sourceRoot":"","sources":["../../../../../src/ui/hooks/queries/queryKeys.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,eAAO,MAAM,SAAS;;;;oCAKC,MAAM,EAAE;;qCAEP,MAAM;;;;;;;iCASV,MAAM,EAAE;;kCAEP,MAAM;sCACF,MAAM;;;;;iCAOX,MAAM;;qCAEF,MAAM;;oCAEP,MAAM;;;;;iCAOT,MAAM;;oCAEH,MAAM;;;;qCAML,MAAM
|
|
1
|
+
{"version":3,"file":"queryKeys.d.ts","sourceRoot":"","sources":["../../../../../src/ui/hooks/queries/queryKeys.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,eAAO,MAAM,SAAS;;;;oCAKC,MAAM,EAAE;;qCAEP,MAAM;;;;;;;iCASV,MAAM,EAAE;;kCAEP,MAAM;sCACF,MAAM;;;;;iCAOX,MAAM;;qCAEF,MAAM;;oCAEP,MAAM;;;;;iCAOT,MAAM;;oCAEH,MAAM;;;;qCAML,MAAM;;;;;;oCAQP,MAAM,WAAW,MAAM,cAAc,MAAM;iCAE9C,MAAM;;CAGhB,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,wBAAwB,GAAI,aAAa,GAAG,SAExD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,qBAAqB,GAAI,aAAa,GAAG,SAErD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,wBAAwB,GAAI,aAAa,GAAG,SAExD,CAAC"}
|
|
@@ -44,4 +44,16 @@ export declare const useUsersBySessions: (sessionIds: string[], options?: {
|
|
|
44
44
|
export declare const usePrivacySettings: (userId?: string, options?: {
|
|
45
45
|
enabled?: boolean;
|
|
46
46
|
}) => import("@tanstack/react-query").UseQueryResult<any, Error>;
|
|
47
|
+
/**
|
|
48
|
+
* Get blocked users
|
|
49
|
+
*/
|
|
50
|
+
export declare const useBlockedUsers: (options?: {
|
|
51
|
+
enabled?: boolean;
|
|
52
|
+
}) => import("@tanstack/react-query").UseQueryResult<import("../../../core").BlockedUser[], Error>;
|
|
53
|
+
/**
|
|
54
|
+
* Get restricted users
|
|
55
|
+
*/
|
|
56
|
+
export declare const useRestrictedUsers: (options?: {
|
|
57
|
+
enabled?: boolean;
|
|
58
|
+
}) => import("@tanstack/react-query").UseQueryResult<import("../../../core").RestrictedUser[], Error>;
|
|
47
59
|
//# sourceMappingURL=useAccountQueries.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAccountQueries.d.ts","sourceRoot":"","sources":["../../../../../src/ui/hooks/queries/useAccountQueries.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAKvD;;GAEG;AACH,eAAO,MAAM,cAAc,GAAI,WAAW,MAAM,GAAG,IAAI,EAAE,UAAU;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,gEAevF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,eAAe,GAAI,YAAY,MAAM,EAAE,EAAE,UAAU;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,yEAepF,CAAC;AAEF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U;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,gEAejF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAAI,UAAU,MAAM,GAAG,IAAI,EAAE,UAAU;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,gEAezF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kBAAkB,GAAI,YAAY,MAAM,EAAE,EAAE,UAAU;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE;;;WAevF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kBAAkB,GAAI,SAAS,MAAM,EAAE,UAAU;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,+DAkElF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,eAAe,GAAI,UAAU;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,iGAY9D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kBAAkB,GAAI,UAAU;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,oGAYjE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrivacySettingsScreen.d.ts","sourceRoot":"","sources":["../../../../src/ui/screens/PrivacySettingsScreen.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"PrivacySettingsScreen.d.ts","sourceRoot":"","sources":["../../../../src/ui/screens/PrivacySettingsScreen.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAyC,MAAM,OAAO,CAAC;AAQ9D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;;AAke3D,wBAAiD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oxyhq/services",
|
|
3
|
-
"version": "5.16.
|
|
3
|
+
"version": "5.16.30",
|
|
4
4
|
"description": "Reusable OxyHQ module to handle authentication, user management, karma system, device-based session management and more 🚀",
|
|
5
5
|
"main": "lib/commonjs/index.js",
|
|
6
6
|
"module": "lib/module/index.js",
|
package/src/index.ts
CHANGED
|
@@ -137,6 +137,8 @@ export {
|
|
|
137
137
|
export { useSessionSocket } from './ui/hooks/useSessionSocket';
|
|
138
138
|
export { useAssets, setOxyAssetInstance } from './ui/hooks/useAssets';
|
|
139
139
|
export { useFileDownloadUrl, setOxyFileUrlInstance } from './ui/hooks/useFileDownloadUrl';
|
|
140
|
+
export { useUsernameValidation, USERNAME_MIN_LENGTH, USERNAME_REGEX, USERNAME_FORMAT_ERROR, USERNAME_DEBOUNCE_MS } from './ui/hooks/auth';
|
|
141
|
+
export type { UsernameValidationResult } from './ui/hooks/auth';
|
|
140
142
|
|
|
141
143
|
// UI hooks - Query hooks (TanStack Query)
|
|
142
144
|
export {
|
|
@@ -148,6 +150,8 @@ export {
|
|
|
148
150
|
useUserByUsername,
|
|
149
151
|
useUsersBySessions,
|
|
150
152
|
usePrivacySettings,
|
|
153
|
+
useBlockedUsers,
|
|
154
|
+
useRestrictedUsers,
|
|
151
155
|
// Service queries
|
|
152
156
|
useSessions,
|
|
153
157
|
useSession,
|
|
@@ -167,6 +171,8 @@ export {
|
|
|
167
171
|
useUpdateAccountSettings,
|
|
168
172
|
useUpdatePrivacySettings,
|
|
169
173
|
useUploadFile,
|
|
174
|
+
useUnblockUser,
|
|
175
|
+
useUnrestrictUser,
|
|
170
176
|
// Service mutations
|
|
171
177
|
useSwitchSession,
|
|
172
178
|
useLogoutSession,
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { useQuery } from '@tanstack/react-query';
|
|
3
|
+
import type { OxyServices } from '../../../core';
|
|
4
|
+
import { handleHttpError, ErrorCodes } from '../../../utils/errorUtils';
|
|
5
|
+
import { useDebounce } from '../../../utils/hookUtils';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Username validation constants
|
|
9
|
+
*/
|
|
10
|
+
export const USERNAME_MIN_LENGTH = 4;
|
|
11
|
+
export const USERNAME_REGEX = /^[a-z0-9]+$/i;
|
|
12
|
+
export const USERNAME_FORMAT_ERROR = 'You can use a-z, 0-9. Minimum length is 4 characters.';
|
|
13
|
+
export const USERNAME_DEBOUNCE_MS = 500;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Username validation result interface
|
|
17
|
+
*/
|
|
18
|
+
export interface UsernameValidationResult {
|
|
19
|
+
isValid: boolean;
|
|
20
|
+
isAvailable: boolean | null; // null = not checked yet
|
|
21
|
+
error: string | null;
|
|
22
|
+
isChecking: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Validate username format using services validation utilities
|
|
27
|
+
*/
|
|
28
|
+
function validateUsernameFormat(username: string): boolean {
|
|
29
|
+
// Use stricter validation: lowercase alphanumeric only, min 4 chars
|
|
30
|
+
return username.length >= USERNAME_MIN_LENGTH && USERNAME_REGEX.test(username);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Check if an error is a network or timeout error
|
|
35
|
+
*/
|
|
36
|
+
function isNetworkOrTimeoutError(error: unknown): boolean {
|
|
37
|
+
const apiError = handleHttpError(error);
|
|
38
|
+
return (
|
|
39
|
+
apiError.code === ErrorCodes.NETWORK_ERROR ||
|
|
40
|
+
apiError.code === ErrorCodes.TIMEOUT ||
|
|
41
|
+
apiError.code === ErrorCodes.CONNECTION_FAILED
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Extract error message from an unknown error shape
|
|
47
|
+
*/
|
|
48
|
+
function extractAuthErrorMessage(error: unknown, fallbackMessage = 'An error occurred'): string {
|
|
49
|
+
const apiError = handleHttpError(error);
|
|
50
|
+
return apiError.message || fallbackMessage;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Hook for username validation with debouncing and availability checking
|
|
55
|
+
*
|
|
56
|
+
* Uses TanStack Query for efficient API calls with:
|
|
57
|
+
* - Automatic request cancellation when username changes
|
|
58
|
+
* - Built-in caching (same username checked multiple times = cached result)
|
|
59
|
+
* - Request deduplication (multiple components checking same username = single request)
|
|
60
|
+
* - Proper error handling
|
|
61
|
+
*
|
|
62
|
+
* @param username - The username to validate
|
|
63
|
+
* @param oxyServices - OxyServices instance for API calls
|
|
64
|
+
* @returns Username validation state and result
|
|
65
|
+
*/
|
|
66
|
+
export function useUsernameValidation(
|
|
67
|
+
username: string,
|
|
68
|
+
oxyServices: OxyServices | null
|
|
69
|
+
): UsernameValidationResult {
|
|
70
|
+
// Debounce the username input to avoid excessive API calls
|
|
71
|
+
const debouncedUsername = useDebounce(username.trim().toLowerCase(), USERNAME_DEBOUNCE_MS);
|
|
72
|
+
|
|
73
|
+
// Validate format synchronously (no API call needed)
|
|
74
|
+
const isValid = useMemo(() => validateUsernameFormat(username), [username]);
|
|
75
|
+
|
|
76
|
+
// Determine if we should check availability
|
|
77
|
+
const shouldCheckAvailability = useMemo(() => {
|
|
78
|
+
if (!debouncedUsername || debouncedUsername.length < USERNAME_MIN_LENGTH) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
return validateUsernameFormat(debouncedUsername);
|
|
82
|
+
}, [debouncedUsername]);
|
|
83
|
+
|
|
84
|
+
// Use TanStack Query for the API call
|
|
85
|
+
// This provides automatic caching, request cancellation, and deduplication
|
|
86
|
+
const {
|
|
87
|
+
data: availabilityResult,
|
|
88
|
+
isLoading: isChecking,
|
|
89
|
+
error: queryError,
|
|
90
|
+
isFetching,
|
|
91
|
+
} = useQuery({
|
|
92
|
+
queryKey: ['username', 'availability', debouncedUsername],
|
|
93
|
+
queryFn: async () => {
|
|
94
|
+
if (!oxyServices) {
|
|
95
|
+
throw new Error('OxyServices not available');
|
|
96
|
+
}
|
|
97
|
+
return await oxyServices.checkUsernameAvailability(debouncedUsername);
|
|
98
|
+
},
|
|
99
|
+
enabled: shouldCheckAvailability && !!oxyServices,
|
|
100
|
+
staleTime: 5 * 60 * 1000, // Cache for 5 minutes (usernames don't change often)
|
|
101
|
+
gcTime: 30 * 60 * 1000, // Keep in cache for 30 minutes
|
|
102
|
+
retry: (failureCount, error) => {
|
|
103
|
+
// Don't retry on network/timeout errors (user might be offline)
|
|
104
|
+
if (isNetworkOrTimeoutError(error)) {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
// Retry up to 2 times for other errors
|
|
108
|
+
return failureCount < 2;
|
|
109
|
+
},
|
|
110
|
+
retryDelay: (attemptIndex) => Math.min(1000 * 2 ** attemptIndex, 3000),
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
// Compute the result based on validation and query state
|
|
114
|
+
return useMemo(() => {
|
|
115
|
+
// If username is too short or invalid format, return early validation
|
|
116
|
+
if (!username || username.length < USERNAME_MIN_LENGTH) {
|
|
117
|
+
return {
|
|
118
|
+
isValid: false,
|
|
119
|
+
isAvailable: null,
|
|
120
|
+
error: null,
|
|
121
|
+
isChecking: false,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (!isValid) {
|
|
126
|
+
return {
|
|
127
|
+
isValid: false,
|
|
128
|
+
isAvailable: false,
|
|
129
|
+
error: USERNAME_FORMAT_ERROR,
|
|
130
|
+
isChecking: false,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// If we're not checking yet (debounce period), show checking state only if user is typing
|
|
135
|
+
const isCurrentlyChecking = isChecking || isFetching;
|
|
136
|
+
|
|
137
|
+
// Handle network/timeout errors gracefully
|
|
138
|
+
if (queryError && isNetworkOrTimeoutError(queryError)) {
|
|
139
|
+
// Allow proceeding if offline/network issue (optimistic)
|
|
140
|
+
return {
|
|
141
|
+
isValid: true,
|
|
142
|
+
isAvailable: true, // Optimistic: allow proceeding
|
|
143
|
+
error: null,
|
|
144
|
+
isChecking: false,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Handle other errors
|
|
149
|
+
if (queryError) {
|
|
150
|
+
return {
|
|
151
|
+
isValid: true,
|
|
152
|
+
isAvailable: false,
|
|
153
|
+
error: extractAuthErrorMessage(queryError, 'Failed to check username availability'),
|
|
154
|
+
isChecking: false,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// If we have a result, use it
|
|
159
|
+
if (availabilityResult) {
|
|
160
|
+
return {
|
|
161
|
+
isValid: true,
|
|
162
|
+
isAvailable: availabilityResult.available,
|
|
163
|
+
error: availabilityResult.available ? null : (availabilityResult.message || 'Username is already taken'),
|
|
164
|
+
isChecking: false,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Still checking (or waiting for debounce)
|
|
169
|
+
return {
|
|
170
|
+
isValid: true,
|
|
171
|
+
isAvailable: null,
|
|
172
|
+
error: null,
|
|
173
|
+
isChecking: isCurrentlyChecking,
|
|
174
|
+
};
|
|
175
|
+
}, [username, isValid, availabilityResult, isChecking, isFetching, queryError]);
|
|
176
|
+
}
|
|
177
|
+
|
package/src/ui/hooks/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { useFollow, useFollowerCounts } from './useFollow';
|
|
2
2
|
export { useFileDownloadUrl, setOxyFileUrlInstance } from './useFileDownloadUrl';
|
|
3
3
|
export { useThemeStyles } from './useThemeStyles';
|
|
4
|
-
export { useThemeColors } from './useThemeColors';
|
|
4
|
+
export { useThemeColors } from './useThemeColors';
|
|
5
|
+
export * from './auth';
|
|
@@ -499,3 +499,39 @@ export const useUploadFile = () => {
|
|
|
499
499
|
});
|
|
500
500
|
};
|
|
501
501
|
|
|
502
|
+
/**
|
|
503
|
+
* Unblock a user with query invalidation
|
|
504
|
+
*/
|
|
505
|
+
export const useUnblockUser = () => {
|
|
506
|
+
const { oxyServices } = useOxy();
|
|
507
|
+
const queryClient = useQueryClient();
|
|
508
|
+
|
|
509
|
+
return useMutation({
|
|
510
|
+
mutationFn: async (userId: string) => {
|
|
511
|
+
return await oxyServices.unblockUser(userId);
|
|
512
|
+
},
|
|
513
|
+
onSuccess: () => {
|
|
514
|
+
// Invalidate blocked users query to refetch the list
|
|
515
|
+
queryClient.invalidateQueries({ queryKey: queryKeys.privacy.blocked() });
|
|
516
|
+
},
|
|
517
|
+
});
|
|
518
|
+
};
|
|
519
|
+
|
|
520
|
+
/**
|
|
521
|
+
* Unrestrict a user with query invalidation
|
|
522
|
+
*/
|
|
523
|
+
export const useUnrestrictUser = () => {
|
|
524
|
+
const { oxyServices } = useOxy();
|
|
525
|
+
const queryClient = useQueryClient();
|
|
526
|
+
|
|
527
|
+
return useMutation({
|
|
528
|
+
mutationFn: async (userId: string) => {
|
|
529
|
+
return await oxyServices.unrestrictUser(userId);
|
|
530
|
+
},
|
|
531
|
+
onSuccess: () => {
|
|
532
|
+
// Invalidate restricted users query to refetch the list
|
|
533
|
+
queryClient.invalidateQueries({ queryKey: queryKeys.privacy.restricted() });
|
|
534
|
+
},
|
|
535
|
+
});
|
|
536
|
+
};
|
|
537
|
+
|
|
@@ -53,6 +53,8 @@ export const queryKeys = {
|
|
|
53
53
|
privacy: {
|
|
54
54
|
all: ['privacy'] as const,
|
|
55
55
|
settings: (userId?: string) => [...queryKeys.privacy.all, 'settings', userId || 'current'] as const,
|
|
56
|
+
blocked: () => [...queryKeys.privacy.all, 'blocked'] as const,
|
|
57
|
+
restricted: () => [...queryKeys.privacy.all, 'restricted'] as const,
|
|
56
58
|
},
|
|
57
59
|
|
|
58
60
|
// Security activity queries
|
|
@@ -195,3 +195,37 @@ export const usePrivacySettings = (userId?: string, options?: { enabled?: boolea
|
|
|
195
195
|
});
|
|
196
196
|
};
|
|
197
197
|
|
|
198
|
+
/**
|
|
199
|
+
* Get blocked users
|
|
200
|
+
*/
|
|
201
|
+
export const useBlockedUsers = (options?: { enabled?: boolean }) => {
|
|
202
|
+
const { oxyServices, isAuthenticated } = useOxy();
|
|
203
|
+
|
|
204
|
+
return useQuery({
|
|
205
|
+
queryKey: queryKeys.privacy.blocked(),
|
|
206
|
+
queryFn: async () => {
|
|
207
|
+
return await oxyServices.getBlockedUsers();
|
|
208
|
+
},
|
|
209
|
+
enabled: (options?.enabled !== false) && isAuthenticated,
|
|
210
|
+
staleTime: 1 * 60 * 1000, // 1 minute
|
|
211
|
+
gcTime: 5 * 60 * 1000, // 5 minutes
|
|
212
|
+
});
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Get restricted users
|
|
217
|
+
*/
|
|
218
|
+
export const useRestrictedUsers = (options?: { enabled?: boolean }) => {
|
|
219
|
+
const { oxyServices, isAuthenticated } = useOxy();
|
|
220
|
+
|
|
221
|
+
return useQuery({
|
|
222
|
+
queryKey: queryKeys.privacy.restricted(),
|
|
223
|
+
queryFn: async () => {
|
|
224
|
+
return await oxyServices.getRestrictedUsers();
|
|
225
|
+
},
|
|
226
|
+
enabled: (options?.enabled !== false) && isAuthenticated,
|
|
227
|
+
staleTime: 1 * 60 * 1000, // 1 minute
|
|
228
|
+
gcTime: 5 * 60 * 1000, // 5 minutes
|
|
229
|
+
});
|
|
230
|
+
};
|
|
231
|
+
|