@bikdotai/bik-component-library 0.0.700-beta.5 → 0.0.700-beta.6

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.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../node_modules/react/jsx-runtime.js"),l=require("react"),t=require("../template-context-mapper/context/templateModalContext.js"),a=require("./helpers/TemplateCreatorHelper.js"),i=require("./helpers/templateMiscHelper.js"),r=require("./models/TemplateMeta.js"),o=require("./RCS/RCSTemplateLikePreview.js"),n=require("./utils/TemplateHelperUtils.js"),d=require("./WhatsApp/WhatsAppLikePreview.js"),s=require("./WhatsApp/WhatsAppLikePreviewV2.js");exports.default=u=>{let{template:p,extras:v,containerStyle:x,usePlaceHolderName:m,showHeader:h,zeroStateComponent:c,size:b,showSampleValues:T,carouselCardIndex:y,isWhatsappCarousel:j,isPreview:w,channel:C}=u;var N,P,V,k,E,R,S,f,L,B,A,g,q,F,H,O,W,I,M,D,U,_,z,Y,G,J,K,Q,X,Z;const{selectedCarouselIndex:$,pod:ee}=t.useTemplateModalContext(),[le,te]=l.useState(),ae=new a.TemplateCreatorHelper,ie=new n.TemplateHelperUtils,re=[];if((null===(P=null===(N=null==le?void 0:le.ctaBtn)||void 0===N?void 0:N.phoneNumber)||void 0===P?void 0:P.isChecked)&&re.push({type:"phoneNumber",text:null!==(V=le.ctaBtn.phoneNumber.btnText)&&void 0!==V?V:"",extra:null!==(k=le.ctaBtn.phoneNumber.phoneNumber)&&void 0!==k?k:""}),(null===(R=null===(E=null==le?void 0:le.ctaBtn)||void 0===E?void 0:E.websiteLinkBtn)||void 0===R?void 0:R.isChecked)&&re.push({type:"website",text:null!==(S=le.ctaBtn.websiteLinkBtn.btnText)&&void 0!==S?S:"",extra:null!==(L=null===(f=le.ctaBtn.websiteLinkBtn)||void 0===f?void 0:f.linkOpens)&&void 0!==L?L:"",placeholder:null!==(B=le.ctaBtn.websiteLinkBtn.placeholder)&&void 0!==B?B:""}),l.useEffect((()=>{p&&ae.parseUITemplateFromDBFormat({dbFormattedTemplate:p,isDuplicate:!1,showSampleValues:T,isV2:!p.htmlContentUrl,pod:ee}).then((e=>{te(Object.assign({},e))}))}),[p,T]),l.useEffect((()=>{p&&ae.parseUITemplateFromDBFormat({dbFormattedTemplate:p,isDuplicate:!1,showSampleValues:T,isV2:!p.htmlContentUrl,pod:ee}).then((e=>{te(Object.assign({},e))}))}),[$]),!p)return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:c});if(i.isRCSChannel(C||(null==p?void 0:p.channel))){const l=ae.parseTemplateConfiguration(p);return e.jsxRuntimeExports.jsx(o.RCSTemplateLikePreview,{showHeader:h,containerPadding:"large"===b?"16px 36px 12px 16px":"12px 36px 12px 12px",containerStyle:x,textType:"html",bodyText:null==le?void 0:le.bodyText,titleText:null==le?void 0:le.titleText,footerText:null==le?void 0:le.footerText,headerMediaType:(null==le?void 0:le.headerType)||r.HEADER_TYPES.NONE,headerText:null==le?void 0:le.headerText,headerAssetLink:null!==(A=null==le?void 0:le.headerAssetLink)&&void 0!==A?A:"",headerAssetName:null!==(g=null==le?void 0:le.headerAssetName)&&void 0!==g?g:"",quickReplybtn:null==le?void 0:le.quickReply,ctaBtn:re,actionTypes:null==le?void 0:le.actionsType,extras:v,hidePreviewText:!0,imagePreviewStyles:{objectFit:"cover"},carouselCardIndex:y,zeroStateComponent:null!=c?c:e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:" "}),bodyVariableList:null!==(F=null===(q=null==le?void 0:le.bodyVariables)||void 0===q?void 0:q.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==F?F:[],headerVariableList:null!==(O=null===(H=null==le?void 0:le.headerVariables)||void 0===H?void 0:H.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==O?O:[],titleVariableList:null!==(I=null===(W=null==le?void 0:le.titleVariables)||void 0===W?void 0:W.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==I?I:[],buttons:null==le?void 0:le.allButtons,isWhatsappCarousel:j,isPreview:w,templateConfiguration:l})}return p.htmlContentUrl?e.jsxRuntimeExports.jsx(d.WhatsappLikePreview,{showHeader:h,containerPadding:"large"===b?"16px 56px 12px 16px":"12px 56px 12px 12px",containerStyle:x,textType:"html",bodyText:ie.whatsappOnlyFillVariablesValueInBodyText(null!==(G=null==le?void 0:le.bodyText)&&void 0!==G?G:"",null!==(J=null==le?void 0:le.bodyVariables)&&void 0!==J?J:[],m),footerText:null==le?void 0:le.footerText,headerMediaType:(null==le?void 0:le.headerType)||r.HEADER_TYPES.NONE,headerText:ie.fillVariablesValInBodyText(null!==(K=null==le?void 0:le.headerText)&&void 0!==K?K:"",null!==(Q=null==le?void 0:le.headerVariables)&&void 0!==Q?Q:[],m),headerAssetLink:null!==(X=null==le?void 0:le.headerAssetLink)&&void 0!==X?X:"",headerAssetName:null!==(Z=null==le?void 0:le.headerAssetName)&&void 0!==Z?Z:"",quickReplybtn:null==le?void 0:le.quickReply,ctaBtn:re,actionTypes:null==le?void 0:le.actionsType,extras:v,hidePreviewText:!0,imagePreviewStyles:{objectFit:"cover"},zeroStateComponent:null!=c?c:e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:" "}),isPreview:w}):e.jsxRuntimeExports.jsx(s.WhatsappLikePreviewV2,{showHeader:h,containerPadding:"large"===b?"16px 56px 12px 16px":"12px 56px 12px 12px",containerStyle:x,textType:"html",bodyText:null==le?void 0:le.bodyText,footerText:null==le?void 0:le.footerText,headerMediaType:(null==le?void 0:le.headerType)||r.HEADER_TYPES.NONE,headerText:null==le?void 0:le.headerText,headerAssetLink:null!==(M=null==le?void 0:le.headerAssetLink)&&void 0!==M?M:"",headerAssetName:null!==(D=null==le?void 0:le.headerAssetName)&&void 0!==D?D:"",quickReplybtn:null==le?void 0:le.quickReply,ctaBtn:re,actionTypes:null==le?void 0:le.actionsType,extras:v,hidePreviewText:!0,imagePreviewStyles:{objectFit:"cover"},carouselCardIndex:y,zeroStateComponent:null!=c?c:e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:" "}),bodyVariableList:null!==(_=null===(U=null==le?void 0:le.bodyVariables)||void 0===U?void 0:U.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==_?_:[],headerVariableList:null!==(Y=null===(z=null==le?void 0:le.headerVariables)||void 0===z?void 0:z.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==Y?Y:[],buttons:null==le?void 0:le.allButtons,limitedTimeOfferComponent:null==le?void 0:le.limitedTimeOfferComponent,isWhatsappCarousel:j,isPreview:w,showCallPermissionCard:null==p?void 0:p.showCallPermissionCard,callPermissionText:null==p?void 0:p.callPermissionText})};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../node_modules/react/jsx-runtime.js"),l=require("react"),t=require("../template-context-mapper/context/templateModalContext.js"),a=require("./helpers/TemplateCreatorHelper.js"),i=require("./helpers/templateMiscHelper.js"),r=require("./models/TemplateMeta.js"),o=require("./RCS/RCSTemplateLikePreview.js"),n=require("./utils/TemplateHelperUtils.js"),d=require("./WhatsApp/WhatsAppLikePreview.js"),s=require("./WhatsApp/WhatsAppLikePreviewV2.js");exports.default=u=>{let{template:p,extras:v,containerStyle:x,usePlaceHolderName:m,showHeader:h,zeroStateComponent:c,size:b,showSampleValues:T,carouselCardIndex:y,isWhatsappCarousel:j,isPreview:w,channel:C}=u;var N,P,V,k,E,R,S,f,L,B,A,g,q,F,H,O,W,I,M,D,U,_,z,Y,G,J,K,Q,X,Z;const{selectedCarouselIndex:$,pod:ee}=t.useTemplateModalContext(),[le,te]=l.useState(),ae=new a.TemplateCreatorHelper,ie=new n.TemplateHelperUtils,re=[];if((null===(P=null===(N=null==le?void 0:le.ctaBtn)||void 0===N?void 0:N.phoneNumber)||void 0===P?void 0:P.isChecked)&&re.push({type:"phoneNumber",text:null!==(V=le.ctaBtn.phoneNumber.btnText)&&void 0!==V?V:"",extra:null!==(k=le.ctaBtn.phoneNumber.phoneNumber)&&void 0!==k?k:""}),(null===(R=null===(E=null==le?void 0:le.ctaBtn)||void 0===E?void 0:E.websiteLinkBtn)||void 0===R?void 0:R.isChecked)&&re.push({type:"website",text:null!==(S=le.ctaBtn.websiteLinkBtn.btnText)&&void 0!==S?S:"",extra:null!==(L=null===(f=le.ctaBtn.websiteLinkBtn)||void 0===f?void 0:f.linkOpens)&&void 0!==L?L:"",placeholder:null!==(B=le.ctaBtn.websiteLinkBtn.placeholder)&&void 0!==B?B:""}),l.useEffect((()=>{p&&ae.parseUITemplateFromDBFormat({dbFormattedTemplate:p,isDuplicate:!1,showSampleValues:T,isV2:!p.htmlContentUrl,pod:ee}).then((e=>{te(Object.assign({},e))}))}),[p,T]),l.useEffect((()=>{p&&ae.parseUITemplateFromDBFormat({dbFormattedTemplate:p,isDuplicate:!1,showSampleValues:T,isV2:!p.htmlContentUrl,pod:ee}).then((e=>{te(Object.assign({},e))}))}),[$]),!p)return e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:c});if(i.isRCSChannel(C||(null==p?void 0:p.channel))){const l=ae.parseTemplateConfiguration(p);return e.jsxRuntimeExports.jsx(o.RCSTemplateLikePreview,{showHeader:h,containerPadding:"large"===b?"16px 36px 12px 16px":"12px 36px 12px 12px",containerStyle:x,textType:"html",bodyText:null==le?void 0:le.bodyText,titleText:null==le?void 0:le.titleText,footerText:null==le?void 0:le.footerText,headerMediaType:(null==le?void 0:le.headerType)||r.HEADER_TYPES.NONE,headerText:null==le?void 0:le.headerText,headerAssetLink:null!==(A=null==le?void 0:le.headerAssetLink)&&void 0!==A?A:"",headerAssetName:null!==(g=null==le?void 0:le.headerAssetName)&&void 0!==g?g:"",quickReplybtn:null==le?void 0:le.quickReply,ctaBtn:re,actionTypes:null==le?void 0:le.actionsType,extras:v,hidePreviewText:!0,imagePreviewStyles:{objectFit:"cover"},carouselCardIndex:y,zeroStateComponent:null!=c?c:e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:" "}),bodyVariableList:null!==(F=null===(q=null==le?void 0:le.bodyVariables)||void 0===q?void 0:q.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==F?F:[],headerVariableList:null!==(O=null===(H=null==le?void 0:le.headerVariables)||void 0===H?void 0:H.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==O?O:[],titleVariableList:null!==(I=null===(W=null==le?void 0:le.titleVariables)||void 0===W?void 0:W.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==I?I:[],buttons:null==le?void 0:le.allButtons,isWhatsappCarousel:j,isPreview:w,templateConfiguration:l})}return p.htmlContentUrl?e.jsxRuntimeExports.jsx(d.WhatsappLikePreview,{showHeader:h,containerPadding:"large"===b?"16px 56px 12px 16px":"12px 56px 12px 12px",containerStyle:x,textType:"html",bodyText:ie.whatsappOnlyFillVariablesValueInBodyText(null!==(G=null==le?void 0:le.bodyText)&&void 0!==G?G:"",null!==(J=null==le?void 0:le.bodyVariables)&&void 0!==J?J:[],m),footerText:null==le?void 0:le.footerText,headerMediaType:(null==le?void 0:le.headerType)||r.HEADER_TYPES.NONE,headerText:ie.fillVariablesValInBodyText(null!==(K=null==le?void 0:le.headerText)&&void 0!==K?K:"",null!==(Q=null==le?void 0:le.headerVariables)&&void 0!==Q?Q:[],m),headerAssetLink:null!==(X=null==le?void 0:le.headerAssetLink)&&void 0!==X?X:"",headerAssetName:null!==(Z=null==le?void 0:le.headerAssetName)&&void 0!==Z?Z:"",quickReplybtn:null==le?void 0:le.quickReply,ctaBtn:re,actionTypes:null==le?void 0:le.actionsType,extras:v,hidePreviewText:!0,imagePreviewStyles:{objectFit:"cover"},zeroStateComponent:null!=c?c:e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:" "}),isPreview:w}):e.jsxRuntimeExports.jsx(s.WhatsappLikePreviewV2,{showHeader:h,containerPadding:"large"===b?"16px 56px 12px 16px":"12px 56px 12px 12px",containerStyle:x,textType:"html",bodyText:null==le?void 0:le.bodyText,footerText:null==le?void 0:le.footerText,headerMediaType:(null==le?void 0:le.headerType)||r.HEADER_TYPES.NONE,headerText:null==le?void 0:le.headerText,headerAssetLink:null!==(M=null==le?void 0:le.headerAssetLink)&&void 0!==M?M:"",headerAssetName:null!==(D=null==le?void 0:le.headerAssetName)&&void 0!==D?D:"",quickReplybtn:null==le?void 0:le.quickReply,ctaBtn:re,actionTypes:null==le?void 0:le.actionsType,extras:v,hidePreviewText:!0,imagePreviewStyles:{objectFit:"cover"},carouselCardIndex:y,zeroStateComponent:null!=c?c:e.jsxRuntimeExports.jsx(e.jsxRuntimeExports.Fragment,{children:" "}),bodyVariableList:null!==(_=null===(U=null==le?void 0:le.bodyVariables)||void 0===U?void 0:U.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==_?_:[],headerVariableList:null!==(Y=null===(z=null==le?void 0:le.headerVariables)||void 0===z?void 0:z.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==Y?Y:[],buttons:null==le?void 0:le.allButtons,limitedTimeOfferComponent:null==le?void 0:le.limitedTimeOfferComponent,isWhatsappCarousel:j,isPreview:w,showCallPermissionCard:null==le?void 0:le.showCallPermissionCard,callPermissionText:null==le?void 0:le.callPermissionText})};
@@ -21,6 +21,7 @@ export declare class TemplateCreatorHelper {
21
21
  * 2. LTO component does not have a dateTime expiry by default. Hence, while sending template to ContextMapper, send with a date or current Date and Time is picked here.
22
22
  */
23
23
  private parseLimitedTimeOfferComponent;
24
+ private parseCallPermissionComponent;
24
25
  parseUITemplateFromDBFormat(data: {
25
26
  dbFormattedTemplate: WhatsAppTemplate;
26
27
  isDuplicate?: boolean;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),t=require("date-fns"),i=require("../../../constants/Theme.js"),n=require("../constants/regexPatterns.js"),l=require("../constants/TemplateConstants.js"),o=require("../models/TemplateMeta.js"),a=require("../models/WhatsAppTemplate.js"),d=require("../utils/TemplateHelperUtils.js");exports.TemplateCreatorHelper=class{parseDataFromHeaderComponent(e,t,i){var n,l,d,r,s,v,u,p,E,T;const c={headerType:o.HEADER_TYPES.NONE,headerVariables:[]},m=null===(n=null==e?void 0:e.components)||void 0===n?void 0:n.find((e=>"HEADER"===e.type));if(m){c.headerType=m.format,c.headerText=m.text,c.headerAssetLink=null===(d=null===(l=m.example)||void 0===l?void 0:l.header_handle)||void 0===d?void 0:d[0];const n=null===(s=null===(r=m.example)||void 0===r?void 0:r.header_text)||void 0===s?void 0:s[0],o=null===(u=null===(v=e.mapping)||void 0===v?void 0:v.header)||void 0===u?void 0:u[0],_=o;if(o){const e=null==o?void 0:o.replace("[[","").replace("]]","").replace("{{","").replace("}}","").replace("((","").replace("))",""),l=/\(\(/.test(o),d=i===a.POD.CHATBOT&&_&&(null==_?void 0:_.startsWith("(("))&&(null==_?void 0:_.endsWith("))")),r={idx:0,variableVal:t||d?n:_,editable:l,editableDefaultValues:l?void 0:n,variableName:e};c.headerVariables=[r],(null===(E=null===(p=m.example)||void 0===p?void 0:p.header_text)||void 0===E?void 0:E.length)&&(c.headerText=null===(T=c.headerText)||void 0===T?void 0:T.replace("{{1}}",`{{${e}}}`))}}return c}validateState(e){var t,i,a,r,s,v,u,p,E,T,c,m,_,h,b,R,y,I,L,C,N,O,B;const x=/\p{Extended_Pictographic}/u;let D="valid";const f={meta:{},ctaBtn:{phoneNumber:{btnText:"",link:""},websiteLink:{btnText:"",link:""}},quickReply:[null,null,null]},A=new d.TemplateHelperUtils;let P=!1;const S=e=>{var t;null===(t=document.getElementById(e))||void 0===t||t.scrollIntoView({behavior:"smooth",block:"nearest"})};if((null===(t=e.meta)||void 0===t?void 0:t.name)?(null===(i=e.meta.name)||void 0===i?void 0:i.trim().length)>l.NAME_LEN_LIMIT?(f.meta.name=l.NAME_LEN_ERROR,D="invalid"):n.specialCharPattern.test(null===(a=e.meta.name)||void 0===a?void 0:a.trim())&&(f.meta.name=l.NO_SPECIAL_CHAR,D="invalid"):(f.meta.name=l.REQUIRED_FIELD,D="invalid"),f.meta.name&&!P&&(S(l.CREATE_TEMPLATE_DOM_IDS.name),P=!0),e.headerType===o.HEADER_TYPES.TEXT){const t=null!==(s=null===(r=e.headerText)||void 0===r?void 0:r.trim())&&void 0!==s?s:"";if(t)if(t.length>l.HEADER_TEXT_LEN_LIMIT)f.header=l.HEADER_LEN_ERROR,D="invalid";else{const e=A.getTemplateVariablesFromState(t);e&&e.length>1&&(f.header=l.ONE_VAR_ALLOWED,D="invalid")}else f.header=l.REQUIRED_FIELD,D="invalid"}else e.headerType===o.HEADER_TYPES.DOCUMENT||e.headerType===o.HEADER_TYPES.IMAGE||(e.headerType,o.HEADER_TYPES.VIDEO);if(e.headerType!==o.HEADER_TYPES.DOCUMENT&&e.headerType!==o.HEADER_TYPES.IMAGE&&e.headerType!==o.HEADER_TYPES.VIDEO||e.headerAssetLink||(f.header=l.HEADER_ASSET_LINK_ERROR,D="invalid"),f.header&&!P&&(S(l.CREATE_TEMPLATE_DOM_IDS.header),P=!0),e.bodyText?e.bodyTextRaw&&(null===(v=e.bodyTextRaw)||void 0===v?void 0:v.trim().length)>l.BODY_TEXT_LEN_LIMIT&&(f.body=l.BODY_LEN_ERROR,D="invalid"):(f.body=l.REQUIRED_FIELD,D="invalid"),f.body&&!P&&(S(l.CREATE_TEMPLATE_DOM_IDS.body),P=!0),e.footerText&&e.footerText.length>l.HEADER_TEXT_LEN_LIMIT&&(f.footer=l.HEADER_LEN_ERROR,D="invalid"),(null==f?void 0:f.footer)&&!P&&(S(l.CREATE_TEMPLATE_DOM_IDS.footer),P=!0),e.actionsType===o.ACTIONS_TYPES.CTA_BTN){if(null===(p=null===(u=e.ctaBtn)||void 0===u?void 0:u.phoneNumber)||void 0===p?void 0:p.isChecked){const t=null===(E=e.ctaBtn.phoneNumber.btnText)||void 0===E?void 0:E.trim(),i=e.ctaBtn.phoneNumber.phoneNumber;f.ctaBtn&&!t?(f.ctaBtn.phoneNumber.btnText=l.REQUIRED_FIELD,D="invalid"):f.ctaBtn&&t&&t.length>l.QUICK_REPLY_BTN_TEXT_LIMIT?(f.ctaBtn.phoneNumber.btnText=l.QUICK_REPLY_LEN_ERROR,D="invalid"):f.ctaBtn&&t&&x.test(t)&&(f.ctaBtn.phoneNumber.btnText=l.BUTTON_EMOJI_ERROR,D="invalid"),f.ctaBtn&&!i?(f.ctaBtn.phoneNumber.link=l.REQUIRED_FIELD,D="invalid"):f.ctaBtn&&i&&i.length<10&&(f.ctaBtn.phoneNumber.link=l.VALID_PHONE_NUMBER,D="invalid")}if(null===(c=null===(T=e.ctaBtn)||void 0===T?void 0:T.websiteLinkBtn)||void 0===c?void 0:c.isChecked){const t=null===(m=e.ctaBtn.websiteLinkBtn.btnText)||void 0===m?void 0:m.trim(),i=null===(_=e.ctaBtn.websiteLinkBtn.linkOpens)||void 0===_?void 0:_.trim(),n=null===(h=e.ctaBtn.websiteLinkBtn.placeholder)||void 0===h?void 0:h.trim();f.ctaBtn&&!t?(f.ctaBtn.websiteLink.btnText=l.REQUIRED_FIELD,D="invalid"):f.ctaBtn&&t&&t.length>l.QUICK_REPLY_BTN_TEXT_LIMIT?(f.ctaBtn.websiteLink.btnText=l.QUICK_REPLY_LEN_ERROR,D="invalid"):f.ctaBtn&&t&&x.test(t)&&(f.ctaBtn.websiteLink.btnText=l.BUTTON_EMOJI_ERROR,D="invalid"),!f.ctaBtn||i||n||(f.ctaBtn.websiteLink.link=l.REQUIRED_FIELD,D="invalid")}}else if(e.actionsType===o.ACTIONS_TYPES.QUICK_REPLY){const t=["","",""];e.quickReply.forEach(((i,n)=>{var o;const a=null===(o=i.text)||void 0===o?void 0:o.trim();if(a)if(a.length>l.QUICK_REPLY_NAME_LEN_LIMIT)t[n]=l.QUICK_REPLY_LEN_ERROR,D="invalid";else if(x.test(a))t[n]=l.BUTTON_EMOJI_ERROR,D="invalid";else{const i=[...e.quickReply];i.splice(n,1);i.find((e=>e.text===a))&&(t[n]=l.QUICK_REPLY_NAME_ERROR,D="invalid")}else t[n]=l.REQUIRED_FIELD,D="invalid"})),f.quickReply=t}if(e.actionsType===o.ACTIONS_TYPES.CTA_BTN||e.actionsType===o.ACTIONS_TYPES.QUICK_REPLY){const e=null===(b=f.quickReply)||void 0===b?void 0:b.reduce(((e,t)=>e||!!t),!1);((null===(y=null===(R=null==f?void 0:f.ctaBtn)||void 0===R?void 0:R.websiteLink)||void 0===y?void 0:y.link)||(null===(L=null===(I=f.ctaBtn)||void 0===I?void 0:I.websiteLink)||void 0===L?void 0:L.btnText)||(null===(N=null===(C=f.ctaBtn)||void 0===C?void 0:C.phoneNumber)||void 0===N?void 0:N.link)||(null===(B=null===(O=f.ctaBtn)||void 0===O?void 0:O.phoneNumber)||void 0===B?void 0:B.btnText)||e)&&!P&&(S(l.CREATE_TEMPLATE_DOM_IDS.actionButtons),P=!0)}return{status:D,errors:f}}parseBodyComponent(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],l=arguments.length>2?arguments[2]:void 0,o=arguments.length>3?arguments[3]:void 0;var d,r,s,v,u,p;const E=[];let T="";const c=null===(d=e.components)||void 0===d?void 0:d.find((e=>"BODY"===e.type));return c&&(null===(v=null===(s=null===(r=c.example)||void 0===r?void 0:r.body_text)||void 0===s?void 0:s[0])||void 0===v||v.forEach(((t,i)=>{var d,r;let s=null===(r=null===(d=e.mapping)||void 0===d?void 0:d.body)||void 0===r?void 0:r[i];const v=s,u=s&&/\(\(/.test(s),p=null==s?void 0:s.match(n.placeHolderNamePattern);(null==p?void 0:p[2])&&(s=null==p?void 0:p[2]);const T=o===a.POD.CHATBOT&&v&&(null==v?void 0:v.startsWith("(("))&&(null==v?void 0:v.endsWith("))"));E.push({idx:i,variableVal:l||T?t:v,editable:!!u,editableDefaultValues:u?void 0:t,variableName:null!=s?s:""})})),T=e.htmlContentUrl?e.htmlContentUrl:(null===(u=c.text)||void 0===u?void 0:u.split(/\{\{[0-9]+\}\}/).length)?null===(p=c.text)||void 0===p?void 0:p.split(/\{\{[0-9]+\}\}/).map(((e,n)=>{if(null==E?void 0:E[n]){const l=E[n].variableName;return t?`${e}{{${l}}}`:`${e} <span> </span><span style="color: ${i.COLORS.content.brand}; text-decoration: underline;">{{${l}}}</span><span> </span>`}return e})).join(""):""),{bodyVariable:E,bodyText:T}}parseTitleComponent(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],l=arguments.length>2?arguments[2]:void 0;var o,a,d,r,s,v;const u=[];let p="";const E=null===(o=e.components)||void 0===o?void 0:o.find((e=>"TITLE"===e.type));return E&&(null===(r=null===(d=null===(a=E.example)||void 0===a?void 0:a.title_text)||void 0===d?void 0:d[0])||void 0===r||r.forEach(((t,i)=>{var o,a;let d=null===(a=null===(o=e.mapping)||void 0===o?void 0:o.body)||void 0===a?void 0:a[i];const r=d,s=d&&/\(\(/.test(d),v=null==d?void 0:d.match(n.placeHolderNamePattern);(null==v?void 0:v[2])&&(d=null==v?void 0:v[2]),u.push({idx:i,variableVal:l?t:r,editable:!!s,editableDefaultValues:s?void 0:t,variableName:null!=d?d:""})})),p=e.htmlContentUrl?e.htmlContentUrl:(null===(s=E.text)||void 0===s?void 0:s.split(/\{\{[0-9]+\}\}/).length)?null===(v=E.text)||void 0===v?void 0:v.split(/\{\{[0-9]+\}\}/).map(((e,n)=>{if(null==u?void 0:u[n]){const l=u[n].variableName;return t?`${e}{{${l}}}`:`${e} <span> </span><span style="color: ${i.COLORS.content.brand}; text-decoration: underline;">{{${l}}}</span><span> </span>`}return e})).join(""):""),{titleText:p,titleVariables:u}}parseFooterComponent(e){var t;const i=null===(t=e.components)||void 0===t?void 0:t.find((e=>"FOOTER"===e.type));return null==i?void 0:i.text}parseButtonComponent(e){var t,i,l,a,d,r,s;const v={actionsType:o.ACTIONS_TYPES.NONE,quickReply:[],ctaBtn:{phoneNumber:void 0,websiteLinkBtn:void 0},allButtons:[]},u=null===(t=e.components)||void 0===t?void 0:t.find((e=>"BUTTONS"===e.type));if(u&&(null===(i=null==u?void 0:u.buttons)||void 0===i?void 0:i.length)){const t="QUICK_REPLY"===(null===(l=null==u?void 0:u.buttons)||void 0===l?void 0:l[0].type)?o.ACTIONS_TYPES.QUICK_REPLY:o.ACTIONS_TYPES.CTA_BTN;if(v.actionsType=t,t===o.ACTIONS_TYPES.QUICK_REPLY){const e=null!==(d=null===(a=null==u?void 0:u.buttons)||void 0===a?void 0:a.map((e=>e)))&&void 0!==d?d:[];v.quickReply=e}else t===o.ACTIONS_TYPES.CTA_BTN&&(null===(r=null==u?void 0:u.buttons)||void 0===r||r.forEach((t=>{var i,l,o,a;if(t.phone_number&&(v.ctaBtn.phoneNumber={isChecked:!0,btnText:t.text,phoneNumber:t.phone_number}),t.url){const d=null!==(o=null===(l=null===(i=null==e?void 0:e.mapping)||void 0===i?void 0:i.buttons)||void 0===l?void 0:l[0])&&void 0!==o?o:void 0;let r=!1;d&&n.editableVarPattern.test(d)&&(r=!0),v.ctaBtn.websiteLinkBtn={isChecked:!0,btnText:t.text,linkOpens:r?null===(a=t.example)||void 0===a?void 0:a[0]:t.url,placeholder:r?void 0:d}}})));v.allButtons=null===(s=u.buttons)||void 0===s?void 0:s.map((e=>"COPY_CODE"===e.type?Object.assign(Object.assign({},e),{placeholder:Array.isArray(e.example)?e.example[0]:(null==e?void 0:e.example)||""}):e))}return v}parseLimitedTimeOfferComponent(e,i){const n={text:"",dateTime:"",code:""};return e.components.forEach((e=>{var l,o,a;if("limited_time_offer"===e.type){n.text=null!==(o=null===(l=e.limited_time_offer)||void 0===l?void 0:l.text)&&void 0!==o?o:"";const i=null===(a=e.example)||void 0===a?void 0:a.limited_time_offer;i&&i.startsWith("{{")&&i.endsWith("}}")?n.dateTime=i:n.dateTime=t.format(i?new Date(i):new Date,"MMM dd")}i.forEach((e=>{var t;"COPY_CODE"===e.type&&(n.code=null!==(t=e.placeholder)&&void 0!==t?t:"")}))})),n}parseUITemplateFromDBFormat(t){var i;return e.__awaiter(this,void 0,void 0,(function*(){const{dbFormattedTemplate:e,isDuplicate:n,isV2:l=!1,showSampleValues:o,pod:a}=t,{headerType:d,headerAssetLink:r,headerAssetName:s,headerText:v,headerVariables:u}=yield this.parseDataFromHeaderComponent(e,void 0,a),{bodyText:p,bodyVariable:E}=yield this.parseBodyComponent(e,l,o,a),{titleText:T,titleVariables:c}=yield this.parseTitleComponent(e,l,o),{actionsType:m,quickReply:_,ctaBtn:h,allButtons:b}=yield this.parseButtonComponent(e),R=this.parseLimitedTimeOfferComponent(e,b),y={quickReply:_,ctaBtn:h,allButtons:b,meta:{name:n?`${e.label} Copy`:e.label,category:null===(i=e.category)||void 0===i?void 0:i.toUpperCase(),subCategory:e.templateCategory,language:e.language,templateId:e.templateId},error:{header:void 0,body:void 0,footer:void 0,quickReply:void 0,meta:void 0,ctaBtn:void 0},actionsType:m,footerText:this.parseFooterComponent(e),bodyVariables:E,bodyText:p,headerType:d,headerAssetLink:r,headerAssetName:s,headerText:v,headerVariables:u,alreadyAsADraft:e.isDraft,mode:"edit",initialLoading:!1,limitedTimeOfferComponent:R,titleText:T,titleVariables:c},{errors:I}=this.validateState(y);return y.error=I,y}))}parseTemplateConfiguration(e){let t;const i=(null==e?void 0:e.content)||{};if("string"==typeof i)try{t=JSON.parse(i)}catch(e){console.error("Error parsing rcsTemplate component JSON:",e),t={orientation:"VERTICAL"}}else t=i;return Object.assign(Object.assign({},t),{templateType:null==e?void 0:e.templateType})}};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),t=require("date-fns"),i=require("../../../constants/Theme.js"),n=require("../constants/regexPatterns.js"),l=require("../constants/TemplateConstants.js"),o=require("../models/TemplateMeta.js"),a=require("../models/WhatsAppTemplate.js"),d=require("../utils/TemplateHelperUtils.js");exports.TemplateCreatorHelper=class{parseDataFromHeaderComponent(e,t,i){var n,l,d,r,s,v,u,p,E,T;const c={headerType:o.HEADER_TYPES.NONE,headerVariables:[]},m=null===(n=null==e?void 0:e.components)||void 0===n?void 0:n.find((e=>"HEADER"===e.type));if(m){c.headerType=m.format,c.headerText=m.text,c.headerAssetLink=null===(d=null===(l=m.example)||void 0===l?void 0:l.header_handle)||void 0===d?void 0:d[0];const n=null===(s=null===(r=m.example)||void 0===r?void 0:r.header_text)||void 0===s?void 0:s[0],o=null===(u=null===(v=e.mapping)||void 0===v?void 0:v.header)||void 0===u?void 0:u[0],_=o;if(o){const e=null==o?void 0:o.replace("[[","").replace("]]","").replace("{{","").replace("}}","").replace("((","").replace("))",""),l=/\(\(/.test(o),d=i===a.POD.CHATBOT&&_&&(null==_?void 0:_.startsWith("(("))&&(null==_?void 0:_.endsWith("))")),r={idx:0,variableVal:t||d?n:_,editable:l,editableDefaultValues:l?void 0:n,variableName:e};c.headerVariables=[r],(null===(E=null===(p=m.example)||void 0===p?void 0:p.header_text)||void 0===E?void 0:E.length)&&(c.headerText=null===(T=c.headerText)||void 0===T?void 0:T.replace("{{1}}",`{{${e}}}`))}}return c}validateState(e){var t,i,a,r,s,v,u,p,E,T,c,m,_,h,b,R,C,y,I,L,N,O,x;const B=/\p{Extended_Pictographic}/u;let f="valid";const A={meta:{},ctaBtn:{phoneNumber:{btnText:"",link:""},websiteLink:{btnText:"",link:""}},quickReply:[null,null,null]},D=new d.TemplateHelperUtils;let P=!1;const S=e=>{var t;null===(t=document.getElementById(e))||void 0===t||t.scrollIntoView({behavior:"smooth",block:"nearest"})};if((null===(t=e.meta)||void 0===t?void 0:t.name)?(null===(i=e.meta.name)||void 0===i?void 0:i.trim().length)>l.NAME_LEN_LIMIT?(A.meta.name=l.NAME_LEN_ERROR,f="invalid"):n.specialCharPattern.test(null===(a=e.meta.name)||void 0===a?void 0:a.trim())&&(A.meta.name=l.NO_SPECIAL_CHAR,f="invalid"):(A.meta.name=l.REQUIRED_FIELD,f="invalid"),A.meta.name&&!P&&(S(l.CREATE_TEMPLATE_DOM_IDS.name),P=!0),e.headerType===o.HEADER_TYPES.TEXT){const t=null!==(s=null===(r=e.headerText)||void 0===r?void 0:r.trim())&&void 0!==s?s:"";if(t)if(t.length>l.HEADER_TEXT_LEN_LIMIT)A.header=l.HEADER_LEN_ERROR,f="invalid";else{const e=D.getTemplateVariablesFromState(t);e&&e.length>1&&(A.header=l.ONE_VAR_ALLOWED,f="invalid")}else A.header=l.REQUIRED_FIELD,f="invalid"}else e.headerType===o.HEADER_TYPES.DOCUMENT||e.headerType===o.HEADER_TYPES.IMAGE||(e.headerType,o.HEADER_TYPES.VIDEO);if(e.headerType!==o.HEADER_TYPES.DOCUMENT&&e.headerType!==o.HEADER_TYPES.IMAGE&&e.headerType!==o.HEADER_TYPES.VIDEO||e.headerAssetLink||(A.header=l.HEADER_ASSET_LINK_ERROR,f="invalid"),A.header&&!P&&(S(l.CREATE_TEMPLATE_DOM_IDS.header),P=!0),e.bodyText?e.bodyTextRaw&&(null===(v=e.bodyTextRaw)||void 0===v?void 0:v.trim().length)>l.BODY_TEXT_LEN_LIMIT&&(A.body=l.BODY_LEN_ERROR,f="invalid"):(A.body=l.REQUIRED_FIELD,f="invalid"),A.body&&!P&&(S(l.CREATE_TEMPLATE_DOM_IDS.body),P=!0),e.footerText&&e.footerText.length>l.HEADER_TEXT_LEN_LIMIT&&(A.footer=l.HEADER_LEN_ERROR,f="invalid"),(null==A?void 0:A.footer)&&!P&&(S(l.CREATE_TEMPLATE_DOM_IDS.footer),P=!0),e.actionsType===o.ACTIONS_TYPES.CTA_BTN){if(null===(p=null===(u=e.ctaBtn)||void 0===u?void 0:u.phoneNumber)||void 0===p?void 0:p.isChecked){const t=null===(E=e.ctaBtn.phoneNumber.btnText)||void 0===E?void 0:E.trim(),i=e.ctaBtn.phoneNumber.phoneNumber;A.ctaBtn&&!t?(A.ctaBtn.phoneNumber.btnText=l.REQUIRED_FIELD,f="invalid"):A.ctaBtn&&t&&t.length>l.QUICK_REPLY_BTN_TEXT_LIMIT?(A.ctaBtn.phoneNumber.btnText=l.QUICK_REPLY_LEN_ERROR,f="invalid"):A.ctaBtn&&t&&B.test(t)&&(A.ctaBtn.phoneNumber.btnText=l.BUTTON_EMOJI_ERROR,f="invalid"),A.ctaBtn&&!i?(A.ctaBtn.phoneNumber.link=l.REQUIRED_FIELD,f="invalid"):A.ctaBtn&&i&&i.length<10&&(A.ctaBtn.phoneNumber.link=l.VALID_PHONE_NUMBER,f="invalid")}if(null===(c=null===(T=e.ctaBtn)||void 0===T?void 0:T.websiteLinkBtn)||void 0===c?void 0:c.isChecked){const t=null===(m=e.ctaBtn.websiteLinkBtn.btnText)||void 0===m?void 0:m.trim(),i=null===(_=e.ctaBtn.websiteLinkBtn.linkOpens)||void 0===_?void 0:_.trim(),n=null===(h=e.ctaBtn.websiteLinkBtn.placeholder)||void 0===h?void 0:h.trim();A.ctaBtn&&!t?(A.ctaBtn.websiteLink.btnText=l.REQUIRED_FIELD,f="invalid"):A.ctaBtn&&t&&t.length>l.QUICK_REPLY_BTN_TEXT_LIMIT?(A.ctaBtn.websiteLink.btnText=l.QUICK_REPLY_LEN_ERROR,f="invalid"):A.ctaBtn&&t&&B.test(t)&&(A.ctaBtn.websiteLink.btnText=l.BUTTON_EMOJI_ERROR,f="invalid"),!A.ctaBtn||i||n||(A.ctaBtn.websiteLink.link=l.REQUIRED_FIELD,f="invalid")}}else if(e.actionsType===o.ACTIONS_TYPES.QUICK_REPLY){const t=["","",""];e.quickReply.forEach(((i,n)=>{var o;const a=null===(o=i.text)||void 0===o?void 0:o.trim();if(a)if(a.length>l.QUICK_REPLY_NAME_LEN_LIMIT)t[n]=l.QUICK_REPLY_LEN_ERROR,f="invalid";else if(B.test(a))t[n]=l.BUTTON_EMOJI_ERROR,f="invalid";else{const i=[...e.quickReply];i.splice(n,1);i.find((e=>e.text===a))&&(t[n]=l.QUICK_REPLY_NAME_ERROR,f="invalid")}else t[n]=l.REQUIRED_FIELD,f="invalid"})),A.quickReply=t}if(e.actionsType===o.ACTIONS_TYPES.CTA_BTN||e.actionsType===o.ACTIONS_TYPES.QUICK_REPLY){const e=null===(b=A.quickReply)||void 0===b?void 0:b.reduce(((e,t)=>e||!!t),!1);((null===(C=null===(R=null==A?void 0:A.ctaBtn)||void 0===R?void 0:R.websiteLink)||void 0===C?void 0:C.link)||(null===(I=null===(y=A.ctaBtn)||void 0===y?void 0:y.websiteLink)||void 0===I?void 0:I.btnText)||(null===(N=null===(L=A.ctaBtn)||void 0===L?void 0:L.phoneNumber)||void 0===N?void 0:N.link)||(null===(x=null===(O=A.ctaBtn)||void 0===O?void 0:O.phoneNumber)||void 0===x?void 0:x.btnText)||e)&&!P&&(S(l.CREATE_TEMPLATE_DOM_IDS.actionButtons),P=!0)}return{status:f,errors:A}}parseBodyComponent(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],l=arguments.length>2?arguments[2]:void 0,o=arguments.length>3?arguments[3]:void 0;var d,r,s,v,u,p;const E=[];let T="";const c=null===(d=e.components)||void 0===d?void 0:d.find((e=>"BODY"===e.type));return c&&(null===(v=null===(s=null===(r=c.example)||void 0===r?void 0:r.body_text)||void 0===s?void 0:s[0])||void 0===v||v.forEach(((t,i)=>{var d,r;let s=null===(r=null===(d=e.mapping)||void 0===d?void 0:d.body)||void 0===r?void 0:r[i];const v=s,u=s&&/\(\(/.test(s),p=null==s?void 0:s.match(n.placeHolderNamePattern);(null==p?void 0:p[2])&&(s=null==p?void 0:p[2]);const T=o===a.POD.CHATBOT&&v&&(null==v?void 0:v.startsWith("(("))&&(null==v?void 0:v.endsWith("))"));E.push({idx:i,variableVal:l||T?t:v,editable:!!u,editableDefaultValues:u?void 0:t,variableName:null!=s?s:""})})),T=e.htmlContentUrl?e.htmlContentUrl:(null===(u=c.text)||void 0===u?void 0:u.split(/\{\{[0-9]+\}\}/).length)?null===(p=c.text)||void 0===p?void 0:p.split(/\{\{[0-9]+\}\}/).map(((e,n)=>{if(null==E?void 0:E[n]){const l=E[n].variableName;return t?`${e}{{${l}}}`:`${e} <span> </span><span style="color: ${i.COLORS.content.brand}; text-decoration: underline;">{{${l}}}</span><span> </span>`}return e})).join(""):""),{bodyVariable:E,bodyText:T}}parseTitleComponent(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],l=arguments.length>2?arguments[2]:void 0;var o,a,d,r,s,v;const u=[];let p="";const E=null===(o=e.components)||void 0===o?void 0:o.find((e=>"TITLE"===e.type));return E&&(null===(r=null===(d=null===(a=E.example)||void 0===a?void 0:a.title_text)||void 0===d?void 0:d[0])||void 0===r||r.forEach(((t,i)=>{var o,a;let d=null===(a=null===(o=e.mapping)||void 0===o?void 0:o.body)||void 0===a?void 0:a[i];const r=d,s=d&&/\(\(/.test(d),v=null==d?void 0:d.match(n.placeHolderNamePattern);(null==v?void 0:v[2])&&(d=null==v?void 0:v[2]),u.push({idx:i,variableVal:l?t:r,editable:!!s,editableDefaultValues:s?void 0:t,variableName:null!=d?d:""})})),p=e.htmlContentUrl?e.htmlContentUrl:(null===(s=E.text)||void 0===s?void 0:s.split(/\{\{[0-9]+\}\}/).length)?null===(v=E.text)||void 0===v?void 0:v.split(/\{\{[0-9]+\}\}/).map(((e,n)=>{if(null==u?void 0:u[n]){const l=u[n].variableName;return t?`${e}{{${l}}}`:`${e} <span> </span><span style="color: ${i.COLORS.content.brand}; text-decoration: underline;">{{${l}}}</span><span> </span>`}return e})).join(""):""),{titleText:p,titleVariables:u}}parseFooterComponent(e){var t;const i=null===(t=e.components)||void 0===t?void 0:t.find((e=>"FOOTER"===e.type));return null==i?void 0:i.text}parseButtonComponent(e){var t,i,l,a,d,r,s;const v={actionsType:o.ACTIONS_TYPES.NONE,quickReply:[],ctaBtn:{phoneNumber:void 0,websiteLinkBtn:void 0},allButtons:[]},u=null===(t=e.components)||void 0===t?void 0:t.find((e=>"BUTTONS"===e.type));if(u&&(null===(i=null==u?void 0:u.buttons)||void 0===i?void 0:i.length)){const t="QUICK_REPLY"===(null===(l=null==u?void 0:u.buttons)||void 0===l?void 0:l[0].type)?o.ACTIONS_TYPES.QUICK_REPLY:o.ACTIONS_TYPES.CTA_BTN;if(v.actionsType=t,t===o.ACTIONS_TYPES.QUICK_REPLY){const e=null!==(d=null===(a=null==u?void 0:u.buttons)||void 0===a?void 0:a.map((e=>e)))&&void 0!==d?d:[];v.quickReply=e}else t===o.ACTIONS_TYPES.CTA_BTN&&(null===(r=null==u?void 0:u.buttons)||void 0===r||r.forEach((t=>{var i,l,o,a;if(t.phone_number&&(v.ctaBtn.phoneNumber={isChecked:!0,btnText:t.text,phoneNumber:t.phone_number}),t.url){const d=null!==(o=null===(l=null===(i=null==e?void 0:e.mapping)||void 0===i?void 0:i.buttons)||void 0===l?void 0:l[0])&&void 0!==o?o:void 0;let r=!1;d&&n.editableVarPattern.test(d)&&(r=!0),v.ctaBtn.websiteLinkBtn={isChecked:!0,btnText:t.text,linkOpens:r?null===(a=t.example)||void 0===a?void 0:a[0]:t.url,placeholder:r?void 0:d}}})));v.allButtons=null===(s=u.buttons)||void 0===s?void 0:s.map((e=>"COPY_CODE"===e.type?Object.assign(Object.assign({},e),{placeholder:Array.isArray(e.example)?e.example[0]:(null==e?void 0:e.example)||""}):e))}return v}parseLimitedTimeOfferComponent(e,i){const n={text:"",dateTime:"",code:""};return e.components.forEach((e=>{var l,o,a;if("limited_time_offer"===e.type){n.text=null!==(o=null===(l=e.limited_time_offer)||void 0===l?void 0:l.text)&&void 0!==o?o:"";const i=null===(a=e.example)||void 0===a?void 0:a.limited_time_offer;i&&i.startsWith("{{")&&i.endsWith("}}")?n.dateTime=i:n.dateTime=t.format(i?new Date(i):new Date,"MMM dd")}i.forEach((e=>{var t;"COPY_CODE"===e.type&&(n.code=null!==(t=e.placeholder)&&void 0!==t?t:"")}))})),n}parseCallPermissionComponent(e){var t;const i=null===(t=e.components)||void 0===t?void 0:t.find((e=>"CALL_PERMISSION_REQUEST"===e.type));return{showCallPermissionCard:Boolean(i),callPermissionText:null==i?void 0:i.text}}parseUITemplateFromDBFormat(t){var i;return e.__awaiter(this,void 0,void 0,(function*(){const{dbFormattedTemplate:e,isDuplicate:n,isV2:l=!1,showSampleValues:o,pod:a}=t,{headerType:d,headerAssetLink:r,headerAssetName:s,headerText:v,headerVariables:u}=yield this.parseDataFromHeaderComponent(e,void 0,a),{bodyText:p,bodyVariable:E}=yield this.parseBodyComponent(e,l,o,a),{titleText:T,titleVariables:c}=yield this.parseTitleComponent(e,l,o),{actionsType:m,quickReply:_,ctaBtn:h,allButtons:b}=yield this.parseButtonComponent(e),R=this.parseLimitedTimeOfferComponent(e,b),{showCallPermissionCard:C,callPermissionText:y}=this.parseCallPermissionComponent(e),I={quickReply:_,ctaBtn:h,allButtons:b,meta:{name:n?`${e.label} Copy`:e.label,category:null===(i=e.category)||void 0===i?void 0:i.toUpperCase(),subCategory:e.templateCategory,language:e.language,templateId:e.templateId},error:{header:void 0,body:void 0,footer:void 0,quickReply:void 0,meta:void 0,ctaBtn:void 0},actionsType:m,footerText:this.parseFooterComponent(e),bodyVariables:E,bodyText:p,headerType:d,headerAssetLink:r,headerAssetName:s,headerText:v,headerVariables:u,alreadyAsADraft:e.isDraft,mode:"edit",initialLoading:!1,limitedTimeOfferComponent:R,titleText:T,titleVariables:c,showCallPermissionCard:C,callPermissionText:y},{errors:L}=this.validateState(I);return I.error=L,I}))}parseTemplateConfiguration(e){let t;const i=(null==e?void 0:e.content)||{};if("string"==typeof i)try{t=JSON.parse(i)}catch(e){console.error("Error parsing rcsTemplate component JSON:",e),t={orientation:"VERTICAL"}}else t=i;return Object.assign(Object.assign({},t),{templateType:null==e?void 0:e.templateType})}};
@@ -104,6 +104,8 @@ export type CreateTemplateType = {
104
104
  dateTime: string;
105
105
  code: string;
106
106
  };
107
+ showCallPermissionCard?: boolean;
108
+ callPermissionText?: string;
107
109
  error: {
108
110
  modalError?: string;
109
111
  header?: string;
@@ -10,7 +10,7 @@ export type WhatsAppCarouselTemplate = {
10
10
  templateCategory: string;
11
11
  type?: 'email' | 'whatsapp';
12
12
  components: {
13
- type: 'BODY' | 'CAROUSEL' | 'CALL_PERMISSION';
13
+ type: 'BODY' | 'CAROUSEL' | 'CALL_PERMISSION_REQUEST';
14
14
  format?: HEADER_TYPES;
15
15
  text?: string;
16
16
  example?: {
@@ -1 +1 @@
1
- import{j as e}from"../../node_modules/react/jsx-runtime.js";import{useState as l,useEffect as a}from"react";import{useTemplateModalContext as t}from"../template-context-mapper/context/templateModalContext.js";import{TemplateCreatorHelper as i}from"./helpers/TemplateCreatorHelper.js";import{isRCSChannel as o}from"./helpers/templateMiscHelper.js";import{HEADER_TYPES as r}from"./models/TemplateMeta.js";import{RCSTemplateLikePreview as n}from"./RCS/RCSTemplateLikePreview.js";import{TemplateHelperUtils as d}from"./utils/TemplateHelperUtils.js";import{WhatsappLikePreview as s}from"./WhatsApp/WhatsAppLikePreview.js";import{WhatsappLikePreviewV2 as p}from"./WhatsApp/WhatsAppLikePreviewV2.js";const u=u=>{let{template:v,extras:m,containerStyle:h,usePlaceHolderName:x,showHeader:c,zeroStateComponent:b,size:T,showSampleValues:y,carouselCardIndex:w,isWhatsappCarousel:C,isPreview:N,channel:V}=u;var f,j,k,P,B,L,g,A,S,F,O,H,I,R,W,q,M,U,z,D,E,_,G,J,K,Q,X,Y,Z,$;const{selectedCarouselIndex:ee,pod:le}=t(),[ae,te]=l(),ie=new i,oe=new d,re=[];if((null===(j=null===(f=null==ae?void 0:ae.ctaBtn)||void 0===f?void 0:f.phoneNumber)||void 0===j?void 0:j.isChecked)&&re.push({type:"phoneNumber",text:null!==(k=ae.ctaBtn.phoneNumber.btnText)&&void 0!==k?k:"",extra:null!==(P=ae.ctaBtn.phoneNumber.phoneNumber)&&void 0!==P?P:""}),(null===(L=null===(B=null==ae?void 0:ae.ctaBtn)||void 0===B?void 0:B.websiteLinkBtn)||void 0===L?void 0:L.isChecked)&&re.push({type:"website",text:null!==(g=ae.ctaBtn.websiteLinkBtn.btnText)&&void 0!==g?g:"",extra:null!==(S=null===(A=ae.ctaBtn.websiteLinkBtn)||void 0===A?void 0:A.linkOpens)&&void 0!==S?S:"",placeholder:null!==(F=ae.ctaBtn.websiteLinkBtn.placeholder)&&void 0!==F?F:""}),a((()=>{v&&ie.parseUITemplateFromDBFormat({dbFormattedTemplate:v,isDuplicate:!1,showSampleValues:y,isV2:!v.htmlContentUrl,pod:le}).then((e=>{te(Object.assign({},e))}))}),[v,y]),a((()=>{v&&ie.parseUITemplateFromDBFormat({dbFormattedTemplate:v,isDuplicate:!1,showSampleValues:y,isV2:!v.htmlContentUrl,pod:le}).then((e=>{te(Object.assign({},e))}))}),[ee]),!v)return e.jsx(e.Fragment,{children:b});if(o(V||(null==v?void 0:v.channel))){const l=ie.parseTemplateConfiguration(v);return e.jsx(n,{showHeader:c,containerPadding:"large"===T?"16px 36px 12px 16px":"12px 36px 12px 12px",containerStyle:h,textType:"html",bodyText:null==ae?void 0:ae.bodyText,titleText:null==ae?void 0:ae.titleText,footerText:null==ae?void 0:ae.footerText,headerMediaType:(null==ae?void 0:ae.headerType)||r.NONE,headerText:null==ae?void 0:ae.headerText,headerAssetLink:null!==(O=null==ae?void 0:ae.headerAssetLink)&&void 0!==O?O:"",headerAssetName:null!==(H=null==ae?void 0:ae.headerAssetName)&&void 0!==H?H:"",quickReplybtn:null==ae?void 0:ae.quickReply,ctaBtn:re,actionTypes:null==ae?void 0:ae.actionsType,extras:m,hidePreviewText:!0,imagePreviewStyles:{objectFit:"cover"},carouselCardIndex:w,zeroStateComponent:null!=b?b:e.jsx(e.Fragment,{children:" "}),bodyVariableList:null!==(R=null===(I=null==ae?void 0:ae.bodyVariables)||void 0===I?void 0:I.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==R?R:[],headerVariableList:null!==(q=null===(W=null==ae?void 0:ae.headerVariables)||void 0===W?void 0:W.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==q?q:[],titleVariableList:null!==(U=null===(M=null==ae?void 0:ae.titleVariables)||void 0===M?void 0:M.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==U?U:[],buttons:null==ae?void 0:ae.allButtons,isWhatsappCarousel:C,isPreview:N,templateConfiguration:l})}return v.htmlContentUrl?e.jsx(s,{showHeader:c,containerPadding:"large"===T?"16px 56px 12px 16px":"12px 56px 12px 12px",containerStyle:h,textType:"html",bodyText:oe.whatsappOnlyFillVariablesValueInBodyText(null!==(K=null==ae?void 0:ae.bodyText)&&void 0!==K?K:"",null!==(Q=null==ae?void 0:ae.bodyVariables)&&void 0!==Q?Q:[],x),footerText:null==ae?void 0:ae.footerText,headerMediaType:(null==ae?void 0:ae.headerType)||r.NONE,headerText:oe.fillVariablesValInBodyText(null!==(X=null==ae?void 0:ae.headerText)&&void 0!==X?X:"",null!==(Y=null==ae?void 0:ae.headerVariables)&&void 0!==Y?Y:[],x),headerAssetLink:null!==(Z=null==ae?void 0:ae.headerAssetLink)&&void 0!==Z?Z:"",headerAssetName:null!==($=null==ae?void 0:ae.headerAssetName)&&void 0!==$?$:"",quickReplybtn:null==ae?void 0:ae.quickReply,ctaBtn:re,actionTypes:null==ae?void 0:ae.actionsType,extras:m,hidePreviewText:!0,imagePreviewStyles:{objectFit:"cover"},zeroStateComponent:null!=b?b:e.jsx(e.Fragment,{children:" "}),isPreview:N}):e.jsx(p,{showHeader:c,containerPadding:"large"===T?"16px 56px 12px 16px":"12px 56px 12px 12px",containerStyle:h,textType:"html",bodyText:null==ae?void 0:ae.bodyText,footerText:null==ae?void 0:ae.footerText,headerMediaType:(null==ae?void 0:ae.headerType)||r.NONE,headerText:null==ae?void 0:ae.headerText,headerAssetLink:null!==(z=null==ae?void 0:ae.headerAssetLink)&&void 0!==z?z:"",headerAssetName:null!==(D=null==ae?void 0:ae.headerAssetName)&&void 0!==D?D:"",quickReplybtn:null==ae?void 0:ae.quickReply,ctaBtn:re,actionTypes:null==ae?void 0:ae.actionsType,extras:m,hidePreviewText:!0,imagePreviewStyles:{objectFit:"cover"},carouselCardIndex:w,zeroStateComponent:null!=b?b:e.jsx(e.Fragment,{children:" "}),bodyVariableList:null!==(_=null===(E=null==ae?void 0:ae.bodyVariables)||void 0===E?void 0:E.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==_?_:[],headerVariableList:null!==(J=null===(G=null==ae?void 0:ae.headerVariables)||void 0===G?void 0:G.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==J?J:[],buttons:null==ae?void 0:ae.allButtons,limitedTimeOfferComponent:null==ae?void 0:ae.limitedTimeOfferComponent,isWhatsappCarousel:C,isPreview:N,showCallPermissionCard:null==v?void 0:v.showCallPermissionCard,callPermissionText:null==v?void 0:v.callPermissionText})};export{u as default};
1
+ import{j as e}from"../../node_modules/react/jsx-runtime.js";import{useState as l,useEffect as a}from"react";import{useTemplateModalContext as t}from"../template-context-mapper/context/templateModalContext.js";import{TemplateCreatorHelper as i}from"./helpers/TemplateCreatorHelper.js";import{isRCSChannel as o}from"./helpers/templateMiscHelper.js";import{HEADER_TYPES as r}from"./models/TemplateMeta.js";import{RCSTemplateLikePreview as n}from"./RCS/RCSTemplateLikePreview.js";import{TemplateHelperUtils as d}from"./utils/TemplateHelperUtils.js";import{WhatsappLikePreview as s}from"./WhatsApp/WhatsAppLikePreview.js";import{WhatsappLikePreviewV2 as p}from"./WhatsApp/WhatsAppLikePreviewV2.js";const u=u=>{let{template:v,extras:m,containerStyle:h,usePlaceHolderName:x,showHeader:c,zeroStateComponent:b,size:T,showSampleValues:y,carouselCardIndex:w,isWhatsappCarousel:C,isPreview:N,channel:V}=u;var f,j,k,P,B,L,g,A,S,F,O,H,I,R,W,q,M,U,z,D,E,_,G,J,K,Q,X,Y,Z,$;const{selectedCarouselIndex:ee,pod:le}=t(),[ae,te]=l(),ie=new i,oe=new d,re=[];if((null===(j=null===(f=null==ae?void 0:ae.ctaBtn)||void 0===f?void 0:f.phoneNumber)||void 0===j?void 0:j.isChecked)&&re.push({type:"phoneNumber",text:null!==(k=ae.ctaBtn.phoneNumber.btnText)&&void 0!==k?k:"",extra:null!==(P=ae.ctaBtn.phoneNumber.phoneNumber)&&void 0!==P?P:""}),(null===(L=null===(B=null==ae?void 0:ae.ctaBtn)||void 0===B?void 0:B.websiteLinkBtn)||void 0===L?void 0:L.isChecked)&&re.push({type:"website",text:null!==(g=ae.ctaBtn.websiteLinkBtn.btnText)&&void 0!==g?g:"",extra:null!==(S=null===(A=ae.ctaBtn.websiteLinkBtn)||void 0===A?void 0:A.linkOpens)&&void 0!==S?S:"",placeholder:null!==(F=ae.ctaBtn.websiteLinkBtn.placeholder)&&void 0!==F?F:""}),a((()=>{v&&ie.parseUITemplateFromDBFormat({dbFormattedTemplate:v,isDuplicate:!1,showSampleValues:y,isV2:!v.htmlContentUrl,pod:le}).then((e=>{te(Object.assign({},e))}))}),[v,y]),a((()=>{v&&ie.parseUITemplateFromDBFormat({dbFormattedTemplate:v,isDuplicate:!1,showSampleValues:y,isV2:!v.htmlContentUrl,pod:le}).then((e=>{te(Object.assign({},e))}))}),[ee]),!v)return e.jsx(e.Fragment,{children:b});if(o(V||(null==v?void 0:v.channel))){const l=ie.parseTemplateConfiguration(v);return e.jsx(n,{showHeader:c,containerPadding:"large"===T?"16px 36px 12px 16px":"12px 36px 12px 12px",containerStyle:h,textType:"html",bodyText:null==ae?void 0:ae.bodyText,titleText:null==ae?void 0:ae.titleText,footerText:null==ae?void 0:ae.footerText,headerMediaType:(null==ae?void 0:ae.headerType)||r.NONE,headerText:null==ae?void 0:ae.headerText,headerAssetLink:null!==(O=null==ae?void 0:ae.headerAssetLink)&&void 0!==O?O:"",headerAssetName:null!==(H=null==ae?void 0:ae.headerAssetName)&&void 0!==H?H:"",quickReplybtn:null==ae?void 0:ae.quickReply,ctaBtn:re,actionTypes:null==ae?void 0:ae.actionsType,extras:m,hidePreviewText:!0,imagePreviewStyles:{objectFit:"cover"},carouselCardIndex:w,zeroStateComponent:null!=b?b:e.jsx(e.Fragment,{children:" "}),bodyVariableList:null!==(R=null===(I=null==ae?void 0:ae.bodyVariables)||void 0===I?void 0:I.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==R?R:[],headerVariableList:null!==(q=null===(W=null==ae?void 0:ae.headerVariables)||void 0===W?void 0:W.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==q?q:[],titleVariableList:null!==(U=null===(M=null==ae?void 0:ae.titleVariables)||void 0===M?void 0:M.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==U?U:[],buttons:null==ae?void 0:ae.allButtons,isWhatsappCarousel:C,isPreview:N,templateConfiguration:l})}return v.htmlContentUrl?e.jsx(s,{showHeader:c,containerPadding:"large"===T?"16px 56px 12px 16px":"12px 56px 12px 12px",containerStyle:h,textType:"html",bodyText:oe.whatsappOnlyFillVariablesValueInBodyText(null!==(K=null==ae?void 0:ae.bodyText)&&void 0!==K?K:"",null!==(Q=null==ae?void 0:ae.bodyVariables)&&void 0!==Q?Q:[],x),footerText:null==ae?void 0:ae.footerText,headerMediaType:(null==ae?void 0:ae.headerType)||r.NONE,headerText:oe.fillVariablesValInBodyText(null!==(X=null==ae?void 0:ae.headerText)&&void 0!==X?X:"",null!==(Y=null==ae?void 0:ae.headerVariables)&&void 0!==Y?Y:[],x),headerAssetLink:null!==(Z=null==ae?void 0:ae.headerAssetLink)&&void 0!==Z?Z:"",headerAssetName:null!==($=null==ae?void 0:ae.headerAssetName)&&void 0!==$?$:"",quickReplybtn:null==ae?void 0:ae.quickReply,ctaBtn:re,actionTypes:null==ae?void 0:ae.actionsType,extras:m,hidePreviewText:!0,imagePreviewStyles:{objectFit:"cover"},zeroStateComponent:null!=b?b:e.jsx(e.Fragment,{children:" "}),isPreview:N}):e.jsx(p,{showHeader:c,containerPadding:"large"===T?"16px 56px 12px 16px":"12px 56px 12px 12px",containerStyle:h,textType:"html",bodyText:null==ae?void 0:ae.bodyText,footerText:null==ae?void 0:ae.footerText,headerMediaType:(null==ae?void 0:ae.headerType)||r.NONE,headerText:null==ae?void 0:ae.headerText,headerAssetLink:null!==(z=null==ae?void 0:ae.headerAssetLink)&&void 0!==z?z:"",headerAssetName:null!==(D=null==ae?void 0:ae.headerAssetName)&&void 0!==D?D:"",quickReplybtn:null==ae?void 0:ae.quickReply,ctaBtn:re,actionTypes:null==ae?void 0:ae.actionsType,extras:m,hidePreviewText:!0,imagePreviewStyles:{objectFit:"cover"},carouselCardIndex:w,zeroStateComponent:null!=b?b:e.jsx(e.Fragment,{children:" "}),bodyVariableList:null!==(_=null===(E=null==ae?void 0:ae.bodyVariables)||void 0===E?void 0:E.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==_?_:[],headerVariableList:null!==(J=null===(G=null==ae?void 0:ae.headerVariables)||void 0===G?void 0:G.map((e=>{var l;return{placeholder:e.variableName,value:null!==(l=e.variableVal)&&void 0!==l?l:e.variableName}})))&&void 0!==J?J:[],buttons:null==ae?void 0:ae.allButtons,limitedTimeOfferComponent:null==ae?void 0:ae.limitedTimeOfferComponent,isWhatsappCarousel:C,isPreview:N,showCallPermissionCard:null==ae?void 0:ae.showCallPermissionCard,callPermissionText:null==ae?void 0:ae.callPermissionText})};export{u as default};
@@ -21,6 +21,7 @@ export declare class TemplateCreatorHelper {
21
21
  * 2. LTO component does not have a dateTime expiry by default. Hence, while sending template to ContextMapper, send with a date or current Date and Time is picked here.
22
22
  */
23
23
  private parseLimitedTimeOfferComponent;
24
+ private parseCallPermissionComponent;
24
25
  parseUITemplateFromDBFormat(data: {
25
26
  dbFormattedTemplate: WhatsAppTemplate;
26
27
  isDuplicate?: boolean;
@@ -1 +1 @@
1
- import{__awaiter as e}from"../../../_virtual/_tslib.js";import{format as t}from"date-fns";import{COLORS as i}from"../../../constants/Theme.js";import{specialCharPattern as n,placeHolderNamePattern as l,editableVarPattern as o}from"../constants/regexPatterns.js";import{REQUIRED_FIELD as a,NAME_LEN_LIMIT as d,NAME_LEN_ERROR as r,NO_SPECIAL_CHAR as s,HEADER_TEXT_LEN_LIMIT as v,HEADER_LEN_ERROR as p,ONE_VAR_ALLOWED as u,HEADER_ASSET_LINK_ERROR as m,BODY_TEXT_LEN_LIMIT as c,BODY_LEN_ERROR as h,QUICK_REPLY_BTN_TEXT_LIMIT as b,QUICK_REPLY_LEN_ERROR as T,BUTTON_EMOJI_ERROR as y,VALID_PHONE_NUMBER as f,QUICK_REPLY_NAME_LEN_LIMIT as x,CREATE_TEMPLATE_DOM_IDS as B,QUICK_REPLY_NAME_ERROR as C}from"../constants/TemplateConstants.js";import{HEADER_TYPES as g,ACTIONS_TYPES as k}from"../models/TemplateMeta.js";import{POD as N}from"../models/WhatsAppTemplate.js";import{TemplateHelperUtils as E}from"../utils/TemplateHelperUtils.js";class L{parseDataFromHeaderComponent(e,t,i){var n,l,o,a,d,r,s,v,p,u;const m={headerType:g.NONE,headerVariables:[]},c=null===(n=null==e?void 0:e.components)||void 0===n?void 0:n.find((e=>"HEADER"===e.type));if(c){m.headerType=c.format,m.headerText=c.text,m.headerAssetLink=null===(o=null===(l=c.example)||void 0===l?void 0:l.header_handle)||void 0===o?void 0:o[0];const n=null===(d=null===(a=c.example)||void 0===a?void 0:a.header_text)||void 0===d?void 0:d[0],h=null===(s=null===(r=e.mapping)||void 0===r?void 0:r.header)||void 0===s?void 0:s[0],b=h;if(h){const e=null==h?void 0:h.replace("[[","").replace("]]","").replace("{{","").replace("}}","").replace("((","").replace("))",""),l=/\(\(/.test(h),o=i===N.CHATBOT&&b&&(null==b?void 0:b.startsWith("(("))&&(null==b?void 0:b.endsWith("))")),a={idx:0,variableVal:t||o?n:b,editable:l,editableDefaultValues:l?void 0:n,variableName:e};m.headerVariables=[a],(null===(p=null===(v=c.example)||void 0===v?void 0:v.header_text)||void 0===p?void 0:p.length)&&(m.headerText=null===(u=m.headerText)||void 0===u?void 0:u.replace("{{1}}",`{{${e}}}`))}}return m}validateState(e){var t,i,l,o,N,L,O,_,V,A,w,R,D,I,U,j,$,q,F,P,M,Y,S;const W=/\p{Extended_Pictographic}/u;let H="valid";const K={meta:{},ctaBtn:{phoneNumber:{btnText:"",link:""},websiteLink:{btnText:"",link:""}},quickReply:[null,null,null]},Q=new E;let G=!1;const J=e=>{var t;null===(t=document.getElementById(e))||void 0===t||t.scrollIntoView({behavior:"smooth",block:"nearest"})};if((null===(t=e.meta)||void 0===t?void 0:t.name)?(null===(i=e.meta.name)||void 0===i?void 0:i.trim().length)>d?(K.meta.name=r,H="invalid"):n.test(null===(l=e.meta.name)||void 0===l?void 0:l.trim())&&(K.meta.name=s,H="invalid"):(K.meta.name=a,H="invalid"),K.meta.name&&!G&&(J(B.name),G=!0),e.headerType===g.TEXT){const t=null!==(N=null===(o=e.headerText)||void 0===o?void 0:o.trim())&&void 0!==N?N:"";if(t)if(t.length>v)K.header=p,H="invalid";else{const e=Q.getTemplateVariablesFromState(t);e&&e.length>1&&(K.header=u,H="invalid")}else K.header=a,H="invalid"}else e.headerType===g.DOCUMENT||e.headerType===g.IMAGE||(e.headerType,g.VIDEO);if(e.headerType!==g.DOCUMENT&&e.headerType!==g.IMAGE&&e.headerType!==g.VIDEO||e.headerAssetLink||(K.header=m,H="invalid"),K.header&&!G&&(J(B.header),G=!0),e.bodyText?e.bodyTextRaw&&(null===(L=e.bodyTextRaw)||void 0===L?void 0:L.trim().length)>c&&(K.body=h,H="invalid"):(K.body=a,H="invalid"),K.body&&!G&&(J(B.body),G=!0),e.footerText&&e.footerText.length>v&&(K.footer=p,H="invalid"),(null==K?void 0:K.footer)&&!G&&(J(B.footer),G=!0),e.actionsType===k.CTA_BTN){if(null===(_=null===(O=e.ctaBtn)||void 0===O?void 0:O.phoneNumber)||void 0===_?void 0:_.isChecked){const t=null===(V=e.ctaBtn.phoneNumber.btnText)||void 0===V?void 0:V.trim(),i=e.ctaBtn.phoneNumber.phoneNumber;K.ctaBtn&&!t?(K.ctaBtn.phoneNumber.btnText=a,H="invalid"):K.ctaBtn&&t&&t.length>b?(K.ctaBtn.phoneNumber.btnText=T,H="invalid"):K.ctaBtn&&t&&W.test(t)&&(K.ctaBtn.phoneNumber.btnText=y,H="invalid"),K.ctaBtn&&!i?(K.ctaBtn.phoneNumber.link=a,H="invalid"):K.ctaBtn&&i&&i.length<10&&(K.ctaBtn.phoneNumber.link=f,H="invalid")}if(null===(w=null===(A=e.ctaBtn)||void 0===A?void 0:A.websiteLinkBtn)||void 0===w?void 0:w.isChecked){const t=null===(R=e.ctaBtn.websiteLinkBtn.btnText)||void 0===R?void 0:R.trim(),i=null===(D=e.ctaBtn.websiteLinkBtn.linkOpens)||void 0===D?void 0:D.trim(),n=null===(I=e.ctaBtn.websiteLinkBtn.placeholder)||void 0===I?void 0:I.trim();K.ctaBtn&&!t?(K.ctaBtn.websiteLink.btnText=a,H="invalid"):K.ctaBtn&&t&&t.length>b?(K.ctaBtn.websiteLink.btnText=T,H="invalid"):K.ctaBtn&&t&&W.test(t)&&(K.ctaBtn.websiteLink.btnText=y,H="invalid"),!K.ctaBtn||i||n||(K.ctaBtn.websiteLink.link=a,H="invalid")}}else if(e.actionsType===k.QUICK_REPLY){const t=["","",""];e.quickReply.forEach(((i,n)=>{var l;const o=null===(l=i.text)||void 0===l?void 0:l.trim();if(o)if(o.length>x)t[n]=T,H="invalid";else if(W.test(o))t[n]=y,H="invalid";else{const i=[...e.quickReply];i.splice(n,1);i.find((e=>e.text===o))&&(t[n]=C,H="invalid")}else t[n]=a,H="invalid"})),K.quickReply=t}if(e.actionsType===k.CTA_BTN||e.actionsType===k.QUICK_REPLY){const e=null===(U=K.quickReply)||void 0===U?void 0:U.reduce(((e,t)=>e||!!t),!1);((null===($=null===(j=null==K?void 0:K.ctaBtn)||void 0===j?void 0:j.websiteLink)||void 0===$?void 0:$.link)||(null===(F=null===(q=K.ctaBtn)||void 0===q?void 0:q.websiteLink)||void 0===F?void 0:F.btnText)||(null===(M=null===(P=K.ctaBtn)||void 0===P?void 0:P.phoneNumber)||void 0===M?void 0:M.link)||(null===(S=null===(Y=K.ctaBtn)||void 0===Y?void 0:Y.phoneNumber)||void 0===S?void 0:S.btnText)||e)&&!G&&(J(B.actionButtons),G=!0)}return{status:H,errors:K}}parseBodyComponent(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=arguments.length>2?arguments[2]:void 0,o=arguments.length>3?arguments[3]:void 0;var a,d,r,s,v,p;const u=[];let m="";const c=null===(a=e.components)||void 0===a?void 0:a.find((e=>"BODY"===e.type));return c&&(null===(s=null===(r=null===(d=c.example)||void 0===d?void 0:d.body_text)||void 0===r?void 0:r[0])||void 0===s||s.forEach(((t,i)=>{var a,d;let r=null===(d=null===(a=e.mapping)||void 0===a?void 0:a.body)||void 0===d?void 0:d[i];const s=r,v=r&&/\(\(/.test(r),p=null==r?void 0:r.match(l);(null==p?void 0:p[2])&&(r=null==p?void 0:p[2]);const m=o===N.CHATBOT&&s&&(null==s?void 0:s.startsWith("(("))&&(null==s?void 0:s.endsWith("))"));u.push({idx:i,variableVal:n||m?t:s,editable:!!v,editableDefaultValues:v?void 0:t,variableName:null!=r?r:""})})),m=e.htmlContentUrl?e.htmlContentUrl:(null===(v=c.text)||void 0===v?void 0:v.split(/\{\{[0-9]+\}\}/).length)?null===(p=c.text)||void 0===p?void 0:p.split(/\{\{[0-9]+\}\}/).map(((e,n)=>{if(null==u?void 0:u[n]){const l=u[n].variableName;return t?`${e}{{${l}}}`:`${e} <span> </span><span style="color: ${i.content.brand}; text-decoration: underline;">{{${l}}}</span><span> </span>`}return e})).join(""):""),{bodyVariable:u,bodyText:m}}parseTitleComponent(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=arguments.length>2?arguments[2]:void 0;var o,a,d,r,s,v;const p=[];let u="";const m=null===(o=e.components)||void 0===o?void 0:o.find((e=>"TITLE"===e.type));return m&&(null===(r=null===(d=null===(a=m.example)||void 0===a?void 0:a.title_text)||void 0===d?void 0:d[0])||void 0===r||r.forEach(((t,i)=>{var o,a;let d=null===(a=null===(o=e.mapping)||void 0===o?void 0:o.body)||void 0===a?void 0:a[i];const r=d,s=d&&/\(\(/.test(d),v=null==d?void 0:d.match(l);(null==v?void 0:v[2])&&(d=null==v?void 0:v[2]),p.push({idx:i,variableVal:n?t:r,editable:!!s,editableDefaultValues:s?void 0:t,variableName:null!=d?d:""})})),u=e.htmlContentUrl?e.htmlContentUrl:(null===(s=m.text)||void 0===s?void 0:s.split(/\{\{[0-9]+\}\}/).length)?null===(v=m.text)||void 0===v?void 0:v.split(/\{\{[0-9]+\}\}/).map(((e,n)=>{if(null==p?void 0:p[n]){const l=p[n].variableName;return t?`${e}{{${l}}}`:`${e} <span> </span><span style="color: ${i.content.brand}; text-decoration: underline;">{{${l}}}</span><span> </span>`}return e})).join(""):""),{titleText:u,titleVariables:p}}parseFooterComponent(e){var t;const i=null===(t=e.components)||void 0===t?void 0:t.find((e=>"FOOTER"===e.type));return null==i?void 0:i.text}parseButtonComponent(e){var t,i,n,l,a,d,r;const s={actionsType:k.NONE,quickReply:[],ctaBtn:{phoneNumber:void 0,websiteLinkBtn:void 0},allButtons:[]},v=null===(t=e.components)||void 0===t?void 0:t.find((e=>"BUTTONS"===e.type));if(v&&(null===(i=null==v?void 0:v.buttons)||void 0===i?void 0:i.length)){const t="QUICK_REPLY"===(null===(n=null==v?void 0:v.buttons)||void 0===n?void 0:n[0].type)?k.QUICK_REPLY:k.CTA_BTN;if(s.actionsType=t,t===k.QUICK_REPLY){const e=null!==(a=null===(l=null==v?void 0:v.buttons)||void 0===l?void 0:l.map((e=>e)))&&void 0!==a?a:[];s.quickReply=e}else t===k.CTA_BTN&&(null===(d=null==v?void 0:v.buttons)||void 0===d||d.forEach((t=>{var i,n,l,a;if(t.phone_number&&(s.ctaBtn.phoneNumber={isChecked:!0,btnText:t.text,phoneNumber:t.phone_number}),t.url){const d=null!==(l=null===(n=null===(i=null==e?void 0:e.mapping)||void 0===i?void 0:i.buttons)||void 0===n?void 0:n[0])&&void 0!==l?l:void 0;let r=!1;d&&o.test(d)&&(r=!0),s.ctaBtn.websiteLinkBtn={isChecked:!0,btnText:t.text,linkOpens:r?null===(a=t.example)||void 0===a?void 0:a[0]:t.url,placeholder:r?void 0:d}}})));s.allButtons=null===(r=v.buttons)||void 0===r?void 0:r.map((e=>"COPY_CODE"===e.type?Object.assign(Object.assign({},e),{placeholder:Array.isArray(e.example)?e.example[0]:(null==e?void 0:e.example)||""}):e))}return s}parseLimitedTimeOfferComponent(e,i){const n={text:"",dateTime:"",code:""};return e.components.forEach((e=>{var l,o,a;if("limited_time_offer"===e.type){n.text=null!==(o=null===(l=e.limited_time_offer)||void 0===l?void 0:l.text)&&void 0!==o?o:"";const i=null===(a=e.example)||void 0===a?void 0:a.limited_time_offer;i&&i.startsWith("{{")&&i.endsWith("}}")?n.dateTime=i:n.dateTime=t(i?new Date(i):new Date,"MMM dd")}i.forEach((e=>{var t;"COPY_CODE"===e.type&&(n.code=null!==(t=e.placeholder)&&void 0!==t?t:"")}))})),n}parseUITemplateFromDBFormat(t){var i;return e(this,void 0,void 0,(function*(){const{dbFormattedTemplate:e,isDuplicate:n,isV2:l=!1,showSampleValues:o,pod:a}=t,{headerType:d,headerAssetLink:r,headerAssetName:s,headerText:v,headerVariables:p}=yield this.parseDataFromHeaderComponent(e,void 0,a),{bodyText:u,bodyVariable:m}=yield this.parseBodyComponent(e,l,o,a),{titleText:c,titleVariables:h}=yield this.parseTitleComponent(e,l,o),{actionsType:b,quickReply:T,ctaBtn:y,allButtons:f}=yield this.parseButtonComponent(e),x=this.parseLimitedTimeOfferComponent(e,f),B={quickReply:T,ctaBtn:y,allButtons:f,meta:{name:n?`${e.label} Copy`:e.label,category:null===(i=e.category)||void 0===i?void 0:i.toUpperCase(),subCategory:e.templateCategory,language:e.language,templateId:e.templateId},error:{header:void 0,body:void 0,footer:void 0,quickReply:void 0,meta:void 0,ctaBtn:void 0},actionsType:b,footerText:this.parseFooterComponent(e),bodyVariables:m,bodyText:u,headerType:d,headerAssetLink:r,headerAssetName:s,headerText:v,headerVariables:p,alreadyAsADraft:e.isDraft,mode:"edit",initialLoading:!1,limitedTimeOfferComponent:x,titleText:c,titleVariables:h},{errors:C}=this.validateState(B);return B.error=C,B}))}parseTemplateConfiguration(e){let t;const i=(null==e?void 0:e.content)||{};if("string"==typeof i)try{t=JSON.parse(i)}catch(e){console.error("Error parsing rcsTemplate component JSON:",e),t={orientation:"VERTICAL"}}else t=i;return Object.assign(Object.assign({},t),{templateType:null==e?void 0:e.templateType})}}export{L as TemplateCreatorHelper};
1
+ import{__awaiter as e}from"../../../_virtual/_tslib.js";import{format as t}from"date-fns";import{COLORS as i}from"../../../constants/Theme.js";import{specialCharPattern as n,placeHolderNamePattern as l,editableVarPattern as o}from"../constants/regexPatterns.js";import{REQUIRED_FIELD as a,NAME_LEN_LIMIT as d,NAME_LEN_ERROR as r,NO_SPECIAL_CHAR as s,HEADER_TEXT_LEN_LIMIT as v,HEADER_LEN_ERROR as p,ONE_VAR_ALLOWED as u,HEADER_ASSET_LINK_ERROR as m,BODY_TEXT_LEN_LIMIT as c,BODY_LEN_ERROR as h,QUICK_REPLY_BTN_TEXT_LIMIT as b,QUICK_REPLY_LEN_ERROR as T,BUTTON_EMOJI_ERROR as y,VALID_PHONE_NUMBER as x,QUICK_REPLY_NAME_LEN_LIMIT as f,CREATE_TEMPLATE_DOM_IDS as B,QUICK_REPLY_NAME_ERROR as C}from"../constants/TemplateConstants.js";import{HEADER_TYPES as g,ACTIONS_TYPES as k}from"../models/TemplateMeta.js";import{POD as N}from"../models/WhatsAppTemplate.js";import{TemplateHelperUtils as E}from"../utils/TemplateHelperUtils.js";class L{parseDataFromHeaderComponent(e,t,i){var n,l,o,a,d,r,s,v,p,u;const m={headerType:g.NONE,headerVariables:[]},c=null===(n=null==e?void 0:e.components)||void 0===n?void 0:n.find((e=>"HEADER"===e.type));if(c){m.headerType=c.format,m.headerText=c.text,m.headerAssetLink=null===(o=null===(l=c.example)||void 0===l?void 0:l.header_handle)||void 0===o?void 0:o[0];const n=null===(d=null===(a=c.example)||void 0===a?void 0:a.header_text)||void 0===d?void 0:d[0],h=null===(s=null===(r=e.mapping)||void 0===r?void 0:r.header)||void 0===s?void 0:s[0],b=h;if(h){const e=null==h?void 0:h.replace("[[","").replace("]]","").replace("{{","").replace("}}","").replace("((","").replace("))",""),l=/\(\(/.test(h),o=i===N.CHATBOT&&b&&(null==b?void 0:b.startsWith("(("))&&(null==b?void 0:b.endsWith("))")),a={idx:0,variableVal:t||o?n:b,editable:l,editableDefaultValues:l?void 0:n,variableName:e};m.headerVariables=[a],(null===(p=null===(v=c.example)||void 0===v?void 0:v.header_text)||void 0===p?void 0:p.length)&&(m.headerText=null===(u=m.headerText)||void 0===u?void 0:u.replace("{{1}}",`{{${e}}}`))}}return m}validateState(e){var t,i,l,o,N,L,_,O,w,V,A,R,D,I,P,U,j,$,q,S,F,M,Y;const W=/\p{Extended_Pictographic}/u;let H="valid";const Q={meta:{},ctaBtn:{phoneNumber:{btnText:"",link:""},websiteLink:{btnText:"",link:""}},quickReply:[null,null,null]},K=new E;let G=!1;const J=e=>{var t;null===(t=document.getElementById(e))||void 0===t||t.scrollIntoView({behavior:"smooth",block:"nearest"})};if((null===(t=e.meta)||void 0===t?void 0:t.name)?(null===(i=e.meta.name)||void 0===i?void 0:i.trim().length)>d?(Q.meta.name=r,H="invalid"):n.test(null===(l=e.meta.name)||void 0===l?void 0:l.trim())&&(Q.meta.name=s,H="invalid"):(Q.meta.name=a,H="invalid"),Q.meta.name&&!G&&(J(B.name),G=!0),e.headerType===g.TEXT){const t=null!==(N=null===(o=e.headerText)||void 0===o?void 0:o.trim())&&void 0!==N?N:"";if(t)if(t.length>v)Q.header=p,H="invalid";else{const e=K.getTemplateVariablesFromState(t);e&&e.length>1&&(Q.header=u,H="invalid")}else Q.header=a,H="invalid"}else e.headerType===g.DOCUMENT||e.headerType===g.IMAGE||(e.headerType,g.VIDEO);if(e.headerType!==g.DOCUMENT&&e.headerType!==g.IMAGE&&e.headerType!==g.VIDEO||e.headerAssetLink||(Q.header=m,H="invalid"),Q.header&&!G&&(J(B.header),G=!0),e.bodyText?e.bodyTextRaw&&(null===(L=e.bodyTextRaw)||void 0===L?void 0:L.trim().length)>c&&(Q.body=h,H="invalid"):(Q.body=a,H="invalid"),Q.body&&!G&&(J(B.body),G=!0),e.footerText&&e.footerText.length>v&&(Q.footer=p,H="invalid"),(null==Q?void 0:Q.footer)&&!G&&(J(B.footer),G=!0),e.actionsType===k.CTA_BTN){if(null===(O=null===(_=e.ctaBtn)||void 0===_?void 0:_.phoneNumber)||void 0===O?void 0:O.isChecked){const t=null===(w=e.ctaBtn.phoneNumber.btnText)||void 0===w?void 0:w.trim(),i=e.ctaBtn.phoneNumber.phoneNumber;Q.ctaBtn&&!t?(Q.ctaBtn.phoneNumber.btnText=a,H="invalid"):Q.ctaBtn&&t&&t.length>b?(Q.ctaBtn.phoneNumber.btnText=T,H="invalid"):Q.ctaBtn&&t&&W.test(t)&&(Q.ctaBtn.phoneNumber.btnText=y,H="invalid"),Q.ctaBtn&&!i?(Q.ctaBtn.phoneNumber.link=a,H="invalid"):Q.ctaBtn&&i&&i.length<10&&(Q.ctaBtn.phoneNumber.link=x,H="invalid")}if(null===(A=null===(V=e.ctaBtn)||void 0===V?void 0:V.websiteLinkBtn)||void 0===A?void 0:A.isChecked){const t=null===(R=e.ctaBtn.websiteLinkBtn.btnText)||void 0===R?void 0:R.trim(),i=null===(D=e.ctaBtn.websiteLinkBtn.linkOpens)||void 0===D?void 0:D.trim(),n=null===(I=e.ctaBtn.websiteLinkBtn.placeholder)||void 0===I?void 0:I.trim();Q.ctaBtn&&!t?(Q.ctaBtn.websiteLink.btnText=a,H="invalid"):Q.ctaBtn&&t&&t.length>b?(Q.ctaBtn.websiteLink.btnText=T,H="invalid"):Q.ctaBtn&&t&&W.test(t)&&(Q.ctaBtn.websiteLink.btnText=y,H="invalid"),!Q.ctaBtn||i||n||(Q.ctaBtn.websiteLink.link=a,H="invalid")}}else if(e.actionsType===k.QUICK_REPLY){const t=["","",""];e.quickReply.forEach(((i,n)=>{var l;const o=null===(l=i.text)||void 0===l?void 0:l.trim();if(o)if(o.length>f)t[n]=T,H="invalid";else if(W.test(o))t[n]=y,H="invalid";else{const i=[...e.quickReply];i.splice(n,1);i.find((e=>e.text===o))&&(t[n]=C,H="invalid")}else t[n]=a,H="invalid"})),Q.quickReply=t}if(e.actionsType===k.CTA_BTN||e.actionsType===k.QUICK_REPLY){const e=null===(P=Q.quickReply)||void 0===P?void 0:P.reduce(((e,t)=>e||!!t),!1);((null===(j=null===(U=null==Q?void 0:Q.ctaBtn)||void 0===U?void 0:U.websiteLink)||void 0===j?void 0:j.link)||(null===(q=null===($=Q.ctaBtn)||void 0===$?void 0:$.websiteLink)||void 0===q?void 0:q.btnText)||(null===(F=null===(S=Q.ctaBtn)||void 0===S?void 0:S.phoneNumber)||void 0===F?void 0:F.link)||(null===(Y=null===(M=Q.ctaBtn)||void 0===M?void 0:M.phoneNumber)||void 0===Y?void 0:Y.btnText)||e)&&!G&&(J(B.actionButtons),G=!0)}return{status:H,errors:Q}}parseBodyComponent(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=arguments.length>2?arguments[2]:void 0,o=arguments.length>3?arguments[3]:void 0;var a,d,r,s,v,p;const u=[];let m="";const c=null===(a=e.components)||void 0===a?void 0:a.find((e=>"BODY"===e.type));return c&&(null===(s=null===(r=null===(d=c.example)||void 0===d?void 0:d.body_text)||void 0===r?void 0:r[0])||void 0===s||s.forEach(((t,i)=>{var a,d;let r=null===(d=null===(a=e.mapping)||void 0===a?void 0:a.body)||void 0===d?void 0:d[i];const s=r,v=r&&/\(\(/.test(r),p=null==r?void 0:r.match(l);(null==p?void 0:p[2])&&(r=null==p?void 0:p[2]);const m=o===N.CHATBOT&&s&&(null==s?void 0:s.startsWith("(("))&&(null==s?void 0:s.endsWith("))"));u.push({idx:i,variableVal:n||m?t:s,editable:!!v,editableDefaultValues:v?void 0:t,variableName:null!=r?r:""})})),m=e.htmlContentUrl?e.htmlContentUrl:(null===(v=c.text)||void 0===v?void 0:v.split(/\{\{[0-9]+\}\}/).length)?null===(p=c.text)||void 0===p?void 0:p.split(/\{\{[0-9]+\}\}/).map(((e,n)=>{if(null==u?void 0:u[n]){const l=u[n].variableName;return t?`${e}{{${l}}}`:`${e} <span> </span><span style="color: ${i.content.brand}; text-decoration: underline;">{{${l}}}</span><span> </span>`}return e})).join(""):""),{bodyVariable:u,bodyText:m}}parseTitleComponent(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=arguments.length>2?arguments[2]:void 0;var o,a,d,r,s,v;const p=[];let u="";const m=null===(o=e.components)||void 0===o?void 0:o.find((e=>"TITLE"===e.type));return m&&(null===(r=null===(d=null===(a=m.example)||void 0===a?void 0:a.title_text)||void 0===d?void 0:d[0])||void 0===r||r.forEach(((t,i)=>{var o,a;let d=null===(a=null===(o=e.mapping)||void 0===o?void 0:o.body)||void 0===a?void 0:a[i];const r=d,s=d&&/\(\(/.test(d),v=null==d?void 0:d.match(l);(null==v?void 0:v[2])&&(d=null==v?void 0:v[2]),p.push({idx:i,variableVal:n?t:r,editable:!!s,editableDefaultValues:s?void 0:t,variableName:null!=d?d:""})})),u=e.htmlContentUrl?e.htmlContentUrl:(null===(s=m.text)||void 0===s?void 0:s.split(/\{\{[0-9]+\}\}/).length)?null===(v=m.text)||void 0===v?void 0:v.split(/\{\{[0-9]+\}\}/).map(((e,n)=>{if(null==p?void 0:p[n]){const l=p[n].variableName;return t?`${e}{{${l}}}`:`${e} <span> </span><span style="color: ${i.content.brand}; text-decoration: underline;">{{${l}}}</span><span> </span>`}return e})).join(""):""),{titleText:u,titleVariables:p}}parseFooterComponent(e){var t;const i=null===(t=e.components)||void 0===t?void 0:t.find((e=>"FOOTER"===e.type));return null==i?void 0:i.text}parseButtonComponent(e){var t,i,n,l,a,d,r;const s={actionsType:k.NONE,quickReply:[],ctaBtn:{phoneNumber:void 0,websiteLinkBtn:void 0},allButtons:[]},v=null===(t=e.components)||void 0===t?void 0:t.find((e=>"BUTTONS"===e.type));if(v&&(null===(i=null==v?void 0:v.buttons)||void 0===i?void 0:i.length)){const t="QUICK_REPLY"===(null===(n=null==v?void 0:v.buttons)||void 0===n?void 0:n[0].type)?k.QUICK_REPLY:k.CTA_BTN;if(s.actionsType=t,t===k.QUICK_REPLY){const e=null!==(a=null===(l=null==v?void 0:v.buttons)||void 0===l?void 0:l.map((e=>e)))&&void 0!==a?a:[];s.quickReply=e}else t===k.CTA_BTN&&(null===(d=null==v?void 0:v.buttons)||void 0===d||d.forEach((t=>{var i,n,l,a;if(t.phone_number&&(s.ctaBtn.phoneNumber={isChecked:!0,btnText:t.text,phoneNumber:t.phone_number}),t.url){const d=null!==(l=null===(n=null===(i=null==e?void 0:e.mapping)||void 0===i?void 0:i.buttons)||void 0===n?void 0:n[0])&&void 0!==l?l:void 0;let r=!1;d&&o.test(d)&&(r=!0),s.ctaBtn.websiteLinkBtn={isChecked:!0,btnText:t.text,linkOpens:r?null===(a=t.example)||void 0===a?void 0:a[0]:t.url,placeholder:r?void 0:d}}})));s.allButtons=null===(r=v.buttons)||void 0===r?void 0:r.map((e=>"COPY_CODE"===e.type?Object.assign(Object.assign({},e),{placeholder:Array.isArray(e.example)?e.example[0]:(null==e?void 0:e.example)||""}):e))}return s}parseLimitedTimeOfferComponent(e,i){const n={text:"",dateTime:"",code:""};return e.components.forEach((e=>{var l,o,a;if("limited_time_offer"===e.type){n.text=null!==(o=null===(l=e.limited_time_offer)||void 0===l?void 0:l.text)&&void 0!==o?o:"";const i=null===(a=e.example)||void 0===a?void 0:a.limited_time_offer;i&&i.startsWith("{{")&&i.endsWith("}}")?n.dateTime=i:n.dateTime=t(i?new Date(i):new Date,"MMM dd")}i.forEach((e=>{var t;"COPY_CODE"===e.type&&(n.code=null!==(t=e.placeholder)&&void 0!==t?t:"")}))})),n}parseCallPermissionComponent(e){var t;const i=null===(t=e.components)||void 0===t?void 0:t.find((e=>"CALL_PERMISSION_REQUEST"===e.type));return{showCallPermissionCard:Boolean(i),callPermissionText:null==i?void 0:i.text}}parseUITemplateFromDBFormat(t){var i;return e(this,void 0,void 0,(function*(){const{dbFormattedTemplate:e,isDuplicate:n,isV2:l=!1,showSampleValues:o,pod:a}=t,{headerType:d,headerAssetLink:r,headerAssetName:s,headerText:v,headerVariables:p}=yield this.parseDataFromHeaderComponent(e,void 0,a),{bodyText:u,bodyVariable:m}=yield this.parseBodyComponent(e,l,o,a),{titleText:c,titleVariables:h}=yield this.parseTitleComponent(e,l,o),{actionsType:b,quickReply:T,ctaBtn:y,allButtons:x}=yield this.parseButtonComponent(e),f=this.parseLimitedTimeOfferComponent(e,x),{showCallPermissionCard:B,callPermissionText:C}=this.parseCallPermissionComponent(e),g={quickReply:T,ctaBtn:y,allButtons:x,meta:{name:n?`${e.label} Copy`:e.label,category:null===(i=e.category)||void 0===i?void 0:i.toUpperCase(),subCategory:e.templateCategory,language:e.language,templateId:e.templateId},error:{header:void 0,body:void 0,footer:void 0,quickReply:void 0,meta:void 0,ctaBtn:void 0},actionsType:b,footerText:this.parseFooterComponent(e),bodyVariables:m,bodyText:u,headerType:d,headerAssetLink:r,headerAssetName:s,headerText:v,headerVariables:p,alreadyAsADraft:e.isDraft,mode:"edit",initialLoading:!1,limitedTimeOfferComponent:f,titleText:c,titleVariables:h,showCallPermissionCard:B,callPermissionText:C},{errors:k}=this.validateState(g);return g.error=k,g}))}parseTemplateConfiguration(e){let t;const i=(null==e?void 0:e.content)||{};if("string"==typeof i)try{t=JSON.parse(i)}catch(e){console.error("Error parsing rcsTemplate component JSON:",e),t={orientation:"VERTICAL"}}else t=i;return Object.assign(Object.assign({},t),{templateType:null==e?void 0:e.templateType})}}export{L as TemplateCreatorHelper};
@@ -104,6 +104,8 @@ export type CreateTemplateType = {
104
104
  dateTime: string;
105
105
  code: string;
106
106
  };
107
+ showCallPermissionCard?: boolean;
108
+ callPermissionText?: string;
107
109
  error: {
108
110
  modalError?: string;
109
111
  header?: string;
@@ -10,7 +10,7 @@ export type WhatsAppCarouselTemplate = {
10
10
  templateCategory: string;
11
11
  type?: 'email' | 'whatsapp';
12
12
  components: {
13
- type: 'BODY' | 'CAROUSEL' | 'CALL_PERMISSION';
13
+ type: 'BODY' | 'CAROUSEL' | 'CALL_PERMISSION_REQUEST';
14
14
  format?: HEADER_TYPES;
15
15
  text?: string;
16
16
  example?: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bikdotai/bik-component-library",
3
- "version": "0.0.700-beta.5",
3
+ "version": "0.0.700-beta.6",
4
4
  "description": "Bik Component Library",
5
5
  "repository": {
6
6
  "type": "git",