@narumitw/pi-notify 0.2.0 → 0.4.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.
@@ -0,0 +1,129 @@
1
+ import { safeText } from "./metadata.js";
2
+ import type { Destination } from "./provider.js";
3
+
4
+ export const providerLabels: Record<Destination["provider"], string> = {
5
+ telegram: "Telegram",
6
+ gotify: "Gotify",
7
+ slack: "Slack",
8
+ ntfy: "ntfy",
9
+ pushover: "Pushover",
10
+ discord: "Discord",
11
+ bark: "Bark",
12
+ webhook: "Generic webhook",
13
+ line: "LINE",
14
+ teams: "Microsoft Teams",
15
+ };
16
+ export const providerLabel = (destination: Destination) => providerLabels[destination.provider];
17
+ export const credentialLabels: Record<Destination["provider"], string> = {
18
+ telegram: "bot token",
19
+ gotify: "application token",
20
+ slack: "webhook URL",
21
+ ntfy: "access token (empty for anonymous)",
22
+ pushover: "application token",
23
+ discord: "webhook URL",
24
+ bark: "device key",
25
+ webhook: "webhook URL",
26
+ line: "channel access token",
27
+ teams: "webhook URL",
28
+ };
29
+ export function displayServerUrl(raw: string): string {
30
+ try {
31
+ const url = new URL(raw);
32
+ // Never include URL credentials, query parameters, or fragments in descriptions.
33
+ return safeText(`${url.protocol}//${url.host}${url.pathname}`);
34
+ } catch {
35
+ return "not configured";
36
+ }
37
+ }
38
+ export function destinationDescription(destination: Destination): string {
39
+ switch (destination.provider) {
40
+ case "telegram":
41
+ return `Telegram · ${safeText(destination.chatId)} · token configured`;
42
+ case "gotify":
43
+ return `Gotify · ${displayServerUrl(destination.serverUrl)} · token configured`;
44
+ case "slack":
45
+ return "Slack · webhook configured";
46
+ case "line":
47
+ return "LINE · channel access token and recipient configured";
48
+ case "teams":
49
+ return "Microsoft Teams · workflow webhook configured";
50
+ case "pushover":
51
+ return "Pushover · application token and user key configured";
52
+ case "discord":
53
+ return "Discord · webhook configured";
54
+ case "bark":
55
+ return `Bark · ${displayServerUrl(destination.serverUrl)} · device key configured`;
56
+ case "webhook":
57
+ return `Generic webhook · URL configured · ${destination.bearerToken ? "Bearer token configured" : "no authentication"}`;
58
+ case "ntfy":
59
+ return `ntfy · ${displayServerUrl(destination.serverUrl)} · ${destination.accessToken ? "token configured" : "anonymous"}`;
60
+ }
61
+ }
62
+ export function destinationLines(destination: Destination): string[] {
63
+ const label = `Label: ${safeText(destination.label)}`;
64
+ switch (destination.provider) {
65
+ case "telegram":
66
+ return [
67
+ label,
68
+ `Chat: ${safeText(destination.chatId)}`,
69
+ `Topic: ${destination.messageThreadId ?? "none"}`,
70
+ "Bot token: configured (hidden)",
71
+ ];
72
+ case "gotify":
73
+ return [
74
+ label,
75
+ `Server: ${displayServerUrl(destination.serverUrl)}`,
76
+ `Priority: ${destination.priority ?? "server default"}`,
77
+ "Application token: configured (hidden)",
78
+ ];
79
+ case "slack":
80
+ return [label, "Channel: fixed by webhook installation", "Webhook URL: configured (hidden)"];
81
+ case "line":
82
+ return [
83
+ label,
84
+ "Channel access token: configured (hidden)",
85
+ "Recipient ID: configured (hidden)",
86
+ "Messaging API only, not LINE Notify. Account quotas and recipient eligibility apply.",
87
+ ];
88
+ case "teams":
89
+ return [
90
+ label,
91
+ "Webhook URL: configured (hidden)",
92
+ "Target: fixed by the owning workflow",
93
+ "Anyone authentication only. HTTP acceptance does not confirm a Teams post.",
94
+ ];
95
+ case "pushover":
96
+ return [
97
+ label,
98
+ "Application token: configured (hidden)",
99
+ "User key: configured (hidden)",
100
+ "Priority: normal (0); emergency mode is not supported.",
101
+ ];
102
+ case "discord":
103
+ return [label, "Webhook URL: configured (hidden)", "Mentions and link embeds are disabled."];
104
+ case "bark":
105
+ return [
106
+ label,
107
+ `Server: ${displayServerUrl(destination.serverUrl)}`,
108
+ "Device key: configured (hidden)",
109
+ "Use HTTPS. HTTP sends credentials and metadata without encryption.",
110
+ ];
111
+ case "webhook":
112
+ return [
113
+ label,
114
+ "Webhook URL: configured (hidden)",
115
+ `Bearer token: ${destination.bearerToken ? "configured (hidden)" : "none"}`,
116
+ "User endpoints can reach the Pi host network. Use HTTPS; HTTP is unencrypted.",
117
+ ];
118
+ case "ntfy":
119
+ return [
120
+ label,
121
+ `Server: ${displayServerUrl(destination.serverUrl)}`,
122
+ `Topic: ${safeText(destination.topic)}`,
123
+ `Priority: ${destination.priority ?? "server default"}`,
124
+ `Access token: ${destination.accessToken ? "configured (hidden)" : "none (anonymous)"}`,
125
+ "A topic name is not access control. Configure server authentication and topic permissions.",
126
+ "Use HTTPS. HTTP sends credentials and metadata without encryption.",
127
+ ];
128
+ }
129
+ }