@leancodepl/cqrs-client-base 8.4.0 → 8.5.1
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 +100 -0
- package/package.json +33 -3
- package/src/index.d.ts +1 -0
- package/index.esm.d.ts +0 -1
- /package/{index.cjs.d.ts → index.d.ts} +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# @leancodepl/cqrs-client-base
|
|
2
|
+
|
|
3
|
+
Base types and interfaces for CQRS clients.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @leancodepl/cqrs-client-base
|
|
9
|
+
# or
|
|
10
|
+
yarn add @leancodepl/cqrs-client-base
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## API
|
|
14
|
+
|
|
15
|
+
### `TokenProvider`
|
|
16
|
+
|
|
17
|
+
Interface for token providers used in CQRS clients.
|
|
18
|
+
|
|
19
|
+
**Properties:**
|
|
20
|
+
- `getToken: () => Promise<string | undefined>` - Returns authentication token
|
|
21
|
+
- `invalidateToken: () => Promise<boolean>` - Invalidates and refreshes token
|
|
22
|
+
|
|
23
|
+
### `ValidationError<TErrorCodes>`
|
|
24
|
+
|
|
25
|
+
Represents validation errors from commands.
|
|
26
|
+
|
|
27
|
+
**Properties:**
|
|
28
|
+
- `PropertyName: string` - Property that failed validation
|
|
29
|
+
- `ErrorMessage: string` - Human-readable error message
|
|
30
|
+
- `AttemptedValue: unknown` - Value that was attempted
|
|
31
|
+
- `ErrorCode: TErrorCodes[keyof TErrorCodes]` - Error code from provided map
|
|
32
|
+
|
|
33
|
+
### `CommandResult<TErrorCodes>`
|
|
34
|
+
|
|
35
|
+
Union type for command results.
|
|
36
|
+
|
|
37
|
+
**Types:**
|
|
38
|
+
- `SuccessfulCommandResult` - When command succeeds
|
|
39
|
+
- `FailedCommandResult<TErrorCodes>` - When command fails with validation errors
|
|
40
|
+
|
|
41
|
+
### `ApiResponse<TResult>`
|
|
42
|
+
|
|
43
|
+
Union type for API responses.
|
|
44
|
+
|
|
45
|
+
**Types:**
|
|
46
|
+
- `ApiSuccess<TResult>` - Successful response with result
|
|
47
|
+
- `ApiError` - Error response
|
|
48
|
+
|
|
49
|
+
## Usage Examples
|
|
50
|
+
|
|
51
|
+
### Token Provider Implementation
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import { TokenProvider } from '@leancodepl/cqrs-client-base';
|
|
55
|
+
|
|
56
|
+
const tokenProvider: TokenProvider = {
|
|
57
|
+
getToken: async () => {
|
|
58
|
+
return localStorage.getItem('authToken');
|
|
59
|
+
},
|
|
60
|
+
invalidateToken: async () => {
|
|
61
|
+
localStorage.removeItem('authToken');
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Command Error Handling
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
import { CommandResult, ValidationError } from '@leancodepl/cqrs-client-base';
|
|
71
|
+
|
|
72
|
+
interface UserErrorCodes {
|
|
73
|
+
EmailExists: 1;
|
|
74
|
+
InvalidEmail: 2;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function handleCommandResult(result: CommandResult<UserErrorCodes>) {
|
|
78
|
+
if (result.WasSuccessful) {
|
|
79
|
+
console.log('Command succeeded');
|
|
80
|
+
} else {
|
|
81
|
+
result.ValidationErrors.forEach((error: ValidationError<UserErrorCodes>) => {
|
|
82
|
+
console.log(`${error.PropertyName}: ${error.ErrorMessage}`);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### API Response Handling
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
import { ApiResponse } from '@leancodepl/cqrs-client-base';
|
|
92
|
+
|
|
93
|
+
function handleApiResponse<T>(response: ApiResponse<T>) {
|
|
94
|
+
if (response.isSuccess) {
|
|
95
|
+
return response.result;
|
|
96
|
+
} else {
|
|
97
|
+
throw new Error('API call failed');
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
```
|
package/package.json
CHANGED
|
@@ -1,17 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leancodepl/cqrs-client-base",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.5.1",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public",
|
|
7
|
+
"registry": "https://registry.npmjs.org/"
|
|
8
|
+
},
|
|
9
|
+
"engines": {
|
|
10
|
+
"node": ">=18.0.0"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/leancodepl/js_corelibrary.git",
|
|
15
|
+
"directory": "packages/cqrs-clients/cqrs-client-base"
|
|
16
|
+
},
|
|
17
|
+
"homepage": "https://github.com/leancodepl/js_corelibrary",
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/leancodepl/js_corelibrary/issues"
|
|
20
|
+
},
|
|
21
|
+
"description": "Base types and interfaces for CQRS client implementations",
|
|
22
|
+
"keywords": [
|
|
23
|
+
"cqrs",
|
|
24
|
+
"types",
|
|
25
|
+
"interfaces",
|
|
26
|
+
"typescript",
|
|
27
|
+
"javascript",
|
|
28
|
+
"leancode"
|
|
29
|
+
],
|
|
30
|
+
"author": {
|
|
31
|
+
"name": "LeanCode",
|
|
32
|
+
"url": "https://leancode.co"
|
|
33
|
+
},
|
|
34
|
+
"sideEffects": false,
|
|
5
35
|
"exports": {
|
|
6
36
|
"./package.json": "./package.json",
|
|
7
37
|
".": {
|
|
8
38
|
"module": "./index.esm.js",
|
|
9
|
-
"types": "./index.
|
|
39
|
+
"types": "./index.d.ts",
|
|
10
40
|
"import": "./index.cjs.mjs",
|
|
11
41
|
"default": "./index.cjs.js"
|
|
12
42
|
}
|
|
13
43
|
},
|
|
14
44
|
"module": "./index.esm.js",
|
|
15
45
|
"main": "./index.cjs.js",
|
|
16
|
-
"types": "./index.
|
|
46
|
+
"types": "./index.d.ts"
|
|
17
47
|
}
|
package/src/index.d.ts
CHANGED
package/index.esm.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src/index";
|
|
File without changes
|