sdk-triggerx 0.1.25 → 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 +14 -0
- package/dist/api/getjob.d.ts +7 -0
- package/dist/api/getjob.js +42 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -286,6 +286,20 @@ console.log(jobData);
|
|
|
286
286
|
|
|
287
287
|
---
|
|
288
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
|
+
|
|
301
|
+
---
|
|
302
|
+
|
|
289
303
|
### 4. Delete a Job
|
|
290
304
|
|
|
291
305
|
```ts
|
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
|
+
}
|