sizebay-core-sdk 1.0.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/.github/pull_request_template.md +24 -0
- package/.github/workflows/publish.yml +48 -0
- package/.github/workflows/tests-on-pr.yml +37 -0
- package/.prettierrc +7 -0
- package/.releaserc.json +32 -0
- package/CHANGELOG.md +13 -0
- package/README.dev.md +184 -0
- package/README.md +115 -0
- package/dist/sizebay-core-sdk.es.js +124 -0
- package/dist/sizebay-core-sdk.umd.js +1 -0
- package/dist/types/src/config/endpoints.d.ts +2 -0
- package/dist/types/src/config/index.d.ts +10 -0
- package/dist/types/src/core/client.d.ts +2 -0
- package/dist/types/src/index.d.ts +2 -0
- package/dist/types/src/modules/ai-image-service.d.ts +8 -0
- package/dist/types/src/modules/index.d.ts +3 -0
- package/dist/types/src/modules/tracker.d.ts +7 -0
- package/dist/types/src/types/ai-image-service.types.d.ts +48 -0
- package/dist/types/src/types/client.types.d.ts +13 -0
- package/dist/types/src/types/event.types.d.ts +13 -0
- package/dist/types/src/types/index.d.ts +4 -0
- package/dist/types/src/types/sdk.types.d.ts +15 -0
- package/dist/types/test/config/config.test.d.ts +1 -0
- package/dist/types/test/core/client.test.d.ts +1 -0
- package/dist/types/test/example.d.ts +1 -0
- package/dist/types/test/index.test.d.ts +1 -0
- package/dist/types/test/jest.setup.d.ts +0 -0
- package/dist/types/test/modules/ai-image-service.test.d.ts +1 -0
- package/dist/types/test/modules/tracker.test.d.ts +1 -0
- package/jest.config.cjs +18 -0
- package/package.json +44 -0
- package/src/config/endpoints.ts +14 -0
- package/src/config/index.ts +42 -0
- package/src/core/client.ts +26 -0
- package/src/index.ts +2 -0
- package/src/modules/ai-image-service.ts +68 -0
- package/src/modules/index.ts +7 -0
- package/src/modules/tracker.ts +37 -0
- package/src/types/ai-image-service.types.ts +52 -0
- package/src/types/client.types.ts +30 -0
- package/src/types/event.types.ts +28 -0
- package/src/types/index.ts +4 -0
- package/src/types/sdk.types.ts +17 -0
- package/test/config/config.test.ts +59 -0
- package/test/core/client.test.ts +32 -0
- package/test/example.ts +53 -0
- package/test/index.test.ts +12 -0
- package/test/jest.setup.ts +8 -0
- package/test/modules/ai-image-service.test.ts +234 -0
- package/test/modules/tracker.test.ts +86 -0
- package/tsconfig.json +28 -0
- package/vite.config.ts +27 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
## Descrição
|
|
2
|
+
<!-- Descreva o que foi feito neste Pull Request. -->
|
|
3
|
+
|
|
4
|
+
## Design Pattern
|
|
5
|
+
<!-- Foi utilizado algum Design Pattern? Se sim, descreva qual e como foi aplicado. -->
|
|
6
|
+
|
|
7
|
+
## Testes Unitários
|
|
8
|
+
- [ ] Testes unitários foram aplicados.
|
|
9
|
+
- [ ] A funcionalidade foi testada manualmente.
|
|
10
|
+
- **Cobertura de Testes:**
|
|
11
|
+
<!-- Anexar aqui imagens ou evidências de cobertura de testes. -->
|
|
12
|
+
|
|
13
|
+
## Evidências de Funcionamento
|
|
14
|
+
<!-- Anexar evidências como capturas de tela ou GIFs mostrando o funcionamento da funcionalidade implementada. -->
|
|
15
|
+
|
|
16
|
+
## Link da História
|
|
17
|
+
<!-- Adicione o link para a história no ClickUp ou ferramenta de gerenciamento de tarefas: -->
|
|
18
|
+
[Link para a história no ClickUp](https://app.clickup.com/)
|
|
19
|
+
|
|
20
|
+
## Checklist
|
|
21
|
+
- [ ] A funcionalidade foi testada manualmente.
|
|
22
|
+
- [ ] O código segue os padrões de formatação do projeto.
|
|
23
|
+
- [ ] A documentação foi atualizada, se aplicável.
|
|
24
|
+
- [ ] Os testes passaram localmente.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
- master
|
|
8
|
+
|
|
9
|
+
permissions:
|
|
10
|
+
contents: write
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
release:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
steps:
|
|
16
|
+
- name: Checkout repository
|
|
17
|
+
uses: actions/checkout@v3
|
|
18
|
+
|
|
19
|
+
- name: Set up Node.js
|
|
20
|
+
uses: actions/setup-node@v3
|
|
21
|
+
with:
|
|
22
|
+
node-version: 'lts/*'
|
|
23
|
+
registry-url: 'https://registry.npmjs.org/'
|
|
24
|
+
|
|
25
|
+
- name: Set up pnpm
|
|
26
|
+
uses: pnpm/action-setup@v2
|
|
27
|
+
with:
|
|
28
|
+
version: '7'
|
|
29
|
+
|
|
30
|
+
- name: Install dependencies
|
|
31
|
+
run: pnpm i
|
|
32
|
+
|
|
33
|
+
- name: Run tests
|
|
34
|
+
run: pnpm test
|
|
35
|
+
|
|
36
|
+
- name: Build project
|
|
37
|
+
run: pnpm run build
|
|
38
|
+
|
|
39
|
+
- name: Test npm authentication
|
|
40
|
+
run: npm whoami --registry=https://registry.npmjs.org/
|
|
41
|
+
env:
|
|
42
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
43
|
+
|
|
44
|
+
- name: Run semantic-release
|
|
45
|
+
run: pnpm run release
|
|
46
|
+
env:
|
|
47
|
+
GITHUB_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }}
|
|
48
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
name: CI - Run Tests on PR
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
- master
|
|
8
|
+
- develop
|
|
9
|
+
types:
|
|
10
|
+
- opened
|
|
11
|
+
- synchronize
|
|
12
|
+
- reopened
|
|
13
|
+
|
|
14
|
+
jobs:
|
|
15
|
+
test:
|
|
16
|
+
runs-on: ubuntu-latest
|
|
17
|
+
|
|
18
|
+
steps:
|
|
19
|
+
- name: Checkout code
|
|
20
|
+
uses: actions/checkout@v3
|
|
21
|
+
|
|
22
|
+
- name: Set up Node.js
|
|
23
|
+
uses: actions/setup-node@v3
|
|
24
|
+
with:
|
|
25
|
+
node-version: 18
|
|
26
|
+
|
|
27
|
+
- name: Install pnpm
|
|
28
|
+
run: npm install -g pnpm
|
|
29
|
+
|
|
30
|
+
- name: Install dependencies
|
|
31
|
+
run: pnpm install
|
|
32
|
+
|
|
33
|
+
- name: Build packages
|
|
34
|
+
run: pnpm run build
|
|
35
|
+
|
|
36
|
+
- name: Run tests
|
|
37
|
+
run: pnpm test:ci
|
package/.prettierrc
ADDED
package/.releaserc.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"branches": ["master"],
|
|
3
|
+
"plugins": [
|
|
4
|
+
[
|
|
5
|
+
"@semantic-release/commit-analyzer",
|
|
6
|
+
{
|
|
7
|
+
"preset": "conventionalcommits"
|
|
8
|
+
}
|
|
9
|
+
],
|
|
10
|
+
[
|
|
11
|
+
"@semantic-release/release-notes-generator",
|
|
12
|
+
{
|
|
13
|
+
"preset": "conventionalcommits"
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
[
|
|
17
|
+
"@semantic-release/changelog",
|
|
18
|
+
{
|
|
19
|
+
"changelogFile": "CHANGELOG.md"
|
|
20
|
+
}
|
|
21
|
+
],
|
|
22
|
+
"@semantic-release/npm",
|
|
23
|
+
[
|
|
24
|
+
"@semantic-release/git",
|
|
25
|
+
{
|
|
26
|
+
"assets": ["package.json", "CHANGELOG.md"],
|
|
27
|
+
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
|
|
28
|
+
}
|
|
29
|
+
]
|
|
30
|
+
]
|
|
31
|
+
}
|
|
32
|
+
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
## 1.0.0 (2025-03-31)
|
|
2
|
+
|
|
3
|
+
### Features
|
|
4
|
+
|
|
5
|
+
* add AI Image Service module ([2280302](https://github.com/sizebay/events-sdk/commit/228030292e3ab9d930a428f0f8dd46778b21ab7d))
|
|
6
|
+
* add env-based endpoints and service-specific config overrides ([3c42273](https://github.com/sizebay/events-sdk/commit/3c4227350e36ee468fa86449b6a5f4ebe2016d32))
|
|
7
|
+
* add module composition logic to client ([f486058](https://github.com/sizebay/events-sdk/commit/f486058e35ca9ebb1efb4ed00848d4dc438d0b03))
|
|
8
|
+
* **ai-image-service:** add product size recommendation ([2cace2e](https://github.com/sizebay/events-sdk/commit/2cace2e7107672dcde3acd7a76f57973a4bba7c1))
|
|
9
|
+
* initial project setup ([37f7e9f](https://github.com/sizebay/events-sdk/commit/37f7e9fd313e0770d527a3b898a5180910124a41))
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* remove `beforeAll` in test setup to avoid reference error ([ea06da4](https://github.com/sizebay/events-sdk/commit/ea06da4019f43eb084a556d3b04c2286b6ec2b84))
|
package/README.dev.md
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
# Sizebay Core SDK - Development Guide
|
|
2
|
+
|
|
3
|
+
This guide is intended to help developers understand the project structure, how to create and integrate new modules, run tests, and configure automated releases with Semantic Release.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Project Structure
|
|
8
|
+
|
|
9
|
+
The project is organized as follows:
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
📦src
|
|
13
|
+
┣ 📂config
|
|
14
|
+
┃ ┣ index.ts // Configuration manager that handles endpoints and service-specific settings.
|
|
15
|
+
┣ 📂core
|
|
16
|
+
┃ ┣ client.ts // Core logic for creating and aggregating modules.
|
|
17
|
+
┣ 📂modules
|
|
18
|
+
┃ ┣ tracker.ts // Example module (Tracker).
|
|
19
|
+
┃ ┣ ai-image-service.ts// Example module (AI Image Service).
|
|
20
|
+
┃ ┗ index.ts // Exports all modules (centralized import for the client).
|
|
21
|
+
┣ 📂types
|
|
22
|
+
┃ ┣ sdk.ts // SDK configuration types.
|
|
23
|
+
┃ ┣ tracker.ts // Types related to the Tracker module.
|
|
24
|
+
┃ ┣ ai-image-service.ts// Types related to the AI Image Service module.
|
|
25
|
+
┃ ┗ index.ts // Exports all public types.
|
|
26
|
+
┣ index.ts // Entry point of the SDK (exports public API).
|
|
27
|
+
┗ 📂test
|
|
28
|
+
┗ example.ts // Example usage and tests for the SDK.
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
**Key Directories:**
|
|
32
|
+
|
|
33
|
+
- **config**: Contains the configuration manager that loads endpoints (from `endpoints.ts`) and applies any service-specific overrides.
|
|
34
|
+
- **core**: Houses the client creation logic that aggregates all modules.
|
|
35
|
+
- **modules**: Each module provides a distinct functionality (e.g., event tracking, AI services). New modules should be added here.
|
|
36
|
+
- **types**: Contains all TypeScript type definitions for both the core SDK and each module.
|
|
37
|
+
- **test**: Provides examples and tests to verify the SDK functionality.
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## Building the SDK
|
|
42
|
+
|
|
43
|
+
To compile the TypeScript source into JavaScript, run:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
npm run build
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
This command compiles the project and outputs the JavaScript files into the directory specified in your TypeScript configuration (usually `./dist`).
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## Running Tests and Examples
|
|
54
|
+
|
|
55
|
+
An example usage is provided in the `test/example.ts` file. To run tests or examples, execute:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
npm run test:dev
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
> **Note:** The test script uses `ts-node` to run TypeScript examples directly.
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## How to Create a New Module
|
|
66
|
+
|
|
67
|
+
To add a new module to the SDK, follow these steps:
|
|
68
|
+
|
|
69
|
+
1. **Create the Module File:**
|
|
70
|
+
- Add your new module in the `src/modules` directory. For instance, create a file named `new-module.ts`.
|
|
71
|
+
|
|
72
|
+
2. **Define the Module Class:**
|
|
73
|
+
- The module class should accept an instance of `Config` in its constructor so it can retrieve its endpoint and other service-specific configurations.
|
|
74
|
+
- Expose only the public methods that should be part of the client’s API.
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
// src/modules/new-module.ts
|
|
78
|
+
import { Config } from '@src/config/config';
|
|
79
|
+
|
|
80
|
+
export class NewModule {
|
|
81
|
+
private endpoint: string;
|
|
82
|
+
|
|
83
|
+
constructor(config: Config) {
|
|
84
|
+
// Retrieve the endpoint configured for the new module.
|
|
85
|
+
this.endpoint = config.getEndpoint('newModule');
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
public async doSomething(params: any): Promise<any> {
|
|
89
|
+
// Module logic here.
|
|
90
|
+
// Use `this.endpoint` for requests.
|
|
91
|
+
return { success: true };
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
3. **Update Type Definitions:**
|
|
97
|
+
- Create a new type file in `src/types` (e.g., `new-module.ts`) for any interfaces or types related to your module.
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
// src/types/new-module.ts
|
|
101
|
+
export interface NewModuleParams {
|
|
102
|
+
param1: string;
|
|
103
|
+
param2?: number;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export interface NewModuleResponse {
|
|
107
|
+
success: boolean;
|
|
108
|
+
data?: any;
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
4. **Update the Modules Index:**
|
|
113
|
+
- In `src/modules/index.ts`, import and add your new module to the list of module classes.
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
// src/modules/index.ts
|
|
117
|
+
import { Tracker } from './tracker';
|
|
118
|
+
import { AIImageService } from './ai-image-service';
|
|
119
|
+
import { NewModule } from './new-module';
|
|
120
|
+
|
|
121
|
+
export const moduleClasses = [
|
|
122
|
+
Tracker,
|
|
123
|
+
AIImageService,
|
|
124
|
+
NewModule,
|
|
125
|
+
// Add new modules here as needed.
|
|
126
|
+
];
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## Configuration & Endpoints
|
|
132
|
+
|
|
133
|
+
The SDK manages endpoints based on the environment. Endpoints for each service are defined in a dedicated module (e.g., `src/config/endpoints.ts`). The `Config` class loads these endpoints based on the `env` option provided during client initialization. It also supports service-specific overrides that are passed via the SDK configuration options.
|
|
134
|
+
|
|
135
|
+
Example configuration usage:
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
import { createClient } from 'sizebay-core-sdk';
|
|
139
|
+
|
|
140
|
+
const client = createClient({
|
|
141
|
+
env: 'development',
|
|
142
|
+
services: {
|
|
143
|
+
aiImageService: {
|
|
144
|
+
timeout: 15000, // Example: override default timeout for AI Image Service.
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## Semantic Release & Automated Releases
|
|
154
|
+
|
|
155
|
+
This project uses [Semantic Release](https://semantic-release.gitbook.io/semantic-release/) to automate versioning, changelog generation, and package publishing. Key dependencies include:
|
|
156
|
+
|
|
157
|
+
- **@semantic-release/changelog**: Generates the changelog based on commit messages.
|
|
158
|
+
- **@semantic-release/commit-analyzer**: Analyzes commit messages (following Conventional Commits) to determine the type of release (major, minor, patch).
|
|
159
|
+
- **@semantic-release/git**: Commits and pushes version bumps and changelog updates.
|
|
160
|
+
- **@semantic-release/npm**: Publishes the updated package to npm.
|
|
161
|
+
- **@semantic-release/release-notes-generator**: Creates release notes from commit messages.
|
|
162
|
+
- **@types/jest**: Provides TypeScript definitions for Jest if you are writing unit tests.
|
|
163
|
+
|
|
164
|
+
### How It Works
|
|
165
|
+
|
|
166
|
+
1. **Commit Conventions:**
|
|
167
|
+
- Follow the [Conventional Commits](https://www.conventionalcommits.org/) standard for your commit messages.
|
|
168
|
+
- The commit analyzer scans these messages to decide whether a new release should be a major, minor, or patch update.
|
|
169
|
+
|
|
170
|
+
2. **Changelog Generation:**
|
|
171
|
+
- The release notes generator and changelog plugins automatically generate a changelog from the commits.
|
|
172
|
+
|
|
173
|
+
3. **Publishing:**
|
|
174
|
+
- After generating the release notes, the Git plugin updates version numbers and changelog files in the repository.
|
|
175
|
+
- Finally, the npm plugin publishes the new version to npm.
|
|
176
|
+
|
|
177
|
+
4. **Configuration:**
|
|
178
|
+
- Semantic Release settings are typically defined in a `.releaserc` file or within the `release` key in `package.json`. Refer to the Semantic Release documentation for customization options.
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
## Contributing
|
|
183
|
+
|
|
184
|
+
Contributions are welcome! If you have ideas, bug fixes, or improvements, please open an issue or submit a pull request on GitHub. Make sure to follow the commit message guidelines and code style conventions.
|
package/README.md
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# Sizebay Core SDK
|
|
2
|
+
|
|
3
|
+
A lightweight, modular, and extensible SDK designed for integrating multiple services (such as event tracking, AI services, etc.) into your application. This package includes environment-based endpoint management, async/await support, and full TypeScript definitions.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Install the package via npm:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install sizebay-core-sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## API Reference
|
|
14
|
+
|
|
15
|
+
### Client
|
|
16
|
+
|
|
17
|
+
#### `createClient(options: SDKConfigOptions): ClientType`
|
|
18
|
+
Creates a new instance of the SDK with the provided configuration.
|
|
19
|
+
|
|
20
|
+
**Options**
|
|
21
|
+
|
|
22
|
+
| Property | Type | Required | Description |
|
|
23
|
+
|----------|----------|----------|---------------------------------------------------------------------|
|
|
24
|
+
| `env` | `string` | No | The environment to use (`'development'` or `'production'`). Defaults to `'development'`. |
|
|
25
|
+
|
|
26
|
+
**Example**
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import { createClient } from 'sizebay-core-sdk';
|
|
30
|
+
|
|
31
|
+
const client = createClient({
|
|
32
|
+
env: 'development',
|
|
33
|
+
});
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
### Tracker Module
|
|
39
|
+
|
|
40
|
+
#### `track(eventName: string, payload: EventPayload): Promise<any>`
|
|
41
|
+
Sends an event to the designated API endpoint.
|
|
42
|
+
|
|
43
|
+
**Parameters**
|
|
44
|
+
|
|
45
|
+
| Parameter | Type | Required | Description |
|
|
46
|
+
|--------------|----------------|----------|--------------------------------------------------|
|
|
47
|
+
| `eventName` | `string` | Yes | The name of the event (e.g., "ADD_TO_CART", "ORDER"). |
|
|
48
|
+
| `payload` | `EventPayload` | Yes | An object containing event data. |
|
|
49
|
+
|
|
50
|
+
**Example**
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
const eventPayload = {
|
|
54
|
+
sid: 'a0cf8559-926a-4a75-b4ca-7c4c13fed69c',
|
|
55
|
+
tenantId: 123,
|
|
56
|
+
eventName: 'ADD_TO_CART',
|
|
57
|
+
sessionId: 123,
|
|
58
|
+
permalink: 'https://www.example.com/2IC-7370',
|
|
59
|
+
properties: {
|
|
60
|
+
quantity: 1,
|
|
61
|
+
device: 'APP',
|
|
62
|
+
country: 'BR',
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
async function trackEvent() {
|
|
67
|
+
try {
|
|
68
|
+
const response = await client.track('ADD_TO_CART', eventPayload);
|
|
69
|
+
console.log('Event tracked successfully:', response);
|
|
70
|
+
} catch (error: any) {
|
|
71
|
+
console.error('Error tracking event:', error.message);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
trackEvent();
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
### AI Image Service Module
|
|
81
|
+
|
|
82
|
+
#### `getSimilarProducts(params: GetSimilarProductsParams): Promise<GetSimilarProductsResponse>`
|
|
83
|
+
Fetches similar products based on the provided image parameters.
|
|
84
|
+
|
|
85
|
+
**Parameters**
|
|
86
|
+
|
|
87
|
+
| Parameter | Type | Required | Description |
|
|
88
|
+
|-----------|----------------------------|----------|------------------------------------------------------------|
|
|
89
|
+
| `params` | `GetSimilarProductsParams` | Yes | An object containing parameters for fetching similar products. |
|
|
90
|
+
|
|
91
|
+
**Example**
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
import { GetSimilarProductsParams } from 'sizebay-core-sdk/types/ai-image-service';
|
|
95
|
+
|
|
96
|
+
const params: GetSimilarProductsParams = {
|
|
97
|
+
tenantId: 123,
|
|
98
|
+
permalink: 'https://example.com/product',
|
|
99
|
+
collectionName: 'summer-collection', // optional
|
|
100
|
+
sessionId: 456, // optional
|
|
101
|
+
page: 1, // optional
|
|
102
|
+
perPage: 10, // optional
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
async function fetchSimilarProducts() {
|
|
106
|
+
try {
|
|
107
|
+
const response = await client.getSimilarProducts(params);
|
|
108
|
+
console.log('Similar products:', response.data);
|
|
109
|
+
} catch (error: any) {
|
|
110
|
+
console.error('Error fetching similar products:', error.message);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
fetchSimilarProducts();
|
|
115
|
+
```
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
const c = {
|
|
2
|
+
tracker: {
|
|
3
|
+
production: "https://data-event-service.internalsizebay.com/events",
|
|
4
|
+
development: "https://data-event-service.internalsizebay.com/events"
|
|
5
|
+
},
|
|
6
|
+
aiImageService: {
|
|
7
|
+
production: "https://ai-image-service.example.com/production",
|
|
8
|
+
development: "https://ai-image-service.example.com/development"
|
|
9
|
+
}
|
|
10
|
+
// Adicione outros serviços conforme necessário
|
|
11
|
+
};
|
|
12
|
+
class a {
|
|
13
|
+
constructor(r) {
|
|
14
|
+
const o = r.env || "development";
|
|
15
|
+
this.serviceOverrides = r.services || {}, this.endpoints = {};
|
|
16
|
+
for (const t in c)
|
|
17
|
+
if (Object.prototype.hasOwnProperty.call(c, t)) {
|
|
18
|
+
const i = c[t][o];
|
|
19
|
+
if (!i)
|
|
20
|
+
continue;
|
|
21
|
+
this.endpoints[t] = i;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
getEndpoint(r) {
|
|
25
|
+
const o = this.endpoints[r];
|
|
26
|
+
if (!o)
|
|
27
|
+
throw new Error(
|
|
28
|
+
`Endpoint for service '${r}' is not configured.`
|
|
29
|
+
);
|
|
30
|
+
return o;
|
|
31
|
+
}
|
|
32
|
+
getServiceConfig(r) {
|
|
33
|
+
return this.serviceOverrides[r] || {};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
class p {
|
|
37
|
+
constructor(r) {
|
|
38
|
+
this.endpoint = r.getEndpoint("tracker");
|
|
39
|
+
}
|
|
40
|
+
async track(r, o) {
|
|
41
|
+
const t = {
|
|
42
|
+
eventName: r,
|
|
43
|
+
...o
|
|
44
|
+
};
|
|
45
|
+
try {
|
|
46
|
+
const e = await fetch(this.endpoint, {
|
|
47
|
+
method: "POST",
|
|
48
|
+
headers: { "Content-Type": "application/json" },
|
|
49
|
+
body: JSON.stringify(t)
|
|
50
|
+
});
|
|
51
|
+
if (!e.ok) {
|
|
52
|
+
const i = await e.text();
|
|
53
|
+
throw new Error(`Request error: ${e.status} - ${i}`);
|
|
54
|
+
}
|
|
55
|
+
return await e.json();
|
|
56
|
+
} catch (e) {
|
|
57
|
+
throw e;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
class d {
|
|
62
|
+
constructor(r) {
|
|
63
|
+
this.endpoint = r.getEndpoint("aiImageService");
|
|
64
|
+
}
|
|
65
|
+
async getSimilarProducts(r) {
|
|
66
|
+
const o = new URL(`${this.endpoint}/recommendations/similar`);
|
|
67
|
+
Object.entries(r).forEach(([t, e]) => {
|
|
68
|
+
e !== void 0 && o.searchParams.append(t, String(e));
|
|
69
|
+
});
|
|
70
|
+
try {
|
|
71
|
+
const t = await fetch(o.toString(), {
|
|
72
|
+
method: "GET",
|
|
73
|
+
headers: {
|
|
74
|
+
"Content-Type": "application/json"
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
if (!t.ok) {
|
|
78
|
+
const e = await t.text();
|
|
79
|
+
throw new Error(`Request error: ${t.status} - ${e}`);
|
|
80
|
+
}
|
|
81
|
+
return await t.json();
|
|
82
|
+
} catch (t) {
|
|
83
|
+
throw new Error(`Error fetching similar products: ${t.message}`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async getRecommendedProductSize(r) {
|
|
87
|
+
const o = new URL(`${this.endpoint}/recommendations/size-by-products`);
|
|
88
|
+
try {
|
|
89
|
+
const t = await fetch(o.toString(), {
|
|
90
|
+
method: "POST",
|
|
91
|
+
headers: {
|
|
92
|
+
"Content-Type": "application/json"
|
|
93
|
+
},
|
|
94
|
+
body: JSON.stringify(r)
|
|
95
|
+
});
|
|
96
|
+
if (!t.ok) {
|
|
97
|
+
const e = await t.text();
|
|
98
|
+
throw new Error(`Request error: ${t.status} - ${e}`);
|
|
99
|
+
}
|
|
100
|
+
return await t.json();
|
|
101
|
+
} catch (t) {
|
|
102
|
+
throw new Error(`Error fetching recommended product size: ${t.message}`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const h = [
|
|
107
|
+
p,
|
|
108
|
+
d
|
|
109
|
+
];
|
|
110
|
+
function f(s) {
|
|
111
|
+
const r = new a(s), o = h.map((e) => new e(r)), t = { config: r };
|
|
112
|
+
return o.forEach((e) => {
|
|
113
|
+
Object.getOwnPropertyNames(e).forEach((n) => {
|
|
114
|
+
typeof e[n] == "function" && (t[n] = e[n].bind(e));
|
|
115
|
+
});
|
|
116
|
+
const i = Object.getPrototypeOf(e);
|
|
117
|
+
Object.getOwnPropertyNames(i).forEach((n) => {
|
|
118
|
+
n !== "constructor" && typeof e[n] == "function" && (t[n] = e[n].bind(e));
|
|
119
|
+
});
|
|
120
|
+
}), t;
|
|
121
|
+
}
|
|
122
|
+
export {
|
|
123
|
+
f as createClient
|
|
124
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(s,i){typeof exports=="object"&&typeof module<"u"?i(exports):typeof define=="function"&&define.amd?define(["exports"],i):(s=typeof globalThis<"u"?globalThis:s||self,i(s["sizebay-core-sdk"]={}))})(this,function(s){"use strict";const i={tracker:{production:"https://data-event-service.internalsizebay.com/events",development:"https://data-event-service.internalsizebay.com/events"},aiImageService:{production:"https://ai-image-service.example.com/production",development:"https://ai-image-service.example.com/development"}};class p{constructor(r){const o=r.env||"development";this.serviceOverrides=r.services||{},this.endpoints={};for(const e in i)if(Object.prototype.hasOwnProperty.call(i,e)){const c=i[e][o];if(!c)continue;this.endpoints[e]=c}}getEndpoint(r){const o=this.endpoints[r];if(!o)throw new Error(`Endpoint for service '${r}' is not configured.`);return o}getServiceConfig(r){return this.serviceOverrides[r]||{}}}class d{constructor(r){this.endpoint=r.getEndpoint("tracker")}async track(r,o){const e={eventName:r,...o};try{const t=await fetch(this.endpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!t.ok){const c=await t.text();throw new Error(`Request error: ${t.status} - ${c}`)}return await t.json()}catch(t){throw t}}}class f{constructor(r){this.endpoint=r.getEndpoint("aiImageService")}async getSimilarProducts(r){const o=new URL(`${this.endpoint}/recommendations/similar`);Object.entries(r).forEach(([e,t])=>{t!==void 0&&o.searchParams.append(e,String(t))});try{const e=await fetch(o.toString(),{method:"GET",headers:{"Content-Type":"application/json"}});if(!e.ok){const t=await e.text();throw new Error(`Request error: ${e.status} - ${t}`)}return await e.json()}catch(e){throw new Error(`Error fetching similar products: ${e.message}`)}}async getRecommendedProductSize(r){const o=new URL(`${this.endpoint}/recommendations/size-by-products`);try{const e=await fetch(o.toString(),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});if(!e.ok){const t=await e.text();throw new Error(`Request error: ${e.status} - ${t}`)}return await e.json()}catch(e){throw new Error(`Error fetching recommended product size: ${e.message}`)}}}const h=[d,f];function u(a){const r=new p(a),o=h.map(t=>new t(r)),e={config:r};return o.forEach(t=>{Object.getOwnPropertyNames(t).forEach(n=>{typeof t[n]=="function"&&(e[n]=t[n].bind(t))});const c=Object.getPrototypeOf(t);Object.getOwnPropertyNames(c).forEach(n=>{n!=="constructor"&&typeof t[n]=="function"&&(e[n]=t[n].bind(t))})}),e}s.createClient=u,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SDKConfigOptions } from '../types';
|
|
2
|
+
export declare class Config {
|
|
3
|
+
private endpoints;
|
|
4
|
+
private serviceOverrides;
|
|
5
|
+
constructor(options: SDKConfigOptions);
|
|
6
|
+
getEndpoint(serviceName: string): string;
|
|
7
|
+
getServiceConfig(serviceName: string): {
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Config } from '../config';
|
|
2
|
+
import { GetRecommendedProductSizeParams, GetRecommendedProductSizeResponse, GetSimilarProductsParams, GetSimilarProductsResponse } from '../types/ai-image-service.types';
|
|
3
|
+
export declare class AIImageService {
|
|
4
|
+
private endpoint;
|
|
5
|
+
constructor(config: Config);
|
|
6
|
+
getSimilarProducts(params: GetSimilarProductsParams): Promise<GetSimilarProductsResponse>;
|
|
7
|
+
getRecommendedProductSize(payload: GetRecommendedProductSizeParams): Promise<GetRecommendedProductSizeResponse>;
|
|
8
|
+
}
|