feedkeeper 0.39.0 → 0.41.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "feedkeeper",
3
- "version": "0.39.0",
3
+ "version": "0.41.0",
4
4
  "description": "A lightweight, self-hosted RSS reader and remote MCP server for your news, blogs, and AI workflows.",
5
5
  "keywords": [
6
6
  "rss",
@@ -0,0 +1,33 @@
1
+ ALTER TABLE push_devices RENAME TO push_devices_web;
2
+ DROP INDEX idx_push_devices_user;
3
+
4
+ CREATE TABLE push_devices (
5
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
6
+ user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
7
+ endpoint TEXT UNIQUE,
8
+ p256dh TEXT,
9
+ auth TEXT,
10
+ created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')),
11
+ native_device_id INTEGER UNIQUE REFERENCES personal_access_tokens(id) ON DELETE CASCADE,
12
+ native_token TEXT,
13
+ native_environment TEXT CHECK(native_environment IN ('development', 'production')),
14
+ native_language TEXT,
15
+ native_feeds INTEGER NOT NULL DEFAULT 0,
16
+ native_editions INTEGER NOT NULL DEFAULT 0,
17
+ CHECK (
18
+ (endpoint IS NOT NULL AND p256dh IS NOT NULL AND auth IS NOT NULL AND native_device_id IS NULL) OR
19
+ (endpoint IS NULL AND native_device_id IS NOT NULL AND native_token IS NOT NULL AND native_environment IS NOT NULL AND native_language IS NOT NULL)
20
+ )
21
+ );
22
+
23
+ INSERT INTO push_devices (id, user_id, endpoint, p256dh, auth, created_at)
24
+ SELECT id, user_id, endpoint, p256dh, auth, created_at FROM push_devices_web;
25
+
26
+ -- Delivery cursors in the existing outbox refer to the original ID sequence.
27
+ UPDATE sqlite_sequence SET seq = MAX(seq, (SELECT seq FROM sqlite_sequence WHERE name = 'push_devices_web'))
28
+ WHERE name = 'push_devices';
29
+ INSERT INTO sqlite_sequence (name, seq)
30
+ SELECT 'push_devices', seq FROM sqlite_sequence WHERE name = 'push_devices_web'
31
+ AND NOT EXISTS (SELECT 1 FROM sqlite_sequence WHERE name = 'push_devices');
32
+ DROP TABLE push_devices_web;
33
+ CREATE INDEX idx_push_devices_user ON push_devices(user_id);
@@ -67,7 +67,7 @@ export function saveDevice(userId, target) {
67
67
  db.prepare(`INSERT INTO push_devices (user_id, endpoint, p256dh, auth) VALUES (?, ?, ?, ?)
68
68
  ON CONFLICT(endpoint) DO UPDATE SET user_id = excluded.user_id, p256dh = excluded.p256dh, auth = excluded.auth`).run(userId, target.endpoint, target.keys.p256dh, target.keys.auth);
69
69
  // Keep the newest devices only.
70
- db.prepare(`DELETE FROM push_devices WHERE user_id = ? AND id NOT IN (SELECT id FROM push_devices WHERE user_id = ? ORDER BY id DESC LIMIT ?)`).run(userId, userId, MAX_DEVICES_PER_USER);
70
+ db.prepare(`DELETE FROM push_devices WHERE user_id = ? AND endpoint IS NOT NULL AND id NOT IN (SELECT id FROM push_devices WHERE user_id = ? AND endpoint IS NOT NULL ORDER BY id DESC LIMIT ?)`).run(userId, userId, MAX_DEVICES_PER_USER);
71
71
  })();
72
72
  }
73
73
  export function removeDevice(userId, endpoint) {
@@ -78,7 +78,7 @@ export function hasDevice(userId, endpoint) {
78
78
  }
79
79
  function devicesOf(userId) {
80
80
  return db
81
- .prepare("SELECT endpoint, p256dh, auth FROM push_devices WHERE user_id = ?")
81
+ .prepare("SELECT endpoint, p256dh, auth FROM push_devices WHERE user_id = ? AND endpoint IS NOT NULL")
82
82
  .all(userId)
83
83
  .map((row) => ({ endpoint: row.endpoint, keys: { p256dh: row.p256dh, auth: row.auth } }));
84
84
  }
@@ -5,6 +5,10 @@ import { newItemsPushPayload, sendPushTarget } from "./push.js";
5
5
  import { parseRetryAfter } from "./feeds/fetcher.js";
6
6
  // Initialized during startup, so background work never retains an HTTP capability cache.
7
7
  const context = new AsyncResource("FeedKeeperPushOutbox");
8
+ let nativeSender;
9
+ export function setNativePushSender(sender) {
10
+ nativeSender = sender;
11
+ }
8
12
  /** Call inside the article/job-completion transaction. No network or recipient-sized array. */
9
13
  export function enqueueNewItemNotifications(feedId, newItems) {
10
14
  if (!newItems)
@@ -96,8 +100,9 @@ export class PushOutbox {
96
100
  .run(subscription.id, event.device_ceiling, event.id);
97
101
  }
98
102
  const device = db.prepare(`
99
- SELECT id,endpoint,p256dh,auth FROM push_devices WHERE user_id = ? AND id > ? AND id <= ? ORDER BY id LIMIT 1`)
100
- .get(subscription.user_id, event.device_cursor, event.device_ceiling);
103
+ SELECT id,endpoint,p256dh,auth,native_device_id,native_token,native_environment,native_language FROM push_devices
104
+ WHERE user_id = ? AND id > ? AND id <= ? AND (endpoint IS NOT NULL OR (native_feeds = 1 AND ?)) ORDER BY id LIMIT 1`)
105
+ .get(subscription.user_id, event.device_cursor, event.device_ceiling, nativeSender ? 1 : 0);
101
106
  if (!device) {
102
107
  this.advanceSubscription(event, subscription.id);
103
108
  return;
@@ -119,7 +124,10 @@ export class PushOutbox {
119
124
  return;
120
125
  }
121
126
  try {
122
- await sendPushTarget({ endpoint: device.endpoint, keys: { p256dh: device.p256dh, auth: device.auth } }, payload);
127
+ if (device.endpoint === null)
128
+ await nativeSender?.(device, payload);
129
+ else
130
+ await sendPushTarget({ endpoint: device.endpoint, keys: { p256dh: device.p256dh, auth: device.auth } }, payload);
123
131
  this.counters.delivered++;
124
132
  }
125
133
  catch (error) {
@@ -127,7 +135,12 @@ export class PushOutbox {
127
135
  const status = error.statusCode;
128
136
  if (status === 404 || status === 410) {
129
137
  // Do not remove a device if its ownership changed during I/O.
130
- db.prepare("DELETE FROM push_devices WHERE id = ? AND user_id = ?").run(device.id, subscription.user_id);
138
+ if (device.endpoint === null) {
139
+ db.prepare("DELETE FROM push_devices WHERE id = ? AND native_token = ? AND native_environment = ?")
140
+ .run(device.id, device.native_token, device.native_environment);
141
+ }
142
+ else
143
+ db.prepare("DELETE FROM push_devices WHERE id = ? AND user_id = ?").run(device.id, subscription.user_id);
131
144
  }
132
145
  else if ((status === undefined || [408, 425, 429, 500, 502, 503, 504].includes(status)) && event.attempts < 2) {
133
146
  const headers = error.headers;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@feedkeeper/server",
3
- "version": "0.39.0",
3
+ "version": "0.41.0",
4
4
  "private": true,
5
5
  "type": "module"
6
6
  }