@kgma/linkdevi-tools 0.1.0 → 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/README.md +29 -2
- package/dist/cli.js +17 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/utm.d.ts +24 -0
- package/dist/utm.js +101 -0
- package/examples/github-actions/utm-lint.yml +25 -0
- package/examples/utm-links.csv +3 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
# LinkDevi developer pack
|
|
2
2
|
|
|
3
|
+
Documentation: [Quickstart](https://linkdevi.com/docs/quickstart) · [CLI](https://linkdevi.com/docs/cli) · [TypeScript SDK](https://linkdevi.com/docs/sdk) · [n8n setup](https://linkdevi.com/docs/n8n) · [AI-readable index](https://linkdevi.com/llms.txt).
|
|
4
|
+
|
|
3
5
|
Offline Campaign Launch Kit helpers, a TypeScript SDK, a Node.js CLI and three n8n workflows. MIT licensed. Node.js 22+.
|
|
4
6
|
|
|
5
7
|
Package name: `@kgma/linkdevi-tools`. The separately distributed `@kgma/linkdevi-mcp` is the MCP connector. This repository includes the complete source and build instructions; npm releases and source releases carry their own version.
|
|
6
8
|
|
|
7
9
|
```sh
|
|
8
|
-
npm install @kgma/linkdevi-tools@0.
|
|
10
|
+
npm install @kgma/linkdevi-tools@0.2.0
|
|
9
11
|
npx --no-install linkdevi --help
|
|
10
12
|
```
|
|
11
13
|
|
|
@@ -26,6 +28,31 @@ Preview, UTM generation, CSV export and CSV preflight run locally, without a key
|
|
|
26
28
|
|
|
27
29
|
The public website uses the same channel/UTM helpers at `/tools/campaign-launch-kit` and `/th/campaign-launch-kit` (also Chinese, Spanish, Indonesian and Japanese). Preview does not reserve quota. A domain in an offline preview does not prove that the account can use it; the service validates that when saving.
|
|
28
30
|
|
|
31
|
+
## UTM Checker / Linter (0.2.0)
|
|
32
|
+
|
|
33
|
+
Version `0.2.0` includes `utm lint`; version `0.1.0` does not. Build this checkout or install the versioned package when available on the registry. The check runs offline, requires no account or API key, does not open destination URLs, and creates no links.
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
npm ci
|
|
37
|
+
npm run build
|
|
38
|
+
node dist/cli.js utm lint examples/utm-links.csv
|
|
39
|
+
node dist/cli.js utm lint examples/utm-links.csv --format json
|
|
40
|
+
node dist/cli.js utm lint examples/utm-links.csv --format github --strict
|
|
41
|
+
# Check the destinations exported by campaign preview:
|
|
42
|
+
node dist/cli.js campaign preview campaign.json --format csv > launch.csv
|
|
43
|
+
node dist/cli.js utm lint launch.csv
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Accepts CSV with one `url` or `destination_url` column (unique headers, up to 100 data records and 256 KiB). Other columns are retained in your original file and are not included in the report. Records must have the same column count as the header. Record numbers are logical CSV records, including the header; quoted multiline fields do not correspond to physical line numbers.
|
|
47
|
+
|
|
48
|
+
Errors cover invalid URLs, missing/blank `utm_source`, `utm_medium` or `utm_campaign`, duplicate UTM parameters including case variants, and decoded control characters. Warnings cover parameter casing, unknown UTM keys, whitespace, source capitalization variants across rows, and repeated URLs ignoring query parameter order. Different non-UTM destination parameters or fragments remain distinct. Naming conventions vary: review warnings deliberately; the tool does not rewrite files, merge source names, check destination availability, or promise analytics attribution.
|
|
49
|
+
|
|
50
|
+
Exit status is `1` for errors or malformed input, `0` for a clean check or warnings only. Add `--strict` to fail on warnings too. JSON has `schemaVersion: 1`, row-level issue codes, and totals. Reports omit destination URLs and parameter values, including GitHub annotations. Keep input files private when needed.
|
|
51
|
+
|
|
52
|
+
The SDK exports `lintUtmUrls`, `lintUtmCsv` and `formatUtmReport`. Use [the workflow example](examples/github-actions/utm-lint.yml) in a source checkout; it needs only read access and no secrets. The repository CI workflow tests Node 22 and 24, checks the sample CSV and installs the packed CLI in a clean consumer. Check the Actions tab for the result on the exact commit you use. Action references follow the official [checkout](https://github.com/actions/checkout) and [setup-node](https://github.com/actions/setup-node) examples and are pinned to the reviewed commits.
|
|
53
|
+
|
|
54
|
+
After reviewing a report, use [Campaign Launch Kit](https://linkdevi.com/tools/campaign-launch-kit?utm_source=github&utm_medium=developer_tool&utm_campaign=utm_linter) to prepare channel links. Preview/export is free without signing in. Saving short links requires a LinkDevi account and uses your workspace permissions and allowance. Keep your existing URL/UTM decisions when preparing a new campaign; linting does not automatically import or save them.
|
|
55
|
+
|
|
29
56
|
## Create and manage saved campaigns
|
|
30
57
|
|
|
31
58
|
1. Create a [LinkDevi account](https://linkdevi.com/register), open Connect AI, and create a scoped key. Use `links:read` and `links:write` for campaign creation, or only `links:read` for read-only use.
|
|
@@ -92,7 +119,7 @@ Reference: [n8n HTTP Request](https://docs.n8n.io/integrations/builtin/core-node
|
|
|
92
119
|
npm test
|
|
93
120
|
npm pack
|
|
94
121
|
# In another project, install the generated local artifact:
|
|
95
|
-
npm install /absolute/path/to/kgma-linkdevi-tools-0.
|
|
122
|
+
npm install /absolute/path/to/kgma-linkdevi-tools-0.2.0.tgz
|
|
96
123
|
npx --no-install linkdevi --help
|
|
97
124
|
```
|
|
98
125
|
|
package/dist/cli.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { readFileSync, writeFileSync, statSync } from "node:fs";
|
|
3
3
|
import { randomUUID } from "node:crypto";
|
|
4
4
|
import { LinkDeviClient, LinkDeviError } from "./index.js";
|
|
5
5
|
import { previewCampaign, validateCampaign, launchCsv, planCsvImport } from "./campaign.js";
|
|
6
|
+
import { lintUtmCsv, formatUtmReport } from "./utm.js";
|
|
6
7
|
const help = `LinkDevi tools — Node 22+
|
|
7
8
|
|
|
8
9
|
linkdevi campaign init [--out campaign.json]
|
|
@@ -11,6 +12,7 @@ const help = `LinkDevi tools — Node 22+
|
|
|
11
12
|
linkdevi campaign list [--page 1]
|
|
12
13
|
linkdevi campaign stats CAMPAIGN_ID
|
|
13
14
|
linkdevi links import links.csv --dry-run
|
|
15
|
+
linkdevi utm lint links.csv [--format json|text|github] [--strict]
|
|
14
16
|
linkdevi capabilities
|
|
15
17
|
|
|
16
18
|
Preview, CSV validation and init work offline without an account.
|
|
@@ -21,6 +23,9 @@ Setup: https://linkdevi.com/features/ai`;
|
|
|
21
23
|
function read(path) {
|
|
22
24
|
if (!path || path.startsWith("--"))
|
|
23
25
|
throw new Error("Provide an input file");
|
|
26
|
+
const info = statSync(path);
|
|
27
|
+
if (!info.isFile() || info.size > 262144)
|
|
28
|
+
throw new Error("Use a regular input file up to 256 KiB");
|
|
24
29
|
const value = readFileSync(path, "utf8");
|
|
25
30
|
if (Buffer.byteLength(value) > 262144)
|
|
26
31
|
throw new Error("Input exceeds 256 KiB");
|
|
@@ -53,6 +58,17 @@ async function main(args) {
|
|
|
53
58
|
return;
|
|
54
59
|
}
|
|
55
60
|
const [group, command, input, ...extra] = args;
|
|
61
|
+
if (group === "utm" && command === "lint") {
|
|
62
|
+
const opts = options(extra, { "--format": "value", "--strict": "flag" });
|
|
63
|
+
const format = String(opts["--format"] || "text");
|
|
64
|
+
if (!["json", "text", "github"].includes(format))
|
|
65
|
+
throw new Error("Unknown report format");
|
|
66
|
+
const report = lintUtmCsv(read(input));
|
|
67
|
+
process.stdout.write(format === "json" ? JSON.stringify(report, null, 2) + "\n" : formatUtmReport(report, format));
|
|
68
|
+
if (report.summary.errors || (opts["--strict"] && report.summary.warnings))
|
|
69
|
+
process.exitCode = 1;
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
56
72
|
if (group === "campaign" && command === "init") {
|
|
57
73
|
const opts = options(args.slice(2), { "--out": "value" });
|
|
58
74
|
const draft = { requestId: randomUUID(), name: "December launch", url: "https://example.com/sale", utmCampaign: "december-launch", domain: "linkdevi.com", channels: ["facebook", "line", "print"] };
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
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
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kgma/linkdevi-tools",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Offline campaign launch kits, a typed LinkDevi API client and
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Offline campaign launch kits and UTM linting, a typed LinkDevi API client and campaign CLI.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"engines": {
|