@ofauth/onlyfans-sdk 2.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,2587 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ BASE_PATH: () => BASE_PATH,
34
+ OFAuthAPIError: () => OFAuthAPIError,
35
+ OFAuthClient: () => OFAuthClient,
36
+ WebhookRouter: () => WebhookRouter,
37
+ WebhookVerificationError: () => WebhookVerificationError,
38
+ createExpressWebhookMiddleware: () => createExpressWebhookMiddleware,
39
+ createFetchWebhookHandler: () => createFetchWebhookHandler,
40
+ createOFAuthClient: () => createOFAuthClient,
41
+ createWebhookRouter: () => createWebhookRouter,
42
+ extractWebhookHeaders: () => extractWebhookHeaders,
43
+ isWebhookVerificationError: () => isWebhookVerificationError,
44
+ proxy: () => proxy,
45
+ request: () => request,
46
+ verifyWebhookPayload: () => verifyWebhookPayload,
47
+ verifyWebhookRequest: () => verifyWebhookRequest,
48
+ verifyWebhookSignature: () => verifyWebhookSignature
49
+ });
50
+ module.exports = __toCommonJS(index_exports);
51
+
52
+ // src/runtime.ts
53
+ var BASE_PATH = "https://api-next.ofauth.com";
54
+ var OFAuthAPIError = class extends Error {
55
+ constructor(response, body) {
56
+ super(body?.message || `HTTP ${response.status}: ${response.statusText}`);
57
+ this.name = "OFAuthAPIError";
58
+ this.status = response.status;
59
+ this.code = body?.code;
60
+ this.details = body?.details;
61
+ this.response = response;
62
+ }
63
+ };
64
+ function buildQueryString(params) {
65
+ const entries = [];
66
+ for (const [key, value] of Object.entries(params)) {
67
+ if (value === void 0 || value === null) continue;
68
+ if (Array.isArray(value)) {
69
+ for (const v of value) {
70
+ entries.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(v))}`);
71
+ }
72
+ } else {
73
+ entries.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);
74
+ }
75
+ }
76
+ return entries.length > 0 ? `?${entries.join("&")}` : "";
77
+ }
78
+ async function request(config, reqConfig) {
79
+ const fetchFn = config.fetchApi || fetch;
80
+ const basePath = config.basePath || BASE_PATH;
81
+ const connectionId = reqConfig.connectionId || config.connectionId;
82
+ const url = basePath + reqConfig.path + (reqConfig.query ? buildQueryString(reqConfig.query) : "");
83
+ const headers = {
84
+ "apiKey": config.apiKey,
85
+ ...reqConfig.headers
86
+ };
87
+ if (connectionId) {
88
+ headers["x-connection-id"] = connectionId;
89
+ }
90
+ if (reqConfig.body && typeof reqConfig.body === "object" && !(reqConfig.body instanceof FormData) && !(reqConfig.body instanceof Blob)) {
91
+ headers["Content-Type"] = "application/json";
92
+ }
93
+ const response = await fetchFn(url, {
94
+ method: reqConfig.method,
95
+ headers,
96
+ body: reqConfig.body instanceof FormData || reqConfig.body instanceof Blob ? reqConfig.body : reqConfig.body ? JSON.stringify(reqConfig.body) : void 0
97
+ });
98
+ if (!response.ok) {
99
+ let errorBody;
100
+ try {
101
+ errorBody = await response.json();
102
+ } catch {
103
+ }
104
+ throw new OFAuthAPIError(response, errorBody);
105
+ }
106
+ const contentType = response.headers.get("content-type");
107
+ if (contentType?.includes("application/json")) {
108
+ return response.json();
109
+ }
110
+ if (response.status === 204) return {};
111
+ return response.text();
112
+ }
113
+ async function proxy(config, opts) {
114
+ const fetchFn = config.fetchApi || fetch;
115
+ const basePath = config.basePath || BASE_PATH;
116
+ let targetPath = opts.path;
117
+ if (targetPath.startsWith("/api2/v2")) {
118
+ targetPath = targetPath.slice(8);
119
+ } else if (targetPath.startsWith("api2/v2")) {
120
+ targetPath = "/" + targetPath.slice(7);
121
+ }
122
+ if (!targetPath.startsWith("/")) {
123
+ targetPath = "/" + targetPath;
124
+ }
125
+ let url = basePath + "/v2/access/proxy" + targetPath;
126
+ if (opts.query) {
127
+ url += buildQueryString(opts.query);
128
+ }
129
+ const headers = {
130
+ "apiKey": config.apiKey
131
+ };
132
+ const connectionId = opts.connectionId || config.connectionId;
133
+ if (connectionId) {
134
+ headers["x-connection-id"] = connectionId;
135
+ }
136
+ if (opts.body && typeof opts.body === "object" && !(opts.body instanceof FormData) && !(opts.body instanceof Blob)) {
137
+ headers["Content-Type"] = "application/json";
138
+ }
139
+ const response = await fetchFn(url, {
140
+ method: opts.method,
141
+ headers,
142
+ body: opts.body instanceof FormData || opts.body instanceof Blob ? opts.body : opts.body ? JSON.stringify(opts.body) : void 0
143
+ });
144
+ if (!response.ok) {
145
+ let errorBody;
146
+ try {
147
+ errorBody = await response.json();
148
+ } catch {
149
+ }
150
+ throw new OFAuthAPIError(response, errorBody);
151
+ }
152
+ const contentType = response.headers.get("content-type");
153
+ if (contentType?.includes("application/json")) {
154
+ return response.json();
155
+ }
156
+ if (response.status === 204) return {};
157
+ return response.text();
158
+ }
159
+
160
+ // src/client.ts
161
+ var AccountConnectionsNamespace = class {
162
+ constructor(config) {
163
+ this._config = config;
164
+ }
165
+ /**
166
+ * Disconnect connection
167
+ */
168
+ delete(params) {
169
+ return request(this._config, {
170
+ path: `/v2/account/connections/${encodeURIComponent(String(params.connectionId))}`,
171
+ method: "DELETE"
172
+ });
173
+ }
174
+ /**
175
+ * List connections
176
+ */
177
+ list(params) {
178
+ return request(this._config, {
179
+ path: "/v2/account/connections",
180
+ method: "GET",
181
+ query: {
182
+ "status": params.status,
183
+ "imported": params.imported,
184
+ "limit": params.limit,
185
+ "offset": params.offset
186
+ }
187
+ });
188
+ }
189
+ /**
190
+ * List connections
191
+ *
192
+ * Returns an async iterator that automatically paginates through all results.
193
+ */
194
+ async *iterate(params) {
195
+ let offset = 0;
196
+ let fetched = 0;
197
+ const limit = params?.pageSize ?? 20;
198
+ const maxItems = params?.maxItems ?? Infinity;
199
+ while (fetched < maxItems) {
200
+ const response = await this.list({
201
+ ...params,
202
+ limit: Math.min(limit, maxItems - fetched),
203
+ offset
204
+ });
205
+ for (const item of response.list) {
206
+ if (fetched >= maxItems) return;
207
+ yield item;
208
+ fetched++;
209
+ }
210
+ if (!response.hasMore) return;
211
+ offset = response.nextOffset ?? offset + response.list.length;
212
+ }
213
+ }
214
+ /**
215
+ * Invalidate connection
216
+ */
217
+ invalidate(params) {
218
+ return request(this._config, {
219
+ path: `/v2/account/connections/${encodeURIComponent(String(params.connectionId))}/invalidate`,
220
+ method: "POST"
221
+ });
222
+ }
223
+ /**
224
+ * Get connection settings
225
+ */
226
+ getSettings(params) {
227
+ return request(this._config, {
228
+ path: `/v2/account/connections/${encodeURIComponent(String(params.connectionId))}/settings`,
229
+ method: "GET"
230
+ });
231
+ }
232
+ /**
233
+ * Update connection settings
234
+ */
235
+ updateSettings(params) {
236
+ return request(this._config, {
237
+ path: `/v2/account/connections/${encodeURIComponent(String(params.connectionId))}/settings`,
238
+ method: "PATCH",
239
+ body: params.body
240
+ });
241
+ }
242
+ /**
243
+ * Import connection
244
+ */
245
+ createImport(params) {
246
+ return request(this._config, {
247
+ path: "/v2/account/connections/import",
248
+ method: "POST",
249
+ body: params.body
250
+ });
251
+ }
252
+ /**
253
+ * Update imported connection session
254
+ */
255
+ updateImport(params) {
256
+ return request(this._config, {
257
+ path: `/v2/account/connections/import/${encodeURIComponent(String(params.connectionId))}`,
258
+ method: "PATCH",
259
+ body: params.body
260
+ });
261
+ }
262
+ };
263
+ var AccountNamespace = class {
264
+ constructor(config) {
265
+ this._config = config;
266
+ this.connections = new AccountConnectionsNamespace(config);
267
+ }
268
+ /**
269
+ * Whoami
270
+ */
271
+ whoami() {
272
+ return request(this._config, {
273
+ path: "/v2/account/whoami",
274
+ method: "GET"
275
+ });
276
+ }
277
+ /**
278
+ * Get organization settings
279
+ */
280
+ getSettings() {
281
+ return request(this._config, {
282
+ path: "/v2/account/settings",
283
+ method: "GET"
284
+ });
285
+ }
286
+ /**
287
+ * Update organization settings
288
+ */
289
+ updateSettings(params) {
290
+ return request(this._config, {
291
+ path: "/v2/account/settings",
292
+ method: "PATCH",
293
+ body: params.body
294
+ });
295
+ }
296
+ };
297
+ var AccessSelfNamespace = class {
298
+ constructor(config) {
299
+ this._config = config;
300
+ }
301
+ /**
302
+ * Get current user
303
+ */
304
+ get() {
305
+ return request(this._config, {
306
+ path: "/v2/access/self",
307
+ method: "GET"
308
+ });
309
+ }
310
+ /**
311
+ * Update current user profile
312
+ */
313
+ update(params) {
314
+ return request(this._config, {
315
+ path: "/v2/access/self",
316
+ method: "PATCH",
317
+ body: params.body
318
+ });
319
+ }
320
+ /**
321
+ * List notifications
322
+ */
323
+ listNotifications(params) {
324
+ return request(this._config, {
325
+ path: "/v2/access/self/notifications",
326
+ method: "GET",
327
+ query: {
328
+ "limit": params.limit,
329
+ "offset": params.offset,
330
+ "type": params.type,
331
+ "relatedUsername": params.relatedUsername
332
+ }
333
+ });
334
+ }
335
+ /**
336
+ * List notifications
337
+ *
338
+ * Returns an async iterator that automatically paginates through all results.
339
+ */
340
+ async *iterateNotifications(params) {
341
+ let offset = 0;
342
+ let fetched = 0;
343
+ const limit = params?.pageSize ?? 20;
344
+ const maxItems = params?.maxItems ?? Infinity;
345
+ while (fetched < maxItems) {
346
+ const response = await this.listNotifications({
347
+ ...params,
348
+ limit: Math.min(limit, maxItems - fetched),
349
+ offset
350
+ });
351
+ for (const item of response.list) {
352
+ if (fetched >= maxItems) return;
353
+ yield item;
354
+ fetched++;
355
+ }
356
+ if (!response.hasMore) return;
357
+ offset = response.nextOffset ?? offset + response.list.length;
358
+ }
359
+ }
360
+ /**
361
+ * List release forms
362
+ */
363
+ listReleaseForms(params) {
364
+ return request(this._config, {
365
+ path: "/v2/access/self/release-forms",
366
+ method: "GET",
367
+ query: {
368
+ "limit": params.limit,
369
+ "offset": params.offset,
370
+ "filter": params.filter,
371
+ "sortBy": params.sortBy,
372
+ "sortDirection": params.sortDirection,
373
+ "search": params.search
374
+ }
375
+ });
376
+ }
377
+ /**
378
+ * List release forms
379
+ *
380
+ * Returns an async iterator that automatically paginates through all results.
381
+ */
382
+ async *iterateReleaseForms(params) {
383
+ let offset = 0;
384
+ let fetched = 0;
385
+ const limit = params?.pageSize ?? 20;
386
+ const maxItems = params?.maxItems ?? Infinity;
387
+ while (fetched < maxItems) {
388
+ const response = await this.listReleaseForms({
389
+ ...params,
390
+ limit: Math.min(limit, maxItems - fetched),
391
+ offset
392
+ });
393
+ for (const item of response.list) {
394
+ if (fetched >= maxItems) return;
395
+ yield item;
396
+ fetched++;
397
+ }
398
+ if (!response.hasMore) return;
399
+ offset = response.nextOffset ?? offset + response.list.length;
400
+ }
401
+ }
402
+ /**
403
+ * List tagged friend users
404
+ */
405
+ listTaggedFriendUsers(params) {
406
+ return request(this._config, {
407
+ path: "/v2/access/self/tagged-friend-users",
408
+ method: "GET",
409
+ query: {
410
+ "limit": params.limit,
411
+ "offset": params.offset,
412
+ "filter": params.filter,
413
+ "sortBy": params.sortBy,
414
+ "sortDirection": params.sortDirection,
415
+ "search": params.search
416
+ }
417
+ });
418
+ }
419
+ /**
420
+ * List tagged friend users
421
+ *
422
+ * Returns an async iterator that automatically paginates through all results.
423
+ */
424
+ async *iterateTaggedFriendUsers(params) {
425
+ let offset = 0;
426
+ let fetched = 0;
427
+ const limit = params?.pageSize ?? 20;
428
+ const maxItems = params?.maxItems ?? Infinity;
429
+ while (fetched < maxItems) {
430
+ const response = await this.listTaggedFriendUsers({
431
+ ...params,
432
+ limit: Math.min(limit, maxItems - fetched),
433
+ offset
434
+ });
435
+ for (const item of response.list) {
436
+ if (fetched >= maxItems) return;
437
+ yield item;
438
+ fetched++;
439
+ }
440
+ if (!response.hasMore) return;
441
+ offset = response.nextOffset ?? offset + response.list.length;
442
+ }
443
+ }
444
+ };
445
+ var AccessEarningsNamespace = class {
446
+ constructor(config) {
447
+ this._config = config;
448
+ }
449
+ /**
450
+ * Get earnings chart
451
+ */
452
+ getChart(params) {
453
+ return request(this._config, {
454
+ path: "/v2/access/earnings/chart",
455
+ method: "GET",
456
+ query: {
457
+ "startDate": params.startDate,
458
+ "endDate": params.endDate,
459
+ "by": params.by,
460
+ "withTotal": params.withTotal,
461
+ "monthlyTotal": params.monthlyTotal
462
+ }
463
+ });
464
+ }
465
+ /**
466
+ * List transactions
467
+ */
468
+ listTransactions(params) {
469
+ return request(this._config, {
470
+ path: "/v2/access/earnings/transactions",
471
+ method: "GET",
472
+ query: {
473
+ "startDate": params.startDate,
474
+ "marker": params.marker,
475
+ "type": params.type,
476
+ "tipsSource": params.tipsSource
477
+ }
478
+ });
479
+ }
480
+ /**
481
+ * List transactions
482
+ *
483
+ * Returns an async iterator that automatically paginates through all results.
484
+ */
485
+ async *iterateTransactions(params) {
486
+ let marker;
487
+ let fetched = 0;
488
+ const maxItems = params?.maxItems ?? Infinity;
489
+ while (fetched < maxItems) {
490
+ const response = await this.listTransactions({
491
+ ...params,
492
+ marker
493
+ });
494
+ for (const item of response.list) {
495
+ if (fetched >= maxItems) return;
496
+ yield item;
497
+ fetched++;
498
+ }
499
+ if (!response.hasMore) return;
500
+ marker = response.marker;
501
+ }
502
+ }
503
+ /**
504
+ * List chargebacks
505
+ */
506
+ listChargebacks(params) {
507
+ return request(this._config, {
508
+ path: "/v2/access/earnings/chargebacks",
509
+ method: "GET",
510
+ query: {
511
+ "limit": params.limit,
512
+ "offset": params.offset,
513
+ "startDate": params.startDate,
514
+ "endDate": params.endDate
515
+ }
516
+ });
517
+ }
518
+ /**
519
+ * List chargebacks
520
+ *
521
+ * Returns an async iterator that automatically paginates through all results.
522
+ */
523
+ async *iterateChargebacks(params) {
524
+ let offset = 0;
525
+ let fetched = 0;
526
+ const limit = params?.pageSize ?? 20;
527
+ const maxItems = params?.maxItems ?? Infinity;
528
+ while (fetched < maxItems) {
529
+ const response = await this.listChargebacks({
530
+ ...params,
531
+ limit: Math.min(limit, maxItems - fetched),
532
+ offset
533
+ });
534
+ for (const item of response.list) {
535
+ if (fetched >= maxItems) return;
536
+ yield item;
537
+ fetched++;
538
+ }
539
+ if (!response.hasMore) return;
540
+ offset = response.nextOffset ?? offset + response.list.length;
541
+ }
542
+ }
543
+ };
544
+ var AccessAnalyticsPostsNamespace = class {
545
+ constructor(config) {
546
+ this._config = config;
547
+ }
548
+ /**
549
+ * Post stats
550
+ */
551
+ get(params) {
552
+ return request(this._config, {
553
+ path: `/v2/access/analytics/posts/${encodeURIComponent(String(params.postId))}`,
554
+ method: "GET"
555
+ });
556
+ }
557
+ /**
558
+ * Posts chart
559
+ */
560
+ getChart(params) {
561
+ return request(this._config, {
562
+ path: "/v2/access/analytics/posts/chart",
563
+ method: "GET",
564
+ query: {
565
+ "startDate": params.startDate,
566
+ "endDate": params.endDate,
567
+ "withTotal": params.withTotal,
568
+ "by": params.by
569
+ }
570
+ });
571
+ }
572
+ /**
573
+ * Top posts
574
+ */
575
+ getTop(params) {
576
+ return request(this._config, {
577
+ path: "/v2/access/analytics/posts/top",
578
+ method: "GET",
579
+ query: {
580
+ "by": params.by,
581
+ "startDate": params.startDate,
582
+ "endDate": params.endDate,
583
+ "limit": params.limit,
584
+ "offset": params.offset
585
+ }
586
+ });
587
+ }
588
+ };
589
+ var AccessAnalyticsStreamsNamespace = class {
590
+ constructor(config) {
591
+ this._config = config;
592
+ }
593
+ /**
594
+ * Streams chart
595
+ */
596
+ getChart(params) {
597
+ return request(this._config, {
598
+ path: "/v2/access/analytics/streams/chart",
599
+ method: "GET",
600
+ query: {
601
+ "startDate": params.startDate,
602
+ "endDate": params.endDate,
603
+ "withTotal": params.withTotal,
604
+ "by": params.by
605
+ }
606
+ });
607
+ }
608
+ /**
609
+ * Top streams
610
+ */
611
+ getTop(params) {
612
+ return request(this._config, {
613
+ path: "/v2/access/analytics/streams/top",
614
+ method: "GET",
615
+ query: {
616
+ "by": params.by,
617
+ "startDate": params.startDate,
618
+ "endDate": params.endDate,
619
+ "limit": params.limit,
620
+ "offset": params.offset
621
+ }
622
+ });
623
+ }
624
+ };
625
+ var AccessAnalyticsStoriesNamespace = class {
626
+ constructor(config) {
627
+ this._config = config;
628
+ }
629
+ /**
630
+ * Stories chart
631
+ */
632
+ getChart(params) {
633
+ return request(this._config, {
634
+ path: "/v2/access/analytics/stories/chart",
635
+ method: "GET",
636
+ query: {
637
+ "startDate": params.startDate,
638
+ "endDate": params.endDate,
639
+ "withTotal": params.withTotal,
640
+ "by": params.by
641
+ }
642
+ });
643
+ }
644
+ /**
645
+ * Top stories
646
+ */
647
+ getTop(params) {
648
+ return request(this._config, {
649
+ path: "/v2/access/analytics/stories/top",
650
+ method: "GET",
651
+ query: {
652
+ "by": params.by,
653
+ "startDate": params.startDate,
654
+ "endDate": params.endDate,
655
+ "limit": params.limit,
656
+ "offset": params.offset
657
+ }
658
+ });
659
+ }
660
+ };
661
+ var AccessAnalyticsMassMessagesNamespace = class {
662
+ constructor(config) {
663
+ this._config = config;
664
+ }
665
+ /**
666
+ * Mass messages chart
667
+ */
668
+ getChart(params) {
669
+ return request(this._config, {
670
+ path: "/v2/access/analytics/mass-messages/chart",
671
+ method: "GET",
672
+ query: {
673
+ "startDate": params.startDate,
674
+ "endDate": params.endDate,
675
+ "withTotal": params.withTotal
676
+ }
677
+ });
678
+ }
679
+ /**
680
+ * Mass messages purchased
681
+ */
682
+ getPurchased(params) {
683
+ return request(this._config, {
684
+ path: "/v2/access/analytics/mass-messages/purchased",
685
+ method: "GET",
686
+ query: {
687
+ "limit": params.limit,
688
+ "offset": params.offset
689
+ }
690
+ });
691
+ }
692
+ /**
693
+ * Mass message buyers
694
+ */
695
+ listBuyers(params) {
696
+ return request(this._config, {
697
+ path: `/v2/access/analytics/mass-messages/${encodeURIComponent(String(params.massMessageId))}/buyers`,
698
+ method: "GET",
699
+ query: {
700
+ "limit": params.limit,
701
+ "offset": params.offset,
702
+ "marker": params.marker
703
+ }
704
+ });
705
+ }
706
+ /**
707
+ * Mass message buyers
708
+ *
709
+ * Returns an async iterator that automatically paginates through all results.
710
+ */
711
+ async *iterateBuyers(params) {
712
+ let marker;
713
+ let fetched = 0;
714
+ const maxItems = params?.maxItems ?? Infinity;
715
+ while (fetched < maxItems) {
716
+ const response = await this.listBuyers({
717
+ ...params,
718
+ marker
719
+ });
720
+ for (const item of response.list) {
721
+ if (fetched >= maxItems) return;
722
+ yield item;
723
+ fetched++;
724
+ }
725
+ if (!response.hasMore) return;
726
+ marker = response.marker;
727
+ }
728
+ }
729
+ };
730
+ var AccessAnalyticsPromotionsNamespace = class {
731
+ constructor(config) {
732
+ this._config = config;
733
+ }
734
+ /**
735
+ * Promotions chart
736
+ */
737
+ getChart(params) {
738
+ return request(this._config, {
739
+ path: "/v2/access/analytics/promotions/chart",
740
+ method: "GET",
741
+ query: {
742
+ "startDate": params.startDate,
743
+ "endDate": params.endDate,
744
+ "withTotal": params.withTotal
745
+ }
746
+ });
747
+ }
748
+ /**
749
+ * Top promotions
750
+ */
751
+ getTop(params) {
752
+ return request(this._config, {
753
+ path: "/v2/access/analytics/promotions/top",
754
+ method: "GET",
755
+ query: {
756
+ "limit": params.limit,
757
+ "offset": params.offset,
758
+ "startDate": params.startDate,
759
+ "endDate": params.endDate
760
+ }
761
+ });
762
+ }
763
+ };
764
+ var AccessAnalyticsTrialsNamespace = class {
765
+ constructor(config) {
766
+ this._config = config;
767
+ }
768
+ /**
769
+ * Trials chart
770
+ */
771
+ getChart(params) {
772
+ return request(this._config, {
773
+ path: "/v2/access/analytics/trials/chart",
774
+ method: "GET",
775
+ query: {
776
+ "startDate": params.startDate,
777
+ "endDate": params.endDate,
778
+ "withTotal": params.withTotal
779
+ }
780
+ });
781
+ }
782
+ /**
783
+ * Top trials
784
+ */
785
+ getTop(params) {
786
+ return request(this._config, {
787
+ path: "/v2/access/analytics/trials/top",
788
+ method: "GET",
789
+ query: {
790
+ "limit": params.limit,
791
+ "offset": params.offset,
792
+ "startDate": params.startDate,
793
+ "endDate": params.endDate
794
+ }
795
+ });
796
+ }
797
+ };
798
+ var AccessAnalyticsCampaignsNamespace = class {
799
+ constructor(config) {
800
+ this._config = config;
801
+ }
802
+ /**
803
+ * Campaigns chart
804
+ */
805
+ getChart(params) {
806
+ return request(this._config, {
807
+ path: "/v2/access/analytics/campaigns/chart",
808
+ method: "GET",
809
+ query: {
810
+ "startDate": params.startDate,
811
+ "endDate": params.endDate,
812
+ "withTotal": params.withTotal
813
+ }
814
+ });
815
+ }
816
+ /**
817
+ * Top campaigns
818
+ */
819
+ getTop(params) {
820
+ return request(this._config, {
821
+ path: "/v2/access/analytics/campaigns/top",
822
+ method: "GET",
823
+ query: {
824
+ "limit": params.limit,
825
+ "offset": params.offset,
826
+ "startDate": params.startDate,
827
+ "endDate": params.endDate
828
+ }
829
+ });
830
+ }
831
+ /**
832
+ * Top campaigns
833
+ *
834
+ * Returns an async iterator that automatically paginates through all results.
835
+ */
836
+ async *iterateTop(params) {
837
+ let offset = 0;
838
+ let fetched = 0;
839
+ const limit = params?.pageSize ?? 20;
840
+ const maxItems = params?.maxItems ?? Infinity;
841
+ while (fetched < maxItems) {
842
+ const response = await this.getTop({
843
+ ...params,
844
+ limit: Math.min(limit, maxItems - fetched),
845
+ offset
846
+ });
847
+ for (const item of response.list) {
848
+ if (fetched >= maxItems) return;
849
+ yield item;
850
+ fetched++;
851
+ }
852
+ if (!response.hasMore) return;
853
+ offset = response.nextOffset ?? offset + response.list.length;
854
+ }
855
+ }
856
+ };
857
+ var AccessAnalyticsVisitorCountriesNamespace = class {
858
+ constructor(config) {
859
+ this._config = config;
860
+ }
861
+ /**
862
+ * Visitor countries chart
863
+ */
864
+ getChart(params) {
865
+ return request(this._config, {
866
+ path: "/v2/access/analytics/visitor-countries/chart",
867
+ method: "GET",
868
+ query: {
869
+ "startDate": params.startDate,
870
+ "endDate": params.endDate,
871
+ "by": params.by
872
+ }
873
+ });
874
+ }
875
+ /**
876
+ * Top visitor countries
877
+ */
878
+ getTop(params) {
879
+ return request(this._config, {
880
+ path: "/v2/access/analytics/visitor-countries/top",
881
+ method: "GET",
882
+ query: {
883
+ "startDate": params.startDate,
884
+ "endDate": params.endDate,
885
+ "by": params.by
886
+ }
887
+ });
888
+ }
889
+ };
890
+ var AccessAnalyticsNamespace = class {
891
+ constructor(config) {
892
+ this._config = config;
893
+ this.posts = new AccessAnalyticsPostsNamespace(config);
894
+ this.streams = new AccessAnalyticsStreamsNamespace(config);
895
+ this.stories = new AccessAnalyticsStoriesNamespace(config);
896
+ this.massMessages = new AccessAnalyticsMassMessagesNamespace(config);
897
+ this.promotions = new AccessAnalyticsPromotionsNamespace(config);
898
+ this.trials = new AccessAnalyticsTrialsNamespace(config);
899
+ this.campaigns = new AccessAnalyticsCampaignsNamespace(config);
900
+ this.visitorCountries = new AccessAnalyticsVisitorCountriesNamespace(config);
901
+ }
902
+ };
903
+ var AccessUsersListsNamespace = class {
904
+ constructor(config) {
905
+ this._config = config;
906
+ }
907
+ /**
908
+ * List user lists
909
+ */
910
+ list(params) {
911
+ return request(this._config, {
912
+ path: "/v2/access/users/lists",
913
+ method: "GET",
914
+ query: {
915
+ "limit": params.limit,
916
+ "offset": params.offset,
917
+ "query": params.query
918
+ }
919
+ });
920
+ }
921
+ /**
922
+ * List user lists
923
+ *
924
+ * Returns an async iterator that automatically paginates through all results.
925
+ */
926
+ async *iterate(params) {
927
+ let offset = 0;
928
+ let fetched = 0;
929
+ const limit = params?.pageSize ?? 20;
930
+ const maxItems = params?.maxItems ?? Infinity;
931
+ while (fetched < maxItems) {
932
+ const response = await this.list({
933
+ ...params,
934
+ limit: Math.min(limit, maxItems - fetched),
935
+ offset
936
+ });
937
+ for (const item of response.list) {
938
+ if (fetched >= maxItems) return;
939
+ yield item;
940
+ fetched++;
941
+ }
942
+ if (!response.hasMore) return;
943
+ offset = response.nextOffset ?? offset + response.list.length;
944
+ }
945
+ }
946
+ /**
947
+ * Create user list
948
+ */
949
+ create(params) {
950
+ return request(this._config, {
951
+ path: "/v2/access/users/lists",
952
+ method: "POST",
953
+ body: params.body
954
+ });
955
+ }
956
+ /**
957
+ * Get user list
958
+ */
959
+ get(params) {
960
+ return request(this._config, {
961
+ path: `/v2/access/users/lists/${encodeURIComponent(String(params.listId))}`,
962
+ method: "GET"
963
+ });
964
+ }
965
+ /**
966
+ * Update user list
967
+ */
968
+ update(params) {
969
+ return request(this._config, {
970
+ path: `/v2/access/users/lists/${encodeURIComponent(String(params.listId))}`,
971
+ method: "PATCH",
972
+ body: params.body
973
+ });
974
+ }
975
+ /**
976
+ * Delete user list
977
+ */
978
+ delete(params) {
979
+ return request(this._config, {
980
+ path: `/v2/access/users/lists/${encodeURIComponent(String(params.listId))}`,
981
+ method: "DELETE"
982
+ });
983
+ }
984
+ /**
985
+ * Add user to multiple lists
986
+ */
987
+ create2(params) {
988
+ return request(this._config, {
989
+ path: `/v2/access/users/${encodeURIComponent(String(params.userId))}/lists`,
990
+ method: "POST",
991
+ body: params.body
992
+ });
993
+ }
994
+ /**
995
+ * List users in user list
996
+ */
997
+ listUsers(params) {
998
+ return request(this._config, {
999
+ path: `/v2/access/users/lists/${encodeURIComponent(String(params.listId))}/users`,
1000
+ method: "GET",
1001
+ query: {
1002
+ "limit": params.limit,
1003
+ "offset": params.offset
1004
+ }
1005
+ });
1006
+ }
1007
+ /**
1008
+ * List users in user list
1009
+ *
1010
+ * Returns an async iterator that automatically paginates through all results.
1011
+ */
1012
+ async *iterateUsers(params) {
1013
+ let offset = 0;
1014
+ let fetched = 0;
1015
+ const limit = params?.pageSize ?? 20;
1016
+ const maxItems = params?.maxItems ?? Infinity;
1017
+ while (fetched < maxItems) {
1018
+ const response = await this.listUsers({
1019
+ ...params,
1020
+ limit: Math.min(limit, maxItems - fetched),
1021
+ offset
1022
+ });
1023
+ for (const item of response.list) {
1024
+ if (fetched >= maxItems) return;
1025
+ yield item;
1026
+ fetched++;
1027
+ }
1028
+ if (!response.hasMore) return;
1029
+ offset = response.nextOffset ?? offset + response.list.length;
1030
+ }
1031
+ }
1032
+ /**
1033
+ * Add user to list
1034
+ */
1035
+ createUsers(params) {
1036
+ return request(this._config, {
1037
+ path: `/v2/access/users/lists/${encodeURIComponent(String(params.listId))}/users/${encodeURIComponent(String(params.userId))}`,
1038
+ method: "POST"
1039
+ });
1040
+ }
1041
+ /**
1042
+ * Remove user from user list
1043
+ */
1044
+ deleteUsers(params) {
1045
+ return request(this._config, {
1046
+ path: `/v2/access/users/lists/${encodeURIComponent(String(params.listId))}/users/${encodeURIComponent(String(params.userId))}`,
1047
+ method: "DELETE"
1048
+ });
1049
+ }
1050
+ };
1051
+ var AccessUsersNamespace = class {
1052
+ constructor(config) {
1053
+ this._config = config;
1054
+ this.lists = new AccessUsersListsNamespace(config);
1055
+ }
1056
+ /**
1057
+ * Get user
1058
+ */
1059
+ get(params) {
1060
+ return request(this._config, {
1061
+ path: `/v2/access/users/${encodeURIComponent(String(params.userId))}`,
1062
+ method: "GET"
1063
+ });
1064
+ }
1065
+ /**
1066
+ * List user posts
1067
+ */
1068
+ listPosts(params) {
1069
+ return request(this._config, {
1070
+ path: `/v2/access/users/${encodeURIComponent(String(params.userId))}/posts`,
1071
+ method: "GET",
1072
+ query: {
1073
+ "limit": params.limit,
1074
+ "sortBy": params.sortBy,
1075
+ "sortDirection": params.sortDirection,
1076
+ "pinned": params.pinned,
1077
+ "includePostCounts": params.includePostCounts,
1078
+ "beforePublishTime": params.beforePublishTime
1079
+ }
1080
+ });
1081
+ }
1082
+ /**
1083
+ * List restricted users
1084
+ */
1085
+ getRestrict(params) {
1086
+ return request(this._config, {
1087
+ path: "/v2/access/users/restrict",
1088
+ method: "GET",
1089
+ query: {
1090
+ "limit": params.limit,
1091
+ "offset": params.offset
1092
+ }
1093
+ });
1094
+ }
1095
+ /**
1096
+ * List restricted users
1097
+ *
1098
+ * Returns an async iterator that automatically paginates through all results.
1099
+ */
1100
+ async *iterateRestrict(params) {
1101
+ let offset = 0;
1102
+ let fetched = 0;
1103
+ const limit = params?.pageSize ?? 20;
1104
+ const maxItems = params?.maxItems ?? Infinity;
1105
+ while (fetched < maxItems) {
1106
+ const response = await this.getRestrict({
1107
+ ...params,
1108
+ limit: Math.min(limit, maxItems - fetched),
1109
+ offset
1110
+ });
1111
+ for (const item of response.list) {
1112
+ if (fetched >= maxItems) return;
1113
+ yield item;
1114
+ fetched++;
1115
+ }
1116
+ if (!response.hasMore) return;
1117
+ offset = response.nextOffset ?? offset + response.list.length;
1118
+ }
1119
+ }
1120
+ /**
1121
+ * Restrict user
1122
+ */
1123
+ restrict(params) {
1124
+ return request(this._config, {
1125
+ path: `/v2/access/users/${encodeURIComponent(String(params.userId))}/restrict`,
1126
+ method: "POST"
1127
+ });
1128
+ }
1129
+ /**
1130
+ * Unrestrict user
1131
+ */
1132
+ restrict2(params) {
1133
+ return request(this._config, {
1134
+ path: `/v2/access/users/${encodeURIComponent(String(params.userId))}/restrict`,
1135
+ method: "DELETE"
1136
+ });
1137
+ }
1138
+ /**
1139
+ * List blocked users
1140
+ */
1141
+ getBlocked(params) {
1142
+ return request(this._config, {
1143
+ path: "/v2/access/users/blocked",
1144
+ method: "GET",
1145
+ query: {
1146
+ "limit": params.limit,
1147
+ "offset": params.offset
1148
+ }
1149
+ });
1150
+ }
1151
+ /**
1152
+ * List blocked users
1153
+ *
1154
+ * Returns an async iterator that automatically paginates through all results.
1155
+ */
1156
+ async *iterateBlocked(params) {
1157
+ let offset = 0;
1158
+ let fetched = 0;
1159
+ const limit = params?.pageSize ?? 20;
1160
+ const maxItems = params?.maxItems ?? Infinity;
1161
+ while (fetched < maxItems) {
1162
+ const response = await this.getBlocked({
1163
+ ...params,
1164
+ limit: Math.min(limit, maxItems - fetched),
1165
+ offset
1166
+ });
1167
+ for (const item of response.list) {
1168
+ if (fetched >= maxItems) return;
1169
+ yield item;
1170
+ fetched++;
1171
+ }
1172
+ if (!response.hasMore) return;
1173
+ offset = response.nextOffset ?? offset + response.list.length;
1174
+ }
1175
+ }
1176
+ /**
1177
+ * List users by IDs
1178
+ */
1179
+ getList(params) {
1180
+ return request(this._config, {
1181
+ path: "/v2/access/users/list",
1182
+ method: "GET",
1183
+ query: {
1184
+ "userIds": params.userIds
1185
+ }
1186
+ });
1187
+ }
1188
+ /**
1189
+ * Search performers
1190
+ */
1191
+ search(params) {
1192
+ return request(this._config, {
1193
+ path: "/v2/access/users/search",
1194
+ method: "GET",
1195
+ query: {
1196
+ "limit": params.limit,
1197
+ "offset": params.offset,
1198
+ "query": params.query
1199
+ }
1200
+ });
1201
+ }
1202
+ };
1203
+ var AccessChatsNamespace = class {
1204
+ constructor(config) {
1205
+ this._config = config;
1206
+ }
1207
+ /**
1208
+ * Chats list
1209
+ */
1210
+ list(params) {
1211
+ return request(this._config, {
1212
+ path: "/v2/access/chats",
1213
+ method: "GET",
1214
+ query: {
1215
+ "limit": params.limit,
1216
+ "offset": params.offset,
1217
+ "order": params.order,
1218
+ "filter": params.filter,
1219
+ "query": params.query,
1220
+ "userListId": params.userListId
1221
+ }
1222
+ });
1223
+ }
1224
+ /**
1225
+ * Chats list
1226
+ *
1227
+ * Returns an async iterator that automatically paginates through all results.
1228
+ */
1229
+ async *iterate(params) {
1230
+ let offset = 0;
1231
+ let fetched = 0;
1232
+ const limit = params?.pageSize ?? 20;
1233
+ const maxItems = params?.maxItems ?? Infinity;
1234
+ while (fetched < maxItems) {
1235
+ const response = await this.list({
1236
+ ...params,
1237
+ limit: Math.min(limit, maxItems - fetched),
1238
+ offset
1239
+ });
1240
+ for (const item of response.list) {
1241
+ if (fetched >= maxItems) return;
1242
+ yield item;
1243
+ fetched++;
1244
+ }
1245
+ if (!response.hasMore) return;
1246
+ offset = response.nextOffset ?? offset + response.list.length;
1247
+ }
1248
+ }
1249
+ /**
1250
+ * Chat messages
1251
+ */
1252
+ listMessages(params) {
1253
+ return request(this._config, {
1254
+ path: `/v2/access/chats/${encodeURIComponent(String(params.userId))}/messages`,
1255
+ method: "GET",
1256
+ query: {
1257
+ "limit": params.limit,
1258
+ "offset": params.offset,
1259
+ "query": params.query
1260
+ }
1261
+ });
1262
+ }
1263
+ /**
1264
+ * Chat messages
1265
+ *
1266
+ * Returns an async iterator that automatically paginates through all results.
1267
+ */
1268
+ async *iterateMessages(params) {
1269
+ let offset = 0;
1270
+ let fetched = 0;
1271
+ const limit = params?.pageSize ?? 20;
1272
+ const maxItems = params?.maxItems ?? Infinity;
1273
+ while (fetched < maxItems) {
1274
+ const response = await this.listMessages({
1275
+ ...params,
1276
+ limit: Math.min(limit, maxItems - fetched),
1277
+ offset
1278
+ });
1279
+ for (const item of response.list) {
1280
+ if (fetched >= maxItems) return;
1281
+ yield item;
1282
+ fetched++;
1283
+ }
1284
+ if (!response.hasMore) return;
1285
+ offset = response.nextOffset ?? offset + response.list.length;
1286
+ }
1287
+ }
1288
+ /**
1289
+ * Send chat message
1290
+ */
1291
+ createMessages(params) {
1292
+ return request(this._config, {
1293
+ path: `/v2/access/chats/${encodeURIComponent(String(params.userId))}/messages`,
1294
+ method: "POST",
1295
+ body: params.body
1296
+ });
1297
+ }
1298
+ /**
1299
+ * Unsend chat message
1300
+ */
1301
+ deleteMessages(params) {
1302
+ return request(this._config, {
1303
+ path: `/v2/access/chats/${encodeURIComponent(String(params.userId))}/messages/${encodeURIComponent(String(params.messageId))}`,
1304
+ method: "DELETE",
1305
+ body: params.body
1306
+ });
1307
+ }
1308
+ /**
1309
+ * Get chat media
1310
+ */
1311
+ listMedia(params) {
1312
+ return request(this._config, {
1313
+ path: `/v2/access/chats/${encodeURIComponent(String(params.userId))}/media`,
1314
+ method: "GET",
1315
+ query: {
1316
+ "limit": params.limit,
1317
+ "offset": params.offset,
1318
+ "skip_users": params.skipUsers,
1319
+ "last_id": params.lastId,
1320
+ "opened": params.opened,
1321
+ "type": params.type
1322
+ }
1323
+ });
1324
+ }
1325
+ /**
1326
+ * Get chat media
1327
+ *
1328
+ * Returns an async iterator that automatically paginates through all results.
1329
+ */
1330
+ async *iterateMedia(params) {
1331
+ let offset = 0;
1332
+ let fetched = 0;
1333
+ const limit = params?.pageSize ?? 20;
1334
+ const maxItems = params?.maxItems ?? Infinity;
1335
+ while (fetched < maxItems) {
1336
+ const response = await this.listMedia({
1337
+ ...params,
1338
+ limit: Math.min(limit, maxItems - fetched),
1339
+ offset
1340
+ });
1341
+ for (const item of response.list) {
1342
+ if (fetched >= maxItems) return;
1343
+ yield item;
1344
+ fetched++;
1345
+ }
1346
+ if (!response.hasMore) return;
1347
+ offset = response.nextOffset ?? offset + response.list.length;
1348
+ }
1349
+ }
1350
+ };
1351
+ var AccessSubscribersNamespace = class {
1352
+ constructor(config) {
1353
+ this._config = config;
1354
+ }
1355
+ /**
1356
+ * List subscribers
1357
+ */
1358
+ list(params) {
1359
+ return request(this._config, {
1360
+ path: "/v2/access/subscribers",
1361
+ method: "GET",
1362
+ query: {
1363
+ "query": params.query,
1364
+ "filter": params.filter,
1365
+ "type": params.type,
1366
+ "startDate": params.startDate,
1367
+ "endDate": params.endDate,
1368
+ "latestType": params.latestType,
1369
+ "limit": params.limit,
1370
+ "offset": params.offset
1371
+ }
1372
+ });
1373
+ }
1374
+ /**
1375
+ * List subscribers
1376
+ *
1377
+ * Returns an async iterator that automatically paginates through all results.
1378
+ */
1379
+ async *iterate(params) {
1380
+ let offset = 0;
1381
+ let fetched = 0;
1382
+ const limit = params?.pageSize ?? 20;
1383
+ const maxItems = params?.maxItems ?? Infinity;
1384
+ while (fetched < maxItems) {
1385
+ const response = await this.list({
1386
+ ...params,
1387
+ limit: Math.min(limit, maxItems - fetched),
1388
+ offset
1389
+ });
1390
+ for (const item of response.list) {
1391
+ if (fetched >= maxItems) return;
1392
+ yield item;
1393
+ fetched++;
1394
+ }
1395
+ if (!response.hasMore) return;
1396
+ offset = response.nextOffset ?? offset + response.list.length;
1397
+ }
1398
+ }
1399
+ /**
1400
+ * Update subscriber note
1401
+ */
1402
+ setNote(params) {
1403
+ return request(this._config, {
1404
+ path: `/v2/access/subscribers/${encodeURIComponent(String(params.userId))}/note`,
1405
+ method: "PUT",
1406
+ body: params.body
1407
+ });
1408
+ }
1409
+ /**
1410
+ * Apply discount to subscriber
1411
+ */
1412
+ setDiscount(params) {
1413
+ return request(this._config, {
1414
+ path: `/v2/access/subscribers/${encodeURIComponent(String(params.userId))}/discount`,
1415
+ method: "PUT",
1416
+ body: params.body
1417
+ });
1418
+ }
1419
+ /**
1420
+ * Set custom name for subscriber
1421
+ */
1422
+ setCustomName(params) {
1423
+ return request(this._config, {
1424
+ path: `/v2/access/subscribers/${encodeURIComponent(String(params.userId))}/custom-name`,
1425
+ method: "PUT",
1426
+ body: params.body
1427
+ });
1428
+ }
1429
+ };
1430
+ var AccessSubscriptionsNamespace = class {
1431
+ constructor(config) {
1432
+ this._config = config;
1433
+ }
1434
+ /**
1435
+ * List subscriptions
1436
+ */
1437
+ list(params) {
1438
+ return request(this._config, {
1439
+ path: "/v2/access/subscriptions",
1440
+ method: "GET",
1441
+ query: {
1442
+ "limit": params.limit,
1443
+ "offset": params.offset,
1444
+ "query": params.query,
1445
+ "filter": params.filter,
1446
+ "type": params.type
1447
+ }
1448
+ });
1449
+ }
1450
+ /**
1451
+ * List subscriptions
1452
+ *
1453
+ * Returns an async iterator that automatically paginates through all results.
1454
+ */
1455
+ async *iterate(params) {
1456
+ let offset = 0;
1457
+ let fetched = 0;
1458
+ const limit = params?.pageSize ?? 20;
1459
+ const maxItems = params?.maxItems ?? Infinity;
1460
+ while (fetched < maxItems) {
1461
+ const response = await this.list({
1462
+ ...params,
1463
+ limit: Math.min(limit, maxItems - fetched),
1464
+ offset
1465
+ });
1466
+ for (const item of response.list) {
1467
+ if (fetched >= maxItems) return;
1468
+ yield item;
1469
+ fetched++;
1470
+ }
1471
+ if (!response.hasMore) return;
1472
+ offset = response.nextOffset ?? offset + response.list.length;
1473
+ }
1474
+ }
1475
+ /**
1476
+ * Get subscription
1477
+ */
1478
+ get(params) {
1479
+ return request(this._config, {
1480
+ path: `/v2/access/subscriptions/${encodeURIComponent(String(params.subscriptionId))}`,
1481
+ method: "GET"
1482
+ });
1483
+ }
1484
+ /**
1485
+ * Get subscription counts
1486
+ */
1487
+ getCount() {
1488
+ return request(this._config, {
1489
+ path: "/v2/access/subscriptions/count",
1490
+ method: "GET"
1491
+ });
1492
+ }
1493
+ /**
1494
+ * Get subscription history
1495
+ */
1496
+ getHistory(params) {
1497
+ return request(this._config, {
1498
+ path: `/v2/access/subscriptions/${encodeURIComponent(String(params.subscriptionId))}/history`,
1499
+ method: "GET",
1500
+ query: {
1501
+ "all": params.all
1502
+ }
1503
+ });
1504
+ }
1505
+ };
1506
+ var AccessPromotionsTrackingLinksNamespace = class {
1507
+ constructor(config) {
1508
+ this._config = config;
1509
+ }
1510
+ /**
1511
+ * List tracking links
1512
+ */
1513
+ list(params) {
1514
+ return request(this._config, {
1515
+ path: "/v2/access/promotions/tracking-links",
1516
+ method: "GET",
1517
+ query: {
1518
+ "limit": params.limit,
1519
+ "offset": params.offset,
1520
+ "pagination": params.pagination,
1521
+ "with_deleted": params.withDeleted,
1522
+ "sorting_deleted": params.sortingDeleted,
1523
+ "stats": params.stats
1524
+ }
1525
+ });
1526
+ }
1527
+ /**
1528
+ * List tracking links
1529
+ *
1530
+ * Returns an async iterator that automatically paginates through all results.
1531
+ */
1532
+ async *iterate(params) {
1533
+ let offset = 0;
1534
+ let fetched = 0;
1535
+ const limit = params?.pageSize ?? 20;
1536
+ const maxItems = params?.maxItems ?? Infinity;
1537
+ while (fetched < maxItems) {
1538
+ const response = await this.list({
1539
+ ...params,
1540
+ limit: Math.min(limit, maxItems - fetched),
1541
+ offset
1542
+ });
1543
+ for (const item of response.list) {
1544
+ if (fetched >= maxItems) return;
1545
+ yield item;
1546
+ fetched++;
1547
+ }
1548
+ if (!response.hasMore) return;
1549
+ offset = response.nextOffset ?? offset + response.list.length;
1550
+ }
1551
+ }
1552
+ /**
1553
+ * Create tracking link
1554
+ */
1555
+ create(params) {
1556
+ return request(this._config, {
1557
+ path: "/v2/access/promotions/tracking-links",
1558
+ method: "POST",
1559
+ body: params.body
1560
+ });
1561
+ }
1562
+ /**
1563
+ * Get tracking link
1564
+ */
1565
+ get(params) {
1566
+ return request(this._config, {
1567
+ path: `/v2/access/promotions/tracking-links/${encodeURIComponent(String(params.trackingLinkId))}`,
1568
+ method: "GET"
1569
+ });
1570
+ }
1571
+ /**
1572
+ * Update tracking link
1573
+ */
1574
+ replace(params) {
1575
+ return request(this._config, {
1576
+ path: `/v2/access/promotions/tracking-links/${encodeURIComponent(String(params.trackingLinkId))}`,
1577
+ method: "PUT",
1578
+ body: params.body
1579
+ });
1580
+ }
1581
+ /**
1582
+ * Delete tracking link
1583
+ */
1584
+ delete(params) {
1585
+ return request(this._config, {
1586
+ path: `/v2/access/promotions/tracking-links/${encodeURIComponent(String(params.trackingLinkId))}`,
1587
+ method: "DELETE"
1588
+ });
1589
+ }
1590
+ /**
1591
+ * Share tracking link access
1592
+ */
1593
+ createShareAccess(params) {
1594
+ return request(this._config, {
1595
+ path: "/v2/access/promotions/tracking-links/share-access",
1596
+ method: "POST",
1597
+ body: params.body
1598
+ });
1599
+ }
1600
+ /**
1601
+ * Revoke tracking link access
1602
+ */
1603
+ deleteShareAccess(params) {
1604
+ return request(this._config, {
1605
+ path: "/v2/access/promotions/tracking-links/share-access",
1606
+ method: "DELETE",
1607
+ body: params.body
1608
+ });
1609
+ }
1610
+ /**
1611
+ * Get tracking link claimers
1612
+ */
1613
+ listClaimers(params) {
1614
+ return request(this._config, {
1615
+ path: `/v2/access/promotions/tracking-links/${encodeURIComponent(String(params.trackingLinkId))}/claimers`,
1616
+ method: "GET"
1617
+ });
1618
+ }
1619
+ };
1620
+ var AccessPromotionsTrialLinksNamespace = class {
1621
+ constructor(config) {
1622
+ this._config = config;
1623
+ }
1624
+ /**
1625
+ * List trial links
1626
+ */
1627
+ list(params) {
1628
+ return request(this._config, {
1629
+ path: "/v2/access/promotions/trial-links",
1630
+ method: "GET",
1631
+ query: {
1632
+ "limit": params.limit,
1633
+ "offset": params.offset
1634
+ }
1635
+ });
1636
+ }
1637
+ /**
1638
+ * Create trial link
1639
+ */
1640
+ create(params) {
1641
+ return request(this._config, {
1642
+ path: "/v2/access/promotions/trial-links",
1643
+ method: "POST",
1644
+ body: params.body
1645
+ });
1646
+ }
1647
+ /**
1648
+ * Get trial link
1649
+ */
1650
+ get(params) {
1651
+ return request(this._config, {
1652
+ path: `/v2/access/promotions/trial-links/${encodeURIComponent(String(params.trialLinkId))}`,
1653
+ method: "GET"
1654
+ });
1655
+ }
1656
+ /**
1657
+ * Update trial link
1658
+ */
1659
+ replace(params) {
1660
+ return request(this._config, {
1661
+ path: `/v2/access/promotions/trial-links/${encodeURIComponent(String(params.trialLinkId))}`,
1662
+ method: "PUT",
1663
+ body: params.body
1664
+ });
1665
+ }
1666
+ /**
1667
+ * Delete trial link
1668
+ */
1669
+ delete(params) {
1670
+ return request(this._config, {
1671
+ path: `/v2/access/promotions/trial-links/${encodeURIComponent(String(params.trialLinkId))}`,
1672
+ method: "DELETE"
1673
+ });
1674
+ }
1675
+ /**
1676
+ * Share trial link access
1677
+ */
1678
+ createShareAccess(params) {
1679
+ return request(this._config, {
1680
+ path: "/v2/access/promotions/trial-links/share-access",
1681
+ method: "POST",
1682
+ body: params.body
1683
+ });
1684
+ }
1685
+ /**
1686
+ * Revoke trial link access
1687
+ */
1688
+ deleteShareAccess(params) {
1689
+ return request(this._config, {
1690
+ path: "/v2/access/promotions/trial-links/share-access",
1691
+ method: "DELETE",
1692
+ body: params.body
1693
+ });
1694
+ }
1695
+ };
1696
+ var AccessPromotionsNamespace = class {
1697
+ constructor(config) {
1698
+ this._config = config;
1699
+ this.trackingLinks = new AccessPromotionsTrackingLinksNamespace(config);
1700
+ this.trialLinks = new AccessPromotionsTrialLinksNamespace(config);
1701
+ }
1702
+ /**
1703
+ * List promotions
1704
+ */
1705
+ list(params) {
1706
+ return request(this._config, {
1707
+ path: "/v2/access/promotions",
1708
+ method: "GET",
1709
+ query: {
1710
+ "limit": params.limit,
1711
+ "offset": params.offset
1712
+ }
1713
+ });
1714
+ }
1715
+ /**
1716
+ * Create promotion
1717
+ */
1718
+ create(params) {
1719
+ return request(this._config, {
1720
+ path: "/v2/access/promotions",
1721
+ method: "POST",
1722
+ body: params.body
1723
+ });
1724
+ }
1725
+ /**
1726
+ * Get promotion
1727
+ */
1728
+ get(params) {
1729
+ return request(this._config, {
1730
+ path: `/v2/access/promotions/${encodeURIComponent(String(params.promotionId))}`,
1731
+ method: "GET"
1732
+ });
1733
+ }
1734
+ /**
1735
+ * Update promotion
1736
+ */
1737
+ replace(params) {
1738
+ return request(this._config, {
1739
+ path: `/v2/access/promotions/${encodeURIComponent(String(params.promotionId))}`,
1740
+ method: "PUT",
1741
+ body: params.body
1742
+ });
1743
+ }
1744
+ /**
1745
+ * Delete promotion
1746
+ */
1747
+ delete(params) {
1748
+ return request(this._config, {
1749
+ path: `/v2/access/promotions/${encodeURIComponent(String(params.promotionId))}`,
1750
+ method: "DELETE"
1751
+ });
1752
+ }
1753
+ /**
1754
+ * List bundles
1755
+ */
1756
+ listBundles(params) {
1757
+ return request(this._config, {
1758
+ path: "/v2/access/promotions/bundles",
1759
+ method: "GET",
1760
+ query: {
1761
+ "limit": params.limit,
1762
+ "offset": params.offset
1763
+ }
1764
+ });
1765
+ }
1766
+ /**
1767
+ * Create bundle
1768
+ */
1769
+ createBundles(params) {
1770
+ return request(this._config, {
1771
+ path: "/v2/access/promotions/bundles",
1772
+ method: "POST",
1773
+ body: params.body
1774
+ });
1775
+ }
1776
+ /**
1777
+ * Get bundle
1778
+ */
1779
+ getBundles(params) {
1780
+ return request(this._config, {
1781
+ path: `/v2/access/promotions/bundles/${encodeURIComponent(String(params.bundleId))}`,
1782
+ method: "GET"
1783
+ });
1784
+ }
1785
+ /**
1786
+ * Update bundle
1787
+ */
1788
+ replaceBundles(params) {
1789
+ return request(this._config, {
1790
+ path: `/v2/access/promotions/bundles/${encodeURIComponent(String(params.bundleId))}`,
1791
+ method: "PUT",
1792
+ body: params.body
1793
+ });
1794
+ }
1795
+ /**
1796
+ * Delete bundle
1797
+ */
1798
+ deleteBundles(params) {
1799
+ return request(this._config, {
1800
+ path: `/v2/access/promotions/bundles/${encodeURIComponent(String(params.bundleId))}`,
1801
+ method: "DELETE"
1802
+ });
1803
+ }
1804
+ /**
1805
+ * Finish promotion
1806
+ */
1807
+ finish(params) {
1808
+ return request(this._config, {
1809
+ path: `/v2/access/promotions/${encodeURIComponent(String(params.promotionId))}/finish`,
1810
+ method: "POST"
1811
+ });
1812
+ }
1813
+ };
1814
+ var AccessVaultListsNamespace = class {
1815
+ constructor(config) {
1816
+ this._config = config;
1817
+ }
1818
+ /**
1819
+ * List vault folders
1820
+ */
1821
+ list(params) {
1822
+ return request(this._config, {
1823
+ path: "/v2/access/vault/lists",
1824
+ method: "GET",
1825
+ query: {
1826
+ "limit": params.limit,
1827
+ "offset": params.offset,
1828
+ "query": params.query
1829
+ }
1830
+ });
1831
+ }
1832
+ /**
1833
+ * List vault folders
1834
+ *
1835
+ * Returns an async iterator that automatically paginates through all results.
1836
+ */
1837
+ async *iterate(params) {
1838
+ let offset = 0;
1839
+ let fetched = 0;
1840
+ const limit = params?.pageSize ?? 20;
1841
+ const maxItems = params?.maxItems ?? Infinity;
1842
+ while (fetched < maxItems) {
1843
+ const response = await this.list({
1844
+ ...params,
1845
+ limit: Math.min(limit, maxItems - fetched),
1846
+ offset
1847
+ });
1848
+ for (const item of response.list) {
1849
+ if (fetched >= maxItems) return;
1850
+ yield item;
1851
+ fetched++;
1852
+ }
1853
+ if (!response.hasMore) return;
1854
+ offset = response.nextOffset ?? offset + response.list.length;
1855
+ }
1856
+ }
1857
+ /**
1858
+ * Create vault list
1859
+ */
1860
+ create(params) {
1861
+ return request(this._config, {
1862
+ path: "/v2/access/vault/lists",
1863
+ method: "POST",
1864
+ body: params.body
1865
+ });
1866
+ }
1867
+ /**
1868
+ * Update vault list
1869
+ */
1870
+ update(params) {
1871
+ return request(this._config, {
1872
+ path: `/v2/access/vault/lists/${encodeURIComponent(String(params.listId))}`,
1873
+ method: "PATCH",
1874
+ body: params.body
1875
+ });
1876
+ }
1877
+ /**
1878
+ * Delete vault list
1879
+ */
1880
+ delete(params) {
1881
+ return request(this._config, {
1882
+ path: `/v2/access/vault/lists/${encodeURIComponent(String(params.listId))}`,
1883
+ method: "DELETE"
1884
+ });
1885
+ }
1886
+ /**
1887
+ * List media in vault list
1888
+ */
1889
+ listMedia(params) {
1890
+ return request(this._config, {
1891
+ path: `/v2/access/vault/lists/${encodeURIComponent(String(params.listId))}/media`,
1892
+ method: "GET",
1893
+ query: {
1894
+ "limit": params.limit,
1895
+ "offset": params.offset,
1896
+ "sortBy": params.sortBy,
1897
+ "sortDirection": params.sortDirection,
1898
+ "query": params.query,
1899
+ "mediaType": params.mediaType
1900
+ }
1901
+ });
1902
+ }
1903
+ /**
1904
+ * List media in vault list
1905
+ *
1906
+ * Returns an async iterator that automatically paginates through all results.
1907
+ */
1908
+ async *iterateMedia(params) {
1909
+ let offset = 0;
1910
+ let fetched = 0;
1911
+ const limit = params?.pageSize ?? 20;
1912
+ const maxItems = params?.maxItems ?? Infinity;
1913
+ while (fetched < maxItems) {
1914
+ const response = await this.listMedia({
1915
+ ...params,
1916
+ limit: Math.min(limit, maxItems - fetched),
1917
+ offset
1918
+ });
1919
+ for (const item of response.list) {
1920
+ if (fetched >= maxItems) return;
1921
+ yield item;
1922
+ fetched++;
1923
+ }
1924
+ if (!response.hasMore) return;
1925
+ offset = response.nextOffset ?? offset + response.list.length;
1926
+ }
1927
+ }
1928
+ /**
1929
+ * Add media to vault list
1930
+ */
1931
+ createMedia(params) {
1932
+ return request(this._config, {
1933
+ path: `/v2/access/vault/lists/${encodeURIComponent(String(params.listId))}/media`,
1934
+ method: "POST",
1935
+ body: params.body
1936
+ });
1937
+ }
1938
+ };
1939
+ var AccessVaultNamespace = class {
1940
+ constructor(config) {
1941
+ this._config = config;
1942
+ this.lists = new AccessVaultListsNamespace(config);
1943
+ }
1944
+ /**
1945
+ * List vault media
1946
+ */
1947
+ listMedia(params) {
1948
+ return request(this._config, {
1949
+ path: "/v2/access/vault/media",
1950
+ method: "GET",
1951
+ query: {
1952
+ "limit": params.limit,
1953
+ "offset": params.offset,
1954
+ "sortBy": params.sortBy,
1955
+ "sortDirection": params.sortDirection,
1956
+ "listId": params.listId,
1957
+ "query": params.query,
1958
+ "mediaType": params.mediaType
1959
+ }
1960
+ });
1961
+ }
1962
+ /**
1963
+ * List vault media
1964
+ *
1965
+ * Returns an async iterator that automatically paginates through all results.
1966
+ */
1967
+ async *iterateMedia(params) {
1968
+ let offset = 0;
1969
+ let fetched = 0;
1970
+ const limit = params?.pageSize ?? 20;
1971
+ const maxItems = params?.maxItems ?? Infinity;
1972
+ while (fetched < maxItems) {
1973
+ const response = await this.listMedia({
1974
+ ...params,
1975
+ limit: Math.min(limit, maxItems - fetched),
1976
+ offset
1977
+ });
1978
+ for (const item of response.list) {
1979
+ if (fetched >= maxItems) return;
1980
+ yield item;
1981
+ fetched++;
1982
+ }
1983
+ if (!response.hasMore) return;
1984
+ offset = response.nextOffset ?? offset + response.list.length;
1985
+ }
1986
+ }
1987
+ };
1988
+ var AccessUploadsNamespace = class {
1989
+ constructor(config) {
1990
+ this._config = config;
1991
+ }
1992
+ /**
1993
+ * Upload single-part media and finalize (No need to call /complete after upload if using this endpoint)
1994
+ */
1995
+ replace(params) {
1996
+ return request(this._config, {
1997
+ path: `/v2/access/uploads/${encodeURIComponent(String(params.mediaUploadId))}`,
1998
+ method: "PUT"
1999
+ });
2000
+ }
2001
+ /**
2002
+ * Check if media already exists in vault
2003
+ */
2004
+ check(params) {
2005
+ return request(this._config, {
2006
+ path: "/v2/access/uploads/check",
2007
+ method: "POST",
2008
+ body: params.body
2009
+ });
2010
+ }
2011
+ /**
2012
+ * Initialize media upload
2013
+ */
2014
+ init(params) {
2015
+ return request(this._config, {
2016
+ path: "/v2/access/uploads/init",
2017
+ method: "POST",
2018
+ body: params.body
2019
+ });
2020
+ }
2021
+ /**
2022
+ * Upload chunk to managed media upload
2023
+ */
2024
+ replaceParts(params) {
2025
+ return request(this._config, {
2026
+ path: `/v2/access/uploads/${encodeURIComponent(String(params.mediaUploadId))}/parts/${encodeURIComponent(String(params.partNumber))}`,
2027
+ method: "PUT"
2028
+ });
2029
+ }
2030
+ /**
2031
+ * Finalize media upload
2032
+ */
2033
+ complete(params) {
2034
+ return request(this._config, {
2035
+ path: "/v2/access/uploads/complete",
2036
+ method: "POST",
2037
+ body: params.body
2038
+ });
2039
+ }
2040
+ };
2041
+ var AccessNamespace = class {
2042
+ constructor(config) {
2043
+ this._config = config;
2044
+ this.self = new AccessSelfNamespace(config);
2045
+ this.earnings = new AccessEarningsNamespace(config);
2046
+ this.analytics = new AccessAnalyticsNamespace(config);
2047
+ this.users = new AccessUsersNamespace(config);
2048
+ this.chats = new AccessChatsNamespace(config);
2049
+ this.subscribers = new AccessSubscribersNamespace(config);
2050
+ this.subscriptions = new AccessSubscriptionsNamespace(config);
2051
+ this.promotions = new AccessPromotionsNamespace(config);
2052
+ this.vault = new AccessVaultNamespace(config);
2053
+ this.uploads = new AccessUploadsNamespace(config);
2054
+ }
2055
+ /**
2056
+ * List own posts
2057
+ */
2058
+ listPosts(params) {
2059
+ return request(this._config, {
2060
+ path: "/v2/access/posts",
2061
+ method: "GET",
2062
+ query: {
2063
+ "limit": params.limit,
2064
+ "sortBy": params.sortBy,
2065
+ "sortDirection": params.sortDirection,
2066
+ "pinned": params.pinned,
2067
+ "includePostCounts": params.includePostCounts,
2068
+ "beforePublishTime": params.beforePublishTime
2069
+ }
2070
+ });
2071
+ }
2072
+ /**
2073
+ * Create post
2074
+ */
2075
+ createPosts(params) {
2076
+ return request(this._config, {
2077
+ path: "/v2/access/posts",
2078
+ method: "POST",
2079
+ body: params.body
2080
+ });
2081
+ }
2082
+ /**
2083
+ * Get post
2084
+ */
2085
+ getPosts(params) {
2086
+ return request(this._config, {
2087
+ path: `/v2/access/posts/${encodeURIComponent(String(params.postId))}`,
2088
+ method: "GET"
2089
+ });
2090
+ }
2091
+ /**
2092
+ * Edit post
2093
+ */
2094
+ replacePosts(params) {
2095
+ return request(this._config, {
2096
+ path: `/v2/access/posts/${encodeURIComponent(String(params.postId))}`,
2097
+ method: "PUT",
2098
+ body: params.body
2099
+ });
2100
+ }
2101
+ /**
2102
+ * Delete post
2103
+ */
2104
+ deletePosts(params) {
2105
+ return request(this._config, {
2106
+ path: `/v2/access/posts/${encodeURIComponent(String(params.postId))}`,
2107
+ method: "DELETE"
2108
+ });
2109
+ }
2110
+ /**
2111
+ * List mass messages
2112
+ */
2113
+ listMassMessages(params) {
2114
+ return request(this._config, {
2115
+ path: "/v2/access/mass-messages",
2116
+ method: "GET",
2117
+ query: {
2118
+ "limit": params.limit,
2119
+ "offset": params.offset,
2120
+ "type": params.type
2121
+ }
2122
+ });
2123
+ }
2124
+ /**
2125
+ * List mass messages
2126
+ *
2127
+ * Returns an async iterator that automatically paginates through all results.
2128
+ */
2129
+ async *iterateMassMessages(params) {
2130
+ let offset = 0;
2131
+ let fetched = 0;
2132
+ const limit = params?.pageSize ?? 20;
2133
+ const maxItems = params?.maxItems ?? Infinity;
2134
+ while (fetched < maxItems) {
2135
+ const response = await this.listMassMessages({
2136
+ ...params,
2137
+ limit: Math.min(limit, maxItems - fetched),
2138
+ offset
2139
+ });
2140
+ for (const item of response.list) {
2141
+ if (fetched >= maxItems) return;
2142
+ yield item;
2143
+ fetched++;
2144
+ }
2145
+ if (!response.hasMore) return;
2146
+ offset = response.nextOffset ?? offset + response.list.length;
2147
+ }
2148
+ }
2149
+ /**
2150
+ * Create mass message
2151
+ */
2152
+ createMassMessages(params) {
2153
+ return request(this._config, {
2154
+ path: "/v2/access/mass-messages",
2155
+ method: "POST",
2156
+ body: params.body
2157
+ });
2158
+ }
2159
+ /**
2160
+ * Get mass message
2161
+ */
2162
+ getMassMessages(params) {
2163
+ return request(this._config, {
2164
+ path: `/v2/access/mass-messages/${encodeURIComponent(String(params.massMessageId))}`,
2165
+ method: "GET"
2166
+ });
2167
+ }
2168
+ /**
2169
+ * Update mass message
2170
+ */
2171
+ replaceMassMessages(params) {
2172
+ return request(this._config, {
2173
+ path: `/v2/access/mass-messages/${encodeURIComponent(String(params.massMessageId))}`,
2174
+ method: "PUT",
2175
+ body: params.body
2176
+ });
2177
+ }
2178
+ /**
2179
+ * Delete mass message
2180
+ */
2181
+ deleteMassMessages(params) {
2182
+ return request(this._config, {
2183
+ path: `/v2/access/mass-messages/${encodeURIComponent(String(params.massMessageId))}`,
2184
+ method: "DELETE"
2185
+ });
2186
+ }
2187
+ };
2188
+ var LinkNamespace = class {
2189
+ constructor(config) {
2190
+ this._config = config;
2191
+ }
2192
+ /**
2193
+ * Get login status
2194
+ */
2195
+ get(params) {
2196
+ return request(this._config, {
2197
+ path: `/v2/link/${encodeURIComponent(String(params.clientSecret))}`,
2198
+ method: "GET"
2199
+ });
2200
+ }
2201
+ /**
2202
+ * Delete login session
2203
+ */
2204
+ delete(params) {
2205
+ return request(this._config, {
2206
+ path: `/v2/link/${encodeURIComponent(String(params.clientSecret))}`,
2207
+ method: "DELETE"
2208
+ });
2209
+ }
2210
+ /**
2211
+ * Initialize a Link session
2212
+ */
2213
+ init(params) {
2214
+ return request(this._config, {
2215
+ path: "/v2/link/init",
2216
+ method: "POST",
2217
+ body: params.body
2218
+ });
2219
+ }
2220
+ };
2221
+ var DynamicRulesNamespace = class {
2222
+ constructor(config) {
2223
+ this._config = config;
2224
+ }
2225
+ /**
2226
+ * Get dynamic rules
2227
+ */
2228
+ list() {
2229
+ return request(this._config, {
2230
+ path: "/v2/dynamic-rules",
2231
+ method: "GET"
2232
+ });
2233
+ }
2234
+ /**
2235
+ * Generate sign headers for a request
2236
+ */
2237
+ sign(params) {
2238
+ return request(this._config, {
2239
+ path: "/v2/dynamic-rules/sign",
2240
+ method: "POST",
2241
+ body: params.body
2242
+ });
2243
+ }
2244
+ /**
2245
+ * Get dynamic rules status
2246
+ */
2247
+ getStatus() {
2248
+ return request(this._config, {
2249
+ path: "/v2/dynamic-rules/status",
2250
+ method: "GET"
2251
+ });
2252
+ }
2253
+ };
2254
+ var VaultPlusStoreNamespace = class {
2255
+ constructor(config) {
2256
+ this._config = config;
2257
+ }
2258
+ /**
2259
+ * Store all media from a vault list
2260
+ */
2261
+ createList(params) {
2262
+ return request(this._config, {
2263
+ path: `/v2/vault-plus/store/list/${encodeURIComponent(String(params.listId))}`,
2264
+ method: "POST",
2265
+ connectionId: params.connectionId
2266
+ });
2267
+ }
2268
+ /**
2269
+ * Get storage status for a connection
2270
+ */
2271
+ getStatus(params) {
2272
+ return request(this._config, {
2273
+ path: "/v2/vault-plus/store/status",
2274
+ method: "GET",
2275
+ connectionId: params.connectionId
2276
+ });
2277
+ }
2278
+ /**
2279
+ * Get organization vault stats
2280
+ */
2281
+ getStats() {
2282
+ return request(this._config, {
2283
+ path: "/v2/vault-plus/store/stats",
2284
+ method: "GET"
2285
+ });
2286
+ }
2287
+ };
2288
+ var VaultPlusNamespace = class {
2289
+ constructor(config) {
2290
+ this._config = config;
2291
+ this.store = new VaultPlusStoreNamespace(config);
2292
+ }
2293
+ /**
2294
+ * Get media item with all quality variants
2295
+ */
2296
+ get(params) {
2297
+ return request(this._config, {
2298
+ path: `/v2/vault-plus/${encodeURIComponent(String(params.mediaId))}`,
2299
+ method: "GET",
2300
+ connectionId: params.connectionId
2301
+ });
2302
+ }
2303
+ /**
2304
+ * Delete a stored media item
2305
+ */
2306
+ delete(params) {
2307
+ return request(this._config, {
2308
+ path: `/v2/vault-plus/${encodeURIComponent(String(params.mediaId))}`,
2309
+ method: "DELETE",
2310
+ connectionId: params.connectionId
2311
+ });
2312
+ }
2313
+ /**
2314
+ * Get multiple media items with all quality variants
2315
+ */
2316
+ createBatch(params) {
2317
+ return request(this._config, {
2318
+ path: "/v2/vault-plus/batch",
2319
+ method: "POST",
2320
+ body: params.body,
2321
+ connectionId: params.connectionId
2322
+ });
2323
+ }
2324
+ /**
2325
+ * List stored media for a connection
2326
+ */
2327
+ getList(params) {
2328
+ return request(this._config, {
2329
+ path: "/v2/vault-plus/list",
2330
+ method: "GET",
2331
+ query: {
2332
+ "status": params.status,
2333
+ "source": params.source,
2334
+ "contentType": params.contentType,
2335
+ "limit": params.limit,
2336
+ "cursor": params.cursor
2337
+ },
2338
+ connectionId: params.connectionId
2339
+ });
2340
+ }
2341
+ /**
2342
+ * Remove all stored media for a connection
2343
+ */
2344
+ purge(params) {
2345
+ return request(this._config, {
2346
+ path: "/v2/vault-plus/purge",
2347
+ method: "DELETE",
2348
+ connectionId: params.connectionId
2349
+ });
2350
+ }
2351
+ };
2352
+ var OFAuthClient = class {
2353
+ constructor(config) {
2354
+ this._config = config;
2355
+ this.account = new AccountNamespace(config);
2356
+ this.access = new AccessNamespace(config);
2357
+ this.link = new LinkNamespace(config);
2358
+ this.dynamicRules = new DynamicRulesNamespace(config);
2359
+ this.vaultPlus = new VaultPlusNamespace(config);
2360
+ }
2361
+ /**
2362
+ * Make a proxied request to the OnlyFans API
2363
+ */
2364
+ proxy(opts) {
2365
+ return proxy(this._config, opts);
2366
+ }
2367
+ };
2368
+ function createOFAuthClient(config) {
2369
+ return new OFAuthClient(config);
2370
+ }
2371
+
2372
+ // src/webhooks.ts
2373
+ var crypto = __toESM(require("crypto"));
2374
+ var WebhookVerificationError = class extends Error {
2375
+ constructor(message, code) {
2376
+ super(message);
2377
+ this.code = code;
2378
+ this.name = "WebhookVerificationError";
2379
+ }
2380
+ };
2381
+ function isWebhookVerificationError(error) {
2382
+ return error instanceof WebhookVerificationError;
2383
+ }
2384
+ function extractWebhookHeaders(headers) {
2385
+ const get = (name) => {
2386
+ if (headers instanceof Headers) return headers.get(name);
2387
+ return headers[name] || headers[name.toLowerCase()] || null;
2388
+ };
2389
+ const svixId = get("svix-id");
2390
+ const svixTimestamp = get("svix-timestamp");
2391
+ const svixSignature = get("svix-signature");
2392
+ if (!svixId || !svixTimestamp || !svixSignature) {
2393
+ throw new WebhookVerificationError(
2394
+ "Missing required webhook headers (svix-id, svix-timestamp, svix-signature)",
2395
+ "MISSING_HEADERS"
2396
+ );
2397
+ }
2398
+ return {
2399
+ "svix-id": svixId,
2400
+ "svix-timestamp": svixTimestamp,
2401
+ "svix-signature": svixSignature
2402
+ };
2403
+ }
2404
+ function verifyWebhookSignature(payload, headers, options) {
2405
+ const { secret, tolerance = 300 } = options;
2406
+ const ts = parseInt(headers["svix-timestamp"], 10);
2407
+ if (isNaN(ts)) {
2408
+ throw new WebhookVerificationError("Invalid timestamp format", "INVALID_TIMESTAMP");
2409
+ }
2410
+ if (Math.abs(Math.floor(Date.now() / 1e3) - ts) > tolerance) {
2411
+ throw new WebhookVerificationError("Webhook timestamp too old", "TIMESTAMP_TOO_OLD");
2412
+ }
2413
+ const cleanSecret = secret.startsWith("whsec_") ? secret.slice(6) : secret;
2414
+ const key = Buffer.from(cleanSecret, "base64");
2415
+ const signed = `${headers["svix-id"]}.${headers["svix-timestamp"]}.${payload}`;
2416
+ const expected = crypto.createHmac("sha256", key).update(signed).digest("base64");
2417
+ const sigs = headers["svix-signature"].split(" ").map((s) => {
2418
+ const [version, signature] = s.split(",");
2419
+ return { version, signature };
2420
+ }).filter((s) => s.version === "v1");
2421
+ if (sigs.length === 0) {
2422
+ throw new WebhookVerificationError("No valid v1 signatures found", "NO_VALID_SIGNATURES");
2423
+ }
2424
+ const isValid = sigs.some((s) => {
2425
+ try {
2426
+ return crypto.timingSafeEqual(
2427
+ Buffer.from(expected, "base64"),
2428
+ Buffer.from(s.signature, "base64")
2429
+ );
2430
+ } catch {
2431
+ return false;
2432
+ }
2433
+ });
2434
+ if (!isValid) {
2435
+ throw new WebhookVerificationError("Signature verification failed", "SIGNATURE_MISMATCH");
2436
+ }
2437
+ return true;
2438
+ }
2439
+ async function verifyWebhookRequest(request2, secret, tolerance) {
2440
+ const headers = extractWebhookHeaders(request2.headers);
2441
+ const payload = await request2.text();
2442
+ verifyWebhookSignature(payload, headers, { secret, tolerance });
2443
+ try {
2444
+ return JSON.parse(payload);
2445
+ } catch {
2446
+ throw new WebhookVerificationError("Failed to parse webhook payload as JSON", "INVALID_JSON");
2447
+ }
2448
+ }
2449
+ function verifyWebhookPayload(payload, headers, secret, tolerance) {
2450
+ const payloadStr = typeof payload === "string" ? payload : payload.toString("utf8");
2451
+ const webhookHeaders = extractWebhookHeaders(headers);
2452
+ verifyWebhookSignature(payloadStr, webhookHeaders, { secret, tolerance });
2453
+ try {
2454
+ return JSON.parse(payloadStr);
2455
+ } catch {
2456
+ throw new WebhookVerificationError("Failed to parse webhook payload as JSON", "INVALID_JSON");
2457
+ }
2458
+ }
2459
+ var WebhookRouter = class {
2460
+ constructor(config) {
2461
+ this.handlers = {};
2462
+ this.secret = config.secret;
2463
+ this.tolerance = config.tolerance ?? 300;
2464
+ if (config.handlers) this.handlers = { ...config.handlers };
2465
+ this.defaultHandler = config.defaultHandler;
2466
+ this.errorHandler = config.errorHandler;
2467
+ }
2468
+ /** Register a handler for a specific event type */
2469
+ on(eventType, handler) {
2470
+ this.handlers[eventType] = handler;
2471
+ return this;
2472
+ }
2473
+ /** Register a default handler for unmatched event types */
2474
+ onDefault(handler) {
2475
+ this.defaultHandler = handler;
2476
+ return this;
2477
+ }
2478
+ /** Register an error handler */
2479
+ onError(handler) {
2480
+ this.errorHandler = handler;
2481
+ return this;
2482
+ }
2483
+ /** Handle a `Request` object (Cloudflare Workers, Deno, Bun, Node 18+) */
2484
+ async handleRequest(request2) {
2485
+ try {
2486
+ const event = await verifyWebhookRequest(
2487
+ request2,
2488
+ this.secret,
2489
+ this.tolerance
2490
+ );
2491
+ await this.processEvent(event);
2492
+ } catch (error) {
2493
+ if (this.errorHandler) this.errorHandler(error);
2494
+ else throw error;
2495
+ }
2496
+ }
2497
+ /** Handle a raw payload + headers (Express.js, Fastify, etc.) */
2498
+ async handlePayload(payload, headers) {
2499
+ try {
2500
+ const event = verifyWebhookPayload(
2501
+ payload,
2502
+ headers,
2503
+ this.secret,
2504
+ this.tolerance
2505
+ );
2506
+ await this.processEvent(event);
2507
+ } catch (error) {
2508
+ if (this.errorHandler) this.errorHandler(error);
2509
+ else throw error;
2510
+ }
2511
+ }
2512
+ /** Update the webhook secret at runtime */
2513
+ updateSecret(secret) {
2514
+ this.secret = secret;
2515
+ }
2516
+ /** Update the timestamp tolerance at runtime */
2517
+ updateTolerance(tolerance) {
2518
+ this.tolerance = tolerance;
2519
+ }
2520
+ async processEvent(event) {
2521
+ try {
2522
+ const handler = this.handlers[event.eventType] || this.defaultHandler;
2523
+ if (!handler) {
2524
+ console.warn(`No handler registered for webhook event type: ${event.eventType}`);
2525
+ return;
2526
+ }
2527
+ await handler(event);
2528
+ } catch (error) {
2529
+ if (this.errorHandler) this.errorHandler(error, event);
2530
+ else throw error;
2531
+ }
2532
+ }
2533
+ };
2534
+ function createWebhookRouter(config) {
2535
+ return new WebhookRouter(config);
2536
+ }
2537
+ function createFetchWebhookHandler(router) {
2538
+ return async (request2) => {
2539
+ try {
2540
+ await router.handleRequest(request2);
2541
+ return new Response("OK", { status: 200 });
2542
+ } catch (error) {
2543
+ if (isWebhookVerificationError(error)) {
2544
+ return new Response(
2545
+ JSON.stringify({ error: error.message, code: error.code }),
2546
+ { status: 401, headers: { "Content-Type": "application/json" } }
2547
+ );
2548
+ }
2549
+ console.error("Webhook processing error:", error);
2550
+ return new Response("Internal server error", { status: 500 });
2551
+ }
2552
+ };
2553
+ }
2554
+ function createExpressWebhookMiddleware(router) {
2555
+ return async (req, res, next) => {
2556
+ try {
2557
+ await router.handlePayload(req.body, req.headers);
2558
+ res.status(200).send("OK");
2559
+ } catch (error) {
2560
+ if (isWebhookVerificationError(error)) {
2561
+ res.status(401).json({ error: error.message, code: error.code });
2562
+ } else {
2563
+ res.status(500).json({ error: "Internal server error" });
2564
+ next(error);
2565
+ }
2566
+ }
2567
+ };
2568
+ }
2569
+ // Annotate the CommonJS export names for ESM import in node:
2570
+ 0 && (module.exports = {
2571
+ BASE_PATH,
2572
+ OFAuthAPIError,
2573
+ OFAuthClient,
2574
+ WebhookRouter,
2575
+ WebhookVerificationError,
2576
+ createExpressWebhookMiddleware,
2577
+ createFetchWebhookHandler,
2578
+ createOFAuthClient,
2579
+ createWebhookRouter,
2580
+ extractWebhookHeaders,
2581
+ isWebhookVerificationError,
2582
+ proxy,
2583
+ request,
2584
+ verifyWebhookPayload,
2585
+ verifyWebhookRequest,
2586
+ verifyWebhookSignature
2587
+ });