@cobaltio/cobalt-js 9.2.1 → 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.
- package/.github/workflows/npm-publish.yml +10 -2
- package/cobalt.d.ts +61 -20
- package/cobalt.js +377 -410
- package/cobalt.ts +120 -34
- 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 +32 -26
- 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 +282 -197
- 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 +1 -1
- 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,260 +77,276 @@ 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.
|
|
318
315
|
* @param {String} slug The application slug.
|
|
319
316
|
* @param {String} [configId] The unique ID of the config.
|
|
320
|
-
* @param {Boolean} [excludeOptions] Whether to exclude the options from the fields in the response.
|
|
321
317
|
* @returns {Promise<Config>} The specified config.
|
|
322
318
|
*/
|
|
323
|
-
getConfig(slug, configId
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
}
|
|
328
|
-
if (res.status >= 400 && res.status < 600) {
|
|
329
|
-
const error = yield res.json();
|
|
330
|
-
throw error;
|
|
331
|
-
}
|
|
332
|
-
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
|
+
},
|
|
333
324
|
});
|
|
325
|
+
if (res.status >= 400 && res.status < 600) {
|
|
326
|
+
const error = await res.json();
|
|
327
|
+
throw error;
|
|
328
|
+
}
|
|
329
|
+
return await res.json();
|
|
334
330
|
}
|
|
335
331
|
/**
|
|
336
332
|
* Update the specified config.
|
|
337
333
|
* @param {UpdateConfigPayload} payload The update payload.
|
|
338
334
|
* @returns {Promise<Config>} The specified config.
|
|
339
335
|
*/
|
|
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();
|
|
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),
|
|
355
344
|
});
|
|
345
|
+
if (res.status >= 400 && res.status < 600) {
|
|
346
|
+
const error = await res.json();
|
|
347
|
+
throw error;
|
|
348
|
+
}
|
|
349
|
+
return await res.json();
|
|
356
350
|
}
|
|
357
351
|
/**
|
|
358
352
|
* Delete the specified config.
|
|
@@ -360,20 +354,18 @@ class Cobalt {
|
|
|
360
354
|
* @param {String} [configId] The unique ID of the config.
|
|
361
355
|
* @returns {Promise<unknown>}
|
|
362
356
|
*/
|
|
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();
|
|
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
|
+
},
|
|
376
363
|
});
|
|
364
|
+
if (res.status >= 400 && res.status < 600) {
|
|
365
|
+
const error = await res.json();
|
|
366
|
+
throw error;
|
|
367
|
+
}
|
|
368
|
+
return await res.json();
|
|
377
369
|
}
|
|
378
370
|
/**
|
|
379
371
|
* Returns the specified field of the config.
|
|
@@ -382,20 +374,18 @@ class Cobalt {
|
|
|
382
374
|
* @param {String} [workflowId] The unique ID of the workflow.
|
|
383
375
|
* @returns {Promise<Field>} The specified config field.
|
|
384
376
|
*/
|
|
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();
|
|
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
|
+
},
|
|
398
383
|
});
|
|
384
|
+
if (res.status >= 400 && res.status < 600) {
|
|
385
|
+
const error = await res.json();
|
|
386
|
+
throw error;
|
|
387
|
+
}
|
|
388
|
+
return await res.json();
|
|
399
389
|
}
|
|
400
390
|
/**
|
|
401
391
|
* Update the specified config field value.
|
|
@@ -405,23 +395,21 @@ class Cobalt {
|
|
|
405
395
|
* @param {String} [workflowId] The unique ID of the workflow.
|
|
406
396
|
* @returns {Promise<Field>} The updated config field.
|
|
407
397
|
*/
|
|
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();
|
|
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 }),
|
|
424
407
|
});
|
|
408
|
+
if (res.status >= 400 && res.status < 600) {
|
|
409
|
+
const error = await res.json();
|
|
410
|
+
throw error;
|
|
411
|
+
}
|
|
412
|
+
return await res.json();
|
|
425
413
|
}
|
|
426
414
|
/**
|
|
427
415
|
* Delete the specified config field value.
|
|
@@ -430,21 +418,19 @@ class Cobalt {
|
|
|
430
418
|
* @param {String} [workflowId] The unique ID of the workflow.
|
|
431
419
|
* @returns {Promise<unknown>}
|
|
432
420
|
*/
|
|
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();
|
|
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
|
+
},
|
|
447
428
|
});
|
|
429
|
+
if (res.status >= 400 && res.status < 600) {
|
|
430
|
+
const error = await res.json();
|
|
431
|
+
throw error;
|
|
432
|
+
}
|
|
433
|
+
return await res.json();
|
|
448
434
|
}
|
|
449
435
|
/**
|
|
450
436
|
* Returns the options for the specified field.
|
|
@@ -454,25 +440,23 @@ class Cobalt {
|
|
|
454
440
|
* @param {String} [workflowId] The unique ID of the workflow, if this is a workflow field.
|
|
455
441
|
* @returns {Promise<RuleOptions>} The specified rule field's options.
|
|
456
442
|
*/
|
|
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();
|
|
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
|
+
}),
|
|
475
454
|
});
|
|
455
|
+
if (res.status >= 400 && res.status < 600) {
|
|
456
|
+
const error = await res.json();
|
|
457
|
+
throw error;
|
|
458
|
+
}
|
|
459
|
+
return await res.json();
|
|
476
460
|
}
|
|
477
461
|
/**
|
|
478
462
|
* Returns the private workflows for the specified application.
|
|
@@ -486,26 +470,23 @@ class Cobalt {
|
|
|
486
470
|
* @param {Boolean} [params.published] Filter by workflow published status.
|
|
487
471
|
* @returns
|
|
488
472
|
*/
|
|
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();
|
|
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
|
+
},
|
|
508
484
|
});
|
|
485
|
+
if (res.status >= 400 && res.status < 600) {
|
|
486
|
+
const error = await res.json();
|
|
487
|
+
throw error;
|
|
488
|
+
}
|
|
489
|
+
return await res.json();
|
|
509
490
|
}
|
|
510
491
|
/**
|
|
511
492
|
* Create a public workflow for the linked account.
|
|
@@ -516,67 +497,60 @@ class Cobalt {
|
|
|
516
497
|
* If slug isn't set, the workflow will be created in the organization's default application.
|
|
517
498
|
* @returns {Promise<PublicWorkflow>} The created public workflow.
|
|
518
499
|
*/
|
|
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;
|
|
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
|
+
}),
|
|
540
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;
|
|
541
519
|
}
|
|
542
520
|
/**
|
|
543
521
|
* Delete the specified public workflow.
|
|
544
522
|
* @param {String} workflowId The workflow ID.
|
|
545
523
|
* @returns {Promise<unknown>}
|
|
546
524
|
*/
|
|
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();
|
|
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
|
+
},
|
|
560
531
|
});
|
|
532
|
+
if (res.status >= 400 && res.status < 600) {
|
|
533
|
+
const error = await res.json();
|
|
534
|
+
throw error;
|
|
535
|
+
}
|
|
536
|
+
return await res.json();
|
|
561
537
|
}
|
|
562
538
|
/**
|
|
563
539
|
* Returns the execution payload for the specified public workflow.
|
|
564
540
|
* @param {String} workflowId The workflow ID.
|
|
565
541
|
* @returns {Promise<WorkflowPayloadResponse>} The workflow payload response.
|
|
566
542
|
*/
|
|
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();
|
|
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
|
+
},
|
|
579
548
|
});
|
|
549
|
+
if (res.status >= 400 && res.status < 600) {
|
|
550
|
+
const error = await res.json();
|
|
551
|
+
throw error;
|
|
552
|
+
}
|
|
553
|
+
return await res.json();
|
|
580
554
|
}
|
|
581
555
|
/**
|
|
582
556
|
* Execute the specified public workflow.
|
|
@@ -586,24 +560,22 @@ class Cobalt {
|
|
|
586
560
|
* @param {Record<string, any>} [options.payload] The execution payload.
|
|
587
561
|
* @returns {Promise<unknown>}
|
|
588
562
|
*/
|
|
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();
|
|
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),
|
|
606
573
|
});
|
|
574
|
+
if (res.status >= 400 && res.status < 600) {
|
|
575
|
+
const error = await res.json();
|
|
576
|
+
throw error;
|
|
577
|
+
}
|
|
578
|
+
return await res.json();
|
|
607
579
|
}
|
|
608
580
|
/**
|
|
609
581
|
* Returns the workflow execution logs for the linked account.
|
|
@@ -619,45 +591,40 @@ class Cobalt {
|
|
|
619
591
|
* @param {String} [params.execution_source] - Filter by execution source (Event, Schedule, API Call)
|
|
620
592
|
* @returns {Promise<PaginatedResponse<Execution>>} The paginated workflow execution logs.
|
|
621
593
|
*/
|
|
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();
|
|
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
|
+
},
|
|
641
605
|
});
|
|
606
|
+
if (res.status >= 400 && res.status < 600) {
|
|
607
|
+
const error = await res.json();
|
|
608
|
+
throw error;
|
|
609
|
+
}
|
|
610
|
+
return await res.json();
|
|
642
611
|
}
|
|
643
612
|
/**
|
|
644
613
|
* Returns the specified workflow execution log.
|
|
645
614
|
* @param {String} executionId The execution ID.
|
|
646
615
|
* @returns {Promise<Execution>} The specified execution log.
|
|
647
616
|
*/
|
|
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();
|
|
617
|
+
async getExecution(executionId) {
|
|
618
|
+
const res = await fetch(`${this.baseUrl}/api/v2/public/execution/${executionId}`, {
|
|
619
|
+
headers: {
|
|
620
|
+
authorization: `Bearer ${this.token}`,
|
|
621
|
+
},
|
|
660
622
|
});
|
|
623
|
+
if (res.status >= 400 && res.status < 600) {
|
|
624
|
+
const error = await res.json();
|
|
625
|
+
throw error;
|
|
626
|
+
}
|
|
627
|
+
return await res.json();
|
|
661
628
|
}
|
|
662
629
|
}
|
|
663
630
|
exports.Cobalt = Cobalt;
|