@trimlynk/sdk 0.0.0-stage → 1.1.3
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 +387 -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 +89 -4
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Typed event models and parsers for incoming TrimLynk webhooks.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.WebhookEvent = void 0;
|
|
7
|
+
exports.parseWebhookEvent = parseWebhookEvent;
|
|
8
|
+
class WebhookEvent {
|
|
9
|
+
event;
|
|
10
|
+
timestamp;
|
|
11
|
+
data;
|
|
12
|
+
id;
|
|
13
|
+
raw;
|
|
14
|
+
constructor(init) {
|
|
15
|
+
this.event = init.event;
|
|
16
|
+
this.timestamp = init.timestamp ?? "";
|
|
17
|
+
this.data = init.data ?? {};
|
|
18
|
+
this.id = init.id;
|
|
19
|
+
this.raw = init.raw ?? {};
|
|
20
|
+
}
|
|
21
|
+
get isClick() {
|
|
22
|
+
return this.event.startsWith("click.");
|
|
23
|
+
}
|
|
24
|
+
get isConversion() {
|
|
25
|
+
return (this.event === "conversion.created" ||
|
|
26
|
+
this.event === "lead.created" ||
|
|
27
|
+
this.event === "sale.created" ||
|
|
28
|
+
this.event.startsWith("conversion."));
|
|
29
|
+
}
|
|
30
|
+
get isLink() {
|
|
31
|
+
return this.event.startsWith("link.");
|
|
32
|
+
}
|
|
33
|
+
get urlId() {
|
|
34
|
+
const val = this.data["urlId"] ??
|
|
35
|
+
this.data["url_id"] ??
|
|
36
|
+
this.data["linkId"] ??
|
|
37
|
+
this.data["link_id"] ??
|
|
38
|
+
this.data["id"];
|
|
39
|
+
return typeof val === "string" ? val : val !== undefined && val !== null ? String(val) : undefined;
|
|
40
|
+
}
|
|
41
|
+
get linkId() {
|
|
42
|
+
return this.urlId;
|
|
43
|
+
}
|
|
44
|
+
get shortCode() {
|
|
45
|
+
const val = this.data["shortCode"] ??
|
|
46
|
+
this.data["short_code"] ??
|
|
47
|
+
this.data["slug"] ??
|
|
48
|
+
this.data["customSlug"];
|
|
49
|
+
return typeof val === "string" ? val : undefined;
|
|
50
|
+
}
|
|
51
|
+
get shortUrl() {
|
|
52
|
+
const val = this.data["shortUrl"] ?? this.data["short_url"];
|
|
53
|
+
return typeof val === "string" ? val : undefined;
|
|
54
|
+
}
|
|
55
|
+
get eventName() {
|
|
56
|
+
const val = this.data["eventName"] ?? this.data["event_name"];
|
|
57
|
+
return typeof val === "string" ? val : undefined;
|
|
58
|
+
}
|
|
59
|
+
get eventValue() {
|
|
60
|
+
const val = this.data["eventValue"] ??
|
|
61
|
+
this.data["event_value"] ??
|
|
62
|
+
this.data["value"] ??
|
|
63
|
+
this.data["revenue"];
|
|
64
|
+
if (val === undefined || val === null)
|
|
65
|
+
return undefined;
|
|
66
|
+
const num = Number(val);
|
|
67
|
+
return Number.isFinite(num) ? num : undefined;
|
|
68
|
+
}
|
|
69
|
+
get revenue() {
|
|
70
|
+
return this.eventValue;
|
|
71
|
+
}
|
|
72
|
+
get currency() {
|
|
73
|
+
const val = this.data["currency"];
|
|
74
|
+
return typeof val === "string" && val ? val : "USD";
|
|
75
|
+
}
|
|
76
|
+
get orderId() {
|
|
77
|
+
const val = this.data["orderId"] ?? this.data["order_id"];
|
|
78
|
+
return typeof val === "string" ? val : undefined;
|
|
79
|
+
}
|
|
80
|
+
get customerId() {
|
|
81
|
+
const val = this.data["customerId"] ?? this.data["customer_id"];
|
|
82
|
+
return typeof val === "string" ? val : undefined;
|
|
83
|
+
}
|
|
84
|
+
get customerEmail() {
|
|
85
|
+
const val = this.data["customerEmail"] ?? this.data["customer_email"];
|
|
86
|
+
return typeof val === "string" ? val : undefined;
|
|
87
|
+
}
|
|
88
|
+
get channel() {
|
|
89
|
+
const val = this.data["channel"] ?? this.data["utmSource"] ?? this.data["utm_source"];
|
|
90
|
+
return typeof val === "string" ? val : undefined;
|
|
91
|
+
}
|
|
92
|
+
static fromDict(payload) {
|
|
93
|
+
const eventName = String(payload["event"] ?? payload["type"] ?? payload["eventType"] ?? "unknown");
|
|
94
|
+
const timestamp = String(payload["timestamp"] ?? payload["createdAt"] ?? payload["created_at"] ?? "");
|
|
95
|
+
const rawData = payload["data"];
|
|
96
|
+
const dataObj = rawData && typeof rawData === "object" && !Array.isArray(rawData)
|
|
97
|
+
? rawData
|
|
98
|
+
: { ...payload };
|
|
99
|
+
const idVal = payload["id"];
|
|
100
|
+
return new WebhookEvent({
|
|
101
|
+
event: eventName,
|
|
102
|
+
timestamp,
|
|
103
|
+
data: dataObj,
|
|
104
|
+
id: typeof idVal === "string" ? idVal : undefined,
|
|
105
|
+
raw: { ...payload },
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.WebhookEvent = WebhookEvent;
|
|
110
|
+
/**
|
|
111
|
+
* Parse raw webhook bytes, JSON string, or plain object into a typed {@link WebhookEvent}.
|
|
112
|
+
*
|
|
113
|
+
* @param payload - Raw JSON string, `Buffer`/`Uint8Array`, or already-parsed object.
|
|
114
|
+
* @returns A typed {@link WebhookEvent} instance with convenience getters (`isConversion`, `revenue`, `orderId`, etc.).
|
|
115
|
+
* @throws {Error} If the payload is not valid JSON or not a JSON object.
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```ts
|
|
119
|
+
* const event = parseWebhookEvent(rawBody);
|
|
120
|
+
* if (event.isConversion) {
|
|
121
|
+
* console.log(`Order #${event.orderId}: $${event.revenue}`);
|
|
122
|
+
* }
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
function parseWebhookEvent(payload) {
|
|
126
|
+
let parsed;
|
|
127
|
+
if (typeof payload === "string") {
|
|
128
|
+
try {
|
|
129
|
+
parsed = JSON.parse(payload);
|
|
130
|
+
}
|
|
131
|
+
catch (err) {
|
|
132
|
+
throw new Error(`Failed to parse webhook JSON payload: ${err instanceof Error ? err.message : String(err)}`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
else if (Buffer.isBuffer(payload) || payload instanceof Uint8Array) {
|
|
136
|
+
try {
|
|
137
|
+
parsed = JSON.parse(Buffer.from(payload).toString("utf8"));
|
|
138
|
+
}
|
|
139
|
+
catch (err) {
|
|
140
|
+
throw new Error(`Failed to parse webhook JSON payload: ${err instanceof Error ? err.message : String(err)}`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
else if (payload && typeof payload === "object" && !Array.isArray(payload)) {
|
|
144
|
+
parsed = payload;
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
throw new Error(`Unsupported webhook payload type: ${typeof payload}`);
|
|
148
|
+
}
|
|
149
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
150
|
+
throw new Error("Webhook payload must be a JSON object");
|
|
151
|
+
}
|
|
152
|
+
return WebhookEvent.fromDict(parsed);
|
|
153
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { TrimLynkConfig } from "./config.js";
|
|
2
|
+
import { TrimLynkError } from "./errors.js";
|
|
3
|
+
export declare const DEVELOPER_API_PREFIX = "/api/v1/developer";
|
|
4
|
+
export interface HttpResponse<T = unknown> {
|
|
5
|
+
statusCode: number;
|
|
6
|
+
data: T;
|
|
7
|
+
headers: Record<string, string>;
|
|
8
|
+
requestId: string | undefined;
|
|
9
|
+
idempotentReplay: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface HttpRequestOptions {
|
|
12
|
+
method: string;
|
|
13
|
+
path: string;
|
|
14
|
+
params?: Record<string, unknown> | undefined;
|
|
15
|
+
jsonBody?: Record<string, unknown> | undefined;
|
|
16
|
+
headers?: Record<string, string> | undefined;
|
|
17
|
+
idempotencyKey?: string | undefined;
|
|
18
|
+
requestId?: string | undefined;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Low-level HTTP client executing requests against the TrimLynk Developer API v1.
|
|
22
|
+
*/
|
|
23
|
+
export declare class HttpClient {
|
|
24
|
+
readonly config: TrimLynkConfig;
|
|
25
|
+
constructor(config: TrimLynkConfig);
|
|
26
|
+
buildUrl(path: string, params?: Record<string, unknown>): string;
|
|
27
|
+
request<T = unknown>(options: HttpRequestOptions): Promise<HttpResponse<T>>;
|
|
28
|
+
private executeOnce;
|
|
29
|
+
}
|
|
30
|
+
export { TrimLynkError };
|
package/dist/cjs/http.js
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TrimLynkError = exports.HttpClient = exports.DEVELOPER_API_PREFIX = void 0;
|
|
4
|
+
const errors_js_1 = require("./errors.js");
|
|
5
|
+
Object.defineProperty(exports, "TrimLynkError", { enumerable: true, get: function () { return errors_js_1.TrimLynkError; } });
|
|
6
|
+
exports.DEVELOPER_API_PREFIX = "/api/v1/developer";
|
|
7
|
+
function sleep(ms) {
|
|
8
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Low-level HTTP client executing requests against the TrimLynk Developer API v1.
|
|
12
|
+
*/
|
|
13
|
+
class HttpClient {
|
|
14
|
+
config;
|
|
15
|
+
constructor(config) {
|
|
16
|
+
this.config = config;
|
|
17
|
+
}
|
|
18
|
+
buildUrl(path, params) {
|
|
19
|
+
let cleanPath = path.startsWith("/") ? path : `/${path}`;
|
|
20
|
+
if (!cleanPath.startsWith(exports.DEVELOPER_API_PREFIX)) {
|
|
21
|
+
cleanPath = `${exports.DEVELOPER_API_PREFIX}${cleanPath}`;
|
|
22
|
+
}
|
|
23
|
+
let url = `${this.config.baseUrl}${cleanPath}`;
|
|
24
|
+
if (params) {
|
|
25
|
+
const searchParams = new URLSearchParams();
|
|
26
|
+
for (const [key, value] of Object.entries(params)) {
|
|
27
|
+
if (value === undefined || value === null) {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
if (typeof value === "boolean") {
|
|
31
|
+
searchParams.set(key, value ? "true" : "false");
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
searchParams.set(key, String(value));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const qs = searchParams.toString();
|
|
38
|
+
if (qs) {
|
|
39
|
+
url = `${url}?${qs}`;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return url;
|
|
43
|
+
}
|
|
44
|
+
async request(options) {
|
|
45
|
+
const maxAttempts = 1 + Math.max(0, this.config.maxRetries);
|
|
46
|
+
let lastError;
|
|
47
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
48
|
+
try {
|
|
49
|
+
return await this.executeOnce(options);
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
lastError = err;
|
|
53
|
+
if (err instanceof errors_js_1.RateLimitError && attempt < maxAttempts) {
|
|
54
|
+
const waitSec = err.retryAfter ?? Math.min(2 ** (attempt - 1), 30);
|
|
55
|
+
await sleep(waitSec * 1000);
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
throw err;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
throw lastError;
|
|
62
|
+
}
|
|
63
|
+
async executeOnce(options) {
|
|
64
|
+
const url = this.buildUrl(options.path, options.params);
|
|
65
|
+
const reqHeaders = {
|
|
66
|
+
Authorization: `Bearer ${this.config.apiKey}`,
|
|
67
|
+
"X-Trimlynk-API-Version": this.config.apiVersion,
|
|
68
|
+
Accept: "application/json",
|
|
69
|
+
"User-Agent": this.config.userAgent,
|
|
70
|
+
...options.headers,
|
|
71
|
+
};
|
|
72
|
+
if (options.idempotencyKey) {
|
|
73
|
+
reqHeaders["Idempotency-Key"] = String(options.idempotencyKey);
|
|
74
|
+
}
|
|
75
|
+
if (options.requestId) {
|
|
76
|
+
reqHeaders["X-Request-Id"] = String(options.requestId);
|
|
77
|
+
}
|
|
78
|
+
let body;
|
|
79
|
+
if (options.jsonBody !== undefined) {
|
|
80
|
+
reqHeaders["Content-Type"] = "application/json";
|
|
81
|
+
body = JSON.stringify(options.jsonBody);
|
|
82
|
+
}
|
|
83
|
+
let response;
|
|
84
|
+
try {
|
|
85
|
+
response = await this.config.fetch(url, {
|
|
86
|
+
method: options.method.toUpperCase(),
|
|
87
|
+
headers: reqHeaders,
|
|
88
|
+
body: body ?? null,
|
|
89
|
+
signal: AbortSignal.timeout(this.config.timeout),
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
if (err instanceof Error && (err.name === "TimeoutError" || err.name === "AbortError")) {
|
|
94
|
+
throw new errors_js_1.TimeoutError(`Request to ${options.path} timed out after ${this.config.timeout / 1000} seconds`, err);
|
|
95
|
+
}
|
|
96
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
97
|
+
throw new errors_js_1.NetworkError(`Network error connecting to TrimLynk API: ${reason}`, err);
|
|
98
|
+
}
|
|
99
|
+
const respHeaders = {};
|
|
100
|
+
response.headers.forEach((value, key) => {
|
|
101
|
+
respHeaders[key.toLowerCase()] = value;
|
|
102
|
+
});
|
|
103
|
+
const rawBody = await response.text();
|
|
104
|
+
let parsedData = null;
|
|
105
|
+
if (rawBody) {
|
|
106
|
+
try {
|
|
107
|
+
parsedData = JSON.parse(rawBody);
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
parsedData = rawBody;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
let resRequestId = respHeaders["x-request-id"];
|
|
114
|
+
if (parsedData && typeof parsedData === "object" && !Array.isArray(parsedData)) {
|
|
115
|
+
const maybeId = parsedData["requestId"];
|
|
116
|
+
if (typeof maybeId === "string" && maybeId) {
|
|
117
|
+
resRequestId = maybeId;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (!response.ok) {
|
|
121
|
+
let errPayload = null;
|
|
122
|
+
if (parsedData && typeof parsedData === "object" && !Array.isArray(parsedData)) {
|
|
123
|
+
errPayload = parsedData;
|
|
124
|
+
}
|
|
125
|
+
else if (rawBody) {
|
|
126
|
+
errPayload = { error: { message: rawBody } };
|
|
127
|
+
}
|
|
128
|
+
const retryAfterRaw = respHeaders["retry-after"];
|
|
129
|
+
let retryAfter;
|
|
130
|
+
if (retryAfterRaw) {
|
|
131
|
+
const parsed = Number.parseInt(retryAfterRaw, 10);
|
|
132
|
+
if (!Number.isNaN(parsed)) {
|
|
133
|
+
retryAfter = parsed;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
throw (0, errors_js_1.parseApiError)(response.status, errPayload, resRequestId, retryAfter);
|
|
137
|
+
}
|
|
138
|
+
const idempotentReplay = (respHeaders["idempotent-replay"] ?? "").toLowerCase() === "true";
|
|
139
|
+
return {
|
|
140
|
+
statusCode: response.status,
|
|
141
|
+
data: parsedData,
|
|
142
|
+
headers: respHeaders,
|
|
143
|
+
requestId: resRequestId,
|
|
144
|
+
idempotentReplay,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
exports.HttpClient = HttpClient;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export { TrimLynk } from "./client.js";
|
|
2
|
+
export { DEFAULT_API_VERSION, DEFAULT_BASE_URL, DEFAULT_TIMEOUT_MS, SDK_VERSION, TrimLynkConfig, USER_AGENT, } from "./config.js";
|
|
3
|
+
export type { FetchLike, TrimLynkConfigOptions, TrimLynkEnvironment } from "./config.js";
|
|
4
|
+
export { APIError, AuthenticationError, ConflictError, IdempotencyConflictError, InternalServerError, InvalidRequestError, InvalidSignatureHeaderError, NetworkError, NotFoundError, PermissionError, RateLimitError, SignatureExpiredError, SignatureMismatchError, SignatureVerificationError, TimeoutError, TrimLynkError, parseApiError, } from "./errors.js";
|
|
5
|
+
export type { APIErrorOptions, RateLimitErrorOptions } from "./errors.js";
|
|
6
|
+
export { WebhookEvent, parseWebhookEvent } from "./events.js";
|
|
7
|
+
export type { WebhookEventInit } from "./events.js";
|
|
8
|
+
export { DEVELOPER_API_PREFIX, HttpClient } from "./http.js";
|
|
9
|
+
export type { HttpRequestOptions, HttpResponse } from "./http.js";
|
|
10
|
+
export { AutoPagingIterator, PaginatedList, PaginationMetadata } from "./pagination.js";
|
|
11
|
+
export type { PaginationMetadataData } from "./pagination.js";
|
|
12
|
+
export { validateWebhookSignature, verifyWebhookSignature } from "./security.js";
|
|
13
|
+
export type { RawWebhookPayload, VerifyWebhookSignatureOptions } from "./security.js";
|
|
14
|
+
export { Link } from "./types.js";
|
|
15
|
+
export type { AnalyticsSummary, Campaign, Conversion, DeleteResult, FunnelAnalytics, LinkAnalytics, LinkData, TestWebhookResult, Webhook, WebhookDelivery, } from "./types.js";
|
|
16
|
+
export { buildUtmUrl } from "./utm.js";
|
|
17
|
+
export type { UtmParams } from "./utm.js";
|
|
18
|
+
export { AnalyticsResource } from "./resources/analytics.js";
|
|
19
|
+
export type { AnalyticsQueryParams, LinkAnalyticsQueryParams } from "./resources/analytics.js";
|
|
20
|
+
export { CampaignsResource } from "./resources/campaigns.js";
|
|
21
|
+
export type { CreateCampaignParams, ListCampaignsParams, UpdateCampaignParams, } from "./resources/campaigns.js";
|
|
22
|
+
export { ConversionsResource } from "./resources/conversions.js";
|
|
23
|
+
export type { CreateConversionParams, ListConversionsParams } from "./resources/conversions.js";
|
|
24
|
+
export { LinksResource } from "./resources/links.js";
|
|
25
|
+
export type { CreateLinkParams, CreateManyLinksOptions, ListLinksParams, UpdateLinkParams, } from "./resources/links.js";
|
|
26
|
+
export { WebhooksResource } from "./resources/webhooks.js";
|
|
27
|
+
export type { ConstructWebhookEventOptions, CreateWebhookParams, ListWebhooksParams, UpdateWebhookParams, } from "./resources/webhooks.js";
|
|
28
|
+
export declare const VERSION = "1.1.3";
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VERSION = exports.WebhooksResource = exports.LinksResource = exports.ConversionsResource = exports.CampaignsResource = exports.AnalyticsResource = exports.buildUtmUrl = exports.Link = exports.verifyWebhookSignature = exports.validateWebhookSignature = exports.PaginationMetadata = exports.PaginatedList = exports.AutoPagingIterator = exports.HttpClient = exports.DEVELOPER_API_PREFIX = exports.parseWebhookEvent = exports.WebhookEvent = exports.parseApiError = exports.TrimLynkError = exports.TimeoutError = exports.SignatureVerificationError = exports.SignatureMismatchError = exports.SignatureExpiredError = exports.RateLimitError = exports.PermissionError = exports.NotFoundError = exports.NetworkError = exports.InvalidSignatureHeaderError = exports.InvalidRequestError = exports.InternalServerError = exports.IdempotencyConflictError = exports.ConflictError = exports.AuthenticationError = exports.APIError = exports.USER_AGENT = exports.TrimLynkConfig = exports.SDK_VERSION = exports.DEFAULT_TIMEOUT_MS = exports.DEFAULT_BASE_URL = exports.DEFAULT_API_VERSION = exports.TrimLynk = void 0;
|
|
4
|
+
var client_js_1 = require("./client.js");
|
|
5
|
+
Object.defineProperty(exports, "TrimLynk", { enumerable: true, get: function () { return client_js_1.TrimLynk; } });
|
|
6
|
+
var config_js_1 = require("./config.js");
|
|
7
|
+
Object.defineProperty(exports, "DEFAULT_API_VERSION", { enumerable: true, get: function () { return config_js_1.DEFAULT_API_VERSION; } });
|
|
8
|
+
Object.defineProperty(exports, "DEFAULT_BASE_URL", { enumerable: true, get: function () { return config_js_1.DEFAULT_BASE_URL; } });
|
|
9
|
+
Object.defineProperty(exports, "DEFAULT_TIMEOUT_MS", { enumerable: true, get: function () { return config_js_1.DEFAULT_TIMEOUT_MS; } });
|
|
10
|
+
Object.defineProperty(exports, "SDK_VERSION", { enumerable: true, get: function () { return config_js_1.SDK_VERSION; } });
|
|
11
|
+
Object.defineProperty(exports, "TrimLynkConfig", { enumerable: true, get: function () { return config_js_1.TrimLynkConfig; } });
|
|
12
|
+
Object.defineProperty(exports, "USER_AGENT", { enumerable: true, get: function () { return config_js_1.USER_AGENT; } });
|
|
13
|
+
var errors_js_1 = require("./errors.js");
|
|
14
|
+
Object.defineProperty(exports, "APIError", { enumerable: true, get: function () { return errors_js_1.APIError; } });
|
|
15
|
+
Object.defineProperty(exports, "AuthenticationError", { enumerable: true, get: function () { return errors_js_1.AuthenticationError; } });
|
|
16
|
+
Object.defineProperty(exports, "ConflictError", { enumerable: true, get: function () { return errors_js_1.ConflictError; } });
|
|
17
|
+
Object.defineProperty(exports, "IdempotencyConflictError", { enumerable: true, get: function () { return errors_js_1.IdempotencyConflictError; } });
|
|
18
|
+
Object.defineProperty(exports, "InternalServerError", { enumerable: true, get: function () { return errors_js_1.InternalServerError; } });
|
|
19
|
+
Object.defineProperty(exports, "InvalidRequestError", { enumerable: true, get: function () { return errors_js_1.InvalidRequestError; } });
|
|
20
|
+
Object.defineProperty(exports, "InvalidSignatureHeaderError", { enumerable: true, get: function () { return errors_js_1.InvalidSignatureHeaderError; } });
|
|
21
|
+
Object.defineProperty(exports, "NetworkError", { enumerable: true, get: function () { return errors_js_1.NetworkError; } });
|
|
22
|
+
Object.defineProperty(exports, "NotFoundError", { enumerable: true, get: function () { return errors_js_1.NotFoundError; } });
|
|
23
|
+
Object.defineProperty(exports, "PermissionError", { enumerable: true, get: function () { return errors_js_1.PermissionError; } });
|
|
24
|
+
Object.defineProperty(exports, "RateLimitError", { enumerable: true, get: function () { return errors_js_1.RateLimitError; } });
|
|
25
|
+
Object.defineProperty(exports, "SignatureExpiredError", { enumerable: true, get: function () { return errors_js_1.SignatureExpiredError; } });
|
|
26
|
+
Object.defineProperty(exports, "SignatureMismatchError", { enumerable: true, get: function () { return errors_js_1.SignatureMismatchError; } });
|
|
27
|
+
Object.defineProperty(exports, "SignatureVerificationError", { enumerable: true, get: function () { return errors_js_1.SignatureVerificationError; } });
|
|
28
|
+
Object.defineProperty(exports, "TimeoutError", { enumerable: true, get: function () { return errors_js_1.TimeoutError; } });
|
|
29
|
+
Object.defineProperty(exports, "TrimLynkError", { enumerable: true, get: function () { return errors_js_1.TrimLynkError; } });
|
|
30
|
+
Object.defineProperty(exports, "parseApiError", { enumerable: true, get: function () { return errors_js_1.parseApiError; } });
|
|
31
|
+
var events_js_1 = require("./events.js");
|
|
32
|
+
Object.defineProperty(exports, "WebhookEvent", { enumerable: true, get: function () { return events_js_1.WebhookEvent; } });
|
|
33
|
+
Object.defineProperty(exports, "parseWebhookEvent", { enumerable: true, get: function () { return events_js_1.parseWebhookEvent; } });
|
|
34
|
+
var http_js_1 = require("./http.js");
|
|
35
|
+
Object.defineProperty(exports, "DEVELOPER_API_PREFIX", { enumerable: true, get: function () { return http_js_1.DEVELOPER_API_PREFIX; } });
|
|
36
|
+
Object.defineProperty(exports, "HttpClient", { enumerable: true, get: function () { return http_js_1.HttpClient; } });
|
|
37
|
+
var pagination_js_1 = require("./pagination.js");
|
|
38
|
+
Object.defineProperty(exports, "AutoPagingIterator", { enumerable: true, get: function () { return pagination_js_1.AutoPagingIterator; } });
|
|
39
|
+
Object.defineProperty(exports, "PaginatedList", { enumerable: true, get: function () { return pagination_js_1.PaginatedList; } });
|
|
40
|
+
Object.defineProperty(exports, "PaginationMetadata", { enumerable: true, get: function () { return pagination_js_1.PaginationMetadata; } });
|
|
41
|
+
var security_js_1 = require("./security.js");
|
|
42
|
+
Object.defineProperty(exports, "validateWebhookSignature", { enumerable: true, get: function () { return security_js_1.validateWebhookSignature; } });
|
|
43
|
+
Object.defineProperty(exports, "verifyWebhookSignature", { enumerable: true, get: function () { return security_js_1.verifyWebhookSignature; } });
|
|
44
|
+
var types_js_1 = require("./types.js");
|
|
45
|
+
Object.defineProperty(exports, "Link", { enumerable: true, get: function () { return types_js_1.Link; } });
|
|
46
|
+
var utm_js_1 = require("./utm.js");
|
|
47
|
+
Object.defineProperty(exports, "buildUtmUrl", { enumerable: true, get: function () { return utm_js_1.buildUtmUrl; } });
|
|
48
|
+
var analytics_js_1 = require("./resources/analytics.js");
|
|
49
|
+
Object.defineProperty(exports, "AnalyticsResource", { enumerable: true, get: function () { return analytics_js_1.AnalyticsResource; } });
|
|
50
|
+
var campaigns_js_1 = require("./resources/campaigns.js");
|
|
51
|
+
Object.defineProperty(exports, "CampaignsResource", { enumerable: true, get: function () { return campaigns_js_1.CampaignsResource; } });
|
|
52
|
+
var conversions_js_1 = require("./resources/conversions.js");
|
|
53
|
+
Object.defineProperty(exports, "ConversionsResource", { enumerable: true, get: function () { return conversions_js_1.ConversionsResource; } });
|
|
54
|
+
var links_js_1 = require("./resources/links.js");
|
|
55
|
+
Object.defineProperty(exports, "LinksResource", { enumerable: true, get: function () { return links_js_1.LinksResource; } });
|
|
56
|
+
var webhooks_js_1 = require("./resources/webhooks.js");
|
|
57
|
+
Object.defineProperty(exports, "WebhooksResource", { enumerable: true, get: function () { return webhooks_js_1.WebhooksResource; } });
|
|
58
|
+
exports.VERSION = "1.1.3";
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export interface PaginationMetadataData {
|
|
2
|
+
page: number;
|
|
3
|
+
limit: number;
|
|
4
|
+
total: number;
|
|
5
|
+
totalPages: number;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Pagination details returned with list endpoints.
|
|
9
|
+
*/
|
|
10
|
+
export declare class PaginationMetadata {
|
|
11
|
+
readonly page: number;
|
|
12
|
+
readonly limit: number;
|
|
13
|
+
readonly total: number;
|
|
14
|
+
readonly totalPages: number;
|
|
15
|
+
constructor(data: PaginationMetadataData);
|
|
16
|
+
static fromApi(data?: Record<string, unknown>): PaginationMetadata;
|
|
17
|
+
toJSON(): PaginationMetadataData;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Holds a page of resource items alongside pagination metadata and request ID.
|
|
21
|
+
*/
|
|
22
|
+
export declare class PaginatedList<T> implements Iterable<T> {
|
|
23
|
+
readonly data: T[];
|
|
24
|
+
readonly pagination: PaginationMetadata;
|
|
25
|
+
readonly requestId: string | undefined;
|
|
26
|
+
constructor(data: T[], pagination: PaginationMetadata, requestId?: string);
|
|
27
|
+
get length(): number;
|
|
28
|
+
[Symbol.iterator](): Iterator<T>;
|
|
29
|
+
toJSON(): {
|
|
30
|
+
data: T[];
|
|
31
|
+
pagination: PaginationMetadataData;
|
|
32
|
+
requestId: string | undefined;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Asynchronously iterates through all pages of a paginated resource transparently.
|
|
37
|
+
*/
|
|
38
|
+
export declare class AutoPagingIterator<T> implements AsyncIterable<T> {
|
|
39
|
+
private readonly fetcher;
|
|
40
|
+
private readonly limit;
|
|
41
|
+
private readonly startPage;
|
|
42
|
+
constructor(fetcher: (page: number, limit: number) => Promise<PaginatedList<T>>, limit?: number, startPage?: number);
|
|
43
|
+
[Symbol.asyncIterator](): AsyncIterator<T>;
|
|
44
|
+
/**
|
|
45
|
+
* Collect all items across all pages into a single array.
|
|
46
|
+
*
|
|
47
|
+
* @returns Promise resolving to an array of all paginated items.
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* const allLinks = await client.links.iter({ limit: 100 }).toArray();
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
toArray(): Promise<T[]>;
|
|
54
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AutoPagingIterator = exports.PaginatedList = exports.PaginationMetadata = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Pagination details returned with list endpoints.
|
|
6
|
+
*/
|
|
7
|
+
class PaginationMetadata {
|
|
8
|
+
page;
|
|
9
|
+
limit;
|
|
10
|
+
total;
|
|
11
|
+
totalPages;
|
|
12
|
+
constructor(data) {
|
|
13
|
+
this.page = data.page;
|
|
14
|
+
this.limit = data.limit;
|
|
15
|
+
this.total = data.total;
|
|
16
|
+
this.totalPages = data.totalPages;
|
|
17
|
+
}
|
|
18
|
+
static fromApi(data = {}) {
|
|
19
|
+
const rawTotalPages = data["totalPages"] ?? data["total_pages"] ?? 0;
|
|
20
|
+
return new PaginationMetadata({
|
|
21
|
+
page: Number(data["page"] ?? 1),
|
|
22
|
+
limit: Number(data["limit"] ?? 50),
|
|
23
|
+
total: Number(data["total"] ?? 0),
|
|
24
|
+
totalPages: Number(rawTotalPages),
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
toJSON() {
|
|
28
|
+
return {
|
|
29
|
+
page: this.page,
|
|
30
|
+
limit: this.limit,
|
|
31
|
+
total: this.total,
|
|
32
|
+
totalPages: this.totalPages,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.PaginationMetadata = PaginationMetadata;
|
|
37
|
+
/**
|
|
38
|
+
* Holds a page of resource items alongside pagination metadata and request ID.
|
|
39
|
+
*/
|
|
40
|
+
class PaginatedList {
|
|
41
|
+
data;
|
|
42
|
+
pagination;
|
|
43
|
+
requestId;
|
|
44
|
+
constructor(data, pagination, requestId) {
|
|
45
|
+
this.data = data;
|
|
46
|
+
this.pagination = pagination;
|
|
47
|
+
this.requestId = requestId;
|
|
48
|
+
}
|
|
49
|
+
get length() {
|
|
50
|
+
return this.data.length;
|
|
51
|
+
}
|
|
52
|
+
[Symbol.iterator]() {
|
|
53
|
+
return this.data[Symbol.iterator]();
|
|
54
|
+
}
|
|
55
|
+
toJSON() {
|
|
56
|
+
return {
|
|
57
|
+
data: this.data,
|
|
58
|
+
pagination: this.pagination.toJSON(),
|
|
59
|
+
requestId: this.requestId,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.PaginatedList = PaginatedList;
|
|
64
|
+
/**
|
|
65
|
+
* Asynchronously iterates through all pages of a paginated resource transparently.
|
|
66
|
+
*/
|
|
67
|
+
class AutoPagingIterator {
|
|
68
|
+
fetcher;
|
|
69
|
+
limit;
|
|
70
|
+
startPage;
|
|
71
|
+
constructor(fetcher, limit = 50, startPage = 1) {
|
|
72
|
+
this.fetcher = fetcher;
|
|
73
|
+
this.limit = Math.max(1, Math.min(limit, 100));
|
|
74
|
+
this.startPage = startPage;
|
|
75
|
+
}
|
|
76
|
+
async *[Symbol.asyncIterator]() {
|
|
77
|
+
let currentPage = this.startPage;
|
|
78
|
+
let totalPages;
|
|
79
|
+
while (true) {
|
|
80
|
+
if (totalPages !== undefined && currentPage > totalPages) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const pageResult = await this.fetcher(currentPage, this.limit);
|
|
84
|
+
totalPages = pageResult.pagination.totalPages;
|
|
85
|
+
if (pageResult.data.length === 0) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
for (const item of pageResult.data) {
|
|
89
|
+
yield item;
|
|
90
|
+
}
|
|
91
|
+
currentPage += 1;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Collect all items across all pages into a single array.
|
|
96
|
+
*
|
|
97
|
+
* @returns Promise resolving to an array of all paginated items.
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* const allLinks = await client.links.iter({ limit: 100 }).toArray();
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
async toArray() {
|
|
104
|
+
const items = [];
|
|
105
|
+
for await (const item of this) {
|
|
106
|
+
items.push(item);
|
|
107
|
+
}
|
|
108
|
+
return items;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
exports.AutoPagingIterator = AutoPagingIterator;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { HttpClient } from "../http.js";
|
|
2
|
+
import { AnalyticsSummary, FunnelAnalytics, LinkAnalytics } from "../types.js";
|
|
3
|
+
export interface AnalyticsQueryParams {
|
|
4
|
+
startDate?: string | Date | undefined;
|
|
5
|
+
endDate?: string | Date | undefined;
|
|
6
|
+
urlId?: string | undefined;
|
|
7
|
+
linkId?: string | undefined;
|
|
8
|
+
requestId?: string | undefined;
|
|
9
|
+
}
|
|
10
|
+
export interface LinkAnalyticsQueryParams {
|
|
11
|
+
startDate?: string | Date | undefined;
|
|
12
|
+
endDate?: string | Date | undefined;
|
|
13
|
+
requestId?: string | undefined;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Resource client for querying aggregate workspace, per-link, and conversion funnel analytics.
|
|
17
|
+
*/
|
|
18
|
+
export declare class AnalyticsResource {
|
|
19
|
+
private readonly http;
|
|
20
|
+
constructor(httpClient: HttpClient);
|
|
21
|
+
/**
|
|
22
|
+
* Query aggregate workspace analytics across clicks, visitors, devices, countries, and referrers.
|
|
23
|
+
*
|
|
24
|
+
* @param params - Optional date range and link ID filters.
|
|
25
|
+
* @returns Normalized {@link AnalyticsSummary} metrics.
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* const summary = await client.analytics.get({ startDate: "2026-01-01" });
|
|
29
|
+
* console.log(summary.totalClicks, summary.countries);
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
get(params?: AnalyticsQueryParams): Promise<AnalyticsSummary>;
|
|
33
|
+
getLink(linkId: string, params?: LinkAnalyticsQueryParams): Promise<LinkAnalytics>;
|
|
34
|
+
conversions(params?: AnalyticsQueryParams): Promise<FunnelAnalytics>;
|
|
35
|
+
}
|