@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/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
  // ---------------------------------------------------------------------------
@@ -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
- }