@molecule/api-resource-firmware 1.0.9 → 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-11-25T20:13:22.685Z
6
+ Generated: 2026-12-01T12:28:54.356Z
7
7
  -->
8
8
 
9
9
  # @molecule/api-resource-firmware
@@ -472,7 +472,7 @@ Peer dependencies:
472
472
  - `@molecule/api-logger` ^1.0.1
473
473
  - `@molecule/api-middleware-validation` ^1.0.1
474
474
  - `@molecule/api-realtime` ^1.0.1
475
- - `@molecule/api-resource` ^1.2.0
475
+ - `@molecule/api-resource` ^1.5.0
476
476
  - `express` ^5.0.0
477
477
  - `zod` ^4.0.0
478
478
 
@@ -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;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,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
@@ -12,7 +12,7 @@ import { Router } from 'express';
12
12
  import { t } from '@molecule/api-i18n';
13
13
  import { logger } from '@molecule/api-logger';
14
14
  import { validateBody, validateQuery } from '@molecule/api-middleware-validation';
15
- import { getParamId, getUserId } from '@molecule/api-resource';
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
18
  /** Responds with a 401 Unauthorized JSON error. */
@@ -152,7 +152,7 @@ export function createFirmwareRouter(opts) {
152
152
  internalError(res);
153
153
  }
154
154
  });
155
- 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) => {
156
156
  try {
157
157
  const auth = res.locals.deviceAuth;
158
158
  if (!auth) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@molecule/api-resource-firmware",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "description": "Firmware versions + OTA rollouts",
5
5
  "homepage": "https://www.molecule.dev/packages/api-resource-firmware",
6
6
  "type": "module",
@@ -50,7 +50,7 @@
50
50
  "@molecule/api-logger": "^1.0.1",
51
51
  "@molecule/api-middleware-validation": "^1.0.1",
52
52
  "@molecule/api-realtime": "^1.0.1",
53
- "@molecule/api-resource": "^1.2.0",
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);