string-sdk
Version:
JavaScript/TypeScript client for the String SmartLink platform (Context OS)
37 lines (36 loc) • 1.43 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CampaignIqClient = void 0;
const cross_fetch_1 = __importDefault(require("cross-fetch"));
class CampaignIqClient {
constructor(opts) {
this.opts = opts;
}
/** Get IQ score for a campaign */
async getCampaignScore(id) {
const res = await (0, cross_fetch_1.default)(`${this.opts.baseUrl}/functions/v1/campaign-iq-score`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
...(this.opts.anonKey ? { apikey: this.opts.anonKey } : {}),
},
body: JSON.stringify({ campaign_id: id }),
});
if (!res.ok)
throw new Error(`getCampaignScore failed: ${await res.text()}`);
return res.json();
}
/** List top campaigns by IQ score */
async listTop(limit = 10) {
const res = await (0, cross_fetch_1.default)(`${this.opts.baseUrl}/rest/v1/campaign_scores?order=score.desc&limit=${limit}`, {
headers: { apikey: this.opts.anonKey || '' },
});
if (!res.ok)
throw new Error(`listTopCampaigns failed: ${await res.text()}`);
return res.json();
}
}
exports.CampaignIqClient = CampaignIqClient;