@io-orkes/conductor-javascript 2.0.0-rc1 → 2.0.0-rc2

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/dist/index.mjs CHANGED
@@ -5,16 +5,9 @@ var LOG_LEVELS = {
5
5
  ERROR: 60
6
6
  };
7
7
  var DefaultLogger = class {
8
+ tags;
9
+ level;
8
10
  constructor(config = {}) {
9
- this.info = (...args) => {
10
- this.log("INFO", ...args);
11
- };
12
- this.debug = (...args) => {
13
- this.log("DEBUG", ...args);
14
- };
15
- this.error = (...args) => {
16
- this.log("ERROR", ...args);
17
- };
18
11
  const { level, tags = [] } = config;
19
12
  this.tags = tags;
20
13
  if (level && level in LOG_LEVELS) {
@@ -36,6 +29,15 @@ var DefaultLogger = class {
36
29
  console.log(name, ...this.tags, ...args);
37
30
  }
38
31
  }
32
+ info = (...args) => {
33
+ this.log("INFO", ...args);
34
+ };
35
+ debug = (...args) => {
36
+ this.log("DEBUG", ...args);
37
+ };
38
+ error = (...args) => {
39
+ this.log("ERROR", ...args);
40
+ };
39
41
  };
40
42
  var noopLogger = {
41
43
  //eslint-disable-next-line
@@ -1486,6 +1488,11 @@ var WorkflowResourceService = class {
1486
1488
 
1487
1489
  // src/common/open-api/core/ApiError.ts
1488
1490
  var ApiError = class extends Error {
1491
+ url;
1492
+ status;
1493
+ statusText;
1494
+ body;
1495
+ request;
1489
1496
  constructor(request3, response, message) {
1490
1497
  super(message);
1491
1498
  this.name = "ApiError";
@@ -1508,9 +1515,14 @@ var CancelError = class extends Error {
1508
1515
  }
1509
1516
  };
1510
1517
  var CancelablePromise = class {
1511
- static {
1512
- Symbol.toStringTag;
1513
- }
1518
+ [Symbol.toStringTag];
1519
+ _isResolved;
1520
+ _isRejected;
1521
+ _isCancelled;
1522
+ _cancelHandlers;
1523
+ _promise;
1524
+ _resolve;
1525
+ _reject;
1514
1526
  constructor(executor) {
1515
1527
  this._isResolved = false;
1516
1528
  this._isRejected = false;
@@ -2147,6 +2159,18 @@ var HumanTaskResourceService = class {
2147
2159
  // src/common/open-api/ConductorClient.ts
2148
2160
  var defaultRequestHandler = (request3, config, options) => request3(config, options);
2149
2161
  var ConductorClient = class {
2162
+ eventResource;
2163
+ healthCheckResource;
2164
+ metadataResource;
2165
+ schedulerResource;
2166
+ taskResource;
2167
+ tokenResource;
2168
+ workflowBulkResource;
2169
+ workflowResource;
2170
+ humanTask;
2171
+ humanTaskResource;
2172
+ request;
2173
+ token;
2150
2174
  constructor(config, requestHandler = defaultRequestHandler) {
2151
2175
  const resolvedConfig = {
2152
2176
  BASE: config?.serverUrl ?? "http://localhost:8080",
@@ -2200,75 +2224,21 @@ var DEFAULT_BATCH_POLLING_TIMEOUT = 100;
2200
2224
 
2201
2225
  // src/task/Poller.ts
2202
2226
  var Poller = class {
2227
+ timeoutHandler;
2228
+ pollFunction;
2229
+ performWorkFunction = async () => {
2230
+ };
2231
+ polling = false;
2232
+ _tasksInProcess = 0;
2233
+ _counterAtO = 0;
2234
+ _pollerId = "";
2235
+ options = {
2236
+ pollInterval: DEFAULT_POLL_INTERVAL,
2237
+ concurrency: DEFAULT_CONCURRENCY,
2238
+ warnAtO: DEFAULT_WARN_AT_O
2239
+ };
2240
+ logger = noopLogger;
2203
2241
  constructor(pollerId, pollFunction, performWorkFunction, pollerOptions, logger) {
2204
- this.performWorkFunction = async () => {
2205
- };
2206
- this.polling = false;
2207
- this._tasksInProcess = 0;
2208
- this._counterAtO = 0;
2209
- this._pollerId = "";
2210
- this.options = {
2211
- pollInterval: DEFAULT_POLL_INTERVAL,
2212
- concurrency: DEFAULT_CONCURRENCY,
2213
- warnAtO: DEFAULT_WARN_AT_O
2214
- };
2215
- this.logger = noopLogger;
2216
- /**
2217
- * Starts polling for work
2218
- */
2219
- this.startPolling = () => {
2220
- if (this.polling) {
2221
- throw new Error("Runner is already started");
2222
- }
2223
- this._tasksInProcess = 0;
2224
- this.polling = true;
2225
- this.poll();
2226
- };
2227
- /**
2228
- * Stops Polling for work
2229
- */
2230
- this.stopPolling = async () => {
2231
- this.polling = false;
2232
- clearTimeout(this.timeoutHandler);
2233
- };
2234
- this.performWork = async (work) => {
2235
- await this.performWorkFunction(work);
2236
- this._tasksInProcess--;
2237
- };
2238
- this.poll = async () => {
2239
- while (this.isPolling) {
2240
- try {
2241
- const count = Math.max(
2242
- 0,
2243
- this.options.concurrency - this._tasksInProcess
2244
- );
2245
- if (count === 0) {
2246
- this.logger.debug(
2247
- "Max in process reached, Will skip polling for " + this._pollerId
2248
- );
2249
- this._counterAtO++;
2250
- if (this._counterAtO > (this.options.warnAtO ?? 100)) {
2251
- this.logger.info(
2252
- `Not polling anything because in process tasks is maxed as concurrency level. ${this._pollerId}`
2253
- );
2254
- }
2255
- } else {
2256
- this._counterAtO = 0;
2257
- const tasksResult = await this.pollFunction(count);
2258
- this._tasksInProcess = this._tasksInProcess + (tasksResult ?? []).length;
2259
- tasksResult.forEach(this.performWork);
2260
- }
2261
- } catch (e) {
2262
- this.logger.error(`Error polling for tasks: ${e.message}`, e);
2263
- }
2264
- await new Promise(
2265
- (r) => this.isPolling ? this.timeoutHandler = setTimeout(
2266
- () => r(true),
2267
- this.options.pollInterval
2268
- ) : r(true)
2269
- );
2270
- }
2271
- };
2272
2242
  this._pollerId = pollerId;
2273
2243
  this.pollFunction = pollFunction;
2274
2244
  this.performWorkFunction = performWorkFunction;
@@ -2281,10 +2251,66 @@ var Poller = class {
2281
2251
  get tasksInProcess() {
2282
2252
  return this._tasksInProcess;
2283
2253
  }
2254
+ /**
2255
+ * Starts polling for work
2256
+ */
2257
+ startPolling = () => {
2258
+ if (this.polling) {
2259
+ throw new Error("Runner is already started");
2260
+ }
2261
+ this._tasksInProcess = 0;
2262
+ this.polling = true;
2263
+ this.poll();
2264
+ };
2265
+ /**
2266
+ * Stops Polling for work
2267
+ */
2268
+ stopPolling = async () => {
2269
+ this.polling = false;
2270
+ clearTimeout(this.timeoutHandler);
2271
+ };
2272
+ performWork = async (work) => {
2273
+ await this.performWorkFunction(work);
2274
+ this._tasksInProcess--;
2275
+ };
2284
2276
  updateOptions(options) {
2285
2277
  const newOptions = { ...this.options, ...options };
2286
2278
  this.options = newOptions;
2287
2279
  }
2280
+ poll = async () => {
2281
+ while (this.isPolling) {
2282
+ try {
2283
+ const count = Math.max(
2284
+ 0,
2285
+ this.options.concurrency - this._tasksInProcess
2286
+ );
2287
+ if (count === 0) {
2288
+ this.logger.debug(
2289
+ "Max in process reached, Will skip polling for " + this._pollerId
2290
+ );
2291
+ this._counterAtO++;
2292
+ if (this._counterAtO > (this.options.warnAtO ?? 100)) {
2293
+ this.logger.info(
2294
+ `Not polling anything because in process tasks is maxed as concurrency level. ${this._pollerId}`
2295
+ );
2296
+ }
2297
+ } else {
2298
+ this._counterAtO = 0;
2299
+ const tasksResult = await this.pollFunction(count);
2300
+ this._tasksInProcess = this._tasksInProcess + (tasksResult ?? []).length;
2301
+ tasksResult.forEach(this.performWork);
2302
+ }
2303
+ } catch (e) {
2304
+ this.logger.error(`Error polling for tasks: ${e.message}`, e);
2305
+ }
2306
+ await new Promise(
2307
+ (r) => this.isPolling ? this.timeoutHandler = setTimeout(
2308
+ () => r(true),
2309
+ this.options.pollInterval
2310
+ ) : r(true)
2311
+ );
2312
+ }
2313
+ };
2288
2314
  };
2289
2315
 
2290
2316
  // src/task/helpers.ts
@@ -2309,6 +2335,12 @@ var defaultRunnerOptions = {
2309
2335
  batchPollingTimeout: DEFAULT_BATCH_POLLING_TIMEOUT
2310
2336
  };
2311
2337
  var TaskRunner = class {
2338
+ taskResource;
2339
+ worker;
2340
+ logger;
2341
+ options;
2342
+ errorHandler;
2343
+ poller;
2312
2344
  constructor({
2313
2345
  worker,
2314
2346
  taskResource,
@@ -2316,91 +2348,6 @@ var TaskRunner = class {
2316
2348
  logger = noopLogger,
2317
2349
  onError: errorHandler = noopErrorHandler
2318
2350
  }) {
2319
- /**
2320
- * Starts polling for work
2321
- */
2322
- this.startPolling = () => {
2323
- this.poller.startPolling();
2324
- this.logger.info(
2325
- `TaskWorker ${this.worker.taskDefName} initialized with concurrency of ${this.poller.options.concurrency} and poll interval of ${this.poller.options.pollInterval}`
2326
- );
2327
- };
2328
- /**
2329
- * Stops Polling for work
2330
- */
2331
- this.stopPolling = async () => {
2332
- await this.poller.stopPolling();
2333
- };
2334
- this.batchPoll = async (count) => {
2335
- const { workerID } = this.options;
2336
- const tasks = await this.taskResource.batchPoll(
2337
- this.worker.taskDefName,
2338
- workerID,
2339
- this.worker.domain ?? this.options.domain,
2340
- count,
2341
- this.options.batchPollingTimeout ?? 100
2342
- // default batch poll defined in the method
2343
- );
2344
- return tasks;
2345
- };
2346
- this.updateTaskWithRetry = async (task, taskResult) => {
2347
- const { workerID } = this.options;
2348
- let retryCount = 0;
2349
- while (retryCount < MAX_RETRIES) {
2350
- try {
2351
- await this.taskResource.updateTask1({
2352
- ...taskResult,
2353
- workerId: workerID
2354
- });
2355
- return;
2356
- } catch (error) {
2357
- this.errorHandler(error, task);
2358
- this.logger.error(
2359
- `Error updating task ${taskResult.taskId} on retry ${retryCount}`,
2360
- error
2361
- );
2362
- retryCount++;
2363
- await new Promise((r) => setTimeout(() => r(true), retryCount * 10));
2364
- }
2365
- }
2366
- this.logger.error(
2367
- `Unable to update task ${taskResult.taskId} after ${retryCount} retries`
2368
- );
2369
- };
2370
- this.executeTask = async (task) => {
2371
- try {
2372
- const result = await this.worker.execute(task);
2373
- await this.updateTaskWithRetry(task, {
2374
- ...result,
2375
- workflowInstanceId: task.workflowInstanceId,
2376
- taskId: task.taskId
2377
- });
2378
- this.logger.debug(`Task has executed successfully ${task.taskId}`);
2379
- } catch (error) {
2380
- await this.updateTaskWithRetry(task, {
2381
- workflowInstanceId: task.workflowInstanceId,
2382
- taskId: task.taskId,
2383
- reasonForIncompletion: error?.message ?? DEFAULT_ERROR_MESSAGE,
2384
- status: "FAILED",
2385
- outputData: {}
2386
- });
2387
- this.errorHandler(error, task);
2388
- this.logger.error(`Error executing ${task.taskId}`, error);
2389
- }
2390
- };
2391
- this.handleUnknownError = (unknownError) => {
2392
- let message = "";
2393
- let stack = "";
2394
- if (unknownError.stack) {
2395
- stack = unknownError.stack;
2396
- }
2397
- if (unknownError.message) {
2398
- message = unknownError.message;
2399
- }
2400
- this.logger.error(
2401
- `Error for ${this.worker.taskDefName}: error: ${message}, stack: ${stack}`
2402
- );
2403
- };
2404
2351
  this.taskResource = taskResource;
2405
2352
  this.logger = logger;
2406
2353
  this.worker = worker;
@@ -2420,6 +2367,21 @@ var TaskRunner = class {
2420
2367
  get isPolling() {
2421
2368
  return this.poller.isPolling;
2422
2369
  }
2370
+ /**
2371
+ * Starts polling for work
2372
+ */
2373
+ startPolling = () => {
2374
+ this.poller.startPolling();
2375
+ this.logger.info(
2376
+ `TaskWorker ${this.worker.taskDefName} initialized with concurrency of ${this.poller.options.concurrency} and poll interval of ${this.poller.options.pollInterval}`
2377
+ );
2378
+ };
2379
+ /**
2380
+ * Stops Polling for work
2381
+ */
2382
+ stopPolling = async () => {
2383
+ await this.poller.stopPolling();
2384
+ };
2423
2385
  updateOptions(options) {
2424
2386
  const newOptions = { ...this.options, ...options };
2425
2387
  const isOptionsUpdated = !optionEquals(this.options, newOptions);
@@ -2437,6 +2399,76 @@ var TaskRunner = class {
2437
2399
  get getOptions() {
2438
2400
  return this.options;
2439
2401
  }
2402
+ batchPoll = async (count) => {
2403
+ const { workerID } = this.options;
2404
+ const tasks = await this.taskResource.batchPoll(
2405
+ this.worker.taskDefName,
2406
+ workerID,
2407
+ this.worker.domain ?? this.options.domain,
2408
+ count,
2409
+ this.options.batchPollingTimeout ?? 100
2410
+ // default batch poll defined in the method
2411
+ );
2412
+ return tasks;
2413
+ };
2414
+ updateTaskWithRetry = async (task, taskResult) => {
2415
+ const { workerID } = this.options;
2416
+ let retryCount = 0;
2417
+ while (retryCount < MAX_RETRIES) {
2418
+ try {
2419
+ await this.taskResource.updateTask1({
2420
+ ...taskResult,
2421
+ workerId: workerID
2422
+ });
2423
+ return;
2424
+ } catch (error) {
2425
+ this.errorHandler(error, task);
2426
+ this.logger.error(
2427
+ `Error updating task ${taskResult.taskId} on retry ${retryCount}`,
2428
+ error
2429
+ );
2430
+ retryCount++;
2431
+ await new Promise((r) => setTimeout(() => r(true), retryCount * 10));
2432
+ }
2433
+ }
2434
+ this.logger.error(
2435
+ `Unable to update task ${taskResult.taskId} after ${retryCount} retries`
2436
+ );
2437
+ };
2438
+ executeTask = async (task) => {
2439
+ try {
2440
+ const result = await this.worker.execute(task);
2441
+ await this.updateTaskWithRetry(task, {
2442
+ ...result,
2443
+ workflowInstanceId: task.workflowInstanceId,
2444
+ taskId: task.taskId
2445
+ });
2446
+ this.logger.debug(`Task has executed successfully ${task.taskId}`);
2447
+ } catch (error) {
2448
+ await this.updateTaskWithRetry(task, {
2449
+ workflowInstanceId: task.workflowInstanceId,
2450
+ taskId: task.taskId,
2451
+ reasonForIncompletion: error?.message ?? DEFAULT_ERROR_MESSAGE,
2452
+ status: "FAILED",
2453
+ outputData: {}
2454
+ });
2455
+ this.errorHandler(error, task);
2456
+ this.logger.error(`Error executing ${task.taskId}`, error);
2457
+ }
2458
+ };
2459
+ handleUnknownError = (unknownError) => {
2460
+ let message = "";
2461
+ let stack = "";
2462
+ if (unknownError.stack) {
2463
+ stack = unknownError.stack;
2464
+ }
2465
+ if (unknownError.message) {
2466
+ message = unknownError.message;
2467
+ }
2468
+ this.logger.error(
2469
+ `Error for ${this.worker.taskDefName}: error: ${message}, stack: ${stack}`
2470
+ );
2471
+ };
2440
2472
  };
2441
2473
 
2442
2474
  // src/task/TaskManager.ts
@@ -2452,84 +2484,14 @@ function workerId(options) {
2452
2484
  return options.workerID ?? os.hostname();
2453
2485
  }
2454
2486
  var TaskManager = class {
2487
+ workerRunners = /* @__PURE__ */ new Map();
2488
+ client;
2489
+ logger;
2490
+ errorHandler;
2491
+ workers;
2492
+ options;
2493
+ polling = false;
2455
2494
  constructor(client, workers, config = {}) {
2456
- this.workerRunners = /* @__PURE__ */ new Map();
2457
- this.polling = false;
2458
- this.workerManagerWorkerOptions = (worker) => {
2459
- return {
2460
- ...this.options,
2461
- concurrency: worker.concurrency ?? this.options.concurrency,
2462
- pollInterval: worker.pollInterval ?? this.options.pollInterval,
2463
- domain: worker.domain ?? this.options.domain
2464
- };
2465
- };
2466
- this.updatePollingOptionForWorker = (workerTaskDefName, options) => {
2467
- const maybeRunner = this.workerRunners.get(workerTaskDefName);
2468
- if (maybeRunner != null) {
2469
- maybeRunner.updateOptions(options);
2470
- } else {
2471
- this.logger.info(
2472
- `No runner found for worker with taskDefName: ${workerTaskDefName}`
2473
- );
2474
- }
2475
- };
2476
- /**
2477
- * new options will get merged to existing options
2478
- * @param options new options to update polling options
2479
- */
2480
- this.updatePollingOptions = (options) => {
2481
- this.workers.forEach((worker) => {
2482
- const newOptions = {
2483
- ...this.workerManagerWorkerOptions(worker),
2484
- ...options
2485
- };
2486
- this.updatePollingOptionForWorker(worker.taskDefName, newOptions);
2487
- });
2488
- this.options.concurrency = options.concurrency ?? this.options.concurrency;
2489
- this.options.pollInterval = options.pollInterval ?? this.options.pollInterval;
2490
- };
2491
- this.sanityCheck = () => {
2492
- if (this.workers.length === 0) {
2493
- throw new Error("No workers supplied to TaskManager");
2494
- }
2495
- const workerIDs = /* @__PURE__ */ new Set();
2496
- for (const item of this.workers) {
2497
- if (workerIDs.has(item.taskDefName)) {
2498
- throw new Error(`Duplicate worker taskDefName: ${item.taskDefName}`);
2499
- }
2500
- workerIDs.add(item.taskDefName);
2501
- }
2502
- };
2503
- /**
2504
- * Start polling for tasks
2505
- */
2506
- this.startPolling = () => {
2507
- this.sanityCheck();
2508
- this.workers.forEach((worker) => {
2509
- const options = this.workerManagerWorkerOptions(worker);
2510
- const runner = new TaskRunner({
2511
- worker,
2512
- options,
2513
- taskResource: this.client.taskResource,
2514
- logger: this.logger,
2515
- onError: this.errorHandler
2516
- });
2517
- runner.startPolling();
2518
- this.workerRunners.set(worker.taskDefName, runner);
2519
- });
2520
- this.polling = true;
2521
- };
2522
- /**
2523
- * Stops polling for tasks
2524
- */
2525
- this.stopPolling = async () => {
2526
- for (const [workerTaskDefName, runner] of this.workerRunners) {
2527
- this.logger.debug(`Stopping taskDefName=${workerTaskDefName}`);
2528
- await runner.stopPolling();
2529
- this.workerRunners.delete(workerTaskDefName);
2530
- }
2531
- this.polling = false;
2532
- };
2533
2495
  if (!workers) {
2534
2496
  throw new Error(
2535
2497
  "No workers supplied to TaskManager. Please pass an array of workers."
@@ -2546,13 +2508,90 @@ var TaskManager = class {
2546
2508
  workerID: workerId(providedOptions)
2547
2509
  };
2548
2510
  }
2511
+ workerManagerWorkerOptions = (worker) => {
2512
+ return {
2513
+ ...this.options,
2514
+ concurrency: worker.concurrency ?? this.options.concurrency,
2515
+ pollInterval: worker.pollInterval ?? this.options.pollInterval,
2516
+ domain: worker.domain ?? this.options.domain
2517
+ };
2518
+ };
2549
2519
  get isPolling() {
2550
2520
  return this.polling;
2551
2521
  }
2522
+ updatePollingOptionForWorker = (workerTaskDefName, options) => {
2523
+ const maybeRunner = this.workerRunners.get(workerTaskDefName);
2524
+ if (maybeRunner != null) {
2525
+ maybeRunner.updateOptions(options);
2526
+ } else {
2527
+ this.logger.info(
2528
+ `No runner found for worker with taskDefName: ${workerTaskDefName}`
2529
+ );
2530
+ }
2531
+ };
2532
+ /**
2533
+ * new options will get merged to existing options
2534
+ * @param options new options to update polling options
2535
+ */
2536
+ updatePollingOptions = (options) => {
2537
+ this.workers.forEach((worker) => {
2538
+ const newOptions = {
2539
+ ...this.workerManagerWorkerOptions(worker),
2540
+ ...options
2541
+ };
2542
+ this.updatePollingOptionForWorker(worker.taskDefName, newOptions);
2543
+ });
2544
+ this.options.concurrency = options.concurrency ?? this.options.concurrency;
2545
+ this.options.pollInterval = options.pollInterval ?? this.options.pollInterval;
2546
+ };
2547
+ sanityCheck = () => {
2548
+ if (this.workers.length === 0) {
2549
+ throw new Error("No workers supplied to TaskManager");
2550
+ }
2551
+ const workerIDs = /* @__PURE__ */ new Set();
2552
+ for (const item of this.workers) {
2553
+ if (workerIDs.has(item.taskDefName)) {
2554
+ throw new Error(`Duplicate worker taskDefName: ${item.taskDefName}`);
2555
+ }
2556
+ workerIDs.add(item.taskDefName);
2557
+ }
2558
+ };
2559
+ /**
2560
+ * Start polling for tasks
2561
+ */
2562
+ startPolling = () => {
2563
+ this.sanityCheck();
2564
+ this.workers.forEach((worker) => {
2565
+ const options = this.workerManagerWorkerOptions(worker);
2566
+ const runner = new TaskRunner({
2567
+ worker,
2568
+ options,
2569
+ taskResource: this.client.taskResource,
2570
+ logger: this.logger,
2571
+ onError: this.errorHandler
2572
+ });
2573
+ runner.startPolling();
2574
+ this.workerRunners.set(worker.taskDefName, runner);
2575
+ });
2576
+ this.polling = true;
2577
+ };
2578
+ /**
2579
+ * Stops polling for tasks
2580
+ */
2581
+ stopPolling = async () => {
2582
+ for (const [workerTaskDefName, runner] of this.workerRunners) {
2583
+ this.logger.debug(`Stopping taskDefName=${workerTaskDefName}`);
2584
+ await runner.stopPolling();
2585
+ this.workerRunners.delete(workerTaskDefName);
2586
+ }
2587
+ this.polling = false;
2588
+ };
2552
2589
  };
2553
2590
 
2554
2591
  // src/core/types.ts
2555
2592
  var ConductorError = class extends Error {
2593
+ _trace;
2594
+ __proto__;
2556
2595
  constructor(message, innerError) {
2557
2596
  super(message);
2558
2597
  this._trace = innerError;
@@ -2587,6 +2626,7 @@ function reverseFind(array, predicate) {
2587
2626
  var RETRY_TIME_IN_MILLISECONDS = 1e4;
2588
2627
  var completedTaskMatchingType = (taskType) => (task) => task.status === "COMPLETED" && task.taskType === taskType;
2589
2628
  var WorkflowExecutor = class {
2629
+ _client;
2590
2630
  constructor(client) {
2591
2631
  this._client = client;
2592
2632
  }
@@ -2892,6 +2932,7 @@ var EMPTY_SEARCH = {
2892
2932
  };
2893
2933
  var DEFAULT_POLL_INTERVAL2 = { pollInterval: 100, maxPollTimes: 20 };
2894
2934
  var HumanExecutor = class {
2935
+ _client;
2895
2936
  constructor(client) {
2896
2937
  this._client = client;
2897
2938
  }
@@ -3536,105 +3577,73 @@ var workflow = (name, tasks) => ({
3536
3577
  timeoutSeconds: 0
3537
3578
  });
3538
3579
 
3539
- // src/orkes/request/fetchCatchDns/DnsResolver.ts
3540
- import { promises } from "dns";
3541
- var DEFAULT_OPTIONS = {
3542
- logger: noopLogger,
3543
- resolver: promises.resolve4
3544
- };
3545
- var dnsResolver = async (host, { resolver = promises.resolve4, logger = console } = DEFAULT_OPTIONS) => {
3546
- try {
3547
- const addresses = await resolver(host);
3548
- if (addresses.length > 0)
3549
- return addresses[0];
3550
- } catch (e) {
3551
- logger.error("Could not resolve host: " + host + " error: " + e);
3552
- }
3553
- return void 0;
3554
- };
3555
-
3556
- // src/orkes/request/fetchCatchDns/DnsCache.ts
3557
- var DnsCacheResolver = class {
3558
- constructor({ initialCache = /* @__PURE__ */ new Map() } = {}) {
3559
- this._cache = /* @__PURE__ */ new Map();
3560
- this._cache = initialCache;
3580
+ // src/orkes/BaseOrkesConductorClient.ts
3581
+ var defaultRequestHandler2 = (request3, config, options) => request3(config, options);
3582
+ var REFRESH_TOKEN_IN_MILLISECONDS = 30 * 60 * 1e3;
3583
+ var AuthConductorClient = class extends ConductorClient {
3584
+ intervalId;
3585
+ constructor(config, requestHandler = defaultRequestHandler2) {
3586
+ super(config, requestHandler);
3561
3587
  }
3562
- async resolve(host) {
3563
- const cachedIp = this._cache.get(host);
3564
- if (cachedIp) {
3565
- return cachedIp;
3566
- }
3567
- const ip = await dnsResolver(host);
3568
- if (ip != void 0) {
3569
- this._cache.set(host, ip);
3588
+ /**
3589
+ * Stops the interval that refreshes the token
3590
+ */
3591
+ stop() {
3592
+ if (this.intervalId != null) {
3593
+ clearInterval(this.intervalId);
3570
3594
  }
3571
- return ip;
3572
- }
3573
- clearCache() {
3574
- this._cache.clear();
3575
3595
  }
3576
- removeCache(host) {
3577
- this._cache.delete(host);
3578
- }
3579
- get cache() {
3580
- return this._cache;
3581
- }
3582
- };
3583
-
3584
- // src/orkes/request/fetchCatchDns/fetchCatchDns.ts
3585
- import { isIP } from "net";
3586
- var isEmpty = (value) => {
3587
- return value === void 0 || value.trim().length === 0;
3588
- };
3589
- var toMaybeUrl = (originalUrl, modifiedParams) => {
3590
- const urlToHit = new URL(originalUrl.toString());
3591
- urlToHit.host = isEmpty(modifiedParams.port) ? `${modifiedParams.host}:${modifiedParams.port}` : modifiedParams.host;
3592
- return urlToHit;
3593
3596
  };
3594
- var DEFAULT_OPTIONS2 = {
3595
- dnsCache: new DnsCacheResolver(),
3596
- headerFactory: (headers) => new Headers(headers || {})
3597
- };
3598
- var fetchCatchDns = (fetch3, {
3599
- dnsCache = new DnsCacheResolver(),
3600
- headerFactory = (headers) => new Headers(headers || {})
3601
- } = DEFAULT_OPTIONS2) => {
3602
- const fetchWithDns = async (input, options) => {
3603
- const parsedUrl = new URL(input.toString());
3604
- const { hostname, host, port } = parsedUrl;
3605
- if (isIP(hostname)) {
3606
- return await fetch3(input, options);
3607
- }
3608
- const maybeTargetIp = await dnsCache.resolve(hostname);
3609
- if (isEmpty(maybeTargetIp)) {
3610
- return await fetch3(input, options);
3611
- }
3612
- const target = toMaybeUrl(input, {
3613
- ...parsedUrl,
3614
- host: maybeTargetIp,
3615
- port
3616
- });
3617
- const headersOverride = headerFactory(options?.headers ?? {});
3618
- if (!headersOverride.has("Host")) {
3619
- headersOverride.set("Host", host);
3620
- }
3621
- const optionsOverride = {
3622
- ...options,
3623
- headers: headersOverride
3624
- };
3625
- try {
3626
- const res = await fetch3(target.toString(), optionsOverride);
3627
- return res;
3628
- } catch (e) {
3629
- if (e && e?.code === "ETIMEDOUT") {
3630
- dnsCache.removeCache(hostname);
3597
+ var baseOrkesConductorClient = (fetchFn, baseRequestHandler = defaultRequestHandler2) => {
3598
+ const requestTokenForKeySecret = (keyId, keySecret, tokenUrl) => fetchFn(tokenUrl, {
3599
+ headers: {
3600
+ "Content-Type": "application/json",
3601
+ Accept: "application/json"
3602
+ },
3603
+ body: JSON.stringify({ keyId, keySecret }),
3604
+ method: "POST"
3605
+ });
3606
+ return async (config, requestHandler = baseRequestHandler) => {
3607
+ if (config?.keySecret != null && config?.keyId != null) {
3608
+ const {
3609
+ serverUrl,
3610
+ keyId,
3611
+ keySecret,
3612
+ refreshTokenInterval = REFRESH_TOKEN_IN_MILLISECONDS
3613
+ } = config;
3614
+ const tokenUrl = `${serverUrl}/token`;
3615
+ const res = await requestTokenForKeySecret(keyId, keySecret, tokenUrl);
3616
+ const { token } = await res.json();
3617
+ const conductorClientInstance = new AuthConductorClient(
3618
+ { ...config, TOKEN: token },
3619
+ requestHandler
3620
+ );
3621
+ if (token != null && refreshTokenInterval > 0) {
3622
+ const intervalId = setInterval(async () => {
3623
+ const res2 = await requestTokenForKeySecret(
3624
+ keyId,
3625
+ keySecret,
3626
+ tokenUrl
3627
+ );
3628
+ const { token: token2 } = await res2.json();
3629
+ conductorClientInstance.token = token2;
3630
+ }, refreshTokenInterval);
3631
+ conductorClientInstance.intervalId = intervalId;
3631
3632
  }
3632
- throw e;
3633
+ return conductorClientInstance;
3634
+ } else {
3635
+ return new ConductorClient(config, requestHandler);
3633
3636
  }
3634
3637
  };
3635
- return fetchWithDns;
3636
3638
  };
3637
3639
 
3640
+ // src/orkes/OrkesConductorClient.ts
3641
+ var defaultRequestHandler3 = (request3, config, options) => request3(config, options);
3642
+ var orkesConductorClient = baseOrkesConductorClient(
3643
+ fetch,
3644
+ defaultRequestHandler3
3645
+ );
3646
+
3638
3647
  // src/orkes/request/request.ts
3639
3648
  var isDefined2 = (value) => {
3640
3649
  return value !== void 0 && value !== null;
@@ -3870,91 +3879,104 @@ var request2 = (config, options, fetchFn = fetch) => {
3870
3879
  });
3871
3880
  };
3872
3881
 
3873
- // src/orkes/BaseOrkesConductorClient.ts
3874
- var defaultRequestHandler2 = (request3, config, options) => request3(config, options);
3875
- var REFRESH_TOKEN_IN_MILLISECONDS = 30 * 60 * 1e3;
3876
- var AuthConductorClient = class extends ConductorClient {
3877
- constructor(config, requestHandler = defaultRequestHandler2) {
3878
- super(config, requestHandler);
3882
+ // src/orkes/request/fetchCatchDns/DnsResolver.ts
3883
+ import { promises } from "dns";
3884
+ var DEFAULT_OPTIONS = {
3885
+ logger: noopLogger,
3886
+ resolver: promises.resolve4
3887
+ };
3888
+ var dnsResolver = async (host, { resolver = promises.resolve4, logger = console } = DEFAULT_OPTIONS) => {
3889
+ try {
3890
+ const addresses = await resolver(host);
3891
+ if (addresses.length > 0)
3892
+ return addresses[0];
3893
+ } catch (e) {
3894
+ logger.error("Could not resolve host: " + host + " error: " + e);
3879
3895
  }
3880
- /**
3881
- * Stops the interval that refreshes the token
3882
- */
3883
- stop() {
3884
- if (this.intervalId != null) {
3885
- clearInterval(this.intervalId);
3896
+ return void 0;
3897
+ };
3898
+
3899
+ // src/orkes/request/fetchCatchDns/DnsCache.ts
3900
+ var DnsCacheResolver = class {
3901
+ _cache = /* @__PURE__ */ new Map();
3902
+ constructor({ initialCache = /* @__PURE__ */ new Map() } = {}) {
3903
+ this._cache = initialCache;
3904
+ }
3905
+ async resolve(host) {
3906
+ const cachedIp = this._cache.get(host);
3907
+ if (cachedIp) {
3908
+ return cachedIp;
3886
3909
  }
3910
+ const ip = await dnsResolver(host);
3911
+ if (ip != void 0) {
3912
+ this._cache.set(host, ip);
3913
+ }
3914
+ return ip;
3915
+ }
3916
+ clearCache() {
3917
+ this._cache.clear();
3918
+ }
3919
+ removeCache(host) {
3920
+ this._cache.delete(host);
3921
+ }
3922
+ get cache() {
3923
+ return this._cache;
3887
3924
  }
3888
3925
  };
3889
- var baseOrkesConductorClient = (fetchFn, baseRequestHandler = defaultRequestHandler2) => {
3890
- const requestTokenForKeySecret = (keyId, keySecret, tokenUrl) => fetchFn(tokenUrl, {
3891
- headers: {
3892
- "Content-Type": "application/json",
3893
- Accept: "application/json"
3894
- },
3895
- body: JSON.stringify({ keyId, keySecret }),
3896
- method: "POST"
3897
- });
3898
- return async (config, requestHandler = baseRequestHandler) => {
3899
- if (config?.keySecret != null && config?.keyId != null) {
3900
- const {
3901
- serverUrl,
3902
- keyId,
3903
- keySecret,
3904
- refreshTokenInterval = REFRESH_TOKEN_IN_MILLISECONDS
3905
- } = config;
3906
- const tokenUrl = `${serverUrl}/token`;
3907
- const res = await requestTokenForKeySecret(keyId, keySecret, tokenUrl);
3908
- const { token } = await res.json();
3909
- const conductorClientInstance = new AuthConductorClient(
3910
- { ...config, TOKEN: token },
3911
- requestHandler
3912
- );
3913
- if (token != null && refreshTokenInterval > 0) {
3914
- const intervalId = setInterval(async () => {
3915
- const res2 = await requestTokenForKeySecret(
3916
- keyId,
3917
- keySecret,
3918
- tokenUrl
3919
- );
3920
- const { token: token2 } = await res2.json();
3921
- conductorClientInstance.token = token2;
3922
- }, refreshTokenInterval);
3923
- conductorClientInstance.intervalId = intervalId;
3926
+
3927
+ // src/orkes/request/fetchCatchDns/fetchCatchDns.ts
3928
+ import { isIP } from "net";
3929
+ var isEmpty = (value) => {
3930
+ return value === void 0 || value.trim().length === 0;
3931
+ };
3932
+ var toMaybeUrl = (originalUrl, modifiedParams) => {
3933
+ const urlToHit = new URL(originalUrl.toString());
3934
+ urlToHit.host = isEmpty(modifiedParams.port) ? `${modifiedParams.host}:${modifiedParams.port}` : modifiedParams.host;
3935
+ return urlToHit;
3936
+ };
3937
+ var DEFAULT_OPTIONS2 = {
3938
+ dnsCache: new DnsCacheResolver(),
3939
+ headerFactory: (headers) => new Headers(headers || {})
3940
+ };
3941
+ var fetchCatchDns = (fetch2, {
3942
+ dnsCache = new DnsCacheResolver(),
3943
+ headerFactory = (headers) => new Headers(headers || {})
3944
+ } = DEFAULT_OPTIONS2) => {
3945
+ const fetchWithDns = async (input, options) => {
3946
+ const parsedUrl = new URL(input.toString());
3947
+ const { hostname, host, port } = parsedUrl;
3948
+ if (isIP(hostname)) {
3949
+ return await fetch2(input, options);
3950
+ }
3951
+ const maybeTargetIp = await dnsCache.resolve(hostname);
3952
+ if (isEmpty(maybeTargetIp)) {
3953
+ return await fetch2(input, options);
3954
+ }
3955
+ const target = toMaybeUrl(input, {
3956
+ ...parsedUrl,
3957
+ host: maybeTargetIp,
3958
+ port
3959
+ });
3960
+ const headersOverride = headerFactory(options?.headers ?? {});
3961
+ if (!headersOverride.has("Host")) {
3962
+ headersOverride.set("Host", host);
3963
+ }
3964
+ const optionsOverride = {
3965
+ ...options,
3966
+ headers: headersOverride
3967
+ };
3968
+ try {
3969
+ const res = await fetch2(target.toString(), optionsOverride);
3970
+ return res;
3971
+ } catch (e) {
3972
+ if (e && e?.code === "ETIMEDOUT") {
3973
+ dnsCache.removeCache(hostname);
3924
3974
  }
3925
- return conductorClientInstance;
3926
- } else {
3927
- return new ConductorClient(config, requestHandler);
3975
+ throw e;
3928
3976
  }
3929
3977
  };
3978
+ return fetchWithDns;
3930
3979
  };
3931
-
3932
- // src/orkes/OrkesConductorClient.ts
3933
- import fetch2, { Headers as Headers2 } from "node-fetch";
3934
- import http from "http";
3935
- import https from "https";
3936
- var httpAgent = new http.Agent({ keepAlive: true });
3937
- var httpsAgent = new https.Agent({ keepAlive: true });
3938
- var agent = (_parsedURL) => _parsedURL.protocol == "http:" ? httpAgent : httpsAgent;
3939
- var nodeFetchWrapper = async (input, options = {}) => {
3940
- const res = await fetch2(input.toString(), {
3941
- ...options,
3942
- agent
3943
- });
3944
- return res;
3945
- };
3946
- var fetchCache = fetchCatchDns(
3947
- nodeFetchWrapper,
3948
- {
3949
- //@ts-ignore
3950
- headerFactory: (headers) => new Headers2(headers || {})
3951
- }
3952
- );
3953
- var defaultRequestHandler3 = (__request, config, options) => request2(config, options, fetchCache);
3954
- var orkesConductorClient = baseOrkesConductorClient(
3955
- fetchCache,
3956
- defaultRequestHandler3
3957
- );
3958
3980
  export {
3959
3981
  ApiError,
3960
3982
  AuthConductorClient,