@h-rig/notifications-plugin 0.0.6-alpha.156 → 0.0.6-alpha.158
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/src/index.d.ts +3 -1
- package/dist/src/index.js +64 -3
- package/dist/src/notifications.d.ts +9 -19
- package/dist/src/notifications.js +2 -2
- package/dist/src/plugin.d.ts +4 -0
- package/dist/src/plugin.js +132 -0
- package/package.json +10 -2
package/dist/src/index.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
export type { RigEvent, NotificationTarget, NotificationConfig, } from "
|
|
1
|
+
export type { RigEvent, NotificationTarget, NotificationConfig, } from "@rig/contracts";
|
|
2
2
|
export { loadNotificationConfig, dispatchEventToTargets, buildTargetPayload, resolveNotifyTimeoutMs, } from "./notifications";
|
|
3
|
+
export { NOTIFICATIONS_PLUGIN_NAME, notificationsPlugin, createNotificationsPlugin, } from "./plugin";
|
|
4
|
+
export { default } from "./plugin";
|
package/dist/src/index.js
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
// @bun
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __returnValue = (v) => v;
|
|
4
|
+
function __exportSetter(name, newValue) {
|
|
5
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
6
|
+
}
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, {
|
|
10
|
+
get: all[name],
|
|
11
|
+
enumerable: true,
|
|
12
|
+
configurable: true,
|
|
13
|
+
set: __exportSetter.bind(all, name)
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
|
|
2
17
|
// packages/notifications-plugin/src/notifications.ts
|
|
18
|
+
var exports_notifications = {};
|
|
19
|
+
__export(exports_notifications, {
|
|
20
|
+
resolveNotifyTimeoutMs: () => resolveNotifyTimeoutMs,
|
|
21
|
+
loadNotificationConfig: () => loadNotificationConfig,
|
|
22
|
+
dispatchEventToTargets: () => dispatchEventToTargets,
|
|
23
|
+
buildTargetPayload: () => buildTargetPayload
|
|
24
|
+
});
|
|
3
25
|
async function loadNotificationConfig(path) {
|
|
4
26
|
try {
|
|
5
27
|
const parsed = await Bun.file(path).json();
|
|
@@ -37,10 +59,10 @@ async function dispatchEventToTargets(event, targets, deps = {}) {
|
|
|
37
59
|
if (response.ok) {
|
|
38
60
|
sent += 1;
|
|
39
61
|
} else {
|
|
40
|
-
console.error(`[
|
|
62
|
+
console.error(`[notify] failed to dispatch event ${event.type} to ${target.id}: ${response.status} ${response.statusText}`);
|
|
41
63
|
}
|
|
42
64
|
} catch (error) {
|
|
43
|
-
console.error(`[
|
|
65
|
+
console.error(`[notify] failed to dispatch event ${event.type} to ${target.id}`, error);
|
|
44
66
|
} finally {
|
|
45
67
|
clearTimeout(timer);
|
|
46
68
|
}
|
|
@@ -66,9 +88,48 @@ function resolveNotifyTimeoutMs() {
|
|
|
66
88
|
const parsed = raw ? Number.parseInt(raw, 10) : NaN;
|
|
67
89
|
return Number.isFinite(parsed) && parsed > 0 ? parsed : 1e4;
|
|
68
90
|
}
|
|
91
|
+
// packages/notifications-plugin/src/plugin.ts
|
|
92
|
+
import { resolve } from "path";
|
|
93
|
+
import { definePlugin } from "@rig/core/config";
|
|
94
|
+
import { defineCapability } from "@rig/core/capability";
|
|
95
|
+
import { NOTIFY_SERVICE_CAPABILITY } from "@rig/contracts";
|
|
96
|
+
var NOTIFICATIONS_PLUGIN_NAME = "@rig/notifications-plugin";
|
|
97
|
+
var NotifyCap = defineCapability(NOTIFY_SERVICE_CAPABILITY);
|
|
98
|
+
function notificationsConfigPath() {
|
|
99
|
+
const root = process.env.RIG_PROJECT_ROOT?.trim() || process.cwd();
|
|
100
|
+
return resolve(root, ".rig", "notifications.json");
|
|
101
|
+
}
|
|
102
|
+
var notificationsPlugin = definePlugin({
|
|
103
|
+
name: NOTIFICATIONS_PLUGIN_NAME,
|
|
104
|
+
version: "0.0.0-alpha.1",
|
|
105
|
+
contributes: {
|
|
106
|
+
capabilities: [
|
|
107
|
+
NotifyCap.provide(async () => {
|
|
108
|
+
const { loadNotificationConfig: loadNotificationConfig2, dispatchEventToTargets: dispatchEventToTargets2 } = await Promise.resolve().then(() => exports_notifications);
|
|
109
|
+
return {
|
|
110
|
+
async notify(event) {
|
|
111
|
+
const config = await loadNotificationConfig2(notificationsConfigPath());
|
|
112
|
+
return dispatchEventToTargets2(event, config.targets);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
}, {
|
|
116
|
+
title: "Notification dispatch",
|
|
117
|
+
description: "Dispatch a Rig lifecycle event to the policy-selected webhook targets configured in .rig/notifications.json."
|
|
118
|
+
})
|
|
119
|
+
]
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
function createNotificationsPlugin() {
|
|
123
|
+
return notificationsPlugin;
|
|
124
|
+
}
|
|
125
|
+
var plugin_default = notificationsPlugin;
|
|
69
126
|
export {
|
|
70
127
|
resolveNotifyTimeoutMs,
|
|
128
|
+
notificationsPlugin,
|
|
71
129
|
loadNotificationConfig,
|
|
72
130
|
dispatchEventToTargets,
|
|
73
|
-
|
|
131
|
+
plugin_default as default,
|
|
132
|
+
createNotificationsPlugin,
|
|
133
|
+
buildTargetPayload,
|
|
134
|
+
NOTIFICATIONS_PLUGIN_NAME
|
|
74
135
|
};
|
|
@@ -1,21 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
type: "slack-webhook" | "linear-webhook" | "notion-webhook" | "generic-webhook";
|
|
11
|
-
url: string;
|
|
12
|
-
enabled?: boolean;
|
|
13
|
-
events?: string[];
|
|
14
|
-
headers?: Record<string, string>;
|
|
15
|
-
};
|
|
16
|
-
export type NotificationConfig = {
|
|
17
|
-
targets: NotificationTarget[];
|
|
18
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* Owned impl of @rig/notifications-plugin: the pure, data-in webhook dispatch
|
|
3
|
+
* primitives. Policy (which targets, which events, config location) lives in the
|
|
4
|
+
* NOTIFY capability factory in `./plugin`. The event/target/config TYPES are the
|
|
5
|
+
* shared seam vocab and live in `@rig/contracts` (re-exported below for the
|
|
6
|
+
* existing `@rig/notifications-plugin/notifications` lib consumers).
|
|
7
|
+
*/
|
|
8
|
+
import type { NotificationConfig, NotificationTarget, RigEvent } from "@rig/contracts";
|
|
9
|
+
export type { NotificationConfig, NotificationTarget, RigEvent } from "@rig/contracts";
|
|
19
10
|
type NotificationFetchResponse = {
|
|
20
11
|
ok: boolean;
|
|
21
12
|
status?: number;
|
|
@@ -28,4 +19,3 @@ export declare function dispatchEventToTargets(event: RigEvent, targets: Notific
|
|
|
28
19
|
}): Promise<number>;
|
|
29
20
|
export declare function buildTargetPayload(target: NotificationTarget, event: RigEvent): Record<string, unknown>;
|
|
30
21
|
export declare function resolveNotifyTimeoutMs(): number;
|
|
31
|
-
export {};
|
|
@@ -37,10 +37,10 @@ async function dispatchEventToTargets(event, targets, deps = {}) {
|
|
|
37
37
|
if (response.ok) {
|
|
38
38
|
sent += 1;
|
|
39
39
|
} else {
|
|
40
|
-
console.error(`[
|
|
40
|
+
console.error(`[notify] failed to dispatch event ${event.type} to ${target.id}: ${response.status} ${response.statusText}`);
|
|
41
41
|
}
|
|
42
42
|
} catch (error) {
|
|
43
|
-
console.error(`[
|
|
43
|
+
console.error(`[notify] failed to dispatch event ${event.type} to ${target.id}`, error);
|
|
44
44
|
} finally {
|
|
45
45
|
clearTimeout(timer);
|
|
46
46
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const NOTIFICATIONS_PLUGIN_NAME = "@rig/notifications-plugin";
|
|
2
|
+
export declare const notificationsPlugin: import("@rig/core/config").RigPlugin;
|
|
3
|
+
export declare function createNotificationsPlugin(): import("@rig/core/config").RigPlugin;
|
|
4
|
+
export default notificationsPlugin;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __returnValue = (v) => v;
|
|
4
|
+
function __exportSetter(name, newValue) {
|
|
5
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
6
|
+
}
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, {
|
|
10
|
+
get: all[name],
|
|
11
|
+
enumerable: true,
|
|
12
|
+
configurable: true,
|
|
13
|
+
set: __exportSetter.bind(all, name)
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// packages/notifications-plugin/src/notifications.ts
|
|
18
|
+
var exports_notifications = {};
|
|
19
|
+
__export(exports_notifications, {
|
|
20
|
+
resolveNotifyTimeoutMs: () => resolveNotifyTimeoutMs,
|
|
21
|
+
loadNotificationConfig: () => loadNotificationConfig,
|
|
22
|
+
dispatchEventToTargets: () => dispatchEventToTargets,
|
|
23
|
+
buildTargetPayload: () => buildTargetPayload
|
|
24
|
+
});
|
|
25
|
+
async function loadNotificationConfig(path) {
|
|
26
|
+
try {
|
|
27
|
+
const parsed = await Bun.file(path).json();
|
|
28
|
+
return {
|
|
29
|
+
targets: (parsed.targets || []).filter((target) => !!target && !!target.id && !!target.url)
|
|
30
|
+
};
|
|
31
|
+
} catch {
|
|
32
|
+
return { targets: [] };
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async function dispatchEventToTargets(event, targets, deps = {}) {
|
|
36
|
+
const fetchFn = deps.fetch ?? globalThis.fetch;
|
|
37
|
+
const timeoutMs = resolveNotifyTimeoutMs();
|
|
38
|
+
let sent = 0;
|
|
39
|
+
for (const target of targets) {
|
|
40
|
+
if (target.enabled === false) {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (target.events && target.events.length > 0 && !target.events.includes(event.type)) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const payload = buildTargetPayload(target, event);
|
|
47
|
+
const controller = new AbortController;
|
|
48
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
49
|
+
try {
|
|
50
|
+
const response = await fetchFn(target.url, {
|
|
51
|
+
method: "POST",
|
|
52
|
+
headers: {
|
|
53
|
+
"Content-Type": "application/json",
|
|
54
|
+
...target.headers || {}
|
|
55
|
+
},
|
|
56
|
+
body: JSON.stringify(payload),
|
|
57
|
+
signal: controller.signal
|
|
58
|
+
});
|
|
59
|
+
if (response.ok) {
|
|
60
|
+
sent += 1;
|
|
61
|
+
} else {
|
|
62
|
+
console.error(`[notify] failed to dispatch event ${event.type} to ${target.id}: ${response.status} ${response.statusText}`);
|
|
63
|
+
}
|
|
64
|
+
} catch (error) {
|
|
65
|
+
console.error(`[notify] failed to dispatch event ${event.type} to ${target.id}`, error);
|
|
66
|
+
} finally {
|
|
67
|
+
clearTimeout(timer);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return sent;
|
|
71
|
+
}
|
|
72
|
+
function buildTargetPayload(target, event) {
|
|
73
|
+
if (target.type === "slack-webhook") {
|
|
74
|
+
return {
|
|
75
|
+
text: `[Rig] ${event.type} ${event.runId ? `(run ${event.runId})` : ""}`.trim(),
|
|
76
|
+
event
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
source: "project-rig",
|
|
81
|
+
target: target.id,
|
|
82
|
+
summary: `${event.type}${event.runId ? `:${event.runId}` : ""}`,
|
|
83
|
+
event
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function resolveNotifyTimeoutMs() {
|
|
87
|
+
const raw = process.env.RIG_NOTIFY_TIMEOUT_MS;
|
|
88
|
+
const parsed = raw ? Number.parseInt(raw, 10) : NaN;
|
|
89
|
+
return Number.isFinite(parsed) && parsed > 0 ? parsed : 1e4;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// packages/notifications-plugin/src/plugin.ts
|
|
93
|
+
import { resolve } from "path";
|
|
94
|
+
import { definePlugin } from "@rig/core/config";
|
|
95
|
+
import { defineCapability } from "@rig/core/capability";
|
|
96
|
+
import { NOTIFY_SERVICE_CAPABILITY } from "@rig/contracts";
|
|
97
|
+
var NOTIFICATIONS_PLUGIN_NAME = "@rig/notifications-plugin";
|
|
98
|
+
var NotifyCap = defineCapability(NOTIFY_SERVICE_CAPABILITY);
|
|
99
|
+
function notificationsConfigPath() {
|
|
100
|
+
const root = process.env.RIG_PROJECT_ROOT?.trim() || process.cwd();
|
|
101
|
+
return resolve(root, ".rig", "notifications.json");
|
|
102
|
+
}
|
|
103
|
+
var notificationsPlugin = definePlugin({
|
|
104
|
+
name: NOTIFICATIONS_PLUGIN_NAME,
|
|
105
|
+
version: "0.0.0-alpha.1",
|
|
106
|
+
contributes: {
|
|
107
|
+
capabilities: [
|
|
108
|
+
NotifyCap.provide(async () => {
|
|
109
|
+
const { loadNotificationConfig: loadNotificationConfig2, dispatchEventToTargets: dispatchEventToTargets2 } = await Promise.resolve().then(() => exports_notifications);
|
|
110
|
+
return {
|
|
111
|
+
async notify(event) {
|
|
112
|
+
const config = await loadNotificationConfig2(notificationsConfigPath());
|
|
113
|
+
return dispatchEventToTargets2(event, config.targets);
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
}, {
|
|
117
|
+
title: "Notification dispatch",
|
|
118
|
+
description: "Dispatch a Rig lifecycle event to the policy-selected webhook targets configured in .rig/notifications.json."
|
|
119
|
+
})
|
|
120
|
+
]
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
function createNotificationsPlugin() {
|
|
124
|
+
return notificationsPlugin;
|
|
125
|
+
}
|
|
126
|
+
var plugin_default = notificationsPlugin;
|
|
127
|
+
export {
|
|
128
|
+
notificationsPlugin,
|
|
129
|
+
plugin_default as default,
|
|
130
|
+
createNotificationsPlugin,
|
|
131
|
+
NOTIFICATIONS_PLUGIN_NAME
|
|
132
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@h-rig/notifications-plugin",
|
|
3
|
-
"version": "0.0.6-alpha.
|
|
3
|
+
"version": "0.0.6-alpha.158",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "First-party notification policy/channels capability plugin for Rig.",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -13,6 +13,10 @@
|
|
|
13
13
|
"types": "./dist/src/index.d.ts",
|
|
14
14
|
"import": "./dist/src/index.js"
|
|
15
15
|
},
|
|
16
|
+
"./plugin": {
|
|
17
|
+
"types": "./dist/src/plugin.d.ts",
|
|
18
|
+
"import": "./dist/src/plugin.js"
|
|
19
|
+
},
|
|
16
20
|
"./notifications": {
|
|
17
21
|
"types": "./dist/src/notifications.d.ts",
|
|
18
22
|
"import": "./dist/src/notifications.js"
|
|
@@ -23,5 +27,9 @@
|
|
|
23
27
|
},
|
|
24
28
|
"main": "./dist/src/index.js",
|
|
25
29
|
"module": "./dist/src/index.js",
|
|
26
|
-
"types": "./dist/src/index.d.ts"
|
|
30
|
+
"types": "./dist/src/index.d.ts",
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@rig/contracts": "npm:@h-rig/contracts@0.0.6-alpha.158",
|
|
33
|
+
"@rig/core": "npm:@h-rig/core@0.0.6-alpha.158"
|
|
34
|
+
}
|
|
27
35
|
}
|