@likyly/sdk 0.0.0-stage → 1.1.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 +286 -2
- package/dist/cjs/client.d.ts +70 -0
- package/dist/cjs/client.js +85 -0
- package/dist/cjs/encoding.d.ts +11 -0
- package/dist/cjs/encoding.js +37 -0
- package/dist/cjs/errors.d.ts +52 -0
- package/dist/cjs/errors.js +83 -0
- package/dist/cjs/http.d.ts +49 -0
- package/dist/cjs/http.js +155 -0
- package/dist/cjs/index.d.ts +8 -0
- package/dist/cjs/index.js +20 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/recommend-cache.d.ts +42 -0
- package/dist/cjs/recommend-cache.js +114 -0
- package/dist/cjs/resources/events.d.ts +45 -0
- package/dist/cjs/resources/events.js +134 -0
- package/dist/cjs/resources/items.d.ts +43 -0
- package/dist/cjs/resources/items.js +97 -0
- package/dist/cjs/resources/placements.d.ts +24 -0
- package/dist/cjs/resources/placements.js +97 -0
- package/dist/cjs/resources/recommendations.d.ts +54 -0
- package/dist/cjs/resources/recommendations.js +130 -0
- package/dist/cjs/resources/users.d.ts +19 -0
- package/dist/cjs/resources/users.js +64 -0
- package/dist/cjs/session.d.ts +32 -0
- package/dist/cjs/session.js +76 -0
- package/dist/cjs/types.d.ts +226 -0
- package/dist/cjs/types.js +2 -0
- package/dist/cjs/version.d.ts +3 -0
- package/dist/cjs/version.js +6 -0
- package/dist/esm/client.d.ts +70 -0
- package/dist/esm/client.js +81 -0
- package/dist/esm/encoding.d.ts +11 -0
- package/dist/esm/encoding.js +31 -0
- package/dist/esm/errors.d.ts +52 -0
- package/dist/esm/errors.js +69 -0
- package/dist/esm/http.d.ts +49 -0
- package/dist/esm/http.js +149 -0
- package/dist/esm/index.d.ts +8 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/recommend-cache.d.ts +42 -0
- package/dist/esm/recommend-cache.js +110 -0
- package/dist/esm/resources/events.d.ts +45 -0
- package/dist/esm/resources/events.js +130 -0
- package/dist/esm/resources/items.d.ts +43 -0
- package/dist/esm/resources/items.js +91 -0
- package/dist/esm/resources/placements.d.ts +24 -0
- package/dist/esm/resources/placements.js +93 -0
- package/dist/esm/resources/recommendations.d.ts +54 -0
- package/dist/esm/resources/recommendations.js +124 -0
- package/dist/esm/resources/users.d.ts +19 -0
- package/dist/esm/resources/users.js +60 -0
- package/dist/esm/session.d.ts +32 -0
- package/dist/esm/session.js +72 -0
- package/dist/esm/types.d.ts +226 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/version.d.ts +3 -0
- package/dist/esm/version.js +3 -0
- package/package.json +60 -4
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/** Free-form JSON object: price, currency, orderId, category, any field of your own. Keys are stored exactly as you send them. */
|
|
2
|
+
export type Properties = Record<string, unknown>;
|
|
3
|
+
export interface Item {
|
|
4
|
+
/** Your own identifier - any string (`SKU-123`, a UUID, `gid://shopify/Product/123`). */
|
|
5
|
+
itemId: string;
|
|
6
|
+
title: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
properties: Properties;
|
|
9
|
+
}
|
|
10
|
+
/** What you send to create or replace an item. Only `title` is required. */
|
|
11
|
+
export interface ItemInput {
|
|
12
|
+
title: string;
|
|
13
|
+
description?: string;
|
|
14
|
+
/** `category` and `description` feed content similarity; everything else is stored as is. */
|
|
15
|
+
properties?: Properties;
|
|
16
|
+
}
|
|
17
|
+
export interface ItemImport extends ItemInput {
|
|
18
|
+
itemId: string;
|
|
19
|
+
}
|
|
20
|
+
export interface ListOptions {
|
|
21
|
+
/** Page size (1-1000, default 100). */
|
|
22
|
+
limit?: number;
|
|
23
|
+
/** Rows to skip. */
|
|
24
|
+
offset?: number;
|
|
25
|
+
}
|
|
26
|
+
export interface ItemList {
|
|
27
|
+
items: Item[];
|
|
28
|
+
/** Total number of items in the catalog (`X-Total-Count`), when the API reported it. */
|
|
29
|
+
total?: number;
|
|
30
|
+
/** The page size you asked for (undefined = the API's default). */
|
|
31
|
+
limit?: number;
|
|
32
|
+
offset: number;
|
|
33
|
+
}
|
|
34
|
+
export interface User {
|
|
35
|
+
userId: string;
|
|
36
|
+
properties: Properties;
|
|
37
|
+
}
|
|
38
|
+
export interface UserInput {
|
|
39
|
+
/** country, segment, language, ... - whatever describes your users. */
|
|
40
|
+
properties?: Properties;
|
|
41
|
+
}
|
|
42
|
+
export interface UserImport extends UserInput {
|
|
43
|
+
userId: string;
|
|
44
|
+
}
|
|
45
|
+
export interface UserList {
|
|
46
|
+
users: User[];
|
|
47
|
+
total?: number;
|
|
48
|
+
limit?: number;
|
|
49
|
+
offset: number;
|
|
50
|
+
}
|
|
51
|
+
/** Result of a batch call. A failing entry is reported in `errors`, it does not throw. */
|
|
52
|
+
export interface BatchResult {
|
|
53
|
+
received: number;
|
|
54
|
+
succeeded: number;
|
|
55
|
+
failed: number;
|
|
56
|
+
errors: {
|
|
57
|
+
index: number;
|
|
58
|
+
id?: string;
|
|
59
|
+
message: string;
|
|
60
|
+
}[];
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* An interaction. `itemId` and at least one of `userId` / `sessionId` are required; sending both
|
|
64
|
+
* ties an anonymous session to the user.
|
|
65
|
+
*/
|
|
66
|
+
export interface EventInput {
|
|
67
|
+
itemId: string;
|
|
68
|
+
userId?: string;
|
|
69
|
+
/** Anonymous visitor / browsing session - no login needed. */
|
|
70
|
+
sessionId?: string;
|
|
71
|
+
/** The `recommendationId` of the recommendation that surfaced this item - enables attribution. */
|
|
72
|
+
recommendationId?: string;
|
|
73
|
+
/** Free-form label of where this happened: `homepage`, `product_page`, `cart`, ... */
|
|
74
|
+
placement?: string;
|
|
75
|
+
quantity?: number;
|
|
76
|
+
/** ISO 8601 string or Date. Defaults to the server's time. */
|
|
77
|
+
occurredAt?: string | Date;
|
|
78
|
+
properties?: Properties;
|
|
79
|
+
/**
|
|
80
|
+
* Idempotency key, unique per account: replaying an event with the same `eventId` records nothing
|
|
81
|
+
* and returns `duplicate: true`. Set it on purchases - it makes retries safe.
|
|
82
|
+
*/
|
|
83
|
+
eventId?: string;
|
|
84
|
+
}
|
|
85
|
+
/** An event of any type, for `events.trackMany`. `type` is an open string (`view`, `favorite`, ...). */
|
|
86
|
+
export interface TypedEventInput extends EventInput {
|
|
87
|
+
type: string;
|
|
88
|
+
}
|
|
89
|
+
export interface EventResult {
|
|
90
|
+
message: string;
|
|
91
|
+
eventId?: string;
|
|
92
|
+
/** True if this `eventId` was already recorded - nothing was written. */
|
|
93
|
+
duplicate: boolean;
|
|
94
|
+
}
|
|
95
|
+
export interface EventBatchResult {
|
|
96
|
+
received: number;
|
|
97
|
+
accepted: number;
|
|
98
|
+
/** Events skipped because their `eventId` was already recorded. */
|
|
99
|
+
duplicates: number;
|
|
100
|
+
}
|
|
101
|
+
/** Call right after login/signup, once you know `userId`, for the `sessionId` the visitor was
|
|
102
|
+
* anonymous under - see `events.identify`. */
|
|
103
|
+
export interface IdentifyInput {
|
|
104
|
+
userId: string;
|
|
105
|
+
sessionId: string;
|
|
106
|
+
}
|
|
107
|
+
export interface IdentifyResult {
|
|
108
|
+
/** How many of this session's past interactions now belong to `userId`. */
|
|
109
|
+
linkedInteractions: number;
|
|
110
|
+
}
|
|
111
|
+
/** Send whatever you know: LIKYLY chooses the best strategy. All fields are optional. */
|
|
112
|
+
export interface RecommendationRequest {
|
|
113
|
+
userId?: string;
|
|
114
|
+
sessionId?: string;
|
|
115
|
+
/** The item being looked at (e.g. the product page). */
|
|
116
|
+
itemId?: string;
|
|
117
|
+
/** Recently viewed items, oldest first. */
|
|
118
|
+
viewedItemIds?: string[];
|
|
119
|
+
/** Free-form label of where the recommendations will be shown. */
|
|
120
|
+
placement?: string;
|
|
121
|
+
/** How many items to return (1-100, default 10). */
|
|
122
|
+
limit?: number;
|
|
123
|
+
/** Diagnostic detail in `explanation`. Secret key only. */
|
|
124
|
+
debug?: boolean;
|
|
125
|
+
}
|
|
126
|
+
export interface SimilarUser {
|
|
127
|
+
userId: string;
|
|
128
|
+
sharedItemIds: string[];
|
|
129
|
+
}
|
|
130
|
+
export interface Explanation {
|
|
131
|
+
reason: string;
|
|
132
|
+
contentSimilarity?: number;
|
|
133
|
+
semanticSimilarity?: number;
|
|
134
|
+
popularityScore?: number;
|
|
135
|
+
interactionCount?: number;
|
|
136
|
+
interactionLabel?: string;
|
|
137
|
+
collaborativeScore?: number;
|
|
138
|
+
sourceItemIds?: string[];
|
|
139
|
+
/** Only with `debug` and a secret key. */
|
|
140
|
+
similarUsers?: SimilarUser[];
|
|
141
|
+
}
|
|
142
|
+
export interface RecommendedItem {
|
|
143
|
+
itemId: string;
|
|
144
|
+
score?: number;
|
|
145
|
+
title?: string;
|
|
146
|
+
description?: string;
|
|
147
|
+
properties: Properties;
|
|
148
|
+
explanation?: Explanation;
|
|
149
|
+
}
|
|
150
|
+
export interface RecommendationResponse {
|
|
151
|
+
/** Send it back on the impression / click / add_to_cart / purchase events for these items. */
|
|
152
|
+
recommendationId: string;
|
|
153
|
+
/** What LIKYLY used: `hybrid`, `content`, `collaborative`, `session` or `popular`. */
|
|
154
|
+
strategy: string;
|
|
155
|
+
placement?: string;
|
|
156
|
+
items: RecommendedItem[];
|
|
157
|
+
}
|
|
158
|
+
interface AdvancedBase {
|
|
159
|
+
placement?: string;
|
|
160
|
+
/** Attach the recommendation to an anonymous session, for attribution. */
|
|
161
|
+
sessionId?: string;
|
|
162
|
+
/** How many items to return (default 10). */
|
|
163
|
+
limit?: number;
|
|
164
|
+
}
|
|
165
|
+
export interface PopularOptions extends AdvancedBase {
|
|
166
|
+
}
|
|
167
|
+
export interface SimilarOptions extends AdvancedBase {
|
|
168
|
+
itemId: string;
|
|
169
|
+
}
|
|
170
|
+
export interface CollaborativeOptions extends AdvancedBase {
|
|
171
|
+
userId: string;
|
|
172
|
+
}
|
|
173
|
+
export interface HybridOptions extends AdvancedBase {
|
|
174
|
+
userId: string;
|
|
175
|
+
itemId: string;
|
|
176
|
+
/** Weight of the collaborative signal against content similarity: 0 = pure content, 1 = pure collaborative (default 0.5). */
|
|
177
|
+
alpha?: number;
|
|
178
|
+
}
|
|
179
|
+
/** Give `viewedItemIds` (an explicit list, oldest first) OR `userId` (LIKYLY's own history of that user's views). */
|
|
180
|
+
export interface SessionOptions extends AdvancedBase {
|
|
181
|
+
viewedItemIds?: string[];
|
|
182
|
+
userId?: string;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* What you know about the moment - every field optional unless the placement's own
|
|
186
|
+
* `signals.required` names it (see `likyly.placements` and GET .../requirements).
|
|
187
|
+
*/
|
|
188
|
+
export interface PlacementContext {
|
|
189
|
+
/** The product/article/listing currently being viewed. */
|
|
190
|
+
itemId?: string;
|
|
191
|
+
categoryId?: string;
|
|
192
|
+
collectionId?: string;
|
|
193
|
+
/** Identified visitor. */
|
|
194
|
+
userId?: string;
|
|
195
|
+
/** Stable anonymous visitor id - used like `sessionId` when `sessionId` is omitted. See `LikylySession`. */
|
|
196
|
+
anonymousId?: string;
|
|
197
|
+
/** Anonymous browsing session. */
|
|
198
|
+
sessionId?: string;
|
|
199
|
+
cartItemIds?: string[];
|
|
200
|
+
locale?: string;
|
|
201
|
+
customContext?: Record<string, unknown>;
|
|
202
|
+
}
|
|
203
|
+
export interface PlacementRecommendOptions {
|
|
204
|
+
/** The placement's slug, e.g. "pdp-related". */
|
|
205
|
+
placement: string;
|
|
206
|
+
context?: PlacementContext;
|
|
207
|
+
/** Overrides the placement's own configured limit for this call. */
|
|
208
|
+
limit?: number;
|
|
209
|
+
}
|
|
210
|
+
export interface PlacementRecommendResponse {
|
|
211
|
+
/** Send it back on the impression / click / add_to_cart / purchase events for these items. */
|
|
212
|
+
recommendationId: string;
|
|
213
|
+
placement: string;
|
|
214
|
+
/** What the placement actually used: `hybrid`, `content`, `collaborative`, `session` or `popular`. */
|
|
215
|
+
strategyUsed: string;
|
|
216
|
+
items: RecommendedItem[];
|
|
217
|
+
}
|
|
218
|
+
export interface RequestOptions {
|
|
219
|
+
/** Cancel the call. */
|
|
220
|
+
signal?: AbortSignal;
|
|
221
|
+
/** Overrides the client's timeout (milliseconds) for this call. */
|
|
222
|
+
timeout?: number;
|
|
223
|
+
/** Overrides the client's retry count for this call. */
|
|
224
|
+
maxRetries?: number;
|
|
225
|
+
}
|
|
226
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,62 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@likyly/sdk",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.1.1",
|
|
4
|
+
"description": "Product recommendations for your site (\"You may also like\", \"Recommended for you\"), learned from what your visitors do. Official LIKYLY client for JavaScript and TypeScript: browser, Node.js, edge.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"likyly",
|
|
7
|
+
"recommendations",
|
|
8
|
+
"product recommendations",
|
|
9
|
+
"recommender",
|
|
10
|
+
"personalization",
|
|
11
|
+
"ecommerce",
|
|
12
|
+
"you may also like",
|
|
13
|
+
"typescript"
|
|
14
|
+
],
|
|
15
|
+
"homepage": "https://www.likyly.com",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/Likyly/likyly-recsys.git",
|
|
19
|
+
"directory": "sdk/js"
|
|
20
|
+
},
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/Likyly/likyly-recsys/issues"
|
|
23
|
+
},
|
|
24
|
+
"author": "LIKYLY (https://www.likyly.com)",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"type": "module",
|
|
27
|
+
"sideEffects": false,
|
|
28
|
+
"main": "./dist/cjs/index.js",
|
|
29
|
+
"module": "./dist/esm/index.js",
|
|
30
|
+
"types": "./dist/esm/index.d.ts",
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"import": {
|
|
34
|
+
"types": "./dist/esm/index.d.ts",
|
|
35
|
+
"default": "./dist/esm/index.js"
|
|
36
|
+
},
|
|
37
|
+
"require": {
|
|
38
|
+
"types": "./dist/cjs/index.d.ts",
|
|
39
|
+
"default": "./dist/cjs/index.js"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"./package.json": "./package.json"
|
|
43
|
+
},
|
|
44
|
+
"files": [
|
|
45
|
+
"dist/esm",
|
|
46
|
+
"dist/cjs",
|
|
47
|
+
"README.md"
|
|
48
|
+
],
|
|
49
|
+
"engines": {
|
|
50
|
+
"node": ">=18"
|
|
51
|
+
},
|
|
52
|
+
"scripts": {
|
|
53
|
+
"build": "rm -rf dist && tsc -p tsconfig.esm.json && tsc -p tsconfig.cjs.json && node scripts/mark-cjs.mjs",
|
|
54
|
+
"typecheck": "tsc -p tsconfig.test.json --noEmit",
|
|
55
|
+
"test": "rm -rf dist/test && tsc -p tsconfig.test.json && node --test \"dist/test/test/*.test.js\"",
|
|
56
|
+
"example": "npm run build && node examples/quickstart.mjs"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@types/node": "^22.0.0",
|
|
60
|
+
"typescript": "^5.5.4"
|
|
61
|
+
}
|
|
62
|
+
}
|