@rocketsearch/vue-uappi 0.2.1 → 0.2.3

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/README.md CHANGED
@@ -30,8 +30,11 @@ Use os componentes em PascalCase (`<RocketSearch>`, `<RocketShowcase position="t
30
30
  Vitrines em abas: `showcaseTabs: true` (ou `['top']`, só nessas posições) no `app.use` junta as vitrines da mesma
31
31
  posição numa barra de abas; a prop `tabs` / `:tabs="false"` do `<RocketShowcase>` vence a opção.
32
32
 
33
- Landing page ("Personalizado" no painel): `<RocketLanding>` mostra todas as vitrines da landing, na ordem do
34
- painel. O identificador vem do nome da rota (`/black-friday` → `black-friday`) ou de `custom-key="..."`.
33
+ Landing page ("Personalizado" no painel): na landing da Uappi (nivel `landing-page`), os `<RocketShowcase position>`
34
+ que o tema já tem mostram as vitrines da landing, cada uma na posição escolhida no painel. O identificador é o fim da
35
+ URL (`/c/black-friday` → `black-friday`). Página sem essas posições: `<RocketLanding>` empilha todas as vitrines da
36
+ landing na ordem do painel, com o identificador do nome da rota ou de `custom-key="..."`. Não use os dois na mesma
37
+ página, senão a vitrine aparece duas vezes.
35
38
  Banners da landing: `<RocketBanner page-type="custom" />`, com a mesma regra do identificador.
36
39
 
37
40
  Banners do megamenu: `<RocketBanner position="menu" :menu-key="aba.label" page-type="home" @loaded="...">`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rocketsearch/vue-uappi",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "Rocket Search para storefronts Uappi em Vue 3 + Vite + Pinia: busca, autocomplete, vitrines, banners e eventos",
5
5
  "type": "module",
6
6
  "main": "index.js",
package/runtime/rocket.js CHANGED
@@ -94,10 +94,11 @@ export function sectionFromNivel (nivel) {
94
94
  // Vocabulário da API de vitrines/banners (pageType): product|category|home|search|cart|checkout.
95
95
  export function pageTypeFromSection (section) {
96
96
  if (section === 'pdp') return 'product';
97
- // Landing (list) não é categoria: as vitrines dela vêm só do <RocketLanding> (pageType=custom + customKey).
98
- // Mandada como category, toda vitrine de categoria vazava para a landing (ROC-709).
97
+ // Landing (list) não é categoria (ROC-709): é a página Personalizado do painel, com o fim da URL
98
+ // como customKey. As posições da landing (hero, top...) pedem as vitrines dela, não as de categoria.
99
+ if (section === 'list') return 'custom';
99
100
  if (section === 'brand') return 'category';
100
- if (section === 'list' || section === 'other') return '';
101
+ if (section === 'other') return '';
101
102
  return section || '';
102
103
  }
103
104
 
@@ -152,6 +153,13 @@ export function createRocket (config) {
152
153
  }
153
154
  rocket.resolvePageType = resolvePageType;
154
155
 
156
+ // Identificador da landing sem custom-key explícito: o fim da URL (/c/black-friday → black-friday),
157
+ // a mesma regra do <RocketLanding>. No servidor não há URL: a landing fica sem vitrine/banner.
158
+ function landingKey (customKey) {
159
+ if (customKey) return customKey;
160
+ return isBrowser ? (location.pathname || '').toLowerCase().split('/').filter(Boolean).pop() || '' : '';
161
+ }
162
+
155
163
  // ---- Sessão ----
156
164
 
157
165
  // Sessão = id local, igual à Linx para shopper anônimo. NÃO usamos o PHPSESSID da Uappi:
@@ -306,7 +314,8 @@ export function createRocket (config) {
306
314
  // customKey: identificador da landing (pageType=custom); sem ele a API responde 400.
307
315
  rocket.getShowcasesByContext = async function (type, customKey) {
308
316
  const pageType = resolvePageType(type);
309
- if (!pageType) return [];
317
+ if (pageType === 'custom') customKey = landingKey(customKey);
318
+ if (!pageType || (pageType === 'custom' && !customKey)) return [];
310
319
  const sessionId = await getSessionIdWithTimeout();
311
320
  const params = { storeId: config.storeId, pageType, page: pageType, sessionId };
312
321
  if (pageType === 'product' && page.productId) params.productId = page.productId;
@@ -346,13 +355,16 @@ export function createRocket (config) {
346
355
  const bannerCache = {};
347
356
  rocket.getBannersByContext = function (type, options) {
348
357
  const pageType = resolvePageType(type);
349
- if (!pageType) return Promise.resolve([]);
350
358
  const opts = options || {};
351
- const customKey = pageType === 'custom' ? opts.customKey : undefined;
352
- const key = pageType + '|' + (opts.position || '') + '|' + (customKey || '');
359
+ const customKey = pageType === 'custom' ? landingKey(opts.customKey) : undefined;
360
+ if (!pageType || (pageType === 'custom' && !customKey)) return Promise.resolve([]);
361
+ // Banner por categoria (ROC-827): a API só devolve o segmentado se casar a categoria visitada,
362
+ // então ela entra no cache — senão a próxima categoria reaproveitaria o banner da anterior.
363
+ const categoryId = pageType === 'category' && page.categoryId ? page.categoryId : undefined;
364
+ const key = pageType + '|' + (opts.position || '') + '|' + (customKey || '') + '|' + (categoryId || '');
353
365
  const hit = bannerCache[key];
354
366
  if (hit && Date.now() - hit.at < BANNER_TTL) return hit.list;
355
- const list = fetchBanners(pageType, opts.position, customKey).then((banners) => {
367
+ const list = fetchBanners(pageType, opts.position, customKey, categoryId).then((banners) => {
356
368
  if (banners) return banners;
357
369
  delete bannerCache[key];
358
370
  return [];
@@ -362,11 +374,12 @@ export function createRocket (config) {
362
374
  };
363
375
 
364
376
  // null = falhou (não entra no cache).
365
- async function fetchBanners (pageType, position, customKey) {
377
+ async function fetchBanners (pageType, position, customKey, categoryId) {
366
378
  try {
367
379
  const sessionId = await getSessionIdWithTimeout();
368
380
  const params = { storeId: config.storeId, pageType, sessionId, position };
369
381
  if (pageType === 'custom') params.customKey = customKey;
382
+ if (categoryId) params.categoryId = categoryId;
370
383
  const res = await fetch(config.apiUrl + '/banners/context?' + query(params), { headers: headers() });
371
384
  if (!res.ok) return null;
372
385
  const banners = await res.json();