n8n-nodes-cervio 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ # MIT License
2
+
3
+ Copyright (c) Cervio
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,176 @@
1
- # Temporary Holding Version
1
+ # n8n-nodes-cervio
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Community node for [n8n](https://n8n.io/) that talks to a [Cervio](https://cervio.app) tenant over the public REST API (`/api/v1`).
4
+
5
+ One node (**Cervio**) + one credential (**Cervio API**). Field lists come from the form write-schema (resource mapper), not free-form JSON. Marked `usableAsTool: true` for n8n AI Agent tools.
6
+
7
+ | | |
8
+ |--|--|
9
+ | Package | `n8n-nodes-cervio` |
10
+ | Version | see `package.json` / [Releases](https://github.com/cervio-app/n8n-nodes-cervio/releases) |
11
+ | License | [MIT](./LICENSE.md) |
12
+
13
+ ## Quick start
14
+
15
+ 1. Create a PAT in Cervio **Admin → API** (see [Permissions](#permissions)).
16
+ 2. In n8n, add credential **Cervio API**:
17
+ - **Base URL** = tenant host only, e.g. `https://acme.cervio.app` (required; no default)
18
+ - **Personal Access Token** = `cpat_…`
19
+ 3. Drop a **Cervio** node and pick an operation.
20
+
21
+ ### Install (local / custom extensions)
22
+
23
+ ```bash
24
+ git clone https://github.com/cervio-app/n8n-nodes-cervio.git
25
+ cd n8n-nodes-cervio
26
+ npm install && npm run build
27
+ npm link
28
+
29
+ mkdir -p ~/.n8n/custom && cd ~/.n8n/custom
30
+ npm link n8n-nodes-cervio
31
+ ```
32
+
33
+ Restart n8n. Or run a disposable n8n against this folder:
34
+
35
+ ```bash
36
+ npm run build
37
+ docker compose up
38
+ # → http://localhost:5678 (N8N_CUSTOM_EXTENSIONS mounts this repo)
39
+ ```
40
+
41
+ ### Cover / demo screenshot
42
+
43
+ Import a 2-node workflow (Manual Trigger → Cervio), attach your credential, pick Entity/View (or Form), zoom the canvas, screenshot:
44
+
45
+ | File | Use |
46
+ |------|-----|
47
+ | [`examples/cover-demo.workflow.json`](./examples/cover-demo.workflow.json) | **List view** — clean cover (recommended) |
48
+ | [`examples/cover-demo-create.workflow.json`](./examples/cover-demo-create.workflow.json) | **Create** — shows the guided field mapper |
49
+
50
+ In n8n: **⋯ → Import from File** → select the JSON → set **Cervio API** credential → choose Entity + View/Form.
51
+
52
+ ## Operations
53
+
54
+ | Group | Operation (`value`) | API (summary) | Typical scopes |
55
+ |-------|---------------------|---------------|----------------|
56
+ | Records | `create` | `POST …/entities/{id}/records` | `records:write` |
57
+ | | `update` | `PATCH …/records/{id}` (+ optional `multi_value_modes`) | `records:write` |
58
+ | | `get` | `GET …/records/{id}` | `records:read` |
59
+ | | `delete` | `DELETE …/records/{id}` (soft) | `records:write` |
60
+ | | `upsert` | `POST …/records/upsert` (`match_field`) | `records:write` |
61
+ | | `validateDraft` | `POST …/forms/{name}/validate-draft` | `records:write`¹ |
62
+ | | `listView` | `GET …/views/{id}/records` (cursor pages) | `records:read` |
63
+ | | `listRecords` | `GET …/entities/{id}/records` (`filter[f]=eq.x`, **admin**) | `records:read` + `system_admin` |
64
+ | Relations | `searchRelation` | `GET …/relation-options?q=&limit=` | `records:read` |
65
+ | | `resolveRelation` | `POST …/resolve` | `records:read` |
66
+ | | `linkRecords` / `unlinkRecords` | `POST`/`DELETE …/fields/{through}/links` | `records:write` |
67
+ | Documents | `listDocuments` | `GET …/documents` | `records:read` |
68
+ | | `uploadDocument` | `POST …/documents` (multipart / binary) | `records:write` |
69
+ | | `openDocument` | `GET …/documents/{id}/open` → `signed_url` | `records:read` |
70
+ | | `generateDocument` | `POST …/documents/generate` | `admin:write` + `system_admin` |
71
+ | Workflows | `startWorkflow` | `POST …/workflows/{id}/runs` | `records:write` + trigger ACL |
72
+ | | `getWorkflowRun` | `GET …/admin/workflows/{id}/runs/{runId}` | `admin:read` + `system_admin` |
73
+
74
+ ¹ Route uses the write-scope guard; dry-run does not persist.
75
+
76
+ **Notes**
77
+
78
+ - Create / Update / Upsert / Validate draft: pick **Entity** → **Form**, then the resource mapper.
79
+ - N:M **through** fields are not on the mapper — use **Link / Unlink** (or Create on the junction entity).
80
+ - Relation dropdowns are capped (~50); use **Search relation** for larger sets.
81
+ - List view defaults: options = slugs, relations = uuids (ready for Update).
82
+ - Generate document: paste a mapped **template UUID** (no public template catalog in v1 yet).
83
+
84
+ ## Permissions
85
+
86
+ There is **no n8n-specific ACL** in Cervio. The node is a REST client; Cervio applies **two layers**. Both must allow the call.
87
+
88
+ ```text
89
+ n8n ──Bearer cpat_…──► 1) PAT scopes (Admin → API)
90
+ │ fail → 401 / scope error
91
+ ▼
92
+ 2) User who owns the PAT (same ACL as UI)
93
+ │ fail → 403 / 404 / empty / validation
94
+ ```
95
+
96
+ ### Layer 1 — Token scopes
97
+
98
+ | Scope | Opens (in this node) |
99
+ |-------|----------------------|
100
+ | `records:read` | Get, List view/records, Search/Resolve relation, List/Open documents |
101
+ | `records:write` | Create, Update, Delete, Upsert, Validate draft, Upload, Link/Unlink, Start workflow |
102
+ | `admin:read` | Form / view / workflow **dropdowns**, Get workflow run |
103
+ | `admin:write` | Generate document from template |
104
+
105
+ `*:write` implies the matching `*:read`. Scopes alone do **not** grant row access or `can_create`.
106
+
107
+ ### Layer 2 — User behind the PAT
108
+
109
+ The PAT impersonates its owner. Entity permissions, record policies, field denials, form/view assignments, document capabilities, and manual-workflow trigger roles still apply — same as the UI.
110
+
111
+ Example: PAT has `records:write` but the user has no `can_create` on the entity → **Create fails**.
112
+
113
+ | Setup | PAT owner | Scopes |
114
+ |-------|-----------|--------|
115
+ | Full guided UX (all pickers, generate, run status, List records) | `system_admin` | `admin:read`, `admin:write`, `records:read`, `records:write` |
116
+ | Narrow sync via assigned views/forms | Service user with that ACL | `records:read` / `records:write` only; prefer **List view**; paste ids if you skip admin pickers |
117
+
118
+ ## Repository layout
119
+
120
+ ```text
121
+ credentials/ Cervio API credential + icons
122
+ nodes/Cervio/ Node implementation, helpers, icons, unit tests
123
+ __tests__/ Vitest (write-schema → resource mapper)
124
+ examples/ Importable demo workflows (cover screenshots)
125
+ scripts/ build helpers + live smoke (optional)
126
+ .github/workflows/ CI + npm publish (dispatch until Trusted Publishing)
127
+ compose.yaml Local n8n with this package mounted
128
+ Dockerfile Optional image that bakes the node into n8n
129
+ types/ Ambient stubs for n8n-workflow (compile without native deps)
130
+ ```
131
+
132
+ Published npm package contents: `dist/` only (`package.json` → `files`).
133
+
134
+ ## Development
135
+
136
+ ```bash
137
+ npm install
138
+ npm run build # tsc + copy icons
139
+ npm test # unit tests
140
+ npm run verify # load compiled node + credential offline
141
+ npm run lint # tsc --noEmit
142
+ ```
143
+
144
+ Conventions, SemVer tags (`vX.Y.Z`), and npm publish: [CONTRIBUTING.md](./CONTRIBUTING.md).
145
+
146
+ ### Live smoke (optional)
147
+
148
+ Against a real tenant (copy [`.env.example`](./.env.example)):
149
+
150
+ ```bash
151
+ export CERVIO_BASE_URL=https://YOUR_TENANT.cervio.app
152
+ export CERVIO_PAT=cpat_…
153
+ npm run smoke # create / list view / update
154
+ npm run smoke:extended # get, upsert, resolve, upload/open, N:M link, workflows
155
+ npm run smoke:relations # heavier relation/multivalue lab fixtures
156
+ ```
157
+
158
+ | Script | Notes |
159
+ |--------|--------|
160
+ | `smoke:extended` | Requires Wave B routes on the tenant. Unlink needs the PAT junction-listing fix on Cervio. Generate skips without a real template id. Start workflow skips without manual-trigger ACL. |
161
+ | `CERVIO_SMOKE_KEEP=1` | Leave created records |
162
+ | `CERVIO_SMOKE_DELETE_ID` | Also soft-delete another disposable id |
163
+
164
+ ## Known limits
165
+
166
+ - **List records** without a view is admin-only — partners should use **List view**
167
+ - Nested child create = two Creates (parent, then child with FK)
168
+ - Lookup-only view columns are labels, not UUIDs — use Search relation / Get for ids
169
+ - List view “all pages”: max 10 × 500 rows
170
+
171
+ ## References
172
+
173
+ - [Cervio](https://cervio.app)
174
+ - Tenant OpenAPI: `public/openapi/v1.yaml` in the Cervio app repo
175
+ - [n8n community nodes](https://docs.n8n.io/integrations/community-nodes/)
176
+ - [Building community nodes](https://docs.n8n.io/integrations/community-nodes/building-community-nodes/)
@@ -0,0 +1,10 @@
1
+ import type { IAuthenticateGeneric, Icon, ICredentialTestRequest, ICredentialType, INodeProperties } from 'n8n-workflow';
2
+ export declare class CervioApi implements ICredentialType {
3
+ name: string;
4
+ displayName: string;
5
+ icon: Icon;
6
+ documentationUrl: string;
7
+ properties: INodeProperties[];
8
+ authenticate: IAuthenticateGeneric;
9
+ test: ICredentialTestRequest;
10
+ }
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CervioApi = void 0;
4
+ class CervioApi {
5
+ constructor() {
6
+ this.name = 'cervioApi';
7
+ this.displayName = 'Cervio API';
8
+ this.icon = {
9
+ light: 'file:cervio.mono.light.svg',
10
+ dark: 'file:cervio.mono.dark.svg',
11
+ };
12
+ this.documentationUrl = 'https://github.com/cervio-app/n8n-nodes-cervio#readme';
13
+ this.properties = [
14
+ {
15
+ displayName: 'Base URL',
16
+ name: 'baseUrl',
17
+ type: 'string',
18
+ default: '',
19
+ placeholder: 'https://tenant.cervio.app',
20
+ required: true,
21
+ description: 'URL dell’istanza Cervio del tenant, senza slash finale (es. https://acme.cervio.app). Va impostata per ogni credenziale.',
22
+ },
23
+ {
24
+ displayName: 'Personal Access Token',
25
+ name: 'apiKey',
26
+ type: 'string',
27
+ typeOptions: { password: true },
28
+ default: '',
29
+ required: true,
30
+ placeholder: 'cpat_…',
31
+ description: 'Token creato in Admin → API. Consigliato: admin:read + admin:write + records:read + records:write (system_admin) per tendine, workflow, generate documento e scritture.',
32
+ },
33
+ ];
34
+ this.authenticate = {
35
+ type: 'generic',
36
+ properties: {
37
+ headers: {
38
+ Accept: 'application/json',
39
+ Authorization: '=Bearer {{$credentials.apiKey}}',
40
+ },
41
+ },
42
+ };
43
+ this.test = {
44
+ request: {
45
+ baseURL: '={{$credentials.baseUrl}}',
46
+ url: '/api/v1/me',
47
+ },
48
+ };
49
+ }
50
+ }
51
+ exports.CervioApi = CervioApi;
52
+ //# sourceMappingURL=CervioApi.credentials.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CervioApi.credentials.js","sourceRoot":"","sources":["../../credentials/CervioApi.credentials.ts"],"names":[],"mappings":";;;AAQA,MAAa,SAAS;IAAtB;QACC,SAAI,GAAG,WAAW,CAAC;QAEnB,gBAAW,GAAG,YAAY,CAAC;QAE3B,SAAI,GAAS;YACZ,KAAK,EAAE,4BAA4B;YACnC,IAAI,EAAE,2BAA2B;SACjC,CAAC;QAEF,qBAAgB,GAAG,uDAAuD,CAAC;QAE3E,eAAU,GAAsB;YAC/B;gBACC,WAAW,EAAE,UAAU;gBACvB,IAAI,EAAE,SAAS;gBACf,IAAI,EAAE,QAAQ;gBACd,OAAO,EAAE,EAAE;gBACX,WAAW,EAAE,2BAA2B;gBACxC,QAAQ,EAAE,IAAI;gBACd,WAAW,EACV,0HAA0H;aAC3H;YACD;gBACC,WAAW,EAAE,uBAAuB;gBACpC,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE;gBAC/B,OAAO,EAAE,EAAE;gBACX,QAAQ,EAAE,IAAI;gBACd,WAAW,EAAE,QAAQ;gBACrB,WAAW,EACV,yKAAyK;aAC1K;SACD,CAAC;QAEF,iBAAY,GAAyB;YACpC,IAAI,EAAE,SAAS;YACf,UAAU,EAAE;gBACX,OAAO,EAAE;oBACR,MAAM,EAAE,kBAAkB;oBAC1B,aAAa,EAAE,iCAAiC;iBAChD;aACD;SACD,CAAC;QAEF,SAAI,GAA2B;YAC9B,OAAO,EAAE;gBACR,OAAO,EAAE,2BAA2B;gBACpC,GAAG,EAAE,YAAY;aACjB;SACD,CAAC;IACH,CAAC;CAAA;AApDD,8BAoDC"}
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 60 60" width="60" height="60">
3
+ <g transform="translate(8.355,16.62)">
4
+ <path fill="#e2e2e2" d="M17.99,14.53c.54-.36,1.01-.56,1.25-.66.76-.3,1.59-.47,2.46-.47h19.63c1.08,0,1.96-.88,1.96-1.96V1.96c0-1.09-.88-1.96-1.96-1.96h-14.86c-.66,0-1.29.13-1.87.36-.18.07-.54.23-.95.5-.09.06-.43.29-.77.63-.51.51-.77.99-1.09,1.61-.05.09-.44.84-.87,1.69-.34.66-.71,1.38-.97,1.91-.65,1.27-1.28,2.47-1.35,2.6-.42.81-.76,1.45-1.43,2.12-.45.45-.9.75-1.02.83-.54.36-1.01.56-1.25.66-.76.3-1.59.47-2.46.47H1.97s0,0,0,0,0,0,0,0c-1.08,0-1.96.88-1.96,1.96v9.45c0,1.08.86,1.95,1.93,1.96,0,0,.02,0,.03,0s.02,0,.03,0h5.69c.66,0,1.29-.13,1.87-.36.18-.07.54-.23.95-.5.09-.06.43-.29.77-.63.51-.51.77-.99,1.09-1.61.06-.11.61-1.18,1.15-2.23.15-.3.3-.6.44-.87.73-1.43,1.51-2.93,1.59-3.09.42-.81.76-1.45,1.43-2.12.45-.44.9-.75,1.02-.83Z"/>
5
+ <path fill="#e2e2e2" d="M43.29,18.55c0-1.08-.87-1.95-1.95-1.95h-18.65c-.66,0-1.29.13-1.87.36-.18.07-.54.23-.95.5-.09.06-.43.29-.77.63-.51.51-.77.99-1.09,1.61-.11.21-2.01,3.86-2.18,4.3-.04.11-.07.22-.07.22-.03.12-.09.32-.09.59,0,.54.22,1.02.57,1.38.35.35.84.57,1.38.57h23.72c1.07,0,1.95-.87,1.95-1.95,0,0,0,0,0,0v-6.26s0,0,0,0Z"/>
6
+ </g>
7
+ </svg>
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 60 60" width="60" height="60">
3
+ <g transform="translate(8.355,16.62)">
4
+ <path fill="#333333" d="M17.99,14.53c.54-.36,1.01-.56,1.25-.66.76-.3,1.59-.47,2.46-.47h19.63c1.08,0,1.96-.88,1.96-1.96V1.96c0-1.09-.88-1.96-1.96-1.96h-14.86c-.66,0-1.29.13-1.87.36-.18.07-.54.23-.95.5-.09.06-.43.29-.77.63-.51.51-.77.99-1.09,1.61-.05.09-.44.84-.87,1.69-.34.66-.71,1.38-.97,1.91-.65,1.27-1.28,2.47-1.35,2.6-.42.81-.76,1.45-1.43,2.12-.45.45-.9.75-1.02.83-.54.36-1.01.56-1.25.66-.76.3-1.59.47-2.46.47H1.97s0,0,0,0,0,0,0,0c-1.08,0-1.96.88-1.96,1.96v9.45c0,1.08.86,1.95,1.93,1.96,0,0,.02,0,.03,0s.02,0,.03,0h5.69c.66,0,1.29-.13,1.87-.36.18-.07.54-.23.95-.5.09-.06.43-.29.77-.63.51-.51.77-.99,1.09-1.61.06-.11.61-1.18,1.15-2.23.15-.3.3-.6.44-.87.73-1.43,1.51-2.93,1.59-3.09.42-.81.76-1.45,1.43-2.12.45-.44.9-.75,1.02-.83Z"/>
5
+ <path fill="#333333" d="M43.29,18.55c0-1.08-.87-1.95-1.95-1.95h-18.65c-.66,0-1.29.13-1.87.36-.18.07-.54.23-.95.5-.09.06-.43.29-.77.63-.51.51-.77.99-1.09,1.61-.11.21-2.01,3.86-2.18,4.3-.04.11-.07.22-.07.22-.03.12-.09.32-.09.59,0,.54.22,1.02.57,1.38.35.35.84.57,1.38.57h23.72c1.07,0,1.95-.87,1.95-1.95,0,0,0,0,0,0v-6.26s0,0,0,0Z"/>
6
+ </g>
7
+ </svg>
@@ -0,0 +1,20 @@
1
+ import type { IExecuteFunctions, ILoadOptionsFunctions, INodeExecutionData, INodePropertyOptions, INodeType, INodeTypeDescription, ResourceMapperFields } from 'n8n-workflow';
2
+ export declare class Cervio implements INodeType {
3
+ description: INodeTypeDescription;
4
+ methods: {
5
+ loadOptions: {
6
+ getEntities(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]>;
7
+ getForms(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]>;
8
+ getViews(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]>;
9
+ getRelationFields(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]>;
10
+ getThroughFields(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]>;
11
+ getMatchFields(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]>;
12
+ getWorkflows(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]>;
13
+ };
14
+ resourceMapping: {
15
+ getFormFieldsCreate(this: ILoadOptionsFunctions): Promise<ResourceMapperFields>;
16
+ getFormFieldsUpdate(this: ILoadOptionsFunctions): Promise<ResourceMapperFields>;
17
+ };
18
+ };
19
+ execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]>;
20
+ }