@claspo/common 7.4.0-nonlinear3 → 7.5.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.
@@ -5,7 +5,8 @@ export interface PrizePoolModelI {
5
5
  options?: PrizePoolOptionI[];
6
6
  }
7
7
  export declare enum PrizeSourceType {
8
- MANUAL = "MANUAL"
8
+ MANUAL = "MANUAL",
9
+ SHOPIFY = "SHOPIFY"
9
10
  }
10
11
  export declare enum PrizeDistributionType {
11
12
  PERCENT_CHANCE = "PERCENT_CHANCE"
@@ -20,8 +21,36 @@ export interface PrizePoolOptionI {
20
21
  }
21
22
  export declare enum PrizeOptionValueType {
22
23
  DISCOUNT_PERCENTAGE = "DISCOUNT_PERCENTAGE",
23
- CUSTOM = "CUSTOM"
24
+ CUSTOM = "CUSTOM",
25
+ PROMOCODE = "PROMOCODE"
24
26
  }
25
27
  export interface PrizeOptionConfigI {
26
28
  imageUrl?: string;
29
+ discountNodeId?: string;
30
+ shopify?: PrizeOptionShopifyConfigI;
31
+ }
32
+ export interface PrizeOptionShopifyConfigI {
33
+ mode?: ShopifyPromoCodeMode;
34
+ discountType: ShopifyDiscountType;
35
+ discountValue: string;
36
+ startsAt?: string | null;
37
+ endsAt?: string | null;
38
+ shopifyAdminUrl?: string;
39
+ available?: boolean;
40
+ unavailableReason?: ShopifyPromoUnavailableReason;
41
+ }
42
+ export declare enum ShopifyPromoCodeMode {
43
+ STATIC = "STATIC",
44
+ UNIQUE = "UNIQUE"
45
+ }
46
+ export declare enum ShopifyDiscountType {
47
+ PERCENTAGE = "PERCENTAGE",
48
+ FIXED_AMOUNT = "FIXED_AMOUNT"
49
+ }
50
+ export declare enum ShopifyPromoUnavailableReason {
51
+ SHOPIFY_UNAVAILABLE = "SHOPIFY_UNAVAILABLE",
52
+ DISCOUNT_NOT_FOUND = "DISCOUNT_NOT_FOUND",
53
+ EXPIRED = "EXPIRED",
54
+ NOT_STARTED = "NOT_STARTED",
55
+ UNSUPPORTED_DISCOUNT = "UNSUPPORTED_DISCOUNT"
27
56
  }
@@ -1 +1 @@
1
- export var PrizeSourceType;!function(e){e.MANUAL="MANUAL"}(PrizeSourceType||(PrizeSourceType={}));export var PrizeDistributionType;!function(e){e.PERCENT_CHANCE="PERCENT_CHANCE"}(PrizeDistributionType||(PrizeDistributionType={}));export var PrizeOptionValueType;!function(e){e.DISCOUNT_PERCENTAGE="DISCOUNT_PERCENTAGE",e.CUSTOM="CUSTOM"}(PrizeOptionValueType||(PrizeOptionValueType={}));
1
+ export var PrizeSourceType;!function(o){o.MANUAL="MANUAL",o.SHOPIFY="SHOPIFY"}(PrizeSourceType||(PrizeSourceType={}));export var PrizeDistributionType;!function(o){o.PERCENT_CHANCE="PERCENT_CHANCE"}(PrizeDistributionType||(PrizeDistributionType={}));export var PrizeOptionValueType;!function(o){o.DISCOUNT_PERCENTAGE="DISCOUNT_PERCENTAGE",o.CUSTOM="CUSTOM",o.PROMOCODE="PROMOCODE"}(PrizeOptionValueType||(PrizeOptionValueType={}));export var ShopifyPromoCodeMode;!function(o){o.STATIC="STATIC",o.UNIQUE="UNIQUE"}(ShopifyPromoCodeMode||(ShopifyPromoCodeMode={}));export var ShopifyDiscountType;!function(o){o.PERCENTAGE="PERCENTAGE",o.FIXED_AMOUNT="FIXED_AMOUNT"}(ShopifyDiscountType||(ShopifyDiscountType={}));export var ShopifyPromoUnavailableReason;!function(o){o.SHOPIFY_UNAVAILABLE="SHOPIFY_UNAVAILABLE",o.DISCOUNT_NOT_FOUND="DISCOUNT_NOT_FOUND",o.EXPIRED="EXPIRED",o.NOT_STARTED="NOT_STARTED",o.UNSUPPORTED_DISCOUNT="UNSUPPORTED_DISCOUNT"}(ShopifyPromoUnavailableReason||(ShopifyPromoUnavailableReason={}));
@@ -24,6 +24,7 @@ export interface WidgetInitConfigI {
24
24
  actionFactoryClass?: any;
25
25
  widgetId?: number;
26
26
  prizePoolModels?: PrizePoolModelI[];
27
+ prizePoolIds?: string[];
27
28
  bundledComponentClasses?: any[];
28
29
  translations?: TranslationsI;
29
30
  trackingService?: TrackingServiceI;
@@ -2,6 +2,7 @@ import { WidgetType } from '../WidgetType';
2
2
  import { LayoutType } from '../LayoutType';
3
3
  import { ClBaseComponentI, ClBaseComponentPropsI, ClComponentType } from '../document/Document.interface';
4
4
  import { ComponentManifestI } from './ComponentManifest.interface';
5
+ import { PrizePoolModelI } from '../PrizePool.interface';
5
6
  export type DisplayConditionCallbackI = (sdk: DisplayConditionSdkI) => boolean;
6
7
  export interface DisplayConditionSdkI {
7
8
  widgetType: WidgetType;
@@ -12,6 +13,7 @@ export interface DisplayConditionSdkI {
12
13
  views: ClBaseComponentI[];
13
14
  manifests: ComponentManifestI[];
14
15
  documentUtils: DisplayConditionDocumentUtilsServiceI;
16
+ prizePool: PrizePoolModelI | null;
15
17
  }
16
18
  export interface DisplayConditionComponentFacadeI {
17
19
  id: string;
@@ -1 +1 @@
1
- import{ClDocumentActionType}from"./Document.interface";import{iterateDepthFirst}from"./DocumentUtils";export var ViewNavEdgeKind;!function(e){e.GO_TO_VIEW="GO_TO_VIEW",e.GO_TO_NEXT_VIEW="GO_TO_NEXT_VIEW",e.GO_TO_PREVIOUS_VIEW="GO_TO_PREVIOUS_VIEW",e.SUBMIT="SUBMIT",e.NPS_CONDITIONAL="NPS_CONDITIONAL"}(ViewNavEdgeKind||(ViewNavEdgeKind={}));export var ViewTerminalKind;!function(e){e.TRUE_TERMINAL="TRUE_TERMINAL",e.INTERMEDIATE="INTERMEDIATE"}(ViewTerminalKind||(ViewTerminalKind={}));const SUBMIT_ACTION_TYPES=[ClDocumentActionType.REQUEST,ClDocumentActionType.SUBSCRIBE_CONTACT],NPS_BAND_KEYS=["detractor","passive","promoter"];export const SUCCESS_LEGACY_LABELS=["DOCUMENT_VIEW_TYPE_SUCCESS","DOCUMENT_VIEW_TYPE_SUCCESSFUL_REQUEST","REQUEST_FORM_VIEW_TYPE_SUCCESS"];export const ERROR_LEGACY_LABELS=["DOCUMENT_VIEW_TYPE_ERROR"];export const ALREADY_SUBSCRIBED_LEGACY_LABELS=["DOCUMENT_VIEW_TYPE_SUBSCRIBED"];export const SYSTEM_RESULT_STATE_LABELS=[...SUCCESS_LEGACY_LABELS,...ERROR_LEGACY_LABELS,...ALREADY_SUBSCRIBED_LEGACY_LABELS];function componentModelHasSubmitAction(e){var n,i;try{return!!(null===(i=null===(n=e.props)||void 0===n?void 0:n.handlers)||void 0===i?void 0:i.find(e=>{var n;return null===(n=null==e?void 0:e.actions)||void 0===n?void 0:n.find(e=>SUBMIT_ACTION_TYPES.includes(e.type))}))}catch(e){return!1}}export function viewHasControls(e){if(!e)return!1;let n=0;return iterateDepthFirst(e,e=>{(["INPUT","MULTIPLE_INPUT","PRIZE_BASED_GAMING"].includes(e.type)||componentModelHasSubmitAction(e))&&n++}),n>0}export function isResultView(e,n){return!!e&&(SYSTEM_RESULT_STATE_LABELS.includes(e.label)||n.includes(e.id))}export function getConfiguredResultViewIds(e,n){return n?!e||e.runAction?[]:[e.successViewId,e.errorViewId,e.alreadySubscribedViewId].filter(Boolean):[]}function resolveResultViewIndex(e,n,i,o){const t=null==n?void 0:n[i];if(t){const n=e.findIndex(e=>e.id===t);if(-1!==n)return n}return e.findIndex(e=>o.includes(e.label))}export function submitAdvancesToNextStep(e,n,i,o){const t=n[i+1];if(!t||isResultView(t,o))return!1;return!e.edges.some(e=>e.toIndex===i+1&&e.fromIndex!==i&&e.isForward&&e.kind!==ViewNavEdgeKind.SUBMIT)}export function buildViewNavigationGraph(e,n){var i;const o=new Map;e.forEach((e,n)=>o.set(e.id,n));const t=null!==(i=null==n?void 0:n.submitActionParams)&&void 0!==i?i:void 0,d=e.some(e=>viewHasControls(e)),r=getConfiguredResultViewIds(t,d),s=d?t:void 0,l=[],E=[],u=(e,n,i)=>i===ViewNavEdgeKind.GO_TO_NEXT_VIEW||n>e,a=(n,i,o,t)=>{void 0===i||i<0||i>=e.length||l.push({fromIndex:n,toIndex:i,kind:o,isForward:u(n,i,o),label:t})},c=(n,i)=>{var t,d;switch(i.type){case ClDocumentActionType.GO_TO_VIEW:return(null===(t=i.params)||void 0===t?void 0:t.viewId)?o.get(i.params.viewId):"number"==typeof(null===(d=i.params)||void 0===d?void 0:d.viewIndex)?i.params.viewIndex:void 0;case ClDocumentActionType.GO_TO_NEXT_VIEW:return n+1<e.length?n+1:void 0;case ClDocumentActionType.GO_TO_PREVIOUS_VIEW:return n-1>=0?n-1:void 0;default:return}},_=e.map(()=>new Set),I=(e,n,i,o)=>{if(void 0===n||-1===n||n===e)return;const t=`${n}:${i}`;_[e].has(t)||(_[e].add(t),a(e,n,i,o))},T=[];e.forEach((e,n)=>{const i=new Set;let t;iterateDepthFirst(e,e=>{var o,d,r,s,l,E,u;const _=null===(o=e.props)||void 0===o?void 0:o.content,I=[];for(const n of null!==(r=null===(d=e.props)||void 0===d?void 0:d.handlers)&&void 0!==r?r:[])for(const e of null!==(s=n.actions)&&void 0!==s?s:[])I.push({action:e,label:null!==(l=null==_?void 0:_.text)&&void 0!==l?l:""});if(Array.isArray(null==_?void 0:_.options))for(const e of _.options)(null==e?void 0:e.action)&&I.push({action:e.action,label:null!==(u=null!==(E=null==e?void 0:e.label)&&void 0!==E?E:null==e?void 0:e.value)&&void 0!==u?u:""});for(const{action:e,label:i}of I)SUBMIT_ACTION_TYPES.includes(e.type)?t=null!=t?t:i:e.type!==ClDocumentActionType.GO_TO_VIEW&&e.type!==ClDocumentActionType.GO_TO_NEXT_VIEW&&e.type!==ClDocumentActionType.GO_TO_PREVIOUS_VIEW||a(n,c(n,e),e.type,i);NPS_BAND_KEYS.map(e=>(_||{})[e]||null).filter(e=>e).forEach(e=>i.add(e))}),i.forEach(e=>{I(n,o.get(e),ViewNavEdgeKind.NPS_CONDITIONAL,"")}),T[n]=t,E[n]=void 0!==t}),e.forEach((n,i)=>{const o=T[i];if(void 0===o)return;const t=e[i+1],E=submitAdvancesToNextStep({edges:l},e,i,r),u=o,a=()=>{I(i,resolveResultViewIndex(e,s,"errorViewId",ERROR_LEGACY_LABELS),ViewNavEdgeKind.SUBMIT,u),s&&!s.alreadySubscribedViewId?I(i,resolveResultViewIndex(e,s,"successViewId",SUCCESS_LEGACY_LABELS),ViewNavEdgeKind.SUBMIT,u):I(i,resolveResultViewIndex(e,s,"alreadySubscribedViewId",ALREADY_SUBSCRIBED_LEGACY_LABELS),ViewNavEdgeKind.SUBMIT,u)};if(E)return I(i,i+1,ViewNavEdgeKind.SUBMIT,u),void(!viewHasControls(t)&&d&&a());const _=null==s?void 0:s.runAction;_?I(i,c(i,_),_.type,u):(I(i,resolveResultViewIndex(e,s,"successViewId",SUCCESS_LEGACY_LABELS),ViewNavEdgeKind.SUBMIT,u),a())});const S=e.map((e,n)=>{var i,o;return{index:n,id:e.id,label:null!==(i=e.label)&&void 0!==i?i:e.id,hasSubmitAction:null!==(o=E[n])&&void 0!==o&&o}});return{nodes:S,edges:l}}export function classifyView(e,n){return e.edges.some(e=>e.fromIndex===n)?ViewTerminalKind.INTERMEDIATE:ViewTerminalKind.TRUE_TERMINAL}export function classifyViews(e){return e.nodes.map(n=>classifyView(e,n.index))}export function isAutoCommitTerminal(e,n){const i=e.nodes[n];return!!i&&(classifyView(e,n)===ViewTerminalKind.TRUE_TERMINAL&&!i.hasSubmitAction)}export function isMultiViewFlow(e){if(e.nodes.length<2)return!1;const n=new Set([0]),i=[0];for(;i.length;){const o=i.shift();for(const t of e.edges)t.fromIndex!==o||n.has(t.toIndex)||(n.add(t.toIndex),i.push(t.toIndex))}return n.size>1}export function isNonLinearFlow(e){return e.edges.some(e=>e.kind===ViewNavEdgeKind.GO_TO_VIEW||e.kind===ViewNavEdgeKind.NPS_CONDITIONAL||e.kind===ViewNavEdgeKind.SUBMIT&&e.toIndex<e.fromIndex)}
1
+ import{ClDocumentActionType}from"./Document.interface";import{iterateDepthFirst}from"./DocumentUtils";export var ViewNavEdgeKind;!function(e){e.GO_TO_VIEW="GO_TO_VIEW",e.GO_TO_NEXT_VIEW="GO_TO_NEXT_VIEW",e.GO_TO_PREVIOUS_VIEW="GO_TO_PREVIOUS_VIEW",e.SUBMIT="SUBMIT",e.NPS_CONDITIONAL="NPS_CONDITIONAL"}(ViewNavEdgeKind||(ViewNavEdgeKind={}));export var ViewTerminalKind;!function(e){e.TRUE_TERMINAL="TRUE_TERMINAL",e.INTERMEDIATE="INTERMEDIATE"}(ViewTerminalKind||(ViewTerminalKind={}));const SUBMIT_ACTION_TYPES=[ClDocumentActionType.REQUEST,ClDocumentActionType.SUBSCRIBE_CONTACT],NPS_BAND_KEYS=["detractor","passive","promoter"];export const SUCCESS_LEGACY_LABELS=["DOCUMENT_VIEW_TYPE_SUCCESS","DOCUMENT_VIEW_TYPE_SUCCESSFUL_REQUEST","REQUEST_FORM_VIEW_TYPE_SUCCESS"];export const ERROR_LEGACY_LABELS=["DOCUMENT_VIEW_TYPE_ERROR"];export const ALREADY_SUBSCRIBED_LEGACY_LABELS=["DOCUMENT_VIEW_TYPE_SUBSCRIBED"];export const SYSTEM_RESULT_STATE_LABELS=[...SUCCESS_LEGACY_LABELS,...ERROR_LEGACY_LABELS,...ALREADY_SUBSCRIBED_LEGACY_LABELS];function componentModelHasSubmitAction(e){var n,i;try{return!!(null===(i=null===(n=e.props)||void 0===n?void 0:n.handlers)||void 0===i?void 0:i.find(e=>{var n;return null===(n=null==e?void 0:e.actions)||void 0===n?void 0:n.find(e=>SUBMIT_ACTION_TYPES.includes(e.type))}))}catch(e){return!1}}export function viewHasControls(e){if(!e)return!1;let n=0;return iterateDepthFirst(e,e=>{(["INPUT","MULTIPLE_INPUT","PRIZE_BASED_GAMING"].includes(e.type)||componentModelHasSubmitAction(e))&&n++}),n>0}export function isResultView(e,n){return!!e&&(SYSTEM_RESULT_STATE_LABELS.includes(e.label)||n.includes(e.id))}export function getConfiguredResultViewIds(e,n){return n?!e||e.runAction?[]:[e.successViewId,e.errorViewId,e.alreadySubscribedViewId].filter(Boolean):[]}function resolveResultViewIndex(e,n,i,o){const t=null==n?void 0:n[i];if(t){const n=e.findIndex(e=>e.id===t);if(-1!==n)return n}return e.findIndex(e=>o.includes(e.label))}export function submitAdvancesToNextStep(e,n,i,o){const t=n[i+1];if(!t||isResultView(t,o))return!1;return!e.edges.some(e=>e.toIndex===i+1&&e.fromIndex!==i&&e.isForward&&e.kind!==ViewNavEdgeKind.SUBMIT)}export function buildViewNavigationGraph(e,n){var i;const o=new Map;e.forEach((e,n)=>o.set(e.id,n));const t=null!==(i=null==n?void 0:n.submitActionParams)&&void 0!==i?i:void 0,d=e.some(e=>viewHasControls(e)),r=getConfiguredResultViewIds(t,d),s=d?t:void 0,E=[],l=[],u=(e,n,i)=>{switch(i){case ViewNavEdgeKind.GO_TO_NEXT_VIEW:case ViewNavEdgeKind.SUBMIT:case ViewNavEdgeKind.NPS_CONDITIONAL:return!0;case ViewNavEdgeKind.GO_TO_PREVIOUS_VIEW:return!1;default:return n>e}},a=(n,i,o,t)=>{void 0===i||i<0||i>=e.length||E.push({fromIndex:n,toIndex:i,kind:o,isForward:u(n,i,o),label:t})},c=(n,i)=>{var t,d;switch(i.type){case ClDocumentActionType.GO_TO_VIEW:return(null===(t=i.params)||void 0===t?void 0:t.viewId)?o.get(i.params.viewId):"number"==typeof(null===(d=i.params)||void 0===d?void 0:d.viewIndex)?i.params.viewIndex:void 0;case ClDocumentActionType.GO_TO_NEXT_VIEW:return n+1<e.length?n+1:void 0;case ClDocumentActionType.GO_TO_PREVIOUS_VIEW:return n-1>=0?n-1:void 0;default:return}},_=e.map(()=>new Set),I=(e,n,i,o)=>{if(void 0===n||-1===n||n===e)return;const t=`${n}:${i}`;_[e].has(t)||(_[e].add(t),a(e,n,i,o))},T=[];e.forEach((e,n)=>{const i=new Set;let t;iterateDepthFirst(e,e=>{var o,d,r,s,E,l,u;const _=null===(o=e.props)||void 0===o?void 0:o.content,I=[];for(const n of null!==(r=null===(d=e.props)||void 0===d?void 0:d.handlers)&&void 0!==r?r:[])for(const e of null!==(s=n.actions)&&void 0!==s?s:[])I.push({action:e,label:null!==(E=null==_?void 0:_.text)&&void 0!==E?E:""});if(Array.isArray(null==_?void 0:_.options))for(const e of _.options)(null==e?void 0:e.action)&&I.push({action:e.action,label:null!==(u=null!==(l=null==e?void 0:e.label)&&void 0!==l?l:null==e?void 0:e.value)&&void 0!==u?u:""});for(const{action:e,label:i}of I)SUBMIT_ACTION_TYPES.includes(e.type)?t=null!=t?t:i:e.type!==ClDocumentActionType.GO_TO_VIEW&&e.type!==ClDocumentActionType.GO_TO_NEXT_VIEW&&e.type!==ClDocumentActionType.GO_TO_PREVIOUS_VIEW||a(n,c(n,e),e.type,i);NPS_BAND_KEYS.map(e=>(_||{})[e]||null).filter(e=>e).forEach(e=>i.add(e))}),i.forEach(e=>{I(n,o.get(e),ViewNavEdgeKind.NPS_CONDITIONAL,"")}),T[n]=t,l[n]=void 0!==t}),e.forEach((n,i)=>{const o=T[i];if(void 0===o)return;const t=e[i+1],l=submitAdvancesToNextStep({edges:E},e,i,r),u=o,a=()=>{I(i,resolveResultViewIndex(e,s,"errorViewId",ERROR_LEGACY_LABELS),ViewNavEdgeKind.SUBMIT,u),s&&!s.alreadySubscribedViewId?I(i,resolveResultViewIndex(e,s,"successViewId",SUCCESS_LEGACY_LABELS),ViewNavEdgeKind.SUBMIT,u):I(i,resolveResultViewIndex(e,s,"alreadySubscribedViewId",ALREADY_SUBSCRIBED_LEGACY_LABELS),ViewNavEdgeKind.SUBMIT,u)};if(l)return I(i,i+1,ViewNavEdgeKind.SUBMIT,u),void(!viewHasControls(t)&&d&&a());const _=null==s?void 0:s.runAction;_?I(i,c(i,_),_.type,u):(I(i,resolveResultViewIndex(e,s,"successViewId",SUCCESS_LEGACY_LABELS),ViewNavEdgeKind.SUBMIT,u),a())});const S=e.map((e,n)=>{var i,o;return{index:n,id:e.id,label:null!==(i=e.label)&&void 0!==i?i:e.id,hasSubmitAction:null!==(o=l[n])&&void 0!==o&&o}});return{nodes:S,edges:E}}export function classifyView(e,n){return e.edges.some(e=>e.fromIndex===n)?ViewTerminalKind.INTERMEDIATE:ViewTerminalKind.TRUE_TERMINAL}export function classifyViews(e){return e.nodes.map(n=>classifyView(e,n.index))}export function isAutoCommitTerminal(e,n){const i=e.nodes[n];return!!i&&(classifyView(e,n)===ViewTerminalKind.TRUE_TERMINAL&&!i.hasSubmitAction)}export function isMultiViewFlow(e){if(e.nodes.length<2)return!1;const n=new Set([0]),i=[0];for(;i.length;){const o=i.shift();for(const t of e.edges)t.fromIndex!==o||n.has(t.toIndex)||(n.add(t.toIndex),i.push(t.toIndex))}return n.size>1}export function isNonLinearFlow(e){return e.edges.some(e=>e.kind===ViewNavEdgeKind.GO_TO_VIEW||e.kind===ViewNavEdgeKind.NPS_CONDITIONAL||e.kind===ViewNavEdgeKind.SUBMIT&&e.toIndex<e.fromIndex)}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@claspo/common",
3
- "version": "7.4.0-nonlinear3",
3
+ "version": "7.5.0-sp1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "engines": {
@@ -28,7 +28,7 @@
28
28
  "sync:docs": "node ../../scripts/sync-docs.js --package=common"
29
29
  },
30
30
  "dependencies": {
31
- "velocityjs": "2.0.6"
31
+ "velocityjs": "2.1.6"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@types/jest": "^27.5.1",
@@ -1 +1 @@
1
- import Velocity from"velocityjs";import SysVelocityContext from"./SysVelocityContext";const sysCtx=(new SysVelocityContext).create();export default class SysVelocityRenderer{render(e,t){return Velocity.render(e,Object.assign(Object.assign({},sysCtx),t))}}
1
+ import*as Velocity from"velocityjs";import SysVelocityContext from"./SysVelocityContext";const sysCtx=(new SysVelocityContext).create();export default class SysVelocityRenderer{render(e,t){return Velocity.render(e,Object.assign(Object.assign({},sysCtx),t))}}