@nuxt/scripts 0.1.3 → 0.1.5
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 +26 -23
- package/dist/client/200.html +5 -5
- package/dist/client/404.html +5 -5
- package/dist/client/_nuxt/{DnntiO6I.js → BBafEUG8.js} +1 -1
- package/dist/client/_nuxt/{Bw1vr1xi.js → C6qP6ksw.js} +1 -1
- package/dist/client/_nuxt/{B7gLnlpM.js → D2oMNJSZ.js} +1 -1
- package/dist/client/_nuxt/{CXVVb7oJ.js → YkgnKQjM.js} +10 -10
- package/dist/client/_nuxt/builds/latest.json +1 -1
- package/dist/client/_nuxt/builds/meta/72c1a85e-b70c-4e27-93ec-d6316f40b143.json +1 -0
- package/dist/client/index.html +5 -5
- package/dist/module.d.mts +43 -0
- package/dist/module.d.ts +43 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +107 -4
- package/dist/runtime/composables/useScript.d.ts +4 -2
- package/dist/runtime/composables/useScript.mjs +13 -1
- package/dist/runtime/composables/validateScriptInputSchema.d.ts +7 -0
- package/dist/runtime/composables/validateScriptInputSchema.mjs +12 -0
- package/dist/runtime/registry/cloudflare-turnstile.d.ts +1 -0
- package/dist/runtime/registry/cloudflare-turnstile.mjs +3 -0
- package/dist/runtime/registry/cloudflare-web-analytics.d.ts +33 -0
- package/dist/runtime/registry/cloudflare-web-analytics.mjs +37 -0
- package/dist/runtime/registry/confetti.d.ts +14 -0
- package/dist/runtime/registry/confetti.mjs +12 -0
- package/dist/runtime/registry/facebook-pixel.d.ts +42 -0
- package/dist/runtime/registry/facebook-pixel.mjs +36 -0
- package/dist/runtime/registry/fathom-analytics.d.ts +33 -0
- package/dist/runtime/registry/fathom-analytics.mjs +27 -0
- package/dist/runtime/registry/google-analytics.d.ts +1 -0
- package/dist/runtime/registry/google-analytics.mjs +3 -0
- package/dist/runtime/registry/google-tag-manager.d.ts +1 -0
- package/dist/runtime/registry/google-tag-manager.mjs +3 -0
- package/dist/runtime/registry/hotjar.d.ts +24 -0
- package/dist/runtime/registry/hotjar.mjs +30 -0
- package/dist/runtime/registry/intercom.d.ts +31 -0
- package/dist/runtime/registry/intercom.mjs +33 -0
- package/dist/runtime/registry/segment.d.ts +25 -0
- package/dist/runtime/registry/segment.mjs +43 -0
- package/dist/runtime/types.d.ts +17 -1
- package/package.json +15 -9
- package/dist/client/_nuxt/builds/meta/dfbad358-c258-488d-9323-84d07e1f8acf.json +0 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type Input } from 'valibot';
|
|
2
|
+
import type { NuxtUseScriptOptions } from '#nuxt-scripts';
|
|
3
|
+
export interface HotjarApi {
|
|
4
|
+
hj: ((event: 'identify', userId: string, attributes?: Record<string, any>) => void) & ((event: 'stateChange', path: string) => void) & ((event: 'event', eventName: string) => void) & ((event: string, arg?: string) => void) & ((...params: any[]) => void) & {
|
|
5
|
+
q: any[];
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
declare global {
|
|
9
|
+
interface Window extends HotjarApi {
|
|
10
|
+
_hjSettings: {
|
|
11
|
+
hjid: number;
|
|
12
|
+
hjsv?: number;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
declare const HotjarOptions: import("valibot").ObjectSchema<{
|
|
17
|
+
id: import("valibot").NumberSchema<number>;
|
|
18
|
+
sv: import("valibot").OptionalSchema<import("valibot").NumberSchema<number>, undefined, number | undefined>;
|
|
19
|
+
}, undefined, {
|
|
20
|
+
id: number;
|
|
21
|
+
sv?: number | undefined;
|
|
22
|
+
}>;
|
|
23
|
+
export declare function useScriptHotjar<T extends HotjarApi>(options?: Input<typeof HotjarOptions>, _scriptOptions?: Omit<NuxtUseScriptOptions<T>, 'beforeInit' | 'use'>): any;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { number, object, optional } from "valibot";
|
|
2
|
+
import { useScript, validateScriptInputSchema } from "#imports";
|
|
3
|
+
const HotjarOptions = object({
|
|
4
|
+
id: number(),
|
|
5
|
+
sv: optional(number())
|
|
6
|
+
});
|
|
7
|
+
export function useScriptHotjar(options, _scriptOptions) {
|
|
8
|
+
const scriptOptions = _scriptOptions || {};
|
|
9
|
+
scriptOptions.beforeInit = () => {
|
|
10
|
+
validateScriptInputSchema(HotjarOptions, options);
|
|
11
|
+
if (import.meta.client) {
|
|
12
|
+
window._hjSettings = window._hjSettings || { hjid: options?.id, hjsv: options?.sv };
|
|
13
|
+
window.hj = window.hj || function(...params) {
|
|
14
|
+
(window.hj.q = window.hj.q || []).push(params);
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
return useScript({
|
|
19
|
+
key: "hotjar",
|
|
20
|
+
src: `https://static.hotjar.com/c/hotjar-${options?.id}.js?sv=${options?.sv}`,
|
|
21
|
+
defer: true
|
|
22
|
+
}, {
|
|
23
|
+
trigger: "onNuxtReady",
|
|
24
|
+
...scriptOptions,
|
|
25
|
+
assetStrategy: "bundle",
|
|
26
|
+
use() {
|
|
27
|
+
return { hj: window.hj };
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type Input } from 'valibot';
|
|
2
|
+
import type { NuxtUseScriptOptions } from '#nuxt-scripts';
|
|
3
|
+
declare const IntercomOptions: import("valibot").ObjectSchema<{
|
|
4
|
+
app_id: import("valibot").StringSchema<string>;
|
|
5
|
+
api_base: import("valibot").OptionalSchema<import("valibot").UnionSchema<(import("valibot").LiteralSchema<"https://api-iam.intercom.io", "https://api-iam.intercom.io"> | import("valibot").LiteralSchema<"https://api-iam.eu.intercom.io", "https://api-iam.eu.intercom.io"> | import("valibot").LiteralSchema<"https://api-iam.au.intercom.io", "https://api-iam.au.intercom.io">)[], "https://api-iam.intercom.io" | "https://api-iam.eu.intercom.io" | "https://api-iam.au.intercom.io">, undefined, "https://api-iam.intercom.io" | "https://api-iam.eu.intercom.io" | "https://api-iam.au.intercom.io" | undefined>;
|
|
6
|
+
name: import("valibot").OptionalSchema<import("valibot").StringSchema<string>, undefined, string | undefined>;
|
|
7
|
+
email: import("valibot").OptionalSchema<import("valibot").StringSchema<string>, undefined, string | undefined>;
|
|
8
|
+
user_id: import("valibot").OptionalSchema<import("valibot").StringSchema<string>, undefined, string | undefined>;
|
|
9
|
+
alignment: import("valibot").OptionalSchema<import("valibot").UnionSchema<(import("valibot").LiteralSchema<"left", "left"> | import("valibot").LiteralSchema<"right", "right">)[], "left" | "right">, undefined, "left" | "right" | undefined>;
|
|
10
|
+
horizontal_padding: import("valibot").OptionalSchema<import("valibot").NumberSchema<number>, undefined, number | undefined>;
|
|
11
|
+
vertical_padding: import("valibot").OptionalSchema<import("valibot").NumberSchema<number>, undefined, number | undefined>;
|
|
12
|
+
}, undefined, {
|
|
13
|
+
app_id: string;
|
|
14
|
+
api_base?: "https://api-iam.intercom.io" | "https://api-iam.eu.intercom.io" | "https://api-iam.au.intercom.io" | undefined;
|
|
15
|
+
name?: string | undefined;
|
|
16
|
+
email?: string | undefined;
|
|
17
|
+
user_id?: string | undefined;
|
|
18
|
+
alignment?: "left" | "right" | undefined;
|
|
19
|
+
horizontal_padding?: number | undefined;
|
|
20
|
+
vertical_padding?: number | undefined;
|
|
21
|
+
}>;
|
|
22
|
+
export interface IntercomApi {
|
|
23
|
+
Intercom: ((event: 'boot', data?: Input<typeof IntercomOptions>) => void) & ((event: 'shutdown') => void) & ((event: 'update', options?: Input<typeof IntercomOptions>) => void) & ((event: 'hide') => void) & ((event: 'show') => void) & ((event: 'showSpace', spaceName: 'home' | 'messages' | 'help' | 'news' | 'tasks' | 'tickets' | string) => void) & ((event: 'showMessages') => void) & ((event: 'showNewMessage', content?: string) => void) & ((event: 'onHide', fn: () => void) => void) & ((event: 'onShow', fn: () => void) => void) & ((event: 'onUnreadCountChange', fn: () => void) => void) & ((event: 'trackEvent', eventName: string, metadata?: Record<string, any>) => void) & ((event: 'getVisitorId') => Promise<string>) & ((event: 'startTour', tourId: string | number) => void) & ((event: 'showArticle', articleId: string | number) => void) & ((event: 'showNews', newsItemId: string | number) => void) & ((event: 'startSurvey', surveyId: string | number) => void) & ((event: 'startChecklist', checklistId: string | number) => void) & ((event: 'showTicket', ticketId: string | number) => void) & ((event: 'showConversation', conversationId: string | number) => void) & ((event: 'onUserEmailSupplied', fn: () => void) => void) & ((event: string, ...params: any[]) => void);
|
|
24
|
+
}
|
|
25
|
+
declare global {
|
|
26
|
+
interface Window extends IntercomApi {
|
|
27
|
+
intercomSettings?: Input<typeof IntercomOptions>;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export declare function useScriptIntercom<T extends IntercomApi>(options?: Input<typeof IntercomOptions>, _scriptOptions?: Omit<NuxtUseScriptOptions<T>, 'beforeInit' | 'use'>): any;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { literal, number, object, optional, string, union } from "valibot";
|
|
2
|
+
import { useScript, validateScriptInputSchema } from "#imports";
|
|
3
|
+
const IntercomOptions = object({
|
|
4
|
+
app_id: string(),
|
|
5
|
+
api_base: optional(union([literal("https://api-iam.intercom.io"), literal("https://api-iam.eu.intercom.io"), literal("https://api-iam.au.intercom.io")])),
|
|
6
|
+
name: optional(string()),
|
|
7
|
+
email: optional(string()),
|
|
8
|
+
user_id: optional(string()),
|
|
9
|
+
// customizing the messenger
|
|
10
|
+
alignment: optional(union([literal("left"), literal("right")])),
|
|
11
|
+
horizontal_padding: optional(number()),
|
|
12
|
+
vertical_padding: optional(number())
|
|
13
|
+
});
|
|
14
|
+
export function useScriptIntercom(options, _scriptOptions) {
|
|
15
|
+
const scriptOptions = _scriptOptions || {};
|
|
16
|
+
scriptOptions.beforeInit = () => {
|
|
17
|
+
validateScriptInputSchema(IntercomOptions, options);
|
|
18
|
+
if (import.meta.client)
|
|
19
|
+
window.intercomSettings = options;
|
|
20
|
+
};
|
|
21
|
+
return useScript({
|
|
22
|
+
key: "intercom",
|
|
23
|
+
src: `https://widget.intercom.io/widget/${options?.app_id}`,
|
|
24
|
+
defer: true
|
|
25
|
+
}, {
|
|
26
|
+
trigger: "onNuxtReady",
|
|
27
|
+
...scriptOptions,
|
|
28
|
+
assetStrategy: "bundle",
|
|
29
|
+
use() {
|
|
30
|
+
return { Intercom: window.Intercom };
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type Input } from 'valibot';
|
|
2
|
+
import type { NuxtUseScriptOptions } from '#nuxt-scripts';
|
|
3
|
+
declare const SegmentOptions: import("valibot").ObjectSchema<{
|
|
4
|
+
writeKey: import("valibot").StringSchema<string>;
|
|
5
|
+
analyticsKey: import("valibot").OptionalSchema<import("valibot").StringSchema<string>, undefined, string | undefined>;
|
|
6
|
+
}, undefined, {
|
|
7
|
+
writeKey: string;
|
|
8
|
+
analyticsKey?: string | undefined;
|
|
9
|
+
}>;
|
|
10
|
+
export interface SegmentApi {
|
|
11
|
+
analytics: {
|
|
12
|
+
track: (event: string, properties?: Record<string, any>) => void;
|
|
13
|
+
page: (name?: string, properties?: Record<string, any>) => void;
|
|
14
|
+
identify: (userId: string, traits?: Record<string, any>, options?: Record<string, any>) => void;
|
|
15
|
+
group: (groupId: string, traits?: Record<string, any>, options?: Record<string, any>) => void;
|
|
16
|
+
alias: (userId: string, previousId: string, options?: Record<string, any>) => void;
|
|
17
|
+
reset: () => void;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
declare global {
|
|
21
|
+
interface Window extends SegmentApi {
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export declare function useScriptSegment<T extends SegmentApi>(options?: Input<typeof SegmentOptions>, _scriptOptions?: Omit<NuxtUseScriptOptions<T>, 'beforeInit' | 'use'>): any;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { object, optional, string } from "valibot";
|
|
2
|
+
import { useScript, validateScriptInputSchema } from "#imports";
|
|
3
|
+
const SegmentOptions = object({
|
|
4
|
+
writeKey: string(),
|
|
5
|
+
analyticsKey: optional(string())
|
|
6
|
+
});
|
|
7
|
+
export function useScriptSegment(options, _scriptOptions) {
|
|
8
|
+
const scriptOptions = _scriptOptions || {};
|
|
9
|
+
scriptOptions.beforeInit = () => {
|
|
10
|
+
validateScriptInputSchema(SegmentOptions, options);
|
|
11
|
+
if (import.meta.client) {
|
|
12
|
+
window.analytics = window.analytics || [];
|
|
13
|
+
window.analytics.methods = ["track", "page", "identify", "group", "alias", "reset"];
|
|
14
|
+
window.analytics.factory = function(method) {
|
|
15
|
+
return function(...params) {
|
|
16
|
+
const args = Array.prototype.slice.call(params);
|
|
17
|
+
args.unshift(method);
|
|
18
|
+
window.analytics.push(args);
|
|
19
|
+
return window.analytics;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
for (let i = 0; i < window.analytics.methods.length; i++) {
|
|
23
|
+
const key = window.analytics.methods[i];
|
|
24
|
+
window.analytics[key] = window.analytics.factory(key);
|
|
25
|
+
}
|
|
26
|
+
window.analytics.page();
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const analyticsKey = options?.analyticsKey || "analytics";
|
|
30
|
+
return useScript({
|
|
31
|
+
"key": "segment",
|
|
32
|
+
"data-global-segment-analytics-key": analyticsKey,
|
|
33
|
+
"src": `https://cdn.segment.com/analytics.js/v1/${options?.writeKey}/analytics.min.js`,
|
|
34
|
+
"defer": true
|
|
35
|
+
}, {
|
|
36
|
+
trigger: "onNuxtReady",
|
|
37
|
+
...scriptOptions,
|
|
38
|
+
assetStrategy: "bundle",
|
|
39
|
+
use() {
|
|
40
|
+
return { analytics: window[analyticsKey] };
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
package/dist/runtime/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { UseScriptOptions } from '@unhead/schema';
|
|
2
|
-
import type { UseScriptInput } from '@unhead/vue';
|
|
2
|
+
import type { UseScriptInput, VueScriptInstance } from '@unhead/vue';
|
|
3
3
|
import type { ComputedRef, Ref } from 'vue';
|
|
4
4
|
export type NuxtUseScriptOptions<T = any> = Omit<UseScriptOptions<T>, 'trigger'> & {
|
|
5
5
|
/**
|
|
@@ -15,6 +15,10 @@ export type NuxtUseScriptOptions<T = any> = Omit<UseScriptOptions<T>, 'trigger'>
|
|
|
15
15
|
* improves privacy by not sharing the user's IP address with third-party servers.
|
|
16
16
|
*/
|
|
17
17
|
assetStrategy?: 'bundle';
|
|
18
|
+
/**
|
|
19
|
+
* A hook to run when a script does not exist and will be initialized for the first time.
|
|
20
|
+
*/
|
|
21
|
+
beforeInit?: () => void;
|
|
18
22
|
};
|
|
19
23
|
export type NuxtUseScriptInput = UseScriptInput;
|
|
20
24
|
export interface TrackedPage {
|
|
@@ -33,3 +37,15 @@ export interface ConsentPromiseOptions {
|
|
|
33
37
|
*/
|
|
34
38
|
loadOnNuxtReady?: boolean;
|
|
35
39
|
}
|
|
40
|
+
export interface NuxtAppScript {
|
|
41
|
+
key: string;
|
|
42
|
+
src: string;
|
|
43
|
+
$script: VueScriptInstance<any>;
|
|
44
|
+
events: {
|
|
45
|
+
type: string;
|
|
46
|
+
fn?: string;
|
|
47
|
+
args?: any;
|
|
48
|
+
trigger?: string;
|
|
49
|
+
at: number;
|
|
50
|
+
}[];
|
|
51
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxt/scripts",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.5",
|
|
5
5
|
"packageManager": "pnpm@8.15.5",
|
|
6
6
|
"description": "Next-gen Scripts for Nuxt",
|
|
7
7
|
"author": {
|
|
@@ -32,34 +32,38 @@
|
|
|
32
32
|
"build": {
|
|
33
33
|
"externals": [
|
|
34
34
|
"@unhead/vue",
|
|
35
|
-
"@unhead/schema"
|
|
35
|
+
"@unhead/schema",
|
|
36
|
+
"@unhead/vue",
|
|
37
|
+
"#nuxt-scripts"
|
|
36
38
|
]
|
|
37
39
|
},
|
|
38
40
|
"dependencies": {
|
|
39
|
-
"@nuxt/devtools-kit": "^1.1.
|
|
40
|
-
"@nuxt/devtools-ui-kit": "^1.1.
|
|
41
|
+
"@nuxt/devtools-kit": "^1.1.5",
|
|
42
|
+
"@nuxt/devtools-ui-kit": "^1.1.5",
|
|
41
43
|
"@nuxt/kit": "^3.11.1",
|
|
44
|
+
"@unhead/vue": "^1.9.3",
|
|
42
45
|
"consola": "^3.2.3",
|
|
43
46
|
"defu": "^6.1.4",
|
|
44
47
|
"estree-walker": "^3.0.3",
|
|
45
48
|
"h3": "^1.11.1",
|
|
46
49
|
"magic-string": "^0.30.8",
|
|
47
|
-
"ofetch": "^1.3.
|
|
50
|
+
"ofetch": "^1.3.4",
|
|
48
51
|
"ohash": "^1.1.3",
|
|
49
52
|
"pathe": "^1.1.2",
|
|
50
53
|
"pkg-types": "^1.0.3",
|
|
51
|
-
"shiki": "^1.2.
|
|
54
|
+
"shiki": "^1.2.1",
|
|
52
55
|
"sirv": "^2.0.4",
|
|
53
56
|
"ufo": "^1.5.3",
|
|
54
57
|
"unplugin": "^1.10.0",
|
|
55
|
-
"unstorage": "^1.10.2"
|
|
58
|
+
"unstorage": "^1.10.2",
|
|
59
|
+
"valibot": "^0.30.0"
|
|
56
60
|
},
|
|
57
61
|
"devDependencies": {
|
|
58
62
|
"@antfu/eslint-config": "2.8.3",
|
|
59
|
-
"@nuxt/devtools-ui-kit": "^1.1.
|
|
63
|
+
"@nuxt/devtools-ui-kit": "^1.1.5",
|
|
60
64
|
"@nuxt/module-builder": "^0.5.5",
|
|
61
65
|
"@nuxt/test-utils": "3.12.0",
|
|
62
|
-
"@unhead/schema": "^1.
|
|
66
|
+
"@unhead/schema": "^1.9.3",
|
|
63
67
|
"acorn-loose": "^8.4.0",
|
|
64
68
|
"bumpp": "^9.4.0",
|
|
65
69
|
"eslint": "8.57.0",
|
|
@@ -67,6 +71,7 @@
|
|
|
67
71
|
"nuxt-scripts-devtools": "latest",
|
|
68
72
|
"playwright-core": "^1.42.1",
|
|
69
73
|
"typescript": "^5.4.3",
|
|
74
|
+
"unimport": "^3.7.1",
|
|
70
75
|
"vitest": "^1.4.0"
|
|
71
76
|
},
|
|
72
77
|
"resolutions": {
|
|
@@ -77,6 +82,7 @@
|
|
|
77
82
|
"client:build": "nuxi generate client",
|
|
78
83
|
"client:dev": "nuxi dev client --port 3300",
|
|
79
84
|
"dev": "nuxi dev playground",
|
|
85
|
+
"dev:ssl": "nuxi dev playground --https",
|
|
80
86
|
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
|
|
81
87
|
"typecheck": "pnpm dlx vue-tsc --noEmit",
|
|
82
88
|
"release": "pnpm build && bumpp && pnpm -r publish --no-git-checks",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"id":"dfbad358-c258-488d-9323-84d07e1f8acf","timestamp":1711553364503,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
|