@hellotext/hellotext 2.5.7 → 2.5.8
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 +0 -25
- package/dist/hellotext.js +1 -1
- package/index.d.ts +0 -6
- package/lib/api/acks.cjs +17 -31
- package/lib/api/acks.js +17 -42
- package/lib/api/businesses.cjs +14 -28
- package/lib/api/businesses.js +13 -36
- package/lib/api/events.cjs +26 -40
- package/lib/api/events.js +28 -52
- package/lib/api/forms.cjs +24 -40
- package/lib/api/forms.js +24 -57
- package/lib/api/identifications.cjs +15 -29
- package/lib/api/identifications.js +15 -40
- package/lib/api/index.cjs +25 -51
- package/lib/api/index.js +27 -54
- package/lib/api/push/identities.cjs +30 -46
- package/lib/api/push/identities.js +30 -63
- package/lib/api/response.cjs +30 -52
- package/lib/api/response.js +31 -60
- package/lib/api/submissions.cjs +18 -34
- package/lib/api/submissions.js +18 -48
- package/lib/api/webchat/messages.cjs +44 -64
- package/lib/api/webchat/messages.js +44 -80
- package/lib/api/webchats.cjs +37 -56
- package/lib/api/webchats.js +37 -65
- package/lib/api/whatsapp_widgets.cjs +49 -72
- package/lib/api/whatsapp_widgets.js +48 -91
- package/lib/builders/input_builder.cjs +36 -48
- package/lib/builders/input_builder.js +36 -48
- package/lib/builders/logo_builder.cjs +10 -29
- package/lib/builders/logo_builder.js +20 -28
- package/lib/channels/application_channel.cjs +136 -178
- package/lib/channels/application_channel.js +137 -180
- package/lib/channels/webchat_channel.cjs +125 -170
- package/lib/channels/webchat_channel.js +125 -170
- package/lib/controllers/form_controller.cjs +82 -121
- package/lib/controllers/form_controller.js +82 -130
- package/lib/controllers/message_controller.cjs +211 -282
- package/lib/controllers/message_controller.js +209 -284
- package/lib/controllers/mixins/usePopover.cjs +3 -6
- package/lib/controllers/mixins/usePopover.js +17 -22
- package/lib/controllers/webchat/emoji_picker_controller.cjs +106 -150
- package/lib/controllers/webchat/emoji_picker_controller.js +105 -170
- package/lib/controllers/webchat/useBehaviour.js +5 -5
- package/lib/controllers/webchat/useOpeningSequence.js +6 -6
- package/lib/controllers/webchat/useTeaser.js +9 -9
- package/lib/controllers/webchat_controller.cjs +916 -1088
- package/lib/controllers/webchat_controller.js +926 -1152
- package/lib/core/configuration/forms.cjs +21 -35
- package/lib/core/configuration/forms.js +20 -35
- package/lib/core/configuration/locale.cjs +36 -71
- package/lib/core/configuration/locale.js +36 -70
- package/lib/core/configuration/push.cjs +9 -21
- package/lib/core/configuration/push.js +8 -20
- package/lib/core/configuration/webchat.cjs +142 -182
- package/lib/core/configuration/webchat.js +145 -189
- package/lib/core/configuration/whatsapp.cjs +76 -102
- package/lib/core/configuration/whatsapp.js +76 -105
- package/lib/core/configuration.cjs +60 -78
- package/lib/core/configuration.js +59 -78
- package/lib/core/event.cjs +36 -59
- package/lib/core/event.js +35 -61
- package/lib/core/sanitize_html.js +4 -4
- package/lib/errors/invalid_event.cjs +5 -26
- package/lib/errors/invalid_event.js +5 -26
- package/lib/errors/not_initialized_error.cjs +5 -26
- package/lib/errors/not_initialized_error.js +5 -26
- package/lib/hellotext.cjs +185 -223
- package/lib/hellotext.js +188 -247
- package/lib/index.js +1 -1
- package/lib/models/business.cjs +114 -152
- package/lib/models/business.js +117 -162
- package/lib/models/cookies.cjs +34 -51
- package/lib/models/cookies.js +34 -51
- package/lib/models/fingerprint.cjs +8 -23
- package/lib/models/fingerprint.js +25 -58
- package/lib/models/form.cjs +106 -142
- package/lib/models/form.js +105 -153
- package/lib/models/form_collection.cjs +63 -101
- package/lib/models/form_collection.js +61 -107
- package/lib/models/page.cjs +106 -129
- package/lib/models/page.js +106 -131
- package/lib/models/push.cjs +278 -322
- package/lib/models/push.js +284 -357
- package/lib/models/query.cjs +21 -41
- package/lib/models/query.js +21 -41
- package/lib/models/session.cjs +33 -65
- package/lib/models/session.js +30 -63
- package/lib/models/user.cjs +29 -51
- package/lib/models/user.js +29 -51
- package/lib/models/utm.cjs +15 -27
- package/lib/models/utm.js +17 -32
- package/lib/models/webchat.cjs +52 -76
- package/lib/models/webchat.js +52 -90
- package/lib/models/whatsapp_widget.cjs +41 -59
- package/lib/models/whatsapp_widget.js +41 -73
- package/lib/vanilla.cjs +4 -7
- package/lib/vanilla.js +2 -1
- package/package.json +1 -9
- package/src/index.bundle.js +0 -1
- package/src/vanilla.js +2 -1
- package/styles/index.css +0 -30
package/lib/models/page.cjs
CHANGED
|
@@ -5,14 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.Page = void 0;
|
|
7
7
|
var _utm = require("./utm");
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
11
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
12
|
-
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); }
|
|
13
|
-
let Page = /*#__PURE__*/function () {
|
|
14
|
-
function Page(url = null) {
|
|
15
|
-
_classCallCheck(this, Page);
|
|
8
|
+
class Page {
|
|
9
|
+
constructor(url = null) {
|
|
16
10
|
this.utm = new _utm.UTM();
|
|
17
11
|
this._url = url;
|
|
18
12
|
}
|
|
@@ -21,144 +15,127 @@ let Page = /*#__PURE__*/function () {
|
|
|
21
15
|
* Get the current page URL
|
|
22
16
|
* @returns {string} The page URL
|
|
23
17
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return this._url !== null && this._url !== undefined ? this._url : window.location.href;
|
|
28
|
-
}
|
|
18
|
+
get url() {
|
|
19
|
+
return this._url !== null && this._url !== undefined ? this._url : window.location.href;
|
|
20
|
+
}
|
|
29
21
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return document.title;
|
|
38
|
-
}
|
|
22
|
+
/**
|
|
23
|
+
* Get the current page title
|
|
24
|
+
* @returns {string} The page title
|
|
25
|
+
*/
|
|
26
|
+
get title() {
|
|
27
|
+
return document.title;
|
|
28
|
+
}
|
|
39
29
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
} catch (e) {
|
|
51
|
-
return '/';
|
|
52
|
-
}
|
|
30
|
+
/**
|
|
31
|
+
* Get the current page path
|
|
32
|
+
* @returns {string} The page path
|
|
33
|
+
*/
|
|
34
|
+
get path() {
|
|
35
|
+
if (this._url) {
|
|
36
|
+
try {
|
|
37
|
+
return new URL(this._url).pathname;
|
|
38
|
+
} catch (e) {
|
|
39
|
+
return '/';
|
|
53
40
|
}
|
|
54
|
-
return window.location.pathname;
|
|
55
41
|
}
|
|
42
|
+
return window.location.pathname;
|
|
43
|
+
}
|
|
56
44
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return this.utm.current;
|
|
65
|
-
}
|
|
45
|
+
/**
|
|
46
|
+
* Get current UTM parameters
|
|
47
|
+
* @returns {Object} The UTM parameters
|
|
48
|
+
*/
|
|
49
|
+
get utmParams() {
|
|
50
|
+
return this.utm.current;
|
|
51
|
+
}
|
|
66
52
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
};
|
|
82
|
-
}
|
|
53
|
+
/**
|
|
54
|
+
* Get page data for tracking
|
|
55
|
+
* @returns {Object} Object containing page object and utm_params
|
|
56
|
+
*/
|
|
57
|
+
get trackingData() {
|
|
58
|
+
return {
|
|
59
|
+
page: {
|
|
60
|
+
url: this.url,
|
|
61
|
+
title: this.title,
|
|
62
|
+
path: this.path
|
|
63
|
+
},
|
|
64
|
+
utm_params: this.utmParams
|
|
65
|
+
};
|
|
66
|
+
}
|
|
83
67
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
const url = this.url;
|
|
93
|
-
if (!url) {
|
|
94
|
-
return null;
|
|
95
|
-
}
|
|
96
|
-
const hostname = new URL(url).hostname;
|
|
97
|
-
return Page.getRootDomain(hostname);
|
|
98
|
-
} catch (e) {
|
|
68
|
+
/**
|
|
69
|
+
* Get the current page domain (root domain for cookie sharing)
|
|
70
|
+
* @returns {string} The root domain with leading dot, or null if no valid URL
|
|
71
|
+
*/
|
|
72
|
+
get domain() {
|
|
73
|
+
try {
|
|
74
|
+
const url = this.url;
|
|
75
|
+
if (!url) {
|
|
99
76
|
return null;
|
|
100
77
|
}
|
|
78
|
+
const hostname = new URL(url).hostname;
|
|
79
|
+
return Page.getRootDomain(hostname);
|
|
80
|
+
} catch (e) {
|
|
81
|
+
return null;
|
|
101
82
|
}
|
|
83
|
+
}
|
|
102
84
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
var _window$location;
|
|
114
|
-
if (typeof window === 'undefined' || !((_window$location = window.location) !== null && _window$location !== void 0 && _window$location.hostname)) {
|
|
115
|
-
return null;
|
|
116
|
-
}
|
|
117
|
-
hostname = window.location.hostname;
|
|
118
|
-
}
|
|
119
|
-
const parts = hostname.split('.');
|
|
120
|
-
|
|
121
|
-
// Handle localhost or single-part domains
|
|
122
|
-
if (parts.length <= 1) {
|
|
123
|
-
return hostname;
|
|
85
|
+
/**
|
|
86
|
+
* Get the root domain from a hostname (static method, no instance needed)
|
|
87
|
+
* @param {string} hostname - The hostname to parse
|
|
88
|
+
* @returns {string} The root domain with leading dot, or null if invalid
|
|
89
|
+
*/
|
|
90
|
+
static getRootDomain(hostname = null) {
|
|
91
|
+
try {
|
|
92
|
+
if (!hostname) {
|
|
93
|
+
if (typeof window === 'undefined' || !window.location?.hostname) {
|
|
94
|
+
return null;
|
|
124
95
|
}
|
|
96
|
+
hostname = window.location.hostname;
|
|
97
|
+
}
|
|
98
|
+
const parts = hostname.split('.');
|
|
125
99
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
// storename.wixsite.com -> .storename.wixsite.com
|
|
131
|
-
const platformSuffixes = ['myshopify.com', 'vtexcommercestable.com.br', 'myvtex.com', 'wixsite.com'];
|
|
132
|
-
for (const suffix of platformSuffixes) {
|
|
133
|
-
const suffixParts = suffix.split('.');
|
|
134
|
-
// Get the last N parts of the hostname (e.g., last 2 parts for 'myshopify.com')
|
|
135
|
-
const domainTail = parts.slice(-suffixParts.length).join('.');
|
|
100
|
+
// Handle localhost or single-part domains
|
|
101
|
+
if (parts.length <= 1) {
|
|
102
|
+
return hostname;
|
|
103
|
+
}
|
|
136
104
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
105
|
+
// Handle e-commerce platform domains where store identifier must be preserved
|
|
106
|
+
// Examples:
|
|
107
|
+
// storename.myshopify.com -> .storename.myshopify.com
|
|
108
|
+
// storename.vtexcommercestable.com.br -> .storename.vtexcommercestable.com.br
|
|
109
|
+
// storename.wixsite.com -> .storename.wixsite.com
|
|
110
|
+
const platformSuffixes = ['myshopify.com', 'vtexcommercestable.com.br', 'myvtex.com', 'wixsite.com'];
|
|
111
|
+
for (const suffix of platformSuffixes) {
|
|
112
|
+
const suffixParts = suffix.split('.');
|
|
113
|
+
// Get the last N parts of the hostname (e.g., last 2 parts for 'myshopify.com')
|
|
114
|
+
const domainTail = parts.slice(-suffixParts.length).join('.');
|
|
145
115
|
|
|
146
|
-
//
|
|
147
|
-
//
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
return `.${parts.slice(-3).join('.')}`;
|
|
116
|
+
// Check if the tail exactly matches the platform suffix
|
|
117
|
+
// and there are additional parts for the store identifier
|
|
118
|
+
if (domainTail === suffix && parts.length > suffixParts.length) {
|
|
119
|
+
// Include store identifier + platform suffix
|
|
120
|
+
// e.g., ['secure', 'mystore', 'myshopify', 'com'] -> '.mystore.myshopify.com'
|
|
121
|
+
return `.${parts.slice(-(suffixParts.length + 1)).join('.')}`;
|
|
153
122
|
}
|
|
123
|
+
}
|
|
154
124
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
125
|
+
// Simple heuristic: if TLD is 2 chars and second-level is short (<=3 chars),
|
|
126
|
+
// it's likely a multi-part TLD like .com.br, .co.uk
|
|
127
|
+
const tld = parts[parts.length - 1];
|
|
128
|
+
const secondLevel = parts[parts.length - 2];
|
|
129
|
+
if (parts.length > 2 && tld.length === 2 && secondLevel.length <= 3) {
|
|
130
|
+
// Multi-part TLD: take last 3 parts (e.g., store.com.br)
|
|
131
|
+
return `.${parts.slice(-3).join('.')}`;
|
|
159
132
|
}
|
|
133
|
+
|
|
134
|
+
// Regular TLD: take last 2 parts (e.g., example.com)
|
|
135
|
+
return `.${parts.slice(-2).join('.')}`;
|
|
136
|
+
} catch (e) {
|
|
137
|
+
return null;
|
|
160
138
|
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
}();
|
|
139
|
+
}
|
|
140
|
+
}
|
|
164
141
|
exports.Page = Page;
|
package/lib/models/page.js
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
2
|
-
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
|
-
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
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
5
|
-
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
1
|
import { UTM } from './utm';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
10
|
-
_classCallCheck(this, Page);
|
|
2
|
+
class Page {
|
|
3
|
+
constructor(url = null) {
|
|
11
4
|
this.utm = new UTM();
|
|
12
5
|
this._url = url;
|
|
13
6
|
}
|
|
@@ -16,145 +9,127 @@ var Page = /*#__PURE__*/function () {
|
|
|
16
9
|
* Get the current page URL
|
|
17
10
|
* @returns {string} The page URL
|
|
18
11
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return this._url !== null && this._url !== undefined ? this._url : window.location.href;
|
|
23
|
-
}
|
|
12
|
+
get url() {
|
|
13
|
+
return this._url !== null && this._url !== undefined ? this._url : window.location.href;
|
|
14
|
+
}
|
|
24
15
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return document.title;
|
|
33
|
-
}
|
|
16
|
+
/**
|
|
17
|
+
* Get the current page title
|
|
18
|
+
* @returns {string} The page title
|
|
19
|
+
*/
|
|
20
|
+
get title() {
|
|
21
|
+
return document.title;
|
|
22
|
+
}
|
|
34
23
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
} catch (e) {
|
|
46
|
-
return '/';
|
|
47
|
-
}
|
|
24
|
+
/**
|
|
25
|
+
* Get the current page path
|
|
26
|
+
* @returns {string} The page path
|
|
27
|
+
*/
|
|
28
|
+
get path() {
|
|
29
|
+
if (this._url) {
|
|
30
|
+
try {
|
|
31
|
+
return new URL(this._url).pathname;
|
|
32
|
+
} catch (e) {
|
|
33
|
+
return '/';
|
|
48
34
|
}
|
|
49
|
-
return window.location.pathname;
|
|
50
35
|
}
|
|
36
|
+
return window.location.pathname;
|
|
37
|
+
}
|
|
51
38
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return this.utm.current;
|
|
60
|
-
}
|
|
39
|
+
/**
|
|
40
|
+
* Get current UTM parameters
|
|
41
|
+
* @returns {Object} The UTM parameters
|
|
42
|
+
*/
|
|
43
|
+
get utmParams() {
|
|
44
|
+
return this.utm.current;
|
|
45
|
+
}
|
|
61
46
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
};
|
|
77
|
-
}
|
|
47
|
+
/**
|
|
48
|
+
* Get page data for tracking
|
|
49
|
+
* @returns {Object} Object containing page object and utm_params
|
|
50
|
+
*/
|
|
51
|
+
get trackingData() {
|
|
52
|
+
return {
|
|
53
|
+
page: {
|
|
54
|
+
url: this.url,
|
|
55
|
+
title: this.title,
|
|
56
|
+
path: this.path
|
|
57
|
+
},
|
|
58
|
+
utm_params: this.utmParams
|
|
59
|
+
};
|
|
60
|
+
}
|
|
78
61
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
var url = this.url;
|
|
88
|
-
if (!url) {
|
|
89
|
-
return null;
|
|
90
|
-
}
|
|
91
|
-
var hostname = new URL(url).hostname;
|
|
92
|
-
return Page.getRootDomain(hostname);
|
|
93
|
-
} catch (e) {
|
|
62
|
+
/**
|
|
63
|
+
* Get the current page domain (root domain for cookie sharing)
|
|
64
|
+
* @returns {string} The root domain with leading dot, or null if no valid URL
|
|
65
|
+
*/
|
|
66
|
+
get domain() {
|
|
67
|
+
try {
|
|
68
|
+
const url = this.url;
|
|
69
|
+
if (!url) {
|
|
94
70
|
return null;
|
|
95
71
|
}
|
|
72
|
+
const hostname = new URL(url).hostname;
|
|
73
|
+
return Page.getRootDomain(hostname);
|
|
74
|
+
} catch (e) {
|
|
75
|
+
return null;
|
|
96
76
|
}
|
|
77
|
+
}
|
|
97
78
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
if (!hostname) {
|
|
109
|
-
var _window$location;
|
|
110
|
-
if (typeof window === 'undefined' || !((_window$location = window.location) !== null && _window$location !== void 0 && _window$location.hostname)) {
|
|
111
|
-
return null;
|
|
112
|
-
}
|
|
113
|
-
hostname = window.location.hostname;
|
|
114
|
-
}
|
|
115
|
-
var parts = hostname.split('.');
|
|
116
|
-
|
|
117
|
-
// Handle localhost or single-part domains
|
|
118
|
-
if (parts.length <= 1) {
|
|
119
|
-
return hostname;
|
|
79
|
+
/**
|
|
80
|
+
* Get the root domain from a hostname (static method, no instance needed)
|
|
81
|
+
* @param {string} hostname - The hostname to parse
|
|
82
|
+
* @returns {string} The root domain with leading dot, or null if invalid
|
|
83
|
+
*/
|
|
84
|
+
static getRootDomain(hostname = null) {
|
|
85
|
+
try {
|
|
86
|
+
if (!hostname) {
|
|
87
|
+
if (typeof window === 'undefined' || !window.location?.hostname) {
|
|
88
|
+
return null;
|
|
120
89
|
}
|
|
90
|
+
hostname = window.location.hostname;
|
|
91
|
+
}
|
|
92
|
+
const parts = hostname.split('.');
|
|
121
93
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
// storename.wixsite.com -> .storename.wixsite.com
|
|
127
|
-
var platformSuffixes = ['myshopify.com', 'vtexcommercestable.com.br', 'myvtex.com', 'wixsite.com'];
|
|
128
|
-
for (var suffix of platformSuffixes) {
|
|
129
|
-
var suffixParts = suffix.split('.');
|
|
130
|
-
// Get the last N parts of the hostname (e.g., last 2 parts for 'myshopify.com')
|
|
131
|
-
var domainTail = parts.slice(-suffixParts.length).join('.');
|
|
94
|
+
// Handle localhost or single-part domains
|
|
95
|
+
if (parts.length <= 1) {
|
|
96
|
+
return hostname;
|
|
97
|
+
}
|
|
132
98
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
99
|
+
// Handle e-commerce platform domains where store identifier must be preserved
|
|
100
|
+
// Examples:
|
|
101
|
+
// storename.myshopify.com -> .storename.myshopify.com
|
|
102
|
+
// storename.vtexcommercestable.com.br -> .storename.vtexcommercestable.com.br
|
|
103
|
+
// storename.wixsite.com -> .storename.wixsite.com
|
|
104
|
+
const platformSuffixes = ['myshopify.com', 'vtexcommercestable.com.br', 'myvtex.com', 'wixsite.com'];
|
|
105
|
+
for (const suffix of platformSuffixes) {
|
|
106
|
+
const suffixParts = suffix.split('.');
|
|
107
|
+
// Get the last N parts of the hostname (e.g., last 2 parts for 'myshopify.com')
|
|
108
|
+
const domainTail = parts.slice(-suffixParts.length).join('.');
|
|
141
109
|
|
|
142
|
-
//
|
|
143
|
-
//
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
return ".".concat(parts.slice(-3).join('.'));
|
|
110
|
+
// Check if the tail exactly matches the platform suffix
|
|
111
|
+
// and there are additional parts for the store identifier
|
|
112
|
+
if (domainTail === suffix && parts.length > suffixParts.length) {
|
|
113
|
+
// Include store identifier + platform suffix
|
|
114
|
+
// e.g., ['secure', 'mystore', 'myshopify', 'com'] -> '.mystore.myshopify.com'
|
|
115
|
+
return `.${parts.slice(-(suffixParts.length + 1)).join('.')}`;
|
|
149
116
|
}
|
|
117
|
+
}
|
|
150
118
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
119
|
+
// Simple heuristic: if TLD is 2 chars and second-level is short (<=3 chars),
|
|
120
|
+
// it's likely a multi-part TLD like .com.br, .co.uk
|
|
121
|
+
const tld = parts[parts.length - 1];
|
|
122
|
+
const secondLevel = parts[parts.length - 2];
|
|
123
|
+
if (parts.length > 2 && tld.length === 2 && secondLevel.length <= 3) {
|
|
124
|
+
// Multi-part TLD: take last 3 parts (e.g., store.com.br)
|
|
125
|
+
return `.${parts.slice(-3).join('.')}`;
|
|
155
126
|
}
|
|
127
|
+
|
|
128
|
+
// Regular TLD: take last 2 parts (e.g., example.com)
|
|
129
|
+
return `.${parts.slice(-2).join('.')}`;
|
|
130
|
+
} catch (e) {
|
|
131
|
+
return null;
|
|
156
132
|
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
}();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
160
135
|
export { Page };
|