powr-sdk-api 4.1.10 → 4.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/dist/index.js +7 -5
  2. package/dist/{services → managers}/functions.js +1 -1
  3. package/dist/managers/index.js +26 -0
  4. package/dist/{services/scheduledTasks.js → managers/tasks.js} +123 -143
  5. package/dist/{services → managers}/tools.js +1 -1
  6. package/dist/middleware/projectId.js +1 -1
  7. package/dist/routes/functions.js +3 -1
  8. package/dist/routes/index.js +3 -27
  9. package/dist/routes/tasks.js +304 -0
  10. package/dist/routes/tools.js +21 -8
  11. package/package.json +69 -71
  12. package/dist/admin/activities.js +0 -81
  13. package/dist/admin/auth.js +0 -234
  14. package/dist/admin/blogs.js +0 -94
  15. package/dist/admin/comments.js +0 -83
  16. package/dist/admin/files.js +0 -56
  17. package/dist/admin/forms.js +0 -242
  18. package/dist/admin/index.js +0 -53
  19. package/dist/admin/invoice.js +0 -163
  20. package/dist/admin/likes.js +0 -126
  21. package/dist/admin/notifications.js +0 -93
  22. package/dist/admin/plexx.js +0 -53
  23. package/dist/admin/ratings.js +0 -189
  24. package/dist/admin/routes.js +0 -132
  25. package/dist/admin/slides.js +0 -101
  26. package/dist/admin/users.js +0 -175
  27. package/dist/admin/waitlists.js +0 -94
  28. package/dist/logger/gcs.js +0 -78
  29. package/dist/logger/s3.js +0 -78
  30. package/dist/middleware/auth.js +0 -76
  31. package/dist/middleware/logger.js +0 -45
  32. package/dist/middleware/response.js +0 -53
  33. package/dist/routes/admin/index.js +0 -520
  34. package/dist/routes/blogs.js +0 -94
  35. package/dist/routes/invoice.js +0 -167
  36. package/dist/routes/plexx.js +0 -269
  37. package/dist/routes/routes.js +0 -143
  38. package/dist/routes/scheduledTasks.js +0 -240
  39. package/dist/scripts/update-tools-schema.js +0 -157
  40. package/dist/services/dbService.js +0 -42
  41. package/dist/services/logger.js +0 -35
  42. package/dist/services/plexx.js +0 -229
  43. package/dist/utils/auth.js +0 -19
  44. package/dist/utils/logger.js +0 -57
  45. package/dist/utils/s3-transport.js +0 -61
  46. package/dist/utils/s3.js +0 -78
@@ -1,132 +0,0 @@
1
- "use strict";
2
-
3
- const express = require("express");
4
- const router = express.Router();
5
- const {
6
- getDb
7
- } = require("../services/dbService");
8
-
9
- // Get all routes entries
10
- router.get('/', async (req, res) => {
11
- const {
12
- projectId
13
- } = req.query;
14
- try {
15
- const query = {
16
- projectId
17
- };
18
- if (!projectId) {
19
- return res.status(400).json({
20
- success: false,
21
- message: 'projectId is required.'
22
- });
23
- }
24
- const routesData = await getDb().collection("routes").find(query).toArray();
25
- return res.status(200).json({
26
- success: true,
27
- allroutes: routesData
28
- });
29
- } catch (error) {
30
- console.error("Error retrieving routes entries:", error);
31
- return res.status(500).json({
32
- success: false,
33
- message: "Failed to retrieve routes entries."
34
- });
35
- }
36
- });
37
-
38
- // Create a new route
39
- router.post('/', async (req, res) => {
40
- try {
41
- const {
42
- projectId
43
- } = req.query;
44
- if (!projectId) {
45
- return res.status(400).json({
46
- success: false,
47
- message: 'projectId is required.'
48
- });
49
- }
50
- const newRoute = req.body;
51
- newRoute.projectId = projectId;
52
- if (!newRoute || Object.keys(newRoute).length === 0) {
53
- return res.status(400).json({
54
- success: false,
55
- message: 'Request body is empty or invalid.'
56
- });
57
- }
58
- const result = await getDb().collection('routes').insertOne(newRoute);
59
- return res.status(201).json({
60
- success: true,
61
- entry: result.ops ? result.ops[0] : newRoute
62
- });
63
- } catch (error) {
64
- console.error('Error inserting route entry:', error);
65
- return res.status(500).json({
66
- success: false,
67
- message: 'Failed to insert route entry.'
68
- });
69
- }
70
- });
71
-
72
- // Update route code
73
- router.put('/:route', async (req, res) => {
74
- try {
75
- const {
76
- route
77
- } = req.params;
78
- const {
79
- code
80
- } = req.body;
81
- const {
82
- projectId
83
- } = req.query;
84
- if (!projectId) {
85
- return res.status(400).json({
86
- success: false,
87
- message: 'projectId is required.'
88
- });
89
- }
90
- if (!code) {
91
- return res.status(400).json({
92
- success: false,
93
- message: 'Code field is required.'
94
- });
95
- }
96
- const query = {
97
- route,
98
- projectId
99
- };
100
- const existingRoute = await getDb().collection('routes').findOne(query);
101
- if (!existingRoute) {
102
- return res.status(404).json({
103
- success: false,
104
- message: 'Route not found.'
105
- });
106
- }
107
- const result = await getDb().collection('routes').updateOne(query, {
108
- $set: {
109
- code
110
- }
111
- });
112
- if (result.matchedCount === 0) {
113
- return res.status(404).json({
114
- success: false,
115
- message: 'Route not found.'
116
- });
117
- }
118
- const updatedRoute = await getDb().collection('routes').findOne(query);
119
- return res.status(200).json({
120
- success: true,
121
- entry: updatedRoute
122
- });
123
- } catch (error) {
124
- console.error('Error updating route code:', error);
125
- return res.status(500).json({
126
- success: false,
127
- message: 'Failed to update route code.',
128
- error: error.message
129
- });
130
- }
131
- });
132
- module.exports = router;
@@ -1,101 +0,0 @@
1
- "use strict";
2
-
3
- const express = require('express');
4
- const router = express.Router();
5
- const {
6
- getDb
7
- } = require('../services/mongo');
8
-
9
- // Get slides
10
- router.get('/', async (req, res) => {
11
- const {
12
- projectId,
13
- tag
14
- } = req.query;
15
- try {
16
- const query = {
17
- projectId
18
- };
19
- if (tag) {
20
- query.tag = tag;
21
- }
22
- console.log("Filter.....:", query);
23
- const slidesData = await getDb().collection('slides').find(query).toArray();
24
- if (!slidesData || slidesData.length === 0) {
25
- console.log("Data not found.");
26
- return res.status(200).json({
27
- success: true,
28
- slides: []
29
- });
30
- }
31
- const sortedData = slidesData.sort((a, b) => new Date(b === null || b === void 0 ? void 0 : b.createdAt) - new Date(a === null || a === void 0 ? void 0 : a.createdAt));
32
- console.log("Slides retrieved and sorted:", sortedData);
33
- return res.status(200).json({
34
- success: true,
35
- slides: sortedData
36
- });
37
- } catch (error) {
38
- console.error("Error retrieving slides:", error);
39
- return res.status(500).json({
40
- success: false,
41
- message: "Failed to retrieve slides."
42
- });
43
- }
44
- });
45
-
46
- // Add slide
47
- router.post('/', async (req, res) => {
48
- const {
49
- projectId,
50
- tag,
51
- city,
52
- url,
53
- title,
54
- description,
55
- expiry
56
- } = req.body;
57
- if (!url || !title || !description || !expiry) {
58
- return res.status(400).json({
59
- success: false,
60
- message: "All fields are required."
61
- });
62
- }
63
- const slideData = {
64
- projectId,
65
- url,
66
- title,
67
- description,
68
- expiry,
69
- createdAt: new Date()
70
- };
71
- if (city) {
72
- slideData.city = city;
73
- }
74
- if (tag) {
75
- slideData.tag = tag;
76
- }
77
- try {
78
- const result = await getDb().collection('slides').insertOne(slideData);
79
- if (result && result.insertedId) {
80
- console.log("Slide added with ID:", result.insertedId);
81
- return res.status(200).json({
82
- success: true,
83
- message: "Slide added successfully.",
84
- slideId: result.insertedId
85
- });
86
- } else {
87
- console.error("Insert operation failed. Result:", result);
88
- return res.status(500).json({
89
- success: false,
90
- message: "Slide could not be added."
91
- });
92
- }
93
- } catch (error) {
94
- console.error("Error adding slide:", error);
95
- return res.status(500).json({
96
- success: false,
97
- message: "Failed to add slide due to a server error."
98
- });
99
- }
100
- });
101
- module.exports = router;
@@ -1,175 +0,0 @@
1
- "use strict";
2
-
3
- const express = require("express");
4
- const router = express.Router();
5
- const {
6
- getDb
7
- } = require("../services/mongo");
8
- const {
9
- ObjectId
10
- } = require("mongodb");
11
- router.post("/", async (req, res) => {
12
- const {
13
- projectId,
14
- phoneNumber,
15
- email,
16
- ...userData
17
- } = req.body;
18
- if (!phoneNumber && !email) {
19
- return res.status(400).json({
20
- success: false,
21
- message: "phoneNumber or email is required."
22
- });
23
- }
24
- const user = {
25
- projectId,
26
- phoneNumber,
27
- email,
28
- ...userData,
29
- createdAt: new Date()
30
- };
31
- try {
32
- const usersCollection = getDb().collection("users");
33
- if (phoneNumber) {
34
- const existingByPhone = await usersCollection.findOne({
35
- projectId,
36
- phoneNumber
37
- });
38
- if (existingByPhone) {
39
- return res.status(409).json({
40
- success: false,
41
- message: "Phone number already exists."
42
- });
43
- }
44
- }
45
- if (email) {
46
- const existingByEmail = await usersCollection.findOne({
47
- projectId,
48
- email
49
- });
50
- if (existingByEmail) {
51
- return res.status(409).json({
52
- success: false,
53
- message: "Email already exists."
54
- });
55
- }
56
- }
57
- const result = await getDb().collection("users").insertOne(user);
58
- return res.status(200).json({
59
- success: true,
60
- message: "User created successfully.",
61
- userId: result.insertedId
62
- });
63
- } catch (error) {
64
- console.error("Error creating user:", error);
65
- return res.status(500).json({
66
- success: false,
67
- message: "Internal server error."
68
- });
69
- }
70
- });
71
- router.get("/", async (req, res) => {
72
- const {
73
- projectId,
74
- _id,
75
- phoneNumber,
76
- email
77
- } = req.query;
78
- if (!_id && !phoneNumber && !email) {
79
- return res.status(400).json({
80
- success: false,
81
- message: "no filters provided.",
82
- users: []
83
- });
84
- }
85
- const filter = {
86
- projectId
87
- };
88
- if (_id) {
89
- try {
90
- filter._id = new ObjectId(_id);
91
- } catch (e) {
92
- return res.status(400).json({
93
- success: false,
94
- message: "Invalid _id format."
95
- });
96
- }
97
- }
98
- if (phoneNumber) {
99
- filter.phoneNumber = phoneNumber;
100
- }
101
- if (email) {
102
- filter.email = email;
103
- }
104
- try {
105
- const users = await getDb().collection("users").find(filter).toArray();
106
- return res.status(200).json({
107
- success: true,
108
- message: "Users fetched successfully.",
109
- users
110
- });
111
- } catch (error) {
112
- console.error("Error fetching users:", error);
113
- return res.status(500).json({
114
- success: false,
115
- message: "Internal server error."
116
- });
117
- }
118
- });
119
- router.post("/getOrCreate", async (req, res) => {
120
- const {
121
- projectId,
122
- phoneNumber,
123
- email,
124
- ...userData
125
- } = req.body;
126
- if (!phoneNumber && !email) {
127
- return res.status(400).json({
128
- success: false,
129
- message: "phoneNumber or email is required."
130
- });
131
- }
132
- const user = {
133
- projectId,
134
- phoneNumber,
135
- email,
136
- ...userData,
137
- createdAt: new Date()
138
- };
139
- try {
140
- const usersCollection = getDb().collection("users");
141
- let existingUser = null;
142
- if (phoneNumber) {
143
- existingUser = await usersCollection.findOne({
144
- projectId,
145
- phoneNumber
146
- });
147
- }
148
- if (!existingUser && email) {
149
- existingUser = await usersCollection.findOne({
150
- projectId,
151
- email
152
- });
153
- }
154
- if (existingUser) {
155
- return res.status(200).json({
156
- success: true,
157
- message: "User already exists.",
158
- userId: existingUser._id
159
- });
160
- }
161
- const result = await usersCollection.insertOne(user);
162
- return res.status(200).json({
163
- success: true,
164
- message: "User created successfully.",
165
- userId: result.insertedId
166
- });
167
- } catch (error) {
168
- console.error("Error creating or fetching user:", error);
169
- return res.status(500).json({
170
- success: false,
171
- message: "Internal server error."
172
- });
173
- }
174
- });
175
- module.exports = router;
@@ -1,94 +0,0 @@
1
- "use strict";
2
-
3
- const express = require("express");
4
- const router = express.Router();
5
- const {
6
- getDb
7
- } = require("../services/mongo");
8
-
9
- // Get waitlist entries
10
- router.get('/', async (req, res) => {
11
- const {
12
- projectId
13
- } = req.query;
14
- try {
15
- const query = {
16
- projectId
17
- };
18
- console.log("Filter.....:", query);
19
- const waitlistData = await getDb().collection("waitlists").find(query).toArray();
20
- if (!waitlistData || waitlistData.length === 0) {
21
- console.log("Data not found.");
22
- return res.status(200).json({
23
- success: true,
24
- entries: []
25
- });
26
- }
27
- const sortedData = waitlistData.sort((a, b) => new Date(b === null || b === void 0 ? void 0 : b.createdAt) - new Date(a === null || a === void 0 ? void 0 : a.createdAt));
28
- console.log("Waitlist entries retrieved and sorted:", sortedData);
29
- return res.status(200).json({
30
- success: true,
31
- entries: sortedData
32
- });
33
- } catch (error) {
34
- console.error("Error retrieving waitlist entries:", error);
35
- return res.status(500).json({
36
- success: false,
37
- message: "Failed to retrieve waitlist entries."
38
- });
39
- }
40
- });
41
-
42
- // Original POST endpoint for adding to waitlist
43
- router.post("/", async (req, res) => {
44
- const {
45
- projectId,
46
- email
47
- } = req.body;
48
- try {
49
- const existingEntry = await getDb().collection("waitlists").findOne({
50
- projectId,
51
- email
52
- });
53
- if (existingEntry) {
54
- return res.status(400).json({
55
- success: false,
56
- message: "You are already in the waitlist "
57
- });
58
- }
59
- } catch (error) {
60
- console.error("Error checking waitlist:", error);
61
- return res.status(500).json({
62
- success: false,
63
- message: "Failed to check waitlist due to a server error."
64
- });
65
- }
66
- const waitListData = {
67
- projectId,
68
- email,
69
- createdAt: new Date()
70
- };
71
- try {
72
- const result = await getDb().collection("waitlists").insertOne(waitListData);
73
- if (result && result.insertedId) {
74
- return res.status(200).json({
75
- success: true,
76
- message: "you are added in the waitist",
77
- userId: result.insertedId
78
- });
79
- } else {
80
- console.error("Insert operation failed. Result:", result);
81
- return res.status(500).json({
82
- success: false,
83
- message: "user could not be added."
84
- });
85
- }
86
- } catch (error) {
87
- console.error("Error adding user:", error);
88
- return res.status(500).json({
89
- success: false,
90
- message: "Failed to add user due to a server error."
91
- });
92
- }
93
- });
94
- module.exports = router;
@@ -1,78 +0,0 @@
1
- "use strict";
2
-
3
- const winston = require('winston');
4
- const {
5
- Storage
6
- } = require('@google-cloud/storage');
7
-
8
- // Create GCS client using environment variables for credentials
9
- const storage = new Storage({
10
- projectId: process.env.GCS_PROJECT_ID,
11
- credentials: {
12
- client_email: process.env.GCS_CLIENT_EMAIL,
13
- private_key: process.env.GCS_PRIVATE_KEY ? process.env.GCS_PRIVATE_KEY.replace(/\\n/g, '\n') : undefined
14
- }
15
- });
16
-
17
- /**
18
- * Custom Winston transport for logging to Google Cloud Storage
19
- */
20
- class GCSTransport extends winston.Transport {
21
- constructor(opts) {
22
- super(opts);
23
- this.bucket = opts.bucket;
24
- this.prefix = opts.prefix || '';
25
- this.buffer = [];
26
- this.bufferSize = opts.bufferSize || 100;
27
- this.flushInterval = opts.flushInterval || 5000;
28
- this.setupFlushInterval();
29
- }
30
- setupFlushInterval() {
31
- setInterval(() => {
32
- this.flush();
33
- }, this.flushInterval);
34
- }
35
- async flush() {
36
- if (this.buffer.length === 0) return;
37
- const logs = this.buffer.splice(0, this.buffer.length);
38
- const date = new Date().toISOString().split('T')[0];
39
- const filename = `${this.prefix}/${date}/${Date.now()}.json`;
40
- try {
41
- const bucket = storage.bucket(this.bucket);
42
- const file = bucket.file(filename);
43
- await file.save(JSON.stringify(logs), {
44
- contentType: 'application/json',
45
- metadata: {
46
- contentType: 'application/json'
47
- }
48
- });
49
- } catch (error) {
50
- console.error('Failed to write logs to Google Cloud Storage:', {
51
- error: error.message,
52
- code: error.code,
53
- bucket: this.bucket,
54
- filename: filename,
55
- projectId: process.env.GCS_PROJECT_ID,
56
- stack: error.stack
57
- });
58
- // Put the logs back in the buffer
59
- this.buffer.unshift(...logs);
60
- }
61
- }
62
- log(info, callback) {
63
- setImmediate(() => {
64
- this.emit('logged', info);
65
- });
66
- this.buffer.push({
67
- timestamp: new Date().toISOString(),
68
- ...info
69
- });
70
- if (this.buffer.length >= this.bufferSize) {
71
- this.flush();
72
- }
73
- callback();
74
- }
75
- }
76
- module.exports = {
77
- GCSTransport
78
- };
package/dist/logger/s3.js DELETED
@@ -1,78 +0,0 @@
1
- "use strict";
2
-
3
- const winston = require('winston');
4
- const {
5
- S3Client,
6
- PutObjectCommand
7
- } = require('@aws-sdk/client-s3');
8
-
9
- // Create S3 client
10
- const s3Client = new S3Client({
11
- region: process.env.AWS_REGION,
12
- credentials: {
13
- accessKeyId: process.env.AWS_ACCESS_KEY_ID,
14
- secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY
15
- }
16
- });
17
-
18
- /**
19
- * Custom Winston transport for logging to S3
20
- */
21
- class S3Transport extends winston.Transport {
22
- constructor(opts) {
23
- super(opts);
24
- this.bucket = opts.bucket;
25
- this.prefix = opts.prefix || '';
26
- this.buffer = [];
27
- this.bufferSize = opts.bufferSize || 100;
28
- this.flushInterval = opts.flushInterval || 5000;
29
- this.setupFlushInterval();
30
- }
31
- setupFlushInterval() {
32
- setInterval(() => {
33
- this.flush();
34
- }, this.flushInterval);
35
- }
36
- async flush() {
37
- if (this.buffer.length === 0) return;
38
- const logs = this.buffer.splice(0, this.buffer.length);
39
- const date = new Date().toISOString().split('T')[0];
40
- const key = `${this.prefix}/${date}/${Date.now()}.json`;
41
- try {
42
- const command = new PutObjectCommand({
43
- Bucket: this.bucket,
44
- Key: key,
45
- Body: JSON.stringify(logs),
46
- ContentType: 'application/json'
47
- });
48
- await s3Client.send(command);
49
- } catch (error) {
50
- console.error('Failed to write logs to S3:', {
51
- error: error.message,
52
- code: error.code,
53
- bucket: this.bucket,
54
- key: key,
55
- region: process.env.AWS_REGION,
56
- stack: error.stack
57
- });
58
- // Put the logs back in the buffer
59
- this.buffer.unshift(...logs);
60
- }
61
- }
62
- log(info, callback) {
63
- setImmediate(() => {
64
- this.emit('logged', info);
65
- });
66
- this.buffer.push({
67
- timestamp: new Date().toISOString(),
68
- ...info
69
- });
70
- if (this.buffer.length >= this.bufferSize) {
71
- this.flush();
72
- }
73
- callback();
74
- }
75
- }
76
- module.exports = {
77
- S3Transport
78
- };