zkcloudworker 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/ts/src/index.d.ts +3 -2
- package/lib/ts/src/index.js +3 -2
- package/lib/ts/src/utils/base64.d.ts +5 -0
- package/lib/ts/src/utils/base64.js +90 -0
- package/lib/ts/src/{fetch.js → utils/fetch.js} +24 -6
- package/lib/ts/src/utils/fields.d.ts +3 -0
- package/lib/ts/src/utils/fields.js +33 -0
- package/lib/ts/tsconfig.tsbuildinfo +1 -1
- package/lib/web/src/api/api.js +263 -286
- package/lib/web/src/api/api.js.map +1 -1
- package/lib/web/src/cloud/cloud.js +12 -25
- package/lib/web/src/cloud/cloud.js.map +1 -1
- package/lib/web/src/cloud/files.js +59 -68
- package/lib/web/src/cloud/files.js.map +1 -1
- package/lib/web/src/cloud/local.js +221 -259
- package/lib/web/src/cloud/local.js.map +1 -1
- package/lib/web/src/encryption/encryption.js +2 -5
- package/lib/web/src/encryption/encryption.js.map +1 -1
- package/lib/web/src/encryption/messages.js +24 -29
- package/lib/web/src/encryption/messages.js.map +1 -1
- package/lib/web/src/encryption/nats-client.js +67 -83
- package/lib/web/src/encryption/nats-client.js.map +1 -1
- package/lib/web/src/fee.js +3 -6
- package/lib/web/src/fee.js.map +1 -1
- package/lib/web/src/index.d.ts +3 -2
- package/lib/web/src/index.js +3 -2
- package/lib/web/src/index.js.map +1 -1
- package/lib/web/src/mina.js +60 -67
- package/lib/web/src/mina.js.map +1 -1
- package/lib/web/src/utils/base64.d.ts +5 -0
- package/lib/web/src/utils/base64.js +84 -0
- package/lib/web/src/utils/base64.js.map +1 -0
- package/lib/web/src/utils/fetch.js +79 -0
- package/lib/web/src/utils/fetch.js.map +1 -0
- package/lib/web/src/utils/fields.d.ts +3 -0
- package/lib/web/src/utils/fields.js +29 -0
- package/lib/web/src/utils/fields.js.map +1 -0
- package/lib/web/tsconfig.web.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/lib/ts/src/api/client-api.d.ts +0 -147
- package/lib/ts/src/api/client-api.js +0 -122
- package/lib/web/src/api/client-api.d.ts +0 -147
- package/lib/web/src/api/client-api.js +0 -134
- package/lib/web/src/api/client-api.js.map +0 -1
- package/lib/web/src/fetch.js +0 -68
- package/lib/web/src/fetch.js.map +0 -1
- /package/lib/ts/src/{fetch.d.ts → utils/fetch.d.ts} +0 -0
- /package/lib/web/src/{fetch.d.ts → utils/fetch.d.ts} +0 -0
package/lib/web/src/api/api.js
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
import { __awaiter } from "tslib";
|
2
1
|
import axios from "axios";
|
3
2
|
import chalk from "chalk";
|
4
3
|
import { sleep } from "../mina";
|
@@ -19,7 +18,7 @@ export class zkCloudWorkerClient {
|
|
19
18
|
const { jwt, zkcloudworker, chain, webhook } = params;
|
20
19
|
this.jwt = jwt;
|
21
20
|
this.endpoint = ZKCLOUDWORKER_API;
|
22
|
-
this.chain = chain
|
21
|
+
this.chain = chain ?? "devnet";
|
23
22
|
this.webhook = webhook;
|
24
23
|
if (jwt === "local") {
|
25
24
|
if (zkcloudworker === undefined)
|
@@ -43,21 +42,19 @@ export class zkCloudWorkerClient {
|
|
43
42
|
* The developers repo should provide a BackupPlugin with the name task
|
44
43
|
* that can be called with the given parameters
|
45
44
|
*/
|
46
|
-
recursiveProof(data) {
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
};
|
60
|
-
});
|
45
|
+
async recursiveProof(data) {
|
46
|
+
const result = await this.apiHub("recursiveProof", data);
|
47
|
+
if (result.data === "error")
|
48
|
+
return {
|
49
|
+
success: false,
|
50
|
+
error: result.error,
|
51
|
+
};
|
52
|
+
else
|
53
|
+
return {
|
54
|
+
success: result.success,
|
55
|
+
jobId: result.data,
|
56
|
+
error: result.error,
|
57
|
+
};
|
61
58
|
}
|
62
59
|
/**
|
63
60
|
* Starts a new job for the function call using serverless api call
|
@@ -75,34 +72,31 @@ export class zkCloudWorkerClient {
|
|
75
72
|
* @returns { success: boolean, error?: string, jobId?: string }
|
76
73
|
* where jonId is the jobId of the job
|
77
74
|
*/
|
78
|
-
execute(data) {
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
error: "execute call error",
|
104
|
-
};
|
105
|
-
});
|
75
|
+
async execute(data) {
|
76
|
+
const result = await this.apiHub("execute", data);
|
77
|
+
if (result.data === "error" ||
|
78
|
+
(typeof result.data === "string" && result.data.startsWith("error")))
|
79
|
+
return {
|
80
|
+
success: false,
|
81
|
+
error: result.error,
|
82
|
+
};
|
83
|
+
else if (result.success === false || result.data?.success === false)
|
84
|
+
return {
|
85
|
+
success: false,
|
86
|
+
error: result.error ?? result.data?.error ?? "execute call failed",
|
87
|
+
};
|
88
|
+
else if (result.success === true && result.data?.success === true)
|
89
|
+
return {
|
90
|
+
success: result.success,
|
91
|
+
jobId: data.mode === "sync" ? undefined : result.data.jobId,
|
92
|
+
result: data.mode === "sync" ? result.data : undefined,
|
93
|
+
error: result.error,
|
94
|
+
};
|
95
|
+
else
|
96
|
+
return {
|
97
|
+
success: false,
|
98
|
+
error: "execute call error",
|
99
|
+
};
|
106
100
|
}
|
107
101
|
/**
|
108
102
|
* Starts a new job for the function call using serverless api call
|
@@ -116,22 +110,20 @@ export class zkCloudWorkerClient {
|
|
116
110
|
* @returns { success: boolean, error?: string, jobId?: string }
|
117
111
|
* where jonId is the jobId of the job
|
118
112
|
*/
|
119
|
-
sendTransactions(data) {
|
120
|
-
|
121
|
-
|
122
|
-
if
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
};
|
134
|
-
});
|
113
|
+
async sendTransactions(data) {
|
114
|
+
const result = await this.apiHub("sendTransactions", data);
|
115
|
+
if (result.data === "error")
|
116
|
+
// TODO: check if this is correct in AWS code
|
117
|
+
return {
|
118
|
+
success: false,
|
119
|
+
error: result.error,
|
120
|
+
};
|
121
|
+
else
|
122
|
+
return {
|
123
|
+
success: result.success,
|
124
|
+
txId: result.data,
|
125
|
+
error: result.error,
|
126
|
+
};
|
135
127
|
}
|
136
128
|
/**
|
137
129
|
* Gets the result of the job using serverless api call
|
@@ -145,22 +137,20 @@ export class zkCloudWorkerClient {
|
|
145
137
|
* if the job is finished, the result will be set and error will be undefined
|
146
138
|
* if the job is not found, the result will be undefined and error will be set
|
147
139
|
*/
|
148
|
-
jobResult(data) {
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
};
|
163
|
-
});
|
140
|
+
async jobResult(data) {
|
141
|
+
const result = await this.apiHub("jobResult", data);
|
142
|
+
if (this.isError(result.data))
|
143
|
+
return {
|
144
|
+
success: false,
|
145
|
+
error: result.error,
|
146
|
+
result: result.data,
|
147
|
+
};
|
148
|
+
else
|
149
|
+
return {
|
150
|
+
success: result.success,
|
151
|
+
error: result.error,
|
152
|
+
result: result.data,
|
153
|
+
};
|
164
154
|
}
|
165
155
|
/**
|
166
156
|
* Gets the result of the job using serverless api call
|
@@ -173,73 +163,66 @@ export class zkCloudWorkerClient {
|
|
173
163
|
* if the job is finished, the result will be set and error will be undefined
|
174
164
|
* if the job is not found, the result will be undefined and error will be set
|
175
165
|
*/
|
176
|
-
deploy(data) {
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
repo,
|
184
|
-
args: packageManager,
|
185
|
-
});
|
186
|
-
if (result.data === "error" ||
|
187
|
-
(typeof result.data === "string" && result.data.startsWith("error")))
|
188
|
-
return {
|
189
|
-
success: false,
|
190
|
-
error: result.error,
|
191
|
-
};
|
192
|
-
else
|
193
|
-
return {
|
194
|
-
success: result.success && ((_a = result.data) === null || _a === void 0 ? void 0 : _a.success),
|
195
|
-
jobId: (_b = result.data) === null || _b === void 0 ? void 0 : _b.jobId,
|
196
|
-
error: result.error,
|
197
|
-
};
|
166
|
+
async deploy(data) {
|
167
|
+
// TODO: encrypt env.json
|
168
|
+
const { repo, developer, packageManager } = data;
|
169
|
+
const result = await this.apiHub("deploy", {
|
170
|
+
developer,
|
171
|
+
repo,
|
172
|
+
args: packageManager,
|
198
173
|
});
|
174
|
+
if (result.data === "error" ||
|
175
|
+
(typeof result.data === "string" && result.data.startsWith("error")))
|
176
|
+
return {
|
177
|
+
success: false,
|
178
|
+
error: result.error,
|
179
|
+
};
|
180
|
+
else
|
181
|
+
return {
|
182
|
+
success: result.success && result.data?.success,
|
183
|
+
jobId: result.data?.jobId,
|
184
|
+
error: result.error,
|
185
|
+
};
|
199
186
|
}
|
200
187
|
/**
|
201
188
|
* Gets the billing report for the jobs sent using JWT
|
202
189
|
* @returns { success: boolean, error?: string, result?: any }
|
203
190
|
* where result is the billing report
|
204
191
|
*/
|
205
|
-
queryBilling() {
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
};
|
220
|
-
});
|
192
|
+
async queryBilling() {
|
193
|
+
const result = await this.apiHub("queryBilling", {});
|
194
|
+
if (this.isError(result.data))
|
195
|
+
return {
|
196
|
+
success: false,
|
197
|
+
error: result.error,
|
198
|
+
result: result.data,
|
199
|
+
};
|
200
|
+
else
|
201
|
+
return {
|
202
|
+
success: result.success,
|
203
|
+
error: result.error,
|
204
|
+
result: result.data,
|
205
|
+
};
|
221
206
|
}
|
222
207
|
/**
|
223
208
|
* Gets the remaining balance
|
224
209
|
* @returns { success: boolean, error?: string, result?: any }
|
225
210
|
* where result is the billing report
|
226
211
|
*/
|
227
|
-
getBalance() {
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
};
|
242
|
-
});
|
212
|
+
async getBalance() {
|
213
|
+
const result = await this.apiHub("getBalance", {});
|
214
|
+
if (this.isError(result.data))
|
215
|
+
return {
|
216
|
+
success: false,
|
217
|
+
error: result.error,
|
218
|
+
result: result.data,
|
219
|
+
};
|
220
|
+
else
|
221
|
+
return {
|
222
|
+
success: result.success,
|
223
|
+
error: result.error,
|
224
|
+
result: result.data,
|
225
|
+
};
|
243
226
|
}
|
244
227
|
/**
|
245
228
|
* Waits for the job to finish
|
@@ -252,194 +235,188 @@ export class zkCloudWorkerClient {
|
|
252
235
|
* @returns { success: boolean, error?: string, result?: any }
|
253
236
|
* where result is the result of the job
|
254
237
|
*/
|
255
|
-
waitForJobResult(data) {
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
if (
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
const text = log.replace(/error/gi, (matched) => chalk.red(matched));
|
277
|
-
console.log(text);
|
278
|
-
}
|
238
|
+
async waitForJobResult(data) {
|
239
|
+
const maxAttempts = data?.maxAttempts ?? 360; // 1 hour
|
240
|
+
const interval = data?.interval ?? 10000;
|
241
|
+
const maxErrors = data?.maxErrors ?? 10;
|
242
|
+
const errorDelay = 30000; // 30 seconds
|
243
|
+
const printedLogs = [];
|
244
|
+
const printLogs = data.printLogs ?? true;
|
245
|
+
function isAllLogsFetched() {
|
246
|
+
if (printLogs === false)
|
247
|
+
return true;
|
248
|
+
// search for "Billed Duration" in the logs and return true if found
|
249
|
+
return printedLogs.some((log) => log.includes("Billed Duration"));
|
250
|
+
}
|
251
|
+
function print(logs) {
|
252
|
+
logs.forEach((log) => {
|
253
|
+
if (printedLogs.includes(log) === false) {
|
254
|
+
printedLogs.push(log);
|
255
|
+
if (printLogs) {
|
256
|
+
// replace all occurrences of "error" with red color
|
257
|
+
const text = log.replace(/error/gi, (matched) => chalk.red(matched));
|
258
|
+
console.log(text);
|
279
259
|
}
|
280
|
-
}
|
260
|
+
}
|
261
|
+
});
|
262
|
+
}
|
263
|
+
let attempts = 0;
|
264
|
+
let errors = 0;
|
265
|
+
while (attempts < maxAttempts) {
|
266
|
+
const result = await this.apiHub("jobResult", {
|
267
|
+
jobId: data.jobId,
|
268
|
+
includeLogs: printLogs,
|
269
|
+
});
|
270
|
+
if (printLogs === true &&
|
271
|
+
result?.data?.logs !== undefined &&
|
272
|
+
result?.data?.logs !== null &&
|
273
|
+
Array.isArray(result.data.logs) === true)
|
274
|
+
print(result.data.logs);
|
275
|
+
if (result.success === false) {
|
276
|
+
errors++;
|
277
|
+
if (errors > maxErrors) {
|
278
|
+
return {
|
279
|
+
success: false,
|
280
|
+
error: "Too many network errors",
|
281
|
+
result: undefined,
|
282
|
+
};
|
283
|
+
}
|
284
|
+
await sleep(errorDelay * errors);
|
281
285
|
}
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
if (
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
errors++;
|
296
|
-
if (errors > maxErrors) {
|
297
|
-
return {
|
298
|
-
success: false,
|
299
|
-
error: "Too many network errors",
|
300
|
-
result: undefined,
|
301
|
-
};
|
302
|
-
}
|
303
|
-
yield sleep(errorDelay * errors);
|
286
|
+
else {
|
287
|
+
if (this.isError(result.data))
|
288
|
+
return {
|
289
|
+
success: false,
|
290
|
+
error: result.error,
|
291
|
+
result: result.data,
|
292
|
+
};
|
293
|
+
else if (result.data?.result !== undefined && isAllLogsFetched()) {
|
294
|
+
return {
|
295
|
+
success: result.success,
|
296
|
+
error: result.error,
|
297
|
+
result: result.data,
|
298
|
+
};
|
304
299
|
}
|
305
|
-
else {
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
};
|
312
|
-
else if (((_g = result.data) === null || _g === void 0 ? void 0 : _g.result) !== undefined && isAllLogsFetched()) {
|
313
|
-
return {
|
314
|
-
success: result.success,
|
315
|
-
error: result.error,
|
316
|
-
result: result.data,
|
317
|
-
};
|
318
|
-
}
|
319
|
-
else if (((_h = result.data) === null || _h === void 0 ? void 0 : _h.jobStatus) === "failed" && isAllLogsFetched()) {
|
320
|
-
return {
|
321
|
-
success: false,
|
322
|
-
error: "Job failed",
|
323
|
-
result: result.data,
|
324
|
-
};
|
325
|
-
}
|
326
|
-
yield sleep(interval);
|
300
|
+
else if (result.data?.jobStatus === "failed" && isAllLogsFetched()) {
|
301
|
+
return {
|
302
|
+
success: false,
|
303
|
+
error: "Job failed",
|
304
|
+
result: result.data,
|
305
|
+
};
|
327
306
|
}
|
328
|
-
|
307
|
+
await sleep(interval);
|
329
308
|
}
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
309
|
+
attempts++;
|
310
|
+
}
|
311
|
+
return {
|
312
|
+
success: false,
|
313
|
+
error: "Timeout",
|
314
|
+
result: undefined,
|
315
|
+
};
|
336
316
|
}
|
337
317
|
/**
|
338
318
|
* Calls the serverless API
|
339
319
|
* @param command the command of the API
|
340
320
|
* @param data the data of the API
|
341
321
|
* */
|
342
|
-
apiHub(command,
|
322
|
+
async apiHub(command,
|
343
323
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
344
324
|
data
|
345
325
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
346
326
|
) {
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
327
|
+
if (this.jwt === "local") {
|
328
|
+
if (this.localWorker === undefined)
|
329
|
+
throw new Error("localWorker is undefined");
|
330
|
+
switch (command) {
|
331
|
+
case "recursiveProof": {
|
332
|
+
const jobId = await LocalCloud.run({
|
333
|
+
command: "recursiveProof",
|
334
|
+
data,
|
335
|
+
chain: this.chain,
|
336
|
+
localWorker: this.localWorker,
|
337
|
+
});
|
338
|
+
return {
|
339
|
+
success: true,
|
340
|
+
data: jobId,
|
341
|
+
};
|
342
|
+
}
|
343
|
+
case "execute": {
|
344
|
+
const jobId = await LocalCloud.run({
|
345
|
+
command: "execute",
|
346
|
+
data,
|
347
|
+
chain: this.chain,
|
348
|
+
localWorker: this.localWorker,
|
349
|
+
});
|
350
|
+
if (data.mode === "sync")
|
351
|
+
return { success: true, data: LocalStorage.jobs[jobId].result };
|
352
|
+
else
|
360
353
|
return {
|
361
354
|
success: true,
|
362
355
|
data: jobId,
|
363
356
|
};
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
data,
|
369
|
-
chain: this.chain,
|
370
|
-
localWorker: this.localWorker,
|
371
|
-
});
|
372
|
-
if (data.mode === "sync")
|
373
|
-
return { success: true, data: LocalStorage.jobs[jobId].result };
|
374
|
-
else
|
375
|
-
return {
|
376
|
-
success: true,
|
377
|
-
data: jobId,
|
378
|
-
};
|
379
|
-
}
|
380
|
-
case "jobResult": {
|
381
|
-
const job = LocalStorage.jobs[data.jobId];
|
382
|
-
if (job === undefined) {
|
383
|
-
return {
|
384
|
-
success: false,
|
385
|
-
error: "local job not found",
|
386
|
-
};
|
387
|
-
}
|
388
|
-
else {
|
389
|
-
return {
|
390
|
-
success: true,
|
391
|
-
data: job,
|
392
|
-
};
|
393
|
-
}
|
394
|
-
}
|
395
|
-
case "sendTransactions": {
|
357
|
+
}
|
358
|
+
case "jobResult": {
|
359
|
+
const job = LocalStorage.jobs[data.jobId];
|
360
|
+
if (job === undefined) {
|
396
361
|
return {
|
397
|
-
success:
|
398
|
-
|
362
|
+
success: false,
|
363
|
+
error: "local job not found",
|
399
364
|
};
|
400
365
|
}
|
401
|
-
|
402
|
-
return {
|
403
|
-
success: true,
|
404
|
-
data: "local_deploy",
|
405
|
-
};
|
406
|
-
case "queryBilling":
|
366
|
+
else {
|
407
367
|
return {
|
408
368
|
success: true,
|
409
|
-
data:
|
410
|
-
};
|
411
|
-
default:
|
412
|
-
return {
|
413
|
-
success: false,
|
414
|
-
error: "local_error",
|
369
|
+
data: job,
|
415
370
|
};
|
371
|
+
}
|
416
372
|
}
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
jwtToken: this.jwt,
|
423
|
-
data: data,
|
424
|
-
chain: this.chain,
|
425
|
-
webhook: this.webhook, // TODO: implement webhook code on AWS
|
426
|
-
};
|
427
|
-
try {
|
428
|
-
const response = yield axios.post(this.endpoint, apiData);
|
429
|
-
return { success: true, data: response.data };
|
430
|
-
}
|
431
|
-
catch (error) {
|
432
|
-
console.error("apiHub error:", (_a = error.message) !== null && _a !== void 0 ? _a : error);
|
433
|
-
return { success: false, error: error };
|
373
|
+
case "sendTransactions": {
|
374
|
+
return {
|
375
|
+
success: true,
|
376
|
+
data: await LocalCloud.addTransactions(data.transactions),
|
377
|
+
};
|
434
378
|
}
|
379
|
+
case "deploy":
|
380
|
+
return {
|
381
|
+
success: true,
|
382
|
+
data: "local_deploy",
|
383
|
+
};
|
384
|
+
case "queryBilling":
|
385
|
+
return {
|
386
|
+
success: true,
|
387
|
+
data: "local_queryBilling",
|
388
|
+
};
|
389
|
+
default:
|
390
|
+
return {
|
391
|
+
success: false,
|
392
|
+
error: "local_error",
|
393
|
+
};
|
435
394
|
}
|
436
|
-
}
|
395
|
+
}
|
396
|
+
else {
|
397
|
+
const apiData = {
|
398
|
+
auth: ZKCLOUDWORKER_AUTH,
|
399
|
+
command: command,
|
400
|
+
jwtToken: this.jwt,
|
401
|
+
data: data,
|
402
|
+
chain: this.chain,
|
403
|
+
webhook: this.webhook, // TODO: implement webhook code on AWS
|
404
|
+
};
|
405
|
+
try {
|
406
|
+
const response = await axios.post(this.endpoint, apiData);
|
407
|
+
return { success: true, data: response.data };
|
408
|
+
}
|
409
|
+
catch (error) {
|
410
|
+
console.error("apiHub error:", error.message ?? error);
|
411
|
+
return { success: false, error: error };
|
412
|
+
}
|
413
|
+
}
|
437
414
|
}
|
438
415
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
439
416
|
isError(data) {
|
440
417
|
if (data === "error")
|
441
418
|
return true;
|
442
|
-
if (
|
419
|
+
if (data?.jobStatus === "failed")
|
443
420
|
return true;
|
444
421
|
if (typeof data === "string" && data.toLowerCase().startsWith("error"))
|
445
422
|
return true;
|