@oxyhq/core 3.4.14 → 3.4.16

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/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
- export { getCanonicalUserHandle, getNormalizedUserId, normalizeUserIdentity, normalizeUserIdentityOrNull, } from './utils/userIdentity.js';
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
  // ---------------------------------------------------------------------------
@@ -17,13 +17,9 @@ export const formatPublicKeyHandle = (publicKey) => {
17
17
  * Resolve a friendly display name for a user.
18
18
  *
19
19
  * Order of preference:
20
- * 1. `name.full`, or composed `name.first name.last` (FIRST-NAME-ONLY SAFE —
21
- * a user with only a first name resolves to that first name, never to the
22
- * lowercase username; this is the exact drift bug the auth app hit).
23
- * 2. `name` (when stored as a plain string)
24
- * 3. `displayName` (server `displayName` virtual — `username || truncatedKey`).
25
- * Placed AFTER the structured name on purpose: the server virtual ignores
26
- * `name`, so preferring it first would re-introduce the first-only bug.
20
+ * 1. `displayName` from the API contract.
21
+ * 2. `name.full`, or composed `name.first name.last` for local unsaved shapes.
22
+ * 3. `name` when stored as a plain string.
27
23
  * 4. `username`
28
24
  * 5. `Account 0x12345678…` (derived from publicKey, when present)
29
25
  * 6. Translated fallback (e.g. "Unnamed")
@@ -35,6 +31,8 @@ export const getAccountDisplayName = (user, locale) => {
35
31
  if (!user)
36
32
  return translate(locale, 'common.unnamed');
37
33
  const { name, displayName, username, publicKey } = user;
34
+ if (typeof displayName === 'string' && displayName.trim())
35
+ return displayName.trim();
38
36
  if (name && typeof name === 'object') {
39
37
  if (typeof name.full === 'string' && name.full.trim())
40
38
  return name.full.trim();
@@ -47,8 +45,6 @@ export const getAccountDisplayName = (user, locale) => {
47
45
  else if (typeof name === 'string' && name.trim()) {
48
46
  return name.trim();
49
47
  }
50
- if (typeof displayName === 'string' && displayName.trim())
51
- return displayName.trim();
52
48
  if (typeof username === 'string' && username.trim())
53
49
  return username.trim();
54
50
  if (typeof publicKey === 'string' && publicKey.length > 0) {
@@ -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
- function normalizeHandle(value) {
22
- const trimmed = value?.trim().replace(/^@+/, '');
23
- if (!trimmed || /[/?#]/.test(trimmed))
24
- return null;
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
- }