@hellotext/hellotext 2.3.7 → 2.3.9
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/README.md +2 -1
- package/dist/hellotext.js +1 -1
- package/index.d.ts +48 -15
- package/lib/controllers/message_controller.cjs +19 -0
- package/lib/controllers/message_controller.js +19 -0
- package/lib/core/event.cjs +1 -1
- package/lib/core/event.js +1 -1
- package/lib/hellotext.cjs +9 -3
- package/lib/hellotext.js +10 -6
- package/lib/models/business.cjs +69 -0
- package/lib/models/business.js +80 -0
- package/package.json +1 -1
- package/src/controllers/message_controller.js +20 -0
- package/src/core/event.js +1 -0
- package/src/hellotext.js +10 -3
- package/src/models/business.js +74 -0
package/index.d.ts
CHANGED
|
@@ -5,24 +5,57 @@ export interface HellotextConfig {
|
|
|
5
5
|
autoMount?: boolean
|
|
6
6
|
successMessage?: boolean | string
|
|
7
7
|
}
|
|
8
|
-
webchat?:
|
|
9
|
-
id?: string
|
|
10
|
-
container?: string
|
|
11
|
-
placement?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'
|
|
12
|
-
classes?: string | string[]
|
|
13
|
-
triggerClasses?: string | string[]
|
|
14
|
-
behaviour?: 'modal' | 'popover'
|
|
15
|
-
style?: {
|
|
16
|
-
primaryColor?: string
|
|
17
|
-
secondaryColor?: string
|
|
18
|
-
typography?: string
|
|
19
|
-
}
|
|
20
|
-
strategy?: 'absolute' | 'fixed'
|
|
21
|
-
}
|
|
8
|
+
webchat?: false | HellotextWebchatConfig
|
|
22
9
|
session?: string
|
|
23
10
|
autoGenerateSession?: boolean
|
|
24
11
|
}
|
|
25
12
|
|
|
13
|
+
export interface HellotextWebchatConfig {
|
|
14
|
+
id?: string
|
|
15
|
+
container?: string
|
|
16
|
+
placement?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'
|
|
17
|
+
classes?: string | string[]
|
|
18
|
+
triggerClasses?: string | string[]
|
|
19
|
+
behaviour?: 'modal' | 'popover'
|
|
20
|
+
style?: {
|
|
21
|
+
primaryColor?: string
|
|
22
|
+
secondaryColor?: string
|
|
23
|
+
typography?: string
|
|
24
|
+
}
|
|
25
|
+
strategy?: 'absolute' | 'fixed'
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface HellotextBusinessCountry {
|
|
29
|
+
code?: string
|
|
30
|
+
prefix?: string
|
|
31
|
+
[key: string]: any
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface HellotextBusinessData {
|
|
35
|
+
id?: string
|
|
36
|
+
country?: HellotextBusinessCountry | string
|
|
37
|
+
features?: Record<string, any>
|
|
38
|
+
locale?: string
|
|
39
|
+
style_url?: string
|
|
40
|
+
webchat?: HellotextWebchatConfig | null
|
|
41
|
+
whitelist?: string | string[] | null
|
|
42
|
+
subscription?: string | null
|
|
43
|
+
[key: string]: any
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface HellotextBusiness {
|
|
47
|
+
id: string
|
|
48
|
+
data: HellotextBusinessData | null
|
|
49
|
+
readonly subscription: string | null | undefined
|
|
50
|
+
readonly country: HellotextBusinessCountry | string | undefined
|
|
51
|
+
readonly enabledWhitelist: boolean
|
|
52
|
+
readonly locale: any
|
|
53
|
+
readonly features: Record<string, any> | null | undefined
|
|
54
|
+
hydrate(): Promise<HellotextBusinessData | null>
|
|
55
|
+
setData(data: HellotextBusinessData): void
|
|
56
|
+
setLocale(locale: string): void
|
|
57
|
+
}
|
|
58
|
+
|
|
26
59
|
export interface TrackingParams {
|
|
27
60
|
amount?: number
|
|
28
61
|
currency?: string
|
|
@@ -63,7 +96,7 @@ declare class Hellotext {
|
|
|
63
96
|
static get session(): string
|
|
64
97
|
static get isInitialized(): boolean
|
|
65
98
|
static forms: any
|
|
66
|
-
static business:
|
|
99
|
+
static business: HellotextBusiness
|
|
67
100
|
static webchat: any
|
|
68
101
|
}
|
|
69
102
|
|
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _stimulus = require("@hotwired/stimulus");
|
|
8
|
+
var _hellotext = _interopRequireDefault(require("../hellotext"));
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
8
10
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
9
11
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
10
12
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
@@ -58,6 +60,23 @@ let _default = /*#__PURE__*/function (_Controller) {
|
|
|
58
60
|
}
|
|
59
61
|
});
|
|
60
62
|
}
|
|
63
|
+
}, {
|
|
64
|
+
key: "addToCart",
|
|
65
|
+
value: function addToCart({
|
|
66
|
+
currentTarget
|
|
67
|
+
}) {
|
|
68
|
+
const card = currentTarget.closest('[data-hellotext--message-target="carouselCard"]');
|
|
69
|
+
const payload = {
|
|
70
|
+
object_parameters: {
|
|
71
|
+
items: [{
|
|
72
|
+
product: card.dataset.id,
|
|
73
|
+
quantity: 1
|
|
74
|
+
}]
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
_hellotext.default.track('cart.added', payload);
|
|
78
|
+
_hellotext.default.eventEmitter.dispatch('cart.added', payload);
|
|
79
|
+
}
|
|
61
80
|
}, {
|
|
62
81
|
key: "moveToLeft",
|
|
63
82
|
value: function moveToLeft() {
|
|
@@ -11,6 +11,7 @@ function _assertThisInitialized(self) { if (self === void 0) { throw new Referen
|
|
|
11
11
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
12
12
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
13
13
|
import { Controller } from '@hotwired/stimulus';
|
|
14
|
+
import Hellotext from '../hellotext';
|
|
14
15
|
var _default = /*#__PURE__*/function (_Controller) {
|
|
15
16
|
_inherits(_default, _Controller);
|
|
16
17
|
var _super = _createSuper(_default);
|
|
@@ -54,6 +55,24 @@ var _default = /*#__PURE__*/function (_Controller) {
|
|
|
54
55
|
}
|
|
55
56
|
});
|
|
56
57
|
}
|
|
58
|
+
}, {
|
|
59
|
+
key: "addToCart",
|
|
60
|
+
value: function addToCart(_ref3) {
|
|
61
|
+
var {
|
|
62
|
+
currentTarget
|
|
63
|
+
} = _ref3;
|
|
64
|
+
var card = currentTarget.closest('[data-hellotext--message-target="carouselCard"]');
|
|
65
|
+
var payload = {
|
|
66
|
+
object_parameters: {
|
|
67
|
+
items: [{
|
|
68
|
+
product: card.dataset.id,
|
|
69
|
+
quantity: 1
|
|
70
|
+
}]
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
Hellotext.track('cart.added', payload);
|
|
74
|
+
Hellotext.eventEmitter.dispatch('cart.added', payload);
|
|
75
|
+
}
|
|
57
76
|
}, {
|
|
58
77
|
key: "moveToLeft",
|
|
59
78
|
value: function moveToLeft() {
|
package/lib/core/event.cjs
CHANGED
|
@@ -68,4 +68,4 @@ let Event = /*#__PURE__*/function () {
|
|
|
68
68
|
return Event;
|
|
69
69
|
}();
|
|
70
70
|
exports.default = Event;
|
|
71
|
-
Event.events = ['session-set', 'utm-set', 'forms:collected', 'form:completed', 'webchat:mounted', 'webchat:opened', 'webchat:closed', 'webchat:message:sent', 'webchat:message:received'];
|
|
71
|
+
Event.events = ['session-set', 'utm-set', 'forms:collected', 'form:completed', 'webchat:mounted', 'webchat:opened', 'webchat:closed', 'webchat:message:sent', 'webchat:message:received', 'cart.added'];
|
package/lib/core/event.js
CHANGED
|
@@ -63,5 +63,5 @@ var Event = /*#__PURE__*/function () {
|
|
|
63
63
|
}]);
|
|
64
64
|
return Event;
|
|
65
65
|
}();
|
|
66
|
-
Event.events = ['session-set', 'utm-set', 'forms:collected', 'form:completed', 'webchat:mounted', 'webchat:opened', 'webchat:closed', 'webchat:message:sent', 'webchat:message:received'];
|
|
66
|
+
Event.events = ['session-set', 'utm-set', 'forms:collected', 'form:completed', 'webchat:mounted', 'webchat:opened', 'webchat:closed', 'webchat:message:sent', 'webchat:message:received', 'cart.added'];
|
|
67
67
|
export { Event as default };
|
package/lib/hellotext.cjs
CHANGED
|
@@ -27,15 +27,21 @@ let Hellotext = /*#__PURE__*/function () {
|
|
|
27
27
|
* @param business public business id
|
|
28
28
|
* @param { Configuration } config
|
|
29
29
|
*/
|
|
30
|
-
async function initialize(business, config) {
|
|
30
|
+
async function initialize(business, config = {}) {
|
|
31
31
|
this.business = new _models.Business(business);
|
|
32
32
|
_core.Configuration.assign(config);
|
|
33
33
|
_models.Session.initialize();
|
|
34
34
|
this.page = new _models.Page();
|
|
35
35
|
this.forms = new _models.FormCollection();
|
|
36
36
|
this.query = new _models.Query();
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
const businessData = await this.business.hydrate();
|
|
38
|
+
const webchatConfig = config.webchat === false ? false : {
|
|
39
|
+
...(businessData && businessData.webchat || {}),
|
|
40
|
+
...(config.webchat || {})
|
|
41
|
+
};
|
|
42
|
+
if (webchatConfig && webchatConfig.id) {
|
|
43
|
+
_core.Configuration.webchat.assign(webchatConfig);
|
|
44
|
+
this.webchat = await _models.Webchat.load(webchatConfig.id);
|
|
39
45
|
}
|
|
40
46
|
if (typeof MutationObserver !== 'undefined') {
|
|
41
47
|
this.forms.collectExistingFormsOnPage();
|
package/lib/hellotext.js
CHANGED
|
@@ -25,21 +25,25 @@ var Hellotext = /*#__PURE__*/function () {
|
|
|
25
25
|
* @param { Configuration } config
|
|
26
26
|
*/
|
|
27
27
|
function () {
|
|
28
|
-
var _initialize = _asyncToGenerator(function* (business
|
|
28
|
+
var _initialize = _asyncToGenerator(function* (business) {
|
|
29
|
+
var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
29
30
|
this.business = new Business(business);
|
|
30
31
|
Configuration.assign(config);
|
|
31
32
|
Session.initialize();
|
|
32
33
|
this.page = new Page();
|
|
33
34
|
this.forms = new FormCollection();
|
|
34
35
|
this.query = new Query();
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
var businessData = yield this.business.hydrate();
|
|
37
|
+
var webchatConfig = config.webchat === false ? false : _objectSpread(_objectSpread({}, businessData && businessData.webchat || {}), config.webchat || {});
|
|
38
|
+
if (webchatConfig && webchatConfig.id) {
|
|
39
|
+
Configuration.webchat.assign(webchatConfig);
|
|
40
|
+
this.webchat = yield Webchat.load(webchatConfig.id);
|
|
37
41
|
}
|
|
38
42
|
if (typeof MutationObserver !== 'undefined') {
|
|
39
43
|
this.forms.collectExistingFormsOnPage();
|
|
40
44
|
}
|
|
41
45
|
});
|
|
42
|
-
function initialize(_x
|
|
46
|
+
function initialize(_x) {
|
|
43
47
|
return _initialize.apply(this, arguments);
|
|
44
48
|
}
|
|
45
49
|
return initialize;
|
|
@@ -73,7 +77,7 @@ var Hellotext = /*#__PURE__*/function () {
|
|
|
73
77
|
body
|
|
74
78
|
});
|
|
75
79
|
});
|
|
76
|
-
function track(
|
|
80
|
+
function track(_x2) {
|
|
77
81
|
return _track.apply(this, arguments);
|
|
78
82
|
}
|
|
79
83
|
return track;
|
|
@@ -121,7 +125,7 @@ var Hellotext = /*#__PURE__*/function () {
|
|
|
121
125
|
}
|
|
122
126
|
return response;
|
|
123
127
|
});
|
|
124
|
-
function identify(
|
|
128
|
+
function identify(_x3) {
|
|
125
129
|
return _identify.apply(this, arguments);
|
|
126
130
|
}
|
|
127
131
|
return identify;
|
package/lib/models/business.cjs
CHANGED
|
@@ -5,19 +5,83 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.Business = void 0;
|
|
7
7
|
var _locales = _interopRequireDefault(require("../locales"));
|
|
8
|
+
var _businesses = _interopRequireDefault(require("../api/businesses"));
|
|
8
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
10
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
10
11
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
11
12
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
12
13
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
13
14
|
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
15
|
+
/**
|
|
16
|
+
* @typedef {Object} BusinessCountry
|
|
17
|
+
* @property {String} [code] - ISO country code configured for the business.
|
|
18
|
+
* @property {String} [prefix] - Phone country prefix configured for the business.
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* @typedef {Object} BusinessWebchat
|
|
22
|
+
* @property {String} [id] - Dashboard webchat id configured for the business.
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* Public business metadata returned by `public/businesses/:id`.
|
|
26
|
+
*
|
|
27
|
+
* @typedef {Object} BusinessData
|
|
28
|
+
* @property {String} [id] - Public business id.
|
|
29
|
+
* @property {BusinessCountry|String} [country] - Business country metadata.
|
|
30
|
+
* @property {Object} [features] - Feature flags enabled for the business.
|
|
31
|
+
* @property {String} [locale] - Default dashboard locale for the business.
|
|
32
|
+
* @property {String} [style_url] - Stylesheet URL to inject for dashboard-managed surfaces.
|
|
33
|
+
* @property {BusinessWebchat|null} [webchat] - Dashboard webchat defaults.
|
|
34
|
+
* @property {String|Array<String>} [whitelist] - Domain whitelist configuration.
|
|
35
|
+
* @property {String} [subscription] - Current business subscription tier.
|
|
36
|
+
*/
|
|
37
|
+
/**
|
|
38
|
+
* Public business context used by the SDK for tracking, forms, and webchat defaults.
|
|
39
|
+
*/
|
|
14
40
|
let Business = /*#__PURE__*/function () {
|
|
41
|
+
/**
|
|
42
|
+
* @param {String} id - Public business id.
|
|
43
|
+
*/
|
|
15
44
|
function Business(id) {
|
|
16
45
|
_classCallCheck(this, Business);
|
|
17
46
|
this.id = id;
|
|
18
47
|
this.data = null;
|
|
19
48
|
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Hydrates business metadata from the public business endpoint.
|
|
52
|
+
*
|
|
53
|
+
* Fetch failures return `null` so tracking initialization can continue even
|
|
54
|
+
* when dashboard-driven webchat defaults are unavailable.
|
|
55
|
+
*
|
|
56
|
+
* @returns {Promise<BusinessData|null>}
|
|
57
|
+
*/
|
|
20
58
|
_createClass(Business, [{
|
|
59
|
+
key: "hydrate",
|
|
60
|
+
value: async function hydrate() {
|
|
61
|
+
try {
|
|
62
|
+
const response = await _businesses.default.get(this.id);
|
|
63
|
+
if (response.ok === false) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
const business = await response.json();
|
|
67
|
+
if (!business) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
this.setData(business);
|
|
71
|
+
if (business.locale) {
|
|
72
|
+
this.setLocale(business.locale);
|
|
73
|
+
}
|
|
74
|
+
return business;
|
|
75
|
+
} catch (_error) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* @param {BusinessData} data
|
|
82
|
+
* @returns {void}
|
|
83
|
+
*/
|
|
84
|
+
}, {
|
|
21
85
|
key: "setData",
|
|
22
86
|
value: function setData(data) {
|
|
23
87
|
this.data = data;
|
|
@@ -43,6 +107,11 @@ let Business = /*#__PURE__*/function () {
|
|
|
43
107
|
get: function () {
|
|
44
108
|
return this.data.whitelist !== 'disabled';
|
|
45
109
|
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* @param {String} locale
|
|
113
|
+
* @returns {void}
|
|
114
|
+
*/
|
|
46
115
|
}, {
|
|
47
116
|
key: "setLocale",
|
|
48
117
|
value: function setLocale(locale) {
|
package/lib/models/business.js
CHANGED
|
@@ -1,16 +1,91 @@
|
|
|
1
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
2
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
1
3
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
2
4
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
3
5
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
4
6
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
5
7
|
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
6
8
|
import locales from '../locales';
|
|
9
|
+
import BusinessesAPI from '../api/businesses';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @typedef {Object} BusinessCountry
|
|
13
|
+
* @property {String} [code] - ISO country code configured for the business.
|
|
14
|
+
* @property {String} [prefix] - Phone country prefix configured for the business.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @typedef {Object} BusinessWebchat
|
|
19
|
+
* @property {String} [id] - Dashboard webchat id configured for the business.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Public business metadata returned by `public/businesses/:id`.
|
|
24
|
+
*
|
|
25
|
+
* @typedef {Object} BusinessData
|
|
26
|
+
* @property {String} [id] - Public business id.
|
|
27
|
+
* @property {BusinessCountry|String} [country] - Business country metadata.
|
|
28
|
+
* @property {Object} [features] - Feature flags enabled for the business.
|
|
29
|
+
* @property {String} [locale] - Default dashboard locale for the business.
|
|
30
|
+
* @property {String} [style_url] - Stylesheet URL to inject for dashboard-managed surfaces.
|
|
31
|
+
* @property {BusinessWebchat|null} [webchat] - Dashboard webchat defaults.
|
|
32
|
+
* @property {String|Array<String>} [whitelist] - Domain whitelist configuration.
|
|
33
|
+
* @property {String} [subscription] - Current business subscription tier.
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Public business context used by the SDK for tracking, forms, and webchat defaults.
|
|
38
|
+
*/
|
|
7
39
|
var Business = /*#__PURE__*/function () {
|
|
40
|
+
/**
|
|
41
|
+
* @param {String} id - Public business id.
|
|
42
|
+
*/
|
|
8
43
|
function Business(id) {
|
|
9
44
|
_classCallCheck(this, Business);
|
|
10
45
|
this.id = id;
|
|
11
46
|
this.data = null;
|
|
12
47
|
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Hydrates business metadata from the public business endpoint.
|
|
51
|
+
*
|
|
52
|
+
* Fetch failures return `null` so tracking initialization can continue even
|
|
53
|
+
* when dashboard-driven webchat defaults are unavailable.
|
|
54
|
+
*
|
|
55
|
+
* @returns {Promise<BusinessData|null>}
|
|
56
|
+
*/
|
|
13
57
|
_createClass(Business, [{
|
|
58
|
+
key: "hydrate",
|
|
59
|
+
value: function () {
|
|
60
|
+
var _hydrate = _asyncToGenerator(function* () {
|
|
61
|
+
try {
|
|
62
|
+
var response = yield BusinessesAPI.get(this.id);
|
|
63
|
+
if (response.ok === false) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
var business = yield response.json();
|
|
67
|
+
if (!business) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
this.setData(business);
|
|
71
|
+
if (business.locale) {
|
|
72
|
+
this.setLocale(business.locale);
|
|
73
|
+
}
|
|
74
|
+
return business;
|
|
75
|
+
} catch (_error) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
function hydrate() {
|
|
80
|
+
return _hydrate.apply(this, arguments);
|
|
81
|
+
}
|
|
82
|
+
return hydrate;
|
|
83
|
+
}()
|
|
84
|
+
/**
|
|
85
|
+
* @param {BusinessData} data
|
|
86
|
+
* @returns {void}
|
|
87
|
+
*/
|
|
88
|
+
}, {
|
|
14
89
|
key: "setData",
|
|
15
90
|
value: function setData(data) {
|
|
16
91
|
this.data = data;
|
|
@@ -36,6 +111,11 @@ var Business = /*#__PURE__*/function () {
|
|
|
36
111
|
get: function get() {
|
|
37
112
|
return this.data.whitelist !== 'disabled';
|
|
38
113
|
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* @param {String} locale
|
|
117
|
+
* @returns {void}
|
|
118
|
+
*/
|
|
39
119
|
}, {
|
|
40
120
|
key: "setLocale",
|
|
41
121
|
value: function setLocale(locale) {
|
package/package.json
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Controller } from '@hotwired/stimulus'
|
|
2
2
|
|
|
3
|
+
import Hellotext from '../hellotext'
|
|
4
|
+
|
|
3
5
|
export default class extends Controller {
|
|
4
6
|
static values = {
|
|
5
7
|
id: String,
|
|
@@ -34,6 +36,24 @@ export default class extends Controller {
|
|
|
34
36
|
})
|
|
35
37
|
}
|
|
36
38
|
|
|
39
|
+
addToCart({ currentTarget }) {
|
|
40
|
+
const card = currentTarget.closest('[data-hellotext--message-target="carouselCard"]')
|
|
41
|
+
|
|
42
|
+
const payload = {
|
|
43
|
+
object_parameters: {
|
|
44
|
+
items: [
|
|
45
|
+
{
|
|
46
|
+
product: card.dataset.id,
|
|
47
|
+
quantity: 1,
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
},
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
Hellotext.track('cart.added', payload)
|
|
54
|
+
Hellotext.eventEmitter.dispatch('cart.added', payload)
|
|
55
|
+
}
|
|
56
|
+
|
|
37
57
|
moveToLeft() {
|
|
38
58
|
if (!this.hasCarouselContainerTarget) return
|
|
39
59
|
|
package/src/core/event.js
CHANGED
package/src/hellotext.js
CHANGED
|
@@ -16,7 +16,7 @@ class Hellotext {
|
|
|
16
16
|
* @param business public business id
|
|
17
17
|
* @param { Configuration } config
|
|
18
18
|
*/
|
|
19
|
-
static async initialize(business, config) {
|
|
19
|
+
static async initialize(business, config = {}) {
|
|
20
20
|
this.business = new Business(business)
|
|
21
21
|
|
|
22
22
|
Configuration.assign(config)
|
|
@@ -27,8 +27,15 @@ class Hellotext {
|
|
|
27
27
|
|
|
28
28
|
this.query = new Query()
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
const businessData = await this.business.hydrate()
|
|
31
|
+
const webchatConfig = config.webchat === false ? false : {
|
|
32
|
+
...((businessData && businessData.webchat) || {}),
|
|
33
|
+
...(config.webchat || {}),
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (webchatConfig && webchatConfig.id) {
|
|
37
|
+
Configuration.webchat.assign(webchatConfig)
|
|
38
|
+
this.webchat = await Webchat.load(webchatConfig.id)
|
|
32
39
|
}
|
|
33
40
|
|
|
34
41
|
if (typeof MutationObserver !== 'undefined') {
|
package/src/models/business.js
CHANGED
|
@@ -1,11 +1,81 @@
|
|
|
1
1
|
import locales from '../locales'
|
|
2
|
+
import BusinessesAPI from '../api/businesses'
|
|
2
3
|
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {Object} BusinessCountry
|
|
6
|
+
* @property {String} [code] - ISO country code configured for the business.
|
|
7
|
+
* @property {String} [prefix] - Phone country prefix configured for the business.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @typedef {Object} BusinessWebchat
|
|
12
|
+
* @property {String} [id] - Dashboard webchat id configured for the business.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Public business metadata returned by `public/businesses/:id`.
|
|
17
|
+
*
|
|
18
|
+
* @typedef {Object} BusinessData
|
|
19
|
+
* @property {String} [id] - Public business id.
|
|
20
|
+
* @property {BusinessCountry|String} [country] - Business country metadata.
|
|
21
|
+
* @property {Object} [features] - Feature flags enabled for the business.
|
|
22
|
+
* @property {String} [locale] - Default dashboard locale for the business.
|
|
23
|
+
* @property {String} [style_url] - Stylesheet URL to inject for dashboard-managed surfaces.
|
|
24
|
+
* @property {BusinessWebchat|null} [webchat] - Dashboard webchat defaults.
|
|
25
|
+
* @property {String|Array<String>} [whitelist] - Domain whitelist configuration.
|
|
26
|
+
* @property {String} [subscription] - Current business subscription tier.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Public business context used by the SDK for tracking, forms, and webchat defaults.
|
|
31
|
+
*/
|
|
3
32
|
class Business {
|
|
33
|
+
/**
|
|
34
|
+
* @param {String} id - Public business id.
|
|
35
|
+
*/
|
|
4
36
|
constructor(id) {
|
|
5
37
|
this.id = id
|
|
6
38
|
this.data = null
|
|
7
39
|
}
|
|
8
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Hydrates business metadata from the public business endpoint.
|
|
43
|
+
*
|
|
44
|
+
* Fetch failures return `null` so tracking initialization can continue even
|
|
45
|
+
* when dashboard-driven webchat defaults are unavailable.
|
|
46
|
+
*
|
|
47
|
+
* @returns {Promise<BusinessData|null>}
|
|
48
|
+
*/
|
|
49
|
+
async hydrate() {
|
|
50
|
+
try {
|
|
51
|
+
const response = await BusinessesAPI.get(this.id)
|
|
52
|
+
|
|
53
|
+
if (response.ok === false) {
|
|
54
|
+
return null
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const business = await response.json()
|
|
58
|
+
|
|
59
|
+
if (!business) {
|
|
60
|
+
return null
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
this.setData(business)
|
|
64
|
+
|
|
65
|
+
if (business.locale) {
|
|
66
|
+
this.setLocale(business.locale)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return business
|
|
70
|
+
} catch (_error) {
|
|
71
|
+
return null
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @param {BusinessData} data
|
|
77
|
+
* @returns {void}
|
|
78
|
+
*/
|
|
9
79
|
setData(data) {
|
|
10
80
|
this.data = data
|
|
11
81
|
|
|
@@ -30,6 +100,10 @@ class Business {
|
|
|
30
100
|
return this.data.whitelist !== 'disabled'
|
|
31
101
|
}
|
|
32
102
|
|
|
103
|
+
/**
|
|
104
|
+
* @param {String} locale
|
|
105
|
+
* @returns {void}
|
|
106
|
+
*/
|
|
33
107
|
setLocale(locale) {
|
|
34
108
|
if (!locales[locale]) {
|
|
35
109
|
return console.warn(`Locale ${locale} not found`)
|