@rmdes/indiekit-endpoint-rss 1.0.0 → 1.0.2

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/index.js CHANGED
@@ -52,7 +52,7 @@ export default class RssEndpoint {
52
52
 
53
53
  /**
54
54
  * Protected routes (require authentication)
55
- * Admin dashboard and feed management
55
+ * Admin dashboard and feed management (write operations)
56
56
  */
57
57
  get routes() {
58
58
  // Dashboard
@@ -61,27 +61,31 @@ export default class RssEndpoint {
61
61
  // Manual sync trigger
62
62
  protectedRouter.post("/sync", dashboardController.sync);
63
63
 
64
+ // Feed management (protected - requires auth)
65
+ protectedRouter.post("/api/feeds", express.json(), feedsController.add);
66
+ protectedRouter.delete("/api/feeds/:id", feedsController.remove);
67
+ protectedRouter.patch("/api/feeds/:id", express.json(), feedsController.toggle);
68
+
69
+ // Manual refresh (protected)
70
+ protectedRouter.post("/api/refresh", statusController.refresh);
71
+
64
72
  return protectedRouter;
65
73
  }
66
74
 
67
75
  /**
68
76
  * Public routes (no authentication required)
69
- * JSON API endpoints for frontend
77
+ * Read-only JSON API endpoints for frontend
70
78
  */
71
79
  get routesPublic() {
72
- // Feeds API
80
+ // Feeds API (read-only)
73
81
  publicRouter.get("/api/feeds", feedsController.list);
74
- publicRouter.post("/api/feeds", express.json(), feedsController.add);
75
- publicRouter.delete("/api/feeds/:id", feedsController.remove);
76
- publicRouter.patch("/api/feeds/:id", express.json(), feedsController.toggle);
77
82
 
78
- // Items API
83
+ // Items API (read-only)
79
84
  publicRouter.get("/api/items", itemsController.list);
80
85
  publicRouter.get("/api/items/:id", itemsController.get);
81
86
 
82
- // Status API
87
+ // Status API (read-only)
83
88
  publicRouter.get("/api/status", statusController.status);
84
- publicRouter.post("/api/refresh", statusController.refresh);
85
89
 
86
90
  return publicRouter;
87
91
  }
@@ -65,15 +65,21 @@ export const dashboardController = {
65
65
  */
66
66
  async sync(request, response) {
67
67
  try {
68
- const Indiekit = request.app.locals.indiekit;
69
- const { rssConfig } = request.app.locals.application;
68
+ const { rssConfig, getRssDb } = request.app.locals.application;
70
69
 
71
- if (!Indiekit || !rssConfig) {
70
+ if (!rssConfig) {
72
71
  return response.status(500).json({
73
72
  error: response.locals.__("rss.error.noConfig"),
74
73
  });
75
74
  }
76
75
 
76
+ const db = getRssDb?.();
77
+ if (!db) {
78
+ return response.status(500).json({
79
+ error: response.locals.__("rss.error.noDatabase"),
80
+ });
81
+ }
82
+
77
83
  const syncState = getSyncState();
78
84
  if (syncState.syncing) {
79
85
  return response.status(409).json({
@@ -82,8 +88,8 @@ export const dashboardController = {
82
88
  });
83
89
  }
84
90
 
85
- // Start sync and wait for result
86
- const result = await runSync(Indiekit, rssConfig);
91
+ // Start sync and wait for result - pass db directly
92
+ const result = await runSync(db, rssConfig);
87
93
 
88
94
  if (result.error) {
89
95
  return response.status(500).json({
package/lib/sync.js CHANGED
@@ -57,13 +57,14 @@ export function stopSync() {
57
57
 
58
58
  /**
59
59
  * Run a single sync cycle
60
- * @param {Object} Indiekit - Indiekit instance
60
+ * @param {Object} dbOrIndiekit - Database instance or Indiekit instance (for backwards compat)
61
61
  * @param {Object} options - Plugin options
62
62
  * @returns {Promise<Object>}
63
63
  */
64
- export async function runSync(Indiekit, options) {
65
- const db = Indiekit.database;
66
- if (!db) {
64
+ export async function runSync(dbOrIndiekit, options) {
65
+ // Support both direct db object and Indiekit object (for background sync)
66
+ const db = dbOrIndiekit.database || dbOrIndiekit;
67
+ if (!db || typeof db.collection !== "function") {
67
68
  syncState.lastError = "No database available";
68
69
  return { error: syncState.lastError };
69
70
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rmdes/indiekit-endpoint-rss",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "RSS feed reader endpoint for Indiekit. Aggregates multiple feeds, caches in MongoDB, displays on frontend.",
5
5
  "keywords": [
6
6
  "indiekit",