'use strict'; const node = require('ofetch/node'); const signature = require('@slay-pics/signature'); var __defProp = Object.defineProperty; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __publicField = (obj, key, value) => { __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); return value; }; class SlayQIngestRPCDriver { constructor(options = {}) { __publicField(this, "_secret"); __publicField(this, "_endpointUrl"); const secret = options.secret ?? process.env.SLAY_Q_WORKER_SECRET; if (!secret) { throw new Error("Missing required secret."); } const endpointUrl = options.endpointUrl ?? process.env.SLAY_Q_INGEST_ENDPOINT; if (!endpointUrl) { throw new Error("Missing endpoint url."); } this._secret = secret; this._endpointUrl = endpointUrl; } async sendRequest(task, data) { try { const sig = signature.calcSig(data, this._secret); await node.ofetch(this._endpointUrl + "/" + task, { method: "POST", headers: { "X-SlayQ-Signature": sig }, body: data }); return null; } catch (e) { console.error(e); return { message: e.message ?? "Unknown Error" }; } } async addJob(jobDef) { return await this.sendRequest("add-worker-job", jobDef); } async triggerWaiting(event, match, matchVal) { return await this.sendRequest("trigger-waiting-workers", { event, match, matchVal: `${matchVal}` }); } async triggerWaitingInvokers(jobKey, result) { return await this.sendRequest("trigger-waiting-invoker", { jobKey, result: result ?? null }); } async waitForEvent(jobKey, event, matchKey, matchValue, stepName, expiresAt) { return await this.sendRequest("wait-for-worker-event", { jobKey, event, matchKey, matchValue: `${matchValue}`, stepName, expiresAt: expiresAt.toISOString() }); } async waitForInvocation(invokerJobKey, targetJobKey, stepName) { return await this.sendRequest("wait-for-invocation", { invokerJobKey, targetJobKey, stepName }); } async cancelPendingTasks(event, matchKey, matchVal) { return await this.sendRequest("cancel-pending-tasks", { event, matchKey, matchVal: `${matchVal}` }); } async updateStepCache(jobKey, stepCache) { return await this.sendRequest("update-step-cache", { jobKey, stepCache }); } } exports.SlayQIngestRPCDriver = SlayQIngestRPCDriver;