@capillarytech/creatives-library 9.0.53 → 9.0.54-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.53",
4
+ "version": "9.0.54-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,10 @@ 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,
42
+ CCS_CHANNEL_NAME_MAP,
41
43
  } from './constants';
42
44
  import { getEnabledSteps } from './utils/getEnabledSteps';
43
45
  import messages from './messages';
@@ -64,6 +66,25 @@ const hasDeliverySettingForChannel = (channelSetting, channel) => {
64
66
  return !!settings && Object.values(settings).some((v) => v !== null && v !== '' && v !== undefined);
65
67
  };
66
68
 
69
+ // createCommDefinition resolves (rather than rejects) with the CCS error envelope
70
+ // for 4xx/5xx responses — see api.js's request()/checkStatus. A duplicate
71
+ // referenceId within the org comes back as this specific 409.
72
+ const isDuplicateReferenceIdError = (res) => res?.success === false && res?.status?.message === 'REFERENCE_ID_EXISTS';
73
+
74
+ /**
75
+ * CCS requires referenceId on create; the consumer-supplied Alert/comm name is
76
+ * mandatory but referenceId is optional in every consumer's own form. Generate
77
+ * a stable fallback from the name rather than failing the save.
78
+ */
79
+ const buildCcsReferenceId = (name) => {
80
+ const slug = (name || 'COMM')
81
+ .trim()
82
+ .toUpperCase()
83
+ .replace(/[^A-Z0-9]+/g, '_')
84
+ .replace(/^_+|_+$/g, '') || 'COMM';
85
+ return `${slug}_${Date.now()}`;
86
+ };
87
+
67
88
  const CommunicationFlow = ({
68
89
  config,
69
90
  initialData,
@@ -91,6 +112,7 @@ const CommunicationFlow = ({
91
112
  };
92
113
  });
93
114
  const [validationErrors, setValidationErrors] = useState({});
115
+ const [saveError, setSaveError] = useState(null);
94
116
 
95
117
  // Memoize enabled steps
96
118
  const enabledSteps = useMemo(() => getEnabledSteps(config), [config]);
@@ -150,74 +172,82 @@ const CommunicationFlow = ({
150
172
  }, []);
151
173
 
152
174
  const handleSave = useCallback(async () => {
175
+ setSaveError(null);
153
176
  const aggregatedData = getAggregatedData();
154
177
  const shouldUseCCS = config?.useCCS !== false;
178
+ let ccsCommDefinition = null;
155
179
 
156
180
  if (shouldUseCCS) {
157
- const ouId = config?.context?.ouId || -1;
158
- const module = config?.context?.module
159
- || (config?.consumer ? config.consumer.toUpperCase() : CAMPAIGNS);
181
+ const isMultiChannel = [CHANNEL_PRIORITY, AB_TEST].includes(aggregatedData.communicationStrategy);
182
+ const contentItem = (aggregatedData.contentItems || [])[0];
183
+ // Consumer-supplied name (e.g. CapNotify's Alert Name field) — CommunicationFlow
184
+ // has no name input of its own, so this is mandatory input from config.context.
185
+ const name = config?.context?.name;
160
186
 
161
- const channelContentKeyMap = CHANNEL_CONTENT_KEY_MAP;
162
- const channelDeliveryKeyMap = CHANNEL_DELIVERY_KEY_MAP;
187
+ // CCS create is SINGLE-strategy only this phase (D1); CHANNEL_PRIORITY/AB_TEST
188
+ // carry multiple content items with no CCS equivalent yet.
189
+ if (!isMultiChannel && contentItem && name) {
190
+ const rawChannel = (contentItem.channel || '').toUpperCase();
191
+ const channel = CCS_CHANNEL_NAME_MAP[rawChannel] || rawChannel;
192
+ const contentKey = CCS_CHANNEL_CONTENT_KEY_MAP[channel];
193
+ const deliveryKey = CCS_CHANNEL_DELIVERY_KEY_MAP[channel];
194
+ const { dynamicControls = {} } = aggregatedData;
195
+ const channelSettings = aggregatedData.deliverySetting?.channelSetting?.[channel] || {};
196
+ const referenceId = config?.context?.referenceId || buildCcsReferenceId(name);
163
197
 
164
- const contentItems = aggregatedData.contentItems || [];
165
- const { dynamicControls = {} } = aggregatedData;
198
+ const payload = {
199
+ referenceId,
200
+ name,
201
+ description: config?.context?.description || undefined,
202
+ strategyType: CCS_STRATEGY_TYPE_SINGLE,
203
+ settings: {
204
+ additionalSettings: {
205
+ useTinyUrl: dynamicControls.useTinyUrl ?? false,
206
+ encryptUrl: dynamicControls.sendToControlCustomers ?? false,
207
+ linkTrackingEnabled: dynamicControls.overrideDailyLimit ?? false,
208
+ userSubscriptionDisabled: dynamicControls.sendToBrandPocs ?? false,
209
+ },
210
+ executionParams: {},
211
+ },
212
+ singleChannelStrategy: {
213
+ variant: {
214
+ channel,
215
+ ...(contentKey && { [contentKey]: contentItem.templateData }),
216
+ ...(deliveryKey && { [deliveryKey]: { channelSettings: { channel, ...channelSettings } } }),
217
+ },
218
+ },
219
+ };
166
220
 
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
221
  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);
222
+ const res = await createCommDefinition(payload);
223
+ if (isDuplicateReferenceIdError(res)) {
224
+ // Duplicate referenceId in this org — block the save so the user can
225
+ // change it, rather than silently proceeding without a CCS comm.
226
+ setSaveError(formatMessage(messages.duplicateReferenceIdError));
227
+ return;
228
+ }
229
+ const data = res?.response?.data;
230
+ if (data?.id) {
231
+ ccsCommDefinition = {
232
+ id: data.id,
233
+ referenceId: data.referenceId,
234
+ version: data.version?.version ?? 1,
235
+ status: data.status,
236
+ };
213
237
  }
214
238
  } catch (error) {
215
- console.error('[CommunicationFlow] CCS createCentralCommsMetaId error:', error);
239
+ console.error('[CommunicationFlow] CCS createCommDefinition error:', error);
216
240
  }
241
+ } else if (!name) {
242
+ console.warn('[CommunicationFlow] Skipping CCS createCommDefinition — config.context.name is required');
243
+ } else if (isMultiChannel) {
244
+ console.warn('[CommunicationFlow] Skipping CCS createCommDefinition — CHANNEL_PRIORITY/AB_TEST strategies are not supported by CCS create yet (SINGLE only)');
245
+ } else if (!contentItem) {
246
+ console.warn('[CommunicationFlow] Skipping CCS createCommDefinition — no content item found (contentItems is empty)');
217
247
  }
218
248
  }
219
249
 
220
- onSave(aggregatedData);
250
+ onSave(ccsCommDefinition ? { ...aggregatedData, ccsCommDefinition } : aggregatedData);
221
251
  }, [getAggregatedData, config, onSave]);
222
252
 
223
253
  // Call onChange callback when stepData changes
@@ -317,6 +347,11 @@ const CommunicationFlow = ({
317
347
  {renderSteps()}
318
348
  {onSave && (
319
349
  <CapRow useLegacy className="communication-flow-container__footer">
350
+ {saveError && (
351
+ <CapLabel type="label2" className="communication-flow-container__save-error">
352
+ {saveError}
353
+ </CapLabel>
354
+ )}
320
355
  <CapButton type="primary" onClick={handleSave} disabled={isSaveDisabled}>
321
356
  {formatMessage(messages.save)}
322
357
  </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,82 +358,151 @@ 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
+ variant: expect.objectContaining({
393
+ channel: 'SMS',
394
+ smsMessageContent: { message: 'Hello' },
395
+ }),
396
+ }),
387
397
  }),
388
398
  );
389
399
  expect(onSave).toHaveBeenCalledTimes(1);
390
400
  });
391
401
 
392
- it('calls getCentralCommsMetaIds when metaIds are returned from createCentralCommsMetaId', async () => {
402
+ it('normalizes the internal MOBILEPUSH channel to CCS\'s MPUSH enum and key names', async () => {
403
+ const onSave = jest.fn();
393
404
  renderWithFlow({
394
405
  features: {},
395
- initialData: { contentItems: [{ channel: 'EMAIL', templateData: {} }] },
406
+ config: ccsConfig,
407
+ initialData: {
408
+ contentItems: [{ channel: 'MOBILEPUSH', templateData: { messageSubject: 'Hi' } }],
409
+ },
410
+ onSave,
396
411
  });
397
412
 
398
413
  await userEvent.click(screen.getByRole('button', { name: /^save$/i }));
399
414
 
400
- await waitFor(() => expect(getCentralCommsMetaIds).toHaveBeenCalledWith('meta-123'));
415
+ await waitFor(() => expect(createCommDefinition).toHaveBeenCalledTimes(1));
416
+ expect(createCommDefinition).toHaveBeenCalledWith(
417
+ expect.objectContaining({
418
+ singleChannelStrategy: expect.objectContaining({
419
+ variant: expect.objectContaining({
420
+ channel: 'MPUSH',
421
+ mpushMessageContent: { messageSubject: 'Hi' },
422
+ }),
423
+ }),
424
+ }),
425
+ );
401
426
  });
402
427
 
403
- it('skips getCentralCommsMetaIds when response contains no id', async () => {
404
- createCentralCommsMetaId.mockResolvedValue({ response: { data: {} } });
428
+ it('merges ccsCommDefinition into the data passed to onSave when create succeeds', async () => {
429
+ const onSave = jest.fn();
405
430
  renderWithFlow({
406
431
  features: {},
432
+ config: ccsConfig,
407
433
  initialData: { contentItems: [{ channel: 'SMS', templateData: {} }] },
434
+ onSave,
408
435
  });
409
436
 
410
437
  await userEvent.click(screen.getByRole('button', { name: /^save$/i }));
411
438
 
412
- await waitFor(() => expect(createCentralCommsMetaId).toHaveBeenCalled());
413
- expect(getCentralCommsMetaIds).not.toHaveBeenCalled();
439
+ await waitFor(() => expect(onSave).toHaveBeenCalledTimes(1));
440
+ expect(onSave).toHaveBeenCalledWith(
441
+ expect.objectContaining({
442
+ ccsCommDefinition: { id: 'cd_123', referenceId: 'ORDER_PLACED_123', version: 1, status: 'DRAFT' },
443
+ }),
444
+ );
414
445
  });
415
446
 
416
- it('uses ouId and module from config.context when provided', async () => {
447
+ it('preserves a real version of 0 from CCS (not coerced to 1 by a falsy-zero fallback)', async () => {
448
+ const onSave = jest.fn();
449
+ createCommDefinition.mockResolvedValueOnce({
450
+ response: { data: { id: 'cd_123', referenceId: 'ORDER_PLACED_123', status: 'DRAFT', version: { version: 0 } } },
451
+ });
417
452
  renderWithFlow({
418
453
  features: {},
419
- config: { ...baseConfig, context: { ouId: 42, module: 'LOYALTY' }, features: {} },
454
+ config: ccsConfig,
420
455
  initialData: { contentItems: [{ channel: 'SMS', templateData: {} }] },
456
+ onSave,
421
457
  });
422
458
 
423
459
  await userEvent.click(screen.getByRole('button', { name: /^save$/i }));
424
460
 
425
- await waitFor(() => expect(createCentralCommsMetaId).toHaveBeenCalled());
426
- expect(createCentralCommsMetaId).toHaveBeenCalledWith(
461
+ await waitFor(() => expect(onSave).toHaveBeenCalledTimes(1));
462
+ expect(onSave).toHaveBeenCalledWith(
427
463
  expect.objectContaining({
428
- centralCommsPayload: expect.objectContaining({ ouId: 42, module: 'LOYALTY' }),
464
+ ccsCommDefinition: { id: 'cd_123', referenceId: 'ORDER_PLACED_123', version: 0, status: 'DRAFT' },
429
465
  }),
430
466
  );
431
467
  });
432
468
 
469
+ it('generates a referenceId from name when config.context.referenceId is absent', async () => {
470
+ // moduleMocks.js spies on Date.now globally, but this config's resetMocks:true
471
+ // clears that return value before every test — set it explicitly here.
472
+ jest.spyOn(Date, 'now').mockReturnValue(1612267539410);
473
+ renderWithFlow({
474
+ features: {},
475
+ config: ccsConfig,
476
+ initialData: { contentItems: [{ channel: 'SMS', templateData: {} }] },
477
+ });
478
+
479
+ await userEvent.click(screen.getByRole('button', { name: /^save$/i }));
480
+
481
+ await waitFor(() => expect(createCommDefinition).toHaveBeenCalled());
482
+ const payload = createCommDefinition.mock.calls[0][0];
483
+ expect(payload.referenceId).toBe('ORDER_PLACED_NOTIFICATION_1612267539410');
484
+ });
485
+
486
+ it('uses config.context.referenceId and description when provided', async () => {
487
+ renderWithFlow({
488
+ features: {},
489
+ config: { ...ccsConfig, context: { ...ccsConfig.context, referenceId: 'ORDER_PLACED', description: 'desc' } },
490
+ initialData: { contentItems: [{ channel: 'SMS', templateData: {} }] },
491
+ });
492
+
493
+ await userEvent.click(screen.getByRole('button', { name: /^save$/i }));
494
+
495
+ await waitFor(() => expect(createCommDefinition).toHaveBeenCalled());
496
+ expect(createCommDefinition).toHaveBeenCalledWith(
497
+ expect.objectContaining({ referenceId: 'ORDER_PLACED', description: 'desc' }),
498
+ );
499
+ });
500
+
433
501
  it('skips CCS entirely when useCCS is false', async () => {
434
502
  const onSave = jest.fn();
435
503
  renderWithFlow({
436
504
  features: {},
437
- config: { ...baseConfig, useCCS: false, features: {} },
505
+ config: { ...ccsConfig, useCCS: false },
438
506
  initialData: { contentItems: [{ channel: 'SMS', templateData: {} }] },
439
507
  onSave,
440
508
  });
@@ -442,14 +510,15 @@ describe('handleSave — CCS flow', () => {
442
510
  await userEvent.click(screen.getByRole('button', { name: /^save$/i }));
443
511
 
444
512
  await waitFor(() => expect(onSave).toHaveBeenCalledTimes(1));
445
- expect(createCentralCommsMetaId).not.toHaveBeenCalled();
513
+ expect(createCommDefinition).not.toHaveBeenCalled();
514
+ expect(onSave).toHaveBeenCalledWith(expect.not.objectContaining({ ccsCommDefinition: expect.anything() }));
446
515
  });
447
516
 
448
- it('still calls onSave when createCentralCommsMetaId rejects', async () => {
449
- createCentralCommsMetaId.mockRejectedValue(new Error('Network error'));
517
+ it('skips createCommDefinition when config.context.name is absent (mandatory)', async () => {
450
518
  const onSave = jest.fn();
451
519
  renderWithFlow({
452
520
  features: {},
521
+ config: { ...baseConfig, features: {} },
453
522
  initialData: { contentItems: [{ channel: 'SMS', templateData: {} }] },
454
523
  onSave,
455
524
  });
@@ -457,12 +526,70 @@ describe('handleSave — CCS flow', () => {
457
526
  await userEvent.click(screen.getByRole('button', { name: /^save$/i }));
458
527
 
459
528
  await waitFor(() => expect(onSave).toHaveBeenCalledTimes(1));
529
+ expect(createCommDefinition).not.toHaveBeenCalled();
460
530
  });
461
531
 
462
- it('skips createCentralCommsMetaId when contentItems is empty', async () => {
532
+ it('skips createCommDefinition for multi-channel strategies (CHANNEL_PRIORITY/AB_TEST)', async () => {
463
533
  const onSave = jest.fn();
464
534
  renderWithFlow({
465
535
  features: {},
536
+ config: ccsConfig,
537
+ initialData: {
538
+ communicationStrategy: CHANNEL_PRIORITY,
539
+ channels: ['SMS', 'EMAIL'],
540
+ contentItems: [{ channel: 'SMS', templateData: {} }, { channel: 'EMAIL', templateData: {} }],
541
+ },
542
+ onSave,
543
+ });
544
+
545
+ await userEvent.click(screen.getByRole('button', { name: /^save$/i }));
546
+
547
+ await waitFor(() => expect(onSave).toHaveBeenCalledTimes(1));
548
+ expect(createCommDefinition).not.toHaveBeenCalled();
549
+ });
550
+
551
+ it('still calls onSave (without ccsCommDefinition) when createCommDefinition rejects', async () => {
552
+ createCommDefinition.mockRejectedValue(new Error('Network error'));
553
+ const onSave = jest.fn();
554
+ renderWithFlow({
555
+ features: {},
556
+ config: ccsConfig,
557
+ initialData: { contentItems: [{ channel: 'SMS', templateData: {} }] },
558
+ onSave,
559
+ });
560
+
561
+ await userEvent.click(screen.getByRole('button', { name: /^save$/i }));
562
+
563
+ await waitFor(() => expect(onSave).toHaveBeenCalledTimes(1));
564
+ expect(onSave).toHaveBeenCalledWith(expect.not.objectContaining({ ccsCommDefinition: expect.anything() }));
565
+ });
566
+
567
+ it('blocks save and shows an error when createCommDefinition resolves with a duplicate REFERENCE_ID_EXISTS conflict', async () => {
568
+ createCommDefinition.mockResolvedValue({
569
+ success: false,
570
+ status: { isError: true, code: 409, message: 'REFERENCE_ID_EXISTS' },
571
+ message: 'REFERENCE_ID_EXISTS',
572
+ });
573
+ const onSave = jest.fn();
574
+ renderWithFlow({
575
+ features: {},
576
+ config: ccsConfig,
577
+ initialData: { contentItems: [{ channel: 'SMS', templateData: {} }] },
578
+ onSave,
579
+ });
580
+
581
+ await userEvent.click(screen.getByRole('button', { name: /^save$/i }));
582
+
583
+ await waitFor(() => expect(createCommDefinition).toHaveBeenCalledTimes(1));
584
+ expect(await screen.findByText(/already in use in your organization/i)).toBeInTheDocument();
585
+ expect(onSave).not.toHaveBeenCalled();
586
+ });
587
+
588
+ it('skips createCommDefinition when contentItems is empty', async () => {
589
+ const onSave = jest.fn();
590
+ renderWithFlow({
591
+ features: {},
592
+ config: ccsConfig,
466
593
  initialData: { contentItems: [] },
467
594
  onSave,
468
595
  });
@@ -470,12 +597,13 @@ describe('handleSave — CCS flow', () => {
470
597
  await userEvent.click(screen.getByRole('button', { name: /^save$/i }));
471
598
 
472
599
  await waitFor(() => expect(onSave).toHaveBeenCalledTimes(1));
473
- expect(createCentralCommsMetaId).not.toHaveBeenCalled();
600
+ expect(createCommDefinition).not.toHaveBeenCalled();
474
601
  });
475
602
 
476
- it('includes additionalSettings derived from dynamicControls in the payload', async () => {
603
+ it('places additionalSettings derived from dynamicControls under settings.additionalSettings (not delivery settings)', async () => {
477
604
  renderWithFlow({
478
605
  features: {},
606
+ config: ccsConfig,
479
607
  initialData: {
480
608
  contentItems: [{ channel: 'SMS', templateData: {} }],
481
609
  dynamicControls: {
@@ -489,14 +617,36 @@ describe('handleSave — CCS flow', () => {
489
617
 
490
618
  await userEvent.click(screen.getByRole('button', { name: /^save$/i }));
491
619
 
492
- await waitFor(() => expect(createCentralCommsMetaId).toHaveBeenCalled());
493
- const payload = createCentralCommsMetaId.mock.calls[0][0];
494
- expect(payload.centralCommsPayload.smsDeliverySettings.additionalSettings).toEqual({
620
+ await waitFor(() => expect(createCommDefinition).toHaveBeenCalled());
621
+ const payload = createCommDefinition.mock.calls[0][0];
622
+ expect(payload.settings.additionalSettings).toEqual({
495
623
  useTinyUrl: true,
496
624
  encryptUrl: true,
497
625
  linkTrackingEnabled: true,
498
626
  userSubscriptionDisabled: true,
499
627
  });
628
+ expect(payload.singleChannelStrategy.variant.smsDeliverySettings.additionalSettings).toBeUndefined();
629
+ });
630
+
631
+ it('includes channelSettings from deliverySetting.channelSetting in the payload', async () => {
632
+ renderWithFlow({
633
+ features: {},
634
+ config: ccsConfig,
635
+ initialData: {
636
+ contentItems: [{ channel: 'SMS', templateData: {} }],
637
+ deliverySetting: { channelSetting: { SMS: { domainId: 1001, gsmSenderId: 'BRAND1' } } },
638
+ },
639
+ });
640
+
641
+ await userEvent.click(screen.getByRole('button', { name: /^save$/i }));
642
+
643
+ await waitFor(() => expect(createCommDefinition).toHaveBeenCalled());
644
+ const payload = createCommDefinition.mock.calls[0][0];
645
+ expect(payload.singleChannelStrategy.variant.smsDeliverySettings.channelSettings).toEqual({
646
+ channel: 'SMS',
647
+ domainId: 1001,
648
+ gsmSenderId: 'BRAND1',
649
+ });
500
650
  });
501
651
  });
502
652
 
@@ -552,39 +702,34 @@ describe('optional chaining safety', () => {
552
702
  jest.clearAllMocks();
553
703
  });
554
704
 
555
- it('defaults ouId to -1 when config.context is absent', async () => {
556
- createCentralCommsMetaId.mockResolvedValue({ response: { data: { id: 'x' } } });
705
+ it('does not crash and skips CCS when config.context is entirely absent', async () => {
706
+ const onSave = jest.fn();
557
707
  renderWithFlow({
558
708
  features: {},
709
+ config: { ...baseConfig, features: {} },
559
710
  initialData: { contentItems: [{ channel: 'SMS', templateData: {} }] },
711
+ onSave,
560
712
  });
561
713
 
562
714
  await userEvent.click(screen.getByRole('button', { name: /^save$/i }));
563
715
 
564
- await waitFor(() => expect(createCentralCommsMetaId).toHaveBeenCalled());
565
- expect(createCentralCommsMetaId).toHaveBeenCalledWith(
566
- expect.objectContaining({
567
- centralCommsPayload: expect.objectContaining({ ouId: -1 }),
568
- }),
569
- );
716
+ await waitFor(() => expect(onSave).toHaveBeenCalledTimes(1));
717
+ expect(createCommDefinition).not.toHaveBeenCalled();
570
718
  });
571
719
 
572
- it('defaults module to consumer.toUpperCase() when config.context.module absent', async () => {
573
- createCentralCommsMetaId.mockResolvedValue({ response: { data: { id: 'x' } } });
720
+ it('does not crash when config.context is present but empty', async () => {
721
+ const onSave = jest.fn();
574
722
  renderWithFlow({
575
723
  features: {},
576
- config: { ...baseConfig, consumer: 'loyalty', features: {} },
724
+ config: { ...baseConfig, context: {}, features: {} },
577
725
  initialData: { contentItems: [{ channel: 'SMS', templateData: {} }] },
726
+ onSave,
578
727
  });
579
728
 
580
729
  await userEvent.click(screen.getByRole('button', { name: /^save$/i }));
581
730
 
582
- await waitFor(() => expect(createCentralCommsMetaId).toHaveBeenCalled());
583
- expect(createCentralCommsMetaId).toHaveBeenCalledWith(
584
- expect.objectContaining({
585
- centralCommsPayload: expect.objectContaining({ module: 'LOYALTY' }),
586
- }),
587
- );
731
+ await waitFor(() => expect(onSave).toHaveBeenCalledTimes(1));
732
+ expect(createCommDefinition).not.toHaveBeenCalled();
588
733
  });
589
734
 
590
735
  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,53 @@ 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 sample payloads, verified against real create responses). Kept
48
+ // separate from CHANNEL_CONTENT_KEY_MAP/CHANNEL_DELIVERY_KEY_MAP below, which
49
+ // are the legacy messageMeta payload's keys.
50
+ export const CCS_CHANNEL_CONTENT_KEY_MAP = {
51
+ SMS: 'smsMessageContent',
52
+ EMAIL: 'emailMessageContent',
53
+ WHATSAPP: 'whatsappMessageContent',
54
+ MPUSH: 'mpushMessageContent',
55
+ INAPP: 'inAppMessageContent',
56
+ ANDROID: 'androidMessageContent',
57
+ IOS: 'iosMessageContent',
58
+ ZALO: 'zaloMessageContent',
59
+ VIBER: 'viberMessageContent',
60
+ LINE: 'lineMessageContent',
61
+ WEBPUSH: 'webPushMessageContent',
62
+ RCS: 'rcsMessageContent',
63
+ };
64
+
65
+ export const CCS_CHANNEL_DELIVERY_KEY_MAP = {
66
+ SMS: 'smsDeliverySettings',
67
+ EMAIL: 'emailDeliverySettings',
68
+ WHATSAPP: 'whatsappDeliverySettings',
69
+ MPUSH: 'mpushDeliverySettings',
70
+ INAPP: 'inAppDeliverySettings',
71
+ ANDROID: 'androidDeliverySettings',
72
+ IOS: 'iosDeliverySettings',
73
+ ZALO: 'zaloDeliverySettings',
74
+ VIBER: 'viberDeliverySettings',
75
+ LINE: 'lineDeliverySettings',
76
+ WEBPUSH: 'webPushDeliverySettings',
77
+ RCS: 'rcsDeliverySettings',
78
+ };
79
+
80
+ // The UI's own internal channel identifier for mobile push is 'MOBILEPUSH'
81
+ // (see CreativesContainer/constants.js MOBILE_PUSH), but CCS's channel enum
82
+ // only recognises 'MPUSH' (globals.js CCS_CHANNELS) — normalize before
83
+ // building the CCS payload. Every other channel identifier matches CCS as-is.
84
+ export const CCS_CHANNEL_NAME_MAP = {
85
+ MOBILEPUSH: 'MPUSH',
86
+ };
87
+
41
88
  // Channel config - single source of truth for CreativesContainer and TemplatesV2
42
89
  // paneKey: TemplatesV2 defaultPanes object key (for channelsToHide)
43
90
  // 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
  };