@molecule/api-resource-firmware 1.0.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/LICENSE +115 -0
- package/dist/browser-guard.d.ts +2 -0
- package/dist/browser-guard.d.ts.map +1 -0
- package/dist/browser-guard.js +18 -0
- package/dist/index.d.ts +59 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +58 -0
- package/dist/routes.d.ts +22 -0
- package/dist/routes.d.ts.map +1 -0
- package/dist/routes.js +199 -0
- package/dist/service.d.ts +73 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/service.js +257 -0
- package/dist/types.d.ts +57 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/validation.d.ts +93 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +55 -0
- package/package.json +49 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work.
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
|
+
form, that is based on (or derived from) the Work and for which the
|
|
41
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
42
|
+
represent, as a whole, an original work of authorship.
|
|
43
|
+
|
|
44
|
+
"Contribution" shall mean any work of authorship, including the
|
|
45
|
+
original version of the Work and any modifications or additions
|
|
46
|
+
to that Work, that is intentionally submitted to the Licensor for
|
|
47
|
+
inclusion in the Work by the copyright owner or by an individual or
|
|
48
|
+
Legal Entity authorized to submit on behalf of the copyright owner.
|
|
49
|
+
|
|
50
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
51
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
52
|
+
subsequently incorporated within the Work.
|
|
53
|
+
|
|
54
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
55
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
56
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
57
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
58
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
59
|
+
Work and such Derivative Works in Source or Object form.
|
|
60
|
+
|
|
61
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
62
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
63
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
64
|
+
patent license to make, have made, use, offer to sell, sell, import,
|
|
65
|
+
and otherwise transfer the Work.
|
|
66
|
+
|
|
67
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
68
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
69
|
+
modifications, and in Source or Object form, provided that You
|
|
70
|
+
meet the following conditions:
|
|
71
|
+
|
|
72
|
+
(a) You must give any other recipients of the Work or
|
|
73
|
+
Derivative Works a copy of this License; and
|
|
74
|
+
|
|
75
|
+
(b) You must cause any modified files to carry prominent notices
|
|
76
|
+
stating that You changed the files; and
|
|
77
|
+
|
|
78
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
79
|
+
that You distribute, all copyright, patent, trademark, and
|
|
80
|
+
attribution notices from the Source form of the Work,
|
|
81
|
+
excluding those notices that do not pertain to any part of
|
|
82
|
+
the Derivative Works; and
|
|
83
|
+
|
|
84
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
85
|
+
distribution, then any Derivative Works that You distribute must
|
|
86
|
+
include a readable copy of the attribution notices contained
|
|
87
|
+
within such NOTICE file.
|
|
88
|
+
|
|
89
|
+
5. Submission of Contributions.
|
|
90
|
+
|
|
91
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
92
|
+
names, trademarks, service marks, or product names of the Licensor.
|
|
93
|
+
|
|
94
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
95
|
+
agreed to in writing, Licensor provides the Work on an "AS IS" BASIS,
|
|
96
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND.
|
|
97
|
+
|
|
98
|
+
8. Limitation of Liability. In no event and under no legal theory shall
|
|
99
|
+
any Contributor be liable to You for damages.
|
|
100
|
+
|
|
101
|
+
9. Accepting Warranty or Additional Liability.
|
|
102
|
+
|
|
103
|
+
Copyright 2026 Molecule Dev, Inc.
|
|
104
|
+
|
|
105
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
106
|
+
you may not use this file except in compliance with the License.
|
|
107
|
+
You may obtain a copy of the License at
|
|
108
|
+
|
|
109
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
110
|
+
|
|
111
|
+
Unless required by applicable law or agreed to in writing, software
|
|
112
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
113
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
114
|
+
See the License for the specific language governing permissions and
|
|
115
|
+
limitations under the License.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-guard.d.ts","sourceRoot":"","sources":["../src/browser-guard.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser guard — `@molecule/api-resource-firmware` is SERVER-ONLY.
|
|
3
|
+
*
|
|
4
|
+
* Generated by scripts/gen-browser-guards.mjs (workspace root) — edit THAT, not this.
|
|
5
|
+
* Evaluating a server package in a browser bundle is always an import-graph mistake
|
|
6
|
+
* (node APIs, secrets); without this guard it surfaces as a cryptic downstream crash
|
|
7
|
+
* ("Buffer is not defined") far from the culprit. Throwing here names the package and
|
|
8
|
+
* the fix at the exact moment the client bundle evaluates it. jsdom tests and SSR are
|
|
9
|
+
* unaffected: the throw requires browser globals AND the absence of a node runtime.
|
|
10
|
+
*/
|
|
11
|
+
const g = globalThis;
|
|
12
|
+
if (g.window !== undefined && g.document !== undefined && !g.process?.versions?.node) {
|
|
13
|
+
throw new Error('@molecule/api-resource-firmware is SERVER-ONLY: it was bundled into browser/client code. Import it only ' +
|
|
14
|
+
'from server code (a server route/function or your API), or dynamic-import it inside ' +
|
|
15
|
+
'the server handler — never from components or shared client modules, and never ' +
|
|
16
|
+
'polyfill Buffer/process to silence this.');
|
|
17
|
+
}
|
|
18
|
+
export {};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@molecule/api-resource-firmware` — owner-scoped firmware versions
|
|
3
|
+
* and OTA rollouts.
|
|
4
|
+
*
|
|
5
|
+
* - Versions follow a draft → published → deprecated lifecycle.
|
|
6
|
+
* - Rollouts target an explicit `device_ids[]` list, a `fleet_id`, or
|
|
7
|
+
* both. The intersection with owner-scoped devices is what actually
|
|
8
|
+
* gets enrolled.
|
|
9
|
+
* - Per-device `firmware_update_tasks` rows are materialized and a
|
|
10
|
+
* matching `device_commands` row with `firmware_update` payload is
|
|
11
|
+
* created. Best-effort realtime broadcasts go out on
|
|
12
|
+
* `firmware:{deviceId}` and `commands:{deviceId}`.
|
|
13
|
+
* - The device reports back via a token-authenticated status endpoint;
|
|
14
|
+
* the resource updates the rollout's completed/failed counters and
|
|
15
|
+
* bumps the device's `firmware_version` on success.
|
|
16
|
+
*
|
|
17
|
+
* Extracted from the iot-device-manager flagship.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* import express from 'express'
|
|
22
|
+
* import {
|
|
23
|
+
* createFirmwareRouter,
|
|
24
|
+
* type DeviceTokenMiddleware,
|
|
25
|
+
* } from '@molecule/api-resource-firmware'
|
|
26
|
+
*
|
|
27
|
+
* // Device-auth implementations vary per deployment (token, mTLS, JWT, …),
|
|
28
|
+
* // so the status-report endpoint takes a caller-supplied authorizer. On
|
|
29
|
+
* // success it MUST set `res.locals.deviceAuth = { deviceId, ownerId }`;
|
|
30
|
+
* // on failure it responds 401.
|
|
31
|
+
* const requireDeviceToken: DeviceTokenMiddleware = async (req, res, next) => {
|
|
32
|
+
* const device = await verifyDeviceToken(req.header('authorization'))
|
|
33
|
+
* if (!device) {
|
|
34
|
+
* res.sendStatus(401)
|
|
35
|
+
* return
|
|
36
|
+
* }
|
|
37
|
+
* res.locals.deviceAuth = { deviceId: device.id, ownerId: device.ownerId }
|
|
38
|
+
* next()
|
|
39
|
+
* }
|
|
40
|
+
*
|
|
41
|
+
* const app = express()
|
|
42
|
+
* app.use('/api/firmware', createFirmwareRouter({ requireDeviceToken }))
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @remarks
|
|
46
|
+
* The schema in `__setup__/firmware.sql` creates `firmware_versions`,
|
|
47
|
+
* `firmware_rollouts`, and `firmware_update_tasks`. The resource also
|
|
48
|
+
* reads/writes `iot_devices`, `fleets`, `fleet_memberships`,
|
|
49
|
+
* `device_commands`, and `device_alerts` — those tables are owned by
|
|
50
|
+
* the iot-device-manager template.
|
|
51
|
+
*
|
|
52
|
+
* @module
|
|
53
|
+
*/
|
|
54
|
+
export * from './browser-guard.js';
|
|
55
|
+
export * from './routes.js';
|
|
56
|
+
export * from './service.js';
|
|
57
|
+
export * from './types.js';
|
|
58
|
+
export * from './validation.js';
|
|
59
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AAEH,cAAc,oBAAoB,CAAA;AAClC,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@molecule/api-resource-firmware` — owner-scoped firmware versions
|
|
3
|
+
* and OTA rollouts.
|
|
4
|
+
*
|
|
5
|
+
* - Versions follow a draft → published → deprecated lifecycle.
|
|
6
|
+
* - Rollouts target an explicit `device_ids[]` list, a `fleet_id`, or
|
|
7
|
+
* both. The intersection with owner-scoped devices is what actually
|
|
8
|
+
* gets enrolled.
|
|
9
|
+
* - Per-device `firmware_update_tasks` rows are materialized and a
|
|
10
|
+
* matching `device_commands` row with `firmware_update` payload is
|
|
11
|
+
* created. Best-effort realtime broadcasts go out on
|
|
12
|
+
* `firmware:{deviceId}` and `commands:{deviceId}`.
|
|
13
|
+
* - The device reports back via a token-authenticated status endpoint;
|
|
14
|
+
* the resource updates the rollout's completed/failed counters and
|
|
15
|
+
* bumps the device's `firmware_version` on success.
|
|
16
|
+
*
|
|
17
|
+
* Extracted from the iot-device-manager flagship.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* import express from 'express'
|
|
22
|
+
* import {
|
|
23
|
+
* createFirmwareRouter,
|
|
24
|
+
* type DeviceTokenMiddleware,
|
|
25
|
+
* } from '@molecule/api-resource-firmware'
|
|
26
|
+
*
|
|
27
|
+
* // Device-auth implementations vary per deployment (token, mTLS, JWT, …),
|
|
28
|
+
* // so the status-report endpoint takes a caller-supplied authorizer. On
|
|
29
|
+
* // success it MUST set `res.locals.deviceAuth = { deviceId, ownerId }`;
|
|
30
|
+
* // on failure it responds 401.
|
|
31
|
+
* const requireDeviceToken: DeviceTokenMiddleware = async (req, res, next) => {
|
|
32
|
+
* const device = await verifyDeviceToken(req.header('authorization'))
|
|
33
|
+
* if (!device) {
|
|
34
|
+
* res.sendStatus(401)
|
|
35
|
+
* return
|
|
36
|
+
* }
|
|
37
|
+
* res.locals.deviceAuth = { deviceId: device.id, ownerId: device.ownerId }
|
|
38
|
+
* next()
|
|
39
|
+
* }
|
|
40
|
+
*
|
|
41
|
+
* const app = express()
|
|
42
|
+
* app.use('/api/firmware', createFirmwareRouter({ requireDeviceToken }))
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @remarks
|
|
46
|
+
* The schema in `__setup__/firmware.sql` creates `firmware_versions`,
|
|
47
|
+
* `firmware_rollouts`, and `firmware_update_tasks`. The resource also
|
|
48
|
+
* reads/writes `iot_devices`, `fleets`, `fleet_memberships`,
|
|
49
|
+
* `device_commands`, and `device_alerts` — those tables are owned by
|
|
50
|
+
* the iot-device-manager template.
|
|
51
|
+
*
|
|
52
|
+
* @module
|
|
53
|
+
*/
|
|
54
|
+
export * from './browser-guard.js';
|
|
55
|
+
export * from './routes.js';
|
|
56
|
+
export * from './service.js';
|
|
57
|
+
export * from './types.js';
|
|
58
|
+
export * from './validation.js';
|
package/dist/routes.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Express router factory for the firmware resource. Mount at any base
|
|
3
|
+
* path (e.g. `/api/firmware`).
|
|
4
|
+
*
|
|
5
|
+
* The per-device status-report endpoint requires a caller-supplied
|
|
6
|
+
* device-token authorizer middleware (since device-auth implementations
|
|
7
|
+
* vary across deployments — token, mTLS, JWT, etc.).
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
import { type RequestHandler, Router } from 'express';
|
|
12
|
+
/**
|
|
13
|
+
* Caller-supplied device-token authorization. Should set
|
|
14
|
+
* `res.locals.deviceAuth = { deviceId, ownerId }` on success or 401 on
|
|
15
|
+
* failure.
|
|
16
|
+
*/
|
|
17
|
+
export type DeviceTokenMiddleware = RequestHandler;
|
|
18
|
+
/** Build the firmware router. */
|
|
19
|
+
export declare function createFirmwareRouter(opts: {
|
|
20
|
+
requireDeviceToken: DeviceTokenMiddleware;
|
|
21
|
+
}): Router;
|
|
22
|
+
//# sourceMappingURL=routes.d.ts.map
|
|
@@ -0,0 +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"}
|
package/dist/routes.js
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Express router factory for the firmware resource. Mount at any base
|
|
3
|
+
* path (e.g. `/api/firmware`).
|
|
4
|
+
*
|
|
5
|
+
* The per-device status-report endpoint requires a caller-supplied
|
|
6
|
+
* device-token authorizer middleware (since device-auth implementations
|
|
7
|
+
* vary across deployments — token, mTLS, JWT, etc.).
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
import { Router } from 'express';
|
|
12
|
+
import { getParamId, getUserId } from '@molecule/api-bonds-default-express';
|
|
13
|
+
import { t } from '@molecule/api-i18n';
|
|
14
|
+
import { logger } from '@molecule/api-logger';
|
|
15
|
+
import { validateBody as validateBodyRaw, validateQuery as validateQueryRaw, } from '@molecule/api-middleware-validation';
|
|
16
|
+
import { createFirmwareForOwner, createRolloutForOwner, getFirmwareForOwner, listFirmwareForOwner, listRolloutsForOwner, publishFirmwareForOwner, recordRolloutDeviceStatus, updateFirmwareForOwner, } from './service.js';
|
|
17
|
+
import { createFirmwareSchema, createRolloutSchema, listFirmwareQuerySchema, listRolloutsQuerySchema, rolloutDeviceStatusSchema, updateFirmwareSchema, } from './validation.js';
|
|
18
|
+
const validateBody = validateBodyRaw;
|
|
19
|
+
const validateQuery = validateQueryRaw;
|
|
20
|
+
/** Responds with a 401 Unauthorized JSON error. */
|
|
21
|
+
function unauthorized(res) {
|
|
22
|
+
return res.status(401).json({
|
|
23
|
+
error: t('auth.unauthorized', undefined, { defaultValue: 'Authentication required.' }),
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/** Responds with a 404 Not Found JSON error for a missing firmware version. */
|
|
27
|
+
function firmwareNotFound(res) {
|
|
28
|
+
return res.status(404).json({
|
|
29
|
+
error: t('firmware.notFound', undefined, { defaultValue: 'Firmware version not found.' }),
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
/** Responds with a 500 Internal Server Error JSON error. */
|
|
33
|
+
function internalError(res) {
|
|
34
|
+
return res.status(500).json({
|
|
35
|
+
error: t('errors.internalServer', undefined, { defaultValue: 'Internal server error.' }),
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/** Build the firmware router. */
|
|
39
|
+
export function createFirmwareRouter(opts) {
|
|
40
|
+
const router = Router();
|
|
41
|
+
router.get('/', validateQuery(listFirmwareQuerySchema), async (req, res) => {
|
|
42
|
+
try {
|
|
43
|
+
const userId = getUserId(res);
|
|
44
|
+
if (!userId)
|
|
45
|
+
return unauthorized(res);
|
|
46
|
+
const q = req.query;
|
|
47
|
+
res.json(await listFirmwareForOwner(userId, q));
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
logger.error('listFirmwareForOwner failed', { error });
|
|
51
|
+
internalError(res);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
router.get('/rollouts/list', validateQuery(listRolloutsQuerySchema), async (req, res) => {
|
|
55
|
+
try {
|
|
56
|
+
const userId = getUserId(res);
|
|
57
|
+
if (!userId)
|
|
58
|
+
return unauthorized(res);
|
|
59
|
+
const q = req.query;
|
|
60
|
+
res.json(await listRolloutsForOwner(userId, q));
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
logger.error('listRolloutsForOwner failed', { error });
|
|
64
|
+
internalError(res);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
router.get('/:id', async (req, res) => {
|
|
68
|
+
try {
|
|
69
|
+
const userId = getUserId(res);
|
|
70
|
+
if (!userId)
|
|
71
|
+
return unauthorized(res);
|
|
72
|
+
const row = await getFirmwareForOwner(userId, getParamId(req));
|
|
73
|
+
if (!row)
|
|
74
|
+
return firmwareNotFound(res);
|
|
75
|
+
res.json(row);
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
logger.error('getFirmwareForOwner failed', { error });
|
|
79
|
+
internalError(res);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
router.post('/', validateBody(createFirmwareSchema), async (req, res) => {
|
|
83
|
+
try {
|
|
84
|
+
const userId = getUserId(res);
|
|
85
|
+
if (!userId)
|
|
86
|
+
return unauthorized(res);
|
|
87
|
+
const created = await createFirmwareForOwner(userId, req.body);
|
|
88
|
+
if (!created)
|
|
89
|
+
return internalError(res);
|
|
90
|
+
res.status(201).json(created);
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
logger.error('createFirmwareForOwner failed', { error });
|
|
94
|
+
internalError(res);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
router.put('/:id', validateBody(updateFirmwareSchema), async (req, res) => {
|
|
98
|
+
try {
|
|
99
|
+
const userId = getUserId(res);
|
|
100
|
+
if (!userId)
|
|
101
|
+
return unauthorized(res);
|
|
102
|
+
const updated = await updateFirmwareForOwner(userId, getParamId(req), req.body);
|
|
103
|
+
if (!updated)
|
|
104
|
+
return firmwareNotFound(res);
|
|
105
|
+
res.json(updated);
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
logger.error('updateFirmwareForOwner failed', { error });
|
|
109
|
+
internalError(res);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
router.post('/:id/publish', async (req, res) => {
|
|
113
|
+
try {
|
|
114
|
+
const userId = getUserId(res);
|
|
115
|
+
if (!userId)
|
|
116
|
+
return unauthorized(res);
|
|
117
|
+
const published = await publishFirmwareForOwner(userId, getParamId(req));
|
|
118
|
+
if (!published)
|
|
119
|
+
return firmwareNotFound(res);
|
|
120
|
+
res.json(published);
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
logger.error('publishFirmwareForOwner failed', { error });
|
|
124
|
+
internalError(res);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
router.post('/rollouts', validateBody(createRolloutSchema), async (req, res) => {
|
|
128
|
+
try {
|
|
129
|
+
const userId = getUserId(res);
|
|
130
|
+
if (!userId)
|
|
131
|
+
return unauthorized(res);
|
|
132
|
+
const body = req.body;
|
|
133
|
+
const result = await createRolloutForOwner(userId, body);
|
|
134
|
+
if (!result.ok) {
|
|
135
|
+
if (result.reason === 'not_found')
|
|
136
|
+
return firmwareNotFound(res);
|
|
137
|
+
if (result.reason === 'not_published') {
|
|
138
|
+
return res.status(400).json({
|
|
139
|
+
error: t('firmware.notPublished', undefined, {
|
|
140
|
+
defaultValue: 'Firmware must be published before rollout.',
|
|
141
|
+
}),
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
return res.status(400).json({
|
|
145
|
+
error: t('firmware.rolloutTargetsRequired', undefined, {
|
|
146
|
+
defaultValue: 'At least one owned device id or a fleet with members is required.',
|
|
147
|
+
}),
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
res.status(201).json(result.rollout);
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
logger.error('createRolloutForOwner failed', { error });
|
|
154
|
+
internalError(res);
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
router.post('/rollouts/:rolloutId/devices/:deviceId/status', opts.requireDeviceToken, validateBody(rolloutDeviceStatusSchema), async (req, res) => {
|
|
158
|
+
try {
|
|
159
|
+
const auth = res.locals.deviceAuth;
|
|
160
|
+
if (!auth) {
|
|
161
|
+
return res.status(401).json({
|
|
162
|
+
error: t('devices.invalidToken', undefined, {
|
|
163
|
+
defaultValue: 'Invalid device token.',
|
|
164
|
+
}),
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
const rolloutId = String(req.params.rolloutId ?? '');
|
|
168
|
+
const deviceId = String(req.params.deviceId ?? '');
|
|
169
|
+
if (deviceId !== auth.deviceId) {
|
|
170
|
+
return res.status(403).json({
|
|
171
|
+
error: t('devices.tokenMismatch', undefined, {
|
|
172
|
+
defaultValue: 'Token does not match device.',
|
|
173
|
+
}),
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
const body = req.body;
|
|
177
|
+
const result = await recordRolloutDeviceStatus({
|
|
178
|
+
rolloutId,
|
|
179
|
+
deviceId,
|
|
180
|
+
ownerId: auth.ownerId,
|
|
181
|
+
status: body.status,
|
|
182
|
+
errorMessage: body.error_message,
|
|
183
|
+
});
|
|
184
|
+
if (!result.ok) {
|
|
185
|
+
return res.status(404).json({
|
|
186
|
+
error: t('firmware.taskNotFound', undefined, {
|
|
187
|
+
defaultValue: 'Firmware update task not found.',
|
|
188
|
+
}),
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
res.json({ ok: true });
|
|
192
|
+
}
|
|
193
|
+
catch (error) {
|
|
194
|
+
logger.error('recordRolloutDeviceStatus failed', { error });
|
|
195
|
+
internalError(res);
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
return router;
|
|
199
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure service-layer helpers for firmware versions and OTA rollouts.
|
|
3
|
+
* Reusable outside of HTTP contexts (background jobs, automation runs).
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import type { FirmwareRolloutRow, FirmwareVersionRow, RolloutStrategy, RolloutTaskStatus } from './types.js';
|
|
8
|
+
/** Whether a string is a syntactically valid UUID. */
|
|
9
|
+
export declare function isUuid(value: string): boolean;
|
|
10
|
+
/** Owner-scoped firmware list. */
|
|
11
|
+
export declare function listFirmwareForOwner(userId: string, filters?: {
|
|
12
|
+
device_type?: string;
|
|
13
|
+
status?: string;
|
|
14
|
+
page?: number;
|
|
15
|
+
limit?: number;
|
|
16
|
+
}): Promise<FirmwareVersionRow[]>;
|
|
17
|
+
/** Owner-scoped firmware read — null when missing or not owned. */
|
|
18
|
+
export declare function getFirmwareForOwner(userId: string, id: string): Promise<FirmwareVersionRow | null>;
|
|
19
|
+
/** Create a draft firmware version. */
|
|
20
|
+
export declare function createFirmwareForOwner(userId: string, input: {
|
|
21
|
+
version: string;
|
|
22
|
+
device_type: string;
|
|
23
|
+
release_notes?: string;
|
|
24
|
+
download_url?: string | null;
|
|
25
|
+
checksum?: string | null;
|
|
26
|
+
file_size?: number;
|
|
27
|
+
}): Promise<FirmwareVersionRow | null>;
|
|
28
|
+
/** Patch a firmware version owned by the user. */
|
|
29
|
+
export declare function updateFirmwareForOwner(userId: string, id: string, patch: Record<string, unknown>): Promise<FirmwareVersionRow | null>;
|
|
30
|
+
/** Flip a firmware version to published + stamp `released_at`. */
|
|
31
|
+
export declare function publishFirmwareForOwner(userId: string, id: string): Promise<FirmwareVersionRow | null>;
|
|
32
|
+
/**
|
|
33
|
+
* Create a rollout, materialize per-device tasks + `firmware_update`
|
|
34
|
+
* device commands, and best-effort broadcast realtime notifications.
|
|
35
|
+
*/
|
|
36
|
+
export declare function createRolloutForOwner(userId: string, input: {
|
|
37
|
+
firmware_id: string;
|
|
38
|
+
device_ids?: string[];
|
|
39
|
+
fleet_id?: string | null;
|
|
40
|
+
strategy?: RolloutStrategy;
|
|
41
|
+
}): Promise<{
|
|
42
|
+
ok: true;
|
|
43
|
+
rollout: FirmwareRolloutRow;
|
|
44
|
+
targets: string[];
|
|
45
|
+
} | {
|
|
46
|
+
ok: false;
|
|
47
|
+
reason: 'not_found' | 'not_published' | 'no_targets';
|
|
48
|
+
}>;
|
|
49
|
+
/** Owner-scoped rollout list. */
|
|
50
|
+
export declare function listRolloutsForOwner(userId: string, filters?: {
|
|
51
|
+
firmware_id?: string;
|
|
52
|
+
status?: string;
|
|
53
|
+
page?: number;
|
|
54
|
+
limit?: number;
|
|
55
|
+
}): Promise<FirmwareRolloutRow[]>;
|
|
56
|
+
/**
|
|
57
|
+
* Record a per-device task status report. Updates the rollout's
|
|
58
|
+
* completed/failed counters + progress percent; on success bumps the
|
|
59
|
+
* device's `firmware_version` to the new release.
|
|
60
|
+
*/
|
|
61
|
+
export declare function recordRolloutDeviceStatus(opts: {
|
|
62
|
+
rolloutId: string;
|
|
63
|
+
deviceId: string;
|
|
64
|
+
ownerId: string;
|
|
65
|
+
status: RolloutTaskStatus;
|
|
66
|
+
errorMessage?: string | null;
|
|
67
|
+
}): Promise<{
|
|
68
|
+
ok: true;
|
|
69
|
+
} | {
|
|
70
|
+
ok: false;
|
|
71
|
+
reason: 'task_not_found';
|
|
72
|
+
}>;
|
|
73
|
+
//# sourceMappingURL=service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EACV,kBAAkB,EAElB,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EAClB,MAAM,YAAY,CAAA;AAUnB,sDAAsD;AACtD,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE7C;AAED,kCAAkC;AAClC,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,MAAM,EACd,OAAO,GAAE;IACP,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;CACV,GACL,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAgB/B;AAED,mEAAmE;AACnE,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,MAAM,GACT,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC,CAIpC;AAED,uCAAuC;AACvC,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE,MAAM,EACd,KAAK,EAAE;IACL,OAAO,EAAE,MAAM,CAAA;IACf,WAAW,EAAE,MAAM,CAAA;IACnB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC5B,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,GACA,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC,CAepC;AAED,kDAAkD;AAClD,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC,CAKpC;AAED,kEAAkE;AAClE,wBAAsB,uBAAuB,CAC3C,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,MAAM,GACT,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC,CASpC;AAsBD;;;GAGG;AACH,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE;IACL,WAAW,EAAE,MAAM,CAAA;IACnB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;IACrB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,QAAQ,CAAC,EAAE,eAAe,CAAA;CAC3B,GACA,OAAO,CACN;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,OAAO,EAAE,kBAAkB,CAAC;IAAC,OAAO,EAAE,MAAM,EAAE,CAAA;CAAE,GAC5D;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,WAAW,GAAG,eAAe,GAAG,YAAY,CAAA;CAAE,CACtE,CAyEA;AAED,iCAAiC;AACjC,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,MAAM,EACd,OAAO,GAAE;IACP,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;CACV,GACL,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAgB/B;AAED;;;;GAIG;AACH,wBAAsB,yBAAyB,CAAC,IAAI,EAAE;IACpD,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,iBAAiB,CAAA;IACzB,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAC7B,GAAG,OAAO,CAAC;IAAE,EAAE,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,gBAAgB,CAAA;CAAE,CAAC,CAkDlE"}
|
package/dist/service.js
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure service-layer helpers for firmware versions and OTA rollouts.
|
|
3
|
+
* Reusable outside of HTTP contexts (background jobs, automation runs).
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { create, findById, findMany, updateById } from '@molecule/api-database';
|
|
8
|
+
import { broadcast } from '@molecule/api-realtime';
|
|
9
|
+
const FW_TABLE = 'firmware_versions';
|
|
10
|
+
const ROLLOUT_TABLE = 'firmware_rollouts';
|
|
11
|
+
const TASK_TABLE = 'firmware_update_tasks';
|
|
12
|
+
const DEVICE_TABLE = 'iot_devices';
|
|
13
|
+
const COMMAND_TABLE = 'device_commands';
|
|
14
|
+
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
15
|
+
/** Whether a string is a syntactically valid UUID. */
|
|
16
|
+
export function isUuid(value) {
|
|
17
|
+
return UUID_RE.test(value);
|
|
18
|
+
}
|
|
19
|
+
/** Owner-scoped firmware list. */
|
|
20
|
+
export async function listFirmwareForOwner(userId, filters = {}) {
|
|
21
|
+
const where = [
|
|
22
|
+
{ field: 'owner_id', operator: '=', value: userId },
|
|
23
|
+
];
|
|
24
|
+
if (filters.device_type) {
|
|
25
|
+
where.push({ field: 'device_type', operator: '=', value: filters.device_type });
|
|
26
|
+
}
|
|
27
|
+
if (filters.status)
|
|
28
|
+
where.push({ field: 'status', operator: '=', value: filters.status });
|
|
29
|
+
const limit = filters.limit ?? 50;
|
|
30
|
+
const page = filters.page ?? 1;
|
|
31
|
+
return findMany(FW_TABLE, {
|
|
32
|
+
where,
|
|
33
|
+
orderBy: [{ field: 'created_at', direction: 'desc' }],
|
|
34
|
+
limit,
|
|
35
|
+
offset: (page - 1) * limit,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/** Owner-scoped firmware read — null when missing or not owned. */
|
|
39
|
+
export async function getFirmwareForOwner(userId, id) {
|
|
40
|
+
const row = await findById(FW_TABLE, id);
|
|
41
|
+
if (!row || row.owner_id !== userId)
|
|
42
|
+
return null;
|
|
43
|
+
return row;
|
|
44
|
+
}
|
|
45
|
+
/** Create a draft firmware version. */
|
|
46
|
+
export async function createFirmwareForOwner(userId, input) {
|
|
47
|
+
const result = await create(FW_TABLE, {
|
|
48
|
+
owner_id: userId,
|
|
49
|
+
version: input.version,
|
|
50
|
+
device_type: input.device_type,
|
|
51
|
+
release_notes: input.release_notes ?? '',
|
|
52
|
+
download_url: input.download_url ?? null,
|
|
53
|
+
checksum: input.checksum ?? null,
|
|
54
|
+
file_size: input.file_size ?? 0,
|
|
55
|
+
status: 'draft',
|
|
56
|
+
released_at: null,
|
|
57
|
+
created_at: new Date(),
|
|
58
|
+
updated_at: new Date(),
|
|
59
|
+
});
|
|
60
|
+
return result.data ?? null;
|
|
61
|
+
}
|
|
62
|
+
/** Patch a firmware version owned by the user. */
|
|
63
|
+
export async function updateFirmwareForOwner(userId, id, patch) {
|
|
64
|
+
const existing = await getFirmwareForOwner(userId, id);
|
|
65
|
+
if (!existing)
|
|
66
|
+
return null;
|
|
67
|
+
const result = await updateById(FW_TABLE, id, { ...patch, updated_at: new Date() });
|
|
68
|
+
return result.data ?? null;
|
|
69
|
+
}
|
|
70
|
+
/** Flip a firmware version to published + stamp `released_at`. */
|
|
71
|
+
export async function publishFirmwareForOwner(userId, id) {
|
|
72
|
+
const existing = await getFirmwareForOwner(userId, id);
|
|
73
|
+
if (!existing)
|
|
74
|
+
return null;
|
|
75
|
+
const result = await updateById(FW_TABLE, id, {
|
|
76
|
+
status: 'published',
|
|
77
|
+
released_at: new Date(),
|
|
78
|
+
updated_at: new Date(),
|
|
79
|
+
});
|
|
80
|
+
return result.data ?? null;
|
|
81
|
+
}
|
|
82
|
+
/** Returns all device IDs owned by the given user. */
|
|
83
|
+
async function ownerDeviceIds(userId) {
|
|
84
|
+
const rows = await findMany(DEVICE_TABLE, {
|
|
85
|
+
where: [{ field: 'owner_id', operator: '=', value: userId }],
|
|
86
|
+
limit: 10_000,
|
|
87
|
+
});
|
|
88
|
+
return rows.map((r) => r.id);
|
|
89
|
+
}
|
|
90
|
+
/** Returns all device IDs belonging to a fleet that the given user owns. */
|
|
91
|
+
async function fleetDeviceIds(userId, fleetId) {
|
|
92
|
+
const fleet = await findById('fleets', fleetId);
|
|
93
|
+
if (!fleet || fleet.owner_id !== userId)
|
|
94
|
+
return [];
|
|
95
|
+
const memberships = await findMany('fleet_memberships', {
|
|
96
|
+
where: [{ field: 'fleet_id', operator: '=', value: fleetId }],
|
|
97
|
+
limit: 10_000,
|
|
98
|
+
});
|
|
99
|
+
return memberships.map((m) => m.device_id);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Create a rollout, materialize per-device tasks + `firmware_update`
|
|
103
|
+
* device commands, and best-effort broadcast realtime notifications.
|
|
104
|
+
*/
|
|
105
|
+
export async function createRolloutForOwner(userId, input) {
|
|
106
|
+
if (!isUuid(input.firmware_id))
|
|
107
|
+
return { ok: false, reason: 'not_found' };
|
|
108
|
+
const firmware = await getFirmwareForOwner(userId, input.firmware_id);
|
|
109
|
+
if (!firmware)
|
|
110
|
+
return { ok: false, reason: 'not_found' };
|
|
111
|
+
if (firmware.status !== 'published')
|
|
112
|
+
return { ok: false, reason: 'not_published' };
|
|
113
|
+
const owned = new Set(await ownerDeviceIds(userId));
|
|
114
|
+
const fromExplicit = (input.device_ids ?? []).filter((id) => owned.has(id));
|
|
115
|
+
const fromFleet = input.fleet_id ? await fleetDeviceIds(userId, input.fleet_id) : [];
|
|
116
|
+
const targets = Array.from(new Set([...fromExplicit, ...fromFleet]));
|
|
117
|
+
if (targets.length === 0)
|
|
118
|
+
return { ok: false, reason: 'no_targets' };
|
|
119
|
+
const rollout = await create(ROLLOUT_TABLE, {
|
|
120
|
+
owner_id: userId,
|
|
121
|
+
firmware_id: input.firmware_id,
|
|
122
|
+
fleet_id: input.fleet_id ?? null,
|
|
123
|
+
device_ids: JSON.stringify(targets),
|
|
124
|
+
strategy: input.strategy ?? 'immediate',
|
|
125
|
+
status: 'active',
|
|
126
|
+
target_count: targets.length,
|
|
127
|
+
completed_count: 0,
|
|
128
|
+
failed_count: 0,
|
|
129
|
+
progress_percent: 0,
|
|
130
|
+
created_at: new Date(),
|
|
131
|
+
updated_at: new Date(),
|
|
132
|
+
});
|
|
133
|
+
const rolloutRow = rollout.data;
|
|
134
|
+
for (const deviceId of targets) {
|
|
135
|
+
try {
|
|
136
|
+
await create(TASK_TABLE, {
|
|
137
|
+
rollout_id: rolloutRow.id,
|
|
138
|
+
firmware_id: input.firmware_id,
|
|
139
|
+
device_id: deviceId,
|
|
140
|
+
status: 'pending',
|
|
141
|
+
error_message: null,
|
|
142
|
+
completed_at: null,
|
|
143
|
+
created_at: new Date(),
|
|
144
|
+
updated_at: new Date(),
|
|
145
|
+
});
|
|
146
|
+
const cmd = await create(COMMAND_TABLE, {
|
|
147
|
+
device_id: deviceId,
|
|
148
|
+
command_type: 'firmware_update',
|
|
149
|
+
payload: JSON.stringify({
|
|
150
|
+
firmware_id: input.firmware_id,
|
|
151
|
+
version: firmware.version,
|
|
152
|
+
download_url: firmware.download_url,
|
|
153
|
+
checksum: firmware.checksum,
|
|
154
|
+
rollout_id: rolloutRow.id,
|
|
155
|
+
}),
|
|
156
|
+
priority: 'high',
|
|
157
|
+
status: 'pending',
|
|
158
|
+
result: null,
|
|
159
|
+
error_message: null,
|
|
160
|
+
acknowledged_at: null,
|
|
161
|
+
completed_at: null,
|
|
162
|
+
created_at: new Date(),
|
|
163
|
+
updated_at: new Date(),
|
|
164
|
+
});
|
|
165
|
+
try {
|
|
166
|
+
await broadcast(`firmware:${deviceId}`, 'rollout', {
|
|
167
|
+
firmware,
|
|
168
|
+
rollout_id: rolloutRow.id,
|
|
169
|
+
});
|
|
170
|
+
await broadcast(`commands:${deviceId}`, 'command', { command: cmd.data });
|
|
171
|
+
}
|
|
172
|
+
catch (_error) {
|
|
173
|
+
/* realtime is best-effort — a failed broadcast does not block the rollout */
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
catch (_error) {
|
|
177
|
+
/* per-target failure already recorded as failed task; continue with remaining targets */
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return { ok: true, rollout: rolloutRow, targets };
|
|
181
|
+
}
|
|
182
|
+
/** Owner-scoped rollout list. */
|
|
183
|
+
export async function listRolloutsForOwner(userId, filters = {}) {
|
|
184
|
+
const where = [
|
|
185
|
+
{ field: 'owner_id', operator: '=', value: userId },
|
|
186
|
+
];
|
|
187
|
+
if (filters.firmware_id) {
|
|
188
|
+
where.push({ field: 'firmware_id', operator: '=', value: filters.firmware_id });
|
|
189
|
+
}
|
|
190
|
+
if (filters.status)
|
|
191
|
+
where.push({ field: 'status', operator: '=', value: filters.status });
|
|
192
|
+
const limit = filters.limit ?? 50;
|
|
193
|
+
const page = filters.page ?? 1;
|
|
194
|
+
return findMany(ROLLOUT_TABLE, {
|
|
195
|
+
where,
|
|
196
|
+
orderBy: [{ field: 'created_at', direction: 'desc' }],
|
|
197
|
+
limit,
|
|
198
|
+
offset: (page - 1) * limit,
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Record a per-device task status report. Updates the rollout's
|
|
203
|
+
* completed/failed counters + progress percent; on success bumps the
|
|
204
|
+
* device's `firmware_version` to the new release.
|
|
205
|
+
*/
|
|
206
|
+
export async function recordRolloutDeviceStatus(opts) {
|
|
207
|
+
const tasks = await findMany(TASK_TABLE, {
|
|
208
|
+
where: [
|
|
209
|
+
{ field: 'rollout_id', operator: '=', value: opts.rolloutId },
|
|
210
|
+
{ field: 'device_id', operator: '=', value: opts.deviceId },
|
|
211
|
+
],
|
|
212
|
+
limit: 1,
|
|
213
|
+
});
|
|
214
|
+
const task = tasks[0];
|
|
215
|
+
if (!task)
|
|
216
|
+
return { ok: false, reason: 'task_not_found' };
|
|
217
|
+
const taskUpdates = {
|
|
218
|
+
status: opts.status,
|
|
219
|
+
error_message: opts.errorMessage ?? null,
|
|
220
|
+
updated_at: new Date(),
|
|
221
|
+
};
|
|
222
|
+
if (opts.status === 'completed' || opts.status === 'failed') {
|
|
223
|
+
taskUpdates.completed_at = new Date();
|
|
224
|
+
}
|
|
225
|
+
await updateById(TASK_TABLE, task.id, taskUpdates);
|
|
226
|
+
const rollout = await findById(ROLLOUT_TABLE, opts.rolloutId);
|
|
227
|
+
if (rollout && rollout.owner_id === opts.ownerId) {
|
|
228
|
+
let completed = Number(rollout.completed_count ?? 0);
|
|
229
|
+
let failed = Number(rollout.failed_count ?? 0);
|
|
230
|
+
if (opts.status === 'completed')
|
|
231
|
+
completed += 1;
|
|
232
|
+
else if (opts.status === 'failed')
|
|
233
|
+
failed += 1;
|
|
234
|
+
const target = Number(rollout.target_count ?? 0);
|
|
235
|
+
const done = completed + failed;
|
|
236
|
+
const progress = target > 0 ? Math.min(100, Math.round((done * 100) / target)) : 100;
|
|
237
|
+
const rolloutUpdates = {
|
|
238
|
+
completed_count: completed,
|
|
239
|
+
failed_count: failed,
|
|
240
|
+
progress_percent: progress,
|
|
241
|
+
updated_at: new Date(),
|
|
242
|
+
};
|
|
243
|
+
if (done >= target)
|
|
244
|
+
rolloutUpdates.status = failed > 0 ? 'failed' : 'completed';
|
|
245
|
+
await updateById(ROLLOUT_TABLE, opts.rolloutId, rolloutUpdates);
|
|
246
|
+
}
|
|
247
|
+
if (opts.status === 'completed') {
|
|
248
|
+
const firmware = await findById(FW_TABLE, task.firmware_id);
|
|
249
|
+
if (firmware) {
|
|
250
|
+
await updateById(DEVICE_TABLE, opts.deviceId, {
|
|
251
|
+
firmware_version: firmware.version,
|
|
252
|
+
updated_at: new Date(),
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return { ok: true };
|
|
257
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for firmware versions + rollouts.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
/** Lifecycle state of a firmware version. */
|
|
7
|
+
export type FirmwareStatus = 'draft' | 'published' | 'deprecated';
|
|
8
|
+
/** Deployment strategy used when rolling out a firmware version to devices. */
|
|
9
|
+
export type RolloutStrategy = 'immediate' | 'canary' | 'gradual';
|
|
10
|
+
/** Current state of a firmware rollout operation. */
|
|
11
|
+
export type RolloutStatus = 'pending' | 'active' | 'completed' | 'failed' | 'canceled';
|
|
12
|
+
/** Current state of an individual device update task within a rollout. */
|
|
13
|
+
export type RolloutTaskStatus = 'pending' | 'in_progress' | 'completed' | 'failed';
|
|
14
|
+
/** Database row representing a firmware version artifact and its metadata. */
|
|
15
|
+
export interface FirmwareVersionRow {
|
|
16
|
+
id: string;
|
|
17
|
+
owner_id: string;
|
|
18
|
+
version: string;
|
|
19
|
+
device_type: string;
|
|
20
|
+
release_notes: string;
|
|
21
|
+
download_url: string | null;
|
|
22
|
+
checksum: string | null;
|
|
23
|
+
file_size: number;
|
|
24
|
+
status: FirmwareStatus;
|
|
25
|
+
released_at: string | Date | null;
|
|
26
|
+
created_at: string | Date;
|
|
27
|
+
updated_at: string | Date;
|
|
28
|
+
}
|
|
29
|
+
/** Database row representing a firmware rollout targeting a fleet or set of devices. */
|
|
30
|
+
export interface FirmwareRolloutRow {
|
|
31
|
+
id: string;
|
|
32
|
+
owner_id: string;
|
|
33
|
+
firmware_id: string;
|
|
34
|
+
fleet_id: string | null;
|
|
35
|
+
device_ids: unknown;
|
|
36
|
+
strategy: RolloutStrategy;
|
|
37
|
+
status: RolloutStatus;
|
|
38
|
+
target_count: number;
|
|
39
|
+
completed_count: number;
|
|
40
|
+
failed_count: number;
|
|
41
|
+
progress_percent: number;
|
|
42
|
+
created_at: string | Date;
|
|
43
|
+
updated_at: string | Date;
|
|
44
|
+
}
|
|
45
|
+
/** Database row representing a single device's update task within a rollout. */
|
|
46
|
+
export interface FirmwareUpdateTaskRow {
|
|
47
|
+
id: string;
|
|
48
|
+
rollout_id: string;
|
|
49
|
+
firmware_id: string;
|
|
50
|
+
device_id: string;
|
|
51
|
+
status: RolloutTaskStatus;
|
|
52
|
+
error_message: string | null;
|
|
53
|
+
completed_at: string | Date | null;
|
|
54
|
+
created_at: string | Date;
|
|
55
|
+
updated_at: string | Date;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,6CAA6C;AAC7C,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,WAAW,GAAG,YAAY,CAAA;AACjE,+EAA+E;AAC/E,MAAM,MAAM,eAAe,GAAG,WAAW,GAAG,QAAQ,GAAG,SAAS,CAAA;AAChE,qDAAqD;AACrD,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,QAAQ,GAAG,WAAW,GAAG,QAAQ,GAAG,UAAU,CAAA;AACtF,0EAA0E;AAC1E,MAAM,MAAM,iBAAiB,GAAG,SAAS,GAAG,aAAa,GAAG,WAAW,GAAG,QAAQ,CAAA;AAElF,8EAA8E;AAC9E,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,MAAM,CAAA;IACV,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;IACf,WAAW,EAAE,MAAM,CAAA;IACnB,aAAa,EAAE,MAAM,CAAA;IACrB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,cAAc,CAAA;IACtB,WAAW,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAA;IACjC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;IACzB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;CAC1B;AAED,wFAAwF;AACxF,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,MAAM,CAAA;IACV,QAAQ,EAAE,MAAM,CAAA;IAChB,WAAW,EAAE,MAAM,CAAA;IACnB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,UAAU,EAAE,OAAO,CAAA;IACnB,QAAQ,EAAE,eAAe,CAAA;IACzB,MAAM,EAAE,aAAa,CAAA;IACrB,YAAY,EAAE,MAAM,CAAA;IACpB,eAAe,EAAE,MAAM,CAAA;IACvB,YAAY,EAAE,MAAM,CAAA;IACpB,gBAAgB,EAAE,MAAM,CAAA;IACxB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;IACzB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;CAC1B;AAED,gFAAgF;AAChF,MAAM,WAAW,qBAAqB;IACpC,EAAE,EAAE,MAAM,CAAA;IACV,UAAU,EAAE,MAAM,CAAA;IAClB,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,iBAAiB,CAAA;IACzB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAA;IAC5B,YAAY,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAA;IAClC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;IACzB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;CAC1B"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod schemas for firmware-resource payloads.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
/** Allowed lifecycle states for a firmware version. */
|
|
8
|
+
export declare const firmwareStatusSchema: z.ZodEnum<{
|
|
9
|
+
draft: "draft";
|
|
10
|
+
published: "published";
|
|
11
|
+
deprecated: "deprecated";
|
|
12
|
+
}>;
|
|
13
|
+
/** Allowed rollout delivery strategies. */
|
|
14
|
+
export declare const rolloutStrategySchema: z.ZodEnum<{
|
|
15
|
+
immediate: "immediate";
|
|
16
|
+
canary: "canary";
|
|
17
|
+
gradual: "gradual";
|
|
18
|
+
}>;
|
|
19
|
+
/** Allowed progress states for a firmware rollout. */
|
|
20
|
+
export declare const rolloutStatusSchema: z.ZodEnum<{
|
|
21
|
+
pending: "pending";
|
|
22
|
+
active: "active";
|
|
23
|
+
completed: "completed";
|
|
24
|
+
failed: "failed";
|
|
25
|
+
canceled: "canceled";
|
|
26
|
+
}>;
|
|
27
|
+
/** Validator for creating a draft firmware version. */
|
|
28
|
+
export declare const createFirmwareSchema: z.ZodObject<{
|
|
29
|
+
version: z.ZodString;
|
|
30
|
+
device_type: z.ZodString;
|
|
31
|
+
release_notes: z.ZodOptional<z.ZodString>;
|
|
32
|
+
download_url: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
33
|
+
checksum: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
34
|
+
file_size: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
|
|
35
|
+
}, z.core.$strip>;
|
|
36
|
+
/** Validator for patching a firmware version (release notes, status, etc). */
|
|
37
|
+
export declare const updateFirmwareSchema: z.ZodObject<{
|
|
38
|
+
release_notes: z.ZodOptional<z.ZodString>;
|
|
39
|
+
download_url: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
40
|
+
checksum: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
41
|
+
file_size: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
|
|
42
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
43
|
+
draft: "draft";
|
|
44
|
+
published: "published";
|
|
45
|
+
deprecated: "deprecated";
|
|
46
|
+
}>>;
|
|
47
|
+
}, z.core.$strip>;
|
|
48
|
+
/** Validator for the firmware-version list query params. */
|
|
49
|
+
export declare const listFirmwareQuerySchema: z.ZodObject<{
|
|
50
|
+
device_type: z.ZodOptional<z.ZodString>;
|
|
51
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
52
|
+
draft: "draft";
|
|
53
|
+
published: "published";
|
|
54
|
+
deprecated: "deprecated";
|
|
55
|
+
}>>;
|
|
56
|
+
page: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
57
|
+
limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
58
|
+
}, z.core.$strip>;
|
|
59
|
+
/** Validator for creating a rollout. */
|
|
60
|
+
export declare const createRolloutSchema: z.ZodObject<{
|
|
61
|
+
firmware_id: z.ZodString;
|
|
62
|
+
device_ids: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
63
|
+
fleet_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
64
|
+
strategy: z.ZodOptional<z.ZodEnum<{
|
|
65
|
+
immediate: "immediate";
|
|
66
|
+
canary: "canary";
|
|
67
|
+
gradual: "gradual";
|
|
68
|
+
}>>;
|
|
69
|
+
}, z.core.$strip>;
|
|
70
|
+
/** Validator for the rollout-list query params. */
|
|
71
|
+
export declare const listRolloutsQuerySchema: z.ZodObject<{
|
|
72
|
+
firmware_id: z.ZodOptional<z.ZodString>;
|
|
73
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
74
|
+
pending: "pending";
|
|
75
|
+
active: "active";
|
|
76
|
+
completed: "completed";
|
|
77
|
+
failed: "failed";
|
|
78
|
+
canceled: "canceled";
|
|
79
|
+
}>>;
|
|
80
|
+
page: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
81
|
+
limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
82
|
+
}, z.core.$strip>;
|
|
83
|
+
/** Validator for a per-device rollout status report. */
|
|
84
|
+
export declare const rolloutDeviceStatusSchema: z.ZodObject<{
|
|
85
|
+
status: z.ZodEnum<{
|
|
86
|
+
pending: "pending";
|
|
87
|
+
completed: "completed";
|
|
88
|
+
failed: "failed";
|
|
89
|
+
in_progress: "in_progress";
|
|
90
|
+
}>;
|
|
91
|
+
error_message: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
92
|
+
}, z.core.$strip>;
|
|
93
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,uDAAuD;AACvD,eAAO,MAAM,oBAAoB;;;;EAA+C,CAAA;AAChF,2CAA2C;AAC3C,eAAO,MAAM,qBAAqB;;;;EAA6C,CAAA;AAC/E,sDAAsD;AACtD,eAAO,MAAM,mBAAmB;;;;;;EAAmE,CAAA;AAEnG,uDAAuD;AACvD,eAAO,MAAM,oBAAoB;;;;;;;iBAO/B,CAAA;AAEF,8EAA8E;AAC9E,eAAO,MAAM,oBAAoB;;;;;;;;;;iBAM/B,CAAA;AAEF,4DAA4D;AAC5D,eAAO,MAAM,uBAAuB;;;;;;;;;iBAKlC,CAAA;AAEF,wCAAwC;AACxC,eAAO,MAAM,mBAAmB;;;;;;;;;iBAK9B,CAAA;AAEF,mDAAmD;AACnD,eAAO,MAAM,uBAAuB;;;;;;;;;;;iBAKlC,CAAA;AAEF,wDAAwD;AACxD,eAAO,MAAM,yBAAyB;;;;;;;;iBAGpC,CAAA"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod schemas for firmware-resource payloads.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
/** Allowed lifecycle states for a firmware version. */
|
|
8
|
+
export const firmwareStatusSchema = z.enum(['draft', 'published', 'deprecated']);
|
|
9
|
+
/** Allowed rollout delivery strategies. */
|
|
10
|
+
export const rolloutStrategySchema = z.enum(['immediate', 'canary', 'gradual']);
|
|
11
|
+
/** Allowed progress states for a firmware rollout. */
|
|
12
|
+
export const rolloutStatusSchema = z.enum(['pending', 'active', 'completed', 'failed', 'canceled']);
|
|
13
|
+
/** Validator for creating a draft firmware version. */
|
|
14
|
+
export const createFirmwareSchema = z.object({
|
|
15
|
+
version: z.string().min(1),
|
|
16
|
+
device_type: z.string().min(1),
|
|
17
|
+
release_notes: z.string().optional(),
|
|
18
|
+
download_url: z.string().url().nullable().optional(),
|
|
19
|
+
checksum: z.string().nullable().optional(),
|
|
20
|
+
file_size: z.coerce.number().int().nonnegative().optional(),
|
|
21
|
+
});
|
|
22
|
+
/** Validator for patching a firmware version (release notes, status, etc). */
|
|
23
|
+
export const updateFirmwareSchema = z.object({
|
|
24
|
+
release_notes: z.string().optional(),
|
|
25
|
+
download_url: z.string().url().nullable().optional(),
|
|
26
|
+
checksum: z.string().nullable().optional(),
|
|
27
|
+
file_size: z.coerce.number().int().nonnegative().optional(),
|
|
28
|
+
status: firmwareStatusSchema.optional(),
|
|
29
|
+
});
|
|
30
|
+
/** Validator for the firmware-version list query params. */
|
|
31
|
+
export const listFirmwareQuerySchema = z.object({
|
|
32
|
+
device_type: z.string().optional(),
|
|
33
|
+
status: firmwareStatusSchema.optional(),
|
|
34
|
+
page: z.coerce.number().int().positive().default(1),
|
|
35
|
+
limit: z.coerce.number().int().positive().max(500).default(50),
|
|
36
|
+
});
|
|
37
|
+
/** Validator for creating a rollout. */
|
|
38
|
+
export const createRolloutSchema = z.object({
|
|
39
|
+
firmware_id: z.string().min(1),
|
|
40
|
+
device_ids: z.array(z.string()).optional(),
|
|
41
|
+
fleet_id: z.string().nullable().optional(),
|
|
42
|
+
strategy: rolloutStrategySchema.optional(),
|
|
43
|
+
});
|
|
44
|
+
/** Validator for the rollout-list query params. */
|
|
45
|
+
export const listRolloutsQuerySchema = z.object({
|
|
46
|
+
firmware_id: z.string().optional(),
|
|
47
|
+
status: rolloutStatusSchema.optional(),
|
|
48
|
+
page: z.coerce.number().int().positive().default(1),
|
|
49
|
+
limit: z.coerce.number().int().positive().max(500).default(50),
|
|
50
|
+
});
|
|
51
|
+
/** Validator for a per-device rollout status report. */
|
|
52
|
+
export const rolloutDeviceStatusSchema = z.object({
|
|
53
|
+
status: z.enum(['pending', 'in_progress', 'completed', 'failed']),
|
|
54
|
+
error_message: z.string().nullable().optional(),
|
|
55
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@molecule/api-resource-firmware",
|
|
3
|
+
"version": "1.0.0",
|
|
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.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"test": "vitest run",
|
|
11
|
+
"test:watch": "vitest"
|
|
12
|
+
},
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"keywords": [
|
|
23
|
+
"molecule",
|
|
24
|
+
"firmware",
|
|
25
|
+
"ota",
|
|
26
|
+
"iot",
|
|
27
|
+
"rollout",
|
|
28
|
+
"resource"
|
|
29
|
+
],
|
|
30
|
+
"license": "Apache-2.0",
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/express": "5.0.6",
|
|
33
|
+
"@types/node": "26.1.2",
|
|
34
|
+
"express": "5.2.1",
|
|
35
|
+
"typescript": "6.0.3",
|
|
36
|
+
"vitest": "4.1.10",
|
|
37
|
+
"zod": "4.4.3"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"@molecule/api-bonds-default-express": "^1.0.0",
|
|
41
|
+
"@molecule/api-database": "^1.0.0",
|
|
42
|
+
"@molecule/api-i18n": "^1.0.0",
|
|
43
|
+
"@molecule/api-logger": "^1.0.0",
|
|
44
|
+
"@molecule/api-middleware-validation": "^1.0.0",
|
|
45
|
+
"@molecule/api-realtime": "^1.0.0",
|
|
46
|
+
"express": "^5.0.0",
|
|
47
|
+
"zod": "^4.0.0"
|
|
48
|
+
}
|
|
49
|
+
}
|