@oxyhq/core 1.11.24 → 2.0.0

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.
Files changed (140) hide show
  1. package/README.md +5 -6
  2. package/dist/cjs/.tsbuildinfo +1 -1
  3. package/dist/cjs/AuthManager.js +678 -4
  4. package/dist/cjs/AuthManagerTypes.js +13 -0
  5. package/dist/cjs/CrossDomainAuth.js +45 -3
  6. package/dist/cjs/OxyServices.base.js +16 -0
  7. package/dist/cjs/i18n/locales/ar-SA.json +83 -0
  8. package/dist/cjs/i18n/locales/ca-ES.json +83 -0
  9. package/dist/cjs/i18n/locales/de-DE.json +83 -0
  10. package/dist/cjs/i18n/locales/en-US.json +83 -0
  11. package/dist/cjs/i18n/locales/es-ES.json +99 -4
  12. package/dist/cjs/i18n/locales/fr-FR.json +83 -0
  13. package/dist/cjs/i18n/locales/it-IT.json +83 -0
  14. package/dist/cjs/i18n/locales/ja-JP.json +83 -0
  15. package/dist/cjs/i18n/locales/ko-KR.json +83 -0
  16. package/dist/cjs/i18n/locales/locales/ar-SA.json +83 -1
  17. package/dist/cjs/i18n/locales/locales/ca-ES.json +83 -1
  18. package/dist/cjs/i18n/locales/locales/de-DE.json +83 -1
  19. package/dist/cjs/i18n/locales/locales/en-US.json +83 -0
  20. package/dist/cjs/i18n/locales/locales/es-ES.json +99 -4
  21. package/dist/cjs/i18n/locales/locales/fr-FR.json +83 -1
  22. package/dist/cjs/i18n/locales/locales/it-IT.json +83 -1
  23. package/dist/cjs/i18n/locales/locales/ja-JP.json +200 -117
  24. package/dist/cjs/i18n/locales/locales/ko-KR.json +83 -1
  25. package/dist/cjs/i18n/locales/locales/pt-PT.json +83 -1
  26. package/dist/cjs/i18n/locales/locales/zh-CN.json +83 -1
  27. package/dist/cjs/i18n/locales/pt-PT.json +83 -0
  28. package/dist/cjs/i18n/locales/zh-CN.json +83 -0
  29. package/dist/cjs/index.js +114 -57
  30. package/dist/cjs/mixins/OxyServices.auth.js +235 -0
  31. package/dist/cjs/mixins/OxyServices.fedcm.js +36 -0
  32. package/dist/cjs/mixins/OxyServices.popup.js +61 -1
  33. package/dist/cjs/mixins/OxyServices.user.js +18 -0
  34. package/dist/cjs/utils/accountUtils.js +64 -1
  35. package/dist/esm/.tsbuildinfo +1 -1
  36. package/dist/esm/AuthManager.js +678 -4
  37. package/dist/esm/AuthManagerTypes.js +12 -0
  38. package/dist/esm/CrossDomainAuth.js +45 -3
  39. package/dist/esm/OxyServices.base.js +16 -0
  40. package/dist/esm/i18n/locales/ar-SA.json +83 -0
  41. package/dist/esm/i18n/locales/ca-ES.json +83 -0
  42. package/dist/esm/i18n/locales/de-DE.json +83 -0
  43. package/dist/esm/i18n/locales/en-US.json +83 -0
  44. package/dist/esm/i18n/locales/es-ES.json +99 -4
  45. package/dist/esm/i18n/locales/fr-FR.json +83 -0
  46. package/dist/esm/i18n/locales/it-IT.json +83 -0
  47. package/dist/esm/i18n/locales/ja-JP.json +83 -0
  48. package/dist/esm/i18n/locales/ko-KR.json +83 -0
  49. package/dist/esm/i18n/locales/locales/ar-SA.json +83 -1
  50. package/dist/esm/i18n/locales/locales/ca-ES.json +83 -1
  51. package/dist/esm/i18n/locales/locales/de-DE.json +83 -1
  52. package/dist/esm/i18n/locales/locales/en-US.json +83 -0
  53. package/dist/esm/i18n/locales/locales/es-ES.json +99 -4
  54. package/dist/esm/i18n/locales/locales/fr-FR.json +83 -1
  55. package/dist/esm/i18n/locales/locales/it-IT.json +83 -1
  56. package/dist/esm/i18n/locales/locales/ja-JP.json +200 -117
  57. package/dist/esm/i18n/locales/locales/ko-KR.json +83 -1
  58. package/dist/esm/i18n/locales/locales/pt-PT.json +83 -1
  59. package/dist/esm/i18n/locales/locales/zh-CN.json +83 -1
  60. package/dist/esm/i18n/locales/pt-PT.json +83 -0
  61. package/dist/esm/i18n/locales/zh-CN.json +83 -0
  62. package/dist/esm/index.js +69 -26
  63. package/dist/esm/mixins/OxyServices.auth.js +235 -0
  64. package/dist/esm/mixins/OxyServices.fedcm.js +36 -0
  65. package/dist/esm/mixins/OxyServices.popup.js +61 -1
  66. package/dist/esm/mixins/OxyServices.user.js +18 -0
  67. package/dist/esm/utils/accountUtils.js +61 -0
  68. package/dist/types/.tsbuildinfo +1 -1
  69. package/dist/types/AuthManager.d.ts +243 -3
  70. package/dist/types/AuthManagerTypes.d.ts +68 -0
  71. package/dist/types/CrossDomainAuth.d.ts +23 -0
  72. package/dist/types/OxyServices.base.d.ts +14 -0
  73. package/dist/types/OxyServices.d.ts +7 -0
  74. package/dist/types/index.d.ts +28 -17
  75. package/dist/types/mixins/OxyServices.analytics.d.ts +1 -0
  76. package/dist/types/mixins/OxyServices.appData.d.ts +1 -0
  77. package/dist/types/mixins/OxyServices.assets.d.ts +4 -1
  78. package/dist/types/mixins/OxyServices.auth.d.ts +73 -1
  79. package/dist/types/mixins/OxyServices.contacts.d.ts +1 -0
  80. package/dist/types/mixins/OxyServices.developer.d.ts +1 -0
  81. package/dist/types/mixins/OxyServices.devices.d.ts +1 -0
  82. package/dist/types/mixins/OxyServices.features.d.ts +2 -5
  83. package/dist/types/mixins/OxyServices.fedcm.d.ts +34 -0
  84. package/dist/types/mixins/OxyServices.karma.d.ts +1 -0
  85. package/dist/types/mixins/OxyServices.language.d.ts +1 -0
  86. package/dist/types/mixins/OxyServices.location.d.ts +1 -0
  87. package/dist/types/mixins/OxyServices.managedAccounts.d.ts +1 -0
  88. package/dist/types/mixins/OxyServices.payment.d.ts +1 -0
  89. package/dist/types/mixins/OxyServices.popup.d.ts +40 -0
  90. package/dist/types/mixins/OxyServices.privacy.d.ts +1 -0
  91. package/dist/types/mixins/OxyServices.redirect.d.ts +1 -0
  92. package/dist/types/mixins/OxyServices.security.d.ts +1 -0
  93. package/dist/types/mixins/OxyServices.topics.d.ts +1 -0
  94. package/dist/types/mixins/OxyServices.user.d.ts +16 -1
  95. package/dist/types/mixins/OxyServices.utility.d.ts +1 -0
  96. package/dist/types/models/interfaces.d.ts +98 -0
  97. package/dist/types/models/session.d.ts +8 -0
  98. package/dist/types/utils/accountUtils.d.ts +33 -0
  99. package/package.json +9 -18
  100. package/src/AuthManager.ts +776 -7
  101. package/src/AuthManagerTypes.ts +72 -0
  102. package/src/CrossDomainAuth.ts +54 -3
  103. package/src/OxyServices.base.ts +17 -0
  104. package/src/OxyServices.ts +7 -0
  105. package/src/__tests__/authManager.cookiePath.test.ts +339 -0
  106. package/src/__tests__/authManager.security.test.ts +342 -0
  107. package/src/__tests__/crossDomainAuth.test.ts +191 -0
  108. package/src/i18n/locales/ar-SA.json +83 -1
  109. package/src/i18n/locales/ca-ES.json +83 -1
  110. package/src/i18n/locales/de-DE.json +83 -1
  111. package/src/i18n/locales/en-US.json +83 -0
  112. package/src/i18n/locales/es-ES.json +99 -4
  113. package/src/i18n/locales/fr-FR.json +83 -1
  114. package/src/i18n/locales/it-IT.json +83 -1
  115. package/src/i18n/locales/ja-JP.json +200 -117
  116. package/src/i18n/locales/ko-KR.json +83 -1
  117. package/src/i18n/locales/pt-PT.json +83 -1
  118. package/src/i18n/locales/zh-CN.json +83 -1
  119. package/src/index.ts +295 -112
  120. package/src/mixins/OxyServices.auth.ts +268 -1
  121. package/src/mixins/OxyServices.fedcm.ts +63 -0
  122. package/src/mixins/OxyServices.popup.ts +79 -1
  123. package/src/mixins/OxyServices.user.ts +33 -1
  124. package/src/mixins/__tests__/popup.test.ts +307 -0
  125. package/src/mixins/__tests__/sessionBaseUrl.test.ts +61 -0
  126. package/src/models/interfaces.ts +116 -0
  127. package/src/models/session.ts +8 -0
  128. package/src/utils/accountUtils.ts +84 -0
  129. package/dist/cjs/crypto/index.js +0 -22
  130. package/dist/cjs/shared/index.js +0 -70
  131. package/dist/cjs/utils/index.js +0 -26
  132. package/dist/esm/crypto/index.js +0 -13
  133. package/dist/esm/shared/index.js +0 -31
  134. package/dist/esm/utils/index.js +0 -7
  135. package/dist/types/crypto/index.d.ts +0 -11
  136. package/dist/types/shared/index.d.ts +0 -28
  137. package/dist/types/utils/index.d.ts +0 -6
  138. package/src/crypto/index.ts +0 -30
  139. package/src/shared/index.ts +0 -82
  140. package/src/utils/index.ts +0 -21
@@ -114,6 +114,89 @@
114
114
  "email": "Email",
115
115
  "password": "Palavra-passe",
116
116
  "confirmPassword": "Confirmar palavra-passe"
117
+ },
118
+ "revoke": "Revoke"
119
+ },
120
+ "notifications": {
121
+ "title": "Notifications",
122
+ "subtitle": "Manage push, email, and security alerts",
123
+ "updateError": "Failed to update notification preferences",
124
+ "sections": {
125
+ "channels": "Channels",
126
+ "alerts": "Alerts",
127
+ "marketing": "Marketing"
128
+ },
129
+ "items": {
130
+ "push": {
131
+ "title": "Push notifications",
132
+ "subtitle": "Real-time alerts on your devices"
133
+ },
134
+ "emailDigest": {
135
+ "title": "Email digest",
136
+ "subtitle": "Periodic summary of your account activity"
137
+ },
138
+ "securityAlerts": {
139
+ "title": "Security alerts",
140
+ "subtitle": "Sign-ins, recovery codes, and key changes"
141
+ },
142
+ "marketingEmails": {
143
+ "title": "Marketing emails",
144
+ "subtitle": "Product news and occasional offers"
145
+ }
146
+ }
147
+ },
148
+ "preferences": {
149
+ "title": "Preferences",
150
+ "subtitle": "Theme, motion, and regional settings",
151
+ "sections": {
152
+ "appearance": "Appearance",
153
+ "language": "Language",
154
+ "region": "Region"
155
+ },
156
+ "theme": {
157
+ "light": "Light",
158
+ "dark": "Dark",
159
+ "system": "System default"
160
+ },
161
+ "items": {
162
+ "theme": {
163
+ "title": "Theme"
164
+ },
165
+ "reduceMotion": {
166
+ "title": "Reduce motion",
167
+ "subtitle": "Minimise animations across Oxy apps",
168
+ "systemOn": "Following system: reduce motion is on"
169
+ },
170
+ "language": {
171
+ "title": "Language"
172
+ },
173
+ "timezone": {
174
+ "title": "Timezone",
175
+ "unknown": "Unable to detect timezone"
176
+ },
177
+ "about": {
178
+ "title": "About preferences",
179
+ "subtitle": "Preferences sync across every Oxy app you sign into"
180
+ }
181
+ }
182
+ },
183
+ "connectedApps": {
184
+ "title": "Connected apps",
185
+ "subtitle": "Manage third-party app access",
186
+ "empty": {
187
+ "title": "No connected apps",
188
+ "subtitle": "Apps you authorize to sign in with your Oxy account will appear here"
189
+ },
190
+ "item": {
191
+ "lastUsed": "Last used {{relative}}"
192
+ },
193
+ "confirm": {
194
+ "title": "Revoke access",
195
+ "message": "Revoke {{name}}'s access to your Oxy account?"
196
+ },
197
+ "toasts": {
198
+ "revoked": "Revoked access for {{name}}",
199
+ "revokeFailed": "Failed to revoke access"
117
200
  }
118
201
  }
119
202
  }
@@ -114,6 +114,89 @@
114
114
  "email": "电子邮件",
115
115
  "password": "密码",
116
116
  "confirmPassword": "确认密码"
117
+ },
118
+ "revoke": "Revoke"
119
+ },
120
+ "notifications": {
121
+ "title": "Notifications",
122
+ "subtitle": "Manage push, email, and security alerts",
123
+ "updateError": "Failed to update notification preferences",
124
+ "sections": {
125
+ "channels": "Channels",
126
+ "alerts": "Alerts",
127
+ "marketing": "Marketing"
128
+ },
129
+ "items": {
130
+ "push": {
131
+ "title": "Push notifications",
132
+ "subtitle": "Real-time alerts on your devices"
133
+ },
134
+ "emailDigest": {
135
+ "title": "Email digest",
136
+ "subtitle": "Periodic summary of your account activity"
137
+ },
138
+ "securityAlerts": {
139
+ "title": "Security alerts",
140
+ "subtitle": "Sign-ins, recovery codes, and key changes"
141
+ },
142
+ "marketingEmails": {
143
+ "title": "Marketing emails",
144
+ "subtitle": "Product news and occasional offers"
145
+ }
146
+ }
147
+ },
148
+ "preferences": {
149
+ "title": "Preferences",
150
+ "subtitle": "Theme, motion, and regional settings",
151
+ "sections": {
152
+ "appearance": "Appearance",
153
+ "language": "Language",
154
+ "region": "Region"
155
+ },
156
+ "theme": {
157
+ "light": "Light",
158
+ "dark": "Dark",
159
+ "system": "System default"
160
+ },
161
+ "items": {
162
+ "theme": {
163
+ "title": "Theme"
164
+ },
165
+ "reduceMotion": {
166
+ "title": "Reduce motion",
167
+ "subtitle": "Minimise animations across Oxy apps",
168
+ "systemOn": "Following system: reduce motion is on"
169
+ },
170
+ "language": {
171
+ "title": "Language"
172
+ },
173
+ "timezone": {
174
+ "title": "Timezone",
175
+ "unknown": "Unable to detect timezone"
176
+ },
177
+ "about": {
178
+ "title": "About preferences",
179
+ "subtitle": "Preferences sync across every Oxy app you sign into"
180
+ }
181
+ }
182
+ },
183
+ "connectedApps": {
184
+ "title": "Connected apps",
185
+ "subtitle": "Manage third-party app access",
186
+ "empty": {
187
+ "title": "No connected apps",
188
+ "subtitle": "Apps you authorize to sign in with your Oxy account will appear here"
189
+ },
190
+ "item": {
191
+ "lastUsed": "Last used {{relative}}"
192
+ },
193
+ "confirm": {
194
+ "title": "Revoke access",
195
+ "message": "Revoke {{name}}'s access to your Oxy account?"
196
+ },
197
+ "toasts": {
198
+ "revoked": "Revoked access for {{name}}",
199
+ "revokeFailed": "Failed to revoke access"
117
200
  }
118
201
  }
119
202
  }
package/dist/esm/index.js CHANGED
@@ -12,53 +12,96 @@
12
12
  *
13
13
  * const user = await oxyClient.signIn(publicKey);
14
14
  * ```
15
+ *
16
+ * Every export below is NOMINAL — no `export *`, no barrels, no compat shims.
17
+ * If a symbol does not appear here, it is NOT part of the public API.
15
18
  */
16
19
  // Ensure crypto polyfills are loaded before anything else
17
20
  import './crypto/polyfill.js';
18
- // --- Core API Client ---
21
+ // ---------------------------------------------------------------------------
22
+ // API client
23
+ // ---------------------------------------------------------------------------
19
24
  export { OxyServices, OxyAuthenticationError, OxyAuthenticationTimeoutError } from './OxyServices.js';
20
25
  export { OXY_CLOUD_URL, oxyClient } from './OxyServices.js';
21
- // --- Authentication ---
26
+ // ---------------------------------------------------------------------------
27
+ // Authentication
28
+ // ---------------------------------------------------------------------------
22
29
  export { AuthManager, createAuthManager } from './AuthManager.js';
23
30
  export { CrossDomainAuth, createCrossDomainAuth } from './CrossDomainAuth.js';
24
31
  export { ServiceCredentialMismatchError } from './mixins/OxyServices.auth.js';
25
32
  export { OxyAppDataIdentifierError } from './mixins/OxyServices.appData.js';
26
- // --- Crypto / Identity ---
27
- export { KeyManager, SignatureService, RecoveryPhraseService, IdentityAlreadyExistsError, IdentityPersistError, } from './crypto/index.js';
28
- // --- Models & Types ---
29
- export * from './models/interfaces.js';
30
- export * from './models/session.js';
31
- export { TopicType, TopicSource } from './models/Topic.js';
32
- // --- Device Management ---
33
+ // ---------------------------------------------------------------------------
34
+ // Auth helpers (token refresh, error normalisation, retry policies)
35
+ // ---------------------------------------------------------------------------
36
+ export { SessionSyncRequiredError, AuthenticationFailedError, ensureValidToken, isAuthenticationError, withAuthErrorHandling, authenticatedApiCall, } from './utils/authHelpers.js';
37
+ // ---------------------------------------------------------------------------
38
+ // Sessions
39
+ // ---------------------------------------------------------------------------
40
+ export { mergeSessions, normalizeAndSortSessions, sessionsArraysEqual, } from './utils/sessionUtils.js';
41
+ // ---------------------------------------------------------------------------
42
+ // Crypto / identity
43
+ // ---------------------------------------------------------------------------
44
+ export { KeyManager, IdentityAlreadyExistsError, IdentityPersistError, } from './crypto/keyManager.js';
45
+ export { SignatureService } from './crypto/signatureService.js';
46
+ export { RecoveryPhraseService } from './crypto/recoveryPhrase.js';
47
+ // ---------------------------------------------------------------------------
48
+ // Devices
49
+ // ---------------------------------------------------------------------------
33
50
  export { DeviceManager } from './utils/deviceManager.js';
34
- // --- Language Utilities ---
51
+ export { SECURITY_EVENT_SEVERITY_MAP } from './models/interfaces.js';
52
+ // Topic enums + type
53
+ export { TopicType, TopicSource } from './models/Topic.js';
54
+ // ---------------------------------------------------------------------------
55
+ // Languages
56
+ // ---------------------------------------------------------------------------
35
57
  export { SUPPORTED_LANGUAGES, getLanguageMetadata, getLanguageName, getNativeLanguageName, normalizeLanguageCode, isRTLLocale, } from './utils/languageUtils.js';
36
- // --- Platform Detection ---
58
+ // ---------------------------------------------------------------------------
59
+ // Platform detection
60
+ // ---------------------------------------------------------------------------
37
61
  export { getPlatformOS, setPlatformOS, isWeb, isNative, isIOS, isAndroid, } from './utils/platform.js';
38
- // --- Shared Utilities ---
62
+ // ---------------------------------------------------------------------------
63
+ // Colour / theme utilities
64
+ // ---------------------------------------------------------------------------
39
65
  export { darkenColor, lightenColor, hexToRgb, rgbToHex, withOpacity, isLightColor, getContrastTextColor, } from './shared/utils/colorUtils.js';
40
66
  export { normalizeTheme, normalizeColorScheme, getOppositeTheme, systemPrefersDarkMode, getSystemColorScheme, } from './shared/utils/themeUtils.js';
67
+ // ---------------------------------------------------------------------------
68
+ // HTTP / error / network helpers
69
+ // ---------------------------------------------------------------------------
41
70
  export { HttpStatus, getErrorStatus, getErrorMessage, isAlreadyRegisteredError, isUnauthorizedError, isForbiddenError, isNotFoundError, isRateLimitError, isServerError, isNetworkError, isRetryableError, } from './shared/utils/errorUtils.js';
42
71
  export { DEFAULT_CIRCUIT_BREAKER_CONFIG, createCircuitBreakerState, calculateBackoffInterval, recordFailure, recordSuccess, shouldAllowRequest, delay, withRetry, } from './shared/utils/networkUtils.js';
43
72
  export { isDev, debugLog, debugWarn, debugError, createDebugLogger, } from './shared/utils/debugUtils.js';
44
- // --- i18n ---
73
+ // ---------------------------------------------------------------------------
74
+ // i18n
75
+ // ---------------------------------------------------------------------------
45
76
  export { translate } from './i18n/index.js';
46
- // --- Auth Helpers ---
47
- export { SessionSyncRequiredError, AuthenticationFailedError, ensureValidToken, isAuthenticationError, withAuthErrorHandling, authenticatedApiCall, } from './utils/authHelpers.js';
48
- // --- Session Utilities ---
49
- export { mergeSessions, normalizeAndSortSessions, sessionsArraysEqual } from './utils/sessionUtils.js';
50
- // --- Constants ---
51
- export { packageInfo } from './constants/version.js';
52
- // --- API & Error Utilities ---
53
- export * from './utils/apiUtils.js';
77
+ // ---------------------------------------------------------------------------
78
+ // API request / URL helpers
79
+ // ---------------------------------------------------------------------------
80
+ export { buildSearchParams, buildUrl, buildPaginationParams, safeJsonParse, } from './utils/apiUtils.js';
54
81
  export { ErrorCodes, createApiError, handleHttpError, validateRequiredFields, } from './utils/errorUtils.js';
55
82
  export { retryAsync } from './utils/asyncUtils.js';
56
- export * from './utils/validationUtils.js';
83
+ // ---------------------------------------------------------------------------
84
+ // Validation
85
+ // ---------------------------------------------------------------------------
86
+ export { EMAIL_REGEX, USERNAME_REGEX, PASSWORD_REGEX, isValidEmail, isValidUsername, isValidPassword, isRequiredString, isRequiredNumber, isRequiredBoolean, isValidArray, isValidObject, isValidUUID, isValidURL, isValidDate, isValidFileSize, isValidFileType, sanitizeString, sanitizeHTML, isValidObjectId, validateAndSanitizeUserInput, } from './utils/validationUtils.js';
87
+ // ---------------------------------------------------------------------------
88
+ // Logging
89
+ // ---------------------------------------------------------------------------
57
90
  export { logger, LogLevel, logAuth, logApi, logSession, logUser, logDevice, logPayment, logPerformance, } from './utils/loggerUtils.js';
58
- // --- Avatar Utilities ---
91
+ // ---------------------------------------------------------------------------
92
+ // Avatars
93
+ // ---------------------------------------------------------------------------
59
94
  export { updateAvatarVisibility } from './utils/avatarUtils.js';
60
- // --- Account Utilities ---
61
- export { buildAccountsArray, createQuickAccount, getAccountDisplayName, getAccountFallbackHandle, formatPublicKeyHandle, } from './utils/accountUtils.js';
62
- // Default export
95
+ // ---------------------------------------------------------------------------
96
+ // Accounts
97
+ // ---------------------------------------------------------------------------
98
+ export { buildAccountsArray, createQuickAccount, getAccountDisplayName, getAccountFallbackHandle, formatPublicKeyHandle, mergeAccountsFromRefreshAll, getAccountColor, } from './utils/accountUtils.js';
99
+ // ---------------------------------------------------------------------------
100
+ // Constants
101
+ // ---------------------------------------------------------------------------
102
+ export { packageInfo } from './constants/version.js';
103
+ // ---------------------------------------------------------------------------
104
+ // Default export (back-compat — OxyServices is the most common consumer entry)
105
+ // ---------------------------------------------------------------------------
63
106
  import { OxyServices } from './OxyServices.js';
64
107
  export default OxyServices;
@@ -380,6 +380,241 @@ export function OxyServicesAuthMixin(Base) {
380
380
  throw this.handleError(error);
381
381
  }
382
382
  }
383
+ /**
384
+ * Refresh every device-local refresh-cookie slot in a single round trip
385
+ * (Google-style multi-account rebuild).
386
+ *
387
+ * Calls `POST {sessionBaseUrl}/auth/refresh-all` with `credentials: 'include'`
388
+ * and NO bearer. The browser attaches every `oxy_rt*` cookie it has; the
389
+ * server rotates each in parallel and returns one entry per VALID account.
390
+ *
391
+ * Failure handling:
392
+ * - 401 → no signed-in accounts on this device → returns `{ accounts: [] }`
393
+ * (NOT an error; this is the cold-boot "not signed in" path).
394
+ * - 404 → server is older than the multi-account endpoint. We fall back to
395
+ * `POST /auth/refresh` (single-slot) and wrap its response in the
396
+ * refresh-all shape so callers can treat the two paths uniformly. The
397
+ * fallback entry has `authuser: 0` (the legacy slot maps to slot 0 by
398
+ * convention) and a minimal `user` shape — consumers needing the full
399
+ * user must fetch it separately. Always exactly one account in this
400
+ * shape.
401
+ * - Any other non-2xx → throws via `handleError`.
402
+ *
403
+ * The refresh cookie itself never enters JS — only the rotated access
404
+ * tokens do. Each access token still needs to be planted via
405
+ * `setTokens(...)` (or per-account in-memory storage) at the consumer.
406
+ */
407
+ async refreshAllSessions() {
408
+ const url = `${this.getSessionBaseUrl().replace(/\/$/, '')}/auth/refresh-all`;
409
+ let response;
410
+ try {
411
+ response = await fetch(url, {
412
+ method: 'POST',
413
+ credentials: 'include',
414
+ headers: { Accept: 'application/json' },
415
+ });
416
+ }
417
+ catch (error) {
418
+ throw this.handleError(error);
419
+ }
420
+ if (response.status === 401) {
421
+ return { accounts: [] };
422
+ }
423
+ if (response.status === 404) {
424
+ // Legacy single-account refresh fallback. Wrap the response so the
425
+ // caller can treat both paths identically.
426
+ const legacy = await this._refreshCookieRaw();
427
+ if (!legacy) {
428
+ return { accounts: [] };
429
+ }
430
+ const fallbackAccount = {
431
+ authuser: 0,
432
+ accessToken: legacy.accessToken,
433
+ expiresAt: legacy.expiresAt,
434
+ sessionId: this._decodeSessionIdFromAccessToken(legacy.accessToken) ?? '',
435
+ // Legacy /auth/refresh does NOT project the user shape; the caller
436
+ // (AuthManager) is expected to hydrate via /users/me after planting.
437
+ user: null,
438
+ };
439
+ return { accounts: [fallbackAccount] };
440
+ }
441
+ if (!response.ok) {
442
+ throw this.handleError(new Error(`Refresh-all failed with HTTP ${response.status}`));
443
+ }
444
+ const payload = (await response.json());
445
+ const raw = Array.isArray(payload.accounts) ? payload.accounts : [];
446
+ const accounts = [];
447
+ for (const entry of raw) {
448
+ if (entry === null || typeof entry !== 'object') {
449
+ continue;
450
+ }
451
+ const e = entry;
452
+ if (!e.accessToken || !e.expiresAt || !e.sessionId || !e.user) {
453
+ continue;
454
+ }
455
+ const userId = e.user.id ?? e.user._id;
456
+ if (!userId || !e.user.username) {
457
+ continue;
458
+ }
459
+ // Normalise the legacy un-suffixed cookie (`authuser: null` on the
460
+ // wire) to slot 0. The SDK surface always operates on numeric indices.
461
+ const authuser = typeof e.authuser === 'number' ? e.authuser : 0;
462
+ accounts.push({
463
+ authuser,
464
+ accessToken: e.accessToken,
465
+ expiresAt: e.expiresAt,
466
+ sessionId: e.sessionId,
467
+ user: {
468
+ id: userId,
469
+ username: e.user.username,
470
+ name: e.user.name,
471
+ avatar: e.user.avatar ?? null,
472
+ email: e.user.email,
473
+ color: e.user.color ?? null,
474
+ },
475
+ });
476
+ }
477
+ return { accounts };
478
+ }
479
+ /**
480
+ * Rotate a single refresh-cookie slot and return the fresh access token.
481
+ *
482
+ * When `authuser` is provided, the server rotates ONLY that slot
483
+ * (`oxy_rt_${authuser}`) — sibling accounts on the same device stay
484
+ * untouched. When omitted, the server picks the lowest indexed slot
485
+ * present (legacy fallback applies). The refresh cookie itself never
486
+ * enters JS.
487
+ *
488
+ * Returns `null` on 401 (no cookie / expired / reused) so the caller can
489
+ * fall through cleanly to the unauthenticated path.
490
+ */
491
+ async refreshTokenViaCookie(opts = {}) {
492
+ const result = await this._refreshCookieRaw(opts.authuser);
493
+ return result;
494
+ }
495
+ /**
496
+ * Sign out a single device-local account by its authuser slot index.
497
+ *
498
+ * Revokes that slot's refresh-token family and deactivates its session;
499
+ * sibling indexed slots stay signed in. The browser-side `oxy_rt_${n}`
500
+ * cookie is cleared by the server's `Set-Cookie` response header.
501
+ */
502
+ async logoutSessionByAuthuser(authuser) {
503
+ const url = `${this.getSessionBaseUrl().replace(/\/$/, '')}/auth/logout?authuser=${encodeURIComponent(String(authuser))}`;
504
+ try {
505
+ const response = await fetch(url, {
506
+ method: 'POST',
507
+ credentials: 'include',
508
+ headers: { Accept: 'application/json' },
509
+ });
510
+ if (!response.ok && response.status !== 401) {
511
+ throw new Error(`Logout (authuser=${authuser}) failed with HTTP ${response.status}`);
512
+ }
513
+ }
514
+ catch (error) {
515
+ throw this.handleError(error);
516
+ }
517
+ }
518
+ /**
519
+ * Sign out EVERY device-local account on this device by clearing every
520
+ * presented refresh-cookie slot at once. Revokes every family + clears
521
+ * every slot. Always succeeds (idempotent on unknown/garbage tokens).
522
+ */
523
+ async logoutAllSessionsViaCookie() {
524
+ const url = `${this.getSessionBaseUrl().replace(/\/$/, '')}/auth/logout`;
525
+ try {
526
+ const response = await fetch(url, {
527
+ method: 'POST',
528
+ credentials: 'include',
529
+ headers: { Accept: 'application/json' },
530
+ });
531
+ if (!response.ok && response.status !== 401) {
532
+ throw new Error(`Logout-all failed with HTTP ${response.status}`);
533
+ }
534
+ }
535
+ catch (error) {
536
+ throw this.handleError(error);
537
+ }
538
+ }
539
+ /**
540
+ * Internal: raw `POST /auth/refresh[?authuser=N]` call returning the
541
+ * minted access token. Returns `null` on 401 / non-2xx. Used as both the
542
+ * implementation of `refreshTokenViaCookie` and the legacy fallback for
543
+ * `refreshAllSessions` against older servers.
544
+ *
545
+ * @internal
546
+ */
547
+ async _refreshCookieRaw(authuser) {
548
+ const base = this.getSessionBaseUrl().replace(/\/$/, '');
549
+ const url = typeof authuser === 'number'
550
+ ? `${base}/auth/refresh?authuser=${encodeURIComponent(String(authuser))}`
551
+ : `${base}/auth/refresh`;
552
+ let response;
553
+ try {
554
+ response = await fetch(url, {
555
+ method: 'POST',
556
+ credentials: 'include',
557
+ headers: { Accept: 'application/json' },
558
+ });
559
+ }
560
+ catch (error) {
561
+ throw this.handleError(error);
562
+ }
563
+ if (!response.ok) {
564
+ return null;
565
+ }
566
+ const payload = (await response.json());
567
+ if (typeof payload.accessToken !== 'string' || !payload.accessToken) {
568
+ return null;
569
+ }
570
+ const expiresAt = typeof payload.expiresAt === 'string' ? payload.expiresAt : '';
571
+ const respAuthuser = typeof payload.authuser === 'number' ? payload.authuser : null;
572
+ return {
573
+ accessToken: payload.accessToken,
574
+ expiresAt,
575
+ authuser: respAuthuser,
576
+ };
577
+ }
578
+ /**
579
+ * Internal: decode (without verifying) the `sessionId` claim from a
580
+ * server-signed access token. The server already verified the signature;
581
+ * the client only reads the claim to drive multi-session state.
582
+ *
583
+ * @internal
584
+ */
585
+ _decodeSessionIdFromAccessToken(token) {
586
+ if (!token || typeof token !== 'string') {
587
+ return null;
588
+ }
589
+ const segments = token.split('.');
590
+ if (segments.length !== 3) {
591
+ return null;
592
+ }
593
+ const payloadSegment = segments[1];
594
+ if (!payloadSegment) {
595
+ return null;
596
+ }
597
+ try {
598
+ const base64 = payloadSegment.replace(/-/g, '+').replace(/_/g, '/');
599
+ const padded = base64.padEnd(base64.length + ((4 - (base64.length % 4)) % 4), '=');
600
+ if (typeof atob !== 'function') {
601
+ return null;
602
+ }
603
+ const json = decodeURIComponent(atob(padded)
604
+ .split('')
605
+ .map((char) => `%${`00${char.charCodeAt(0).toString(16)}`.slice(-2)}`)
606
+ .join(''));
607
+ const parsed = JSON.parse(json);
608
+ if (parsed === null || typeof parsed !== 'object') {
609
+ return null;
610
+ }
611
+ const claims = parsed;
612
+ return typeof claims.sessionId === 'string' ? claims.sessionId : null;
613
+ }
614
+ catch {
615
+ return null;
616
+ }
617
+ }
383
618
  /**
384
619
  * Get sessions by session ID
385
620
  */
@@ -697,6 +697,42 @@ export function OxyServicesFedCMMixin(Base) {
697
697
  // Storage blocked
698
698
  }
699
699
  }
700
+ /**
701
+ * List the authenticated user's authorized RP apps.
702
+ *
703
+ * Returns the intersection of the user's FedCM grants and the currently-
704
+ * approved RP catalog — what powers the "Connected apps" management UI in
705
+ * @oxyhq/services. Requires a real user session; service tokens are
706
+ * rejected by the underlying endpoint.
707
+ */
708
+ async listAuthorizedApps() {
709
+ try {
710
+ const response = await this.makeRequest('GET', '/fedcm/me/authorized-apps', undefined, {
711
+ cache: true,
712
+ cacheTTL: 30 * 1000, // 30 second cache — short, this drives a manageable UI
713
+ });
714
+ return response.apps ?? [];
715
+ }
716
+ catch (error) {
717
+ throw this.handleError(error);
718
+ }
719
+ }
720
+ /**
721
+ * Revoke the authenticated user's authorization for a specific RP origin.
722
+ *
723
+ * The next FedCM sign-in from that origin will require explicit re-consent.
724
+ * The corresponding cache entry is invalidated so a subsequent
725
+ * `listAuthorizedApps()` call sees fresh data.
726
+ */
727
+ async revokeAuthorizedApp(origin) {
728
+ try {
729
+ await this.makeRequest('DELETE', `/fedcm/me/authorized-apps/${encodeURIComponent(origin)}`, undefined, { cache: false });
730
+ this.clearCacheEntry('GET:/fedcm/me/authorized-apps');
731
+ }
732
+ catch (error) {
733
+ throw this.handleError(error);
734
+ }
735
+ }
700
736
  },
701
737
  _a.DEFAULT_CONFIG_URL = 'https://auth.oxy.so/fedcm.json',
702
738
  _a.FEDCM_TIMEOUT = 15000 // 15 seconds for interactive
@@ -77,7 +77,37 @@ export function OxyServicesPopupAuthMixin(Base) {
77
77
  clientId: window.location.origin,
78
78
  redirectUri: `${this.resolveAuthUrl()}/auth/callback`,
79
79
  });
80
- const popup = this.openCenteredPopup(authUrl, 'Oxy Sign In', width, height);
80
+ // If the caller pre-opened a popup on the raw user gesture (recommended
81
+ // path — see `openBlankPopup` and `PopupAuthOptions.popup`), navigate it
82
+ // to the auth URL instead of issuing a fresh `window.open` (which would
83
+ // be blocked once any prior `await` has consumed the user activation).
84
+ let popup;
85
+ const preOpened = options.popup ?? null;
86
+ if (preOpened) {
87
+ if (preOpened.closed) {
88
+ // The pre-opened popup is gone — distinguish a user cancel (they
89
+ // closed the blank window before sign-in could navigate it) from a
90
+ // blocker rejection. Lumping these together as "Popup blocked" is
91
+ // misleading: the popup was NOT blocked, it was opened successfully
92
+ // and then dismissed.
93
+ throw new OxyAuthenticationError('Sign-in window was closed before authentication could start.');
94
+ }
95
+ try {
96
+ preOpened.location.replace(authUrl);
97
+ }
98
+ catch (replaceError) {
99
+ // `location.replace` can throw in sandboxed / cross-origin-locked
100
+ // environments. Fall back to `href` assignment, which is more
101
+ // permissive. Logged at debug-level so consumers can correlate
102
+ // unusual sign-in behaviour without producing noise in normal flows.
103
+ debug.warn('location.replace failed, falling back to location.href', replaceError);
104
+ preOpened.location.href = authUrl;
105
+ }
106
+ popup = preOpened;
107
+ }
108
+ else {
109
+ popup = this.openCenteredPopup(authUrl, 'Oxy Sign In', width, height);
110
+ }
81
111
  if (!popup) {
82
112
  throw new OxyAuthenticationError('Popup blocked. Please allow popups for this site and try again.');
83
113
  }
@@ -220,6 +250,36 @@ export function OxyServicesPopupAuthMixin(Base) {
220
250
  document.body.removeChild(iframe);
221
251
  }
222
252
  }
253
+ /**
254
+ * Open a blank, centered popup window SYNCHRONOUSLY.
255
+ *
256
+ * Use this in a click (or other user-gesture) handler BEFORE any `await`
257
+ * to capture the transient user-activation. Pass the returned handle into
258
+ * `signInWithPopup({ popup })` once the async portion of the flow runs.
259
+ *
260
+ * Returns `null` if the browser's popup blocker rejected the open.
261
+ *
262
+ * @example
263
+ * ```typescript
264
+ * const onSignInClick = () => {
265
+ * const popup = oxyServices.openBlankPopup();
266
+ * (async () => {
267
+ * const silent = await oxyServices.silentSignInWithFedCM();
268
+ * if (silent) { popup?.close(); return; }
269
+ * await oxyServices.signInWithPopup({ popup });
270
+ * })();
271
+ * };
272
+ * ```
273
+ */
274
+ openBlankPopup(width, height) {
275
+ if (typeof window === 'undefined') {
276
+ return null;
277
+ }
278
+ const ctor = this.constructor;
279
+ const w = width ?? ctor.POPUP_WIDTH;
280
+ const h = height ?? ctor.POPUP_HEIGHT;
281
+ return this.openCenteredPopup('about:blank', 'Oxy Sign In', w, h);
282
+ }
223
283
  /**
224
284
  * Open a centered popup window
225
285
  *