@claspo/renderer 18.8.1 → 18.9.0-sp1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@claspo/renderer",
|
|
3
|
-
"version": "18.
|
|
3
|
+
"version": "18.9.0-sp1",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": " tsc --project tsconfig.json --watch",
|
|
6
6
|
"build": "rm -rf out && tsc --project tsconfig.json && npm run minify",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"node": ">=18.16.0"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@claspo/common": "7.
|
|
18
|
+
"@claspo/common": "7.5.0-sp1",
|
|
19
19
|
"@testing-library/dom": "^10.4.0"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
package/prize-pool/PrizePool.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import sum from"@claspo/common/math/sum";import RandomDistributor from"@claspo/common/math/RandomDistributor";const
|
|
1
|
+
import sum from"@claspo/common/math/sum";import RandomDistributor from"@claspo/common/math/RandomDistributor";import{PrizeOptionValueType,PrizeSourceType,ShopifyDiscountType,ShopifyPromoCodeMode}from"@claspo/common/PrizePool.interface";const FETCHABLE_SOURCE_TYPES=[PrizeSourceType.MANUAL,PrizeSourceType.SHOPIFY];export default class PrizePool{constructor(i,e,o){if(this.httpClient=e,this.configService=o,this.instanceModel=i||{},"FIXED"!==this.instanceModel.model){const i=(this.configService.getConfig("prizePoolIds")||[])[0];i&&i!==this.instanceModel.id&&(this.instanceModel=Object.assign(Object.assign({},this.instanceModel),{id:i,options:void 0}));const e=this.configService.getConfig("prizePoolModels");if(e){const i=this.instanceModel.id&&e.find(i=>i.id===this.instanceModel.id)||e[0];i&&(this.instanceModel=i)}}this.prizeOption=null,this.randomDistributor=new RandomDistributor}async load(){const{id:i,model:e,sourceType:o,options:t}=this.instanceModel;if(!(!t&&!!i&&"FIXED"!==e&&(!o||FETCHABLE_SOURCE_TYPES.includes(o))))return;const n=this.configService.getConfig("widgetId");try{const e=this.configService.getConfig("hostUrl"),t=`${e}forms/v2/prize/pool/${i}`,s=`${e}forms/v1/prizePool/${i}/reward?widgetId=${n}`,[r,l]=await Promise.all([await this.httpClient.execute(t,"GET").then(i=>i.json()),await this.httpClient.execute(s,"GET",null,{"cl-customer-id":this.configService.getConfig("clCustomerId")}).then(i=>i.json())]);this.instanceModel=Object.assign(Object.assign({},this.instanceModel),{sourceType:o||r.sourceType,options:r.options});const c=r.options.find(i=>i.id===l.id);this.prizeOption=Object.assign(Object.assign({},c),l)}catch(e){console.error(`PrizePool: failed to load pool or reward for widgetId "${n}" with poolId "${i}"`,e)}}getModel(){return this.instanceModel}async getPrize(){if(!this.instanceModel)return null;if("FIXED"===this.instanceModel.model)return this.instanceModel.data;if(FETCHABLE_SOURCE_TYPES.includes(this.instanceModel.sourceType)){if(this.instanceModel.options&&!this.prizeOption){if(this._hasDynamicCodeOption())return null;this.prizeOption=this._calculatePrize()}return this.prizeOption?this.mapPrizeOption(this.prizeOption):null}return null}submitPrize(){}mapPrizeOption(i){const e=this._mapShopifyDiscountLabel(i);let o=null!==e?e:i.valueType===PrizeOptionValueType.PROMOCODE?i.value||"":this._mapLabelSuffix(i.value,i.valueType),t=i.code;return{id:i.id,label:o,value:t}}_calculatePrize(){const i=sum(this.instanceModel.options.map(i=>parseFloat(i.weight)));return this.randomDistributor.calculateFromWeights(this.instanceModel.options,i)}_mapShopifyDiscountLabel(i){var e;const o=null===(e=null==i?void 0:i.config)||void 0===e?void 0:e.shopify;return o&&void 0!==o.discountValue&&null!==o.discountValue?o.discountType===ShopifyDiscountType.PERCENTAGE?`${o.discountValue}%`:`${o.discountValue}`:null}_hasDynamicCodeOption(){return(this.instanceModel.options||[]).some(i=>{var e,o;return(null===(o=null===(e=null==i?void 0:i.config)||void 0===e?void 0:e.shopify)||void 0===o?void 0:o.mode)===ShopifyPromoCodeMode.UNIQUE})}_mapLabelSuffix(i,e){return e===PrizeOptionValueType.DISCOUNT_PERCENTAGE?`${i}%`:i}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ContextEvents}from"../context/ContextEvents";export default class AbstractMergeTagsProcessor{constructor(e,t){this.context=e,this.configService=t,this.element=null,this.mergeTags=null,this.componentId=null,this.contextRecordUpdatesSubscription=null}destroy(){this.contextRecordUpdatesSubscription&&(this.contextRecordUpdatesSubscription.off(),this.contextRecordUpdatesSubscription=null)}process(e,t,s){this.element=e,this.mergeTags=t,this.componentId=s,this._subscribeToDynamicMergeTagUpdates(),this.mergeTags&&0!==Object.keys(this.mergeTags).length&&this.element.
|
|
1
|
+
import{ContextEvents}from"../context/ContextEvents";export default class AbstractMergeTagsProcessor{constructor(e,t){this.context=e,this.configService=t,this.element=null,this.mergeTags=null,this.componentId=null,this.contextRecordUpdatesSubscription=null}destroy(){this.contextRecordUpdatesSubscription&&(this.contextRecordUpdatesSubscription.off(),this.contextRecordUpdatesSubscription=null)}process(e,t,s){this.element=e,this.mergeTags=t,this.componentId=s,this._subscribeToDynamicMergeTagUpdates(),this.mergeTags&&0!==Object.keys(this.mergeTags).length&&this.element.querySelectorAll('[cl-type="MERGE_TAG"]').forEach(e=>{const t=e.getAttribute("cl-id"),s=this.mergeTags[t];s&&this.processSingleMergeTag(e,s)})}processSingleMergeTag(e,t){throw new Error("BaseMergeTagsProcessor: processSingleMergeTag is not implemented")}_subscribeToDynamicMergeTagUpdates(){this.contextRecordUpdatesSubscription&&(this.contextRecordUpdatesSubscription.off(),this.contextRecordUpdatesSubscription=null),this.contextRecordUpdatesSubscription=this.context.on(ContextEvents.RECORD_UPDATED,e=>{this._processDynamicMergeTags(e)})}_processDynamicMergeTags(e){if(!this.element||!this.mergeTags)return;const t=(null==e?void 0:e.key)||(null==e?void 0:e.id);if(!t)return;const s=this.mergeTags[t];if(!s)return;const i=this._findMergeTagElement(s.id);i&&this.processSingleMergeTag(i,s)}_findMergeTagElement(e){return this.element?this.element.getAttribute("cl-id")===e?this.element:this.element.querySelector(`[cl-id="${e}"]`):null}}
|