@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/cjs/index.js CHANGED
@@ -18,10 +18,10 @@
18
18
  * If a symbol does not appear here, it is NOT part of the public API.
19
19
  */
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.withOpacity = exports.rgbToHex = exports.hexToRgb = exports.lightenColor = exports.darkenColor = exports.isAndroid = exports.isIOS = exports.isNative = exports.isWeb = exports.setPlatformOS = exports.getPlatformOS = exports.isRTLLocale = exports.normalizeLanguageCode = exports.getNativeLanguageName = exports.getLanguageName = exports.getLanguageMetadata = exports.SUPPORTED_LANGUAGES = exports.TopicSource = exports.TopicType = exports.SECURITY_EVENT_SEVERITY_MAP = exports.DeviceManager = exports.RecoveryPhraseService = exports.SignatureService = exports.IdentityPersistError = exports.IdentityAlreadyExistsError = exports.KeyManager = exports.sessionsArraysEqual = exports.normalizeAndSortSessions = exports.mergeSessions = exports.authenticatedApiCall = exports.withAuthErrorHandling = exports.isAuthenticationError = exports.ensureValidToken = exports.AuthenticationFailedError = exports.SessionSyncRequiredError = exports.normalizeUserIdentityOrNull = exports.normalizeUserIdentity = exports.getNormalizedUserId = exports.getCanonicalUserHandle = exports.OxyAppDataIdentifierError = exports.ServiceCredentialMismatchError = exports.createCrossDomainAuth = exports.CrossDomainAuth = exports.createAuthManager = exports.AuthManager = exports.oxyClient = exports.OXY_CLOUD_URL = exports.OxyAuthenticationTimeoutError = exports.OxyAuthenticationError = exports.OxyServices = void 0;
22
- exports.isRequiredBoolean = exports.isRequiredNumber = exports.isRequiredString = exports.isValidPassword = exports.isValidUsername = exports.isValidEmail = exports.PASSWORD_REGEX = exports.USERNAME_REGEX = exports.EMAIL_REGEX = exports.retryAsync = exports.validateRequiredFields = exports.handleHttpError = exports.createApiError = exports.ErrorCodes = exports.safeJsonParse = exports.buildPaginationParams = exports.buildUrl = exports.buildSearchParams = exports.translate = exports.createDebugLogger = exports.debugError = exports.debugWarn = exports.debugLog = exports.isDev = exports.withRetry = exports.delay = exports.shouldAllowRequest = exports.recordSuccess = exports.recordFailure = exports.calculateBackoffInterval = exports.createCircuitBreakerState = exports.DEFAULT_CIRCUIT_BREAKER_CONFIG = exports.isRetryableError = exports.isNetworkError = exports.isServerError = exports.isRateLimitError = exports.isNotFoundError = exports.isForbiddenError = exports.isUnauthorizedError = exports.isAlreadyRegisteredError = exports.getErrorMessage = exports.getErrorStatus = exports.HttpStatus = exports.getSystemColorScheme = exports.systemPrefersDarkMode = exports.getOppositeTheme = exports.normalizeColorScheme = exports.normalizeTheme = exports.getContrastTextColor = exports.isLightColor = void 0;
23
- exports.guardActive = exports.isCentralIdPOrigin = exports.buildSsoBounceUrl = exports.getSsoCallbackBootstrapScript = exports.ssoNavigate = exports.ssoCallbackBootstrapKey = exports.ssoAttemptedKey = exports.ssoNoSessionKey = exports.ssoDestKey = exports.ssoGuardKey = exports.ssoStateKey = exports.SSO_GUARD_TTL_MS = exports.SSO_CALLBACK_PATH = exports.generateSsoState = exports.consumeSsoReturn = exports.parseSsoReturnFragment = exports.resolveCentralAuthUrl = exports.CENTRAL_IDP_APEX = exports.CENTRAL_AUTH_URL = exports.MULTIPART_TLDS = exports.registrableApex = exports.autoDetectAuthWebUrl = exports.getAccountColor = exports.mergeAccountsFromRefreshAll = exports.formatPublicKeyHandle = exports.getAccountFallbackHandle = exports.getAccountDisplayName = exports.createQuickAccount = exports.buildAccountsArray = exports.updateAvatarVisibility = exports.logPerformance = exports.logPayment = exports.logDevice = exports.logUser = exports.logSession = exports.logApi = exports.logAuth = exports.LogLevel = exports.logger = exports.validateAndSanitizeUserInput = exports.isValidObjectId = exports.sanitizeHTML = exports.sanitizeString = exports.isValidFileType = exports.isValidFileSize = exports.isValidDate = exports.isValidURL = exports.isValidUUID = exports.isValidObject = exports.isValidArray = void 0;
24
- exports.packageInfo = exports.runColdBoot = void 0;
21
+ exports.rgbToHex = exports.hexToRgb = exports.lightenColor = exports.darkenColor = exports.isAndroid = exports.isIOS = exports.isNative = exports.isWeb = exports.setPlatformOS = exports.getPlatformOS = exports.isRTLLocale = exports.normalizeLanguageCode = exports.getNativeLanguageName = exports.getLanguageName = exports.getLanguageMetadata = exports.SUPPORTED_LANGUAGES = exports.TopicSource = exports.TopicType = exports.SECURITY_EVENT_SEVERITY_MAP = exports.DeviceManager = exports.RecoveryPhraseService = exports.SignatureService = exports.IdentityPersistError = exports.IdentityAlreadyExistsError = exports.KeyManager = exports.sessionsArraysEqual = exports.normalizeAndSortSessions = exports.mergeSessions = exports.authenticatedApiCall = exports.withAuthErrorHandling = exports.isAuthenticationError = exports.ensureValidToken = exports.AuthenticationFailedError = exports.SessionSyncRequiredError = exports.getNormalizedUserHandle = exports.getCanonicalUserHandle = exports.normalizeUserIdentityOrNull = exports.normalizeUserIdentity = exports.getNormalizedUserId = exports.OxyAppDataIdentifierError = exports.ServiceCredentialMismatchError = exports.createCrossDomainAuth = exports.CrossDomainAuth = exports.createAuthManager = exports.AuthManager = exports.oxyClient = exports.OXY_CLOUD_URL = exports.OxyAuthenticationTimeoutError = exports.OxyAuthenticationError = exports.OxyServices = void 0;
22
+ exports.isRequiredNumber = exports.isRequiredString = exports.isValidPassword = exports.isValidUsername = exports.isValidEmail = exports.PASSWORD_REGEX = exports.USERNAME_REGEX = exports.EMAIL_REGEX = exports.retryAsync = exports.validateRequiredFields = exports.handleHttpError = exports.createApiError = exports.ErrorCodes = exports.safeJsonParse = exports.buildPaginationParams = exports.buildUrl = exports.buildSearchParams = exports.translate = exports.createDebugLogger = exports.debugError = exports.debugWarn = exports.debugLog = exports.isDev = exports.withRetry = exports.delay = exports.shouldAllowRequest = exports.recordSuccess = exports.recordFailure = exports.calculateBackoffInterval = exports.createCircuitBreakerState = exports.DEFAULT_CIRCUIT_BREAKER_CONFIG = exports.isRetryableError = exports.isNetworkError = exports.isServerError = exports.isRateLimitError = exports.isNotFoundError = exports.isForbiddenError = exports.isUnauthorizedError = exports.isAlreadyRegisteredError = exports.getErrorMessage = exports.getErrorStatus = exports.HttpStatus = exports.getSystemColorScheme = exports.systemPrefersDarkMode = exports.getOppositeTheme = exports.normalizeColorScheme = exports.normalizeTheme = exports.getContrastTextColor = exports.isLightColor = exports.withOpacity = void 0;
23
+ exports.isCentralIdPOrigin = exports.buildSsoBounceUrl = exports.getSsoCallbackBootstrapScript = exports.ssoNavigate = exports.ssoCallbackBootstrapKey = exports.ssoAttemptedKey = exports.ssoNoSessionKey = exports.ssoDestKey = exports.ssoGuardKey = exports.ssoStateKey = exports.SSO_GUARD_TTL_MS = exports.SSO_CALLBACK_PATH = exports.generateSsoState = exports.consumeSsoReturn = exports.parseSsoReturnFragment = exports.resolveCentralAuthUrl = exports.CENTRAL_IDP_APEX = exports.CENTRAL_AUTH_URL = exports.MULTIPART_TLDS = exports.registrableApex = exports.autoDetectAuthWebUrl = exports.getAccountColor = exports.mergeAccountsFromRefreshAll = exports.formatPublicKeyHandle = exports.getAccountFallbackHandle = exports.getAccountDisplayName = exports.createQuickAccount = exports.buildAccountsArray = exports.updateAvatarVisibility = exports.logPerformance = exports.logPayment = exports.logDevice = exports.logUser = exports.logSession = exports.logApi = exports.logAuth = exports.LogLevel = exports.logger = exports.validateAndSanitizeUserInput = exports.isValidObjectId = exports.sanitizeHTML = exports.sanitizeString = exports.isValidFileType = exports.isValidFileSize = exports.isValidDate = exports.isValidURL = exports.isValidUUID = exports.isValidObject = exports.isValidArray = exports.isRequiredBoolean = void 0;
24
+ exports.packageInfo = exports.runColdBoot = exports.guardActive = void 0;
25
25
  // Ensure crypto polyfills are loaded before anything else
26
26
  require("./crypto/polyfill");
27
27
  // ---------------------------------------------------------------------------
@@ -47,11 +47,16 @@ var OxyServices_auth_1 = require("./mixins/OxyServices.auth");
47
47
  Object.defineProperty(exports, "ServiceCredentialMismatchError", { enumerable: true, get: function () { return OxyServices_auth_1.ServiceCredentialMismatchError; } });
48
48
  var OxyServices_appData_1 = require("./mixins/OxyServices.appData");
49
49
  Object.defineProperty(exports, "OxyAppDataIdentifierError", { enumerable: true, get: function () { return OxyServices_appData_1.OxyAppDataIdentifierError; } });
50
+ // ---------------------------------------------------------------------------
51
+ // User identity and handles
52
+ // ---------------------------------------------------------------------------
50
53
  var userIdentity_1 = require("./utils/userIdentity");
51
- Object.defineProperty(exports, "getCanonicalUserHandle", { enumerable: true, get: function () { return userIdentity_1.getCanonicalUserHandle; } });
52
54
  Object.defineProperty(exports, "getNormalizedUserId", { enumerable: true, get: function () { return userIdentity_1.getNormalizedUserId; } });
53
55
  Object.defineProperty(exports, "normalizeUserIdentity", { enumerable: true, get: function () { return userIdentity_1.normalizeUserIdentity; } });
54
56
  Object.defineProperty(exports, "normalizeUserIdentityOrNull", { enumerable: true, get: function () { return userIdentity_1.normalizeUserIdentityOrNull; } });
57
+ var userHandle_1 = require("./utils/userHandle");
58
+ Object.defineProperty(exports, "getCanonicalUserHandle", { enumerable: true, get: function () { return userHandle_1.getCanonicalUserHandle; } });
59
+ Object.defineProperty(exports, "getNormalizedUserHandle", { enumerable: true, get: function () { return userHandle_1.getNormalizedUserHandle; } });
55
60
  // ---------------------------------------------------------------------------
56
61
  // Auth helpers (token refresh, error normalisation, retry policies)
57
62
  // ---------------------------------------------------------------------------
@@ -21,13 +21,9 @@ exports.formatPublicKeyHandle = formatPublicKeyHandle;
21
21
  * Resolve a friendly display name for a user.
22
22
  *
23
23
  * Order of preference:
24
- * 1. `name.full`, or composed `name.first name.last` (FIRST-NAME-ONLY SAFE —
25
- * a user with only a first name resolves to that first name, never to the
26
- * lowercase username; this is the exact drift bug the auth app hit).
27
- * 2. `name` (when stored as a plain string)
28
- * 3. `displayName` (server `displayName` virtual — `username || truncatedKey`).
29
- * Placed AFTER the structured name on purpose: the server virtual ignores
30
- * `name`, so preferring it first would re-introduce the first-only bug.
24
+ * 1. `displayName` from the API contract.
25
+ * 2. `name.full`, or composed `name.first name.last` for local unsaved shapes.
26
+ * 3. `name` when stored as a plain string.
31
27
  * 4. `username`
32
28
  * 5. `Account 0x12345678…` (derived from publicKey, when present)
33
29
  * 6. Translated fallback (e.g. "Unnamed")
@@ -39,6 +35,8 @@ const getAccountDisplayName = (user, locale) => {
39
35
  if (!user)
40
36
  return (0, i18n_1.translate)(locale, 'common.unnamed');
41
37
  const { name, displayName, username, publicKey } = user;
38
+ if (typeof displayName === 'string' && displayName.trim())
39
+ return displayName.trim();
42
40
  if (name && typeof name === 'object') {
43
41
  if (typeof name.full === 'string' && name.full.trim())
44
42
  return name.full.trim();
@@ -51,8 +49,6 @@ const getAccountDisplayName = (user, locale) => {
51
49
  else if (typeof name === 'string' && name.trim()) {
52
50
  return name.trim();
53
51
  }
54
- if (typeof displayName === 'string' && displayName.trim())
55
- return displayName.trim();
56
52
  if (typeof username === 'string' && username.trim())
57
53
  return username.trim();
58
54
  if (typeof publicKey === 'string' && publicKey.length > 0) {
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getNormalizedUserHandle = getNormalizedUserHandle;
4
+ exports.getCanonicalUserHandle = getCanonicalUserHandle;
5
+ function normalizeHandlePart(value) {
6
+ const trimmed = value?.trim().replace(/^@+/, '');
7
+ if (!trimmed || /[/?#]/.test(trimmed))
8
+ return null;
9
+ return trimmed;
10
+ }
11
+ /**
12
+ * Returns the normalized profile handle used by Oxy consumers for display and
13
+ * profile routing.
14
+ *
15
+ * Local users resolve to `username`. Federated users resolve to
16
+ * `username@instance` when the username does not already include an instance.
17
+ * Route-like values are rejected so callers do not accidentally turn paths or
18
+ * query strings into profile destinations.
19
+ */
20
+ function getNormalizedUserHandle(user) {
21
+ const username = normalizeHandlePart(user?.username ?? user?.handle);
22
+ if (!username)
23
+ return null;
24
+ const isFederated = user?.isFederated === true || user?.type === 'federated';
25
+ const instance = normalizeHandlePart(user?.instance ?? user?.federation?.domain);
26
+ if (isFederated && instance && !username.includes('@')) {
27
+ return `${username}@${instance}`;
28
+ }
29
+ return username;
30
+ }
31
+ /**
32
+ * Compatibility alias for the first public name shipped with this helper.
33
+ * Prefer {@link getNormalizedUserHandle} in new code.
34
+ */
35
+ function getCanonicalUserHandle(user) {
36
+ return getNormalizedUserHandle(user);
37
+ }
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getNormalizedUserId = getNormalizedUserId;
4
4
  exports.normalizeUserIdentity = normalizeUserIdentity;
5
5
  exports.normalizeUserIdentityOrNull = normalizeUserIdentityOrNull;
6
- exports.getCanonicalUserHandle = getCanonicalUserHandle;
7
6
  function stringifyIdentity(value) {
8
7
  if (typeof value === 'string') {
9
8
  const trimmed = value.trim();
@@ -24,18 +23,21 @@ function stringifyIdentity(value) {
24
23
  }
25
24
  return null;
26
25
  }
27
- function normalizeHandle(value) {
28
- const trimmed = value?.trim().replace(/^@+/, '');
29
- if (!trimmed || /[/?#]/.test(trimmed))
30
- return null;
31
- return trimmed;
32
- }
26
+ /**
27
+ * Returns the stable SDK user id from API payloads that may use either `id` or
28
+ * Mongo-style `_id`.
29
+ */
33
30
  function getNormalizedUserId(user) {
34
31
  if (!user) {
35
32
  return null;
36
33
  }
37
34
  return stringifyIdentity(user.id) ?? stringifyIdentity(user._id);
38
35
  }
36
+ /**
37
+ * Normalizes a user payload to always expose `id`. Throws when the payload does
38
+ * not contain a usable id, because SDK callers should never receive anonymous
39
+ * user objects from authenticated identity endpoints.
40
+ */
39
41
  function normalizeUserIdentity(user) {
40
42
  const id = getNormalizedUserId(user);
41
43
  if (!id) {
@@ -46,14 +48,3 @@ function normalizeUserIdentity(user) {
46
48
  function normalizeUserIdentityOrNull(user) {
47
49
  return user ? normalizeUserIdentity(user) : null;
48
50
  }
49
- function getCanonicalUserHandle(user) {
50
- const username = normalizeHandle(user?.username ?? user?.handle);
51
- if (!username)
52
- return null;
53
- const isFederated = user?.isFederated === true || user?.type === 'federated';
54
- const instance = normalizeHandle(user?.instance ?? user?.federation?.domain);
55
- if (isFederated && instance && !username.includes('@')) {
56
- return `${username}@${instance}`;
57
- }
58
- return username;
59
- }