@sales-planner/http-client 0.1.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
@@ -2,8 +2,6 @@
2
2
 
3
3
  Type-safe HTTP client for the Sales Planner API.
4
4
 
5
- > This package re-exports the client from `@sales-planner/shared`. You can use either package.
6
-
7
5
  ## Installation
8
6
 
9
7
  ```bash
@@ -0,0 +1,75 @@
1
+ import type { ApiKey, Marketplace, Role, SalesHistory, Shop, Sku, Tenant, User, CreateApiKeyDto, CreateMarketplaceDto, CreateRoleDto, CreateSalesHistoryDto, CreateShopDto, CreateSkuDto, CreateTenantDto, CreateTenantWithShopDto, CreateUserDto, CreateUserRoleDto, ImportSalesHistoryItem, ImportSkuItem, UpdateSalesHistoryDto, UpdateSkuDto, DeleteDataResult, ImportResult, SalesHistoryExportItem, SkuExportItem, TenantWithShopAndApiKey, UserWithRolesAndTenants, PeriodQuery, ShopContextParams } from '@sales-planner/shared';
2
+ export interface ClientConfig {
3
+ baseUrl: string;
4
+ apiKey: string;
5
+ }
6
+ export declare class SalesPlannerClient {
7
+ private baseUrl;
8
+ private apiKey;
9
+ constructor(config: ClientConfig);
10
+ private handleErrorResponse;
11
+ private request;
12
+ private requestText;
13
+ private uploadCsv;
14
+ private requestPublic;
15
+ private requestTextPublic;
16
+ getMe(): Promise<UserWithRolesAndTenants>;
17
+ getUsers(): Promise<User[]>;
18
+ getUser(id: number): Promise<User>;
19
+ createUser(dto: CreateUserDto): Promise<User>;
20
+ deleteUser(id: number): Promise<void>;
21
+ getTenants(): Promise<Tenant[]>;
22
+ getTenant(id: number): Promise<Tenant>;
23
+ createTenant(dto: CreateTenantDto): Promise<Tenant>;
24
+ createTenantWithShopAndUser(dto: CreateTenantWithShopDto): Promise<TenantWithShopAndApiKey>;
25
+ updateTenant(id: number, dto: Partial<CreateTenantDto>): Promise<Tenant>;
26
+ deleteTenant(id: number): Promise<void>;
27
+ getShops(tenantId?: number): Promise<Shop[]>;
28
+ getShop(id: number): Promise<Shop>;
29
+ createShop(dto: CreateShopDto): Promise<Shop>;
30
+ updateShop(id: number, dto: Partial<CreateShopDto>): Promise<Shop>;
31
+ deleteShop(id: number): Promise<void>;
32
+ deleteShopData(id: number): Promise<DeleteDataResult>;
33
+ getSkus(ctx: ShopContextParams): Promise<Sku[]>;
34
+ getSku(id: number, ctx: ShopContextParams): Promise<Sku>;
35
+ createSku(dto: Omit<CreateSkuDto, 'shop_id' | 'tenant_id'>, ctx: ShopContextParams): Promise<Sku>;
36
+ updateSku(id: number, dto: UpdateSkuDto, ctx: ShopContextParams): Promise<Sku>;
37
+ deleteSku(id: number, ctx: ShopContextParams): Promise<void>;
38
+ importSkusJson(items: ImportSkuItem[], ctx: ShopContextParams): Promise<ImportResult>;
39
+ importSkusCsv(csvContent: string, ctx: ShopContextParams): Promise<ImportResult>;
40
+ exportSkusJson(ctx: ShopContextParams): Promise<SkuExportItem[]>;
41
+ exportSkusCsv(ctx: ShopContextParams): Promise<string>;
42
+ getSkusExampleJson(): Promise<ImportSkuItem[]>;
43
+ getSkusExampleCsv(): Promise<string>;
44
+ getSalesHistory(ctx: ShopContextParams, query?: PeriodQuery): Promise<SalesHistory[]>;
45
+ getSalesHistoryItem(id: number, ctx: ShopContextParams): Promise<SalesHistory>;
46
+ createSalesHistory(dto: Omit<CreateSalesHistoryDto, 'shop_id' | 'tenant_id'>, ctx: ShopContextParams): Promise<SalesHistory>;
47
+ updateSalesHistory(id: number, dto: UpdateSalesHistoryDto, ctx: ShopContextParams): Promise<SalesHistory>;
48
+ deleteSalesHistory(id: number, ctx: ShopContextParams): Promise<void>;
49
+ importSalesHistoryJson(items: ImportSalesHistoryItem[], ctx: ShopContextParams): Promise<ImportResult>;
50
+ importSalesHistoryCsv(csvContent: string, ctx: ShopContextParams): Promise<ImportResult>;
51
+ exportSalesHistoryJson(ctx: ShopContextParams, query?: PeriodQuery): Promise<SalesHistoryExportItem[]>;
52
+ exportSalesHistoryCsv(ctx: ShopContextParams, query?: PeriodQuery): Promise<string>;
53
+ getSalesHistoryExampleJson(): Promise<ImportSalesHistoryItem[]>;
54
+ getSalesHistoryExampleCsv(): Promise<string>;
55
+ getRoles(): Promise<Role[]>;
56
+ getRole(id: number): Promise<Role>;
57
+ createRole(dto: CreateRoleDto): Promise<Role>;
58
+ updateRole(id: number, dto: Partial<CreateRoleDto>): Promise<Role>;
59
+ deleteRole(id: number): Promise<void>;
60
+ createUserRole(dto: CreateUserRoleDto): Promise<void>;
61
+ deleteUserRole(id: number): Promise<void>;
62
+ getApiKeys(): Promise<ApiKey[]>;
63
+ createApiKey(dto: CreateApiKeyDto): Promise<ApiKey>;
64
+ deleteApiKey(id: number): Promise<void>;
65
+ getMarketplaces(): Promise<Marketplace[]>;
66
+ getMarketplace(id: string): Promise<Marketplace>;
67
+ createMarketplace(dto: CreateMarketplaceDto): Promise<Marketplace>;
68
+ updateMarketplace(id: string, dto: Partial<CreateMarketplaceDto>): Promise<Marketplace>;
69
+ deleteMarketplace(id: string): Promise<void>;
70
+ }
71
+ export declare class ApiError extends Error {
72
+ status: number;
73
+ constructor(status: number, message: string);
74
+ }
75
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +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,EACJ,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,EACZ,gBAAgB,EAChB,YAAY,EACZ,sBAAsB,EACtB,aAAa,EACb,uBAAuB,EACvB,uBAAuB,EACvB,WAAW,EACX,iBAAiB,EA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,OAAO,CAAC,IAAI,CAAC;IAI7C,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlE,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,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 ADDED
@@ -0,0 +1,315 @@
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 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
+ }
22
+ async request(method, path, options) {
23
+ const url = new URL(this.baseUrl + path);
24
+ if (options?.params) {
25
+ for (const [key, value] of Object.entries(options.params)) {
26
+ if (value !== undefined) {
27
+ url.searchParams.set(key, String(value));
28
+ }
29
+ }
30
+ }
31
+ const response = await fetch(url.toString(), {
32
+ method,
33
+ headers: {
34
+ 'Content-Type': 'application/json',
35
+ 'X-API-Key': this.apiKey,
36
+ },
37
+ body: options?.body ? JSON.stringify(options.body) : undefined,
38
+ });
39
+ if (!response.ok) {
40
+ await this.handleErrorResponse(response);
41
+ }
42
+ if (response.status === 204) {
43
+ return undefined;
44
+ }
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);
51
+ }
52
+ async requestText(method, path, options) {
53
+ const url = new URL(this.baseUrl + path);
54
+ if (options?.params) {
55
+ for (const [key, value] of Object.entries(options.params)) {
56
+ if (value !== undefined) {
57
+ url.searchParams.set(key, String(value));
58
+ }
59
+ }
60
+ }
61
+ const response = await fetch(url.toString(), {
62
+ method,
63
+ headers: {
64
+ 'X-API-Key': this.apiKey,
65
+ },
66
+ });
67
+ if (!response.ok) {
68
+ await this.handleErrorResponse(response);
69
+ }
70
+ return response.text();
71
+ }
72
+ async uploadCsv(path, csvContent, params) {
73
+ const url = new URL(this.baseUrl + path);
74
+ for (const [key, value] of Object.entries(params)) {
75
+ if (value !== undefined) {
76
+ url.searchParams.set(key, String(value));
77
+ }
78
+ }
79
+ const formData = new FormData();
80
+ const blob = new Blob([csvContent], { type: 'text/csv' });
81
+ formData.append('file', blob, 'upload.csv');
82
+ const response = await fetch(url.toString(), {
83
+ method: 'POST',
84
+ headers: {
85
+ 'X-API-Key': this.apiKey,
86
+ },
87
+ body: formData,
88
+ });
89
+ if (!response.ok) {
90
+ await this.handleErrorResponse(response);
91
+ }
92
+ return response.json();
93
+ }
94
+ async requestPublic(method, path) {
95
+ const url = new URL(this.baseUrl + path);
96
+ const response = await fetch(url.toString(), {
97
+ method,
98
+ headers: {
99
+ 'Content-Type': 'application/json',
100
+ },
101
+ });
102
+ if (!response.ok) {
103
+ await this.handleErrorResponse(response);
104
+ }
105
+ return response.json();
106
+ }
107
+ async requestTextPublic(method, path) {
108
+ const url = new URL(this.baseUrl + path);
109
+ const response = await fetch(url.toString(), { method });
110
+ if (!response.ok) {
111
+ await this.handleErrorResponse(response);
112
+ }
113
+ return response.text();
114
+ }
115
+ // ============================================================
116
+ // Me
117
+ // ============================================================
118
+ async getMe() {
119
+ return this.request('GET', '/me');
120
+ }
121
+ // ============================================================
122
+ // Users
123
+ // ============================================================
124
+ async getUsers() {
125
+ return this.request('GET', '/users');
126
+ }
127
+ async getUser(id) {
128
+ return this.request('GET', `/users/${id}`);
129
+ }
130
+ async createUser(dto) {
131
+ return this.request('POST', '/users', { body: dto });
132
+ }
133
+ async deleteUser(id) {
134
+ return this.request('DELETE', `/users/${id}`);
135
+ }
136
+ // ============================================================
137
+ // Tenants
138
+ // ============================================================
139
+ async getTenants() {
140
+ return this.request('GET', '/tenants');
141
+ }
142
+ async getTenant(id) {
143
+ return this.request('GET', `/tenants/${id}`);
144
+ }
145
+ async createTenant(dto) {
146
+ return this.request('POST', '/tenants', { body: dto });
147
+ }
148
+ async createTenantWithShopAndUser(dto) {
149
+ return this.request('POST', '/tenants/with-shop-and-user', { body: dto });
150
+ }
151
+ async updateTenant(id, dto) {
152
+ return this.request('PUT', `/tenants/${id}`, { body: dto });
153
+ }
154
+ async deleteTenant(id) {
155
+ return this.request('DELETE', `/tenants/${id}`);
156
+ }
157
+ // ============================================================
158
+ // Shops
159
+ // ============================================================
160
+ async getShops(tenantId) {
161
+ return this.request('GET', '/shops', { params: { tenantId } });
162
+ }
163
+ async getShop(id) {
164
+ return this.request('GET', `/shops/${id}`);
165
+ }
166
+ async createShop(dto) {
167
+ return this.request('POST', '/shops', { body: dto });
168
+ }
169
+ async updateShop(id, dto) {
170
+ return this.request('PUT', `/shops/${id}`, { body: dto });
171
+ }
172
+ async deleteShop(id) {
173
+ return this.request('DELETE', `/shops/${id}`);
174
+ }
175
+ async deleteShopData(id) {
176
+ return this.request('DELETE', `/shops/${id}/data`);
177
+ }
178
+ // ============================================================
179
+ // SKUs
180
+ // ============================================================
181
+ async getSkus(ctx) {
182
+ return this.request('GET', '/skus', { params: ctx });
183
+ }
184
+ async getSku(id, ctx) {
185
+ return this.request('GET', `/skus/${id}`, { params: ctx });
186
+ }
187
+ async createSku(dto, ctx) {
188
+ return this.request('POST', '/skus', { body: dto, params: ctx });
189
+ }
190
+ async updateSku(id, dto, ctx) {
191
+ return this.request('PUT', `/skus/${id}`, { body: dto, params: ctx });
192
+ }
193
+ async deleteSku(id, ctx) {
194
+ return this.request('DELETE', `/skus/${id}`, { params: ctx });
195
+ }
196
+ async importSkusJson(items, ctx) {
197
+ return this.request('POST', '/skus/import/json', { body: items, params: ctx });
198
+ }
199
+ async importSkusCsv(csvContent, ctx) {
200
+ return this.uploadCsv('/skus/import/csv', csvContent, ctx);
201
+ }
202
+ async exportSkusJson(ctx) {
203
+ return this.request('GET', '/skus/export/json', { params: ctx });
204
+ }
205
+ async exportSkusCsv(ctx) {
206
+ return this.requestText('GET', '/skus/export/csv', { params: ctx });
207
+ }
208
+ async getSkusExampleJson() {
209
+ return this.requestPublic('GET', '/skus/examples/json');
210
+ }
211
+ async getSkusExampleCsv() {
212
+ return this.requestTextPublic('GET', '/skus/examples/csv');
213
+ }
214
+ // ============================================================
215
+ // Sales History
216
+ // ============================================================
217
+ async getSalesHistory(ctx, query) {
218
+ return this.request('GET', '/sales-history', { params: { ...ctx, ...query } });
219
+ }
220
+ async getSalesHistoryItem(id, ctx) {
221
+ return this.request('GET', `/sales-history/${id}`, { params: ctx });
222
+ }
223
+ async createSalesHistory(dto, ctx) {
224
+ return this.request('POST', '/sales-history', { body: dto, params: ctx });
225
+ }
226
+ async updateSalesHistory(id, dto, ctx) {
227
+ return this.request('PUT', `/sales-history/${id}`, { body: dto, params: ctx });
228
+ }
229
+ async deleteSalesHistory(id, ctx) {
230
+ return this.request('DELETE', `/sales-history/${id}`, { params: ctx });
231
+ }
232
+ async importSalesHistoryJson(items, ctx) {
233
+ return this.request('POST', '/sales-history/import/json', { body: items, params: ctx });
234
+ }
235
+ async importSalesHistoryCsv(csvContent, ctx) {
236
+ return this.uploadCsv('/sales-history/import/csv', csvContent, ctx);
237
+ }
238
+ async exportSalesHistoryJson(ctx, query) {
239
+ return this.request('GET', '/sales-history/export/json', { params: { ...ctx, ...query } });
240
+ }
241
+ async exportSalesHistoryCsv(ctx, query) {
242
+ return this.requestText('GET', '/sales-history/export/csv', { params: { ...ctx, ...query } });
243
+ }
244
+ async getSalesHistoryExampleJson() {
245
+ return this.requestPublic('GET', '/sales-history/examples/json');
246
+ }
247
+ async getSalesHistoryExampleCsv() {
248
+ return this.requestTextPublic('GET', '/sales-history/examples/csv');
249
+ }
250
+ // ============================================================
251
+ // Roles
252
+ // ============================================================
253
+ async getRoles() {
254
+ return this.request('GET', '/roles');
255
+ }
256
+ async getRole(id) {
257
+ return this.request('GET', `/roles/${id}`);
258
+ }
259
+ async createRole(dto) {
260
+ return this.request('POST', '/roles', { body: dto });
261
+ }
262
+ async updateRole(id, dto) {
263
+ return this.request('PUT', `/roles/${id}`, { body: dto });
264
+ }
265
+ async deleteRole(id) {
266
+ return this.request('DELETE', `/roles/${id}`);
267
+ }
268
+ // ============================================================
269
+ // User Roles
270
+ // ============================================================
271
+ async createUserRole(dto) {
272
+ return this.request('POST', '/user-roles', { body: dto });
273
+ }
274
+ async deleteUserRole(id) {
275
+ return this.request('DELETE', `/user-roles/${id}`);
276
+ }
277
+ // ============================================================
278
+ // API Keys
279
+ // ============================================================
280
+ async getApiKeys() {
281
+ return this.request('GET', '/api-keys');
282
+ }
283
+ async createApiKey(dto) {
284
+ return this.request('POST', '/api-keys', { body: dto });
285
+ }
286
+ async deleteApiKey(id) {
287
+ return this.request('DELETE', `/api-keys/${id}`);
288
+ }
289
+ // ============================================================
290
+ // Marketplaces
291
+ // ============================================================
292
+ async getMarketplaces() {
293
+ return this.request('GET', '/marketplaces');
294
+ }
295
+ async getMarketplace(id) {
296
+ return this.request('GET', `/marketplaces/${id}`);
297
+ }
298
+ async createMarketplace(dto) {
299
+ return this.request('POST', '/marketplaces', { body: dto });
300
+ }
301
+ async updateMarketplace(id, dto) {
302
+ return this.request('PUT', `/marketplaces/${id}`, { body: dto });
303
+ }
304
+ async deleteMarketplace(id) {
305
+ return this.request('DELETE', `/marketplaces/${id}`);
306
+ }
307
+ }
308
+ export class ApiError extends Error {
309
+ status;
310
+ constructor(status, message) {
311
+ super(message);
312
+ this.status = status;
313
+ this.name = 'ApiError';
314
+ }
315
+ }
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { SalesPlannerClient, ApiError } from '@sales-planner/shared';
2
- export type { ClientConfig } from '@sales-planner/shared';
1
+ export { SalesPlannerClient, ApiError } from './client.js';
2
+ export type { ClientConfig } from './client.js';
3
3
  export type { User, Tenant, Shop, Sku, SalesHistory, Role, UserRole, ApiKey, Marketplace, CreateUserDto, CreateTenantDto, CreateTenantWithShopDto, CreateShopDto, CreateSkuDto, UpdateSkuDto, ImportSkuItem, CreateSalesHistoryDto, UpdateSalesHistoryDto, ImportSalesHistoryItem, CreateApiKeyDto, CreateRoleDto, CreateUserRoleDto, CreateMarketplaceDto, ShopContextParams, PeriodQuery, UserWithRolesAndTenants, TenantWithShopAndApiKey, ImportResult, DeleteDataResult, SkuExportItem, SalesHistoryExportItem, } from '@sales-planner/shared';
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACrE,YAAY,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAG1D,YAAY,EAEV,IAAI,EACJ,MAAM,EACN,IAAI,EACJ,GAAG,EACH,YAAY,EACZ,IAAI,EACJ,QAAQ,EACR,MAAM,EACN,WAAW,EAEX,aAAa,EACb,eAAe,EACf,uBAAuB,EACvB,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,qBAAqB,EACrB,qBAAqB,EACrB,sBAAsB,EACtB,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,oBAAoB,EAEpB,iBAAiB,EACjB,WAAW,EAEX,uBAAuB,EACvB,uBAAuB,EACvB,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACb,sBAAsB,GACvB,MAAM,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC3D,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGhD,YAAY,EAEV,IAAI,EACJ,MAAM,EACN,IAAI,EACJ,GAAG,EACH,YAAY,EACZ,IAAI,EACJ,QAAQ,EACR,MAAM,EACN,WAAW,EAEX,aAAa,EACb,eAAe,EACf,uBAAuB,EACvB,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,qBAAqB,EACrB,qBAAqB,EACrB,sBAAsB,EACtB,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,oBAAoB,EAEpB,iBAAiB,EACjB,WAAW,EAEX,uBAAuB,EACvB,uBAAuB,EACvB,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACb,sBAAsB,GACvB,MAAM,uBAAuB,CAAC"}
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- // Re-export client and types from @sales-planner/shared
2
- export { SalesPlannerClient, ApiError } from '@sales-planner/shared';
1
+ // Client
2
+ export { SalesPlannerClient, ApiError } from './client.js';
package/package.json CHANGED
@@ -1,10 +1,15 @@
1
1
  {
2
2
  "name": "@sales-planner/http-client",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "HTTP client for Sales Planner API",
5
5
  "author": "Damir Manapov",
6
6
  "license": "MIT",
7
- "keywords": ["sales-planner", "api-client", "http-client", "typescript"],
7
+ "keywords": [
8
+ "sales-planner",
9
+ "api-client",
10
+ "http-client",
11
+ "typescript"
12
+ ],
8
13
  "type": "module",
9
14
  "main": "./dist/index.js",
10
15
  "types": "./dist/index.d.ts",
@@ -18,14 +23,14 @@
18
23
  "dist",
19
24
  "README.md"
20
25
  ],
21
- "scripts": {
22
- "build": "tsc",
23
- "typecheck": "tsc --noEmit"
24
- },
25
26
  "dependencies": {
26
- "@sales-planner/shared": "^0.2.0"
27
+ "@sales-planner/shared": "0.4.0"
27
28
  },
28
29
  "devDependencies": {
29
30
  "typescript": "^5.7.3"
31
+ },
32
+ "scripts": {
33
+ "build": "tsc",
34
+ "typecheck": "tsc --noEmit"
30
35
  }
31
- }
36
+ }