{"version":3,"sources":["webpack://web-components-es6-loader/./src/tracking.ts","webpack://web-components-es6-loader/./src/casper.ts"],"names":["eventObj","event","component_name","experience_name","experience_rule","experience_match","event_raised_by","trackCasperMatchOrMismatch","component","window","module","variations","personalisation","name","rules","rule","asyncRules","createCasperExperience","resolve","undefined","isRunningPreview","Error","firstVariationId","variation","getFirstPersoVariationId","instanciateExperience","projectId","order","hasAsync","hasAsyncTargetingRules","experience","noTracking","functionBody","Function","createRule","data","displayNewVariation","variationId","onCasperMatch","hasSpecificRule","hasMismatchTargetingRule","project","componentId","findComponentData","e","console","setTimeout","onCasperMismatch","hasDefaultVariation"],"mappings":"2cAEA,IAAMA,EAA8B,CAClCC,MADkC,oBAElCC,eAFkC,GAGlCC,gBAHkC,GAIlCC,gBAJkC,GAKlCC,iBALkC,QAMlCC,gBAAiB,gBAGZ,SAASC,EAA2BC,EAApC,KACLC,qBAAuBA,sBAAvBA,GADoH,IAE5GC,EAAuBF,EAFqF,OAEpGG,EAAeH,EAFqF,WAI9GP,EAA2B,EAAH,GAA9B,GACAA,mBAEA,IAAMW,EAAkBD,KAAxB,gBACA,KAAqB,KACXE,EAAgBD,EADL,KACLE,EAAUF,EADL,MAEnBX,oBACAA,kBAAwBa,EAAA,KAAU,mBAAgBC,EAAhB,QAAV,KAAxBd,OAGF,IAEEA,0BACAQ,8BCvBJ,IAAMO,EAAa,CAAC,iBAAkB,gBAAtC,SAKO,SAASC,EAAuB,EAAhC,OAML,QADM,IADNC,WAAmEC,IAE9DV,OAAD,iBAA2BW,IAC7B,MAAM,IAAIC,MAAV,sDAEF,IAAMC,EAyJR,SAAkCd,GAChC,OAAOA,EAAA,sBAA+B,0BAAee,qBA1J5BC,CAAzB,IACIF,MAA2BF,KAC7BK,EAAsBC,EAAWlB,EAAWc,EAAkBK,EAA9DF,GAiBJ,SAASA,EAAsB,EAA/B,SAOE,QADA,IADAP,WAAmEC,GAE9DV,OAAL,gBAGA,IAAMG,EAAmCJ,gBAAzC,gBAEM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D,EAAuBrB,GAC9B,OAAO+B,EAAgB/B,GAAW,uBAAgBQ,UAAmBD,EAAnBC,SAOpD,SAASuB,EAAgB/B,EAAzB,GACE,OAAOA,EAAA,iBAA0B,YAC/B,aAAIe,mBACKA,6BAAP,MAqFC,SAASyB,EAAoBxC,GAClC,OAAOqB,MAAqCT,IAG9C,SAASA,IACP,WAAOX","file":"casper.js","sourcesContent":["import { GTMDataObjectItem, Component, Rule } from './types'\n// https://dsu-confluence.nestle.biz/x/vhcNDw && DIGEX-10165 && DIGEX-12220\nconst eventObj: GTMDataObjectItem = {\n  event: 'casper_experience',\n  component_name: '',\n  experience_name: '',\n  experience_rule: '',\n  experience_match: 'false',\n  event_raised_by: 'page builder',\n}\n\nexport function trackCasperMatchOrMismatch(component: Component, variationId: number, matchOrMismatch: boolean): void {\n  window.gtmDataObject = window.gtmDataObject || []\n  const { module, variations } = component\n\n  const event: GTMDataObjectItem = { ...eventObj }\n  event.component_name = module\n\n  const personalisation = variations[variationId].personalisation\n  if (personalisation) {\n    const { name, rules } = personalisation\n    event.experience_name = name\n    event.experience_rule = rules.map((rule: Rule) => rule.type).join(' | ')\n  }\n  \n  if (matchOrMismatch){\n    // DIGEX-12960 - don't push experience_match: false\n    event.experience_match = 'true'\n    window.gtmDataObject.push(event)\n  }\n}\n\n// casperExperienceActivation","import { Component, ExperienceType, Personalization } from './types'\nimport { displayNewVariation } from './loader'\nimport { Rule } from './types'\nimport { trackCasperMatchOrMismatch } from './tracking'\n\nconst asyncRules = ['basketContains', 'basketTotalIs', 'since']\n\n/**\n * creates the casper Experience\n */\nexport function createCasperExperience(\n  projectId: string,\n  component: Component,\n  order: number,\n  resolve: ((value: void | PromiseLike<void>) => void) | undefined = undefined\n): void {\n  if (!window.casperEventHub && !isRunningPreview()) {\n    throw new Error(\"Error Casper Generator - can't find casperEventHub\")\n  }\n  const firstVariationId = getFirstPersoVariationId(component)\n  if (firstVariationId != -1 && !isRunningPreview()) {\n    instanciateExperience(projectId, component, firstVariationId, order, resolve)\n  }\n}\n\n/**\n * returns true when the given variation has personalization\n */\n/*function hasPersonalization(variation: Variation): boolean {\n  return (\n    typeof variation.personalisation !== 'undefined' &&\n    variation.personalisation !== null\n  )\n}*/\n\n/**\n * Instanciates the casper Experience\n */\nfunction instanciateExperience(\n  projectId: string,\n  component: Component,\n  variationId: number,\n  order: number,\n  resolve: ((value: void | PromiseLike<void>) => void) | undefined = undefined\n) {\n  if (!window.casperEventHub) {\n    return\n  }\n  const personalisation: Personalization = component.variations[variationId]\n    .personalisation as Personalization\n  const hasAsync = hasAsyncTargetingRules(component)\n  const experience: ExperienceType = new window.casperEventHub.Experience(personalisation.name, { noTracking: true })\n  personalisation.rules.forEach(function (rule) {\n    const functionBody = 'experience.' + rule.type + '(' + rule.condition + ')'\n    /**\n     * disabling this rule in this case because it's the right way here :\n     * casper targeting rule arguments are complex and we can't come up\n     * with a proper way of parsing them without this eval like method\n     */\n    // eslint-disable-next-line @typescript-eslint/no-implied-eval\n    const createRule = new Function('experience', functionBody)\n    createRule(experience)\n  })\n  experience.executeOnMatch(function (data) {\n    onCasperMatch(projectId, component, variationId, order, resolve)\n    data.unsubscribe()\n  })\n  /*\n  this condition prevents the async experiences of type ABC+ to run properly\n  commenting for now I got to test/deep dive in the procedure to confirm\n  if (!hasAsync) {\n  */\n  experience.executeOnMismatch(function (data) {\n    if (!hasMismatchTargetingRule(component)) {\n      onCasperMismatch(projectId, component.uuid, variationId, order, resolve)\n      if (!hasAsync) data.unsubscribe()\n    }\n  })\n  //}\n  experience.evaluate()\n}\n\n/**\n *  Returns true if any personalization except the standard varation's one\n *  has async targeting rules because in this case , the standard variant\n *  should be rendered at pageload without waiting for any Casper XP match\n */\nfunction hasAsyncTargetingRules(component: Component) {\n  return hasSpecificRule(component, (rule: Rule) => asyncRules.indexOf(rule.type) !== -1)\n}\n\nfunction hasMismatchTargetingRule(component: Component) {\n  return hasSpecificRule(component, (rule: Rule) => rule.type === 'mismatches')\n}\n\nfunction hasSpecificRule(component: Component, comparison: (rule: Rule) => boolean) {\n  return component.variations.some((variation) => {\n    if (variation.personalisation != null) {\n      return variation.personalisation.rules.some(comparison)\n    } else {\n      return false\n    }\n  })\n}\n\n/**\n * continue component initialization when a Casper XP matches\n */\nfunction onCasperMatch(\n  projectId: string,\n  component: Component,\n  variationId: number,\n  order: number,\n  resolve: ((value: void | PromiseLike<void>) => void) | undefined = undefined\n): void {\n  displayNewVariation(projectId, component, variationId, order, resolve)\n  trackCasperMatchOrMismatch(component, variationId, true)\n}\n\n/**\n * Continues the component's first variant (standard) initialization\n * or generates the next variant's casper XP when a previous\n * Casper XP mismatches\n */\nfunction onCasperMismatch(\n  projectId: string,\n  componentId: string,\n  variationId: number,\n  order: number,\n  resolve: ((value: void | PromiseLike<void>) => void) | undefined = undefined\n): void {\n  let component: Component\n  try {\n    component = findComponentData(projectId, componentId)\n  } catch (e) {\n    console.log(e)\n    return\n  }\n  if (\n    component.variations.length > variationId + 1 &&\n    component.variations[variationId + 1].personalisation !== null\n  ) {\n    setTimeout(function () {\n      try {\n        instanciateExperience(projectId, component, variationId + 1, order, resolve)\n        trackCasperMatchOrMismatch(component, variationId, false)\n      } catch (e) {\n        console.log(e)\n      }\n    }, 0)\n  } else if (component.variations[0].personalisation === null) {\n    displayNewVariation(projectId, component, 0, order, resolve)\n  }\n}\n\n/**\n * Retrieves component data from nwc.projects\n */\nfunction findComponentData(projectId: string, componentId: string): Component {\n  if (!window.nwc || !window.nwc.projects) {\n    throw new Error(\"Error Casper Generator - can't find nwc.projects\")\n  }\n  const project = window.nwc.projects.find((project) => project.id === projectId)\n  if (!project) throw new Error(\"Error Casper Generator - can't find project \" + projectId)\n  const component = project.components.find((component) => component.uuid === componentId)\n  if (!component)\n    throw new Error(\n      \"Error Casper Generator - can't find component \" + componentId + ' in project ' + projectId\n    )\n  return component\n}\n\nfunction getFirstPersoVariationId(component: Component) {\n  return component.variations.findIndex((variation) => variation.personalisation !== null)\n}\n\n/**\n * returns true if the component's default variation [0] should be\n * displayed without waiting for the experience to evaluate\n * Cases where it is true :\n *  -the experience contains event based targeting rules\n *  -the loader runs inside Page Builder's preview\n */\nexport function hasDefaultVariation(component: Component): boolean {\n  return hasAsyncTargetingRules(component) || isRunningPreview()\n}\n\nfunction isRunningPreview() {\n  return window.location.pathname.indexOf('/iframe.html') !== -1\n}\n"],"sourceRoot":""}