@capillarytech/creatives-library 9.0.52 → 9.0.53-alpha.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.
@@ -63,7 +63,6 @@ export const ENABLE_AI_SUGGESTIONS = 'ENABLE_AI_SUGGESTIONS';
63
63
  export const AI_CONTENT_BOT_DISABLED = 'AI_CONTENT_BOT_DISABLED';
64
64
  export const AI_DOCUMENTATION_BOT_ENABLED = 'AI_DOCUMENTATION_BOT_ENABLED';
65
65
  export const ENABLE_PRODUCT_SUPPORT_VIDEOS = 'ENABLE_PRODUCT_SUPPORT_VIDEOS';
66
- export const SUPPORT_ENGAGEMENT_MODULE = 'SUPPORT_ENGAGEMENT_MODULE';
67
66
  export const EMBEDDED = 'embedded';
68
67
  // --- Tag/Validation Constants ---
69
68
  export const CARD_RELATED_TAGS = [
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@capillarytech/creatives-library",
3
3
  "author": "meharaj",
4
- "version": "9.0.52",
4
+ "version": "9.0.53-alpha.0",
5
5
  "description": "Capillary creatives ui",
6
6
  "main": "./index.js",
7
7
  "module": "./index.es.js",
package/services/api.js CHANGED
@@ -701,6 +701,15 @@ export const createCentralCommsMetaId = (payload, metaType = TRANSACTION) => {
701
701
  return request(url, getAPICallObject('POST', payload, false, false, false, true));
702
702
  };
703
703
 
704
+ // CCS CommDefinition API (new Veyron /api/v1/commdefinition surface, proxied
705
+ // through cap-creatives-api's /comm-definitions). Used by CommunicationFlow's
706
+ // own Save action — separate from the legacy messageMeta functions above,
707
+ // which remain in use by CreativesContainer's own save flow (Cap/sagas.js).
708
+ export const createCommDefinition = (payload) => {
709
+ const url = `${API_ENDPOINT}/comm-definitions`;
710
+ return request(url, getAPICallObject('POST', payload, false, false, false, true));
711
+ };
712
+
704
713
  export const getCentralCommsMetaIds = (metaIds, metaType = TRANSACTION) => {
705
714
  const url = `${API_ENDPOINT}/common/central-comms/meta-id/${metaType}?metaIds=${metaIds}`;
706
715
  return request(url, getAPICallObject('GET', null, false, false, false, true));
package/utils/common.js CHANGED
@@ -99,10 +99,6 @@ export const hasSupportCKEditor = Auth.hasFeatureAccess.bind(
99
99
  null,
100
100
  SUPPORT_CK_EDITOR,
101
101
  );
102
- export const hasSupportEngagementModule = Auth.hasFeatureAccess.bind(
103
- null,
104
- SUPPORT_ENGAGEMENT_MODULE,
105
- );
106
102
 
107
103
  export const hasGiftVoucherFeature = Auth.hasFeatureAccess.bind(
108
104
  null,
@@ -17,10 +17,11 @@ import { createStructuredSelector } from 'reselect';
17
17
  import CapRow from '@capillarytech/cap-ui-library/CapRow';
18
18
  import CapDivider from '@capillarytech/cap-ui-library/CapDivider';
19
19
  import CapButton from '@capillarytech/cap-ui-library/CapButton';
20
+ import CapLabel from '@capillarytech/cap-ui-library/CapLabel';
20
21
  // import injectSaga from '../../utils/injectSaga'; // cap-coupons flows disabled
21
22
  // import injectReducer from '../../utils/injectReducer';
22
23
  import { makeSelectAuthenticated } from '../Cap/selectors';
23
- import { createCentralCommsMetaId, getCentralCommsMetaIds } from '../../services/api';
24
+ import { createCommDefinition } from '../../services/api';
24
25
  import DynamicControlsStep from './steps/DynamicControlsStep';
25
26
  import MessageTypeStep from './steps/MessageTypeStep';
26
27
  import CommunicationStrategyStep from './steps/CommunicationStrategyStep';
@@ -35,9 +36,9 @@ import {
35
36
  CHANNELS,
36
37
  INCENTIVE_TYPES,
37
38
  DYNAMIC_CONTROLS_CONFIG,
38
- CHANNEL_CONTENT_KEY_MAP,
39
- CHANNEL_DELIVERY_KEY_MAP,
40
- CAMPAIGNS,
39
+ CCS_STRATEGY_TYPE_SINGLE,
40
+ CCS_CHANNEL_CONTENT_KEY_MAP,
41
+ CCS_CHANNEL_DELIVERY_KEY_MAP,
41
42
  } from './constants';
42
43
  import { getEnabledSteps } from './utils/getEnabledSteps';
43
44
  import messages from './messages';
@@ -64,6 +65,25 @@ const hasDeliverySettingForChannel = (channelSetting, channel) => {
64
65
  return !!settings && Object.values(settings).some((v) => v !== null && v !== '' && v !== undefined);
65
66
  };
66
67
 
68
+ // createCommDefinition resolves (rather than rejects) with the CCS error envelope
69
+ // for 4xx/5xx responses — see api.js's request()/checkStatus. A duplicate
70
+ // referenceId within the org comes back as this specific 409.
71
+ const isDuplicateReferenceIdError = (res) => res?.success === false && res?.status?.message === 'REFERENCE_ID_EXISTS';
72
+
73
+ /**
74
+ * CCS requires referenceId on create; the consumer-supplied Alert/comm name is
75
+ * mandatory but referenceId is optional in every consumer's own form. Generate
76
+ * a stable fallback from the name rather than failing the save.
77
+ */
78
+ const buildCcsReferenceId = (name) => {
79
+ const slug = (name || 'COMM')
80
+ .trim()
81
+ .toUpperCase()
82
+ .replace(/[^A-Z0-9]+/g, '_')
83
+ .replace(/^_+|_+$/g, '') || 'COMM';
84
+ return `${slug}_${Date.now()}`;
85
+ };
86
+
67
87
  const CommunicationFlow = ({
68
88
  config,
69
89
  initialData,
@@ -91,6 +111,7 @@ const CommunicationFlow = ({
91
111
  };
92
112
  });
93
113
  const [validationErrors, setValidationErrors] = useState({});
114
+ const [saveError, setSaveError] = useState(null);
94
115
 
95
116
  // Memoize enabled steps
96
117
  const enabledSteps = useMemo(() => getEnabledSteps(config), [config]);
@@ -150,74 +171,75 @@ const CommunicationFlow = ({
150
171
  }, []);
151
172
 
152
173
  const handleSave = useCallback(async () => {
174
+ setSaveError(null);
153
175
  const aggregatedData = getAggregatedData();
154
176
  const shouldUseCCS = config?.useCCS !== false;
177
+ let ccsCommDefinition = null;
155
178
 
156
179
  if (shouldUseCCS) {
157
- const ouId = config?.context?.ouId || -1;
158
- const module = config?.context?.module
159
- || (config?.consumer ? config.consumer.toUpperCase() : CAMPAIGNS);
180
+ const isMultiChannel = [CHANNEL_PRIORITY, AB_TEST].includes(aggregatedData.communicationStrategy);
181
+ const contentItem = (aggregatedData.contentItems || [])[0];
182
+ // Consumer-supplied name (e.g. CapNotify's Alert Name field) — CommunicationFlow
183
+ // has no name input of its own, so this is mandatory input from config.context.
184
+ const name = config?.context?.name;
160
185
 
161
- const channelContentKeyMap = CHANNEL_CONTENT_KEY_MAP;
162
- const channelDeliveryKeyMap = CHANNEL_DELIVERY_KEY_MAP;
186
+ // CCS create is SINGLE-strategy only this phase (D1); CHANNEL_PRIORITY/AB_TEST
187
+ // carry multiple content items with no CCS equivalent yet.
188
+ if (!isMultiChannel && contentItem && name) {
189
+ const channel = (contentItem.channel || '').toUpperCase();
190
+ const contentKey = CCS_CHANNEL_CONTENT_KEY_MAP[channel];
191
+ const deliveryKey = CCS_CHANNEL_DELIVERY_KEY_MAP[channel];
192
+ const { dynamicControls = {} } = aggregatedData;
193
+ const channelSettings = aggregatedData.deliverySetting?.channelSetting?.[channel] || {};
194
+ const referenceId = config?.context?.referenceId || buildCcsReferenceId(name);
163
195
 
164
- const contentItems = aggregatedData.contentItems || [];
165
- const { dynamicControls = {} } = aggregatedData;
196
+ const payload = {
197
+ referenceId,
198
+ name,
199
+ description: config?.context?.description || undefined,
200
+ strategyType: CCS_STRATEGY_TYPE_SINGLE,
201
+ settings: {
202
+ additionalSettings: {
203
+ useTinyUrl: dynamicControls.useTinyUrl ?? false,
204
+ encryptUrl: dynamicControls.sendToControlCustomers ?? false,
205
+ linkTrackingEnabled: dynamicControls.overrideDailyLimit ?? false,
206
+ userSubscriptionDisabled: dynamicControls.sendToBrandPocs ?? false,
207
+ },
208
+ executionParams: {},
209
+ },
210
+ singleChannelStrategy: {
211
+ channel,
212
+ ...(contentKey && { [contentKey]: contentItem.templateData }),
213
+ ...(deliveryKey && { [deliveryKey]: { channelSettings: { channel, ...channelSettings } } }),
214
+ },
215
+ };
166
216
 
167
- const additionalSettings = {
168
- useTinyUrl: dynamicControls.useTinyUrl ?? false,
169
- encryptUrl: dynamicControls.sendToControlCustomers ?? false,
170
- linkTrackingEnabled: dynamicControls.overrideDailyLimit ?? false,
171
- userSubscriptionDisabled: dynamicControls.sendToBrandPocs ?? false,
172
- };
173
-
174
- if (contentItems.length > 0) {
175
217
  try {
176
- const responses = await Promise.all(
177
- contentItems.map((item) => {
178
- const channel = (item.channel || '').toUpperCase();
179
- const contentKey = channelContentKeyMap[channel];
180
- const deliveryKey = channelDeliveryKeyMap[channel];
181
- const payload = {
182
- centralCommsPayload: {
183
- ouId,
184
- channel,
185
- module,
186
- executionParams: {},
187
- clientName: 'EMF',
188
- ...(contentKey && {
189
- [contentKey]: { channel, ...item.templateData },
190
- }),
191
- ...(deliveryKey && {
192
- [deliveryKey]: {
193
- additionalSettings,
194
- channelSettings: {
195
- channel,
196
- ...(aggregatedData.deliverySetting?.channelSetting?.[channel] || {}),
197
- },
198
- },
199
- }),
200
- },
201
- };
202
- return createCentralCommsMetaId(payload);
203
- }),
204
- );
205
-
206
- const metaIds = responses
207
- .map((res) => res?.response?.data?.id)
208
- .filter(Boolean)
209
- .join(',');
210
-
211
- if (metaIds) {
212
- const getResponse = await getCentralCommsMetaIds(metaIds);
218
+ const res = await createCommDefinition(payload);
219
+ if (isDuplicateReferenceIdError(res)) {
220
+ // Duplicate referenceId in this org — block the save so the user can
221
+ // change it, rather than silently proceeding without a CCS comm.
222
+ setSaveError(formatMessage(messages.duplicateReferenceIdError));
223
+ return;
224
+ }
225
+ const data = res?.response?.data;
226
+ if (data?.id) {
227
+ ccsCommDefinition = {
228
+ id: data.id,
229
+ referenceId: data.referenceId,
230
+ version: data.version?.version || 1,
231
+ status: data.status,
232
+ };
213
233
  }
214
234
  } catch (error) {
215
- console.error('[CommunicationFlow] CCS createCentralCommsMetaId error:', error);
235
+ console.error('[CommunicationFlow] CCS createCommDefinition error:', error);
216
236
  }
237
+ } else if (!name) {
238
+ console.warn('[CommunicationFlow] Skipping CCS createCommDefinition — config.context.name is required');
217
239
  }
218
240
  }
219
241
 
220
- onSave(aggregatedData);
242
+ onSave(ccsCommDefinition ? { ...aggregatedData, ccsCommDefinition } : aggregatedData);
221
243
  }, [getAggregatedData, config, onSave]);
222
244
 
223
245
  // Call onChange callback when stepData changes
@@ -317,6 +339,11 @@ const CommunicationFlow = ({
317
339
  {renderSteps()}
318
340
  {onSave && (
319
341
  <CapRow useLegacy className="communication-flow-container__footer">
342
+ {saveError && (
343
+ <CapLabel type="label2" className="communication-flow-container__save-error">
344
+ {saveError}
345
+ </CapLabel>
346
+ )}
320
347
  <CapButton type="primary" onClick={handleSave} disabled={isSaveDisabled}>
321
348
  {formatMessage(messages.save)}
322
349
  </CapButton>
@@ -19,6 +19,7 @@ import CapIcon from '@capillarytech/cap-ui-library/CapIcon';
19
19
  import CapLabel from '@capillarytech/cap-ui-library/CapLabel';
20
20
  import CapHeader from '@capillarytech/cap-ui-library/CapHeader';
21
21
  import CapSlideBox from '@capillarytech/cap-ui-library/CapSlideBox';
22
+ import CapTooltip from '@capillarytech/cap-ui-library/CapTooltip';
22
23
  import CommunicationFlow from './index';
23
24
  import { CHANNELS, DEFAULT_COMMUNICATION_STRATEGY_OPTIONS, DYNAMIC_CONTROLS_CONFIG } from './constants';
24
25
  import {
@@ -74,6 +75,8 @@ const CommunicationFlowCard = ({
74
75
  onChange,
75
76
  cap,
76
77
  intl,
78
+ disabled,
79
+ disabledTooltip,
77
80
  }) => {
78
81
  const { formatMessage } = intl || {};
79
82
  const [showSlideBox, setShowSlideBox] = useState(false);
@@ -91,8 +94,9 @@ const CommunicationFlowCard = ({
91
94
  }, [onCancel]);
92
95
 
93
96
  const handleOpen = useCallback(() => {
97
+ if (disabled) return;
94
98
  setShowSlideBox(true);
95
- }, []);
99
+ }, [disabled]);
96
100
 
97
101
  const firstItem = savedData?.contentItems?.[0];
98
102
  const channelConfig = firstItem
@@ -182,9 +186,17 @@ const CommunicationFlowCard = ({
182
186
  <CapImage src={addCreativesIllustration} />
183
187
  </CapColumn>
184
188
  <CapColumn span={14} className="empty-card-action-col">
185
- <CapButton type="secondary" onClick={handleOpen}>
186
- {formatMessage(messages.addCreatives)}
187
- </CapButton>
189
+ {disabled && disabledTooltip ? (
190
+ <CapTooltip title={disabledTooltip}>
191
+ <CapButton type="secondary" disabled>
192
+ {formatMessage(messages.addCreatives)}
193
+ </CapButton>
194
+ </CapTooltip>
195
+ ) : (
196
+ <CapButton type="secondary" onClick={handleOpen} disabled={disabled}>
197
+ {formatMessage(messages.addCreatives)}
198
+ </CapButton>
199
+ )}
188
200
  </CapColumn>
189
201
  </CapRow>
190
202
  </CapCard>
@@ -227,6 +239,8 @@ CommunicationFlowCard.propTypes = {
227
239
  onChange: PropTypes.func,
228
240
  cap: PropTypes.object,
229
241
  intl: PropTypes.object.isRequired,
242
+ disabled: PropTypes.bool, // Disables the "Add creatives" trigger (e.g. until a consumer-required field is filled)
243
+ disabledTooltip: PropTypes.node, // Shown on hover when disabled is true
230
244
  };
231
245
 
232
246
  CommunicationFlowCard.defaultProps = {
@@ -235,6 +249,8 @@ CommunicationFlowCard.defaultProps = {
235
249
  onCancel: null,
236
250
  onChange: null,
237
251
  cap: null,
252
+ disabled: false,
253
+ disabledTooltip: null,
238
254
  };
239
255
 
240
256
  export default injectIntl(CommunicationFlowCard);
@@ -1,8 +1,7 @@
1
1
  import React from 'react';
2
2
 
3
3
  jest.mock('../../../services/api', () => ({
4
- createCentralCommsMetaId: jest.fn(),
5
- getCentralCommsMetaIds: jest.fn(),
4
+ createCommDefinition: jest.fn(),
6
5
  }));
7
6
 
8
7
  jest.mock('../../CreativesContainer', () => function MockCreativesContainer({
@@ -38,7 +37,7 @@ import { IntlProvider } from 'react-intl';
38
37
  import history from '../../../utils/history';
39
38
  import { initialReducer } from '../../../initialReducer';
40
39
  import CommunicationFlow from '../CommunicationFlow';
41
- import { createCentralCommsMetaId, getCentralCommsMetaIds } from '../../../services/api';
40
+ import { createCommDefinition } from '../../../services/api';
42
41
  import { getEnabledSteps } from '../utils/getEnabledSteps';
43
42
  import {
44
43
  CHANNELS,
@@ -359,74 +358,93 @@ describe('isSaveDisabled', () => {
359
358
  });
360
359
 
361
360
  describe('handleSave — CCS flow', () => {
361
+ const ccsConfig = { ...baseConfig, context: { name: 'Order Placed Notification' }, features: {} };
362
+
362
363
  beforeEach(() => {
363
- createCentralCommsMetaId.mockResolvedValue({ response: { data: { id: 'meta-123' } } });
364
- getCentralCommsMetaIds.mockResolvedValue({ response: { data: {} } });
364
+ createCommDefinition.mockResolvedValue({
365
+ response: { data: { id: 'cd_123', referenceId: 'ORDER_PLACED_123', status: 'DRAFT', version: { version: 1 } } },
366
+ });
365
367
  });
366
368
 
367
369
  afterEach(() => {
368
370
  jest.clearAllMocks();
369
371
  });
370
372
 
371
- it('calls createCentralCommsMetaId for each content item when useCCS is not false', async () => {
373
+ it('calls createCommDefinition with a SINGLE-strategy payload when useCCS is not false', async () => {
372
374
  const onSave = jest.fn();
373
375
  renderWithFlow({
374
376
  features: {},
377
+ config: ccsConfig,
375
378
  initialData: {
376
- contentItems: [{ channel: 'sms', templateData: { smsBody: 'Hello' } }],
379
+ contentItems: [{ channel: 'sms', templateData: { message: 'Hello' } }],
377
380
  },
378
381
  onSave,
379
382
  });
380
383
 
381
384
  await userEvent.click(screen.getByRole('button', { name: /^save$/i }));
382
385
 
383
- await waitFor(() => expect(createCentralCommsMetaId).toHaveBeenCalledTimes(1));
384
- expect(createCentralCommsMetaId).toHaveBeenCalledWith(
386
+ await waitFor(() => expect(createCommDefinition).toHaveBeenCalledTimes(1));
387
+ expect(createCommDefinition).toHaveBeenCalledWith(
385
388
  expect.objectContaining({
386
- centralCommsPayload: expect.objectContaining({ channel: 'SMS', module: 'CAMPAIGNS' }),
389
+ name: 'Order Placed Notification',
390
+ strategyType: 'SINGLE',
391
+ singleChannelStrategy: expect.objectContaining({
392
+ channel: 'SMS',
393
+ smsMessageContent: { message: 'Hello' },
394
+ }),
387
395
  }),
388
396
  );
389
397
  expect(onSave).toHaveBeenCalledTimes(1);
390
398
  });
391
399
 
392
- it('calls getCentralCommsMetaIds when metaIds are returned from createCentralCommsMetaId', async () => {
400
+ it('merges ccsCommDefinition into the data passed to onSave when create succeeds', async () => {
401
+ const onSave = jest.fn();
393
402
  renderWithFlow({
394
403
  features: {},
395
- initialData: { contentItems: [{ channel: 'EMAIL', templateData: {} }] },
404
+ config: ccsConfig,
405
+ initialData: { contentItems: [{ channel: 'SMS', templateData: {} }] },
406
+ onSave,
396
407
  });
397
408
 
398
409
  await userEvent.click(screen.getByRole('button', { name: /^save$/i }));
399
410
 
400
- await waitFor(() => expect(getCentralCommsMetaIds).toHaveBeenCalledWith('meta-123'));
411
+ await waitFor(() => expect(onSave).toHaveBeenCalledTimes(1));
412
+ expect(onSave).toHaveBeenCalledWith(
413
+ expect.objectContaining({
414
+ ccsCommDefinition: { id: 'cd_123', referenceId: 'ORDER_PLACED_123', version: 1, status: 'DRAFT' },
415
+ }),
416
+ );
401
417
  });
402
418
 
403
- it('skips getCentralCommsMetaIds when response contains no id', async () => {
404
- createCentralCommsMetaId.mockResolvedValue({ response: { data: {} } });
419
+ it('generates a referenceId from name when config.context.referenceId is absent', async () => {
420
+ // moduleMocks.js spies on Date.now globally, but this config's resetMocks:true
421
+ // clears that return value before every test — set it explicitly here.
422
+ jest.spyOn(Date, 'now').mockReturnValue(1612267539410);
405
423
  renderWithFlow({
406
424
  features: {},
425
+ config: ccsConfig,
407
426
  initialData: { contentItems: [{ channel: 'SMS', templateData: {} }] },
408
427
  });
409
428
 
410
429
  await userEvent.click(screen.getByRole('button', { name: /^save$/i }));
411
430
 
412
- await waitFor(() => expect(createCentralCommsMetaId).toHaveBeenCalled());
413
- expect(getCentralCommsMetaIds).not.toHaveBeenCalled();
431
+ await waitFor(() => expect(createCommDefinition).toHaveBeenCalled());
432
+ const payload = createCommDefinition.mock.calls[0][0];
433
+ expect(payload.referenceId).toBe('ORDER_PLACED_NOTIFICATION_1612267539410');
414
434
  });
415
435
 
416
- it('uses ouId and module from config.context when provided', async () => {
436
+ it('uses config.context.referenceId and description when provided', async () => {
417
437
  renderWithFlow({
418
438
  features: {},
419
- config: { ...baseConfig, context: { ouId: 42, module: 'LOYALTY' }, features: {} },
439
+ config: { ...ccsConfig, context: { ...ccsConfig.context, referenceId: 'ORDER_PLACED', description: 'desc' } },
420
440
  initialData: { contentItems: [{ channel: 'SMS', templateData: {} }] },
421
441
  });
422
442
 
423
443
  await userEvent.click(screen.getByRole('button', { name: /^save$/i }));
424
444
 
425
- await waitFor(() => expect(createCentralCommsMetaId).toHaveBeenCalled());
426
- expect(createCentralCommsMetaId).toHaveBeenCalledWith(
427
- expect.objectContaining({
428
- centralCommsPayload: expect.objectContaining({ ouId: 42, module: 'LOYALTY' }),
429
- }),
445
+ await waitFor(() => expect(createCommDefinition).toHaveBeenCalled());
446
+ expect(createCommDefinition).toHaveBeenCalledWith(
447
+ expect.objectContaining({ referenceId: 'ORDER_PLACED', description: 'desc' }),
430
448
  );
431
449
  });
432
450
 
@@ -434,7 +452,7 @@ describe('handleSave — CCS flow', () => {
434
452
  const onSave = jest.fn();
435
453
  renderWithFlow({
436
454
  features: {},
437
- config: { ...baseConfig, useCCS: false, features: {} },
455
+ config: { ...ccsConfig, useCCS: false },
438
456
  initialData: { contentItems: [{ channel: 'SMS', templateData: {} }] },
439
457
  onSave,
440
458
  });
@@ -442,14 +460,50 @@ describe('handleSave — CCS flow', () => {
442
460
  await userEvent.click(screen.getByRole('button', { name: /^save$/i }));
443
461
 
444
462
  await waitFor(() => expect(onSave).toHaveBeenCalledTimes(1));
445
- expect(createCentralCommsMetaId).not.toHaveBeenCalled();
463
+ expect(createCommDefinition).not.toHaveBeenCalled();
464
+ expect(onSave).toHaveBeenCalledWith(expect.not.objectContaining({ ccsCommDefinition: expect.anything() }));
465
+ });
466
+
467
+ it('skips createCommDefinition when config.context.name is absent (mandatory)', async () => {
468
+ const onSave = jest.fn();
469
+ renderWithFlow({
470
+ features: {},
471
+ config: { ...baseConfig, features: {} },
472
+ initialData: { contentItems: [{ channel: 'SMS', templateData: {} }] },
473
+ onSave,
474
+ });
475
+
476
+ await userEvent.click(screen.getByRole('button', { name: /^save$/i }));
477
+
478
+ await waitFor(() => expect(onSave).toHaveBeenCalledTimes(1));
479
+ expect(createCommDefinition).not.toHaveBeenCalled();
480
+ });
481
+
482
+ it('skips createCommDefinition for multi-channel strategies (CHANNEL_PRIORITY/AB_TEST)', async () => {
483
+ const onSave = jest.fn();
484
+ renderWithFlow({
485
+ features: {},
486
+ config: ccsConfig,
487
+ initialData: {
488
+ communicationStrategy: CHANNEL_PRIORITY,
489
+ channels: ['SMS', 'EMAIL'],
490
+ contentItems: [{ channel: 'SMS', templateData: {} }, { channel: 'EMAIL', templateData: {} }],
491
+ },
492
+ onSave,
493
+ });
494
+
495
+ await userEvent.click(screen.getByRole('button', { name: /^save$/i }));
496
+
497
+ await waitFor(() => expect(onSave).toHaveBeenCalledTimes(1));
498
+ expect(createCommDefinition).not.toHaveBeenCalled();
446
499
  });
447
500
 
448
- it('still calls onSave when createCentralCommsMetaId rejects', async () => {
449
- createCentralCommsMetaId.mockRejectedValue(new Error('Network error'));
501
+ it('still calls onSave (without ccsCommDefinition) when createCommDefinition rejects', async () => {
502
+ createCommDefinition.mockRejectedValue(new Error('Network error'));
450
503
  const onSave = jest.fn();
451
504
  renderWithFlow({
452
505
  features: {},
506
+ config: ccsConfig,
453
507
  initialData: { contentItems: [{ channel: 'SMS', templateData: {} }] },
454
508
  onSave,
455
509
  });
@@ -457,12 +511,35 @@ describe('handleSave — CCS flow', () => {
457
511
  await userEvent.click(screen.getByRole('button', { name: /^save$/i }));
458
512
 
459
513
  await waitFor(() => expect(onSave).toHaveBeenCalledTimes(1));
514
+ expect(onSave).toHaveBeenCalledWith(expect.not.objectContaining({ ccsCommDefinition: expect.anything() }));
460
515
  });
461
516
 
462
- it('skips createCentralCommsMetaId when contentItems is empty', async () => {
517
+ it('blocks save and shows an error when createCommDefinition resolves with a duplicate REFERENCE_ID_EXISTS conflict', async () => {
518
+ createCommDefinition.mockResolvedValue({
519
+ success: false,
520
+ status: { isError: true, code: 409, message: 'REFERENCE_ID_EXISTS' },
521
+ message: 'REFERENCE_ID_EXISTS',
522
+ });
463
523
  const onSave = jest.fn();
464
524
  renderWithFlow({
465
525
  features: {},
526
+ config: ccsConfig,
527
+ initialData: { contentItems: [{ channel: 'SMS', templateData: {} }] },
528
+ onSave,
529
+ });
530
+
531
+ await userEvent.click(screen.getByRole('button', { name: /^save$/i }));
532
+
533
+ await waitFor(() => expect(createCommDefinition).toHaveBeenCalledTimes(1));
534
+ expect(await screen.findByText(/already in use in your organization/i)).toBeInTheDocument();
535
+ expect(onSave).not.toHaveBeenCalled();
536
+ });
537
+
538
+ it('skips createCommDefinition when contentItems is empty', async () => {
539
+ const onSave = jest.fn();
540
+ renderWithFlow({
541
+ features: {},
542
+ config: ccsConfig,
466
543
  initialData: { contentItems: [] },
467
544
  onSave,
468
545
  });
@@ -470,12 +547,13 @@ describe('handleSave — CCS flow', () => {
470
547
  await userEvent.click(screen.getByRole('button', { name: /^save$/i }));
471
548
 
472
549
  await waitFor(() => expect(onSave).toHaveBeenCalledTimes(1));
473
- expect(createCentralCommsMetaId).not.toHaveBeenCalled();
550
+ expect(createCommDefinition).not.toHaveBeenCalled();
474
551
  });
475
552
 
476
- it('includes additionalSettings derived from dynamicControls in the payload', async () => {
553
+ it('places additionalSettings derived from dynamicControls under settings.additionalSettings (not delivery settings)', async () => {
477
554
  renderWithFlow({
478
555
  features: {},
556
+ config: ccsConfig,
479
557
  initialData: {
480
558
  contentItems: [{ channel: 'SMS', templateData: {} }],
481
559
  dynamicControls: {
@@ -489,14 +567,36 @@ describe('handleSave — CCS flow', () => {
489
567
 
490
568
  await userEvent.click(screen.getByRole('button', { name: /^save$/i }));
491
569
 
492
- await waitFor(() => expect(createCentralCommsMetaId).toHaveBeenCalled());
493
- const payload = createCentralCommsMetaId.mock.calls[0][0];
494
- expect(payload.centralCommsPayload.smsDeliverySettings.additionalSettings).toEqual({
570
+ await waitFor(() => expect(createCommDefinition).toHaveBeenCalled());
571
+ const payload = createCommDefinition.mock.calls[0][0];
572
+ expect(payload.settings.additionalSettings).toEqual({
495
573
  useTinyUrl: true,
496
574
  encryptUrl: true,
497
575
  linkTrackingEnabled: true,
498
576
  userSubscriptionDisabled: true,
499
577
  });
578
+ expect(payload.singleChannelStrategy.smsDeliverySettings.additionalSettings).toBeUndefined();
579
+ });
580
+
581
+ it('includes channelSettings from deliverySetting.channelSetting in the payload', async () => {
582
+ renderWithFlow({
583
+ features: {},
584
+ config: ccsConfig,
585
+ initialData: {
586
+ contentItems: [{ channel: 'SMS', templateData: {} }],
587
+ deliverySetting: { channelSetting: { SMS: { domainId: 1001, gsmSenderId: 'BRAND1' } } },
588
+ },
589
+ });
590
+
591
+ await userEvent.click(screen.getByRole('button', { name: /^save$/i }));
592
+
593
+ await waitFor(() => expect(createCommDefinition).toHaveBeenCalled());
594
+ const payload = createCommDefinition.mock.calls[0][0];
595
+ expect(payload.singleChannelStrategy.smsDeliverySettings.channelSettings).toEqual({
596
+ channel: 'SMS',
597
+ domainId: 1001,
598
+ gsmSenderId: 'BRAND1',
599
+ });
500
600
  });
501
601
  });
502
602
 
@@ -552,39 +652,34 @@ describe('optional chaining safety', () => {
552
652
  jest.clearAllMocks();
553
653
  });
554
654
 
555
- it('defaults ouId to -1 when config.context is absent', async () => {
556
- createCentralCommsMetaId.mockResolvedValue({ response: { data: { id: 'x' } } });
655
+ it('does not crash and skips CCS when config.context is entirely absent', async () => {
656
+ const onSave = jest.fn();
557
657
  renderWithFlow({
558
658
  features: {},
659
+ config: { ...baseConfig, features: {} },
559
660
  initialData: { contentItems: [{ channel: 'SMS', templateData: {} }] },
661
+ onSave,
560
662
  });
561
663
 
562
664
  await userEvent.click(screen.getByRole('button', { name: /^save$/i }));
563
665
 
564
- await waitFor(() => expect(createCentralCommsMetaId).toHaveBeenCalled());
565
- expect(createCentralCommsMetaId).toHaveBeenCalledWith(
566
- expect.objectContaining({
567
- centralCommsPayload: expect.objectContaining({ ouId: -1 }),
568
- }),
569
- );
666
+ await waitFor(() => expect(onSave).toHaveBeenCalledTimes(1));
667
+ expect(createCommDefinition).not.toHaveBeenCalled();
570
668
  });
571
669
 
572
- it('defaults module to consumer.toUpperCase() when config.context.module absent', async () => {
573
- createCentralCommsMetaId.mockResolvedValue({ response: { data: { id: 'x' } } });
670
+ it('does not crash when config.context is present but empty', async () => {
671
+ const onSave = jest.fn();
574
672
  renderWithFlow({
575
673
  features: {},
576
- config: { ...baseConfig, consumer: 'loyalty', features: {} },
674
+ config: { ...baseConfig, context: {}, features: {} },
577
675
  initialData: { contentItems: [{ channel: 'SMS', templateData: {} }] },
676
+ onSave,
578
677
  });
579
678
 
580
679
  await userEvent.click(screen.getByRole('button', { name: /^save$/i }));
581
680
 
582
- await waitFor(() => expect(createCentralCommsMetaId).toHaveBeenCalled());
583
- expect(createCentralCommsMetaId).toHaveBeenCalledWith(
584
- expect.objectContaining({
585
- centralCommsPayload: expect.objectContaining({ module: 'LOYALTY' }),
586
- }),
587
- );
681
+ await waitFor(() => expect(onSave).toHaveBeenCalledTimes(1));
682
+ expect(createCommDefinition).not.toHaveBeenCalled();
588
683
  });
589
684
 
590
685
  it('initializes channel from config.channel when initialData.channel is absent', () => {
@@ -108,6 +108,22 @@ describe('CommunicationFlowCard', () => {
108
108
  fireEvent.click(screen.getByText('Add creatives'));
109
109
  expect(screen.getByTestId('comm-flow-mock')).toHaveAttribute('data-mode', 'create');
110
110
  });
111
+
112
+ it('disables the Add creatives button when disabled prop is true', () => {
113
+ renderCard({ disabled: true, disabledTooltip: 'Enter an Alert name to add content' });
114
+ expect(screen.getByText('Add creatives').closest('button')).toBeDisabled();
115
+ });
116
+
117
+ it('does not open SlideBox when Add creatives is clicked while disabled', () => {
118
+ renderCard({ disabled: true, disabledTooltip: 'Enter an Alert name to add content' });
119
+ fireEvent.click(screen.getByText('Add creatives'));
120
+ expect(screen.queryByTestId('slide-box')).not.toBeInTheDocument();
121
+ });
122
+
123
+ it('Add creatives button is enabled by default (disabled prop absent)', () => {
124
+ renderCard();
125
+ expect(screen.getByText('Add creatives').closest('button')).not.toBeDisabled();
126
+ });
111
127
  });
112
128
 
113
129
  describe('configured state (initialData provided)', () => {
@@ -38,6 +38,46 @@ export const CHANNEL_PRIORITY = 'CHANNEL_PRIORITY';
38
38
  export const AB_TEST = 'AB_TEST';
39
39
  export const SINGLE_TEMPLATE = 'SINGLE_TEMPLATE';
40
40
 
41
+ // CCS CommDefinition strategyType — distinct from SINGLE_TEMPLATE above, which
42
+ // is this UI's own communicationStrategy value. Only SINGLE is supported this
43
+ // phase; CCS create is skipped entirely for CHANNEL_PRIORITY/AB_TEST.
44
+ export const CCS_STRATEGY_TYPE_SINGLE = 'SINGLE';
45
+
46
+ // Mirrors CCS's SingleChannelStrategy field names exactly (Cap Notify API
47
+ // Design doc, "Channel Strategy overview" / class dump). Kept separate from
48
+ // CHANNEL_CONTENT_KEY_MAP/CHANNEL_DELIVERY_KEY_MAP below, which are the legacy
49
+ // messageMeta payload's keys and do not match CCS naming for every channel
50
+ // (e.g. legacy uses lowercase 'mpushMessageContent'; CCS uses 'mPushMessageContent').
51
+ export const CCS_CHANNEL_CONTENT_KEY_MAP = {
52
+ SMS: 'smsMessageContent',
53
+ EMAIL: 'emailMessageContent',
54
+ WHATSAPP: 'whatsappMessageContent',
55
+ MPUSH: 'mPushMessageContent',
56
+ INAPP: 'inAppMessageContent',
57
+ ANDROID: 'androidMessageContent',
58
+ IOS: 'iosMessageContent',
59
+ ZALO: 'zaloMessageContent',
60
+ VIBER: 'viberMessageContent',
61
+ LINE: 'lineMessageContent',
62
+ WEBPUSH: 'webPushMessageContent',
63
+ RCS: 'rcsMessageContent',
64
+ };
65
+
66
+ export const CCS_CHANNEL_DELIVERY_KEY_MAP = {
67
+ SMS: 'smsDeliverySettings',
68
+ EMAIL: 'emailDeliverySettings',
69
+ WHATSAPP: 'whatsappDeliverySettings',
70
+ MPUSH: 'mPushDeliverySettings',
71
+ INAPP: 'inAppDeliverySettings',
72
+ ANDROID: 'androidDeliverySettings',
73
+ IOS: 'iosDeliverySettings',
74
+ ZALO: 'zaloDeliverySettings',
75
+ VIBER: 'viberDeliverySettings',
76
+ LINE: 'lineDeliverySettings',
77
+ WEBPUSH: 'webPushDeliverySettings',
78
+ RCS: 'rcsDeliverySettings',
79
+ };
80
+
41
81
  // Channel config - single source of truth for CreativesContainer and TemplatesV2
42
82
  // paneKey: TemplatesV2 defaultPanes object key (for channelsToHide)
43
83
  // channelProp: CreativesContainer channel prop (must match pane.key for tab to be active)
@@ -9,7 +9,6 @@
9
9
  import React from 'react';
10
10
  import PropTypes from 'prop-types';
11
11
  import CommunicationFlow from './CommunicationFlow';
12
- import { hasSupportEngagementModule } from '../../utils/common';
13
12
 
14
13
  const CommunicationFlowContainer = ({
15
14
  config,
@@ -18,22 +17,16 @@ const CommunicationFlowContainer = ({
18
17
  onCancel,
19
18
  onChange,
20
19
  ...otherProps
21
- }) => {
22
- if (!hasSupportEngagementModule()) {
23
- return null;
24
- }
25
-
26
- return (
27
- <CommunicationFlow
28
- config={config}
29
- initialData={initialData}
30
- onSave={onSave}
31
- onCancel={onCancel}
32
- onChange={onChange}
33
- {...otherProps}
34
- />
35
- );
36
- };
20
+ }) => (
21
+ <CommunicationFlow
22
+ config={config}
23
+ initialData={initialData}
24
+ onSave={onSave}
25
+ onCancel={onCancel}
26
+ onChange={onChange}
27
+ {...otherProps}
28
+ />
29
+ );
37
30
 
38
31
  CommunicationFlowContainer.propTypes = {
39
32
  config: PropTypes.shape({
@@ -87,11 +80,13 @@ CommunicationFlowContainer.propTypes = {
87
80
  controls: PropTypes.array,
88
81
  }),
89
82
  }),
90
- context: PropTypes.object, // ouId, campaignId, programId, etc.
91
- useCCS: PropTypes.bool, // If false, skips CCS bulk-claim-approve on save. Defaults to true.
83
+ context: PropTypes.object, // ouId, campaignId, programId; name (required for CCS create),
84
+ // referenceId (optional, auto-generated from name if absent), description (optional).
85
+ useCCS: PropTypes.bool, // If false, skips the CCS createCommDefinition call on save. Defaults to true.
92
86
  }).isRequired,
93
87
  initialData: PropTypes.object, // for edit/preview mode
94
- onSave: PropTypes.func.isRequired, // (data) => void - called when user saves
88
+ onSave: PropTypes.func.isRequired, // (data) => void - called when user saves; data.ccsCommDefinition
89
+ // ({id, referenceId, version, status}) is present when the CCS create succeeded
95
90
  onCancel: PropTypes.func.isRequired, // () => void - called when user cancels
96
91
  onChange: PropTypes.func, // (data) => void - optional, called on data changes
97
92
  };
@@ -363,4 +363,8 @@ export default {
363
363
  id: `${prefix}.senderNotConfiguredError`,
364
364
  defaultMessage: 'Selected domain gateway id is not correct. Please change the domain id or contact the gateway team to register them with Capillary.',
365
365
  },
366
+ duplicateReferenceIdError: {
367
+ id: `${prefix}.duplicateReferenceIdError`,
368
+ defaultMessage: 'This reference ID is already in use in your organization. Please use a different reference ID.',
369
+ },
366
370
  };