@sales-planner/shared 0.2.0 → 0.3.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 CHANGED
@@ -1,6 +1,8 @@
1
- be for project ot rep package?# @sales-planner/shared
1
+ # @sales-planner/shared
2
2
 
3
- Shared types and HTTP client for the Sales Planner API.
3
+ Shared types and DTOs for the Sales Planner API.
4
+
5
+ > **Note**: For the HTTP client, use `@sales-planner/http-client` instead.
4
6
 
5
7
  ## Installation
6
8
 
@@ -12,97 +14,65 @@ pnpm add @sales-planner/shared
12
14
 
13
15
  ## Usage
14
16
 
15
- ### HTTP Client
17
+ This package provides TypeScript types only (no runtime code).
16
18
 
17
19
  ```typescript
18
- import { SalesPlannerClient } from '@sales-planner/shared';
19
-
20
- const client = new SalesPlannerClient({
21
- baseUrl: 'https://sales-planner-back.vercel.app',
22
- apiKey: 'your-api-key'
23
- });
24
-
25
- // Get current user
26
- const me = await client.getMe();
27
-
28
- // Get shops
29
- const shops = await client.getShops();
30
-
31
- // Get SKUs for a shop
32
- const skus = await client.getSkus({ shop_id: 1, tenant_id: 1 });
33
-
34
- // Import sales history
35
- const result = await client.importSalesHistoryJson([
36
- { sku_code: 'SKU-001', period: '2026-01', quantity: 100 }
37
- ], { shop_id: 1, tenant_id: 1 });
20
+ import type {
21
+ // Entities
22
+ User, Tenant, Shop, Sku, SalesHistory,
23
+ Role, UserRole, ApiKey, Marketplace,
24
+
25
+ // DTOs
26
+ CreateUserDto, CreateTenantDto, CreateShopDto,
27
+ CreateSkuDto, UpdateSkuDto, ImportSkuItem,
28
+ CreateSalesHistoryDto, UpdateSalesHistoryDto, ImportSalesHistoryItem,
29
+ CreateApiKeyDto, CreateRoleDto, CreateUserRoleDto, CreateMarketplaceDto,
30
+
31
+ // Query types
32
+ ShopContextParams, PeriodQuery,
33
+
34
+ // Response types
35
+ UserWithRolesAndTenants, TenantWithShopAndApiKey,
36
+ ImportResult, DeleteDataResult,
37
+ SkuExportItem, SalesHistoryExportItem
38
+ } from '@sales-planner/shared';
38
39
  ```
39
40
 
40
- ### Available Methods
41
-
42
- #### Authentication
43
- - `getMe()` - Get current user with roles and tenants
44
-
45
- #### Users
46
- - `getUsers()`, `getUser(id)`, `createUser(dto)`, `deleteUser(id)`
41
+ ## Types Reference
47
42
 
48
- #### Tenants
49
- - `getTenants()`, `getTenant(id)`, `createTenant(dto)`, `updateTenant(id, dto)`, `deleteTenant(id)`
50
- - `createTenantWithShopAndUser(dto)` - Create tenant with shop and user in one call
43
+ ### Entities
51
44
 
52
- #### Shops
53
- - `getShops(tenantId?)`, `getShop(id)`, `createShop(dto)`, `updateShop(id, dto)`, `deleteShop(id)`
54
- - `deleteShopData(id)` - Delete all data (SKUs, sales history) for a shop
45
+ | Type | Description |
46
+ |------|-------------|
47
+ | `User` | User account |
48
+ | `Tenant` | Organization/company |
49
+ | `Shop` | Store within a tenant |
50
+ | `Sku` | Stock keeping unit |
51
+ | `SalesHistory` | Sales record for a period |
52
+ | `Role` | Access role |
53
+ | `UserRole` | User-role assignment |
54
+ | `ApiKey` | API authentication key |
55
+ | `Marketplace` | E-commerce platform |
55
56
 
56
- #### SKUs
57
- - `getSkus(ctx)`, `getSku(id, ctx)`, `createSku(dto, ctx)`, `updateSku(id, dto, ctx)`, `deleteSku(id, ctx)`
58
- - `importSkusJson(items, ctx)`, `importSkusCsv(csvContent, ctx)`
59
- - `exportSkusJson(ctx)`, `exportSkusCsv(ctx)`
60
- - `getSkusExampleJson()`, `getSkusExampleCsv()` - Get import format examples
57
+ ### Query Types
61
58
 
62
- #### Sales History
63
- - `getSalesHistory(ctx, query?)`, `getSalesHistoryItem(id, ctx)`
64
- - `createSalesHistory(dto, ctx)`, `updateSalesHistory(id, dto, ctx)`, `deleteSalesHistory(id, ctx)`
65
- - `importSalesHistoryJson(items, ctx)`, `importSalesHistoryCsv(csvContent, ctx)`
66
- - `exportSalesHistoryJson(ctx, query?)`, `exportSalesHistoryCsv(ctx, query?)`
67
- - `getSalesHistoryExampleJson()`, `getSalesHistoryExampleCsv()` - Get import format examples
59
+ | Type | Description |
60
+ |------|-------------|
61
+ | `ShopContextParams` | `{ shop_id: number; tenant_id: number }` |
62
+ | `PeriodQuery` | `{ period_from?: string; period_to?: string }` |
68
63
 
69
- #### Roles & User Roles
70
- - `getRoles()`, `getRole(id)`, `createRole(dto)`, `updateRole(id, dto)`, `deleteRole(id)`
71
- - `createUserRole(dto)`, `deleteUserRole(id)`
64
+ ### Response Types
72
65
 
73
- #### API Keys
74
- - `getApiKeys()`, `createApiKey(dto)`, `deleteApiKey(id)`
66
+ | Type | Description |
67
+ |------|-------------|
68
+ | `UserWithRolesAndTenants` | User with their roles and tenants |
69
+ | `TenantWithShopAndApiKey` | Created tenant with shop and API key |
70
+ | `ImportResult` | `{ created: number; updated: number; errors: string[] }` |
71
+ | `DeleteDataResult` | `{ deletedSkus: number; deletedSalesHistory: number }` |
75
72
 
76
- #### Marketplaces
77
- - `getMarketplaces()`, `getMarketplace(id)`, `createMarketplace(dto)`, `updateMarketplace(id, dto)`, `deleteMarketplace(id)`
73
+ ## Related Packages
78
74
 
79
- ### Types
80
-
81
- All entity types, DTOs, and response types are exported:
82
-
83
- ```typescript
84
- import type {
85
- User, Tenant, Shop, Sku, SalesHistory,
86
- CreateUserDto, CreateTenantDto, CreateShopDto,
87
- ShopContextParams, PeriodQuery,
88
- UserWithRolesAndTenants, ImportResult
89
- } from '@sales-planner/shared';
90
- ```
91
-
92
- ### Error Handling
93
-
94
- ```typescript
95
- import { SalesPlannerClient, ApiError } from '@sales-planner/shared';
96
-
97
- try {
98
- const user = await client.getUser(999);
99
- } catch (error) {
100
- if (error instanceof ApiError) {
101
- console.log(error.status); // 404
102
- console.log(error.message); // "User not found"
103
- }
104
- }
105
- ```
75
+ - `@sales-planner/http-client` - HTTP client for the API (includes this package)
106
76
 
107
77
  ## License
108
78
 
package/dist/index.d.ts CHANGED
@@ -2,5 +2,4 @@ export * from './entities.js';
2
2
  export * from './dto.js';
3
3
  export * from './responses.js';
4
4
  export * from './query.js';
5
- export { SalesPlannerClient, ApiError, type ClientConfig } from './client.js';
6
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,eAAe,CAAC;AAG9B,cAAc,UAAU,CAAC;AAGzB,cAAc,gBAAgB,CAAC;AAG/B,cAAc,YAAY,CAAC;AAG3B,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,eAAe,CAAC;AAG9B,cAAc,UAAU,CAAC;AAGzB,cAAc,gBAAgB,CAAC;AAG/B,cAAc,YAAY,CAAC"}
package/dist/index.js CHANGED
@@ -6,5 +6,3 @@ export * from './dto.js';
6
6
  export * from './responses.js';
7
7
  // Query types
8
8
  export * from './query.js';
9
- // Client
10
- export { SalesPlannerClient, ApiError } from './client.js';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sales-planner/shared",
3
- "version": "0.2.0",
4
- "description": "Shared types and HTTP client for Sales Planner API",
3
+ "version": "0.3.1",
4
+ "description": "Shared types and DTOs for Sales Planner API",
5
5
  "author": "Damir Manapov",
6
6
  "license": "MIT",
7
7
  "keywords": [
package/dist/client.d.ts DELETED
@@ -1,77 +0,0 @@
1
- import type { ApiKey, Marketplace, Role, SalesHistory, Shop, Sku, Tenant, User } from './entities.js';
2
- import type { CreateApiKeyDto, CreateMarketplaceDto, CreateRoleDto, CreateSalesHistoryDto, CreateShopDto, CreateSkuDto, CreateTenantDto, CreateTenantWithShopDto, CreateUserDto, CreateUserRoleDto, ImportSalesHistoryItem, ImportSkuItem, UpdateSalesHistoryDto, UpdateSkuDto } from './dto.js';
3
- import type { DeleteDataResult, ImportResult, SalesHistoryExportItem, SkuExportItem, TenantWithShopAndApiKey, UserWithRolesAndTenants } from './responses.js';
4
- import type { PeriodQuery, ShopContextParams } from './query.js';
5
- export interface ClientConfig {
6
- baseUrl: string;
7
- apiKey: string;
8
- }
9
- export declare class SalesPlannerClient {
10
- private baseUrl;
11
- private apiKey;
12
- constructor(config: ClientConfig);
13
- private request;
14
- private requestText;
15
- private uploadCsv;
16
- private requestPublic;
17
- private requestTextPublic;
18
- getMe(): Promise<UserWithRolesAndTenants>;
19
- getUsers(): Promise<User[]>;
20
- getUser(id: number): Promise<User>;
21
- createUser(dto: CreateUserDto): Promise<User>;
22
- deleteUser(id: number): Promise<void>;
23
- getTenants(): Promise<Tenant[]>;
24
- getTenant(id: number): Promise<Tenant>;
25
- createTenant(dto: CreateTenantDto): Promise<Tenant>;
26
- createTenantWithShopAndUser(dto: CreateTenantWithShopDto): Promise<TenantWithShopAndApiKey>;
27
- updateTenant(id: number, dto: Partial<CreateTenantDto>): Promise<Tenant>;
28
- deleteTenant(id: number): Promise<void>;
29
- getShops(tenantId?: number): Promise<Shop[]>;
30
- getShop(id: number): Promise<Shop>;
31
- createShop(dto: CreateShopDto): Promise<Shop>;
32
- updateShop(id: number, dto: Partial<CreateShopDto>): Promise<Shop>;
33
- deleteShop(id: number): Promise<void>;
34
- deleteShopData(id: number): Promise<DeleteDataResult>;
35
- getSkus(ctx: ShopContextParams): Promise<Sku[]>;
36
- getSku(id: number, ctx: ShopContextParams): Promise<Sku>;
37
- createSku(dto: Omit<CreateSkuDto, 'shop_id' | 'tenant_id'>, ctx: ShopContextParams): Promise<Sku>;
38
- updateSku(id: number, dto: UpdateSkuDto, ctx: ShopContextParams): Promise<Sku>;
39
- deleteSku(id: number, ctx: ShopContextParams): Promise<void>;
40
- importSkusJson(items: ImportSkuItem[], ctx: ShopContextParams): Promise<ImportResult>;
41
- importSkusCsv(csvContent: string, ctx: ShopContextParams): Promise<ImportResult>;
42
- exportSkusJson(ctx: ShopContextParams): Promise<SkuExportItem[]>;
43
- exportSkusCsv(ctx: ShopContextParams): Promise<string>;
44
- getSkusExampleJson(): Promise<ImportSkuItem[]>;
45
- getSkusExampleCsv(): Promise<string>;
46
- getSalesHistory(ctx: ShopContextParams, query?: PeriodQuery): Promise<SalesHistory[]>;
47
- getSalesHistoryItem(id: number, ctx: ShopContextParams): Promise<SalesHistory>;
48
- createSalesHistory(dto: Omit<CreateSalesHistoryDto, 'shop_id' | 'tenant_id'>, ctx: ShopContextParams): Promise<SalesHistory>;
49
- updateSalesHistory(id: number, dto: UpdateSalesHistoryDto, ctx: ShopContextParams): Promise<SalesHistory>;
50
- deleteSalesHistory(id: number, ctx: ShopContextParams): Promise<void>;
51
- importSalesHistoryJson(items: ImportSalesHistoryItem[], ctx: ShopContextParams): Promise<ImportResult>;
52
- importSalesHistoryCsv(csvContent: string, ctx: ShopContextParams): Promise<ImportResult>;
53
- exportSalesHistoryJson(ctx: ShopContextParams, query?: PeriodQuery): Promise<SalesHistoryExportItem[]>;
54
- exportSalesHistoryCsv(ctx: ShopContextParams, query?: PeriodQuery): Promise<string>;
55
- getSalesHistoryExampleJson(): Promise<ImportSalesHistoryItem[]>;
56
- getSalesHistoryExampleCsv(): Promise<string>;
57
- getRoles(): Promise<Role[]>;
58
- getRole(id: number): Promise<Role>;
59
- createRole(dto: CreateRoleDto): Promise<Role>;
60
- updateRole(id: number, dto: Partial<CreateRoleDto>): Promise<Role>;
61
- deleteRole(id: number): Promise<void>;
62
- createUserRole(dto: CreateUserRoleDto): Promise<void>;
63
- deleteUserRole(id: number): Promise<void>;
64
- getApiKeys(): Promise<ApiKey[]>;
65
- createApiKey(dto: CreateApiKeyDto): Promise<ApiKey>;
66
- deleteApiKey(id: number): Promise<void>;
67
- getMarketplaces(): Promise<Marketplace[]>;
68
- getMarketplace(id: string): Promise<Marketplace>;
69
- createMarketplace(dto: CreateMarketplaceDto): Promise<Marketplace>;
70
- updateMarketplace(id: string, dto: Partial<CreateMarketplaceDto>): Promise<Marketplace>;
71
- deleteMarketplace(id: string): Promise<void>;
72
- }
73
- export declare class ApiError extends Error {
74
- status: number;
75
- constructor(status: number, message: string);
76
- }
77
- //# sourceMappingURL=client.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,MAAM,EACN,WAAW,EACX,IAAI,EACJ,YAAY,EACZ,IAAI,EACJ,GAAG,EACH,MAAM,EACN,IAAI,EACL,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EACV,eAAe,EACf,oBAAoB,EACpB,aAAa,EACb,qBAAqB,EACrB,aAAa,EACb,YAAY,EACZ,eAAe,EACf,uBAAuB,EACvB,aAAa,EACb,iBAAiB,EACjB,sBAAsB,EACtB,aAAa,EACb,qBAAqB,EACrB,YAAY,EACb,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EACV,gBAAgB,EAChB,YAAY,EACZ,sBAAsB,EACtB,aAAa,EACb,uBAAuB,EACvB,uBAAuB,EACxB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEjE,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,MAAM,CAAS;gBAEX,MAAM,EAAE,YAAY;YAKlB,OAAO;YAuCP,WAAW;YAgCX,SAAS;YAiCT,aAAa;YAkBb,iBAAiB;IAiBzB,KAAK,IAAI,OAAO,CAAC,uBAAuB,CAAC;IAQzC,QAAQ,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;IAI3B,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlC,UAAU,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC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C,eAAe,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;IAIzC,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAIhD,iBAAiB,CAAC,GAAG,EAAE,oBAAoB,GAAG,OAAO,CAAC,WAAW,CAAC;IAIlE,iBAAiB,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,CAAC,oBAAoB,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC;IAIvF,iBAAiB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAGnD;AAED,qBAAa,QAAS,SAAQ,KAAK;IAExB,MAAM,EAAE,MAAM;gBAAd,MAAM,EAAE,MAAM,EACrB,OAAO,EAAE,MAAM;CAKlB"}
package/dist/client.js DELETED
@@ -1,301 +0,0 @@
1
- export class SalesPlannerClient {
2
- baseUrl;
3
- apiKey;
4
- constructor(config) {
5
- this.baseUrl = config.baseUrl.replace(/\/$/, '');
6
- this.apiKey = config.apiKey;
7
- }
8
- async request(method, path, options) {
9
- const url = new URL(this.baseUrl + path);
10
- if (options?.params) {
11
- for (const [key, value] of Object.entries(options.params)) {
12
- if (value !== undefined) {
13
- url.searchParams.set(key, String(value));
14
- }
15
- }
16
- }
17
- const response = await fetch(url.toString(), {
18
- method,
19
- headers: {
20
- 'Content-Type': 'application/json',
21
- 'X-API-Key': this.apiKey,
22
- },
23
- body: options?.body ? JSON.stringify(options.body) : undefined,
24
- });
25
- if (!response.ok) {
26
- const error = await response.json().catch(() => ({ message: response.statusText }));
27
- throw new ApiError(response.status, error.message || 'Request failed');
28
- }
29
- if (response.status === 204) {
30
- return undefined;
31
- }
32
- return response.json();
33
- }
34
- async requestText(method, path, options) {
35
- const url = new URL(this.baseUrl + path);
36
- if (options?.params) {
37
- for (const [key, value] of Object.entries(options.params)) {
38
- if (value !== undefined) {
39
- url.searchParams.set(key, String(value));
40
- }
41
- }
42
- }
43
- const response = await fetch(url.toString(), {
44
- method,
45
- headers: {
46
- 'X-API-Key': this.apiKey,
47
- },
48
- });
49
- if (!response.ok) {
50
- const error = await response.json().catch(() => ({ message: response.statusText }));
51
- throw new ApiError(response.status, error.message || 'Request failed');
52
- }
53
- return response.text();
54
- }
55
- async uploadCsv(path, csvContent, params) {
56
- const url = new URL(this.baseUrl + path);
57
- for (const [key, value] of Object.entries(params)) {
58
- if (value !== undefined) {
59
- url.searchParams.set(key, String(value));
60
- }
61
- }
62
- const formData = new FormData();
63
- const blob = new Blob([csvContent], { type: 'text/csv' });
64
- formData.append('file', blob, 'upload.csv');
65
- const response = await fetch(url.toString(), {
66
- method: 'POST',
67
- headers: {
68
- 'X-API-Key': this.apiKey,
69
- },
70
- body: formData,
71
- });
72
- if (!response.ok) {
73
- const error = await response.json().catch(() => ({ message: response.statusText }));
74
- throw new ApiError(response.status, error.message || 'Request failed');
75
- }
76
- return response.json();
77
- }
78
- async requestPublic(method, path) {
79
- const url = new URL(this.baseUrl + path);
80
- const response = await fetch(url.toString(), {
81
- method,
82
- headers: {
83
- 'Content-Type': 'application/json',
84
- },
85
- });
86
- if (!response.ok) {
87
- const error = await response.json().catch(() => ({ message: response.statusText }));
88
- throw new ApiError(response.status, error.message || 'Request failed');
89
- }
90
- return response.json();
91
- }
92
- async requestTextPublic(method, path) {
93
- const url = new URL(this.baseUrl + path);
94
- const response = await fetch(url.toString(), { method });
95
- if (!response.ok) {
96
- const error = await response.json().catch(() => ({ message: response.statusText }));
97
- throw new ApiError(response.status, error.message || 'Request failed');
98
- }
99
- return response.text();
100
- }
101
- // ============================================================
102
- // Me
103
- // ============================================================
104
- async getMe() {
105
- return this.request('GET', '/me');
106
- }
107
- // ============================================================
108
- // Users
109
- // ============================================================
110
- async getUsers() {
111
- return this.request('GET', '/users');
112
- }
113
- async getUser(id) {
114
- return this.request('GET', `/users/${id}`);
115
- }
116
- async createUser(dto) {
117
- return this.request('POST', '/users', { body: dto });
118
- }
119
- async deleteUser(id) {
120
- return this.request('DELETE', `/users/${id}`);
121
- }
122
- // ============================================================
123
- // Tenants
124
- // ============================================================
125
- async getTenants() {
126
- return this.request('GET', '/tenants');
127
- }
128
- async getTenant(id) {
129
- return this.request('GET', `/tenants/${id}`);
130
- }
131
- async createTenant(dto) {
132
- return this.request('POST', '/tenants', { body: dto });
133
- }
134
- async createTenantWithShopAndUser(dto) {
135
- return this.request('POST', '/tenants/with-shop-and-user', { body: dto });
136
- }
137
- async updateTenant(id, dto) {
138
- return this.request('PUT', `/tenants/${id}`, { body: dto });
139
- }
140
- async deleteTenant(id) {
141
- return this.request('DELETE', `/tenants/${id}`);
142
- }
143
- // ============================================================
144
- // Shops
145
- // ============================================================
146
- async getShops(tenantId) {
147
- return this.request('GET', '/shops', { params: { tenantId } });
148
- }
149
- async getShop(id) {
150
- return this.request('GET', `/shops/${id}`);
151
- }
152
- async createShop(dto) {
153
- return this.request('POST', '/shops', { body: dto });
154
- }
155
- async updateShop(id, dto) {
156
- return this.request('PUT', `/shops/${id}`, { body: dto });
157
- }
158
- async deleteShop(id) {
159
- return this.request('DELETE', `/shops/${id}`);
160
- }
161
- async deleteShopData(id) {
162
- return this.request('DELETE', `/shops/${id}/data`);
163
- }
164
- // ============================================================
165
- // SKUs
166
- // ============================================================
167
- async getSkus(ctx) {
168
- return this.request('GET', '/skus', { params: ctx });
169
- }
170
- async getSku(id, ctx) {
171
- return this.request('GET', `/skus/${id}`, { params: ctx });
172
- }
173
- async createSku(dto, ctx) {
174
- return this.request('POST', '/skus', { body: dto, params: ctx });
175
- }
176
- async updateSku(id, dto, ctx) {
177
- return this.request('PUT', `/skus/${id}`, { body: dto, params: ctx });
178
- }
179
- async deleteSku(id, ctx) {
180
- return this.request('DELETE', `/skus/${id}`, { params: ctx });
181
- }
182
- async importSkusJson(items, ctx) {
183
- return this.request('POST', '/skus/import/json', { body: items, params: ctx });
184
- }
185
- async importSkusCsv(csvContent, ctx) {
186
- return this.uploadCsv('/skus/import/csv', csvContent, ctx);
187
- }
188
- async exportSkusJson(ctx) {
189
- return this.request('GET', '/skus/export/json', { params: ctx });
190
- }
191
- async exportSkusCsv(ctx) {
192
- return this.requestText('GET', '/skus/export/csv', { params: ctx });
193
- }
194
- async getSkusExampleJson() {
195
- return this.requestPublic('GET', '/skus/examples/json');
196
- }
197
- async getSkusExampleCsv() {
198
- return this.requestTextPublic('GET', '/skus/examples/csv');
199
- }
200
- // ============================================================
201
- // Sales History
202
- // ============================================================
203
- async getSalesHistory(ctx, query) {
204
- return this.request('GET', '/sales-history', { params: { ...ctx, ...query } });
205
- }
206
- async getSalesHistoryItem(id, ctx) {
207
- return this.request('GET', `/sales-history/${id}`, { params: ctx });
208
- }
209
- async createSalesHistory(dto, ctx) {
210
- return this.request('POST', '/sales-history', { body: dto, params: ctx });
211
- }
212
- async updateSalesHistory(id, dto, ctx) {
213
- return this.request('PUT', `/sales-history/${id}`, { body: dto, params: ctx });
214
- }
215
- async deleteSalesHistory(id, ctx) {
216
- return this.request('DELETE', `/sales-history/${id}`, { params: ctx });
217
- }
218
- async importSalesHistoryJson(items, ctx) {
219
- return this.request('POST', '/sales-history/import/json', { body: items, params: ctx });
220
- }
221
- async importSalesHistoryCsv(csvContent, ctx) {
222
- return this.uploadCsv('/sales-history/import/csv', csvContent, ctx);
223
- }
224
- async exportSalesHistoryJson(ctx, query) {
225
- return this.request('GET', '/sales-history/export/json', { params: { ...ctx, ...query } });
226
- }
227
- async exportSalesHistoryCsv(ctx, query) {
228
- return this.requestText('GET', '/sales-history/export/csv', { params: { ...ctx, ...query } });
229
- }
230
- async getSalesHistoryExampleJson() {
231
- return this.requestPublic('GET', '/sales-history/examples/json');
232
- }
233
- async getSalesHistoryExampleCsv() {
234
- return this.requestTextPublic('GET', '/sales-history/examples/csv');
235
- }
236
- // ============================================================
237
- // Roles
238
- // ============================================================
239
- async getRoles() {
240
- return this.request('GET', '/roles');
241
- }
242
- async getRole(id) {
243
- return this.request('GET', `/roles/${id}`);
244
- }
245
- async createRole(dto) {
246
- return this.request('POST', '/roles', { body: dto });
247
- }
248
- async updateRole(id, dto) {
249
- return this.request('PUT', `/roles/${id}`, { body: dto });
250
- }
251
- async deleteRole(id) {
252
- return this.request('DELETE', `/roles/${id}`);
253
- }
254
- // ============================================================
255
- // User Roles
256
- // ============================================================
257
- async createUserRole(dto) {
258
- return this.request('POST', '/user-roles', { body: dto });
259
- }
260
- async deleteUserRole(id) {
261
- return this.request('DELETE', `/user-roles/${id}`);
262
- }
263
- // ============================================================
264
- // API Keys
265
- // ============================================================
266
- async getApiKeys() {
267
- return this.request('GET', '/api-keys');
268
- }
269
- async createApiKey(dto) {
270
- return this.request('POST', '/api-keys', { body: dto });
271
- }
272
- async deleteApiKey(id) {
273
- return this.request('DELETE', `/api-keys/${id}`);
274
- }
275
- // ============================================================
276
- // Marketplaces
277
- // ============================================================
278
- async getMarketplaces() {
279
- return this.request('GET', '/marketplaces');
280
- }
281
- async getMarketplace(id) {
282
- return this.request('GET', `/marketplaces/${id}`);
283
- }
284
- async createMarketplace(dto) {
285
- return this.request('POST', '/marketplaces', { body: dto });
286
- }
287
- async updateMarketplace(id, dto) {
288
- return this.request('PUT', `/marketplaces/${id}`, { body: dto });
289
- }
290
- async deleteMarketplace(id) {
291
- return this.request('DELETE', `/marketplaces/${id}`);
292
- }
293
- }
294
- export class ApiError extends Error {
295
- status;
296
- constructor(status, message) {
297
- super(message);
298
- this.status = status;
299
- this.name = 'ApiError';
300
- }
301
- }