@oxyhq/core 1.8.0 → 1.8.1
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/cjs/.tsbuildinfo +1 -0
- package/dist/cjs/HttpService.js +8 -55
- package/dist/cjs/crypto/signatureService.js +1 -1
- package/dist/cjs/index.js +8 -1
- package/dist/cjs/mixins/OxyServices.assets.js +13 -15
- package/dist/cjs/utils/accountUtils.js +49 -0
- package/dist/cjs/utils/avatarUtils.js +28 -0
- package/dist/esm/.tsbuildinfo +1 -0
- package/dist/esm/HttpService.js +8 -55
- package/dist/esm/crypto/signatureService.js +1 -1
- package/dist/esm/index.js +4 -0
- package/dist/esm/mixins/OxyServices.assets.js +13 -15
- package/dist/esm/utils/accountUtils.js +44 -0
- package/dist/esm/utils/avatarUtils.js +25 -0
- package/dist/types/.tsbuildinfo +1 -0
- package/dist/types/HttpService.d.ts +5 -57
- package/dist/types/OxyServices.d.ts +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/mixins/OxyServices.assets.d.ts +12 -3
- package/dist/types/utils/accountUtils.d.ts +36 -0
- package/dist/types/utils/avatarUtils.d.ts +16 -0
- package/package.json +2 -2
- package/src/HttpService.ts +13 -60
- package/src/OxyServices.ts +3 -0
- package/src/crypto/signatureService.ts +2 -2
- package/src/index.ts +7 -0
- package/src/mixins/OxyServices.assets.ts +16 -17
- package/src/types/expo-crypto.d.ts +16 -0
- package/src/types/expo-secure-store.d.ts +17 -0
- package/src/utils/accountUtils.ts +69 -0
- package/src/utils/avatarUtils.ts +37 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared account types and pure helper functions.
|
|
3
|
+
* Used by both @oxyhq/services (React Native) and @oxyhq/auth (Web) account stores.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export interface QuickAccount {
|
|
7
|
+
sessionId: string;
|
|
8
|
+
userId?: string;
|
|
9
|
+
username: string;
|
|
10
|
+
displayName: string;
|
|
11
|
+
avatar?: string;
|
|
12
|
+
avatarUrl?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Build an ordered array of QuickAccounts from a map and order list.
|
|
17
|
+
*/
|
|
18
|
+
export const buildAccountsArray = (
|
|
19
|
+
accounts: Record<string, QuickAccount>,
|
|
20
|
+
order: string[]
|
|
21
|
+
): QuickAccount[] => {
|
|
22
|
+
const result: QuickAccount[] = [];
|
|
23
|
+
for (const id of order) {
|
|
24
|
+
const account = accounts[id];
|
|
25
|
+
if (account) result.push(account);
|
|
26
|
+
}
|
|
27
|
+
return result;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Create a QuickAccount from user data returned by the API.
|
|
32
|
+
*
|
|
33
|
+
* @param sessionId - Session identifier
|
|
34
|
+
* @param userData - Raw user object from the API
|
|
35
|
+
* @param existingAccount - Previously cached account (to preserve avatarUrl if unchanged)
|
|
36
|
+
* @param getFileDownloadUrl - Function to generate avatar download URL from file ID
|
|
37
|
+
*/
|
|
38
|
+
export const createQuickAccount = (
|
|
39
|
+
sessionId: string,
|
|
40
|
+
userData: {
|
|
41
|
+
name?: { full?: string; first?: string };
|
|
42
|
+
username?: string;
|
|
43
|
+
id?: string;
|
|
44
|
+
_id?: { toString(): string } | string;
|
|
45
|
+
avatar?: string;
|
|
46
|
+
},
|
|
47
|
+
existingAccount?: QuickAccount,
|
|
48
|
+
getFileDownloadUrl?: (fileId: string, variant: string) => string
|
|
49
|
+
): QuickAccount => {
|
|
50
|
+
const displayName = userData.name?.full || userData.name?.first || userData.username || 'Account';
|
|
51
|
+
const userId = userData.id || (typeof userData._id === 'string' ? userData._id : userData._id?.toString());
|
|
52
|
+
|
|
53
|
+
// Preserve existing avatarUrl if avatar hasn't changed (prevents image reload)
|
|
54
|
+
let avatarUrl: string | undefined;
|
|
55
|
+
if (existingAccount && existingAccount.avatar === userData.avatar && existingAccount.avatarUrl) {
|
|
56
|
+
avatarUrl = existingAccount.avatarUrl;
|
|
57
|
+
} else if (userData.avatar && getFileDownloadUrl) {
|
|
58
|
+
avatarUrl = getFileDownloadUrl(userData.avatar, 'thumb');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
sessionId,
|
|
63
|
+
userId,
|
|
64
|
+
username: userData.username || '',
|
|
65
|
+
displayName,
|
|
66
|
+
avatar: userData.avatar,
|
|
67
|
+
avatarUrl,
|
|
68
|
+
};
|
|
69
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal interface for services that can update asset visibility.
|
|
3
|
+
* Kept loose to avoid mixin type-inference issues with the OxyServices class.
|
|
4
|
+
*/
|
|
5
|
+
export interface AssetVisibilityService {
|
|
6
|
+
assetUpdateVisibility(fileId: string, visibility: 'private' | 'public' | 'unlisted'): Promise<unknown>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Updates file visibility to public for avatar use.
|
|
11
|
+
* Logs non-404 errors to help debug upload issues.
|
|
12
|
+
*
|
|
13
|
+
* @param fileId - The file ID to update visibility for
|
|
14
|
+
* @param oxyServices - OxyServices instance (or any object with assetUpdateVisibility)
|
|
15
|
+
* @param contextName - Context name for error logging
|
|
16
|
+
*/
|
|
17
|
+
export async function updateAvatarVisibility(
|
|
18
|
+
fileId: string | undefined,
|
|
19
|
+
oxyServices: AssetVisibilityService,
|
|
20
|
+
contextName: string = 'AvatarUtils'
|
|
21
|
+
): Promise<void> {
|
|
22
|
+
if (!fileId || fileId.startsWith('temp-')) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
await oxyServices.assetUpdateVisibility(fileId, 'public');
|
|
28
|
+
} catch (visError: unknown) {
|
|
29
|
+
// 404 is expected when asset doesn't exist yet — skip logging
|
|
30
|
+
const status = (visError instanceof Error && 'status' in visError)
|
|
31
|
+
? (visError as Error & { status: number }).status
|
|
32
|
+
: undefined;
|
|
33
|
+
if (status !== 404) {
|
|
34
|
+
console.error(`[${contextName}] Failed to update avatar visibility for ${fileId}:`, visError);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|