@oxyhq/core 3.4.14 → 3.4.15
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/README.md +25 -2
- package/dist/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/index.js +10 -5
- package/dist/cjs/utils/userHandle.js +37 -0
- package/dist/cjs/utils/userIdentity.js +9 -18
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/index.js +5 -1
- package/dist/esm/utils/userHandle.js +33 -0
- package/dist/esm/utils/userIdentity.js +9 -17
- package/dist/types/.tsbuildinfo +1 -1
- package/dist/types/index.d.ts +3 -2
- package/dist/types/utils/userHandle.d.ts +26 -0
- package/dist/types/utils/userIdentity.d.ts +9 -11
- package/package.json +1 -1
- package/src/__tests__/userIdentity.test.ts +37 -12
- package/src/index.ts +9 -2
- package/src/utils/asyncUtils.ts +1 -2
- package/src/utils/userHandle.ts +49 -0
- package/src/utils/userIdentity.ts +9 -31
package/dist/esm/index.js
CHANGED
|
@@ -30,7 +30,11 @@ 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
|
-
|
|
33
|
+
// ---------------------------------------------------------------------------
|
|
34
|
+
// User identity and handles
|
|
35
|
+
// ---------------------------------------------------------------------------
|
|
36
|
+
export { getNormalizedUserId, normalizeUserIdentity, normalizeUserIdentityOrNull, } from './utils/userIdentity.js';
|
|
37
|
+
export { getCanonicalUserHandle, getNormalizedUserHandle, } from './utils/userHandle.js';
|
|
34
38
|
// ---------------------------------------------------------------------------
|
|
35
39
|
// Auth helpers (token refresh, error normalisation, retry policies)
|
|
36
40
|
// ---------------------------------------------------------------------------
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
function normalizeHandlePart(value) {
|
|
2
|
+
const trimmed = value?.trim().replace(/^@+/, '');
|
|
3
|
+
if (!trimmed || /[/?#]/.test(trimmed))
|
|
4
|
+
return null;
|
|
5
|
+
return trimmed;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Returns the normalized profile handle used by Oxy consumers for display and
|
|
9
|
+
* profile routing.
|
|
10
|
+
*
|
|
11
|
+
* Local users resolve to `username`. Federated users resolve to
|
|
12
|
+
* `username@instance` when the username does not already include an instance.
|
|
13
|
+
* Route-like values are rejected so callers do not accidentally turn paths or
|
|
14
|
+
* query strings into profile destinations.
|
|
15
|
+
*/
|
|
16
|
+
export function getNormalizedUserHandle(user) {
|
|
17
|
+
const username = normalizeHandlePart(user?.username ?? user?.handle);
|
|
18
|
+
if (!username)
|
|
19
|
+
return null;
|
|
20
|
+
const isFederated = user?.isFederated === true || user?.type === 'federated';
|
|
21
|
+
const instance = normalizeHandlePart(user?.instance ?? user?.federation?.domain);
|
|
22
|
+
if (isFederated && instance && !username.includes('@')) {
|
|
23
|
+
return `${username}@${instance}`;
|
|
24
|
+
}
|
|
25
|
+
return username;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Compatibility alias for the first public name shipped with this helper.
|
|
29
|
+
* Prefer {@link getNormalizedUserHandle} in new code.
|
|
30
|
+
*/
|
|
31
|
+
export function getCanonicalUserHandle(user) {
|
|
32
|
+
return getNormalizedUserHandle(user);
|
|
33
|
+
}
|
|
@@ -18,18 +18,21 @@ function stringifyIdentity(value) {
|
|
|
18
18
|
}
|
|
19
19
|
return null;
|
|
20
20
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return trimmed;
|
|
26
|
-
}
|
|
21
|
+
/**
|
|
22
|
+
* Returns the stable SDK user id from API payloads that may use either `id` or
|
|
23
|
+
* Mongo-style `_id`.
|
|
24
|
+
*/
|
|
27
25
|
export function getNormalizedUserId(user) {
|
|
28
26
|
if (!user) {
|
|
29
27
|
return null;
|
|
30
28
|
}
|
|
31
29
|
return stringifyIdentity(user.id) ?? stringifyIdentity(user._id);
|
|
32
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Normalizes a user payload to always expose `id`. Throws when the payload does
|
|
33
|
+
* not contain a usable id, because SDK callers should never receive anonymous
|
|
34
|
+
* user objects from authenticated identity endpoints.
|
|
35
|
+
*/
|
|
33
36
|
export function normalizeUserIdentity(user) {
|
|
34
37
|
const id = getNormalizedUserId(user);
|
|
35
38
|
if (!id) {
|
|
@@ -40,14 +43,3 @@ export function normalizeUserIdentity(user) {
|
|
|
40
43
|
export function normalizeUserIdentityOrNull(user) {
|
|
41
44
|
return user ? normalizeUserIdentity(user) : null;
|
|
42
45
|
}
|
|
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
|
-
}
|