@trimlynk/sdk 0.0.0-stage → 1.1.2
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 +19 -0
- package/README.md +68 -2
- package/dist/cjs/cli/commands/analytics.d.ts +3 -0
- package/dist/cjs/cli/commands/analytics.js +80 -0
- package/dist/cjs/cli/commands/auth.d.ts +4 -0
- package/dist/cjs/cli/commands/auth.js +122 -0
- package/dist/cjs/cli/commands/campaigns.d.ts +6 -0
- package/dist/cjs/cli/commands/campaigns.js +229 -0
- package/dist/cjs/cli/commands/config.d.ts +3 -0
- package/dist/cjs/cli/commands/config.js +51 -0
- package/dist/cjs/cli/commands/conversions.d.ts +4 -0
- package/dist/cjs/cli/commands/conversions.js +160 -0
- package/dist/cjs/cli/commands/links.d.ts +6 -0
- package/dist/cjs/cli/commands/links.js +270 -0
- package/dist/cjs/cli/commands/webhooks.d.ts +10 -0
- package/dist/cjs/cli/commands/webhooks.js +510 -0
- package/dist/cjs/cli/configStore.d.ts +10 -0
- package/dist/cjs/cli/configStore.js +63 -0
- package/dist/cjs/cli/credentials.d.ts +23 -0
- package/dist/cjs/cli/credentials.js +235 -0
- package/dist/cjs/cli/exitCodes.d.ts +9 -0
- package/dist/cjs/cli/exitCodes.js +12 -0
- package/dist/cjs/cli/formatting.d.ts +19 -0
- package/dist/cjs/cli/formatting.js +110 -0
- package/dist/cjs/cli/index.d.ts +3 -0
- package/dist/cjs/cli/index.js +278 -0
- package/dist/cjs/cli/types.d.ts +13 -0
- package/dist/cjs/cli/types.js +2 -0
- package/dist/cjs/client.d.ts +89 -0
- package/dist/cjs/client.js +126 -0
- package/dist/cjs/config.d.ts +49 -0
- package/dist/cjs/config.js +67 -0
- package/dist/cjs/errors.d.ts +60 -0
- package/dist/cjs/errors.js +149 -0
- package/dist/cjs/events.d.ts +50 -0
- package/dist/cjs/events.js +153 -0
- package/dist/cjs/http.d.ts +30 -0
- package/dist/cjs/http.js +148 -0
- package/dist/cjs/index.d.ts +28 -0
- package/dist/cjs/index.js +58 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/pagination.d.ts +54 -0
- package/dist/cjs/pagination.js +111 -0
- package/dist/cjs/resources/analytics.d.ts +35 -0
- package/dist/cjs/resources/analytics.js +74 -0
- package/dist/cjs/resources/campaigns.d.ts +65 -0
- package/dist/cjs/resources/campaigns.js +139 -0
- package/dist/cjs/resources/conversions.d.ts +37 -0
- package/dist/cjs/resources/conversions.js +82 -0
- package/dist/cjs/resources/links.d.ts +95 -0
- package/dist/cjs/resources/links.js +199 -0
- package/dist/cjs/resources/webhooks.d.ts +66 -0
- package/dist/cjs/resources/webhooks.js +178 -0
- package/dist/cjs/security.d.ts +53 -0
- package/dist/cjs/security.js +156 -0
- package/dist/cjs/types.d.ts +149 -0
- package/dist/cjs/types.js +347 -0
- package/dist/cjs/utm.d.ts +36 -0
- package/dist/cjs/utm.js +44 -0
- package/dist/esm/cli/commands/analytics.d.ts +4 -0
- package/dist/esm/cli/commands/analytics.d.ts.map +1 -0
- package/dist/esm/cli/commands/analytics.js +77 -0
- package/dist/esm/cli/commands/analytics.js.map +1 -0
- package/dist/esm/cli/commands/auth.d.ts +5 -0
- package/dist/esm/cli/commands/auth.d.ts.map +1 -0
- package/dist/esm/cli/commands/auth.js +118 -0
- package/dist/esm/cli/commands/auth.js.map +1 -0
- package/dist/esm/cli/commands/campaigns.d.ts +7 -0
- package/dist/esm/cli/commands/campaigns.d.ts.map +1 -0
- package/dist/esm/cli/commands/campaigns.js +223 -0
- package/dist/esm/cli/commands/campaigns.js.map +1 -0
- package/dist/esm/cli/commands/config.d.ts +4 -0
- package/dist/esm/cli/commands/config.d.ts.map +1 -0
- package/dist/esm/cli/commands/config.js +48 -0
- package/dist/esm/cli/commands/config.js.map +1 -0
- package/dist/esm/cli/commands/conversions.d.ts +5 -0
- package/dist/esm/cli/commands/conversions.d.ts.map +1 -0
- package/dist/esm/cli/commands/conversions.js +156 -0
- package/dist/esm/cli/commands/conversions.js.map +1 -0
- package/dist/esm/cli/commands/links.d.ts +7 -0
- package/dist/esm/cli/commands/links.d.ts.map +1 -0
- package/dist/esm/cli/commands/links.js +264 -0
- package/dist/esm/cli/commands/links.js.map +1 -0
- package/dist/esm/cli/commands/webhooks.d.ts +11 -0
- package/dist/esm/cli/commands/webhooks.d.ts.map +1 -0
- package/dist/esm/cli/commands/webhooks.js +500 -0
- package/dist/esm/cli/commands/webhooks.js.map +1 -0
- package/dist/esm/cli/configStore.d.ts +11 -0
- package/dist/esm/cli/configStore.d.ts.map +1 -0
- package/dist/esm/cli/configStore.js +54 -0
- package/dist/esm/cli/configStore.js.map +1 -0
- package/dist/esm/cli/credentials.d.ts +24 -0
- package/dist/esm/cli/credentials.d.ts.map +1 -0
- package/dist/esm/cli/credentials.js +226 -0
- package/dist/esm/cli/credentials.js.map +1 -0
- package/dist/esm/cli/exitCodes.d.ts +10 -0
- package/dist/esm/cli/exitCodes.d.ts.map +1 -0
- package/dist/esm/cli/exitCodes.js +10 -0
- package/dist/esm/cli/exitCodes.js.map +1 -0
- package/dist/esm/cli/formatting.d.ts +20 -0
- package/dist/esm/cli/formatting.d.ts.map +1 -0
- package/dist/esm/cli/formatting.js +95 -0
- package/dist/esm/cli/formatting.js.map +1 -0
- package/dist/esm/cli/index.d.ts +4 -0
- package/dist/esm/cli/index.d.ts.map +1 -0
- package/dist/esm/cli/index.js +276 -0
- package/dist/esm/cli/index.js.map +1 -0
- package/dist/esm/cli/types.d.ts +14 -0
- package/dist/esm/cli/types.d.ts.map +1 -0
- package/dist/esm/cli/types.js +2 -0
- package/dist/esm/cli/types.js.map +1 -0
- package/dist/esm/client.d.ts +90 -0
- package/dist/esm/client.d.ts.map +1 -0
- package/dist/esm/client.js +123 -0
- package/dist/esm/client.js.map +1 -0
- package/dist/esm/config.d.ts +50 -0
- package/dist/esm/config.d.ts.map +1 -0
- package/dist/esm/config.js +64 -0
- package/dist/esm/config.js.map +1 -0
- package/dist/esm/errors.d.ts +61 -0
- package/dist/esm/errors.d.ts.map +1 -0
- package/dist/esm/errors.js +130 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/events.d.ts +51 -0
- package/dist/esm/events.d.ts.map +1 -0
- package/dist/esm/events.js +149 -0
- package/dist/esm/events.js.map +1 -0
- package/dist/esm/http.d.ts +31 -0
- package/dist/esm/http.d.ts.map +1 -0
- package/dist/esm/http.js +145 -0
- package/dist/esm/http.js.map +1 -0
- package/dist/esm/index.d.ts +29 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +16 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/pagination.d.ts +55 -0
- package/dist/esm/pagination.d.ts.map +1 -0
- package/dist/esm/pagination.js +106 -0
- package/dist/esm/pagination.js.map +1 -0
- package/dist/esm/resources/analytics.d.ts +36 -0
- package/dist/esm/resources/analytics.d.ts.map +1 -0
- package/dist/esm/resources/analytics.js +71 -0
- package/dist/esm/resources/analytics.js.map +1 -0
- package/dist/esm/resources/campaigns.d.ts +66 -0
- package/dist/esm/resources/campaigns.d.ts.map +1 -0
- package/dist/esm/resources/campaigns.js +136 -0
- package/dist/esm/resources/campaigns.js.map +1 -0
- package/dist/esm/resources/conversions.d.ts +38 -0
- package/dist/esm/resources/conversions.d.ts.map +1 -0
- package/dist/esm/resources/conversions.js +79 -0
- package/dist/esm/resources/conversions.js.map +1 -0
- package/dist/esm/resources/links.d.ts +96 -0
- package/dist/esm/resources/links.d.ts.map +1 -0
- package/dist/esm/resources/links.js +196 -0
- package/dist/esm/resources/links.js.map +1 -0
- package/dist/esm/resources/webhooks.d.ts +67 -0
- package/dist/esm/resources/webhooks.d.ts.map +1 -0
- package/dist/esm/resources/webhooks.js +175 -0
- package/dist/esm/resources/webhooks.js.map +1 -0
- package/dist/esm/security.d.ts +54 -0
- package/dist/esm/security.d.ts.map +1 -0
- package/dist/esm/security.js +153 -0
- package/dist/esm/security.js.map +1 -0
- package/dist/esm/types.d.ts +150 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +335 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/utm.d.ts +37 -0
- package/dist/esm/utm.d.ts.map +1 -0
- package/dist/esm/utm.js +42 -0
- package/dist/esm/utm.js.map +1 -0
- package/package.json +91 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
TrimLynk Software Development Kit (SDK) End-User License Agreement
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Vivek Gaur, Ashish Kumar Dwivedi / TrimLynk. All rights reserved.
|
|
4
|
+
|
|
5
|
+
1. GRANT OF USE
|
|
6
|
+
TrimLynk hereby grants you a personal, worldwide, non-exclusive, non-transferable, revocable license to install, import, and execute this software package in your applications solely for the purpose of integrating with and consuming TrimLynk APIs and services.
|
|
7
|
+
|
|
8
|
+
2. RESTRICTIONS
|
|
9
|
+
Except as expressly permitted by applicable law, you may not:
|
|
10
|
+
(a) Modify, adapt, translate, reverse engineer, decompile, or disassemble any portion of the software;
|
|
11
|
+
(b) Create derivative works based on the software;
|
|
12
|
+
(c) Rent, lease, loan, resell, sublicense, or distribute modified copies of the software to any third party;
|
|
13
|
+
(d) Remove or obscure any proprietary notices, labels, or marks on the software.
|
|
14
|
+
|
|
15
|
+
3. INTELLECTUAL PROPERTY
|
|
16
|
+
The software, including its architecture, interfaces, and documentation, constitutes proprietary intellectual property of TrimLynk. No ownership rights are transferred to you.
|
|
17
|
+
|
|
18
|
+
4. DISCLAIMER OF WARRANTIES
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE OR THE USE THEREOF.
|
package/README.md
CHANGED
|
@@ -1,3 +1,69 @@
|
|
|
1
|
-
#
|
|
1
|
+
# TrimLynk Node.js & TypeScript SDK (`@trimlynk/sdk`)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Official Node.js / TypeScript SDK and CLI for the [TrimLynk Developer API v1](https://trimlynk.com/developers/sdks).
|
|
4
|
+
|
|
5
|
+
- **Zero runtime dependencies** (built on native Node.js `fetch`, `node:crypto`, `node:util`, `node:fs`)
|
|
6
|
+
- **Node.js `>=22.0.0`** with dual **ESM & CommonJS** exports and full TypeScript declarations
|
|
7
|
+
- **Bundled `trimlynk` CLI** with native OS keychain support (macOS Keychain, Linux Secret Service, Windows DPAPI) + `0600` file fallback
|
|
8
|
+
|
|
9
|
+
> **API Reference**: Browse the generated TypeDoc Markdown documentation at [docs/README.md](./docs/README.md).
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @trimlynk/sdk
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Or install globally for the `trimlynk` CLI:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install -g @trimlynk/sdk
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Quick Start
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { TrimLynk } from "@trimlynk/sdk";
|
|
27
|
+
|
|
28
|
+
const client = new TrimLynk({
|
|
29
|
+
apiKey: process.env.TRIMLYNK_API_KEY,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const link = await client.links.create({
|
|
33
|
+
originalUrl: "https://example.com/pricing",
|
|
34
|
+
customSlug: "pricing-2026",
|
|
35
|
+
title: "Pricing Page",
|
|
36
|
+
tags: ["marketing", "q4"],
|
|
37
|
+
utmSource: "newsletter",
|
|
38
|
+
autoDecorateUtm: true,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
console.log(link.shortUrl);
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
CommonJS is also supported:
|
|
45
|
+
|
|
46
|
+
```js
|
|
47
|
+
const { TrimLynk } = require("@trimlynk/sdk");
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Features
|
|
51
|
+
|
|
52
|
+
- **Resources**: `client.links`, `client.analytics`, `client.conversions`, `client.campaigns`, `client.webhooks`
|
|
53
|
+
- **Auto-Pagination**: `for await (const link of client.links.iter()) { ... }` or `await client.links.iter().toArray()`
|
|
54
|
+
- **Bulk Concurrency**: `await client.links.createMany(items, { concurrency: 5 })`
|
|
55
|
+
- **QR Code Saving**: `await client.links.downloadQr(linkId, "./qr.png")`
|
|
56
|
+
- **Idempotency**: Pass `idempotencyKey` on `create()` calls and inspect `result.idempotentReplay`
|
|
57
|
+
- **Typed Error Hierarchy**: `AuthenticationError`, `InvalidRequestError`, `NotFoundError`, `RateLimitError`, `IdempotencyConflictError`, `TimeoutError`, `NetworkError`, `SignatureVerificationError`
|
|
58
|
+
- **Webhook Verification**: `client.webhooks.constructEvent({ payload, signatureHeader, secret })` and `TrimLynk.verifyWebhookSignature(...)`
|
|
59
|
+
- **UTM Builder**: `buildUtmUrl("https://example.com", { source: "twitter", medium: "social" })`
|
|
60
|
+
|
|
61
|
+
## CLI Usage
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
trimlynk auth login
|
|
65
|
+
trimlynk links create https://example.com --slug demo --quiet
|
|
66
|
+
trimlynk links list --all --json
|
|
67
|
+
trimlynk analytics summary
|
|
68
|
+
trimlynk webhooks listen --tunnel-url https://your-tunnel.ngrok-free.dev
|
|
69
|
+
```
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ClientFactory, GlobalCliOptions } from "../types.js";
|
|
2
|
+
export declare function cmdAnalyticsSummary(argv: string[], opts: GlobalCliOptions, getClient: ClientFactory): Promise<number>;
|
|
3
|
+
export declare function cmdAnalyticsLink(argv: string[], opts: GlobalCliOptions, getClient: ClientFactory): Promise<number>;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cmdAnalyticsSummary = cmdAnalyticsSummary;
|
|
4
|
+
exports.cmdAnalyticsLink = cmdAnalyticsLink;
|
|
5
|
+
const node_util_1 = require("node:util");
|
|
6
|
+
const exitCodes_js_1 = require("../exitCodes.js");
|
|
7
|
+
const formatting_js_1 = require("../formatting.js");
|
|
8
|
+
async function cmdAnalyticsSummary(argv, opts, getClient) {
|
|
9
|
+
const { values } = (0, node_util_1.parseArgs)({
|
|
10
|
+
args: argv,
|
|
11
|
+
allowPositionals: false,
|
|
12
|
+
options: {
|
|
13
|
+
"start-date": { type: "string" },
|
|
14
|
+
"end-date": { type: "string" },
|
|
15
|
+
"url-id": { type: "string" },
|
|
16
|
+
"link-id": { type: "string" },
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
const client = getClient();
|
|
20
|
+
const summary = await client.analytics.get({
|
|
21
|
+
startDate: values["start-date"],
|
|
22
|
+
endDate: values["end-date"],
|
|
23
|
+
urlId: values["url-id"] ?? values["link-id"],
|
|
24
|
+
});
|
|
25
|
+
if (opts.quiet) {
|
|
26
|
+
process.stdout.write(`${summary.totalClicks}\n`);
|
|
27
|
+
}
|
|
28
|
+
else if (opts.json) {
|
|
29
|
+
(0, formatting_js_1.outputJson)(summary);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
(0, formatting_js_1.printDetails)([
|
|
33
|
+
["Total Clicks:", summary.totalClicks],
|
|
34
|
+
["Unique Visitors:", summary.uniqueVisitors],
|
|
35
|
+
["Request ID:", summary.requestId],
|
|
36
|
+
]);
|
|
37
|
+
const countryRows = Object.entries(summary.countries)
|
|
38
|
+
.slice(0, 10)
|
|
39
|
+
.map(([c, n]) => [c, n]);
|
|
40
|
+
if (countryRows.length > 0) {
|
|
41
|
+
process.stdout.write("\nTop Countries:\n");
|
|
42
|
+
(0, formatting_js_1.printTable)(["COUNTRY", "CLICKS"], countryRows);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return exitCodes_js_1.EXIT_SUCCESS;
|
|
46
|
+
}
|
|
47
|
+
async function cmdAnalyticsLink(argv, opts, getClient) {
|
|
48
|
+
const { values, positionals } = (0, node_util_1.parseArgs)({
|
|
49
|
+
args: argv,
|
|
50
|
+
allowPositionals: true,
|
|
51
|
+
options: {
|
|
52
|
+
"start-date": { type: "string" },
|
|
53
|
+
"end-date": { type: "string" },
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
const linkId = positionals[0];
|
|
57
|
+
if (!linkId) {
|
|
58
|
+
(0, formatting_js_1.printError)("Missing required <link_id> argument.");
|
|
59
|
+
return exitCodes_js_1.EXIT_INVALID_ARGS;
|
|
60
|
+
}
|
|
61
|
+
const client = getClient();
|
|
62
|
+
const data = await client.analytics.getLink(linkId, {
|
|
63
|
+
startDate: values["start-date"],
|
|
64
|
+
endDate: values["end-date"],
|
|
65
|
+
});
|
|
66
|
+
if (opts.quiet) {
|
|
67
|
+
process.stdout.write(`${data.clicks}\n`);
|
|
68
|
+
}
|
|
69
|
+
else if (opts.json) {
|
|
70
|
+
(0, formatting_js_1.outputJson)(data);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
(0, formatting_js_1.printDetails)([
|
|
74
|
+
["Link ID:", data.linkId],
|
|
75
|
+
["Clicks:", data.clicks],
|
|
76
|
+
["Request ID:", data.requestId],
|
|
77
|
+
]);
|
|
78
|
+
}
|
|
79
|
+
return exitCodes_js_1.EXIT_SUCCESS;
|
|
80
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ClientFactory, GlobalCliOptions } from "../types.js";
|
|
2
|
+
export declare function cmdLogin(opts: GlobalCliOptions, getClient: ClientFactory): Promise<number>;
|
|
3
|
+
export declare function cmdLogout(opts: GlobalCliOptions): Promise<number>;
|
|
4
|
+
export declare function cmdStatus(opts: GlobalCliOptions, getClient: ClientFactory, check: boolean): Promise<number>;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cmdLogin = cmdLogin;
|
|
4
|
+
exports.cmdLogout = cmdLogout;
|
|
5
|
+
exports.cmdStatus = cmdStatus;
|
|
6
|
+
const promises_1 = require("node:readline/promises");
|
|
7
|
+
const errors_js_1 = require("../../errors.js");
|
|
8
|
+
const credentials_js_1 = require("../credentials.js");
|
|
9
|
+
const exitCodes_js_1 = require("../exitCodes.js");
|
|
10
|
+
const formatting_js_1 = require("../formatting.js");
|
|
11
|
+
async function cmdLogin(opts, getClient) {
|
|
12
|
+
let apiKey = opts.apiKey;
|
|
13
|
+
if (!apiKey) {
|
|
14
|
+
if (!process.stdin.isTTY) {
|
|
15
|
+
(0, formatting_js_1.printError)("Cannot prompt for API key in non-interactive environment. Use TRIMLYNK_API_KEY or --api-key.");
|
|
16
|
+
return exitCodes_js_1.EXIT_AUTHENTICATION_ERROR;
|
|
17
|
+
}
|
|
18
|
+
const rl = (0, promises_1.createInterface)({ input: process.stdin, output: process.stdout });
|
|
19
|
+
try {
|
|
20
|
+
apiKey = (await rl.question("TrimLynk API key: ")).trim();
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
process.stdout.write("\nAborted.\n");
|
|
24
|
+
return exitCodes_js_1.EXIT_GENERAL_ERROR;
|
|
25
|
+
}
|
|
26
|
+
finally {
|
|
27
|
+
rl.close();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (!apiKey) {
|
|
31
|
+
(0, formatting_js_1.printError)("API key cannot be empty.");
|
|
32
|
+
return exitCodes_js_1.EXIT_AUTHENTICATION_ERROR;
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
const client = getClient({ apiKey });
|
|
36
|
+
await client.links.list({ limit: 1 });
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
if (err instanceof errors_js_1.AuthenticationError) {
|
|
40
|
+
(0, formatting_js_1.printError)(`Authentication failed: ${err.message}`, {
|
|
41
|
+
code: err.code,
|
|
42
|
+
requestId: err.requestId,
|
|
43
|
+
});
|
|
44
|
+
return exitCodes_js_1.EXIT_AUTHENTICATION_ERROR;
|
|
45
|
+
}
|
|
46
|
+
if (err instanceof errors_js_1.TrimLynkError) {
|
|
47
|
+
(0, formatting_js_1.printError)(`Failed to verify API key: ${err.message}`);
|
|
48
|
+
return exitCodes_js_1.EXIT_GENERAL_ERROR;
|
|
49
|
+
}
|
|
50
|
+
throw err;
|
|
51
|
+
}
|
|
52
|
+
(0, credentials_js_1.saveApiKey)(apiKey);
|
|
53
|
+
if (opts.json) {
|
|
54
|
+
(0, formatting_js_1.outputJson)({
|
|
55
|
+
authenticated: true,
|
|
56
|
+
masked_key: (0, credentials_js_1.maskApiKey)(apiKey),
|
|
57
|
+
environment: opts.environment ?? "live",
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
else if (!opts.quiet) {
|
|
61
|
+
process.stdout.write(`${(0, formatting_js_1.green)("✓ Successfully authenticated with TrimLynk")}\n`);
|
|
62
|
+
process.stdout.write(`Stored API Key: ${(0, credentials_js_1.maskApiKey)(apiKey)}\n`);
|
|
63
|
+
}
|
|
64
|
+
return exitCodes_js_1.EXIT_SUCCESS;
|
|
65
|
+
}
|
|
66
|
+
async function cmdLogout(opts) {
|
|
67
|
+
const removed = (0, credentials_js_1.deleteApiKey)();
|
|
68
|
+
if (opts.json) {
|
|
69
|
+
(0, formatting_js_1.outputJson)({ logged_out: true, credentials_removed: removed });
|
|
70
|
+
}
|
|
71
|
+
else if (!opts.quiet) {
|
|
72
|
+
if (removed) {
|
|
73
|
+
process.stdout.write(`${(0, formatting_js_1.green)("✓ Successfully logged out from TrimLynk")}\n`);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
process.stdout.write("No stored credentials found.\n");
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return exitCodes_js_1.EXIT_SUCCESS;
|
|
80
|
+
}
|
|
81
|
+
async function cmdStatus(opts, getClient, check) {
|
|
82
|
+
const apiKey = (0, credentials_js_1.resolveApiKey)(opts.apiKey);
|
|
83
|
+
const env = opts.environment ?? "live";
|
|
84
|
+
const source = (0, credentials_js_1.getCredentialSource)(opts.apiKey);
|
|
85
|
+
let remoteStatus = "not checked";
|
|
86
|
+
if (check && apiKey) {
|
|
87
|
+
try {
|
|
88
|
+
const client = getClient({ apiKey });
|
|
89
|
+
await client.links.list({ limit: 1 });
|
|
90
|
+
remoteStatus = "valid";
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
if (err instanceof errors_js_1.AuthenticationError) {
|
|
94
|
+
remoteStatus = "invalid / expired";
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
remoteStatus = `error checking (${err instanceof Error ? err.message : String(err)})`;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (opts.json) {
|
|
102
|
+
(0, formatting_js_1.outputJson)({
|
|
103
|
+
authenticated: Boolean(apiKey),
|
|
104
|
+
environment: env,
|
|
105
|
+
api_key: (0, credentials_js_1.maskApiKey)(apiKey),
|
|
106
|
+
source,
|
|
107
|
+
remote_status: remoteStatus,
|
|
108
|
+
api_version: "1",
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
(0, formatting_js_1.printDetails)([
|
|
113
|
+
["Authenticated:", apiKey ? "yes" : "no"],
|
|
114
|
+
["Environment:", env],
|
|
115
|
+
["API Key:", (0, credentials_js_1.maskApiKey)(apiKey)],
|
|
116
|
+
["Source:", source],
|
|
117
|
+
["Remote Status:", remoteStatus],
|
|
118
|
+
["API Version:", "1"],
|
|
119
|
+
]);
|
|
120
|
+
}
|
|
121
|
+
return exitCodes_js_1.EXIT_SUCCESS;
|
|
122
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ClientFactory, GlobalCliOptions } from "../types.js";
|
|
2
|
+
export declare function cmdCampaignsCreate(argv: string[], opts: GlobalCliOptions, getClient: ClientFactory): Promise<number>;
|
|
3
|
+
export declare function cmdCampaignsList(argv: string[], opts: GlobalCliOptions, getClient: ClientFactory): Promise<number>;
|
|
4
|
+
export declare function cmdCampaignsGet(argv: string[], opts: GlobalCliOptions, getClient: ClientFactory): Promise<number>;
|
|
5
|
+
export declare function cmdCampaignsUpdate(argv: string[], opts: GlobalCliOptions, getClient: ClientFactory): Promise<number>;
|
|
6
|
+
export declare function cmdCampaignsDelete(argv: string[], opts: GlobalCliOptions, getClient: ClientFactory): Promise<number>;
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cmdCampaignsCreate = cmdCampaignsCreate;
|
|
4
|
+
exports.cmdCampaignsList = cmdCampaignsList;
|
|
5
|
+
exports.cmdCampaignsGet = cmdCampaignsGet;
|
|
6
|
+
exports.cmdCampaignsUpdate = cmdCampaignsUpdate;
|
|
7
|
+
exports.cmdCampaignsDelete = cmdCampaignsDelete;
|
|
8
|
+
const node_util_1 = require("node:util");
|
|
9
|
+
const exitCodes_js_1 = require("../exitCodes.js");
|
|
10
|
+
const formatting_js_1 = require("../formatting.js");
|
|
11
|
+
async function cmdCampaignsCreate(argv, opts, getClient) {
|
|
12
|
+
const { values } = (0, node_util_1.parseArgs)({
|
|
13
|
+
args: argv,
|
|
14
|
+
allowPositionals: false,
|
|
15
|
+
options: {
|
|
16
|
+
name: { type: "string" },
|
|
17
|
+
description: { type: "string" },
|
|
18
|
+
color: { type: "string" },
|
|
19
|
+
icon: { type: "string" },
|
|
20
|
+
status: { type: "string" },
|
|
21
|
+
goal: { type: "string" },
|
|
22
|
+
budget: { type: "string" },
|
|
23
|
+
"start-date": { type: "string" },
|
|
24
|
+
"end-date": { type: "string" },
|
|
25
|
+
"utm-source": { type: "string" },
|
|
26
|
+
"utm-medium": { type: "string" },
|
|
27
|
+
"utm-campaign": { type: "string" },
|
|
28
|
+
"idempotency-key": { type: "string" },
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
if (!values.name) {
|
|
32
|
+
(0, formatting_js_1.printError)("--name is required.");
|
|
33
|
+
return exitCodes_js_1.EXIT_INVALID_ARGS;
|
|
34
|
+
}
|
|
35
|
+
const client = getClient();
|
|
36
|
+
const cmp = await client.campaigns.create({
|
|
37
|
+
name: values.name,
|
|
38
|
+
description: values.description,
|
|
39
|
+
color: values.color,
|
|
40
|
+
icon: values.icon,
|
|
41
|
+
status: values.status,
|
|
42
|
+
goal: values.goal !== undefined ? Number.parseInt(values.goal, 10) : undefined,
|
|
43
|
+
budget: values.budget,
|
|
44
|
+
startDate: values["start-date"],
|
|
45
|
+
endDate: values["end-date"],
|
|
46
|
+
utmSource: values["utm-source"],
|
|
47
|
+
utmMedium: values["utm-medium"],
|
|
48
|
+
utmCampaign: values["utm-campaign"],
|
|
49
|
+
idempotencyKey: values["idempotency-key"],
|
|
50
|
+
});
|
|
51
|
+
if (opts.quiet) {
|
|
52
|
+
process.stdout.write(`${cmp.id}\n`);
|
|
53
|
+
}
|
|
54
|
+
else if (opts.json) {
|
|
55
|
+
(0, formatting_js_1.outputJson)(cmp);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
process.stdout.write(`✓ Campaign created: ${cmp.id}\n\n`);
|
|
59
|
+
(0, formatting_js_1.printDetails)([
|
|
60
|
+
["ID:", cmp.id],
|
|
61
|
+
["Name:", cmp.name],
|
|
62
|
+
["Status:", cmp.status ?? "active"],
|
|
63
|
+
["Request ID:", cmp.requestId],
|
|
64
|
+
]);
|
|
65
|
+
}
|
|
66
|
+
return exitCodes_js_1.EXIT_SUCCESS;
|
|
67
|
+
}
|
|
68
|
+
async function cmdCampaignsList(argv, opts, getClient) {
|
|
69
|
+
const { values } = (0, node_util_1.parseArgs)({
|
|
70
|
+
args: argv,
|
|
71
|
+
allowPositionals: false,
|
|
72
|
+
options: {
|
|
73
|
+
page: { type: "string" },
|
|
74
|
+
limit: { type: "string" },
|
|
75
|
+
all: { type: "boolean", default: false },
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
const pageNum = values.page ? Number.parseInt(values.page, 10) : 1;
|
|
79
|
+
const limitNum = values.limit ? Number.parseInt(values.limit, 10) : 50;
|
|
80
|
+
const client = getClient();
|
|
81
|
+
if (values.all) {
|
|
82
|
+
const items = await client.campaigns.iter({ limit: limitNum }).toArray();
|
|
83
|
+
if (opts.quiet) {
|
|
84
|
+
for (const item of items)
|
|
85
|
+
process.stdout.write(`${item.id}\n`);
|
|
86
|
+
}
|
|
87
|
+
else if (opts.json) {
|
|
88
|
+
(0, formatting_js_1.outputJson)(items);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
const rows = items.map((c) => [c.id, c.name, c.status ?? "active", c.linkCount ?? 0]);
|
|
92
|
+
(0, formatting_js_1.printTable)(["ID", "NAME", "STATUS", "LINKS"], rows);
|
|
93
|
+
process.stdout.write(`\nTotal: ${items.length} campaigns (streamed)\n`);
|
|
94
|
+
}
|
|
95
|
+
return exitCodes_js_1.EXIT_SUCCESS;
|
|
96
|
+
}
|
|
97
|
+
const page = await client.campaigns.list({ page: pageNum, limit: limitNum });
|
|
98
|
+
if (opts.quiet) {
|
|
99
|
+
for (const item of page)
|
|
100
|
+
process.stdout.write(`${item.id}\n`);
|
|
101
|
+
}
|
|
102
|
+
else if (opts.json) {
|
|
103
|
+
(0, formatting_js_1.outputJson)(page);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
const rows = page.data.map((c) => [c.id, c.name, c.status ?? "active", c.linkCount ?? 0]);
|
|
107
|
+
(0, formatting_js_1.printTable)(["ID", "NAME", "STATUS", "LINKS"], rows);
|
|
108
|
+
const p = page.pagination;
|
|
109
|
+
const start = p.total > 0 ? (p.page - 1) * p.limit + 1 : 0;
|
|
110
|
+
const end = Math.min(p.page * p.limit, p.total);
|
|
111
|
+
process.stdout.write(`\nShowing ${start}–${end} of ${p.total} (Page ${p.page} of ${p.totalPages})\n`);
|
|
112
|
+
}
|
|
113
|
+
return exitCodes_js_1.EXIT_SUCCESS;
|
|
114
|
+
}
|
|
115
|
+
async function cmdCampaignsGet(argv, opts, getClient) {
|
|
116
|
+
const campaignId = argv[0];
|
|
117
|
+
if (!campaignId) {
|
|
118
|
+
(0, formatting_js_1.printError)("Missing required <campaign_id> argument.");
|
|
119
|
+
return exitCodes_js_1.EXIT_INVALID_ARGS;
|
|
120
|
+
}
|
|
121
|
+
const client = getClient();
|
|
122
|
+
const cmp = await client.campaigns.get(campaignId);
|
|
123
|
+
if (opts.quiet) {
|
|
124
|
+
process.stdout.write(`${cmp.id}\n`);
|
|
125
|
+
}
|
|
126
|
+
else if (opts.json) {
|
|
127
|
+
(0, formatting_js_1.outputJson)(cmp);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
(0, formatting_js_1.printDetails)([
|
|
131
|
+
["ID:", cmp.id],
|
|
132
|
+
["Name:", cmp.name],
|
|
133
|
+
["Status:", cmp.status ?? "active"],
|
|
134
|
+
["Description:", cmp.description ?? "(none)"],
|
|
135
|
+
["Links:", cmp.linkCount ?? 0],
|
|
136
|
+
["Request ID:", cmp.requestId],
|
|
137
|
+
]);
|
|
138
|
+
}
|
|
139
|
+
return exitCodes_js_1.EXIT_SUCCESS;
|
|
140
|
+
}
|
|
141
|
+
async function cmdCampaignsUpdate(argv, opts, getClient) {
|
|
142
|
+
const { values, positionals } = (0, node_util_1.parseArgs)({
|
|
143
|
+
args: argv,
|
|
144
|
+
allowPositionals: true,
|
|
145
|
+
options: {
|
|
146
|
+
name: { type: "string" },
|
|
147
|
+
description: { type: "string" },
|
|
148
|
+
color: { type: "string" },
|
|
149
|
+
icon: { type: "string" },
|
|
150
|
+
status: { type: "string" },
|
|
151
|
+
goal: { type: "string" },
|
|
152
|
+
budget: { type: "string" },
|
|
153
|
+
"start-date": { type: "string" },
|
|
154
|
+
"end-date": { type: "string" },
|
|
155
|
+
"utm-source": { type: "string" },
|
|
156
|
+
"utm-medium": { type: "string" },
|
|
157
|
+
"utm-campaign": { type: "string" },
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
const campaignId = positionals[0];
|
|
161
|
+
if (!campaignId) {
|
|
162
|
+
(0, formatting_js_1.printError)("Missing required <campaign_id> argument.");
|
|
163
|
+
return exitCodes_js_1.EXIT_INVALID_ARGS;
|
|
164
|
+
}
|
|
165
|
+
const client = getClient();
|
|
166
|
+
const cmp = await client.campaigns.update(campaignId, {
|
|
167
|
+
name: values.name,
|
|
168
|
+
description: values.description,
|
|
169
|
+
color: values.color,
|
|
170
|
+
icon: values.icon,
|
|
171
|
+
status: values.status,
|
|
172
|
+
goal: values.goal !== undefined ? Number.parseInt(values.goal, 10) : undefined,
|
|
173
|
+
budget: values.budget,
|
|
174
|
+
startDate: values["start-date"],
|
|
175
|
+
endDate: values["end-date"],
|
|
176
|
+
utmSource: values["utm-source"],
|
|
177
|
+
utmMedium: values["utm-medium"],
|
|
178
|
+
utmCampaign: values["utm-campaign"],
|
|
179
|
+
});
|
|
180
|
+
if (opts.quiet) {
|
|
181
|
+
process.stdout.write(`${cmp.id}\n`);
|
|
182
|
+
}
|
|
183
|
+
else if (opts.json) {
|
|
184
|
+
(0, formatting_js_1.outputJson)(cmp);
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
process.stdout.write(`✓ Campaign updated: ${cmp.id}\n\n`);
|
|
188
|
+
(0, formatting_js_1.printDetails)([
|
|
189
|
+
["ID:", cmp.id],
|
|
190
|
+
["Name:", cmp.name],
|
|
191
|
+
["Status:", cmp.status ?? "active"],
|
|
192
|
+
["Request ID:", cmp.requestId],
|
|
193
|
+
]);
|
|
194
|
+
}
|
|
195
|
+
return exitCodes_js_1.EXIT_SUCCESS;
|
|
196
|
+
}
|
|
197
|
+
async function cmdCampaignsDelete(argv, opts, getClient) {
|
|
198
|
+
const { values, positionals } = (0, node_util_1.parseArgs)({
|
|
199
|
+
args: argv,
|
|
200
|
+
allowPositionals: true,
|
|
201
|
+
options: {
|
|
202
|
+
yes: { type: "boolean", short: "y", default: false },
|
|
203
|
+
},
|
|
204
|
+
});
|
|
205
|
+
const campaignId = positionals[0];
|
|
206
|
+
if (!campaignId) {
|
|
207
|
+
(0, formatting_js_1.printError)("Missing required <campaign_id> argument.");
|
|
208
|
+
return exitCodes_js_1.EXIT_INVALID_ARGS;
|
|
209
|
+
}
|
|
210
|
+
if (!values.yes) {
|
|
211
|
+
const confirmed = await (0, formatting_js_1.confirmAction)(`Are you sure you want to delete campaign ${campaignId}?`);
|
|
212
|
+
if (!confirmed) {
|
|
213
|
+
process.stdout.write("Operation cancelled.\n");
|
|
214
|
+
return exitCodes_js_1.EXIT_SUCCESS;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
const client = getClient();
|
|
218
|
+
const res = await client.campaigns.delete(campaignId);
|
|
219
|
+
if (opts.quiet) {
|
|
220
|
+
process.stdout.write(`${campaignId}\n`);
|
|
221
|
+
}
|
|
222
|
+
else if (opts.json) {
|
|
223
|
+
(0, formatting_js_1.outputJson)(res);
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
process.stdout.write(`✓ Campaign deleted: ${campaignId}\n`);
|
|
227
|
+
}
|
|
228
|
+
return exitCodes_js_1.EXIT_SUCCESS;
|
|
229
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cmdConfigGet = cmdConfigGet;
|
|
4
|
+
exports.cmdConfigSet = cmdConfigSet;
|
|
5
|
+
const configStore_js_1 = require("../configStore.js");
|
|
6
|
+
const credentials_js_1 = require("../credentials.js");
|
|
7
|
+
const exitCodes_js_1 = require("../exitCodes.js");
|
|
8
|
+
const formatting_js_1 = require("../formatting.js");
|
|
9
|
+
async function cmdConfigGet(opts, key) {
|
|
10
|
+
if (key) {
|
|
11
|
+
const val = key === "api_key"
|
|
12
|
+
? (0, credentials_js_1.maskApiKey)((0, credentials_js_1.resolveApiKey)())
|
|
13
|
+
: (0, configStore_js_1.getConfigValue)(key) ?? "(not set)";
|
|
14
|
+
if (opts.json) {
|
|
15
|
+
(0, formatting_js_1.outputJson)({ [key]: val });
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
process.stdout.write(`${key}: ${val}\n`);
|
|
19
|
+
}
|
|
20
|
+
return exitCodes_js_1.EXIT_SUCCESS;
|
|
21
|
+
}
|
|
22
|
+
const config = (0, configStore_js_1.readConfig)();
|
|
23
|
+
const displayData = {
|
|
24
|
+
api_key: (0, credentials_js_1.maskApiKey)((0, credentials_js_1.resolveApiKey)()),
|
|
25
|
+
environment: config["environment"] ?? "live",
|
|
26
|
+
base_url: config["base_url"] ?? "https://api.trimlynk.com",
|
|
27
|
+
...config,
|
|
28
|
+
};
|
|
29
|
+
displayData["api_key"] = (0, credentials_js_1.maskApiKey)((0, credentials_js_1.resolveApiKey)());
|
|
30
|
+
if (opts.json) {
|
|
31
|
+
(0, formatting_js_1.outputJson)(displayData);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
(0, formatting_js_1.printDetails)(Object.entries(displayData).map(([k, v]) => [`${k}:`, v]));
|
|
35
|
+
}
|
|
36
|
+
return exitCodes_js_1.EXIT_SUCCESS;
|
|
37
|
+
}
|
|
38
|
+
async function cmdConfigSet(opts, key, value) {
|
|
39
|
+
if (!key || value === undefined) {
|
|
40
|
+
(0, formatting_js_1.printError)("Usage: trimlynk config set <key> <value>");
|
|
41
|
+
return exitCodes_js_1.EXIT_INVALID_ARGS;
|
|
42
|
+
}
|
|
43
|
+
(0, configStore_js_1.setConfigValue)(key, value);
|
|
44
|
+
if (opts.json) {
|
|
45
|
+
(0, formatting_js_1.outputJson)({ key, value, updated: true });
|
|
46
|
+
}
|
|
47
|
+
else if (!opts.quiet) {
|
|
48
|
+
process.stdout.write(`✓ Configuration updated: ${key} = ${value}\n`);
|
|
49
|
+
}
|
|
50
|
+
return exitCodes_js_1.EXIT_SUCCESS;
|
|
51
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ClientFactory, GlobalCliOptions } from "../types.js";
|
|
2
|
+
export declare function cmdConversionsCreate(argv: string[], opts: GlobalCliOptions, getClient: ClientFactory): Promise<number>;
|
|
3
|
+
export declare function cmdConversionsList(argv: string[], opts: GlobalCliOptions, getClient: ClientFactory): Promise<number>;
|
|
4
|
+
export declare function cmdConversionsGet(argv: string[], opts: GlobalCliOptions, getClient: ClientFactory): Promise<number>;
|