@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.
- package/README.md +5 -6
- package/dist/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/AuthManager.js +678 -4
- package/dist/cjs/AuthManagerTypes.js +13 -0
- package/dist/cjs/CrossDomainAuth.js +45 -3
- package/dist/cjs/OxyServices.base.js +16 -0
- package/dist/cjs/i18n/locales/ar-SA.json +83 -0
- package/dist/cjs/i18n/locales/ca-ES.json +83 -0
- package/dist/cjs/i18n/locales/de-DE.json +83 -0
- package/dist/cjs/i18n/locales/en-US.json +83 -0
- package/dist/cjs/i18n/locales/es-ES.json +99 -4
- package/dist/cjs/i18n/locales/fr-FR.json +83 -0
- package/dist/cjs/i18n/locales/it-IT.json +83 -0
- package/dist/cjs/i18n/locales/ja-JP.json +83 -0
- package/dist/cjs/i18n/locales/ko-KR.json +83 -0
- package/dist/cjs/i18n/locales/locales/ar-SA.json +83 -1
- package/dist/cjs/i18n/locales/locales/ca-ES.json +83 -1
- package/dist/cjs/i18n/locales/locales/de-DE.json +83 -1
- package/dist/cjs/i18n/locales/locales/en-US.json +83 -0
- package/dist/cjs/i18n/locales/locales/es-ES.json +99 -4
- package/dist/cjs/i18n/locales/locales/fr-FR.json +83 -1
- package/dist/cjs/i18n/locales/locales/it-IT.json +83 -1
- package/dist/cjs/i18n/locales/locales/ja-JP.json +200 -117
- package/dist/cjs/i18n/locales/locales/ko-KR.json +83 -1
- package/dist/cjs/i18n/locales/locales/pt-PT.json +83 -1
- package/dist/cjs/i18n/locales/locales/zh-CN.json +83 -1
- package/dist/cjs/i18n/locales/pt-PT.json +83 -0
- package/dist/cjs/i18n/locales/zh-CN.json +83 -0
- package/dist/cjs/index.js +114 -57
- package/dist/cjs/mixins/OxyServices.auth.js +235 -0
- package/dist/cjs/mixins/OxyServices.fedcm.js +36 -0
- package/dist/cjs/mixins/OxyServices.popup.js +61 -1
- package/dist/cjs/mixins/OxyServices.user.js +18 -0
- package/dist/cjs/utils/accountUtils.js +64 -1
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/AuthManager.js +678 -4
- package/dist/esm/AuthManagerTypes.js +12 -0
- package/dist/esm/CrossDomainAuth.js +45 -3
- package/dist/esm/OxyServices.base.js +16 -0
- package/dist/esm/i18n/locales/ar-SA.json +83 -0
- package/dist/esm/i18n/locales/ca-ES.json +83 -0
- package/dist/esm/i18n/locales/de-DE.json +83 -0
- package/dist/esm/i18n/locales/en-US.json +83 -0
- package/dist/esm/i18n/locales/es-ES.json +99 -4
- package/dist/esm/i18n/locales/fr-FR.json +83 -0
- package/dist/esm/i18n/locales/it-IT.json +83 -0
- package/dist/esm/i18n/locales/ja-JP.json +83 -0
- package/dist/esm/i18n/locales/ko-KR.json +83 -0
- package/dist/esm/i18n/locales/locales/ar-SA.json +83 -1
- package/dist/esm/i18n/locales/locales/ca-ES.json +83 -1
- package/dist/esm/i18n/locales/locales/de-DE.json +83 -1
- package/dist/esm/i18n/locales/locales/en-US.json +83 -0
- package/dist/esm/i18n/locales/locales/es-ES.json +99 -4
- package/dist/esm/i18n/locales/locales/fr-FR.json +83 -1
- package/dist/esm/i18n/locales/locales/it-IT.json +83 -1
- package/dist/esm/i18n/locales/locales/ja-JP.json +200 -117
- package/dist/esm/i18n/locales/locales/ko-KR.json +83 -1
- package/dist/esm/i18n/locales/locales/pt-PT.json +83 -1
- package/dist/esm/i18n/locales/locales/zh-CN.json +83 -1
- package/dist/esm/i18n/locales/pt-PT.json +83 -0
- package/dist/esm/i18n/locales/zh-CN.json +83 -0
- package/dist/esm/index.js +69 -26
- package/dist/esm/mixins/OxyServices.auth.js +235 -0
- package/dist/esm/mixins/OxyServices.fedcm.js +36 -0
- package/dist/esm/mixins/OxyServices.popup.js +61 -1
- package/dist/esm/mixins/OxyServices.user.js +18 -0
- package/dist/esm/utils/accountUtils.js +61 -0
- package/dist/types/.tsbuildinfo +1 -1
- package/dist/types/AuthManager.d.ts +243 -3
- package/dist/types/AuthManagerTypes.d.ts +68 -0
- package/dist/types/CrossDomainAuth.d.ts +23 -0
- package/dist/types/OxyServices.base.d.ts +14 -0
- package/dist/types/OxyServices.d.ts +7 -0
- package/dist/types/index.d.ts +28 -17
- package/dist/types/mixins/OxyServices.analytics.d.ts +1 -0
- package/dist/types/mixins/OxyServices.appData.d.ts +1 -0
- package/dist/types/mixins/OxyServices.assets.d.ts +4 -1
- package/dist/types/mixins/OxyServices.auth.d.ts +73 -1
- package/dist/types/mixins/OxyServices.contacts.d.ts +1 -0
- package/dist/types/mixins/OxyServices.developer.d.ts +1 -0
- package/dist/types/mixins/OxyServices.devices.d.ts +1 -0
- package/dist/types/mixins/OxyServices.features.d.ts +2 -5
- package/dist/types/mixins/OxyServices.fedcm.d.ts +34 -0
- package/dist/types/mixins/OxyServices.karma.d.ts +1 -0
- package/dist/types/mixins/OxyServices.language.d.ts +1 -0
- package/dist/types/mixins/OxyServices.location.d.ts +1 -0
- package/dist/types/mixins/OxyServices.managedAccounts.d.ts +1 -0
- package/dist/types/mixins/OxyServices.payment.d.ts +1 -0
- package/dist/types/mixins/OxyServices.popup.d.ts +40 -0
- package/dist/types/mixins/OxyServices.privacy.d.ts +1 -0
- package/dist/types/mixins/OxyServices.redirect.d.ts +1 -0
- package/dist/types/mixins/OxyServices.security.d.ts +1 -0
- package/dist/types/mixins/OxyServices.topics.d.ts +1 -0
- package/dist/types/mixins/OxyServices.user.d.ts +16 -1
- package/dist/types/mixins/OxyServices.utility.d.ts +1 -0
- package/dist/types/models/interfaces.d.ts +98 -0
- package/dist/types/models/session.d.ts +8 -0
- package/dist/types/utils/accountUtils.d.ts +33 -0
- package/package.json +9 -18
- package/src/AuthManager.ts +776 -7
- package/src/AuthManagerTypes.ts +72 -0
- package/src/CrossDomainAuth.ts +54 -3
- package/src/OxyServices.base.ts +17 -0
- package/src/OxyServices.ts +7 -0
- package/src/__tests__/authManager.cookiePath.test.ts +339 -0
- package/src/__tests__/authManager.security.test.ts +342 -0
- package/src/__tests__/crossDomainAuth.test.ts +191 -0
- package/src/i18n/locales/ar-SA.json +83 -1
- package/src/i18n/locales/ca-ES.json +83 -1
- package/src/i18n/locales/de-DE.json +83 -1
- package/src/i18n/locales/en-US.json +83 -0
- package/src/i18n/locales/es-ES.json +99 -4
- package/src/i18n/locales/fr-FR.json +83 -1
- package/src/i18n/locales/it-IT.json +83 -1
- package/src/i18n/locales/ja-JP.json +200 -117
- package/src/i18n/locales/ko-KR.json +83 -1
- package/src/i18n/locales/pt-PT.json +83 -1
- package/src/i18n/locales/zh-CN.json +83 -1
- package/src/index.ts +295 -112
- package/src/mixins/OxyServices.auth.ts +268 -1
- package/src/mixins/OxyServices.fedcm.ts +63 -0
- package/src/mixins/OxyServices.popup.ts +79 -1
- package/src/mixins/OxyServices.user.ts +33 -1
- package/src/mixins/__tests__/popup.test.ts +307 -0
- package/src/mixins/__tests__/sessionBaseUrl.test.ts +61 -0
- package/src/models/interfaces.ts +116 -0
- package/src/models/session.ts +8 -0
- package/src/utils/accountUtils.ts +84 -0
- package/dist/cjs/crypto/index.js +0 -22
- package/dist/cjs/shared/index.js +0 -70
- package/dist/cjs/utils/index.js +0 -26
- package/dist/esm/crypto/index.js +0 -13
- package/dist/esm/shared/index.js +0 -31
- package/dist/esm/utils/index.js +0 -7
- package/dist/types/crypto/index.d.ts +0 -11
- package/dist/types/shared/index.d.ts +0 -28
- package/dist/types/utils/index.d.ts +0 -6
- package/src/crypto/index.ts +0 -30
- package/src/shared/index.ts +0 -82
- package/src/utils/index.ts +0 -21
|
@@ -385,6 +385,241 @@ function OxyServicesAuthMixin(Base) {
|
|
|
385
385
|
throw this.handleError(error);
|
|
386
386
|
}
|
|
387
387
|
}
|
|
388
|
+
/**
|
|
389
|
+
* Refresh every device-local refresh-cookie slot in a single round trip
|
|
390
|
+
* (Google-style multi-account rebuild).
|
|
391
|
+
*
|
|
392
|
+
* Calls `POST {sessionBaseUrl}/auth/refresh-all` with `credentials: 'include'`
|
|
393
|
+
* and NO bearer. The browser attaches every `oxy_rt*` cookie it has; the
|
|
394
|
+
* server rotates each in parallel and returns one entry per VALID account.
|
|
395
|
+
*
|
|
396
|
+
* Failure handling:
|
|
397
|
+
* - 401 → no signed-in accounts on this device → returns `{ accounts: [] }`
|
|
398
|
+
* (NOT an error; this is the cold-boot "not signed in" path).
|
|
399
|
+
* - 404 → server is older than the multi-account endpoint. We fall back to
|
|
400
|
+
* `POST /auth/refresh` (single-slot) and wrap its response in the
|
|
401
|
+
* refresh-all shape so callers can treat the two paths uniformly. The
|
|
402
|
+
* fallback entry has `authuser: 0` (the legacy slot maps to slot 0 by
|
|
403
|
+
* convention) and a minimal `user` shape — consumers needing the full
|
|
404
|
+
* user must fetch it separately. Always exactly one account in this
|
|
405
|
+
* shape.
|
|
406
|
+
* - Any other non-2xx → throws via `handleError`.
|
|
407
|
+
*
|
|
408
|
+
* The refresh cookie itself never enters JS — only the rotated access
|
|
409
|
+
* tokens do. Each access token still needs to be planted via
|
|
410
|
+
* `setTokens(...)` (or per-account in-memory storage) at the consumer.
|
|
411
|
+
*/
|
|
412
|
+
async refreshAllSessions() {
|
|
413
|
+
const url = `${this.getSessionBaseUrl().replace(/\/$/, '')}/auth/refresh-all`;
|
|
414
|
+
let response;
|
|
415
|
+
try {
|
|
416
|
+
response = await fetch(url, {
|
|
417
|
+
method: 'POST',
|
|
418
|
+
credentials: 'include',
|
|
419
|
+
headers: { Accept: 'application/json' },
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
catch (error) {
|
|
423
|
+
throw this.handleError(error);
|
|
424
|
+
}
|
|
425
|
+
if (response.status === 401) {
|
|
426
|
+
return { accounts: [] };
|
|
427
|
+
}
|
|
428
|
+
if (response.status === 404) {
|
|
429
|
+
// Legacy single-account refresh fallback. Wrap the response so the
|
|
430
|
+
// caller can treat both paths identically.
|
|
431
|
+
const legacy = await this._refreshCookieRaw();
|
|
432
|
+
if (!legacy) {
|
|
433
|
+
return { accounts: [] };
|
|
434
|
+
}
|
|
435
|
+
const fallbackAccount = {
|
|
436
|
+
authuser: 0,
|
|
437
|
+
accessToken: legacy.accessToken,
|
|
438
|
+
expiresAt: legacy.expiresAt,
|
|
439
|
+
sessionId: this._decodeSessionIdFromAccessToken(legacy.accessToken) ?? '',
|
|
440
|
+
// Legacy /auth/refresh does NOT project the user shape; the caller
|
|
441
|
+
// (AuthManager) is expected to hydrate via /users/me after planting.
|
|
442
|
+
user: null,
|
|
443
|
+
};
|
|
444
|
+
return { accounts: [fallbackAccount] };
|
|
445
|
+
}
|
|
446
|
+
if (!response.ok) {
|
|
447
|
+
throw this.handleError(new Error(`Refresh-all failed with HTTP ${response.status}`));
|
|
448
|
+
}
|
|
449
|
+
const payload = (await response.json());
|
|
450
|
+
const raw = Array.isArray(payload.accounts) ? payload.accounts : [];
|
|
451
|
+
const accounts = [];
|
|
452
|
+
for (const entry of raw) {
|
|
453
|
+
if (entry === null || typeof entry !== 'object') {
|
|
454
|
+
continue;
|
|
455
|
+
}
|
|
456
|
+
const e = entry;
|
|
457
|
+
if (!e.accessToken || !e.expiresAt || !e.sessionId || !e.user) {
|
|
458
|
+
continue;
|
|
459
|
+
}
|
|
460
|
+
const userId = e.user.id ?? e.user._id;
|
|
461
|
+
if (!userId || !e.user.username) {
|
|
462
|
+
continue;
|
|
463
|
+
}
|
|
464
|
+
// Normalise the legacy un-suffixed cookie (`authuser: null` on the
|
|
465
|
+
// wire) to slot 0. The SDK surface always operates on numeric indices.
|
|
466
|
+
const authuser = typeof e.authuser === 'number' ? e.authuser : 0;
|
|
467
|
+
accounts.push({
|
|
468
|
+
authuser,
|
|
469
|
+
accessToken: e.accessToken,
|
|
470
|
+
expiresAt: e.expiresAt,
|
|
471
|
+
sessionId: e.sessionId,
|
|
472
|
+
user: {
|
|
473
|
+
id: userId,
|
|
474
|
+
username: e.user.username,
|
|
475
|
+
name: e.user.name,
|
|
476
|
+
avatar: e.user.avatar ?? null,
|
|
477
|
+
email: e.user.email,
|
|
478
|
+
color: e.user.color ?? null,
|
|
479
|
+
},
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
return { accounts };
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Rotate a single refresh-cookie slot and return the fresh access token.
|
|
486
|
+
*
|
|
487
|
+
* When `authuser` is provided, the server rotates ONLY that slot
|
|
488
|
+
* (`oxy_rt_${authuser}`) — sibling accounts on the same device stay
|
|
489
|
+
* untouched. When omitted, the server picks the lowest indexed slot
|
|
490
|
+
* present (legacy fallback applies). The refresh cookie itself never
|
|
491
|
+
* enters JS.
|
|
492
|
+
*
|
|
493
|
+
* Returns `null` on 401 (no cookie / expired / reused) so the caller can
|
|
494
|
+
* fall through cleanly to the unauthenticated path.
|
|
495
|
+
*/
|
|
496
|
+
async refreshTokenViaCookie(opts = {}) {
|
|
497
|
+
const result = await this._refreshCookieRaw(opts.authuser);
|
|
498
|
+
return result;
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* Sign out a single device-local account by its authuser slot index.
|
|
502
|
+
*
|
|
503
|
+
* Revokes that slot's refresh-token family and deactivates its session;
|
|
504
|
+
* sibling indexed slots stay signed in. The browser-side `oxy_rt_${n}`
|
|
505
|
+
* cookie is cleared by the server's `Set-Cookie` response header.
|
|
506
|
+
*/
|
|
507
|
+
async logoutSessionByAuthuser(authuser) {
|
|
508
|
+
const url = `${this.getSessionBaseUrl().replace(/\/$/, '')}/auth/logout?authuser=${encodeURIComponent(String(authuser))}`;
|
|
509
|
+
try {
|
|
510
|
+
const response = await fetch(url, {
|
|
511
|
+
method: 'POST',
|
|
512
|
+
credentials: 'include',
|
|
513
|
+
headers: { Accept: 'application/json' },
|
|
514
|
+
});
|
|
515
|
+
if (!response.ok && response.status !== 401) {
|
|
516
|
+
throw new Error(`Logout (authuser=${authuser}) failed with HTTP ${response.status}`);
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
catch (error) {
|
|
520
|
+
throw this.handleError(error);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* Sign out EVERY device-local account on this device by clearing every
|
|
525
|
+
* presented refresh-cookie slot at once. Revokes every family + clears
|
|
526
|
+
* every slot. Always succeeds (idempotent on unknown/garbage tokens).
|
|
527
|
+
*/
|
|
528
|
+
async logoutAllSessionsViaCookie() {
|
|
529
|
+
const url = `${this.getSessionBaseUrl().replace(/\/$/, '')}/auth/logout`;
|
|
530
|
+
try {
|
|
531
|
+
const response = await fetch(url, {
|
|
532
|
+
method: 'POST',
|
|
533
|
+
credentials: 'include',
|
|
534
|
+
headers: { Accept: 'application/json' },
|
|
535
|
+
});
|
|
536
|
+
if (!response.ok && response.status !== 401) {
|
|
537
|
+
throw new Error(`Logout-all failed with HTTP ${response.status}`);
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
catch (error) {
|
|
541
|
+
throw this.handleError(error);
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
/**
|
|
545
|
+
* Internal: raw `POST /auth/refresh[?authuser=N]` call returning the
|
|
546
|
+
* minted access token. Returns `null` on 401 / non-2xx. Used as both the
|
|
547
|
+
* implementation of `refreshTokenViaCookie` and the legacy fallback for
|
|
548
|
+
* `refreshAllSessions` against older servers.
|
|
549
|
+
*
|
|
550
|
+
* @internal
|
|
551
|
+
*/
|
|
552
|
+
async _refreshCookieRaw(authuser) {
|
|
553
|
+
const base = this.getSessionBaseUrl().replace(/\/$/, '');
|
|
554
|
+
const url = typeof authuser === 'number'
|
|
555
|
+
? `${base}/auth/refresh?authuser=${encodeURIComponent(String(authuser))}`
|
|
556
|
+
: `${base}/auth/refresh`;
|
|
557
|
+
let response;
|
|
558
|
+
try {
|
|
559
|
+
response = await fetch(url, {
|
|
560
|
+
method: 'POST',
|
|
561
|
+
credentials: 'include',
|
|
562
|
+
headers: { Accept: 'application/json' },
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
catch (error) {
|
|
566
|
+
throw this.handleError(error);
|
|
567
|
+
}
|
|
568
|
+
if (!response.ok) {
|
|
569
|
+
return null;
|
|
570
|
+
}
|
|
571
|
+
const payload = (await response.json());
|
|
572
|
+
if (typeof payload.accessToken !== 'string' || !payload.accessToken) {
|
|
573
|
+
return null;
|
|
574
|
+
}
|
|
575
|
+
const expiresAt = typeof payload.expiresAt === 'string' ? payload.expiresAt : '';
|
|
576
|
+
const respAuthuser = typeof payload.authuser === 'number' ? payload.authuser : null;
|
|
577
|
+
return {
|
|
578
|
+
accessToken: payload.accessToken,
|
|
579
|
+
expiresAt,
|
|
580
|
+
authuser: respAuthuser,
|
|
581
|
+
};
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Internal: decode (without verifying) the `sessionId` claim from a
|
|
585
|
+
* server-signed access token. The server already verified the signature;
|
|
586
|
+
* the client only reads the claim to drive multi-session state.
|
|
587
|
+
*
|
|
588
|
+
* @internal
|
|
589
|
+
*/
|
|
590
|
+
_decodeSessionIdFromAccessToken(token) {
|
|
591
|
+
if (!token || typeof token !== 'string') {
|
|
592
|
+
return null;
|
|
593
|
+
}
|
|
594
|
+
const segments = token.split('.');
|
|
595
|
+
if (segments.length !== 3) {
|
|
596
|
+
return null;
|
|
597
|
+
}
|
|
598
|
+
const payloadSegment = segments[1];
|
|
599
|
+
if (!payloadSegment) {
|
|
600
|
+
return null;
|
|
601
|
+
}
|
|
602
|
+
try {
|
|
603
|
+
const base64 = payloadSegment.replace(/-/g, '+').replace(/_/g, '/');
|
|
604
|
+
const padded = base64.padEnd(base64.length + ((4 - (base64.length % 4)) % 4), '=');
|
|
605
|
+
if (typeof atob !== 'function') {
|
|
606
|
+
return null;
|
|
607
|
+
}
|
|
608
|
+
const json = decodeURIComponent(atob(padded)
|
|
609
|
+
.split('')
|
|
610
|
+
.map((char) => `%${`00${char.charCodeAt(0).toString(16)}`.slice(-2)}`)
|
|
611
|
+
.join(''));
|
|
612
|
+
const parsed = JSON.parse(json);
|
|
613
|
+
if (parsed === null || typeof parsed !== 'object') {
|
|
614
|
+
return null;
|
|
615
|
+
}
|
|
616
|
+
const claims = parsed;
|
|
617
|
+
return typeof claims.sessionId === 'string' ? claims.sessionId : null;
|
|
618
|
+
}
|
|
619
|
+
catch {
|
|
620
|
+
return null;
|
|
621
|
+
}
|
|
622
|
+
}
|
|
388
623
|
/**
|
|
389
624
|
* Get sessions by session ID
|
|
390
625
|
*/
|
|
@@ -701,6 +701,42 @@ function OxyServicesFedCMMixin(Base) {
|
|
|
701
701
|
// Storage blocked
|
|
702
702
|
}
|
|
703
703
|
}
|
|
704
|
+
/**
|
|
705
|
+
* List the authenticated user's authorized RP apps.
|
|
706
|
+
*
|
|
707
|
+
* Returns the intersection of the user's FedCM grants and the currently-
|
|
708
|
+
* approved RP catalog — what powers the "Connected apps" management UI in
|
|
709
|
+
* @oxyhq/services. Requires a real user session; service tokens are
|
|
710
|
+
* rejected by the underlying endpoint.
|
|
711
|
+
*/
|
|
712
|
+
async listAuthorizedApps() {
|
|
713
|
+
try {
|
|
714
|
+
const response = await this.makeRequest('GET', '/fedcm/me/authorized-apps', undefined, {
|
|
715
|
+
cache: true,
|
|
716
|
+
cacheTTL: 30 * 1000, // 30 second cache — short, this drives a manageable UI
|
|
717
|
+
});
|
|
718
|
+
return response.apps ?? [];
|
|
719
|
+
}
|
|
720
|
+
catch (error) {
|
|
721
|
+
throw this.handleError(error);
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
/**
|
|
725
|
+
* Revoke the authenticated user's authorization for a specific RP origin.
|
|
726
|
+
*
|
|
727
|
+
* The next FedCM sign-in from that origin will require explicit re-consent.
|
|
728
|
+
* The corresponding cache entry is invalidated so a subsequent
|
|
729
|
+
* `listAuthorizedApps()` call sees fresh data.
|
|
730
|
+
*/
|
|
731
|
+
async revokeAuthorizedApp(origin) {
|
|
732
|
+
try {
|
|
733
|
+
await this.makeRequest('DELETE', `/fedcm/me/authorized-apps/${encodeURIComponent(origin)}`, undefined, { cache: false });
|
|
734
|
+
this.clearCacheEntry('GET:/fedcm/me/authorized-apps');
|
|
735
|
+
}
|
|
736
|
+
catch (error) {
|
|
737
|
+
throw this.handleError(error);
|
|
738
|
+
}
|
|
739
|
+
}
|
|
704
740
|
},
|
|
705
741
|
_a.DEFAULT_CONFIG_URL = 'https://auth.oxy.so/fedcm.json',
|
|
706
742
|
_a.FEDCM_TIMEOUT = 15000 // 15 seconds for interactive
|
|
@@ -81,7 +81,37 @@ function OxyServicesPopupAuthMixin(Base) {
|
|
|
81
81
|
clientId: window.location.origin,
|
|
82
82
|
redirectUri: `${this.resolveAuthUrl()}/auth/callback`,
|
|
83
83
|
});
|
|
84
|
-
|
|
84
|
+
// If the caller pre-opened a popup on the raw user gesture (recommended
|
|
85
|
+
// path — see `openBlankPopup` and `PopupAuthOptions.popup`), navigate it
|
|
86
|
+
// to the auth URL instead of issuing a fresh `window.open` (which would
|
|
87
|
+
// be blocked once any prior `await` has consumed the user activation).
|
|
88
|
+
let popup;
|
|
89
|
+
const preOpened = options.popup ?? null;
|
|
90
|
+
if (preOpened) {
|
|
91
|
+
if (preOpened.closed) {
|
|
92
|
+
// The pre-opened popup is gone — distinguish a user cancel (they
|
|
93
|
+
// closed the blank window before sign-in could navigate it) from a
|
|
94
|
+
// blocker rejection. Lumping these together as "Popup blocked" is
|
|
95
|
+
// misleading: the popup was NOT blocked, it was opened successfully
|
|
96
|
+
// and then dismissed.
|
|
97
|
+
throw new OxyServices_errors_1.OxyAuthenticationError('Sign-in window was closed before authentication could start.');
|
|
98
|
+
}
|
|
99
|
+
try {
|
|
100
|
+
preOpened.location.replace(authUrl);
|
|
101
|
+
}
|
|
102
|
+
catch (replaceError) {
|
|
103
|
+
// `location.replace` can throw in sandboxed / cross-origin-locked
|
|
104
|
+
// environments. Fall back to `href` assignment, which is more
|
|
105
|
+
// permissive. Logged at debug-level so consumers can correlate
|
|
106
|
+
// unusual sign-in behaviour without producing noise in normal flows.
|
|
107
|
+
debug.warn('location.replace failed, falling back to location.href', replaceError);
|
|
108
|
+
preOpened.location.href = authUrl;
|
|
109
|
+
}
|
|
110
|
+
popup = preOpened;
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
popup = this.openCenteredPopup(authUrl, 'Oxy Sign In', width, height);
|
|
114
|
+
}
|
|
85
115
|
if (!popup) {
|
|
86
116
|
throw new OxyServices_errors_1.OxyAuthenticationError('Popup blocked. Please allow popups for this site and try again.');
|
|
87
117
|
}
|
|
@@ -224,6 +254,36 @@ function OxyServicesPopupAuthMixin(Base) {
|
|
|
224
254
|
document.body.removeChild(iframe);
|
|
225
255
|
}
|
|
226
256
|
}
|
|
257
|
+
/**
|
|
258
|
+
* Open a blank, centered popup window SYNCHRONOUSLY.
|
|
259
|
+
*
|
|
260
|
+
* Use this in a click (or other user-gesture) handler BEFORE any `await`
|
|
261
|
+
* to capture the transient user-activation. Pass the returned handle into
|
|
262
|
+
* `signInWithPopup({ popup })` once the async portion of the flow runs.
|
|
263
|
+
*
|
|
264
|
+
* Returns `null` if the browser's popup blocker rejected the open.
|
|
265
|
+
*
|
|
266
|
+
* @example
|
|
267
|
+
* ```typescript
|
|
268
|
+
* const onSignInClick = () => {
|
|
269
|
+
* const popup = oxyServices.openBlankPopup();
|
|
270
|
+
* (async () => {
|
|
271
|
+
* const silent = await oxyServices.silentSignInWithFedCM();
|
|
272
|
+
* if (silent) { popup?.close(); return; }
|
|
273
|
+
* await oxyServices.signInWithPopup({ popup });
|
|
274
|
+
* })();
|
|
275
|
+
* };
|
|
276
|
+
* ```
|
|
277
|
+
*/
|
|
278
|
+
openBlankPopup(width, height) {
|
|
279
|
+
if (typeof window === 'undefined') {
|
|
280
|
+
return null;
|
|
281
|
+
}
|
|
282
|
+
const ctor = this.constructor;
|
|
283
|
+
const w = width ?? ctor.POPUP_WIDTH;
|
|
284
|
+
const h = height ?? ctor.POPUP_HEIGHT;
|
|
285
|
+
return this.openCenteredPopup('about:blank', 'Oxy Sign In', w, h);
|
|
286
|
+
}
|
|
227
287
|
/**
|
|
228
288
|
* Open a centered popup window
|
|
229
289
|
*
|
|
@@ -218,6 +218,24 @@ function OxyServicesUserMixin(Base) {
|
|
|
218
218
|
throw this.handleError(error);
|
|
219
219
|
}
|
|
220
220
|
}
|
|
221
|
+
/**
|
|
222
|
+
* Update the authenticated user's notification preferences.
|
|
223
|
+
*
|
|
224
|
+
* Thin wrapper over `updateProfile` that constrains the patch to known
|
|
225
|
+
* notification channels — same persistence path, same cache invalidation,
|
|
226
|
+
* but type-safe at the call site.
|
|
227
|
+
*/
|
|
228
|
+
async updateNotificationPreferences(preferences) {
|
|
229
|
+
return this.updateProfile({ notificationPreferences: preferences });
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Update the authenticated user's general preferences (language, theme,
|
|
233
|
+
* reduce-motion, timezone). Persisted on the User document via
|
|
234
|
+
* `PUT /users/me` — same cache-invalidation behaviour as `updateProfile`.
|
|
235
|
+
*/
|
|
236
|
+
async updateUserPreferences(preferences) {
|
|
237
|
+
return this.updateProfile({ userPreferences: preferences });
|
|
238
|
+
}
|
|
221
239
|
/**
|
|
222
240
|
* Request account verification
|
|
223
241
|
*/
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Used by both @oxyhq/services (React Native) and @oxyhq/auth (Web) account stores.
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.createQuickAccount = exports.buildAccountsArray = exports.getAccountFallbackHandle = exports.getAccountDisplayName = exports.formatPublicKeyHandle = void 0;
|
|
7
|
+
exports.getAccountColor = exports.mergeAccountsFromRefreshAll = exports.createQuickAccount = exports.buildAccountsArray = exports.getAccountFallbackHandle = exports.getAccountDisplayName = exports.formatPublicKeyHandle = void 0;
|
|
8
8
|
const i18n_1 = require("../i18n");
|
|
9
9
|
/**
|
|
10
10
|
* Truncate a long public key for display, e.g. `0x12345678…`.
|
|
@@ -116,3 +116,66 @@ const createQuickAccount = (sessionId, userData, existingAccount, getFileDownloa
|
|
|
116
116
|
};
|
|
117
117
|
};
|
|
118
118
|
exports.createQuickAccount = createQuickAccount;
|
|
119
|
+
/**
|
|
120
|
+
* Merge a fresh `/auth/refresh-all` snapshot into an existing QuickAccount
|
|
121
|
+
* list, preserving any cached fields (`avatarUrl`) for slots that didn't
|
|
122
|
+
* change. The fresh response is canonical: the resulting list contains EXACTLY
|
|
123
|
+
* the slots present in `fresh`, sorted by `authuser` ascending. Stale stored
|
|
124
|
+
* accounts that no longer appear in `fresh` are dropped (the server already
|
|
125
|
+
* authoritatively cleared the corresponding cookie).
|
|
126
|
+
*
|
|
127
|
+
* @param stored Previously persisted QuickAccount list (any order).
|
|
128
|
+
* @param fresh Server's authoritative refresh-all response.
|
|
129
|
+
* @returns Canonical merged list, sorted by `authuser` asc.
|
|
130
|
+
*/
|
|
131
|
+
const mergeAccountsFromRefreshAll = (stored, fresh) => {
|
|
132
|
+
const storedByAuthuser = new Map();
|
|
133
|
+
if (stored) {
|
|
134
|
+
for (const account of stored) {
|
|
135
|
+
if (typeof account.authuser === 'number') {
|
|
136
|
+
storedByAuthuser.set(account.authuser, account);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
const merged = fresh.map((entry) => {
|
|
141
|
+
const previous = storedByAuthuser.get(entry.authuser);
|
|
142
|
+
// `entry.user` is null on the SDK legacy-fallback path; preserve any
|
|
143
|
+
// previously cached identity for that slot rather than overwriting
|
|
144
|
+
// it with blanks, and let the AuthManager's getCurrentUser() hydration
|
|
145
|
+
// refresh it on the next snapshot.
|
|
146
|
+
const wireUser = entry.user;
|
|
147
|
+
const username = wireUser?.username ?? previous?.username ?? '';
|
|
148
|
+
const displayName = (0, exports.getAccountDisplayName)({
|
|
149
|
+
name: wireUser?.name,
|
|
150
|
+
username,
|
|
151
|
+
});
|
|
152
|
+
const avatar = wireUser?.avatar ?? previous?.avatar ?? undefined;
|
|
153
|
+
const avatarUrl = previous && previous.avatar === avatar ? previous.avatarUrl : undefined;
|
|
154
|
+
return {
|
|
155
|
+
sessionId: entry.sessionId,
|
|
156
|
+
userId: wireUser?.id ?? previous?.userId,
|
|
157
|
+
username,
|
|
158
|
+
displayName,
|
|
159
|
+
avatar,
|
|
160
|
+
avatarUrl,
|
|
161
|
+
authuser: entry.authuser,
|
|
162
|
+
color: wireUser?.color ?? previous?.color ?? null,
|
|
163
|
+
};
|
|
164
|
+
});
|
|
165
|
+
merged.sort((a, b) => {
|
|
166
|
+
const aIdx = a.authuser ?? Number.POSITIVE_INFINITY;
|
|
167
|
+
const bIdx = b.authuser ?? Number.POSITIVE_INFINITY;
|
|
168
|
+
return aIdx - bIdx;
|
|
169
|
+
});
|
|
170
|
+
return merged;
|
|
171
|
+
};
|
|
172
|
+
exports.mergeAccountsFromRefreshAll = mergeAccountsFromRefreshAll;
|
|
173
|
+
/**
|
|
174
|
+
* Return the account's preferred Bloom color preset, or `null` if it has no
|
|
175
|
+
* preference. Centralises the `color ?? null` normalisation so consumers can
|
|
176
|
+
* drive per-account theming without duplicating the nullish-handling.
|
|
177
|
+
*/
|
|
178
|
+
const getAccountColor = (account) => {
|
|
179
|
+
return account.color ?? null;
|
|
180
|
+
};
|
|
181
|
+
exports.getAccountColor = getAccountColor;
|