@affonso/cli 0.1.5 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -10
- package/dist/index.js +515 -921
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -29,7 +29,7 @@ var import_commander = require("commander");
|
|
|
29
29
|
// package.json
|
|
30
30
|
var package_default = {
|
|
31
31
|
name: "@affonso/cli",
|
|
32
|
-
version: "0.
|
|
32
|
+
version: "0.2.0",
|
|
33
33
|
description: "Command line interface for the Affonso affiliate marketing platform",
|
|
34
34
|
bin: {
|
|
35
35
|
affonso: "dist/index.js"
|
|
@@ -52,7 +52,7 @@ var package_default = {
|
|
|
52
52
|
node: ">=18"
|
|
53
53
|
},
|
|
54
54
|
dependencies: {
|
|
55
|
-
"@affonso/sdk": "^0.2
|
|
55
|
+
"@affonso/sdk": "^1.0.2",
|
|
56
56
|
commander: "^12.0.0",
|
|
57
57
|
open: "^10.0.0"
|
|
58
58
|
},
|
|
@@ -71,826 +71,8 @@ var package_default = {
|
|
|
71
71
|
license: "MIT"
|
|
72
72
|
};
|
|
73
73
|
|
|
74
|
-
//
|
|
75
|
-
var
|
|
76
|
-
status;
|
|
77
|
-
code;
|
|
78
|
-
field;
|
|
79
|
-
details;
|
|
80
|
-
headers;
|
|
81
|
-
constructor(message, opts2) {
|
|
82
|
-
super(message);
|
|
83
|
-
this.name = "AffonsoError";
|
|
84
|
-
this.status = opts2?.status;
|
|
85
|
-
this.code = opts2?.code;
|
|
86
|
-
this.field = opts2?.field;
|
|
87
|
-
this.details = opts2?.details;
|
|
88
|
-
this.headers = opts2?.headers;
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
var AuthenticationError = class extends AffonsoError {
|
|
92
|
-
constructor(message, opts2) {
|
|
93
|
-
super(message, { ...opts2, status: 401 });
|
|
94
|
-
this.name = "AuthenticationError";
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
var PermissionError = class extends AffonsoError {
|
|
98
|
-
constructor(message, opts2) {
|
|
99
|
-
super(message, { ...opts2, status: 403 });
|
|
100
|
-
this.name = "PermissionError";
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
var NotFoundError = class extends AffonsoError {
|
|
104
|
-
constructor(message, opts2) {
|
|
105
|
-
super(message, { ...opts2, status: 404 });
|
|
106
|
-
this.name = "NotFoundError";
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
var ValidationError = class extends AffonsoError {
|
|
110
|
-
details;
|
|
111
|
-
constructor(message, details, opts2) {
|
|
112
|
-
super(message, { ...opts2, status: 400, details });
|
|
113
|
-
this.name = "ValidationError";
|
|
114
|
-
this.details = details;
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
var DuplicateError = class extends AffonsoError {
|
|
118
|
-
constructor(message, opts2) {
|
|
119
|
-
super(message, { ...opts2, status: 409 });
|
|
120
|
-
this.name = "DuplicateError";
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
var RateLimitError = class extends AffonsoError {
|
|
124
|
-
retryAfter;
|
|
125
|
-
constructor(message, retryAfter, opts2) {
|
|
126
|
-
super(message, { ...opts2, status: 429 });
|
|
127
|
-
this.name = "RateLimitError";
|
|
128
|
-
this.retryAfter = retryAfter;
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
var InternalError = class extends AffonsoError {
|
|
132
|
-
constructor(message, opts2) {
|
|
133
|
-
super(message, opts2);
|
|
134
|
-
this.name = "InternalError";
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
var ConnectionError = class extends AffonsoError {
|
|
138
|
-
constructor(message) {
|
|
139
|
-
super(message, { status: void 0 });
|
|
140
|
-
this.name = "ConnectionError";
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
function errorFromResponse(status, body, headers) {
|
|
144
|
-
const err = body.error ?? {};
|
|
145
|
-
const message = err.message ?? `Request failed with status ${status}`;
|
|
146
|
-
const code = err.code;
|
|
147
|
-
const opts2 = { status, code, field: err.field, details: err.details, headers };
|
|
148
|
-
if (code === "VALIDATION_ERROR" || !code && status === 400) {
|
|
149
|
-
return new ValidationError(message, err.details ?? [], opts2);
|
|
150
|
-
}
|
|
151
|
-
if (code === "RATE_LIMIT_EXCEEDED" || !code && status === 429) {
|
|
152
|
-
const retry = headers.get("x-ratelimit-reset");
|
|
153
|
-
return new RateLimitError(message, retry ? Number(retry) : void 0, opts2);
|
|
154
|
-
}
|
|
155
|
-
if (code === "UNAUTHORIZED" || !code && status === 401) {
|
|
156
|
-
return new AuthenticationError(message, opts2);
|
|
157
|
-
}
|
|
158
|
-
if (code === "FORBIDDEN" || !code && status === 403) {
|
|
159
|
-
return new PermissionError(message, opts2);
|
|
160
|
-
}
|
|
161
|
-
if (code === "NOT_FOUND" || !code && status === 404) {
|
|
162
|
-
return new NotFoundError(message, opts2);
|
|
163
|
-
}
|
|
164
|
-
if (code === "DUPLICATE_ERROR" || !code && status === 409) {
|
|
165
|
-
return new DuplicateError(message, opts2);
|
|
166
|
-
}
|
|
167
|
-
if (status >= 500) return new InternalError(message, opts2);
|
|
168
|
-
return new AffonsoError(message, opts2);
|
|
169
|
-
}
|
|
170
|
-
var VERSION = true ? "0.2.0" : "0.1.0";
|
|
171
|
-
function buildQueryString(params) {
|
|
172
|
-
const parts = [];
|
|
173
|
-
for (const [key, value] of Object.entries(params)) {
|
|
174
|
-
if (value === void 0 || value === null) continue;
|
|
175
|
-
if (Array.isArray(value)) {
|
|
176
|
-
for (const v of value) {
|
|
177
|
-
parts.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(v))}`);
|
|
178
|
-
}
|
|
179
|
-
} else {
|
|
180
|
-
parts.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
return parts.length > 0 ? `?${parts.join("&")}` : "";
|
|
184
|
-
}
|
|
185
|
-
function isRetryable(status) {
|
|
186
|
-
return status === 429 || status >= 500;
|
|
187
|
-
}
|
|
188
|
-
function sleep(ms) {
|
|
189
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
190
|
-
}
|
|
191
|
-
function isNode() {
|
|
192
|
-
return typeof process !== "undefined" && process.versions != null && process.versions.node != null;
|
|
193
|
-
}
|
|
194
|
-
var HttpClient = class {
|
|
195
|
-
config;
|
|
196
|
-
constructor(config) {
|
|
197
|
-
this.config = config;
|
|
198
|
-
}
|
|
199
|
-
async request(opts2) {
|
|
200
|
-
const url = `${this.config.baseUrl}${opts2.path}${opts2.query ? buildQueryString(opts2.query) : ""}`;
|
|
201
|
-
const headers = {
|
|
202
|
-
Authorization: `Bearer ${this.config.apiKey}`,
|
|
203
|
-
"Content-Type": "application/json"
|
|
204
|
-
};
|
|
205
|
-
if (isNode()) {
|
|
206
|
-
headers["User-Agent"] = `affonso-sdk/${VERSION}`;
|
|
207
|
-
}
|
|
208
|
-
let lastError;
|
|
209
|
-
for (let attempt = 0; attempt <= this.config.maxRetries; attempt++) {
|
|
210
|
-
const controller = new AbortController();
|
|
211
|
-
const timeoutId = setTimeout(
|
|
212
|
-
() => controller.abort(new Error("Request timed out")),
|
|
213
|
-
this.config.timeout
|
|
214
|
-
);
|
|
215
|
-
try {
|
|
216
|
-
const response = await this.config.fetch(url, {
|
|
217
|
-
method: opts2.method,
|
|
218
|
-
headers,
|
|
219
|
-
body: opts2.body ? JSON.stringify(opts2.body) : void 0,
|
|
220
|
-
signal: controller.signal
|
|
221
|
-
});
|
|
222
|
-
clearTimeout(timeoutId);
|
|
223
|
-
if (response.status === 204) {
|
|
224
|
-
return void 0;
|
|
225
|
-
}
|
|
226
|
-
let body;
|
|
227
|
-
try {
|
|
228
|
-
body = await response.json();
|
|
229
|
-
} catch {
|
|
230
|
-
throw new AffonsoError(
|
|
231
|
-
`Expected JSON response but received unparseable body (status ${response.status})`,
|
|
232
|
-
{ status: response.status, headers: response.headers }
|
|
233
|
-
);
|
|
234
|
-
}
|
|
235
|
-
if (!response.ok || body.success === false) {
|
|
236
|
-
const error = errorFromResponse(response.status, body, response.headers);
|
|
237
|
-
if (isRetryable(response.status) && attempt < this.config.maxRetries) {
|
|
238
|
-
lastError = error;
|
|
239
|
-
const waitMs = this.getRetryDelay(attempt, response.headers);
|
|
240
|
-
await sleep(waitMs);
|
|
241
|
-
continue;
|
|
242
|
-
}
|
|
243
|
-
throw error;
|
|
244
|
-
}
|
|
245
|
-
return body;
|
|
246
|
-
} catch (err) {
|
|
247
|
-
clearTimeout(timeoutId);
|
|
248
|
-
if (err instanceof Error && err.name === "AbortError") {
|
|
249
|
-
const connErr = new ConnectionError("Request timed out");
|
|
250
|
-
if (attempt < this.config.maxRetries) {
|
|
251
|
-
lastError = connErr;
|
|
252
|
-
await sleep(this.getRetryDelay(attempt));
|
|
253
|
-
continue;
|
|
254
|
-
}
|
|
255
|
-
throw connErr;
|
|
256
|
-
}
|
|
257
|
-
if (err instanceof AffonsoError) {
|
|
258
|
-
throw err;
|
|
259
|
-
}
|
|
260
|
-
if (err instanceof Error) {
|
|
261
|
-
const connErr = new ConnectionError(err.message);
|
|
262
|
-
if (attempt < this.config.maxRetries) {
|
|
263
|
-
lastError = connErr;
|
|
264
|
-
await sleep(this.getRetryDelay(attempt));
|
|
265
|
-
continue;
|
|
266
|
-
}
|
|
267
|
-
throw connErr;
|
|
268
|
-
}
|
|
269
|
-
throw err;
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
throw lastError ?? new ConnectionError("Request failed after retries");
|
|
273
|
-
}
|
|
274
|
-
getRetryDelay(attempt, headers) {
|
|
275
|
-
if (headers) {
|
|
276
|
-
const reset = headers.get("x-ratelimit-reset");
|
|
277
|
-
if (reset) {
|
|
278
|
-
const resetMs = Number(reset) * 1e3 - Date.now();
|
|
279
|
-
if (resetMs > 0 && resetMs < 6e4) return resetMs;
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
return Math.min(1e3 * 2 ** attempt, 1e4);
|
|
283
|
-
}
|
|
284
|
-
};
|
|
285
|
-
var OffsetPage = class _OffsetPage {
|
|
286
|
-
data;
|
|
287
|
-
pagination;
|
|
288
|
-
httpClient;
|
|
289
|
-
requestOpts;
|
|
290
|
-
constructor(data, pagination, httpClient, requestOpts) {
|
|
291
|
-
this.data = data;
|
|
292
|
-
this.pagination = pagination;
|
|
293
|
-
this.httpClient = httpClient;
|
|
294
|
-
this.requestOpts = requestOpts;
|
|
295
|
-
}
|
|
296
|
-
async getNextPage() {
|
|
297
|
-
if (!this.pagination.has_next_page) return null;
|
|
298
|
-
const nextOpts = {
|
|
299
|
-
...this.requestOpts,
|
|
300
|
-
query: {
|
|
301
|
-
...this.requestOpts.query,
|
|
302
|
-
page: this.pagination.page + 1
|
|
303
|
-
}
|
|
304
|
-
};
|
|
305
|
-
const response = await this.httpClient.request(nextOpts);
|
|
306
|
-
return new _OffsetPage(response.data, response.pagination, this.httpClient, nextOpts);
|
|
307
|
-
}
|
|
308
|
-
async *autoPaginate(maxPages = 1e3) {
|
|
309
|
-
let page = this;
|
|
310
|
-
let pageCount = 0;
|
|
311
|
-
while (page && pageCount < maxPages) {
|
|
312
|
-
for (const item of page.data) {
|
|
313
|
-
yield item;
|
|
314
|
-
}
|
|
315
|
-
pageCount++;
|
|
316
|
-
page = await page.getNextPage();
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
};
|
|
320
|
-
var CursorPage = class _CursorPage {
|
|
321
|
-
data;
|
|
322
|
-
hasMore;
|
|
323
|
-
httpClient;
|
|
324
|
-
requestOpts;
|
|
325
|
-
constructor(data, hasMore, httpClient, requestOpts) {
|
|
326
|
-
this.data = data;
|
|
327
|
-
this.hasMore = hasMore;
|
|
328
|
-
this.httpClient = httpClient;
|
|
329
|
-
this.requestOpts = requestOpts;
|
|
330
|
-
}
|
|
331
|
-
async getNextPage() {
|
|
332
|
-
if (!this.hasMore || this.data.length === 0) return null;
|
|
333
|
-
const lastId = this.data[this.data.length - 1].id;
|
|
334
|
-
const nextOpts = {
|
|
335
|
-
...this.requestOpts,
|
|
336
|
-
query: {
|
|
337
|
-
...this.requestOpts.query,
|
|
338
|
-
starting_after: lastId
|
|
339
|
-
}
|
|
340
|
-
};
|
|
341
|
-
const response = await this.httpClient.request(nextOpts);
|
|
342
|
-
return new _CursorPage(response.data, response.has_more, this.httpClient, nextOpts);
|
|
343
|
-
}
|
|
344
|
-
async *autoPaginate(maxPages = 1e3) {
|
|
345
|
-
let page = this;
|
|
346
|
-
let pageCount = 0;
|
|
347
|
-
while (page && pageCount < maxPages) {
|
|
348
|
-
for (const item of page.data) {
|
|
349
|
-
yield item;
|
|
350
|
-
}
|
|
351
|
-
pageCount++;
|
|
352
|
-
page = await page.getNextPage();
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
};
|
|
356
|
-
var Affiliates = class {
|
|
357
|
-
httpClient;
|
|
358
|
-
constructor(httpClient) {
|
|
359
|
-
this.httpClient = httpClient;
|
|
360
|
-
}
|
|
361
|
-
async list(params) {
|
|
362
|
-
const query = params ? { ...params } : {};
|
|
363
|
-
const requestOpts = { method: "GET", path: "/affiliates", query };
|
|
364
|
-
const response = await this.httpClient.request(requestOpts);
|
|
365
|
-
return new OffsetPage(response.data, response.pagination, this.httpClient, requestOpts);
|
|
366
|
-
}
|
|
367
|
-
async retrieve(id, params) {
|
|
368
|
-
const query = params ? { ...params } : void 0;
|
|
369
|
-
const response = await this.httpClient.request({
|
|
370
|
-
method: "GET",
|
|
371
|
-
path: `/affiliates/${encodeURIComponent(id)}`,
|
|
372
|
-
query
|
|
373
|
-
});
|
|
374
|
-
return response.data;
|
|
375
|
-
}
|
|
376
|
-
async create(params) {
|
|
377
|
-
const response = await this.httpClient.request({
|
|
378
|
-
method: "POST",
|
|
379
|
-
path: "/affiliates",
|
|
380
|
-
body: params
|
|
381
|
-
});
|
|
382
|
-
return response.data;
|
|
383
|
-
}
|
|
384
|
-
async update(id, params) {
|
|
385
|
-
const response = await this.httpClient.request({
|
|
386
|
-
method: "PUT",
|
|
387
|
-
path: `/affiliates/${encodeURIComponent(id)}`,
|
|
388
|
-
body: params
|
|
389
|
-
});
|
|
390
|
-
return response.data;
|
|
391
|
-
}
|
|
392
|
-
async del(id) {
|
|
393
|
-
return this.httpClient.request({
|
|
394
|
-
method: "DELETE",
|
|
395
|
-
path: `/affiliates/${encodeURIComponent(id)}`
|
|
396
|
-
});
|
|
397
|
-
}
|
|
398
|
-
};
|
|
399
|
-
var Clicks = class {
|
|
400
|
-
httpClient;
|
|
401
|
-
constructor(httpClient) {
|
|
402
|
-
this.httpClient = httpClient;
|
|
403
|
-
}
|
|
404
|
-
async create(params) {
|
|
405
|
-
const response = await this.httpClient.request({
|
|
406
|
-
method: "POST",
|
|
407
|
-
path: "/clicks",
|
|
408
|
-
body: params
|
|
409
|
-
});
|
|
410
|
-
return response.data;
|
|
411
|
-
}
|
|
412
|
-
};
|
|
413
|
-
var Commissions = class {
|
|
414
|
-
httpClient;
|
|
415
|
-
constructor(httpClient) {
|
|
416
|
-
this.httpClient = httpClient;
|
|
417
|
-
}
|
|
418
|
-
async list(params) {
|
|
419
|
-
const query = params ? { ...params } : {};
|
|
420
|
-
const requestOpts = { method: "GET", path: "/commissions", query };
|
|
421
|
-
const response = await this.httpClient.request(requestOpts);
|
|
422
|
-
return new OffsetPage(response.data, response.pagination, this.httpClient, requestOpts);
|
|
423
|
-
}
|
|
424
|
-
async retrieve(id, params) {
|
|
425
|
-
const query = params ? { ...params } : void 0;
|
|
426
|
-
const response = await this.httpClient.request({
|
|
427
|
-
method: "GET",
|
|
428
|
-
path: `/commissions/${encodeURIComponent(id)}`,
|
|
429
|
-
query
|
|
430
|
-
});
|
|
431
|
-
return response.data;
|
|
432
|
-
}
|
|
433
|
-
async create(params) {
|
|
434
|
-
const response = await this.httpClient.request({
|
|
435
|
-
method: "POST",
|
|
436
|
-
path: "/commissions",
|
|
437
|
-
body: params
|
|
438
|
-
});
|
|
439
|
-
return response.data;
|
|
440
|
-
}
|
|
441
|
-
async update(id, params) {
|
|
442
|
-
const response = await this.httpClient.request({
|
|
443
|
-
method: "PUT",
|
|
444
|
-
path: `/commissions/${encodeURIComponent(id)}`,
|
|
445
|
-
body: params
|
|
446
|
-
});
|
|
447
|
-
return response.data;
|
|
448
|
-
}
|
|
449
|
-
async del(id) {
|
|
450
|
-
return this.httpClient.request({
|
|
451
|
-
method: "DELETE",
|
|
452
|
-
path: `/commissions/${encodeURIComponent(id)}`
|
|
453
|
-
});
|
|
454
|
-
}
|
|
455
|
-
};
|
|
456
|
-
var Coupons = class {
|
|
457
|
-
httpClient;
|
|
458
|
-
constructor(httpClient) {
|
|
459
|
-
this.httpClient = httpClient;
|
|
460
|
-
}
|
|
461
|
-
async list(params) {
|
|
462
|
-
const query = params ? { ...params } : {};
|
|
463
|
-
const requestOpts = { method: "GET", path: "/coupons", query };
|
|
464
|
-
const response = await this.httpClient.request(requestOpts);
|
|
465
|
-
return new OffsetPage(response.data, response.pagination, this.httpClient, requestOpts);
|
|
466
|
-
}
|
|
467
|
-
async retrieve(id, params) {
|
|
468
|
-
const query = params ? { ...params } : void 0;
|
|
469
|
-
const response = await this.httpClient.request({
|
|
470
|
-
method: "GET",
|
|
471
|
-
path: `/coupons/${encodeURIComponent(id)}`,
|
|
472
|
-
query
|
|
473
|
-
});
|
|
474
|
-
return response.data;
|
|
475
|
-
}
|
|
476
|
-
async create(params) {
|
|
477
|
-
const response = await this.httpClient.request({
|
|
478
|
-
method: "POST",
|
|
479
|
-
path: "/coupons",
|
|
480
|
-
body: params
|
|
481
|
-
});
|
|
482
|
-
return response.data;
|
|
483
|
-
}
|
|
484
|
-
async del(id) {
|
|
485
|
-
return this.httpClient.request({
|
|
486
|
-
method: "DELETE",
|
|
487
|
-
path: `/coupons/${encodeURIComponent(id)}`
|
|
488
|
-
});
|
|
489
|
-
}
|
|
490
|
-
};
|
|
491
|
-
var EmbedTokens = class {
|
|
492
|
-
httpClient;
|
|
493
|
-
constructor(httpClient) {
|
|
494
|
-
this.httpClient = httpClient;
|
|
495
|
-
}
|
|
496
|
-
async create(params) {
|
|
497
|
-
const response = await this.httpClient.request({
|
|
498
|
-
method: "POST",
|
|
499
|
-
path: "/embed/token",
|
|
500
|
-
body: params
|
|
501
|
-
});
|
|
502
|
-
return response.data;
|
|
503
|
-
}
|
|
504
|
-
};
|
|
505
|
-
var Marketplace = class {
|
|
506
|
-
httpClient;
|
|
507
|
-
constructor(httpClient) {
|
|
508
|
-
this.httpClient = httpClient;
|
|
509
|
-
}
|
|
510
|
-
async list(params) {
|
|
511
|
-
const query = params ? { ...params } : {};
|
|
512
|
-
const requestOpts = { method: "GET", path: "/marketplace", query };
|
|
513
|
-
const response = await this.httpClient.request(requestOpts);
|
|
514
|
-
return new OffsetPage(response.data, response.pagination, this.httpClient, requestOpts);
|
|
515
|
-
}
|
|
516
|
-
async retrieve(id) {
|
|
517
|
-
const response = await this.httpClient.request({
|
|
518
|
-
method: "GET",
|
|
519
|
-
path: `/marketplace/${encodeURIComponent(id)}`
|
|
520
|
-
});
|
|
521
|
-
return response.data;
|
|
522
|
-
}
|
|
523
|
-
};
|
|
524
|
-
var Payouts = class {
|
|
525
|
-
httpClient;
|
|
526
|
-
constructor(httpClient) {
|
|
527
|
-
this.httpClient = httpClient;
|
|
528
|
-
}
|
|
529
|
-
async list(params) {
|
|
530
|
-
const query = params ? { ...params } : {};
|
|
531
|
-
const requestOpts = { method: "GET", path: "/payouts", query };
|
|
532
|
-
const response = await this.httpClient.request(requestOpts);
|
|
533
|
-
return new OffsetPage(response.data, response.pagination, this.httpClient, requestOpts);
|
|
534
|
-
}
|
|
535
|
-
async retrieve(id) {
|
|
536
|
-
const response = await this.httpClient.request({
|
|
537
|
-
method: "GET",
|
|
538
|
-
path: `/payouts/${encodeURIComponent(id)}`
|
|
539
|
-
});
|
|
540
|
-
return response.data;
|
|
541
|
-
}
|
|
542
|
-
async update(id, params) {
|
|
543
|
-
const response = await this.httpClient.request({
|
|
544
|
-
method: "PUT",
|
|
545
|
-
path: `/payouts/${encodeURIComponent(id)}`,
|
|
546
|
-
body: params
|
|
547
|
-
});
|
|
548
|
-
return response.data;
|
|
549
|
-
}
|
|
550
|
-
};
|
|
551
|
-
var ProgramCreatives = class {
|
|
552
|
-
httpClient;
|
|
553
|
-
constructor(httpClient) {
|
|
554
|
-
this.httpClient = httpClient;
|
|
555
|
-
}
|
|
556
|
-
async list(params) {
|
|
557
|
-
const query = params ? { ...params } : {};
|
|
558
|
-
const requestOpts = { method: "GET", path: "/program/creatives", query };
|
|
559
|
-
const response = await this.httpClient.request(requestOpts);
|
|
560
|
-
return new OffsetPage(response.data, response.pagination, this.httpClient, requestOpts);
|
|
561
|
-
}
|
|
562
|
-
async retrieve(id) {
|
|
563
|
-
const response = await this.httpClient.request({
|
|
564
|
-
method: "GET",
|
|
565
|
-
path: `/program/creatives/${encodeURIComponent(id)}`
|
|
566
|
-
});
|
|
567
|
-
return response.data;
|
|
568
|
-
}
|
|
569
|
-
async create(params) {
|
|
570
|
-
const response = await this.httpClient.request({
|
|
571
|
-
method: "POST",
|
|
572
|
-
path: "/program/creatives",
|
|
573
|
-
body: params
|
|
574
|
-
});
|
|
575
|
-
return response.data;
|
|
576
|
-
}
|
|
577
|
-
async update(id, params) {
|
|
578
|
-
const response = await this.httpClient.request({
|
|
579
|
-
method: "PATCH",
|
|
580
|
-
path: `/program/creatives/${encodeURIComponent(id)}`,
|
|
581
|
-
body: params
|
|
582
|
-
});
|
|
583
|
-
return response.data;
|
|
584
|
-
}
|
|
585
|
-
async del(id) {
|
|
586
|
-
return this.httpClient.request({
|
|
587
|
-
method: "DELETE",
|
|
588
|
-
path: `/program/creatives/${encodeURIComponent(id)}`
|
|
589
|
-
});
|
|
590
|
-
}
|
|
591
|
-
};
|
|
592
|
-
var ProgramFraudRules = class {
|
|
593
|
-
httpClient;
|
|
594
|
-
constructor(httpClient) {
|
|
595
|
-
this.httpClient = httpClient;
|
|
596
|
-
}
|
|
597
|
-
async retrieve() {
|
|
598
|
-
const response = await this.httpClient.request({
|
|
599
|
-
method: "GET",
|
|
600
|
-
path: "/program/fraud-rules"
|
|
601
|
-
});
|
|
602
|
-
return response.data;
|
|
603
|
-
}
|
|
604
|
-
async update(params) {
|
|
605
|
-
const response = await this.httpClient.request({
|
|
606
|
-
method: "PATCH",
|
|
607
|
-
path: "/program/fraud-rules",
|
|
608
|
-
body: params
|
|
609
|
-
});
|
|
610
|
-
return response.data;
|
|
611
|
-
}
|
|
612
|
-
};
|
|
613
|
-
var ProgramGroups = class {
|
|
614
|
-
httpClient;
|
|
615
|
-
constructor(httpClient) {
|
|
616
|
-
this.httpClient = httpClient;
|
|
617
|
-
}
|
|
618
|
-
async list(params) {
|
|
619
|
-
const query = params ? { ...params } : void 0;
|
|
620
|
-
const response = await this.httpClient.request({
|
|
621
|
-
method: "GET",
|
|
622
|
-
path: "/program/groups",
|
|
623
|
-
query
|
|
624
|
-
});
|
|
625
|
-
return response.data;
|
|
626
|
-
}
|
|
627
|
-
async retrieve(id, params) {
|
|
628
|
-
const query = params ? { ...params } : void 0;
|
|
629
|
-
const response = await this.httpClient.request({
|
|
630
|
-
method: "GET",
|
|
631
|
-
path: `/program/groups/${encodeURIComponent(id)}`,
|
|
632
|
-
query
|
|
633
|
-
});
|
|
634
|
-
return response.data;
|
|
635
|
-
}
|
|
636
|
-
async create(params) {
|
|
637
|
-
const response = await this.httpClient.request({
|
|
638
|
-
method: "POST",
|
|
639
|
-
path: "/program/groups",
|
|
640
|
-
body: params
|
|
641
|
-
});
|
|
642
|
-
return response.data;
|
|
643
|
-
}
|
|
644
|
-
async update(id, params) {
|
|
645
|
-
const response = await this.httpClient.request({
|
|
646
|
-
method: "PATCH",
|
|
647
|
-
path: `/program/groups/${encodeURIComponent(id)}`,
|
|
648
|
-
body: params
|
|
649
|
-
});
|
|
650
|
-
return response.data;
|
|
651
|
-
}
|
|
652
|
-
async del(id) {
|
|
653
|
-
return this.httpClient.request({
|
|
654
|
-
method: "DELETE",
|
|
655
|
-
path: `/program/groups/${encodeURIComponent(id)}`
|
|
656
|
-
});
|
|
657
|
-
}
|
|
658
|
-
};
|
|
659
|
-
var ProgramNotifications = class {
|
|
660
|
-
httpClient;
|
|
661
|
-
constructor(httpClient) {
|
|
662
|
-
this.httpClient = httpClient;
|
|
663
|
-
}
|
|
664
|
-
async list() {
|
|
665
|
-
const response = await this.httpClient.request({
|
|
666
|
-
method: "GET",
|
|
667
|
-
path: "/program/notifications"
|
|
668
|
-
});
|
|
669
|
-
return response.data;
|
|
670
|
-
}
|
|
671
|
-
async update(emailTypeId, params) {
|
|
672
|
-
const response = await this.httpClient.request({
|
|
673
|
-
method: "PATCH",
|
|
674
|
-
path: `/program/notifications/${encodeURIComponent(emailTypeId)}`,
|
|
675
|
-
body: params
|
|
676
|
-
});
|
|
677
|
-
return response.data;
|
|
678
|
-
}
|
|
679
|
-
};
|
|
680
|
-
var ProgramPaymentTerms = class {
|
|
681
|
-
httpClient;
|
|
682
|
-
constructor(httpClient) {
|
|
683
|
-
this.httpClient = httpClient;
|
|
684
|
-
}
|
|
685
|
-
async retrieve() {
|
|
686
|
-
const response = await this.httpClient.request({
|
|
687
|
-
method: "GET",
|
|
688
|
-
path: "/program/payment-terms"
|
|
689
|
-
});
|
|
690
|
-
return response.data;
|
|
691
|
-
}
|
|
692
|
-
async update(params) {
|
|
693
|
-
const response = await this.httpClient.request({
|
|
694
|
-
method: "PATCH",
|
|
695
|
-
path: "/program/payment-terms",
|
|
696
|
-
body: params
|
|
697
|
-
});
|
|
698
|
-
return response.data;
|
|
699
|
-
}
|
|
700
|
-
};
|
|
701
|
-
var ProgramPortal = class {
|
|
702
|
-
httpClient;
|
|
703
|
-
constructor(httpClient) {
|
|
704
|
-
this.httpClient = httpClient;
|
|
705
|
-
}
|
|
706
|
-
async retrieve() {
|
|
707
|
-
const response = await this.httpClient.request({
|
|
708
|
-
method: "GET",
|
|
709
|
-
path: "/program/portal"
|
|
710
|
-
});
|
|
711
|
-
return response.data;
|
|
712
|
-
}
|
|
713
|
-
async update(params) {
|
|
714
|
-
const response = await this.httpClient.request({
|
|
715
|
-
method: "PATCH",
|
|
716
|
-
path: "/program/portal",
|
|
717
|
-
body: params
|
|
718
|
-
});
|
|
719
|
-
return response.data;
|
|
720
|
-
}
|
|
721
|
-
};
|
|
722
|
-
var ProgramRestrictions = class {
|
|
723
|
-
httpClient;
|
|
724
|
-
constructor(httpClient) {
|
|
725
|
-
this.httpClient = httpClient;
|
|
726
|
-
}
|
|
727
|
-
async retrieve() {
|
|
728
|
-
const response = await this.httpClient.request({
|
|
729
|
-
method: "GET",
|
|
730
|
-
path: "/program/restrictions"
|
|
731
|
-
});
|
|
732
|
-
return response.data;
|
|
733
|
-
}
|
|
734
|
-
async update(params) {
|
|
735
|
-
const response = await this.httpClient.request({
|
|
736
|
-
method: "PATCH",
|
|
737
|
-
path: "/program/restrictions",
|
|
738
|
-
body: params
|
|
739
|
-
});
|
|
740
|
-
return response.data;
|
|
741
|
-
}
|
|
742
|
-
};
|
|
743
|
-
var ProgramSettingsResource = class {
|
|
744
|
-
httpClient;
|
|
745
|
-
constructor(httpClient) {
|
|
746
|
-
this.httpClient = httpClient;
|
|
747
|
-
}
|
|
748
|
-
async retrieve() {
|
|
749
|
-
const response = await this.httpClient.request({
|
|
750
|
-
method: "GET",
|
|
751
|
-
path: "/program"
|
|
752
|
-
});
|
|
753
|
-
return response.data;
|
|
754
|
-
}
|
|
755
|
-
async update(params) {
|
|
756
|
-
const response = await this.httpClient.request({
|
|
757
|
-
method: "PATCH",
|
|
758
|
-
path: "/program",
|
|
759
|
-
body: params
|
|
760
|
-
});
|
|
761
|
-
return response.data;
|
|
762
|
-
}
|
|
763
|
-
};
|
|
764
|
-
var ProgramTracking = class {
|
|
765
|
-
httpClient;
|
|
766
|
-
constructor(httpClient) {
|
|
767
|
-
this.httpClient = httpClient;
|
|
768
|
-
}
|
|
769
|
-
async retrieve() {
|
|
770
|
-
const response = await this.httpClient.request({
|
|
771
|
-
method: "GET",
|
|
772
|
-
path: "/program/tracking"
|
|
773
|
-
});
|
|
774
|
-
return response.data;
|
|
775
|
-
}
|
|
776
|
-
async update(params) {
|
|
777
|
-
const response = await this.httpClient.request({
|
|
778
|
-
method: "PATCH",
|
|
779
|
-
path: "/program/tracking",
|
|
780
|
-
body: params
|
|
781
|
-
});
|
|
782
|
-
return response.data;
|
|
783
|
-
}
|
|
784
|
-
};
|
|
785
|
-
var Program = class {
|
|
786
|
-
paymentTerms;
|
|
787
|
-
tracking;
|
|
788
|
-
restrictions;
|
|
789
|
-
groups;
|
|
790
|
-
creatives;
|
|
791
|
-
notifications;
|
|
792
|
-
portal;
|
|
793
|
-
fraudRules;
|
|
794
|
-
settings;
|
|
795
|
-
constructor(httpClient) {
|
|
796
|
-
this.settings = new ProgramSettingsResource(httpClient);
|
|
797
|
-
this.paymentTerms = new ProgramPaymentTerms(httpClient);
|
|
798
|
-
this.tracking = new ProgramTracking(httpClient);
|
|
799
|
-
this.restrictions = new ProgramRestrictions(httpClient);
|
|
800
|
-
this.groups = new ProgramGroups(httpClient);
|
|
801
|
-
this.creatives = new ProgramCreatives(httpClient);
|
|
802
|
-
this.notifications = new ProgramNotifications(httpClient);
|
|
803
|
-
this.portal = new ProgramPortal(httpClient);
|
|
804
|
-
this.fraudRules = new ProgramFraudRules(httpClient);
|
|
805
|
-
}
|
|
806
|
-
async retrieve() {
|
|
807
|
-
return this.settings.retrieve();
|
|
808
|
-
}
|
|
809
|
-
async update(params) {
|
|
810
|
-
return this.settings.update(params);
|
|
811
|
-
}
|
|
812
|
-
};
|
|
813
|
-
var Referrals = class {
|
|
814
|
-
httpClient;
|
|
815
|
-
constructor(httpClient) {
|
|
816
|
-
this.httpClient = httpClient;
|
|
817
|
-
}
|
|
818
|
-
async list(params) {
|
|
819
|
-
const query = params ? { ...params } : {};
|
|
820
|
-
const requestOpts = { method: "GET", path: "/referrals", query };
|
|
821
|
-
const response = await this.httpClient.request(requestOpts);
|
|
822
|
-
return new CursorPage(response.data, response.has_more, this.httpClient, requestOpts);
|
|
823
|
-
}
|
|
824
|
-
async retrieve(id, params) {
|
|
825
|
-
const query = params ? { ...params } : void 0;
|
|
826
|
-
const response = await this.httpClient.request({
|
|
827
|
-
method: "GET",
|
|
828
|
-
path: `/referrals/${encodeURIComponent(id)}`,
|
|
829
|
-
query
|
|
830
|
-
});
|
|
831
|
-
return response.data;
|
|
832
|
-
}
|
|
833
|
-
async create(params) {
|
|
834
|
-
const response = await this.httpClient.request({
|
|
835
|
-
method: "POST",
|
|
836
|
-
path: "/referrals",
|
|
837
|
-
body: params
|
|
838
|
-
});
|
|
839
|
-
return response.data;
|
|
840
|
-
}
|
|
841
|
-
async update(id, params) {
|
|
842
|
-
const response = await this.httpClient.request({
|
|
843
|
-
method: "PUT",
|
|
844
|
-
path: `/referrals/${encodeURIComponent(id)}`,
|
|
845
|
-
body: params
|
|
846
|
-
});
|
|
847
|
-
return response.data;
|
|
848
|
-
}
|
|
849
|
-
async del(id) {
|
|
850
|
-
return this.httpClient.request({
|
|
851
|
-
method: "DELETE",
|
|
852
|
-
path: `/referrals/${encodeURIComponent(id)}`
|
|
853
|
-
});
|
|
854
|
-
}
|
|
855
|
-
};
|
|
856
|
-
var DEFAULT_BASE_URL = "https://api.affonso.io/v1";
|
|
857
|
-
var DEFAULT_TIMEOUT = 3e4;
|
|
858
|
-
var DEFAULT_MAX_RETRIES = 2;
|
|
859
|
-
var Affonso = class {
|
|
860
|
-
affiliates;
|
|
861
|
-
referrals;
|
|
862
|
-
clicks;
|
|
863
|
-
commissions;
|
|
864
|
-
coupons;
|
|
865
|
-
payouts;
|
|
866
|
-
program;
|
|
867
|
-
embedTokens;
|
|
868
|
-
marketplace;
|
|
869
|
-
constructor(apiKey, config) {
|
|
870
|
-
if (!apiKey) {
|
|
871
|
-
throw new Error(
|
|
872
|
-
"An API key is required. Pass it as the first argument: new Affonso('sk_...')"
|
|
873
|
-
);
|
|
874
|
-
}
|
|
875
|
-
const httpConfig = {
|
|
876
|
-
apiKey,
|
|
877
|
-
baseUrl: config?.baseUrl ?? DEFAULT_BASE_URL,
|
|
878
|
-
timeout: config?.timeout ?? DEFAULT_TIMEOUT,
|
|
879
|
-
maxRetries: config?.maxRetries ?? DEFAULT_MAX_RETRIES,
|
|
880
|
-
fetch: config?.fetch ?? ((...args) => globalThis.fetch(...args))
|
|
881
|
-
};
|
|
882
|
-
const httpClient = new HttpClient(httpConfig);
|
|
883
|
-
this.affiliates = new Affiliates(httpClient);
|
|
884
|
-
this.referrals = new Referrals(httpClient);
|
|
885
|
-
this.clicks = new Clicks(httpClient);
|
|
886
|
-
this.commissions = new Commissions(httpClient);
|
|
887
|
-
this.coupons = new Coupons(httpClient);
|
|
888
|
-
this.payouts = new Payouts(httpClient);
|
|
889
|
-
this.program = new Program(httpClient);
|
|
890
|
-
this.embedTokens = new EmbedTokens(httpClient);
|
|
891
|
-
this.marketplace = new Marketplace(httpClient);
|
|
892
|
-
}
|
|
893
|
-
};
|
|
74
|
+
// src/lib/client.ts
|
|
75
|
+
var import_sdk = require("@affonso/sdk");
|
|
894
76
|
|
|
895
77
|
// src/auth/oauth.ts
|
|
896
78
|
var import_node_crypto = __toESM(require("crypto"));
|
|
@@ -1154,12 +336,23 @@ async function getClient(opts2) {
|
|
|
1154
336
|
console.error("Error: Authentication required. Run `affonso login` or set AFFONSO_API_KEY.");
|
|
1155
337
|
process.exit(1);
|
|
1156
338
|
}
|
|
1157
|
-
return new Affonso(auth.apiKey, {
|
|
339
|
+
return new import_sdk.Affonso(auth.apiKey, {
|
|
340
|
+
baseUrl,
|
|
341
|
+
signingSecret: process.env.AFFONSO_SIGNING_SECRET,
|
|
342
|
+
sourceSigningSecrets: {
|
|
343
|
+
...process.env.AFFONSO_CUSTOM_SOURCE_SIGNING_SECRET ? { custom: process.env.AFFONSO_CUSTOM_SOURCE_SIGNING_SECRET } : {},
|
|
344
|
+
...process.env.AFFONSO_SEGMENT_SIGNING_SECRET ? {
|
|
345
|
+
segment: process.env.AFFONSO_SEGMENT_SIGNING_SECRET,
|
|
346
|
+
segment_webhook: process.env.AFFONSO_SEGMENT_SIGNING_SECRET
|
|
347
|
+
} : {}
|
|
348
|
+
}
|
|
349
|
+
});
|
|
1158
350
|
}
|
|
1159
351
|
|
|
1160
352
|
// src/lib/errors.ts
|
|
353
|
+
var import_sdk2 = require("@affonso/sdk");
|
|
1161
354
|
function handleError(err, json) {
|
|
1162
|
-
if (err instanceof AffonsoError) {
|
|
355
|
+
if (err instanceof import_sdk2.AffonsoError) {
|
|
1163
356
|
if (json) {
|
|
1164
357
|
console.error(
|
|
1165
358
|
JSON.stringify(
|
|
@@ -1227,6 +420,35 @@ function opts(cmd) {
|
|
|
1227
420
|
return merged;
|
|
1228
421
|
}
|
|
1229
422
|
|
|
423
|
+
// src/lib/parse.ts
|
|
424
|
+
var import_node_fs2 = require("fs");
|
|
425
|
+
function readJsonInput(value) {
|
|
426
|
+
if (!value.startsWith("@")) return value;
|
|
427
|
+
const path2 = value.slice(1);
|
|
428
|
+
if (!path2) throw new Error("JSON file path must follow @.");
|
|
429
|
+
return (0, import_node_fs2.readFileSync)(path2, "utf8");
|
|
430
|
+
}
|
|
431
|
+
function parseJson(value, optionName) {
|
|
432
|
+
try {
|
|
433
|
+
return JSON.parse(readJsonInput(value));
|
|
434
|
+
} catch (error) {
|
|
435
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
436
|
+
throw new Error(`Invalid JSON for ${optionName}: ${detail}`);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
function parseJsonObject(value, optionName) {
|
|
440
|
+
if (value === void 0) return void 0;
|
|
441
|
+
const parsed = parseJson(value, optionName);
|
|
442
|
+
if (parsed === null || Array.isArray(parsed) || typeof parsed !== "object") {
|
|
443
|
+
throw new Error(`${optionName} must contain a JSON object.`);
|
|
444
|
+
}
|
|
445
|
+
return parsed;
|
|
446
|
+
}
|
|
447
|
+
function commaSeparated(value) {
|
|
448
|
+
if (value === void 0) return void 0;
|
|
449
|
+
return value.split(",").map((item) => item.trim()).filter(Boolean);
|
|
450
|
+
}
|
|
451
|
+
|
|
1230
452
|
// src/output/json.ts
|
|
1231
453
|
function formatJson(data) {
|
|
1232
454
|
return JSON.stringify(data, null, 2);
|
|
@@ -1325,7 +547,7 @@ function outputSuccess(message, opts2) {
|
|
|
1325
547
|
// src/commands/affiliates.ts
|
|
1326
548
|
function registerAffiliateCommands(program2) {
|
|
1327
549
|
const affiliates = program2.command("affiliates").description("Manage affiliates");
|
|
1328
|
-
affiliates.command("list").description("List affiliates").option("--limit <n>", "Items per page", "50").option("--page <n>", "Page number", "1").option("--status <status>", "Filter by status (pending, approved, rejected)").option("--search <query>", "Search by name or email").option("--group-id <id>", "Filter by group ID").option("--
|
|
550
|
+
affiliates.command("list").description("List affiliates").option("--limit <n>", "Items per page", "50").option("--page <n>", "Page number", "1").option("--status <status>", "Filter by status (pending, approved, rejected)").option("--search <query>", "Search by name or email").option("--group-id <id>", "Filter by group ID").option("--expand <fields>", "Expand fields (comma-separated)").option("--sort <field:dir>", "Sort (e.g. createdAt:desc)").option("--date-from <date>", "Filter from date").option("--date-to <date>", "Filter to date").action(async function() {
|
|
1329
551
|
const o = opts(this);
|
|
1330
552
|
try {
|
|
1331
553
|
const client = await getClient(o);
|
|
@@ -1335,7 +557,6 @@ function registerAffiliateCommands(program2) {
|
|
|
1335
557
|
partnership_status: o.status,
|
|
1336
558
|
search: o.search,
|
|
1337
559
|
group_id: o.groupId,
|
|
1338
|
-
program_id: o.programId,
|
|
1339
560
|
expand: o.expand,
|
|
1340
561
|
sort: o.sort,
|
|
1341
562
|
dateFrom: o.dateFrom,
|
|
@@ -1365,29 +586,33 @@ function registerAffiliateCommands(program2) {
|
|
|
1365
586
|
handleError(err, o.json);
|
|
1366
587
|
}
|
|
1367
588
|
});
|
|
1368
|
-
affiliates.command("create").description("Create an affiliate").requiredOption("--name <name>", "Affiliate name").requiredOption("--email <email>", "Affiliate email").
|
|
589
|
+
affiliates.command("create").description("Create an affiliate").requiredOption("--name <name>", "Affiliate name").requiredOption("--email <email>", "Affiliate email").option("--tracking-id <id>", "Custom tracking ID").option("--group-id <id>", "Group ID").option("--company-name <name>", "Company name").option("--country-code <code>", "Country code").option("--status <status>", "Partnership status (pending, approved, rejected)").option("--onboarding-completed", "Mark onboarding as completed").option("--payout-method <method>", "Payout method").option("--payout-details-json <json|@file>", "Payout details as JSON or @file").option("--external-user-id <id>", "External user ID").option("--metadata-json <json|@file>", "Metadata as JSON or @file").action(async function() {
|
|
1369
590
|
const o = opts(this);
|
|
1370
591
|
try {
|
|
1371
|
-
const
|
|
1372
|
-
const result = await client.affiliates.create({
|
|
592
|
+
const params = {
|
|
1373
593
|
name: o.name,
|
|
1374
594
|
email: o.email,
|
|
1375
|
-
program_id: o.programId,
|
|
1376
595
|
tracking_id: o.trackingId,
|
|
1377
596
|
group_id: o.groupId,
|
|
1378
597
|
company_name: o.companyName,
|
|
1379
598
|
country_code: o.countryCode,
|
|
1380
|
-
|
|
1381
|
-
|
|
599
|
+
status: o.status,
|
|
600
|
+
onboarding_completed: o.onboardingCompleted || void 0,
|
|
601
|
+
payout_method: o.payoutMethod,
|
|
602
|
+
payout_details: parseJsonObject(o.payoutDetailsJson, "--payout-details-json"),
|
|
603
|
+
external_user_id: o.externalUserId,
|
|
604
|
+
metadata: parseJsonObject(o.metadataJson, "--metadata-json")
|
|
605
|
+
};
|
|
606
|
+
const client = await getClient(o);
|
|
607
|
+
const result = await client.affiliates.create(params);
|
|
1382
608
|
output(result, o);
|
|
1383
609
|
} catch (err) {
|
|
1384
610
|
handleError(err, o.json);
|
|
1385
611
|
}
|
|
1386
612
|
});
|
|
1387
|
-
affiliates.command("update <id>").description("Update an affiliate").option("--name <name>", "Affiliate name").option("--email <email>", "Affiliate email").option("--status <status>", "Status (pending, approved, rejected)").option("--group-id <id>", "Group ID").option("--company-name <name>", "Company name").option("--country-code <code>", "Country code").option("--external-user-id <id>", "External user ID").option("--onboarding-completed", "Mark onboarding as completed").action(async function(id) {
|
|
613
|
+
affiliates.command("update <id>").description("Update an affiliate").option("--name <name>", "Affiliate name").option("--email <email>", "Affiliate email").option("--status <status>", "Status (pending, approved, rejected)").option("--group-id <id>", "Group ID").option("--company-name <name>", "Company name").option("--country-code <code>", "Country code").option("--invoice-details-json <json|@file>", "Invoice details as JSON or @file").option("--payout-method <method>", "Payout method").option("--payout-details-json <json|@file>", "Payout details as JSON or @file").option("--external-user-id <id>", "External user ID").option("--metadata-json <json|@file>", "Metadata as JSON or @file").option("--onboarding-completed", "Mark onboarding as completed").option("--no-onboarding-completed", "Mark onboarding as incomplete").action(async function(id) {
|
|
1388
614
|
const o = opts(this);
|
|
1389
615
|
try {
|
|
1390
|
-
const client = await getClient(o);
|
|
1391
616
|
const params = {};
|
|
1392
617
|
if (o.name !== void 0) params.name = o.name;
|
|
1393
618
|
if (o.email !== void 0) params.email = o.email;
|
|
@@ -1395,8 +620,17 @@ function registerAffiliateCommands(program2) {
|
|
|
1395
620
|
if (o.groupId !== void 0) params.group_id = o.groupId;
|
|
1396
621
|
if (o.companyName !== void 0) params.company_name = o.companyName;
|
|
1397
622
|
if (o.countryCode !== void 0) params.country_code = o.countryCode;
|
|
623
|
+
if (o.invoiceDetailsJson !== void 0)
|
|
624
|
+
params.invoice_details = parseJsonObject(o.invoiceDetailsJson, "--invoice-details-json");
|
|
625
|
+
if (o.payoutMethod !== void 0) params.payout_method = o.payoutMethod;
|
|
626
|
+
if (o.payoutDetailsJson !== void 0)
|
|
627
|
+
params.payout_details = parseJsonObject(o.payoutDetailsJson, "--payout-details-json");
|
|
1398
628
|
if (o.externalUserId !== void 0) params.external_user_id = o.externalUserId;
|
|
1399
|
-
if (o.
|
|
629
|
+
if (o.metadataJson !== void 0)
|
|
630
|
+
params.metadata = parseJsonObject(o.metadataJson, "--metadata-json");
|
|
631
|
+
if (o.onboardingCompleted !== void 0)
|
|
632
|
+
params.onboarding_completed = o.onboardingCompleted;
|
|
633
|
+
const client = await getClient(o);
|
|
1400
634
|
const result = await client.affiliates.update(id, params);
|
|
1401
635
|
output(result, o);
|
|
1402
636
|
} catch (err) {
|
|
@@ -1413,18 +647,58 @@ function registerAffiliateCommands(program2) {
|
|
|
1413
647
|
handleError(err, o.json);
|
|
1414
648
|
}
|
|
1415
649
|
});
|
|
650
|
+
const onboarding = affiliates.command("onboarding-responses").description("Manage affiliate onboarding responses");
|
|
651
|
+
onboarding.command("get <affiliate-id>").description("Get an affiliate's onboarding responses").action(async function(affiliateId) {
|
|
652
|
+
const o = opts(this);
|
|
653
|
+
try {
|
|
654
|
+
const client = await getClient(o);
|
|
655
|
+
output(await client.affiliates.retrieveOnboardingResponses(affiliateId), o);
|
|
656
|
+
} catch (err) {
|
|
657
|
+
handleError(err, o.json);
|
|
658
|
+
}
|
|
659
|
+
});
|
|
660
|
+
onboarding.command("submit <affiliate-id>").description("Submit an affiliate's onboarding responses").requiredOption("--responses-json <json|@file>", "Response array as JSON or @file").option("--mark-complete", "Mark onboarding as complete").action(async function(affiliateId) {
|
|
661
|
+
const o = opts(this);
|
|
662
|
+
try {
|
|
663
|
+
const responses = parseJson(
|
|
664
|
+
o.responsesJson,
|
|
665
|
+
"--responses-json"
|
|
666
|
+
);
|
|
667
|
+
if (!Array.isArray(responses))
|
|
668
|
+
throw new Error("--responses-json must contain a JSON array.");
|
|
669
|
+
const client = await getClient(o);
|
|
670
|
+
output(
|
|
671
|
+
await client.affiliates.submitOnboardingResponses(affiliateId, {
|
|
672
|
+
responses,
|
|
673
|
+
mark_complete: o.markComplete || void 0
|
|
674
|
+
}),
|
|
675
|
+
o
|
|
676
|
+
);
|
|
677
|
+
} catch (err) {
|
|
678
|
+
handleError(err, o.json);
|
|
679
|
+
}
|
|
680
|
+
});
|
|
681
|
+
affiliates.command("portal-token <id>").description("Create a portal login token for an affiliate").action(async function(id) {
|
|
682
|
+
const o = opts(this);
|
|
683
|
+
try {
|
|
684
|
+
const client = await getClient(o);
|
|
685
|
+
output(await client.affiliates.createPortalToken(id), o);
|
|
686
|
+
} catch (err) {
|
|
687
|
+
handleError(err, o.json);
|
|
688
|
+
}
|
|
689
|
+
});
|
|
1416
690
|
}
|
|
1417
691
|
|
|
1418
692
|
// src/commands/clicks.ts
|
|
1419
693
|
function registerClickCommands(program2) {
|
|
1420
694
|
const clicks = program2.command("clicks").description("Track click events");
|
|
1421
|
-
clicks.command("create").description("Record a click event").requiredOption("--
|
|
695
|
+
clicks.command("create").description("Record a click event").requiredOption("--tracking-id <id>", "Tracking ID").option("--created-at <date>", "Creation timestamp (ISO 8601)").option("--referrer <url>", "Referrer URL").option("--utm-source <val>", "UTM source").option("--utm-medium <val>", "UTM medium").option("--utm-campaign <val>", "UTM campaign").option("--utm-term <val>", "UTM term").option("--utm-content <val>", "UTM content").option("--sub1 <val>", "Sub-tracking parameter 1").option("--sub2 <val>", "Sub-tracking parameter 2").option("--sub3 <val>", "Sub-tracking parameter 3").option("--sub4 <val>", "Sub-tracking parameter 4").option("--sub5 <val>", "Sub-tracking parameter 5").option("--ip <ip>", "IP address").option("--user-agent <ua>", "User agent string").option("--gclid <id>", "Google click ID").option("--fbclid <id>", "Meta click ID").option("--msclkid <id>", "Microsoft click ID").option("--ttclid <id>", "TikTok click ID").action(async function() {
|
|
1422
696
|
const o = opts(this);
|
|
1423
697
|
try {
|
|
1424
698
|
const client = await getClient(o);
|
|
1425
699
|
const result = await client.clicks.create({
|
|
1426
|
-
programId: o.programId,
|
|
1427
700
|
trackingId: o.trackingId,
|
|
701
|
+
createdAt: o.createdAt,
|
|
1428
702
|
referrer: o.referrer,
|
|
1429
703
|
utmSource: o.utmSource,
|
|
1430
704
|
utmMedium: o.utmMedium,
|
|
@@ -1437,7 +711,11 @@ function registerClickCommands(program2) {
|
|
|
1437
711
|
sub4: o.sub4,
|
|
1438
712
|
sub5: o.sub5,
|
|
1439
713
|
ip: o.ip,
|
|
1440
|
-
userAgent: o.userAgent
|
|
714
|
+
userAgent: o.userAgent,
|
|
715
|
+
gclid: o.gclid,
|
|
716
|
+
fbclid: o.fbclid,
|
|
717
|
+
msclkid: o.msclkid,
|
|
718
|
+
ttclid: o.ttclid
|
|
1441
719
|
});
|
|
1442
720
|
output(result, o);
|
|
1443
721
|
} catch (err) {
|
|
@@ -1490,7 +768,7 @@ function registerCommissionCommands(program2) {
|
|
|
1490
768
|
handleError(err, o.json);
|
|
1491
769
|
}
|
|
1492
770
|
});
|
|
1493
|
-
commissions.command("create").description("Create a commission").requiredOption("--referral-id <id>", "Referral ID").requiredOption("--sale-amount <n>", "Sale amount").
|
|
771
|
+
commissions.command("create").description("Create a commission").requiredOption("--referral-id <id>", "Referral ID").requiredOption("--sale-amount <n>", "Sale amount").option("--sale-amount-currency <code>", "Sale currency (defaults to program currency)").requiredOption("--commission-amount <n>", "Commission amount").option("--commission-currency <code>", "Commission currency").option("--is-subscription", "Mark as subscription commission").option("--status <status>", "Commission status").option("--sales-status <status>", "Sales status").option("--payment-intent-id <id>", "Payment intent ID").option("--hold-period-days <n>", "Hold period in days").option("--created-at <date>", "Creation timestamp (ISO 8601)").action(async function() {
|
|
1494
772
|
const o = opts(this);
|
|
1495
773
|
try {
|
|
1496
774
|
const client = await getClient(o);
|
|
@@ -1504,7 +782,8 @@ function registerCommissionCommands(program2) {
|
|
|
1504
782
|
status: o.status,
|
|
1505
783
|
sales_status: o.salesStatus,
|
|
1506
784
|
payment_intent_id: o.paymentIntentId,
|
|
1507
|
-
hold_period_days: o.holdPeriodDays ? Number(o.holdPeriodDays) : void 0
|
|
785
|
+
hold_period_days: o.holdPeriodDays ? Number(o.holdPeriodDays) : void 0,
|
|
786
|
+
created_at: o.createdAt
|
|
1508
787
|
});
|
|
1509
788
|
output(result, o);
|
|
1510
789
|
} catch (err) {
|
|
@@ -1589,10 +868,61 @@ function registerConfigCommands(program2) {
|
|
|
1589
868
|
});
|
|
1590
869
|
}
|
|
1591
870
|
|
|
871
|
+
// src/commands/conversions.ts
|
|
872
|
+
function registerConversionCommands(program2) {
|
|
873
|
+
const conversions = program2.command("conversions").description("Track and refund conversions");
|
|
874
|
+
conversions.command("create").description("Create a conversion (requires AFFONSO_SIGNING_SECRET)").requiredOption("--sale-amount <n>", "Sale amount").requiredOption("--external-event-id <id>", "Idempotent external event ID").option("--referral-id <id>", "Referral ID").option("--click-id <id>", "Click ID").option("--affonso-id <id>", "Affonso click ID").option("--affonso-referral <id>", "Affonso referral identifier").option("--customer-id <id>", "Customer ID").option("--external-user-id <id>", "External user ID").option("--sale-amount-currency <code>", "Sale currency").option("--product-ids <ids>", "Product IDs (comma-separated)").option("--price-ids <ids>", "Price IDs (comma-separated)").option("--interval <interval>", "Billing interval (monthly, yearly)").option("--is-subscription", "Mark as a subscription").option("--created-at <date>", "Creation timestamp (ISO 8601)").option("--status <status>", "Commission status").option("--sales-status <status>", "Sales status").option("--metadata-json <json|@file>", "Metadata as JSON or @file").action(async function() {
|
|
875
|
+
const o = opts(this);
|
|
876
|
+
try {
|
|
877
|
+
const params = {
|
|
878
|
+
referral_id: o.referralId,
|
|
879
|
+
click_id: o.clickId,
|
|
880
|
+
affonso_id: o.affonsoId,
|
|
881
|
+
affonso_referral: o.affonsoReferral,
|
|
882
|
+
customer_id: o.customerId,
|
|
883
|
+
external_user_id: o.externalUserId,
|
|
884
|
+
sale_amount: Number(o.saleAmount),
|
|
885
|
+
sale_amount_currency: o.saleAmountCurrency,
|
|
886
|
+
product_ids: commaSeparated(o.productIds),
|
|
887
|
+
price_ids: commaSeparated(o.priceIds),
|
|
888
|
+
interval: o.interval,
|
|
889
|
+
is_subscription: o.isSubscription || void 0,
|
|
890
|
+
external_event_id: o.externalEventId,
|
|
891
|
+
created_at: o.createdAt,
|
|
892
|
+
status: o.status,
|
|
893
|
+
sales_status: o.salesStatus,
|
|
894
|
+
metadata: parseJsonObject(o.metadataJson, "--metadata-json")
|
|
895
|
+
};
|
|
896
|
+
const client = await getClient(o);
|
|
897
|
+
output(await client.conversions.create(params), o);
|
|
898
|
+
} catch (err) {
|
|
899
|
+
handleError(err, o.json);
|
|
900
|
+
}
|
|
901
|
+
});
|
|
902
|
+
conversions.command("refund <id>").description("Refund a conversion (requires AFFONSO_SIGNING_SECRET)").option("--amount <n>", "Partial refund amount").option("--currency <code>", "Refund currency").option("--reason <reason>", "Refund reason").option("--external-event-id <id>", "Idempotent external event ID").option("--refunded-at <date>", "Refund timestamp (ISO 8601)").action(async function(id) {
|
|
903
|
+
const o = opts(this);
|
|
904
|
+
try {
|
|
905
|
+
const client = await getClient(o);
|
|
906
|
+
output(
|
|
907
|
+
await client.conversions.refund(id, {
|
|
908
|
+
amount: o.amount === void 0 ? void 0 : Number(o.amount),
|
|
909
|
+
currency: o.currency,
|
|
910
|
+
reason: o.reason,
|
|
911
|
+
external_event_id: o.externalEventId,
|
|
912
|
+
refunded_at: o.refundedAt
|
|
913
|
+
}),
|
|
914
|
+
o
|
|
915
|
+
);
|
|
916
|
+
} catch (err) {
|
|
917
|
+
handleError(err, o.json);
|
|
918
|
+
}
|
|
919
|
+
});
|
|
920
|
+
}
|
|
921
|
+
|
|
1592
922
|
// src/commands/coupons.ts
|
|
1593
923
|
function registerCouponCommands(program2) {
|
|
1594
924
|
const coupons = program2.command("coupons").description("Manage coupons");
|
|
1595
|
-
coupons.command("list").description("List coupons").option("--limit <n>", "Items per page", "50").option("--page <n>", "Page number", "1").option("--affiliate-id <id>", "Filter by affiliate ID").option("--
|
|
925
|
+
coupons.command("list").description("List coupons").option("--limit <n>", "Items per page", "50").option("--page <n>", "Page number", "1").option("--affiliate-id <id>", "Filter by affiliate ID").option("--search <query>", "Search by code").option("--expand <fields>", "Expand fields").option("--sort <field:dir>", "Sort").action(async function() {
|
|
1596
926
|
const o = opts(this);
|
|
1597
927
|
try {
|
|
1598
928
|
const client = await getClient(o);
|
|
@@ -1600,7 +930,6 @@ function registerCouponCommands(program2) {
|
|
|
1600
930
|
limit: Number(o.limit),
|
|
1601
931
|
page: Number(o.page),
|
|
1602
932
|
affiliate_id: o.affiliateId,
|
|
1603
|
-
program_id: o.programId,
|
|
1604
933
|
search: o.search,
|
|
1605
934
|
expand: o.expand,
|
|
1606
935
|
sort: o.sort
|
|
@@ -1642,7 +971,7 @@ function registerCouponCommands(program2) {
|
|
|
1642
971
|
duration: o.duration,
|
|
1643
972
|
duration_in_months: o.durationInMonths ? Number(o.durationInMonths) : void 0,
|
|
1644
973
|
currency: o.currency,
|
|
1645
|
-
product_ids: o.productIds?.split(",")
|
|
974
|
+
product_ids: o.productIds?.split(",").map((id) => id.trim()).filter(Boolean)
|
|
1646
975
|
});
|
|
1647
976
|
output(result, o);
|
|
1648
977
|
} catch (err) {
|
|
@@ -1664,15 +993,20 @@ function registerCouponCommands(program2) {
|
|
|
1664
993
|
// src/commands/embed-tokens.ts
|
|
1665
994
|
function registerEmbedTokenCommands(program2) {
|
|
1666
995
|
const embedTokens = program2.command("embed-tokens").description("Generate embed tokens");
|
|
1667
|
-
embedTokens.command("create").description("Create an embed token").
|
|
996
|
+
embedTokens.command("create").description("Create an embed token").requiredOption("--email <email>", "Partner email").option("--external-user-id <id>", "External user ID").option("--name <name>", "Partner name").option("--image <url>", "Partner image URL").option("--group-id <id>", "Affiliate group ID").option("--metadata-json <json|@file>", "Metadata as JSON or @file").action(async function() {
|
|
1668
997
|
const o = opts(this);
|
|
1669
998
|
try {
|
|
999
|
+
const metadata = parseJsonObject(o.metadataJson, "--metadata-json");
|
|
1670
1000
|
const client = await getClient(o);
|
|
1671
1001
|
const result = await client.embedTokens.create({
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1002
|
+
partner: {
|
|
1003
|
+
email: o.email,
|
|
1004
|
+
name: o.name,
|
|
1005
|
+
image: o.image
|
|
1006
|
+
},
|
|
1007
|
+
groupId: o.groupId,
|
|
1008
|
+
externalUserId: o.externalUserId,
|
|
1009
|
+
metadata
|
|
1676
1010
|
});
|
|
1677
1011
|
output(result, o);
|
|
1678
1012
|
} catch (err) {
|
|
@@ -1681,6 +1015,38 @@ function registerEmbedTokenCommands(program2) {
|
|
|
1681
1015
|
});
|
|
1682
1016
|
}
|
|
1683
1017
|
|
|
1018
|
+
// src/commands/events.ts
|
|
1019
|
+
function registerEventCommands(program2) {
|
|
1020
|
+
program2.command("events").description("Track server-side events").command("create").description("Create a server-side event (requires AFFONSO_SIGNING_SECRET)").requiredOption("--event-name <name>", "Event name").option("--event-type <type>", "Event type (conversion, lead, trial, milestone)").option("--referral-id <id>", "Referral ID").option("--click-id <id>", "Click ID").option("--affonso-id <id>", "Affonso click ID").option("--affonso-referral <id>", "Affonso referral identifier").option("--customer-id <id>", "Customer ID").option("--external-user-id <id>", "External user ID").option("--occurred-at <date>", "Event timestamp (ISO 8601)").option("--external-event-id <id>", "Idempotent external event ID").option("--sale-amount <n>", "Sale amount").option("--sale-amount-currency <code>", "Sale currency").option("--product-ids <ids>", "Product IDs (comma-separated)").option("--price-ids <ids>", "Price IDs (comma-separated)").option("--interval <interval>", "Billing interval (monthly, yearly)").option("--is-subscription", "Mark as a subscription").option("--metadata-json <json|@file>", "Metadata as JSON or @file").action(async function() {
|
|
1021
|
+
const o = opts(this);
|
|
1022
|
+
try {
|
|
1023
|
+
const params = {
|
|
1024
|
+
event_name: o.eventName,
|
|
1025
|
+
event_type: o.eventType,
|
|
1026
|
+
referral_id: o.referralId,
|
|
1027
|
+
click_id: o.clickId,
|
|
1028
|
+
affonso_id: o.affonsoId,
|
|
1029
|
+
affonso_referral: o.affonsoReferral,
|
|
1030
|
+
customer_id: o.customerId,
|
|
1031
|
+
external_user_id: o.externalUserId,
|
|
1032
|
+
occurred_at: o.occurredAt,
|
|
1033
|
+
external_event_id: o.externalEventId,
|
|
1034
|
+
sale_amount: o.saleAmount === void 0 ? void 0 : Number(o.saleAmount),
|
|
1035
|
+
sale_amount_currency: o.saleAmountCurrency,
|
|
1036
|
+
product_ids: commaSeparated(o.productIds),
|
|
1037
|
+
price_ids: commaSeparated(o.priceIds),
|
|
1038
|
+
interval: o.interval,
|
|
1039
|
+
is_subscription: o.isSubscription || void 0,
|
|
1040
|
+
metadata: parseJsonObject(o.metadataJson, "--metadata-json")
|
|
1041
|
+
};
|
|
1042
|
+
const client = await getClient(o);
|
|
1043
|
+
output(await client.events.create(params), o);
|
|
1044
|
+
} catch (err) {
|
|
1045
|
+
handleError(err, o.json);
|
|
1046
|
+
}
|
|
1047
|
+
});
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1684
1050
|
// src/commands/login.ts
|
|
1685
1051
|
function registerLoginCommand(program2) {
|
|
1686
1052
|
program2.command("login").description("Log in via browser (OAuth 2.1)").action(async function() {
|
|
@@ -1730,27 +1096,26 @@ function registerLogoutCommand(program2) {
|
|
|
1730
1096
|
}
|
|
1731
1097
|
|
|
1732
1098
|
// src/commands/marketplace.ts
|
|
1099
|
+
var import_sdk3 = require("@affonso/sdk");
|
|
1733
1100
|
function registerMarketplaceCommands(program2) {
|
|
1734
1101
|
const marketplace = program2.command("marketplace").description("Browse the affiliate marketplace (public, no auth required)");
|
|
1735
|
-
marketplace.command("list").description("List marketplace programs").option("--limit <n>", "Items per page", "50").option("--page <n>", "Page number", "1").option("--category <cat>", "Filter by category").
|
|
1102
|
+
marketplace.command("list").description("List marketplace programs").option("--limit <n>", "Items per page", "50").option("--page <n>", "Page number", "1").option("--category <cat>", "Filter by category").action(async function() {
|
|
1736
1103
|
const o = opts(this);
|
|
1737
1104
|
try {
|
|
1738
1105
|
const baseUrl = resolveBaseUrl(o.baseUrl);
|
|
1739
|
-
const client = new Affonso("public", { baseUrl });
|
|
1106
|
+
const client = new import_sdk3.Affonso("public", { baseUrl });
|
|
1740
1107
|
const result = await client.marketplace.list({
|
|
1741
1108
|
limit: Number(o.limit),
|
|
1742
1109
|
page: Number(o.page),
|
|
1743
|
-
category: o.category
|
|
1744
|
-
search: o.search,
|
|
1745
|
-
sort: o.sort
|
|
1110
|
+
category: o.category
|
|
1746
1111
|
});
|
|
1747
1112
|
output(result, o, [
|
|
1748
1113
|
"id",
|
|
1749
1114
|
"name",
|
|
1750
|
-
"
|
|
1751
|
-
"
|
|
1752
|
-
"
|
|
1753
|
-
"
|
|
1115
|
+
"marketplace_joined_at",
|
|
1116
|
+
"access_mode",
|
|
1117
|
+
"currency",
|
|
1118
|
+
"website_url"
|
|
1754
1119
|
]);
|
|
1755
1120
|
} catch (err) {
|
|
1756
1121
|
handleError(err, o.json);
|
|
@@ -1760,7 +1125,7 @@ function registerMarketplaceCommands(program2) {
|
|
|
1760
1125
|
const o = opts(this);
|
|
1761
1126
|
try {
|
|
1762
1127
|
const baseUrl = resolveBaseUrl(o.baseUrl);
|
|
1763
|
-
const client = new Affonso("public", { baseUrl });
|
|
1128
|
+
const client = new import_sdk3.Affonso("public", { baseUrl });
|
|
1764
1129
|
const result = await client.marketplace.retrieve(id);
|
|
1765
1130
|
output(result, o);
|
|
1766
1131
|
} catch (err) {
|
|
@@ -1769,6 +1134,69 @@ function registerMarketplaceCommands(program2) {
|
|
|
1769
1134
|
});
|
|
1770
1135
|
}
|
|
1771
1136
|
|
|
1137
|
+
// src/commands/onboarding-form.ts
|
|
1138
|
+
function questions(value) {
|
|
1139
|
+
const parsed = parseJson(value, "--questions-json");
|
|
1140
|
+
if (!Array.isArray(parsed)) throw new Error("--questions-json must contain a JSON array.");
|
|
1141
|
+
return parsed;
|
|
1142
|
+
}
|
|
1143
|
+
function registerOnboardingFormCommands(program2) {
|
|
1144
|
+
const form = program2.command("onboarding-form").description("Manage the onboarding form");
|
|
1145
|
+
form.command("get").description("Get the onboarding form").action(async function() {
|
|
1146
|
+
const o = opts(this);
|
|
1147
|
+
try {
|
|
1148
|
+
const client = await getClient(o);
|
|
1149
|
+
output(await client.onboardingForm.retrieve(), o);
|
|
1150
|
+
} catch (err) {
|
|
1151
|
+
handleError(err, o.json);
|
|
1152
|
+
}
|
|
1153
|
+
});
|
|
1154
|
+
form.command("create").description("Create the onboarding form").requiredOption("--name <name>", "Form name").requiredOption("--questions-json <json|@file>", "Questions array as JSON or @file").option("--description <text>", "Form description").action(async function() {
|
|
1155
|
+
const o = opts(this);
|
|
1156
|
+
try {
|
|
1157
|
+
const parsedQuestions = questions(o.questionsJson);
|
|
1158
|
+
const client = await getClient(o);
|
|
1159
|
+
output(
|
|
1160
|
+
await client.onboardingForm.create({
|
|
1161
|
+
name: o.name,
|
|
1162
|
+
description: o.description,
|
|
1163
|
+
questions: parsedQuestions
|
|
1164
|
+
}),
|
|
1165
|
+
o
|
|
1166
|
+
);
|
|
1167
|
+
} catch (err) {
|
|
1168
|
+
handleError(err, o.json);
|
|
1169
|
+
}
|
|
1170
|
+
});
|
|
1171
|
+
form.command("update").description("Update the onboarding form").option("--name <name>", "Form name").option("--description <text>", "Form description").option("--questions-json <json|@file>", "Questions array as JSON or @file").action(async function() {
|
|
1172
|
+
const o = opts(this);
|
|
1173
|
+
try {
|
|
1174
|
+
const parsedQuestions = o.questionsJson === void 0 ? void 0 : questions(o.questionsJson);
|
|
1175
|
+
const client = await getClient(o);
|
|
1176
|
+
output(
|
|
1177
|
+
await client.onboardingForm.update({
|
|
1178
|
+
name: o.name,
|
|
1179
|
+
description: o.description,
|
|
1180
|
+
questions: parsedQuestions
|
|
1181
|
+
}),
|
|
1182
|
+
o
|
|
1183
|
+
);
|
|
1184
|
+
} catch (err) {
|
|
1185
|
+
handleError(err, o.json);
|
|
1186
|
+
}
|
|
1187
|
+
});
|
|
1188
|
+
form.command("delete").description("Delete the onboarding form").action(async function() {
|
|
1189
|
+
const o = opts(this);
|
|
1190
|
+
try {
|
|
1191
|
+
const client = await getClient(o);
|
|
1192
|
+
const result = await client.onboardingForm.del();
|
|
1193
|
+
outputSuccess(result.message ?? "Onboarding form deleted.", o);
|
|
1194
|
+
} catch (err) {
|
|
1195
|
+
handleError(err, o.json);
|
|
1196
|
+
}
|
|
1197
|
+
});
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1772
1200
|
// src/commands/payouts.ts
|
|
1773
1201
|
function registerPayoutCommands(program2) {
|
|
1774
1202
|
const payouts = program2.command("payouts").description("Manage payouts");
|
|
@@ -1839,20 +1267,24 @@ function registerProgramCommands(program2) {
|
|
|
1839
1267
|
handleError(err, o.json);
|
|
1840
1268
|
}
|
|
1841
1269
|
});
|
|
1842
|
-
prog.command("update").description("Update program settings").option("--name <name>", "Program name").option("--tagline <text>", "Tagline").option("--
|
|
1270
|
+
prog.command("update").description("Update program settings").option("--name <name>", "Program name").option("--tagline <text>", "Tagline").option("--description <text>", "Description").option("--website-url <url>", "Website URL").option("--logo-url <url>", "Logo URL").option("--access-mode <mode>", "Access mode: PUBLIC, PRIVATE, or INVITE").option("--affiliate-links-enabled", "Enable affiliate links").option("--no-affiliate-links-enabled", "Disable affiliate links").option(
|
|
1271
|
+
"--customer-information-visibility <visibility>",
|
|
1272
|
+
"Customer data visibility (HIDDEN, NAME, EMAIL, NAME_AND_EMAIL)"
|
|
1273
|
+
).action(async function() {
|
|
1843
1274
|
const o = opts(this);
|
|
1844
1275
|
try {
|
|
1845
1276
|
const client = await getClient(o);
|
|
1846
1277
|
const params = {};
|
|
1847
1278
|
if (o.name !== void 0) params.name = o.name;
|
|
1848
1279
|
if (o.tagline !== void 0) params.tagline = o.tagline;
|
|
1849
|
-
if (o.category !== void 0) params.category = o.category;
|
|
1850
1280
|
if (o.description !== void 0) params.description = o.description;
|
|
1851
1281
|
if (o.websiteUrl !== void 0) params.website_url = o.websiteUrl;
|
|
1852
1282
|
if (o.logoUrl !== void 0) params.logo_url = o.logoUrl;
|
|
1853
1283
|
if (o.accessMode !== void 0) params.access_mode = o.accessMode;
|
|
1854
1284
|
if (o.affiliateLinksEnabled !== void 0)
|
|
1855
1285
|
params.affiliate_links_enabled = o.affiliateLinksEnabled;
|
|
1286
|
+
if (o.customerInformationVisibility !== void 0)
|
|
1287
|
+
params.customer_information_visibility = o.customerInformationVisibility;
|
|
1856
1288
|
const result = await client.program.update(params);
|
|
1857
1289
|
output(result, o);
|
|
1858
1290
|
} catch (err) {
|
|
@@ -1880,7 +1312,10 @@ function registerPaymentTerms(prog) {
|
|
|
1880
1312
|
handleError(err, o.json);
|
|
1881
1313
|
}
|
|
1882
1314
|
});
|
|
1883
|
-
pt.command("update").description("Update payment terms").option("--commission-type <type>", "Commission type (
|
|
1315
|
+
pt.command("update").description("Update payment terms").option("--commission-type <type>", "Commission type (PERCENTAGE, FIXED, CREDITS)").option("--commission-rate <n>", "Commission rate").option("--commission-duration <dur>", "Duration (lifetime, time_limited, payment_limited)").option("--commissions-limit <n>", "Commission duration limit").option("--commissions-hold-days <n>", "Commission hold period in days").option("--payment-threshold <n>", "Minimum payout threshold").option("--payment-frequency <freq>", "Payment frequency (weekly, monthly)").option("--payment-methods <methods>", "Payment methods (comma-separated)").option("--custom-payment-terms <text>", "Custom payment terms").option("--cookie-lifetime <days>", "Cookie lifetime in days").option("--auto-payout", "Enable auto payout").option("--no-auto-payout", "Disable auto payout").option(
|
|
1316
|
+
"--invoice-rule <rule>",
|
|
1317
|
+
"Invoice rule (NONE, OWNER_PROVIDES, AFFILIATE_PROVIDES, SELF_BILLING)"
|
|
1318
|
+
).option("--invoice-prefix <prefix>", "Invoice number prefix").option("--require-tax-forms", "Require tax forms").option("--no-require-tax-forms", "Do not require tax forms").option("--owner-company-name <name>", "Owner company name").option("--owner-address-line-1 <value>", "Owner address line 1").option("--owner-address-line-2 <value>", "Owner address line 2").option("--owner-city <city>", "Owner city").option("--owner-postal-code <code>", "Owner postal code").option("--owner-country <code>", "Owner country code").option("--owner-vat-id <id>", "Owner VAT ID").option("--owner-vat-rate <n>", "Owner VAT rate").action(async function() {
|
|
1884
1319
|
const o = opts(this);
|
|
1885
1320
|
try {
|
|
1886
1321
|
const client = await getClient(o);
|
|
@@ -1888,13 +1323,27 @@ function registerPaymentTerms(prog) {
|
|
|
1888
1323
|
if (o.commissionType !== void 0) params.commission_type = o.commissionType;
|
|
1889
1324
|
if (o.commissionRate !== void 0) params.commission_rate = Number(o.commissionRate);
|
|
1890
1325
|
if (o.commissionDuration !== void 0) params.commission_duration = o.commissionDuration;
|
|
1891
|
-
if (o.
|
|
1892
|
-
|
|
1326
|
+
if (o.commissionsLimit !== void 0) params.commissions_limit = Number(o.commissionsLimit);
|
|
1327
|
+
if (o.commissionsHoldDays !== void 0)
|
|
1328
|
+
params.commissions_hold_days = Number(o.commissionsHoldDays);
|
|
1893
1329
|
if (o.paymentThreshold !== void 0) params.payment_threshold = Number(o.paymentThreshold);
|
|
1894
1330
|
if (o.paymentFrequency !== void 0) params.payment_frequency = o.paymentFrequency;
|
|
1331
|
+
if (o.paymentMethods !== void 0)
|
|
1332
|
+
params.payment_methods = commaSeparated(o.paymentMethods) ?? [];
|
|
1333
|
+
if (o.customPaymentTerms !== void 0) params.custom_payment_terms = o.customPaymentTerms;
|
|
1895
1334
|
if (o.cookieLifetime !== void 0) params.cookie_lifetime = Number(o.cookieLifetime);
|
|
1896
1335
|
if (o.autoPayout !== void 0) params.auto_payout = o.autoPayout;
|
|
1897
|
-
if (o.
|
|
1336
|
+
if (o.invoiceRule !== void 0) params.invoice_rule = o.invoiceRule;
|
|
1337
|
+
if (o.invoicePrefix !== void 0) params.invoice_prefix = o.invoicePrefix;
|
|
1338
|
+
if (o.requireTaxForms !== void 0) params.require_tax_forms = o.requireTaxForms;
|
|
1339
|
+
if (o.ownerCompanyName !== void 0) params.owner_company_name = o.ownerCompanyName;
|
|
1340
|
+
if (o.ownerAddressLine1 !== void 0) params.owner_address_line_1 = o.ownerAddressLine1;
|
|
1341
|
+
if (o.ownerAddressLine2 !== void 0) params.owner_address_line_2 = o.ownerAddressLine2;
|
|
1342
|
+
if (o.ownerCity !== void 0) params.owner_city = o.ownerCity;
|
|
1343
|
+
if (o.ownerPostalCode !== void 0) params.owner_postal_code = o.ownerPostalCode;
|
|
1344
|
+
if (o.ownerCountry !== void 0) params.owner_country = o.ownerCountry;
|
|
1345
|
+
if (o.ownerVatId !== void 0) params.owner_vat_id = o.ownerVatId;
|
|
1346
|
+
if (o.ownerVatRate !== void 0) params.owner_vat_rate = Number(o.ownerVatRate);
|
|
1898
1347
|
const result = await client.program.paymentTerms.update(params);
|
|
1899
1348
|
output(result, o);
|
|
1900
1349
|
} catch (err) {
|
|
@@ -1914,17 +1363,30 @@ function registerTracking(prog) {
|
|
|
1914
1363
|
handleError(err, o.json);
|
|
1915
1364
|
}
|
|
1916
1365
|
});
|
|
1917
|
-
tracking.command("update").description("Update tracking settings").option("--default-referral-parameter <param>", "Default referral parameter").option("--enabled-referral-parameters <params>", "Enabled parameters (comma-separated)").option("--
|
|
1366
|
+
tracking.command("update").description("Update tracking settings").option("--default-referral-parameter <param>", "Default referral parameter").option("--enabled-referral-parameters <params>", "Enabled parameters (comma-separated)").option("--email-tracking-enabled", "Enable email tracking").option("--no-email-tracking-enabled", "Disable email tracking").option("--name-tracking-enabled", "Enable name tracking").option("--no-name-tracking-enabled", "Disable name tracking").option("--postbacks-enabled", "Enable postbacks").option("--no-postbacks-enabled", "Disable postbacks").option("--append-affonso-id-enabled", "Append the Affonso click ID").option("--no-append-affonso-id-enabled", "Do not append the Affonso click ID").option("--tracking-template-enabled", "Enable the tracking template").option("--no-tracking-template-enabled", "Disable the tracking template").option("--tracking-template-json <json|@file>", "Tracking template array as JSON or @file").action(async function() {
|
|
1918
1367
|
const o = opts(this);
|
|
1919
1368
|
try {
|
|
1920
|
-
const client = await getClient(o);
|
|
1921
1369
|
const params = {};
|
|
1922
1370
|
if (o.defaultReferralParameter !== void 0)
|
|
1923
1371
|
params.default_referral_parameter = o.defaultReferralParameter;
|
|
1924
1372
|
if (o.enabledReferralParameters !== void 0)
|
|
1925
|
-
params.enabled_referral_parameters = o.enabledReferralParameters
|
|
1926
|
-
if (o.
|
|
1927
|
-
|
|
1373
|
+
params.enabled_referral_parameters = commaSeparated(o.enabledReferralParameters) ?? [];
|
|
1374
|
+
if (o.emailTrackingEnabled !== void 0)
|
|
1375
|
+
params.email_tracking_enabled = o.emailTrackingEnabled;
|
|
1376
|
+
if (o.nameTrackingEnabled !== void 0)
|
|
1377
|
+
params.name_tracking_enabled = o.nameTrackingEnabled;
|
|
1378
|
+
if (o.postbacksEnabled !== void 0) params.postbacks_enabled = o.postbacksEnabled;
|
|
1379
|
+
if (o.appendAffonsoIdEnabled !== void 0)
|
|
1380
|
+
params.append_affonso_id_enabled = o.appendAffonsoIdEnabled;
|
|
1381
|
+
if (o.trackingTemplateEnabled !== void 0)
|
|
1382
|
+
params.tracking_template_enabled = o.trackingTemplateEnabled;
|
|
1383
|
+
if (o.trackingTemplateJson !== void 0) {
|
|
1384
|
+
const template = parseJson(o.trackingTemplateJson, "--tracking-template-json");
|
|
1385
|
+
if (!Array.isArray(template))
|
|
1386
|
+
throw new Error("--tracking-template-json must contain a JSON array.");
|
|
1387
|
+
params.tracking_template = template;
|
|
1388
|
+
}
|
|
1389
|
+
const client = await getClient(o);
|
|
1928
1390
|
const result = await client.program.tracking.update(params);
|
|
1929
1391
|
output(result, o);
|
|
1930
1392
|
} catch (err) {
|
|
@@ -1944,7 +1406,7 @@ function registerRestrictions(prog) {
|
|
|
1944
1406
|
handleError(err, o.json);
|
|
1945
1407
|
}
|
|
1946
1408
|
});
|
|
1947
|
-
restrictions.command("update").description("Update restrictions").option("--websites", "Allow websites").option("--no-websites", "Disallow websites").option("--social-marketing", "Allow social marketing").option("--no-social-marketing", "Disallow social marketing").option("--organic-social", "Allow organic social").option("--no-organic-social", "Disallow organic social").option("--email-marketing", "Allow email marketing").option("--no-email-marketing", "Disallow email marketing").option("--
|
|
1409
|
+
restrictions.command("update").description("Update restrictions").option("--websites", "Allow websites").option("--no-websites", "Disallow websites").option("--social-marketing", "Allow social marketing").option("--no-social-marketing", "Disallow social marketing").option("--organic-social", "Allow organic social").option("--no-organic-social", "Disallow organic social").option("--email-marketing", "Allow email marketing").option("--no-email-marketing", "Disallow email marketing").option("--mobile-traffic", "Allow mobile traffic").option("--no-mobile-traffic", "Disallow mobile traffic").option("--search-engine-marketing", "Allow search engine marketing").option("--no-search-engine-marketing", "Disallow search engine marketing").option("--organic-search", "Allow organic search").option("--no-organic-search", "Disallow organic search").option("--rebrokering", "Allow rebrokering").option("--no-rebrokering", "Disallow rebrokering").option("--incent", "Allow incentivized traffic").option("--no-incent", "Disallow incentivized traffic").option("--brand-bidding", "Allow brand bidding").option("--no-brand-bidding", "Disallow brand bidding").option("--additional-restrictions <text>", "Additional restriction text").action(async function() {
|
|
1948
1410
|
const o = opts(this);
|
|
1949
1411
|
try {
|
|
1950
1412
|
const client = await getClient(o);
|
|
@@ -1954,17 +1416,19 @@ function registerRestrictions(prog) {
|
|
|
1954
1416
|
["socialMarketing", "social_marketing"],
|
|
1955
1417
|
["organicSocial", "organic_social"],
|
|
1956
1418
|
["emailMarketing", "email_marketing"],
|
|
1957
|
-
["
|
|
1958
|
-
["
|
|
1959
|
-
["
|
|
1960
|
-
["
|
|
1961
|
-
["
|
|
1962
|
-
["
|
|
1419
|
+
["mobileTraffic", "mobile_traffic"],
|
|
1420
|
+
["searchEngineMarketing", "search_engine_marketing"],
|
|
1421
|
+
["organicSearch", "organic_search"],
|
|
1422
|
+
["rebrokering", "rebrokering"],
|
|
1423
|
+
["incent", "incent"],
|
|
1424
|
+
["brandBidding", "brand_bidding"]
|
|
1963
1425
|
];
|
|
1964
1426
|
for (const [camel, snake] of fieldMap) {
|
|
1965
1427
|
const val = o[camel];
|
|
1966
1428
|
if (val !== void 0) params[snake] = val;
|
|
1967
1429
|
}
|
|
1430
|
+
if (o.additionalRestrictions !== void 0)
|
|
1431
|
+
params.additional_restrictions = o.additionalRestrictions;
|
|
1968
1432
|
const result = await client.program.restrictions.update(params);
|
|
1969
1433
|
output(result, o);
|
|
1970
1434
|
} catch (err) {
|
|
@@ -1984,16 +1448,36 @@ function registerFraudRules(prog) {
|
|
|
1984
1448
|
handleError(err, o.json);
|
|
1985
1449
|
}
|
|
1986
1450
|
});
|
|
1987
|
-
fraud.command("update").description("Update fraud rules").option("--self-referral <mode>", "Self-referral mode (off, detect, block)").option("--duplicate-
|
|
1451
|
+
fraud.command("update").description("Update fraud rules").option("--self-referral-mode <mode>", "Self-referral mode (off, detect, block)").option("--cross-program-ban-mode <mode>", "Cross-program ban mode").option("--duplicate-payout-mode <mode>", "Duplicate payout mode").option("--suspicious-email-mode <mode>", "Suspicious email mode").option("--banned-referral-mode <mode>", "Banned referral mode").option("--paid-traffic-mode <mode>", "Paid traffic mode").option("--blocked-country-mode <mode>", "Blocked country mode").option("--banned-referral-config-json <json|@file>", "Banned referral config").option("--paid-traffic-config-json <json|@file>", "Paid traffic config").option("--blocked-country-config-json <json|@file>", "Blocked country config").action(async function() {
|
|
1988
1452
|
const o = opts(this);
|
|
1989
1453
|
try {
|
|
1990
|
-
const client = await getClient(o);
|
|
1991
1454
|
const params = {};
|
|
1992
|
-
if (o.
|
|
1993
|
-
if (o.
|
|
1994
|
-
|
|
1995
|
-
if (o.
|
|
1996
|
-
params.
|
|
1455
|
+
if (o.selfReferralMode !== void 0) params.self_referral_mode = o.selfReferralMode;
|
|
1456
|
+
if (o.crossProgramBanMode !== void 0)
|
|
1457
|
+
params.cross_program_ban_mode = o.crossProgramBanMode;
|
|
1458
|
+
if (o.duplicatePayoutMode !== void 0)
|
|
1459
|
+
params.duplicate_payout_mode = o.duplicatePayoutMode;
|
|
1460
|
+
if (o.suspiciousEmailMode !== void 0)
|
|
1461
|
+
params.suspicious_email_mode = o.suspiciousEmailMode;
|
|
1462
|
+
if (o.bannedReferralMode !== void 0) params.banned_referral_mode = o.bannedReferralMode;
|
|
1463
|
+
if (o.paidTrafficMode !== void 0) params.paid_traffic_mode = o.paidTrafficMode;
|
|
1464
|
+
if (o.blockedCountryMode !== void 0) params.blocked_country_mode = o.blockedCountryMode;
|
|
1465
|
+
if (o.bannedReferralConfigJson !== void 0)
|
|
1466
|
+
params.banned_referral_config = parseJsonObject(
|
|
1467
|
+
o.bannedReferralConfigJson,
|
|
1468
|
+
"--banned-referral-config-json"
|
|
1469
|
+
);
|
|
1470
|
+
if (o.paidTrafficConfigJson !== void 0)
|
|
1471
|
+
params.paid_traffic_config = parseJsonObject(
|
|
1472
|
+
o.paidTrafficConfigJson,
|
|
1473
|
+
"--paid-traffic-config-json"
|
|
1474
|
+
);
|
|
1475
|
+
if (o.blockedCountryConfigJson !== void 0)
|
|
1476
|
+
params.blocked_country_config = parseJsonObject(
|
|
1477
|
+
o.blockedCountryConfigJson,
|
|
1478
|
+
"--blocked-country-config-json"
|
|
1479
|
+
);
|
|
1480
|
+
const client = await getClient(o);
|
|
1997
1481
|
const result = await client.program.fraudRules.update(params);
|
|
1998
1482
|
output(result, o);
|
|
1999
1483
|
} catch (err) {
|
|
@@ -2013,20 +1497,29 @@ function registerPortal(prog) {
|
|
|
2013
1497
|
handleError(err, o.json);
|
|
2014
1498
|
}
|
|
2015
1499
|
});
|
|
2016
|
-
portal.command("update").description("Update portal settings").option("--primary-color <color>", "Primary color (hex)").option("--
|
|
1500
|
+
portal.command("update").description("Update portal settings").option("--single-program-portal", "Enable the single-program portal").option("--no-single-program-portal", "Disable the single-program portal").option("--hide-branding", "Hide Affonso branding").option("--no-hide-branding", "Show Affonso branding").option("--hide-details", "Hide program details").option("--no-hide-details", "Show program details").option("--primary-color <color>", "Primary color (hex)").option("--secondary-color <color>", "Secondary color (hex)").option("--show-leaderboard", "Show the leaderboard").option("--no-show-leaderboard", "Hide the leaderboard").option("--terms-conditions-status", "Enable terms and conditions").option("--no-terms-conditions-status", "Disable terms and conditions").option("--terms-conditions-value <value>", "Terms text or URL").option("--privacy-policy-status", "Enable the privacy policy").option("--no-privacy-policy-status", "Disable the privacy policy").option("--privacy-policy-value <value>", "Privacy policy text or URL").option("--support-email-status", "Show the support email").option("--no-support-email-status", "Hide the support email").option("--support-email-value <email>", "Support email").option("--custom-texts-json <json|@file>", "Custom texts as JSON or @file").action(async function() {
|
|
2017
1501
|
const o = opts(this);
|
|
2018
1502
|
try {
|
|
2019
|
-
const client = await getClient(o);
|
|
2020
1503
|
const params = {};
|
|
1504
|
+
if (o.singleProgramPortal !== void 0)
|
|
1505
|
+
params.single_program_portal = o.singleProgramPortal;
|
|
1506
|
+
if (o.hideBranding !== void 0) params.hide_branding = o.hideBranding;
|
|
1507
|
+
if (o.hideDetails !== void 0) params.hide_details = o.hideDetails;
|
|
2021
1508
|
if (o.primaryColor !== void 0) params.primary_color = o.primaryColor;
|
|
2022
|
-
if (o.
|
|
2023
|
-
if (o.
|
|
2024
|
-
if (o.
|
|
2025
|
-
|
|
2026
|
-
if (o.
|
|
2027
|
-
|
|
2028
|
-
if (o.
|
|
2029
|
-
|
|
1509
|
+
if (o.secondaryColor !== void 0) params.secondary_color = o.secondaryColor;
|
|
1510
|
+
if (o.showLeaderboard !== void 0) params.show_leaderboard = o.showLeaderboard;
|
|
1511
|
+
if (o.termsConditionsStatus !== void 0)
|
|
1512
|
+
params.terms_conditions_status = o.termsConditionsStatus;
|
|
1513
|
+
if (o.termsConditionsValue !== void 0)
|
|
1514
|
+
params.terms_conditions_value = o.termsConditionsValue;
|
|
1515
|
+
if (o.privacyPolicyStatus !== void 0)
|
|
1516
|
+
params.privacy_policy_status = o.privacyPolicyStatus;
|
|
1517
|
+
if (o.privacyPolicyValue !== void 0) params.privacy_policy_value = o.privacyPolicyValue;
|
|
1518
|
+
if (o.supportEmailStatus !== void 0) params.support_email_status = o.supportEmailStatus;
|
|
1519
|
+
if (o.supportEmailValue !== void 0) params.support_email_value = o.supportEmailValue;
|
|
1520
|
+
if (o.customTextsJson !== void 0)
|
|
1521
|
+
params.custom_texts = parseJsonObject(o.customTextsJson, "--custom-texts-json");
|
|
1522
|
+
const client = await getClient(o);
|
|
2030
1523
|
const result = await client.program.portal.update(params);
|
|
2031
1524
|
output(result, o);
|
|
2032
1525
|
} catch (err) {
|
|
@@ -2041,18 +1534,19 @@ function registerNotifications(prog) {
|
|
|
2041
1534
|
try {
|
|
2042
1535
|
const client = await getClient(o);
|
|
2043
1536
|
const result = await client.program.notifications.list();
|
|
2044
|
-
output(result, o, ["
|
|
1537
|
+
output(result, o, ["email_type_id", "is_active", "custom_subject", "custom_body"]);
|
|
2045
1538
|
} catch (err) {
|
|
2046
1539
|
handleError(err, o.json);
|
|
2047
1540
|
}
|
|
2048
1541
|
});
|
|
2049
|
-
notifications.command("update <id>").description("Update a notification setting").option("--subject <text>", "
|
|
1542
|
+
notifications.command("update <id>").description("Update a notification setting").option("--custom-subject <text>", "Custom email subject").option("--custom-body <text>", "Custom email body").option("--active", "Enable notification").option("--no-active", "Disable notification").action(async function(id) {
|
|
2050
1543
|
const o = opts(this);
|
|
2051
1544
|
try {
|
|
2052
1545
|
const client = await getClient(o);
|
|
2053
1546
|
const params = {};
|
|
2054
|
-
if (o.
|
|
2055
|
-
if (o.
|
|
1547
|
+
if (o.customSubject !== void 0) params.custom_subject = o.customSubject;
|
|
1548
|
+
if (o.customBody !== void 0) params.custom_body = o.customBody;
|
|
1549
|
+
if (o.active !== void 0) params.is_active = o.active;
|
|
2056
1550
|
const result = await client.program.notifications.update(id, params);
|
|
2057
1551
|
output(result, o);
|
|
2058
1552
|
} catch (err) {
|
|
@@ -2073,8 +1567,8 @@ function registerGroups(prog) {
|
|
|
2073
1567
|
"id",
|
|
2074
1568
|
"name",
|
|
2075
1569
|
"description",
|
|
1570
|
+
"custom_website_url",
|
|
2076
1571
|
"is_default",
|
|
2077
|
-
"affiliate_count",
|
|
2078
1572
|
"created_at"
|
|
2079
1573
|
]);
|
|
2080
1574
|
} catch (err) {
|
|
@@ -2093,13 +1587,14 @@ function registerGroups(prog) {
|
|
|
2093
1587
|
handleError(err, o.json);
|
|
2094
1588
|
}
|
|
2095
1589
|
});
|
|
2096
|
-
groups.command("create").description("Create a group").requiredOption("--name <name>", "Group name").option("--description <text>", "Group description").option("--is-default", "Set as default group").action(async function() {
|
|
1590
|
+
groups.command("create").description("Create a group").requiredOption("--name <name>", "Group name").option("--description <text>", "Group description").option("--custom-website-url <url>", "Custom website URL").option("--is-default", "Set as default group").action(async function() {
|
|
2097
1591
|
const o = opts(this);
|
|
2098
1592
|
try {
|
|
2099
1593
|
const client = await getClient(o);
|
|
2100
1594
|
const result = await client.program.groups.create({
|
|
2101
1595
|
name: o.name,
|
|
2102
1596
|
description: o.description,
|
|
1597
|
+
custom_website_url: o.customWebsiteUrl,
|
|
2103
1598
|
is_default: o.isDefault
|
|
2104
1599
|
});
|
|
2105
1600
|
output(result, o);
|
|
@@ -2107,13 +1602,14 @@ function registerGroups(prog) {
|
|
|
2107
1602
|
handleError(err, o.json);
|
|
2108
1603
|
}
|
|
2109
1604
|
});
|
|
2110
|
-
groups.command("update <id>").description("Update a group").option("--name <name>", "Group name").option("--description <text>", "Group description").option("--is-default", "Set as default group").option("--no-is-default", "Unset as default group").action(async function(id) {
|
|
1605
|
+
groups.command("update <id>").description("Update a group").option("--name <name>", "Group name").option("--description <text>", "Group description").option("--custom-website-url <url>", "Custom website URL").option("--is-default", "Set as default group").option("--no-is-default", "Unset as default group").action(async function(id) {
|
|
2111
1606
|
const o = opts(this);
|
|
2112
1607
|
try {
|
|
2113
1608
|
const client = await getClient(o);
|
|
2114
1609
|
const params = {};
|
|
2115
1610
|
if (o.name !== void 0) params.name = o.name;
|
|
2116
1611
|
if (o.description !== void 0) params.description = o.description;
|
|
1612
|
+
if (o.customWebsiteUrl !== void 0) params.custom_website_url = o.customWebsiteUrl;
|
|
2117
1613
|
if (o.isDefault !== void 0) params.is_default = o.isDefault;
|
|
2118
1614
|
const result = await client.program.groups.update(id, params);
|
|
2119
1615
|
output(result, o);
|
|
@@ -2134,17 +1630,16 @@ function registerGroups(prog) {
|
|
|
2134
1630
|
}
|
|
2135
1631
|
function registerCreatives(prog) {
|
|
2136
1632
|
const creatives = prog.command("creatives").description("Manage creatives");
|
|
2137
|
-
creatives.command("list").description("List creatives").option("--limit <n>", "Items per page", "50").option("--page <n>", "Page number", "1").option("--
|
|
1633
|
+
creatives.command("list").description("List creatives").option("--limit <n>", "Items per page", "50").option("--page <n>", "Page number", "1").option("--category <category>", "Filter by category").action(async function() {
|
|
2138
1634
|
const o = opts(this);
|
|
2139
1635
|
try {
|
|
2140
1636
|
const client = await getClient(o);
|
|
2141
1637
|
const result = await client.program.creatives.list({
|
|
2142
1638
|
limit: Number(o.limit),
|
|
2143
1639
|
page: Number(o.page),
|
|
2144
|
-
|
|
2145
|
-
search: o.search
|
|
1640
|
+
category: o.category
|
|
2146
1641
|
});
|
|
2147
|
-
output(result, o, ["id", "name", "
|
|
1642
|
+
output(result, o, ["id", "name", "category", "url", "created_at"]);
|
|
2148
1643
|
} catch (err) {
|
|
2149
1644
|
handleError(err, o.json);
|
|
2150
1645
|
}
|
|
@@ -2159,36 +1654,48 @@ function registerCreatives(prog) {
|
|
|
2159
1654
|
handleError(err, o.json);
|
|
2160
1655
|
}
|
|
2161
1656
|
});
|
|
2162
|
-
creatives.command("create").description("Create a creative").
|
|
1657
|
+
creatives.command("create").description("Create a creative").option("--name <name>", "Creative name").option("--category <category>", "Creative category").option("--subcategory <subcategory>", "Creative subcategory").option("--description <text>", "Description").option("--url <url>", "URL").option("--content <content>", "Text or embed content").option("--tags <tags>", "Tags (comma-separated)").option("--width <n>", "Width in pixels").option("--height <n>", "Height in pixels").option("--usage-notes <text>", "Usage notes").option("--restrictions <text>", "Usage restrictions").action(async function() {
|
|
2163
1658
|
const o = opts(this);
|
|
2164
1659
|
try {
|
|
2165
1660
|
const client = await getClient(o);
|
|
2166
|
-
|
|
1661
|
+
if (o.width === void 0 !== (o.height === void 0))
|
|
1662
|
+
throw new Error("--width and --height must be provided together.");
|
|
1663
|
+
const params = {
|
|
2167
1664
|
name: o.name,
|
|
2168
|
-
|
|
1665
|
+
category: o.category,
|
|
1666
|
+
subcategory: o.subcategory,
|
|
2169
1667
|
description: o.description,
|
|
2170
1668
|
url: o.url,
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
1669
|
+
content: o.content,
|
|
1670
|
+
tags: commaSeparated(o.tags),
|
|
1671
|
+
dimensions: o.width !== void 0 ? { width: Number(o.width), height: Number(o.height) } : void 0,
|
|
1672
|
+
usage_notes: o.usageNotes,
|
|
1673
|
+
restrictions: o.restrictions
|
|
1674
|
+
};
|
|
1675
|
+
const result = await client.program.creatives.create(params);
|
|
2175
1676
|
output(result, o);
|
|
2176
1677
|
} catch (err) {
|
|
2177
1678
|
handleError(err, o.json);
|
|
2178
1679
|
}
|
|
2179
1680
|
});
|
|
2180
|
-
creatives.command("update <id>").description("Update a creative").option("--name <name>", "Creative name").option("--
|
|
1681
|
+
creatives.command("update <id>").description("Update a creative").option("--name <name>", "Creative name").option("--category <category>", "Creative category").option("--subcategory <subcategory>", "Creative subcategory").option("--description <text>", "Description").option("--url <url>", "URL").option("--content <content>", "Text or embed content").option("--tags <tags>", "Tags (comma-separated)").option("--width <n>", "Width in pixels").option("--height <n>", "Height in pixels").option("--usage-notes <text>", "Usage notes").option("--restrictions <text>", "Usage restrictions").action(async function(id) {
|
|
2181
1682
|
const o = opts(this);
|
|
2182
1683
|
try {
|
|
2183
1684
|
const client = await getClient(o);
|
|
1685
|
+
if (o.width === void 0 !== (o.height === void 0))
|
|
1686
|
+
throw new Error("--width and --height must be provided together.");
|
|
2184
1687
|
const params = {};
|
|
2185
1688
|
if (o.name !== void 0) params.name = o.name;
|
|
2186
|
-
if (o.
|
|
1689
|
+
if (o.category !== void 0) params.category = o.category;
|
|
1690
|
+
if (o.subcategory !== void 0) params.subcategory = o.subcategory;
|
|
2187
1691
|
if (o.description !== void 0) params.description = o.description;
|
|
2188
1692
|
if (o.url !== void 0) params.url = o.url;
|
|
2189
|
-
if (o.
|
|
2190
|
-
if (o.
|
|
2191
|
-
if (o.
|
|
1693
|
+
if (o.content !== void 0) params.content = o.content;
|
|
1694
|
+
if (o.tags !== void 0) params.tags = commaSeparated(o.tags);
|
|
1695
|
+
if (o.width !== void 0)
|
|
1696
|
+
params.dimensions = { width: Number(o.width), height: Number(o.height) };
|
|
1697
|
+
if (o.usageNotes !== void 0) params.usage_notes = o.usageNotes;
|
|
1698
|
+
if (o.restrictions !== void 0) params.restrictions = o.restrictions;
|
|
2192
1699
|
const result = await client.program.creatives.update(id, params);
|
|
2193
1700
|
output(result, o);
|
|
2194
1701
|
} catch (err) {
|
|
@@ -2210,7 +1717,7 @@ function registerCreatives(prog) {
|
|
|
2210
1717
|
// src/commands/referrals.ts
|
|
2211
1718
|
function registerReferralCommands(program2) {
|
|
2212
1719
|
const referrals = program2.command("referrals").description("Manage referrals");
|
|
2213
|
-
referrals.command("list").description("List referrals").option("--limit <n>", "Items per page", "50").option("--starting-after <id>", "Cursor: fetch items after this ID").option("--ending-before <id>", "Cursor: fetch items before this ID").option("--affiliate-id <id>", "Filter by affiliate ID").option("--status <status>", "Filter by status").option("--order <dir>", "Order (asc, desc)").option("--expand <fields>", "Expand fields").option("--created-gte <date>", "Created after date").option("--created-lte <date>", "Created before date").action(async function() {
|
|
1720
|
+
referrals.command("list").description("List referrals").option("--limit <n>", "Items per page", "50").option("--starting-after <id>", "Cursor: fetch items after this ID").option("--ending-before <id>", "Cursor: fetch items before this ID").option("--affiliate-id <id>", "Filter by affiliate ID").option("--external-user-id <id>", "Filter by external user ID").option("--status <status>", "Filter by status").option("--order <dir>", "Order (asc, desc)").option("--expand <fields>", "Expand fields").option("--created-gte <date>", "Created after date").option("--created-lte <date>", "Created before date").action(async function() {
|
|
2214
1721
|
const o = opts(this);
|
|
2215
1722
|
try {
|
|
2216
1723
|
const client = await getClient(o);
|
|
@@ -2219,6 +1726,7 @@ function registerReferralCommands(program2) {
|
|
|
2219
1726
|
starting_after: o.startingAfter,
|
|
2220
1727
|
ending_before: o.endingBefore,
|
|
2221
1728
|
affiliate_id: o.affiliateId,
|
|
1729
|
+
external_user_id: o.externalUserId,
|
|
2222
1730
|
status: o.status,
|
|
2223
1731
|
order: o.order,
|
|
2224
1732
|
expand: o.expand,
|
|
@@ -2243,9 +1751,10 @@ function registerReferralCommands(program2) {
|
|
|
2243
1751
|
handleError(err, o.json);
|
|
2244
1752
|
}
|
|
2245
1753
|
});
|
|
2246
|
-
referrals.command("create").description("Create a referral").requiredOption("--email <email>", "Referral email").requiredOption("--affiliate-id <id>", "Affiliate ID").option("--subscription-id <id>", "Subscription ID").option("--customer-id <id>", "Customer ID").option("--click-id <id>", "Click ID").option("--status <status>", "Initial status").option("--name <name>", "Referral name").action(async function() {
|
|
1754
|
+
referrals.command("create").description("Create a referral").requiredOption("--email <email>", "Referral email").requiredOption("--affiliate-id <id>", "Affiliate ID").option("--subscription-id <id>", "Subscription ID").option("--customer-id <id>", "Customer ID").option("--click-id <id>", "Click ID").option("--status <status>", "Initial status").option("--name <name>", "Referral name").option("--created-at <date>", "Creation timestamp (ISO 8601)").option("--metadata-json <json|@file>", "Metadata as JSON or @file").action(async function() {
|
|
2247
1755
|
const o = opts(this);
|
|
2248
1756
|
try {
|
|
1757
|
+
const metadata = parseJsonObject(o.metadataJson, "--metadata-json");
|
|
2249
1758
|
const client = await getClient(o);
|
|
2250
1759
|
const result = await client.referrals.create({
|
|
2251
1760
|
email: o.email,
|
|
@@ -2254,23 +1763,27 @@ function registerReferralCommands(program2) {
|
|
|
2254
1763
|
customer_id: o.customerId,
|
|
2255
1764
|
click_id: o.clickId,
|
|
2256
1765
|
status: o.status,
|
|
2257
|
-
name: o.name
|
|
1766
|
+
name: o.name,
|
|
1767
|
+
created_at: o.createdAt,
|
|
1768
|
+
metadata
|
|
2258
1769
|
});
|
|
2259
1770
|
output(result, o);
|
|
2260
1771
|
} catch (err) {
|
|
2261
1772
|
handleError(err, o.json);
|
|
2262
1773
|
}
|
|
2263
1774
|
});
|
|
2264
|
-
referrals.command("update <id>").description("Update a referral").option("--email <email>", "Referral email").option("--status <status>", "Status").option("--subscription-id <id>", "Subscription ID").option("--customer-id <id>", "Customer ID").option("--name <name>", "Referral name").action(async function(id) {
|
|
1775
|
+
referrals.command("update <id>").description("Update a referral").option("--email <email>", "Referral email").option("--status <status>", "Status").option("--subscription-id <id>", "Subscription ID").option("--customer-id <id>", "Customer ID").option("--name <name>", "Referral name").option("--metadata-json <json|@file>", "Metadata as JSON or @file").action(async function(id) {
|
|
2265
1776
|
const o = opts(this);
|
|
2266
1777
|
try {
|
|
2267
|
-
const client = await getClient(o);
|
|
2268
1778
|
const params = {};
|
|
2269
1779
|
if (o.email !== void 0) params.email = o.email;
|
|
2270
1780
|
if (o.status !== void 0) params.status = o.status;
|
|
2271
1781
|
if (o.subscriptionId !== void 0) params.subscription_id = o.subscriptionId;
|
|
2272
1782
|
if (o.customerId !== void 0) params.customer_id = o.customerId;
|
|
2273
1783
|
if (o.name !== void 0) params.name = o.name;
|
|
1784
|
+
if (o.metadataJson !== void 0)
|
|
1785
|
+
params.metadata = parseJsonObject(o.metadataJson, "--metadata-json");
|
|
1786
|
+
const client = await getClient(o);
|
|
2274
1787
|
const result = await client.referrals.update(id, params);
|
|
2275
1788
|
output(result, o);
|
|
2276
1789
|
} catch (err) {
|
|
@@ -2289,6 +1802,81 @@ function registerReferralCommands(program2) {
|
|
|
2289
1802
|
});
|
|
2290
1803
|
}
|
|
2291
1804
|
|
|
1805
|
+
// src/commands/signups.ts
|
|
1806
|
+
function registerSignupCommands(program2) {
|
|
1807
|
+
program2.command("signups").description("Manage server-side signups").command("create").description("Create a server-side signup").requiredOption("--click-id <id>", "Click ID").option("--email <email>", "Customer email").option("--external-user-id <id>", "External user ID").option("--name <name>", "Customer name").action(async function() {
|
|
1808
|
+
const o = opts(this);
|
|
1809
|
+
try {
|
|
1810
|
+
const client = await getClient(o);
|
|
1811
|
+
output(
|
|
1812
|
+
await client.signups.create({
|
|
1813
|
+
click_id: o.clickId,
|
|
1814
|
+
email: o.email,
|
|
1815
|
+
external_user_id: o.externalUserId,
|
|
1816
|
+
name: o.name
|
|
1817
|
+
}),
|
|
1818
|
+
o
|
|
1819
|
+
);
|
|
1820
|
+
} catch (err) {
|
|
1821
|
+
handleError(err, o.json);
|
|
1822
|
+
}
|
|
1823
|
+
});
|
|
1824
|
+
}
|
|
1825
|
+
|
|
1826
|
+
// src/commands/sources.ts
|
|
1827
|
+
function registerSourceCommands(program2) {
|
|
1828
|
+
program2.command("sources").description("Ingest source events").command("ingest <source>").description(
|
|
1829
|
+
"Ingest a signed source event (custom or segment_webhook; configure its signing-secret environment variable)"
|
|
1830
|
+
).requiredOption("--payload-json <json|@file>", "Source payload as JSON or @file").action(async function(source) {
|
|
1831
|
+
const o = opts(this);
|
|
1832
|
+
try {
|
|
1833
|
+
const payload = parseJsonObject(o.payloadJson, "--payload-json");
|
|
1834
|
+
if (!payload) throw new Error("--payload-json is required.");
|
|
1835
|
+
const client = await getClient(o);
|
|
1836
|
+
output(await client.sources.ingest(source, payload), o);
|
|
1837
|
+
} catch (err) {
|
|
1838
|
+
handleError(err, o.json);
|
|
1839
|
+
}
|
|
1840
|
+
});
|
|
1841
|
+
}
|
|
1842
|
+
|
|
1843
|
+
// src/commands/tracking.ts
|
|
1844
|
+
var import_sdk4 = require("@affonso/sdk");
|
|
1845
|
+
function registerTrackingCommands(program2) {
|
|
1846
|
+
program2.command("tracking").description("Track public referral traffic").command("track").description("Resolve and record a public tracking request").requiredOption("--program-id <id>", "Program ID").option("--tracking-id <id>", "Affiliate tracking ID").option("--referrer <url>", "Referrer URL").option("--user-agent <value>", "User agent").option("--utm-source <value>", "UTM source").option("--utm-medium <value>", "UTM medium").option("--utm-campaign <value>", "UTM campaign").option("--utm-term <value>", "UTM term").option("--utm-content <value>", "UTM content").option("--sub1 <value>", "Sub-tracking parameter 1").option("--sub2 <value>", "Sub-tracking parameter 2").option("--sub3 <value>", "Sub-tracking parameter 3").option("--sub4 <value>", "Sub-tracking parameter 4").option("--sub5 <value>", "Sub-tracking parameter 5").option("--gclid <id>", "Google click ID").option("--fbclid <id>", "Meta click ID").option("--msclkid <id>", "Microsoft click ID").option("--ttclid <id>", "TikTok click ID").option("--has-consent", "Record that tracking consent was granted").action(async function() {
|
|
1847
|
+
const o = opts(this);
|
|
1848
|
+
try {
|
|
1849
|
+
const client = new import_sdk4.Affonso("public", { baseUrl: resolveBaseUrl(o.baseUrl) });
|
|
1850
|
+
output(
|
|
1851
|
+
await client.tracking.track({
|
|
1852
|
+
programId: o.programId,
|
|
1853
|
+
trackingId: o.trackingId,
|
|
1854
|
+
referrer: o.referrer,
|
|
1855
|
+
userAgent: o.userAgent,
|
|
1856
|
+
utmSource: o.utmSource,
|
|
1857
|
+
utmMedium: o.utmMedium,
|
|
1858
|
+
utmCampaign: o.utmCampaign,
|
|
1859
|
+
utmTerm: o.utmTerm,
|
|
1860
|
+
utmContent: o.utmContent,
|
|
1861
|
+
sub1: o.sub1,
|
|
1862
|
+
sub2: o.sub2,
|
|
1863
|
+
sub3: o.sub3,
|
|
1864
|
+
sub4: o.sub4,
|
|
1865
|
+
sub5: o.sub5,
|
|
1866
|
+
gclid: o.gclid,
|
|
1867
|
+
fbclid: o.fbclid,
|
|
1868
|
+
msclkid: o.msclkid,
|
|
1869
|
+
ttclid: o.ttclid,
|
|
1870
|
+
hasConsent: o.hasConsent || void 0
|
|
1871
|
+
}),
|
|
1872
|
+
o
|
|
1873
|
+
);
|
|
1874
|
+
} catch (err) {
|
|
1875
|
+
handleError(err, o.json);
|
|
1876
|
+
}
|
|
1877
|
+
});
|
|
1878
|
+
}
|
|
1879
|
+
|
|
2292
1880
|
// src/commands/whoami.ts
|
|
2293
1881
|
function registerWhoamiCommand(program2) {
|
|
2294
1882
|
program2.command("whoami").description("Show current authentication status").action(async function() {
|
|
@@ -2332,11 +1920,17 @@ function createProgram() {
|
|
|
2332
1920
|
registerReferralCommands(program2);
|
|
2333
1921
|
registerClickCommands(program2);
|
|
2334
1922
|
registerCommissionCommands(program2);
|
|
1923
|
+
registerConversionCommands(program2);
|
|
1924
|
+
registerEventCommands(program2);
|
|
1925
|
+
registerSignupCommands(program2);
|
|
1926
|
+
registerSourceCommands(program2);
|
|
2335
1927
|
registerCouponCommands(program2);
|
|
2336
1928
|
registerPayoutCommands(program2);
|
|
2337
1929
|
registerProgramCommands(program2);
|
|
2338
1930
|
registerMarketplaceCommands(program2);
|
|
2339
1931
|
registerEmbedTokenCommands(program2);
|
|
1932
|
+
registerOnboardingFormCommands(program2);
|
|
1933
|
+
registerTrackingCommands(program2);
|
|
2340
1934
|
return program2;
|
|
2341
1935
|
}
|
|
2342
1936
|
|