@vectoriox/iox-ui 5.100.0 → 5.101.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.
@@ -14,10 +14,11 @@ export enum SignInPurpose {
14
14
  Portal = 'portal',
15
15
  }
16
16
 
17
- /** A provider the broker runs. Google is live; the rest join one adapter at a time (board 18). */
17
+ /** A provider the broker runs (board 18). The enum's order is the order every sign-in shows them in. Each id is the path
18
+ * segment of the ONE address registered with that provider: `https://auth.iox.studio/<id>/callback`. */
18
19
  export enum SignInProvider {
19
20
  Google = 'google',
20
- Meta = 'meta',
21
+ Facebook = 'facebook',
21
22
  GitHub = 'github',
22
23
  LinkedIn = 'linkedin',
23
24
  }
@@ -32,17 +33,21 @@ export interface SignInProviderSpec {
32
33
  readonly protocol: SignInProtocol;
33
34
  /** The answer is signed, so a studio can check it itself — the only kind an admin may sign in with (C-D6). */
34
35
  readonly signedAnswer: boolean;
35
- /** Running on the broker today. */
36
+ /** The broker has an adapter for it. Whether it is ON (both keys in the broker's env) is the broker's answer to
37
+ * `BrokerApiRoute.Providers`, read at run time — never a release. */
36
38
  readonly live: boolean;
37
39
  }
38
40
 
39
41
  export const SIGN_IN_PROVIDER_SPECS: Readonly<Record<SignInProvider, SignInProviderSpec>> = Object.freeze({
40
42
  [SignInProvider.Google]: { protocol: SignInProtocol.Oidc, signedAnswer: true, live: true },
41
- [SignInProvider.LinkedIn]: { protocol: SignInProtocol.Oidc, signedAnswer: true, live: false },
42
- [SignInProvider.Meta]: { protocol: SignInProtocol.OAuth2, signedAnswer: false, live: false },
43
- [SignInProvider.GitHub]: { protocol: SignInProtocol.OAuth2, signedAnswer: false, live: false },
43
+ [SignInProvider.Facebook]: { protocol: SignInProtocol.OAuth2, signedAnswer: false, live: true },
44
+ [SignInProvider.GitHub]: { protocol: SignInProtocol.OAuth2, signedAnswer: false, live: true },
45
+ [SignInProvider.LinkedIn]: { protocol: SignInProtocol.Oidc, signedAnswer: true, live: true },
44
46
  });
45
47
 
48
+ /** Every provider, in the order a sign-in shows them. */
49
+ export const SIGN_IN_PROVIDERS: ReadonlyArray<SignInProvider> = Object.freeze(Object.values(SignInProvider));
50
+
46
51
  export function isSignInProvider(value: unknown): value is SignInProvider {
47
52
  return typeof value === 'string' && (Object.values(SignInProvider) as string[]).includes(value);
48
53
  }
@@ -72,8 +77,29 @@ export const SIGN_IN_HANDOFF_TTL_SECONDS = 60;
72
77
  export enum BrokerApiRoute {
73
78
  Tickets = 'instances/me/sign-in/tickets',
74
79
  Redeem = 'instances/me/sign-in/redeem',
80
+ /** `GET` → only the providers that are ON: `{ "google": true }` (`SignInProvidersAnswer`). */
81
+ Providers = 'instances/me/sign-in/providers',
75
82
  }
76
83
 
84
+ /** `GET instances/me/sign-in/providers` — each provider that is ON, `true`; an off one is absent. */
85
+ export type SignInProvidersAnswer = Partial<Record<SignInProvider, true>>;
86
+
87
+ /** The providers ON in a broker's answer, in the order a sign-in shows them; anything else in the body is ignored. */
88
+ export function providersOn(answer: unknown): SignInProvider[] {
89
+ if (!answer || typeof answer !== 'object' || Array.isArray(answer)) return [];
90
+ const on = answer as Record<string, unknown>;
91
+ return SIGN_IN_PROVIDERS.filter(p => on[p] === true);
92
+ }
93
+
94
+ /** The providers ON at the broker that may serve `purpose` (C-D6: a team member only with a signed answer). */
95
+ export function providersServing(on: readonly SignInProvider[], purpose: SignInPurpose): SignInProvider[] {
96
+ const set = new Set(on);
97
+ return SIGN_IN_PROVIDERS.filter(p => set.has(p) && SIGN_IN_PROVIDER_SPECS[p].live && providerServes(p, purpose));
98
+ }
99
+
100
+ /** How long a studio or the portal may keep the broker's providers answer before asking again. */
101
+ export const SIGN_IN_PROVIDERS_CACHE_SECONDS = 60;
102
+
77
103
  /** The browser's routes on `auth.iox.studio`, one pair per provider. */
78
104
  export enum BrokerBrowserRoute {
79
105
  Start = 'start',
@@ -150,6 +176,8 @@ export enum BrokerRefusalCode {
150
176
  CodeUsedOrExpired = 'code-used-or-expired',
151
177
  /** 403 — another tenant's code. */
152
178
  NotYours = 'not-yours',
179
+ /** 400 — a purpose this asker may not use, or a provider that may not serve it (C-D6). */
180
+ InvalidRequest = 'invalid-request',
153
181
  }
154
182
 
155
183
  export const BROKER_REFUSAL_STATUS: Readonly<Record<BrokerRefusalCode, number>> = Object.freeze({
@@ -159,6 +187,7 @@ export const BROKER_REFUSAL_STATUS: Readonly<Record<BrokerRefusalCode, number>>
159
187
  [BrokerRefusalCode.CodeUnknown]: 404,
160
188
  [BrokerRefusalCode.CodeUsedOrExpired]: 410,
161
189
  [BrokerRefusalCode.NotYours]: 403,
190
+ [BrokerRefusalCode.InvalidRequest]: 400,
162
191
  });
163
192
 
164
193
  export function isBrokerRefusalCode(value: unknown): value is BrokerRefusalCode {
@@ -171,6 +200,14 @@ export function isBrokerRefusalCode(value: unknown): value is BrokerRefusalCode
171
200
  export const SIGN_IN_HANDOFF_PARAM = 'iox_signin';
172
201
  /** The failure's query parameter on the return address. */
173
202
  export const SIGN_IN_ERROR_PARAM = 'iox_signin_error';
203
+ /** Beside a failure a studio sends back: the provider it was (`?iox_signin_via=github`), so the words can name it. */
204
+ export const SIGN_IN_VIA_PARAM = 'iox_signin_via';
205
+ /**
206
+ * The binding parameter on every return address a studio or the portal asks the broker for: `iox_sb=<sha256 of the
207
+ * random value in the starting browser's httpOnly cookie>`. The redeemed `returnUrl` must carry THIS browser's hash — a
208
+ * hand-off started in another browser is refused (login CSRF).
209
+ */
210
+ export const SIGN_IN_BINDING_PARAM = 'iox_sb';
174
211
 
175
212
  /** Why the browser came back without a person. */
176
213
  export enum SignInReturnError {
@@ -1,6 +1,7 @@
1
1
  import { isSameOriginPath } from './guards';
2
2
  import { isEmailCodeShape, normalizeEmailCode, normalizeSignInEmail, SiteCustomer } from './site-auth';
3
- import { brokerStartUrl, SignInProvider } from './sign-in';
3
+ import { brokerStartUrl, SIGN_IN_PROVIDERS, SignInProvider } from './sign-in';
4
+ import { EMAIL_CODE_PROVIDER, SITE_SIGN_IN_METHODS, SiteSignInMethod } from './site-methods';
4
5
  import { SiteSignInRefusalCode, siteSignInCodeOf } from './words';
5
6
 
6
7
  /**
@@ -19,6 +20,8 @@ export interface SiteAuthTransport {
19
20
  /** Check the code; the signed-in buyer. */
20
21
  verifyCode(email: string, code: string): Promise<SiteCustomer>;
21
22
  signOut(): Promise<void>;
23
+ /** The ways this site lets a buyer sign in (`SiteAuthRoute.Methods`). Absent = the parts hide nothing. */
24
+ methods?(): Promise<SiteSignInMethod[]>;
22
25
  }
23
26
 
24
27
  /** A refused transport call, carrying the code the visitor's words come from (`signInRefusal`). */
@@ -55,7 +58,8 @@ export interface SimulatedSiteAuthTransport extends SiteAuthTransport {
55
58
  * sample buyer under the typed email, any other six digits are `code-wrong`; a provider's start answers the broker's
56
59
  * address with a sample ticket (the canvas host never follows it).
57
60
  */
58
- export function simulatedSiteAuthTransport(start: SiteCustomer | null = null): SimulatedSiteAuthTransport {
61
+ export function simulatedSiteAuthTransport(start: SiteCustomer | null = null,
62
+ methods: readonly SiteSignInMethod[] = SITE_SIGN_IN_METHODS): SimulatedSiteAuthTransport {
59
63
  let customer: SiteCustomer | null = start;
60
64
  const sentTo = new Set<string>();
61
65
  return {
@@ -88,6 +92,9 @@ export function simulatedSiteAuthTransport(start: SiteCustomer | null = null): S
88
92
  async signOut() {
89
93
  customer = null;
90
94
  },
95
+ async methods() {
96
+ return [EMAIL_CODE_PROVIDER, ...SIGN_IN_PROVIDERS.filter(p => methods.includes(p))];
97
+ },
91
98
  };
92
99
  }
93
100
 
@@ -98,6 +105,7 @@ export const NO_SITE_AUTH_TRANSPORT: SiteAuthTransport = Object.freeze({
98
105
  sendCode: async () => { throw new SiteAuthError(SiteSignInRefusalCode.Network); },
99
106
  verifyCode: async () => { throw new SiteAuthError(SiteSignInRefusalCode.Network); },
100
107
  signOut: async () => undefined,
108
+ methods: async () => [EMAIL_CODE_PROVIDER],
101
109
  });
102
110
 
103
111
  // ── what a page shows of the buyer ───────────────────────────────────────────────────────────
@@ -17,6 +17,8 @@ export enum SiteAuthRoute {
17
17
  /** `GET` → `{ customer }` (null when signed out). */
18
18
  Me = 'me',
19
19
  MyOrders = 'me/orders',
20
+ /** `GET` → `{ methods }` — the ways this site lets a buyer sign in right now (`siteSignInMethods`). Public. */
21
+ Methods = 'auth/methods',
20
22
  }
21
23
 
22
24
  /** Every route a site's sign-in calls, by name (the provider pair is per provider — `siteProviderPath`). */
@@ -136,6 +138,17 @@ export function signInStateCookieName(orgId: string): string {
136
138
  return `${SIGN_IN_STATE_COOKIE_PREFIX}${orgId}`;
137
139
  }
138
140
 
141
+ /**
142
+ * A cookie no sibling host can plant (vectoriox/iox-cms#73 — cookie tossing from another `*.iox.studio`): over https the
143
+ * name takes the `__Host-` prefix, which a browser accepts only `Secure`, with `Path=/` and no `Domain`. A server that
144
+ * sets one with this name must set exactly those; plain http (local development) keeps the bare name.
145
+ */
146
+ export const HOST_ONLY_COOKIE_PREFIX = '__Host-';
147
+
148
+ export function hostOnlyCookieName(name: string, secure: boolean): string {
149
+ return secure ? `${HOST_ONLY_COOKIE_PREFIX}${name}` : name;
150
+ }
151
+
139
152
  // ── the email code ─────────────────────────────────────────────────────────────────────────────
140
153
 
141
154
  export const EMAIL_CODE_LENGTH = 6;
@@ -180,3 +193,16 @@ export function accountHref(orgLabel?: string | null): string {
180
193
  const label = String(orgLabel ?? '').replace(/^\/+|\/+$/g, '');
181
194
  return label ? `/${encodeURIComponent(label)}/${ACCOUNT_PATH}` : `/${ACCOUNT_PATH}`;
182
195
  }
196
+
197
+ /** The account page's segment for one order: `/<orgLabel>/account/orders/<number>`. */
198
+ export const ACCOUNT_ORDERS_SEGMENT = 'orders';
199
+
200
+ /** One of the signed-in buyer's own orders, under the account page — read by the session, never by a link token. */
201
+ export function accountOrderHref(orgLabel: string | null | undefined, orderNumber: string | number): string {
202
+ return `${accountHref(orgLabel)}/${ACCOUNT_ORDERS_SEGMENT}/${encodeURIComponent(String(orderNumber))}`;
203
+ }
204
+
205
+ /** `GET /api/site/<org>/me/orders/<number>` — one order of the signed-in buyer (404 for anyone else's). */
206
+ export function siteMyOrderPath(orgId: string, orderNumber: string | number): string {
207
+ return `${siteAuthPath(orgId, SiteAuthRoute.MyOrders)}/${encodeURIComponent(String(orderNumber))}`;
208
+ }
@@ -0,0 +1,78 @@
1
+ import { providersServing, SIGN_IN_PROVIDERS, SignInProvider, SignInPurpose } from './sign-in';
2
+
3
+ /**
4
+ * Which ways a studio's SITE lets a buyer sign in (Settings ▸ Sign-in, board 18): the email code always, and each
5
+ * provider the owner switched on — while the broker has it ON and it may serve a buyer (C-D6). ONE rule for the studio
6
+ * that enforces it (iox-cms), the site that shows it (the engine, the canvas) and the screen that sets it (cms-client).
7
+ */
8
+
9
+ /** The email code — a `customerIdentities.provider` value beside the broker's providers; it never touches the broker. */
10
+ export const EMAIL_CODE_PROVIDER = 'email-code' as const;
11
+ export type EmailCodeProvider = typeof EMAIL_CODE_PROVIDER;
12
+
13
+ /** A way a buyer signs in, and the `customerIdentities.provider` it is stored as. */
14
+ export type SiteSignInMethod = EmailCodeProvider | SignInProvider;
15
+
16
+ /** Every method, in the order a sign-in shows them. */
17
+ export const SITE_SIGN_IN_METHODS: ReadonlyArray<SiteSignInMethod> = Object.freeze([EMAIL_CODE_PROVIDER, ...SIGN_IN_PROVIDERS]);
18
+
19
+ export function isSiteSignInMethod(value: unknown): value is SiteSignInMethod {
20
+ return typeof value === 'string' && (SITE_SIGN_IN_METHODS as readonly string[]).includes(value);
21
+ }
22
+
23
+ /** The settings type a studio's org stores its choice under (`settings` collection, one row per org). */
24
+ export const SITE_SIGN_IN_SETTINGS_TYPE = 'signIn';
25
+
26
+ /** What the owner chose: each provider on or off for buyers. The email code is not a choice — it is always on. */
27
+ export interface SiteSignInSettings {
28
+ providers: Record<SignInProvider, boolean>;
29
+ }
30
+
31
+ /** A studio that never chose: Google on (C-D6 — "Google on by default, the others as owner switches"). */
32
+ export const DEFAULT_SITE_SIGN_IN_SETTINGS: Readonly<SiteSignInSettings> = Object.freeze({
33
+ providers: Object.freeze({
34
+ [SignInProvider.Google]: true,
35
+ [SignInProvider.Facebook]: false,
36
+ [SignInProvider.GitHub]: false,
37
+ [SignInProvider.LinkedIn]: false,
38
+ }) as Record<SignInProvider, boolean>,
39
+ });
40
+
41
+ /** Any stored or posted value as a whole setting: every provider present, booleans only, unknown keys dropped. */
42
+ export function normalizeSiteSignInSettings(raw: unknown): SiteSignInSettings {
43
+ const given = raw && typeof raw === 'object' ? (raw as { providers?: unknown }).providers : undefined;
44
+ const map = given && typeof given === 'object' && !Array.isArray(given) ? given as Record<string, unknown> : {};
45
+ const providers = {} as Record<SignInProvider, boolean>;
46
+ for (const p of SIGN_IN_PROVIDERS) providers[p] = typeof map[p] === 'boolean' ? map[p] as boolean : DEFAULT_SITE_SIGN_IN_SETTINGS.providers[p];
47
+ return { providers };
48
+ }
49
+
50
+ /** The methods a site offers right now: the email code, then every provider the owner switched on that the broker has
51
+ * ON (`brokerOn`) and that may serve a buyer. */
52
+ export function siteSignInMethods(settings: unknown, brokerOn: readonly SignInProvider[]): SiteSignInMethod[] {
53
+ const chosen = normalizeSiteSignInSettings(settings).providers;
54
+ return [EMAIL_CODE_PROVIDER, ...providersServing(brokerOn, SignInPurpose.Site).filter(p => chosen[p])];
55
+ }
56
+
57
+ /** May a buyer start `provider` on this site right now? */
58
+ export function siteOffersProvider(settings: unknown, brokerOn: readonly SignInProvider[], provider: SignInProvider): boolean {
59
+ return siteSignInMethods(settings, brokerOn).includes(provider);
60
+ }
61
+
62
+ /** `GET api/site/<org>/auth/methods` — public, cacheable. */
63
+ export interface SiteSignInMethodsAnswer {
64
+ methods: SiteSignInMethod[];
65
+ }
66
+
67
+ /** The methods in an answer (unknown values dropped, in the shown order); the email code is always one of them. */
68
+ export function siteSignInMethodsOf(answer: unknown): SiteSignInMethod[] {
69
+ const listed = answer && typeof answer === 'object' ? (answer as { methods?: unknown }).methods : undefined;
70
+ const set = new Set(Array.isArray(listed) ? listed.filter(isSiteSignInMethod) : []);
71
+ set.add(EMAIL_CODE_PROVIDER);
72
+ return SITE_SIGN_IN_METHODS.filter(m => set.has(m));
73
+ }
74
+
75
+ /** The providers among a site's methods. */
76
+ export function siteSignInProviders(methods: readonly SiteSignInMethod[]): SignInProvider[] {
77
+ return SIGN_IN_PROVIDERS.filter(p => methods.includes(p));
78
+ }
@@ -1,4 +1,5 @@
1
- import { BrokerRefusalCode, SignInReturnError } from './sign-in';
1
+ import { signInProviderName } from './provider-marks';
2
+ import { BrokerRefusalCode, isSignInProvider, readSignInReturn, SIGN_IN_ERROR_PARAM, SIGN_IN_VIA_PARAM, SignInProvider, SignInReturnError } from './sign-in';
2
3
 
3
4
  /**
4
5
  * The sign-in dialog's words and its refusals, in English and Hebrew. A string-rendered site has no translation
@@ -29,7 +30,8 @@ export enum SignInWord {
29
30
  SignIn = 'signIn',
30
31
  SignInTo = 'signInTo',
31
32
  Why = 'why',
32
- ContinueWithGoogle = 'continueWithGoogle',
33
+ /** `{provider}` = the brand's own name (`signInProviderName`), never translated. */
34
+ ContinueWith = 'continueWith',
33
35
  Or = 'or',
34
36
  Email = 'email',
35
37
  EmailPlaceholder = 'emailPlaceholder',
@@ -49,6 +51,12 @@ export enum SignInWord {
49
51
  SignedIn = 'signedIn',
50
52
  SignedOut = 'signedOut',
51
53
  NoPassword = 'noPassword',
54
+ /** Before the checkout's "Sign in". */
55
+ HaveAccount = 'haveAccount',
56
+ /** The account page with no orders. */
57
+ NoOrders = 'noOrders',
58
+ /** An order row on the account page: `{date}`. */
59
+ PlacedOn = 'placedOn',
52
60
  }
53
61
 
54
62
  /** `{site}`, `{email}`, `{name}`, `{minutes}` are filled by `signInWord`. */
@@ -56,7 +64,7 @@ export const SIGN_IN_WORDS: Readonly<Record<SignInWord, SignInLabel>> = Object.f
56
64
  [SignInWord.SignIn]: { en: 'Sign in', he: 'התחברות' },
57
65
  [SignInWord.SignInTo]: { en: 'Sign in to {site}', he: 'התחברות ל־{site}' },
58
66
  [SignInWord.Why]: { en: 'See your orders and check out faster.', he: 'לראות את ההזמנות שלך ולשלם מהר יותר.' },
59
- [SignInWord.ContinueWithGoogle]: { en: 'Continue with Google', he: 'המשך עם Google' },
67
+ [SignInWord.ContinueWith]: { en: 'Continue with {provider}', he: 'המשך עם {provider}' },
60
68
  [SignInWord.Or]: { en: 'or', he: 'או' },
61
69
  [SignInWord.Email]: { en: 'Email', he: 'אימייל' },
62
70
  [SignInWord.EmailPlaceholder]: { en: 'name@example.com', he: 'name@example.com' },
@@ -76,6 +84,9 @@ export const SIGN_IN_WORDS: Readonly<Record<SignInWord, SignInLabel>> = Object.f
76
84
  [SignInWord.SignedIn]: { en: 'You are signed in.', he: 'התחברת.' },
77
85
  [SignInWord.SignedOut]: { en: 'You are signed out.', he: 'התנתקת.' },
78
86
  [SignInWord.NoPassword]: { en: 'No password — we email you a code.', he: 'בלי סיסמה — נשלח לך קוד במייל.' },
87
+ [SignInWord.HaveAccount]: { en: 'Have an account?', he: 'יש לך חשבון?' },
88
+ [SignInWord.NoOrders]: { en: 'No orders yet.', he: 'עדיין אין הזמנות.' },
89
+ [SignInWord.PlacedOn]: { en: 'Placed {date}', he: 'בוצעה ב־{date}' },
79
90
  });
80
91
 
81
92
  export function signInWord(word: SignInWord, lang: string | null | undefined, fill: Readonly<Record<string, string | number>> = {}): string {
@@ -88,7 +99,7 @@ export function signInWord(word: SignInWord, lang: string | null | undefined, fi
88
99
  export enum SignInSlot {
89
100
  Email = 'email',
90
101
  Code = 'code',
91
- /** Under "Continue with Google". */
102
+ /** Under the provider buttons ("Continue with Google"). */
92
103
  Provider = 'provider',
93
104
  /** The dialog as a whole. */
94
105
  Dialog = 'dialog',
@@ -114,6 +125,8 @@ export enum SiteSignInRefusalCode {
114
125
  StateMismatch = 'state-mismatch',
115
126
  Blocked = 'blocked',
116
127
  NotSignedIn = 'not-signed-in',
128
+ /** The studio has no working mailer, so it cannot send a code (it never says whether the email is known). */
129
+ EmailUnavailable = 'email-unavailable',
117
130
  Network = 'network',
118
131
  }
119
132
 
@@ -122,7 +135,8 @@ interface SignInRefusalRule {
122
135
  readonly label: SignInLabel;
123
136
  }
124
137
 
125
- const TRY_GOOGLE_AGAIN: SignInLabel = { en: 'Google sign-in did not work. Try again, or use an email code.', he: 'ההתחברות עם Google לא הצליחה. נסו שוב, או התחברו עם קוד במייל.' };
138
+ /** `{provider}` is the brand's name (`signInRefusal`'s `provider`), else a neutral word. */
139
+ const TRY_PROVIDER_AGAIN: SignInLabel = { en: 'Signing in with {provider} did not work. Try again, or use an email code.', he: 'ההתחברות עם {provider} לא הצליחה. נסו שוב, או התחברו עם קוד במייל.' };
126
140
  const SEND_NEW_CODE: SignInLabel = { en: 'This code has expired. Send a new one.', he: 'תוקף הקוד פג. שלחו קוד חדש.' };
127
141
 
128
142
  export const SIGN_IN_REFUSALS: Readonly<Record<SiteSignInRefusalCode, SignInRefusalRule>> = Object.freeze({
@@ -131,14 +145,15 @@ export const SIGN_IN_REFUSALS: Readonly<Record<SiteSignInRefusalCode, SignInRefu
131
145
  [SiteSignInRefusalCode.CodeExpired]: { slot: SignInSlot.Code, label: SEND_NEW_CODE },
132
146
  [SiteSignInRefusalCode.TooManyTries]: { slot: SignInSlot.Code, label: { en: 'Too many wrong codes. Send a new one.', he: 'יותר מדי קודים שגויים. שלחו קוד חדש.' } },
133
147
  [SiteSignInRefusalCode.RateLimited]: { slot: SignInSlot.Dialog, label: { en: 'Too many tries. Wait a minute and try again.', he: 'יותר מדי ניסיונות. המתינו דקה ונסו שוב.' } },
134
- [SiteSignInRefusalCode.ProviderUnavailable]: { slot: SignInSlot.Provider, label: { en: 'Google sign-in is not available right now. Use an email code.', he: 'ההתחברות עם Google לא זמינה כרגע. התחברו עם קוד במייל.' } },
135
- [SiteSignInRefusalCode.Cancelled]: { slot: SignInSlot.Provider, label: { en: 'Google sign-in was cancelled.', he: 'ההתחברות עם Google בוטלה.' } },
136
- [SiteSignInRefusalCode.Refused]: { slot: SignInSlot.Provider, label: { en: 'Google could not confirm this account. Use an email code.', he: 'Google לא אישר את החשבון הזה. התחברו עם קוד במייל.' } },
148
+ [SiteSignInRefusalCode.ProviderUnavailable]: { slot: SignInSlot.Provider, label: { en: 'Signing in with {provider} is not available right now. Use an email code.', he: 'ההתחברות עם {provider} לא זמינה כרגע. התחברו עם קוד במייל.' } },
149
+ [SiteSignInRefusalCode.Cancelled]: { slot: SignInSlot.Provider, label: { en: 'Signing in with {provider} was cancelled.', he: 'ההתחברות עם {provider} בוטלה.' } },
150
+ [SiteSignInRefusalCode.Refused]: { slot: SignInSlot.Provider, label: { en: '{provider} could not confirm this account. Use an email code.', he: '{provider} לא אישר את החשבון הזה. התחברו עם קוד במייל.' } },
137
151
  [SiteSignInRefusalCode.Expired]: { slot: SignInSlot.Provider, label: { en: 'The sign-in took too long. Try again.', he: 'ההתחברות ארכה יותר מדי. נסו שוב.' } },
138
- [SiteSignInRefusalCode.Failed]: { slot: SignInSlot.Provider, label: TRY_GOOGLE_AGAIN },
139
- [SiteSignInRefusalCode.StateMismatch]: { slot: SignInSlot.Provider, label: TRY_GOOGLE_AGAIN },
152
+ [SiteSignInRefusalCode.Failed]: { slot: SignInSlot.Provider, label: TRY_PROVIDER_AGAIN },
153
+ [SiteSignInRefusalCode.StateMismatch]: { slot: SignInSlot.Provider, label: TRY_PROVIDER_AGAIN },
140
154
  [SiteSignInRefusalCode.Blocked]: { slot: SignInSlot.Dialog, label: { en: 'This account cannot sign in here. Contact the business.', he: 'החשבון הזה לא יכול להתחבר כאן. פנו לעסק.' } },
141
155
  [SiteSignInRefusalCode.NotSignedIn]: { slot: SignInSlot.Dialog, label: { en: 'You are signed out. Sign in again.', he: 'התנתקת. התחברו שוב.' } },
156
+ [SiteSignInRefusalCode.EmailUnavailable]: { slot: SignInSlot.Email, label: { en: 'This site cannot send sign-in codes right now. Try again later.', he: 'האתר לא יכול לשלוח קודי התחברות כרגע. נסו שוב מאוחר יותר.' } },
142
157
  [SiteSignInRefusalCode.Network]: { slot: SignInSlot.Dialog, label: { en: 'We could not reach the site. Try again.', he: 'לא הצלחנו להגיע לאתר. נסו שוב.' } },
143
158
  });
144
159
 
@@ -154,6 +169,7 @@ const FROM_BROKER: Readonly<Record<BrokerRefusalCode, SiteSignInRefusalCode>> =
154
169
  [BrokerRefusalCode.CodeUnknown]: SiteSignInRefusalCode.Expired,
155
170
  [BrokerRefusalCode.CodeUsedOrExpired]: SiteSignInRefusalCode.Expired,
156
171
  [BrokerRefusalCode.NotYours]: SiteSignInRefusalCode.Failed,
172
+ [BrokerRefusalCode.InvalidRequest]: SiteSignInRefusalCode.ProviderUnavailable,
157
173
  });
158
174
 
159
175
  const FROM_RETURN: Readonly<Record<SignInReturnError, SiteSignInRefusalCode>> = Object.freeze({
@@ -177,18 +193,45 @@ export interface SignInRefusal {
177
193
  words: string;
178
194
  }
179
195
 
180
- /** One refusal, on its slot, in the visitor's words. */
181
- export function signInRefusal(code: unknown, lang: string | null | undefined): SignInRefusal {
196
+ /** A provider refusal names no brand when the provider is not known. */
197
+ const ANY_PROVIDER: SignInLabel = { en: 'this account', he: 'החשבון' };
198
+ const NO_PROVIDER_LABEL: Partial<Record<SiteSignInRefusalCode, SignInLabel>> = {
199
+ [SiteSignInRefusalCode.Refused]: { en: 'The provider could not confirm this account. Use an email code.', he: 'הספק לא אישר את החשבון הזה. התחברו עם קוד במייל.' },
200
+ };
201
+
202
+ /** One refusal, on its slot, in the visitor's words; a provider's refusal names it (`provider`). */
203
+ export function signInRefusal(code: unknown, lang: string | null | undefined, provider?: SignInProvider | null): SignInRefusal {
182
204
  const known = siteSignInCodeOf(code);
183
205
  const rule = SIGN_IN_REFUSALS[known];
184
- return { code: known, slot: rule.slot, words: rule.label[signInLanguage(lang)] };
206
+ const language = signInLanguage(lang);
207
+ const name = signInProviderName(provider);
208
+ const label = !name && NO_PROVIDER_LABEL[known] ? NO_PROVIDER_LABEL[known]! : rule.label;
209
+ return { code: known, slot: rule.slot, words: fillIn(label[language], { provider: name || ANY_PROVIDER[language] }) };
185
210
  }
186
211
 
187
212
  /** A refused call's body (`{ code }`) — or nothing at all (`network`) — as one refusal. The body's `message` is a log
188
213
  * line and is never shown. A 429 with no code is `rate-limited`. */
189
- export function signInRefusalOf(body: unknown, lang: string | null | undefined, status?: number | null): SignInRefusal {
214
+ export function signInRefusalOf(body: unknown, lang: string | null | undefined, status?: number | null,
215
+ provider?: SignInProvider | null): SignInRefusal {
190
216
  const code = body && typeof body === 'object' ? (body as { code?: unknown }).code : undefined;
191
- if (code !== undefined) return signInRefusal(code, lang);
192
- if (status === 429) return signInRefusal(SiteSignInRefusalCode.RateLimited, lang);
193
- return signInRefusal(body === undefined || body === null ? SiteSignInRefusalCode.Network : SiteSignInRefusalCode.Failed, lang);
217
+ if (code !== undefined) return signInRefusal(code, lang, provider);
218
+ if (status === 429) return signInRefusal(SiteSignInRefusalCode.RateLimited, lang, provider);
219
+ return signInRefusal(body === undefined || body === null ? SiteSignInRefusalCode.Network : SiteSignInRefusalCode.Failed, lang, provider);
220
+ }
221
+
222
+ /** A provider sign-in that came back refused to a site's page: the site's own code (a studio's `blocked`,
223
+ * `state-mismatch`… kept; a broker return error mapped) and the provider it was (`?iox_signin_via=`), or null. */
224
+ export interface SiteSignInReturnRefusal {
225
+ code: SiteSignInRefusalCode;
226
+ provider: SignInProvider | null;
227
+ }
228
+
229
+ export function siteSignInReturnRefusal(search: string | URLSearchParams | null | undefined): SiteSignInReturnRefusal | null {
230
+ const params = typeof search === 'string' ? new URLSearchParams(search.startsWith('?') ? search.slice(1) : search) : search;
231
+ if (!params) return null;
232
+ const raw = params.get(SIGN_IN_ERROR_PARAM);
233
+ if (raw === null) return null;
234
+ const via = params.get(SIGN_IN_VIA_PARAM);
235
+ const code = isSiteSignInRefusalCode(raw) ? raw : siteSignInCodeOf(readSignInReturn(params)?.error);
236
+ return { code, provider: isSignInProvider(via) ? via : null };
194
237
  }
@@ -1105,12 +1105,12 @@ dialog[data-iox-dialog].iox-es.iox-role-shop-cart-drawer:is([data-iox-closing],
1105
1105
 
1106
1106
  /* The dialog asks one thing at a time: the email (Google beside it), then the code just sent. */
1107
1107
  .iox-role-account-sign-in:not([data-iox-sign-in-step='code']) .iox-role-account-code-step { display: none !important; }
1108
- .iox-role-account-sign-in[data-iox-sign-in-step='code'] :is(.iox-role-account-email-step, .iox-role-account-google,
1109
- .iox-role-account-or, .iox-role-account-provider-error, .iox-role-account-why) { display: none !important; }
1110
- .iox-role-account-sign-in[aria-busy='true'] :is(.iox-role-account-google, .iox-role-account-send-code, .iox-role-account-verify,
1111
- .iox-role-account-send-again)[aria-busy='true'] { cursor: progress; }
1112
- .iox-role-account-sign-in :is(.iox-role-account-google, .iox-role-account-send-code, .iox-role-account-verify,
1113
- .iox-role-account-send-again)[aria-disabled='true'] { pointer-events: none; }
1108
+ .iox-role-account-sign-in[data-iox-sign-in-step='code'] :is(.iox-role-account-email-step, .iox-role-account-providers,
1109
+ .iox-role-account-google, .iox-role-account-or, .iox-role-account-provider-error, .iox-role-account-why) { display: none !important; }
1110
+ .iox-role-account-sign-in[aria-busy='true'] :is(.iox-role-account-google, .iox-role-account-facebook, .iox-role-account-github,
1111
+ .iox-role-account-linkedin, .iox-role-account-send-code, .iox-role-account-verify, .iox-role-account-send-again)[aria-busy='true'] { cursor: progress; }
1112
+ .iox-role-account-sign-in :is(.iox-role-account-google, .iox-role-account-facebook, .iox-role-account-github, .iox-role-account-linkedin,
1113
+ .iox-role-account-send-code, .iox-role-account-verify, .iox-role-account-send-again)[aria-disabled='true'] { pointer-events: none; }
1114
1114
  /* The code reads as a code: digits spaced, the same left-to-right in a Hebrew site. */
1115
1115
  .iox-role-account-code .iox-field__control { letter-spacing: 0.3em; font-variant-numeric: tabular-nums; direction: ltr; }
1116
1116