sizebay-core-sdk 1.0.1 → 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.
- package/CHANGELOG.md +6 -0
- package/README.md +58 -11
- package/dist/types/src/modules/tracker.d.ts +2 -2
- package/dist/types/src/types/event.types.d.ts +15 -0
- package/package.json +1 -1
- package/src/modules/tracker.ts +2 -2
- package/src/types/event.types.ts +25 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
## [1.1.0](https://github.com/sizebay/events-sdk/compare/v1.0.1...v1.1.0) (2025-04-01)
|
|
2
|
+
|
|
3
|
+
### Features
|
|
4
|
+
|
|
5
|
+
* **tracker:** update TrackData types and documentation ([e7187f2](https://github.com/sizebay/events-sdk/commit/e7187f2ca7b5d0ecee3404b19bf3fa21f8c14953))
|
|
6
|
+
|
|
1
7
|
## [1.0.1](https://github.com/sizebay/events-sdk/compare/v1.0.0...v1.0.1) (2025-04-01)
|
|
2
8
|
|
|
3
9
|
### Bug Fixes
|
package/README.md
CHANGED
|
@@ -35,25 +35,63 @@ const client = createClient({
|
|
|
35
35
|
|
|
36
36
|
---
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
## Tracker Module
|
|
39
39
|
|
|
40
|
-
#### `track(eventName: string, payload:
|
|
41
|
-
Sends an event to the designated API endpoint.
|
|
40
|
+
#### `track(eventName: string, payload: TrackData): Promise<TrackResponse>`
|
|
41
|
+
Sends an event to the designated API endpoint, returning a standardized response.
|
|
42
42
|
|
|
43
43
|
**Parameters**
|
|
44
44
|
|
|
45
|
-
| Parameter
|
|
46
|
-
|
|
47
|
-
| `eventName`
|
|
48
|
-
| `payload`
|
|
45
|
+
| Parameter | Type | Required | Description |
|
|
46
|
+
|-------------|-------------|----------|-----------------------------------------------------------------------|
|
|
47
|
+
| `eventName` | `string` | Yes | The name of the event (e.g., "ADD_TO_CART", "ORDER"). |
|
|
48
|
+
| `payload` | `TrackData` | Yes | An object containing event data. See the structure of `TrackData` below. |
|
|
49
|
+
|
|
50
|
+
**TrackData Structure**
|
|
51
|
+
|
|
52
|
+
| Property | Type | Required | Description |
|
|
53
|
+
|-------------|-------------------------------|----------|-----------------------------------------------------------------------|
|
|
54
|
+
| **sid** | `string` | Yes | Unique session identifier. |
|
|
55
|
+
| **tenantId**| `number` | Yes | Identifier of the tenant (client) sending the event. |
|
|
56
|
+
| **sessionId**| `number` | Yes | Internal session identifier. |
|
|
57
|
+
| **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. |
|
|
58
|
+
| **properties**| `Record<string, JSONValue>` | Yes | Object containing additional properties as key-value pairs. |
|
|
59
|
+
**Returns**
|
|
60
|
+
|
|
61
|
+
- **201** – Event successfully created.
|
|
62
|
+
```json
|
|
63
|
+
{
|
|
64
|
+
"statusCode": 201,
|
|
65
|
+
"message": "Event successfully created."
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
- **400** – Invalid or missing fields.
|
|
69
|
+
```json
|
|
70
|
+
{
|
|
71
|
+
"statusCode": 400,
|
|
72
|
+
"error": "Bad Request",
|
|
73
|
+
"message": [
|
|
74
|
+
"tenantId must be an integer number"
|
|
75
|
+
]
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
- **500** – Internal server error.
|
|
79
|
+
```json
|
|
80
|
+
{
|
|
81
|
+
"statusCode": 500,
|
|
82
|
+
"error": "Internal server error",
|
|
83
|
+
"message": [
|
|
84
|
+
"Unexpected error on server side"
|
|
85
|
+
]
|
|
86
|
+
}
|
|
87
|
+
```
|
|
49
88
|
|
|
50
89
|
**Example**
|
|
51
90
|
|
|
52
91
|
```typescript
|
|
53
|
-
const eventPayload = {
|
|
92
|
+
const eventPayload: TrackData = {
|
|
54
93
|
sid: 'a0cf8559-926a-4a75-b4ca-7c4c13fed69c',
|
|
55
94
|
tenantId: 123,
|
|
56
|
-
eventName: 'ADD_TO_CART',
|
|
57
95
|
sessionId: 123,
|
|
58
96
|
permalink: 'https://www.example.com/2IC-7370',
|
|
59
97
|
properties: {
|
|
@@ -66,9 +104,18 @@ const eventPayload = {
|
|
|
66
104
|
async function trackEvent() {
|
|
67
105
|
try {
|
|
68
106
|
const response = await client.track('ADD_TO_CART', eventPayload);
|
|
69
|
-
|
|
107
|
+
|
|
108
|
+
if (response.statusCode === 201) {
|
|
109
|
+
console.log('Event tracked successfully:', response.message);
|
|
110
|
+
} else {
|
|
111
|
+
console.error(
|
|
112
|
+
`Error tracking event (${response.statusCode}):`,
|
|
113
|
+
response.error,
|
|
114
|
+
response.message
|
|
115
|
+
);
|
|
116
|
+
}
|
|
70
117
|
} catch (error: any) {
|
|
71
|
-
console.error('
|
|
118
|
+
console.error('Unexpected error tracking event:', error.message);
|
|
72
119
|
}
|
|
73
120
|
}
|
|
74
121
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { TrackData } from '../types';
|
|
1
|
+
import { TrackData, TrackResponse } from '../types';
|
|
2
2
|
import { Config } from '../config';
|
|
3
3
|
export declare class Tracker {
|
|
4
4
|
private endpoint;
|
|
5
5
|
constructor(config: Config);
|
|
6
|
-
track(eventName: string, payload: TrackData): Promise<
|
|
6
|
+
track(eventName: string, payload: TrackData): Promise<TrackResponse>;
|
|
7
7
|
}
|
|
@@ -11,3 +11,18 @@ export interface TrackData {
|
|
|
11
11
|
export interface DataEventPayload extends TrackData {
|
|
12
12
|
eventName: string;
|
|
13
13
|
}
|
|
14
|
+
export interface TrackSuccessResponse {
|
|
15
|
+
statusCode: 201;
|
|
16
|
+
message: 'Event successfully created.';
|
|
17
|
+
}
|
|
18
|
+
export interface TrackBadRequestResponse {
|
|
19
|
+
statusCode: 400;
|
|
20
|
+
error: 'Bad Request';
|
|
21
|
+
message: string[];
|
|
22
|
+
}
|
|
23
|
+
export interface TrackServerErrorResponse {
|
|
24
|
+
statusCode: 500;
|
|
25
|
+
error: 'Internal server error';
|
|
26
|
+
message: string[];
|
|
27
|
+
}
|
|
28
|
+
export type TrackResponse = TrackSuccessResponse | TrackBadRequestResponse | TrackServerErrorResponse;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sizebay-core-sdk",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.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/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
package/src/modules/tracker.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DataEventPayload, TrackData } from "../types";
|
|
1
|
+
import { DataEventPayload, TrackData, TrackResponse } from "../types";
|
|
2
2
|
import { Config } from "../config";
|
|
3
3
|
|
|
4
4
|
export class Tracker {
|
|
@@ -9,7 +9,7 @@ export class Tracker {
|
|
|
9
9
|
this.endpoint = config.getEndpoint('tracker');
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
public async track(eventName: string, payload: TrackData): Promise<
|
|
12
|
+
public async track(eventName: string, payload: TrackData): Promise<TrackResponse> {
|
|
13
13
|
const data: DataEventPayload = {
|
|
14
14
|
eventName,
|
|
15
15
|
...payload,
|
package/src/types/event.types.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Represents any valid JSON value.
|
|
3
|
-
*/
|
|
4
1
|
export type JSONValue =
|
|
5
2
|
| string
|
|
6
3
|
| number
|
|
@@ -9,9 +6,6 @@ export type JSONValue =
|
|
|
9
6
|
| JSONValue[]
|
|
10
7
|
| { [key: string]: JSONValue };
|
|
11
8
|
|
|
12
|
-
/**
|
|
13
|
-
* Interface that defines the structure of a tracked event.
|
|
14
|
-
*/
|
|
15
9
|
export interface TrackData {
|
|
16
10
|
sid: string;
|
|
17
11
|
tenantId: number;
|
|
@@ -20,9 +14,30 @@ export interface TrackData {
|
|
|
20
14
|
properties: Record<string, JSONValue>;
|
|
21
15
|
}
|
|
22
16
|
|
|
23
|
-
/**
|
|
24
|
-
* Payload for the track event.
|
|
25
|
-
*/
|
|
26
17
|
export interface DataEventPayload extends TrackData {
|
|
27
18
|
eventName: string;
|
|
28
|
-
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface TrackSuccessResponse {
|
|
22
|
+
statusCode: 201;
|
|
23
|
+
message: 'Event successfully created.';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface TrackBadRequestResponse {
|
|
27
|
+
statusCode: 400;
|
|
28
|
+
error: 'Bad Request';
|
|
29
|
+
|
|
30
|
+
message: string[];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface TrackServerErrorResponse {
|
|
34
|
+
statusCode: 500;
|
|
35
|
+
error: 'Internal server error';
|
|
36
|
+
|
|
37
|
+
message: string[];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type TrackResponse =
|
|
41
|
+
| TrackSuccessResponse
|
|
42
|
+
| TrackBadRequestResponse
|
|
43
|
+
| TrackServerErrorResponse;
|