@molecule/api-resource-firmware 1.0.7 → 1.0.10

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/README.md CHANGED
@@ -3,7 +3,7 @@ AUTO-GENERATED — DO NOT EDIT THIS FILE.
3
3
  Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
4
4
  Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
5
5
  To change this document, edit the module-level JSDoc in src/index.ts.
6
- Generated: 2026-10-26T04:23:48.394Z
6
+ Generated: 2026-12-01T12:28:54.356Z
7
7
  -->
8
8
 
9
9
  # @molecule/api-resource-firmware
@@ -60,7 +60,7 @@ app.use('/api/firmware', createFirmwareRouter({ requireDeviceToken }))
60
60
  ## Installation
61
61
 
62
62
  ```bash
63
- npm install @molecule/api-resource-firmware @molecule/api-bonds-default-express @molecule/api-database @molecule/api-i18n @molecule/api-logger @molecule/api-middleware-validation @molecule/api-realtime express zod
63
+ npm install @molecule/api-resource-firmware @molecule/api-database @molecule/api-i18n @molecule/api-logger @molecule/api-middleware-validation @molecule/api-realtime @molecule/api-resource express zod
64
64
  npm install -D @types/express
65
65
  ```
66
66
 
@@ -467,23 +467,23 @@ const rolloutDeviceStatusSchema: z.ZodObject<
467
467
 
468
468
  Peer dependencies:
469
469
 
470
- - `@molecule/api-bonds-default-express` ^1.0.1
471
470
  - `@molecule/api-database` ^1.0.1
472
471
  - `@molecule/api-i18n` ^1.0.1
473
472
  - `@molecule/api-logger` ^1.0.1
474
473
  - `@molecule/api-middleware-validation` ^1.0.1
475
474
  - `@molecule/api-realtime` ^1.0.1
475
+ - `@molecule/api-resource` ^1.5.0
476
476
  - `express` ^5.0.0
477
477
  - `zod` ^4.0.0
478
478
 
479
479
  ### Runtime Dependencies
480
480
 
481
- - `@molecule/api-bonds-default-express`
482
481
  - `@molecule/api-database`
483
482
  - `@molecule/api-i18n`
484
483
  - `@molecule/api-logger`
485
484
  - `@molecule/api-middleware-validation`
486
485
  - `@molecule/api-realtime`
486
+ - `@molecule/api-resource`
487
487
  - `express`
488
488
  - `zod`
489
489
 
@@ -1 +1 @@
1
- {"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAgB,KAAK,cAAc,EAAiB,MAAM,EAAE,MAAM,SAAS,CAAA;AAiClF;;;;GAIG;AACH,MAAM,MAAM,qBAAqB,GAAG,cAAc,CAAA;AA4BlD,iCAAiC;AACjC,wBAAgB,oBAAoB,CAAC,IAAI,EAAE;IAAE,kBAAkB,EAAE,qBAAqB,CAAA;CAAE,GAAG,MAAM,CAyKhG"}
1
+ {"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAgB,KAAK,cAAc,EAAiB,MAAM,EAAE,MAAM,SAAS,CAAA;AA2BlF;;;;GAIG;AACH,MAAM,MAAM,qBAAqB,GAAG,cAAc,CAAA;AA4BlD,iCAAiC;AACjC,wBAAgB,oBAAoB,CAAC,IAAI,EAAE;IAAE,kBAAkB,EAAE,qBAAqB,CAAA;CAAE,GAAG,MAAM,CA0KhG"}
package/dist/routes.js CHANGED
@@ -9,14 +9,12 @@
9
9
  * @module
10
10
  */
11
11
  import { Router } from 'express';
12
- import { getParamId, getUserId } from '@molecule/api-bonds-default-express';
13
12
  import { t } from '@molecule/api-i18n';
14
13
  import { logger } from '@molecule/api-logger';
15
- import { validateBody as validateBodyRaw, validateQuery as validateQueryRaw, } from '@molecule/api-middleware-validation';
14
+ import { validateBody, validateQuery } from '@molecule/api-middleware-validation';
15
+ import { getParamId, getUserId, rateLimitResourceRoute } from '@molecule/api-resource';
16
16
  import { createFirmwareForOwner, createRolloutForOwner, getFirmwareForOwner, listFirmwareForOwner, listRolloutsForOwner, publishFirmwareForOwner, recordRolloutDeviceStatus, updateFirmwareForOwner, } from './service.js';
17
17
  import { createFirmwareSchema, createRolloutSchema, listFirmwareQuerySchema, listRolloutsQuerySchema, rolloutDeviceStatusSchema, updateFirmwareSchema, } from './validation.js';
18
- const validateBody = validateBodyRaw;
19
- const validateQuery = validateQueryRaw;
20
18
  /** Responds with a 401 Unauthorized JSON error. */
21
19
  function unauthorized(res) {
22
20
  return res.status(401).json({
@@ -43,7 +41,7 @@ export function createFirmwareRouter(opts) {
43
41
  const userId = getUserId(res);
44
42
  if (!userId)
45
43
  return unauthorized(res);
46
- const q = req.query;
44
+ const q = listFirmwareQuerySchema.parse(req.query);
47
45
  res.json(await listFirmwareForOwner(userId, q));
48
46
  }
49
47
  catch (error) {
@@ -56,7 +54,7 @@ export function createFirmwareRouter(opts) {
56
54
  const userId = getUserId(res);
57
55
  if (!userId)
58
56
  return unauthorized(res);
59
- const q = req.query;
57
+ const q = listRolloutsQuerySchema.parse(req.query);
60
58
  res.json(await listRolloutsForOwner(userId, q));
61
59
  }
62
60
  catch (error) {
@@ -154,7 +152,7 @@ export function createFirmwareRouter(opts) {
154
152
  internalError(res);
155
153
  }
156
154
  });
157
- router.post('/rollouts/:rolloutId/devices/:deviceId/status', opts.requireDeviceToken, validateBody(rolloutDeviceStatusSchema), async (req, res) => {
155
+ router.post('/rollouts/:rolloutId/devices/:deviceId/status', rateLimitResourceRoute('firmware:device-status'), opts.requireDeviceToken, validateBody(rolloutDeviceStatusSchema), async (req, res) => {
158
156
  try {
159
157
  const auth = res.locals.deviceAuth;
160
158
  if (!auth) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@molecule/api-resource-firmware",
3
- "version": "1.0.7",
4
- "description": "Owner-scoped firmware versions + OTA rollouts: draft/publish/deprecate, per-device update tasks, realtime command dispatch, device-token-authenticated status reporting. Extracted from iot-device-manager flagship.",
3
+ "version": "1.0.10",
4
+ "description": "Firmware versions + OTA rollouts",
5
5
  "homepage": "https://www.molecule.dev/packages/api-resource-firmware",
6
6
  "type": "module",
7
7
  "main": "dist/index.js",
@@ -45,12 +45,12 @@
45
45
  "zod": "4.6.7"
46
46
  },
47
47
  "peerDependencies": {
48
- "@molecule/api-bonds-default-express": "^1.0.1",
49
48
  "@molecule/api-database": "^1.0.1",
50
49
  "@molecule/api-i18n": "^1.0.1",
51
50
  "@molecule/api-logger": "^1.0.1",
52
51
  "@molecule/api-middleware-validation": "^1.0.1",
53
52
  "@molecule/api-realtime": "^1.0.1",
53
+ "@molecule/api-resource": "^1.5.0",
54
54
  "express": "^5.0.0",
55
55
  "zod": "^4.0.0"
56
56
  }
@@ -1,15 +1,15 @@
1
1
  -- @molecule/api-resource-firmware — schema setup
2
2
 
3
3
  CREATE TABLE IF NOT EXISTS firmware_versions (
4
- id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
4
+ id UUID PRIMARY KEY NOT NULL DEFAULT gen_random_uuid(),
5
5
  owner_id UUID NOT NULL,
6
6
  version TEXT NOT NULL,
7
7
  device_type TEXT NOT NULL,
8
8
  release_notes TEXT NOT NULL DEFAULT '',
9
9
  download_url TEXT,
10
10
  checksum TEXT,
11
- file_size BIGINT NOT NULL DEFAULT 0,
12
- status TEXT NOT NULL DEFAULT 'draft',
11
+ file_size BIGINT NOT NULL DEFAULT 0 CHECK (file_size >= 0),
12
+ status TEXT NOT NULL DEFAULT 'draft' CHECK (status IN ('draft', 'published', 'deprecated')),
13
13
  released_at TIMESTAMPTZ,
14
14
  created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
15
15
  updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
@@ -17,39 +17,45 @@ CREATE TABLE IF NOT EXISTS firmware_versions (
17
17
 
18
18
  CREATE INDEX IF NOT EXISTS idx_firmware_versions_owner_status
19
19
  ON firmware_versions (owner_id, status);
20
+ CREATE INDEX IF NOT EXISTS idx_firmware_versions_owner_device_type
21
+ ON firmware_versions (owner_id, device_type);
20
22
 
21
23
  CREATE TABLE IF NOT EXISTS firmware_rollouts (
22
- id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
24
+ id UUID PRIMARY KEY NOT NULL DEFAULT gen_random_uuid(),
23
25
  owner_id UUID NOT NULL,
24
- firmware_id UUID NOT NULL,
26
+ firmware_id UUID NOT NULL REFERENCES firmware_versions (id),
25
27
  fleet_id UUID,
26
28
  device_ids JSONB NOT NULL DEFAULT '[]'::jsonb,
27
- strategy TEXT NOT NULL DEFAULT 'immediate',
28
- status TEXT NOT NULL DEFAULT 'active',
29
- target_count INTEGER NOT NULL DEFAULT 0,
30
- completed_count INTEGER NOT NULL DEFAULT 0,
31
- failed_count INTEGER NOT NULL DEFAULT 0,
32
- progress_percent INTEGER NOT NULL DEFAULT 0,
29
+ strategy TEXT NOT NULL DEFAULT 'immediate' CHECK (strategy IN ('immediate', 'canary', 'gradual')),
30
+ status TEXT NOT NULL DEFAULT 'active' CHECK (status IN ('pending', 'active', 'completed', 'failed', 'canceled')),
31
+ target_count INTEGER NOT NULL DEFAULT 0 CHECK (target_count >= 0),
32
+ completed_count INTEGER NOT NULL DEFAULT 0 CHECK (completed_count >= 0),
33
+ failed_count INTEGER NOT NULL DEFAULT 0 CHECK (failed_count >= 0),
34
+ progress_percent INTEGER NOT NULL DEFAULT 0 CHECK (progress_percent BETWEEN 0 AND 100),
33
35
  created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
34
36
  updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
35
37
  );
36
38
 
37
39
  CREATE INDEX IF NOT EXISTS idx_firmware_rollouts_owner_status
38
40
  ON firmware_rollouts (owner_id, status);
41
+ CREATE INDEX IF NOT EXISTS idx_firmware_rollouts_firmware
42
+ ON firmware_rollouts (firmware_id);
39
43
 
40
44
  CREATE TABLE IF NOT EXISTS firmware_update_tasks (
41
- id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
42
- rollout_id UUID NOT NULL,
43
- firmware_id UUID NOT NULL,
45
+ id UUID PRIMARY KEY NOT NULL DEFAULT gen_random_uuid(),
46
+ rollout_id UUID NOT NULL REFERENCES firmware_rollouts (id),
47
+ firmware_id UUID NOT NULL REFERENCES firmware_versions (id),
44
48
  device_id UUID NOT NULL,
45
- status TEXT NOT NULL DEFAULT 'pending',
49
+ status TEXT NOT NULL DEFAULT 'pending' CHECK (status IN ('pending', 'in_progress', 'completed', 'failed')),
46
50
  error_message TEXT,
47
51
  completed_at TIMESTAMPTZ,
48
52
  created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
49
53
  updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
50
54
  );
51
55
 
52
- CREATE INDEX IF NOT EXISTS idx_firmware_tasks_rollout
53
- ON firmware_update_tasks (rollout_id);
56
+ CREATE INDEX IF NOT EXISTS idx_firmware_tasks_rollout_device
57
+ ON firmware_update_tasks (rollout_id, device_id);
58
+ CREATE INDEX IF NOT EXISTS idx_firmware_tasks_firmware
59
+ ON firmware_update_tasks (firmware_id);
54
60
  CREATE INDEX IF NOT EXISTS idx_firmware_tasks_device
55
61
  ON firmware_update_tasks (device_id);