@starklabs/backend-core 1.2.4 → 1.2.5

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/.env.example CHANGED
@@ -1,21 +1,23 @@
1
1
  # development@v3
2
2
  PORT=4000
3
- API_VERSION=1 # must be an integer
4
-
3
+ API_VERSION=1
4
+ BACKEND_URL=http://localhost:4000/api/v1
5
+ FRONTEND_URL=http://localhost:3000
6
+ MONGODB_URI=
7
+ DATABASE_NAME=starklabs
8
+ ISOFFLINE=true
9
+ ENV=development
5
10
  # Duration format: 1m | 5m | 10m | 15m | 30m | 1h | 6h | 12h | 1d | 3d | 7d | 14d | 30d
6
11
  TOKEN_EXPIRY=7d
7
12
  JWT_SECRET=
8
13
  MASTER_KEY=
9
- ISOFFLINE=true
10
- ENV=development
11
14
  INTERNAL_ROLES=["developer","admin"]
12
15
  RESEND_API_KEY=
13
-
14
16
  # Duration format: 1m | 5m | 10m | 15m | 30m | 1h | 6h | 12h | 1d | 3d | 7d | 14d | 30d
15
17
  RATE_LIMIT_DURATION=15m
16
18
  RATE_LIMIT_REQ=200
17
19
  RATE_LIMIT_MSG="Too many requests, please try again later."
18
20
  CLOUDINARY_API_SECRET=
19
- CLOUDINARY_API_KEY=5
21
+ CLOUDINARY_API_KEY=
20
22
  CLOUDINARY_CLOUD_NAME=
21
- CLOUDINARY_FOLDER_NAME=uploads
23
+ CLOUDINARY_FOLDER_NAME=starklabs-webdev
@@ -82,14 +82,25 @@ const startServer = async () => {
82
82
  cloudinaryCloudName,
83
83
  cloudinaryAPISecret,
84
84
  apiVersion,
85
+ isOffline,
86
+ mongoDBURI,
87
+ databaseName,
88
+ backendURL,
89
+ frontendURL,
85
90
  } = config;
86
91
 
87
- app.use(cors());
92
+ app.use(
93
+ cors({
94
+ credentials: true,
95
+ origin: frontendURL,
96
+ methods: ["GET", "POST", "PUT", "PATCH", "DELETE"],
97
+ }),
98
+ );
88
99
  app.use(helmet());
89
100
  app.use(cookieParser());
90
101
  app.use(apiLimiter({ rateLimitDuration, maxReqLimit, rateLimitMsg }));
91
102
 
92
- connectDB();
103
+ connectDB(isOffline, mongoDBURI, databaseName);
93
104
 
94
105
  configureCloudinary({
95
106
  cloudinaryAPIKey,
package/dist/js/lib/db.js CHANGED
@@ -8,27 +8,28 @@ const connectLocally = async () => {
8
8
  AppLog("check", "db", "Connected to OFFLINE-DB!");
9
9
  };
10
10
 
11
- // connecting to db
12
11
  /**
13
12
  *
14
- * @param {"MONGODB_URI"} uri
15
- * @param {"DATABASE_NAME"} database
16
- * @param {true | false} NETWORK
13
+ * @param {true | false} isOffline
14
+ * @param {"MONGODB_URI"} mongodbURI
15
+ * @param {"DATABASE_NAME"} databaseName
17
16
  * @returns
18
17
  */
19
- const connectDB = async (
20
- MONGODB_URI = "",
21
- DATABASE_NAME = "starklabs",
22
- NETWORK = false,
23
- ) => {
24
- const mongodbUri = MONGODB_URI || "mongodb://localhost:27017";
18
+ const connectDB = async (isOffline, mongoDBURI, databaseName) => {
25
19
  try {
26
- if (!NETWORK) {
27
- await connectLocally();
28
- return;
29
- }
20
+ if (!isOffline && !mongoDBURI)
21
+ throw new Error(
22
+ "You are online! mongoDBURI is required. Please check .env or StarkCore({})",
23
+ );
30
24
 
31
- await mongoose.connect(`${mongodbUri}/${DATABASE_NAME}`);
25
+ if (!databaseName)
26
+ throw new Error(
27
+ "databaseName is required. Please check .env or StarkCore({})",
28
+ );
29
+
30
+ if (isOffline) return connectLocally(databaseName);
31
+
32
+ await mongoose.connect(`${mongoDBURI}/${databaseName}`);
32
33
  AppLog("check", "db", "Connected successfully!");
33
34
  } catch (error) {
34
35
  AppLog("X", "db", "Error while connecting!");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@starklabs/backend-core",
3
- "version": "1.2.4",
3
+ "version": "1.2.5",
4
4
  "description": "A comprehensive backend authentication library featuring MongoDB integration, JWT-based authentication, encryption/decryption using libsodium, and utilities for error handling and logging. Supports both ES modules and CommonJS. Requires MONGODB_URI, DB_NAME, MASTER_KEY, and JWT_SECRET environment variables.",
5
5
  "keywords": [
6
6
  "auth-mongo",