sdk-triggerx 0.1.22 → 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 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 jobData = await getJobDataById(client, jobId);
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
- // First, fetch the job data
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
- // Then, fetch the task data (logs) for this job
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/jobs.js CHANGED
@@ -44,6 +44,10 @@ function toCreateJobDataFromTime(input, balances, userAddress, jobCostPrediction
44
44
  arguments: input.arguments,
45
45
  dynamic_arguments_script_url: input.dynamicArgumentsScriptUrl,
46
46
  is_imua: input.isImua ?? true,
47
+ is_safe: input.walletMode === 'safe',
48
+ safe_name: input.safeName || '',
49
+ safe_address: input.safeAddress || '',
50
+ language: input.language || '',
47
51
  };
48
52
  }
49
53
  function toCreateJobDataFromEvent(input, balances, userAddress, jobCostPrediction) {
@@ -71,6 +75,10 @@ function toCreateJobDataFromEvent(input, balances, userAddress, jobCostPredictio
71
75
  arguments: input.arguments,
72
76
  dynamic_arguments_script_url: input.dynamicArgumentsScriptUrl,
73
77
  is_imua: input.isImua ?? true,
78
+ is_safe: input.walletMode === 'safe',
79
+ safe_name: input.safeName || '',
80
+ safe_address: input.safeAddress || '',
81
+ language: input.language || '',
74
82
  };
75
83
  }
76
84
  function toCreateJobDataFromCondition(input, balances, userAddress, jobCostPrediction) {
@@ -100,6 +108,10 @@ function toCreateJobDataFromCondition(input, balances, userAddress, jobCostPredi
100
108
  arguments: input.arguments,
101
109
  dynamic_arguments_script_url: input.dynamicArgumentsScriptUrl,
102
110
  is_imua: input.isImua ?? true,
111
+ is_safe: input.walletMode === 'safe',
112
+ safe_name: input.safeName || '',
113
+ safe_address: input.safeAddress || '',
114
+ language: input.language || '',
103
115
  };
104
116
  }
105
117
  // --- Encoding helpers for different job types ---
package/dist/types.d.ts CHANGED
@@ -60,11 +60,13 @@ export interface TimeBasedJobInput {
60
60
  dynamicArgumentsScriptUrl?: string;
61
61
  autotopupTG?: boolean;
62
62
  walletMode?: WalletMode;
63
+ safeName?: string;
64
+ language?: string;
63
65
  /**
64
66
  * The Safe address to use when walletMode is 'safe'.
65
67
  * Required if walletMode is 'safe'.
66
68
  */
67
- safeAddress: string;
69
+ safeAddress?: string;
68
70
  }
69
71
  export interface EventBasedJobInput {
70
72
  jobTitle: string;
@@ -83,11 +85,13 @@ export interface EventBasedJobInput {
83
85
  dynamicArgumentsScriptUrl?: string;
84
86
  autotopupTG?: boolean;
85
87
  walletMode?: WalletMode;
88
+ safeName?: string;
89
+ language?: string;
86
90
  /**
87
91
  * The Safe address to use when walletMode is 'safe'.
88
92
  * Required if walletMode is 'safe'.
89
93
  */
90
- safeAddress: string;
94
+ safeAddress?: string;
91
95
  }
92
96
  export interface ConditionBasedJobInput {
93
97
  jobTitle: string;
@@ -108,11 +112,13 @@ export interface ConditionBasedJobInput {
108
112
  dynamicArgumentsScriptUrl?: string;
109
113
  autotopupTG?: boolean;
110
114
  walletMode?: WalletMode;
115
+ safeName?: string;
116
+ language?: string;
111
117
  /**
112
118
  * The Safe address to use when walletMode is 'safe'.
113
119
  * Required if walletMode is 'safe'.
114
120
  */
115
- safeAddress: string;
121
+ safeAddress?: string;
116
122
  }
117
123
  export interface CreateJobData {
118
124
  job_id: string;
@@ -147,6 +153,10 @@ export interface CreateJobData {
147
153
  arguments?: string[];
148
154
  dynamic_arguments_script_url?: string;
149
155
  is_imua: boolean;
156
+ is_safe?: boolean;
157
+ safe_name?: string;
158
+ safe_address?: string;
159
+ language?: string;
150
160
  }
151
161
  export interface JobResponse {
152
162
  success: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sdk-triggerx",
3
- "version": "0.1.22",
3
+ "version": "0.1.25",
4
4
  "description": "SDK for interacting with the TriggerX backend and smart contracts.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",