@leadcms/sdk 3.3.4 → 3.3.7
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 +3 -0
- package/dist/cli/bin/pull-all.js +9 -2
- package/dist/cli/bin/pull-all.js.map +1 -1
- package/dist/cli/bin/pull-comments.js +9 -2
- package/dist/cli/bin/pull-comments.js.map +1 -1
- package/dist/cli/bin/pull-content.js +9 -2
- package/dist/cli/bin/pull-content.js.map +1 -1
- package/dist/cli/bin/pull-email-templates.d.ts +6 -0
- package/dist/cli/bin/pull-email-templates.d.ts.map +1 -0
- package/dist/cli/bin/pull-email-templates.js +24 -0
- package/dist/cli/bin/pull-email-templates.js.map +1 -0
- package/dist/cli/bin/pull-media.js +9 -2
- package/dist/cli/bin/pull-media.js.map +1 -1
- package/dist/cli/bin/push-all.js +17 -4
- package/dist/cli/bin/push-all.js.map +1 -1
- package/dist/cli/bin/push-content.js +9 -2
- package/dist/cli/bin/push-content.js.map +1 -1
- package/dist/cli/bin/push-email-templates.d.ts +6 -0
- package/dist/cli/bin/push-email-templates.d.ts.map +1 -0
- package/dist/cli/bin/push-email-templates.js +21 -0
- package/dist/cli/bin/push-email-templates.js.map +1 -0
- package/dist/cli/bin/push-media.js +9 -2
- package/dist/cli/bin/push-media.js.map +1 -1
- package/dist/cli/bin/push.js +2 -0
- package/dist/cli/bin/push.js.map +1 -1
- package/dist/cli/bin/status-all.d.ts +1 -1
- package/dist/cli/bin/status-all.js +255 -31
- package/dist/cli/bin/status-all.js.map +1 -1
- package/dist/cli/bin/status-content.js +9 -2
- package/dist/cli/bin/status-content.js.map +1 -1
- package/dist/cli/bin/status-email-templates.d.ts +6 -0
- package/dist/cli/bin/status-email-templates.d.ts.map +1 -0
- package/dist/cli/bin/status-email-templates.js +29 -0
- package/dist/cli/bin/status-email-templates.js.map +1 -0
- package/dist/cli/bin/status-media.js +9 -2
- package/dist/cli/bin/status-media.js.map +1 -1
- package/dist/cli/bin/status.js +2 -0
- package/dist/cli/bin/status.js.map +1 -1
- package/dist/cli/bin/watch.js +2 -0
- package/dist/cli/bin/watch.js.map +1 -1
- package/dist/cli/index.js +27 -2
- package/dist/cli/index.js.map +1 -1
- package/dist/lib/cms-config-types.d.ts +4 -0
- package/dist/lib/cms-config-types.d.ts.map +1 -1
- package/dist/lib/cms-config-types.js +6 -0
- package/dist/lib/cms-config-types.js.map +1 -1
- package/dist/lib/cms.d.ts.map +1 -1
- package/dist/lib/cms.js +1 -0
- package/dist/lib/cms.js.map +1 -1
- package/dist/lib/config.d.ts +2 -0
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +5 -0
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/content-merge.d.ts +2 -2
- package/dist/lib/content-merge.d.ts.map +1 -1
- package/dist/lib/content-merge.js +39 -35
- package/dist/lib/content-merge.js.map +1 -1
- package/dist/lib/content-transformation.d.ts +1 -1
- package/dist/lib/content-transformation.d.ts.map +1 -1
- package/dist/lib/content-transformation.js +8 -2
- package/dist/lib/content-transformation.js.map +1 -1
- package/dist/lib/data-service.d.ts +56 -0
- package/dist/lib/data-service.d.ts.map +1 -1
- package/dist/lib/data-service.js +246 -36
- package/dist/lib/data-service.js.map +1 -1
- package/dist/lib/email-template-transformation.d.ts +36 -0
- package/dist/lib/email-template-transformation.d.ts.map +1 -0
- package/dist/lib/email-template-transformation.js +88 -0
- package/dist/lib/email-template-transformation.js.map +1 -0
- package/dist/lib/logger.d.ts +63 -0
- package/dist/lib/logger.d.ts.map +1 -0
- package/dist/lib/logger.js +87 -0
- package/dist/lib/logger.js.map +1 -0
- package/dist/lib/spinner.d.ts +25 -0
- package/dist/lib/spinner.d.ts.map +1 -0
- package/dist/lib/spinner.js +80 -0
- package/dist/lib/spinner.js.map +1 -0
- package/dist/scripts/fetch-leadcms-comments.d.ts.map +1 -1
- package/dist/scripts/fetch-leadcms-comments.js +22 -21
- package/dist/scripts/fetch-leadcms-comments.js.map +1 -1
- package/dist/scripts/fetch-leadcms-content.d.ts.map +1 -1
- package/dist/scripts/fetch-leadcms-content.js +46 -45
- package/dist/scripts/fetch-leadcms-content.js.map +1 -1
- package/dist/scripts/fetch-leadcms-email-templates.d.ts +15 -0
- package/dist/scripts/fetch-leadcms-email-templates.d.ts.map +1 -0
- package/dist/scripts/fetch-leadcms-email-templates.js +272 -0
- package/dist/scripts/fetch-leadcms-email-templates.js.map +1 -0
- package/dist/scripts/init-leadcms.d.ts.map +1 -1
- package/dist/scripts/init-leadcms.js +22 -3
- package/dist/scripts/init-leadcms.js.map +1 -1
- package/dist/scripts/leadcms-helpers.d.ts +1 -0
- package/dist/scripts/leadcms-helpers.d.ts.map +1 -1
- package/dist/scripts/leadcms-helpers.js +7 -5
- package/dist/scripts/leadcms-helpers.js.map +1 -1
- package/dist/scripts/pull-all.d.ts +5 -1
- package/dist/scripts/pull-all.d.ts.map +1 -1
- package/dist/scripts/pull-all.js +38 -17
- package/dist/scripts/pull-all.js.map +1 -1
- package/dist/scripts/pull-comments.d.ts.map +1 -1
- package/dist/scripts/pull-comments.js +3 -2
- package/dist/scripts/pull-comments.js.map +1 -1
- package/dist/scripts/pull-content.d.ts.map +1 -1
- package/dist/scripts/pull-content.js +3 -2
- package/dist/scripts/pull-content.js.map +1 -1
- package/dist/scripts/pull-email-templates.d.ts +13 -0
- package/dist/scripts/pull-email-templates.d.ts.map +1 -0
- package/dist/scripts/pull-email-templates.js +79 -0
- package/dist/scripts/pull-email-templates.js.map +1 -0
- package/dist/scripts/pull-media.d.ts.map +1 -1
- package/dist/scripts/pull-media.js +3 -2
- package/dist/scripts/pull-media.js.map +1 -1
- package/dist/scripts/push-email-templates.d.ts +50 -0
- package/dist/scripts/push-email-templates.d.ts.map +1 -0
- package/dist/scripts/push-email-templates.js +687 -0
- package/dist/scripts/push-email-templates.js.map +1 -0
- package/dist/scripts/push-leadcms-content.d.ts +45 -1
- package/dist/scripts/push-leadcms-content.d.ts.map +1 -1
- package/dist/scripts/push-leadcms-content.js +112 -28
- package/dist/scripts/push-leadcms-content.js.map +1 -1
- package/dist/scripts/push-media.d.ts +2 -0
- package/dist/scripts/push-media.d.ts.map +1 -1
- package/dist/scripts/push-media.js +8 -5
- package/dist/scripts/push-media.js.map +1 -1
- package/dist/scripts/sse-watcher.d.ts.map +1 -1
- package/dist/scripts/sse-watcher.js +72 -71
- package/dist/scripts/sse-watcher.js.map +1 -1
- package/leadcms.config.json.sample +2 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-service.d.ts","sourceRoot":"","sources":["../../src/lib/data-service.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"data-service.d.ts","sourceRoot":"","sources":["../../src/lib/data-service.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA4CH,UAAU,WAAW;IACnB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,UAAU,WAAW;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd;AAED,UAAU,iBAAiB;IACzB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;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AI,CAAC;IAiDpD;;OAEG;IACH,UAAU,IAAI,OAAO;IAKrB;;OAEG;IACH,eAAe,IAAI,MAAM,GAAG,IAAI;IAKhC;;OAEG;IACH,kBAAkB,CAAC,WAAW,EAAE,MAAM,GAAG,QAAQ;IA6BjD;;OAEG;IACH,YAAY,IAAI,QAAQ,GAAG,IAAI;IAiB/B;;OAEG;IACH,aAAa,IAAI,IAAI;CAOtB;AAGD,eAAO,MAAM,kBAAkB,oBAA2B,CAAC;AAG3D,OAAO,EAAE,kBAAkB,EAAE,CAAC;AAG9B,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,CAAC"}
|
package/dist/lib/data-service.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Handles API calls vs mock data internally using dependency injection pattern
|
|
4
4
|
*/
|
|
5
5
|
import axios from 'axios';
|
|
6
|
+
import { logger } from './logger.js';
|
|
6
7
|
/**
|
|
7
8
|
* Formats API validation errors in a user-friendly way
|
|
8
9
|
*/
|
|
@@ -184,10 +185,10 @@ class LeadCMSDataService {
|
|
|
184
185
|
// Initialize mock data if needed
|
|
185
186
|
if (this.useMock) {
|
|
186
187
|
this.initializeMockData();
|
|
187
|
-
|
|
188
|
+
logger.verbose(`[DATA SERVICE] Using mock mode with scenario: ${this.currentScenario?.name}`);
|
|
188
189
|
}
|
|
189
190
|
else {
|
|
190
|
-
|
|
191
|
+
logger.verbose(`[DATA SERVICE] Using real API mode: ${this.baseURL}`);
|
|
191
192
|
}
|
|
192
193
|
this.initialized = true;
|
|
193
194
|
}
|
|
@@ -202,6 +203,8 @@ class LeadCMSDataService {
|
|
|
202
203
|
remoteContent: JSON.parse(JSON.stringify(scenario.remoteContent)),
|
|
203
204
|
contentTypes: { ...scenario.contentTypes },
|
|
204
205
|
remoteMedia: JSON.parse(JSON.stringify(scenario.remoteMedia)),
|
|
206
|
+
emailTemplates: JSON.parse(JSON.stringify(scenario.emailTemplates || [])),
|
|
207
|
+
emailGroups: JSON.parse(JSON.stringify(scenario.emailGroups || [])),
|
|
205
208
|
scenario: scenario.name
|
|
206
209
|
};
|
|
207
210
|
}
|
|
@@ -221,13 +224,13 @@ class LeadCMSDataService {
|
|
|
221
224
|
async getAllContent() {
|
|
222
225
|
this._initialize();
|
|
223
226
|
if (this.useMock && this.mockData) {
|
|
224
|
-
|
|
227
|
+
logger.verbose('[MOCK] Returning mock content data');
|
|
225
228
|
// Simulate network delay
|
|
226
229
|
await new Promise(resolve => setTimeout(resolve, 50));
|
|
227
230
|
return [...this.mockData.remoteContent];
|
|
228
231
|
}
|
|
229
232
|
try {
|
|
230
|
-
|
|
233
|
+
logger.verbose('[API] Fetching content from LeadCMS...');
|
|
231
234
|
if (!this.baseURL) {
|
|
232
235
|
throw new Error('LeadCMS URL is not configured. Please set LEADCMS_URL or NEXT_PUBLIC_LEADCMS_URL in your .env file.');
|
|
233
236
|
}
|
|
@@ -237,29 +240,29 @@ class LeadCMSDataService {
|
|
|
237
240
|
});
|
|
238
241
|
// Ensure we always return an array
|
|
239
242
|
if (response.status === 204) {
|
|
240
|
-
|
|
243
|
+
logger.verbose('[API DEBUG] Status 204 - No Content');
|
|
241
244
|
return [];
|
|
242
245
|
}
|
|
243
246
|
const data = response.data;
|
|
244
247
|
if (!data) {
|
|
245
|
-
|
|
248
|
+
logger.verbose('[API DEBUG] No content data returned from API (data is falsy)');
|
|
246
249
|
return [];
|
|
247
250
|
}
|
|
248
251
|
// Check if response has 'items' property (API wrapper format)
|
|
249
252
|
let items;
|
|
250
253
|
if (data.items && Array.isArray(data.items)) {
|
|
251
|
-
|
|
254
|
+
logger.verbose(`[API] Found items array in response wrapper with ${data.items.length} items`);
|
|
252
255
|
items = data.items;
|
|
253
256
|
}
|
|
254
257
|
else if (Array.isArray(data)) {
|
|
255
|
-
|
|
258
|
+
logger.verbose(`[API] Response data is direct array with ${data.length} items`);
|
|
256
259
|
items = data;
|
|
257
260
|
}
|
|
258
261
|
else {
|
|
259
262
|
console.warn('[API] API returned unexpected data format:', typeof data, data);
|
|
260
263
|
return [];
|
|
261
264
|
}
|
|
262
|
-
|
|
265
|
+
logger.verbose(`[API DEBUG] Successfully parsed ${items.length} content items`);
|
|
263
266
|
return items;
|
|
264
267
|
}
|
|
265
268
|
catch (error) {
|
|
@@ -273,7 +276,7 @@ class LeadCMSDataService {
|
|
|
273
276
|
async getContentTypes() {
|
|
274
277
|
this._initialize();
|
|
275
278
|
if (this.useMock && this.mockData) {
|
|
276
|
-
|
|
279
|
+
logger.verbose('[MOCK] Returning mock content types');
|
|
277
280
|
await new Promise(resolve => setTimeout(resolve, 30));
|
|
278
281
|
return Object.entries(this.mockData.contentTypes).map(([uid, format]) => ({
|
|
279
282
|
uid,
|
|
@@ -282,7 +285,7 @@ class LeadCMSDataService {
|
|
|
282
285
|
}));
|
|
283
286
|
}
|
|
284
287
|
try {
|
|
285
|
-
|
|
288
|
+
logger.verbose('[API] Fetching content types from LeadCMS...');
|
|
286
289
|
if (!this.baseURL) {
|
|
287
290
|
throw new Error('LeadCMS URL is not configured. Please set LEADCMS_URL or NEXT_PUBLIC_LEADCMS_URL in your .env file.');
|
|
288
291
|
}
|
|
@@ -302,13 +305,13 @@ class LeadCMSDataService {
|
|
|
302
305
|
async getContentById(id) {
|
|
303
306
|
this._initialize();
|
|
304
307
|
if (this.useMock && this.mockData) {
|
|
305
|
-
|
|
308
|
+
logger.verbose(`[MOCK] Getting content with ID: ${id}`);
|
|
306
309
|
await new Promise(resolve => setTimeout(resolve, 50));
|
|
307
310
|
const content = this.mockData.remoteContent.find(c => c.id === id);
|
|
308
311
|
return content || null;
|
|
309
312
|
}
|
|
310
313
|
try {
|
|
311
|
-
|
|
314
|
+
logger.verbose(`[API] Fetching content with ID: ${id}`);
|
|
312
315
|
if (!this.baseURL) {
|
|
313
316
|
throw new Error('LeadCMS URL is not configured.');
|
|
314
317
|
}
|
|
@@ -319,7 +322,7 @@ class LeadCMSDataService {
|
|
|
319
322
|
}
|
|
320
323
|
catch (error) {
|
|
321
324
|
if (error.response?.status === 404) {
|
|
322
|
-
|
|
325
|
+
logger.verbose(`[API] Content with ID ${id} not found`);
|
|
323
326
|
return null;
|
|
324
327
|
}
|
|
325
328
|
if (error.response?.status === 401) {
|
|
@@ -344,7 +347,7 @@ class LeadCMSDataService {
|
|
|
344
347
|
async createContent(content) {
|
|
345
348
|
this._initialize();
|
|
346
349
|
if (this.useMock && this.mockData) {
|
|
347
|
-
|
|
350
|
+
logger.verbose(`[MOCK] Creating content: ${content.title}`);
|
|
348
351
|
await new Promise(resolve => setTimeout(resolve, 100));
|
|
349
352
|
const newContent = {
|
|
350
353
|
...content,
|
|
@@ -356,7 +359,7 @@ class LeadCMSDataService {
|
|
|
356
359
|
return newContent;
|
|
357
360
|
}
|
|
358
361
|
try {
|
|
359
|
-
|
|
362
|
+
logger.verbose(`[API] Creating content: ${content.title}`);
|
|
360
363
|
const response = await axios.post(`${this.baseURL}/api/content`, content, {
|
|
361
364
|
headers: this.getApiHeaders()
|
|
362
365
|
});
|
|
@@ -392,7 +395,7 @@ class LeadCMSDataService {
|
|
|
392
395
|
async updateContent(id, content) {
|
|
393
396
|
this._initialize();
|
|
394
397
|
if (this.useMock && this.mockData) {
|
|
395
|
-
|
|
398
|
+
logger.verbose(`[MOCK] Updating content ID ${id}: ${content.title}`);
|
|
396
399
|
await new Promise(resolve => setTimeout(resolve, 80));
|
|
397
400
|
const existingIndex = this.mockData.remoteContent.findIndex(c => c.id === id);
|
|
398
401
|
if (existingIndex === -1) {
|
|
@@ -407,7 +410,7 @@ class LeadCMSDataService {
|
|
|
407
410
|
return updatedContent;
|
|
408
411
|
}
|
|
409
412
|
try {
|
|
410
|
-
|
|
413
|
+
logger.verbose(`[API] Updating content ID ${id}: ${content.title}`);
|
|
411
414
|
const response = await axios.put(`${this.baseURL}/api/content/${id}`, content, {
|
|
412
415
|
headers: this.getApiHeaders()
|
|
413
416
|
});
|
|
@@ -443,7 +446,7 @@ class LeadCMSDataService {
|
|
|
443
446
|
async deleteContent(id) {
|
|
444
447
|
this._initialize();
|
|
445
448
|
if (this.useMock && this.mockData) {
|
|
446
|
-
|
|
449
|
+
logger.verbose(`[MOCK] Deleting content with ID: ${id}`);
|
|
447
450
|
await new Promise(resolve => setTimeout(resolve, 80));
|
|
448
451
|
// Remove from mock data
|
|
449
452
|
const index = this.mockData.remoteContent.findIndex(c => c.id === id);
|
|
@@ -453,14 +456,14 @@ class LeadCMSDataService {
|
|
|
453
456
|
return;
|
|
454
457
|
}
|
|
455
458
|
try {
|
|
456
|
-
|
|
459
|
+
logger.verbose(`[API] Deleting content with ID: ${id}`);
|
|
457
460
|
if (!this.baseURL) {
|
|
458
461
|
throw new Error('LeadCMS URL is not configured.');
|
|
459
462
|
}
|
|
460
463
|
await axios.delete(`${this.baseURL}/api/content/${id}`, {
|
|
461
464
|
headers: this.getApiHeaders()
|
|
462
465
|
});
|
|
463
|
-
|
|
466
|
+
logger.verbose('[API] Content deleted successfully');
|
|
464
467
|
}
|
|
465
468
|
catch (error) {
|
|
466
469
|
if (error.response?.status === 401) {
|
|
@@ -476,13 +479,213 @@ class LeadCMSDataService {
|
|
|
476
479
|
throw error;
|
|
477
480
|
}
|
|
478
481
|
}
|
|
482
|
+
/**
|
|
483
|
+
* Get all email templates from LeadCMS or mock data
|
|
484
|
+
*/
|
|
485
|
+
async getAllEmailTemplates() {
|
|
486
|
+
this._initialize();
|
|
487
|
+
if (this.useMock && this.mockData) {
|
|
488
|
+
logger.verbose('[MOCK] Returning mock email templates');
|
|
489
|
+
await new Promise(resolve => setTimeout(resolve, 30));
|
|
490
|
+
return [...this.mockData.emailTemplates];
|
|
491
|
+
}
|
|
492
|
+
try {
|
|
493
|
+
logger.verbose('[API] Fetching email templates from LeadCMS...');
|
|
494
|
+
if (!this.baseURL) {
|
|
495
|
+
throw new Error('LeadCMS URL is not configured.');
|
|
496
|
+
}
|
|
497
|
+
const response = await axios.get(`${this.baseURL}/api/email-templates`, { headers: this.getApiHeaders() });
|
|
498
|
+
return Array.isArray(response.data) ? response.data : [];
|
|
499
|
+
}
|
|
500
|
+
catch (error) {
|
|
501
|
+
if (error.response?.status === 401) {
|
|
502
|
+
throw formatAuthenticationError(error);
|
|
503
|
+
}
|
|
504
|
+
console.error('[API] Failed to fetch email templates:', error.message);
|
|
505
|
+
throw error;
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* Get all email groups from LeadCMS or mock data
|
|
510
|
+
*/
|
|
511
|
+
async getAllEmailGroups() {
|
|
512
|
+
this._initialize();
|
|
513
|
+
if (this.useMock && this.mockData) {
|
|
514
|
+
logger.verbose('[MOCK] Returning mock email groups');
|
|
515
|
+
await new Promise(resolve => setTimeout(resolve, 30));
|
|
516
|
+
return [...this.mockData.emailGroups];
|
|
517
|
+
}
|
|
518
|
+
try {
|
|
519
|
+
logger.verbose('[API] Fetching email groups from LeadCMS...');
|
|
520
|
+
if (!this.baseURL) {
|
|
521
|
+
throw new Error('LeadCMS URL is not configured.');
|
|
522
|
+
}
|
|
523
|
+
const response = await axios.get(`${this.baseURL}/api/email-groups`, { headers: this.getApiHeaders() });
|
|
524
|
+
return Array.isArray(response.data) ? response.data : [];
|
|
525
|
+
}
|
|
526
|
+
catch (error) {
|
|
527
|
+
if (error.response?.status === 401) {
|
|
528
|
+
throw formatAuthenticationError(error);
|
|
529
|
+
}
|
|
530
|
+
console.error('[API] Failed to fetch email groups:', error.message);
|
|
531
|
+
throw error;
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* Create a new email group in LeadCMS or mock
|
|
536
|
+
*/
|
|
537
|
+
async createEmailGroup(group) {
|
|
538
|
+
this._initialize();
|
|
539
|
+
if (this.useMock && this.mockData) {
|
|
540
|
+
logger.verbose(`[MOCK] Creating email group: ${group.name}`);
|
|
541
|
+
await new Promise(resolve => setTimeout(resolve, 60));
|
|
542
|
+
const newGroup = {
|
|
543
|
+
...group,
|
|
544
|
+
id: Math.floor(Math.random() * 1000) + 100,
|
|
545
|
+
createdAt: new Date().toISOString(),
|
|
546
|
+
updatedAt: null,
|
|
547
|
+
};
|
|
548
|
+
this.mockData.emailGroups.push(newGroup);
|
|
549
|
+
return newGroup;
|
|
550
|
+
}
|
|
551
|
+
try {
|
|
552
|
+
logger.verbose(`[API] Creating email group: ${group.name}`);
|
|
553
|
+
if (!this.baseURL) {
|
|
554
|
+
throw new Error('LeadCMS URL is not configured.');
|
|
555
|
+
}
|
|
556
|
+
const response = await axios.post(`${this.baseURL}/api/email-groups`, group, { headers: this.getApiHeaders() });
|
|
557
|
+
return response.data;
|
|
558
|
+
}
|
|
559
|
+
catch (error) {
|
|
560
|
+
if (error.response?.status === 401) {
|
|
561
|
+
throw formatAuthenticationError(error);
|
|
562
|
+
}
|
|
563
|
+
console.error(`[API] Failed to create email group '${group.name}':`, error.message);
|
|
564
|
+
throw error;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* Create new email template in LeadCMS or mock
|
|
569
|
+
*/
|
|
570
|
+
async createEmailTemplate(template) {
|
|
571
|
+
this._initialize();
|
|
572
|
+
if (this.useMock && this.mockData) {
|
|
573
|
+
logger.verbose(`[MOCK] Creating email template: ${template.name}`);
|
|
574
|
+
await new Promise(resolve => setTimeout(resolve, 60));
|
|
575
|
+
const newTemplate = {
|
|
576
|
+
...template,
|
|
577
|
+
id: Math.floor(Math.random() * 1000) + 100,
|
|
578
|
+
createdAt: new Date().toISOString(),
|
|
579
|
+
updatedAt: new Date().toISOString(),
|
|
580
|
+
};
|
|
581
|
+
this.mockData.emailTemplates.push(newTemplate);
|
|
582
|
+
return newTemplate;
|
|
583
|
+
}
|
|
584
|
+
try {
|
|
585
|
+
logger.verbose(`[API] Creating email template: ${template.name}`);
|
|
586
|
+
const response = await axios.post(`${this.baseURL}/api/email-templates`, template, { headers: this.getApiHeaders() });
|
|
587
|
+
return response.data;
|
|
588
|
+
}
|
|
589
|
+
catch (error) {
|
|
590
|
+
if (error.response?.status === 401) {
|
|
591
|
+
throw formatAuthenticationError(error);
|
|
592
|
+
}
|
|
593
|
+
if (error.response?.status === 422 && error.response?.data?.errors) {
|
|
594
|
+
const validationMessage = formatApiValidationErrors(error.response);
|
|
595
|
+
const enhancedError = new Error(`Validation failed${validationMessage}`);
|
|
596
|
+
enhancedError.status = 422;
|
|
597
|
+
enhancedError.validationErrors = error.response.data.errors;
|
|
598
|
+
throw enhancedError;
|
|
599
|
+
}
|
|
600
|
+
console.error('[API] Failed to create email template:', error.message);
|
|
601
|
+
throw error;
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* Update existing email template in LeadCMS or mock
|
|
606
|
+
*/
|
|
607
|
+
async updateEmailTemplate(id, template) {
|
|
608
|
+
this._initialize();
|
|
609
|
+
if (this.useMock && this.mockData) {
|
|
610
|
+
logger.verbose(`[MOCK] Updating email template ID ${id}: ${template.name}`);
|
|
611
|
+
await new Promise(resolve => setTimeout(resolve, 60));
|
|
612
|
+
const existingIndex = this.mockData.emailTemplates.findIndex(t => t.id === id);
|
|
613
|
+
if (existingIndex === -1) {
|
|
614
|
+
throw new Error(`Email template with id ${id} not found`);
|
|
615
|
+
}
|
|
616
|
+
const updatedTemplate = {
|
|
617
|
+
...this.mockData.emailTemplates[existingIndex],
|
|
618
|
+
...template,
|
|
619
|
+
updatedAt: new Date().toISOString(),
|
|
620
|
+
};
|
|
621
|
+
this.mockData.emailTemplates[existingIndex] = updatedTemplate;
|
|
622
|
+
return updatedTemplate;
|
|
623
|
+
}
|
|
624
|
+
try {
|
|
625
|
+
logger.verbose(`[API] Updating email template ID ${id}: ${template.name}`);
|
|
626
|
+
const response = await axios.patch(`${this.baseURL}/api/email-templates/${id}`, template, { headers: this.getApiHeaders() });
|
|
627
|
+
return response.data;
|
|
628
|
+
}
|
|
629
|
+
catch (error) {
|
|
630
|
+
if (error.response?.status === 401) {
|
|
631
|
+
throw formatAuthenticationError(error);
|
|
632
|
+
}
|
|
633
|
+
if (error.response?.status === 422 && error.response?.data?.errors) {
|
|
634
|
+
const validationMessage = formatApiValidationErrors(error.response);
|
|
635
|
+
const enhancedError = new Error(`Validation failed${validationMessage}`);
|
|
636
|
+
enhancedError.status = 422;
|
|
637
|
+
enhancedError.validationErrors = error.response.data.errors;
|
|
638
|
+
throw enhancedError;
|
|
639
|
+
}
|
|
640
|
+
console.error('[API] Failed to update email template:', error.message);
|
|
641
|
+
throw error;
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
/**
|
|
645
|
+
* Delete email template from LeadCMS
|
|
646
|
+
*/
|
|
647
|
+
async deleteEmailTemplate(id) {
|
|
648
|
+
this._initialize();
|
|
649
|
+
if (this.useMock && this.mockData) {
|
|
650
|
+
logger.verbose(`[MOCK] Deleting email template with ID: ${id}`);
|
|
651
|
+
await new Promise(resolve => setTimeout(resolve, 50));
|
|
652
|
+
const index = this.mockData.emailTemplates.findIndex(t => t.id === id);
|
|
653
|
+
if (index !== -1) {
|
|
654
|
+
this.mockData.emailTemplates.splice(index, 1);
|
|
655
|
+
}
|
|
656
|
+
return;
|
|
657
|
+
}
|
|
658
|
+
try {
|
|
659
|
+
logger.verbose(`[API] Deleting email template with ID: ${id}`);
|
|
660
|
+
if (!this.baseURL) {
|
|
661
|
+
throw new Error('LeadCMS URL is not configured.');
|
|
662
|
+
}
|
|
663
|
+
await axios.delete(`${this.baseURL}/api/email-templates/${id}`, {
|
|
664
|
+
headers: this.getApiHeaders(),
|
|
665
|
+
});
|
|
666
|
+
logger.verbose('[API] Email template deleted successfully');
|
|
667
|
+
}
|
|
668
|
+
catch (error) {
|
|
669
|
+
if (error.response?.status === 401) {
|
|
670
|
+
throw formatAuthenticationError(error);
|
|
671
|
+
}
|
|
672
|
+
if (error.response?.status === 422) {
|
|
673
|
+
const enhancedError = new Error(`Email template validation failed: ${formatApiValidationErrors(error.response)}`);
|
|
674
|
+
enhancedError.status = 422;
|
|
675
|
+
enhancedError.validationErrors = error.response.data.errors;
|
|
676
|
+
throw enhancedError;
|
|
677
|
+
}
|
|
678
|
+
console.error('[API] Failed to delete email template:', error.message);
|
|
679
|
+
throw error;
|
|
680
|
+
}
|
|
681
|
+
}
|
|
479
682
|
/**
|
|
480
683
|
* Create content type in LeadCMS or mock
|
|
481
684
|
*/
|
|
482
685
|
async createContentType(contentType) {
|
|
483
686
|
this._initialize();
|
|
484
687
|
if (this.useMock && this.mockData && contentType.uid && contentType.format) {
|
|
485
|
-
|
|
688
|
+
logger.verbose(`[MOCK] Creating content type: ${contentType.uid}`);
|
|
486
689
|
await new Promise(resolve => setTimeout(resolve, 60));
|
|
487
690
|
this.mockData.contentTypes[contentType.uid] = contentType.format;
|
|
488
691
|
return {
|
|
@@ -492,7 +695,7 @@ class LeadCMSDataService {
|
|
|
492
695
|
};
|
|
493
696
|
}
|
|
494
697
|
try {
|
|
495
|
-
|
|
698
|
+
logger.verbose(`[API] Creating content type: ${contentType.uid}`);
|
|
496
699
|
const response = await axios.post(`${this.baseURL}/api/content-types`, contentType, {
|
|
497
700
|
headers: this.getApiHeaders()
|
|
498
701
|
});
|
|
@@ -509,7 +712,7 @@ class LeadCMSDataService {
|
|
|
509
712
|
async getAllMedia(scopeUid) {
|
|
510
713
|
this._initialize();
|
|
511
714
|
if (this.useMock && this.mockData) {
|
|
512
|
-
|
|
715
|
+
logger.verbose('[MOCK] Returning mock media data');
|
|
513
716
|
await new Promise(resolve => setTimeout(resolve, 50));
|
|
514
717
|
let media = [...this.mockData.remoteMedia];
|
|
515
718
|
if (scopeUid) {
|
|
@@ -518,7 +721,7 @@ class LeadCMSDataService {
|
|
|
518
721
|
return media;
|
|
519
722
|
}
|
|
520
723
|
try {
|
|
521
|
-
|
|
724
|
+
logger.verbose('[API] Fetching media from LeadCMS using sync API...');
|
|
522
725
|
if (!this.baseURL) {
|
|
523
726
|
throw new Error('LeadCMS URL is not configured.');
|
|
524
727
|
}
|
|
@@ -548,7 +751,7 @@ class LeadCMSDataService {
|
|
|
548
751
|
syncToken = nextToken;
|
|
549
752
|
page++;
|
|
550
753
|
}
|
|
551
|
-
|
|
754
|
+
logger.verbose(`[API] Fetched ${allMedia.length} media items`);
|
|
552
755
|
return allMedia;
|
|
553
756
|
}
|
|
554
757
|
catch (error) {
|
|
@@ -562,7 +765,7 @@ class LeadCMSDataService {
|
|
|
562
765
|
async uploadMedia(formData) {
|
|
563
766
|
this._initialize();
|
|
564
767
|
if (this.useMock && this.mockData) {
|
|
565
|
-
|
|
768
|
+
logger.verbose('[MOCK] Uploading media file');
|
|
566
769
|
await new Promise(resolve => setTimeout(resolve, 100));
|
|
567
770
|
// Extract data from FormData for mock
|
|
568
771
|
const scopeUid = formData.get('ScopeUid');
|
|
@@ -584,7 +787,7 @@ class LeadCMSDataService {
|
|
|
584
787
|
return newMedia;
|
|
585
788
|
}
|
|
586
789
|
try {
|
|
587
|
-
|
|
790
|
+
logger.verbose('[API] Uploading media file...');
|
|
588
791
|
if (!this.baseURL) {
|
|
589
792
|
throw new Error('LeadCMS URL is not configured.');
|
|
590
793
|
}
|
|
@@ -594,7 +797,7 @@ class LeadCMSDataService {
|
|
|
594
797
|
// Don't set Content-Type, let axios set it with boundary for multipart
|
|
595
798
|
}
|
|
596
799
|
});
|
|
597
|
-
|
|
800
|
+
logger.verbose('[API] Media uploaded successfully');
|
|
598
801
|
return response.data;
|
|
599
802
|
}
|
|
600
803
|
catch (error) {
|
|
@@ -617,7 +820,7 @@ class LeadCMSDataService {
|
|
|
617
820
|
async updateMedia(formData) {
|
|
618
821
|
this._initialize();
|
|
619
822
|
if (this.useMock && this.mockData) {
|
|
620
|
-
|
|
823
|
+
logger.verbose('[MOCK] Updating media file');
|
|
621
824
|
await new Promise(resolve => setTimeout(resolve, 100));
|
|
622
825
|
const scopeUid = formData.get('ScopeUid');
|
|
623
826
|
const fileName = formData.get('FileName');
|
|
@@ -633,7 +836,7 @@ class LeadCMSDataService {
|
|
|
633
836
|
return updatedMedia;
|
|
634
837
|
}
|
|
635
838
|
try {
|
|
636
|
-
|
|
839
|
+
logger.verbose('[API] Updating media file...');
|
|
637
840
|
if (!this.baseURL) {
|
|
638
841
|
throw new Error('LeadCMS URL is not configured.');
|
|
639
842
|
}
|
|
@@ -642,7 +845,7 @@ class LeadCMSDataService {
|
|
|
642
845
|
'Authorization': `Bearer ${this.apiKey}`,
|
|
643
846
|
}
|
|
644
847
|
});
|
|
645
|
-
|
|
848
|
+
logger.verbose('[API] Media updated successfully');
|
|
646
849
|
return response.data;
|
|
647
850
|
}
|
|
648
851
|
catch (error) {
|
|
@@ -665,7 +868,7 @@ class LeadCMSDataService {
|
|
|
665
868
|
async deleteMedia(pathToFile) {
|
|
666
869
|
this._initialize();
|
|
667
870
|
if (this.useMock && this.mockData) {
|
|
668
|
-
|
|
871
|
+
logger.verbose(`[MOCK] Deleting media file: ${pathToFile}`);
|
|
669
872
|
await new Promise(resolve => setTimeout(resolve, 80));
|
|
670
873
|
// Parse path to extract scopeUid and name
|
|
671
874
|
// Path format: /api/media/scopeUid/filename or scopeUid/filename
|
|
@@ -680,14 +883,14 @@ class LeadCMSDataService {
|
|
|
680
883
|
return;
|
|
681
884
|
}
|
|
682
885
|
try {
|
|
683
|
-
|
|
886
|
+
logger.verbose(`[API] Deleting media file: ${pathToFile}`);
|
|
684
887
|
if (!this.baseURL) {
|
|
685
888
|
throw new Error('LeadCMS URL is not configured.');
|
|
686
889
|
}
|
|
687
890
|
await axios.delete(`${this.baseURL}/api/media/${pathToFile}`, {
|
|
688
891
|
headers: this.getApiHeaders()
|
|
689
892
|
});
|
|
690
|
-
|
|
893
|
+
logger.verbose('[API] Media deleted successfully');
|
|
691
894
|
}
|
|
692
895
|
catch (error) {
|
|
693
896
|
if (error.response?.status === 401) {
|
|
@@ -728,9 +931,14 @@ class LeadCMSDataService {
|
|
|
728
931
|
remoteContent: JSON.parse(JSON.stringify(scenario.remoteContent)),
|
|
729
932
|
contentTypes: { ...scenario.contentTypes },
|
|
730
933
|
remoteMedia: JSON.parse(JSON.stringify(scenario.remoteMedia)),
|
|
934
|
+
emailTemplates: JSON.parse(JSON.stringify(scenario.emailTemplates || [])),
|
|
935
|
+
emailGroups: JSON.parse(JSON.stringify(scenario.emailGroups || [])),
|
|
731
936
|
scenario: scenario.name
|
|
732
937
|
};
|
|
733
|
-
|
|
938
|
+
logger.verbose(`[MOCK] Switched to scenario: ${scenario.name}`);
|
|
939
|
+
if (!this.mockData) {
|
|
940
|
+
throw new Error('Mock data not initialized');
|
|
941
|
+
}
|
|
734
942
|
return this.mockData;
|
|
735
943
|
}
|
|
736
944
|
/**
|
|
@@ -745,6 +953,8 @@ class LeadCMSDataService {
|
|
|
745
953
|
remoteContent: [...this.mockData.remoteContent],
|
|
746
954
|
contentTypes: { ...this.mockData.contentTypes },
|
|
747
955
|
remoteMedia: [...this.mockData.remoteMedia],
|
|
956
|
+
emailTemplates: [...this.mockData.emailTemplates],
|
|
957
|
+
emailGroups: [...this.mockData.emailGroups],
|
|
748
958
|
scenario: this.currentScenario?.name || ''
|
|
749
959
|
};
|
|
750
960
|
}
|