agentref 1.0.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.
@@ -0,0 +1,421 @@
1
+ interface PaginationMeta {
2
+ total: number;
3
+ page: number;
4
+ pageSize: number;
5
+ hasMore: boolean;
6
+ nextCursor?: string;
7
+ requestId: string;
8
+ }
9
+ interface PaginatedResponse<T> {
10
+ data: T[];
11
+ meta: PaginationMeta;
12
+ }
13
+ interface AgentRefConfig {
14
+ apiKey?: string;
15
+ baseUrl?: string;
16
+ timeout?: number;
17
+ maxRetries?: number;
18
+ dangerouslyAllowBrowser?: boolean;
19
+ }
20
+ interface MutationOptions {
21
+ idempotencyKey?: string;
22
+ }
23
+ interface Merchant {
24
+ id: string;
25
+ email: string;
26
+ companyName?: string | null;
27
+ domain?: string | null;
28
+ domainVerified?: boolean;
29
+ trustLevel?: string;
30
+ stripeConnected?: boolean;
31
+ createdAt?: string;
32
+ [key: string]: unknown;
33
+ }
34
+ type CommissionType = 'one_time' | 'recurring' | 'recurring_limited';
35
+ type ProgramStatus = 'active' | 'paused' | 'archived';
36
+ interface Program {
37
+ id: string;
38
+ name: string;
39
+ description?: string | null;
40
+ landingPageUrl?: string | null;
41
+ commissionType: CommissionType;
42
+ commissionPercent: number;
43
+ commissionLimitMonths?: number | null;
44
+ cookieDuration: number;
45
+ payoutThreshold: number;
46
+ autoApproveAffiliates: boolean;
47
+ status: ProgramStatus;
48
+ isPublic?: boolean;
49
+ merchantId?: string;
50
+ createdAt?: string;
51
+ updatedAt?: string;
52
+ [key: string]: unknown;
53
+ }
54
+ interface CreateProgramParams {
55
+ name: string;
56
+ commissionType: CommissionType;
57
+ commissionPercent: number;
58
+ cookieDuration?: number;
59
+ payoutThreshold?: number;
60
+ autoApproveAffiliates?: boolean;
61
+ description?: string;
62
+ landingPageUrl?: string;
63
+ commissionLimitMonths?: number;
64
+ }
65
+ interface UpdateProgramParams {
66
+ name?: string;
67
+ commissionType?: CommissionType;
68
+ commissionPercent?: number;
69
+ cookieDuration?: number;
70
+ payoutThreshold?: number;
71
+ autoApproveAffiliates?: boolean;
72
+ description?: string;
73
+ landingPageUrl?: string;
74
+ status?: ProgramStatus;
75
+ }
76
+ interface CreateCouponParams {
77
+ affiliateId: string;
78
+ code: string;
79
+ expiresAt?: string;
80
+ }
81
+ interface ProgramStats {
82
+ [key: string]: unknown;
83
+ }
84
+ type AffiliateStatus = 'pending' | 'approved' | 'blocked';
85
+ interface Affiliate {
86
+ id: string;
87
+ userId?: string;
88
+ programId?: string;
89
+ code?: string;
90
+ status?: AffiliateStatus | string;
91
+ totalClicks?: number;
92
+ totalConversions?: number;
93
+ totalEarnings?: number;
94
+ createdAt?: string;
95
+ [key: string]: unknown;
96
+ }
97
+ type ConversionStatus = 'pending' | 'approved' | 'rejected' | 'refunded';
98
+ interface Conversion {
99
+ id: string;
100
+ affiliateId?: string;
101
+ programId?: string;
102
+ amount?: number;
103
+ commission?: number;
104
+ status?: ConversionStatus | string;
105
+ method?: 'cookie' | 'coupon' | 'metadata' | string;
106
+ stripeSessionId?: string | null;
107
+ createdAt?: string;
108
+ [key: string]: unknown;
109
+ }
110
+ interface ConversionStats {
111
+ [key: string]: unknown;
112
+ }
113
+ type PayoutStatus = 'pending' | 'processing' | 'completed' | 'failed';
114
+ interface Payout {
115
+ id: string;
116
+ affiliateId?: string;
117
+ amount?: number;
118
+ status?: PayoutStatus | string;
119
+ method?: string | null;
120
+ createdAt?: string;
121
+ completedAt?: string | null;
122
+ [key: string]: unknown;
123
+ }
124
+ interface PendingAffiliate {
125
+ affiliateId?: string;
126
+ email?: string;
127
+ name?: string | null;
128
+ code?: string;
129
+ programId?: string;
130
+ programName?: string;
131
+ payoutMethod?: 'paypal' | 'bank_transfer' | null;
132
+ paypalEmail?: string | null;
133
+ bankIban?: string | null;
134
+ pendingAmount?: number;
135
+ currency?: string;
136
+ threshold?: number;
137
+ meetsThreshold?: boolean;
138
+ commissionCount?: number;
139
+ hasPayoutMethod?: boolean;
140
+ [key: string]: unknown;
141
+ }
142
+ interface PayoutStats {
143
+ [key: string]: unknown;
144
+ }
145
+ type FlagStatus = 'open' | 'reviewed' | 'dismissed' | 'confirmed';
146
+ type FlagType = 'suspicious_activity' | 'self_referral' | 'high_click_frequency' | 'conversion_anomaly' | 'manual_review';
147
+ interface Flag {
148
+ id: string;
149
+ affiliateId?: string;
150
+ type?: FlagType | string;
151
+ status?: FlagStatus | string;
152
+ details?: Record<string, unknown> | null;
153
+ note?: string | null;
154
+ createdAt?: string;
155
+ resolvedAt?: string | null;
156
+ [key: string]: unknown;
157
+ }
158
+ interface FlagStats {
159
+ [key: string]: unknown;
160
+ }
161
+ interface ResolveFlagParams {
162
+ status: 'reviewed' | 'dismissed' | 'confirmed';
163
+ note?: string;
164
+ blockAffiliate?: boolean;
165
+ }
166
+ type BillingTierId = 'free' | 'starter' | 'growth' | 'pro' | 'scale';
167
+ interface BillingTier {
168
+ id: BillingTierId;
169
+ name: string;
170
+ price: number;
171
+ maxRevenue?: number;
172
+ features?: string[];
173
+ bookable?: boolean;
174
+ [key: string]: unknown;
175
+ }
176
+ interface BillingStatus {
177
+ tier?: BillingTierId | string;
178
+ monthlyRevenue?: number;
179
+ nextTier?: BillingTierId | string | null;
180
+ stripeSubscriptionId?: string | null;
181
+ [key: string]: unknown;
182
+ }
183
+ interface Coupon {
184
+ id: string;
185
+ code: string;
186
+ affiliateId?: string;
187
+ programId?: string;
188
+ createdAt?: string;
189
+ [key: string]: unknown;
190
+ }
191
+ interface Invite {
192
+ token?: string;
193
+ email?: string;
194
+ programId?: string;
195
+ expiresAt?: string;
196
+ createdAt?: string;
197
+ [key: string]: unknown;
198
+ }
199
+
200
+ type HttpMethod = 'GET' | 'HEAD' | 'POST' | 'PATCH' | 'DELETE';
201
+ interface RequestOptions {
202
+ method: HttpMethod;
203
+ path: string;
204
+ body?: unknown;
205
+ query?: Record<string, string | number | boolean | undefined>;
206
+ idempotencyKey?: string;
207
+ }
208
+ declare class HttpClient {
209
+ private readonly apiKey;
210
+ private readonly baseUrl;
211
+ private readonly timeout;
212
+ private readonly maxRetries;
213
+ constructor(config?: AgentRefConfig);
214
+ request<T>(options: RequestOptions): Promise<T>;
215
+ private buildUrl;
216
+ private parseError;
217
+ private isRetryable;
218
+ private retryAfterToSeconds;
219
+ private retryAfterToMs;
220
+ private wait;
221
+ private backoff;
222
+ }
223
+
224
+ declare class AffiliatesResource {
225
+ private readonly http;
226
+ constructor(http: HttpClient);
227
+ list(params?: {
228
+ programId?: string;
229
+ includeBlocked?: boolean;
230
+ cursor?: string;
231
+ limit?: number;
232
+ page?: number;
233
+ pageSize?: number;
234
+ offset?: number;
235
+ }): Promise<PaginatedResponse<Affiliate>>;
236
+ get(id: string): Promise<Affiliate>;
237
+ approve(id: string, options?: MutationOptions): Promise<Affiliate>;
238
+ block(id: string, data?: {
239
+ reason?: string;
240
+ }, options?: MutationOptions): Promise<Affiliate>;
241
+ unblock(id: string, options?: MutationOptions): Promise<Affiliate>;
242
+ }
243
+
244
+ declare class BillingResource {
245
+ private readonly http;
246
+ constructor(http: HttpClient);
247
+ current(): Promise<BillingStatus>;
248
+ tiers(): Promise<BillingTier[]>;
249
+ subscribe(data: {
250
+ tier: 'starter' | 'growth' | 'pro' | 'scale';
251
+ }, options?: MutationOptions): Promise<BillingStatus>;
252
+ }
253
+
254
+ declare class ConversionsResource {
255
+ private readonly http;
256
+ constructor(http: HttpClient);
257
+ list(params?: {
258
+ programId?: string;
259
+ affiliateId?: string;
260
+ status?: string;
261
+ startDate?: string;
262
+ endDate?: string;
263
+ from?: string;
264
+ to?: string;
265
+ cursor?: string;
266
+ limit?: number;
267
+ page?: number;
268
+ pageSize?: number;
269
+ offset?: number;
270
+ }): Promise<PaginatedResponse<Conversion>>;
271
+ stats(params?: {
272
+ programId?: string;
273
+ period?: '7d' | '30d' | '90d' | 'all';
274
+ }): Promise<ConversionStats>;
275
+ recent(params?: {
276
+ limit?: number;
277
+ }): Promise<Conversion[]>;
278
+ }
279
+
280
+ declare class FlagsResource {
281
+ private readonly http;
282
+ constructor(http: HttpClient);
283
+ list(params?: {
284
+ status?: string;
285
+ type?: string;
286
+ affiliateId?: string;
287
+ cursor?: string;
288
+ limit?: number;
289
+ page?: number;
290
+ pageSize?: number;
291
+ offset?: number;
292
+ }): Promise<PaginatedResponse<Flag>>;
293
+ stats(): Promise<FlagStats>;
294
+ resolve(id: string, data: ResolveFlagParams, options?: MutationOptions): Promise<Flag>;
295
+ }
296
+
297
+ interface DomainStatus {
298
+ domain: string | null;
299
+ verified: boolean;
300
+ txtRecord?: string | null;
301
+ [key: string]: unknown;
302
+ }
303
+ declare class MerchantResource {
304
+ private readonly http;
305
+ constructor(http: HttpClient);
306
+ get(): Promise<Merchant>;
307
+ domainStatus(): Promise<DomainStatus>;
308
+ }
309
+
310
+ declare class PayoutsResource {
311
+ private readonly http;
312
+ constructor(http: HttpClient);
313
+ list(params?: {
314
+ programId?: string;
315
+ affiliateId?: string;
316
+ status?: PayoutStatus;
317
+ startDate?: string;
318
+ endDate?: string;
319
+ from?: string;
320
+ to?: string;
321
+ cursor?: string;
322
+ limit?: number;
323
+ page?: number;
324
+ pageSize?: number;
325
+ offset?: number;
326
+ }): Promise<PaginatedResponse<Payout>>;
327
+ listPending(params?: {
328
+ programId?: string;
329
+ cursor?: string;
330
+ limit?: number;
331
+ page?: number;
332
+ pageSize?: number;
333
+ offset?: number;
334
+ }): Promise<PaginatedResponse<PendingAffiliate>>;
335
+ stats(params?: {
336
+ programId?: string;
337
+ period?: '7d' | '30d' | '90d' | 'all';
338
+ }): Promise<PayoutStats>;
339
+ }
340
+
341
+ declare class ProgramsResource {
342
+ private readonly http;
343
+ constructor(http: HttpClient);
344
+ list(params?: {
345
+ cursor?: string;
346
+ limit?: number;
347
+ page?: number;
348
+ pageSize?: number;
349
+ offset?: number;
350
+ }): Promise<PaginatedResponse<Program>>;
351
+ listAll(params?: {
352
+ pageSize?: number;
353
+ }): AsyncGenerator<Program>;
354
+ get(id: string): Promise<Program>;
355
+ create(data: CreateProgramParams, options?: MutationOptions): Promise<Program>;
356
+ update(id: string, data: UpdateProgramParams): Promise<Program>;
357
+ delete(id: string): Promise<Program>;
358
+ stats(id: string, params?: {
359
+ period?: string;
360
+ }): Promise<ProgramStats>;
361
+ listAffiliates(id: string, params?: {
362
+ includeBlocked?: boolean;
363
+ cursor?: string;
364
+ limit?: number;
365
+ page?: number;
366
+ pageSize?: number;
367
+ offset?: number;
368
+ }): Promise<PaginatedResponse<Affiliate>>;
369
+ listCoupons(id: string): Promise<Coupon[]>;
370
+ createCoupon(id: string, data: CreateCouponParams, options?: MutationOptions): Promise<Coupon>;
371
+ createInvite(id: string, data: {
372
+ email?: string;
373
+ name?: string;
374
+ isPublic?: boolean;
375
+ usageLimit?: number;
376
+ expiresInDays?: number;
377
+ }, options?: MutationOptions): Promise<Invite>;
378
+ }
379
+
380
+ declare class AgentRef {
381
+ readonly programs: ProgramsResource;
382
+ readonly affiliates: AffiliatesResource;
383
+ readonly conversions: ConversionsResource;
384
+ readonly payouts: PayoutsResource;
385
+ readonly flags: FlagsResource;
386
+ readonly billing: BillingResource;
387
+ readonly merchant: MerchantResource;
388
+ constructor(config?: AgentRefConfig);
389
+ }
390
+
391
+ declare class AgentRefError extends Error {
392
+ readonly code: string;
393
+ readonly status: number;
394
+ readonly requestId: string;
395
+ constructor(message: string, code: string, status: number, requestId: string);
396
+ }
397
+ declare class AuthError extends AgentRefError {
398
+ constructor(message: string, code: string, requestId: string);
399
+ }
400
+ declare class ForbiddenError extends AgentRefError {
401
+ constructor(message: string, code: string, requestId: string);
402
+ }
403
+ declare class ValidationError extends AgentRefError {
404
+ readonly details: unknown;
405
+ constructor(message: string, code: string, requestId: string, details?: unknown);
406
+ }
407
+ declare class NotFoundError extends AgentRefError {
408
+ constructor(message: string, code: string, requestId: string);
409
+ }
410
+ declare class ConflictError extends AgentRefError {
411
+ constructor(message: string, code: string, requestId: string);
412
+ }
413
+ declare class RateLimitError extends AgentRefError {
414
+ readonly retryAfter: number;
415
+ constructor(message: string, code: string, requestId: string, retryAfter: number);
416
+ }
417
+ declare class ServerError extends AgentRefError {
418
+ constructor(message: string, code: string, status: number, requestId: string);
419
+ }
420
+
421
+ export { type Affiliate, type AffiliateStatus, AgentRef, type AgentRefConfig, AgentRefError, AuthError, type BillingStatus, type BillingTier, type BillingTierId, type CommissionType, ConflictError, type Conversion, type ConversionStats, type ConversionStatus, type Coupon, type CreateCouponParams, type CreateProgramParams, type Flag, type FlagStats, type FlagStatus, type FlagType, ForbiddenError, type Invite, type Merchant, type MutationOptions, NotFoundError, type PaginatedResponse, type PaginationMeta, type Payout, type PayoutStats, type PayoutStatus, type PendingAffiliate, type Program, type ProgramStats, type ProgramStatus, RateLimitError, type ResolveFlagParams, ServerError, type UpdateProgramParams, ValidationError };