sidekick-server-2 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +223 -0
- package/dist/ai/index.d.ts +2 -0
- package/dist/ai/index.d.ts.map +1 -0
- package/dist/ai/index.js +2 -0
- package/dist/ai/index.js.map +1 -0
- package/dist/ai/perplexity-ai.d.ts +3 -0
- package/dist/ai/perplexity-ai.d.ts.map +1 -0
- package/dist/ai/perplexity-ai.js +28 -0
- package/dist/ai/perplexity-ai.js.map +1 -0
- package/dist/app-config.d.ts +13 -0
- package/dist/app-config.d.ts.map +1 -0
- package/dist/app-config.js +33 -0
- package/dist/app-config.js.map +1 -0
- package/dist/cors-config.d.ts +9 -0
- package/dist/cors-config.d.ts.map +1 -0
- package/dist/cors-config.js +24 -0
- package/dist/cors-config.js.map +1 -0
- package/dist/db-connection.d.ts +13 -0
- package/dist/db-connection.d.ts.map +1 -0
- package/dist/db-connection.js +22 -0
- package/dist/db-connection.js.map +1 -0
- package/dist/error-handler.d.ts +3 -0
- package/dist/error-handler.d.ts.map +1 -0
- package/dist/error-handler.js +15 -0
- package/dist/error-handler.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +87 -0
- package/dist/index.js.map +1 -0
- package/dist/local-cache.d.ts +14 -0
- package/dist/local-cache.d.ts.map +1 -0
- package/dist/local-cache.js +44 -0
- package/dist/local-cache.js.map +1 -0
- package/dist/r2-buckets/get-signed-url.d.ts +2 -0
- package/dist/r2-buckets/get-signed-url.d.ts.map +1 -0
- package/dist/r2-buckets/get-signed-url.js +22 -0
- package/dist/r2-buckets/get-signed-url.js.map +1 -0
- package/dist/r2-buckets/index.d.ts +3 -0
- package/dist/r2-buckets/index.d.ts.map +1 -0
- package/dist/r2-buckets/index.js +3 -0
- package/dist/r2-buckets/index.js.map +1 -0
- package/dist/r2-buckets/r2-client.d.ts +3 -0
- package/dist/r2-buckets/r2-client.d.ts.map +1 -0
- package/dist/r2-buckets/r2-client.js +18 -0
- package/dist/r2-buckets/r2-client.js.map +1 -0
- package/dist/r2-buckets/upload-r2.d.ts +11 -0
- package/dist/r2-buckets/upload-r2.d.ts.map +1 -0
- package/dist/r2-buckets/upload-r2.js +49 -0
- package/dist/r2-buckets/upload-r2.js.map +1 -0
- package/dist/routes/authentication/check-session.d.ts +4 -0
- package/dist/routes/authentication/check-session.d.ts.map +1 -0
- package/dist/routes/authentication/check-session.js +79 -0
- package/dist/routes/authentication/check-session.js.map +1 -0
- package/dist/routes/authentication/login-router.d.ts +3 -0
- package/dist/routes/authentication/login-router.d.ts.map +1 -0
- package/dist/routes/authentication/login-router.js +83 -0
- package/dist/routes/authentication/login-router.js.map +1 -0
- package/dist/routes/authentication/reset-password.d.ts +3 -0
- package/dist/routes/authentication/reset-password.d.ts.map +1 -0
- package/dist/routes/authentication/reset-password.js +92 -0
- package/dist/routes/authentication/reset-password.js.map +1 -0
- package/dist/routes/authentication/send-otp-router.d.ts +3 -0
- package/dist/routes/authentication/send-otp-router.d.ts.map +1 -0
- package/dist/routes/authentication/send-otp-router.js +89 -0
- package/dist/routes/authentication/send-otp-router.js.map +1 -0
- package/dist/routes/authentication/user-profile.d.ts +3 -0
- package/dist/routes/authentication/user-profile.d.ts.map +1 -0
- package/dist/routes/authentication/user-profile.js +44 -0
- package/dist/routes/authentication/user-profile.js.map +1 -0
- package/dist/routes/authentication/user-registration-router.d.ts +3 -0
- package/dist/routes/authentication/user-registration-router.d.ts.map +1 -0
- package/dist/routes/authentication/user-registration-router.js +120 -0
- package/dist/routes/authentication/user-registration-router.js.map +1 -0
- package/dist/routes/authentication/validator.d.ts +14 -0
- package/dist/routes/authentication/validator.d.ts.map +1 -0
- package/dist/routes/authentication/validator.js +69 -0
- package/dist/routes/authentication/validator.js.map +1 -0
- package/dist/routes/countries/countries-router.d.ts +3 -0
- package/dist/routes/countries/countries-router.d.ts.map +1 -0
- package/dist/routes/countries/countries-router.js +23 -0
- package/dist/routes/countries/countries-router.js.map +1 -0
- package/dist/routes/feature-flags/feature-flags.d.ts +5 -0
- package/dist/routes/feature-flags/feature-flags.d.ts.map +1 -0
- package/dist/routes/feature-flags/feature-flags.js +28 -0
- package/dist/routes/feature-flags/feature-flags.js.map +1 -0
- package/dist/routes/index.d.ts +9 -0
- package/dist/routes/index.d.ts.map +1 -0
- package/dist/routes/index.js +92 -0
- package/dist/routes/index.js.map +1 -0
- package/dist/routes/link-metadata.d.ts +3 -0
- package/dist/routes/link-metadata.d.ts.map +1 -0
- package/dist/routes/link-metadata.js +34 -0
- package/dist/routes/link-metadata.js.map +1 -0
- package/dist/routes/orgs/index.d.ts +2 -0
- package/dist/routes/orgs/index.d.ts.map +1 -0
- package/dist/routes/orgs/index.js +2 -0
- package/dist/routes/orgs/index.js.map +1 -0
- package/dist/routes/orgs/invitation.d.ts +3 -0
- package/dist/routes/orgs/invitation.d.ts.map +1 -0
- package/dist/routes/orgs/invitation.js +103 -0
- package/dist/routes/orgs/invitation.js.map +1 -0
- package/dist/routes/orgs/org-delete.d.ts +3 -0
- package/dist/routes/orgs/org-delete.d.ts.map +1 -0
- package/dist/routes/orgs/org-delete.js +53 -0
- package/dist/routes/orgs/org-delete.js.map +1 -0
- package/dist/routes/orgs/org-get.d.ts +3 -0
- package/dist/routes/orgs/org-get.d.ts.map +1 -0
- package/dist/routes/orgs/org-get.js +45 -0
- package/dist/routes/orgs/org-get.js.map +1 -0
- package/dist/routes/orgs/org-members.d.ts +12 -0
- package/dist/routes/orgs/org-members.d.ts.map +1 -0
- package/dist/routes/orgs/org-members.js +560 -0
- package/dist/routes/orgs/org-members.js.map +1 -0
- package/dist/routes/orgs/org-post.d.ts +3 -0
- package/dist/routes/orgs/org-post.d.ts.map +1 -0
- package/dist/routes/orgs/org-post.js +89 -0
- package/dist/routes/orgs/org-post.js.map +1 -0
- package/dist/routes/orgs/org-put.d.ts +3 -0
- package/dist/routes/orgs/org-put.d.ts.map +1 -0
- package/dist/routes/orgs/org-put.js +87 -0
- package/dist/routes/orgs/org-put.js.map +1 -0
- package/dist/routes/orgs/org-registration-router.d.ts +3 -0
- package/dist/routes/orgs/org-registration-router.d.ts.map +1 -0
- package/dist/routes/orgs/org-registration-router.js +12 -0
- package/dist/routes/orgs/org-registration-router.js.map +1 -0
- package/dist/routes/orgs/org-utils.d.ts +14 -0
- package/dist/routes/orgs/org-utils.d.ts.map +1 -0
- package/dist/routes/orgs/org-utils.js +234 -0
- package/dist/routes/orgs/org-utils.js.map +1 -0
- package/dist/routes/orgs/premium-org-utils.d.ts +3 -0
- package/dist/routes/orgs/premium-org-utils.d.ts.map +1 -0
- package/dist/routes/orgs/premium-org-utils.js +61 -0
- package/dist/routes/orgs/premium-org-utils.js.map +1 -0
- package/dist/routes/paid-plans/billingsdk-config.d.ts +36 -0
- package/dist/routes/paid-plans/billingsdk-config.d.ts.map +1 -0
- package/dist/routes/paid-plans/billingsdk-config.js +2 -0
- package/dist/routes/paid-plans/billingsdk-config.js.map +1 -0
- package/dist/routes/paid-plans/get-subscription-config.d.ts +3 -0
- package/dist/routes/paid-plans/get-subscription-config.d.ts.map +1 -0
- package/dist/routes/paid-plans/get-subscription-config.js +25 -0
- package/dist/routes/paid-plans/get-subscription-config.js.map +1 -0
- package/dist/routes/paid-plans/payment-gateway.d.ts +3 -0
- package/dist/routes/paid-plans/payment-gateway.d.ts.map +1 -0
- package/dist/routes/paid-plans/payment-gateway.js +324 -0
- package/dist/routes/paid-plans/payment-gateway.js.map +1 -0
- package/dist/routes/paid-plans/purchased-plans.d.ts +8 -0
- package/dist/routes/paid-plans/purchased-plans.d.ts.map +1 -0
- package/dist/routes/paid-plans/purchased-plans.js +191 -0
- package/dist/routes/paid-plans/purchased-plans.js.map +1 -0
- package/dist/routes/paid-plans/subscription-utils.d.ts +25 -0
- package/dist/routes/paid-plans/subscription-utils.d.ts.map +1 -0
- package/dist/routes/paid-plans/subscription-utils.js +156 -0
- package/dist/routes/paid-plans/subscription-utils.js.map +1 -0
- package/dist/s3-buckets/get-signed-url.d.ts +2 -0
- package/dist/s3-buckets/get-signed-url.d.ts.map +1 -0
- package/dist/s3-buckets/get-signed-url.js +22 -0
- package/dist/s3-buckets/get-signed-url.js.map +1 -0
- package/dist/s3-buckets/index.d.ts +3 -0
- package/dist/s3-buckets/index.d.ts.map +1 -0
- package/dist/s3-buckets/index.js +3 -0
- package/dist/s3-buckets/index.js.map +1 -0
- package/dist/s3-buckets/s3-client.d.ts +3 -0
- package/dist/s3-buckets/s3-client.d.ts.map +1 -0
- package/dist/s3-buckets/s3-client.js +17 -0
- package/dist/s3-buckets/s3-client.js.map +1 -0
- package/dist/s3-buckets/upload-s3.d.ts +11 -0
- package/dist/s3-buckets/upload-s3.d.ts.map +1 -0
- package/dist/s3-buckets/upload-s3.js +51 -0
- package/dist/s3-buckets/upload-s3.js.map +1 -0
- package/dist/secret.d.ts +4 -0
- package/dist/secret.d.ts.map +1 -0
- package/dist/secret.js +11 -0
- package/dist/secret.js.map +1 -0
- package/dist/socket-config.d.ts +4 -0
- package/dist/socket-config.d.ts.map +1 -0
- package/dist/socket-config.js +23 -0
- package/dist/socket-config.js.map +1 -0
- package/dist/types.d.ts +141 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/common-utils.d.ts +61 -0
- package/dist/utils/common-utils.d.ts.map +1 -0
- package/dist/utils/common-utils.js +99 -0
- package/dist/utils/common-utils.js.map +1 -0
- package/dist/utils/email-helper.d.ts +6 -0
- package/dist/utils/email-helper.d.ts.map +1 -0
- package/dist/utils/email-helper.js +33 -0
- package/dist/utils/email-helper.js.map +1 -0
- package/dist/utils/enums.d.ts +17 -0
- package/dist/utils/enums.d.ts.map +1 -0
- package/dist/utils/enums.js +27 -0
- package/dist/utils/enums.js.map +1 -0
- package/dist/utils/error-logger.d.ts +4 -0
- package/dist/utils/error-logger.d.ts.map +1 -0
- package/dist/utils/error-logger.js +30 -0
- package/dist/utils/error-logger.js.map +1 -0
- package/dist/utils/index.d.ts +9 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +9 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/otp-helper.d.ts +5 -0
- package/dist/utils/otp-helper.d.ts.map +1 -0
- package/dist/utils/otp-helper.js +89 -0
- package/dist/utils/otp-helper.js.map +1 -0
- package/dist/utils/response-utils.d.ts +8 -0
- package/dist/utils/response-utils.d.ts.map +1 -0
- package/dist/utils/response-utils.js +37 -0
- package/dist/utils/response-utils.js.map +1 -0
- package/dist/utils/sql-helper.d.ts +27 -0
- package/dist/utils/sql-helper.d.ts.map +1 -0
- package/dist/utils/sql-helper.js +97 -0
- package/dist/utils/sql-helper.js.map +1 -0
- package/dist/utils/type.d.ts +81 -0
- package/dist/utils/type.d.ts.map +1 -0
- package/dist/utils/type.js +2 -0
- package/dist/utils/type.js.map +1 -0
- package/package.json +70 -0
package/README.md
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
# SideKick Server
|
|
2
|
+
|
|
3
|
+
A reusable Node.js server library with built-in authentication, organization management, and payment integration. Built with Express, TypeScript, and MySQL.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🔐 **Authentication System** - JWT-based authentication with OTP support
|
|
8
|
+
- 👥 **Organization Management** - Multi-tenant organization structure with invitations
|
|
9
|
+
- 💳 **Payment Integration** - Razorpay integration for subscription plans
|
|
10
|
+
- 🌍 **CORS Configuration** - Flexible CORS setup
|
|
11
|
+
- 📧 **Email Support** - Nodemailer integration
|
|
12
|
+
- 🔌 **Extensible** - Add custom routes and middleware
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install sidekick-server
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### Peer Dependencies
|
|
21
|
+
|
|
22
|
+
You need to install these peer dependencies in your project:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm install express cors mysql2
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Quick Start
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import mysql from 'mysql2/promise';
|
|
32
|
+
import { initSideKick } from 'sidekick-server';
|
|
33
|
+
import { APP_INFO_ACCOUNT_TYPE } from 'sidekick-server/dist/utils/enums.js';
|
|
34
|
+
|
|
35
|
+
// Create database connection pool
|
|
36
|
+
const dbPool = mysql.createPool({
|
|
37
|
+
host: 'localhost',
|
|
38
|
+
user: 'root',
|
|
39
|
+
password: 'your-password',
|
|
40
|
+
database: 'your-database',
|
|
41
|
+
waitForConnections: true,
|
|
42
|
+
connectionLimit: 10,
|
|
43
|
+
queueLimit: 0,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// Initialize SideKick server
|
|
47
|
+
const server = initSideKick({
|
|
48
|
+
database: dbPool,
|
|
49
|
+
appInfo: {
|
|
50
|
+
appName: 'My App',
|
|
51
|
+
appDescription: 'My awesome application',
|
|
52
|
+
version: '1.0.0',
|
|
53
|
+
CLIENT_URL: 'http://localhost:3000',
|
|
54
|
+
account_type_txt: {
|
|
55
|
+
singular: 'Team',
|
|
56
|
+
plural: 'Teams',
|
|
57
|
+
value: APP_INFO_ACCOUNT_TYPE.TEAM,
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
cors: {
|
|
61
|
+
allowedOrigins: ['http://localhost:3000', 'https://myapp.com'],
|
|
62
|
+
},
|
|
63
|
+
jwt: {
|
|
64
|
+
secret: 'your-jwt-secret',
|
|
65
|
+
expiresIn: '24h',
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// Start the server
|
|
70
|
+
const PORT = process.env.PORT || 3000;
|
|
71
|
+
server.listen(PORT, () => {
|
|
72
|
+
console.log(`Server running on port ${PORT}`);
|
|
73
|
+
});
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Configuration
|
|
77
|
+
|
|
78
|
+
### SideKickConfig
|
|
79
|
+
|
|
80
|
+
| Property | Type | Required | Description |
|
|
81
|
+
| -------------- | --------------------- | -------- | --------------------------- |
|
|
82
|
+
| `database` | `Pool` | Yes | MySQL2 connection pool |
|
|
83
|
+
| `appInfo` | `AppInfo` | Yes | Application information |
|
|
84
|
+
| `cors` | `CorsConfig` | Yes | CORS configuration |
|
|
85
|
+
| `jwt` | `JwtConfig` | Yes | JWT configuration |
|
|
86
|
+
| `customRoutes` | `CustomRoutesHandler` | No | Custom route handler |
|
|
87
|
+
| `port` | `number` | No | Port number (for reference) |
|
|
88
|
+
|
|
89
|
+
### AppInfo
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
{
|
|
93
|
+
appName: string;
|
|
94
|
+
appDescription: string;
|
|
95
|
+
version: string;
|
|
96
|
+
logo?: string; // SVG or image URL
|
|
97
|
+
primaryThemeColor?: string; // Hex color
|
|
98
|
+
CLIENT_URL: string; // Frontend URL
|
|
99
|
+
account_type_txt: {
|
|
100
|
+
singular: string;
|
|
101
|
+
plural: string;
|
|
102
|
+
value: typeof APP_INFO_ACCOUNT_TYPE.TEAM;
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Custom Routes
|
|
108
|
+
|
|
109
|
+
You can add custom routes to extend the server functionality:
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
const server = initSideKick({
|
|
113
|
+
// ... other config
|
|
114
|
+
customRoutes: (app) => {
|
|
115
|
+
app.get('/custom-endpoint', (req, res) => {
|
|
116
|
+
res.json({ message: 'Custom route!' });
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
app.post('/custom-action', async (req, res) => {
|
|
120
|
+
// Your custom logic
|
|
121
|
+
res.json({ success: true });
|
|
122
|
+
});
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Built-in Routes
|
|
128
|
+
|
|
129
|
+
The library includes the following routes:
|
|
130
|
+
|
|
131
|
+
### Public Routes (No Authentication Required)
|
|
132
|
+
|
|
133
|
+
- `POST /send-otp` - Send OTP for verification
|
|
134
|
+
- `POST /user-registration` - Register new user
|
|
135
|
+
- `POST /login` - User login
|
|
136
|
+
- `POST /reset-password` - Reset password
|
|
137
|
+
- `GET /get-plans` - Get available subscription plans
|
|
138
|
+
|
|
139
|
+
### Protected Routes (Authentication Required)
|
|
140
|
+
|
|
141
|
+
- `GET /check-session` - Verify session
|
|
142
|
+
- `POST /organization` - Create organization
|
|
143
|
+
- `GET /org-member` - Get organization members
|
|
144
|
+
- `POST /invitation` - Send invitation
|
|
145
|
+
- `GET /get-countries` - Get countries list
|
|
146
|
+
- `POST /payment-gateway` - Payment gateway integration
|
|
147
|
+
- `GET /purchased-plans` - Get purchased plans
|
|
148
|
+
|
|
149
|
+
## Environment Variables
|
|
150
|
+
|
|
151
|
+
While the library doesn't use `.env` files directly, you may want to use them in your application:
|
|
152
|
+
|
|
153
|
+
```env
|
|
154
|
+
PORT=3000
|
|
155
|
+
DB_HOST=localhost
|
|
156
|
+
DB_USER=root
|
|
157
|
+
DB_PASSWORD=your-password
|
|
158
|
+
DB_NAME=your-database
|
|
159
|
+
JWT_SECRET=your-jwt-secret
|
|
160
|
+
CLIENT_URL=http://localhost:3000
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## TypeScript Support
|
|
164
|
+
|
|
165
|
+
The library is written in TypeScript and includes type definitions. Import types as needed:
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
import { SideKickConfig, AppInfo, CorsConfig, JwtConfig, CustomRoutesHandler, DatabaseConnection } from 'sidekick-server';
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## Development
|
|
172
|
+
|
|
173
|
+
If you want to contribute or modify the library:
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
# Clone the repository
|
|
177
|
+
git clone <repository-url>
|
|
178
|
+
|
|
179
|
+
# Install dependencies
|
|
180
|
+
npm install
|
|
181
|
+
|
|
182
|
+
# Install peer dependencies for development
|
|
183
|
+
npm install express cors mysql2
|
|
184
|
+
|
|
185
|
+
# Build the library
|
|
186
|
+
npm run build
|
|
187
|
+
|
|
188
|
+
# Run in development mode
|
|
189
|
+
npm run dev
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## Local Testing with Yalc
|
|
193
|
+
|
|
194
|
+
For local testing before publishing to npm, use [yalc](https://github.com/wclr/yalc):
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
# Install yalc globally (if not already installed)
|
|
198
|
+
npm install -g yalc
|
|
199
|
+
|
|
200
|
+
# In the library directory
|
|
201
|
+
npm run build:yalc
|
|
202
|
+
# or
|
|
203
|
+
yalc publish
|
|
204
|
+
|
|
205
|
+
# In your test project
|
|
206
|
+
yalc add sidekick-server
|
|
207
|
+
npm install
|
|
208
|
+
|
|
209
|
+
# After making changes to the library
|
|
210
|
+
npm run build:yalc # Automatically builds and pushes to yalc
|
|
211
|
+
|
|
212
|
+
# To remove from test project
|
|
213
|
+
yalc remove sidekick-server
|
|
214
|
+
npm install
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## License
|
|
218
|
+
|
|
219
|
+
ISC
|
|
220
|
+
|
|
221
|
+
## Author
|
|
222
|
+
|
|
223
|
+
Trinesh Lokhande
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ai/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC"}
|
package/dist/ai/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ai/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"perplexity-ai.d.ts","sourceRoot":"","sources":["../../src/ai/perplexity-ai.ts"],"names":[],"mappings":"AAIA,QAAA,MAAM,eAAe,GAAU,QAAQ,MAAM,iBAwB5C,CAAC;AAEF,OAAO,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { getSecretValue } from '../secret.js';
|
|
3
|
+
import logger from '../utils/error-logger.js';
|
|
4
|
+
const queryPerplexity = async (prompt) => {
|
|
5
|
+
const url = 'https://api.perplexity.ai/chat/completions'; // Perplexity chat endpoint
|
|
6
|
+
const data = {
|
|
7
|
+
model: 'sonar',
|
|
8
|
+
messages: [
|
|
9
|
+
{ role: 'system', content: 'You are a Grammar checker' },
|
|
10
|
+
{ role: 'user', content: prompt },
|
|
11
|
+
],
|
|
12
|
+
};
|
|
13
|
+
const apiKey = getSecretValue('perplexityApiKey');
|
|
14
|
+
const headers = {
|
|
15
|
+
Authorization: `Bearer ${apiKey}`,
|
|
16
|
+
Accept: 'application/json',
|
|
17
|
+
};
|
|
18
|
+
try {
|
|
19
|
+
const response = await axios.post(url, data, { headers });
|
|
20
|
+
return response.data;
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
logger.error('Error querying Perplexity API:', error.response?.data || error.message);
|
|
24
|
+
throw error;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
export { queryPerplexity };
|
|
28
|
+
//# sourceMappingURL=perplexity-ai.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"perplexity-ai.js","sourceRoot":"","sources":["../../src/ai/perplexity-ai.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,MAAM,MAAM,0BAA0B,CAAC;AAE9C,MAAM,eAAe,GAAG,KAAK,EAAE,MAAc,EAAE,EAAE;IAC/C,MAAM,GAAG,GAAG,4CAA4C,CAAC,CAAC,2BAA2B;IAErF,MAAM,IAAI,GAAG;QACX,KAAK,EAAE,OAAO;QACd,QAAQ,EAAE;YACR,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,2BAA2B,EAAE;YACxD,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE;SAClC;KACF,CAAC;IAEF,MAAM,MAAM,GAAG,cAAc,CAAC,kBAAkB,CAAC,CAAC;IAClD,MAAM,OAAO,GAAG;QACd,aAAa,EAAE,UAAU,MAAM,EAAE;QACjC,MAAM,EAAE,kBAAkB;KAC3B,CAAC;IAEF,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;QAC1D,OAAO,QAAQ,CAAC,IAAI,CAAC;IACvB,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,MAAM,CAAC,KAAK,CAAC,gCAAgC,EAAE,KAAK,CAAC,QAAQ,EAAE,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;QACtF,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC,CAAC;AAEF,OAAO,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AppInfo } from './types.js';
|
|
2
|
+
export declare const APP_INFO_ACCOUNT_TYPE: {
|
|
3
|
+
TEAM: string;
|
|
4
|
+
ORG: string;
|
|
5
|
+
};
|
|
6
|
+
export declare let appInfo: AppInfo;
|
|
7
|
+
/**
|
|
8
|
+
* Set application configuration
|
|
9
|
+
* @param config - Application information configuration
|
|
10
|
+
*/
|
|
11
|
+
export declare const setAppConfig: (config: AppInfo) => void;
|
|
12
|
+
export declare const setAccountType: (type?: Partial<typeof APP_INFO_ACCOUNT_TYPE>) => void;
|
|
13
|
+
//# sourceMappingURL=app-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-config.d.ts","sourceRoot":"","sources":["../src/app-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,eAAO,MAAM,qBAAqB;;;CAGjC,CAAC;AAGF,eAAO,IAAI,OAAO,EAAE,OAcnB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,YAAY,GAAI,QAAQ,OAAO,KAAG,IAE9C,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,OAAO,OAAO,CAAC,OAAO,qBAAqB,CAAC,SAG1E,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export const APP_INFO_ACCOUNT_TYPE = {
|
|
2
|
+
TEAM: 'team',
|
|
3
|
+
ORG: 'org',
|
|
4
|
+
};
|
|
5
|
+
// Default app info (can be overridden via setAppConfig)
|
|
6
|
+
export let appInfo = {
|
|
7
|
+
appId: 'gamma_tech',
|
|
8
|
+
appName: 'Gamma Tech',
|
|
9
|
+
appDescription: 'Gamma Tech is a software company that provides a range of services to help businesses grow and succeed.',
|
|
10
|
+
version: '2.0.1',
|
|
11
|
+
logo: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-notebook-text-icon lucide-notebook-text"><path d="M2 6h4"/><path d="M2 10h4"/><path d="M2 14h4"/><path d="M2 18h4"/><rect width="16" height="20" x="4" y="2" rx="2"/><path d="M9.5 8h5"/><path d="M9.5 12H16"/><path d="M9.5 16H14"/></svg>',
|
|
12
|
+
primaryThemeColor: '#00c950',
|
|
13
|
+
CLIENT_URL: 'http://localhost:5173',
|
|
14
|
+
supportEmail: 'support@gammatech.com',
|
|
15
|
+
account_type_txt: {
|
|
16
|
+
singular: 'Team',
|
|
17
|
+
plural: 'Teams',
|
|
18
|
+
value: APP_INFO_ACCOUNT_TYPE.TEAM,
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Set application configuration
|
|
23
|
+
* @param config - Application information configuration
|
|
24
|
+
*/
|
|
25
|
+
export const setAppConfig = (config) => {
|
|
26
|
+
appInfo = config;
|
|
27
|
+
};
|
|
28
|
+
export const setAccountType = (type) => {
|
|
29
|
+
if (!type)
|
|
30
|
+
return;
|
|
31
|
+
Object.assign(APP_INFO_ACCOUNT_TYPE, type);
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=app-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-config.js","sourceRoot":"","sources":["../src/app-config.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,IAAI,EAAE,MAAM;IACZ,GAAG,EAAE,KAAK;CACX,CAAC;AAEF,wDAAwD;AACxD,MAAM,CAAC,IAAI,OAAO,GAAY;IAC5B,KAAK,EAAE,YAAY;IACnB,OAAO,EAAE,YAAY;IACrB,cAAc,EAAE,yGAAyG;IACzH,OAAO,EAAE,OAAO;IAChB,IAAI,EAAE,ubAAub;IAC7b,iBAAiB,EAAE,SAAS;IAC5B,UAAU,EAAE,uBAAuB;IACnC,YAAY,EAAE,uBAAuB;IACrC,gBAAgB,EAAE;QAChB,QAAQ,EAAE,MAAM;QAChB,MAAM,EAAE,OAAO;QACf,KAAK,EAAE,qBAAqB,CAAC,IAAI;KAClC;CACF,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,MAAe,EAAQ,EAAE;IACpD,OAAO,GAAG,MAAM,CAAC;AACnB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,IAA4C,EAAE,EAAE;IAC7E,IAAI,CAAC,IAAI;QAAE,OAAO;IAClB,MAAM,CAAC,MAAM,CAAC,qBAAqB,EAAE,IAAI,CAAC,CAAC;AAC7C,CAAC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import cors from 'cors';
|
|
2
|
+
/**
|
|
3
|
+
* Create CORS configuration
|
|
4
|
+
* @param allowedOrigins - Array of allowed origin URLs
|
|
5
|
+
* @returns CORS options object
|
|
6
|
+
*/
|
|
7
|
+
declare const corsConfig: (allowedOrigins: string[]) => cors.CorsOptions;
|
|
8
|
+
export default corsConfig;
|
|
9
|
+
//# sourceMappingURL=cors-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cors-config.d.ts","sourceRoot":"","sources":["../src/cors-config.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB;;;;GAIG;AACH,QAAA,MAAM,UAAU,GAAI,gBAAgB,MAAM,EAAE,KAAG,IAAI,CAAC,WAiBnD,CAAC;AAEF,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create CORS configuration
|
|
3
|
+
* @param allowedOrigins - Array of allowed origin URLs
|
|
4
|
+
* @returns CORS options object
|
|
5
|
+
*/
|
|
6
|
+
const corsConfig = (allowedOrigins) => {
|
|
7
|
+
const corsOptions = {
|
|
8
|
+
origin: (origin, callback) => {
|
|
9
|
+
// Allow requests with no origin (like curl, mobile apps, or same-origin requests)
|
|
10
|
+
if (!origin) {
|
|
11
|
+
return callback(null, true);
|
|
12
|
+
}
|
|
13
|
+
if (allowedOrigins.length === 0 || (origin && allowedOrigins.includes(origin))) {
|
|
14
|
+
callback(null, true); // Allow request
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
callback(new Error(`CORS Error: This ${origin || 'empty'} origin is not allowed.`)); // Block request
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
return corsOptions;
|
|
22
|
+
};
|
|
23
|
+
export default corsConfig;
|
|
24
|
+
//# sourceMappingURL=cors-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cors-config.js","sourceRoot":"","sources":["../src/cors-config.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,UAAU,GAAG,CAAC,cAAwB,EAAoB,EAAE;IAChE,MAAM,WAAW,GAAqB;QACpC,MAAM,EAAE,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE;YAC3B,kFAAkF;YAClF,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,OAAO,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YAC9B,CAAC;YAED,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,MAAM,IAAI,cAAc,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC;gBAC/E,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,gBAAgB;YACxC,CAAC;iBAAM,CAAC;gBACN,QAAQ,CAAC,IAAI,KAAK,CAAC,oBAAoB,MAAM,IAAI,OAAO,yBAAyB,CAAC,CAAC,CAAC,CAAC,gBAAgB;YACvG,CAAC;QACH,CAAC;KACF,CAAC;IAEF,OAAO,WAAW,CAAC;AACrB,CAAC,CAAC;AAEF,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Pool } from 'mysql2/promise';
|
|
2
|
+
/**
|
|
3
|
+
* Set the database connection pool
|
|
4
|
+
* @param pool - MySQL2 connection pool provided by the user
|
|
5
|
+
*/
|
|
6
|
+
export declare const setDatabaseConnection: (pool: Pool) => void;
|
|
7
|
+
/**
|
|
8
|
+
* Get the database connection pool
|
|
9
|
+
* @throws Error if database connection is not set
|
|
10
|
+
*/
|
|
11
|
+
export declare const getDatabaseConnection: () => Pool;
|
|
12
|
+
export default getDatabaseConnection;
|
|
13
|
+
//# sourceMappingURL=db-connection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"db-connection.d.ts","sourceRoot":"","sources":["../src/db-connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAKtC;;;GAGG;AACH,eAAO,MAAM,qBAAqB,GAAI,MAAM,IAAI,KAAG,IAElD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,qBAAqB,QAAO,IAKxC,CAAC;AAGF,eAAe,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Database connection pool - must be set via setDatabaseConnection before use
|
|
2
|
+
let dbConnectionPool = null;
|
|
3
|
+
/**
|
|
4
|
+
* Set the database connection pool
|
|
5
|
+
* @param pool - MySQL2 connection pool provided by the user
|
|
6
|
+
*/
|
|
7
|
+
export const setDatabaseConnection = (pool) => {
|
|
8
|
+
dbConnectionPool = pool;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Get the database connection pool
|
|
12
|
+
* @throws Error if database connection is not set
|
|
13
|
+
*/
|
|
14
|
+
export const getDatabaseConnection = () => {
|
|
15
|
+
if (!dbConnectionPool) {
|
|
16
|
+
throw new Error('Database connection not initialized. Call setDatabaseConnection() first.');
|
|
17
|
+
}
|
|
18
|
+
return dbConnectionPool;
|
|
19
|
+
};
|
|
20
|
+
// Default export for backward compatibility
|
|
21
|
+
export default getDatabaseConnection;
|
|
22
|
+
//# sourceMappingURL=db-connection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"db-connection.js","sourceRoot":"","sources":["../src/db-connection.ts"],"names":[],"mappings":"AAEA,8EAA8E;AAC9E,IAAI,gBAAgB,GAAgB,IAAI,CAAC;AAEzC;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,IAAU,EAAQ,EAAE;IACxD,gBAAgB,GAAG,IAAI,CAAC;AAC1B,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAS,EAAE;IAC9C,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC,0EAA0E,CAAC,CAAC;IAC9F,CAAC;IACD,OAAO,gBAAgB,CAAC;AAC1B,CAAC,CAAC;AAEF,4CAA4C;AAC5C,eAAe,qBAAqB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-handler.d.ts","sourceRoot":"","sources":["../src/error-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAI1D,eAAO,MAAM,YAAY,GAAI,KAAK,KAAK,EAAE,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,SAavF,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import logger from './utils/error-logger.js';
|
|
2
|
+
import { throwErrorInResponseIfErrorIsNotCustom } from './utils/response-utils.js';
|
|
3
|
+
export const errorHandler = (err, req, res, next) => {
|
|
4
|
+
logger.error({
|
|
5
|
+
...err,
|
|
6
|
+
message: err.message,
|
|
7
|
+
stack: err.stack,
|
|
8
|
+
}); // optional logging
|
|
9
|
+
throwErrorInResponseIfErrorIsNotCustom(res, err, {
|
|
10
|
+
errorMsg: 'An unexpected error occurred.',
|
|
11
|
+
solution: 'Please try again later.',
|
|
12
|
+
});
|
|
13
|
+
next(err);
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=error-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-handler.js","sourceRoot":"","sources":["../src/error-handler.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,OAAO,EAAE,sCAAsC,EAAE,MAAM,2BAA2B,CAAC;AAEnF,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,GAAU,EAAE,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;IAC1F,MAAM,CAAC,KAAK,CAAC;QACX,GAAG,GAAG;QACN,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,KAAK,EAAE,GAAG,CAAC,KAAK;KACjB,CAAC,CAAC,CAAC,mBAAmB;IAEvB,sCAAsC,CAAC,GAAG,EAAE,GAAG,EAAE;QAC/C,QAAQ,EAAE,+BAA+B;QACzC,QAAQ,EAAE,yBAAyB;KACpC,CAAC,CAAC;IAEH,IAAI,CAAC,GAAG,CAAC,CAAC;AACZ,CAAC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import http from 'http';
|
|
2
|
+
import { getCurrencySymbol } from './routes/paid-plans/subscription-utils.js';
|
|
3
|
+
import { SideKickConfig } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Initialize SideKick server with custom configuration
|
|
6
|
+
* @param config - SideKick configuration object
|
|
7
|
+
* @returns HTTP server instance (not started - call .listen() to start)
|
|
8
|
+
*/
|
|
9
|
+
export declare const initSideKick: (config: SideKickConfig) => http.Server;
|
|
10
|
+
export type { SideKickConfig, AppInfo, CorsConfig, JwtConfig, CustomRoutesHandler, DatabaseConnection } from './types.js';
|
|
11
|
+
export * from './utils/index.js';
|
|
12
|
+
export * from './routes/orgs/index.js';
|
|
13
|
+
export * from './s3-buckets/index.js';
|
|
14
|
+
export * from './local-cache.js';
|
|
15
|
+
export * from './ai/index.js';
|
|
16
|
+
export { getCurrencySymbol };
|
|
17
|
+
export type { Plan } from './routes/paid-plans/billingsdk-config.js';
|
|
18
|
+
export * from './r2-buckets/index.js';
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAcxB,OAAO,EAAE,iBAAiB,EAAsD,MAAM,2CAA2C,CAAC;AAElI,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAI5C;;;;GAIG;AACH,eAAO,MAAM,YAAY,GAAI,QAAQ,cAAc,KAAG,IAAI,CAAC,MA0E1D,CAAC;AAGF,YAAY,EAAE,cAAc,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAC1H,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,iBAAiB,EAAE,CAAC;AAC7B,YAAY,EAAE,IAAI,EAAE,MAAM,0CAA0C,CAAC;AACrE,cAAc,uBAAuB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import http from 'http';
|
|
2
|
+
import cors from 'cors';
|
|
3
|
+
import express from 'express';
|
|
4
|
+
import { rateLimit } from 'express-rate-limit';
|
|
5
|
+
import helmet from 'helmet';
|
|
6
|
+
import { setAccountType, setAppConfig } from './app-config.js';
|
|
7
|
+
import corsConfig from './cors-config.js';
|
|
8
|
+
import { setDatabaseConnection } from './db-connection.js';
|
|
9
|
+
import { errorHandler } from './error-handler.js';
|
|
10
|
+
import { setFeatureFlag } from './routes/feature-flags/feature-flags.js';
|
|
11
|
+
import routes from './routes/index.js';
|
|
12
|
+
// import initSocketIO from './socket-config.js';
|
|
13
|
+
import { getCurrencySymbol, setCurrency, setFaqs, setFreePlan, setPremiumPlans } from './routes/paid-plans/subscription-utils.js';
|
|
14
|
+
import { setSecret } from './secret.js';
|
|
15
|
+
import { setEmailConfig } from './utils/email-helper.js';
|
|
16
|
+
import { updateRolesEnum } from './utils/enums.js';
|
|
17
|
+
/**
|
|
18
|
+
* Initialize SideKick server with custom configuration
|
|
19
|
+
* @param config - SideKick configuration object
|
|
20
|
+
* @returns HTTP server instance (not started - call .listen() to start)
|
|
21
|
+
*/
|
|
22
|
+
export const initSideKick = (config) => {
|
|
23
|
+
// Set configuration
|
|
24
|
+
setAppConfig(config.appInfo);
|
|
25
|
+
setAccountType(config.accountType || {});
|
|
26
|
+
setDatabaseConnection(config.database);
|
|
27
|
+
const { subscriptions } = config;
|
|
28
|
+
setCurrency(subscriptions.currency, subscriptions.currencySymbol);
|
|
29
|
+
setFreePlan(subscriptions.freePlan);
|
|
30
|
+
setPremiumPlans(subscriptions.premiumPlans);
|
|
31
|
+
setFaqs(subscriptions.faqs);
|
|
32
|
+
setEmailConfig(config.emailConfig || null);
|
|
33
|
+
setSecret(config.secretConfig || {});
|
|
34
|
+
setFeatureFlag(config.featureFlags || {});
|
|
35
|
+
updateRolesEnum(config.rolesEnum || {});
|
|
36
|
+
// Create Express app
|
|
37
|
+
const expressApp = express();
|
|
38
|
+
// Create HTTP server
|
|
39
|
+
const httpServer = http.createServer(expressApp);
|
|
40
|
+
expressApp.use(express.json({ limit: '10kb' })); // Limit body size to prevent DDoS via large payloads
|
|
41
|
+
// Security Headers
|
|
42
|
+
expressApp.use(helmet());
|
|
43
|
+
// Global Rate Limiting
|
|
44
|
+
const limiter = rateLimit({
|
|
45
|
+
windowMs: 15 * 60 * 1000, // 15 minutes
|
|
46
|
+
limit: 1000, // Limit each IP to 100 requests per windowMs
|
|
47
|
+
standardHeaders: 'draft-7', // Use standard headers for rate limit info
|
|
48
|
+
legacyHeaders: false, // Disable the `X-RateLimit-*` headers
|
|
49
|
+
message: {
|
|
50
|
+
errorMsg: 'Too many requests from this IP, please try again.',
|
|
51
|
+
solution: 'Please slow down your requests or contact support if you believe this is an error.',
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
expressApp.use(limiter);
|
|
55
|
+
// Register custom routes if provided
|
|
56
|
+
if (config.customRoutesPublic) {
|
|
57
|
+
config.customRoutesPublic(expressApp);
|
|
58
|
+
}
|
|
59
|
+
// Configure CORS
|
|
60
|
+
const corsConfiguration = corsConfig(config.cors.allowedOrigins);
|
|
61
|
+
// Express middleware
|
|
62
|
+
expressApp.use(cors(corsConfiguration));
|
|
63
|
+
// Register routes
|
|
64
|
+
routes(expressApp);
|
|
65
|
+
// Register custom routes if provided
|
|
66
|
+
if (config.customRoutes) {
|
|
67
|
+
config.customRoutes(expressApp);
|
|
68
|
+
}
|
|
69
|
+
// 404 handler for unmatched routes
|
|
70
|
+
expressApp.use((req, res, next) => {
|
|
71
|
+
const err = new Error('Invalid API endpoint.');
|
|
72
|
+
next(err);
|
|
73
|
+
});
|
|
74
|
+
// Error handler (must be last)
|
|
75
|
+
expressApp.use(errorHandler);
|
|
76
|
+
// Initialize socket io (if needed)
|
|
77
|
+
// initSocketIO(httpServer, corsConfiguration);
|
|
78
|
+
return httpServer;
|
|
79
|
+
};
|
|
80
|
+
export * from './utils/index.js';
|
|
81
|
+
export * from './routes/orgs/index.js';
|
|
82
|
+
export * from './s3-buckets/index.js';
|
|
83
|
+
export * from './local-cache.js';
|
|
84
|
+
export * from './ai/index.js';
|
|
85
|
+
export { getCurrencySymbol };
|
|
86
|
+
export * from './r2-buckets/index.js';
|
|
87
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,UAAU,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,MAAM,MAAM,mBAAmB,CAAC;AACvC,iDAAiD;AACjD,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,M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,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,iBAAiB,EAAE,CAAC;AAE7B,cAAc,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
declare class LocalCache {
|
|
2
|
+
private lCache;
|
|
3
|
+
constructor(maxSize: number);
|
|
4
|
+
get(key: string): Promise<any | undefined>;
|
|
5
|
+
set(key: string, value: any, ttl?: number): Promise<void>;
|
|
6
|
+
del(key: string): Promise<void>;
|
|
7
|
+
size(): Promise<number>;
|
|
8
|
+
keys(): Promise<string[]>;
|
|
9
|
+
has(key: string): Promise<boolean>;
|
|
10
|
+
getAllValues(): Promise<any[]>;
|
|
11
|
+
}
|
|
12
|
+
export declare const getSingletonCacheInstance: (instanceName: string, maxSize: number) => Promise<LocalCache>;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=local-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-cache.d.ts","sourceRoot":"","sources":["../src/local-cache.ts"],"names":[],"mappings":"AAEA,cAAM,UAAU;IACd,OAAO,CAAC,MAAM,CAAwB;gBAE1B,OAAO,EAAE,MAAM;IAMrB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,GAAG,SAAS,CAAC;IAI1C,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQzD,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/B,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC;IAIvB,IAAI,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAIzB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIlC,YAAY,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;CAGrC;AAID,eAAO,MAAM,yBAAyB,GAAU,cAAc,MAAM,EAAE,SAAS,MAAM,wBAMpF,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { LRUCache } from 'lru-cache';
|
|
2
|
+
class LocalCache {
|
|
3
|
+
lCache;
|
|
4
|
+
constructor(maxSize) {
|
|
5
|
+
this.lCache = new LRUCache({
|
|
6
|
+
max: maxSize || 100,
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
async get(key) {
|
|
10
|
+
return this.lCache.get(key);
|
|
11
|
+
}
|
|
12
|
+
async set(key, value, ttl) {
|
|
13
|
+
if (ttl) {
|
|
14
|
+
this.lCache.set(key, value, { ttl });
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
this.lCache.set(key, value);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
async del(key) {
|
|
21
|
+
this.lCache.delete(key);
|
|
22
|
+
}
|
|
23
|
+
async size() {
|
|
24
|
+
return this.lCache.size;
|
|
25
|
+
}
|
|
26
|
+
async keys() {
|
|
27
|
+
return Array.from(this.lCache.keys());
|
|
28
|
+
}
|
|
29
|
+
async has(key) {
|
|
30
|
+
return this.lCache.has(key);
|
|
31
|
+
}
|
|
32
|
+
async getAllValues() {
|
|
33
|
+
return Array.from(this.lCache.values());
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const cacheInstances = {};
|
|
37
|
+
export const getSingletonCacheInstance = async (instanceName, maxSize) => {
|
|
38
|
+
if (cacheInstances[instanceName]) {
|
|
39
|
+
return cacheInstances[instanceName];
|
|
40
|
+
}
|
|
41
|
+
cacheInstances[instanceName] = new LocalCache(maxSize);
|
|
42
|
+
return cacheInstances[instanceName];
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=local-cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{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