UNPKG

string-sdk

Version:

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

40 lines (39 loc) 1.4 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SignalsClient = void 0; const cross_fetch_1 = __importDefault(require("cross-fetch")); class SignalsClient { constructor(opts) { this.opts = opts; } /** * Ingests a signal event (click, view, conversion, etc.). */ async trackEvent(payload) { const res = await (0, cross_fetch_1.default)(`${this.opts.baseUrl}/api/signals/track-event`, { method: 'POST', headers: { 'Content-Type': 'application/json', ...(this.opts.anonKey ? { apikey: this.opts.anonKey } : {}), }, body: JSON.stringify(payload), }); if (!res.ok) throw new Error(`trackEvent failed: ${await res.text()}`); } /** * Query raw signal events using Supabase REST filters. */ async queryEvents(filter) { const res = await (0, cross_fetch_1.default)(`${this.opts.baseUrl}/rest/v1/signals?${filter}`, { headers: { apikey: this.opts.anonKey || '' }, }); if (!res.ok) throw new Error(`queryEvents failed: ${await res.text()}`); return res.json(); } } exports.SignalsClient = SignalsClient;