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