workflow-common 1.0.0

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.
Files changed (54) hide show
  1. package/README.md +25 -0
  2. package/package.json +24 -0
  3. package/src/index.ts +2 -0
  4. package/src/tasks/AddPropertyToJsonTask.ts +31 -0
  5. package/src/tasks/ApplySessionSorageTask.ts +31 -0
  6. package/src/tasks/CheckElementExistsTask.ts +30 -0
  7. package/src/tasks/ClearInputTask.ts +26 -0
  8. package/src/tasks/ClickElementTask.ts +26 -0
  9. package/src/tasks/CloseBrowserTask.ts +16 -0
  10. package/src/tasks/DeliverViaWebhookTask.ts +21 -0
  11. package/src/tasks/DoubleClickElementTask.ts +26 -0
  12. package/src/tasks/ExtractElementByTextTask.ts +46 -0
  13. package/src/tasks/ExtractTextAndValidateTask.ts +36 -0
  14. package/src/tasks/FillCredentialsTask.ts +31 -0
  15. package/src/tasks/FillInputTask.ts +31 -0
  16. package/src/tasks/GoForwardTask.ts +21 -0
  17. package/src/tasks/GobackTask.ts +21 -0
  18. package/src/tasks/HoverElementTask.ts +26 -0
  19. package/src/tasks/HttpRequestTask.ts +57 -0
  20. package/src/tasks/LaunchBrowserTask.ts +20 -0
  21. package/src/tasks/LogMessageTask.ts +36 -0
  22. package/src/tasks/LoginViaBasicAuthTask.ts +31 -0
  23. package/src/tasks/NavigateUrlTask.ts +26 -0
  24. package/src/tasks/PageToHtmlTask.ts +25 -0
  25. package/src/tasks/PressKeyTask.ts +33 -0
  26. package/src/tasks/ReadPropertyFromJsonTask.ts +26 -0
  27. package/src/tasks/ReloadPageTask.ts +21 -0
  28. package/src/tasks/RightClickElementTask.ts +26 -0
  29. package/src/tasks/ScrollToBottomTask.ts +26 -0
  30. package/src/tasks/ScrollToElementTask.ts +26 -0
  31. package/src/tasks/ScrollToTopTask.ts +26 -0
  32. package/src/tasks/SelectDropdownTask.ts +31 -0
  33. package/src/tasks/SetCookieTask.ts +47 -0
  34. package/src/tasks/StoreAuthTokenTask.ts +45 -0
  35. package/src/tasks/TaskRegisteryTask.ts +171 -0
  36. package/src/tasks/ToogleCheckboxTask.ts +32 -0
  37. package/src/tasks/UploadFileTask.ts +31 -0
  38. package/src/tasks/ValidateCheckboxTask.ts +42 -0
  39. package/src/tasks/WaitForElementTask.ts +42 -0
  40. package/src/tasks/WaitForNavigationTask.ts +21 -0
  41. package/src/tasks/WaitForTimeTask.ts +27 -0
  42. package/src/tasks/index.ts +38 -0
  43. package/src/types/appNode.ts +25 -0
  44. package/src/types/common.ts +5 -0
  45. package/src/types/execution.ts +40 -0
  46. package/src/types/executor.ts +33 -0
  47. package/src/types/index.ts +10 -0
  48. package/src/types/log.ts +16 -0
  49. package/src/types/schedule.ts +119 -0
  50. package/src/types/suites.ts +13 -0
  51. package/src/types/task.ts +80 -0
  52. package/src/types/workflow.ts +49 -0
  53. package/src/types/workflowTasks.ts +9 -0
  54. package/tsconfig.json +13 -0
@@ -0,0 +1,38 @@
1
+ export * from './AddPropertyToJsonTask';
2
+ export * from './ApplySessionSorageTask';
3
+ export * from './CheckElementExistsTask';
4
+ export * from './ClearInputTask';
5
+ export * from './ClickElementTask';
6
+ export * from './CloseBrowserTask';
7
+ export * from './DeliverViaWebhookTask';
8
+ export * from './DoubleClickElementTask';
9
+ export * from './ExtractElementByTextTask';
10
+ export * from './ExtractTextAndValidateTask';
11
+ export * from './FillCredentialsTask';
12
+ export * from './FillInputTask';
13
+ export * from './GobackTask';
14
+ export * from './GoForwardTask';
15
+ export * from './HoverElementTask';
16
+ export * from './HttpRequestTask';
17
+ export * from './LaunchBrowserTask';
18
+ export * from './LoginViaBasicAuthTask';
19
+ export * from './LogMessageTask';
20
+ export * from './NavigateUrlTask';
21
+ export * from './PageToHtmlTask';
22
+ export * from './PressKeyTask';
23
+ export * from './ReadPropertyFromJsonTask';
24
+ export * from './ReloadPageTask';
25
+ export * from './RightClickElementTask';
26
+ export * from './ScrollToBottomTask';
27
+ export * from './ScrollToElementTask';
28
+ export * from './ScrollToTopTask';
29
+ export * from './SelectDropdownTask';
30
+ export * from './SetCookieTask';
31
+ export * from './StoreAuthTokenTask';
32
+ export * from './TaskRegisteryTask';
33
+ //export * from './ToggleCheckboxTask';
34
+ export * from './UploadFileTask';
35
+ export * from './ValidateCheckboxTask';
36
+ export * from './WaitForElementTask';
37
+ export * from './WaitForNavigationTask';
38
+ export * from './WaitForTimeTask';
@@ -0,0 +1,25 @@
1
+ import { Node } from '@xyflow/react';
2
+ import { TaskParam, TaskType } from './task';
3
+
4
+ export interface AppNodeData {
5
+ [key: string]: unknown;
6
+ type: TaskType;
7
+ inputs: Record<string, string>;
8
+ label: string;
9
+ }
10
+
11
+ export interface AppNode extends Node {
12
+ data: AppNodeData;
13
+ }
14
+
15
+ export interface ParamsProps {
16
+ param: TaskParam;
17
+ value: string;
18
+ updateNodeParamValue: (newValue: string) => void;
19
+ disabled?: boolean;
20
+ }
21
+
22
+ export type AppNodeMissingInputs = {
23
+ nodeId: string;
24
+ inputs: string[];
25
+ };
@@ -0,0 +1,5 @@
1
+ export const Browsers = [
2
+ { label: 'Chrome', value: 'chrome' },
3
+ { label: 'Firefox', value: 'firefox' },
4
+ { label: 'Safari (WebKit)', value: 'safari' },
5
+ ];
@@ -0,0 +1,40 @@
1
+ import { WorkflowExecutionStatus, WorkflowExecutionTrigger } from './workflow';
2
+
3
+ export type WorkflowExecution = {
4
+ id: string;
5
+ workflowId: string;
6
+ userId: string;
7
+ status: WorkflowExecutionStatus;
8
+ startedAt?: Date | null;
9
+ endedAt?: string | null;
10
+ trigger: WorkflowExecutionTrigger;
11
+ definition?: string | null;
12
+ phases?: ExecutionPhase[];
13
+ browser: string;
14
+ videoUrl: string | null;
15
+ };
16
+
17
+ export type ExecutionPhase = {
18
+ id: string;
19
+ number: number;
20
+ userId: string;
21
+ status: string;
22
+ startedAt: Date | null;
23
+ completedAt: Date | null;
24
+ name: string;
25
+ node: string;
26
+ inputs: string | null;
27
+ outputs: string | null;
28
+ screenshot: string | null;
29
+ workflowExecutionId: string;
30
+ logs: Logs[];
31
+ };
32
+
33
+ export type Logs = {
34
+ id: string;
35
+ phaseId: string;
36
+ timestamp: Date;
37
+ message: string;
38
+ type: string;
39
+ logLevel: 'info' | 'error' | 'debug' | 'warn';
40
+ };
@@ -0,0 +1,33 @@
1
+ import { Browser, Page } from 'playwright';
2
+ import { LogCollector } from './log';
3
+ import { Workflowtask } from './workflow';
4
+
5
+ export interface Environment {
6
+ phases: {
7
+ [key: string]: {
8
+ inputs: { [key: string]: string };
9
+ outputs: { [key: string]: string };
10
+ screenshot?: string;
11
+ };
12
+ };
13
+ browser?: Browser;
14
+ page?: Page;
15
+ browserType?: string;
16
+ }
17
+
18
+ export interface ExecutionEnvironmentType<T extends Workflowtask> {
19
+ getInput(name: T['inputs'][number]['name']): string;
20
+ setOutput(name: T['outputs'][number]['name'], value: string): void;
21
+
22
+ getBrowser(): Browser | undefined;
23
+ setBrowser(browser: Browser): void;
24
+
25
+ getPage(): Page | undefined;
26
+ setPage(page: Page): void;
27
+
28
+ setScreenshot(screenshot: string): void;
29
+
30
+ getBrowserType(): string;
31
+
32
+ log: LogCollector;
33
+ }
@@ -0,0 +1,10 @@
1
+ export * from './appNode';
2
+ export * from './executor';
3
+ export * from './common';
4
+ export * from './execution';
5
+ export * from './log';
6
+ export * from './schedule';
7
+ export * from './task';
8
+ export * from './workflow';
9
+ export * from './workflowTasks';
10
+ export * from './suites';
@@ -0,0 +1,16 @@
1
+ export interface LogEntry {
2
+ message: string;
3
+ timestamp: Date;
4
+ level: string;
5
+ type?: string;
6
+ }
7
+
8
+ export interface LogCollector {
9
+ info: (message: string) => void;
10
+ warn: (message: string) => void;
11
+ error: (message: string) => void;
12
+ debug: (message: string) => void;
13
+ console: (message: string) => void;
14
+ getStandardLogs: () => LogEntry[];
15
+ getConsoleLogs: () => LogEntry[];
16
+ }
@@ -0,0 +1,119 @@
1
+ import { Timestamp } from "firebase/firestore";
2
+ import { addDays, addWeeks, addMonths, set, isBefore } from "date-fns";
3
+
4
+ export enum ScheduleStatus {
5
+ ENABLED = "ENABLED",
6
+ DISABLED = "DISABLED",
7
+ PAUSED = "PAUSED",
8
+ }
9
+
10
+ export enum ScheduleFrequency {
11
+ ONCE = "ONCE",
12
+ DAILY = "DAILY",
13
+ WEEKLY = "WEEKLY",
14
+ MONTHLY = "MONTHLY",
15
+ }
16
+
17
+ export interface Schedule {
18
+ id: string;
19
+ workflowId: string;
20
+ applicationId: string;
21
+ name: string;
22
+ description?: string;
23
+ status: ScheduleStatus;
24
+ frequency: ScheduleFrequency;
25
+ nextRunAt: Timestamp;
26
+ lastRunAt?: Timestamp;
27
+ lastRunId?: string;
28
+ lastRunStatus?: "COMPLETED" | "FAILED";
29
+ createdAt: Timestamp;
30
+ createdBy: string;
31
+ updatedAt: Timestamp;
32
+ updatedBy: string;
33
+ timezone: string;
34
+ retryCount: number;
35
+ maxRetries: number;
36
+ retryDelay: number; // in minutes
37
+ configuration: configuration;
38
+ }
39
+
40
+ export interface configuration {
41
+ time?: string; // HH:mm format
42
+ dayOfWeek?: number; // 0-6 (Sunday-Saturday)
43
+ dayOfMonth?: number; // 1-31
44
+ browser: string;
45
+ }
46
+
47
+ export interface ScheduleExecution {
48
+ id: string;
49
+ scheduleId: string;
50
+ workflowId: string;
51
+ status: "PENDING" | "IN_PROGRESS" | "COMPLETED" | "FAILED";
52
+ startedAt: Timestamp;
53
+ completedAt?: Timestamp;
54
+ error?: string;
55
+ retryCount: number;
56
+ nextRetryAt?: Timestamp;
57
+ }
58
+
59
+ export function calculateNextRunAt(
60
+ frequency: ScheduleFrequency,
61
+ configuration: configuration
62
+ ) {
63
+ const now = new Date();
64
+ const [hour, minute] = (configuration.time || "00:00").split(":").map(Number);
65
+
66
+ switch (frequency) {
67
+ case "ONCE": {
68
+ const runDate = set(now, {
69
+ hours: hour,
70
+ minutes: minute,
71
+ seconds: 0,
72
+ milliseconds: 0,
73
+ });
74
+ return Timestamp.fromDate(runDate);
75
+ }
76
+
77
+ case "DAILY": {
78
+ let next = set(now, {
79
+ hours: hour,
80
+ minutes: minute,
81
+ seconds: 0,
82
+ milliseconds: 0,
83
+ });
84
+ if (isBefore(next, now)) next = addDays(next, 1);
85
+ return Timestamp.fromDate(next);
86
+ }
87
+
88
+ case "WEEKLY": {
89
+ const targetWeekday = configuration.dayOfWeek ?? 0; // Sunday = 0
90
+ let next = set(now, {
91
+ hours: hour,
92
+ minutes: minute,
93
+ seconds: 0,
94
+ milliseconds: 0,
95
+ });
96
+ while (next.getDay() !== targetWeekday) {
97
+ next = addDays(next, 1);
98
+ }
99
+ if (isBefore(next, now)) next = addWeeks(next, 1);
100
+ return Timestamp.fromDate(next);
101
+ }
102
+
103
+ case "MONTHLY": {
104
+ const targetDay = configuration.dayOfMonth ?? 1;
105
+ let next = set(now, {
106
+ date: targetDay,
107
+ hours: hour,
108
+ minutes: minute,
109
+ seconds: 0,
110
+ milliseconds: 0,
111
+ });
112
+ if (isBefore(next, now)) next = addMonths(next, 1);
113
+ return Timestamp.fromDate(next);
114
+ }
115
+
116
+ default:
117
+ throw new Error("Invalid frequency type");
118
+ }
119
+ }
@@ -0,0 +1,13 @@
1
+ import { WorkflowExecutionStatus, WorkflowExecutionTrigger } from './workflow';
2
+
3
+ export type SuiteExecution = {
4
+ id: string;
5
+ status: WorkflowExecutionStatus;
6
+ startedAt?: Date | null;
7
+ endedAt?: string | null;
8
+ trigger: WorkflowExecutionTrigger;
9
+ browser: string;
10
+ executionType: string;
11
+ executionIds: string[];
12
+ suiteId: string;
13
+ };
@@ -0,0 +1,80 @@
1
+ export enum TaskType {
2
+ //Browser & Page Control
3
+ LAUNCH_BROWSER = 'LAUNCH_BROWSER',
4
+ CLOSE_BROWSER = 'CLOSE_BROWSER',
5
+ RELOAD_PAGE = 'RELOAD_PAGE',
6
+ NAVIGATE_URL = 'NAVIGATE_URL',
7
+ GO_BACK = 'GO_BACK',
8
+ GO_FORWARD = 'GO_FORWARD',
9
+
10
+ //Page Content Extraction
11
+ PAGE_TO_HTML = 'PAGE_TO_HTML',
12
+ EXTRACT_ELEMENT_BY_TEXT = 'EXTRACT_ELEMENT_BY_TEXT',
13
+
14
+ //Interactions & Form Handling
15
+ FILL_INPUT = 'FILL_INPUT',
16
+ FILL_CREDENTIAL = 'FILL_CREDENTIAL',
17
+ CLICK_ELEMENT = 'CLICK_ELEMENT',
18
+ SELECT_DROPDOWN = 'SELECT_DROPDOWN',
19
+ VALIDATE_CHECKBOX = 'VALIDATE_CHECKBOX',
20
+ CLEAR_INPUT = 'CLEAR_INPUT',
21
+ // TOGGLE_CHECKBOX = 'TOGGLE_CHECKBOX',
22
+ UPLOAD_FILE = 'UPLOAD_FILE',
23
+ HOVER_ELEMENT = 'HOVER_ELEMENT',
24
+ DOUBLE_CLICK_ELEMENT = 'DOUBLE_CLICK_ELEMENT',
25
+ RIGHT_CLICK_ELEMENT = 'RIGHT_CLICK_ELEMENT',
26
+ PRESS_KEY = 'PRESS_KEY',
27
+
28
+ //Waits & Conditions
29
+ WAIT_FOR_ELEMENT = 'WAIT_FOR_ELEMENT',
30
+ WAIT_FOR_TIME = 'WAIT_FOR_TIME',
31
+ WAIT_FOR_NAVIGATION = 'WAIT_FOR_NAVIGATION',
32
+ CHECK_ELEMENT_EXISTS = 'CHECK_ELEMENT_EXISTS',
33
+ EXTRACT_TEXT_AND_VALIDATE = 'EXTRACT_TEXT_AND_VALIDATE',
34
+
35
+ //Scrolling
36
+ SCROLL_TO_ELEMENT = 'SCROLL_TO_ELEMENT',
37
+ SCROLL_TO_TOP = 'SCROLL_TO_TOP',
38
+ SCROLL_TO_BOTTOM = 'SCROLL_TO_BOTTOM',
39
+
40
+ //Flow & Data Manipulation
41
+ READ_PROPERTY_FROM_JSON = 'READ_PROPERTY_FROM_JSON',
42
+ ADD_PROPERTY_TO_JSON = 'ADD_PROPERTY_TO_JSON',
43
+
44
+ //Authentication & Session
45
+ SET_COOKIE = 'SET_COOKIE',
46
+ LOGIN_VIA_BASIC_AUTH = 'LOGIN_VIA_BASIC_AUTH',
47
+ APPLY_SESSION_STORAGE = 'APPLY_SESSION_STORAGE',
48
+ STORE_AUTH_TOKEN = 'STORE_AUTH_TOKEN',
49
+
50
+ //Delivery & Output
51
+ DELIVER_VIA_WEBHOOK = 'DELIVER_VIA_WEBHOOK',
52
+ HTTP_REQUEST = 'HTTP_REQUEST',
53
+ LOG_MESSAGE = 'LOG_MESSAGE',
54
+ }
55
+
56
+ export enum TaskParamType {
57
+ STRING = 'STRING',
58
+ BROWSER_INSTANCE = 'BROWSER_INSTANCE',
59
+ SELECT = 'SELECT',
60
+ CREDENTIAL = 'CREDENTIAL',
61
+ JSON = 'JSON',
62
+ NUMBER = 'NUMBER',
63
+ BOOLEAN = 'BOOLEAN',
64
+ ARRAY = 'ARRAY',
65
+ OBJECT = 'OBJECT',
66
+ }
67
+
68
+ export interface TaskParam {
69
+ name: string;
70
+ type: TaskParamType;
71
+ helperText?: string;
72
+ required?: boolean;
73
+ hideHandle?: boolean;
74
+ [key: string]: unknown;
75
+ }
76
+
77
+ export interface TaskOutput {
78
+ name: string;
79
+ type: TaskParamType;
80
+ }
@@ -0,0 +1,49 @@
1
+ import { TaskParam, TaskType } from './task';
2
+ import { AppNode } from './appNode';
3
+
4
+ export enum WorkflowStatus {
5
+ DRAFT = 'DRAFT',
6
+ PUBLISHED = 'PUBLISHED',
7
+ }
8
+
9
+ export type Workflowtask = {
10
+ label: string;
11
+ type: TaskType;
12
+ isEntryPoint?: boolean;
13
+ inputs: TaskParam[];
14
+ outputs: TaskParam[];
15
+ };
16
+
17
+ export type WorkflowExecutionPlan = WorkflowExecutionPlanPhase[];
18
+
19
+ export type WorkflowExecutionPlanPhase = {
20
+ phase: number;
21
+ nodes: AppNode[];
22
+ };
23
+
24
+ export enum WorkflowExecutionStatus {
25
+ PENDING = 'PENDING',
26
+ RUNNING = 'RUNNING',
27
+ COMPLETED = 'COMPLETED',
28
+ FAILED = 'FAILED',
29
+ }
30
+
31
+ export enum ExecutionPhaseStatus {
32
+ CREATED = 'CREATED',
33
+ PENDING = 'PENDING',
34
+ RUNNING = 'RUNNING',
35
+ COMPLETED = 'COMPLETED',
36
+ FAILED = 'FAILED',
37
+ }
38
+
39
+ export enum WorkflowExecutionTrigger {
40
+ MANUAL = 'MANUAL',
41
+ SCHEDULED = 'SCHEDULED',
42
+ }
43
+
44
+ export enum ScheduleExecutionStatus {
45
+ PENDING = 'PENDING',
46
+ RUNNING = 'RUNNING',
47
+ COMPLETED = 'COMPLETED',
48
+ FAILED = 'FAILED',
49
+ }
@@ -0,0 +1,9 @@
1
+ import { TaskParam, TaskType } from './task';
2
+
3
+ export type WorkflowTask = {
4
+ label: string;
5
+ type: TaskType;
6
+ isEntryPoint?: boolean;
7
+ inputs: TaskParam[];
8
+ outputs: TaskParam[];
9
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "CommonJS",
5
+ "declaration": true,
6
+ "outDir": "dist",
7
+ "rootDir": "src",
8
+ "strict": true,
9
+ "esModuleInterop": true
10
+ },
11
+ "include": ["src"]
12
+ }
13
+