@vectoriox/iox-ui 5.97.0 → 5.99.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 (37) hide show
  1. package/fesm2022/vectoriox-iox-ui-generation-core.mjs +1114 -223
  2. package/fesm2022/vectoriox-iox-ui-generation-core.mjs.map +1 -1
  3. package/fesm2022/vectoriox-iox-ui-harness-core.mjs +115 -42
  4. package/fesm2022/vectoriox-iox-ui-harness-core.mjs.map +1 -1
  5. package/fesm2022/vectoriox-iox-ui-identity-core.mjs +535 -0
  6. package/fesm2022/vectoriox-iox-ui-identity-core.mjs.map +1 -0
  7. package/generation-core/index.d.ts +515 -17
  8. package/harness-core/index.d.ts +66 -6
  9. package/identity-core/index.d.ts +364 -0
  10. package/identity-core/package.json +3 -0
  11. package/package.json +5 -1
  12. package/src/generation-core/audit-site.ts +8 -0
  13. package/src/generation-core/compose-site.ts +130 -4
  14. package/src/generation-core/nav-shape.ts +4 -2
  15. package/src/generation-core/patterns.ts +25 -1
  16. package/src/generation-core/pictures.ts +1 -1
  17. package/src/generation-core/plan-derived.ts +10 -5
  18. package/src/generation-core/plan-edits.ts +8 -7
  19. package/src/generation-core/plan-wire.ts +59 -10
  20. package/src/generation-core/plan-words.ts +18 -1
  21. package/src/generation-core/public-api.ts +1 -0
  22. package/src/generation-core/shop-plan.ts +165 -0
  23. package/src/generation-core/showcase.ts +29 -4
  24. package/src/generation-core/site-build-run.ts +25 -0
  25. package/src/generation-core/site-plan.model.ts +49 -1
  26. package/src/generation-core/site-spec.generated.ts +330 -2
  27. package/src/generation-core/stock-photos.ts +19 -2
  28. package/src/generation-core/validate-site-plan.ts +146 -8
  29. package/src/harness-core/business-types.ts +13 -0
  30. package/src/harness-core/harness-spec.generated.ts +69 -39
  31. package/src/harness-core/needs.ts +30 -1
  32. package/src/harness-core/site-reading.ts +8 -2
  33. package/src/identity-core/guards.ts +87 -0
  34. package/src/identity-core/public-api.ts +13 -0
  35. package/src/identity-core/sign-in.ts +223 -0
  36. package/src/identity-core/site-auth.ts +172 -0
  37. package/src/identity-core/words.ts +194 -0
@@ -0,0 +1,194 @@
1
+ import { BrokerRefusalCode, SignInReturnError } from './sign-in';
2
+
3
+ /**
4
+ * The sign-in dialog's words and its refusals, in English and Hebrew. A string-rendered site has no translation
5
+ * service, so the core carries both itself (commerce-core `CHECKOUT_WORDS` precedent); a host with its own translations
6
+ * may key them by the stable codes instead.
7
+ */
8
+
9
+ export interface SignInLabel {
10
+ readonly en: string;
11
+ readonly he: string;
12
+ }
13
+
14
+ export enum SignInLanguage {
15
+ En = 'en',
16
+ He = 'he',
17
+ }
18
+
19
+ export function signInLanguage(lang: string | null | undefined): SignInLanguage {
20
+ const primary = String(lang ?? '').trim().toLowerCase().split(/[-_]/)[0];
21
+ return primary === 'he' || primary === 'iw' ? SignInLanguage.He : SignInLanguage.En;
22
+ }
23
+
24
+ function fillIn(words: string, fill: Readonly<Record<string, string | number>>): string {
25
+ return words.replace(/\{(\w+)\}/g, (all, key) => (key in fill ? String(fill[key]) : all));
26
+ }
27
+
28
+ export enum SignInWord {
29
+ SignIn = 'signIn',
30
+ SignInTo = 'signInTo',
31
+ Why = 'why',
32
+ ContinueWithGoogle = 'continueWithGoogle',
33
+ Or = 'or',
34
+ Email = 'email',
35
+ EmailPlaceholder = 'emailPlaceholder',
36
+ SendCode = 'sendCode',
37
+ CodeSent = 'codeSent',
38
+ Code = 'code',
39
+ CodeValid = 'codeValid',
40
+ SendAgain = 'sendAgain',
41
+ Verify = 'verify',
42
+ OtherEmail = 'otherEmail',
43
+ Working = 'working',
44
+ Close = 'close',
45
+ SignOut = 'signOut',
46
+ Account = 'account',
47
+ YourOrders = 'yourOrders',
48
+ Hello = 'hello',
49
+ SignedIn = 'signedIn',
50
+ SignedOut = 'signedOut',
51
+ NoPassword = 'noPassword',
52
+ }
53
+
54
+ /** `{site}`, `{email}`, `{name}`, `{minutes}` are filled by `signInWord`. */
55
+ export const SIGN_IN_WORDS: Readonly<Record<SignInWord, SignInLabel>> = Object.freeze({
56
+ [SignInWord.SignIn]: { en: 'Sign in', he: 'התחברות' },
57
+ [SignInWord.SignInTo]: { en: 'Sign in to {site}', he: 'התחברות ל־{site}' },
58
+ [SignInWord.Why]: { en: 'See your orders and check out faster.', he: 'לראות את ההזמנות שלך ולשלם מהר יותר.' },
59
+ [SignInWord.ContinueWithGoogle]: { en: 'Continue with Google', he: 'המשך עם Google' },
60
+ [SignInWord.Or]: { en: 'or', he: 'או' },
61
+ [SignInWord.Email]: { en: 'Email', he: 'אימייל' },
62
+ [SignInWord.EmailPlaceholder]: { en: 'name@example.com', he: 'name@example.com' },
63
+ [SignInWord.SendCode]: { en: 'Send me a code', he: 'שלחו לי קוד' },
64
+ [SignInWord.CodeSent]: { en: 'We sent a 6-digit code to {email}', he: 'שלחנו קוד בן 6 ספרות אל {email}' },
65
+ [SignInWord.Code]: { en: 'Code', he: 'קוד' },
66
+ [SignInWord.CodeValid]: { en: 'Valid for {minutes} minutes', he: 'בתוקף ל־{minutes} דקות' },
67
+ [SignInWord.SendAgain]: { en: 'Send again', he: 'שליחה חוזרת' },
68
+ [SignInWord.Verify]: { en: 'Sign in', he: 'התחברות' },
69
+ [SignInWord.OtherEmail]: { en: 'Use another email', he: 'אימייל אחר' },
70
+ [SignInWord.Working]: { en: 'One moment…', he: 'רגע…' },
71
+ [SignInWord.Close]: { en: 'Close', he: 'סגירה' },
72
+ [SignInWord.SignOut]: { en: 'Sign out', he: 'התנתקות' },
73
+ [SignInWord.Account]: { en: 'Account', he: 'החשבון שלי' },
74
+ [SignInWord.YourOrders]: { en: 'Your orders', he: 'ההזמנות שלך' },
75
+ [SignInWord.Hello]: { en: 'Hello, {name}', he: 'שלום, {name}' },
76
+ [SignInWord.SignedIn]: { en: 'You are signed in.', he: 'התחברת.' },
77
+ [SignInWord.SignedOut]: { en: 'You are signed out.', he: 'התנתקת.' },
78
+ [SignInWord.NoPassword]: { en: 'No password — we email you a code.', he: 'בלי סיסמה — נשלח לך קוד במייל.' },
79
+ });
80
+
81
+ export function signInWord(word: SignInWord, lang: string | null | undefined, fill: Readonly<Record<string, string | number>> = {}): string {
82
+ return fillIn(SIGN_IN_WORDS[word][signInLanguage(lang)], fill);
83
+ }
84
+
85
+ // ── a refusal, said on its field ─────────────────────────────────────────────────────────────
86
+
87
+ /** Where in the sign-in dialog a refusal is said. */
88
+ export enum SignInSlot {
89
+ Email = 'email',
90
+ Code = 'code',
91
+ /** Under "Continue with Google". */
92
+ Provider = 'provider',
93
+ /** The dialog as a whole. */
94
+ Dialog = 'dialog',
95
+ }
96
+
97
+ /**
98
+ * Every code a site's sign-in can hear: iox-cms's answers, the broker's return errors (`?iox_signin_error=`), and
99
+ * `network` for no answer at all.
100
+ */
101
+ export enum SiteSignInRefusalCode {
102
+ InvalidEmail = 'invalid-email',
103
+ CodeWrong = 'code-wrong',
104
+ CodeExpired = 'code-expired',
105
+ TooManyTries = 'too-many-tries',
106
+ RateLimited = 'rate-limited',
107
+ /** The broker cannot run the provider (down, not configured, the host refused). */
108
+ ProviderUnavailable = 'provider-unavailable',
109
+ Cancelled = 'cancelled',
110
+ Refused = 'refused',
111
+ Expired = 'expired',
112
+ Failed = 'failed',
113
+ /** The return came back without this browser's sign-in cookie — a forged or stale return. */
114
+ StateMismatch = 'state-mismatch',
115
+ Blocked = 'blocked',
116
+ NotSignedIn = 'not-signed-in',
117
+ Network = 'network',
118
+ }
119
+
120
+ interface SignInRefusalRule {
121
+ readonly slot: SignInSlot;
122
+ readonly label: SignInLabel;
123
+ }
124
+
125
+ const TRY_GOOGLE_AGAIN: SignInLabel = { en: 'Google sign-in did not work. Try again, or use an email code.', he: 'ההתחברות עם Google לא הצליחה. נסו שוב, או התחברו עם קוד במייל.' };
126
+ const SEND_NEW_CODE: SignInLabel = { en: 'This code has expired. Send a new one.', he: 'תוקף הקוד פג. שלחו קוד חדש.' };
127
+
128
+ export const SIGN_IN_REFUSALS: Readonly<Record<SiteSignInRefusalCode, SignInRefusalRule>> = Object.freeze({
129
+ [SiteSignInRefusalCode.InvalidEmail]: { slot: SignInSlot.Email, label: { en: 'Enter an email address, like name@example.com.', he: 'הקלידו כתובת אימייל, למשל name@example.com.' } },
130
+ [SiteSignInRefusalCode.CodeWrong]: { slot: SignInSlot.Code, label: { en: 'That code is not right. Check it and try again.', he: 'הקוד לא נכון. בדקו ונסו שוב.' } },
131
+ [SiteSignInRefusalCode.CodeExpired]: { slot: SignInSlot.Code, label: SEND_NEW_CODE },
132
+ [SiteSignInRefusalCode.TooManyTries]: { slot: SignInSlot.Code, label: { en: 'Too many wrong codes. Send a new one.', he: 'יותר מדי קודים שגויים. שלחו קוד חדש.' } },
133
+ [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 לא אישר את החשבון הזה. התחברו עם קוד במייל.' } },
137
+ [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 },
140
+ [SiteSignInRefusalCode.Blocked]: { slot: SignInSlot.Dialog, label: { en: 'This account cannot sign in here. Contact the business.', he: 'החשבון הזה לא יכול להתחבר כאן. פנו לעסק.' } },
141
+ [SiteSignInRefusalCode.NotSignedIn]: { slot: SignInSlot.Dialog, label: { en: 'You are signed out. Sign in again.', he: 'התנתקת. התחברו שוב.' } },
142
+ [SiteSignInRefusalCode.Network]: { slot: SignInSlot.Dialog, label: { en: 'We could not reach the site. Try again.', he: 'לא הצלחנו להגיע לאתר. נסו שוב.' } },
143
+ });
144
+
145
+ export function isSiteSignInRefusalCode(code: unknown): code is SiteSignInRefusalCode {
146
+ return typeof code === 'string' && (Object.values(SiteSignInRefusalCode) as string[]).includes(code);
147
+ }
148
+
149
+ /** A broker refusal as the site says it: a person never hears "return-host-refused". */
150
+ const FROM_BROKER: Readonly<Record<BrokerRefusalCode, SiteSignInRefusalCode>> = Object.freeze({
151
+ [BrokerRefusalCode.ReturnHostRefused]: SiteSignInRefusalCode.ProviderUnavailable,
152
+ [BrokerRefusalCode.UnknownProvider]: SiteSignInRefusalCode.ProviderUnavailable,
153
+ [BrokerRefusalCode.ProviderNotConfigured]: SiteSignInRefusalCode.ProviderUnavailable,
154
+ [BrokerRefusalCode.CodeUnknown]: SiteSignInRefusalCode.Expired,
155
+ [BrokerRefusalCode.CodeUsedOrExpired]: SiteSignInRefusalCode.Expired,
156
+ [BrokerRefusalCode.NotYours]: SiteSignInRefusalCode.Failed,
157
+ });
158
+
159
+ const FROM_RETURN: Readonly<Record<SignInReturnError, SiteSignInRefusalCode>> = Object.freeze({
160
+ [SignInReturnError.Cancelled]: SiteSignInRefusalCode.Cancelled,
161
+ [SignInReturnError.Refused]: SiteSignInRefusalCode.Refused,
162
+ [SignInReturnError.Expired]: SiteSignInRefusalCode.Expired,
163
+ [SignInReturnError.Failed]: SiteSignInRefusalCode.Failed,
164
+ });
165
+
166
+ /** Any code a sign-in heard, as the site's own: a site code as is, a broker code or a return error mapped, else `failed`. */
167
+ export function siteSignInCodeOf(code: unknown): SiteSignInRefusalCode {
168
+ if (isSiteSignInRefusalCode(code)) return code;
169
+ if (typeof code === 'string' && code in FROM_BROKER) return FROM_BROKER[code as BrokerRefusalCode];
170
+ if (typeof code === 'string' && code in FROM_RETURN) return FROM_RETURN[code as SignInReturnError];
171
+ return SiteSignInRefusalCode.Failed;
172
+ }
173
+
174
+ export interface SignInRefusal {
175
+ code: SiteSignInRefusalCode;
176
+ slot: SignInSlot;
177
+ words: string;
178
+ }
179
+
180
+ /** One refusal, on its slot, in the visitor's words. */
181
+ export function signInRefusal(code: unknown, lang: string | null | undefined): SignInRefusal {
182
+ const known = siteSignInCodeOf(code);
183
+ const rule = SIGN_IN_REFUSALS[known];
184
+ return { code: known, slot: rule.slot, words: rule.label[signInLanguage(lang)] };
185
+ }
186
+
187
+ /** A refused call's body (`{ code }`) — or nothing at all (`network`) — as one refusal. The body's `message` is a log
188
+ * 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 {
190
+ 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);
194
+ }