sizebay-core-sdk 1.4.1 → 1.5.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 +278 -339
- package/dist/modules/ai-image-service.d.ts +3 -1
- package/dist/sizebay-core-sdk.es.js +39 -16
- package/dist/sizebay-core-sdk.umd.js +1 -1
- package/dist/types/ai-image-service.types.d.ts +41 -1
- package/dist/types/clothType.type.d.ts +7 -0
- package/dist/types/index.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,133 +1,96 @@
|
|
|
1
1
|
# Sizebay Core SDK
|
|
2
2
|
|
|
3
|
-
A
|
|
3
|
+
A modular SDK for integrating Sizebay services into your application. Features environment-based endpoint management, async/await support, built-in retry logic, and full TypeScript definitions.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
* Event tracking
|
|
6
|
+
* AI image recommendations (similar / complementary / sizing)
|
|
7
|
+
* Session & profile management
|
|
8
|
+
* Environment-aware endpoints (`-dev` / `-prod`)
|
|
9
|
+
* Full TypeScript typings
|
|
6
10
|
|
|
7
|
-
|
|
11
|
+
---
|
|
8
12
|
|
|
9
|
-
|
|
10
|
-
npm install sizebay-core-sdk
|
|
11
|
-
```
|
|
13
|
+
## Table of Contents
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
1. [Installation](#installation)
|
|
16
|
+
2. [Quick Start](#quick-start)
|
|
17
|
+
3. [Tracker Module](#tracker-module)
|
|
18
|
+
4. [AI Image Service Module](#ai-image-service-module)
|
|
19
|
+
5. [Image Search Services](#image-search-services)
|
|
20
|
+
6. [Session Module](#session-module)
|
|
21
|
+
7. [DTO Reference](#dto-reference)
|
|
14
22
|
|
|
15
|
-
|
|
23
|
+
---
|
|
16
24
|
|
|
17
|
-
|
|
25
|
+
## Installation
|
|
18
26
|
|
|
19
|
-
|
|
27
|
+
Install via npm:
|
|
20
28
|
|
|
21
|
-
|
|
29
|
+
```bash
|
|
30
|
+
npm install sizebay-core-sdk
|
|
31
|
+
```
|
|
22
32
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## Quick Start
|
|
26
36
|
|
|
27
|
-
|
|
37
|
+
### Create a client
|
|
28
38
|
|
|
29
39
|
```typescript
|
|
30
40
|
import { createClient } from 'sizebay-core-sdk';
|
|
31
41
|
|
|
32
|
-
const client = createClient({
|
|
33
|
-
|
|
34
|
-
});
|
|
42
|
+
const client = createClient({ env: 'development' });
|
|
43
|
+
// env: 'development' | 'production' (default: 'development')
|
|
35
44
|
```
|
|
36
45
|
|
|
37
46
|
---
|
|
38
47
|
|
|
39
48
|
## Tracker Module
|
|
40
49
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
Sends an event to the designated API endpoint, returning a standardized response.
|
|
44
|
-
|
|
45
|
-
**Parameters**
|
|
46
|
-
|
|
47
|
-
| Parameter | Type | Required | Description |
|
|
48
|
-
| ----------- | ----------- | -------- | ------------------------------------------------------------------------ |
|
|
49
|
-
| `eventName` | `string` | Yes | The name of the event (e.g., "ADD_TO_CART", "ORDER"). |
|
|
50
|
-
| `payload` | `TrackData` | Yes | An object containing event data. See the structure of `TrackData` below. |
|
|
51
|
-
|
|
52
|
-
**TrackData Structure**
|
|
53
|
-
|
|
54
|
-
| Property | Type | Required | Description |
|
|
55
|
-
| -------------- | --------------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------- |
|
|
56
|
-
| **sid** | `string` | Yes | Unique user identifier. |
|
|
57
|
-
| **tenantId** | `number` | Yes | Identifier of the tenant (client) sending the event. |
|
|
58
|
-
| **properties** | `Record<string, JSONValue>` | Yes | Object containing additional properties as key-value pairs. |
|
|
59
|
-
| **permalink** | `string` (optional) | No | Product URL associated with the event. When the event is linked to product (e.g., ADD_TO_CART RECOMMENDATION_DONE), it is required. |
|
|
60
|
-
|
|
61
|
-
**Returns**
|
|
62
|
-
|
|
63
|
-
- **201** – Event successfully created.
|
|
64
|
-
```json
|
|
65
|
-
{
|
|
66
|
-
"statusCode": 201,
|
|
67
|
-
"message": "Event successfully created."
|
|
68
|
-
}
|
|
69
|
-
```
|
|
70
|
-
- **400** – Invalid or missing fields.
|
|
71
|
-
```json
|
|
72
|
-
{
|
|
73
|
-
"statusCode": 400,
|
|
74
|
-
"error": "Bad Request",
|
|
75
|
-
"message": ["tenantId must be an integer number"]
|
|
76
|
-
}
|
|
77
|
-
```
|
|
78
|
-
- **500** – Internal server error.
|
|
79
|
-
```json
|
|
80
|
-
{
|
|
81
|
-
"statusCode": 500,
|
|
82
|
-
"error": "Internal server error",
|
|
83
|
-
"message": ["Unexpected error on server side"]
|
|
84
|
-
}
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
**Example**
|
|
50
|
+
### `track(eventName: string, payload: TrackData): Promise<TrackResponse>`
|
|
88
51
|
|
|
89
|
-
|
|
90
|
-
const eventPayload: TrackData = {
|
|
91
|
-
sid: 'A098AFD9F57SG54GD2H21341NK0',
|
|
92
|
-
tenantId: 123,
|
|
93
|
-
permalink: 'https://www.example.com/2IC-7370',
|
|
94
|
-
properties: {
|
|
95
|
-
quantity: 1,
|
|
96
|
-
device: 'APP',
|
|
97
|
-
country: 'BR',
|
|
98
|
-
},
|
|
99
|
-
};
|
|
52
|
+
Send an event to the API.
|
|
100
53
|
|
|
101
|
-
|
|
102
|
-
try {
|
|
103
|
-
const response = await client.track('ADD_TO_CART', eventPayload);
|
|
104
|
-
|
|
105
|
-
if (response.statusCode === 201) {
|
|
106
|
-
console.log('Event tracked successfully:', response.message);
|
|
107
|
-
} else {
|
|
108
|
-
console.error(
|
|
109
|
-
`Error tracking event (${response.statusCode}):`,
|
|
110
|
-
response.error,
|
|
111
|
-
response.message,
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
} catch (error: any) {
|
|
115
|
-
console.error('Unexpected error tracking event:', error.message);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
54
|
+
#### Parameters
|
|
118
55
|
|
|
119
|
-
|
|
120
|
-
|
|
56
|
+
| Parameter | Type | Required | Description |
|
|
57
|
+
| ----------- | ----------- | :------: | ------------------------------- |
|
|
58
|
+
| `eventName` | string | Yes | e.g. `"ADD_TO_CART"`, `"ORDER"` |
|
|
59
|
+
| `payload` | `TrackData` | Yes | See structure below |
|
|
121
60
|
|
|
122
|
-
|
|
61
|
+
#### `TrackData`
|
|
123
62
|
|
|
124
|
-
|
|
63
|
+
| Field | Type | Required | Description |
|
|
64
|
+
| ------------ | --------------------------- | :------: | ------------------------------------------------------------------ |
|
|
65
|
+
| `sid` | string | Yes | String user ID (`catalogUser.id`) |
|
|
66
|
+
| `tenantId` | number | Yes | Tenant (client) ID |
|
|
67
|
+
| `sessionId` | number | No | Numeric session ID |
|
|
68
|
+
| `permalink` | string | Cond.\* | Required for product-related events (e.g. `"RECOMMENDATION_DONE"`) |
|
|
69
|
+
| `properties` | `Record<string, JSONValue>` | Yes | Additional event data |
|
|
125
70
|
|
|
126
|
-
|
|
71
|
+
\*Condition: enforced by SDK when needed.
|
|
72
|
+
|
|
73
|
+
#### Returns
|
|
127
74
|
|
|
128
|
-
|
|
75
|
+
> **Returns:** `TrackResponse`
|
|
76
|
+
>
|
|
77
|
+
> * `statusCode`: `number`
|
|
78
|
+
> * `message`: `string`
|
|
129
79
|
|
|
130
|
-
|
|
80
|
+
#### Example
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
const payload = {
|
|
84
|
+
sid: 'a0cf8559-926a-4a75-b4ca-7c4c13fed69c',
|
|
85
|
+
tenantId: 123,
|
|
86
|
+
sessionId: 456,
|
|
87
|
+
permalink: 'https://www.example.com/2IC-7370',
|
|
88
|
+
properties: { quantity: 1, device: 'APP', country: 'BR' },
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const response = await client.track('ADD_TO_CART', payload);
|
|
92
|
+
console.log(response.statusCode, response.message);
|
|
93
|
+
```
|
|
131
94
|
|
|
132
95
|
---
|
|
133
96
|
|
|
@@ -135,264 +98,232 @@ Here’s a cleaned-up, fully English version with consistent terminology, correc
|
|
|
135
98
|
|
|
136
99
|
### `getSimilarProducts(params: GetSimilarProductsParams): Promise<GetSimilarProductsResponse>`
|
|
137
100
|
|
|
138
|
-
Fetch
|
|
101
|
+
Fetch products similar to a reference.
|
|
139
102
|
|
|
140
103
|
#### Parameters
|
|
141
104
|
|
|
142
|
-
|
|
|
143
|
-
| -------------------- |
|
|
144
|
-
| `tenantId` |
|
|
145
|
-
| `collectionName` |
|
|
146
|
-
| `sid` |
|
|
147
|
-
| `permalink` |
|
|
148
|
-
| `
|
|
149
|
-
| `
|
|
150
|
-
| `
|
|
151
|
-
| `filterByWhatFitsMe` |
|
|
152
|
-
| `personaHash` |
|
|
153
|
-
|
|
154
|
-
|
|
105
|
+
| Field | Type | Required | Description |
|
|
106
|
+
| -------------------- | ----------- | :------: | ----------------------------------------------- |
|
|
107
|
+
| `tenantId` | number | Yes | Tenant ID |
|
|
108
|
+
| `collectionName` | string | Yes | Embeddings collection |
|
|
109
|
+
| `sid` | string | Yes | String user ID |
|
|
110
|
+
| `permalink` | string | Yes | Reference product URL |
|
|
111
|
+
| `sizeSystem` | string | Yes | e.g. `"BR"`, `"EU"` |
|
|
112
|
+
| `page` | number | No | Page number |
|
|
113
|
+
| `perPage` | number | No | Items per page |
|
|
114
|
+
| `filterByWhatFitsMe` | boolean | No | Enable “What Fits Me” filter (default: `false`) |
|
|
115
|
+
| `personaHash` | string | Cond.\* | Required when `filterByWhatFitsMe` is `true` |
|
|
116
|
+
|
|
117
|
+
#### Returns
|
|
118
|
+
|
|
119
|
+
> **Returns:** `GetSimilarProductsResponse`
|
|
155
120
|
>
|
|
156
|
-
>
|
|
157
|
-
>
|
|
158
|
-
>
|
|
159
|
-
>
|
|
160
|
-
> - `suitableSizes?`: `SuitableSizeDto[]` — Size recommendations (only if `filterByWhatFitsMe = true`).
|
|
121
|
+
> * `data`: `ProductDto[]` — Similar items
|
|
122
|
+
> * `page`: `number` — Current page
|
|
123
|
+
> * `perPage`: `number` — Items per page
|
|
124
|
+
> * `total`: `number` — Total matched items
|
|
161
125
|
|
|
162
126
|
#### Example
|
|
163
127
|
|
|
164
128
|
```typescript
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
const params: GetSimilarProductsParams = {
|
|
129
|
+
const similarResponse = await client.getSimilarProducts({
|
|
168
130
|
tenantId: 123,
|
|
169
|
-
collectionName: '
|
|
170
|
-
sid: '
|
|
171
|
-
permalink: 'https://
|
|
131
|
+
collectionName: 'clothing',
|
|
132
|
+
sid: 'abc123',
|
|
133
|
+
permalink: 'https://domain.com/product/xyz',
|
|
134
|
+
sizeSystem: 'US',
|
|
172
135
|
page: 1,
|
|
173
|
-
perPage: 10
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
personaHash: '6b4f2e8b-0bb2-43d1-8bea-7f6d1c5d5a71',
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
async function fetchSimilar() {
|
|
180
|
-
try {
|
|
181
|
-
const response = await client.getSimilarProducts(params);
|
|
182
|
-
console.log('Products:', response.data);
|
|
183
|
-
if (response.suitableSizes) {
|
|
184
|
-
console.log('Recommended sizes:', response.suitableSizes);
|
|
185
|
-
}
|
|
186
|
-
} catch (err: any) {
|
|
187
|
-
console.error('Error:', err.message);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
fetchSimilar();
|
|
136
|
+
perPage: 10
|
|
137
|
+
});
|
|
138
|
+
console.log(similarResponse.data, similarResponse.total);
|
|
192
139
|
```
|
|
193
140
|
|
|
194
141
|
---
|
|
195
142
|
|
|
196
|
-
### `
|
|
143
|
+
### `getComplementaryProducts(params: GetComplementaryProductsParams): Promise<GetComplementaryProductsResponse>`
|
|
197
144
|
|
|
198
|
-
Retrieve
|
|
145
|
+
Retrieve pairs of complementary products.
|
|
199
146
|
|
|
200
147
|
#### Parameters
|
|
201
148
|
|
|
202
|
-
|
|
|
203
|
-
|
|
|
204
|
-
| `tenantId`
|
|
205
|
-
| `
|
|
206
|
-
| `
|
|
207
|
-
| `
|
|
149
|
+
| Field | Type | Required | Description |
|
|
150
|
+
| -------------------- | ----------- | :------: | ------------------------------ |
|
|
151
|
+
| `tenantId` | number | Yes | Tenant ID |
|
|
152
|
+
| `collectionName` | string | Yes | Embeddings collection |
|
|
153
|
+
| `sid` | string | Yes | String user ID |
|
|
154
|
+
| `permalink` | string | Yes | Reference product URL |
|
|
155
|
+
| `sizeSystem` | string | Yes | e.g. `"BR"`, `"EU"` |
|
|
156
|
+
| `limit` | number | No | Max number of pairs |
|
|
157
|
+
| `filterByWhatFitsMe` | boolean | No | Enable WFM filter |
|
|
158
|
+
| `personaHash` | string | Cond.\* | Required when WFM filter is on |
|
|
208
159
|
|
|
209
|
-
|
|
210
|
-
|
|
160
|
+
#### Returns
|
|
161
|
+
|
|
162
|
+
> **Returns:** `GetComplementaryProductsResponse`
|
|
163
|
+
>
|
|
164
|
+
> * `baseProduct`: `ProductDto`
|
|
165
|
+
> * `complementary`: `ComplementaryPairDto[]`
|
|
211
166
|
>
|
|
212
|
-
>
|
|
213
|
-
>
|
|
214
|
-
>
|
|
167
|
+
> * `first`: `ProductDto` (required)
|
|
168
|
+
> * `secondary`: `ProductDto` (optional)
|
|
169
|
+
> * `page`: `number` — Current page
|
|
170
|
+
> * `perPage`: `number` — Items per page
|
|
171
|
+
> * `total`: `number` — Total matched items
|
|
215
172
|
|
|
216
173
|
#### Example
|
|
217
174
|
|
|
218
175
|
```typescript
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
const payload: GetRecommendedSizeByProductsParams = {
|
|
176
|
+
const compResponse = await client.getComplementaryProducts({
|
|
222
177
|
tenantId: 123,
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
const recommendations = await client.getRecommendedSizeByProducts(payload);
|
|
231
|
-
recommendations.forEach(({ id, recommendedSize }) => {
|
|
232
|
-
console.log(`Product ${id}: ${recommendedSize}`);
|
|
233
|
-
});
|
|
234
|
-
} catch (err: any) {
|
|
235
|
-
console.error('Error:', err.message);
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
fetchSizes();
|
|
178
|
+
collectionName: 'clothing',
|
|
179
|
+
sid: 'abc123',
|
|
180
|
+
permalink: 'https://domain.com/product/xyz',
|
|
181
|
+
sizeSystem: 'US',
|
|
182
|
+
limit: 5
|
|
183
|
+
});
|
|
184
|
+
console.log(compResponse.baseProduct, compResponse.complementary);
|
|
240
185
|
```
|
|
241
186
|
|
|
242
187
|
---
|
|
243
188
|
|
|
244
|
-
|
|
189
|
+
## Image Search Services
|
|
245
190
|
|
|
246
|
-
|
|
191
|
+
### `searchSimilarByImage(payload: GetSimilarByImageBodyDto): Promise<GetSimilarProductsResponse>`
|
|
247
192
|
|
|
248
|
-
|
|
193
|
+
Find visually similar items from an uploaded image.
|
|
194
|
+
|
|
195
|
+
#### Payload
|
|
196
|
+
|
|
197
|
+
| Field | Type | Required | Description |
|
|
198
|
+
| -------------------- | ----------- | :------: | ----------------------------------- |
|
|
199
|
+
| `image` | string | Yes | Base-64 data URL (`data:image/...`) |
|
|
200
|
+
| `tenantId` | number | Yes | Tenant ID |
|
|
201
|
+
| `collectionName` | string | Yes | Embeddings collection |
|
|
202
|
+
| `sid` | string | Yes | String user ID |
|
|
203
|
+
| `sizeSystem` | string | Yes | Size system |
|
|
204
|
+
| `filterByWhatFitsMe` | boolean | No | Apply WFM filter |
|
|
205
|
+
| `personaHash` | string | Cond.\* | Required when WFM is on |
|
|
206
|
+
| `gender` | string | No | User gender context |
|
|
207
|
+
| `style` | string | No | Preferred style |
|
|
208
|
+
| `color` | string | No | Main color hint |
|
|
209
|
+
| `category` | string | No | High-level category |
|
|
210
|
+
| `page` | number | No | Page number |
|
|
211
|
+
| `perPage` | number | No | Items per page |
|
|
249
212
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
| `collectionName` | `string` | **Yes** | Qdrant collection name for embeddings. |
|
|
254
|
-
| `sid` | `string` | **Yes** | Session ID for event tracking. |
|
|
255
|
-
| `permalink` | `string` | **Yes** | Permanent link (URL) of the base product. |
|
|
256
|
-
| `limit` | `number` | No | Maximum number of complementary pairs. |
|
|
257
|
-
| `sizeSystem` | `string` | **Yes** | Size system code (e.g., `'BR'`, `'US'`, `'EU'`). |
|
|
258
|
-
| `filterByWhatFitsMe` | `boolean` | No | If `true`, apply “What Fits Me” size filter. Defaults to `false`. |
|
|
259
|
-
| `personaHash` | `string` | Cond.\* | Persona hash from Size & Fit; **required** when `filterByWhatFitsMe = true`. |
|
|
260
|
-
|
|
261
|
-
> **Returns:** `Promise<GetComplementaryProductsResponse>`
|
|
213
|
+
#### Returns
|
|
214
|
+
|
|
215
|
+
> **Returns:** `GetSimilarProductsResponse`
|
|
262
216
|
>
|
|
263
|
-
>
|
|
264
|
-
>
|
|
265
|
-
>
|
|
217
|
+
> * `data`: `ProductDto[]`
|
|
218
|
+
> * `page`: `number`
|
|
219
|
+
> * `perPage`: `number`
|
|
220
|
+
> * `total`: `number`
|
|
266
221
|
|
|
267
222
|
#### Example
|
|
268
223
|
|
|
269
224
|
```typescript
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
sizeSystem: 'BR',
|
|
279
|
-
filterByWhatFitsMe: true,
|
|
280
|
-
personaHash: '6b4f2e8b-0bb2-43d1-8bea-7f6d1c5d5a71',
|
|
281
|
-
};
|
|
282
|
-
|
|
283
|
-
async function fetchPairs() {
|
|
284
|
-
try {
|
|
285
|
-
const response = await client.getComplementaryProducts(params);
|
|
286
|
-
console.log('Base:', response.baseProduct);
|
|
287
|
-
response.complementary.forEach(({ first, secondary }) => {
|
|
288
|
-
console.log(`${first.title} ↔ ${secondary.title}`);
|
|
289
|
-
});
|
|
290
|
-
if (response.suitableSizes) {
|
|
291
|
-
console.log('Size recommendations:', response.suitableSizes);
|
|
292
|
-
}
|
|
293
|
-
} catch (err: any) {
|
|
294
|
-
console.error('Error:', err.message);
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
fetchPairs();
|
|
225
|
+
const imgSimilar = await client.searchSimilarByImage({
|
|
226
|
+
image: 'data:image/png;base64,...',
|
|
227
|
+
tenantId: 123,
|
|
228
|
+
collectionName: 'clothing',
|
|
229
|
+
sid: 'abc123',
|
|
230
|
+
sizeSystem: 'US'
|
|
231
|
+
});
|
|
232
|
+
console.log(imgSimilar.data);
|
|
299
233
|
```
|
|
300
234
|
|
|
301
235
|
---
|
|
302
236
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
### `Product` / `ProductDto`
|
|
306
|
-
|
|
307
|
-
| Field | Type | Description |
|
|
308
|
-
| ---------------------- | ------------------- | ------------------------------------------- |
|
|
309
|
-
| `id` | `string` | Unique product identifier. |
|
|
310
|
-
| `title` | `string` | Product title. |
|
|
311
|
-
| `productType` | `string` | Product category/type. |
|
|
312
|
-
| `link` | `string` | Product page URL. |
|
|
313
|
-
| `imageLink` | `string` | Main image URL. |
|
|
314
|
-
| `gender` | `string` | Gender segment (`"male"`, `"female"`, etc). |
|
|
315
|
-
| `availability` | `string` | Stock status (e.g., `"in stock"`). |
|
|
316
|
-
| `productHash` | `string` | Hash for deduplication. |
|
|
317
|
-
| `price` | `string` | Formatted price (e.g., `"29.99 USD"`). |
|
|
318
|
-
| `salePrice?` | `string` | Promotional price, if applicable. |
|
|
319
|
-
| `itemGroupId` | `string` | Variant group ID. |
|
|
320
|
-
| `brand` | `string` | Brand name. |
|
|
321
|
-
| `color` | `string` | Color description. |
|
|
322
|
-
| `gtin` | `string` | Global Trade Item Number. |
|
|
323
|
-
| `additionalImageLinks` | `string[]` | Other image URLs. |
|
|
324
|
-
| `suitableSizes?` | `SuitableSizeDto[]` | Size recommendations (when filtering). |
|
|
237
|
+
### `searchComplementaryByImage(payload: GetComplementaryByImageBodyDto): Promise<GetComplementaryProductsByImageResponse>`
|
|
325
238
|
|
|
326
|
-
|
|
239
|
+
Get products that complete a look from an image.
|
|
327
240
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
|
331
|
-
|
|
|
332
|
-
| `
|
|
241
|
+
#### Payload
|
|
242
|
+
|
|
243
|
+
| Field | Type | Required | Description |
|
|
244
|
+
| -------------------- | ------------------------------------------- | :------: | ----------------------- |
|
|
245
|
+
| `image` | string | Yes | Base-64 data URL |
|
|
246
|
+
| `tenantId` | number | Yes | Tenant ID |
|
|
247
|
+
| `collectionName` | string | Yes | Embeddings collection |
|
|
248
|
+
| `sid` | string | Yes | String user ID |
|
|
249
|
+
| `sizeSystem` | string | Yes | Size system |
|
|
250
|
+
| `productClass` | `"top" \| "bottom" \| "shoe" \| "fullbody"` | Yes | Base item class |
|
|
251
|
+
| `filterByWhatFitsMe` | boolean | No | Apply WFM filter |
|
|
252
|
+
| `personaHash` | string | Cond.\* | Required when WFM is on |
|
|
253
|
+
| `gender` | string | No | User gender context |
|
|
254
|
+
| `style` | string | No | Preferred style |
|
|
255
|
+
| `color` | string | No | Main color hint |
|
|
256
|
+
| `page` | number | No | Page number |
|
|
257
|
+
| `perPage` | number | No | Items per page |
|
|
258
|
+
|
|
259
|
+
#### Returns
|
|
260
|
+
|
|
261
|
+
> **Returns:** `GetComplementaryProductsByImageResponse`
|
|
262
|
+
>
|
|
263
|
+
> * `baseProduct`: `ProductDto`
|
|
264
|
+
> * `complementary`: `ProductDto[]`
|
|
265
|
+
> * `page`: `number`
|
|
266
|
+
> * `perPage`: `number`
|
|
267
|
+
> * `total`: `number`
|
|
268
|
+
|
|
269
|
+
#### Example
|
|
270
|
+
|
|
271
|
+
```typescript
|
|
272
|
+
const imgComp = await client.searchComplementaryByImage({
|
|
273
|
+
image: 'data:image/png;base64,...',
|
|
274
|
+
tenantId: 123,
|
|
275
|
+
collectionName: 'clothing',
|
|
276
|
+
sid: 'abc123',
|
|
277
|
+
sizeSystem: 'US',
|
|
278
|
+
productClass: 'top'
|
|
279
|
+
});
|
|
280
|
+
console.log(imgComp.complementary);
|
|
281
|
+
```
|
|
333
282
|
|
|
334
283
|
---
|
|
335
284
|
|
|
336
285
|
## Session Module
|
|
337
286
|
|
|
338
|
-
|
|
287
|
+
Retrieves and caches session context:
|
|
339
288
|
|
|
340
|
-
|
|
289
|
+
* **sid** (`string`): Catalog user ID returned by session endpoint
|
|
290
|
+
* **sessionId** (`number`): Numeric session identifier
|
|
341
291
|
|
|
342
|
-
|
|
343
|
-
- `sessionId` – the numeric session identifier
|
|
292
|
+
### `getSessionInfo(): Promise<SessionContext>`
|
|
344
293
|
|
|
345
|
-
|
|
294
|
+
Fetches or reuses session context.
|
|
346
295
|
|
|
347
296
|
#### Returns
|
|
348
297
|
|
|
349
|
-
|
|
298
|
+
```ts
|
|
299
|
+
interface SessionContext {
|
|
300
|
+
sid: string;
|
|
301
|
+
sessionId: number;
|
|
302
|
+
}
|
|
303
|
+
```
|
|
350
304
|
|
|
351
305
|
#### Example
|
|
352
306
|
|
|
353
307
|
```typescript
|
|
354
308
|
const { sid, sessionId } = await client.getSessionInfo();
|
|
355
|
-
console.log('
|
|
356
|
-
console.log('Numeric sessionId:', sessionId);
|
|
309
|
+
console.log('SID:', sid, 'sessionId:', sessionId);
|
|
357
310
|
```
|
|
358
311
|
|
|
359
|
-
---
|
|
360
|
-
|
|
361
312
|
### `sendProfile(payload: SessionProfilePayload, sid?: string): Promise<void>`
|
|
362
313
|
|
|
363
|
-
Sends
|
|
314
|
+
Sends user profile data. Uses cached `sid` if not provided.
|
|
364
315
|
|
|
365
316
|
#### Parameters
|
|
366
317
|
|
|
367
|
-
|
|
|
368
|
-
| --------- |
|
|
369
|
-
| `payload` |
|
|
370
|
-
| `sid` |
|
|
371
|
-
|
|
372
|
-
#### `SessionProfilePayload` Structure
|
|
373
|
-
|
|
374
|
-
| Field | Type | Required | Description |
|
|
375
|
-
| ---------------- | ----------------------------------------------------- | -------- | ------------------------------------------ |
|
|
376
|
-
| `userId` | `string` | Yes | The user’s unique ID |
|
|
377
|
-
| `name` | `string` | Yes | The profile name |
|
|
378
|
-
| `skinType` | `number` | Yes | Skin type category |
|
|
379
|
-
| `footShape` | `string \| null` | No | Optional foot shape |
|
|
380
|
-
| `gender` | `string` | Yes | User’s gender (`'M'` or `'F'`) |
|
|
381
|
-
| `age` | `string` | Yes | User’s age as a string |
|
|
382
|
-
| `is3dFeel` | `boolean` | Yes | Whether 3D feel is enabled |
|
|
383
|
-
| `weight` | `string` | Yes | User’s weight in string format |
|
|
384
|
-
| `height` | `string` | Yes | User’s height in string format |
|
|
385
|
-
| `measures` | `{ insoleLength: number; poundWeight: number\|null }` | Yes | Additional measurements |
|
|
386
|
-
| `product` | `string \| null` | No | Optional product context |
|
|
387
|
-
| `isMetric` | `boolean` | Yes | Whether measurements use the metric system |
|
|
388
|
-
| `bodyShapeChest` | `number` | Yes | Chest shape index |
|
|
389
|
-
| `bodyShapeWaist` | `number` | Yes | Waist shape index |
|
|
390
|
-
| `bodyShapeHip` | `number` | Yes | Hip shape index |
|
|
318
|
+
| Field | Type | Required | Description |
|
|
319
|
+
| --------- | --------------------- | :------: | ------------------------------------ |
|
|
320
|
+
| `payload` | SessionProfilePayload | Yes | Profile details |
|
|
321
|
+
| `sid` | string | No | Catalog user ID (defaults to cached) |
|
|
391
322
|
|
|
392
323
|
#### Example
|
|
393
324
|
|
|
394
325
|
```typescript
|
|
395
|
-
const
|
|
326
|
+
const profilePayload: SessionProfilePayload = {
|
|
396
327
|
userId: 'abc123',
|
|
397
328
|
name: 'szb-profile-no-name',
|
|
398
329
|
skinType: 0,
|
|
@@ -410,66 +341,74 @@ const profile: SessionProfilePayload = {
|
|
|
410
341
|
bodyShapeHip: 0,
|
|
411
342
|
};
|
|
412
343
|
|
|
413
|
-
await client.sendProfile(
|
|
344
|
+
await client.sendProfile(profilePayload);
|
|
414
345
|
```
|
|
415
346
|
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
```tsx
|
|
419
|
-
import { useMemo, useState } from 'react';
|
|
420
|
-
import { createClient } from 'sizebay-core-sdk';
|
|
421
|
-
|
|
422
|
-
export function MyComponent() {
|
|
423
|
-
// client is only created once on mount
|
|
424
|
-
const client = useMemo(() => createClient({ env: 'development' }), []);
|
|
425
|
-
|
|
426
|
-
const [profileStatus, setProfileStatus] = useState<string | null>(null);
|
|
427
|
-
|
|
428
|
-
const handleGetSessionInfo = async () => {
|
|
429
|
-
const { sid } = await client.getSessionInfo();
|
|
430
|
-
// …use sid…
|
|
431
|
-
};
|
|
347
|
+
---
|
|
432
348
|
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
349
|
+
## DTO Reference
|
|
350
|
+
|
|
351
|
+
### `ProductDto`
|
|
352
|
+
|
|
353
|
+
| Field | Type | Description |
|
|
354
|
+
| ---------------------- | ------------------- | ----------------------------------------- |
|
|
355
|
+
| `id` | `string` | Unique product ID |
|
|
356
|
+
| `itemGroupId` | `string` | Variant group ID |
|
|
357
|
+
| **URLs** | | |
|
|
358
|
+
| `link` | `string` | Product page URL |
|
|
359
|
+
| `imageLink` | `string` | Main image URL |
|
|
360
|
+
| `additionalImageLinks` | `string[]` | Extra image URLs |
|
|
361
|
+
| **Details** | | |
|
|
362
|
+
| `title` | `string` | Product title |
|
|
363
|
+
| `productType` | `string` | Category/type |
|
|
364
|
+
| `gender` | `string` | Gender target |
|
|
365
|
+
| `availability` | `string` | Stock status |
|
|
366
|
+
| `price` | `string` | Price string |
|
|
367
|
+
| `salePrice?` | `string` | Sale price (optional) |
|
|
368
|
+
| `brand` | `string` | Brand name |
|
|
369
|
+
| `color` | `string` | Color description |
|
|
370
|
+
| `style` | `string` | Style description |
|
|
371
|
+
| `category` | `string` | High-level category |
|
|
372
|
+
| `gtin` | `string` | GTIN / barcode |
|
|
373
|
+
| `productHash` | `string` | Hash for de-duplication |
|
|
374
|
+
| **Sizing (WFM)** | | |
|
|
375
|
+
| `suitableSizes?` | `SuitableSizeDto[]` | Only when the “What Fits Me” filter is on |
|
|
437
376
|
|
|
438
|
-
|
|
439
|
-
}
|
|
440
|
-
```
|
|
377
|
+
### `SuitableSizeDto`
|
|
441
378
|
|
|
442
|
-
|
|
379
|
+
| Field | Type | Description |
|
|
380
|
+
| ------------- | ------ | ------------------------- |
|
|
381
|
+
| `size` | string | Recommended size label |
|
|
382
|
+
| `comfortable` | number | Comfort score (0–1) |
|
|
383
|
+
| `value?` | boolean| if is suitable |
|
|
443
384
|
|
|
444
|
-
|
|
385
|
+
### `ComplementaryPairDto`
|
|
445
386
|
|
|
446
387
|
```ts
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
let _client: ClientType | null = null;
|
|
452
|
-
export function getClient(): ClientType {
|
|
453
|
-
if (!_client) {
|
|
454
|
-
_client = createClient({ env: 'development' });
|
|
455
|
-
}
|
|
456
|
-
return _client;
|
|
388
|
+
interface ComplementaryPairDto {
|
|
389
|
+
first: ProductDto;
|
|
390
|
+
secondary?: ProductDto;
|
|
457
391
|
}
|
|
458
|
-
|
|
459
|
-
// anywhere in your app
|
|
460
|
-
import { getClient } from './sdk';
|
|
461
|
-
const client = getClient();
|
|
462
|
-
await client.getSessionInfo();
|
|
463
|
-
await client.sendProfile(profilePayload);
|
|
464
392
|
```
|
|
465
393
|
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
394
|
+
### `SessionProfilePayload`
|
|
395
|
+
|
|
396
|
+
| Field | Type | Required | Description |
|
|
397
|
+
| ---------------- | ----------------------------------------------------- | :------: | ------------------------ |
|
|
398
|
+
| `userId` | string | Yes | User’s unique ID |
|
|
399
|
+
| `name` | string | Yes | Profile name |
|
|
400
|
+
| `skinType` | number | Yes | Skin type category |
|
|
401
|
+
| `footShape` | string \| null | No | Optional foot shape |
|
|
402
|
+
| `gender` | string | Yes | `'M'` or `'F'` |
|
|
403
|
+
| `age` | string | Yes | Age as string |
|
|
404
|
+
| `is3dFeel` | boolean | Yes | 3D feel enabled |
|
|
405
|
+
| `weight` | string | Yes | Weight as string |
|
|
406
|
+
| `height` | string | Yes | Height as string |
|
|
407
|
+
| `measures` | `{ insoleLength: number; poundWeight: number\|null }` | Yes | Additional measurements |
|
|
408
|
+
| `product` | string \| null | No | Optional product context |
|
|
409
|
+
| `isMetric` | boolean | Yes | Metric system enabled |
|
|
410
|
+
| `bodyShapeChest` | number | Yes | Chest shape index |
|
|
411
|
+
| `bodyShapeWaist` | number | Yes | Waist shape index |
|
|
412
|
+
| `bodyShapeHip` | number | Yes | Hip shape index |
|
|
469
413
|
|
|
470
|
-
|
|
471
|
-
await client.sendProfile(
|
|
472
|
-
profilePayload,
|
|
473
|
-
'028BC4AF5791a68fbbf8c48b4300a6a3319165552a9d',
|
|
474
|
-
);
|
|
475
|
-
```
|
|
414
|
+
---
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Config } from '../config';
|
|
2
|
-
import { GetComplementaryProductsParams, GetComplementaryProductsResponse, GetRecommendedSizeByProductsParams, GetRecommendedSizeByProductsResponse, GetSimilarProductsParams, GetSimilarProductsResponse } from '../types/ai-image-service.types';
|
|
2
|
+
import { GetComplementaryByImageBodyDto, GetComplementaryProductsByImageResponse, GetComplementaryProductsParams, GetComplementaryProductsResponse, GetRecommendedSizeByProductsParams, GetRecommendedSizeByProductsResponse, GetSimilarByImageBodyDto, GetSimilarProductsParams, GetSimilarProductsResponse } from '../types/ai-image-service.types';
|
|
3
3
|
export declare class AIImageService {
|
|
4
4
|
private endpoint;
|
|
5
5
|
constructor(config: Config);
|
|
@@ -7,4 +7,6 @@ export declare class AIImageService {
|
|
|
7
7
|
getSimilarProducts(params: GetSimilarProductsParams): Promise<GetSimilarProductsResponse>;
|
|
8
8
|
getRecommendedSizeByProducts(payload: GetRecommendedSizeByProductsParams): Promise<GetRecommendedSizeByProductsResponse[]>;
|
|
9
9
|
getComplementaryProducts(params: GetComplementaryProductsParams): Promise<GetComplementaryProductsResponse>;
|
|
10
|
+
searchSimilarByImage(payload: GetSimilarByImageBodyDto): Promise<GetSimilarProductsResponse>;
|
|
11
|
+
searchComplementaryByImage(payload: GetComplementaryByImageBodyDto): Promise<GetComplementaryProductsByImageResponse>;
|
|
10
12
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const d = {
|
|
2
2
|
tracker: {
|
|
3
3
|
production: "https://data-event-service.internalsizebay.com",
|
|
4
4
|
development: "https://data-event-service-dev.internalsizebay.com"
|
|
@@ -17,9 +17,9 @@ class l {
|
|
|
17
17
|
constructor(t) {
|
|
18
18
|
const e = t.env || "development";
|
|
19
19
|
this.serviceOverrides = t.services || {}, this.endpoints = {};
|
|
20
|
-
for (const s in
|
|
21
|
-
if (Object.prototype.hasOwnProperty.call(
|
|
22
|
-
const o =
|
|
20
|
+
for (const s in d)
|
|
21
|
+
if (Object.prototype.hasOwnProperty.call(d, s)) {
|
|
22
|
+
const o = d[s][e];
|
|
23
23
|
if (!o)
|
|
24
24
|
continue;
|
|
25
25
|
this.endpoints[s] = o;
|
|
@@ -62,7 +62,7 @@ class u {
|
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
|
-
class
|
|
65
|
+
class c extends Error {
|
|
66
66
|
constructor(t, e) {
|
|
67
67
|
let s;
|
|
68
68
|
try {
|
|
@@ -71,22 +71,22 @@ class a extends Error {
|
|
|
71
71
|
} catch {
|
|
72
72
|
s = e;
|
|
73
73
|
}
|
|
74
|
-
super(s), this.statusCode = t, this.details = e, Object.setPrototypeOf(this,
|
|
74
|
+
super(s), this.statusCode = t, this.details = e, Object.setPrototypeOf(this, c.prototype);
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
|
-
async function
|
|
77
|
+
async function a(r, t) {
|
|
78
78
|
let e;
|
|
79
79
|
try {
|
|
80
80
|
e = await fetch(r, t);
|
|
81
81
|
} catch (n) {
|
|
82
|
-
throw new
|
|
82
|
+
throw new c(0, n.message);
|
|
83
83
|
}
|
|
84
84
|
const s = await e.text();
|
|
85
85
|
if (!e.ok)
|
|
86
|
-
throw new
|
|
86
|
+
throw new c(e.status, s);
|
|
87
87
|
return JSON.parse(s);
|
|
88
88
|
}
|
|
89
|
-
class
|
|
89
|
+
class m {
|
|
90
90
|
constructor(t) {
|
|
91
91
|
this.endpoint = t.getEndpoint("aiImageService");
|
|
92
92
|
}
|
|
@@ -118,7 +118,7 @@ class f {
|
|
|
118
118
|
*/
|
|
119
119
|
getSimilarProducts(t) {
|
|
120
120
|
const e = new URL(`${this.endpoint}/recommendations/similar`);
|
|
121
|
-
return this.appendQueryParams(e, t),
|
|
121
|
+
return this.appendQueryParams(e, t), a(e.toString(), {
|
|
122
122
|
method: "GET",
|
|
123
123
|
headers: { "Content-Type": "application/json" }
|
|
124
124
|
});
|
|
@@ -139,7 +139,7 @@ class f {
|
|
|
139
139
|
*/
|
|
140
140
|
getRecommendedSizeByProducts(t) {
|
|
141
141
|
const e = `${this.endpoint}/recommendations/size-by-products`;
|
|
142
|
-
return
|
|
142
|
+
return a(e, {
|
|
143
143
|
method: "POST",
|
|
144
144
|
headers: { "Content-Type": "application/json" },
|
|
145
145
|
body: JSON.stringify(t)
|
|
@@ -162,13 +162,29 @@ class f {
|
|
|
162
162
|
*/
|
|
163
163
|
getComplementaryProducts(t) {
|
|
164
164
|
const e = new URL(`${this.endpoint}/recommendations/complementary`);
|
|
165
|
-
return this.appendQueryParams(e, t),
|
|
165
|
+
return this.appendQueryParams(e, t), a(e.toString(), {
|
|
166
166
|
method: "GET",
|
|
167
167
|
headers: { "Content-Type": "application/json" }
|
|
168
168
|
});
|
|
169
169
|
}
|
|
170
|
+
searchSimilarByImage(t) {
|
|
171
|
+
const e = `${this.endpoint}/image-search/similar`;
|
|
172
|
+
return a(e, {
|
|
173
|
+
method: "POST",
|
|
174
|
+
headers: { "Content-Type": "application/json" },
|
|
175
|
+
body: JSON.stringify(t)
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
searchComplementaryByImage(t) {
|
|
179
|
+
const e = `${this.endpoint}/image-search/complementary`;
|
|
180
|
+
return a(e, {
|
|
181
|
+
method: "POST",
|
|
182
|
+
headers: { "Content-Type": "application/json" },
|
|
183
|
+
body: JSON.stringify(t)
|
|
184
|
+
});
|
|
185
|
+
}
|
|
170
186
|
}
|
|
171
|
-
class
|
|
187
|
+
class f {
|
|
172
188
|
constructor(t) {
|
|
173
189
|
this.sid = null, this.sessionId = null;
|
|
174
190
|
const e = t.getEndpoint("session");
|
|
@@ -226,8 +242,8 @@ class m {
|
|
|
226
242
|
}
|
|
227
243
|
const y = [
|
|
228
244
|
u,
|
|
229
|
-
|
|
230
|
-
|
|
245
|
+
m,
|
|
246
|
+
f
|
|
231
247
|
];
|
|
232
248
|
function g(r = {}) {
|
|
233
249
|
const t = new l(r), e = y.map((n) => new n(t)), s = {};
|
|
@@ -242,6 +258,13 @@ function g(r = {}) {
|
|
|
242
258
|
});
|
|
243
259
|
}), s;
|
|
244
260
|
}
|
|
261
|
+
const w = {
|
|
262
|
+
FULL_BODY: "fullbody",
|
|
263
|
+
BOTTOM: "bottom",
|
|
264
|
+
TOP: "top",
|
|
265
|
+
SHOE: "shoe"
|
|
266
|
+
};
|
|
245
267
|
export {
|
|
268
|
+
w as ClothType,
|
|
246
269
|
g as createClient
|
|
247
270
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(r,a){typeof exports=="object"&&typeof module<"u"?a(exports):typeof define=="function"&&define.amd?define(["exports"],a):(r=typeof globalThis<"u"?globalThis:r||self,a(r["sizebay-core-sdk"]={}))})(this,function(r){"use strict";const a={tracker:{production:"https://data-event-service.internalsizebay.com",development:"https://data-event-service-dev.internalsizebay.com"},aiImageService:{production:"https://ai-image-service.internalsizebay.com",development:"https://ai-image-service-dev.internalsizebay.com"},session:{production:"https://vfr-v3-production.sizebay.technology/api/me",development:"https://vfr-v3-staging.sizebay.eu/api/me"}};class l{constructor(e){const t=e.env||"development";this.serviceOverrides=e.services||{},this.endpoints={};for(const n in a)if(Object.prototype.hasOwnProperty.call(a,n)){const o=a[n][t];if(!o)continue;this.endpoints[n]=o}}getEndpoint(e){const t=this.endpoints[e];if(!t)throw new Error(`Endpoint for service '${e}' is not configured.`);return t}getServiceConfig(e){return this.serviceOverrides[e]||{}}}class u{constructor(e){this.endpoint=e.getEndpoint("tracker")}async track(e,t){const n={eventName:e,...t},s=new URL(`${this.endpoint}/events`);try{const o=await fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!o.ok){const i=await o.text();throw new Error(`Request error: ${o.status} - ${i}`)}return await o.json()}catch(o){throw o}}}class p extends Error{constructor(e,t){let n;try{const s=JSON.parse(t);n=(s==null?void 0:s.message)||t}catch{n=t}super(n),this.statusCode=e,this.details=t,Object.setPrototypeOf(this,p.prototype)}}async function d(c,e){let t;try{t=await fetch(c,e)}catch(s){throw new p(0,s.message)}const n=await t.text();if(!t.ok)throw new p(t.status,n);return JSON.parse(n)}class f{constructor(e){this.endpoint=e.getEndpoint("aiImageService")}appendQueryParams(e,t){Object.entries(t).forEach(([n,s])=>{s!=null&&e.searchParams.append(n,String(s))})}getSimilarProducts(e){const t=new URL(`${this.endpoint}/recommendations/similar`);return this.appendQueryParams(t,e),d(t.toString(),{method:"GET",headers:{"Content-Type":"application/json"}})}getRecommendedSizeByProducts(e){const t=`${this.endpoint}/recommendations/size-by-products`;return d(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}getComplementaryProducts(e){const t=new URL(`${this.endpoint}/recommendations/complementary`);return this.appendQueryParams(t,e),d(t.toString(),{method:"GET",headers:{"Content-Type":"application/json"}})}searchSimilarByImage(e){const t=`${this.endpoint}/image-search/similar`;return d(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}searchComplementaryByImage(e){const t=`${this.endpoint}/image-search/complementary`;return d(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})}}class m{constructor(e){this.sid=null,this.sessionId=null;const t=e.getEndpoint("session");this.sessionEndpoint=`${t}/`,this.profileEndpoint=`${t}/user/profile`}async getSessionInfo(){if(this.sid&&this.sessionId!==null)return{sid:this.sid,sessionId:this.sessionId};const e=await fetch(this.sessionEndpoint,{credentials:"include"});if(!e.ok){const n=await e.text();throw new Error(`Failed to fetch session info: ${e.status} – ${n}`)}const t=await e.json();return this.sid=t.catalogUser.id,this.sessionId=t.sessionId,{sid:this.sid,sessionId:this.sessionId}}async sendProfile(e,t){const n=t??(await this.getSessionInfo()).sid,s=new URL(this.profileEndpoint);s.searchParams.set("sid",n);const o=await fetch(s.toString(),{credentials:"include",method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({userId:n,id:null,...e})});if(!o.ok){const i=await o.text();throw new Error(`Failed to send profile: ${o.status} – ${i}`)}}}const y=[u,f,m];function g(c={}){const e=new l(c),t=y.map(s=>new s(e)),n={};return t.forEach(s=>{[...Object.getOwnPropertyNames(s),...Object.getOwnPropertyNames(Object.getPrototypeOf(s))].forEach(i=>{if(i==="constructor")return;const h=s[i];typeof h=="function"&&(n[i]||(n[i]=(...O)=>h.apply(s,O)))})}),n}const w={FULL_BODY:"fullbody",BOTTOM:"bottom",TOP:"top",SHOE:"shoe"};r.ClothType=w,r.createClient=g,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ClothType } from './clothType.type';
|
|
1
2
|
export interface GetSimilarProductsParams {
|
|
2
3
|
tenantId: number;
|
|
3
4
|
collectionName: string;
|
|
@@ -39,12 +40,14 @@ export interface ProductDto {
|
|
|
39
40
|
itemGroupId: string;
|
|
40
41
|
brand: string;
|
|
41
42
|
color: string;
|
|
43
|
+
style: string;
|
|
44
|
+
category: string;
|
|
42
45
|
gtin: string;
|
|
43
46
|
additionalImageLinks: string[];
|
|
44
47
|
suitableSizes?: Array<{
|
|
45
48
|
size: string;
|
|
46
49
|
comfortable: number;
|
|
47
|
-
value?:
|
|
50
|
+
value?: boolean;
|
|
48
51
|
}>;
|
|
49
52
|
}
|
|
50
53
|
export interface GetSimilarProductsResponse {
|
|
@@ -66,3 +69,40 @@ export interface GetComplementaryProductsResponse {
|
|
|
66
69
|
baseProduct: ProductDto;
|
|
67
70
|
complementary: ComplementaryPairDto[];
|
|
68
71
|
}
|
|
72
|
+
export interface GetSimilarByImageBodyDto {
|
|
73
|
+
image: string;
|
|
74
|
+
tenantId: number;
|
|
75
|
+
collectionName: string;
|
|
76
|
+
sid: string;
|
|
77
|
+
sizeSystem: string;
|
|
78
|
+
filterByWhatFitsMe?: boolean;
|
|
79
|
+
personaHash?: string;
|
|
80
|
+
gender?: string;
|
|
81
|
+
style?: string;
|
|
82
|
+
color?: string;
|
|
83
|
+
category?: string;
|
|
84
|
+
page?: number;
|
|
85
|
+
perPage?: number;
|
|
86
|
+
}
|
|
87
|
+
export interface GetComplementaryByImageBodyDto {
|
|
88
|
+
image: string;
|
|
89
|
+
tenantId: number;
|
|
90
|
+
collectionName: string;
|
|
91
|
+
sid: string;
|
|
92
|
+
sizeSystem: string;
|
|
93
|
+
clothType: ClothType;
|
|
94
|
+
filterByWhatFitsMe?: boolean;
|
|
95
|
+
personaHash?: string;
|
|
96
|
+
gender?: string;
|
|
97
|
+
style?: string;
|
|
98
|
+
color?: string;
|
|
99
|
+
page?: number;
|
|
100
|
+
perPage?: number;
|
|
101
|
+
}
|
|
102
|
+
export interface GetComplementaryProductsByImageResponse {
|
|
103
|
+
baseProduct: ProductDto;
|
|
104
|
+
complementary: ProductDto[];
|
|
105
|
+
page: number;
|
|
106
|
+
perPage: number;
|
|
107
|
+
total: number;
|
|
108
|
+
}
|
package/dist/types/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sizebay-core-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "A SDK designed for integrating multiple services (such as event tracking, AI services, etc.) into your application.",
|
|
5
5
|
"main": "dist/sizebay-core-sdk.umd.js",
|
|
6
6
|
"module": "dist/sizebay-core-sdk.es.js",
|