@claspo/renderer 18.10.2-gbx3 → 18.11.0-dsp3
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/action/ActionFactory.js +1 -1
- package/action/actions/GoToNextViewAction.d.ts +2 -3
- package/action/actions/GoToNextViewAction.js +1 -1
- package/action/actions/GoToViewAction.d.ts +2 -3
- package/action/actions/GoToViewAction.js +1 -1
- package/package.json +2 -2
- package/prize-pool/PrizePool.d.ts +10 -1
- package/prize-pool/PrizePool.js +1 -1
- package/action/actions/interceptForwardNavigation.d.ts +0 -1
- package/action/actions/interceptForwardNavigation.js +0 -1
package/action/ActionFactory.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import SysActionTypes from"./SysActionTypes";import SubscribeContactAction from"./actions/SubscribeContactAction";import RequestAction from"./actions/RequestAction";import DispatchEventAction from"./actions/DispatchEventAction";import GoToPreviousViewAction from"./actions/GoToPreviousViewAction";import GoToNextViewAction from"./actions/GoToNextViewAction";import GoToViewAction from"./actions/GoToViewAction";import HttpClient from"@claspo/common/network/HttpClient";import ShowWidgetAction from"./actions/ShowWidgetAction";import OpenLinkAction from"./actions/OpenLinkAction";import CloseWidgetAction from"./actions/CloseWidgetAction";export default class ActionFactory{constructor(t,i,e,o,
|
|
1
|
+
import SysActionTypes from"./SysActionTypes";import SubscribeContactAction from"./actions/SubscribeContactAction";import RequestAction from"./actions/RequestAction";import DispatchEventAction from"./actions/DispatchEventAction";import GoToPreviousViewAction from"./actions/GoToPreviousViewAction";import GoToNextViewAction from"./actions/GoToNextViewAction";import GoToViewAction from"./actions/GoToViewAction";import HttpClient from"@claspo/common/network/HttpClient";import ShowWidgetAction from"./actions/ShowWidgetAction";import OpenLinkAction from"./actions/OpenLinkAction";import CloseWidgetAction from"./actions/CloseWidgetAction";export default class ActionFactory{constructor(t,i,e,o,n,c,s){this.eventEmitter=t,this.form=i,this.configService=e,this.tracking=o,this.stateService=n,this.context=c,this.getServices=s}get(t){switch(t.type){case SysActionTypes.SUBSCRIBE_CONTACT:return new SubscribeContactAction(this.eventEmitter,this.form,t,HttpClient,this.configService,this.tracking,this.stateService,this.context,this.getServices);case SysActionTypes.REQUEST:return new RequestAction(this.eventEmitter,this.form,t,HttpClient,this.configService,this.tracking,this.stateService,this.context,this.getServices);case SysActionTypes.DISPATCH_EVENT:return new DispatchEventAction(this.eventEmitter,t,this.form,this.configService,this.context);case SysActionTypes.GO_TO_VIEW:return new GoToViewAction(this.eventEmitter,t,this.configService,this.form,this.getServices().viewRouter,this.getServices().documentModel,this.tracking,this.getServices().activePathTracker);case SysActionTypes.GO_TO_PREVIOUS_VIEW:return new GoToPreviousViewAction(this.eventEmitter,t,this.tracking,this.getServices().activePathTracker);case SysActionTypes.GO_TO_NEXT_VIEW:return new GoToNextViewAction(this.eventEmitter,this.form,t,this.tracking);case SysActionTypes.SHOW_WIDGET:return new ShowWidgetAction(this.eventEmitter,t,this.tracking);case SysActionTypes.OPEN_LINK:return new OpenLinkAction(t,this.configService,this.tracking);case SysActionTypes.CLOSE_WIDGET:return new CloseWidgetAction(this.eventEmitter,t,this.configService,this.tracking);default:throw new Error(`Not supported action type ${t.type}`)}}}
|
|
@@ -4,8 +4,7 @@ export default class GoToNextViewAction {
|
|
|
4
4
|
form: any;
|
|
5
5
|
config: any;
|
|
6
6
|
tracking: any;
|
|
7
|
-
stateService: any;
|
|
8
7
|
type: SysActionTypes;
|
|
9
|
-
constructor(eventEmitter: any, form: any, config: any, tracking: any
|
|
10
|
-
execute(
|
|
8
|
+
constructor(eventEmitter: any, form: any, config: any, tracking: any);
|
|
9
|
+
execute(): Promise<boolean>;
|
|
11
10
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import SysActionTypes from"../SysActionTypes";
|
|
1
|
+
import SysActionTypes from"../SysActionTypes";export default class GoToNextViewAction{constructor(t,i,e,s){this.type=SysActionTypes.GO_TO_NEXT_VIEW,this.eventEmitter=t,this.form=i,this.config=e,this.tracking=s}async execute(){if(this.form.markAsTouched(),this.form.getControlsAsArray().length){if(!await this.form.waitForPendingValidationAndCheckIfValid())return this.eventEmitter.emit("INVALID_CONTACT_DATA_SUBMIT_ATTEMPT"),!1}return this.eventEmitter.emit(this.type),!0}}
|
|
@@ -7,10 +7,9 @@ export default class GoToViewAction {
|
|
|
7
7
|
documentModel: any;
|
|
8
8
|
tracking: any;
|
|
9
9
|
activePathTracker: any;
|
|
10
|
-
stateService: any;
|
|
11
10
|
type: SysActionTypes;
|
|
12
|
-
constructor(eventEmitter: any, actionConfig: any, configService: any, form: any, viewRouter: any, documentModel: any, tracking: any, activePathTracker: any
|
|
13
|
-
execute(
|
|
11
|
+
constructor(eventEmitter: any, actionConfig: any, configService: any, form: any, viewRouter: any, documentModel: any, tracking: any, activePathTracker: any);
|
|
12
|
+
execute(): Promise<boolean>;
|
|
14
13
|
private getTargetViewIndex;
|
|
15
14
|
private isForwardNavigation;
|
|
16
15
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import SysActionTypes from"../SysActionTypes";import ErrorLogger from"../../error/ErrorLogger";
|
|
1
|
+
import SysActionTypes from"../SysActionTypes";import ErrorLogger from"../../error/ErrorLogger";export default class GoToViewAction{constructor(t,i,e,r,o,a,s,n){this.type=SysActionTypes.GO_TO_VIEW,this.eventEmitter=t,this.config=i,this.form=r,this.viewRouter=o,this.documentModel=a,this.tracking=s,this.activePathTracker=n}async execute(){var t;try{this.form.markAsTouched();const i=this.isForwardNavigation(this.getTargetViewIndex());if(i&&(null===(t=this.config.params.validateForm)||void 0===t||t)){if(!await this.form.waitForPendingValidationAndCheckIfValid())return this.eventEmitter.emit("INVALID_CONTACT_DATA_SUBMIT_ATTEMPT"),!1}return this.eventEmitter.emit(this.type,this.config.params.viewId||this.config.params.viewIndex,{isForward:i}),this.config.params.trackClick&&this.tracking.trackClick({params:this.config.params.trackClickParams,countAsTargetAction:this.config.params.countAsTargetAction}),!0}catch(t){return ErrorLogger.log(`GoToViewAction.execute failed: ${(null==t?void 0:t.stack)||t}`),!1}}getTargetViewIndex(){return this.config.params.viewId?this.documentModel.getViews().findIndex(t=>t.id===this.config.params.viewId):this.config.params.viewIndex}isForwardNavigation(t){var i,e,r;if("number"!=typeof t||t<0)return!1;const o=null!==(r=null===(e=null===(i=this.activePathTracker)||void 0===i?void 0:i.getActivePath)||void 0===e?void 0:e.call(i))&&void 0!==r?r:[];return o.length?!o.includes(t):this.viewRouter.getCurrentViewIndex()<t}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@claspo/renderer",
|
|
3
|
-
"version": "18.
|
|
3
|
+
"version": "18.11.0-dsp3",
|
|
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.5.
|
|
18
|
+
"@claspo/common": "7.5.5-dsp3",
|
|
19
19
|
"@testing-library/dom": "^10.4.0"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
@@ -4,9 +4,18 @@ export default class PrizePool {
|
|
|
4
4
|
configService: any;
|
|
5
5
|
prizeOption: any;
|
|
6
6
|
randomDistributor: any;
|
|
7
|
+
_loadPromise: Promise<void> | null;
|
|
8
|
+
_claimPromise: Promise<void> | null;
|
|
9
|
+
_reserved: boolean;
|
|
7
10
|
constructor(config: any, httpClient: any, configService: any);
|
|
8
11
|
load(): Promise<void>;
|
|
9
|
-
|
|
12
|
+
claimCode(): Promise<void>;
|
|
13
|
+
_claim(): Promise<void>;
|
|
14
|
+
_load(): Promise<void>;
|
|
15
|
+
_resolveReservation(reservation: any, options: any, prizePoolId: any): any;
|
|
16
|
+
_fetchReward(url: any, options: any, prizePoolId: any): Promise<any>;
|
|
17
|
+
_resolveReward(reward: any, options: any, prizePoolId: any): any;
|
|
18
|
+
_findPoolOption(rewardOrReservation: any, options: any): any;
|
|
10
19
|
_mergeRewardIntoOption(reward: any, options: any): any;
|
|
11
20
|
_fetchPool(url: string, prizePoolId: string): Promise<any>;
|
|
12
21
|
_fetchJson(url: any, headers?: any): Promise<any>;
|
package/prize-pool/PrizePool.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import sum from"@claspo/common/math/sum";import RandomDistributor from"@claspo/common/math/RandomDistributor";import{PrizeCodeType,PrizeOptionValueType,PrizeSourceType}from"@claspo/common/PrizePool.interface";import{PreviewMode}from"../sdk/PreviewMode";import ErrorLogger from"../error/ErrorLogger";const FETCHABLE_SOURCE_TYPES=[PrizeSourceType.MANUAL,PrizeSourceType.SHOPIFY],drawnPrizeCodePlaceholder="CLXXXXXXXX";export default class PrizePool{constructor(e,i
|
|
1
|
+
import sum from"@claspo/common/math/sum";import RandomDistributor from"@claspo/common/math/RandomDistributor";import{PrizeCodeType,PrizeOptionValueType,PrizeSourceType}from"@claspo/common/PrizePool.interface";import{PreviewMode}from"../sdk/PreviewMode";import ErrorLogger from"../error/ErrorLogger";const FETCHABLE_SOURCE_TYPES=[PrizeSourceType.MANUAL,PrizeSourceType.SHOPIFY],drawnPrizeCodePlaceholder="CLXXXXXXXX";export default class PrizePool{constructor(e,o,i){if(this.httpClient=o,this.configService=i,this.instanceModel=e||{},"FIXED"!==this.instanceModel.model){const e=this.configService.getConfig("prizePoolModels");if(e&&this.instanceModel.id){const o=e.find(e=>e.id===this.instanceModel.id);o&&(this.instanceModel=o)}}this.prizeOption=null,this.randomDistributor=new RandomDistributor,this._loadPromise=null,this._claimPromise=null,this._reserved=!1}async load(){return this._loadPromise||(this._loadPromise=this._load()),this._loadPromise}async claimCode(){return this._claimPromise||(this._claimPromise=this._claim()),this._claimPromise}async _claim(){if(await this.load(),!this._reserved)return;const{id:e}=this.instanceModel,o=this.configService.getConfig("hostUrl"),i=this.configService.getConfig("widgetId"),t=`${o}forms/v1/prizePool/${e}/reward?widgetId=${i}`;try{this.prizeOption=await this._fetchReward(t,this.instanceModel.options,e)}catch(o){throw console.error(`PrizePool: failed to claim a code for widgetId "${i}" with poolId "${e}"`,o),o}}async _load(){const{id:e,model:o,sourceType:i,options:t}=this.instanceModel;if(!(!t&&!!e&&"FIXED"!==o&&(!i||FETCHABLE_SOURCE_TYPES.includes(i))))return;const r=this.configService.getConfig("widgetId");try{const o=this.configService.getConfig("hostUrl"),t=`${o}forms/v2/prize/pool/${e}`,n=`${o}forms/v1/prizePool/${e}/reward?widgetId=${r}`,s=`${o}forms/v1/prizePool/${e}/reserve-reward?widgetId=${r}`;if(this._isPreview()){const o=await this._fetchPool(t,e);if(this.instanceModel=Object.assign(Object.assign({},this.instanceModel),{sourceType:i||o.sourceType,options:o.options}),this._mintsCodePerWinner(o.options))return;return void(this.prizeOption=await this._fetchReward(n,o.options,e))}const[a,l]=await Promise.all([this._fetchPool(t,e),this._fetchJson(s,{"cl-customer-id":this.configService.getConfig("clCustomerId")})]);this.instanceModel=Object.assign(Object.assign({},this.instanceModel),{sourceType:i||a.sourceType,options:a.options}),this.prizeOption=this._resolveReservation(l,a.options,e),this._reserved=!0}catch(o){throw console.error(`PrizePool: failed to load pool or reservation for widgetId "${r}" with poolId "${e}"`,o),o}}_resolveReservation(e,o,i){if(!this._findPoolOption(e,o))throw ErrorLogger.log(`PrizePool: the pool ${i} does not hold the reserved option ${null==e?void 0:e.id}`),new Error("PrizePool: the reserved option is not in the pool");return this._mergeRewardIntoOption(e,o)}async _fetchReward(e,o,i){const t=await this._fetchJson(e,{"cl-customer-id":this.configService.getConfig("clCustomerId")});return this._resolveReward(t,o,i)}_resolveReward(e,o,i){const t=this._mergeRewardIntoOption(e,o);if(null==e?void 0:e.unavailableReason)throw ErrorLogger.log(`PrizePool: the reward from pool ${i} cannot be handed out with a reason "${e.unavailableReason}"`),new Error("PrizePool: the reward cannot be handed out");if(t.valueType===PrizeOptionValueType.PROMOCODE&&!t.code)throw ErrorLogger.log(`PrizePool: the reward from pool ${i} came back without a promo code`),new Error("PrizePool: the reward cannot be handed out");return t}_findPoolOption(e,o){return(o||[]).find(o=>o.id===(null==e?void 0:e.id))}_mergeRewardIntoOption(e,o){return Object.assign(Object.assign({},this._findPoolOption(e,o)),e)}async _fetchPool(e,o){const i=await this._fetchJson(e);if(!1===(null==i?void 0:i.available))throw ErrorLogger.log(`PrizePool: the pool ${o} is not available and cannot be handed out with a reason "${i.unavailableReason}"`),new Error("PrizePool: the pool is not available and cannot be handed out");return i}async _fetchJson(e,o){const i=await this.httpClient.execute({url:e,headers:o});if(!i.ok)throw new Error(`PrizePool: request failed with status ${i.status} - ${e}`);return i.json()}getModel(){return this.instanceModel}async getPrize(){return this.instanceModel?"FIXED"===this.instanceModel.model?this.instanceModel.data:FETCHABLE_SOURCE_TYPES.includes(this.instanceModel.sourceType)?(this.instanceModel.options&&!this.prizeOption&&(this.prizeOption=this._calculatePrize()),this.prizeOption?this.mapPrizeOption(this.prizeOption):null):null:null}submitPrize(){}mapPrizeOption(e){var o,i;const t=e.valueType===PrizeOptionValueType.PROMOCODE?e.value||"":this._mapLabelSuffix(e.value,e.valueType);return{id:e.id,label:t,value:e.code,navigateToViewId:null!==(i=null===(o=e.config)||void 0===o?void 0:o.navigateToViewId)&&void 0!==i?i:null}}_calculatePrize(){const e=sum(this.instanceModel.options.map(e=>parseFloat(e.weight))),o=this.randomDistributor.calculateFromWeights(this.instanceModel.options,e);return o&&this._isCodeMintedPerWinner(o)?Object.assign(Object.assign({},o),{code:"CLXXXXXXXX"}):o}_mintsCodePerWinner(e){return(e||[]).some(e=>this._isCodeMintedPerWinner(e))}_isPreview(){return!!(this.configService.getConfig(PreviewMode.CABINET_PREVIEW)||this.configService.getConfig(PreviewMode.EDITOR_PREVIEW)||this.configService.getConfig(PreviewMode.DEMO))}_isCodeMintedPerWinner(e){var o;return(null===(o=null==e?void 0:e.config)||void 0===o?void 0:o.codeType)===PrizeCodeType.UNIQUE}_mapLabelSuffix(e,o){return o===PrizeOptionValueType.DISCOUNT_PERCENTAGE?`${e}%`:e}}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function interceptForwardNavigation(stateService: any, eventEmitter: any, force: boolean): boolean;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function interceptForwardNavigation(t,i,n){var o,e;const a=(null===(o=null==t?void 0:t.getState)||void 0===o?void 0:o.call(t))||{};if(!a.interceptForwardNavigationActions||n)return!1;const r=null===(e=a.emitActionOnForwardNavigation)||void 0===e?void 0:e.eventName;return r&&i.emit(r),!0}
|