@oxyhq/core 1.11.24 → 2.1.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 (150) 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 +121 -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/cjs/utils/coldBoot.js +71 -0
  36. package/dist/cjs/utils/fapiAutoDetect.js +88 -0
  37. package/dist/esm/.tsbuildinfo +1 -1
  38. package/dist/esm/AuthManager.js +678 -4
  39. package/dist/esm/AuthManagerTypes.js +12 -0
  40. package/dist/esm/CrossDomainAuth.js +45 -3
  41. package/dist/esm/OxyServices.base.js +16 -0
  42. package/dist/esm/i18n/locales/ar-SA.json +83 -0
  43. package/dist/esm/i18n/locales/ca-ES.json +83 -0
  44. package/dist/esm/i18n/locales/de-DE.json +83 -0
  45. package/dist/esm/i18n/locales/en-US.json +83 -0
  46. package/dist/esm/i18n/locales/es-ES.json +99 -4
  47. package/dist/esm/i18n/locales/fr-FR.json +83 -0
  48. package/dist/esm/i18n/locales/it-IT.json +83 -0
  49. package/dist/esm/i18n/locales/ja-JP.json +83 -0
  50. package/dist/esm/i18n/locales/ko-KR.json +83 -0
  51. package/dist/esm/i18n/locales/locales/ar-SA.json +83 -1
  52. package/dist/esm/i18n/locales/locales/ca-ES.json +83 -1
  53. package/dist/esm/i18n/locales/locales/de-DE.json +83 -1
  54. package/dist/esm/i18n/locales/locales/en-US.json +83 -0
  55. package/dist/esm/i18n/locales/locales/es-ES.json +99 -4
  56. package/dist/esm/i18n/locales/locales/fr-FR.json +83 -1
  57. package/dist/esm/i18n/locales/locales/it-IT.json +83 -1
  58. package/dist/esm/i18n/locales/locales/ja-JP.json +200 -117
  59. package/dist/esm/i18n/locales/locales/ko-KR.json +83 -1
  60. package/dist/esm/i18n/locales/locales/pt-PT.json +83 -1
  61. package/dist/esm/i18n/locales/locales/zh-CN.json +83 -1
  62. package/dist/esm/i18n/locales/pt-PT.json +83 -0
  63. package/dist/esm/i18n/locales/zh-CN.json +83 -0
  64. package/dist/esm/index.js +74 -26
  65. package/dist/esm/mixins/OxyServices.auth.js +235 -0
  66. package/dist/esm/mixins/OxyServices.fedcm.js +36 -0
  67. package/dist/esm/mixins/OxyServices.popup.js +61 -1
  68. package/dist/esm/mixins/OxyServices.user.js +18 -0
  69. package/dist/esm/utils/accountUtils.js +61 -0
  70. package/dist/esm/utils/coldBoot.js +68 -0
  71. package/dist/esm/utils/fapiAutoDetect.js +85 -0
  72. package/dist/types/.tsbuildinfo +1 -1
  73. package/dist/types/AuthManager.d.ts +243 -3
  74. package/dist/types/AuthManagerTypes.d.ts +68 -0
  75. package/dist/types/CrossDomainAuth.d.ts +23 -0
  76. package/dist/types/OxyServices.base.d.ts +14 -0
  77. package/dist/types/OxyServices.d.ts +7 -0
  78. package/dist/types/index.d.ts +31 -17
  79. package/dist/types/mixins/OxyServices.analytics.d.ts +1 -0
  80. package/dist/types/mixins/OxyServices.appData.d.ts +1 -0
  81. package/dist/types/mixins/OxyServices.assets.d.ts +4 -1
  82. package/dist/types/mixins/OxyServices.auth.d.ts +73 -1
  83. package/dist/types/mixins/OxyServices.contacts.d.ts +1 -0
  84. package/dist/types/mixins/OxyServices.developer.d.ts +1 -0
  85. package/dist/types/mixins/OxyServices.devices.d.ts +1 -0
  86. package/dist/types/mixins/OxyServices.features.d.ts +2 -5
  87. package/dist/types/mixins/OxyServices.fedcm.d.ts +34 -0
  88. package/dist/types/mixins/OxyServices.karma.d.ts +1 -0
  89. package/dist/types/mixins/OxyServices.language.d.ts +1 -0
  90. package/dist/types/mixins/OxyServices.location.d.ts +1 -0
  91. package/dist/types/mixins/OxyServices.managedAccounts.d.ts +1 -0
  92. package/dist/types/mixins/OxyServices.payment.d.ts +1 -0
  93. package/dist/types/mixins/OxyServices.popup.d.ts +40 -0
  94. package/dist/types/mixins/OxyServices.privacy.d.ts +1 -0
  95. package/dist/types/mixins/OxyServices.redirect.d.ts +1 -0
  96. package/dist/types/mixins/OxyServices.security.d.ts +1 -0
  97. package/dist/types/mixins/OxyServices.topics.d.ts +1 -0
  98. package/dist/types/mixins/OxyServices.user.d.ts +16 -1
  99. package/dist/types/mixins/OxyServices.utility.d.ts +1 -0
  100. package/dist/types/models/interfaces.d.ts +98 -0
  101. package/dist/types/models/session.d.ts +8 -0
  102. package/dist/types/utils/accountUtils.d.ts +33 -0
  103. package/dist/types/utils/coldBoot.d.ts +102 -0
  104. package/dist/types/utils/fapiAutoDetect.d.ts +37 -0
  105. package/package.json +9 -18
  106. package/src/AuthManager.ts +776 -7
  107. package/src/AuthManagerTypes.ts +72 -0
  108. package/src/CrossDomainAuth.ts +54 -3
  109. package/src/OxyServices.base.ts +17 -0
  110. package/src/OxyServices.ts +7 -0
  111. package/src/__tests__/authManager.cookiePath.test.ts +339 -0
  112. package/src/__tests__/authManager.security.test.ts +342 -0
  113. package/src/__tests__/crossDomainAuth.test.ts +191 -0
  114. package/src/i18n/locales/ar-SA.json +83 -1
  115. package/src/i18n/locales/ca-ES.json +83 -1
  116. package/src/i18n/locales/de-DE.json +83 -1
  117. package/src/i18n/locales/en-US.json +83 -0
  118. package/src/i18n/locales/es-ES.json +99 -4
  119. package/src/i18n/locales/fr-FR.json +83 -1
  120. package/src/i18n/locales/it-IT.json +83 -1
  121. package/src/i18n/locales/ja-JP.json +200 -117
  122. package/src/i18n/locales/ko-KR.json +83 -1
  123. package/src/i18n/locales/pt-PT.json +83 -1
  124. package/src/i18n/locales/zh-CN.json +83 -1
  125. package/src/index.ts +309 -112
  126. package/src/mixins/OxyServices.auth.ts +268 -1
  127. package/src/mixins/OxyServices.fedcm.ts +63 -0
  128. package/src/mixins/OxyServices.popup.ts +79 -1
  129. package/src/mixins/OxyServices.user.ts +33 -1
  130. package/src/mixins/__tests__/popup.test.ts +307 -0
  131. package/src/mixins/__tests__/sessionBaseUrl.test.ts +61 -0
  132. package/src/models/interfaces.ts +116 -0
  133. package/src/models/session.ts +8 -0
  134. package/src/utils/__tests__/coldBoot.test.ts +226 -0
  135. package/src/utils/__tests__/fapiAutoDetect.test.ts +93 -0
  136. package/src/utils/accountUtils.ts +84 -0
  137. package/src/utils/coldBoot.ts +136 -0
  138. package/src/utils/fapiAutoDetect.ts +82 -0
  139. package/dist/cjs/crypto/index.js +0 -22
  140. package/dist/cjs/shared/index.js +0 -70
  141. package/dist/cjs/utils/index.js +0 -26
  142. package/dist/esm/crypto/index.js +0 -13
  143. package/dist/esm/shared/index.js +0 -31
  144. package/dist/esm/utils/index.js +0 -7
  145. package/dist/types/crypto/index.d.ts +0 -11
  146. package/dist/types/shared/index.d.ts +0 -28
  147. package/dist/types/utils/index.d.ts +0 -6
  148. package/src/crypto/index.ts +0 -30
  149. package/src/shared/index.ts +0 -82
  150. package/src/utils/index.ts +0 -21
@@ -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
  *
@@ -215,6 +215,24 @@ export function OxyServicesUserMixin(Base) {
215
215
  throw this.handleError(error);
216
216
  }
217
217
  }
218
+ /**
219
+ * Update the authenticated user's notification preferences.
220
+ *
221
+ * Thin wrapper over `updateProfile` that constrains the patch to known
222
+ * notification channels — same persistence path, same cache invalidation,
223
+ * but type-safe at the call site.
224
+ */
225
+ async updateNotificationPreferences(preferences) {
226
+ return this.updateProfile({ notificationPreferences: preferences });
227
+ }
228
+ /**
229
+ * Update the authenticated user's general preferences (language, theme,
230
+ * reduce-motion, timezone). Persisted on the User document via
231
+ * `PUT /users/me` — same cache-invalidation behaviour as `updateProfile`.
232
+ */
233
+ async updateUserPreferences(preferences) {
234
+ return this.updateProfile({ userPreferences: preferences });
235
+ }
218
236
  /**
219
237
  * Request account verification
220
238
  */
@@ -108,3 +108,64 @@ export const createQuickAccount = (sessionId, userData, existingAccount, getFile
108
108
  avatarUrl,
109
109
  };
110
110
  };
111
+ /**
112
+ * Merge a fresh `/auth/refresh-all` snapshot into an existing QuickAccount
113
+ * list, preserving any cached fields (`avatarUrl`) for slots that didn't
114
+ * change. The fresh response is canonical: the resulting list contains EXACTLY
115
+ * the slots present in `fresh`, sorted by `authuser` ascending. Stale stored
116
+ * accounts that no longer appear in `fresh` are dropped (the server already
117
+ * authoritatively cleared the corresponding cookie).
118
+ *
119
+ * @param stored Previously persisted QuickAccount list (any order).
120
+ * @param fresh Server's authoritative refresh-all response.
121
+ * @returns Canonical merged list, sorted by `authuser` asc.
122
+ */
123
+ export const mergeAccountsFromRefreshAll = (stored, fresh) => {
124
+ const storedByAuthuser = new Map();
125
+ if (stored) {
126
+ for (const account of stored) {
127
+ if (typeof account.authuser === 'number') {
128
+ storedByAuthuser.set(account.authuser, account);
129
+ }
130
+ }
131
+ }
132
+ const merged = fresh.map((entry) => {
133
+ const previous = storedByAuthuser.get(entry.authuser);
134
+ // `entry.user` is null on the SDK legacy-fallback path; preserve any
135
+ // previously cached identity for that slot rather than overwriting
136
+ // it with blanks, and let the AuthManager's getCurrentUser() hydration
137
+ // refresh it on the next snapshot.
138
+ const wireUser = entry.user;
139
+ const username = wireUser?.username ?? previous?.username ?? '';
140
+ const displayName = getAccountDisplayName({
141
+ name: wireUser?.name,
142
+ username,
143
+ });
144
+ const avatar = wireUser?.avatar ?? previous?.avatar ?? undefined;
145
+ const avatarUrl = previous && previous.avatar === avatar ? previous.avatarUrl : undefined;
146
+ return {
147
+ sessionId: entry.sessionId,
148
+ userId: wireUser?.id ?? previous?.userId,
149
+ username,
150
+ displayName,
151
+ avatar,
152
+ avatarUrl,
153
+ authuser: entry.authuser,
154
+ color: wireUser?.color ?? previous?.color ?? null,
155
+ };
156
+ });
157
+ merged.sort((a, b) => {
158
+ const aIdx = a.authuser ?? Number.POSITIVE_INFINITY;
159
+ const bIdx = b.authuser ?? Number.POSITIVE_INFINITY;
160
+ return aIdx - bIdx;
161
+ });
162
+ return merged;
163
+ };
164
+ /**
165
+ * Return the account's preferred Bloom color preset, or `null` if it has no
166
+ * preference. Centralises the `color ?? null` normalisation so consumers can
167
+ * drive per-account theming without duplicating the nullish-handling.
168
+ */
169
+ export const getAccountColor = (account) => {
170
+ return account.color ?? null;
171
+ };
@@ -0,0 +1,68 @@
1
+ /**
2
+ * coldBoot — a pure, ordered, short-circuit runner for "cold boot"
3
+ * authentication resolution.
4
+ *
5
+ * On a fresh page load / app launch the SDK may have several ways to recover an
6
+ * existing session (silent FedCM, a persisted refresh token, a cross-domain
7
+ * claim, an explicit popup flow, …). They must be attempted in a *deterministic
8
+ * order*, and the FIRST one that yields a session wins — every later step is
9
+ * skipped. This module encodes exactly that contract and nothing else.
10
+ *
11
+ * Design constraints (all enforced):
12
+ * - PURE: no DOM, no `navigator`, no `window`, no React, no platform globals.
13
+ * - NO module-level mutable state. Every call to {@link runColdBoot} is fully
14
+ * self-contained, so it is safe under bundler re-evaluation (e.g. the Metro
15
+ * web bundle, which is precisely why the FedCM silent-SSO guard had to live
16
+ * in consumers rather than a core singleton).
17
+ * - Architecture-agnostic: both candidate cross-domain SSO designs consume
18
+ * this same primitive; it knows nothing about HOW a step resolves a session.
19
+ *
20
+ * A step is skipped (without running) when its `enabled` predicate returns
21
+ * false. Any thrown error — from either `enabled` or `run` — is reported via
22
+ * `onStepError` and treated as a non-fatal skip, so one broken recovery path
23
+ * can never prevent a later, healthy one from succeeding.
24
+ */
25
+ /**
26
+ * Run the ordered cold-boot steps and resolve to the first recovered session,
27
+ * or `unauthenticated` if none recovers one.
28
+ *
29
+ * Semantics:
30
+ * 1. Iterate `steps` in order.
31
+ * 2. If a step has an `enabled` predicate, call it inside try/catch:
32
+ * - throw → report via `onStepError(id, err)` → treat as disabled → continue.
33
+ * - returns false → continue (skip, `run` not called).
34
+ * 3. Otherwise await `step.run()` inside try/catch:
35
+ * - throw → report via `onStepError(id, err)` → continue.
36
+ * - `{ kind: 'session' }` → return `{ kind: 'session', via: step.id, session }`.
37
+ * - `{ kind: 'skip' }` → continue.
38
+ * 4. After the loop with no winner → `{ kind: 'unauthenticated' }`.
39
+ */
40
+ export async function runColdBoot(options) {
41
+ const { steps, onStepError } = options;
42
+ for (const step of steps) {
43
+ if (step.enabled) {
44
+ let isEnabled;
45
+ try {
46
+ isEnabled = step.enabled();
47
+ }
48
+ catch (error) {
49
+ onStepError?.(step.id, error);
50
+ continue;
51
+ }
52
+ if (!isEnabled)
53
+ continue;
54
+ }
55
+ let result;
56
+ try {
57
+ result = await step.run();
58
+ }
59
+ catch (error) {
60
+ onStepError?.(step.id, error);
61
+ continue;
62
+ }
63
+ if (result.kind === 'session') {
64
+ return { kind: 'session', via: step.id, session: result.session };
65
+ }
66
+ }
67
+ return { kind: 'unauthenticated' };
68
+ }
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Auto-detect the FAPI (IdP) URL from the current browser hostname.
3
+ *
4
+ * This is the canonical cross-domain IdP-resolution primitive for the Oxy
5
+ * ecosystem. Both candidate cross-domain SSO designs derive `auth.<rp-apex>`
6
+ * through this helper; do not fork it.
7
+ *
8
+ * Clerk-style multi-domain SSO depends on the IdP being reachable on a
9
+ * subdomain of the RP's own apex (e.g. `auth.mention.earth` CNAMEd to the
10
+ * central Oxy IdP). That way every FedCM endpoint, the session cookie,
11
+ * and any popup/redirect target are same-site with the RP — the only way
12
+ * to get first-party cookies in Safari ITP and Firefox Total Cookie
13
+ * Protection.
14
+ *
15
+ * This helper computes `https://auth.<rp-apex>` from
16
+ * `window.location.hostname` so a consuming app doesn't have to pass
17
+ * `authWebUrl` explicitly. Returns `undefined` for environments where
18
+ * auto-detection would be wrong:
19
+ *
20
+ * - SSR / non-browser (no `window`).
21
+ * - `localhost`, `127.0.0.1`, IPv4/IPv6 literals.
22
+ * - Hostnames with fewer than two labels.
23
+ * - Hostnames whose trailing two labels form a known multi-part public
24
+ * suffix (e.g. `co.uk`), where the naive `labels.slice(-2)` apex would be
25
+ * an attacker-registrable suffix like `auth.co.uk` rather than the real
26
+ * registrable domain.
27
+ *
28
+ * When the page is already loaded ON the IdP itself (`auth.<anything>`),
29
+ * the helper returns the current origin so the SDK keeps everything
30
+ * same-origin instead of hopping to a different IdP host.
31
+ *
32
+ * The IdP backend independently derives `iss`, `provider_urls`, and the
33
+ * `fedcm.json` icon URLs from the request host
34
+ * (`packages/auth/server/index.ts`), so an honest CNAME pair is all that
35
+ * is required for end-to-end FedCM correctness — no per-RP config.
36
+ */
37
+ /**
38
+ * Known multi-part public suffixes where the registrable domain is the LAST
39
+ * THREE labels, not two. Deriving an apex from `labels.slice(-2)` against any
40
+ * of these would yield an attacker-registrable suffix (e.g. `auth.co.uk`),
41
+ * so we bail out instead.
42
+ *
43
+ * This is intentionally a small, explicit allow-list rather than the full
44
+ * Public Suffix List — it covers the suffixes the Oxy ecosystem's RPs use.
45
+ * Any multi-part-TLD RP MUST extend this set (or wire in a proper PSL check)
46
+ * before relying on this helper, otherwise auto-detection silently bails to
47
+ * `undefined` and the consumer must pass `authWebUrl` explicitly.
48
+ */
49
+ const MULTIPART_TLDS = new Set([
50
+ 'co.uk',
51
+ 'com.au',
52
+ 'co.jp',
53
+ 'co.nz',
54
+ 'com.br',
55
+ 'co.za',
56
+ 'com.mx',
57
+ 'co.in',
58
+ 'co.kr',
59
+ 'com.sg',
60
+ ]);
61
+ export function autoDetectAuthWebUrl(location = typeof window !== 'undefined' ? window.location : undefined) {
62
+ if (!location)
63
+ return undefined;
64
+ const { hostname, protocol } = location;
65
+ if (!hostname)
66
+ return undefined;
67
+ if (protocol !== 'https:' && protocol !== 'http:')
68
+ return undefined;
69
+ if (hostname === 'localhost' || hostname === '127.0.0.1')
70
+ return undefined;
71
+ if (/^\d+\.\d+\.\d+\.\d+$/.test(hostname))
72
+ return undefined;
73
+ if (hostname.startsWith('['))
74
+ return undefined;
75
+ if (hostname.startsWith('auth.')) {
76
+ return `${protocol}//${hostname}`;
77
+ }
78
+ const labels = hostname.split('.');
79
+ if (labels.length < 2)
80
+ return undefined;
81
+ if (MULTIPART_TLDS.has(labels.slice(-2).join('.')))
82
+ return undefined;
83
+ const apex = labels.slice(-2).join('.');
84
+ return `${protocol}//auth.${apex}`;
85
+ }