@oxyhq/core 5.5.0 → 7.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 (196) hide show
  1. package/dist/cjs/.tsbuildinfo +1 -1
  2. package/dist/cjs/HttpService.js +7 -4
  3. package/dist/cjs/OxyServices.base.js +7 -102
  4. package/dist/cjs/boot/coldBootV2.js +350 -0
  5. package/dist/cjs/boot/deviceBootReturn.js +152 -0
  6. package/dist/cjs/crypto/keyManager.js +95 -0
  7. package/dist/cjs/i18n/locales/en-US.json +13 -1
  8. package/dist/cjs/i18n/locales/es-ES.json +13 -1
  9. package/dist/cjs/i18n/locales/locales/en-US.json +13 -1
  10. package/dist/cjs/i18n/locales/locales/es-ES.json +13 -1
  11. package/dist/cjs/index.js +54 -45
  12. package/dist/cjs/mixins/OxyServices.accounts.js +13 -26
  13. package/dist/cjs/mixins/OxyServices.auth.js +66 -201
  14. package/dist/cjs/mixins/OxyServices.deviceBoot.js +119 -0
  15. package/dist/cjs/mixins/index.js +8 -17
  16. package/dist/cjs/server/index.js +2 -2
  17. package/dist/cjs/session/SessionClient.js +40 -1
  18. package/dist/cjs/session/authStateStore.js +284 -0
  19. package/dist/cjs/session/refresh.js +264 -0
  20. package/dist/cjs/shared/utils/debugUtils.js +3 -3
  21. package/dist/cjs/utils/accountUtils.js +1 -55
  22. package/dist/cjs/utils/authWebUrl.js +10 -39
  23. package/dist/cjs/utils/coldBoot.js +10 -8
  24. package/dist/cjs/utils/platform.js +19 -0
  25. package/dist/cjs/utils/registrableApex.js +49 -0
  26. package/dist/cjs/utils/ssoBounce.js +15 -362
  27. package/dist/cjs/utils/validationUtils.js +57 -0
  28. package/dist/esm/.tsbuildinfo +1 -1
  29. package/dist/esm/HttpService.js +7 -4
  30. package/dist/esm/OxyServices.base.js +7 -102
  31. package/dist/esm/boot/coldBootV2.js +344 -0
  32. package/dist/esm/boot/deviceBootReturn.js +146 -0
  33. package/dist/esm/crypto/keyManager.js +95 -0
  34. package/dist/esm/i18n/locales/en-US.json +13 -1
  35. package/dist/esm/i18n/locales/es-ES.json +13 -1
  36. package/dist/esm/i18n/locales/locales/en-US.json +13 -1
  37. package/dist/esm/i18n/locales/locales/es-ES.json +13 -1
  38. package/dist/esm/index.js +34 -17
  39. package/dist/esm/mixins/OxyServices.accounts.js +13 -26
  40. package/dist/esm/mixins/OxyServices.auth.js +66 -201
  41. package/dist/esm/mixins/OxyServices.deviceBoot.js +116 -0
  42. package/dist/esm/mixins/index.js +8 -17
  43. package/dist/esm/server/index.js +1 -1
  44. package/dist/esm/session/SessionClient.js +40 -1
  45. package/dist/esm/session/authStateStore.js +278 -0
  46. package/dist/esm/session/refresh.js +257 -0
  47. package/dist/esm/shared/utils/debugUtils.js +3 -3
  48. package/dist/esm/utils/accountUtils.js +0 -53
  49. package/dist/esm/utils/authWebUrl.js +9 -37
  50. package/dist/esm/utils/coldBoot.js +10 -8
  51. package/dist/esm/utils/platform.js +18 -0
  52. package/dist/esm/utils/registrableApex.js +46 -0
  53. package/dist/esm/utils/ssoBounce.js +14 -345
  54. package/dist/esm/utils/validationUtils.js +56 -0
  55. package/dist/types/.tsbuildinfo +1 -1
  56. package/dist/types/HttpService.d.ts +14 -1
  57. package/dist/types/OxyServices.base.d.ts +0 -52
  58. package/dist/types/OxyServices.d.ts +0 -25
  59. package/dist/types/boot/coldBootV2.d.ts +76 -0
  60. package/dist/types/boot/deviceBootReturn.d.ts +83 -0
  61. package/dist/types/crypto/keyManager.d.ts +21 -0
  62. package/dist/types/index.d.ts +14 -21
  63. package/dist/types/mixins/OxyServices.accounts.d.ts +24 -29
  64. package/dist/types/mixins/OxyServices.analytics.d.ts +0 -2
  65. package/dist/types/mixins/OxyServices.appData.d.ts +0 -2
  66. package/dist/types/mixins/OxyServices.assets.d.ts +0 -2
  67. package/dist/types/mixins/OxyServices.auth.d.ts +35 -77
  68. package/dist/types/mixins/OxyServices.civic.d.ts +0 -2
  69. package/dist/types/mixins/OxyServices.connectedApps.d.ts +0 -2
  70. package/dist/types/mixins/OxyServices.contacts.d.ts +0 -2
  71. package/dist/types/mixins/OxyServices.deviceBoot.d.ts +110 -0
  72. package/dist/types/mixins/OxyServices.devices.d.ts +0 -2
  73. package/dist/types/mixins/OxyServices.features.d.ts +0 -2
  74. package/dist/types/mixins/OxyServices.identity.d.ts +0 -2
  75. package/dist/types/mixins/OxyServices.language.d.ts +0 -2
  76. package/dist/types/mixins/OxyServices.links.d.ts +0 -2
  77. package/dist/types/mixins/OxyServices.location.d.ts +0 -2
  78. package/dist/types/mixins/OxyServices.nodes.d.ts +0 -2
  79. package/dist/types/mixins/OxyServices.payment.d.ts +0 -2
  80. package/dist/types/mixins/OxyServices.privacy.d.ts +0 -2
  81. package/dist/types/mixins/OxyServices.reputation.d.ts +0 -2
  82. package/dist/types/mixins/OxyServices.security.d.ts +0 -2
  83. package/dist/types/mixins/OxyServices.topics.d.ts +0 -2
  84. package/dist/types/mixins/OxyServices.user.d.ts +0 -2
  85. package/dist/types/mixins/OxyServices.utility.d.ts +0 -2
  86. package/dist/types/mixins/index.d.ts +5 -9
  87. package/dist/types/models/interfaces.d.ts +0 -67
  88. package/dist/types/models/session.d.ts +4 -5
  89. package/dist/types/server/index.d.ts +1 -1
  90. package/dist/types/session/SessionClient.d.ts +26 -1
  91. package/dist/types/session/authStateStore.d.ts +119 -0
  92. package/dist/types/session/refresh.d.ts +93 -0
  93. package/dist/types/shared/utils/debugUtils.d.ts +3 -3
  94. package/dist/types/utils/accountUtils.d.ts +2 -17
  95. package/dist/types/utils/authWebUrl.d.ts +9 -35
  96. package/dist/types/utils/coldBoot.d.ts +17 -14
  97. package/dist/types/utils/platform.d.ts +14 -0
  98. package/dist/types/utils/registrableApex.d.ts +31 -0
  99. package/dist/types/utils/ssoBounce.d.ts +14 -280
  100. package/dist/types/utils/validationUtils.d.ts +15 -0
  101. package/package.json +2 -2
  102. package/src/HttpService.ts +20 -4
  103. package/src/OxyServices.base.ts +7 -112
  104. package/src/OxyServices.ts +0 -38
  105. package/src/boot/__tests__/coldBootV2.test.ts +317 -0
  106. package/src/boot/__tests__/deviceBootReturn.test.ts +158 -0
  107. package/src/boot/coldBootV2.ts +426 -0
  108. package/src/boot/deviceBootReturn.ts +195 -0
  109. package/src/crypto/__tests__/sharedDeviceToken.test.ts +24 -0
  110. package/src/crypto/keyManager.ts +101 -0
  111. package/src/i18n/locales/en-US.json +13 -1
  112. package/src/i18n/locales/es-ES.json +13 -1
  113. package/src/index.ts +75 -65
  114. package/src/mixins/OxyServices.accounts.ts +27 -39
  115. package/src/mixins/OxyServices.auth.ts +78 -253
  116. package/src/mixins/OxyServices.deviceBoot.ts +146 -0
  117. package/src/mixins/__tests__/OxyServices.deviceBoot.test.ts +107 -0
  118. package/src/mixins/__tests__/accounts.test.ts +17 -44
  119. package/src/mixins/__tests__/passwordSignIn.test.ts +91 -0
  120. package/src/mixins/index.ts +10 -23
  121. package/src/models/interfaces.ts +0 -79
  122. package/src/models/session.ts +4 -5
  123. package/src/server/index.ts +1 -1
  124. package/src/session/SessionClient.ts +53 -2
  125. package/src/session/__tests__/SessionClient.additive.test.ts +92 -0
  126. package/src/session/__tests__/SessionClient.rest.test.ts +25 -0
  127. package/src/session/__tests__/SessionClient.state.test.ts +18 -5
  128. package/src/session/__tests__/authStateStore.test.ts +209 -0
  129. package/src/session/__tests__/refresh.test.ts +256 -0
  130. package/src/session/authStateStore.ts +335 -0
  131. package/src/session/refresh.ts +334 -0
  132. package/src/shared/utils/debugUtils.ts +3 -3
  133. package/src/utils/__tests__/authWebUrl.test.ts +5 -40
  134. package/src/utils/__tests__/registrableApex.test.ts +62 -0
  135. package/src/utils/__tests__/validationUtils.test.ts +30 -0
  136. package/src/utils/accountUtils.ts +2 -65
  137. package/src/utils/authWebUrl.ts +9 -39
  138. package/src/utils/coldBoot.ts +17 -14
  139. package/src/utils/platform.ts +21 -0
  140. package/src/utils/registrableApex.ts +45 -0
  141. package/src/utils/ssoBounce.ts +14 -393
  142. package/src/utils/validationUtils.ts +62 -0
  143. package/dist/cjs/AuthManager.js +0 -1110
  144. package/dist/cjs/AuthManagerTypes.js +0 -13
  145. package/dist/cjs/CrossDomainAuth.js +0 -206
  146. package/dist/cjs/mixins/OxyServices.fedcm.js +0 -823
  147. package/dist/cjs/mixins/OxyServices.redirect.js +0 -95
  148. package/dist/cjs/mixins/OxyServices.silent.js +0 -204
  149. package/dist/cjs/mixins/OxyServices.sso.js +0 -208
  150. package/dist/cjs/utils/fapiAutoDetect.js +0 -99
  151. package/dist/cjs/utils/ssoEstablish.js +0 -110
  152. package/dist/cjs/utils/ssoReturn.js +0 -275
  153. package/dist/esm/AuthManager.js +0 -1105
  154. package/dist/esm/AuthManagerTypes.js +0 -12
  155. package/dist/esm/CrossDomainAuth.js +0 -201
  156. package/dist/esm/mixins/OxyServices.fedcm.js +0 -821
  157. package/dist/esm/mixins/OxyServices.redirect.js +0 -92
  158. package/dist/esm/mixins/OxyServices.silent.js +0 -202
  159. package/dist/esm/mixins/OxyServices.sso.js +0 -204
  160. package/dist/esm/utils/fapiAutoDetect.js +0 -95
  161. package/dist/esm/utils/ssoEstablish.js +0 -107
  162. package/dist/esm/utils/ssoReturn.js +0 -271
  163. package/dist/types/AuthManager.d.ts +0 -380
  164. package/dist/types/AuthManagerTypes.d.ts +0 -81
  165. package/dist/types/CrossDomainAuth.d.ts +0 -164
  166. package/dist/types/mixins/OxyServices.fedcm.d.ts +0 -331
  167. package/dist/types/mixins/OxyServices.redirect.d.ts +0 -92
  168. package/dist/types/mixins/OxyServices.silent.d.ts +0 -132
  169. package/dist/types/mixins/OxyServices.sso.d.ts +0 -138
  170. package/dist/types/utils/fapiAutoDetect.d.ts +0 -56
  171. package/dist/types/utils/ssoEstablish.d.ts +0 -85
  172. package/dist/types/utils/ssoReturn.d.ts +0 -156
  173. package/src/AuthManager.ts +0 -1269
  174. package/src/AuthManagerTypes.ts +0 -86
  175. package/src/CrossDomainAuth.ts +0 -243
  176. package/src/__tests__/authManager.cookiePath.test.ts +0 -390
  177. package/src/__tests__/authManager.security.test.ts +0 -377
  178. package/src/__tests__/crossDomainAuth.test.ts +0 -116
  179. package/src/__tests__/establishDeviceRefreshSlot.test.ts +0 -221
  180. package/src/mixins/OxyServices.fedcm.ts +0 -1026
  181. package/src/mixins/OxyServices.redirect.ts +0 -122
  182. package/src/mixins/OxyServices.silent.ts +0 -272
  183. package/src/mixins/OxyServices.sso.ts +0 -261
  184. package/src/mixins/__tests__/constructorAuthWebUrl.test.ts +0 -85
  185. package/src/mixins/__tests__/fedcm.test.ts +0 -667
  186. package/src/mixins/__tests__/sessionBaseUrl.test.ts +0 -61
  187. package/src/mixins/__tests__/silent.test.ts +0 -102
  188. package/src/mixins/__tests__/sso.test.ts +0 -228
  189. package/src/utils/__tests__/consumeSsoReturn.test.ts +0 -816
  190. package/src/utils/__tests__/fapiAutoDetect.test.ts +0 -183
  191. package/src/utils/__tests__/ssoBounce.test.ts +0 -219
  192. package/src/utils/__tests__/ssoEstablish.test.ts +0 -204
  193. package/src/utils/__tests__/ssoReturn.test.ts +0 -276
  194. package/src/utils/fapiAutoDetect.ts +0 -91
  195. package/src/utils/ssoEstablish.ts +0 -174
  196. package/src/utils/ssoReturn.ts +0 -389
@@ -1,12 +0,0 @@
1
- /**
2
- * AuthManager — public types for the multi-account cookie path.
3
- *
4
- * Lives in its own module (rather than the 670-line `models/interfaces.ts`)
5
- * so consumers can `import type` exactly the multi-account surface without
6
- * pulling in the full interfaces graph, and so `AuthManager.ts` stays
7
- * decoupled from the wire shapes — these types re-state the wire as the
8
- * AuthManager's in-memory representation.
9
- *
10
- * @module core/AuthManagerTypes
11
- */
12
- export {};
@@ -1,201 +0,0 @@
1
- /**
2
- * Cross-Domain Authentication Helper
3
- *
4
- * Provides a simplified API for cross-domain SSO authentication. The
5
- * automatic sign-in path uses a full-page redirect through the central IdP
6
- * (`auth.oxy.so`) — a tokenless, universal mechanism that works in every
7
- * browser.
8
- *
9
- * FedCM (`signInWithFedCM`) is intentionally NOT part of the automatic
10
- * (`'auto'`) path: it is a Chrome-only browser API, and a misconfigured or
11
- * unreachable FedCM endpoint fails fast and silently, which — combined with a
12
- * caller's auth-guard effect re-invoking `signIn()` whenever the user is still
13
- * unauthenticated — produced a real production incident (an accelerating
14
- * `autoSignIn` → FedCM-fails → redirect retry loop). `signInWithFedCM` remains
15
- * available for callers that want to opt into it EXPLICITLY
16
- * (`signIn({ method: 'fedcm' })`).
17
- *
18
- * Usage:
19
- * ```typescript
20
- * import { CrossDomainAuth } from '@oxyhq/core';
21
- *
22
- * const auth = new CrossDomainAuth(oxyServices);
23
- *
24
- * // Automatic method selection (always redirect)
25
- * const session = await auth.signIn();
26
- *
27
- * // Or use a specific method
28
- * auth.signInWithRedirect();
29
- * ```
30
- */
31
- import { logger } from './utils/loggerUtils.js';
32
- export class CrossDomainAuth {
33
- constructor(oxyServices) {
34
- this.oxyServices = oxyServices;
35
- }
36
- /**
37
- * Sign in with automatic method selection.
38
- *
39
- * Auto mode always uses the full-page redirect (see the class doc comment
40
- * for why FedCM was removed from this path). Pass `{ method: 'fedcm' }` to
41
- * opt into FedCM explicitly.
42
- *
43
- * @param options - Authentication options
44
- * @returns Session with user data and access token
45
- */
46
- async signIn(options = {}) {
47
- const method = options.method || 'auto';
48
- if (method === 'fedcm') {
49
- return this.signInWithFedCM(options);
50
- }
51
- if (method === 'redirect') {
52
- this.signInWithRedirect(options);
53
- return null; // Redirect doesn't return immediately
54
- }
55
- // Auto mode: try methods in order of preference.
56
- return this.autoSignIn(options);
57
- }
58
- /**
59
- * Automatic sign-in.
60
- *
61
- * Goes straight to the full-page redirect — the sole automatic method.
62
- * FedCM is deliberately NOT attempted here (see the class doc comment):
63
- * it is Chrome-only, and its fast/silent failure mode combined with a
64
- * caller's auth-guard effect re-invoking `signIn()` produced a real
65
- * production sign-in loop. Use `signIn({ method: 'fedcm' })` to opt in
66
- * explicitly.
67
- *
68
- * @private
69
- */
70
- async autoSignIn(options) {
71
- options.onMethodSelected?.('redirect');
72
- this.signInWithRedirect(options);
73
- return null;
74
- }
75
- /**
76
- * Sign in using FedCM (Federated Credential Management)
77
- *
78
- * Best method - browser-native, Google-like experience
79
- */
80
- async signInWithFedCM(options = {}) {
81
- return this.oxyServices.signInWithFedCM({
82
- context: options.isSignup ? 'signup' : 'signin',
83
- });
84
- }
85
- /**
86
- * Sign in using full-page redirect
87
- *
88
- * Fallback method - works everywhere but loses app state
89
- */
90
- signInWithRedirect(options = {}) {
91
- this.oxyServices.signInWithRedirect({
92
- redirectUri: options.redirectUri,
93
- mode: options.isSignup ? 'signup' : 'login',
94
- });
95
- }
96
- /**
97
- * Handle redirect callback
98
- *
99
- * Call this on app startup to check if we're returning from auth redirect
100
- */
101
- handleRedirectCallback() {
102
- return this.oxyServices.handleAuthCallback();
103
- }
104
- /**
105
- * Silent sign-in (check for existing session)
106
- *
107
- * Tries to automatically sign in without user interaction, via the
108
- * iframe-based silent auth against the per-apex `/auth/silent` IdP host.
109
- * FedCM is deliberately NOT attempted here (see the class doc comment).
110
- *
111
- * @returns Session if user is already signed in, null otherwise
112
- */
113
- async silentSignIn() {
114
- try {
115
- return await this.oxyServices.silentSignIn();
116
- }
117
- catch (error) {
118
- logger.debug('iframe silent sign-in did not resolve', { component: 'CrossDomainAuth', method: 'silentSignIn' }, error);
119
- return null;
120
- }
121
- }
122
- /**
123
- * Restore session from storage.
124
- *
125
- * Access tokens are no longer persisted in browser storage; providers restore
126
- * through refresh cookies / SSO code exchange instead.
127
- */
128
- restoreSession() {
129
- return false;
130
- }
131
- /**
132
- * Check if FedCM is supported in current browser
133
- */
134
- isFedCMSupported() {
135
- // FedCM support is exposed both as a static and an instance method on
136
- // OxyServices; the instance method is reliable across mixin composition.
137
- return this.oxyServices.isFedCMSupported?.() || false;
138
- }
139
- /**
140
- * Get recommended authentication method for current environment
141
- *
142
- * Redirect is the sole recommended automatic method — it works in every
143
- * browser, unlike FedCM (Chrome-only). Callers that want FedCM must opt in
144
- * explicitly via `signIn({ method: 'fedcm' })`.
145
- *
146
- * @returns Recommended method name and reason
147
- */
148
- getRecommendedMethod() {
149
- if (typeof window !== 'undefined') {
150
- return {
151
- method: 'redirect',
152
- reason: 'Browser environment - redirect SSO works without token callback URLs',
153
- };
154
- }
155
- return {
156
- method: 'redirect',
157
- reason: 'Fallback method - works in all environments',
158
- };
159
- }
160
- /**
161
- * Initialize cross-domain auth on app startup
162
- *
163
- * This handles:
164
- * 1. Redirect callback (if returning from auth.oxy.so)
165
- * 2. Silent sign-in (check for existing SSO session)
166
- *
167
- * @returns Session if user is authenticated, null otherwise
168
- */
169
- async initialize() {
170
- // 1. Check if this is a redirect callback
171
- const callbackSession = this.handleRedirectCallback();
172
- if (callbackSession) {
173
- return callbackSession;
174
- }
175
- // 2. Try silent sign-in (check for SSO session at auth.oxy.so)
176
- return await this.silentSignIn();
177
- }
178
- }
179
- /**
180
- * Helper function to create CrossDomainAuth instance
181
- *
182
- * @example
183
- * ```typescript
184
- * import { createCrossDomainAuth } from '@oxyhq/core';
185
- *
186
- * const oxyServices = new OxyServices({ baseURL: 'https://api.oxy.so' });
187
- * const auth = createCrossDomainAuth(oxyServices);
188
- *
189
- * // On app startup
190
- * const session = await auth.initialize();
191
- * if (session) {
192
- * console.log('User is signed in:', session.user);
193
- * }
194
- *
195
- * // Sign in button click
196
- * const session = await auth.signIn();
197
- * ```
198
- */
199
- export function createCrossDomainAuth(oxyServices) {
200
- return new CrossDomainAuth(oxyServices);
201
- }