@bikdotai/bik-component-library 0.0.350-beta.1 → 0.0.350-beta.2
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/dist/cjs/components/QueryBuilder/Filters/Event/components/EventFilter.js +1 -1
- package/dist/cjs/components/QueryBuilder/constants/DATE_OPERATORS_OPTIONS.js +1 -1
- package/dist/cjs/components/template-preview/constants/regexPatterns.js +1 -1
- package/dist/cjs/components/template-preview/helpers/TemplateCreatorHelper.js +1 -1
- package/dist/esm/components/QueryBuilder/Filters/Event/components/EventFilter.js +1 -1
- package/dist/esm/components/QueryBuilder/constants/DATE_OPERATORS_OPTIONS.js +1 -1
- package/dist/esm/components/template-preview/constants/regexPatterns.js +1 -1
- package/dist/esm/components/template-preview/helpers/TemplateCreatorHelper.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../../../_virtual/_tslib.js"),r=require("react/jsx-runtime"),o=require("react"),t=require("../../../../dropdown/OpenedDropdown/utils/iterationOnOptions.js"),a=require("../../../components/AllowedListDropdown.js"),l=require("../../../components/Connectors/Connector.js"),i=require("../../../helpers/ApiResponse.helper.js"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../../../_virtual/_tslib.js"),r=require("react/jsx-runtime"),o=require("react"),t=require("../../../../dropdown/OpenedDropdown/utils/iterationOnOptions.js"),a=require("../../../components/AllowedListDropdown.js"),l=require("../../../components/Connectors/Connector.js"),i=require("../../../helpers/ApiResponse.helper.js"),u=require("../../../hooks/useQueryBuilder.js"),n=require("../../../hooks/useQueryBuilderCache.js"),d=require("../../../types/QueryBuilder.type.js"),v=require("../../../types/QueryBuilderOperator.type.js"),s=require("../../../components/DropdownWrapper.js"),p=require("../../../components/QueryBuilderNode/Base/BaseQueryBuilderNode.js");const y=new i.ApiResponseHelper;exports.default=i=>{let{node:c,allowedNodes:f,apiHandler:T,mode:_,selectorKey:O}=i;var j,m,h,q,C,B,N,S,E,k,w,x,P,Q,b,g,A,R;const[V,D]=o.useState([]),[M,L]=o.useState(!1),{deleteProperty:$,createProperty:F,selectType:H,createMeta:J,updateMeta:K,updateProperty:U,selectPropertyJoinOperator:W,clearProperty:Y}=u.useQueryBuilder(O),{cacheWrap:G}=n.useQueryBuilderCache(),[z,I]=o.useState(!0),X=null===(j=null==c?void 0:c.metas)||void 0===j?void 0:j.find((e=>"date"===e.key)),Z=null===(m=null==c?void 0:c.metas)||void 0===m?void 0:m.find((e=>"frequency"===e.key)),ee=null===(h=null==c?void 0:c.metas)||void 0===h?void 0:h.find((e=>"eventName"===e.key)),[re,oe]=o.useState(!1),[te,ae]=o.useState(!1),[le,ie]=o.useState(!1);return o.useEffect((()=>{G((()=>T({})),"EVENT_NAMES").then((e=>{I(!1);const r=y.convertToGroupOptions(e,(null==ee?void 0:ee.value)?[ee.value]:void 0);if("create"!==_&&ee)return D([...r]),void L(!0);D([...r]),L(!0)}))}),[]),r.jsx(p.BaseQueryBuilderNode,Object.assign({selectPropertyJoinOperator:W,node:c,addPropertyBtnText:(null==ee?void 0:ee.value)&&"Add event property",deleteProperty:$,createProperty:F,propertySelectorText:"Select property",fetchPropertyData:function(){return e.__awaiter(this,void 0,void 0,(function*(){var e;return yield(e=null==ee?void 0:ee.value,G((()=>T({query:{eventName:e}})),`EVENT_NAMES_${e}`))}))},onPropertyNameSelect:function(r,o){return e.__awaiter(this,void 0,void 0,(function*(){if(U(Object.assign(Object.assign({},o),{name:r.id,dataType:r.type,operator:void 0,value:void 0,error:{}}),c._id),!r.needValuesRetrieval)return[];const e=yield((e,r)=>G((()=>T({query:{eventName:e,propertyName:r}})),`EVENT_NAMES_${e}_${r}`))(null==ee?void 0:ee.value,r.id);return null!=e?e:[]}))},onPropertyOperatorChange:function(e,r){U(Object.assign(Object.assign({},r),{operator:e,value:void 0,error:{}}),c._id)},onPropertyValueChange:function(e,r){U(Object.assign(Object.assign({},r),{value:e,error:{}}),c._id)},mode:_,onPropertyValueSearch:function(r,o){var t,a;return e.__awaiter(this,void 0,void 0,(function*(){const l=yield((r,o,t)=>e.__awaiter(void 0,void 0,void 0,(function*(){return yield T({query:{eventName:r,propertyName:o,searchKey:t}})})))(null==ee?void 0:ee.value,o.name,r);return null!==(a=null===(t=null==l?void 0:l.data)||void 0===t?void 0:t.map((e=>({label:e.name,value:e.id,selected:!1}))))&&void 0!==a?a:[]}))}},{children:r.jsxs("div",Object.assign({style:{flexDirection:"column",display:"flex",gap:12}},{children:[r.jsxs("div",Object.assign({style:{flexDirection:"row",display:"flex",gap:12}},{children:[r.jsx(a.default,{disabled:"view"===_,selectedType:c.type,allowedList:f,onSelect:function(e){oe(!0),D((e=>[...t.iterateOnOptions(e,{selected:!1})])),setTimeout((()=>{H(e.value,c._id),oe(!1)}),1)}}),!re&&r.jsx(s.default,{isSearchable:!0,isLoading:z,disabled:"view"===_,width:"200px",dropdownLabel:"Select event name",options:V,selectedValues:(null==ee?void 0:ee.value)?[ee.value]:void 0,onSelect:function(e){Array.isArray(e)||(Y(c._id),ee?K({key:"eventName",value:e.value,error:{}},c._id):J({key:"eventName",value:e.value},c._id),Z?(ae(!0),setTimeout((()=>{K({key:"frequency",value:{dataType:d.QueryBuilderConnectorType.frequency,operator:v.FREQUENCY_OPERATORS.atleast,value:1},error:{}},c._id),ae(!1)}),1)):J({key:"frequency",value:{dataType:d.QueryBuilderConnectorType.frequency,operator:v.FREQUENCY_OPERATORS.atleast,value:1}},c._id),X?(ie(!0),setTimeout((()=>{K({key:"date",value:{dataType:d.QueryBuilderConnectorType.date,operator:v.DATE_OPERATORS["last 30 days"]},error:{}},c._id),ie(!1)}),1)):J({key:"date",value:{dataType:d.QueryBuilderConnectorType.date,operator:v.DATE_OPERATORS["last 30 days"]}},c._id))},error:null!==(E=null!==(N=null===(B=null===(C=null===(q=c.metas)||void 0===q?void 0:q[0])||void 0===C?void 0:C.error)||void 0===B?void 0:B.key)&&void 0!==N?N:null===(S=null==ee?void 0:ee.error)||void 0===S?void 0:S.key)&&void 0!==E?E:null===(k=null==ee?void 0:ee.error)||void 0===k?void 0:k.value})]})),(null==Z?void 0:Z.key)&&!te&&r.jsx(l.default,{disabled:"view"===_,extra:{},errors:{val:null===(x=null===(w=Z.error)||void 0===w?void 0:w.value)||void 0===x?void 0:x.value,operator:null===(Q=null===(P=Z.error)||void 0===P?void 0:P.value)||void 0===Q?void 0:Q.operator},connectorVal:Z.value.value,connectorType:Z.value.dataType,defaultConnector:Z.value.operator,onOperatorChange:function(e){K({key:"frequency",value:{dataType:d.QueryBuilderConnectorType.frequency,operator:e,value:1},error:{}},c._id)},onValueChange:function(e){var r;M&&K({key:"frequency",value:{dataType:d.QueryBuilderConnectorType.frequency,operator:null===(r=null==Z?void 0:Z.value)||void 0===r?void 0:r.operator,value:e},error:{}},c._id)}}),(null==X?void 0:X.key)&&!le&&r.jsx(l.default,{disabled:"view"===_,extra:{},errors:{val:null===(g=null===(b=X.error)||void 0===b?void 0:b.value)||void 0===g?void 0:g.value,operator:null===(R=null===(A=X.error)||void 0===A?void 0:A.value)||void 0===R?void 0:R.operator},connectorVal:X.value.value,connectorType:X.value.dataType,defaultConnector:X.value.operator,onOperatorChange:function(e){K({key:"date",value:{dataType:d.QueryBuilderConnectorType.date,operator:e,value:void 0},error:{}},c._id)},onValueChange:function(e){var r;M&&K({key:"date",value:{dataType:d.QueryBuilderConnectorType.date,operator:null===(r=null==X?void 0:X.value)||void 0===r?void 0:r.operator,value:e},error:{}},c._id)}})]}))}))};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.DATE_OPERATORS_OPTIONS=[{label:"Commonly used",options:[{selected:!1,value:"today",label:"Today",description:"Events performed in the current day (starting at 00:00 hours)"},{selected:!1,value:"yesterday",label:"Yesterday",description:"Events performed in the previous day (starting at 00:00 hours)"},{selected:!1,value:"last 7 days",label:"Last 7 days",description:"Events performed in the previous 7 complete days along with the current day"},{selected:!
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.DATE_OPERATORS_OPTIONS=[{label:"Commonly used",options:[{selected:!1,value:"today",label:"Today",description:"Events performed in the current day (starting at 00:00 hours)"},{selected:!1,value:"yesterday",label:"Yesterday",description:"Events performed in the previous day (starting at 00:00 hours)"},{selected:!1,value:"last 7 days",label:"Last 7 days",description:"Events performed in the previous 7 complete days along with the current day"},{selected:!0,value:"last 30 days",label:"Last 30 days",description:"Events performed in the previous 30 complete days along with the current day"},{selected:!1,value:"this week",label:"This week",description:"Events performed in the current calendar week (starting Monday), including the current day"},{selected:!1,value:"last week",label:"Last week",description:"Events performed in the previous calendar week (starting Monday)"},{selected:!1,value:"this month",label:"This month",description:"Events performed in the current calendar month, including the current day"},{selected:!1,value:"last month",label:"Last month",description:"Events performed in the current calendar month, including the current day"}]},{label:"Relative",options:[{selected:!1,value:"exactly",label:"Exactly",description:"Events performed precisely in a specific time frame (days, hours, or minutes) before the current time"},{selected:!1,value:"in the last",label:"In the last",description:"Events performed within the period between the current time and a specified time frame (days, hours, or minutes), relative to and before the current time"},{selected:!1,value:"in between last",label:"In between last",description:"Events performed within the range from one specific time frame to another specific time frame, both relative to and before the current time"}]},{label:"Absolute",options:[{selected:!1,value:"on",label:"On",description:"Events performed exactly on a particular date"},{selected:!1,value:"notOn",label:"Not On"},{selected:!1,value:"inBetween",label:"In Between",description:"Events performed between a specified date range"},{selected:!1,value:"notInBetween",label:"Not In Between"},{selected:!1,value:"before",label:"Before",description:"Events performed before a particular date (excluding that particular date)"},{selected:!1,value:"after",label:"After",description:"Events performed after a particular date (excluding that particular date)"}]}];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e=/\{\{[A-Za-z0-9 .]+\}\}/g,t=e;exports.editableBracketPattern=/[((|))]/,exports.editableVarPattern=/\((\(|\[)[A-Za-z0-9 ]+(\]|\))\)/,exports.globalHalfVariablePattern=/\{\{[a-zA-Z0-9]+(?=( |\}))(?!\}\})/g,exports.globalVariablePattern=e,exports.lockedVarPattern=/\[\[[A-Za-z0-9 .]+\]\]/,exports.placeHolderNamePattern=/(\[\[|\(\()
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e=/\{\{[A-Za-z0-9 .]+\}\}/g,t=e;exports.editableBracketPattern=/[((|))]/,exports.editableVarPattern=/\((\(|\[)[A-Za-z0-9 ]+(\]|\))\)/,exports.globalHalfVariablePattern=/\{\{[a-zA-Z0-9]+(?=( |\}))(?!\}\})/g,exports.globalVariablePattern=e,exports.lockedVarPattern=/\[\[[A-Za-z0-9 .]+\]\]/,exports.placeHolderNamePattern=/(\[\[|\(\()(.*)(\)\)|\]\])/,exports.previewLinkMDFormatPattern=/\[([^[]+)\](\(.*\))/,exports.specialCharPattern=/[!@#$%^&*()_+\-={};':"\\|,.<>?]+/,exports.templateVariablePattern=t,exports.variablePattern=/\{\{[A-Za-z0-9 ._]+\}\}/,exports.variablePatternGlobal=/\{\{[A-Za-z0-9 _]+\}\}/g;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),t=require("../../../constants/Theme.js"),n=require("../constants/regexPatterns.js"),i=require("../constants/TemplateConstants.js"),l=require("../models/TemplateMeta.js"),o=require("../utils/TemplateHelperUtils.js");exports.TemplateCreatorHelper=class{parseDataFromHeaderComponent(e){var t,n,i,o,a,d,r,v,s,E;const u={headerType:l.HEADER_TYPES.NONE,headerVariables:[]},T=null===(t=e.components)||void 0===t?void 0:t.find((e=>"HEADER"===e.type));if(T){u.headerType=T.format,u.headerText=T.text,u.headerAssetLink=null===(i=null===(n=T.example)||void 0===n?void 0:n.header_handle)||void 0===i?void 0:i[0];const t=null===(a=null===(o=T.example)||void 0===o?void 0:o.header_text)||void 0===a?void 0:a[0],l=null===(r=null===(d=e.mapping)||void 0===d?void 0:d.header)||void 0===r?void 0:r[0];if(t&&l){const e=null==l?void 0:l.replace("[[","").replace("]]","").replace("
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),t=require("../../../constants/Theme.js"),n=require("../constants/regexPatterns.js"),i=require("../constants/TemplateConstants.js"),l=require("../models/TemplateMeta.js"),o=require("../utils/TemplateHelperUtils.js");exports.TemplateCreatorHelper=class{parseDataFromHeaderComponent(e){var t,n,i,o,a,d,r,v,s,E;const u={headerType:l.HEADER_TYPES.NONE,headerVariables:[]},T=null===(t=e.components)||void 0===t?void 0:t.find((e=>"HEADER"===e.type));if(T){u.headerType=T.format,u.headerText=T.text,u.headerAssetLink=null===(i=null===(n=T.example)||void 0===n?void 0:n.header_handle)||void 0===i?void 0:i[0];const t=null===(a=null===(o=T.example)||void 0===o?void 0:o.header_text)||void 0===a?void 0:a[0],l=null===(r=null===(d=e.mapping)||void 0===d?void 0:d.header)||void 0===r?void 0:r[0];if(t&&l){const e=null==l?void 0:l.replace("[[","").replace("]]","").replace("((","").replace("))",""),n=/\(\(/.test(l),i={idx:0,variableVal:t,editable:n,editableDefaultValues:n?void 0:t,variableName:e};u.headerVariables=[i],(null===(s=null===(v=T.example)||void 0===v?void 0:v.header_text)||void 0===s?void 0:s.length)&&(u.headerText=null===(E=u.headerText)||void 0===E?void 0:E.replace("{{1}}",`{{${e}}}`))}}return u}validateState(e){var t,a,d,r,v,s,E,u,T,p,_,c,R,m,h,b,I,L,N,y,B;const A=/\p{Extended_Pictographic}/u;let C="valid";const D={meta:{},ctaBtn:{phoneNumber:{btnText:"",link:""},websiteLink:{btnText:"",link:""}},quickReply:[null,null,null]},O=new o.TemplateHelperUtils;let x=!1;const P=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)?e.meta.name.trim().length>i.NAME_LEN_LIMIT?(D.meta.name=i.NAME_LEN_ERROR,C="invalid"):n.specialCharPattern.test(e.meta.name.trim())&&(D.meta.name=i.NO_SPECIAL_CHAR,C="invalid"):(D.meta.name=i.REQUIRED_FIELD,C="invalid"),D.meta.name&&!x&&(P(i.CREATE_TEMPLATE_DOM_IDS.name),x=!0),e.headerType===l.HEADER_TYPES.TEXT){const t=null!==(d=null===(a=e.headerText)||void 0===a?void 0:a.trim())&&void 0!==d?d:"";if(t)if(t.length>i.HEADER_TEXT_LEN_LIMIT)D.header=i.HEADER_LEN_ERROR,C="invalid";else{const e=O.getTemplateVariablesFromState(t);e&&e.length>1&&(D.header=i.ONE_VAR_ALLOWED,C="invalid")}else D.header=i.REQUIRED_FIELD,C="invalid"}else e.headerType===l.HEADER_TYPES.DOCUMENT||e.headerType===l.HEADER_TYPES.IMAGE||(e.headerType,l.HEADER_TYPES.VIDEO);if(e.headerType!==l.HEADER_TYPES.DOCUMENT&&e.headerType!==l.HEADER_TYPES.IMAGE&&e.headerType!==l.HEADER_TYPES.VIDEO||e.headerAssetLink||(D.header=i.HEADER_ASSET_LINK_ERROR,C="invalid"),D.header&&!x&&(P(i.CREATE_TEMPLATE_DOM_IDS.header),x=!0),e.bodyText?e.bodyTextRaw&&(null===(r=e.bodyTextRaw)||void 0===r?void 0:r.trim().length)>i.BODY_TEXT_LEN_LIMIT&&(D.body=i.BODY_LEN_ERROR,C="invalid"):(D.body=i.REQUIRED_FIELD,C="invalid"),D.body&&!x&&(P(i.CREATE_TEMPLATE_DOM_IDS.body),x=!0),e.footerText&&e.footerText.length>i.HEADER_TEXT_LEN_LIMIT&&(D.footer=i.HEADER_LEN_ERROR,C="invalid"),(null==D?void 0:D.footer)&&!x&&(P(i.CREATE_TEMPLATE_DOM_IDS.footer),x=!0),e.actionsType===l.ACTIONS_TYPES.CTA_BTN){if(null===(s=null===(v=e.ctaBtn)||void 0===v?void 0:v.phoneNumber)||void 0===s?void 0:s.isChecked){const t=null===(E=e.ctaBtn.phoneNumber.btnText)||void 0===E?void 0:E.trim(),n=e.ctaBtn.phoneNumber.phoneNumber;D.ctaBtn&&!t?(D.ctaBtn.phoneNumber.btnText=i.REQUIRED_FIELD,C="invalid"):D.ctaBtn&&t&&t.length>i.QUICK_REPLY_BTN_TEXT_LIMIT?(D.ctaBtn.phoneNumber.btnText=i.QUICK_REPLY_LEN_ERROR,C="invalid"):D.ctaBtn&&t&&A.test(t)&&(D.ctaBtn.phoneNumber.btnText=i.BUTTON_EMOJI_ERROR,C="invalid"),D.ctaBtn&&!n?(D.ctaBtn.phoneNumber.link=i.REQUIRED_FIELD,C="invalid"):D.ctaBtn&&n&&n.length<10&&(D.ctaBtn.phoneNumber.link=i.VALID_PHONE_NUMBER,C="invalid")}if(null===(T=null===(u=e.ctaBtn)||void 0===u?void 0:u.websiteLinkBtn)||void 0===T?void 0:T.isChecked){const t=null===(p=e.ctaBtn.websiteLinkBtn.btnText)||void 0===p?void 0:p.trim(),n=null===(_=e.ctaBtn.websiteLinkBtn.linkOpens)||void 0===_?void 0:_.trim(),l=null===(c=e.ctaBtn.websiteLinkBtn.placeholder)||void 0===c?void 0:c.trim();D.ctaBtn&&!t?(D.ctaBtn.websiteLink.btnText=i.REQUIRED_FIELD,C="invalid"):D.ctaBtn&&t&&t.length>i.QUICK_REPLY_BTN_TEXT_LIMIT?(D.ctaBtn.websiteLink.btnText=i.QUICK_REPLY_LEN_ERROR,C="invalid"):D.ctaBtn&&t&&A.test(t)&&(D.ctaBtn.websiteLink.btnText=i.BUTTON_EMOJI_ERROR,C="invalid"),!D.ctaBtn||n||l||(D.ctaBtn.websiteLink.link=i.REQUIRED_FIELD,C="invalid")}}else if(e.actionsType===l.ACTIONS_TYPES.QUICK_REPLY){const t=["","",""];e.quickReply.forEach(((n,l)=>{const o=n.text.trim();if(o)if(o.length>i.QUICK_REPLY_NAME_LEN_LIMIT)t[l]=i.QUICK_REPLY_LEN_ERROR,C="invalid";else if(A.test(o))t[l]=i.BUTTON_EMOJI_ERROR,C="invalid";else{const n=[...e.quickReply];n.splice(l,1);n.find((e=>e.text===o))&&(t[l]=i.QUICK_REPLY_NAME_ERROR,C="invalid")}else t[l]=i.REQUIRED_FIELD,C="invalid"})),D.quickReply=t}if(e.actionsType===l.ACTIONS_TYPES.CTA_BTN||e.actionsType===l.ACTIONS_TYPES.QUICK_REPLY){const e=null===(R=D.quickReply)||void 0===R?void 0:R.reduce(((e,t)=>e||!!t),!1);((null===(h=null===(m=null==D?void 0:D.ctaBtn)||void 0===m?void 0:m.websiteLink)||void 0===h?void 0:h.link)||(null===(I=null===(b=D.ctaBtn)||void 0===b?void 0:b.websiteLink)||void 0===I?void 0:I.btnText)||(null===(N=null===(L=D.ctaBtn)||void 0===L?void 0:L.phoneNumber)||void 0===N?void 0:N.link)||(null===(B=null===(y=D.ctaBtn)||void 0===y?void 0:y.phoneNumber)||void 0===B?void 0:B.btnText)||e)&&!x&&(P(i.CREATE_TEMPLATE_DOM_IDS.actionButtons),x=!0)}return{status:C,errors:D}}parseBodyComponent(e){let i=arguments.length>1&&void 0!==arguments[1]&&arguments[1];var l,o,a,d,r;const v=[];let s="";const E=null===(l=e.components)||void 0===l?void 0:l.find((e=>"BODY"===e.type));return E&&(null===(a=null===(o=E.example)||void 0===o?void 0:o.body_text)||void 0===a||a[0].forEach(((t,i)=>{var l,o;let a=null===(o=null===(l=e.mapping)||void 0===l?void 0:l.body)||void 0===o?void 0:o[i];const d=a&&/\(\(/.test(a),r=null==a?void 0:a.match(n.placeHolderNamePattern);(null==r?void 0:r[2])&&(a=null==r?void 0:r[2]),v.push({idx:i,variableVal:t,editable:!!d,editableDefaultValues:d?void 0:t,variableName:null!=a?a:""})})),s=e.htmlContentUrl?e.htmlContentUrl:(null===(d=E.text)||void 0===d?void 0:d.split(/\{\{[0-9]+\}\}/).length)?null===(r=E.text)||void 0===r?void 0:r.split(/\{\{[0-9]+\}\}/).map(((e,n)=>{if(null==v?void 0:v[n]){const l=v[n].variableName;return i?`${e}{{${l}}}`:`${e} <span> </span><span style="color: ${t.COLORS.content.brand}; text-decoration: underline;">{{${l}}}</span><span> </span>`}return e})).join(""):""),{bodyVariable:v,bodyText:s}}parseFooterComponent(e){var t;const n=null===(t=e.components)||void 0===t?void 0:t.find((e=>"FOOTER"===e.type));return null==n?void 0:n.text}parseButtonComponent(e){var t,i,o,a,d,r;const v={actionsType:l.ACTIONS_TYPES.NONE,quickReply:[],ctaBtn:{phoneNumber:void 0,websiteLinkBtn:void 0}},s=null===(t=e.components)||void 0===t?void 0:t.find((e=>"BUTTONS"===e.type));if(s&&(null===(i=null==s?void 0:s.buttons)||void 0===i?void 0:i.length)){const t="QUICK_REPLY"===(null===(o=null==s?void 0:s.buttons)||void 0===o?void 0:o[0].type)?l.ACTIONS_TYPES.QUICK_REPLY:l.ACTIONS_TYPES.CTA_BTN;if(v.actionsType=t,t===l.ACTIONS_TYPES.QUICK_REPLY){const e=null!==(d=null===(a=null==s?void 0:s.buttons)||void 0===a?void 0:a.map((e=>e)))&&void 0!==d?d:[];return v.quickReply=e,v}t===l.ACTIONS_TYPES.CTA_BTN&&(null===(r=null==s?void 0:s.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}}})))}return v}parseUITemplateFromDBFormat(t,n){let i=arguments.length>2&&void 0!==arguments[2]&&arguments[2];var l;return e.__awaiter(this,void 0,void 0,(function*(){const{headerType:e,headerAssetLink:o,headerAssetName:a,headerText:d,headerVariables:r}=yield this.parseDataFromHeaderComponent(t),{bodyText:v,bodyVariable:s}=yield this.parseBodyComponent(t,i),{actionsType:E,quickReply:u,ctaBtn:T}=yield this.parseButtonComponent(t),p={quickReply:u,ctaBtn:T,meta:{name:n?`${t.label} Copy`:t.label,category:null===(l=t.category)||void 0===l?void 0:l.toUpperCase(),subCategory:t.templateCategory,language:t.language,templateId:t.templateId},error:{header:void 0,body:void 0,footer:void 0,quickReply:void 0,meta:void 0,ctaBtn:void 0},actionsType:E,footerText:this.parseFooterComponent(t),bodyVariables:s,bodyText:v,headerType:e,headerAssetLink:o,headerAssetName:a,headerText:d,headerVariables:r,alreadyAsADraft:t.isDraft,mode:"edit",initialLoading:!1},{errors:_}=this.validateState(p);return p.error=_,p}))}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__awaiter as e}from"../../../../../_virtual/_tslib.js";import{jsx as o,jsxs as r}from"react/jsx-runtime";import{useState as t,useEffect as a}from"react";import{iterateOnOptions as l}from"../../../../dropdown/OpenedDropdown/utils/iterationOnOptions.js";import i from"../../../components/AllowedListDropdown.js";import n from"../../../components/Connectors/Connector.js";import{ApiResponseHelper as d}from"../../../helpers/ApiResponse.helper.js";import{useQueryBuilder as u}from"../../../hooks/useQueryBuilder.js";import{useQueryBuilderCache as v}from"../../../hooks/useQueryBuilderCache.js";import{QueryBuilderConnectorType as p}from"../../../types/QueryBuilder.type.js";import{FREQUENCY_OPERATORS as s,DATE_OPERATORS as c}from"../../../types/QueryBuilderOperator.type.js";import y from"../../../components/DropdownWrapper.js";import{BaseQueryBuilderNode as m}from"../../../components/QueryBuilderNode/Base/BaseQueryBuilderNode.js";const f=new d,h=d=>{let{node:h,allowedNodes:T,apiHandler:_,mode:j,selectorKey:k}=d;var O,g,N,b,w,P,q,x,C,S,V,B,E,A,D,Q,M,L;const[$,J]=t([]),[K,R]=t(!1),{deleteProperty:W,createProperty:G,selectType:H,createMeta:z,updateMeta:F,updateProperty:I,selectPropertyJoinOperator:U,clearProperty:X}=u(k),{cacheWrap:Y}=v(),[Z,ee]=t(!0),oe=null===(O=null==h?void 0:h.metas)||void 0===O?void 0:O.find((e=>"date"===e.key)),re=null===(g=null==h?void 0:h.metas)||void 0===g?void 0:g.find((e=>"frequency"===e.key)),te=null===(N=null==h?void 0:h.metas)||void 0===N?void 0:N.find((e=>"eventName"===e.key)),[ae,le]=t(!1),[ie,ne]=t(!1),[de,ue]=t(!1);return a((()=>{Y((()=>_({})),"EVENT_NAMES").then((e=>{ee(!1);const o=f.convertToGroupOptions(e,(null==te?void 0:te.value)?[te.value]:void 0);if("create"!==j&&te)return J([...o]),void R(!0);J([...o]),R(!0)}))}),[]),o(m,Object.assign({selectPropertyJoinOperator:U,node:h,addPropertyBtnText:(null==te?void 0:te.value)&&"Add event property",deleteProperty:W,createProperty:G,propertySelectorText:"Select property",fetchPropertyData:function(){return e(this,void 0,void 0,(function*(){var e;return yield(e=null==te?void 0:te.value,Y((()=>_({query:{eventName:e}})),`EVENT_NAMES_${e}`))}))},onPropertyNameSelect:function(o,r){return e(this,void 0,void 0,(function*(){if(I(Object.assign(Object.assign({},r),{name:o.id,dataType:o.type,operator:void 0,value:void 0,error:{}}),h._id),!o.needValuesRetrieval)return[];const e=yield((e,o)=>Y((()=>_({query:{eventName:e,propertyName:o}})),`EVENT_NAMES_${e}_${o}`))(null==te?void 0:te.value,o.id);return null!=e?e:[]}))},onPropertyOperatorChange:function(e,o){I(Object.assign(Object.assign({},o),{operator:e,value:void 0,error:{}}),h._id)},onPropertyValueChange:function(e,o){I(Object.assign(Object.assign({},o),{value:e,error:{}}),h._id)},mode:j,onPropertyValueSearch:function(o,r){var t,a;return e(this,void 0,void 0,(function*(){const l=yield((o,r,t)=>e(void 0,void 0,void 0,(function*(){return yield _({query:{eventName:o,propertyName:r,searchKey:t}})})))(null==te?void 0:te.value,r.name,o);return null!==(a=null===(t=null==l?void 0:l.data)||void 0===t?void 0:t.map((e=>({label:e.name,value:e.id,selected:!1}))))&&void 0!==a?a:[]}))}},{children:r("div",Object.assign({style:{flexDirection:"column",display:"flex",gap:12}},{children:[r("div",Object.assign({style:{flexDirection:"row",display:"flex",gap:12}},{children:[o(i,{disabled:"view"===j,selectedType:h.type,allowedList:T,onSelect:function(e){le(!0),J((e=>[...l(e,{selected:!1})])),setTimeout((()=>{H(e.value,h._id),le(!1)}),1)}}),!ae&&o(y,{isSearchable:!0,isLoading:Z,disabled:"view"===j,width:"200px",dropdownLabel:"Select event name",options:$,selectedValues:(null==te?void 0:te.value)?[te.value]:void 0,onSelect:function(e){Array.isArray(e)||(X(h._id),te?F({key:"eventName",value:e.value,error:{}},h._id):z({key:"eventName",value:e.value},h._id),re?(ne(!0),setTimeout((()=>{F({key:"frequency",value:{dataType:p.frequency,operator:s.atleast,value:1},error:{}},h._id),ne(!1)}),1)):z({key:"frequency",value:{dataType:p.frequency,operator:s.atleast,value:1}},h._id),oe?(ue(!0),setTimeout((()=>{F({key:"date",value:{dataType:p.date,operator:c["last
|
|
1
|
+
import{__awaiter as e}from"../../../../../_virtual/_tslib.js";import{jsx as o,jsxs as r}from"react/jsx-runtime";import{useState as t,useEffect as a}from"react";import{iterateOnOptions as l}from"../../../../dropdown/OpenedDropdown/utils/iterationOnOptions.js";import i from"../../../components/AllowedListDropdown.js";import n from"../../../components/Connectors/Connector.js";import{ApiResponseHelper as d}from"../../../helpers/ApiResponse.helper.js";import{useQueryBuilder as u}from"../../../hooks/useQueryBuilder.js";import{useQueryBuilderCache as v}from"../../../hooks/useQueryBuilderCache.js";import{QueryBuilderConnectorType as p}from"../../../types/QueryBuilder.type.js";import{FREQUENCY_OPERATORS as s,DATE_OPERATORS as c}from"../../../types/QueryBuilderOperator.type.js";import y from"../../../components/DropdownWrapper.js";import{BaseQueryBuilderNode as m}from"../../../components/QueryBuilderNode/Base/BaseQueryBuilderNode.js";const f=new d,h=d=>{let{node:h,allowedNodes:T,apiHandler:_,mode:j,selectorKey:k}=d;var O,g,N,b,w,P,q,x,C,S,V,B,E,A,D,Q,M,L;const[$,J]=t([]),[K,R]=t(!1),{deleteProperty:W,createProperty:G,selectType:H,createMeta:z,updateMeta:F,updateProperty:I,selectPropertyJoinOperator:U,clearProperty:X}=u(k),{cacheWrap:Y}=v(),[Z,ee]=t(!0),oe=null===(O=null==h?void 0:h.metas)||void 0===O?void 0:O.find((e=>"date"===e.key)),re=null===(g=null==h?void 0:h.metas)||void 0===g?void 0:g.find((e=>"frequency"===e.key)),te=null===(N=null==h?void 0:h.metas)||void 0===N?void 0:N.find((e=>"eventName"===e.key)),[ae,le]=t(!1),[ie,ne]=t(!1),[de,ue]=t(!1);return a((()=>{Y((()=>_({})),"EVENT_NAMES").then((e=>{ee(!1);const o=f.convertToGroupOptions(e,(null==te?void 0:te.value)?[te.value]:void 0);if("create"!==j&&te)return J([...o]),void R(!0);J([...o]),R(!0)}))}),[]),o(m,Object.assign({selectPropertyJoinOperator:U,node:h,addPropertyBtnText:(null==te?void 0:te.value)&&"Add event property",deleteProperty:W,createProperty:G,propertySelectorText:"Select property",fetchPropertyData:function(){return e(this,void 0,void 0,(function*(){var e;return yield(e=null==te?void 0:te.value,Y((()=>_({query:{eventName:e}})),`EVENT_NAMES_${e}`))}))},onPropertyNameSelect:function(o,r){return e(this,void 0,void 0,(function*(){if(I(Object.assign(Object.assign({},r),{name:o.id,dataType:o.type,operator:void 0,value:void 0,error:{}}),h._id),!o.needValuesRetrieval)return[];const e=yield((e,o)=>Y((()=>_({query:{eventName:e,propertyName:o}})),`EVENT_NAMES_${e}_${o}`))(null==te?void 0:te.value,o.id);return null!=e?e:[]}))},onPropertyOperatorChange:function(e,o){I(Object.assign(Object.assign({},o),{operator:e,value:void 0,error:{}}),h._id)},onPropertyValueChange:function(e,o){I(Object.assign(Object.assign({},o),{value:e,error:{}}),h._id)},mode:j,onPropertyValueSearch:function(o,r){var t,a;return e(this,void 0,void 0,(function*(){const l=yield((o,r,t)=>e(void 0,void 0,void 0,(function*(){return yield _({query:{eventName:o,propertyName:r,searchKey:t}})})))(null==te?void 0:te.value,r.name,o);return null!==(a=null===(t=null==l?void 0:l.data)||void 0===t?void 0:t.map((e=>({label:e.name,value:e.id,selected:!1}))))&&void 0!==a?a:[]}))}},{children:r("div",Object.assign({style:{flexDirection:"column",display:"flex",gap:12}},{children:[r("div",Object.assign({style:{flexDirection:"row",display:"flex",gap:12}},{children:[o(i,{disabled:"view"===j,selectedType:h.type,allowedList:T,onSelect:function(e){le(!0),J((e=>[...l(e,{selected:!1})])),setTimeout((()=>{H(e.value,h._id),le(!1)}),1)}}),!ae&&o(y,{isSearchable:!0,isLoading:Z,disabled:"view"===j,width:"200px",dropdownLabel:"Select event name",options:$,selectedValues:(null==te?void 0:te.value)?[te.value]:void 0,onSelect:function(e){Array.isArray(e)||(X(h._id),te?F({key:"eventName",value:e.value,error:{}},h._id):z({key:"eventName",value:e.value},h._id),re?(ne(!0),setTimeout((()=>{F({key:"frequency",value:{dataType:p.frequency,operator:s.atleast,value:1},error:{}},h._id),ne(!1)}),1)):z({key:"frequency",value:{dataType:p.frequency,operator:s.atleast,value:1}},h._id),oe?(ue(!0),setTimeout((()=>{F({key:"date",value:{dataType:p.date,operator:c["last 30 days"]},error:{}},h._id),ue(!1)}),1)):z({key:"date",value:{dataType:p.date,operator:c["last 30 days"]}},h._id))},error:null!==(C=null!==(q=null===(P=null===(w=null===(b=h.metas)||void 0===b?void 0:b[0])||void 0===w?void 0:w.error)||void 0===P?void 0:P.key)&&void 0!==q?q:null===(x=null==te?void 0:te.error)||void 0===x?void 0:x.key)&&void 0!==C?C:null===(S=null==te?void 0:te.error)||void 0===S?void 0:S.value})]})),(null==re?void 0:re.key)&&!ie&&o(n,{disabled:"view"===j,extra:{},errors:{val:null===(B=null===(V=re.error)||void 0===V?void 0:V.value)||void 0===B?void 0:B.value,operator:null===(A=null===(E=re.error)||void 0===E?void 0:E.value)||void 0===A?void 0:A.operator},connectorVal:re.value.value,connectorType:re.value.dataType,defaultConnector:re.value.operator,onOperatorChange:function(e){F({key:"frequency",value:{dataType:p.frequency,operator:e,value:1},error:{}},h._id)},onValueChange:function(e){var o;K&&F({key:"frequency",value:{dataType:p.frequency,operator:null===(o=null==re?void 0:re.value)||void 0===o?void 0:o.operator,value:e},error:{}},h._id)}}),(null==oe?void 0:oe.key)&&!de&&o(n,{disabled:"view"===j,extra:{},errors:{val:null===(Q=null===(D=oe.error)||void 0===D?void 0:D.value)||void 0===Q?void 0:Q.value,operator:null===(L=null===(M=oe.error)||void 0===M?void 0:M.value)||void 0===L?void 0:L.operator},connectorVal:oe.value.value,connectorType:oe.value.dataType,defaultConnector:oe.value.operator,onOperatorChange:function(e){F({key:"date",value:{dataType:p.date,operator:e,value:void 0},error:{}},h._id)},onValueChange:function(e){var o;K&&F({key:"date",value:{dataType:p.date,operator:null===(o=null==oe?void 0:oe.value)||void 0===o?void 0:o.operator,value:e},error:{}},h._id)}})]}))}))};export{h as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=[{label:"Commonly used",options:[{selected:!1,value:"today",label:"Today",description:"Events performed in the current day (starting at 00:00 hours)"},{selected:!1,value:"yesterday",label:"Yesterday",description:"Events performed in the previous day (starting at 00:00 hours)"},{selected:!1,value:"last 7 days",label:"Last 7 days",description:"Events performed in the previous 7 complete days along with the current day"},{selected:!
|
|
1
|
+
const e=[{label:"Commonly used",options:[{selected:!1,value:"today",label:"Today",description:"Events performed in the current day (starting at 00:00 hours)"},{selected:!1,value:"yesterday",label:"Yesterday",description:"Events performed in the previous day (starting at 00:00 hours)"},{selected:!1,value:"last 7 days",label:"Last 7 days",description:"Events performed in the previous 7 complete days along with the current day"},{selected:!0,value:"last 30 days",label:"Last 30 days",description:"Events performed in the previous 30 complete days along with the current day"},{selected:!1,value:"this week",label:"This week",description:"Events performed in the current calendar week (starting Monday), including the current day"},{selected:!1,value:"last week",label:"Last week",description:"Events performed in the previous calendar week (starting Monday)"},{selected:!1,value:"this month",label:"This month",description:"Events performed in the current calendar month, including the current day"},{selected:!1,value:"last month",label:"Last month",description:"Events performed in the current calendar month, including the current day"}]},{label:"Relative",options:[{selected:!1,value:"exactly",label:"Exactly",description:"Events performed precisely in a specific time frame (days, hours, or minutes) before the current time"},{selected:!1,value:"in the last",label:"In the last",description:"Events performed within the period between the current time and a specified time frame (days, hours, or minutes), relative to and before the current time"},{selected:!1,value:"in between last",label:"In between last",description:"Events performed within the range from one specific time frame to another specific time frame, both relative to and before the current time"}]},{label:"Absolute",options:[{selected:!1,value:"on",label:"On",description:"Events performed exactly on a particular date"},{selected:!1,value:"notOn",label:"Not On"},{selected:!1,value:"inBetween",label:"In Between",description:"Events performed between a specified date range"},{selected:!1,value:"notInBetween",label:"Not In Between"},{selected:!1,value:"before",label:"Before",description:"Events performed before a particular date (excluding that particular date)"},{selected:!1,value:"after",label:"After",description:"Events performed after a particular date (excluding that particular date)"}]}];export{e as DATE_OPERATORS_OPTIONS};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const a=/\[\[[A-Za-z0-9 .]+\]\]/,z=/\((\(|\[)[A-Za-z0-9 ]+(\]|\))\)/,A=/(\[\[|\(\()
|
|
1
|
+
const a=/\[\[[A-Za-z0-9 .]+\]\]/,z=/\((\(|\[)[A-Za-z0-9 ]+(\]|\))\)/,A=/(\[\[|\(\()(.*)(\)\)|\]\])/,Z=/\{\{[A-Za-z0-9 .]+\}\}/g,g=/\{\{[a-zA-Z0-9]+(?=( |\}))(?!\}\})/g,_=/[!@#$%^&*()_+\-={};':"\\|,.<>?]+/,o=/\{\{[A-Za-z0-9 ._]+\}\}/,t=/\{\{[A-Za-z0-9 _]+\}\}/g,c=Z,e=/\[([^[]+)\](\(.*\))/,n=/[((|))]/;export{n as editableBracketPattern,z as editableVarPattern,g as globalHalfVariablePattern,Z as globalVariablePattern,a as lockedVarPattern,A as placeHolderNamePattern,e as previewLinkMDFormatPattern,_ as specialCharPattern,c as templateVariablePattern,o as variablePattern,t as variablePatternGlobal};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__awaiter as e}from"../../../_virtual/_tslib.js";import{COLORS as t}from"../../../constants/Theme.js";import{specialCharPattern as n,placeHolderNamePattern as i,editableVarPattern as o}from"../constants/regexPatterns.js";import{REQUIRED_FIELD as l,NAME_LEN_LIMIT as a,NAME_LEN_ERROR as d,NO_SPECIAL_CHAR as r,HEADER_TEXT_LEN_LIMIT as v,HEADER_LEN_ERROR as s,ONE_VAR_ALLOWED as u,HEADER_ASSET_LINK_ERROR as p,BODY_TEXT_LEN_LIMIT as c,BODY_LEN_ERROR as m,QUICK_REPLY_BTN_TEXT_LIMIT as h,QUICK_REPLY_LEN_ERROR as b,BUTTON_EMOJI_ERROR as T,VALID_PHONE_NUMBER as y,QUICK_REPLY_NAME_LEN_LIMIT as B,CREATE_TEMPLATE_DOM_IDS as x,QUICK_REPLY_NAME_ERROR as f}from"../constants/TemplateConstants.js";import{HEADER_TYPES as k,ACTIONS_TYPES as N}from"../models/TemplateMeta.js";import{TemplateHelperUtils as g}from"../utils/TemplateHelperUtils.js";class C{parseDataFromHeaderComponent(e){var t,n,i,o,l,a,d,r,v,s;const u={headerType:k.NONE,headerVariables:[]},p=null===(t=e.components)||void 0===t?void 0:t.find((e=>"HEADER"===e.type));if(p){u.headerType=p.format,u.headerText=p.text,u.headerAssetLink=null===(i=null===(n=p.example)||void 0===n?void 0:n.header_handle)||void 0===i?void 0:i[0];const t=null===(l=null===(o=p.example)||void 0===o?void 0:o.header_text)||void 0===l?void 0:l[0],c=null===(d=null===(a=e.mapping)||void 0===a?void 0:a.header)||void 0===d?void 0:d[0];if(t&&c){const e=null==c?void 0:c.replace("[[","").replace("]]","").replace("
|
|
1
|
+
import{__awaiter as e}from"../../../_virtual/_tslib.js";import{COLORS as t}from"../../../constants/Theme.js";import{specialCharPattern as n,placeHolderNamePattern as i,editableVarPattern as o}from"../constants/regexPatterns.js";import{REQUIRED_FIELD as l,NAME_LEN_LIMIT as a,NAME_LEN_ERROR as d,NO_SPECIAL_CHAR as r,HEADER_TEXT_LEN_LIMIT as v,HEADER_LEN_ERROR as s,ONE_VAR_ALLOWED as u,HEADER_ASSET_LINK_ERROR as p,BODY_TEXT_LEN_LIMIT as c,BODY_LEN_ERROR as m,QUICK_REPLY_BTN_TEXT_LIMIT as h,QUICK_REPLY_LEN_ERROR as b,BUTTON_EMOJI_ERROR as T,VALID_PHONE_NUMBER as y,QUICK_REPLY_NAME_LEN_LIMIT as B,CREATE_TEMPLATE_DOM_IDS as x,QUICK_REPLY_NAME_ERROR as f}from"../constants/TemplateConstants.js";import{HEADER_TYPES as k,ACTIONS_TYPES as N}from"../models/TemplateMeta.js";import{TemplateHelperUtils as g}from"../utils/TemplateHelperUtils.js";class C{parseDataFromHeaderComponent(e){var t,n,i,o,l,a,d,r,v,s;const u={headerType:k.NONE,headerVariables:[]},p=null===(t=e.components)||void 0===t?void 0:t.find((e=>"HEADER"===e.type));if(p){u.headerType=p.format,u.headerText=p.text,u.headerAssetLink=null===(i=null===(n=p.example)||void 0===n?void 0:n.header_handle)||void 0===i?void 0:i[0];const t=null===(l=null===(o=p.example)||void 0===o?void 0:o.header_text)||void 0===l?void 0:l[0],c=null===(d=null===(a=e.mapping)||void 0===a?void 0:a.header)||void 0===d?void 0:d[0];if(t&&c){const e=null==c?void 0:c.replace("[[","").replace("]]","").replace("((","").replace("))",""),n=/\(\(/.test(c),i={idx:0,variableVal:t,editable:n,editableDefaultValues:n?void 0:t,variableName:e};u.headerVariables=[i],(null===(v=null===(r=p.example)||void 0===r?void 0:r.header_text)||void 0===v?void 0:v.length)&&(u.headerText=null===(s=u.headerText)||void 0===s?void 0:s.replace("{{1}}",`{{${e}}}`))}}return u}validateState(e){var t,i,o,C,L,E,R,_,w,A,V,I,D,U,O,q,F,j,P,$,Y;const K=/\p{Extended_Pictographic}/u;let M="valid";const Q={meta:{},ctaBtn:{phoneNumber:{btnText:"",link:""},websiteLink:{btnText:"",link:""}},quickReply:[null,null,null]},H=new g;let S=!1;const G=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)?e.meta.name.trim().length>a?(Q.meta.name=d,M="invalid"):n.test(e.meta.name.trim())&&(Q.meta.name=r,M="invalid"):(Q.meta.name=l,M="invalid"),Q.meta.name&&!S&&(G(x.name),S=!0),e.headerType===k.TEXT){const t=null!==(o=null===(i=e.headerText)||void 0===i?void 0:i.trim())&&void 0!==o?o:"";if(t)if(t.length>v)Q.header=s,M="invalid";else{const e=H.getTemplateVariablesFromState(t);e&&e.length>1&&(Q.header=u,M="invalid")}else Q.header=l,M="invalid"}else e.headerType===k.DOCUMENT||e.headerType===k.IMAGE||(e.headerType,k.VIDEO);if(e.headerType!==k.DOCUMENT&&e.headerType!==k.IMAGE&&e.headerType!==k.VIDEO||e.headerAssetLink||(Q.header=p,M="invalid"),Q.header&&!S&&(G(x.header),S=!0),e.bodyText?e.bodyTextRaw&&(null===(C=e.bodyTextRaw)||void 0===C?void 0:C.trim().length)>c&&(Q.body=m,M="invalid"):(Q.body=l,M="invalid"),Q.body&&!S&&(G(x.body),S=!0),e.footerText&&e.footerText.length>v&&(Q.footer=s,M="invalid"),(null==Q?void 0:Q.footer)&&!S&&(G(x.footer),S=!0),e.actionsType===N.CTA_BTN){if(null===(E=null===(L=e.ctaBtn)||void 0===L?void 0:L.phoneNumber)||void 0===E?void 0:E.isChecked){const t=null===(R=e.ctaBtn.phoneNumber.btnText)||void 0===R?void 0:R.trim(),n=e.ctaBtn.phoneNumber.phoneNumber;Q.ctaBtn&&!t?(Q.ctaBtn.phoneNumber.btnText=l,M="invalid"):Q.ctaBtn&&t&&t.length>h?(Q.ctaBtn.phoneNumber.btnText=b,M="invalid"):Q.ctaBtn&&t&&K.test(t)&&(Q.ctaBtn.phoneNumber.btnText=T,M="invalid"),Q.ctaBtn&&!n?(Q.ctaBtn.phoneNumber.link=l,M="invalid"):Q.ctaBtn&&n&&n.length<10&&(Q.ctaBtn.phoneNumber.link=y,M="invalid")}if(null===(w=null===(_=e.ctaBtn)||void 0===_?void 0:_.websiteLinkBtn)||void 0===w?void 0:w.isChecked){const t=null===(A=e.ctaBtn.websiteLinkBtn.btnText)||void 0===A?void 0:A.trim(),n=null===(V=e.ctaBtn.websiteLinkBtn.linkOpens)||void 0===V?void 0:V.trim(),i=null===(I=e.ctaBtn.websiteLinkBtn.placeholder)||void 0===I?void 0:I.trim();Q.ctaBtn&&!t?(Q.ctaBtn.websiteLink.btnText=l,M="invalid"):Q.ctaBtn&&t&&t.length>h?(Q.ctaBtn.websiteLink.btnText=b,M="invalid"):Q.ctaBtn&&t&&K.test(t)&&(Q.ctaBtn.websiteLink.btnText=T,M="invalid"),!Q.ctaBtn||n||i||(Q.ctaBtn.websiteLink.link=l,M="invalid")}}else if(e.actionsType===N.QUICK_REPLY){const t=["","",""];e.quickReply.forEach(((n,i)=>{const o=n.text.trim();if(o)if(o.length>B)t[i]=b,M="invalid";else if(K.test(o))t[i]=T,M="invalid";else{const n=[...e.quickReply];n.splice(i,1);n.find((e=>e.text===o))&&(t[i]=f,M="invalid")}else t[i]=l,M="invalid"})),Q.quickReply=t}if(e.actionsType===N.CTA_BTN||e.actionsType===N.QUICK_REPLY){const e=null===(D=Q.quickReply)||void 0===D?void 0:D.reduce(((e,t)=>e||!!t),!1);((null===(O=null===(U=null==Q?void 0:Q.ctaBtn)||void 0===U?void 0:U.websiteLink)||void 0===O?void 0:O.link)||(null===(F=null===(q=Q.ctaBtn)||void 0===q?void 0:q.websiteLink)||void 0===F?void 0:F.btnText)||(null===(P=null===(j=Q.ctaBtn)||void 0===j?void 0:j.phoneNumber)||void 0===P?void 0:P.link)||(null===(Y=null===($=Q.ctaBtn)||void 0===$?void 0:$.phoneNumber)||void 0===Y?void 0:Y.btnText)||e)&&!S&&(G(x.actionButtons),S=!0)}return{status:M,errors:Q}}parseBodyComponent(e){let n=arguments.length>1&&void 0!==arguments[1]&&arguments[1];var o,l,a,d,r;const v=[];let s="";const u=null===(o=e.components)||void 0===o?void 0:o.find((e=>"BODY"===e.type));return u&&(null===(a=null===(l=u.example)||void 0===l?void 0:l.body_text)||void 0===a||a[0].forEach(((t,n)=>{var o,l;let a=null===(l=null===(o=e.mapping)||void 0===o?void 0:o.body)||void 0===l?void 0:l[n];const d=a&&/\(\(/.test(a),r=null==a?void 0:a.match(i);(null==r?void 0:r[2])&&(a=null==r?void 0:r[2]),v.push({idx:n,variableVal:t,editable:!!d,editableDefaultValues:d?void 0:t,variableName:null!=a?a:""})})),s=e.htmlContentUrl?e.htmlContentUrl:(null===(d=u.text)||void 0===d?void 0:d.split(/\{\{[0-9]+\}\}/).length)?null===(r=u.text)||void 0===r?void 0:r.split(/\{\{[0-9]+\}\}/).map(((e,i)=>{if(null==v?void 0:v[i]){const o=v[i].variableName;return n?`${e}{{${o}}}`:`${e} <span> </span><span style="color: ${t.content.brand}; text-decoration: underline;">{{${o}}}</span><span> </span>`}return e})).join(""):""),{bodyVariable:v,bodyText:s}}parseFooterComponent(e){var t;const n=null===(t=e.components)||void 0===t?void 0:t.find((e=>"FOOTER"===e.type));return null==n?void 0:n.text}parseButtonComponent(e){var t,n,i,l,a,d;const r={actionsType:N.NONE,quickReply:[],ctaBtn:{phoneNumber:void 0,websiteLinkBtn:void 0}},v=null===(t=e.components)||void 0===t?void 0:t.find((e=>"BUTTONS"===e.type));if(v&&(null===(n=null==v?void 0:v.buttons)||void 0===n?void 0:n.length)){const t="QUICK_REPLY"===(null===(i=null==v?void 0:v.buttons)||void 0===i?void 0:i[0].type)?N.QUICK_REPLY:N.CTA_BTN;if(r.actionsType=t,t===N.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:[];return r.quickReply=e,r}t===N.CTA_BTN&&(null===(d=null==v?void 0:v.buttons)||void 0===d||d.forEach((t=>{var n,i,l,a;if(t.phone_number&&(r.ctaBtn.phoneNumber={isChecked:!0,btnText:t.text,phoneNumber:t.phone_number}),t.url){const d=null!==(l=null===(i=null===(n=null==e?void 0:e.mapping)||void 0===n?void 0:n.buttons)||void 0===i?void 0:i[0])&&void 0!==l?l:void 0;let v=!1;d&&o.test(d)&&(v=!0),r.ctaBtn.websiteLinkBtn={isChecked:!0,btnText:t.text,linkOpens:v?null===(a=t.example)||void 0===a?void 0:a[0]:t.url,placeholder:v?void 0:d}}})))}return r}parseUITemplateFromDBFormat(t,n){let i=arguments.length>2&&void 0!==arguments[2]&&arguments[2];var o;return e(this,void 0,void 0,(function*(){const{headerType:e,headerAssetLink:l,headerAssetName:a,headerText:d,headerVariables:r}=yield this.parseDataFromHeaderComponent(t),{bodyText:v,bodyVariable:s}=yield this.parseBodyComponent(t,i),{actionsType:u,quickReply:p,ctaBtn:c}=yield this.parseButtonComponent(t),m={quickReply:p,ctaBtn:c,meta:{name:n?`${t.label} Copy`:t.label,category:null===(o=t.category)||void 0===o?void 0:o.toUpperCase(),subCategory:t.templateCategory,language:t.language,templateId:t.templateId},error:{header:void 0,body:void 0,footer:void 0,quickReply:void 0,meta:void 0,ctaBtn:void 0},actionsType:u,footerText:this.parseFooterComponent(t),bodyVariables:s,bodyText:v,headerType:e,headerAssetLink:l,headerAssetName:a,headerText:d,headerVariables:r,alreadyAsADraft:t.isDraft,mode:"edit",initialLoading:!1},{errors:h}=this.validateState(m);return m.error=h,m}))}}export{C as TemplateCreatorHelper};
|