sdk-triggerx 0.1.5 → 0.1.7

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.
Files changed (94) hide show
  1. package/dist/api/jobs.d.ts +21 -9
  2. package/dist/api/jobs.js +195 -39
  3. package/dist/client.d.ts +4 -1
  4. package/dist/client.js +13 -3
  5. package/dist/contracts/JobRegistry.d.ts +3 -3
  6. package/dist/contracts/JobRegistry.js +2 -4
  7. package/dist/index.d.ts +0 -1
  8. package/dist/index.js +0 -1
  9. package/dist/types.d.ts +118 -20
  10. package/package.json +14 -10
  11. package/.eslintrc.json +0 -16
  12. package/dist/api/tasks.d.ts +0 -4
  13. package/dist/api/tasks.js +0 -13
  14. package/dist/src/api/jobs.d.ts +0 -27
  15. package/dist/src/api/jobs.js +0 -297
  16. package/dist/src/api/tasks.d.ts +0 -4
  17. package/dist/src/api/tasks.js +0 -13
  18. package/dist/src/client.d.ts +0 -10
  19. package/dist/src/client.js +0 -37
  20. package/dist/src/config.d.ts +0 -6
  21. package/dist/src/config.js +0 -10
  22. package/dist/src/contracts/JobRegistry.d.ts +0 -12
  23. package/dist/src/contracts/JobRegistry.js +0 -24
  24. package/dist/src/contracts/TriggerXContract.d.ts +0 -6
  25. package/dist/src/contracts/TriggerXContract.js +0 -14
  26. package/dist/src/contracts/abi/JobRegistry.json +0 -1554
  27. package/dist/src/contracts/index.d.ts +0 -1
  28. package/dist/src/contracts/index.js +0 -17
  29. package/dist/src/index.d.ts +0 -7
  30. package/dist/src/index.js +0 -25
  31. package/dist/src/types.d.ts +0 -232
  32. package/dist/src/types.js +0 -15
  33. package/dist/src/utils/errors.d.ts +0 -4
  34. package/dist/src/utils/errors.js +0 -17
  35. package/dist/test/createJobExample.d.ts +0 -1
  36. package/dist/test/createJobExample.js +0 -84
  37. package/dist/test/deleteJob.test.d.ts +0 -1
  38. package/dist/test/deleteJob.test.js +0 -22
  39. package/dist/test/example.test.d.ts +0 -1
  40. package/dist/test/example.test.js +0 -11
  41. package/dist/test/getJobDataById.test.d.ts +0 -1
  42. package/dist/test/getJobDataById.test.js +0 -23
  43. package/dist/test/getUserData.test.d.ts +0 -1
  44. package/dist/test/getUserData.test.js +0 -22
  45. package/dist/test/getjob.test.d.ts +0 -1
  46. package/dist/test/getjob.test.js +0 -21
  47. package/dist/test/testTgFunctions.d.ts +0 -1
  48. package/dist/test/testTgFunctions.js +0 -56
  49. package/jest.config.js +0 -7
  50. package/scripts/deploy.ts +0 -9
  51. package/src/api/checkTgBalance.ts +0 -27
  52. package/src/api/deleteJob.ts +0 -22
  53. package/src/api/getJobDataById.ts +0 -24
  54. package/src/api/getUserData.ts +0 -24
  55. package/src/api/getjob.ts +0 -26
  56. package/src/api/jobs.ts +0 -352
  57. package/src/api/topupTg.ts +0 -17
  58. package/src/api/withdrawTg.ts +0 -25
  59. package/src/client.ts +0 -38
  60. package/src/config.ts +0 -13
  61. package/src/contracts/JobRegistry.ts +0 -45
  62. package/src/contracts/TriggerXContract.ts +0 -14
  63. package/src/contracts/abi/.gitkeep +0 -1
  64. package/src/contracts/abi/GasRegistry.json +0 -607
  65. package/src/contracts/abi/JobRegistry.json +0 -1554
  66. package/src/contracts/index.ts +0 -1
  67. package/src/index.ts +0 -7
  68. package/src/types.ts +0 -249
  69. package/src/utils/errors.ts +0 -13
  70. package/test/createJobExample.ts +0 -91
  71. package/test/deleteJob.test.ts +0 -25
  72. package/test/example.test.d.ts +0 -1
  73. package/test/example.test.js +0 -11
  74. package/test/example.test.ts +0 -10
  75. package/test/getJobDataById.test.ts +0 -27
  76. package/test/getUserData.test.ts +0 -25
  77. package/test/getjob.test.ts +0 -23
  78. package/test/testTgFunctions.ts +0 -56
  79. package/tsconfig.json +0 -16
  80. /package/dist/{src/api → api}/checkTgBalance.d.ts +0 -0
  81. /package/dist/{src/api → api}/checkTgBalance.js +0 -0
  82. /package/dist/{src/api → api}/deleteJob.d.ts +0 -0
  83. /package/dist/{src/api → api}/deleteJob.js +0 -0
  84. /package/dist/{src/api → api}/getJobDataById.d.ts +0 -0
  85. /package/dist/{src/api → api}/getJobDataById.js +0 -0
  86. /package/dist/{src/api → api}/getUserData.d.ts +0 -0
  87. /package/dist/{src/api → api}/getUserData.js +0 -0
  88. /package/dist/{src/api → api}/getjob.d.ts +0 -0
  89. /package/dist/{src/api → api}/getjob.js +0 -0
  90. /package/dist/{src/api → api}/topupTg.d.ts +0 -0
  91. /package/dist/{src/api → api}/topupTg.js +0 -0
  92. /package/dist/{src/api → api}/withdrawTg.d.ts +0 -0
  93. /package/dist/{src/api → api}/withdrawTg.js +0 -0
  94. /package/dist/{src/contracts → contracts}/abi/GasRegistry.json +0 -0
@@ -1,15 +1,27 @@
1
1
  import { TriggerXClient } from '../client';
2
2
  import { TimeBasedJobInput, EventBasedJobInput, ConditionBasedJobInput, CreateJobData, JobResponse } from '../types';
3
- export declare function toCreateJobDataFromTime(input: TimeBasedJobInput): CreateJobData;
4
- export declare function toCreateJobDataFromEvent(input: EventBasedJobInput): CreateJobData;
5
- export declare function toCreateJobDataFromCondition(input: ConditionBasedJobInput): CreateJobData;
3
+ import { Signer } from 'ethers';
4
+ export declare function toCreateJobDataFromTime(input: TimeBasedJobInput, balances: {
5
+ etherBalance: bigint;
6
+ tokenBalanceWei: bigint;
7
+ }, userAddress: string, jobCostPrediction: number): CreateJobData;
8
+ export declare function toCreateJobDataFromEvent(input: EventBasedJobInput, balances: {
9
+ etherBalance: bigint;
10
+ tokenBalanceWei: bigint;
11
+ }, userAddress: string, jobCostPrediction: number): CreateJobData;
12
+ export declare function toCreateJobDataFromCondition(input: ConditionBasedJobInput, balances: {
13
+ etherBalance: bigint;
14
+ tokenBalanceWei: bigint;
15
+ }, userAddress: string, jobCostPrediction: number): CreateJobData;
6
16
  export interface CreateJobParams {
7
17
  jobInput: TimeBasedJobInput | EventBasedJobInput | ConditionBasedJobInput;
8
- privateKey: string;
9
- providerUrl: string;
10
- contractAddress: string;
11
- abi: any;
12
- encodedData: string;
13
- jobType: number;
18
+ signer: Signer;
19
+ encodedData?: string;
14
20
  }
21
+ /**
22
+ * Create a job on the blockchain.
23
+ * @param client TriggerXClient instance
24
+ * @param params Parameters for creating the job
25
+ * @returns JobResponse containing the result of the job creation
26
+ */
15
27
  export declare function createJob(client: TriggerXClient, params: CreateJobParams): Promise<JobResponse>;
package/dist/api/jobs.js CHANGED
@@ -1,31 +1,39 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.toCreateJobDataFromTime = toCreateJobDataFromTime;
4
7
  exports.toCreateJobDataFromEvent = toCreateJobDataFromEvent;
5
8
  exports.toCreateJobDataFromCondition = toCreateJobDataFromCondition;
6
9
  exports.createJob = createJob;
7
10
  const JobRegistry_1 = require("../contracts/JobRegistry");
11
+ const ethers_1 = require("ethers");
12
+ const JobRegistry_json_1 = __importDefault(require("../contracts/abi/JobRegistry.json"));
13
+ const topupTg_1 = require("./topupTg");
14
+ const checkTgBalance_1 = require("./checkTgBalance");
8
15
  const JOB_ID = '300949528249665590178224313442040528409305273634097553067152835846309150732';
9
16
  const DYNAMIC_ARGS_URL = 'https://teal-random-koala-993.mypinata.cloud/ipfs/bafkreif426p7t7takzhw3g6we2h6wsvf27p5jxj3gaiynqf22p3jvhx4la';
10
- function toCreateJobDataFromTime(input) {
17
+ const JOB_REGISTRY_ADDRESS = '0xdB66c11221234C6B19cCBd29868310c31494C21C'; // Set your fixed contract address here
18
+ function toCreateJobDataFromTime(input, balances, userAddress, jobCostPrediction) {
11
19
  return {
12
20
  job_id: JOB_ID,
13
- user_address: input.userAddress,
14
- ether_balance: input.etherBalance,
15
- token_balance: input.tokenBalance,
21
+ user_address: userAddress,
22
+ ether_balance: balances.etherBalance,
23
+ token_balance: balances.tokenBalanceWei,
16
24
  job_title: input.jobTitle,
17
25
  task_definition_id: input.dynamicArgumentsScriptUrl ? 2 : 1,
18
26
  custom: true,
19
27
  time_frame: input.timeFrame,
20
- recurring: input.recurring ?? false,
21
- job_cost_prediction: input.jobCostPrediction,
28
+ recurring: false,
29
+ job_cost_prediction: jobCostPrediction,
22
30
  timezone: input.timezone,
23
- created_chain_id: input.createdChainId,
31
+ created_chain_id: input.chainId,
24
32
  schedule_type: input.scheduleType,
25
- time_interval: input.timeInterval,
26
- cron_expression: input.cronExpression,
27
- specific_schedule: input.specificSchedule,
28
- target_chain_id: input.targetChainId,
33
+ time_interval: input.scheduleType === 'interval' ? input.timeInterval : undefined,
34
+ cron_expression: input.scheduleType === 'cron' ? input.cronExpression : undefined,
35
+ specific_schedule: input.scheduleType === 'specific' ? input.specificSchedule : undefined,
36
+ target_chain_id: input.chainId,
29
37
  target_contract_address: input.targetContractAddress,
30
38
  target_function: input.targetFunction,
31
39
  abi: input.abi,
@@ -35,24 +43,24 @@ function toCreateJobDataFromTime(input) {
35
43
  is_imua: input.isImua ?? true,
36
44
  };
37
45
  }
38
- function toCreateJobDataFromEvent(input) {
46
+ function toCreateJobDataFromEvent(input, balances, userAddress, jobCostPrediction) {
39
47
  return {
40
48
  job_id: JOB_ID,
41
- user_address: input.userAddress,
42
- ether_balance: input.etherBalance,
43
- token_balance: input.tokenBalance,
49
+ user_address: userAddress,
50
+ ether_balance: balances.etherBalance,
51
+ token_balance: balances.tokenBalanceWei,
44
52
  job_title: input.jobTitle,
45
53
  task_definition_id: input.dynamicArgumentsScriptUrl ? 4 : 3,
46
54
  custom: true,
47
55
  time_frame: input.timeFrame,
48
56
  recurring: input.recurring ?? false,
49
- job_cost_prediction: input.jobCostPrediction,
57
+ job_cost_prediction: jobCostPrediction,
50
58
  timezone: input.timezone,
51
- created_chain_id: input.createdChainId,
52
- trigger_chain_id: input.triggerChainId,
59
+ created_chain_id: input.chainId,
60
+ trigger_chain_id: input.triggerChainId ?? input.chainId,
53
61
  trigger_contract_address: input.triggerContractAddress,
54
62
  trigger_event: input.triggerEvent,
55
- target_chain_id: input.targetChainId,
63
+ target_chain_id: input.chainId,
56
64
  target_contract_address: input.targetContractAddress,
57
65
  target_function: input.targetFunction,
58
66
  abi: input.abi,
@@ -62,26 +70,26 @@ function toCreateJobDataFromEvent(input) {
62
70
  is_imua: input.isImua ?? true,
63
71
  };
64
72
  }
65
- function toCreateJobDataFromCondition(input) {
73
+ function toCreateJobDataFromCondition(input, balances, userAddress, jobCostPrediction) {
66
74
  return {
67
75
  job_id: JOB_ID,
68
- user_address: input.userAddress,
69
- ether_balance: input.etherBalance,
70
- token_balance: input.tokenBalance,
76
+ user_address: userAddress,
77
+ ether_balance: balances.etherBalance,
78
+ token_balance: balances.tokenBalanceWei,
71
79
  job_title: input.jobTitle,
72
80
  task_definition_id: input.dynamicArgumentsScriptUrl ? 6 : 5,
73
81
  custom: true,
74
82
  time_frame: input.timeFrame,
75
83
  recurring: input.recurring ?? false,
76
- job_cost_prediction: input.jobCostPrediction,
84
+ job_cost_prediction: jobCostPrediction,
77
85
  timezone: input.timezone,
78
- created_chain_id: input.createdChainId,
86
+ created_chain_id: input.chainId,
79
87
  condition_type: input.conditionType,
80
88
  upper_limit: input.upperLimit,
81
89
  lower_limit: input.lowerLimit,
82
90
  value_source_type: input.valueSourceType,
83
91
  value_source_url: input.valueSourceUrl,
84
- target_chain_id: input.targetChainId,
92
+ target_chain_id: input.chainId,
85
93
  target_contract_address: input.targetContractAddress,
86
94
  target_function: input.targetFunction,
87
95
  abi: input.abi,
@@ -91,44 +99,192 @@ function toCreateJobDataFromCondition(input) {
91
99
  is_imua: input.isImua ?? true,
92
100
  };
93
101
  }
102
+ // --- Encoding helpers for different job types ---
103
+ function encodeJobType1Data(timeInterval) {
104
+ return ethers_1.ethers.AbiCoder.defaultAbiCoder().encode(['uint256'], [timeInterval]);
105
+ }
106
+ function encodeJobType2Data(timeInterval, ipfsHash) {
107
+ return ethers_1.ethers.AbiCoder.defaultAbiCoder().encode(['uint256', 'bytes32'], [timeInterval, ipfsHash]);
108
+ }
109
+ function encodeJobType3or5Data(recurringJob) {
110
+ return ethers_1.ethers.AbiCoder.defaultAbiCoder().encode(['bool'], [recurringJob]);
111
+ }
112
+ function encodeJobType4or6Data(recurringJob, ipfsHash) {
113
+ return ethers_1.ethers.AbiCoder.defaultAbiCoder().encode(['bool', 'bytes32'], [recurringJob, ipfsHash]);
114
+ }
115
+ /**
116
+ * Create a job on the blockchain.
117
+ * @param client TriggerXClient instance
118
+ * @param params Parameters for creating the job
119
+ * @returns JobResponse containing the result of the job creation
120
+ */
94
121
  async function createJob(client, params) {
95
- // 1. Call contract to create job and get jobId
96
- const { jobInput, privateKey, providerUrl, contractAddress, abi, encodedData, jobType } = params;
97
- let jobTitle, timeFrame, targetContractAddress;
122
+ let { jobInput, signer, encodedData } = params;
123
+ // Use the API key from the client instance
124
+ const apiKey = client.getApiKey();
125
+ const userAddress = await signer.getAddress();
126
+ let jobTitle, timeFrame, targetContractAddress, jobType;
98
127
  if ('jobTitle' in jobInput)
99
128
  jobTitle = jobInput.jobTitle;
100
129
  if ('timeFrame' in jobInput)
101
130
  timeFrame = jobInput.timeFrame;
102
131
  if ('targetContractAddress' in jobInput)
103
132
  targetContractAddress = jobInput.targetContractAddress;
133
+ // Validate schedule-specific fields for time-based jobs
134
+ if ('scheduleType' in jobInput) {
135
+ if (jobInput.scheduleType === 'interval' && (jobInput.timeInterval === undefined || jobInput.timeInterval === null)) {
136
+ throw new Error('timeInterval is required when scheduleType is interval');
137
+ }
138
+ if (jobInput.scheduleType === 'cron' && !jobInput.cronExpression) {
139
+ throw new Error('cronExpression is required when scheduleType is cron');
140
+ }
141
+ if (jobInput.scheduleType === 'specific' && !jobInput.specificSchedule) {
142
+ throw new Error('specificSchedule is required when scheduleType is specific');
143
+ }
144
+ }
145
+ // Infer jobType from jobInput
146
+ if ('scheduleType' in jobInput) {
147
+ jobType = jobInput.dynamicArgumentsScriptUrl ? 2 : 1; // Time-based job
148
+ }
149
+ else if ('triggerChainId' in jobInput) {
150
+ jobType = jobInput.dynamicArgumentsScriptUrl ? 4 : 3; // Event-based job
151
+ }
152
+ else {
153
+ jobType = jobInput.dynamicArgumentsScriptUrl ? 6 : 5; // Condition-based job
154
+ }
155
+ // --- Generate encodedData if not provided ---
156
+ if (!encodedData) {
157
+ // Time-based jobs
158
+ if ('scheduleType' in jobInput) {
159
+ if (jobType === 1) {
160
+ encodedData = encodeJobType1Data(jobInput.timeInterval ?? 0);
161
+ }
162
+ else if (jobType === 2) {
163
+ encodedData = encodeJobType2Data(jobInput.timeInterval ?? 0, jobInput.dynamicArgumentsScriptUrl || '');
164
+ }
165
+ }
166
+ // Event-based jobs
167
+ else if ('triggerChainId' in jobInput) {
168
+ if (jobType === 3 || jobType === 5) {
169
+ encodedData = encodeJobType3or5Data(jobInput.recurring ?? false);
170
+ }
171
+ else if (jobType === 4 || jobType === 6) {
172
+ encodedData = encodeJobType4or6Data(jobInput.recurring ?? false, jobInput.dynamicArgumentsScriptUrl || '');
173
+ }
174
+ }
175
+ // Condition-based jobs
176
+ else {
177
+ if (jobType === 3 || jobType === 5) {
178
+ encodedData = encodeJobType3or5Data(jobInput.recurring ?? false);
179
+ }
180
+ else if (jobType === 4 || jobType === 6) {
181
+ encodedData = encodeJobType4or6Data(jobInput.recurring ?? false, jobInput.dynamicArgumentsScriptUrl || '');
182
+ }
183
+ }
184
+ }
185
+ // Handle job_cost_prediction logic based on argType (static/dynamic)
186
+ // If static, set to 0.1. If dynamic, call backend API to get fee and ask user to proceed.
187
+ // Determine argType directly from user input
188
+ let argType = 1; // default to static
189
+ if ('argType' in jobInput) {
190
+ if (jobInput.argType === 'dynamic' || jobInput.argType === 2) {
191
+ argType = 2;
192
+ }
193
+ else {
194
+ argType = 1;
195
+ }
196
+ }
197
+ //if jobis time based then check the no of executions of the job from time frame and time interval by deviding time frame by time interval
198
+ let noOfExecutions = 1;
199
+ if ('scheduleType' in jobInput) {
200
+ noOfExecutions = jobInput.timeFrame / (jobInput.timeInterval ?? 0);
201
+ }
202
+ // Set job_cost_prediction
203
+ let job_cost_prediction = 0.1 * noOfExecutions; // default for static
204
+ if (argType === 2) {
205
+ // Dynamic: call backend API to get fee
206
+ const ipfs_url = jobInput.dynamicArgumentsScriptUrl;
207
+ if (!ipfs_url) {
208
+ throw new Error('dynamicArgumentsScriptUrl is required for dynamic argType');
209
+ }
210
+ // Call backend API to get fee
211
+ let fee = 0;
212
+ try {
213
+ const feeRes = await client.get('/api/fees', { params: { ipfs_url } });
214
+ // The API now returns { total_fee: number }
215
+ if (feeRes && typeof feeRes.total_fee === 'number') {
216
+ fee = feeRes.total_fee;
217
+ }
218
+ else if (feeRes && feeRes.data && typeof feeRes.data.total_fee === 'number') {
219
+ fee = feeRes.data.total_fee;
220
+ }
221
+ else {
222
+ throw new Error('Invalid response from /api/fees: missing total_fee');
223
+ }
224
+ }
225
+ catch (err) {
226
+ throw new Error('Failed to fetch job cost prediction: ' + err.message);
227
+ }
228
+ job_cost_prediction = fee * noOfExecutions;
229
+ }
230
+ // Ask user if they want to proceed
231
+ // Since this is a library, we can't prompt in Node.js directly.
232
+ // We'll throw an error with the fee and let the caller handle the prompt/confirmation.
233
+ // If you want to automate, you can add a `proceed` flag to params in the future.
234
+ // Check if the user has enough TG to cover the job cost prediction
235
+ const { tgBalanceWei, tgBalance } = await (0, checkTgBalance_1.checkTgBalance)(signer);
236
+ if (Number(tgBalance) < job_cost_prediction) {
237
+ // Check if user has enabled auto topup
238
+ // For each job type, autotopupTG should be present in jobInput
239
+ const autoTopupTG = jobInput.autotopupTG === true;
240
+ if (!autoTopupTG) {
241
+ throw new Error(`Insufficient TG balance. Job cost prediction is ${job_cost_prediction}. Current TG balance: ${tgBalance}. Please set autotopupTG: true in jobInput.`);
242
+ }
243
+ else {
244
+ // autotopupTG is true, automatically top up
245
+ const requiredTG = Math.ceil(job_cost_prediction * 1000); // 1 TG = 0.001 ETH
246
+ await (0, topupTg_1.topupTg)(requiredTG, signer);
247
+ }
248
+ }
249
+ // Compute balances to store with the job
250
+ const tokenBalanceWei = tgBalanceWei;
251
+ const etherBalance = tokenBalanceWei / 1000n;
252
+ // Patch jobInput with job_cost_prediction for downstream usage
253
+ jobInput.jobCostPrediction = job_cost_prediction;
104
254
  const jobId = await (0, JobRegistry_1.createJobOnChain)({
105
255
  jobTitle: jobTitle,
106
256
  jobType,
107
257
  timeFrame: timeFrame,
108
258
  targetContractAddress: targetContractAddress,
109
- encodedData,
110
- contractAddress,
111
- abi,
112
- privateKey,
113
- providerUrl,
259
+ encodedData: encodedData || '',
260
+ contractAddress: JOB_REGISTRY_ADDRESS,
261
+ abi: JobRegistry_json_1.default.abi,
262
+ signer,
114
263
  });
115
264
  // 2. Convert input to CreateJobData
116
265
  let jobData;
266
+ const balances = { etherBalance, tokenBalanceWei };
117
267
  if ('scheduleType' in jobInput) {
118
- jobData = toCreateJobDataFromTime(jobInput);
268
+ jobData = toCreateJobDataFromTime(jobInput, balances, userAddress, job_cost_prediction);
119
269
  }
120
270
  else if ('triggerChainId' in jobInput) {
121
- jobData = toCreateJobDataFromEvent(jobInput);
271
+ jobData = toCreateJobDataFromEvent(jobInput, balances, userAddress, job_cost_prediction);
122
272
  }
123
273
  else {
124
- jobData = toCreateJobDataFromCondition(jobInput);
274
+ jobData = toCreateJobDataFromCondition(jobInput, balances, userAddress, job_cost_prediction);
125
275
  }
126
276
  // 3. Set the job_id from contract
127
277
  jobData.job_id = jobId;
128
278
  // 4. Call the API
129
279
  try {
130
- const res = await client.post('/api/jobs', [jobData], {
131
- headers: { 'Content-Type': 'application/json', 'X-API-KEY': 'ADMIN' },
280
+ // Ensure JSON-serializable payload (use numbers for balances)
281
+ const jobDataForApi = {
282
+ ...jobData,
283
+ ether_balance: typeof jobData.ether_balance === 'bigint' ? Number(jobData.ether_balance) : Number(jobData.ether_balance),
284
+ token_balance: typeof jobData.token_balance === 'bigint' ? Number(jobData.token_balance) : Number(jobData.token_balance),
285
+ };
286
+ const res = await client.post('/api/jobs', [jobDataForApi], {
287
+ headers: { 'Content-Type': 'application/json', 'X-API-KEY': apiKey },
132
288
  });
133
289
  return { success: true, data: res };
134
290
  }
package/dist/client.d.ts CHANGED
@@ -1,7 +1,10 @@
1
1
  import { AxiosRequestConfig } from 'axios';
2
2
  export declare class TriggerXClient {
3
3
  private client;
4
- constructor(config?: AxiosRequestConfig);
4
+ private apiKey;
5
+ constructor(apiKey: string, config?: AxiosRequestConfig);
6
+ getApiKey(): string;
5
7
  get<T>(url: string, config?: AxiosRequestConfig): Promise<T>;
6
8
  post<T>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T>;
9
+ put<T>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T>;
7
10
  }
package/dist/client.js CHANGED
@@ -7,14 +7,19 @@ exports.TriggerXClient = void 0;
7
7
  const axios_1 = __importDefault(require("axios"));
8
8
  const config_1 = require("./config");
9
9
  class TriggerXClient {
10
- constructor(config) {
10
+ constructor(apiKey, config) {
11
+ this.apiKey = apiKey; // Initialize the apiKey
11
12
  const baseConfig = (0, config_1.getConfig)();
12
13
  this.client = axios_1.default.create({
13
- baseURL: config?.baseURL || baseConfig.apiUrl || 'http://localhost:9002',
14
- headers: { 'Authorization': `Bearer ${baseConfig.apiKey}` },
14
+ baseURL: config?.baseURL || baseConfig.apiUrl || 'https://data.triggerx.network', //http://localhost:9002 , https://data.triggerx.network
15
+ headers: { 'Authorization': `Bearer ${this.apiKey}` }, // Set the API key here
15
16
  ...config,
16
17
  });
17
18
  }
19
+ // Method to get the API key
20
+ getApiKey() {
21
+ return this.apiKey;
22
+ }
18
23
  async get(url, config) {
19
24
  const response = await this.client.get(url, config);
20
25
  return response.data;
@@ -23,5 +28,10 @@ class TriggerXClient {
23
28
  const response = await this.client.post(url, data, config);
24
29
  return response.data;
25
30
  }
31
+ // New PUT method
32
+ async put(url, data, config) {
33
+ const response = await this.client.put(url, data, config);
34
+ return response.data;
35
+ }
26
36
  }
27
37
  exports.TriggerXClient = TriggerXClient;
@@ -1,3 +1,4 @@
1
+ import { Signer } from 'ethers';
1
2
  export interface CreateJobOnChainParams {
2
3
  jobTitle: string;
3
4
  jobType: number;
@@ -6,7 +7,6 @@ export interface CreateJobOnChainParams {
6
7
  encodedData: string;
7
8
  contractAddress: string;
8
9
  abi: any;
9
- privateKey: string;
10
- providerUrl: string;
10
+ signer: Signer;
11
11
  }
12
- export declare function createJobOnChain({ jobTitle, jobType, timeFrame, targetContractAddress, encodedData, contractAddress, abi, privateKey, providerUrl, }: CreateJobOnChainParams): Promise<string>;
12
+ export declare function createJobOnChain({ jobTitle, jobType, timeFrame, targetContractAddress, encodedData, contractAddress, abi, signer, }: CreateJobOnChainParams): Promise<string>;
@@ -2,10 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createJobOnChain = createJobOnChain;
4
4
  const ethers_1 = require("ethers");
5
- async function createJobOnChain({ jobTitle, jobType, timeFrame, targetContractAddress, encodedData, contractAddress, abi, privateKey, providerUrl, }) {
6
- const provider = new ethers_1.ethers.JsonRpcProvider(providerUrl);
7
- const wallet = new ethers_1.ethers.Wallet(privateKey, provider);
8
- const contract = new ethers_1.ethers.Contract(contractAddress, abi, wallet);
5
+ async function createJobOnChain({ jobTitle, jobType, timeFrame, targetContractAddress, encodedData, contractAddress, abi, signer, }) {
6
+ const contract = new ethers_1.ethers.Contract(contractAddress, abi, signer);
9
7
  const tx = await contract.createJob(jobTitle, jobType, timeFrame, targetContractAddress, encodedData);
10
8
  const receipt = await tx.wait();
11
9
  // Try to extract jobId from event logs (assume event is JobCreated(jobId,...))
package/dist/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  export * from './client';
2
2
  export * from './config';
3
3
  export * from './types';
4
- export * from './api/tasks';
5
4
  export * from './api/jobs';
6
5
  export { createJobOnChain } from './contracts/JobRegistry';
7
6
  export * from './contracts';
package/dist/index.js CHANGED
@@ -18,7 +18,6 @@ exports.createJobOnChain = void 0;
18
18
  __exportStar(require("./client"), exports);
19
19
  __exportStar(require("./config"), exports);
20
20
  __exportStar(require("./types"), exports);
21
- __exportStar(require("./api/tasks"), exports);
22
21
  __exportStar(require("./api/jobs"), exports);
23
22
  var JobRegistry_1 = require("./contracts/JobRegistry");
24
23
  Object.defineProperty(exports, "createJobOnChain", { enumerable: true, get: function () { return JobRegistry_1.createJobOnChain; } });
package/dist/types.d.ts CHANGED
@@ -28,9 +28,6 @@ export type CreateJobInput = (TimeBasedJobInput & {
28
28
  argType: ArgType.Static | ArgType.Dynamic;
29
29
  });
30
30
  export interface TimeBasedJobInput {
31
- userAddress: string;
32
- etherBalance: BigInt | number;
33
- tokenBalance: BigInt | number;
34
31
  jobTitle: string;
35
32
  timeFrame: number;
36
33
  scheduleType: 'cron' | 'specific' | 'interval';
@@ -38,21 +35,16 @@ export interface TimeBasedJobInput {
38
35
  cronExpression?: string;
39
36
  specificSchedule?: string;
40
37
  timezone: string;
41
- recurring?: boolean;
42
- jobCostPrediction: number;
43
- createdChainId: string;
44
- targetChainId: string;
38
+ chainId: string;
45
39
  targetContractAddress: string;
46
40
  targetFunction: string;
47
41
  abi: string;
48
42
  isImua?: boolean;
49
43
  arguments?: string[];
50
44
  dynamicArgumentsScriptUrl?: string;
45
+ autotopupTG?: boolean;
51
46
  }
52
47
  export interface EventBasedJobInput {
53
- userAddress: string;
54
- etherBalance: BigInt | number;
55
- tokenBalance: BigInt | number;
56
48
  jobTitle: string;
57
49
  timeFrame: number;
58
50
  triggerChainId: string;
@@ -60,38 +52,33 @@ export interface EventBasedJobInput {
60
52
  triggerEvent: string;
61
53
  timezone: string;
62
54
  recurring?: boolean;
63
- jobCostPrediction: number;
64
- createdChainId: string;
65
- targetChainId: string;
55
+ chainId: string;
66
56
  targetContractAddress: string;
67
57
  targetFunction: string;
68
58
  abi: string;
69
59
  isImua?: boolean;
70
60
  arguments?: string[];
71
61
  dynamicArgumentsScriptUrl?: string;
62
+ autotopupTG?: boolean;
72
63
  }
73
64
  export interface ConditionBasedJobInput {
74
- userAddress: string;
75
- etherBalance: BigInt | number;
76
- tokenBalance: BigInt | number;
77
65
  jobTitle: string;
78
66
  timeFrame: number;
79
- conditionType: string;
67
+ conditionType: 'greater_than' | 'less_than' | 'between' | 'equals' | 'not_equals' | 'greater_equal' | 'less_equal';
80
68
  upperLimit: number;
81
69
  lowerLimit: number;
82
70
  valueSourceType: string;
83
71
  valueSourceUrl: string;
84
72
  timezone: string;
85
73
  recurring?: boolean;
86
- jobCostPrediction: number;
87
- createdChainId: string;
88
- targetChainId: string;
74
+ chainId: string;
89
75
  targetContractAddress: string;
90
76
  targetFunction: string;
91
77
  abi: string;
92
78
  isImua?: boolean;
93
79
  arguments?: string[];
94
80
  dynamicArgumentsScriptUrl?: string;
81
+ autotopupTG?: boolean;
95
82
  }
96
83
  export interface CreateJobData {
97
84
  job_id: string;
@@ -132,3 +119,114 @@ export interface JobResponse {
132
119
  data?: any;
133
120
  error?: string;
134
121
  }
122
+ export interface JobDataAPI {
123
+ job_id: string;
124
+ job_title: string;
125
+ task_definition_id: number;
126
+ user_id: number;
127
+ link_job_id: string;
128
+ chain_status: number;
129
+ custom: boolean;
130
+ time_frame: number;
131
+ recurring: boolean;
132
+ status: string;
133
+ job_cost_prediction: number;
134
+ job_cost_actual: number;
135
+ task_ids: number[];
136
+ created_at: Date;
137
+ updated_at: Date;
138
+ last_executed_at: Date;
139
+ timezone: string;
140
+ is_imua: boolean;
141
+ created_chain_id: string;
142
+ }
143
+ export interface TimeJobData {
144
+ job_id: string;
145
+ task_definition_id: number;
146
+ expiration_time: Date;
147
+ created_at: Date;
148
+ updated_at: Date;
149
+ time_interval: number;
150
+ schedule_type: string;
151
+ cron_expression: string;
152
+ specific_schedule: string;
153
+ timezone: string;
154
+ next_execution_timestamp: Date;
155
+ target_chain_id: string;
156
+ target_contract_address: string;
157
+ target_function: string;
158
+ abi: string;
159
+ arg_type: number;
160
+ arguments: string[];
161
+ dynamic_arguments_script_url: string;
162
+ is_completed: boolean;
163
+ is_active: boolean;
164
+ }
165
+ export interface EventJobData {
166
+ job_id: string;
167
+ task_definition_id: number;
168
+ expiration_time: Date;
169
+ created_at: Date;
170
+ updated_at: Date;
171
+ recurring: boolean;
172
+ trigger_chain_id: string;
173
+ trigger_contract_address: string;
174
+ trigger_event: string;
175
+ timezone: string;
176
+ target_chain_id: string;
177
+ target_contract_address: string;
178
+ target_function: string;
179
+ abi: string;
180
+ arg_type: number;
181
+ arguments: string[];
182
+ dynamic_arguments_script_url: string;
183
+ is_completed: boolean;
184
+ is_active: boolean;
185
+ }
186
+ export interface ConditionJobData {
187
+ job_id: string;
188
+ task_definition_id: number;
189
+ expiration_time: Date;
190
+ created_at: Date;
191
+ updated_at: Date;
192
+ recurring: boolean;
193
+ condition_type: string;
194
+ upper_limit: number;
195
+ lower_limit: number;
196
+ value_source_type: string;
197
+ value_source_url: string;
198
+ timezone: string;
199
+ target_chain_id: string;
200
+ target_contract_address: string;
201
+ target_function: string;
202
+ abi: string;
203
+ arg_type: number;
204
+ arguments: string[];
205
+ dynamic_arguments_script_url: string;
206
+ is_completed: boolean;
207
+ is_active: boolean;
208
+ }
209
+ export interface JobResponseUser {
210
+ success: boolean;
211
+ error?: string;
212
+ jobs?: JobResponseAPI;
213
+ }
214
+ export interface JobResponseAPI {
215
+ job_data?: JobDataAPI;
216
+ time_job_data?: TimeJobData;
217
+ event_job_data?: EventJobData;
218
+ condition_job_data?: ConditionJobData;
219
+ }
220
+ export interface UserData {
221
+ user_id: number;
222
+ user_address: string;
223
+ job_ids: string[];
224
+ ether_balance: BigInt | number;
225
+ token_balance: BigInt | number;
226
+ user_points: number;
227
+ total_jobs: number;
228
+ total_tasks: number;
229
+ created_at: Date;
230
+ last_updated_at: Date;
231
+ email: string;
232
+ }