sdk-triggerx 0.1.5 → 0.1.6

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.
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const sdk_triggerx_1 = require("sdk-triggerx");
3
+ const src_1 = require("../src");
4
4
  const types_1 = require("../src/types");
5
5
  const ethers_1 = require("ethers");
6
6
  async function main() {
7
7
  const apiKey = 'TGRX-02c20872-4bdf-4fd9-9e74-556861b16690';
8
- const client = new sdk_triggerx_1.TriggerXClient(apiKey);
8
+ const client = new src_1.TriggerXClient(apiKey);
9
9
  // Example: Time-based static job
10
10
  const jobInput = {
11
11
  jobType: types_1.JobType.Time,
@@ -74,7 +74,7 @@ async function main() {
74
74
  const provider = new ethers_1.ethers.JsonRpcProvider(providerUrl);
75
75
  const signer = new ethers_1.ethers.Wallet(privateKey, provider);
76
76
  console.log('Job input:', client);
77
- const result = await (0, sdk_triggerx_1.createJob)(client, {
77
+ const result = await (0, src_1.createJob)(client, {
78
78
  jobInput: jobInput,
79
79
  // @ts-ignore
80
80
  signer: signer,
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "sdk-triggerx",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
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",
7
7
  "scripts": {
8
8
  "build": "tsc",
9
9
  "test": "jest",
10
- "lint": "eslint src --ext .ts"
10
+ "lint": "eslint src --ext .ts",
11
+ "example": "npm run -s build && node dist/test/createJobExample.js"
11
12
  },
12
13
  "author": "",
13
14
  "license": "MIT",
@@ -22,11 +23,11 @@
22
23
  "ethers": ">=6 <7"
23
24
  },
24
25
  "devDependencies": {
25
- "ethers": "^6.15.0",
26
26
  "@types/jest": "^30.0.0",
27
27
  "@typescript-eslint/eslint-plugin": "^8.38.0",
28
28
  "@typescript-eslint/parser": "^8.38.0",
29
29
  "eslint": "^9.32.0",
30
+ "ethers": "^6.15.0",
30
31
  "jest": "^30.0.5",
31
32
  "ts-jest": "^29.4.0",
32
33
  "typescript": "^5.8.3"
@@ -1,11 +1,11 @@
1
- import { TriggerXClient, createJob } from 'sdk-triggerx';
1
+ import { TriggerXClient, createJob } from '../src';
2
2
  import { JobType, ArgType, CreateJobInput } from '../src/types';
3
3
  import { ethers } from 'ethers';
4
4
 
5
5
  async function main() {
6
6
 
7
7
  const apiKey = 'TGRX-02c20872-4bdf-4fd9-9e74-556861b16690';
8
- const client = new TriggerXClient(apiKey as any);
8
+ const client = new TriggerXClient(apiKey as any);
9
9
 
10
10
  // Example: Time-based static job
11
11
  const jobInput: CreateJobInput = {
@@ -1,15 +0,0 @@
1
- import { TriggerXClient } from '../client';
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;
6
- export interface CreateJobParams {
7
- jobInput: TimeBasedJobInput | EventBasedJobInput | ConditionBasedJobInput;
8
- privateKey: string;
9
- providerUrl: string;
10
- contractAddress: string;
11
- abi: any;
12
- encodedData: string;
13
- jobType: number;
14
- }
15
- export declare function createJob(client: TriggerXClient, params: CreateJobParams): Promise<JobResponse>;
package/dist/api/jobs.js DELETED
@@ -1,138 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toCreateJobDataFromTime = toCreateJobDataFromTime;
4
- exports.toCreateJobDataFromEvent = toCreateJobDataFromEvent;
5
- exports.toCreateJobDataFromCondition = toCreateJobDataFromCondition;
6
- exports.createJob = createJob;
7
- const JobRegistry_1 = require("../contracts/JobRegistry");
8
- const JOB_ID = '300949528249665590178224313442040528409305273634097553067152835846309150732';
9
- const DYNAMIC_ARGS_URL = 'https://teal-random-koala-993.mypinata.cloud/ipfs/bafkreif426p7t7takzhw3g6we2h6wsvf27p5jxj3gaiynqf22p3jvhx4la';
10
- function toCreateJobDataFromTime(input) {
11
- return {
12
- job_id: JOB_ID,
13
- user_address: input.userAddress,
14
- ether_balance: input.etherBalance,
15
- token_balance: input.tokenBalance,
16
- job_title: input.jobTitle,
17
- task_definition_id: input.dynamicArgumentsScriptUrl ? 2 : 1,
18
- custom: true,
19
- time_frame: input.timeFrame,
20
- recurring: input.recurring ?? false,
21
- job_cost_prediction: input.jobCostPrediction,
22
- timezone: input.timezone,
23
- created_chain_id: input.createdChainId,
24
- 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,
29
- target_contract_address: input.targetContractAddress,
30
- target_function: input.targetFunction,
31
- abi: input.abi,
32
- arg_type: input.dynamicArgumentsScriptUrl ? 2 : 1,
33
- arguments: input.arguments,
34
- dynamic_arguments_script_url: input.dynamicArgumentsScriptUrl,
35
- is_imua: input.isImua ?? true,
36
- };
37
- }
38
- function toCreateJobDataFromEvent(input) {
39
- return {
40
- job_id: JOB_ID,
41
- user_address: input.userAddress,
42
- ether_balance: input.etherBalance,
43
- token_balance: input.tokenBalance,
44
- job_title: input.jobTitle,
45
- task_definition_id: input.dynamicArgumentsScriptUrl ? 4 : 3,
46
- custom: true,
47
- time_frame: input.timeFrame,
48
- recurring: input.recurring ?? false,
49
- job_cost_prediction: input.jobCostPrediction,
50
- timezone: input.timezone,
51
- created_chain_id: input.createdChainId,
52
- trigger_chain_id: input.triggerChainId,
53
- trigger_contract_address: input.triggerContractAddress,
54
- trigger_event: input.triggerEvent,
55
- target_chain_id: input.targetChainId,
56
- target_contract_address: input.targetContractAddress,
57
- target_function: input.targetFunction,
58
- abi: input.abi,
59
- arg_type: input.dynamicArgumentsScriptUrl ? 2 : 1,
60
- arguments: input.arguments,
61
- dynamic_arguments_script_url: input.dynamicArgumentsScriptUrl,
62
- is_imua: input.isImua ?? true,
63
- };
64
- }
65
- function toCreateJobDataFromCondition(input) {
66
- return {
67
- job_id: JOB_ID,
68
- user_address: input.userAddress,
69
- ether_balance: input.etherBalance,
70
- token_balance: input.tokenBalance,
71
- job_title: input.jobTitle,
72
- task_definition_id: input.dynamicArgumentsScriptUrl ? 6 : 5,
73
- custom: true,
74
- time_frame: input.timeFrame,
75
- recurring: input.recurring ?? false,
76
- job_cost_prediction: input.jobCostPrediction,
77
- timezone: input.timezone,
78
- created_chain_id: input.createdChainId,
79
- condition_type: input.conditionType,
80
- upper_limit: input.upperLimit,
81
- lower_limit: input.lowerLimit,
82
- value_source_type: input.valueSourceType,
83
- value_source_url: input.valueSourceUrl,
84
- target_chain_id: input.targetChainId,
85
- target_contract_address: input.targetContractAddress,
86
- target_function: input.targetFunction,
87
- abi: input.abi,
88
- arg_type: input.dynamicArgumentsScriptUrl ? 2 : 1,
89
- arguments: input.arguments,
90
- dynamic_arguments_script_url: input.dynamicArgumentsScriptUrl,
91
- is_imua: input.isImua ?? true,
92
- };
93
- }
94
- 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;
98
- if ('jobTitle' in jobInput)
99
- jobTitle = jobInput.jobTitle;
100
- if ('timeFrame' in jobInput)
101
- timeFrame = jobInput.timeFrame;
102
- if ('targetContractAddress' in jobInput)
103
- targetContractAddress = jobInput.targetContractAddress;
104
- const jobId = await (0, JobRegistry_1.createJobOnChain)({
105
- jobTitle: jobTitle,
106
- jobType,
107
- timeFrame: timeFrame,
108
- targetContractAddress: targetContractAddress,
109
- encodedData,
110
- contractAddress,
111
- abi,
112
- privateKey,
113
- providerUrl,
114
- });
115
- // 2. Convert input to CreateJobData
116
- let jobData;
117
- if ('scheduleType' in jobInput) {
118
- jobData = toCreateJobDataFromTime(jobInput);
119
- }
120
- else if ('triggerChainId' in jobInput) {
121
- jobData = toCreateJobDataFromEvent(jobInput);
122
- }
123
- else {
124
- jobData = toCreateJobDataFromCondition(jobInput);
125
- }
126
- // 3. Set the job_id from contract
127
- jobData.job_id = jobId;
128
- // 4. Call the API
129
- try {
130
- const res = await client.post('/api/jobs', [jobData], {
131
- headers: { 'Content-Type': 'application/json', 'X-API-KEY': 'ADMIN' },
132
- });
133
- return { success: true, data: res };
134
- }
135
- catch (error) {
136
- return { success: false, error: error.message };
137
- }
138
- }
@@ -1,4 +0,0 @@
1
- import { TriggerXClient } from '../client';
2
- import { Task, ApiResponse } from '../types';
3
- export declare function getTasks(client: TriggerXClient): Promise<ApiResponse<Task[]>>;
4
- export declare function createTask(client: TriggerXClient, task: Partial<Task>): Promise<ApiResponse<Task>>;
package/dist/api/tasks.js DELETED
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTasks = getTasks;
4
- exports.createTask = createTask;
5
- async function getTasks(client) {
6
- // Placeholder implementation
7
- return client.get('/tasks');
8
- }
9
- async function createTask(client, task) {
10
- // Placeholder implementation
11
- // return client.post<ApiResponse<Task>>('/tasks', task);
12
- return { data: { id: '1', name: task.name || '', status: 'pending', createdAt: new Date().toISOString() } };
13
- }
package/dist/client.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import { AxiosRequestConfig } from 'axios';
2
- export declare class TriggerXClient {
3
- private client;
4
- constructor(config?: AxiosRequestConfig);
5
- get<T>(url: string, config?: AxiosRequestConfig): Promise<T>;
6
- post<T>(url: string, data?: any, config?: AxiosRequestConfig): Promise<T>;
7
- }
package/dist/client.js DELETED
@@ -1,27 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.TriggerXClient = void 0;
7
- const axios_1 = __importDefault(require("axios"));
8
- const config_1 = require("./config");
9
- class TriggerXClient {
10
- constructor(config) {
11
- const baseConfig = (0, config_1.getConfig)();
12
- this.client = axios_1.default.create({
13
- baseURL: config?.baseURL || baseConfig.apiUrl || 'http://localhost:9002',
14
- headers: { 'Authorization': `Bearer ${baseConfig.apiKey}` },
15
- ...config,
16
- });
17
- }
18
- async get(url, config) {
19
- const response = await this.client.get(url, config);
20
- return response.data;
21
- }
22
- async post(url, data, config) {
23
- const response = await this.client.post(url, data, config);
24
- return response.data;
25
- }
26
- }
27
- exports.TriggerXClient = TriggerXClient;
package/dist/config.d.ts DELETED
@@ -1,6 +0,0 @@
1
- export interface SDKConfig {
2
- apiKey: string;
3
- apiUrl: string;
4
- contractAddress: string;
5
- }
6
- export declare function getConfig(): SDKConfig;
package/dist/config.js DELETED
@@ -1,15 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getConfig = getConfig;
7
- const dotenv_1 = __importDefault(require("dotenv"));
8
- dotenv_1.default.config();
9
- function getConfig() {
10
- return {
11
- apiKey: process.env.API_KEY || '',
12
- apiUrl: process.env.API_URL || '',
13
- contractAddress: process.env.CONTRACT_ADDRESS || '',
14
- };
15
- }
@@ -1,12 +0,0 @@
1
- export interface CreateJobOnChainParams {
2
- jobTitle: string;
3
- jobType: number;
4
- timeFrame: number;
5
- targetContractAddress: string;
6
- encodedData: string;
7
- contractAddress: string;
8
- abi: any;
9
- privateKey: string;
10
- providerUrl: string;
11
- }
12
- export declare function createJobOnChain({ jobTitle, jobType, timeFrame, targetContractAddress, encodedData, contractAddress, abi, privateKey, providerUrl, }: CreateJobOnChainParams): Promise<string>;
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createJobOnChain = createJobOnChain;
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);
9
- const tx = await contract.createJob(jobTitle, jobType, timeFrame, targetContractAddress, encodedData);
10
- const receipt = await tx.wait();
11
- // Try to extract jobId from event logs (assume event is JobCreated(jobId,...))
12
- const event = receipt.logs
13
- .map((log) => {
14
- try {
15
- return contract.interface.parseLog(log);
16
- }
17
- catch {
18
- return null;
19
- }
20
- })
21
- .find((e) => e && e.name === 'JobCreated');
22
- if (event && event.args && event.args[0]) {
23
- return event.args[0].toString();
24
- }
25
- throw new Error('Job ID not found in contract events');
26
- }
@@ -1,6 +0,0 @@
1
- import { Provider } from 'ethers';
2
- export declare class TriggerXContract {
3
- private contract;
4
- constructor(address: string, abi: any, provider: Provider);
5
- getTaskCount(): Promise<number>;
6
- }
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TriggerXContract = void 0;
4
- const ethers_1 = require("ethers");
5
- class TriggerXContract {
6
- constructor(address, abi, provider) {
7
- this.contract = new ethers_1.Contract(address, abi, provider);
8
- }
9
- async getTaskCount() {
10
- // Placeholder for contract call
11
- return this.contract.taskCount();
12
- }
13
- }
14
- exports.TriggerXContract = TriggerXContract;