@oxyhq/auth 2.0.4 → 2.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/dist/cjs/.tsbuildinfo +1 -1
  2. package/dist/cjs/WebOxyProvider.js +37 -0
  3. package/dist/cjs/hooks/mutations/useAccountMutations.js +185 -43
  4. package/dist/cjs/hooks/queryClient.js +136 -92
  5. package/dist/cjs/hooks/useFileDownloadUrl.js +12 -36
  6. package/dist/cjs/hooks/useSessionSocket.js +81 -94
  7. package/dist/cjs/index.js +1 -2
  8. package/dist/cjs/utils/sessionHelpers.js +3 -1
  9. package/dist/cjs/utils/storageHelpers.js +36 -10
  10. package/dist/esm/.tsbuildinfo +1 -1
  11. package/dist/esm/WebOxyProvider.js +38 -1
  12. package/dist/esm/hooks/mutations/useAccountMutations.js +186 -44
  13. package/dist/esm/hooks/queryClient.js +132 -89
  14. package/dist/esm/hooks/useFileDownloadUrl.js +11 -34
  15. package/dist/esm/hooks/useSessionSocket.js +81 -94
  16. package/dist/esm/index.js +1 -1
  17. package/dist/esm/utils/sessionHelpers.js +3 -1
  18. package/dist/esm/utils/storageHelpers.js +36 -10
  19. package/dist/types/.tsbuildinfo +1 -1
  20. package/dist/types/WebOxyProvider.d.ts +1 -1
  21. package/dist/types/hooks/mutations/useAccountMutations.d.ts +153 -9
  22. package/dist/types/hooks/queries/useAccountQueries.d.ts +11 -7
  23. package/dist/types/hooks/queries/useSecurityQueries.d.ts +2 -2
  24. package/dist/types/hooks/queries/useServicesQueries.d.ts +7 -5
  25. package/dist/types/hooks/queryClient.d.ts +24 -10
  26. package/dist/types/hooks/useAssets.d.ts +1 -1
  27. package/dist/types/hooks/useFileDownloadUrl.d.ts +2 -6
  28. package/dist/types/index.d.ts +1 -1
  29. package/dist/types/utils/sessionHelpers.d.ts +3 -1
  30. package/package.json +22 -3
  31. package/src/WebOxyProvider.tsx +39 -1
  32. package/src/hooks/mutations/useAccountMutations.ts +230 -57
  33. package/src/hooks/queryClient.ts +140 -83
  34. package/src/hooks/useFileDownloadUrl.ts +15 -39
  35. package/src/hooks/useSessionSocket.ts +123 -91
  36. package/src/index.ts +1 -1
  37. package/src/utils/sessionHelpers.ts +3 -1
  38. package/src/utils/storageHelpers.ts +49 -10
package/src/index.ts CHANGED
@@ -104,7 +104,7 @@ export { useWebSSO, isWebBrowser } from './hooks/useWebSSO';
104
104
  export { useSessionSocket } from './hooks/useSessionSocket';
105
105
  export type { UseSessionSocketOptions } from './hooks/useSessionSocket';
106
106
  export { useAssets, setOxyAssetInstance } from './hooks/useAssets';
107
- export { useFileDownloadUrl, setOxyFileUrlInstance } from './hooks/useFileDownloadUrl';
107
+ export { useFileDownloadUrl } from './hooks/useFileDownloadUrl';
108
108
  export { useFollow, useFollowerCounts } from './hooks/useFollow';
109
109
  export { useFileFiltering } from './hooks/useFileFiltering';
110
110
  export type { ViewMode, SortBy, SortOrder } from './hooks/useFileFiltering';
@@ -68,7 +68,9 @@ export const mapSessionsToClient = (
68
68
  };
69
69
 
70
70
  /**
71
- * Fetch device sessions with fallback to the legacy session endpoint when needed.
71
+ * Fetch device sessions, falling back to the per-user session endpoint
72
+ * if the device endpoint is unavailable (older API versions or disabled
73
+ * device-grouping feature flag).
72
74
  *
73
75
  * @param oxyServices - Oxy service instance
74
76
  * @param sessionId - Session identifier to fetch
@@ -19,7 +19,8 @@ const MEMORY_STORAGE = (): StorageInterface => {
19
19
 
20
20
  return {
21
21
  async getItem(key: string) {
22
- return store.has(key) ? store.get(key)! : null;
22
+ const value = store.get(key);
23
+ return value === undefined ? null : value;
23
24
  },
24
25
  async setItem(key: string, value: string) {
25
26
  store.set(key, value);
@@ -46,29 +47,33 @@ const createWebStorage = (): StorageInterface => {
46
47
  async getItem(key: string) {
47
48
  try {
48
49
  return window.localStorage.getItem(key);
49
- } catch {
50
+ } catch (err) {
51
+ console.warn('[oxy.storage] localStorage.getItem failed:', err);
50
52
  return null;
51
53
  }
52
54
  },
53
55
  async setItem(key: string, value: string) {
54
56
  try {
55
57
  window.localStorage.setItem(key, value);
56
- } catch {
57
- // Ignore quota or access issues for now.
58
+ } catch (err) {
59
+ // Quota exceeded or storage disabled (e.g., Safari private mode).
60
+ // Surface to logs so it is debuggable, but do not throw so callers
61
+ // can keep functioning with degraded persistence.
62
+ console.warn('[oxy.storage] localStorage.setItem failed:', err);
58
63
  }
59
64
  },
60
65
  async removeItem(key: string) {
61
66
  try {
62
67
  window.localStorage.removeItem(key);
63
- } catch {
64
- // Ignore failures.
68
+ } catch (err) {
69
+ console.warn('[oxy.storage] localStorage.removeItem failed:', err);
65
70
  }
66
71
  },
67
72
  async clear() {
68
73
  try {
69
74
  window.localStorage.clear();
70
- } catch {
71
- // Ignore failures.
75
+ } catch (err) {
76
+ console.warn('[oxy.storage] localStorage.clear failed:', err);
72
77
  }
73
78
  },
74
79
  };
@@ -76,6 +81,31 @@ const createWebStorage = (): StorageInterface => {
76
81
 
77
82
  let asyncStorageInstance: StorageInterface | null = null;
78
83
 
84
+ /**
85
+ * Structural type for the React Native AsyncStorage default export.
86
+ * Only includes the methods this SDK uses.
87
+ */
88
+ interface AsyncStorageLike {
89
+ getItem: (key: string) => Promise<string | null>;
90
+ setItem: (key: string, value: string) => Promise<void>;
91
+ removeItem: (key: string) => Promise<void>;
92
+ clear: () => Promise<void>;
93
+ }
94
+
95
+ /**
96
+ * Type guard verifying that an imported value exposes the AsyncStorage API.
97
+ */
98
+ const isAsyncStorageLike = (value: unknown): value is AsyncStorageLike => {
99
+ if (typeof value !== 'object' || value === null) return false;
100
+ const candidate = value as Record<string, unknown>;
101
+ return (
102
+ typeof candidate.getItem === 'function' &&
103
+ typeof candidate.setItem === 'function' &&
104
+ typeof candidate.removeItem === 'function' &&
105
+ typeof candidate.clear === 'function'
106
+ );
107
+ };
108
+
79
109
  /**
80
110
  * Lazily import React Native AsyncStorage implementation.
81
111
  */
@@ -87,8 +117,17 @@ const createNativeStorage = async (): Promise<StorageInterface> => {
87
117
  try {
88
118
  // Variable indirection prevents bundlers (Vite, webpack) from statically resolving this
89
119
  const moduleName = '@react-native-async-storage/async-storage';
90
- const asyncStorageModule = await import(moduleName);
91
- asyncStorageInstance = asyncStorageModule.default as unknown as StorageInterface;
120
+ const asyncStorageModule = (await import(moduleName)) as { default?: unknown };
121
+ const candidate = asyncStorageModule.default;
122
+ if (!isAsyncStorageLike(candidate)) {
123
+ throw new Error('AsyncStorage default export does not match expected API');
124
+ }
125
+ asyncStorageInstance = {
126
+ getItem: (key) => candidate.getItem(key),
127
+ setItem: (key, value) => candidate.setItem(key, value),
128
+ removeItem: (key) => candidate.removeItem(key),
129
+ clear: () => candidate.clear(),
130
+ };
92
131
  return asyncStorageInstance;
93
132
  } catch (error) {
94
133
  if (process.env.NODE_ENV !== 'production') {