@vtex/faststore-plugin-buyer-portal 2.0.43 → 2.0.45

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": "@vtex/faststore-plugin-buyer-portal",
3
- "version": "2.0.43",
3
+ "version": "2.0.45",
4
4
  "description": "A plugin for faststore with buyer portal",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -53,7 +53,6 @@ export type AddressFormValues = Pick<
53
53
  export type ClearableAddressField = "state" | "streetNumber" | "neighborhood";
54
54
 
55
55
  const NEIGHBORHOOD_LABEL = "addresses.forms.neighborhood";
56
- const COLONIA_LABEL = "addresses.forms.colonia";
57
56
 
58
57
  const FALLBACK_RULE: CountryRule = {
59
58
  zip: { required: true, pattern: null, renderFirst: false },
@@ -148,7 +147,7 @@ const COUNTRY_RULES: Record<SupportedCountryCode, CountryRule> = {
148
147
  neighborhood: {
149
148
  visible: true,
150
149
  required: true,
151
- labelKey: COLONIA_LABEL,
150
+ labelKey: NEIGHBORHOOD_LABEL,
152
151
  },
153
152
  state: { visible: true, required: true },
154
153
  streetAddress: { separated: true },
@@ -376,12 +375,7 @@ export function collectAddressIssues(
376
375
  rule.neighborhood.required &&
377
376
  isBlank(values.neighborhood)
378
377
  ) {
379
- pushRequired(
380
- "neighborhood",
381
- rule.neighborhood.labelKey === COLONIA_LABEL
382
- ? "addresses.validation.coloniaRequired"
383
- : "addresses.validation.neighborhoodRequired"
384
- );
378
+ pushRequired("neighborhood", "addresses.validation.neighborhoodRequired");
385
379
  }
386
380
 
387
381
  return issues;
@@ -0,0 +1,57 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+
5
+ import { describe, expect, it } from "vitest";
6
+
7
+ import { LOCALIZATION_ENTRY_IDS } from "../constants";
8
+
9
+ import type { LocalizationFeature } from "../constants";
10
+
11
+ const PAGES_DIR = path.join(
12
+ path.dirname(fileURLToPath(import.meta.url)),
13
+ "../../../../pages"
14
+ );
15
+
16
+ // Returns the text of the `entryIds` option passed to getLocalizationLabelsService,
17
+ // e.g. `[LOCALIZATION_ENTRY_IDS.orgUnits, LOCALIZATION_ENTRY_IDS.users]`.
18
+ const getRequestedEntries = (page: string): LocalizationFeature[] => {
19
+ const source = fs.readFileSync(path.join(PAGES_DIR, `${page}.tsx`), "utf8");
20
+ const call = source.match(
21
+ /getLocalizationLabelsService\(\{\s*entryIds:\s*([\s\S]*?)\s*,\s*locale/
22
+ );
23
+
24
+ if (!call) throw new Error(`No getLocalizationLabelsService call in ${page}`);
25
+
26
+ return Array.from(call[1].matchAll(/LOCALIZATION_ENTRY_IDS\.(\w+)/g)).map(
27
+ ([, name]) => name as LocalizationFeature
28
+ );
29
+ };
30
+
31
+ // Components rendered by a page resolve `t("<feature>.…")` keys from the entries
32
+ // its loader requests. A shared component whose entry is not requested renders
33
+ // the raw key (B2BTEAM-4276, B2BTEAM-4277).
34
+ const REQUIRED_ENTRIES: Record<string, LocalizationFeature[]> = {
35
+ // Sidebar → AccountingFieldDropdown, CreateAccountingFieldDrawer
36
+ profile: ["accountingFields"],
37
+ // OrgUnitsDropdownMenu → CreateUserDrawerSelector → CreateUserDrawer*
38
+ "org-units": ["users"],
39
+ // AddAllToOrgUnitDropdown → CreateUserDrawerSelector → CreateUserDrawer*
40
+ "org-unit-details": ["users"],
41
+ };
42
+
43
+ describe("page loaders request the localization entries their components use", () => {
44
+ it("knows every required entry", () => {
45
+ Object.values(REQUIRED_ENTRIES)
46
+ .flat()
47
+ .forEach((feature) => {
48
+ expect(LOCALIZATION_ENTRY_IDS).toHaveProperty(feature);
49
+ });
50
+ });
51
+
52
+ Object.entries(REQUIRED_ENTRIES).forEach(([page, features]) => {
53
+ it.each(features)(`${page} requests %s`, (feature) => {
54
+ expect(getRequestedEntries(page)).toContain(feature);
55
+ });
56
+ });
57
+ });
@@ -33,4 +33,4 @@ export const STOREFRONT_RESOURCE_NAMES = {
33
33
  export type StorefrontResourceName =
34
34
  (typeof STOREFRONT_RESOURCE_NAMES)[keyof typeof STOREFRONT_RESOURCE_NAMES];
35
35
 
36
- export const CURRENT_VERSION = "2.0.43";
36
+ export const CURRENT_VERSION = "2.0.45";
@@ -96,6 +96,7 @@ const loaderFunction = async (
96
96
  LOCALIZATION_ENTRY_IDS.orgUnits,
97
97
  LOCALIZATION_ENTRY_IDS.addresses,
98
98
  LOCALIZATION_ENTRY_IDS.accountingFields,
99
+ LOCALIZATION_ENTRY_IDS.users,
99
100
  ],
100
101
  locale: data.locale,
101
102
  }),
@@ -87,7 +87,10 @@ const loaderFunction = async (
87
87
  }),
88
88
  getUserByIdService({ orgUnitId, userId, cookie }),
89
89
  getLocalizationLabelsService({
90
- entryIds: LOCALIZATION_ENTRY_IDS.orgUnits,
90
+ entryIds: [
91
+ LOCALIZATION_ENTRY_IDS.orgUnits,
92
+ LOCALIZATION_ENTRY_IDS.users,
93
+ ],
91
94
  locale: data.locale,
92
95
  }),
93
96
  contractDetailsPromise,
@@ -46,7 +46,10 @@ export async function loaderFunction(
46
46
  data,
47
47
  async ({ customerId, cookie, userId, ...clientContext }) => {
48
48
  const labelsPromise = getLocalizationLabelsService({
49
- entryIds: LOCALIZATION_ENTRY_IDS.profile,
49
+ entryIds: [
50
+ LOCALIZATION_ENTRY_IDS.profile,
51
+ LOCALIZATION_ENTRY_IDS.accountingFields,
52
+ ],
50
53
  locale: data.locale,
51
54
  });
52
55