- 6 new PocketBase migrations: customer_pos, customer_po_lines, invoices, invoice_items, email_inbox, workflow_runs - n8N workflow JSON: 01-customer-po-to-parsed.json + 02-parsed-po-to-invoice.json - MCP server config (.cursor/mcp.json + .mcp.json) for AI agent PB access - .env.example template with all required credentials documented - n8n/README.md with deployment, testing, and customization notes
175 lines
No EOL
4.5 KiB
JavaScript
175 lines
No EOL
4.5 KiB
JavaScript
/// <reference path="../pb_data/types.d.ts" />
|
|
|
|
// =========================================================================
|
|
// email_inbox — every email the n8N IMAP trigger sees, audit trail
|
|
// =========================================================================
|
|
//
|
|
// Even emails we ignore (no PDF, wrong sender, auto-reply, bounce) get a
|
|
// record here so we have a paper trail. n8N writes one row per email before
|
|
// branching on whether to process it.
|
|
// =========================================================================
|
|
|
|
migrate((app) => {
|
|
const cpoCol = app.findCollectionByNameOrId("customer_pos");
|
|
|
|
const collection = new Collection({
|
|
"createRule": "@request.auth.id != ''",
|
|
"deleteRule": "@request.auth.id != ''",
|
|
"listRule": "@request.auth.id != ''",
|
|
"name": "email_inbox",
|
|
"system": false,
|
|
"type": "base",
|
|
"updateRule": "@request.auth.id != ''",
|
|
"viewRule": "@request.auth.id != ''",
|
|
"fields": [
|
|
{
|
|
"autogeneratePattern": "",
|
|
"hidden": false,
|
|
"id": "txt_inbox_uid",
|
|
"max": 200,
|
|
"min": 0,
|
|
"name": "imap_uid",
|
|
"pattern": "",
|
|
"presentable": false,
|
|
"primaryKey": false,
|
|
"required": false,
|
|
"system": false,
|
|
"type": "text"
|
|
},
|
|
{
|
|
"autogeneratePattern": "",
|
|
"hidden": false,
|
|
"id": "txt_inbox_from",
|
|
"max": 500,
|
|
"min": 0,
|
|
"name": "from",
|
|
"pattern": "",
|
|
"presentable": false,
|
|
"primaryKey": false,
|
|
"required": false,
|
|
"system": false,
|
|
"type": "text"
|
|
},
|
|
{
|
|
"autogeneratePattern": "",
|
|
"hidden": false,
|
|
"id": "txt_inbox_subject",
|
|
"max": 500,
|
|
"min": 0,
|
|
"name": "subject",
|
|
"pattern": "",
|
|
"presentable": false,
|
|
"primaryKey": false,
|
|
"required": false,
|
|
"system": false,
|
|
"type": "text"
|
|
},
|
|
{
|
|
"autogeneratePattern": "",
|
|
"hidden": false,
|
|
"id": "txt_inbox_to",
|
|
"max": 500,
|
|
"min": 0,
|
|
"name": "to",
|
|
"pattern": "",
|
|
"presentable": false,
|
|
"primaryKey": false,
|
|
"required": false,
|
|
"system": false,
|
|
"type": "text"
|
|
},
|
|
{
|
|
"autogeneratePattern": "",
|
|
"hidden": false,
|
|
"id": "txt_inbox_body",
|
|
"max": 200000,
|
|
"min": 0,
|
|
"name": "body_plain",
|
|
"pattern": "",
|
|
"presentable": false,
|
|
"primaryKey": false,
|
|
"required": false,
|
|
"system": false,
|
|
"type": "text"
|
|
},
|
|
{
|
|
"hidden": false,
|
|
"id": "dt_inbox_received",
|
|
"max": "",
|
|
"min": "",
|
|
"name": "received_at",
|
|
"presentable": false,
|
|
"required": false,
|
|
"system": false,
|
|
"type": "date"
|
|
},
|
|
{
|
|
"hidden": false,
|
|
"id": "bool_inbox_has_attachments",
|
|
"name": "has_attachments",
|
|
"presentable": false,
|
|
"required": false,
|
|
"system": false,
|
|
"type": "bool"
|
|
},
|
|
{
|
|
"autogeneratePattern": "",
|
|
"hidden": false,
|
|
"id": "txt_inbox_attachment_names",
|
|
"max": 2000,
|
|
"min": 0,
|
|
"name": "attachment_names",
|
|
"pattern": "",
|
|
"presentable": false,
|
|
"primaryKey": false,
|
|
"required": false,
|
|
"system": false,
|
|
"type": "text"
|
|
},
|
|
{
|
|
"hidden": false,
|
|
"id": "sel_inbox_disposition",
|
|
"maxSelect": 1,
|
|
"name": "disposition",
|
|
"presentable": true,
|
|
"required": false,
|
|
"system": false,
|
|
"type": "select",
|
|
"values": ["processed", "ignored", "duplicate", "error", "manual_review"]
|
|
},
|
|
{
|
|
"cascadeDelete": false,
|
|
"collectionId": cpoCol.id,
|
|
"hidden": false,
|
|
"id": "rel_inbox_cpo",
|
|
"maxSelect": 1,
|
|
"minSelect": 0,
|
|
"name": "linked_customer_po",
|
|
"presentable": false,
|
|
"required": false,
|
|
"system": false,
|
|
"type": "relation"
|
|
},
|
|
{
|
|
"autogeneratePattern": "",
|
|
"hidden": false,
|
|
"id": "txt_inbox_error",
|
|
"max": 0,
|
|
"min": 0,
|
|
"name": "error_message",
|
|
"pattern": "",
|
|
"presentable": false,
|
|
"primaryKey": false,
|
|
"required": false,
|
|
"system": false,
|
|
"type": "text"
|
|
}
|
|
],
|
|
"indexes": []
|
|
});
|
|
|
|
return app.save(collection);
|
|
}, (app) => {
|
|
const collection = app.findCollectionByNameOrId("email_inbox");
|
|
return app.delete(collection);
|
|
}) |