@kwirthmagnify/kwirth-sender-teams 0.1.2 → 0.1.3

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/build.mjs ADDED
@@ -0,0 +1,28 @@
1
+ import esbuild from 'esbuild'
2
+ import fs from 'fs'
3
+ import path from 'path'
4
+
5
+ fs.mkdirSync('dist', { recursive: true })
6
+
7
+ await esbuild.build({
8
+ entryPoints: ['src/back/index.ts'],
9
+ bundle: true,
10
+ format: 'cjs',
11
+ platform: 'node',
12
+ target: 'node20',
13
+ outfile: 'dist/back.js',
14
+ loader: { '.ts': 'ts' },
15
+ minify: false,
16
+ })
17
+ console.log('Built dist/back.js')
18
+
19
+ const meta = JSON.parse(fs.readFileSync('package.json', 'utf-8'))
20
+ const distMeta = {
21
+ id: meta.id,
22
+ name: meta.name,
23
+ displayName: meta.displayName,
24
+ version: meta.version,
25
+ description: meta.description,
26
+ }
27
+ fs.writeFileSync(path.join('dist', 'package.json'), JSON.stringify(distMeta, null, 2))
28
+ console.log('Wrote dist/package.json')
@@ -50,7 +50,7 @@ var TeamsSender = class {
50
50
  getConfigSchema() {
51
51
  return [
52
52
  { name: "name", label: "Name", type: "text", required: true },
53
- { name: "webhookUrl", label: "Webhook URL", type: "text", required: true },
53
+ { name: "webhookUrl", label: "Webhook URL", type: "text", required: true, common: true },
54
54
  { name: "title", label: "Default title", type: "text", required: false }
55
55
  ];
56
56
  }
@@ -0,0 +1,7 @@
1
+ {
2
+ "id": "teams",
3
+ "name": "@kwirthmagnify/kwirth-sender-teams",
4
+ "displayName": "MS Teams Sender",
5
+ "version": "0.1.2",
6
+ "description": "MS Teams sender for Kwirth — sends messages via incoming webhook"
7
+ }
package/package.json CHANGED
@@ -1,7 +1,21 @@
1
- {
2
- "id": "teams",
3
- "name": "@kwirthmagnify/kwirth-sender-teams",
4
- "displayName": "MS Teams Sender",
5
- "version": "0.1.2",
6
- "description": "MS Teams sender for Kwirth — sends messages via incoming webhook"
7
- }
1
+ {
2
+ "id": "teams",
3
+ "name": "@kwirthmagnify/kwirth-sender-teams",
4
+ "publisher": "@kwirthmagnify",
5
+ "version": "0.1.3",
6
+ "displayName": "MS Teams Sender",
7
+ "description": "MS Teams sender for Kwirth — sends messages via incoming webhook",
8
+ "type": "module",
9
+ "scripts": {
10
+ "build": "node build.mjs",
11
+ "watch": "node watch.mjs"
12
+ },
13
+ "dependencies": {
14
+ "@kwirthmagnify/kwirth-common-back": "^0.5.11"
15
+ },
16
+ "devDependencies": {
17
+ "@types/node": "^20.12.13",
18
+ "esbuild": "^0.27.2",
19
+ "typescript": "^5.4.0"
20
+ }
21
+ }
@@ -0,0 +1,75 @@
1
+ import { ISender, ISenderAccess, ISenderConfig, ISenderFieldDef, ISenderMessage } from '@kwirthmagnify/kwirth-common-back'
2
+
3
+ export interface ITeamsSenderConfig extends ISenderConfig {
4
+ name: string
5
+ webhookUrl: string
6
+ title?: string
7
+ }
8
+
9
+ const LEVEL_COLOR: Record<string, string> = {
10
+ error: 'FF0000',
11
+ warning: 'FFA500',
12
+ info: '0078D4',
13
+ debug: '808080',
14
+ }
15
+
16
+ export class TeamsSender implements ISender {
17
+ readonly id = 'teams'
18
+ private configs = new Map<string, ITeamsSenderConfig>()
19
+
20
+ addConfig(config: ISenderConfig): void {
21
+ this.configs.set(config.name, config as ITeamsSenderConfig)
22
+ }
23
+
24
+ removeConfig(name: string): void {
25
+ this.configs.delete(name)
26
+ }
27
+
28
+ hasConfig(name: string): boolean {
29
+ return this.configs.has(name)
30
+ }
31
+
32
+ getConfigNames(): string[] {
33
+ return Array.from(this.configs.keys())
34
+ }
35
+
36
+ getConfigSchema(): ISenderFieldDef[] {
37
+ return [
38
+ { name: 'name', label: 'Name', type: 'text', required: true },
39
+ { name: 'webhookUrl', label: 'Webhook URL', type: 'text', required: true, common: true },
40
+ { name: 'title', label: 'Default title', type: 'text', required: false },
41
+ ]
42
+ }
43
+
44
+ async send(configName: string, message: ISenderMessage): Promise<void> {
45
+ const cfg = this.configs.get(configName)
46
+ if (!cfg?.webhookUrl) throw new Error(`TeamsSender: config '${configName}' not found or missing webhookUrl`)
47
+
48
+ const title = message.subject ?? cfg.title ?? ''
49
+ const color = LEVEL_COLOR[message.level ?? 'info'] ?? '0078D4'
50
+
51
+ const card: Record<string, unknown> = {
52
+ '@type': 'MessageCard',
53
+ '@context': 'https://schema.org/extensions',
54
+ themeColor: color,
55
+ summary: title || message.body.substring(0, 100),
56
+ sections: [
57
+ ...(title ? [{ activityTitle: `**${title}**` }] : []),
58
+ { text: message.body },
59
+ ],
60
+ }
61
+
62
+ const resp = await fetch(cfg.webhookUrl, {
63
+ method: 'POST',
64
+ headers: { 'Content-Type': 'application/json' },
65
+ body: JSON.stringify(card),
66
+ })
67
+
68
+ if (!resp.ok) throw new Error(`TeamsSender: webhook returned ${resp.status} ${resp.statusText}`)
69
+ }
70
+
71
+ async startSender(_senders: ISenderAccess): Promise<void> {}
72
+ async stopSender(): Promise<void> {}
73
+ }
74
+
75
+ export default TeamsSender
package/tsconfig.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "strict": true,
7
+ "lib": ["ES2020"],
8
+ "types": ["node"],
9
+ "skipLibCheck": true,
10
+ "esModuleInterop": true
11
+ },
12
+ "include": ["src"]
13
+ }
package/watch.mjs ADDED
@@ -0,0 +1,68 @@
1
+ import esbuild from 'esbuild'
2
+ import fs from 'fs'
3
+ import path from 'path'
4
+
5
+ const kwirthGlobalsPlugin = {
6
+ name: 'kwirth-globals',
7
+ setup(build) {
8
+ const globals = {
9
+ 'react': 'window.__kwirth__.React',
10
+ '@mui/material': 'window.__kwirth__.MUI.material',
11
+ '@mui/icons-material': 'window.__kwirth__.MUI.icons',
12
+ '@kwirthmagnify/kwirth-common': 'window.__kwirth__.kwirthCommon',
13
+ }
14
+ for (const pkg of Object.keys(globals)) {
15
+ build.onResolve({ filter: new RegExp(`^${pkg.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}$`) }, () => ({ path: pkg, namespace: 'kwirth-globals' }))
16
+ }
17
+ build.onLoad({ filter: /.*/, namespace: 'kwirth-globals' }, (args) => ({
18
+ contents: `module.exports = ${globals[args.path]}`, loader: 'js',
19
+ }))
20
+ },
21
+ }
22
+
23
+ const notifyPlugin = (label) => ({
24
+ name: `notify-${label}`,
25
+ setup(build) {
26
+ build.onEnd(result => {
27
+ const t = new Date().toLocaleTimeString()
28
+ if (result.errors.length) {
29
+ console.error(`[${t}] ${label} FAILED: ${result.errors.map(e => e.text).join('; ')}`)
30
+ } else {
31
+ console.log(`[${t}] ${label} OK`)
32
+ }
33
+ })
34
+ },
35
+ })
36
+
37
+ fs.mkdirSync('dist', { recursive: true })
38
+ const meta = JSON.parse(fs.readFileSync('package.json', 'utf-8'))
39
+ fs.writeFileSync(path.join('dist', 'package.json'), JSON.stringify({ id: meta.id, name: meta.name, displayName: meta.displayName, version: meta.version, description: meta.description }, null, 2))
40
+
41
+ const backCtx = await esbuild.context({
42
+ entryPoints: ['src/back/index.ts'],
43
+ bundle: true,
44
+ format: 'cjs',
45
+ platform: 'node',
46
+ target: 'node20',
47
+ outfile: 'dist/back.js',
48
+ loader: { '.ts': 'ts' },
49
+ minify: false,
50
+ plugins: [notifyPlugin('back')],
51
+ })
52
+
53
+ const frontCtx = await esbuild.context({
54
+ entryPoints: ['src/front/index.tsx'],
55
+ bundle: true,
56
+ format: 'iife',
57
+ outfile: 'dist/front.js',
58
+ plugins: [kwirthGlobalsPlugin, notifyPlugin('front')],
59
+ loader: { '.tsx': 'tsx', '.ts': 'ts' },
60
+ jsx: 'transform',
61
+ jsxFactory: 'React.createElement',
62
+ jsxFragment: 'React.Fragment',
63
+ target: 'es2020',
64
+ minify: false,
65
+ })
66
+
67
+ await Promise.all([backCtx.watch(), frontCtx.watch()])
68
+ console.log('[watch] Watching src/ — back.js and front.js rebuild on every change.')