@capillarytech/creatives-library 8.0.125-alpha.2 → 8.0.125-alpha.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@capillarytech/creatives-library",
3
3
  "author": "meharaj",
4
- "version": "8.0.125-alpha.2",
4
+ "version": "8.0.125-alpha.4",
5
5
  "description": "Capillary creatives ui",
6
6
  "main": "./index.js",
7
7
  "module": "./index.es.js",
@@ -27,6 +27,9 @@ import { NONE } from "../v2Containers/Whatsapp/constants";
27
27
  function createPayload({
28
28
  templateName, androidContent, iosContent, imageSrc = {}, mpushVideoSrcAndPreview = {}, accountData, options = {}, sameContent = false,
29
29
  } = {}) {
30
+ // Platform support checks must be at the top
31
+ const isAndroidSupported = accountData?.configs?.android === '1';
32
+ const isIosSupported = accountData?.configs?.ios === '1';
30
33
  // Validate and trim template name
31
34
  const trimmedTemplateName = (templateName || "").trim();
32
35
  if (!trimmedTemplateName) {
@@ -34,11 +37,11 @@ function createPayload({
34
37
  }
35
38
 
36
39
  // Validate androidContent and iosContent
37
- if (!androidContent || !androidContent?.title || !androidContent?.message) {
40
+ if (androidContent && (!androidContent?.title || !androidContent?.message)) {
38
41
  throw new Error("Android content must have title and message");
39
42
  }
40
43
 
41
- if (!iosContent || !iosContent?.title || !iosContent?.message) {
44
+ if (iosContent && (!iosContent?.title || !iosContent?.message)) {
42
45
  throw new Error("iOS content must have title and message");
43
46
  }
44
47
 
@@ -172,59 +175,86 @@ function createPayload({
172
175
  }
173
176
 
174
177
  // Compose androidContent for legacy payload
175
- const androidLegacy = {
176
- luid: "{{luid}}",
177
- cuid: "{{cuid}}",
178
- communicationId: "{{communicationId}}",
179
- title: androidContent.title,
180
- message: androidContent.message,
181
- expandableDetails: buildExpandableDetails(androidContent, safeImageSrc.androidImageSrc),
182
- custom: buildCustomFields(androidContent),
183
- type: androidContent.mediaType,
184
- deviceType: 'ANDROID',
185
- };
186
-
187
- // Add main notification body CTA if actionOnClick is enabled
188
- if (androidContent?.actionOnClick && (androidContent?.deepLinkValue || androidContent?.externalLinkValue)) {
189
- const actionLink = androidContent?.linkType === EXTERNAL_LINK ? androidContent?.externalLinkValue : androidContent?.deepLinkValue;
190
- androidLegacy.cta = {
191
- type: androidContent.linkType === EXTERNAL_LINK ? EXTERNAL_URL : DEEP_LINK,
192
- actionLink,
178
+ let androidLegacy;
179
+ if (isAndroidSupported && isValidContent(androidContent)) {
180
+ androidLegacy = {
181
+ luid: "{{luid}}",
182
+ cuid: "{{cuid}}",
183
+ communicationId: "{{communicationId}}",
184
+ title: androidContent.title,
185
+ message: androidContent.message,
186
+ expandableDetails: buildExpandableDetails(androidContent, safeImageSrc.androidImageSrc),
187
+ custom: buildCustomFields(androidContent),
188
+ type: androidContent.mediaType,
189
+ deviceType: 'ANDROID',
193
190
  };
191
+ if (androidContent?.actionOnClick && (androidContent?.deepLinkValue || androidContent?.externalLinkValue)) {
192
+ const actionLink = androidContent?.linkType === EXTERNAL_LINK ? androidContent?.externalLinkValue : androidContent?.deepLinkValue;
193
+ androidLegacy.cta = {
194
+ type: androidContent.linkType === EXTERNAL_LINK ? EXTERNAL_URL : DEEP_LINK,
195
+ actionLink,
196
+ };
197
+ }
194
198
  }
195
199
 
196
200
  // Compose iosContent for legacy payload
197
- const iosLegacy = {
198
- luid: "{{luid}}",
199
- cuid: "{{cuid}}",
200
- communicationId: "{{communicationId}}",
201
- title: iosContent.title,
202
- message: iosContent.message,
203
- expandableDetails: buildExpandableDetails(iosContent, safeImageSrc.iosImageSrc, 'IOS'),
204
- custom: buildCustomFields(iosContent),
205
- type: iosContent.mediaType,
206
- deviceType: 'IOS',
207
- };
208
-
209
- // Add main notification body CTA if actionOnClick is enabled
210
- if (iosContent?.actionOnClick && (iosContent?.deepLinkValue || iosContent?.externalLinkValue)) {
211
- const actionLink = iosContent?.linkType === EXTERNAL_LINK ? iosContent?.externalLinkValue : iosContent?.deepLinkValue;
212
- iosLegacy.cta = {
213
- type: iosContent?.linkType === EXTERNAL_LINK ? EXTERNAL_URL : DEEP_LINK,
214
- actionLink,
201
+ let iosLegacy;
202
+ if (isIosSupported && isValidContent(iosContent)) {
203
+ iosLegacy = {
204
+ luid: "{{luid}}",
205
+ cuid: "{{cuid}}",
206
+ communicationId: "{{communicationId}}",
207
+ title: iosContent.title,
208
+ message: iosContent.message,
209
+ expandableDetails: buildExpandableDetails(iosContent, safeImageSrc.iosImageSrc, 'IOS'),
210
+ custom: buildCustomFields(iosContent),
211
+ type: iosContent.mediaType,
212
+ deviceType: 'IOS',
215
213
  };
214
+ if (iosContent?.actionOnClick && (iosContent?.deepLinkValue || iosContent?.externalLinkValue)) {
215
+ const actionLink = iosContent?.linkType === EXTERNAL_LINK ? iosContent?.externalLinkValue : iosContent?.deepLinkValue;
216
+ iosLegacy.cta = {
217
+ type: iosContent?.linkType === EXTERNAL_LINK ? EXTERNAL_URL : DEEP_LINK,
218
+ actionLink,
219
+ };
220
+ }
221
+ }
222
+
223
+ // Helper to check if content is non-empty and valid
224
+ function isValidContent(content) {
225
+ return content && typeof content === 'object' && content.title && content.message;
226
+ }
227
+
228
+ // Determine platform support from accountData
229
+ // const isAndroidSupported = accountData?.configs?.android === '1';
230
+ // const isIosSupported = accountData?.configs?.ios === '1';
231
+
232
+ if (isAndroidSupported && (!androidContent || !androidContent?.title || !androidContent?.message)) {
233
+ console.error('Android content missing or invalid:', androidContent);
234
+ throw new Error("Android content must have title and message");
235
+ }
236
+ if (isIosSupported && (!iosContent || !iosContent?.title || !iosContent?.message)) {
237
+ console.error('iOS content missing or invalid:', iosContent);
238
+ throw new Error("iOS content must have title and message");
216
239
  }
217
240
 
218
241
  // Compose the full payload in legacy format
242
+ const versionsBase = {};
243
+ if (androidLegacy) versionsBase.ANDROID = androidLegacy;
244
+ if (iosLegacy) versionsBase.IOS = iosLegacy;
245
+
246
+ // Fallback template name to platform title if not provided
247
+ let finalTemplateName = trimmedTemplateName;
248
+ if (!finalTemplateName) {
249
+ finalTemplateName = (androidContent && androidContent.title) || (iosContent && iosContent.title) || '';
250
+ }
251
+
219
252
  const payload = {
220
253
  versions: {
221
- base: {
222
- ANDROID: androidLegacy,
223
- IOS: iosLegacy,
224
- },
254
+ base: versionsBase,
225
255
  },
226
256
  type: MOBILE_PUSH_CHANNEL,
227
- name: trimmedTemplateName,
257
+ name: finalTemplateName,
228
258
  definition: {
229
259
  accountId,
230
260
  licenseCode,
@@ -248,20 +248,13 @@ function getLinkTypeFields({inputFieldsArgs, fieldIndex, deepLinkOptions, formDa
248
248
  }
249
249
 
250
250
  function getContent(obj) {
251
- const {
252
- versions : {
253
- base: {
254
- ANDROID: {
255
- title : androidTitle,
256
- message : androidMessage
257
- } = {},
258
- IOS: {
259
- title: iosTitle,
260
- message: iosMessage
261
- } = {}
262
- } = {}
263
- } = {}
264
- } = obj;
251
+ const base = obj?.versions?.base || {};
252
+ const android = base.ANDROID || {};
253
+ const ios = base.IOS || {};
254
+ const androidTitle = android.title || '';
255
+ const androidMessage = android.message || '';
256
+ const iosTitle = ios.title || '';
257
+ const iosMessage = ios.message || '';
265
258
  return `${androidTitle} ${androidMessage} ${iosTitle} ${iosMessage}`;
266
259
  }
267
260
  export {