@eldrajs/theme-cli 0.2.3 → 0.2.5

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 (136) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +6 -0
  3. package/dist/cli.js +9 -4
  4. package/dist/index.d.ts +6 -12
  5. package/dist/index.js +1 -1
  6. package/dist/{validate-DprFpjV7.js → validate-CC6Mp5i_.js} +11 -19
  7. package/package.json +3 -3
  8. package/template/.eldra/previews.json +35 -35
  9. package/template/README.md +3 -1
  10. package/template/app/app.vue +1 -3
  11. package/template/app/assets/main.css +13 -15
  12. package/template/app/components/ui/UiImage.vue +29 -17
  13. package/template/app/components/ui/__tests__/UiImage.spec.ts +24 -15
  14. package/template/app/pages/[...slug].vue +1 -1
  15. package/template/app/storefront/gateway.ts +0 -3
  16. package/template/app/storefront/structuredData.ts +2 -2
  17. package/template/app/storefront/types.ts +0 -5
  18. package/template/app/utils/seoInput.ts +0 -1
  19. package/template/blocks/announcement-bar/Block.vue +3 -2
  20. package/template/blocks/announcement-bar/__tests__/Block.spec.ts +1 -1
  21. package/template/blocks/announcement-bar/preview.png +0 -0
  22. package/template/blocks/article/Block.vue +3 -4
  23. package/template/blocks/article/preview.png +0 -0
  24. package/template/blocks/article-list/Block.vue +18 -9
  25. package/template/blocks/article-list/preview.png +0 -0
  26. package/template/blocks/breadcrumbs/Block.vue +1 -1
  27. package/template/blocks/breadcrumbs/__tests__/Block.spec.ts +9 -9
  28. package/template/blocks/breadcrumbs/preview.png +0 -0
  29. package/template/blocks/cart/Block.vue +1 -1
  30. package/template/blocks/cart/parts/CartLines.vue +3 -2
  31. package/template/blocks/cart/parts/ShippingBar.vue +1 -1
  32. package/template/blocks/cart/parts/Summary.vue +5 -9
  33. package/template/blocks/cart/preview.png +0 -0
  34. package/template/blocks/collection-grid/Block.vue +11 -14
  35. package/template/blocks/collection-grid/__tests__/Block.spec.ts +12 -14
  36. package/template/blocks/collection-grid/preview.png +0 -0
  37. package/template/blocks/collection-header/Block.vue +5 -5
  38. package/template/blocks/collection-header/preview.png +0 -0
  39. package/template/blocks/contact/Block.vue +1 -1
  40. package/template/blocks/contact/__tests__/Block.spec.ts +2 -2
  41. package/template/blocks/contact/preview.png +0 -0
  42. package/template/blocks/cta/Block.vue +16 -18
  43. package/template/blocks/cta/__tests__/Block.spec.ts +8 -12
  44. package/template/blocks/cta/preview.png +0 -0
  45. package/template/blocks/faq/Block.vue +3 -13
  46. package/template/blocks/faq/__tests__/Block.spec.ts +2 -2
  47. package/template/blocks/faq/preview.png +0 -0
  48. package/template/blocks/feature-grid/Block.vue +1 -1
  49. package/template/blocks/feature-grid/__tests__/Block.spec.ts +1 -1
  50. package/template/blocks/feature-grid/preview.png +0 -0
  51. package/template/blocks/footer/Block.vue +14 -11
  52. package/template/blocks/footer/__tests__/Block.spec.ts +5 -5
  53. package/template/blocks/footer/preview.png +0 -0
  54. package/template/blocks/form/Block.vue +1 -1
  55. package/template/blocks/form/preview.png +0 -0
  56. package/template/blocks/gallery/__tests__/Block.spec.ts +1 -1
  57. package/template/blocks/gallery/preview.png +0 -0
  58. package/template/blocks/hero/Block.vue +8 -11
  59. package/template/blocks/hero/__tests__/Block.spec.ts +9 -7
  60. package/template/blocks/hero/preview.png +0 -0
  61. package/template/blocks/image/Block.vue +4 -4
  62. package/template/blocks/image/__tests__/Block.spec.ts +5 -6
  63. package/template/blocks/image/preview.png +0 -0
  64. package/template/blocks/logo-cloud/__tests__/Block.spec.ts +1 -1
  65. package/template/blocks/logo-cloud/preview.png +0 -0
  66. package/template/blocks/navigation/Block.vue +16 -26
  67. package/template/blocks/navigation/__tests__/Block.spec.ts +22 -20
  68. package/template/blocks/navigation/preview.png +0 -0
  69. package/template/blocks/newsletter/__tests__/Block.spec.ts +1 -1
  70. package/template/blocks/newsletter/preview.png +0 -0
  71. package/template/blocks/order-status/Block.vue +8 -9
  72. package/template/blocks/order-status/__tests__/Block.spec.ts +1 -2
  73. package/template/blocks/order-status/preview.png +0 -0
  74. package/template/blocks/pricing-table/__tests__/Block.spec.ts +1 -1
  75. package/template/blocks/pricing-table/preview.png +0 -0
  76. package/template/blocks/product-carousel/Block.vue +6 -6
  77. package/template/blocks/product-carousel/__tests__/Block.spec.ts +26 -8
  78. package/template/blocks/product-carousel/preview.png +0 -0
  79. package/template/blocks/product-detail/Block.vue +8 -8
  80. package/template/blocks/product-detail/__tests__/Block.spec.ts +1 -1
  81. package/template/blocks/product-detail/parts/Gallery.vue +1 -1
  82. package/template/blocks/product-detail/preview.png +0 -0
  83. package/template/blocks/quote/Block.vue +1 -1
  84. package/template/blocks/quote/__tests__/Block.spec.ts +7 -4
  85. package/template/blocks/quote/preview.png +0 -0
  86. package/template/blocks/rich-text/preview.png +0 -0
  87. package/template/blocks/search/Block.vue +2 -2
  88. package/template/blocks/search/PopularChips.vue +1 -1
  89. package/template/blocks/search/preview.png +0 -0
  90. package/template/blocks/split-content/Block.vue +2 -3
  91. package/template/blocks/split-content/__tests__/Block.spec.ts +2 -2
  92. package/template/blocks/split-content/preview.png +0 -0
  93. package/template/blocks/stats/__tests__/Block.spec.ts +1 -1
  94. package/template/blocks/stats/preview.png +0 -0
  95. package/template/blocks/tabs/Block.vue +4 -5
  96. package/template/blocks/tabs/__tests__/Block.spec.ts +2 -2
  97. package/template/blocks/tabs/preview.png +0 -0
  98. package/template/blocks/team/preview.png +0 -0
  99. package/template/blocks/testimonials/Block.vue +10 -9
  100. package/template/blocks/testimonials/__tests__/Block.spec.ts +1 -1
  101. package/template/blocks/testimonials/preview.png +0 -0
  102. package/template/blocks/timeline/__tests__/Block.spec.ts +2 -2
  103. package/template/blocks/timeline/preview.png +0 -0
  104. package/template/blocks/trust-strip/Block.vue +1 -1
  105. package/template/blocks/trust-strip/__tests__/Block.spec.ts +1 -1
  106. package/template/blocks/trust-strip/preview.png +0 -0
  107. package/template/blocks/video-embed/Block.vue +3 -3
  108. package/template/blocks/video-embed/__tests__/Block.spec.ts +1 -1
  109. package/template/blocks/video-embed/preview.png +0 -0
  110. package/template/blocks/wishlist/Block.vue +1 -1
  111. package/template/blocks/wishlist/preview.png +0 -0
  112. package/template/nuxt.config.ts +5 -4
  113. package/template/package.json +2 -1
  114. package/template/stories/pages/article.stories.ts +2 -3
  115. package/template/stories/pages/cart.stories.ts +2 -3
  116. package/template/stories/pages/category.stories.ts +2 -3
  117. package/template/stories/pages/collection.stories.ts +2 -3
  118. package/template/stories/pages/home.stories.ts +2 -3
  119. package/template/stories/pages/product.stories.ts +3 -4
  120. package/template/stories/pages/products.stories.ts +2 -3
  121. package/template/stories/pages/search.stories.ts +2 -3
  122. package/template/stories/pages/wishlist.stories.ts +2 -3
  123. package/template/test/carouselKeyboard.spec.ts +2 -2
  124. package/template/test/carouselRing.browser.spec.ts +2 -2
  125. package/template/test/carouselSlideWidth.browser.spec.ts +9 -9
  126. package/template/test/eldraIcon.spec.ts +1 -1
  127. package/template/test/mainCss.spec.ts +7 -0
  128. package/template/test/pages/article.spec.ts +5 -5
  129. package/template/test/pages/collection.spec.ts +5 -5
  130. package/template/test/pages/hydration.spec.ts +10 -10
  131. package/template/test/prerenderRefresh.browser.spec.ts +51 -1
  132. package/template/test/seoInput.spec.ts +5 -4
  133. package/template/test/storefront/structuredData.spec.ts +3 -6
  134. package/template/test/structuredData.generate.spec.ts +1 -1
  135. package/template/test/support/mockGateway.ts +8 -3
  136. package/template/test/support/mountPage.ts +2 -3
@@ -154,7 +154,7 @@ async function visit(path: string): Promise<Visit> {
154
154
  samples.push(
155
155
  await page.evaluate(() => ({
156
156
  busy: document.querySelectorAll('[aria-busy="true"]').length,
157
- dimmed: document.querySelectorAll('.eldra-revalidating').length,
157
+ dimmed: document.querySelectorAll('.eldra\\:eldra-revalidating').length,
158
158
  spinners: document.querySelectorAll('[data-part="spinner"]').length,
159
159
  announced: [...document.querySelectorAll('[role="status"]')].filter((node) =>
160
160
  /Updating/i.test((node as HTMLElement).textContent ?? '')
@@ -1254,6 +1254,56 @@ describe('prerendered commerce data on the generated static site', () => {
1254
1254
  }
1255
1255
  });
1256
1256
 
1257
+ /** A campaign mail's link, through `@eldrajs/theme-nuxt`'s capture and the SDK's cart add, on a generated site. */
1258
+ it('credits the cart to the campaign the visitor landed from, once they agree', async () => {
1259
+ const campaignId = '0b9f8a52-3c1d-4e6f-9a7b-2c4d6e8f0a1b';
1260
+ const attribution = {
1261
+ campaignId,
1262
+ utmSource: 'eldra',
1263
+ utmMedium: 'email',
1264
+ utmCampaign: 'haustutsala',
1265
+ };
1266
+ const page = await browser.newPage();
1267
+ try {
1268
+ await page.goto(
1269
+ `${statics.origin}${productPage}?utm_source=eldra&utm_medium=email&utm_campaign=haustutsala` +
1270
+ `&utm_id=${campaignId}&gclid=not-kept`,
1271
+ { waitUntil: 'domcontentloaded' }
1272
+ );
1273
+ await page.waitForTimeout(CATALOG_DELAY_MS + 1500);
1274
+ const kept = () => page.evaluate(() => localStorage.getItem('eldra.campaignAttribution'));
1275
+ expect(await kept(), 'nothing is kept before the visitor agrees').toBeNull();
1276
+ const answer = (granted: boolean) =>
1277
+ page.evaluate((value) => {
1278
+ (
1279
+ window as Window & { eldraCampaignAttributionConsent?: boolean }
1280
+ ).eldraCampaignAttributionConsent = value;
1281
+ window.dispatchEvent(new Event('eldra:campaign-attribution-consent'));
1282
+ }, granted);
1283
+ await answer(true);
1284
+ const stored = await kept();
1285
+ expect(JSON.parse(stored ?? 'null')).toMatchObject({ ...attribution, consented: true });
1286
+ expect(stored).not.toContain('gclid');
1287
+
1288
+ gateway.reset();
1289
+ await page.locator('main button[type="submit"]', { hasText: 'Add to cart' }).first().click();
1290
+ await expect.poll(() => gateway.cartAdds.length, { timeout: 5000 }).toBe(1);
1291
+ expect(gateway.cartAdds[0]).toMatchObject({
1292
+ productId: expect.any(String),
1293
+ variantId: `var-${PRODUCT_HANDLE}`,
1294
+ attribution,
1295
+ });
1296
+
1297
+ await answer(false);
1298
+ expect(await kept(), 'withdrawing removes it').toBeNull();
1299
+ await page.locator('main button[type="submit"]', { hasText: 'Add to cart' }).first().click();
1300
+ await expect.poll(() => gateway.cartAdds.length, { timeout: 5000 }).toBe(2);
1301
+ expect(gateway.cartAdds[1]).not.toHaveProperty('attribution');
1302
+ } finally {
1303
+ await page.close();
1304
+ }
1305
+ });
1306
+
1257
1307
  /**
1258
1308
  * **A reload with a cart already in the browser.**
1259
1309
  *
@@ -50,23 +50,24 @@ describe('seoInput', () => {
50
50
  expect(input.options.contentImage).toMatch(/\/lg$/);
51
51
  });
52
52
 
53
- it('sets product.brand from the projection and product.category from the resolved name', () => {
53
+ it('sets product.category from the resolved name and no product.brand, even from a record that has one', () => {
54
54
  const input = seoInput({
55
55
  ...base,
56
56
  catalog: { kind: 'product', slug: 'mug' },
57
57
  productCategory: 'Mugs',
58
58
  entry: { data: { title: 'Mug', brand: 'Acme', variants: [] } },
59
59
  });
60
- expect(input.data).toMatchObject({ 'product.brand': 'Acme', 'product.category': 'Mugs' });
60
+ expect(input.data).toMatchObject({ 'product.category': 'Mugs' });
61
+ expect('product.brand' in input.data).toBe(false);
61
62
  });
62
63
 
63
- it('leaves product.brand and product.category empty when the product has none', () => {
64
+ it('leaves product.category empty when the product has none', () => {
64
65
  const input = seoInput({
65
66
  ...base,
66
67
  catalog: { kind: 'product', slug: 'mug' },
67
68
  entry: { data: { title: 'Mug' } },
68
69
  });
69
- expect(input.data).toMatchObject({ 'product.brand': '', 'product.category': '' });
70
+ expect(input.data).toMatchObject({ 'product.category': '' });
70
71
  });
71
72
 
72
73
  it('leaves a missing price empty instead of inventing one', () => {
@@ -105,7 +105,7 @@ describe('pageStructuredData', () => {
105
105
  title: 'Mug',
106
106
  currentUrl: `${ORIGIN}/products/mug`,
107
107
  trail: [{ label: 'Cups', path: '/categories/cups' }],
108
- product: product({ brand: 'Acme' }),
108
+ product: product(),
109
109
  })
110
110
  );
111
111
  expect(types(entries)).toEqual(['breadcrumb', 'product']);
@@ -117,14 +117,14 @@ describe('pageStructuredData', () => {
117
117
  name: 'Mug',
118
118
  description: 'A hand-thrown mug.',
119
119
  image: ['https://cdn.test/mug.jpg'],
120
- brand: { name: 'Acme' },
120
+ brand: { name: 'Shop' },
121
121
  offers: { price: 2800, priceCurrency: 'ISK', availability: 'https://schema.org/InStock' },
122
122
  });
123
123
  // The number the markup states is the number the visible price is formatted from.
124
124
  expect(formatMoney(node.offers.price, 'ISK', 'en-US')).toContain('2,800');
125
125
  });
126
126
 
127
- it('maps stock states to availability and falls back to the shop name as brand', () => {
127
+ it('maps stock states to availability', () => {
128
128
  const availability = (stock: StorefrontProduct['stock']) =>
129
129
  (
130
130
  pageStructuredData(parts({ kind: 'product', product: product({ stock }) }))[1]!.node
@@ -133,9 +133,6 @@ describe('pageStructuredData', () => {
133
133
  expect(availability('out')).toBe('https://schema.org/OutOfStock');
134
134
  expect(availability('preorder')).toBe('https://schema.org/PreOrder');
135
135
  expect(availability('low')).toBe('https://schema.org/LimitedAvailability');
136
- expect(
137
- pageStructuredData(parts({ kind: 'product', product: product() }))[1]!.node.brand
138
- ).toEqual({ '@type': 'Brand', name: 'Shop' });
139
136
  });
140
137
 
141
138
  it('writes one offer per variant, AggregateOffer when prices differ, and drops a bad barcode', () => {
@@ -112,7 +112,7 @@ describe('generated pages carry schema.org JSON-LD', () => {
112
112
  expect(product).toMatchObject({
113
113
  name: 'Ash glaze mug',
114
114
  url: `${ORIGIN}/products/${PRODUCT_HANDLE}`,
115
- brand: { name: 'Northwind Ceramics' },
115
+ brand: { name: 'Northwind Goods' },
116
116
  sku: PRODUCT_HANDLE.toUpperCase(),
117
117
  gtin: '4006381333931',
118
118
  offers: {
@@ -65,7 +65,6 @@ interface MockProduct {
65
65
  minPrice: number;
66
66
  maxPrice: number;
67
67
  compareAtPrice?: number;
68
- brand?: string;
69
68
  variants: MockVariant[];
70
69
  }
71
70
 
@@ -92,7 +91,6 @@ export const COLLECTION_HANDLE = 'the-winter-edit';
92
91
 
93
92
  export const PRODUCTS: MockProduct[] = [
94
93
  product(PRODUCT_HANDLE, 'Ash glaze mug', 42, {
95
- brand: 'Northwind Ceramics',
96
94
  variants: [
97
95
  {
98
96
  id: `var-${PRODUCT_HANDLE}`,
@@ -234,7 +232,6 @@ const detailOf = (row: MockProduct): Record<string, unknown> => ({
234
232
  // already read. Both, with the same value, is what a live response looks like.
235
233
  primaryCategoryId: row.categoryId,
236
234
  categoryIds: [row.categoryId],
237
- ...(row.brand === undefined ? {} : { brand: row.brand }),
238
235
  description: { text: `${row.title} — thrown by hand, glazed in ash.` },
239
236
  mediaLinks: [],
240
237
  options: [],
@@ -797,6 +794,8 @@ export interface MockGateway {
797
794
  url: string;
798
795
  /** `pathname + search` of every request, in order. */
799
796
  requests: string[];
797
+ /** The JSON body of every `POST /shopping-cart/v1/cart/items`, in order; each answers the seeded cart. */
798
+ cartAdds: unknown[];
800
799
  /** Milliseconds every `/catalog/v1/**` answer is held back. Settable between phases. */
801
800
  catalogDelayMs: number;
802
801
  /**
@@ -828,6 +827,7 @@ export function startMockGateway(
828
827
  setMockCatalogContract(options.catalogContract ?? '3.8.0');
829
828
  return new Promise((resolve) => {
830
829
  const requests: string[] = [];
830
+ const cartAdds: unknown[] = [];
831
831
  const state = {
832
832
  catalogDelayMs: 0,
833
833
  cartDelayMs: 0,
@@ -965,6 +965,9 @@ export function startMockGateway(
965
965
  );
966
966
  } else if (url.pathname === '/inventory/v1/stock/availability') {
967
967
  answer(availabilityOf(await readJsonBody(req)));
968
+ } else if (url.pathname === '/shopping-cart/v1/cart/items' && req.method === 'POST') {
969
+ cartAdds.push(await readJsonBody(req));
970
+ answer(seededCart());
968
971
  } else if (segments[0] === 'shopping-cart' && segments[2] === 'cart') {
969
972
  // The one cart this mock knows, and only by the id a test seeded. Any other id is a cart
970
973
  // the gateway has forgotten — which the store answers by clearing `eldra.cartId` and
@@ -1014,6 +1017,7 @@ export function startMockGateway(
1014
1017
  server,
1015
1018
  url: `http://127.0.0.1:${address.port}`,
1016
1019
  requests,
1020
+ cartAdds,
1017
1021
  get catalogDelayMs() {
1018
1022
  return state.catalogDelayMs;
1019
1023
  },
@@ -1034,6 +1038,7 @@ export function startMockGateway(
1034
1038
  },
1035
1039
  reset() {
1036
1040
  requests.length = 0;
1041
+ cartAdds.length = 0;
1037
1042
  },
1038
1043
  close: () =>
1039
1044
  new Promise<void>((done, fail) =>
@@ -91,9 +91,8 @@ export async function mountPageWithSkipLink(
91
91
  href: '#main',
92
92
  as: EldraRouterLink,
93
93
  variant: 'standalone',
94
- classes: {
95
- root: 'bg-primary text-primary-contrast rounded-md sr-only px-4 py-2 focus:not-sr-only focus:fixed focus:top-4 focus:left-4 focus:z-50',
96
- },
94
+ class:
95
+ 'bg-primary text-primary-contrast rounded-md sr-only px-4 py-2 focus:not-sr-only focus:fixed focus:top-4 focus:left-4 focus:z-50',
97
96
  },
98
97
  () => t('nav.skipToContent')
99
98
  ),