sdk-triggerx 0.1.24 → 0.1.26
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 +19 -1
- package/dist/api/getJobDataById.d.ts +1 -1
- package/dist/api/getJobDataById.js +11 -8
- package/dist/api/getjob.d.ts +7 -0
- package/dist/api/getjob.js +42 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -277,10 +277,27 @@ 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
|
+
|
|
287
|
+
---
|
|
288
|
+
|
|
289
|
+
#### 📋 Get All Jobs for a User Address
|
|
290
|
+
|
|
291
|
+
```ts
|
|
292
|
+
import { getJobsByUserAddress } from 'sdk-triggerx';
|
|
293
|
+
|
|
294
|
+
const userAddress = '0x...';
|
|
295
|
+
const jobsByUser = await getJobsByUserAddress(client, userAddress);
|
|
296
|
+
console.log(jobsByUser);
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
> **Note:** This fetches all jobs belonging to the specified user address from the `/api/jobs/user/:user_address` endpoint.
|
|
300
|
+
|
|
284
301
|
---
|
|
285
302
|
|
|
286
303
|
### 4. Delete a Job
|
|
@@ -336,3 +353,4 @@ Includes:
|
|
|
336
353
|
|
|
337
354
|
**MIT License**
|
|
338
355
|
|
|
356
|
+
|
|
@@ -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');
|
package/dist/api/getjob.d.ts
CHANGED
|
@@ -6,3 +6,10 @@ import { JobResponseUser } from '../types';
|
|
|
6
6
|
* @returns JobResponse containing job data or error
|
|
7
7
|
*/
|
|
8
8
|
export declare function getJobData(client: TriggerXClient): Promise<JobResponseUser>;
|
|
9
|
+
/**
|
|
10
|
+
* Fetch all jobs for a given user address from the backend endpoint.
|
|
11
|
+
* @param client TriggerXClient instance
|
|
12
|
+
* @param userAddress string (the user's address)
|
|
13
|
+
* @returns JobResponseUser containing user's jobs or error
|
|
14
|
+
*/
|
|
15
|
+
export declare function getJobsByUserAddress(client: TriggerXClient, userAddress: string): Promise<JobResponseUser>;
|
package/dist/api/getjob.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getJobData = getJobData;
|
|
4
|
+
exports.getJobsByUserAddress = getJobsByUserAddress;
|
|
4
5
|
const errors_1 = require("../utils/errors");
|
|
5
6
|
/**
|
|
6
7
|
* Fetch job data for a given API key by calling the backend endpoint.
|
|
@@ -39,3 +40,44 @@ async function getJobData(client) {
|
|
|
39
40
|
return (0, errors_1.createErrorResponse)(error, 'Failed to fetch job data');
|
|
40
41
|
}
|
|
41
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Fetch all jobs for a given user address from the backend endpoint.
|
|
45
|
+
* @param client TriggerXClient instance
|
|
46
|
+
* @param userAddress string (the user's address)
|
|
47
|
+
* @returns JobResponseUser containing user's jobs or error
|
|
48
|
+
*/
|
|
49
|
+
async function getJobsByUserAddress(client, userAddress) {
|
|
50
|
+
if (!userAddress || typeof userAddress !== 'string') {
|
|
51
|
+
return (0, errors_1.createErrorResponse)(new errors_1.ValidationError('userAddress', 'User address is required and must be a string'), 'Validation error');
|
|
52
|
+
}
|
|
53
|
+
const apiKey = client.getApiKey();
|
|
54
|
+
if (!apiKey) {
|
|
55
|
+
return (0, errors_1.createErrorResponse)(new errors_1.AuthenticationError('API key is required but not provided'), 'Authentication error');
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
const data = await client.get(`/api/jobs/user/${userAddress}`, {
|
|
59
|
+
headers: {
|
|
60
|
+
'Content-Type': 'application/json',
|
|
61
|
+
'X-API-KEY': apiKey,
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
return { success: true, jobs: data.jobs };
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
console.error('Error fetching jobs by user address:', error);
|
|
68
|
+
const httpStatusCode = (0, errors_1.extractHttpStatusCode)(error);
|
|
69
|
+
const errorCode = (0, errors_1.determineErrorCode)(error, httpStatusCode);
|
|
70
|
+
if (error instanceof Error) {
|
|
71
|
+
if (error.message.includes('network') || error.message.includes('timeout')) {
|
|
72
|
+
return (0, errors_1.createErrorResponse)(new errors_1.NetworkError('Network error while fetching jobs for user', { originalError: error, userAddress }, httpStatusCode), 'Network error');
|
|
73
|
+
}
|
|
74
|
+
else if (error.message.includes('401') || error.message.includes('unauthorized')) {
|
|
75
|
+
return (0, errors_1.createErrorResponse)(new errors_1.AuthenticationError('Unauthorized access to user jobs', { originalError: error, userAddress }, 401), 'Authentication error');
|
|
76
|
+
}
|
|
77
|
+
else if (error.message.includes('API') || error.message.includes('response')) {
|
|
78
|
+
return (0, errors_1.createErrorResponse)(new errors_1.ApiError('API error while fetching jobs for user', { originalError: error, userAddress }, httpStatusCode), 'API error');
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return (0, errors_1.createErrorResponse)(error, 'Failed to fetch jobs for user');
|
|
82
|
+
}
|
|
83
|
+
}
|