@sales-planner/shared 0.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/README.md ADDED
@@ -0,0 +1,103 @@
1
+ # @sales-planner/shared
2
+
3
+ Shared TypeScript types for the Sales Planner platform.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add @sales-planner/shared
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import type {
15
+ User,
16
+ Tenant,
17
+ Shop,
18
+ Sku,
19
+ SalesHistory,
20
+ CreateUserDto,
21
+ CreateTenantDto,
22
+ UserWithRolesAndTenants,
23
+ } from '@sales-planner/shared';
24
+ ```
25
+
26
+ ## Types
27
+
28
+ ### Entities
29
+
30
+ Core database entities:
31
+
32
+ | Type | Description |
33
+ |------|-------------|
34
+ | `User` | User account |
35
+ | `Tenant` | Tenant (organization) |
36
+ | `Shop` | Shop within a tenant |
37
+ | `Sku` | SKU (product) in a shop |
38
+ | `SalesHistory` | Monthly sales data for a SKU |
39
+ | `Role` | Role definition (viewer, editor, etc.) |
40
+ | `ApiKey` | API key for authentication |
41
+ | `Marketplace` | Marketplace reference |
42
+
43
+ ### DTOs (Data Transfer Objects)
44
+
45
+ Request payloads for creating/updating entities:
46
+
47
+ | Type | Description |
48
+ |------|-------------|
49
+ | `CreateUserDto` | Create a new user |
50
+ | `CreateTenantDto` | Create a new tenant |
51
+ | `CreateTenantWithShopDto` | Create tenant with shop and API key |
52
+ | `CreateShopDto` | Create a new shop |
53
+ | `CreateSkuDto` | Create a new SKU |
54
+ | `UpdateSkuDto` | Update a SKU |
55
+ | `CreateSalesHistoryDto` | Create sales history entry |
56
+ | `UpdateSalesHistoryDto` | Update sales history |
57
+ | `CreateRoleDto` | Create a new role |
58
+ | `CreateApiKeyDto` | Create a new API key |
59
+ | `CreateUserRoleDto` | Assign role to user |
60
+ | `ImportSkuItem` | SKU item for bulk import |
61
+ | `ImportSalesHistoryItem` | Sales history item for bulk import |
62
+
63
+ ### Response Types
64
+
65
+ API response structures:
66
+
67
+ | Type | Description |
68
+ |------|-------------|
69
+ | `UserWithRolesAndTenants` | User with their roles and tenant access |
70
+ | `UserRole` | Role assignment with role details |
71
+ | `TenantInfo` | Tenant info with shops |
72
+ | `ShopInfo` | Shop info with user's role |
73
+ | `TenantWithShopAndApiKey` | Result of tenant creation with shop |
74
+ | `ImportResult` | Bulk import result (created/updated counts) |
75
+ | `DeleteDataResult` | Data deletion result |
76
+ | `SkuExportItem` | SKU export format |
77
+ | `SalesHistoryExportItem` | Sales history export format |
78
+
79
+ ### Query Types
80
+
81
+ Request parameters:
82
+
83
+ | Type | Description |
84
+ |------|-------------|
85
+ | `ShopContextParams` | Shop context (`tenant_id`, `shop_id`) |
86
+ | `PeriodQuery` | Period filter (`periodFrom`, `periodTo`) |
87
+
88
+ ## Package Structure
89
+
90
+ ```
91
+ src/
92
+ ├── entities.ts # Core entity types
93
+ ├── dto.ts # Data transfer objects
94
+ ├── responses.ts # API response types
95
+ ├── query.ts # Query parameter types
96
+ └── index.ts # Re-exports all types
97
+ ```
98
+
99
+ ## Design Principles
100
+
101
+ - **Types only** - No runtime code, fully tree-shakeable
102
+ - **Single source of truth** - Used by both API and client packages
103
+ - **ESM** - Native ES modules with `.js` extensions
package/dist/dto.d.ts ADDED
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Data Transfer Objects for create/update operations
3
+ */
4
+ export interface CreateUserDto {
5
+ email: string;
6
+ name: string;
7
+ default_shop_id?: number;
8
+ }
9
+ export interface CreateTenantDto {
10
+ title: string;
11
+ owner_id?: number;
12
+ }
13
+ export interface CreateTenantWithShopDto {
14
+ tenantTitle: string;
15
+ shopTitle?: string;
16
+ userEmail: string;
17
+ userName: string;
18
+ }
19
+ export interface CreateShopDto {
20
+ title: string;
21
+ tenant_id: number;
22
+ }
23
+ export interface CreateSkuDto {
24
+ code: string;
25
+ title: string;
26
+ shop_id: number;
27
+ tenant_id: number;
28
+ }
29
+ export interface UpdateSkuDto {
30
+ code?: string;
31
+ title?: string;
32
+ }
33
+ export interface ImportSkuItem {
34
+ code: string;
35
+ title: string;
36
+ }
37
+ export interface CreateSalesHistoryDto {
38
+ sku_id: number;
39
+ shop_id: number;
40
+ tenant_id: number;
41
+ period: string;
42
+ quantity: number;
43
+ }
44
+ export interface UpdateSalesHistoryDto {
45
+ quantity?: number;
46
+ }
47
+ export interface ImportSalesHistoryItem {
48
+ sku_code: string;
49
+ period: string;
50
+ quantity: number;
51
+ }
52
+ export interface CreateApiKeyDto {
53
+ user_id: number;
54
+ key?: string;
55
+ name?: string;
56
+ expires_at?: string;
57
+ }
58
+ export interface CreateRoleDto {
59
+ name: string;
60
+ description?: string;
61
+ }
62
+ export interface CreateUserRoleDto {
63
+ user_id: number;
64
+ role_id: number;
65
+ tenant_id?: number;
66
+ shop_id?: number;
67
+ }
68
+ //# sourceMappingURL=dto.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dto.d.ts","sourceRoot":"","sources":["../src/dto.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,uBAAuB;IACtC,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB"}
package/dist/dto.js ADDED
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Data Transfer Objects for create/update operations
3
+ */
4
+ export {};
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Core database entities
3
+ */
4
+ export interface User {
5
+ id: number;
6
+ email: string;
7
+ name: string;
8
+ default_shop_id: number | null;
9
+ created_at: Date;
10
+ updated_at: Date;
11
+ }
12
+ export interface Tenant {
13
+ id: number;
14
+ title: string;
15
+ owner_id: number | null;
16
+ created_by: number;
17
+ created_at: Date;
18
+ updated_at: Date;
19
+ }
20
+ export interface Shop {
21
+ id: number;
22
+ title: string;
23
+ tenant_id: number;
24
+ created_at: Date;
25
+ updated_at: Date;
26
+ }
27
+ export interface Sku {
28
+ id: number;
29
+ code: string;
30
+ title: string;
31
+ shop_id: number;
32
+ tenant_id: number;
33
+ created_at: Date;
34
+ updated_at: Date;
35
+ }
36
+ export interface SalesHistory {
37
+ id: number;
38
+ sku_id: number;
39
+ shop_id: number;
40
+ tenant_id: number;
41
+ period: string;
42
+ quantity: number;
43
+ created_at: Date;
44
+ updated_at: Date;
45
+ }
46
+ export interface Role {
47
+ id: number;
48
+ name: string;
49
+ description: string | null;
50
+ created_at: Date;
51
+ updated_at: Date;
52
+ }
53
+ export interface ApiKey {
54
+ id: number;
55
+ user_id: number;
56
+ key: string;
57
+ name: string | null;
58
+ expires_at: Date | null;
59
+ last_used_at: Date | null;
60
+ created_at: Date;
61
+ updated_at: Date;
62
+ }
63
+ export interface Marketplace {
64
+ id: string;
65
+ title: string;
66
+ created_at: Date;
67
+ updated_at: Date;
68
+ }
69
+ //# sourceMappingURL=entities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entities.d.ts","sourceRoot":"","sources":["../src/entities.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,IAAI;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,UAAU,EAAE,IAAI,CAAC;IACjB,UAAU,EAAE,IAAI,CAAC;CAClB;AAED,MAAM,WAAW,MAAM;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,E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C;IAC1B,UAAU,EAAE,IAAI,CAAC;IACjB,UAAU,EAAE,IAAI,CAAC;CAClB;AAED,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,IAAI,CAAC;IACjB,UAAU,EAAE,IAAI,CAAC;CAClB"}
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Core database entities
3
+ */
4
+ export {};
@@ -0,0 +1,5 @@
1
+ export * from './entities.js';
2
+ export * from './dto.js';
3
+ export * from './responses.js';
4
+ export * from './query.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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"}
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ // Entities
2
+ export * from './entities.js';
3
+ // DTOs
4
+ export * from './dto.js';
5
+ // Response types
6
+ export * from './responses.js';
7
+ // Query types
8
+ export * from './query.js';
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Query parameter types
3
+ */
4
+ export interface ShopContextParams {
5
+ shop_id: number;
6
+ tenant_id: number;
7
+ [key: string]: string | number | undefined;
8
+ }
9
+ export interface PeriodQuery {
10
+ period_from?: string;
11
+ period_to?: string;
12
+ }
13
+ //# sourceMappingURL=query.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;CAC5C;AAED,MAAM,WAAW,WAAW;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB"}
package/dist/query.js ADDED
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Query parameter types
3
+ */
4
+ export {};
@@ -0,0 +1,60 @@
1
+ /**
2
+ * API response types
3
+ */
4
+ import type { Tenant, User } from './entities.js';
5
+ export interface UserRole {
6
+ id: number;
7
+ role_name: string;
8
+ tenant_id: number | null;
9
+ tenant_title: string | null;
10
+ shop_id: number | null;
11
+ shop_title: string | null;
12
+ }
13
+ export interface ShopInfo {
14
+ id: number;
15
+ title: string;
16
+ }
17
+ export interface TenantInfo {
18
+ id: number;
19
+ title: string;
20
+ is_owner: boolean;
21
+ shops: ShopInfo[];
22
+ }
23
+ export interface UserWithRolesAndTenants extends User {
24
+ roles: UserRole[];
25
+ tenants: TenantInfo[];
26
+ }
27
+ export interface TenantWithShopAndApiKey {
28
+ tenant: Tenant;
29
+ shop: {
30
+ id: number;
31
+ title: string;
32
+ tenant_id: number;
33
+ };
34
+ user: {
35
+ id: number;
36
+ email: string;
37
+ name: string;
38
+ };
39
+ apiKey: string;
40
+ }
41
+ export interface ImportResult {
42
+ created: number;
43
+ updated: number;
44
+ skus_created?: number;
45
+ errors: string[];
46
+ }
47
+ export interface DeleteDataResult {
48
+ skusDeleted: number;
49
+ salesHistoryDeleted: number;
50
+ }
51
+ export interface SalesHistoryExportItem {
52
+ sku_code: string;
53
+ period: string;
54
+ quantity: number;
55
+ }
56
+ export interface SkuExportItem {
57
+ code: string;
58
+ title: string;
59
+ }
60
+ //# sourceMappingURL=responses.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"responses.d.ts","sourceRoot":"","sources":["../src/responses.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAElD,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,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AE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf"}
@@ -0,0 +1,4 @@
1
+ /**
2
+ * API response types
3
+ */
4
+ export {};
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@sales-planner/shared",
3
+ "version": "0.1.0",
4
+ "description": "Shared types and DTOs for Sales Planner API",
5
+ "author": "Damir Manapov",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "main": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "README.md"
19
+ ],
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "scripts": {
24
+ "build": "tsc",
25
+ "typecheck": "tsc --noEmit",
26
+ "prepublishOnly": "pnpm run build"
27
+ },
28
+ "devDependencies": {
29
+ "typescript": "^5.7.3"
30
+ }
31
+ }