@djangocfg/ext-newsletter 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +140 -0
- package/dist/chunk-LQLPNWHR.js +2075 -0
- package/dist/hooks.cjs +2539 -0
- package/dist/hooks.d.cts +267 -0
- package/dist/hooks.d.ts +267 -0
- package/dist/hooks.js +370 -0
- package/dist/index.cjs +2153 -0
- package/dist/index.d.cts +2084 -0
- package/dist/index.d.ts +2084 -0
- package/dist/index.js +1 -0
- package/package.json +80 -0
- package/src/api/generated/ext_newsletter/_utils/fetchers/ext_newsletter__newsletter.ts +210 -0
- package/src/api/generated/ext_newsletter/_utils/fetchers/ext_newsletter__newsletter__bulk_email.ts +93 -0
- package/src/api/generated/ext_newsletter/_utils/fetchers/ext_newsletter__newsletter__campaigns.ts +338 -0
- package/src/api/generated/ext_newsletter/_utils/fetchers/ext_newsletter__newsletter__logs.ts +92 -0
- package/src/api/generated/ext_newsletter/_utils/fetchers/ext_newsletter__newsletter__newsletters.ts +150 -0
- package/src/api/generated/ext_newsletter/_utils/fetchers/ext_newsletter__newsletter__subscriptions.ts +210 -0
- package/src/api/generated/ext_newsletter/_utils/fetchers/ext_newsletter__newsletter__testing.ts +93 -0
- package/src/api/generated/ext_newsletter/_utils/fetchers/index.ts +34 -0
- package/src/api/generated/ext_newsletter/_utils/hooks/ext_newsletter__newsletter.ts +81 -0
- package/src/api/generated/ext_newsletter/_utils/hooks/ext_newsletter__newsletter__bulk_email.ts +42 -0
- package/src/api/generated/ext_newsletter/_utils/hooks/ext_newsletter__newsletter__campaigns.ts +130 -0
- package/src/api/generated/ext_newsletter/_utils/hooks/ext_newsletter__newsletter__logs.ts +37 -0
- package/src/api/generated/ext_newsletter/_utils/hooks/ext_newsletter__newsletter__newsletters.ts +52 -0
- package/src/api/generated/ext_newsletter/_utils/hooks/ext_newsletter__newsletter__subscriptions.ts +78 -0
- package/src/api/generated/ext_newsletter/_utils/hooks/ext_newsletter__newsletter__testing.ts +42 -0
- package/src/api/generated/ext_newsletter/_utils/hooks/index.ts +34 -0
- package/src/api/generated/ext_newsletter/_utils/schemas/BulkEmailRequest.schema.ts +26 -0
- package/src/api/generated/ext_newsletter/_utils/schemas/BulkEmailResponse.schema.ts +23 -0
- package/src/api/generated/ext_newsletter/_utils/schemas/EmailLog.schema.ts +31 -0
- package/src/api/generated/ext_newsletter/_utils/schemas/ErrorResponse.schema.ts +20 -0
- package/src/api/generated/ext_newsletter/_utils/schemas/Newsletter.schema.ts +26 -0
- package/src/api/generated/ext_newsletter/_utils/schemas/NewsletterCampaign.schema.ts +33 -0
- package/src/api/generated/ext_newsletter/_utils/schemas/NewsletterCampaignRequest.schema.ts +26 -0
- package/src/api/generated/ext_newsletter/_utils/schemas/NewsletterSubscription.schema.ts +27 -0
- package/src/api/generated/ext_newsletter/_utils/schemas/PaginatedEmailLogList.schema.ts +24 -0
- package/src/api/generated/ext_newsletter/_utils/schemas/PaginatedNewsletterCampaignList.schema.ts +24 -0
- package/src/api/generated/ext_newsletter/_utils/schemas/PaginatedNewsletterList.schema.ts +24 -0
- package/src/api/generated/ext_newsletter/_utils/schemas/PaginatedNewsletterSubscriptionList.schema.ts +24 -0
- package/src/api/generated/ext_newsletter/_utils/schemas/PatchedNewsletterCampaignRequest.schema.ts +26 -0
- package/src/api/generated/ext_newsletter/_utils/schemas/PatchedUnsubscribeRequest.schema.ts +19 -0
- package/src/api/generated/ext_newsletter/_utils/schemas/SendCampaignRequest.schema.ts +19 -0
- package/src/api/generated/ext_newsletter/_utils/schemas/SendCampaignResponse.schema.ts +22 -0
- package/src/api/generated/ext_newsletter/_utils/schemas/SubscribeRequest.schema.ts +20 -0
- package/src/api/generated/ext_newsletter/_utils/schemas/SubscribeResponse.schema.ts +21 -0
- package/src/api/generated/ext_newsletter/_utils/schemas/SuccessResponse.schema.ts +20 -0
- package/src/api/generated/ext_newsletter/_utils/schemas/TestEmailRequest.schema.ts +21 -0
- package/src/api/generated/ext_newsletter/_utils/schemas/Unsubscribe.schema.ts +19 -0
- package/src/api/generated/ext_newsletter/_utils/schemas/UnsubscribeRequest.schema.ts +19 -0
- package/src/api/generated/ext_newsletter/_utils/schemas/index.ts +40 -0
- package/src/api/generated/ext_newsletter/api-instance.ts +131 -0
- package/src/api/generated/ext_newsletter/client.ts +319 -0
- package/src/api/generated/ext_newsletter/enums.ts +24 -0
- package/src/api/generated/ext_newsletter/errors.ts +116 -0
- package/src/api/generated/ext_newsletter/ext_newsletter__newsletter/client.ts +38 -0
- package/src/api/generated/ext_newsletter/ext_newsletter__newsletter/index.ts +2 -0
- package/src/api/generated/ext_newsletter/ext_newsletter__newsletter/models.ts +71 -0
- package/src/api/generated/ext_newsletter/ext_newsletter__newsletter__bulk_email/client.ts +24 -0
- package/src/api/generated/ext_newsletter/ext_newsletter__newsletter__bulk_email/index.ts +2 -0
- package/src/api/generated/ext_newsletter/ext_newsletter__newsletter__bulk_email/models.ts +29 -0
- package/src/api/generated/ext_newsletter/ext_newsletter__newsletter__campaigns/client.ts +85 -0
- package/src/api/generated/ext_newsletter/ext_newsletter__newsletter__campaigns/index.ts +2 -0
- package/src/api/generated/ext_newsletter/ext_newsletter__newsletter__campaigns/models.ts +100 -0
- package/src/api/generated/ext_newsletter/ext_newsletter__newsletter__logs/client.ts +35 -0
- package/src/api/generated/ext_newsletter/ext_newsletter__newsletter__logs/index.ts +2 -0
- package/src/api/generated/ext_newsletter/ext_newsletter__newsletter__logs/models.ts +51 -0
- package/src/api/generated/ext_newsletter/ext_newsletter__newsletter__newsletters/client.ts +45 -0
- package/src/api/generated/ext_newsletter/ext_newsletter__newsletter__newsletters/index.ts +2 -0
- package/src/api/generated/ext_newsletter/ext_newsletter__newsletter__newsletters/models.ts +42 -0
- package/src/api/generated/ext_newsletter/ext_newsletter__newsletter__subscriptions/client.ts +55 -0
- package/src/api/generated/ext_newsletter/ext_newsletter__newsletter__subscriptions/index.ts +2 -0
- package/src/api/generated/ext_newsletter/ext_newsletter__newsletter__subscriptions/models.ts +92 -0
- package/src/api/generated/ext_newsletter/ext_newsletter__newsletter__testing/client.ts +24 -0
- package/src/api/generated/ext_newsletter/ext_newsletter__newsletter__testing/index.ts +2 -0
- package/src/api/generated/ext_newsletter/ext_newsletter__newsletter__testing/models.ts +24 -0
- package/src/api/generated/ext_newsletter/http.ts +103 -0
- package/src/api/generated/ext_newsletter/index.ts +315 -0
- package/src/api/generated/ext_newsletter/logger.ts +259 -0
- package/src/api/generated/ext_newsletter/retry.ts +175 -0
- package/src/api/generated/ext_newsletter/schema.json +1739 -0
- package/src/api/generated/ext_newsletter/storage.ts +161 -0
- package/src/api/generated/ext_newsletter/validation-events.ts +133 -0
- package/src/api/index.ts +9 -0
- package/src/components/Hero/index.tsx +160 -0
- package/src/components/Hero/types.ts +37 -0
- package/src/config.ts +20 -0
- package/src/contexts/newsletter/NewsletterContext.tsx +264 -0
- package/src/contexts/newsletter/types.ts +32 -0
- package/src/hooks/index.ts +21 -0
- package/src/index.ts +14 -0
- package/src/utils/logger.ts +9 -0
package/src/api/generated/ext_newsletter/_utils/fetchers/ext_newsletter__newsletter__campaigns.ts
ADDED
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed fetchers for Campaigns
|
|
3
|
+
*
|
|
4
|
+
* Universal functions that work in any environment:
|
|
5
|
+
* - Next.js (App Router / Pages Router / Server Components)
|
|
6
|
+
* - React Native
|
|
7
|
+
* - Node.js backend
|
|
8
|
+
*
|
|
9
|
+
* These fetchers use Zod schemas for runtime validation.
|
|
10
|
+
*
|
|
11
|
+
* Usage:
|
|
12
|
+
* ```typescript
|
|
13
|
+
* // Configure API once (in your app entry point)
|
|
14
|
+
* import { configureAPI } from '../../api-instance'
|
|
15
|
+
* configureAPI({ baseUrl: 'https://api.example.com' })
|
|
16
|
+
*
|
|
17
|
+
* // Then use fetchers anywhere
|
|
18
|
+
* const users = await getUsers({ page: 1 })
|
|
19
|
+
*
|
|
20
|
+
* // With SWR
|
|
21
|
+
* const { data } = useSWR(['users', params], () => getUsers(params))
|
|
22
|
+
*
|
|
23
|
+
* // With React Query
|
|
24
|
+
* const { data } = useQuery(['users', params], () => getUsers(params))
|
|
25
|
+
*
|
|
26
|
+
* // In Server Component or SSR (pass custom client)
|
|
27
|
+
* import { API } from '../../index'
|
|
28
|
+
* const api = new API('https://api.example.com')
|
|
29
|
+
* const users = await getUsers({ page: 1 }, api)
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
import { consola } from 'consola'
|
|
33
|
+
import { NewsletterCampaignSchema, type NewsletterCampaign } from '../schemas/NewsletterCampaign.schema'
|
|
34
|
+
import { NewsletterCampaignRequestSchema, type NewsletterCampaignRequest } from '../schemas/NewsletterCampaignRequest.schema'
|
|
35
|
+
import { PaginatedNewsletterCampaignListSchema, type PaginatedNewsletterCampaignList } from '../schemas/PaginatedNewsletterCampaignList.schema'
|
|
36
|
+
import { SendCampaignRequestSchema, type SendCampaignRequest } from '../schemas/SendCampaignRequest.schema'
|
|
37
|
+
import { SendCampaignResponseSchema, type SendCampaignResponse } from '../schemas/SendCampaignResponse.schema'
|
|
38
|
+
import { getAPIInstance } from '../../api-instance'
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* List Newsletter Campaigns
|
|
42
|
+
*
|
|
43
|
+
* @method GET
|
|
44
|
+
* @path /cfg/newsletter/campaigns/
|
|
45
|
+
*/
|
|
46
|
+
export async function getNewsletterCampaignsList( params?: { page?: number; page_size?: number }, client?: any
|
|
47
|
+
): Promise<PaginatedNewsletterCampaignList> {
|
|
48
|
+
const api = client || getAPIInstance()
|
|
49
|
+
const response = await api.ext_newsletter_campaigns.newsletterCampaignsList(params?.page, params?.page_size)
|
|
50
|
+
try {
|
|
51
|
+
return PaginatedNewsletterCampaignListSchema.parse(response)
|
|
52
|
+
} catch (error) {
|
|
53
|
+
// Zod validation error - log detailed information
|
|
54
|
+
consola.error('❌ Zod Validation Failed');
|
|
55
|
+
consola.box(`getNewsletterCampaignsList\nPath: /cfg/newsletter/campaigns/\nMethod: GET`);
|
|
56
|
+
|
|
57
|
+
if (error instanceof Error && 'issues' in error && Array.isArray((error as any).issues)) {
|
|
58
|
+
consola.error('Validation Issues:');
|
|
59
|
+
(error as any).issues.forEach((issue: any, index: number) => {
|
|
60
|
+
consola.error(` ${index + 1}. ${issue.path.join('.') || 'root'}`);
|
|
61
|
+
consola.error(` ├─ Message: ${issue.message}`);
|
|
62
|
+
if (issue.expected) consola.error(` ├─ Expected: ${issue.expected}`);
|
|
63
|
+
if (issue.received) consola.error(` └─ Received: ${issue.received}`);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
consola.error('Response data:', response);
|
|
68
|
+
|
|
69
|
+
// Dispatch browser CustomEvent (only if window is defined)
|
|
70
|
+
if (typeof window !== 'undefined' && error instanceof Error && 'issues' in error) {
|
|
71
|
+
try {
|
|
72
|
+
const event = new CustomEvent('zod-validation-error', {
|
|
73
|
+
detail: {
|
|
74
|
+
operation: 'getNewsletterCampaignsList',
|
|
75
|
+
path: '/cfg/newsletter/campaigns/',
|
|
76
|
+
method: 'GET',
|
|
77
|
+
error: error,
|
|
78
|
+
response: response,
|
|
79
|
+
timestamp: new Date(),
|
|
80
|
+
},
|
|
81
|
+
bubbles: true,
|
|
82
|
+
cancelable: false,
|
|
83
|
+
});
|
|
84
|
+
window.dispatchEvent(event);
|
|
85
|
+
} catch (eventError) {
|
|
86
|
+
// Silently fail - event dispatch should never crash the app
|
|
87
|
+
consola.warn('Failed to dispatch validation error event:', eventError);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Re-throw the error
|
|
92
|
+
throw error;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Create Newsletter Campaign
|
|
99
|
+
*
|
|
100
|
+
* @method POST
|
|
101
|
+
* @path /cfg/newsletter/campaigns/
|
|
102
|
+
*/
|
|
103
|
+
export async function createNewsletterCampaignsCreate( data: NewsletterCampaignRequest, client?: any
|
|
104
|
+
): Promise<NewsletterCampaign> {
|
|
105
|
+
const api = client || getAPIInstance()
|
|
106
|
+
const response = await api.ext_newsletter_campaigns.newsletterCampaignsCreate(data)
|
|
107
|
+
try {
|
|
108
|
+
return NewsletterCampaignSchema.parse(response)
|
|
109
|
+
} catch (error) {
|
|
110
|
+
// Zod validation error - log detailed information
|
|
111
|
+
consola.error('❌ Zod Validation Failed');
|
|
112
|
+
consola.box(`createNewsletterCampaignsCreate\nPath: /cfg/newsletter/campaigns/\nMethod: POST`);
|
|
113
|
+
|
|
114
|
+
if (error instanceof Error && 'issues' in error && Array.isArray((error as any).issues)) {
|
|
115
|
+
consola.error('Validation Issues:');
|
|
116
|
+
(error as any).issues.forEach((issue: any, index: number) => {
|
|
117
|
+
consola.error(` ${index + 1}. ${issue.path.join('.') || 'root'}`);
|
|
118
|
+
consola.error(` ├─ Message: ${issue.message}`);
|
|
119
|
+
if (issue.expected) consola.error(` ├─ Expected: ${issue.expected}`);
|
|
120
|
+
if (issue.received) consola.error(` └─ Received: ${issue.received}`);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
consola.error('Response data:', response);
|
|
125
|
+
|
|
126
|
+
// Dispatch browser CustomEvent (only if window is defined)
|
|
127
|
+
if (typeof window !== 'undefined' && error instanceof Error && 'issues' in error) {
|
|
128
|
+
try {
|
|
129
|
+
const event = new CustomEvent('zod-validation-error', {
|
|
130
|
+
detail: {
|
|
131
|
+
operation: 'createNewsletterCampaignsCreate',
|
|
132
|
+
path: '/cfg/newsletter/campaigns/',
|
|
133
|
+
method: 'POST',
|
|
134
|
+
error: error,
|
|
135
|
+
response: response,
|
|
136
|
+
timestamp: new Date(),
|
|
137
|
+
},
|
|
138
|
+
bubbles: true,
|
|
139
|
+
cancelable: false,
|
|
140
|
+
});
|
|
141
|
+
window.dispatchEvent(event);
|
|
142
|
+
} catch (eventError) {
|
|
143
|
+
// Silently fail - event dispatch should never crash the app
|
|
144
|
+
consola.warn('Failed to dispatch validation error event:', eventError);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Re-throw the error
|
|
149
|
+
throw error;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Get Campaign Details
|
|
156
|
+
*
|
|
157
|
+
* @method GET
|
|
158
|
+
* @path /cfg/newsletter/campaigns/{id}/
|
|
159
|
+
*/
|
|
160
|
+
export async function getNewsletterCampaignsRetrieve( id: number, client?: any
|
|
161
|
+
): Promise<NewsletterCampaign> {
|
|
162
|
+
const api = client || getAPIInstance()
|
|
163
|
+
const response = await api.ext_newsletter_campaigns.newsletterCampaignsRetrieve(id)
|
|
164
|
+
try {
|
|
165
|
+
return NewsletterCampaignSchema.parse(response)
|
|
166
|
+
} catch (error) {
|
|
167
|
+
// Zod validation error - log detailed information
|
|
168
|
+
consola.error('❌ Zod Validation Failed');
|
|
169
|
+
consola.box(`getNewsletterCampaignsRetrieve\nPath: /cfg/newsletter/campaigns/{id}/\nMethod: GET`);
|
|
170
|
+
|
|
171
|
+
if (error instanceof Error && 'issues' in error && Array.isArray((error as any).issues)) {
|
|
172
|
+
consola.error('Validation Issues:');
|
|
173
|
+
(error as any).issues.forEach((issue: any, index: number) => {
|
|
174
|
+
consola.error(` ${index + 1}. ${issue.path.join('.') || 'root'}`);
|
|
175
|
+
consola.error(` ├─ Message: ${issue.message}`);
|
|
176
|
+
if (issue.expected) consola.error(` ├─ Expected: ${issue.expected}`);
|
|
177
|
+
if (issue.received) consola.error(` └─ Received: ${issue.received}`);
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
consola.error('Response data:', response);
|
|
182
|
+
|
|
183
|
+
// Dispatch browser CustomEvent (only if window is defined)
|
|
184
|
+
if (typeof window !== 'undefined' && error instanceof Error && 'issues' in error) {
|
|
185
|
+
try {
|
|
186
|
+
const event = new CustomEvent('zod-validation-error', {
|
|
187
|
+
detail: {
|
|
188
|
+
operation: 'getNewsletterCampaignsRetrieve',
|
|
189
|
+
path: '/cfg/newsletter/campaigns/{id}/',
|
|
190
|
+
method: 'GET',
|
|
191
|
+
error: error,
|
|
192
|
+
response: response,
|
|
193
|
+
timestamp: new Date(),
|
|
194
|
+
},
|
|
195
|
+
bubbles: true,
|
|
196
|
+
cancelable: false,
|
|
197
|
+
});
|
|
198
|
+
window.dispatchEvent(event);
|
|
199
|
+
} catch (eventError) {
|
|
200
|
+
// Silently fail - event dispatch should never crash the app
|
|
201
|
+
consola.warn('Failed to dispatch validation error event:', eventError);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Re-throw the error
|
|
206
|
+
throw error;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Update Campaign
|
|
213
|
+
*
|
|
214
|
+
* @method PUT
|
|
215
|
+
* @path /cfg/newsletter/campaigns/{id}/
|
|
216
|
+
*/
|
|
217
|
+
export async function updateNewsletterCampaignsUpdate( id: number, data: NewsletterCampaignRequest, client?: any
|
|
218
|
+
): Promise<NewsletterCampaign> {
|
|
219
|
+
const api = client || getAPIInstance()
|
|
220
|
+
const response = await api.ext_newsletter_campaigns.newsletterCampaignsUpdate(id, data)
|
|
221
|
+
try {
|
|
222
|
+
return NewsletterCampaignSchema.parse(response)
|
|
223
|
+
} catch (error) {
|
|
224
|
+
// Zod validation error - log detailed information
|
|
225
|
+
consola.error('❌ Zod Validation Failed');
|
|
226
|
+
consola.box(`updateNewsletterCampaignsUpdate\nPath: /cfg/newsletter/campaigns/{id}/\nMethod: PUT`);
|
|
227
|
+
|
|
228
|
+
if (error instanceof Error && 'issues' in error && Array.isArray((error as any).issues)) {
|
|
229
|
+
consola.error('Validation Issues:');
|
|
230
|
+
(error as any).issues.forEach((issue: any, index: number) => {
|
|
231
|
+
consola.error(` ${index + 1}. ${issue.path.join('.') || 'root'}`);
|
|
232
|
+
consola.error(` ├─ Message: ${issue.message}`);
|
|
233
|
+
if (issue.expected) consola.error(` ├─ Expected: ${issue.expected}`);
|
|
234
|
+
if (issue.received) consola.error(` └─ Received: ${issue.received}`);
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
consola.error('Response data:', response);
|
|
239
|
+
|
|
240
|
+
// Dispatch browser CustomEvent (only if window is defined)
|
|
241
|
+
if (typeof window !== 'undefined' && error instanceof Error && 'issues' in error) {
|
|
242
|
+
try {
|
|
243
|
+
const event = new CustomEvent('zod-validation-error', {
|
|
244
|
+
detail: {
|
|
245
|
+
operation: 'updateNewsletterCampaignsUpdate',
|
|
246
|
+
path: '/cfg/newsletter/campaigns/{id}/',
|
|
247
|
+
method: 'PUT',
|
|
248
|
+
error: error,
|
|
249
|
+
response: response,
|
|
250
|
+
timestamp: new Date(),
|
|
251
|
+
},
|
|
252
|
+
bubbles: true,
|
|
253
|
+
cancelable: false,
|
|
254
|
+
});
|
|
255
|
+
window.dispatchEvent(event);
|
|
256
|
+
} catch (eventError) {
|
|
257
|
+
// Silently fail - event dispatch should never crash the app
|
|
258
|
+
consola.warn('Failed to dispatch validation error event:', eventError);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// Re-throw the error
|
|
263
|
+
throw error;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Delete Campaign
|
|
270
|
+
*
|
|
271
|
+
* @method DELETE
|
|
272
|
+
* @path /cfg/newsletter/campaigns/{id}/
|
|
273
|
+
*/
|
|
274
|
+
export async function deleteNewsletterCampaignsDestroy( id: number, client?: any
|
|
275
|
+
): Promise<void> {
|
|
276
|
+
const api = client || getAPIInstance()
|
|
277
|
+
const response = await api.ext_newsletter_campaigns.newsletterCampaignsDestroy(id)
|
|
278
|
+
return response
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Send Newsletter Campaign
|
|
284
|
+
*
|
|
285
|
+
* @method POST
|
|
286
|
+
* @path /cfg/newsletter/campaigns/send/
|
|
287
|
+
*/
|
|
288
|
+
export async function createNewsletterCampaignsSendCreate( data: SendCampaignRequest, client?: any
|
|
289
|
+
): Promise<SendCampaignResponse> {
|
|
290
|
+
const api = client || getAPIInstance()
|
|
291
|
+
const response = await api.ext_newsletter_campaigns.newsletterCampaignsSendCreate(data)
|
|
292
|
+
try {
|
|
293
|
+
return SendCampaignResponseSchema.parse(response)
|
|
294
|
+
} catch (error) {
|
|
295
|
+
// Zod validation error - log detailed information
|
|
296
|
+
consola.error('❌ Zod Validation Failed');
|
|
297
|
+
consola.box(`createNewsletterCampaignsSendCreate\nPath: /cfg/newsletter/campaigns/send/\nMethod: POST`);
|
|
298
|
+
|
|
299
|
+
if (error instanceof Error && 'issues' in error && Array.isArray((error as any).issues)) {
|
|
300
|
+
consola.error('Validation Issues:');
|
|
301
|
+
(error as any).issues.forEach((issue: any, index: number) => {
|
|
302
|
+
consola.error(` ${index + 1}. ${issue.path.join('.') || 'root'}`);
|
|
303
|
+
consola.error(` ├─ Message: ${issue.message}`);
|
|
304
|
+
if (issue.expected) consola.error(` ├─ Expected: ${issue.expected}`);
|
|
305
|
+
if (issue.received) consola.error(` └─ Received: ${issue.received}`);
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
consola.error('Response data:', response);
|
|
310
|
+
|
|
311
|
+
// Dispatch browser CustomEvent (only if window is defined)
|
|
312
|
+
if (typeof window !== 'undefined' && error instanceof Error && 'issues' in error) {
|
|
313
|
+
try {
|
|
314
|
+
const event = new CustomEvent('zod-validation-error', {
|
|
315
|
+
detail: {
|
|
316
|
+
operation: 'createNewsletterCampaignsSendCreate',
|
|
317
|
+
path: '/cfg/newsletter/campaigns/send/',
|
|
318
|
+
method: 'POST',
|
|
319
|
+
error: error,
|
|
320
|
+
response: response,
|
|
321
|
+
timestamp: new Date(),
|
|
322
|
+
},
|
|
323
|
+
bubbles: true,
|
|
324
|
+
cancelable: false,
|
|
325
|
+
});
|
|
326
|
+
window.dispatchEvent(event);
|
|
327
|
+
} catch (eventError) {
|
|
328
|
+
// Silently fail - event dispatch should never crash the app
|
|
329
|
+
consola.warn('Failed to dispatch validation error event:', eventError);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// Re-throw the error
|
|
334
|
+
throw error;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed fetchers for Logs
|
|
3
|
+
*
|
|
4
|
+
* Universal functions that work in any environment:
|
|
5
|
+
* - Next.js (App Router / Pages Router / Server Components)
|
|
6
|
+
* - React Native
|
|
7
|
+
* - Node.js backend
|
|
8
|
+
*
|
|
9
|
+
* These fetchers use Zod schemas for runtime validation.
|
|
10
|
+
*
|
|
11
|
+
* Usage:
|
|
12
|
+
* ```typescript
|
|
13
|
+
* // Configure API once (in your app entry point)
|
|
14
|
+
* import { configureAPI } from '../../api-instance'
|
|
15
|
+
* configureAPI({ baseUrl: 'https://api.example.com' })
|
|
16
|
+
*
|
|
17
|
+
* // Then use fetchers anywhere
|
|
18
|
+
* const users = await getUsers({ page: 1 })
|
|
19
|
+
*
|
|
20
|
+
* // With SWR
|
|
21
|
+
* const { data } = useSWR(['users', params], () => getUsers(params))
|
|
22
|
+
*
|
|
23
|
+
* // With React Query
|
|
24
|
+
* const { data } = useQuery(['users', params], () => getUsers(params))
|
|
25
|
+
*
|
|
26
|
+
* // In Server Component or SSR (pass custom client)
|
|
27
|
+
* import { API } from '../../index'
|
|
28
|
+
* const api = new API('https://api.example.com')
|
|
29
|
+
* const users = await getUsers({ page: 1 }, api)
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
import { consola } from 'consola'
|
|
33
|
+
import { PaginatedEmailLogListSchema, type PaginatedEmailLogList } from '../schemas/PaginatedEmailLogList.schema'
|
|
34
|
+
import { getAPIInstance } from '../../api-instance'
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* List Email Logs
|
|
38
|
+
*
|
|
39
|
+
* @method GET
|
|
40
|
+
* @path /cfg/newsletter/logs/
|
|
41
|
+
*/
|
|
42
|
+
export async function getNewsletterLogsList( params?: { page?: number; page_size?: number }, client?: any
|
|
43
|
+
): Promise<PaginatedEmailLogList> {
|
|
44
|
+
const api = client || getAPIInstance()
|
|
45
|
+
const response = await api.ext_newsletter_logs.newsletterLogsList(params?.page, params?.page_size)
|
|
46
|
+
try {
|
|
47
|
+
return PaginatedEmailLogListSchema.parse(response)
|
|
48
|
+
} catch (error) {
|
|
49
|
+
// Zod validation error - log detailed information
|
|
50
|
+
consola.error('❌ Zod Validation Failed');
|
|
51
|
+
consola.box(`getNewsletterLogsList\nPath: /cfg/newsletter/logs/\nMethod: GET`);
|
|
52
|
+
|
|
53
|
+
if (error instanceof Error && 'issues' in error && Array.isArray((error as any).issues)) {
|
|
54
|
+
consola.error('Validation Issues:');
|
|
55
|
+
(error as any).issues.forEach((issue: any, index: number) => {
|
|
56
|
+
consola.error(` ${index + 1}. ${issue.path.join('.') || 'root'}`);
|
|
57
|
+
consola.error(` ├─ Message: ${issue.message}`);
|
|
58
|
+
if (issue.expected) consola.error(` ├─ Expected: ${issue.expected}`);
|
|
59
|
+
if (issue.received) consola.error(` └─ Received: ${issue.received}`);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
consola.error('Response data:', response);
|
|
64
|
+
|
|
65
|
+
// Dispatch browser CustomEvent (only if window is defined)
|
|
66
|
+
if (typeof window !== 'undefined' && error instanceof Error && 'issues' in error) {
|
|
67
|
+
try {
|
|
68
|
+
const event = new CustomEvent('zod-validation-error', {
|
|
69
|
+
detail: {
|
|
70
|
+
operation: 'getNewsletterLogsList',
|
|
71
|
+
path: '/cfg/newsletter/logs/',
|
|
72
|
+
method: 'GET',
|
|
73
|
+
error: error,
|
|
74
|
+
response: response,
|
|
75
|
+
timestamp: new Date(),
|
|
76
|
+
},
|
|
77
|
+
bubbles: true,
|
|
78
|
+
cancelable: false,
|
|
79
|
+
});
|
|
80
|
+
window.dispatchEvent(event);
|
|
81
|
+
} catch (eventError) {
|
|
82
|
+
// Silently fail - event dispatch should never crash the app
|
|
83
|
+
consola.warn('Failed to dispatch validation error event:', eventError);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Re-throw the error
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
|
package/src/api/generated/ext_newsletter/_utils/fetchers/ext_newsletter__newsletter__newsletters.ts
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed fetchers for Newsletters
|
|
3
|
+
*
|
|
4
|
+
* Universal functions that work in any environment:
|
|
5
|
+
* - Next.js (App Router / Pages Router / Server Components)
|
|
6
|
+
* - React Native
|
|
7
|
+
* - Node.js backend
|
|
8
|
+
*
|
|
9
|
+
* These fetchers use Zod schemas for runtime validation.
|
|
10
|
+
*
|
|
11
|
+
* Usage:
|
|
12
|
+
* ```typescript
|
|
13
|
+
* // Configure API once (in your app entry point)
|
|
14
|
+
* import { configureAPI } from '../../api-instance'
|
|
15
|
+
* configureAPI({ baseUrl: 'https://api.example.com' })
|
|
16
|
+
*
|
|
17
|
+
* // Then use fetchers anywhere
|
|
18
|
+
* const users = await getUsers({ page: 1 })
|
|
19
|
+
*
|
|
20
|
+
* // With SWR
|
|
21
|
+
* const { data } = useSWR(['users', params], () => getUsers(params))
|
|
22
|
+
*
|
|
23
|
+
* // With React Query
|
|
24
|
+
* const { data } = useQuery(['users', params], () => getUsers(params))
|
|
25
|
+
*
|
|
26
|
+
* // In Server Component or SSR (pass custom client)
|
|
27
|
+
* import { API } from '../../index'
|
|
28
|
+
* const api = new API('https://api.example.com')
|
|
29
|
+
* const users = await getUsers({ page: 1 }, api)
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
import { consola } from 'consola'
|
|
33
|
+
import { NewsletterSchema, type Newsletter } from '../schemas/Newsletter.schema'
|
|
34
|
+
import { PaginatedNewsletterListSchema, type PaginatedNewsletterList } from '../schemas/PaginatedNewsletterList.schema'
|
|
35
|
+
import { getAPIInstance } from '../../api-instance'
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* List Active Newsletters
|
|
39
|
+
*
|
|
40
|
+
* @method GET
|
|
41
|
+
* @path /cfg/newsletter/newsletters/
|
|
42
|
+
*/
|
|
43
|
+
export async function getNewsletterNewslettersList( params?: { page?: number; page_size?: number }, client?: any
|
|
44
|
+
): Promise<PaginatedNewsletterList> {
|
|
45
|
+
const api = client || getAPIInstance()
|
|
46
|
+
const response = await api.ext_newsletter_newsletters.newsletterNewslettersList(params?.page, params?.page_size)
|
|
47
|
+
try {
|
|
48
|
+
return PaginatedNewsletterListSchema.parse(response)
|
|
49
|
+
} catch (error) {
|
|
50
|
+
// Zod validation error - log detailed information
|
|
51
|
+
consola.error('❌ Zod Validation Failed');
|
|
52
|
+
consola.box(`getNewsletterNewslettersList\nPath: /cfg/newsletter/newsletters/\nMethod: GET`);
|
|
53
|
+
|
|
54
|
+
if (error instanceof Error && 'issues' in error && Array.isArray((error as any).issues)) {
|
|
55
|
+
consola.error('Validation Issues:');
|
|
56
|
+
(error as any).issues.forEach((issue: any, index: number) => {
|
|
57
|
+
consola.error(` ${index + 1}. ${issue.path.join('.') || 'root'}`);
|
|
58
|
+
consola.error(` ├─ Message: ${issue.message}`);
|
|
59
|
+
if (issue.expected) consola.error(` ├─ Expected: ${issue.expected}`);
|
|
60
|
+
if (issue.received) consola.error(` └─ Received: ${issue.received}`);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
consola.error('Response data:', response);
|
|
65
|
+
|
|
66
|
+
// Dispatch browser CustomEvent (only if window is defined)
|
|
67
|
+
if (typeof window !== 'undefined' && error instanceof Error && 'issues' in error) {
|
|
68
|
+
try {
|
|
69
|
+
const event = new CustomEvent('zod-validation-error', {
|
|
70
|
+
detail: {
|
|
71
|
+
operation: 'getNewsletterNewslettersList',
|
|
72
|
+
path: '/cfg/newsletter/newsletters/',
|
|
73
|
+
method: 'GET',
|
|
74
|
+
error: error,
|
|
75
|
+
response: response,
|
|
76
|
+
timestamp: new Date(),
|
|
77
|
+
},
|
|
78
|
+
bubbles: true,
|
|
79
|
+
cancelable: false,
|
|
80
|
+
});
|
|
81
|
+
window.dispatchEvent(event);
|
|
82
|
+
} catch (eventError) {
|
|
83
|
+
// Silently fail - event dispatch should never crash the app
|
|
84
|
+
consola.warn('Failed to dispatch validation error event:', eventError);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Re-throw the error
|
|
89
|
+
throw error;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Get Newsletter Details
|
|
96
|
+
*
|
|
97
|
+
* @method GET
|
|
98
|
+
* @path /cfg/newsletter/newsletters/{id}/
|
|
99
|
+
*/
|
|
100
|
+
export async function getNewsletterNewslettersRetrieve( id: number, client?: any
|
|
101
|
+
): Promise<Newsletter> {
|
|
102
|
+
const api = client || getAPIInstance()
|
|
103
|
+
const response = await api.ext_newsletter_newsletters.newsletterNewslettersRetrieve(id)
|
|
104
|
+
try {
|
|
105
|
+
return NewsletterSchema.parse(response)
|
|
106
|
+
} catch (error) {
|
|
107
|
+
// Zod validation error - log detailed information
|
|
108
|
+
consola.error('❌ Zod Validation Failed');
|
|
109
|
+
consola.box(`getNewsletterNewslettersRetrieve\nPath: /cfg/newsletter/newsletters/{id}/\nMethod: GET`);
|
|
110
|
+
|
|
111
|
+
if (error instanceof Error && 'issues' in error && Array.isArray((error as any).issues)) {
|
|
112
|
+
consola.error('Validation Issues:');
|
|
113
|
+
(error as any).issues.forEach((issue: any, index: number) => {
|
|
114
|
+
consola.error(` ${index + 1}. ${issue.path.join('.') || 'root'}`);
|
|
115
|
+
consola.error(` ├─ Message: ${issue.message}`);
|
|
116
|
+
if (issue.expected) consola.error(` ├─ Expected: ${issue.expected}`);
|
|
117
|
+
if (issue.received) consola.error(` └─ Received: ${issue.received}`);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
consola.error('Response data:', response);
|
|
122
|
+
|
|
123
|
+
// Dispatch browser CustomEvent (only if window is defined)
|
|
124
|
+
if (typeof window !== 'undefined' && error instanceof Error && 'issues' in error) {
|
|
125
|
+
try {
|
|
126
|
+
const event = new CustomEvent('zod-validation-error', {
|
|
127
|
+
detail: {
|
|
128
|
+
operation: 'getNewsletterNewslettersRetrieve',
|
|
129
|
+
path: '/cfg/newsletter/newsletters/{id}/',
|
|
130
|
+
method: 'GET',
|
|
131
|
+
error: error,
|
|
132
|
+
response: response,
|
|
133
|
+
timestamp: new Date(),
|
|
134
|
+
},
|
|
135
|
+
bubbles: true,
|
|
136
|
+
cancelable: false,
|
|
137
|
+
});
|
|
138
|
+
window.dispatchEvent(event);
|
|
139
|
+
} catch (eventError) {
|
|
140
|
+
// Silently fail - event dispatch should never crash the app
|
|
141
|
+
consola.warn('Failed to dispatch validation error event:', eventError);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Re-throw the error
|
|
146
|
+
throw error;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
|