alignai
Version:
Server-side Align AI SDK for Node.js
36 lines (35 loc) • 1.5 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AlignAI = void 0;
const connect_1 = require("@connectrpc/connect");
const connect_node_1 = require("@connectrpc/connect-node");
const uuid_1 = require("uuid");
const consts_1 = require("./consts");
const ingestion_connect_1 = require("./buf/ingestion_connect");
class AlignAI {
constructor(projectId, apiKey, apiHost) {
var _a, _b;
const transport = (0, connect_node_1.createConnectTransport)({
httpVersion: "1.1",
baseUrl: apiHost !== null && apiHost !== void 0 ? apiHost : consts_1.defaultApiHost,
});
this.projectId = (_a = projectId !== null && projectId !== void 0 ? projectId : process.env.ALIGNAI_PROJECT_ID) !== null && _a !== void 0 ? _a : '';
this.apiKey = (_b = apiKey !== null && apiKey !== void 0 ? apiKey : process.env.ALIGNAI_API_KEY) !== null && _b !== void 0 ? _b : '';
this.client = (0, connect_1.createPromiseClient)(ingestion_connect_1.IngestionService, transport);
}
async collectEvents(...events) {
await this.client.collectEvents({
requestId: (0, uuid_1.v4)(),
events: events.map((event) => {
const pb = event.toPB();
pb.projectId = this.projectId;
return pb;
}),
}, {
headers: {
Authorization: `Bearer ${this.apiKey}`,
}
});
}
}
exports.AlignAI = AlignAI;