@vectoriox/iox-ui 5.99.0 → 5.100.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 (39) hide show
  1. package/actions-core/index.d.ts +7 -4
  2. package/composite-core/index.d.ts +222 -2
  3. package/design-core/index.d.ts +334 -1
  4. package/fesm2022/vectoriox-iox-ui-actions-core.mjs +16 -7
  5. package/fesm2022/vectoriox-iox-ui-actions-core.mjs.map +1 -1
  6. package/fesm2022/vectoriox-iox-ui-composite-core.mjs +948 -256
  7. package/fesm2022/vectoriox-iox-ui-composite-core.mjs.map +1 -1
  8. package/fesm2022/vectoriox-iox-ui-design-core.mjs +416 -1
  9. package/fesm2022/vectoriox-iox-ui-design-core.mjs.map +1 -1
  10. package/fesm2022/vectoriox-iox-ui-forms-core.mjs +3 -24
  11. package/fesm2022/vectoriox-iox-ui-forms-core.mjs.map +1 -1
  12. package/fesm2022/vectoriox-iox-ui-generation-core.mjs +23 -13
  13. package/fesm2022/vectoriox-iox-ui-generation-core.mjs.map +1 -1
  14. package/fesm2022/vectoriox-iox-ui-identity-core.mjs +99 -1
  15. package/fesm2022/vectoriox-iox-ui-identity-core.mjs.map +1 -1
  16. package/fesm2022/vectoriox-iox-ui.mjs +2 -59
  17. package/fesm2022/vectoriox-iox-ui.mjs.map +1 -1
  18. package/forms-core/index.d.ts +2 -23
  19. package/generation-core/index.d.ts +3 -1
  20. package/identity-core/index.d.ts +64 -2
  21. package/index.d.ts +0 -1
  22. package/package.json +1 -1
  23. package/src/actions-core/action.model.ts +1 -1
  24. package/src/actions-core/element-actions.ts +16 -6
  25. package/src/composite-core/account-runtime.ts +428 -0
  26. package/src/composite-core/account.ts +281 -0
  27. package/src/composite-core/public-api.ts +2 -0
  28. package/src/composite-core/recipe-parts.ts +48 -0
  29. package/src/composite-core/shop.ts +6 -26
  30. package/src/design-core/field-classes.ts +65 -0
  31. package/src/design-core/flavor-spec.generated.ts +346 -0
  32. package/src/design-core/public-api.ts +1 -0
  33. package/src/forms-core/field-markup.ts +2 -22
  34. package/src/generation-core/compose-site.ts +19 -9
  35. package/src/generation-core/nav-shape.ts +4 -4
  36. package/src/identity-core/public-api.ts +1 -0
  37. package/src/identity-core/site-auth-transport.ts +134 -0
  38. package/src/identity-core/site-auth.ts +10 -0
  39. package/styles/iox-design.css +38 -0
@@ -1577,6 +1577,36 @@ export const SPEC_TIERS = {
1577
1577
  "name": "cart-note-bg",
1578
1578
  "type": "color",
1579
1579
  "default": "var(--iox-surface-2)"
1580
+ },
1581
+ {
1582
+ "name": "account-button-pad",
1583
+ "type": "spacing",
1584
+ "default": "3px 12px"
1585
+ },
1586
+ {
1587
+ "name": "account-button-gap",
1588
+ "type": "spacing",
1589
+ "default": "8px"
1590
+ },
1591
+ {
1592
+ "name": "account-avatar-size",
1593
+ "type": "size",
1594
+ "default": "26px"
1595
+ },
1596
+ {
1597
+ "name": "account-avatar-bg",
1598
+ "type": "color",
1599
+ "default": "var(--iox-accent)"
1600
+ },
1601
+ {
1602
+ "name": "account-avatar-ink",
1603
+ "type": "color",
1604
+ "default": "var(--iox-accent-ink)"
1605
+ },
1606
+ {
1607
+ "name": "sign-in-error-ink",
1608
+ "type": "color",
1609
+ "default": "var(--iox-danger)"
1580
1610
  }
1581
1611
  ]
1582
1612
  } as const;
@@ -4742,6 +4772,70 @@ export const SPEC_ELEMENT_STYLES = [
4742
4772
  "fontSize": "var(--iox-size-small)"
4743
4773
  }
4744
4774
  },
4775
+ {
4776
+ "id": "account-button",
4777
+ "label": "Account button",
4778
+ "group": "Buttons",
4779
+ "appliesTo": [
4780
+ "ButtonBlock"
4781
+ ],
4782
+ "base": {
4783
+ "color": "var(--iox-text)",
4784
+ "backgroundColor": "transparent",
4785
+ "minHeight": "var(--iox-cart-button-size)",
4786
+ "padding": "var(--iox-account-button-pad)",
4787
+ "gap": "var(--iox-account-button-gap)",
4788
+ "borderStyle": "solid",
4789
+ "borderWidth": "var(--iox-border-width)",
4790
+ "borderColor": "var(--iox-line-strong)",
4791
+ "borderRadius": "var(--iox-radius-pill)",
4792
+ "fontFamily": "var(--iox-font-label)",
4793
+ "fontSize": "var(--iox-size-small)",
4794
+ "transitionDuration": "var(--iox-dur-hover)",
4795
+ "transitionTimingFunction": "var(--iox-ease-hover)"
4796
+ },
4797
+ "hover": {
4798
+ "backgroundColor": "var(--iox-surface-2)"
4799
+ },
4800
+ "active": {
4801
+ "scaleX": "var(--iox-press-scale)",
4802
+ "scaleY": "var(--iox-press-scale)"
4803
+ },
4804
+ "focus": {
4805
+ "boxShadow": "var(--iox-focus-ring)"
4806
+ }
4807
+ },
4808
+ {
4809
+ "id": "account-avatar",
4810
+ "label": "Account initial",
4811
+ "group": "Content blocks",
4812
+ "appliesTo": [
4813
+ "Container"
4814
+ ],
4815
+ "base": {
4816
+ "backgroundColor": "var(--iox-account-avatar-bg)",
4817
+ "color": "var(--iox-account-avatar-ink)",
4818
+ "borderRadius": "var(--iox-radius-pill)",
4819
+ "minWidth": "var(--iox-account-avatar-size)",
4820
+ "minHeight": "var(--iox-account-avatar-size)",
4821
+ "fontFamily": "var(--iox-font-label)",
4822
+ "fontSize": "var(--iox-size-label)",
4823
+ "fontWeight": "var(--iox-weight-strong)"
4824
+ }
4825
+ },
4826
+ {
4827
+ "id": "sign-in-error",
4828
+ "label": "Sign-in error",
4829
+ "group": "Text",
4830
+ "appliesTo": [
4831
+ "Text"
4832
+ ],
4833
+ "base": {
4834
+ "color": "var(--iox-sign-in-error-ink)",
4835
+ "fontFamily": "var(--iox-font-body)",
4836
+ "fontSize": "var(--iox-size-small)"
4837
+ }
4838
+ },
4745
4839
  {
4746
4840
  "id": "notice-success",
4747
4841
  "label": "Success message",
@@ -7726,6 +7820,48 @@ export const SPEC_FLAVOR_PACKS = [
7726
7820
  "type": "color",
7727
7821
  "group": "components",
7728
7822
  "value": "var(--iox-surface-2)"
7823
+ },
7824
+ {
7825
+ "name": "account-button-pad",
7826
+ "tier": "component",
7827
+ "type": "spacing",
7828
+ "group": "components",
7829
+ "value": "3px 12px"
7830
+ },
7831
+ {
7832
+ "name": "account-button-gap",
7833
+ "tier": "component",
7834
+ "type": "spacing",
7835
+ "group": "components",
7836
+ "value": "8px"
7837
+ },
7838
+ {
7839
+ "name": "account-avatar-size",
7840
+ "tier": "component",
7841
+ "type": "size",
7842
+ "group": "components",
7843
+ "value": "26px"
7844
+ },
7845
+ {
7846
+ "name": "account-avatar-bg",
7847
+ "tier": "component",
7848
+ "type": "color",
7849
+ "group": "components",
7850
+ "value": "var(--iox-accent)"
7851
+ },
7852
+ {
7853
+ "name": "account-avatar-ink",
7854
+ "tier": "component",
7855
+ "type": "color",
7856
+ "group": "components",
7857
+ "value": "var(--iox-accent-ink)"
7858
+ },
7859
+ {
7860
+ "name": "sign-in-error-ink",
7861
+ "tier": "component",
7862
+ "type": "color",
7863
+ "group": "components",
7864
+ "value": "var(--iox-danger)"
7729
7865
  }
7730
7866
  ]
7731
7867
  },
@@ -10016,6 +10152,48 @@ export const SPEC_FLAVOR_PACKS = [
10016
10152
  "type": "color",
10017
10153
  "group": "components",
10018
10154
  "value": "var(--iox-surface-2)"
10155
+ },
10156
+ {
10157
+ "name": "account-button-pad",
10158
+ "tier": "component",
10159
+ "type": "spacing",
10160
+ "group": "components",
10161
+ "value": "3px 12px"
10162
+ },
10163
+ {
10164
+ "name": "account-button-gap",
10165
+ "tier": "component",
10166
+ "type": "spacing",
10167
+ "group": "components",
10168
+ "value": "8px"
10169
+ },
10170
+ {
10171
+ "name": "account-avatar-size",
10172
+ "tier": "component",
10173
+ "type": "size",
10174
+ "group": "components",
10175
+ "value": "26px"
10176
+ },
10177
+ {
10178
+ "name": "account-avatar-bg",
10179
+ "tier": "component",
10180
+ "type": "color",
10181
+ "group": "components",
10182
+ "value": "var(--iox-accent)"
10183
+ },
10184
+ {
10185
+ "name": "account-avatar-ink",
10186
+ "tier": "component",
10187
+ "type": "color",
10188
+ "group": "components",
10189
+ "value": "var(--iox-accent-ink)"
10190
+ },
10191
+ {
10192
+ "name": "sign-in-error-ink",
10193
+ "tier": "component",
10194
+ "type": "color",
10195
+ "group": "components",
10196
+ "value": "var(--iox-danger)"
10019
10197
  }
10020
10198
  ]
10021
10199
  },
@@ -12294,6 +12472,48 @@ export const SPEC_FLAVOR_PACKS = [
12294
12472
  "type": "color",
12295
12473
  "group": "components",
12296
12474
  "value": "var(--iox-surface-2)"
12475
+ },
12476
+ {
12477
+ "name": "account-button-pad",
12478
+ "tier": "component",
12479
+ "type": "spacing",
12480
+ "group": "components",
12481
+ "value": "3px 12px"
12482
+ },
12483
+ {
12484
+ "name": "account-button-gap",
12485
+ "tier": "component",
12486
+ "type": "spacing",
12487
+ "group": "components",
12488
+ "value": "8px"
12489
+ },
12490
+ {
12491
+ "name": "account-avatar-size",
12492
+ "tier": "component",
12493
+ "type": "size",
12494
+ "group": "components",
12495
+ "value": "26px"
12496
+ },
12497
+ {
12498
+ "name": "account-avatar-bg",
12499
+ "tier": "component",
12500
+ "type": "color",
12501
+ "group": "components",
12502
+ "value": "var(--iox-accent)"
12503
+ },
12504
+ {
12505
+ "name": "account-avatar-ink",
12506
+ "tier": "component",
12507
+ "type": "color",
12508
+ "group": "components",
12509
+ "value": "var(--iox-accent-ink)"
12510
+ },
12511
+ {
12512
+ "name": "sign-in-error-ink",
12513
+ "tier": "component",
12514
+ "type": "color",
12515
+ "group": "components",
12516
+ "value": "var(--iox-danger)"
12297
12517
  }
12298
12518
  ]
12299
12519
  },
@@ -14616,6 +14836,48 @@ export const SPEC_FLAVOR_PACKS = [
14616
14836
  "type": "color",
14617
14837
  "group": "components",
14618
14838
  "value": "var(--iox-surface-2)"
14839
+ },
14840
+ {
14841
+ "name": "account-button-pad",
14842
+ "tier": "component",
14843
+ "type": "spacing",
14844
+ "group": "components",
14845
+ "value": "3px 12px"
14846
+ },
14847
+ {
14848
+ "name": "account-button-gap",
14849
+ "tier": "component",
14850
+ "type": "spacing",
14851
+ "group": "components",
14852
+ "value": "8px"
14853
+ },
14854
+ {
14855
+ "name": "account-avatar-size",
14856
+ "tier": "component",
14857
+ "type": "size",
14858
+ "group": "components",
14859
+ "value": "26px"
14860
+ },
14861
+ {
14862
+ "name": "account-avatar-bg",
14863
+ "tier": "component",
14864
+ "type": "color",
14865
+ "group": "components",
14866
+ "value": "var(--iox-accent)"
14867
+ },
14868
+ {
14869
+ "name": "account-avatar-ink",
14870
+ "tier": "component",
14871
+ "type": "color",
14872
+ "group": "components",
14873
+ "value": "var(--iox-accent-ink)"
14874
+ },
14875
+ {
14876
+ "name": "sign-in-error-ink",
14877
+ "tier": "component",
14878
+ "type": "color",
14879
+ "group": "components",
14880
+ "value": "var(--iox-danger)"
14619
14881
  }
14620
14882
  ]
14621
14883
  },
@@ -16900,6 +17162,48 @@ export const SPEC_FLAVOR_PACKS = [
16900
17162
  "type": "color",
16901
17163
  "group": "components",
16902
17164
  "value": "var(--iox-surface-2)"
17165
+ },
17166
+ {
17167
+ "name": "account-button-pad",
17168
+ "tier": "component",
17169
+ "type": "spacing",
17170
+ "group": "components",
17171
+ "value": "3px 12px"
17172
+ },
17173
+ {
17174
+ "name": "account-button-gap",
17175
+ "tier": "component",
17176
+ "type": "spacing",
17177
+ "group": "components",
17178
+ "value": "8px"
17179
+ },
17180
+ {
17181
+ "name": "account-avatar-size",
17182
+ "tier": "component",
17183
+ "type": "size",
17184
+ "group": "components",
17185
+ "value": "26px"
17186
+ },
17187
+ {
17188
+ "name": "account-avatar-bg",
17189
+ "tier": "component",
17190
+ "type": "color",
17191
+ "group": "components",
17192
+ "value": "var(--iox-accent)"
17193
+ },
17194
+ {
17195
+ "name": "account-avatar-ink",
17196
+ "tier": "component",
17197
+ "type": "color",
17198
+ "group": "components",
17199
+ "value": "var(--iox-accent-ink)"
17200
+ },
17201
+ {
17202
+ "name": "sign-in-error-ink",
17203
+ "tier": "component",
17204
+ "type": "color",
17205
+ "group": "components",
17206
+ "value": "var(--iox-danger)"
16903
17207
  }
16904
17208
  ]
16905
17209
  },
@@ -19193,6 +19497,48 @@ export const SPEC_FLAVOR_PACKS = [
19193
19497
  "type": "color",
19194
19498
  "group": "components",
19195
19499
  "value": "var(--iox-surface-2)"
19500
+ },
19501
+ {
19502
+ "name": "account-button-pad",
19503
+ "tier": "component",
19504
+ "type": "spacing",
19505
+ "group": "components",
19506
+ "value": "3px 12px"
19507
+ },
19508
+ {
19509
+ "name": "account-button-gap",
19510
+ "tier": "component",
19511
+ "type": "spacing",
19512
+ "group": "components",
19513
+ "value": "8px"
19514
+ },
19515
+ {
19516
+ "name": "account-avatar-size",
19517
+ "tier": "component",
19518
+ "type": "size",
19519
+ "group": "components",
19520
+ "value": "26px"
19521
+ },
19522
+ {
19523
+ "name": "account-avatar-bg",
19524
+ "tier": "component",
19525
+ "type": "color",
19526
+ "group": "components",
19527
+ "value": "var(--iox-accent)"
19528
+ },
19529
+ {
19530
+ "name": "account-avatar-ink",
19531
+ "tier": "component",
19532
+ "type": "color",
19533
+ "group": "components",
19534
+ "value": "var(--iox-accent-ink)"
19535
+ },
19536
+ {
19537
+ "name": "sign-in-error-ink",
19538
+ "tier": "component",
19539
+ "type": "color",
19540
+ "group": "components",
19541
+ "value": "var(--iox-danger)"
19196
19542
  }
19197
19543
  ]
19198
19544
  }
@@ -18,6 +18,7 @@ export * from './flavor';
18
18
  export * from './element-styles';
19
19
  export * from './adopt';
20
20
  export * from './node-classes';
21
+ export * from './field-classes';
21
22
  export * from './empty-image';
22
23
  export * from './node-links';
23
24
  export * from './brand';
@@ -15,29 +15,9 @@
15
15
  import { ChoiceAppearance, ControlType } from './form.model';
16
16
  import { datePickerWords } from './dates';
17
17
  import { fieldOptionsOf } from './options';
18
+ import { FieldClass } from '@vectoriox/iox-ui/design-core';
18
19
 
19
- /** The classes the markup carries — the runtimes and the shared CSS key on these, never on a literal. */
20
- export enum FieldClass {
21
- Root = 'iox-field',
22
- Label = 'iox-field__label',
23
- LabelHidden = 'iox-field__label--hidden',
24
- Required = 'iox-field__required',
25
- Control = 'iox-field__control',
26
- Help = 'iox-field__help',
27
- Error = 'iox-field__error',
28
- Group = 'iox-field__group',
29
- Option = 'iox-field__option',
30
- Choices = 'iox-field__choices',
31
- ChoicesChips = 'iox-field__choices--chips',
32
- ChoicesList = 'iox-field__choices--list',
33
- Chips = 'iox-field__chips',
34
- Chip = 'iox-field__chip',
35
- ChipInput = 'iox-field__control--chip',
36
- DateButton = 'iox-field__control--date',
37
- DateValue = 'iox-field__date-value',
38
- DateIcon = 'iox-field__date-icon',
39
- DateInput = 'iox-field__date-input',
40
- }
20
+ export { FIELD_INVALID_CLASS, FieldClass, writeFieldError } from '@vectoriox/iox-ui/design-core';
41
21
 
42
22
  /** On the date button: the raw Earliest / Latest (`'0'`, an ISO day), resolved by the visitor's own today. */
43
23
  export const DATE_MIN_ATTRIBUTE = 'data-iox-date-min';
@@ -9,7 +9,7 @@ import {
9
9
  AccordionAutoBinds, CompositeNodeSpec, findByRole, LIGHTBOX_LABEL, SLIDE_TO_ROW, SLIDE_TYPE, buildTabsRecipe, tabLabelNodeOf,
10
10
  tabPanelImageOf, tabPanelTextOf, tabsListOf, tabsPanels, tabsPanelsOf, tabsTriggers, TABS_CONTENT_LIMIT, TABS_IMAGE_BIND_PROP, TABS_LABEL_BIND_PROP,
11
11
  TABS_TEXT_BIND_PROP, TABS_WORDS, TabsAutoBinds, BadgeTone, BADGE_TONES, buildSegmentedRecipe, CardWords, ITEM_OPEN_STATE, segmentedOptions,
12
- setHeaderBehaviour, SHOP_RECIPES, ShopRecipe, ShopRole, bindShopPart, ShopBindTarget,
12
+ setHeaderBehaviour, SHOP_RECIPES, ShopRecipe, ShopRole, bindShopPart, ShopBindTarget, ACCOUNT_RECIPES, AccountRecipe,
13
13
  } from '@vectoriox/iox-ui/composite-core';
14
14
 
15
15
  import { EntranceMark, EntrancePart, planEntrances } from './entrances';
@@ -1094,6 +1094,11 @@ const CART_DRAWER_KEY = 'cart-drawer';
1094
1094
  /** The ids the composer gives them (the header's bag; the drawer, a global after the page). */
1095
1095
  export const SHOP_CART_BUTTON_ID = 'header-cart';
1096
1096
  export const SHOP_CART_DRAWER_ID = 'cart';
1097
+ /** E3a's root keys and the ids the composer gives them: the header's account entry, the ONE sign-in dialog (a global). */
1098
+ const ACCOUNT_ENTRY_KEY = 'account';
1099
+ const SIGN_IN_DIALOG_KEY = 'sign-in';
1100
+ export const ACCOUNT_ENTRY_ID = 'header-account';
1101
+ export const SIGN_IN_DIALOG_ID = 'sign-in';
1097
1102
 
1098
1103
  /**
1099
1104
  * Commerce G1: a shop part stamped whole from E1c's recipe (`SHOP_RECIPES`) — the product page's own reading the page's
@@ -1120,26 +1125,31 @@ function composeShopRecipe(pn: PatternNode, id: string, repeater: RepeaterScope
1120
1125
  }
1121
1126
 
1122
1127
  /**
1123
- * Commerce G1 (C-D21): a selling site is a whole store on every page — the header holds the bag (before the menu
1124
- * button; the brand takes the row's free space, so the bag sits at the end on every width, either direction), and the
1125
- * site holds the ONE cart drawer as a global after the page (`SHOP_GLOBAL_RECIPES`), which every bag opens. Check out
1126
- * is the drawer's own (the fixed checkout). Pure: new globals.
1128
+ * Commerce G1 (C-D21): a selling site is a whole store on every page — the header holds the account entry and the bag
1129
+ * (before the menu button; the brand takes the row's free space, so they sit at the end on every width, either
1130
+ * direction), and the site holds the ONE cart drawer and the ONE sign-in dialog as globals after the page
1131
+ * (`SHOP_GLOBAL_RECIPES`, `ACCOUNT_GLOBAL_RECIPES` — E3a, R-H9), which every bag and every entry open. Check out is the
1132
+ * drawer's own (the fixed checkout). Pure: new globals.
1127
1133
  */
1128
- function withStore(globals: SerializedNode[]): SerializedNode[] {
1134
+ function withStore(globals: SerializedNode[], locale: string): SerializedNode[] {
1129
1135
  const out = [...globals];
1130
1136
  const header = out.find(g => g.id === GlobalSlot.Header);
1131
1137
  if (header) {
1132
1138
  const kids = header.children ?? (header.children = []);
1139
+ const account = ACCOUNT_RECIPES[AccountRecipe.Entry](recipeFactory(ACCOUNT_ENTRY_ID, ACCOUNT_ENTRY_KEY), locale) as SerializedNode;
1133
1140
  const bag = SHOP_RECIPES[ShopRecipe.CartButton](recipeFactory(SHOP_CART_BUTTON_ID, CART_BUTTON_KEY)) as SerializedNode;
1134
1141
  const menu = kids.findIndex(k => k.role === NavRole.MenuButton);
1135
- kids.splice(menu >= 0 ? menu : kids.length, 0, bag);
1142
+ kids.splice(menu >= 0 ? menu : kids.length, 0, account, bag);
1136
1143
  const brand = kids.find(k => k.role === NavRole.Brand);
1137
1144
  if (brand) setStyleProps(brand, { flexGrow: '1' });
1138
1145
  }
1139
1146
  const drawer = SHOP_RECIPES[ShopRecipe.CartDrawer](recipeFactory(SHOP_CART_DRAWER_ID, CART_DRAWER_KEY)) as SerializedNode;
1140
1147
  drawer.isGlobal = true;
1141
1148
  drawer.globalPosition = PatternGlobalPosition.After;
1142
- out.push(drawer);
1149
+ const signIn = ACCOUNT_RECIPES[AccountRecipe.SignInDialog](recipeFactory(SIGN_IN_DIALOG_ID, SIGN_IN_DIALOG_KEY), locale) as SerializedNode;
1150
+ signIn.isGlobal = true;
1151
+ signIn.globalPosition = PatternGlobalPosition.After;
1152
+ out.push(drawer, signIn);
1143
1153
  return out;
1144
1154
  }
1145
1155
 
@@ -1481,7 +1491,7 @@ export function composeSite(plan: SitePlan, context: ComposeContext): ComposedSi
1481
1491
  const root = header ? globals.find(g => g.id === slot) : null;
1482
1492
  if (header && root) setHeaderBehaviour(root as unknown as CompositeNode, header.behaviour, header.edge ?? null);
1483
1493
  }
1484
- if (planSells(plan)) globals = withStore(globals);
1494
+ if (planSells(plan)) globals = withStore(globals, plan.locale ?? DEFAULT_SITE_LOCALE);
1485
1495
 
1486
1496
  return {
1487
1497
  source: clone(plan.source),
@@ -1,4 +1,4 @@
1
- import { ShopRole } from '@vectoriox/iox-ui/composite-core';
1
+ import { AccountRole, ShopRole } from '@vectoriox/iox-ui/composite-core';
2
2
  import { LinkType } from '@vectoriox/iox-ui/design-core';
3
3
 
4
4
  import { PatternGlobalPosition } from './patterns';
@@ -434,10 +434,10 @@ function removeRole(node: SerializedNode, role: NavRole): SerializedNode | null
434
434
  return removed;
435
435
  }
436
436
 
437
- /** The root's own parts that hide at the phone width: everything but the brand, the menu button, the drawer and a
438
- * store's bag (commerce G1 — a phone visitor reaches the cart from every page). */
437
+ /** The root's own parts that hide at the phone width: everything but the brand, the menu button, the drawer, a store's
438
+ * bag (commerce G1 — a phone visitor reaches the cart from every page) and its account entry (E3a — icon only there). */
439
439
  function phoneHiddenParts(root: SerializedNode): SerializedNode[] {
440
- const keep = new Set<string | undefined>([NavRole.Brand, NavRole.MenuButton, NavRole.Drawer, ShopRole.CartButton]);
440
+ const keep = new Set<string | undefined>([NavRole.Brand, NavRole.MenuButton, NavRole.Drawer, ShopRole.CartButton, AccountRole.Account]);
441
441
  return (root.children ?? []).filter((c, i) => !keep.has(roleOf(c)) && !(i === 0 && !c.role && c.type === LINKED));
442
442
  }
443
443
 
@@ -11,3 +11,4 @@ export * from './sign-in';
11
11
  export * from './guards';
12
12
  export * from './site-auth';
13
13
  export * from './words';
14
+ export * from './site-auth-transport';
@@ -0,0 +1,134 @@
1
+ import { isSameOriginPath } from './guards';
2
+ import { isEmailCodeShape, normalizeEmailCode, normalizeSignInEmail, SiteCustomer } from './site-auth';
3
+ import { brokerStartUrl, SignInProvider } from './sign-in';
4
+ import { SiteSignInRefusalCode, siteSignInCodeOf } from './words';
5
+
6
+ /**
7
+ * THE TRANSPORT a site's sign-in parts speak (commerce E3a, the `CartTransport` rule): the parts own no HTTP. The engine
8
+ * implements it over iox-cms's site routes (`siteAuthPath`, `siteProviderPath`, the cookie carried by the browser); the
9
+ * builder canvas uses `simulatedSiteAuthTransport` — the ADMIN's browser is never a buyer, so nothing is sent and no
10
+ * session exists.
11
+ */
12
+ export interface SiteAuthTransport {
13
+ /** The signed-in buyer, or null. */
14
+ me(): Promise<SiteCustomer | null>;
15
+ /** Ask the studio to start a provider's sign-in; the answer is the address the browser goes to next. */
16
+ startProvider(provider: SignInProvider, returnPath: string): Promise<{ startUrl: string }>;
17
+ /** Send a code to `email` (the studio always accepts — it never says whether the email is known). */
18
+ sendCode(email: string): Promise<void>;
19
+ /** Check the code; the signed-in buyer. */
20
+ verifyCode(email: string, code: string): Promise<SiteCustomer>;
21
+ signOut(): Promise<void>;
22
+ }
23
+
24
+ /** A refused transport call, carrying the code the visitor's words come from (`signInRefusal`). */
25
+ export class SiteAuthError extends Error {
26
+ readonly code: SiteSignInRefusalCode;
27
+
28
+ constructor(code: unknown) {
29
+ const known = siteSignInCodeOf(code);
30
+ super(known);
31
+ this.name = 'SiteAuthError';
32
+ this.code = known;
33
+ }
34
+ }
35
+
36
+ /** The code any thrown value carries: a `SiteAuthError`'s own, else `network` (the call never answered). */
37
+ export function siteAuthErrorCode(error: unknown): SiteSignInRefusalCode {
38
+ return error instanceof SiteAuthError ? error.code : SiteSignInRefusalCode.Network;
39
+ }
40
+
41
+ /** The sample buyer the canvas signs in as. */
42
+ export const SAMPLE_CUSTOMER: Readonly<SiteCustomer> = Object.freeze({ id: 'sample-customer', email: 'noa.levi@example.com', name: 'Noa Levi' });
43
+
44
+ /** The one code the simulated transport accepts (any other six digits are "not right" — so the error can be designed). */
45
+ export const SIMULATED_SIGN_IN_CODE = '123456';
46
+
47
+ export interface SimulatedSiteAuthTransport extends SiteAuthTransport {
48
+ /** Who is signed in on the canvas right now. */
49
+ readonly customer: SiteCustomer | null;
50
+ setCustomer(customer: SiteCustomer | null): void;
51
+ }
52
+
53
+ /**
54
+ * The canvas' transport: in memory, nothing sent. A code is "sent" to any well-formed email; `123456` signs in as the
55
+ * sample buyer under the typed email, any other six digits are `code-wrong`; a provider's start answers the broker's
56
+ * address with a sample ticket (the canvas host never follows it).
57
+ */
58
+ export function simulatedSiteAuthTransport(start: SiteCustomer | null = null): SimulatedSiteAuthTransport {
59
+ let customer: SiteCustomer | null = start;
60
+ const sentTo = new Set<string>();
61
+ return {
62
+ get customer() {
63
+ return customer;
64
+ },
65
+ setCustomer(next) {
66
+ customer = next;
67
+ },
68
+ async me() {
69
+ return customer;
70
+ },
71
+ async startProvider(provider, returnPath) {
72
+ if (!isSameOriginPath(returnPath)) throw new SiteAuthError(SiteSignInRefusalCode.Failed);
73
+ return { startUrl: brokerStartUrl(provider, 'sample-ticket') };
74
+ },
75
+ async sendCode(email) {
76
+ const key = normalizeSignInEmail(email);
77
+ if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(key)) throw new SiteAuthError(SiteSignInRefusalCode.InvalidEmail);
78
+ sentTo.add(key);
79
+ },
80
+ async verifyCode(email, code) {
81
+ const key = normalizeSignInEmail(email);
82
+ const digits = normalizeEmailCode(code);
83
+ if (!sentTo.has(key) || !isEmailCodeShape(digits)) throw new SiteAuthError(SiteSignInRefusalCode.CodeWrong);
84
+ if (digits !== SIMULATED_SIGN_IN_CODE) throw new SiteAuthError(SiteSignInRefusalCode.CodeWrong);
85
+ customer = { ...SAMPLE_CUSTOMER, email: key };
86
+ return customer;
87
+ },
88
+ async signOut() {
89
+ customer = null;
90
+ },
91
+ };
92
+ }
93
+
94
+ /** A transport that has nothing to reach: `me` is null, every change refused as `network`. */
95
+ export const NO_SITE_AUTH_TRANSPORT: SiteAuthTransport = Object.freeze({
96
+ me: async () => null,
97
+ startProvider: async () => { throw new SiteAuthError(SiteSignInRefusalCode.ProviderUnavailable); },
98
+ sendCode: async () => { throw new SiteAuthError(SiteSignInRefusalCode.Network); },
99
+ verifyCode: async () => { throw new SiteAuthError(SiteSignInRefusalCode.Network); },
100
+ signOut: async () => undefined,
101
+ });
102
+
103
+ // ── what a page shows of the buyer ───────────────────────────────────────────────────────────
104
+
105
+ /** The context slot the account parts bind to (`$customer.initial`, `$customer.name`). */
106
+ export const CUSTOMER_SLOT = '$customer';
107
+
108
+ /** `$customer` — what a page may show of the buyer: never the id. */
109
+ export interface CustomerSlot {
110
+ signedIn: boolean;
111
+ name: string;
112
+ /** The first letter of the name, else of the email; '' when signed out. */
113
+ initial: string;
114
+ email: string;
115
+ }
116
+
117
+ /** The first visible letter of a name or an email, upper-cased where the script has case. */
118
+ export function customerInitial(customer: Pick<SiteCustomer, 'name' | 'email'> | null | undefined): string {
119
+ const source = (customer?.name ?? '').trim() || (customer?.email ?? '').trim();
120
+ const first = Array.from(source)[0] ?? '';
121
+ return first.toLocaleUpperCase();
122
+ }
123
+
124
+ /** The name a page greets with: the buyer's own, else the email's local part. */
125
+ export function customerDisplayName(customer: Pick<SiteCustomer, 'name' | 'email'> | null | undefined): string {
126
+ const name = (customer?.name ?? '').trim();
127
+ if (name) return name;
128
+ return (customer?.email ?? '').split('@')[0] ?? '';
129
+ }
130
+
131
+ export function customerSlotOf(customer: SiteCustomer | null | undefined): CustomerSlot {
132
+ if (!customer) return { signedIn: false, name: '', initial: '', email: '' };
133
+ return { signedIn: true, name: customerDisplayName(customer), initial: customerInitial(customer), email: customer.email };
134
+ }