@revenexx/cover 0.2.42 → 0.2.43

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@revenexx/cover",
3
- "version": "0.2.42",
3
+ "version": "0.2.43",
4
4
  "description": "Cover \u2014 revenexx design system for Nuxt. Distributed as a Nuxt layer: generic UI components, theming tokens and stores shared by the demo shop, custom storefronts and the Blokkli theme.",
5
5
  "type": "module",
6
6
  "main": "./nuxt.config.ts",
@@ -52,9 +52,10 @@ function toAccountAddress(row: ApiAddressRow): AccountAddress {
52
52
  }
53
53
 
54
54
  /**
55
- * Live address book: the signed-in contact's addresses in the customers
56
- * app. The contact comes from the session cookie; guests have no address
57
- * book. The customers schema requires ISO 3166-1 alpha-2 countries.
55
+ * Live address book: the signed-in buyer's addresses in the customers app —
56
+ * their own AND their company's, because in B2B the delivery addresses belong
57
+ * to the company. Both references come from the session cookie; guests have no
58
+ * address book. The customers schema requires ISO 3166-1 alpha-2 countries.
58
59
  */
59
60
  export class ApiAddressBookService implements IAddressBookService {
60
61
  private contactRef(event: H3Event): { contact_id?: string; organization_id?: string } {
@@ -69,19 +70,49 @@ export class ApiAddressBookService implements IAddressBookService {
69
70
  return contact_id;
70
71
  }
71
72
 
73
+ /**
74
+ * The addresses this buyer may ship and bill to: their own, plus their
75
+ * company's.
76
+ *
77
+ * The company half is not a nicety. In B2B the delivery addresses are the
78
+ * COMPANY's — that is how they arrive from an ERP, hung on the
79
+ * organisation with no person attached — and a buyer read by contact alone
80
+ * then signs in to "no address available" while the merchant is looking at
81
+ * four of them in the Cockpit. Nobody can order, and nothing in the shop
82
+ * explains why.
83
+ *
84
+ * Two calls rather than one because the list filter is an AND: there is no
85
+ * way to ask for "mine or my company's" in a single query. They are
86
+ * merged by id, personal first, so a buyer's own entry stays the one a
87
+ * checkout adopts when neither is marked default.
88
+ */
72
89
  async list(event: H3Event): Promise<AccountAddress[]> {
73
- const { contact_id } = this.contactRef(event);
74
- if (!contact_id) {
90
+ const { contact_id, organization_id } = this.contactRef(event);
91
+ if (!contact_id && !organization_id) {
75
92
  return [];
76
93
  }
77
94
  try {
78
95
  // Typed list filter (customers.addresses.list declares its query
79
96
  // params — @revenexx/sdk >= 0.0.11).
80
- const { items } = await useRevenexxSdk().customers.customersAddressesList({
81
- contactId: contact_id,
82
- limit: 200,
83
- }) as unknown as { items: ApiAddressRow[] };
84
- return items.map(toAccountAddress);
97
+ const sdk = useRevenexxSdk();
98
+ const [own, company] = await Promise.all([
99
+ contact_id
100
+ ? sdk.customers.customersAddressesList({ contactId: contact_id, limit: 200 }) as unknown as Promise<{ items: ApiAddressRow[] }>
101
+ : Promise.resolve({ items: [] as ApiAddressRow[] }),
102
+ organization_id
103
+ ? sdk.customers.customersAddressesList({ organizationId: organization_id, limit: 200 }) as unknown as Promise<{ items: ApiAddressRow[] }>
104
+ : Promise.resolve({ items: [] as ApiAddressRow[] }),
105
+ ]);
106
+ const seen = new Set<string>();
107
+ return [...(own.items ?? []), ...(company.items ?? [])]
108
+ .filter((row) => {
109
+ if (seen.has(row.id)) {
110
+ return false;
111
+ }
112
+ seen.add(row.id);
113
+ return true;
114
+ })
115
+ .map(toAccountAddress);
85
116
  }
86
117
  catch (err) {
87
118
  getLogService().error("API request failed: addresses/list", apiErrorContext(err));