@commversion/libs 0.3.0 → 0.4.1-pre-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.
Files changed (50) hide show
  1. package/README.md +2 -0
  2. package/dist/lc-geoblocking.js +1 -0
  3. package/dist/lc-utm-params.js +1 -0
  4. package/dist/schedule-event.js +1 -6
  5. package/package.json +7 -5
  6. package/_templates/generator/help/index.ejs.t +0 -5
  7. package/_templates/generator/new/hello.ejs.t +0 -18
  8. package/_templates/generator/with-prompt/hello.ejs.t +0 -18
  9. package/_templates/generator/with-prompt/prompt.js +0 -14
  10. package/_templates/scripts/new/dev-build-scripts.ejs.t +0 -7
  11. package/_templates/scripts/new/readme.ejs.t +0 -14
  12. package/_templates/scripts/new/root-readme.ejs.t +0 -6
  13. package/_templates/scripts/new/src_index_html.ejs.t +0 -60
  14. package/_templates/scripts/new/src_main.ejs.t +0 -8
  15. package/_templates/scripts/new/src_script.ejs.t +0 -9
  16. package/_templates/scripts/new/tests_script.ejs.t +0 -9
  17. package/_templates/scripts/new/vite-config.ejs.t +0 -20
  18. package/scripts/lc-exit-intent/README.md +0 -21
  19. package/scripts/lc-exit-intent/src/exit-intent.js +0 -23
  20. package/scripts/lc-exit-intent/src/index.html +0 -52
  21. package/scripts/lc-exit-intent/src/main.js +0 -3
  22. package/scripts/lc-exit-intent/tests/exit-intent.test.js +0 -52
  23. package/scripts/lc-exit-intent/vite.config.js +0 -17
  24. package/scripts/lc-ga-tags/README.md +0 -19
  25. package/scripts/lc-ga-tags/src/append-ga-session.js +0 -11
  26. package/scripts/lc-ga-tags/src/index.html +0 -66
  27. package/scripts/lc-ga-tags/src/main.js +0 -3
  28. package/scripts/lc-ga-tags/tests/append-ga-session.test.js +0 -33
  29. package/scripts/lc-ga-tags/vite.config.js +0 -17
  30. package/scripts/lc-input-error/README.md +0 -22
  31. package/scripts/lc-input-error/src/index.html +0 -74
  32. package/scripts/lc-input-error/src/input-error.js +0 -13
  33. package/scripts/lc-input-error/src/main.js +0 -3
  34. package/scripts/lc-input-error/tests/input-error.test.js +0 -27
  35. package/scripts/lc-input-error/vite.config.js +0 -17
  36. package/scripts/lc-show-hide/README.md +0 -45
  37. package/scripts/lc-show-hide/src/index.html +0 -58
  38. package/scripts/lc-show-hide/src/main.js +0 -5
  39. package/scripts/lc-show-hide/src/predicate-functions.js +0 -11
  40. package/scripts/lc-show-hide/src/show-hide.js +0 -49
  41. package/scripts/lc-show-hide/tests/predicate-functions.test.js +0 -31
  42. package/scripts/lc-show-hide/vite.config.js +0 -17
  43. package/scripts/schedule-event/README.md +0 -58
  44. package/scripts/schedule-event/src/index.html +0 -14
  45. package/scripts/schedule-event/src/main.js +0 -13
  46. package/scripts/schedule-event/src/parse-schedule.js +0 -16
  47. package/scripts/schedule-event/src/schedule-event.js +0 -18
  48. package/scripts/schedule-event/tests/parse-schedule.test.js +0 -51
  49. package/scripts/schedule-event/tests/schedule-event.test.js +0 -23
  50. package/scripts/schedule-event/vite.config.js +0 -17
@@ -1,66 +0,0 @@
1
- <html>
2
- <body>
3
- <!-- Global site tag (gtag.js) - Google Analytics -->
4
- <script
5
- async
6
- src="https://www.googletagmanager.com/gtag/js?id=G-JWDT3GZR82"
7
- ></script>
8
- <script>
9
- window.dataLayer = window.dataLayer || [];
10
- function gtag() {
11
- dataLayer.push(arguments);
12
- }
13
- gtag("js", new Date());
14
-
15
- gtag("config", "G-JWDT3GZR82");
16
- </script>
17
- <!-- Start of LiveChat (www.livechatinc.com) code -->
18
- <script>
19
- window.__lc = window.__lc || {};
20
- window.__lc.license = 10793607;
21
- (function (n, t, c) {
22
- function i(n) {
23
- return e._h ? e._h.apply(null, n) : e._q.push(n);
24
- }
25
- var e = {
26
- _q: [],
27
- _h: null,
28
- _v: "2.0",
29
- on: function () {
30
- i(["on", c.call(arguments)]);
31
- },
32
- once: function () {
33
- i(["once", c.call(arguments)]);
34
- },
35
- off: function () {
36
- i(["off", c.call(arguments)]);
37
- },
38
- get: function () {
39
- if (!e._h)
40
- throw new Error(
41
- "[LiveChatWidget] You can't use getters before load."
42
- );
43
- return i(["get", c.call(arguments)]);
44
- },
45
- call: function () {
46
- i(["call", c.call(arguments)]);
47
- },
48
- init: function () {
49
- var n = t.createElement("script");
50
- (n.async = !0),
51
- (n.type = "text/javascript"),
52
- (n.src = "https://cdn.livechatinc.com/tracking.js"),
53
- t.head.appendChild(n);
54
- },
55
- };
56
- !n.__lc.asyncInit && e.init(),
57
- (n.LiveChatWidget = n.LiveChatWidget || e);
58
- })(window, document, [].slice);
59
- </script>
60
- <!-- End of LiveChat code -->
61
-
62
- <script async src="./main.js"></script>
63
-
64
- <h1>lets see if this works</h1>
65
- </body>
66
- </html>
@@ -1,3 +0,0 @@
1
- import { appendGaSession } from "./append-ga-session";
2
-
3
- window.LiveChatWidget.on("ready", appendGaSession);
@@ -1,33 +0,0 @@
1
- import { expect } from "@esm-bundle/chai";
2
- import { fake } from "sinon";
3
- import { appendGaSession } from "../src/append-ga-session.js";
4
-
5
- it("should not engage if no ga exists", () => {
6
- window.LiveChatWidget = {
7
- on: fake(),
8
- call: fake(),
9
- };
10
-
11
- appendGaSession();
12
-
13
- expect(window.LiveChatWidget.call.called).to.be.false;
14
- });
15
-
16
- it("should engage if ga exists", () => {
17
- window.LiveChatWidget = {
18
- on: fake(),
19
- call: fake(),
20
- };
21
-
22
- window.gaGlobal = {
23
- vid: "some-id",
24
- };
25
-
26
- appendGaSession();
27
-
28
- expect(
29
- window.LiveChatWidget.call.calledWith("update_session_variables", {
30
- ga_session: "some-id",
31
- })
32
- ).to.be.true;
33
- });
@@ -1,17 +0,0 @@
1
- import path from "path";
2
-
3
- const config = {
4
- build: {
5
- outDir: path.resolve("dist"),
6
- emptyOutDir: false,
7
- target: "es2015",
8
- lib: {
9
- entry: path.resolve(__dirname, "src/main.js"),
10
- name: "lcGaTags",
11
- fileName: () => `lc-ga-tags.js`,
12
- formats: ["iife"],
13
- },
14
- },
15
- };
16
-
17
- export default config;
@@ -1,22 +0,0 @@
1
- # LiveChat Input Error
2
-
3
- Target visitors that struggle with forms.
4
-
5
- ## Installation
6
-
7
- Use the following snippet to install the plugin to website _after_ LiveChat tags.
8
-
9
- ```html
10
- <script
11
- async
12
- src="https://cdn.jsdelivr.net/npm/@commversion/libs@version/dist/lc-input-error.js"
13
- ></script>
14
- ```
15
-
16
- ## Usage
17
-
18
- This script does not need any configuration.
19
-
20
- When an `invalid` event is emitted from an input element, chat widget will expand and an `input_error` custom variable will be assigned to the visitor.
21
-
22
- Possible values for `input_error` are `true` and `false`.
@@ -1,74 +0,0 @@
1
- <html>
2
- <body>
3
- <link
4
- rel="stylesheet"
5
- href="https://cdn.jsdelivr.net/npm/simpledotcss@1.0.5/simple.min.css"
6
- />
7
- <!-- Start of LiveChat (www.livechatinc.com) code -->
8
- <script>
9
- window.__lc = window.__lc || {};
10
- window.__lc.license = 10793607;
11
- (function (n, t, c) {
12
- function i(n) {
13
- return e._h ? e._h.apply(null, n) : e._q.push(n);
14
- }
15
- var e = {
16
- _q: [],
17
- _h: null,
18
- _v: "2.0",
19
- on: function () {
20
- i(["on", c.call(arguments)]);
21
- },
22
- once: function () {
23
- i(["once", c.call(arguments)]);
24
- },
25
- off: function () {
26
- i(["off", c.call(arguments)]);
27
- },
28
- get: function () {
29
- if (!e._h)
30
- throw new Error(
31
- "[LiveChatWidget] You can't use getters before load."
32
- );
33
- return i(["get", c.call(arguments)]);
34
- },
35
- call: function () {
36
- i(["call", c.call(arguments)]);
37
- },
38
- init: function () {
39
- var n = t.createElement("script");
40
- (n.async = !0),
41
- (n.type = "text/javascript"),
42
- (n.src = "https://cdn.livechatinc.com/tracking.js"),
43
- t.head.appendChild(n);
44
- },
45
- };
46
- !n.__lc.asyncInit && e.init(),
47
- (n.LiveChatWidget = n.LiveChatWidget || e);
48
- })(window, document, [].slice);
49
- </script>
50
- <!-- End of LiveChat code -->
51
-
52
- <script async src="./main.js" type="module"></script>
53
-
54
- <h1>Form error</h1>
55
-
56
- <form>
57
- <div>
58
- <label>
59
- Name
60
- <input type="text" name="name" required="true" />
61
- </label>
62
- </div>
63
- <div>
64
- <label>
65
- Email
66
- <input type="email" name="email" />
67
- </label>
68
- </div>
69
- <div>
70
- <button type="submit">Submit</button>
71
- </div>
72
- </form>
73
- </body>
74
- </html>
@@ -1,13 +0,0 @@
1
- export const handleInputError = () => {
2
- const { LiveChatWidget } = window;
3
-
4
- const inputs = document.querySelectorAll("input");
5
-
6
- inputs.forEach((el) => {
7
- el.addEventListener("invalid", () => {
8
- LiveChatWidget.call("update_session_variables", {
9
- input_error: "true",
10
- });
11
- });
12
- });
13
- };
@@ -1,3 +0,0 @@
1
- import { handleInputError } from "./input-error.js";
2
-
3
- window.LiveChatWidget.on("ready", handleInputError);
@@ -1,27 +0,0 @@
1
- import { expect } from "@esm-bundle/chai";
2
- import { fake } from "sinon";
3
-
4
- import { handleInputError } from "../src/input-error.js";
5
-
6
- it("should update input_error session variable", () => {
7
- window.LiveChatWidget = {
8
- call: fake(),
9
- get: fake(() => ({ status: "browsing" })),
10
- };
11
-
12
- document.open();
13
- document.write('<input type="email" required="true"/>');
14
- document.close();
15
-
16
- const event = new Event("invalid");
17
-
18
- handleInputError();
19
-
20
- document.querySelector("input").dispatchEvent(event);
21
-
22
- expect(
23
- window.LiveChatWidget.call.calledWith("update_session_variables", {
24
- input_error: "true",
25
- })
26
- ).to.be.true;
27
- });
@@ -1,17 +0,0 @@
1
- import path from "path";
2
-
3
- const config = {
4
- build: {
5
- outDir: path.resolve("dist"),
6
- emptyOutDir: false,
7
- target: "es2015",
8
- lib: {
9
- entry: path.resolve(__dirname, "src/main.js"),
10
- name: "lcInputError",
11
- fileName: () => `lc-input-error.js`,
12
- formats: ["iife"],
13
- },
14
- },
15
- };
16
-
17
- export default config;
@@ -1,45 +0,0 @@
1
- # LiveChat Show-Hide
2
-
3
- Show and hide the chat widget on certain pages.
4
-
5
- ## Installation
6
-
7
- Use the following snippet to install the plugin to website _after_ tags.
8
-
9
- ```html
10
- <script
11
- async
12
- src="https://cdn.jsdelivr.net/npm/@commversion/libs@version/dist/lc-show-hide.js"
13
- ></script>
14
- ```
15
-
16
- ## Usage
17
-
18
- The `lc-show-hide` script can be configured in two ways, depending on the requirements.
19
-
20
- One is to configure the pages the chat should be shown only:
21
-
22
- ```html
23
- <script>
24
- window.commversion = {
25
- show: "^/show$", // Chat widget will be shown ONLY to /show page
26
- };
27
- </script>
28
- ```
29
-
30
- Another would be to configure the pages chat will be explicitly hidden:
31
-
32
- ```html
33
- <script>
34
- window.commversion = {
35
- hide: "^/hide$", // Chat widget will be shown everywhere EXCEPT /hide page
36
- };
37
- </script>
38
- ```
39
-
40
- Mind that the page configuration is a regular expression. You can use (regexer)[https://regexr.com/] to try out regular expressions.
41
-
42
- Note: The chat widget will be **shown** regardless configuration when:
43
-
44
- - A visitor has an active conversation.
45
- - A visitor has been previously engaged by a greeting.
@@ -1,58 +0,0 @@
1
- <html>
2
- <body>
3
- <!-- Start of LiveChat (www.livechatinc.com) code -->
4
- <script>
5
- window.__lc = window.__lc || {};
6
- window.__lc.license = 10793607;
7
- (function (n, t, c) {
8
- function i(n) {
9
- return e._h ? e._h.apply(null, n) : e._q.push(n);
10
- }
11
- var e = {
12
- _q: [],
13
- _h: null,
14
- _v: "2.0",
15
- on: function () {
16
- i(["on", c.call(arguments)]);
17
- },
18
- once: function () {
19
- i(["once", c.call(arguments)]);
20
- },
21
- off: function () {
22
- i(["off", c.call(arguments)]);
23
- },
24
- get: function () {
25
- if (!e._h)
26
- throw new Error(
27
- "[LiveChatWidget] You can't use getters before load."
28
- );
29
- return i(["get", c.call(arguments)]);
30
- },
31
- call: function () {
32
- i(["call", c.call(arguments)]);
33
- },
34
- init: function () {
35
- var n = t.createElement("script");
36
- (n.async = !0),
37
- (n.type = "text/javascript"),
38
- (n.src = "https://cdn.livechatinc.com/tracking.js"),
39
- t.head.appendChild(n);
40
- },
41
- };
42
- !n.__lc.asyncInit && e.init(),
43
- (n.LiveChatWidget = n.LiveChatWidget || e);
44
- })(window, document, [].slice);
45
- </script>
46
- <!-- End of LiveChat code -->
47
-
48
- <script async src="./main.js" type="module"></script>
49
- <script>
50
- window.commversion = {
51
- // show: "^/show$",
52
- hide: "^/hide$",
53
- };
54
- </script>
55
-
56
- <h1>show-hide</h1>
57
- </body>
58
- </html>
@@ -1,5 +0,0 @@
1
- import { showHide } from "./show-hide.js";
2
-
3
- window.commversion = window.commversion || {};
4
-
5
- window.LiveChatWidget.on("ready", showHide(window.commversion));
@@ -1,11 +0,0 @@
1
- export const showPredicate = (pagesRegExp, currentUrl) => {
2
- const shouldHide = !pagesRegExp.test(currentUrl);
3
-
4
- return shouldHide;
5
- };
6
-
7
- export const hidePredicate = (pagesRegExp, currentUrl) => {
8
- const shouldHide = pagesRegExp.test(currentUrl);
9
-
10
- return shouldHide;
11
- };
@@ -1,49 +0,0 @@
1
- import { hidePredicate, showPredicate } from "./predicate-functions.js";
2
-
3
- const hideableStatuses = ["browsing"];
4
-
5
- const getPlugin = (configuration) => {
6
- if (configuration.show && configuration.hide) {
7
- return {
8
- predicateFn: () =>
9
- console.error(
10
- "Cannot set both show and hide configuration. Please choose one."
11
- ),
12
- };
13
- }
14
-
15
- if (configuration.show) {
16
- return {
17
- predicateFn: showPredicate,
18
- pluginConfiguration: configuration.show,
19
- };
20
- }
21
-
22
- if (configuration.hide) {
23
- return {
24
- predicateFn: hidePredicate,
25
- pluginConfiguration: configuration.hide,
26
- };
27
- }
28
-
29
- return {
30
- predicateFn: () => console.error("No configuration for show/hide script."),
31
- };
32
- };
33
-
34
- export const showHide =
35
- (configuration) =>
36
- ({ customerData }) => {
37
- const { LiveChatWidget } = window;
38
- const currentUrl = window.location.pathname;
39
-
40
- const { predicateFn, pluginConfiguration } = getPlugin(configuration);
41
-
42
- const shouldHide =
43
- predicateFn(new RegExp(pluginConfiguration), currentUrl) &&
44
- hideableStatuses.includes(customerData.status);
45
-
46
- if (shouldHide) {
47
- LiveChatWidget.call("hide");
48
- }
49
- };
@@ -1,31 +0,0 @@
1
- import { expect } from "@esm-bundle/chai";
2
- import { fake } from "sinon";
3
- import { hidePredicate, showPredicate } from "../src/predicate-functions.js";
4
-
5
- describe("hidePredicate", () => {
6
- it("should return true", () => {
7
- const shouldHide = hidePredicate(new RegExp("^/$"), "/");
8
-
9
- expect(shouldHide).to.be.true;
10
- });
11
-
12
- it("should return false", () => {
13
- const shouldHide = hidePredicate(new RegExp("^/$"), "/test");
14
-
15
- expect(shouldHide).to.be.false;
16
- });
17
- });
18
-
19
- describe("showPredicate", () => {
20
- it("should return false", () => {
21
- const shouldHide = showPredicate(new RegExp("^/$"), "/");
22
-
23
- expect(shouldHide).to.be.false;
24
- });
25
-
26
- it("should return reue", () => {
27
- const shouldHide = showPredicate(new RegExp("^/$"), "/test");
28
-
29
- expect(shouldHide).to.be.true;
30
- });
31
- });
@@ -1,17 +0,0 @@
1
- import path from "path";
2
-
3
- const config = {
4
- build: {
5
- outDir: path.resolve("dist"),
6
- emptyOutDir: false,
7
- target: "es2015",
8
- lib: {
9
- entry: path.resolve(__dirname, "src/main.js"),
10
- name: "lcShowHide",
11
- fileName: () => "lc-show-hide.js",
12
- formats: ["iife"],
13
- },
14
- },
15
- };
16
-
17
- export default config;
@@ -1,58 +0,0 @@
1
- # Schedule event
2
-
3
- A plugin to help trigger events on weekly basis.
4
-
5
- ## Installation
6
-
7
- Use the following snippet to install the plugin to website.
8
-
9
- ```html
10
- <script
11
- async
12
- src="https://cdn.jsdelivr.net/npm/@commversion/libs@version/dist/schedule-event.js"
13
- ></script>
14
-
15
- <script>
16
- window.commversion = window.commversion || {};
17
-
18
- window.commversion.timezone = "Asia/Kolkata";
19
- window.commversion.schedule = [
20
- {
21
- from: [0, 0, 0],
22
- to: [1, 23, 59],
23
- callback: () => alert("triggers sunday & monday"),
24
- },
25
- {
26
- from: [2, 0, 0],
27
- to: [3, 23, 59],
28
- callback: () => alert("triggers tuesday & wednesday"),
29
- },
30
- ];
31
- </script>
32
- ```
33
-
34
- ## Usage
35
-
36
- The script needs to set some configuration into `window.commversion`. It needs to define the schedule plan for the triggers and the website's timezone.
37
-
38
- ### Timezones
39
-
40
- All IANA timezones are supported but not local idioms for non-western date-times.
41
- Please find the list of all timezones at this [Wikipedia article](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).
42
-
43
- ### Rules syntax
44
-
45
- A special set of rules are used to define the schedule. Each rule has to hold a `from` property (consider this the starting point), a `to` property (ending point) and a `callback` function to trigger when active.
46
-
47
- `from` and `to` are defined like this:
48
-
49
- ```
50
- [1, 13, 30]
51
- │ │ │
52
- │ │ └─────► minute of the hour
53
- │ └─────────► hour of the day (24hrs)
54
- └────────────► day of the week (Sunday is 0)
55
-
56
- ```
57
-
58
- In case multiple rules are overriding each other's schedule, only the first will be considered as active.
@@ -1,14 +0,0 @@
1
- <html>
2
- <body>
3
- <script async src="./main.js"></script>
4
- <script>
5
- window.commversion = {
6
- schedule: [
7
- { from: [0, 0, 0], to: [2, 23, 59], callback: () => alert("runs") },
8
- ],
9
- timezone: "Asia/Kolkata",
10
- };
11
- </script>
12
- <h1>lets see if this works</h1>
13
- </body>
14
- </html>
@@ -1,13 +0,0 @@
1
- import scheduleEvent from "./schedule-event.js";
2
-
3
- window.commversion = window.commversion || {};
4
-
5
- const { schedule, timezone } = window.commversion;
6
-
7
- [schedule, timezone].forEach((p) => {
8
- if (typeof p !== "undefined") return;
9
-
10
- throw new Error("Invalid configuration");
11
- });
12
-
13
- scheduleEvent(schedule, timezone);
@@ -1,16 +0,0 @@
1
- const noop = () => {};
2
- const getScore = (day, hour, minute) => day * 1440 + hour * 60 + minute;
3
-
4
- export default (schedule, now) => {
5
- const action = schedule.reverse().reduce((acc, { from, to, callback }) => {
6
- const scoreFrom = getScore(from[0], from[1], from[2]);
7
- const scoreTo = getScore(to[0], to[1], to[2]);
8
- const scoreNow = getScore(now[0], now[1], now[2]);
9
-
10
- const isActive = scoreFrom <= scoreNow && scoreNow < scoreTo;
11
-
12
- return isActive ? callback : acc;
13
- }, noop);
14
-
15
- return action;
16
- };
@@ -1,18 +0,0 @@
1
- import spacetime from "spacetime";
2
- import parseSchedule from "./parse-schedule.js";
3
-
4
- const scheduleEvent = async (schedule, timezone) => {
5
- const now = spacetime(new Date(), timezone, {
6
- weekStart: 0,
7
- });
8
-
9
- const callback = parseSchedule(schedule, [
10
- now.day(),
11
- now.hour(),
12
- now.minute(),
13
- ]);
14
-
15
- await callback();
16
- };
17
-
18
- export default scheduleEvent;