@voyant-travel/workflows-react 0.107.10
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/LICENSE +201 -0
- package/NOTICE +52 -0
- package/README.md +106 -0
- package/dist/client.d.ts +2 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +1 -0
- package/dist/components/common.d.ts +30 -0
- package/dist/components/common.d.ts.map +1 -0
- package/dist/components/common.js +108 -0
- package/dist/components/workflow-run-actions.d.ts +7 -0
- package/dist/components/workflow-run-actions.d.ts.map +1 -0
- package/dist/components/workflow-run-actions.js +72 -0
- package/dist/components/workflow-run-detail-page.d.ts +10 -0
- package/dist/components/workflow-run-detail-page.d.ts.map +1 -0
- package/dist/components/workflow-run-detail-page.js +96 -0
- package/dist/components/workflow-runs-filters.d.ts +32 -0
- package/dist/components/workflow-runs-filters.d.ts.map +1 -0
- package/dist/components/workflow-runs-filters.js +97 -0
- package/dist/components/workflow-runs-page.d.ts +12 -0
- package/dist/components/workflow-runs-page.d.ts.map +1 -0
- package/dist/components/workflow-runs-page.js +132 -0
- package/dist/components/workflow-schedules-page.d.ts +21 -0
- package/dist/components/workflow-schedules-page.d.ts.map +1 -0
- package/dist/components/workflow-schedules-page.js +144 -0
- package/dist/i18n/en.d.ts +4 -0
- package/dist/i18n/en.d.ts.map +1 -0
- package/dist/i18n/en.js +135 -0
- package/dist/i18n/index.d.ts +5 -0
- package/dist/i18n/index.d.ts.map +1 -0
- package/dist/i18n/index.js +3 -0
- package/dist/i18n/messages.d.ts +125 -0
- package/dist/i18n/messages.d.ts.map +1 -0
- package/dist/i18n/messages.js +1 -0
- package/dist/i18n/provider.d.ts +26 -0
- package/dist/i18n/provider.d.ts.map +1 -0
- package/dist/i18n/provider.js +44 -0
- package/dist/i18n/ro.d.ts +4 -0
- package/dist/i18n/ro.d.ts.map +1 -0
- package/dist/i18n/ro.js +137 -0
- package/dist/index.d.ts +56 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/schedules-client.d.ts +2 -0
- package/dist/schedules-client.d.ts.map +1 -0
- package/dist/schedules-client.js +1 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/dist/ui.d.ts +9 -0
- package/dist/ui.d.ts.map +1 -0
- package/dist/ui.js +6 -0
- package/dist/workflow-runs-client.d.ts +124 -0
- package/dist/workflow-runs-client.d.ts.map +1 -0
- package/dist/workflow-runs-client.js +138 -0
- package/dist/workflow-runs.d.ts +36 -0
- package/dist/workflow-runs.d.ts.map +1 -0
- package/dist/workflow-runs.js +70 -0
- package/dist/workflow-schedules-client.d.ts +70 -0
- package/dist/workflow-schedules-client.d.ts.map +1 -0
- package/dist/workflow-schedules-client.js +91 -0
- package/package.json +123 -0
- package/src/client.ts +4 -0
- package/src/components/common.tsx +182 -0
- package/src/components/workflow-run-actions.tsx +160 -0
- package/src/components/workflow-run-detail-page.tsx +393 -0
- package/src/components/workflow-runs-filters.tsx +349 -0
- package/src/components/workflow-runs-page.tsx +357 -0
- package/src/components/workflow-schedules-page.tsx +398 -0
- package/src/i18n/en.ts +142 -0
- package/src/i18n/index.ts +26 -0
- package/src/i18n/messages.ts +125 -0
- package/src/i18n/provider.tsx +96 -0
- package/src/i18n/ro.ts +144 -0
- package/src/index.ts +94 -0
- package/src/schedules-client.ts +8 -0
- package/src/styles.css +11 -0
- package/src/types.ts +14 -0
- package/src/ui.ts +63 -0
- package/src/workflow-runs-client.ts +304 -0
- package/src/workflow-runs.ts +120 -0
- package/src/workflow-schedules-client.ts +177 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
export interface WorkflowRunErrorPayload {
|
|
2
|
+
message: string;
|
|
3
|
+
code?: string;
|
|
4
|
+
stepName?: string;
|
|
5
|
+
stack?: string;
|
|
6
|
+
}
|
|
7
|
+
export type WorkflowRunStatus = "running" | "succeeded" | "failed" | "cancelled";
|
|
8
|
+
export interface WorkflowRun {
|
|
9
|
+
id: string;
|
|
10
|
+
workflowName: string;
|
|
11
|
+
trigger: string;
|
|
12
|
+
correlationId: string | null;
|
|
13
|
+
tags: string[];
|
|
14
|
+
status: WorkflowRunStatus;
|
|
15
|
+
input: Record<string, unknown> | null;
|
|
16
|
+
result: Record<string, unknown> | null;
|
|
17
|
+
error: WorkflowRunErrorPayload | null;
|
|
18
|
+
parentRunId: string | null;
|
|
19
|
+
triggeredByUserId: string | null;
|
|
20
|
+
resumeFromStep: string | null;
|
|
21
|
+
startedAt: string;
|
|
22
|
+
completedAt: string | null;
|
|
23
|
+
durationMs: number | null;
|
|
24
|
+
createdAt: string;
|
|
25
|
+
updatedAt: string;
|
|
26
|
+
}
|
|
27
|
+
export type WorkflowRunStepStatus = "running" | "succeeded" | "failed" | "skipped" | "compensated";
|
|
28
|
+
export interface WorkflowRunStep {
|
|
29
|
+
id: string;
|
|
30
|
+
runId: string;
|
|
31
|
+
stepName: string;
|
|
32
|
+
sequence: number;
|
|
33
|
+
status: WorkflowRunStepStatus;
|
|
34
|
+
output: Record<string, unknown> | null;
|
|
35
|
+
error: WorkflowRunErrorPayload | null;
|
|
36
|
+
startedAt: string;
|
|
37
|
+
completedAt: string | null;
|
|
38
|
+
durationMs: number | null;
|
|
39
|
+
}
|
|
40
|
+
export interface ListWorkflowRunsQuery {
|
|
41
|
+
workflowName?: string;
|
|
42
|
+
status?: WorkflowRunStatus;
|
|
43
|
+
tag?: string;
|
|
44
|
+
parentRunId?: string;
|
|
45
|
+
limit?: number;
|
|
46
|
+
offset?: number;
|
|
47
|
+
}
|
|
48
|
+
export interface ListWorkflowRunsResponse {
|
|
49
|
+
data: WorkflowRun[];
|
|
50
|
+
total: number;
|
|
51
|
+
limit: number;
|
|
52
|
+
offset: number;
|
|
53
|
+
}
|
|
54
|
+
export interface WorkflowRunDetailResponse {
|
|
55
|
+
data: {
|
|
56
|
+
run: WorkflowRun;
|
|
57
|
+
steps: WorkflowRunStep[];
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export interface WorkflowRunActionResponse {
|
|
61
|
+
data: {
|
|
62
|
+
runId: string;
|
|
63
|
+
parentRunId: string;
|
|
64
|
+
resumeFromStep?: string;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
export interface WorkflowRunActionError {
|
|
68
|
+
error: string;
|
|
69
|
+
detail?: string;
|
|
70
|
+
idempotency?: "safe" | "unsafe" | "resume-only";
|
|
71
|
+
}
|
|
72
|
+
export type WorkflowRunActionResult = {
|
|
73
|
+
ok: true;
|
|
74
|
+
data: WorkflowRunActionResponse["data"];
|
|
75
|
+
} | {
|
|
76
|
+
ok: false;
|
|
77
|
+
error: WorkflowRunActionError;
|
|
78
|
+
};
|
|
79
|
+
export interface WorkflowRunsApi {
|
|
80
|
+
listRuns(query: ListWorkflowRunsQuery): Promise<ListWorkflowRunsResponse>;
|
|
81
|
+
getRun(id: string): Promise<WorkflowRunDetailResponse>;
|
|
82
|
+
rerunRun(id: string, opts?: {
|
|
83
|
+
confirm?: boolean;
|
|
84
|
+
}): Promise<WorkflowRunActionResult>;
|
|
85
|
+
resumeRun(id: string): Promise<WorkflowRunActionResult>;
|
|
86
|
+
}
|
|
87
|
+
export type WorkflowRunsFetcher = (input: string, init?: RequestInit) => Promise<Response>;
|
|
88
|
+
export interface WorkflowRunsApiClientOptions {
|
|
89
|
+
apiBase?: string;
|
|
90
|
+
baseUrl?: string;
|
|
91
|
+
fetcher?: WorkflowRunsFetcher;
|
|
92
|
+
credentials?: RequestCredentials;
|
|
93
|
+
headers?: HeadersInit;
|
|
94
|
+
}
|
|
95
|
+
export interface WorkflowRunsClientOptions {
|
|
96
|
+
baseUrl: string;
|
|
97
|
+
fetcher: WorkflowRunsFetcher;
|
|
98
|
+
credentials?: RequestCredentials;
|
|
99
|
+
headers?: HeadersInit;
|
|
100
|
+
}
|
|
101
|
+
export declare class WorkflowRunsApiError extends Error {
|
|
102
|
+
readonly status: number;
|
|
103
|
+
readonly body: unknown;
|
|
104
|
+
constructor(message: string, status: number, body: unknown);
|
|
105
|
+
}
|
|
106
|
+
export declare const defaultWorkflowRunsFetcher: WorkflowRunsFetcher;
|
|
107
|
+
export declare const workflowRunsQueryKeys: {
|
|
108
|
+
readonly all: readonly ["voyant", "workflow-runs"];
|
|
109
|
+
readonly lists: () => readonly ["voyant", "workflow-runs", "list"];
|
|
110
|
+
readonly list: (query: ListWorkflowRunsQuery) => readonly ["voyant", "workflow-runs", "list", ListWorkflowRunsQuery];
|
|
111
|
+
readonly details: () => readonly ["voyant", "workflow-runs", "detail"];
|
|
112
|
+
readonly detail: (id: string) => readonly ["voyant", "workflow-runs", "detail", string];
|
|
113
|
+
};
|
|
114
|
+
export declare function createWorkflowRunsClientOptions(client?: Partial<WorkflowRunsClientOptions>): WorkflowRunsClientOptions;
|
|
115
|
+
export declare function createWorkflowRunsApiClient(options?: WorkflowRunsApiClientOptions): WorkflowRunsApi;
|
|
116
|
+
export declare function listWorkflowRuns(query?: ListWorkflowRunsQuery, client?: WorkflowRunsClientOptions): Promise<ListWorkflowRunsResponse>;
|
|
117
|
+
export declare function getWorkflowRun(id: string, client?: WorkflowRunsClientOptions): Promise<WorkflowRunDetailResponse>;
|
|
118
|
+
export declare function rerunWorkflowRun(input: {
|
|
119
|
+
id: string;
|
|
120
|
+
confirm?: boolean;
|
|
121
|
+
}, client?: WorkflowRunsClientOptions): Promise<WorkflowRunActionResult>;
|
|
122
|
+
export declare function resumeWorkflowRun(id: string, client?: WorkflowRunsClientOptions): Promise<WorkflowRunActionResult>;
|
|
123
|
+
export declare function workflowRunIsTerminal(status: WorkflowRunStatus): boolean;
|
|
124
|
+
//# sourceMappingURL=workflow-runs-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow-runs-client.d.ts","sourceRoot":"","sources":["../src/workflow-runs-client.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,CAA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EV,wBAAgB,+BAA+B,CAC7C,MAAM,CAAC,EAAE,OAAO,CAAC,yBAAyB,CAAC,GAC1C,yBAAyB,CAO3B;AAED,wBAAgB,2BAA2B,CACzC,OAAO,GAAE,4BAAiC,GACzC,eAAe,CAcjB;AAED,wBAAsB,gBAAgB,CACpC,KAAK,GAAE,qBAA0B,EACjC,MAAM,GAAE,yBAA6D,GACpE,OAAO,CAAC,wBAAwB,CAAC,CAMnC;AAED,wBAAsB,cAAc,CAClC,EAAE,EAAE,MAAM,EACV,MAAM,GAAE,yBAA6D,GACpE,OAAO,CAAC,yBAAyB,CAAC,CAMpC;AAED,wBAAsB,gBAAgB,CACpC,KAAK,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,EACxC,MAAM,GAAE,yBAA6D,GACpE,OAAO,CAAC,uBAAuB,CAAC,CAWlC;AAED,wBAAsB,iBAAiB,CACrC,EAAE,EAAE,MAAM,EACV,MAAM,GAAE,yBAA6D,GACpE,OAAO,CAAC,uBAAuB,CAAC,CAQlC;AAED,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAExE"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
export class WorkflowRunsApiError extends Error {
|
|
2
|
+
status;
|
|
3
|
+
body;
|
|
4
|
+
constructor(message, status, body) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = "WorkflowRunsApiError";
|
|
7
|
+
this.status = status;
|
|
8
|
+
this.body = body;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export const defaultWorkflowRunsFetcher = (input, init) => fetch(input, init);
|
|
12
|
+
export const workflowRunsQueryKeys = {
|
|
13
|
+
all: ["voyant", "workflow-runs"],
|
|
14
|
+
lists: () => [...workflowRunsQueryKeys.all, "list"],
|
|
15
|
+
list: (query) => [...workflowRunsQueryKeys.lists(), query],
|
|
16
|
+
details: () => [...workflowRunsQueryKeys.all, "detail"],
|
|
17
|
+
detail: (id) => [...workflowRunsQueryKeys.details(), id],
|
|
18
|
+
};
|
|
19
|
+
export function createWorkflowRunsClientOptions(client) {
|
|
20
|
+
return {
|
|
21
|
+
baseUrl: client?.baseUrl ?? "",
|
|
22
|
+
fetcher: client?.fetcher ?? defaultWorkflowRunsFetcher,
|
|
23
|
+
credentials: client?.credentials,
|
|
24
|
+
headers: client?.headers,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export function createWorkflowRunsApiClient(options = {}) {
|
|
28
|
+
const client = createWorkflowRunsClientOptions({
|
|
29
|
+
baseUrl: options.baseUrl ?? options.apiBase ?? "",
|
|
30
|
+
fetcher: options.fetcher,
|
|
31
|
+
credentials: options.credentials ?? "include",
|
|
32
|
+
headers: options.headers,
|
|
33
|
+
});
|
|
34
|
+
return {
|
|
35
|
+
listRuns: (query) => listWorkflowRuns(query, client),
|
|
36
|
+
getRun: (id) => getWorkflowRun(id, client),
|
|
37
|
+
rerunRun: (id, opts) => rerunWorkflowRun({ id, confirm: opts?.confirm }, client),
|
|
38
|
+
resumeRun: (id) => resumeWorkflowRun(id, client),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export async function listWorkflowRuns(query = {}, client = createWorkflowRunsClientOptions()) {
|
|
42
|
+
return fetchWorkflowRunsJson(`/v1/admin/workflow-runs${buildWorkflowRunsSearch(query)}`, { method: "GET" }, client);
|
|
43
|
+
}
|
|
44
|
+
export async function getWorkflowRun(id, client = createWorkflowRunsClientOptions()) {
|
|
45
|
+
return fetchWorkflowRunsJson(`/v1/admin/workflow-runs/${encodeURIComponent(id)}`, { method: "GET" }, client);
|
|
46
|
+
}
|
|
47
|
+
export async function rerunWorkflowRun(input, client = createWorkflowRunsClientOptions()) {
|
|
48
|
+
return runWorkflowRunAction(await requestWorkflowRuns(`/v1/admin/workflow-runs/${encodeURIComponent(input.id)}/rerun`, {
|
|
49
|
+
method: "POST",
|
|
50
|
+
body: JSON.stringify({ confirm: input.confirm ?? false }),
|
|
51
|
+
}, client));
|
|
52
|
+
}
|
|
53
|
+
export async function resumeWorkflowRun(id, client = createWorkflowRunsClientOptions()) {
|
|
54
|
+
return runWorkflowRunAction(await requestWorkflowRuns(`/v1/admin/workflow-runs/${encodeURIComponent(id)}/resume`, { method: "POST" }, client));
|
|
55
|
+
}
|
|
56
|
+
export function workflowRunIsTerminal(status) {
|
|
57
|
+
return status !== "running";
|
|
58
|
+
}
|
|
59
|
+
async function fetchWorkflowRunsJson(path, init, client) {
|
|
60
|
+
const response = await requestWorkflowRuns(path, init, client);
|
|
61
|
+
const body = await safeJson(response);
|
|
62
|
+
if (!response.ok) {
|
|
63
|
+
throw new WorkflowRunsApiError(extractErrorMessage(response.status, response.statusText, body), response.status, body);
|
|
64
|
+
}
|
|
65
|
+
return body;
|
|
66
|
+
}
|
|
67
|
+
async function requestWorkflowRuns(path, init, client) {
|
|
68
|
+
const headers = new Headers(client.headers);
|
|
69
|
+
for (const [key, value] of new Headers(init.headers).entries()) {
|
|
70
|
+
headers.set(key, value);
|
|
71
|
+
}
|
|
72
|
+
if (init.body !== undefined && !headers.has("Content-Type")) {
|
|
73
|
+
headers.set("Content-Type", "application/json");
|
|
74
|
+
}
|
|
75
|
+
const requestInit = { ...init, headers };
|
|
76
|
+
if (client.credentials !== undefined) {
|
|
77
|
+
requestInit.credentials = client.credentials;
|
|
78
|
+
}
|
|
79
|
+
return client.fetcher(joinUrl(client.baseUrl, path), requestInit);
|
|
80
|
+
}
|
|
81
|
+
async function runWorkflowRunAction(res) {
|
|
82
|
+
const body = await safeJson(res);
|
|
83
|
+
if (res.ok) {
|
|
84
|
+
return { ok: true, data: body.data };
|
|
85
|
+
}
|
|
86
|
+
return { ok: false, error: body };
|
|
87
|
+
}
|
|
88
|
+
function buildWorkflowRunsSearch(query) {
|
|
89
|
+
const params = new URLSearchParams();
|
|
90
|
+
if (query.workflowName)
|
|
91
|
+
params.set("workflowName", query.workflowName);
|
|
92
|
+
if (query.status)
|
|
93
|
+
params.set("status", query.status);
|
|
94
|
+
if (query.tag)
|
|
95
|
+
params.set("tag", query.tag);
|
|
96
|
+
if (query.parentRunId)
|
|
97
|
+
params.set("parentRunId", query.parentRunId);
|
|
98
|
+
if (query.limit !== undefined)
|
|
99
|
+
params.set("limit", String(query.limit));
|
|
100
|
+
if (query.offset !== undefined)
|
|
101
|
+
params.set("offset", String(query.offset));
|
|
102
|
+
const search = params.toString();
|
|
103
|
+
return search ? `?${search}` : "";
|
|
104
|
+
}
|
|
105
|
+
async function safeJson(response) {
|
|
106
|
+
const text = await response.text();
|
|
107
|
+
if (!text)
|
|
108
|
+
return undefined;
|
|
109
|
+
try {
|
|
110
|
+
return JSON.parse(text);
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
return text;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
function extractErrorMessage(status, statusText, body) {
|
|
117
|
+
if (typeof body === "object" && body !== null) {
|
|
118
|
+
if ("error" in body && typeof body.error === "string")
|
|
119
|
+
return body.error;
|
|
120
|
+
if ("detail" in body && typeof body.detail === "string")
|
|
121
|
+
return body.detail;
|
|
122
|
+
}
|
|
123
|
+
return `Workflow runs API error: ${status} ${statusText}`;
|
|
124
|
+
}
|
|
125
|
+
function joinUrl(baseUrl, path) {
|
|
126
|
+
const resolvedBaseUrl = resolveBaseUrl(baseUrl);
|
|
127
|
+
const trimmedBase = resolvedBaseUrl.endsWith("/") ? resolvedBaseUrl.slice(0, -1) : resolvedBaseUrl;
|
|
128
|
+
const trimmedPath = path.startsWith("/") ? path : `/${path}`;
|
|
129
|
+
return `${trimmedBase}${trimmedPath}`;
|
|
130
|
+
}
|
|
131
|
+
function resolveBaseUrl(baseUrl) {
|
|
132
|
+
if (baseUrl.trim())
|
|
133
|
+
return baseUrl;
|
|
134
|
+
if (typeof window !== "undefined") {
|
|
135
|
+
return `${window.location.origin}/api`;
|
|
136
|
+
}
|
|
137
|
+
return "http://localhost:3300/api";
|
|
138
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { defaultFetcher, useVoyantReactContext, type VoyantFetcher, type VoyantReactContextValue, VoyantReactProvider, type VoyantReactProviderProps } from "@voyant-travel/react";
|
|
2
|
+
import { type ListWorkflowRunsQuery, type WorkflowRunsClientOptions } from "./workflow-runs-client.js";
|
|
3
|
+
export * from "./workflow-runs-client.js";
|
|
4
|
+
export { defaultFetcher, useVoyantReactContext as useVoyantWorkflowsContext, type VoyantFetcher, type VoyantReactContextValue as VoyantWorkflowsContextValue, VoyantReactProvider as VoyantWorkflowsProvider, type VoyantReactProviderProps as VoyantWorkflowsProviderProps, };
|
|
5
|
+
export declare function getWorkflowRunsQueryOptions(query?: ListWorkflowRunsQuery, client?: WorkflowRunsClientOptions, options?: {
|
|
6
|
+
pollIntervalMs?: number;
|
|
7
|
+
}): import("@tanstack/react-query").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<import("./workflow-runs-client.js").ListWorkflowRunsResponse, Error, import("./workflow-runs-client.js").ListWorkflowRunsResponse, readonly ["voyant", "workflow-runs", "list", ListWorkflowRunsQuery]>, "queryFn"> & {
|
|
8
|
+
queryFn?: import("@tanstack/react-query").QueryFunction<import("./workflow-runs-client.js").ListWorkflowRunsResponse, readonly ["voyant", "workflow-runs", "list", ListWorkflowRunsQuery], never> | undefined;
|
|
9
|
+
} & {
|
|
10
|
+
queryKey: readonly ["voyant", "workflow-runs", "list", ListWorkflowRunsQuery] & {
|
|
11
|
+
[dataTagSymbol]: import("./workflow-runs-client.js").ListWorkflowRunsResponse;
|
|
12
|
+
[dataTagErrorSymbol]: Error;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
export declare function getWorkflowRunQueryOptions(id: string | null | undefined, client?: WorkflowRunsClientOptions, options?: {
|
|
16
|
+
pollIntervalMs?: number;
|
|
17
|
+
}): import("@tanstack/react-query").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<import("./workflow-runs-client.js").WorkflowRunDetailResponse, Error, import("./workflow-runs-client.js").WorkflowRunDetailResponse, readonly ["voyant", "workflow-runs", "detail", string]>, "queryFn"> & {
|
|
18
|
+
queryFn?: import("@tanstack/react-query").QueryFunction<import("./workflow-runs-client.js").WorkflowRunDetailResponse, readonly ["voyant", "workflow-runs", "detail", string], never> | undefined;
|
|
19
|
+
} & {
|
|
20
|
+
queryKey: readonly ["voyant", "workflow-runs", "detail", string] & {
|
|
21
|
+
[dataTagSymbol]: import("./workflow-runs-client.js").WorkflowRunDetailResponse;
|
|
22
|
+
[dataTagErrorSymbol]: Error;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export declare function useWorkflowRuns(query?: ListWorkflowRunsQuery, options?: {
|
|
26
|
+
pollIntervalMs?: number;
|
|
27
|
+
}): import("@tanstack/react-query").UseQueryResult<import("./workflow-runs-client.js").ListWorkflowRunsResponse, Error>;
|
|
28
|
+
export declare function useWorkflowRun(id: string | null | undefined, options?: {
|
|
29
|
+
pollIntervalMs?: number;
|
|
30
|
+
}): import("@tanstack/react-query").UseQueryResult<import("./workflow-runs-client.js").WorkflowRunDetailResponse, Error>;
|
|
31
|
+
export declare function useRerunMutation(): import("@tanstack/react-query").UseMutationResult<import("./workflow-runs-client.js").WorkflowRunActionResult, Error, {
|
|
32
|
+
id: string;
|
|
33
|
+
confirm?: boolean;
|
|
34
|
+
}, unknown>;
|
|
35
|
+
export declare function useResumeMutation(): import("@tanstack/react-query").UseMutationResult<import("./workflow-runs-client.js").WorkflowRunActionResult, Error, string, unknown>;
|
|
36
|
+
//# sourceMappingURL=workflow-runs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow-runs.d.ts","sourceRoot":"","sources":["../src/workflow-runs.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB,KAAK,aAAa,EAClB,KAAK,uBAAuB,EAC5B,mBAAmB,EACnB,KAAK,wBAAwB,EAC9B,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAGL,KAAK,qBAAqB,EAI1B,KAAK,yBAAyB,EAG/B,MAAM,2BAA2B,CAAA;AAElC,cAAc,2BAA2B,CAAA;AACzC,OAAO,EACL,cAAc,EACd,qBAAqB,IAAI,yBAAyB,EAClD,KAAK,aAAa,EAClB,KAAK,uBAAuB,IAAI,2BAA2B,EAC3D,mBAAmB,IAAI,uBAAuB,EAC9C,KAAK,wBAAwB,IAAI,4BAA4B,GAC9D,CAAA;AAED,wBAAgB,2BAA2B,CACzC,KAAK,GAAE,qBAA0B,EACjC,MAAM,GAAE,yBAA6D,EACrE,OAAO,GAAE;IAAE,cAAc,CAAC,EAAE,MAAM,CAAA;CAAO;;;;;;;EAa1C;AAED,wBAAgB,0BAA0B,CACxC,EAAE,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAC7B,MAAM,GAAE,yBAA6D,EACrE,OAAO,GAAE;IAAE,cAAc,CAAC,EAAE,MAAM,CAAA;CAAO;;;;;;;EAe1C;AAED,wBAAgB,eAAe,CAC7B,KAAK,GAAE,qBAA0B,EACjC,OAAO,GAAE;IAAE,cAAc,CAAC,EAAE,MAAM,CAAA;CAAO,uHAI1C;AAED,wBAAgB,cAAc,CAC5B,EAAE,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAC7B,OAAO,GAAE;IAAE,cAAc,CAAC,EAAE,MAAM,CAAA;CAAO,wHAI1C;AAED,wBAAgB,gBAAgB;QAKF,MAAM;cAAY,OAAO;YAUtD;AAED,wBAAgB,iBAAiB,2IAehC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { queryOptions, useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
3
|
+
import { defaultFetcher, useVoyantReactContext, VoyantReactProvider, } from "@voyant-travel/react";
|
|
4
|
+
import { createWorkflowRunsClientOptions, getWorkflowRun, listWorkflowRuns, rerunWorkflowRun, resumeWorkflowRun, workflowRunIsTerminal, workflowRunsQueryKeys, } from "./workflow-runs-client.js";
|
|
5
|
+
export * from "./workflow-runs-client.js";
|
|
6
|
+
export { defaultFetcher, useVoyantReactContext as useVoyantWorkflowsContext, VoyantReactProvider as VoyantWorkflowsProvider, };
|
|
7
|
+
export function getWorkflowRunsQueryOptions(query = {}, client = createWorkflowRunsClientOptions(), options = {}) {
|
|
8
|
+
const pollIntervalMs = options.pollIntervalMs ?? 5000;
|
|
9
|
+
return queryOptions({
|
|
10
|
+
queryKey: workflowRunsQueryKeys.list(query),
|
|
11
|
+
queryFn: () => listWorkflowRuns(query, client),
|
|
12
|
+
refetchInterval: (queryState) => {
|
|
13
|
+
const data = queryState.state.data;
|
|
14
|
+
return data?.data.some((run) => !workflowRunIsTerminal(run.status)) ? pollIntervalMs : false;
|
|
15
|
+
},
|
|
16
|
+
refetchIntervalInBackground: false,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
export function getWorkflowRunQueryOptions(id, client = createWorkflowRunsClientOptions(), options = {}) {
|
|
20
|
+
const pollIntervalMs = options.pollIntervalMs ?? 2000;
|
|
21
|
+
const runId = id ?? "";
|
|
22
|
+
return queryOptions({
|
|
23
|
+
queryKey: workflowRunsQueryKeys.detail(runId),
|
|
24
|
+
queryFn: () => getWorkflowRun(runId, client),
|
|
25
|
+
enabled: Boolean(runId),
|
|
26
|
+
refetchInterval: (queryState) => {
|
|
27
|
+
const run = queryState.state.data?.data.run;
|
|
28
|
+
return run && !workflowRunIsTerminal(run.status) ? pollIntervalMs : false;
|
|
29
|
+
},
|
|
30
|
+
refetchIntervalInBackground: false,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
export function useWorkflowRuns(query = {}, options = {}) {
|
|
34
|
+
const client = useVoyantReactContext();
|
|
35
|
+
return useQuery(getWorkflowRunsQueryOptions(query, client, options));
|
|
36
|
+
}
|
|
37
|
+
export function useWorkflowRun(id, options = {}) {
|
|
38
|
+
const client = useVoyantReactContext();
|
|
39
|
+
return useQuery(getWorkflowRunQueryOptions(id, client, options));
|
|
40
|
+
}
|
|
41
|
+
export function useRerunMutation() {
|
|
42
|
+
const queryClient = useQueryClient();
|
|
43
|
+
const client = useVoyantReactContext();
|
|
44
|
+
return useMutation({
|
|
45
|
+
mutationFn: (input) => rerunWorkflowRun(input, client),
|
|
46
|
+
onSuccess: (result) => {
|
|
47
|
+
void queryClient.invalidateQueries({ queryKey: workflowRunsQueryKeys.all });
|
|
48
|
+
if (result.ok) {
|
|
49
|
+
void queryClient.invalidateQueries({
|
|
50
|
+
queryKey: workflowRunsQueryKeys.detail(result.data.parentRunId),
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
export function useResumeMutation() {
|
|
57
|
+
const queryClient = useQueryClient();
|
|
58
|
+
const client = useVoyantReactContext();
|
|
59
|
+
return useMutation({
|
|
60
|
+
mutationFn: (id) => resumeWorkflowRun(id, client),
|
|
61
|
+
onSuccess: (result) => {
|
|
62
|
+
void queryClient.invalidateQueries({ queryKey: workflowRunsQueryKeys.all });
|
|
63
|
+
if (result.ok) {
|
|
64
|
+
void queryClient.invalidateQueries({
|
|
65
|
+
queryKey: workflowRunsQueryKeys.detail(result.data.parentRunId),
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
export interface WorkflowScheduleDecl {
|
|
2
|
+
cron?: string;
|
|
3
|
+
every?: string | number;
|
|
4
|
+
at?: string;
|
|
5
|
+
timezone?: string;
|
|
6
|
+
enabled?: boolean;
|
|
7
|
+
overlap?: "skip" | "queue" | "allow";
|
|
8
|
+
environments?: ("production" | "preview" | "development")[];
|
|
9
|
+
name?: string;
|
|
10
|
+
input?: unknown;
|
|
11
|
+
}
|
|
12
|
+
export interface WorkflowScheduleSummary {
|
|
13
|
+
workflowId: string;
|
|
14
|
+
scheduleId: string;
|
|
15
|
+
schedule: WorkflowScheduleDecl;
|
|
16
|
+
/** Epoch millis of the next computed fire, or null when undecidable. */
|
|
17
|
+
nextRunAt: number | null;
|
|
18
|
+
enabled: boolean;
|
|
19
|
+
disabledReason?: "registration_disabled" | "env_filtered";
|
|
20
|
+
/** Epoch millis of the last scheduler dispatch attempt, when known. */
|
|
21
|
+
lastFireAt?: number | null;
|
|
22
|
+
/** Run id produced by the last scheduler dispatch attempt, when known. */
|
|
23
|
+
lastRunId?: string | null;
|
|
24
|
+
/** Last scheduler dispatch/lock error, when known. */
|
|
25
|
+
lastError?: string | null;
|
|
26
|
+
/** Epoch millis until which this schedule is locked, when known. */
|
|
27
|
+
lockedUntil?: number | null;
|
|
28
|
+
/** Epoch millis of the last successful scheduled run, when known. */
|
|
29
|
+
lastSuccessfulRunAt?: number | null;
|
|
30
|
+
/** Epoch millis when the persisted scheduler state was last updated. */
|
|
31
|
+
stateUpdatedAt?: number | null;
|
|
32
|
+
}
|
|
33
|
+
export interface ListWorkflowSchedulesResponse {
|
|
34
|
+
environment: string;
|
|
35
|
+
versionId: string;
|
|
36
|
+
schedulesEnabledByEnv?: boolean;
|
|
37
|
+
data: WorkflowScheduleSummary[];
|
|
38
|
+
}
|
|
39
|
+
export interface WorkflowSchedulesApi {
|
|
40
|
+
listSchedules(environment: string): Promise<ListWorkflowSchedulesResponse>;
|
|
41
|
+
}
|
|
42
|
+
export type WorkflowSchedulesFetcher = (input: string, init?: RequestInit) => Promise<Response>;
|
|
43
|
+
export interface WorkflowSchedulesApiClientOptions {
|
|
44
|
+
/** Base URL for the orchestrator. Defaults to the current origin. */
|
|
45
|
+
apiBase?: string;
|
|
46
|
+
baseUrl?: string;
|
|
47
|
+
fetcher?: WorkflowSchedulesFetcher;
|
|
48
|
+
credentials?: RequestCredentials;
|
|
49
|
+
headers?: HeadersInit;
|
|
50
|
+
}
|
|
51
|
+
export interface WorkflowSchedulesClientOptions {
|
|
52
|
+
baseUrl: string;
|
|
53
|
+
fetcher: WorkflowSchedulesFetcher;
|
|
54
|
+
credentials?: RequestCredentials;
|
|
55
|
+
headers?: HeadersInit;
|
|
56
|
+
}
|
|
57
|
+
export declare class WorkflowSchedulesApiError extends Error {
|
|
58
|
+
readonly status: number;
|
|
59
|
+
readonly body: unknown;
|
|
60
|
+
constructor(message: string, status: number, body: unknown);
|
|
61
|
+
}
|
|
62
|
+
export declare const defaultWorkflowSchedulesFetcher: WorkflowSchedulesFetcher;
|
|
63
|
+
export declare const workflowSchedulesQueryKeys: {
|
|
64
|
+
readonly all: readonly ["voyant", "workflow-schedules"];
|
|
65
|
+
readonly list: (environment: string) => readonly ["voyant", "workflow-schedules", "list", string];
|
|
66
|
+
};
|
|
67
|
+
export declare function createWorkflowSchedulesClientOptions(client?: Partial<WorkflowSchedulesClientOptions>): WorkflowSchedulesClientOptions;
|
|
68
|
+
export declare function createWorkflowSchedulesApiClient(options?: WorkflowSchedulesApiClientOptions): WorkflowSchedulesApi;
|
|
69
|
+
export declare function listWorkflowSchedules(environment: string, client?: WorkflowSchedulesClientOptions): Promise<ListWorkflowSchedulesResponse>;
|
|
70
|
+
//# sourceMappingURL=workflow-schedules-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow-schedules-client.d.ts","sourceRoot":"","sources":["../src/workflow-schedules-client.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,oBAAoB;IACnC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACvB,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,OAAO,CAAA;IACpC,YAAY,CAAC,EAAE,CAAC,YAAY,GAAG,SAAS,GAAG,aAAa,CAAC,EAAE,CAAA;IAC3D,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,OA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,EAAE,kBAAkB,CAAA;IAChC,OAAO,CAAC,EAAE,WAAW,CAAA;CACtB;AAED,MAAM,WAAW,8BAA8B;IAC7C,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,wBAAwB,CAAA;IACjC,WAAW,CAAC,EAAE,kBAAkB,CAAA;IAChC,OAAO,CAAC,EAAE,WAAW,CAAA;CACtB;AAED,qBAAa,yBAA0B,SAAQ,KAAK;IAClD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;gBAEV,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO;CAM3D;AAED,eAAO,MAAM,+BAA+B,EAAE,wBAC1B,CAAA;AAEpB,eAAO,MAAM,0BAA0B;;iCAEjB,MAAM;CAClB,CAAA;AAEV,wBAAgB,oCAAoC,CAClD,MAAM,CAAC,EAAE,OAAO,CAAC,8BAA8B,CAAC,GAC/C,8BAA8B,CAOhC;AAED,wBAAgB,gCAAgC,CAC9C,OAAO,GAAE,iCAAsC,GAC9C,oBAAoB,CAWtB;AAED,wBAAsB,qBAAqB,CACzC,WAAW,EAAE,MAAM,EACnB,MAAM,GAAE,8BAAuE,GAC9E,OAAO,CAAC,6BAA6B,CAAC,CAYxC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// Client for the orchestrator's `/api/schedules/:env` aggregate view.
|
|
2
|
+
// Mirrors `workflow-runs-client.ts` so the workflow-schedules UI can be
|
|
3
|
+
// pointed at any worker that exposes `@voyant-travel/workflows-orchestrator-cloudflare`'s
|
|
4
|
+
// schedules handler.
|
|
5
|
+
export class WorkflowSchedulesApiError extends Error {
|
|
6
|
+
status;
|
|
7
|
+
body;
|
|
8
|
+
constructor(message, status, body) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.name = "WorkflowSchedulesApiError";
|
|
11
|
+
this.status = status;
|
|
12
|
+
this.body = body;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export const defaultWorkflowSchedulesFetcher = (input, init) => fetch(input, init);
|
|
16
|
+
export const workflowSchedulesQueryKeys = {
|
|
17
|
+
all: ["voyant", "workflow-schedules"],
|
|
18
|
+
list: (environment) => [...workflowSchedulesQueryKeys.all, "list", environment],
|
|
19
|
+
};
|
|
20
|
+
export function createWorkflowSchedulesClientOptions(client) {
|
|
21
|
+
return {
|
|
22
|
+
baseUrl: client?.baseUrl ?? "",
|
|
23
|
+
fetcher: client?.fetcher ?? defaultWorkflowSchedulesFetcher,
|
|
24
|
+
credentials: client?.credentials,
|
|
25
|
+
headers: client?.headers,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export function createWorkflowSchedulesApiClient(options = {}) {
|
|
29
|
+
const client = createWorkflowSchedulesClientOptions({
|
|
30
|
+
baseUrl: options.baseUrl ?? options.apiBase ?? "",
|
|
31
|
+
fetcher: options.fetcher,
|
|
32
|
+
credentials: options.credentials ?? "include",
|
|
33
|
+
headers: options.headers,
|
|
34
|
+
});
|
|
35
|
+
return {
|
|
36
|
+
listSchedules: (environment) => listWorkflowSchedules(environment, client),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export async function listWorkflowSchedules(environment, client = createWorkflowSchedulesClientOptions()) {
|
|
40
|
+
const path = `/api/schedules/${encodeURIComponent(environment)}`;
|
|
41
|
+
const response = await request(path, { method: "GET" }, client);
|
|
42
|
+
const body = await safeJson(response);
|
|
43
|
+
if (!response.ok) {
|
|
44
|
+
throw new WorkflowSchedulesApiError(extractErrorMessage(response.status, response.statusText, body), response.status, body);
|
|
45
|
+
}
|
|
46
|
+
return body;
|
|
47
|
+
}
|
|
48
|
+
async function request(path, init, client) {
|
|
49
|
+
const headers = new Headers(client.headers);
|
|
50
|
+
for (const [key, value] of new Headers(init.headers).entries()) {
|
|
51
|
+
headers.set(key, value);
|
|
52
|
+
}
|
|
53
|
+
const requestInit = { ...init, headers };
|
|
54
|
+
if (client.credentials !== undefined) {
|
|
55
|
+
requestInit.credentials = client.credentials;
|
|
56
|
+
}
|
|
57
|
+
return client.fetcher(joinUrl(client.baseUrl, path), requestInit);
|
|
58
|
+
}
|
|
59
|
+
async function safeJson(response) {
|
|
60
|
+
const text = await response.text();
|
|
61
|
+
if (!text)
|
|
62
|
+
return undefined;
|
|
63
|
+
try {
|
|
64
|
+
return JSON.parse(text);
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return text;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function extractErrorMessage(status, statusText, body) {
|
|
71
|
+
if (typeof body === "object" && body !== null) {
|
|
72
|
+
if ("error" in body && typeof body.error === "string")
|
|
73
|
+
return body.error;
|
|
74
|
+
if ("message" in body && typeof body.message === "string")
|
|
75
|
+
return body.message;
|
|
76
|
+
}
|
|
77
|
+
return `Workflow schedules API error: ${status} ${statusText}`;
|
|
78
|
+
}
|
|
79
|
+
function joinUrl(baseUrl, path) {
|
|
80
|
+
const resolved = resolveBaseUrl(baseUrl);
|
|
81
|
+
const trimmedBase = resolved.endsWith("/") ? resolved.slice(0, -1) : resolved;
|
|
82
|
+
const trimmedPath = path.startsWith("/") ? path : `/${path}`;
|
|
83
|
+
return `${trimmedBase}${trimmedPath}`;
|
|
84
|
+
}
|
|
85
|
+
function resolveBaseUrl(baseUrl) {
|
|
86
|
+
if (baseUrl.trim())
|
|
87
|
+
return baseUrl;
|
|
88
|
+
if (typeof window !== "undefined")
|
|
89
|
+
return window.location.origin;
|
|
90
|
+
return "http://localhost:8787";
|
|
91
|
+
}
|