UNPKG

string-sdk

Version:

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

46 lines (45 loc) 1.58 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.AeoClient = void 0; const cross_fetch_1 = __importDefault(require("cross-fetch")); class AeoClient { constructor(opts) { this.opts = opts; } /** * Returns the AEO score (0-100) for a given URL. */ async getScore(url) { const res = await (0, cross_fetch_1.default)(`${this.opts.baseUrl}/functions/v1/aeo-score`, { method: 'POST', headers: { 'Content-Type': 'application/json', ...(this.opts.anonKey ? { apikey: this.opts.anonKey } : {}), }, body: JSON.stringify({ url }), }); if (!res.ok) throw new Error(`getScore failed: ${await res.text()}`); return res.json(); } /** * Generates SEO / AEO optimized HTML for provided content. */ async optimizeContent(html) { const res = await (0, cross_fetch_1.default)(`${this.opts.baseUrl}/functions/v1/aeo-optimize`, { method: 'POST', headers: { 'Content-Type': 'application/json', ...(this.opts.anonKey ? { apikey: this.opts.anonKey } : {}), }, body: JSON.stringify({ html }), }); if (!res.ok) throw new Error(`optimizeContent failed: ${await res.text()}`); return res.json(); } } exports.AeoClient = AeoClient;