@cobaltio/cobalt-js 9.2.1 → 9.3.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/pull_request_template.md +48 -0
- package/.github/workflows/npm-publish.yml +10 -2
- package/.github/workflows/pr-validation.yml +224 -0
- package/CLAUDE.md +10 -0
- package/cobalt.d.ts +60 -18
- package/cobalt.js +378 -409
- package/cobalt.ts +118 -30
- package/docs/assets/hierarchy.js +1 -1
- package/docs/assets/icons.js +1 -1
- package/docs/assets/icons.svg +1 -1
- package/docs/assets/main.js +3 -3
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/Cobalt.html +32 -25
- package/docs/enums/AuthStatus.html +2 -2
- package/docs/enums/AuthType.html +2 -2
- package/docs/hierarchy.html +1 -1
- package/docs/interfaces/Application.html +14 -18
- package/docs/interfaces/AuthConfig.html +9 -0
- package/docs/interfaces/CobaltOptions.html +3 -3
- package/docs/interfaces/Config.html +2 -2
- package/docs/interfaces/ConfigField.html +4 -4
- package/docs/interfaces/ConfigPayload.html +4 -4
- package/docs/interfaces/ConfigWorkflow.html +2 -2
- package/docs/interfaces/ConnectedAccount.html +14 -0
- package/docs/interfaces/ExecuteWorkflowPayload.html +5 -5
- package/docs/interfaces/Execution.html +2 -2
- package/docs/interfaces/ExecutionFilters.html +8 -8
- package/docs/interfaces/GetExecutionsParams.html +9 -9
- package/docs/interfaces/InputField.html +9 -9
- package/docs/interfaces/KeyBasedParams.html +7 -0
- package/docs/interfaces/Label.html +3 -3
- package/docs/interfaces/OAuthParams.html +9 -0
- package/docs/interfaces/PublicWorkflow.html +8 -8
- package/docs/interfaces/PublicWorkflowPayload.html +4 -4
- package/docs/interfaces/PublicWorkflowsPayload.html +7 -7
- package/docs/interfaces/RuleOptions.html +2 -2
- package/docs/interfaces/UpdateConfigPayload.html +5 -5
- package/docs/interfaces/WorkflowPayload.html +4 -4
- package/docs/interfaces/WorkflowPayloadResponse.html +2 -2
- package/docs/llms.txt +283 -195
- package/docs/modules.html +1 -1
- package/docs/types/ExecutionSource.html +1 -1
- package/docs/types/ExecutionStatus.html +1 -1
- package/docs/types/ExecutionType.html +1 -1
- package/package.json +3 -3
- 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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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 {
|
|
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,
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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
|
-
|
|
156
|
-
|
|
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 {
|
|
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,
|
|
167
|
-
return
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
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
|
-
//
|
|
183
|
-
resolve(
|
|
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
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
}
|
|
202
|
-
})
|
|
203
|
-
|
|
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 {
|
|
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
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
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(
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
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
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
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
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
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
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
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.
|
|
@@ -320,39 +317,38 @@ class Cobalt {
|
|
|
320
317
|
* @param {Boolean} [excludeOptions] Whether to exclude the options from the fields in the response.
|
|
321
318
|
* @returns {Promise<Config>} The specified config.
|
|
322
319
|
*/
|
|
323
|
-
getConfig(slug, configId, excludeOptions) {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
const error = yield res.json();
|
|
330
|
-
throw error;
|
|
331
|
-
}
|
|
332
|
-
return yield res.json();
|
|
320
|
+
async getConfig(slug, configId, excludeOptions) {
|
|
321
|
+
const res = await fetch(`${this.baseUrl}/api/v2/f-sdk/slug/${slug}/config${configId ? `/${configId}` : ""}`, {
|
|
322
|
+
headers: {
|
|
323
|
+
authorization: `Bearer ${this.token}`,
|
|
324
|
+
...(excludeOptions ? { disable_field_options: "true" } : {}),
|
|
325
|
+
},
|
|
333
326
|
});
|
|
327
|
+
if (res.status >= 400 && res.status < 600) {
|
|
328
|
+
const error = await res.json();
|
|
329
|
+
throw error;
|
|
330
|
+
}
|
|
331
|
+
return await res.json();
|
|
334
332
|
}
|
|
335
333
|
/**
|
|
336
334
|
* Update the specified config.
|
|
337
335
|
* @param {UpdateConfigPayload} payload The update payload.
|
|
338
336
|
* @returns {Promise<Config>} The specified config.
|
|
339
337
|
*/
|
|
340
|
-
updateConfig(payload) {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
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();
|
|
338
|
+
async updateConfig(payload) {
|
|
339
|
+
const res = await fetch(`${this.baseUrl}/api/v2/f-sdk/config`, {
|
|
340
|
+
method: "PUT",
|
|
341
|
+
headers: {
|
|
342
|
+
authorization: `Bearer ${this.token}`,
|
|
343
|
+
"content-type": "application/json",
|
|
344
|
+
},
|
|
345
|
+
body: JSON.stringify(payload),
|
|
355
346
|
});
|
|
347
|
+
if (res.status >= 400 && res.status < 600) {
|
|
348
|
+
const error = await res.json();
|
|
349
|
+
throw error;
|
|
350
|
+
}
|
|
351
|
+
return await res.json();
|
|
356
352
|
}
|
|
357
353
|
/**
|
|
358
354
|
* Delete the specified config.
|
|
@@ -360,20 +356,18 @@ class Cobalt {
|
|
|
360
356
|
* @param {String} [configId] The unique ID of the config.
|
|
361
357
|
* @returns {Promise<unknown>}
|
|
362
358
|
*/
|
|
363
|
-
deleteConfig(slug, configId) {
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
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();
|
|
359
|
+
async deleteConfig(slug, configId) {
|
|
360
|
+
const res = await fetch(`${this.baseUrl}/api/v2/f-sdk/slug/${slug}/config${configId ? `/${configId}` : ""}`, {
|
|
361
|
+
method: "DELETE",
|
|
362
|
+
headers: {
|
|
363
|
+
authorization: `Bearer ${this.token}`,
|
|
364
|
+
},
|
|
376
365
|
});
|
|
366
|
+
if (res.status >= 400 && res.status < 600) {
|
|
367
|
+
const error = await res.json();
|
|
368
|
+
throw error;
|
|
369
|
+
}
|
|
370
|
+
return await res.json();
|
|
377
371
|
}
|
|
378
372
|
/**
|
|
379
373
|
* Returns the specified field of the config.
|
|
@@ -382,20 +376,18 @@ class Cobalt {
|
|
|
382
376
|
* @param {String} [workflowId] The unique ID of the workflow.
|
|
383
377
|
* @returns {Promise<Field>} The specified config field.
|
|
384
378
|
*/
|
|
385
|
-
getConfigField(slug, fieldId, workflowId) {
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
},
|
|
392
|
-
});
|
|
393
|
-
if (res.status >= 400 && res.status < 600) {
|
|
394
|
-
const error = yield res.json();
|
|
395
|
-
throw error;
|
|
396
|
-
}
|
|
397
|
-
return yield res.json();
|
|
379
|
+
async getConfigField(slug, fieldId, workflowId) {
|
|
380
|
+
const res = await fetch(`${this.baseUrl}/api/v2/public/config/field/${fieldId}${workflowId ? `?workflow_id=${workflowId}` : ""}`, {
|
|
381
|
+
headers: {
|
|
382
|
+
authorization: `Bearer ${this.token}`,
|
|
383
|
+
slug,
|
|
384
|
+
},
|
|
398
385
|
});
|
|
386
|
+
if (res.status >= 400 && res.status < 600) {
|
|
387
|
+
const error = await res.json();
|
|
388
|
+
throw error;
|
|
389
|
+
}
|
|
390
|
+
return await res.json();
|
|
399
391
|
}
|
|
400
392
|
/**
|
|
401
393
|
* Update the specified config field value.
|
|
@@ -405,23 +397,21 @@ class Cobalt {
|
|
|
405
397
|
* @param {String} [workflowId] The unique ID of the workflow.
|
|
406
398
|
* @returns {Promise<Field>} The updated config field.
|
|
407
399
|
*/
|
|
408
|
-
updateConfigField(slug, fieldId, value, workflowId) {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
body: JSON.stringify({ value }),
|
|
418
|
-
});
|
|
419
|
-
if (res.status >= 400 && res.status < 600) {
|
|
420
|
-
const error = yield res.json();
|
|
421
|
-
throw error;
|
|
422
|
-
}
|
|
423
|
-
return yield res.json();
|
|
400
|
+
async updateConfigField(slug, fieldId, value, workflowId) {
|
|
401
|
+
const res = await fetch(`${this.baseUrl}/api/v2/public/config/field/${fieldId}${workflowId ? `?workflow_id=${workflowId}` : ""}`, {
|
|
402
|
+
method: "PUT",
|
|
403
|
+
headers: {
|
|
404
|
+
authorization: `Bearer ${this.token}`,
|
|
405
|
+
"content-type": "application/json",
|
|
406
|
+
slug,
|
|
407
|
+
},
|
|
408
|
+
body: JSON.stringify({ value }),
|
|
424
409
|
});
|
|
410
|
+
if (res.status >= 400 && res.status < 600) {
|
|
411
|
+
const error = await res.json();
|
|
412
|
+
throw error;
|
|
413
|
+
}
|
|
414
|
+
return await res.json();
|
|
425
415
|
}
|
|
426
416
|
/**
|
|
427
417
|
* Delete the specified config field value.
|
|
@@ -430,21 +420,19 @@ class Cobalt {
|
|
|
430
420
|
* @param {String} [workflowId] The unique ID of the workflow.
|
|
431
421
|
* @returns {Promise<unknown>}
|
|
432
422
|
*/
|
|
433
|
-
deleteConfigField(slug, fieldId, workflowId) {
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
},
|
|
441
|
-
});
|
|
442
|
-
if (res.status >= 400 && res.status < 600) {
|
|
443
|
-
const error = yield res.json();
|
|
444
|
-
throw error;
|
|
445
|
-
}
|
|
446
|
-
return yield res.json();
|
|
423
|
+
async deleteConfigField(slug, fieldId, workflowId) {
|
|
424
|
+
const res = await fetch(`${this.baseUrl}/api/v2/public/config/field/${fieldId}${workflowId ? `?workflow_id=${workflowId}` : ""}`, {
|
|
425
|
+
method: "DELETE",
|
|
426
|
+
headers: {
|
|
427
|
+
authorization: `Bearer ${this.token}`,
|
|
428
|
+
slug,
|
|
429
|
+
},
|
|
447
430
|
});
|
|
431
|
+
if (res.status >= 400 && res.status < 600) {
|
|
432
|
+
const error = await res.json();
|
|
433
|
+
throw error;
|
|
434
|
+
}
|
|
435
|
+
return await res.json();
|
|
448
436
|
}
|
|
449
437
|
/**
|
|
450
438
|
* Returns the options for the specified field.
|
|
@@ -454,25 +442,23 @@ class Cobalt {
|
|
|
454
442
|
* @param {String} [workflowId] The unique ID of the workflow, if this is a workflow field.
|
|
455
443
|
* @returns {Promise<RuleOptions>} The specified rule field's options.
|
|
456
444
|
*/
|
|
457
|
-
getFieldOptions(lhs, slug, fieldId, workflowId) {
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
}),
|
|
469
|
-
});
|
|
470
|
-
if (res.status >= 400 && res.status < 600) {
|
|
471
|
-
const error = yield res.json();
|
|
472
|
-
throw error;
|
|
473
|
-
}
|
|
474
|
-
return yield res.json();
|
|
445
|
+
async getFieldOptions(lhs, slug, fieldId, workflowId) {
|
|
446
|
+
const res = await fetch(`${this.baseUrl}/api/v2/public/config/rule-engine/${fieldId}${workflowId ? `?workflow_id=${workflowId}` : ""}`, {
|
|
447
|
+
method: "POST",
|
|
448
|
+
headers: {
|
|
449
|
+
authorization: `Bearer ${this.token}`,
|
|
450
|
+
"content-type": "application/json",
|
|
451
|
+
slug,
|
|
452
|
+
},
|
|
453
|
+
body: JSON.stringify({
|
|
454
|
+
rule_column: { lhs },
|
|
455
|
+
}),
|
|
475
456
|
});
|
|
457
|
+
if (res.status >= 400 && res.status < 600) {
|
|
458
|
+
const error = await res.json();
|
|
459
|
+
throw error;
|
|
460
|
+
}
|
|
461
|
+
return await res.json();
|
|
476
462
|
}
|
|
477
463
|
/**
|
|
478
464
|
* Returns the private workflows for the specified application.
|
|
@@ -486,26 +472,23 @@ class Cobalt {
|
|
|
486
472
|
* @param {Boolean} [params.published] Filter by workflow published status.
|
|
487
473
|
* @returns
|
|
488
474
|
*/
|
|
489
|
-
getWorkflows() {
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
const
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
authorization: `Bearer ${this.token}`,
|
|
501
|
-
},
|
|
502
|
-
});
|
|
503
|
-
if (res.status >= 400 && res.status < 600) {
|
|
504
|
-
const error = yield res.json();
|
|
505
|
-
throw error;
|
|
506
|
-
}
|
|
507
|
-
return yield res.json();
|
|
475
|
+
async getWorkflows({ page = 1, limit = 100, ...rest } = {}) {
|
|
476
|
+
const query = new URLSearchParams({ page: String(page), limit: String(limit) });
|
|
477
|
+
for (const key of Object.keys(rest)) {
|
|
478
|
+
const value = rest[key];
|
|
479
|
+
if (value !== undefined && value !== "")
|
|
480
|
+
query.set(key, String(value));
|
|
481
|
+
}
|
|
482
|
+
const res = await fetch(`${this.baseUrl}/api/v2/public/workflow?${query}`, {
|
|
483
|
+
headers: {
|
|
484
|
+
authorization: `Bearer ${this.token}`,
|
|
485
|
+
},
|
|
508
486
|
});
|
|
487
|
+
if (res.status >= 400 && res.status < 600) {
|
|
488
|
+
const error = await res.json();
|
|
489
|
+
throw error;
|
|
490
|
+
}
|
|
491
|
+
return await res.json();
|
|
509
492
|
}
|
|
510
493
|
/**
|
|
511
494
|
* Create a public workflow for the linked account.
|
|
@@ -516,67 +499,60 @@ class Cobalt {
|
|
|
516
499
|
* If slug isn't set, the workflow will be created in the organization's default application.
|
|
517
500
|
* @returns {Promise<PublicWorkflow>} The created public workflow.
|
|
518
501
|
*/
|
|
519
|
-
createWorkflow(params) {
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
slug: params.slug,
|
|
532
|
-
}),
|
|
533
|
-
});
|
|
534
|
-
if (res.status >= 400 && res.status < 600) {
|
|
535
|
-
const error = yield res.json();
|
|
536
|
-
throw error;
|
|
537
|
-
}
|
|
538
|
-
const data = yield res.json();
|
|
539
|
-
return (_a = data === null || data === void 0 ? void 0 : data.workflow) !== null && _a !== void 0 ? _a : data;
|
|
502
|
+
async createWorkflow(params) {
|
|
503
|
+
const res = await fetch(`${this.baseUrl}/api/v2/public/workflow`, {
|
|
504
|
+
method: "POST",
|
|
505
|
+
headers: {
|
|
506
|
+
authorization: `Bearer ${this.token}`,
|
|
507
|
+
"content-type": "application/json",
|
|
508
|
+
},
|
|
509
|
+
body: JSON.stringify({
|
|
510
|
+
name: params.name,
|
|
511
|
+
description: params.description,
|
|
512
|
+
slug: params.slug,
|
|
513
|
+
}),
|
|
540
514
|
});
|
|
515
|
+
if (res.status >= 400 && res.status < 600) {
|
|
516
|
+
const error = await res.json();
|
|
517
|
+
throw error;
|
|
518
|
+
}
|
|
519
|
+
const data = await res.json();
|
|
520
|
+
return data?.workflow ?? data;
|
|
541
521
|
}
|
|
542
522
|
/**
|
|
543
523
|
* Delete the specified public workflow.
|
|
544
524
|
* @param {String} workflowId The workflow ID.
|
|
545
525
|
* @returns {Promise<unknown>}
|
|
546
526
|
*/
|
|
547
|
-
deleteWorkflow(workflowId) {
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
},
|
|
554
|
-
});
|
|
555
|
-
if (res.status >= 400 && res.status < 600) {
|
|
556
|
-
const error = yield res.json();
|
|
557
|
-
throw error;
|
|
558
|
-
}
|
|
559
|
-
return yield res.json();
|
|
527
|
+
async deleteWorkflow(workflowId) {
|
|
528
|
+
const res = await fetch(`${this.baseUrl}/api/v2/public/workflow/${workflowId}`, {
|
|
529
|
+
method: "DELETE",
|
|
530
|
+
headers: {
|
|
531
|
+
authorization: `Bearer ${this.token}`,
|
|
532
|
+
},
|
|
560
533
|
});
|
|
534
|
+
if (res.status >= 400 && res.status < 600) {
|
|
535
|
+
const error = await res.json();
|
|
536
|
+
throw error;
|
|
537
|
+
}
|
|
538
|
+
return await res.json();
|
|
561
539
|
}
|
|
562
540
|
/**
|
|
563
541
|
* Returns the execution payload for the specified public workflow.
|
|
564
542
|
* @param {String} workflowId The workflow ID.
|
|
565
543
|
* @returns {Promise<WorkflowPayloadResponse>} The workflow payload response.
|
|
566
544
|
*/
|
|
567
|
-
getWorkflowPayload(workflowId) {
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
},
|
|
573
|
-
});
|
|
574
|
-
if (res.status >= 400 && res.status < 600) {
|
|
575
|
-
const error = yield res.json();
|
|
576
|
-
throw error;
|
|
577
|
-
}
|
|
578
|
-
return yield res.json();
|
|
545
|
+
async getWorkflowPayload(workflowId) {
|
|
546
|
+
const res = await fetch(`${this.baseUrl}/api/v2/public/workflow/request-structure/${workflowId}`, {
|
|
547
|
+
headers: {
|
|
548
|
+
authorization: `Bearer ${this.token}`,
|
|
549
|
+
},
|
|
579
550
|
});
|
|
551
|
+
if (res.status >= 400 && res.status < 600) {
|
|
552
|
+
const error = await res.json();
|
|
553
|
+
throw error;
|
|
554
|
+
}
|
|
555
|
+
return await res.json();
|
|
580
556
|
}
|
|
581
557
|
/**
|
|
582
558
|
* Execute the specified public workflow.
|
|
@@ -586,24 +562,22 @@ class Cobalt {
|
|
|
586
562
|
* @param {Record<string, any>} [options.payload] The execution payload.
|
|
587
563
|
* @returns {Promise<unknown>}
|
|
588
564
|
*/
|
|
589
|
-
executeWorkflow(options) {
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
body: JSON.stringify(options === null || options === void 0 ? void 0 : options.payload),
|
|
600
|
-
});
|
|
601
|
-
if (res.status >= 400 && res.status < 600) {
|
|
602
|
-
const error = yield res.json();
|
|
603
|
-
throw error;
|
|
604
|
-
}
|
|
605
|
-
return yield res.json();
|
|
565
|
+
async executeWorkflow(options) {
|
|
566
|
+
const res = await fetch(`${this.baseUrl}/api/v2/public/workflow/${options?.worklfow}/execute`, {
|
|
567
|
+
method: "POST",
|
|
568
|
+
headers: {
|
|
569
|
+
authorization: `Bearer ${this.token}`,
|
|
570
|
+
"content-type": "application/json",
|
|
571
|
+
slug: options?.slug || "",
|
|
572
|
+
sync_execution: options?.sync_execution ? "true" : "false",
|
|
573
|
+
},
|
|
574
|
+
body: JSON.stringify(options?.payload),
|
|
606
575
|
});
|
|
576
|
+
if (res.status >= 400 && res.status < 600) {
|
|
577
|
+
const error = await res.json();
|
|
578
|
+
throw error;
|
|
579
|
+
}
|
|
580
|
+
return await res.json();
|
|
607
581
|
}
|
|
608
582
|
/**
|
|
609
583
|
* Returns the workflow execution logs for the linked account.
|
|
@@ -619,45 +593,40 @@ class Cobalt {
|
|
|
619
593
|
* @param {String} [params.execution_source] - Filter by execution source (Event, Schedule, API Call)
|
|
620
594
|
* @returns {Promise<PaginatedResponse<Execution>>} The paginated workflow execution logs.
|
|
621
595
|
*/
|
|
622
|
-
getExecutions() {
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
const
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
authorization: `Bearer ${this.token}`,
|
|
634
|
-
},
|
|
635
|
-
});
|
|
636
|
-
if (res.status >= 400 && res.status < 600) {
|
|
637
|
-
const error = yield res.json();
|
|
638
|
-
throw error;
|
|
639
|
-
}
|
|
640
|
-
return yield res.json();
|
|
596
|
+
async getExecutions({ page = 1, limit = 10, ...rest } = {}) {
|
|
597
|
+
const query = new URLSearchParams({ page: String(page), limit: String(limit) });
|
|
598
|
+
for (const key of Object.keys(rest)) {
|
|
599
|
+
const value = rest[key];
|
|
600
|
+
if (value !== undefined && value !== "")
|
|
601
|
+
query.set(key, String(value));
|
|
602
|
+
}
|
|
603
|
+
const res = await fetch(`${this.baseUrl}/api/v2/public/execution?${query}`, {
|
|
604
|
+
headers: {
|
|
605
|
+
authorization: `Bearer ${this.token}`,
|
|
606
|
+
},
|
|
641
607
|
});
|
|
608
|
+
if (res.status >= 400 && res.status < 600) {
|
|
609
|
+
const error = await res.json();
|
|
610
|
+
throw error;
|
|
611
|
+
}
|
|
612
|
+
return await res.json();
|
|
642
613
|
}
|
|
643
614
|
/**
|
|
644
615
|
* Returns the specified workflow execution log.
|
|
645
616
|
* @param {String} executionId The execution ID.
|
|
646
617
|
* @returns {Promise<Execution>} The specified execution log.
|
|
647
618
|
*/
|
|
648
|
-
getExecution(executionId) {
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
},
|
|
654
|
-
});
|
|
655
|
-
if (res.status >= 400 && res.status < 600) {
|
|
656
|
-
const error = yield res.json();
|
|
657
|
-
throw error;
|
|
658
|
-
}
|
|
659
|
-
return yield res.json();
|
|
619
|
+
async getExecution(executionId) {
|
|
620
|
+
const res = await fetch(`${this.baseUrl}/api/v2/public/execution/${executionId}`, {
|
|
621
|
+
headers: {
|
|
622
|
+
authorization: `Bearer ${this.token}`,
|
|
623
|
+
},
|
|
660
624
|
});
|
|
625
|
+
if (res.status >= 400 && res.status < 600) {
|
|
626
|
+
const error = await res.json();
|
|
627
|
+
throw error;
|
|
628
|
+
}
|
|
629
|
+
return await res.json();
|
|
661
630
|
}
|
|
662
631
|
}
|
|
663
632
|
exports.Cobalt = Cobalt;
|