@astrofoundry/pi-astro 0.40.68 → 0.40.69
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/package.json
CHANGED
|
@@ -245,11 +245,13 @@ export function deviceNetworkWrite(args: string[]): UnifiWrite {
|
|
|
245
245
|
}
|
|
246
246
|
|
|
247
247
|
const CLIENT_FIXED_IP_KEYS = new Set(["use_fixedip", "fixed_ip", "network_id"]);
|
|
248
|
+
/** A client record's `_id`: 24 hex digits, or a UUID (Mira's console returned UUIDs on 2026-11-12). */
|
|
249
|
+
const CLIENT_ID = /^(?:[0-9a-f]{24}|[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$/;
|
|
248
250
|
|
|
249
251
|
/** `client-fixed-ip <clientId> <json>`: only a known client's DHCP reservation, through the application's client records. */
|
|
250
252
|
export function clientFixedIpWrite(args: string[]): UnifiWrite {
|
|
251
253
|
const [id, json, ...extra] = args;
|
|
252
|
-
if (id === undefined || !
|
|
254
|
+
if (id === undefined || !CLIENT_ID.test(id) || json === undefined || extra.length > 0) throw new UsageError("client-fixed-ip <clientId> <json>");
|
|
253
255
|
const body = jsonBody(json);
|
|
254
256
|
const keys = Object.keys(JSON.parse(body) as Record<string, unknown>);
|
|
255
257
|
if (keys.length === 0 || keys.some((k) => !CLIENT_FIXED_IP_KEYS.has(k))) throw new UsageError(`client-fixed-ip body keys: ${[...CLIENT_FIXED_IP_KEYS].join(", ")}`);
|
|
@@ -155,6 +155,8 @@ describe("network wrapper", () => {
|
|
|
155
155
|
expect(() => portForwardDelete(["../x", "qb"])).toThrow(UsageError);
|
|
156
156
|
const fixed = JSON.stringify({ use_fixedip: true, fixed_ip: "10.1.50.50", network_id: "0123456789abcdef01234567" });
|
|
157
157
|
expect(clientFixedIpWrite(["0123456789abcdef01234567", fixed])).toEqual({ method: "PUT", path: "/api/s/default/rest/user/0123456789abcdef01234567", body: fixed });
|
|
158
|
+
expect(clientFixedIpWrite(["071e4027-d2e9-4f61-9fc4-5a92e85cf842", fixed]).path).toBe("/api/s/default/rest/user/071e4027-d2e9-4f61-9fc4-5a92e85cf842");
|
|
159
|
+
expect(() => clientFixedIpWrite(["071e4027-d2e9-4f61-9fc4-5a92e85cf84/..", fixed])).toThrow(/client-fixed-ip/);
|
|
158
160
|
expect(() => clientFixedIpWrite(["0123456789abcdef01234567", JSON.stringify({ name: "x" })])).toThrow(/body keys/);
|
|
159
161
|
expect(appGetPath(["/v2/api/site/default/nat"])).toBe("/v2/api/site/default/nat");
|
|
160
162
|
expect(() => appGetPath(["/api/s/other/stat/device"])).toThrow(UsageError);
|