@social.dev/server-sdk 0.0.1-alpha.4 → 0.0.1-alpha.41

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.
Files changed (245) hide show
  1. package/README.md +691 -40
  2. package/dist/app.module.d.ts +3 -3
  3. package/dist/app.module.js +10 -5
  4. package/dist/app.module.js.map +1 -1
  5. package/dist/auth/auth.controller.d.ts +9 -1
  6. package/dist/auth/auth.controller.js +53 -2
  7. package/dist/auth/auth.controller.js.map +1 -1
  8. package/dist/auth/auth.module.js +4 -0
  9. package/dist/auth/auth.module.js.map +1 -1
  10. package/dist/auth/auth.service.d.ts +7 -6
  11. package/dist/auth/auth.service.js +18 -15
  12. package/dist/auth/auth.service.js.map +1 -1
  13. package/dist/auth/dto/login-success.dto.d.ts +1 -1
  14. package/dist/auth/dto/login-success.dto.js +6 -3
  15. package/dist/auth/dto/login-success.dto.js.map +1 -1
  16. package/dist/auth/dto/register-success.dto.d.ts +3 -0
  17. package/dist/auth/dto/register-success.dto.js +12 -0
  18. package/dist/auth/dto/register-success.dto.js.map +1 -0
  19. package/dist/auth/dto/register.dto.d.ts +6 -0
  20. package/dist/auth/dto/register.dto.js +45 -0
  21. package/dist/auth/dto/register.dto.js.map +1 -0
  22. package/dist/auth/enums/auth-method.enum.d.ts +2 -2
  23. package/dist/auth/enums/auth-method.enum.js +2 -2
  24. package/dist/auth/enums/auth-method.enum.js.map +1 -1
  25. package/dist/auth/oidc/dto/requests.d.ts +6 -0
  26. package/dist/auth/oidc/dto/requests.js +47 -0
  27. package/dist/auth/oidc/dto/requests.js.map +1 -0
  28. package/dist/auth/oidc/dto/responses.js +1 -1
  29. package/dist/auth/oidc/dto/responses.js.map +1 -1
  30. package/dist/auth/oidc/oidc.controller.d.ts +7 -2
  31. package/dist/auth/oidc/oidc.controller.js +31 -17
  32. package/dist/auth/oidc/oidc.controller.js.map +1 -1
  33. package/dist/auth/oidc/oidc.module.js +2 -0
  34. package/dist/auth/oidc/oidc.module.js.map +1 -1
  35. package/dist/auth/oidc/oidc.service.d.ts +13 -7
  36. package/dist/auth/oidc/oidc.service.js +38 -30
  37. package/dist/auth/oidc/oidc.service.js.map +1 -1
  38. package/dist/auth/session/session.controller.js +8 -3
  39. package/dist/auth/session/session.controller.js.map +1 -1
  40. package/dist/auth/session/session.service.d.ts +2 -2
  41. package/dist/auth/session/session.service.js +9 -5
  42. package/dist/auth/session/session.service.js.map +1 -1
  43. package/dist/bootstrap.d.ts +2 -1
  44. package/dist/bootstrap.js +6 -1
  45. package/dist/bootstrap.js.map +1 -1
  46. package/dist/chat/chat.controller.d.ts +1 -2
  47. package/dist/chat/chat.controller.js +8 -4
  48. package/dist/chat/chat.controller.js.map +1 -1
  49. package/dist/chat/chat.module.js +6 -0
  50. package/dist/chat/chat.module.js.map +1 -1
  51. package/dist/chat/chat.service.d.ts +10 -2
  52. package/dist/chat/chat.service.js +79 -17
  53. package/dist/chat/chat.service.js.map +1 -1
  54. package/dist/chat/dto/responses.dto.d.ts +4 -0
  55. package/dist/chat/dto/responses.dto.js +25 -1
  56. package/dist/chat/dto/responses.dto.js.map +1 -1
  57. package/dist/chat/entities/conversation-member.entity.js +1 -1
  58. package/dist/chat/entities/conversation-member.entity.js.map +1 -1
  59. package/dist/chat/entities/conversation.entity.d.ts +1 -0
  60. package/dist/chat/entities/conversation.entity.js +8 -1
  61. package/dist/chat/entities/conversation.entity.js.map +1 -1
  62. package/dist/chat/entities/message.entity.js.map +1 -1
  63. package/dist/common/decorators/api-paginated-response.d.ts +1 -1
  64. package/dist/common/decorators/api-paginated-response.js +2 -2
  65. package/dist/common/decorators/api-paginated-response.js.map +1 -1
  66. package/dist/common/dto/paginated-response.dto.d.ts +2 -0
  67. package/dist/common/dto/paginated-response.dto.js +14 -3
  68. package/dist/common/dto/paginated-response.dto.js.map +1 -1
  69. package/dist/community/community.acl.js.map +1 -1
  70. package/dist/community/community.controller.d.ts +1 -2
  71. package/dist/community/community.controller.js +9 -5
  72. package/dist/community/community.controller.js.map +1 -1
  73. package/dist/community/community.module.js +1 -0
  74. package/dist/community/community.module.js.map +1 -1
  75. package/dist/community/community.service.d.ts +10 -3
  76. package/dist/community/community.service.js +30 -12
  77. package/dist/community/community.service.js.map +1 -1
  78. package/dist/configs/configs.module.js +3 -0
  79. package/dist/configs/configs.module.js.map +1 -1
  80. package/dist/configs/configs.service.d.ts +23 -0
  81. package/dist/configs/configs.service.js +14 -1
  82. package/dist/configs/configs.service.js.map +1 -1
  83. package/dist/core/event-stream/event-stream-processor.interface.d.ts +8 -0
  84. package/dist/core/event-stream/event-stream-processor.interface.js +3 -0
  85. package/dist/core/event-stream/event-stream-processor.interface.js.map +1 -0
  86. package/dist/core/event-stream/event-stream-processor.service.d.ts +13 -0
  87. package/dist/core/event-stream/event-stream-processor.service.js +55 -0
  88. package/dist/core/event-stream/event-stream-processor.service.js.map +1 -0
  89. package/dist/core/event-stream/event-stream.module.d.ts +11 -0
  90. package/dist/core/event-stream/event-stream.module.js +49 -0
  91. package/dist/core/event-stream/event-stream.module.js.map +1 -0
  92. package/dist/core/event-stream/event-stream.service.d.ts +16 -0
  93. package/dist/core/event-stream/event-stream.service.js +100 -0
  94. package/dist/core/event-stream/event-stream.service.js.map +1 -0
  95. package/dist/core/event-stream/types.d.ts +2 -0
  96. package/dist/core/event-stream/types.js +3 -0
  97. package/dist/core/event-stream/types.js.map +1 -0
  98. package/dist/core/hook/hook.module.d.ts +4 -0
  99. package/dist/core/hook/hook.module.js +30 -0
  100. package/dist/core/hook/hook.module.js.map +1 -0
  101. package/dist/core/hook/hook.service.d.ts +7 -0
  102. package/dist/core/{plugin/plugin-hook.service.js → hook/hook.service.js} +10 -10
  103. package/dist/core/hook/hook.service.js.map +1 -0
  104. package/dist/core/plugin/plugin.module.js +7 -5
  105. package/dist/core/plugin/plugin.module.js.map +1 -1
  106. package/dist/db.js +1 -1
  107. package/dist/db.js.map +1 -1
  108. package/dist/file-storage/file-storage.service.d.ts +1 -1
  109. package/dist/file-storage/file-storage.service.js +6 -6
  110. package/dist/file-storage/file-storage.service.js.map +1 -1
  111. package/dist/file-storage/utils.js +3 -1
  112. package/dist/file-storage/utils.js.map +1 -1
  113. package/dist/index.d.ts +0 -1
  114. package/dist/index.js +1 -3
  115. package/dist/index.js.map +1 -1
  116. package/dist/media/entities/media.entity.js +1 -1
  117. package/dist/media/entities/media.entity.js.map +1 -1
  118. package/dist/media/media.acl.d.ts +2 -4
  119. package/dist/media/media.acl.js +3 -0
  120. package/dist/media/media.acl.js.map +1 -1
  121. package/dist/media/media.service.js +15 -12
  122. package/dist/media/media.service.js.map +1 -1
  123. package/dist/migrations/1757061785934-PushNotificationTokens.d.ts +6 -0
  124. package/dist/migrations/1757061785934-PushNotificationTokens.js +20 -0
  125. package/dist/migrations/1757061785934-PushNotificationTokens.js.map +1 -0
  126. package/dist/migrations/1758623241397-AddUserTimestamps.d.ts +6 -0
  127. package/dist/migrations/1758623241397-AddUserTimestamps.js +16 -0
  128. package/dist/migrations/1758623241397-AddUserTimestamps.js.map +1 -0
  129. package/dist/{1756201302119-migrations.d.ts → migrations/1758704603161-UserFollows.d.ts} +1 -1
  130. package/dist/migrations/1758704603161-UserFollows.js +18 -0
  131. package/dist/migrations/1758704603161-UserFollows.js.map +1 -0
  132. package/dist/network/entities/network.entity.js +0 -3
  133. package/dist/network/entities/network.entity.js.map +1 -1
  134. package/dist/network/network.middleware.js +2 -2
  135. package/dist/network/network.middleware.js.map +1 -1
  136. package/dist/network/network.module.js +2 -1
  137. package/dist/network/network.module.js.map +1 -1
  138. package/dist/network/network.service.d.ts +5 -2
  139. package/dist/network/network.service.js +23 -6
  140. package/dist/network/network.service.js.map +1 -1
  141. package/dist/notification/dto/delete-push-token.dto.d.ts +3 -0
  142. package/dist/{common/entities/base.repository.js → notification/dto/delete-push-token.dto.js} +14 -20
  143. package/dist/notification/dto/delete-push-token.dto.js.map +1 -0
  144. package/dist/notification/dto/register-push-token.dto.d.ts +5 -0
  145. package/dist/notification/dto/register-push-token.dto.js +38 -0
  146. package/dist/notification/dto/register-push-token.dto.js.map +1 -0
  147. package/dist/notification/entities/push-token.entity.d.ts +11 -0
  148. package/dist/notification/entities/push-token.entity.js +60 -0
  149. package/dist/notification/entities/push-token.entity.js.map +1 -0
  150. package/dist/notification/enums/push-service.enum.d.ts +6 -0
  151. package/dist/notification/enums/push-service.enum.js +11 -0
  152. package/dist/notification/enums/push-service.enum.js.map +1 -0
  153. package/dist/notification/hook-listener.service.d.ts +13 -0
  154. package/dist/notification/hook-listener.service.js +58 -0
  155. package/dist/notification/hook-listener.service.js.map +1 -0
  156. package/dist/notification/notification.module.d.ts +2 -0
  157. package/dist/notification/notification.module.js +24 -0
  158. package/dist/notification/notification.module.js.map +1 -0
  159. package/dist/notification/push-notification.controller.d.ts +9 -0
  160. package/dist/notification/push-notification.controller.js +69 -0
  161. package/dist/notification/push-notification.controller.js.map +1 -0
  162. package/dist/notification/push-notification.module.d.ts +2 -0
  163. package/dist/notification/push-notification.module.js +27 -0
  164. package/dist/notification/push-notification.module.js.map +1 -0
  165. package/dist/notification/push-notification.service.d.ts +22 -0
  166. package/dist/notification/push-notification.service.js +84 -0
  167. package/dist/notification/push-notification.service.js.map +1 -0
  168. package/dist/post/post.controller.d.ts +3 -2
  169. package/dist/post/post.controller.js +28 -8
  170. package/dist/post/post.controller.js.map +1 -1
  171. package/dist/post/post.module.js +2 -0
  172. package/dist/post/post.module.js.map +1 -1
  173. package/dist/post/post.service.d.ts +7 -3
  174. package/dist/post/post.service.js +18 -8
  175. package/dist/post/post.service.js.map +1 -1
  176. package/dist/tsconfig.build.tsbuildinfo +1 -1
  177. package/dist/user/avatar/avatar.controller.d.ts +10 -0
  178. package/dist/user/avatar/avatar.controller.js +89 -0
  179. package/dist/user/avatar/avatar.controller.js.map +1 -0
  180. package/dist/user/avatar/avatar.service.d.ts +12 -0
  181. package/dist/user/avatar/avatar.service.js +68 -0
  182. package/dist/user/avatar/avatar.service.js.map +1 -0
  183. package/dist/user/constants.d.ts +1 -0
  184. package/dist/user/constants.js +5 -0
  185. package/dist/user/constants.js.map +1 -0
  186. package/dist/user/dto/update-profile.dto.d.ts +3 -0
  187. package/dist/user/dto/update-profile.dto.js +26 -0
  188. package/dist/user/dto/update-profile.dto.js.map +1 -0
  189. package/dist/user/dto/user-response.dto.d.ts +6 -0
  190. package/dist/user/dto/user-response.dto.js +37 -1
  191. package/dist/user/dto/user-response.dto.js.map +1 -1
  192. package/dist/user/dto/user.dto.d.ts +8 -0
  193. package/dist/user/dto/user.dto.js +21 -0
  194. package/dist/user/dto/user.dto.js.map +1 -0
  195. package/dist/user/entities/user.entity.d.ts +4 -0
  196. package/dist/user/entities/user.entity.js +19 -1
  197. package/dist/user/entities/user.entity.js.map +1 -1
  198. package/dist/user/follow/dto/follow-response.dto.d.ts +4 -0
  199. package/dist/user/follow/dto/follow-response.dto.js +38 -0
  200. package/dist/user/follow/dto/follow-response.dto.js.map +1 -0
  201. package/dist/user/follow/dto/follow.dto.d.ts +4 -0
  202. package/dist/user/follow/dto/follow.dto.js +26 -0
  203. package/dist/user/follow/dto/follow.dto.js.map +1 -0
  204. package/dist/user/follow/entities/follow.entity.d.ts +10 -0
  205. package/dist/user/follow/entities/follow.entity.js +60 -0
  206. package/dist/user/follow/entities/follow.entity.js.map +1 -0
  207. package/dist/user/follow/follow.controller.d.ts +9 -0
  208. package/dist/user/follow/follow.controller.js +56 -0
  209. package/dist/user/follow/follow.controller.js.map +1 -0
  210. package/dist/user/follow/follow.module.d.ts +2 -0
  211. package/dist/user/follow/follow.module.js +26 -0
  212. package/dist/user/follow/follow.module.js.map +1 -0
  213. package/dist/user/follow/follow.service.d.ts +11 -0
  214. package/dist/user/follow/follow.service.js +56 -0
  215. package/dist/user/follow/follow.service.js.map +1 -0
  216. package/dist/user/user.controller.d.ts +6 -2
  217. package/dist/user/user.controller.js +47 -8
  218. package/dist/user/user.controller.js.map +1 -1
  219. package/dist/user/user.module.js +12 -3
  220. package/dist/user/user.module.js.map +1 -1
  221. package/dist/user/user.service.d.ts +12 -5
  222. package/dist/user/user.service.js +49 -11
  223. package/dist/user/user.service.js.map +1 -1
  224. package/package.json +6 -3
  225. package/dist/1756201302119-migrations.js +0 -84
  226. package/dist/1756201302119-migrations.js.map +0 -1
  227. package/dist/auth/enums/auth-methods.enum.d.ts +0 -2
  228. package/dist/auth/enums/auth-methods.enum.js +0 -7
  229. package/dist/auth/enums/auth-methods.enum.js.map +0 -1
  230. package/dist/auth/session/auth.controller.d.ts +0 -10
  231. package/dist/auth/session/auth.controller.js +0 -92
  232. package/dist/auth/session/auth.controller.js.map +0 -1
  233. package/dist/auth/session/auth.service.d.ts +0 -12
  234. package/dist/auth/session/auth.service.js +0 -46
  235. package/dist/auth/session/auth.service.js.map +0 -1
  236. package/dist/common/constants.d.ts +0 -1
  237. package/dist/common/constants.js +0 -5
  238. package/dist/common/constants.js.map +0 -1
  239. package/dist/common/entities/base.repository.d.ts +0 -7
  240. package/dist/common/entities/base.repository.js.map +0 -1
  241. package/dist/core/plugin/plugin-hook.service.d.ts +0 -7
  242. package/dist/core/plugin/plugin-hook.service.js.map +0 -1
  243. package/dist/user/dto/update-user.dto.d.ts +0 -5
  244. package/dist/user/dto/update-user.dto.js +0 -13
  245. package/dist/user/dto/update-user.dto.js.map +0 -1
package/README.md CHANGED
@@ -1,73 +1,724 @@
1
- ## Social.Dev server
1
+ # @social.dev/server-sdk
2
2
 
3
- ## Project setup
3
+ Server SDK for Social.dev - A comprehensive NestJS-based framework for building scalable social media server applications.
4
+
5
+ ## Overview
6
+
7
+ The `@social.dev/server-sdk` package provides:
8
+ - 🏗️ **NestJS Framework** - Built on top of NestJS 11 for enterprise-grade applications
9
+ - 🔐 **Authentication System** - Multiple auth methods including OIDC, JWT, and cookie-based sessions
10
+ - 💾 **Database Integration** - TypeORM with PostgreSQL support and migration tools
11
+ - 🔌 **Plugin Architecture** - Extensible plugin system for custom functionality
12
+ - 💬 **Chat System** - Real-time messaging with conversation management
13
+ - 👥 **Community Features** - Sub-communities with member management
14
+ - 📝 **Post Management** - Content creation and interaction system
15
+ - 🔔 **Notifications** - Push notification support with device management
16
+ - 📁 **File Storage** - S3-compatible file storage integration
17
+ - 📊 **API Documentation** - Auto-generated Swagger/OpenAPI documentation
18
+ - 🌐 **Multi-Network Support** - Domain-based network isolation
19
+
20
+ ## Installation
4
21
 
5
22
  ```bash
6
- $ npm install
23
+ # Using pnpm (recommended)
24
+ pnpm add @social.dev/server-sdk
25
+
26
+ # Using npm
27
+ npm install @social.dev/server-sdk
28
+
29
+ # Using yarn
30
+ yarn add @social.dev/server-sdk
31
+ ```
32
+
33
+ ### Prerequisites
34
+
35
+ - Node.js 18 or higher
36
+ - PostgreSQL 14 or higher
37
+ - Redis (optional, for caching)
38
+ - S3-compatible storage (optional, for file uploads)
39
+
40
+ ## Quick Start
41
+
42
+ ### Basic Setup
43
+
44
+ Create a new file `index.ts` in your server application:
45
+
46
+ ```typescript
47
+ import { bootstrap } from '@social.dev/server-sdk/bootstrap';
48
+
49
+ // Initialize the server with minimal configuration
50
+ bootstrap({
51
+ auth: {
52
+ methods: ['password'], // Enable password authentication
53
+ },
54
+ });
55
+ ```
56
+
57
+ ### Advanced Setup with OIDC and Plugins
58
+
59
+ ```typescript
60
+ import { bootstrap } from '@social.dev/server-sdk/bootstrap';
61
+ import { AuthMethodEnum } from '@social.dev/server-sdk/auth/enums/auth-method.enum';
62
+ import { PluginFactory } from '@social.dev/server-sdk/core/plugin/plugin.factory';
63
+ import SocialDevAiPlugin from '@social.dev/plugin-ai';
64
+
65
+ // Register plugins before bootstrap
66
+ PluginFactory.addPlugin(
67
+ SocialDevAiPlugin.forRoot({
68
+ userIds: [3], // User IDs that can access AI features
69
+ })
70
+ );
71
+
72
+ // Bootstrap the server with comprehensive configuration
73
+ bootstrap({
74
+ auth: {
75
+ methods: [AuthMethodEnum.Oidc, AuthMethodEnum.Password],
76
+ oidc: {
77
+ providers: [
78
+ {
79
+ id: 'keycloak',
80
+ name: 'Company Keycloak',
81
+ issuer: 'https://keycloak.example.com/auth/realms/company',
82
+ clientId: 'social-dev-app',
83
+ clientSecret: process.env.OIDC_CLIENT_SECRET,
84
+ },
85
+ ],
86
+ },
87
+ },
88
+ network: {
89
+ domainAliasMap: {
90
+ 'localhost': 1,
91
+ 'dev.example.com': 2,
92
+ 'staging.example.com': 3,
93
+ },
94
+ },
95
+ });
7
96
  ```
8
97
 
9
- ## Compile and run the project
98
+ ## Configuration
99
+
100
+ ### Environment Variables
101
+
102
+ Create a `.env` file in your project root:
103
+
104
+ ```env
105
+ # Server Configuration
106
+ SOCIAL_DEV_SERVER_PORT=3000
107
+ NODE_ENV=development
108
+
109
+ # Database Configuration
110
+ POSTGRES_HOST=localhost
111
+ POSTGRES_PORT=5432
112
+ POSTGRES_USER=socialdev
113
+ POSTGRES_PASSWORD=yourpassword
114
+ POSTGRES_DB=socialdev_db
115
+
116
+ # Authentication
117
+ JWT_SECRET=your-super-secret-jwt-key
118
+ JWT_EXPIRES_IN=7d
119
+
120
+ # OIDC Configuration (optional)
121
+ OIDC_CLIENT_SECRET=your-oidc-secret
122
+
123
+ # S3 Storage (optional)
124
+ AWS_ACCESS_KEY_ID=your-access-key
125
+ AWS_SECRET_ACCESS_KEY=your-secret-key
126
+ AWS_REGION=us-east-1
127
+ S3_BUCKET_NAME=socialdev-uploads
128
+
129
+ # Push Notifications (optional)
130
+ FCM_SERVER_KEY=your-fcm-server-key
131
+ APNS_KEY_ID=your-apns-key-id
132
+ APNS_TEAM_ID=your-apns-team-id
133
+ ```
134
+
135
+ ### Bootstrap Configuration Options
136
+
137
+ ```typescript
138
+ interface BootstrapConfig {
139
+ auth?: {
140
+ // Available authentication methods
141
+ methods: AuthMethodEnum[];
142
+
143
+ // OIDC provider configuration
144
+ oidc?: {
145
+ providers: OidcProvider[];
146
+ };
147
+
148
+ // JWT configuration
149
+ jwt?: {
150
+ secret?: string;
151
+ expiresIn?: string;
152
+ };
153
+ };
154
+
155
+ network?: {
156
+ // Map domains to network IDs for multi-tenant support
157
+ domainAliasMap: { [domain: string]: number };
158
+ };
159
+
160
+ database?: {
161
+ // Override default database configuration
162
+ host?: string;
163
+ port?: number;
164
+ username?: string;
165
+ password?: string;
166
+ database?: string;
167
+ synchronize?: boolean; // Auto-sync schema (dev only!)
168
+ };
169
+
170
+ storage?: {
171
+ // S3 configuration
172
+ accessKeyId?: string;
173
+ secretAccessKey?: string;
174
+ region?: string;
175
+ bucket?: string;
176
+ };
177
+ }
178
+ ```
179
+
180
+ ## Core Modules
181
+
182
+ ### Authentication Module
183
+
184
+ The SDK supports multiple authentication methods:
185
+
186
+ ```typescript
187
+ // Available authentication methods
188
+ enum AuthMethodEnum {
189
+ Password = 'password',
190
+ Oidc = 'oidc',
191
+ Magic = 'magic', // Magic link via email
192
+ }
193
+
194
+ // OIDC Provider configuration
195
+ interface OidcProvider {
196
+ id: string; // Unique identifier
197
+ name: string; // Display name
198
+ issuer: string; // OIDC issuer URL
199
+ clientId: string; // OAuth client ID
200
+ clientSecret: string; // OAuth client secret
201
+ scope?: string; // OAuth scopes (default: 'openid profile email')
202
+ }
203
+ ```
204
+
205
+ ### User Module
206
+
207
+ User management with profiles and authentication:
208
+
209
+ ```typescript
210
+ // User entity structure
211
+ interface User {
212
+ id: number;
213
+ username: string;
214
+ email: string;
215
+ name?: string;
216
+ bio?: string;
217
+ avatar?: string;
218
+ verified: boolean;
219
+ createdAt: Date;
220
+ updatedAt: Date;
221
+ }
222
+ ```
223
+
224
+ ### Post Module
225
+
226
+ Content creation and management:
227
+
228
+ ```typescript
229
+ // Post entity structure
230
+ interface Post {
231
+ id: number;
232
+ content: string;
233
+ authorId: number;
234
+ parentId?: number; // For replies
235
+ attachments?: MediaAsset[];
236
+ likes: number;
237
+ comments: number;
238
+ shares: number;
239
+ createdAt: Date;
240
+ updatedAt: Date;
241
+ }
242
+ ```
243
+
244
+ ### Chat Module
245
+
246
+ Real-time messaging system:
247
+
248
+ ```typescript
249
+ // Conversation management
250
+ interface Conversation {
251
+ id: number;
252
+ participants: User[];
253
+ lastMessage?: Message;
254
+ unreadCount: number;
255
+ createdAt: Date;
256
+ updatedAt: Date;
257
+ }
258
+
259
+ // Message structure
260
+ interface Message {
261
+ id: number;
262
+ conversationId: number;
263
+ senderId: number;
264
+ content: string;
265
+ attachments?: MediaAsset[];
266
+ readBy: number[];
267
+ createdAt: Date;
268
+ }
269
+ ```
270
+
271
+ ### Community Module
272
+
273
+ Sub-communities (subs) management:
274
+
275
+ ```typescript
276
+ // Sub entity structure
277
+ interface Sub {
278
+ id: number;
279
+ name: string;
280
+ description?: string;
281
+ avatar?: string;
282
+ banner?: string;
283
+ memberCount: number;
284
+ postCount: number;
285
+ createdAt: Date;
286
+ }
287
+
288
+ // Member management
289
+ interface SubMember {
290
+ subId: number;
291
+ userId: number;
292
+ role: 'owner' | 'moderator' | 'member';
293
+ joinedAt: Date;
294
+ }
295
+ ```
296
+
297
+ ### Notification Module
298
+
299
+ Push notification management:
300
+
301
+ ```typescript
302
+ // Device registration
303
+ interface NotificationDevice {
304
+ id: number;
305
+ userId: number;
306
+ token: string;
307
+ platform: 'ios' | 'android' | 'web';
308
+ active: boolean;
309
+ }
310
+
311
+ // Notification sending
312
+ interface Notification {
313
+ userId: number;
314
+ title: string;
315
+ body: string;
316
+ data?: Record<string, any>;
317
+ priority?: 'high' | 'normal';
318
+ }
319
+ ```
320
+
321
+ ## Plugin System
322
+
323
+ The SDK supports a powerful plugin architecture for extending functionality:
324
+
325
+ ### Creating a Custom Plugin
326
+
327
+ ```typescript
328
+ // plugins/my-plugin/index.ts
329
+ import { Injectable, Module } from '@nestjs/common';
330
+ import { PluginInterface } from '@social.dev/server-sdk/core/plugin/plugin.interface';
331
+
332
+ @Injectable()
333
+ class MyPluginService {
334
+ async processContent(content: string): Promise<string> {
335
+ // Your plugin logic here
336
+ return content.toUpperCase();
337
+ }
338
+ }
339
+
340
+ @Module({
341
+ providers: [MyPluginService],
342
+ exports: [MyPluginService],
343
+ })
344
+ export class MyPlugin implements PluginInterface {
345
+ static forRoot(options?: { enabled?: boolean }) {
346
+ return {
347
+ module: MyPlugin,
348
+ providers: [
349
+ {
350
+ provide: 'MY_PLUGIN_OPTIONS',
351
+ useValue: options || {},
352
+ },
353
+ ],
354
+ };
355
+ }
356
+ }
357
+ ```
358
+
359
+ ### Registering Plugins
360
+
361
+ ```typescript
362
+ import { PluginFactory } from '@social.dev/server-sdk/core/plugin/plugin.factory';
363
+ import { MyPlugin } from './plugins/my-plugin';
364
+
365
+ // Register plugin before bootstrap
366
+ PluginFactory.addPlugin(
367
+ MyPlugin.forRoot({
368
+ enabled: true,
369
+ })
370
+ );
371
+
372
+ // Then bootstrap the server
373
+ bootstrap({ /* ... */ });
374
+ ```
375
+
376
+ ## Database Migrations
377
+
378
+ ### Generating Migrations
379
+
380
+ ```bash
381
+ # Build the SDK first
382
+ pnpm build
383
+
384
+ # Generate a new migration based on entity changes
385
+ npx typeorm migration:generate \
386
+ -d ./node_modules/@social.dev/server-sdk/dist/db.js \
387
+ ./migrations/AddUserBio
388
+ ```
389
+
390
+ ### Running Migrations
391
+
392
+ ```bash
393
+ # Run all pending migrations
394
+ npx typeorm migration:run \
395
+ -d ./node_modules/@social.dev/server-sdk/dist/db.js
396
+
397
+ # Revert the last migration
398
+ npx typeorm migration:revert \
399
+ -d ./node_modules/@social.dev/server-sdk/dist/db.js
400
+ ```
401
+
402
+ ### Creating Custom Migrations
403
+
404
+ ```typescript
405
+ // migrations/1234567890-CustomMigration.ts
406
+ import { MigrationInterface, QueryRunner, Table } from 'typeorm';
407
+
408
+ export class CustomMigration1234567890 implements MigrationInterface {
409
+ async up(queryRunner: QueryRunner): Promise<void> {
410
+ await queryRunner.createTable(
411
+ new Table({
412
+ name: 'custom_table',
413
+ columns: [
414
+ {
415
+ name: 'id',
416
+ type: 'int',
417
+ isPrimary: true,
418
+ isGenerated: true,
419
+ generationStrategy: 'increment',
420
+ },
421
+ {
422
+ name: 'name',
423
+ type: 'varchar',
424
+ },
425
+ ],
426
+ }),
427
+ true
428
+ );
429
+ }
430
+
431
+ async down(queryRunner: QueryRunner): Promise<void> {
432
+ await queryRunner.dropTable('custom_table');
433
+ }
434
+ }
435
+ ```
436
+
437
+ ## API Documentation
438
+
439
+ The SDK automatically generates Swagger/OpenAPI documentation:
10
440
 
11
441
  ```bash
12
- # development
13
- $ npm run start
442
+ # Start your server
443
+ pnpm dev
444
+
445
+ # Access the documentation
446
+ open http://localhost:3000/schema
447
+ ```
448
+
449
+ ### Custom API Endpoints
450
+
451
+ You can add custom endpoints by creating NestJS controllers:
452
+
453
+ ```typescript
454
+ // src/custom/custom.controller.ts
455
+ import { Controller, Get, Post, Body, UseGuards } from '@nestjs/common';
456
+ import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
457
+ import { AuthGuard } from '@social.dev/server-sdk/auth/auth.guard';
458
+
459
+ @ApiTags('custom')
460
+ @Controller('custom')
461
+ export class CustomController {
462
+ @Get('public')
463
+ getPublicData() {
464
+ return { message: 'This is public' };
465
+ }
14
466
 
15
- # watch mode
16
- $ npm run start:dev
467
+ @Post('protected')
468
+ @UseGuards(AuthGuard)
469
+ @ApiBearerAuth()
470
+ createProtectedResource(@Body() data: any) {
471
+ return { success: true, data };
472
+ }
473
+ }
17
474
 
18
- # production mode
19
- $ npm run start:prod
475
+ // Register in a module
476
+ @Module({
477
+ controllers: [CustomController],
478
+ })
479
+ export class CustomModule {}
20
480
  ```
21
481
 
22
- ## Run tests
482
+ ## Development Scripts
23
483
 
24
484
  ```bash
25
- # unit tests
26
- $ npm run test
485
+ # Install dependencies
486
+ pnpm install
27
487
 
28
- # e2e tests
29
- $ npm run test:e2e
488
+ # Development mode with hot reload
489
+ pnpm dev
30
490
 
31
- # test coverage
32
- $ npm run test:cov
491
+ # Build for production
492
+ pnpm build
493
+
494
+ # Start production server
495
+ pnpm start:prod
496
+
497
+ # Run tests
498
+ pnpm test
499
+
500
+ # Run tests with coverage
501
+ pnpm test:cov
502
+
503
+ # Lint code
504
+ pnpm lint
505
+
506
+ # Format code
507
+ pnpm format
33
508
  ```
34
509
 
35
- ## Deployment
510
+ ## Production Deployment
36
511
 
37
- When you're ready to deploy your NestJS application to production, there are some key steps you can take to ensure it runs as efficiently as possible. Check out the [deployment documentation](https://docs.nestjs.com/deployment) for more information.
512
+ ### Using PM2
38
513
 
39
- If you are looking for a cloud-based platform to deploy your NestJS application, check out [Mau](https://mau.nestjs.com), our official platform for deploying NestJS applications on AWS. Mau makes deployment straightforward and fast, requiring just a few simple steps:
514
+ ```javascript
515
+ // ecosystem.config.js
516
+ module.exports = {
517
+ apps: [{
518
+ name: 'social-dev-server',
519
+ script: './dist/index.js',
520
+ instances: 'max',
521
+ exec_mode: 'cluster',
522
+ env: {
523
+ NODE_ENV: 'production',
524
+ SOCIAL_DEV_SERVER_PORT: 3000,
525
+ },
526
+ }],
527
+ };
528
+ ```
40
529
 
41
530
  ```bash
42
- $ npm install -g @nestjs/mau
43
- $ mau deploy
531
+ # Build and start with PM2
532
+ pnpm build
533
+ pm2 start ecosystem.config.js
44
534
  ```
45
535
 
46
- With Mau, you can deploy your application in just a few clicks, allowing you to focus on building features rather than managing infrastructure.
536
+ ### Using Docker
47
537
 
48
- ## Resources
538
+ ```dockerfile
539
+ # Dockerfile
540
+ FROM node:18-alpine AS builder
49
541
 
50
- Check out a few resources that may come in handy when working with NestJS:
542
+ WORKDIR /app
543
+ COPY package*.json pnpm-lock.yaml ./
544
+ RUN npm install -g pnpm
545
+ RUN pnpm install --frozen-lockfile
51
546
 
52
- - Visit the [NestJS Documentation](https://docs.nestjs.com) to learn more about the framework.
53
- - For questions and support, please visit our [Discord channel](https://discord.gg/G7Qnnhy).
54
- - To dive deeper and get more hands-on experience, check out our official video [courses](https://courses.nestjs.com/).
55
- - Deploy your application to AWS with the help of [NestJS Mau](https://mau.nestjs.com) in just a few clicks.
56
- - Visualize your application graph and interact with the NestJS application in real-time using [NestJS Devtools](https://devtools.nestjs.com).
57
- - Need help with your project (part-time to full-time)? Check out our official [enterprise support](https://enterprise.nestjs.com).
58
- - To stay in the loop and get updates, follow us on [X](https://x.com/nestframework) and [LinkedIn](https://linkedin.com/company/nestjs).
59
- - Looking for a job, or have a job to offer? Check out our official [Jobs board](https://jobs.nestjs.com).
547
+ COPY . .
548
+ RUN pnpm build
60
549
 
61
- ## Support
550
+ FROM node:18-alpine
551
+
552
+ WORKDIR /app
553
+ COPY --from=builder /app/dist ./dist
554
+ COPY --from=builder /app/node_modules ./node_modules
555
+ COPY --from=builder /app/package.json ./
62
556
 
63
- Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).
557
+ EXPOSE 3000
558
+ CMD ["node", "dist/index.js"]
559
+ ```
560
+
561
+ ### Using Vercel
562
+
563
+ ```json
564
+ // vercel.json
565
+ {
566
+ "version": 2,
567
+ "builds": [
568
+ {
569
+ "src": "api/index.ts",
570
+ "use": "@vercel/node"
571
+ }
572
+ ],
573
+ "routes": [
574
+ {
575
+ "src": "/(.*)",
576
+ "dest": "/api"
577
+ }
578
+ ]
579
+ }
580
+ ```
581
+
582
+ ```typescript
583
+ // api/index.ts
584
+ import { bootstrap } from '@social.dev/server-sdk/bootstrap';
585
+
586
+ export default async function handler(req, res) {
587
+ const app = await bootstrap({
588
+ // Your configuration
589
+ });
590
+ return app.getHttpAdapter().getInstance()(req, res);
591
+ }
592
+ ```
593
+
594
+ ## Multi-Network Support
595
+
596
+ The SDK supports running multiple isolated networks on a single server instance:
597
+
598
+ ```typescript
599
+ bootstrap({
600
+ network: {
601
+ domainAliasMap: {
602
+ 'network1.example.com': 1,
603
+ 'network2.example.com': 2,
604
+ 'api.company.com': 3,
605
+ },
606
+ },
607
+ });
608
+
609
+ // Each domain will have isolated:
610
+ // - Users and authentication
611
+ // - Posts and content
612
+ // - Communities
613
+ // - Chat conversations
614
+ // - Notifications
615
+ ```
616
+
617
+ ## Security Best Practices
618
+
619
+ 1. **Environment Variables**: Never commit `.env` files to version control
620
+ 2. **Database**: Always disable `synchronize` in production
621
+ 3. **CORS**: Configure allowed origins in production
622
+ 4. **Rate Limiting**: Implement rate limiting for API endpoints
623
+ 5. **Input Validation**: Use DTOs with class-validator for all inputs
624
+ 6. **Authentication**: Use strong JWT secrets and appropriate expiration times
625
+ 7. **HTTPS**: Always use HTTPS in production
626
+
627
+ ## TypeScript Support
628
+
629
+ The SDK is written in TypeScript and provides full type definitions:
630
+
631
+ ```typescript
632
+ import type {
633
+ User,
634
+ Post,
635
+ Sub,
636
+ Message,
637
+ Conversation,
638
+ AuthMethodEnum,
639
+ OidcProvider,
640
+ Configs,
641
+ } from '@social.dev/server-sdk';
642
+ ```
643
+
644
+ ## Examples
645
+
646
+ Check out the [apps/server](../../apps/server) directory for a complete implementation example using the SDK.
647
+
648
+ ### Example Server Implementation
649
+
650
+ ```typescript
651
+ // apps/server/index.ts
652
+ import SocialDevAiPlugin from '@social.dev/plugin-ai';
653
+ import { AuthMethodEnum } from '@social.dev/server-sdk/auth/enums/auth-method.enum';
654
+ import { PluginFactory } from '@social.dev/server-sdk/core/plugin/plugin.factory';
655
+
656
+ // Initialize plugins
657
+ PluginFactory.addPlugin(
658
+ SocialDevAiPlugin.forRoot({
659
+ userIds: [3],
660
+ })
661
+ );
662
+
663
+ // Initialize the server
664
+ import('@social.dev/server-sdk/bootstrap').then(({ bootstrap }) => {
665
+ bootstrap({
666
+ auth: {
667
+ methods: [AuthMethodEnum.Oidc],
668
+ oidc: {
669
+ providers: [
670
+ {
671
+ id: 'minds-inc',
672
+ name: 'Minds Keycloak',
673
+ issuer: 'https://keycloak.minds.com/auth/realms/minds-inc',
674
+ clientId: 'demo-social-dev',
675
+ clientSecret: process.env.SOCIAL_DEV_OIDC_SECRET,
676
+ },
677
+ ],
678
+ },
679
+ },
680
+ network: {
681
+ domainAliasMap: {
682
+ localhost: 2,
683
+ },
684
+ },
685
+ });
686
+ });
687
+ ```
688
+
689
+ ## Troubleshooting
64
690
 
65
- ## Stay in touch
691
+ ### Common Issues
66
692
 
67
- - Author - [Kamil Myśliwiec](https://twitter.com/kammysliwiec)
68
- - Website - [https://nestjs.com](https://nestjs.com/)
69
- - Twitter - [@nestframework](https://twitter.com/nestframework)
693
+ 1. **Database Connection Failed**
694
+ - Check PostgreSQL is running
695
+ - Verify database credentials in `.env`
696
+ - Ensure database exists
697
+
698
+ 2. **Port Already in Use**
699
+ - Change `SOCIAL_DEV_SERVER_PORT` in `.env`
700
+ - Kill existing process: `lsof -i :3000`
701
+
702
+ 3. **Migration Errors**
703
+ - Build the SDK first: `pnpm build`
704
+ - Check database permissions
705
+ - Review migration SQL for conflicts
706
+
707
+ 4. **OIDC Authentication Failed**
708
+ - Verify issuer URL is accessible
709
+ - Check client ID and secret
710
+ - Ensure redirect URIs are configured
711
+
712
+ ## Contributing
713
+
714
+ Contributions are welcome! Please read our contributing guidelines before submitting PRs.
70
715
 
71
716
  ## License
72
717
 
73
- Nest is [MIT licensed](https://github.com/nestjs/nest/blob/master/LICENSE).
718
+ MIT
719
+
720
+ ## Support
721
+
722
+ - [Documentation](https://docs.social.dev)
723
+ - [GitHub Issues](https://github.com/socialdotdev/social.dev/issues)
724
+ - [Discord Community](https://discord.gg/socialdev)