@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,5 +1,8 @@
1
1
  import { roleClass } from '@vectoriox/iox-ui/design-core';
2
- import { CUSTOMER_SLOT, EMAIL_CODE_TTL_MINUTES, SignInLanguage, signInLanguage, SignInWord, signInWord } from '@vectoriox/iox-ui/identity-core';
2
+ import {
3
+ ACCOUNT_PATH, CUSTOMER_SLOT, EMAIL_CODE_TTL_MINUTES, SIGN_IN_PROVIDERS, SignInLanguage, signInLanguage, SignInProvider, signInProviderMarkUri, signInProviderName,
4
+ SignInWord, signInWord,
5
+ } from '@vectoriox/iox-ui/identity-core';
3
6
 
4
7
  import { CompositeNode, CompositeNodeFactory, writeProp } from './composite-node';
5
8
  import { bindSlot, COLUMN, onClick, recipeButton, recipeIcon, recipePart, recipeText, ROW, WORDS, ZERO } from './recipe-parts';
@@ -15,14 +18,17 @@ import { bindSlot, COLUMN, onClick, recipeButton, recipeIcon, recipePart, recipe
15
18
  * · Popover account.menu › Text account.menu-greeting · ButtonBlock account.orders (a link to the
16
19
  * account page) · ButtonBlock account.sign-out (signOut)
17
20
  * Sign-in dialog Dialog account.sign-in › head (Heading account.title · Close) · Text account.why
18
- * · ButtonBlock account.google "Continue with Google" · Text account.provider-error · Text account.or
21
+ * · Container account.providers › ButtonBlock account.google / .facebook / .github / .linkedin
22
+ * ("Continue with <brand>", the brand's mark) · Text account.provider-error · Text account.or
19
23
  * · Container account.email-step › Field account.email · ButtonBlock account.send-code
20
24
  * · Container account.code-step › Text account.code-sent · Field account.code · ButtonBlock account.verify
21
25
  * · row (Text account.code-valid · Send again · Use another email)
22
26
  * · Text account.dialog-error
23
27
  *
24
28
  * Words are the recipe's in English (board 12); the runtime writes the visitor's language over the ones it owns
25
- * (the code-sent line, refusals) and a studio edits the rest like any Text.
29
+ * (the code-sent line, refusals) and a studio edits the rest like any Text. Every provider's button is stamped; the
30
+ * runtime hides the ones the site does not offer right now (`SiteAuthTransport.methods` — Settings ▸ Sign-in and the
31
+ * broker's providers), so a provider switched on later appears with no change to the page.
26
32
  */
27
33
 
28
34
  export enum AccountRole {
@@ -40,7 +46,11 @@ export enum AccountRole {
40
46
  Title = 'account.title',
41
47
  Close = 'account.close',
42
48
  Why = 'account.why',
49
+ Providers = 'account.providers',
43
50
  Google = 'account.google',
51
+ Facebook = 'account.facebook',
52
+ GitHub = 'account.github',
53
+ LinkedIn = 'account.linkedin',
44
54
  ProviderError = 'account.provider-error',
45
55
  Or = 'account.or',
46
56
  EmailStep = 'account.email-step',
@@ -58,6 +68,14 @@ export enum AccountRole {
58
68
 
59
69
  export const ACCOUNT_ROLES: ReadonlySet<string> = new Set(Object.values(AccountRole));
60
70
 
71
+ /** Each provider's button in the sign-in dialog. */
72
+ export const PROVIDER_ROLES: Readonly<Record<SignInProvider, AccountRole>> = Object.freeze({
73
+ [SignInProvider.Google]: AccountRole.Google,
74
+ [SignInProvider.Facebook]: AccountRole.Facebook,
75
+ [SignInProvider.GitHub]: AccountRole.GitHub,
76
+ [SignInProvider.LinkedIn]: AccountRole.LinkedIn,
77
+ });
78
+
61
79
  export function isAccountRole(role: string | null | undefined): boolean {
62
80
  return !!role && ACCOUNT_ROLES.has(role);
63
81
  }
@@ -102,7 +120,8 @@ export function accountRecipeWords(lang: string | null | undefined = 'en') {
102
120
  title: w(SignInWord.SignIn),
103
121
  close: w(SignInWord.Close),
104
122
  why: w(SignInWord.Why),
105
- google: w(SignInWord.ContinueWithGoogle),
123
+ providers: Object.freeze(Object.fromEntries(SIGN_IN_PROVIDERS.map(p => [p, w(SignInWord.ContinueWith, { provider: signInProviderName(p) })]))) as
124
+ Readonly<Record<SignInProvider, string>>,
106
125
  or: w(SignInWord.Or),
107
126
  email: w(SignInWord.Email),
108
127
  emailPlaceholder: w(SignInWord.EmailPlaceholder),
@@ -173,7 +192,7 @@ export function buildAccountMenuRecipe(create: CompositeNodeFactory, lang: strin
173
192
  const greeting = words(create, 'account-menu-greeting', AccountRole.MenuGreeting, Style.Body, t.greeting, 'Greeting',
174
193
  { ...WORDS, margin: '0px 0px 6px 0px', fontWeight: '600' });
175
194
  const orders = recipePart(create, 'account-orders', 'ButtonBlock', AccountRole.Orders, Style.Ghost,
176
- { tag: 'a', linkType: 'external', href: '/account', target: '_self' }, 'Your orders', { ...TEXT_BUTTON, justifyContent: 'flex-start', width: '100%' });
195
+ { tag: 'a', linkType: 'external', href: ACCOUNT_PATH, target: '_self' }, 'Your orders', { ...TEXT_BUTTON, justifyContent: 'flex-start', width: '100%' });
177
196
  orders.children = [words(create, 'account-orders-label', null, Style.Label, t.orders, 'Text', WORDS, 'span')];
178
197
  const signOut = labelled(create, 'account-sign-out', AccountRole.SignOut, Style.Ghost, t.signOut, 'Sign out',
179
198
  { ...TEXT_BUTTON, justifyContent: 'flex-start', width: '100%' });
@@ -229,12 +248,9 @@ export function buildSignInDialogRecipe(create: CompositeNodeFactory, lang: stri
229
248
  head.children = [title, close];
230
249
 
231
250
  const why = words(create, 'sign-in-why', AccountRole.Why, Style.Small, t.why, 'Why sign in');
232
- const google = recipeButton(create, 'sign-in-google', AccountRole.Google, Style.Secondary, 'Continue with Google', '', { ...FULL, gap: '8px' });
233
- google.children = [
234
- recipeIcon(create, 'sign-in-google-icon', 'ph ph-google-logo', '18px'),
235
- words(create, 'sign-in-google-label', null, Style.Label, t.google, 'Text', WORDS, 'span'),
236
- ];
237
- const providerError = words(create, 'sign-in-provider-error', AccountRole.ProviderError, Style.Error, '', 'Google error');
251
+ const providers = recipePart(create, 'sign-in-providers', 'Container', AccountRole.Providers, null, {}, 'Sign-in providers', { ...COLUMN, gap: '8px' });
252
+ providers.children = SIGN_IN_PROVIDERS.map(p => providerButton(create, p, t.providers[p]));
253
+ const providerError = words(create, 'sign-in-provider-error', AccountRole.ProviderError, Style.Error, '', 'Provider error');
238
254
  const or = words(create, 'sign-in-or', AccountRole.Or, Style.Small, t.or, 'Or', { ...WORDS, width: '100%', textAlign: 'center' });
239
255
 
240
256
  const emailStep = recipePart(create, 'sign-in-email-step', 'Container', AccountRole.EmailStep, null, {}, 'Email step', { ...COLUMN, gap: '10px' });
@@ -260,10 +276,22 @@ export function buildSignInDialogRecipe(create: CompositeNodeFactory, lang: stri
260
276
  again,
261
277
  ];
262
278
  const dialogError = words(create, 'sign-in-dialog-error', AccountRole.DialogError, Style.Error, '', 'Error');
263
- dialog.children = [head, why, google, providerError, or, emailStep, codeStep, dialogError];
279
+ dialog.children = [head, why, providers, providerError, or, emailStep, codeStep, dialogError];
264
280
  return dialog;
265
281
  }
266
282
 
283
+ /** "Continue with <brand>" with the brand's own mark (its button guidelines), wearing the look's secondary button. */
284
+ function providerButton(create: CompositeNodeFactory, provider: SignInProvider, label: string): CompositeNode {
285
+ const name = signInProviderName(provider);
286
+ const button = recipeButton(create, `sign-in-${provider}`, PROVIDER_ROLES[provider], Style.Secondary, `Continue with ${name}`, '', { ...FULL, gap: '8px' });
287
+ button.children = [
288
+ recipePart(create, `sign-in-${provider}-mark`, 'Image', null, null, { src: signInProviderMarkUri(provider), alt: '' }, `${name} mark`,
289
+ { width: '18px', height: '18px', minHeight: 'auto', flexShrink: '0' }),
290
+ words(create, `sign-in-${provider}-label`, null, Style.Label, label, 'Text', WORDS, 'span'),
291
+ ];
292
+ return button;
293
+ }
294
+
267
295
  /** The account recipes, by name. */
268
296
  export enum AccountRecipe {
269
297
  Entry = 'accountEntry',
@@ -1,4 +1,6 @@
1
1
  import { ELEMENT_ACTION_DESCRIPTORS, resolveActionAvailability } from '@vectoriox/iox-ui/actions-core';
2
+ import { CheckoutGateRefusal, labelIn } from '@vectoriox/iox-ui/commerce-core';
3
+ import { ShopRole } from '@vectoriox/iox-ui/composite-core';
2
4
  import { auditDesignContrast, DesignTokenLike } from '@vectoriox/iox-ui/design-core';
3
5
  import { collectFormSpec, ControlType, FIELD_NODE_TYPE, FORM_CHANNEL_ROLE, FORM_NODE_TYPE, isChannelFilled } from '@vectoriox/iox-ui/forms-core';
4
6
 
@@ -53,6 +55,13 @@ export enum SiteFindingCode {
53
55
  /** Commerce G1 (shop-aware §3i): a sample product the build added still has no price — a price is a fact a buyer is
54
56
  * held to, so the owner sets it (or removes the sample) before the store goes live. */
55
57
  SamplePrice = 'sample-price',
58
+ /** Commerce G2: a sample product the build added has no stock count yet — how many the owner has is theirs to say;
59
+ * unanswered, the sample is sold out to every visitor (the build never invents stock). */
60
+ SampleStock = 'sample-stock',
61
+ /** Commerce G2 (R-H8): a site that sells, while the checkout gate (commerce-core `checkoutGate`, C-D19) still refuses
62
+ * one of its facts — a way to get paid, delivery, the business's identity, the owner's own legal pages. Each is the
63
+ * owner's to answer, never written for them; the finding carries the gate's code in `fact`. */
64
+ StoreFact = 'store-fact',
56
65
  StockPhoto = 'stock-photo',
57
66
  /** M7: a picture made with AI for the site still stands where one of the studio's own could. */
58
67
  MadePicture = 'made-picture',
@@ -83,6 +92,8 @@ export const FINDING_SEVERITY: Readonly<Record<SiteFindingCode, CheckSeverity>>
83
92
  [SiteFindingCode.CopyPlaceholder]: CheckSeverity.Ask,
84
93
  [SiteFindingCode.SampleItems]: CheckSeverity.Ask,
85
94
  [SiteFindingCode.SamplePrice]: CheckSeverity.Block,
95
+ [SiteFindingCode.SampleStock]: CheckSeverity.Block,
96
+ [SiteFindingCode.StoreFact]: CheckSeverity.Block,
86
97
  [SiteFindingCode.StockPhoto]: CheckSeverity.Ask,
87
98
  [SiteFindingCode.MadePicture]: CheckSeverity.Ask,
88
99
  [SiteFindingCode.PictureMissing]: CheckSeverity.Warn,
@@ -110,6 +121,8 @@ const CHECK_OF: Readonly<Record<SiteFindingCode, SiteCheckId>> = {
110
121
  [SiteFindingCode.CopyPlaceholder]: SiteCheckId.Facts,
111
122
  [SiteFindingCode.SampleItems]: SiteCheckId.Facts,
112
123
  [SiteFindingCode.SamplePrice]: SiteCheckId.Facts,
124
+ [SiteFindingCode.SampleStock]: SiteCheckId.Facts,
125
+ [SiteFindingCode.StoreFact]: SiteCheckId.Facts,
113
126
  [SiteFindingCode.StockPhoto]: SiteCheckId.Facts,
114
127
  [SiteFindingCode.MadePicture]: SiteCheckId.Facts,
115
128
  [SiteFindingCode.PictureMissing]: SiteCheckId.Facts,
@@ -134,6 +147,8 @@ export interface SiteFinding {
134
147
  nodeId?: string;
135
148
  /** The global slot (`header` / `footer`) when it is in a global. */
136
149
  owner?: string;
150
+ /** `store-fact`: the checkout gate's code (commerce-core `CheckoutGateCode`) — which fact, so a screen can open where it is answered. */
151
+ fact?: string;
137
152
  }
138
153
 
139
154
  export interface SiteCheck {
@@ -177,6 +192,13 @@ export interface SiteAuditSnapshot {
177
192
  samples?: ReadonlyArray<{ contentType: string; id: string; label?: string }>;
178
193
  /** Commerce G1: sample products (`isSample`) whose price is still not set. */
179
194
  unpricedSamples?: ReadonlyArray<{ id: string; label?: string }>;
195
+ /** Commerce G2: sample products (`isSample`) whose stock count was never set. */
196
+ unstockedSamples?: ReadonlyArray<{ id: string; label?: string }>;
197
+ /**
198
+ * Commerce G2: what the checkout gate refuses for this studio (commerce-core `checkoutGate(…).refusals`) and the
199
+ * studio's language its words are said in. Read only when the site sells (`siteSells`).
200
+ */
201
+ store?: { refusals: ReadonlyArray<Pick<CheckoutGateRefusal, 'code' | 'label'>>; lang?: string | null } | null;
180
202
  /** Stock photos a build placed that are still on the page. */
181
203
  stock?: ReadonlyArray<{ nodeId: string; pageId?: string; owner?: string }>;
182
204
  /** M7: pictures made with AI that are still on the page. */
@@ -201,6 +223,17 @@ const COLOUR_TRAITS = /color|Color|^background$|boxShadow|textShadow/;
201
223
  const HEADING_LEVEL = /^h([1-6])$/;
202
224
  const DIALOG_TYPE = 'Dialog';
203
225
  const SELF = 'self';
226
+ /** The parts that take a buyer toward the checkout — a price alone shows; these sell. */
227
+ const SELLING_ROLES: ReadonlySet<string> = new Set([ShopRole.Add, ShopRole.BuyNow, ShopRole.CartButton, ShopRole.CartDrawer, ShopRole.Checkout]);
228
+
229
+ /** Commerce G2: the site sells — a page or a global holds a part that puts a product in the bag or opens the checkout. */
230
+ export function siteSells(snapshot: Pick<SiteAuditSnapshot, 'pages' | 'globals'>): boolean {
231
+ let sells = false;
232
+ const visit = (n: SerializedNode) => { if (!sells && !!n.role && SELLING_ROLES.has(n.role)) sells = true; };
233
+ for (const page of snapshot.pages) walkSerialized(page.layout, visit);
234
+ walkSerialized(snapshot.globals, visit);
235
+ return sells;
236
+ }
204
237
 
205
238
  /** A route pattern (`/work/:slug`) matches a concrete path (`/work/blue-bowl`). */
206
239
  export function routeMatches(pattern: string, path: string): boolean {
@@ -237,7 +270,7 @@ interface Ctx {
237
270
  nodeIds: Map<string, string>;
238
271
  }
239
272
 
240
- function add(ctx: Ctx, code: SiteFindingCode, message: string, where: { pageId?: string; nodeId?: string; owner?: string } = {}): void {
273
+ function add(ctx: Ctx, code: SiteFindingCode, message: string, where: { pageId?: string; nodeId?: string; owner?: string; fact?: string } = {}): void {
241
274
  ctx.out.push({ check: CHECK_OF[code], severity: FINDING_SEVERITY[code], code, message, ...where });
242
275
  }
243
276
 
@@ -299,6 +332,10 @@ function checkFacts(ctx: Ctx, snapshot: SiteAuditSnapshot, pages: ReadonlyArray<
299
332
  }
300
333
  for (const s of snapshot.samples ?? []) add(ctx, SiteFindingCode.SampleItems, `"${s.label ?? s.id}" is a sample — replace or remove it.`, { nodeId: s.id });
301
334
  for (const s of snapshot.unpricedSamples ?? []) add(ctx, SiteFindingCode.SamplePrice, `"${s.label ?? s.id}" has no price yet — set yours, or remove the sample.`, { nodeId: s.id });
335
+ for (const s of snapshot.unstockedSamples ?? []) add(ctx, SiteFindingCode.SampleStock, `"${s.label ?? s.id}" has no stock yet — say how many you have, or remove the sample.`, { nodeId: s.id });
336
+ if (snapshot.store?.refusals.length && siteSells(snapshot)) {
337
+ for (const r of snapshot.store.refusals) add(ctx, SiteFindingCode.StoreFact, labelIn(r.label, snapshot.store.lang), { fact: r.code });
338
+ }
302
339
  for (const s of (snapshot.stock ?? []).filter(inScope)) add(ctx, SiteFindingCode.StockPhoto, 'A stock photo stands in for one of yours.', { pageId: s.pageId, nodeId: s.nodeId, owner: s.owner });
303
340
  for (const s of (snapshot.made ?? []).filter(inScope)) add(ctx, SiteFindingCode.MadePicture, 'A picture made with AI stands in for one of yours.', { pageId: s.pageId, nodeId: s.nodeId, owner: s.owner });
304
341
  for (const s of (snapshot.missing ?? []).filter(inScope)) add(ctx, SiteFindingCode.PictureMissing, 'A picture could not be made for this spot — add one of yours.', { pageId: s.pageId, nodeId: s.nodeId, owner: s.owner });
@@ -150,6 +150,9 @@ export enum BuildNoticeCode {
150
150
  /** Commerce G1: the studio had never set its currency and VAT — the build stored the ones its language implies
151
151
  * (Hebrew: ILS and 18%), said here so the owner checks them in Settings ▸ General before setting prices. */
152
152
  ShopMoneyInferred = 'shop-money-inferred',
153
+ /** Commerce G2: the facts the owner gave (email, phone, address) became the shop's contact details where it had none
154
+ * — said, so the owner adds what only they know (the legal name, the business number) in Shop ▸ Settings. */
155
+ ShopBusinessFromFacts = 'shop-business-from-facts',
153
156
  }
154
157
 
155
158
  export interface BuildNotice {
@@ -0,0 +1,60 @@
1
+ import { SignInProvider } from './sign-in';
2
+
3
+ /**
4
+ * How each provider's button presents it — ONE copy for every IOX sign-in (the site's dialog, the admin login, the
5
+ * portal). Each brand's button guidelines: its own name, never translated ("Continue with GitHub" / "המשך עם GitHub"),
6
+ * and its official mark in its own colours, unaltered — Google's four-colour G, LinkedIn's "in" on its blue, Facebook's
7
+ * white f on its blue circle; GitHub's mark is single-colour by its rules, so it takes the button's ink (`currentColor`).
8
+ */
9
+ export interface SignInProviderBrand {
10
+ /** The brand's name, as the brand writes it. */
11
+ readonly name: string;
12
+ /** The mark as one inline SVG (a square `viewBox`, no size — the button sizes it). */
13
+ readonly mark: string;
14
+ /** The mark for an `<img>`, where `currentColor` means nothing — when it differs from `mark`. */
15
+ readonly imageMark?: string;
16
+ }
17
+
18
+ const SVG = (viewBox: string, body: string) => `<svg xmlns="http://www.w3.org/2000/svg" viewBox="${viewBox}" aria-hidden="true" focusable="false">${body}</svg>`;
19
+
20
+ const GITHUB_PATH = 'M8 0c4.42 0 8 3.58 8 8a8.013 8.013 0 0 1-5.45 7.59c-.4.08-.55-.17-.55-.38 0-.27.01-1.13.01-2.2 0-.75-.25-1.23-.54-1.48 1.78-.2 3.65-.88 3.65-3.95 0-.88-.31-1.59-.82-2.15.08-.2.36-1.02-.08-2.12 0 0-.67-.22-2.2.82-.64-.18-1.32-.27-2-.27-.68 0-1.36.09-2 .27-1.53-1.03-2.2-.82-2.2-.82-.44 1.1-.16 1.92-.08 2.12-.51.56-.82 1.28-.82 2.15 0 3.06 1.86 3.75 3.64 3.95-.23.2-.44.55-.51 1.07-.46.21-1.61.55-2.33-.66-.15-.24-.6-.83-1.23-.82-.67.01-.27.38.01.53.34.19.73.9.82 1.13.16.45.68 1.31 2.69.94 0 .67.01 1.3.01 1.49 0 .21-.15.45-.55.38A7.995 7.995 0 0 1 0 8c0-4.42 3.58-8 8-8Z';
21
+
22
+ export const SIGN_IN_PROVIDER_BRANDS: Readonly<Record<SignInProvider, SignInProviderBrand>> = Object.freeze({
23
+ [SignInProvider.Google]: {
24
+ name: 'Google',
25
+ mark: SVG('0 0 48 48',
26
+ '<path fill="#EA4335" d="M24 9.5c3.54 0 6.71 1.22 9.21 3.6l6.85-6.85C35.9 2.38 30.47 0 24 0 14.62 0 6.51 5.38 2.56 13.22l7.98 6.19C12.43 13.72 17.74 9.5 24 9.5z"/>'
27
+ + '<path fill="#4285F4" d="M46.98 24.55c0-1.57-.15-3.09-.38-4.55H24v9.02h12.94c-.58 2.96-2.26 5.48-4.78 7.18l7.73 6c4.51-4.18 7.09-10.36 7.09-17.65z"/>'
28
+ + '<path fill="#FBBC05" d="M10.53 28.59c-.48-1.45-.76-2.99-.76-4.59s.27-3.14.76-4.59l-7.98-6.19C.92 16.46 0 20.12 0 24c0 3.88.92 7.54 2.56 10.78l7.97-6.19z"/>'
29
+ + '<path fill="#34A853" d="M24 48c6.48 0 11.93-2.13 15.89-5.81l-7.73-6c-2.15 1.45-4.92 2.3-8.16 2.3-6.26 0-11.57-4.22-13.47-9.91l-7.98 6.19C6.51 42.62 14.62 48 24 48z"/>'),
30
+ },
31
+ [SignInProvider.Facebook]: {
32
+ name: 'Facebook',
33
+ mark: SVG('0 0 24 24',
34
+ '<circle cx="12" cy="12" r="12" fill="#0866FF"/>'
35
+ + '<path fill="#FFFFFF" d="M16.671 15.469 17.203 12h-3.328V9.749c0-.949.465-1.874 1.956-1.874h1.513V4.922s-1.374-.234-2.686-.234c-2.741 0-4.533 1.66-4.533 4.668V12H7.078v3.469h3.047v8.385a12.09 12.09 0 0 0 3.75 0v-8.385h2.796Z"/>'),
36
+ },
37
+ [SignInProvider.GitHub]: {
38
+ name: 'GitHub',
39
+ mark: SVG('0 0 16 16', `<path fill="currentColor" d="${GITHUB_PATH}"/>`),
40
+ // Black or white only (GitHub's rule): the black mark on its own white disc reads on any button.
41
+ imageMark: SVG('0 0 16 16', `<circle cx="8" cy="8" r="7.5" fill="#FFFFFF"/><path fill="#1F2328" d="${GITHUB_PATH}"/>`),
42
+ },
43
+ [SignInProvider.LinkedIn]: {
44
+ name: 'LinkedIn',
45
+ mark: SVG('0 0 24 24',
46
+ '<rect width="24" height="24" rx="3" fill="#0A66C2"/>'
47
+ + '<path fill="#FFFFFF" d="M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85 3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433a2.062 2.062 0 1 1 0-4.125 2.062 2.062 0 0 1 0 4.125zm1.782 13.019H3.555V9h3.564v11.452z"/>'),
48
+ },
49
+ });
50
+
51
+ /** The provider's name as its brand writes it. */
52
+ export function signInProviderName(provider: SignInProvider | null | undefined): string {
53
+ return (provider && SIGN_IN_PROVIDER_BRANDS[provider]?.name) || '';
54
+ }
55
+
56
+ /** The mark as a `data:` address — for an `<img>` (a builder Image part, an admin button). */
57
+ export function signInProviderMarkUri(provider: SignInProvider): string {
58
+ const brand = SIGN_IN_PROVIDER_BRANDS[provider];
59
+ return `data:image/svg+xml,${encodeURIComponent(brand.imageMark ?? brand.mark)}`;
60
+ }
@@ -12,3 +12,5 @@ export * from './guards';
12
12
  export * from './site-auth';
13
13
  export * from './words';
14
14
  export * from './site-auth-transport';
15
+ export * from './provider-marks';
16
+ export * from './site-methods';
@@ -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
+ }