1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[9938],{99938:function(e,o,t){Object.defineProperty(o,"__esModule",{value:!0});let i=t(44610),n=t(67462),{clearGuestTypeFilters:r,sortMenuAlpha:l,intList:a}=t(46212),d=n._(i._({},a.touchepos||{}),{afterVenueCreate:"/manager/integrations?type=touchepos",successfullConnectionValue:"venueId",description:[{heading:!0,text:"Connect"},{text:"Connect your Touche POS for:",style:{marginTop:20}},{icon:"tickCircleSolidGreen",text:"Unlimited Free menu sync",style:{marginTop:20}},{icon:"tickCircleSolidGreen",text:"Submitted orders will appear in Touche POS",style:{marginTop:10}},{icon:"alert",text:"You will need your Touche POS API Key and Venue ID. Contact your Touche POS representative to obtain these credentials.",style:{marginTop:20}},{hideIf:"integrations.touchepos.venueId",heading:!0,text:"STEP 1 - Enter your API Key",style:{marginTop:20}},{hideIf:"integrations.touchepos.venueId",text:"Found in your Touche POS back office under Settings > API Access",style:{marginTop:10}},{hideIf:"integrations.touchepos.venueId",type:"input",placeholder:"API Key",value:"toucheposApiKey",update:{setNestedState:!0}},{hideIf:"integrations.touchepos.venueId",heading:!0,text:"STEP 2 - Enter your Venue ID",style:{marginTop:20}},{hideIf:"integrations.touchepos.venueId",text:"Your unique Touche POS venue identifier",style:{marginTop:10}},{hideIf:"integrations.touchepos.venueId",type:"input",placeholder:"Venue ID",value:"toucheposVenueId",update:{setNestedState:!0},button:{icon:"save",onClick:e=>d.setup(e)}},{showIf:"integrations.touchepos.venueId",type:"toggleActive"},{showIf:"integrations.touchepos.venueId",type:"integrationError"},{showIf:"integrations.touchepos.venueId",type:"manualUpdate"},{showIf:"integrations.touchepos.venueId",type:"clearConfig"}],setup:async e=>{var o,t;let{v:a,backup:s,state:u}=e,c=(null==u?void 0:u.toucheposApiKey)||"",p=(null==u?void 0:u.toucheposVenueId)||"";if(!c||!p){a.handleError({v:a,error:"Please fill in all fields: API Key and Venue ID"});return}let v=d.helpers.getBaseUrl(a),g=await a.cloudFunction({v:a,name:"custom",params:{httpRequest:{params:["get","".concat(v,"/api/v1/venues/").concat(p),void 0,d.helpers.getOptions({apiKey:c})]}}}),m=null==g?void 0:g.data,h=(null==m?void 0:m.name)||(null==m?void 0:m.venueName)||"",y=(null==m?void 0:m.currency)||(null==m?void 0:m.currencyCode)||"";if(console.log("touchepos setup venueResp",JSON.stringify(m)),await s({v:a,type:"create"}),h||m&&!m.error&&!m.errors){console.log("Touche POS Correct Key, Proceeding with venueId",p);let o=a.info.integrations||{};o.touchepos={active:!0,apiKey:c,venueId:p,baseUrl:v,venueName:h,currency:y},console.log("Touche POS updateIntegrations",p,h),a.updateData({v:a,integrations:o}),r(a),l(a),d.get(n._(i._({},e),{apiKey:c,venueId:p}))}else a.handleError({v:a,error:(null==m?void 0:m.error)||(null==m?void 0:null===(t=m.errors)||void 0===t?void 0:null===(o=t[0])||void 0===o?void 0:o.message)||"Invalid credentials. Please check your Touche POS API Key and Venue ID, or contact support at ".concat(a.wlc.supportEmail)})},get:async e=>{var o,t,r,l,a,s,u,c,p,v,g,m;let h;let{v:y,apiKey:f,venueId:I}=e;console.log("get Touche POS Menu",y),f=f||(null===(r=y.info)||void 0===r?void 0:null===(t=r.integrations)||void 0===t?void 0:null===(o=t.touchepos)||void 0===o?void 0:o.apiKey)||"",I=I||(null===(s=y.info)||void 0===s?void 0:null===(a=s.integrations)||void 0===a?void 0:null===(l=a.touchepos)||void 0===l?void 0:l.venueId)||"";let S=d.helpers.getBaseUrl(y),O=async()=>{let e=d.helpers.getOptions({apiKey:f}),o=async o=>{let t=[],i=0;do{var n,r,l=await y.cloudFunction({v:y,name:"custom",params:{httpRequest:{params:["get","".concat(o).concat(o.includes("?")?"&":"?","limit=").concat(200,"&offset=").concat(i),void 0,e]}}});let a=(null==l?void 0:null===(n=l.data)||void 0===n?void 0:n.items)||(null==l?void 0:null===(r=l.data)||void 0===r?void 0:r.data)||(null==l?void 0:l.data);if(!Array.isArray(a)||!a.length)break;t=t.concat(a),i+=200}while(t.length%200==0);return t},[t,i,n,r]=await Promise.all([o("".concat(S,"/api/v1/venues/").concat(I,"/categories")),o("".concat(S,"/api/v1/venues/").concat(I,"/menu-items")),o("".concat(S,"/api/v1/venues/").concat(I,"/modifier-groups")),o("".concat(S,"/api/v1/venues/").concat(I,"/taxes"))]);console.log("touchepos getData raw",null==t?void 0:t.length,null==i?void 0:i.length,null==n?void 0:n.length,null==r?void 0:r.length),console.log("touchepos getData trimmed",h={categories:t,menuItems:i,modifierGroups:n,taxes:r,errors:[]})};await O(),console.log("get Touche POS Menu Resp 1",y,h);let k=null==h?void 0:null===(u=h.menuItems)||void 0===u?void 0:u.length;if(console.log("get touchepos has items",y,k),k||(await new Promise(e=>setTimeout(e,1e4)),await O(),k=null==h?void 0:null===(c=h.menuItems)||void 0===c?void 0:c.length,console.log("get Touche POS Menu Resp 2",y,h)),k)y.setState({integrationError:""}),d.mapData(n._(i._({},e),{data:h,venueId:I}));else{let e=(null==h?void 0:null===(v=h.errors)||void 0===v?void 0:null===(p=v[0])||void 0===p?void 0:p.message)||(null==h?void 0:null===(m=h.errors)||void 0===m?void 0:null===(g=m[0])||void 0===g?void 0:g.detail)||"No items found";y.setState({integrationError:{error:e,description:"Please check your Touche POS account and API credentials then click MANUAL UPDATE. If this error persists, please DISCONNECT and RECONNECT Touche POS"}})}},mapData:e=>{var o,t,r,l,a,d;let{v:s,data:u,venueId:c}=e,p={},v={};c=c||(null===(r=s.info)||void 0===r?void 0:null===(t=r.integrations)||void 0===t?void 0:null===(o=t.touchepos)||void 0===o?void 0:o.venueId)||"";let g=(null==u?void 0:u.categories)||[],m=(null==u?void 0:u.menuItems)||[],h=(null==u?void 0:u.modifierGroups)||[],y=(null==u?void 0:u.taxes)||[],f=s.currencySymbol||"$",I=g.reduce((e,o)=>n._(i._({},e),{[o.id||o.categoryId]:o}),{}),S=h.reduce((e,o)=>n._(i._({},e),{[o.id||o.modifierGroupId]:o}),{});
1y&&y.forEach(e=>{let o=e.id||e.taxId||"";o&&(v[o]={name:e.name||e.taxName||"",rate:parseFloat(e.rate||e.percentage||0),manual:!0,included:void 0===e.included||e.included})}),console.log("touchepos tax data",v);let O=m.map(e=>{var o,t,n,r;let l=e.id||e.itemId||e.menuItemId||"",a=e.name||e.itemName||"",d=e.description||"",s=parseFloat(e.price||e.unitPrice||e.basePrice||0),u=e.image||e.imageUrl||e.imageUri||"",c=!1!==e.active&&!1!==e.available;if(!l||!c)return null;let p=e.categoryId||(null===(o=e.category)||void 0===o?void 0:o.id)||e.categories&&e.categories[0]||"",v={index:-1,required:!0,multipleSelect:!1,name:"Select",options:{[String(l)]:{key:String(l),option:a,priceAdjust:s,selected:!0}}},g={},m=e.modifierGroups||e.modifiers||[];Array.isArray(m)&&m.forEach(e=>{let o=e.id||e.modifierGroupId||e,t=S[o]||("object"==typeof e?e:null);if(!t)return;let i=String(t.id||t.modifierGroupId||o),n=t.name||t.groupName||"Options",r=t.required||t.minSelection>0||!1,l=!1!==t.multiSelect&&1!==t.maxSelection,a=t.modifiers||t.options||t.items||[],d={};a.forEach((e,o)=>{let t=String(e.id||e.modifierId||e.optionId||""),i=e.name||e.optionName||"",n=parseFloat(e.price||e.priceAdjust||0);t&&(d[t]={key:t,option:i,priceAdjust:n,selected:0===o&&!!r})}),Object.keys(d).length&&(g[i]={key:i,required:r,multipleSelect:l,name:n,index:"",options:d})});let h=e.taxIds||(e.taxId?[String(e.taxId)]:[]),y=(null==v?void 0:null===(r=v.options)||void 0===r?void 0:null===(t=r[null===(n=Object.keys((null==v?void 0:v.options)||""))||void 0===n?void 0:n[0]])||void 0===t?void 0:t.priceAdjust)||"";return{key:String(l),active:!0,description:"".concat(d," ").concat(y?f+y:"").trim(),image:u,price:0,title:a,variance:i._({variants:v},g),categories:p?[String(p)]:[],taxIds:h}}).filter(Boolean);O&&O.forEach(e=>{var o,t,i,n,r;let l=(null==e?void 0:null===(o=e.categories)||void 0===o?void 0:o[0])||"";if(Object.keys((null===(i=e.variance)||void 0===i?void 0:null===(t=i.variants)||void 0===t?void 0:t.options)||{}).length){if(l){console.log("touchepos not skipped category");let o=I[l];p[l]=p[l]||{menuTitle:(null==o?void 0:o.name)||(null==o?void 0:o.categoryName)||"Category",active:!0,menuItems:{}},p[l].menuItems[e.key]=e}else console.log("touchepos not skipped allitems"),p.allItems=p.allItems||{menuTitle:"Menu",active:!0,menuItems:{}},p.allItems.menuItems[e.key]=e}else console.log("touchepos FILTERING skip no opt",null===(r=e.variance)||void 0===r?void 0:null===(n=r.variants)||void 0===n?void 0:n.options)});let k={menuItemGroupsNew:p||{},currency:(null===(d=s.info)||void 0===d?void 0:null===(a=d.integrations)||void 0===a?void 0:null===(l=a.touchepos)||void 0===l?void 0:l.currency)||s.currency||"USD",dietTags:"",taxes:v};console.log("xxx saving",k),s.manager&&s.updateData({v:s,info:i._({},k)}),s.setState2({info:k,lb:""})},afterOrder:async e=>{d.createOrder(e)},updateOrder:async e=>{var o;let{req:t,orders:i}=e,n=t.body,r=(null==n?void 0:n.event)||(null==n?void 0:n.eventType)||"",l=(null==n?void 0:null===(o=n.data)||void 0===o?void 0:o.order)||(null==n?void 0:n.order)||n;console.log("touchepos updateOrder webhook",r,JSON.stringify(n));let a=(null==l?void 0:l.id)||(null==l?void 0:l.orderId);if(!a){console.log("touchepos updateOrder - no order id in payload");return}let d=(null==l?void 0:l.status)||(null==l?void 0:l.orderStatus)||"",s="accepted"===d||"confirmed"===d?{status:3}:"preparing"===d||"in_progress"===d?{status:3}:"ready"===d||"prepared"===d?{status:4}:"completed"===d||"fulfilled"===d?{status:5}:"cancelled"===d||"rejected"===d?{status:7}:{};if(console.log("touchepos updateOrder status mapping","orderStatus:",d,"mapped:",JSON.stringify(s)),!Object.keys(s).length){console.log("touchepos updateOrder - no status change to map",d);return}let u=await i({type:"findByExternalRef",externalRef:String(a)});if(u.error){console.log("touchepos updateOrder -",u.error,a);return}console.log("touchepos updateOrder found order",u.clientKey,u.orderId,"current status:",u.order.status,"new:",JSON.stringify(s)),await i({type:"update",clientKey:u.clientKey,orderId:u.orderId,update:s}),console.log("touchepos updateOrder SUCCESS",u.clientKey,u.orderId)},createOrder:async e=>{var o,t,n,r,l,a,d,s,u,c,p,v;let g,{order:m,orders:h}=e,y=null===(o=m.integrations)||void 0===o?void 0:o.touchepos,f=m.whiteLabelConfig||{};if(console.log("touchepos createOrder START:",JSON.stringify(y)),!y)return;let I=y.baseUrl||"https://api.gotouche.com",S=y.venueId,O=y.apiKey,k=[];
1m.basket&&m.basket.itemsNew&&m.basket.itemsNew.forEach(e=>{var o;console.log("touchepos createOrder item",JSON.stringify(e));let t=e.variance&&e.variance.variants&&(null===(o=Object.entries(e.variance.variants.options).filter(e=>e[1].selected)[0])||void 0===o?void 0:o[1]);console.log("touchepos createOrder variant",JSON.stringify(t));let n=[];e.variance&&Object.entries(e.variance).forEach(e=>{"variants"!==(e=i._({key:e[0]},e[1])).key&&e.options&&Object.entries(e.options).forEach(e=>{(e=i._({key:e[0]},e[1])).selected&&n.push({modifierId:e.key,name:e.option,price:e.priceAdjust||0})})}),k.push({menuItemId:(null==t?void 0:t.key)||e.key||"",name:e.title||"",quantity:e.quantitySelected||1,unitPrice:(null==t?void 0:t.priceAdjust)||0,modifiers:n.length?n:void 0,notes:e.notes||void 0})}),console.log("touchepos createOrder items",JSON.stringify(k));let T=(null===(l=m.time)||void 0===l?void 0:null===(r=l.toDate)||void 0===r?void 0:null===(n=r.call(l))||void 0===n?void 0:null===(t=n.toISOString)||void 0===t?void 0:t.call(n))||new Date().toISOString()||"NA",N=m.custName||(null===(a=m.userInfo)||void 0===a?void 0:a.name)||"Customer",b=m.tableName?"".concat(m.tableName," - ").concat(N):N,w=(null===(d=m.guestType)||void 0===d?void 0:d.delivery)?"delivery":(null===(s=m.guestType)||void 0===s?void 0:s.takeaway)?"takeaway":"dine_in",P={externalOrderId:(null===(u=m.key)||void 0===u?void 0:u.slice(-48))||String(Date.now()),venueId:S,orderType:w,orderTime:T,customer:{name:b,phone:(null===(c=m.userInfo)||void 0===c?void 0:c.phone)||"",email:(null===(p=m.userInfo)||void 0===p?void 0:p.email)||""},tableName:m.tableName||void 0,notes:(null===(v=m.basket)||void 0===v?void 0:v.basketNotes)||void 0,items:k,source:f.businessName||"QR App"};console.log("touchepos createOrder payload",JSON.stringify(P));for(let e=1;e<=3;e++){try{let o=await fetch("".concat(I,"/api/v1/venues/").concat(S,"/orders"),{method:"POST",headers:{"x-api-key":O,"Content-Type":"application/json"},body:JSON.stringify(P)});if(g=await o.json(),console.log("touchepos createOrder response attempt",e,JSON.stringify(g)),!g.errors&&!g.error||o.status<500)break;console.log("touchepos createOrder 5XX error, retrying...",e)}catch(o){console.log("touchepos createOrder fetch error attempt",e,o.message),g={error:o.message}}e<3&&await new Promise(e=>setTimeout(e,5e3))}let x=(null==g?void 0:g.orderId)||(null==g?void 0:g.id)?{ref:g.orderId||g.id}:{error:(null==g?void 0:g.error)||"Unknown error",resFull:g};h({type:"update2",clientKey:m.clientKey,orderId:m.orderId,update:{externalRef:x}})},helpers:{getBaseUrl:e=>"test"===e.env?"https://api-sandbox.gotouche.com":"https://api.gotouche.com",getOptions:e=>{let{apiKey:o}=e;return{headers:{"x-api-key":o,"Content-Type":"application/json"}}},getError:e=>{var o,t,i,n;return(null==e?void 0:e.error)||(null==e?void 0:null===(t=e.errors)||void 0===t?void 0:null===(o=t[0])||void 0===o?void 0:o.message)||(null==e?void 0:null===(n=e.errors)||void 0===n?void 0:null===(i=n[0])||void 0===i?void 0:i.detail)||"Touche POS Error"}}});e.exports=d}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.