-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
134 lines (119 loc) · 3.94 KB
/
Copy pathindex.ts
File metadata and controls
134 lines (119 loc) · 3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/**
* Platform SEO REST (`/api/seo/*`).
* Genetic tag: sdk.seo.gen1
*/
import { HTTPClient } from '../client/http-client';
export interface SeoMetaTags {
title?: string;
description?: string;
canonical?: string;
robots?: string;
'og:title'?: string;
'og:description'?: string;
'og:image'?: string;
'og:url'?: string;
'og:type'?: string;
'og:locale'?: string;
'twitter:card'?: string;
'twitter:title'?: string;
'twitter:description'?: string;
'twitter:image'?: string;
structured_data?: Record<string, unknown>;
hreflang?: Array<{ hreflang: string; href: string }>;
}
export interface SeoMetaOptions {
locale?: string;
signal?: AbortSignal;
}
export interface SeoCacheClearResult {
success: boolean;
static_invalidated?: number;
meta_invalidated?: number;
registry_version?: string;
indexnow?: Record<string, unknown>;
}
export interface SeoHealthCheck {
registry_version: string;
indexable_path_count: number;
funnel_paths: string[];
}
/** Hosting funnel paths served by platform marketing SEO cluster. */
export const HOSTING_FUNNEL_PATHS = ['/', '/host-site', '/demo', '/for-developers'] as const;
export type HostingFunnelPath = (typeof HOSTING_FUNNEL_PATHS)[number];
export class AgentSeo {
constructor(private client: HTTPClient) {}
/** GET /api/seo/meta?path=&locale= */
async getMeta(path: string, options: SeoMetaOptions = {}): Promise<SeoMetaTags> {
const params: Record<string, string> = { path };
if (options.locale) params.locale = options.locale;
const res = await this.client.get<SeoMetaTags>('/seo/meta', params, {
signal: options.signal,
skipAuthStateCheck: true,
});
return res.data;
}
/** Batch meta fetch for multiple paths (parallel). */
async getMetaBatch(
paths: readonly string[],
options: SeoMetaOptions = {},
): Promise<Record<string, SeoMetaTags>> {
const out: Record<string, SeoMetaTags> = {};
await Promise.all(
paths.map(async (p) => {
out[p] = await this.getMeta(p, options);
}),
);
return out;
}
/** GET /api/seo/robots.txt */
async getRobotsTxt(signal?: AbortSignal): Promise<string> {
const res = await this.client.get<string>('/seo/robots.txt', undefined, {
signal,
skipAuthStateCheck: true,
});
return String(res.data ?? '');
}
/** GET /api/seo/sitemap.xml */
async getSitemapXml(signal?: AbortSignal): Promise<string> {
const res = await this.client.get<string>('/seo/sitemap.xml', undefined, {
signal,
skipAuthStateCheck: true,
});
return String(res.data ?? '');
}
/** POST /api/seo/cache/clear */
async clearCache(signal?: AbortSignal): Promise<SeoCacheClearResult> {
const res = await this.client.post<SeoCacheClearResult>(
'/seo/cache/clear',
{},
{ signal },
);
return res.data;
}
/** Read registry version from a meta response header (lightweight probe). */
async getRegistryVersion(signal?: AbortSignal): Promise<string | null> {
const res = await this.client.get<SeoMetaTags>(
'/seo/meta',
{ path: '/' },
{ signal, skipAuthStateCheck: true },
);
const raw = res.headers?.['x-seo-registry-version'];
return typeof raw === 'string' ? raw : null;
}
/** Lightweight health snapshot for ops dashboards. */
async healthCheck(signal?: AbortSignal): Promise<SeoHealthCheck> {
const registry_version = (await this.getRegistryVersion(signal)) ?? 'unknown';
const funnel = await this.getMetaBatch(HOSTING_FUNNEL_PATHS, { signal });
return {
registry_version,
indexable_path_count: Object.keys(funnel).length,
funnel_paths: HOSTING_FUNNEL_PATHS.slice(),
};
}
/** Convenience: fetch meta for each hosting funnel path. */
async getHostingFunnelCopy(locale?: string): Promise<Partial<Record<HostingFunnelPath, SeoMetaTags>>> {
return this.getMetaBatch(HOSTING_FUNNEL_PATHS, { locale }) as Promise<
Partial<Record<HostingFunnelPath, SeoMetaTags>>
>;
}
}