This repository has been archived on 2026-04-03. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
core/src/js/workflow-api.js
Jeffrey Smith 7f191e18cd Changeset 0.29.3 (#198)
Co-authored-by: Jeffrey Smith <jasafpro@gmail.com>
Co-committed-by: Jeffrey Smith <jasafpro@gmail.com>
2026-03-18 00:15:18 +00:00

108 lines
3.8 KiB
JavaScript

// ==========================================
// Chat Switchboard — Workflow API Methods
// ==========================================
// Extends the global API object with workflow CRUD, stage management,
// publishing, instance lifecycle, and assignment queue operations.
// Loaded after api.js on the chat and admin surfaces.
// ── Workflow Definitions ────────────────
API.listWorkflows = function(teamId) {
const q = teamId ? `?team_id=${teamId}` : '';
return this._get('/api/v1/workflows' + q);
};
API.getWorkflow = function(id) {
return this._get(`/api/v1/workflows/${id}`);
};
API.createWorkflow = function(data) {
return this._post('/api/v1/workflows', data);
};
API.updateWorkflow = function(id, patch) {
return this._patch(`/api/v1/workflows/${id}`, patch);
};
API.deleteWorkflow = function(id) {
return this._del(`/api/v1/workflows/${id}`);
};
// ── Stages ──────────────────────────────
API.listStages = function(workflowId) {
return this._get(`/api/v1/workflows/${workflowId}/stages`);
};
API.createStage = function(workflowId, data) {
return this._post(`/api/v1/workflows/${workflowId}/stages`, data);
};
API.updateStage = function(workflowId, stageId, data) {
return this._put(`/api/v1/workflows/${workflowId}/stages/${stageId}`, data);
};
API.deleteStage = function(workflowId, stageId) {
return this._del(`/api/v1/workflows/${workflowId}/stages/${stageId}`);
};
API.reorderStages = function(workflowId, orderedIds) {
return this._patch(`/api/v1/workflows/${workflowId}/stages/reorder`, { ordered_ids: orderedIds });
};
// ── Versioning ──────────────────────────
API.publishWorkflow = function(workflowId) {
return this._post(`/api/v1/workflows/${workflowId}/publish`, {});
};
API.getWorkflowVersion = function(workflowId, version) {
return this._get(`/api/v1/workflows/${workflowId}/versions/${version}`);
};
// ── Instances ───────────────────────────
API.startWorkflow = function(workflowId) {
return this._post(`/api/v1/workflows/${workflowId}/start`, {});
};
API.getWorkflowStatus = function(channelId) {
return this._get(`/api/v1/channels/${channelId}/workflow/status`);
};
API.advanceWorkflow = function(channelId, data) {
return this._post(`/api/v1/channels/${channelId}/workflow/advance`, { data });
};
API.rejectWorkflow = function(channelId, reason) {
return this._post(`/api/v1/channels/${channelId}/workflow/reject`, { reason });
};
// ── Forms ────────────────────────────────
API.getWorkflowForm = function(channelId) {
return this._get(`/api/v1/w/${channelId}/form`);
};
API.submitWorkflowForm = function(channelId, data) {
return this._post(`/api/v1/w/${channelId}/form-submit`, data);
};
// ── Assignments ─────────────────────────
API.listMyAssignments = function() {
return this._get('/api/v1/workflow-assignments/mine');
};
API.listTeamAssignments = function(teamId, status) {
return this._get(`/api/v1/teams/${teamId}/assignments?status=${status || 'unassigned'}`);
};
API.claimAssignment = function(id) {
return this._post(`/api/v1/workflow-assignments/${id}/claim`, {});
};
API.completeAssignment = function(id) {
return this._post(`/api/v1/workflow-assignments/${id}/complete`, {});
};