@kgma/linkdevi-tools 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 +21 -0
- package/README.md +125 -2
- package/dist/campaign.d.ts +101 -0
- package/dist/campaign.js +162 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +139 -0
- package/dist/index.d.ts +83 -0
- package/dist/index.js +73 -0
- package/dist/utm.d.ts +24 -0
- package/dist/utm.js +101 -0
- package/examples/campaign.json +12 -0
- package/examples/github-actions/utm-lint.yml +25 -0
- package/examples/links.csv +2 -0
- package/examples/sdk-example.ts +13 -0
- package/examples/utm-links.csv +3 -0
- package/package.json +59 -4
- package/workflows/01-google-sheets-to-links.json +211 -0
- package/workflows/02-campaign-to-csv.json +164 -0
- package/workflows/03-rss-to-share-kit.json +242 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export * from "./campaign.js";
|
|
2
|
+
export * from "./utm.js";
|
|
3
|
+
import { validateCampaign } from "./campaign.js";
|
|
4
|
+
export class LinkDeviError extends Error {
|
|
5
|
+
status;
|
|
6
|
+
code;
|
|
7
|
+
retryAfter;
|
|
8
|
+
ambiguous;
|
|
9
|
+
constructor(status, code, retryAfter = null, ambiguous = false) {
|
|
10
|
+
super(ambiguous ? "Response unavailable; creation may have committed. Reuse the original requestId and exact payload." : `LinkDevi request failed (HTTP ${status || "unavailable"}).`);
|
|
11
|
+
this.status = status;
|
|
12
|
+
this.code = code;
|
|
13
|
+
this.retryAfter = retryAfter;
|
|
14
|
+
this.ambiguous = ambiguous;
|
|
15
|
+
this.name = "LinkDeviError";
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export class LinkDeviClient {
|
|
19
|
+
origin;
|
|
20
|
+
apiKey;
|
|
21
|
+
fetchImpl;
|
|
22
|
+
constructor(options) {
|
|
23
|
+
this.origin = new URL(options.baseUrl ?? "https://linkdevi.com");
|
|
24
|
+
const u = this.origin;
|
|
25
|
+
if (u.username || u.password || u.search || u.hash || u.pathname !== "/" || !(u.protocol === "https:" || (u.protocol === "http:" && ["localhost", "127.0.0.1", "[::1]"].includes(u.hostname))))
|
|
26
|
+
throw new Error("Use an HTTPS service origin, or localhost HTTP for testing");
|
|
27
|
+
if (!/^su_[a-zA-Z0-9]+$/.test(options.apiKey ?? ""))
|
|
28
|
+
throw new Error("A scoped LinkDevi API key is required");
|
|
29
|
+
this.apiKey = options.apiKey;
|
|
30
|
+
this.fetchImpl = options.fetch ?? fetch;
|
|
31
|
+
}
|
|
32
|
+
async call(action, args = {}, mutates = false) {
|
|
33
|
+
let response;
|
|
34
|
+
try {
|
|
35
|
+
response = await this.fetchImpl(new URL("/api/v1/agent", this.origin), { method: "POST", redirect: "error", signal: AbortSignal.timeout(25000), headers: { Authorization: `Bearer ${this.apiKey}`, "Content-Type": "application/json" }, body: JSON.stringify({ action, ...args }) });
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
throw new LinkDeviError(0, "NETWORK_UNAVAILABLE", null, mutates);
|
|
39
|
+
}
|
|
40
|
+
let data;
|
|
41
|
+
try {
|
|
42
|
+
data = await response.json();
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
throw new LinkDeviError(response.status, "INVALID_RESPONSE", null, mutates);
|
|
46
|
+
}
|
|
47
|
+
if (!response.ok) {
|
|
48
|
+
const retry = response.headers.get("retry-after"), seconds = retry ? Number(retry) : NaN;
|
|
49
|
+
const rawCode = data && typeof data === "object" && "error" in data ? String(data.error) : "HTTP_ERROR";
|
|
50
|
+
const code = /^[a-zA-Z_]{1,64}$/.test(rawCode) && !rawCode.includes(this.apiKey) ? rawCode : "HTTP_ERROR";
|
|
51
|
+
throw new LinkDeviError(response.status, code, Number.isFinite(seconds) && seconds >= 0 ? seconds : null);
|
|
52
|
+
}
|
|
53
|
+
if (!data || typeof data !== "object" || Array.isArray(data))
|
|
54
|
+
throw new LinkDeviError(response.status, "INVALID_RESPONSE", null, mutates);
|
|
55
|
+
return data;
|
|
56
|
+
}
|
|
57
|
+
capabilities() { return this.call("capabilities"); }
|
|
58
|
+
previewCampaign(campaign) { return this.call("preview_campaign", { campaign: validateCampaign(campaign, true) }); }
|
|
59
|
+
createCampaign(campaign) { return this.call("create_campaign", { campaign: validateCampaign(campaign, true) }, true); }
|
|
60
|
+
listCampaigns(page = 1) {
|
|
61
|
+
if (!Number.isInteger(page) || page < 1 || page > 10000)
|
|
62
|
+
throw new Error("Invalid page");
|
|
63
|
+
return this.call("list_campaigns", { page });
|
|
64
|
+
}
|
|
65
|
+
campaignStats(campaignId) { return this.call("campaign_stats", { campaignId: this.id(campaignId) }); }
|
|
66
|
+
linkQr(linkId, size = 300) {
|
|
67
|
+
if (!Number.isInteger(size) || size < 100 || size > 512)
|
|
68
|
+
throw new Error("Size must be 100–512");
|
|
69
|
+
return this.call("link_qr", { linkId: this.id(linkId), size });
|
|
70
|
+
}
|
|
71
|
+
id(value) { if (!/^[a-zA-Z0-9_-]{1,100}$/.test(value))
|
|
72
|
+
throw new Error("Invalid resource ID"); return value; }
|
|
73
|
+
}
|
package/dist/utm.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface UtmIssue {
|
|
2
|
+
code: string;
|
|
3
|
+
severity: "error" | "warning";
|
|
4
|
+
message: string;
|
|
5
|
+
}
|
|
6
|
+
export interface UtmLintReport {
|
|
7
|
+
schemaVersion: 1;
|
|
8
|
+
offline: true;
|
|
9
|
+
createsResources: false;
|
|
10
|
+
summary: {
|
|
11
|
+
rows: number;
|
|
12
|
+
errors: number;
|
|
13
|
+
warnings: number;
|
|
14
|
+
};
|
|
15
|
+
rows: {
|
|
16
|
+
row: number;
|
|
17
|
+
issues: UtmIssue[];
|
|
18
|
+
}[];
|
|
19
|
+
}
|
|
20
|
+
/** Checks local inputs only. Reports intentionally omit destinations and parameter values. */
|
|
21
|
+
export declare function lintUtmUrls(inputs: string[]): UtmLintReport;
|
|
22
|
+
/** Accepts a url column or the destination_url column exported by Campaign Launch Kit. */
|
|
23
|
+
export declare function lintUtmCsv(raw: string): UtmLintReport;
|
|
24
|
+
export declare function formatUtmReport(report: UtmLintReport, format?: "text" | "github"): string;
|
package/dist/utm.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { parseCsv } from "./campaign.js";
|
|
2
|
+
const required = ["utm_source", "utm_medium", "utm_campaign"];
|
|
3
|
+
const known = new Set([...required, "utm_content", "utm_term", "utm_id", "utm_source_platform", "utm_creative_format", "utm_marketing_tactic"]);
|
|
4
|
+
/** Checks local inputs only. Reports intentionally omit destinations and parameter values. */
|
|
5
|
+
export function lintUtmUrls(inputs) {
|
|
6
|
+
if (!Array.isArray(inputs) || !inputs.length || inputs.length > 100)
|
|
7
|
+
throw new Error("Provide 1–100 URLs");
|
|
8
|
+
const seen = new Map();
|
|
9
|
+
const sources = new Map();
|
|
10
|
+
const rows = inputs.map((raw, index) => {
|
|
11
|
+
const issues = [];
|
|
12
|
+
const add = (code, severity, message) => issues.push({ code, severity, message });
|
|
13
|
+
let url;
|
|
14
|
+
try {
|
|
15
|
+
if (typeof raw !== "string" || !raw || raw.length > 2048 || /[\u0000-\u001f\u007f]/.test(raw))
|
|
16
|
+
throw new Error();
|
|
17
|
+
url = new URL(raw);
|
|
18
|
+
if (!["http:", "https:"].includes(url.protocol) || url.username || url.password)
|
|
19
|
+
throw new Error();
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
add("INVALID_URL", "error", "Use an absolute HTTP(S) URL without credentials or control characters (maximum 2,048 characters).");
|
|
23
|
+
return { row: index + 1, issues };
|
|
24
|
+
}
|
|
25
|
+
const params = new Map();
|
|
26
|
+
for (const [key, value] of url.searchParams) {
|
|
27
|
+
const lower = key.toLowerCase();
|
|
28
|
+
if (!lower.startsWith("utm_"))
|
|
29
|
+
continue;
|
|
30
|
+
params.set(lower, [...(params.get(lower) || []), value]);
|
|
31
|
+
if (key !== lower)
|
|
32
|
+
add("UTM_KEY_CASE", "warning", "Use lowercase UTM parameter names consistently.");
|
|
33
|
+
if (!known.has(lower))
|
|
34
|
+
add("UNKNOWN_UTM_PARAMETER", "warning", "An unrecognized UTM parameter may not be used by your analytics setup.");
|
|
35
|
+
if (/[\u0000-\u001f\u007f]/.test(value))
|
|
36
|
+
add("UTM_CONTROL_CHARACTER", "error", "A decoded UTM value contains a control character. Remove it before sharing.");
|
|
37
|
+
if (value !== value.trim() || /\s/.test(value))
|
|
38
|
+
add("UTM_WHITESPACE", "warning", "A UTM value contains whitespace; review naming consistency.");
|
|
39
|
+
}
|
|
40
|
+
for (const key of required) {
|
|
41
|
+
if (!params.get(key)?.some(v => v.trim()))
|
|
42
|
+
add("MISSING_" + key.toUpperCase(), "error", key + " is required and must not be blank.");
|
|
43
|
+
}
|
|
44
|
+
for (const values of params.values()) {
|
|
45
|
+
if (values.length > 1)
|
|
46
|
+
add("DUPLICATE_UTM_PARAMETER", "error", "A UTM parameter appears more than once, including case variants. Choose one value deliberately.");
|
|
47
|
+
}
|
|
48
|
+
const source = params.get("utm_source");
|
|
49
|
+
if (source?.length === 1 && source[0].trim()) {
|
|
50
|
+
const group = source[0].trim().toLowerCase();
|
|
51
|
+
const variants = sources.get(group) || new Map();
|
|
52
|
+
variants.set(source[0], [...(variants.get(source[0]) || []), index]);
|
|
53
|
+
sources.set(group, variants);
|
|
54
|
+
}
|
|
55
|
+
const canonical = new URL(url);
|
|
56
|
+
canonical.searchParams.sort();
|
|
57
|
+
const identity = canonical.href;
|
|
58
|
+
if (seen.has(identity))
|
|
59
|
+
add("DUPLICATE_URL", "warning", "This destination and tracking combination repeats an earlier row (query parameter order ignored).");
|
|
60
|
+
else
|
|
61
|
+
seen.set(identity, index);
|
|
62
|
+
return { row: index + 1, issues };
|
|
63
|
+
});
|
|
64
|
+
for (const variants of sources.values()) {
|
|
65
|
+
if (variants.size < 2)
|
|
66
|
+
continue;
|
|
67
|
+
for (const indexes of variants.values())
|
|
68
|
+
for (const index of indexes)
|
|
69
|
+
rows[index].issues.push({
|
|
70
|
+
code: "INCONSISTENT_SOURCE", severity: "warning", message: "The same source uses different capitalization or surrounding whitespace across rows. Review before merging analytics.",
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
const issues = rows.flatMap(row => row.issues);
|
|
74
|
+
return { schemaVersion: 1, offline: true, createsResources: false, summary: { rows: rows.length, errors: issues.filter(i => i.severity === "error").length, warnings: issues.filter(i => i.severity === "warning").length }, rows };
|
|
75
|
+
}
|
|
76
|
+
/** Accepts a url column or the destination_url column exported by Campaign Launch Kit. */
|
|
77
|
+
export function lintUtmCsv(raw) {
|
|
78
|
+
const [headers, ...data] = parseCsv(raw);
|
|
79
|
+
if (!headers || new Set(headers).size !== headers.length || !data.length)
|
|
80
|
+
throw new Error("CSV needs unique headers and 1–100 data rows");
|
|
81
|
+
const candidates = ["url", "destination_url"].filter(key => headers.includes(key));
|
|
82
|
+
if (candidates.length !== 1)
|
|
83
|
+
throw new Error("CSV needs exactly one url or destination_url column");
|
|
84
|
+
const column = headers.indexOf(candidates[0]);
|
|
85
|
+
const report = lintUtmUrls(data.map(row => row.length === headers.length ? row[column] : ""));
|
|
86
|
+
// Row numbers are logical CSV records, since quoted fields can span physical lines.
|
|
87
|
+
for (const row of report.rows)
|
|
88
|
+
row.row++;
|
|
89
|
+
return report;
|
|
90
|
+
}
|
|
91
|
+
export function formatUtmReport(report, format = "text") {
|
|
92
|
+
const lines = [];
|
|
93
|
+
for (const row of report.rows)
|
|
94
|
+
for (const issue of row.issues) {
|
|
95
|
+
const message = `CSV record ${row.row}: ${issue.code} — ${issue.message}`;
|
|
96
|
+
lines.push(format === "github" ? `::${issue.severity}::${message.replaceAll("%", "%25").replaceAll("\r", "%0D").replaceAll("\n", "%0A")}` : `${issue.severity.toUpperCase()} ${message}`);
|
|
97
|
+
}
|
|
98
|
+
lines.push(`${report.summary.rows} URLs checked; ${report.summary.errors} errors; ${report.summary.warnings} warnings. Offline check; no links created.`);
|
|
99
|
+
lines.push("Prepare a campaign: https://linkdevi.com/tools/campaign-launch-kit?utm_source=github&utm_medium=developer_tool&utm_campaign=utm_linter");
|
|
100
|
+
return lines.join("\n") + "\n";
|
|
101
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Copy to .github/workflows/utm-lint.yml in a checkout of this tools package.
|
|
2
|
+
# For the LinkDevi monorepo, set defaults.run.working-directory to
|
|
3
|
+
# integrations/linkdevi-tools. No LinkDevi key is required.
|
|
4
|
+
name: Check campaign UTM links
|
|
5
|
+
on:
|
|
6
|
+
pull_request:
|
|
7
|
+
workflow_dispatch:
|
|
8
|
+
permissions:
|
|
9
|
+
contents: read
|
|
10
|
+
jobs:
|
|
11
|
+
utm:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
timeout-minutes: 5
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
|
|
16
|
+
with:
|
|
17
|
+
persist-credentials: false
|
|
18
|
+
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7
|
|
19
|
+
with:
|
|
20
|
+
node-version: '24'
|
|
21
|
+
package-manager-cache: false
|
|
22
|
+
- run: npm ci --ignore-scripts --no-audit --no-fund
|
|
23
|
+
- run: npm run build
|
|
24
|
+
- name: Check UTM links without creating resources
|
|
25
|
+
run: node dist/cli.js utm lint examples/utm-links.csv --format github --strict
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { LinkDeviClient, previewCampaign, type CampaignRequest } from "../dist/index.js";
|
|
2
|
+
// Save this intent's UUID and payload before creating. Keep both unchanged on retry.
|
|
3
|
+
const intent: CampaignRequest = {
|
|
4
|
+
requestId: "a43c37c0-350a-44ef-9d40-a5900c246891",
|
|
5
|
+
name: "December launch", url: "https://example.com/sale", utmCampaign: "december-launch",
|
|
6
|
+
domain: "linkdevi.com", channels: ["facebook", "line", "print"],
|
|
7
|
+
};
|
|
8
|
+
console.log(previewCampaign(intent)); // Offline, no key and no quota.
|
|
9
|
+
// Opt in deliberately after reviewing the preview. No model is invoked.
|
|
10
|
+
if (process.env.LINKDEVI_CREATE === "1") {
|
|
11
|
+
const client = new LinkDeviClient({ apiKey: process.env.LINKDEVI_API_KEY ?? "" });
|
|
12
|
+
console.log(await client.createCampaign(intent));
|
|
13
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,61 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kgma/linkdevi-tools",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Offline campaign launch kits and UTM linting, a typed LinkDevi API client and campaign CLI.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=22"
|
|
9
|
+
},
|
|
10
|
+
"bin": {
|
|
11
|
+
"linkdevi": "dist/cli.js"
|
|
12
|
+
},
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./campaign": {
|
|
19
|
+
"types": "./dist/campaign.d.ts",
|
|
20
|
+
"import": "./dist/campaign.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist",
|
|
25
|
+
"examples",
|
|
26
|
+
"workflows",
|
|
27
|
+
"README.md",
|
|
28
|
+
"LICENSE"
|
|
29
|
+
],
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public",
|
|
32
|
+
"registry": "https://registry.npmjs.org/"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "tsc -p tsconfig.json",
|
|
36
|
+
"test": "npm run build && node --test test/*.test.mjs",
|
|
37
|
+
"prepack": "npm run build"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"typescript": "5.9.3",
|
|
41
|
+
"@types/node": "25.5.0"
|
|
42
|
+
},
|
|
43
|
+
"repository": {
|
|
44
|
+
"type": "git",
|
|
45
|
+
"url": "git+https://github.com/kgma-glitch/linkdevi-tools.git"
|
|
46
|
+
},
|
|
47
|
+
"homepage": "https://linkdevi.com/tools/campaign-launch-kit",
|
|
48
|
+
"bugs": {
|
|
49
|
+
"url": "https://github.com/kgma-glitch/linkdevi-tools/issues"
|
|
50
|
+
},
|
|
51
|
+
"keywords": [
|
|
52
|
+
"linkdevi",
|
|
53
|
+
"url-shortener",
|
|
54
|
+
"utm",
|
|
55
|
+
"campaign",
|
|
56
|
+
"cli",
|
|
57
|
+
"sdk",
|
|
58
|
+
"n8n",
|
|
59
|
+
"ai"
|
|
60
|
+
]
|
|
61
|
+
}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "LinkDevi — Google Sheets to saved campaign links",
|
|
3
|
+
"nodes": [
|
|
4
|
+
{
|
|
5
|
+
"id": "run-manually",
|
|
6
|
+
"name": "Run manually",
|
|
7
|
+
"type": "n8n-nodes-base.manualTrigger",
|
|
8
|
+
"typeVersion": 1,
|
|
9
|
+
"position": [
|
|
10
|
+
0,
|
|
11
|
+
0
|
|
12
|
+
],
|
|
13
|
+
"parameters": {}
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"id": "read-campaign-rows",
|
|
17
|
+
"name": "Read campaign rows",
|
|
18
|
+
"type": "n8n-nodes-base.googleSheets",
|
|
19
|
+
"typeVersion": 4.7,
|
|
20
|
+
"position": [
|
|
21
|
+
250,
|
|
22
|
+
0
|
|
23
|
+
],
|
|
24
|
+
"parameters": {
|
|
25
|
+
"operation": "read",
|
|
26
|
+
"documentId": {
|
|
27
|
+
"__rl": true,
|
|
28
|
+
"value": "REPLACE_WITH_SPREADSHEET_ID",
|
|
29
|
+
"mode": "id"
|
|
30
|
+
},
|
|
31
|
+
"sheetName": {
|
|
32
|
+
"__rl": true,
|
|
33
|
+
"value": "Campaigns",
|
|
34
|
+
"mode": "name"
|
|
35
|
+
},
|
|
36
|
+
"options": {}
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"id": "prepare-campaign-rows",
|
|
41
|
+
"name": "Prepare campaign rows",
|
|
42
|
+
"type": "n8n-nodes-base.code",
|
|
43
|
+
"typeVersion": 2,
|
|
44
|
+
"position": [
|
|
45
|
+
500,
|
|
46
|
+
0
|
|
47
|
+
],
|
|
48
|
+
"parameters": {
|
|
49
|
+
"mode": "runOnceForAllItems",
|
|
50
|
+
"jsCode": "const uuid=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;\nconst allowed=['facebook','instagram','tiktok','line','email','print','youtube','x'];\nconst input=$input.all(); if(input.length>100) throw new Error('Read at most 100 sheet rows per run');\nconst used=new Set();\nreturn input.flatMap((item,index)=>{\n const r=item.json; if(r.shortUrls) return [];\n if(!uuid.test(String(r.requestId)) || used.has(r.requestId)) throw new Error('Each row needs its own UUID requestId, saved in the sheet before running');\n used.add(r.requestId);\n const channels=String(r.channels??'').split('|').map(x=>x.trim());\n if(!channels.length || new Set(channels).size!==channels.length || channels.some(c=>!allowed.includes(c))) throw new Error('Invalid channels');\n if(!r.name || !r.utmCampaign || !/^https?:\\/\\//i.test(String(r.url)) || /^https?:\\/\\/[^/]*@/i.test(String(r.url))) throw new Error('Provide name, URL and utmCampaign');\n return [{json:{requestId:r.requestId,campaign:{requestId:r.requestId,name:String(r.name),url:String(r.url),utmCampaign:String(r.utmCampaign),domain:String(r.domain||'linkdevi.com'),channels}},pairedItem:{item:index}}];\n});"
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"id": "create-saved-campaign",
|
|
55
|
+
"name": "Create saved campaign",
|
|
56
|
+
"type": "n8n-nodes-base.httpRequest",
|
|
57
|
+
"typeVersion": 4.3,
|
|
58
|
+
"position": [
|
|
59
|
+
750,
|
|
60
|
+
0
|
|
61
|
+
],
|
|
62
|
+
"parameters": {
|
|
63
|
+
"method": "POST",
|
|
64
|
+
"url": "https://linkdevi.com/api/v1/agent",
|
|
65
|
+
"authentication": "genericCredentialType",
|
|
66
|
+
"genericAuthType": "httpHeaderAuth",
|
|
67
|
+
"sendBody": true,
|
|
68
|
+
"specifyBody": "json",
|
|
69
|
+
"jsonBody": "={{ { action: 'create_campaign', campaign: $json.campaign } }}",
|
|
70
|
+
"options": {
|
|
71
|
+
"timeout": 25000,
|
|
72
|
+
"redirect": {
|
|
73
|
+
"redirect": {
|
|
74
|
+
"followRedirects": false
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
"batching": {
|
|
78
|
+
"batch": {
|
|
79
|
+
"batchSize": 1,
|
|
80
|
+
"batchInterval": 2500
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
"retryOnFail": false,
|
|
86
|
+
"onError": "stopWorkflow"
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
"id": "write-links-to-sheet",
|
|
90
|
+
"name": "Write links to sheet",
|
|
91
|
+
"type": "n8n-nodes-base.googleSheets",
|
|
92
|
+
"typeVersion": 4.7,
|
|
93
|
+
"position": [
|
|
94
|
+
1000,
|
|
95
|
+
0
|
|
96
|
+
],
|
|
97
|
+
"parameters": {
|
|
98
|
+
"operation": "update",
|
|
99
|
+
"documentId": {
|
|
100
|
+
"__rl": true,
|
|
101
|
+
"value": "REPLACE_WITH_SPREADSHEET_ID",
|
|
102
|
+
"mode": "id"
|
|
103
|
+
},
|
|
104
|
+
"sheetName": {
|
|
105
|
+
"__rl": true,
|
|
106
|
+
"value": "Campaigns",
|
|
107
|
+
"mode": "name"
|
|
108
|
+
},
|
|
109
|
+
"columns": {
|
|
110
|
+
"mappingMode": "defineBelow",
|
|
111
|
+
"value": {
|
|
112
|
+
"requestId": "={{ $('Prepare campaign rows').item.json.requestId }}",
|
|
113
|
+
"shortUrls": "={{ $json.campaign.channels.map(c => c.link?.shortUrl || '').filter(Boolean).join(' | ') }}",
|
|
114
|
+
"campaignId": "={{ $json.campaign.id }}"
|
|
115
|
+
},
|
|
116
|
+
"matchingColumns": [
|
|
117
|
+
"requestId"
|
|
118
|
+
],
|
|
119
|
+
"schema": [
|
|
120
|
+
{
|
|
121
|
+
"id": "requestId",
|
|
122
|
+
"displayName": "requestId",
|
|
123
|
+
"type": "string",
|
|
124
|
+
"canBeUsedToMatch": true
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
"id": "shortUrls",
|
|
128
|
+
"displayName": "shortUrls",
|
|
129
|
+
"type": "string"
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
"id": "campaignId",
|
|
133
|
+
"displayName": "campaignId",
|
|
134
|
+
"type": "string"
|
|
135
|
+
}
|
|
136
|
+
]
|
|
137
|
+
},
|
|
138
|
+
"options": {
|
|
139
|
+
"cellFormat": "RAW"
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
"id": "read-before-running",
|
|
145
|
+
"name": "Read before running",
|
|
146
|
+
"type": "n8n-nodes-base.stickyNote",
|
|
147
|
+
"typeVersion": 1,
|
|
148
|
+
"position": [
|
|
149
|
+
0,
|
|
150
|
+
-430
|
|
151
|
+
],
|
|
152
|
+
"parameters": {
|
|
153
|
+
"content": "## Setup\n1. Create a LinkDevi account, then a scoped key with links:read and links:write. Hosted plan limits apply.\n2. In Create saved campaign, select a Header Auth credential: header name Authorization, value Bearer YOUR_SCOPED_KEY. Keep the key only in n8n Credentials.\n3. Keep retries disabled. Redirects are disabled so credentials stay on the configured origin.\n4. Preview your data before running. Each selected channel uses one stored-link slot. A timeout may have committed: preserve requestId and the exact campaign payload on retry.\n5. These workflows do not call an LLM, send email, post to social media or enable a schedule. Activate only after reviewing your own setup.\nGuide: https://linkdevi.com/features/ai\n\n## Sheet columns\nrequestId, name, url, utmCampaign, channels, domain, shortUrls, campaignId\nUse one UNIQUE, pre-saved UUID per row. channels uses |, e.g. facebook|line|print. Rows with shortUrls are skipped. Configure the same spreadsheet in both Sheets nodes and select your Google Sheets credential. Output matching uses requestId, not a changing row position. Limit input to 100 rows; 429 stops the workflow. Review your data and credentials before running.",
|
|
154
|
+
"width": 700,
|
|
155
|
+
"height": 360
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
],
|
|
159
|
+
"connections": {
|
|
160
|
+
"Run manually": {
|
|
161
|
+
"main": [
|
|
162
|
+
[
|
|
163
|
+
{
|
|
164
|
+
"node": "Read campaign rows",
|
|
165
|
+
"type": "main",
|
|
166
|
+
"index": 0
|
|
167
|
+
}
|
|
168
|
+
]
|
|
169
|
+
]
|
|
170
|
+
},
|
|
171
|
+
"Read campaign rows": {
|
|
172
|
+
"main": [
|
|
173
|
+
[
|
|
174
|
+
{
|
|
175
|
+
"node": "Prepare campaign rows",
|
|
176
|
+
"type": "main",
|
|
177
|
+
"index": 0
|
|
178
|
+
}
|
|
179
|
+
]
|
|
180
|
+
]
|
|
181
|
+
},
|
|
182
|
+
"Prepare campaign rows": {
|
|
183
|
+
"main": [
|
|
184
|
+
[
|
|
185
|
+
{
|
|
186
|
+
"node": "Create saved campaign",
|
|
187
|
+
"type": "main",
|
|
188
|
+
"index": 0
|
|
189
|
+
}
|
|
190
|
+
]
|
|
191
|
+
]
|
|
192
|
+
},
|
|
193
|
+
"Create saved campaign": {
|
|
194
|
+
"main": [
|
|
195
|
+
[
|
|
196
|
+
{
|
|
197
|
+
"node": "Write links to sheet",
|
|
198
|
+
"type": "main",
|
|
199
|
+
"index": 0
|
|
200
|
+
}
|
|
201
|
+
]
|
|
202
|
+
]
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
"active": false,
|
|
206
|
+
"settings": {
|
|
207
|
+
"executionOrder": "v1"
|
|
208
|
+
},
|
|
209
|
+
"pinData": {},
|
|
210
|
+
"tags": []
|
|
211
|
+
}
|