@almadar/integrations 2.23.0 → 2.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{contracts-CLTh6gjT.d.ts → contracts-Dv9PM_Cz.d.ts} +17 -1
- package/dist/index.d.ts +13 -2
- package/dist/index.js +77 -1
- package/dist/index.js.map +1 -1
- package/dist/runtime/index.d.ts +1 -1
- package/dist/runtime/index.js +82 -0
- package/dist/runtime/index.js.map +1 -1
- package/package.json +2 -2
package/dist/runtime/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { I as IntegrationFactory } from '../factory-DTdVeyAi.js';
|
|
2
2
|
import { e as IntegrationParams } from '../BaseIntegration-MA-b4fh8.js';
|
|
3
|
-
import { j as IntegrationName, h as IntegrationActionName, i as IntegrationContracts } from '../contracts-
|
|
3
|
+
import { j as IntegrationName, h as IntegrationActionName, i as IntegrationContracts } from '../contracts-Dv9PM_Cz.js';
|
|
4
4
|
import '@almadar/core';
|
|
5
5
|
|
|
6
6
|
/**
|
package/dist/runtime/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import { google } from 'googleapis';
|
|
|
5
5
|
import twilio from 'twilio';
|
|
6
6
|
import sgMail from '@sendgrid/mail';
|
|
7
7
|
import { Resend } from 'resend';
|
|
8
|
+
import { createHmac } from 'crypto';
|
|
8
9
|
import { getAvailableProvider, LLMClient, EmbeddingClient } from '@almadar/llm';
|
|
9
10
|
import { z } from 'zod';
|
|
10
11
|
import { execSync, spawn } from 'child_process';
|
|
@@ -856,6 +857,81 @@ var EmailIntegration = class extends BaseIntegration {
|
|
|
856
857
|
}
|
|
857
858
|
};
|
|
858
859
|
registerIntegration("email", EmailIntegration);
|
|
860
|
+
var WebhookIntegration = class extends BaseIntegration {
|
|
861
|
+
constructor(config) {
|
|
862
|
+
super(config);
|
|
863
|
+
this.signingSecret = config.env.WEBHOOK_SIGNING_SECRET || "";
|
|
864
|
+
this.timeoutMs = Number(config.env.WEBHOOK_TIMEOUT_MS) || 1e4;
|
|
865
|
+
this.logger.info("Webhook integration initialized");
|
|
866
|
+
}
|
|
867
|
+
async execute(action, params) {
|
|
868
|
+
const validation = this.validateParams(action, params);
|
|
869
|
+
if (!validation.valid) {
|
|
870
|
+
return {
|
|
871
|
+
success: false,
|
|
872
|
+
error: {
|
|
873
|
+
name: "IntegrationError",
|
|
874
|
+
message: "Validation failed",
|
|
875
|
+
code: "VALIDATION_ERROR",
|
|
876
|
+
details: validation.errors
|
|
877
|
+
},
|
|
878
|
+
metadata: this.createMetadata(action, 0)
|
|
879
|
+
};
|
|
880
|
+
}
|
|
881
|
+
const startTime = Date.now();
|
|
882
|
+
let retries = 0;
|
|
883
|
+
try {
|
|
884
|
+
let data;
|
|
885
|
+
switch (action) {
|
|
886
|
+
case "send":
|
|
887
|
+
data = await this.executeWithRetry(() => this.send(params));
|
|
888
|
+
break;
|
|
889
|
+
default:
|
|
890
|
+
throw new Error(`Unknown action: ${action}`);
|
|
891
|
+
}
|
|
892
|
+
return {
|
|
893
|
+
success: true,
|
|
894
|
+
data,
|
|
895
|
+
metadata: this.createMetadata(action, Date.now() - startTime, retries)
|
|
896
|
+
};
|
|
897
|
+
} catch (error) {
|
|
898
|
+
return this.handleError(action, error);
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
async send(params) {
|
|
902
|
+
const { url, event, payload, secret } = params;
|
|
903
|
+
const body = JSON.stringify({
|
|
904
|
+
event,
|
|
905
|
+
payload: payload ?? {},
|
|
906
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
907
|
+
});
|
|
908
|
+
const headers = {
|
|
909
|
+
"Content-Type": "application/json",
|
|
910
|
+
"X-Almadar-Event": event
|
|
911
|
+
};
|
|
912
|
+
const signingSecret = secret || this.signingSecret;
|
|
913
|
+
if (signingSecret) {
|
|
914
|
+
headers["X-Almadar-Signature"] = "sha256=" + createHmac("sha256", signingSecret).update(body).digest("hex");
|
|
915
|
+
}
|
|
916
|
+
this.logger.debug("Sending webhook", { url: String(url), event: String(event) });
|
|
917
|
+
const startTime = Date.now();
|
|
918
|
+
const response = await fetch(url, {
|
|
919
|
+
method: "POST",
|
|
920
|
+
headers,
|
|
921
|
+
body,
|
|
922
|
+
signal: AbortSignal.timeout(this.timeoutMs)
|
|
923
|
+
});
|
|
924
|
+
if (response.status >= 500) {
|
|
925
|
+
throw new Error(`Webhook endpoint returned ${response.status}`);
|
|
926
|
+
}
|
|
927
|
+
return {
|
|
928
|
+
status: response.status,
|
|
929
|
+
ok: response.ok,
|
|
930
|
+
durationMs: Date.now() - startTime
|
|
931
|
+
};
|
|
932
|
+
}
|
|
933
|
+
};
|
|
934
|
+
registerIntegration("webhook", WebhookIntegration);
|
|
859
935
|
var LLMIntegration = class extends BaseIntegration {
|
|
860
936
|
constructor(config) {
|
|
861
937
|
super(config);
|
|
@@ -3713,6 +3789,12 @@ var RuntimeIntegrationManager = class {
|
|
|
3713
3789
|
}
|
|
3714
3790
|
});
|
|
3715
3791
|
}
|
|
3792
|
+
this.factory.configure("webhook", {
|
|
3793
|
+
env: {
|
|
3794
|
+
WEBHOOK_SIGNING_SECRET: env.WEBHOOK_SIGNING_SECRET || "",
|
|
3795
|
+
WEBHOOK_TIMEOUT_MS: env.WEBHOOK_TIMEOUT_MS || ""
|
|
3796
|
+
}
|
|
3797
|
+
});
|
|
3716
3798
|
const llmEnv = {};
|
|
3717
3799
|
for (const k of ["ANTHROPIC_API_KEY", "OPENAI_API_KEY", "DEEPSEEK_API_KEY", "KIMI_API_KEY", "OPEN_ROUTER_API_KEY"]) {
|
|
3718
3800
|
if (env[k]) llmEnv[k] = env[k];
|