@recapi/client 0.11.0 → 0.11.1
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 +23 -16
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ needs a newer browser moves this floor and says so under [Changes](#changes).
|
|
|
19
19
|
|
|
20
20
|
On every change to the library, CI runs what a shop page relies on in
|
|
21
21
|
Chromium, Firefox and WebKit, Safari's engine
|
|
22
|
-
(
|
|
22
|
+
(recapi's browser test suite): the
|
|
23
23
|
lists of `recommend()` and `popular()`, a view and a cart credited to the
|
|
24
24
|
recommendation, the history after a reload, the queued events sent when the
|
|
25
25
|
page is left or hidden, consent and Global Privacy Control. That WebKit is
|
|
@@ -35,7 +35,7 @@ are, gzipped, and browsers cache them:
|
|
|
35
35
|
|
|
36
36
|
```html
|
|
37
37
|
<script type="module">
|
|
38
|
-
import { createClient } from 'https://api.example.com/sdk/0.11.
|
|
38
|
+
import { createClient } from 'https://api.example.com/sdk/0.11.1/index.js';
|
|
39
39
|
|
|
40
40
|
const recapi = createClient({ apiKey: 'rk_pub_…', baseUrl: 'https://api.example.com', consent: false });
|
|
41
41
|
// From your cookie banner, once the visitor agrees: recapi.setConsent(true).
|
|
@@ -190,7 +190,7 @@ nothing to paste again. A file of its own rather than more exports of
|
|
|
190
190
|
CDN with `?width=400`), the title and `price_min` formatted with
|
|
191
191
|
`Intl.NumberFormat` in `Shopify.currency.active` and the page's `lang`
|
|
192
192
|
(no price if either is missing). An item whose
|
|
193
|
-
[metadata](
|
|
193
|
+
[metadata](https://recapi.io/docs/api#item-metadata) has a `name` and an http(s)
|
|
194
194
|
`url` skips that lookup: its card is drawn from `name`, `url`, `picture`
|
|
195
195
|
(http(s) only) and `price` (text shown as it is, or a number in the
|
|
196
196
|
shop's currency, `{{ shop.currency }}`, shown only to visitors browsing in
|
|
@@ -199,7 +199,7 @@ nothing to paste again. A file of its own rather than more exports of
|
|
|
199
199
|
snippet can't send metadata: the shop sends it with `PUT /v1/items`, and
|
|
200
200
|
marks a sold-out product inactive there, since no lookup checks it. The
|
|
201
201
|
products export upload and the product webhooks (the quick start's step 4,
|
|
202
|
-
[API](
|
|
202
|
+
[API](https://recapi.io/docs/api#post-v1shopifywebhooks--shopifys-product-webhooks))
|
|
203
203
|
fill it without code; a card whose metadata says `available: false` (maybe
|
|
204
204
|
sold out) is looked up instead. A default style makes them a product row
|
|
205
205
|
in the theme's colours and fonts; all its selectors sit inside
|
|
@@ -400,7 +400,7 @@ The row asks through `recommendLists()`, the call that takes all of a page's
|
|
|
400
400
|
rows, billed as one recommendation with no product on two rows ([Several
|
|
401
401
|
rows in one call](#several-rows-in-one-call)). A page has one recapi row (the
|
|
402
402
|
product page's spot, a block and `[recapi]` never show two), so a page costs
|
|
403
|
-
one call, two only when the top-up runs. Items whose [metadata](
|
|
403
|
+
one call, two only when the top-up runs. Items whose [metadata](https://recapi.io/docs/api#item-metadata)
|
|
404
404
|
has a `name` and an http(s) `url` are left out of that request and drawn
|
|
405
405
|
from it, as in the Shopify snippet (a number `price` is in the shop's
|
|
406
406
|
currency, `woocommerce_currency`, and shown only while the visitor browses
|
|
@@ -510,7 +510,7 @@ install has neither header's effect: both are comments there.
|
|
|
510
510
|
|
|
511
511
|
### Magento
|
|
512
512
|
|
|
513
|
-
The Magento 2 module ([
|
|
513
|
+
The Magento 2 module ([guide](https://recapi.io/docs/magento)) prints
|
|
514
514
|
the SDK on every storefront page for views and add-to-carts, and sends
|
|
515
515
|
orders from the server with the PHP library. With consent, its script
|
|
516
516
|
mirrors the visitor's id and clicked recommendations into a first-party
|
|
@@ -644,7 +644,7 @@ the library as is.
|
|
|
644
644
|
|
|
645
645
|
### Showing why an item is listed
|
|
646
646
|
|
|
647
|
-
Every item carries `why`, a short [reason code](
|
|
647
|
+
Every item carries `why`, a short [reason code](https://recapi.io/docs/api#reason-codes)
|
|
648
648
|
that names no item of the visitor's history, so any page can show it. Pick
|
|
649
649
|
your own words, and show no label for a code you don't know (new ones may
|
|
650
650
|
come):
|
|
@@ -683,13 +683,13 @@ for (const item of items) {
|
|
|
683
683
|
### Client methods
|
|
684
684
|
|
|
685
685
|
- **`track(itemId, level, { recommendationId? })`**: `level` is any integer
|
|
686
|
-
0–10 of the [recommended scale](
|
|
686
|
+
0–10 of the [recommended scale](https://recapi.io/docs/api#interaction-levels) (3
|
|
687
687
|
opened, 5 strong interest, 10 the action that matters most), or one of its
|
|
688
688
|
shop names `'view'`, `'cart'` and `'purchase'` (3, 5 and 10). `'reject'`
|
|
689
689
|
(or any level -1 to -10) is an explicit "not interested": the item is
|
|
690
690
|
never recommended to this user again until a positive event on it. Use
|
|
691
691
|
it for a rejection control only, never for skips or bounces
|
|
692
|
-
([Rejections](
|
|
692
|
+
([Rejections](https://recapi.io/docs/api#rejections)). Updates the
|
|
693
693
|
local history at once and queues the event with `anon_id`, `user_id`, a
|
|
694
694
|
timestamp and a fresh `event_id` (the idempotency
|
|
695
695
|
key, reused on retries). Level 0 means an impression: it is sent but does
|
|
@@ -702,7 +702,7 @@ for (const item of items) {
|
|
|
702
702
|
- **`recommend({ count, tagsAny, tagsAll, exclude, contextItemId, placement, discovery })`**
|
|
703
703
|
resolves to `{ recommendationId, fallback, items: [{ itemId, score, slot, why, metadata }] }`.
|
|
704
704
|
`metadata` is the object you stored with the item
|
|
705
|
-
([Item metadata](
|
|
705
|
+
([Item metadata](https://recapi.io/docs/api#item-metadata): name, picture, link,
|
|
706
706
|
price…), absent when it has none, so you can render the list without a
|
|
707
707
|
lookup. `why` is the item's [reason code](#showing-why-an-item-is-listed).
|
|
708
708
|
It never retries and waits at most 1.5 s (less if `timeoutMs` is lower):
|
|
@@ -747,7 +747,7 @@ const [similar, more] = await recapi.recommendLists({
|
|
|
747
747
|
});
|
|
748
748
|
```
|
|
749
749
|
|
|
750
|
-
### Errors
|
|
750
|
+
### Errors and troubleshooting
|
|
751
751
|
|
|
752
752
|
Every failure is a `RecapiError` with `code`, `status` and `message`. The
|
|
753
753
|
API error body supplies these when present. Client-side codes are
|
|
@@ -758,6 +758,10 @@ transient failures apart. `recommend()` and `popular()` resolve with a
|
|
|
758
758
|
list instead of rejecting on `network`, `timeout`, 5xx, 429, 401 and 403
|
|
759
759
|
errors, and report the error to `onError` (see [Fallback](#fallback)).
|
|
760
760
|
|
|
761
|
+
Each error code, its cause and its fix: [Errors](https://recapi.io/docs/errors).
|
|
762
|
+
No lists yet, empty lists, only popular items, key errors: [Troubleshooting](https://recapi.io/docs/troubleshooting).
|
|
763
|
+
Shops: the [Shopify](https://recapi.io/docs/shopify), [WooCommerce](https://recapi.io/docs/woocommerce) and [Magento](https://recapi.io/docs/magento) guides.
|
|
764
|
+
|
|
761
765
|
### Fallback
|
|
762
766
|
|
|
763
767
|
When recapi does not answer `recommend()` within 1.5 s, cannot be
|
|
@@ -803,8 +807,8 @@ untouched. An empty or `null` `contextItemId` just means none.
|
|
|
803
807
|
|
|
804
808
|
### History
|
|
805
809
|
|
|
806
|
-
The history follows
|
|
807
|
-
|
|
810
|
+
The history follows the history spec all recapi libraries share, and its
|
|
811
|
+
test vectors check it.
|
|
808
812
|
Each item has a score that decays with a 7-day half-life. The SDK keeps
|
|
809
813
|
the 50 heaviest items plus an ordered list of the 20 most recent distinct
|
|
810
814
|
items. Requests carry `history: [[item_id, weight, age_s], …]` and
|
|
@@ -1044,6 +1048,9 @@ minifier, to keep zero dev dependencies.
|
|
|
1044
1048
|
|
|
1045
1049
|
## Changes
|
|
1046
1050
|
|
|
1051
|
+
- 2026-11-19: version 0.11.1. No code change: this page's links lead to
|
|
1052
|
+
the public docs, and an errors section names the errors and
|
|
1053
|
+
troubleshooting pages.
|
|
1047
1054
|
- 2026-11-19: version 0.11.0. The Shopify snippet's product pages get a
|
|
1048
1055
|
second row, bought together, in the same call (`boughtTogether` turns it
|
|
1049
1056
|
off or retitles it), and a refused top-up keeps the cards already drawn.
|
|
@@ -1147,7 +1154,7 @@ minifier, to keep zero dev dependencies.
|
|
|
1147
1154
|
|
|
1148
1155
|
```sh
|
|
1149
1156
|
npm test # node --test, zero dev dependencies
|
|
1150
|
-
|
|
1157
|
+
"$(git rev-parse --show-toplevel)/scripts/node18.sh" --test test/*.test.js # the same on Node 18, the floor
|
|
1151
1158
|
```
|
|
1152
1159
|
|
|
1153
1160
|
`make test` and CI run the tests on Node 18 as well as the current Node,
|
|
@@ -1157,7 +1164,7 @@ means changing `engines`, this README's first lines and
|
|
|
1157
1164
|
`docs/development.md` together.
|
|
1158
1165
|
|
|
1159
1166
|
The same steps in real browsers (Chromium, Firefox, WebKit): see
|
|
1160
|
-
|
|
1167
|
+
"Testing" in the repository's development guide.
|
|
1161
1168
|
|
|
1162
1169
|
The API embeds `src/*.js` (module `recapi/sdkjs`, `embed.go`) and serves
|
|
1163
1170
|
them at `/sdk/<version>/`, where browsers cache every file but `index.js` for
|
|
@@ -1168,7 +1175,7 @@ each file's exports), and change the `/sdk/<version>/` paths in this
|
|
|
1168
1175
|
README and `docs/api.md` (the quick start follows by itself). Never edit
|
|
1169
1176
|
an existing entry of `published.json`.
|
|
1170
1177
|
Once production runs that version, the release service has GitHub publish
|
|
1171
|
-
it to npm as `@recapi/client
|
|
1178
|
+
it to npm as `@recapi/client`:
|
|
1172
1179
|
nobody runs `npm publish` by hand.
|
|
1173
1180
|
|
|
1174
1181
|
Every older path, whatever its version number, redirects to the new
|
package/package.json
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@recapi/client",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.1",
|
|
4
4
|
"description": "Browser and Node client for the recapi recommendation API: local decayed history, event batching, attribution.",
|
|
5
|
+
"homepage": "https://recapi.io/docs",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://recapi.io/contact"
|
|
8
|
+
},
|
|
5
9
|
"type": "module",
|
|
6
10
|
"main": "./src/index.js",
|
|
7
11
|
"types": "./index.d.ts",
|