@heyanon/sdk 2.3.10 → 2.4.1

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.
@@ -0,0 +1,439 @@
1
+ /**
2
+ * Custom error class for breaking workflow execution
3
+ */
4
+ export declare class WorkflowBreakError extends Error {
5
+ /**
6
+ * The reason for breaking the workflow
7
+ */
8
+ readonly breakReason: unknown;
9
+ /**
10
+ * Create a new WorkflowBreakError
11
+ * @param breakReason Optional reason for breaking the workflow
12
+ */
13
+ constructor(breakReason?: unknown);
14
+ }
15
+ /**
16
+ * Options for configuring a workflow action
17
+ * @template T The type of the action's result
18
+ */
19
+ export interface ActionOptions<T> {
20
+ /**
21
+ * Name of the action
22
+ */
23
+ name: string;
24
+ /**
25
+ * Number of retry attempts
26
+ * @default 1
27
+ */
28
+ attempts?: number;
29
+ /**
30
+ * Delay between retries in milliseconds
31
+ * @default 0
32
+ */
33
+ delayMs?: number;
34
+ /**
35
+ * Function to execute
36
+ * @param context The workflow context
37
+ * @returns Promise with the action's result
38
+ */
39
+ action: (context: WorkflowContext) => Promise<T>;
40
+ /**
41
+ * Optional function to execute before each retry
42
+ * @param attempt Current attempt number (1-based)
43
+ * @param error The error that triggered the retry
44
+ * @param context The workflow context
45
+ */
46
+ onRetry?: (attempt: number, error: Error, context: WorkflowContext) => Promise<void>;
47
+ /**
48
+ * Optional function to execute when action succeeds
49
+ * @param result The action's result
50
+ * @param context The workflow context
51
+ */
52
+ onSuccess?: (attempt: number, result: T, context: WorkflowContext) => Promise<void>;
53
+ /**
54
+ * Optional function to execute when action fails
55
+ * @param error The error that caused the failure
56
+ * @param context The workflow context
57
+ */
58
+ onFailed?: (attempt: number, error: Error, context: WorkflowContext) => Promise<void>;
59
+ }
60
+ /**
61
+ * Options for configuring a workflow
62
+ */
63
+ export interface WorkflowOptions {
64
+ /**
65
+ * Number of retry attempts
66
+ * @default 1
67
+ */
68
+ attempts?: number;
69
+ /**
70
+ * Delay between retries in milliseconds
71
+ * @default 0
72
+ */
73
+ delayMs?: number;
74
+ /**
75
+ * Optional callback to execute when workflow is broken
76
+ * @param reason The reason for breaking the workflow
77
+ * @param context The workflow context
78
+ */
79
+ onBreak?: (reason: any, context: WorkflowContext) => Promise<void>;
80
+ /**
81
+ * Optional callback to execute when workflow is retried
82
+ * @param error The error that caused the retry
83
+ * @param context The workflow context
84
+ */
85
+ onRetry?: (error: Error, context: WorkflowContext) => Promise<void>;
86
+ /**
87
+ * Optional callback to execute when workflow completes successfully
88
+ * @param context The workflow context
89
+ */
90
+ onSuccess?: (context: WorkflowContext) => Promise<void>;
91
+ /**
92
+ * Optional callback to execute when workflow fails
93
+ * @param error The error that caused the failure
94
+ * @param context The workflow context
95
+ */
96
+ onFailed?: (error: Error, context: WorkflowContext) => Promise<void>;
97
+ }
98
+ /**
99
+ * Class representing a workflow action that can be executed with retry logic
100
+ * @template T The type of the action's result
101
+ */
102
+ export declare class WorkflowAction<T> {
103
+ /**
104
+ * Name of the action
105
+ */
106
+ private readonly name;
107
+ /**
108
+ * Current attempt number
109
+ */
110
+ private currentAttempt;
111
+ /**
112
+ * Number of retry attempts
113
+ */
114
+ private attempts;
115
+ /**
116
+ * Delay between retries in milliseconds
117
+ */
118
+ private delayMs;
119
+ /**
120
+ * Function to execute
121
+ */
122
+ private readonly action;
123
+ /**
124
+ * Optional function to execute before each retry
125
+ */
126
+ private readonly onRetry?;
127
+ /**
128
+ * Optional function to execute when action succeeds
129
+ */
130
+ private readonly onSuccess?;
131
+ /**
132
+ * Optional function to execute when action fails
133
+ */
134
+ private readonly onFailed?;
135
+ /**
136
+ * Create a new WorkflowAction
137
+ * @param options Action configuration
138
+ */
139
+ constructor(options: ActionOptions<T>);
140
+ /**
141
+ * Get the name of the action
142
+ * @returns The name of the action
143
+ */
144
+ getName(): string;
145
+ /**
146
+ * Private retry method for action execution
147
+ * @param fn The function to retry
148
+ * @param context The workflow context
149
+ * @returns Promise with the result of the function
150
+ * @throws {Error} If all retry attempts fail
151
+ */
152
+ private retry;
153
+ /**
154
+ * Execute the action with retry logic
155
+ * @param context The workflow context containing results from previous actions
156
+ * @returns Promise with the result of the action
157
+ * @throws {Error} If all retry attempts fail
158
+ * @throws {WorkflowBreakError} If the workflow is broken
159
+ */
160
+ execute(context: WorkflowContext): Promise<T>;
161
+ }
162
+ /**
163
+ * Context object passed to each action, containing results from previous actions
164
+ */
165
+ export declare class WorkflowContext {
166
+ /**
167
+ * Results from previous actions, stored by name
168
+ */
169
+ private resultsByName;
170
+ /**
171
+ * Results from previous actions, stored by index
172
+ */
173
+ private resultsByIndex;
174
+ /**
175
+ * Reference to the workflow instance
176
+ */
177
+ private workflow;
178
+ /**
179
+ * Current attempt number
180
+ */
181
+ private currentAttempt;
182
+ /**
183
+ * Current action name
184
+ */
185
+ private currentActionName;
186
+ /**
187
+ * Create a new WorkflowContext
188
+ * @param workflow The workflow instance
189
+ */
190
+ constructor(workflow: WorkflowRetry);
191
+ /**
192
+ * Get the current attempt number
193
+ * @returns The current attempt number (1-based)
194
+ */
195
+ getAttempt(): number;
196
+ /**
197
+ * Set the current attempt number
198
+ * @param attempt The attempt number to set
199
+ */
200
+ setAttempt(attempt: number): void;
201
+ /**
202
+ * Get the current action name
203
+ * @returns The name of the currently executed action
204
+ */
205
+ getActionName(): string;
206
+ /**
207
+ * Set the current action name
208
+ * @param name The name of the action to set
209
+ */
210
+ setActionName(name: string): void;
211
+ /**
212
+ * Get the result of a specific action by name
213
+ * @param name The name of the action result to retrieve
214
+ * @returns The result of the action with the specified name
215
+ * @throws {Error} If no result is available with the specified name
216
+ */
217
+ getResultByName<T>(name: string): T;
218
+ /**
219
+ * Get all results from previous actions
220
+ * @returns Array of all results
221
+ */
222
+ getAllResults(): any[];
223
+ /**
224
+ * Add a result to the context
225
+ * @param name The name of the action
226
+ * @param result The result to add
227
+ */
228
+ addResult(name: string, result: any): void;
229
+ /**
230
+ * Get the results by name
231
+ * @returns Map of results by name
232
+ */
233
+ getResultsByName(): Map<string, any>;
234
+ /**
235
+ * Get the workflow instance
236
+ * @returns The workflow instance
237
+ */
238
+ getWorkflow(): WorkflowRetry;
239
+ }
240
+ /**
241
+ * Class representing the result of a workflow execution
242
+ */
243
+ export declare class WorkflowResult {
244
+ /**
245
+ * Results from actions, stored by name
246
+ */
247
+ private readonly resultsByName;
248
+ /**
249
+ * Results from actions, stored by index
250
+ */
251
+ private readonly resultsByIndex;
252
+ /**
253
+ * Failures from actions, stored by action name and attempt number
254
+ */
255
+ private readonly failuresByAction;
256
+ /**
257
+ * Create a new WorkflowResult
258
+ * @param results Array of results from actions
259
+ * @param actionNames Array of action names corresponding to the results
260
+ */
261
+ constructor(results?: any[], actionNames?: string[]);
262
+ /**
263
+ * Add a result to the workflow result
264
+ * @param name The name of the action
265
+ * @param result The result to add
266
+ */
267
+ addResult(name: string, result: any): void;
268
+ /**
269
+ * Add a failure to the workflow result
270
+ * @param name The name of the action that failed
271
+ * @param attempt The attempt number
272
+ * @param reason The reason for the failure
273
+ */
274
+ addFailure(name: string, attempt: number, reason: any): void;
275
+ /**
276
+ * Get all failures for a specific action
277
+ * @param name The name of the action
278
+ * @returns Map of attempt numbers to failure reasons
279
+ */
280
+ getFailuresByAction(name: string): Map<number, any>;
281
+ /**
282
+ * Get all failures across all actions
283
+ * @returns Map of action names to maps of attempt numbers to failure reasons
284
+ */
285
+ getAllFailures(): Map<string, Map<number, any>>;
286
+ /**
287
+ * Check if an action failed in a specific attempt
288
+ * @param name The name of the action
289
+ * @param attempt The attempt number
290
+ * @returns True if the action failed in the specified attempt
291
+ */
292
+ hasFailure(name: string, attempt: number): boolean;
293
+ /**
294
+ * Get the failure reason for an action in a specific attempt
295
+ * @param name The name of the action
296
+ * @param attempt The attempt number
297
+ * @returns The failure reason or undefined if no failure occurred
298
+ */
299
+ getFailure(name: string, attempt: number): any;
300
+ /**
301
+ * Get all attempts when an action failed
302
+ * @param name The name of the action
303
+ * @returns Array of attempt numbers
304
+ */
305
+ getFailureAttempts(name: string): number[];
306
+ /**
307
+ * Get all actions that failed
308
+ * @returns Array of action names
309
+ */
310
+ getFailedActions(): string[];
311
+ /**
312
+ * Get all actions that failed with a specific reason
313
+ * @param reason The failure reason to search for
314
+ * @returns Array of action names
315
+ */
316
+ getActionsFailedWithReason(reason: any): string[];
317
+ /**
318
+ * Compare two reasons for equality
319
+ * @param reason1 First reason
320
+ * @param reason2 Second reason
321
+ * @returns True if the reasons are equal
322
+ * @private
323
+ */
324
+ private areReasonsEqual;
325
+ /**
326
+ * Get the result of a specific action by name
327
+ * @param name The name of the action
328
+ * @returns The result of the action with the specified name
329
+ * @throws {Error} If no result is available with the specified name
330
+ */
331
+ getResult<T>(name: string): T;
332
+ /**
333
+ * Get the result of the last action in the workflow
334
+ * @returns The result of the last action
335
+ * @throws {Error} If no results are available
336
+ */
337
+ getLastActionResult<T>(): T;
338
+ /**
339
+ * Get all results from the workflow
340
+ * @returns Array of all results
341
+ */
342
+ getAllResults(): any[];
343
+ /**
344
+ * Get the number of results
345
+ * @returns The number of results
346
+ */
347
+ getResultCount(): number;
348
+ }
349
+ /**
350
+ * Class for handling workflow retries with configurable attempts and delay
351
+ */
352
+ export declare class WorkflowRetry {
353
+ /**
354
+ * List of actions to execute in the workflow
355
+ */
356
+ private readonly actions;
357
+ /**
358
+ * Number of retry attempts
359
+ */
360
+ private readonly attempts;
361
+ /**
362
+ * Delay between retries in milliseconds
363
+ */
364
+ private readonly delayMs;
365
+ /**
366
+ * Flag indicating if the workflow was broken
367
+ */
368
+ private isBroken;
369
+ /**
370
+ * Reason for breaking the workflow
371
+ */
372
+ private breakReason;
373
+ /**
374
+ * Optional callback to execute when workflow is retried
375
+ * @param error The error that caused the retry
376
+ * @param context The workflow context
377
+ */
378
+ private readonly onRetry?;
379
+ /**
380
+ * Optional callback to execute when workflow is broken
381
+ * @param reason The reason for breaking the workflow
382
+ * @param context The workflow context
383
+ */
384
+ private readonly onBreak?;
385
+ /**
386
+ * Optional callback to execute when workflow completes successfully
387
+ * @param context The workflow context
388
+ */
389
+ private readonly onSuccess?;
390
+ /**
391
+ * Optional callback to execute when workflow fails
392
+ * @param error The error that caused the failure
393
+ * @param context The workflow context
394
+ */
395
+ private readonly onFailed?;
396
+ /**
397
+ * Create a new WorkflowRetry instance
398
+ * @param options Configuration options for the workflow and actions
399
+ */
400
+ constructor(options?: WorkflowOptions);
401
+ /**
402
+ * Break the workflow execution with an error
403
+ * @param reason Optional reason for breaking the workflow
404
+ * @param customError Optional custom error to throw instead of WorkflowBreakError
405
+ * @throws {WorkflowBreakError} Always throws to break the workflow
406
+ */
407
+ break(reason?: unknown): never;
408
+ /**
409
+ * Check if the workflow was broken
410
+ * @returns True if the workflow was broken
411
+ */
412
+ wasBroken(): boolean;
413
+ /**
414
+ * Get the reason for breaking the workflow
415
+ * @returns The reason for breaking the workflow
416
+ */
417
+ getBreakReason(): unknown;
418
+ /**
419
+ * Add an action to the workflow
420
+ * @param options Action options including the action function and retry configuration
421
+ * @returns The WorkflowRetry instance for method chaining
422
+ */
423
+ addAction<T>(options: ActionOptions<T>): WorkflowRetry;
424
+ /**
425
+ * Private retry method for workflow execution
426
+ * @param fn The function to retry
427
+ * @param context The workflow context
428
+ * @returns Promise with the result of the function
429
+ * @throws {Error} If all retry attempts fail
430
+ */
431
+ private retry;
432
+ /**
433
+ * Execute all actions in the workflow with retry logic
434
+ * @returns Promise with a WorkflowResult object containing the results
435
+ * @throws {Error} If any action fails after all retry attempts
436
+ * @throws {WorkflowBreakError} If the workflow is broken
437
+ */
438
+ execute(): Promise<WorkflowResult>;
439
+ }
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heyanon/sdk",
3
- "version": "2.3.10",
3
+ "version": "2.4.1",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -50,7 +50,7 @@
50
50
  "@ton/ton": "15.2.0",
51
51
  "ccxt": "4.4.78",
52
52
  "openai": "5.12.1",
53
- "viem": "2.22.9",
53
+ "viem": "2.41.2",
54
54
  "vitest": "^2.1.8"
55
55
  }
56
56
  }