windmill-client 1.618.2 → 1.618.4

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,413 @@
1
+ import { DenoS3LightClientSettings, S3ObjectRecord, type S3Object } from "./s3Types";
2
+ export { type S3Object, type S3ObjectRecord, type S3ObjectURI, } from "./s3Types";
3
+ export { datatable, ducklake, type SqlTemplateFunction, type DatatableSqlTemplateFunction, } from "./sqlUtils";
4
+ export type Sql = string;
5
+ export type Email = string;
6
+ export type Base64 = string;
7
+ export type Resource<S extends string> = any;
8
+ export declare const SHARED_FOLDER = "/shared";
9
+ /**
10
+ * Initialize the Windmill client with authentication token and base URL
11
+ * @param token - Authentication token (defaults to WM_TOKEN env variable)
12
+ * @param baseUrl - API base URL (defaults to BASE_INTERNAL_URL or BASE_URL env variable)
13
+ */
14
+ export declare function setClient(token?: string, baseUrl?: string): void;
15
+ /**
16
+ * Create a client configuration from env variables
17
+ * @returns client configuration
18
+ */
19
+ export declare function getWorkspace(): string;
20
+ /**
21
+ * Get a resource value by path
22
+ * @param path path of the resource, default to internal state path
23
+ * @param undefinedIfEmpty if the resource does not exist, return undefined instead of throwing an error
24
+ * @returns resource value
25
+ */
26
+ export declare function getResource(path?: string, undefinedIfEmpty?: boolean): Promise<any>;
27
+ /**
28
+ * Get the true root job id
29
+ * @param jobId job id to get the root job id from (default to current job)
30
+ * @returns root job id
31
+ */
32
+ export declare function getRootJobId(jobId?: string): Promise<string>;
33
+ /**
34
+ * @deprecated Use runScriptByPath or runScriptByHash instead
35
+ */
36
+ export declare function runScript(path?: string | null, hash_?: string | null, args?: Record<string, any> | null, verbose?: boolean): Promise<any>;
37
+ /**
38
+ * Run a script synchronously by its path and wait for the result
39
+ * @param path - Script path in Windmill
40
+ * @param args - Arguments to pass to the script
41
+ * @param verbose - Enable verbose logging
42
+ * @returns Script execution result
43
+ */
44
+ export declare function runScriptByPath(path: string, args?: Record<string, any> | null, verbose?: boolean): Promise<any>;
45
+ /**
46
+ * Run a script synchronously by its hash and wait for the result
47
+ * @param hash_ - Script hash in Windmill
48
+ * @param args - Arguments to pass to the script
49
+ * @param verbose - Enable verbose logging
50
+ * @returns Script execution result
51
+ */
52
+ export declare function runScriptByHash(hash_: string, args?: Record<string, any> | null, verbose?: boolean): Promise<any>;
53
+ /**
54
+ * Append a text to the result stream
55
+ * @param text text to append to the result stream
56
+ */
57
+ export declare function appendToResultStream(text: string): void;
58
+ /**
59
+ * Stream to the result stream
60
+ * @param stream stream to stream to the result stream
61
+ */
62
+ export declare function streamResult(stream: AsyncIterable<string>): Promise<void>;
63
+ /**
64
+ * Run a flow synchronously by its path and wait for the result
65
+ * @param path - Flow path in Windmill
66
+ * @param args - Arguments to pass to the flow
67
+ * @param verbose - Enable verbose logging
68
+ * @returns Flow execution result
69
+ */
70
+ export declare function runFlow(path?: string | null, args?: Record<string, any> | null, verbose?: boolean): Promise<any>;
71
+ /**
72
+ * Wait for a job to complete and return its result
73
+ * @param jobId - ID of the job to wait for
74
+ * @param verbose - Enable verbose logging
75
+ * @returns Job result when completed
76
+ */
77
+ export declare function waitJob(jobId: string, verbose?: boolean): Promise<any>;
78
+ /**
79
+ * Get the result of a completed job
80
+ * @param jobId - ID of the completed job
81
+ * @returns Job result
82
+ */
83
+ export declare function getResult(jobId: string): Promise<any>;
84
+ /**
85
+ * Get the result of a job if completed, or its current status
86
+ * @param jobId - ID of the job
87
+ * @returns Object with started, completed, success, and result properties
88
+ */
89
+ export declare function getResultMaybe(jobId: string): Promise<any>;
90
+ /**
91
+ * Wrap a function to execute as a Windmill task within a flow context
92
+ * @param f - Function to wrap as a task
93
+ * @returns Async wrapper function that executes as a Windmill job
94
+ */
95
+ export declare function task<P, T>(f: (_: P) => T): (_: P) => Promise<T>;
96
+ /**
97
+ * @deprecated Use runScriptByPathAsync or runScriptByHashAsync instead
98
+ */
99
+ export declare function runScriptAsync(path: string | null, hash_: string | null, args: Record<string, any> | null, scheduledInSeconds?: number | null): Promise<string>;
100
+ /**
101
+ * Run a script asynchronously by its path
102
+ * @param path - Script path in Windmill
103
+ * @param args - Arguments to pass to the script
104
+ * @param scheduledInSeconds - Schedule execution for a future time (in seconds)
105
+ * @returns Job ID of the created job
106
+ */
107
+ export declare function runScriptByPathAsync(path: string, args?: Record<string, any> | null, scheduledInSeconds?: number | null): Promise<string>;
108
+ /**
109
+ * Run a script asynchronously by its hash
110
+ * @param hash_ - Script hash in Windmill
111
+ * @param args - Arguments to pass to the script
112
+ * @param scheduledInSeconds - Schedule execution for a future time (in seconds)
113
+ * @returns Job ID of the created job
114
+ */
115
+ export declare function runScriptByHashAsync(hash_: string, args?: Record<string, any> | null, scheduledInSeconds?: number | null): Promise<string>;
116
+ /**
117
+ * Run a flow asynchronously by its path
118
+ * @param path - Flow path in Windmill
119
+ * @param args - Arguments to pass to the flow
120
+ * @param scheduledInSeconds - Schedule execution for a future time (in seconds)
121
+ * @param doNotTrackInParent - If false, tracks state in parent job (only use when fully awaiting the job)
122
+ * @returns Job ID of the created job
123
+ */
124
+ export declare function runFlowAsync(path: string | null, args: Record<string, any> | null, scheduledInSeconds?: number | null, doNotTrackInParent?: boolean): Promise<string>;
125
+ /**
126
+ * Resolve a resource value in case the default value was picked because the input payload was undefined
127
+ * @param obj resource value or path of the resource under the format `$res:path`
128
+ * @returns resource value
129
+ */
130
+ export declare function resolveDefaultResource(obj: any): Promise<any>;
131
+ /**
132
+ * Get the state file path from environment variables
133
+ * @returns State path string
134
+ */
135
+ export declare function getStatePath(): string;
136
+ /**
137
+ * Set a resource value by path
138
+ * @param path path of the resource to set, default to state path
139
+ * @param value new value of the resource to set
140
+ * @param initializeToTypeIfNotExist if the resource does not exist, initialize it with this type
141
+ */
142
+ export declare function setResource(value: any, path?: string, initializeToTypeIfNotExist?: string): Promise<void>;
143
+ /**
144
+ * Set the state
145
+ * @param state state to set
146
+ * @deprecated use setState instead
147
+ */
148
+ export declare function setInternalState(state: any): Promise<void>;
149
+ /**
150
+ * Set the state
151
+ * @param state state to set
152
+ * @param path Optional state resource path override. Defaults to `getStatePath()`.
153
+ */
154
+ export declare function setState(state: any, path?: string): Promise<void>;
155
+ /**
156
+ * Set the progress
157
+ * Progress cannot go back and limited to 0% to 99% range
158
+ * @param percent Progress to set in %
159
+ * @param jobId? Job to set progress for
160
+ */
161
+ export declare function setProgress(percent: number, jobId?: any): Promise<void>;
162
+ /**
163
+ * Get the progress
164
+ * @param jobId? Job to get progress from
165
+ * @returns Optional clamped between 0 and 100 progress value
166
+ */
167
+ export declare function getProgress(jobId?: any): Promise<number | null>;
168
+ /**
169
+ * Set a flow user state
170
+ * @param key key of the state
171
+ * @param value value of the state
172
+
173
+ */
174
+ export declare function setFlowUserState(key: string, value: any, errorIfNotPossible?: boolean): Promise<void>;
175
+ /**
176
+ * Get a flow user state
177
+ * @param path path of the variable
178
+
179
+ */
180
+ export declare function getFlowUserState(key: string, errorIfNotPossible?: boolean): Promise<any>;
181
+ /**
182
+ * Get the internal state
183
+ * @deprecated use getState instead
184
+ */
185
+ export declare function getInternalState(): Promise<any>;
186
+ /**
187
+ * Get the state shared across executions
188
+ * @param path Optional state resource path override. Defaults to `getStatePath()`.
189
+ */
190
+ export declare function getState(path?: string): Promise<any>;
191
+ /**
192
+ * Get a variable by path
193
+ * @param path path of the variable
194
+ * @returns variable value
195
+ */
196
+ export declare function getVariable(path: string): Promise<string>;
197
+ /**
198
+ * Set a variable by path, create if not exist
199
+ * @param path path of the variable
200
+ * @param value value of the variable
201
+ * @param isSecretIfNotExist if the variable does not exist, create it as secret or not (default: false)
202
+ * @param descriptionIfNotExist if the variable does not exist, create it with this description (default: "")
203
+ */
204
+ export declare function setVariable(path: string, value: string, isSecretIfNotExist?: boolean, descriptionIfNotExist?: string): Promise<void>;
205
+ /**
206
+ * Build a PostgreSQL connection URL from a database resource
207
+ * @param path - Path to the database resource
208
+ * @returns PostgreSQL connection URL string
209
+ */
210
+ export declare function databaseUrlFromResource(path: string): Promise<string>;
211
+ /**
212
+ * Get S3 client settings from a resource or workspace default
213
+ * @param s3_resource_path - Path to S3 resource (uses workspace default if undefined)
214
+ * @returns S3 client configuration settings
215
+ */
216
+ export declare function denoS3LightClientSettings(s3_resource_path: string | undefined): Promise<DenoS3LightClientSettings>;
217
+ /**
218
+ * Load the content of a file stored in S3. If the s3ResourcePath is undefined, it will default to the workspace S3 resource.
219
+ *
220
+ * ```typescript
221
+ * let fileContent = await wmill.loadS3FileContent(inputFile)
222
+ * // if the file is a raw text file, it can be decoded and printed directly:
223
+ * const text = new TextDecoder().decode(fileContentStream)
224
+ * console.log(text);
225
+ * ```
226
+ */
227
+ export declare function loadS3File(s3object: S3Object, s3ResourcePath?: string | undefined): Promise<Uint8Array | undefined>;
228
+ /**
229
+ * Load the content of a file stored in S3 as a stream. If the s3ResourcePath is undefined, it will default to the workspace S3 resource.
230
+ *
231
+ * ```typescript
232
+ * let fileContentBlob = await wmill.loadS3FileStream(inputFile)
233
+ * // if the content is plain text, the blob can be read directly:
234
+ * console.log(await fileContentBlob.text());
235
+ * ```
236
+ */
237
+ export declare function loadS3FileStream(s3object: S3Object, s3ResourcePath?: string | undefined): Promise<Blob | undefined>;
238
+ /**
239
+ * Persist a file to the S3 bucket. If the s3ResourcePath is undefined, it will default to the workspace S3 resource.
240
+ *
241
+ * ```typescript
242
+ * const s3object = await writeS3File(s3Object, "Hello Windmill!")
243
+ * const fileContentAsUtf8Str = (await s3object.toArray()).toString('utf-8')
244
+ * console.log(fileContentAsUtf8Str)
245
+ * ```
246
+ */
247
+ export declare function writeS3File(s3object: S3Object | undefined, fileContent: string | Blob, s3ResourcePath?: string | undefined, contentType?: string | undefined, contentDisposition?: string | undefined): Promise<S3Object>;
248
+ /**
249
+ * Sign S3 objects to be used by anonymous users in public apps
250
+ * @param s3objects s3 objects to sign
251
+ * @returns signed s3 objects
252
+ */
253
+ export declare function signS3Objects(s3objects: S3Object[]): Promise<S3Object[]>;
254
+ /**
255
+ * Sign S3 object to be used by anonymous users in public apps
256
+ * @param s3object s3 object to sign
257
+ * @returns signed s3 object
258
+ */
259
+ export declare function signS3Object(s3object: S3Object): Promise<S3Object>;
260
+ /**
261
+ * Generate a presigned public URL for an array of S3 objects.
262
+ * If an S3 object is not signed yet, it will be signed first.
263
+ * @param s3Objects s3 objects to sign
264
+ * @returns list of signed public URLs
265
+ */
266
+ export declare function getPresignedS3PublicUrls(s3Objects: S3Object[], { baseUrl }?: {
267
+ baseUrl?: string;
268
+ }): Promise<string[]>;
269
+ /**
270
+ * Generate a presigned public URL for an S3 object. If the S3 object is not signed yet, it will be signed first.
271
+ * @param s3Object s3 object to sign
272
+ * @returns signed public URL
273
+ */
274
+ export declare function getPresignedS3PublicUrl(s3Objects: S3Object, { baseUrl }?: {
275
+ baseUrl?: string;
276
+ }): Promise<string>;
277
+ /**
278
+ * Get URLs needed for resuming a flow after this step
279
+ * @param approver approver name
280
+ * @param flowLevel if true, generate resume URLs for the parent flow instead of the specific step.
281
+ * This allows pre-approvals that can be consumed by any later suspend step in the same flow.
282
+ * @returns approval page UI URL, resume and cancel API URLs for resuming the flow
283
+ */
284
+ export declare function getResumeUrls(approver?: string, flowLevel?: boolean): Promise<{
285
+ approvalPage: string;
286
+ resume: string;
287
+ cancel: string;
288
+ }>;
289
+ /**
290
+ * @deprecated use getResumeUrls instead
291
+ */
292
+ export declare function getResumeEndpoints(approver?: string): Promise<{
293
+ approvalPage: string;
294
+ resume: string;
295
+ cancel: string;
296
+ }>;
297
+ /**
298
+ * Get an OIDC jwt token for auth to external services (e.g: Vault, AWS) (ee only)
299
+ * @param audience audience of the token
300
+ * @param expiresIn Optional number of seconds until the token expires
301
+ * @returns jwt token
302
+ */
303
+ export declare function getIdToken(audience: string, expiresIn?: number): Promise<string>;
304
+ /**
305
+ * Convert a base64-encoded string to Uint8Array
306
+ * @param data - Base64-encoded string
307
+ * @returns Decoded Uint8Array
308
+ */
309
+ export declare function base64ToUint8Array(data: string): Uint8Array;
310
+ /**
311
+ * Convert a Uint8Array to base64-encoded string
312
+ * @param arrayBuffer - Uint8Array to encode
313
+ * @returns Base64-encoded string
314
+ */
315
+ export declare function uint8ArrayToBase64(arrayBuffer: Uint8Array): string;
316
+ /**
317
+ * Get email from workspace username
318
+ * This method is particularly useful for apps that require the email address of the viewer.
319
+ * Indeed, in the viewer context, WM_USERNAME is set to the username of the viewer but WM_EMAIL is set to the email of the creator of the app.
320
+ * @param username
321
+ * @returns email address
322
+ */
323
+ export declare function usernameToEmail(username: string): Promise<string>;
324
+ interface SlackApprovalOptions {
325
+ slackResourcePath: string;
326
+ channelId: string;
327
+ message?: string;
328
+ approver?: string;
329
+ defaultArgsJson?: Record<string, any>;
330
+ dynamicEnumsJson?: Record<string, any>;
331
+ }
332
+ interface TeamsApprovalOptions {
333
+ teamName: string;
334
+ channelName: string;
335
+ message?: string;
336
+ approver?: string;
337
+ defaultArgsJson?: Record<string, any>;
338
+ dynamicEnumsJson?: Record<string, any>;
339
+ }
340
+ /**
341
+ * Sends an interactive approval request via Slack, allowing optional customization of the message, approver, and form fields.
342
+ *
343
+ * **[Enterprise Edition Only]** To include form fields in the Slack approval request, go to **Advanced -> Suspend -> Form**
344
+ * and define a form. Learn more at [Windmill Documentation](https://www.windmill.dev/docs/flows/flow_approval#form).
345
+ *
346
+ * @param {Object} options - The configuration options for the Slack approval request.
347
+ * @param {string} options.slackResourcePath - The path to the Slack resource in Windmill.
348
+ * @param {string} options.channelId - The Slack channel ID where the approval request will be sent.
349
+ * @param {string} [options.message] - Optional custom message to include in the Slack approval request.
350
+ * @param {string} [options.approver] - Optional user ID or name of the approver for the request.
351
+ * @param {DefaultArgs} [options.defaultArgsJson] - Optional object defining or overriding the default arguments to a form field.
352
+ * @param {Enums} [options.dynamicEnumsJson] - Optional object overriding the enum default values of an enum form field.
353
+ *
354
+ * @returns {Promise<void>} Resolves when the Slack approval request is successfully sent.
355
+ *
356
+ * @throws {Error} If the function is not called within a flow or flow preview.
357
+ * @throws {Error} If the `JobService.getSlackApprovalPayload` call fails.
358
+ *
359
+ * **Usage Example:**
360
+ * ```typescript
361
+ * await requestInteractiveSlackApproval({
362
+ * slackResourcePath: "/u/alex/my_slack_resource",
363
+ * channelId: "admins-slack-channel",
364
+ * message: "Please approve this request",
365
+ * approver: "approver123",
366
+ * defaultArgsJson: { key1: "value1", key2: 42 },
367
+ * dynamicEnumsJson: { foo: ["choice1", "choice2"], bar: ["optionA", "optionB"] },
368
+ * });
369
+ * ```
370
+ *
371
+ * **Note:** This function requires execution within a Windmill flow or flow preview.
372
+ */
373
+ export declare function requestInteractiveSlackApproval({ slackResourcePath, channelId, message, approver, defaultArgsJson, dynamicEnumsJson, }: SlackApprovalOptions): Promise<void>;
374
+ /**
375
+ * Sends an interactive approval request via Teams, allowing optional customization of the message, approver, and form fields.
376
+ *
377
+ * **[Enterprise Edition Only]** To include form fields in the Teams approval request, go to **Advanced -> Suspend -> Form**
378
+ * and define a form. Learn more at [Windmill Documentation](https://www.windmill.dev/docs/flows/flow_approval#form).
379
+ *
380
+ * @param {Object} options - The configuration options for the Teams approval request.
381
+ * @param {string} options.teamName - The Teams team name where the approval request will be sent.
382
+ * @param {string} options.channelName - The Teams channel name where the approval request will be sent.
383
+ * @param {string} [options.message] - Optional custom message to include in the Teams approval request.
384
+ * @param {string} [options.approver] - Optional user ID or name of the approver for the request.
385
+ * @param {DefaultArgs} [options.defaultArgsJson] - Optional object defining or overriding the default arguments to a form field.
386
+ * @param {Enums} [options.dynamicEnumsJson] - Optional object overriding the enum default values of an enum form field.
387
+ *
388
+ * @returns {Promise<void>} Resolves when the Teams approval request is successfully sent.
389
+ *
390
+ * @throws {Error} If the function is not called within a flow or flow preview.
391
+ * @throws {Error} If the `JobService.getTeamsApprovalPayload` call fails.
392
+ *
393
+ * **Usage Example:**
394
+ * ```typescript
395
+ * await requestInteractiveTeamsApproval({
396
+ * teamName: "admins-teams",
397
+ * channelName: "admins-teams-channel",
398
+ * message: "Please approve this request",
399
+ * approver: "approver123",
400
+ * defaultArgsJson: { key1: "value1", key2: 42 },
401
+ * dynamicEnumsJson: { foo: ["choice1", "choice2"], bar: ["optionA", "optionB"] },
402
+ * });
403
+ * ```
404
+ *
405
+ * **Note:** This function requires execution within a Windmill flow or flow preview.
406
+ */
407
+ export declare function requestInteractiveTeamsApproval({ teamName, channelName, message, approver, defaultArgsJson, dynamicEnumsJson, }: TeamsApprovalOptions): Promise<void>;
408
+ /**
409
+ * Parse an S3 object from URI string or record format
410
+ * @param s3Object - S3 object as URI string (s3://storage/key) or record
411
+ * @returns S3 object record with storage and s3 key
412
+ */
413
+ export declare function parseS3Object(s3Object: S3Object): S3ObjectRecord;