UNPKG

string-sdk

Version:

JavaScript/TypeScript client for the String SmartLink platform (Context OS)

42 lines (41 loc) 1.59 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.AgentSeoClient = void 0; const cross_fetch_1 = __importDefault(require("cross-fetch")); class AgentSeoClient { constructor(opts) { this.opts = opts; } /** Crawl a URL with Context OS crawler and return structured data */ async crawlUrl(url) { const res = await (0, cross_fetch_1.default)(`${this.opts.baseUrl}/functions/v1/seo-crawl`, { method: 'POST', headers: { 'Content-Type': 'application/json', ...(this.opts.anonKey ? { apikey: this.opts.anonKey } : {}), }, body: JSON.stringify({ url }), }); if (!res.ok) throw new Error(`crawlUrl failed: ${await res.text()}`); return res.json(); } /** Get SEO recommendations for the given URL */ async getRecommendations(url) { const res = await (0, cross_fetch_1.default)(`${this.opts.baseUrl}/functions/v1/seo-recommend`, { method: 'POST', headers: { 'Content-Type': 'application/json', ...(this.opts.anonKey ? { apikey: this.opts.anonKey } : {}), }, body: JSON.stringify({ url }), }); if (!res.ok) throw new Error(`getRecommendations failed: ${await res.text()}`); return res.json(); } } exports.AgentSeoClient = AgentSeoClient;