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