@mudrichenkoevgeny/shared-foundation 0.0.48 → 0.0.49
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 +37 -4
- package/index.d.ts +602 -32
- package/index.js +869 -1
- package/index.mjs +869 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -19,11 +19,44 @@ yarn add @mudrichenkoevgeny/shared-foundation zod
|
|
|
19
19
|
|
|
20
20
|
## Features
|
|
21
21
|
|
|
22
|
-
- **Zod Schemas**: Auto-generated `z.ZodType` validation schemas for all Request payloads and Response DTOs.
|
|
22
|
+
- **Zod Schemas**: Auto-generated `z.ZodType` validation schemas for all Request payloads and Response DTOs (`loginByEmailRequestSchema`, `apiErrorResponseSchema`, `userDetailsPayloadSchema`).
|
|
23
23
|
- **Runtime Enums**: TS types & runtime JS objects for all enums and string unions (`UserAuthProvider`, `UserRole`, `UserAccountStatus`, `AccountLockoutType`, `ClientType`, `SortOrder`, `UserSortValues`, etc.).
|
|
24
|
-
- **Route Constants**: Strongly typed API endpoint routes.
|
|
25
|
-
- **Error & Permission Codes**: Literal string definitions for all application error codes and permission strings.
|
|
26
|
-
- **Branded Types & Helpers**: Type-safe domain identifiers with converter helpers.
|
|
24
|
+
- **Route Constants**: Strongly typed API endpoint routes (`ManagementSecuritySettingsRoutes`, `OpenLoginRoutes`, `SelfManagementUserRoutes`).
|
|
25
|
+
- **Error & Permission Codes**: Literal string definitions for all application error codes (`SecurityErrorCodes`, `CommonErrorCodes`) and permission strings (`SecurityPermissionCode`, `UserPermissionCode`).
|
|
26
|
+
- **Branded Types & Helpers**: Type-safe domain identifiers (`UserId`, `PermissionCode`, `UserSessionId`, `UserIdentifierId`, `AuditEventId`, `ClientDeviceId`) with converter helpers (`toUserIdOrThrow`, `toPermissionCodeOrNull`).
|
|
27
|
+
- **Domain Models & Mappers**: Fully typed TS domain models (`UserSession`, `UserDetails`, `ClientDeviceInfo`) and their runtime mappers from/to API payloads (`toUserSession`, `toUserSessionPayload`).
|
|
28
|
+
- **Composite Parsers**: Helper classes for runtime parsing of polymorphic values (`CompositeAuditActionTypeParser`, `CompositeAuditMetadataKeyParser`, `CompositeAuditResourceTypeParser`).
|
|
29
|
+
|
|
30
|
+
## Quick Usage Example
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
import {
|
|
34
|
+
ManagementSecuritySettingsRoutes,
|
|
35
|
+
SecurityErrorCodes,
|
|
36
|
+
apiErrorResponseSchema,
|
|
37
|
+
toUserIdOrThrow
|
|
38
|
+
} from '@mudrichenkoevgeny/shared-foundation';
|
|
39
|
+
|
|
40
|
+
// 1. Using Route Constants
|
|
41
|
+
const url = ManagementSecuritySettingsRoutes.GET_MANAGEMENT_SECURITY_SETTINGS;
|
|
42
|
+
|
|
43
|
+
// 2. Branded Types
|
|
44
|
+
const userId = toUserIdOrThrow('123e4567-e89b-12d3-a456-426614174000');
|
|
45
|
+
|
|
46
|
+
// 3. Validating API Responses with Zod
|
|
47
|
+
async function fetchUserSettings() {
|
|
48
|
+
const response = await fetch(url);
|
|
49
|
+
const json = await response.json();
|
|
50
|
+
|
|
51
|
+
if (!response.ok) {
|
|
52
|
+
const error = apiErrorResponseSchema.parse(json);
|
|
53
|
+
if (error.code === SecurityErrorCodes.TOTP_NOT_ENABLED) {
|
|
54
|
+
console.error('TOTP configuration required');
|
|
55
|
+
}
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
```
|
|
27
60
|
|
|
28
61
|
## Source Code & Repository
|
|
29
62
|
|