@cobaltio/cobalt-js 9.2.0 → 9.3.0-beta.1

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 (41) hide show
  1. package/.github/workflows/npm-publish.yml +10 -2
  2. package/cobalt.d.ts +60 -18
  3. package/cobalt.js +377 -411
  4. package/cobalt.ts +118 -30
  5. package/docs/assets/hierarchy.js +1 -1
  6. package/docs/assets/navigation.js +1 -1
  7. package/docs/assets/search.js +1 -1
  8. package/docs/classes/Cobalt.html +32 -25
  9. package/docs/enums/AuthStatus.html +2 -2
  10. package/docs/enums/AuthType.html +2 -2
  11. package/docs/hierarchy.html +1 -1
  12. package/docs/interfaces/Application.html +14 -18
  13. package/docs/interfaces/AuthConfig.html +9 -0
  14. package/docs/interfaces/CobaltOptions.html +3 -3
  15. package/docs/interfaces/Config.html +2 -2
  16. package/docs/interfaces/ConfigField.html +4 -4
  17. package/docs/interfaces/ConfigPayload.html +4 -4
  18. package/docs/interfaces/ConfigWorkflow.html +2 -2
  19. package/docs/interfaces/ConnectedAccount.html +14 -0
  20. package/docs/interfaces/ExecuteWorkflowPayload.html +5 -5
  21. package/docs/interfaces/Execution.html +2 -2
  22. package/docs/interfaces/ExecutionFilters.html +8 -8
  23. package/docs/interfaces/GetExecutionsParams.html +9 -9
  24. package/docs/interfaces/InputField.html +9 -9
  25. package/docs/interfaces/KeyBasedParams.html +7 -0
  26. package/docs/interfaces/Label.html +3 -3
  27. package/docs/interfaces/OAuthParams.html +9 -0
  28. package/docs/interfaces/PublicWorkflow.html +8 -8
  29. package/docs/interfaces/PublicWorkflowPayload.html +4 -4
  30. package/docs/interfaces/PublicWorkflowsPayload.html +7 -7
  31. package/docs/interfaces/RuleOptions.html +2 -2
  32. package/docs/interfaces/UpdateConfigPayload.html +5 -5
  33. package/docs/interfaces/WorkflowPayload.html +4 -4
  34. package/docs/interfaces/WorkflowPayloadResponse.html +2 -2
  35. package/docs/llms.txt +281 -195
  36. package/docs/modules.html +1 -1
  37. package/docs/types/ExecutionSource.html +1 -1
  38. package/docs/types/ExecutionStatus.html +1 -1
  39. package/docs/types/ExecutionType.html +1 -1
  40. package/package.json +1 -1
  41. package/tsconfig.json +12 -12
package/cobalt.js CHANGED
@@ -2,26 +2,6 @@
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
- };
25
5
  Object.defineProperty(exports, "__esModule", { value: true });
26
6
  exports.Cobalt = exports.AuthStatus = exports.AuthType = void 0;
27
7
  var AuthType;
@@ -54,43 +34,41 @@ class Cobalt {
54
34
  * @private
55
35
  * @returns {Promise<unknown>}
56
36
  */
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;
37
+ async getAccountDetails() {
38
+ const res = await fetch(`${this.baseUrl}/api/v3/org/basics`, {
39
+ headers: {
40
+ authorization: `Bearer ${this.token}`,
41
+ },
70
42
  });
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;
71
49
  }
72
50
  /**
73
51
  * Returns the org & customer details for the associated token.
74
52
  * @private
75
53
  * @returns {Promise<unknown>}
76
54
  */
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;
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
+ }),
93
65
  });
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;
94
72
  }
95
73
  /**
96
74
  * Returns the application details for the specified application, provided
@@ -99,219 +77,238 @@ class Cobalt {
99
77
  * @param {String} [slug] The application slug.
100
78
  * @returns {Promise<Application | Application[]>} The application details.
101
79
  */
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;
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
+ },
115
85
  });
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;
116
92
  }
117
93
  /**
118
94
  * Returns all the enabled apps.
119
95
  * @returns {Promise<Application[]>} The list of applications.
120
96
  */
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;
97
+ async getApps() {
98
+ const res = await fetch(`${this.baseUrl}/api/v2/f-sdk/application`, {
99
+ headers: {
100
+ authorization: `Bearer ${this.token}`,
101
+ },
134
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
+ },
120
+ });
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 || [];
135
127
  }
136
128
  /**
137
129
  * Returns the auth URL that users can use to authenticate themselves to the
138
130
  * specified application.
139
131
  * @private
140
- * @param {String} slug The application slug.
141
- * @param {Object.<string, string>} [params] The key value pairs of auth data.
132
+ * @param {OAuthParams} params The OAuth parameters.
142
133
  * @returns {Promise<String>} The auth URL where users can authenticate themselves.
143
134
  */
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;
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);
154
142
  }
155
- const data = yield res.json();
156
- return data.auth_url;
143
+ }
144
+ const res = await fetch(`${this.baseUrl}/api/v1/${slug}/integrate?${queryParams.toString()}`, {
145
+ headers: {
146
+ authorization: `Bearer ${this.token}`,
147
+ },
157
148
  });
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;
158
155
  }
159
156
  /**
160
157
  * Handle OAuth for the specified application.
161
158
  * @private
162
- * @param {String} slug The application slug.
163
- * @param {Object.<string, string>} [params] The key value pairs of auth data.
159
+ * @param {OAuthParams} params The OAuth parameters.
164
160
  * @returns {Promise<Boolean>} Whether the user authenticated.
165
161
  */
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
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)
179
175
  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) {
180
184
  // clear interval
181
185
  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
- }
186
+ // resolve status
187
+ resolve(false);
193
188
  }
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
- });
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);
205
200
  });
206
201
  }
207
202
  /**
208
203
  * 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.
204
+ * @param {KeyBasedParams} params The key based parameters.
211
205
  * @returns {Promise<Boolean>} Whether the auth data was saved successfully.
212
206
  */
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;
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
+ }),
229
217
  });
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;
230
224
  }
231
225
  /**
232
226
  * Connects the specified application using the provided authentication type and optional auth data.
233
227
  * @param params - The parameters for connecting the application.
234
228
  * @param params.slug - The application slug.
229
+ * @param params.authConfig - The identifier of the auth config.
235
230
  * @param params.type - The authentication type to use. If not provided, it defaults to `keybased` if payload is provided, otherwise `oauth2`.
236
231
  * @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`.
237
233
  * @returns A promise that resolves to true if the connection was successful, otherwise false.
238
234
  * @throws Throws an error if the authentication type is invalid or the connection fails.
239
235
  */
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
- });
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
+ }
253
247
  }
254
248
  /**
255
249
  * Disconnect the specified application and remove any associated data from Cobalt.
256
250
  * @param {String} slug The application slug.
257
251
  * @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.
258
253
  * @returns {Promise<unknown>}
259
254
  */
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();
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
+ },
273
266
  });
267
+ if (res.status >= 400 && res.status < 600) {
268
+ const error = await res.json();
269
+ throw error;
270
+ }
271
+ return await res.json();
274
272
  }
275
273
  /**
276
274
  * Returns the specified config, or creates one if it doesn't exist.
277
275
  * @param {ConfigPayload} payload The payload object for config.
278
276
  * @returns {Promise<Config>} The specified config.
279
277
  */
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();
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
+ }),
295
289
  });
290
+ if (res.status >= 400 && res.status < 600) {
291
+ const error = await res.json();
292
+ throw error;
293
+ }
294
+ return await res.json();
296
295
  }
297
296
  /**
298
297
  * Returns the configs created for the specified application.
299
298
  * @param {String} slug The application slug.
300
299
  * @returns {Promise<{ config_id: string; }[]>} The configs created for the specified application.
301
300
  */
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();
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
+ },
314
306
  });
307
+ if (res.status >= 400 && res.status < 600) {
308
+ const error = await res.json();
309
+ throw error;
310
+ }
311
+ return await res.json();
315
312
  }
316
313
  /**
317
314
  * Returns the specified config.
@@ -319,41 +316,37 @@ class Cobalt {
319
316
  * @param {String} [configId] The unique ID of the config.
320
317
  * @returns {Promise<Config>} The specified config.
321
318
  */
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();
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
+ },
334
324
  });
325
+ if (res.status >= 400 && res.status < 600) {
326
+ const error = await res.json();
327
+ throw error;
328
+ }
329
+ return await res.json();
335
330
  }
336
331
  /**
337
332
  * Update the specified config.
338
333
  * @param {UpdateConfigPayload} payload The update payload.
339
334
  * @returns {Promise<Config>} The specified config.
340
335
  */
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();
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),
356
344
  });
345
+ if (res.status >= 400 && res.status < 600) {
346
+ const error = await res.json();
347
+ throw error;
348
+ }
349
+ return await res.json();
357
350
  }
358
351
  /**
359
352
  * Delete the specified config.
@@ -361,20 +354,18 @@ class Cobalt {
361
354
  * @param {String} [configId] The unique ID of the config.
362
355
  * @returns {Promise<unknown>}
363
356
  */
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();
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
+ },
377
363
  });
364
+ if (res.status >= 400 && res.status < 600) {
365
+ const error = await res.json();
366
+ throw error;
367
+ }
368
+ return await res.json();
378
369
  }
379
370
  /**
380
371
  * Returns the specified field of the config.
@@ -383,20 +374,18 @@ class Cobalt {
383
374
  * @param {String} [workflowId] The unique ID of the workflow.
384
375
  * @returns {Promise<Field>} The specified config field.
385
376
  */
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();
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
+ },
399
383
  });
384
+ if (res.status >= 400 && res.status < 600) {
385
+ const error = await res.json();
386
+ throw error;
387
+ }
388
+ return await res.json();
400
389
  }
401
390
  /**
402
391
  * Update the specified config field value.
@@ -406,23 +395,21 @@ class Cobalt {
406
395
  * @param {String} [workflowId] The unique ID of the workflow.
407
396
  * @returns {Promise<Field>} The updated config field.
408
397
  */
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();
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 }),
425
407
  });
408
+ if (res.status >= 400 && res.status < 600) {
409
+ const error = await res.json();
410
+ throw error;
411
+ }
412
+ return await res.json();
426
413
  }
427
414
  /**
428
415
  * Delete the specified config field value.
@@ -431,21 +418,19 @@ class Cobalt {
431
418
  * @param {String} [workflowId] The unique ID of the workflow.
432
419
  * @returns {Promise<unknown>}
433
420
  */
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();
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
+ },
448
428
  });
429
+ if (res.status >= 400 && res.status < 600) {
430
+ const error = await res.json();
431
+ throw error;
432
+ }
433
+ return await res.json();
449
434
  }
450
435
  /**
451
436
  * Returns the options for the specified field.
@@ -455,25 +440,23 @@ class Cobalt {
455
440
  * @param {String} [workflowId] The unique ID of the workflow, if this is a workflow field.
456
441
  * @returns {Promise<RuleOptions>} The specified rule field's options.
457
442
  */
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();
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
+ }),
476
454
  });
455
+ if (res.status >= 400 && res.status < 600) {
456
+ const error = await res.json();
457
+ throw error;
458
+ }
459
+ return await res.json();
477
460
  }
478
461
  /**
479
462
  * Returns the private workflows for the specified application.
@@ -487,26 +470,23 @@ class Cobalt {
487
470
  * @param {Boolean} [params.published] Filter by workflow published status.
488
471
  * @returns
489
472
  */
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();
473
+ async getWorkflows({ page = 1, limit = 100, ...rest } = {}) {
474
+ const query = new URLSearchParams({ page: String(page), limit: String(limit) });
475
+ for (const key of Object.keys(rest)) {
476
+ const value = rest[key];
477
+ if (value !== undefined && value !== "")
478
+ query.set(key, String(value));
479
+ }
480
+ const res = await fetch(`${this.baseUrl}/api/v2/public/workflow?${query}`, {
481
+ headers: {
482
+ authorization: `Bearer ${this.token}`,
483
+ },
509
484
  });
485
+ if (res.status >= 400 && res.status < 600) {
486
+ const error = await res.json();
487
+ throw error;
488
+ }
489
+ return await res.json();
510
490
  }
511
491
  /**
512
492
  * Create a public workflow for the linked account.
@@ -517,67 +497,60 @@ class Cobalt {
517
497
  * If slug isn't set, the workflow will be created in the organization's default application.
518
498
  * @returns {Promise<PublicWorkflow>} The created public workflow.
519
499
  */
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;
500
+ async createWorkflow(params) {
501
+ const res = await fetch(`${this.baseUrl}/api/v2/public/workflow`, {
502
+ method: "POST",
503
+ headers: {
504
+ authorization: `Bearer ${this.token}`,
505
+ "content-type": "application/json",
506
+ },
507
+ body: JSON.stringify({
508
+ name: params.name,
509
+ description: params.description,
510
+ slug: params.slug,
511
+ }),
541
512
  });
513
+ if (res.status >= 400 && res.status < 600) {
514
+ const error = await res.json();
515
+ throw error;
516
+ }
517
+ const data = await res.json();
518
+ return data?.workflow ?? data;
542
519
  }
543
520
  /**
544
521
  * Delete the specified public workflow.
545
522
  * @param {String} workflowId The workflow ID.
546
523
  * @returns {Promise<unknown>}
547
524
  */
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();
525
+ async deleteWorkflow(workflowId) {
526
+ const res = await fetch(`${this.baseUrl}/api/v2/public/workflow/${workflowId}`, {
527
+ method: "DELETE",
528
+ headers: {
529
+ authorization: `Bearer ${this.token}`,
530
+ },
561
531
  });
532
+ if (res.status >= 400 && res.status < 600) {
533
+ const error = await res.json();
534
+ throw error;
535
+ }
536
+ return await res.json();
562
537
  }
563
538
  /**
564
539
  * Returns the execution payload for the specified public workflow.
565
540
  * @param {String} workflowId The workflow ID.
566
541
  * @returns {Promise<WorkflowPayloadResponse>} The workflow payload response.
567
542
  */
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();
543
+ async getWorkflowPayload(workflowId) {
544
+ const res = await fetch(`${this.baseUrl}/api/v2/public/workflow/request-structure/${workflowId}`, {
545
+ headers: {
546
+ authorization: `Bearer ${this.token}`,
547
+ },
580
548
  });
549
+ if (res.status >= 400 && res.status < 600) {
550
+ const error = await res.json();
551
+ throw error;
552
+ }
553
+ return await res.json();
581
554
  }
582
555
  /**
583
556
  * Execute the specified public workflow.
@@ -587,24 +560,22 @@ class Cobalt {
587
560
  * @param {Record<string, any>} [options.payload] The execution payload.
588
561
  * @returns {Promise<unknown>}
589
562
  */
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
+ async executeWorkflow(options) {
564
+ const res = await fetch(`${this.baseUrl}/api/v2/public/workflow/${options?.worklfow}/execute`, {
565
+ method: "POST",
566
+ headers: {
567
+ authorization: `Bearer ${this.token}`,
568
+ "content-type": "application/json",
569
+ slug: options?.slug || "",
570
+ sync_execution: options?.sync_execution ? "true" : "false",
571
+ },
572
+ body: JSON.stringify(options?.payload),
607
573
  });
574
+ if (res.status >= 400 && res.status < 600) {
575
+ const error = await res.json();
576
+ throw error;
577
+ }
578
+ return await res.json();
608
579
  }
609
580
  /**
610
581
  * Returns the workflow execution logs for the linked account.
@@ -620,45 +591,40 @@ class Cobalt {
620
591
  * @param {String} [params.execution_source] - Filter by execution source (Event, Schedule, API Call)
621
592
  * @returns {Promise<PaginatedResponse<Execution>>} The paginated workflow execution logs.
622
593
  */
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();
594
+ async getExecutions({ page = 1, limit = 10, ...rest } = {}) {
595
+ const query = new URLSearchParams({ page: String(page), limit: String(limit) });
596
+ for (const key of Object.keys(rest)) {
597
+ const value = rest[key];
598
+ if (value !== undefined && value !== "")
599
+ query.set(key, String(value));
600
+ }
601
+ const res = await fetch(`${this.baseUrl}/api/v2/public/execution?${query}`, {
602
+ headers: {
603
+ authorization: `Bearer ${this.token}`,
604
+ },
642
605
  });
606
+ if (res.status >= 400 && res.status < 600) {
607
+ const error = await res.json();
608
+ throw error;
609
+ }
610
+ return await res.json();
643
611
  }
644
612
  /**
645
613
  * Returns the specified workflow execution log.
646
614
  * @param {String} executionId The execution ID.
647
615
  * @returns {Promise<Execution>} The specified execution log.
648
616
  */
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();
617
+ async getExecution(executionId) {
618
+ const res = await fetch(`${this.baseUrl}/api/v2/public/execution/${executionId}`, {
619
+ headers: {
620
+ authorization: `Bearer ${this.token}`,
621
+ },
661
622
  });
623
+ if (res.status >= 400 && res.status < 600) {
624
+ const error = await res.json();
625
+ throw error;
626
+ }
627
+ return await res.json();
662
628
  }
663
629
  }
664
630
  exports.Cobalt = Cobalt;