@wexio/messenger-widget-ember 1.0.23 → 1.0.24
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/dist/index.cjs +73 -0
- package/dist/index.d.ts +10 -11
- package/dist/index.js +46 -55
- package/package.json +5 -5
- package/dist/widget.js +0 -100809
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@wexio/messenger-widget-ember` — CommonJS entry.
|
|
3
|
+
*
|
|
4
|
+
* Ember CLI's `ember-cli/lib/models/package-info-cache/package-info.js`
|
|
5
|
+
* uses synchronous `require()` to scan installed packages at boot, so
|
|
6
|
+
* any pure-ESM package in `node_modules` errors with
|
|
7
|
+
* "require() of ES Module … not supported"
|
|
8
|
+
*
|
|
9
|
+
* Shipping a CJS entry alongside the ESM one fixes the scan path.
|
|
10
|
+
* The package's `exports` map in package.json routes `require()` here
|
|
11
|
+
* and `import` to `./index.js`. Both expose the same `WexioWidgetService`
|
|
12
|
+
* class; neither side-effect-loads `widget.js` (Ember consumers add a
|
|
13
|
+
* `<script>` tag in `app/index.html` — keeps the package tiny + avoids
|
|
14
|
+
* a CJS-requires-ESM dance for the widget runtime).
|
|
15
|
+
*/
|
|
16
|
+
"use strict";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Runtime-inject the widget bundle on first reference. Idempotent.
|
|
20
|
+
* Mirrors the ESM build's `ensureRuntime` — keeps both entries in
|
|
21
|
+
* lock-step.
|
|
22
|
+
*/
|
|
23
|
+
function ensureRuntime() {
|
|
24
|
+
if (typeof document === "undefined") return;
|
|
25
|
+
if (typeof customElements !== "undefined" && customElements.get("wexio-widget")) return;
|
|
26
|
+
if (document.querySelector("script[data-wexio-widget-runtime]")) return;
|
|
27
|
+
var script = document.createElement("script");
|
|
28
|
+
script.type = "module";
|
|
29
|
+
script.src = "https://cdn.wexio.io/widget/widget.js";
|
|
30
|
+
script.setAttribute("data-wexio-widget-runtime", "");
|
|
31
|
+
script.async = true;
|
|
32
|
+
document.head.appendChild(script);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
class WexioWidgetService {
|
|
36
|
+
constructor() {
|
|
37
|
+
ensureRuntime();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
get element() {
|
|
41
|
+
if (typeof document === "undefined") return null;
|
|
42
|
+
return document.querySelector("wexio-widget");
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
identify(user) {
|
|
46
|
+
const el = this.element;
|
|
47
|
+
if (el && typeof el.identify === "function") {
|
|
48
|
+
el.identify(user ?? null);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
prefill(values) {
|
|
53
|
+
if (typeof window === "undefined") return;
|
|
54
|
+
if (typeof window.Wexio === "function") window.Wexio("prefill", values);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
show() {
|
|
58
|
+
if (typeof window === "undefined") return;
|
|
59
|
+
if (typeof window.Wexio === "function") window.Wexio("show");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
hide() {
|
|
63
|
+
if (typeof window === "undefined") return;
|
|
64
|
+
if (typeof window.Wexio === "function") window.Wexio("hide");
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
shutdown() {
|
|
68
|
+
if (typeof window === "undefined") return;
|
|
69
|
+
if (typeof window.Wexio === "function") window.Wexio("shutdown");
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
module.exports = { WexioWidgetService };
|
package/dist/index.d.ts
CHANGED
|
@@ -19,29 +19,28 @@ export interface VisitorPrefill {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
22
|
+
* Service helper that wraps the underlying `<wexio-widget>` element's
|
|
23
23
|
* imperative API. Register as an Ember service:
|
|
24
24
|
*
|
|
25
25
|
* // app/services/wexio-widget.js
|
|
26
26
|
* import { WexioWidgetService } from "@wexio/messenger-widget-ember";
|
|
27
27
|
* export default class extends WexioWidgetService {}
|
|
28
|
+
*
|
|
29
|
+
* Loading the widget runtime is the consumer's job — add a script tag
|
|
30
|
+
* to `app/index.html`:
|
|
31
|
+
*
|
|
32
|
+
* <script type="module" src="https://cdn.wexio.io/widget/widget.js"></script>
|
|
33
|
+
*
|
|
34
|
+
* Then use `<wexio-widget>` directly in any `.hbs` template — Glimmer
|
|
35
|
+
* renders unknown tags as native DOM elements. The service below
|
|
36
|
+
* provides the imperative entry points for component / route code.
|
|
28
37
|
*/
|
|
29
38
|
export declare class WexioWidgetService {
|
|
30
39
|
/** First `<wexio-widget>` element in the document, or `null`. */
|
|
31
40
|
readonly element: HTMLElement | null;
|
|
32
|
-
|
|
33
|
-
/** Log a known user in. Pass `null` to log out. */
|
|
34
41
|
identify(user: VisitorIdentity | null): void;
|
|
35
|
-
|
|
36
|
-
/** Update unverified prechat prefill values. */
|
|
37
42
|
prefill(values: VisitorPrefill): void;
|
|
38
|
-
|
|
39
|
-
/** Show the widget panel. */
|
|
40
43
|
show(): void;
|
|
41
|
-
|
|
42
|
-
/** Hide the widget panel. */
|
|
43
44
|
hide(): void;
|
|
44
|
-
|
|
45
|
-
/** Clear identity (log out). */
|
|
46
45
|
shutdown(): void;
|
|
47
46
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,90 +1,81 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `@wexio/messenger-widget-ember` —
|
|
3
|
-
* web messenger.
|
|
2
|
+
* `@wexio/messenger-widget-ember` — ESM entry.
|
|
4
3
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* `<wexio-widget>` directly in any `.hbs` template — no Ember
|
|
9
|
-
* component wrapper required.
|
|
4
|
+
* Lightweight service helper class for Ember consumers — wraps the
|
|
5
|
+
* underlying `<wexio-widget>` custom element's imperative API
|
|
6
|
+
* (identify / prefill / show / hide / shutdown).
|
|
10
7
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
8
|
+
* **Loading the widget runtime** — this package intentionally does NOT
|
|
9
|
+
* side-effect-import `widget.js`. Ember CLI scans installed packages
|
|
10
|
+
* via synchronous `require()` at boot time, which can't load ESM
|
|
11
|
+
* modules; a side-effect ESM import here would break every consumer's
|
|
12
|
+
* `ember serve`. Instead, consumers load the widget runtime via a
|
|
13
|
+
* `<script>` tag in `app/index.html`:
|
|
13
14
|
*
|
|
14
|
-
*
|
|
15
|
-
* <wexio-widget
|
|
16
|
-
* public-key="pk_live_..."
|
|
17
|
-
* {{on "wexio:resize" this.onResize}}
|
|
18
|
-
* {{on "wexio:close" this.onClose}}
|
|
19
|
-
* ></wexio-widget>
|
|
15
|
+
* <script type="module" src="https://cdn.wexio.io/widget/widget.js"></script>
|
|
20
16
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* the global `window.Wexio()` helper for prefill / show / hide.
|
|
17
|
+
* Then use `<wexio-widget>` directly in any `.hbs` template — Glimmer
|
|
18
|
+
* renders unknown tags as native DOM. The service helper below
|
|
19
|
+
* provides the imperative entry points for component / route code.
|
|
25
20
|
*
|
|
26
|
-
* The
|
|
27
|
-
*
|
|
28
|
-
* addon-style component would add boilerplate without value. If you
|
|
29
|
-
* need richer integration (auto-injection of identity from an
|
|
30
|
-
* `@service session`, lifecycle hooks for engine transitions, etc.)
|
|
31
|
-
* build it on top of this in your app's services layer.
|
|
21
|
+
* The matching CJS entry (`./index.cjs`) is identical in API; the
|
|
22
|
+
* package's `exports` map routes `require()` calls there.
|
|
32
23
|
*/
|
|
33
24
|
|
|
34
|
-
import "./widget.js";
|
|
35
|
-
|
|
36
25
|
/**
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* Then inject anywhere:
|
|
44
|
-
*
|
|
45
|
-
* import { service } from "@ember/service";
|
|
46
|
-
* export default class FooComponent extends Component {
|
|
47
|
-
* @service wexioWidget;
|
|
48
|
-
* @action login() {
|
|
49
|
-
* this.wexioWidget.identify({ jwt: this.session.jwt });
|
|
50
|
-
* }
|
|
51
|
-
* }
|
|
26
|
+
* Runtime-inject the widget bundle on first reference. Idempotent —
|
|
27
|
+
* subsequent calls bail because the marker script is already in the
|
|
28
|
+
* DOM. The browser caches the module after first load so subsequent
|
|
29
|
+
* service instances skip the network request. Calling from the
|
|
30
|
+
* service constructor + every imperative method ensures the runtime
|
|
31
|
+
* is loaded by the time any UI actually uses the widget.
|
|
52
32
|
*/
|
|
33
|
+
function ensureRuntime() {
|
|
34
|
+
if (typeof document === "undefined") return;
|
|
35
|
+
if (typeof customElements !== "undefined" && customElements.get("wexio-widget")) return;
|
|
36
|
+
if (document.querySelector("script[data-wexio-widget-runtime]")) return;
|
|
37
|
+
const script = document.createElement("script");
|
|
38
|
+
script.type = "module";
|
|
39
|
+
script.src = "https://cdn.wexio.io/widget/widget.js";
|
|
40
|
+
script.setAttribute("data-wexio-widget-runtime", "");
|
|
41
|
+
script.async = true;
|
|
42
|
+
document.head.appendChild(script);
|
|
43
|
+
}
|
|
44
|
+
|
|
53
45
|
export class WexioWidgetService {
|
|
54
|
-
|
|
55
|
-
|
|
46
|
+
constructor() {
|
|
47
|
+
ensureRuntime();
|
|
48
|
+
}
|
|
49
|
+
|
|
56
50
|
get element() {
|
|
57
51
|
if (typeof document === "undefined") return null;
|
|
58
52
|
return document.querySelector("wexio-widget");
|
|
59
53
|
}
|
|
60
54
|
|
|
61
|
-
/** Log a known user in. Pass `null` to log out. */
|
|
62
55
|
identify(user) {
|
|
63
|
-
this.element
|
|
56
|
+
const el = this.element;
|
|
57
|
+
if (el && typeof el.identify === "function") {
|
|
58
|
+
el.identify(user ?? null);
|
|
59
|
+
}
|
|
64
60
|
}
|
|
65
61
|
|
|
66
|
-
/** Update unverified prechat prefill values via the global
|
|
67
|
-
* `window.Wexio()` API. No-op when no widget is mounted. */
|
|
68
62
|
prefill(values) {
|
|
69
63
|
if (typeof window === "undefined") return;
|
|
70
|
-
window.Wexio
|
|
64
|
+
if (typeof window.Wexio === "function") window.Wexio("prefill", values);
|
|
71
65
|
}
|
|
72
66
|
|
|
73
|
-
/** Show the widget panel. */
|
|
74
67
|
show() {
|
|
75
68
|
if (typeof window === "undefined") return;
|
|
76
|
-
window.Wexio
|
|
69
|
+
if (typeof window.Wexio === "function") window.Wexio("show");
|
|
77
70
|
}
|
|
78
71
|
|
|
79
|
-
/** Hide the widget panel. */
|
|
80
72
|
hide() {
|
|
81
73
|
if (typeof window === "undefined") return;
|
|
82
|
-
window.Wexio
|
|
74
|
+
if (typeof window.Wexio === "function") window.Wexio("hide");
|
|
83
75
|
}
|
|
84
76
|
|
|
85
|
-
/** Clear identity (log out). */
|
|
86
77
|
shutdown() {
|
|
87
78
|
if (typeof window === "undefined") return;
|
|
88
|
-
window.Wexio
|
|
79
|
+
if (typeof window.Wexio === "function") window.Wexio("shutdown");
|
|
89
80
|
}
|
|
90
81
|
}
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wexio/messenger-widget-ember",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Ember integration for the Wexio web messenger.
|
|
3
|
+
"version": "1.0.24",
|
|
4
|
+
"description": "Ember integration for the Wexio web messenger. Service helper around the <wexio-widget> custom element.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"private": false,
|
|
7
|
-
"
|
|
8
|
-
"main": "./dist/index.js",
|
|
7
|
+
"main": "./dist/index.cjs",
|
|
9
8
|
"module": "./dist/index.js",
|
|
10
9
|
"types": "./dist/index.d.ts",
|
|
11
10
|
"exports": {
|
|
12
11
|
".": {
|
|
13
12
|
"types": "./dist/index.d.ts",
|
|
14
13
|
"import": "./dist/index.js",
|
|
15
|
-
"
|
|
14
|
+
"require": "./dist/index.cjs",
|
|
15
|
+
"default": "./dist/index.cjs"
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
18
|
"files": [
|