diff --git a/.vscode/tasks.json b/.vscode/tasks.json index b68d9ab..ef8bdf5 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -16,11 +16,18 @@ { "label": "dev", "dependsOn": [ + "dev extension", "dev directus", - "dev extension" ], "problemMatcher": [] }, + { + "label": "dev extension", + "command": "npm run dev", + "type": "shell", + "hide": true, + "problemMatcher": [] + }, { "label": "dev directus", "command": "npx directus start", @@ -31,12 +38,5 @@ "hide": true, "problemMatcher": [] }, - { - "label": "dev extension", - "command": "npm run dev", - "type": "shell", - "hide": true, - "problemMatcher": [] - } ] } \ No newline at end of file diff --git a/directus/data.db b/directus/data.db index 4875529..1bf1898 100644 Binary files a/directus/data.db and b/directus/data.db differ diff --git a/package-lock.json b/package-lock.json index 25d6f20..8041c53 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,8 @@ "@directus/extensions": "^3.0.1", "@directus/extensions-sdk": "13.0.1", "@directus/types": "^13.0.0", - "typescript": "^5.7.3", + "@types/node": "^22.13.9", + "typescript": "^5.8.2", "vue": "^3.5.13", "vue-router": "^4.5.0" } @@ -1383,9 +1384,9 @@ "license": "MIT" }, "node_modules/@types/node": { - "version": "22.13.5", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.13.5.tgz", - "integrity": "sha512-+lTU0PxZXn0Dr1NBtC7Y8cR21AJr87dLLU953CWA6pMxxv/UDc7jYAY90upcrie1nRcD6XNG5HOYEDtgW5TxAg==", + "version": "22.13.9", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.13.9.tgz", + "integrity": "sha512-acBjXdRJ3A6Pb3tqnw9HZmyR3Fiol3aGxRCK1x3d+6CDAMjl7I649wpSd+yNURCjbOUGu9tqtLKnTGxmK6CyGw==", "dev": true, "license": "MIT", "dependencies": { @@ -4953,9 +4954,9 @@ } }, "node_modules/typescript": { - "version": "5.7.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.7.3.tgz", - "integrity": "sha512-84MVSjMEHP+FQRPy3pX9sTVV/INIex71s9TL2Gm5FG/WG1SqXeKyZ0k7/blY/4FdOzI12CBy1vGc4og/eus0fw==", + "version": "5.8.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.8.2.tgz", + "integrity": "sha512-aJn6wq13/afZp/jT9QZmwEjDqqvSGp1VT5GVg+f/t6/oVyrgXM6BY1h9BRh/O5p3PlUPAe+WuiEZOmb/49RqoQ==", "dev": true, "license": "Apache-2.0", "bin": { diff --git a/package.json b/package.json index bb516aa..11ca516 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,15 @@ { "type": "layout", "name": "tasks", - "source": "src/tasks/index.js" + "source": "src/tasks/index.ts" + }, + { + "type": "operation", + "name": "windmill", + "source": { + "app": "src/windmill/app.ts", + "api": "src/windmill/api.ts" + } } ], "host": "^10.10.0" @@ -28,10 +36,11 @@ }, "devDependencies": { "@directus/types": "^13.0.0", - "@directus/extensions-sdk": "13.0.1", - "@directus/extensions": "^3.0.1", - "typescript": "^5.7.3", + "@directus/extensions-sdk": "13.0.3", + "@directus/extensions": "^3.0.3", + "typescript": "^5.8.2", "vue": "^3.5.13", - "vue-router": "^4.5.0" + "vue-router": "^4.5.0", + "@types/node": "^22.13.9" } } \ No newline at end of file diff --git a/src/tasks/layout.vue b/src/tasks/layout.vue index ced8a30..b083a9e 100644 --- a/src/tasks/layout.vue +++ b/src/tasks/layout.vue @@ -12,7 +12,7 @@ @click="router.push(`${collection}/${item.id}`)"> @@ -85,7 +85,7 @@ export default defineComponent({ type: Array as PropType, required: true, }, - me: Object, + me: String, } }) diff --git a/src/windmill/api.ts b/src/windmill/api.ts new file mode 100644 index 0000000..91f5647 --- /dev/null +++ b/src/windmill/api.ts @@ -0,0 +1,47 @@ +import { defineOperationApi } from '@directus/extensions-sdk'; + +type Options = { + token: string + instance: string + flow: string +} + +type Data = { + // create and update trigger + event?: string + collection?: string + + // create trigger + key: string + + // update trigger + keys?: string[] + + // manual trigger + body?: { + collection: string + keys: string[] + } +} + +export default defineOperationApi({ + id: 'windmill', + handler: async ({ token, instance, flow }, { data }) => { + const last = data.$last as Data + const body = JSON.stringify({ + event: last.event ?? "manual", + instance: instance, + collection: last.collection ?? last.body?.collection, + keys: last.keys ?? last.body?.keys ?? [last.key] + }) + + return await fetch(`https://windmill.swablab.de/api/r/${flow}`, { + method: 'POST', + headers: { + "Content-Type": "application/json", + "Authorization": `Bearer ${token}` + }, + body + }) + }, +}); diff --git a/src/windmill/app.ts b/src/windmill/app.ts new file mode 100644 index 0000000..a81e50f --- /dev/null +++ b/src/windmill/app.ts @@ -0,0 +1,67 @@ +import { defineOperationApp } from "@directus/extensions-sdk"; + +export default defineOperationApp({ + id: "windmill", + name: "swablab windmill", + icon: "wind_power", + description: "trigger a windmill action", + overview: ({ instance, flow }) => [ + { + label: "Instance", + text: instance, + }, + { + label: "Flow", + text: flow, + }, + ], + options: [ + { + field: "token", + name: "Token", + type: "string", + meta: { + width: "full", + interface: "input", + required: true, + note: "See Vaultwarden", + options: { + masked: true + } + } + }, + { + field: "instance", + name: "Instance", + type: "string", + meta: { + width: "full", + interface: 'select-dropdown', + required: true, + options: { + choices: [ + { + text: 'Directus', + value: 'directus', + }, + { + text: 'Management', + value: 'management', + }, + ], + } + }, + }, + { + field: "flow", + name: "Flow", + type: "string", + meta: { + width: "full", + interface: "input", + required: true, + note: "https://windmill.swablab.de/api/r/..." + }, + }, + ], +}); diff --git a/src/windmill/shims.d.ts b/src/windmill/shims.d.ts new file mode 100644 index 0000000..9923fb6 --- /dev/null +++ b/src/windmill/shims.d.ts @@ -0,0 +1,5 @@ +declare module '*.vue' { + import { DefineComponent } from 'vue'; + const component: DefineComponent<{}, {}, any>; + export default component; +}