@likyly/sdk 0.0.0-stage → 1.1.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.
Files changed (59) hide show
  1. package/README.md +278 -2
  2. package/dist/cjs/client.d.ts +70 -0
  3. package/dist/cjs/client.js +85 -0
  4. package/dist/cjs/encoding.d.ts +11 -0
  5. package/dist/cjs/encoding.js +37 -0
  6. package/dist/cjs/errors.d.ts +52 -0
  7. package/dist/cjs/errors.js +83 -0
  8. package/dist/cjs/http.d.ts +49 -0
  9. package/dist/cjs/http.js +155 -0
  10. package/dist/cjs/index.d.ts +8 -0
  11. package/dist/cjs/index.js +20 -0
  12. package/dist/cjs/package.json +1 -0
  13. package/dist/cjs/recommend-cache.d.ts +42 -0
  14. package/dist/cjs/recommend-cache.js +114 -0
  15. package/dist/cjs/resources/events.d.ts +45 -0
  16. package/dist/cjs/resources/events.js +134 -0
  17. package/dist/cjs/resources/items.d.ts +43 -0
  18. package/dist/cjs/resources/items.js +97 -0
  19. package/dist/cjs/resources/placements.d.ts +24 -0
  20. package/dist/cjs/resources/placements.js +97 -0
  21. package/dist/cjs/resources/recommendations.d.ts +54 -0
  22. package/dist/cjs/resources/recommendations.js +130 -0
  23. package/dist/cjs/resources/users.d.ts +19 -0
  24. package/dist/cjs/resources/users.js +64 -0
  25. package/dist/cjs/session.d.ts +32 -0
  26. package/dist/cjs/session.js +76 -0
  27. package/dist/cjs/types.d.ts +226 -0
  28. package/dist/cjs/types.js +2 -0
  29. package/dist/cjs/version.d.ts +3 -0
  30. package/dist/cjs/version.js +6 -0
  31. package/dist/esm/client.d.ts +70 -0
  32. package/dist/esm/client.js +81 -0
  33. package/dist/esm/encoding.d.ts +11 -0
  34. package/dist/esm/encoding.js +31 -0
  35. package/dist/esm/errors.d.ts +52 -0
  36. package/dist/esm/errors.js +69 -0
  37. package/dist/esm/http.d.ts +49 -0
  38. package/dist/esm/http.js +149 -0
  39. package/dist/esm/index.d.ts +8 -0
  40. package/dist/esm/index.js +4 -0
  41. package/dist/esm/recommend-cache.d.ts +42 -0
  42. package/dist/esm/recommend-cache.js +110 -0
  43. package/dist/esm/resources/events.d.ts +45 -0
  44. package/dist/esm/resources/events.js +130 -0
  45. package/dist/esm/resources/items.d.ts +43 -0
  46. package/dist/esm/resources/items.js +91 -0
  47. package/dist/esm/resources/placements.d.ts +24 -0
  48. package/dist/esm/resources/placements.js +93 -0
  49. package/dist/esm/resources/recommendations.d.ts +54 -0
  50. package/dist/esm/resources/recommendations.js +124 -0
  51. package/dist/esm/resources/users.d.ts +19 -0
  52. package/dist/esm/resources/users.js +60 -0
  53. package/dist/esm/session.d.ts +32 -0
  54. package/dist/esm/session.js +72 -0
  55. package/dist/esm/types.d.ts +226 -0
  56. package/dist/esm/types.js +1 -0
  57. package/dist/esm/version.d.ts +3 -0
  58. package/dist/esm/version.js +3 -0
  59. package/package.json +40 -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 {};
@@ -0,0 +1,3 @@
1
+ export declare const SDK_VERSION = "1.1.0";
2
+ export declare const DEFAULT_BASE_URL = "https://api.likyly.com";
3
+ export declare const USER_AGENT = "likyly-typescript/1.1.0";
@@ -0,0 +1,3 @@
1
+ export const SDK_VERSION = "1.1.0";
2
+ export const DEFAULT_BASE_URL = "https://api.likyly.com";
3
+ export const USER_AGENT = `likyly-typescript/${SDK_VERSION}`;
package/package.json CHANGED
@@ -1,6 +1,42 @@
1
1
  {
2
2
  "name": "@likyly/sdk",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.1.0",
4
+ "description": "Official LIKYLY SDK for TypeScript / Node.js: items, users, events, recommendations and placements.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "sideEffects": false,
8
+ "main": "./dist/cjs/index.js",
9
+ "module": "./dist/esm/index.js",
10
+ "types": "./dist/esm/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "import": {
14
+ "types": "./dist/esm/index.d.ts",
15
+ "default": "./dist/esm/index.js"
16
+ },
17
+ "require": {
18
+ "types": "./dist/cjs/index.d.ts",
19
+ "default": "./dist/cjs/index.js"
20
+ }
21
+ },
22
+ "./package.json": "./package.json"
23
+ },
24
+ "files": [
25
+ "dist/esm",
26
+ "dist/cjs",
27
+ "README.md"
28
+ ],
29
+ "engines": {
30
+ "node": ">=18"
31
+ },
32
+ "scripts": {
33
+ "build": "rm -rf dist && tsc -p tsconfig.esm.json && tsc -p tsconfig.cjs.json && node scripts/mark-cjs.mjs",
34
+ "typecheck": "tsc -p tsconfig.test.json --noEmit",
35
+ "test": "rm -rf dist/test && tsc -p tsconfig.test.json && node --test \"dist/test/test/*.test.js\"",
36
+ "example": "npm run build && node examples/quickstart.mjs"
37
+ },
38
+ "devDependencies": {
39
+ "@types/node": "^22.0.0",
40
+ "typescript": "^5.5.4"
41
+ }
42
+ }