@kwirthmagnify/kwirth-sender-teams 0.1.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/back.js +88 -0
- package/package.json +7 -0
package/back.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/back/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
TeamsSender: () => TeamsSender,
|
|
24
|
+
default: () => index_default
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
var LEVEL_COLOR = {
|
|
28
|
+
error: "FF0000",
|
|
29
|
+
warning: "FFA500",
|
|
30
|
+
info: "0078D4",
|
|
31
|
+
debug: "808080"
|
|
32
|
+
};
|
|
33
|
+
var TeamsSender = class {
|
|
34
|
+
constructor() {
|
|
35
|
+
this.id = "teams";
|
|
36
|
+
this.configs = /* @__PURE__ */ new Map();
|
|
37
|
+
}
|
|
38
|
+
addConfig(config) {
|
|
39
|
+
this.configs.set(config.name, config);
|
|
40
|
+
}
|
|
41
|
+
removeConfig(name) {
|
|
42
|
+
this.configs.delete(name);
|
|
43
|
+
}
|
|
44
|
+
hasConfig(name) {
|
|
45
|
+
return this.configs.has(name);
|
|
46
|
+
}
|
|
47
|
+
getConfigNames() {
|
|
48
|
+
return Array.from(this.configs.keys());
|
|
49
|
+
}
|
|
50
|
+
getConfigSchema() {
|
|
51
|
+
return [
|
|
52
|
+
{ name: "name", label: "Name", type: "text", required: true },
|
|
53
|
+
{ name: "webhookUrl", label: "Webhook URL", type: "text", required: true },
|
|
54
|
+
{ name: "title", label: "Default title", type: "text", required: false }
|
|
55
|
+
];
|
|
56
|
+
}
|
|
57
|
+
async send(configName, message) {
|
|
58
|
+
const cfg = this.configs.get(configName);
|
|
59
|
+
if (!cfg?.webhookUrl) throw new Error(`TeamsSender: config '${configName}' not found or missing webhookUrl`);
|
|
60
|
+
const title = message.subject ?? cfg.title ?? "";
|
|
61
|
+
const color = LEVEL_COLOR[message.level ?? "info"] ?? "0078D4";
|
|
62
|
+
const card = {
|
|
63
|
+
"@type": "MessageCard",
|
|
64
|
+
"@context": "https://schema.org/extensions",
|
|
65
|
+
themeColor: color,
|
|
66
|
+
summary: title || message.body.substring(0, 100),
|
|
67
|
+
sections: [
|
|
68
|
+
...title ? [{ activityTitle: `**${title}**` }] : [],
|
|
69
|
+
{ text: message.body }
|
|
70
|
+
]
|
|
71
|
+
};
|
|
72
|
+
const resp = await fetch(cfg.webhookUrl, {
|
|
73
|
+
method: "POST",
|
|
74
|
+
headers: { "Content-Type": "application/json" },
|
|
75
|
+
body: JSON.stringify(card)
|
|
76
|
+
});
|
|
77
|
+
if (!resp.ok) throw new Error(`TeamsSender: webhook returned ${resp.status} ${resp.statusText}`);
|
|
78
|
+
}
|
|
79
|
+
async startSender(_senders) {
|
|
80
|
+
}
|
|
81
|
+
async stopSender() {
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
var index_default = TeamsSender;
|
|
85
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
86
|
+
0 && (module.exports = {
|
|
87
|
+
TeamsSender
|
|
88
|
+
});
|