@oxyhq/core 3.4.13 → 3.4.14
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 -1
- package/dist/cjs/index.js +5 -4
- package/dist/cjs/utils/userIdentity.js +18 -0
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/utils/userIdentity.js +17 -0
- package/dist/types/.tsbuildinfo +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/utils/userIdentity.d.ts +11 -0
- package/package.json +1 -1
- package/src/__tests__/userIdentity.test.ts +46 -1
- package/src/index.ts +7 -1
- package/src/utils/userIdentity.ts +31 -0
package/dist/esm/index.js
CHANGED
|
@@ -30,7 +30,7 @@ export { AuthManager, createAuthManager } from './AuthManager.js';
|
|
|
30
30
|
export { CrossDomainAuth, createCrossDomainAuth } from './CrossDomainAuth.js';
|
|
31
31
|
export { ServiceCredentialMismatchError } from './mixins/OxyServices.auth.js';
|
|
32
32
|
export { OxyAppDataIdentifierError } from './mixins/OxyServices.appData.js';
|
|
33
|
-
export { getNormalizedUserId, normalizeUserIdentity, normalizeUserIdentityOrNull } from './utils/userIdentity.js';
|
|
33
|
+
export { getCanonicalUserHandle, getNormalizedUserId, normalizeUserIdentity, normalizeUserIdentityOrNull, } from './utils/userIdentity.js';
|
|
34
34
|
// ---------------------------------------------------------------------------
|
|
35
35
|
// Auth helpers (token refresh, error normalisation, retry policies)
|
|
36
36
|
// ---------------------------------------------------------------------------
|
|
@@ -18,6 +18,12 @@ function stringifyIdentity(value) {
|
|
|
18
18
|
}
|
|
19
19
|
return null;
|
|
20
20
|
}
|
|
21
|
+
function normalizeHandle(value) {
|
|
22
|
+
const trimmed = value?.trim().replace(/^@+/, '');
|
|
23
|
+
if (!trimmed || /[/?#]/.test(trimmed))
|
|
24
|
+
return null;
|
|
25
|
+
return trimmed;
|
|
26
|
+
}
|
|
21
27
|
export function getNormalizedUserId(user) {
|
|
22
28
|
if (!user) {
|
|
23
29
|
return null;
|
|
@@ -34,3 +40,14 @@ export function normalizeUserIdentity(user) {
|
|
|
34
40
|
export function normalizeUserIdentityOrNull(user) {
|
|
35
41
|
return user ? normalizeUserIdentity(user) : null;
|
|
36
42
|
}
|
|
43
|
+
export function getCanonicalUserHandle(user) {
|
|
44
|
+
const username = normalizeHandle(user?.username ?? user?.handle);
|
|
45
|
+
if (!username)
|
|
46
|
+
return null;
|
|
47
|
+
const isFederated = user?.isFederated === true || user?.type === 'federated';
|
|
48
|
+
const instance = normalizeHandle(user?.instance ?? user?.federation?.domain);
|
|
49
|
+
if (isFederated && instance && !username.includes('@')) {
|
|
50
|
+
return `${username}@${instance}`;
|
|
51
|
+
}
|
|
52
|
+
return username;
|
|
53
|
+
}
|