@mudrichenkoevgeny/shared-foundation 0.0.46 → 0.0.47
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 +65 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# @mudrichenkoevgeny/shared-foundation
|
|
2
|
+
|
|
3
|
+
TypeScript & Zod contracts, API routes, error codes, permission models, and branded types generated directly from the [shared-foundation](https://github.com/mudrichenkoevgeny/shared-foundation) Kotlin Multiplatform (KMP) repository.
|
|
4
|
+
|
|
5
|
+
Provides a single source of truth (SSOT) between Kotlin Backend/KMP services and TypeScript/React web applications.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# pnpm
|
|
11
|
+
pnpm add @mudrichenkoevgeny/shared-foundation zod
|
|
12
|
+
|
|
13
|
+
# npm
|
|
14
|
+
npm install @mudrichenkoevgeny/shared-foundation zod
|
|
15
|
+
|
|
16
|
+
# yarn
|
|
17
|
+
yarn add @mudrichenkoevgeny/shared-foundation zod
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Features
|
|
21
|
+
|
|
22
|
+
- **Zod Schemas**: Auto-generated `z.ZodType` validation schemas for all Request payloads and Response DTOs (`loginByEmailRequestSchema`, `apiErrorResponseSchema`, `userDetailsPayloadSchema`).
|
|
23
|
+
- **Route Constants**: Strongly typed API endpoint routes (`ManagementSecuritySettingsRoutes`, `OpenLoginRoutes`, `SelfManagementUserRoutes`).
|
|
24
|
+
- **Error & Permission Codes**: Literal string definitions for all application error codes (`SecurityErrorCodes`, `CommonErrorCodes`) and permission strings (`SecurityPermissionCode`, `UserPermissionCode`).
|
|
25
|
+
- **Branded Types & Helpers**: Type-safe domain identifiers (`UserId`, `PermissionCode`, `UserSessionId`, `UserIdentifierId`, `AuditEventId`, `ClientDeviceId`) with converter helpers (`toUserIdOrThrow`, `toPermissionCodeOrNull`).
|
|
26
|
+
|
|
27
|
+
## Quick Usage Example
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
import {
|
|
31
|
+
ManagementSecuritySettingsRoutes,
|
|
32
|
+
SecurityErrorCodes,
|
|
33
|
+
apiErrorResponseSchema,
|
|
34
|
+
toUserIdOrThrow
|
|
35
|
+
} from '@mudrichenkoevgeny/shared-foundation';
|
|
36
|
+
|
|
37
|
+
// 1. Using Route Constants
|
|
38
|
+
const url = ManagementSecuritySettingsRoutes.GET_MANAGEMENT_SECURITY_SETTINGS;
|
|
39
|
+
|
|
40
|
+
// 2. Branded Types
|
|
41
|
+
const userId = toUserIdOrThrow('123e4567-e89b-12d3-a456-426614174000');
|
|
42
|
+
|
|
43
|
+
// 3. Validating API Responses with Zod
|
|
44
|
+
async function fetchUserSettings() {
|
|
45
|
+
const response = await fetch(url);
|
|
46
|
+
const json = await response.json();
|
|
47
|
+
|
|
48
|
+
if (!response.ok) {
|
|
49
|
+
const error = apiErrorResponseSchema.parse(json);
|
|
50
|
+
if (error.code === SecurityErrorCodes.TOTP_NOT_ENABLED) {
|
|
51
|
+
console.error('TOTP configuration required');
|
|
52
|
+
}
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Source Code & Repository
|
|
59
|
+
|
|
60
|
+
The source code for this library and generator is maintained in the main GitHub repository:
|
|
61
|
+
**[GitHub Repository: mudrichenkoevgeny/shared-foundation](https://github.com/mudrichenkoevgeny/shared-foundation)**
|
|
62
|
+
|
|
63
|
+
## License
|
|
64
|
+
|
|
65
|
+
Apache License 2.0. See [LICENSE](https://github.com/mudrichenkoevgeny/shared-foundation/blob/main/LICENSE) for details.
|