zkcloudworker 0.5.1 → 0.5.3
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/lib/ts/src/api/api.js +14 -6
- 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 +260 -275
- 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,186 +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
|
-
|
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) {
|
268
256
|
// replace all occurrences of "error" with red color
|
269
257
|
const text = log.replace(/error/gi, (matched) => chalk.red(matched));
|
270
258
|
console.log(text);
|
271
259
|
}
|
272
|
-
}
|
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);
|
273
285
|
}
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
if (
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
errors++;
|
288
|
-
if (errors > maxErrors) {
|
289
|
-
return {
|
290
|
-
success: false,
|
291
|
-
error: "Too many network errors",
|
292
|
-
result: undefined,
|
293
|
-
};
|
294
|
-
}
|
295
|
-
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
|
+
};
|
296
299
|
}
|
297
|
-
else {
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
};
|
304
|
-
else if (((_g = result.data) === null || _g === void 0 ? void 0 : _g.result) !== undefined) {
|
305
|
-
return {
|
306
|
-
success: result.success,
|
307
|
-
error: result.error,
|
308
|
-
result: result.data,
|
309
|
-
};
|
310
|
-
}
|
311
|
-
else if (((_h = result.data) === null || _h === void 0 ? void 0 : _h.jobStatus) === "failed") {
|
312
|
-
return {
|
313
|
-
success: false,
|
314
|
-
error: "Job failed",
|
315
|
-
result: result.data,
|
316
|
-
};
|
317
|
-
}
|
318
|
-
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
|
+
};
|
319
306
|
}
|
320
|
-
|
307
|
+
await sleep(interval);
|
321
308
|
}
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
309
|
+
attempts++;
|
310
|
+
}
|
311
|
+
return {
|
312
|
+
success: false,
|
313
|
+
error: "Timeout",
|
314
|
+
result: undefined,
|
315
|
+
};
|
328
316
|
}
|
329
317
|
/**
|
330
318
|
* Calls the serverless API
|
331
319
|
* @param command the command of the API
|
332
320
|
* @param data the data of the API
|
333
321
|
* */
|
334
|
-
apiHub(command,
|
322
|
+
async apiHub(command,
|
335
323
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
336
324
|
data
|
337
325
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
338
326
|
) {
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
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
|
352
353
|
return {
|
353
354
|
success: true,
|
354
355
|
data: jobId,
|
355
356
|
};
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
data,
|
361
|
-
chain: this.chain,
|
362
|
-
localWorker: this.localWorker,
|
363
|
-
});
|
364
|
-
if (data.mode === "sync")
|
365
|
-
return { success: true, data: LocalStorage.jobs[jobId].result };
|
366
|
-
else
|
367
|
-
return {
|
368
|
-
success: true,
|
369
|
-
data: jobId,
|
370
|
-
};
|
371
|
-
}
|
372
|
-
case "jobResult": {
|
373
|
-
const job = LocalStorage.jobs[data.jobId];
|
374
|
-
if (job === undefined) {
|
375
|
-
return {
|
376
|
-
success: false,
|
377
|
-
error: "local job not found",
|
378
|
-
};
|
379
|
-
}
|
380
|
-
else {
|
381
|
-
return {
|
382
|
-
success: true,
|
383
|
-
data: job,
|
384
|
-
};
|
385
|
-
}
|
386
|
-
}
|
387
|
-
case "sendTransactions": {
|
357
|
+
}
|
358
|
+
case "jobResult": {
|
359
|
+
const job = LocalStorage.jobs[data.jobId];
|
360
|
+
if (job === undefined) {
|
388
361
|
return {
|
389
|
-
success:
|
390
|
-
|
362
|
+
success: false,
|
363
|
+
error: "local job not found",
|
391
364
|
};
|
392
365
|
}
|
393
|
-
|
394
|
-
return {
|
395
|
-
success: true,
|
396
|
-
data: "local_deploy",
|
397
|
-
};
|
398
|
-
case "queryBilling":
|
366
|
+
else {
|
399
367
|
return {
|
400
368
|
success: true,
|
401
|
-
data:
|
402
|
-
};
|
403
|
-
default:
|
404
|
-
return {
|
405
|
-
success: false,
|
406
|
-
error: "local_error",
|
369
|
+
data: job,
|
407
370
|
};
|
371
|
+
}
|
408
372
|
}
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
jwtToken: this.jwt,
|
415
|
-
data: data,
|
416
|
-
chain: this.chain,
|
417
|
-
webhook: this.webhook, // TODO: implement webhook code on AWS
|
418
|
-
};
|
419
|
-
try {
|
420
|
-
const response = yield axios.post(this.endpoint, apiData);
|
421
|
-
return { success: true, data: response.data };
|
422
|
-
}
|
423
|
-
catch (error) {
|
424
|
-
console.error("apiHub error:", (_a = error.message) !== null && _a !== void 0 ? _a : error);
|
425
|
-
return { success: false, error: error };
|
373
|
+
case "sendTransactions": {
|
374
|
+
return {
|
375
|
+
success: true,
|
376
|
+
data: await LocalCloud.addTransactions(data.transactions),
|
377
|
+
};
|
426
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
|
+
};
|
427
394
|
}
|
428
|
-
}
|
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
|
+
}
|
429
414
|
}
|
430
415
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
431
416
|
isError(data) {
|
432
417
|
if (data === "error")
|
433
418
|
return true;
|
434
|
-
if (
|
419
|
+
if (data?.jobStatus === "failed")
|
435
420
|
return true;
|
436
421
|
if (typeof data === "string" && data.toLowerCase().startsWith("error"))
|
437
422
|
return true;
|