n8n-nodes-mesharc 0.1.1 → 0.2.1
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/README.md +32 -8
- package/dist/nodes/MeshArc/GenericFunctions.d.ts +4 -2
- package/dist/nodes/MeshArc/GenericFunctions.js +19 -0
- package/dist/nodes/MeshArc/GenericFunctions.js.map +1 -1
- package/dist/nodes/MeshArcTrigger/MeshArcTrigger.node.d.ts +3 -10
- package/dist/nodes/MeshArcTrigger/MeshArcTrigger.node.js +9 -96
- package/dist/nodes/MeshArcTrigger/MeshArcTrigger.node.js.map +1 -1
- package/dist/nodes/MeshArcTrigger/v1/MeshArcTriggerV1.d.ts +12 -0
- package/dist/nodes/MeshArcTrigger/v1/MeshArcTriggerV1.js +108 -0
- package/dist/nodes/MeshArcTrigger/v1/MeshArcTriggerV1.js.map +1 -0
- package/dist/nodes/MeshArcTrigger/v2/MeshArcTriggerV2.d.ts +19 -0
- package/dist/nodes/MeshArcTrigger/v2/MeshArcTriggerV2.js +149 -0
- package/dist/nodes/MeshArcTrigger/v2/MeshArcTriggerV2.js.map +1 -0
- package/dist/package.json +10 -3
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -3
package/README.md
CHANGED
|
@@ -11,14 +11,22 @@ Both can also be used as tools by n8n's AI Agent.
|
|
|
11
11
|
|
|
12
12
|
## Installation
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
MeshArc is a verified community node, so it installs from inside n8n, on n8n Cloud or self-hosted:
|
|
15
|
+
|
|
16
|
+
1. Open a workflow and the nodes panel (**+**, or press **N**).
|
|
17
|
+
2. Search for **MeshArc**. It appears under **More from the community**.
|
|
18
|
+
3. Select it and click **Install**.
|
|
19
|
+
|
|
20
|
+
Only an instance owner or admin can install it; after that, every member of the instance can use it. See n8n's guide to [installing verified community nodes](https://docs.n8n.io/integrations/community-nodes/installation-and-management/install-verified-community-nodes).
|
|
21
|
+
|
|
22
|
+
**Self-hosted, with verified nodes switched off?** An owner or admin can install it from npm instead: go to **Settings → Community Nodes → Install**, enter `n8n-nodes-mesharc`, and confirm. See n8n's [GUI installation guide](https://docs.n8n.io/integrations/community-nodes/installation-and-management/gui-installation).
|
|
15
23
|
|
|
16
24
|
## Credentials
|
|
17
25
|
|
|
18
26
|
You need a MeshArc API key.
|
|
19
27
|
|
|
20
28
|
1. Sign in at [mesharc.dev](https://mesharc.dev). The free plan includes 1,000 credits with no card.
|
|
21
|
-
2. Go to **Settings → API keys** and create a key. Scraping, crawling, mapping and
|
|
29
|
+
2. Go to **Settings → API keys** and create a key. Scraping, crawling, mapping, searching and the instant trigger need a key that can **write**. A read-only key can only use **Get Changes** and the polling trigger (version 1).
|
|
22
30
|
3. In n8n, create a **MeshArc API** credential and paste the key. n8n tests it straight away.
|
|
23
31
|
|
|
24
32
|
## Operations
|
|
@@ -39,14 +47,20 @@ For Scrape, Crawl and Get Crawl, turn **Simplify** off to get MeshArc's full res
|
|
|
39
47
|
**MeshArc Trigger → Page Changed** starts the workflow when a run of a MeshArc project finds changed pages.
|
|
40
48
|
|
|
41
49
|
1. In MeshArc, create a project for the site you want to watch, and give it a schedule (hourly, daily, weekly). MeshArc crawls on that schedule and records what changed.
|
|
42
|
-
2. In n8n, add **MeshArc Trigger**. Pick the **Project**, choose which **Changes** start the workflow (Added, Modified, Removed, Fields Changed)
|
|
50
|
+
2. In n8n, add **MeshArc Trigger**. Pick the **Project**, and choose which **Changes** start the workflow (Added, Modified, Removed, Fields Changed).
|
|
51
|
+
3. Activate the workflow.
|
|
52
|
+
|
|
53
|
+
**It is instant.** Activating the workflow subscribes it to the project in MeshArc, and MeshArc sends each finished run to n8n as soon as its changes are recorded. Deactivating the workflow removes the subscription. This needs an n8n that MeshArc can reach from the internet: n8n Cloud, or a self-hosted n8n with a public URL. An n8n on `localhost` cannot be reached.
|
|
43
54
|
|
|
44
55
|
**How it behaves:**
|
|
45
56
|
- **Each changed page is one item:** kind, URL, title, words added and removed, word counts, project, run, and time.
|
|
46
|
-
- **Activating it reports nothing old.**
|
|
47
|
-
- **
|
|
48
|
-
- **
|
|
49
|
-
- **
|
|
57
|
+
- **Activating it reports nothing old.** Only runs that finish after that start the workflow.
|
|
58
|
+
- **A run that changed nothing starts nothing,** and neither does a project's first run, which has nothing to compare with.
|
|
59
|
+
- **Only MeshArc can start it.** Each subscription has its own signing secret, and a message without a valid signature is refused.
|
|
60
|
+
- **Your project's own webhook is not touched.** The subscription is separate, so a webhook URL you set in MeshArc keeps working.
|
|
61
|
+
- **Listen for Test Event** waits for the project's next finished run.
|
|
62
|
+
|
|
63
|
+
**Workflows made with version 1 keep polling.** Before 0.2.0, the trigger checked MeshArc on a schedule instead. Workflows that already use it keep doing so, unchanged: it reports every run once, even when several finish between two checks, and its **Fetch Test Event** shows the latest real changes. New triggers use the instant version.
|
|
50
64
|
|
|
51
65
|
## Cost
|
|
52
66
|
|
|
@@ -56,12 +70,22 @@ Requests are billed in MeshArc credits, the same as any other API call:
|
|
|
56
70
|
- a sitemap read is 1 credit per sitemap file;
|
|
57
71
|
- a web search costs what its results page costs.
|
|
58
72
|
|
|
59
|
-
**Get Changes** and the trigger only read what MeshArc already stored, so they cost nothing. See [pricing](https://mesharc.dev/pricing).
|
|
73
|
+
**Get Changes** and the trigger only read what MeshArc already stored, so they cost nothing. The crawls themselves are the project's, billed on its schedule. See [pricing](https://mesharc.dev/pricing).
|
|
60
74
|
|
|
61
75
|
## Compatibility
|
|
62
76
|
|
|
63
77
|
Tested with n8n 2.43 on Node.js 24.
|
|
64
78
|
|
|
79
|
+
## Development
|
|
80
|
+
|
|
81
|
+
Working on this package needs Node.js 24 or later (`.nvmrc`): n8n's expression runtime, which `npm ci` installs with the `n8n-workflow` peer dependency, builds a native module (`isolated-vm`) that requires it. Installing the node in n8n has no such requirement of its own.
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
nvm use
|
|
85
|
+
npm ci
|
|
86
|
+
npm run lint && npm run build
|
|
87
|
+
```
|
|
88
|
+
|
|
65
89
|
## Resources
|
|
66
90
|
|
|
67
91
|
- [MeshArc docs](https://mesharc.dev/docs) and [API reference](https://mesharc.dev/docs/api)
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import type { IDataObject, IExecuteFunctions, IHttpRequestMethods, ILoadOptionsFunctions, INodeListSearchResult, IPollFunctions } from 'n8n-workflow';
|
|
1
|
+
import type { IDataObject, IExecuteFunctions, IHookFunctions, IHttpRequestMethods, ILoadOptionsFunctions, INodeListSearchResult, IPollFunctions, IWebhookFunctions } from 'n8n-workflow';
|
|
2
2
|
export declare const BASE_URL = "https://api.mesharc.dev/api/v1";
|
|
3
|
-
type Context = IExecuteFunctions | IPollFunctions | ILoadOptionsFunctions;
|
|
3
|
+
type Context = IExecuteFunctions | IPollFunctions | ILoadOptionsFunctions | IHookFunctions | IWebhookFunctions;
|
|
4
4
|
export declare function mesharcRequest(this: Context, method: IHttpRequestMethods, path: string, body?: IDataObject, qs?: IDataObject): Promise<IDataObject>;
|
|
5
5
|
export declare function isRunning(status: unknown): boolean;
|
|
6
6
|
export declare function waitForJob(this: IExecuteFunctions, first: IDataObject, path: string, qs: IDataObject | undefined, timeoutSeconds: number, pollSeconds?: number): Promise<IDataObject>;
|
|
7
7
|
export declare function simplifyPage(row: IDataObject): IDataObject;
|
|
8
8
|
export declare function wordCount(value: unknown): number;
|
|
9
9
|
export declare function changeItem(projectId: string, change: IDataObject, entry: IDataObject): IDataObject;
|
|
10
|
+
export declare function runChangeItems(this: Context, projectId: string, runId: string, kinds: string[]): Promise<IDataObject[]>;
|
|
11
|
+
export declare function validSignature(secret: string, body: Buffer, header: string): boolean;
|
|
10
12
|
export declare function searchProjects(this: ILoadOptionsFunctions, filter?: string): Promise<INodeListSearchResult>;
|
|
11
13
|
export {};
|
|
@@ -7,7 +7,10 @@ exports.waitForJob = waitForJob;
|
|
|
7
7
|
exports.simplifyPage = simplifyPage;
|
|
8
8
|
exports.wordCount = wordCount;
|
|
9
9
|
exports.changeItem = changeItem;
|
|
10
|
+
exports.runChangeItems = runChangeItems;
|
|
11
|
+
exports.validSignature = validSignature;
|
|
10
12
|
exports.searchProjects = searchProjects;
|
|
13
|
+
const crypto_1 = require("crypto");
|
|
11
14
|
const n8n_workflow_1 = require("n8n-workflow");
|
|
12
15
|
exports.BASE_URL = 'https://api.mesharc.dev/api/v1';
|
|
13
16
|
async function mesharcRequest(method, path, body, qs) {
|
|
@@ -76,6 +79,22 @@ function changeItem(projectId, change, entry) {
|
|
|
76
79
|
fields: (_j = entry.fields) !== null && _j !== void 0 ? _j : [],
|
|
77
80
|
};
|
|
78
81
|
}
|
|
82
|
+
async function runChangeItems(projectId, runId, kinds) {
|
|
83
|
+
const res = await mesharcRequest.call(this, 'GET', `/projects/${projectId}/changes`, undefined, { run_id: runId });
|
|
84
|
+
const change = res.change;
|
|
85
|
+
if (!change)
|
|
86
|
+
return [];
|
|
87
|
+
return (change.feed || [])
|
|
88
|
+
.filter((entry) => kinds.includes(String(entry.kind)))
|
|
89
|
+
.map((entry) => changeItem(projectId, change, entry));
|
|
90
|
+
}
|
|
91
|
+
function validSignature(secret, body, header) {
|
|
92
|
+
if (!secret || !header)
|
|
93
|
+
return false;
|
|
94
|
+
const expected = Buffer.from(`sha256=${(0, crypto_1.createHmac)('sha256', secret).update(body).digest('hex')}`);
|
|
95
|
+
const given = Buffer.from(header);
|
|
96
|
+
return given.length === expected.length && (0, crypto_1.timingSafeEqual)(given, expected);
|
|
97
|
+
}
|
|
79
98
|
async function searchProjects(filter) {
|
|
80
99
|
const rows = (await mesharcRequest.call(this, 'GET', '/projects'));
|
|
81
100
|
const wanted = (filter || '').toLowerCase();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GenericFunctions.js","sourceRoot":"","sources":["../../../nodes/MeshArc/GenericFunctions.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"GenericFunctions.js","sourceRoot":"","sources":["../../../nodes/MeshArc/GenericFunct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,OAAO;QACN,OAAO,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;aACxC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,eAAC,OAAA,CAAC,MAAM,IAAI,MAAM,CAAC,MAAA,CAAC,CAAC,IAAI,mCAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,MAAA,CAAC,CAAC,IAAI,mCAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA,EAAA,CAAC;aACpI,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;;YACV,MAAM,IAAI,GAAG,MAAM,CAAC,MAAA,CAAC,CAAC,IAAI,mCAAI,CAAC,CAAC,EAAE,CAAC,CAAC;YAEpC,MAAM,IAAI,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;YAC5E,OAAO,EAAE,IAAI,EAAE,GAAG,IAAI,GAAG,IAAI,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;QACxD,CAAC,CAAC;KACH,CAAC;AACH,CAAC"}
|
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
description: INodeTypeDescription;
|
|
5
|
-
methods: {
|
|
6
|
-
listSearch: {
|
|
7
|
-
searchProjects: typeof searchProjects;
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
poll(this: IPollFunctions): Promise<INodeExecutionData[][] | null>;
|
|
1
|
+
import { VersionedNodeType } from 'n8n-workflow';
|
|
2
|
+
export declare class MeshArcTrigger extends VersionedNodeType {
|
|
3
|
+
constructor();
|
|
11
4
|
}
|
|
@@ -2,110 +2,23 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MeshArcTrigger = void 0;
|
|
4
4
|
const n8n_workflow_1 = require("n8n-workflow");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
class MeshArcTrigger {
|
|
5
|
+
const MeshArcTriggerV1_1 = require("./v1/MeshArcTriggerV1");
|
|
6
|
+
const MeshArcTriggerV2_1 = require("./v2/MeshArcTriggerV2");
|
|
7
|
+
class MeshArcTrigger extends n8n_workflow_1.VersionedNodeType {
|
|
8
8
|
constructor() {
|
|
9
|
-
|
|
9
|
+
const baseDescription = {
|
|
10
10
|
displayName: 'MeshArc Trigger',
|
|
11
11
|
name: 'meshArcTrigger',
|
|
12
12
|
icon: { light: 'file:../../icons/mesharc.svg', dark: 'file:../../icons/mesharc.dark.svg' },
|
|
13
13
|
group: ['trigger'],
|
|
14
|
-
version: 1,
|
|
15
|
-
subtitle: 'Page changed',
|
|
16
14
|
description: 'Starts the workflow when a run of a MeshArc project finds pages added, changed or removed',
|
|
17
|
-
|
|
18
|
-
credentials: [{ name: 'mesharcApi', required: true }],
|
|
19
|
-
polling: true,
|
|
20
|
-
inputs: [],
|
|
21
|
-
outputs: [n8n_workflow_1.NodeConnectionTypes.Main],
|
|
22
|
-
properties: [
|
|
23
|
-
{
|
|
24
|
-
displayName: 'Event',
|
|
25
|
-
name: 'event',
|
|
26
|
-
type: 'options',
|
|
27
|
-
noDataExpression: true,
|
|
28
|
-
default: 'pageChanged',
|
|
29
|
-
options: [
|
|
30
|
-
{
|
|
31
|
-
name: 'Page Changed',
|
|
32
|
-
value: 'pageChanged',
|
|
33
|
-
description: 'A finished run of the project found a page added, changed or removed',
|
|
34
|
-
},
|
|
35
|
-
],
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
displayName: 'Project',
|
|
39
|
-
name: 'project',
|
|
40
|
-
type: 'resourceLocator',
|
|
41
|
-
required: true,
|
|
42
|
-
default: { mode: 'list', value: '' },
|
|
43
|
-
description: 'The MeshArc project that watches the site. Its runs are scheduled in MeshArc.',
|
|
44
|
-
modes: [
|
|
45
|
-
{ displayName: 'From List', name: 'list', type: 'list', typeOptions: { searchListMethod: 'searchProjects', searchable: true } },
|
|
46
|
-
{ displayName: 'ID', name: 'id', type: 'string', placeholder: '58a019f9742f4d488a1d108d0c2f945f' },
|
|
47
|
-
],
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
displayName: 'Changes',
|
|
51
|
-
name: 'kinds',
|
|
52
|
-
type: 'multiOptions',
|
|
53
|
-
default: ['added', 'modified', 'removed'],
|
|
54
|
-
description: 'Which kinds of change start the workflow',
|
|
55
|
-
options: [
|
|
56
|
-
{ name: 'Added', value: 'added', description: 'A page that was not there before' },
|
|
57
|
-
{ name: 'Fields Changed', value: 'fields', description: 'Only extracted fields changed, not the text' },
|
|
58
|
-
{ name: 'Modified', value: 'modified', description: "A page whose text changed" },
|
|
59
|
-
{ name: 'Removed', value: 'removed', description: 'A page that is gone' },
|
|
60
|
-
],
|
|
61
|
-
},
|
|
62
|
-
],
|
|
15
|
+
defaultVersion: 2,
|
|
63
16
|
};
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const state = this.getWorkflowStaticData('node');
|
|
68
|
-
const projectId = this.getNodeParameter('project', '', { extractValue: true });
|
|
69
|
-
const kinds = this.getNodeParameter('kinds', []);
|
|
70
|
-
const latest = await GenericFunctions_1.mesharcRequest.call(this, 'GET', `/projects/${projectId}/changes`);
|
|
71
|
-
const runs = (latest.runs || []).filter((run) => run.id);
|
|
72
|
-
const items = async (run) => {
|
|
73
|
-
if (run.baseline)
|
|
74
|
-
return [];
|
|
75
|
-
const res = await GenericFunctions_1.mesharcRequest.call(this, 'GET', `/projects/${projectId}/changes`, undefined, {
|
|
76
|
-
run_id: run.id,
|
|
77
|
-
});
|
|
78
|
-
const change = res.change;
|
|
79
|
-
if (!change)
|
|
80
|
-
return [];
|
|
81
|
-
return (change.feed || [])
|
|
82
|
-
.filter((entry) => kinds.includes(String(entry.kind)))
|
|
83
|
-
.map((entry) => (0, GenericFunctions_1.changeItem)(projectId, change, entry));
|
|
17
|
+
const nodeVersions = {
|
|
18
|
+
1: new MeshArcTriggerV1_1.MeshArcTriggerV1(baseDescription),
|
|
19
|
+
2: new MeshArcTriggerV2_1.MeshArcTriggerV2(baseDescription),
|
|
84
20
|
};
|
|
85
|
-
|
|
86
|
-
for (const run of runs.slice(0, MAX_RUNS_PER_POLL)) {
|
|
87
|
-
const found = await items(run);
|
|
88
|
-
if (found.length)
|
|
89
|
-
return [this.helpers.returnJsonArray(found)];
|
|
90
|
-
}
|
|
91
|
-
return null;
|
|
92
|
-
}
|
|
93
|
-
if (!runs.length)
|
|
94
|
-
return null;
|
|
95
|
-
const newest = String(runs[0].id);
|
|
96
|
-
if (!state.lastRunId) {
|
|
97
|
-
state.lastRunId = newest;
|
|
98
|
-
return null;
|
|
99
|
-
}
|
|
100
|
-
const seenAt = runs.findIndex((run) => run.id === state.lastRunId);
|
|
101
|
-
const unseen = (seenAt === -1 ? runs : runs.slice(0, seenAt)).slice(0, MAX_RUNS_PER_POLL).reverse();
|
|
102
|
-
if (!unseen.length)
|
|
103
|
-
return null;
|
|
104
|
-
const found = [];
|
|
105
|
-
for (const run of unseen)
|
|
106
|
-
found.push(...(await items(run)));
|
|
107
|
-
state.lastRunId = newest;
|
|
108
|
-
return found.length ? [this.helpers.returnJsonArray(found)] : null;
|
|
21
|
+
super(nodeVersions, baseDescription);
|
|
109
22
|
}
|
|
110
23
|
}
|
|
111
24
|
exports.MeshArcTrigger = MeshArcTrigger;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MeshArcTrigger.node.js","sourceRoot":"","sources":["../../../nodes/MeshArcTrigger/MeshArcTrigger.node.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"MeshArcTrigger.node.js","sourceRoot":"","sources":["../../../nodes/MeshArcTrigger/MeshArcTrigger.node.ts"],"names":[],"mappings":";;;AACA,+CAAiD;AAEjD,4DAAyD;AACzD,4DAAyD;AAMzD,MAAa,cAAe,SAAQ,gCAAiB;IACpD;QACC,MAAM,eAAe,GAA6B;YACjD,WAAW,EAAE,iBAAiB;YAC9B,IAAI,EAAE,gBAAgB;YACtB,IAAI,EAAE,EAAE,KAAK,EAAE,8BAA8B,EAAE,IAAI,EAAE,mCAAmC,EAAE;YAC1F,KAAK,EAAE,CAAC,SAAS,CAAC;YAClB,WAAW,EAAE,2FAA2F;YACxG,cAAc,EAAE,CAAC;SACjB,CAAC;QACF,MAAM,YAAY,GAAuC;YACxD,CAAC,EAAE,IAAI,mCAAgB,CAAC,eAAe,CAAC;YACxC,CAAC,EAAE,IAAI,mCAAgB,CAAC,eAAe,CAAC;SACxC,CAAC;QACF,KAAK,CAAC,YAAY,EAAE,eAAe,CAAC,CAAC;IACtC,CAAC;CACD;AAhBD,wCAgBC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { INodeExecutionData, INodeType, INodeTypeBaseDescription, INodeTypeDescription, IPollFunctions } from 'n8n-workflow';
|
|
2
|
+
import { searchProjects } from '../../MeshArc/GenericFunctions';
|
|
3
|
+
export declare class MeshArcTriggerV1 implements INodeType {
|
|
4
|
+
description: INodeTypeDescription;
|
|
5
|
+
constructor(baseDescription: INodeTypeBaseDescription);
|
|
6
|
+
methods: {
|
|
7
|
+
listSearch: {
|
|
8
|
+
searchProjects: typeof searchProjects;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
poll(this: IPollFunctions): Promise<INodeExecutionData[][] | null>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MeshArcTriggerV1 = void 0;
|
|
4
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
5
|
+
const GenericFunctions_1 = require("../../MeshArc/GenericFunctions");
|
|
6
|
+
const MAX_RUNS_PER_POLL = 10;
|
|
7
|
+
class MeshArcTriggerV1 {
|
|
8
|
+
constructor(baseDescription) {
|
|
9
|
+
this.methods = { listSearch: { searchProjects: GenericFunctions_1.searchProjects } };
|
|
10
|
+
this.description = {
|
|
11
|
+
...baseDescription,
|
|
12
|
+
version: 1,
|
|
13
|
+
subtitle: 'Page changed',
|
|
14
|
+
defaults: { name: 'MeshArc Trigger' },
|
|
15
|
+
credentials: [{ name: 'mesharcApi', required: true }],
|
|
16
|
+
polling: true,
|
|
17
|
+
inputs: [],
|
|
18
|
+
outputs: [n8n_workflow_1.NodeConnectionTypes.Main],
|
|
19
|
+
properties: [
|
|
20
|
+
{
|
|
21
|
+
displayName: 'Event',
|
|
22
|
+
name: 'event',
|
|
23
|
+
type: 'options',
|
|
24
|
+
noDataExpression: true,
|
|
25
|
+
default: 'pageChanged',
|
|
26
|
+
options: [
|
|
27
|
+
{
|
|
28
|
+
name: 'Page Changed',
|
|
29
|
+
value: 'pageChanged',
|
|
30
|
+
description: 'A finished run of the project found a page added, changed or removed',
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
displayName: 'Project',
|
|
36
|
+
name: 'project',
|
|
37
|
+
type: 'resourceLocator',
|
|
38
|
+
required: true,
|
|
39
|
+
default: { mode: 'list', value: '' },
|
|
40
|
+
description: 'The MeshArc project that watches the site. Its runs are scheduled in MeshArc.',
|
|
41
|
+
modes: [
|
|
42
|
+
{ displayName: 'From List', name: 'list', type: 'list', typeOptions: { searchListMethod: 'searchProjects', searchable: true } },
|
|
43
|
+
{ displayName: 'ID', name: 'id', type: 'string', placeholder: '58a019f9742f4d488a1d108d0c2f945f' },
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
displayName: 'Changes',
|
|
48
|
+
name: 'kinds',
|
|
49
|
+
type: 'multiOptions',
|
|
50
|
+
default: ['added', 'modified', 'removed'],
|
|
51
|
+
description: 'Which kinds of change start the workflow',
|
|
52
|
+
options: [
|
|
53
|
+
{ name: 'Added', value: 'added', description: 'A page that was not there before' },
|
|
54
|
+
{ name: 'Fields Changed', value: 'fields', description: 'Only extracted fields changed, not the text' },
|
|
55
|
+
{ name: 'Modified', value: 'modified', description: "A page whose text changed" },
|
|
56
|
+
{ name: 'Removed', value: 'removed', description: 'A page that is gone' },
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
async poll() {
|
|
63
|
+
const state = this.getWorkflowStaticData('node');
|
|
64
|
+
const projectId = this.getNodeParameter('project', '', { extractValue: true });
|
|
65
|
+
const kinds = this.getNodeParameter('kinds', []);
|
|
66
|
+
const latest = await GenericFunctions_1.mesharcRequest.call(this, 'GET', `/projects/${projectId}/changes`);
|
|
67
|
+
const runs = (latest.runs || []).filter((run) => run.id);
|
|
68
|
+
const items = async (run) => {
|
|
69
|
+
if (run.baseline)
|
|
70
|
+
return [];
|
|
71
|
+
const res = await GenericFunctions_1.mesharcRequest.call(this, 'GET', `/projects/${projectId}/changes`, undefined, {
|
|
72
|
+
run_id: run.id,
|
|
73
|
+
});
|
|
74
|
+
const change = res.change;
|
|
75
|
+
if (!change)
|
|
76
|
+
return [];
|
|
77
|
+
return (change.feed || [])
|
|
78
|
+
.filter((entry) => kinds.includes(String(entry.kind)))
|
|
79
|
+
.map((entry) => (0, GenericFunctions_1.changeItem)(projectId, change, entry));
|
|
80
|
+
};
|
|
81
|
+
if (this.getMode() === 'manual') {
|
|
82
|
+
for (const run of runs.slice(0, MAX_RUNS_PER_POLL)) {
|
|
83
|
+
const found = await items(run);
|
|
84
|
+
if (found.length)
|
|
85
|
+
return [this.helpers.returnJsonArray(found)];
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
if (!runs.length)
|
|
90
|
+
return null;
|
|
91
|
+
const newest = String(runs[0].id);
|
|
92
|
+
if (!state.lastRunId) {
|
|
93
|
+
state.lastRunId = newest;
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
const seenAt = runs.findIndex((run) => run.id === state.lastRunId);
|
|
97
|
+
const unseen = (seenAt === -1 ? runs : runs.slice(0, seenAt)).slice(0, MAX_RUNS_PER_POLL).reverse();
|
|
98
|
+
if (!unseen.length)
|
|
99
|
+
return null;
|
|
100
|
+
const found = [];
|
|
101
|
+
for (const run of unseen)
|
|
102
|
+
found.push(...(await items(run)));
|
|
103
|
+
state.lastRunId = newest;
|
|
104
|
+
return found.length ? [this.helpers.returnJsonArray(found)] : null;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
exports.MeshArcTriggerV1 = MeshArcTriggerV1;
|
|
108
|
+
//# sourceMappingURL=MeshArcTriggerV1.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MeshArcTriggerV1.js","sourceRoot":"","sources":["../../../../nodes/MeshArcTrigger/v1/MeshArcTriggerV1.ts"],"names":[],"mappings":";;;AAQA,+CAAmD;AAEnD,qEAA4F;AAG5F,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAG7B,MAAa,gBAAgB;IAG5B,YAAY,eAAyC;QAsDrD,YAAO,GAAG,EAAE,UAAU,EAAE,EAAE,cAAc,EAAd,iCAAc,EAAE,EAAE,CAAC;QArD5C,IAAI,CAAC,WAAW,GAAG;YAClB,GAAG,eAAe;YAClB,OAAO,EAAE,CAAC;YACV,QAAQ,EAAE,cAAc;YACxB,QAAQ,EAAE,EAAE,IAAI,EAAE,iBAAiB,EAAE;YACrC,WAAW,EAAE,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;YACrD,OAAO,EAAE,IAAI;YACb,MAAM,EAAE,EAAE;YACV,OAAO,EAAE,CAAC,kCAAmB,CAAC,IAAI,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kB,EAAE,CAAC;QAChC,KAAK,MAAM,GAAG,IAAI,MAAM;YAAE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAE5D,KAAK,CAAC,SAAS,GAAG,MAAM,CAAC;QACzB,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACpE,CAAC;CACD;AA3GD,4CA2GC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { IHookFunctions, INodeType, INodeTypeBaseDescription, INodeTypeDescription, IWebhookFunctions, IWebhookResponseData } from 'n8n-workflow';
|
|
2
|
+
import { searchProjects } from '../../MeshArc/GenericFunctions';
|
|
3
|
+
export declare class MeshArcTriggerV2 implements INodeType {
|
|
4
|
+
description: INodeTypeDescription;
|
|
5
|
+
constructor(baseDescription: INodeTypeBaseDescription);
|
|
6
|
+
methods: {
|
|
7
|
+
listSearch: {
|
|
8
|
+
searchProjects: typeof searchProjects;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
webhookMethods: {
|
|
12
|
+
default: {
|
|
13
|
+
checkExists(this: IHookFunctions): Promise<boolean>;
|
|
14
|
+
create(this: IHookFunctions): Promise<boolean>;
|
|
15
|
+
delete(this: IHookFunctions): Promise<boolean>;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
webhook(this: IWebhookFunctions): Promise<IWebhookResponseData>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MeshArcTriggerV2 = void 0;
|
|
4
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
5
|
+
const GenericFunctions_1 = require("../../MeshArc/GenericFunctions");
|
|
6
|
+
const SUBSCRIBED_EVENTS = ['run.finished'];
|
|
7
|
+
async function removeSubscription(id) {
|
|
8
|
+
var _a;
|
|
9
|
+
const res = (await this.helpers.httpRequestWithAuthentication.call(this, 'mesharcApi', {
|
|
10
|
+
method: 'DELETE',
|
|
11
|
+
url: `${GenericFunctions_1.BASE_URL}/webhooks/subscriptions/${encodeURIComponent(id)}`,
|
|
12
|
+
json: true,
|
|
13
|
+
ignoreHttpStatusErrors: true,
|
|
14
|
+
returnFullResponse: true,
|
|
15
|
+
}));
|
|
16
|
+
if (res.statusCode >= 400 && res.statusCode !== 404) {
|
|
17
|
+
throw new n8n_workflow_1.NodeApiError(this.getNode(), (_a = res.body) !== null && _a !== void 0 ? _a : {}, { httpCode: String(res.statusCode) });
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
class MeshArcTriggerV2 {
|
|
21
|
+
constructor(baseDescription) {
|
|
22
|
+
this.methods = { listSearch: { searchProjects: GenericFunctions_1.searchProjects } };
|
|
23
|
+
this.webhookMethods = {
|
|
24
|
+
default: {
|
|
25
|
+
async checkExists() {
|
|
26
|
+
const data = this.getWorkflowStaticData('node');
|
|
27
|
+
if (!data.subscriptionId || !data.secret)
|
|
28
|
+
return false;
|
|
29
|
+
const projectId = this.getNodeParameter('project', '', { extractValue: true });
|
|
30
|
+
const res = await GenericFunctions_1.mesharcRequest.call(this, 'GET', '/webhooks/subscriptions', undefined, { projectId });
|
|
31
|
+
const url = this.getNodeWebhookUrl('default');
|
|
32
|
+
const found = (res.subscriptions || []).some((sub) => sub.id === data.subscriptionId && sub.url === url);
|
|
33
|
+
if (!found) {
|
|
34
|
+
await removeSubscription.call(this, String(data.subscriptionId));
|
|
35
|
+
delete data.subscriptionId;
|
|
36
|
+
delete data.secret;
|
|
37
|
+
}
|
|
38
|
+
return found;
|
|
39
|
+
},
|
|
40
|
+
async create() {
|
|
41
|
+
const data = this.getWorkflowStaticData('node');
|
|
42
|
+
const projectId = this.getNodeParameter('project', '', { extractValue: true });
|
|
43
|
+
const res = await GenericFunctions_1.mesharcRequest.call(this, 'POST', '/webhooks/subscriptions', {
|
|
44
|
+
projectId,
|
|
45
|
+
url: this.getNodeWebhookUrl('default'),
|
|
46
|
+
events: SUBSCRIBED_EVENTS,
|
|
47
|
+
label: 'n8n',
|
|
48
|
+
});
|
|
49
|
+
const sub = res.subscription || {};
|
|
50
|
+
if (!sub.id || !sub.secret)
|
|
51
|
+
return false;
|
|
52
|
+
data.subscriptionId = sub.id;
|
|
53
|
+
data.secret = sub.secret;
|
|
54
|
+
return true;
|
|
55
|
+
},
|
|
56
|
+
async delete() {
|
|
57
|
+
const data = this.getWorkflowStaticData('node');
|
|
58
|
+
if (data.subscriptionId)
|
|
59
|
+
await removeSubscription.call(this, String(data.subscriptionId));
|
|
60
|
+
delete data.subscriptionId;
|
|
61
|
+
delete data.secret;
|
|
62
|
+
return true;
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
this.description = {
|
|
67
|
+
...baseDescription,
|
|
68
|
+
version: 2,
|
|
69
|
+
subtitle: 'Page changed',
|
|
70
|
+
defaults: { name: 'MeshArc Trigger' },
|
|
71
|
+
credentials: [{ name: 'mesharcApi', required: true }],
|
|
72
|
+
inputs: [],
|
|
73
|
+
outputs: [n8n_workflow_1.NodeConnectionTypes.Main],
|
|
74
|
+
webhooks: [{ name: 'default', httpMethod: 'POST', responseMode: 'onReceived', path: 'webhook' }],
|
|
75
|
+
properties: [
|
|
76
|
+
{
|
|
77
|
+
displayName: 'MeshArc sends each finished run to this workflow as it happens, so n8n must be reachable from the internet (a public URL, not localhost)',
|
|
78
|
+
name: 'notice',
|
|
79
|
+
type: 'notice',
|
|
80
|
+
default: '',
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
displayName: 'Event',
|
|
84
|
+
name: 'event',
|
|
85
|
+
type: 'options',
|
|
86
|
+
noDataExpression: true,
|
|
87
|
+
default: 'pageChanged',
|
|
88
|
+
options: [
|
|
89
|
+
{
|
|
90
|
+
name: 'Page Changed',
|
|
91
|
+
value: 'pageChanged',
|
|
92
|
+
description: 'A finished run of the project found a page added, changed or removed',
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
displayName: 'Project',
|
|
98
|
+
name: 'project',
|
|
99
|
+
type: 'resourceLocator',
|
|
100
|
+
required: true,
|
|
101
|
+
default: { mode: 'list', value: '' },
|
|
102
|
+
description: 'The MeshArc project that watches the site. Its runs are scheduled in MeshArc.',
|
|
103
|
+
modes: [
|
|
104
|
+
{ displayName: 'From List', name: 'list', type: 'list', typeOptions: { searchListMethod: 'searchProjects', searchable: true } },
|
|
105
|
+
{ displayName: 'ID', name: 'id', type: 'string', placeholder: '58a019f9742f4d488a1d108d0c2f945f' },
|
|
106
|
+
],
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
displayName: 'Changes',
|
|
110
|
+
name: 'kinds',
|
|
111
|
+
type: 'multiOptions',
|
|
112
|
+
default: ['added', 'modified', 'removed'],
|
|
113
|
+
description: 'Which kinds of change start the workflow',
|
|
114
|
+
options: [
|
|
115
|
+
{ name: 'Added', value: 'added', description: 'A page that was not there before' },
|
|
116
|
+
{ name: 'Fields Changed', value: 'fields', description: 'Only extracted fields changed, not the text' },
|
|
117
|
+
{ name: 'Modified', value: 'modified', description: 'A page whose text changed' },
|
|
118
|
+
{ name: 'Removed', value: 'removed', description: 'A page that is gone' },
|
|
119
|
+
],
|
|
120
|
+
},
|
|
121
|
+
],
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
async webhook() {
|
|
125
|
+
var _a, _b;
|
|
126
|
+
const data = this.getWorkflowStaticData('node');
|
|
127
|
+
const req = this.getRequestObject();
|
|
128
|
+
const headers = this.getHeaderData();
|
|
129
|
+
if (!req.rawBody || !(0, GenericFunctions_1.validSignature)(String((_a = data.secret) !== null && _a !== void 0 ? _a : ''), req.rawBody, String((_b = headers['x-mesharc-signature']) !== null && _b !== void 0 ? _b : ''))) {
|
|
130
|
+
this.getResponseObject().status(401).json({ error: 'invalid signature' });
|
|
131
|
+
return { noWebhookResponse: true };
|
|
132
|
+
}
|
|
133
|
+
if (headers['x-mesharc-event'] !== 'run.finished')
|
|
134
|
+
return {};
|
|
135
|
+
const message = this.getBodyData().data || {};
|
|
136
|
+
const project = message.project || {};
|
|
137
|
+
const run = message.run || {};
|
|
138
|
+
const projectId = this.getNodeParameter('project', '', { extractValue: true });
|
|
139
|
+
if (message.baseline || project.id !== projectId || !run.id)
|
|
140
|
+
return {};
|
|
141
|
+
const kinds = this.getNodeParameter('kinds', []);
|
|
142
|
+
const found = await GenericFunctions_1.runChangeItems.call(this, projectId, String(run.id), kinds);
|
|
143
|
+
if (!found.length)
|
|
144
|
+
return {};
|
|
145
|
+
return { workflowData: [this.helpers.returnJsonArray(found)] };
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
exports.MeshArcTriggerV2 = MeshArcTriggerV2;
|
|
149
|
+
//# sourceMappingURL=MeshArcTriggerV2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MeshArcTriggerV2.js","sourceRoot":"","sources":["../../../../nodes/MeshArcTrigger/v2/MeshArcTriggerV2.ts"],"names":[],"mappings":";;;AAUA,+CAAiE;AAEjE,qEAMwC;AAGxC,MAAM,iBAAiB,GAAG,CAAC,cAAc,CAAC,CAAC;AAG3C,KAAK,UAAU,kBAAkB,CAAuB,EAAU;;IACjE,MAAM,GAAG,GAAG,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,6BAA6B,CAAC,IAAI,CAAC,IAAI,EAAE,YAAY,EAAE;QACtF,MAAM,EAAE,QAAQ;QAChB,GAAG,EAAE,GAAG,2BAAQ,2BAA2B,kBAAkB,CAAC,EAAE,CAAC,EAAE;QACnE,IAAI,EAAE,IAAI;QACV,sBAAsB,EAAE,IAAI;QAC5B,kBAAkB,EAAE,IAAI;KACxB,CAAC,CAA6C,CAAC;IAChD,IAAI,GAAG,CAAC,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