powr-sdk-api 1.5.1 → 2.0.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 +109 -0
- package/dist/index.js +7 -1
- package/dist/routes/admin/index.js +20 -0
- package/dist/routes/index.js +30 -0
- package/package.json +7 -3
package/README.md
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# Powr SDK API
|
|
2
|
+
|
|
3
|
+
A shared API core library for PowrStack projects that provides common middleware, error handling, logging, and route management.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install powr-sdk-api
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Basic Setup
|
|
14
|
+
|
|
15
|
+
```javascript
|
|
16
|
+
const express = require('express');
|
|
17
|
+
const {
|
|
18
|
+
createRoutes,
|
|
19
|
+
errorHandler,
|
|
20
|
+
requestHandler,
|
|
21
|
+
logger
|
|
22
|
+
} = require('powr-sdk-api');
|
|
23
|
+
|
|
24
|
+
const app = express();
|
|
25
|
+
|
|
26
|
+
// Add middleware
|
|
27
|
+
app.use(requestHandler);
|
|
28
|
+
app.use(express.json());
|
|
29
|
+
|
|
30
|
+
// Initialize routes
|
|
31
|
+
createRoutes(app, {
|
|
32
|
+
projectId: 'your-project-id',
|
|
33
|
+
baseUrl: '/api',
|
|
34
|
+
logger: logger
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// Error handling (should be last)
|
|
38
|
+
app.use(errorHandler);
|
|
39
|
+
|
|
40
|
+
app.listen(3000, () => {
|
|
41
|
+
logger.info('Server running on port 3000');
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Admin Routes Only
|
|
46
|
+
|
|
47
|
+
```javascript
|
|
48
|
+
const express = require('express');
|
|
49
|
+
const { createAdminRoutes } = require('powr-sdk-api');
|
|
50
|
+
|
|
51
|
+
const app = express();
|
|
52
|
+
|
|
53
|
+
// Initialize only admin routes
|
|
54
|
+
createAdminRoutes(app, {
|
|
55
|
+
projectId: 'your-project-id',
|
|
56
|
+
apiUrl: '/admin',
|
|
57
|
+
logger: console
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
app.listen(3000);
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### With Custom Middleware
|
|
64
|
+
|
|
65
|
+
```javascript
|
|
66
|
+
const express = require('express');
|
|
67
|
+
const { createRoutes, validateAuth } = require('powr-sdk-api');
|
|
68
|
+
|
|
69
|
+
const app = express();
|
|
70
|
+
|
|
71
|
+
// Custom auth middleware
|
|
72
|
+
const customAuth = (req, res, next) => {
|
|
73
|
+
// Your custom authentication logic
|
|
74
|
+
next();
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
createRoutes(app, {
|
|
78
|
+
projectId: 'your-project-id',
|
|
79
|
+
authMiddleware: customAuth,
|
|
80
|
+
logger: console
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
app.listen(3000);
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Available Exports
|
|
87
|
+
|
|
88
|
+
- `createRoutes(app, options)` - Initialize all routes
|
|
89
|
+
- `createAdminRoutes(app, options)` - Initialize only admin routes
|
|
90
|
+
- `errorHandler` - Express error handling middleware
|
|
91
|
+
- `requestHandler` - Request logging middleware
|
|
92
|
+
- `validateAuth` - JWT authentication middleware
|
|
93
|
+
- `generateToken` - JWT token generation utility
|
|
94
|
+
- `logger` - Winston logger instance
|
|
95
|
+
- `createSwaggerSpec` - Swagger documentation generator
|
|
96
|
+
|
|
97
|
+
## Options
|
|
98
|
+
|
|
99
|
+
### createRoutes/createAdminRoutes options:
|
|
100
|
+
|
|
101
|
+
- `projectId` (required) - Your project identifier
|
|
102
|
+
- `baseUrl` (optional) - Base URL for routes (default: '/api')
|
|
103
|
+
- `apiUrl` (optional) - Admin API URL (default: '/admin')
|
|
104
|
+
- `authMiddleware` (optional) - Custom authentication middleware
|
|
105
|
+
- `logger` (optional) - Logger instance (default: console)
|
|
106
|
+
|
|
107
|
+
## Version
|
|
108
|
+
|
|
109
|
+
Current version: 2.0.1
|
package/dist/index.js
CHANGED
|
@@ -16,6 +16,10 @@ const {
|
|
|
16
16
|
} = require("./middleware/notfound");
|
|
17
17
|
const createSwaggerSpec = require("./swagger");
|
|
18
18
|
const logger = require("./logger");
|
|
19
|
+
const {
|
|
20
|
+
createRoutes,
|
|
21
|
+
createAdminRoutes
|
|
22
|
+
} = require("./routes");
|
|
19
23
|
module.exports = {
|
|
20
24
|
errorCatcher,
|
|
21
25
|
errorHandler,
|
|
@@ -24,5 +28,7 @@ module.exports = {
|
|
|
24
28
|
createSwaggerSpec,
|
|
25
29
|
generateToken,
|
|
26
30
|
validateAuth,
|
|
27
|
-
notFoundHandler
|
|
31
|
+
notFoundHandler,
|
|
32
|
+
createRoutes,
|
|
33
|
+
createAdminRoutes
|
|
28
34
|
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// Admin routes for powr-sdk-api
|
|
4
|
+
// This file will contain the admin route handlers
|
|
5
|
+
|
|
6
|
+
const createAdminRoutes = (app, options = {}) => {
|
|
7
|
+
const {
|
|
8
|
+
projectId,
|
|
9
|
+
apiUrl = '/admin',
|
|
10
|
+
authMiddleware = null,
|
|
11
|
+
logger = console
|
|
12
|
+
} = options;
|
|
13
|
+
|
|
14
|
+
// Admin routes will be implemented here
|
|
15
|
+
logger.info('Admin routes initialized for project:', projectId);
|
|
16
|
+
return app;
|
|
17
|
+
};
|
|
18
|
+
module.exports = {
|
|
19
|
+
createAdminRoutes
|
|
20
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// Main routes index for powr-sdk-api
|
|
4
|
+
// This file exports all route handlers for easy integration
|
|
5
|
+
|
|
6
|
+
const {
|
|
7
|
+
createAdminRoutes
|
|
8
|
+
} = require('./admin');
|
|
9
|
+
const createRoutes = (app, options = {}) => {
|
|
10
|
+
const {
|
|
11
|
+
projectId,
|
|
12
|
+
baseUrl = '/api',
|
|
13
|
+
authMiddleware = null,
|
|
14
|
+
logger = console
|
|
15
|
+
} = options;
|
|
16
|
+
|
|
17
|
+
// Initialize admin routes
|
|
18
|
+
createAdminRoutes(app, {
|
|
19
|
+
projectId,
|
|
20
|
+
apiUrl: `${baseUrl}/admin`,
|
|
21
|
+
authMiddleware,
|
|
22
|
+
logger
|
|
23
|
+
});
|
|
24
|
+
logger.info('All routes initialized for project:', projectId);
|
|
25
|
+
return app;
|
|
26
|
+
};
|
|
27
|
+
module.exports = {
|
|
28
|
+
createRoutes,
|
|
29
|
+
createAdminRoutes
|
|
30
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "powr-sdk-api",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Shared API core library for PowrStack projects",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -37,11 +37,15 @@
|
|
|
37
37
|
"homepage": "https://github.com/powrstack/powr-sdk-api#readme",
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@aws-sdk/client-s3": "^3.787.0",
|
|
40
|
+
"@google-cloud/storage": "^7.16.0",
|
|
40
41
|
"express": "^4.18.2",
|
|
41
|
-
"jsonwebtoken": "^9.0.2",
|
|
42
|
+
"jsonwebtoken": "^9.0.2",
|
|
42
43
|
"swagger-jsdoc": "^6.2.8",
|
|
43
44
|
"swagger-ui-express": "^5.0.0",
|
|
44
|
-
"winston": "^3.17.0"
|
|
45
|
+
"winston": "^3.17.0",
|
|
46
|
+
"mongodb": "^6.3.0",
|
|
47
|
+
"multer": "^1.4.5-lts.1",
|
|
48
|
+
"bcrypt": "^5.1.1"
|
|
45
49
|
},
|
|
46
50
|
"devDependencies": {
|
|
47
51
|
"@babel/cli": "^7.23.9",
|