sdk-triggerx 0.1.24 → 0.1.25
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 +5 -1
- package/dist/api/getJobDataById.d.ts +1 -1
- package/dist/api/getJobDataById.js +11 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -277,10 +277,13 @@ console.log(jobs);
|
|
|
277
277
|
import { getJobDataById } from 'sdk-triggerx';
|
|
278
278
|
|
|
279
279
|
const jobId = 'YOUR_JOB_ID';
|
|
280
|
-
const
|
|
280
|
+
const userAddress = '0x...'; // The address that owns the job
|
|
281
|
+
const jobData = await getJobDataById(client, jobId, userAddress);
|
|
281
282
|
console.log(jobData);
|
|
282
283
|
```
|
|
283
284
|
|
|
285
|
+
> **Note:** The job data API now requires both the `jobId` and the user’s address as parameters. Passing both is mandatory; otherwise, you will receive a validation error from the backend.
|
|
286
|
+
|
|
284
287
|
---
|
|
285
288
|
|
|
286
289
|
### 4. Delete a Job
|
|
@@ -336,3 +339,4 @@ Includes:
|
|
|
336
339
|
|
|
337
340
|
**MIT License**
|
|
338
341
|
|
|
342
|
+
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TriggerXClient } from '../client';
|
|
2
2
|
import { JobDataWithTasks } from '../types';
|
|
3
|
-
export declare const getJobDataById: (client: TriggerXClient, jobId: string) => Promise<{
|
|
3
|
+
export declare const getJobDataById: (client: TriggerXClient, jobId: string, userAddress: string) => Promise<{
|
|
4
4
|
success: boolean;
|
|
5
5
|
data?: JobDataWithTasks;
|
|
6
6
|
error?: string;
|
|
@@ -3,24 +3,27 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.getJobDataById = void 0;
|
|
5
5
|
const errors_1 = require("../utils/errors");
|
|
6
|
-
const getJobDataById = async (client, jobId) => {
|
|
6
|
+
const getJobDataById = async (client, jobId, userAddress) => {
|
|
7
7
|
// Validate inputs
|
|
8
8
|
if (!jobId || typeof jobId !== 'string') {
|
|
9
9
|
return (0, errors_1.createErrorResponse)(new errors_1.ValidationError('jobId', 'Job ID is required and must be a string'), 'Validation error');
|
|
10
10
|
}
|
|
11
|
+
if (!userAddress || typeof userAddress !== 'string') {
|
|
12
|
+
return (0, errors_1.createErrorResponse)(new errors_1.ValidationError('userAddress', 'User address is required and must be a string'), 'Validation error');
|
|
13
|
+
}
|
|
11
14
|
const apiKey = client.getApiKey();
|
|
12
15
|
if (!apiKey) {
|
|
13
16
|
return (0, errors_1.createErrorResponse)(new errors_1.AuthenticationError('API key is required but not provided'), 'Authentication error');
|
|
14
17
|
}
|
|
15
18
|
try {
|
|
16
|
-
//
|
|
17
|
-
const jobResponse = await client.get(`/api/jobs/${jobId}`, {
|
|
19
|
+
// Fetch the job data using new user-based API endpoint
|
|
20
|
+
const jobResponse = await client.get(`/api/jobs/user/${userAddress}/${jobId}`, {
|
|
18
21
|
headers: {
|
|
19
22
|
'Content-Type': 'application/json',
|
|
20
23
|
'X-API-KEY': apiKey,
|
|
21
24
|
},
|
|
22
25
|
});
|
|
23
|
-
//
|
|
26
|
+
// Fetch the task data (logs) using new endpoint if required (let's keep same logic)
|
|
24
27
|
const taskResponse = await client.get(`/api/tasks/job/${jobId}`, {
|
|
25
28
|
headers: {
|
|
26
29
|
'Content-Type': 'application/json',
|
|
@@ -40,16 +43,16 @@ const getJobDataById = async (client, jobId) => {
|
|
|
40
43
|
const errorCode = (0, errors_1.determineErrorCode)(error, httpStatusCode);
|
|
41
44
|
if (error instanceof Error) {
|
|
42
45
|
if (error.message.includes('network') || error.message.includes('timeout')) {
|
|
43
|
-
return (0, errors_1.createErrorResponse)(new errors_1.NetworkError('Network error while fetching job data', { originalError: error, jobId }, httpStatusCode), 'Network error');
|
|
46
|
+
return (0, errors_1.createErrorResponse)(new errors_1.NetworkError('Network error while fetching job data', { originalError: error, jobId, userAddress }, httpStatusCode), 'Network error');
|
|
44
47
|
}
|
|
45
48
|
else if (error.message.includes('404') || error.message.includes('not found')) {
|
|
46
|
-
return (0, errors_1.createErrorResponse)(new errors_1.ValidationError('jobId', 'Job not found', { originalError: error, jobId }, 404), 'Validation error');
|
|
49
|
+
return (0, errors_1.createErrorResponse)(new errors_1.ValidationError('jobId or userAddress', 'Job not found', { originalError: error, jobId, userAddress }, 404), 'Validation error');
|
|
47
50
|
}
|
|
48
51
|
else if (error.message.includes('401') || error.message.includes('unauthorized')) {
|
|
49
|
-
return (0, errors_1.createErrorResponse)(new errors_1.AuthenticationError('Unauthorized access to job data', { originalError: error, jobId }, 401), 'Authentication error');
|
|
52
|
+
return (0, errors_1.createErrorResponse)(new errors_1.AuthenticationError('Unauthorized access to job data', { originalError: error, jobId, userAddress }, 401), 'Authentication error');
|
|
50
53
|
}
|
|
51
54
|
else if (error.message.includes('API') || error.message.includes('response')) {
|
|
52
|
-
return (0, errors_1.createErrorResponse)(new errors_1.ApiError('API error while fetching job data', { originalError: error, jobId }, httpStatusCode), 'API error');
|
|
55
|
+
return (0, errors_1.createErrorResponse)(new errors_1.ApiError('API error while fetching job data', { originalError: error, jobId, userAddress }, httpStatusCode), 'API error');
|
|
53
56
|
}
|
|
54
57
|
}
|
|
55
58
|
return (0, errors_1.createErrorResponse)(error, 'Failed to fetch job data');
|