@kwirthmagnify/kwirth-sender-timed 0.1.6 → 0.1.7

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.
Files changed (3) hide show
  1. package/back.js +29 -0
  2. package/front.js +5 -1
  3. package/package.json +1 -1
package/back.js CHANGED
@@ -115,9 +115,24 @@ function tzOffset(tz) {
115
115
  return "";
116
116
  }
117
117
  }
118
+ function parseMinutes(hhmm) {
119
+ const [h, m] = hhmm.split(":").map(Number);
120
+ return (h ?? 0) * 60 + (m ?? 0);
121
+ }
122
+ function currentContext(timezone) {
123
+ const now = timezone ? new Date((/* @__PURE__ */ new Date()).toLocaleString("en-US", { timeZone: timezone })) : /* @__PURE__ */ new Date();
124
+ return { minutes: now.getHours() * 60 + now.getMinutes(), day: now.getDay() };
125
+ }
126
+ function matchesWindow(rule, minutes, day) {
127
+ if (rule.days && rule.days.length > 0 && !rule.days.includes(day)) return false;
128
+ const from = parseMinutes(rule.from);
129
+ const to = parseMinutes(rule.to);
130
+ return from <= to ? minutes >= from && minutes < to : minutes >= from || minutes < to;
131
+ }
118
132
  var TimedSender = class {
119
133
  constructor() {
120
134
  this.id = "timed";
135
+ this.senderType = "filter";
121
136
  this.configs = /* @__PURE__ */ new Map();
122
137
  }
123
138
  addConfig(config) {
@@ -134,8 +149,22 @@ var TimedSender = class {
134
149
  getConfigNames() {
135
150
  return Array.from(this.configs.keys());
136
151
  }
152
+ getNodeMeta() {
153
+ return { label: "Timed filter", icon: "AccessTime", description: "Routes or drops messages based on time-of-day windows and day-of-week rules." };
154
+ }
137
155
  async send(_configName, _message) {
138
156
  }
157
+ async evalFilter(configName, _message, forward) {
158
+ const config = this.configs.get(configName);
159
+ if (!config) return;
160
+ const { minutes, day } = currentContext(config.timezone);
161
+ for (const rule of config.rules ?? []) {
162
+ if (!matchesWindow(rule, minutes, day)) continue;
163
+ if (rule.action === "send") await forward();
164
+ return;
165
+ }
166
+ if ((config.defaultAction ?? "drop") === "send") await forward();
167
+ }
139
168
  getConfigSchema() {
140
169
  return [
141
170
  { name: "name", label: "Name", required: true },
package/front.js CHANGED
@@ -363,5 +363,9 @@
363
363
 
364
364
  // src/front/index.tsx
365
365
  window.__kwirth_senders__ = window.__kwirth_senders__ ?? {};
366
- window.__kwirth_senders__["timed"] = TimedConfigDialog_default;
366
+ window.__kwirth_senders__["timed"] = {
367
+ ConfigDialog: TimedConfigDialog_default,
368
+ nodeLabel: "Timed filter",
369
+ nodeDescription: "Routes or drops messages based on time-of-day windows and day-of-week rules."
370
+ };
367
371
  })();
package/package.json CHANGED
@@ -2,6 +2,6 @@
2
2
  "id": "timed",
3
3
  "name": "@kwirthmagnify/kwirth-sender-timed",
4
4
  "displayName": "Timed Sender",
5
- "version": "0.1.6",
5
+ "version": "0.1.7",
6
6
  "description": "Timed sender for Kwirth — routes or drops messages based on time-of-day windows and day-of-week rules"
7
7
  }