@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,235 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defaultKeychainAdapter = exports.CREDENTIALS_FILE_NAME = exports.CONFIG_DIR_NAME = exports.KEYRING_USERNAME = exports.KEYRING_SERVICE_NAME = void 0;
|
|
4
|
+
exports.getConfigDir = getConfigDir;
|
|
5
|
+
exports.getCredentialsFile = getCredentialsFile;
|
|
6
|
+
exports.maskApiKey = maskApiKey;
|
|
7
|
+
exports.resolveApiKey = resolveApiKey;
|
|
8
|
+
exports.getCredentialSource = getCredentialSource;
|
|
9
|
+
exports.saveApiKey = saveApiKey;
|
|
10
|
+
exports.deleteApiKey = deleteApiKey;
|
|
11
|
+
const node_child_process_1 = require("node:child_process");
|
|
12
|
+
const node_fs_1 = require("node:fs");
|
|
13
|
+
const node_os_1 = require("node:os");
|
|
14
|
+
const node_path_1 = require("node:path");
|
|
15
|
+
exports.KEYRING_SERVICE_NAME = "trimlynk";
|
|
16
|
+
exports.KEYRING_USERNAME = "api_key";
|
|
17
|
+
exports.CONFIG_DIR_NAME = ".trimlynk";
|
|
18
|
+
exports.CREDENTIALS_FILE_NAME = "credentials.json";
|
|
19
|
+
function runCmd(cmd, args, input) {
|
|
20
|
+
try {
|
|
21
|
+
return (0, node_child_process_1.execFileSync)(cmd, args, {
|
|
22
|
+
input,
|
|
23
|
+
encoding: "utf8",
|
|
24
|
+
stdio: [input !== undefined ? "pipe" : "ignore", "pipe", "ignore"],
|
|
25
|
+
timeout: 3000,
|
|
26
|
+
}).trim();
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Zero-dependency OS keychain adapter using native OS tools:
|
|
34
|
+
* - macOS: `security` (Keychain)
|
|
35
|
+
* - Linux: `secret-tool` (libsecret / FreeDesktop Secret Service)
|
|
36
|
+
* - Windows: PowerShell DPAPI protected credential blob
|
|
37
|
+
*/
|
|
38
|
+
exports.defaultKeychainAdapter = {
|
|
39
|
+
getPassword(service, account) {
|
|
40
|
+
if (process.platform === "darwin") {
|
|
41
|
+
return runCmd("security", ["find-generic-password", "-s", service, "-a", account, "-w"]);
|
|
42
|
+
}
|
|
43
|
+
if (process.platform === "linux") {
|
|
44
|
+
return runCmd("secret-tool", ["lookup", "service", service, "username", account]);
|
|
45
|
+
}
|
|
46
|
+
if (process.platform === "win32") {
|
|
47
|
+
const credPath = (0, node_path_1.join)(getConfigDir(), "credentials.dpapi");
|
|
48
|
+
if (!(0, node_fs_1.existsSync)(credPath))
|
|
49
|
+
return null;
|
|
50
|
+
const script = [
|
|
51
|
+
"$ErrorActionPreference='Stop'",
|
|
52
|
+
`$raw = Get-Content -LiteralPath '${credPath.replace(/'/g, "''")}' -Raw`,
|
|
53
|
+
"$sec = ConvertTo-SecureString $raw",
|
|
54
|
+
"$bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($sec)",
|
|
55
|
+
"try { [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($bstr) } finally { [System.Runtime.InteropServices.Marshal]::ZeroFreeBSTR($bstr) }",
|
|
56
|
+
].join("; ");
|
|
57
|
+
return runCmd("powershell", ["-NoProfile", "-NonInteractive", "-Command", script]);
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
},
|
|
61
|
+
setPassword(service, account, secret) {
|
|
62
|
+
if (process.platform === "darwin") {
|
|
63
|
+
const res = runCmd("security", [
|
|
64
|
+
"add-generic-password",
|
|
65
|
+
"-U",
|
|
66
|
+
"-s",
|
|
67
|
+
service,
|
|
68
|
+
"-a",
|
|
69
|
+
account,
|
|
70
|
+
"-w",
|
|
71
|
+
secret,
|
|
72
|
+
]);
|
|
73
|
+
return res !== null;
|
|
74
|
+
}
|
|
75
|
+
if (process.platform === "linux") {
|
|
76
|
+
const res = runCmd("secret-tool", ["store", "--label=TrimLynk API Key", "service", service, "username", account], secret);
|
|
77
|
+
return res !== null;
|
|
78
|
+
}
|
|
79
|
+
if (process.platform === "win32") {
|
|
80
|
+
const credPath = (0, node_path_1.join)(getConfigDir(), "credentials.dpapi");
|
|
81
|
+
const escaped = secret.replace(/'/g, "''");
|
|
82
|
+
const script = [
|
|
83
|
+
"$ErrorActionPreference='Stop'",
|
|
84
|
+
`$sec = ConvertTo-SecureString '${escaped}' -AsPlainText -Force`,
|
|
85
|
+
"$enc = ConvertFrom-SecureString $sec",
|
|
86
|
+
`Set-Content -LiteralPath '${credPath.replace(/'/g, "''")}' -Value $enc -NoNewline`,
|
|
87
|
+
].join("; ");
|
|
88
|
+
return runCmd("powershell", ["-NoProfile", "-NonInteractive", "-Command", script]) !== null;
|
|
89
|
+
}
|
|
90
|
+
return false;
|
|
91
|
+
},
|
|
92
|
+
deletePassword(service, account) {
|
|
93
|
+
if (process.platform === "darwin") {
|
|
94
|
+
return runCmd("security", ["delete-generic-password", "-s", service, "-a", account]) !== null;
|
|
95
|
+
}
|
|
96
|
+
if (process.platform === "linux") {
|
|
97
|
+
return runCmd("secret-tool", ["clear", "service", service, "username", account]) !== null;
|
|
98
|
+
}
|
|
99
|
+
if (process.platform === "win32") {
|
|
100
|
+
const credPath = (0, node_path_1.join)(getConfigDir(), "credentials.dpapi");
|
|
101
|
+
if ((0, node_fs_1.existsSync)(credPath)) {
|
|
102
|
+
try {
|
|
103
|
+
(0, node_fs_1.unlinkSync)(credPath);
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
return false;
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
function getConfigDir(homeOverride) {
|
|
116
|
+
const dir = (0, node_path_1.join)(homeOverride ?? (0, node_os_1.homedir)(), exports.CONFIG_DIR_NAME);
|
|
117
|
+
if (!(0, node_fs_1.existsSync)(dir)) {
|
|
118
|
+
(0, node_fs_1.mkdirSync)(dir, { recursive: true, mode: 0o700 });
|
|
119
|
+
try {
|
|
120
|
+
(0, node_fs_1.chmodSync)(dir, 0o700);
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
// Ignore on Windows
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return dir;
|
|
127
|
+
}
|
|
128
|
+
function getCredentialsFile(homeOverride) {
|
|
129
|
+
return (0, node_path_1.join)(getConfigDir(homeOverride), exports.CREDENTIALS_FILE_NAME);
|
|
130
|
+
}
|
|
131
|
+
function maskApiKey(apiKey) {
|
|
132
|
+
if (!apiKey)
|
|
133
|
+
return "not configured";
|
|
134
|
+
const clean = apiKey.trim();
|
|
135
|
+
if (clean.length <= 12)
|
|
136
|
+
return "••••••••";
|
|
137
|
+
return `${clean.slice(0, 8)}••••••••••••${clean.slice(-4)}`;
|
|
138
|
+
}
|
|
139
|
+
function resolveApiKey(cliArg, keychain = exports.defaultKeychainAdapter, homeOverride) {
|
|
140
|
+
if (cliArg && cliArg.trim())
|
|
141
|
+
return cliArg.trim();
|
|
142
|
+
const envKey = (process.env["TRIMLYNK_API_KEY"] ?? "").trim();
|
|
143
|
+
if (envKey)
|
|
144
|
+
return envKey;
|
|
145
|
+
if (!homeOverride) {
|
|
146
|
+
try {
|
|
147
|
+
const krKey = keychain.getPassword(exports.KEYRING_SERVICE_NAME, exports.KEYRING_USERNAME);
|
|
148
|
+
if (krKey && krKey.trim())
|
|
149
|
+
return krKey.trim();
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
// Ignore keychain errors
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
const credFile = getCredentialsFile(homeOverride);
|
|
156
|
+
if ((0, node_fs_1.existsSync)(credFile)) {
|
|
157
|
+
try {
|
|
158
|
+
const data = JSON.parse((0, node_fs_1.readFileSync)(credFile, "utf8"));
|
|
159
|
+
const key = typeof data["api_key"] === "string" ? data["api_key"].trim() : "";
|
|
160
|
+
if (key)
|
|
161
|
+
return key;
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
// Ignore parse errors
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
function getCredentialSource(cliArg, keychain = exports.defaultKeychainAdapter, homeOverride) {
|
|
170
|
+
if (cliArg && cliArg.trim())
|
|
171
|
+
return "command-line argument";
|
|
172
|
+
if ((process.env["TRIMLYNK_API_KEY"] ?? "").trim()) {
|
|
173
|
+
return "environment variable (TRIMLYNK_API_KEY)";
|
|
174
|
+
}
|
|
175
|
+
if (!homeOverride) {
|
|
176
|
+
try {
|
|
177
|
+
const krKey = keychain.getPassword(exports.KEYRING_SERVICE_NAME, exports.KEYRING_USERNAME);
|
|
178
|
+
if (krKey && krKey.trim())
|
|
179
|
+
return "system keyring";
|
|
180
|
+
}
|
|
181
|
+
catch {
|
|
182
|
+
// Ignore
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
if ((0, node_fs_1.existsSync)(getCredentialsFile(homeOverride))) {
|
|
186
|
+
return "config file (~/.trimlynk/credentials.json)";
|
|
187
|
+
}
|
|
188
|
+
return "none";
|
|
189
|
+
}
|
|
190
|
+
function saveApiKey(apiKey, keychain = exports.defaultKeychainAdapter, homeOverride) {
|
|
191
|
+
const clean = apiKey.trim();
|
|
192
|
+
if (!clean) {
|
|
193
|
+
throw new Error("Cannot save an empty API key");
|
|
194
|
+
}
|
|
195
|
+
if (!homeOverride) {
|
|
196
|
+
try {
|
|
197
|
+
keychain.setPassword(exports.KEYRING_SERVICE_NAME, exports.KEYRING_USERNAME, clean);
|
|
198
|
+
}
|
|
199
|
+
catch {
|
|
200
|
+
// Fallback to file
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
const credFile = getCredentialsFile(homeOverride);
|
|
204
|
+
(0, node_fs_1.writeFileSync)(credFile, JSON.stringify({ api_key: clean }, null, 2), "utf8");
|
|
205
|
+
try {
|
|
206
|
+
(0, node_fs_1.chmodSync)(credFile, 0o600);
|
|
207
|
+
}
|
|
208
|
+
catch {
|
|
209
|
+
// Ignore on Windows
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
function deleteApiKey(keychain = exports.defaultKeychainAdapter, homeOverride) {
|
|
213
|
+
let removed = false;
|
|
214
|
+
if (!homeOverride) {
|
|
215
|
+
try {
|
|
216
|
+
if (keychain.deletePassword(exports.KEYRING_SERVICE_NAME, exports.KEYRING_USERNAME)) {
|
|
217
|
+
removed = true;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
catch {
|
|
221
|
+
// Ignore
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
const credFile = getCredentialsFile(homeOverride);
|
|
225
|
+
if ((0, node_fs_1.existsSync)(credFile)) {
|
|
226
|
+
try {
|
|
227
|
+
(0, node_fs_1.unlinkSync)(credFile);
|
|
228
|
+
removed = true;
|
|
229
|
+
}
|
|
230
|
+
catch {
|
|
231
|
+
// Ignore
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return removed;
|
|
235
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const EXIT_SUCCESS = 0;
|
|
2
|
+
export declare const EXIT_GENERAL_ERROR = 1;
|
|
3
|
+
export declare const EXIT_INVALID_ARGS = 2;
|
|
4
|
+
export declare const EXIT_AUTHENTICATION_ERROR = 3;
|
|
5
|
+
export declare const EXIT_PERMISSION_ERROR = 4;
|
|
6
|
+
export declare const EXIT_NOT_FOUND = 5;
|
|
7
|
+
export declare const EXIT_RATE_LIMITED = 6;
|
|
8
|
+
export declare const EXIT_API_ERROR = 7;
|
|
9
|
+
export declare const EXIT_NETWORK_ERROR = 8;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EXIT_NETWORK_ERROR = exports.EXIT_API_ERROR = exports.EXIT_RATE_LIMITED = exports.EXIT_NOT_FOUND = exports.EXIT_PERMISSION_ERROR = exports.EXIT_AUTHENTICATION_ERROR = exports.EXIT_INVALID_ARGS = exports.EXIT_GENERAL_ERROR = exports.EXIT_SUCCESS = void 0;
|
|
4
|
+
exports.EXIT_SUCCESS = 0;
|
|
5
|
+
exports.EXIT_GENERAL_ERROR = 1;
|
|
6
|
+
exports.EXIT_INVALID_ARGS = 2;
|
|
7
|
+
exports.EXIT_AUTHENTICATION_ERROR = 3;
|
|
8
|
+
exports.EXIT_PERMISSION_ERROR = 4;
|
|
9
|
+
exports.EXIT_NOT_FOUND = 5;
|
|
10
|
+
exports.EXIT_RATE_LIMITED = 6;
|
|
11
|
+
exports.EXIT_API_ERROR = 7;
|
|
12
|
+
exports.EXIT_NETWORK_ERROR = 8;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare function isColorEnabled(): boolean;
|
|
2
|
+
export declare function colorize(text: string, code: string): string;
|
|
3
|
+
export declare const green: (text: string) => string;
|
|
4
|
+
export declare const red: (text: string) => string;
|
|
5
|
+
export declare const yellow: (text: string) => string;
|
|
6
|
+
export declare const blue: (text: string) => string;
|
|
7
|
+
export declare const bold: (text: string) => string;
|
|
8
|
+
export declare const dim: (text: string) => string;
|
|
9
|
+
export declare function outputJson(data: unknown): void;
|
|
10
|
+
export declare function printTable(headers: string[], rows: unknown[][]): void;
|
|
11
|
+
export declare function printDetails(pairs: Array<[string, unknown]>): void;
|
|
12
|
+
export interface PrintErrorOptions {
|
|
13
|
+
code?: string | undefined;
|
|
14
|
+
requestId?: string | undefined;
|
|
15
|
+
retryAfter?: number | undefined;
|
|
16
|
+
details?: Record<string, unknown> | undefined;
|
|
17
|
+
}
|
|
18
|
+
export declare function printError(message: string, opts?: PrintErrorOptions): void;
|
|
19
|
+
export declare function confirmAction(prompt: string, defaultYes?: boolean, forceYes?: boolean): Promise<boolean>;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dim = exports.bold = exports.blue = exports.yellow = exports.red = exports.green = void 0;
|
|
4
|
+
exports.isColorEnabled = isColorEnabled;
|
|
5
|
+
exports.colorize = colorize;
|
|
6
|
+
exports.outputJson = outputJson;
|
|
7
|
+
exports.printTable = printTable;
|
|
8
|
+
exports.printDetails = printDetails;
|
|
9
|
+
exports.printError = printError;
|
|
10
|
+
exports.confirmAction = confirmAction;
|
|
11
|
+
const promises_1 = require("node:readline/promises");
|
|
12
|
+
function isColorEnabled() {
|
|
13
|
+
if (process.env["NO_COLOR"])
|
|
14
|
+
return false;
|
|
15
|
+
const ci = (process.env["CI"] ?? "").toLowerCase();
|
|
16
|
+
if (ci === "true" || ci === "1")
|
|
17
|
+
return false;
|
|
18
|
+
return Boolean(process.stdout.isTTY);
|
|
19
|
+
}
|
|
20
|
+
function colorize(text, code) {
|
|
21
|
+
if (!isColorEnabled())
|
|
22
|
+
return text;
|
|
23
|
+
return `\x1b[${code}m${text}\x1b[0m`;
|
|
24
|
+
}
|
|
25
|
+
const green = (text) => colorize(text, "32");
|
|
26
|
+
exports.green = green;
|
|
27
|
+
const red = (text) => colorize(text, "31");
|
|
28
|
+
exports.red = red;
|
|
29
|
+
const yellow = (text) => colorize(text, "33");
|
|
30
|
+
exports.yellow = yellow;
|
|
31
|
+
const blue = (text) => colorize(text, "34");
|
|
32
|
+
exports.blue = blue;
|
|
33
|
+
const bold = (text) => colorize(text, "1");
|
|
34
|
+
exports.bold = bold;
|
|
35
|
+
const dim = (text) => colorize(text, "2");
|
|
36
|
+
exports.dim = dim;
|
|
37
|
+
function outputJson(data) {
|
|
38
|
+
const normalized = data && typeof data === "object" && "toJSON" in data && typeof data.toJSON === "function"
|
|
39
|
+
? data.toJSON()
|
|
40
|
+
: data;
|
|
41
|
+
process.stdout.write(`${JSON.stringify(normalized, null, 2)}\n`);
|
|
42
|
+
}
|
|
43
|
+
function printTable(headers, rows) {
|
|
44
|
+
if (rows.length === 0) {
|
|
45
|
+
process.stdout.write("No items to display.\n");
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const cols = headers.length;
|
|
49
|
+
const widths = headers.map((h) => h.length);
|
|
50
|
+
for (const row of rows) {
|
|
51
|
+
for (let i = 0; i < Math.min(cols, row.length); i++) {
|
|
52
|
+
const cell = row[i] !== undefined && row[i] !== null ? String(row[i]) : "";
|
|
53
|
+
if (cell.length > widths[i]) {
|
|
54
|
+
widths[i] = cell.length;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const headerLine = headers.map((h, i) => h.padEnd(widths[i])).join(" ");
|
|
59
|
+
process.stdout.write(`${(0, exports.bold)(headerLine)}\n`);
|
|
60
|
+
process.stdout.write(`${widths.map((w) => "-".repeat(w)).join(" ")}\n`);
|
|
61
|
+
for (const row of rows) {
|
|
62
|
+
const line = Array.from({ length: cols }, (_, i) => {
|
|
63
|
+
const cell = row[i] !== undefined && row[i] !== null ? String(row[i]) : "";
|
|
64
|
+
return cell.padEnd(widths[i]);
|
|
65
|
+
}).join(" ");
|
|
66
|
+
process.stdout.write(`${line}\n`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function printDetails(pairs) {
|
|
70
|
+
const maxLabel = pairs.length > 0 ? Math.max(...pairs.map(([label]) => label.length)) : 10;
|
|
71
|
+
for (const [label, val] of pairs) {
|
|
72
|
+
const valStr = val !== undefined && val !== null ? String(val) : "";
|
|
73
|
+
process.stdout.write(`${(0, exports.bold)(label.padEnd(maxLabel + 2))} ${valStr}\n`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function printError(message, opts = {}) {
|
|
77
|
+
process.stderr.write(`${(0, exports.red)("Error:")} ${message}\n`);
|
|
78
|
+
if (opts.code) {
|
|
79
|
+
process.stderr.write(`${(0, exports.bold)("Code:")} ${opts.code}\n`);
|
|
80
|
+
}
|
|
81
|
+
if (opts.retryAfter !== undefined) {
|
|
82
|
+
process.stderr.write(`${(0, exports.yellow)("Retry after:")} ${opts.retryAfter} seconds\n`);
|
|
83
|
+
}
|
|
84
|
+
if (opts.details && Object.keys(opts.details).length > 0) {
|
|
85
|
+
process.stderr.write(`${(0, exports.bold)("Details:")} ${JSON.stringify(opts.details)}\n`);
|
|
86
|
+
}
|
|
87
|
+
if (opts.requestId) {
|
|
88
|
+
process.stderr.write(`${(0, exports.dim)("Request ID:")} ${opts.requestId}\n`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
async function confirmAction(prompt, defaultYes = false, forceYes = false) {
|
|
92
|
+
if (forceYes)
|
|
93
|
+
return true;
|
|
94
|
+
if (!process.stdin.isTTY)
|
|
95
|
+
return false;
|
|
96
|
+
const suffix = defaultYes ? " [Y/n]: " : " [y/N]: ";
|
|
97
|
+
const rl = (0, promises_1.createInterface)({ input: process.stdin, output: process.stdout });
|
|
98
|
+
try {
|
|
99
|
+
const reply = (await rl.question(`${prompt}${suffix}`)).trim().toLowerCase();
|
|
100
|
+
if (!reply)
|
|
101
|
+
return defaultYes;
|
|
102
|
+
return reply === "y" || reply === "yes";
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
finally {
|
|
108
|
+
rl.close();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.runCli = runCli;
|
|
5
|
+
const node_util_1 = require("node:util");
|
|
6
|
+
const client_js_1 = require("../client.js");
|
|
7
|
+
const config_js_1 = require("../config.js");
|
|
8
|
+
const errors_js_1 = require("../errors.js");
|
|
9
|
+
const analytics_js_1 = require("./commands/analytics.js");
|
|
10
|
+
const auth_js_1 = require("./commands/auth.js");
|
|
11
|
+
const campaigns_js_1 = require("./commands/campaigns.js");
|
|
12
|
+
const config_js_2 = require("./commands/config.js");
|
|
13
|
+
const conversions_js_1 = require("./commands/conversions.js");
|
|
14
|
+
const links_js_1 = require("./commands/links.js");
|
|
15
|
+
const webhooks_js_1 = require("./commands/webhooks.js");
|
|
16
|
+
const configStore_js_1 = require("./configStore.js");
|
|
17
|
+
const credentials_js_1 = require("./credentials.js");
|
|
18
|
+
const exitCodes_js_1 = require("./exitCodes.js");
|
|
19
|
+
const formatting_js_1 = require("./formatting.js");
|
|
20
|
+
const HELP_TEXT = `Official CLI for TrimLynk URL intelligence, short links, analytics, and webhooks.
|
|
21
|
+
|
|
22
|
+
Usage:
|
|
23
|
+
trimlynk [global options] <command> <subcommand> [options]
|
|
24
|
+
|
|
25
|
+
Global Options:
|
|
26
|
+
--json Output raw, machine-readable JSON
|
|
27
|
+
-q, --quiet Suppress formatting and output primary IDs/URLs only
|
|
28
|
+
--api-key <KEY> Override TrimLynk API key for this command
|
|
29
|
+
--environment <ENV> Specify API environment ('live' or 'test')
|
|
30
|
+
--base-url <URL> Override TrimLynk API base URL
|
|
31
|
+
--version Show CLI version
|
|
32
|
+
-h, --help Show this help message
|
|
33
|
+
|
|
34
|
+
Commands:
|
|
35
|
+
auth login | logout | status [--check]
|
|
36
|
+
links create | list | get | update | delete
|
|
37
|
+
analytics summary | link
|
|
38
|
+
conversions create | list | get
|
|
39
|
+
campaigns create | list | get | update | delete
|
|
40
|
+
webhooks create | list | get | update | delete | test | deliveries | retry | listen
|
|
41
|
+
config get | set
|
|
42
|
+
`;
|
|
43
|
+
function extractGlobalFlags(rawArgv) {
|
|
44
|
+
const opts = {
|
|
45
|
+
json: false,
|
|
46
|
+
quiet: false,
|
|
47
|
+
};
|
|
48
|
+
let showVersion = false;
|
|
49
|
+
let showHelp = false;
|
|
50
|
+
const rest = [];
|
|
51
|
+
for (let i = 0; i < rawArgv.length; i++) {
|
|
52
|
+
const arg = rawArgv[i];
|
|
53
|
+
if (arg === "--json") {
|
|
54
|
+
opts.json = true;
|
|
55
|
+
}
|
|
56
|
+
else if (arg === "-q" || arg === "--quiet") {
|
|
57
|
+
opts.quiet = true;
|
|
58
|
+
}
|
|
59
|
+
else if (arg === "--version") {
|
|
60
|
+
showVersion = true;
|
|
61
|
+
}
|
|
62
|
+
else if (arg === "-h" || arg === "--help") {
|
|
63
|
+
showHelp = true;
|
|
64
|
+
}
|
|
65
|
+
else if (arg === "--api-key" && i + 1 < rawArgv.length) {
|
|
66
|
+
opts.apiKey = rawArgv[++i];
|
|
67
|
+
}
|
|
68
|
+
else if (arg.startsWith("--api-key=")) {
|
|
69
|
+
opts.apiKey = arg.slice("--api-key=".length);
|
|
70
|
+
}
|
|
71
|
+
else if (arg === "--environment" && i + 1 < rawArgv.length) {
|
|
72
|
+
opts.environment = rawArgv[++i];
|
|
73
|
+
}
|
|
74
|
+
else if (arg.startsWith("--environment=")) {
|
|
75
|
+
opts.environment = arg.slice("--environment=".length);
|
|
76
|
+
}
|
|
77
|
+
else if (arg === "--base-url" && i + 1 < rawArgv.length) {
|
|
78
|
+
opts.baseUrl = rawArgv[++i];
|
|
79
|
+
}
|
|
80
|
+
else if (arg.startsWith("--base-url=")) {
|
|
81
|
+
opts.baseUrl = arg.slice("--base-url=".length);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
rest.push(arg);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return { opts, showVersion, showHelp, rest };
|
|
88
|
+
}
|
|
89
|
+
async function runCli(rawArgv = process.argv.slice(2), customGetClient) {
|
|
90
|
+
const { opts, showVersion, showHelp, rest } = extractGlobalFlags(rawArgv);
|
|
91
|
+
if (showVersion) {
|
|
92
|
+
process.stdout.write(`trimlynk ${config_js_1.SDK_VERSION}\n`);
|
|
93
|
+
return exitCodes_js_1.EXIT_SUCCESS;
|
|
94
|
+
}
|
|
95
|
+
if (showHelp) {
|
|
96
|
+
process.stdout.write(HELP_TEXT);
|
|
97
|
+
return exitCodes_js_1.EXIT_SUCCESS;
|
|
98
|
+
}
|
|
99
|
+
const group = rest[0];
|
|
100
|
+
const action = rest[1];
|
|
101
|
+
const actionArgv = rest.slice(2);
|
|
102
|
+
if (!group) {
|
|
103
|
+
process.stdout.write(HELP_TEXT);
|
|
104
|
+
return exitCodes_js_1.EXIT_INVALID_ARGS;
|
|
105
|
+
}
|
|
106
|
+
const getClient = customGetClient ??
|
|
107
|
+
((overrides = {}) => {
|
|
108
|
+
const apiKey = overrides.apiKey ?? (0, credentials_js_1.resolveApiKey)(opts.apiKey);
|
|
109
|
+
if (!apiKey) {
|
|
110
|
+
throw new errors_js_1.AuthenticationError("TrimLynk API key is required. Authenticate using 'trimlynk auth login' or pass --api-key / TRIMLYNK_API_KEY.");
|
|
111
|
+
}
|
|
112
|
+
const env = overrides.environment ?? (0, configStore_js_1.resolveEnvironment)(opts.environment);
|
|
113
|
+
const baseUrl = overrides.baseUrl ?? (0, configStore_js_1.resolveBaseUrl)(opts.baseUrl);
|
|
114
|
+
return new client_js_1.TrimLynk({ apiKey, baseUrl, environment: env });
|
|
115
|
+
});
|
|
116
|
+
try {
|
|
117
|
+
switch (group) {
|
|
118
|
+
case "auth": {
|
|
119
|
+
if (action === "login")
|
|
120
|
+
return await (0, auth_js_1.cmdLogin)(opts, getClient);
|
|
121
|
+
if (action === "logout")
|
|
122
|
+
return await (0, auth_js_1.cmdLogout)(opts);
|
|
123
|
+
if (action === "status") {
|
|
124
|
+
const { values } = (0, node_util_1.parseArgs)({
|
|
125
|
+
args: actionArgv,
|
|
126
|
+
allowPositionals: false,
|
|
127
|
+
options: { check: { type: "boolean", default: false } },
|
|
128
|
+
});
|
|
129
|
+
return await (0, auth_js_1.cmdStatus)(opts, getClient, values.check);
|
|
130
|
+
}
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
case "links": {
|
|
134
|
+
if (action === "create")
|
|
135
|
+
return await (0, links_js_1.cmdLinksCreate)(actionArgv, opts, getClient);
|
|
136
|
+
if (action === "list")
|
|
137
|
+
return await (0, links_js_1.cmdLinksList)(actionArgv, opts, getClient);
|
|
138
|
+
if (action === "get")
|
|
139
|
+
return await (0, links_js_1.cmdLinksGet)(actionArgv, opts, getClient);
|
|
140
|
+
if (action === "update")
|
|
141
|
+
return await (0, links_js_1.cmdLinksUpdate)(actionArgv, opts, getClient);
|
|
142
|
+
if (action === "delete")
|
|
143
|
+
return await (0, links_js_1.cmdLinksDelete)(actionArgv, opts, getClient);
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
case "analytics": {
|
|
147
|
+
if (action === "summary")
|
|
148
|
+
return await (0, analytics_js_1.cmdAnalyticsSummary)(actionArgv, opts, getClient);
|
|
149
|
+
if (action === "link")
|
|
150
|
+
return await (0, analytics_js_1.cmdAnalyticsLink)(actionArgv, opts, getClient);
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
case "conversions": {
|
|
154
|
+
if (action === "create")
|
|
155
|
+
return await (0, conversions_js_1.cmdConversionsCreate)(actionArgv, opts, getClient);
|
|
156
|
+
if (action === "list")
|
|
157
|
+
return await (0, conversions_js_1.cmdConversionsList)(actionArgv, opts, getClient);
|
|
158
|
+
if (action === "get")
|
|
159
|
+
return await (0, conversions_js_1.cmdConversionsGet)(actionArgv, opts, getClient);
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
case "campaigns": {
|
|
163
|
+
if (action === "create")
|
|
164
|
+
return await (0, campaigns_js_1.cmdCampaignsCreate)(actionArgv, opts, getClient);
|
|
165
|
+
if (action === "list")
|
|
166
|
+
return await (0, campaigns_js_1.cmdCampaignsList)(actionArgv, opts, getClient);
|
|
167
|
+
if (action === "get")
|
|
168
|
+
return await (0, campaigns_js_1.cmdCampaignsGet)(actionArgv, opts, getClient);
|
|
169
|
+
if (action === "update")
|
|
170
|
+
return await (0, campaigns_js_1.cmdCampaignsUpdate)(actionArgv, opts, getClient);
|
|
171
|
+
if (action === "delete")
|
|
172
|
+
return await (0, campaigns_js_1.cmdCampaignsDelete)(actionArgv, opts, getClient);
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
case "webhooks": {
|
|
176
|
+
if (action === "create")
|
|
177
|
+
return await (0, webhooks_js_1.cmdWebhooksCreate)(actionArgv, opts, getClient);
|
|
178
|
+
if (action === "list")
|
|
179
|
+
return await (0, webhooks_js_1.cmdWebhooksList)(actionArgv, opts, getClient);
|
|
180
|
+
if (action === "get")
|
|
181
|
+
return await (0, webhooks_js_1.cmdWebhooksGet)(actionArgv, opts, getClient);
|
|
182
|
+
if (action === "update")
|
|
183
|
+
return await (0, webhooks_js_1.cmdWebhooksUpdate)(actionArgv, opts, getClient);
|
|
184
|
+
if (action === "delete")
|
|
185
|
+
return await (0, webhooks_js_1.cmdWebhooksDelete)(actionArgv, opts, getClient);
|
|
186
|
+
if (action === "test")
|
|
187
|
+
return await (0, webhooks_js_1.cmdWebhooksTest)(actionArgv, opts, getClient);
|
|
188
|
+
if (action === "deliveries")
|
|
189
|
+
return await (0, webhooks_js_1.cmdWebhooksDeliveries)(actionArgv, opts, getClient);
|
|
190
|
+
if (action === "retry")
|
|
191
|
+
return await (0, webhooks_js_1.cmdWebhooksRetry)(actionArgv, opts, getClient);
|
|
192
|
+
if (action === "listen")
|
|
193
|
+
return await (0, webhooks_js_1.cmdWebhooksListen)(actionArgv, opts, getClient);
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
case "config": {
|
|
197
|
+
if (action === "get")
|
|
198
|
+
return await (0, config_js_2.cmdConfigGet)(opts, actionArgv[0]);
|
|
199
|
+
if (action === "set")
|
|
200
|
+
return await (0, config_js_2.cmdConfigSet)(opts, actionArgv[0], actionArgv[1]);
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
default:
|
|
204
|
+
break;
|
|
205
|
+
}
|
|
206
|
+
process.stdout.write(HELP_TEXT);
|
|
207
|
+
return exitCodes_js_1.EXIT_INVALID_ARGS;
|
|
208
|
+
}
|
|
209
|
+
catch (err) {
|
|
210
|
+
if (err instanceof errors_js_1.AuthenticationError) {
|
|
211
|
+
(0, formatting_js_1.printError)(err.message, { code: err.code, requestId: err.requestId });
|
|
212
|
+
return exitCodes_js_1.EXIT_AUTHENTICATION_ERROR;
|
|
213
|
+
}
|
|
214
|
+
if (err instanceof errors_js_1.PermissionError) {
|
|
215
|
+
(0, formatting_js_1.printError)(err.message, { code: err.code, requestId: err.requestId });
|
|
216
|
+
return exitCodes_js_1.EXIT_PERMISSION_ERROR;
|
|
217
|
+
}
|
|
218
|
+
if (err instanceof errors_js_1.NotFoundError) {
|
|
219
|
+
(0, formatting_js_1.printError)(err.message, { code: err.code, requestId: err.requestId });
|
|
220
|
+
return exitCodes_js_1.EXIT_NOT_FOUND;
|
|
221
|
+
}
|
|
222
|
+
if (err instanceof errors_js_1.RateLimitError) {
|
|
223
|
+
(0, formatting_js_1.printError)(err.message, {
|
|
224
|
+
code: err.code,
|
|
225
|
+
requestId: err.requestId,
|
|
226
|
+
retryAfter: err.retryAfter,
|
|
227
|
+
});
|
|
228
|
+
return exitCodes_js_1.EXIT_RATE_LIMITED;
|
|
229
|
+
}
|
|
230
|
+
if (err instanceof errors_js_1.IdempotencyConflictError || err instanceof errors_js_1.ConflictError) {
|
|
231
|
+
(0, formatting_js_1.printError)(err.message, { code: err.code, requestId: err.requestId });
|
|
232
|
+
return exitCodes_js_1.EXIT_API_ERROR;
|
|
233
|
+
}
|
|
234
|
+
if (err instanceof errors_js_1.InvalidRequestError) {
|
|
235
|
+
(0, formatting_js_1.printError)(err.message, {
|
|
236
|
+
code: err.code,
|
|
237
|
+
requestId: err.requestId,
|
|
238
|
+
details: err.details,
|
|
239
|
+
});
|
|
240
|
+
return exitCodes_js_1.EXIT_INVALID_ARGS;
|
|
241
|
+
}
|
|
242
|
+
if (err instanceof errors_js_1.InternalServerError) {
|
|
243
|
+
(0, formatting_js_1.printError)(err.message, { code: err.code, requestId: err.requestId });
|
|
244
|
+
return exitCodes_js_1.EXIT_API_ERROR;
|
|
245
|
+
}
|
|
246
|
+
if (err instanceof errors_js_1.TimeoutError || err instanceof errors_js_1.NetworkError) {
|
|
247
|
+
(0, formatting_js_1.printError)(err.message);
|
|
248
|
+
return exitCodes_js_1.EXIT_NETWORK_ERROR;
|
|
249
|
+
}
|
|
250
|
+
if (err instanceof errors_js_1.APIError) {
|
|
251
|
+
(0, formatting_js_1.printError)(err.message, {
|
|
252
|
+
code: err.code,
|
|
253
|
+
requestId: err.requestId,
|
|
254
|
+
details: err.details,
|
|
255
|
+
});
|
|
256
|
+
return exitCodes_js_1.EXIT_API_ERROR;
|
|
257
|
+
}
|
|
258
|
+
if (err instanceof errors_js_1.TrimLynkError) {
|
|
259
|
+
(0, formatting_js_1.printError)(err.message);
|
|
260
|
+
return exitCodes_js_1.EXIT_GENERAL_ERROR;
|
|
261
|
+
}
|
|
262
|
+
if (err instanceof Error && err.code === "ERR_PARSE_ARGS_UNKNOWN_OPTION") {
|
|
263
|
+
(0, formatting_js_1.printError)(err.message);
|
|
264
|
+
return exitCodes_js_1.EXIT_INVALID_ARGS;
|
|
265
|
+
}
|
|
266
|
+
(0, formatting_js_1.printError)(`Unexpected error: ${err instanceof Error ? err.message : String(err)}`);
|
|
267
|
+
return exitCodes_js_1.EXIT_GENERAL_ERROR;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
const isDirectExecution = typeof process !== "undefined" &&
|
|
271
|
+
Array.isArray(process.argv) &&
|
|
272
|
+
process.argv[1] !== undefined &&
|
|
273
|
+
(process.argv[1].endsWith("cli/index.js") || process.argv[1].endsWith("cli\\index.js"));
|
|
274
|
+
if (isDirectExecution) {
|
|
275
|
+
runCli().then((code) => {
|
|
276
|
+
process.exitCode = code;
|
|
277
|
+
});
|
|
278
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { TrimLynk } from "../client.js";
|
|
2
|
+
export interface GlobalCliOptions {
|
|
3
|
+
json: boolean;
|
|
4
|
+
quiet: boolean;
|
|
5
|
+
apiKey?: string | undefined;
|
|
6
|
+
environment?: string | undefined;
|
|
7
|
+
baseUrl?: string | undefined;
|
|
8
|
+
}
|
|
9
|
+
export type ClientFactory = (overrides?: {
|
|
10
|
+
apiKey?: string | undefined;
|
|
11
|
+
environment?: string | undefined;
|
|
12
|
+
baseUrl?: string | undefined;
|
|
13
|
+
}) => TrimLynk;
|