@vectoriox/iox-ui 5.100.0 → 5.102.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.
@@ -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