refactor: extract seed provision scripts to dedicated directory

Move bootstrap, default, and inform scripts from inline template
strings in lib/init.ts to standalone files under seed/, loaded via
an esbuild text-loader plugin. Add type-checking (provisions.d.ts,
tsconfig.json) and ESLint config for the seed scripts. Set tsconfig
module to Preserve to support import attributes.
This commit is contained in:
Zaid Humaimidi committed 2026-03-13 13:48:45 -07:00
1 parent f39e2ce7cf
commit d445aa03cf
10 files changed
+236 -56

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
const now = Date.now();
// Clear cached data model to force a refresh
clear("Device", now);
clear("InternetGatewayDevice", now);
+40
View File
@@ -0,0 +1,40 @@
const hourly = Date.now(3600000);
// Refresh basic parameters hourly
declare("InternetGatewayDevice.DeviceInfo.HardwareVersion", {
path: hourly,
value: hourly,
});
declare("InternetGatewayDevice.DeviceInfo.SoftwareVersion", {
path: hourly,
value: hourly,
});
declare(
"InternetGatewayDevice.WANDevice.*.WANConnectionDevice.*.WANIPConnection.*.MACAddress",
{ path: hourly, value: hourly },
);
declare(
"InternetGatewayDevice.WANDevice.*.WANConnectionDevice.*.WANIPConnection.*.ExternalIPAddress",
{ path: hourly, value: hourly },
);
declare("InternetGatewayDevice.LANDevice.*.WLANConfiguration.*.SSID", {
path: hourly,
value: hourly,
});
// Don't refresh password field periodically because CPEs always report blank passowrds for security reasons
declare("InternetGatewayDevice.LANDevice.*.WLANConfiguration.*.KeyPassphrase", {
path: hourly,
value: 1,
});
declare("InternetGatewayDevice.LANDevice.*.Hosts.Host.*.HostName", {
path: hourly,
value: hourly,
});
declare("InternetGatewayDevice.LANDevice.*.Hosts.Host.*.IPAddress", {
path: hourly,
value: hourly,
});
declare("InternetGatewayDevice.LANDevice.*.Hosts.Host.*.MACAddress", {
path: hourly,
value: hourly,
});
+67
View File
@@ -0,0 +1,67 @@
// Device ID as user name
const username = declare("DeviceID.ID", { value: 1 }).value[0];
// Password will be fixed for a given device because Math.random() is seeded with device ID by default.
const password = Math.trunc(Math.random() * Number.MAX_SAFE_INTEGER).toString(
36,
);
const informInterval = 300;
// Refresh values daily
const daily = Date.now(86400000);
// Unique inform offset per device for better load distribution
const informTime = daily % 86400000;
declare(
"InternetGatewayDevice.ManagementServer.ConnectionRequestUsername",
{ value: daily },
{ value: username },
);
declare(
"InternetGatewayDevice.ManagementServer.ConnectionRequestPassword",
{ value: daily },
{ value: password },
);
declare(
"InternetGatewayDevice.ManagementServer.PeriodicInformEnable",
{ value: daily },
{ value: true },
);
declare(
"InternetGatewayDevice.ManagementServer.PeriodicInformInterval",
{ value: daily },
{ value: informInterval },
);
declare(
"InternetGatewayDevice.ManagementServer.PeriodicInformTime",
{ value: daily },
{ value: informTime },
);
declare(
"Device.ManagementServer.ConnectionRequestUsername",
{ value: daily },
{ value: username },
);
declare(
"Device.ManagementServer.ConnectionRequestPassword",
{ value: daily },
{ value: password },
);
declare(
"Device.ManagementServer.PeriodicInformEnable",
{ value: daily },
{ value: true },
);
declare(
"Device.ManagementServer.PeriodicInformInterval",
{ value: daily },
{ value: informInterval },
);
declare(
"Device.ManagementServer.PeriodicInformTime",
{ value: daily },
{ value: informTime },
);
+71
View File
@@ -0,0 +1,71 @@
interface Timestamps {
path?: number;
object?: number;
writable?: number;
value?: number;
notification?: number;
accessList?: number;
}
interface Values {
path?: number | [number, number];
object?: boolean;
writable?: boolean;
value?: string | number | boolean | [string | number | boolean, string?];
notification?: number;
accessList?: string[];
}
interface ParameterWrapper extends Iterable<ParameterWrapper> {
readonly path: string | undefined;
readonly size: number | undefined;
readonly object: 0 | 1 | undefined;
readonly writable: 0 | 1 | undefined;
readonly value: [string | number | boolean, string] | undefined;
readonly notification: number | undefined;
readonly accessList: string[] | undefined;
}
declare function declare(
path: string,
timestamps?: Timestamps | null,
values?: Values | null,
): ParameterWrapper;
declare function clear(
path: string,
timestamp: number,
attributes?: Timestamps,
): void;
declare function commit(): void;
declare function ext(...args: unknown[]): unknown;
declare function log(msg: string, meta?: Record<string, unknown>): void;
declare const args: unknown[];
interface DateConstructor {
new (): Date;
new (
year: number,
monthIndex?: number,
day?: number,
hours?: number,
minutes?: number,
seconds?: number,
milliseconds?: number,
): Date;
now(intervalOrCron?: number | string, variance?: number): number;
parse(dateString: string): number;
UTC(
year: number,
monthIndex?: number,
day?: number,
hours?: number,
minutes?: number,
seconds?: number,
milliseconds?: number,
): number;
}
+10
View File
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"noEmit": true,
"target": "ES2022",
"types": []
},
"include": ["./*.js", "./*.d.ts"]
}