@recapi/client 0.36.0 → 0.37.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.
package/README.md CHANGED
@@ -54,7 +54,7 @@ are, gzipped, and browsers cache them:
54
54
 
55
55
  ```html
56
56
  <script type="module">
57
- import { createClient } from 'https://api.example.com/sdk/0.36.0/index.js';
57
+ import { createClient } from 'https://api.example.com/sdk/0.37.0/index.js';
58
58
 
59
59
  const recapi = createClient({ apiKey: 'rk_pub_…', baseUrl: 'https://api.example.com', consent: false });
60
60
  // From your cookie banner, once the visitor agrees: recapi.setConsent(true).
@@ -947,7 +947,7 @@ row, with nothing to set in the dashboard (`BOUGHT_TOGETHER` is the product
947
947
  page's second row).
948
948
 
949
949
  ```js
950
- import { RECENTLY_VIEWED } from 'https://api.example.com/sdk/0.36.0/index.js';
950
+ import { RECENTLY_VIEWED } from 'https://api.example.com/sdk/0.37.0/index.js';
951
951
 
952
952
  const [home, recent] = await recapi.recommendLists({
953
953
  lists: [{ placement: 'home', count: 4 }, { placement: RECENTLY_VIEWED, count: 4 }]
@@ -1279,11 +1279,13 @@ way only an id recapi makes (`rec_` and hex digits) is read: any other
1279
1279
  Events are still sent, without `anon_id`. Don't call `track()` if you
1280
1280
  need no network at all. Such an event may name the product page the
1281
1281
  visitor came from on your shop: `track(itemId, 'view', { contextItemId })`.
1282
- `track('view')` and the Shopify snippet fill it themselves from the
1283
- browser's address of the page before, when it is on your shop and can be
1284
- a product's: never the home page, a search, the cart, the checkout, an
1285
- order or an account page, nor a query but a product's (`?id=`). It is sent
1286
- only while the visitor has no id, and read from no storage. Withdrawing consent deletes the stored data.
1282
+ `track('view')`, the Shopify snippet, the WooCommerce plugin and the
1283
+ Magento module fill it themselves from the browser's address of the page
1284
+ before; the pages never sent are listed under
1285
+ [Consent](https://recapi.io/docs/concepts#consent). It is sent only while
1286
+ the visitor has no id, read from no storage, and stands in the page's
1287
+ memory-only history, so the page's lists read where the visitor came
1288
+ from. Withdrawing consent deletes the stored data.
1287
1289
  Granting it merges the in-memory history into storage.
1288
1290
 
1289
1291
  The entry to paste into a cookie banner tool, and how to keep it from
@@ -1353,16 +1355,16 @@ key on a format change makes old data invisible.
1353
1355
  ## Size budget
1354
1356
 
1355
1357
  What a first visit downloads before the library runs: each entry is one
1356
- file, joined and gzipped as the API serves it (library 0.36.0). A test fails
1358
+ file, joined and gzipped as the API serves it (library 0.37.0). A test fails
1357
1359
  when an entry passes its budget (`go test ./internal/jssdk -run SizeBudget -v`
1358
1360
  in `server/` prints these):
1359
1361
 
1360
1362
  | Entry | Bytes | Gzipped | Budget | Its files as they are |
1361
1363
  |---|--:|--:|--:|--:|
1362
- | `index.js` (the pasted tag) | 43,991 | 17,637 | 18,000 | 6 files, 39,877 |
1363
- | `woocommerce.js` | 53,871 | 21,177 | 21,450 | 9 files, 56,556 |
1364
- | `shopify.js` | 56,581 | 22,231 | 22,550 | 9 files, 59,526 |
1365
- | `magento.js` | 53,180 | 20,905 | 21,200 | 9 files, 56,176 |
1364
+ | `index.js` (the pasted tag) | 44,616 | 17,927 | 18,250 | 6 files, 40,404 |
1365
+ | `woocommerce.js` | 54,497 | 21,464 | 21,700 | 9 files, 57,215 |
1366
+ | `shopify.js` | 57,209 | 22,530 | 22,800 | 9 files, 60,185 |
1367
+ | `magento.js` | 53,820 | 21,202 | 21,450 | 9 files, 56,847 |
1366
1368
 
1367
1369
  `index.js` holds the row too, which it used to fetch at the first `row()`.
1368
1370
 
@@ -1380,6 +1382,12 @@ in `server/` writes the files as served, for `scripts/e2e/chain.mjs /tmp/served`
1380
1382
 
1381
1383
  ## Changes
1382
1384
 
1385
+ - 2026-12-04: version 0.37.0. Without consent, the product page a visitor
1386
+ came from stands in the page's memory-only history, so its lists read
1387
+ where they came from; search, cart and account pages in other languages
1388
+ are never sent as the page before.
1389
+ - 2026-12-04: version 0.36.1. In a marked browser the line under the row
1390
+ goes when its row hides, and comes back with the next row drawn.
1383
1391
  - 2026-12-04: version 0.36.0. A visitor without consent can name the
1384
1392
  product page they came from (`contextItemId` on `track()`);
1385
1393
  `track('view')` and the Shopify snippet read it from the browser.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@recapi/client",
3
- "version": "0.36.0",
3
+ "version": "0.37.0",
4
4
  "description": "Browser and Node client for the recapi recommendation API: local decayed history, event batching, attribution.",
5
5
  "homepage": "https://recapi.io/docs",
6
6
  "bugs": {
package/src/cards.js CHANGED
@@ -232,10 +232,23 @@ export function carry(url, recommendationId) {
232
232
  /** The bought-together title only over a real pair: similar products under it would be true cards under a false title. */
233
233
  export const paired = (cards) => cards.some(({ why }) => why === 'bought_together');
234
234
 
235
+ /** The staff line put under a row (ownLine), by row. */
236
+ const lineUnder = new WeakMap();
237
+
238
+ /**
239
+ * The staff line goes with the row it is under, hidden or emptied, or it
240
+ * would stand alone under nothing; the next row drawn puts it back.
241
+ */
242
+ export function unlined(el) {
243
+ lineUnder.get(el)?.remove();
244
+ lineUnder.delete(el);
245
+ }
246
+
235
247
  /** Not only [hidden]: any display rule of the site's beats that one. */
236
248
  export function hide(el) {
237
249
  el.hidden = true;
238
250
  el.style.setProperty('display', 'none', 'important');
251
+ unlined(el);
239
252
  }
240
253
 
241
254
  /**
@@ -273,5 +286,6 @@ export function ownLine(el) {
273
286
  line.remove();
274
287
  });
275
288
  line.append(button);
289
+ lineUnder.set(el, line);
276
290
  el.insertAdjacentElement('afterend', line);
277
291
  }
package/src/client.js CHANGED
@@ -825,7 +825,16 @@ export function createClient(options) {
825
825
  if (quiet) return;
826
826
  const t = now();
827
827
  let attributed = recommendationId;
828
+ const before = pageBefore(itemId, options.contextItemId);
828
829
  mutate(() => {
830
+ // Without consent each page starts with an empty history, kept in
831
+ // memory only: the page the visitor came from, which the event names
832
+ // anyway, stands in as a view a moment before, so this page's lists
833
+ // read where the visitor came from (AP-1067). An address id is read
834
+ // as the product it links by the API.
835
+ if (before !== undefined && level > 0 && !consent && !history.top.has(before)) {
836
+ history = applyEvent(history, { item: before, level: LEVEL_NAMES.view, t: t - 1 }, config);
837
+ }
829
838
  if (level !== 0) history = applyEvent(history, { item: itemId, level, t }, config);
830
839
  // An explicit id of the recommendation that showed the item is still
831
840
  // the click on it; another id leaves the entry alone.
@@ -844,7 +853,7 @@ export function createClient(options) {
844
853
  timestamp: new Date(t).toISOString(),
845
854
  event_id: uuid(),
846
855
  own: own(),
847
- context_item_id: pageBefore(itemId, options.contextItemId)
856
+ context_item_id: before
848
857
  }));
849
858
  if (level === LEVEL_NAMES.view && describing) describePage(itemId);
850
859
  },
package/src/magento.js CHANGED
@@ -16,7 +16,7 @@
16
16
  */
17
17
 
18
18
  import { createClient } from './index.js';
19
- import { GRID, addStyle, blankStyle, blanks, card, cardStyle, carry, escape, headingAbove, idOf, listOf, listStyle, nameOf, nameStyle, near, opened, ownLine, paired, pictureOf, recentlyViewed, region, wasOf, wasStyle, web } from './cards.js';
19
+ import { GRID, addStyle, blankStyle, blanks, card, cardStyle, carry, escape, headingAbove, idOf, listOf, listStyle, nameOf, nameStyle, near, opened, ownLine, paired, pictureOf, recentlyViewed, region, unlined, wasOf, wasStyle, web } from './cards.js';
20
20
  import { bought, fillRows, followReturns, landing, onReturn, orderStorage } from './shops.js';
21
21
  import { storageKey } from './storage.js';
22
22
  // Their own imports, named so the browser asks for all at once (TestEntriesImportTheirWholeGraph).
@@ -242,6 +242,7 @@ export async function magentoPage(page) {
242
242
  if (!cards.length) {
243
243
  row.slot.innerHTML = '';
244
244
  blockOf(row.slot).hidden = true;
245
+ unlined(blockOf(row.slot));
245
246
  return;
246
247
  }
247
248
  if (!styledYet) styled();
package/src/page.js CHANGED
@@ -157,10 +157,18 @@ const PRODUCT_KEYS = new Set(['p', 'id', 'pid', 'product', 'product_id', 'produc
157
157
 
158
158
  // Path segments of pages that are no product's, and may name what a visitor
159
159
  // searched, bought or is: search, cart, checkout and order, account and
160
- // sign-in pages, and the shops' own category and tag lists.
160
+ // sign-in pages, and the shops' own category and tag lists. The server also
161
+ // drops a page before that links no product of a shop with links (AP-1067):
162
+ // this list is the guard where the catalog can't tell.
161
163
  const NOT_PRODUCT = new Set(['search', 'catalogsearch', 'cart', 'basket', 'checkout', 'order', 'orders', 'order-received', 'order-pay', 'track-order', 'order-tracking',
162
164
  'thank-you', 'thankyou', 'payment', 'invoice', 'account', 'my-account', 'customer', 'login', 'logout', 'signin', 'sign-in', 'register', 'password',
163
- 'lost-password', 'reset-password', 'wishlist', 'wp-admin', 'wp-login.php', 'wp-json', 'admin', 'product-category', 'product-tag']);
165
+ 'lost-password', 'reset-password', 'wishlist', 'wp-admin', 'wp-login.php', 'wp-json', 'admin', 'product-category', 'product-tag',
166
+ // The same pages in the shops' other languages: a path-style search
167
+ // names its words with no query (`/suche/rotes-kleid`).
168
+ 'suche', 'recherche', 'buscar', 'busqueda', 'búsqueda', 'zoeken', 'ricerca', 'pesquisa', 'busca', 'szukaj', 'sok', 'sök', 'haku', 'hledat',
169
+ 'warenkorb', 'kasse', 'panier', 'commande', 'carrito', 'winkelwagen', 'winkelmandje', 'afrekenen', 'carrello', 'cesta',
170
+ 'mein-konto', 'kundenkonto', 'mon-compte', 'mi-cuenta', 'mijn-account', 'il-mio-account', 'minha-conta',
171
+ 'produkt-kategorie', 'categorie-produit', 'categoria-producto', 'productcategorie', 'categoria-prodotto', 'categoria-produto']);
164
172
 
165
173
  /**
166
174
  * The page before's id for an event without consent (AP-1066), by