@kuckit/users-module 1.0.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/dist/index.d.ts +39 -0
- package/dist/index.js +108 -0
- package/package.json +47 -0
- package/src/index.ts +2 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as _kuckit_sdk0 from "@kuckit/sdk";
|
|
2
|
+
|
|
3
|
+
//#region src/module.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Configuration options for the users module
|
|
6
|
+
*/
|
|
7
|
+
interface UsersModuleConfig {
|
|
8
|
+
/** Enable caching for user profile reads */
|
|
9
|
+
enableCaching?: boolean;
|
|
10
|
+
/** Cache TTL in milliseconds */
|
|
11
|
+
cacheTtlMs?: number;
|
|
12
|
+
/** Enable retry logic for write operations */
|
|
13
|
+
enableRetry?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Users module for Kuckit SDK
|
|
17
|
+
*
|
|
18
|
+
* This module provides user management functionality:
|
|
19
|
+
* - User repository (Drizzle-based)
|
|
20
|
+
* - Use cases: getUserProfile, updateUserProfile, createUser
|
|
21
|
+
* - Event publishing for user domain events
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* // In your application's module config:
|
|
26
|
+
* const modules: ModuleSpec[] = [
|
|
27
|
+
* {
|
|
28
|
+
* package: '@kuckit/users-module',
|
|
29
|
+
* config: {
|
|
30
|
+
* enableCaching: true,
|
|
31
|
+
* cacheTtlMs: 60000,
|
|
32
|
+
* },
|
|
33
|
+
* },
|
|
34
|
+
* ]
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
declare const kuckitModule: _kuckit_sdk0.KuckitModuleDefinition<UsersModuleConfig>;
|
|
38
|
+
//#endregion
|
|
39
|
+
export { type UsersModuleConfig, kuckitModule };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { asFunction, defineKuckitModule } from "@kuckit/sdk";
|
|
2
|
+
import { makeCreateUser, makeGetUserProfile, makeUpdateUserProfile } from "@kuckit/application";
|
|
3
|
+
import { decorateUseCase, makeDrizzleUserRepository, makeEventPublisherAdapter, withCaching, withRetry } from "@kuckit/infrastructure";
|
|
4
|
+
|
|
5
|
+
//#region src/module.ts
|
|
6
|
+
/**
|
|
7
|
+
* Users module for Kuckit SDK
|
|
8
|
+
*
|
|
9
|
+
* This module provides user management functionality:
|
|
10
|
+
* - User repository (Drizzle-based)
|
|
11
|
+
* - Use cases: getUserProfile, updateUserProfile, createUser
|
|
12
|
+
* - Event publishing for user domain events
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* // In your application's module config:
|
|
17
|
+
* const modules: ModuleSpec[] = [
|
|
18
|
+
* {
|
|
19
|
+
* package: '@kuckit/users-module',
|
|
20
|
+
* config: {
|
|
21
|
+
* enableCaching: true,
|
|
22
|
+
* cacheTtlMs: 60000,
|
|
23
|
+
* },
|
|
24
|
+
* },
|
|
25
|
+
* ]
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
const kuckitModule = defineKuckitModule({
|
|
29
|
+
id: "kuckit.users",
|
|
30
|
+
displayName: "Users",
|
|
31
|
+
description: "User accounts, profiles, and authentication features",
|
|
32
|
+
version: "0.1.0",
|
|
33
|
+
capabilities: ["nav.item", "settings.page"],
|
|
34
|
+
async register(ctx) {
|
|
35
|
+
const { container, config } = ctx;
|
|
36
|
+
const enableCaching = config.enableCaching ?? true;
|
|
37
|
+
const cacheTtlMs = config.cacheTtlMs ?? 6e4;
|
|
38
|
+
const enableRetry = config.enableRetry ?? true;
|
|
39
|
+
container.register({ userRepository: asFunction(({ db }) => makeDrizzleUserRepository(db)).scoped() });
|
|
40
|
+
container.register({ eventPublisher: asFunction(({ eventBus, logger }) => makeEventPublisherAdapter(eventBus, logger)).singleton() });
|
|
41
|
+
container.register({
|
|
42
|
+
getUserProfile: asFunction(({ userRepository, logger, requestId, cacheStore }) => {
|
|
43
|
+
let useCase = makeGetUserProfile({ userRepository });
|
|
44
|
+
if (enableCaching) useCase = withCaching(useCase, cacheStore, {
|
|
45
|
+
keyFn: (input) => `user:${input.userId}`,
|
|
46
|
+
ttlMs: cacheTtlMs,
|
|
47
|
+
staleWhileRevalidateMs: cacheTtlMs / 2
|
|
48
|
+
});
|
|
49
|
+
return decorateUseCase(useCase, {
|
|
50
|
+
logger,
|
|
51
|
+
requestId: requestId ?? "unknown",
|
|
52
|
+
feature: "getUserProfile"
|
|
53
|
+
}, "getUserProfile");
|
|
54
|
+
}).scoped(),
|
|
55
|
+
updateUserProfile: asFunction(({ userRepository, eventPublisher, clock, logger, requestId }) => {
|
|
56
|
+
let useCase = makeUpdateUserProfile({
|
|
57
|
+
userRepository,
|
|
58
|
+
eventPublisher,
|
|
59
|
+
clock
|
|
60
|
+
});
|
|
61
|
+
if (enableRetry) useCase = withRetry(useCase, {
|
|
62
|
+
maxAttempts: 3,
|
|
63
|
+
initialBackoffMs: 100,
|
|
64
|
+
maxBackoffMs: 5e3,
|
|
65
|
+
backoffMultiplier: 2
|
|
66
|
+
});
|
|
67
|
+
return decorateUseCase(useCase, {
|
|
68
|
+
logger,
|
|
69
|
+
requestId: requestId ?? "unknown",
|
|
70
|
+
feature: "updateUserProfile"
|
|
71
|
+
}, "updateUserProfile");
|
|
72
|
+
}).scoped(),
|
|
73
|
+
createUser: asFunction(({ userRepository, eventPublisher, clock, logger, requestId }) => {
|
|
74
|
+
let useCase = makeCreateUser({
|
|
75
|
+
userRepository,
|
|
76
|
+
eventPublisher,
|
|
77
|
+
clock
|
|
78
|
+
});
|
|
79
|
+
if (enableRetry) useCase = withRetry(useCase, {
|
|
80
|
+
maxAttempts: 2,
|
|
81
|
+
initialBackoffMs: 50,
|
|
82
|
+
maxBackoffMs: 50,
|
|
83
|
+
backoffMultiplier: 1
|
|
84
|
+
});
|
|
85
|
+
return decorateUseCase(useCase, {
|
|
86
|
+
logger,
|
|
87
|
+
requestId: requestId ?? "unknown",
|
|
88
|
+
feature: "createUser"
|
|
89
|
+
}, "createUser");
|
|
90
|
+
}).scoped()
|
|
91
|
+
});
|
|
92
|
+
},
|
|
93
|
+
async onBootstrap(ctx) {
|
|
94
|
+
const { container, config } = ctx;
|
|
95
|
+
container.resolve("logger").info("Users module initialized", {
|
|
96
|
+
enableCaching: config.enableCaching ?? true,
|
|
97
|
+
cacheTtlMs: config.cacheTtlMs ?? 6e4,
|
|
98
|
+
enableRetry: config.enableRetry ?? true
|
|
99
|
+
});
|
|
100
|
+
},
|
|
101
|
+
async onShutdown(ctx) {
|
|
102
|
+
const { container } = ctx;
|
|
103
|
+
container.resolve("logger").info("Users module shutting down");
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
//#endregion
|
|
108
|
+
export { kuckitModule };
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kuckit/users-module",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "User management module for Kuckit SDK",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "src/index.ts",
|
|
7
|
+
"types": "src/index.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"kuckit": {
|
|
12
|
+
"id": "kuckit.users",
|
|
13
|
+
"server": ".",
|
|
14
|
+
"client": "./client"
|
|
15
|
+
},
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./src/index.ts",
|
|
19
|
+
"default": "./src/index.ts"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"main": "dist/index.js",
|
|
24
|
+
"types": "dist/index.d.ts",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"default": "./dist/index.js"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsdown"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@kuckit/sdk": "workspace:*",
|
|
37
|
+
"typescript": "^5"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@kuckit/domain": "workspace:*",
|
|
41
|
+
"@kuckit/application": "workspace:*",
|
|
42
|
+
"@kuckit/infrastructure": "workspace:*"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"tsdown": "catalog:"
|
|
46
|
+
}
|
|
47
|
+
}
|
package/src/index.ts
ADDED