@huaqiu/dsh-tool-plugin-update 0.6.6 → 0.6.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.
package/src/routes.ts CHANGED
@@ -27,6 +27,14 @@
27
27
  * → GET /api/v1/plugin-updates/source
28
28
  * POST /plugin-update/plugin-source
29
29
  * → POST /api/v1/plugin-updates/source {url}
30
+ * GET /plugin-update/status → GET /api/v1/plugin-updates/status
31
+ * GET /plugin-update/status/<id>
32
+ * → GET /api/v1/plugin-updates/status/<id>
33
+ *
34
+ * The status routes expose the durable update-job lifecycle (active job +
35
+ * recent jobs). They are read-only passthroughs: an unknown job id upstream
36
+ * answers `404 { error: 'unknown job' }`, which this forwarder passes through
37
+ * verbatim rather than turning into a plugin-side 500.
30
38
  *
31
39
  * The runtime-update request is user-confirmed in this plugin's review panel:
32
40
  * hq-edge validates the version against a fresh manifest, downloads and
@@ -110,6 +118,20 @@ function readBody(req: IncomingMessage): Promise<string> {
110
118
  * forwarder answers 405 rather than forwarding a GET to a POST-only upstream
111
119
  * and surfacing hq-edge's 404 as a plugin bug.
112
120
  */
121
+ /**
122
+ * Match a dynamic `/status/<jobId>` sub-path. Returns the job id for a single
123
+ * non-empty segment (no nested slashes), else null. The id is opaque — this
124
+ * route forwards it verbatim; hq-edge owns validation and the 404 for unknown
125
+ * ids.
126
+ */
127
+ function matchJobStatusPath(sub: string): string | null {
128
+ const prefix = '/status/'
129
+ if (!sub.startsWith(prefix)) return null
130
+ const id = sub.slice(prefix.length)
131
+ if (id.length === 0 || id.includes('/') || id.includes('?')) return null
132
+ return id
133
+ }
134
+
113
135
  function routeFor(
114
136
  sub: string,
115
137
  method: string,
@@ -127,6 +149,17 @@ function routeFor(
127
149
  if (sub === '/report' || sub === '') {
128
150
  return method === 'GET' ? { method: 'GET', path: '/api/v1/plugin-updates' } : null
129
151
  }
152
+ if (sub === '/status') {
153
+ return method === 'GET'
154
+ ? { method: 'GET', path: '/api/v1/plugin-updates/status' }
155
+ : null
156
+ }
157
+ const jobId = matchJobStatusPath(sub)
158
+ if (jobId !== null) {
159
+ return method === 'GET'
160
+ ? { method: 'GET', path: `/api/v1/plugin-updates/status/${encodeURIComponent(jobId)}` }
161
+ : null
162
+ }
130
163
  if (sub === '/runtime') {
131
164
  return method === 'GET' ? { method: 'GET', path: '/api/v1/runtime-update' } : null
132
165
  }
@@ -154,8 +187,9 @@ function routeFor(
154
187
  return null
155
188
  }
156
189
 
157
- /** Every sub-path this forwarder serves — used to tell a 404 from a 405. */
158
- const ROUTE_SUB_PATHS = new Set([
190
+ /** Every static sub-path this forwarder serves — used to tell a 404 from a
191
+ * 405. The dynamic `/status/<id>` path is matched separately. */
192
+ const STATIC_SUB_PATHS = new Set([
159
193
  '',
160
194
  '/report',
161
195
  '/check',
@@ -166,8 +200,18 @@ const ROUTE_SUB_PATHS = new Set([
166
200
  '/runtime-request',
167
201
  '/runtime-source',
168
202
  '/plugin-source',
203
+ '/status',
169
204
  ])
170
205
 
206
+ /**
207
+ * Whether a sub-path names a route this forwarder recognizes at all. A
208
+ * recognized sub-path hit with an unsupported method is a 405; an unrecognized
209
+ * one is a 404. `/status/<id>` is recognized for any single-segment id.
210
+ */
211
+ function isKnownSubPath(sub: string): boolean {
212
+ return STATIC_SUB_PATHS.has(sub) || matchJobStatusPath(sub) !== null
213
+ }
214
+
171
215
  /** Create the prefix-route handler forwarding to hq-edge. */
172
216
  export function createUpdateForwarder(
173
217
  baseUrlResolver: BaseUrlResolver,
@@ -186,11 +230,9 @@ export function createUpdateForwarder(
186
230
  if (target === null) {
187
231
  // Either an unknown sub-path (404) or a known one under a method it does
188
232
  // not serve (405). Both are client errors caught here, not upstream.
189
- sendJson(res, sub === '' || ROUTE_SUB_PATHS.has(sub) ? 405 : 404, {
190
- error:
191
- sub === '' || ROUTE_SUB_PATHS.has(sub)
192
- ? `method ${req.method} not allowed on ${sub || '/'}`
193
- : 'not found',
233
+ const known = isKnownSubPath(sub)
234
+ sendJson(res, known ? 405 : 404, {
235
+ error: known ? `method ${req.method} not allowed on ${sub || '/'}` : 'not found',
194
236
  })
195
237
  return
196
238
  }