@xyd-js/plugin-intercom 0.0.0-build

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 ADDED
@@ -0,0 +1,7 @@
1
+ # @xyd-js/plugin-intercom
2
+
3
+ ## 0.0.0-build+6952c2c-20250813013245
4
+
5
+ ### Patch Changes
6
+
7
+ - update all packages
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 xyd
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,3 @@
1
+ declare function IntercomPlugin(pluginOptions?: any): any;
2
+
3
+ export { IntercomPlugin as default };
package/dist/index.js ADDED
@@ -0,0 +1,79 @@
1
+ // src/script.ts
2
+ function initIntercom(appId, apiBase) {
3
+ window.intercomSettings = {
4
+ api_base: apiBase,
5
+ app_id: appId
6
+ // user_id: user.id, // IMPORTANT: Replace "user.id" with the variable you use to capture the user's ID
7
+ // name: user.name, // IMPORTANT: Replace "user.name" with the variable you use to capture the user's name
8
+ // email: user.email, // IMPORTANT: Replace "user.email" with the variable you use to capture the user's email address
9
+ // created_at: user.createdAt, // IMPORTANT: Replace "user.createdAt" with the variable you use to capture the user's sign-up date
10
+ };
11
+ (function() {
12
+ var w = window;
13
+ var ic = w.Intercom;
14
+ if (typeof ic === "function") {
15
+ ic("reattach_activator");
16
+ ic("update", w.intercomSettings);
17
+ } else {
18
+ var d = document;
19
+ var i = function() {
20
+ i.c(arguments);
21
+ };
22
+ i.q = [];
23
+ i.c = function(args) {
24
+ i.q.push(args);
25
+ };
26
+ w.Intercom = i;
27
+ var l = function() {
28
+ var s = d.createElement("script");
29
+ s.type = "text/javascript";
30
+ s.async = true;
31
+ s.src = "https://widget.intercom.io/widget/" + appId;
32
+ var x = d.getElementsByTagName("script")[0];
33
+ if (x && x.parentNode) {
34
+ x.parentNode.insertBefore(s, x);
35
+ } else {
36
+ d.head.appendChild(s);
37
+ }
38
+ };
39
+ if (document.readyState === "complete") {
40
+ l();
41
+ } else if (w.attachEvent) {
42
+ w.attachEvent("onload", l);
43
+ } else {
44
+ w.addEventListener("load", l, false);
45
+ }
46
+ }
47
+ })();
48
+ }
49
+
50
+ // src/index.ts
51
+ function IntercomPlugin(pluginOptions = {}) {
52
+ return function() {
53
+ const headScripts = [];
54
+ const {
55
+ appId,
56
+ apiBase = "https://api-iam.intercom.io"
57
+ } = pluginOptions;
58
+ if (appId) {
59
+ headScripts.push(
60
+ [
61
+ "script",
62
+ {},
63
+ `(${initIntercom.toString()})('${appId}', '${apiBase}')`
64
+ ]
65
+ );
66
+ } else {
67
+ console.warn("Intercom appId is not set");
68
+ }
69
+ return {
70
+ name: "plugin-intercom",
71
+ vite: [],
72
+ head: headScripts
73
+ };
74
+ };
75
+ }
76
+ export {
77
+ IntercomPlugin as default
78
+ };
79
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/script.ts","../src/index.ts"],"sourcesContent":["// TODO: in the future better API + more typesafe\n\nexport function initIntercom(\n appId: string,\n apiBase: string,\n) {\n window.intercomSettings = {\n api_base: apiBase,\n app_id: appId,\n // user_id: user.id, // IMPORTANT: Replace \"user.id\" with the variable you use to capture the user's ID\n // name: user.name, // IMPORTANT: Replace \"user.name\" with the variable you use to capture the user's name\n // email: user.email, // IMPORTANT: Replace \"user.email\" with the variable you use to capture the user's email address\n // created_at: user.createdAt, // IMPORTANT: Replace \"user.createdAt\" with the variable you use to capture the user's sign-up date\n };\n\n (function () {\n var w = window;\n var ic = w.Intercom;\n if (typeof ic === \"function\") {\n ic(\"reattach_activator\");\n ic(\"update\", w.intercomSettings);\n } else {\n var d = document;\n var i = function () {\n i.c(arguments);\n };\n i.q = [];\n i.c = function (args) {\n i.q.push(args);\n };\n w.Intercom = i;\n var l = function () {\n var s = d.createElement(\"script\");\n s.type = \"text/javascript\";\n s.async = true;\n s.src = \"https://widget.intercom.io/widget/\" + appId;\n var x = d.getElementsByTagName(\"script\")[0];\n if (x && x.parentNode) {\n x.parentNode.insertBefore(s, x);\n } else {\n d.head.appendChild(s);\n }\n };\n if (document.readyState === \"complete\") {\n l();\n } else if (w.attachEvent) {\n w.attachEvent(\"onload\", l);\n } else {\n w.addEventListener(\"load\", l, false);\n }\n }\n })();\n\n\n}\n","import { initIntercom } from './script'\n\nexport default function IntercomPlugin(\n pluginOptions: any = {} // TODO: fix any\n): any {\n return function () {\n const headScripts: ([string, Record<string, any>] | [string, Record<string, any>, string])[] = []\n\n const {\n appId,\n apiBase = \"https://api-iam.intercom.io\",\n } = pluginOptions;\n \n if (appId) {\n headScripts.push(\n [\n \"script\",\n {},\n `(${initIntercom.toString()})('${appId}', '${apiBase}')`\n ]\n )\n } else {\n console.warn(\"Intercom appId is not set\")\n }\n\n return {\n name: \"plugin-intercom\",\n vite: [],\n head: headScripts\n }\n }\n}\n\n"],"mappings":";AAEO,SAAS,aACZ,OACA,SACF;AACE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;AAAA,MACJ;AAAA,IACJ,OAAO;AACH,cAAQ,KAAK,2BAA2B;AAAA,IAC5C;AAEA,WAAO;AAAA,MACH,MAAM;AAAA,MACN,MAAM,CAAC;AAAA,MACP,MAAM;AAAA,IACV;AAAA,EACJ;AACJ;","names":[]}
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@xyd-js/plugin-intercom",
3
+ "version": "0.0.0-build+6952c2c-20250813013245",
4
+ "author": "",
5
+ "description": "",
6
+ "license": "MIT",
7
+ "main": "./dist/index.js",
8
+ "type": "module",
9
+ "exports": {
10
+ "./package.json": "./package.json",
11
+ ".": {
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
15
+ "dependencies": {},
16
+ "peerDependencies": {},
17
+ "devDependencies": {
18
+ "vite": "^7.0.0",
19
+ "@vitest/coverage-v8": "^1.6.1",
20
+ "rimraf": "^3.0.2",
21
+ "tsup": "^8.4.0",
22
+ "vitest": "^1.6.1"
23
+ },
24
+ "scripts": {
25
+ "clean": "rimraf build",
26
+ "prebuild": "pnpm clean",
27
+ "build": "tsup",
28
+ "test": "vitest",
29
+ "test:coverage": "vitest run --coverage"
30
+ }
31
+ }
@@ -0,0 +1,8 @@
1
+ declare global {]
2
+ interface Window {
3
+ intercomSettings: any;
4
+ Intercom: any;
5
+ }
6
+ }
7
+
8
+ export {}
package/src/index.ts ADDED
@@ -0,0 +1,33 @@
1
+ import { initIntercom } from './script'
2
+
3
+ export default function IntercomPlugin(
4
+ pluginOptions: any = {} // TODO: fix any
5
+ ): any {
6
+ return function () {
7
+ const headScripts: ([string, Record<string, any>] | [string, Record<string, any>, string])[] = []
8
+
9
+ const {
10
+ appId,
11
+ apiBase = "https://api-iam.intercom.io",
12
+ } = pluginOptions;
13
+
14
+ if (appId) {
15
+ headScripts.push(
16
+ [
17
+ "script",
18
+ {},
19
+ `(${initIntercom.toString()})('${appId}', '${apiBase}')`
20
+ ]
21
+ )
22
+ } else {
23
+ console.warn("Intercom appId is not set")
24
+ }
25
+
26
+ return {
27
+ name: "plugin-intercom",
28
+ vite: [],
29
+ head: headScripts
30
+ }
31
+ }
32
+ }
33
+
package/src/script.ts ADDED
@@ -0,0 +1,55 @@
1
+ // TODO: in the future better API + more typesafe
2
+
3
+ export function initIntercom(
4
+ appId: string,
5
+ apiBase: string,
6
+ ) {
7
+ window.intercomSettings = {
8
+ api_base: apiBase,
9
+ app_id: appId,
10
+ // user_id: user.id, // IMPORTANT: Replace "user.id" with the variable you use to capture the user's ID
11
+ // name: user.name, // IMPORTANT: Replace "user.name" with the variable you use to capture the user's name
12
+ // email: user.email, // IMPORTANT: Replace "user.email" with the variable you use to capture the user's email address
13
+ // created_at: user.createdAt, // IMPORTANT: Replace "user.createdAt" with the variable you use to capture the user's sign-up date
14
+ };
15
+
16
+ (function () {
17
+ var w = window;
18
+ var ic = w.Intercom;
19
+ if (typeof ic === "function") {
20
+ ic("reattach_activator");
21
+ ic("update", w.intercomSettings);
22
+ } else {
23
+ var d = document;
24
+ var i = function () {
25
+ i.c(arguments);
26
+ };
27
+ i.q = [];
28
+ i.c = function (args) {
29
+ i.q.push(args);
30
+ };
31
+ w.Intercom = i;
32
+ var l = function () {
33
+ var s = d.createElement("script");
34
+ s.type = "text/javascript";
35
+ s.async = true;
36
+ s.src = "https://widget.intercom.io/widget/" + appId;
37
+ var x = d.getElementsByTagName("script")[0];
38
+ if (x && x.parentNode) {
39
+ x.parentNode.insertBefore(s, x);
40
+ } else {
41
+ d.head.appendChild(s);
42
+ }
43
+ };
44
+ if (document.readyState === "complete") {
45
+ l();
46
+ } else if (w.attachEvent) {
47
+ w.attachEvent("onload", l);
48
+ } else {
49
+ w.addEventListener("load", l, false);
50
+ }
51
+ }
52
+ })();
53
+
54
+
55
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "esnext",
4
+ "esModuleInterop": true,
5
+ "moduleResolution": "bundler",
6
+ "target": "esnext",
7
+ "baseUrl": ".",
8
+ "lib": ["dom", "dom.iterable", "esnext"],
9
+ "allowJs": true,
10
+ "skipLibCheck": true,
11
+ "strict": false,
12
+ "noEmit": true,
13
+ "incremental": false,
14
+ "resolveJsonModule": true,
15
+ "isolatedModules": true,
16
+ "jsx": "preserve",
17
+ "plugins": [],
18
+ "strictNullChecks": true
19
+ },
20
+ "include": ["src/**/*.ts", "src/**/*.tsx"],
21
+ "exclude": ["node_modules"]
22
+ }
package/tsup.config.ts ADDED
@@ -0,0 +1,21 @@
1
+ import {defineConfig, Options} from 'tsup';
2
+
3
+ const config: Options = {
4
+ entry: {
5
+ index: 'src/index.ts'
6
+ },
7
+ dts: {
8
+ entry: {
9
+ index: 'src/index.ts'
10
+ },
11
+ resolve: true, // Resolve external types
12
+ },
13
+ format: ['esm'],
14
+ platform: 'node',
15
+ shims: false,
16
+ splitting: false,
17
+ sourcemap: true,
18
+ clean: true,
19
+ }
20
+
21
+ export default defineConfig(config);