@refoldai/refold-js 10.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 (53) hide show
  1. package/.claude/skills/method/SKILL.md +282 -0
  2. package/.claude/skills/review-pr/SKILL.md +80 -0
  3. package/.claude/skills/style/SKILL.md +67 -0
  4. package/.claude/skills/verify/SKILL.md +85 -0
  5. package/.github/pull_request_template.md +48 -0
  6. package/.github/workflows/npm-publish.yml +35 -0
  7. package/.github/workflows/pr-validation.yml +224 -0
  8. package/CLAUDE.md +127 -0
  9. package/LICENSE +21 -0
  10. package/README.md +63 -0
  11. package/docs/.nojekyll +1 -0
  12. package/docs/assets/hierarchy.js +1 -0
  13. package/docs/assets/highlight.css +113 -0
  14. package/docs/assets/icons.js +18 -0
  15. package/docs/assets/icons.svg +1 -0
  16. package/docs/assets/main.js +60 -0
  17. package/docs/assets/navigation.js +1 -0
  18. package/docs/assets/search.js +1 -0
  19. package/docs/assets/style.css +1633 -0
  20. package/docs/classes/Refold.html +123 -0
  21. package/docs/enums/AuthStatus.html +3 -0
  22. package/docs/enums/AuthType.html +4 -0
  23. package/docs/hierarchy.html +1 -0
  24. package/docs/index.html +36 -0
  25. package/docs/interfaces/Application.html +37 -0
  26. package/docs/interfaces/Config.html +6 -0
  27. package/docs/interfaces/ConfigField.html +17 -0
  28. package/docs/interfaces/ConfigPayload.html +8 -0
  29. package/docs/interfaces/ConfigWorkflow.html +6 -0
  30. package/docs/interfaces/ExecuteWorkflowPayload.html +9 -0
  31. package/docs/interfaces/Execution.html +19 -0
  32. package/docs/interfaces/ExecutionFilters.html +16 -0
  33. package/docs/interfaces/GetExecutionsParams.html +19 -0
  34. package/docs/interfaces/InputField.html +18 -0
  35. package/docs/interfaces/Label.html +6 -0
  36. package/docs/interfaces/PublicWorkflow.html +16 -0
  37. package/docs/interfaces/PublicWorkflowPayload.html +8 -0
  38. package/docs/interfaces/PublicWorkflowsPayload.html +15 -0
  39. package/docs/interfaces/RefoldOptions.html +5 -0
  40. package/docs/interfaces/RuleOptions.html +4 -0
  41. package/docs/interfaces/UpdateConfigPayload.html +10 -0
  42. package/docs/interfaces/WorkflowPayload.html +8 -0
  43. package/docs/interfaces/WorkflowPayloadResponse.html +4 -0
  44. package/docs/llms.txt +986 -0
  45. package/docs/modules.html +1 -0
  46. package/docs/types/ExecutionSource.html +2 -0
  47. package/docs/types/ExecutionStatus.html +2 -0
  48. package/docs/types/ExecutionType.html +2 -0
  49. package/package.json +38 -0
  50. package/refold.d.ts +556 -0
  51. package/refold.js +667 -0
  52. package/refold.ts +1044 -0
  53. package/tsconfig.json +12 -0
package/refold.js ADDED
@@ -0,0 +1,667 @@
1
+ "use strict";
2
+ /**
3
+ * Refold Frontend SDK
4
+ */
5
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
6
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
7
+ return new (P || (P = Promise))(function (resolve, reject) {
8
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
9
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
10
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
11
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
12
+ });
13
+ };
14
+ var __rest = (this && this.__rest) || function (s, e) {
15
+ var t = {};
16
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
17
+ t[p] = s[p];
18
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
19
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
20
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
21
+ t[p[i]] = s[p[i]];
22
+ }
23
+ return t;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.Refold = exports.AuthStatus = exports.AuthType = void 0;
27
+ var AuthType;
28
+ (function (AuthType) {
29
+ AuthType["OAuth2"] = "oauth2";
30
+ AuthType["KeyBased"] = "keybased";
31
+ })(AuthType || (exports.AuthType = AuthType = {}));
32
+ var AuthStatus;
33
+ (function (AuthStatus) {
34
+ AuthStatus["Active"] = "active";
35
+ AuthStatus["Expired"] = "expired";
36
+ })(AuthStatus || (exports.AuthStatus = AuthStatus = {}));
37
+ class Refold {
38
+ /**
39
+ * Refold Frontend SDK
40
+ * @param {Object} options The options to configure the Refold SDK.
41
+ * @param {String} [options.token] The session token.
42
+ * @param {String} [options.baseUrl=https://app.refold.ai] The base URL of the Refold API.
43
+ */
44
+ constructor(options = {}) {
45
+ this.baseUrl = options.baseUrl
46
+ ? /^https?:\/\//.test(options.baseUrl)
47
+ ? options.baseUrl
48
+ : "https://" + options.baseUrl
49
+ : "https://app.refold.ai";
50
+ this.token = options.token || "";
51
+ }
52
+ /**
53
+ * Returns the org & customer details for the associated token.
54
+ * @private
55
+ * @returns {Promise<unknown>}
56
+ */
57
+ getAccountDetails() {
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ const res = yield fetch(`${this.baseUrl}/api/v3/org/basics`, {
60
+ headers: {
61
+ authorization: `Bearer ${this.token}`,
62
+ },
63
+ });
64
+ if (res.status >= 400 && res.status < 600) {
65
+ const error = yield res.json();
66
+ throw error;
67
+ }
68
+ const data = yield res.json();
69
+ return data;
70
+ });
71
+ }
72
+ /**
73
+ * Returns the org & customer details for the associated token.
74
+ * @private
75
+ * @returns {Promise<unknown>}
76
+ */
77
+ updateAccount(payload) {
78
+ return __awaiter(this, void 0, void 0, function* () {
79
+ const res = yield fetch(`${this.baseUrl}/api/v2/public/linked-account`, {
80
+ method: "PUT",
81
+ headers: {
82
+ authorization: `Bearer ${this.token}`,
83
+ "content-type": "application/json",
84
+ },
85
+ body: JSON.stringify(Object.assign({}, payload)),
86
+ });
87
+ if (res.status >= 400 && res.status < 600) {
88
+ const error = yield res.json();
89
+ throw error;
90
+ }
91
+ const data = yield res.json();
92
+ return data;
93
+ });
94
+ }
95
+ /**
96
+ * Returns the application details for the specified application, provided
97
+ * the application is enabled in Refold. If no application is specified,
98
+ * it returns all the enabled applications.
99
+ * @param {String} [slug] The application slug.
100
+ * @returns {Promise<Application | Application[]>} The application details.
101
+ */
102
+ getApp(slug) {
103
+ return __awaiter(this, void 0, void 0, function* () {
104
+ const res = yield fetch(`${this.baseUrl}/api/v2/f-sdk/application${slug ? `/${slug}` : ""}`, {
105
+ headers: {
106
+ authorization: `Bearer ${this.token}`,
107
+ },
108
+ });
109
+ if (res.status >= 400 && res.status < 600) {
110
+ const error = yield res.json();
111
+ throw error;
112
+ }
113
+ const data = yield res.json();
114
+ return data;
115
+ });
116
+ }
117
+ /**
118
+ * Returns all the enabled apps.
119
+ * @returns {Promise<Application[]>} The list of applications.
120
+ */
121
+ getApps() {
122
+ return __awaiter(this, void 0, void 0, function* () {
123
+ const res = yield fetch(`${this.baseUrl}/api/v2/f-sdk/application`, {
124
+ headers: {
125
+ authorization: `Bearer ${this.token}`,
126
+ },
127
+ });
128
+ if (res.status >= 400 && res.status < 600) {
129
+ const error = yield res.json();
130
+ throw error;
131
+ }
132
+ const data = yield res.json();
133
+ return data;
134
+ });
135
+ }
136
+ /**
137
+ * Returns the auth URL that users can use to authenticate themselves to the
138
+ * specified application.
139
+ * @private
140
+ * @param {String} slug The application slug.
141
+ * @param {Object.<string, string>} [params] The key value pairs of auth data.
142
+ * @returns {Promise<String>} The auth URL where users can authenticate themselves.
143
+ */
144
+ getOAuthUrl(slug, params) {
145
+ return __awaiter(this, void 0, void 0, function* () {
146
+ const res = yield fetch(`${this.baseUrl}/api/v1/${slug}/integrate?${new URLSearchParams(params).toString()}`, {
147
+ headers: {
148
+ authorization: `Bearer ${this.token}`,
149
+ },
150
+ });
151
+ if (res.status >= 400 && res.status < 600) {
152
+ const error = yield res.json();
153
+ throw error;
154
+ }
155
+ const data = yield res.json();
156
+ return data.auth_url;
157
+ });
158
+ }
159
+ /**
160
+ * Handle OAuth for the specified application.
161
+ * @private
162
+ * @param {String} slug The application slug.
163
+ * @param {Object.<string, string>} [params] The key value pairs of auth data.
164
+ * @returns {Promise<Boolean>} Whether the user authenticated.
165
+ */
166
+ oauth(slug, params) {
167
+ return __awaiter(this, void 0, void 0, function* () {
168
+ return new Promise((resolve, reject) => {
169
+ this.getOAuthUrl(slug, params)
170
+ .then(oauthUrl => {
171
+ const connectWindow = window.open(oauthUrl);
172
+ // keep checking connection status
173
+ const interval = setInterval(() => {
174
+ this.getApp(slug)
175
+ .then(app => {
176
+ var _a;
177
+ if (app && ((_a = app.connected_accounts) === null || _a === void 0 ? void 0 : _a.filter(a => a.auth_type === AuthType.OAuth2).some(a => a.status === AuthStatus.Active))) {
178
+ // close auth window
179
+ connectWindow && connectWindow.close();
180
+ // clear interval
181
+ clearInterval(interval);
182
+ // resovle status
183
+ resolve(true);
184
+ }
185
+ else {
186
+ // user closed oauth window without authenticating
187
+ if (connectWindow && connectWindow.closed) {
188
+ // clear interval
189
+ clearInterval(interval);
190
+ // resolve status
191
+ resolve(false);
192
+ }
193
+ }
194
+ })
195
+ .catch(e => {
196
+ console.error(e);
197
+ // connectWindow?.close();
198
+ clearInterval(interval);
199
+ reject(e);
200
+ });
201
+ }, 3e3);
202
+ })
203
+ .catch(reject);
204
+ });
205
+ });
206
+ }
207
+ /**
208
+ * Save auth data for the specified keybased application.
209
+ * @param {String} slug The application slug.
210
+ * @param {Object.<string, string>} [payload] The key value pairs of auth data.
211
+ * @returns {Promise<Boolean>} Whether the auth data was saved successfully.
212
+ */
213
+ keybased(slug, payload) {
214
+ return __awaiter(this, void 0, void 0, function* () {
215
+ const res = yield fetch(`${this.baseUrl}/api/v2/app/${slug}/save`, {
216
+ method: "POST",
217
+ headers: {
218
+ authorization: `Bearer ${this.token}`,
219
+ "content-type": "application/json",
220
+ },
221
+ body: JSON.stringify(Object.assign({}, payload)),
222
+ });
223
+ if (res.status >= 400 && res.status < 600) {
224
+ const error = yield res.json();
225
+ throw error;
226
+ }
227
+ const data = yield res.json();
228
+ return data.success;
229
+ });
230
+ }
231
+ /**
232
+ * Connects the specified application using the provided authentication type and optional auth data.
233
+ * @param params - The parameters for connecting the application.
234
+ * @param params.slug - The application slug.
235
+ * @param params.type - The authentication type to use. If not provided, it defaults to `keybased` if payload is provided, otherwise `oauth2`.
236
+ * @param params.payload - key-value pairs of authentication data required for the specified auth type.
237
+ * @returns A promise that resolves to true if the connection was successful, otherwise false.
238
+ * @throws Throws an error if the authentication type is invalid or the connection fails.
239
+ */
240
+ connect(_a) {
241
+ return __awaiter(this, arguments, void 0, function* ({ slug, type, payload, }) {
242
+ switch (type) {
243
+ case AuthType.OAuth2:
244
+ return this.oauth(slug, payload);
245
+ case AuthType.KeyBased:
246
+ return this.keybased(slug, payload);
247
+ default:
248
+ if (payload)
249
+ return this.keybased(slug, payload);
250
+ return this.oauth(slug);
251
+ }
252
+ });
253
+ }
254
+ /**
255
+ * Disconnect the specified application and remove any associated data from Refold.
256
+ * @param {String} slug The application slug.
257
+ * @param {AuthType} [type] The authentication type to use. If not provided, it'll remove all the connected accounts.
258
+ * @returns {Promise<unknown>}
259
+ */
260
+ disconnect(slug, type) {
261
+ return __awaiter(this, void 0, void 0, function* () {
262
+ const res = yield fetch(`${this.baseUrl}/api/v1/linked-acc/integration/${slug}${type ? `?auth_type=${type}` : ""}`, {
263
+ method: "DELETE",
264
+ headers: {
265
+ authorization: `Bearer ${this.token}`,
266
+ },
267
+ });
268
+ if (res.status >= 400 && res.status < 600) {
269
+ const error = yield res.json();
270
+ throw error;
271
+ }
272
+ return yield res.json();
273
+ });
274
+ }
275
+ /**
276
+ * Returns the specified config, or creates one if it doesn't exist.
277
+ * @param {ConfigPayload} payload The payload object for config.
278
+ * @returns {Promise<Config>} The specified config.
279
+ */
280
+ config(payload) {
281
+ return __awaiter(this, void 0, void 0, function* () {
282
+ const res = yield fetch(`${this.baseUrl}/api/v2/f-sdk/config`, {
283
+ method: "POST",
284
+ headers: {
285
+ authorization: `Bearer ${this.token}`,
286
+ "content-type": "application/json",
287
+ },
288
+ body: JSON.stringify(Object.assign(Object.assign({}, payload), { labels: payload.labels || [] })),
289
+ });
290
+ if (res.status >= 400 && res.status < 600) {
291
+ const error = yield res.json();
292
+ throw error;
293
+ }
294
+ return yield res.json();
295
+ });
296
+ }
297
+ /**
298
+ * Returns the configs created for the specified application.
299
+ * @param {String} slug The application slug.
300
+ * @returns {Promise<{ config_id: string; }[]>} The configs created for the specified application.
301
+ */
302
+ getConfigs(slug) {
303
+ return __awaiter(this, void 0, void 0, function* () {
304
+ const res = yield fetch(`${this.baseUrl}/api/v2/public/slug/${slug}/configs`, {
305
+ headers: {
306
+ authorization: `Bearer ${this.token}`,
307
+ },
308
+ });
309
+ if (res.status >= 400 && res.status < 600) {
310
+ const error = yield res.json();
311
+ throw error;
312
+ }
313
+ return yield res.json();
314
+ });
315
+ }
316
+ /**
317
+ * Returns the specified config.
318
+ * @param {String} slug The application slug.
319
+ * @param {String} [configId] The unique ID of the config.
320
+ * @param {Boolean} [excludeOptions] Whether to exclude the options from the fields in the response.
321
+ * @returns {Promise<Config>} The specified config.
322
+ */
323
+ getConfig(slug, configId, excludeOptions) {
324
+ return __awaiter(this, void 0, void 0, function* () {
325
+ const res = yield fetch(`${this.baseUrl}/api/v2/f-sdk/slug/${slug}/config${configId ? `/${configId}` : ""}`, {
326
+ headers: Object.assign({ authorization: `Bearer ${this.token}` }, (excludeOptions ? { disable_field_options: "true" } : {})),
327
+ });
328
+ if (res.status >= 400 && res.status < 600) {
329
+ const error = yield res.json();
330
+ throw error;
331
+ }
332
+ return yield res.json();
333
+ });
334
+ }
335
+ /**
336
+ * Update the specified config.
337
+ * @param {UpdateConfigPayload} payload The update payload.
338
+ * @returns {Promise<Config>} The specified config.
339
+ */
340
+ updateConfig(payload) {
341
+ return __awaiter(this, void 0, void 0, function* () {
342
+ const res = yield fetch(`${this.baseUrl}/api/v2/f-sdk/config`, {
343
+ method: "PUT",
344
+ headers: {
345
+ authorization: `Bearer ${this.token}`,
346
+ "content-type": "application/json",
347
+ },
348
+ body: JSON.stringify(payload),
349
+ });
350
+ if (res.status >= 400 && res.status < 600) {
351
+ const error = yield res.json();
352
+ throw error;
353
+ }
354
+ return yield res.json();
355
+ });
356
+ }
357
+ /**
358
+ * Delete the specified config.
359
+ * @param {String} slug The application slug.
360
+ * @param {String} [configId] The unique ID of the config.
361
+ * @returns {Promise<unknown>}
362
+ */
363
+ deleteConfig(slug, configId) {
364
+ return __awaiter(this, void 0, void 0, function* () {
365
+ const res = yield fetch(`${this.baseUrl}/api/v2/f-sdk/slug/${slug}/config${configId ? `/${configId}` : ""}`, {
366
+ method: "DELETE",
367
+ headers: {
368
+ authorization: `Bearer ${this.token}`,
369
+ },
370
+ });
371
+ if (res.status >= 400 && res.status < 600) {
372
+ const error = yield res.json();
373
+ throw error;
374
+ }
375
+ return yield res.json();
376
+ });
377
+ }
378
+ /**
379
+ * Returns the specified field of the config.
380
+ * @param {String} slug The application slug.
381
+ * @param {String} fieldId The unique ID of the field.
382
+ * @param {String} [workflowId] The unique ID of the workflow.
383
+ * @param {Record<string, unknown>} [payload] The payload to be sent in the request body.
384
+ * @returns {Promise<Field>} The specified config field.
385
+ */
386
+ getConfigField(slug, fieldId, workflowId, payload) {
387
+ return __awaiter(this, void 0, void 0, function* () {
388
+ const res = yield fetch(`${this.baseUrl}/api/v2/public/config/field/${fieldId}${workflowId ? `?workflow_id=${workflowId}` : ""}`, {
389
+ method: "POST",
390
+ headers: {
391
+ authorization: `Bearer ${this.token}`,
392
+ "content-type": "application/json",
393
+ slug,
394
+ },
395
+ body: JSON.stringify(payload || {}),
396
+ });
397
+ if (res.status >= 400 && res.status < 600) {
398
+ const error = yield res.json();
399
+ throw error;
400
+ }
401
+ return yield res.json();
402
+ });
403
+ }
404
+ /**
405
+ * Update the specified config field value.
406
+ * @param {String} slug The application slug.
407
+ * @param {String} fieldId The unique ID of the field.
408
+ * @param {String | Number | Boolean | null} value The new value for the field.
409
+ * @param {String} [workflowId] The unique ID of the workflow.
410
+ * @returns {Promise<Field>} The updated config field.
411
+ */
412
+ updateConfigField(slug, fieldId, value, workflowId) {
413
+ return __awaiter(this, void 0, void 0, function* () {
414
+ const res = yield fetch(`${this.baseUrl}/api/v2/public/config/field/${fieldId}${workflowId ? `?workflow_id=${workflowId}` : ""}`, {
415
+ method: "PUT",
416
+ headers: {
417
+ authorization: `Bearer ${this.token}`,
418
+ "content-type": "application/json",
419
+ slug,
420
+ },
421
+ body: JSON.stringify({ value }),
422
+ });
423
+ if (res.status >= 400 && res.status < 600) {
424
+ const error = yield res.json();
425
+ throw error;
426
+ }
427
+ return yield res.json();
428
+ });
429
+ }
430
+ /**
431
+ * Delete the specified config field value.
432
+ * @param {String} slug The application slug.
433
+ * @param {String} fieldId The unique ID of the field.
434
+ * @param {String} [workflowId] The unique ID of the workflow.
435
+ * @returns {Promise<unknown>}
436
+ */
437
+ deleteConfigField(slug, fieldId, workflowId) {
438
+ return __awaiter(this, void 0, void 0, function* () {
439
+ const res = yield fetch(`${this.baseUrl}/api/v2/public/config/field/${fieldId}${workflowId ? `?workflow_id=${workflowId}` : ""}`, {
440
+ method: "DELETE",
441
+ headers: {
442
+ authorization: `Bearer ${this.token}`,
443
+ slug,
444
+ },
445
+ });
446
+ if (res.status >= 400 && res.status < 600) {
447
+ const error = yield res.json();
448
+ throw error;
449
+ }
450
+ return yield res.json();
451
+ });
452
+ }
453
+ /**
454
+ * Returns the options for the specified field.
455
+ * @param {String} lhs The selected value of the lhs field.
456
+ * @param {String} slug The application slug.
457
+ * @param {String} fieldId The unique ID of the field.
458
+ * @param {String} [workflowId] The unique ID of the workflow, if this is a workflow field.
459
+ * @returns {Promise<RuleOptions>} The specified rule field's options.
460
+ */
461
+ getFieldOptions(lhs, slug, fieldId, workflowId) {
462
+ return __awaiter(this, void 0, void 0, function* () {
463
+ const res = yield fetch(`${this.baseUrl}/api/v2/public/config/rule-engine/${fieldId}${workflowId ? `?workflow_id=${workflowId}` : ""}`, {
464
+ method: "POST",
465
+ headers: {
466
+ authorization: `Bearer ${this.token}`,
467
+ "content-type": "application/json",
468
+ slug,
469
+ },
470
+ body: JSON.stringify({
471
+ rule_column: { lhs },
472
+ }),
473
+ });
474
+ if (res.status >= 400 && res.status < 600) {
475
+ const error = yield res.json();
476
+ throw error;
477
+ }
478
+ return yield res.json();
479
+ });
480
+ }
481
+ /**
482
+ * Returns the private workflows for the specified application.
483
+ * @param {Object} params
484
+ * @param {String} [params.slug]
485
+ * @param {String} [params.name]
486
+ * @param {Number} [params.page]
487
+ * @param {Number} [params.limit]
488
+ * @param {String} [params.start_date] ISO date string — filter workflows created on or after this date.
489
+ * @param {String} [params.end_date] ISO date string — filter workflows created on or before this date.
490
+ * @param {Boolean} [params.published] Filter by workflow published status.
491
+ * @returns
492
+ */
493
+ getWorkflows() {
494
+ return __awaiter(this, arguments, void 0, function* (_a = {}) {
495
+ var { page = 1, limit = 100 } = _a, rest = __rest(_a, ["page", "limit"]);
496
+ const query = new URLSearchParams({ page: String(page), limit: String(limit) });
497
+ for (const key of Object.keys(rest)) {
498
+ const value = rest[key];
499
+ if (value !== undefined && value !== "")
500
+ query.set(key, String(value));
501
+ }
502
+ const res = yield fetch(`${this.baseUrl}/api/v2/public/workflow?${query}`, {
503
+ headers: {
504
+ authorization: `Bearer ${this.token}`,
505
+ },
506
+ });
507
+ if (res.status >= 400 && res.status < 600) {
508
+ const error = yield res.json();
509
+ throw error;
510
+ }
511
+ return yield res.json();
512
+ });
513
+ }
514
+ /**
515
+ * Create a public workflow for the linked account.
516
+ * @param {Object} params
517
+ * @param {String} params.name The workflow name.
518
+ * @param {String} [params.description] The workflow description.
519
+ * @param {String} [params.slug] The application slug in which this workflow should be created.
520
+ * If slug isn't set, the workflow will be created in the organization's default application.
521
+ * @returns {Promise<PublicWorkflow>} The created public workflow.
522
+ */
523
+ createWorkflow(params) {
524
+ return __awaiter(this, void 0, void 0, function* () {
525
+ var _a;
526
+ const res = yield fetch(`${this.baseUrl}/api/v2/public/workflow`, {
527
+ method: "POST",
528
+ headers: {
529
+ authorization: `Bearer ${this.token}`,
530
+ "content-type": "application/json",
531
+ },
532
+ body: JSON.stringify({
533
+ name: params.name,
534
+ description: params.description,
535
+ slug: params.slug,
536
+ }),
537
+ });
538
+ if (res.status >= 400 && res.status < 600) {
539
+ const error = yield res.json();
540
+ throw error;
541
+ }
542
+ const data = yield res.json();
543
+ return (_a = data === null || data === void 0 ? void 0 : data.workflow) !== null && _a !== void 0 ? _a : data;
544
+ });
545
+ }
546
+ /**
547
+ * Delete the specified public workflow.
548
+ * @param {String} workflowId The workflow ID.
549
+ * @returns {Promise<unknown>}
550
+ */
551
+ deleteWorkflow(workflowId) {
552
+ return __awaiter(this, void 0, void 0, function* () {
553
+ const res = yield fetch(`${this.baseUrl}/api/v2/public/workflow/${workflowId}`, {
554
+ method: "DELETE",
555
+ headers: {
556
+ authorization: `Bearer ${this.token}`,
557
+ },
558
+ });
559
+ if (res.status >= 400 && res.status < 600) {
560
+ const error = yield res.json();
561
+ throw error;
562
+ }
563
+ return yield res.json();
564
+ });
565
+ }
566
+ /**
567
+ * Returns the execution payload for the specified public workflow.
568
+ * @param {String} workflowId The workflow ID.
569
+ * @returns {Promise<WorkflowPayloadResponse>} The workflow payload response.
570
+ */
571
+ getWorkflowPayload(workflowId) {
572
+ return __awaiter(this, void 0, void 0, function* () {
573
+ const res = yield fetch(`${this.baseUrl}/api/v2/public/workflow/request-structure/${workflowId}`, {
574
+ headers: {
575
+ authorization: `Bearer ${this.token}`,
576
+ },
577
+ });
578
+ if (res.status >= 400 && res.status < 600) {
579
+ const error = yield res.json();
580
+ throw error;
581
+ }
582
+ return yield res.json();
583
+ });
584
+ }
585
+ /**
586
+ * Execute the specified public workflow.
587
+ * @param {ExecuteWorkflowPayload} options The execution payload.
588
+ * @param {String} options.worklfow The workflow id or alias.
589
+ * @param {String} [options.slug] The application's slug this workflow belongs to. Slug is required if you're using workflow alias.
590
+ * @param {Record<string, any>} [options.payload] The execution payload.
591
+ * @returns {Promise<unknown>}
592
+ */
593
+ executeWorkflow(options) {
594
+ return __awaiter(this, void 0, void 0, function* () {
595
+ const res = yield fetch(`${this.baseUrl}/api/v2/public/workflow/${options === null || options === void 0 ? void 0 : options.worklfow}/execute`, {
596
+ method: "POST",
597
+ headers: {
598
+ authorization: `Bearer ${this.token}`,
599
+ "content-type": "application/json",
600
+ slug: (options === null || options === void 0 ? void 0 : options.slug) || "",
601
+ sync_execution: (options === null || options === void 0 ? void 0 : options.sync_execution) ? "true" : "false",
602
+ },
603
+ body: JSON.stringify(options === null || options === void 0 ? void 0 : options.payload),
604
+ });
605
+ if (res.status >= 400 && res.status < 600) {
606
+ const error = yield res.json();
607
+ throw error;
608
+ }
609
+ return yield res.json();
610
+ });
611
+ }
612
+ /**
613
+ * Returns the workflow execution logs for the linked account.
614
+ * @param {Object} [params]
615
+ * @param {Number} [params.page]
616
+ * @param {Number} [params.limit]
617
+ * @param {String} [params.status] - Filter by execution status (COMPLETED, RUNNING, ERRORED, STOPPED, STOPPING, TIMED_OUT)
618
+ * @param {String} [params.workflow_name] - Filter by workflow name
619
+ * @param {String} [params.workflow_id] - Filter by workflow ID
620
+ * @param {String} [params.start_date] - Filter executions after this date
621
+ * @param {String} [params.end_date] - Filter executions before this date
622
+ * @param {String} [params.execution_type] - Filter by execution type (SYNC, ASYNC)
623
+ * @param {String} [params.execution_source] - Filter by execution source (Event, Schedule, API Call)
624
+ * @returns {Promise<PaginatedResponse<Execution>>} The paginated workflow execution logs.
625
+ */
626
+ getExecutions() {
627
+ return __awaiter(this, arguments, void 0, function* (_a = {}) {
628
+ var { page = 1, limit = 10 } = _a, rest = __rest(_a, ["page", "limit"]);
629
+ const query = new URLSearchParams({ page: String(page), limit: String(limit) });
630
+ for (const key of Object.keys(rest)) {
631
+ const value = rest[key];
632
+ if (value !== undefined && value !== "")
633
+ query.set(key, String(value));
634
+ }
635
+ const res = yield fetch(`${this.baseUrl}/api/v2/public/execution?${query}`, {
636
+ headers: {
637
+ authorization: `Bearer ${this.token}`,
638
+ },
639
+ });
640
+ if (res.status >= 400 && res.status < 600) {
641
+ const error = yield res.json();
642
+ throw error;
643
+ }
644
+ return yield res.json();
645
+ });
646
+ }
647
+ /**
648
+ * Returns the specified workflow execution log.
649
+ * @param {String} executionId The execution ID.
650
+ * @returns {Promise<Execution>} The specified execution log.
651
+ */
652
+ getExecution(executionId) {
653
+ return __awaiter(this, void 0, void 0, function* () {
654
+ const res = yield fetch(`${this.baseUrl}/api/v2/public/execution/${executionId}`, {
655
+ headers: {
656
+ authorization: `Bearer ${this.token}`,
657
+ },
658
+ });
659
+ if (res.status >= 400 && res.status < 600) {
660
+ const error = yield res.json();
661
+ throw error;
662
+ }
663
+ return yield res.json();
664
+ });
665
+ }
666
+ }
667
+ exports.Refold = Refold;