powr-sdk-api 4.3.1 → 4.3.3
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/dist/index.js +4 -2
- package/dist/managers/index.js +5 -20
- package/dist/managers/tasks.js +11 -8
- package/dist/routes/tasks.js +10 -12
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -19,7 +19,8 @@ const {
|
|
|
19
19
|
const {
|
|
20
20
|
initializeFunctions,
|
|
21
21
|
initializeTools,
|
|
22
|
-
executeTasks
|
|
22
|
+
executeTasks,
|
|
23
|
+
executeTool
|
|
23
24
|
} = require("./managers");
|
|
24
25
|
const {
|
|
25
26
|
verifyToken
|
|
@@ -34,5 +35,6 @@ module.exports = {
|
|
|
34
35
|
initializeFunctions,
|
|
35
36
|
initializeTools,
|
|
36
37
|
verifyToken,
|
|
37
|
-
executeTasks
|
|
38
|
+
executeTasks,
|
|
39
|
+
executeTool
|
|
38
40
|
};
|
package/dist/managers/index.js
CHANGED
|
@@ -2,25 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
const functionsManager = require('./functions');
|
|
4
4
|
const toolsManager = require('./tools');
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
// Async Functions initialization function
|
|
8
|
-
const initializeFunctions = async (options = {}) => {
|
|
9
|
-
// Initialize Functions manager with options
|
|
10
|
-
await functionsManager.initialize(options);
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
// Async Tools initialization function
|
|
14
|
-
const initializeTools = async (options = {}) => {
|
|
15
|
-
// Initialize Tools manager with options
|
|
16
|
-
await toolsManager.initialize(options);
|
|
17
|
-
};
|
|
5
|
+
const tasksManager = require('./tasks');
|
|
18
6
|
module.exports = {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
// Initialization/Execution methods
|
|
24
|
-
initializeFunctions,
|
|
25
|
-
initializeTools
|
|
7
|
+
initializeFunctions: functionsManager.initialize,
|
|
8
|
+
initializeTools: toolsManager.initialize,
|
|
9
|
+
executeTasks: tasksManager.executeScheduledTasks,
|
|
10
|
+
executeTool: toolsManager.executeToolAction
|
|
26
11
|
};
|
package/dist/managers/tasks.js
CHANGED
|
@@ -3,7 +3,10 @@
|
|
|
3
3
|
const {
|
|
4
4
|
getDb
|
|
5
5
|
} = require("../services/mongo");
|
|
6
|
-
|
|
6
|
+
const {
|
|
7
|
+
ObjectId
|
|
8
|
+
} = require("mongodb");
|
|
9
|
+
class TasksManager {
|
|
7
10
|
// Create a new scheduled task
|
|
8
11
|
async createTask(taskData) {
|
|
9
12
|
try {
|
|
@@ -91,7 +94,7 @@ class ScheduledTasksManager {
|
|
|
91
94
|
|
|
92
95
|
// Build query based on user role
|
|
93
96
|
let query = {
|
|
94
|
-
_id: taskId
|
|
97
|
+
_id: new ObjectId(taskId)
|
|
95
98
|
};
|
|
96
99
|
if (isAdmin) {
|
|
97
100
|
// Admin can access any task in the project
|
|
@@ -128,7 +131,7 @@ class ScheduledTasksManager {
|
|
|
128
131
|
|
|
129
132
|
// Build query based on user role
|
|
130
133
|
let query = {
|
|
131
|
-
_id: taskId
|
|
134
|
+
_id: new ObjectId(taskId)
|
|
132
135
|
};
|
|
133
136
|
if (isAdmin) {
|
|
134
137
|
// Admin can update any task in the project
|
|
@@ -180,7 +183,7 @@ class ScheduledTasksManager {
|
|
|
180
183
|
|
|
181
184
|
// Build query based on user role
|
|
182
185
|
let query = {
|
|
183
|
-
_id: taskId
|
|
186
|
+
_id: new ObjectId(taskId)
|
|
184
187
|
};
|
|
185
188
|
if (isAdmin) {
|
|
186
189
|
// Admin can delete any task in the project
|
|
@@ -225,7 +228,7 @@ class ScheduledTasksManager {
|
|
|
225
228
|
|
|
226
229
|
// Build query based on user role
|
|
227
230
|
let query = {
|
|
228
|
-
_id: taskId
|
|
231
|
+
_id: new ObjectId(taskId)
|
|
229
232
|
};
|
|
230
233
|
if (isAdmin) {
|
|
231
234
|
// Admin can toggle any task in the project
|
|
@@ -271,7 +274,7 @@ class ScheduledTasksManager {
|
|
|
271
274
|
|
|
272
275
|
// Build query based on user role
|
|
273
276
|
let query = {
|
|
274
|
-
_id: taskId
|
|
277
|
+
_id: new ObjectId(taskId)
|
|
275
278
|
};
|
|
276
279
|
if (isAdmin) {
|
|
277
280
|
// Admin can execute any task in the project
|
|
@@ -435,5 +438,5 @@ class ScheduledTasksManager {
|
|
|
435
438
|
}
|
|
436
439
|
|
|
437
440
|
// Create and export singleton instance
|
|
438
|
-
const
|
|
439
|
-
module.exports =
|
|
441
|
+
const tasksManager = new TasksManager();
|
|
442
|
+
module.exports = tasksManager;
|
package/dist/routes/tasks.js
CHANGED
|
@@ -2,16 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
const express = require("express");
|
|
4
4
|
const router = express.Router();
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
scheduledTasksManager
|
|
8
|
-
} = require("../managers");
|
|
5
|
+
const tasksManager = require("../managers/tasks");
|
|
6
|
+
const toolsManager = require("../managers/tools");
|
|
9
7
|
|
|
10
8
|
// GET /tasks - Get all tasks
|
|
11
9
|
router.get("/", async (req, res) => {
|
|
12
10
|
try {
|
|
13
11
|
const isAdmin = req.user.access === 100;
|
|
14
|
-
const result = await
|
|
12
|
+
const result = await tasksManager.getUserTasks(req.user.powrId, req.projectId, isAdmin);
|
|
15
13
|
if (result.success) {
|
|
16
14
|
return res.status(200).json({
|
|
17
15
|
success: true,
|
|
@@ -36,7 +34,7 @@ router.get("/", async (req, res) => {
|
|
|
36
34
|
router.get("/:taskId", async (req, res) => {
|
|
37
35
|
try {
|
|
38
36
|
const isAdmin = req.user.access === 100;
|
|
39
|
-
const result = await
|
|
37
|
+
const result = await tasksManager.getTask(req.params.taskId, req.user.powrId, req.projectId, isAdmin);
|
|
40
38
|
if (result.success) {
|
|
41
39
|
return res.status(200).json({
|
|
42
40
|
success: true,
|
|
@@ -108,7 +106,7 @@ router.post("/", async (req, res) => {
|
|
|
108
106
|
projectId: req.projectId,
|
|
109
107
|
isActive: isActive !== false // Default to true
|
|
110
108
|
};
|
|
111
|
-
const result = await
|
|
109
|
+
const result = await tasksManager.createTask(taskData);
|
|
112
110
|
if (result.success) {
|
|
113
111
|
res.status(201).json({
|
|
114
112
|
success: true,
|
|
@@ -174,7 +172,7 @@ router.put("/:taskId", async (req, res) => {
|
|
|
174
172
|
if (params !== undefined) updateData.params = params;
|
|
175
173
|
if (isActive !== undefined) updateData.isActive = isActive;
|
|
176
174
|
const isAdmin = req.user.access === 100;
|
|
177
|
-
const result = await
|
|
175
|
+
const result = await tasksManager.updateTask(req.params.taskId, req.user.powrId, req.projectId, updateData, isAdmin);
|
|
178
176
|
if (result.success) {
|
|
179
177
|
res.status(200).json({
|
|
180
178
|
success: true,
|
|
@@ -200,7 +198,7 @@ router.post("/:taskId/execute", async (req, res) => {
|
|
|
200
198
|
try {
|
|
201
199
|
const taskId = req.params.taskId;
|
|
202
200
|
const isAdmin = req.user.access === 100;
|
|
203
|
-
const result = await
|
|
201
|
+
const result = await tasksManager.executeTask(taskId, req.user.powrId, req.projectId, isAdmin);
|
|
204
202
|
if (result.success) {
|
|
205
203
|
res.json({
|
|
206
204
|
success: true,
|
|
@@ -230,7 +228,7 @@ router.post("/:taskId/toggle", async (req, res) => {
|
|
|
230
228
|
isActive
|
|
231
229
|
} = req.body;
|
|
232
230
|
const isAdmin = req.user.access === 100;
|
|
233
|
-
const result = await
|
|
231
|
+
const result = await tasksManager.toggleTask(taskId, req.user.powrId, req.projectId, isActive, isAdmin);
|
|
234
232
|
if (result.success) {
|
|
235
233
|
res.json({
|
|
236
234
|
success: true,
|
|
@@ -256,7 +254,7 @@ router.delete("/:taskId", async (req, res) => {
|
|
|
256
254
|
try {
|
|
257
255
|
const taskId = req.params.taskId;
|
|
258
256
|
const isAdmin = req.user.access === 100;
|
|
259
|
-
const result = await
|
|
257
|
+
const result = await tasksManager.deleteTask(taskId, req.user.powrId, req.projectId, isAdmin);
|
|
260
258
|
if (result.success) {
|
|
261
259
|
res.json({
|
|
262
260
|
success: true,
|
|
@@ -284,7 +282,7 @@ router.post("/execute-scheduled", async (req, res) => {
|
|
|
284
282
|
console.log(`🔍 API: Executing scheduled tasks for project: ${projectId}`);
|
|
285
283
|
|
|
286
284
|
// Execute all scheduled tasks for this project
|
|
287
|
-
const result = await
|
|
285
|
+
const result = await tasksManager.executeScheduledTasks(projectId);
|
|
288
286
|
console.log(`✅ API: Scheduled tasks execution completed for project: ${projectId}`);
|
|
289
287
|
res.json({
|
|
290
288
|
success: true,
|