@djangocfg/ext-newsletter 1.0.2 → 1.0.4

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,2203 @@
1
+ import { createConsola, consola } from 'consola';
2
+ import pRetry, { AbortError } from 'p-retry';
3
+ import { z } from 'zod';
4
+ import { createExtensionAPI } from '@djangocfg/ext-base/api';
5
+ import { createExtensionConfig } from '@djangocfg/ext-base';
6
+
7
+ var __defProp = Object.defineProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+
13
+ // src/api/generated/ext_newsletter/ext_newsletter__newsletter__bulk_email/client.ts
14
+ var ExtNewsletterBulkEmail = class {
15
+ client;
16
+ constructor(client) {
17
+ this.client = client;
18
+ }
19
+ /**
20
+ * Send Bulk Email
21
+ *
22
+ * Send bulk emails to multiple recipients using base email template.
23
+ */
24
+ async newsletterBulkCreate(data) {
25
+ const response = await this.client.request("POST", "/cfg/newsletter/bulk/", { body: data });
26
+ return response;
27
+ }
28
+ };
29
+
30
+ // src/api/generated/ext_newsletter/ext_newsletter__newsletter__bulk_email/models.ts
31
+ var models_exports = {};
32
+
33
+ // src/api/generated/ext_newsletter/ext_newsletter__newsletter__campaigns/client.ts
34
+ var ExtNewsletterCampaigns = class {
35
+ client;
36
+ constructor(client) {
37
+ this.client = client;
38
+ }
39
+ /**
40
+ * List Newsletter Campaigns
41
+ *
42
+ * Get a list of all newsletter campaigns.
43
+ */
44
+ async newsletterCampaignsList(...args) {
45
+ const isParamsObject = args.length === 1 && typeof args[0] === "object" && args[0] !== null && !Array.isArray(args[0]);
46
+ let params;
47
+ if (isParamsObject) {
48
+ params = args[0];
49
+ } else {
50
+ params = { page: args[0], page_size: args[1] };
51
+ }
52
+ const response = await this.client.request("GET", "/cfg/newsletter/campaigns/", { params });
53
+ return response;
54
+ }
55
+ /**
56
+ * Create Newsletter Campaign
57
+ *
58
+ * Create a new newsletter campaign.
59
+ */
60
+ async newsletterCampaignsCreate(data) {
61
+ const response = await this.client.request("POST", "/cfg/newsletter/campaigns/", { body: data });
62
+ return response;
63
+ }
64
+ /**
65
+ * Get Campaign Details
66
+ *
67
+ * Retrieve details of a specific newsletter campaign.
68
+ */
69
+ async newsletterCampaignsRetrieve(id) {
70
+ const response = await this.client.request("GET", `/cfg/newsletter/campaigns/${id}/`);
71
+ return response;
72
+ }
73
+ /**
74
+ * Update Campaign
75
+ *
76
+ * Update a newsletter campaign.
77
+ */
78
+ async newsletterCampaignsUpdate(id, data) {
79
+ const response = await this.client.request("PUT", `/cfg/newsletter/campaigns/${id}/`, { body: data });
80
+ return response;
81
+ }
82
+ /**
83
+ * Delete Campaign
84
+ *
85
+ * Delete a newsletter campaign.
86
+ */
87
+ async newsletterCampaignsDestroy(id) {
88
+ await this.client.request("DELETE", `/cfg/newsletter/campaigns/${id}/`);
89
+ return;
90
+ }
91
+ /**
92
+ * Send Newsletter Campaign
93
+ *
94
+ * Send a newsletter campaign to all subscribers.
95
+ */
96
+ async newsletterCampaignsSendCreate(data) {
97
+ const response = await this.client.request("POST", "/cfg/newsletter/campaigns/send/", { body: data });
98
+ return response;
99
+ }
100
+ };
101
+
102
+ // src/api/generated/ext_newsletter/ext_newsletter__newsletter__campaigns/models.ts
103
+ var models_exports2 = {};
104
+
105
+ // src/api/generated/ext_newsletter/ext_newsletter__newsletter__logs/client.ts
106
+ var ExtNewsletterLogs = class {
107
+ client;
108
+ constructor(client) {
109
+ this.client = client;
110
+ }
111
+ /**
112
+ * List Email Logs
113
+ *
114
+ * Get a list of email sending logs.
115
+ */
116
+ async newsletterLogsList(...args) {
117
+ const isParamsObject = args.length === 1 && typeof args[0] === "object" && args[0] !== null && !Array.isArray(args[0]);
118
+ let params;
119
+ if (isParamsObject) {
120
+ params = args[0];
121
+ } else {
122
+ params = { page: args[0], page_size: args[1] };
123
+ }
124
+ const response = await this.client.request("GET", "/cfg/newsletter/logs/", { params });
125
+ return response;
126
+ }
127
+ };
128
+
129
+ // src/api/generated/ext_newsletter/ext_newsletter__newsletter__logs/models.ts
130
+ var models_exports3 = {};
131
+
132
+ // src/api/generated/ext_newsletter/ext_newsletter__newsletter__newsletters/client.ts
133
+ var ExtNewsletterNewsletters = class {
134
+ client;
135
+ constructor(client) {
136
+ this.client = client;
137
+ }
138
+ /**
139
+ * List Active Newsletters
140
+ *
141
+ * Get a list of all active newsletters available for subscription.
142
+ */
143
+ async newsletterNewslettersList(...args) {
144
+ const isParamsObject = args.length === 1 && typeof args[0] === "object" && args[0] !== null && !Array.isArray(args[0]);
145
+ let params;
146
+ if (isParamsObject) {
147
+ params = args[0];
148
+ } else {
149
+ params = { page: args[0], page_size: args[1] };
150
+ }
151
+ const response = await this.client.request("GET", "/cfg/newsletter/newsletters/", { params });
152
+ return response;
153
+ }
154
+ /**
155
+ * Get Newsletter Details
156
+ *
157
+ * Retrieve details of a specific newsletter.
158
+ */
159
+ async newsletterNewslettersRetrieve(id) {
160
+ const response = await this.client.request("GET", `/cfg/newsletter/newsletters/${id}/`);
161
+ return response;
162
+ }
163
+ };
164
+
165
+ // src/api/generated/ext_newsletter/ext_newsletter__newsletter__newsletters/models.ts
166
+ var models_exports4 = {};
167
+
168
+ // src/api/generated/ext_newsletter/ext_newsletter__newsletter__subscriptions/client.ts
169
+ var ExtNewsletterSubscriptions = class {
170
+ client;
171
+ constructor(client) {
172
+ this.client = client;
173
+ }
174
+ /**
175
+ * Subscribe to Newsletter
176
+ *
177
+ * Subscribe an email address to a newsletter.
178
+ */
179
+ async newsletterSubscribeCreate(data) {
180
+ const response = await this.client.request("POST", "/cfg/newsletter/subscribe/", { body: data });
181
+ return response;
182
+ }
183
+ /**
184
+ * List User Subscriptions
185
+ *
186
+ * Get a list of current user's active newsletter subscriptions.
187
+ */
188
+ async newsletterSubscriptionsList(...args) {
189
+ const isParamsObject = args.length === 1 && typeof args[0] === "object" && args[0] !== null && !Array.isArray(args[0]);
190
+ let params;
191
+ if (isParamsObject) {
192
+ params = args[0];
193
+ } else {
194
+ params = { page: args[0], page_size: args[1] };
195
+ }
196
+ const response = await this.client.request("GET", "/cfg/newsletter/subscriptions/", { params });
197
+ return response;
198
+ }
199
+ /**
200
+ * Unsubscribe from Newsletter
201
+ *
202
+ * Unsubscribe from a newsletter using subscription ID.
203
+ */
204
+ async newsletterUnsubscribeCreate(data) {
205
+ const response = await this.client.request("POST", "/cfg/newsletter/unsubscribe/", { body: data });
206
+ return response;
207
+ }
208
+ };
209
+
210
+ // src/api/generated/ext_newsletter/ext_newsletter__newsletter__subscriptions/models.ts
211
+ var models_exports5 = {};
212
+
213
+ // src/api/generated/ext_newsletter/ext_newsletter__newsletter__testing/client.ts
214
+ var ExtNewsletterTesting = class {
215
+ client;
216
+ constructor(client) {
217
+ this.client = client;
218
+ }
219
+ /**
220
+ * Test Email Sending
221
+ *
222
+ * Send a test email to verify mailer configuration.
223
+ */
224
+ async newsletterTestCreate(data) {
225
+ const response = await this.client.request("POST", "/cfg/newsletter/test/", { body: data });
226
+ return response;
227
+ }
228
+ };
229
+
230
+ // src/api/generated/ext_newsletter/ext_newsletter__newsletter__testing/models.ts
231
+ var models_exports6 = {};
232
+
233
+ // src/api/generated/ext_newsletter/ext_newsletter__newsletter/client.ts
234
+ var ExtNewsletterNewsletter = class {
235
+ client;
236
+ constructor(client) {
237
+ this.client = client;
238
+ }
239
+ /**
240
+ * Retrieve, update, or delete a newsletter campaign.
241
+ */
242
+ async campaignsPartialUpdate(id, data) {
243
+ const response = await this.client.request("PATCH", `/cfg/newsletter/campaigns/${id}/`, { body: data });
244
+ return response;
245
+ }
246
+ /**
247
+ * Handle newsletter unsubscriptions.
248
+ */
249
+ async unsubscribeUpdate(data) {
250
+ const response = await this.client.request("PUT", "/cfg/newsletter/unsubscribe/", { body: data });
251
+ return response;
252
+ }
253
+ /**
254
+ * Handle newsletter unsubscriptions.
255
+ */
256
+ async unsubscribePartialUpdate(data) {
257
+ const response = await this.client.request("PATCH", "/cfg/newsletter/unsubscribe/", { body: data });
258
+ return response;
259
+ }
260
+ };
261
+
262
+ // src/api/generated/ext_newsletter/ext_newsletter__newsletter/models.ts
263
+ var models_exports7 = {};
264
+
265
+ // src/api/generated/ext_newsletter/http.ts
266
+ var FetchAdapter = class {
267
+ async request(request) {
268
+ const { method, url, headers, body, params, formData } = request;
269
+ let finalUrl = url;
270
+ if (params) {
271
+ const searchParams = new URLSearchParams();
272
+ Object.entries(params).forEach(([key, value]) => {
273
+ if (value !== null && value !== void 0) {
274
+ searchParams.append(key, String(value));
275
+ }
276
+ });
277
+ const queryString = searchParams.toString();
278
+ if (queryString) {
279
+ finalUrl = url.includes("?") ? `${url}&${queryString}` : `${url}?${queryString}`;
280
+ }
281
+ }
282
+ const finalHeaders = { ...headers };
283
+ let requestBody;
284
+ if (formData) {
285
+ requestBody = formData;
286
+ } else if (body) {
287
+ finalHeaders["Content-Type"] = "application/json";
288
+ requestBody = JSON.stringify(body);
289
+ }
290
+ const response = await fetch(finalUrl, {
291
+ method,
292
+ headers: finalHeaders,
293
+ body: requestBody,
294
+ credentials: "include"
295
+ // Include Django session cookies
296
+ });
297
+ let data = null;
298
+ const contentType = response.headers.get("content-type");
299
+ if (response.status !== 204 && contentType?.includes("application/json")) {
300
+ data = await response.json();
301
+ } else if (response.status !== 204) {
302
+ data = await response.text();
303
+ }
304
+ const responseHeaders = {};
305
+ response.headers.forEach((value, key) => {
306
+ responseHeaders[key] = value;
307
+ });
308
+ return {
309
+ data,
310
+ status: response.status,
311
+ statusText: response.statusText,
312
+ headers: responseHeaders
313
+ };
314
+ }
315
+ };
316
+
317
+ // src/api/generated/ext_newsletter/errors.ts
318
+ var APIError = class extends Error {
319
+ constructor(statusCode, statusText, response, url, message) {
320
+ super(message || `HTTP ${statusCode}: ${statusText}`);
321
+ this.statusCode = statusCode;
322
+ this.statusText = statusText;
323
+ this.response = response;
324
+ this.url = url;
325
+ this.name = "APIError";
326
+ }
327
+ /**
328
+ * Get error details from response.
329
+ * DRF typically returns: { "detail": "Error message" } or { "field": ["error1", "error2"] }
330
+ */
331
+ get details() {
332
+ if (typeof this.response === "object" && this.response !== null) {
333
+ return this.response;
334
+ }
335
+ return null;
336
+ }
337
+ /**
338
+ * Get field-specific validation errors from DRF.
339
+ * Returns: { "field_name": ["error1", "error2"], ... }
340
+ */
341
+ get fieldErrors() {
342
+ const details = this.details;
343
+ if (!details) return null;
344
+ const fieldErrors = {};
345
+ for (const [key, value] of Object.entries(details)) {
346
+ if (Array.isArray(value)) {
347
+ fieldErrors[key] = value;
348
+ }
349
+ }
350
+ return Object.keys(fieldErrors).length > 0 ? fieldErrors : null;
351
+ }
352
+ /**
353
+ * Get single error message from DRF.
354
+ * Checks for "detail", "message", or first field error.
355
+ */
356
+ get errorMessage() {
357
+ const details = this.details;
358
+ if (!details) return this.message;
359
+ if (details.detail) {
360
+ return Array.isArray(details.detail) ? details.detail.join(", ") : String(details.detail);
361
+ }
362
+ if (details.message) {
363
+ return String(details.message);
364
+ }
365
+ const fieldErrors = this.fieldErrors;
366
+ if (fieldErrors) {
367
+ const firstField = Object.keys(fieldErrors)[0];
368
+ if (firstField) {
369
+ return `${firstField}: ${fieldErrors[firstField]?.join(", ")}`;
370
+ }
371
+ }
372
+ return this.message;
373
+ }
374
+ // Helper methods for common HTTP status codes
375
+ get isValidationError() {
376
+ return this.statusCode === 400;
377
+ }
378
+ get isAuthError() {
379
+ return this.statusCode === 401;
380
+ }
381
+ get isPermissionError() {
382
+ return this.statusCode === 403;
383
+ }
384
+ get isNotFoundError() {
385
+ return this.statusCode === 404;
386
+ }
387
+ get isServerError() {
388
+ return this.statusCode >= 500 && this.statusCode < 600;
389
+ }
390
+ };
391
+ var NetworkError = class extends Error {
392
+ constructor(message, url, originalError) {
393
+ super(message);
394
+ this.url = url;
395
+ this.originalError = originalError;
396
+ this.name = "NetworkError";
397
+ }
398
+ };
399
+ var DEFAULT_CONFIG = {
400
+ enabled: process.env.NODE_ENV !== "production",
401
+ logRequests: true,
402
+ logResponses: true,
403
+ logErrors: true,
404
+ logBodies: true,
405
+ logHeaders: false
406
+ };
407
+ var SENSITIVE_HEADERS = [
408
+ "authorization",
409
+ "cookie",
410
+ "set-cookie",
411
+ "x-api-key",
412
+ "x-csrf-token"
413
+ ];
414
+ var APILogger = class {
415
+ config;
416
+ consola;
417
+ constructor(config = {}) {
418
+ this.config = { ...DEFAULT_CONFIG, ...config };
419
+ this.consola = config.consola || createConsola({
420
+ level: this.config.enabled ? 4 : 0
421
+ });
422
+ }
423
+ /**
424
+ * Enable logging
425
+ */
426
+ enable() {
427
+ this.config.enabled = true;
428
+ }
429
+ /**
430
+ * Disable logging
431
+ */
432
+ disable() {
433
+ this.config.enabled = false;
434
+ }
435
+ /**
436
+ * Update configuration
437
+ */
438
+ setConfig(config) {
439
+ this.config = { ...this.config, ...config };
440
+ }
441
+ /**
442
+ * Filter sensitive headers
443
+ */
444
+ filterHeaders(headers) {
445
+ if (!headers) return {};
446
+ const filtered = {};
447
+ Object.keys(headers).forEach((key) => {
448
+ const lowerKey = key.toLowerCase();
449
+ if (SENSITIVE_HEADERS.includes(lowerKey)) {
450
+ filtered[key] = "***";
451
+ } else {
452
+ filtered[key] = headers[key] || "";
453
+ }
454
+ });
455
+ return filtered;
456
+ }
457
+ /**
458
+ * Log request
459
+ */
460
+ logRequest(request) {
461
+ if (!this.config.enabled || !this.config.logRequests) return;
462
+ const { method, url, headers, body } = request;
463
+ this.consola.start(`${method} ${url}`);
464
+ if (this.config.logHeaders && headers) {
465
+ this.consola.debug("Headers:", this.filterHeaders(headers));
466
+ }
467
+ if (this.config.logBodies && body) {
468
+ this.consola.debug("Body:", body);
469
+ }
470
+ }
471
+ /**
472
+ * Log response
473
+ */
474
+ logResponse(request, response) {
475
+ if (!this.config.enabled || !this.config.logResponses) return;
476
+ const { method, url } = request;
477
+ const { status, statusText, data, duration } = response;
478
+ this.consola.success(
479
+ `${method} ${url} ${status} ${statusText} (${duration}ms)`
480
+ );
481
+ if (this.config.logBodies && data) {
482
+ this.consola.debug("Response:", data);
483
+ }
484
+ }
485
+ /**
486
+ * Log error
487
+ */
488
+ logError(request, error) {
489
+ if (!this.config.enabled || !this.config.logErrors) return;
490
+ const { method, url } = request;
491
+ const { message, statusCode, fieldErrors, duration } = error;
492
+ this.consola.error(
493
+ `${method} ${url} ${statusCode || "Network"} Error (${duration}ms)`
494
+ );
495
+ this.consola.error("Message:", message);
496
+ if (fieldErrors && Object.keys(fieldErrors).length > 0) {
497
+ this.consola.error("Field Errors:");
498
+ Object.entries(fieldErrors).forEach(([field, errors]) => {
499
+ errors.forEach((err) => {
500
+ this.consola.error(` \u2022 ${field}: ${err}`);
501
+ });
502
+ });
503
+ }
504
+ }
505
+ /**
506
+ * Log general info
507
+ */
508
+ info(message, ...args) {
509
+ if (!this.config.enabled) return;
510
+ this.consola.info(message, ...args);
511
+ }
512
+ /**
513
+ * Log warning
514
+ */
515
+ warn(message, ...args) {
516
+ if (!this.config.enabled) return;
517
+ this.consola.warn(message, ...args);
518
+ }
519
+ /**
520
+ * Log error
521
+ */
522
+ error(message, ...args) {
523
+ if (!this.config.enabled) return;
524
+ this.consola.error(message, ...args);
525
+ }
526
+ /**
527
+ * Log debug
528
+ */
529
+ debug(message, ...args) {
530
+ if (!this.config.enabled) return;
531
+ this.consola.debug(message, ...args);
532
+ }
533
+ /**
534
+ * Log success
535
+ */
536
+ success(message, ...args) {
537
+ if (!this.config.enabled) return;
538
+ this.consola.success(message, ...args);
539
+ }
540
+ /**
541
+ * Create a sub-logger with prefix
542
+ */
543
+ withTag(tag) {
544
+ return this.consola.withTag(tag);
545
+ }
546
+ };
547
+ new APILogger();
548
+ var DEFAULT_RETRY_CONFIG = {
549
+ retries: 3,
550
+ factor: 2,
551
+ minTimeout: 1e3,
552
+ maxTimeout: 6e4,
553
+ randomize: true,
554
+ onFailedAttempt: () => {
555
+ }
556
+ };
557
+ function shouldRetry(error) {
558
+ if (error instanceof NetworkError) {
559
+ return true;
560
+ }
561
+ if (error instanceof APIError) {
562
+ const status = error.statusCode;
563
+ if (status >= 500 && status < 600) {
564
+ return true;
565
+ }
566
+ if (status === 429) {
567
+ return true;
568
+ }
569
+ return false;
570
+ }
571
+ return true;
572
+ }
573
+ async function withRetry(fn, config) {
574
+ const finalConfig = { ...DEFAULT_RETRY_CONFIG, ...config };
575
+ return pRetry(
576
+ async () => {
577
+ try {
578
+ return await fn();
579
+ } catch (error) {
580
+ if (!shouldRetry(error)) {
581
+ throw new AbortError(error);
582
+ }
583
+ throw error;
584
+ }
585
+ },
586
+ {
587
+ retries: finalConfig.retries,
588
+ factor: finalConfig.factor,
589
+ minTimeout: finalConfig.minTimeout,
590
+ maxTimeout: finalConfig.maxTimeout,
591
+ randomize: finalConfig.randomize,
592
+ onFailedAttempt: finalConfig.onFailedAttempt ? (error) => {
593
+ const pRetryError = error;
594
+ finalConfig.onFailedAttempt({
595
+ error: pRetryError,
596
+ attemptNumber: pRetryError.attemptNumber,
597
+ retriesLeft: pRetryError.retriesLeft
598
+ });
599
+ } : void 0
600
+ }
601
+ );
602
+ }
603
+
604
+ // src/api/generated/ext_newsletter/client.ts
605
+ var APIClient = class {
606
+ baseUrl;
607
+ httpClient;
608
+ logger = null;
609
+ retryConfig = null;
610
+ // Sub-clients
611
+ ext_newsletter_bulk_email;
612
+ ext_newsletter_campaigns;
613
+ ext_newsletter_logs;
614
+ ext_newsletter_newsletters;
615
+ ext_newsletter_subscriptions;
616
+ ext_newsletter_testing;
617
+ ext_newsletter_newsletter;
618
+ constructor(baseUrl, options) {
619
+ this.baseUrl = baseUrl.replace(/\/$/, "");
620
+ this.httpClient = options?.httpClient || new FetchAdapter();
621
+ if (options?.loggerConfig !== void 0) {
622
+ this.logger = new APILogger(options.loggerConfig);
623
+ }
624
+ if (options?.retryConfig !== void 0) {
625
+ this.retryConfig = options.retryConfig;
626
+ }
627
+ this.ext_newsletter_bulk_email = new ExtNewsletterBulkEmail(this);
628
+ this.ext_newsletter_campaigns = new ExtNewsletterCampaigns(this);
629
+ this.ext_newsletter_logs = new ExtNewsletterLogs(this);
630
+ this.ext_newsletter_newsletters = new ExtNewsletterNewsletters(this);
631
+ this.ext_newsletter_subscriptions = new ExtNewsletterSubscriptions(this);
632
+ this.ext_newsletter_testing = new ExtNewsletterTesting(this);
633
+ this.ext_newsletter_newsletter = new ExtNewsletterNewsletter(this);
634
+ }
635
+ /**
636
+ * Get CSRF token from cookies (for SessionAuthentication).
637
+ *
638
+ * Returns null if cookie doesn't exist (JWT-only auth).
639
+ */
640
+ getCsrfToken() {
641
+ const name = "csrftoken";
642
+ const value = `; ${document.cookie}`;
643
+ const parts = value.split(`; ${name}=`);
644
+ if (parts.length === 2) {
645
+ return parts.pop()?.split(";").shift() || null;
646
+ }
647
+ return null;
648
+ }
649
+ /**
650
+ * Make HTTP request with Django CSRF and session handling.
651
+ * Automatically retries on network errors and 5xx server errors.
652
+ */
653
+ async request(method, path, options) {
654
+ if (this.retryConfig) {
655
+ return withRetry(() => this._makeRequest(method, path, options), {
656
+ ...this.retryConfig,
657
+ onFailedAttempt: (info) => {
658
+ if (this.logger) {
659
+ this.logger.warn(
660
+ `Retry attempt ${info.attemptNumber}/${info.retriesLeft + info.attemptNumber} for ${method} ${path}: ${info.error.message}`
661
+ );
662
+ }
663
+ this.retryConfig?.onFailedAttempt?.(info);
664
+ }
665
+ });
666
+ }
667
+ return this._makeRequest(method, path, options);
668
+ }
669
+ /**
670
+ * Internal request method (without retry wrapper).
671
+ * Used by request() method with optional retry logic.
672
+ */
673
+ async _makeRequest(method, path, options) {
674
+ const url = this.baseUrl ? `${this.baseUrl}${path}` : path;
675
+ const startTime = Date.now();
676
+ const headers = {
677
+ ...options?.headers || {}
678
+ };
679
+ if (!options?.formData && !headers["Content-Type"]) {
680
+ headers["Content-Type"] = "application/json";
681
+ }
682
+ if (this.logger) {
683
+ this.logger.logRequest({
684
+ method,
685
+ url,
686
+ headers,
687
+ body: options?.formData || options?.body,
688
+ timestamp: startTime
689
+ });
690
+ }
691
+ try {
692
+ const response = await this.httpClient.request({
693
+ method,
694
+ url,
695
+ headers,
696
+ params: options?.params,
697
+ body: options?.body,
698
+ formData: options?.formData
699
+ });
700
+ const duration = Date.now() - startTime;
701
+ if (response.status >= 400) {
702
+ const error = new APIError(
703
+ response.status,
704
+ response.statusText,
705
+ response.data,
706
+ url
707
+ );
708
+ if (this.logger) {
709
+ this.logger.logError(
710
+ {
711
+ method,
712
+ url,
713
+ headers,
714
+ body: options?.formData || options?.body,
715
+ timestamp: startTime
716
+ },
717
+ {
718
+ message: error.message,
719
+ statusCode: response.status,
720
+ duration,
721
+ timestamp: Date.now()
722
+ }
723
+ );
724
+ }
725
+ throw error;
726
+ }
727
+ if (this.logger) {
728
+ this.logger.logResponse(
729
+ {
730
+ method,
731
+ url,
732
+ headers,
733
+ body: options?.formData || options?.body,
734
+ timestamp: startTime
735
+ },
736
+ {
737
+ status: response.status,
738
+ statusText: response.statusText,
739
+ data: response.data,
740
+ duration,
741
+ timestamp: Date.now()
742
+ }
743
+ );
744
+ }
745
+ return response.data;
746
+ } catch (error) {
747
+ const duration = Date.now() - startTime;
748
+ if (error instanceof APIError) {
749
+ throw error;
750
+ }
751
+ const isCORSError = error instanceof TypeError && (error.message.toLowerCase().includes("cors") || error.message.toLowerCase().includes("failed to fetch") || error.message.toLowerCase().includes("network request failed"));
752
+ if (this.logger) {
753
+ if (isCORSError) {
754
+ this.logger.error(`\u{1F6AB} CORS Error: ${method} ${url}`);
755
+ this.logger.error(` \u2192 ${error instanceof Error ? error.message : String(error)}`);
756
+ this.logger.error(` \u2192 Configure security_domains parameter on the server`);
757
+ } else {
758
+ this.logger.error(`\u26A0\uFE0F Network Error: ${method} ${url}`);
759
+ this.logger.error(` \u2192 ${error instanceof Error ? error.message : String(error)}`);
760
+ }
761
+ }
762
+ if (typeof window !== "undefined") {
763
+ try {
764
+ if (isCORSError) {
765
+ window.dispatchEvent(new CustomEvent("cors-error", {
766
+ detail: {
767
+ url,
768
+ method,
769
+ error: error instanceof Error ? error.message : String(error),
770
+ timestamp: /* @__PURE__ */ new Date()
771
+ },
772
+ bubbles: true,
773
+ cancelable: false
774
+ }));
775
+ } else {
776
+ window.dispatchEvent(new CustomEvent("network-error", {
777
+ detail: {
778
+ url,
779
+ method,
780
+ error: error instanceof Error ? error.message : String(error),
781
+ timestamp: /* @__PURE__ */ new Date()
782
+ },
783
+ bubbles: true,
784
+ cancelable: false
785
+ }));
786
+ }
787
+ } catch (eventError) {
788
+ }
789
+ }
790
+ const networkError = error instanceof Error ? new NetworkError(error.message, url, error) : new NetworkError("Unknown error", url);
791
+ if (this.logger) {
792
+ this.logger.logError(
793
+ {
794
+ method,
795
+ url,
796
+ headers,
797
+ body: options?.formData || options?.body,
798
+ timestamp: startTime
799
+ },
800
+ {
801
+ message: networkError.message,
802
+ duration,
803
+ timestamp: Date.now()
804
+ }
805
+ );
806
+ }
807
+ throw networkError;
808
+ }
809
+ }
810
+ };
811
+
812
+ // src/api/generated/ext_newsletter/storage.ts
813
+ var LocalStorageAdapter = class {
814
+ logger;
815
+ constructor(logger) {
816
+ this.logger = logger;
817
+ }
818
+ getItem(key) {
819
+ try {
820
+ if (typeof window !== "undefined" && window.localStorage) {
821
+ const value = localStorage.getItem(key);
822
+ this.logger?.debug(`LocalStorage.getItem("${key}"): ${value ? "found" : "not found"}`);
823
+ return value;
824
+ }
825
+ this.logger?.warn("LocalStorage not available: window.localStorage is undefined");
826
+ } catch (error) {
827
+ this.logger?.error("LocalStorage.getItem failed:", error);
828
+ }
829
+ return null;
830
+ }
831
+ setItem(key, value) {
832
+ try {
833
+ if (typeof window !== "undefined" && window.localStorage) {
834
+ localStorage.setItem(key, value);
835
+ this.logger?.debug(`LocalStorage.setItem("${key}"): success`);
836
+ } else {
837
+ this.logger?.warn("LocalStorage not available: window.localStorage is undefined");
838
+ }
839
+ } catch (error) {
840
+ this.logger?.error("LocalStorage.setItem failed:", error);
841
+ }
842
+ }
843
+ removeItem(key) {
844
+ try {
845
+ if (typeof window !== "undefined" && window.localStorage) {
846
+ localStorage.removeItem(key);
847
+ this.logger?.debug(`LocalStorage.removeItem("${key}"): success`);
848
+ } else {
849
+ this.logger?.warn("LocalStorage not available: window.localStorage is undefined");
850
+ }
851
+ } catch (error) {
852
+ this.logger?.error("LocalStorage.removeItem failed:", error);
853
+ }
854
+ }
855
+ };
856
+ var CookieStorageAdapter = class {
857
+ logger;
858
+ constructor(logger) {
859
+ this.logger = logger;
860
+ }
861
+ getItem(key) {
862
+ try {
863
+ if (typeof document === "undefined") {
864
+ this.logger?.warn("Cookies not available: document is undefined (SSR context?)");
865
+ return null;
866
+ }
867
+ const value = `; ${document.cookie}`;
868
+ const parts = value.split(`; ${key}=`);
869
+ if (parts.length === 2) {
870
+ const result = parts.pop()?.split(";").shift() || null;
871
+ this.logger?.debug(`CookieStorage.getItem("${key}"): ${result ? "found" : "not found"}`);
872
+ return result;
873
+ }
874
+ this.logger?.debug(`CookieStorage.getItem("${key}"): not found`);
875
+ } catch (error) {
876
+ this.logger?.error("CookieStorage.getItem failed:", error);
877
+ }
878
+ return null;
879
+ }
880
+ setItem(key, value) {
881
+ try {
882
+ if (typeof document !== "undefined") {
883
+ document.cookie = `${key}=${value}; path=/; max-age=31536000`;
884
+ this.logger?.debug(`CookieStorage.setItem("${key}"): success`);
885
+ } else {
886
+ this.logger?.warn("Cookies not available: document is undefined (SSR context?)");
887
+ }
888
+ } catch (error) {
889
+ this.logger?.error("CookieStorage.setItem failed:", error);
890
+ }
891
+ }
892
+ removeItem(key) {
893
+ try {
894
+ if (typeof document !== "undefined") {
895
+ document.cookie = `${key}=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT`;
896
+ this.logger?.debug(`CookieStorage.removeItem("${key}"): success`);
897
+ } else {
898
+ this.logger?.warn("Cookies not available: document is undefined (SSR context?)");
899
+ }
900
+ } catch (error) {
901
+ this.logger?.error("CookieStorage.removeItem failed:", error);
902
+ }
903
+ }
904
+ };
905
+ var MemoryStorageAdapter = class {
906
+ storage = /* @__PURE__ */ new Map();
907
+ logger;
908
+ constructor(logger) {
909
+ this.logger = logger;
910
+ }
911
+ getItem(key) {
912
+ const value = this.storage.get(key) || null;
913
+ this.logger?.debug(`MemoryStorage.getItem("${key}"): ${value ? "found" : "not found"}`);
914
+ return value;
915
+ }
916
+ setItem(key, value) {
917
+ this.storage.set(key, value);
918
+ this.logger?.debug(`MemoryStorage.setItem("${key}"): success`);
919
+ }
920
+ removeItem(key) {
921
+ this.storage.delete(key);
922
+ this.logger?.debug(`MemoryStorage.removeItem("${key}"): success`);
923
+ }
924
+ };
925
+
926
+ // src/api/generated/ext_newsletter/enums.ts
927
+ var enums_exports = {};
928
+ __export(enums_exports, {
929
+ EmailLogStatus: () => EmailLogStatus,
930
+ NewsletterCampaignStatus: () => NewsletterCampaignStatus
931
+ });
932
+ var EmailLogStatus = /* @__PURE__ */ ((EmailLogStatus2) => {
933
+ EmailLogStatus2["PENDING"] = "pending";
934
+ EmailLogStatus2["SENT"] = "sent";
935
+ EmailLogStatus2["FAILED"] = "failed";
936
+ return EmailLogStatus2;
937
+ })(EmailLogStatus || {});
938
+ var NewsletterCampaignStatus = /* @__PURE__ */ ((NewsletterCampaignStatus2) => {
939
+ NewsletterCampaignStatus2["DRAFT"] = "draft";
940
+ NewsletterCampaignStatus2["SENDING"] = "sending";
941
+ NewsletterCampaignStatus2["SENT"] = "sent";
942
+ NewsletterCampaignStatus2["FAILED"] = "failed";
943
+ return NewsletterCampaignStatus2;
944
+ })(NewsletterCampaignStatus || {});
945
+
946
+ // src/api/generated/ext_newsletter/_utils/schemas/index.ts
947
+ var schemas_exports = {};
948
+ __export(schemas_exports, {
949
+ BulkEmailRequestSchema: () => BulkEmailRequestSchema,
950
+ BulkEmailResponseSchema: () => BulkEmailResponseSchema,
951
+ EmailLogSchema: () => EmailLogSchema,
952
+ ErrorResponseSchema: () => ErrorResponseSchema,
953
+ NewsletterCampaignRequestSchema: () => NewsletterCampaignRequestSchema,
954
+ NewsletterCampaignSchema: () => NewsletterCampaignSchema,
955
+ NewsletterSchema: () => NewsletterSchema,
956
+ NewsletterSubscriptionSchema: () => NewsletterSubscriptionSchema,
957
+ PaginatedEmailLogListSchema: () => PaginatedEmailLogListSchema,
958
+ PaginatedNewsletterCampaignListSchema: () => PaginatedNewsletterCampaignListSchema,
959
+ PaginatedNewsletterListSchema: () => PaginatedNewsletterListSchema,
960
+ PaginatedNewsletterSubscriptionListSchema: () => PaginatedNewsletterSubscriptionListSchema,
961
+ PatchedNewsletterCampaignRequestSchema: () => PatchedNewsletterCampaignRequestSchema,
962
+ PatchedUnsubscribeRequestSchema: () => PatchedUnsubscribeRequestSchema,
963
+ SendCampaignRequestSchema: () => SendCampaignRequestSchema,
964
+ SendCampaignResponseSchema: () => SendCampaignResponseSchema,
965
+ SubscribeRequestSchema: () => SubscribeRequestSchema,
966
+ SubscribeResponseSchema: () => SubscribeResponseSchema,
967
+ SuccessResponseSchema: () => SuccessResponseSchema,
968
+ TestEmailRequestSchema: () => TestEmailRequestSchema,
969
+ UnsubscribeRequestSchema: () => UnsubscribeRequestSchema,
970
+ UnsubscribeSchema: () => UnsubscribeSchema
971
+ });
972
+ var BulkEmailRequestSchema = z.object({
973
+ recipients: z.array(z.email()),
974
+ subject: z.string().min(1).max(255),
975
+ email_title: z.string().min(1).max(255),
976
+ main_text: z.string().min(1),
977
+ main_html_content: z.string().optional(),
978
+ button_text: z.string().max(100).optional(),
979
+ button_url: z.url().optional(),
980
+ secondary_text: z.string().optional()
981
+ });
982
+ var BulkEmailResponseSchema = z.object({
983
+ success: z.boolean(),
984
+ sent_count: z.int(),
985
+ failed_count: z.int(),
986
+ total_recipients: z.int(),
987
+ error: z.string().optional()
988
+ });
989
+ var EmailLogSchema = z.object({
990
+ id: z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i),
991
+ user: z.int().nullable(),
992
+ user_email: z.string(),
993
+ newsletter: z.int().nullable(),
994
+ newsletter_title: z.string(),
995
+ recipient: z.string(),
996
+ subject: z.string(),
997
+ body: z.string(),
998
+ status: z.nativeEnum(EmailLogStatus),
999
+ created_at: z.iso.datetime(),
1000
+ sent_at: z.iso.datetime().nullable(),
1001
+ error_message: z.string().nullable()
1002
+ });
1003
+ var ErrorResponseSchema = z.object({
1004
+ success: z.boolean().optional(),
1005
+ message: z.string()
1006
+ });
1007
+ var NewsletterSchema = z.object({
1008
+ id: z.int(),
1009
+ title: z.string().max(255),
1010
+ description: z.string().optional(),
1011
+ is_active: z.boolean().optional(),
1012
+ auto_subscribe: z.boolean().optional(),
1013
+ created_at: z.iso.datetime(),
1014
+ updated_at: z.iso.datetime(),
1015
+ subscribers_count: z.int()
1016
+ });
1017
+ var NewsletterCampaignSchema = z.object({
1018
+ id: z.int(),
1019
+ newsletter: z.int(),
1020
+ newsletter_title: z.string(),
1021
+ subject: z.string().max(255),
1022
+ email_title: z.string().max(255),
1023
+ main_text: z.string(),
1024
+ main_html_content: z.string().optional(),
1025
+ button_text: z.string().max(100).optional(),
1026
+ button_url: z.url().optional(),
1027
+ secondary_text: z.string().optional(),
1028
+ status: z.nativeEnum(NewsletterCampaignStatus),
1029
+ created_at: z.iso.datetime(),
1030
+ sent_at: z.iso.datetime().nullable(),
1031
+ recipient_count: z.int()
1032
+ });
1033
+ var NewsletterCampaignRequestSchema = z.object({
1034
+ newsletter: z.int(),
1035
+ subject: z.string().min(1).max(255),
1036
+ email_title: z.string().min(1).max(255),
1037
+ main_text: z.string().min(1),
1038
+ main_html_content: z.string().optional(),
1039
+ button_text: z.string().max(100).optional(),
1040
+ button_url: z.url().optional(),
1041
+ secondary_text: z.string().optional()
1042
+ });
1043
+ var NewsletterSubscriptionSchema = z.object({
1044
+ id: z.int(),
1045
+ newsletter: z.int(),
1046
+ newsletter_title: z.string(),
1047
+ user: z.int().nullable().optional(),
1048
+ user_email: z.string(),
1049
+ email: z.email(),
1050
+ is_active: z.boolean().optional(),
1051
+ subscribed_at: z.iso.datetime(),
1052
+ unsubscribed_at: z.iso.datetime().nullable()
1053
+ });
1054
+ var PaginatedEmailLogListSchema = z.object({
1055
+ count: z.int(),
1056
+ page: z.int(),
1057
+ pages: z.int(),
1058
+ page_size: z.int(),
1059
+ has_next: z.boolean(),
1060
+ has_previous: z.boolean(),
1061
+ next_page: z.int().nullable().optional(),
1062
+ previous_page: z.int().nullable().optional(),
1063
+ results: z.array(EmailLogSchema)
1064
+ });
1065
+ var PaginatedNewsletterCampaignListSchema = z.object({
1066
+ count: z.int(),
1067
+ page: z.int(),
1068
+ pages: z.int(),
1069
+ page_size: z.int(),
1070
+ has_next: z.boolean(),
1071
+ has_previous: z.boolean(),
1072
+ next_page: z.int().nullable().optional(),
1073
+ previous_page: z.int().nullable().optional(),
1074
+ results: z.array(NewsletterCampaignSchema)
1075
+ });
1076
+ var PaginatedNewsletterListSchema = z.object({
1077
+ count: z.int(),
1078
+ page: z.int(),
1079
+ pages: z.int(),
1080
+ page_size: z.int(),
1081
+ has_next: z.boolean(),
1082
+ has_previous: z.boolean(),
1083
+ next_page: z.int().nullable().optional(),
1084
+ previous_page: z.int().nullable().optional(),
1085
+ results: z.array(NewsletterSchema)
1086
+ });
1087
+ var PaginatedNewsletterSubscriptionListSchema = z.object({
1088
+ count: z.int(),
1089
+ page: z.int(),
1090
+ pages: z.int(),
1091
+ page_size: z.int(),
1092
+ has_next: z.boolean(),
1093
+ has_previous: z.boolean(),
1094
+ next_page: z.int().nullable().optional(),
1095
+ previous_page: z.int().nullable().optional(),
1096
+ results: z.array(NewsletterSubscriptionSchema)
1097
+ });
1098
+ var PatchedNewsletterCampaignRequestSchema = z.object({
1099
+ newsletter: z.int().optional(),
1100
+ subject: z.string().min(1).max(255).optional(),
1101
+ email_title: z.string().min(1).max(255).optional(),
1102
+ main_text: z.string().min(1).optional(),
1103
+ main_html_content: z.string().optional(),
1104
+ button_text: z.string().max(100).optional(),
1105
+ button_url: z.url().optional(),
1106
+ secondary_text: z.string().optional()
1107
+ });
1108
+ var PatchedUnsubscribeRequestSchema = z.object({
1109
+ subscription_id: z.int().optional()
1110
+ });
1111
+ var SendCampaignRequestSchema = z.object({
1112
+ campaign_id: z.int()
1113
+ });
1114
+ var SendCampaignResponseSchema = z.object({
1115
+ success: z.boolean(),
1116
+ message: z.string().optional(),
1117
+ sent_count: z.int().optional(),
1118
+ error: z.string().optional()
1119
+ });
1120
+ var SubscribeRequestSchema = z.object({
1121
+ newsletter_id: z.int(),
1122
+ email: z.email()
1123
+ });
1124
+ var SubscribeResponseSchema = z.object({
1125
+ success: z.boolean(),
1126
+ message: z.string(),
1127
+ subscription_id: z.int().optional()
1128
+ });
1129
+ var SuccessResponseSchema = z.object({
1130
+ success: z.boolean(),
1131
+ message: z.string()
1132
+ });
1133
+ var TestEmailRequestSchema = z.object({
1134
+ email: z.email(),
1135
+ subject: z.string().min(1).max(255).optional(),
1136
+ message: z.string().min(1).optional()
1137
+ });
1138
+ var UnsubscribeSchema = z.object({
1139
+ subscription_id: z.int()
1140
+ });
1141
+ var UnsubscribeRequestSchema = z.object({
1142
+ subscription_id: z.int()
1143
+ });
1144
+
1145
+ // src/api/generated/ext_newsletter/validation-events.ts
1146
+ function dispatchValidationError(detail) {
1147
+ if (typeof window === "undefined") {
1148
+ return;
1149
+ }
1150
+ try {
1151
+ const event = new CustomEvent("zod-validation-error", {
1152
+ detail,
1153
+ bubbles: true,
1154
+ cancelable: false
1155
+ });
1156
+ window.dispatchEvent(event);
1157
+ } catch (error) {
1158
+ console.warn("Failed to dispatch validation error event:", error);
1159
+ }
1160
+ }
1161
+ function onValidationError(callback) {
1162
+ if (typeof window === "undefined") {
1163
+ return () => {
1164
+ };
1165
+ }
1166
+ const handler = (event) => {
1167
+ if (event instanceof CustomEvent) {
1168
+ callback(event.detail);
1169
+ }
1170
+ };
1171
+ window.addEventListener("zod-validation-error", handler);
1172
+ return () => {
1173
+ window.removeEventListener("zod-validation-error", handler);
1174
+ };
1175
+ }
1176
+ function formatZodError(error) {
1177
+ const issues = error.issues.map((issue, index) => {
1178
+ const path = issue.path.join(".") || "root";
1179
+ const parts = [`${index + 1}. ${path}: ${issue.message}`];
1180
+ if ("expected" in issue && issue.expected) {
1181
+ parts.push(` Expected: ${issue.expected}`);
1182
+ }
1183
+ if ("received" in issue && issue.received) {
1184
+ parts.push(` Received: ${issue.received}`);
1185
+ }
1186
+ return parts.join("\n");
1187
+ });
1188
+ return issues.join("\n");
1189
+ }
1190
+
1191
+ // src/api/generated/ext_newsletter/_utils/fetchers/index.ts
1192
+ var fetchers_exports = {};
1193
+ __export(fetchers_exports, {
1194
+ createNewsletterBulkCreate: () => createNewsletterBulkCreate,
1195
+ createNewsletterCampaignsCreate: () => createNewsletterCampaignsCreate,
1196
+ createNewsletterCampaignsSendCreate: () => createNewsletterCampaignsSendCreate,
1197
+ createNewsletterSubscribeCreate: () => createNewsletterSubscribeCreate,
1198
+ createNewsletterTestCreate: () => createNewsletterTestCreate,
1199
+ createNewsletterUnsubscribeCreate: () => createNewsletterUnsubscribeCreate,
1200
+ deleteNewsletterCampaignsDestroy: () => deleteNewsletterCampaignsDestroy,
1201
+ getNewsletterCampaignsList: () => getNewsletterCampaignsList,
1202
+ getNewsletterCampaignsRetrieve: () => getNewsletterCampaignsRetrieve,
1203
+ getNewsletterLogsList: () => getNewsletterLogsList,
1204
+ getNewsletterNewslettersList: () => getNewsletterNewslettersList,
1205
+ getNewsletterNewslettersRetrieve: () => getNewsletterNewslettersRetrieve,
1206
+ getNewsletterSubscriptionsList: () => getNewsletterSubscriptionsList,
1207
+ partialUpdateNewsletterCampaignsPartialUpdate: () => partialUpdateNewsletterCampaignsPartialUpdate,
1208
+ partialUpdateNewsletterUnsubscribePartialUpdate: () => partialUpdateNewsletterUnsubscribePartialUpdate,
1209
+ updateNewsletterCampaignsUpdate: () => updateNewsletterCampaignsUpdate,
1210
+ updateNewsletterUnsubscribeUpdate: () => updateNewsletterUnsubscribeUpdate
1211
+ });
1212
+
1213
+ // src/api/generated/ext_newsletter/api-instance.ts
1214
+ var globalAPI = null;
1215
+ function getAPIInstance() {
1216
+ if (!globalAPI) {
1217
+ throw new Error(
1218
+ 'API not configured. Call configureAPI() with your base URL before using fetchers or hooks.\n\nExample:\n import { configureAPI } from "./api-instance"\n configureAPI({ baseUrl: "https://api.example.com" })'
1219
+ );
1220
+ }
1221
+ return globalAPI;
1222
+ }
1223
+ function isAPIConfigured() {
1224
+ return globalAPI !== null;
1225
+ }
1226
+ function configureAPI(config) {
1227
+ globalAPI = new API(config.baseUrl, config.options);
1228
+ if (config.token) {
1229
+ globalAPI.setToken(config.token, config.refreshToken);
1230
+ }
1231
+ return globalAPI;
1232
+ }
1233
+ function reconfigureAPI(updates) {
1234
+ const instance = getAPIInstance();
1235
+ if (updates.baseUrl) {
1236
+ instance.setBaseUrl(updates.baseUrl);
1237
+ }
1238
+ if (updates.token) {
1239
+ instance.setToken(updates.token, updates.refreshToken);
1240
+ }
1241
+ return instance;
1242
+ }
1243
+ function clearAPITokens() {
1244
+ const instance = getAPIInstance();
1245
+ instance.clearTokens();
1246
+ }
1247
+ function resetAPI() {
1248
+ if (globalAPI) {
1249
+ globalAPI.clearTokens();
1250
+ }
1251
+ globalAPI = null;
1252
+ }
1253
+
1254
+ // src/api/generated/ext_newsletter/_utils/fetchers/ext_newsletter__newsletter.ts
1255
+ async function partialUpdateNewsletterCampaignsPartialUpdate(id, data, client) {
1256
+ const api = client || getAPIInstance();
1257
+ const response = await api.ext_newsletter_newsletter.campaignsPartialUpdate(id, data);
1258
+ try {
1259
+ return NewsletterCampaignSchema.parse(response);
1260
+ } catch (error) {
1261
+ consola.error("\u274C Zod Validation Failed");
1262
+ consola.box(`partialUpdateNewsletterCampaignsPartialUpdate
1263
+ Path: /cfg/newsletter/campaigns/{id}/
1264
+ Method: PATCH`);
1265
+ if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1266
+ consola.error("Validation Issues:");
1267
+ error.issues.forEach((issue, index) => {
1268
+ consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1269
+ consola.error(` \u251C\u2500 Message: ${issue.message}`);
1270
+ if (issue.expected) consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1271
+ if (issue.received) consola.error(` \u2514\u2500 Received: ${issue.received}`);
1272
+ });
1273
+ }
1274
+ consola.error("Response data:", response);
1275
+ if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1276
+ try {
1277
+ const event = new CustomEvent("zod-validation-error", {
1278
+ detail: {
1279
+ operation: "partialUpdateNewsletterCampaignsPartialUpdate",
1280
+ path: "/cfg/newsletter/campaigns/{id}/",
1281
+ method: "PATCH",
1282
+ error,
1283
+ response,
1284
+ timestamp: /* @__PURE__ */ new Date()
1285
+ },
1286
+ bubbles: true,
1287
+ cancelable: false
1288
+ });
1289
+ window.dispatchEvent(event);
1290
+ } catch (eventError) {
1291
+ consola.warn("Failed to dispatch validation error event:", eventError);
1292
+ }
1293
+ }
1294
+ throw error;
1295
+ }
1296
+ }
1297
+ async function updateNewsletterUnsubscribeUpdate(data, client) {
1298
+ const api = client || getAPIInstance();
1299
+ const response = await api.ext_newsletter_newsletter.unsubscribeUpdate(data);
1300
+ try {
1301
+ return UnsubscribeSchema.parse(response);
1302
+ } catch (error) {
1303
+ consola.error("\u274C Zod Validation Failed");
1304
+ consola.box(`updateNewsletterUnsubscribeUpdate
1305
+ Path: /cfg/newsletter/unsubscribe/
1306
+ Method: PUT`);
1307
+ if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1308
+ consola.error("Validation Issues:");
1309
+ error.issues.forEach((issue, index) => {
1310
+ consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1311
+ consola.error(` \u251C\u2500 Message: ${issue.message}`);
1312
+ if (issue.expected) consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1313
+ if (issue.received) consola.error(` \u2514\u2500 Received: ${issue.received}`);
1314
+ });
1315
+ }
1316
+ consola.error("Response data:", response);
1317
+ if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1318
+ try {
1319
+ const event = new CustomEvent("zod-validation-error", {
1320
+ detail: {
1321
+ operation: "updateNewsletterUnsubscribeUpdate",
1322
+ path: "/cfg/newsletter/unsubscribe/",
1323
+ method: "PUT",
1324
+ error,
1325
+ response,
1326
+ timestamp: /* @__PURE__ */ new Date()
1327
+ },
1328
+ bubbles: true,
1329
+ cancelable: false
1330
+ });
1331
+ window.dispatchEvent(event);
1332
+ } catch (eventError) {
1333
+ consola.warn("Failed to dispatch validation error event:", eventError);
1334
+ }
1335
+ }
1336
+ throw error;
1337
+ }
1338
+ }
1339
+ async function partialUpdateNewsletterUnsubscribePartialUpdate(data, client) {
1340
+ const api = client || getAPIInstance();
1341
+ const response = await api.ext_newsletter_newsletter.unsubscribePartialUpdate(data);
1342
+ try {
1343
+ return UnsubscribeSchema.parse(response);
1344
+ } catch (error) {
1345
+ consola.error("\u274C Zod Validation Failed");
1346
+ consola.box(`partialUpdateNewsletterUnsubscribePartialUpdate
1347
+ Path: /cfg/newsletter/unsubscribe/
1348
+ Method: PATCH`);
1349
+ if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1350
+ consola.error("Validation Issues:");
1351
+ error.issues.forEach((issue, index) => {
1352
+ consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1353
+ consola.error(` \u251C\u2500 Message: ${issue.message}`);
1354
+ if (issue.expected) consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1355
+ if (issue.received) consola.error(` \u2514\u2500 Received: ${issue.received}`);
1356
+ });
1357
+ }
1358
+ consola.error("Response data:", response);
1359
+ if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1360
+ try {
1361
+ const event = new CustomEvent("zod-validation-error", {
1362
+ detail: {
1363
+ operation: "partialUpdateNewsletterUnsubscribePartialUpdate",
1364
+ path: "/cfg/newsletter/unsubscribe/",
1365
+ method: "PATCH",
1366
+ error,
1367
+ response,
1368
+ timestamp: /* @__PURE__ */ new Date()
1369
+ },
1370
+ bubbles: true,
1371
+ cancelable: false
1372
+ });
1373
+ window.dispatchEvent(event);
1374
+ } catch (eventError) {
1375
+ consola.warn("Failed to dispatch validation error event:", eventError);
1376
+ }
1377
+ }
1378
+ throw error;
1379
+ }
1380
+ }
1381
+ async function createNewsletterBulkCreate(data, client) {
1382
+ const api = client || getAPIInstance();
1383
+ const response = await api.ext_newsletter_bulk_email.newsletterBulkCreate(data);
1384
+ try {
1385
+ return BulkEmailResponseSchema.parse(response);
1386
+ } catch (error) {
1387
+ consola.error("\u274C Zod Validation Failed");
1388
+ consola.box(`createNewsletterBulkCreate
1389
+ Path: /cfg/newsletter/bulk/
1390
+ Method: POST`);
1391
+ if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1392
+ consola.error("Validation Issues:");
1393
+ error.issues.forEach((issue, index) => {
1394
+ consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1395
+ consola.error(` \u251C\u2500 Message: ${issue.message}`);
1396
+ if (issue.expected) consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1397
+ if (issue.received) consola.error(` \u2514\u2500 Received: ${issue.received}`);
1398
+ });
1399
+ }
1400
+ consola.error("Response data:", response);
1401
+ if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1402
+ try {
1403
+ const event = new CustomEvent("zod-validation-error", {
1404
+ detail: {
1405
+ operation: "createNewsletterBulkCreate",
1406
+ path: "/cfg/newsletter/bulk/",
1407
+ method: "POST",
1408
+ error,
1409
+ response,
1410
+ timestamp: /* @__PURE__ */ new Date()
1411
+ },
1412
+ bubbles: true,
1413
+ cancelable: false
1414
+ });
1415
+ window.dispatchEvent(event);
1416
+ } catch (eventError) {
1417
+ consola.warn("Failed to dispatch validation error event:", eventError);
1418
+ }
1419
+ }
1420
+ throw error;
1421
+ }
1422
+ }
1423
+ async function getNewsletterCampaignsList(params, client) {
1424
+ const api = client || getAPIInstance();
1425
+ const response = await api.ext_newsletter_campaigns.newsletterCampaignsList(params?.page, params?.page_size);
1426
+ try {
1427
+ return PaginatedNewsletterCampaignListSchema.parse(response);
1428
+ } catch (error) {
1429
+ consola.error("\u274C Zod Validation Failed");
1430
+ consola.box(`getNewsletterCampaignsList
1431
+ Path: /cfg/newsletter/campaigns/
1432
+ Method: GET`);
1433
+ if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1434
+ consola.error("Validation Issues:");
1435
+ error.issues.forEach((issue, index) => {
1436
+ consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1437
+ consola.error(` \u251C\u2500 Message: ${issue.message}`);
1438
+ if (issue.expected) consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1439
+ if (issue.received) consola.error(` \u2514\u2500 Received: ${issue.received}`);
1440
+ });
1441
+ }
1442
+ consola.error("Response data:", response);
1443
+ if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1444
+ try {
1445
+ const event = new CustomEvent("zod-validation-error", {
1446
+ detail: {
1447
+ operation: "getNewsletterCampaignsList",
1448
+ path: "/cfg/newsletter/campaigns/",
1449
+ method: "GET",
1450
+ error,
1451
+ response,
1452
+ timestamp: /* @__PURE__ */ new Date()
1453
+ },
1454
+ bubbles: true,
1455
+ cancelable: false
1456
+ });
1457
+ window.dispatchEvent(event);
1458
+ } catch (eventError) {
1459
+ consola.warn("Failed to dispatch validation error event:", eventError);
1460
+ }
1461
+ }
1462
+ throw error;
1463
+ }
1464
+ }
1465
+ async function createNewsletterCampaignsCreate(data, client) {
1466
+ const api = client || getAPIInstance();
1467
+ const response = await api.ext_newsletter_campaigns.newsletterCampaignsCreate(data);
1468
+ try {
1469
+ return NewsletterCampaignSchema.parse(response);
1470
+ } catch (error) {
1471
+ consola.error("\u274C Zod Validation Failed");
1472
+ consola.box(`createNewsletterCampaignsCreate
1473
+ Path: /cfg/newsletter/campaigns/
1474
+ Method: POST`);
1475
+ if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1476
+ consola.error("Validation Issues:");
1477
+ error.issues.forEach((issue, index) => {
1478
+ consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1479
+ consola.error(` \u251C\u2500 Message: ${issue.message}`);
1480
+ if (issue.expected) consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1481
+ if (issue.received) consola.error(` \u2514\u2500 Received: ${issue.received}`);
1482
+ });
1483
+ }
1484
+ consola.error("Response data:", response);
1485
+ if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1486
+ try {
1487
+ const event = new CustomEvent("zod-validation-error", {
1488
+ detail: {
1489
+ operation: "createNewsletterCampaignsCreate",
1490
+ path: "/cfg/newsletter/campaigns/",
1491
+ method: "POST",
1492
+ error,
1493
+ response,
1494
+ timestamp: /* @__PURE__ */ new Date()
1495
+ },
1496
+ bubbles: true,
1497
+ cancelable: false
1498
+ });
1499
+ window.dispatchEvent(event);
1500
+ } catch (eventError) {
1501
+ consola.warn("Failed to dispatch validation error event:", eventError);
1502
+ }
1503
+ }
1504
+ throw error;
1505
+ }
1506
+ }
1507
+ async function getNewsletterCampaignsRetrieve(id, client) {
1508
+ const api = client || getAPIInstance();
1509
+ const response = await api.ext_newsletter_campaigns.newsletterCampaignsRetrieve(id);
1510
+ try {
1511
+ return NewsletterCampaignSchema.parse(response);
1512
+ } catch (error) {
1513
+ consola.error("\u274C Zod Validation Failed");
1514
+ consola.box(`getNewsletterCampaignsRetrieve
1515
+ Path: /cfg/newsletter/campaigns/{id}/
1516
+ Method: GET`);
1517
+ if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1518
+ consola.error("Validation Issues:");
1519
+ error.issues.forEach((issue, index) => {
1520
+ consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1521
+ consola.error(` \u251C\u2500 Message: ${issue.message}`);
1522
+ if (issue.expected) consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1523
+ if (issue.received) consola.error(` \u2514\u2500 Received: ${issue.received}`);
1524
+ });
1525
+ }
1526
+ consola.error("Response data:", response);
1527
+ if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1528
+ try {
1529
+ const event = new CustomEvent("zod-validation-error", {
1530
+ detail: {
1531
+ operation: "getNewsletterCampaignsRetrieve",
1532
+ path: "/cfg/newsletter/campaigns/{id}/",
1533
+ method: "GET",
1534
+ error,
1535
+ response,
1536
+ timestamp: /* @__PURE__ */ new Date()
1537
+ },
1538
+ bubbles: true,
1539
+ cancelable: false
1540
+ });
1541
+ window.dispatchEvent(event);
1542
+ } catch (eventError) {
1543
+ consola.warn("Failed to dispatch validation error event:", eventError);
1544
+ }
1545
+ }
1546
+ throw error;
1547
+ }
1548
+ }
1549
+ async function updateNewsletterCampaignsUpdate(id, data, client) {
1550
+ const api = client || getAPIInstance();
1551
+ const response = await api.ext_newsletter_campaigns.newsletterCampaignsUpdate(id, data);
1552
+ try {
1553
+ return NewsletterCampaignSchema.parse(response);
1554
+ } catch (error) {
1555
+ consola.error("\u274C Zod Validation Failed");
1556
+ consola.box(`updateNewsletterCampaignsUpdate
1557
+ Path: /cfg/newsletter/campaigns/{id}/
1558
+ Method: PUT`);
1559
+ if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1560
+ consola.error("Validation Issues:");
1561
+ error.issues.forEach((issue, index) => {
1562
+ consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1563
+ consola.error(` \u251C\u2500 Message: ${issue.message}`);
1564
+ if (issue.expected) consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1565
+ if (issue.received) consola.error(` \u2514\u2500 Received: ${issue.received}`);
1566
+ });
1567
+ }
1568
+ consola.error("Response data:", response);
1569
+ if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1570
+ try {
1571
+ const event = new CustomEvent("zod-validation-error", {
1572
+ detail: {
1573
+ operation: "updateNewsletterCampaignsUpdate",
1574
+ path: "/cfg/newsletter/campaigns/{id}/",
1575
+ method: "PUT",
1576
+ error,
1577
+ response,
1578
+ timestamp: /* @__PURE__ */ new Date()
1579
+ },
1580
+ bubbles: true,
1581
+ cancelable: false
1582
+ });
1583
+ window.dispatchEvent(event);
1584
+ } catch (eventError) {
1585
+ consola.warn("Failed to dispatch validation error event:", eventError);
1586
+ }
1587
+ }
1588
+ throw error;
1589
+ }
1590
+ }
1591
+ async function deleteNewsletterCampaignsDestroy(id, client) {
1592
+ const api = client || getAPIInstance();
1593
+ const response = await api.ext_newsletter_campaigns.newsletterCampaignsDestroy(id);
1594
+ return response;
1595
+ }
1596
+ async function createNewsletterCampaignsSendCreate(data, client) {
1597
+ const api = client || getAPIInstance();
1598
+ const response = await api.ext_newsletter_campaigns.newsletterCampaignsSendCreate(data);
1599
+ try {
1600
+ return SendCampaignResponseSchema.parse(response);
1601
+ } catch (error) {
1602
+ consola.error("\u274C Zod Validation Failed");
1603
+ consola.box(`createNewsletterCampaignsSendCreate
1604
+ Path: /cfg/newsletter/campaigns/send/
1605
+ Method: POST`);
1606
+ if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1607
+ consola.error("Validation Issues:");
1608
+ error.issues.forEach((issue, index) => {
1609
+ consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1610
+ consola.error(` \u251C\u2500 Message: ${issue.message}`);
1611
+ if (issue.expected) consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1612
+ if (issue.received) consola.error(` \u2514\u2500 Received: ${issue.received}`);
1613
+ });
1614
+ }
1615
+ consola.error("Response data:", response);
1616
+ if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1617
+ try {
1618
+ const event = new CustomEvent("zod-validation-error", {
1619
+ detail: {
1620
+ operation: "createNewsletterCampaignsSendCreate",
1621
+ path: "/cfg/newsletter/campaigns/send/",
1622
+ method: "POST",
1623
+ error,
1624
+ response,
1625
+ timestamp: /* @__PURE__ */ new Date()
1626
+ },
1627
+ bubbles: true,
1628
+ cancelable: false
1629
+ });
1630
+ window.dispatchEvent(event);
1631
+ } catch (eventError) {
1632
+ consola.warn("Failed to dispatch validation error event:", eventError);
1633
+ }
1634
+ }
1635
+ throw error;
1636
+ }
1637
+ }
1638
+ async function getNewsletterLogsList(params, client) {
1639
+ const api = client || getAPIInstance();
1640
+ const response = await api.ext_newsletter_logs.newsletterLogsList(params?.page, params?.page_size);
1641
+ try {
1642
+ return PaginatedEmailLogListSchema.parse(response);
1643
+ } catch (error) {
1644
+ consola.error("\u274C Zod Validation Failed");
1645
+ consola.box(`getNewsletterLogsList
1646
+ Path: /cfg/newsletter/logs/
1647
+ Method: GET`);
1648
+ if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1649
+ consola.error("Validation Issues:");
1650
+ error.issues.forEach((issue, index) => {
1651
+ consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1652
+ consola.error(` \u251C\u2500 Message: ${issue.message}`);
1653
+ if (issue.expected) consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1654
+ if (issue.received) consola.error(` \u2514\u2500 Received: ${issue.received}`);
1655
+ });
1656
+ }
1657
+ consola.error("Response data:", response);
1658
+ if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1659
+ try {
1660
+ const event = new CustomEvent("zod-validation-error", {
1661
+ detail: {
1662
+ operation: "getNewsletterLogsList",
1663
+ path: "/cfg/newsletter/logs/",
1664
+ method: "GET",
1665
+ error,
1666
+ response,
1667
+ timestamp: /* @__PURE__ */ new Date()
1668
+ },
1669
+ bubbles: true,
1670
+ cancelable: false
1671
+ });
1672
+ window.dispatchEvent(event);
1673
+ } catch (eventError) {
1674
+ consola.warn("Failed to dispatch validation error event:", eventError);
1675
+ }
1676
+ }
1677
+ throw error;
1678
+ }
1679
+ }
1680
+ async function getNewsletterNewslettersList(params, client) {
1681
+ const api = client || getAPIInstance();
1682
+ const response = await api.ext_newsletter_newsletters.newsletterNewslettersList(params?.page, params?.page_size);
1683
+ try {
1684
+ return PaginatedNewsletterListSchema.parse(response);
1685
+ } catch (error) {
1686
+ consola.error("\u274C Zod Validation Failed");
1687
+ consola.box(`getNewsletterNewslettersList
1688
+ Path: /cfg/newsletter/newsletters/
1689
+ Method: GET`);
1690
+ if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1691
+ consola.error("Validation Issues:");
1692
+ error.issues.forEach((issue, index) => {
1693
+ consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1694
+ consola.error(` \u251C\u2500 Message: ${issue.message}`);
1695
+ if (issue.expected) consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1696
+ if (issue.received) consola.error(` \u2514\u2500 Received: ${issue.received}`);
1697
+ });
1698
+ }
1699
+ consola.error("Response data:", response);
1700
+ if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1701
+ try {
1702
+ const event = new CustomEvent("zod-validation-error", {
1703
+ detail: {
1704
+ operation: "getNewsletterNewslettersList",
1705
+ path: "/cfg/newsletter/newsletters/",
1706
+ method: "GET",
1707
+ error,
1708
+ response,
1709
+ timestamp: /* @__PURE__ */ new Date()
1710
+ },
1711
+ bubbles: true,
1712
+ cancelable: false
1713
+ });
1714
+ window.dispatchEvent(event);
1715
+ } catch (eventError) {
1716
+ consola.warn("Failed to dispatch validation error event:", eventError);
1717
+ }
1718
+ }
1719
+ throw error;
1720
+ }
1721
+ }
1722
+ async function getNewsletterNewslettersRetrieve(id, client) {
1723
+ const api = client || getAPIInstance();
1724
+ const response = await api.ext_newsletter_newsletters.newsletterNewslettersRetrieve(id);
1725
+ try {
1726
+ return NewsletterSchema.parse(response);
1727
+ } catch (error) {
1728
+ consola.error("\u274C Zod Validation Failed");
1729
+ consola.box(`getNewsletterNewslettersRetrieve
1730
+ Path: /cfg/newsletter/newsletters/{id}/
1731
+ Method: GET`);
1732
+ if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1733
+ consola.error("Validation Issues:");
1734
+ error.issues.forEach((issue, index) => {
1735
+ consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1736
+ consola.error(` \u251C\u2500 Message: ${issue.message}`);
1737
+ if (issue.expected) consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1738
+ if (issue.received) consola.error(` \u2514\u2500 Received: ${issue.received}`);
1739
+ });
1740
+ }
1741
+ consola.error("Response data:", response);
1742
+ if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1743
+ try {
1744
+ const event = new CustomEvent("zod-validation-error", {
1745
+ detail: {
1746
+ operation: "getNewsletterNewslettersRetrieve",
1747
+ path: "/cfg/newsletter/newsletters/{id}/",
1748
+ method: "GET",
1749
+ error,
1750
+ response,
1751
+ timestamp: /* @__PURE__ */ new Date()
1752
+ },
1753
+ bubbles: true,
1754
+ cancelable: false
1755
+ });
1756
+ window.dispatchEvent(event);
1757
+ } catch (eventError) {
1758
+ consola.warn("Failed to dispatch validation error event:", eventError);
1759
+ }
1760
+ }
1761
+ throw error;
1762
+ }
1763
+ }
1764
+ async function createNewsletterSubscribeCreate(data, client) {
1765
+ const api = client || getAPIInstance();
1766
+ const response = await api.ext_newsletter_subscriptions.newsletterSubscribeCreate(data);
1767
+ try {
1768
+ return SubscribeResponseSchema.parse(response);
1769
+ } catch (error) {
1770
+ consola.error("\u274C Zod Validation Failed");
1771
+ consola.box(`createNewsletterSubscribeCreate
1772
+ Path: /cfg/newsletter/subscribe/
1773
+ Method: POST`);
1774
+ if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1775
+ consola.error("Validation Issues:");
1776
+ error.issues.forEach((issue, index) => {
1777
+ consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1778
+ consola.error(` \u251C\u2500 Message: ${issue.message}`);
1779
+ if (issue.expected) consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1780
+ if (issue.received) consola.error(` \u2514\u2500 Received: ${issue.received}`);
1781
+ });
1782
+ }
1783
+ consola.error("Response data:", response);
1784
+ if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1785
+ try {
1786
+ const event = new CustomEvent("zod-validation-error", {
1787
+ detail: {
1788
+ operation: "createNewsletterSubscribeCreate",
1789
+ path: "/cfg/newsletter/subscribe/",
1790
+ method: "POST",
1791
+ error,
1792
+ response,
1793
+ timestamp: /* @__PURE__ */ new Date()
1794
+ },
1795
+ bubbles: true,
1796
+ cancelable: false
1797
+ });
1798
+ window.dispatchEvent(event);
1799
+ } catch (eventError) {
1800
+ consola.warn("Failed to dispatch validation error event:", eventError);
1801
+ }
1802
+ }
1803
+ throw error;
1804
+ }
1805
+ }
1806
+ async function getNewsletterSubscriptionsList(params, client) {
1807
+ const api = client || getAPIInstance();
1808
+ const response = await api.ext_newsletter_subscriptions.newsletterSubscriptionsList(params?.page, params?.page_size);
1809
+ try {
1810
+ return PaginatedNewsletterSubscriptionListSchema.parse(response);
1811
+ } catch (error) {
1812
+ consola.error("\u274C Zod Validation Failed");
1813
+ consola.box(`getNewsletterSubscriptionsList
1814
+ Path: /cfg/newsletter/subscriptions/
1815
+ Method: GET`);
1816
+ if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1817
+ consola.error("Validation Issues:");
1818
+ error.issues.forEach((issue, index) => {
1819
+ consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1820
+ consola.error(` \u251C\u2500 Message: ${issue.message}`);
1821
+ if (issue.expected) consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1822
+ if (issue.received) consola.error(` \u2514\u2500 Received: ${issue.received}`);
1823
+ });
1824
+ }
1825
+ consola.error("Response data:", response);
1826
+ if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1827
+ try {
1828
+ const event = new CustomEvent("zod-validation-error", {
1829
+ detail: {
1830
+ operation: "getNewsletterSubscriptionsList",
1831
+ path: "/cfg/newsletter/subscriptions/",
1832
+ method: "GET",
1833
+ error,
1834
+ response,
1835
+ timestamp: /* @__PURE__ */ new Date()
1836
+ },
1837
+ bubbles: true,
1838
+ cancelable: false
1839
+ });
1840
+ window.dispatchEvent(event);
1841
+ } catch (eventError) {
1842
+ consola.warn("Failed to dispatch validation error event:", eventError);
1843
+ }
1844
+ }
1845
+ throw error;
1846
+ }
1847
+ }
1848
+ async function createNewsletterUnsubscribeCreate(data, client) {
1849
+ const api = client || getAPIInstance();
1850
+ const response = await api.ext_newsletter_subscriptions.newsletterUnsubscribeCreate(data);
1851
+ try {
1852
+ return SuccessResponseSchema.parse(response);
1853
+ } catch (error) {
1854
+ consola.error("\u274C Zod Validation Failed");
1855
+ consola.box(`createNewsletterUnsubscribeCreate
1856
+ Path: /cfg/newsletter/unsubscribe/
1857
+ Method: POST`);
1858
+ if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1859
+ consola.error("Validation Issues:");
1860
+ error.issues.forEach((issue, index) => {
1861
+ consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1862
+ consola.error(` \u251C\u2500 Message: ${issue.message}`);
1863
+ if (issue.expected) consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1864
+ if (issue.received) consola.error(` \u2514\u2500 Received: ${issue.received}`);
1865
+ });
1866
+ }
1867
+ consola.error("Response data:", response);
1868
+ if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1869
+ try {
1870
+ const event = new CustomEvent("zod-validation-error", {
1871
+ detail: {
1872
+ operation: "createNewsletterUnsubscribeCreate",
1873
+ path: "/cfg/newsletter/unsubscribe/",
1874
+ method: "POST",
1875
+ error,
1876
+ response,
1877
+ timestamp: /* @__PURE__ */ new Date()
1878
+ },
1879
+ bubbles: true,
1880
+ cancelable: false
1881
+ });
1882
+ window.dispatchEvent(event);
1883
+ } catch (eventError) {
1884
+ consola.warn("Failed to dispatch validation error event:", eventError);
1885
+ }
1886
+ }
1887
+ throw error;
1888
+ }
1889
+ }
1890
+ async function createNewsletterTestCreate(data, client) {
1891
+ const api = client || getAPIInstance();
1892
+ const response = await api.ext_newsletter_testing.newsletterTestCreate(data);
1893
+ try {
1894
+ return BulkEmailResponseSchema.parse(response);
1895
+ } catch (error) {
1896
+ consola.error("\u274C Zod Validation Failed");
1897
+ consola.box(`createNewsletterTestCreate
1898
+ Path: /cfg/newsletter/test/
1899
+ Method: POST`);
1900
+ if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1901
+ consola.error("Validation Issues:");
1902
+ error.issues.forEach((issue, index) => {
1903
+ consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1904
+ consola.error(` \u251C\u2500 Message: ${issue.message}`);
1905
+ if (issue.expected) consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1906
+ if (issue.received) consola.error(` \u2514\u2500 Received: ${issue.received}`);
1907
+ });
1908
+ }
1909
+ consola.error("Response data:", response);
1910
+ if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1911
+ try {
1912
+ const event = new CustomEvent("zod-validation-error", {
1913
+ detail: {
1914
+ operation: "createNewsletterTestCreate",
1915
+ path: "/cfg/newsletter/test/",
1916
+ method: "POST",
1917
+ error,
1918
+ response,
1919
+ timestamp: /* @__PURE__ */ new Date()
1920
+ },
1921
+ bubbles: true,
1922
+ cancelable: false
1923
+ });
1924
+ window.dispatchEvent(event);
1925
+ } catch (eventError) {
1926
+ consola.warn("Failed to dispatch validation error event:", eventError);
1927
+ }
1928
+ }
1929
+ throw error;
1930
+ }
1931
+ }
1932
+
1933
+ // src/api/generated/ext_newsletter/index.ts
1934
+ var TOKEN_KEY = "auth_token";
1935
+ var REFRESH_TOKEN_KEY = "refresh_token";
1936
+ var API = class {
1937
+ baseUrl;
1938
+ _client;
1939
+ _token = null;
1940
+ _refreshToken = null;
1941
+ storage;
1942
+ options;
1943
+ // Sub-clients
1944
+ ext_newsletter_bulk_email;
1945
+ ext_newsletter_campaigns;
1946
+ ext_newsletter_logs;
1947
+ ext_newsletter_newsletters;
1948
+ ext_newsletter_subscriptions;
1949
+ ext_newsletter_testing;
1950
+ ext_newsletter_newsletter;
1951
+ constructor(baseUrl, options) {
1952
+ this.baseUrl = baseUrl;
1953
+ this.options = options;
1954
+ const logger = options?.loggerConfig ? new APILogger(options.loggerConfig) : void 0;
1955
+ this.storage = options?.storage || new LocalStorageAdapter(logger);
1956
+ this._loadTokensFromStorage();
1957
+ this._client = new APIClient(this.baseUrl, {
1958
+ retryConfig: this.options?.retryConfig,
1959
+ loggerConfig: this.options?.loggerConfig
1960
+ });
1961
+ this._injectAuthHeader();
1962
+ this.ext_newsletter_bulk_email = this._client.ext_newsletter_bulk_email;
1963
+ this.ext_newsletter_campaigns = this._client.ext_newsletter_campaigns;
1964
+ this.ext_newsletter_logs = this._client.ext_newsletter_logs;
1965
+ this.ext_newsletter_newsletters = this._client.ext_newsletter_newsletters;
1966
+ this.ext_newsletter_subscriptions = this._client.ext_newsletter_subscriptions;
1967
+ this.ext_newsletter_testing = this._client.ext_newsletter_testing;
1968
+ this.ext_newsletter_newsletter = this._client.ext_newsletter_newsletter;
1969
+ }
1970
+ _loadTokensFromStorage() {
1971
+ this._token = this.storage.getItem(TOKEN_KEY);
1972
+ this._refreshToken = this.storage.getItem(REFRESH_TOKEN_KEY);
1973
+ }
1974
+ _reinitClients() {
1975
+ this._client = new APIClient(this.baseUrl, {
1976
+ retryConfig: this.options?.retryConfig,
1977
+ loggerConfig: this.options?.loggerConfig
1978
+ });
1979
+ this._injectAuthHeader();
1980
+ this.ext_newsletter_bulk_email = this._client.ext_newsletter_bulk_email;
1981
+ this.ext_newsletter_campaigns = this._client.ext_newsletter_campaigns;
1982
+ this.ext_newsletter_logs = this._client.ext_newsletter_logs;
1983
+ this.ext_newsletter_newsletters = this._client.ext_newsletter_newsletters;
1984
+ this.ext_newsletter_subscriptions = this._client.ext_newsletter_subscriptions;
1985
+ this.ext_newsletter_testing = this._client.ext_newsletter_testing;
1986
+ this.ext_newsletter_newsletter = this._client.ext_newsletter_newsletter;
1987
+ }
1988
+ _injectAuthHeader() {
1989
+ const originalRequest = this._client.request.bind(this._client);
1990
+ this._client.request = async (method, path, options) => {
1991
+ const token = this.getToken();
1992
+ const mergedOptions = {
1993
+ ...options,
1994
+ headers: {
1995
+ ...options?.headers || {},
1996
+ ...token ? { "Authorization": `Bearer ${token}` } : {}
1997
+ }
1998
+ };
1999
+ return originalRequest(method, path, mergedOptions);
2000
+ };
2001
+ }
2002
+ /**
2003
+ * Get current JWT token
2004
+ */
2005
+ getToken() {
2006
+ return this.storage.getItem(TOKEN_KEY);
2007
+ }
2008
+ /**
2009
+ * Get current refresh token
2010
+ */
2011
+ getRefreshToken() {
2012
+ return this.storage.getItem(REFRESH_TOKEN_KEY);
2013
+ }
2014
+ /**
2015
+ * Set JWT token and refresh token
2016
+ * @param token - JWT access token
2017
+ * @param refreshToken - JWT refresh token (optional)
2018
+ */
2019
+ setToken(token, refreshToken) {
2020
+ this._token = token;
2021
+ this.storage.setItem(TOKEN_KEY, token);
2022
+ if (refreshToken) {
2023
+ this._refreshToken = refreshToken;
2024
+ this.storage.setItem(REFRESH_TOKEN_KEY, refreshToken);
2025
+ }
2026
+ this._reinitClients();
2027
+ }
2028
+ /**
2029
+ * Clear all tokens
2030
+ */
2031
+ clearTokens() {
2032
+ this._token = null;
2033
+ this._refreshToken = null;
2034
+ this.storage.removeItem(TOKEN_KEY);
2035
+ this.storage.removeItem(REFRESH_TOKEN_KEY);
2036
+ this._reinitClients();
2037
+ }
2038
+ /**
2039
+ * Check if user is authenticated
2040
+ */
2041
+ isAuthenticated() {
2042
+ return !!this.getToken();
2043
+ }
2044
+ /**
2045
+ * Update base URL and reinitialize clients
2046
+ * @param url - New base URL
2047
+ */
2048
+ setBaseUrl(url) {
2049
+ this.baseUrl = url;
2050
+ this._reinitClients();
2051
+ }
2052
+ /**
2053
+ * Get current base URL
2054
+ */
2055
+ getBaseUrl() {
2056
+ return this.baseUrl;
2057
+ }
2058
+ /**
2059
+ * Get OpenAPI schema path
2060
+ * @returns Path to the OpenAPI schema JSON file
2061
+ *
2062
+ * Note: The OpenAPI schema is available in the schema.json file.
2063
+ * You can load it dynamically using:
2064
+ * ```typescript
2065
+ * const schema = await fetch('./schema.json').then(r => r.json());
2066
+ * // or using fs in Node.js:
2067
+ * // const schema = JSON.parse(fs.readFileSync('./schema.json', 'utf-8'));
2068
+ * ```
2069
+ */
2070
+ getSchemaPath() {
2071
+ return "./schema.json";
2072
+ }
2073
+ };
2074
+ var apiNewsletter = createExtensionAPI(API);
2075
+
2076
+ // package.json
2077
+ var package_default = {
2078
+ name: "@djangocfg/ext-newsletter",
2079
+ version: "1.0.4",
2080
+ description: "Newsletter and subscription management extension for DjangoCFG",
2081
+ keywords: [
2082
+ "django",
2083
+ "djangocfg",
2084
+ "extension",
2085
+ "newsletter",
2086
+ "subscription",
2087
+ "email",
2088
+ "marketing",
2089
+ "typescript",
2090
+ "react"
2091
+ ],
2092
+ author: {
2093
+ name: "DjangoCFG",
2094
+ url: "https://djangocfg.com"
2095
+ },
2096
+ homepage: "https://hub.djangocfg.com/extensions/djangocfg-ext-newsletter",
2097
+ repository: {
2098
+ type: "git",
2099
+ url: "https://github.com/markolofsen/django-cfg.git",
2100
+ directory: "extensions/newsletter"
2101
+ },
2102
+ bugs: {
2103
+ url: "https://github.com/markolofsen/django-cfg/issues"
2104
+ },
2105
+ license: "MIT",
2106
+ type: "module",
2107
+ main: "./dist/index.cjs",
2108
+ module: "./dist/index.js",
2109
+ types: "./dist/index.d.ts",
2110
+ exports: {
2111
+ ".": {
2112
+ types: "./dist/index.d.ts",
2113
+ import: "./dist/index.js",
2114
+ require: "./dist/index.cjs"
2115
+ },
2116
+ "./hooks": {
2117
+ types: "./dist/hooks.d.ts",
2118
+ import: "./dist/hooks.js",
2119
+ require: "./dist/hooks.cjs"
2120
+ },
2121
+ "./config": {
2122
+ types: "./dist/config.d.ts",
2123
+ import: "./dist/config.js",
2124
+ require: "./dist/config.cjs"
2125
+ }
2126
+ },
2127
+ files: [
2128
+ "dist",
2129
+ "src",
2130
+ "preview.png"
2131
+ ],
2132
+ scripts: {
2133
+ build: "tsup",
2134
+ dev: "tsup --watch",
2135
+ check: "tsc --noEmit"
2136
+ },
2137
+ peerDependencies: {
2138
+ "@djangocfg/api": "workspace:*",
2139
+ "@djangocfg/ext-base": "workspace:*",
2140
+ "@djangocfg/ui-nextjs": "workspace:*",
2141
+ consola: "^3.4.2",
2142
+ "lucide-react": "^0.545.0",
2143
+ next: "^15.5.7",
2144
+ "p-retry": "^7.0.0",
2145
+ react: "^18 || ^19",
2146
+ "react-dom": "^18 || ^19",
2147
+ swr: "^2.3.7",
2148
+ zod: "^4.1.13"
2149
+ },
2150
+ devDependencies: {
2151
+ "@djangocfg/api": "workspace:*",
2152
+ "@djangocfg/ext-base": "workspace:*",
2153
+ "@djangocfg/typescript-config": "workspace:*",
2154
+ "@types/node": "^24.7.2",
2155
+ "@types/react": "^19.0.0",
2156
+ consola: "^3.4.2",
2157
+ "p-retry": "^7.0.0",
2158
+ swr: "^2.3.7",
2159
+ tsup: "^8.5.0",
2160
+ typescript: "^5.9.3"
2161
+ }
2162
+ };
2163
+
2164
+ // src/config.ts
2165
+ var extensionConfig = createExtensionConfig(package_default, {
2166
+ name: "newsletter",
2167
+ displayName: "Newsletter & Campaigns",
2168
+ category: "content",
2169
+ features: [
2170
+ "Subscription management",
2171
+ "Email template system",
2172
+ "Campaign tracking",
2173
+ "Subscriber segmentation",
2174
+ "Analytics dashboard",
2175
+ "Automated campaigns"
2176
+ ],
2177
+ minVersion: "2.0.0",
2178
+ examples: [
2179
+ {
2180
+ title: "Newsletter Subscription Form",
2181
+ description: "Add a newsletter signup form",
2182
+ code: `import { NewsletterForm } from '@djangocfg/ext-newsletter';
2183
+
2184
+ export default function Footer() {
2185
+ return (
2186
+ <NewsletterForm
2187
+ onSubscribe={(email) => {
2188
+ console.log('New subscriber:', email);
2189
+ }}
2190
+ texts={{
2191
+ placeholder: 'Enter your email',
2192
+ button: 'Subscribe',
2193
+ success: 'Thanks for subscribing!',
2194
+ }}
2195
+ />
2196
+ );
2197
+ }`,
2198
+ language: "tsx"
2199
+ }
2200
+ ]
2201
+ });
2202
+
2203
+ export { API, APIClient, APIError, APILogger, BulkEmailRequestSchema, BulkEmailResponseSchema, CookieStorageAdapter, DEFAULT_RETRY_CONFIG, EmailLogSchema, enums_exports as Enums, ErrorResponseSchema, models_exports as ExtNewsletterBulkEmailTypes, models_exports2 as ExtNewsletterCampaignsTypes, models_exports3 as ExtNewsletterLogsTypes, models_exports7 as ExtNewsletterNewsletterTypes, models_exports4 as ExtNewsletterNewslettersTypes, models_exports5 as ExtNewsletterSubscriptionsTypes, models_exports6 as ExtNewsletterTestingTypes, FetchAdapter, fetchers_exports as Fetchers, LocalStorageAdapter, MemoryStorageAdapter, NetworkError, NewsletterCampaignRequestSchema, NewsletterCampaignSchema, NewsletterSchema, NewsletterSubscriptionSchema, PaginatedEmailLogListSchema, PaginatedNewsletterCampaignListSchema, PaginatedNewsletterListSchema, PaginatedNewsletterSubscriptionListSchema, PatchedNewsletterCampaignRequestSchema, PatchedUnsubscribeRequestSchema, REFRESH_TOKEN_KEY, schemas_exports as Schemas, SendCampaignRequestSchema, SendCampaignResponseSchema, SubscribeRequestSchema, SubscribeResponseSchema, SuccessResponseSchema, TOKEN_KEY, TestEmailRequestSchema, UnsubscribeRequestSchema, UnsubscribeSchema, apiNewsletter, clearAPITokens, configureAPI, createNewsletterBulkCreate, createNewsletterCampaignsCreate, createNewsletterCampaignsSendCreate, createNewsletterSubscribeCreate, createNewsletterTestCreate, createNewsletterUnsubscribeCreate, deleteNewsletterCampaignsDestroy, dispatchValidationError, extensionConfig, formatZodError, getAPIInstance, getNewsletterCampaignsList, getNewsletterCampaignsRetrieve, getNewsletterLogsList, getNewsletterNewslettersList, getNewsletterNewslettersRetrieve, getNewsletterSubscriptionsList, isAPIConfigured, onValidationError, partialUpdateNewsletterCampaignsPartialUpdate, partialUpdateNewsletterUnsubscribePartialUpdate, reconfigureAPI, resetAPI, shouldRetry, updateNewsletterCampaignsUpdate, updateNewsletterUnsubscribeUpdate, withRetry };