@capillarytech/creatives-library 9.2.3 → 9.2.4-alpha.feature-rcs-multi-account.52
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/package.json +1 -1
- package/v2Components/CommonTestAndPreview/DeliverySettings/ModifyDeliverySettings.js +9 -0
- package/v2Components/CommonTestAndPreview/DeliverySettings/index.js +44 -3
- package/v2Components/CommonTestAndPreview/DeliverySettings/messages.js +14 -0
- package/v2Components/CommonTestAndPreview/SendTestMessage.js +14 -0
- package/v2Components/CommonTestAndPreview/index.js +118 -11
- package/v2Components/CommonTestAndPreview/reducer.js +8 -2
- package/v2Components/CommonTestAndPreview/selectors.js +6 -0
- package/v2Components/CommonTestAndPreview/tests/DeliverySettings/ModifyDeliverySettings.test.js +11 -0
- package/v2Components/CommonTestAndPreview/tests/DeliverySettings/index.test.js +92 -0
- package/v2Components/CommonTestAndPreview/tests/index.test.js +200 -0
- package/v2Components/CommonTestAndPreview/tests/reducer.test.js +4 -0
- package/v2Components/CommonTestAndPreview/tests/selectors.test.js +10 -0
- package/v2Components/TestAndPreviewSlidebox/index.js +8 -0
- package/v2Containers/CommunicationFlow/CommunicationFlow.js +9 -1
- package/v2Containers/CommunicationFlow/Tests/CommunicationFlow.test.js +76 -1
- package/v2Containers/CommunicationFlow/messages.js +12 -0
- package/v2Containers/CommunicationFlow/steps/ChannelSelectionStep/ChannelSelectionStep.js +5 -0
- package/v2Containers/CommunicationFlow/steps/DeliverySettingsStep/DeliverySettingsSection.js +195 -19
- package/v2Containers/CommunicationFlow/steps/DeliverySettingsStep/SenderDetails.js +37 -4
- package/v2Containers/CommunicationFlow/steps/DeliverySettingsStep/Tests/DeliverySettingsSection.test.js +360 -0
- package/v2Containers/CommunicationFlow/steps/DeliverySettingsStep/Tests/SenderDetails.test.js +25 -0
- package/v2Containers/CommunicationFlow/steps/DeliverySettingsStep/Tests/deliverySettingsConfig.test.js +80 -0
- package/v2Containers/CommunicationFlow/steps/DeliverySettingsStep/deliverySettingsConfig.js +39 -8
- package/v2Containers/CreativesContainer/index.js +24 -0
- package/v2Containers/CreativesContainer/tests/index.test.js +82 -0
- package/v2Containers/Rcs/accountUtils.js +126 -0
- package/v2Containers/Rcs/index.js +30 -4
- package/v2Containers/Rcs/tests/__snapshots__/index.test.js.snap +108 -0
- package/v2Containers/Rcs/tests/accountUtils.test.js +178 -0
- package/v2Containers/Rcs/tests/testAndPreviewAccount.test.js +193 -0
- package/v2Containers/SmsTrai/Edit/tests/__snapshots__/index.test.js.snap +27 -0
- package/v2Containers/Templates/ChannelTypeIllustration.js +12 -0
- package/v2Containers/Templates/index.js +10 -5
- package/v2Containers/Templates/messages.js +4 -0
- package/v2Containers/Templates/tests/ChannelTypeIllustration.test.js +14 -2
- package/v2Containers/Templates/tests/index.test.js +112 -0
- package/v2Containers/Whatsapp/tests/__snapshots__/index.test.js.snap +2 -2
|
@@ -250,6 +250,88 @@ describe('Test SlideBoxContent container', () => {
|
|
|
250
250
|
expect(instance.state.templateData.smsFallBackContent).toEqual({ message: 'fallback-body' });
|
|
251
251
|
});
|
|
252
252
|
|
|
253
|
+
describe('RCS multi-account fields on consumer templateData', () => {
|
|
254
|
+
const rcsAccountA = { id: 101, name: 'Brand A', sourceAccountIdentifier: 'acc-A' };
|
|
255
|
+
const buildRcsFormValue = (accountId) => ({
|
|
256
|
+
validity: true,
|
|
257
|
+
value: {
|
|
258
|
+
name: 'rcs_creative_name',
|
|
259
|
+
type: 'RCS',
|
|
260
|
+
versions: {
|
|
261
|
+
base: {
|
|
262
|
+
content: {
|
|
263
|
+
RCS: {
|
|
264
|
+
rcsContent: {
|
|
265
|
+
contentType: 'RICHCARD', cardType: 'STANDALONE', cardSettings: {}, cardContent: [{}], accountId,
|
|
266
|
+
},
|
|
267
|
+
},
|
|
268
|
+
},
|
|
269
|
+
},
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
});
|
|
273
|
+
const renderRcsEdit = ({ selectedRcsAccount, templateData = rcsEditTemplateData }) => shallowWithIntl(
|
|
274
|
+
<Creatives
|
|
275
|
+
loyaltyMetaData={loyaltyMetaData}
|
|
276
|
+
Templates={{ ...rcsTemplates, selectedRcsAccount }}
|
|
277
|
+
channel="RCS"
|
|
278
|
+
slidBoxContent="editTemplate"
|
|
279
|
+
templateData={templateData}
|
|
280
|
+
handleCloseCreatives={handleCloseCreatives}
|
|
281
|
+
getCreativesData={getCreativesData}
|
|
282
|
+
isFullMode={false}
|
|
283
|
+
templateActions={{
|
|
284
|
+
getCdnTransformationConfig,
|
|
285
|
+
}}
|
|
286
|
+
/>,
|
|
287
|
+
);
|
|
288
|
+
|
|
289
|
+
it('adds the selected account when it is the account the template was saved with', async () => {
|
|
290
|
+
const wrapper = renderRcsEdit({ selectedRcsAccount: rcsAccountA });
|
|
291
|
+
const formValue = buildRcsFormValue('101');
|
|
292
|
+
const templateData = await wrapper.instance().getCreativesData('RCS', formValue, formValue);
|
|
293
|
+
expect(templateData.accountId).toBe('101');
|
|
294
|
+
expect(templateData.sourceAccountIdentifier).toBe('acc-A');
|
|
295
|
+
expect(templateData.accountName).toBe('Brand A');
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
it('keeps the consumer-provided account when it is verified for the template accountId', async () => {
|
|
299
|
+
const wrapper = renderRcsEdit({
|
|
300
|
+
selectedRcsAccount: rcsAccountA,
|
|
301
|
+
templateData: {
|
|
302
|
+
...rcsEditTemplateData, accountId: 202, sourceAccountIdentifier: 'acc-B', accountName: 'Brand B',
|
|
303
|
+
},
|
|
304
|
+
});
|
|
305
|
+
const formValue = buildRcsFormValue('202');
|
|
306
|
+
const templateData = await wrapper.instance().getCreativesData('RCS', formValue, formValue);
|
|
307
|
+
expect(templateData.accountId).toBe('202');
|
|
308
|
+
expect(templateData.sourceAccountIdentifier).toBe('acc-B');
|
|
309
|
+
expect(templateData.accountName).toBe('Brand B');
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
it('omits the account fields when the consumer-provided account is not the template accountId', async () => {
|
|
313
|
+
const wrapper = renderRcsEdit({
|
|
314
|
+
selectedRcsAccount: rcsAccountA,
|
|
315
|
+
templateData: {
|
|
316
|
+
...rcsEditTemplateData, accountId: 303, sourceAccountIdentifier: 'acc-C', accountName: 'Brand C',
|
|
317
|
+
},
|
|
318
|
+
});
|
|
319
|
+
const formValue = buildRcsFormValue('202');
|
|
320
|
+
const templateData = await wrapper.instance().getCreativesData('RCS', formValue, formValue);
|
|
321
|
+
expect(templateData.accountId).toBe('202');
|
|
322
|
+
expect(templateData).not.toHaveProperty('sourceAccountIdentifier');
|
|
323
|
+
expect(templateData).not.toHaveProperty('accountName');
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
it('omits the account fields when no account is known', async () => {
|
|
327
|
+
const wrapper = renderRcsEdit({ selectedRcsAccount: undefined });
|
|
328
|
+
const formValue = buildRcsFormValue('');
|
|
329
|
+
const templateData = await wrapper.instance().getCreativesData('RCS', formValue, formValue);
|
|
330
|
+
expect(templateData).not.toHaveProperty('sourceAccountIdentifier');
|
|
331
|
+
expect(templateData).not.toHaveProperty('accountName');
|
|
332
|
+
});
|
|
333
|
+
});
|
|
334
|
+
|
|
253
335
|
it('RCS getFormData mirrors rcsCardVarMapped onto templateData for campaign reopen', async () => {
|
|
254
336
|
renderedComponent = shallowWithIntl(
|
|
255
337
|
<Creatives
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RCS multi-account helpers.
|
|
3
|
+
*
|
|
4
|
+
* A saved RCS template stores its account in `rcsContent.accountId` / `accountId`: the WeCRM account's
|
|
5
|
+
* sourceAccountIdentifier (full mode) or its WeCRM id (library mode). Each RCS domain links to its account
|
|
6
|
+
* through `connectionProperties.sourceAccountIdentifier`.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const toTrimmedString = (value) => (value == null ? '' : String(value).trim());
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Account key for a template whose saved account is known but cannot be matched (no longer among the WeCRM RCS
|
|
13
|
+
* accounts). It never equals a real sourceAccountIdentifier and gets no domain from the helpers below, so it
|
|
14
|
+
* means "account not configured" — never the first-domain fallback.
|
|
15
|
+
*/
|
|
16
|
+
export const RCS_ACCOUNT_UNAVAILABLE = '__rcs_account_unavailable__';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Whether a WeCRM RCS account is the one referenced by a saved `accountId`.
|
|
20
|
+
* @param {Object} account - WeCRM RCS account ({ id, sourceAccountIdentifier, ... })
|
|
21
|
+
* @param {string|number} accountId - saved accountId (WeCRM id or sourceAccountIdentifier)
|
|
22
|
+
* @returns {boolean}
|
|
23
|
+
*/
|
|
24
|
+
export const isRcsAccountForAccountId = (account, accountId) => {
|
|
25
|
+
const id = toTrimmedString(accountId);
|
|
26
|
+
if (!account || !id) return false;
|
|
27
|
+
return [account.sourceAccountIdentifier, account.id].map(toTrimmedString).includes(id);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Find the WeCRM RCS account referenced by a saved `accountId` (WeCRM id or sourceAccountIdentifier).
|
|
32
|
+
* @param {Array} accounts - WeCRM RCS accounts
|
|
33
|
+
* @param {string|number} accountId
|
|
34
|
+
* @returns {Object|null}
|
|
35
|
+
*/
|
|
36
|
+
export const findRcsAccountByAccountId = (accounts, accountId) => {
|
|
37
|
+
if (!Array.isArray(accounts)) return null;
|
|
38
|
+
return accounts.find((account) => isRcsAccountForAccountId(account, accountId)) || null;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Resolve a template's RCS account key from its saved accountId and the WeCRM RCS accounts request state.
|
|
43
|
+
* - `none`: no saved accountId → '' (account unknown: first-domain behaviour)
|
|
44
|
+
* - `resolved`: account found → its sourceAccountIdentifier
|
|
45
|
+
* - `failed`: accounts request failed → '' (callers must not default a sender or send; offer a retry)
|
|
46
|
+
* - `pending`: accounts not loaded yet → '' (callers must not default a sender or send yet)
|
|
47
|
+
* - `missing`: accounts loaded, saved account not among them → RCS_ACCOUNT_UNAVAILABLE (not configured)
|
|
48
|
+
*
|
|
49
|
+
* @param {Object} params
|
|
50
|
+
* @param {string|number} params.accountId - saved accountId (WeCRM id or sourceAccountIdentifier)
|
|
51
|
+
* @param {Array} params.accounts - WeCRM RCS accounts
|
|
52
|
+
* @param {boolean} params.isLoaded - the accounts request completed successfully
|
|
53
|
+
* @param {boolean} params.hasFailed - the accounts request failed
|
|
54
|
+
* @returns {{ status: string, accountKey: string }}
|
|
55
|
+
*/
|
|
56
|
+
export const resolveRcsAccountKey = ({
|
|
57
|
+
accountId, accounts, isLoaded, hasFailed,
|
|
58
|
+
}) => {
|
|
59
|
+
if (!toTrimmedString(accountId)) return { status: 'none', accountKey: '' };
|
|
60
|
+
const sourceAccountIdentifier = toTrimmedString(findRcsAccountByAccountId(accounts, accountId)?.sourceAccountIdentifier);
|
|
61
|
+
if (sourceAccountIdentifier) return { status: 'resolved', accountKey: sourceAccountIdentifier };
|
|
62
|
+
if (hasFailed) return { status: 'failed', accountKey: '' };
|
|
63
|
+
if (!isLoaded) return { status: 'pending', accountKey: '' };
|
|
64
|
+
return { status: 'missing', accountKey: RCS_ACCOUNT_UNAVAILABLE };
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* RCS domains usable for a template's account (same binding as WhatsApp, by sourceAccountIdentifier).
|
|
69
|
+
* - account unknown (empty id): every domain, the pre-multi-account behaviour
|
|
70
|
+
* - account known: the domains of that account; else the only domain when it carries no account id
|
|
71
|
+
* (legacy single-domain org); else [] — the account is not configured
|
|
72
|
+
* - RCS_ACCOUNT_UNAVAILABLE: [] (the account no longer exists)
|
|
73
|
+
*
|
|
74
|
+
* @param {Array} domains - RCS domain rows
|
|
75
|
+
* @param {string} sourceAccountIdentifier - template account's sourceAccountIdentifier
|
|
76
|
+
* @param {Function} getDomainAccountId - (domain) => that domain's sourceAccountIdentifier
|
|
77
|
+
* @returns {Array}
|
|
78
|
+
*/
|
|
79
|
+
export const getRcsDomainsForAccount = (domains, sourceAccountIdentifier, getDomainAccountId) => {
|
|
80
|
+
const domainList = Array.isArray(domains) ? domains.filter(Boolean) : [];
|
|
81
|
+
const accountId = toTrimmedString(sourceAccountIdentifier);
|
|
82
|
+
if (!accountId) return domainList;
|
|
83
|
+
if (accountId === RCS_ACCOUNT_UNAVAILABLE || !domainList.length) return [];
|
|
84
|
+
const getAccountId = typeof getDomainAccountId === 'function' ? getDomainAccountId : () => '';
|
|
85
|
+
const accountDomains = domainList.filter((domain) => toTrimmedString(getAccountId(domain)) === accountId);
|
|
86
|
+
if (accountDomains.length) return accountDomains;
|
|
87
|
+
if (domainList.length === 1 && !toTrimmedString(getAccountId(domainList[0]))) return domainList;
|
|
88
|
+
return [];
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Pick the RCS domain for a template's account (first of getRcsDomainsForAccount).
|
|
93
|
+
* - account unknown (empty id): first domain, the pre-multi-account behaviour
|
|
94
|
+
* - account known: its domain; else the legacy single domain without account id; else null — the account is
|
|
95
|
+
* not configured, never another account's domain
|
|
96
|
+
*
|
|
97
|
+
* @param {Array} domains - RCS domain rows
|
|
98
|
+
* @param {string} sourceAccountIdentifier - template account's sourceAccountIdentifier
|
|
99
|
+
* @param {Function} getDomainAccountId - (domain) => that domain's sourceAccountIdentifier
|
|
100
|
+
* @returns {Object|null}
|
|
101
|
+
*/
|
|
102
|
+
export const pickRcsDomainForAccount = (domains, sourceAccountIdentifier, getDomainAccountId) => (
|
|
103
|
+
getRcsDomainsForAccount(domains, sourceAccountIdentifier, getDomainAccountId)[0] || null
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
/** sourceAccountIdentifier of a parsed Test & Preview RCS domain row (see parseSenderDetailsResponse). */
|
|
107
|
+
export const getParsedRcsDomainAccountId = (domain) => domain?.sourceAccountIdentifier;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* The saved RCS account id of a creative form (`rcsContent.accountId`: WeCRM id from hosts / library saves,
|
|
111
|
+
* or sourceAccountIdentifier from the editor). '' when absent.
|
|
112
|
+
*/
|
|
113
|
+
export const getRcsAccountIdFromCreativeForm = (creativeForm) => {
|
|
114
|
+
const rcsSection = creativeForm?.versions?.base?.content?.RCS ?? creativeForm?.content?.RCS ?? {};
|
|
115
|
+
return toTrimmedString(rcsSection?.rcsContent?.accountId ?? rcsSection?.accountId);
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* True when the template's account is known and has no RCS domain of its own — including when the settled
|
|
120
|
+
* domain list is empty (the account cannot send either way). False when the account is unknown.
|
|
121
|
+
* Callers must only pass a settled domain list (not one that is still loading).
|
|
122
|
+
*/
|
|
123
|
+
export const isRcsAccountNotConfigured = (domains, sourceAccountIdentifier, getDomainAccountId) => {
|
|
124
|
+
if (!toTrimmedString(sourceAccountIdentifier)) return false;
|
|
125
|
+
return !pickRcsDomainForAccount(domains, sourceAccountIdentifier, getDomainAccountId);
|
|
126
|
+
};
|
|
@@ -162,6 +162,7 @@ import {
|
|
|
162
162
|
checkSmsFallbackBlocksDone,
|
|
163
163
|
isSmsFallbackContentTooLong,
|
|
164
164
|
} from './utils';
|
|
165
|
+
import { isRcsAccountForAccountId } from './accountUtils';
|
|
165
166
|
import {
|
|
166
167
|
getCarouselImageAssetIndex,
|
|
167
168
|
getCarouselVideoAssetIndex,
|
|
@@ -2904,16 +2905,40 @@ const onTitleAddVar = () => {
|
|
|
2904
2905
|
return payload;
|
|
2905
2906
|
};
|
|
2906
2907
|
|
|
2908
|
+
/**
|
|
2909
|
+
* RCS multi-account: account an existing template was saved with (`rcsContent.accountId`: WeCRM id or
|
|
2910
|
+
* sourceAccountIdentifier). Read straight from the template details so every card type (carousel included)
|
|
2911
|
+
* is covered. '' for a new template.
|
|
2912
|
+
*/
|
|
2913
|
+
const savedTemplateRcsAccountId = useMemo(() => {
|
|
2914
|
+
if (!isEditFlow) return '';
|
|
2915
|
+
// Template API shape first (versions.base.content.RCS.rcsContent.accountId); library / consumer templateData
|
|
2916
|
+
// carries it as rcsContent.accountId or the root accountId (getCreativesData shape).
|
|
2917
|
+
const savedAccountId = [
|
|
2918
|
+
get(rcsHydrationDetails, 'versions.base.content.RCS.rcsContent.accountId'),
|
|
2919
|
+
get(rcsHydrationDetails, 'rcsContent.accountId'),
|
|
2920
|
+
get(rcsHydrationDetails, 'accountId'),
|
|
2921
|
+
].map((value) => (value == null ? '' : String(value).trim())).find(Boolean);
|
|
2922
|
+
return savedAccountId || '';
|
|
2923
|
+
}, [isEditFlow, rcsHydrationDetails]);
|
|
2924
|
+
|
|
2907
2925
|
/** Shape expected by CommonTestAndPreview buildRcsTestMessagePayload (versions.base.content.RCS). */
|
|
2908
2926
|
const testPreviewFormData = useMemo(() => {
|
|
2909
2927
|
const payload = createPayload();
|
|
2910
2928
|
const rcs = payload?.versions?.base?.content?.RCS;
|
|
2911
2929
|
if (!rcs) return null;
|
|
2912
2930
|
// createMessageMeta uses WeCRM `id` when present; else template API account id (sourceAccountIdentifier).
|
|
2913
|
-
const
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2931
|
+
const hasSelectedWecrmAccountId = wecrmAccountId != null && String(wecrmAccountId).trim() !== '';
|
|
2932
|
+
const selectedAccountIdForMeta = hasSelectedWecrmAccountId ? String(wecrmAccountId) : accountId;
|
|
2933
|
+
// Existing template: preview with its own saved account. The current selection is used only when it is that
|
|
2934
|
+
// same account (keeps the WeCRM id for createMessageMeta); a new template uses the selection as before.
|
|
2935
|
+
const isSelectionTheSavedAccount = !savedTemplateRcsAccountId || isRcsAccountForAccountId(
|
|
2936
|
+
{ id: wecrmAccountId, sourceAccountIdentifier: accountId },
|
|
2937
|
+
savedTemplateRcsAccountId,
|
|
2938
|
+
);
|
|
2939
|
+
const accountIdForCreateMessageMeta = isSelectionTheSavedAccount
|
|
2940
|
+
? selectedAccountIdForMeta
|
|
2941
|
+
: savedTemplateRcsAccountId;
|
|
2917
2942
|
const isSlotMappingModeForPreview = isEditFlow || !isFullMode;
|
|
2918
2943
|
let rcsForTest = {
|
|
2919
2944
|
...rcs,
|
|
@@ -3028,6 +3053,7 @@ const onTitleAddVar = () => {
|
|
|
3028
3053
|
templateType,
|
|
3029
3054
|
accountId,
|
|
3030
3055
|
wecrmAccountId,
|
|
3056
|
+
savedTemplateRcsAccountId,
|
|
3031
3057
|
accessToken,
|
|
3032
3058
|
accountName,
|
|
3033
3059
|
hostName,
|