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