@jomkv/keybud-v2-contracts 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/README.md ADDED
@@ -0,0 +1,193 @@
1
+ # KeyBud V2 Contracts
2
+
3
+ Shared TypeScript contracts and type definitions for KeyBud V2, providing type-safe communication between frontend and backend applications.
4
+
5
+ ## Overview
6
+
7
+ This package contains shared contracts for WebSocket events, payloads, and other common types used across the KeyBud V2 ecosystem. It ensures type safety and consistency between the frontend and backend implementations.
8
+
9
+ ## Installation
10
+
11
+ ```sh
12
+ pnpm add @jomkv/keybud-v2-contracts
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```typescript
18
+ import {
19
+ AUTH_EVENT_NAMES,
20
+ MESSAGE_EVENT_NAMES,
21
+ type AuthClientToServerEvents,
22
+ type MessageServerToClientEvents,
23
+ type NewMessagePayload,
24
+ } from "@jomkv/keybud-v2-contracts";
25
+ ```
26
+
27
+ ## Structure
28
+
29
+ ### WebSocket Contracts
30
+
31
+ #### Authentication (`ws/auth`)
32
+
33
+ Handles authentication-related WebSocket events:
34
+
35
+ - **Event Names**: `AUTH_EVENT_NAMES`
36
+ - `SUBSCRIBE` - Client subscribes to auth events
37
+ - `SUBSCRIBE_SUCCESS` - Server confirms subscription
38
+ - `COMPLETE` - Client completes login
39
+
40
+ - **Events**:
41
+ - `AuthClientToServerEvents` - Client-to-server event types
42
+ - `ServerToClientEvents` - Server-to-client event types
43
+
44
+ - **Payloads**: `AuthSubscribePayload`, `AuthSubscribeSuccessPayload`
45
+
46
+ #### Messages (`ws/messages`)
47
+
48
+ Handles messaging-related WebSocket events:
49
+
50
+ - **Event Names**: `MESSAGE_EVENT_NAMES`
51
+ - `SUBSCRIBE` - Client subscribes to messages
52
+ - `NEW_MESSAGE` - Server sends new message
53
+
54
+ - **Events**:
55
+ - `MessageClientToServerEvents` - Client-to-server event types
56
+ - `MessageServerToClientEvents` - Server-to-client event types
57
+
58
+ - **Payloads**: `MessageSubscribePayload`, `NewMessagePayload`
59
+
60
+ ## Development
61
+
62
+ ### Prerequisites
63
+
64
+ - Node.js >= 14.17
65
+ - pnpm 10.17.0
66
+
67
+ ### Scripts
68
+
69
+ ```sh
70
+ # Run tests (not yet implemented)
71
+ pnpm test
72
+ ```
73
+
74
+ ### Project Configuration
75
+
76
+ - **TypeScript**: Strict mode enabled with modern module resolution
77
+ - **Package Manager**: pnpm with workspace support
78
+ - **Module System**: ES Modules
79
+
80
+ ## Contributing
81
+
82
+ 1. Fork the repository
83
+ 2. Create your feature branch
84
+ 3. Add your contracts to the appropriate directory under `src/`
85
+ 4. Export new contracts from `src/index.ts`
86
+ 5. Submit a pull request
87
+
88
+ ## License
89
+
90
+ MIT © Jom Karlo Verzosa
91
+
92
+ ## Repository
93
+
94
+ [https://github.com/jomkv/keybud-v2-contracts](https://github.com/jomkv/keybud-v2-contracts)
95
+
96
+ ````# KeyBud V2 Contracts
97
+
98
+ Shared TypeScript contracts and type definitions for KeyBud V2, providing type-safe communication between frontend and backend applications.
99
+
100
+ ## Overview
101
+
102
+ This package contains shared contracts for WebSocket events, payloads, and other common types used across the KeyBud V2 ecosystem. It ensures type safety and consistency between the frontend and backend implementations.
103
+
104
+ ## Installation
105
+
106
+ ```sh
107
+ pnpm add @jomkv/keybud-v2-contracts
108
+ ````
109
+
110
+ ## Usage
111
+
112
+ ```typescript
113
+ import {
114
+ AUTH_EVENT_NAMES,
115
+ MESSAGE_EVENT_NAMES,
116
+ type AuthClientToServerEvents,
117
+ type MessageServerToClientEvents,
118
+ type NewMessagePayload,
119
+ } from "@jomkv/keybud-v2-contracts";
120
+ ```
121
+
122
+ ## Structure
123
+
124
+ ### WebSocket Contracts
125
+
126
+ #### Authentication (`ws/auth`)
127
+
128
+ Handles authentication-related WebSocket events:
129
+
130
+ - **Event Names**: `AUTH_EVENT_NAMES`
131
+ - `SUBSCRIBE` - Client subscribes to auth events
132
+ - `SUBSCRIBE_SUCCESS` - Server confirms subscription
133
+ - `COMPLETE` - Client completes login
134
+
135
+ - **Events**:
136
+ - `AuthClientToServerEvents` - Client-to-server event types
137
+ - `ServerToClientEvents` - Server-to-client event types
138
+
139
+ - **Payloads**: `AuthSubscribePayload`, `AuthSubscribeSuccessPayload`
140
+
141
+ #### Messages (`ws/messages`)
142
+
143
+ Handles messaging-related WebSocket events:
144
+
145
+ - **Event Names**: `MESSAGE_EVENT_NAMES`
146
+ - `SUBSCRIBE` - Client subscribes to messages
147
+ - `NEW_MESSAGE` - Server sends new message
148
+
149
+ - **Events**:
150
+ - `MessageClientToServerEvents` - Client-to-server event types
151
+ - `MessageServerToClientEvents` - Server-to-client event types
152
+
153
+ - **Payloads**: `MessageSubscribePayload`, `NewMessagePayload`
154
+
155
+ ## Development
156
+
157
+ ### Prerequisites
158
+
159
+ - Node.js >= 14.17
160
+ - pnpm 10.17.0
161
+
162
+ ### Scripts
163
+
164
+ ```sh
165
+ # Run tests (not yet implemented)
166
+ pnpm test
167
+ ```
168
+
169
+ ### Project Configuration
170
+
171
+ - **TypeScript**: Strict mode enabled with modern module resolution
172
+ - **Package Manager**: pnpm with workspace support
173
+ - **Module System**: ES Modules
174
+
175
+ ## Contributing
176
+
177
+ 1. Fork the repository
178
+ 2. Create your feature branch
179
+ 3. Add your contracts to the appropriate directory under `src/`
180
+ 4. Export new contracts from `src/index.ts`
181
+ 5. Submit a pull request
182
+
183
+ ## License
184
+
185
+ MIT © Jom Karlo Verzosa
186
+
187
+ ## Repository
188
+
189
+ [https://github.com/jomkv/keybud-v2-contracts](https://github.com/jomkv/keybud-v2-contracts)
190
+
191
+ ```
192
+
193
+ ```
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@jomkv/keybud-v2-contracts",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "keywords": [],
6
+ "homepage": "https://github.com/jomkv/keybud-v2-contracts#readme",
7
+ "bugs": {
8
+ "url": "https://github.com/jomkv/keybud-v2-contracts/issues"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/jomkv/keybud-v2-contracts.git"
13
+ },
14
+ "license": "MIT",
15
+ "author": "Jom Karlo Verzosa",
16
+ "type": "module",
17
+ "main": "index.js",
18
+ "scripts": {
19
+ "test": "echo \"Error: no test specified\" && exit 1"
20
+ },
21
+ "devDependencies": {
22
+ "@types/node": "^25.0.8",
23
+ "ts-node": "^10.9.2",
24
+ "typescript": "^5.9.3"
25
+ },
26
+ "packageManager": "pnpm@10.17.0"
27
+ }
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./ws/auth/index.ts";
2
+ export * from "./ws/messages/index.ts";
@@ -0,0 +1,8 @@
1
+ export const AUTH_EVENT_NAMES = {
2
+ SUBSCRIBE: "auth:subscribe",
3
+ SUBSCRIBE_SUCCESS: "auth:subscribe_success",
4
+ COMPLETE: "auth:complete", // client completes login
5
+ } as const;
6
+
7
+ export type AuthEventName =
8
+ (typeof AUTH_EVENT_NAMES)[keyof typeof AUTH_EVENT_NAMES];
@@ -0,0 +1,14 @@
1
+ import type { AUTH_EVENT_NAMES } from "./event-names.ts";
2
+ import type {
3
+ AuthSubscribePayload,
4
+ AuthSubscribeSuccessPayload,
5
+ } from "./payloads.js";
6
+
7
+ export interface AuthClientToServerEvents {
8
+ [AUTH_EVENT_NAMES.SUBSCRIBE]: AuthSubscribePayload;
9
+ }
10
+
11
+ export interface ServerToClientEvents {
12
+ [AUTH_EVENT_NAMES.SUBSCRIBE_SUCCESS]: AuthSubscribeSuccessPayload;
13
+ [AUTH_EVENT_NAMES.COMPLETE]: {};
14
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./event-names.ts";
2
+ export * from "./events.ts";
3
+ export * from "./payloads.ts";
@@ -0,0 +1,7 @@
1
+ export interface AuthSubscribePayload {
2
+ sessionId: string;
3
+ }
4
+
5
+ export interface AuthSubscribeSuccessPayload {
6
+ sessionId: string;
7
+ }
@@ -0,0 +1,7 @@
1
+ export const MESSAGE_EVENT_NAMES = {
2
+ SUBSCRIBE: "message:subscribe",
3
+ NEW_MESSAGE: "message:new",
4
+ } as const;
5
+
6
+ export type MessageEventName =
7
+ (typeof MESSAGE_EVENT_NAMES)[keyof typeof MESSAGE_EVENT_NAMES];
@@ -0,0 +1,10 @@
1
+ import type { MESSAGE_EVENT_NAMES } from "./event-names.ts";
2
+ import type { MessageSubscribePayload, NewMessagePayload } from "./payloads.js";
3
+
4
+ export interface MessageClientToServerEvents {
5
+ [MESSAGE_EVENT_NAMES.SUBSCRIBE]: MessageSubscribePayload;
6
+ }
7
+
8
+ export interface MessageServerToClientEvents {
9
+ [MESSAGE_EVENT_NAMES.NEW_MESSAGE]: NewMessagePayload;
10
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./event-names.ts";
2
+ export * from "./events.ts";
3
+ export * from "./payloads.ts";
@@ -0,0 +1,12 @@
1
+ export interface NewMessagePayload {
2
+ id: number;
3
+ senderId: number;
4
+ conversationId: number;
5
+ content: string;
6
+ createdAt: Date;
7
+ readAt?: Date;
8
+ }
9
+
10
+ export interface MessageSubscribePayload {
11
+ userId: number;
12
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ // Visit https://aka.ms/tsconfig to read more about this file
3
+ "compilerOptions": {
4
+ // File Layout
5
+ // "rootDir": "./src",
6
+ // "outDir": "./dist",
7
+
8
+ // Environment Settings
9
+ // See also https://aka.ms/tsconfig/module
10
+ "module": "nodenext",
11
+ "target": "esnext",
12
+ "types": [],
13
+ // For nodejs:
14
+ // "lib": ["esnext"],
15
+ // "types": ["node"],
16
+ // and npm install -D @types/node
17
+
18
+ // Other Outputs
19
+ "sourceMap": true,
20
+ "declaration": true,
21
+ "declarationMap": true,
22
+
23
+ // Stricter Typechecking Options
24
+ "noUncheckedIndexedAccess": true,
25
+ "exactOptionalPropertyTypes": true,
26
+
27
+ // Style Options
28
+ // "noImplicitReturns": true,
29
+ // "noImplicitOverride": true,
30
+ // "noUnusedLocals": true,
31
+ // "noUnusedParameters": true,
32
+ // "noFallthroughCasesInSwitch": true,
33
+ // "noPropertyAccessFromIndexSignature": true,
34
+
35
+ // Recommended Options
36
+ "strict": true,
37
+ "jsx": "react-jsx",
38
+ "verbatimModuleSyntax": true,
39
+ "isolatedModules": true,
40
+ "noUncheckedSideEffectImports": true,
41
+ "moduleDetection": "force",
42
+ "skipLibCheck": true,
43
+
44
+ // Custom
45
+ "allowImportingTsExtensions": true,
46
+ "noEmit": true
47
+ }
48
+ }