@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.
Files changed (172) hide show
  1. package/LICENSE +19 -0
  2. package/README.md +387 -2
  3. package/dist/cjs/cli/commands/analytics.d.ts +3 -0
  4. package/dist/cjs/cli/commands/analytics.js +80 -0
  5. package/dist/cjs/cli/commands/auth.d.ts +4 -0
  6. package/dist/cjs/cli/commands/auth.js +122 -0
  7. package/dist/cjs/cli/commands/campaigns.d.ts +6 -0
  8. package/dist/cjs/cli/commands/campaigns.js +229 -0
  9. package/dist/cjs/cli/commands/config.d.ts +3 -0
  10. package/dist/cjs/cli/commands/config.js +51 -0
  11. package/dist/cjs/cli/commands/conversions.d.ts +4 -0
  12. package/dist/cjs/cli/commands/conversions.js +160 -0
  13. package/dist/cjs/cli/commands/links.d.ts +6 -0
  14. package/dist/cjs/cli/commands/links.js +270 -0
  15. package/dist/cjs/cli/commands/webhooks.d.ts +10 -0
  16. package/dist/cjs/cli/commands/webhooks.js +510 -0
  17. package/dist/cjs/cli/configStore.d.ts +10 -0
  18. package/dist/cjs/cli/configStore.js +63 -0
  19. package/dist/cjs/cli/credentials.d.ts +23 -0
  20. package/dist/cjs/cli/credentials.js +235 -0
  21. package/dist/cjs/cli/exitCodes.d.ts +9 -0
  22. package/dist/cjs/cli/exitCodes.js +12 -0
  23. package/dist/cjs/cli/formatting.d.ts +19 -0
  24. package/dist/cjs/cli/formatting.js +110 -0
  25. package/dist/cjs/cli/index.d.ts +3 -0
  26. package/dist/cjs/cli/index.js +278 -0
  27. package/dist/cjs/cli/types.d.ts +13 -0
  28. package/dist/cjs/cli/types.js +2 -0
  29. package/dist/cjs/client.d.ts +89 -0
  30. package/dist/cjs/client.js +126 -0
  31. package/dist/cjs/config.d.ts +49 -0
  32. package/dist/cjs/config.js +67 -0
  33. package/dist/cjs/errors.d.ts +60 -0
  34. package/dist/cjs/errors.js +149 -0
  35. package/dist/cjs/events.d.ts +50 -0
  36. package/dist/cjs/events.js +153 -0
  37. package/dist/cjs/http.d.ts +30 -0
  38. package/dist/cjs/http.js +148 -0
  39. package/dist/cjs/index.d.ts +28 -0
  40. package/dist/cjs/index.js +58 -0
  41. package/dist/cjs/package.json +3 -0
  42. package/dist/cjs/pagination.d.ts +54 -0
  43. package/dist/cjs/pagination.js +111 -0
  44. package/dist/cjs/resources/analytics.d.ts +35 -0
  45. package/dist/cjs/resources/analytics.js +74 -0
  46. package/dist/cjs/resources/campaigns.d.ts +65 -0
  47. package/dist/cjs/resources/campaigns.js +139 -0
  48. package/dist/cjs/resources/conversions.d.ts +37 -0
  49. package/dist/cjs/resources/conversions.js +82 -0
  50. package/dist/cjs/resources/links.d.ts +95 -0
  51. package/dist/cjs/resources/links.js +199 -0
  52. package/dist/cjs/resources/webhooks.d.ts +66 -0
  53. package/dist/cjs/resources/webhooks.js +178 -0
  54. package/dist/cjs/security.d.ts +53 -0
  55. package/dist/cjs/security.js +156 -0
  56. package/dist/cjs/types.d.ts +149 -0
  57. package/dist/cjs/types.js +347 -0
  58. package/dist/cjs/utm.d.ts +36 -0
  59. package/dist/cjs/utm.js +44 -0
  60. package/dist/esm/cli/commands/analytics.d.ts +4 -0
  61. package/dist/esm/cli/commands/analytics.d.ts.map +1 -0
  62. package/dist/esm/cli/commands/analytics.js +77 -0
  63. package/dist/esm/cli/commands/analytics.js.map +1 -0
  64. package/dist/esm/cli/commands/auth.d.ts +5 -0
  65. package/dist/esm/cli/commands/auth.d.ts.map +1 -0
  66. package/dist/esm/cli/commands/auth.js +118 -0
  67. package/dist/esm/cli/commands/auth.js.map +1 -0
  68. package/dist/esm/cli/commands/campaigns.d.ts +7 -0
  69. package/dist/esm/cli/commands/campaigns.d.ts.map +1 -0
  70. package/dist/esm/cli/commands/campaigns.js +223 -0
  71. package/dist/esm/cli/commands/campaigns.js.map +1 -0
  72. package/dist/esm/cli/commands/config.d.ts +4 -0
  73. package/dist/esm/cli/commands/config.d.ts.map +1 -0
  74. package/dist/esm/cli/commands/config.js +48 -0
  75. package/dist/esm/cli/commands/config.js.map +1 -0
  76. package/dist/esm/cli/commands/conversions.d.ts +5 -0
  77. package/dist/esm/cli/commands/conversions.d.ts.map +1 -0
  78. package/dist/esm/cli/commands/conversions.js +156 -0
  79. package/dist/esm/cli/commands/conversions.js.map +1 -0
  80. package/dist/esm/cli/commands/links.d.ts +7 -0
  81. package/dist/esm/cli/commands/links.d.ts.map +1 -0
  82. package/dist/esm/cli/commands/links.js +264 -0
  83. package/dist/esm/cli/commands/links.js.map +1 -0
  84. package/dist/esm/cli/commands/webhooks.d.ts +11 -0
  85. package/dist/esm/cli/commands/webhooks.d.ts.map +1 -0
  86. package/dist/esm/cli/commands/webhooks.js +500 -0
  87. package/dist/esm/cli/commands/webhooks.js.map +1 -0
  88. package/dist/esm/cli/configStore.d.ts +11 -0
  89. package/dist/esm/cli/configStore.d.ts.map +1 -0
  90. package/dist/esm/cli/configStore.js +54 -0
  91. package/dist/esm/cli/configStore.js.map +1 -0
  92. package/dist/esm/cli/credentials.d.ts +24 -0
  93. package/dist/esm/cli/credentials.d.ts.map +1 -0
  94. package/dist/esm/cli/credentials.js +226 -0
  95. package/dist/esm/cli/credentials.js.map +1 -0
  96. package/dist/esm/cli/exitCodes.d.ts +10 -0
  97. package/dist/esm/cli/exitCodes.d.ts.map +1 -0
  98. package/dist/esm/cli/exitCodes.js +10 -0
  99. package/dist/esm/cli/exitCodes.js.map +1 -0
  100. package/dist/esm/cli/formatting.d.ts +20 -0
  101. package/dist/esm/cli/formatting.d.ts.map +1 -0
  102. package/dist/esm/cli/formatting.js +95 -0
  103. package/dist/esm/cli/formatting.js.map +1 -0
  104. package/dist/esm/cli/index.d.ts +4 -0
  105. package/dist/esm/cli/index.d.ts.map +1 -0
  106. package/dist/esm/cli/index.js +276 -0
  107. package/dist/esm/cli/index.js.map +1 -0
  108. package/dist/esm/cli/types.d.ts +14 -0
  109. package/dist/esm/cli/types.d.ts.map +1 -0
  110. package/dist/esm/cli/types.js +2 -0
  111. package/dist/esm/cli/types.js.map +1 -0
  112. package/dist/esm/client.d.ts +90 -0
  113. package/dist/esm/client.d.ts.map +1 -0
  114. package/dist/esm/client.js +123 -0
  115. package/dist/esm/client.js.map +1 -0
  116. package/dist/esm/config.d.ts +50 -0
  117. package/dist/esm/config.d.ts.map +1 -0
  118. package/dist/esm/config.js +64 -0
  119. package/dist/esm/config.js.map +1 -0
  120. package/dist/esm/errors.d.ts +61 -0
  121. package/dist/esm/errors.d.ts.map +1 -0
  122. package/dist/esm/errors.js +130 -0
  123. package/dist/esm/errors.js.map +1 -0
  124. package/dist/esm/events.d.ts +51 -0
  125. package/dist/esm/events.d.ts.map +1 -0
  126. package/dist/esm/events.js +149 -0
  127. package/dist/esm/events.js.map +1 -0
  128. package/dist/esm/http.d.ts +31 -0
  129. package/dist/esm/http.d.ts.map +1 -0
  130. package/dist/esm/http.js +145 -0
  131. package/dist/esm/http.js.map +1 -0
  132. package/dist/esm/index.d.ts +29 -0
  133. package/dist/esm/index.d.ts.map +1 -0
  134. package/dist/esm/index.js +16 -0
  135. package/dist/esm/index.js.map +1 -0
  136. package/dist/esm/pagination.d.ts +55 -0
  137. package/dist/esm/pagination.d.ts.map +1 -0
  138. package/dist/esm/pagination.js +106 -0
  139. package/dist/esm/pagination.js.map +1 -0
  140. package/dist/esm/resources/analytics.d.ts +36 -0
  141. package/dist/esm/resources/analytics.d.ts.map +1 -0
  142. package/dist/esm/resources/analytics.js +71 -0
  143. package/dist/esm/resources/analytics.js.map +1 -0
  144. package/dist/esm/resources/campaigns.d.ts +66 -0
  145. package/dist/esm/resources/campaigns.d.ts.map +1 -0
  146. package/dist/esm/resources/campaigns.js +136 -0
  147. package/dist/esm/resources/campaigns.js.map +1 -0
  148. package/dist/esm/resources/conversions.d.ts +38 -0
  149. package/dist/esm/resources/conversions.d.ts.map +1 -0
  150. package/dist/esm/resources/conversions.js +79 -0
  151. package/dist/esm/resources/conversions.js.map +1 -0
  152. package/dist/esm/resources/links.d.ts +96 -0
  153. package/dist/esm/resources/links.d.ts.map +1 -0
  154. package/dist/esm/resources/links.js +196 -0
  155. package/dist/esm/resources/links.js.map +1 -0
  156. package/dist/esm/resources/webhooks.d.ts +67 -0
  157. package/dist/esm/resources/webhooks.d.ts.map +1 -0
  158. package/dist/esm/resources/webhooks.js +175 -0
  159. package/dist/esm/resources/webhooks.js.map +1 -0
  160. package/dist/esm/security.d.ts +54 -0
  161. package/dist/esm/security.d.ts.map +1 -0
  162. package/dist/esm/security.js +153 -0
  163. package/dist/esm/security.js.map +1 -0
  164. package/dist/esm/types.d.ts +150 -0
  165. package/dist/esm/types.d.ts.map +1 -0
  166. package/dist/esm/types.js +335 -0
  167. package/dist/esm/types.js.map +1 -0
  168. package/dist/esm/utm.d.ts +37 -0
  169. package/dist/esm/utm.d.ts.map +1 -0
  170. package/dist/esm/utm.js +42 -0
  171. package/dist/esm/utm.js.map +1 -0
  172. package/package.json +89 -4
@@ -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,3 @@
1
+ import type { GlobalCliOptions } from "../types.js";
2
+ export declare function cmdConfigGet(opts: GlobalCliOptions, key?: string): Promise<number>;
3
+ export declare function cmdConfigSet(opts: GlobalCliOptions, key?: string, value?: string): Promise<number>;
@@ -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>;
@@ -0,0 +1,160 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cmdConversionsCreate = cmdConversionsCreate;
4
+ exports.cmdConversionsList = cmdConversionsList;
5
+ exports.cmdConversionsGet = cmdConversionsGet;
6
+ const node_util_1 = require("node:util");
7
+ const exitCodes_js_1 = require("../exitCodes.js");
8
+ const formatting_js_1 = require("../formatting.js");
9
+ async function cmdConversionsCreate(argv, opts, getClient) {
10
+ const { values } = (0, node_util_1.parseArgs)({
11
+ args: argv,
12
+ allowPositionals: false,
13
+ options: {
14
+ "url-id": { type: "string" },
15
+ "link-id": { type: "string" },
16
+ "event-name": { type: "string" },
17
+ value: { type: "string" },
18
+ revenue: { type: "string" },
19
+ amount: { type: "string" },
20
+ currency: { type: "string", default: "USD" },
21
+ "order-id": { type: "string" },
22
+ "customer-email": { type: "string" },
23
+ "click-id": { type: "string" },
24
+ "idempotency-key": { type: "string" },
25
+ },
26
+ });
27
+ const urlId = values["url-id"] ?? values["link-id"];
28
+ const eventName = values["event-name"];
29
+ if (!urlId || !eventName) {
30
+ (0, formatting_js_1.printError)("--url-id and --event-name are required.");
31
+ return exitCodes_js_1.EXIT_INVALID_ARGS;
32
+ }
33
+ const rawVal = values.value ?? values.revenue ?? values.amount;
34
+ const eventValue = rawVal !== undefined ? Number(rawVal) : undefined;
35
+ const client = getClient();
36
+ const conv = await client.conversions.create({
37
+ urlId,
38
+ eventName,
39
+ eventValue,
40
+ currency: values.currency,
41
+ orderId: values["order-id"],
42
+ customerEmail: values["customer-email"],
43
+ clickId: values["click-id"],
44
+ idempotencyKey: values["idempotency-key"],
45
+ });
46
+ if (opts.quiet) {
47
+ process.stdout.write(`${conv.id}\n`);
48
+ }
49
+ else if (opts.json) {
50
+ (0, formatting_js_1.outputJson)(conv);
51
+ }
52
+ else {
53
+ process.stdout.write(`✓ Conversion recorded: ${conv.id}\n\n`);
54
+ (0, formatting_js_1.printDetails)([
55
+ ["ID:", conv.id],
56
+ ["Link ID:", conv.urlId],
57
+ ["Event:", conv.eventName],
58
+ ["Value:", conv.eventValue !== undefined ? `${conv.eventValue} ${conv.currency}` : "(none)"],
59
+ ["Order ID:", conv.orderId ?? "(none)"],
60
+ ["Request ID:", conv.requestId],
61
+ ]);
62
+ }
63
+ return exitCodes_js_1.EXIT_SUCCESS;
64
+ }
65
+ async function cmdConversionsList(argv, opts, getClient) {
66
+ const { values } = (0, node_util_1.parseArgs)({
67
+ args: argv,
68
+ allowPositionals: false,
69
+ options: {
70
+ page: { type: "string" },
71
+ limit: { type: "string" },
72
+ "event-name": { type: "string" },
73
+ "url-id": { type: "string" },
74
+ "link-id": { 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 urlId = values["url-id"] ?? values["link-id"];
81
+ const client = getClient();
82
+ if (values.all) {
83
+ const items = await client.conversions
84
+ .iter({ limit: limitNum, eventName: values["event-name"], urlId })
85
+ .toArray();
86
+ if (opts.quiet) {
87
+ for (const item of items)
88
+ process.stdout.write(`${item.id}\n`);
89
+ }
90
+ else if (opts.json) {
91
+ (0, formatting_js_1.outputJson)(items);
92
+ }
93
+ else {
94
+ const rows = items.map((c) => [
95
+ c.id,
96
+ c.eventName,
97
+ c.eventValue !== undefined ? `${c.eventValue} ${c.currency}` : "-",
98
+ c.urlId,
99
+ ]);
100
+ (0, formatting_js_1.printTable)(["ID", "EVENT", "VALUE", "LINK ID"], rows);
101
+ process.stdout.write(`\nTotal: ${items.length} conversions (streamed)\n`);
102
+ }
103
+ return exitCodes_js_1.EXIT_SUCCESS;
104
+ }
105
+ const page = await client.conversions.list({
106
+ page: pageNum,
107
+ limit: limitNum,
108
+ eventName: values["event-name"],
109
+ urlId,
110
+ });
111
+ if (opts.quiet) {
112
+ for (const item of page)
113
+ process.stdout.write(`${item.id}\n`);
114
+ }
115
+ else if (opts.json) {
116
+ (0, formatting_js_1.outputJson)(page);
117
+ }
118
+ else {
119
+ const rows = page.data.map((c) => [
120
+ c.id,
121
+ c.eventName,
122
+ c.eventValue !== undefined ? `${c.eventValue} ${c.currency}` : "-",
123
+ c.urlId,
124
+ ]);
125
+ (0, formatting_js_1.printTable)(["ID", "EVENT", "VALUE", "LINK ID"], rows);
126
+ const p = page.pagination;
127
+ const start = p.total > 0 ? (p.page - 1) * p.limit + 1 : 0;
128
+ const end = Math.min(p.page * p.limit, p.total);
129
+ process.stdout.write(`\nShowing ${start}–${end} of ${p.total} (Page ${p.page} of ${p.totalPages})\n`);
130
+ }
131
+ return exitCodes_js_1.EXIT_SUCCESS;
132
+ }
133
+ async function cmdConversionsGet(argv, opts, getClient) {
134
+ const conversionId = argv[0];
135
+ if (!conversionId) {
136
+ (0, formatting_js_1.printError)("Missing required <conversion_id> argument.");
137
+ return exitCodes_js_1.EXIT_INVALID_ARGS;
138
+ }
139
+ const client = getClient();
140
+ const conv = await client.conversions.get(conversionId);
141
+ if (opts.quiet) {
142
+ process.stdout.write(`${conv.id}\n`);
143
+ }
144
+ else if (opts.json) {
145
+ (0, formatting_js_1.outputJson)(conv);
146
+ }
147
+ else {
148
+ (0, formatting_js_1.printDetails)([
149
+ ["ID:", conv.id],
150
+ ["Link ID:", conv.urlId],
151
+ ["Event:", conv.eventName],
152
+ ["Value:", conv.eventValue !== undefined ? `${conv.eventValue} ${conv.currency}` : "(none)"],
153
+ ["Order ID:", conv.orderId ?? "(none)"],
154
+ ["Customer Email:", conv.customerEmail ?? "(none)"],
155
+ ["Created At:", conv.createdAt ?? "(none)"],
156
+ ["Request ID:", conv.requestId],
157
+ ]);
158
+ }
159
+ return exitCodes_js_1.EXIT_SUCCESS;
160
+ }
@@ -0,0 +1,6 @@
1
+ import type { ClientFactory, GlobalCliOptions } from "../types.js";
2
+ export declare function cmdLinksCreate(argv: string[], opts: GlobalCliOptions, getClient: ClientFactory): Promise<number>;
3
+ export declare function cmdLinksList(argv: string[], opts: GlobalCliOptions, getClient: ClientFactory): Promise<number>;
4
+ export declare function cmdLinksGet(argv: string[], opts: GlobalCliOptions, getClient: ClientFactory): Promise<number>;
5
+ export declare function cmdLinksUpdate(argv: string[], opts: GlobalCliOptions, getClient: ClientFactory): Promise<number>;
6
+ export declare function cmdLinksDelete(argv: string[], opts: GlobalCliOptions, getClient: ClientFactory): Promise<number>;