//native
type Kustomer = {
apiKey: string;
};
/**
* Create a workflow
* Creats a new workflow.
*/
export async function main(
auth: Kustomer,
body: {
name: string;
replaces?: string;
description?: string;
meta?: {};
trigger?:
| {
id: string;
eventName?: string;
callable: false | true;
schema: {};
meta?: {};
transitions: {
meta?: {};
target: string;
condition: {
op:
| "and"
| "or"
| "exists"
| "dne"
| "true"
| "false"
| "eq"
| "neq"
| "gt"
| "gte"
| "lt"
| "lte"
| "lt-date"
| "gt-date"
| "contains"
| "not-contains";
values: unknown[];
};
}[];
}
| {
id: string;
appVersion?: string;
meta?: {};
eventName: string;
transitions: {
meta?: {};
target: string;
condition: {
op:
| "and"
| "or"
| "exists"
| "dne"
| "true"
| "false"
| "eq"
| "neq"
| "gt"
| "gte"
| "lt"
| "lte"
| "lt-date"
| "gt-date"
| "contains"
| "not-contains";
values: unknown[];
};
}[];
};
steps?: {
id: string;
appVersion?: string;
meta?: {};
action?: string;
params?: {};
transitions: {
meta?: {};
target: string;
condition: {
op:
| "and"
| "or"
| "exists"
| "dne"
| "true"
| "false"
| "eq"
| "neq"
| "gt"
| "gte"
| "lt"
| "lte"
| "lt-date"
| "gt-date"
| "contains"
| "not-contains";
values: unknown[];
};
}[];
errorCases?: {
condition: { op: "and" | "or"; values: unknown[] };
errorAction: {
type?:
| "continue"
| "retry-workflow"
| "retry-action"
| "stop-processing";
};
}[];
}[];
enabled?: false | true;
logging?: false | true;
},
) {
const url = new URL(`https://api.kustomerapp.com/v1/workflows`);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.apiKey,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 235 days ago