@sales-planner/shared 0.2.0 → 0.3.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 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/client.d.ts CHANGED
@@ -10,6 +10,7 @@ export declare class SalesPlannerClient {
10
10
  private baseUrl;
11
11
  private apiKey;
12
12
  constructor(config: ClientConfig);
13
+ private handleErrorResponse;
13
14
  private request;
14
15
  private requestText;
15
16
  private uploadCsv;
@@ -1 +1 @@
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,IAAI,CAA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AAG,OAAO,CAAC,IAAI,CAAC;IAQrC,cAAc,CAAC,GAAG,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAIrD,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQzC,UAAU,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAI/B,YAAY,CAAC,GAAG,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC;IAInD,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQvC,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 CHANGED
@@ -5,6 +5,20 @@ export class SalesPlannerClient {
5
5
  this.baseUrl = config.baseUrl.replace(/\/$/, '');
6
6
  this.apiKey = config.apiKey;
7
7
  }
8
+ async handleErrorResponse(response) {
9
+ const text = await response.text();
10
+ let message = response.statusText;
11
+ if (text) {
12
+ try {
13
+ const error = JSON.parse(text);
14
+ message = error.message || message;
15
+ }
16
+ catch {
17
+ message = text;
18
+ }
19
+ }
20
+ throw new ApiError(response.status, message || 'Request failed');
21
+ }
8
22
  async request(method, path, options) {
9
23
  const url = new URL(this.baseUrl + path);
10
24
  if (options?.params) {
@@ -23,13 +37,17 @@ export class SalesPlannerClient {
23
37
  body: options?.body ? JSON.stringify(options.body) : undefined,
24
38
  });
25
39
  if (!response.ok) {
26
- const error = await response.json().catch(() => ({ message: response.statusText }));
27
- throw new ApiError(response.status, error.message || 'Request failed');
40
+ await this.handleErrorResponse(response);
28
41
  }
29
42
  if (response.status === 204) {
30
43
  return undefined;
31
44
  }
32
- return response.json();
45
+ // Handle empty response body (e.g., void return type from NestJS)
46
+ const text = await response.text();
47
+ if (!text) {
48
+ return undefined;
49
+ }
50
+ return JSON.parse(text);
33
51
  }
34
52
  async requestText(method, path, options) {
35
53
  const url = new URL(this.baseUrl + path);
@@ -47,8 +65,7 @@ export class SalesPlannerClient {
47
65
  },
48
66
  });
49
67
  if (!response.ok) {
50
- const error = await response.json().catch(() => ({ message: response.statusText }));
51
- throw new ApiError(response.status, error.message || 'Request failed');
68
+ await this.handleErrorResponse(response);
52
69
  }
53
70
  return response.text();
54
71
  }
@@ -70,8 +87,7 @@ export class SalesPlannerClient {
70
87
  body: formData,
71
88
  });
72
89
  if (!response.ok) {
73
- const error = await response.json().catch(() => ({ message: response.statusText }));
74
- throw new ApiError(response.status, error.message || 'Request failed');
90
+ await this.handleErrorResponse(response);
75
91
  }
76
92
  return response.json();
77
93
  }
@@ -84,8 +100,7 @@ export class SalesPlannerClient {
84
100
  },
85
101
  });
86
102
  if (!response.ok) {
87
- const error = await response.json().catch(() => ({ message: response.statusText }));
88
- throw new ApiError(response.status, error.message || 'Request failed');
103
+ await this.handleErrorResponse(response);
89
104
  }
90
105
  return response.json();
91
106
  }
@@ -93,8 +108,7 @@ export class SalesPlannerClient {
93
108
  const url = new URL(this.baseUrl + path);
94
109
  const response = await fetch(url.toString(), { method });
95
110
  if (!response.ok) {
96
- const error = await response.json().catch(() => ({ message: response.statusText }));
97
- throw new ApiError(response.status, error.message || 'Request failed');
111
+ await this.handleErrorResponse(response);
98
112
  }
99
113
  return response.text();
100
114
  }
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.0",
4
+ "description": "Shared types and DTOs for Sales Planner API",
5
5
  "author": "Damir Manapov",
6
6
  "license": "MIT",
7
7
  "keywords": [