@buddy-technology/offer-component 0.3.3 → 1.1.0
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/CHANGELOG.md +51 -2
- package/README.md +77 -16
- package/dist/index.js +304 -136
- package/dist/index.js.map +1 -0
- package/dist/index.modern.mjs +273 -0
- package/dist/index.modern.mjs.map +1 -0
- package/lib/components/BuddyOfferElement.d.ts +5 -0
- package/lib/components/BuddyOfferElement.d.ts.map +1 -0
- package/lib/components/index.d.ts +2 -0
- package/lib/components/index.d.ts.map +1 -0
- package/lib/hooks/index.d.ts +3 -0
- package/lib/hooks/index.d.ts.map +1 -0
- package/lib/hooks/useConfig.d.ts +7 -0
- package/lib/hooks/useConfig.d.ts.map +1 -0
- package/lib/hooks/useUpdateEffect.d.ts +4 -0
- package/lib/hooks/useUpdateEffect.d.ts.map +1 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/interface/index.d.ts +76 -0
- package/lib/interface/index.d.ts.map +1 -0
- package/lib/util/dictionary.d.ts +21 -0
- package/lib/util/dictionary.d.ts.map +1 -0
- package/lib/util/index.d.ts +9 -0
- package/lib/util/index.d.ts.map +1 -0
- package/package.json +23 -29
- package/release.config.js +22 -0
- package/setupTests.ts +8 -0
- package/tsconfig.eslint.json +12 -0
- package/API.md +0 -184
- package/dist/util.js +0 -252
- package/lib/types.d.ts +0 -151
package/setupTests.ts
ADDED
package/API.md
DELETED
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
## Functions
|
|
2
|
-
|
|
3
|
-
<dl>
|
|
4
|
-
<dt><a href="#BuddyOfferElement">BuddyOfferElement(options)</a> ⇒ <code><a href="#BuddyOfferElementProps">FunctionComponent.<BuddyOfferElementProps></a></code></dt>
|
|
5
|
-
<dd></dd>
|
|
6
|
-
</dl>
|
|
7
|
-
|
|
8
|
-
## Typedefs
|
|
9
|
-
|
|
10
|
-
<dl>
|
|
11
|
-
<dt><a href="#DataObject">DataObject</a> : <code>Object</code></dt>
|
|
12
|
-
<dd></dd>
|
|
13
|
-
<dt><a href="#AddToCartFunction">AddToCartFunction</a> ⇒ <code><a href="#DataObject">DataObject</a></code></dt>
|
|
14
|
-
<dd><p>A callback to be called with a payload object when users opt into the offer.</p>
|
|
15
|
-
</dd>
|
|
16
|
-
<dt><a href="#RemoveFromCartFunction">RemoveFromCartFunction</a> ⇒ <code><a href="#DataObject">DataObject</a></code></dt>
|
|
17
|
-
<dd><p>A callback to be called with a payload object when users opt out of the offer.</p>
|
|
18
|
-
</dd>
|
|
19
|
-
<dt><a href="#ScrollToTopFunction">ScrollToTopFunction</a> : <code>function</code></dt>
|
|
20
|
-
<dd><p>A function to override the default scroll to top of offer element behavior when navigating between screens</p>
|
|
21
|
-
</dd>
|
|
22
|
-
<dt><a href="#OverridesObject">OverridesObject</a> : <code>Object</code></dt>
|
|
23
|
-
<dd></dd>
|
|
24
|
-
<dt><a href="#ThemeObject">ThemeObject</a> : <code>Object</code></dt>
|
|
25
|
-
<dd></dd>
|
|
26
|
-
<dt><a href="#LogoOverride">LogoOverride</a> : <code>Object</code></dt>
|
|
27
|
-
<dd></dd>
|
|
28
|
-
<dt><a href="#EventObject">EventObject</a> : <code>Object</code></dt>
|
|
29
|
-
<dd></dd>
|
|
30
|
-
<dt><a href="#OnUserEventCallback">OnUserEventCallback</a> : <code>function</code></dt>
|
|
31
|
-
<dd></dd>
|
|
32
|
-
<dt><a href="#BuddyOfferElementProps">BuddyOfferElementProps</a> : <code>Object</code></dt>
|
|
33
|
-
<dd></dd>
|
|
34
|
-
</dl>
|
|
35
|
-
|
|
36
|
-
<a name="BuddyOfferElement"></a>
|
|
37
|
-
|
|
38
|
-
## BuddyOfferElement(options) ⇒ [<code>FunctionComponent.<BuddyOfferElementProps></code>](#BuddyOfferElementProps)
|
|
39
|
-
**Kind**: global function
|
|
40
|
-
|
|
41
|
-
| Param | Type |
|
|
42
|
-
| --- | --- |
|
|
43
|
-
| options | [<code>BuddyOfferElementProps</code>](#BuddyOfferElementProps) |
|
|
44
|
-
|
|
45
|
-
<a name="DataObject"></a>
|
|
46
|
-
|
|
47
|
-
## DataObject : <code>Object</code>
|
|
48
|
-
**Kind**: global typedef
|
|
49
|
-
**Properties**
|
|
50
|
-
|
|
51
|
-
| Name | Type | Description |
|
|
52
|
-
| --- | --- | --- |
|
|
53
|
-
| [customer] | <code>Object</code> | customer data |
|
|
54
|
-
| [policy] | <code>Object</code> | policy data |
|
|
55
|
-
|
|
56
|
-
<a name="AddToCartFunction"></a>
|
|
57
|
-
|
|
58
|
-
## AddToCartFunction ⇒ [<code>DataObject</code>](#DataObject)
|
|
59
|
-
A callback to be called with a payload object when users opt into the offer.
|
|
60
|
-
|
|
61
|
-
**Kind**: global typedef
|
|
62
|
-
**Returns**: [<code>DataObject</code>](#DataObject) - the policy payload
|
|
63
|
-
<a name="RemoveFromCartFunction"></a>
|
|
64
|
-
|
|
65
|
-
## RemoveFromCartFunction ⇒ [<code>DataObject</code>](#DataObject)
|
|
66
|
-
A callback to be called with a payload object when users opt out of the offer.
|
|
67
|
-
|
|
68
|
-
**Kind**: global typedef
|
|
69
|
-
**Returns**: [<code>DataObject</code>](#DataObject) - the policy payload
|
|
70
|
-
<a name="ScrollToTopFunction"></a>
|
|
71
|
-
|
|
72
|
-
## ScrollToTopFunction : <code>function</code>
|
|
73
|
-
A function to override the default scroll to top of offer element behavior when navigating between screens
|
|
74
|
-
|
|
75
|
-
**Kind**: global typedef
|
|
76
|
-
<a name="OverridesObject"></a>
|
|
77
|
-
|
|
78
|
-
## OverridesObject : <code>Object</code>
|
|
79
|
-
**Kind**: global typedef
|
|
80
|
-
**Properties**
|
|
81
|
-
|
|
82
|
-
| Name | Type | Description |
|
|
83
|
-
| --- | --- | --- |
|
|
84
|
-
| [webFonts] | <code>Array.<String></code> | array of url strings linking to web fonts. |
|
|
85
|
-
| [styles] | <code>Object</code> | Object Styles object for overriding any css. |
|
|
86
|
-
| [colors] | <code>Object</code> | Object for overriding individual color options. |
|
|
87
|
-
|
|
88
|
-
<a name="ThemeObject"></a>
|
|
89
|
-
|
|
90
|
-
## ThemeObject : <code>Object</code>
|
|
91
|
-
**Kind**: global typedef
|
|
92
|
-
**Properties**
|
|
93
|
-
|
|
94
|
-
| Name | Type | Default | Description |
|
|
95
|
-
| --- | --- | --- | --- |
|
|
96
|
-
| [baseTheme] | <code>String</code> | <code>'base'</code> | The base theme to style with. Can be used simply as a started and overwritten. |
|
|
97
|
-
| [palette] | <code>String</code> | <code>'base'</code> | The base color scheme to style with. Can be used simply as a started and overwritten. |
|
|
98
|
-
| [overrides] | [<code>OverridesObject</code>](#OverridesObject) | | |
|
|
99
|
-
|
|
100
|
-
**Example**
|
|
101
|
-
```js
|
|
102
|
-
const theme = {
|
|
103
|
-
baseTheme: 'base',
|
|
104
|
-
palette: 'buddy',
|
|
105
|
-
overrides: {
|
|
106
|
-
webFonts: [
|
|
107
|
-
'https://fonts.googleapis.com/css2?family=Rubik:wght@700&display=swap',
|
|
108
|
-
],
|
|
109
|
-
styles: {
|
|
110
|
-
h1: {
|
|
111
|
-
color: 'var(--color-text-primary)',
|
|
112
|
-
fontFamily: 'Rubik, sans-serif',
|
|
113
|
-
fontSize: '2rem',
|
|
114
|
-
'@media (min-width: 992px)': {
|
|
115
|
-
fontSize: '3rem',
|
|
116
|
-
},
|
|
117
|
-
'&:hover': {
|
|
118
|
-
boxShadow: 'none',
|
|
119
|
-
backgroundColor: '#FBF9EF',
|
|
120
|
-
},
|
|
121
|
-
},
|
|
122
|
-
body: { color: '#0A242D' },
|
|
123
|
-
'.input-text': {
|
|
124
|
-
border: 'none',
|
|
125
|
-
color: '#333333',
|
|
126
|
-
},
|
|
127
|
-
},
|
|
128
|
-
colors: { textPrimary: '#0A242D' },
|
|
129
|
-
},
|
|
130
|
-
};
|
|
131
|
-
```
|
|
132
|
-
<a name="LogoOverride"></a>
|
|
133
|
-
|
|
134
|
-
## LogoOverride : <code>Object</code>
|
|
135
|
-
**Kind**: global typedef
|
|
136
|
-
**Properties**
|
|
137
|
-
|
|
138
|
-
| Name | Type | Description |
|
|
139
|
-
| --- | --- | --- |
|
|
140
|
-
| url | <code>String</code> | destination url when users click the trust badge |
|
|
141
|
-
| src | <code>String</code> | src of the img for displaying the trust badge |
|
|
142
|
-
| [alt] | <code>String</code> | alt text for trust badge image |
|
|
143
|
-
|
|
144
|
-
<a name="EventObject"></a>
|
|
145
|
-
|
|
146
|
-
## EventObject : <code>Object</code>
|
|
147
|
-
**Kind**: global typedef
|
|
148
|
-
|
|
149
|
-
| Param | Type | Description |
|
|
150
|
-
| --- | --- | --- |
|
|
151
|
-
| eventType | <code>string</code> | the type of user event (eg:'onCheckout') |
|
|
152
|
-
| data | <code>object</code> | data object related to the user event. |
|
|
153
|
-
| data.timestamp | <code>object</code> | timestamp of the event. All events have a timestamp property. |
|
|
154
|
-
|
|
155
|
-
<a name="OnUserEventCallback"></a>
|
|
156
|
-
|
|
157
|
-
## OnUserEventCallback : <code>function</code>
|
|
158
|
-
**Kind**: global typedef
|
|
159
|
-
|
|
160
|
-
| Param | Type | Description |
|
|
161
|
-
| --- | --- | --- |
|
|
162
|
-
| type | [<code>EventObject</code>](#EventObject) | the type of user event (eg:'onCheckout') |
|
|
163
|
-
|
|
164
|
-
<a name="BuddyOfferElementProps"></a>
|
|
165
|
-
|
|
166
|
-
## BuddyOfferElementProps : <code>Object</code>
|
|
167
|
-
**Kind**: global typedef
|
|
168
|
-
**Properties**
|
|
169
|
-
|
|
170
|
-
| Name | Type | Default | Description |
|
|
171
|
-
| --- | --- | --- | --- |
|
|
172
|
-
| ion | <code>String</code> | | The ion id for the offering. |
|
|
173
|
-
| partnerID | <code>String</code> | | The partner ID required for instantiating the Offer |
|
|
174
|
-
| [stage] | <code>String</code> | <code>"STAGING"</code> | toggle's the environment for the Offer Component. Defaults to STAGING. Must be set to "PRODUCTION" before going live. |
|
|
175
|
-
| [viewType] | <code>String</code> | <code>"paginated"</code> | establishes how the offer should display to the user. One of: 'paginated', 'single-form' or 'offer-only.' |
|
|
176
|
-
| [theme] | [<code>ThemeObject</code>](#ThemeObject) | | theming object for customizing offer component's styles |
|
|
177
|
-
| [data] | [<code>DataObject</code>](#DataObject) | | Any customer or policy data to pre-fill the offer with. Refer to your individual ION for data structure. |
|
|
178
|
-
| [onUserEvent] | [<code>OnUserEventCallback</code>](#OnUserEventCallback) | | callback function for tracking user behavioral data. Triggers on user interactions such as input focus/blur, in-app navigation, etc. Refer to the docs for more details. |
|
|
179
|
-
| [onAddToCart] | [<code>AddToCartFunction</code>](#AddToCartFunction) | | callback function triggered when users opt into an offer-only offer. |
|
|
180
|
-
| [onRemoveFromCart] | [<code>RemoveFromCartFunction</code>](#RemoveFromCartFunction) | | callback function triggered when users opt out of an offer-only offer. |
|
|
181
|
-
| [overrideScrollToTop] | [<code>ScrollToTopFunction</code>](#ScrollToTopFunction) | | When present, this overrides the default scroll to top of offer element behavior when navigating between screens. |
|
|
182
|
-
| [includeCheckout] | <code>boolean</code> | | toggles whether or not to display the card capture checkout view. Defaults to true. When false, an AddToCart callback must be provided. |
|
|
183
|
-
| [logoOverride] | [<code>LogoOverride</code>](#LogoOverride) | | object for overriding Buddy's trust badge. |
|
|
184
|
-
|
package/dist/util.js
DELETED
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.updateOffer = exports.loadScript = exports.findScript = void 0;
|
|
7
|
-
|
|
8
|
-
require("core-js/modules/es.array.includes.js");
|
|
9
|
-
|
|
10
|
-
require("core-js/modules/es.string.trim.js");
|
|
11
|
-
|
|
12
|
-
require("core-js/modules/es.array.reduce.js");
|
|
13
|
-
|
|
14
|
-
require("core-js/modules/es.regexp.exec.js");
|
|
15
|
-
|
|
16
|
-
require("core-js/modules/es.regexp.test.js");
|
|
17
|
-
|
|
18
|
-
require("core-js/modules/es.promise.js");
|
|
19
|
-
|
|
20
|
-
require("core-js/modules/es.string.includes.js");
|
|
21
|
-
|
|
22
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
23
|
-
|
|
24
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
25
|
-
|
|
26
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
27
|
-
|
|
28
|
-
const EXISTING_SCRIPT_MESSAGE = 'Buddy Offer Script is already loaded.';
|
|
29
|
-
const SCRIPTS = {
|
|
30
|
-
LOCAL: {
|
|
31
|
-
URL: 'http://localhost:8008/index.js',
|
|
32
|
-
REGEX: /^http:\/\/localhost:8008\/index\.js\/?(\?.*)?$/
|
|
33
|
-
},
|
|
34
|
-
// TODO: Delete this in favor of "testing", once we're sure nothing is using it.
|
|
35
|
-
DEVELOPMENT: {
|
|
36
|
-
URL: 'https://js.buddy.insure/v2/dev/index.js',
|
|
37
|
-
REGEX: /^https:\/\/js\.buddy\.insure\/v2\/dev\/index\.js\/?(\?.*)?$/
|
|
38
|
-
},
|
|
39
|
-
TESTING: {
|
|
40
|
-
URL: 'https://js.buddy.insure/v2/testing/index.js',
|
|
41
|
-
REGEX: /^https:\/\/js\.buddy\.insure\/v2\/testing\/index\.js\/?(\?.*)?$/
|
|
42
|
-
},
|
|
43
|
-
STAGING: {
|
|
44
|
-
URL: 'https://js.buddy.insure/v2/staging/index.js',
|
|
45
|
-
REGEX: /^https:\/\/js\.buddy\.insure\/v2\/staging\/index\.js\/?(\?.*)?$/
|
|
46
|
-
},
|
|
47
|
-
PRODUCTION: {
|
|
48
|
-
URL: 'https://js.buddy.insure/v2/index.js',
|
|
49
|
-
REGEX: /^https:\/\/js\.buddy\.insure\/v2\/index\.js\/?(\?.*)?$/
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
const STAGES = Object.keys(SCRIPTS);
|
|
53
|
-
/**
|
|
54
|
-
* @type {Object}
|
|
55
|
-
* @property {string} stage
|
|
56
|
-
*/
|
|
57
|
-
|
|
58
|
-
const defaultOptions = {
|
|
59
|
-
stage: 'STAGING'
|
|
60
|
-
};
|
|
61
|
-
/**
|
|
62
|
-
* @function isEmptyOrNil
|
|
63
|
-
* @param {*} value
|
|
64
|
-
* @returns {Boolean}
|
|
65
|
-
*/
|
|
66
|
-
|
|
67
|
-
const isEmptyOrNil = value => {
|
|
68
|
-
const isNil = val => [undefined, null].includes(val);
|
|
69
|
-
|
|
70
|
-
const isEmptyStr = str => typeof str === 'string' && str.trim().length === 0;
|
|
71
|
-
|
|
72
|
-
const isEmptyObjOrArr = obj => typeof obj === 'object' && obj.length === undefined && Object.keys(obj).length === 0 || Array.isArray(obj) && obj.length === 0;
|
|
73
|
-
|
|
74
|
-
return isNil(value) || isEmptyStr(value) || isEmptyObjOrArr(value);
|
|
75
|
-
};
|
|
76
|
-
/**
|
|
77
|
-
* @param {Array<String>} propsToCheck
|
|
78
|
-
* @param {Object} obj
|
|
79
|
-
* @returns {(null | String)}
|
|
80
|
-
*/
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const validatePropertiesOfObject = (propsToCheck, obj) => {
|
|
84
|
-
const emptyProps = propsToCheck.filter(prop => isEmptyOrNil(obj[prop]));
|
|
85
|
-
|
|
86
|
-
if (emptyProps.length) {
|
|
87
|
-
const displayMissingProps = emptyProps.reduce((prev, current, i) => {
|
|
88
|
-
const isLastEl = i === emptyProps.length - 1;
|
|
89
|
-
return isLastEl ? "".concat(prev).concat(current, ".") : "".concat(prev).concat(current, ", ");
|
|
90
|
-
}, '');
|
|
91
|
-
return "The following props are required: ".concat(displayMissingProps);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return null;
|
|
95
|
-
};
|
|
96
|
-
/**
|
|
97
|
-
* @function findScript
|
|
98
|
-
* @param {String} stage
|
|
99
|
-
* @returns {(HTMLElement | undefined)}
|
|
100
|
-
*/
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const findScript = function findScript() {
|
|
104
|
-
let stage = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultOptions.stage;
|
|
105
|
-
const {
|
|
106
|
-
URL,
|
|
107
|
-
REGEX
|
|
108
|
-
} = SCRIPTS[stage];
|
|
109
|
-
const scripts = Array.from(document.querySelectorAll("script[src^=\"".concat(URL, "\"]")));
|
|
110
|
-
const matchedScript = scripts.find(_ref => {
|
|
111
|
-
let {
|
|
112
|
-
src
|
|
113
|
-
} = _ref;
|
|
114
|
-
return REGEX.test(src);
|
|
115
|
-
});
|
|
116
|
-
return matchedScript;
|
|
117
|
-
};
|
|
118
|
-
/**
|
|
119
|
-
* @function updateOffer
|
|
120
|
-
* @param {Object} options
|
|
121
|
-
*/
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
exports.findScript = findScript;
|
|
125
|
-
|
|
126
|
-
const updateOffer = options => {
|
|
127
|
-
if (window.Buddy) {
|
|
128
|
-
try {
|
|
129
|
-
window.Buddy.updateOffer(options);
|
|
130
|
-
} catch (error) {
|
|
131
|
-
// eslint-disable-next-line no-console
|
|
132
|
-
console.error(error);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
/**
|
|
137
|
-
* @function createOffer
|
|
138
|
-
* @param {Object} options
|
|
139
|
-
*/
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
exports.updateOffer = updateOffer;
|
|
143
|
-
|
|
144
|
-
const createOffer = options => {
|
|
145
|
-
if (window.Buddy) {
|
|
146
|
-
try {
|
|
147
|
-
window.Buddy.createOffer(options);
|
|
148
|
-
} catch (error) {
|
|
149
|
-
// eslint-disable-next-line no-console
|
|
150
|
-
console.error(error);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
/**
|
|
155
|
-
* @function injectScript
|
|
156
|
-
* @param {Object} options
|
|
157
|
-
* @returns {HTMLElement}
|
|
158
|
-
*/
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
const injectScript = options => {
|
|
162
|
-
const finalOptions = _objectSpread(_objectSpread({}, defaultOptions), options);
|
|
163
|
-
|
|
164
|
-
const script = document.createElement('script');
|
|
165
|
-
script.src = "".concat(SCRIPTS[finalOptions.stage].URL);
|
|
166
|
-
document.body.appendChild(script);
|
|
167
|
-
|
|
168
|
-
script.onload = () => createOffer(finalOptions);
|
|
169
|
-
|
|
170
|
-
return script;
|
|
171
|
-
};
|
|
172
|
-
/**
|
|
173
|
-
* @type {(Promise | null)}
|
|
174
|
-
*/
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
let scriptPromise = null;
|
|
178
|
-
/**
|
|
179
|
-
* @function loadScript
|
|
180
|
-
* @param {Object} options
|
|
181
|
-
* @returns {Promise}
|
|
182
|
-
*/
|
|
183
|
-
|
|
184
|
-
const loadScript = options => {
|
|
185
|
-
// Ensure that we only attempt to script once
|
|
186
|
-
if (scriptPromise !== null) {
|
|
187
|
-
return scriptPromise;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
scriptPromise = new Promise((resolve, reject) => {
|
|
191
|
-
if (typeof window === 'undefined') {
|
|
192
|
-
// Resolve to null when imported server side. This makes the module
|
|
193
|
-
// safe to import in an isomorphic code base.
|
|
194
|
-
resolve(null);
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
if (window.Buddy) {
|
|
199
|
-
// eslint-disable-next-line no-console
|
|
200
|
-
console.warn(EXISTING_SCRIPT_MESSAGE);
|
|
201
|
-
resolve(window.Buddy);
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
try {
|
|
206
|
-
const requiredProps = ['ion', 'partnerID'];
|
|
207
|
-
const missingRequiredProps = validatePropertiesOfObject(requiredProps, options);
|
|
208
|
-
|
|
209
|
-
if (missingRequiredProps) {
|
|
210
|
-
reject(new Error(missingRequiredProps));
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
if (!(options !== null && options !== void 0 && options.stage)) {
|
|
215
|
-
// eslint-disable-next-line no-console
|
|
216
|
-
console.warn("No stage passed to BuddyOfferElement. Using default stage: ".concat(defaultOptions.stage));
|
|
217
|
-
} // If stage is passed, ensure it is one of the prescribed options.
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
if (options !== null && options !== void 0 && options.stage && !STAGES.includes(options.stage)) {
|
|
221
|
-
const msg = "The stage prop must be one of: [".concat(STAGES.join(' , '), "], but received \"").concat(options.stage, ".\"");
|
|
222
|
-
reject(new Error(msg));
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
let script = findScript(options === null || options === void 0 ? void 0 : options.stage);
|
|
227
|
-
|
|
228
|
-
if (script) {
|
|
229
|
-
// eslint-disable-next-line no-console
|
|
230
|
-
console.warn(EXISTING_SCRIPT_MESSAGE);
|
|
231
|
-
} else if (!script) {
|
|
232
|
-
script = injectScript(options);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
script.addEventListener('load', () => {
|
|
236
|
-
if (window.Buddy) {
|
|
237
|
-
resolve(window.Buddy);
|
|
238
|
-
} else {
|
|
239
|
-
reject(new Error('Buddy Offer Element not available'));
|
|
240
|
-
}
|
|
241
|
-
});
|
|
242
|
-
script.addEventListener('error', () => {
|
|
243
|
-
reject(new Error('Failed to load Buddy Offer Element'));
|
|
244
|
-
});
|
|
245
|
-
} catch (error) {
|
|
246
|
-
reject(error);
|
|
247
|
-
}
|
|
248
|
-
});
|
|
249
|
-
return scriptPromise;
|
|
250
|
-
};
|
|
251
|
-
|
|
252
|
-
exports.loadScript = loadScript;
|
package/lib/types.d.ts
DELETED
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
export = BuddyOfferElement
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @property [customer] - customer data
|
|
5
|
-
* @property [policy] - policy data
|
|
6
|
-
*/
|
|
7
|
-
declare type DataObject = {
|
|
8
|
-
customer?: any;
|
|
9
|
-
policy?: any;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* A callback to be called with a payload object when users opt into the offer.
|
|
14
|
-
*/
|
|
15
|
-
declare type AddToCartFunction = () => DataObject;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* A callback to be called with a payload object when users opt out of the offer.
|
|
19
|
-
*/
|
|
20
|
-
declare type RemoveFromCartFunction = () => DataObject;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* A function to override the default scroll to top of offer element behavior when navigating between screens
|
|
24
|
-
*/
|
|
25
|
-
declare type ScrollToTopFunction = () => void;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* @property [webFonts] - array of url strings linking to web fonts.
|
|
29
|
-
* @property [styles] - Object Styles object for overriding any css.
|
|
30
|
-
* @property [colors] - Object for overriding individual color options.
|
|
31
|
-
*/
|
|
32
|
-
declare type OverridesObject = {
|
|
33
|
-
webFonts?: String[];
|
|
34
|
-
styles?: any;
|
|
35
|
-
colors?: any;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* @example
|
|
40
|
-
* const theme = {
|
|
41
|
-
* baseTheme: 'base',
|
|
42
|
-
* palette: 'buddy',
|
|
43
|
-
* overrides: {
|
|
44
|
-
* webFonts: [
|
|
45
|
-
* 'https://fonts.googleapis.com/css2?family=Rubik:wght@700&display=swap',
|
|
46
|
-
* ],
|
|
47
|
-
* styles: {
|
|
48
|
-
* h1: {
|
|
49
|
-
* color: 'var(--color-text-primary)',
|
|
50
|
-
* fontFamily: 'Rubik, sans-serif',
|
|
51
|
-
* fontSize: '2rem',
|
|
52
|
-
* '@media (min-width: 992px)': {
|
|
53
|
-
* fontSize: '3rem',
|
|
54
|
-
* },
|
|
55
|
-
* '&:hover': {
|
|
56
|
-
* boxShadow: 'none',
|
|
57
|
-
* backgroundColor: '#FBF9EF',
|
|
58
|
-
* },
|
|
59
|
-
* },
|
|
60
|
-
* body: { color: '#0A242D' },
|
|
61
|
-
* '.input-text': {
|
|
62
|
-
* border: 'none',
|
|
63
|
-
* color: '#333333',
|
|
64
|
-
* },
|
|
65
|
-
* },
|
|
66
|
-
* colors: { textPrimary: '#0A242D' },
|
|
67
|
-
* },
|
|
68
|
-
* };
|
|
69
|
-
* @property [baseTheme = 'base'] - The base theme to style with. Can be used simply as a started and overwritten.
|
|
70
|
-
* @property [palette = 'base'] - The base color scheme to style with. Can be used simply as a started and overwritten.
|
|
71
|
-
*/
|
|
72
|
-
declare type ThemeObject = {
|
|
73
|
-
baseTheme?: string;
|
|
74
|
-
palette?: string;
|
|
75
|
-
overrides?: OverridesObject;
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* @property url - destination url when users click the trust badge
|
|
80
|
-
* @property src - src of the img for displaying the trust badge
|
|
81
|
-
* @property [alt] - alt text for trust badge image
|
|
82
|
-
*/
|
|
83
|
-
declare type LogoOverride = {
|
|
84
|
-
url: string;
|
|
85
|
-
src: string;
|
|
86
|
-
alt?: string;
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* @param eventType - the type of user event (eg:'onCheckout')
|
|
91
|
-
* @param data - data object related to the user event.
|
|
92
|
-
* @param data.timestamp - timestamp of the event. All events have a timestamp property.
|
|
93
|
-
*/
|
|
94
|
-
declare type EventObject = any;
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* @param type - the type of user event (eg:'onCheckout')
|
|
98
|
-
*/
|
|
99
|
-
declare type OnUserEventCallback = (type: EventObject) => void;
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* @property ion - The ion id for the offering.
|
|
103
|
-
* @property partnerID - The partner ID required for instantiating the Offer
|
|
104
|
-
* @property [stage = STAGING] - toggle's the environment for the Offer Component. Defaults to STAGING. Must be set to PRODUCTION before going live.
|
|
105
|
-
* @property [viewType = paginated] - establishes how the offer should display to the user. One of: 'paginated', 'single-form' or 'offer-only.'
|
|
106
|
-
* @property [theme] - theming object for customizing offer component's styles
|
|
107
|
-
* @property [data] - Any customer or policy data to pre-fill the offer with. Refer to your individual ION for data structure.
|
|
108
|
-
* @property [onUserEvent] - callback function for tracking user behavioral data. Triggers on user interactions such as input focus/blur, in-app navigation, etc. Refer to the docs for more details.
|
|
109
|
-
* @property [onAddToCart] - callback function triggered when users opt into an offer-only offer.
|
|
110
|
-
* @property [onRemoveFromCart] - callback function triggered when users opt out of an offer-only offer.
|
|
111
|
-
* @property [overrideScrollToTop] - When present, this overrides the default scroll to top of offer element behavior when navigating between screens.
|
|
112
|
-
* @property [includeCheckout] - toggles whether or not to display the card capture checkout view. Defaults to true. When false, an AddToCart callback must be provided.
|
|
113
|
-
* @property [logoOverride] - object for overriding Buddy's trust badge.
|
|
114
|
-
*/
|
|
115
|
-
declare type BuddyOfferElementProps = {
|
|
116
|
-
ion: string;
|
|
117
|
-
partnerID: string;
|
|
118
|
-
stage?: string;
|
|
119
|
-
viewType?: string;
|
|
120
|
-
theme?: ThemeObject;
|
|
121
|
-
data?: DataObject;
|
|
122
|
-
onUserEvent?: OnUserEventCallback;
|
|
123
|
-
onAddToCart?: AddToCartFunction;
|
|
124
|
-
onRemoveFromCart?: RemoveFromCartFunction;
|
|
125
|
-
overrideScrollToTop?: ScrollToTopFunction;
|
|
126
|
-
includeCheckout?: boolean;
|
|
127
|
-
logoOverride?: LogoOverride;
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
declare function BuddyOfferElement(options: BuddyOfferElementProps): FunctionComponent<BuddyOfferElementProps>;
|
|
131
|
-
|
|
132
|
-
declare const defaultOptions: {
|
|
133
|
-
stage: string;
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
declare function isEmptyOrNil(value: any): boolean;
|
|
137
|
-
|
|
138
|
-
declare function validatePropertiesOfObject(propsToCheck: String[], obj: any): null | string;
|
|
139
|
-
|
|
140
|
-
declare function findScript(stage: string): HTMLElement | undefined;
|
|
141
|
-
|
|
142
|
-
declare function updateOffer(options: any): void;
|
|
143
|
-
|
|
144
|
-
declare function createOffer(options: any): void;
|
|
145
|
-
|
|
146
|
-
declare function injectScript(options: any): HTMLElement;
|
|
147
|
-
|
|
148
|
-
declare var scriptPromise: Promise | null;
|
|
149
|
-
|
|
150
|
-
declare function loadScript(options: any): Promise;
|
|
151
|
-
|