@oneclick.dev/sdk
Version:
The OneClick Studio SDK
36 lines (35 loc) • 1.22 kB
JavaScript
class FlowClient {
constructor(config) {
const { endpoint, key, project } = config;
if (!endpoint || !key || !project) {
throw new Error('Missing required configuration: endpoint, key, or project.');
}
this.endpoint = endpoint;
this.key = key;
this.project = project;
}
/**
* Fires a flow by name with optional dynamic parameters.
*
* @param flowName The name/slug of the flow to trigger
* @param payload Any dynamic data to pass to the flow
*/
async fire({ flowName, payload }) {
if (!flowName) {
throw new Error('Missing required field: flowName.');
}
const response = await fetch(`${this.endpoint}/api/v1/projects/${this.project}/flows/${flowName}/fire`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${this.key}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(payload)
});
if (!response.ok) {
const text = await response.text();
throw new Error(`Flow trigger failed: ${response.status} ${text}`);
}
}
}
export default FlowClient;