@webzolver/client 1.4.0 → 1.5.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.
- package/dist/index.d.ts +19 -1
- package/dist/index.js +19 -1
- package/dist/seo-Dr5q1emj.d.ts +104 -0
- package/dist/seo.d.ts +2 -104
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,20 @@
|
|
|
1
|
-
export { C as ContentResponse, L as ListItem, a as ListSectionKeys, S as SectionFields, b as SeoMetadata, c as SingleSection, d as SingleSectionKeys, W as WebZolverClient, e as WebZolverClientConfig, f as WebZolverError, g as createClient, generateCloudflareRedirects, generateSitemapXml, renderSeoTags } from './seo.js';
|
|
1
|
+
export { C as ContentResponse, L as ListItem, a as ListSectionKeys, S as SectionFields, b as SeoMetadata, c as SingleSection, d as SingleSectionKeys, W as WebZolverClient, e as WebZolverClientConfig, f as WebZolverError, g as createClient, h as generateCloudflareRedirects, i as generateSitemapXml, r as renderSeoTags } from './seo-Dr5q1emj.js';
|
|
2
2
|
import '@webzolver/schema';
|
|
3
|
+
|
|
4
|
+
interface TrafficScriptOptions {
|
|
5
|
+
/** Identificador del sitio en el portal. */
|
|
6
|
+
site: string;
|
|
7
|
+
/** URL del portal. Por defecto `https://portal.webzolver.cl`. */
|
|
8
|
+
apiUrl?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Script de visitas y contactos (~1 KB, sin cookies ni localStorage) para poner
|
|
12
|
+
* inline en el `<head>`. Envía al portal:
|
|
13
|
+
* - `pageview` al cargar cada página (también con las View Transitions de Astro);
|
|
14
|
+
* - `whatsapp`, `phone` o `email` al hacer clic en un enlace `wa.me`, `tel:` o `mailto:`;
|
|
15
|
+
* - `form` al enviar un formulario (se excluye con `data-wz-ignore`).
|
|
16
|
+
* `window.wzTrack('form')` registra un evento a mano. No corre en localhost.
|
|
17
|
+
*/
|
|
18
|
+
declare function trafficScript(options: TrafficScriptOptions): string;
|
|
19
|
+
|
|
20
|
+
export { type TrafficScriptOptions, trafficScript };
|
package/dist/index.js
CHANGED
|
@@ -77,11 +77,29 @@ var WebZolverClient = class {
|
|
|
77
77
|
function createClient(config) {
|
|
78
78
|
return new WebZolverClient(config);
|
|
79
79
|
}
|
|
80
|
+
|
|
81
|
+
// src/traffic.ts
|
|
82
|
+
function trafficScript(options) {
|
|
83
|
+
if (!/^[a-z0-9][a-z0-9_-]*$/.test(options.site)) throw new Error(`Identificador de sitio inv\xE1lido: ${options.site}`);
|
|
84
|
+
const endpoint = `${(options.apiUrl || "https://portal.webzolver.cl").replace(/\/$/, "")}/api/v1/collect`;
|
|
85
|
+
return `(function(){var S=${JSON.stringify(options.site)},E=${JSON.stringify(endpoint)},l=location,n=navigator,d=document,f=1;
|
|
86
|
+
if(n.webdriver||/^(localhost|127\\.|\\[::1\\]|0\\.0\\.0\\.0)|\\.local$/.test(l.hostname)||!/^https?:$/.test(l.protocol))return;
|
|
87
|
+
function send(t){var r="",u="";if(f){try{r=d.referrer?new URL(d.referrer).hostname:"";if(r===l.hostname)r=""}catch(e){}try{u=new URLSearchParams(l.search).get("utm_source")||""}catch(e){}}
|
|
88
|
+
f=0;var b=JSON.stringify({s:S,t:t,p:l.pathname,r:r,u:u});
|
|
89
|
+
try{if(n.sendBeacon&&n.sendBeacon(E,new Blob([b],{type:"text/plain"})))return}catch(e){}
|
|
90
|
+
try{fetch(E,{method:"POST",body:b,keepalive:true,mode:"no-cors",headers:{"content-type":"text/plain"}})}catch(e){}}
|
|
91
|
+
window.wzTrack=send;send("pageview");
|
|
92
|
+
d.addEventListener("astro:after-swap",function(){send("pageview")});
|
|
93
|
+
d.addEventListener("click",function(ev){var a=ev.target&&ev.target.closest&&ev.target.closest("a[href]");if(!a)return;var h=a.getAttribute("href")||"";
|
|
94
|
+
var t=/^tel:/i.test(h)?"phone":/^mailto:/i.test(h)?"email":/(^whatsapp:|wa\\.me\\/|whatsapp\\.com\\/)/i.test(h)?"whatsapp":"";if(t)send(t)},true);
|
|
95
|
+
d.addEventListener("submit",function(ev){var x=ev.target;if(x&&x.hasAttribute&&!x.hasAttribute("data-wz-ignore"))send("form")},true)})();`;
|
|
96
|
+
}
|
|
80
97
|
export {
|
|
81
98
|
WebZolverClient,
|
|
82
99
|
WebZolverError,
|
|
83
100
|
createClient,
|
|
84
101
|
generateCloudflareRedirects,
|
|
85
102
|
generateSitemapXml,
|
|
86
|
-
renderSeoTags
|
|
103
|
+
renderSeoTags,
|
|
104
|
+
trafficScript
|
|
87
105
|
};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { SiteSchemaDefinition, InferSectionFields } from '@webzolver/schema';
|
|
2
|
+
|
|
3
|
+
type SingleSectionKeys<T extends SiteSchemaDefinition> = {
|
|
4
|
+
[K in keyof T['sections']]: T['sections'][K]['mode'] extends 'single' ? K : never;
|
|
5
|
+
}[keyof T['sections']] & string;
|
|
6
|
+
type ListSectionKeys<T extends SiteSchemaDefinition> = {
|
|
7
|
+
[K in keyof T['sections']]: T['sections'][K]['mode'] extends 'list' ? K : never;
|
|
8
|
+
}[keyof T['sections']] & string;
|
|
9
|
+
type SectionFields<T extends SiteSchemaDefinition, K extends keyof T['sections']> = InferSectionFields<T['sections'][K]['fields']>;
|
|
10
|
+
interface SeoMetadata {
|
|
11
|
+
title?: string;
|
|
12
|
+
description?: string;
|
|
13
|
+
image?: {
|
|
14
|
+
url: string;
|
|
15
|
+
alt?: string;
|
|
16
|
+
};
|
|
17
|
+
noindex?: boolean;
|
|
18
|
+
}
|
|
19
|
+
interface ListItem<D> {
|
|
20
|
+
id: string;
|
|
21
|
+
slug: string;
|
|
22
|
+
sortOrder: number;
|
|
23
|
+
data: D;
|
|
24
|
+
seo: SeoMetadata;
|
|
25
|
+
publishedAt: string | null;
|
|
26
|
+
}
|
|
27
|
+
interface SingleSection<D> {
|
|
28
|
+
data: D;
|
|
29
|
+
seo: SeoMetadata;
|
|
30
|
+
updatedAt: string | null;
|
|
31
|
+
}
|
|
32
|
+
interface ContentResponse {
|
|
33
|
+
site: {
|
|
34
|
+
slug: string;
|
|
35
|
+
name: string;
|
|
36
|
+
};
|
|
37
|
+
contentVersion?: number;
|
|
38
|
+
publishedAt?: string | null;
|
|
39
|
+
sections: Record<string, SingleSection<Record<string, unknown>> | ListItem<Record<string, unknown>>[] | null>;
|
|
40
|
+
}
|
|
41
|
+
interface WebZolverClientConfig<T extends SiteSchemaDefinition = SiteSchemaDefinition> {
|
|
42
|
+
/** Slug del sitio en el portal (ej. `cye-clima`). */
|
|
43
|
+
site: string;
|
|
44
|
+
/** URL del portal (ej. `https://portal.webzolver.cl`). */
|
|
45
|
+
apiUrl: string;
|
|
46
|
+
schema?: T;
|
|
47
|
+
fetchImpl?: typeof fetch;
|
|
48
|
+
}
|
|
49
|
+
declare class WebZolverError extends Error {
|
|
50
|
+
readonly status: number;
|
|
51
|
+
constructor(message: string, status: number);
|
|
52
|
+
}
|
|
53
|
+
declare class WebZolverClient<T extends SiteSchemaDefinition = SiteSchemaDefinition> {
|
|
54
|
+
private readonly config;
|
|
55
|
+
private content;
|
|
56
|
+
private readonly base;
|
|
57
|
+
private readonly fetchImpl;
|
|
58
|
+
constructor(config: WebZolverClientConfig<T>);
|
|
59
|
+
private request;
|
|
60
|
+
/** Todo el contenido publicado en una sola petición (se reutiliza durante el build). Sin llave: es público. */
|
|
61
|
+
getContent(): Promise<ContentResponse>;
|
|
62
|
+
getSection<K extends SingleSectionKeys<T>>(key: K): Promise<SectionFields<T, K> | null>;
|
|
63
|
+
getSectionWithSeo<K extends SingleSectionKeys<T>>(key: K): Promise<SingleSection<SectionFields<T, K>> | null>;
|
|
64
|
+
getList<K extends ListSectionKeys<T>>(key: K): Promise<Array<ListItem<SectionFields<T, K>>>>;
|
|
65
|
+
getBySlug<K extends ListSectionKeys<T>>(key: K, slug: string): Promise<ListItem<SectionFields<T, K>> | null>;
|
|
66
|
+
/** Para `getStaticPaths()` en `src/pages/productos/[slug].astro`. */
|
|
67
|
+
getStaticPaths<K extends ListSectionKeys<T>>(key: K): Promise<{
|
|
68
|
+
params: {
|
|
69
|
+
slug: string;
|
|
70
|
+
};
|
|
71
|
+
props: {
|
|
72
|
+
entry: ListItem<InferSectionFields<T["sections"][K]["fields"]>>;
|
|
73
|
+
};
|
|
74
|
+
}[]>;
|
|
75
|
+
getSeo(key: keyof T['sections'] & string, slug?: string): Promise<SeoMetadata>;
|
|
76
|
+
getRedirects(): Promise<Array<{
|
|
77
|
+
from: string;
|
|
78
|
+
to: string;
|
|
79
|
+
}>>;
|
|
80
|
+
}
|
|
81
|
+
declare function createClient<T extends SiteSchemaDefinition>(config: WebZolverClientConfig<T>): WebZolverClient<T>;
|
|
82
|
+
|
|
83
|
+
declare function renderSeoTags(seo: SeoMetadata, defaults: {
|
|
84
|
+
siteName: string;
|
|
85
|
+
baseUrl: string;
|
|
86
|
+
currentPath: string;
|
|
87
|
+
type?: 'website' | 'article';
|
|
88
|
+
}): string;
|
|
89
|
+
declare function generateSitemapXml(baseUrl: string, staticPaths: string[], collectionEntries: Array<{
|
|
90
|
+
routePrefix: string;
|
|
91
|
+
slug: string;
|
|
92
|
+
updatedAt?: string;
|
|
93
|
+
}>): string;
|
|
94
|
+
/** Contenido para `public/_redirects` (Cloudflare Pages / Netlify). */
|
|
95
|
+
declare function generateCloudflareRedirects(options: {
|
|
96
|
+
site: string;
|
|
97
|
+
portalUrl?: string;
|
|
98
|
+
redirects: Array<{
|
|
99
|
+
from: string;
|
|
100
|
+
to: string;
|
|
101
|
+
}>;
|
|
102
|
+
}): string;
|
|
103
|
+
|
|
104
|
+
export { type ContentResponse as C, type ListItem as L, type SectionFields as S, WebZolverClient as W, type ListSectionKeys as a, type SeoMetadata as b, type SingleSection as c, type SingleSectionKeys as d, type WebZolverClientConfig as e, WebZolverError as f, createClient as g, generateCloudflareRedirects as h, generateSitemapXml as i, renderSeoTags as r };
|
package/dist/seo.d.ts
CHANGED
|
@@ -1,104 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
type SingleSectionKeys<T extends SiteSchemaDefinition> = {
|
|
4
|
-
[K in keyof T['sections']]: T['sections'][K]['mode'] extends 'single' ? K : never;
|
|
5
|
-
}[keyof T['sections']] & string;
|
|
6
|
-
type ListSectionKeys<T extends SiteSchemaDefinition> = {
|
|
7
|
-
[K in keyof T['sections']]: T['sections'][K]['mode'] extends 'list' ? K : never;
|
|
8
|
-
}[keyof T['sections']] & string;
|
|
9
|
-
type SectionFields<T extends SiteSchemaDefinition, K extends keyof T['sections']> = InferSectionFields<T['sections'][K]['fields']>;
|
|
10
|
-
interface SeoMetadata {
|
|
11
|
-
title?: string;
|
|
12
|
-
description?: string;
|
|
13
|
-
image?: {
|
|
14
|
-
url: string;
|
|
15
|
-
alt?: string;
|
|
16
|
-
};
|
|
17
|
-
noindex?: boolean;
|
|
18
|
-
}
|
|
19
|
-
interface ListItem<D> {
|
|
20
|
-
id: string;
|
|
21
|
-
slug: string;
|
|
22
|
-
sortOrder: number;
|
|
23
|
-
data: D;
|
|
24
|
-
seo: SeoMetadata;
|
|
25
|
-
publishedAt: string | null;
|
|
26
|
-
}
|
|
27
|
-
interface SingleSection<D> {
|
|
28
|
-
data: D;
|
|
29
|
-
seo: SeoMetadata;
|
|
30
|
-
updatedAt: string | null;
|
|
31
|
-
}
|
|
32
|
-
interface ContentResponse {
|
|
33
|
-
site: {
|
|
34
|
-
slug: string;
|
|
35
|
-
name: string;
|
|
36
|
-
};
|
|
37
|
-
contentVersion?: number;
|
|
38
|
-
publishedAt?: string | null;
|
|
39
|
-
sections: Record<string, SingleSection<Record<string, unknown>> | ListItem<Record<string, unknown>>[] | null>;
|
|
40
|
-
}
|
|
41
|
-
interface WebZolverClientConfig<T extends SiteSchemaDefinition = SiteSchemaDefinition> {
|
|
42
|
-
/** Slug del sitio en el portal (ej. `cye-clima`). */
|
|
43
|
-
site: string;
|
|
44
|
-
/** URL del portal (ej. `https://portal.webzolver.cl`). */
|
|
45
|
-
apiUrl: string;
|
|
46
|
-
schema?: T;
|
|
47
|
-
fetchImpl?: typeof fetch;
|
|
48
|
-
}
|
|
49
|
-
declare class WebZolverError extends Error {
|
|
50
|
-
readonly status: number;
|
|
51
|
-
constructor(message: string, status: number);
|
|
52
|
-
}
|
|
53
|
-
declare class WebZolverClient<T extends SiteSchemaDefinition = SiteSchemaDefinition> {
|
|
54
|
-
private readonly config;
|
|
55
|
-
private content;
|
|
56
|
-
private readonly base;
|
|
57
|
-
private readonly fetchImpl;
|
|
58
|
-
constructor(config: WebZolverClientConfig<T>);
|
|
59
|
-
private request;
|
|
60
|
-
/** Todo el contenido publicado en una sola petición (se reutiliza durante el build). Sin llave: es público. */
|
|
61
|
-
getContent(): Promise<ContentResponse>;
|
|
62
|
-
getSection<K extends SingleSectionKeys<T>>(key: K): Promise<SectionFields<T, K> | null>;
|
|
63
|
-
getSectionWithSeo<K extends SingleSectionKeys<T>>(key: K): Promise<SingleSection<SectionFields<T, K>> | null>;
|
|
64
|
-
getList<K extends ListSectionKeys<T>>(key: K): Promise<Array<ListItem<SectionFields<T, K>>>>;
|
|
65
|
-
getBySlug<K extends ListSectionKeys<T>>(key: K, slug: string): Promise<ListItem<SectionFields<T, K>> | null>;
|
|
66
|
-
/** Para `getStaticPaths()` en `src/pages/productos/[slug].astro`. */
|
|
67
|
-
getStaticPaths<K extends ListSectionKeys<T>>(key: K): Promise<{
|
|
68
|
-
params: {
|
|
69
|
-
slug: string;
|
|
70
|
-
};
|
|
71
|
-
props: {
|
|
72
|
-
entry: ListItem<InferSectionFields<T["sections"][K]["fields"]>>;
|
|
73
|
-
};
|
|
74
|
-
}[]>;
|
|
75
|
-
getSeo(key: keyof T['sections'] & string, slug?: string): Promise<SeoMetadata>;
|
|
76
|
-
getRedirects(): Promise<Array<{
|
|
77
|
-
from: string;
|
|
78
|
-
to: string;
|
|
79
|
-
}>>;
|
|
80
|
-
}
|
|
81
|
-
declare function createClient<T extends SiteSchemaDefinition>(config: WebZolverClientConfig<T>): WebZolverClient<T>;
|
|
82
|
-
|
|
83
|
-
declare function renderSeoTags(seo: SeoMetadata, defaults: {
|
|
84
|
-
siteName: string;
|
|
85
|
-
baseUrl: string;
|
|
86
|
-
currentPath: string;
|
|
87
|
-
type?: 'website' | 'article';
|
|
88
|
-
}): string;
|
|
89
|
-
declare function generateSitemapXml(baseUrl: string, staticPaths: string[], collectionEntries: Array<{
|
|
90
|
-
routePrefix: string;
|
|
91
|
-
slug: string;
|
|
92
|
-
updatedAt?: string;
|
|
93
|
-
}>): string;
|
|
94
|
-
/** Contenido para `public/_redirects` (Cloudflare Pages / Netlify). */
|
|
95
|
-
declare function generateCloudflareRedirects(options: {
|
|
96
|
-
site: string;
|
|
97
|
-
portalUrl?: string;
|
|
98
|
-
redirects: Array<{
|
|
99
|
-
from: string;
|
|
100
|
-
to: string;
|
|
101
|
-
}>;
|
|
102
|
-
}): string;
|
|
103
|
-
|
|
104
|
-
export { type ContentResponse as C, type ListItem as L, type SectionFields as S, WebZolverClient as W, type ListSectionKeys as a, type SeoMetadata as b, type SingleSection as c, type SingleSectionKeys as d, type WebZolverClientConfig as e, WebZolverError as f, createClient as g, generateCloudflareRedirects, generateSitemapXml, renderSeoTags };
|
|
1
|
+
export { h as generateCloudflareRedirects, i as generateSitemapXml, r as renderSeoTags } from './seo-Dr5q1emj.js';
|
|
2
|
+
import '@webzolver/schema';
|