Repository: zaidka/genieacs Branch: master Commit: 7546ab833a99 Files: 187 Total size: 1.6 MB Directory structure: gitextract_j_xjh90s/ ├── .gitignore ├── .prettierignore ├── AGENTS.md ├── ARCHITECTURE.md ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── bin/ │ ├── genieacs-cwmp.ts │ ├── genieacs-ext.ts │ ├── genieacs-fs.ts │ ├── genieacs-nbi.ts │ └── genieacs-ui.ts ├── build/ │ ├── assets.ts │ ├── build.ts │ ├── generate-fonts.sh │ ├── lint.ts │ ├── spellcheck-dict.pws │ ├── spellcheck.sh │ └── test.ts ├── docs/ │ ├── .readthedocs.yaml │ ├── administration-faq.rst │ ├── api-reference.rst │ ├── conf.py │ ├── cpe-authentication.rst │ ├── environment-variables.rst │ ├── ext-sample.js │ ├── extensions.rst │ ├── https.rst │ ├── index.rst │ ├── installation-guide.rst │ ├── provisions.rst │ ├── requirements.txt │ ├── roles-and-permissions.rst │ └── virtual-parameters.rst ├── eslint.config.mjs ├── lib/ │ ├── api-functions.ts │ ├── auth.ts │ ├── bundle-views.ts │ ├── cache.ts │ ├── cluster.ts │ ├── common/ │ │ ├── authorizer.ts │ │ ├── debounce.ts │ │ ├── errors.ts │ │ ├── expression/ │ │ │ ├── evaluate.ts │ │ │ ├── normalize.ts │ │ │ ├── pagination.ts │ │ │ ├── parser.ts │ │ │ └── synth.ts │ │ ├── expression.ts │ │ ├── memoize.ts │ │ ├── path-set.ts │ │ ├── path.ts │ │ └── yaml.ts │ ├── config.ts │ ├── connection-request.ts │ ├── cwmp/ │ │ ├── db.ts │ │ └── local-cache.ts │ ├── cwmp.ts │ ├── db/ │ │ ├── db.ts │ │ ├── synth.ts │ │ ├── types.ts │ │ └── util.ts │ ├── debug.ts │ ├── default-provisions.ts │ ├── device.ts │ ├── extensions.ts │ ├── forwarded.ts │ ├── fs.ts │ ├── gpn-heuristic.ts │ ├── init.ts │ ├── instance-set.ts │ ├── local-cache.ts │ ├── lock.ts │ ├── logger.ts │ ├── nbi.ts │ ├── ping.ts │ ├── query.ts │ ├── sandbox.ts │ ├── scheduling.ts │ ├── server.ts │ ├── session.ts │ ├── soap.ts │ ├── types.ts │ ├── ui/ │ │ ├── api.ts │ │ ├── db.ts │ │ └── local-cache.ts │ ├── ui.ts │ ├── util.ts │ ├── versioned-map.ts │ ├── xml-parser.ts │ └── xmpp-client.ts ├── npm-shrinkwrap.json ├── package.json ├── seed/ │ ├── bootstrap.js │ ├── datamodel-explorer.jsx │ ├── default.js │ ├── device-page-tr098.jsx │ ├── device-page-tr181.jsx │ ├── device-page.jsx │ ├── icon.jsx │ ├── inform.js │ ├── instance-table.jsx │ ├── overview-page.jsx │ ├── parameter.jsx │ ├── pie-chart.jsx │ ├── provisions.d.ts │ ├── summon-button.jsx │ ├── tags.jsx │ ├── tsconfig.json │ └── views.d.ts ├── test/ │ ├── auth.ts │ ├── db.ts │ ├── device.ts │ ├── mocks/ │ │ └── store.ts │ ├── pagination.ts │ ├── path-set.ts │ ├── path.ts │ ├── ping.ts │ ├── reactive-store.ts │ ├── signals.ts │ ├── synth.ts │ ├── util.ts │ ├── xml-parser.ts │ ├── yaml-tests.json │ └── yaml.ts ├── tsconfig.json └── ui/ ├── app.ts ├── autocomplete-compnent.ts ├── change-password-component.ts ├── code-editor-component.ts ├── codemirror-loader.ts ├── components/ │ ├── all-parameters.ts │ ├── container.ts │ ├── device-actions.ts │ ├── device-faults.ts │ ├── device-link.ts │ ├── loading.ts │ ├── overview-dot.ts │ ├── parameter-list.ts │ ├── parameter-table.ts │ ├── parameter.ts │ ├── ping.ts │ ├── summon-button.ts │ └── tags.ts ├── components.ts ├── config-functions.ts ├── config-page.ts ├── config.ts ├── css/ │ └── app.css ├── datalist.ts ├── device-page.ts ├── devices-page.ts ├── drawer-component.ts ├── dynamic-loader.ts ├── error-page.ts ├── faults-page.ts ├── files-page.ts ├── filter-component.ts ├── index-table-component.ts ├── layout.tsx ├── login-page.tsx ├── long-text-component.ts ├── notifications.ts ├── overlay.ts ├── overview-page.ts ├── permissions-page.ts ├── pie-chart-component.ts ├── presets-page.ts ├── provisions-page.ts ├── put-form-component.ts ├── reactive-store.ts ├── signals.ts ├── skewed-date.ts ├── smart-query.ts ├── store.ts ├── tailwind-utility-components.ts ├── task-queue.ts ├── timeago.ts ├── ui-config-component.ts ├── users-page.ts ├── views-bundle-placeholder.ts ├── views-page.ts ├── views.ts ├── virtual-parameters-page.ts ├── wizard-page.ts └── yaml-loader.ts ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ *~ node_modules dist docs/_build ================================================ FILE: .prettierignore ================================================ dist npm-shrinkwrap.json ================================================ FILE: AGENTS.md ================================================ # AGENTS.md — GenieACS GenieACS is a TR-069 Auto Configuration Server for remote management of CPE devices (routers, modems, gateways). TypeScript codebase compiled with esbuild, backed by MongoDB. ## Architecture Overview Four services share a single MongoDB instance: - **CWMP** (port 7547) — TR-069 protocol handler; manages device sessions - **NBI** (port 7557) — Northbound REST API for external consumers - **FS** (port 7567) — File server for firmware/config (GridFS-backed) - **UI** (port 3000) — Web interface (Koa backend + Mithril.js SPA frontend) Key subsystems: expression engine (`lib/common/expression/`) compiles a Lisp-like DSL used for queries, config, and authorization; session engine (`lib/session.ts`) drives CWMP interactions via declarations rather than imperative RPCs; sandbox (`lib/sandbox.ts`) runs user-defined provision scripts in `vm.Script` with deterministic replay. Read `ARCHITECTURE.md` for a full map of the codebase when working on unfamiliar areas. It covers service boundaries, the expression pipeline, the path system, the CWMP session state machine, the database layer, and architectural invariants. ## Project Structure - `lib/` — Core server-side logic - `lib/common/` — Shared code (runs in both Node.js and browser) - `lib/db/` — MongoDB database layer - `lib/ui/` — UI backend helpers - `ui/` — Frontend SPA (Mithril.js) - `bin/` — Service entry points (5 executables) - `build/` — Build scripts (esbuild pipeline) - `test/` — Unit tests (node:test) - `docs/` — User docs (Sphinx/reStructuredText) - `public/` — Static assets (favicon, logo) ## Build / Lint / Test Commands ```bash npm run build # Production build (esbuild pipeline -> dist/) NODE_ENV=development npm run build # Dev build (no minification) npm run lint # Prettier + ESLint + tsc --noEmit in parallel npm test # Compile tests with esbuild, run with node --test ``` ### Running a Single Test File ```bash esbuild --log-level=warning --bundle --platform=node --target=node18 \ --packages=external --sourcemap=inline --outdir=test test/path.ts \ && node --test --enable-source-maps test/path.js \ && rm test/path.js ``` ### Running a Single Test Case ```bash esbuild --log-level=warning --bundle --platform=node --target=node18 \ --packages=external --sourcemap=inline --outdir=test test/path.ts \ && node --test --enable-source-maps --test-name-pattern="^parse$" test/path.js \ && rm test/path.js ``` ### Lint Sub-commands ```bash prettier --prose-wrap always --write . eslint 'bin/*.ts' 'lib/**/*.ts' 'ui/**/*.ts' 'test/**/*.ts' 'build/**/*.ts' tsc --noEmit ``` ## Before Committing Read `CONTRIBUTING.md` and ensure your changes comply with it. In particular: - Run `npm run lint` and `npm test` and fix any failures. - Follow the code style, naming, import, and comment conventions documented there. - Use the Conventional Commits format for commit messages. ================================================ FILE: ARCHITECTURE.md ================================================ # Architecture This document describes the high-level architecture of GenieACS. If you want to familiarize yourself with the codebase, you are in the right place. ## Bird's Eye View GenieACS is a TR-069 Auto Configuration Server (ACS). It manages CPE devices (routers, modems, gateways) using the CWMP protocol (TR-069). The system consists of four network-facing services that share a MongoDB database: ``` +------------+ CPE Devices --->| CWMP (7547)|-+ +------------+ | +-----------+ | +---------+ CPE Devices --->| FS (7567) |--+---->| MongoDB | +-----------+ | +---------+ +-----------+ | OSS / Scripts ->| NBI (7557)|--+ +-----------+ | +-----------+ | Administrators->| UI (3000) |--+ +-----------+ ``` - **CWMP** -- The core TR-069 protocol server. CPE devices connect here to report their state and receive configuration instructions via SOAP/XML over HTTP. - **NBI** -- Northbound Interface. A REST API for external systems (OSS/BSS, scripts, automation) to manage devices, tasks, presets, and configuration programmatically. - **FS** -- File Server. Serves firmware images and configuration files to CPE devices during download operations. - **UI** -- Web interface. A Koa-based backend serving a Mithril.js single-page application for administrators to browse devices, manage configuration, and trigger operations. All four services follow the same process model: a primary process forks configurable worker processes via Node.js `cluster` (see `cluster.ts`). Workers connect to MongoDB and start an HTTP(S) server. ## Code Map ``` bin/ Service entry points (5 executables) lib/ All backend logic common/ Shared utilities (expression engine, Path, errors) expression.ts Expression class hierarchy (base + subclasses) expression/ Expression parser, evaluator, normalizer, minimizer cwmp/ CWMP-service-specific DB and caching db/ Database layer (MongoDB collections, query synthesis) ui/ UI-service-specific API, DB, and caching types/ (empty, reserved) ui/ Frontend SPA (Mithril.js) components/ Reusable UI components (parameter, tags, ping, etc.) css/ Stylesheets (vanilla CSS) icons/ SVG icons (compiled into a sprite) test/ Unit tests (Node.js native test runner) build/ Build scripts (esbuild-based) public/ Static assets (logo, favicon) ``` ### Entry Points (`bin/`) Each file in `bin/` bootstraps one service. They are structurally identical: initialize logging, read config, fork workers in the primary process, connect to MongoDB and start the HTTP server in each worker. - `genieacs-cwmp.ts` -- CWMP service. Unique in that it disables HTTP keep-alive (`keepAliveTimeout: 0`) and provides custom `onConnection` / `onClientError` hooks for TR-069 session lifecycle management. - `genieacs-nbi.ts` -- NBI service. Straightforward REST API server. - `genieacs-fs.ts` -- File server. The leanest service; does not use the extensions subsystem. - `genieacs-ui.ts` -- UI service. Wraps the Koa application as the HTTP listener. - `genieacs-ext.ts` -- **Not a service.** This is a child process worker spawned by the extensions subsystem. It communicates with its parent via IPC, executing user-defined extension scripts in isolation. ### The Expression System (`lib/common/expression.ts`, `lib/common/expression/`) The `Expression` class (defined in `lib/common/expression.ts`) is the most important abstraction in the codebase. It uses a typed class hierarchy: `Expression.Literal` (wraps `string | number | boolean | null`), `Expression.Parameter` (wraps a `Path`), `Expression.Binary` (operator + left/right), `Expression.Unary` (operator + operand), `Expression.FunctionCall` (name + args), and `Expression.Conditional` (condition/then/otherwise). For example, in the SQL-like text syntax: ``` Device.ModelName = "BrandX" AND Events.Inform > 1000 ``` Expressions are used pervasively: - **Query/filter language** -- Database queries for devices, faults, presets, etc. are all represented as expressions and compiled to MongoDB filters. - **Configuration values** -- Config entries and preset preconditions are expressions, enabling dynamic evaluation. - **Authorization** -- Permission filters and validators are expressions. - **Pagination cursors** -- Keyset pagination boundaries are expressed as filter expressions. The expression pipeline flows through four modules: 1. `parser.ts` -- Parses a SQL-like text syntax into the AST using a hand-rolled recursive descent parser with a `Cursor`-based scanner. Also provides `stringifyExpression()` for serialization. The `map()` / `mapAsync()` tree-walking primitives are abstract methods on the `Expression` class, and `stringify()` is now `Expression.toString()`. 2. `normalize.ts` -- Algebraic normalization using exact rational polynomial arithmetic over native `bigint` values. The `Polynomial` class extends `Expression` as an intermediate representation. Ensures equivalent expressions have the same canonical form (e.g., `a + 2 > b` and `a > b - 2` normalize identically). 3. `synth.ts` -- Boolean logic minimization via the Espresso algorithm (espresso-iisojs). Converts expressions to minimal sum-of-products form with three-valued logic (true/false/null). Handles domain-specific constraints like comparison ordering and LIKE pattern relationships. 4. `evaluate.ts` -- Runtime evaluation. The `reduce()` function evaluates operators on literal values and supports partial evaluation (returns a reduced expression if some values are unknown). Parameter resolution is handled by the `Expression.evaluate()` method (in `lib/common/expression.ts`) which calls `reduce()` after mapping children via a user-supplied callback. `pagination.ts` implements cursor-based pagination by generating filter expressions from sort-key bookmarks. ### The Path System (`lib/common/path.ts`, `lib/common/path-set.ts`) `Path` represents a TR-069 parameter path (e.g., `Device.WiFi.SSID.1.Name`). Paths can contain wildcards (`*`) and alias expressions (`[key:value]`) for query-based addressing. Key design decisions: - **Cached** -- `Path.parse()` caches instances in a two-generation LRU cache rotated every 120 seconds. The constructor is public (used directly by the parser and by methods like `slice()`, `concat()`, and `stripAlias()`). - **Bitmask encoding** -- The `wildcard` and `alias` fields are bitfields for O(1) segment-type checking. This limits paths to 32 segments. A `colon` field tracks the number of attribute path segments (after a `:` separator), enabling `paramLength` and `attrLength` accessors. - **Immutable** -- Segment arrays are `Object.freeze()`-d. `PathSet` is a multi-indexed collection of paths supporting pattern-matching queries. It maintains separate `paramSegmentIndex` and `attrSegmentIndex` arrays (one `Map>` per position), plus a `stringIndex` map. The `find()` method takes bitmasks to control which segments require exact matches vs. wildcard compatibility, then uses set intersection across the smallest index sets. A higher-level `findCompat()` method computes the appropriate bitmasks for superset/subset matching. ### CWMP Protocol Layer (`lib/cwmp.ts`, `lib/soap.ts`, `lib/xml-parser.ts`) `xml-parser.ts` is a custom single-pass XML parser (no DOM). It scans character-by-character with bitwise state flags, building a tree of elements with namespace support. Does not support CDATA. `soap.ts` handles both parsing CPE SOAP messages and generating ACS SOAP responses. It dispatches on the SOAP body's method name to type-specific parsers for Inform, TransferComplete, GetParameterNamesResponse, etc. Supports CWMP versions 1.0 through 1.4. `cwmp.ts` is the HTTP-level CWMP request handler. It manages the session state machine: 1. **State 0** -- Expects an Inform. Authenticates the device (Basic or Digest auth, configurable via expression). Acquires a distributed lock. Loads device data from MongoDB. Sends InformResponse. 2. **State 1** -- Waits for the CPE to send an empty POST (ready for ACS RPCs). Processes any TransferComplete messages. 3. **State 2** -- The ACS drives RPCs (GetParameterNames, GetParameterValues, SetParameterValues, AddObject, DeleteObject, Download, Reboot, FactoryReset). The CPE responds to each. Session persistence across TCP disconnects: when a socket closes mid-session, the entire `SessionContext` is serialized to Redis (the MongoDB `cache` collection) and restored when the CPE reconnects (identified by a session cookie). ### Session Engine (`lib/session.ts`) The session engine implements the **declaration-driven data fetching** pattern. Rather than issuing RPCs imperatively, provisions create `Declaration` objects stating what paths and attributes they need to read or write. The engine then: 1. Processes all declarations into a `SyncState` -- a structured plan of which parameters to refresh, which values to set, which instances to create/delete, etc. 2. Generates the minimal set of CWMP RPCs needed to fulfill the plan. 3. After each RPC response, updates `DeviceData` and re-evaluates. 4. Iterates until all declarations are satisfied. The preset system (`applyPresets` in `cwmp.ts`) implements a policy engine: presets are rules with precondition expressions that, when matched, contribute provisions to the session. After provisions execute, if device data changed, presets are re-evaluated (up to 4 cycles to prevent infinite loops). ### Provisions and Virtual Parameters **Provisions** are the unit of configuration intent. Built-in provisions (`default-provisions.ts`) include `refresh`, `value`, `tag`, `reboot`, `reset`, `download`, and `instances`. Custom provisions are user-defined JavaScript scripts stored in the `provisions` MongoDB collection. **Virtual parameters** are scripts that present computed/derived values as if they were real device parameters under the `VirtualParameters.*` namespace. They run in two phases: a "get" phase reads real parameters and returns a computed value; a "set" phase translates a desired value into real parameter changes. Virtual parameters can reference other virtual parameters (up to depth 8). ### Sandbox (`lib/sandbox.ts`) The sandbox provides a secure execution environment for provision and virtual parameter scripts using `vm.Script` with a 50ms timeout. It uses a **replay-based execution model**: 1. A script runs and calls `declare()` to request data. 2. When `commit()` is called, the script throws a sentinel symbol and exits. 3. The engine fetches the requested data via CWMP RPCs. 4. The script is **re-run from the beginning** with the fetched data available. 5. Earlier `declare()` calls return cached results; the script progresses further. 6. This repeats until the script completes without throwing. The sandbox API: `declare(path, timestamps, values)` returns a `ParameterWrapper` proxy; `clear(path, timestamp, attributes)` invalidates cached data; `ext(...args)` calls external extensions (results are cached per revision to survive replays); `commit()` explicitly triggers a fetch cycle. `Math.random()` is replaced with a seeded PRNG for determinism. ### Device Data Model (`lib/types.ts`, `lib/device.ts`) `DeviceData` is the in-memory working copy of a device's parameter tree during a session: - `paths: PathSet` -- All known parameter paths. - `timestamps: VersionedMap` -- When each path was last refreshed. - `attributes: VersionedMap` -- Per-path attributes (object, writable, value, notification, accessList), each paired with a timestamp. - `trackers` / `changes` -- Change tracking for re-evaluation. `VersionedMap` (in `versioned-map.ts`) provides multi-revision snapshots, enabling the sandbox replay model where scripts may be re-run at different revision levels. `device.ts` handles setting and clearing parameter data with invariant enforcement (e.g., if `value` is set, `object` is forced to 0; parent paths are ensured to exist). The `unpack()` function resolves wildcards and alias paths against concrete device data. ### NBI (`lib/nbi.ts`) A raw Node.js HTTP listener (no framework) with regex-based URL routing. Endpoints include CRUD for presets, provisions, virtual parameters, objects, and files; device task management (with optional synchronous execution via connection request); fault management; generic collection querying; and ping. The NBI uses MongoDB-style JSON queries directly. For the `devices` collection, `query.ts` expands user-friendly queries by auto-appending `._value` to parameter paths and generating multi-type interpretations (string, number, date, regex) for filter values. ### File Server (`lib/fs.ts`) A minimal HTTP file server reading from MongoDB GridFS. Supports GET/HEAD with full HTTP caching (ETag, Last-Modified, If-None-Match, If-Modified-Since) and Range requests (HTTP 206) for partial content downloads. Files are cached in-memory via memoization. ### UI Backend (`lib/ui.ts`, `lib/ui/`) A Koa application with JWT authentication, role-based authorization, and a rich CRUD API under `/api/`. The root route serves an HTML shell that bootstraps the Mithril.js SPA with injected config, user info, and hashed asset filenames. `lib/ui/api.ts` defines generic CRUD endpoints for all resource types (devices, presets, provisions, files, config, users, permissions, faults, tasks) with authorization checks at every level. Specialized endpoints handle file upload/download, synchronous task execution, tag management, password changes, and CSV export. `lib/ui/db.ts` translates between the UI's flat parameter representation and MongoDB's nested document structure. The `flattenDevice()` function is the key transformation: it recursively walks the nested device document and produces a flat key-value map with colon-delimited attribute keys (e.g., `"Device.WiFi.SSID.1.Name" -> value`, `"Device.WiFi.SSID.1.Name:type" -> "xsd:string"`, `"Device.WiFi.SSID.1.Name:writable" -> true`). The `FlatDevice` type is `Record` where `Value = string | number | boolean | null`. `lib/ui/local-cache.ts` caches permissions, users, and config in-process with hash-based revision tracking. The `getConfig()` function uses typed overloads -- it takes a typed default value (`string`, `number`, or `boolean`) and an expression evaluation callback, returning a value of the same type as the default. ### Database Layer (`lib/db/`) `db/db.ts` is the single entry point to MongoDB. It manages 14 collections: | Collection | Purpose | | ------------------- | -------------------------------- | | `devices` | CPE device parameter trees | | `presets` | Configuration rules | | `provisions` | Provision scripts | | `virtualParameters` | Virtual parameter scripts | | `objects` | Generic objects | | `tasks` | Queued device management tasks | | `faults` | Error records with retry state | | `operations` | In-flight async operations | | `files` (GridFS) | Firmware images and config files | | `permissions` | RBAC rules | | `users` | User accounts | | `config` | Key-value configuration | | `cache` | Distributed cache (TTL index) | | `locks` | Distributed locks (TTL index) | `db/synth.ts` is the sophisticated expression-to-MongoDB query compiler. It normalizes expressions, converts them to a Boolean satisfiability representation using the `Clause` hierarchy, minimizes via Espresso, and emits MongoDB `$and`/`$or`/`$not` filter objects. This is used by the UI backend. `cwmp/db.ts` handles CWMP-specific persistence: loading the nested device document into `DeviceData` (`fetchDevice`), diffing changes back into MongoDB update operations (`saveDevice`), and managing faults, tasks, and operations. ### Query Systems There are two separate query paths: 1. **NBI queries** (`lib/query.ts`) -- Processes MongoDB-style JSON queries from external API consumers. Expands parameter names, generates multi-type value interpretations, and passes through to MongoDB directly. 2. **UI/Expression queries** (`lib/db/synth.ts`) -- Compiles the internal expression language into optimized MongoDB filters via Boolean minimization. This is the more sophisticated path, used by the UI backend. ### Frontend (`ui/`) A Mithril.js SPA with hash-based routing (`#!/`). Key modules: - `app.ts` -- Route definitions. The `pagify()` function wraps each page into a `RouteResolver` that handles initialization, error boundaries, and data fulfillment. - `layout.ts` -- Top-level layout (header, navigation, content, overlay). - `store.ts` -- Centralized data store. Implements a query-based reactive cache with deduplication and incremental fetching. The `fulfill()` method (called after every render) batches pending queries, computes filter diffs via `unionDiff()`, and fetches only missing data. Connection monitoring polls every 3 seconds for server health, clock skew, and config changes. - `components.ts` -- Component registry with a context propagation system. The proxied `m()` function resolves string component names and the `m.context()` API passes data (like the current device object) down the component tree without explicit prop threading. - `smart-query.ts` -- Translates user-friendly `Label: value` searches into filter expressions with type-aware matching (string, number, timestamp, MAC address, tag). - `task-queue.ts` -- Two-stage task pipeline: staging (user configures tasks) then queue (tasks are committed and executed via the backend). - `dynamic-loader.ts` -- Lazy loading of heavy libraries (CodeMirror, YAML) via dynamic `import()`. ### Build System (`build/`) The build is a self-bootstrapping esbuild pipeline (`npm run build` pipes `build/build.ts` through esbuild then node). It produces: - **Backend binaries** -- 5 entry points bundled for Node.js 12+ with shebang banners, executable permissions, and `.js` extension stripped. - **Frontend bundle** -- `ui/app.ts` bundled for browsers (ESM, code-split) with content-hashed filenames. - **CSS** -- `ui/css/app.css` bundled and minified with content-hashed output. - **SVG sprite** -- All icons in `ui/icons/` optimized via SVGO and combined into a single sprite. `build/assets.ts` is a compile-time bridge: at rest it contains placeholder filenames; during build, the `assetsPlugin` replaces them with actual content-hashed names so both backend and frontend reference the correct assets. Build metadata includes the date and a hash derived from the git state, appended to the package version. ## Cross-Cutting Concerns ### Multi-Level Caching ``` memoize.ts In-process function cache (2-4 min, two-generation rotation) | local-cache.ts In-process snapshot cache (5s refresh, hash-based revisions) | cache.ts MongoDB-backed distributed cache (configurable TTL) | MongoDB TTL index auto-expiration ``` Each service has its own `local-cache` that periodically checks the distributed cache for staleness. Distributed locks (`lock.ts`) coordinate rebuilds so only one worker does the expensive computation. ### Configuration (`lib/config.ts`) Three-tier priority: CLI args > environment variables (`GENIEACS_*`) > config file (`config.json`) > defaults. Supports per-device overrides by appending `-OUI-ProductClass-SerialNumber` to option names. ### Distributed Locking (`lib/lock.ts`) MongoDB-based mutual exclusion using upsert + duplicate key detection. TTL indexes prevent deadlocks from crashed processes. Clock skew tolerance of 30 seconds. ### Authentication - **CWMP devices** -- HTTP Basic or Digest auth, configurable per-device via expressions (`auth.ts`). - **UI users** -- JWT tokens in cookies. Passwords hashed with PBKDF2-SHA512 (10000 iterations). Role-based authorization via `Authorizer` with expression-based filters and validators. ### Connection Requests (`lib/connection-request.ts`) Three methods to ask a CPE device to initiate a CWMP session: - **HTTP** -- Standard TR-069 connection request with Digest/Basic auth. - **UDP** -- For NAT traversal (STUN-based) with HMAC-SHA1 signed messages. - **XMPP** -- TR-069 Annex K via a full XMPP client (`xmpp-client.ts`). ### Extensions (`lib/extensions.ts`) User-defined scripts executed in long-lived child processes (`genieacs-ext.ts`) communicating via IPC. Processes are lazily spawned per script name and reused. Each request gets a unique ID; responses are matched by ID with a configurable timeout. ### Logging (`lib/logger.ts`) Dual-stream structured logging (application + access logs). Supports simple and JSON formats, systemd journal integration, and automatic log rotation detection. Protocol traces can be written to a debug file in YAML or JSON format (`debug.ts`). ### Three-Valued Logic The system consistently implements SQL-style three-valued logic (true/false/null). This is visible in expression evaluation, the `Clause` hierarchy's separate true/false/null methods, and the 2-bit minterm encoding in the Boolean minimizer. NULL means "unknown" and propagates through operations following SQL semantics. ## Architectural Invariants - **The expression system does not depend on any service-specific code.** The `lib/common/expression/` modules are pure and shared across all services. - **The sandbox is deterministic across replays.** `Math.random()` is seeded from the device ID, `Date.now()` is controlled, and extension results are cached. A script re-run with the same inputs produces the same outputs. - **Services share no in-process state.** All cross-process coordination goes through MongoDB (the `cache` and `locks` collections). Each worker process is independent. - **Device data is never mutated in place during a session.** `VersionedMap` provides revision-based snapshots. The sandbox writes to new revisions; earlier revisions remain readable for re-evaluation. - **CWMP session exclusivity.** A distributed lock (`cwmp_session_`) ensures only one session exists per device at a time. The lock is refreshed periodically and released at session end. - **The UI backend never queries MongoDB with raw user input.** All queries go through the expression-to-MongoDB compiler (`db/synth.ts`), which validates and normalizes expressions before generating filters. ================================================ FILE: CHANGELOG.md ================================================ # Change Log ## 1.2.14 (2026-03-12) - Prevent UI crash when a malformed URL is sent to the server. - Fix potential edge-case bugs in expression evaluation and session serialization. ## 1.2.13 (2024-06-06) - Increase connection timeout for UI and NBI from 30 to 120 seconds to avoid timeouts when running unindexed queries in large deployments. - Fix race condition causing 503 error when deleting multiple faults at once. - Fix some UI config options not being evaluated as dynamic expressions. - Fix an issue where certain edge-case query expressions were not being correctly converted to MongoDB queries, resulting in inaccurate search results. ## 1.2.12 (2024-03-28) - Fix broken XMPP support in the previous release. - Fix regression causing CSV downloads to be buffered in memory before being streamed to the client. ## 1.2.11 (2024-03-21) - Resolved an issue from the previous release that caused incompatibility with Node.js versions 12 through 15. ## 1.2.10 (2024-03-18) - Add support for XMPP connection requests. Use the environment variables `XMPP_JID` and `XMPP_PASSWORD` to configure the XMPP connection for the ACS. - The environment variables `CWMP_SSL_CERT` and `CWMP_SSL_KEY`, as well as their counterparts for UI, NBI, and FS, now accept PEM-encoded certificates and keys in addition to file paths. - The UI no longer requires users to refresh the page after modifying presets, provisions, or virtual parameters. Refreshing is now only necessary for changes to users, permissions, or UI configurations. - Improved conversion of GenieACS expressions into MongoDB queries for more optimized queries and better index utilization. - Refactor UI pagination and sorting to fix issues from the previous approach, especially with sorting by rapidly changing parameters such as 'last inform' time. - The file server now supports HEAD requests, the Range header, and conditional requests. - Addressed an issue causing file server disconnections for slow clients over HTTPS. - Fix bug preventing users from changing their own passwords. - Introduced a new 'locks' collection for database locking, replacing the previous use of the 'cache' collection for this purpose. - Various other minor fixes and enhancements. ## 1.2.9 (2022-08-22) - New config option `cwmp.skipRootGpn` to enable a workaround for some problematic CPEs that reject GPN requests on data model root. - Stream query results and CSV downloads as data becomes available instead of buffering the entire response. - Log HTTP/HTTPS client errors in debug log. - Fix occasional lock expired errors after updating presets, etc. - Fix bug where queries containing `<>` operator may return incorrect results. - Fix a performance hit caused by DB calls containing the entire CPE data model rather then just the updated parameters. - Fix bug where tags containing special characters are saved in their encoded form when set via a Provision script. - Fix issue causing invalid `xsd:dateTime` values to be saved in DB as `NaN` rather than maintain the original string value. - Fix bug using `$regex` operator with a numeric or a datetime string. - Fix ping not working on certain platforms. - Ping requests are now authenticated. - Fix error when the `FORWARDED_HEADER` environment variable contains IPv4 CIDR while the listening interface is IPv6 and vice versa. - Fix false warning "unexpected parameter in response" showing in `genieacs-cwmp` logs. - Other minor fixes and stability improvements. ## 1.2.8 (2021-10-27) - Fix a remote code execution security vulnerability in genieacs-ui. - All UI components can now be configured using fully dynamic expressions. Previously some component types only accept fixed string values as properties. - The `container` UI component can now be configured with an `element` property that's either a string or a nested pair of `tag` and `attributes` properties. The various attributes under the `attributes` property can now make use of a new function `ENCODEURICOMPONENT()` to facilitate creating custom hyperlinks in the UI. - Improve sorting buttons' behavior in the device listing page and other pages. Sorting by multiple columns should now feel more intuitive. - Support the modulo (%) operator in expressions. - Fix a regression in the previous release where the config option 'ui.pageSize' no longer works. - Fix process crash when a CPE sends an unsupported ACS method. ## 1.2.7 (2021-09-18) - Fix regression causing frequent invalid session errors. - Fix regression breaking digest authentication in connection requests. ## 1.2.6 (2021-09-16) - New config option `cwmp.downloadSuccessOnTimeout` to enable a workaround for CPEs that neglect to send a TransferComplete message after a successful download. - Display a progress bar when uploading new files. - Default to dual stack interface binding (i.e. `::` instead of `0.0.0.0`). Unless the binding interface is explicitly set, this will cause IPv4 addresses in the logs to be displayed as IPv4-mapped IPv6 addresses (e.g. `::ffff:127.0.0.1` instead of `127.0.0.1`). - Detect and correct for client side (browser) clock skew that would otherwise alter the numbers in the pie charts. - Various improvements relating to dealing with buggy TR-069 client implementations. - Fix a bug causing "lock expired" exceptions when a CWMP session remains open for a very long time due to slow clients. - Fix metadata of uploaded files going missing due to nginx stripping away what it considers to be invalid headers. The nginx directive `ignore_invalid_headers` is no longer required. - Fix crash when a CPE is assigned a tag containing a dot. - Fix bug preventing the user from closing the preset pop-up after being presented with unsupported preset message. - Fix exceptions raised from ext scripts manifesting as timeout faults. - Fix download getting triggered repeatedly when the value passed to `Download` parameter is greater than the current timestamp. - Fix crash when passing invalid attributes to `declare`. - Fix crash in NBI when pushing tasks to non-existing devices. - Fix crash in NBI when passing invalid JSON to various API endpoints. - Fix crash when the output from `ping` command cannot be parsed in some rare edge cases. - A number of other fixes and stability improvements. ## 1.2.5 (2021-03-12) - Support specifying custom types when uploading files. - Fix JS compatibility issue with Safari browser. ## 1.2.4 (2021-02-24) - The data model state of a CPE is no longer forgotten after unsuccessful session termination (e.g. timeout). This addresses a number of undesired side effects that arise when a CPE does not terminate the session properly. - Executing tasks that take a long time to complete (e.g. refreshing the entire data model) no longer shows a timeout error while the task is still being processed. - New function `ROUND()` available to expressions. It works similar to the function by the same name in SQLite and PostgreSQL. - Log access events for `genieacs-nbi` service. - Pipe stdout/stderr from extension scripts to the `genieacs-cwmp` process log. - Parameter values of type `xsd:dateTime` are now displayed in the UI and CSV downloads as a date string rather than a numeric value. - Add file download link in the files listing page. - Display spinner loading animation throughout the UI. - Display GenieACS version and build number underneath the logo. - New option to specify how many parameters are displayed at a time in the all-parameters component. Simply set `limit` property in the component config. - Reduce overly strong Brotli compression level which was causing significant page load slowdown when Brotli is used. - Retire dump-data-model tool. `genieacs-sim` can now use a CSV file as its data model. - Reduce the number of concurrent database connections from each process. - Remove dependency on 'hostInfo' MongoDB command which is a privileged action. It is now possible to use shared MongoDB instances with limited privileged. - Fix bug in NBI where querying files returns 404 error. - Fix ping not working for devices with an IPv6 address. - Fix an elusive memory leak in `genieacs-fs` that slowly eats up memory and can go unnoticed for long periods of time. - Fix a rare edge case where a `declare()` call to set a parameter value may not work as intended if the parameter was originally received as part of the Inform message. - A number of other fixes and stability improvements. ## 1.2.3 (2020-10-26) - New config option 'cwmp.skipWritableCheck' for when some CPEs incorrectly report writable parameters as non-writable. When set to true, the scripts will no longer respect the 'writable' attribute of the CPE parameters and will send a SetParamteerValues, AddObject, or DeleteObject request anyway. - Tags no longer restrict what characters are allowed. Any character other than alphanumeric characters, hyphen, or underscore is now encoded in the data model (i.e. Tags.\) using its hex value preceded by "0x". - Ask for a confirmation before closing a pop-up dialog with unsaved changes. - Better XML validation to avoid crashes caused by invalid CPE requests. - Fix confusing 404 error message when the user attempts to modify a resource when they don't have the necessary permissions. - Fix a rare issue where genieacs-cwmp stops accepting new connections after running for a few weeks. - Fix exception when IS NULL operator is used in certain situations. ## 1.2.2 (2020-10-03) - Added button to push files to selected devices from device listing page. - A few minor UI improvements. - Fix exception that can happen and persist after a Download request. - Fix validation bug preventing running refreshObject task on data model root. - Fix invalid arguments fault in refresh preset configuration when upgrading from v1.1. ## 1.2.1 (2020-09-08) - Fix bug causing faults to not be displayed in the UI. - Fix bug where deleting objects does not get reflected immediately in the UI. - Improve conversion between filters written in the expression format and MongoDB queries. There should now be fewer edge cases where the two are not equisatisfiable. ## 1.2.0 (2020-09-01) - Support GetParameterAttributes and SetParameterAttributes TR-069 methods. - Support CASE statement and COALESCE function in expressions. - Provision arguments can now be a list of expressions that are dynamically evaluated. - Support Forwarded HTTP header to display in the logs the correct IP of CPEs behind a reverse proxy. Must be configured using FORWARDED_HEADER option. - Config expressions can now access all available device parameters, not only serial number, product class, and OUI. - Use relative URLs throughout the UI to allow serving from a subdirectory using a reverse proxy. - Make Date.parse() and Date.UTC() available to provision scripts. - libxmljs has been entirely removed in favor of our bespoke XML parser. - Removed the config option CWMP_KEEP_ALIVE_TIMEOUT. SESSION_TIMEOUT is now used to determine the TCP connection timeout. - The all-parameters component now limits the number of parameters displayed for better performance. - The process genieacs-cwmp is now much less likely to throw exceptions as a result of invalid requests from CPE. - A large number of bug fixes and stability improvements. ## 1.2.0-beta.0 (2019-07-30) - A brand new UI superseding genieacs-gui. - New initialization wizard on first run. - New expression/query language used in search filters and preset preconditions. - CPE -> ACS authentication is now supported. - New config option (CWMP_KEEP_ALIVE_TIMEOUT) to specify how long to wait for a reply from the CPE before closing the TCP connection. - Debug logging has been reimplemented utilizing YAML format for logs. - Handle 9005 faults (Invalid Parameter Name) gracefully by attempting to rediscover the path of the missing parameter recursively. - declare() statements not followed by an explicit commit() are now deferred until all currently active scripts have been executed. - FS_HOSTNAME now defaults to the server's hostname or IP. - The API now validates the structure of task objects before saving. - New XML parser implementation for better performance. You can revert to the old parser by enabling the config option XML_LIBXMLJS. Requires Node.js v11 or v10. - Performance optimizations. While performance has improved for the majority of use cases, there may be situations where performance has degraded. It's recommended to revisit your hardware requirements. - Connection request authentication no longer uses 'auth.js' file. Instead, the connection request authentication behavior can now be customized using an 'expression'. - The config file (config.json) has been deprecated. System configuration (e.g. listen ports, worker count) are now recommended to be passed as environment. variables. Other general configuration options are stored in the database so as to not require service restart for changes to take effect. - Optional redis dependency has been removed completely. - Tags now allow only alphanumeric characters and underscore. - Supported versions of Node.js and MongoDB are 10.x and up and 2.6 and up respectively. ## 1.1.3 (2018-10-23) - New config option (MAX_COMMIT_ITERATIONS) to avoid max commit iterations faults for more complex scripts. - Support base64 and hexBinary parameter types. - Strict parsing of number values in queries (e.g. "123abc" no longer accepted as 123). - Mixing $ne and $not operators is not allowed. Now it throws an error instead of returning incorrect results. - When a task expires, any associated fault is also deleted. - API now accepts 'timeout' argument when posting a task. - A number of stability fixes. ## 1.1.2 (2018-02-24) - A large number of bug fixes as well as stability and performance improvements. - Three security vulnerabilities disclosed by Maximilian Hils have been patched. - New config option UDP_CONNECTION_REQUEST_PORT to specify binding port for UDP connection requests. - New config option DATETIME_MILLISECONDS to strip milliseconds from dateTime values. - New config option BOOLEAN_LITERAL to use 1/0 or true/false for boolean values. - Parameter values that cannot be parsed according to the reported type now show a warning message. - Virtual parameter scripts now use the variable 'args' instead of the special 'TIMESTAMPS' and 'VALUES' variables. The content of the args array is: {declare timestamps}, {declare values}, {current timestamps}, {current values}. - Virtual parameter value types are now inferred from the JavaScript type if the returned value attribute is not a value-type pair. - Show a fault when a virtual parameter script doesn't return the required attributes. - Redis is now optional (and disabled by default), reducing the complexity of scalable deployments. - Better detection of cyclical presets resulting in fewer faults for complex provisioning scripts. - Math.random() is now deterministic on per-device basis. A function has been added to allow specifying a seed value (e.g. Math.random.seed(Date.now())). - Overload spikes are now handled gracefully by refusing to accept new sessions temporarily when under abnormal load. - Added log messages for session timeouts, connection drops, and XML parsing errors. - Date.now() now takes an optional argument to specify "time steps" (in milliseconds). This can be used to ensure a group of parameters are all refreshed at the same time intervals. - Only the non-default configuration options are now logged at process start. - Faults caused by errors from extensions now show a cleaner stack trace. - Exit main process if there are too many worker crashes (e.g. when DB is down). - Updated dependencies and included a lockfile to ensure installations get the exact dependencies it was tested against. ## 1.1.1 (2017-03-23) - Avoid crashing when connection request credentials are missing. - Show a warning instead of crashing when failing to parse parameter values according to the expected value type. - Add missing "Registered" event. - Fix bug where in certain cases many more instances than declared are created. - Fix parameter discovery bug when declared path timestamp is 1 or is not set. - Fix preset precondition failing when testing against datetime parameters and certain other parameters like \_deviceId.\_ProductClass. ## 1.1.0 (2017-03-10) - Provisions enable implementing dynamic device configuration or complex device provisioning work flow using arbitrary scripts. - Virtual parameters are user-defined parameters whose values are evaluated from a custom script. - Extensions are sandboxed Node.js scripts that are accessible from provision and virtual parameter scripts to facilitate integration with external entities. - Support for UDP/STUN based connection requests for reaching devices behind NAT (TR-069 Annex G). - Presets can now be scheduled using a cron-like expression. - Presets can now be tied to specific device events (e.g. boot). - Presets precondition queries no longer support "\$or" or other MongoDB logical operators. - Faults are no longer a part of tasks but are now first class objects. - Presets are now assigned to channels. A fault in one channel only blocks presets in that channel. - New API CRUD functions for provisions, virtual parameters, and faults. - New config options for XML output. - API responses now include "GenieACS-Version" header. - Graceful shutdown when receiving SIGINT and SIGTERM events. - Support SSL intermediate certificate chains. - Supported Node.js versions are 6.x and 7.x. - Supported MongoDB versions are 2.6 through 3.4. - Expect performance differences due to major under the hood changes. Some operations are faster and some are slower. Overall performance is improved. - GenieACS will no longer fetch the entire device data model upon first contact but will instead only fetch the parameters it needs to fulfill the presets. - Logs have been overhauled and split into two streams: process log (stderr) and access log (stdout). Also added config options to dump logs to files rather than standard streams. - Connection request authentication credentials are picked up from the device data model if available. config/auth.js is still supported as a fallback and now supports an optional callback argument. - Custom commands have been removed. Use virtual parameters and/or extensions. - Aliases and value normalizers (config/parameters.json) have been removed. Use virtual parameters. - The API /devices//preset has been removed. - Rarely used RequestDownload method no longer supported. - The TR-069 client simulator has moved to its own repo at https://github.com/zaidka/genieacs-sim ================================================ FILE: CONTRIBUTING.md ================================================ # Contributing to GenieACS ## Questions and Support Please use the [forum](https://forum.genieacs.com) for questions, help requests, and general discussion. GitHub Issues are reserved for confirmed bug reports. ## Issues We use GitHub Issues to track bugs. When filing a bug report: - Provide a clear description of the problem. - Include steps to reproduce the issue. - Note the GenieACS version, Node.js version, and MongoDB version. - Include relevant log output if applicable. If you face interoperability issues with a CPE, it is more often than not a device-specific issue. Please consult the [forum](https://forum.genieacs.com) before opening an Issue. ## Pull Requests Pull requests are welcome. For bug fixes, go ahead and open a PR directly. For new features or significant changes, please discuss in the [forum](https://forum.genieacs.com) first to ensure alignment with the project's direction. When submitting a PR: - Keep changes focused. One PR should address one concern. - Run `npm run lint` and `npm test` before submitting. - Update documentation in `docs/` if your change affects user-facing behavior. - Add tests where appropriate (see [Testing](#testing)). - Write a clear PR description explaining what the change does and why. ## Code Style ### Naming Conventions - **Variables and functions**: `camelCase` - **Classes**: `PascalCase` - **Interfaces and type aliases**: `PascalCase`, without an `I` or `T` prefix - **Module-level constants**: `UPPER_SNAKE_CASE` - **Private class members**: prefixed with underscore (`_name`, `_cache`) Choose descriptive, meaningful names. A longer clear name is better than a short ambiguous one. ### Imports Organize imports in three groups, in this order: 1. Node.js built-in modules, using the `node:` prefix 2. External packages 3. Local project modules Use `.ts` extensions for all local imports. ```typescript import { readFileSync } from "node:fs"; import * as http from "node:http"; import { Collection } from "mongodb"; import { connect, disconnect } from "./db.ts"; import Path from "./common/path.ts"; ``` ### Functions and Exports Use the `function` keyword for all named and exported function declarations. Arrow functions should only be used for callbacks and short inline expressions. ```typescript // Named/exported functions use function keyword export function processRequest(req: Request): Response { // ... } // Arrow functions for callbacks items.filter((item) => item.active); promise.then((result) => { // ... }); ``` ### TypeScript - All function declarations must have explicit return types. This is enforced by ESLint. - Using `any` is permitted where full typing would be impractical, but prefer more specific types when reasonable. - Prefer `Record` over `{ [key: string]: T }` for mapped types. - Use type assertions (`as`) sparingly and only when you have stronger type knowledge than the compiler. ### Comments Code should be self-documenting. Use comments sparingly and only when the "why" is not obvious from the code itself. When you do comment, use inline `//` style. Do not use JSDoc (`/** */`) or block comments (`/* */`). ```typescript // Good: explains a non-obvious reason // Escapes everything except alphanumerics and underscore function escapeRegExp(str: string): string { /* ... */ } // Good: links to an external reference // Source: http://stackoverflow.com/a/6969486 // Good: flags a known limitation // TODO support "MD5-sess" algorithm directive // Bad: restates what the code does // Loop through each item and increment the counter for (const item of items) { counter++; } ``` ### Error Handling Use `== null` (not `=== null || === undefined`) for null/undefined checks. ESLint is configured to allow this. ## Testing ### When to Write Tests Tests are most valuable for pure logic: parsers, data transformations, algorithms, and utility functions where inputs and outputs are well defined. A regression test accompanying a bug fix is also worthwhile to prevent the same issue from resurfacing. Not every change needs a test. Use judgment and consider the likelihood and cost of breakage. Avoid writing tests that duplicate coverage already provided by existing tests, and resist the urge to test trivial code just for the sake of coverage numbers. ### Conventions Tests use the Node.js built-in test runner (`node:test`) and assertion module (`node:assert`). No external test libraries or mocking frameworks are used. ```typescript import test from "node:test"; import assert from "node:assert"; void test("parseValue returns correct type for integer strings", () => { const result = parseValue("42"); assert.strictEqual(result, 42); }); void test("parseValue throws on invalid input", () => { assert.throws(() => parseValue(""), new Error("empty value")); }); ``` Key conventions: - Prefix `test()` calls with `void` to satisfy the `no-floating-promises` lint rule. - Keep tests flat. Do not nest `describe` blocks. - Use descriptive test names that state what is being tested and the expected outcome. - Use `assert.strictEqual()` for value comparisons and `assert.deepStrictEqual()` for objects and arrays. Test files live in the `test/` directory and are named after the module they test (e.g. `test/path.ts` tests `lib/common/path.ts`). ## Dependencies This project deliberately keeps its dependency footprint small. Before adding a new dependency: - Prefer Node.js built-in APIs when they can do the job. - Consider whether the functionality is simple enough to implement directly. - Justify the addition in your PR description. Do not add development tool dependencies (linter plugins, editor integrations, etc.) without prior discussion. ## File Organization | Directory | Contents | | ------------- | -------------------------------------------- | | `lib/` | Core server-side application code | | `lib/common/` | Code shared between server and browser | | `lib/db/` | Database layer (MongoDB) | | `lib/ui/` | UI backend helpers | | `ui/` | Frontend code (Mithril.js SPA) | | `bin/` | Service entry points | | `build/` | Build tooling | | `test/` | Test files | | `docs/` | User documentation (Sphinx/reStructuredText) | | `public/` | Static assets (favicon, logo) | Place new code in the directory that matches its purpose. Server-side logic belongs in `lib/`, code that must run in both Node.js and the browser belongs in `lib/common/`, and frontend-only code belongs in `ui/`. ## Documentation User documentation lives in the `docs/` directory as reStructuredText files built with Sphinx and published to [docs.genieacs.com](https://docs.genieacs.com). When your change affects user-facing behavior: - Update the relevant documentation in `docs/`. - If adding a new feature, consider whether it warrants a new page or a section in an existing page. - Keep documentation concise and practical. Match the existing tone: direct, factual, no filler. Documentation changes should be included in the same PR as the code change, not submitted separately. ### ARCHITECTURE.md `ARCHITECTURE.md` describes the high-level architecture of the project: the service boundaries, major subsystems, data flow, and key invariants. It is aimed at contributors who need a mental map of the codebase. This file has a different update cadence than `docs/`. It should be revisited a few times a year rather than kept in lockstep with every code change. When you do update it, follow these principles: - **Only describe things that are unlikely to change frequently.** Module responsibilities, service boundaries, key data structures, and architectural invariants belong here. Implementation details, function signatures, and config option lists do not. - **Name important files, modules, and types but do not link them.** Links go stale. Encourage the reader to use symbol search to find named entities; this also helps them discover related, similarly named things. - **Keep it short.** Every recurring contributor will read it. A shorter document is less likely to become stale and more likely to be maintained. - **Describe the "what" and "where", not the "how".** This is a map of the country, not an atlas of its states. Pull detailed explanations into inline code comments or separate documents. - **Call out architectural invariants explicitly.** Important invariants are often expressed as the _absence_ of something (e.g., "the expression system does not depend on service-specific code") and are hard to discover by reading code alone. ## Git Workflow ### Commit Messages This project follows the [Conventional Commits](https://www.conventionalcommits.org/) format: (): [optional body] - Use the imperative mood, present tense: "Fix bug", not "Fixed bug" or "Fixes bug". - Do not capitalize the first letter of the subject (the type prefix handles visual structure). - Do not end the subject line with a period. - Keep the subject line under 72 characters. - When more context is helpful, add a body separated from the subject by a blank line, wrapped at 72 characters. The goal is to provide enough information for someone scanning the commit history to find a specific change (e.g. for troubleshooting or rebasing) or to draft changelog entries for a release. Don't be verbose, but don't be cryptic either. #### Types | Type | When to use | | ---------- | --------------------------------------------------------------------------- | | `fix` | Bug fixes | | `feat` | New features or capabilities | | `refactor` | Code restructuring with no behavior change | | `test` | Adding or updating tests | | `docs` | Documentation changes (`docs/`, `CONTRIBUTING.md`, `README.md`) | | `build` | Build system, dependencies, esbuild config, `package.json` scripts | | `chore` | Maintenance tasks that don't fit above (`.gitignore`, tooling config, etc.) | #### Scopes Scope is optional. Use it when it adds useful context; omit it when the change is cross-cutting or the subject already makes it obvious. | Scope | Covers | | ------ | ----------------------------------- | | `cwmp` | CWMP service (including extensions) | | `nbi` | Northbound REST API service | | `fs` | File service | | `ui` | Web UI (frontend and backend) | | `db` | Database layer | If a change touches multiple scopes, either pick the primary one or omit the scope entirely. #### Examples feat(nbi): add bulk device delete endpoint fix(cwmp): handle missing ParameterKey in InformResponse refactor(db): replace raw queries with parameterized calls fix(ui): correct parameter table sort order test: add XML parser edge case coverage docs: update provisioning guide for new API build: upgrade esbuild to v0.20 fix(cwmp): increase server timeout to 2 mins To allow enough time for running unindexed queries in large deployments. ### Branches - `master` is the main development branch. - Create a feature or fix branch for your work and open a PR against `master`. - Use concise, descriptive branch names in lowercase with hyphens: `fix-race-condition`, `support-xmpp-requests`. ## Changelog The changelog (`CHANGELOG.md`) is maintained for each release and is written for users and system administrators, not developers. - Write entries as clear, user-facing prose. Do not copy commit messages verbatim. - Each entry should describe what changed and, when helpful, why it matters. - Group entries under a version heading with the release date: `## 1.2.13 (2024-06-06)`. - Start each entry with a verb: "Fix", "Add", "Improve", "Remove", etc. - Include enough context that a user can understand the impact without reading the code. You do not need to update the changelog in your PR. The maintainer will add changelog entries during the release process. ## Contributor License Agreement By submitting a pull request to this repository, you acknowledge that, while maintaining copyright, you grant GenieACS Inc. a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable license to reproduce, prepare derivative works of, publicly display, publicly perform, sublicense, and distribute your contributions and such derivative works under the AGPLv3 license or any other license terms, including, but not limited to, proprietary or commercial license terms. You confirm that you own or have rights to distribute and sublicense the source code contained therein, and that your content does not infringe upon the intellectual property rights of a third party. ================================================ FILE: LICENSE ================================================ GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU Affero General Public License is a free, copyleft license for software and other kinds of works, specifically designed to ensure cooperation with the community in the case of network server software. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, our General Public Licenses are intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. Developers that use our General Public Licenses protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License which gives you legal permission to copy, distribute and/or modify the software. A secondary benefit of defending all users' freedom is that improvements made in alternate versions of the program, if they receive widespread use, become available for other developers to incorporate. Many developers of free software are heartened and encouraged by the resulting cooperation. However, in the case of software used on network servers, this result may fail to come about. The GNU General Public License permits making a modified version and letting the public access it on a server without ever releasing its source code to the public. The GNU Affero General Public License is designed specifically to ensure that, in such cases, the modified source code becomes available to the community. It requires the operator of a network server to provide the source code of the modified version running there to the users of that server. Therefore, public use of a modified version, on a publicly accessible server, gives the public access to the source code of the modified version. An older license, called the Affero General Public License and published by Affero, was designed to accomplish similar goals. This is a different license, not a version of the Affero GPL, but Affero has released a new version of the Affero GPL which permits relicensing under this license. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU Affero General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Remote Network Interaction; Use with the GNU General Public License. Notwithstanding any other provision of this License, if you modify the Program, your modified version must prominently offer all users interacting with it remotely through a computer network (if your version supports such interaction) an opportunity to receive the Corresponding Source of your version by providing access to the Corresponding Source from a network server at no charge, through some standard or customary means of facilitating copying of software. This Corresponding Source shall include the Corresponding Source for any work covered by version 3 of the GNU General Public License that is incorporated pursuant to the following paragraph. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the work with which it is combined will remain governed by version 3 of the GNU General Public License. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU Affero General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU Affero General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU Affero General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU Affero General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If your software can interact with users remotely through a computer network, you should also make sure that it provides a way for users to get its source. For example, if your program is a web application, its interface could display a "Source" link that leads users to an archive of the code. There are many ways you could offer source, and different solutions will be better for different programs; see section 13 for the specific requirements. You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU AGPL, see . ================================================ FILE: README.md ================================================ # GenieACS **This is the development branch for GenieACS v1.3. It is unstable and not ready for production use. For the latest stable release, see the [v1.2 branch](https://github.com/genieacs/genieacs/tree/v1.2).** GenieACS is a high performance Auto Configuration Server (ACS) for remote management of TR-069 enabled devices. It utilizes a declarative and fault tolerant configuration engine for automating complex provisioning scenarios at scale. It's battle-tested to handle hundreds of thousands and potentially millions of concurrent devices. ## Quick Start Install [Node.js](http://nodejs.org/) and [MongoDB](http://www.mongodb.org/). Refer to their corresponding documentation for installation instructions. The supported versions are: - Node.js: 12.3+ - MongoDB: 3.6+ Install GenieACS from NPM: sudo npm install -g genieacs To build from source instead, clone this repo or download the source archive then _cd_ into the source directory then run: npm install npm run build Finally, run the following services (found under `./dist/bin/` if building from source): ### genieacs-cwmp This is the service that the CPEs will communicate with. It listens on port 7547 by default. Configure the ACS URL in your devices accordingly. You may optionally use [genieacs-sim](https://github.com/genieacs/genieacs-sim) as a dummy TR-069 simulator if you don't have a CPE at hand. ### genieacs-nbi This is the northbound interface module. It exposes a REST API on port 7557 by default. This one is only required if you have an external system integrating with GenieACS using this API. ### genieacs-fs This is the file server from which the CPEs will download firmware images and such. It listens on port 7567 by default. ### genieacs-ui This serves the web based user interface. It listens on port 3000 by default. You must pass _--ui-jwt-secret_ argument to supply the secret key used for signing browser cookies: genieacs-ui --ui-jwt-secret secret The UI has plenty of configuration options. When you open GenieACS's UI in a browser you'll be greeted with a database initialization wizard to help you populate some initial configuration. Visit [docs.genieacs.com](https://docs.genieacs.com) for more documentation and a complete installation guide for production deployments. ## Support The [forum](https://forum.genieacs.com) is a good place to get guidance and help from the community. Head on over and join the conversation! For commercial support options, please visit [genieacs.com](https://genieacs.com/support/). ## License Copyright 2013-2026 GenieACS Inc. GenieACS is released under the [AGPLv3 license terms](https://raw.githubusercontent.com/genieacs/genieacs/master/LICENSE). ================================================ FILE: bin/genieacs-cwmp.ts ================================================ import * as config from "../lib/config.ts"; import * as logger from "../lib/logger.ts"; import * as cluster from "../lib/cluster.ts"; import * as server from "../lib/server.ts"; import * as cwmp from "../lib/cwmp.ts"; import * as db from "../lib/db/db.ts"; import * as extensions from "../lib/extensions.ts"; import { version as VERSION } from "../package.json"; logger.init("cwmp", VERSION); const SERVICE_ADDRESS = config.get("CWMP_INTERFACE") as string; const SERVICE_PORT = config.get("CWMP_PORT") as number; function exitWorkerGracefully(): void { setTimeout(exitWorkerUngracefully, 5000).unref(); Promise.all([ db.disconnect(), extensions.killAll(), cluster.worker.disconnect(), ]) .then(logger.close) .catch(exitWorkerUngracefully); } function exitWorkerUngracefully(): void { void extensions.killAll().finally(() => { process.exit(1); }); } if (!cluster.worker) { const WORKER_COUNT = config.get("CWMP_WORKER_PROCESSES") as number; logger.info({ message: `genieacs-cwmp starting`, pid: process.pid, version: VERSION, }); cluster.start(WORKER_COUNT, SERVICE_PORT, SERVICE_ADDRESS); process.on("SIGINT", () => { logger.info({ message: "Received signal SIGINT, exiting", pid: process.pid, }); cluster.stop(); }); process.on("SIGTERM", () => { logger.info({ message: "Received signal SIGTERM, exiting", pid: process.pid, }); cluster.stop(); }); } else { const key = config.get("CWMP_SSL_KEY") as string; const cert = config.get("CWMP_SSL_CERT") as string; const options = { port: SERVICE_PORT, host: SERVICE_ADDRESS, ssl: key && cert ? { key, cert } : null, onConnection: cwmp.onConnection, onClientError: cwmp.onClientError, timeout: 30000, keepAliveTimeout: 0, requestTimeout: cwmp.REQUEST_TIMEOUT, }; // Need this for Node < 15 process.on("unhandledRejection", (err) => { throw err; }); process.on("uncaughtException", (err) => { if ((err as NodeJS.ErrnoException).code === "ERR_IPC_DISCONNECTED") return; logger.error({ message: "Uncaught exception", exception: err, pid: process.pid, }); server.stop(false).then(exitWorkerGracefully).catch(exitWorkerUngracefully); }); const initPromise = db .connect() .then(() => { server.start(options, cwmp.listener); }) .catch((err) => { setTimeout(() => { throw err; }); }); process.on("SIGINT", () => { void initPromise.finally(() => { server .stop(false) .then(exitWorkerGracefully) .catch(exitWorkerUngracefully); }); }); process.on("SIGTERM", () => { void initPromise.finally(() => { server .stop(false) .then(exitWorkerGracefully) .catch(exitWorkerUngracefully); }); }); } ================================================ FILE: bin/genieacs-ext.ts ================================================ import { Fault } from "../lib/types.ts"; const jobs = new Set(); const fileName = process.argv[2]; let script; function errorToFault(err: Error): Fault { if (!err) return null; if (!err.name) return { code: "ext", message: `${err}` }; const fault: Fault = { code: `ext.${err.name}`, message: err.message, detail: { name: err.name, message: err.message, }, }; if (err.stack) { fault.detail["stack"] = err.stack; // Trim the stack trace const stackTrimIndex = fault.detail["stack"].match( /\s+at\s[^\s]+\s\(.*genieacs-ext:.+\)/, ); if (stackTrimIndex) { fault.detail["stack"] = fault.detail["stack"].slice( 0, stackTrimIndex.index, ); } } return fault; } // Need this for Node < 15 process.on("unhandledRejection", (err) => { throw err; }); process.on("uncaughtException", (err) => { const fault = errorToFault(err); jobs.forEach((jobId) => { process.send([jobId, fault, null]); }); jobs.clear(); process.disconnect(); }); process.on("message", (message) => { jobs.add(message[0]); if (!script) { const cwd = process.env["GENIEACS_EXT_DIR"]; process.chdir(cwd); // eslint-disable-next-line @typescript-eslint/no-require-imports script = require(`${cwd}/${fileName}`); } const funcName = message[1][0]; if (!script[funcName]) { const fault = { code: "ext", message: `No such function '${funcName}' in extension '${fileName}'`, }; process.send([message[0], fault, null]); return; } script[funcName](message[1].slice(1), (err, res) => { if (!jobs.delete(message[0])) return; process.send([message[0], errorToFault(err), res]); }); }); // Ignore SIGINT process.on("SIGINT", () => { // Ignore }); ================================================ FILE: bin/genieacs-fs.ts ================================================ import * as config from "../lib/config.ts"; import * as logger from "../lib/logger.ts"; import * as cluster from "../lib/cluster.ts"; import * as server from "../lib/server.ts"; import { listener } from "../lib/fs.ts"; import * as db from "../lib/db/db.ts"; import { version as VERSION } from "../package.json"; logger.init("fs", VERSION); const SERVICE_ADDRESS = config.get("FS_INTERFACE") as string; const SERVICE_PORT = config.get("FS_PORT") as number; function exitWorkerGracefully(): void { setTimeout(exitWorkerUngracefully, 5000).unref(); Promise.all([db.disconnect(), cluster.worker.disconnect()]) .then(logger.close) .catch(exitWorkerUngracefully); } function exitWorkerUngracefully(): void { process.exit(1); } if (!cluster.worker) { const WORKER_COUNT = config.get("FS_WORKER_PROCESSES") as number; logger.info({ message: `genieacs-fs starting`, pid: process.pid, version: VERSION, }); cluster.start(WORKER_COUNT, SERVICE_PORT, SERVICE_ADDRESS); process.on("SIGINT", () => { logger.info({ message: "Received signal SIGINT, exiting", pid: process.pid, }); cluster.stop(); }); process.on("SIGTERM", () => { logger.info({ message: "Received signal SIGTERM, exiting", pid: process.pid, }); cluster.stop(); }); } else { const key = config.get("FS_SSL_KEY") as string; const cert = config.get("FS_SSL_CERT") as string; const options = { port: SERVICE_PORT, host: SERVICE_ADDRESS, ssl: key && cert ? { key, cert } : null, timeout: 30000, }; // Need this for Node < 15 process.on("unhandledRejection", (err) => { throw err; }); process.on("uncaughtException", (err) => { if ((err as NodeJS.ErrnoException).code === "ERR_IPC_DISCONNECTED") return; logger.error({ message: "Uncaught exception", exception: err, pid: process.pid, }); server.stop().then(exitWorkerGracefully).catch(exitWorkerUngracefully); }); const initPromise = db .connect() .then(() => { server.start(options, listener); }) .catch((err) => { setTimeout(() => { throw err; }); }); process.on("SIGINT", () => { void initPromise.finally(() => { server.stop().then(exitWorkerGracefully).catch(exitWorkerUngracefully); }); }); process.on("SIGTERM", () => { void initPromise.finally(() => { server.stop().then(exitWorkerGracefully).catch(exitWorkerUngracefully); }); }); } ================================================ FILE: bin/genieacs-nbi.ts ================================================ import * as config from "../lib/config.ts"; import * as logger from "../lib/logger.ts"; import * as cluster from "../lib/cluster.ts"; import * as server from "../lib/server.ts"; import { listener } from "../lib/nbi.ts"; import * as db from "../lib/db/db.ts"; import * as extensions from "../lib/extensions.ts"; import { version as VERSION } from "../package.json"; logger.init("nbi", VERSION); const SERVICE_ADDRESS = config.get("NBI_INTERFACE") as string; const SERVICE_PORT = config.get("NBI_PORT") as number; function exitWorkerGracefully(): void { setTimeout(exitWorkerUngracefully, 5000).unref(); Promise.all([ db.disconnect(), extensions.killAll(), cluster.worker.disconnect(), ]) .then(logger.close) .catch(exitWorkerUngracefully); } function exitWorkerUngracefully(): void { void extensions.killAll().finally(() => { process.exit(1); }); } if (!cluster.worker) { const WORKER_COUNT = config.get("NBI_WORKER_PROCESSES") as number; logger.info({ message: `genieacs-nbi starting`, pid: process.pid, version: VERSION, }); cluster.start(WORKER_COUNT, SERVICE_PORT, SERVICE_ADDRESS); process.on("SIGINT", () => { logger.info({ message: "Received signal SIGINT, exiting", pid: process.pid, }); cluster.stop(); }); process.on("SIGTERM", () => { logger.info({ message: "Received signal SIGTERM, exiting", pid: process.pid, }); cluster.stop(); }); } else { const key = config.get("NBI_SSL_KEY") as string; const cert = config.get("NBI_SSL_CERT") as string; const options = { port: SERVICE_PORT, host: SERVICE_ADDRESS, ssl: key && cert ? { key, cert } : null, timeout: 120000, }; // Need this for Node < 15 process.on("unhandledRejection", (err) => { throw err; }); process.on("uncaughtException", (err) => { if ((err as NodeJS.ErrnoException).code === "ERR_IPC_DISCONNECTED") return; logger.error({ message: "Uncaught exception", exception: err, pid: process.pid, }); server.stop().then(exitWorkerGracefully).catch(exitWorkerUngracefully); }); const initPromise = db .connect() .then(() => { server.start(options, listener); }) .catch((err) => { setTimeout(() => { throw err; }); }); process.on("SIGINT", () => { void initPromise.finally(() => { server.stop().then(exitWorkerGracefully).catch(exitWorkerUngracefully); }); }); process.on("SIGTERM", () => { void initPromise.finally(() => { server.stop().then(exitWorkerGracefully).catch(exitWorkerUngracefully); }); }); } ================================================ FILE: bin/genieacs-ui.ts ================================================ import * as config from "../lib/config.ts"; import * as logger from "../lib/logger.ts"; import * as cluster from "../lib/cluster.ts"; import * as server from "../lib/server.ts"; import { listener } from "../lib/ui.ts"; import * as extensions from "../lib/extensions.ts"; import * as db from "../lib/db/db.ts"; import { version as VERSION } from "../package.json"; logger.init("ui", VERSION); const SERVICE_ADDRESS = config.get("UI_INTERFACE") as string; const SERVICE_PORT = config.get("UI_PORT") as number; function exitWorkerGracefully(): void { setTimeout(exitWorkerUngracefully, 5000).unref(); Promise.all([ db.disconnect(), extensions.killAll(), cluster.worker.disconnect(), ]) .then(logger.close) .catch(exitWorkerUngracefully); } function exitWorkerUngracefully(): void { void extensions.killAll().finally(() => { process.exit(1); }); } if (!cluster.worker) { const WORKER_COUNT = config.get("UI_WORKER_PROCESSES") as number; logger.info({ message: `genieacs-ui starting`, pid: process.pid, version: VERSION, }); cluster.start(WORKER_COUNT, SERVICE_PORT, SERVICE_ADDRESS); process.on("SIGINT", () => { logger.info({ message: "Received signal SIGINT, exiting", pid: process.pid, }); cluster.stop(); }); process.on("SIGTERM", () => { logger.info({ message: "Received signal SIGTERM, exiting", pid: process.pid, }); cluster.stop(); }); } else { const key = config.get("UI_SSL_KEY") as string; const cert = config.get("UI_SSL_CERT") as string; const options = { port: SERVICE_PORT, host: SERVICE_ADDRESS, ssl: key && cert ? { key, cert } : null, timeout: 120000, }; // Need this for Node < 15 process.on("unhandledRejection", (err) => { throw err; }); process.on("uncaughtException", (err) => { if ((err as NodeJS.ErrnoException).code === "ERR_IPC_DISCONNECTED") return; logger.error({ message: "Uncaught exception", exception: err, pid: process.pid, }); server.stop().then(exitWorkerGracefully).catch(exitWorkerUngracefully); }); const initPromise = db .connect() .then(() => { server.start(options, async (req, res) => listener(req, res)); }) .catch((err) => { setTimeout(() => { throw err; }); }); process.on("SIGINT", () => { void initPromise.finally(() => { server.stop().then(exitWorkerGracefully).catch(exitWorkerUngracefully); }); }); process.on("SIGTERM", () => { void initPromise.finally(() => { server.stop().then(exitWorkerGracefully).catch(exitWorkerUngracefully); }); }); } ================================================ FILE: build/assets.ts ================================================ export const APP_JS = "app.js"; export const APP_CSS = "app.css"; export const ICONS_SVG = "icons.svg"; export const LOGO_SVG = "logo.svg"; export const FAVICON_PNG = "favicon.png"; ================================================ FILE: build/build.ts ================================================ import path from "node:path"; import fs from "node:fs"; import { createHash } from "node:crypto"; import { promisify } from "node:util"; import { exec } from "node:child_process"; import * as esbuild from "esbuild"; import { optimize } from "svgo"; import * as xmlParser from "../lib/xml-parser.ts"; const fsAsync = { readdir: promisify(fs.readdir), readFile: promisify(fs.readFile), writeFile: promisify(fs.writeFile), copyFile: promisify(fs.copyFile), rename: promisify(fs.rename), chmod: promisify(fs.chmod), lstat: promisify(fs.lstat), exists: promisify(fs.exists), rmdir: promisify(fs.rmdir), unlink: promisify(fs.unlink), mkdir: promisify(fs.mkdir), }; const execAsync = promisify(exec); const MODE = process.env["NODE_ENV"] || "production"; const INPUT_DIR = process.cwd(); const OUTPUT_DIR = path.join(INPUT_DIR, "dist"); async function rmDir(dirPath: string): Promise { if (!(await fsAsync.exists(dirPath))) return; const files = await fsAsync.readdir(dirPath); for (const file of files) { const filePath = path.join(dirPath, file); if ((await fsAsync.lstat(filePath)).isDirectory()) await rmDir(filePath); else await fsAsync.unlink(filePath); } await fsAsync.rmdir(dirPath); } // For lockfileVersion = 1 function stripDevDeps(deps): void { if (!deps["dependencies"]) return; for (const [k, v] of Object.entries(deps["dependencies"])) { if (v["dev"]) delete deps["dependencies"][k]; else stripDevDeps(v); } if (!Object.keys(deps["dependencies"]).length) delete deps["dependencies"]; } // For lockfileVersion = 2 function stripDevDeps2(deps): void { if (!deps["packages"]) return; for (const [k, v] of Object.entries(deps["packages"])) { delete v["devDependencies"]; if (v["dev"]) delete deps["packages"][k]; } } function xmlTostring(xml): string { const children = []; for (const c of xml.children || []) children.push(xmlTostring(c)); return xml.name === "root" && xml.bodyIndex === 0 ? children.join("") : `<${xml.name} ${xml.attrs}>${children.join("")}`; } function assetHash(buffer: Buffer | string): string { return createHash("md5").update(buffer).digest("hex").slice(0, 8); } const ASSETS = {} as { APP_JS?: string; APP_CSS?: string; ICONS_SVG?: string; LOGO_SVG?: string; FAVICON_PNG?: string; }; const assetsPlugin = { name: "assets", setup(build) { build.onLoad({ filter: /\/build\/assets.ts$/ }, () => { const lines = Object.entries(ASSETS).map( ([k, v]) => `export const ${k} = ${JSON.stringify(v)};`, ); return { contents: lines.join("\n") }; }); }, } as esbuild.Plugin; const seedPlugin = { name: "seed", setup(build) { build.onLoad({ filter: /\/seed\// }, (args) => { if (args.with?.["type"] !== "text") return undefined; let contents = fs.readFileSync(args.path, "utf8"); // Strip TypeScript directives that are only needed for type-checking contents = contents.replace(/^\s*\/\/\s*@ts-.*\n/gm, "\n"); return { contents, loader: "text" }; }); }, } as esbuild.Plugin; const packageDotJsonPlugin = { name: "packageDotJson", setup(build) { const sourcePath = path.join(INPUT_DIR, "package.json"); build.onResolve({ filter: /\/package.json$/ }, (args) => { const p = path.join(args.resolveDir, args.path); if (p !== sourcePath) return undefined; return { path: path.join(OUTPUT_DIR, "package.json") }; }); }, } as esbuild.Plugin; const inlineDepsPlugin = { name: "inlineDeps", setup(build) { const deps = ["espresso-iisojs", "@codemirror", "mithril", "yaml"]; const depFiles = new Set(); build.onResolve({ filter: /^[^.]/ }, async (args) => { if (args.pluginData === "inlineDeps") return undefined; if ( depFiles.has(args.importer) || deps.some((d) => args.path.startsWith(d)) ) { const res = await build.resolve(args.path, { importer: args.importer, namespace: args.namespace, resolveDir: args.resolveDir, kind: args.kind, with: args.with, pluginData: "inlineDeps", }); depFiles.add(res.path); return res; } return { sideEffects: false, external: true }; }); }, } as esbuild.Plugin; function generateSymbol(id: string, svgStr: string): string { const xml = xmlParser.parseXml(svgStr); const svg = xml.children[0]; const svgAttrs = xmlParser.parseAttrs(svg.attrs); let viewBox = ""; for (const a of svgAttrs) { if (a.name === "viewBox") { viewBox = `viewBox="${a.value}"`; break; } } const symbolBody = xml.children[0].children .map((c) => xmlTostring(c)) .join(""); return `${symbolBody}`; } async function getBuildMetadata(): Promise { const date = new Date().toISOString().slice(2, 10).replaceAll("-", ""); const [commit, diff, newFiles] = await Promise.all([ execAsync("git rev-parse HEAD"), execAsync("git diff HEAD"), execAsync("git ls-files --others --exclude-standard"), ]).then((res) => res.map((r) => r.stdout.trim())); if (!diff && !newFiles) return date + commit.slice(0, 4); const hash = createHash("md5"); hash.update(commit).update(diff).update(newFiles); for (const file of newFiles.split("\n").filter((f) => f)) hash.update(await fsAsync.readFile(file)); return date + hash.digest("hex").slice(0, 4); } async function init(): Promise { const [buildMetadata, packageJsonFile, npmShrinkwrapFile] = await Promise.all( [ getBuildMetadata(), fsAsync.readFile(path.join(INPUT_DIR, "package.json")), fsAsync.readFile(path.join(INPUT_DIR, "npm-shrinkwrap.json")), ], ); const packageJson = JSON.parse(packageJsonFile.toString()); delete packageJson["devDependencies"]; delete packageJson["private"]; delete packageJson["scripts"]; packageJson["version"] = `${packageJson["version"]}+${buildMetadata}`; const npmShrinkwrap = JSON.parse(npmShrinkwrapFile.toString()); npmShrinkwrap["version"] = packageJson["version"]; stripDevDeps(npmShrinkwrap); stripDevDeps2(npmShrinkwrap); await rmDir(OUTPUT_DIR); await fsAsync.mkdir(OUTPUT_DIR); await Promise.all([ fsAsync.mkdir(path.join(OUTPUT_DIR, "bin")), fsAsync.mkdir(path.join(OUTPUT_DIR, "public")), fsAsync.writeFile( path.join(OUTPUT_DIR, "package.json"), JSON.stringify(packageJson, null, 2), ), fsAsync.writeFile( path.join(OUTPUT_DIR, "npm-shrinkwrap.json"), JSON.stringify(npmShrinkwrap, null, 2), ), ]); } async function copyStatic(): Promise { const files = [ "LICENSE", "README.md", "CHANGELOG.md", "public/logo.svg", "public/favicon.png", ]; const [logo, favicon] = await Promise.all([ fsAsync.readFile(path.join(INPUT_DIR, "public/logo.svg")), fsAsync.readFile(path.join(INPUT_DIR, "public/favicon.png")), ]); ASSETS.LOGO_SVG = `logo-${assetHash(logo)}.svg`; ASSETS.FAVICON_PNG = `favicon-${assetHash(favicon)}.png`; const filenames = {} as Record; filenames["public/logo.svg"] = path.join("public", ASSETS.LOGO_SVG); filenames["public/favicon.png"] = path.join("public", ASSETS.FAVICON_PNG); await Promise.all( files.map((f) => fsAsync.copyFile( path.join(INPUT_DIR, f), path.join(OUTPUT_DIR, filenames[f] || f), ), ), ); } async function generateCss(): Promise { const tailwindPlugin = { name: "tailwind", setup(build) { build.onLoad({ filter: /\/ui\/css\/app.css$/ }, async (args) => { const res = await execAsync(`npx @tailwindcss/cli -i ${args.path}`); return { loader: "css", contents: res.stdout }; }); }, } as esbuild.Plugin; const res = await esbuild.build({ bundle: true, absWorkingDir: INPUT_DIR, minify: MODE === "production", sourcemap: "linked", sourcesContent: false, entryPoints: ["ui/css/app.css"], entryNames: "[dir]/[name]-[hash]", outfile: path.join(OUTPUT_DIR, "public/app.css"), plugins: [tailwindPlugin], loader: { ".woff2": "dataurl", }, target: ["chrome111", "safari16.4", "firefox128"], metafile: true, }); for (const [k, v] of Object.entries(res.metafile.outputs)) { if (v.entryPoint === "ui/css/app.css") { ASSETS.APP_CSS = path.relative( path.join(OUTPUT_DIR, "public"), path.join(INPUT_DIR, k), ); break; } } } async function generateBackendJs(): Promise { const services = [ "genieacs-cwmp", "genieacs-ext", "genieacs-nbi", "genieacs-fs", "genieacs-ui", ]; await esbuild.build({ bundle: true, absWorkingDir: INPUT_DIR, minify: MODE === "production", define: { "process.env.NODE_ENV": JSON.stringify(MODE), }, sourcemap: "inline", sourcesContent: false, platform: "node", target: "node12.13.0", packages: "external", banner: { js: "#!/usr/bin/env node" }, entryPoints: services.map((s) => `bin/${s}.ts`), outdir: path.join(OUTPUT_DIR, "bin"), plugins: [packageDotJsonPlugin, assetsPlugin, seedPlugin], }); for (const bin of services) { const p = path.join(OUTPUT_DIR, "bin", bin); await fsAsync.rename(`${p}.js`, p); // Mark as executable const mode = (await fsAsync.lstat(p)).mode; await fsAsync.chmod(p, mode | 73); } } async function generateFrontendJs(): Promise { const res = await esbuild.build({ bundle: true, absWorkingDir: INPUT_DIR, splitting: true, minify: MODE === "production", sourcemap: "linked", sourcesContent: false, platform: "browser", format: "esm", target: ["chrome111", "safari16.4", "firefox128"], entryPoints: ["ui/app.ts"], entryNames: "[dir]/[name]-[hash]", outdir: path.join(OUTPUT_DIR, "public"), plugins: [packageDotJsonPlugin, inlineDepsPlugin, assetsPlugin], metafile: true, }); for (const [k, v] of Object.entries(res.metafile.outputs)) { for (const imp of v.imports) if (imp.external && imp.path !== "views-bundle") throw new Error(`External import found: ${imp.path}`); if (v.entryPoint === "ui/app.ts") { ASSETS.APP_JS = path.relative( path.join(OUTPUT_DIR, "public"), path.join(INPUT_DIR, k), ); } } } async function generateIconsSprite(): Promise { const symbols = [] as string[]; const iconsDir = path.join(INPUT_DIR, "ui/icons"); for (const file of await fsAsync.readdir(iconsDir)) { const id = path.parse(file).name; const filePath = path.join(iconsDir, file); const src = (await fsAsync.readFile(filePath)).toString(); const { data } = await optimize(src, { plugins: [ { name: "preset-default", params: { overrides: { removeViewBox: false, }, }, }, ], }); symbols.push(generateSymbol(id, data)); } const data = `${symbols.join( "", )}`; ASSETS.ICONS_SVG = `icons-${assetHash(data)}.svg`; await fsAsync.writeFile( path.join(OUTPUT_DIR, "public", ASSETS.ICONS_SVG), data, ); } init() .then(() => Promise.all([ Promise.all([generateIconsSprite(), copyStatic()]).then( generateFrontendJs, ), generateCss(), ]).then(generateBackendJs), ) .catch((err) => { process.stderr.write(err.stack + "\n"); }); ================================================ FILE: build/generate-fonts.sh ================================================ #!/bin/bash cd "$(dirname "$0")" declare -A FONTS=( [InterVariable]=https://rsms.me/inter/font-files/InterVariable.woff2 [InterVariable-Italic]=https://rsms.me/inter/font-files/InterVariable-Italic.woff2 [RobotoMono]=https://raw.githubusercontent.com/googlefonts/RobotoMono/main/fonts/variable/RobotoMono%5Bwght%5D.ttf ) for name in "${!FONTS[@]}" do url="${FONTS[$name]}" echo "Downloading $url" TMP=$(mktemp) curl "$url" -s --output "$TMP" pyftsubset "$TMP" --output-file="../ui/css/$name.woff2" --flavor=woff2 --unicodes="U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+2000-206F,U+2074,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD" --layout-features+="tnum" done ================================================ FILE: build/lint.ts ================================================ import { exec } from "node:child_process"; import { promisify } from "node:util"; const execPromise = promisify(exec); async function runEslint(): Promise { const CMD = "eslint 'bin/*.ts' 'lib/**/*.ts' 'ui/**/*.ts' 'test/**/*.ts' 'build/**/*.ts' 'seed/*'"; const env = { ...(process.stdout.isTTY && { FORCE_COLOR: "1" }), ...process.env, }; try { const { stdout, stderr } = await execPromise(CMD, { env }); if (stderr) throw new Error(stderr); return stdout; } catch (err) { if (err.killed || err.signal || err.stderr || err.code !== 1) throw err; return err.stdout; } } async function runTsc(): Promise { const CMD = "tsc --noEmit && tsc -p seed/tsconfig.json"; const env = { ...(process.stdout.isTTY && { FORCE_COLOR: "1" }), ...process.env, }; const { stdout, stderr } = await execPromise(CMD, { env }); if (stderr) throw new Error(stderr); return stdout; } async function runPrettier(): Promise { const CMD = "prettier --prose-wrap always --write ."; const env = { ...(process.stdout.isTTY && { FORCE_COLOR: "1" }), ...process.env, }; const { stdout, stderr } = await execPromise(CMD, { env }); if (stderr) throw new Error(stderr); return stdout; } async function runAll(): Promise { const prom1 = runPrettier(); const prom2 = runEslint(); const prom3 = runTsc(); console.log(await prom1); console.log(await prom2); console.log(await prom3); } runAll().catch(console.error); ================================================ FILE: build/spellcheck-dict.pws ================================================ personal_ws-1.1 en 0 genieacs GenieACS javascript sudo config cwmp CPE systemctl nbi CWMP NBI ACS SSL xsd args DeviceID GENIEACS env param arg AUTH igd TCP toctree auth EnvironmentFile JSON json parameterValues setParameterValues stderr stdout attr cfg CPEs ExecStart faq FileType GenieACS's JWT maxdepth npm objectName refreshObject SerialNumber systemd usr WantedBy yaml chown Config getParameterValues https InternetGatewayDevice mkdir OUI sql TODO UDP addObject AGPLv const cpe cron deleteObject FactoryReset factoryReset FileName fileType Github hostname HTTPS jwt latlong NPM oui parameterNames ProductClass productClass repo SSID sublicense TLS WANIPConnection WPA YourProvisionName abc Abdulla accessors AddObject AddressingType api APIs chmod cwmp's dateext DATETIME dateTime datetime declaratively delaycompress DeleteObject deviceId DHCP dir distro equisatisfiable ExternalIPAddress failover favor func GetParameterAttributes getPassword gte gui hexBinary Hils HOSTNAME init journalctl journald LastFileName LastFileType lastInform LIBXMLJS libxmljs literalinclude lockfile logrotate lte mipsbe normalizers pre quickstart README redis reimplemented RequestDownload RESTful rollout sandboxed scalable SetParameterAttributes SetParamteerValues SIGINT SIGTERM skipWritableCheck stringify subdirectory TargetFileName useradd VirtualParameters vparam xml YAML Zaid cacheExpire iss http statusCode rawData pos Brotli CSV hostInfo IPv downloadSuccessOnTimeout TransferComplete nginx ENCODEURICOMPONENT pageSize skipRootGpn GPN NaN CIDR XMPP PEM JID unindexed ================================================ FILE: build/spellcheck.sh ================================================ #! /bin/sh cd "$(dirname "$0")" FILES=`ls ../docs/*.rst ../docs/*.js ../*.md` for FILE in $FILES do echo $FILE cat $FILE | aspell list --lang=en --add-extra-dicts=./spellcheck-dict.pws --ignore 2 echo done ================================================ FILE: build/test.ts ================================================ import path from "node:path"; import { readdir, readFile } from "node:fs/promises"; import * as esbuild from "esbuild"; const INPUT_DIR = process.cwd(); // Redirect ui/store.ts imports to test/mocks/store.ts const mockStorePlugin: esbuild.Plugin = { name: "mock-store", setup(build) { const storePath = path.join(INPUT_DIR, "ui/store.ts"); const mockStorePath = path.join(INPUT_DIR, "test/mocks/store.ts"); build.onResolve({ filter: /\.\/store\.ts$/ }, (args) => { const resolved = path.join(args.resolveDir, args.path); if (resolved === storePath) { return { path: mockStorePath }; } return undefined; }); }, }; // Export private functions from reactive-store.ts for testing const exportPrivateFunctionsPlugin: esbuild.Plugin = { name: "export-private-functions", setup(build) { const reactiveStorePath = path.join(INPUT_DIR, "ui/reactive-store.ts"); build.onLoad({ filter: /reactive-store\.ts$/ }, async (args) => { if (args.path !== reactiveStorePath) return undefined; let contents = await readFile(args.path, "utf8"); const exports = ` // Test-only exports (added by build/test.ts) export { compareFunction as _testCompareFunction }; export { getObjectId as _testGetObjectId }; export { applyDefaultSort as _testApplyDefaultSort }; export { stores as _testStores }; export { getStore as _testGetStore }; export { ResourceStore as _testResourceStore }; `; contents += exports; return { contents, loader: "ts" }; }); }, }; async function buildTests(): Promise { // Find all test files const testFiles = (await readdir(path.join(INPUT_DIR, "test"))) .filter((f) => f.endsWith(".ts")) .map((f) => path.join("test", f)); await esbuild.build({ entryPoints: testFiles, bundle: true, platform: "node", target: "node18", packages: "external", sourcemap: "inline", outdir: "test", logLevel: "warning", plugins: [mockStorePlugin, exportPrivateFunctionsPlugin], }); } buildTests().catch((err) => { process.stderr.write(err.stack + "\n"); process.exit(1); }); ================================================ FILE: docs/.readthedocs.yaml ================================================ # Read the Docs configuration file for Sphinx projects # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details version: 2 build: os: ubuntu-22.04 tools: python: "3.12" sphinx: configuration: docs/conf.py formats: all python: install: - requirements: docs/requirements.txt ================================================ FILE: docs/administration-faq.rst ================================================ .. _administration-faq: Administration FAQ ================== .. _administration-faq-duplicate-log-entries: Duplicate log entries when using :func:`log()` function ------------------------------------------------------- Because GenieACS uses a full fledged scripting language for device configuration, the only way to guarantee that it has satisfied the 'desired state' is by repeatedly executing the script until there's no more discrepancies with the current device state. Though it may seem like this will cause duplicate requests going to the device, this isn't actually the case because device configuration are stated declaratively and that the scripts themselves are pure functions in the context of a session (e.g. Date.now() always returns the same value within the session). To illustrate with an example, consider the following script: .. code:: javascript log("Executing script"); declare("Device.param", null, {value: 1}); commit(); declare("Device.param", null, {value: 2}); This will set the value of the 'Device.param' to 1, then to 2. Then as the script is run again the value is set back to 1 and so on. A stable state will never be reached so GenieACS will execute the script a few times until it gives up and throws a fault. This is an edge case that should be avoided. A more typical case is where the script is run once or twice. Essentially if an execution doesn't result in any request to the CPE or a change in the data model then a stable state is deemed to have been reached. Configurations not pushed to device after factory reset --------------------------------------------------------- After a device is reset to its factory default state, the cached data model in GenieACS's database needs to be invalidated to force rediscovery. Ensure the following lines are called on ``0 BOOTSTRAP`` event: .. code:: javascript const now = Date.now(); // Clear cached data model to force a refresh clear("Device", now); clear("InternetGatewayDevice", now); Most device parameters are missing ---------------------------------- For performance reasons (server, client, and network), GenieACS by default only fetches parts of the data model that are necessary to satisfy the declarations in your provision scripts. Create declarations for any parameters you need fetched by default. If you're unsure and want to explore the available parameters exposed by the device, refresh the root parameter (e.g. ``InternetGatewayDevice``) from GenieACS's UI. You typically only need to do that one time for a given CPE model. ================================================ FILE: docs/api-reference.rst ================================================ API Reference ============= GenieACS exposes a rich RESTful API through its NBI component. This document serves as a reference for the available APIs. This API makes use of MongoDB's query language in some of its endpoints. Refer to MongoDB's documentation for details. .. note:: The examples below use ``curl`` command for simplicity and ease of testing. Query parameters are URL-encoded, but the original pre-encoding values are shown for reference. These examples assume genieacs-nbi is running locally and listening on the default NBI port (7557). .. warning:: A common pitfall is not properly percent-encoding special characters in the device ID or query in the URL. Endpoints --------- GET /\/?query=\ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Search for records in the database (e.g. devices, tasks, presets, files). Returns a JSON representation of all items in the given collection that match the search criteria. *collection*: The data collection to search. Could be one of: tasks, devices, presets, objects. *query*: Search query. Refer to MongoDB queries for reference. Examples ^^^^^^^^ - Find a device by its ID: .. code:: javascript query = {"_id": "202BC1-BM632w-000000"} .. code:: bash curl -i 'http://localhost:7557/devices/?query=%7B%22_id%22%3A%22202BC1-BM632w-000000%22%7D' - Find a device by its MAC address: .. code:: javascript query = { "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.MACAddress": "20:2B:C1:E0:06:65" } .. code:: bash curl -i 'http://localhost:7557/devices/?query=%7B%22InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.MACAddress%22%3A%2220:2B:C1:E0:06:65%22%7D' - Search for devices that have not initiated an inform in the last 7 days. .. code:: javascript query = { "_lastInform": { "$lt" : "2017-12-11 13:16:23 +0000" } } .. code:: bash curl -i 'http://localhost:7557/devices/?query=%7B%22_lastInform%22%3A%7B%22%24lt%22%3A%222017-12-11%2013%3A16%3A23%20%2B0000%22%7D%7D' - Show pending tasks for a given device: .. code:: javascript query = {"device": "202BC1-BM632w-000000"} .. code:: bash curl -i 'http://localhost:7557/tasks/?query=%7B%22device%22%3A%22202BC1-BM632w-000000%22%7D' - Return specific parameters for a given device: .. code:: javascript query = {"_id": "202BC1-BM632w-000000"} .. code:: bash curl -i 'http://localhost:7557/devices?query=%7B%22_id%22%3A%22202BC1-BM632w-000000%22%7D&projection=InternetGatewayDevice.DeviceInfo.ModelName,InternetGatewayDevice.DeviceInfo.Manufacturer' The ``projection`` URL param is a comma-separated list of the parameters to receive. POST /devices/\/tasks?[connection_request] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Enqueue task(s) and optionally trigger a connection request to the device. Refer to :ref:`tasks` section for information about the task object format. Returns status code 200 if the tasks have been successfully executed, and 202 if the tasks have been queued to be executed at the next inform. *device_id*: The ID of the device. *connection_request*: Indicates that a connection request will be triggered to execute the tasks immediately. Otherwise, the tasks will be queued and be processed at the next inform. The response body is the task object as it is inserted in the database. The object will include ``_id`` property which you can use to look up the task later. Examples ^^^^^^^^ - Refresh all device parameters now: .. code:: bash curl -i 'http://localhost:7557/devices/202BC1-BM632w-000000/tasks?connection_request' \ -X POST \ --data '{"name": "refreshObject", "objectName": ""}' - Change WiFi SSID and password: .. code:: javascript { "name": "setParameterValues", "parameterValues": [ ["InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.SSID", "GenieACS", "xsd:string"], ["InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.PreSharedKey.1.PreSharedKey", "hello world", "xsd:string"] ] } .. code:: bash curl -i 'http://localhost:7557/devices/202BC1-BM632w-000000/tasks?connection_request' \ -X POST \ --data '{"name":"setParameterValues", "parameterValues": [["InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.SSID", "GenieACS", "xsd:string"],["InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.PreSharedKey.1.PreSharedKey", "hello world", "xsd:string"]]}' POST /tasks/\/retry ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Retry a faulty task at the next inform. *task_id*: The ID of the task as returned by 'GET /tasks' request. Example ^^^^^^^ .. code:: bash curl -i 'http://localhost:7557/tasks/5403908ef28ea3a25c138adc/retry' -X POST DELETE /tasks/\ ~~~~~~~~~~~~~~~~~~~~~~~~~ Delete the given task. *task_id*: The ID of the task as returned by 'GET /tasks' request. Example ^^^^^^^ .. code:: bash curl -i 'http://localhost:7557/tasks/5403908ef28ea3a25c138adc' -X DELETE DELETE /faults/\ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Delete the given fault. *fault_id*: The ID of the fault as returned by 'GET /faults' request. The ID format is "\:\". Example ^^^^^^^ .. code:: bash curl -i 'http://localhost:7557/faults/202BC1-BM632w-000000:default' -X DELETE DELETE /devices/\ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Delete the given device from the database. Example ^^^^^^^ .. code:: bash curl -X DELETE -i 'http://localhost:7557/devices/202BC1-BM632w-000001' .. note:: Note that the device will be registered again when/if it contacts the ACS again (e.g. on the next periodic inform). POST /devices/\/tags/\ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Assign a tag to a device. Has no effect if such tag already exists. *device_id*: The ID of the device. *tag*: The tag to be assigned. Example ^^^^^^^ Assign the tag "testing" to a device: .. code:: bash curl -i 'http://localhost:7557/devices/202BC1-BM632w-000000/tags/testing' -X POST DELETE /devices/\/tags/\ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Remove a tag from a device. *device_id*: The ID of the device. *tag*: The tag to be removed. Example ^^^^^^^ Remove the tag "testing" from a device: .. code:: bash curl -i 'http://localhost:7557/devices/202BC1-BM632w-000000/tags/testing' -X DELETE PUT /presets/\ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Create or update a preset. Returns status code 200 if the preset has been added/updated successfully. The body of the request is a JSON representation of the preset. Refer to :ref:`presets` section below for details about its format. *preset_name*: The name of the preset. Example ^^^^^^^ Create a preset to set 5 minutes inform interval for all devices tagged with "test": .. code:: javascript query = { "weight": 0, "precondition": "{\"_tags\": \"test\"}" "configurations": [ { "type": "value", "name": "InternetGatewayDevice.ManagementServer.PeriodicInformEnable", "value": "true" }, { "type": "value", "name": "InternetGatewayDevice.ManagementServer.PeriodicInformInterval", "value": "300" } ] } .. code:: bash curl -i 'http://localhost:7557/presets/inform' \ -X PUT \ --data '{"weight": 0, "precondition": "{\"_tags\": \"test\"}", "configurations": [{"type": "value", "name": "InternetGatewayDevice.ManagementServer.PeriodicInformEnable", "value": "true"}, {"type": "value", "name": "InternetGatewayDevice.ManagementServer.PeriodicInformInterval", "value": "300"}]}' DELETE /presets/\ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code:: bash curl -i 'http://localhost:7557/presets/inform' -X DELETE PUT /files/\ ~~~~~~~~~~~~~~~~~~~~~~~~ Upload a new file or overwrite an existing one. Returns status code 200 if the file has been added/updated successfully. The file content should be sent as the request body. *file_name*: The name of the uploaded file. The following file metadata may be sent as request headers: - ``fileType``: For firmware images it should be "1 Firmware Upgrade Image". Other common types are "2 Web Content" and "3 Vendor Configuration File". - ``oui``: The OUI of the device model that this file belongs to. - ``productClass``: The product class of the device. - ``version``: In case of firmware images, this refer to the firmware version. Example ^^^^^^^ Upload a firmware image file: .. code:: bash curl -i 'http://localhost:7557/files/new_firmware_v1.0.bin' \ -X PUT \ --data-binary @"./new_firmware_v1.0.bin" \ --header "fileType: 1 Firmware Upgrade Image" \ --header "oui: 123456" \ --header "productClass: ABC" \ --header "version: 1.0" DELETE /files/\ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Delete a previously uploaded file: .. code:: bash curl -i 'http://localhost:7557/files/new_firmware_v1.0.bin' -X DELETE GET /files/ ~~~~~~~~~~~ Gets all previously uploaded files. GET /files/?query={"filename":"\"} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Find files using a query. .. _tasks: Tasks ----- Find the different available tasks and their object structure. ``getParameterValues`` ~~~~~~~~~~~~~~~~~~~~~~ .. code:: javascript query = { "name": "getParameterValues", "parameterNames": [ "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnectionNumberOfEntries", "InternetGatewayDevice.Time.NTPServer1", "InternetGatewayDevice.Time.Status" ] } .. code:: bash curl -i 'http://localhost:7557/devices/00236a-96318REF-SR360NA0A4%252D0003196/tasks?timeout=3000&connection_request' \ -X POST \ --data '{"name": "getParameterValues", "parameterNames": ["InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnectionNumberOfEntries", "InternetGatewayDevice.Time.NTPServer1", "InternetGatewayDevice.Time.Status"] }' You may request a single or multiple parameters at once. After the task has been executed successfully you can then fetch the CPE object and read the parameters from the JSON object. .. code:: javascript query = {"_id": "00236a-96318REF-SR360NA0A4%2D0003196"} .. code:: bash curl -i 'http://localhost:7557/devices/?query=%7B%22_id%22%3A%2200236a-96318REF-SR360NA0A4%252D0003196%22%7D' ``refreshObject`` ~~~~~~~~~~~~~~~~~ .. code:: bash curl -i 'http://localhost:7557/devices/00236a-SR552n-SR552NA084%252D0003269/tasks?timeout=3000&connection_request' \ -X POST \ --data '{"name": "refreshObject", "objectName": "InternetGatewayDevice.WANDevice.1.WANConnectionDevice"}' ``setParameterValues`` ~~~~~~~~~~~~~~~~~~~~~~ .. code:: bash curl -i 'http://localhost:7557/devices/00236a-SR552n-SR552NA084%252D0003269/tasks?timeout=3000&connection_request' \ -X POST \ --data '{"name": "setParameterValues", "parameterValues": [["InternetGatewayDevice.ManagementServer.UpgradesManaged",false]]}' Multiple values can be set at once by adding multiple arrays to the parameterValues key. For example: .. code:: javascript { name: "setParameterValues", parameterValues: [["InternetGatewayDevice.ManagementServer.UpgradesManaged", false], ["InternetGatewayDevice.Time.Enable", true], ["InternetGatewayDevice.Time.NTPServer1", "pool.ntp.org"]] } ``addObject`` ~~~~~~~~~~~~~ .. code:: bash curl -i 'http://localhost:7557/devices/00236a-SR552n-SR552NA084%252D0003269/tasks?timeout=3000&connection_request' \ -X POST \ --data '{"name":"addObject","objectName":"InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANPPPConnection"}' ``deleteObject`` ~~~~~~~~~~~~~~~~ .. code:: bash curl -i 'http://localhost:7557/devices/00236a-SR552n-SR552NA084%252D0003269/tasks?timeout=3000&connection_request' \ -X POST \ --data '{"name":"deleteObject","objectName":"InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANPPPConnection.1"}' ``reboot`` ~~~~~~~~~~ .. code:: bash curl -i 'http://localhost:7557/devices/00236a-SR552n-SR552NA084%252D0003269/tasks?timeout=3000&connection_request' \ -X POST \ --data '{"name": "reboot"}' ``factoryReset`` ~~~~~~~~~~~~~~~~ .. code:: bash curl -i 'http://localhost:7557/devices/00236a-SR552n-SR552NA084%252D0003269/tasks?timeout=3000&connection_request' \ -X POST \ --data '{"name": "factoryReset"}' ``download`` ~~~~~~~~~~~~ .. code:: bash curl -i 'http://localhost:7557/devices/00236a-SR552n-SR552NA084%252D0003269/tasks?timeout=3000&connection_request' \ -X POST \ --data '{"name": "download", "file": "mipsbe-6-42-lite.xml"}' .. _presets: Presets ------- Presets assign a set of configuration or a Provision script to devices based on a precondition (search filter), schedule (cron expression), and events. Precondition ~~~~~~~~~~~~ The ``precondition`` property is a JSON string representation of the search filter to test if the preset applies to a given device. Examples preconditions are: - ``{"param": "value"}`` - ``{"param": value", "param2": {"$ne": "value2"}}`` Other operators that can be used are ``$gt``, ``$lt``, ``$gte`` and ``$lte``. Configuration ~~~~~~~~~~~~~ The configuration property is an array containing the different configurations to be applied to a device, as shown below: .. code:: javascript [ { "type": "value", "name": "InternetGatewayDevice.ManagementServer.PeriodicInformEnable", "value": "true" }, { "type": "value", "name": "InternetGatewayDevice.ManagementServer.PeriodicInformInterval", "value": "300" }, { "type": "delete_object", "name": "object_parent", "object": "object_name" }, { "type": "add_object", "name": "object_parent", "object": "object_name" }, { "type": "provision", "name": "YourProvisionName" }, ] The configuration type ``provision`` triggers a Provision script. In the example above, the provision named "YourProvisionName" will be executed. Provisions ---------- Create a provision ~~~~~~~~~~~~~~~~~~ The Provision's JavaScript code is the body of the HTTP PUT request. .. code:: bash curl -X PUT -i 'http://localhost:7557/provisions/mynewprovision' --data 'log("Provision started at " + now);' Delete a provision ~~~~~~~~~~~~~~~~~~ .. code:: bash curl -X DELETE -i 'http://localhost:7557/provisions/mynewprovision' Get provisions ~~~~~~~~~~~~~~ Get all provisions: .. code:: bash curl -X GET -i 'http://localhost:7557/provisions/' ================================================ FILE: docs/conf.py ================================================ # Configuration file for the Sphinx documentation builder. # # This file only contains a selection of the most common options. For a full # list see the documentation: # http://www.sphinx-doc.org/en/master/config # -- Path setup -------------------------------------------------------------- # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. # # import os # import sys # sys.path.insert(0, os.path.abspath('.')) import json # -- Project information ----------------------------------------------------- project = 'GenieACS Documentation' copyright = '2024, GenieACS Inc.' author = 'GenieACS Inc.' # The full version, including alpha/beta/rc tags release = json.load(open("../package.json"))["version"] # -- General configuration --------------------------------------------------- # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ ] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This pattern also affects html_static_path and html_extra_path. exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] # -- Options for HTML output ------------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # # html_theme = 'alabaster' html_theme = 'sphinx_rtd_theme' html_logo = "logo.svg" html_theme_options = { "logo_only": True } # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". # html_static_path = ['_static'] master_doc = 'index' highlight_language = 'javascript' ================================================ FILE: docs/cpe-authentication.rst ================================================ .. _cpe-authentication: CPE Authentication ================== CPE to ACS ---------- .. note:: By default GenieACS will accept any incoming connection via HTTP/HTTPS and respond to it. The following parameters are used to set and get (password is redacted but can be set) the username/password used to authenticate against the ACS: Username: ``Device.ManagementServer.Username`` or ``InternetGatewayDevice.ManagementServer.Username`` Password: ``Device.ManagementServer.Password`` or ``InternetGatewayDevice.ManagementServer.Password`` Enable CPE to ACS Authentication ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CPE to ACS authentication can be configured in the web interface by using the `Config` option in the `Admin` tab. Go to the `Admin` -> `Config` page and click on `New config` button at the bottom of the page. This will open pop-up which requires you to fill in a key and value. The key should be ``cwmp.auth``. The value accepts a boolean. Setting the value to ``true`` makes it so that GenieACS accepts any incoming connection, setting it to ``false`` makes GenieACS deny all incoming connections. This can be further configured using the ``AUTH()`` and ``EXT()`` functions. The ``AUTH()`` function ~~~~~~~~~~~~~~~~~~~~~~~ The ``AUTH()`` function accepts two parameters, username and password. It checks the given username and password with the incoming request to determine whether to return true or false. Basic usage of the ``AUTH()`` function could be as follows: .. code:: sql AUTH("fixed-username", "fixed-password") This will only accept incoming request who authenticate with "fixed-username" and "fixed-password". The various device parameters can be referenced from within the ``cwmp.auth`` expression. For example: .. code:: sql AUTH(Device.ManagementServer.Username, Device.ManagementServer.Password) The ``EXT()`` function ~~~~~~~~~~~~~~~~~~~~~~ The ``EXT()`` function makes it possible to call an :ref:`extension ` script from the auth expression. This can be used to fetch the credentials from an external source: .. code:: sql AUTH(DeviceID.SerialNumber, EXT("authenticate", "getPassword", DeviceID.SerialNumber)) ACS to CPE ---------- TODO ================================================ FILE: docs/environment-variables.rst ================================================ .. _environment-variables: Environment Variables ===================== Configuring GenieACS services can be done through the following environment variables: .. attention:: All GenieACS environment variables must be prefixed with ``GENIEACS_``. MONGODB_CONNECTION_URL MongoDB connection string. Default: ``mongodb://127.0.0.1/genieacs`` EXT_DIR The directory from which to look up extension scripts. Default: ``/config/ext`` EXT_TIMEOUT Timeout (in milliseconds) to allow for calls to extensions to return a response. Default: ``3000`` DEBUG_FILE File to dump CPE debug log. Default: unset DEBUG_FORMAT Debug log format. Valid values are 'yaml' and 'json'. Default: ``yaml`` LOG_FORMAT The format used for the log entries in ``CWMP_LOG_FILE``, ``NBI_LOG_FILE``, ``FS_LOG_FILE``, and ``UI_LOG_FILE``. Possible values are ``simple`` and ``json``. Default: ``simple`` ACCESS_LOG_FORMAT The format used for the log entries in ``CWMP_ACCESS_LOG_FILE``, ``NBI_ACCESS_LOG_FILE``, ``FS_ACCESS_LOG_FILE``, and ``UI_ACCESS_LOG_FILE``. Possible values are ``simple`` and ``json``. Default: ``simple`` CWMP_WORKER_PROCESSES The number of worker processes to spawn for genieacs-cwmp. A value of 0 means as many as there are CPU cores available. Default: ``0`` CWMP_PORT The TCP port that genieacs-cwmp listens on. Default: ``7547`` CWMP_INTERFACE The network interface that genieacs-cwmp binds to. Default: ``::`` CWMP_SSL_CERT Path to certificate file. If omitted, non-secure HTTP will be used. Default: unset CWMP_SSL_KEY Path to certificate key file. If omitted, non-secure HTTP will be used. Default: unset CWMP_LOG_FILE File to log process related events for genieacs-cwmp. If omitted, logs will go to stderr. Default: unset CWMP_ACCESS_LOG_FILE File to log incoming requests for genieacs-cwmp. If omitted, logs will go to stdout. Default: unset NBI_WORKER_PROCESSES The number of worker processes to spawn for genieacs-nbi. A value of 0 means as many as there are CPU cores available. Default: ``0`` NBI_PORT The TCP port that genieacs-nbi listens on. Default: ``7557`` NBI_INTERFACE The network interface that genieacs-nbi binds to. Default: ``::`` NBI_SSL_CERT Path to certificate file. If omitted, non-secure HTTP will be used. Default: unset NBI_SSL_KEY Path to certificate key file. If omitted, non-secure HTTP will be used. Default: unset NBI_LOG_FILE File to log process related events for genieacs-nbi. If omitted, logs will go to stderr. Default: unset NBI_ACCESS_LOG_FILE File to log incoming requests for genieacs-nbi. If omitted, logs will go to stdout. Default: unset FS_WORKER_PROCESSES The number of worker processes to spawn for genieacs-fs. A value of 0 means as many as there are CPU cores available. Default: ``0`` FS_PORT The TCP port that genieacs-fs listens on. Default: ``7567`` FS_INTERFACE The network interface that genieacs-fs binds to. Default: ``::`` FS_SSL_CERT Path to certificate file. If omitted, non-secure HTTP will be used. Default: unset FS_SSL_KEY Path to certificate key file. If omitted, non-secure HTTP will be used. Default: unset FS_LOG_FILE File to log process related events for genieacs-fs. If omitted, logs will go to stderr. Default: unset FS_ACCESS_LOG_FILE File to log incoming requests for genieacs-fs. If omitted, logs will go to stdout. Default: unset FS_URL_PREFIX The URL prefix (e.g. 'https://example.com:7567/') to use when generating the file URL for TR-069 Download requests. Set this if genieacs-fs and genieacs-cwmp are behind a proxy or running on different servers. Default: auto generated based on the hostname from the ACS URL, FS_PORT config, and whether or not SSL is enabled for genieacs-fs. UI_WORKER_PROCESSES The number of worker processes to spawn for genieacs-ui. A value of 0 means as many as there are CPU cores available. Default: ``0`` UI_PORT The TCP port that genieacs-ui listens on. Default: ``3000`` UI_INTERFACE The network interface that genieacs-ui binds to. Default: ``::`` UI_SSL_CERT Path to certificate file. If omitted, non-secure HTTP will be used. Default: unset UI_SSL_KEY Path to certificate key file. If omitted, non-secure HTTP will be used. Default: unset UI_LOG_FILE File to log process related events for genieacs-ui. If omitted, logs will go to stderr. Default: unset UI_ACCESS_LOG_FILE File to log incoming requests for genieacs-ui. If omitted, logs will go to stdout. Default: unset UI_JWT_SECRET The key used for signing JWT tokens that are stored in browser cookies. The string can be up to 64 characters in length. Default: unset ================================================ FILE: docs/ext-sample.js ================================================ // This is an example GenieACS extension to get the current latitude/longitude // of the International Space Station. Why, you ask? Because why not. // To install, copy this file to config/ext/iss.js. "use strict"; const http = require("http"); let cache = null; let cacheExpire = 0; function latlong(args, callback) { if (Date.now() < cacheExpire) return callback(null, cache); http .get("http://api.open-notify.org/iss-now.json", (res) => { if (res.statusCode !== 200) return callback( new Error(`Request failed (status code: ${res.statusCode})`), ); let rawData = ""; res.on("data", (chunk) => (rawData += chunk)); res.on("end", () => { let pos = JSON.parse(rawData)["iss_position"]; cache = [+pos["latitude"], +pos["longitude"]]; cacheExpire = Date.now() + 10000; callback(null, cache); }); }) .on("error", (err) => { callback(err); }); } exports.latlong = latlong; ================================================ FILE: docs/extensions.rst ================================================ .. _extensions: Extensions ========== Given that :ref:`provisions` and :ref:`virtual-parameters` are executed in a sandbox environment, it is not possible to interact with external sources or execute any action that requires OS, file system, or network access. Extensions exist to bridge that gap. Extensions are fully-privileged Node.js modules and as such have access to standard Node libraries and 3rd party packages. Functions exposed by the extension can be called from Provision scripts using the ``ext()`` function. A typical use case for extensions is fetching credentials from a database to have that pushed to the device during provisioning. By default, the extension JS code must be placed under ``config/ext`` directory. You may need to create that directory if it doesn't already exist. The example extension below fetches data from an external REST API and returns that to the caller: .. literalinclude:: ext-sample.js :language: javascript To call this extension from a Provision or a Virtual Parameter script: .. code:: javascript // The arguments "arg1" and "arg2" are passed to the latlong. Though they are // unused in this particular example. const res = ext("ext-sample", "latlong", "arg1", "arg2"); log(JSON.stringify(res)); ================================================ FILE: docs/https.rst ================================================ .. _https: HTTPS ===== TODO ================================================ FILE: docs/index.rst ================================================ .. GenieACS documentation master file, created by sphinx-quickstart on Wed Jun 5 13:47:06 2019. You can adapt this file completely to your liking, but it should at least contain the root `toctree` directive. Welcome to GenieACS's documentation! ==================================== .. toctree:: :caption: Table of Contents .. raw:: latex \part{Installation} .. toctree:: :maxdepth: 1 :caption: Installation installation-guide environment-variables .. raw:: latex \part{Administration} .. toctree:: :maxdepth: 1 :caption: Administration provisions virtual-parameters administration-faq .. raw:: latex \part{Integration} .. toctree:: :maxdepth: 1 :caption: Integration extensions api-reference .. raw:: latex \part{Security} .. toctree:: :maxdepth: 1 :caption: Security https cpe-authentication roles-and-permissions ================================================ FILE: docs/installation-guide.rst ================================================ Installation Guide ================== This guide is for installing GenieACS on a single server on any Linux distro that uses *systemd* as its init system. The various GenieACS services are independent of each other and may be installed on different servers. You may also run multiple instances of each in a load-balancing/failover setup. .. attention:: For production deployments make sure to configure TLS and change ``UI_JWT_SECRET`` to a unique and secure string. Refer to :ref:`https` section for how to enable TLS to encrypt traffic. Prerequisites ------------- .. topic:: Node.js GenieACS requires Node.js 12.13 and up. Refer to https://nodejs.org/ for instructions. .. topic:: MongoDB GenieACS requires MongoDB 3.6 and up. Refer to https://www.mongodb.com/ for instructions. Install GenieACS ------------------- .. topic:: Installing from NPM: .. parsed-literal:: sudo npm install -g genieacs@\ |release| .. topic:: Installing from source If you prefer installing from source, such as when running a GenieACS copy with custom patches, refer to README.md file in the source package. Adjust the next steps below accordingly. Configure systemd ----------------- .. topic:: Create a system user to run GenieACS daemons .. code:: bash sudo useradd --system --no-create-home --user-group genieacs .. topic:: Create directory to save extensions and environment file We'll use :file:`/opt/genieacs/ext/` directory to store extension scripts (if any). .. code:: bash mkdir /opt/genieacs mkdir /opt/genieacs/ext chown genieacs:genieacs /opt/genieacs/ext Create the file :file:`/opt/genieacs/genieacs.env` to hold our configuration options which we pass to GenieACS as environment variables. See :ref:`environment-variables` section for a list of all available configuration options. .. code:: bash GENIEACS_CWMP_ACCESS_LOG_FILE=/var/log/genieacs/genieacs-cwmp-access.log GENIEACS_NBI_ACCESS_LOG_FILE=/var/log/genieacs/genieacs-nbi-access.log GENIEACS_FS_ACCESS_LOG_FILE=/var/log/genieacs/genieacs-fs-access.log GENIEACS_UI_ACCESS_LOG_FILE=/var/log/genieacs/genieacs-ui-access.log GENIEACS_DEBUG_FILE=/var/log/genieacs/genieacs-debug.yaml NODE_OPTIONS=--enable-source-maps GENIEACS_EXT_DIR=/opt/genieacs/ext Generate a secure JWT secret and append to :file:`/opt/genieacs/genieacs.env`: .. code:: bash node -e "console.log(\"GENIEACS_UI_JWT_SECRET=\" + require('crypto').randomBytes(128).toString('hex'))" >> /opt/genieacs/genieacs.env Set file ownership and permissions: .. code:: bash sudo chown genieacs:genieacs /opt/genieacs/genieacs.env sudo chmod 600 /opt/genieacs/genieacs.env .. topic:: Create logs directory .. code:: bash mkdir /var/log/genieacs chown genieacs:genieacs /var/log/genieacs .. topic:: Create systemd unit files Create a systemd unit file for each of the four GenieACS services. Note that we're using EnvironmentFile directive to read the environment variables from the file we created earlier. Each service has two streams of logs: access log and process log. Access logs are configured here to be dumped in a log file under :file:`/var/log/genieacs/` while process logs go to *journald*. Use ``journalctl`` command to view process logs. .. attention:: If the command :command:`systemctl edit --force --full` fails, you can create the unit file manually. 1. Run the following command to create ``genieacs-cwmp`` service: .. code:: bash sudo systemctl edit --force --full genieacs-cwmp Then paste the following in the editor and save: .. code:: cfg [Unit] Description=GenieACS CWMP After=network.target [Service] User=genieacs EnvironmentFile=/opt/genieacs/genieacs.env ExecStart=/usr/bin/genieacs-cwmp [Install] WantedBy=default.target 2. Run the following command to create ``genieacs-nbi`` service: .. code:: bash sudo systemctl edit --force --full genieacs-nbi Then paste the following in the editor and save: .. code:: cfg [Unit] Description=GenieACS NBI After=network.target [Service] User=genieacs EnvironmentFile=/opt/genieacs/genieacs.env ExecStart=/usr/bin/genieacs-nbi [Install] WantedBy=default.target 3. Run the following command to create ``genieacs-fs`` service: .. code:: bash sudo systemctl edit --force --full genieacs-fs Then paste the following in the editor and save: .. code:: cfg [Unit] Description=GenieACS FS After=network.target [Service] User=genieacs EnvironmentFile=/opt/genieacs/genieacs.env ExecStart=/usr/bin/genieacs-fs [Install] WantedBy=default.target 4. Run the following command to create ``genieacs-ui`` service: .. code:: bash sudo systemctl edit --force --full genieacs-ui Then paste the following in the editor and save: .. code:: cfg [Unit] Description=GenieACS UI After=network.target [Service] User=genieacs EnvironmentFile=/opt/genieacs/genieacs.env ExecStart=/usr/bin/genieacs-ui [Install] WantedBy=default.target .. topic:: Configure log file rotation using logrotate Save the following as :file:`/etc/logrotate.d/genieacs` .. code:: /var/log/genieacs/*.log /var/log/genieacs/*.yaml { daily rotate 30 compress delaycompress dateext } .. topic:: Enable and start services .. code:: bash sudo systemctl enable genieacs-cwmp sudo systemctl start genieacs-cwmp sudo systemctl status genieacs-cwmp sudo systemctl enable genieacs-nbi sudo systemctl start genieacs-nbi sudo systemctl status genieacs-nbi sudo systemctl enable genieacs-fs sudo systemctl start genieacs-fs sudo systemctl status genieacs-fs sudo systemctl enable genieacs-ui sudo systemctl start genieacs-ui sudo systemctl status genieacs-ui Review the status message for each to verify that the services are running successfully. ================================================ FILE: docs/provisions.rst ================================================ .. _provisions: Provisions ========== A Provision is a piece of JavaScript code that is executed on the server on a per-device basis. It enables implementing complex provisioning scenarios and other operations such as automated firmware upgrade rollout. Apart from a few special functions, the script is essentially a standard ES6 code executed in strict mode. Provisions are mapped to devices using presets. Note that the added performance overhead when using Provisions as opposed to simple preset configuration entries is relatively small. Anything that can be done via preset configurations can be done using a Provision script. In fact, the now deprecated configuration format is still supported primarily for backward compatibility and it is recommended to use Provision scripts for all configuration. When assigning a Provision script to a preset, you may pass arguments to the script. The arguments can be accessed from the script through the global ``args`` variable. .. note:: Provision scripts may get executed multiple times in a given session. Although all data model-mutating operations are idempotent, a script as a whole may not be. It is, therefore, necessary to repeatedly run the script until there are no more side effects and a stable state is reached. Built-in functions ------------------ ``declare(path, timestamps, values)`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This function is for declaring parameter values to be set, as well as specify constraints on how recent you'd like the parameter value (or other attributes) to have been refreshed from the device. If the given timestamp is lower than the timestamp of the last refresh from the device, then this function will return the last known value. Otherwise, the value will be fetched from the device before being returned to the caller. The timestamp argument is an object where the key is the attribute name (e.g. ``value``, ``object``, ``writable``, ``path``) and the value is an integer representing a Unix timestamp. The values argument is an object similar to the timestamp argument but its property values being the parameter values to be set. The possible attributes in 'timestamps' and 'values' arguments are: - ``value``: a [, ] pair This attribute is not available for objects or object instances. If the value is not a [, ] array then it'll assumed to be a value without a type and therefore the type will be inferred from the parameter's type. - ``writable``: boolean The meaning of this attribute can vary depending on the type of the parameter. In the case of regular parameters, it indicates if its value is writable. In the case of objects, it's whether or not it's possible to add new object instances. In the case of object instances, it indicates whether or not this instance can be deleted. - ``object``: boolean True if this is an object or object instance, false otherwise. - ``path``: string This attribute is special in that it's not a parameter attribute per se, but it refers to the presence of parameters matching the given path. For example, given the following wildcard path: ``InternetGatewayDevice.LANDevice.1.Hosts.Host.*.MACAddress`` Using a recent timestamp for path in ``declare()`` will result in a sync with the device to rediscover all Host instances (``Host.*``). The path attribute can also be used to create or delete object instances as described in :ref:`path-format` section. The return value of ``declare()`` is an iterator to access parameters that match the given path. Each item in the iterator has the attribute 'path' in addition to any other attribute given in the ``declare()`` call. The iterator object itself has convenience attribute accessors which come in handy when you're expecting a single parameter (e.g. when path does not contain wildcards or aliases). .. code:: javascript // Example: Setting the SSID as the last 6 characters of the serial number let serial = declare("Device.DeviceInfo.SerialNumber", {value: 1}); declare("Device.LANDevice.1.WLANConfiguration.1.SSID", null, {value: serial.value[0]}); ``clear(path, timestamp)`` ~~~~~~~~~~~~~~~~~~~~~~~~~~ This function invalidates the database copy of parameters (and their child parameters) that match the given path and have a last refresh timestamp that is less than the given timestamp. The most obvious use for this function is to invalidate the database copy of the entire data model after the device has been factory reset: .. code:: javascript // Example: Clear cached device data model Note // Make sure to apply only on "0 BOOTSTRAP" event clear("Device", Date.now()); clear("InternetGatewayDevice", Date.now()); ``commit()`` ~~~~~~~~~~~~ This function commits the pending declarations and performs any necessary sync with the device. It's usually not required to call this function as it called implicitly at the end of the script and when accessing any property of the promise-like object returned by the ``declare()`` function. Calling this explicitly is only necessary if you want to control the order in which parameters are configured. ``ext(file, function, arg1, arg2, ...)`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Execute an extension script and return the result. The first argument is the script filename while second argument is the function name within that script. Any remaining arguments will be passed to that function. See :ref:`extensions` for more details. ``log(message)`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Prints out a string in genieacs-cwmp's access log. It's meant to be used for debugging. Note that you may see multiple log entries as the script can be executed multiple times in a session. See :ref:`this FAQ `. .. _path-format: Path format ----------- A parameter path may contain a wildcard (``*``) or an alias filter (``[name:value]``). A wildcard segment in a parameter path will apply the declared configuration to zero or more parameters that match the given path where the wildcard segment can be anything. An alias filter is like a wildcard, but additionally performs filtering on the child parameters based on the key-value pairs provided. For example, the following path: ``Device.WANDevice.1.WANConnectionDevice.1.WANIPConnection.[AddressingType:DHCP].ExternalIPAddress`` will return a list of ExternalIPAddress parameters (0 or more) where the sibling parameter AddressingType is assigned the value "DHCP". This can be useful when the exact instance numbers may be different from one device to another. It is possible to use more than one key-value pair in the alias filter. It's also possible to use multiple filters or use a combination of filters and wildcards. Creating/deleting object instances ---------------------------------- Given the declarative nature of provisions, we cannot explicitly tell the device to create or delete an instance under a given object. Instead, we specify the number of instances we want there to be, and based on that GenieACS will determine whether or not it needs to create or delete instances. For example, the following declaration will ensure we have one and only one WANIPConnection object: .. code:: javascript // Example: Ensure we have one and only one WANIPConnection object declare("InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.*", null, {path: 1}); Note the wildcard at the end of the parameter path. It is also possible to use alias filters as the last path segment which will ensure that the declared number of instances is satisfied given the alias filter: .. code:: javascript // Ensure that *all* other instances are deleted declare("InternetGatewayDevice.X_BROADCOM_COM_IPAddrAccCtrl.X_BROADCOM_COM_IPAddrAccCtrlListCfg.[]", null, {path: 0}); // Add the two entries we care about declare("InternetGatewayDevice.X_BROADCOM_COM_IPAddrAccCtrl.X_BROADCOM_COM_IPAddrAccCtrlListCfg.[SourceIPAddress:192.168.1.0,SourceNetMask:255.255.255.0]", {path: now}, {path: 1}); declare("InternetGatewayDevice.X_BROADCOM_COM_IPAddrAccCtrl.X_BROADCOM_COM_IPAddrAccCtrlListCfg.[SourceIPAddress:172.16.12.0,SourceNetMask:255.255.0.0]", {path: now}, {path: 1}); Special GenieACS parameters --------------------------- In addition to the parameters exposed in the device's data model through TR-069, GenieACS has its own set of special parameters: ``DeviceID`` ~~~~~~~~~~~~ This parameter sub-tree includes the following read-only parameters: - ``DeviceID.ID`` - ``DeviceID.SerialNumber`` - ``DeviceID.ProductClass`` - ``DeviceID.OUI`` - ``DeviceID.Manufacturer`` ``Tags`` ~~~~~~~~ The ``Tags`` root parameter is used to expose device tags in the data model. Tags appear as child parameters that are writable and have boolean value. Setting a tag to ``false`` will delete that tag, and setting the value of a non-existing tag parameter to ``true`` will create it. .. code:: javascript // Example: Remove "tag1", add "tag2", and read "tag3" declare("Tags.tag1", null, {value: false}); declare("Tags.tag2", null, {value: true}); let tag3 = declare("Tags.tag3", {value: 1}); ``Reboot`` ~~~~~~~~~~ The ``Reboot`` root parameter hold the timestamp of the last reboot command. The parameter value is writable and declaring a timestamp value that is larger than the current value will trigger a reboot. .. code:: javascript // Example: Reboot the device only if it hasn't been rebooted in the past 300 seconds declare("Reboot", null, {value: Date.now() - (300 * 1000)}); ``FactoryReset`` ~~~~~~~~~~~~~~~~ Works like ``Reboot`` parameter but for factory reset. .. code:: javascript // Example: Default the device to factory settings declare("FactoryReset", null, {value: Date.now()}); ``Downloads`` ~~~~~~~~~~~~~ The ``Downloads`` sub-tree holds information about the last download command(s). A download command is represented as an instance (e.g. ``Downloads.1``) containing parameters such as ``Download`` (timestamp), ``LastFileType``, ``LastFileName``. The parameters ``FileType``, ``FileName``, ``TargetFileName`` and ``Download`` are writable and can be used to trigger a new download. .. code:: javascript declare("Downloads.[FileType:1 Firmware Upgrade Image]", {path: 1}, {path: 1}); declare("Downloads.[FileType:1 Firmware Upgrade Image].FileName", {value: 1}, {value: "firmware-2017.01.tar"}); declare("Downloads.[FileType:1 Firmware Upgrade Image].Download", {value: 1}, {value: Date.now()}); Common file types are: - ``1 Firmware Upgrade Image`` - ``2 Web Content`` - ``3 Vendor Configuration File`` - ``4 Tone File`` - ``5 Ringer File`` .. warning:: Pushing a file to the device is often a service-interrupting operation. It's recommended to only trigger it on certain events such as ``1 BOOT`` or during a predetermined maintenance window). After the CPE had finished downloading and applying the config file, it will send a ``7 TRANSFER COMPLETE`` event. You may use that to trigger a reboot after the firmware image or configuration file had been applied. ================================================ FILE: docs/requirements.txt ================================================ sphinx_rtd_theme==2.0.0 ================================================ FILE: docs/roles-and-permissions.rst ================================================ .. _roles-and-permissions: Roles and Permissions ===================== TODO ================================================ FILE: docs/virtual-parameters.rst ================================================ .. _virtual-parameters: Virtual Parameters ================== Virtual parameters are user-defined parameters whose values are generated using a custom Javascript code. Virtual parameters behave just like regular parameters and appear in the data model under ``VirtualParameters.`` path. Virtual parameter names cannot contain a period (``.``). The execution environment for virtual parameters is almost identical to that of provisions. See :ref:`provisions` for more details and examples. The only differences between the scripts of provisions and virtual parameters are: - You can't pass custom arguments to virtual parameter scripts. Instead, the variable ``args`` will hold the current vparam timestamps and values as well as the declared timestamps and values. Like this: .. code:: javascript // [, , ] [{path: 1559849387191, value: 1559849387191}, {value: ["new val", "xsd:string"]}, {path: 1559840000000, value: 1559840000000}, {value: ["cur val", "xsd:string"]}] - Virtual parameter scripts must return an object containing the attributes of this parameter. .. note:: Just like a regular parameter, creating a virtual parameter does not automatically add it to the parameter list for a device. It needs to fetched (manually or via a preset) before you can see it in the data model. Examples -------- Unified MAC parameter across different device models ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code:: javascript // Example: Unified MAC parameter across different device models let m = "00:00:00:00:00:00"; let d = declare("Device.WANDevice.*.WANConnectionDevice.*.WANIPConnection.*.MACAddress", {value: Date.now()}); let igd = declare("InternetGatewayDevice.WANDevice.*.WANConnectionDevice.*.WANPPPConnection.*.MACAddress", {value: Date.now()}); if (d.size) { for (let p of d) { if (p.value[0]) { m = p.value[0]; break; } } } else if (igd.size) { for (let p of igd) { if (p.value[0]) { m = p.value[0]; break; } } } return {writable: false, value: [m, "xsd:string"]}; Expose an external value as a virtual parameter ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code:: javascript // Example: Expose an external value as a virtual parameter let serial = declare("DeviceID.SerialNumber", {value: 1}); if (args[1].value) { ext("example-ext", "set", serial.value[0], args[1].value[0]); return {writable: true, value: [args[1].value[0], "xsd:string"]}; } else { let v = ext("example-ext", "get", serial.value[0]); return {writable: true, value: [v, "xsd:string"]}; } Create an editable virtual parameter for WPA passphrase ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code:: javascript // Example: Create an editable virtual parameter for WPA passphrase let m = ""; if (args[1].value) { m = args[1].value[0]; declare("Device.WiFi.AccessPoint.1.Security.KeyPassphrase", null, {value: m}); declare("InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.KeyPassphrase", null, {value: m}); } else { let d = declare("Device.WiFi.AccessPoint.1.Security.KeyPassphrase", {value: Date.now()}); let igd = declare("InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.KeyPassphrase", {value: Date.now()}); if (d.size) { m = d.value[0]; } else if (igd.size) { m = igd.value[0]; } } return {writable: true, value: [m, "xsd:string"]}; ================================================ FILE: eslint.config.mjs ================================================ import { defineConfig } from "@eslint/config-helpers"; import eslint from "@eslint/js"; import tseslint from "typescript-eslint"; import eslintConfigPrettier from "eslint-config-prettier"; import globals from "globals"; export default defineConfig( { ignores: ["dist/", "test/*.js"], }, eslint.configs.recommended, ...tseslint.configs.recommended, eslintConfigPrettier, { languageOptions: { globals: { ...globals.es2022, ...globals.node, }, parserOptions: { projectService: true, tsconfigRootDir: import.meta.dirname, }, }, rules: { "@typescript-eslint/no-shadow": ["error", { allow: ["err"] }], "handle-callback-err": "error", "prefer-arrow-callback": "error", "no-buffer-constructor": "error", "prefer-const": ["error", { destructuring: "all" }], eqeqeq: ["error", "always", { null: "ignore" }], "@typescript-eslint/no-explicit-any": "off", "@typescript-eslint/no-use-before-define": [ "error", { functions: false }, ], "@typescript-eslint/explicit-function-return-type": [ "error", { allowExpressions: true }, ], "@typescript-eslint/no-floating-promises": "error", "@typescript-eslint/no-misused-promises": "error", "no-prototype-builtins": "off", }, }, { files: ["ui/**/*.ts", "ui/**/*.tsx"], languageOptions: { globals: { ...globals.browser, }, }, }, { files: ["seed/*.js"], languageOptions: { parserOptions: { project: null, }, globals: { declare: "readonly", clear: "readonly", commit: "readonly", ext: "readonly", log: "readonly", args: "readonly", }, }, rules: { "@typescript-eslint/explicit-function-return-type": "off", "@typescript-eslint/no-floating-promises": "off", "@typescript-eslint/no-misused-promises": "off", "@typescript-eslint/no-shadow": "off", "no-shadow": ["error", { allow: ["err", "total"] }], }, }, { files: ["seed/*.jsx"], languageOptions: { parserOptions: { project: null, }, globals: { ...globals.browser, node: "readonly", Signal: "readonly", }, }, rules: { "@typescript-eslint/explicit-function-return-type": "off", "@typescript-eslint/no-floating-promises": "off", "@typescript-eslint/no-misused-promises": "off", "@typescript-eslint/no-shadow": "off", "no-shadow": ["error", { allow: ["err", "total"] }], }, }, ); ================================================ FILE: lib/api-functions.ts ================================================ import { ObjectId } from "mongodb"; import { collections } from "./db/db.ts"; import { deleteConfig, deleteFault as dbDeleteFault, deleteFile, deletePermission, deletePreset, deleteProvision, deleteTask, deleteUser, deleteVirtualParameter, putConfig, putPermission, putPreset, putProvision, putUser, putVirtualParameter, putView, deleteView, } from "./ui/db.ts"; import * as common from "./util.ts"; import * as cache from "./cache.ts"; import { acquireLock, getToken, releaseLock } from "./lock.ts"; import { getRevision, getConfig, getConfigExpression, getUsers, } from "./ui/local-cache.ts"; import { httpConnectionRequest, udpConnectionRequest, xmppConnectionRequest, } from "./connection-request.ts"; import { Task } from "./types.ts"; import Expression, { Value } from "./common/expression.ts"; import { hashPassword } from "./auth.ts"; import { flattenDevice } from "./ui/db.ts"; import { ResourceLockedError } from "./common/errors.ts"; import * as config from "../lib/config.ts"; const XMPP_CONFIGURED = !!config.get("XMPP_JID"); export async function connectionRequest( deviceId: string, device?: Record, ): Promise { if (!device) { const res = await collections.devices.findOne({ _id: deviceId }); if (!res) throw new Error("No such device"); device = flattenDevice(res); } let connectionRequestUrl, udpConnectionRequestAddress, stunEnable, connReqJabberId, username, password; if (device["InternetGatewayDevice.ManagementServer.ConnectionRequestURL"]) { connectionRequestUrl = device["InternetGatewayDevice.ManagementServer.ConnectionRequestURL"] || ""; udpConnectionRequestAddress = device[ "InternetGatewayDevice.ManagementServer.UDPConnectionRequestAddress" ] || ""; stunEnable = device["InternetGatewayDevice.ManagementServer.STUNEnable"] || ""; connReqJabberId = device["InternetGatewayDevice.ManagementServer.ConnReqJabberID"] || ""; username = device[ "InternetGatewayDevice.ManagementServer.ConnectionRequestUsername" ] || ""; password = device[ "InternetGatewayDevice.ManagementServer.ConnectionRequestPassword" ] || ""; } else { connectionRequestUrl = device["Device.ManagementServer.ConnectionRequestURL"] || ""; udpConnectionRequestAddress = device["Device.ManagementServer.UDPConnectionRequestAddress"] || ""; stunEnable = device["Device.ManagementServer.STUNEnable"] || ""; connReqJabberId = device["Device.ManagementServer.ConnReqJabberID"] || ""; username = device["Device.ManagementServer.ConnectionRequestUsername"] || ""; password = device["Device.ManagementServer.ConnectionRequestPassword"] || ""; } let remoteAddress; try { remoteAddress = new URL(connectionRequestUrl).hostname; } catch { return "Invalid connection request URL"; } const snapshot = await getRevision(); const now = Date.now(); const evalCallback = (exp: Expression): Expression => { if (exp instanceof Expression.Parameter) { let name = exp.path.toString(); if (name === "id") name = "DeviceID.ID"; else if (name === "serialNumber") name = "DeviceID.SerialNumber"; else if (name === "productClass") name = "DeviceID.ProductClass"; else if (name === "oui") name = "DeviceID.OUI"; else if (name === "remoteAddress") return new Expression.Literal(remoteAddress); else if (name === "username") return new Expression.Literal(username); else if (name === "password") return new Expression.Literal(password); return new Expression.Literal(device[name] ?? null); } else if (exp instanceof Expression.FunctionCall) { if (exp.name === "NOW") return new Expression.Literal(now); else if (exp.name === "REMOTE_ADDRESS") return new Expression.Literal(remoteAddress); else if (exp.name === "USERNAME") return new Expression.Literal(username); else if (exp.name === "PASSWORD") return new Expression.Literal(password); } return exp; }; const configCallback = (exp: Expression): Expression.Literal => { const e = evalCallback(exp); if (e instanceof Expression.Literal) return e; return new Expression.Literal(null); }; const UDP_CONNECTION_REQUEST_PORT = getConfig( snapshot, "cwmp.udpConnectionRequestPort", 0, configCallback, ); const CONNECTION_REQUEST_TIMEOUT = getConfig( snapshot, "cwmp.connectionRequestTimeout", 2000, configCallback, ); const CONNECTION_REQUEST_ALLOW_BASIC_AUTH = getConfig( snapshot, "cwmp.connectionRequestAllowBasicAuth", false, configCallback, ); let authExp: Expression = getConfigExpression( snapshot, "cwmp.connectionRequestAuth", ); if (!authExp) { authExp = new Expression.FunctionCall("AUTH", [ new Expression.FunctionCall("USERNAME", []), new Expression.FunctionCall("PASSWORD", []), ]); } authExp = authExp.evaluate(evalCallback); const debug = getConfig(snapshot, "cwmp.debug", false, configCallback); let udpProm = Promise.resolve(false); if (udpConnectionRequestAddress && +stunEnable) { try { const u = new URL("udp://" + udpConnectionRequestAddress); udpProm = udpConnectionRequest( u.hostname, parseInt(u.port || "80"), authExp, UDP_CONNECTION_REQUEST_PORT, debug, deviceId, ).then( () => true, () => false, ); } catch { // Ignore invalid address } } let status; if (connReqJabberId && XMPP_CONFIGURED) { status = await xmppConnectionRequest( connReqJabberId, authExp, CONNECTION_REQUEST_TIMEOUT, debug, deviceId, ); } else { status = await httpConnectionRequest( connectionRequestUrl, authExp, CONNECTION_REQUEST_ALLOW_BASIC_AUTH, CONNECTION_REQUEST_TIMEOUT, debug, deviceId, ); } if (await udpProm) return ""; return status; } export async function awaitSessionStart( deviceId: string, lastInform: number, timeout: number, ): Promise { const now = Date.now(); const device = await collections.devices.findOne( { _id: deviceId }, { projection: { _lastInform: 1 } }, ); const li = (device["_lastInform"] as Date).getTime(); if (li > lastInform) return true; const token = await getToken(`cwmp_session_${deviceId}`); if (token?.startsWith("cwmp_session_")) return true; if (timeout < 500) return false; await new Promise((resolve) => setTimeout(resolve, 500)); timeout -= Date.now() - now; return awaitSessionStart(deviceId, lastInform, timeout); } export async function awaitSessionEnd( deviceId: string, timeout: number, ): Promise { const now = Date.now(); const token = await getToken(`cwmp_session_${deviceId}`); if (!token?.startsWith("cwmp_session_")) return true; if (timeout < 500) return false; await new Promise((resolve) => setTimeout(resolve, 500)); timeout -= Date.now() - now; return awaitSessionEnd(deviceId, timeout); } function sanitizeTask(task): void { task.timestamp = new Date(task.timestamp || Date.now()); if (task.expiry) { if (task.expiry instanceof Date || isNaN(task.expiry)) task.expiry = new Date(task.expiry); else task.expiry = new Date(task.timestamp.getTime() + +task.expiry * 1000); } const validParamValue = (p): boolean => { if ( !Array.isArray(p) || p.length < 2 || typeof p[0] !== "string" || !p[0].length || !["string", "boolean", "number"].includes(typeof p[1]) || (p[2] != null && typeof p[2] !== "string") ) return false; return true; }; switch (task.name) { case "getParameterValues": if (!Array.isArray(task.parameterNames) || !task.parameterNames.length) throw new Error("Missing 'parameterNames' property"); for (const p of task.parameterNames) { if (typeof p !== "string" || !p.length) throw new Error(`Invalid parameter name '${p}'`); } break; case "setParameterValues": if (!Array.isArray(task.parameterValues) || !task.parameterValues.length) throw new Error("Missing 'parameterValues' property"); for (const p of task.parameterValues) { if (!validParamValue(p)) throw new Error(`Invalid parameter value '${p}'`); } break; case "refreshObject": if (typeof task.objectName !== "string") throw new Error("Missing 'objectName' property"); break; case "deleteObject": if (typeof task.objectName !== "string" || !task.objectName.length) throw new Error("Missing 'objectName' property"); break; case "addObject": if (task.parameterValues != null) { if (!Array.isArray(task.parameterValues)) throw new Error("Invalid 'parameterValues' property"); for (const p of task.parameterValues) { if (!validParamValue(p)) throw new Error(`Invalid parameter value '${p}'`); } } break; case "download": // genieacs-gui sends file ID instead of fileName and fileType if (!task.file) { if (typeof task.fileType !== "string" || !task.fileType.length) throw new Error("Missing 'fileType' property"); if (typeof task.fileName !== "string" || !task.fileName.length) throw new Error("Missing 'fileName' property"); } if ( task.targetFileName != null && typeof task.targetFileName !== "string" ) throw new Error("Invalid 'targetFileName' property"); break; case "provisions": if ( !Array.isArray(task.provisions) || !task.provisions.every((arr) => arr.every( (s) => s == null || ["boolean", "number", "string"].includes(typeof s), ), ) ) throw new Error("Invalid 'provisions' property"); break; case "reboot": break; case "factoryReset": break; default: throw new Error("Invalid task name"); } return task; } export async function insertTasks(tasks: any[]): Promise { if (tasks && !Array.isArray(tasks)) tasks = [tasks]; else if (!tasks?.length) return tasks || []; for (const task of tasks) { sanitizeTask(task); if (task.uniqueKey) { await collections.tasks.deleteOne({ device: task.device, uniqueKey: task.uniqueKey, }); } } await collections.tasks.insertMany(tasks); for (const task of tasks) task._id = task._id.toString(); return tasks; } export async function deleteDevice(deviceId: string): Promise { const token = await acquireLock(`cwmp_session_${deviceId}`, 5000); if (!token) throw new ResourceLockedError("Device is in session"); try { await Promise.all([ collections.tasks.deleteMany({ device: deviceId }), collections.devices.deleteOne({ _id: deviceId }), collections.faults.deleteMany({ _id: { $regex: `^${common.escapeRegExp(deviceId)}\\:`, }, }), collections.operations.deleteMany({ _id: { $regex: `^${common.escapeRegExp(deviceId)}\\:`, }, }), ]); } finally { await releaseLock(`cwmp_session_${deviceId}`, token); } } export async function deleteFault(id: string): Promise { const deviceId = id.split(":", 1)[0]; const channel = id.slice(deviceId.length + 1); const token = await acquireLock(`cwmp_session_${deviceId}`, 5000); if (!token) throw new ResourceLockedError("Device is in session"); try { const proms = [dbDeleteFault(id)]; if (channel.startsWith("task_")) proms.push(deleteTask(new ObjectId(channel.slice(5)))); await Promise.all(proms); } finally { await releaseLock(`cwmp_session_${deviceId}`, token); } } export async function deleteResource( resource: string, id: string, ): Promise { if (resource === "devices") { await deleteDevice(id); } else if (resource === "files") { await deleteFile(id); await cache.del("cwmp-local-cache-hash"); } else if (resource === "faults") { await deleteFault(id); } else if (resource === "provisions") { await deleteProvision(id); await cache.del("cwmp-local-cache-hash"); } else if (resource === "presets") { await deletePreset(id); await cache.del("cwmp-local-cache-hash"); } else if (resource === "virtualParameters") { await deleteVirtualParameter(id); await cache.del("cwmp-local-cache-hash"); } else if (resource === "config") { await deleteConfig(id); await Promise.all([ cache.del("ui-local-cache-hash"), cache.del("cwmp-local-cache-hash"), ]); } else if (resource === "permissions") { await deletePermission(id); await cache.del("ui-local-cache-hash"); } else if (resource === "users") { await deleteUser(id); await cache.del("ui-local-cache-hash"); } else if (resource === "views") { await deleteView(id); await cache.del("ui-local-cache-hash"); } else { throw new Error(`Unknown resource ${resource}`); } } // TODO Implement validation export async function putResource( resource: string, id: string, data: any, ): Promise { if (resource === "presets") { await putPreset(id, data); await cache.del("cwmp-local-cache-hash"); } else if (resource === "provisions") { await putProvision(id, data); await cache.del("cwmp-local-cache-hash"); } else if (resource === "virtualParameters") { await putVirtualParameter(id, data); await cache.del("cwmp-local-cache-hash"); } else if (resource === "config") { await putConfig(id, data); await Promise.all([ cache.del("ui-local-cache-hash"), cache.del("cwmp-local-cache-hash"), ]); } else if (resource === "permissions") { await putPermission(id, data); await cache.del("ui-local-cache-hash"); } else if (resource === "users") { delete data["password"]; delete data["salt"]; await putUser(id, data); await cache.del("ui-local-cache-hash"); } else if (resource === "views") { await putView(id, data); await cache.del("ui-local-cache-hash"); } else { throw new Error(`Unknown resource ${resource}`); } } export function authLocal( snapshot: string, username: string, password: string, ): Promise { return new Promise((resolve, reject) => { const users = getUsers(snapshot); const user = users[username]; if (!user?.password) return void resolve(null); hashPassword(password, user.salt) .then((hash) => { if (hash === user.password) resolve(true); else resolve(false); }) .catch(reject); }); } ================================================ FILE: lib/auth.ts ================================================ import { createHash, randomBytes, pbkdf2 } from "node:crypto"; function parseHeaderFeilds(str: string): Record { const res = {}; const parts = str.split(","); let part: string; while ((part = parts.shift()) != null) { const name = part.split("=", 1)[0]; if (name.length === part.length) { if (!part.trim()) continue; throw new Error("Unable to parse auth header"); } let value = part.slice(name.length + 1); if (!/^\s*"/.test(value)) { value = value.trim(); } else { while (!/[^\\]"\s*$/.test(value)) { const p = parts.shift(); if (p == null) throw new Error("Unable to parse auth header"); value += "," + p; } try { value = JSON.parse(value); } catch (error) { throw new Error("Unable to parse auth header", { cause: error }); } } res[name.trim()] = value; } return res; } export function parseAuthorizationHeader(authHeader: string): { method: string; } { authHeader = authHeader.trim(); const method = authHeader.split(" ", 1)[0]; const res = { method: method }; if (method === "Basic") { // Inspired by https://github.com/jshttp/basic-auth const USER_PASS_REGEX = /^([^:]*):(.*)$/; const creds = USER_PASS_REGEX.exec( Buffer.from(authHeader.slice(method.length + 1), "base64").toString(), ); if (!creds) throw new Error("Unable to parse auth header"); res["username"] = creds[1]; res["password"] = creds[2]; } else if (method === "Digest") { Object.assign(res, parseHeaderFeilds(authHeader.slice(method.length + 1))); } return res; } export function parseWwwAuthenticateHeader( authHeader: string, ): Record { authHeader = authHeader.trim(); const method = authHeader.split(" ", 1)[0]; const res = { method: method }; Object.assign(res, parseHeaderFeilds(authHeader.slice(method.length + 1))); return res; } export function basic(username: string, password: string): string { return "Basic " + Buffer.from(`${username}:${password}`).toString("base64"); } export function digest( username: string | Buffer, realm: string | Buffer, password: string | Buffer, nonce: string | Buffer, httpMethod: string | Buffer, uri: string | Buffer, qop?: string | Buffer, body?: string | Buffer, cnonce?: string | Buffer, nc?: string | Buffer, ): string { const ha1 = createHash("md5"); ha1.update(username).update(":").update(realm).update(":").update(password); // TODO support "MD5-sess" algorithm directive const ha1d = ha1.digest("hex"); const ha2 = createHash("md5"); ha2.update(httpMethod).update(":").update(uri); if (qop === "auth-int") { const bodyHash = createHash("md5") .update(body || "") .digest("hex"); ha2.update(":").update(bodyHash); } const ha2d = ha2.digest("hex"); const hash = createHash("md5"); hash.update(ha1d).update(":").update(nonce); if (qop) { hash .update(":") .update(nc) .update(":") .update(cnonce) .update(":") .update(qop); } hash.update(":").update(ha2d); return hash.digest("hex"); } export function solveDigest( username: string | Buffer, password: string | Buffer, uri: string | Buffer, httpMethod: string | Buffer, body: string | Buffer, authHeader: Record, ): string { const cnonce = randomBytes(8).toString("hex"); const nc = "00000001"; let qop; if (authHeader.qop) { if (authHeader.qop.indexOf(",") !== -1) qop = "auth"; // Either auth or auth-int, prefer auth else qop = authHeader.qop; } const hash = digest( username, authHeader.realm, password, authHeader.nonce, httpMethod, uri, qop, body, cnonce, nc, ); let authString = `Digest username="${username}"`; authString += `,realm="${authHeader.realm}"`; authString += `,nonce="${authHeader.nonce}"`; authString += `,uri="${uri}"`; if (authHeader.algorithm) authString += `,algorithm=${authHeader.algorithm}`; if (qop) authString += `,qop=${qop},nc=${nc},cnonce="${cnonce}"`; authString += `,response="${hash}"`; if (authHeader.opaque) authString += `,opaque="${authHeader.opaque}"`; return authString; } export function generateSalt(length: number): Promise { return new Promise((resolve, reject) => { randomBytes(length, (err, rand) => { if (err) return void reject(err); resolve(rand.toString("hex")); }); }); } export function hashPassword(pass: string, salt: string): Promise { return new Promise((resolve, reject) => { pbkdf2(pass, salt, 10000, 128, "sha512", (err, hash) => { if (err) return void reject(err); resolve(hash.toString("hex")); }); }); } ================================================ FILE: lib/bundle-views.ts ================================================ import esbuild from "esbuild"; import { APP_JS } from "../build/assets.ts"; import { Views } from "./types.ts"; export async function validateViewScript( id: string, script: string, ): Promise { const input = buildInput({ [id]: { md5: "", script } } as unknown as Views); try { await runBuild(input); } catch (err) { if (!err.errors?.length) throw err; const e = err.errors[0]; if (!e.location) return e.text; const offset = input .slice(0, input.indexOf("function(node,")) .split("\n").length; const line = e.location.line - offset; return `${e.text} at ${id}:${line}:${e.location.column}`; } return null; } function buildInput(views: Views): string { const appJsPath = `./${APP_JS}`; const viewEntries: string[] = []; for (const [k, v] of Object.entries(views)) { viewEntries.push(` "${k}": function(node, setTimeout, setInterval, Date) { ${v.script} }`); } return ` import {ViewNode, Signal} from "${appJsPath}"; function h(name, attributes, ...children) { return new ViewNode(name, attributes, children.flat()); } export default { ${viewEntries.join(",\n")} }; `; } export async function bundleViews(views: Views): Promise { return runBuild(buildInput(views)); } async function runBuild(input: string): Promise { const appJsPath = `./${APP_JS}`; const buildResult = await esbuild.build({ stdin: { contents: input, loader: "jsx", }, bundle: true, write: false, format: "esm", logLevel: "silent", minify: process.env.NODE_ENV === "production", jsxFactory: "h", jsxFragment: "null", plugins: [ { name: "import-resolver", setup(build) { build.onResolve({ filter: /.*/ }, (args) => { if (args.path === appJsPath) return { sideEffects: false, external: true }; return { path: args.path, namespace: "env-ns" }; }); build.onLoad({ filter: /.*/, namespace: "env-ns" }, () => { throw new Error(`import not supported`); }); }, }, ], }); return buildResult.outputFiles[0].text; } ================================================ FILE: lib/cache.ts ================================================ import { collections } from "./db/db.ts"; import * as config from "./config.ts"; const CLOCK_SKEW_TOLERANCE = 30000; const MAX_CACHE_TTL = +config.get("MAX_CACHE_TTL"); export async function get(key: string): Promise { const res = await collections.cache.findOne({ _id: key }); return res?.value; } export async function del(key: string): Promise { await collections.cache.deleteOne({ _id: key }); } export async function set( key: string, value: string, ttl: number = MAX_CACHE_TTL, ): Promise { const timestamp = new Date(); const expire = new Date( timestamp.getTime() + CLOCK_SKEW_TOLERANCE + ttl * 1000, ); await collections.cache.replaceOne( { _id: key }, { value, expire, timestamp }, { upsert: true }, ); } export async function pop(key: string): Promise { const res = await collections.cache.findOneAndDelete({ _id: key }); return res.value?.value; } ================================================ FILE: lib/cluster.ts ================================================ import cluster, { Worker } from "node:cluster"; import { cpus } from "node:os"; import * as logger from "./logger.ts"; let respawnTimestamp = 0; let crashes: number[] = []; function fork(): Worker { const w = cluster.fork(); w.on("error", (err: NodeJS.ErrnoException) => { // Avoid exception when attempting to kill the process just as it's exiting if (err.code !== "EPIPE") throw err; setTimeout(() => { if (!w.isDead()) throw err; }, 50); }); return w; } function restartWorker(worker, code, signal): void { const msg = { message: "Worker died", pid: worker.process.pid, exitCode: null, signal: null, }; if (code != null) msg.exitCode = code; if (signal != null) msg.signal = signal; logger.error(msg); const now = Date.now(); crashes.push(now); let min1 = 0, min2 = 0, min3 = 0; crashes = crashes.filter((n) => { if (n > now - 60000) ++min1; else if (n > now - 120000) ++min2; else if (n > now - 180000) ++min3; else return false; return true; }); if (min1 > 5 && min2 > 5 && min3 > 5) { process.exitCode = 1; cluster.removeListener("exit", restartWorker); for (const pid in cluster.workers) cluster.workers[pid].kill(); logger.error({ message: "Too many crashes, exiting", pid: process.pid, }); return; } respawnTimestamp = Math.max(now, respawnTimestamp + 2000); if (respawnTimestamp === now) { fork(); return; } setTimeout(() => { if (process.exitCode) return; fork(); }, respawnTimestamp - now); } export function start( workerCount: number, servicePort: number, serviceAddress: string, ): void { cluster.on("listening", (worker, address) => { if ( (address.addressType === 4 || address.addressType === 6) && address.address === serviceAddress && address.port === servicePort ) { logger.info({ message: "Worker listening", pid: worker.process.pid, address: address.address, port: address.port, }); } }); cluster.on("exit", restartWorker); if (!workerCount) workerCount = Math.max(2, cpus().length); for (let i = 0; i < workerCount; ++i) fork(); } export function stop(): void { cluster.removeListener("exit", restartWorker); for (const pid in cluster.workers) cluster.workers[pid].kill(); } export const worker = cluster.worker; ================================================ FILE: lib/common/authorizer.ts ================================================ import { PermissionSet } from "../types.ts"; import Expression from "./expression.ts"; export default class Authorizer { declare private permissionSets: PermissionSet[]; declare private validatorCache: WeakMap< any, (mutationType, mutation, any) => boolean >; declare private hasAccessCache: Map; declare private getFilterCache: Map; public constructor(permissionSets: PermissionSet[]) { this.permissionSets = permissionSets; this.validatorCache = new WeakMap(); this.hasAccessCache = new Map(); this.getFilterCache = new Map(); } public hasAccess(resourceType: string, access: number): boolean { const cacheKey = `${resourceType}-${access}`; if (this.hasAccessCache.has(cacheKey)) return this.hasAccessCache.get(cacheKey); let has = false; for (const permissionSet of this.permissionSets) { for (const perm of permissionSet) { if (perm[resourceType]) { if (perm[resourceType].access >= access) { has = true; break; } } } } this.hasAccessCache.set(cacheKey, has); return has; } public getFilter(resourceType: string, access: number): Expression { const cacheKey = `${resourceType}-${access}`; if (this.getFilterCache.has(cacheKey)) return this.getFilterCache.get(cacheKey); let filter: Expression = new Expression.Literal(false); for (const permissionSet of this.permissionSets) { for (const perm of permissionSet) { if (perm[resourceType]) { if (perm[resourceType].access >= access) filter = Expression.or(filter, perm[resourceType].filter); } } } this.getFilterCache.set(cacheKey, filter); return filter; } public getValidator( resourceType: string, resource: unknown, ): (mutationType: string, mutation?: any, args?: any) => boolean { if (this.validatorCache.has(resource)) return this.validatorCache.get(resource); let validators: Expression = new Expression.Literal(false); for (const permissionSet of this.permissionSets) { for (const perm of permissionSet) { if ( perm[resourceType] && perm[resourceType].access >= 3 && perm[resourceType].validate ) validators = Expression.or(validators, perm[resourceType].validate); } } const validator = ( mutationType: string, mutation: any, any: any, ): boolean => { const object = { mutationType, mutation, resourceType, object: resource, options: any, }; const now = Date.now(); const res = validators.evaluate((exp) => { if (exp instanceof Expression.Literal) return exp; if (exp instanceof Expression.Parameter) { if (exp.path.colon) return new Expression.Literal(null); const entry = exp.path.segments[0] as string; const paramName = exp.path.slice(1); let value = null; if (["mutation", "options"].includes(entry)) { value = object[entry]; for (const seg of paramName.segments) { if (value == null) break; if (typeof value !== "object") value = null; else value = value[seg as string]; } } else if (object[entry]) { if (paramName.length) value = object[entry][paramName.toString()]; else value = object[entry]; } return new Expression.Literal(value); } else if (exp instanceof Expression.FunctionCall) { if (exp.name === "NOW") return new Expression.Literal(now); } return new Expression.Literal(null); }).value; return !!res; }; this.validatorCache.set(resource, validator); return validator; } public getPermissionSets(): PermissionSet[] { return this.permissionSets; } } ================================================ FILE: lib/common/debounce.ts ================================================ export default function debounce( func: (args: T[]) => void, timeout: number, ): (arg: T) => void { let timer: ReturnType; let args: T[] = []; return (arg: T) => { args.push(arg); clearTimeout(timer); timer = setTimeout(() => { const argscopy = args; args = []; func(argscopy); }, timeout); }; } ================================================ FILE: lib/common/errors.ts ================================================ export class ResourceLockedError extends Error { constructor(message: string) { super(message); this.name = "ResourceLockedError"; } } ================================================ FILE: lib/common/expression/evaluate.ts ================================================ import Expression from "../expression.ts"; import { likePatternToRegExp } from "./parser.ts"; function compare( a: boolean | number | string, b: boolean | number | string, ): number { if (typeof a === "boolean") a = +a; if (typeof b === "boolean") b = +b; if (typeof a !== typeof b) return typeof a === "string" ? 1 : -1; return a > b ? 1 : a < b ? -1 : 0; } function toNumber(a: boolean | number | string): number { switch (typeof a) { case "number": return a; case "boolean": return +a; case "string": return parseFloat(a) || 0; } } function toString(a: boolean | number | string): string { switch (typeof a) { case "string": return a; case "number": return a.toString(); case "boolean": return (+a).toString(); } } const regExpCache: WeakMap = new WeakMap(); export function reduce(exp: Expression): Expression { if (exp instanceof Expression.Literal) return exp; if (exp instanceof Expression.Unary) { if (exp.operator === "NOT") { if (exp.operand instanceof Expression.Literal) { if (exp.operand.value == null) return exp.operand; return new Expression.Literal(!exp.operand.value); } else if (exp.operand instanceof Expression.Unary) { if (exp.operand.operator === "NOT") return exp.operand.operand; } } else if (exp.operator === "IS NULL") { if (exp.operand instanceof Expression.Literal) { return new Expression.Literal(exp.operand.value == null); } } else if (exp.operator === "IS NOT NULL") { if (exp.operand instanceof Expression.Literal) { return new Expression.Literal(exp.operand.value != null); } } } else if (exp instanceof Expression.Binary) { if (exp.operator === "AND") { return Expression.and(exp.left, exp.right); } else if (exp.operator === "OR") { return Expression.or(exp.left, exp.right); } else if (["=", ">", "<", "<>", ">=", "<="].includes(exp.operator)) { if (exp.left instanceof Expression.Literal && exp.left.value == null) return exp.left; if (exp.right instanceof Expression.Literal && exp.right.value == null) return exp.right; if ( exp.left instanceof Expression.Literal && exp.right instanceof Expression.Literal ) { const c = compare(exp.left.value, exp.right.value); switch (exp.operator) { case "=": return new Expression.Literal(c === 0); case ">": return new Expression.Literal(c > 0); case "<": return new Expression.Literal(c < 0); case "<>": return new Expression.Literal(c !== 0); case ">=": return new Expression.Literal(c >= 0); case "<=": return new Expression.Literal(c <= 0); } } } else if (["+", "-", "*", "/"].includes(exp.operator)) { if (exp.left instanceof Expression.Literal && exp.left.value == null) return exp.left; if (exp.right instanceof Expression.Literal && exp.right.value == null) return exp.right; if ( exp.left instanceof Expression.Literal && exp.right instanceof Expression.Literal ) { const a = toNumber(exp.left.value); const b = toNumber(exp.right.value); switch (exp.operator) { case "+": return new Expression.Literal(a + b); case "-": return new Expression.Literal(a - b); case "*": return new Expression.Literal(a * b); case "/": return new Expression.Literal(a / b); } } } else if (exp.operator === "%") { if (exp.left instanceof Expression.Literal && exp.left.value == null) return exp.left; if (exp.right instanceof Expression.Literal && exp.right.value == null) return exp.right; if ( exp.left instanceof Expression.Literal && exp.right instanceof Expression.Literal ) { const a = toNumber(exp.left.value); const b = Math.trunc(toNumber(exp.right.value)); if (b === 0) return new Expression.Literal(null); return new Expression.Literal(a % b); } } else if (exp.operator === "||") { if (exp.left instanceof Expression.Literal && exp.left.value == null) return exp.left; if (exp.right instanceof Expression.Literal && exp.right.value == null) return exp.right; if ( exp.left instanceof Expression.Literal && exp.right instanceof Expression.Literal ) { const a = toString(exp.left.value); const b = toString(exp.right.value); return new Expression.Literal(a + b); } } else if (exp.operator === "LIKE") { if (exp.left instanceof Expression.Literal && exp.left.value == null) return exp.left; if (exp.right instanceof Expression.Literal && exp.right.value == null) return exp.right; if ( exp.left instanceof Expression.Literal && exp.right instanceof Expression.Literal ) { const s = toString(exp.left.value); let r = regExpCache.get(exp.right); if (!r) { r = likePatternToRegExp(toString(exp.right.value)); regExpCache.set(exp.right, r); } return new Expression.Literal(r.test(s)); } } else if (exp.operator === "NOT LIKE") { if (exp.left instanceof Expression.Literal && exp.left.value == null) return exp.left; if (exp.right instanceof Expression.Literal && exp.right.value == null) return exp.right; if ( exp.left instanceof Expression.Literal && exp.right instanceof Expression.Literal ) { const s = toString(exp.left.value); let r = regExpCache.get(exp.right); if (!r) { r = likePatternToRegExp(toString(exp.right.value)); regExpCache.set(exp.right, r); } return new Expression.Literal(!r.test(s)); } } } else if (exp instanceof Expression.FunctionCall) { if (exp.name === "COALESCE") { const args = exp.args.filter( (arg) => !(arg instanceof Expression.Literal && arg.value == null), ); if (!args.length) return new Expression.Literal(null); if (args.length === 1) return args[0]; if (args[0] instanceof Expression.Literal) return args[0]; if (args.length !== exp.args.length) return new Expression.FunctionCall("COALESCE", args); } else if (exp.name === "UPPER") { if (exp.args[0] instanceof Expression.Literal) { if (exp.args[0].value == null) return exp.args[0]; const a = toString(exp.args[0].value); return new Expression.Literal(a.toUpperCase()); } } else if (exp.name === "LOWER") { if (exp.args[0] instanceof Expression.Literal) { if (exp.args[0].value == null) return exp.args[0]; const a = toString(exp.args[0].value); return new Expression.Literal(a.toLowerCase()); } } else if (exp.name === "ROUND") { let p = 0; if (exp.args.length > 1) { if (exp.args[1] instanceof Expression.Literal) { if (exp.args[1].value == null) return exp.args[1]; p = Math.trunc(toNumber(exp.args[1].value)); } } if (exp.args[0] instanceof Expression.Literal) { if (exp.args[0].value == null) return exp.args[0]; const n = toNumber(exp.args[0].value); const d = 10 ** p; const m = n * d * (1 + Number.EPSILON); return new Expression.Literal(Math.round(m) / d); } } } else if (exp instanceof Expression.Conditional) { if (exp.condition instanceof Expression.Literal) { if (exp.condition.value) return exp.then; return exp.otherwise; } } return exp; } ================================================ FILE: lib/common/expression/normalize.ts ================================================ import Expression from "../expression.ts"; import { reduce } from "./evaluate.ts"; class Indeterminates { declare public map: Map; declare public sortedKeys: Expression[]; public constructor(exp?: Expression) { this.map = new Map(); if (exp) { this.map.set(exp, 1); this.sortedKeys = [exp]; } else { this.sortedKeys = []; } } public reciprocal(): Indeterminates { const res = new Indeterminates(); res.sortedKeys = this.sortedKeys; res.map = new Map(); for (const [k, v] of this.map) res.map.set(k, 0 - v); return res; } public static multiply( indeterminates1: Indeterminates, indeterminates2: Indeterminates, ): Indeterminates { const res = new Indeterminates(); res.sortedKeys = indeterminates1.sortedKeys.slice(); res.map = new Map(indeterminates1.map); const strMap: Map = new Map(); for (const k of res.map.keys()) strMap.set(k.toString(), k); for (const [key, val] of indeterminates2.map) { const k = strMap.get(key.toString()); if (!k) { res.map.set(key, val); res.sortedKeys.push(key); } else { const v2 = val + res.map.get(k); if (!v2) { res.map.delete(k); res.sortedKeys = res.sortedKeys.filter((s) => s !== k); } else { res.map.set(k, v2); } } } res.sortedKeys.sort((a, b) => { const str1 = a.toString(); const str2 = b.toString(); if (str1.length !== str2.length) return str2.length - str1.length; else if (str1 > str2) return 1; else if (str1 < str2) return -1; return 0; }); return res; } public static compare(a: Indeterminates, b: Indeterminates): number { if (a.sortedKeys.length !== b.sortedKeys.length) return b.sortedKeys.length - a.sortedKeys.length; for (let i = 0; i < a.sortedKeys.length; ++i) { const k1 = a.sortedKeys[i]; const w1 = a.map.get(k1); const k2 = b.sortedKeys[i]; const w2 = b.map.get(k2); if (w1 !== w2) return w2 - w1; if (k1.toString().length > k2.toString().length) return -1; else if (k1.toString().length < k2.toString().length) return 1; else if (k1.toString() > k2.toString()) return 1; else if (k1.toString() < k2.toString()) return -1; } return 0; } } interface Term { indeterminates: Indeterminates; coefficientNumerator: bigint; coefficientDenominator: bigint; } function findGcd(a: bigint, b: bigint): bigint { while (b !== 0n) { const t = b; b = a % b; a = t; } return a; } class Polynomial extends Expression { declare public terms: Term[]; public constructor(terms: Term[]) { super(); this.terms = terms; } map(): Polynomial { return this; } async mapAsync(): Promise { return this; } public static simplifyTerms(terms: Term[]): Term[] { const ts = terms .slice() .sort((a: Term, b: Term) => Indeterminates.compare(a.indeterminates, b.indeterminates), ); for (let i = 1; i < ts.length; ++i) { const t1 = ts[i - 1]; const t2 = ts[i]; if (Indeterminates.compare(t1.indeterminates, t2.indeterminates) === 0) { const numerator = t1.coefficientNumerator * t2.coefficientDenominator + t2.coefficientNumerator * t1.coefficientDenominator; const denominator = t1.coefficientDenominator * t2.coefficientDenominator; const gcd = findGcd(numerator, denominator); ts[i] = { indeterminates: t2.indeterminates, coefficientNumerator: numerator / gcd, coefficientDenominator: denominator / gcd, }; ts[i - 1] = { indeterminates: t1.indeterminates, coefficientNumerator: 0n, coefficientDenominator: t1.coefficientDenominator, }; } } return ts.filter((v) => v.coefficientNumerator !== 0n); } public static fromIndeterminate(indeterminate: Expression): Polynomial { const indeterminates = new Indeterminates(indeterminate); const terms = [ { indeterminates: indeterminates, coefficientNumerator: 1n, coefficientDenominator: 1n, }, ]; return new Polynomial(terms); } public static fromConstant(constant: number): Polynomial { const [int, frac] = Math.abs(constant).toString(2).split(".", 2); let numerator = BigInt("0b" + int); if (constant < 0) numerator = numerator / -1n; let denominator = 1n; if (frac) { denominator = 2n ** BigInt(frac.length); numerator = numerator * denominator + BigInt("0b" + frac); } const terms = [ { indeterminates: new Indeterminates(), coefficientNumerator: numerator, coefficientDenominator: denominator, }, ]; return new Polynomial(terms); } public negation(): Polynomial { const terms = this.terms.map((t) => ({ indeterminates: t.indeterminates, coefficientNumerator: t.coefficientNumerator * -1n, coefficientDenominator: t.coefficientDenominator, })); return new Polynomial(terms); } public reciprocal(): Polynomial { const terms = this.terms.map((t) => ({ indeterminates: t.indeterminates.reciprocal(), coefficientNumerator: t.coefficientDenominator, coefficientDenominator: t.coefficientNumerator, })); return new Polynomial(terms); } public constant(): Polynomial { const terms = this.terms.filter((t) => !t.indeterminates.sortedKeys.length); return new Polynomial(terms); } public add(rhs: Polynomial): Polynomial { return new Polynomial( Polynomial.simplifyTerms(this.terms.concat(rhs.terms)), ); } public subtract(rhs: Polynomial): Polynomial { return this.add(rhs.negation()); } public multiply(rhs: Polynomial): Polynomial { const terms: Term[] = []; for (const t1 of this.terms) { for (const t2 of rhs.terms) { const numerator = t1.coefficientNumerator * t2.coefficientNumerator; const denominator = t1.coefficientDenominator * t2.coefficientDenominator; const gcd = findGcd(numerator, denominator); terms.push({ indeterminates: Indeterminates.multiply( t1.indeterminates, t2.indeterminates, ), coefficientNumerator: numerator / gcd, coefficientDenominator: denominator / gcd, }); } } return new Polynomial(Polynomial.simplifyTerms(terms)); } public divide(rhs: Polynomial): Polynomial { return this.multiply(rhs.reciprocal()); } public toExpression(): Expression { const add: Expression[] = []; for (const t of this.terms) { const coefficient = Number(t.coefficientNumerator) / Number(t.coefficientDenominator); const mul: Expression[] = []; if (t.indeterminates.sortedKeys.length) { for (const k of t.indeterminates.sortedKeys) { const w = t.indeterminates.map.get(k); for (let i = Math.abs(w); i > 0; --i) { if (w > 0) mul.push(k); else mul.push( new Expression.Binary("/", new Expression.Literal(1), k), ); } } if (coefficient !== 1) mul.push(new Expression.Literal(coefficient)); while (mul.length > 1) { const r = mul.pop(); const l = mul.pop(); mul.push(new Expression.Binary("*", l, r)); } add.push(mul[0]); } else { add.push(new Expression.Literal(coefficient)); } } while (add.length > 1) { const r = add.pop(); const l = add.pop(); add.push(new Expression.Binary("+", l, r)); } if (!add.length) return new Expression.Literal(0); return add[0]; } } const SWAPPED_OPS = { "=": "=", "<>": "<>", ">": "<", ">=": "<=", "<": ">", "<=": ">=", }; function cartesianProduct(arrays: T[][]): T[][] { return arrays.reduce( (acc, cur) => acc.flatMap((a) => cur.map((item) => [...a, item])), [[]], ); } function toPolynomial(e: Expression): Polynomial { if (e instanceof Polynomial) return e; if (e instanceof Expression.Literal) { if (e.value == null) return null; if (typeof e.value === "number") return Polynomial.fromConstant(e.value); if (typeof e.value === "string") return Polynomial.fromConstant(parseFloat(e.value) || 0); if (typeof e.value === "boolean") return Polynomial.fromConstant(+e.value); } return Polynomial.fromIndeterminate(e); } function fromPolynomial(e: Expression): Expression { if (e instanceof Polynomial) return e.toExpression(); if (e instanceof Expression.Conditional) return e.map(fromPolynomial); return e; } function normalizeCallback(exp: Expression): Expression { if (exp instanceof Expression.FunctionCall) { if (exp.name === "COALESCE") { let e: Expression = new Expression.Literal(null); for (let i = exp.args.length - 1; i >= 0; --i) { e = new Expression.Conditional( normalizeCallback(new Expression.Unary("IS NOT NULL", exp.args[i])), exp.args[i], e, ); } return normalizeCallback(e); } } if (exp instanceof Expression.Conditional) { let e = exp; if (e.condition instanceof Polynomial) e = new Expression.Conditional( e.condition.toExpression(), e.then, e.otherwise, ); if (e.then instanceof Expression.Conditional) { e = new Expression.Conditional( Expression.and(e.condition, e.then.condition), e.then.then, new Expression.Conditional(e.condition, e.then.otherwise, e.otherwise), ); } return e; } const combs: [Expression, Expression][][] = []; const callback: (e: Expression) => Expression = (e) => { if (e instanceof Expression.Conditional) { combs[combs.length - 1].push([e.condition, e.then]); callback(e.otherwise); } else { combs[combs.length - 1].push([new Expression.Literal(true), e]); } return e; }; exp.map((e) => { combs.push([]); callback(e); return e; }); if (combs.some((a) => a.length > 1)) { let res: Expression = new Expression.Literal(null); for (const p of cartesianProduct(combs).reverse()) { let condition: Expression = new Expression.Literal(true); const e = reduce( normalizeCallback( exp.map((_, i) => { condition = Expression.and(condition, p[i][0]); return p[i][1]; }), ), ); if (!(condition instanceof Expression.Literal)) res = new Expression.Conditional(condition, e, res); else if (condition.value) res = e; } return res; } if (exp instanceof Expression.Binary) { if (["+", "-", "*", "/"].includes(exp.operator)) { const lhs = toPolynomial(exp.left); const rhs = toPolynomial(exp.right); if (lhs == null || rhs == null) return new Expression.Literal(null); if (exp.operator === "+") return lhs.add(rhs); if (exp.operator === "-") return lhs.subtract(rhs); if (exp.operator === "*") return lhs.multiply(rhs); if (exp.operator === "/") return lhs.divide(rhs); } else if ([">", ">=", "<", "<=", "=", "<>"].includes(exp.operator)) { let lhs: Polynomial, rhs: Polynomial; if (exp.left instanceof Polynomial) lhs = exp.left; else if (exp.left instanceof Expression.Literal) { if (exp.left.value == null) return exp.left; else if (typeof exp.left.value === "number") lhs = Polynomial.fromConstant(exp.left.value); } if (exp.right instanceof Polynomial) rhs = exp.right; else if (exp.right instanceof Expression.Literal) { if (exp.right.value == null) return exp.right; else if (typeof exp.right.value === "number") rhs = Polynomial.fromConstant(exp.right.value); } if (lhs || rhs) { if (!lhs) lhs = Polynomial.fromIndeterminate(exp.left); if (!rhs) rhs = Polynomial.fromIndeterminate(exp.right); lhs = lhs.subtract(rhs); rhs = lhs.constant().negation(); lhs = lhs.add(rhs); if (!lhs.terms.length) { const l = lhs.toExpression() as Expression.Literal; const r = rhs.toExpression() as Expression.Literal; if (exp.operator === "=") return new Expression.Literal(l.value === r.value); else if (exp.operator === "<>") return new Expression.Literal(l.value !== r.value); else if (exp.operator === ">") return new Expression.Literal(l.value > r.value); else if (exp.operator === ">=") return new Expression.Literal(l.value >= r.value); else if (exp.operator === "<") return new Expression.Literal(l.value < r.value); else if (exp.operator === "<=") return new Expression.Literal(l.value <= r.value); else throw new Error("Invalid operator"); } let flipOp = 1; const n = lhs.terms[0].coefficientNumerator; const d = lhs.terms[0].coefficientDenominator; if (n < 0n || d < 0n) flipOp *= -1; const reciprocal = new Polynomial([ { indeterminates: new Indeterminates(), coefficientNumerator: d, coefficientDenominator: n, }, ]); lhs = lhs.multiply(reciprocal); rhs = rhs.multiply(reciprocal); const keys = lhs.terms[0].indeterminates.sortedKeys; let invert = lhs.terms[0].indeterminates.map.get(keys[0]) < 0 ? -1 : 0; for (const t of lhs.terms) for (const v of t.indeterminates.map.values()) invert += v; if (invert < 0) { flipOp *= -1; lhs = lhs.reciprocal(); rhs = rhs.reciprocal(); } if (flipOp > 0) exp = new Expression.Binary(exp.operator, lhs, rhs); else exp = new Expression.Binary(SWAPPED_OPS[exp.operator], lhs, rhs); } } } // Restore polynomial expressions exp = exp.map(fromPolynomial); return exp; } export default function normalize(exp: Expression): Expression { return fromPolynomial(exp.evaluate(normalizeCallback)); } ================================================ FILE: lib/common/expression/pagination.ts ================================================ import { complement } from "espresso-iisojs"; import Expression from "../expression.ts"; import normalize from "./normalize.ts"; import { Clause, SynthContext } from "./synth.ts"; import Path from "../path.ts"; type Bookmark = Record; type Minterm = number[]; export function toBookmark( sort: Record, row: unknown, ): Bookmark { const bookmark: Bookmark = {}; for (const param of Object.keys(sort)) { let v = row[param]; if (v != null && typeof v === "object") v = v.value?.[0]; bookmark[param] = v; } return bookmark; } export function bookmarkToExpression( bookmark: Bookmark, sort: Record, ): Expression { return Object.entries(sort) .reverse() .reduce( (cur, kv) => { const [param, asc] = kv; const p = new Expression.Parameter(Path.parse(param)); const b = new Expression.Literal(bookmark[param]); if (asc < 0) { if (bookmark[param] == null) { return Expression.or( new Expression.Unary("IS NOT NULL", p), Expression.and(new Expression.Unary("IS NULL", p), cur), ); } return new Expression.Binary( "OR", new Expression.Binary(">", p, b), new Expression.Binary("AND", new Expression.Binary("=", p, b), cur), ); } else { let f: Expression = new Expression.Unary("IS NULL", p); if (bookmark[param] == null) return Expression.and(f, cur); f = Expression.or(f, new Expression.Binary("<", p, b)); return Expression.or( f, Expression.and(new Expression.Binary("=", p, b), cur), ); } }, new Expression.Literal(true) as Expression, ); } function getCover( context: SynthContext, minterm: Minterm, allSort: [string, number][], ): Minterm[] { if (!allSort.length) return [[]]; const [param, sort] = allSort[0]; const cov: Minterm = []; const nextCov: Minterm = []; if (sort > 0) { const lhs = new Clause.Exp(new Expression.Parameter(Path.parse(param))); const isNull = context.getVar(new Clause.IsNull(lhs)); cov.push((isNull << 2) ^ 2); } for (const m of minterm) { const clause = context.getClause(m >>> 2); if (clause instanceof Clause.IsNull) { if (!(clause.operand instanceof Clause.Exp)) continue; if (!(clause.operand.exp instanceof Expression.Parameter)) continue; if (clause.operand.exp.path.toString() !== param) continue; nextCov.push(m); if (sort < 0 && m & 1) cov.push(m, m ^ 1); } else if (clause instanceof Clause.Compare) { if (!(clause.lhs instanceof Clause.Exp)) continue; if (!(clause.lhs.exp instanceof Expression.Parameter)) continue; if (clause.lhs.exp.path.toString() !== param) continue; if (!(m & 1) && sort > 0) continue; nextCov.push(m); const negate = (m ^ (m >> 1)) & 1; if (sort > 0) { if ( (clause.op === "=" && !negate) || (clause.op === ">" && !negate) || (clause.op === "<" && negate) ) { const c = new Clause.Compare(clause.lhs, ">", clause.rhs); const v = context.getVar(c); cov.push((v << 2) ^ 3); } } else if (sort < 0) { if ( (clause.op === "=" && !negate) || (clause.op === ">" && negate) || (clause.op === "<" && !negate) ) { const c = new Clause.Compare(clause.lhs, "<", clause.rhs); const v = context.getVar(c); cov.push((v << 2) ^ 0); } } } } const next = getCover(context, minterm, allSort.slice(1)); return [cov, ...next.map((n) => [...nextCov, ...n])]; } export function paginate( fetched: Expression, toFetch: Expression, sort: Record, ): [Expression, Expression] { fetched = normalize(fetched); if (fetched instanceof Expression.Literal && !fetched.value) return [new Expression.Literal(false), toFetch]; toFetch = normalize(toFetch); if (toFetch instanceof Expression.Literal && !toFetch.value) return [new Expression.Literal(false), toFetch]; const synth1 = Clause.fromExpression(fetched); const synth2 = Clause.fromExpression(toFetch); const context = new SynthContext(); const expr1Minterms = synth1.getMinterms(context, 0b100); const expr2MintermsC = synth2.getMinterms(context, 0b011); const gaps = context.sanitizeMinterms( complement([ ...expr1Minterms, ...expr2MintermsC, ...context.getDcSet([...expr1Minterms, ...expr2MintermsC]), ]), ); const cover = gaps.flatMap((m) => getCover(context, m, Object.entries(sort))); const minterms1 = context.minimize(complement([...cover, ...expr2MintermsC])); const minterms2 = context.minimize( complement([...minterms1, ...expr2MintermsC]), ); return [context.toExpression(minterms1), context.toExpression(minterms2)]; } ================================================ FILE: lib/common/expression/parser.ts ================================================ import Path from "../path.ts"; import Expression from "../expression.ts"; export class Cursor { input: string; pos: number; boundryStack: number[][]; boundry: number[]; charCode: number; constructor(input: string) { this.input = input; this.pos = 0; this.boundryStack = []; this.boundry = []; this.charCode = input.charCodeAt(0) || 0; } fork(): Cursor { const cursor = new Cursor(this.input); cursor.pos = this.pos; cursor.boundryStack = this.boundryStack.slice(); cursor.boundry = this.boundry; cursor.charCode = this.charCode; return cursor; } sync(cursor: Cursor): void { this.pos = cursor.pos; this.boundryStack = cursor.boundryStack.slice(); this.boundry = cursor.boundry; this.charCode = cursor.charCode; } read(cur: Cursor): string { return this.input.slice(this.pos, cur.pos); } step(): Cursor { if (this.charCode === 0) return this; ++this.pos; this.charCode = this.input.charCodeAt(this.pos) || 0; if (this.boundry.includes(this.charCode)) this.charCode = 0; return this; } walk(callback: (charCode: number) => boolean): Cursor { while (this.charCode && callback(this.charCode)) this.step(); return this; } descend(chars: number[], override = true): void { this.boundryStack.push(this.boundry); if (override) this.boundry = chars; else this.boundry = [...this.boundry, ...chars]; this.charCode = this.input.charCodeAt(this.pos) || 0; if (this.boundry.includes(this.charCode)) this.charCode = 0; } ascend(): void { if (!this.boundryStack.length) throw new Error("Unmatched boundry"); this.boundry = this.boundryStack.pop(); this.charCode = this.input.charCodeAt(this.pos) || 0; } skipwhitespace(): Cursor { return this.walk((c) => c <= 32); } } const CHAR_SINGLE_QUOTE = 39; const CHAR_DOUBLE_QUOTE = 34; const CHAR_OPEN_PAREN = 40; const CHAR_CLOSE_PAREN = 41; const CHAR_COMMA = 44; const CHAR_PERIOD = 46; const CHAR_COLON = 58; const CHAR_OPEN_BRACKET = 91; const CHAR_BACKSLASH = 92; const CHAR_CLOSE_BRACKET = 93; const BINARY_OPERATORS = [ ">=", "<=", "<>", "=", ">", "<", "LIKE", "NOT LIKE", "AND", "OR", "*", "/", "%", "||", "-", "+", ]; const PRECEDENCE = { OR: 10, AND: 11, NOT: 12, "=": 20, "<>": 20, ">": 20, ">=": 20, "<": 20, "<=": 20, LIKE: 20, "NOT LIKE": 20, "IS NULL": 20, "IS NOT NULL": 20, "||": 30, "+": 31, "-": 31, "*": 32, "/": 32, "%": 32, }; function* range(s: number, e: number): Generator { for (let i = s; i < e; i++) yield i; } const PATH_CHARS = new Set([ ...range(65, 91), ...range(97, 123), ...range(48, 58), 95, 45, 42, 123, 125, ]); function findOperator(cursor: Cursor): string { cursor.skipwhitespace(); let found = ""; let foundCursor = cursor; let operators = [...BINARY_OPERATORS, "IS NULL", "IS NOT NULL"]; for (let i = 0; operators.length && cursor.charCode; ++i) { let c = cursor.charCode; cursor.step(); if (c >= 97 && c <= 122) c -= 32; if (c <= 32) { cursor.skipwhitespace(); c = 32; } operators = operators.filter((o) => { if (o.charCodeAt(i) !== c) return false; if (o.length === i + 1) { found = o; foundCursor = cursor.fork(); } return true; }); } if (found) cursor.sync(foundCursor); return found; } // Turn escaped characters into real ones (e.g. "\\n" becomes "\n"). function interpretEscapes(str): string { const escapes = { b: "\b", f: "\f", n: "\n", r: "\r", t: "\t", }; return str.replace(/\\(u[0-9a-fA-F]{4}|[^u])/g, (_, escape) => { const type = escape.charAt(0); const hex = escape.slice(1); if (type === "u") return String.fromCharCode(parseInt(hex, 16)); if (escapes.hasOwnProperty(type)) return escapes[type]; return type; }); } export function parseExpression(cursor: Cursor, presedence = 0): Expression { cursor.skipwhitespace(); const char = cursor.charCode; let lhs: Expression; if (char === CHAR_OPEN_PAREN) { cursor.step(); cursor.descend([CHAR_CLOSE_PAREN]); lhs = parseExpression(cursor, 0); cursor.ascend(); cursor.skipwhitespace(); if (cursor.charCode !== CHAR_CLOSE_PAREN) throw new Error("Expected ')'" + cursor.pos + " " + cursor.charCode); cursor.step(); } else if (char === CHAR_DOUBLE_QUOTE) { cursor.step(); const cursor2 = cursor.fork(); for ( cursor2.descend([]); cursor2.charCode !== CHAR_DOUBLE_QUOTE; cursor2.step() ) { if (!cursor2.charCode) throw new Error("Unterminated string"); if (cursor2.charCode === CHAR_BACKSLASH) cursor2.step(); } cursor2.ascend(); const str = cursor.read(cursor2); cursor.sync(cursor2); cursor.step(); return new Expression.Literal(interpretEscapes(str)); } else if (char === CHAR_SINGLE_QUOTE) { cursor.step(); const cursor2 = cursor.fork(); for ( cursor2.descend([]); cursor2.charCode !== CHAR_SINGLE_QUOTE; cursor2.step() ) { if (!cursor2.charCode) throw new Error("Unterminated string"); if (cursor2.charCode === CHAR_BACKSLASH) cursor2.step(); } cursor2.ascend(); const str = cursor.read(cursor2); cursor.sync(cursor2); cursor.step(); return new Expression.Literal(str.replaceAll("''", "'")); } else { const cursor2 = cursor.fork(); cursor.walk( (c) => c > 32 && c !== CHAR_OPEN_PAREN && c !== CHAR_OPEN_BRACKET, ); const token = cursor2.read(cursor); if (!token) throw new Error("Invalid expression"); if (/^true$/i.test(token)) lhs = new Expression.Literal(true); else if (/^false$/i.test(token)) lhs = new Expression.Literal(false); else if (/^null$/i.test(token)) lhs = new Expression.Literal(null); else if (/^-?(0|[1-9][0-9]*)([.][0-9]+)?([eE][+-]?[0-9]+)?$/.test(token)) lhs = new Expression.Literal(Number(token)); else if (/^not$/i.test(token)) { lhs = new Expression.Unary( "NOT", parseExpression(cursor, PRECEDENCE["NOT"]), ); } else if (/^case$/i.test(token)) { const pairs: [Expression, Expression][] = []; for (;;) { cursor.skipwhitespace(); const whenStr = cursor.fork().read(cursor.walk((c) => c > 32)); if (/^else$/i.test(whenStr)) { lhs = parseExpression(cursor); continue; } if (/^end$/i.test(whenStr)) break; else if (lhs) throw new Error("Expected END"); if (!/^when$/i.test(whenStr)) throw new Error("Expected WHEN"); const condition = parseExpression(cursor); cursor.skipwhitespace(); const thenStr = cursor.fork().read(cursor.walk((c) => c > 32)); if (!/^then$/i.test(thenStr)) throw new Error("Expected THEN"); const then = parseExpression(cursor); pairs.push([condition, then]); } if (!lhs) lhs = new Expression.Literal(null); while (pairs.length) { const [condition, then] = pairs.pop(); lhs = new Expression.Conditional(condition, then, lhs); } } else if (cursor.charCode === CHAR_OPEN_PAREN) { cursor.step(); cursor.descend([CHAR_CLOSE_PAREN]); cursor.skipwhitespace(); const args = [] as Expression[]; while (cursor.charCode) { cursor.descend([CHAR_COMMA], false); const e = parseExpression(cursor); args.push(e); cursor.ascend(); cursor.skipwhitespace(); if ((cursor.charCode as number) !== CHAR_COMMA) break; cursor.step(); } cursor.ascend(); cursor.step(); lhs = new Expression.FunctionCall(token, args); } else { const p = parsePath(cursor2); lhs = new Expression.Parameter(p); cursor.sync(cursor2); } } for (;;) { cursor.skipwhitespace(); const cursor2 = cursor.fork(); const op = findOperator(cursor2); const p = PRECEDENCE[op]; if (p <= presedence) return lhs; if (op === "IS NULL") { lhs = new Expression.Unary("IS NULL", lhs); } else if (op === "IS NOT NULL") { lhs = new Expression.Unary("IS NOT NULL", lhs); } else if (BINARY_OPERATORS.includes(op)) { lhs = new Expression.Binary(op, lhs, parseExpression(cursor2, p)); } else if (op) throw new Error("Unrecognized operator: " + op); else break; cursor.sync(cursor2); } return lhs; } // Parse old-format alias value: unquoted, double-quoted, or single-quoted. // Returns the parsed string value. Cursor is advanced past the value. function parseOldAliasValue(cursor: Cursor): string { cursor.walk((c) => c <= 32); // skip leading whitespace const c = cursor.charCode; if (c === CHAR_DOUBLE_QUOTE) { // Double-quoted: use JSON.parse semantics (handles \", \n, \uXXXX etc.) // Descend with no boundaries so commas/brackets inside quotes are not // treated as terminators. const start = cursor.pos; cursor.step(); cursor.descend([]); while (cursor.charCode) { if (cursor.charCode === CHAR_BACKSLASH) { cursor.step(); if (!cursor.charCode) break; } else if (cursor.charCode === CHAR_DOUBLE_QUOTE) { cursor.ascend(); cursor.step(); return JSON.parse(cursor.input.slice(start, cursor.pos)) as string; } cursor.step(); } throw new Error("Unterminated string"); } if (c === CHAR_SINGLE_QUOTE) { // Single-quoted: strip quotes, no escape processing cursor.step(); cursor.descend([]); const start = cursor.pos; while (cursor.charCode && cursor.charCode !== CHAR_SINGLE_QUOTE) cursor.step(); if (!cursor.charCode) throw new Error("Unterminated string"); const value = cursor.input.slice(start, cursor.pos); cursor.ascend(); cursor.step(); return value; } // Unquoted: read until , or ] (respecting boundary), trim result const start = cursor.pos; cursor.walk(() => true); return cursor.input.slice(start, cursor.pos).trim(); } // Parse old-format alias content: key:value,key:value,... // Cursor should be positioned at the start of bracket content // (after '[', with ']' set as boundary). // Returns an Expression: Binary("AND", ...) chain of Binary("=", param, literal). // Empty content returns Literal(true). function parseOldAlias(cursor: Cursor): Expression { cursor.skipwhitespace(); if (!cursor.charCode) return new Expression.Literal(true); let result: Expression | null = null; for (;;) { cursor.skipwhitespace(); // Parse key as a path (supports nested aliases via parsePath). // Add colon and comma as boundaries so the path stops there. cursor.descend([CHAR_COLON, CHAR_COMMA], false); const keyPath = parsePath(cursor); cursor.ascend(); // After ascend, check for the colon separator cursor.skipwhitespace(); if ((cursor.charCode as number) !== CHAR_COLON) throw new Error("Expected ':'"); cursor.step(); // Parse value (reads until boundary , or ]) cursor.descend([CHAR_COMMA], false); const value = parseOldAliasValue(cursor); cursor.ascend(); const pair = new Expression.Binary( "=", new Expression.Parameter(keyPath), new Expression.Literal(value), ); result = result ? new Expression.Binary("AND", result, pair) : pair; cursor.skipwhitespace(); if ((cursor.charCode as number) !== CHAR_COMMA) break; cursor.step(); } return result; } export function parsePath(cur: Cursor): Path { const segments: (string | Expression)[] = []; let colon = 0; const cur2 = cur.fork(); for (;;) { let char = cur2.charCode; let exp: Expression; if (char === CHAR_OPEN_BRACKET) { if (cur2.pos !== cur.pos) throw new Error("Invalid path"); cur2.step(); cur2.descend([CHAR_CLOSE_BRACKET]); // Try parsing as expression first const cur3 = cur2.fork(); let err: unknown; try { exp = parseExpression(cur3); } catch (e) { err = e; } // Fall back to old alias format if not a valid expression or produced // a bare Parameter (old format like [a:1] mis-parsed as a path). if (err || exp instanceof Expression.Parameter) { exp = parseOldAlias(cur2); } else { cur2.sync(cur3); } cur2.ascend(); char = cur2.charCode; if (char !== CHAR_CLOSE_BRACKET) throw new Error("Expected ']'"); char = cur2.step().charCode; } if (!PATH_CHARS.has(char)) { if (cur2.pos <= cur.pos) throw new Error("Invalid path"); if (char === CHAR_COLON) { if (colon) throw new Error("Multiple colons"); colon = segments.length + 1; } if (exp) segments.push(exp); else segments.push(cur.read(cur2)); if (char !== CHAR_PERIOD && char !== CHAR_COLON) break; cur2.step(); cur.sync(cur2); continue; } if (exp) throw new Error("Invalid path"); cur2.step(); } cur.sync(cur2); if (colon) colon = segments.length - colon; return new Path(segments, colon); } export function stringifyExpression(exp: Expression, level = 0): string { function wrap(e: string, op: string): string { if (PRECEDENCE[op] <= level) return `(${e})`; else return e; } if (exp instanceof Expression.Literal) { if (exp.value == null) return "NULL"; if (exp.value === true) return "TRUE"; if (exp.value === false) return "FALSE"; return JSON.stringify(exp.value); } else if (exp instanceof Expression.Unary) { if (exp.operator === "NOT") { return wrap( `NOT ${stringifyExpression(exp.operand, PRECEDENCE[exp.operator])}`, "NOT", ); } else if (exp.operator === "IS NULL" || exp.operator === "IS NOT NULL") { return wrap( `${stringifyExpression(exp.operand, PRECEDENCE[exp.operator])} ${exp.operator}`, exp.operator, ); } } else if (exp instanceof Expression.Binary) { const op = exp.operator; if (!(op in PRECEDENCE)) throw new Error("Invalid operator"); return wrap( `${stringifyExpression(exp.left, PRECEDENCE[op] - 1)} ${exp.operator} ${stringifyExpression(exp.right, PRECEDENCE[op])}`, op, ); } else if (exp instanceof Expression.Parameter) { return exp.path.toString(); } else if (exp instanceof Expression.FunctionCall) { return `${exp.name}(${exp.args.map((a) => stringifyExpression(a)).join(", ")})`; } else if (exp instanceof Expression.Conditional) { let str = `CASE WHEN ${stringifyExpression(exp.condition)} THEN ${stringifyExpression(exp.then)}`; if ( exp.otherwise instanceof Expression.Literal && exp.otherwise.value == null ) str += " END"; else if (exp.otherwise instanceof Expression.Conditional) str += stringifyExpression(exp.otherwise).slice(4); else str += ` ELSE ${stringifyExpression(exp.otherwise)} END`; return str; } throw new Error("Invalid expression"); } export function parseLikePattern(pat: string, esc: string): string[] { const chars = pat.split(""); for (let i = 0; i < chars.length; ++i) { const c = chars[i]; if (c === esc) { chars[i] = chars[i + 1] || ""; chars[i + 1] = ""; } else if (c === "_") { chars[i] = "\\_"; } else if (c === "%") { chars[i] = "\\%"; while (chars[i + 1] === "%") chars[++i] = ""; } } return chars.filter((c) => c); } export function likePatternToRegExp(pat: string, esc = "", flags = ""): RegExp { const convChars = { "-": "\\-", "/": "\\/", "\\": "\\/", "^": "\\^", $: "\\$", "*": "\\*", "+": "\\+", "?": "\\?", ".": "\\.", "(": "\\(", ")": "\\)", "|": "\\|", "[": "\\[", "]": "\\]", "{": "\\{", "}": "\\}", "\\%": ".*", "\\_": ".", }; let chars = parseLikePattern(pat, esc); if (!chars.length) return new RegExp("^$", flags); chars = chars.map((c) => convChars[c] || c); chars[0] = chars[0] === ".*" ? "" : "^" + chars[0]; const l = chars.length - 1; chars[l] = [".*", ""].includes(chars[l]) ? "" : chars[l] + "$"; return new RegExp(chars.join(""), flags); } ================================================ FILE: lib/common/expression/synth.ts ================================================ import { espresso, complement, tautology } from "espresso-iisojs"; import Expression from "../expression.ts"; import { parseLikePattern } from "./parser.ts"; import normalize from "./normalize.ts"; type Minterm = number[]; export abstract class SynthContextBase< T extends { toString: () => string } = unknown, U = unknown, > { public variables = new Map(); protected clauses = new Map(); public getVar(c: U): number { const str = c.toString(); let idx = this.variables.get(str); if (idx == null) { idx = this.variables.size; this.variables.set(str, idx); this.clauses.set(idx, c); } return idx; } public getClause(v: number): U { return this.clauses.get(v); } abstract getMinterms(exp: T, res: number): Minterm[]; abstract getDcSet(minterms: Minterm[]): Minterm[]; // eslint-disable-next-line @typescript-eslint/no-unused-vars canRaise(idx: number, set: Set): boolean { return true; } // eslint-disable-next-line @typescript-eslint/no-unused-vars canLower(idx: number, set: Set): boolean { return true; } bias(a: number, b: number): number { // Bias towards 1 then lower index return (b ^ 1) - (a ^ 1); } sanitizeMinterms(minterms: Minterm[]): Minterm[] { return minterms; } minimize(minterms: Minterm[], dcSet: Minterm[] = []): Minterm[] { minterms = this.sanitizeMinterms(minterms); const canRaise = this.canRaise.bind(this); const canLower = this.canLower.bind(this); const bias = this.bias.bind(this); return espresso( minterms, [...this.getDcSet([...minterms, ...dcSet]), ...dcSet], { canRaise, canLower, bias, }, ); } } function* findIsNullDeps(exp: Expression): IterableIterator { if (exp instanceof Expression.Literal) return; else if (exp instanceof Expression.Unary) { if (exp.operator === "IS NULL" || exp.operator === "IS NOT NULL") return; yield* findIsNullDeps(exp.operand); } else if (exp instanceof Expression.Binary) { yield* findIsNullDeps(exp.left); yield* findIsNullDeps(exp.right); } else if (exp instanceof Expression.FunctionCall) { if (exp.name === "NOW") return; else if (exp.name === "LOWER" || exp.name === "UPPER") yield* findIsNullDeps(exp.args[0]); else if (exp.name === "ROUND") { for (const e of exp.args.slice(0, 2)) yield* findIsNullDeps(e); } } else yield exp; } export abstract class Clause { private _isNullable: Set; protected _expression: Expression; abstract getMinterms( context: SynthContextBase, res: number, ): Minterm[]; expression(): Expression { if (this._expression !== undefined) return this._expression; const context = createSynthContext(); const minterms = this.getMinterms(context, 0b100); const minimized = context.minimize(minterms); this._expression = context.toExpression(minimized) as Expression; return this._expression; } isBoolean(): boolean { return true; } isNullable(c: Clause.IsNull): boolean { if (!this._isNullable) { this._isNullable = new Set( [...this.getNullables()].map((n) => n.toString()), ); } return this._isNullable.has(c.toString()); } *getNullables(): IterableIterator { const exp = this.expression(); for (const e of findIsNullDeps(exp)) { if (e === exp) yield new Clause.IsNull(this); else yield new Clause.IsNull(new Clause.Exp(e)); } } toString(): string { return this.expression().toString(); } } // eslint-disable-next-line @typescript-eslint/no-namespace export namespace Clause { export class Not extends Clause { constructor(public operand: Clause) { super(); } getMinterms(context: SynthContextBase, res: number): Minterm[] { let r = res & 0b001; if (res & 0b010) r |= 0b100; if (res & 0b100) r |= 0b010; return this.operand.getMinterms(context, r); } } export class And extends Clause { constructor(public operands: Clause[]) { super(); } getMinterms(context: SynthContextBase, res: number): Minterm[] { res = res & 0b111; if (!res) return []; if (res === 0b111) return [[]]; if (res === 0b110) return [ ...this.getMinterms(context, 0b010), ...this.getMinterms(context, 0b100), ]; if (!(res & 0b010)) return complement(this.getMinterms(context, ~res)); const minterms: Minterm[] = []; for (const o of this.operands) { const m = o.getMinterms(context, res); if (m.length === 1 && !m[0].length) return [[]]; minterms.push(...m); } return minterms; } } export class IsNull extends Clause { constructor(public operand: Clause) { super(); } getMinterms(context: SynthContextBase, res: number): Minterm[] { res = res & 0b111; const minterms: Minterm[] = []; if ((res & 0b110) === 0b110) return [[]]; if (res & 0b100) minterms.push(...this.operand.getMinterms(context, 0b001)); if (res & 0b010) minterms.push(...this.operand.getMinterms(context, 0b110)); return minterms; } isBoolean(): boolean { return true; } *getNullables(): IterableIterator { // Never returns null } expression(): Expression { const nullables = [...this.operand.getNullables()]; if (nullables.length === 1 && nullables[0].operand === this.operand) return new Expression.Unary("IS NULL", this.operand.expression()); return super.expression(); } } export class Exp extends Clause { constructor(public exp: Expression) { super(); } getMinterms(context: SynthContextBase, res: number): Minterm[] { if (!(this.exp instanceof Expression.Literal)) return context.getMinterms(this, res); if (this.exp.value == null) return res & 0b001 ? [[]] : []; if (this.exp.value && res & 0b100) return [[]]; if (!this.exp.value && res & 0b010) return [[]]; return []; } expression(): Expression { return this.exp; } isBoolean(): boolean { if (this.exp instanceof Expression.Literal) { return ( this.exp.value === true || this.exp.value === false || this.exp.value == null ); } return false; } } export class Compare extends Clause { constructor( public lhs: Clause, public op: ">" | "<" | "=", public rhs: boolean | number | string, ) { super(); } getMinterms(context: SynthContextBase, res: number): Minterm[] { res = res & 0b111; if (!res) return []; if (res === 0b111) return [[]]; if (res === 0b001 || res === 0b110) return this.lhs.getMinterms(context, res); return context.getMinterms(this, res); } *getNullables(): IterableIterator { yield* this.lhs.getNullables(); } isBoolean(): boolean { return true; } expression(): Expression { return new Expression.Binary( this.op, this.lhs.expression(), new Expression.Literal(this.rhs), ); } } export class Like extends Clause { public readonly caseSensitive: boolean; public readonly contradiction: boolean; public readonly pattern: string[]; public readonly lhs: Clause; constructor( lhs: Clause, public rhs: string, public esc?: string, ) { super(); const exp = lhs.expression(); let caseSensitive = true; let contradiction = false; if (exp instanceof Expression.FunctionCall) { if (exp.name === "UPPER" || exp.name === "LOWER") { const p = exp.name === "UPPER" ? rhs.toUpperCase() : rhs.toLowerCase(); if (p === rhs) caseSensitive = false; else contradiction = true; lhs = new Exp(exp.args[0]); } } this.lhs = lhs; this.pattern = parseLikePattern(rhs, esc); this.caseSensitive = caseSensitive; this.contradiction = contradiction; } getMinterms(context: SynthContextBase, res: number): Minterm[] { res = res & 0b111; if (!res) return []; if (res === 0b111) return [[]]; if (res === 0b001 || res === 0b110) return this.lhs.getMinterms(context, res); return context.getMinterms(this, res); } isBoolean(): boolean { return true; } isNullable(c: IsNull): boolean { return this.lhs.isNullable(c); } getNullables(): IterableIterator { return this.lhs.getNullables(); } expression(): Expression { let lhs = this.lhs.expression(); if (this.contradiction) { if (this.rhs === this.rhs.toLocaleUpperCase()) lhs = new Expression.FunctionCall("LOWER", [lhs]); else lhs = new Expression.FunctionCall("UPPER", [lhs]); } else if (!this.caseSensitive) { if (this.rhs === this.rhs.toLocaleUpperCase()) lhs = new Expression.FunctionCall("UPPER", [lhs]); else lhs = new Expression.FunctionCall("LOWER", [lhs]); } return new Expression.Binary( "LIKE", lhs, new Expression.Literal(this.rhs), ); } } export class Conditional extends Clause { constructor( public condition: Clause, public then: Clause, public otherwise: Clause, ) { super(); } getMinterms(context: SynthContextBase, res: number): Minterm[] { const condition = this.condition.getMinterms(context, 0b011); if (!condition.length) return this.then.getMinterms(context, res); return [ ...complement([...condition, ...this.then.getMinterms(context, ~res)]), ...complement([ ...complement(condition), ...this.otherwise.getMinterms(context, ~res), ]), ]; } expression(): Expression { if (this._expression != null) return this._expression; if (this.isBoolean()) { this._expression = new Clause.Not(new Clause.Not(this)).expression(); return this._expression; } const context = createSynthContext(); const cases: { when: Minterm[]; then: Expression }[] = []; let clause = this as Conditional; for (;;) { let minterms = clause.condition.getMinterms(context, 0b100); const then = clause.then.expression(); if ( cases.length && then.toString() === cases[cases.length - 1].then.toString() ) minterms.push(...cases.pop().when); minterms = context.minimize( minterms, cases.flatMap((c) => c.when), ); if (!minterms.length) continue; cases.push({ when: minterms, then }); if (minterms.length === 1 && !minterms[0].length) break; if (clause.otherwise instanceof Conditional) clause = clause.otherwise; else clause = new Conditional( new Exp(new Expression.Literal(true)), clause.otherwise, new Exp(new Expression.Literal(null)), ); } while ( cases[cases.length - 1].then instanceof Expression.Literal && (cases[cases.length - 1].then as Expression.Literal).value == null ) cases.pop(); let res: Expression = new Expression.Literal(null); while (cases.length) { const c = cases.pop(); if (c.when.length === 1 && !c.when[0].length) { res = c.then; } else { res = new Expression.Conditional( context.toExpression(c.when), c.then, res, ); } } this._expression = res; return this._expression; } isBoolean(): boolean { return this.then.isBoolean() && this.otherwise.isBoolean(); } } export function fromExpression(exp: Expression): Clause { let res: Clause; let negate = false; if (exp instanceof Expression.Unary) { let op = exp.operator; negate = true; if (op === "IS NOT NULL") op = "IS NULL"; else negate = false; if (op === "NOT") res = new Clause.Not(fromExpression(exp.operand)); else if (op === "IS NULL") res = new IsNull(fromExpression(exp.operand)); } else if (exp instanceof Expression.Binary) { let op = exp.operator; negate = true; if (op === "NOT LIKE") op = "LIKE"; else if (op === "<>") op = "="; else if (op === ">=") op = "<"; else if (op === "<=") op = ">"; else negate = false; if (op === "AND") { res = new Clause.And([ fromExpression(exp.left), fromExpression(exp.right), ]); } else if (op === "OR") { negate = true; res = new Clause.And([ new Clause.Not(fromExpression(exp.left)), new Clause.Not(fromExpression(exp.right)), ]); } else if (exp.right instanceof Expression.Literal) { if (["=", ">", "<"].includes(op)) { if ( ["boolean", "number", "string"].includes(typeof exp.right.value) ) { res = new Compare( fromExpression(exp.left), op as ">" | "<" | "=", exp.right.value, ); } } else if (op === "LIKE") { if (typeof exp.right.value === "string") res = new Like(fromExpression(exp.left), exp.right.value); } } } else if (exp instanceof Expression.Conditional) { res = new Conditional( fromExpression(exp.condition), fromExpression(exp.then), fromExpression(exp.otherwise), ); } if (!res) res = new Exp(exp); if (negate) res = new Not(res); return res; } } function groupBy( input: T[], callback: (item: T) => K, ): Iterable<[K, T[]]> { const groups = new Map(); for (const item of input) { const key = callback(item); let arr = groups.get(key); if (!arr) groups.set(key, (arr = [])); arr.push(item); } return groups.entries(); } export class SynthContext extends SynthContextBase { constructor() { super(); } getMinterms(clause: Clause, res: number): number[][] { const v = this.getVar(clause); switch (res & 0b111) { case 0b100: return [[(v << 2) ^ 3]]; case 0b010: return [[(v << 2) ^ 1]]; case 0b001: return [[v << 2, (v << 2) ^ 2]]; case 0b110: return [[(v << 2) ^ 3], [(v << 2) ^ 1]]; case 0b101: return [[(v << 2) ^ 3], [v << 2, (v << 2) ^ 2]]; case 0b011: return [[(v << 2) ^ 1], [v << 2, (v << 2) ^ 2]]; default: throw new Error("Invalid minterms"); } } getDcSet(minterms: Minterm[]): number[][] { const dcSet: number[][] = []; const whitelist = new Set([...minterms.flat()].map((v) => v >> 2)); const allClauses = [...whitelist].map((v) => this.getClause(v)); const comparisons = allClauses.filter( (c) => c instanceof Clause.Compare, ) as Clause.Compare[]; // Comparisons for (const [, clauses] of groupBy(comparisons, (c) => c.lhs.toString())) { const lhs = clauses[0].lhs; const values = new Set(clauses.map((c) => c.rhs)); const valuesSorted = [...values].sort((a, b) => { const ta = typeof a; const tb = typeof b; if (ta === tb) return a > b ? 1 : -1; else if (ta === "string") return 1; else if (tb === "string") return -1; return +a - +b; }); for (const [i, v] of valuesSorted.entries()) { const eq = this.getVar(new Clause.Compare(lhs, "=", v)); const gt = this.getVar(new Clause.Compare(lhs, ">", v)); const lt = this.getVar(new Clause.Compare(lhs, "<", v)); dcSet.push([(eq << 2) ^ 3, (gt << 2) ^ 3]); dcSet.push([(lt << 2) ^ 3, (gt << 2) ^ 3]); dcSet.push([(lt << 2) ^ 3, (eq << 2) ^ 3]); dcSet.push([(lt << 2) ^ 1, (eq << 2) ^ 1, (gt << 2) ^ 1]); const negEquivOp = [lt, eq, gt].filter((o) => !whitelist.has(o)); if (negEquivOp.length === 1) whitelist.add(negEquivOp[0]); for (let j = 0; j < i; j++) { const eq2 = this.getVar( new Clause.Compare(lhs, "=", valuesSorted[j]), ); const gt2 = this.getVar( new Clause.Compare(lhs, ">", valuesSorted[j]), ); const lt2 = this.getVar( new Clause.Compare(lhs, "<", valuesSorted[j]), ); // This is the minimum clauses required if all relavent vars // were included in the DC set. // dcSet.push([(eq << 2) ^ 3, (eq2 << 2) ^ 3]); // dcSet.push([(lt << 2) ^ 1, (gt2 << 2) ^ 1]); // But we use non-minimal set because intermediate vars // between any two may not be present in the DC set. dcSet.push([(gt2 << 2) ^ 1, (lt << 2) ^ 1]); dcSet.push([(eq2 << 2) ^ 3, (lt << 2) ^ 1]); dcSet.push([(lt2 << 2) ^ 3, (lt << 2) ^ 1]); dcSet.push([(gt2 << 2) ^ 1, (gt << 2) ^ 3]); dcSet.push([(gt2 << 2) ^ 1, (eq << 2) ^ 3]); dcSet.push([(eq2 << 2) ^ 3, (gt << 2) ^ 3]); dcSet.push([(eq2 << 2) ^ 3, (eq << 2) ^ 3]); dcSet.push([(lt2 << 2) ^ 3, (gt << 2) ^ 3]); dcSet.push([(lt2 << 2) ^ 3, (eq << 2) ^ 3]); } } } // LIKE const likes = allClauses.filter( (c) => c instanceof Clause.Like, ) as Clause.Like[]; for (const [, clauses] of groupBy(likes, (c) => c.lhs.toString())) { for (let i1 = 0; i1 < clauses.length; ++i1) { const l1 = clauses[i1]; if (l1.contradiction) { dcSet.push([(this.getVar(l1) << 2) ^ 3]); continue; } for (let i2 = i1 + 1; i2 < clauses.length; ++i2) { const l2 = clauses[i2]; if (l2.contradiction) continue; let p1 = l1.pattern; let p2 = l2.pattern; if (!l1.caseSensitive || !l2.caseSensitive) { p1 = p1.map((c) => c.toLowerCase()); p2 = p2.map((c) => c.toLowerCase()); } if (likeDisjoint(p1, p2)) { dcSet.push([ (this.getVar(l1) << 2) ^ 3, (this.getVar(l2) << 2) ^ 3, ]); } else if ( (!l1.caseSensitive || l2.caseSensitive) && likeImplies(p1, p2) ) { dcSet.push([ (this.getVar(l1) << 2) ^ 2, (this.getVar(l2) << 2) ^ 3, ]); dcSet.push([ (this.getVar(l1) << 2) ^ 1, (this.getVar(l2) << 2) ^ 0, ]); } else if ( (!l2.caseSensitive || l1.caseSensitive) && likeImplies(p2, p1) ) { dcSet.push([ (this.getVar(l1) << 2) ^ 3, (this.getVar(l2) << 2) ^ 2, ]); dcSet.push([ (this.getVar(l1) << 2) ^ 0, (this.getVar(l2) << 2) ^ 1, ]); } } } } for (const [lhsKey, likeGroup] of groupBy(likes, (c) => c.lhs.toString())) { const compareGroupAll = comparisons.filter( (c) => c.lhs.toString() === lhsKey, ); for (const like of likeGroup) { if (like.contradiction) continue; const pattern = like.caseSensitive ? like.pattern : like.pattern.map((c) => c.toLowerCase()); const likeVar = this.getVar(like); for (const compare of compareGroupAll.filter((c) => c.op === "=")) { if (typeof compare.rhs !== "string") continue; const value = like.caseSensitive ? compare.rhs : compare.rhs.toLowerCase(); const matches = likeMatches(pattern, value, true); const eqVar = this.getVar(compare); if (matches) { dcSet.push([(eqVar << 2) ^ 3, (likeVar << 2) ^ 1]); // Don't add eq=true AND like=null as DC; combined with eq=true AND // like=false, espresso would treat LIKE as don't-care when eq=true } else { dcSet.push([(eqVar << 2) ^ 3, (likeVar << 2) ^ 3]); } } // Prefix patterns like 'abc%' match strings in range [prefix, upperBound) const prefix = getPureLikePrefix(pattern); if (prefix) { const upperBound = getLikePrefixUpperBound(prefix); // string < prefix means it can't match the pattern for (const compare of compareGroupAll.filter((c) => c.op === "<")) { if (typeof compare.rhs !== "string") continue; const value = like.caseSensitive ? compare.rhs : compare.rhs.toLowerCase(); const ltVar = this.getVar(compare); if (value <= prefix) { dcSet.push([(ltVar << 2) ^ 3, (likeVar << 2) ^ 3]); } } // string > upperBound means it can't match the pattern // (string > prefix could still match, e.g., 'abcd' > 'abc' matches 'abc%') if (upperBound) { for (const compare of compareGroupAll.filter((c) => c.op === ">")) { if (typeof compare.rhs !== "string") continue; const value = like.caseSensitive ? compare.rhs : compare.rhs.toLowerCase(); const gtVar = this.getVar(compare); if (value >= upperBound) { dcSet.push([(gtVar << 2) ^ 3, (likeVar << 2) ^ 3]); } } } } } } for (const v of whitelist) { const clause = this.getClause(v); const nullables = [...clause.getNullables()].map((c) => this.getVar(c)); if (nullables.length) { dcSet.push([ ...nullables.map((n) => (n << 2) ^ 2), (v << 2) ^ 0, (v << 2) ^ 2, ]); for (const n of nullables) { dcSet.push([(n << 2) ^ 3, (v << 2) ^ 1]); dcSet.push([(n << 2) ^ 3, (v << 2) ^ 3]); whitelist.add(n); } } if (clause instanceof Clause.IsNull) { if (clause.operand instanceof Clause.Exp) { if (clause.operand.exp instanceof Expression.Parameter) { const str = clause.operand.exp.path.toString(); if (str === "DeviceID.ID" || str === "_id") dcSet.push([(v << 2) ^ 3]); } } } } return dcSet.filter((m) => m.every((v) => whitelist.has(v >> 2))); } canRaise(idx: number, set: Set): boolean { const clause = this.getClause(idx >> 2); if (clause instanceof Clause.IsNull) { for (const i of set) { if (i === idx || i & 1) continue; const c = this.getClause(i >> 2); if (c.isNullable(clause)) return false; } return true; } return !(idx & 1) || !set.has(idx ^ 3); } canLower(idx: number, set: Set): boolean { if (idx & 1) return true; const clause = this.getClause(idx >> 2); if (clause instanceof Clause.IsNull) return true; return set.has(idx ^ 3) || set.has(idx ^ 1); } bias(a: number, b: number): number { // Bias towards 1 then true return ((b & 3) ^ 3) - ((a & 3) ^ 3); } sanitizeMinterms(minterms: Minterm[]): Minterm[] { const res = [] as number[][]; loop: for (const m of minterms) { const merged: Map = new Map(); for (const i of m) merged.set(i >> 2, (merged.get(i >> 2) || 0) | (1 << (i & 3))); const minterm: number[] = []; const perms: number[][] = []; for (const [k, v] of merged) { if ((v & 0b0011) === 0b0011) continue loop; if ((v & 0b1100) === 0b1100) continue loop; const clause = this.clauses.get(k); if (!clause) throw new Error("Invalid literal"); if (clause instanceof Clause.IsNull) { if (v === 0b0100) minterm.push((k << 2) ^ 2); else if (v === 0b1000) minterm.push((k << 2) ^ 3); else throw new Error("Invalid literal"); continue; } if ((v & 0b1010) === 0b1010) continue loop; const isNullVars = [...clause.getNullables()].map((c) => this.getVar(c), ); const t = k << 2; if (v === 0b0101) { if (isNullVars.length === 1) minterm.push((isNullVars[0] << 2) ^ 3); else perms.push(isNullVars.map((n) => (n << 2) ^ 3)); } else if (v === 0b0001) { perms.push([...isNullVars.map((n) => (n << 2) ^ 3), t ^ 3]); } else if (v === 0b0100) { perms.push([...isNullVars.map((n) => (n << 2) ^ 3), t ^ 1]); } else if (v & 0b1000) { minterm.push(t ^ 3); } else if (v & 0b0010) { minterm.push(t ^ 1); } } let ms = [minterm]; while (perms.length) { const newMs: number[][] = []; const perm = perms.pop(); for (const p of perm) newMs.push(...ms.map((mm) => [...mm, p])); ms = newMs; } res.push(...ms); } return res; } toExpression(sop: number[][]): Expression { let res: Expression = new Expression.Literal(false); for (const s of sop) { let conjs: Expression = new Expression.Literal(true); for (const i of s) { const clause = this.getClause(i >>> 2); if (!clause) throw new Error("Invalid literal"); if (clause instanceof Clause.IsNull) { if (!(i & 2)) throw new Error("Invalid literal"); } else if (!(i & 1)) { // Should never be reached if minimized correctly const isNullVars = [...clause.getNullables()].map((c) => this.getVar(c), ); conjs = Expression.and( conjs, this.toExpression([ [i ^ 3], ...isNullVars.map((n) => [(n << 2) ^ 3]), ]), ); continue; } let expr = clause.expression(); if (!(i & 1) !== !(i & 2)) expr = new Expression.Unary("NOT", expr); if (expr instanceof Expression.Unary && expr.operator === "NOT") { const e = expr.operand; if (e instanceof Expression.Unary) { if (e.operator === "IS NULL") expr = new Expression.Unary("IS NOT NULL", e.operand); else if (e.operator === "IS NOT NULL") expr = new Expression.Unary("IS NULL", e.operand); else if (e.operator === "NOT") expr = e.operand; } else if (e instanceof Expression.Binary) { if (e.operator === "LIKE") expr = new Expression.Binary("NOT LIKE", e.left, e.right); else if (e.operator === "=") expr = new Expression.Binary("<>", e.left, e.right); else if (e.operator === "<>") expr = new Expression.Binary("=", e.left, e.right); else if (e.operator === ">") expr = new Expression.Binary("<=", e.left, e.right); else if (e.operator === ">=") expr = new Expression.Binary("<", e.left, e.right); else if (e.operator === "<") expr = new Expression.Binary(">=", e.left, e.right); else if (e.operator === "<=") expr = new Expression.Binary(">", e.left, e.right); } } conjs = Expression.and(conjs, expr); } res = Expression.or(res, conjs); } return res; } } // Classes aren't hoisted in JS but functions are. This function is used to // create a new SynthContext instance from inside the Clause class. export function createSynthContext(): SynthContext { return new SynthContext(); } function likeMatches( pattern: string[], value: string, caseSensitive: boolean, ): boolean { if (!caseSensitive) { value = value.toLowerCase(); pattern = pattern.map((c) => c === "\\%" || c === "\\_" ? c : c.toLowerCase(), ); } let pi = 0; let vi = 0; let backtrackPi = -1; let backtrackVi = -1; while (vi < value.length) { if (pi < pattern.length && pattern[pi] === "\\%") { backtrackPi = pi; backtrackVi = vi; pi++; } else if ( pi < pattern.length && (pattern[pi] === "\\_" || pattern[pi] === value[vi]) ) { pi++; vi++; } else if (backtrackPi >= 0) { pi = backtrackPi + 1; backtrackVi++; vi = backtrackVi; } else { return false; } } while (pi < pattern.length && pattern[pi] === "\\%") pi++; return pi === pattern.length; } function getLikePrefixUpperBound(prefix: string): string | null { if (!prefix) return null; for (let i = prefix.length - 1; i >= 0; i--) { const charCode = prefix.charCodeAt(i); // 0x10ffff is max Unicode code point; sufficient for practical strings if (charCode < 0x10ffff) { return prefix.slice(0, i) + String.fromCodePoint(charCode + 1); } } return null; } function getPureLikePrefix(pattern: string[]): string | null { if (pattern.length === 0) return null; let hasTrailingPercent = false; let prefix = ""; for (let i = 0; i < pattern.length; i++) { const c = pattern[i]; if (c === "\\%") { for (let j = i; j < pattern.length; j++) { if (pattern[j] !== "\\%") return null; } hasTrailingPercent = true; break; } else if (c === "\\_") { return null; } else { prefix += c; } } if (!hasTrailingPercent) return null; if (!prefix) return null; return prefix; } export function likeImplies(pat1: string[], pat2: string[]): boolean { let backtrack: [number, number] = null; for (let i1 = 0, i2 = 0; ; ++i1, ++i2) { while (i1 < pat1.length && pat1[i1] === "\\%") backtrack = [i1++, i2]; if (i2 >= pat2.length) return i1 >= pat1.length; const c = i1 < pat1.length ? pat1[i1] : null; if (c !== pat2[i2] && c !== "\\_") { if (!backtrack) return false; [i1, i2] = backtrack; ++backtrack[1]; } } } export function likeDisjoint(pat1: string[], pat2: string[]): boolean { const left1Idx = pat1.indexOf("\\%"); const left2Idx = pat2.indexOf("\\%"); const right1Idx = pat1.lastIndexOf("\\%"); const right2Idx = pat2.lastIndexOf("\\%"); const left1 = pat1.slice(0, left1Idx !== -1 ? left1Idx : pat1.length); const left2 = pat2.slice(0, left2Idx !== -1 ? left2Idx : pat2.length); const right1 = pat1.slice(right1Idx !== -1 ? right1Idx + 1 : 0).reverse(); const right2 = pat2.slice(right2Idx !== -1 ? right2Idx + 1 : 0).reverse(); for (let i = 0; i < Math.min(left1.length, left2.length); ++i) { if (left1[i] !== left2[i] && left1[i] !== "\\_" && left2[i] !== "\\_") return true; } for (let i = 0; i < Math.min(right1.length, right2.length); ++i) { if (right1[i] !== right2[i] && right1[i] !== "\\_" && right2[i] !== "\\_") return true; } if (pat1.length === left1.length) return pat2.filter((c) => c !== "\\%").length > pat1.length; else if (pat2.length === left2.length) return pat1.filter((c) => c !== "\\%").length > pat2.length; return false; } export function minimize(expr: Expression, boolean = false): Expression { let synth = Clause.fromExpression(normalize(expr)); if (boolean) synth = new Clause.Not(new Clause.Not(synth)); return synth.expression(); } export function unionDiff( expr1: Expression, expr2: Expression, ): [Expression, Expression] { expr2 = normalize(expr2); if (expr2 instanceof Expression.Literal && !expr2.value) return [expr1, new Expression.Literal(false)]; const synth2 = Clause.fromExpression(expr2); if (expr1 instanceof Expression.Literal && !expr1.value) { const e = synth2.expression(); return [e, e]; } expr1 = normalize(expr1); const synth1 = Clause.fromExpression(expr1); const context = new SynthContext(); const expr2Minterms = synth2.getMinterms(context, 0b100); const expr1Minterms = synth1.getMinterms(context, 0b100); const union = context.minimize([...expr1Minterms, ...expr2Minterms]); const diff = context.minimize( complement([...expr1Minterms, ...complement(expr2Minterms)]), ); return [context.toExpression(union), context.toExpression(diff)]; } export function covers(expr1: Expression, expr2: Expression): boolean { expr2 = normalize(expr2); if (expr2 instanceof Expression.Literal && !expr2.value) return true; expr1 = normalize(expr1); if (expr1 instanceof Expression.Literal && expr1.value) return true; const synt1 = Clause.fromExpression(expr1); const synt2 = Clause.fromExpression(expr2); const context = new SynthContext(); const expr1Minterms = synt1.getMinterms(context, 0b100); const expr2Minterms = synt2.getMinterms(context, 0b100); return tautology([ ...context.sanitizeMinterms(complement(expr2Minterms)), ...context.getDcSet([...expr2Minterms, ...expr1Minterms]), ...context.sanitizeMinterms(expr1Minterms), ]); } export function areEquivalent(expr1: Expression, expr2: Expression): boolean { expr1 = normalize(expr1); expr2 = normalize(expr2); // Both are trivial (true/false) if ( expr1 instanceof Expression.Literal && expr2 instanceof Expression.Literal ) { return !!expr1.value === !!expr2.value; } const synth1 = Clause.fromExpression(expr1); const synth2 = Clause.fromExpression(expr2); const context = new SynthContext(); const expr1Minterms = synth1.getMinterms(context, 0b100); const expr2Minterms = synth2.getMinterms(context, 0b100); const dcSet = context.getDcSet([...expr1Minterms, ...expr2Minterms]); // Equivalent iff expr1 covers expr2 AND expr2 covers expr1 // expr1 covers expr2: NOT(expr2) OR expr1 is tautology // expr2 covers expr1: NOT(expr1) OR expr2 is tautology const notExpr1 = complement(expr1Minterms); const notExpr2 = complement(expr2Minterms); return ( tautology([ ...context.sanitizeMinterms([...notExpr2, ...expr1Minterms]), ...dcSet, ]) && tautology([ ...context.sanitizeMinterms([...notExpr1, ...expr2Minterms]), ...dcSet, ]) ); } // Returns expr2 - expr1 (what's in expr2 but not in expr1) export function subtract(expr1: Expression, expr2: Expression): Expression { expr2 = normalize(expr2); if (expr2 instanceof Expression.Literal && !expr2.value) return new Expression.Literal(false); expr1 = normalize(expr1); if (expr1 instanceof Expression.Literal && !expr1.value) { const synth2 = Clause.fromExpression(expr2); return synth2.expression(); } if (expr1 instanceof Expression.Literal && expr1.value) return new Expression.Literal(false); const synth1 = Clause.fromExpression(expr1); const synth2 = Clause.fromExpression(expr2); const context = new SynthContext(); const expr1Minterms = synth1.getMinterms(context, 0b100); const expr2Minterms = synth2.getMinterms(context, 0b100); const diff = context.minimize( complement([...expr1Minterms, ...complement(expr2Minterms)]), ); return context.toExpression(diff); } ================================================ FILE: lib/common/expression.ts ================================================ import { Cursor, parseExpression, stringifyExpression, } from "./expression/parser.ts"; import Path from "./path.ts"; import { reduce } from "./expression/evaluate.ts"; export type Value = string | number | boolean | null; export abstract class Expression { private _string: string; abstract map(fn: (e: Expression, i: number) => Expression): Expression; abstract mapAsync( fn: (e: Expression, i: number) => Promise, ): Promise; toString(): string { if (!this._string) this._string = stringifyExpression(this); return this._string; } evaluate(fn: (e: Expression) => T = (e) => e as T): T { return fn(reduce(this.map((e) => e.evaluate(fn)))); } async evaluateAsync( fn: (e: Expression) => Promise, ): Promise { return await fn( reduce(await this.mapAsync(async (e) => await e.evaluateAsync(fn))), ); } static parse(input: string): Expression { const cursor = new Cursor(input); const exp = parseExpression(cursor); if (cursor.charCode) throw new Error("Unexpected character"); return exp; } static and(left: Expression, right: Expression): Expression { // Flatten same-operator tree into operands const operands: Expression[] = []; const stack: Expression[] = [right, left]; while (stack.length) { const e = stack.pop()!; if (e instanceof Expression.Binary && e.operator === "AND") stack.push(e.right, e.left); else operands.push(e); } // Fold literals using three-valued AND logic let folded: boolean | null = true; let i = 0; while (i < operands.length) { const e = operands[i]; if (e instanceof Expression.Literal) { operands.splice(i, 1); if (e.value == null) folded = folded === false ? false : null; else if (!e.value) return new Expression.Literal(false); // truthy is identity for AND; discard } else { i++; } } // Rebuild: folded value + remaining non-literal operands if (!operands.length) return new Expression.Literal(folded); let result = operands.reduce((a, b) => new Expression.Binary("AND", a, b)); if (folded === null) result = new Expression.Binary( "AND", new Expression.Literal(null), result, ); return result; } static or(left: Expression, right: Expression): Expression { // Flatten same-operator tree into operands const operands: Expression[] = []; const stack: Expression[] = [right, left]; while (stack.length) { const e = stack.pop()!; if (e instanceof Expression.Binary && e.operator === "OR") stack.push(e.right, e.left); else operands.push(e); } // Fold literals using three-valued OR logic let folded: boolean | null = false; let i = 0; while (i < operands.length) { const e = operands[i]; if (e instanceof Expression.Literal) { operands.splice(i, 1); if (e.value == null) folded = folded === true ? true : null; else if (e.value) return new Expression.Literal(true); // falsy is identity for OR; discard } else { i++; } } // Rebuild: folded value + remaining non-literal operands if (!operands.length) return new Expression.Literal(folded); let result = operands.reduce((a, b) => new Expression.Binary("OR", a, b)); if (folded === null) result = new Expression.Binary( "OR", new Expression.Literal(null), result, ); return result; } } // eslint-disable-next-line @typescript-eslint/no-namespace export namespace Expression { export class Literal extends Expression { constructor(public readonly value: Value) { super(); } map(): Literal { return this; } async mapAsync(): Promise { return this; } } export class Parameter extends Expression { constructor(public readonly path: Path) { super(); } map(): Parameter { return this; } async mapAsync(): Promise { return this; } toString(): string { return this.path.toString(); } } export class Unary extends Expression { constructor( public readonly operator: string, public readonly operand: Expression, ) { super(); } map(fn: (e: Expression, i: number) => Expression): Unary { const operand = fn(this.operand, 0); if (operand === this.operand) return this; return Reflect.construct(this.constructor, [this.operator, operand]); } async mapAsync( fn: (e: Expression, i: number) => Promise, ): Promise { const operand = await fn(this.operand, 0); if (operand === this.operand) return this; return Reflect.construct(this.constructor, [this.operator, operand]); } } export class Binary extends Expression { constructor( public readonly operator: string, public readonly left: Expression, public readonly right: Expression, ) { super(); } map(fn: (e: Expression, i: number) => Expression): Binary { const left = fn(this.left, 0); const right = fn(this.right, 1); if (left === this.left && right === this.right) return this; return Reflect.construct(this.constructor, [this.operator, left, right]); } async mapAsync( fn: (e: Expression, i: number) => Promise, ): Promise { const left = await fn(this.left, 0); const right = await fn(this.right, 1); if (left === this.left && right === this.right) return this; return Reflect.construct(this.constructor, [this.operator, left, right]); } } export class FunctionCall extends Expression { constructor( public readonly name: string, public readonly args: Expression[], ) { super(); } map(fn: (e: Expression, i: number) => Expression): FunctionCall { const args = this.args.map(fn); if (args.every((arg, i) => arg === this.args[i])) return this; return new FunctionCall(this.name, args); } async mapAsync( fn: (e: Expression, i: number) => Promise, ): Promise { const args = await Promise.all(this.args.map(fn)); if (args.every((arg, i) => arg === this.args[i])) return this; return new FunctionCall(this.name, args); } } export class Conditional extends Expression { constructor( public readonly condition: Expression, public readonly then: Expression, public readonly otherwise: Expression, ) { super(); } map(fn: (e: Expression, i: number) => Expression): Conditional { const condition = fn(this.condition, 0); const then = fn(this.then, 1); const otherwise = fn(this.otherwise, 2); if ( condition === this.condition && then === this.then && otherwise === this.otherwise ) return this; return new Conditional(condition, then, otherwise); } async mapAsync( fn: (e: Expression, i: number) => Promise, ): Promise { const condition = await fn(this.condition, 0); const then = await fn(this.then, 1); const otherwise = await fn(this.otherwise, 2); if ( condition === this.condition && then === this.then && otherwise === this.otherwise ) return this; return new Conditional(condition, then, otherwise); } } } export function extractPaths(exp: Expression): Path[] { if (exp instanceof Expression.Parameter) return [exp.path]; const paths: Path[] = []; exp.map((e) => { if (e instanceof Expression.Parameter) paths.push(e.path); else paths.push(...extractPaths(e)); return e; }); return paths; } export function parseList(input: string): Expression[] { const CHAR_COMMA = 44; const res: Expression[] = []; const cursor = new Cursor(input); cursor.skipwhitespace(); if (!cursor.charCode) return res; res.push(parseExpression(cursor)); while (cursor.charCode === CHAR_COMMA) { cursor.step(); res.push(parseExpression(cursor)); } if (cursor.charCode) throw new Error("Unexpected character"); return res; } export default Expression; ================================================ FILE: lib/common/memoize.ts ================================================ let cache1 = new Map(); let cache2 = new Map(); const keys = new WeakMap(); function getKey(obj): string { if (obj === null) return "null"; else if (obj === undefined) return "undefined"; const t = typeof obj; if (t === "number" || t === "boolean" || t === "string") return `${t}:${obj}`; if (t !== "function" && t !== "object") throw new Error(`Cannot memoize ${t} arguments`); let k = keys.get(obj); if (!k) { const rnd = Math.trunc(Math.random() * Number.MAX_SAFE_INTEGER); k = `${t}:${rnd.toString(36)}`; keys.set(obj, k); } return k; } export default function memoize any>(func: T): T { const funcKey = getKey(func); return ((...args) => { const key = JSON.stringify(args.map(getKey)) + funcKey; if (cache1.has(key)) return cache1.get(key); let r; if (cache2.has(key)) { cache1.set(key, (r = cache2.get(key))); } else { cache1.set(key, (r = func(...args))); // Evict rejected promises if (r instanceof Promise) { r.catch(() => { cache1.delete(key); cache2.delete(key); }); } } return r; }) as any; } const interval = setInterval(() => { cache2 = cache1; cache1 = new Map(); }, 120000); // Don't hold Node.js process if (interval.unref) interval.unref(); ================================================ FILE: lib/common/path-set.ts ================================================ import Path from "./path.ts"; export default class PathSet { private paramSegmentIndex: Map>[] = []; private attrSegmentIndex: Map>[] = []; private stringIndex: Map = new Map(); public constructor() {} public add(pathStr: string): Path { let path: Path = this.get(pathStr); if (path) return path; path = Path.parse(pathStr); if (path.alias) throw new Error("PathSet does not support aliased paths"); this.stringIndex.set(path.toString(), path); while (this.paramSegmentIndex.length < path.paramLength) this.paramSegmentIndex.push(new Map()); while (this.attrSegmentIndex.length < path.attrLength) this.attrSegmentIndex.push(new Map()); for (let i = 0; i < path.length; ++i) { const fragment = path.segments[i] as string; const fragmentIndex = i < path.paramLength ? this.paramSegmentIndex[i] : this.attrSegmentIndex[i - path.paramLength]; let fragmentIndexSet = fragmentIndex.get(fragment); if (!fragmentIndexSet) { fragmentIndexSet = new Set(); fragmentIndex.set(fragment, fragmentIndexSet); } fragmentIndexSet.add(path); } return path; } public get(path: string): Path { return this.stringIndex.get(path); } public findCompat( path: Path, superset = false, subset = false, depth = path.length, ): Path[] { if (path.attrLength) throw new Error("findCompat() does not support attribute paths"); depth = Math.min(31, depth); const paramMask = (1 << path.paramLength) - 1; let mask = ((0b10 << depth) - 1) & ~paramMask; if (superset) mask |= ~path.wildcard & paramMask; if (subset) mask |= path.wildcard; return this.find(path, mask, 1); } public find(path: Path, paramMask: number, attrMask: number): Path[] { if (path.alias) throw new Error("PathSet does not support aliased paths"); if (path.paramLength > this.paramSegmentIndex.length) return []; if (path.attrLength > this.attrSegmentIndex.length) return []; const emptySet: Set = new Set(); const indexes: [Set, Set][] = []; const paramLengthMask = (1 << path.paramLength) - 1; const attrLengthMask = (1 << path.attrLength) - 1; const mask = (paramMask & paramLengthMask) | (attrMask << path.paramLength); for (const [i, s] of path.segments.entries()) { const b = 1 << i; const m = mask & b; const w = b & path.wildcard; if (w && m) continue; const idxSet = i < path.paramLength ? this.paramSegmentIndex[i] : this.attrSegmentIndex[i - path.paramLength]; const idx1 = idxSet.get(s as string) || emptySet; let idx2 = emptySet; if (m) idx2 = idxSet.get("*") || emptySet; indexes.push([idx1, idx2]); } indexes.sort((a, b) => a[0].size + a[1].size - (b[0].size + b[1].size)); let res: Path[]; if (!indexes.length) res = [...this.stringIndex.values()]; else res = [...indexes[0][0], ...indexes[0][1]]; const paramCover = ~paramLengthMask & paramMask; const attrCover = ~attrLengthMask & attrMask; res = res.filter( (p) => (1 << p.paramLength) & paramCover && (1 << p.attrLength) & attrCover, ); for (let i = 1; i < indexes.length; ++i) { const [idx1, idx2] = indexes[i]; res = res.filter((p) => idx1.has(p) || idx2.has(p)); } return res; } } ================================================ FILE: lib/common/path.ts ================================================ import Expression from "./expression.ts"; import { Cursor, parsePath } from "./expression/parser.ts"; type Segments = (string | Expression)[]; let cache1 = new Map(); let cache2 = new Map(); export default class Path { declare public readonly segments: Segments; declare public readonly colon: number; declare public readonly wildcard: number; declare public readonly alias: number; declare protected _string: string; declare protected _stringIndex: number[]; constructor(segments: Segments, colon: number) { if (!(colon <= segments.length)) throw new Error("Invalid path"); if (segments.length > 32) throw new Error("Path too long"); Object.freeze(segments); let alias = 0; let wildcard = 0; const arr = segments.map((s, i) => { if (s instanceof Expression) { alias |= 1 << i; return `[${s.toString()}]`; } else if (s === "*") { wildcard |= 1 << i; } return s; }); let offset = 0; const stringIndex = arr.map((s, i) => (offset += s.length) + i); this.segments = segments; this.colon = colon; this.wildcard = wildcard; this.alias = alias; if (!colon) this._string = arr.join("."); else this._string = arr.slice(0, -colon).join(".") + ":" + arr.slice(-colon).join("."); this._stringIndex = stringIndex; } public static parse(input: string): Path { let path = cache1.get(input); if (!path) { path = cache2.get(input); if (!path) { const cursor = new Cursor(input); path = parsePath(cursor); if (cursor.charCode) throw new Error("Unexpected character"); if (path.toString() !== input) cache1.set(path.toString(), path); } cache1.set(input, path); } return path; } public get length(): number { return this.segments.length; } public get paramLength(): number { return this.segments.length - this.colon; } public get attrLength(): number { return this.colon; } public toString(): string { return this._string; } public slice(start = 0, end: number = this.segments.length): Path { if (start < 0) start = Math.max(0, this.segments.length + start); if (end < 0) end = Math.max(0, this.segments.length + end); if (start >= end) return Path.root; let i1 = start > 0 ? this._stringIndex[start - 1] + 1 : 0; // Include the ":" when slicing exactly at the colon boundary if (this.colon && start === this.segments.length - this.colon) --i1; const i2 = end <= this.segments.length ? this._stringIndex[end - 1] : this._string.length; const str = this._string.slice(i1, i2); let path = cache1.get(str); if (!path) { path = cache2.get(str); if (!path) { const segments = this.segments.slice(start, end); const colon = start <= this.segments.length - this.colon ? Math.max(0, this.colon - this.segments.length + end) : 0; path = new Path(segments, colon); } cache1.set(str, path); } return path; } public concat(path2: Path): Path { if (!path2._string) return this; else if (!this._string) return path2; if (this.colon && path2.colon && path2.colon < path2.segments.length) throw new Error("Invalid path"); const colon = this.colon ? this.colon + path2.segments.length : path2.colon; let str; if (this.colon && path2.colon === path2.segments.length) { // Right is all-colon; strip its ":" prefix and join with "." str = `${this._string}.${path2._string.slice(1)}`; } else if (path2.colon === path2.segments.length) { // Left has no colon; right is all-colon; concatenate directly str = `${this._string}${path2._string}`; } else { str = `${this._string}.${path2._string}`; } let path = cache1.get(str); if (!path) { path = cache2.get(str); if (!path) { const segments = this.segments.concat(path2.segments); path = new Path(segments, colon); } cache1.set(str, path); } return path; } public stripAlias(): Path { if (!this.alias) return this; const segments = this.segments.map((s) => s instanceof Expression ? "*" : s, ); let str: string; if (!this.colon) str = segments.join("."); else str = segments.slice(0, -this.colon).join(".") + ":" + segments.slice(-this.colon).join("."); let path = cache1.get(str); if (!path) { path = cache2.get(str); if (!path) { path = new Path(segments, this.colon); } cache1.set(str, path); } return path; } static root = new Path([], 0); } const interval = setInterval(() => { cache2 = cache1; cache1 = new Map(); }, 120000); // Don't hold Node.js process if (interval.unref) interval.unref(); ================================================ FILE: lib/common/yaml.ts ================================================ const LINE_WIDTH = 80; const INDENTATION = " "; const STRING_RESERVED = new Set([ "true", "True", "TRUE", "false", "False", "FALSE", "null", "Null", "NULL", ]); function isPrintable(str: string): boolean { return !/[^\t\n\x20-\x7e\x85\u{a0}-\u{d7ff}\u{e000}-\u{fffd}\u{10000}-\u{10ffff}]/u.test( str, ); } function stringifyKey(str: string): string { if (!str || !isPrintable(str)) return JSON.stringify(str); if (/^[\s-?:,[\]{}#&$!|>'"%@`]|: | #|[\n,[\]{}]|\s$/.test(str)) return JSON.stringify(str); return str; } function foldString(str: string): string[] { if (str.length <= LINE_WIDTH) return [str]; if (str.startsWith(" ")) return [str]; const lines: string[] = []; let idx = 0; let cand = 0; for (let i = 1; i < str.length - 1; ++i) { if (str[i] !== " ") continue; if (str[i + 1] === " ") { i += 2; while (str[i] === " ") ++i; continue; } if (i <= idx + LINE_WIDTH) { cand = i; continue; } const c = cand > idx ? cand : i; lines.push(str.slice(idx, c)); idx = c + 1; cand = i; } if (cand > idx && str.length > idx + LINE_WIDTH) { lines.push(str.slice(idx, cand)); idx = cand + 1; } lines.push(str.slice(idx)); return lines; } function stringifyString(str: string, res: string[], prefix1, prefix2): void { if (/^\s*$/.test(str) || STRING_RESERVED.has(str) || !isPrintable(str)) { res.push(prefix1 + JSON.stringify(str)); return; } if (!prefix2) prefix2 = INDENTATION; const lines = str.split("\n"); if (lines.length > 1) { let idt = ""; let chmp = "-"; if ((lines.find((l) => l) || "").startsWith(" ")) idt = `${INDENTATION.length}`; if (!lines[lines.length - 1]) { lines.pop(); if (lines[lines.length - 1]) chmp = ""; else chmp = "+"; } if (/^\s+$/.test(lines[lines.length - 1])) { res.push(prefix1 + JSON.stringify(str)); return; } let isFolded = false; const folded = lines.map((l) => { const ls = foldString(l); if (ls.length > 1) isFolded = true; return ls; }); if (!isFolded) { res.push( `${prefix1}|${idt}${chmp}`, ...lines.map((l) => (l ? prefix2 + l : l)), ); return; } res.push(`${prefix1}>${idt}${chmp}`); res.push(...folded[0].map((f) => prefix2 + f)); for (let i = 1; i < folded.length; ++i) { const prevLine = folded[i - 1][0]; if (prevLine && !folded[i - 1][0].startsWith(" ")) res.push(""); res.push(...folded[i].map((f) => prefix2 + f)); } return; } if ( /^[\s-?:,[\]{}#&$!|>'"%@`]|: | #|\s$/.test(str) || parseFloat(str) === +str ) { res.push(prefix1 + JSON.stringify(str)); return; } res.push(prefix1 + str); } function stringifyAny( obj: unknown, res: string[], prefix1 = "", prefix2 = "", ): void { if (obj == null) { res.push(`${prefix1}null`); return; } if (typeof obj === "number" || typeof obj === "boolean") { res.push(`${prefix1}${JSON.stringify(obj)}`); return; } if (obj instanceof Date) { res.push(`${prefix1}${obj.toJSON()}`); return; } if (typeof obj === "string") { stringifyString(obj, res, prefix1, prefix2); return; } if (Array.isArray(obj)) { if (!obj.length) { res.push(prefix1 + "[]"); return; } if (!prefix1 || prefix1.endsWith("- ")) { stringifyAny(obj[0], res, prefix1 + "- ", prefix2 + INDENTATION); prefix1 = prefix2 + "- "; prefix2 = prefix2 + INDENTATION; for (let i = 1; i < obj.length; ++i) stringifyAny(obj[i], res, prefix1, prefix2); } else { res.push(prefix1); prefix1 = prefix2 + "- "; prefix2 = prefix2 + INDENTATION; for (let i = 0; i < obj.length; ++i) stringifyAny(obj[i], res, prefix1, prefix2); } return; } const entries = Object.entries(obj).filter((e) => e[1] !== undefined); if (!entries.length) { res.push(prefix1 + "{}"); return; } if (!prefix1 || prefix1.endsWith("- ")) { stringifyAny( entries[0][1], res, prefix1 + `${stringifyKey(entries[0][0])}: `, prefix2 + INDENTATION, ); prefix1 = prefix2; prefix2 = prefix2 + INDENTATION; for (let i = 1; i < entries.length; ++i) { stringifyAny( entries[i][1], res, prefix1 + `${stringifyKey(entries[i][0])}: `, prefix2, ); } } else { res.push(prefix1); prefix1 = prefix2; prefix2 = prefix2 + INDENTATION; for (let i = 0; i < entries.length; ++i) { stringifyAny( entries[i][1], res, prefix1 + `${stringifyKey(entries[i][0])}: `, prefix2, ); } } } export function stringify(obj: unknown): string { if (obj === undefined) return undefined; const lines: string[] = []; stringifyAny(obj, lines); return lines.join("\n") + "\n"; } ================================================ FILE: lib/config.ts ================================================ import { resolve } from "node:path"; import { readFileSync, existsSync } from "node:fs"; // Find project root directory export let ROOT_DIR = resolve(__dirname, ".."); while (!existsSync(`${ROOT_DIR}/package.json`)) { const d = resolve(ROOT_DIR, ".."); if (d === ROOT_DIR) { ROOT_DIR = process.cwd(); break; } ROOT_DIR = d; } // For compatibility with v1.1 let configDir, cwmpSsl, nbiSsl, fsSsl, uiSsl, fsHostname; const options = { EXT_DIR: { type: "path", default: resolve(ROOT_DIR, "config/ext") }, MONGODB_CONNECTION_URL: { type: "string", default: "mongodb://127.0.0.1/genieacs", }, CWMP_WORKER_PROCESSES: { type: "int", default: 0 }, CWMP_PORT: { type: "int", default: 7547 }, CWMP_INTERFACE: { type: "string", default: "::" }, CWMP_SSL_CERT: { type: "string", default: "" }, CWMP_SSL_KEY: { type: "string", default: "" }, CWMP_LOG_FILE: { type: "path", default: "" }, CWMP_ACCESS_LOG_FILE: { type: "path", default: "" }, NBI_WORKER_PROCESSES: { type: "int", default: 0 }, NBI_PORT: { type: "int", default: 7557 }, NBI_INTERFACE: { type: "string", default: "::" }, NBI_SSL_CERT: { type: "string", default: "" }, NBI_SSL_KEY: { type: "string", default: "" }, NBI_LOG_FILE: { type: "path", default: "" }, NBI_ACCESS_LOG_FILE: { type: "path", default: "" }, FS_WORKER_PROCESSES: { type: "int", default: 0 }, FS_PORT: { type: "int", default: 7567 }, FS_INTERFACE: { type: "string", default: "::" }, FS_SSL_CERT: { type: "string", default: "" }, FS_SSL_KEY: { type: "string", default: "" }, FS_URL_PREFIX: { type: "string", default: "" }, FS_LOG_FILE: { type: "path", default: "" }, FS_ACCESS_LOG_FILE: { type: "path", default: "" }, UI_WORKER_PROCESSES: { type: "int", default: 0 }, UI_PORT: { type: "int", default: 3000 }, UI_INTERFACE: { type: "string", default: "::" }, UI_SSL_CERT: { type: "string", default: "" }, UI_SSL_KEY: { type: "string", default: "" }, UI_LOG_FILE: { type: "path", default: "" }, UI_ACCESS_LOG_FILE: { type: "path", default: "" }, UI_JWT_SECRET: { type: "string", default: "" }, UDP_CONNECTION_REQUEST_PORT: { type: "int", default: 0 }, FORWARDED_HEADER: { type: "string", default: "" }, DOWNLOAD_TIMEOUT: { type: "int", default: 3600 }, EXT_TIMEOUT: { type: "int", default: 3000 }, MAX_CACHE_TTL: { type: "int", default: 86400 }, DEBUG_FILE: { type: "path", default: "" }, DEBUG_FORMAT: { type: "string", default: "yaml" }, DEBUG: { type: "bool", default: false }, RETRY_DELAY: { type: "int", default: 300 }, SESSION_TIMEOUT: { type: "int", default: 30 }, CONNECTION_REQUEST_TIMEOUT: { type: "int", default: 2000 }, GPN_NEXT_LEVEL: { type: "int", default: 0 }, GPV_BATCH_SIZE: { type: "int", default: 32 }, MAX_DEPTH: { type: "int", default: 16 }, COOKIES_PATH: { type: "string" }, LOG_FORMAT: { type: "string", default: "simple" }, ACCESS_LOG_FORMAT: { type: "string", default: "" }, MAX_CONCURRENT_REQUESTS: { type: "int", default: 20 }, DATETIME_MILLISECONDS: { type: "bool", default: true }, BOOLEAN_LITERAL: { type: "bool", default: true }, CONNECTION_REQUEST_ALLOW_BASIC_AUTH: { type: "bool", default: false }, MAX_COMMIT_ITERATIONS: { type: "int", default: 32 }, // Should probably never be changed DEVICE_ONLINE_THRESHOLD: { type: "int", default: 4000 }, XMPP_JID: { type: "string", default: "" }, XMPP_PASSWORD: { type: "string", default: "" }, }; const allConfig: { [name: string]: string | number } = {}; function setConfig(name, value, commandLineArgument = false): boolean { if (allConfig[name] != null) return true; // For compatibility with v1.1 if (name === "CONFIG_DIR" || name === "config-dir") configDir = configDir || resolve(ROOT_DIR, value); if (name === "CWMP_SSL" || name === "cwmp-ssl") cwmpSsl = cwmpSsl || String(value).toLowerCase().trim(); if (name === "NBI_SSL" || name === "nbi-ssl") nbiSsl = nbiSsl || String(value).toLowerCase().trim(); if (name === "FS_SSL" || name === "fs-ssl") fsSsl = fsSsl || String(value).toLowerCase().trim(); if (name === "UI_SSL" || name === "ui-ssl") uiSsl = uiSsl || String(value).toLowerCase().trim(); if (name === "FS_HOSTNAME" || name === "fs-hostname") fsHostname = fsHostname || String(value).trim(); // For compatibility with v1.0 if (name === "PRESETS_CACHE_DURATION" || name === "presets-cache-duration") setConfig("MAX_CACHE_TTL", value); if ( name === "GET_PARAMETER_NAMES_DEPTH_THRESHOLD" || name === "get-parameter-names-depth-threshold" ) setConfig("GPN_NEXT_LEVEL", value); if ( name === "TASK_PARAMETERS_BATCH_SIZE" || name === "task-parameters-batch-size" ) setConfig("GPV_BATCH_SIZE", value); if (name === "FS_IP" || name === "fs-ip") setConfig("FS_HOSTNAME", value); function cast(val, type): string | number | boolean { switch (type) { case "int": return Number(val); case "bool": return ["true", "1"].includes(String(val).trim().toLowerCase()); case "string": return String(val); case "path": if (!val) return ""; return resolve(val); default: return null; } } let _value = null; for (const [optionName, optionDetails] of Object.entries(options)) { let n = optionName; if (commandLineArgument) n = n.toLowerCase().replace(/_/g, "-"); if (name === n) { _value = cast(value, optionDetails.type); n = optionName; } else if (name.startsWith(`${n}-`)) { _value = cast(value, optionDetails.type); n = `${optionName}-${name.slice(optionName.length + 1)}`; } if (_value != null) { allConfig[n] = _value; // Save as environmnet variable to pass on to any child process process.env[`GENIEACS_${n}`] = _value; return true; } } return false; } // Command line arguments const argv = process.argv.slice(2); while (argv.length) { const arg = argv.shift(); if (arg[0] === "-") { const v = argv.shift(); setConfig(arg.slice(2), v, true); } } // Environment variable for (const [k, v] of Object.entries(process.env)) if (k.startsWith("GENIEACS_")) setConfig(k.slice(9), v); // Configuration file const configFilename = configDir ? `${configDir}/config.json` : `${ROOT_DIR}/config/config.json`; if (existsSync(configFilename)) { const configFile = JSON.parse(readFileSync(configFilename).toString()); for (const [k, v] of Object.entries(configFile)) { if (!setConfig(k, v)) // Pass as environment variable to be accessable by extensions process.env[`GENIEACS_${k}`] = `${v}`; } } if (configDir) setConfig("EXT_DIR", `${configDir}/ext`); if (["true", "1"].includes(cwmpSsl)) { const d = configDir || `${ROOT_DIR}/config`; setConfig("CWMP_SSL_CERT", `${d}/cwmp.crt`); setConfig("CWMP_SSL_KEY", `${d}/cwmp.key`); } if (["true", "1"].includes(nbiSsl)) { const d = configDir || `${ROOT_DIR}/config`; setConfig("NBI_SSL_CERT", `${d}/cwmp.crt`); setConfig("NBI_SSL_KEY", `${d}/cwmp.key`); } if (["true", "1"].includes(fsSsl)) { const d = configDir || `${ROOT_DIR}/config`; setConfig("FS_SSL_CERT", `${d}/cwmp.crt`); setConfig("FS_SSL_KEY", `${d}/cwmp.key`); } if (["true", "1"].includes(uiSsl)) { const d = configDir || `${ROOT_DIR}/config`; setConfig("UI_SSL_CERT", `${d}/cwmp.crt`); setConfig("UI_SSL_KEY", `${d}/cwmp.key`); } if (fsHostname) { const FS_PORT = allConfig["FS_PORT"] || 7567; const FS_SSL = !!allConfig["FS_SSL_CERT"]; setConfig( "FS_URL_PREFIX", (FS_SSL ? "https" : "http") + `://${fsHostname}:${FS_PORT}/`, ); } // Defaults for (const [k, v] of Object.entries(options)) if (v["default"] != null) setConfig(k, v["default"]); export function get( optionName: string, deviceId?: string, ): string | number | boolean { if (!deviceId) return allConfig[optionName]; optionName = `${optionName}-${deviceId}`; let v = allConfig[optionName]; if (v != null) return v; let i = optionName.lastIndexOf("-"); v = allConfig[optionName.slice(0, i)]; if (v != null) return v; i = optionName.lastIndexOf("-", i - 1); v = allConfig[optionName.slice(0, i)]; if (v != null) return v; i = optionName.lastIndexOf("-", i - 1); v = allConfig[optionName.slice(0, i)]; if (v != null) return v; i = optionName.lastIndexOf("-", i - 1); if (i > 0) { v = allConfig[optionName.slice(0, i)]; if (v != null) return v; } return null; } export function getDefault(optionName: string): string | number | boolean { const option = options[optionName]; if (!option) return null; let val = option["default"]; if (val && option.type === "path") val = resolve(val); return val; } ================================================ FILE: lib/connection-request.ts ================================================ import * as crypto from "node:crypto"; import * as dgram from "node:dgram"; import * as http from "node:http"; import Expression, { Value } from "./common/expression.ts"; import * as auth from "./auth.ts"; import * as extensions from "./extensions.ts"; import * as debug from "./debug.ts"; import XmppClient from "./xmpp-client.ts"; import * as config from "../lib/config.ts"; import { encodeEntities, parseAttrs, Element } from "./xml-parser.ts"; import * as logger from "../lib/logger.ts"; async function extractAuth( exp: Expression, dflt: Value, ): Promise<[string, string, Expression]> { let username: string, password: string; const _exp = await exp.evaluateAsync( async (e: Expression): Promise => { if (e instanceof Expression.Parameter) return new Expression.Literal(null); if (e instanceof Expression.FunctionCall) { if (e.name === "NOW") return new Expression.Literal(0); if (!username) { if (e.name === "EXT") { if (!e.args.every((a) => a instanceof Expression.Literal)) return new Expression.Literal(null); const args = e.args.map((a) => a.value.toString()); if (typeof args[0] !== "string" || typeof args[1] !== "string") return new Expression.Literal(null); const { fault, value } = await extensions.run(args); if (fault) return new Expression.Literal(null); return new Expression.Literal(value); } else if (e.name === "AUTH") { if (e.args.every((a) => a instanceof Expression.Literal)) { username = `${e.args[0].value ?? ""}`; password = `${e.args[1].value ?? ""}`; } return new Expression.Literal(dflt); } } } return e; }, ); return [username, password, _exp]; } function httpGet( url: URL, options: http.RequestOptions, _debug: boolean, deviceId: string, ): Promise<{ statusCode: number; headers: http.IncomingHttpHeaders }> { return new Promise((resolve, reject) => { const req = http .get(url, options, (res) => { res.resume(); resolve({ statusCode: res.statusCode, headers: res.headers }); if (_debug) { debug.outgoingHttpRequest(req, deviceId, "GET", url, null); debug.incomingHttpResponse(res, deviceId, null); } }) .on("error", (err) => { req.destroy(); reject(err); if (_debug) debug.outgoingHttpRequestError(req, deviceId, "GET", url, err); }) .on("timeout", () => { req.destroy(); }); }); } export async function httpConnectionRequest( address: string, authExp: Expression, allowBasicAuth: boolean, timeout: number, _debug: boolean, deviceId: string, ): Promise { const url = new URL(address); if (url.protocol !== "http:") return "Invalid connection request URL or protocol"; const options: http.RequestOptions = { agent: new http.Agent({ maxSockets: 1, keepAlive: true, timeout: timeout }), }; let authHeader: Record; let username: string; let password: string; while (!authHeader || (username != null && password != null)) { let opts = options; if (authHeader) { if (authHeader["method"] === "Basic") { if (!allowBasicAuth) return "Basic HTTP authentication not allowed"; opts = Object.assign( { headers: { Authorization: auth.basic(username || "", password || ""), }, }, options, ); } else if (authHeader["method"] === "Digest") { opts = Object.assign( { headers: { Authorization: auth.solveDigest( username, password, url.pathname + url.search, "GET", null, authHeader, ), }, }, options, ); } else { return "Unrecognized auth method"; } } let res: { statusCode: number; headers: http.IncomingHttpHeaders }; try { res = await httpGet(url, opts, _debug, deviceId); } catch (err) { // Workaround for some devices unexpectedly closing the connection if (authHeader) { try { res = await httpGet(url, opts, _debug, deviceId); } catch (err) { return `Connection request error: ${err.message}`; } } if (err["code"] === "ECONNRESET" || err["code"] === "ECONNREFUSED") return "Device is offline"; return `Connection request error: ${err.message}`; } if (res.statusCode === 200 || res.statusCode === 204) return ""; // When a Connection Request is received for the Virtual CWMP Device and the Proxied // Device is offline the CPE Proxier MUST respond with an HTTP 503 failure if (res.statusCode === 503) return "Device is offline"; if (res.statusCode === 401 && res.headers["www-authenticate"]) { try { authHeader = auth.parseWwwAuthenticateHeader( res.headers["www-authenticate"], ); } catch { return "Connection request error: Error parsing www-authenticate header"; } [username, password, authExp] = await extractAuth(authExp, false); } else { return `Connection request error: Unexpected status code ${res.statusCode}`; } } return "Connection request error: Incorrect connection request credentials"; } export async function udpConnectionRequest( host: string, port: number, authExp: Expression, sourcePort = 0, _debug: boolean, deviceId: string, ): Promise { const now = Date.now(); const client = dgram.createSocket({ type: "udp4", reuseAddr: true }); // When a device is NAT'ed, the UDP Connection Request must originate from // the same address and port used by the STUN server, in order to traverse // the firewall. This does require that the Genieacs NBI and STUN server // are allowed to bind to the same address and port. The STUN server needs // to open its UDP port with the SO_REUSEADDR option, allowing the NBI to // also bind to the same port. if (sourcePort) client.bind({ port: sourcePort, exclusive: true }); let username: string; let password: string; [username, password, authExp] = await extractAuth(authExp, null); if (username == null) username = ""; if (password == null) password = ""; while (username != null && password != null) { const ts = Math.trunc(now / 1000); const id = Math.trunc(Math.random() * 4294967295); const cn = crypto.randomBytes(8).toString("hex"); const sig = crypto .createHmac("sha1", password) .update(`${ts}${id}${username}${cn}`) .digest("hex"); const uri = `http://${host}:${port}?ts=${ts}&id=${id}&un=${username}&cn=${cn}&sig=${sig}`; const msg = `GET ${uri} HTTP/1.1\r\nHost: ${host}:${port}\r\n\r\n`; const message = Buffer.from(msg); for (let i = 0; i < 3; ++i) { await new Promise((resolve, reject) => { client.send(message, 0, message.length, port, host, (err: Error) => { if (err) reject(err); else resolve(); if (_debug) debug.outgoingUdpMessage(host, deviceId, port, msg); }); }); } [username, password, authExp] = await extractAuth(authExp, null); } client.close(); } const XMPP_JID = config.get("XMPP_JID") as string; const XMPP_PASSWORD = config.get("XMPP_PASSWORD") as string; const XMPP_RESOURCE = crypto.randomBytes(8).toString("hex"); let xmppClient: XmppClient; function xmppClientOnError(err: Error): void { xmppClient = null; logger.error({ message: "XMPP exception", exception: err, pid: process.pid, }); } function xmppClientOnClose(): void { xmppClient = null; } export async function xmppConnectionRequest( jid: string, authExp: Expression, timeout: number, _debug: boolean, deviceId: string, ): Promise { if (!xmppClient) { const [host, username] = XMPP_JID.split("@").reverse(); xmppClient = await XmppClient.connect({ host, username, resource: XMPP_RESOURCE, password: XMPP_PASSWORD, timeout: 120000, }); xmppClient.on("error", xmppClientOnError); xmppClient.on("close", xmppClientOnClose); xmppClient.unref(); } let username: string; let password: string; [username, password, authExp] = await extractAuth(authExp, null); while (username != null && password != null) { const msg = `${encodeEntities( username, )}${encodeEntities( password, )}`; let res: Element, rawRes: string, rawReq: string; try { ({ res, rawRes, rawReq } = await xmppClient.sendIqStanza( XMPP_JID, jid, "get", msg, timeout, )); } catch (err) { return err.message; } if (_debug) { debug.outgoingXmppStanza(deviceId, rawReq); debug.incomingXmppStanza(deviceId, rawRes); } const attrs = parseAttrs(res.attrs); const type = attrs.find((a) => a.name === "type"); if (type && type.value === "result") return ""; const error = res.children.find((c) => c.name === "error"); if (!error || !error.children[0]) return "Unexpected XMPP connection request response"; if (error.children[0].name === "service-unavailable") return "Device is offline"; if (error.children[0].name !== "not-authorized") return "Unexpected XMPP connection request response"; [username, password, authExp] = await extractAuth(authExp, null); } return "Incorrect connection request credentials"; } ================================================ FILE: lib/cwmp/db.ts ================================================ import { ObjectId } from "mongodb"; import { decodeTag, encodeTag, escapeRegExp } from "../util.ts"; import { DeviceData, Attributes, SessionFault, Task, Operation, } from "../types.ts"; import { collections } from "../db/db.ts"; import { optimizeProjection } from "../db/util.ts"; import * as MongoTypes from "../db/types.ts"; const INVALID_PATH_SUFFIX = "__invalid"; function compareAccessLists(list1: string[], list2: string[]): boolean { if (list1.length !== list2.length) return false; for (const [i, v] of list1.entries()) if (v !== list2[i]) return false; return true; } export async function fetchDevice( id: string, timestamp: number, ): Promise<[string, number, Attributes?][]> { const res: [string, number, Attributes?][] = [ ["Events", timestamp, { object: [timestamp, 1], writable: [timestamp, 0] }], [ "DeviceID", timestamp, { object: [timestamp, 1], writable: [timestamp, 0] }, ], ]; const device = (await collections.devices.findOne({ _id: id })) as any; if (!device) return null; function storeParams( obj, path: string, pathLength: number, ts: number, ): void { if (obj["_timestamp"]) obj["_timestamp"] = +obj["_timestamp"]; if (obj["_attributesTimestamp"]) obj["_attributesTimestamp"] = +obj["_attributesTimestamp"]; const attrs: Attributes = {}; let t = obj["_timestamp"] || 1; if (ts > t) t = ts; if (obj["_value"] != null) { attrs.value = [obj["_timestamp"] || 1, [obj["_value"], obj["_type"]]]; if (obj["_type"] === "xsd:dateTime" && obj["_value"] instanceof Date) attrs.value[1][0] = +attrs.value[1][0]; obj["_object"] = false; } if (obj["_writable"] != null) attrs.writable = [ts || 1, obj["_writable"] ? 1 : 0]; if (obj["_object"] != null) attrs.object = [t, obj["_object"] ? 1 : 0]; if (obj["_notification"] != null) { attrs.notification = [ obj["_attributesTimestamp"] || 1, obj["_notification"], ]; } if (obj["_accessList"] != null) attrs.accessList = [obj["_attributesTimestamp"] || 1, obj["_accessList"]]; try { res.push([path, t, attrs]); } catch { // The path parser is now more strict so we might be in a situation where // the database contains invalid paths from before this change So here we // encode the invalid characters. const splits = path.split("."); splits[splits.length - 1] = encodeTag(splits[splits.length - 1]) + INVALID_PATH_SUFFIX; path = splits.join("."); res.push([path, t, attrs]); return; } for (const [k, v] of Object.entries(obj)) { if (!k.startsWith("_")) { obj["_object"] = true; storeParams(v, `${path}.${k}`, pathLength + 1, obj["_timestamp"]); } } if (obj["_object"] && obj["_timestamp"]) res.push([path + ".*", obj["_timestamp"]]); } const ts: number = +device["_timestamp"] || 0; if (ts) res.push(["*", ts]); for (const [k, v] of Object.entries(device)) { switch (k) { case "_lastInform": res.push([ "Events.Inform", +v, { object: [+v, 0], writable: [+v, 0], value: [+v, [+v, "xsd:dateTime"]], }, ]); break; case "_lastBoot": res.push([ "Events.1_BOOT", +v, { object: [+v, 0], writable: [+v, 0], value: [+v, [+v, "xsd:dateTime"]], }, ]); break; case "_lastBootstrap": res.push([ "Events.0_BOOTSTRAP", +v, { object: [+v, 0], writable: [+v, 0], value: [+v, [+v, "xsd:dateTime"]], }, ]); break; case "_registered": // Use current timestamp for registered event attribute timestamps res.push([ "Events.Registered", timestamp, { object: [timestamp, 0], writable: [timestamp, 0], value: [timestamp, [+v, "xsd:dateTime"]], }, ]); break; case "_id": res.push([ "DeviceID.ID", timestamp, { object: [timestamp, 0], writable: [timestamp, 0], value: [timestamp, [v as string, "xsd:string"]], }, ]); break; case "_tags": if ((v as string[]).length) { res.push([ "Tags", timestamp, { object: [timestamp, 1], writable: [timestamp, 0] }, ]); } for (const t of v as string[]) { res.push([ "Tags." + encodeTag(t), timestamp, { object: [timestamp, 0], writable: [timestamp, 1], value: [timestamp, [true, "xsd:boolean"]], }, ]); } break; case "_deviceId": if (v["_Manufacturer"] != null) { res.push([ "DeviceID.Manufacturer", timestamp, { object: [timestamp, 0], writable: [timestamp, 0], value: [timestamp, [v["_Manufacturer"], "xsd:string"]], }, ]); } if (v["_OUI"] != null) { res.push([ "DeviceID.OUI", timestamp, { object: [timestamp, 0], writable: [timestamp, 0], value: [timestamp, [v["_OUI"], "xsd:string"]], }, ]); } if (v["_ProductClass"] != null) { res.push([ "DeviceID.ProductClass", timestamp, { object: [timestamp, 0], writable: [timestamp, 0], value: [timestamp, [v["_ProductClass"], "xsd:string"]], }, ]); } if (v["_SerialNumber"] != null) { res.push([ "DeviceID.SerialNumber", timestamp, { object: [timestamp, 0], writable: [timestamp, 0], value: [timestamp, [v["_SerialNumber"], "xsd:string"]], }, ]); } break; default: if (!k.startsWith("_")) storeParams(v, k, 1, ts); } } return res; } export async function saveDevice( deviceId: string, deviceData: DeviceData, isNew: boolean, sessionTimestamp: number, ): Promise { const update = { $set: {}, $unset: {}, $addToSet: {}, $pull: {} }; for (const diff of deviceData.timestamps.diff()) { if (diff[0].wildcard !== 1 << (diff[0].length - 1)) continue; if ( diff[0].segments[0] === "Events" || diff[0].segments[0] === "DeviceID" || diff[0].segments[0] === "Tags" ) continue; const parent = deviceData.paths.get(diff[0].slice(0, -1).toString()); // Param timestamps may be greater than session timestamp to track revisions if (diff[2] > sessionTimestamp) diff[2] = sessionTimestamp; if (diff[2] == null && diff[1] != null) { update["$unset"][ parent.length ? parent.toString() + "._timestamp" : "_timestamp" ] = 1; } else { if (parent && (!parent.length || deviceData.attributes.has(parent))) { update["$set"][ parent.length ? parent.toString() + "._timestamp" : "_timestamp" ] = new Date(diff[2]); } } } for (const diff of deviceData.attributes.diff()) { const path = diff[0]; const value1 = (((diff[1] || {}).value || [])[1] || [])[0]; const value2 = (((diff[2] || {}).value || [])[1] || [])[0]; const valueType1 = (((diff[1] || {}).value || [])[1] || [])[1]; const valueType2 = (((diff[2] || {}).value || [])[1] || [])[1]; const valueTimestamp1 = ((diff[1] || {}).value || [])[0]; const valueTimestamp2 = ((diff[2] || {}).value || [])[0]; const object1 = ((diff[1] || {}).object || [])[1]; const object2 = ((diff[2] || {}).object || [])[1]; const writable2 = ((diff[2] || {}).writable || [])[1]; const writable1 = ((diff[1] || {}).writable || [])[1]; const attributesTimestamp1 = ((diff[1] || {}).notification || [])[0]; const attributesTimestamp2 = ((diff[2] || {}).notification || [])[0]; const notification1 = ((diff[1] || {}).notification || [])[1]; const notification2 = ((diff[2] || {}).notification || [])[1]; const accessList1 = ((diff[1] || {}).accessList || [])[1]; const accessList2 = ((diff[2] || {}).accessList || [])[1]; switch (path.segments[0]) { case "Events": if (path.length === 2 && value2 !== value1) { if (!diff[2]) { switch (path.segments[1]) { case "Inform": update["$unset"]["_lastInform"] = 1; break; case "1_BOOT": update["$unset"]["_lastBoot"] = 1; break; case "0_BOOTSTRAP": update["$unset"]["_lastBootstrap"] = 1; break; case "Registered": update["$unset"]["_registered"] = 1; } } else { const t = new Date(diff[2].value[1][0] as number); switch (path.segments[1]) { case "Inform": update["$set"]["_lastInform"] = t; break; case "1_BOOT": update["$set"]["_lastBoot"] = t; break; case "0_BOOTSTRAP": update["$set"]["_lastBootstrap"] = t; break; case "Registered": update["$set"]["_registered"] = t; } } } break; case "DeviceID": if (value2 !== value1) { const v = diff[2].value[1][0]; switch (path.segments[1]) { case "ID": update["$set"]["_id"] = v; break; case "Manufacturer": update["$set"]["_deviceId._Manufacturer"] = v; break; case "OUI": update["$set"]["_deviceId._OUI"] = v; break; case "ProductClass": update["$set"]["_deviceId._ProductClass"] = v; break; case "SerialNumber": update["$set"]["_deviceId._SerialNumber"] = v; } } break; case "Tags": if (value2 !== value1) { if (value2 != null) { if (!update["$addToSet"]["_tags"]) update["$addToSet"]["_tags"] = { $each: [] }; update["$addToSet"]["_tags"]["$each"].push( decodeTag(path.segments[1] as string), ); } else { if (!update["$pull"]["_tags"]) { update["$pull"]["_tags"] = { $in: [], }; } update["$pull"]["_tags"]["$in"].push( decodeTag(path.segments[1] as string), ); } } break; default: if (!diff[2]) { let pathStr = path.toString(); // Paths with that suffix are encoded and need to be decoded if (pathStr.endsWith(INVALID_PATH_SUFFIX)) { const splits = pathStr.split("."); splits[splits.length - 1] = decodeTag( splits[splits.length - 1].slice( 0, 0 - INVALID_PATH_SUFFIX.length, ), ); pathStr = splits.join("."); } update["$unset"][pathStr] = 1; continue; } for (const attrName of Object.keys(diff[2])) { // Param timestamps may be greater than session timestamp to track revisions if (diff[2][attrName][0] > sessionTimestamp) diff[2][attrName][0] = sessionTimestamp; if (diff[2][attrName][1] != null) { switch (attrName) { case "value": if (value2 !== value1) { if ( valueType2 === "xsd:dateTime" && Number.isInteger(value2 as number) ) { update["$set"][path.toString() + "._value"] = new Date( value2 as number, ); } else { update["$set"][path.toString() + "._value"] = value2; } } if (valueType2 !== valueType1) update["$set"][path.toString() + "._type"] = valueType2; if (valueTimestamp2 !== valueTimestamp1) { update["$set"][path.toString() + "._timestamp"] = new Date( valueTimestamp2, ); } break; case "object": if (!diff[1]?.object || object2 !== object1) { update["$set"][ path.length ? path.toString() + "._object" : "_object" ] = !!object2; } break; case "writable": if (!diff[1]?.writable || writable2 !== writable1) { update["$set"][ path.length ? path.toString() + "._writable" : "_writable" ] = !!writable2; } break; case "notification": if ( !diff[1] || !diff[1].notification || notification2 !== notification1 ) { update["$set"][ path.length ? path.toString() + "._notification" : "_notification" ] = notification2; } if (attributesTimestamp2 !== attributesTimestamp1) { update["$set"][path.toString() + "._attributesTimestamp"] = new Date(attributesTimestamp2); } break; case "accessList": if ( !diff[1] || !diff[1].accessList || !compareAccessLists(accessList2, accessList1) ) { update["$set"][ path.length ? path.toString() + "._accessList" : "_accessList" ] = accessList2; } if (attributesTimestamp2 !== attributesTimestamp1) { update["$set"][path.toString() + "._attributesTimestamp"] = new Date(attributesTimestamp2); } } } } if (diff[1]) { for (const attrName of Object.keys(diff[1])) { if ( diff[1][attrName][1] != null && diff[2]?.[attrName]?.[1] == null ) { const p = path.length ? path.toString() + "." : ""; update["$unset"][`${p}_${attrName}`] = 1; if (attrName === "value") { update["$unset"][p + "_type"] = 1; update["$unset"][p + "_timestamp"] = 1; } else if (attrName === "notification") { if (accessList2 == null) update["$unset"][`${p}_attributesTimestamp`] = 1; } else if (attrName === "accessList") { if (notification2 == null) update["$unset"][`${p}_attributesTimestamp`] = 1; } } } } } } update["$unset"] = optimizeProjection(update["$unset"]); // Remove overlap possibly caused by parameters changing from objects // to regular parameters or vice versa. Reason being that _timestamp // represents two different things depending on whether the parameter // is an object or not. for (const k of Object.keys(update["$unset"])) if (update["$set"][k] != null) delete update["$unset"][k]; // Remove empty keys for (const [k, v] of Object.entries(update)) { if (k === "$addToSet") { for (const [kk, vv] of Object.entries(v)) if (!vv["$each"].length) delete v[kk]; } else if (k === "$pull") { for (const [kk, vv] of Object.entries(v)) if (!vv["$in"].length) delete v[kk]; } if (!Object.keys(v).length) delete update[k]; } if (!Object.keys(update).length) return; // Mongo doesn't allow $addToSet and $pull at the same time let update2; if (update["$addToSet"] && update["$pull"]) { update2 = { $pull: update["$pull"] }; delete update["$pull"]; } const result = await collections.devices.updateOne( { _id: deviceId }, update, { upsert: isNew, }, ); if (!result.matchedCount && !result.upsertedCount) throw new Error(`Device ${deviceId} not found in database`); if (update2) { await collections.devices.updateOne({ _id: deviceId }, update2); return; } } export async function getFaults( deviceId: string, ): Promise<{ [channel: string]: SessionFault }> { const res = await collections.faults .find({ _id: { $regex: `^${escapeRegExp(deviceId)}\\:` } }) .toArray(); const faults: { [channel: string]: SessionFault } = {}; for (const r of res) { const channel = r._id.slice(deviceId.length + 1); const fault: SessionFault = { code: r.code, message: r.message, ...(r.detail && { detail: r.detail }), timestamp: +r.timestamp, provisions: JSON.parse(r.provisions), retries: r.retries, ...(r.expiry && { expiry: +r.expiry }), }; faults[channel] = fault; } return faults; } export async function saveFault( deviceId: string, channel: string, fault: SessionFault, ): Promise { const id = `${deviceId}:${channel}`; const f: MongoTypes.Fault = { _id: id, device: deviceId, channel: channel, timestamp: new Date(fault.timestamp), code: fault.code, message: fault.message, ...(fault.detail && { detail: fault.detail }), retries: fault.retries, ...(fault.expiry && { expiry: new Date(fault.expiry) }), provisions: JSON.stringify(fault.provisions), }; await collections.faults.replaceOne({ _id: id }, f, { upsert: true }); } export async function deleteFault( deviceId: string, channel: string, ): Promise { await collections.faults.deleteOne({ _id: `${deviceId}:${channel}` }); } export async function getDueTasks( deviceId: string, timestamp: number, ): Promise<[Task[], number]> { const cur = collections.tasks .find({ device: deviceId }) .sort({ timestamp: 1 }); const tasks = [] as Task[]; for await (const t of cur) { if (+t.timestamp >= timestamp) return [tasks, +t.timestamp]; const task: Task = { _id: t._id.toString(), name: t.name, ...(t.timestamp && { timestamp: +t.timestamp }), ...(t.expiry && { expiry: +t.expiry }), ...(t.name === "getParameterValues" && { parameterNames: t.parameterNames, }), ...(t.name === "setParameterValues" && { parameterValues: t.parameterValues, }), ...(t.name === "refreshObject" && { objectName: t.objectName, }), ...(t.name === "download" && { fileType: t.fileType, fileName: t.fileName, targetFileName: t.targetFileName, }), ...(t.name === "addObject" && { objectName: t.objectName, parameterValues: t.parameterValues, }), ...(t.name === "deleteObject" && { objectName: t.objectName, }), ...(t.name === "provisions" && { provisions: t.provisions, }), }; tasks.push(task); // For API compatibility if (task.name === "download" && t["file"]) { let q; if (ObjectId.isValid(t["file"])) q = { _id: { $in: [t["file"], new ObjectId(t["file"])] } }; else q = { _id: t["file"] }; const res = await collections.files.find(q).toArray(); if (res[0]) { if (!task.fileType) task.fileType = res[0].metadata.fileType; if (!task.fileName) task.fileName = res[0].filename || res[0]._id.toString(); } } } return [tasks, null]; } export async function clearTasks( deviceId: string, taskIds: string[], ): Promise { await collections.tasks.deleteMany({ _id: { $in: taskIds.map((id) => new ObjectId(id)) }, }); } export async function getOperations( deviceId: string, ): Promise<{ [commandKey: string]: Operation }> { const res = await collections.operations .find({ _id: { $regex: `^${escapeRegExp(deviceId)}\\:` } }) .toArray(); const operations: { [commandKey: string]: Operation } = {}; for (const r of res) { const commandKey = r._id.slice(deviceId.length + 1); // Workaround for a bug in v1.2.1 where operation object is saved without deserialization if (typeof r.provisions !== "string") { delete r._id; operations[commandKey] = r as unknown as Operation; continue; } const operation: Operation = { name: r.name, timestamp: +r.timestamp, channels: typeof r.channels === "string" ? JSON.parse(r.channels) : r.channels, retries: JSON.parse(r.retries), provisions: JSON.parse(r.provisions), ...(r.args && { args: JSON.parse(r.args) }), }; operations[commandKey] = operation; } return operations; } export async function saveOperation( deviceId: string, commandKey: string, operation: Operation, ): Promise { const id = `${deviceId}:${commandKey}`; const o: MongoTypes.Operation = { _id: id, name: operation.name, timestamp: new Date(operation.timestamp), channels: JSON.stringify(operation.channels), provisions: JSON.stringify(operation.provisions), retries: JSON.stringify(operation.retries), args: JSON.stringify(operation.args), }; await collections.operations.replaceOne({ _id: id }, o, { upsert: true, }); } export async function deleteOperation( deviceId: string, commandKey: string, ): Promise { await collections.operations.deleteOne({ _id: `${deviceId}:${commandKey}` }); } ================================================ FILE: lib/cwmp/local-cache.ts ================================================ import * as vm from "node:vm"; import * as crypto from "node:crypto"; import { collections } from "../db/db.ts"; import { convertOldPrecondition } from "../db/util.ts"; import * as logger from "../logger.ts"; import * as scheduling from "../scheduling.ts"; import Expression, { Value } from "../common/expression.ts"; import { Preset, Provisions, VirtualParameters, Files, Config, } from "../types.ts"; import { LocalCache } from "../local-cache.ts"; interface Snapshot { presets: Preset[]; provisions: Provisions; virtualParameters: VirtualParameters; files: Files; config: Config; } function flattenObject>( src: T, prefix = "", dst = {} as T, ): T { for (const k of Object.keys(src)) { const v = src[k]; if (typeof v === "object" && !Array.isArray(v)) flattenObject(v as T, `${prefix}${k}.`, dst); else dst[`${prefix}${k}`] = v; } return dst; } async function fetchPresets(): Promise<[string, Preset[]]> { const res = await collections.presets.find().toArray(); let objects = await collections.objects.find().toArray(); res.sort((a, b) => (a._id > b._id ? 1 : -1)); objects.sort((a, b) => (a._id > b._id ? 1 : -1)); const h = crypto .createHash("md5") .update(JSON.stringify(res)) .update(JSON.stringify(objects)) .digest("hex"); objects = objects.map((obj) => { // Flatten object obj = flattenObject(obj); // If no keys are defined, consider all parameters as keys to keep the // same behavior from v1.0 if (!obj["_keys"]?.length) obj["_keys"] = Object.keys(obj).filter((k) => !k.startsWith("_")); return obj; }); res.sort((a, b) => { if (a["weight"] === b["weight"]) return a["_id"] > b["_id"] ? 1 : a["_id"] < b["_id"] ? -1 : 0; else return a["weight"] - b["weight"]; }); const presets = [] as Preset[]; for (const preset of res) { let schedule: { md5: string; duration: number; schedule: any } = null; if (preset["schedule"]) { const parts = preset["schedule"].trim().split(/\s+/); schedule = { md5: crypto.createHash("md5").update(preset["schedule"]).digest("hex"), duration: null, schedule: null, }; try { schedule.duration = +parts.shift() * 1000; schedule.schedule = scheduling.parseCron(parts.join(" ")); } catch { logger.warn({ message: "Invalid preset schedule", preset: preset["_id"], schedule: preset["schedule"], }); schedule.schedule = false; } } const events = preset["events"] || {}; let precondition: Expression = new Expression.Literal(true); if (preset["precondition"]) { try { precondition = Expression.parse(preset["precondition"]); } catch { precondition = convertOldPrecondition( JSON.parse(preset["precondition"]), ); } // Simplify expression precondition = precondition.evaluate((e) => e); } const _provisions: Preset["provisions"] = []; // Generate provisions from the old configuration format for (const c of preset.configurations) { switch (c.type) { case "age": _provisions.push([ "refresh", new Expression.Literal(c.name), new Expression.Literal(+c.age), ]); break; case "value": _provisions.push([ "value", new Expression.Literal(c.name), new Expression.Literal(c.value), ]); break; case "add_tag": _provisions.push([ "tag", new Expression.Literal(c.tag), new Expression.Literal(true), ]); break; case "delete_tag": _provisions.push([ "tag", new Expression.Literal(c.tag), new Expression.Literal(false), ]); break; case "provision": _provisions.push([ c.name, ...(c.args || []).map((a) => Expression.parse(a)), ]); break; case "add_object": for (const obj of objects) { if (obj["_id"] === c.object) { const alias = obj["_keys"] .map((k) => `${k}:${JSON.stringify(obj[k])}`) .join(","); const p = `${c.name}.[${alias}]`; _provisions.push([ "instances", new Expression.Literal(p), new Expression.Literal(1), ]); for (const k in obj) { if (!k.startsWith("_") && !(obj["_keys"].indexOf(k) !== -1)) _provisions.push([ "value", new Expression.Literal(`${p}.${k}`), new Expression.Literal(obj[k]), ]); } } } break; case "delete_object": for (const obj of objects) { if (obj["_id"] === c.object) { const alias = obj["_keys"] .map((k) => `${k}:${JSON.stringify(obj[k])}`) .join(","); const p = `${c.name}.[${alias}]`; _provisions.push([ "instances", new Expression.Literal(p), new Expression.Literal(0), ]); } } break; default: { const exhaustiveCheck: never = c; throw new Error( `Unknown configuration type ${exhaustiveCheck["type"]}`, ); } } } presets.push({ name: preset["_id"], channel: (preset["channel"] as string) || "default", schedule: schedule, events: events, precondition: precondition, provisions: _provisions, }); } return [h, presets]; } async function fetchProvisions(): Promise<[string, Provisions]> { const res = await collections.provisions.find().toArray(); res.sort((a, b) => (a._id > b._id ? 1 : -1)); const h = crypto.createHash("md5").update(JSON.stringify(res)).digest("hex"); const provisions = {}; for (const r of res) { provisions[r._id] = {}; provisions[r._id].md5 = crypto .createHash("md5") .update(r.script) .digest("hex"); provisions[r._id].script = new vm.Script( `"use strict";(function(){\n${r.script}\n})();`, { filename: r._id, lineOffset: -1 }, ); } return [h, provisions]; } async function fetchVirtualParameters(): Promise<[string, VirtualParameters]> { const res = await collections.virtualParameters.find().toArray(); res.sort((a, b) => (a._id > b._id ? 1 : -1)); const h = crypto.createHash("md5").update(JSON.stringify(res)).digest("hex"); const virtualParameters = {}; for (const r of res) { virtualParameters[r._id] = {}; virtualParameters[r._id].md5 = crypto .createHash("md5") .update(r.script) .digest("hex"); virtualParameters[r._id].script = new vm.Script( `"use strict";(function(){\n${r.script}\n})();`, { filename: r._id, lineOffset: -1 }, ); } return [h, virtualParameters]; } async function fetchFiles(): Promise<[string, Files]> { const res = await collections.files.find().toArray(); res.sort((a, b) => (a._id > b._id ? 1 : -1)); const h = crypto.createHash("md5").update(JSON.stringify(res)).digest("hex"); const files = {}; for (const r of res) { const id = r.filename || r._id.toString(); files[id] = {}; files[id].length = r.length; } return [h, files]; } async function fetchConfig(): Promise<[string, Config]> { const conf = await collections.config.find().toArray(); conf.sort((a, b) => (a._id > b._id ? 1 : -1)); const h = crypto.createHash("md5").update(JSON.stringify(conf)).digest("hex"); const _config = {}; for (const c of conf) { // Evaluate expressions to simplify them _config[c._id] = Expression.parse(c.value).evaluate((e) => e); } return [h, _config]; } const localCache = new LocalCache("cwmp-local-cache-hash", refresh); async function refresh(): Promise<[string, Snapshot]> { const res = await Promise.all([ fetchPresets(), fetchProvisions(), fetchVirtualParameters(), fetchFiles(), fetchConfig(), ]); const h = crypto.createHash("md5"); for (const r of res) h.update(r[0]); const snapshot = { presets: res[0][1], provisions: res[1][1], virtualParameters: res[2][1], files: res[3][1], config: res[4][1], }; return [h.digest("hex"), snapshot]; } export async function getRevision(): Promise { return await localCache.getRevision(); } export function getPresets(revision: string): Preset[] { return localCache.get(revision).presets; } export function getProvisions(revision: string): Provisions { return localCache.get(revision).provisions; } export function getVirtualParameters(revision: string): VirtualParameters { return localCache.get(revision).virtualParameters; } export function getFiles(revision: string): Files { return localCache.get(revision).files; } export function getConfig( revision: string, key: string, dflt: string, fn: (e: Expression) => Expression.Literal, ): string; export function getConfig( revision: string, key: string, dflt: number, fn: (e: Expression) => Expression.Literal, ): number; export function getConfig( revision: string, key: string, dflt: boolean, fn: (e: Expression) => Expression.Literal, ): boolean; export function getConfig( revision: string, key: string, dflt: Value, fn: (e: Expression) => Expression.Literal, ): Value { const snapshot = localCache.get(revision); if (!snapshot) throw new Error("Cache snapshot does not exist"); const e = snapshot.config[key]; if (!e) return dflt; const v = e.evaluate(fn).value; if (typeof v !== typeof dflt) return dflt; return v; } export function getConfigExpression( snapshotKey: string, key: string, ): Expression { const snapshot = localCache.get(snapshotKey); return snapshot.config[key]; } ================================================ FILE: lib/cwmp.ts ================================================ import * as zlib from "node:zlib"; import * as crypto from "node:crypto"; import { Socket } from "node:net"; import { IncomingMessage, ServerResponse } from "node:http"; import { pipeline, Readable } from "node:stream"; import { promisify } from "node:util"; import { decode, encodingExists } from "iconv-lite"; import * as auth from "./auth.ts"; import * as config from "./config.ts"; import { generateDeviceId, once, setTimeoutPromise } from "./util.ts"; import * as soap from "./soap.ts"; import * as session from "./session.ts"; import Expression, { Value } from "./common/expression.ts"; import * as cache from "./cache.ts"; import * as lock from "./lock.ts"; import * as localCache from "./cwmp/local-cache.ts"; import { clearTasks, deleteFault, deleteOperation, fetchDevice, getDueTasks, getFaults, getOperations, saveDevice, saveFault, saveOperation, } from "./cwmp/db.ts"; import * as logger from "./logger.ts"; import * as scheduling from "./scheduling.ts"; import Path from "./common/path.ts"; import * as extensions from "./extensions.ts"; import { SessionContext, AcsRequest, SessionFault, Fault, SoapMessage, InformRequest, Preset, GetRPCMethodsResponse, CpeFault, } from "./types.ts"; import { parseXmlDeclaration } from "./xml-parser.ts"; import * as debug from "./debug.ts"; import { getRequestOrigin } from "./forwarded.ts"; import { getSocketEndpoints } from "./server.ts"; const gzipPromisified = promisify(zlib.gzip); const deflatePromisified = promisify(zlib.deflate); const REALM = "GenieACS"; const MAX_CYCLES = 4; const MAX_CONCURRENT_REQUESTS = +config.get("MAX_CONCURRENT_REQUESTS"); const MAX_SESSION_DURATION = 300000; const LOCK_REFRESH_INTERVAL = 10000; export const REQUEST_TIMEOUT = 10000; const currentSessions = new WeakMap(); const sessionsNonces = new WeakMap(); const stats = { concurrentRequests: 0, totalRequests: 0, droppedRequests: 0, initiatedSessions: 0, }; async function authenticate( sessionContext: SessionContext, body: string, ): Promise { const authExpression: Expression = localCache.getConfigExpression( sessionContext.cacheSnapshot, "cwmp.auth", ); if (!authExpression) return true; let authentication; if (sessionContext.httpRequest.headers["authorization"]) { try { authentication = auth.parseAuthorizationHeader( sessionContext.httpRequest.headers["authorization"], ); } catch { return false; } } if (authentication?.method === "Digest") { const sessionNonce = sessionsNonces.get(sessionContext.httpRequest.socket); if ( !sessionNonce || authentication.nonce !== sessionNonce || (authentication.qop && (!authentication.cnonce || !authentication.nc)) ) return false; authentication["body"] = body; } const res = await authExpression.evaluateAsync( async (e: Expression): Promise => { e = session.configContextCallback(sessionContext, e); if (e instanceof Expression.Parameter) return new Expression.Literal(null); if (e instanceof Expression.FunctionCall) { if (e.name === "NOW") return new Expression.Literal(sessionContext.timestamp); if (e.name === "EXT") { if (!e.args.every((a) => a instanceof Expression.Literal)) return new Expression.Literal(null); const args = e.args.map((a) => a.value.toString()); if (typeof args[0] !== "string" || typeof args[1] !== "string") return new Expression.Literal(null); const { fault, value } = await extensions.run(args); if (fault) return new Expression.Literal(null); return new Expression.Literal(value); } else if (e.name === "AUTH") { if (e.args.every((a) => a instanceof Expression.Literal)) { const username = e.args[0].value; const password = e.args[1].value; if (username != null && password != null && authentication) { if (authentication["method"] === "Basic") { return new Expression.Literal( authentication["username"] === username.toString() && authentication["password"] === password.toString(), ); } if (authentication["method"] === "Digest") { const expected = auth.digest( username.toString(), REALM, password.toString(), authentication["nonce"], "POST", authentication["uri"], authentication["qop"], body, authentication["cnonce"], authentication["nc"], ); return new Expression.Literal( expected === authentication["response"], ); } } } return new Expression.Literal(false); } } return e; }, ); if (res instanceof Expression.Literal) return !!res.value; return false; } async function writeResponse( sessionContext: SessionContext, res, close = false, ): Promise { // Close connection after last request in session if (close) res.headers["Connection"] = "close"; let data = res.data; // Respond using the same content-encoding as the request if ( sessionContext.httpRequest.headers["content-encoding"] && res.data.length > 0 ) { switch (sessionContext.httpRequest.headers["content-encoding"]) { case "gzip": res.headers["Content-Encoding"] = "gzip"; data = await gzipPromisified(data); break; case "deflate": res.headers["Content-Encoding"] = "deflate"; data = await deflatePromisified(data); } } const httpResponse = sessionContext.httpResponse; // Don't use httpResponse.socket as it may be null, even before end() is called const connection = sessionContext.httpRequest.socket; httpResponse.setHeader("Content-Length", Buffer.byteLength(data)); httpResponse.writeHead(res.code, res.headers); if (sessionContext.debug) debug.outgoingHttpResponse(httpResponse, sessionContext.deviceId, res.data); httpResponse.end(data); if (connection.destroyed) { logger.accessError({ sessionContext: sessionContext, message: "Connection dropped", }); await endSession(sessionContext); } else if (close) { session.clearProvisions(sessionContext); await endSession(sessionContext); } else { const now = Date.now(); sessionContext.lastActivity = now; currentSessions.set(connection, sessionContext); if (now >= sessionContext.extendLock) { sessionContext.extendLock = now + LOCK_REFRESH_INTERVAL; const lockToken = await lock.acquireLock( `cwmp_session_${sessionContext.deviceId}`, sessionContext.timeout * 1000 + LOCK_REFRESH_INTERVAL + REQUEST_TIMEOUT, 0, `cwmp_session_${sessionContext.sessionId}`, ); if (!lockToken) throw new Error("Failed to extend lock"); } } } function recordFault( sessionContext: SessionContext, fault: Fault, provisions, channels, ): void; function recordFault(sessionContext: SessionContext, fault: Fault): void; function recordFault( sessionContext: SessionContext, fault: Fault, provisions?, channels?, ): void { if (!provisions) { provisions = sessionContext.provisions; channels = sessionContext.channels; } const channelKeys = Object.keys(channels); if (!channelKeys.length) throw new Error("Fault not associated with a channel!"); const faults = sessionContext.faults; for (const channel of channelKeys) { const provs = sessionContext.faults[channel] ? sessionContext.faults[channel].provisions : []; faults[channel] = Object.assign( { provisions: provs, timestamp: sessionContext.timestamp }, fault, ) as SessionFault; if (channel.startsWith("task_")) { const taskId = channel.slice(5); for (const t of sessionContext.tasks) if (t._id === taskId && t.expiry) faults[channel].expiry = t.expiry; } if (sessionContext.retries[channel] != null) { ++sessionContext.retries[channel]; } else { sessionContext.retries[channel] = 0; if (channelKeys.length !== 1) faults[channel].retryNow = true; } if (channels[channel] === 0) faults[channel].precondition = true; if (!sessionContext.faultsTouched) sessionContext.faultsTouched = {}; sessionContext.faultsTouched[channel] = true; logger.accessWarn({ sessionContext: sessionContext, message: "Channel has faulted", fault: fault, channel: channel, retries: sessionContext.retries[channel], }); } for (let i = 0; i < provisions.length; ++i) { for (const channel of channelKeys) { if ((channels[channel] >> i) & 1) faults[channel].provisions.push(provisions[i]); } } for (const channel of channelKeys) { const provs = faults[channel].provisions; faults[channel].provisions = []; appendProvisions(faults[channel].provisions, provs); } session.clearProvisions(sessionContext); } async function inform( sessionContext: SessionContext, rpc: SoapMessage, ): Promise<{ code: number; headers: Record; data: string }> { const acsResponse = await session.inform( sessionContext, rpc.cpeRequest as InformRequest, ); const res = soap.response({ id: rpc.id, acsResponse: acsResponse, cwmpVersion: sessionContext.cwmpVersion, }); const cookiesPath = localCache.getConfig( sessionContext.cacheSnapshot, "cwmp.cookiesPath", "", (e) => session.configContextCallback(sessionContext, e), ); if (cookiesPath) { res.headers["Set-Cookie"] = `session=${sessionContext.sessionId}; Path=${cookiesPath}`; } else { res.headers["Set-Cookie"] = `session=${sessionContext.sessionId}`; } return res; } async function transferComplete(sessionContext, rpc): Promise { const { acsResponse, operation, fault } = await session.transferComplete( sessionContext, rpc.cpeRequest, ); if (!operation) { logger.accessWarn({ sessionContext: sessionContext, message: "Unrecognized command key", rpc: rpc, }); } if (fault) { Object.assign(sessionContext.retries, operation.retries); recordFault( sessionContext, fault, operation.provisions, operation.channels, ); } const res = soap.response({ id: rpc.id, acsResponse: acsResponse, cwmpVersion: sessionContext.cwmpVersion, }); return writeResponse(sessionContext, res); } // Append provisions and remove duplicates function appendProvisions(original, toAppend): boolean { let modified = false; const stringified = new WeakMap(); for (const p of original) stringified.set(p, JSON.stringify(p)); for (let i = toAppend.length - 1; i >= 0; --i) { let p = toAppend[i]; const s = JSON.stringify(p); for (let j = original.length - 1; j >= 0; --j) { const ss = stringified.get(original[j]); if (s === ss) { if (!p || j >= original.length - (toAppend.length - i)) { p = null; } else { original.splice(j, 1); modified = true; } } } if (p) { original.splice(original.length - (toAppend.length - i) + 1, 0, p); stringified.set(p, s); modified = true; } } return modified; } async function applyPresets(sessionContext: SessionContext): Promise { const deviceData = sessionContext.deviceData; const presets = localCache.getPresets(sessionContext.cacheSnapshot); // Filter presets based on existing faults const blackList = {}; let whiteList = null; let whiteListProvisions = null; const RETRY_DELAY = +localCache.getConfig( sessionContext.cacheSnapshot, "cwmp.retryDelay", 300, (e) => session.configContextCallback(sessionContext, e), ); if (sessionContext.faults) { for (const [channel, fault] of Object.entries(sessionContext.faults)) { let retryTimestamp = 0; if (!fault.retryNow) { retryTimestamp = fault.timestamp + RETRY_DELAY * Math.pow(2, sessionContext.retries[channel]) * 1000; } if (retryTimestamp <= sessionContext.timestamp) { whiteList = channel; whiteListProvisions = fault.provisions; break; } blackList[channel] = fault.precondition ? 1 : 2; } } deviceData.timestamps.revision = 1; deviceData.attributes.revision = 1; const deviceEvents = {}; for (const p of deviceData.paths.find(Path.parse("Events"), 0b001, 0b1)) { const attrs = deviceData.attributes.get(p); const t = attrs?.value[1][0] as number; if (t >= sessionContext.timestamp) deviceEvents[p.segments[1] as string] = true; } const parameters = new Set(); const filteredPresets: Preset[] = []; for (const preset of presets) { if (whiteList != null) { if (preset.channel !== whiteList) continue; } else if (blackList[preset.channel] === 1) { continue; } let eventsMatch = true; for (const [k, v] of Object.entries(preset.events)) { if (!v !== !deviceEvents[k.replace(/\s+/g, "_")]) { eventsMatch = false; break; } } if (!eventsMatch) continue; if (preset.schedule?.schedule) { const r = scheduling.cron( sessionContext.timestamp, preset.schedule.schedule, ); if (!(r[0] + preset.schedule.duration > sessionContext.timestamp)) continue; } const pre = { ...preset }; const evalCallback = (e: Expression): Expression => { if (e instanceof Expression.FunctionCall && e.name === "NOW") return new Expression.Literal(sessionContext.timestamp); if (e instanceof Expression.Parameter) { // Mark channel in case of fault during fetching precondition sessionContext.channels[preset.channel] = 0; parameters.add(e.path.toString()); } return e; }; pre.precondition = preset.precondition.evaluate(evalCallback); pre.provisions = pre.provisions.map((prov) => { let args = prov.slice(1) as Expression[]; args = args.map((arg) => arg.evaluate(evalCallback)); return [prov[0], ...args]; }); filteredPresets.push(pre); } const declarations = [...parameters].map((v) => ({ path: Path.parse(v), pathGet: 1, pathSet: null, attrGet: { value: 1 }, attrSet: null, defer: true, })); const { fault: flt, rpcId: reqId, rpc: acsReq, } = await session.rpcRequest(sessionContext, declarations); if (flt) { recordFault(sessionContext, flt); session.clearProvisions(sessionContext); return applyPresets(sessionContext); } if (acsReq) return sendAcsRequest(sessionContext, reqId, acsReq); session.clearProvisions(sessionContext); if (whiteList != null) session.addProvisions(sessionContext, whiteList, whiteListProvisions); const appendProvisionsToFaults = {}; const evalCallback2 = (e: Expression): Expression.Literal => { e = session.configContextCallback(sessionContext, e); if (!(e instanceof Expression.Literal)) return new Expression.Literal(null); return e; }; for (const p of filteredPresets) { if (p.precondition.evaluate(evalCallback2).value) { const provs = p.provisions.map((pp) => [ pp[0], ...pp .slice(1) .map((arg) => (arg as Expression).evaluate(evalCallback2).value), ]) as [string, ...Value[]][]; if (blackList[p.channel] === 2) { appendProvisionsToFaults[p.channel] = ( appendProvisionsToFaults[p.channel] || [] ).concat(provs); } else { session.addProvisions(sessionContext, p.channel, provs); } } } for (const [channel, provisions] of Object.entries( appendProvisionsToFaults, )) { if ( appendProvisions(sessionContext.faults[channel].provisions, provisions) ) { if (!sessionContext.faultsTouched) sessionContext.faultsTouched = {}; sessionContext.faultsTouched[channel] = true; } } // Don't increment when processing a single channel (e.g. after fault) if (whiteList == null) sessionContext.presetCycles = (sessionContext.presetCycles || 0) + 1; if (sessionContext.presetCycles > MAX_CYCLES) { const fault = { code: "preset_loop", message: "The presets are stuck in an endless configuration loop", timestamp: sessionContext.timestamp, }; recordFault(sessionContext, fault); // No need to save retryNow for (const f of Object.values(sessionContext.faults)) delete f.retryNow; session.clearProvisions(sessionContext); return sendAcsRequest(sessionContext); } deviceData.timestamps.dirty = 0; deviceData.attributes.dirty = 0; const { fault: fault, rpcId: id, rpc: acsRequest, } = await session.rpcRequest(sessionContext, null); if (fault) { recordFault(sessionContext, fault); session.clearProvisions(sessionContext); return applyPresets(sessionContext); } if (!acsRequest) { for (const channel of Object.keys(sessionContext.channels)) { if (sessionContext.faults[channel]) { delete sessionContext.faults[channel]; if (!sessionContext.faultsTouched) sessionContext.faultsTouched = {}; sessionContext.faultsTouched[channel] = true; } } if (whiteList != null) return applyPresets(sessionContext); if ( sessionContext.deviceData.timestamps.dirty > 1 || sessionContext.deviceData.attributes.dirty > 1 ) return applyPresets(sessionContext); } return sendAcsRequest(sessionContext, id, acsRequest); } async function nextRpc(sessionContext: SessionContext): Promise { const { fault: fault, rpcId: id, rpc: acsRequest, } = await session.rpcRequest(sessionContext, null); if (fault) { recordFault(sessionContext, fault); session.clearProvisions(sessionContext); return nextRpc(sessionContext); } if (acsRequest) return sendAcsRequest(sessionContext, id, acsRequest); for (const [channel, flags] of Object.entries(sessionContext.channels)) { if (flags && sessionContext.faults[channel]) { delete sessionContext.faults[channel]; if (!sessionContext.faultsTouched) sessionContext.faultsTouched = {}; sessionContext.faultsTouched[channel] = true; } if (channel.startsWith("task_")) { const taskId = channel.slice(5); if (!sessionContext.doneTasks) sessionContext.doneTasks = []; sessionContext.doneTasks.push(taskId); for (let j = 0; j < sessionContext.tasks.length; ++j) { if (sessionContext.tasks[j]._id === taskId) { sessionContext.tasks.splice(j, 1); break; } } } } session.clearProvisions(sessionContext); // Clear expired tasks sessionContext.tasks = sessionContext.tasks.filter((task) => { if (!(task.expiry <= sessionContext.timestamp)) return true; logger.accessInfo({ sessionContext: sessionContext, message: "Task expired", task: task, }); if (!sessionContext.doneTasks) sessionContext.doneTasks = []; sessionContext.doneTasks.push(task._id); const channel = `task_${task._id}`; if (sessionContext.faults[channel]) { delete sessionContext.faults[channel]; if (!sessionContext.faultsTouched) sessionContext.faultsTouched = {}; sessionContext.faultsTouched[channel] = true; } return false; }); const task = sessionContext.tasks.find( (t) => !sessionContext.faults[`task_${t._id}`], ); if (!task) return applyPresets(sessionContext); let alias; switch (task.name) { case "getParameterValues": // Set channel in case params array is empty sessionContext.channels[`task_${task._id}`] = 0; for (const p of task.parameterNames) { session.addProvisions(sessionContext, `task_${task._id}`, [ ["refresh", p], ]); } break; case "setParameterValues": // Set channel in case params array is empty sessionContext.channels[`task_${task._id}`] = 0; for (const p of task.parameterValues) { session.addProvisions(sessionContext, `task_${task._id}`, [ ["value", p[0], p[1]], ]); } break; case "refreshObject": session.addProvisions(sessionContext, `task_${task._id}`, [ ["refresh", task.objectName], ]); break; case "reboot": session.addProvisions(sessionContext, `task_${task._id}`, [["reboot"]]); break; case "factoryReset": session.addProvisions(sessionContext, `task_${task._id}`, [["reset"]]); break; case "download": session.addProvisions(sessionContext, `task_${task._id}`, [ ["download", task.fileType, task.fileName, task.targetFileName || ""], ]); break; case "addObject": alias = (task.parameterValues || []) .map((p) => `${p[0]}:${JSON.stringify(p[1])}`) .join(","); session.addProvisions(sessionContext, `task_${task._id}`, [ ["instances", `${task.objectName}.[${alias}]`, "+1"], ]); break; case "deleteObject": session.addProvisions(sessionContext, `task_${task._id}`, [ ["instances", task.objectName, 0], ]); break; case "provisions": session.addProvisions( sessionContext, `task_${task._id}`, task.provisions, ); break; default: if (!sessionContext.doneTasks) sessionContext.doneTasks = []; sessionContext.doneTasks.push(task._id); sessionContext.tasks = sessionContext.tasks.filter((t) => t !== task); logger.accessWarn({ sessionContext: sessionContext, message: "Invalid task", taskId: task._id, }); } return nextRpc(sessionContext); } async function endSession(sessionContext: SessionContext): Promise { if (sessionContext.provisions.length) { const fault = { code: "session_terminated", message: "The TR-069 session was unsuccessfully terminated", timestamp: sessionContext.timestamp, }; recordFault(sessionContext, fault); // No need to save retryNow for (const f of Object.values(sessionContext.faults)) delete f.retryNow; } const promises = []; promises.push( saveDevice( sessionContext.deviceId, sessionContext.deviceData, sessionContext.new, sessionContext.timestamp, ), ); if (sessionContext.operationsTouched) { for (const k of Object.keys(sessionContext.operationsTouched)) { if (sessionContext.operations[k]) { promises.push( saveOperation( sessionContext.deviceId, k, sessionContext.operations[k], ), ); } else { promises.push(deleteOperation(sessionContext.deviceId, k)); } } } if (sessionContext.doneTasks?.length) { promises.push( clearTasks(sessionContext.deviceId, sessionContext.doneTasks), ); } if (sessionContext.faultsTouched) { for (const k of Object.keys(sessionContext.faultsTouched)) { if (sessionContext.faults[k]) { sessionContext.faults[k].retries = sessionContext.retries[k]; promises.push( saveFault(sessionContext.deviceId, k, sessionContext.faults[k]), ); } else { promises.push(deleteFault(sessionContext.deviceId, k)); } } } await Promise.all(promises); await lock.releaseLock( `cwmp_session_${sessionContext.deviceId}`, `cwmp_session_${sessionContext.sessionId}`, ); if (sessionContext.new) { logger.accessInfo({ sessionContext: sessionContext, message: "New device registered", }); } } async function sendAcsRequest( sessionContext: SessionContext, id?: string, acsRequest?: AcsRequest, ): Promise { if (!acsRequest) return writeResponse(sessionContext, soap.response(null), true); if (acsRequest.name === "Download") { acsRequest.fileSize = 0; if (!acsRequest.url) { let prefix = "" + config.get("FS_URL_PREFIX"); if (!prefix) { const FS_PORT = +config.get("FS_PORT"); const ssl = !!config.get("FS_SSL_CERT"); const origin = getRequestOrigin(sessionContext.httpRequest); let hostname = origin.localAddress; if (origin.host) [hostname] = origin.host.split(":", 1); prefix = (ssl ? "https" : "http") + `://${hostname}:${FS_PORT}/`; } acsRequest.url = prefix + encodeURI(acsRequest.fileName); const files = localCache.getFiles(sessionContext.cacheSnapshot); if (files[acsRequest.fileName]) acsRequest.fileSize = files[acsRequest.fileName].length; } } const rpc = { id: id, acsRequest: acsRequest, cwmpVersion: sessionContext.cwmpVersion, }; logger.accessInfo({ sessionContext: sessionContext, message: "ACS request", rpc: rpc, }); const res = soap.response(rpc); return writeResponse(sessionContext, res); } // When socket closes, store active sessions in cache export async function onConnection(socket: Socket): Promise { try { await once(socket, "close", MAX_SESSION_DURATION); } catch { socket.destroy(); } const sessionContext = currentSessions.get(socket); if (!sessionContext) return; currentSessions.delete(socket); if (sessionContext.authState !== 2) { logger.accessError({ message: "Authentication failure", sessionContext: sessionContext, }); return; } const now = Date.now(); const lastActivity = sessionContext.lastActivity; const timeoutMsg = { sessionContext: sessionContext, message: "Session timeout", sessionTimestamp: sessionContext.timestamp, }; const timeout = sessionContext.lastActivity + sessionContext.timeout * 1000 - now; if (timeout <= 0) { logger.accessError(timeoutMsg); // TODO it's possible that lock would have already been expired await endSession(sessionContext); return; } await cache.set( `session_${sessionContext.sessionId}`, await session.serialize(sessionContext), Math.ceil(timeout / 1000) + 3, ); await setTimeoutPromise(timeout + 1000, false); const sessionStr = await cache.get(`session_${sessionContext.sessionId}`); if (!sessionStr) return; const _sessionContext = await session.deserialize(sessionStr); if (_sessionContext.lastActivity === lastActivity) { logger.accessError(timeoutMsg); await endSession(sessionContext); } } export async function onClientError(err: Error, socket: Socket): Promise { const remoteAddress = getSocketEndpoints(socket).remoteAddress; const cacheSnapshot = await localCache.getRevision(); const debugEnabled = localCache.getConfig( cacheSnapshot, "cwmp.debug", false, (e) => { if (e instanceof Expression.FunctionCall) { if (e.name === "REMOTE_ADDRESS") return new Expression.Literal(remoteAddress); if (e.name === "NOW") return new Expression.Literal(Date.now()); } if (!(e instanceof Expression.Literal)) return new Expression.Literal(null); return e; }, ); if (debugEnabled) debug.clientError(remoteAddress, err); } setInterval(() => { if (stats.droppedRequests) { logger.warn({ message: "Worker overloaded", droppedRequests: stats.droppedRequests, totalRequests: stats.totalRequests, initiatedSessions: stats.initiatedSessions, pid: process.pid, }); } stats.totalRequests = 0; stats.droppedRequests = 0; stats.initiatedSessions = 0; }, 10000).unref(); async function reportBadState(sessionContext: SessionContext): Promise { logger.accessError({ message: "Bad session state", sessionContext: sessionContext, }); const httpResponse = sessionContext.httpResponse; const body = "Bad session state"; httpResponse.setHeader("Content-Length", Buffer.byteLength(body)); httpResponse.writeHead(400, { Connection: "close" }); if (sessionContext.debug) debug.outgoingHttpResponse(httpResponse, sessionContext.deviceId, body); httpResponse.end(body); if (sessionContext.state) return endSession(sessionContext); } async function responseUnauthorized( sessionContext: SessionContext, close: boolean, ): Promise { const resHeaders = {}; if (close) { // Invalid credentials logger.accessError({ message: "Authentication failure", sessionContext: sessionContext, }); resHeaders["Connection"] = "close"; } else { if (getRequestOrigin(sessionContext.httpRequest).encrypted) { resHeaders["WWW-Authenticate"] = `Basic realm="${REALM}"`; } else { const nonce = crypto.randomBytes(16).toString("hex"); sessionsNonces.set(sessionContext.httpRequest.socket, nonce); let d = `Digest realm="${REALM}"`; d += ',qop="auth,auth-int"'; d += `,nonce="${nonce}"`; resHeaders["WWW-Authenticate"] = d; } currentSessions.set(sessionContext.httpRequest.socket, sessionContext); } const httpResponse = sessionContext.httpResponse; const body = "Unauthorized"; httpResponse.setHeader("Content-Length", Buffer.byteLength(body)); httpResponse.writeHead(401, resHeaders); if (sessionContext.debug) debug.outgoingHttpResponse(httpResponse, sessionContext.deviceId, body); httpResponse.end(body); } async function processRequest( sessionContext: SessionContext, rpc: SoapMessage, parseWarnings: Record[], body: string, ): Promise { for (const w of parseWarnings) { w.sessionContext = sessionContext; logger.accessWarn(w); } if (sessionContext.state === 0) { if (rpc.cpeRequest?.name !== "Inform") return reportBadState(sessionContext); const res = await inform(sessionContext, rpc); sessionContext.debug = !!localCache.getConfig( sessionContext.cacheSnapshot, "cwmp.debug", false, (e) => session.configContextCallback(sessionContext, e), ); if (!sessionContext.timeout) { sessionContext.timeout = +localCache.getConfig( sessionContext.cacheSnapshot, "cwmp.sessionTimeout", 30, (e) => session.configContextCallback(sessionContext, e), ); } sessionContext.httpRequest.socket.setTimeout(sessionContext.timeout * 1000); if (sessionContext.debug) { debug.incomingHttpRequest( sessionContext.httpRequest, sessionContext.deviceId, body, ); } const authenticated = await authenticate(sessionContext, body); if (!authenticated) { if (!sessionContext.authState) { sessionContext.authState = 1; return responseUnauthorized(sessionContext, false); } else { return responseUnauthorized(sessionContext, true); } } sessionContext.extendLock = sessionContext.timestamp + LOCK_REFRESH_INTERVAL; const lockToken = await lock.acquireLock( `cwmp_session_${sessionContext.deviceId}`, sessionContext.timeout * 1000 + LOCK_REFRESH_INTERVAL + REQUEST_TIMEOUT, 0, `cwmp_session_${sessionContext.sessionId}`, ); if (!lockToken) { logger.accessError({ message: "CPE already in session", sessionContext: sessionContext, }); const _body = "CPE already in session"; sessionContext.httpResponse.setHeader( "Content-Length", Buffer.byteLength(_body), ); sessionContext.httpResponse.writeHead(400, { Connection: "close" }); if (sessionContext.debug) { debug.outgoingHttpResponse( sessionContext.httpResponse, sessionContext.deviceId, _body, ); } sessionContext.httpResponse.end(_body); return; } sessionContext.state = 1; sessionContext.authState = 2; logger.accessInfo({ sessionContext: sessionContext, message: "Inform", rpc: rpc, }); return writeResponse(sessionContext, res); } if (sessionContext.debug) { debug.incomingHttpRequest( sessionContext.httpRequest, sessionContext.deviceId, body, ); } // Reauthenticate in case of new connection if (sessionContext.authState !== 2) { const authenticated = await authenticate(sessionContext, body); if (!authenticated) { if (!sessionContext.authState) { sessionContext.authState = 1; return responseUnauthorized(sessionContext, false); } else { await endSession(sessionContext); return responseUnauthorized(sessionContext, true); } } sessionContext.authState = 2; } if (rpc.cpeRequest) { if (rpc.cpeRequest.name === "TransferComplete") { if (sessionContext.state !== 1) return reportBadState(sessionContext); logger.accessInfo({ sessionContext: sessionContext, message: "CPE request", rpc: rpc, }); return transferComplete(sessionContext, rpc); } else if (rpc.cpeRequest.name === "GetRPCMethods") { if (sessionContext.state !== 1) return reportBadState(sessionContext); logger.accessInfo({ sessionContext: sessionContext, message: "CPE request", rpc: rpc, }); const res = soap.response({ id: rpc.id, acsResponse: { name: "GetRPCMethodsResponse", methodList: ["Inform", "GetRPCMethods", "TransferComplete"], } as GetRPCMethodsResponse, cwmpVersion: sessionContext.cwmpVersion, }); return writeResponse(sessionContext, res); } else { if (sessionContext.state !== 1 || rpc.cpeRequest.name === "Inform") return void reportBadState(sessionContext); throw new Error("ACS method not supported"); } } else if (rpc.cpeResponse) { if (sessionContext.state !== 2) return reportBadState(sessionContext); const fault = await session.rpcResponse( sessionContext, rpc.id, rpc.cpeResponse, ); if (fault) { recordFault(sessionContext, fault); session.clearProvisions(sessionContext); } return nextRpc(sessionContext); } else if (rpc.cpeFault) { if (sessionContext.state !== 2) return reportBadState(sessionContext); logger.accessWarn({ sessionContext: sessionContext, message: "CPE fault", rpc: rpc, }); const fault = await session.rpcFault(sessionContext, rpc.id, rpc.cpeFault); if (fault) { recordFault(sessionContext, fault); session.clearProvisions(sessionContext); } return nextRpc(sessionContext); } else if (rpc.unknownMethod) { if (sessionContext.state === 1) { logger.accessWarn({ sessionContext: sessionContext, message: "Method not supported", method: rpc.unknownMethod, }); const f: CpeFault = { faultCode: "Server", faultString: "CWMP fault", detail: { faultCode: "8000", faultString: "Method not supported", }, }; const res = soap.response({ id: rpc.id, acsFault: f, cwmpVersion: sessionContext.cwmpVersion, }); return writeResponse(sessionContext, res); } else if (sessionContext.state === 2) { const fault = { code: "invalid_response", message: "Response name does not match request name", }; recordFault(sessionContext, fault); session.clearProvisions(sessionContext); return nextRpc(sessionContext); } else { return reportBadState(sessionContext); } } else { // CPE sent empty response if (sessionContext.state !== 1) return reportBadState(sessionContext); sessionContext.state = 2; const { faults, operations } = await session.timeoutOperations(sessionContext); for (const [i, f] of faults.entries()) { for (const [k, v] of Object.entries(operations[i].retries)) sessionContext.retries[k] = v; recordFault( sessionContext, f, operations[i].provisions, operations[i].channels, ); } return nextRpc(sessionContext); } } export async function listener( httpRequest: IncomingMessage, httpResponse: ServerResponse, ): Promise { stats.concurrentRequests += 1; try { await listenerAsync(httpRequest, httpResponse); } catch (err) { currentSessions.delete(httpRequest.socket); throw err; } finally { stats.concurrentRequests -= 1; } } async function clientError( httpRequest: IncomingMessage, httpResponse: ServerResponse, sessionContext: SessionContext, body: string, msg: string, ): Promise { let debugEnabled: boolean; let deviceId: string = null; if (sessionContext) { debugEnabled = sessionContext.debug; deviceId = sessionContext.deviceId; } else { const cacheSnapshot = await localCache.getRevision(); const remoteAddress = getRequestOrigin(httpRequest).remoteAddress; debugEnabled = localCache.getConfig( cacheSnapshot, "cwmp.debug", false, (e) => { if (e instanceof Expression.FunctionCall) { if (e.name === "REMOTE_ADDRESS") return new Expression.Literal(remoteAddress); if (e.name === "NOW") return new Expression.Literal(Date.now()); } if (!(e instanceof Expression.Literal)) return new Expression.Literal(null); return e; }, ); } httpResponse.setHeader("Content-Length", Buffer.byteLength(msg)); httpResponse.writeHead(400, { Connection: "close" }); if (debugEnabled) { debug.incomingHttpRequest(httpRequest, deviceId, body); debug.outgoingHttpResponse(httpResponse, deviceId, msg); } httpResponse.end(msg); if (sessionContext?.state) await endSession(sessionContext); } function decodeString(buffer: Buffer, charset: string): string { try { return buffer.toString(charset as BufferEncoding); } catch { if (encodingExists(charset)) return decode(buffer, charset); } return null; } async function listenerAsync( httpRequest: IncomingMessage, httpResponse: ServerResponse, ): Promise { stats.totalRequests += 1; if (httpRequest.method !== "POST") { httpResponse.writeHead(405, { Allow: "POST", Connection: "close", }); httpResponse.end("405 Method Not Allowed"); return; } let sessionId; // Separation by comma is important as some devices don't comform to standard const COOKIE_REGEX = /\s*([a-zA-Z0-9\-_]+?)\s*=\s*"?([a-zA-Z0-9\-_]*?)"?\s*(,|;|$)/g; let match; while ((match = COOKIE_REGEX.exec(httpRequest.headers.cookie))) if (match[1] === "session") sessionId = match[2]; // If overloaded, ask CPE to retry in 60 seconds if (!sessionId && stats.concurrentRequests > MAX_CONCURRENT_REQUESTS) { httpResponse.writeHead(503, { "Retry-after": 60, Connection: "close", }); httpResponse.end("503 Service Unavailable"); stats.droppedRequests += 1; return; } let stream: Readable = httpRequest; if (httpRequest.headers["content-encoding"]) { switch (httpRequest.headers["content-encoding"]) { case "gzip": stream = pipeline(stream, zlib.createGunzip(), () => { // Errors are also raised by the async iterator }); break; case "deflate": stream = pipeline(stream, zlib.createInflate(), () => { // Errors are also raised by the async iterator }); break; default: httpResponse.writeHead(415, { Connection: "close" }); httpResponse.end("415 Unsupported Media Type"); return; } } const chunks: Buffer[] = []; try { let readableEnded = false; stream.on("end", () => { readableEnded = true; }); for await (const chunk of stream) chunks.push(chunk); // In Node versions prior to 15, the stream will not emit an error if the // connection is closed before the stream is finished. // For Node 12.9+ we can just use stream.readableEnded if (!readableEnded) throw new Error("Connection closed"); } catch { return; } const body = Buffer.concat(chunks); let sessionContext = currentSessions.get(httpRequest.socket); if (sessionContext) { currentSessions.delete(httpRequest.socket); sessionContext.httpRequest = httpRequest; sessionContext.httpResponse = httpResponse; if ( (sessionContext.sessionId !== sessionId && sessionContext.state) || sessionContext.lastActivity + sessionContext.timeout * 1000 < Date.now() ) { logger.accessError({ message: "Invalid session", sessionContext: sessionContext, }); return clientError( httpRequest, httpResponse, sessionContext, body.toString(), "Invalid session", ); } } let charset: string; if (httpRequest.headers["content-type"]) { const m = httpRequest.headers["content-type"].match( /charset=['"]?([^'"\s]+)/i, ); if (m) charset = m[1].toLowerCase(); } if (!charset) { const parse = parseXmlDeclaration(body); const e = parse ? parse.find((s) => s.localName === "encoding") : null; charset = e ? e.value.toLowerCase() : "utf8"; } const bodyStr = decodeString(body, charset); if (bodyStr == null) { if (!sessionContext && sessionId) { await new Promise((resolve) => setTimeout(resolve, 100)); const sessionContextString = await cache.pop(`session_${sessionId}`); if (sessionContextString) { sessionContext = await session.deserialize(sessionContextString); sessionContext.httpRequest = httpRequest; sessionContext.httpResponse = httpResponse; } } const msg = `Unknown encoding '${charset}'`; logger.accessError({ message: "XML parse error", parseError: msg, sessionContext: sessionContext || { httpRequest: httpRequest, httpResponse: httpResponse, }, }); return clientError( httpRequest, httpResponse, sessionContext, body.toString(), msg, ); } const parseWarnings = []; let rpc: SoapMessage; try { rpc = soap.request(bodyStr, parseWarnings); } catch (err) { if (!sessionContext && sessionId) { await new Promise((resolve) => setTimeout(resolve, 100)); const sessionContextString = await cache.pop(`session_${sessionId}`); if (sessionContextString) { sessionContext = await session.deserialize(sessionContextString); sessionContext.httpRequest = httpRequest; sessionContext.httpResponse = httpResponse; } } logger.accessError({ message: "XML parse error", parseError: err.message, sessionContext: sessionContext || { httpRequest: httpRequest, httpResponse: httpResponse, }, }); return clientError( httpRequest, httpResponse, sessionContext, bodyStr, err.message, ); } if (!sessionContext && sessionId && rpc.cpeRequest?.name !== "Inform") { await new Promise((resolve) => setTimeout(resolve, 100)); const sessionContextString = await cache.pop(`session_${sessionId}`); if (sessionContextString) { sessionContext = await session.deserialize(sessionContextString); sessionContext.httpRequest = httpRequest; sessionContext.httpResponse = httpResponse; httpRequest.socket.setTimeout(sessionContext.timeout * 1000); if (sessionContext.authState !== 1) sessionContext.authState = 0; } } if (sessionContext) return processRequest(sessionContext, rpc, parseWarnings, bodyStr); if (rpc.cpeRequest?.name !== "Inform") { logger.accessError({ message: "Invalid session", sessionContext: { httpRequest: httpRequest, httpResponse: httpResponse, }, }); return clientError( httpRequest, httpResponse, null, bodyStr, "Invalid session", ); } if (stats.concurrentRequests > MAX_CONCURRENT_REQUESTS) { // Check again just in case device included old session ID // from the previous session httpResponse.writeHead(503, { "Retry-after": 60, Connection: "close" }); httpResponse.end("503 Service Unavailable"); stats.droppedRequests += 1; return; } stats.initiatedSessions += 1; const deviceId = generateDeviceId(rpc.cpeRequest.deviceId); const cacheSnapshot = await localCache.getRevision(); const _sessionContext = session.init( deviceId, rpc.cwmpVersion, rpc.sessionTimeout, ); _sessionContext.cacheSnapshot = cacheSnapshot; _sessionContext.httpRequest = httpRequest; _sessionContext.httpResponse = httpResponse; _sessionContext.sessionId = crypto.randomBytes(8).toString("hex"); const [dueTasks, faults, operations] = await Promise.all([ getDueTasks(deviceId, _sessionContext.timestamp), getFaults(deviceId), getOperations(deviceId), ]); _sessionContext.tasks = dueTasks[0]; _sessionContext.operations = operations; _sessionContext.faults = faults; _sessionContext.retries = {}; for (const [k, v] of Object.entries(_sessionContext.faults)) { if (v.expiry >= _sessionContext.timestamp) { // Delete expired faults delete _sessionContext.faults[k]; if (!_sessionContext.faultsTouched) _sessionContext.faultsTouched = {}; _sessionContext.faultsTouched[k] = true; } else { _sessionContext.retries[k] = v.retries; } } const parameters = await fetchDevice( _sessionContext.deviceId, _sessionContext.timestamp, ); if (parameters) { for (const p of parameters) { const path = _sessionContext.deviceData.paths.add(p[0]); _sessionContext.deviceData.timestamps.set(path, p[1], 0); if (p[2]) _sessionContext.deviceData.attributes.set(path, p[2], 0); } } else { // Device not available in database, mark as new _sessionContext.new = true; } return processRequest(_sessionContext, rpc, parseWarnings, bodyStr); } ================================================ FILE: lib/db/db.ts ================================================ import { MongoClient, Collection, GridFSBucket } from "mongodb"; import { get } from "../config.ts"; import * as MongoTypes from "./types.ts"; export let filesBucket: GridFSBucket; export const collections = { devices: null as Collection, presets: null as Collection, objects: null as Collection, provisions: null as Collection, virtualParameters: null as Collection, faults: null as Collection, tasks: null as Collection, files: null as Collection, operations: null as Collection, permissions: null as Collection, users: null as Collection, config: null as Collection, cache: null as Collection, locks: null as Collection, views: null as Collection, }; let clientPromise: Promise; export async function connect(): Promise { clientPromise = MongoClient.connect("" + get("MONGODB_CONNECTION_URL")); const client = await clientPromise; const db = client.db(); collections.tasks = db.collection("tasks"); collections.devices = db.collection("devices"); collections.presets = db.collection("presets"); collections.objects = db.collection("objects"); collections.files = db.collection("fs.files"); collections.provisions = db.collection("provisions"); collections.virtualParameters = db.collection("virtualParameters"); collections.faults = db.collection("faults"); collections.operations = db.collection("operations"); collections.permissions = db.collection("permissions"); collections.users = db.collection("users"); collections.config = db.collection("config"); collections.cache = db.collection("cache"); collections.locks = db.collection("locks"); collections.views = db.collection("views"); filesBucket = new GridFSBucket(db); await Promise.all([ collections.tasks.createIndex({ device: 1, timestamp: 1 }), collections.cache.createIndex({ expire: 1 }, { expireAfterSeconds: 0 }), collections.locks.createIndex({ expire: 1 }, { expireAfterSeconds: 0 }), ]); } export async function disconnect(): Promise { if (clientPromise != null) await (await clientPromise).close(); } ================================================ FILE: lib/db/synth.ts ================================================ import { Filter } from "mongodb"; import { EJSON } from "bson"; import { complement } from "espresso-iisojs"; import { parseLikePattern } from "../common/expression/parser.ts"; import Expression from "../common/expression.ts"; import { decodeTag } from "../util.ts"; import { SynthContextBase, likeDisjoint, likeImplies, Clause, } from "../common/expression/synth.ts"; import normalize from "../common/expression/normalize.ts"; type Minterm = number[]; function getParam(exp: Expression, collection: string): string { if (!(exp instanceof Expression.Parameter)) throw new Error("Left-hand operand must be a parameter"); const p = exp.path.toString(); if (collection === "devices") { if (p === "DeviceID.ID") return "_id"; else if (p === "DeviceID") return "_deviceId"; else if (p.startsWith("DeviceID.")) return "_deviceId._" + p.slice(9); else if (p === "Events.Inform") return "_lastInform"; else if (p === "Events.Registered") return "_registered"; else if (p === "Events.0_BOOTSTRAP") return "_lastBootstrap"; else if (p === "Events.1_BOOT") return "_lastBoot"; else if (!p.endsWith("._value") && !p.startsWith("Tags.")) return `${p}._value`; } return p; } function getTypes(parameter: string, collection: string): string[] { if (collection === "devices") { if (parameter === "_id") return ["string"]; if (parameter === "_lastInform") return ["date"]; if (parameter === "_registered") return ["date"]; if (parameter === "_lastBootstrap") return ["date"]; if (parameter === "_lastBoot") return ["date"]; if (parameter.startsWith("_deviceId.")) return ["string"]; if (parameter === "Reboot._value") return ["date"]; if (parameter === "FactoryReset._value") return ["date"]; if (parameter.endsWith("_timestamp")) return ["date"]; if (parameter.startsWith("Downloads.")) { if (parameter.endsWith("Download._value")) return ["date"]; if (parameter.endsWith("Time._value")) return ["date"]; if (parameter.endsWith("Name._value")) return ["string"]; if (parameter.endsWith("Type._value")) return ["string"]; } if (parameter.endsWith("_value")) return ["bool", "number", "date", "string"]; } else if (collection === "tasks") { if (parameter === "_id") return ["oid"]; if (parameter === "timestamp") return ["date"]; if (parameter === "expiry") return ["date"]; if (parameter === "name") return ["string"]; if (parameter === "device") return ["string"]; } else if (collection === "faults") { if (parameter === "_id") return ["string"]; if (parameter === "timestamp") return ["date"]; if (parameter === "expiry") return ["date"]; if (parameter === "code") return ["string"]; if (parameter === "retries") return ["number"]; if (parameter === "channel") return ["string"]; if (parameter === "device") return ["string"]; if (parameter === "message") return ["string"]; } else if (collection === "users") { if (parameter === "_id") return ["string"]; if (parameter === "roles") return ["string"]; else if (parameter === "password") throw new Error("Cannot query restricted parameters"); else if (parameter === "salt") throw new Error("Cannot query restricted parameters"); } else if (collection === "config") { if (parameter === "_id") return ["string"]; else if (parameter === "value") return ["string"]; } else if (collection === "files") { if (parameter === "_id") return ["string"]; if (parameter === "metadata.fileType") return ["string"]; if (parameter === "metadata.oui") return ["string"]; if (parameter === "metadata.productClass") return ["string"]; if (parameter === "metadata.version") return ["string"]; } else if (collection === "permissions") { if (parameter === "_id") return ["string"]; if (parameter === "role") return ["string"]; if (parameter === "resource") return ["devices"]; if (parameter === "access") return ["number"]; if (parameter === "filter") return ["string"]; if (parameter === "validate") return ["string"]; } else if (collection === "presets") { if (parameter === "_id") return ["string"]; if (parameter === "weight") return ["number"]; if (parameter === "channel") return ["string"]; if (parameter === "precondition") return ["string"]; if (parameter.startsWith("events.")) return ["bool"]; } else if (collection === "provisions") { if (parameter === "_id") return ["string"]; if (parameter === "script") return ["string"]; } else if (collection === "virtualParameters") { if (parameter === "_id") return ["string"]; if (parameter === "script") return ["string"]; } if (parameter === "_id") return ["oid", "string"]; return ["bool", "number", "date", "string"]; } function roundOid(oid: string, roundUp: boolean): string { const match = (oid.match(/^[0-9a-f]*/)?.[0] ?? "").slice(0, 24); let num = BigInt("0x0" + match); let lastChar = 0; if (oid.length > match.length) lastChar += oid.charCodeAt(match.length); if (match.length < 24) lastChar -= 48; if (lastChar > 0 && roundUp) num++; num <<= BigInt(4 * (24 - match.length)); if (lastChar < 0 && !roundUp) --num; const str = num.toString(16); if (str.length > 24 || str.startsWith("-")) return null; return str.padStart(24, "0"); } function groupBy( input: T[], callback: (item: T) => K, ): Iterable<[K, T[]]> { const groups = new Map(); for (const item of input) { const key = callback(item); let arr = groups.get(key); if (!arr) groups.set(key, (arr = [])); arr.push(item); } return groups.entries(); } abstract class MongoClause { abstract readonly parameter: string; abstract toQuery(truthy: boolean): Filter; toString(): string { return JSON.stringify(this.toQuery(true)); } } class MongoClauseArray extends MongoClause { constructor( public readonly parameter: string, public readonly value: string, ) { super(); } toQuery(truthy: boolean): Filter { if (truthy) return { [this.parameter]: { $eq: this.value } }; else return { [this.parameter]: { $ne: this.value } }; } } class MongoClauseCompare extends MongoClause { constructor( public readonly parameter: string, public readonly op: "$eq" | "$gt" | "$lt" | "$gte" | "$lte", public readonly value: T, public readonly type: "" | "bool" | "number" | "string" | "date" | "oid", ) { super(); } toQuery(truthy: boolean): Filter { let v: any = this.value; if (this.type === "date" && typeof v === "number") v = { $date: new Date(v).toISOString() }; if (this.type === "oid" && typeof v === "string") v = { $oid: v }; if (truthy) return { [this.parameter]: { [this.op]: v } }; else if (this.op === "$eq") return { [this.parameter]: { $ne: v } }; else return { [this.parameter]: { $not: { [this.op]: v } } }; } } class MongoClauseType extends MongoClause { constructor( public readonly parameter: string, public readonly type: string, ) { super(); } toQuery(truthy: boolean): Filter { if (truthy) return { [this.parameter]: { $type: this.type } }; else return { [this.parameter]: { $not: { $type: this.type } } }; } } class MongoClauseLike extends MongoClause { readonly pattern: string[]; constructor( public readonly parameter: string, pat: string, esc: string, public readonly caseSensitive: boolean, ) { super(); this.pattern = parseLikePattern(pat, esc); } toQuery(truthy: boolean): Filter { const convChars = { "-": "\\-", "/": "\\/", "\\": "\\/", "^": "\\^", $: "\\$", "*": "\\*", "+": "\\+", "?": "\\?", ".": "\\.", "(": "\\(", ")": "\\)", "|": "\\|", "[": "\\[", "]": "\\]", "{": "\\{", "}": "\\}", "\\%": ".*", "\\_": ".", }; const chars = this.pattern.map((c) => convChars[c] ?? c); chars[0] = chars[0] === ".*" ? "" : "^" + chars[0]; const l = chars.length - 1; chars[l] = [".*", ""].includes(chars[l]) ? "" : chars[l] + "$"; const pattern = chars.join(""); const options = this.caseSensitive ? "s" : "is"; if (truthy) { return { [this.parameter]: { $regularExpression: { options, pattern } } }; } else { return { [this.parameter]: { $not: { $regularExpression: { options, pattern } }, }, }; } } } class MongoSynthContext extends SynthContextBase { constructor(private readonly collection: string) { super(); } getMinterms(clause: Clause, res: number): number[][] { res = res & 0b111; if (res & (res - 1)) return complement(this.getMinterms(clause, ~res)); const exp = clause.expression(); if (res === 0b001) { const minterms: number[][] = []; for (const dep of clause.getNullables()) { const e = dep.operand.expression(); const param = getParam(e, this.collection); if (param.startsWith("Tags.") && this.collection === "devices") { const t = decodeTag(param.slice(5)); const c = new MongoClauseArray("_tags", t); minterms.push([this.getVar(c) << 1]); continue; } const c = new MongoClauseCompare(param, "$eq", null, ""); minterms.push([(this.getVar(c) << 1) ^ 1]); } return minterms; } if (!(exp instanceof Expression.Binary)) throw new Error("Invalid query expression"); const truthy = res === 0b100; if ([">", "<", "="].includes(exp.operator)) { const param = getParam(exp.left, this.collection); if (!(exp.right instanceof Expression.Literal)) throw new Error(`Right-hand operand must be a literal value`); let rhs = exp.right.value; if (typeof rhs === "boolean") rhs = +rhs; if ( param.startsWith("Tags.") && this.collection === "devices" && exp.operator === "=" ) { const t = decodeTag(param.slice(5)); const c = new MongoClauseArray("_tags", t); if (typeof rhs === "string") rhs = 2; if (exp.operator === "=") { if ((rhs === 1) !== truthy) return []; } else if (exp.operator === ">") { if ((truthy && rhs >= 1) || (!truthy && rhs < 1)) return []; } else if (exp.operator === "<") { if ((truthy && rhs <= 1) || (!truthy && rhs > 1)) return []; } return [[(this.getVar(c) << 1) ^ 1]]; } let op: "$gt" | "$lt" | "$eq" | "$gte" | "$lte"; if (exp.operator === "=") op = "$eq"; else if (exp.operator === ">") op = truthy ? "$gt" : "$lte"; else if (exp.operator === "<") op = truthy ? "$lt" : "$gte"; const possibleTypes = new Set(getTypes(param, this.collection)); const clauses: MongoClause[] = []; if (typeof rhs === "number") { if (possibleTypes.has("number")) clauses.push(new MongoClauseCompare(param, op, rhs, "number")); if (possibleTypes.has("date")) clauses.push(new MongoClauseCompare(param, op, rhs, "date")); if (possibleTypes.has("bool") && (rhs === 0 || rhs === 1)) clauses.push(new MongoClauseCompare(param, op, !!rhs, "bool")); } else if (typeof rhs === "string") { if (possibleTypes.has("string")) clauses.push(new MongoClauseCompare(param, op, rhs, "string")); if (possibleTypes.has("oid")) { const oid = roundOid(rhs, op === "$lt" || op === "$lte"); if (oid && (op !== "$eq" || oid === rhs)) clauses.push(new MongoClauseCompare(param, op, oid, "oid")); } } if (op === "$eq" && !truthy) { clauses.push(new MongoClauseCompare(param, "$eq", null, "")); return [clauses.map((c) => this.getVar(c) << 1)]; } // In the following clauses we could use $type operator, but we want the // final query to use comparison operators to check for type because the // $type operator in MongoDB doesn't use indexes if (typeof rhs === "number") { if (possibleTypes.has("bool")) { if ( (rhs > 1 && (op === "$lt" || op === "$lte")) || (rhs < 0 && (op === "$gt" || op === "$gte")) ) clauses.push(new MongoClauseCompare(param, "$gte", false, "bool")); } if (op === "$gt" || op === "$gte") { if (possibleTypes.has("string")) clauses.push(new MongoClauseCompare(param, "$gte", "", "string")); if (possibleTypes.has("oid")) { clauses.push( new MongoClauseCompare( param, "$gte", "000000000000000000000000", "oid", ), ); } } } else if (typeof rhs === "string") { if (op === "$lt" || op === "$lte") { if (possibleTypes.has("bool")) clauses.push(new MongoClauseCompare(param, "$gte", false, "bool")); if (possibleTypes.has("number")) { clauses.push(new MongoClauseCompare(param, "$gte", 0, "number")); clauses.push(new MongoClauseCompare(param, "$lt", 0, "number")); } if (possibleTypes.has("date")) { clauses.push(new MongoClauseCompare(param, "$gte", 0, "date")); clauses.push(new MongoClauseCompare(param, "$lt", 0, "date")); } } } return clauses.map((c) => [(this.getVar(c) << 1) ^ 1]); } else if (exp.operator === "LIKE") { if ( !( exp.right instanceof Expression.Literal && typeof exp.right.value === "string" ) ) throw new Error("Right-hand operand of 'LIKE' must be a string"); const pat = exp.right.value; let p = exp.left; let caseSensitive = true; if ( p instanceof Expression.FunctionCall && ["UPPER", "LOWER"].includes(p.name) ) { if (p.name === "UPPER" && pat !== pat.toUpperCase()) return truthy ? [] : [[]]; if (p.name === "LOWER" && pat !== pat.toLowerCase()) return truthy ? [] : [[]]; caseSensitive = false; p = p.args[0]; } const param = getParam(p, this.collection); const c = new MongoClauseLike(param, pat, null, caseSensitive); if (truthy) return [[(this.getVar(c) << 1) ^ 1]]; const typeClause = new MongoClauseCompare(param, "$gte", "", "string"); const r = [[this.getVar(c) << 1, (this.getVar(typeClause) << 1) ^ 1]]; return r; } else { throw new Error("Invalid query expression"); } } getDcSet(minterms: Minterm[]): number[][] { const dcSet: number[][] = []; const vars = new Set(minterms.flat().map((l) => l >> 1)); const clauses = Array.from(vars).map((v) => this.getClause(v)); for (const [parameter, clauses2] of groupBy(clauses, (c) => c.parameter)) { const comparisons = clauses2.filter( (c) => c instanceof MongoClauseCompare && c.value !== null, ) as MongoClauseCompare[]; for (const [type, clauses3] of groupBy(comparisons, (c) => c.type)) { const isType = this.getVar(new MongoClauseType(parameter, type)); const values = new Set(clauses3.map((c) => c.value)); const valuesSorted = Array.from(values).sort((a, b) => a > b ? 1 : -1, ); for (const [i, v] of valuesSorted.entries()) { const eq = this.getVar( new MongoClauseCompare(parameter, "$eq", v, type), ); const gt = this.getVar( new MongoClauseCompare(parameter, "$gt", v, type), ); const lt = this.getVar( new MongoClauseCompare(parameter, "$lt", v, type), ); const gte = this.getVar( new MongoClauseCompare(parameter, "$gte", v, type), ); const lte = this.getVar( new MongoClauseCompare(parameter, "$lte", v, type), ); if (type === "bool") { if (v === false) dcSet.push([(lt << 1) ^ 1]); else if (v === true) dcSet.push([(gt << 1) ^ 1]); } else if (type === "string") { if (v === "") dcSet.push([(lt << 1) ^ 1]); } else if (type === "oid") { if (v < "000000000000000000000000") dcSet.push([(lte << 1) ^ 1]); else if (v === "000000000000000000000000") dcSet.push([(lt << 1) ^ 1]); else if (v > "ffffffffffffffffffffffff") dcSet.push([(gte << 1) ^ 1]); else if (v === "ffffffffffffffffffffffff") dcSet.push([(gt << 1) ^ 1]); } dcSet.push([(lt << 1) ^ 1, (gte << 1) ^ 1]); dcSet.push([(gt << 1) ^ 1, (gte << 1) ^ 0]); dcSet.push([(eq << 1) ^ 0, (lt << 1) ^ 0, (lte << 1) ^ 1]); dcSet.push([(eq << 1) ^ 1, (gte << 1) ^ 0]); dcSet.push([(eq << 1) ^ 1, (gt << 1) ^ 1]); if (i === 0) { dcSet.push([(isType << 1) ^ 0, (gte << 1) ^ 1]); dcSet.push([(isType << 1) ^ 0, (lt << 1) ^ 1]); } else { const gt2 = this.getVar( new MongoClauseCompare( parameter, "$gt", valuesSorted[i - 1], type, ), ); const lte2 = this.getVar( new MongoClauseCompare( parameter, "$lte", valuesSorted[i - 1], type, ), ); dcSet.push([(gt2 << 1) ^ 0, (gte << 1) ^ 1]); dcSet.push([(gt2 << 1) ^ 0, (lte2 << 1) ^ 0, (lt << 1) ^ 1]); } if (i === valuesSorted.length - 1) dcSet.push([(isType << 1) ^ 1, (gt << 1) ^ 0, (lte << 1) ^ 0]); } } const likes = clauses2.filter( (c) => c instanceof MongoClauseLike, ) as MongoClauseLike[]; if (likes.length) { const isType = this.getVar(new MongoClauseType(parameter, "string")); for (let i1 = 0; i1 < likes.length; ++i1) { const l1 = likes[i1]; let p1 = l1.pattern; dcSet.push([(this.getVar(l1) << 1) ^ 1, (isType << 1) ^ 0]); for (let i2 = i1 + 1; i2 < likes.length; ++i2) { const l2 = likes[i2]; let p2 = l2.pattern; if (!l1.caseSensitive || !l2.caseSensitive) { p1 = p1.map((c) => c.toLowerCase()); p2 = p2.map((c) => c.toLowerCase()); } if (likeDisjoint(p1, p2)) { dcSet.push([ (this.getVar(l1) << 1) ^ 1, (this.getVar(l2) << 1) ^ 1, ]); } else if ( (!l1.caseSensitive || l2.caseSensitive) && likeImplies(p1, p2) ) { dcSet.push([ (this.getVar(l1) << 1) ^ 0, (this.getVar(l2) << 1) ^ 1, ]); } else if ( (!l2.caseSensitive || l1.caseSensitive) && likeImplies(p2, p1) ) { dcSet.push([ (this.getVar(l1) << 1) ^ 1, (this.getVar(l2) << 1) ^ 0, ]); } } } } const isNull = this.getVar( new MongoClauseCompare(parameter, "$eq", null, ""), ); const types = getTypes(parameter, this.collection).map((t) => this.getVar(new MongoClauseType(parameter, t)), ); dcSet.push([(isNull << 1) ^ 0, ...types.map((t) => (t << 1) ^ 0)]); for (let i = 0; i < types.length; ++i) { const t1 = types[i]; dcSet.push([(t1 << 1) ^ 1, (isNull << 1) ^ 1]); for (let j = i + 1; j < types.length; ++j) { const t2 = types[j]; dcSet.push([(t1 << 1) ^ 1, (t2 << 1) ^ 1]); } } if (parameter === "_id") dcSet.push([(isNull << 1) ^ 1]); } return dcSet; } canRaise(i: number, s: Set): boolean { if (!(i & 1)) return true; const c = this.getClause(i >> 1); if (c instanceof MongoClauseCompare) { for (const j of s) { if (j === i) continue; const c2 = this.getClause(j >> 1); if (c2.parameter !== c.parameter) continue; if (!(j & 1)) return false; if (c2 instanceof MongoClauseType) return false; } } return true; } toQuery(minterms: Minterm[]): Filter { const or = []; const ejsonOps = ["$oid", "$date", "$regularExpression"]; for (const minterm of minterms) { const query = {}; loop: for (const clause of minterm) { if (!minterm.length) return {}; const negate = !!(clause & 1); const c = this.getClause(clause >> 1); const q = c.toQuery(negate); if (Object.keys(q).length !== 1) throw new Error("Invalid query expression"); const [param, value] = Object.entries(q)[0]; const dests = [query, ...(query["$and"] ?? [])]; for (const dest of dests) { if (!(param in dest)) { dest[param] = value; continue loop; } let src = value; let dst = dest[param]; if (Object.getPrototypeOf(src).constructor !== Object) continue; if (Object.getPrototypeOf(dst).constructor !== Object) continue; let srcKeys = Object.keys(src); let dstKeys = Object.keys(dst); if ([...srcKeys, ...dstKeys].every((k) => k === "$not")) { src = src["$not"]; dst = dst["$not"]; if (Object.getPrototypeOf(src).constructor !== Object) continue; if (Object.getPrototypeOf(dst).constructor !== Object) continue; srcKeys = Object.keys(src); dstKeys = Object.keys(dst); } if (srcKeys.some((k) => dstKeys.includes(k))) continue; // Don't mix regular operators with EJSON special operators if (srcKeys.some((k) => ejsonOps.includes(k))) continue; if (dstKeys.some((k) => ejsonOps.includes(k))) continue; Object.assign(dst, src); continue loop; } query["$and"] ??= []; query["$and"].push({ [param]: value }); } or.push(query); } if (or.length === 1) return or[0]; return { $or: or }; } } export function toMongoQuery( exp: Expression, resource: string, ): Filter | false { exp = normalize(exp); const clause = Clause.fromExpression(normalize(exp)); const context = new MongoSynthContext(resource); const minterms = clause.getMinterms(context, 0b100); const minimized = context.minimize(minterms); if (!minimized.length) return false; return EJSON.deserialize(context.toQuery(minimized)); } export function validQuery(exp: Expression, resource: string): void { const clause = Clause.fromExpression(normalize(exp)); const context = new MongoSynthContext(resource); clause.getMinterms(context, 0b100); } ================================================ FILE: lib/db/types.ts ================================================ import { ObjectId } from "mongodb"; import { FaultStruct } from "../types.ts"; import { Value } from "../common/expression.ts"; export interface Fault { _id: string; device: string; channel: string; timestamp: Date; provisions: string; retries: number; code: string; message: string; detail?: | FaultStruct | { name: string; message: string; stack?: string; }; expiry?: Date; } interface TaskBase { _id: ObjectId; timestamp?: Date; expiry?: Date; name: string; device: string; } export interface View { _id: string; script: string; } interface TaskGetParameterValues extends TaskBase { name: "getParameterValues"; parameterNames: string[]; } interface TaskSetParameterValues extends TaskBase { name: "setParameterValues"; parameterValues: [string, string | number | boolean, string?][]; } interface TaskRefreshObject extends TaskBase { name: "refreshObject"; objectName: string; } interface TaskReboot extends TaskBase { name: "reboot"; } interface TaskFactoryReset extends TaskBase { name: "factoryReset"; } interface TaskDownload extends TaskBase { name: "download"; fileType: string; fileName: string; targetFileName?: string; } interface TaskAddObject extends TaskBase { name: "addObject"; objectName: string; parameterValues: [string, string | number | boolean, string?][]; } interface TaskDeleteObject extends TaskBase { name: "deleteObject"; objectName: string; } interface TaskProvisions extends TaskBase { name: "provisions"; provisions?: [string, ...Value[]][]; } export type Task = | TaskGetParameterValues | TaskSetParameterValues | TaskRefreshObject | TaskReboot | TaskFactoryReset | TaskDownload | TaskAddObject | TaskDeleteObject | TaskProvisions; export interface Operation { _id: string; name: string; timestamp: Date; channels: string; retries: string; provisions: string; args: string; } export interface Config { _id: string; value: string; } export interface Cache { _id: string; value: string; timestamp: Date; expire: Date; } export interface Device { _id: string; _lastInform: Date; _registered: Date; _tags?: string[]; _timestamp?: Date; } type Configuration = | { type: "age"; name: string; age: number } | { type: "value"; name: string; value: boolean | number | string } | { type: "add_tag"; tag: string } | { type: "delete_tag"; tag: string } | { type: "add_object"; name: string; object: string } | { type: "delete_object"; name: string; object: string } | { type: "provision"; name: string; args?: string[] }; export interface Preset { _id: string; weight: number; channel: string; events: Record; configurations: Configuration[]; } export interface Object { _id: string; } export interface Provision { _id: string; script: string; } export interface VirtualParameter { _id: string; script: string; } export interface File { _id: string; length: number; filename: string; uploadDate: Date; metadata?: { fileType?: string; oui?: string; productClass?: string; version?: string; }; } export interface Permission { _id: string; role: string; resource: string; access: 1 | 2 | 3; filter?: string; validate?: string; } export interface User { _id: string; password: string; roles: string; salt: string; } export interface Lock { _id: string; value: string; timestamp: Date; expire: Date; } ================================================ FILE: lib/db/util.ts ================================================ import Expression, { Value } from "../common/expression.ts"; import Path from "../common/path.ts"; import { encodeTag } from "../util.ts"; // Optimize projection by removing overlaps // This can modify the object export function optimizeProjection(obj: { [path: string]: 1 }): { [path: string]: 1; } { if (obj[""]) return { "": obj[""] }; const keys = Object.keys(obj).sort(); if (keys.length <= 1) return obj; for (let i = 1; i < keys.length; ++i) { const a = keys[i - 1]; const b = keys[i]; if (b.startsWith(a)) { if (b.charAt(a.length) === "." || b.charAt(a.length - 1) === ".") { delete obj[b]; keys.splice(i--, 1); } } } return obj; } export function convertOldPrecondition(q: Record): Expression { function recursive(_query): Expression { let res: Expression = new Expression.Literal(true); for (const [k, v] of Object.entries(_query)) { if (k[0] === "$") { if (k === "$and") { for (const vv of Object.values(v)) res = Expression.and(res, recursive(vv)); } else if (k === "$or") { let or: Expression = new Expression.Literal(false); for (const vv of Object.values(v)) or = Expression.or(or, recursive(vv)); res = Expression.and(res, or); } else { throw new Error(`Operator ${k} not supported`); } } else if (k === "_tags") { if (typeof v === "object") { if (Array.isArray(v)) throw new Error(`Invalid type`); for (const [op, val] of Object.entries(v)) { if (op === "$ne") { if (typeof v["$ne"] !== "string") throw new Error("Only string values are allowed for _tags"); res = Expression.and( res, new Expression.Unary( "IS NULL", new Expression.Parameter( Path.parse(`Tags.${encodeTag(val)}`), ), ), ); } else if (op === "$eq") { if (typeof v["$eq"] !== "string") throw new Error("Only string values are allowed for _tags"); res = Expression.and( res, new Expression.Unary( "IS NOT NULL", new Expression.Parameter( Path.parse(`Tags.${encodeTag(val)}`), ), ), ); } else { throw new Error(`Invalid tag query`); } } } else { res = Expression.and( res, new Expression.Unary( "IS NOT NULL", new Expression.Parameter( Path.parse(`Tags.${encodeTag(v as string)}`), ), ), ); } } else if (k.startsWith("Tags.")) { let exists: boolean; if (typeof v === "boolean") exists = v; else if (v.hasOwnProperty("$eq")) exists = !!v["$eq"]; else if (v.hasOwnProperty("$ne")) exists = !v["$ne"]; else if (v.hasOwnProperty("$exists")) exists = !!v["$exists"]; else throw new Error(`Invalid tag query`); res = Expression.and( res, new Expression.Unary( exists ? "IS NOT NULL" : "IS NULL", new Expression.Parameter(Path.parse(k)), ), ); } else if (typeof v === "object") { if (Array.isArray(v)) throw new Error(`Invalid type`); for (const [kk, vv] of Object.entries(v)) { if (kk === "$eq") { res = Expression.and( res, new Expression.Binary( "=", new Expression.Parameter(Path.parse(k)), new Expression.Literal(vv), ), ); } else if (kk === "$ne") { const p = new Expression.Parameter(Path.parse(k)); res = Expression.and( res, Expression.or( new Expression.Binary("<>", p, new Expression.Literal(vv)), new Expression.Unary("IS NULL", p), ), ); } else if (kk === "$lt") { res = Expression.and( res, new Expression.Binary( "<", new Expression.Parameter(Path.parse(k)), new Expression.Literal(vv), ), ); } else if (kk === "$lte") { res = Expression.and( res, new Expression.Binary( "<=", new Expression.Parameter(Path.parse(k)), new Expression.Literal(vv), ), ); } else if (kk === "$gt") { res = Expression.and( res, new Expression.Binary( ">", new Expression.Parameter(Path.parse(k)), new Expression.Literal(vv), ), ); } else if (kk === "$gte") { res = Expression.and( res, new Expression.Binary( ">=", new Expression.Parameter(Path.parse(k)), new Expression.Literal(vv), ), ); } else { throw new Error(`Operator ${kk} not supported`); } if (!["string", "number", "boolean"].includes(typeof vv)) throw new Error(`Invalid value for ${kk} operator`); } } else { res = Expression.and( res, new Expression.Binary( "=", new Expression.Parameter(Path.parse(k)), new Expression.Literal(v as Value), ), ); } } return res; } // empty filter if (!Object.keys(q).length) return new Expression.Literal(true); return recursive(q); } ================================================ FILE: lib/debug.ts ================================================ import { IncomingMessage, ServerResponse, ClientRequest } from "node:http"; import { Socket } from "node:net"; import { appendFileSync } from "node:fs"; import { stringify } from "./common/yaml.ts"; import * as config from "./config.ts"; import { getSocketEndpoints } from "./server.ts"; const DEBUG_FILE = "" + config.get("DEBUG_FILE"); const DEBUG_FORMAT = "" + config.get("DEBUG_FORMAT"); const connectionTimestamps = new WeakMap(); function getConnectionTimestamp(connection: Socket): Date { let t = connectionTimestamps.get(connection); if (!t) { t = new Date(); connectionTimestamps.set(connection, t); } return t; } export function incomingHttpRequest( httpRequest: IncomingMessage, deviceId: string, body: string, ): void { if (!DEBUG_FILE) return; const now = new Date(); const con = httpRequest.socket; const socketEndpoints = getSocketEndpoints(con); const msg = { event: "incoming HTTP request", timestamp: now, remoteAddress: socketEndpoints.remoteAddress, deviceId: deviceId, connection: getConnectionTimestamp(con), localPort: socketEndpoints.localPort, method: httpRequest.method, url: httpRequest.url, headers: httpRequest.headers, body: body, }; if (DEBUG_FORMAT === "yaml") appendFileSync(DEBUG_FILE, "---\n" + stringify(msg)); else if (DEBUG_FORMAT === "json") appendFileSync(DEBUG_FILE, JSON.stringify(msg) + "\n"); else throw new Error(`Unrecognized DEBUG_FORMAT option`); } export function outgoingHttpResponse( httpResponse: ServerResponse, deviceId: string, body: string, ): void { if (!DEBUG_FILE) return; const now = new Date(); const con = httpResponse.socket; const socketEndpoints = getSocketEndpoints(con); const msg = { event: "outgoing HTTP response", timestamp: now, remoteAddress: socketEndpoints.remoteAddress, deviceId: deviceId, connection: getConnectionTimestamp(con), statusCode: httpResponse.statusCode, headers: httpResponse.getHeaders(), body: body, }; if (DEBUG_FORMAT === "yaml") appendFileSync(DEBUG_FILE, "---\n" + stringify(msg)); else if (DEBUG_FORMAT === "json") appendFileSync(DEBUG_FILE, JSON.stringify(msg) + "\n"); else throw new Error(`Unrecognized DEBUG_FORMAT option`); } export function outgoingHttpRequest( httpRequest: ClientRequest, deviceId: string, method: "GET" | "PUT" | "POST" | "DELETE", url: URL, body: string, ): void { if (!DEBUG_FILE) return; const now = new Date(); const con = httpRequest.socket; const msg = { event: "outgoing HTTP request", timestamp: now, remoteAddress: con.remoteAddress, deviceId: deviceId, connection: getConnectionTimestamp(con), remotePort: url.port, method: method, url: url.pathname + url.search, headers: httpRequest.getHeaders(), body: body, }; if (DEBUG_FORMAT === "yaml") appendFileSync(DEBUG_FILE, "---\n" + stringify(msg)); else if (DEBUG_FORMAT === "json") appendFileSync(DEBUG_FILE, JSON.stringify(msg) + "\n"); else throw new Error(`Unrecognized DEBUG_FORMAT option`); } export function outgoingHttpRequestError( httpRequest: ClientRequest, deviceId: string, method: "GET" | "PUT" | "POST" | "DELETE", url: URL, err: Error, ): void { if (!DEBUG_FILE) return; const now = new Date(); const msg = { event: "outgoing HTTP request", timestamp: now, remoteAddress: url.hostname, deviceId: deviceId, connection: null, remotePort: url.port, method: method, url: url.pathname + url.search, headers: httpRequest.getHeaders(), error: err.message, }; if (DEBUG_FORMAT === "yaml") appendFileSync(DEBUG_FILE, "---\n" + stringify(msg)); else if (DEBUG_FORMAT === "json") appendFileSync(DEBUG_FILE, JSON.stringify(msg) + "\n"); else throw new Error(`Unrecognized DEBUG_FORMAT option`); } export function incomingHttpResponse( httpResponse: IncomingMessage, deviceId: string, body: string, ): void { if (!DEBUG_FILE) return; const now = new Date(); const con = httpResponse.socket; const msg = { event: "incoming HTTP response", timestamp: now, remoteAddress: con.remoteAddress, deviceId: deviceId, connection: getConnectionTimestamp(httpResponse.socket), statusCode: httpResponse.statusCode, headers: httpResponse.headers, body: body, }; if (DEBUG_FORMAT === "yaml") appendFileSync(DEBUG_FILE, "---\n" + stringify(msg)); else if (DEBUG_FORMAT === "json") appendFileSync(DEBUG_FILE, JSON.stringify(msg) + "\n"); else throw new Error(`Unrecognized DEBUG_FORMAT option`); } export function outgoingUdpMessage( remoteAddress: string, deviceId: string, remotePort: number, body: string, ): void { if (!DEBUG_FILE) return; const now = new Date(); const msg = { event: "outgoing UDP message", timestamp: now, remoteAddress: remoteAddress, deviceId: deviceId, remotePort: remotePort, body: body, }; if (DEBUG_FORMAT === "yaml") appendFileSync(DEBUG_FILE, "---\n" + stringify(msg)); else if (DEBUG_FORMAT === "json") appendFileSync(DEBUG_FILE, JSON.stringify(msg) + "\n"); else throw new Error(`Unrecognized DEBUG_FORMAT option`); } export function clientError(remoteAddress: string, err: Error): void { if (!DEBUG_FILE) return; const now = new Date(); const msg = { event: "client error", timestamp: now, remoteAddress: remoteAddress, error: err.message, }; if (DEBUG_FORMAT === "yaml") appendFileSync(DEBUG_FILE, "---\n" + stringify(msg)); else if (DEBUG_FORMAT === "json") appendFileSync(DEBUG_FILE, JSON.stringify(msg) + "\n"); else throw new Error(`Unrecognized DEBUG_FORMAT option`); } export function outgoingXmppStanza(deviceId: string, body: string): void { if (!DEBUG_FILE) return; const now = new Date(); const msg = { event: "outgoing XMPP stanza", timestamp: now, deviceId: deviceId, body: body, }; if (DEBUG_FORMAT === "yaml") appendFileSync(DEBUG_FILE, "---\n" + stringify(msg)); else if (DEBUG_FORMAT === "json") appendFileSync(DEBUG_FILE, JSON.stringify(msg) + "\n"); else throw new Error(`Unrecognized DEBUG_FORMAT option`); } export function incomingXmppStanza(deviceId: string, body: string): void { if (!DEBUG_FILE) return; const now = new Date(); const msg = { event: "incoming XMPP stanza", timestamp: now, deviceId: deviceId, body: body, }; if (DEBUG_FORMAT === "yaml") appendFileSync(DEBUG_FILE, "---\n" + stringify(msg)); else if (DEBUG_FORMAT === "json") appendFileSync(DEBUG_FILE, JSON.stringify(msg) + "\n"); else throw new Error(`Unrecognized DEBUG_FORMAT option`); } ================================================ FILE: lib/default-provisions.ts ================================================ import Path from "./common/path.ts"; import * as config from "./config.ts"; import * as device from "./device.ts"; import * as scheduling from "./scheduling.ts"; import { SessionContext, Declaration } from "./types.ts"; const MAX_DEPTH = +config.get("MAX_DEPTH"); export function refresh( sessionContext: SessionContext, provision: (string | number | boolean)[], declarations: Declaration[], ): boolean { if ( (provision.length !== 2 || typeof provision[1] !== "string") && (provision.length !== 3 || typeof provision[1] !== "string" || typeof provision[2] !== "number") && (provision.length < 4 || typeof provision[1] !== "string" || typeof provision[2] !== "number" || typeof provision[3] !== "boolean") ) throw new Error("Invalid arguments"); const every = 1000 * ((provision[2] as number) || 1); const offset = scheduling.variance(sessionContext.deviceId, every); const t = scheduling.interval(sessionContext.timestamp, every, offset); let attrGet; let refreshChildren; if (provision[3] == null) { refreshChildren = true; attrGet = { object: 1, writable: 1, value: t }; } else { attrGet = {}; refreshChildren = !!provision[3]; for (const a of provision.slice(4)) attrGet[a as string] = t; } let path = Path.parse(provision[1]); let l = path.length; if (refreshChildren) { const segments = path.segments.slice(); l = segments.length; segments.length = MAX_DEPTH; segments.fill("*", l); path = Path.parse(segments.join(".")); } for (let i = l; i <= path.length; ++i) { declarations.push({ path: path.slice(0, i), pathGet: t, pathSet: null, attrGet: attrGet, attrSet: null, defer: true, }); } return true; } export function value( sessionContext: SessionContext, provision: (string | number | boolean)[], declarations: Declaration[], ): boolean { if ( provision.length < 3 || provision.length > 4 || typeof provision[1] !== "string" ) throw new Error("Invalid arguments"); let attr: string, val: any; if (provision.length === 3) { attr = "value"; val = provision[2]; } else { attr = (provision[2] as string) || ""; val = provision[3]; } if (attr === "accessList") { val = (val || "") .split(",") .map((s) => s.trim()) .filter((s) => !!s); } else if (attr === "value") { val = [val]; } declarations.push({ path: Path.parse(provision[1]), pathGet: 1, pathSet: null, attrGet: { [attr]: 1 }, attrSet: { [attr]: val }, defer: true, }); return true; } export function tag( sessionContext: SessionContext, provision: (string | number | boolean)[], declarations: Declaration[], ): boolean { if ( provision.length !== 3 || typeof provision[1] !== "string" || typeof provision[2] !== "boolean" ) throw new Error("Invalid arguments"); declarations.push({ path: Path.parse(`Tags.${provision[1]}`), pathGet: 1, pathSet: null, attrGet: { value: 1 }, attrSet: { value: [provision[2]] }, defer: true, }); return true; } export function reboot( sessionContext: SessionContext, provision: (string | number | boolean)[], declarations: Declaration[], ): boolean { if (provision.length !== 1) throw new Error("Invalid arguments"); declarations.push({ path: Path.parse("Reboot"), pathGet: 1, pathSet: null, attrGet: { value: 1 }, attrSet: { value: [sessionContext.timestamp] }, defer: true, }); return true; } export function reset( sessionContext: SessionContext, provision: (string | number | boolean)[], declarations: Declaration[], ): boolean { if (provision.length !== 1) throw new Error("Invalid arguments"); declarations.push({ path: Path.parse("FactoryReset"), pathGet: 1, pathSet: null, attrGet: { value: 1 }, attrSet: { value: [sessionContext.timestamp] }, defer: true, }); return true; } export function download( sessionContext: SessionContext, provision: (string | number | boolean)[], declarations: Declaration[], ): boolean { if ( (provision.length !== 3 || typeof provision[1] !== "string" || typeof provision[2] !== "string") && (provision.length !== 4 || typeof provision[1] !== "string" || typeof provision[2] !== "string" || typeof provision[3] !== "string") ) throw new Error("Invalid arguments"); const alias = [ `FileType:${JSON.stringify(provision[1] || "")}`, `FileName:${JSON.stringify(provision[2] || "")}`, `TargetFileName:${JSON.stringify(provision[3] || "")}`, ].join(","); declarations.push({ path: Path.parse(`Downloads.[${alias}]`), pathGet: 1, pathSet: 1, attrGet: null, attrSet: null, defer: true, }); declarations.push({ path: Path.parse(`Downloads.[${alias}].Download`), pathGet: 1, pathSet: null, attrGet: { value: 1 }, attrSet: { value: [sessionContext.timestamp] }, defer: true, }); return true; } export function instances( sessionContext: SessionContext, provision: (string | number | boolean)[], declarations: Declaration[], startRevision: number, endRevision: number, ): boolean { if (provision.length !== 3 || typeof provision[1] !== "string") throw new Error("Invalid arguments"); let count = Number(provision[2]); if (Number.isNaN(count)) throw new Error("Invalid arguments"); const path = Path.parse(provision[1]); if (provision[2][0] === "+" || provision[2][0] === "-") { declarations.push({ path: path, pathGet: 1, pathSet: null, attrGet: null, attrSet: null, defer: true, }); if (endRevision === startRevision) return false; const unpacked = device.unpack( sessionContext.deviceData, path, startRevision + 1, ); count = Math.max(0, unpacked.length + count); } declarations.push({ path: path, pathGet: 1, pathSet: count, attrGet: null, attrSet: null, defer: true, }); return true; } ================================================ FILE: lib/device.ts ================================================ import Expression, { Value } from "./common/expression.ts"; import Path from "./common/path.ts"; import { DeviceData, Declaration, Clear, AttributeTimestamps, Attributes, } from "./types.ts"; const CHANGE_FLAGS = { object: 2, writable: 4, value: 8, notification: 16, accessList: 32, }; function parseBool(v): boolean { v = "" + v; if (v === "true" || v === "TRUE" || v === "True" || v === "1") return true; else if (v === "false" || v === "FALSE" || v === "False" || v === "0") return false; else return null; } export function sanitizeParameterValue( parameterValue: [string | number | boolean, string], ): [string | number | boolean, string] { if (parameterValue[0] != null) { switch (parameterValue[1]) { case "xsd:boolean": if (typeof parameterValue[0] !== "boolean") { const b = parseBool(parameterValue[0]); if (b == null) parameterValue[0] = "" + parameterValue[0]; else parameterValue[0] = b; } break; case "xsd:int": case "xsd:unsignedInt": if (typeof parameterValue[0] !== "number") { const i = parseInt(parameterValue[0] as string); if (isNaN(i)) parameterValue[0] = "" + parameterValue[0]; else parameterValue[0] = i; } break; case "xsd:dateTime": if (typeof parameterValue[0] !== "number") { // Don't use parseInt because it reads date string as a number let i = +parameterValue[0]; if (isNaN(i)) { i = Date.parse(parameterValue[0] as string); if (isNaN(i)) parameterValue[0] = "" + parameterValue[0]; else parameterValue[0] = i; } else { parameterValue[0] = i; } } break; default: parameterValue[0] = "" + parameterValue[0]; break; } } return parameterValue; } export function getAliasDeclarations( path: Path, timestamp: number, attrGet = null, ): Declaration[] { const stripped = path.stripAlias(); let decs: Declaration[] = [ { path: stripped, pathGet: timestamp, pathSet: null, attrGet: attrGet, attrSet: null, defer: true, }, ]; if (path.alias) { for (const [i, alias] of path.segments.entries()) { if (alias instanceof Expression) { const parent = stripped.slice(0, i + 1); for (const [p] of expressionToAlias(alias)) { decs = decs.concat( getAliasDeclarations(parent.concat(p), timestamp, { value: timestamp, }), ); } } } } return decs; } export function expressionToAlias(exp: Expression): [Path, Value][] { if (exp instanceof Expression.Literal && exp.value === true) return []; if (exp instanceof Expression.Binary) { if (exp.operator === "AND") return [...expressionToAlias(exp.left), ...expressionToAlias(exp.right)]; else if (exp.operator === "=") { if ( exp.left instanceof Expression.Parameter && exp.right instanceof Expression.Literal ) return [[exp.left.path, exp.right.value]]; } } throw new Error("Invalid alias expression"); } export function unpack( deviceData: DeviceData, path: Path, revision?: number, ): Path[] { let allMatches = [] as Path[]; if (!path.alias) { for (const p of deviceData.paths.findCompat(path, false, true)) if (deviceData.attributes.has(p, revision)) allMatches.push(p); } else { const wildcardPath = path.stripAlias(); for (const p of deviceData.paths.findCompat(wildcardPath, false, true)) if (deviceData.attributes.has(p, revision)) allMatches.push(p); for (let i = path.length - 1; i >= 0; --i) { if (path.alias & (1 << i)) { for (const [param, val] of expressionToAlias( path.segments[i] as Expression, )) { const p = wildcardPath.slice(0, i + 1).concat(param); const unpacked = unpack(deviceData, p, revision); const filtered: Path[] = []; for (const up of unpacked) { const attributes = deviceData.attributes.get(up, revision); if ( attributes && attributes.value && attributes.value[1] && sanitizeParameterValue([val, attributes.value[1][1]])[0] === attributes.value[1][0] ) { for (let m = 0; m < allMatches.length; ++m) { let k; const match = allMatches[m]; if (!match) continue; for (k = i; k >= 0; --k) if (match.segments[k] !== up.segments[k]) break; if (k < 0) { filtered.push(match); allMatches[m] = null; } } } } allMatches = filtered; } } } } allMatches.sort((p1, p2) => { for (let i = 0; i < p1.length; ++i) { const a = p1.segments[i] as string; const b = p2.segments[i] as string; if (a !== b) { // Use numeric sorting for numbers const ia = parseInt(a); const ib = parseInt(b); if (ia === +a && ib === +b) return ia - ib; else if (a < b) return -1; else return 1; } } return 0; }); return allMatches; } export function clear( deviceData: DeviceData, path: Path, timestamp: number, attributes: AttributeTimestamps, changeFlags = 0, ): void { const changeTrackers = {}; timestamp = timestamp || 0; let descendantsTimestamp = timestamp; if (attributes?.object) { if (attributes.object > descendantsTimestamp) descendantsTimestamp = attributes.object; if (!(attributes.object <= attributes.value)) attributes.value = attributes.object; } for (const p of deviceData.paths.findCompat( path, true, true, descendantsTimestamp ? 99 : path.length, )) { const tracker = deviceData.trackers.get(p); for (const k in tracker) changeTrackers[k] |= tracker[k]; const currentTimestamp = deviceData.timestamps.get(p); if (currentTimestamp === undefined) continue; if ( timestamp > currentTimestamp || (descendantsTimestamp > currentTimestamp && p.length > path.length) ) { deviceData.timestamps.delete(p); deviceData.attributes.delete(p); changeFlags |= 1; } else if (attributes && p.length === path.length) { const currentAttributes = deviceData.attributes.get(p); if (currentAttributes) { let newAttrs; for (const attrName in attributes) { if ( attrName in currentAttributes && attributes[attrName] > currentAttributes[attrName][0] ) { changeFlags |= CHANGE_FLAGS[attrName]; if (!newAttrs) { newAttrs = Object.assign({}, currentAttributes); deviceData.attributes.set(p, newAttrs); } delete newAttrs[attrName]; } } } } } // Note: For performance, we're merging all changes together rather than // mark changes based the exact parameters affected. for (const k in changeTrackers) if (changeTrackers[k] & changeFlags) deviceData.changes.add(k); } function compareEquality(a, b): boolean { const t = typeof a; if ( a === null || a === undefined || t === "number" || t === "boolean" || t === "string" || t === "symbol" ) return a === b; return JSON.stringify(a) === JSON.stringify(b); } export function set( deviceData: DeviceData, pathStr: string, timestamp: number, attributes: Attributes, toClear?: Clear[], ): Clear[] { const path = deviceData.paths.add(pathStr); const currentTimestamp = deviceData.timestamps.get(path); let currentAttributes; if (path.wildcard) attributes = undefined; else if (currentTimestamp) currentAttributes = deviceData.attributes.get(path); let changeFlags = 0; if (attributes) { if ( attributes.value && attributes.value[1] && attributes.value[0] >= (attributes.object ? attributes.object[0] : 0) ) attributes.object = [attributes.value[0], 0]; if ( attributes.object && attributes.object[1] && attributes.object[0] >= (attributes.value ? attributes.value[0] : 0) ) attributes.value = [attributes.object[0], null]; const newAttributes = Object.assign({}, currentAttributes, attributes); if (currentAttributes) { for (const attrName in attributes) { timestamp = Math.max(timestamp, attributes[attrName][0]); if (!(attrName in currentAttributes)) changeFlags |= CHANGE_FLAGS[attrName]; else if (attributes[attrName][0] <= currentAttributes[attrName][0]) newAttributes[attrName] = currentAttributes[attrName]; else if ( !compareEquality( attributes[attrName][1], currentAttributes[attrName][1], ) ) changeFlags |= CHANGE_FLAGS[attrName]; } } else { changeFlags |= 1; } deviceData.attributes.set(path, newAttributes); if (!(timestamp <= currentTimestamp)) { deviceData.timestamps.set(path, timestamp); if (path.length > 1) { toClear = set( deviceData, path.slice(0, path.length - 1).toString(), timestamp, { object: [timestamp, 1] }, toClear, ); } } } else if (!(timestamp <= currentTimestamp)) { deviceData.timestamps.set(path, timestamp); if (currentAttributes) { deviceData.attributes.delete(path); changeFlags |= 1; } else if (path.wildcard) { for (const p of deviceData.paths.findCompat( path, false, true, path.length, )) { if (timestamp > deviceData.timestamps.get(p)) { toClear = toClear || []; toClear.push([p, timestamp]); } } } } if (changeFlags) { if (changeFlags & 1) { toClear = toClear || []; toClear.push([path, timestamp, null, changeFlags]); } else if (changeFlags & CHANGE_FLAGS.object) { toClear = toClear || []; toClear.push([path, 0, { object: attributes.object[0] }, changeFlags]); } else { for (const p of deviceData.paths.findCompat( path, true, false, path.length, )) { const tracker = deviceData.trackers.get(p); for (const k in tracker) if (tracker[k] & changeFlags) deviceData.changes.add(k); } } } return toClear; } export function track( deviceData: DeviceData, pathStr: string, marker: string, attributes?: string[], ): void { const path = deviceData.paths.add(pathStr); let f = 1; if (attributes) for (const attrName of attributes) f |= CHANGE_FLAGS[attrName]; let cur = deviceData.trackers.get(path); if (!cur) { cur = {}; deviceData.trackers.set(path, cur); } cur[marker] |= f; } export function clearTrackers( deviceData: DeviceData, tracker: string | string[], ): void { if (Array.isArray(tracker)) { for (const v of deviceData.trackers.values()) for (const t of tracker) delete v[t]; for (const t of tracker) deviceData.changes.delete(t); } else { for (const v of deviceData.trackers.values()) delete v[tracker]; deviceData.changes.delete(tracker); } } ================================================ FILE: lib/extensions.ts ================================================ import { spawn, ChildProcess } from "node:child_process"; import * as crypto from "node:crypto"; import readline from "node:readline"; import * as config from "./config.ts"; import { Fault } from "./types.ts"; import { ROOT_DIR } from "./config.ts"; import * as logger from "./logger.ts"; const TIMEOUT = +config.get("EXT_TIMEOUT"); const processes: { [script: string]: ChildProcess } = {}; const jobs = new Map(); export function run(args: string[]): Promise<{ fault: Fault; value: any }> { return new Promise((resolve) => { const scriptName = args[0]; const id = crypto.randomBytes(8).toString("hex"); jobs.set(id, resolve); if (!processes[scriptName]) { const p = spawn(ROOT_DIR + "/bin/genieacs-ext", [scriptName], { stdio: ["ignore", "pipe", "pipe", "ipc"], }); processes[scriptName] = p; p.on("error", (err) => { if (processes[scriptName] === p) { if (jobs.delete(id)) { resolve({ fault: { code: err.name, message: err.message }, value: null, }); } // eslint-disable-next-line @typescript-eslint/no-floating-promises kill(processes[scriptName]); delete processes[scriptName]; } }); p.on("disconnect", () => { if (processes[scriptName] === p) delete processes[scriptName]; }); p.on("message", (message) => { const func = jobs.get(message[0]); if (func) { jobs.delete(message[0]); // Wait for any disconnect even to fire setTimeout(() => { func({ fault: message[1], value: message[2] }); }); } }); const rlstdout = readline.createInterface(p.stdout); rlstdout.on("line", (line) => { logger.info({ message: `Ext ${scriptName}(${p.pid}): ${line}` }); }); const rlstderr = readline.createInterface(p.stderr); rlstderr.on("line", (line) => { logger.warn({ message: `Ext ${scriptName}(${p.pid}): ${line}` }); }); } setTimeout(() => { if (jobs.delete(id)) { resolve({ fault: { code: "timeout", message: "Extension timed out" }, value: null, }); } }, TIMEOUT); if (!processes[scriptName].connected) return false; return processes[scriptName].send([id, args.slice(1)]); }); } function kill(process: ChildProcess): Promise { return new Promise((resolve) => { const timeToKill = Date.now() + 5000; process.kill(); const t = setInterval(() => { if (!process.connected) { clearInterval(t); resolve(); } else if (Date.now() > timeToKill) { process.kill("SIGKILL"); clearInterval(t); resolve(); } }, 100); }); } export async function killAll(): Promise { await Promise.all( Object.entries(processes).map(([k, p]) => { delete processes[k]; return kill(p); }), ); } ================================================ FILE: lib/forwarded.ts ================================================ import { IncomingMessage } from "node:http"; import { TLSSocket } from "node:tls"; import { parseCIDR, parse, IPv6, IPv4 } from "ipaddr.js"; import * as config from "./config.ts"; import { getSocketEndpoints } from "./server.ts"; interface RequestOrigin { localAddress: string; localPort: number; remoteAddress: string; remotePort: number; host: string; encrypted: boolean; } const FORWARDED_HEADER = "" + config.get("FORWARDED_HEADER"); const cache = new WeakMap(); const cidrs: [IPv4 | IPv6, number][] = []; for (const str of FORWARDED_HEADER.split(",").map((s) => s.trim())) { try { cidrs.push(parseCIDR(str)); } catch { // Not a valid CIDR format, try parsing as IP try { const ip = parse(str); cidrs.push([ip, ip.toByteArray().length * 8]); } catch { // Not a valid IP either, ignore } } } function parseForwardedHeader(str: string): { [name: string]: string } { str = str.toLowerCase(); const res: { [name: string]: string } = {}; let keyIdx = 0; let valueIdx = -1; let key: string; for (let i = 0; i < str.length; ++i) { const char = str.charCodeAt(i); if (char === 61 /* = */) { if (keyIdx >= 0) { key = str.slice(keyIdx, i).trim(); keyIdx = -1; valueIdx = i + 1; } } else if (char === 59 /* ; */) { if (valueIdx >= 0) res[key] = str.slice(valueIdx, i).trim(); valueIdx = -1; keyIdx = i + 1; } else if (char === 44 /* , */) { if (valueIdx >= 0) res[key] = str.slice(valueIdx, i).trim(); return res; } else if (char === 34 /* " */) { if (valueIdx >= 0) { const quoteIdx = i; if (!str.slice(valueIdx, quoteIdx).trim()) { for (i = i + 1; i < str.length; ++i) { const c = str.charCodeAt(i); if (c === 92 /* \ */) ++i; if (c === 34 /* " */) { res[key] = JSON.parse(str.slice(quoteIdx, i + 1).trim()); valueIdx = -1; keyIdx = i + 1; break; } } } } } } if (valueIdx >= 0) res[key] = str.slice(valueIdx).trim(); return res; } export function getRequestOrigin(request: IncomingMessage): RequestOrigin { let origin = cache.get(request); if (!origin) { const soc = request.socket; const socketEndpoints = getSocketEndpoints(soc); origin = { localAddress: socketEndpoints.localAddress, localPort: socketEndpoints.localPort, remoteAddress: socketEndpoints.remoteAddress, remotePort: socketEndpoints.remotePort, host: request.headers["host"], encrypted: !!(request.socket as TLSSocket).encrypted, }; const header = request.headers["forwarded"]; if (header) { const ip = parse(socketEndpoints.remoteAddress); if ( cidrs.some((cidr) => ip.kind() === cidr[0].kind() && ip.match(cidr)) ) { const parsed = parseForwardedHeader(header); if (parsed["proto"] === "https") { origin.encrypted = true; origin.localPort = 443; } else if (parsed["proto"] === "http") { origin.encrypted = false; origin.localPort = 80; } if (parsed["host"]) { origin.host = parsed["host"]; const [, port] = parsed["host"].split(":", 2); origin.localPort = +port || origin.localPort; } if (parsed["for"]) { if (parsed["for"].startsWith("[")) { const i = parsed["for"].lastIndexOf("]"); if (i >= 0) { origin.remoteAddress = parsed["for"].slice(1, i); origin.remotePort = parseInt(parsed["for"].slice(i + 2)) || origin.remotePort; } } else { const i = parsed["for"].lastIndexOf(":"); if (i >= 0) { origin.remoteAddress = parsed["for"].slice(0, i); origin.remotePort = parseInt(parsed["for"].slice(i + 1)) || origin.remotePort; } else { origin.remoteAddress = parsed["for"]; } } } if (parsed["by"]) { if (parsed["by"].startsWith("[")) { const i = parsed["by"].lastIndexOf("]"); if (i >= 0) { origin.localAddress = parsed["by"].slice(1, i); origin.localPort = parseInt(parsed["by"].slice(i + 2)) || origin.localPort; } } else { const i = parsed["by"].lastIndexOf(":"); if (i >= 0) { origin.localAddress = parsed["by"].slice(0, i); origin.localPort = parseInt(parsed["by"].slice(i + 1)) || origin.localPort; } else { origin.localAddress = parsed["by"]; } } } } } cache.set(request, origin); } return origin; } ================================================ FILE: lib/fs.ts ================================================ import * as url from "node:url"; import { IncomingMessage, ServerResponse } from "node:http"; import { PassThrough, pipeline, Readable } from "node:stream"; import { createHash } from "node:crypto"; import { filesBucket, collections } from "./db/db.ts"; import * as logger from "./logger.ts"; import { getRequestOrigin } from "./forwarded.ts"; import memoize from "./common/memoize.ts"; const getFile = memoize( async ( etag: string, size: number, filename: string, ): Promise> => { const chunks: Buffer[] = []; // Using for-await over the download stream can throw ERR_STREAM_PREMATURE_CLOSE // for very small files. Possibly a bug in MongoDB driver or Nodejs itself. // Using a PassThrough stream to avoid this. const downloadStream = pipeline( filesBucket.openDownloadStreamByName(filename), new PassThrough(), (err) => { if (err) throw err; }, ); for await (const chunk of downloadStream) chunks.push(chunk); // Node 12-14 don't throw error when stream is closed prematurely. // However, we don't need to check for that since we're checking file size. if (size !== chunks.reduce((a, b) => a + b.length, 0)) throw new Error("File size mismatch"); return chunks; }, ); async function* partialContent( chunks: Iterable, start: number, end: number, ): AsyncIterable { let bytesToSkip = start; let bytesToRead = end - start; for (let chunk of chunks) { if (bytesToRead <= 0) return; if (bytesToSkip >= chunk.length) { bytesToSkip -= chunk.length; continue; } chunk = chunk.subarray(bytesToSkip, bytesToSkip + bytesToRead); bytesToRead -= chunk.length; bytesToSkip = 0; yield chunk; } } function generateETag(file: { _id: string; uploadDate: Date; length: number; }): string { const hash = createHash("md5"); hash.update(`${file._id}-${file.uploadDate.getTime()}-${file.length}`); return hash.digest("hex"); } function matchEtag(etag: string, header: string): boolean { for (let t of header.split(",")) { t = t.trim(); if (t.startsWith("W/")) t = t.substring(2); try { t = JSON.parse(t); } catch { // Ignore } if (t === "*") return true; if (etag === t) return true; } return false; } export async function listener( request: IncomingMessage, response: ServerResponse, ): Promise { if (request.method !== "GET" && request.method !== "HEAD") { response.writeHead(405, { Allow: "GET, HEAD" }); response.end("405 Method Not Allowed"); return; } const urlParts = url.parse(request.url, true); const filename = decodeURIComponent(urlParts.pathname.substring(1)); const log = { message: "Fetch file", filename: filename, remoteAddress: getRequestOrigin(request).remoteAddress, method: request.method, }; const file = await collections.files.findOne({ _id: filename }); if (!file) { response.writeHead(404); response.end(); log.message += " not found"; logger.accessError(log); return; } logger.accessInfo(log); const etag = generateETag(file); const lastModified = file["uploadDate"]; lastModified.setMilliseconds(0); let status = 200; let start = 0; let end = file.length; if (request.headers["if-match"]) if (!matchEtag(etag, request.headers["if-match"])) status = 412; if (request.headers["if-unmodified-since"]) { const d = new Date(request.headers["if-unmodified-since"]); if (lastModified > d) status = 412; } if (request.headers["if-none-match"]) { if (matchEtag(etag, request.headers["if-none-match"])) status = 304; } else if (request.headers["if-modified-since"]) { const d = new Date(request.headers["if-modified-since"]); if (lastModified <= d) status = 304; } if (request.headers.range && status === 200) { const match = request.headers.range.match(/^bytes=(\d*)-(\d*)$/); status = 416; if (match && (match[1] || match[2])) { if (match[2]) end = parseInt(match[2]) + 1; if (match[1]) start = parseInt(match[1]); else start = file.length - parseInt(match[2]); if (start < end && end <= file.length) status = 206; } if (request.headers["if-range"]) { const h = request.headers["if-range"] as string; const d = new Date(h); if (!matchEtag(etag, h) && !(lastModified <= d)) { status = 200; start = 0; end = file.length; } } } if (status === 412) { response.writeHead(412); response.end(); return; } if (status === 304) { response.writeHead(304, { ETag: etag, "Last-Modified": lastModified.toUTCString(), }); response.end(); return; } if (status === 416) { response.writeHead(416, { "Content-Range": `bytes */${file.length}`, "Content-Length": "0", }); response.end(); return; } response.writeHead(status, { "Content-Type": "application/octet-stream", "Content-Length": end - start, "Accept-Ranges": "bytes", ETag: etag, "Last-Modified": lastModified.toUTCString(), ...(status === 206 && { "Content-Range": `bytes ${start}-${end - 1}/${file.length}`, }), }); if (request.method === "HEAD") { response.end(); return; } const chunks = await getFile(etag, file.length, filename); pipeline(Readable.from(partialContent(chunks, start, end)), response, () => { // Ignore errors resulting from client disconnecting }); } ================================================ FILE: lib/gpn-heuristic.ts ================================================ import Path from "./common/path.ts"; const WILDCARD_MULTIPLIER = 2; const UNDISCOVERED_DEPTH = 7; // Simple heuristic to estimate GPN count given a set of patterns to be // discovered. Used to decide whether to use nextLevel = false in GPN. // gpnPatterns is [pattern, flags] // pattern is a path (array) // flags is an int where its bits mark the segments in the pattern that // need refreshing. Leading 0s indicate that the pattern up to that // point has been discovered. export function estimateGpnCount( gpnPatterns: [Path, number][], depth = 0, ): number { const children: { [segment: string]: [Path, number][] } = {}; const wildcardChildren: [Path, number][] = []; let wildcardDiscovered = false; let gpnCount = 0; for (const pattern of gpnPatterns) { const path = pattern[0]; const flags = pattern[1] >> depth; const k = path.segments[depth] as string; if (!k) { if (flags & 1) gpnCount = 1; continue; } if (flags & 1) { gpnCount = 1; if (depth > UNDISCOVERED_DEPTH) continue; } else if (k === "*") { wildcardDiscovered = true; } if (k === "*") { wildcardChildren.push(pattern); } else { children[k] = children[k] || []; children[k].push(pattern); } } let wildcardGpnCount = 0; if (!wildcardDiscovered && wildcardChildren.length) { wildcardGpnCount += estimateGpnCount(wildcardChildren, depth + 1) * WILDCARD_MULTIPLIER; } for (const k of Object.keys(children)) { const c = estimateGpnCount(children[k].concat(wildcardChildren), depth + 1); wildcardGpnCount -= c; gpnCount += c; } gpnCount += Math.max(0, wildcardGpnCount); return gpnCount; } ================================================ FILE: lib/init.ts ================================================ import { getRevision, getUiConfig, getUsers } from "./ui/local-cache.ts"; import { generateSalt, hashPassword } from "./auth.ts"; import { collections } from "./db/db.ts"; import { putConfig, putPermission, putPreset, putProvision, putUser, putView, } from "./ui/db.ts"; import { del } from "./cache.ts"; import BOOTSTRAP_SCRIPT from "../seed/bootstrap.js" with { type: "text" }; import DEFAULT_SCRIPT from "../seed/default.js" with { type: "text" }; import INFORM_SCRIPT from "../seed/inform.js" with { type: "text" }; import OVERVIEW_PAGE from "../seed/overview-page.jsx" with { type: "text" }; import PIE_CHART from "../seed/pie-chart.jsx" with { type: "text" }; import DEVICE_PAGE from "../seed/device-page.jsx" with { type: "text" }; import DEVICE_PAGE_TR098 from "../seed/device-page-tr098.jsx" with { type: "text" }; import DEVICE_PAGE_TR181 from "../seed/device-page-tr181.jsx" with { type: "text" }; import PARAMETER from "../seed/parameter.jsx" with { type: "text" }; import SUMMON_BUTTON from "../seed/summon-button.jsx" with { type: "text" }; import ICON from "../seed/icon.jsx" with { type: "text" }; import DATAMODEL_EXPLORER from "../seed/datamodel-explorer.jsx" with { type: "text" }; import INSTANCE_TABLE from "../seed/instance-table.jsx" with { type: "text" }; import TAGS from "../seed/tags.jsx" with { type: "text" }; interface Status { users: boolean; presets: boolean; filters: boolean; device: boolean; index: boolean; overview: boolean; } export async function getStatus(): Promise { const [configSnapshot, presetCount] = await Promise.all([ getRevision(), collections.presets.countDocuments(), ]); const users = getUsers(configSnapshot); const ui = getUiConfig(configSnapshot); const status = { users: !Object.keys(users).length, presets: !presetCount, filters: true, device: true, index: true, overview: true, }; for (const k of Object.keys(ui)) { if (k.startsWith("filters.")) status.filters = false; if (k === "device" || k.startsWith("device.")) status.device = false; if (k.startsWith("index.")) status.index = false; if (k === "overview" || k.startsWith("overview.")) status.overview = false; } return status; } export async function seed(options: Record): Promise { const resources = {}; const proms = []; if (options.users) { resources["permissions"] = [ { role: "admin", resource: "devices", access: 3, validate: "true" }, { role: "admin", resource: "faults", access: 3, validate: "true" }, { role: "admin", resource: "files", access: 3, validate: "true" }, { role: "admin", resource: "presets", access: 3, validate: "true" }, { role: "admin", resource: "provisions", access: 3, validate: "true" }, { role: "admin", resource: "config", access: 3, validate: "true" }, { role: "admin", resource: "permissions", access: 3, validate: "true" }, { role: "admin", resource: "users", access: 3, validate: "true" }, { role: "admin", resource: "virtualParameters", access: 3, validate: "true", }, { role: "admin", resource: "views", access: 3, validate: "true", }, ]; resources["users"] = [ { username: "admin", password: "admin", roles: ["admin"] }, ]; } if (options.filters) { resources["config"] = (resources["config"] || []).concat([ { _id: "ui.filters.0.label", value: "'Serial number'" }, { _id: "ui.filters.0.parameter", value: "DeviceID.SerialNumber" }, { _id: "ui.filters.0.type", value: "'string'" }, { _id: "ui.filters.1.label", value: "'Product class'" }, { _id: "ui.filters.1.parameter", value: "DeviceID.ProductClass" }, { _id: "ui.filters.1.type", value: "'string'" }, { _id: "ui.filters.2.label", value: "'Tag'" }, { _id: "ui.filters.2.type", value: "'tag'" }, ]); } if (options.device) { resources["config"] = (resources["config"] || []).concat([ { _id: "ui.device", value: "'device-page'" }, ]); resources["views"] = (resources["views"] || []).concat([ { _id: "device-page", script: DEVICE_PAGE }, { _id: "device-page-tr098", script: DEVICE_PAGE_TR098 }, { _id: "device-page-tr181", script: DEVICE_PAGE_TR181 }, { _id: "parameter", script: PARAMETER }, { _id: "summon-button", script: SUMMON_BUTTON }, { _id: "icon", script: ICON }, { _id: "datamodel-explorer", script: DATAMODEL_EXPLORER }, { _id: "instance-table", script: INSTANCE_TABLE }, { _id: "tags", script: TAGS }, ]); } if (options.index) { resources["config"] = (resources["config"] || []).concat([ { _id: "ui.index.0.type", value: "'device-link'" }, { _id: "ui.index.0.label", value: "'Serial number'" }, { _id: "ui.index.0.parameter", value: "DeviceID.SerialNumber" }, { _id: "ui.index.0.components.0.type", value: "'parameter'" }, { _id: "ui.index.1.label", value: "'Product class'" }, { _id: "ui.index.1.parameter", value: "DeviceID.ProductClass" }, { _id: "ui.index.2.label", value: "'Software version'" }, { _id: "ui.index.2.parameter", value: "InternetGatewayDevice.DeviceInfo.SoftwareVersion", }, { _id: "ui.index.3.label", value: "'IP'" }, { _id: "ui.index.3.parameter", value: "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.ExternalIPAddress", }, { _id: "ui.index.4.label", value: "'SSID'" }, { _id: "ui.index.4.parameter", value: "InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.SSID", }, { _id: "ui.index.5.type", value: "'container'" }, { _id: "ui.index.5.label", value: "'Last inform'" }, { _id: "ui.index.5.element", value: "'span.inform'" }, { _id: "ui.index.5.parameter", value: "DATE_STRING(Events.Inform)" }, { _id: "ui.index.5.components.0.type", value: "'parameter'" }, { _id: "ui.index.5.components.1.chart", value: "'online'" }, { _id: "ui.index.5.components.1.type", value: "'overview-dot'" }, { _id: "ui.index.6.type", value: "'tags'" }, { _id: "ui.index.6.label", value: "'Tags'" }, { _id: "ui.index.6.parameter", value: "Tags" }, { _id: "ui.index.6.unsortable", value: "true" }, { _id: "ui.index.6.writable", value: "false" }, ]); } if (options.overview) { resources["config"] = (resources["config"] || []).concat([ { _id: "ui.overview", value: "'overview-page'" }, ]); resources["views"] = (resources["views"] || []).concat([ { _id: "overview-page", script: OVERVIEW_PAGE }, { _id: "pie-chart", script: PIE_CHART }, ]); } if (options.presets) { resources["presets"] = [ { _id: "bootstrap", weight: 0, channel: "bootstrap", events: "0 BOOTSTRAP", provision: "bootstrap", }, { _id: "default", weight: 0, channel: "default", provision: "default" }, { _id: "inform", weight: 0, channel: "inform", provision: "inform" }, ]; resources["provisions"] = [ { _id: "bootstrap", script: BOOTSTRAP_SCRIPT }, { _id: "default", script: DEFAULT_SCRIPT }, { _id: "inform", script: INFORM_SCRIPT }, ]; } if (resources["permissions"]) { for (const p of resources["permissions"]) { p["_id"] = `${p["role"]}:${p["resource"]}:${p["access"]}`; proms.push(putPermission(p["_id"], p)); } } if (resources["users"]) { for (const u of resources["users"]) { u["salt"] = await generateSalt(64); u["password"] = await hashPassword(u["password"], u["salt"]); u["roles"] = (u["roles"] || []).join(","); u["_id"] = u["username"]; delete u["username"]; proms.push(putUser(u["_id"], u)); } } if (resources["provisions"]) { for (const p of resources["provisions"]) proms.push(putProvision(p["_id"], p)); } if (resources["presets"]) for (const p of resources["presets"]) proms.push(putPreset(p["_id"], p)); if (resources["views"]) for (const v of resources["views"]) proms.push(putView(v["_id"], v)); if (resources["config"]) for (const c of resources["config"]) proms.push(putConfig(c["_id"], c)); await proms; await Promise.all([del("ui-local-cache-hash"), del("cwmp-local-cache-hash")]); } ================================================ FILE: lib/instance-set.ts ================================================ interface Instance { [name: string]: string; } export default class InstanceSet { declare private set: Set; public constructor() { this.set = new Set(); } public add(instance: Instance): void { this.set.add(instance); } public delete(instance: Instance): void { this.set.delete(instance); } public superset(instance: Instance): Instance[] { const res = []; for (const inst of this.set) { let match = true; for (const k in instance) { if (inst[k] !== instance[k]) { match = false; break; } } if (match) res.push(inst); } res.sort((a, b) => { const keysA = Object.keys(a); const keysB = Object.keys(b); if (keysA.length !== keysB.length) return keysB.length - keysA.length; keysA.sort(); keysB.sort(); for (let i = 0; i < keysA.length; ++i) { if (keysA[i] > keysB[i]) return 1; else if (keysA[i] < keysB[i]) return -1; else if (a[keysA[i]] > b[keysB[i]]) return 1; else if (a[keysA[i]] < b[keysB[i]]) return -1; } return 0; }); return res; } public subset(instance: Instance): Instance[] { const res = []; for (const inst of this.set) { let match = true; for (const k in inst) { if (inst[k] !== instance[k]) { match = false; break; } } if (match) res.push(inst); } res.sort((a, b) => { const keysA = Object.keys(a); const keysB = Object.keys(b); if (keysA.length !== keysB.length) return keysA.length - keysB.length; keysA.sort(); keysB.sort(); for (let i = 0; i < keysA.length; ++i) { if (keysA[i] > keysB[i]) return 1; else if (keysA[i] < keysB[i]) return -1; else if (a[keysA[i]] > b[keysB[i]]) return 1; else if (a[keysA[i]] < b[keysB[i]]) return -1; } return 0; }); return res; } public [Symbol.iterator](): IterableIterator { return this.set.values(); } public forEach(callback: (instance: Instance) => void): void { this.set.forEach(callback); } public values(): IterableIterator { return this.set.values(); } public clear(): void { this.set.clear(); } public get size(): number { return this.set.size; } } ================================================ FILE: lib/local-cache.ts ================================================ import { setTimeoutPromise } from "./util.ts"; import { get, set } from "./cache.ts"; import { acquireLock, releaseLock } from "./lock.ts"; const REFRESH = 5000; const EVICT_TIMEOUT = 120000; export class LocalCache { private nextRefresh = 1; private currentRevision: string = null; private snapshots: Map = new Map(); constructor( private cacheKey: string, private callback: () => Promise<[string, T]>, ) {} async getRevision(): Promise { if (Date.now() > this.nextRefresh) await this.refresh(); return this.currentRevision; } hasRevision(revision: string): boolean { return this.snapshots.has(revision); } get(revision: string): T { const snapshot = this.snapshots.get(revision); if (!snapshot) throw new Error("Cache snapshot does not exist"); return snapshot; } async refresh(): Promise { if (!this.nextRefresh) { await setTimeoutPromise(20); await this.refresh(); return; } const now = Date.now(); if (now < this.nextRefresh) return; this.nextRefresh = 0; const dbHash = await get(this.cacheKey); if (this.currentRevision && dbHash === this.currentRevision) { this.nextRefresh = now + (REFRESH - (now % REFRESH)); return; } const lockToken = await acquireLock(this.cacheKey, 5000); const [hash, snapshot] = await this.callback(); if (this.currentRevision) { const r = this.currentRevision; const s = this.snapshots.get(r); setTimeout(() => { if (this.snapshots.get(r) === s) this.snapshots.delete(r); }, EVICT_TIMEOUT).unref(); } this.currentRevision = hash; this.snapshots.set(hash, snapshot); if (lockToken) { if (hash !== dbHash) await set(this.cacheKey, hash, 300); await releaseLock(this.cacheKey, lockToken); } this.nextRefresh = now + (REFRESH - (now % REFRESH)); } } ================================================ FILE: lib/lock.ts ================================================ import { collections } from "./db/db.ts"; const CLOCK_SKEW_TOLERANCE = 30000; export async function acquireLock( lockName: string, ttl: number, timeout = 0, token = Math.random().toString(36).slice(2), ): Promise { try { const now = Date.now(); const r = await collections.locks.findOneAndUpdate( { _id: lockName, value: token }, { $set: { expire: new Date(now + ttl + CLOCK_SKEW_TOLERANCE), }, $currentDate: { timestamp: true }, }, { upsert: true, returnDocument: "after" }, ); if (Math.abs(r.value.timestamp.getTime() - now) > CLOCK_SKEW_TOLERANCE) throw new Error("Database clock skew too great"); } catch (err) { if (err.code !== 11000) throw err; if (!(timeout > 0)) return null; const w = 50 + Math.random() * 50; await new Promise((resolve) => setTimeout(resolve, w)); return acquireLock(lockName, ttl, timeout - w, token); } return token; } export async function releaseLock( lockName: string, token: string, ): Promise { const res = await collections.locks.deleteOne({ _id: lockName, value: token, }); if (res.deletedCount !== 1) throw new Error("Lock expired"); } export async function getToken(lockName: string): Promise { const res = await collections.locks.findOne({ _id: lockName }); return res?.value; } ================================================ FILE: lib/logger.ts ================================================ import * as fs from "node:fs"; import * as os from "node:os"; import * as config from "./config.ts"; import { getRequestOrigin } from "./forwarded.ts"; import { SessionContext, AcsRequest, CpeRequest, CpeFault, InformRequest, Fault, } from "./types.ts"; const REOPEN_EVERY = 60000; const LOG_FORMAT = config.get("LOG_FORMAT"); const ACCESS_LOG_FORMAT = config.get("ACCESS_LOG_FORMAT") || LOG_FORMAT; const defaultMeta: { [name: string]: any } = {}; let LOG_SYSTEMD = false; let ACCESS_LOG_SYSTEMD = false; let LOG_FILE, ACCESS_LOG_FILE; declare global { /* eslint-disable-next-line @typescript-eslint/no-namespace */ namespace NodeJS { export interface WritableStream { fd?: number; } } } declare module "fs" { interface WriteStream { fd?: number; } } let logStream = fs.createWriteStream(null, { fd: process.stderr.fd }); let logStat = fs.fstatSync(logStream.fd); let accessLogStream = fs.createWriteStream(null, { fd: process.stdout.fd }); let accessLogStat = fs.fstatSync(accessLogStream.fd); // Reopen if original files have been moved (e.g. logrotate) function reopen(): void { let counter = 1; if (LOG_FILE) { ++counter; fs.stat(LOG_FILE, (err, stat) => { if (err && !err.message.startsWith("ENOENT:")) throw err; if (!(stat && stat.dev === logStat.dev && stat.ino === logStat.ino)) { logStream.end(); logStream = fs.createWriteStream(null, { fd: fs.openSync(LOG_FILE, "a"), }); logStat = fs.fstatSync(logStream.fd); } if (--counter === 0) setTimeout(reopen, REOPEN_EVERY - (Date.now() % REOPEN_EVERY)).unref(); }); } if (ACCESS_LOG_FILE) { ++counter; fs.stat(ACCESS_LOG_FILE, (err, stat) => { if (err && !err.message.startsWith("ENOENT:")) throw err; if ( !( stat && stat.dev === accessLogStat.dev && stat.ino === accessLogStat.ino ) ) { accessLogStream.end(); accessLogStream = fs.createWriteStream(null, { fd: fs.openSync(ACCESS_LOG_FILE, "a"), }); accessLogStat = fs.fstatSync(accessLogStream.fd); } if (--counter === 0) setTimeout(reopen, REOPEN_EVERY - (Date.now() % REOPEN_EVERY)).unref(); }); } if (--counter === 0) setTimeout(reopen, REOPEN_EVERY - (Date.now() % REOPEN_EVERY)).unref(); } export function init(service: string, version: string): void { defaultMeta.hostname = os.hostname(); defaultMeta.pid = process.pid; defaultMeta.name = `genieacs-${service}`; defaultMeta.version = version; LOG_FILE = config.get(`${service.toUpperCase()}_LOG_FILE`); ACCESS_LOG_FILE = config.get(`${service.toUpperCase()}_ACCESS_LOG_FILE`); if (LOG_FILE) { logStream = fs.createWriteStream(null, { fd: fs.openSync(LOG_FILE, "a") }); logStat = fs.fstatSync(logStream.fd); } if (ACCESS_LOG_FILE) { accessLogStream = fs.createWriteStream(null, { fd: fs.openSync(ACCESS_LOG_FILE, "a"), }); accessLogStat = fs.fstatSync(accessLogStream.fd); } // Determine if logs are going to journald const JOURNAL_STREAM = process.env["JOURNAL_STREAM"]; if (JOURNAL_STREAM) { const [dev, inode] = JOURNAL_STREAM.split(":").map(parseInt); LOG_SYSTEMD = logStat.dev === dev && logStat.ino === inode; ACCESS_LOG_SYSTEMD = accessLogStat.dev === dev && accessLogStat.ino === inode; } if (LOG_FILE || ACCESS_LOG_FILE) // Can't use setInterval as we need all workers to cehck at the same time setTimeout(reopen, REOPEN_EVERY - (Date.now() % REOPEN_EVERY)).unref(); } export function close(): void { accessLogStream.end(); logStream.end(); } export function flatten( details: Record, ): Record { if (details.sessionContext) { const sessionContext = details.sessionContext as SessionContext; details.deviceId = sessionContext.deviceId; details.remoteAddress = getRequestOrigin( sessionContext.httpRequest, ).remoteAddress; delete details.sessionContext; } if (details.exception) { const err = details.exception as Error; details.exceptionName = err.name; details.exceptionMessage = err.message; details.exceptionStack = err.stack; delete details.exception; } if (details.task) { details.taskId = details.task["_id"]; delete details.task; } if (details.rpc) { const rpc = details.rpc as { id: string; acsRequest?: AcsRequest; cpeRequest?: CpeRequest; cpeFault?: CpeFault; }; if (rpc.acsRequest) { details.acsRequestId = rpc.id; details.acsRequestName = rpc.acsRequest.name; if (rpc.acsRequest["commandKey"]) details.acsRequestCommandKey = rpc.acsRequest["commandKey"]; } else if (rpc.cpeRequest) { details.cpeRequestId = rpc.id; if (rpc.cpeRequest.name === "Inform") { details.informEvent = (rpc.cpeRequest as InformRequest).event.join(","); details.informRetryCount = (rpc.cpeRequest as InformRequest).retryCount; } else { details.cpeRequestName = rpc.cpeRequest.name; if (rpc.cpeRequest["commandKey"]) details.cpeRequestCommandKey = rpc.cpeRequest["commandKey"]; } } else if (rpc.cpeFault) { details.acsRequestId = rpc.id; details.cpeFaultCode = rpc.cpeFault.detail.faultCode; details.cpeFaultString = rpc.cpeFault.detail.faultString; } delete details.rpc; } if (details.fault) { const fault = details.fault as Fault; details.faultCode = fault.code; details.faultMessage = fault.message; delete details.fault; } // For genieacs-ui if (details.context) { details.remoteAddress = getRequestOrigin( details.context["req"], ).remoteAddress; if (details.context["state"].user) details.user = details.context["state"].user.username; delete details.context; } for (const [k, v] of Object.entries(details)) if (v == null) delete details[k]; return details; } function formatJson( details: Record, systemd: boolean, ): string { if (systemd) { let severity = ""; if (details.severity === "info") severity = "<6>"; else if (details.severity === "warn") severity = "<4>"; else if (details.severity === "error") severity = "<3>"; return `${severity}${JSON.stringify(flatten(details))}${os.EOL}`; } return `${JSON.stringify(flatten(details))}${os.EOL}`; } function formatSimple( details: Record, systemd: boolean, ): string { const skip = { user: true, remoteAddress: true, severity: true, timestamp: true, message: true, deviceId: !!details.sessionContext, }; flatten(details); let remote = ""; if (details.remoteAddress) { if (details.deviceId && skip["deviceId"]) remote = `${details.remoteAddress} ${details.deviceId}: `; else if (details.user) remote = `${details.user}@${details.remoteAddress}: `; else remote = `${details.remoteAddress}: `; } const keys = Object.keys(details); let meta = ""; const kv = []; for (const k of keys) if (!skip[k]) kv.push(`${k}=${JSON.stringify(details[k])}`); if (kv.length) meta = `; ${kv.join(" ")}`; if (systemd) { let severity = ""; if (details.severity === "info") severity = "<6>"; else if (details.severity === "warn") severity = "<4>"; else if (details.severity === "error") severity = "<3>"; return `${severity}${remote}${details.message}${meta}${os.EOL}`; } return `${details.timestamp} [${( details.severity as string ).toUpperCase()}] ${remote}${details.message}${meta}${os.EOL}`; } function log(details: Record): void { details.timestamp = new Date().toISOString(); if (LOG_FORMAT === "json") { details = Object.assign({}, defaultMeta, details); logStream.write(formatJson(details, LOG_SYSTEMD)); } else { logStream.write(formatSimple(details, LOG_SYSTEMD)); } } export function info(details: Record): void { details.severity = "info"; log(details); } export function warn(details: Record): void { details.severity = "warn"; log(details); } export function error(details: Record): void { details.severity = "error"; log(details); } export function accessLog(details: Record): void { details.timestamp = new Date().toISOString(); if (ACCESS_LOG_FORMAT === "json") { Object.assign(details, defaultMeta); accessLogStream.write(formatJson(details, ACCESS_LOG_SYSTEMD)); } else { accessLogStream.write(formatSimple(details, ACCESS_LOG_SYSTEMD)); } } export function accessInfo(details: Record): void { details.severity = "info"; accessLog(details); } export function accessWarn(details: Record): void { details.severity = "warn"; accessLog(details); } export function accessError(details: Record): void { details.severity = "error"; accessLog(details); } ================================================ FILE: lib/nbi.ts ================================================ import * as vm from "node:vm"; import { IncomingMessage, ServerResponse } from "node:http"; import { Collection, ObjectId } from "mongodb"; import { getRevision, getConfig } from "./ui/local-cache.ts"; import { filesBucket, collections } from "./db/db.ts"; import { optimizeProjection } from "./db/util.ts"; import * as query from "./query.ts"; import * as apiFunctions from "./api-functions.ts"; import * as cache from "./cache.ts"; import { version as VERSION } from "../package.json"; import { ping } from "./ping.ts"; import * as logger from "./logger.ts"; import { flattenDevice } from "./ui/db.ts"; import { getRequestOrigin } from "./forwarded.ts"; import { acquireLock, releaseLock } from "./lock.ts"; import { ResourceLockedError } from "./common/errors.ts"; import Expression from "./common/expression.ts"; const DEVICE_TASKS_REGEX = /^\/devices\/([a-zA-Z0-9\-_%]+)\/tasks\/?$/; const TASKS_REGEX = /^\/tasks\/([a-zA-Z0-9\-_%]+)(\/[a-zA-Z_]*)?$/; const TAGS_REGEX = /^\/devices\/([a-zA-Z0-9\-_%]+)\/tags\/([a-zA-Z0-9\-_%]+)\/?$/; const PRESETS_REGEX = /^\/presets\/([a-zA-Z0-9\-_%]+)\/?$/; const OBJECTS_REGEX = /^\/objects\/([a-zA-Z0-9\-_%]+)\/?$/; const FILES_REGEX = /^\/files\/([a-zA-Z0-9%!*'();:@&=+$,?#[\]\-_.~]+)\/?$/; const PING_REGEX = /^\/ping\/([a-zA-Z0-9\-_.:]+)\/?$/; const QUERY_REGEX = /^\/([a-zA-Z0-9_]+)\/?$/; const DELETE_DEVICE_REGEX = /^\/devices\/([a-zA-Z0-9\-_%]+)\/?$/; const PROVISIONS_REGEX = /^\/provisions\/([a-zA-Z0-9\-_%]+)\/?$/; const VIRTUAL_PARAMETERS_REGEX = /^\/virtual_parameters\/([a-zA-Z0-9\-_%]+)\/?$/; const FAULTS_REGEX = /^\/faults\/([a-zA-Z0-9\-_%:]+)\/?$/; async function getBody(request: IncomingMessage): Promise { const chunks: Buffer[] = []; let readableEnded = false; request.on("end", () => { readableEnded = true; }); for await (const chunk of request) chunks.push(chunk); // In Node versions prior to 15, the stream will not emit an error if the // connection is closed before the stream is finished. // For Node 12.9+ we can just use stream.readableEnded if (!readableEnded) throw new Error("Connection closed"); return Buffer.concat(chunks); } export async function listener( request: IncomingMessage, response: ServerResponse, ): Promise { response.setHeader("GenieACS-Version", VERSION); const origin = getRequestOrigin(request); const url = new URL( request.url, (origin.encrypted ? "https://" : "http://") + origin.host, ); const body = await getBody(request).catch(() => null); // Ignore incomplete requests if (body == null) return; logger.accessInfo( Object.assign({}, Object.fromEntries(url.searchParams), { remoteAddress: origin.remoteAddress, message: `${request.method} ${url.pathname}`, }), ); return handler(request, response, url, body); } async function handler( request: IncomingMessage, response: ServerResponse, url: URL, body: Buffer, ): Promise { if (PRESETS_REGEX.test(url.pathname)) { const presetName = decodeURIComponent(PRESETS_REGEX.exec(url.pathname)[1]); if (request.method === "PUT") { let preset; try { preset = JSON.parse(body.toString()); } catch (err) { response.writeHead(400); response.end(`${err.name}: ${err.message}`); return; } preset._id = presetName; await collections.presets.replaceOne({ _id: presetName }, preset, { upsert: true, }); await cache.del("cwmp-local-cache-hash"); response.writeHead(200); response.end(); } else if (request.method === "DELETE") { await collections.presets.deleteOne({ _id: presetName }); await cache.del("cwmp-local-cache-hash"); response.writeHead(200); response.end(); } else { response.writeHead(405, { Allow: "PUT, DELETE" }); response.end("405 Method Not Allowed"); } } else if (OBJECTS_REGEX.test(url.pathname)) { const objectName = decodeURIComponent(OBJECTS_REGEX.exec(url.pathname)[1]); if (request.method === "PUT") { let object; try { object = JSON.parse(body.toString()); } catch (err) { response.writeHead(400); response.end(`${err.name}: ${err.message}`); return; } object._id = objectName; await collections.objects.replaceOne({ _id: objectName }, object, { upsert: true, }); await cache.del("cwmp-local-cache-hash"); response.writeHead(200); response.end(); } else if (request.method === "DELETE") { await collections.objects.deleteOne({ _id: objectName }); await cache.del("cwmp-local-cache-hash"); response.writeHead(200); response.end(); } else { response.writeHead(405, { Allow: "PUT, DELETE" }); response.end("405 Method Not Allowed"); } } else if (PROVISIONS_REGEX.test(url.pathname)) { const provisionName = decodeURIComponent( PROVISIONS_REGEX.exec(url.pathname)[1], ); if (request.method === "PUT") { const object = { _id: provisionName, script: body.toString(), }; try { new vm.Script(`"use strict";(function(){\n${object.script}\n})();`); } catch (err) { response.writeHead(400); response.end(`${err.name}: ${err.message}`); return; } await collections.provisions.replaceOne({ _id: provisionName }, object, { upsert: true, }); await cache.del("cwmp-local-cache-hash"); response.writeHead(200); response.end(); } else if (request.method === "DELETE") { await collections.provisions.deleteOne({ _id: provisionName }); await cache.del("cwmp-local-cache-hash"); response.writeHead(200); response.end(); } else { response.writeHead(405, { Allow: "PUT, DELETE" }); response.end("405 Method Not Allowed"); } } else if (VIRTUAL_PARAMETERS_REGEX.test(url.pathname)) { const virtualParameterName = decodeURIComponent( VIRTUAL_PARAMETERS_REGEX.exec(url.pathname)[1], ); if (request.method === "PUT") { const object = { _id: virtualParameterName, script: body.toString(), }; try { new vm.Script(`"use strict";(function(){\n${object.script}\n})();`); } catch (err) { response.writeHead(400); response.end(`${err.name}: ${err.message}`); return; } await collections.virtualParameters.replaceOne( { _id: virtualParameterName }, object, { upsert: true }, ); await cache.del("cwmp-local-cache-hash"); response.writeHead(200); response.end(); } else if (request.method === "DELETE") { await collections.virtualParameters.deleteOne({ _id: virtualParameterName, }); await cache.del("cwmp-local-cache-hash"); response.writeHead(200); response.end(); } else { response.writeHead(405, { Allow: "PUT, DELETE" }); response.end("405 Method Not Allowed"); } } else if (TAGS_REGEX.test(url.pathname)) { const r = TAGS_REGEX.exec(url.pathname); const deviceId = decodeURIComponent(r[1]); const tag = decodeURIComponent(r[2]); if (request.method === "POST") { const updateRes = await collections.devices.updateOne( { _id: deviceId }, { $addToSet: { _tags: tag } }, ); if (!updateRes.matchedCount) { response.writeHead(404); response.end("No such device"); return; } response.writeHead(200); response.end(); } else if (request.method === "DELETE") { const updateRes = await collections.devices.updateOne( { _id: deviceId }, { $pull: { _tags: tag } }, ); if (!updateRes.matchedCount) { response.writeHead(404); response.end("No such device"); return; } response.writeHead(200); response.end(); } else { response.writeHead(405, { Allow: "POST, DELETE" }); response.end("405 Method Not Allowed"); } } else if (FAULTS_REGEX.test(url.pathname)) { if (request.method === "DELETE") { const faultId = decodeURIComponent(FAULTS_REGEX.exec(url.pathname)[1]); try { await apiFunctions.deleteFault(faultId); } catch (err) { if (err instanceof ResourceLockedError) { response.writeHead(503); response.end("Device is in session"); return; } throw err; } response.writeHead(200); response.end(); } else { response.writeHead(405, { Allow: "DELETE" }); response.end("405 Method Not Allowed"); } } else if (DEVICE_TASKS_REGEX.test(url.pathname)) { if (request.method === "POST") { const deviceId = decodeURIComponent( DEVICE_TASKS_REGEX.exec(url.pathname)[1], ); const conReq = url.searchParams.has("connection_request"); let task; if (body.length) { try { task = JSON.parse(body.toString()); task.device = deviceId; } catch (err) { response.writeHead(400); response.end(`${err.name}: ${err.message}`); return; } } if (!task && !conReq) { response.writeHead(400); response.end(); return; } if (!task || !conReq) { const dev = await collections.devices.findOne({ _id: deviceId }); if (!dev) { response.writeHead(404); response.end("No such device"); return; } if (task) { await apiFunctions.insertTasks(task); response.writeHead(202, { "Content-Type": "application/json" }); response.end(JSON.stringify(task)); } else { const status = await apiFunctions.connectionRequest( deviceId, flattenDevice(dev), ); if (status) { response.writeHead(504, status); response.end(status); } else { response.writeHead(200); response.end(); } } return; } const socketTimeout: number = request.socket.timeout; // Extend socket timeout while waiting for session if (socketTimeout) request.socket.setTimeout(300000); const token = await acquireLock(`cwmp_session_${deviceId}`, 5000, 30000); if (!token) { // Restore socket timeout if (socketTimeout) request.socket.setTimeout(socketTimeout); const dev = await collections.devices.findOne({ _id: deviceId }); if (!dev) { response.writeHead(404); response.end("No such device"); return; } await apiFunctions.insertTasks(task); response.writeHead(202, "Task queued but not processed", { "Content-Type": "application/json", }); response.end(JSON.stringify(task)); return; } let dev; try { dev = await collections.devices.findOne({ _id: deviceId }); if (!dev) { response.writeHead(404); response.end("No such device"); return; } await apiFunctions.insertTasks(task); } finally { await releaseLock(`cwmp_session_${deviceId}`, token); } const lastInform = (dev["_lastInform"] as Date).getTime(); const device = flattenDevice(dev); const configCallback = (e: Expression): Expression.Literal => { if (e instanceof Expression.Literal) return e; else if (e instanceof Expression.Parameter) { const p = device[e.path.toString()]; if (p != null) return new Expression.Literal(p); } else if (e instanceof Expression.FunctionCall) { if (e.name === "NOW") return new Expression.Literal(Date.now()); if (e.name === "REMOTE_ADDRESS") { for (const root of ["InternetGatewayDevice", "Device"]) { const p = device[`${root}.ManagementServer.ConnectionRequestURL`]; if (p != null) return new Expression.Literal(new URL(p as string).hostname); } } } return new Expression.Literal(null); }; let onlineThreshold: number; if (url.searchParams.has("timeout")) { onlineThreshold = parseInt(url.searchParams.get("timeout")); } else { const revision = await getRevision(); onlineThreshold = getConfig( revision, "cwmp.deviceOnlineThreshold", 4000, configCallback, ); } let status = await apiFunctions.connectionRequest(deviceId, device); if (!status) { const sessionStarted = await apiFunctions.awaitSessionStart( deviceId, lastInform, onlineThreshold, ); if (!sessionStarted) { status = "Task queued but not processed"; } else { const sessionEnded = await apiFunctions.awaitSessionEnd( deviceId, 120000, ); if (!sessionEnded) { status = "Task queued but not processed"; } else { const f = await collections.faults.count({ _id: `${deviceId}:task_${task._id}`, }); if (f) status = "Task faulted"; } } } // Restore socket timeout if (socketTimeout) request.socket.setTimeout(socketTimeout); if (status) { response.writeHead(202, status, { "Content-Type": "application/json" }); response.end(JSON.stringify(task)); } else { response.writeHead(200, { "Content-Type": "application/json" }); response.end(JSON.stringify(task)); } } else { response.writeHead(405, { Allow: "POST" }); response.end("405 Method Not Allowed"); } } else if (TASKS_REGEX.test(url.pathname)) { const r = TASKS_REGEX.exec(url.pathname); const taskId = decodeURIComponent(r[1]); const action = r[2]; if (!action || action === "/") { if (request.method === "DELETE") { const task = await collections.tasks.findOne( { _id: new ObjectId(taskId) }, { projection: { device: 1 } }, ); if (!task) { response.writeHead(404); response.end("Task not found"); return; } const deviceId = task.device; const token = await acquireLock(`cwmp_session_${deviceId}`, 5000); if (!token) { response.writeHead(503); response.end("Device is in session"); return; } try { await Promise.all([ collections.tasks.deleteOne({ _id: new ObjectId(taskId) }), collections.faults.deleteOne({ _id: `${deviceId}:task_${taskId}` }), ]); } finally { await releaseLock(`cwmp_session_${deviceId}`, token); } response.writeHead(200); response.end(); } else { response.writeHead(405, { Allow: "PUT DELETE" }); response.end("405 Method Not Allowed"); } } else if (action === "/retry") { if (request.method === "POST") { const task = await collections.tasks.findOne( { _id: new ObjectId(taskId) }, { projection: { device: 1 } }, ); const deviceId = task.device; const token = await acquireLock(`cwmp_session_${deviceId}`, 5000); if (!token) { response.writeHead(503); response.end("Device is in session"); return; } try { await collections.faults.deleteOne({ _id: `${deviceId}:task_${taskId}`, }); } finally { await releaseLock(`cwmp_session_${deviceId}`, token); } response.writeHead(200); response.end(); } else { response.writeHead(405, { Allow: "POST" }); response.end("405 Method Not Allowed"); } } else { response.writeHead(404); response.end(); } } else if (FILES_REGEX.test(url.pathname)) { const filename = decodeURIComponent(FILES_REGEX.exec(url.pathname)[1]); if (request.method === "PUT") { const metadata = { fileType: request.headers.filetype, oui: request.headers.oui, productClass: request.headers.productclass, version: request.headers.version, }; try { await filesBucket.delete(filename as unknown as ObjectId); } catch { // Ignore error if file doesn't exist } return new Promise((resolve, reject) => { const uploadStream = filesBucket.openUploadStreamWithId( filename as unknown as ObjectId, filename, { metadata: metadata, }, ); uploadStream.on("error", reject); uploadStream.end(body, () => { response.writeHead(201); response.end(); resolve(); }); }); } else if (request.method === "DELETE") { try { await filesBucket.delete(filename as unknown as ObjectId); } catch (err) { if (err.message.startsWith("FileNotFound")) { response.writeHead(404); response.end("404 Not Found"); return; } throw err; } response.writeHead(200); response.end(); } else { response.writeHead(405, { Allow: "PUT, DELETE" }); response.end("405 Method Not Allowed"); } } else if (PING_REGEX.test(url.pathname)) { const host = decodeURIComponent(PING_REGEX.exec(url.pathname)[1]); return new Promise((resolve) => { ping(host, (err, res, stdout) => { if (err) { if (!res) { response.writeHead(500, { Connection: "close" }); response.end(`${err.name}: ${err.message}`); return; } response.writeHead(404, { "Cache-Control": "no-cache" }); response.end(`${err.name}: ${err.message}`); return; } response.writeHead(200, { "Content-Type": "text/plain", "Cache-Control": "no-cache", }); response.end(stdout); resolve(); }); }); } else if (DELETE_DEVICE_REGEX.test(url.pathname)) { if (request.method !== "DELETE") { response.writeHead(405, { Allow: "DELETE" }); response.end("405 Method Not Allowed"); return; } const deviceId = decodeURIComponent( DELETE_DEVICE_REGEX.exec(url.pathname)[1], ); try { await apiFunctions.deleteDevice(deviceId); } catch (err) { if (err instanceof ResourceLockedError) { response.writeHead(503); response.end("Device is in session"); return; } throw err; } response.writeHead(200); response.end(); } else if (QUERY_REGEX.test(url.pathname)) { let collectionName = QUERY_REGEX.exec(url.pathname)[1]; // Convert to camel case let i = collectionName.indexOf("_"); while (i++ >= 0) { const up = i < collectionName.length ? collectionName[i].toUpperCase() : ""; collectionName = collectionName.slice(0, i - 1) + up + collectionName.slice(i + 1); i = collectionName.indexOf("_", i); } if (request.method !== "GET" && request.method !== "HEAD") { response.writeHead(405, { Allow: "GET, HEAD" }); response.end("405 Method Not Allowed"); return; } const collection = collections[collectionName] as Collection; if (!collection) { response.writeHead(404); response.end("404 Not Found"); return; } let q = {}; if (url.searchParams.has("query")) { try { q = JSON.parse(url.searchParams.get("query") as string); } catch (err) { response.writeHead(400); response.end(`${err.name}: ${err.message}`); return; } } switch (collectionName) { case "devices": q = query.expand(q); break; case "tasks": q = query.sanitizeQueryTypes(q, { _id: (v) => new ObjectId(v as string), timestamp: (v) => new Date(v as number), retries: Number, }); break; case "faults": q = query.sanitizeQueryTypes(q, { timestamp: (v) => new Date(v as number), retries: Number, }); } let projection = null; if (url.searchParams.has("projection")) { projection = {}; for (const p of (url.searchParams.get("projection") as string).split(",")) projection[p.trim()] = 1; projection = optimizeProjection(projection); } const cur = collection.find(q, { projection: projection }); if (url.searchParams.has("sort")) { let s; try { s = JSON.parse(url.searchParams.get("sort") as string); } catch (err) { response.writeHead(400); response.end(`${err.name}: ${err.message}`); return; } const sort = {}; for (const [k, v] of Object.entries(s)) { if (k[k.lastIndexOf(".") + 1] !== "_" && collectionName === "devices") sort[`${k}._value`] = v; else sort[k] = v; } cur.sort(sort); } const total = await collection.countDocuments(q); response.writeHead(200, { "Content-Type": "application/json", total: total, }); if (request.method === "HEAD") { response.end(); return; } if (url.searchParams.has("skip")) cur.skip(parseInt(url.searchParams.get("skip") as string)); if (url.searchParams.has("limit")) cur.limit(parseInt(url.searchParams.get("limit") as string)); response.write("[\n"); i = 0; for await (const item of cur) { if (i++) response.write(",\n"); response.write(JSON.stringify(item)); } response.end("\n]"); } else { response.writeHead(404); response.end("404 Not Found"); } } ================================================ FILE: lib/ping.ts ================================================ import { platform } from "node:os"; import { exec } from "node:child_process"; import { domainToASCII } from "node:url"; export interface PingResult { packetsTransmitted: number; packetsReceived: number; packetLoss: number; min: number; avg: number; max: number; mdev: number; } function isValidHost(host: string): boolean { // Valid chars in IPv4, IPv6, domain names if (/^[a-zA-Z0-9\-.:[\]-]+$/.test(host)) return true; // Check if input is an IDN convert to Punycode // Can't merge with above because domainToASCII doesn't accept IP addresses return /^[a-zA-Z0-9\-.:[\]-]+$/.test(domainToASCII(host)); } export function parsePing(osPlatform: string, stdout: string): PingResult { let parseRegExp1: RegExp, parseRegExp2: RegExp, parsed: PingResult; switch (osPlatform) { case "linux": parseRegExp1 = /(\d+) packets transmitted, (\d+) .*received, ([\d.]+)% .*loss[^]*= ([\d.]+)\/([\d.]+)\/([\d.]+)\/([\d.]+)/; parseRegExp2 = /(\d+) packets transmitted, (\d+) .*received, ([\d.]+)% .*loss/; break; case "freebsd": parseRegExp1 = /(\d+) packets transmitted, (\d+) packets received, ([\d.]+)% packet loss\nround-trip min\/avg\/max\/stddev = ([\d.]+)\/([\d.]+)\/([\d.]+)\/([\d.]+) ms/; parseRegExp2 = /(\d+) packets transmitted, (\d+) packets received, ([\d.]+)% packet loss/; break; } const m1 = stdout.match(parseRegExp1); if (m1) { parsed = { packetsTransmitted: +m1[1], packetsReceived: +m1[2], packetLoss: +m1[3], min: +m1[4], avg: +m1[5], max: +m1[6], mdev: +m1[7], }; } else { const m2 = stdout.match(parseRegExp2); if (m2) { parsed = { packetsTransmitted: +m2[1], packetsReceived: +m2[2], packetLoss: +m2[3], min: null, avg: null, max: null, mdev: null, }; } } return parsed; } export function ping( host: string, callback: (err: Error, res?: PingResult, stdout?: string) => void, ): void { // Validate input to prevent possible remote code execution // Credit to Alex Hordijk for reporting this vulnerability if (!isValidHost(host)) return callback(new Error("Invalid host")); host = host.replace("[", "").replace("]", ""); let cmd: string; switch (platform()) { case "linux": cmd = `ping -w 1 -i 0.2 -c 3 ${host}`; break; case "freebsd": // Send a single packet because on FreeBSD only superuser can send // packets that are only 200 ms apart. cmd = `ping -t 1 -c 3 ${host}`; break; default: return callback(new Error("Platform not supported")); } exec(cmd, (err, stdout) => { if (err) return callback(err); const parsed: PingResult = parsePing(platform(), stdout); return callback(err, parsed, stdout); }); } ================================================ FILE: lib/query.ts ================================================ function isObject(obj: any): boolean { return Object.prototype.toString.call(obj) === "[object Object]"; } function stringToRegexp(input, flags?): RegExp | false { if (input.indexOf("*") === -1) return false; let output = input.replace(/[[\]\\^$.|?+()]/, "\\$&"); if (output[0] === "*") output = output.replace(/^\*+/g, ""); else output = "^" + output; if (output[output.length - 1] === "*") output = output.replace(/\*+$/g, ""); else output = output + "$"; output = output.replace(/[*]/, ".*"); return new RegExp(output, flags); } function normalize(input): any { if (typeof input === "string") { const vals: any = [input]; const m = /^\/(.*?)\/(g?i?m?y?)$/.exec(input); if (m) vals.push({ $regex: new RegExp(m[1], m[2]) }); if (+input === parseFloat(input)) vals.push(+input); const d = new Date(input); if (input.length >= 8 && d.getFullYear() > 1983) vals.push(d); const r = stringToRegexp(input); if (r !== false) vals.push({ $regex: r }); return vals; } return input; } const EXPAND_OPS = new Set([ "$eq", "$gt", "$gte", "$in", "$lt", "$lte", "$ne", "$nin", ]); function expandValue(value: unknown): unknown[] { if (Array.isArray(value)) { let a = []; for (const j of value) a = a.concat(expandValue(j)); return [a]; } else if (!isObject(value)) { const n = normalize(value); if (!Array.isArray(n)) return [n]; else return n; } const objs = []; const indices = []; const keys = []; const values = []; for (const [k, v] of Object.entries(value)) { keys.push(k); if (EXPAND_OPS.has(k)) values.push(expandValue(v)); else values.push([v]); indices.push(0); } let i = 0; while (i < indices.length) { const obj = {}; for (let j = 0; j < keys.length; ++j) obj[keys[j]] = values[j][indices[j]]; objs.push(obj); for (i = 0; i < indices.length; ++i) { indices[i] += 1; if (indices[i] < values[i].length) break; indices[i] = 0; } } return objs; } function permute(param, val): any[] { const conditions = []; const values = expandValue(val); if (param[param.lastIndexOf(".") + 1] !== "_") param += "._value"; for (const v of values) { const obj = {}; obj[param] = v; conditions.push(obj); } return conditions; } export function expand( query: Record, ): Record { const newQuery = {}; for (const [k, v] of Object.entries(query)) { if (k[0] === "$") { // Operator newQuery[k] = (v as any[]).map((e) => expand(e)); } else { const conditions = permute(k, v); if (conditions.length > 1) { newQuery["$and"] = newQuery["$and"] || []; if (v && (v["$ne"] != null || v["$not"] != null)) { if (Object.keys(v).length > 1) throw new Error("Cannot mix $ne or $not with other operators"); for (const c of conditions) newQuery["$and"].push(c); } else { newQuery["$and"].push({ $or: conditions }); } } else { Object.assign(newQuery, conditions[0]); } } } return newQuery; } export function sanitizeQueryTypes( query: Record, types: Record unknown>, ): Record { for (const [k, v] of Object.entries(query)) { if (k[0] === "$") { // Logical operator for (const vv of v as any[]) sanitizeQueryTypes(vv, types); } else if (k in types) { if (isObject(v)) { for (const [kk, vv] of Object.entries(v)) { switch (kk) { case "$in": case "$nin": for (let i = 0; i < vv.length; ++i) vv[i] = types[k](vv[i]); break; case "$eq": case "$gt": case "$gte": case "$lt": case "$lte": case "$ne": v[kk] = types[k](vv); break; case "$exists": case "$type": // Ignore break; default: throw new Error("Operator not supported"); } } } else { query[k] = types[k](query[k]); } } } return query; } ================================================ FILE: lib/sandbox.ts ================================================ import * as vm from "node:vm"; import seedrandom from "seedrandom"; import * as device from "./device.ts"; import * as extensions from "./extensions.ts"; import * as logger from "./logger.ts"; import * as scheduling from "./scheduling.ts"; import Path from "./common/path.ts"; import { Fault, SessionContext, ScriptResult } from "./types.ts"; // Used for throwing to exit user script and commit const COMMIT = Symbol(); // Used to execute extensions and restart const EXT = Symbol(); const UNDEFINED = undefined; const context = vm.createContext(undefined, { microtaskMode: "afterEvaluate" }); let state; const runningExtensions = new WeakMap< SessionContext, Map> >(); function runExtension(sessionContext, key, extCall): Promise { let re = runningExtensions.get(sessionContext); if (!re) { re = new Map>(); runningExtensions.set(sessionContext, re); } let prom = re.get(key); if (prom == null) { re.set( key, (prom = new Promise((resolve, reject) => { extensions .run(extCall) .then(({ fault, value }) => { re.delete(key); if (!fault) sessionContext.extensionsCache[key] = value; resolve(fault); }) .catch(reject); })), ); } return prom; } class SandboxDate { public constructor( ...argumentList: [ number?, number?, number?, number?, number?, number?, number?, ] ) { if (argumentList.length) return new Date(...argumentList); return new Date(state.sessionContext.timestamp); } public static now(intervalOrCron, variance): number { let t = state.sessionContext.timestamp; if (typeof intervalOrCron === "number") { if (variance == null) variance = intervalOrCron; let offset = 0; if (variance) offset = scheduling.variance(state.sessionContext.deviceId, variance); t = scheduling.interval(t, intervalOrCron, offset); } else if (typeof intervalOrCron === "string") { let offset = 0; if (variance) offset = scheduling.variance(state.sessionContext.deviceId, variance); const cron = scheduling.parseCron(intervalOrCron); t = scheduling.cron(t, cron, offset)[0]; } else if (intervalOrCron) { throw new Error("Invalid Date.now() argument"); } return t; } public static parse(dateString: string): number { return Date.parse(dateString); } public static UTC( ...args: [number, number?, number?, number?, number?, number?, number?] ): number { return Date.UTC(...args); } } function random(): number { if (!state.rng) state.rng = seedrandom(state.sessionContext.deviceId); return state.rng(); } random.seed = function (s) { state.rng = seedrandom(s); }; class ParameterWrapper { public constructor(path: Path, attributes, unpacked?, unpackedRevision?) { for (const attrName of attributes) { Object.defineProperty(this, attrName, { get: function () { if (state.uncommitted) commit(); if (state.revision !== unpackedRevision) { unpackedRevision = state.revision; unpacked = device.unpack( state.sessionContext.deviceData, path, state.revision, ); } if (!unpacked.length) return UNDEFINED; const attr = state.sessionContext.deviceData.attributes.get( unpacked[0], state.revision, )[attrName]; if (!attr) return UNDEFINED; return attr[1]; }, }); } Object.defineProperty(this, "path", { get: function () { if (state.uncommitted) commit(); if (state.revision !== unpackedRevision) { unpackedRevision = state.revision; unpacked = device.unpack( state.sessionContext.deviceData, path, state.revision, ); } if (!unpacked.length) return UNDEFINED; return unpacked[0].toString(); }, }); Object.defineProperty(this, "size", { get: function () { if (state.uncommitted) commit(); if (state.revision !== unpackedRevision) { unpackedRevision = state.revision; unpacked = device.unpack( state.sessionContext.deviceData, path, state.revision, ); } if (!unpacked.length) return UNDEFINED; return unpacked.length; }, }); this[Symbol.iterator] = function* () { if (state.uncommitted) commit(); if (state.revision !== unpackedRevision) { unpackedRevision = state.revision; unpacked = device.unpack( state.sessionContext.deviceData, path, state.revision, ); } for (const p of unpacked) yield new ParameterWrapper(p, attributes, [p], state.revision); }; } } function declare( path: string, timestamps: { [attr: string]: number }, values: { [attr: string]: any }, ): ParameterWrapper { state.uncommitted = true; if (!timestamps) timestamps = {}; if (!values) values = {}; const parsedPath = Path.parse(path); const declaration = { path: parsedPath, pathGet: 1, pathSet: null, attrGet: null, attrSet: null, defer: true, }; const attrs = new Set(); for (const [attrName, attrValue] of Object.entries(values)) { if (attrName === "path") { declaration.pathSet = attrValue; } else { attrs.add(attrName); if (!declaration.attrGet) declaration.attrGet = {}; if (!declaration.attrSet) declaration.attrSet = {}; declaration.attrGet[attrName] = 1; if (attrName === "value" && !Array.isArray(values.value)) declaration.attrSet.value = [values.value]; else declaration.attrSet[attrName] = values[attrName]; } } for (const [attrName, attrTimestamp] of Object.entries(timestamps)) { if (!(attrTimestamp >= 1)) continue; if (attrName === "path") { declaration.pathGet = attrTimestamp; } else { attrs.add(attrName); if (!declaration.attrGet) declaration.attrGet = {}; declaration.attrGet[attrName] = attrTimestamp; } } state.declarations.push(declaration); return new ParameterWrapper(parsedPath, attrs); } function clear(path: string, timestamp: number, attributes?): void { state.uncommitted = true; if (state.revision === state.maxRevision) state.clear.push([Path.parse(path), timestamp, attributes]); } function commit(): void { ++state.revision; state.uncommitted = false; if (state.revision === state.maxRevision + 1) { for (const d of state.declarations) d.defer = false; throw COMMIT; } else if (state.revision > state.maxRevision + 1) { throw new Error( "Declare function should not be called from within a try/catch block", ); } } function ext(...args: unknown[]): any { ++state.extCounter; const extCall = args.map(String); const key = `${state.revision}: ${JSON.stringify(extCall)}`; if (key in state.sessionContext.extensionsCache) return state.sessionContext.extensionsCache[key]; state.extensions[key] = extCall; throw EXT; } function log(msg: string, meta: Record): void { if (state.revision === state.maxRevision && state.extCounter >= 0) { const details = Object.assign({}, meta, { sessionContext: state.sessionContext, message: `Script: ${msg}`, }); delete details["hostname"]; delete details["pid"]; delete details["name"]; delete details["version"]; delete details["deviceId"]; delete details["remoteAddress"]; logger.accessInfo(details); } } Object.defineProperty(context, "Date", { value: SandboxDate }); Object.defineProperty(context, "declare", { value: declare }); Object.defineProperty(context, "clear", { value: clear }); Object.defineProperty(context, "commit", { value: commit }); Object.defineProperty(context, "ext", { value: ext }); Object.defineProperty(context, "log", { value: log }); // Monkey-patch Math.random() to make it deterministic context.random = random; vm.runInContext("Math.random = random;", context); delete context.random; function errorToFault(err: Error): Fault { if (!err) return null; if (!err.name) return { code: "script", message: `${err}` }; const fault: Fault = { code: `script.${err.name}`, message: err.message, detail: { name: err.name, message: err.message, }, }; if (err.stack) { fault.detail["stack"] = err.stack; // Trim the stack trace at the self-executing anonymous wrapper function const stackTrimIndex = fault.detail["stack"].match( /\s+at\s[^\s]+\s+at\s[^\s]+\s\(vm\.js.+\)/, ); if (stackTrimIndex) { fault.detail["stack"] = fault.detail["stack"].slice( 0, stackTrimIndex.index, ); } } return fault; } export async function run( script: vm.Script, globals: Record, sessionContext: SessionContext, startRevision: number, maxRevision: number, extCounter = 0, ): Promise { state = { sessionContext: sessionContext, revision: startRevision, maxRevision: maxRevision, uncommitted: false, declarations: [], extensions: {}, clear: [], rng: null, extCounter: extCounter, }; for (const n of Object.keys(context)) delete context[n]; Object.assign(context, globals); let ret, status; try { ret = script.runInContext(context, { displayErrors: false, timeout: 50 }); status = 0; } catch (err) { if (err === COMMIT) { status = 1; } else if (err === EXT) { status = 2; } else { return { fault: errorToFault(err), clear: null, declare: null, done: false, returnValue: null, }; } } const _state = state; let fault; await Promise.all( Object.entries(_state.extensions).map(async ([k, v]) => { fault = (await runExtension(_state.sessionContext, k, v)) || fault; }), ); if (fault) { return { fault: fault, clear: null, declare: null, done: false, returnValue: null, }; } if (status === 2) { return run( script, globals, sessionContext, startRevision, maxRevision, extCounter - _state.extCounter, ); } return { fault: null, clear: _state.clear, declare: _state.declarations, done: status === 0, returnValue: ret, }; } ================================================ FILE: lib/scheduling.ts ================================================ import * as crypto from "node:crypto"; import * as later from "@breejs/later"; function md532(str): number { const digest = crypto.createHash("md5").update(str).digest(); return ( digest.readUInt32LE(0) ^ digest.readUInt32LE(4) ^ digest.readUInt32LE(8) ^ digest.readUInt32LE(12) ); } export function variance(deviceId: string, vrnc: number): number { return (md532(deviceId) >>> 0) % vrnc; } export function interval( timestamp: number, intrvl: number, offset = 0, ): number { return Math.trunc((timestamp + offset) / intrvl) * intrvl - offset; } export function parseCron(cronExp: string): any { const parts = cronExp.trim().split(/\s+/); if (parts.length === 5) parts.unshift("*"); return later.schedule(later.parse.cron(parts.join(" "), true)); } export function cron( timestamp: number, schedule: unknown, offset = 0, ): number[] { // TODO later.js doesn't throw erorr if expression is invalid! const ret = [0, 0]; const prev = (schedule as any).prev(1, new Date(timestamp + offset)); if (prev) ret[0] = prev.setMilliseconds(0) - offset; const next = (schedule as any).next(1, new Date(timestamp + offset + 1000)); if (next) ret[1] = next.setMilliseconds(0) - offset; return ret; } ================================================ FILE: lib/server.ts ================================================ import { readFileSync } from "node:fs"; import * as http from "node:http"; import * as https from "node:https"; import { Socket } from "node:net"; import * as path from "node:path"; import { ROOT_DIR } from "./config.ts"; let server: http.Server | https.Server; let listener: http.RequestListener; let stopping = false; function closeServer(timeout, callback): void { if (!server) return void callback(); setTimeout(() => { if (!callback) return; // Ignore HTTP requests from connection that may still be open server.removeListener("request", listener); server.setTimeout(1); const cb = callback; callback = null; setTimeout(cb, 1000); }, timeout).unref(); server.close(() => { if (!callback) return; const cb = callback; callback = null; // Allow some time for connection close events to fire setTimeout(cb, 50); }); } interface ServerOptions { port?: number; host?: string; ssl?: { key: string; cert: string }; timeout?: number; keepAliveTimeout?: number; requestTimeout?: number; onConnection?: (socket: Socket) => void; onClientError?: (err: Error, socket: Socket) => void; } interface SocketEndpoint { localAddress: string; localPort: number; remoteAddress: string; remotePort: number; remoteFamily: "IPv4" | "IPv6"; } // Save this info as they're not accessible after a socket has been closed const socketEndpoints: WeakMap = new WeakMap(); type Promisify any> = ( ...args: Parameters ) => Promise>; function getValidPrivKeys(value: string): Buffer[] { return value.split(":").map((str) => { str = str.trim(); const buf = str.startsWith("-----BEGIN ") ? Buffer.from(str) : readFileSync(path.resolve(ROOT_DIR, str)); return buf; }); } function getValidCerts(value: string): Buffer[] { return value.split(":").map((str) => { str = str.trim(); const buf = str.startsWith("-----BEGIN ") ? Buffer.from(str) : readFileSync(path.resolve(ROOT_DIR, str)); return buf; }); } export function start( options: ServerOptions, _listener: Promisify, ): void { listener = (req, res) => { if (stopping) res.setHeader("Connection", "close"); _listener(req, res).catch((err) => { try { res.socket.unref(); if (res.headersSent) { res.writeHead(500, { Connection: "close" }); res.end(`${err.name}: ${err.message}`); } } catch { // Ignore } throw err; }); }; if (options.ssl) { const opts = { key: getValidPrivKeys(options.ssl.key), cert: getValidCerts(options.ssl.cert), }; server = https.createServer(opts, listener); if (options.onConnection) server.on("secureConnection", options.onConnection); } else { server = http.createServer(listener); if (options.onConnection) server.on("connection", options.onConnection); } server.on("connection", (socket: Socket) => { socketEndpoints.set(socket, { localAddress: socket.localAddress, localPort: socket.localPort, remoteAddress: socket.remoteAddress, remotePort: socket.remotePort, remoteFamily: socket.remoteFamily as "IPv4" | "IPv6", }); }); if (options.onClientError) { server.on("clientError", (err, socket: Socket) => { if (err["code"] !== "ECONNRESET" && socket.writable) socket.end("HTTP/1.1 400 Bad Request\r\nConnection: close\r\n\r\n"); // As per Node docs: This event is guaranteed to be passed an instance // of the class options.onClientError(err, socket as Socket); }); } server.timeout = options.timeout || 0; if (options.keepAliveTimeout != null) server.keepAliveTimeout = options.keepAliveTimeout; if (options.requestTimeout != null) server.requestTimeout = options.requestTimeout; server.listen({ port: options.port, host: options.host }); } export function stop(terminateConnections = true): Promise { stopping = terminateConnections; return new Promise((resolve, reject) => { setTimeout(() => { reject(new Error("Could not close server in a timely manner")); }, 30000).unref(); closeServer(20000, resolve); }); } export function getSocketEndpoints(socket: Socket): SocketEndpoint { // TLSSocket keeps a reference to the raw TCP socket in _parent return socketEndpoints.get(socket["_parent"] ?? socket); } ================================================ FILE: lib/session.ts ================================================ import * as device from "./device.ts"; import * as sandbox from "./sandbox.ts"; import * as localCache from "./cwmp/local-cache.ts"; import * as defaultProvisions from "./default-provisions.ts"; import { estimateGpnCount } from "./gpn-heuristic.ts"; import Path from "./common/path.ts"; import PathSet from "./common/path-set.ts"; import VersionedMap from "./versioned-map.ts"; import InstanceSet from "./instance-set.ts"; import { Attributes, SessionContext, DeviceData, VirtualParameterDeclaration, AttributeTimestamps, AttributeValues, Fault, Declaration, Clear, CpeResponse, CpeFault, AcsRequest, AcsResponse, InformRequest, TransferCompleteRequest, Operation, ScriptResult, GetParameterValues, GetParameterAttributes, GetParameterNames, SetParameterValues, SetParameterAttributes, AddObject, DeleteObject, Download, Reboot, FactoryReset, AddObjectResponse, GetParameterValuesResponse, } from "./types.ts"; import { getRequestOrigin } from "./forwarded.ts"; import * as logger from "./logger.ts"; import { encodeTag } from "./util.ts"; import Expression, { Value } from "./common/expression.ts"; const VALID_PARAM_TYPES = new Set([ "xsd:int", "xsd:unsignedInt", "xsd:boolean", "xsd:string", "xsd:dateTime", "xsd:base64", "xsd:hexBinary", ]); function initDeviceData(): DeviceData { return { paths: new PathSet(), timestamps: new VersionedMap(), attributes: new VersionedMap(), trackers: new Map(), changes: new Set(), }; } export function init( deviceId: string, cwmpVersion: string, timeout: number, ): SessionContext { const timestamp = Date.now(); const sessionContext: SessionContext = { timestamp: timestamp, deviceId: deviceId, deviceData: initDeviceData(), cwmpVersion: cwmpVersion, timeout: timeout, provisions: [], channels: {}, virtualParameters: [], revisions: [0], rpcCount: 0, iteration: 0, cycle: 0, extensionsCache: {}, declarations: [], state: 0, authState: 0, }; return sessionContext; } function generateRpcId(sessionContext: SessionContext): string { return ( sessionContext.timestamp.toString(16) + ("0" + sessionContext.cycle.toString(16)).slice(-2) + ("0" + sessionContext.rpcCount.toString(16)).slice(-2) ); } export function configContextCallback( sessionContext: SessionContext, exp: Expression, ): Expression.Literal { if (exp instanceof Expression.Literal) return exp; else if (exp instanceof Expression.FunctionCall) { if (exp.name === "NOW") return new Expression.Literal(sessionContext.timestamp); if (exp.name === "REMOTE_ADDRESS") return new Expression.Literal( getRequestOrigin(sessionContext.httpRequest).remoteAddress, ); } else if (exp instanceof Expression.Parameter) { const deviceData = sessionContext.deviceData; const paths = deviceData.paths; const path = paths.get(exp.path.toString()); if (path) { const attrs = deviceData.attributes.get(path, 1); if (attrs?.value?.[1]) return new Expression.Literal(attrs.value[1][0]); } } return new Expression.Literal(null); } export async function inform( sessionContext: SessionContext, rpcReq: InformRequest, ): Promise { const timestamp = sessionContext.timestamp + sessionContext.iteration + 1; const params: [string, number, Attributes][] = [ [ "DeviceID.Manufacturer", timestamp, { object: [timestamp, 0], writable: [timestamp, 0], value: [timestamp, [rpcReq.deviceId.Manufacturer, "xsd:string"]], }, ], [ "DeviceID.OUI", timestamp, { object: [timestamp, 0], writable: [timestamp, 0], value: [timestamp, [rpcReq.deviceId.OUI, "xsd:string"]], }, ], [ "DeviceID.ProductClass", timestamp, { object: [timestamp, 0], writable: [timestamp, 0], value: [timestamp, [rpcReq.deviceId.ProductClass, "xsd:string"]], }, ], [ "DeviceID.SerialNumber", timestamp, { object: [timestamp, 0], writable: [timestamp, 0], value: [timestamp, [rpcReq.deviceId.SerialNumber, "xsd:string"]], }, ], ]; for (const p of rpcReq.parameterList) { const path = p[0]; params.push([ path.toString(), timestamp, { object: [timestamp, 0], value: [timestamp, p.slice(1) as [string | number | boolean, string]], }, ]); } params.push([ "Events.Inform", timestamp, { object: [timestamp, 0], writable: [timestamp, 0], value: [timestamp, [sessionContext.timestamp, "xsd:dateTime"]], }, ]); for (const e of rpcReq.event) { params.push([ `Events.${encodeTag(e.replace(/\s+/g, "_"))}`, timestamp, { object: [timestamp, 0], writable: [timestamp, 0], value: [timestamp, [sessionContext.timestamp, "xsd:dateTime"]], }, ]); } if (sessionContext.new) { params.push([ "DeviceID.ID", timestamp, { object: [timestamp, 0], writable: [timestamp, 0], value: [timestamp, [sessionContext.deviceId, "xsd:string"]], }, ]); params.push([ "Events.Registered", timestamp, { object: [timestamp, 0], writable: [timestamp, 0], value: [timestamp, [sessionContext.timestamp, "xsd:dateTime"]], }, ]); } sessionContext.deviceData.timestamps.revision = 1; sessionContext.deviceData.attributes.revision = 1; let toClear = null; for (const p of params) { // Don't need to clear wildcards for Events if (p[0].startsWith("Events.")) { device.set(sessionContext.deviceData, p[0], p[1], p[2]); } else { toClear = device.set( sessionContext.deviceData, p[0], p[1], p[2], toClear, ); } } if (toClear) { for (const c of toClear) device.clear(sessionContext.deviceData, c[0], c[1], c[2], c[3]); } return { name: "InformResponse" }; } export async function transferComplete( sessionContext: SessionContext, rpcReq: TransferCompleteRequest, ): Promise<{ acsResponse: AcsResponse; operation: Operation; fault: Fault }> { const revision = (sessionContext.revisions[sessionContext.revisions.length - 1] || 0) + 1; sessionContext.deviceData.timestamps.revision = revision; sessionContext.deviceData.attributes.revision = revision; const commandKey = rpcReq.commandKey; const operation = sessionContext.operations[commandKey]; if (!operation) { return { acsResponse: { name: "TransferCompleteResponse" }, operation: null, fault: null, }; } const instance = operation.args.instance; delete sessionContext.operations[commandKey]; if (!sessionContext.operationsTouched) sessionContext.operationsTouched = {}; sessionContext.operationsTouched[commandKey] = 1; if (rpcReq.faultStruct?.faultCode !== "0") { revertDownloadParameters(sessionContext, operation.args.instance); const fault: Fault = { code: `cwmp.${rpcReq.faultStruct.faultCode}`, message: rpcReq.faultStruct.faultString, detail: rpcReq.faultStruct, timestamp: operation.timestamp, }; return { acsResponse: { name: "TransferCompleteResponse" }, operation: operation, fault: fault, }; } let toClear = null; const timestamp = sessionContext.timestamp + sessionContext.iteration + 1; toClear = device.set( sessionContext.deviceData, `Downloads.${instance}.LastDownload`, timestamp, { value: [timestamp, [operation.timestamp, "xsd:dateTime"]] }, toClear, ); toClear = device.set( sessionContext.deviceData, `Downloads.${instance}.LastFileType`, timestamp, { value: [timestamp, [operation.args.fileType, "xsd:string"]] }, toClear, ); toClear = device.set( sessionContext.deviceData, `Downloads.${instance}.LastFileName`, timestamp, { value: [timestamp, [operation.args.fileName, "xsd:string"]] }, toClear, ); toClear = device.set( sessionContext.deviceData, `Downloads.${instance}.LastTargetFileName`, timestamp, { value: [timestamp, [operation.args.targetFileName, "xsd:string"]] }, toClear, ); toClear = device.set( sessionContext.deviceData, `Downloads.${instance}.StartTime`, timestamp, { value: [timestamp, [+rpcReq.startTime, "xsd:dateTime"]] }, toClear, ); toClear = device.set( sessionContext.deviceData, `Downloads.${instance}.CompleteTime`, timestamp, { value: [timestamp, [+rpcReq.completeTime, "xsd:dateTime"]] }, toClear, ); if (toClear) { for (const c of toClear) device.clear(sessionContext.deviceData, c[0], c[1], c[2], c[3]); } return { acsResponse: { name: "TransferCompleteResponse" }, operation: operation, fault: null, }; } function revertDownloadParameters( sessionContext: SessionContext, instance, ): void { const timestamp = sessionContext.timestamp + sessionContext.iteration + 1; const lastDownloadPath = sessionContext.deviceData.paths.add( `Downloads.${instance}.LastDownload`, ); const lastDownload = sessionContext.deviceData.attributes.get(lastDownloadPath); const toClear = device.set( sessionContext.deviceData, `Downloads.${instance}.Download`, timestamp, { value: [timestamp, [lastDownload?.value[1]?.[0] || 0, "xsd:dateTime"]], }, ); if (toClear) { for (const c of toClear) device.clear(sessionContext.deviceData, c[0], c[1], c[2], c[3]); } } export async function timeoutOperations( sessionContext: SessionContext, ): Promise<{ faults: Fault[]; operations: Operation[] }> { const revision = (sessionContext.revisions[sessionContext.revisions.length - 1] || 0) + 1; sessionContext.deviceData.timestamps.revision = revision; sessionContext.deviceData.attributes.revision = revision; const faults = []; const operations = []; for (const [commandKey, operation] of Object.entries( sessionContext.operations, )) { if (operation.name !== "Download") throw new Error(`Unknown operation name ${operation.name}`); const DOWNLOAD_TIMEOUT = localCache.getConfig( sessionContext.cacheSnapshot, "cwmp.downloadTimeout", 3600, (e) => configContextCallback(sessionContext, e), ) * 1000; if (sessionContext.timestamp < operation.timestamp + DOWNLOAD_TIMEOUT) continue; logger.accessWarn({ sessionContext: sessionContext, message: "Download operation timed out", commandKey: commandKey, }); const SUCCESS_ON_TIMEOUT = localCache.getConfig( sessionContext.cacheSnapshot, "cwmp.downloadSuccessOnTimeout", false, (e) => configContextCallback(sessionContext, e), ); if (SUCCESS_ON_TIMEOUT) { const r = { name: "TransferComplete" as const, commandKey: commandKey, startTime: 0, completeTime: 0, }; // Call transferComplete code and ignore the response await transferComplete(sessionContext, r); continue; } delete sessionContext.operations[commandKey]; if (!sessionContext.operationsTouched) sessionContext.operationsTouched = {}; sessionContext.operationsTouched[commandKey] = 1; faults.push({ code: "timeout", message: "Download operation timed out", timestamp: operation.timestamp, }); operations.push(operation); revertDownloadParameters(sessionContext, operation.args.instance); } return { faults, operations }; } export function addProvisions( sessionContext: SessionContext, channel: string, provisions: [string, ...Value[]][], ): void { // Multiply by two because every iteration is two // phases: read and update const MAX_ITERATIONS = localCache.getConfig( sessionContext.cacheSnapshot, "cwmp.maxCommitIterations", 32, (e) => configContextCallback(sessionContext, e), ) * 2; delete sessionContext.syncState; delete sessionContext.rpcRequest; sessionContext.declarations = []; sessionContext.provisionsRet = []; if (sessionContext.revisions[sessionContext.revisions.length - 1] > 0) { sessionContext.deviceData.timestamps.collapse(1); sessionContext.deviceData.attributes.collapse(1); sessionContext.revisions = [0]; sessionContext.extensionsCache = {}; } if (sessionContext.iteration !== sessionContext.cycle * MAX_ITERATIONS) { sessionContext.cycle += 1; sessionContext.rpcCount = 0; sessionContext.iteration = sessionContext.cycle * MAX_ITERATIONS; } sessionContext.channels[channel] |= 0; for (const provision of provisions) { const channels = [channel]; // Remove duplicate provisions const provisionStr = JSON.stringify(provision); for (const [j, p] of sessionContext.provisions.entries()) { if (JSON.stringify(p) === provisionStr) { sessionContext.provisions.splice(j, 1); for (const c of Object.keys(sessionContext.channels)) { if (sessionContext.channels[c] & (1 << j)) channels.push(c); const a = sessionContext.channels[c] >> (j + 1); sessionContext.channels[c] &= (1 << j) - 1; sessionContext.channels[c] |= a << j; } } } for (const c of channels) sessionContext.channels[c] |= 1 << sessionContext.provisions.length; sessionContext.provisions.push(provision); } } export function clearProvisions(sessionContext: SessionContext): void { // Multiply by two because every iteration is two // phases: read and update const MAX_ITERATIONS = +localCache.getConfig( sessionContext.cacheSnapshot, "cwmp.maxCommitIterations", 32, (e) => configContextCallback(sessionContext, e), ) * 2; if (sessionContext.revisions[sessionContext.revisions.length - 1] > 0) { sessionContext.deviceData.timestamps.collapse(1); sessionContext.deviceData.attributes.collapse(1); } if (sessionContext.iteration !== sessionContext.cycle * MAX_ITERATIONS) { sessionContext.cycle += 1; sessionContext.rpcCount = 0; sessionContext.iteration = sessionContext.cycle * MAX_ITERATIONS; } delete sessionContext.syncState; delete sessionContext.rpcRequest; sessionContext.provisions = []; sessionContext.virtualParameters = []; sessionContext.channels = {}; sessionContext.declarations = []; sessionContext.provisionsRet = []; sessionContext.revisions = [0]; sessionContext.extensionsCache = {}; } async function runProvisions( sessionContext: SessionContext, provisions: any[][], startRevision: number, endRevision: number, ): Promise { const allProvisions = localCache.getProvisions(sessionContext.cacheSnapshot); const res = await Promise.all( provisions.map(async (provision) => { if (!allProvisions[provision[0]]) { if (defaultProvisions[provision[0]]) { const dec = []; let done = true; let fault = null; try { done = defaultProvisions[provision[0]]( sessionContext, provision, dec, startRevision, endRevision, ); } catch (err) { fault = { code: `script.${err.name}`, message: err.message, detail: { name: err.name, message: err.message, stack: `${err.name}: ${err.message}\n at ${provision[0]}`, }, }; } return { fault: fault, clear: null, declare: dec, done: done, returnValue: null, }; } return null; } return sandbox.run( allProvisions[provision[0]].script, { args: provision.slice(1) }, sessionContext, startRevision, endRevision, ); }), ); let done = true; let allDeclarations = []; let allClear = []; let fault; for (const r of res) { if (!r) continue; done = done && r.done; if (r.declare) allDeclarations = allDeclarations.concat(r.declare); if (r.clear) allClear = allClear.concat(r.clear); fault = r.fault || fault; } if (done) for (const d of allDeclarations) d.defer = false; return { fault: fault, clear: allClear, declare: allDeclarations, done: done, returnValue: null, }; } async function runVirtualParameters( sessionContext: SessionContext, provisions: any[][], startRevision: number, endRevision: number, ): Promise { const allVirtualParameters = localCache.getVirtualParameters( sessionContext.cacheSnapshot, ); const res = await Promise.all( provisions.map(async (provision) => { const globals = { args: provision.slice(1), }; const r = await sandbox.run( allVirtualParameters[provision[0]].script, globals, sessionContext, startRevision, endRevision, ); if (r.done && !r.fault) { if (!r.returnValue) { r.fault = { code: "script", message: "Invalid virtual parameter return value", }; return r; } const ret: { writable?: boolean; value?: [string | number | boolean, string?]; } = {}; if (r.returnValue.writable != null) { ret.writable = !!r.returnValue.writable; } else if ( provision[1].writable != null || provision[2].writable != null ) { r.fault = { code: "script", message: `Virtual parameter '${provision[0]}' must provide 'writable' attribute`, }; return r; } if (r.returnValue.value != null) { let v: string | number | boolean, t: string; if (Array.isArray(r.returnValue.value)) [v, t] = r.returnValue.value; else v = r.returnValue.value; if (!t) { if (typeof v === "number") t = "xsd:int"; else if (typeof v === "boolean") t = "xsd:boolean"; else if ((v as any) instanceof Date) t = "xsd:datetime"; else t = "xsd:string"; } if (v == null || !VALID_PARAM_TYPES.has(t)) { r.fault = { code: "script", message: "Invalid virtual parameter value attribute", }; return r; } ret.value = device.sanitizeParameterValue([v, t]); } else if (provision[1].value != null || provision[2].value != null) { r.fault = { code: "script", message: `Virtual parameter '${provision[0]}' must provide 'value' attribute`, }; return r; } r.returnValue = ret; } return r; }), ); let done = true; const virtualParameterUpdates = []; let allDeclarations = []; let allClear = []; let fault; for (const r of res) { if (!r) { virtualParameterUpdates.push(null); continue; } done = done && r.done; if (r.declare) allDeclarations = allDeclarations.concat(r.declare); if (r.clear) allClear = allClear.concat(r.clear); virtualParameterUpdates.push(r.returnValue); fault = r.fault || fault; } if (done) for (const d of allDeclarations) d.defer = false; return { fault: fault, clear: allClear, declare: allDeclarations, done: done, returnValue: done ? virtualParameterUpdates : null, }; } function runDeclarations( sessionContext: SessionContext, declarations: Declaration[], ): VirtualParameterDeclaration[] { if (!sessionContext.syncState) { sessionContext.syncState = { refreshAttributes: { exist: new Set(), object: new Set(), writable: new Set(), value: new Set(), notification: new Set(), accessList: new Set(), }, spv: new Map(), spa: new Map(), gpn: new Set(), gpnPatterns: new Map(), tags: new Map(), virtualParameterDeclarations: [], instancesToDelete: new Map(), instancesToCreate: new Map(), downloadsToDelete: new Set(), downloadsToCreate: new InstanceSet(), downloadsValues: new Map(), downloadsDownload: new Map(), reboot: 0, factoryReset: 0, }; } const allDeclareTimestamps = new Map(); const allDeclareAttributeTimestamps = new Map(); const allDeclareAttributeValues = new Map(); const allVirtualParameters = localCache.getVirtualParameters( sessionContext.cacheSnapshot, ); function mergeAttributeTimestamps(p: Path, attrs: AttributeTimestamps): void { let cur = allDeclareAttributeTimestamps.get(p); if (!cur) { allDeclareAttributeTimestamps.set(p, attrs); } else { cur = Object.assign({}, cur); for (const [k, v] of Object.entries(attrs)) cur[k] = Math.max(v, cur[k] || 0); allDeclareAttributeTimestamps.set(p, cur); } } function mergeAttributeValues( p: Path, attrs: AttributeValues, defer: boolean, ): void { let cur = allDeclareAttributeValues.get(p); if (!cur) { if (!defer) allDeclareAttributeValues.set(p, attrs); } else { cur = Object.assign({}, cur, attrs); allDeclareAttributeValues.set(p, cur); } } for (const declaration of declarations) { let path = declaration.path; let unpacked: Path[]; // Can't run declarations on root if (!path.length) continue; if ( (path.alias | path.wildcard) & 1 || path.segments[0] === "VirtualParameters" ) { sessionContext.deviceData.paths.add("VirtualParameters"); if ((path.alias | path.wildcard) & 2) { sessionContext.deviceData.paths.add("VirtualParameters.*"); for (const k of Object.keys(allVirtualParameters)) { sessionContext.deviceData.paths.add(`VirtualParameters.${k}`); } } } if ((path.alias | path.wildcard) & 1 || path.segments[0] === "Reboot") sessionContext.deviceData.paths.add("Reboot"); if ((path.alias | path.wildcard) & 1 || path.segments[0] === "FactoryReset") sessionContext.deviceData.paths.add("FactoryReset"); if (path.alias) { const aliasDecs = device.getAliasDeclarations( path, declaration.pathGet || 1, ); for (const ad of aliasDecs) { const p = sessionContext.deviceData.paths.add(ad.path.toString()); allDeclareTimestamps.set( p, Math.max(ad.pathGet || 1, allDeclareTimestamps.get(p) || 0), ); let attrTrackers: string[]; if (ad.attrGet) { attrTrackers = Object.keys(ad.attrGet); mergeAttributeTimestamps(p, ad.attrGet); } device.track( sessionContext.deviceData, p.toString(), "prerequisite", attrTrackers, ); } unpacked = device.unpack(sessionContext.deviceData, path); for (const u of unpacked) { allDeclareTimestamps.set( u, Math.max(declaration.pathGet || 1, allDeclareTimestamps.get(u) || 0), ); if (declaration.attrGet) mergeAttributeTimestamps(u, declaration.attrGet); } } else { path = sessionContext.deviceData.paths.add(path.toString()); allDeclareTimestamps.set( path, Math.max(declaration.pathGet || 1, allDeclareTimestamps.get(path) || 0), ); if (declaration.attrGet) mergeAttributeTimestamps(path, declaration.attrGet); device.track(sessionContext.deviceData, path.toString(), "prerequisite"); } if (declaration.attrSet) { if (path.alias | path.wildcard) { if (!unpacked) unpacked = device.unpack(sessionContext.deviceData, path); for (const u of unpacked) { mergeAttributeValues(u, declaration.attrSet, declaration.defer); // Ensure writable attr is available mergeAttributeTimestamps(u, { writable: 1 }); } } else { mergeAttributeValues(path, declaration.attrSet, declaration.defer); // Ensure writable attr is available mergeAttributeTimestamps(path, { writable: 1 }); } } if (declaration.pathSet != null) { let minInstances: number, maxInstances: number; if (Array.isArray(declaration.pathSet)) { minInstances = declaration.pathSet[0]; maxInstances = declaration.pathSet[1]; } else { minInstances = maxInstances = declaration.pathSet; } let parent = path.slice(0, -1); let keys: Record; if (path.segments[path.length - 1] instanceof Expression) { keys = {}; for (const [p, v] of device.expressionToAlias( path.segments[path.length - 1] as Expression, )) keys[p.toString()] = v as string; } else if (path.segments[path.length - 1] === "*") { keys = {}; } if (!parent.wildcard && !parent.alias) { parent = sessionContext.deviceData.paths.add(parent.toString()); if (!unpacked) unpacked = device.unpack(sessionContext.deviceData, path); // Ensure writable attr is available mergeAttributeTimestamps(parent, { writable: 1 }); for (const u of unpacked) mergeAttributeTimestamps(u, { writable: 1 }); processInstances( sessionContext, parent, unpacked, keys, minInstances, maxInstances, declaration.defer, ); } else { const parentsUnpacked = device.unpack( sessionContext.deviceData, parent, ); for (const par of parentsUnpacked) { const up = device.unpack( sessionContext.deviceData, par.concat(path.slice(-1)), ); // Ensure writable attr is available mergeAttributeTimestamps(par, { writable: 1 }); for (const u of up) mergeAttributeTimestamps(u, { writable: 1 }); processInstances( sessionContext, par, up, keys, minInstances, maxInstances, declaration.defer, ); } } } } return processDeclarations( sessionContext, allDeclareTimestamps, allDeclareAttributeTimestamps, allDeclareAttributeValues, ); } export async function rpcRequest( sessionContext: SessionContext, _declarations: Declaration[], ): Promise<{ fault: Fault; rpcId: string; rpc: AcsRequest }> { if (sessionContext.rpcRequest != null) { return { fault: null, rpcId: generateRpcId(sessionContext), rpc: sessionContext.rpcRequest, }; } if ( !sessionContext.virtualParameters.length && !sessionContext.declarations.length && !_declarations?.length && !sessionContext.provisions.length ) return { fault: null, rpcId: null, rpc: null }; if ( sessionContext.declarations.length <= sessionContext.virtualParameters.length ) { const inception = sessionContext.declarations.length; const revision = (sessionContext.revisions[inception] || 0) + 1; sessionContext.deviceData.timestamps.revision = revision; sessionContext.deviceData.attributes.revision = revision; let run: typeof runProvisions, provisions; if (inception === 0) { run = runProvisions; provisions = sessionContext.provisions; } else { run = runVirtualParameters; provisions = sessionContext.virtualParameters[inception - 1]; } const { fault, clear: toClear, declare: decs, done: done, returnValue: ret, } = await run( sessionContext, provisions, sessionContext.revisions[inception - 1] || 0, sessionContext.revisions[inception], ); if (fault) { fault.timestamp = sessionContext.timestamp; return { fault: fault, rpcId: null, rpc: null }; } // Enforce max clear timestamp for (const c of toClear) { if (c[1] > sessionContext.timestamp) c[1] = sessionContext.timestamp; if (c[2]) { for (const [k, v] of Object.entries(c[2])) if (v > sessionContext.timestamp) c[2][k] = sessionContext.timestamp; } } sessionContext.declarations.push(decs); sessionContext.provisionsRet[inception] = inception ? ret : done; for (const d of decs) { // Enforce max timestamp if (d.pathGet > sessionContext.timestamp) d.pathGet = sessionContext.timestamp; if (d.attrGet) { for (const [k, v] of Object.entries(d.attrGet)) { if (v > sessionContext.timestamp) d.attrGet[k] = sessionContext.timestamp; } } } if (toClear) { for (const c of toClear) device.clear(sessionContext.deviceData, c[0], c[1], c[2], c[3]); } return rpcRequest(sessionContext, _declarations); } if (_declarations?.length) { delete sessionContext.syncState; if (!sessionContext.declarations[0]) sessionContext.declarations[0] = []; sessionContext.declarations[0] = sessionContext.declarations[0].concat(_declarations); return rpcRequest(sessionContext, null); } if (sessionContext.rpcCount >= 255) { return { fault: { code: "too_many_rpcs", message: "Too many RPC requests", timestamp: sessionContext.timestamp, }, rpcId: null, rpc: null, }; } if (sessionContext.revisions.length >= 8) { return { fault: { code: "deeply_nested_vparams", message: "Virtual parameters are referencing other virtual parameters in a deeply nested manner", timestamp: sessionContext.timestamp, }, rpcId: null, rpc: null, }; } if (sessionContext.cycle >= 255) { return { fault: { code: "too_many_cycles", message: "Too many provision cycles", timestamp: sessionContext.timestamp, }, rpcId: null, rpc: null, }; } // Multiply by two because every iteration is two // phases: read and update const MAX_ITERATIONS = +localCache.getConfig( sessionContext.cacheSnapshot, "cwmp.maxCommitIterations", 32, (e) => configContextCallback(sessionContext, e), ) * 2; if (sessionContext.iteration >= MAX_ITERATIONS * (sessionContext.cycle + 1)) { return { fault: { code: "too_many_commits", message: "Too many commit iterations", timestamp: sessionContext.timestamp, }, rpcId: null, rpc: null, }; } if ( !( sessionContext.syncState && sessionContext.syncState.virtualParameterDeclarations && sessionContext.syncState.virtualParameterDeclarations.length >= sessionContext.declarations.length ) ) { const inception = sessionContext.syncState && sessionContext.syncState.virtualParameterDeclarations ? sessionContext.syncState.virtualParameterDeclarations.length : 0; // Avoid unnecessary increment of iteration when using vparams if (inception === sessionContext.declarations.length - 1) sessionContext.iteration += 2; let vpd = runDeclarations( sessionContext, sessionContext.declarations[inception], ); const timestamp = sessionContext.timestamp + sessionContext.iteration; let toClear: Clear[]; const allVirtualParameters = localCache.getVirtualParameters( sessionContext.cacheSnapshot, ); vpd = vpd.filter((declaration) => { if (Object.keys(allVirtualParameters).length) { if (declaration[0].length === 1) { // Avoid setting on every inform as "exist" timestamp // is not saved in DB if (!sessionContext.deviceData.attributes.has(declaration[0])) { toClear = device.set( sessionContext.deviceData, declaration[0].toString(), timestamp, { object: [timestamp, 1], writable: [timestamp, 0] }, toClear, ); } return false; } else if (declaration[0].length === 2) { if (declaration[0].segments[1] === "*") { for (const k of Object.keys(allVirtualParameters)) { toClear = device.set( sessionContext.deviceData, `VirtualParameters.${k}`, timestamp, { object: [timestamp, 0], }, toClear, ); } toClear = device.set( sessionContext.deviceData, declaration[0].toString(), timestamp, null, toClear, ); return false; } else if ( allVirtualParameters[declaration[0].segments[1] as string] ) { // Avoid setting on every inform as "exist" timestamp // is not saved in DB if (!sessionContext.deviceData.attributes.has(declaration[0])) { toClear = device.set( sessionContext.deviceData, declaration[0].toString(), timestamp, { object: [timestamp, 0] }, toClear, ); } return true; } } } for (const p of sessionContext.deviceData.paths.findCompat( declaration[0], false, true, )) { if (sessionContext.deviceData.attributes.has(p)) { if (!toClear) toClear = []; toClear.push([declaration[0], timestamp]); break; } } return false; }); if (toClear) { for (const c of toClear) device.clear(sessionContext.deviceData, c[0], c[1], c[2], c[3]); } sessionContext.syncState.virtualParameterDeclarations[inception] = vpd; return rpcRequest(sessionContext, null); } if (!sessionContext.syncState) return { fault: null, rpcId: null, rpc: null }; const inception = sessionContext.declarations.length - 1; let provisions = generateGetVirtualParameterProvisions( sessionContext, sessionContext.syncState.virtualParameterDeclarations[inception], ); if (!provisions) { sessionContext.rpcRequest = generateGetRpcRequest(sessionContext); if (!sessionContext.rpcRequest) { // Only check after read stage is complete to minimize reprocessing of // declarations especially during initial discovery of data model if (sessionContext.deviceData.changes.has("prerequisite")) { delete sessionContext.syncState; device.clearTrackers(sessionContext.deviceData, "prerequisite"); return rpcRequest(sessionContext, null); } let toClear: Clear[]; const timestamp = sessionContext.timestamp + sessionContext.iteration + 1; // Update tags for (const [p, v] of sessionContext.syncState.tags) { const c = sessionContext.deviceData.attributes.get(p); if (v && !c) { toClear = device.set( sessionContext.deviceData, p.toString(), timestamp, { object: [timestamp, 0], writable: [timestamp, 1], value: [timestamp, [true, "xsd:boolean"]], }, toClear, ); } else if (c && !v) { toClear = device.set( sessionContext.deviceData, p.toString(), timestamp, null, toClear, ); } } // Downloads let index: number; for (const instance of sessionContext.syncState.downloadsToCreate) { if (index == null) { index = 0; for (const p of sessionContext.deviceData.paths.findCompat( Path.parse("Downloads.*"), false, true, )) { if ( +p.segments[1] > index && sessionContext.deviceData.attributes.has(p) ) index = +p.segments[1]; } } ++index; toClear = device.set( sessionContext.deviceData, "Downloads", timestamp, { object: [timestamp, 1], writable: [timestamp, 1] }, toClear, ); toClear = device.set( sessionContext.deviceData, `Downloads.${index}`, timestamp, { object: [timestamp, 1], writable: [timestamp, 1] }, toClear, ); const params = { FileType: { writable: 1, value: [instance.FileType || "", "xsd:string"], }, FileName: { writable: 1, value: [instance.FileName || "", "xsd:string"], }, TargetFileName: { writable: 1, value: [instance.TargetFileName || "", "xsd:string"], }, Download: { writable: 1, value: [instance.Download || 0, "xsd:dateTime"], }, LastFileType: { writable: 0, value: ["", "xsd:string"] }, LastFileName: { writable: 0, value: ["", "xsd:string"] }, LastTargetFileName: { writable: 0, value: ["", "xsd:string"] }, LastDownload: { writable: 0, value: [0, "xsd:dateTime"] }, StartTime: { writable: 0, value: [0, "xsd:dateTime"] }, CompleteTime: { writable: 0, value: [0, "xsd:dateTime"] }, }; for (const [k, v] of Object.entries(params)) { toClear = device.set( sessionContext.deviceData, `Downloads.${index}.${k}`, timestamp, { object: [timestamp, 0], writable: [timestamp, v.writable as 0 | 1], value: [ timestamp, v.value as [string | number | boolean, string], ], }, toClear, ); } toClear = device.set( sessionContext.deviceData, `Downloads.${index}.*`, timestamp, null, toClear, ); } sessionContext.syncState.downloadsToCreate.clear(); for (const instance of sessionContext.syncState.downloadsToDelete) { toClear = device.set( sessionContext.deviceData, instance.toString(), timestamp, null, toClear, ); for (const p of sessionContext.syncState.downloadsValues.keys()) { if (p.segments[1] === instance.segments[1]) sessionContext.syncState.downloadsValues.delete(p); } } sessionContext.syncState.downloadsToDelete.clear(); for (const [p, v] of sessionContext.syncState.downloadsValues) { const attrs = sessionContext.deviceData.attributes.get(p); if (attrs) { if (attrs.writable?.[1] && attrs.value) { const val = device.sanitizeParameterValue([v, attrs.value[1][1]]); if (val[0] !== attrs.value[1][0]) { toClear = device.set( sessionContext.deviceData, p.toString(), timestamp, { value: [timestamp, val] }, toClear, ); } } } } if (toClear || sessionContext.deviceData.changes.has("prerequisite")) { if (toClear) { for (const c of toClear) device.clear(sessionContext.deviceData, c[0], c[1], c[2], c[3]); } return rpcRequest(sessionContext, null); } provisions = generateSetVirtualParameterProvisions( sessionContext, sessionContext.syncState.virtualParameterDeclarations[inception], ); if (!provisions) sessionContext.rpcRequest = generateSetRpcRequest(sessionContext); } } if (provisions) { sessionContext.virtualParameters.push(provisions); sessionContext.revisions.push(sessionContext.revisions[inception]); return rpcRequest(sessionContext, null); } if (sessionContext.rpcRequest) { return { fault: null, rpcId: generateRpcId(sessionContext), rpc: sessionContext.rpcRequest, }; } ++sessionContext.revisions[inception]; sessionContext.declarations.pop(); sessionContext.syncState.virtualParameterDeclarations.pop(); const ret = sessionContext.provisionsRet.splice(inception)[0]; if (!ret) return rpcRequest(sessionContext, null); sessionContext.revisions.pop(); const rev = sessionContext.revisions[sessionContext.revisions.length - 1] || 0; sessionContext.deviceData.timestamps.collapse(rev + 1); sessionContext.deviceData.attributes.collapse(rev + 1); sessionContext.deviceData.timestamps.revision = rev + 1; sessionContext.deviceData.attributes.revision = rev + 1; for (const k of Object.keys(sessionContext.extensionsCache)) { if (rev < Number(k.split(":", 1)[0])) delete sessionContext.extensionsCache[k]; } const vparams = sessionContext.virtualParameters.pop(); if (!vparams) return { fault: null, rpcId: null, rpc: null }; const timestamp = sessionContext.timestamp + sessionContext.iteration; let toClear; for (const [i, vpu] of ret.entries()) { for (const [k, v] of Object.entries(vpu)) vpu[k] = [timestamp + (vparams[i][2][k] != null ? 1 : 0), v]; toClear = device.set( sessionContext.deviceData, `VirtualParameters.${vparams[i][0]}`, timestamp, vpu, toClear, ); } if (toClear) { for (const c of toClear) device.clear(sessionContext.deviceData, c[0], c[1], c[2], c[3]); } return rpcRequest(sessionContext, null); } function generateGetRpcRequest( sessionContext: SessionContext, ): GetParameterNames | GetParameterValues | GetParameterAttributes { const syncState = sessionContext.syncState; if (!syncState) return null; for (const path of syncState.refreshAttributes.exist) { let found = false; for (const p of sessionContext.deviceData.paths.findCompat( path, false, true, 99, )) { if ( syncState.refreshAttributes.value.has(p) || syncState.refreshAttributes.object.has(p) || syncState.refreshAttributes.writable.has(p) || syncState.refreshAttributes.notification.has(p) || syncState.refreshAttributes.accessList.has(p) || syncState.gpn.has(p) ) { found = true; break; } } if (!found) { const p = sessionContext.deviceData.paths.add( path.slice(0, -1).toString(), ); syncState.gpn.add(p); const f = 1 << p.length; syncState.gpnPatterns.set(p, f | syncState.gpnPatterns.get(p)); } } syncState.refreshAttributes.exist.clear(); for (const path of syncState.refreshAttributes.object) { let found = false; for (const p of sessionContext.deviceData.paths.findCompat( path, false, true, 99, )) { if ( syncState.refreshAttributes.value.has(p) || (p.length > path.length && (syncState.refreshAttributes.object.has(p) || syncState.refreshAttributes.writable.has(p) || syncState.refreshAttributes.notification.has(p) || syncState.refreshAttributes.accessList.has(p))) ) { found = true; break; } } if (!found) { const p = sessionContext.deviceData.paths.add( path.slice(0, -1).toString(), ); syncState.gpn.add(p); const f = 1 << p.length; syncState.gpnPatterns.set(p, f | syncState.gpnPatterns.get(p)); } } syncState.refreshAttributes.object.clear(); for (const path of syncState.refreshAttributes.writable) { const p = sessionContext.deviceData.paths.add(path.slice(0, -1).toString()); syncState.gpn.add(p); const f = 1 << p.length; syncState.gpnPatterns.set(p, f | syncState.gpnPatterns.get(p)); } syncState.refreshAttributes.writable.clear(); if (syncState.gpn.size) { const GPN_NEXT_LEVEL = localCache.getConfig( sessionContext.cacheSnapshot, "cwmp.gpnNextLevel", 0, (e) => configContextCallback(sessionContext, e), ) as number; const paths = Array.from(syncState.gpn.keys()).sort( (a, b) => b.length - a.length, ); let path = paths.pop(); // Skip root GPN workaround if (path && !path.length) { const SKIP_ROOT_GPN = localCache.getConfig( sessionContext.cacheSnapshot, "cwmp.skipRootGpn", false, (e) => configContextCallback(sessionContext, e), ); if (SKIP_ROOT_GPN) path = paths.pop(); } while ( path && path.length && !sessionContext.deviceData.attributes.has(path) ) { syncState.gpn.delete(path); path = paths.pop(); } if (path) { let nextLevel: boolean; let est = 0; if (path.length >= GPN_NEXT_LEVEL) { const patterns: [Path, number][] = [[path, 0]]; for (const p of sessionContext.deviceData.paths.findCompat( path, true, false, 99, )) { const v = syncState.gpnPatterns.get(p); if (v) patterns.push([p, (v >> path.length) << path.length]); } est = estimateGpnCount(patterns); } if (est < Math.pow(2, Math.max(0, 8 - path.length))) { nextLevel = true; syncState.gpn.delete(path); } else { nextLevel = false; for (const p of sessionContext.deviceData.paths.findCompat( path, false, true, 99, )) syncState.gpn.delete(p); } return { name: "GetParameterNames", parameterPath: path.length ? path.toString() + "." : "", nextLevel: nextLevel, }; } } if (syncState.refreshAttributes.value.size) { const GPV_BATCH_SIZE = localCache.getConfig( sessionContext.cacheSnapshot, "cwmp.gpvBatchSize", 32, (e) => configContextCallback(sessionContext, e), ) as number; const parameterNames: string[] = []; for (const path of syncState.refreshAttributes.value) { syncState.refreshAttributes.value.delete(path); // Need to check in case param is deleted or changed to object const attrs = sessionContext.deviceData.attributes.get(path); if (attrs?.object?.[1] === 0) { parameterNames.push(path.toString()); if (parameterNames.length >= GPV_BATCH_SIZE) break; } } if (parameterNames.length) { return { name: "GetParameterValues", parameterNames: parameterNames, }; } } if ( syncState.refreshAttributes.notification.size || syncState.refreshAttributes.accessList.size ) { const GPV_BATCH_SIZE = localCache.getConfig( sessionContext.cacheSnapshot, "cwmp.gpvBatchSize", 32, (e) => configContextCallback(sessionContext, e), ) as number; const parameterNames: string[] = []; for (const path of syncState.refreshAttributes.notification) { syncState.refreshAttributes.notification.delete(path); syncState.refreshAttributes.accessList.delete(path); // Need to check in case param is deleted const attrs = sessionContext.deviceData.attributes.get(path); if (attrs) { parameterNames.push(path.toString()); if (parameterNames.length >= GPV_BATCH_SIZE) break; } } if (parameterNames.length < GPV_BATCH_SIZE) { for (const path of syncState.refreshAttributes.accessList) { syncState.refreshAttributes.accessList.delete(path); const attrs = sessionContext.deviceData.attributes.get(path); if (attrs) { parameterNames.push(path.toString()); if (parameterNames.length >= GPV_BATCH_SIZE) break; } } } if (parameterNames.length) { return { name: "GetParameterAttributes", parameterNames: parameterNames, }; } } return null; } function compareAccessLists(list1: string[], list2: string[]): boolean { if (list1.length !== list2.length) return false; for (const [i, v] of list1.entries()) if (v !== list2[i]) return false; return true; } function generateSetRpcRequest( sessionContext: SessionContext, ): ( | SetParameterValues | SetParameterAttributes | AddObject | DeleteObject | FactoryReset | Reboot | Download ) & { next?: string } { const syncState = sessionContext.syncState; if (!syncState) return null; const deviceData = sessionContext.deviceData; const SKIP_WRITABLE_CHECK = localCache.getConfig( sessionContext.cacheSnapshot, "cwmp.skipWritableCheck", false, (e) => configContextCallback(sessionContext, e), ); const canWrite = (attrs: Attributes): boolean => SKIP_WRITABLE_CHECK || (attrs.writable && !!attrs.writable[1]); // Delete instance for (const instances of syncState.instancesToDelete.values()) { for (const instance of instances) { const attrs = sessionContext.deviceData.attributes.get(instance); if (attrs && canWrite(attrs)) { instances.delete(instance); return { name: "DeleteObject", objectName: instance.toString() + ".", }; } } } // Create instance for (const [param, instances] of syncState.instancesToCreate) { const attrs = sessionContext.deviceData.attributes.get(param); if (attrs && canWrite(attrs)) { const instance = instances.values().next().value; if (instance) { instances.delete(instance); return { name: "AddObject", objectName: param.toString() + ".", instanceValues: instance, next: "getInstanceKeys", }; } } } // Set values const GPV_BATCH_SIZE = localCache.getConfig( sessionContext.cacheSnapshot, "cwmp.gpvBatchSize", 32, (e) => configContextCallback(sessionContext, e), ) as number; const DATETIME_MILLISECONDS = localCache.getConfig( sessionContext.cacheSnapshot, "cwmp.datetimeMilliseconds", true, (e) => configContextCallback(sessionContext, e), ); const BOOLEAN_LITERAL = localCache.getConfig( sessionContext.cacheSnapshot, "cwmp.booleanLiteral", true, (e) => configContextCallback(sessionContext, e), ); const parameterValues: [string, string | number | boolean, string][] = []; for (const [k, v] of syncState.spv) { syncState.spv.delete(k); const attrs = sessionContext.deviceData.attributes.get(k); const curVal = attrs.value?.[1]; if (curVal && canWrite(attrs)) { const val = v.slice() as [string | number | boolean, string]; if (!val[1]) val[1] = curVal[1]; device.sanitizeParameterValue(val); // Strip milliseconds if ( val[1] === "xsd:dateTime" && !DATETIME_MILLISECONDS && typeof val[0] === "number" ) val[0] -= val[0] % 1000; if (val[0] !== curVal[0] || val[1] !== curVal[1]) parameterValues.push([k.toString(), val[0], val[1]]); if (parameterValues.length >= GPV_BATCH_SIZE) break; } } if (parameterValues.length) { return { name: "SetParameterValues", parameterList: parameterValues, DATETIME_MILLISECONDS: DATETIME_MILLISECONDS, BOOLEAN_LITERAL: BOOLEAN_LITERAL, }; } // Set attributes const parameterAttributes: [string, number, string[]][] = []; for (const [k, v] of syncState.spa) { syncState.spa.delete(k); const attrs = sessionContext.deviceData.attributes.get(k); if ( v.notification != null && (!attrs.notification || v.notification === attrs.notification[1]) ) v.notification = null; if ( v.accessList != null && (!attrs.accessList || compareAccessLists(v.accessList, attrs.accessList[1])) ) v.accessList = null; if (v.notification != null || v.accessList != null) parameterAttributes.push([k.toString(), v.notification, v.accessList]); if (parameterAttributes.length >= GPV_BATCH_SIZE) break; } if (parameterAttributes.length) { return { name: "SetParameterAttributes", parameterList: parameterAttributes, }; } // Downloads for (const [p, t] of syncState.downloadsDownload) { if (!(t > 0 && t <= sessionContext.timestamp)) continue; const attrs = deviceData.attributes.get(p); const t2 = attrs?.value?.[1]?.[0] as number; if (!(t <= t2)) { const fileTypeAttrs = deviceData.attributes.get( deviceData.paths.get(p.slice(0, -1).toString() + ".FileType"), ); const fileNameAttrs = deviceData.attributes.get( deviceData.paths.get(p.slice(0, -1).toString() + ".FileName"), ); const targetFileNameAttrs = deviceData.attributes.get( deviceData.paths.get(p.slice(0, -1).toString() + ".TargetFileName"), ); return { name: "Download", commandKey: generateRpcId(sessionContext), instance: p.segments[1] as string, fileType: fileTypeAttrs?.value?.[1][0] as string, fileName: fileNameAttrs?.value?.[1][0] as string, targetFileName: targetFileNameAttrs?.value?.[1][0] as string, }; } } // Reboot if (syncState.reboot > 0 && syncState.reboot <= sessionContext.timestamp) { const p = sessionContext.deviceData.paths.get("Reboot"); const attrs = p ? sessionContext.deviceData.attributes.get(p) : null; const t = attrs?.value?.[1][0] as number; if (!(t >= syncState.reboot)) { delete syncState.reboot; return { name: "Reboot" }; } } // Factory reset if ( syncState.factoryReset > 0 && syncState.factoryReset <= sessionContext.timestamp ) { const p = sessionContext.deviceData.paths.get("FactoryReset"); const attrs = p ? sessionContext.deviceData.attributes.get(p) : null; const t = attrs?.value?.[1][0] as number; if (!(t >= syncState.factoryReset)) { delete syncState.factoryReset; return { name: "FactoryReset" }; } } return null; } function generateGetVirtualParameterProvisions( sessionContext: SessionContext, virtualParameterDeclarations: VirtualParameterDeclaration[], ): [ string, AttributeTimestamps, AttributeValues, AttributeTimestamps, AttributeValues, ][] { let provisions; if (virtualParameterDeclarations) { for (const declaration of virtualParameterDeclarations) { if (declaration[1]) { const currentTimestamps = {}; const currentValues = {}; const dec = {}; const attrs = sessionContext.deviceData.attributes.get(declaration[0]) || {}; for (const [k, v] of Object.entries(declaration[1])) { if (k !== "value" && k !== "writable") continue; if (!attrs[k] || v > attrs[k][0]) dec[k] = v; } for (const [k, v] of Object.entries(attrs)) { currentTimestamps[k] = v[0]; currentValues[k] = v[1]; } if (Object.keys(dec).length) { if (!provisions) provisions = []; provisions.push([ declaration[0].segments[1], dec, {}, currentTimestamps, currentValues, ]); } } } } return provisions; } function generateSetVirtualParameterProvisions( sessionContext: SessionContext, virtualParameterDeclarations: VirtualParameterDeclaration[], ): [ string, AttributeTimestamps, AttributeValues, AttributeTimestamps, AttributeValues, ][] { let provisions; if (virtualParameterDeclarations) { for (const declaration of virtualParameterDeclarations) { if (declaration[2]?.value != null) { const attrs = sessionContext.deviceData.attributes.get(declaration[0]); if ( attrs && attrs.writable && attrs.writable[1] && attrs.value && attrs.value[1] != null ) { const val = declaration[2].value.slice() as [ string | number | boolean, string, ]; if (val[1] == null) val[1] = attrs.value[1][1]; device.sanitizeParameterValue(val); if (val[0] !== attrs.value[1][0] || val[1] !== attrs.value[1][1]) { if (!provisions) provisions = []; const currentTimestamps = {}; const currentValues = {}; for (const [k, v] of Object.entries(attrs)) { currentTimestamps[k] = v[0]; currentValues[k] = v[1]; } provisions.push([ declaration[0].segments[1], {}, { value: val }, currentTimestamps, currentValues, ]); } } } } } return provisions; } function processDeclarations( sessionContext: SessionContext, allDeclareTimestamps, allDeclareAttributeTimestamps: Map, allDeclareAttributeValues: Map, ): VirtualParameterDeclaration[] { const deviceData = sessionContext.deviceData; const syncState = sessionContext.syncState; const paths = deviceData.paths.findCompat(Path.root, false, true, 99); paths.sort((a, b): number => a.wildcard === b.wildcard ? a.length - b.length : a.wildcard - b.wildcard, ); const virtualParameterDeclarations = [] as VirtualParameterDeclaration[]; function func( leafParam: Path, leafIsObject: number, leafTimestamp: number, _paths: Path[], ): void { const currentPath = _paths[0]; const children = new Map(); let declareTimestamp = 0; let declareAttributeTimestamps; let declareAttributeValues; let currentTimestamp = 0; let currentAttributes; if (currentPath.wildcard === 0) currentAttributes = deviceData.attributes.get(currentPath); for (const path of _paths) { if (path.length > currentPath.length) { const fragment = path.segments[currentPath.length] as string; let child = children.get(fragment); if (!child) { if (path.length > currentPath.length + 1) { // This is to ensure we don't descend more than one step at a time const p = path.slice(0, currentPath.length + 1); child = [p]; } else { child = []; } children.set(fragment, child); } child.push(path); continue; } currentTimestamp = Math.max( currentTimestamp, deviceData.timestamps.get(path) || 0, ); declareTimestamp = Math.max( declareTimestamp, allDeclareTimestamps.get(path) || 0, ); if (currentPath.wildcard === 0) { const attrs = allDeclareAttributeTimestamps.get(path); if (attrs) { if (declareAttributeTimestamps) { declareAttributeTimestamps = Object.assign( {}, declareAttributeTimestamps, ); for (const [k, v] of Object.entries(attrs)) { declareAttributeTimestamps[k] = Math.max( v, declareAttributeTimestamps[k] || 0, ); } } else { declareAttributeTimestamps = attrs; } } declareAttributeValues = allDeclareAttributeValues.get(path) || declareAttributeValues; } } if (currentAttributes) { leafParam = currentPath; leafIsObject = currentAttributes.object?.[1]; // Possible V8 bug causes null === 0 if (leafIsObject != null && leafIsObject === 0) leafTimestamp = Math.max(leafTimestamp, currentAttributes.object[0]); } else { leafTimestamp = Math.max(leafTimestamp, currentTimestamp); } switch ( currentPath.segments[0] !== "*" ? currentPath.segments[0] : leafParam.segments[0] ) { case "Reboot": if (currentPath.length === 1) { if (declareAttributeValues?.value) syncState.reboot = +new Date(declareAttributeValues.value[0]); } break; case "FactoryReset": if (currentPath.length === 1) { if (declareAttributeValues?.value) syncState.factoryReset = +new Date(declareAttributeValues.value[0]); } break; case "Tags": if ( currentPath.length === 2 && currentPath.wildcard === 0 && declareAttributeValues && declareAttributeValues.value ) { syncState.tags.set( currentPath, device.sanitizeParameterValue([ declareAttributeValues.value[0], "xsd:boolean", ])[0] as boolean, ); } break; case "Events": case "DeviceID": // Do nothing break; case "Downloads": if ( currentPath.length === 3 && currentPath.wildcard === 0 && declareAttributeValues && declareAttributeValues.value ) { if (currentPath.segments[2] === "Download") { syncState.downloadsDownload.set( currentPath, declareAttributeValues.value[0], ); } else { syncState.downloadsValues.set( currentPath, declareAttributeValues.value[0], ); } } break; case "VirtualParameters": if (currentPath.length <= 2) { let d; if (!(declareTimestamp <= currentTimestamp)) d = [currentPath]; if (currentPath.wildcard === 0) { if (declareAttributeTimestamps) { for (const [attrName, attrTimestamp] of Object.entries( declareAttributeTimestamps, )) { if ( !( currentAttributes && currentAttributes[attrName] && attrTimestamp <= currentAttributes[attrName][0] ) ) { if (!d) d = [currentPath]; if (!d[1]) d[1] = {}; d[1][attrName] = attrTimestamp; } } } if (declareAttributeValues) { if (!d) d = [currentPath]; d[2] = declareAttributeValues; } } if (d) virtualParameterDeclarations.push(d); } break; default: if ( declareTimestamp > currentTimestamp && declareTimestamp > leafTimestamp ) { if (currentPath === leafParam) { syncState.refreshAttributes.exist.add(leafParam); } else if (leafIsObject) { syncState.gpn.add(leafParam); if (leafTimestamp > 0) { const f = 1 << leafParam.length; syncState.gpnPatterns.set( leafParam, f | syncState.gpnPatterns.get(leafParam), ); } else { const f = ((1 << currentPath.length) - 1) ^ ((1 << leafParam.length) - 1); syncState.gpnPatterns.set( currentPath, f | syncState.gpnPatterns.get(currentPath), ); } } else { syncState.refreshAttributes.object.add(leafParam); if (leafIsObject == null) { const f = ((1 << syncState.gpnPatterns.size) - 1) ^ ((1 << leafParam.length) - 1); syncState.gpnPatterns.set( currentPath, f | syncState.gpnPatterns.get(currentPath), ); } } } if (currentAttributes) { if (declareAttributeTimestamps) { for (const [attrName, attrTimestamp] of Object.entries( declareAttributeTimestamps, )) { if ( !( currentAttributes[attrName] && attrTimestamp <= currentAttributes[attrName][0] ) ) { if (attrName === "value") { if ( !( currentAttributes.object && currentAttributes.object[1] != null ) ) syncState.refreshAttributes.object.add(currentPath); else if (currentAttributes.object[1] === 0) syncState.refreshAttributes.value.add(currentPath); } else if (attrName in syncState.refreshAttributes) { syncState.refreshAttributes[attrName].add(currentPath); } } } } if (declareAttributeValues) { if (declareAttributeValues.value != null) syncState.spv.set(currentPath, declareAttributeValues.value); if (declareAttributeValues.notification != null) { const spa = syncState.spa.get(currentPath); if (spa) { spa.notification = declareAttributeValues.notification; } else { syncState.spa.set(currentPath, { notification: declareAttributeValues.notification, accessList: null, }); } } if (declareAttributeValues.accessList != null) { const spa = syncState.spa.get(currentPath); if (spa) { spa.accessList = declareAttributeValues.accessList; } else { syncState.spa.set(currentPath, { notification: null, accessList: declareAttributeValues.accessList, }); } } } } } for (let [fragment, child] of children) { // This fine expression avoids duplicate visits, don't ask. if ( ((currentPath.wildcard ^ child[0].wildcard) & ((1 << currentPath.length) - 1)) >> leafParam.length === 0 ) { if (fragment !== "*") { const wildcardChild = children.get("*"); if (wildcardChild) child = child.concat(wildcardChild); } func(leafParam, leafIsObject, leafTimestamp, child); } } } if ( allDeclareTimestamps.size || allDeclareAttributeTimestamps.size || allDeclareAttributeValues.size ) func(Path.root, 1, 0, [Path.root, ...paths]); return virtualParameterDeclarations; } function processInstances( sessionContext: SessionContext, parent: Path, parameters: Path[], keys: Record, minInstances: number, maxInstances: number, defer: boolean, ): void { parent = sessionContext.deviceData.paths.add(parent.toString()); let instancesToCreate: InstanceSet, instancesToDelete: Set; if (parent.segments[0] === "Downloads") { if (parent.length !== 1) return; instancesToDelete = sessionContext.syncState.downloadsToDelete; instancesToCreate = sessionContext.syncState.downloadsToCreate; } else { instancesToDelete = sessionContext.syncState.instancesToDelete.get(parent); if (instancesToDelete == null) { instancesToDelete = new Set(); sessionContext.syncState.instancesToDelete.set(parent, instancesToDelete); } instancesToCreate = sessionContext.syncState.instancesToCreate.get(parent); if (instancesToCreate == null) { instancesToCreate = new InstanceSet(); sessionContext.syncState.instancesToCreate.set(parent, instancesToCreate); } } if (defer && instancesToCreate.size === 0 && instancesToDelete.size === 0) return; let counter = 0; for (const p of parameters) { ++counter; if (counter > maxInstances) instancesToDelete.add(p); else if (counter <= minInstances) instancesToDelete.delete(p); } // Key is null if deleting a particular instance rather than use alias if (!keys) return; for (const inst of instancesToCreate.superset(keys)) { ++counter; if (counter > maxInstances) instancesToCreate.delete(inst); } for (const inst of instancesToCreate.subset(keys)) { ++counter; if (counter <= minInstances) { instancesToCreate.delete(inst); instancesToCreate.add(JSON.parse(JSON.stringify(keys))); } } while (counter < minInstances) { ++counter; instancesToCreate.add(JSON.parse(JSON.stringify(keys))); } } export async function rpcResponse( sessionContext: SessionContext, id: string, _rpcRes: CpeResponse, ): Promise { function invalidResponse(message: string): Fault { return { code: "invalid_response", message: message, }; } if (id !== generateRpcId(sessionContext)) return invalidResponse("Request ID not recognized"); ++sessionContext.rpcCount; const rpcRes = _rpcRes; const rpcReq: typeof sessionContext.rpcRequest & { next?: string } = sessionContext.rpcRequest; if (!rpcReq.next) { sessionContext.rpcRequest = null; } else if (rpcReq.next === "getInstanceKeys") { const parameterNames = []; const instanceValues: Record = {}; const req = rpcReq as AddObject; const res = rpcRes as AddObjectResponse; for (const [k, v] of Object.entries(req.instanceValues)) { const n = `${req.objectName}${res.instanceNumber}.${k}`; parameterNames.push(n); instanceValues[n] = v; } if (!parameterNames.length) { sessionContext.rpcRequest = null; } else { const r: GetParameterValues & { next: "setInstanceKeys"; instanceValues: Record; } = { name: "GetParameterValues", parameterNames: parameterNames, next: "setInstanceKeys", instanceValues: instanceValues, }; sessionContext.rpcRequest = r; } } else if (rpcReq.next === "setInstanceKeys") { const req = rpcReq as GetParameterValues & { instanceValues: Record; }; const res = rpcRes as GetParameterValuesResponse; const parameterList: [string, string | number | boolean, string][] = []; for (const p of res.parameterList) { if (p[1] !== req.instanceValues[p[0].toString()]) { const v = device.sanitizeParameterValue([ req.instanceValues[p[0].toString()], p[2] as string, ]); parameterList.push([p[0].toString(), v[0], v[1]]); } } if (!parameterList.length) { sessionContext.rpcRequest = null; } else { const DATETIME_MILLISECONDS = localCache.getConfig( sessionContext.cacheSnapshot, "cwmp.datetimeMilliseconds", true, (e) => configContextCallback(sessionContext, e), ); const BOOLEAN_LITERAL = localCache.getConfig( sessionContext.cacheSnapshot, "cwmp.booleanLiteral", true, (e) => configContextCallback(sessionContext, e), ); const r: SetParameterValues = { name: "SetParameterValues", parameterList: parameterList, DATETIME_MILLISECONDS: DATETIME_MILLISECONDS, BOOLEAN_LITERAL: BOOLEAN_LITERAL, }; sessionContext.rpcRequest = r; } } const timestamp = sessionContext.timestamp + sessionContext.iteration; const revision = (sessionContext.revisions[sessionContext.revisions.length - 1] || 0) + 1; sessionContext.deviceData.timestamps.revision = revision; sessionContext.deviceData.attributes.revision = revision; let toClear: Clear[]; if (rpcRes.name === "GetParameterValuesResponse") { if (rpcReq.name !== "GetParameterValues") return invalidResponse("Response name does not match request name"); const requested = new Set(rpcReq.parameterNames); for (const [path, value, type] of rpcRes.parameterList) { if (!requested.delete(path.toString())) { logger.accessWarn({ sessionContext: sessionContext, message: "Unexpected parameter in response", parameter: path.toString(), }); continue; } toClear = device.set( sessionContext.deviceData, path.toString(), timestamp, { object: [timestamp, 0], value: [timestamp, [value, type]], }, toClear, ); } if (requested.size) { for (const p of requested) { logger.accessWarn({ sessionContext: sessionContext, message: "Missing parameter in response", parameter: p, }); toClear = device.set( sessionContext.deviceData, p, timestamp, { object: [timestamp, 0], value: [timestamp, ["", "xsd:string"]], }, toClear, ); } } } else if (rpcRes.name === "GetParameterAttributesResponse") { if (rpcReq.name !== "GetParameterAttributes") throw new Error("Response name does not match request name"); const requested = new Set(rpcReq.parameterNames); for (const [path, notification, accessList] of rpcRes.parameterList) { if (!requested.delete(path.toString())) { logger.accessWarn({ sessionContext: sessionContext, message: "Unexpected parameter in response", parameter: path.toString(), }); continue; } toClear = device.set( sessionContext.deviceData, path.toString(), timestamp, { notification: [timestamp, notification], accessList: [timestamp, accessList], }, toClear, ); } if (requested.size) { for (const p of requested) { logger.accessWarn({ sessionContext: sessionContext, message: "Missing parameter in response", parameter: p, }); toClear = device.set( sessionContext.deviceData, p, timestamp, { notification: [timestamp, 0], accessList: [timestamp, []], }, toClear, ); } } } else if (rpcRes.name === "GetParameterNamesResponse") { if (rpcReq.name !== "GetParameterNames") return invalidResponse("Response name does not match request name"); let root: Path; if (!rpcReq.parameterPath) root = Path.root; else if (rpcReq.parameterPath.endsWith(".")) root = Path.parse(rpcReq.parameterPath.slice(0, -1)); else root = Path.parse(rpcReq.parameterPath); // Sort to help fill in missing params rpcRes.parameterList.sort((a, b) => { const pa = a[0]; const pb = b[0]; const l = Math.min(pa.length, pb.length); for (let i = 0; i < l; ++i) { if (pa.segments[i] > pb.segments[i]) return 1; if (pa.segments[i] < pb.segments[i]) return -1; } return pa.length - pb.length; }); // Fill in missing unreported parent params for (let idx = 1; idx < rpcRes.parameterList.length; ++idx) { const prev = rpcRes.parameterList[idx - 1][0]; const cur = rpcRes.parameterList[idx][0]; let offset = 0; for (let i = cur.length - 2; i >= 0; --i) { if (i < prev.length && prev.segments[i] === cur.segments[i]) { // Set object to true in case CPE didn't indicate that it's an object if (i === prev.length - 1) rpcRes.parameterList[idx - 1][1] = true; break; } // TODO consider showing a warning rpcRes.parameterList.splice(idx, 0, [cur.slice(0, i + 1), true, true]); ++offset; } idx += offset; } if (!root.length) { for (const n of [ "DeviceID", "Events", "Tags", "Reboot", "FactoryReset", "VirtualParameters", "Downloads", ]) { const p = sessionContext.deviceData.paths.get(n); if (p && sessionContext.deviceData.attributes.has(p)) sessionContext.deviceData.timestamps.set(p, timestamp); } } const wildcardPath = Path.parse("*"); const wildcardParams: Path[] = [root.concat(wildcardPath)]; for (const [path, object, writable] of rpcRes.parameterList) { if ( !path.toString().startsWith(rpcReq.parameterPath) && !(`${path.toString()}.` === rpcReq.parameterPath && !rpcReq.nextLevel) ) { logger.accessWarn({ sessionContext: sessionContext, message: "Unexpected parameter in response", parameter: path.toString(), }); continue; } if (object && !rpcReq.nextLevel) wildcardParams.push(path.concat(wildcardPath)); toClear = device.set( sessionContext.deviceData, path.toString(), timestamp, { object: [timestamp, object ? 1 : 0], writable: [timestamp, writable ? 1 : 0], }, toClear, ); } for (const path of wildcardParams) { toClear = device.set( sessionContext.deviceData, path.toString(), timestamp, null, toClear, ); } } else if (rpcRes.name === "SetParameterValuesResponse") { if (rpcReq.name !== "SetParameterValues") return invalidResponse("Response name does not match request name"); for (const p of rpcReq.parameterList) { toClear = device.set( sessionContext.deviceData, p[0], timestamp + 1, { object: [timestamp + 1, 0], value: [ timestamp + 1, p.slice(1) as [string | number | boolean, string], ], }, toClear, ); } } else if (rpcRes.name === "SetParameterAttributesResponse") { if (rpcReq.name !== "SetParameterAttributes") return invalidResponse("Response name does not match request name"); for (const p of rpcReq.parameterList) { let attrs; if (p[1] != null && p[2] != null) { attrs = { notification: [timestamp + 1, p[1]], accessList: [timestamp + 1, p[2]], }; } else if (p[1] != null) { attrs = { notification: [timestamp + 1, p[1]], }; } else if (p[2] != null) { attrs = { accessList: [timestamp + 1, p[2]], }; } toClear = device.set( sessionContext.deviceData, p[0], timestamp + 1, attrs, toClear, ); } } else if (rpcRes.name === "AddObjectResponse") { if (rpcReq.name !== "AddObject") return invalidResponse("Response name does not match request name"); toClear = device.set( sessionContext.deviceData, rpcReq.objectName + rpcRes.instanceNumber, timestamp + 1, { object: [timestamp + 1, 1] }, toClear, ); } else if (rpcRes.name === "DeleteObjectResponse") { if (rpcReq.name !== "DeleteObject") return invalidResponse("Response name does not match request name"); toClear = device.set( sessionContext.deviceData, rpcReq.objectName.slice(0, -1), timestamp + 1, null, toClear, ); } else if (rpcRes.name === "RebootResponse") { if (rpcReq.name !== "Reboot") return invalidResponse("Response name does not match request name"); toClear = device.set( sessionContext.deviceData, "Reboot", timestamp + 1, { value: [timestamp + 1, [sessionContext.timestamp, "xsd:dateTime"]] }, toClear, ); } else if (rpcRes.name === "FactoryResetResponse") { if (rpcReq.name !== "FactoryReset") return invalidResponse("Response name does not match request name"); toClear = device.set( sessionContext.deviceData, "FactoryReset", timestamp + 1, { value: [timestamp + 1, [sessionContext.timestamp, "xsd:dateTime"]] }, toClear, ); } else if (rpcRes.name === "DownloadResponse") { if (rpcReq.name !== "Download") return invalidResponse("Response name does not match request name"); toClear = device.set( sessionContext.deviceData, `Downloads.${rpcReq.instance}.Download`, timestamp + 1, { value: [timestamp + 1, [sessionContext.timestamp, "xsd:dateTime"]] }, toClear, ); if (rpcRes.status === 0) { toClear = device.set( sessionContext.deviceData, `Downloads.${rpcReq.instance}.LastDownload`, timestamp + 1, { value: [timestamp + 1, [sessionContext.timestamp, "xsd:dateTime"]], }, toClear, ); toClear = device.set( sessionContext.deviceData, `Downloads.${rpcReq.instance}.LastFileType`, timestamp + 1, { value: [timestamp + 1, [rpcReq.fileType, "xsd:string"]] }, toClear, ); toClear = device.set( sessionContext.deviceData, `Downloads.${rpcReq.instance}.LastFileName`, timestamp + 1, { value: [timestamp + 1, [rpcReq.fileType, "xsd:string"]] }, toClear, ); toClear = device.set( sessionContext.deviceData, `Downloads.${rpcReq.instance}.LastTargetFileName`, timestamp + 1, { value: [timestamp + 1, [rpcReq.fileType, "xsd:string"]] }, toClear, ); toClear = device.set( sessionContext.deviceData, `Downloads.${rpcReq.instance}.StartTime`, timestamp + 1, { value: [timestamp + 1, [+rpcRes.startTime, "xsd:dateTime"]] }, toClear, ); toClear = device.set( sessionContext.deviceData, `Downloads.${rpcReq.instance}.CompleteTime`, timestamp + 1, { value: [timestamp + 1, [+rpcRes.completeTime, "xsd:dateTime"]] }, toClear, ); } else { const operation = { name: "Download", timestamp: sessionContext.timestamp, provisions: sessionContext.provisions, channels: sessionContext.channels, retries: {}, args: { instance: rpcReq.instance, fileType: rpcReq.fileType, fileName: rpcReq.fileName, targetFileName: rpcReq.targetFileName, }, }; for (const channel of Object.keys(sessionContext.channels)) { if (sessionContext.retries[channel] != null) operation.retries[channel] = sessionContext.retries[channel]; } sessionContext.operations[rpcReq.commandKey] = operation; if (!sessionContext.operationsTouched) sessionContext.operationsTouched = {}; sessionContext.operationsTouched[rpcReq.commandKey] = 1; } } else { return invalidResponse("Response name not recognized"); } if (toClear) { for (const c of toClear) device.clear(sessionContext.deviceData, c[0], c[1], c[2], c[3]); } return null; } export async function rpcFault( sessionContext: SessionContext, id: string, faultResponse: CpeFault, ): Promise { const rpcReq = sessionContext.rpcRequest; delete sessionContext.syncState; delete sessionContext.rpcRequest; ++sessionContext.rpcCount; // Recover from invalid parameter name faults if (faultResponse.detail.faultCode === "9005") { const timestamp = sessionContext.timestamp + sessionContext.iteration + 1; const revision = (sessionContext.revisions[sessionContext.revisions.length - 1] || 0) + 1; sessionContext.deviceData.timestamps.revision = revision; sessionContext.deviceData.attributes.revision = revision; let toClear: Clear[]; if (rpcReq.name === "GetParameterNames") { if (rpcReq.parameterPath) { toClear = [ [Path.parse(rpcReq.parameterPath.replace(/\.$/, "")), timestamp], ]; } } else if (rpcReq.name === "GetParameterValues") { toClear = rpcReq.parameterNames.map( (p) => [Path.parse(p.replace(/\.$/, "")), timestamp] as Clear, ); } else if (rpcReq.name === "SetParameterValues") { toClear = ( rpcReq.parameterList as [string, string | number | boolean, string][] ).map((p) => [Path.parse(p[0].replace(/\.$/, "")), timestamp] as Clear); } else if (rpcReq.name === "AddObject") { toClear = [[Path.parse(rpcReq.objectName.replace(/\.$/, "")), timestamp]]; } else if (rpcReq.name === "DeleteObject") { toClear = [[Path.parse(rpcReq.objectName.replace(/\.$/, "")), timestamp]]; } else if (rpcReq.name === "GetParameterAttributes") { toClear = rpcReq.parameterNames.map( (p) => [Path.parse(p.replace(/\.$/, "")), timestamp] as Clear, ); } else if (rpcReq.name === "SetParameterAttributes") { toClear = (rpcReq.parameterList as [string, number, string[]][]).map( (p) => [Path.parse(p[0].replace(/\.$/, "")), timestamp] as Clear, ); } if (toClear) { for (const c of toClear) device.clear(sessionContext.deviceData, c[0], c[1], c[2], c[3]); return null; } } const fault: Fault = { code: `cwmp.${faultResponse.detail.faultCode}`, message: faultResponse.detail.faultString, detail: faultResponse.detail, }; return fault; } export async function deserialize( sessionContextString: string, ): Promise { const sessionContext = JSON.parse(sessionContextString) as SessionContext; for (const decs of sessionContext.declarations) for (const d of decs) d.path = Path.parse(d.path as unknown as string); const deviceData = initDeviceData(); for (const r of sessionContext.deviceData as unknown as any[]) { const path = deviceData.paths.add(r[0]); if (r[1]) deviceData.trackers.set(path, r[1]); if (r[2]) { deviceData.timestamps.setRevisions(path, r[2]); if (r[3]) deviceData.attributes.setRevisions(path, r[3]); } } sessionContext.deviceData = deviceData; // Ensure cache is populated await localCache.getRevision(); return sessionContext; } export async function serialize( sessionContext: SessionContext, ): Promise { const deviceData = []; for (const path of sessionContext.deviceData.paths.findCompat( Path.root, false, false, 99, )) { const e = [ path.toString(), sessionContext.deviceData.trackers.get(path) || null, sessionContext.deviceData.timestamps.getRevisions(path) || null, sessionContext.deviceData.attributes.getRevisions(path) || null, ]; deviceData.push(e); } const declarations = sessionContext.declarations.map((decs) => { return decs.map((d) => Object.assign({}, d, { path: d.path.toString() })); }); const jsonSessionContext = Object.assign({}, sessionContext, { deviceData: deviceData, declarations: declarations, syncState: null, toLoad: null, httpRequest: null, httpResponse: null, }); const sessionContextString = JSON.stringify(jsonSessionContext); return sessionContextString; } ================================================ FILE: lib/soap.ts ================================================ import { parseXml, Element, parseAttrs, encodeEntities, decodeEntities, } from "./xml-parser.ts"; import memoize from "./common/memoize.ts"; import { version as VERSION } from "../package.json"; import { InformRequest, FaultStruct, SpvFault, CpeFault, SoapMessage, TransferCompleteRequest, AcsRequest, type GetParameterNamesResponse, type GetParameterValuesResponse, type GetParameterAttributesResponse, type SetParameterValuesResponse, type SetParameterAttributesResponse, type AddObjectResponse, type DeleteObject, type DeleteObjectResponse, type RebootResponse, type FactoryResetResponse, type DownloadResponse, GetRPCMethodsRequest, RequestDownloadRequest, AcsResponse, } from "./types.ts"; import Path from "./common/path.ts"; const SERVER_NAME = `GenieACS/${VERSION}`; const NAMESPACES = { "1.0": { "soap-enc": "http://schemas.xmlsoap.org/soap/encoding/", "soap-env": "http://schemas.xmlsoap.org/soap/envelope/", xsd: "http://www.w3.org/2001/XMLSchema", xsi: "http://www.w3.org/2001/XMLSchema-instance", cwmp: "urn:dslforum-org:cwmp-1-0", }, "1.1": { "soap-enc": "http://schemas.xmlsoap.org/soap/encoding/", "soap-env": "http://schemas.xmlsoap.org/soap/envelope/", xsd: "http://www.w3.org/2001/XMLSchema", xsi: "http://www.w3.org/2001/XMLSchema-instance", cwmp: "urn:dslforum-org:cwmp-1-1", }, "1.2": { "soap-enc": "http://schemas.xmlsoap.org/soap/encoding/", "soap-env": "http://schemas.xmlsoap.org/soap/envelope/", xsd: "http://www.w3.org/2001/XMLSchema", xsi: "http://www.w3.org/2001/XMLSchema-instance", cwmp: "urn:dslforum-org:cwmp-1-2", }, "1.3": { "soap-enc": "http://schemas.xmlsoap.org/soap/encoding/", "soap-env": "http://schemas.xmlsoap.org/soap/envelope/", xsd: "http://www.w3.org/2001/XMLSchema", xsi: "http://www.w3.org/2001/XMLSchema-instance", cwmp: "urn:dslforum-org:cwmp-1-2", }, "1.4": { "soap-enc": "http://schemas.xmlsoap.org/soap/encoding/", "soap-env": "http://schemas.xmlsoap.org/soap/envelope/", xsd: "http://www.w3.org/2001/XMLSchema", xsi: "http://www.w3.org/2001/XMLSchema-instance", cwmp: "urn:dslforum-org:cwmp-1-3", }, }; let warnings: Record[]; const memoizedParseAttrs = memoize(parseAttrs); function parseBool(v: string): boolean { if (v === "true" || v === "1") return true; if (v === "false" || v === "0") return false; return null; } function event(xml: Element): string[] { return xml.children .filter((n) => n.localName === "EventStruct") .map((c) => c.children.find((n) => n.localName === "EventCode").text); } function parameterInfoList(xml: Element): [Path, boolean, boolean][] { return xml.children .map<[Path, boolean, boolean]>((e) => { if (e.localName !== "ParameterInfoStruct") return null; let param: string, value: string; for (const c of e.children) { switch (c.localName) { case "Name": param = c.text; break; case "Writable": value = c.text; break; } } let parsed: boolean = parseBool(value); if (parsed == null) { warnings.push({ message: "Missing or invalid XML node", element: "Writable", parameter: param, }); parsed = false; } try { if (param && !param.endsWith(".")) return [Path.parse(param), false, parsed]; else return [Path.parse(param.slice(0, -1)), true, parsed]; } catch { warnings.push({ message: "Missing or invalid XML node", element: "Name", parameter: param, }); return null; } }) .filter((e) => e != null); } const getValueType = memoize((str: string) => { const attrs = parseAttrs(str); for (const attr of attrs) if (attr.localName === "type") return attr.value; return null; }); function parameterValueList( xml: Element, ): [Path, string | number | boolean, string][] { return xml.children .map<[Path, string | number | boolean, string]>((e) => { if (e.localName !== "ParameterValueStruct") return null; let valueElement: Element, param: string; for (const c of e.children) { switch (c.localName) { case "Name": param = c.text; break; case "Value": valueElement = c; break; } } let valueType = getValueType(valueElement.attrs); if (!valueType) { warnings.push({ message: "Missing or invalid XML node", attribute: "type", parameter: param, }); valueType = "xsd:string"; } const value = decodeEntities(valueElement.text); let parsed: string | number | boolean = value; if (valueType === "xsd:boolean") { parsed = parseBool(value); if (parsed == null) { warnings.push({ message: "Missing or invalid XML node", element: "Value", parameter: param, }); parsed = value; } } else if (valueType === "xsd:int" || valueType === "xsd:unsignedInt") { parsed = parseInt(value); if (isNaN(parsed)) { warnings.push({ message: "Missing or invalid XML node", element: "Value", parameter: param, }); parsed = value; } } else if (valueType === "xsd:dateTime") { parsed = Date.parse(value); if (isNaN(parsed)) { warnings.push({ message: "Missing or invalid XML node", element: "Value", parameter: param, }); parsed = value; } } try { return [Path.parse(param), parsed, valueType]; } catch { warnings.push({ message: "Missing or invalid XML node", element: "Name", parameter: param, }); return null; } }) .filter((e) => e != null); } function parameterAttributeList(xml: Element): [Path, number, string[]][] { return xml.children .map<[Path, number, string[]]>((e) => { if (e.localName !== "ParameterAttributeStruct") return null; let notificationElement: Element, accessListElement: Element, param: string; for (const c of e.children) { switch (c.localName) { case "Name": param = c.text; break; case "Notification": notificationElement = c; break; case "AccessList": accessListElement = c; break; } } let notification = parseInt(notificationElement.text); if (isNaN(notification)) { warnings.push({ message: "Missing or invalid XML node", element: "Notification", parameter: param, }); notification = 0; } const accessList = accessListElement.children .filter((c) => c.localName === "string") .map((c) => decodeEntities(c.text)); try { return [Path.parse(param), notification, accessList]; } catch { warnings.push({ message: "Missing or invalid XML node", element: "Name", parameter: param, }); return null; } }) .filter((e) => e != null); } function GetParameterNames(methodRequest): string { return `${ methodRequest.parameterPath }${+methodRequest.nextLevel}`; } function GetParameterNamesResponse(xml): GetParameterNamesResponse { return { name: "GetParameterNamesResponse", parameterList: parameterInfoList( xml.children.find((n) => n.localName === "ParameterList"), ), }; } function GetParameterValues(methodRequest): string { return `${methodRequest.parameterNames .map((p) => `${p}`) .join("")}`; } function GetParameterValuesResponse(xml: Element): GetParameterValuesResponse { return { name: "GetParameterValuesResponse", parameterList: parameterValueList( xml.children.find((n) => n.localName === "ParameterList"), ), }; } function GetParameterAttributes(methodRequest): string { return `${methodRequest.parameterNames .map((p) => `${p}`) .join("")}`; } function GetParameterAttributesResponse( xml: Element, ): GetParameterAttributesResponse { return { name: "GetParameterAttributesResponse", parameterList: parameterAttributeList( xml.children.find((n) => n.localName === "ParameterList"), ), }; } function SetParameterValues(methodRequest): string { const params = methodRequest.parameterList.map((p) => { let val = p[1]; if (p[2] === "xsd:dateTime" && typeof val === "number") { val = new Date(val).toISOString(); if (methodRequest.DATETIME_MILLISECONDS === false) val = val.replace(".000", ""); } if (p[2] === "xsd:boolean" && typeof val === "boolean") if (methodRequest.BOOLEAN_LITERAL === false) val = +val; return `${p[0]}${encodeEntities("" + val)}`; }); return `${params.join("")}${ methodRequest.parameterKey || "" }`; } function SetParameterValuesResponse(xml: Element): SetParameterValuesResponse { let status: number; for (const c of xml.children) { switch (c.localName) { case "Status": status = parseInt(c.text); break; } } if (!(status >= 0)) { warnings.push({ message: "Missing or invalid XML node", element: "Status", }); status = 0; } return { name: "SetParameterValuesResponse", status: status, }; } function SetParameterAttributes(methodRequest): string { const params = methodRequest.parameterList.map((p) => { return `${ p[0] }${ p[1] == null ? "false" : "true" }${ p[1] == null ? "" : p[1] }${ p[2] == null ? "false" : "true" }${ p[2] == null ? "" : p[2].map((s) => `${encodeEntities(s)}`).join("") }`; }); return `${params.join("")}`; } function SetParameterAttributesResponse(): SetParameterAttributesResponse { return { name: "SetParameterAttributesResponse", }; } function AddObject(methodRequest): string { return `${ methodRequest.objectName }${ methodRequest.parameterKey || "" }`; } function AddObjectResponse(xml: Element): AddObjectResponse { let instanceNumber: string, status: number; for (const c of xml.children) { switch (c.localName) { case "InstanceNumber": instanceNumber = c.text; break; case "Status": status = parseInt(c.text); break; } } if (!/^[0-9]+$/.test(instanceNumber)) throw new Error("Missing or invalid instance number"); if (!(status >= 0)) { warnings.push({ message: "Missing or invalid XML node", element: "Status", }); status = 0; } return { name: "AddObjectResponse", instanceNumber: instanceNumber, status: status, }; } function DeleteObject(methodRequest): string { return `${ methodRequest.objectName }${ methodRequest.parameterKey || "" }`; } function DeleteObjectResponse(xml: Element): DeleteObjectResponse { let status: number; for (const c of xml.children) { switch (c.localName) { case "Status": status = parseInt(c.text); break; } } if (!(status >= 0)) { warnings.push({ message: "Missing or invalid XML node", element: "Status", }); status = 0; } return { name: "DeleteObjectResponse", status: status, }; } function Reboot(methodRequest): string { return `${ methodRequest.commandKey || "" }`; } function RebootResponse(): RebootResponse { return { name: "RebootResponse", }; } function FactoryReset(): string { return ""; } function FactoryResetResponse(): FactoryResetResponse { return { name: "FactoryResetResponse", }; } function Download(methodRequest): string { return `${ methodRequest.commandKey || "" }${methodRequest.fileType}${ methodRequest.url }${encodeEntities( methodRequest.username || "", )}${encodeEntities( methodRequest.password || "", )}${ methodRequest.fileSize || "0" }${encodeEntities( methodRequest.targetFileName || "", )}${ methodRequest.delaySeconds || "0" }${encodeEntities( methodRequest.successUrl || "", )}${encodeEntities( methodRequest.failureUrl || "", )}`; } function DownloadResponse(xml: Element): DownloadResponse { let status: number, startTime: number, completeTime: number; for (const c of xml.children) { switch (c.localName) { case "Status": status = parseInt(c.text); break; case "StartTime": startTime = Date.parse(c.text); break; case "CompleteTime": completeTime = Date.parse(c.text); break; } } if (!(status >= 0)) { warnings.push({ message: "Missing or invalid XML node", element: "Status", }); status = 0; } if (startTime == null || isNaN(startTime)) { warnings.push({ message: "Missing or invalid XML node", element: "StartTime", }); startTime = Date.parse("0001-01-01T00:00:00Z"); } if (completeTime == null || isNaN(completeTime)) { warnings.push({ message: "Missing or invalid XML node", element: "CompleteTime", }); completeTime = Date.parse("0001-01-01T00:00:00Z"); } return { name: "DownloadResponse", status: status, startTime: startTime, completeTime: completeTime, }; } function Inform(xml: Element): InformRequest { let retryCount: number, evnt: string[]; let parameterList: [Path, string | number | boolean, string][]; const deviceId = { Manufacturer: null, OUI: null, ProductClass: null, SerialNumber: null, }; for (const c of xml.children) { switch (c.localName) { case "ParameterList": parameterList = parameterValueList(c); break; case "DeviceId": for (const cc of c.children) { const n = cc.localName; if (n in deviceId) deviceId[n] = decodeEntities(cc.text); } break; case "Event": evnt = event(c); break; case "RetryCount": retryCount = parseInt(c.text); break; } } if (!deviceId || !deviceId.SerialNumber || !deviceId.OUI) throw new Error("Missing or invalid DeviceId element"); if (!parameterList) { warnings.push({ message: "Missing or invalid XML node", element: "ParameterList", }); parameterList = []; } if (!evnt) { warnings.push({ message: "Missing or invalid XML node", element: "Event" }); evnt = []; } if (retryCount == null || isNaN(retryCount)) { warnings.push({ message: "Missing or invalid XML node", element: "RetryCount", }); retryCount = 0; } return { name: "Inform", parameterList: parameterList, deviceId: deviceId, event: evnt, retryCount: retryCount, }; } function InformResponse(): string { return "1"; } function GetRPCMethods(): GetRPCMethodsRequest { return { name: "GetRPCMethods" }; } function GetRPCMethodsResponse(methodResponse): string { return `${methodResponse.methodList .map((m) => `${m}`) .join("")}`; } function TransferComplete(xml: Element): TransferCompleteRequest { let commandKey: string, _faultStruct: FaultStruct, startTime: number, completeTime: number; for (const c of xml.children) { switch (c.localName) { case "CommandKey": commandKey = c.text; break; case "FaultStruct": _faultStruct = faultStruct(c); break; case "StartTime": startTime = Date.parse(c.text); break; case "CompleteTime": completeTime = Date.parse(c.text); break; } } if (commandKey == null) { warnings.push({ message: "Missing or invalid XML node", element: "CommandKey", }); commandKey = ""; } if (!_faultStruct) { warnings.push({ message: "Missing or invalid XML node", element: "FaultStruct", }); _faultStruct = { faultCode: "0", faultString: "" }; } if (startTime == null || isNaN(startTime)) { warnings.push({ message: "Missing or invalid XML node", element: "StartTime", }); startTime = Date.parse("0001-01-01T00:00:00Z"); } if (completeTime == null || isNaN(completeTime)) { warnings.push({ message: "Missing or invalid XML node", element: "CompleteTime", }); completeTime = Date.parse("0001-01-01T00:00:00Z"); } return { name: "TransferComplete", commandKey: commandKey, faultStruct: _faultStruct, startTime: startTime, completeTime: completeTime, }; } function TransferCompleteResponse(): string { return ""; } function RequestDownload(xml: Element): RequestDownloadRequest { return { name: "RequestDownload", fileType: xml.children.find((n) => n.localName === "FileType").text, }; } function RequestDownloadResponse(): string { return ""; } function AcsFault(f: CpeFault): string { return `${encodeEntities( f.faultCode, )}${encodeEntities( f.faultString, )}${encodeEntities( f.detail.faultCode, )}${encodeEntities( f.detail.faultString, )}`; } function faultStruct(xml: Element): FaultStruct { let faultCode: string, faultString: string, setParameterValuesFault: SpvFault[], pn: string, fc: string, fs: string; for (const c of xml.children) { switch (c.localName) { case "FaultCode": faultCode = c.text; break; case "FaultString": faultString = decodeEntities(c.text); break; case "SetParameterValuesFault": setParameterValuesFault = setParameterValuesFault || []; pn = fc = fs = null; for (const cc of c.children) { switch (cc.localName) { case "ParameterName": pn = cc.text; break; case "FaultCode": fc = cc.text; break; case "FaultString": fs = decodeEntities(cc.text); break; } } setParameterValuesFault.push({ parameterName: pn, faultCode: fc, faultString: fs, }); } } if (faultCode == null) { warnings.push({ message: "Missing or invalid XML node", element: "FaultCode", }); faultCode = ""; } if (faultString == null) { warnings.push({ message: "Missing or invalid XML node", element: "FaultString", }); faultString = ""; } return { faultCode, faultString, setParameterValuesFault }; } function fault(xml: Element): CpeFault { let faultCode: string, faultString: string, detail: FaultStruct; for (const c of xml.children) { switch (c.localName) { case "faultcode": faultCode = c.text; break; case "faultstring": faultString = decodeEntities(c.text); break; case "detail": detail = faultStruct(c.children.find((n) => n.localName === "Fault")); break; } } if (!detail) throw new Error("Missing detail element"); if (faultCode == null) { warnings.push({ message: "Missing or invalid XML node", element: "faultcode", }); faultCode = "Client"; } if (faultString == null) { warnings.push({ message: "Missing or invalid XML node", element: "faultstring", }); faultString = "CWMP fault"; } return { faultCode, faultString, detail } as CpeFault; } export function request( body: string, warn: Record[], ): SoapMessage { warnings = warn; const rpc = { id: null, cwmpVersion: null, sessionTimeout: null, cpeRequest: null, cpeFault: null, cpeResponse: null, unknownMethod: null, }; if (!body.length) return rpc; const xml = parseXml(body); if (!xml.children.length) return rpc; const envelope = xml.children[0]; let headerElement: Element, bodyElement: Element; for (const c of envelope.children) { switch (c.localName) { case "Header": headerElement = c; break; case "Body": bodyElement = c; break; } } if (headerElement) { for (const c of headerElement.children) { switch (c.localName) { case "ID": rpc.id = decodeEntities(c.text); break; case "sessionTimeout": rpc.sessionTimeout = parseInt(c.text); break; } } } const methodElement = bodyElement.children[0]; if (methodElement.localName === "Inform") { let namespace, namespaceHref; for (const e of [methodElement, bodyElement, envelope]) { namespace = namespace || e.namespace; if (e.attrs) { const attrs = memoizedParseAttrs(e.attrs); const attr = namespace ? attrs.find( (s) => s.namespace === "xmlns" && s.localName === namespace, ) : attrs.find((s) => s.name === "xmlns"); if (attr) namespaceHref = attr.value; } } switch (namespaceHref) { case "urn:dslforum-org:cwmp-1-0": rpc.cwmpVersion = "1.0"; break; case "urn:dslforum-org:cwmp-1-1": rpc.cwmpVersion = "1.1"; break; case "urn:dslforum-org:cwmp-1-2": if (rpc.sessionTimeout) rpc.cwmpVersion = "1.3"; else rpc.cwmpVersion = "1.2"; break; case "urn:dslforum-org:cwmp-1-3": rpc.cwmpVersion = "1.4"; break; default: throw new Error("Unrecognized CWMP version"); } } switch (methodElement.localName) { case "Inform": rpc.cpeRequest = Inform(methodElement); break; case "GetRPCMethods": rpc.cpeRequest = GetRPCMethods(); break; case "TransferComplete": rpc.cpeRequest = TransferComplete(methodElement); break; case "RequestDownload": rpc.cpeRequest = RequestDownload(methodElement); break; case "GetParameterNamesResponse": rpc.cpeResponse = GetParameterNamesResponse(methodElement); break; case "GetParameterValuesResponse": rpc.cpeResponse = GetParameterValuesResponse(methodElement); break; case "GetParameterAttributesResponse": rpc.cpeResponse = GetParameterAttributesResponse(methodElement); break; case "SetParameterValuesResponse": rpc.cpeResponse = SetParameterValuesResponse(methodElement); break; case "SetParameterAttributesResponse": rpc.cpeResponse = SetParameterAttributesResponse(); break; case "AddObjectResponse": rpc.cpeResponse = AddObjectResponse(methodElement); break; case "DeleteObjectResponse": rpc.cpeResponse = DeleteObjectResponse(methodElement); break; case "RebootResponse": rpc.cpeResponse = RebootResponse(); break; case "FactoryResetResponse": rpc.cpeResponse = FactoryResetResponse(); break; case "DownloadResponse": rpc.cpeResponse = DownloadResponse(methodElement); break; case "Fault": rpc.cpeFault = fault(methodElement); break; default: rpc.unknownMethod = methodElement.localName; break; } return rpc; } const namespacesAttrs = { "1.0": Object.entries(NAMESPACES["1.0"]) .map(([k, v]) => `xmlns:${k}="${v}"`) .join(" "), "1.1": Object.entries(NAMESPACES["1.1"]) .map(([k, v]) => `xmlns:${k}="${v}"`) .join(" "), "1.2": Object.entries(NAMESPACES["1.2"]) .map(([k, v]) => `xmlns:${k}="${v}"`) .join(" "), "1.3": Object.entries(NAMESPACES["1.3"]) .map(([k, v]) => `xmlns:${k}="${v}"`) .join(" "), "1.4": Object.entries(NAMESPACES["1.4"]) .map(([k, v]) => `xmlns:${k}="${v}"`) .join(" "), }; export function response(rpc: { id: string; acsRequest?: AcsRequest; acsResponse?: AcsResponse; acsFault?: CpeFault; cwmpVersion?: string; }): { code: number; headers: Record; data: string } { const headers = { Server: SERVER_NAME, SOAPServer: SERVER_NAME, }; if (!rpc) return { code: 204, headers: headers, data: "" }; let body; if (rpc.acsResponse) { switch (rpc.acsResponse.name) { case "InformResponse": body = InformResponse(); break; case "GetRPCMethodsResponse": body = GetRPCMethodsResponse(rpc.acsResponse); break; case "TransferCompleteResponse": body = TransferCompleteResponse(); break; case "RequestDownloadResponse": body = RequestDownloadResponse(); break; default: throw new Error( `Unknown method response type ${ (rpc.acsResponse as AcsResponse).name }`, ); } } else if (rpc.acsRequest) { switch (rpc.acsRequest.name) { case "GetParameterNames": body = GetParameterNames(rpc.acsRequest); break; case "GetParameterValues": body = GetParameterValues(rpc.acsRequest); break; case "GetParameterAttributes": body = GetParameterAttributes(rpc.acsRequest); break; case "SetParameterValues": body = SetParameterValues(rpc.acsRequest); break; case "SetParameterAttributes": body = SetParameterAttributes(rpc.acsRequest); break; case "AddObject": body = AddObject(rpc.acsRequest); break; case "DeleteObject": body = DeleteObject(rpc.acsRequest); break; case "Reboot": body = Reboot(rpc.acsRequest); break; case "FactoryReset": body = FactoryReset(); break; case "Download": body = Download(rpc.acsRequest); break; default: throw new Error( `Unknown method request ${(rpc.acsRequest as AcsRequest).name}`, ); } } else if (rpc.acsFault) { body = AcsFault(rpc.acsFault); } headers["Content-Type"] = 'text/xml; charset="utf-8"'; return { code: 200, headers: headers, data: `\n${ rpc.id }${body}`, }; } ================================================ FILE: lib/types.ts ================================================ import { IncomingMessage, ServerResponse } from "node:http"; import { Script } from "node:vm"; import Path from "./common/path.ts"; import PathSet from "./common/path-set.ts"; import VersionedMap from "./versioned-map.ts"; import InstanceSet from "./instance-set.ts"; import Expression, { Value } from "./common/expression.ts"; export interface Fault { code: string; message: string; detail?: | FaultStruct | { name: string; message: string; stack?: string; }; timestamp?: number; } export interface SessionFault extends Fault { timestamp: number; provisions: string[][]; retryNow?: boolean; precondition?: boolean; retries?: number; expiry?: number; } export interface Attributes { object?: [number, 1 | 0]; writable?: [number, 1 | 0]; value?: [number, [string | number | boolean, string]]; notification?: [number, number]; accessList?: [number, string[]]; } export interface AttributeTimestamps { object?: number; writable?: number; value?: number; notification?: number; accessList?: number; } export interface AttributeValues { object?: boolean; writable?: boolean; value?: [string | number | boolean, string?]; notification?: number; accessList?: string[]; } export interface DeviceData { paths: PathSet; timestamps: VersionedMap; attributes: VersionedMap; trackers: Map; changes: Set; } export type VirtualParameterDeclaration = [ Path, { path?: number; object?: number; writable?: number; value?: number; notification?: number; accessList?: number; }?, { path?: [number, number]; object?: boolean; writable?: boolean; value?: [string | number | boolean, string?]; notification?: number; accessList?: string[]; }?, ]; export interface SyncState { refreshAttributes: { exist: Set; object: Set; writable: Set; value: Set; notification: Set; accessList: Set; }; spv: Map; spa: Map; gpn: Set; gpnPatterns: Map; tags: Map; virtualParameterDeclarations: VirtualParameterDeclaration[][]; instancesToDelete: Map>; instancesToCreate: Map; downloadsToDelete: Set; downloadsToCreate: InstanceSet; downloadsValues: Map; downloadsDownload: Map; reboot: number; factoryReset: number; } export interface SessionContext { sessionId?: string; timestamp: number; deviceId: string; deviceData: DeviceData; cwmpVersion: string; timeout: number; provisions: any[]; channels: { [channel: string]: number }; virtualParameters: [ string, AttributeTimestamps, AttributeValues, AttributeTimestamps, AttributeValues, ][][]; revisions: number[]; rpcCount: number; iteration: number; cycle: number; extensionsCache: any; declarations: Declaration[][]; faults?: { [channel: string]: SessionFault }; retries?: { [channel: string]: number }; cacheSnapshot?: string; httpResponse?: ServerResponse; httpRequest?: IncomingMessage; faultsTouched?: { [channel: string]: boolean }; presetCycles?: number; new?: boolean; debug?: boolean; state: number; authState: number; tasks?: Task[]; operations?: { [commandKey: string]: Operation }; syncState?: SyncState; lastActivity?: number; extendLock?: number; rpcRequest?: AcsRequest; operationsTouched?: { [commandKey: string]: 1 | 0 }; provisionsRet?: any[]; doneTasks?: string[]; } export interface Task { _id?: string; name: string; parameterNames?: string[]; parameterValues?: [string, string | number | boolean, string?][]; objectName?: string; fileType?: string; fileName?: string; targetFileName?: string; expiry?: number; provisions?: [string, ...Value[]][]; } export interface Operation { name: string; timestamp: number; provisions: string[][]; channels: { [channel: string]: number }; retries: { [channel: string]: number }; args: { instance: string; fileType: string; fileName: string; targetFileName: string; }; } export type AcsRequest = | GetParameterNames | GetParameterValues | GetParameterAttributes | SetParameterValues | SetParameterAttributes | AddObject | DeleteObject | FactoryReset | Reboot | Download; export interface GetParameterNames { name: "GetParameterNames"; parameterPath: string; nextLevel: boolean; } export interface GetParameterValues { name: "GetParameterValues"; parameterNames: string[]; } export interface GetParameterAttributes { name: "GetParameterAttributes"; parameterNames: string[]; } export interface SetParameterValues { name: "SetParameterValues"; parameterList: [string, boolean | number | string, string][]; parameterKey?: string; DATETIME_MILLISECONDS?: boolean; BOOLEAN_LITERAL?: boolean; } export interface SetParameterAttributes { name: "SetParameterAttributes"; parameterList: [string, number, string[]][]; } export interface AddObject { name: "AddObject"; objectName: string; parameterKey?: string; instanceValues: Record; } export interface DeleteObject { name: "DeleteObject"; objectName: string; parameterKey?: string; } export interface FactoryReset { name: "FactoryReset"; commandKey?: string; } export interface Reboot { name: "Reboot"; commandKey?: string; } export interface Download { name: "Download"; commandKey: string; instance: string; fileType: string; fileName?: string; url?: string; username?: string; password?: string; fileSize?: number; targetFileName?: string; delaySecods?: number; successUrl?: string; failureUrl?: string; } export interface SpvFault { parameterName: string; faultCode: string; faultString: string; } export interface FaultStruct { faultCode: string; faultString: string; setParameterValuesFault?: SpvFault[]; } export interface CpeFault { faultCode: "Client" | "Server"; faultString: "CWMP fault"; detail?: FaultStruct; } export type CpeResponse = | GetParameterNamesResponse | GetParameterValuesResponse | GetParameterAttributesResponse | SetParameterValuesResponse | SetParameterAttributesResponse | AddObjectResponse | DeleteObjectResponse | RebootResponse | FactoryResetResponse | DownloadResponse; export interface GetParameterNamesResponse { name: "GetParameterNamesResponse"; parameterList: [Path, boolean, boolean][]; } export interface GetParameterValuesResponse { name: "GetParameterValuesResponse"; parameterList: [Path, string | number | boolean, string][]; } export interface GetParameterAttributesResponse { name: "GetParameterAttributesResponse"; parameterList: [Path, number, string[]][]; } export interface SetParameterValuesResponse { name: "SetParameterValuesResponse"; status: number; } export interface SetParameterAttributesResponse { name: "SetParameterAttributesResponse"; } export interface AddObjectResponse { name: "AddObjectResponse"; instanceNumber: string; status: number; } export interface DeleteObjectResponse { name: "DeleteObjectResponse"; status: number; } export interface RebootResponse { name: "RebootResponse"; } export interface FactoryResetResponse { name: "FactoryResetResponse"; } export interface DownloadResponse { name: "DownloadResponse"; status: number; startTime?: number; completeTime?: number; } export type CpeRequest = | InformRequest | TransferCompleteRequest | GetRPCMethodsRequest | RequestDownloadRequest; export interface InformRequest { name: "Inform"; deviceId: { Manufacturer: string; OUI: string; ProductClass?: string; SerialNumber: string; }; event: string[]; retryCount: number; parameterList: [Path, string | number | boolean, string][]; } export interface TransferCompleteRequest { name: "TransferComplete"; commandKey?: string; faultStruct?: FaultStruct; startTime?: number; completeTime?: number; } export interface GetRPCMethodsRequest { name: "GetRPCMethods"; } export interface RequestDownloadRequest { name: "RequestDownload"; fileType: string; } export type AcsResponse = | InformResponse | GetRPCMethodsResponse | TransferCompleteResponse | RequestDownloadResponse; export interface InformResponse { name: "InformResponse"; } export interface GetRPCMethodsResponse { name: "GetRPCMethodsResponse"; methodList: string[]; } export interface TransferCompleteResponse { name: "TransferCompleteResponse"; } export interface RequestDownloadResponse { name: "RequestDownloadResponse"; } export interface QueryOptions { projection?: any; skip?: number; limit?: number; sort?: { [param: string]: number; }; } export interface Declaration { path: Path; pathGet: number; pathSet?: number | [number, number]; attrGet?: { object?: number; writable?: number; value?: number; notification?: number; accessList?: number; }; attrSet?: { object?: boolean; writable?: boolean; value?: [string | number | boolean, string?]; notification?: number; accessList?: string[]; }; defer: boolean; } export type Clear = [ Path, number, { object?: number; writable?: number; value?: number; notification?: number; accessList?: number; }?, number?, ]; export interface Preset { name: string; channel: string; schedule?: { md5: string; duration: number; schedule: any }; events?: { [event: string]: boolean }; precondition?: Expression; provisions: [string, ...Expression[]][]; } export interface Provisions { [name: string]: { md5: string; script: Script }; } export interface VirtualParameters { [name: string]: { md5: string; script: Script }; } export interface Views { [name: string]: { md5: string; script: string }; } export interface Files { [name: string]: { length: number }; } export interface Users { [name: string]: { password: string; salt: string; roles: string[] }; } export interface Permissions { [role: string]: { [access: number]: { [resource: string]: { access: number; filter: Expression; validate: Expression; }; }; }; } export type PermissionSet = { [resource: string]: { access: number; validate: Expression; filter: Expression; }; }[]; export interface Config { [name: string]: Expression; } export type UiConfig = Record; export interface SoapMessage { id: string; cwmpVersion: string; sessionTimeout: number; cpeRequest?: CpeRequest; cpeFault?: CpeFault; cpeResponse?: CpeResponse; unknownMethod?: string; } export interface ScriptResult { fault: Fault; clear: Clear[]; declare: Declaration[]; done: boolean; returnValue: any; } ================================================ FILE: lib/ui/api.ts ================================================ import { Readable } from "node:stream"; import Router from "@koa/router"; import { ObjectId } from "mongodb"; import * as db from "./db.ts"; import * as apiFunctions from "../api-functions.ts"; import Expression, { extractPaths } from "../common/expression.ts"; import Path from "../common/path.ts"; import * as logger from "../logger.ts"; import { getConfig } from "../ui/local-cache.ts"; import { Task } from "../types.ts"; import { generateSalt, hashPassword } from "../auth.ts"; import { del } from "../cache.ts"; import Authorizer from "../common/authorizer.ts"; import { ping } from "../ping.ts"; import { decodeTag } from "../util.ts"; import { stringify as yamlStringify } from "../common/yaml.ts"; import { ResourceLockedError } from "../common/errors.ts"; import { acquireLock, releaseLock } from "../lock.ts"; import { collections } from "../db/db.ts"; const router = new Router(); export default router; function logUnauthorizedWarning(log): void { log.message += " not authorized"; logger.accessWarn(log); } const RESOURCE_DELETE = 1 << 0; const RESOURCE_PUT = 1 << 1; const RESOURCE_IDS = { devices: "DeviceID.ID", presets: "_id", provisions: "_id", files: "_id", virtualParameters: "_id", config: "_id", permissions: "_id", users: "_id", faults: "_id", tasks: "_id", views: "_id", }; const resources = { devices: 0 | RESOURCE_DELETE, presets: 0 | RESOURCE_DELETE | RESOURCE_PUT, provisions: 0 | RESOURCE_DELETE | RESOURCE_PUT, files: 0 | RESOURCE_DELETE, virtualParameters: 0 | RESOURCE_DELETE | RESOURCE_PUT, config: 0 | RESOURCE_DELETE | RESOURCE_PUT, permissions: 0 | RESOURCE_DELETE | RESOURCE_PUT, users: 0 | RESOURCE_DELETE | RESOURCE_PUT, faults: 0 | RESOURCE_DELETE, tasks: 0, views: 0 | RESOURCE_DELETE | RESOURCE_PUT, }; function singleParam(p: string | string[]): string { return Array.isArray(p) ? p[p.length - 1] : p; } router.get(`/devices/:id.csv`, async (ctx) => { const authorizer: Authorizer = ctx.state.authorizer; const log = { message: "Query device (CSV)", context: ctx, id: ctx.params.id, }; const filter = Expression.and( authorizer.getFilter("devices", 2), new Expression.Binary( "=", new Expression.Parameter(Path.parse(RESOURCE_IDS.devices)), new Expression.Literal(ctx.params.id), ), ); if (!authorizer.hasAccess("devices", 2)) { logUnauthorizedWarning(log); return void (ctx.status = 403); } const { value: device } = await db.query("devices", filter).next(); if (!device) return void (ctx.status = 404); ctx.type = "text/csv"; ctx.attachment( `device-${ctx.params.id}-${new Date() .toISOString() .replace(/[:.]/g, "")}.csv`, ); const lines: string[] = [ "Parameter,Object,Writable,Value,Value type,Timestamp,Value timestamp,Notification,Access list,Attributes timestamp", ]; const keys = Object.keys(device).sort(); let prevParam = ""; let attrs: Record = {}; function flushRow(): void { if (!prevParam) return; let value: string | number | boolean | null = attrs["value"] ?? ""; if (attrs["type"] === "xsd:dateTime" && typeof value === "number") value = new Date(value).toJSON(); const row = [ prevParam, attrs["object"] ?? "", attrs["writable"] ?? "", `"${String(value).replace(/"/g, '""')}"`, attrs["type"] ?? "", attrs["timestamp"] != null ? new Date(+attrs["timestamp"]).toJSON() : "", attrs["valueTimestamp"] != null ? new Date(+attrs["valueTimestamp"]).toJSON() : "", attrs["notification"] ?? "", attrs["accessList"] ?? "", attrs["attributesTimestamp"] != null ? new Date(+attrs["attributesTimestamp"]).toJSON() : "", ]; lines.push(row.map((r) => (r != null ? r : "")).join(",")); } for (const k of keys) { const colonIdx = k.lastIndexOf(":"); const param = colonIdx === -1 ? k : k.slice(0, colonIdx); const attr = colonIdx === -1 ? "value" : k.slice(colonIdx + 1); if (param !== prevParam) { flushRow(); prevParam = param; attrs = {}; } attrs[attr] = device[k]; } flushRow(); ctx.body = lines.join("\n"); logger.accessInfo(log); }); for (const [resource, flags] of Object.entries(resources)) { router.head(`/${resource}`, async (ctx) => { const authorizer: Authorizer = ctx.state.authorizer; let filter: Expression = authorizer.getFilter(resource, 1); if (ctx.request.query.filter) filter = Expression.and( filter, Expression.parse(singleParam(ctx.request.query.filter)), ); const log = { message: `Count ${resource}`, context: ctx, filter: ctx.request.query.filter, count: null, }; if (!authorizer.hasAccess(resource, 1)) { logUnauthorizedWarning(log); return void (ctx.status = 403); } // Exclude temporary tasks and faults if (resource === "tasks" || resource === "faults") { const p = new Expression.Parameter(Path.parse("expiry")); filter = Expression.and( filter, Expression.or( new Expression.Binary( ">=", p, new Expression.Literal(Date.now() + 60000), ), new Expression.Unary("IS NULL", p), ), ); } const count = await db.count(resource, filter); ctx.set("X-Total-Count", `${count}`); ctx.body = ""; log.count = count; logger.accessInfo(log); }); router.get(`/${resource}`, async (ctx) => { const authorizer: Authorizer = ctx.state.authorizer; const options: Parameters[2] = {}; let filter: Expression = authorizer.getFilter(resource, 2); if (ctx.request.query.filter) filter = Expression.and( filter, Expression.parse(singleParam(ctx.request.query.filter)), ); if (ctx.request.query.limit) options.limit = +ctx.request.query.limit; if (ctx.request.query.skip) options.skip = +ctx.request.query.skip; if (ctx.request.query.sort) options.sort = JSON.parse(singleParam(ctx.request.query.sort)); if (ctx.request.query.projection) { options.projection = singleParam(ctx.request.query.projection) .split(",") .reduce((obj, k) => Object.assign(obj, { [k]: 1 }), {}); } const log = { message: `Query ${resource}`, context: ctx, filter: ctx.request.query.filter, limit: options.limit, skip: options.skip, sort: options.sort, projection: options.projection, }; if (!authorizer.hasAccess(resource, 2)) { logUnauthorizedWarning(log); return void (ctx.status = 403); } // Exclude temporary tasks and faults if (resource === "tasks" || resource === "faults") { const p = new Expression.Parameter(Path.parse("expiry")); filter = Expression.and( filter, Expression.or( new Expression.Binary( ">=", p, new Expression.Literal(Date.now() + 60000), ), new Expression.Unary("IS NULL", p), ), ); } logger.accessInfo(log); ctx.type = "application/json"; ctx.body = Readable.from( (async function* () { let c = 0; yield "[\n"; for await (const obj of db.query(resource, filter, options)) yield (c++ ? "," : "") + JSON.stringify(obj) + "\n"; yield "]"; })(), ); }); // CSV download router.get(`/${resource}.csv`, async (ctx) => { const authorizer: Authorizer = ctx.state.authorizer; const options: Parameters[2] = { projection: {} }; let filter: Expression = authorizer.getFilter(resource, 2); if (ctx.request.query.filter) filter = Expression.and( filter, Expression.parse(singleParam(ctx.request.query.filter)), ); if (ctx.request.query.limit) options.limit = +ctx.request.query.limit; if (ctx.request.query.skip) options.skip = +ctx.request.query.skip; if (ctx.request.query.sort) options.sort = JSON.parse(singleParam(ctx.request.query.sort)); const log = { message: `Query ${resource} (CSV)`, context: ctx, filter: ctx.request.query.filter, limit: options.limit, skip: options.skip, sort: options.sort, }; if (!authorizer.hasAccess(resource, 2)) { logUnauthorizedWarning(log); return void (ctx.status = 403); } const columnsStr: Record = JSON.parse( singleParam(ctx.request.query.columns), ); const now = Date.now(); const columns: Record = Object.fromEntries( Object.entries(columnsStr).map(([k, v]) => { let exp = Expression.parse(v); exp = exp.evaluate((e) => { if (e instanceof Expression.FunctionCall && e.name === "NOW") return new Expression.Literal(now); return e; }); for (const p of extractPaths(exp)) options.projection[p.toString()] = 1; return [k, exp]; }), ); // Exclude temporary tasks and faults if (resource === "tasks" || resource === "faults") { const p = new Expression.Parameter(Path.parse("expiry")); filter = Expression.and( filter, Expression.or( new Expression.Binary( ">=", p, new Expression.Literal(Date.now() + 60000), ), new Expression.Unary("IS NULL", p), ), ); } logger.accessInfo(log); ctx.type = "text/csv"; ctx.attachment( `${resource}-${new Date(now).toISOString().replace(/[:.]/g, "")}.csv`, ); ctx.body = Readable.from( (async function* () { yield Object.keys(columns).map((k) => `"${k.replace(/"/, '""')}"`) + "\n"; for await (const obj of db.query(resource, filter, options)) { const arr = Object.values(columns).map((exp) => { return exp.evaluate((e) => { if (e instanceof Expression.Literal) return e; else if (e instanceof Expression.FunctionCall) { if (e.name === "NOW") return new Expression.Literal(now); if (e.name === "DATE_STRING") { if (e.args[0] instanceof Expression.Literal) return new Expression.Literal( new Date(e.args[0].value as number).toJSON(), ); } } else if (e instanceof Expression.Parameter) { let v = obj[e.path.toString()]; if (resource === "devices") { if (e.path.toString() === "Tags") { const tags = []; for (const p in obj) if (p.startsWith("Tags.") && p.lastIndexOf(":") === -1) tags.push(decodeTag(p.slice(5))); v = tags.join(", "); } if (e === exp) { const type = obj[e.path.toString() + ":type"]; if (type === "xsd:dateTime" && typeof v === "number") v = new Date(v).toJSON(); } } else if (resource === "faults") { if (e.path.toString() === "detail") v = yamlStringify(v); } if (typeof v === "string") v = `"${v.replace(/"/g, '""')}"`; if (v != null) return new Expression.Literal(v); } return new Expression.Literal(null); }).value; }); yield arr.join(",") + "\n"; } })(), ); }); router.head(`/${resource}/:id`, async (ctx) => { const authorizer: Authorizer = ctx.state.authorizer; const log = { message: `Count ${resource}`, context: ctx, filter: `${RESOURCE_IDS[resource]} = "${ctx.params.id}"`, }; const filter = Expression.and( authorizer.getFilter(resource, 2), new Expression.Binary( "=", new Expression.Parameter(Path.parse(RESOURCE_IDS[resource])), new Expression.Literal(ctx.params.id), ), ); if (!authorizer.hasAccess(resource, 2)) { logUnauthorizedWarning(log); return void (ctx.status = 403); } const count = await db.count(resource, filter); if (!count) return void (ctx.status = 404); logger.accessInfo(log); ctx.body = ""; }); router.get(`/${resource}/:id`, async (ctx) => { const authorizer: Authorizer = ctx.state.authorizer; const log = { message: `Query ${resource}`, context: ctx, filter: `${RESOURCE_IDS[resource]} = "${ctx.params.id}"`, }; const filter = Expression.and( authorizer.getFilter(resource, 2), new Expression.Binary( "=", new Expression.Parameter(Path.parse(RESOURCE_IDS[resource])), new Expression.Literal(ctx.params.id), ), ); if (!authorizer.hasAccess(resource, 2)) { logUnauthorizedWarning(log); return void (ctx.status = 403); } const { value: res } = await db.query(resource, filter).next(); if (!res) return void (ctx.status = 404); logger.accessInfo(log); ctx.body = res; }); if (flags & RESOURCE_DELETE) { router.delete(`/${resource}/:id`, async (ctx) => { const authorizer: Authorizer = ctx.state.authorizer; const log = { message: `Delete ${resource}`, context: ctx, id: ctx.params.id, }; const filter = Expression.and( authorizer.getFilter(resource, 3), new Expression.Binary( "=", new Expression.Parameter(Path.parse(RESOURCE_IDS[resource])), new Expression.Literal(ctx.params.id), ), ); if (!authorizer.hasAccess(resource, 3)) { logUnauthorizedWarning(log); return void (ctx.status = 403); } const { value: res } = await db.query(resource, filter).next(); if (!res) return void (ctx.status = 404); const validate = authorizer.getValidator(resource, res); if (!validate("delete")) { logUnauthorizedWarning(log); return void (ctx.status = 403); } try { await apiFunctions.deleteResource(resource, ctx.params.id); } catch (err) { if (err instanceof ResourceLockedError) { log.message += " failed"; logger.accessWarn(log); ctx.status = 503; ctx.body = err.message; return; } throw err; } logger.accessInfo(log); ctx.body = ""; }); } if (flags & RESOURCE_PUT) { router.put(`/${resource}/:id`, async (ctx) => { const authorizer: Authorizer = ctx.state.authorizer; const id = ctx.params.id; const log = { message: `Put ${resource}`, context: ctx, id: id, }; if (!authorizer.hasAccess(resource, 3)) { logUnauthorizedWarning(log); return void (ctx.status = 403); } const obj = ctx.request.body; const validate = authorizer.getValidator(resource, obj); if (!validate("put")) { logUnauthorizedWarning(log); return void (ctx.status = 403); } try { await apiFunctions.putResource(resource, id, obj); } catch (err) { log.message += " failed"; logger.accessWarn(log); ctx.body = `${err.name}: ${err.message}`; return void (ctx.status = 400); } logger.accessInfo(log); ctx.body = ""; }); } } router.get("/blob/files/:id", async (ctx) => { const authorizer: Authorizer = ctx.state.authorizer; const resource = "files"; const id = ctx.params.id; const log = { message: `Download ${resource}`, context: ctx, id: id, }; const filter = Expression.and( authorizer.getFilter(resource, 2), new Expression.Binary( "=", new Expression.Parameter(Path.parse(RESOURCE_IDS[resource])), new Expression.Literal(ctx.params.id), ), ); if (!authorizer.hasAccess(resource, 2)) { logUnauthorizedWarning(log); return void (ctx.status = 403); } const count = await db.count(resource, filter); if (!count) return void (ctx.status = 404); logger.accessInfo(log); ctx.body = db.downloadFile(id); ctx.attachment(id); }); router.put("/files/:id", async (ctx) => { const authorizer: Authorizer = ctx.state.authorizer; const resource = "files"; const id = ctx.params.id; const log = { message: `Upload ${resource}`, context: ctx, id: id, metadata: null, }; if (!authorizer.hasAccess(resource, 3)) { logUnauthorizedWarning(log); return void (ctx.status = 403); } const metadata = { fileType: singleParam(ctx.request.headers["metadata-filetype"]) || "", oui: singleParam(ctx.request.headers["metadata-oui"]) || "", productClass: singleParam(ctx.request.headers["metadata-productclass"]) || "", version: singleParam(ctx.request.headers["metadata-version"]) || "", }; const validate = authorizer.getValidator(resource, metadata); if (!validate("put")) { logUnauthorizedWarning(log); return void (ctx.status = 403); } try { await db.deleteFile(id); } catch { // File doesn't exist, ignore } await db.putFile(id, metadata, ctx.req); log.metadata = metadata; logger.accessInfo(log); ctx.body = ""; }); router.post("/devices/:id/tasks", async (ctx) => { const deviceId = ctx.params.id; const authorizer: Authorizer = ctx.state.authorizer; const log = { message: "Commit tasks", context: ctx, deviceId: deviceId, tasks: null, }; if (!authorizer.hasAccess("devices", 3)) { logUnauthorizedWarning(log); return void (ctx.status = 403); } const socketTimeout: number = ctx.socket.timeout; // Extend socket timeout while waiting for session if (socketTimeout) ctx.socket.setTimeout(300000); const token = await acquireLock(`cwmp_session_${deviceId}`, 5000, 30000); if (!token) { log.message += " failed"; logger.accessWarn(log); ctx.body = "Device is in session"; ctx.status = 503; // Restore socket timeout if (socketTimeout) ctx.socket.setTimeout(socketTimeout); return; } let device; let statuses: { _id: string; status: string }[]; try { const filter = Expression.and( authorizer.getFilter("devices", 3), new Expression.Binary( "=", new Expression.Parameter(Path.parse(RESOURCE_IDS["devices"])), new Expression.Literal(ctx.params.id), ), ); device = (await db.query("devices", filter).next()).value; if (!device) return void (ctx.status = 404); const validate = authorizer.getValidator("devices", device); for (const t of ctx.request.body) { if (!validate("task", t)) { logUnauthorizedWarning(log); return void (ctx.status = 403); } } let tasks = ctx.request.body as Task[]; for (const task of tasks) { delete task._id; task["device"] = deviceId; } tasks = await apiFunctions.insertTasks(tasks); statuses = tasks.map((t) => ({ _id: t._id, status: "pending" })); } finally { await releaseLock(`cwmp_session_${deviceId}`, token); } const now = Date.now(); const onlineThreshold = getConfig( ctx.state.configSnapshot, "cwmp.deviceOnlineThreshold", 4000, (exp) => { if (exp instanceof Expression.Literal) return exp; else if (exp instanceof Expression.Parameter) { const p = device[exp.path.toString()]; if (p != null) return new Expression.Literal(p); } else if (exp instanceof Expression.FunctionCall) { if (exp.name === "NOW") return new Expression.Literal(now); if (exp.name === "REMOTE_ADDRESS") { for (const root of ["InternetGatewayDevice", "Device"]) { const p = device[`${root}.ManagementServer.ConnectionRequestURL`]; if (p != null) return new Expression.Literal(new URL(p).hostname); } } } return new Expression.Literal(null); }, ); const lastInform = device["Events.Inform"] as number; let status = await apiFunctions.connectionRequest(deviceId, device); if (!status) { const sessionStarted = await apiFunctions.awaitSessionStart( deviceId, lastInform, onlineThreshold, ); if (!sessionStarted) { status = "No contact from CPE"; } else { const sessionEnded = await apiFunctions.awaitSessionEnd(deviceId, 120000); if (!sessionEnded) status = "Session took too long to complete"; } } if (!status) { const promises = statuses.map((t) => collections.faults.count({ _id: `${deviceId}:task_${t._id}` }), ); const res = await Promise.all(promises); for (const [i, r] of statuses.entries()) r.status = res[i] ? "fault" : "done"; } await Promise.all(statuses.map((t) => db.deleteTask(new ObjectId(t._id)))); // Restore socket timeout if (socketTimeout) ctx.socket.setTimeout(socketTimeout); log.tasks = statuses.map((t) => t._id).join(","); logger.accessInfo(log); ctx.set("Connection-Request", status || "OK"); ctx.body = statuses; }); router.post("/devices/:id/tags", async (ctx) => { const authorizer: Authorizer = ctx.state.authorizer; const log = { message: "Update tags", context: ctx, deviceId: ctx.params.id, tags: ctx.request.body, }; const filter = Expression.and( authorizer.getFilter("devices", 3), new Expression.Binary( "=", new Expression.Parameter(Path.parse(RESOURCE_IDS["devices"])), new Expression.Literal(ctx.params.id), ), ); if (!authorizer.hasAccess("devices", 3)) { logUnauthorizedWarning(log); return void (ctx.status = 403); } const { value: res } = await db.query("devices", filter).next(); if (!res) return void (ctx.status = 404); const validate = authorizer.getValidator("devices", res); if (!validate("tags", ctx.request.body)) { logUnauthorizedWarning(log); return void (ctx.status = 403); } try { await db.updateDeviceTags(ctx.params.id, ctx.request.body); } catch (error) { log.message += " failed"; logger.accessWarn(log); ctx.body = error.message; return void (ctx.status = 400); } logger.accessInfo(log); ctx.body = ""; }); router.get("/ping/:host", async (ctx) => { if (!ctx.state.user) return void (ctx.status = 401); return new Promise((resolve) => { ping(ctx.params.host, (err, parsed) => { if (parsed) { ctx.body = parsed; } else { ctx.status = 500; ctx.body = err ? `${err.name}: ${err.message}` : "Unknown error"; } resolve(); }); }); }); router.put("/users/:id/password", async (ctx) => { const authorizer: Authorizer = ctx.state.authorizer; const username = ctx.params.id; const log = { message: "Change password", context: ctx, username: username, }; if (!ctx.state.user) { // User not logged in if ( !(await apiFunctions.authLocal( ctx.state.configSnapshot, username, ctx.request.body.authPassword, )) ) { logUnauthorizedWarning(log); ctx.status = 401; ctx.body = "Authentication failed, check your username and password"; return; } } else if (!authorizer.hasAccess("users", 3)) { logUnauthorizedWarning(log); return void (ctx.status = 403); } const newPassword = ctx.request.body.newPassword; if (ctx.state.user) { const filter = Expression.and( authorizer.getFilter("users", 3), new Expression.Binary( "=", new Expression.Parameter(Path.parse(RESOURCE_IDS["users"])), new Expression.Literal(username), ), ); const { value: res } = await db.query("users", filter).next(); if (!res) return void (ctx.status = 404); const validate = authorizer.getValidator("users", res); if (!validate("password", { password: newPassword })) { logUnauthorizedWarning(log); return void (ctx.status = 403); } } const salt = await generateSalt(64); const password = await hashPassword(newPassword, salt); await db.putUser(username, { password, salt }); await del("ui-local-cache-hash"); logger.accessInfo(log); ctx.body = ""; }); ================================================ FILE: lib/ui/db.ts ================================================ import { Script } from "node:vm"; import { Readable } from "node:stream"; import { Collection, ObjectId, WithoutId } from "mongodb"; import { encodeTag } from "../util.ts"; import { Fault, Task } from "../types.ts"; import { collections, filesBucket } from "../db/db.ts"; import { validateViewScript } from "../bundle-views.ts"; import { convertOldPrecondition, optimizeProjection } from "../db/util.ts"; import * as MongoTypes from "../db/types.ts"; import Expression, { parseList, Value } from "../common/expression.ts"; import { toMongoQuery } from "../db/synth.ts"; function processDeviceProjection( projection: Record, ): Record { if (!projection) return projection; const p = {}; for (const [k, v] of Object.entries(projection)) { if (k === "DeviceID.ID") { p["_id"] = 1; } else if (k.startsWith("DeviceID")) { p["_deviceId._SerialNumber"] = v; p["_deviceId._OUI"] = v; p["_deviceId._ProductClass"] = v; p["_deviceId._Manufacturer"] = v; } else if (k.startsWith("Tags")) { p["_tags"] = v; } else if (k.startsWith("Events")) { p["_lastInform"] = v; p["_registered"] = v; p["_lastBoot"] = v; p["_lastBootstrap"] = v; } else { p[k] = v; } } return p; } function processDeviceSort( sort: Record, ): Record { if (!sort) return sort; const s = {}; for (const [k, v] of Object.entries(sort)) { if (k === "DeviceID.ID") s["_id"] = v; else if (k.startsWith("DeviceID.")) s[`_deviceId._${k.slice(9)}`] = v; else if (k === "Events.Inform") s["_lastInform"] = v; else if (k === "Events.Registered") s["_registered"] = v; else if (k === "Events.1_BOOT") s["_lastBoot"] = v; else if (k === "Events.0_BOOTSTRAP") s["_lastBootstrap"] = v; else s[`${k}._value`] = v; } return s; } function parseDate(d: Date): number | string { const n = +d; return isNaN(n) ? "" + d : n; } export interface FlatDevice { [param: string]: Value; } export function flattenDevice(device: Record): FlatDevice { function recursive( input, root: string, output: FlatDevice, timestamp: number, ): void { for (const [name, tree] of Object.entries(input)) { if (!root) { if (name === "_lastInform") { output["Events.Inform"] = parseDate(tree as Date); output["Events.Inform:type"] = "xsd:dateTime"; } else if (name === "_registered") { output["Events.Registered"] = parseDate(tree as Date); output["Events.Registered:type"] = "xsd:dateTime"; } else if (name === "_lastBoot") { output["Events.1_BOOT"] = parseDate(tree as Date); output["Events.1_BOOT:type"] = "xsd:dateTime"; } else if (name === "_lastBootstrap") { output["Events.0_BOOTSTRAP"] = parseDate(tree as Date); output["Events.0_BOOTSTRAP:type"] = "xsd:dateTime"; } else if (name === "_id") { output["DeviceID.ID"] = tree as string; output["DeviceID.ID:type"] = "xsd:dateTime"; } else if (name === "_deviceId") { output["DeviceID.Manufacturer"] = tree["_Manufacturer"]; output["DeviceID.Manufacturer:type"] = "xsd:string"; output["DeviceID.OUI"] = tree["_OUI"]; output["DeviceID.OUI:type"] = "xsd:string"; output["DeviceID.ProductClass"] = tree["_ProductClass"]; output["DeviceID.ProductClass:type"] = "xsd:string"; output["DeviceID.SerialNumber"] = tree["_SerialNumber"]; output["DeviceID.SerialNumber:type"] = "xsd:string"; } else if (name === "_tags") { output["Tags:object"] = true; output["Tags:writable"] = true; for (const t of tree as string[]) { const et = encodeTag(t); output[`Tags.${et}`] = true; output[`Tags.${et}:type`] = "xsd:boolean"; output[`Tags.${et}:writable`] = true; } } } if (name.startsWith("_")) continue; let childrenTimestamp = timestamp; if (!root) childrenTimestamp = +(input["_timestamp"] || 1); else if (+input["_timestamp"] > timestamp) childrenTimestamp = +input["_timestamp"]; const r = root ? `${root}.${name}` : name; if (tree["_value"] != null) { output[r] = tree["_value"] instanceof Date ? +tree["_value"] : tree["_value"]; output[`${r}:type`] = tree["_type"]; output[`${r}:timestamp`] = childrenTimestamp; output[`${r}:valueTimestamp`] = +( tree["_timestamp"] || childrenTimestamp ); } else if (tree["_object"] != null) { output[`${r}:object`] = tree["_object"]; output[`${r}:timestamp`] = childrenTimestamp; } if (tree["_writable"] != null) { output[`${r}:writable`] = tree["_writable"]; output[`${r}:timestamp`] = childrenTimestamp; } if (tree["_notification"] != null) { output[`${r}:notification`] = tree["_notification"]; output[`${r}:attributesTimestamp`] = +tree["_attributesTimestamp"] || 1; } if (tree["_accessList"] != null) { output[`${r}:accessList`] = tree["_accessList"].join(","); output[`${r}:attributesTimestamp`] = +tree["_attributesTimestamp"] || 1; } recursive(tree, r, output, childrenTimestamp); } } const newDevice: FlatDevice = {}; const timestamp = new Date((device["_lastInform"] as Date) || 1).getTime(); recursive(device, "", newDevice, timestamp); return newDevice; } function flattenFault(fault: unknown): Fault { const f = Object.assign({}, fault) as Fault; if (f.timestamp) f.timestamp = +f.timestamp; if (f["expiry"]) f["expiry"] = +f["expiry"]; return f as Fault; } function flattenTask(task: unknown): Task { const t = Object.assign({}, task) as Task; t._id = "" + t._id; if (t["timestamp"]) t["timestamp"] = +t["timestamp"]; if (t.expiry) t.expiry = +t.expiry; return t; } function flattenPreset( preset: Record, ): Record { const p = Object.assign({}, preset); if (p.precondition) { try { // Try parse to check expression validity Expression.parse(p.precondition as string); } catch { const e = convertOldPrecondition(JSON.parse(p.precondition as string)); if (e instanceof Expression.Literal && e.value) p.precondition = e.toString(); else p.precondition = ""; } } if (p.events) { const e = []; for (const [k, v] of Object.entries(p.events)) e.push(v ? k : `-${k}`); p.events = e.join(", "); } const provision = p.configurations[0]; if ( (p.configurations as any[]).length === 1 && provision.type === "provision" && provision.name && provision.name.length ) { p.provision = provision.name; p.provisionArgs = provision.args ? provision.args.map((a) => a.toString()).join(", ") : ""; } delete p.configurations; return p; } function flattenFile(file: Record): Record { const f = {}; f["_id"] = file["_id"]; if (file.metadata) { f["metadata.fileType"] = file["metadata"]["fileType"] || ""; f["metadata.oui"] = file["metadata"]["oui"] || ""; f["metadata.productClass"] = file["metadata"]["productClass"] || ""; f["metadata.version"] = file["metadata"]["version"] || ""; } return f; } function preProcessPreset(data: Record): MongoTypes.Preset { const preset = Object.assign({}, data); if (!preset.precondition) preset.precondition = ""; else Expression.parse(preset.precondition as string); // Try parse to check validity preset.weight = parseInt(preset.weight as string) || 0; const events = {}; if (preset.events) { for (let e of (preset.events as string).split(",")) { let v = true; e = e.trim(); if (e.startsWith("-")) { v = false; e = e.slice(1).trim(); } if (e) events[e] = v; } } preset.events = events; if (!preset.provision) throw new Error("Invalid preset provision"); const configuration = { type: "provision", name: preset.provision, args: null, }; if (preset.provisionArgs) configuration.args = parseList(preset.provisionArgs as string); delete preset.provision; delete preset.provisionArgs; preset.configurations = [configuration]; return preset as unknown as MongoTypes.Preset; } interface QueryOptions { projection?: any; skip?: number; limit?: number; sort?: { [param: string]: number; }; } export async function* query( resource: string, filter: Expression, options?: QueryOptions, ): AsyncGenerator { options = options || {}; const now = Date.now(); filter = filter.evaluate((e) => { if (e instanceof Expression.FunctionCall) { if (e.name === "NOW") return new Expression.Literal(now); } return e; }); const q = toMongoQuery(filter, resource); if (!q) return; const collection = collections[resource] as Collection; const cursor = collection.find(q); if (options.projection) { let projection = options.projection; if (resource === "devices") projection = processDeviceProjection(options.projection); if (resource === "presets") projection.configurations = 1; projection = optimizeProjection(projection); cursor.project(projection); } if (resource === "users") cursor.project({ password: 0, salt: 0 }); if (options.skip) cursor.skip(options.skip); if (options.limit) cursor.limit(options.limit); if (options.sort) { let s = Object.entries(options.sort) .sort((a, b) => Math.abs(b[1]) - Math.abs(a[1])) .reduce( (obj, [k, v]) => Object.assign(obj, { [k]: Math.min(Math.max(v, -1), 1) }), {}, ); if (resource === "devices") s = processDeviceSort(s); cursor.sort(s); } for await (let doc of cursor) { if (resource === "devices") doc = flattenDevice(doc); else if (resource === "faults") doc = flattenFault(doc); else if (resource === "tasks") doc = flattenTask(doc); else if (resource === "presets") doc = flattenPreset(doc); else if (resource === "files") doc = flattenFile(doc); yield doc; } } export function count(resource: string, filter: Expression): Promise { const collection = collections[resource] as Collection; const now = Date.now(); filter = filter.evaluate((e) => { if (e instanceof Expression.FunctionCall) { if (e.name === "NOW") return new Expression.Literal(now); } return e; }); const q = toMongoQuery(filter, resource); if (!q) return Promise.resolve(0); return collection.countDocuments(q); } export async function updateDeviceTags( deviceId: string, tags: Record, ): Promise { const add = []; const pull = []; for (let [tag, onOff] of Object.entries(tags)) { tag = tag.trim(); if (onOff) add.push(tag); else pull.push(tag); } const object = {}; if (add?.length) object["$addToSet"] = { _tags: { $each: add } }; if (pull?.length) object["$pullAll"] = { _tags: pull }; await collections.devices.updateOne({ _id: deviceId }, object); } export async function putPreset( id: string, object: Record, ): Promise { const p = preProcessPreset(object); await collections.presets.replaceOne({ _id: id }, p, { upsert: true }); } export async function deletePreset(id: string): Promise { await collections.presets.deleteOne({ _id: id }); } export async function putProvision( id: string, object: { script: string }, ): Promise { if (!object.script) object.script = ""; try { new Script(`"use strict";(function(){\n${object.script}\n})();`, { filename: id, lineOffset: -1, }); } catch (err) { if (err.stack?.startsWith(`${id}:`)) { return Promise.reject( new Error(`${err.name} at ${err.stack.split("\n", 1)[0]}`), ); } return Promise.reject(err); } await collections.provisions.replaceOne({ _id: id }, object, { upsert: true, }); } export async function deleteProvision(id: string): Promise { await collections.provisions.deleteOne({ _id: id }); } export async function putVirtualParameter( id: string, object: { script: string }, ): Promise { if (!object.script) object.script = ""; try { new Script(`"use strict";(function(){\n${object.script}\n})();`, { filename: id, lineOffset: -1, }); } catch (err) { if (err.stack?.startsWith(`${id}:`)) { return Promise.reject( new Error(`${err.name} at ${err.stack.split("\n", 1)[0]}`), ); } return Promise.reject(err); } await collections.virtualParameters.replaceOne({ _id: id }, object, { upsert: true, }); } export async function deleteVirtualParameter(id: string): Promise { await collections.virtualParameters.deleteOne({ _id: id }); } export async function putConfig( id: string, object: WithoutId, ): Promise { await collections.config.replaceOne({ _id: id }, object, { upsert: true }); } export async function deleteConfig(id: string): Promise { await collections.config.deleteOne({ _id: id }); } export async function putPermission( id: string, object: WithoutId, ): Promise { await collections.permissions.replaceOne({ _id: id }, object, { upsert: true, }); } export async function deletePermission(id: string): Promise { await collections.permissions.deleteOne({ _id: id }); } export async function putUser( id: string, object: Partial>, ): Promise { // update instead of replace to keep the password if not set by user await collections.users.updateOne( { _id: id }, { $set: object }, { upsert: true }, ); } export async function deleteUser(id: string): Promise { await collections.users.deleteOne({ _id: id }); } export function downloadFile(filename: string): Readable { return filesBucket.openDownloadStreamByName(filename); } export function putFile( filename: string, metadata: Record, contentStream: Readable, ): Promise { return new Promise((resolve, reject) => { const uploadStream = filesBucket.openUploadStreamWithId( filename as unknown as ObjectId, filename, { metadata: metadata, }, ); let readableEnded = false; contentStream.on("end", () => { readableEnded = true; }); contentStream.on("close", () => { // In Node versions prior to 15, the stream will not emit an error if the // connection is closed before the stream is finished. // For Node 12.9+ we can just use stream.readableEnded if (!readableEnded) uploadStream.destroy(new Error("Stream closed prematurely")); }); contentStream.on("error", (err) => { uploadStream.destroy(err); }); uploadStream.on("error", reject); uploadStream.on("finish", resolve); contentStream.pipe(uploadStream); }); } export async function deleteFile(filename: string): Promise { await filesBucket.delete(filename as any); } export async function deleteFault(id: string): Promise { await collections.faults.deleteOne({ _id: id }); } export async function deleteTask(id: ObjectId): Promise { await collections.tasks.deleteOne({ _id: id }); } export async function putView( id: string, object: { script: string }, ): Promise { if (!object.script) object.script = ""; const err = await validateViewScript(id, object.script); if (err) throw new Error(err); await collections.views.replaceOne({ _id: id }, object, { upsert: true, }); } export async function deleteView(id: string): Promise { await collections.views.deleteOne({ _id: id }); } ================================================ FILE: lib/ui/local-cache.ts ================================================ import * as crypto from "node:crypto"; import { collections } from "../db/db.ts"; import Expression, { Value } from "../common/expression.ts"; import { Users, Permissions, Config, UiConfig, Views } from "../types.ts"; import { LocalCache } from "../local-cache.ts"; import { bundleViews } from "../bundle-views.ts"; interface Snapshot { permissions: Permissions; users: Users; config: Config; ui: UiConfig; viewsBundle: string; } async function fetchPermissions(): Promise<[string, Permissions]> { const perms = await collections.permissions.find().toArray(); perms.sort((a, b) => (a._id > b._id ? 1 : -1)); const h = crypto .createHash("md5") .update(JSON.stringify(perms)) .digest("hex"); const permissions: Permissions = {}; for (const p of perms) { if (!permissions[p.role]) permissions[p.role] = {}; if (!permissions[p.role][p.access]) permissions[p.role][p.access] = {}; let validate: Expression; if (p.validate) validate = Expression.parse(p.validate); else validate = new Expression.Literal(true); permissions[p.role][p.access][p.resource] = { access: p.access, filter: Expression.parse(p.filter || "true"), validate, }; } return [h, permissions]; } async function fetchUsers(): Promise<[string, Users]> { const _users = await collections.users.find().toArray(); _users.sort((a, b) => (a._id > b._id ? 1 : -1)); const h = crypto .createHash("md5") .update(JSON.stringify(_users)) .digest("hex"); const users = {}; for (const user of _users) { users[user._id] = { password: user.password, salt: user.salt, roles: user.roles.split(",").map((s) => s.trim()), }; } return [h, users]; } async function fetchConfig(): Promise<[string, Config, UiConfig]> { const conf = await collections.config.find().toArray(); conf.sort((a, b) => (a._id > b._id ? 1 : -1)); const h = crypto.createHash("md5").update(JSON.stringify(conf)).digest("hex"); const ui: UiConfig = {}; const _config = {}; for (const c of conf) { if (c._id.startsWith("ui.")) { ui[c._id.slice(3)] = c.value; continue; } // Evaluate expressions to simplify them const val = Expression.parse(c.value).evaluate((e) => e); _config[c._id] = val; } return [h, _config, ui]; } async function fetchViews(): Promise<[string, Views]> { const res = await collections.views.find().toArray(); const h = crypto.createHash("md5").update(JSON.stringify(res)).digest("hex"); const views: Views = {}; for (const r of res) { views[r["_id"]] = { md5: crypto.createHash("md5").update(r["script"]).digest("hex"), script: r.script, }; } return [h, views]; } const localCache = new LocalCache("ui-local-cache-hash", refresh); async function refresh(): Promise<[string, Snapshot]> { const res = await Promise.all([ fetchPermissions(), fetchUsers(), fetchConfig(), fetchViews(), ]); const h = crypto.createHash("md5"); for (const r of res) h.update(r[0]); const snapshot = { permissions: res[0][1], users: res[1][1], config: res[2][1], ui: res[2][2], viewsBundle: await bundleViews(res[3][1]), }; return [h.digest("hex"), snapshot]; } export async function getRevision(): Promise { return await localCache.getRevision(); } export function getConfig( revision: string, key: string, dflt: string, fn: (e: Expression) => Expression.Literal, ): string; export function getConfig( revision: string, key: string, dflt: number, fn: (e: Expression) => Expression.Literal, ): number; export function getConfig( revision: string, key: string, dflt: boolean, fn: (e: Expression) => Expression.Literal, ): boolean; export function getConfig( revision: string, key: string, dflt: Value, fn: (e: Expression) => Expression.Literal, ): Value { const snapshot = localCache.get(revision); if (!snapshot) throw new Error("Cache snapshot does not exist"); const e = snapshot.config[key]; if (!e) return dflt; const v = e.evaluate(fn).value; if (typeof v !== typeof dflt) return dflt; return v; } export function getConfigExpression(revision: string, key: string): Expression { const snapshot = localCache.get(revision); return snapshot.config[key]; } export function getUsers(revision: string): Users { const snapshot = localCache.get(revision); return snapshot.users; } export function getPermissions(revision: string): Permissions { const snapshot = localCache.get(revision); return snapshot.permissions; } export function getUiConfig(revision: string): UiConfig { const snapshot = localCache.get(revision); return snapshot.ui; } export function getViewsBundle(revision: string): string { const snapshot = localCache.get(revision); return snapshot.viewsBundle; } ================================================ FILE: lib/ui.ts ================================================ import { constants } from "node:zlib"; import Koa from "koa"; import Router from "@koa/router"; import * as jwt from "jsonwebtoken"; import koaSend from "koa-send"; import koaCompress from "koa-compress"; import koaBodyParser from "@koa/bodyparser"; import koaJwt from "koa-jwt"; import * as config from "./config.ts"; import api from "./ui/api.ts"; import Authorizer from "./common/authorizer.ts"; import * as logger from "./logger.ts"; import * as localCache from "./ui/local-cache.ts"; import { PermissionSet } from "./types.ts"; import { authLocal } from "./api-functions.ts"; import * as init from "./init.ts"; import { version as VERSION } from "../package.json"; import memoize from "./common/memoize.ts"; import { APP_JS, APP_CSS, FAVICON_PNG } from "../build/assets.ts"; const koa = new Koa(); const router = new Router(); const JWT_SECRET = "" + config.get("UI_JWT_SECRET"); const JWT_COOKIE = "genieacs-ui-jwt"; const getAuthorizer = memoize( (snapshot: string, rolesStr: string): Authorizer => { const roles: string[] = JSON.parse(rolesStr); const allPermissions = localCache.getPermissions(snapshot); const permissionSets: PermissionSet[] = roles.map((r) => Object.values(allPermissions[r] || {}), ); return new Authorizer(permissionSets); }, ); koa.on("error", (err, ctx) => { setTimeout(() => { // Ignored errors resulting from aborted requests if (ctx?.req.aborted) return; // Ignore client errors (e.g. malicious path) if (err.status === 400) return; throw err; }); }); koa.use(async (ctx, next) => { const configSnapshot = await localCache.getRevision(); ctx.state.configSnapshot = configSnapshot; ctx.set("X-Config-Snapshot", configSnapshot); ctx.set("GenieACS-Version", VERSION); return next(); }); koa.use( koaJwt({ secret: JWT_SECRET, passthrough: true, cookie: JWT_COOKIE, isRevoked: async (ctx, token) => { if (token["authMethod"] === "local") { return !localCache.getUsers(ctx.state.configSnapshot)[ token["username"] ]; } return true; }, }), ); koa.use(async (ctx, next) => { let roles: string[] = []; if (ctx.state.user?.username) { let user; if (ctx.state.user.authMethod === "local") { user = localCache.getUsers(ctx.state.configSnapshot)[ ctx.state.user.username ]; } else { throw new Error("Invalid auth method"); } roles = user.roles || []; } ctx.state.authorizer = getAuthorizer( ctx.state.configSnapshot, JSON.stringify(roles), ); return next(); }); router.post("/login", async (ctx) => { if (!JWT_SECRET) { ctx.status = 500; ctx.body = "UI_JWT_SECRET is not set"; logger.error({ message: "UI_JWT_SECRET is not set" }); return; } const username = ctx.request.body.username; const password = ctx.request.body.password; const remember = ctx.request.body.remember; const TWO_WEEKS_SECS = 1209600; const ONE_DAY_SECS = 86400; const log = { message: "Log in", context: ctx, username: username, method: null, }; function success(authMethod): void { log.method = authMethod; const expiresIn = remember ? TWO_WEEKS_SECS : ONE_DAY_SECS; const token = jwt.sign({ username, authMethod }, JWT_SECRET, { expiresIn, }); ctx.cookies.set(JWT_COOKIE, token, { sameSite: "lax", maxAge: remember ? expiresIn * 1000 : null, }); ctx.body = JSON.stringify(token); logger.accessInfo(log); } function failure(): void { ctx.status = 400; ctx.body = "Incorrect username or password"; log.message += " failed"; logger.accessWarn(log); } if (await authLocal(ctx.state.configSnapshot, username, password)) return void success("local"); failure(); }); router.post("/logout", async (ctx) => { ctx.cookies.set(JWT_COOKIE); // Delete cookie ctx.body = ""; logger.accessInfo({ message: "Log out", context: ctx, }); }); koa.use(async (ctx, next) => { if (ctx.request.type === "application/octet-stream") ctx.disableBodyParser = true; return next(); }); koa.use(koaBodyParser()); router.use("/api", api.routes(), api.allowedMethods()); router.get("/health", (ctx) => { ctx.body = { status: "OK", timestamp: Date.now(), configSnapshot: ctx.state.configSnapshot, version: VERSION, }; }); router.get("/init", async (ctx) => { const status = await init.getStatus(); if (Object.keys(localCache.getUsers(ctx.state.configSnapshot)).length) { if (!ctx.state.authorizer.hasAccess("users", 3)) status["users"] = false; if (!ctx.state.authorizer.hasAccess("permissions", 3)) status["users"] = false; if (!ctx.state.authorizer.hasAccess("config", 3)) { status["filters"] = false; status["device"] = false; status["index"] = false; status["overview"] = false; } if (!ctx.state.authorizer.hasAccess("presets", 3)) status["presets"] = false; if (!ctx.state.authorizer.hasAccess("provisions", 3)) status["presets"] = false; } ctx.body = status; }); router.post("/init", async (ctx) => { const status = ctx.request.body; if (Object.keys(localCache.getUsers(ctx.state.configSnapshot)).length) { if (!ctx.state.authorizer.hasAccess("users", 3)) status["users"] = false; if (!ctx.state.authorizer.hasAccess("permissions", 3)) status["users"] = false; if (!ctx.state.authorizer.hasAccess("config", 3)) { status["filters"] = false; status["device"] = false; status["index"] = false; status["overview"] = false; } if (!ctx.state.authorizer.hasAccess("presets", 3)) status["presets"] = false; if (!ctx.state.authorizer.hasAccess("provisions", 3)) status["presets"] = false; } await init.seed(status); ctx.body = ""; }); router.get("/", async (ctx) => { // koa-router seems to tolerate double slashes in the URL but that can // be problematic when using relatives asset paths in HTML if (ctx.path.endsWith("//")) return; const ps: PermissionSet[] = ctx.state.authorizer.getPermissionSets(); const permissionSets = ps.map((p) => p.map((s) => Object.fromEntries( Object.entries(s).map(([resource, { access, validate, filter }]) => [ resource, { access, validate: validate.toString(), filter: filter.toString() }, ]), ), ), ); let wizard = ""; if (!Object.keys(localCache.getUsers(ctx.state.configSnapshot)).length) wizard = ''; let viewsUrl: string; if (ctx.state.user) viewsUrl = `./views-bundle-${ctx.state.configSnapshot}.js`; else viewsUrl = "data:application/javascript,export default {}"; ctx.body = ` GenieACS ${wizard} `; }); router.get("/views-bundle-:revision.js", async (ctx) => { if (!ctx.state.user) return void (ctx.status = 403); try { ctx.body = localCache.getViewsBundle(ctx.params.revision); ctx.set({ "Content-Type": "application/javascript" }); } catch { ctx.status = 404; } }); koa.use( koaCompress({ gzip: { flush: constants.Z_SYNC_FLUSH, }, deflate: { flush: constants.Z_SYNC_FLUSH, }, br: { flush: constants.BROTLI_OPERATION_FLUSH, params: { [constants.BROTLI_PARAM_QUALITY]: 5, }, }, }), ); koa.use(router.routes()); koa.use(async (ctx, next) => { await next(); if (ctx.method !== "HEAD" && ctx.method !== "GET") return; if (ctx.body != null || ctx.status !== 404) return; if (/(?:^|[\\/])\.\.(?:[\\/]|$)/.test(ctx.path)) return; try { await koaSend(ctx, ctx.path, { root: config.ROOT_DIR + "/public" }); } catch (err) { if (err.status !== 404) throw err; } }); export const listener = koa.callback(); ================================================ FILE: lib/util.ts ================================================ import { EventEmitter } from "node:events"; export function generateDeviceId( deviceIdStruct: Record, ): string { // Escapes everything except alphanumerics and underscore function esc(str): string { return str.replace(/[^A-Za-z0-9_]/g, (chr) => { const buf = Buffer.from(chr, "utf8"); let rep = ""; for (const b of buf) rep += "%" + b.toString(16).toUpperCase(); return rep; }); } // Guaranteeing globally unique id as defined in TR-069 if (deviceIdStruct["ProductClass"]) { return ( esc(deviceIdStruct["OUI"]) + "-" + esc(deviceIdStruct["ProductClass"]) + "-" + esc(deviceIdStruct["SerialNumber"]) ); } return esc(deviceIdStruct["OUI"]) + "-" + esc(deviceIdStruct["SerialNumber"]); } // Source: http://stackoverflow.com/a/6969486 export function escapeRegExp(str: string): string { return str.replace(/[-[\]/{}()*+?.\\^$|]/g, "\\$&"); } export function encodeTag(tag: string): string { return encodeURIComponent(tag) .replace( /[!~*'().]/g, (c) => "%" + c.charCodeAt(0).toString(16).toUpperCase(), ) .replace(/0x(?=[0-9A-Z]{2})/g, "0%78") .replace(/%/g, "0x"); } export function decodeTag(tag: string): string { return decodeURIComponent(tag.replace(/0x(?=[0-9A-Z]{2})/g, "%")); } export function once( emitter: EventEmitter, event: string, timeout: number, ): Promise { return new Promise((resolve, reject) => { const timer = setTimeout(() => { reject(new Error(`Event ${event} timed out after ${timeout} ms`)); }, timeout); emitter.once(event, (...args: unknown[]) => { clearTimeout(timer); resolve(args); }); }); } export function setTimeoutPromise(delay: number, ref = true): Promise { return new Promise((resolve) => { const timerId = setTimeout(resolve, delay); if (!ref) timerId.unref(); }); } ================================================ FILE: lib/versioned-map.ts ================================================ const NONEXISTENT = Symbol(); const UNDEFINED = undefined; interface Revisions { [rev: number]: V; delete?: number; } export default class VersionedMap { declare private _sizeDiff: number[]; declare private _revision: number; declare private map: Map; declare public dirty: number; public constructor() { this._sizeDiff = [0]; this._revision = 0; this.map = new Map(); this.dirty = 0; } public get size(): number { return this.map.size + this._sizeDiff[this.revision]; } public get revision(): number { return this._revision; } public set revision(rev: number) { for (let i = this._sizeDiff.length; i <= rev; ++i) this._sizeDiff[i] = this._sizeDiff[i - 1]; this._revision = rev; } public get(key: K, rev = this._revision): V { const revisions = this.map.get(key); if (!revisions) return UNDEFINED; const v = revisions[Math.min(revisions.length - 1, rev)]; if (v === NONEXISTENT) return UNDEFINED; return v as V; } public has(key: K, rev = this._revision): boolean { const revisions = this.map.get(key); if (!revisions) return false; const v = revisions[Math.min(revisions.length - 1, rev)]; if (v === NONEXISTENT) return false; return true; } public set(key: K, value: V, rev = this._revision): this { let revisions = this.map.get(key); if (!revisions) { this.dirty |= 1 << rev; for (let i = 0; i < rev; ++i) this._sizeDiff[i] -= 1; revisions = []; for (let i = 0; i < rev; ++i) revisions[i] = NONEXISTENT; revisions[rev] = value; this.map.set(key, revisions); return this; } // Can't modify old revisions if (rev < revisions.length - 1) return null; const old = revisions[revisions.length - 1]; this.dirty |= 1 << rev; if (old === NONEXISTENT) ++this._sizeDiff[rev]; for (let i = revisions.length; i < rev; ++i) revisions[i] = old; revisions[rev] = value; return this; } public delete(key: K, rev = this._revision): boolean { const revisions = this.map.get(key); if (!revisions) return false; // Can't modify old revisions if (rev < revisions.length - 1) return null; const old = revisions[revisions.length - 1]; if (old === NONEXISTENT) return false; this.dirty |= 1 << rev; --this._sizeDiff[rev]; for (let i = revisions.length; i < rev; ++i) revisions[i] = old; revisions[rev] = NONEXISTENT; return true; } public getRevisions(key: K): Revisions { const revisions = this.map.get(key); if (!revisions) return null; const res: Revisions = {}; let prev: V | symbol = NONEXISTENT; for (const [i, v] of revisions.entries()) { if (v === prev) continue; if (v === NONEXISTENT) res.delete |= 1 << i; else res[i] = v as V; prev = v; } if (prev === NONEXISTENT && !res.delete) return null; return res; } public setRevisions(key: K, revisionsObj: Revisions): void { const del = revisionsObj.delete || 0; const mutations = Object.keys(revisionsObj).reduce( (acc, cur) => (cur === "delete" ? acc : acc | (1 << +cur)), del, ); if (!mutations) return; const revisions = []; let prev: V | symbol = NONEXISTENT; for (let i = 0; mutations >> i; ++i) { let v = prev; if (del & (1 << i)) v = NONEXISTENT; else if (i in revisionsObj) v = revisionsObj[i]; if (v !== prev) this.dirty |= 1 << i; revisions[i] = v; prev = v; } this.map.set(key, revisions); } public getDiff(key: K): [V, V] { const revisions = this.map.get(key); if (!revisions) return [UNDEFINED, UNDEFINED]; let first = revisions[0]; if (first === NONEXISTENT) first = UNDEFINED; let last = revisions[revisions.length - 1]; if (last === NONEXISTENT) last = UNDEFINED; return [first as V, last as V]; } public *diff(): IterableIterator<[K, V, V]> { for (const [key, revisions] of this.map) { if (revisions.length <= 1) continue; let first = revisions[0]; let last = revisions[revisions.length - 1]; if (first === NONEXISTENT && last === NONEXISTENT) continue; if (first === NONEXISTENT) first = UNDEFINED; if (last === NONEXISTENT) last = UNDEFINED; yield [key, first as V, last as V]; } } public collapse(revision: number): void { if (this._sizeDiff.length <= revision) return; this._sizeDiff[revision] = this._sizeDiff[this._sizeDiff.length - 1]; this._sizeDiff.splice(revision + 1, this._sizeDiff.length); const d = this.dirty >> revision; this.dirty = this.dirty ^ (d << revision); this.dirty |= +!!d << revision; for (const [k, v] of this.map) { const l = v.length - 1; if (l <= revision) continue; const last = v[l]; v.splice(revision, l - revision); if (last === NONEXISTENT && !v.some((vv) => vv !== NONEXISTENT)) this.map.delete(k); } } public *[Symbol.iterator](): IterableIterator<[K, V]> { for (const [key, revisions] of this.map) { const last = revisions[revisions.length - 1]; if (last === NONEXISTENT) continue; yield [key, last as V]; } } } ================================================ FILE: lib/xml-parser.ts ================================================ const CHAR_SINGLE_QUOTE = 39; const CHAR_DOUBLE_QUOTE = 34; const CHAR_LESS_THAN = 60; const CHAR_GREATER_THAN = 62; const CHAR_COLON = 58; const CHAR_SPACE = 32; const CHAR_TAB = 9; const CHAR_CR = 13; const CHAR_LF = 10; const CHAR_SLASH = 47; const CHAR_EXMARK = 33; const CHAR_QMARK = 63; const CHAR_EQUAL = 61; const STATE_LESS_THAN = 1; const STATE_SINGLE_QUOTE = 2; const STATE_DOUBLE_QUOTE = 3; export interface Attribute { name: string; namespace: string; localName: string; value: string; } export interface Element { name: string; namespace: string; localName: string; attrs: string; text: string; bodyIndex: number; children: Element[]; } export function parseXmlDeclaration(buffer: Buffer): Attribute[] { const encodings: BufferEncoding[] = ["utf16le", "utf8", "latin1", "ascii"]; for (const enc of encodings) { let str = buffer.toString(enc, 0, 150); if (str.startsWith("")); try { return parseAttrs(str.slice(5)); } catch { // Ignore } } } return null; } export function parseAttrs(string: string): Attribute[] { const attrs: Attribute[] = []; const len = string.length; let state = 0; let name = ""; let namespace = ""; let localName = ""; let idx = 0; let colonIdx = 0; for (let i = 0; i < len; ++i) { const c = string.charCodeAt(i); switch (c) { case CHAR_SINGLE_QUOTE: case CHAR_DOUBLE_QUOTE: if (state === c) { state = 0; if (name) { const value = string.slice(idx + 1, i); const e = { name: name, namespace: namespace, localName: localName, value: value, }; attrs.push(e); name = ""; idx = i + 1; } } else { state = c; idx = i; } continue; case CHAR_COLON: if (state) continue; if (idx >= colonIdx) colonIdx = i; continue; case CHAR_EQUAL: if (state) continue; if (name) throw new Error(`Unexpected character at ${i}`); name = string.slice(idx, i).trim(); // TODO validate name if (colonIdx > idx) { namespace = string.slice(idx, colonIdx).trim(); localName = string.slice(colonIdx + 1, i).trim(); } else { namespace = ""; localName = name; } } } if (name) throw new Error(`Attribute must have value at ${idx}`); const tail = string.slice(idx); if (tail.trim()) throw new Error(`Unexpected string at ${len - tail.length}`); return attrs; } export function decodeEntities(string: string): string { return string.replace(/&[0-9a-z#]+;/gi, (match) => { switch (match) { case """: return '"'; case "&": return "&"; case "'": return "'"; case "<": return "<"; case ">": return ">"; default: if (match.startsWith("&#x")) { const str = match.slice(3, -1).toLowerCase(); const n = parseInt(str, 16); if (str.endsWith(n.toString(16))) return String.fromCharCode(n); } else if (match.startsWith("&#")) { const str = match.slice(2, -1); const n = parseInt(str); if (str.endsWith(n.toString())) return String.fromCharCode(n); } } return match; }); } export function encodeEntities(string: string): string { const entities = { "&": "&", '"': """, "'": "'", "<": "<", ">": ">", }; return string.replace(/[&"'<>]/g, (m) => entities[m]); } export function parseXml(string: string): Element { const len = string.length; let state1 = 0; let state1Index = 0; let state2 = 0; let state2Index = 0; const root: Element = { name: "root", namespace: "", localName: "root", attrs: "", text: "", bodyIndex: 0, children: [], }; const stack: Element[] = [root]; for (let i = 0; i < len; ++i) { switch (string.charCodeAt(i)) { case CHAR_SINGLE_QUOTE: switch (state1 & 0xff) { case STATE_SINGLE_QUOTE: state1 = state2; state1Index = state2Index; state2 = 0; continue; case STATE_LESS_THAN: state2 = state1; state2Index = state1Index; state1 = STATE_SINGLE_QUOTE; state1Index = i; continue; } continue; case CHAR_DOUBLE_QUOTE: switch (state1 & 0xff) { case STATE_DOUBLE_QUOTE: state1 = state2; state1Index = state2Index; state2 = 0; continue; case STATE_LESS_THAN: state2 = state1; state2Index = state1Index; state1 = STATE_DOUBLE_QUOTE; state1Index = i; continue; } continue; case CHAR_LESS_THAN: if ((state1 & 0xff) === 0) { state2 = state1; state2Index = state1Index; state1 = STATE_LESS_THAN; state1Index = i; } continue; case CHAR_COLON: if ((state1 & 0xff) === STATE_LESS_THAN) { const colonIndex = (state1 >> 8) & 0xff; if (colonIndex === 0) state1 ^= ((i - state1Index) & 0xff) << 8; } continue; case CHAR_SPACE: case CHAR_TAB: case CHAR_CR: case CHAR_LF: if ((state1 & 0xff) === STATE_LESS_THAN) { const wsIndex = (state1 >> 16) & 0xff; if (wsIndex === 0) state1 ^= ((i - state1Index) & 0xff) << 16; } continue; case CHAR_GREATER_THAN: if ((state1 & 0xff) === STATE_LESS_THAN) { const secondChar = string.charCodeAt(state1Index + 1); const wsIndex: number = (state1 >> 16) & 0xff; let name: string, colonIndex: number, e: Element, parent: Element, selfClosing: number, localName: string, namespace: string; switch (secondChar) { case CHAR_SLASH: e = stack.pop(); name = wsIndex === 0 ? string.slice(state1Index + 2, i) : string.slice(state1Index + 2, state1Index + wsIndex); if (e.name !== name) throw new Error(`Unmatched closing tag at ${i}`); if (!e.children.length) e.text = string.slice(e.bodyIndex, state1Index); state1 = state2; state1Index = state2Index; state2 = 0; continue; case CHAR_EXMARK: if (string.startsWith("![CDATA[", state1Index + 1)) { if (string.endsWith("]]", i)) throw new Error(`CDATA nodes are not supported at ${i}`); } else if (string.startsWith("!--", state1Index + 1)) { // Comment node, ignore if (string.endsWith("--", i)) { state1 = state2; state1Index = state2Index; state2 = 0; } } continue; case CHAR_QMARK: if (string.charCodeAt(i - 1) === CHAR_QMARK) { // XML declaration node, ignore state1 = state2; state1Index = state2Index; state2 = 0; } continue; default: selfClosing = +(string.charCodeAt(i - 1) === CHAR_SLASH); parent = stack[stack.length - 1]; colonIndex = (state1 >> 8) & 0xff; name = wsIndex === 0 ? string.slice(state1Index + 1, i - selfClosing) : string.slice(state1Index + 1, state1Index + wsIndex); if (colonIndex && (!wsIndex || colonIndex < wsIndex)) { localName = name.slice(colonIndex); namespace = name.slice(0, colonIndex - 1); } else { localName = name; namespace = ""; } e = { name: name, namespace: namespace, localName: localName, attrs: wsIndex ? string.slice(state1Index + wsIndex + 1, i - selfClosing) : "", text: "", bodyIndex: i + 1, children: [], }; parent.children.push(e); if (!selfClosing) stack.push(e); state1 = state2; state1Index = state2Index; state2 = 0; continue; } } continue; } } if (state1) throw new Error(`Unclosed token at ${state1Index}`); if (stack.length > 1) { const e = stack[stack.length - 1]; throw new Error(`Unclosed XML element at ${e.bodyIndex}`); } if (!root.children.length) root.text = string; return root; } ================================================ FILE: lib/xmpp-client.ts ================================================ import * as net from "node:net"; import * as tls from "node:tls"; import { EventEmitter } from "node:events"; import { createHash, createHmac, randomBytes } from "node:crypto"; import { parseXml, Element, parseAttrs } from "./xml-parser.ts"; function encodeBase64(str: string): string { return Buffer.from(str).toString("base64"); } function decodeBase64(str: string): string { return Buffer.from(str, "base64").toString(); } function detectStreamTag(data: string): number { const i1 = data.indexOf("", i1); if (i2 < 0) throw new Error("Cannot detect opening stream tag"); return i2 + 1; } function xmppStream( socket: net.Socket, callback: Generator, ): Promise { return new Promise((resolve, reject) => { const onError = (err: Error): void => { socket.removeListener("error", onError); reject(err); }; socket.on("error", onError); const onData = (chunk: Buffer): void => { try { const str = chunk.toString("utf8"); const xml = parseXml(str); const { value, done } = callback.next(xml.children[0]); if (done) { socket.removeListener("error", onError); socket.removeListener("data", onData); resolve(value as T); } } catch (err) { socket.removeListener("error", onError); socket.removeListener("data", onData); reject(err); } }; socket.once("data", (chunk: Buffer) => { try { const str = chunk.toString("utf8"); const i = detectStreamTag(str); const streamTagStr = str.slice(0, i); const xml = parseXml(streamTagStr + ""); callback.next(xml.children[0]); chunk = chunk.slice(Buffer.byteLength(streamTagStr)); if (chunk.length) onData(chunk); socket.on("data", onData); } catch (err) { socket.removeListener("error", onError); socket.removeListener("data", onData); reject(err); } }); try { callback.next(); } catch (err) { socket.removeListener("error", onError); socket.removeListener("data", onData); reject(err); } }); } const INT_1 = Buffer.from([0, 0, 0, 1]); const saltedPasswordCache = { password: "", iterationCount: 0, saltBase64: "", salted: Buffer.allocUnsafe(0), }; function saltPassword( password: string, saltBase64: string, iteractionCount: number, ): Buffer { if ( password === saltedPasswordCache.password && saltBase64 === saltedPasswordCache.saltBase64 && iteractionCount === saltedPasswordCache.iterationCount ) return saltedPasswordCache.salted; const hi = createHmac("sha1", password) .update(Buffer.concat([Buffer.from(saltBase64, "base64"), INT_1])) .digest(); let hi2: Buffer = hi; for (let i = 1; i < iteractionCount; ++i) { hi2 = createHmac("sha1", password).update(hi2).digest(); for (const [j, b] of hi2.entries()) hi[j] ^= b; } saltedPasswordCache.saltBase64 = saltBase64; saltedPasswordCache.password = password; saltedPasswordCache.iterationCount = iteractionCount; saltedPasswordCache.salted = hi; return hi; } function* loginPlain( socket: net.Socket, username: string, password: string, ): Generator { socket.write( `${encodeBase64( `\x00${username}\x00${password}`, )}`, ); const res1 = yield; if ( res1.name === "failure" && res1.children.some((c) => c.name === "not-authorized") ) throw new Error("Not authorized"); if (res1.name !== "success") throw new Error(`Unexpected response ${res1.name}`); } function* loginScram( socket: net.Socket, username: string, password: string, ): Generator { const cnonce = randomBytes(8).toString("base64"); const gs2Header = "n,,"; const clientFirstMessageBare = `n=${username},r=${cnonce}`; const clientFirstMessage = gs2Header + clientFirstMessageBare; socket.write( `${encodeBase64( clientFirstMessage, )}`, ); const res1 = yield; if (res1.name !== "challenge") throw new Error(`Unexpected element ${res1.name}`); const serverFirstMessage = decodeBase64(res1.text); let iterationCount: number; let saltBase64: string; let nonce: string; for (const s of serverFirstMessage.split(",")) { if (s.startsWith("i=")) iterationCount = parseInt(s.slice(2)); else if (s.startsWith("s=")) saltBase64 = s.slice(2); else if (s.startsWith("r=")) nonce = s.slice(2); } if (iterationCount == null || isNaN(iterationCount)) throw new Error("Invalid iteration count"); if (saltBase64 == null) throw new Error("Missing salt"); if (nonce == null) throw new Error("Missing nonce"); const saltedPassword = saltPassword(password, saltBase64, iterationCount); const clientKey = createHmac("sha1", saltedPassword) .update("Client Key") .digest(); const storedKey = createHash("sha1").update(clientKey).digest(); const clientFinalMessageWithoutProof = `c=${encodeBase64( gs2Header, )},r=${nonce}`; const authMessage = `${clientFirstMessageBare},${serverFirstMessage},${clientFinalMessageWithoutProof}`; const clientSignature = createHmac("sha1", storedKey) .update(authMessage) .digest(); const clientProof = Buffer.from(clientKey); for (const [i, b] of clientSignature.entries()) clientProof[i] ^= b; const clientFinalMessage = `${clientFinalMessageWithoutProof},p=${clientProof.toString( "base64", )}`; socket.write( `${encodeBase64( clientFinalMessage, )}`, ); const res2 = yield; if ( res2.name === "failure" && res2.children.some((c) => c.name === "not-authorized") ) throw new Error("Not authorized"); if (res2.name !== "success") throw new Error(`Unexpected response ${res2.name}`); const serverKey = createHmac("sha1", saltedPassword) .update("Server Key") .digest(); const serverSignature = createHmac("sha1", serverKey) .update(authMessage) .digest("base64"); if (!decodeBase64(res2.text).endsWith(serverSignature)) throw new Error("Invalid server signature"); } function* starttls(socket: net.Socket): Generator { socket.write(""); const res1 = yield; if (res1.name !== "proceed") throw new Error("Failed to initiate STARTTLS"); } function* bind( socket: net.Socket, resource: string, ): Generator { const id = randomBytes(8).toString("base64"); socket.write( `${resource}`, ); const res1 = yield; if (res1.name !== "iq") throw new Error(`Unexpected element ${res1.name}`); const attrs1 = parseAttrs(res1.attrs); const idAttr = attrs1.find((a) => a.name === "id"); if (!idAttr || idAttr.value !== id) throw new Error("Invalid ID"); const typeAttr = attrs1.find((a) => a.name === "type"); if (!typeAttr) throw new Error("Missing type attribute"); if (typeAttr.value !== "result") throw new Error("Cannot bind to resource"); } const STATUS_RESTART_STREAM = 1; const STATUS_STARTTLS = 2; function* init( socket: net.Socket, host: string, username: string, password: string, resource: string, ): Generator { socket.write( ``, ); const open = yield; if (open.name !== "stream:stream") throw new Error(`Unexpected element ${open.name}`); const features = yield; if (features.name !== "stream:features") throw new Error(`Unexpected element ${features.name}`); for (const feature of features.children) { if (feature.name === "starttls") { if (feature.children.some((c) => c.name === "required")) { yield* starttls(socket); return STATUS_STARTTLS; } } else if (feature.name === "mechanisms") { const mechanisms: Set = new Set( feature.children.map((c) => c.text), ); if (mechanisms.has("PLAIN")) { yield* loginPlain(socket, username, password); return STATUS_RESTART_STREAM; } else if (mechanisms.has("SCRAM-SHA-1")) { yield* loginScram(socket, username, password); return STATUS_RESTART_STREAM; } else { throw new Error("No supported SASL method"); } } else if (feature.name === "bind") { yield* bind(socket, resource); return 0; } } return 0; } function upgradeTls(socket: net.Socket, host: string): Promise { return new Promise((resolve, reject) => { socket.on("error", reject); const newSocket = tls.connect({ socket, host }, () => { socket.removeListener("error", reject); resolve(newSocket); }); }); } interface XmppClientOptions { host: string; port?: number; username?: string; password?: string; resource?: string; timeout?: number; } export default class XmppClient extends EventEmitter { private _socket: net.Socket; private _host: string; private _username: string; private _resource: string; private _iqStanzaCallbacks: Map< string, (err: Error, r?: { rawRes: string; res: Element }) => void >; private constructor() { super(); this._socket = null; this._host = null; this._username = null; this._resource = null; this._iqStanzaCallbacks = new Map(); } static async connect(opts: XmppClientOptions): Promise { function connectSocket(host: string, port: number): Promise { return new Promise((resolve, reject) => { const socket = new net.Socket(); socket.on("error", reject); socket.connect(port, host, () => { socket.removeListener("error", reject); resolve(socket); }); }); } let socket = await connectSocket(opts.host, opts.port || 5222); try { let status = 1; while (status) { if (status === STATUS_STARTTLS) socket = await upgradeTls(socket, opts.host); status = await xmppStream( socket, init(socket, opts.host, opts.username, opts.password, opts.resource), ); } } catch (err) { socket.destroy(); throw err; } const client = new XmppClient(); client._socket = socket; client._host = opts.host; client._username = opts.username; client._resource = opts.resource; socket.on("data", client._onData.bind(client)); socket.on("error", client._onError.bind(client)); if (opts.timeout) socket.setTimeout(opts.timeout, client.close.bind(client)); return client; } close(): void { this._socket.end(""); this._socket.removeAllListeners("data"); this._socket.removeAllListeners("error"); this.emit("close"); } ref(): void { this._socket.ref(); } unref(): void { this._socket.unref(); } get host(): string { return this._host; } get username(): string { return this._username; } get resource(): string { return this._resource; } private _onData(chunk: Buffer): void { try { let close = false; let str = chunk.toString("utf8"); if (str.endsWith("")) { str = str.slice(0, -16); close = true; } const xml = parseXml(str); const idx = xml.children.map((c) => c.bodyIndex); for (const [i, c] of xml.children.entries()) { const s = str.slice(idx[i], idx[i + 1]); if (c.name === "iq") { const attrs = parseAttrs(c.attrs); const id = attrs.find((a) => a.name === "id"); if (id) { const cb = this._iqStanzaCallbacks.get(id.value); if (cb) cb(null, { rawRes: s, res: c }); } } this.emit("stanza", c, s); } if (close) { this._socket.removeAllListeners("data"); this._socket.removeAllListeners("error"); this.emit("close"); } } catch (err) { this._socket.removeAllListeners("data"); this._socket.removeAllListeners("error"); this.emit("error", err); } } private _onError(err: Error): void { this._socket.end(); this.emit("error", err); for (const cb of this._iqStanzaCallbacks.values()) cb(err); } send(msg: string): void { this._socket.write(msg); } sendIqStanza( from: string, to: string, type: string, body: string, timeout = 3000, ): Promise<{ rawReq: string; rawRes: string; res: Element }> { return new Promise((resolve, reject) => { const id = randomBytes(8).toString("base64"); const rawReq = `${body}`; this.send(rawReq); const t = setTimeout(() => { this._iqStanzaCallbacks.delete(id); reject( new Error("Did not receive IQ stanza response in a timely manner"), ); }, timeout); this._iqStanzaCallbacks.set(id, (err, r) => { this._iqStanzaCallbacks.delete(id); clearTimeout(t); if (err) reject(err); else resolve(Object.assign(r, { rawReq })); }); }); } } ================================================ FILE: npm-shrinkwrap.json ================================================ { "name": "genieacs", "version": "1.3.0-dev", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "genieacs", "version": "1.3.0-dev", "license": "AGPL-3.0", "dependencies": { "@breejs/later": "^4.2.0", "@koa/bodyparser": "^5.1.2", "@koa/router": "^13.1.1", "bson": "^4.7.2", "espresso-iisojs": "^1.0.8", "iconv-lite": "^0.6.3", "ipaddr.js": "^2.3.0", "jsonwebtoken": "^9.0.3", "koa": "^2.16.4", "koa-compress": "^5.2.0", "koa-jwt": "^4.0.3", "koa-send": "^5.0.1", "mongodb": "^4.16.0", "seedrandom": "^3.0.5" }, "bin": { "genieacs-cwmp": "bin/genieacs-cwmp", "genieacs-fs": "bin/genieacs-fs", "genieacs-nbi": "bin/genieacs-nbi", "genieacs-ui": "bin/genieacs-ui" }, "devDependencies": { "@codemirror/commands": "^6.10.2", "@codemirror/lang-javascript": "^6.2.5", "@codemirror/lang-yaml": "^6.1.2", "@codemirror/language": "^6.12.2", "@codemirror/state": "^6.5.4", "@codemirror/view": "^6.39.16", "@eslint/js": "^10.0.1", "@tailwindcss/cli": "^4.2.1", "@tailwindcss/forms": "^0.5.11", "@types/jsonwebtoken": "^9.0.10", "@types/koa": "^2.15.0", "@types/koa-compress": "^4.0.7", "@types/mithril": "^2.2.7", "@types/node": "^25.3.5", "@types/seedrandom": "^3.0.8", "esbuild": "^0.27.4", "eslint": "^10.0.3", "eslint-config-prettier": "^10.1.8", "globals": "^17.4.0", "mithril": "^2.3.8", "prettier": "^3.8.1", "sql.js": "^1.14.1", "svgo": "^3.3.3", "tailwindcss": "^4.2.1", "typescript": "^5.9.3", "typescript-eslint": "^8.56.1", "yaml": "^1.10.2" }, "engines": { "node": ">=12.13.0" } }, "node_modules/@aws-crypto/sha256-browser": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/@aws-crypto/sha256-browser/-/sha256-browser-5.2.0.tgz", "integrity": "sha512-AXfN/lGotSQwu6HNcEsIASo7kWXZ5HYWvfOmSNKDsEqC4OashTp8alTmaz+F7TC2L083SFv5RdB+qU3Vs1kZqw==", "optional": true, "dependencies": { "@aws-crypto/sha256-js": "^5.2.0", "@aws-crypto/supports-web-crypto": "^5.2.0", "@aws-crypto/util": "^5.2.0", "@aws-sdk/types": "^3.222.0", "@aws-sdk/util-locate-window": "^3.0.0", "@smithy/util-utf8": "^2.0.0", "tslib": "^2.6.2" } }, "node_modules/@aws-crypto/sha256-browser/node_modules/@smithy/is-array-buffer": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/@smithy/is-array-buffer/-/is-array-buffer-2.2.0.tgz", "integrity": "sha512-GGP3O9QFD24uGeAXYUjwSTXARoqpZykHadOmA8G5vfJPK0/DC67qa//0qvqrJzL1xc8WQWX7/yc7fwudjPHPhA==", "optional": true, "dependencies": { "tslib": "^2.6.2" }, "engines": { "node": ">=14.0.0" } }, "node_modules/@aws-crypto/sha256-browser/node_modules/@smithy/util-buffer-from": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/@smithy/util-buffer-from/-/util-buffer-from-2.2.0.tgz", "integrity": "sha512-IJdWBbTcMQ6DA0gdNhh/BwrLkDR+ADW5Kr1aZmd4k3DIF6ezMV4R2NIAmT08wQJ3yUK82thHWmC/TnK/wpMMIA==", "optional": true, "dependencies": { "@smithy/is-array-buffer": "^2.2.0", "tslib": "^2.6.2" }, "engines": { "node": ">=14.0.0" } }, "node_modules/@aws-crypto/sha256-browser/node_modules/@smithy/util-utf8": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/@smithy/util-utf8/-/util-utf8-2.3.0.tgz", "integrity": "sha512-R8Rdn8Hy72KKcebgLiv8jQcQkXoLMOGGv5uI1/k0l+snqkOzQ1R0ChUBCxWMlBsFMekWjq0wRudIweFs7sKT5A==", "optional": true, "dependencies": { "@smithy/util-buffer-from": "^2.2.0", "tslib": "^2.6.2" }, "engines": { "node": ">=14.0.0" } }, "node_modules/@aws-crypto/sha256-js": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/@aws-crypto/sha256-js/-/sha256-js-5.2.0.tgz", "integrity": "sha512-FFQQyu7edu4ufvIZ+OadFpHHOt+eSTBaYaki44c+akjg7qZg9oOQeLlk77F6tSYqjDAFClrHJk9tMf0HdVyOvA==", "optional": true, "dependencies": { "@aws-crypto/util": "^5.2.0", "@aws-sdk/types": "^3.222.0", "tslib": "^2.6.2" }, "engines": { "node": ">=16.0.0" } }, "node_modules/@aws-crypto/supports-web-crypto": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/@aws-crypto/supports-web-crypto/-/supports-web-crypto-5.2.0.tgz", "integrity": "sha512-iAvUotm021kM33eCdNfwIN//F77/IADDSs58i+MDaOqFrVjZo9bAal0NK7HurRuWLLpF1iLX7gbWrjHjeo+YFg==", "optional": true, "dependencies": { "tslib": "^2.6.2" } }, "node_modules/@aws-crypto/util": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/@aws-crypto/util/-/util-5.2.0.tgz", "integrity": "sha512-4RkU9EsI6ZpBve5fseQlGNUWKMa1RLPQ1dnjnQoe07ldfIzcsGb5hC5W0Dm7u423KWzawlrpbjXBrXCEv9zazQ==", "optional": true, "dependencies": { "@aws-sdk/types": "^3.222.0", "@smithy/util-utf8": "^2.0.0", "tslib": "^2.6.2" } }, "node_modules/@aws-crypto/util/node_modules/@smithy/is-array-buffer": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/@smithy/is-array-buffer/-/is-array-buffer-2.2.0.tgz", "integrity": "sha512-GGP3O9QFD24uGeAXYUjwSTXARoqpZykHadOmA8G5vfJPK0/DC67qa//0qvqrJzL1xc8WQWX7/yc7fwudjPHPhA==", "optional": true, "dependencies": { "tslib": "^2.6.2" }, "engines": { "node": ">=14.0.0" } }, "node_modules/@aws-crypto/util/node_modules/@smithy/util-buffer-from": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/@smithy/util-buffer-from/-/util-buffer-from-2.2.0.tgz", "integrity": "sha512-IJdWBbTcMQ6DA0gdNhh/BwrLkDR+ADW5Kr1aZmd4k3DIF6ezMV4R2NIAmT08wQJ3yUK82thHWmC/TnK/wpMMIA==", "optional": true, "dependencies": { "@smithy/is-array-buffer": "^2.2.0", "tslib": "^2.6.2" }, "engines": { "node": ">=14.0.0" } }, "node_modules/@aws-crypto/util/node_modules/@smithy/util-utf8": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/@smithy/util-utf8/-/util-utf8-2.3.0.tgz", "integrity": "sha512-R8Rdn8Hy72KKcebgLiv8jQcQkXoLMOGGv5uI1/k0l+snqkOzQ1R0ChUBCxWMlBsFMekWjq0wRudIweFs7sKT5A==", "optional": true, "dependencies": { "@smithy/util-buffer-from": "^2.2.0", "tslib": "^2.6.2" }, "engines": { "node": ">=14.0.0" } }, "node_modules/@aws-sdk/client-cognito-identity": { "version": "3.1008.0", "resolved": "https://registry.npmjs.org/@aws-sdk/client-cognito-identity/-/client-cognito-identity-3.1008.0.tgz", "integrity": "sha512-zzHnrTImR1JJ/Sq90y35UiFiriwge6W8qZQxIBJCgAMwEGkQAqHEAc3d6ptLmwdntcid3dx7wvauOXbpiMVbAQ==", "optional": true, "dependencies": { "@aws-crypto/sha256-browser": "5.2.0", "@aws-crypto/sha256-js": "5.2.0", "@aws-sdk/core": "^3.973.19", "@aws-sdk/credential-provider-node": "^3.972.20", "@aws-sdk/middleware-host-header": "^3.972.7", "@aws-sdk/middleware-logger": "^3.972.7", "@aws-sdk/middleware-recursion-detection": "^3.972.7", "@aws-sdk/middleware-user-agent": "^3.972.20", "@aws-sdk/region-config-resolver": "^3.972.7", "@aws-sdk/types": "^3.973.5", "@aws-sdk/util-endpoints": "^3.996.4", "@aws-sdk/util-user-agent-browser": "^3.972.7", "@aws-sdk/util-user-agent-node": "^3.973.6", "@smithy/config-resolver": "^4.4.10", "@smithy/core": "^3.23.9", "@smithy/fetch-http-handler": "^5.3.13", "@smithy/hash-node": "^4.2.11", "@smithy/invalid-dependency": "^4.2.11", "@smithy/middleware-content-length": "^4.2.11", "@smithy/middleware-endpoint": "^4.4.23", "@smithy/middleware-retry": "^4.4.40", "@smithy/middleware-serde": "^4.2.12", "@smithy/middleware-stack": "^4.2.11", "@smithy/node-config-provider": "^4.3.11", "@smithy/node-http-handler": "^4.4.14", "@smithy/protocol-http": "^5.3.11", "@smithy/smithy-client": "^4.12.3", "@smithy/types": "^4.13.0", "@smithy/url-parser": "^4.2.11", "@smithy/util-base64": "^4.3.2", "@smithy/util-body-length-browser": "^4.2.2", "@smithy/util-body-length-node": "^4.2.3", "@smithy/util-defaults-mode-browser": "^4.3.39", "@smithy/util-defaults-mode-node": "^4.2.42", "@smithy/util-endpoints": "^3.3.2", "@smithy/util-middleware": "^4.2.11", "@smithy/util-retry": "^4.2.11", "@smithy/util-utf8": "^4.2.2", "tslib": "^2.6.2" }, "engines": { "node": ">=20.0.0" } }, "node_modules/@aws-sdk/core": { "version": "3.973.19", "resolved": "https://registry.npmjs.org/@aws-sdk/core/-/core-3.973.19.tgz", "integrity": "sha512-56KePyOcZnKTWCd89oJS1G6j3HZ9Kc+bh/8+EbvtaCCXdP6T7O7NzCiPuHRhFLWnzXIaXX3CxAz0nI5My9spHQ==", "optional": true, "dependencies": { "@aws-sdk/types": "^3.973.5", "@aws-sdk/xml-builder": "^3.972.10", "@smithy/core": "^3.23.9", "@smithy/node-config-provider": "^4.3.11", "@smithy/property-provider": "^4.2.11", "@smithy/protocol-http": "^5.3.11", "@smithy/signature-v4": "^5.3.11", "@smithy/smithy-client": "^4.12.3", "@smithy/types": "^4.13.0", "@smithy/util-base64": "^4.3.2", "@smithy/util-middleware": "^4.2.11", "@smithy/util-utf8": "^4.2.2", "tslib": "^2.6.2" }, "engines": { "node": ">=20.0.0" } }, "node_modules/@aws-sdk/credential-provider-cognito-identity": { "version": "3.972.12", "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-cognito-identity/-/credential-provider-cognito-identity-3.972.12.tgz", "integrity": "sha512-0R7EKJBd19VGoYMrp7ozikwRh6KpapIO3T/Vf9tMrAVxrUNd5V+A6V1gxypY7iJv9GwVR1ZWL/nFt/m0KvcjIQ==", "optional": true, "dependencies": { "@aws-sdk/nested-clients": "^3.996.9", "@aws-sdk/types": "^3.973.5", "@smithy/property-provider": "^4.2.11", "@smithy/types": "^4.13.0", "tslib": "^2.6.2" }, "engines": { "node": ">=20.0.0" } }, "node_modules/@aws-sdk/credential-provider-env": { "version": "3.972.17", "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-env/-/credential-provider-env-3.972.17.tgz", "integrity": "sha512-MBAMW6YELzE1SdkOniqr51mrjapQUv8JXSGxtwRjQV0mwVDutVsn22OPAUt4RcLRvdiHQmNBDEFP9iTeSVCOlA==", "optional": true, "dependencies": { "@aws-sdk/core": "^3.973.19", "@aws-sdk/types": "^3.973.5", "@smithy/property-provider": "^4.2.11", "@smithy/types": "^4.13.0", "tslib": "^2.6.2" }, "engines": { "node": ">=20.0.0" } }, "node_modules/@aws-sdk/credential-provider-http": { "version": "3.972.19", "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-http/-/credential-provider-http-3.972.19.tgz", "integrity": "sha512-9EJROO8LXll5a7eUFqu48k6BChrtokbmgeMWmsH7lBb6lVbtjslUYz/ShLi+SHkYzTomiGBhmzTW7y+H4BxsnA==", "optional": true, "dependencies": { "@aws-sdk/core": "^3.973.19", "@aws-sdk/types": "^3.973.5", "@smithy/fetch-http-handler": "^5.3.13", "@smithy/node-http-handler": "^4.4.14", "@smithy/property-provider": "^4.2.11", "@smithy/protocol-http": "^5.3.11", "@smithy/smithy-client": "^4.12.3", "@smithy/types": "^4.13.0", "@smithy/util-stream": "^4.5.17", "tslib": "^2.6.2" }, "engines": { "node": ">=20.0.0" } }, "node_modules/@aws-sdk/credential-provider-ini": { "version": "3.972.19", "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-ini/-/credential-provider-ini-3.972.19.tgz", "integrity": "sha512-pVJVjWqVrPqjpFq7o0mCmeZu1Y0c94OCHSYgivdCD2wfmYVtBbwQErakruhgOD8pcMcx9SCqRw1pzHKR7OGBcA==", "optional": true, "dependencies": { "@aws-sdk/core": "^3.973.19", "@aws-sdk/credential-provider-env": "^3.972.17", "@aws-sdk/credential-provider-http": "^3.972.19", "@aws-sdk/credential-provider-login": "^3.972.19", "@aws-sdk/credential-provider-process": "^3.972.17", "@aws-sdk/credential-provider-sso": "^3.972.19", "@aws-sdk/credential-provider-web-identity": "^3.972.19", "@aws-sdk/nested-clients": "^3.996.9", "@aws-sdk/types": "^3.973.5", "@smithy/credential-provider-imds": "^4.2.11", "@smithy/property-provider": "^4.2.11", "@smithy/shared-ini-file-loader": "^4.4.6", "@smithy/types": "^4.13.0", "tslib": "^2.6.2" }, "engines": { "node": ">=20.0.0" } }, "node_modules/@aws-sdk/credential-provider-login": { "version": "3.972.19", "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-login/-/credential-provider-login-3.972.19.tgz", "integrity": "sha512-jOXdZ1o+CywQKr6gyxgxuUmnGwTTnY2Kxs1PM7fI6AYtDWDnmW/yKXayNqkF8KjP1unflqMWKVbVt5VgmE3L0g==", "optional": true, "dependencies": { "@aws-sdk/core": "^3.973.19", "@aws-sdk/nested-clients": "^3.996.9", "@aws-sdk/types": "^3.973.5", "@smithy/property-provider": "^4.2.11", "@smithy/protocol-http": "^5.3.11", "@smithy/shared-ini-file-loader": "^4.4.6", "@smithy/types": "^4.13.0", "tslib": "^2.6.2" }, "engines": { "node": ">=20.0.0" } }, "node_modules/@aws-sdk/credential-provider-node": { "version": "3.972.20", "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-node/-/credential-provider-node-3.972.20.tgz", "integrity": "sha512-0xHca2BnPY0kzjDYPH7vk8YbfdBPpWVS67rtqQMalYDQUCBYS37cZ55K6TuFxCoIyNZgSCFrVKr9PXC5BVvQQw==", "optional": true, "dependencies": { "@aws-sdk/credential-provider-env": "^3.972.17", "@aws-sdk/credential-provider-http": "^3.972.19", "@aws-sdk/credential-provider-ini": "^3.972.19", "@aws-sdk/credential-provider-process": "^3.972.17", "@aws-sdk/credential-provider-sso": "^3.972.19", "@aws-sdk/credential-provider-web-identity": "^3.972.19", "@aws-sdk/types": "^3.973.5", "@smithy/credential-provider-imds": "^4.2.11", "@smithy/property-provider": "^4.2.11", "@smithy/shared-ini-file-loader": "^4.4.6", "@smithy/types": "^4.13.0", "tslib": "^2.6.2" }, "engines": { "node": ">=20.0.0" } }, "node_modules/@aws-sdk/credential-provider-process": { "version": "3.972.17", "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-process/-/credential-provider-process-3.972.17.tgz", "integrity": "sha512-c8G8wT1axpJDgaP3xzcy+q8Y1fTi9A2eIQJvyhQ9xuXrUZhlCfXbC0vM9bM1CUXiZppFQ1p7g0tuUMvil/gCPg==", "optional": true, "dependencies": { "@aws-sdk/core": "^3.973.19", "@aws-sdk/types": "^3.973.5", "@smithy/property-provider": "^4.2.11", "@smithy/shared-ini-file-loader": "^4.4.6", "@smithy/types": "^4.13.0", "tslib": "^2.6.2" }, "engines": { "node": ">=20.0.0" } }, "node_modules/@aws-sdk/credential-provider-sso": { "version": "3.972.19", "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-sso/-/credential-provider-sso-3.972.19.tgz", "integrity": "sha512-kVjQsEU3b///q7EZGrUzol9wzwJFKbEzqJKSq82A9ShrUTEO7FNylTtby3sPV19ndADZh1H3FB3+5ZrvKtEEeg==", "optional": true, "dependencies": { "@aws-sdk/core": "^3.973.19", "@aws-sdk/nested-clients": "^3.996.9", "@aws-sdk/token-providers": "3.1008.0", "@aws-sdk/types": "^3.973.5", "@smithy/property-provider": "^4.2.11", "@smithy/shared-ini-file-loader": "^4.4.6", "@smithy/types": "^4.13.0", "tslib": "^2.6.2" }, "engines": { "node": ">=20.0.0" } }, "node_modules/@aws-sdk/credential-provider-web-identity": { "version": "3.972.19", "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-web-identity/-/credential-provider-web-identity-3.972.19.tgz", "integrity": "sha512-BV1BlTFdG4w4tAihxN7iXDBoNcNewXD4q8uZlNQiUrnqxwGWUhKHODIQVSPlQGxXClEj+63m+cqZskw+ESmeZg==", "optional": true, "dependencies": { "@aws-sdk/core": "^3.973.19", "@aws-sdk/nested-clients": "^3.996.9", "@aws-sdk/types": "^3.973.5", "@smithy/property-provider": "^4.2.11", "@smithy/shared-ini-file-loader": "^4.4.6", "@smithy/types": "^4.13.0", "tslib": "^2.6.2" }, "engines": { "node": ">=20.0.0" } }, "node_modules/@aws-sdk/credential-providers": { "version": "3.1008.0", "resolved": "https://registry.npmjs.org/@aws-sdk/credential-providers/-/credential-providers-3.1008.0.tgz", "integrity": "sha512-JPjsKAYpuaDwmeE2WvrrfTb27FYa6kIe0gj1JCazHWGteQ6LDycBddsDsRSgq2MfqAqdcHnrgnfGzY1+j8AxoQ==", "optional": true, "dependencies": { "@aws-sdk/client-cognito-identity": "3.1008.0", "@aws-sdk/core": "^3.973.19", "@aws-sdk/credential-provider-cognito-identity": "^3.972.12", "@aws-sdk/credential-provider-env": "^3.972.17", "@aws-sdk/credential-provider-http": "^3.972.19", "@aws-sdk/credential-provider-ini": "^3.972.19", "@aws-sdk/credential-provider-login": "^3.972.19", "@aws-sdk/credential-provider-node": "^3.972.20", "@aws-sdk/credential-provider-process": "^3.972.17", "@aws-sdk/credential-provider-sso": "^3.972.19", "@aws-sdk/credential-provider-web-identity": "^3.972.19", "@aws-sdk/nested-clients": "^3.996.9", "@aws-sdk/types": "^3.973.5", "@smithy/config-resolver": "^4.4.10", "@smithy/core": "^3.23.9", "@smithy/credential-provider-imds": "^4.2.11", "@smithy/node-config-provider": "^4.3.11", "@smithy/property-provider": "^4.2.11", "@smithy/types": "^4.13.0", "tslib": "^2.6.2" }, "engines": { "node": ">=20.0.0" } }, "node_modules/@aws-sdk/middleware-host-header": { "version": "3.972.7", "resolved": "https://registry.npmjs.org/@aws-sdk/middleware-host-header/-/middleware-host-header-3.972.7.tgz", "integrity": "sha512-aHQZgztBFEpDU1BB00VWCIIm85JjGjQW1OG9+98BdmaOpguJvzmXBGbnAiYcciCd+IS4e9BEq664lhzGnWJHgQ==", "optional": true, "dependencies": { "@aws-sdk/types": "^3.973.5", "@smithy/protocol-http": "^5.3.11", "@smithy/types": "^4.13.0", "tslib": "^2.6.2" }, "engines": { "node": ">=20.0.0" } }, "node_modules/@aws-sdk/middleware-logger": { "version": "3.972.7", "resolved": "https://registry.npmjs.org/@aws-sdk/middleware-logger/-/middleware-logger-3.972.7.tgz", "integrity": "sha512-LXhiWlWb26txCU1vcI9PneESSeRp/RYY/McuM4SpdrimQR5NgwaPb4VJCadVeuGWgh6QmqZ6rAKSoL1ob16W6w==", "optional": true, "dependencies": { "@aws-sdk/types": "^3.973.5", "@smithy/types": "^4.13.0", "tslib": "^2.6.2" }, "engines": { "node": ">=20.0.0" } }, "node_modules/@aws-sdk/middleware-recursion-detection": { "version": "3.972.7", "resolved": "https://registry.npmjs.org/@aws-sdk/middleware-recursion-detection/-/middleware-recursion-detection-3.972.7.tgz", "integrity": "sha512-l2VQdcBcYLzIzykCHtXlbpiVCZ94/xniLIkAj0jpnpjY4xlgZx7f56Ypn+uV1y3gG0tNVytJqo3K9bfMFee7SQ==", "optional": true, "dependencies": { "@aws-sdk/types": "^3.973.5", "@aws/lambda-invoke-store": "^0.2.2", "@smithy/protocol-http": "^5.3.11", "@smithy/types": "^4.13.0", "tslib": "^2.6.2" }, "engines": { "node": ">=20.0.0" } }, "node_modules/@aws-sdk/middleware-user-agent": { "version": "3.972.20", "resolved": "https://registry.npmjs.org/@aws-sdk/middleware-user-agent/-/middleware-user-agent-3.972.20.tgz", "integrity": "sha512-3kNTLtpUdeahxtnJRnj/oIdLAUdzTfr9N40KtxNhtdrq+Q1RPMdCJINRXq37m4t5+r3H70wgC3opW46OzFcZYA==", "optional": true, "dependencies": { "@aws-sdk/core": "^3.973.19", "@aws-sdk/types": "^3.973.5", "@aws-sdk/util-endpoints": "^3.996.4", "@smithy/core": "^3.23.9", "@smithy/protocol-http": "^5.3.11", "@smithy/types": "^4.13.0", "@smithy/util-retry": "^4.2.11", "tslib": "^2.6.2" }, "engines": { "node": ">=20.0.0" } }, "node_modules/@aws-sdk/nested-clients": { "version": "3.996.9", "resolved": "https://registry.npmjs.org/@aws-sdk/nested-clients/-/nested-clients-3.996.9.tgz", "integrity": "sha512-+RpVtpmQbbtzFOKhMlsRcXM/3f1Z49qTOHaA8gEpHOYruERmog6f2AUtf/oTRLCWjR9H2b3roqryV/hI7QMW8w==", "optional": true, "dependencies": { "@aws-crypto/sha256-browser": "5.2.0", "@aws-crypto/sha256-js": "5.2.0", "@aws-sdk/core": "^3.973.19", "@aws-sdk/middleware-host-header": "^3.972.7", "@aws-sdk/middleware-logger": "^3.972.7", "@aws-sdk/middleware-recursion-detection": "^3.972.7", "@aws-sdk/middleware-user-agent": "^3.972.20", "@aws-sdk/region-config-resolver": "^3.972.7", "@aws-sdk/types": "^3.973.5", "@aws-sdk/util-endpoints": "^3.996.4", "@aws-sdk/util-user-agent-browser": "^3.972.7", "@aws-sdk/util-user-agent-node": "^3.973.6", "@smithy/config-resolver": "^4.4.10", "@smithy/core": "^3.23.9", "@smithy/fetch-http-handler": "^5.3.13", "@smithy/hash-node": "^4.2.11", "@smithy/invalid-dependency": "^4.2.11", "@smithy/middleware-content-length": "^4.2.11", "@smithy/middleware-endpoint": "^4.4.23", "@smithy/middleware-retry": "^4.4.40", "@smithy/middleware-serde": "^4.2.12", "@smithy/middleware-stack": "^4.2.11", "@smithy/node-config-provider": "^4.3.11", "@smithy/node-http-handler": "^4.4.14", "@smithy/protocol-http": "^5.3.11", "@smithy/smithy-client": "^4.12.3", "@smithy/types": "^4.13.0", "@smithy/url-parser": "^4.2.11", "@smithy/util-base64": "^4.3.2", "@smithy/util-body-length-browser": "^4.2.2", "@smithy/util-body-length-node": "^4.2.3", "@smithy/util-defaults-mode-browser": "^4.3.39", "@smithy/util-defaults-mode-node": "^4.2.42", "@smithy/util-endpoints": "^3.3.2", "@smithy/util-middleware": "^4.2.11", "@smithy/util-retry": "^4.2.11", "@smithy/util-utf8": "^4.2.2", "tslib": "^2.6.2" }, "engines": { "node": ">=20.0.0" } }, "node_modules/@aws-sdk/region-config-resolver": { "version": "3.972.7", "resolved": "https://registry.npmjs.org/@aws-sdk/region-config-resolver/-/region-config-resolver-3.972.7.tgz", "integrity": "sha512-/Ev/6AI8bvt4HAAptzSjThGUMjcWaX3GX8oERkB0F0F9x2dLSBdgFDiyrRz3i0u0ZFZFQ1b28is4QhyqXTUsVA==", "optional": true, "dependencies": { "@aws-sdk/types": "^3.973.5", "@smithy/config-resolver": "^4.4.10", "@smithy/node-config-provider": "^4.3.11", "@smithy/types": "^4.13.0", "tslib": "^2.6.2" }, "engines": { "node": ">=20.0.0" } }, "node_modules/@aws-sdk/token-providers": { "version": "3.1008.0", "resolved": "https://registry.npmjs.org/@aws-sdk/token-providers/-/token-providers-3.1008.0.tgz", "integrity": "sha512-TulwlHQBWcJs668kNUDMZHN51DeLrDsYT59Ux4a/nbvr025gM6HjKJJ3LvnZccam7OS/ZKUVkWomCneRQKJbBg==", "optional": true, "dependencies": { "@aws-sdk/core": "^3.973.19", "@aws-sdk/nested-clients": "^3.996.9", "@aws-sdk/types": "^3.973.5", "@smithy/property-provider": "^4.2.11", "@smithy/shared-ini-file-loader": "^4.4.6", "@smithy/types": "^4.13.0", "tslib": "^2.6.2" }, "engines": { "node": ">=20.0.0" } }, "node_modules/@aws-sdk/types": { "version": "3.973.5", "resolved": "https://registry.npmjs.org/@aws-sdk/types/-/types-3.973.5.tgz", "integrity": "sha512-hl7BGwDCWsjH8NkZfx+HgS7H2LyM2lTMAI7ba9c8O0KqdBLTdNJivsHpqjg9rNlAlPyREb6DeDRXUl0s8uFdmQ==", "optional": true, "dependencies": { "@smithy/types": "^4.13.0", "tslib": "^2.6.2" }, "engines": { "node": ">=20.0.0" } }, "node_modules/@aws-sdk/util-endpoints": { "version": "3.996.4", "resolved": "https://registry.npmjs.org/@aws-sdk/util-endpoints/-/util-endpoints-3.996.4.tgz", "integrity": "sha512-Hek90FBmd4joCFj+Vc98KLJh73Zqj3s2W56gjAcTkrNLMDI5nIFkG9YpfcJiVI1YlE2Ne1uOQNe+IgQ/Vz2XRA==", "optional": true, "dependencies": { "@aws-sdk/types": "^3.973.5", "@smithy/types": "^4.13.0", "@smithy/url-parser": "^4.2.11", "@smithy/util-endpoints": "^3.3.2", "tslib": "^2.6.2" }, "engines": { "node": ">=20.0.0" } }, "node_modules/@aws-sdk/util-locate-window": { "version": "3.965.5", "resolved": "https://registry.npmjs.org/@aws-sdk/util-locate-window/-/util-locate-window-3.965.5.tgz", "integrity": "sha512-WhlJNNINQB+9qtLtZJcpQdgZw3SCDCpXdUJP7cToGwHbCWCnRckGlc6Bx/OhWwIYFNAn+FIydY8SZ0QmVu3xTQ==", "optional": true, "dependencies": { "tslib": "^2.6.2" }, "engines": { "node": ">=20.0.0" } }, "node_modules/@aws-sdk/util-user-agent-browser": { "version": "3.972.7", "resolved": "https://registry.npmjs.org/@aws-sdk/util-user-agent-browser/-/util-user-agent-browser-3.972.7.tgz", "integrity": "sha512-7SJVuvhKhMF/BkNS1n0QAJYgvEwYbK2QLKBrzDiwQGiTRU6Yf1f3nehTzm/l21xdAOtWSfp2uWSddPnP2ZtsVw==", "optional": true, "dependencies": { "@aws-sdk/types": "^3.973.5", "@smithy/types": "^4.13.0", "bowser": "^2.11.0", "tslib": "^2.6.2" } }, "node_modules/@aws-sdk/util-user-agent-node": { "version": "3.973.6", "resolved": "https://registry.npmjs.org/@aws-sdk/util-user-agent-node/-/util-user-agent-node-3.973.6.tgz", "integrity": "sha512-iF7G0prk7AvmOK64FcLvc/fW+Ty1H+vttajL7PvJFReU8urMxfYmynTTuFKDTA76Wgpq3FzTPKwabMQIXQHiXQ==", "optional": true, "dependencies": { "@aws-sdk/middleware-user-agent": "^3.972.20", "@aws-sdk/types": "^3.973.5", "@smithy/node-config-provider": "^4.3.11", "@smithy/types": "^4.13.0", "@smithy/util-config-provider": "^4.2.2", "tslib": "^2.6.2" }, "engines": { "node": ">=20.0.0" }, "peerDependencies": { "aws-crt": ">=1.0.0" }, "peerDependenciesMeta": { "aws-crt": { "optional": true } } }, "node_modules/@aws-sdk/xml-builder": { "version": "3.972.10", "resolved": "https://registry.npmjs.org/@aws-sdk/xml-builder/-/xml-builder-3.972.10.tgz", "integrity": "sha512-OnejAIVD+CxzyAUrVic7lG+3QRltyja9LoNqCE/1YVs8ichoTbJlVSaZ9iSMcnHLyzrSNtvaOGjSDRP+d/ouFA==", "optional": true, "dependencies": { "@smithy/types": "^4.13.0", "fast-xml-parser": "5.4.1", "tslib": "^2.6.2" }, "engines": { "node": ">=20.0.0" } }, "node_modules/@aws/lambda-invoke-store": { "version": "0.2.4", "resolved": "https://registry.npmjs.org/@aws/lambda-invoke-store/-/lambda-invoke-store-0.2.4.tgz", "integrity": "sha512-iY8yvjE0y651BixKNPgmv1WrQc+GZ142sb0z4gYnChDDY2YqI4P/jsSopBWrKfAt7LOJAkOXt7rC/hms+WclQQ==", "optional": true, "engines": { "node": ">=18.0.0" } }, "node_modules/@breejs/later": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/@breejs/later/-/later-4.2.0.tgz", "integrity": "sha512-EVMD0SgJtOuFeg0lAVbCwa+qeTKILb87jqvLyUtQswGD9+ce2nB52Y5zbTF1Hc0MDFfbydcMcxb47jSdhikVHA==", "engines": { "node": ">= 10" } }, "node_modules/@codemirror/autocomplete": { "version": "6.16.3", "resolved": "https://registry.npmjs.org/@codemirror/autocomplete/-/autocomplete-6.16.3.tgz", "integrity": "sha512-Vl/tIeRVVUCRDuOG48lttBasNQu8usGgXQawBXI7WJAiUDSFOfzflmEsZFZo48mAvAaa4FZ/4/yLLxFtdJaKYA==", "dev": true, "dependencies": { "@codemirror/language": "^6.0.0", "@codemirror/state": "^6.0.0", "@codemirror/view": "^6.17.0", "@lezer/common": "^1.0.0" }, "peerDependencies": { "@codemirror/language": "^6.0.0", "@codemirror/state": "^6.0.0", "@codemirror/view": "^6.0.0", "@lezer/common": "^1.0.0" } }, "node_modules/@codemirror/commands": { "version": "6.10.2", "resolved": "https://registry.npmjs.org/@codemirror/commands/-/commands-6.10.2.tgz", "integrity": "sha512-vvX1fsih9HledO1c9zdotZYUZnE4xV0m6i3m25s5DIfXofuprk6cRcLUZvSk3CASUbwjQX21tOGbkY2BH8TpnQ==", "dev": true, "license": "MIT", "dependencies": { "@codemirror/language": "^6.0.0", "@codemirror/state": "^6.4.0", "@codemirror/view": "^6.27.0", "@lezer/common": "^1.1.0" } }, "node_modules/@codemirror/lang-javascript": { "version": "6.2.5", "resolved": "https://registry.npmjs.org/@codemirror/lang-javascript/-/lang-javascript-6.2.5.tgz", "integrity": "sha512-zD4e5mS+50htS7F+TYjBPsiIFGanfVqg4HyUz6WNFikgOPf2BgKlx+TQedI1w6n/IqRBVBbBWmGFdLB/7uxO4A==", "dev": true, "license": "MIT", "dependencies": { "@codemirror/autocomplete": "^6.0.0", "@codemirror/language": "^6.6.0", "@codemirror/lint": "^6.0.0", "@codemirror/state": "^6.0.0", "@codemirror/view": "^6.17.0", "@lezer/common": "^1.0.0", "@lezer/javascript": "^1.0.0" } }, "node_modules/@codemirror/lang-yaml": { "version": "6.1.2", "resolved": "https://registry.npmjs.org/@codemirror/lang-yaml/-/lang-yaml-6.1.2.tgz", "integrity": "sha512-dxrfG8w5Ce/QbT7YID7mWZFKhdhsaTNOYjOkSIMt1qmC4VQnXSDSYVHHHn8k6kJUfIhtLo8t1JJgltlxWdsITw==", "dev": true, "license": "MIT", "dependencies": { "@codemirror/autocomplete": "^6.0.0", "@codemirror/language": "^6.0.0", "@codemirror/state": "^6.0.0", "@lezer/common": "^1.2.0", "@lezer/highlight": "^1.2.0", "@lezer/lr": "^1.0.0", "@lezer/yaml": "^1.0.0" } }, "node_modules/@codemirror/language": { "version": "6.12.2", "resolved": "https://registry.npmjs.org/@codemirror/language/-/language-6.12.2.tgz", "integrity": "sha512-jEPmz2nGGDxhRTg3lTpzmIyGKxz3Gp3SJES4b0nAuE5SWQoKdT5GoQ69cwMmFd+wvFUhYirtDTr0/DRHpQAyWg==", "dev": true, "license": "MIT", "dependencies": { "@codemirror/state": "^6.0.0", "@codemirror/view": "^6.23.0", "@lezer/common": "^1.5.0", "@lezer/highlight": "^1.0.0", "@lezer/lr": "^1.0.0", "style-mod": "^4.0.0" } }, "node_modules/@codemirror/lint": { "version": "6.8.1", "resolved": "https://registry.npmjs.org/@codemirror/lint/-/lint-6.8.1.tgz", "integrity": "sha512-IZ0Y7S4/bpaunwggW2jYqwLuHj0QtESf5xcROewY6+lDNwZ/NzvR4t+vpYgg9m7V8UXLPYqG+lu3DF470E5Oxg==", "dev": true, "dependencies": { "@codemirror/state": "^6.0.0", "@codemirror/view": "^6.0.0", "crelt": "^1.0.5" } }, "node_modules/@codemirror/state": { "version": "6.5.4", "resolved": "https://registry.npmjs.org/@codemirror/state/-/state-6.5.4.tgz", "integrity": "sha512-8y7xqG/hpB53l25CIoit9/ngxdfoG+fx+V3SHBrinnhOtLvKHRyAJJuHzkWrR4YXXLX8eXBsejgAAxHUOdW1yw==", "dev": true, "license": "MIT", "dependencies": { "@marijn/find-cluster-break": "^1.0.0" } }, "node_modules/@codemirror/view": { "version": "6.39.16", "resolved": "https://registry.npmjs.org/@codemirror/view/-/view-6.39.16.tgz", "integrity": "sha512-m6S22fFpKtOWhq8HuhzsI1WzUP/hB9THbDj0Tl5KX4gbO6Y91hwBl7Yky33NdvB6IffuRFiBxf1R8kJMyXmA4Q==", "dev": true, "license": "MIT", "dependencies": { "@codemirror/state": "^6.5.0", "crelt": "^1.0.6", "style-mod": "^4.1.0", "w3c-keyname": "^2.2.4" } }, "node_modules/@esbuild/aix-ppc64": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.27.4.tgz", "integrity": "sha512-cQPwL2mp2nSmHHJlCyoXgHGhbEPMrEEU5xhkcy3Hs/O7nGZqEpZ2sUtLaL9MORLtDfRvVl2/3PAuEkYZH0Ty8Q==", "cpu": [ "ppc64" ], "dev": true, "license": "MIT", "optional": true, "os": [ "aix" ], "engines": { "node": ">=18" } }, "node_modules/@esbuild/android-arm": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.27.4.tgz", "integrity": "sha512-X9bUgvxiC8CHAGKYufLIHGXPJWnr0OCdR0anD2e21vdvgCI8lIfqFbnoeOz7lBjdrAGUhqLZLcQo6MLhTO2DKQ==", "cpu": [ "arm" ], "dev": true, "license": "MIT", "optional": true, "os": [ "android" ], "engines": { "node": ">=18" } }, "node_modules/@esbuild/android-arm64": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.27.4.tgz", "integrity": "sha512-gdLscB7v75wRfu7QSm/zg6Rx29VLdy9eTr2t44sfTW7CxwAtQghZ4ZnqHk3/ogz7xao0QAgrkradbBzcqFPasw==", "cpu": [ "arm64" ], "dev": true, "license": "MIT", "optional": true, "os": [ "android" ], "engines": { "node": ">=18" } }, "node_modules/@esbuild/android-x64": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.27.4.tgz", "integrity": "sha512-PzPFnBNVF292sfpfhiyiXCGSn9HZg5BcAz+ivBuSsl6Rk4ga1oEXAamhOXRFyMcjwr2DVtm40G65N3GLeH1Lvw==", "cpu": [ "x64" ], "dev": true, "license": "MIT", "optional": true, "os": [ "android" ], "engines": { "node": ">=18" } }, "node_modules/@esbuild/darwin-arm64": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.27.4.tgz", "integrity": "sha512-b7xaGIwdJlht8ZFCvMkpDN6uiSmnxxK56N2GDTMYPr2/gzvfdQN8rTfBsvVKmIVY/X7EM+/hJKEIbbHs9oA4tQ==", "cpu": [ "arm64" ], "dev": true, "license": "MIT", "optional": true, "os": [ "darwin" ], "engines": { "node": ">=18" } }, "node_modules/@esbuild/darwin-x64": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.27.4.tgz", "integrity": "sha512-sR+OiKLwd15nmCdqpXMnuJ9W2kpy0KigzqScqHI3Hqwr7IXxBp3Yva+yJwoqh7rE8V77tdoheRYataNKL4QrPw==", "cpu": [ "x64" ], "dev": true, "license": "MIT", "optional": true, "os": [ "darwin" ], "engines": { "node": ">=18" } }, "node_modules/@esbuild/freebsd-arm64": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.27.4.tgz", "integrity": "sha512-jnfpKe+p79tCnm4GVav68A7tUFeKQwQyLgESwEAUzyxk/TJr4QdGog9sqWNcUbr/bZt/O/HXouspuQDd9JxFSw==", "cpu": [ "arm64" ], "dev": true, "license": "MIT", "optional": true, "os": [ "freebsd" ], "engines": { "node": ">=18" } }, "node_modules/@esbuild/freebsd-x64": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.27.4.tgz", "integrity": "sha512-2kb4ceA/CpfUrIcTUl1wrP/9ad9Atrp5J94Lq69w7UwOMolPIGrfLSvAKJp0RTvkPPyn6CIWrNy13kyLikZRZQ==", "cpu": [ "x64" ], "dev": true, "license": "MIT", "optional": true, "os": [ "freebsd" ], "engines": { "node": ">=18" } }, "node_modules/@esbuild/linux-arm": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.27.4.tgz", "integrity": "sha512-aBYgcIxX/wd5n2ys0yESGeYMGF+pv6g0DhZr3G1ZG4jMfruU9Tl1i2Z+Wnj9/KjGz1lTLCcorqE2viePZqj4Eg==", "cpu": [ "arm" ], "dev": true, "license": "MIT", "optional": true, "os": [ "linux" ], "engines": { "node": ">=18" } }, "node_modules/@esbuild/linux-arm64": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.27.4.tgz", "integrity": "sha512-7nQOttdzVGth1iz57kxg9uCz57dxQLHWxopL6mYuYthohPKEK0vU0C3O21CcBK6KDlkYVcnDXY099HcCDXd9dA==", "cpu": [ "arm64" ], "dev": true, "license": "MIT", "optional": true, "os": [ "linux" ], "engines": { "node": ">=18" } }, "node_modules/@esbuild/linux-ia32": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.27.4.tgz", "integrity": "sha512-oPtixtAIzgvzYcKBQM/qZ3R+9TEUd1aNJQu0HhGyqtx6oS7qTpvjheIWBbes4+qu1bNlo2V4cbkISr8q6gRBFA==", "cpu": [ "ia32" ], "dev": true, "license": "MIT", "optional": true, "os": [ "linux" ], "engines": { "node": ">=18" } }, "node_modules/@esbuild/linux-loong64": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.27.4.tgz", "integrity": "sha512-8mL/vh8qeCoRcFH2nM8wm5uJP+ZcVYGGayMavi8GmRJjuI3g1v6Z7Ni0JJKAJW+m0EtUuARb6Lmp4hMjzCBWzA==", "cpu": [ "loong64" ], "dev": true, "license": "MIT", "optional": true, "os": [ "linux" ], "engines": { "node": ">=18" } }, "node_modules/@esbuild/linux-mips64el": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.27.4.tgz", "integrity": "sha512-1RdrWFFiiLIW7LQq9Q2NES+HiD4NyT8Itj9AUeCl0IVCA459WnPhREKgwrpaIfTOe+/2rdntisegiPWn/r/aAw==", "cpu": [ "mips64el" ], "dev": true, "license": "MIT", "optional": true, "os": [ "linux" ], "engines": { "node": ">=18" } }, "node_modules/@esbuild/linux-ppc64": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.27.4.tgz", "integrity": "sha512-tLCwNG47l3sd9lpfyx9LAGEGItCUeRCWeAx6x2Jmbav65nAwoPXfewtAdtbtit/pJFLUWOhpv0FpS6GQAmPrHA==", "cpu": [ "ppc64" ], "dev": true, "license": "MIT", "optional": true, "os": [ "linux" ], "engines": { "node": ">=18" } }, "node_modules/@esbuild/linux-riscv64": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.27.4.tgz", "integrity": "sha512-BnASypppbUWyqjd1KIpU4AUBiIhVr6YlHx/cnPgqEkNoVOhHg+YiSVxM1RLfiy4t9cAulbRGTNCKOcqHrEQLIw==", "cpu": [ "riscv64" ], "dev": true, "license": "MIT", "optional": true, "os": [ "linux" ], "engines": { "node": ">=18" } }, "node_modules/@esbuild/linux-s390x": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.27.4.tgz", "integrity": "sha512-+eUqgb/Z7vxVLezG8bVB9SfBie89gMueS+I0xYh2tJdw3vqA/0ImZJ2ROeWwVJN59ihBeZ7Tu92dF/5dy5FttA==", "cpu": [ "s390x" ], "dev": true, "license": "MIT", "optional": true, "os": [ "linux" ], "engines": { "node": ">=18" } }, "node_modules/@esbuild/linux-x64": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.27.4.tgz", "integrity": "sha512-S5qOXrKV8BQEzJPVxAwnryi2+Iq5pB40gTEIT69BQONqR7JH1EPIcQ/Uiv9mCnn05jff9umq/5nqzxlqTOg9NA==", "cpu": [ "x64" ], "dev": true, "license": "MIT", "optional": true, "os": [ "linux" ], "engines": { "node": ">=18" } }, "node_modules/@esbuild/netbsd-arm64": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.27.4.tgz", "integrity": "sha512-xHT8X4sb0GS8qTqiwzHqpY00C95DPAq7nAwX35Ie/s+LO9830hrMd3oX0ZMKLvy7vsonee73x0lmcdOVXFzd6Q==", "cpu": [ "arm64" ], "dev": true, "optional": true, "os": [ "netbsd" ], "engines": { "node": ">=18" } }, "node_modules/@esbuild/netbsd-x64": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.27.4.tgz", "integrity": "sha512-RugOvOdXfdyi5Tyv40kgQnI0byv66BFgAqjdgtAKqHoZTbTF2QqfQrFwa7cHEORJf6X2ht+l9ABLMP0dnKYsgg==", "cpu": [ "arm64" ], "dev": true, "license": "MIT", "optional": true, "os": [ "netbsd" ], "engines": { "node": ">=18" } }, "node_modules/@esbuild/openbsd-arm64": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.27.4.tgz", "integrity": "sha512-2MyL3IAaTX+1/qP0O1SwskwcwCoOI4kV2IBX1xYnDDqthmq5ArrW94qSIKCAuRraMgPOmG0RDTA74mzYNQA9ow==", "cpu": [ "arm64" ], "dev": true, "license": "MIT", "optional": true, "os": [ "openbsd" ], "engines": { "node": ">=18" } }, "node_modules/@esbuild/openbsd-x64": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.27.4.tgz", "integrity": "sha512-u8fg/jQ5aQDfsnIV6+KwLOf1CmJnfu1ShpwqdwC0uA7ZPwFws55Ngc12vBdeUdnuWoQYx/SOQLGDcdlfXhYmXQ==", "cpu": [ "x64" ], "dev": true, "license": "MIT", "optional": true, "os": [ "netbsd" ], "engines": { "node": ">=18" } }, "node_modules/@esbuild/openharmony-arm64": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/openharmony-arm64/-/openharmony-arm64-0.27.4.tgz", "integrity": "sha512-JkTZrl6VbyO8lDQO3yv26nNr2RM2yZzNrNHEsj9bm6dOwwu9OYN28CjzZkH57bh4w0I2F7IodpQvUAEd1mbWXg==", "cpu": [ "arm64" ], "dev": true, "license": "MIT", "optional": true, "os": [ "openharmony" ], "engines": { "node": ">=18" } }, "node_modules/@esbuild/sunos-x64": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.27.4.tgz", "integrity": "sha512-/gOzgaewZJfeJTlsWhvUEmUG4tWEY2Spp5M20INYRg2ZKl9QPO3QEEgPeRtLjEWSW8FilRNacPOg8R1uaYkA6g==", "cpu": [ "x64" ], "dev": true, "license": "MIT", "optional": true, "os": [ "sunos" ], "engines": { "node": ">=18" } }, "node_modules/@esbuild/win32-arm64": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.27.4.tgz", "integrity": "sha512-Z9SExBg2y32smoDQdf1HRwHRt6vAHLXcxD2uGgO/v2jK7Y718Ix4ndsbNMU/+1Qiem9OiOdaqitioZwxivhXYg==", "cpu": [ "arm64" ], "dev": true, "license": "MIT", "optional": true, "os": [ "win32" ], "engines": { "node": ">=18" } }, "node_modules/@esbuild/win32-ia32": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.27.4.tgz", "integrity": "sha512-DAyGLS0Jz5G5iixEbMHi5KdiApqHBWMGzTtMiJ72ZOLhbu/bzxgAe8Ue8CTS3n3HbIUHQz/L51yMdGMeoxXNJw==", "cpu": [ "ia32" ], "dev": true, "license": "MIT", "optional": true, "os": [ "win32" ], "engines": { "node": ">=18" } }, "node_modules/@esbuild/win32-x64": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.27.4.tgz", "integrity": "sha512-+knoa0BDoeXgkNvvV1vvbZX4+hizelrkwmGJBdT17t8FNPwG2lKemmuMZlmaNQ3ws3DKKCxpb4zRZEIp3UxFCg==", "cpu": [ "x64" ], "dev": true, "license": "MIT", "optional": true, "os": [ "win32" ], "engines": { "node": ">=18" } }, "node_modules/@eslint-community/eslint-utils": { "version": "4.9.1", "resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.9.1.tgz", "integrity": "sha512-phrYmNiYppR7znFEdqgfWHXR6NCkZEK7hwWDHZUjit/2/U0r6XvkDl0SYnoM51Hq7FhCGdLDT6zxCCOY1hexsQ==", "dev": true, "license": "MIT", "dependencies": { "eslint-visitor-keys": "^3.4.3" }, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" }, "funding": { "url": "https://opencollective.com/eslint" }, "peerDependencies": { "eslint": "^6.0.0 || ^7.0.0 || >=8.0.0" } }, "node_modules/@eslint-community/regexpp": { "version": "4.12.2", "resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.12.2.tgz", "integrity": "sha512-EriSTlt5OC9/7SXkRSCAhfSxxoSUgBm33OH+IkwbdpgoqsSsUg7y3uh+IICI/Qg4BBWr3U2i39RpmycbxMq4ew==", "dev": true, "engines": { "node": "^12.0.0 || ^14.0.0 || >=16.0.0" } }, "node_modules/@eslint/config-array": { "version": "0.23.3", "resolved": "https://registry.npmjs.org/@eslint/config-array/-/config-array-0.23.3.tgz", "integrity": "sha512-j+eEWmB6YYLwcNOdlwQ6L2OsptI/LO6lNBuLIqe5R7RetD658HLoF+Mn7LzYmAWWNNzdC6cqP+L6r8ujeYXWLw==", "dev": true, "license": "Apache-2.0", "dependencies": { "@eslint/object-schema": "^3.0.3", "debug": "^4.3.1", "minimatch": "^10.2.4" }, "engines": { "node": "^20.19.0 || ^22.13.0 || >=24" } }, "node_modules/@eslint/config-array/node_modules/balanced-match": { "version": "4.0.4", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-4.0.4.tgz", "integrity": "sha512-BLrgEcRTwX2o6gGxGOCNyMvGSp35YofuYzw9h1IMTRmKqttAZZVU67bdb9Pr2vUHA8+j3i2tJfjO6C6+4myGTA==", "dev": true, "license": "MIT", "engines": { "node": "18 || 20 || >=22" } }, "node_modules/@eslint/config-array/node_modules/brace-expansion": { "version": "5.0.4", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.4.tgz", "integrity": "sha512-h+DEnpVvxmfVefa4jFbCf5HdH5YMDXRsmKflpf1pILZWRFlTbJpxeU55nJl4Smt5HQaGzg1o6RHFPJaOqnmBDg==", "dev": true, "license": "MIT", "dependencies": { "balanced-match": "^4.0.2" }, "engines": { "node": "18 || 20 || >=22" } }, "node_modules/@eslint/config-array/node_modules/minimatch": { "version": "10.2.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.2.4.tgz", "integrity": "sha512-oRjTw/97aTBN0RHbYCdtF1MQfvusSIBQM0IZEgzl6426+8jSC0nF1a/GmnVLpfB9yyr6g6FTqWqiZVbxrtaCIg==", "dev": true, "license": "BlueOak-1.0.0", "dependencies": { "brace-expansion": "^5.0.2" }, "engines": { "node": "18 || 20 || >=22" }, "funding": { "url": "https://github.com/sponsors/isaacs" } }, "node_modules/@eslint/config-helpers": { "version": "0.5.3", "resolved": "https://registry.npmjs.org/@eslint/config-helpers/-/config-helpers-0.5.3.tgz", "integrity": "sha512-lzGN0onllOZCGroKJmRwY6QcEHxbjBw1gwB8SgRSqK8YbbtEXMvKynsXc3553ckIEBxsbMBU7oOZXKIPGZNeZw==", "dev": true, "license": "Apache-2.0", "dependencies": { "@eslint/core": "^1.1.1" }, "engines": { "node": "^20.19.0 || ^22.13.0 || >=24" } }, "node_modules/@eslint/core": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/@eslint/core/-/core-1.1.1.tgz", "integrity": "sha512-QUPblTtE51/7/Zhfv8BDwO0qkkzQL7P/aWWbqcf4xWLEYn1oKjdO0gglQBB4GAsu7u6wjijbCmzsUTy6mnk6oQ==", "dev": true, "license": "Apache-2.0", "dependencies": { "@types/json-schema": "^7.0.15" }, "engines": { "node": "^20.19.0 || ^22.13.0 || >=24" } }, "node_modules/@eslint/js": { "version": "10.0.1", "resolved": "https://registry.npmjs.org/@eslint/js/-/js-10.0.1.tgz", "integrity": "sha512-zeR9k5pd4gxjZ0abRoIaxdc7I3nDktoXZk2qOv9gCNWx3mVwEn32VRhyLaRsDiJjTs0xq/T8mfPtyuXu7GWBcA==", "dev": true, "license": "MIT", "engines": { "node": "^20.19.0 || ^22.13.0 || >=24" }, "funding": { "url": "https://eslint.org/donate" }, "peerDependencies": { "eslint": "^10.0.0" }, "peerDependenciesMeta": { "eslint": { "optional": true } } }, "node_modules/@eslint/object-schema": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/@eslint/object-schema/-/object-schema-3.0.3.tgz", "integrity": "sha512-iM869Pugn9Nsxbh/YHRqYiqd23AmIbxJOcpUMOuWCVNdoQJ5ZtwL6h3t0bcZzJUlC3Dq9jCFCESBZnX0GTv7iQ==", "dev": true, "license": "Apache-2.0", "engines": { "node": "^20.19.0 || ^22.13.0 || >=24" } }, "node_modules/@eslint/plugin-kit": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/@eslint/plugin-kit/-/plugin-kit-0.6.1.tgz", "integrity": "sha512-iH1B076HoAshH1mLpHMgwdGeTs0CYwL0SPMkGuSebZrwBp16v415e9NZXg2jtrqPVQjf6IANe2Vtlr5KswtcZQ==", "dev": true, "license": "Apache-2.0", "dependencies": { "@humanwhocodes/object-schema": "^2.0.3", "debug": "^4.3.1", "minimatch": "^3.0.5" }, "engines": { "node": "^20.19.0 || ^22.13.0 || >=24" } }, "node_modules/@eslint/plugin-kit/node_modules/brace-expansion": { "version": "1.1.12", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.12.tgz", "integrity": "sha512-9T9UjW3r0UW5c1Q7GTwllptXwhvYmEzFhzMfZ9H7FQWt+uZePjZPjBP/W1ZEyZ1twGWom5/56TF4lPcqjnDHcg==", "dev": true, "license": "MIT", "dependencies": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" } }, "node_modules/@eslint/plugin-kit/node_modules/minimatch": { "version": "3.1.5", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.5.tgz", "integrity": "sha512-VgjWUsnnT6n+NUk6eZq77zeFdpW2LWDzP6zFGrCbHXiYNul5Dzqk2HHQ5uFH2DNW5Xbp8+jVzaeNt94ssEEl4w==", "dev": true, "license": "ISC", "dependencies": { "brace-expansion": "^1.1.7" }, "engines": { "node": "*" } }, "node_modules/@humanfs/core": { "version": "0.19.1", "resolved": "https://registry.npmjs.org/@humanfs/core/-/core-0.19.1.tgz", "integrity": "sha512-5DyQ4+1JEUzejeK1JGICcideyfUbGixgS9jNgex5nqkW+cY7WZhxBigmieN5Qnw9ZosSNVC9KQKyb+GUaGyKUA==", "dev": true, "license": "Apache-2.0", "engines": { "node": ">=18.18.0" } }, "node_modules/@humanfs/node": { "version": "0.16.7", "resolved": "https://registry.npmjs.org/@humanfs/node/-/node-0.16.7.tgz", "integrity": "sha512-/zUx+yOsIrG4Y43Eh2peDeKCxlRt/gET6aHfaKpuq267qXdYDFViVHfMaLyygZOnl0kGWxFIgsBy8QFuTLUXEQ==", "dev": true, "license": "Apache-2.0", "dependencies": { "@humanfs/core": "^0.19.1", "@humanwhocodes/retry": "^0.4.0" }, "engines": { "node": ">=18.18.0" } }, "node_modules/@humanwhocodes/module-importer": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/@humanwhocodes/module-importer/-/module-importer-1.0.1.tgz", "integrity": "sha512-bxveV4V8v5Yb4ncFTT3rPSgZBOpCkjfK0y4oVVVJwIuDVBRMDXrPyXRL988i5ap9m9bnyEEjWfm5WkBmtffLfA==", "dev": true, "engines": { "node": ">=12.22" }, "funding": { "type": "github", "url": "https://github.com/sponsors/nzakas" } }, "node_modules/@humanwhocodes/object-schema": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-2.0.3.tgz", "integrity": "sha512-93zYdMES/c1D69yZiKDBj0V24vqNzB/koF26KPaagAfd3P/4gUlh3Dys5ogAK+Exi9QyzlD8x/08Zt7wIKcDcA==", "deprecated": "Use @eslint/object-schema instead", "dev": true }, "node_modules/@humanwhocodes/retry": { "version": "0.4.3", "resolved": "https://registry.npmjs.org/@humanwhocodes/retry/-/retry-0.4.3.tgz", "integrity": "sha512-bV0Tgo9K4hfPCek+aMAn81RppFKv2ySDQeMoSZuvTASywNTnVJCArCZE2FWqpvIatKu7VMRLWlR1EazvVhDyhQ==", "dev": true, "license": "Apache-2.0", "engines": { "node": ">=18.18" }, "funding": { "type": "github", "url": "https://github.com/sponsors/nzakas" } }, "node_modules/@jridgewell/gen-mapping": { "version": "0.3.13", "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.13.tgz", "integrity": "sha512-2kkt/7niJ6MgEPxF0bYdQ6etZaA+fQvDcLKckhy1yIQOzaoKjBBjSj63/aLVjYE3qhRt5dvM+uUyfCg6UKCBbA==", "dev": true, "license": "MIT", "dependencies": { "@jridgewell/sourcemap-codec": "^1.5.0", "@jridgewell/trace-mapping": "^0.3.24" } }, "node_modules/@jridgewell/remapping": { "version": "2.3.5", "resolved": "https://registry.npmjs.org/@jridgewell/remapping/-/remapping-2.3.5.tgz", "integrity": "sha512-LI9u/+laYG4Ds1TDKSJW2YPrIlcVYOwi2fUC6xB43lueCjgxV4lffOCZCtYFiH6TNOX+tQKXx97T4IKHbhyHEQ==", "dev": true, "license": "MIT", "dependencies": { "@jridgewell/gen-mapping": "^0.3.5", "@jridgewell/trace-mapping": "^0.3.24" } }, "node_modules/@jridgewell/resolve-uri": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.2.tgz", "integrity": "sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==", "dev": true, "license": "MIT", "engines": { "node": ">=6.0.0" } }, "node_modules/@jridgewell/sourcemap-codec": { "version": "1.5.5", "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.5.tgz", "integrity": "sha512-cYQ9310grqxueWbl+WuIUIaiUaDcj7WOq5fVhEljNVgRfOUhY9fy2zTvfoqWsnebh8Sl70VScFbICvJnLKB0Og==", "dev": true, "license": "MIT" }, "node_modules/@jridgewell/trace-mapping": { "version": "0.3.31", "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.31.tgz", "integrity": "sha512-zzNR+SdQSDJzc8joaeP8QQoCQr8NuYx2dIIytl1QeBEZHJ9uW6hebsrYgbz8hJwUQao3TWCMtmfV8Nu1twOLAw==", "dev": true, "license": "MIT", "dependencies": { "@jridgewell/resolve-uri": "^3.1.0", "@jridgewell/sourcemap-codec": "^1.4.14" } }, "node_modules/@koa/bodyparser": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/@koa/bodyparser/-/bodyparser-5.1.2.tgz", "integrity": "sha512-eGJm9/66iUX+LUH03Cz0e94unbSKrmSPCick4MO5UorAAomcjC5Kl+SkoZ6CSyPew3neMYjj7n+djnlGYBSJAg==", "dependencies": { "co-body": "^6.1.0", "lodash.merge": "^4.6.2", "type-is": "^1.6.18" }, "engines": { "node": ">= 16" }, "peerDependencies": { "koa": "^2.14.1" } }, "node_modules/@koa/router": { "version": "13.1.1", "resolved": "https://registry.npmjs.org/@koa/router/-/router-13.1.1.tgz", "integrity": "sha512-JQEuMANYRVHs7lm7KY9PCIjkgJk73h4m4J+g2mkw2Vo1ugPZ17UJVqEH8F+HeAdjKz5do1OaLe7ArDz+z308gw==", "deprecated": "Please upgrade to v15 or higher. All reported bugs in this version are fixed in newer releases, dependencies have been updated, and security has been improved.", "dependencies": { "debug": "^4.4.1", "http-errors": "^2.0.0", "koa-compose": "^4.1.0", "path-to-regexp": "^6.3.0" }, "engines": { "node": ">= 18" } }, "node_modules/@lezer/common": { "version": "1.5.1", "resolved": "https://registry.npmjs.org/@lezer/common/-/common-1.5.1.tgz", "integrity": "sha512-6YRVG9vBkaY7p1IVxL4s44n5nUnaNnGM2/AckNgYOnxTG2kWh1vR8BMxPseWPjRNpb5VtXnMpeYAEAADoRV1Iw==", "dev": true, "license": "MIT" }, "node_modules/@lezer/highlight": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/@lezer/highlight/-/highlight-1.2.3.tgz", "integrity": "sha512-qXdH7UqTvGfdVBINrgKhDsVTJTxactNNxLk7+UMwZhU13lMHaOBlJe9Vqp907ya56Y3+ed2tlqzys7jDkTmW0g==", "dev": true, "license": "MIT", "dependencies": { "@lezer/common": "^1.3.0" } }, "node_modules/@lezer/javascript": { "version": "1.5.4", "resolved": "https://registry.npmjs.org/@lezer/javascript/-/javascript-1.5.4.tgz", "integrity": "sha512-vvYx3MhWqeZtGPwDStM2dwgljd5smolYD2lR2UyFcHfxbBQebqx8yjmFmxtJ/E6nN6u1D9srOiVWm3Rb4tmcUA==", "dev": true, "license": "MIT", "dependencies": { "@lezer/common": "^1.2.0", "@lezer/highlight": "^1.1.3", "@lezer/lr": "^1.3.0" } }, "node_modules/@lezer/lr": { "version": "1.4.8", "resolved": "https://registry.npmjs.org/@lezer/lr/-/lr-1.4.8.tgz", "integrity": "sha512-bPWa0Pgx69ylNlMlPvBPryqeLYQjyJjqPx+Aupm5zydLIF3NE+6MMLT8Yi23Bd9cif9VS00aUebn+6fDIGBcDA==", "dev": true, "license": "MIT", "dependencies": { "@lezer/common": "^1.0.0" } }, "node_modules/@lezer/yaml": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/@lezer/yaml/-/yaml-1.0.4.tgz", "integrity": "sha512-2lrrHqxalACEbxIbsjhqGpSW8kWpUKuY6RHgnSAFZa6qK62wvnPxA8hGOwOoDbwHcOFs5M4o27mjGu+P7TvBmw==", "dev": true, "license": "MIT", "dependencies": { "@lezer/common": "^1.2.0", "@lezer/highlight": "^1.0.0", "@lezer/lr": "^1.4.0" } }, "node_modules/@marijn/find-cluster-break": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/@marijn/find-cluster-break/-/find-cluster-break-1.0.2.tgz", "integrity": "sha512-l0h88YhZFyKdXIFNfSWpyjStDjGHwZ/U7iobcK1cQQD8sejsONdQtTVU+1wVN1PBw40PiiHB1vA5S7VTfQiP9g==", "dev": true, "license": "MIT" }, "node_modules/@mongodb-js/saslprep": { "version": "1.4.6", "resolved": "https://registry.npmjs.org/@mongodb-js/saslprep/-/saslprep-1.4.6.tgz", "integrity": "sha512-y+x3H1xBZd38n10NZF/rEBlvDOOMQ6LKUTHqr8R9VkJ+mmQOYtJFxIlkkK8fZrtOiL6VixbOBWMbZGBdal3Z1g==", "optional": true, "dependencies": { "sparse-bitfield": "^3.0.3" } }, "node_modules/@parcel/watcher": { "version": "2.5.6", "resolved": "https://registry.npmjs.org/@parcel/watcher/-/watcher-2.5.6.tgz", "integrity": "sha512-tmmZ3lQxAe/k/+rNnXQRawJ4NjxO2hqiOLTHvWchtGZULp4RyFeh6aU4XdOYBFe2KE1oShQTv4AblOs2iOrNnQ==", "dev": true, "hasInstallScript": true, "license": "MIT", "dependencies": { "detect-libc": "^2.0.3", "is-glob": "^4.0.3", "node-addon-api": "^7.0.0", "picomatch": "^4.0.3" }, "engines": { "node": ">= 10.0.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/parcel" }, "optionalDependencies": { "@parcel/watcher-android-arm64": "2.5.6", "@parcel/watcher-darwin-arm64": "2.5.6", "@parcel/watcher-darwin-x64": "2.5.6", "@parcel/watcher-freebsd-x64": "2.5.6", "@parcel/watcher-linux-arm-glibc": "2.5.6", "@parcel/watcher-linux-arm-musl": "2.5.6", "@parcel/watcher-linux-arm64-glibc": "2.5.6", "@parcel/watcher-linux-arm64-musl": "2.5.6", "@parcel/watcher-linux-x64-glibc": "2.5.6", "@parcel/watcher-linux-x64-musl": "2.5.6", "@parcel/watcher-win32-arm64": "2.5.6", "@parcel/watcher-win32-ia32": "2.5.6", "@parcel/watcher-win32-x64": "2.5.6" } }, "node_modules/@parcel/watcher-android-arm64": { "version": "2.5.6", "resolved": "https://registry.npmjs.org/@parcel/watcher-android-arm64/-/watcher-android-arm64-2.5.6.tgz", "integrity": "sha512-YQxSS34tPF/6ZG7r/Ih9xy+kP/WwediEUsqmtf0cuCV5TPPKw/PQHRhueUo6JdeFJaqV3pyjm0GdYjZotbRt/A==", "cpu": [ "arm64" ], "dev": true, "license": "MIT", "optional": true, "os": [ "android" ], "engines": { "node": ">= 10.0.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/parcel" } }, "node_modules/@parcel/watcher-darwin-arm64": { "version": "2.5.6", "resolved": "https://registry.npmjs.org/@parcel/watcher-darwin-arm64/-/watcher-darwin-arm64-2.5.6.tgz", "integrity": "sha512-Z2ZdrnwyXvvvdtRHLmM4knydIdU9adO3D4n/0cVipF3rRiwP+3/sfzpAwA/qKFL6i1ModaabkU7IbpeMBgiVEA==", "cpu": [ "arm64" ], "dev": true, "license": "MIT", "optional": true, "os": [ "darwin" ], "engines": { "node": ">= 10.0.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/parcel" } }, "node_modules/@parcel/watcher-darwin-x64": { "version": "2.5.6", "resolved": "https://registry.npmjs.org/@parcel/watcher-darwin-x64/-/watcher-darwin-x64-2.5.6.tgz", "integrity": "sha512-HgvOf3W9dhithcwOWX9uDZyn1lW9R+7tPZ4sug+NGrGIo4Rk1hAXLEbcH1TQSqxts0NYXXlOWqVpvS1SFS4fRg==", "cpu": [ "x64" ], "dev": true, "license": "MIT", "optional": true, "os": [ "darwin" ], "engines": { "node": ">= 10.0.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/parcel" } }, "node_modules/@parcel/watcher-freebsd-x64": { "version": "2.5.6", "resolved": "https://registry.npmjs.org/@parcel/watcher-freebsd-x64/-/watcher-freebsd-x64-2.5.6.tgz", "integrity": "sha512-vJVi8yd/qzJxEKHkeemh7w3YAn6RJCtYlE4HPMoVnCpIXEzSrxErBW5SJBgKLbXU3WdIpkjBTeUNtyBVn8TRng==", "cpu": [ "x64" ], "dev": true, "license": "MIT", "optional": true, "os": [ "freebsd" ], "engines": { "node": ">= 10.0.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/parcel" } }, "node_modules/@parcel/watcher-linux-arm-glibc": { "version": "2.5.6", "resolved": "https://registry.npmjs.org/@parcel/watcher-linux-arm-glibc/-/watcher-linux-arm-glibc-2.5.6.tgz", "integrity": "sha512-9JiYfB6h6BgV50CCfasfLf/uvOcJskMSwcdH1PHH9rvS1IrNy8zad6IUVPVUfmXr+u+Km9IxcfMLzgdOudz9EQ==", "cpu": [ "arm" ], "dev": true, "license": "MIT", "optional": true, "os": [ "linux" ], "engines": { "node": ">= 10.0.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/parcel" } }, "node_modules/@parcel/watcher-linux-arm-musl": { "version": "2.5.6", "resolved": "https://registry.npmjs.org/@parcel/watcher-linux-arm-musl/-/watcher-linux-arm-musl-2.5.6.tgz", "integrity": "sha512-Ve3gUCG57nuUUSyjBq/MAM0CzArtuIOxsBdQ+ftz6ho8n7s1i9E1Nmk/xmP323r2YL0SONs1EuwqBp2u1k5fxg==", "cpu": [ "arm" ], "dev": true, "license": "MIT", "optional": true, "os": [ "linux" ], "engines": { "node": ">= 10.0.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/parcel" } }, "node_modules/@parcel/watcher-linux-arm64-glibc": { "version": "2.5.6", "resolved": "https://registry.npmjs.org/@parcel/watcher-linux-arm64-glibc/-/watcher-linux-arm64-glibc-2.5.6.tgz", "integrity": "sha512-f2g/DT3NhGPdBmMWYoxixqYr3v/UXcmLOYy16Bx0TM20Tchduwr4EaCbmxh1321TABqPGDpS8D/ggOTaljijOA==", "cpu": [ "arm64" ], "dev": true, "license": "MIT", "optional": true, "os": [ "linux" ], "engines": { "node": ">= 10.0.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/parcel" } }, "node_modules/@parcel/watcher-linux-arm64-musl": { "version": "2.5.6", "resolved": "https://registry.npmjs.org/@parcel/watcher-linux-arm64-musl/-/watcher-linux-arm64-musl-2.5.6.tgz", "integrity": "sha512-qb6naMDGlbCwdhLj6hgoVKJl2odL34z2sqkC7Z6kzir8b5W65WYDpLB6R06KabvZdgoHI/zxke4b3zR0wAbDTA==", "cpu": [ "arm64" ], "dev": true, "license": "MIT", "optional": true, "os": [ "linux" ], "engines": { "node": ">= 10.0.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/parcel" } }, "node_modules/@parcel/watcher-linux-x64-glibc": { "version": "2.5.6", "resolved": "https://registry.npmjs.org/@parcel/watcher-linux-x64-glibc/-/watcher-linux-x64-glibc-2.5.6.tgz", "integrity": "sha512-kbT5wvNQlx7NaGjzPFu8nVIW1rWqV780O7ZtkjuWaPUgpv2NMFpjYERVi0UYj1msZNyCzGlaCWEtzc+exjMGbQ==", "cpu": [ "x64" ], "dev": true, "license": "MIT", "optional": true, "os": [ "linux" ], "engines": { "node": ">= 10.0.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/parcel" } }, "node_modules/@parcel/watcher-linux-x64-musl": { "version": "2.5.6", "resolved": "https://registry.npmjs.org/@parcel/watcher-linux-x64-musl/-/watcher-linux-x64-musl-2.5.6.tgz", "integrity": "sha512-1JRFeC+h7RdXwldHzTsmdtYR/Ku8SylLgTU/reMuqdVD7CtLwf0VR1FqeprZ0eHQkO0vqsbvFLXUmYm/uNKJBg==", "cpu": [ "x64" ], "dev": true, "license": "MIT", "optional": true, "os": [ "linux" ], "engines": { "node": ">= 10.0.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/parcel" } }, "node_modules/@parcel/watcher-win32-arm64": { "version": "2.5.6", "resolved": "https://registry.npmjs.org/@parcel/watcher-win32-arm64/-/watcher-win32-arm64-2.5.6.tgz", "integrity": "sha512-3ukyebjc6eGlw9yRt678DxVF7rjXatWiHvTXqphZLvo7aC5NdEgFufVwjFfY51ijYEWpXbqF5jtrK275z52D4Q==", "cpu": [ "arm64" ], "dev": true, "license": "MIT", "optional": true, "os": [ "win32" ], "engines": { "node": ">= 10.0.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/parcel" } }, "node_modules/@parcel/watcher-win32-ia32": { "version": "2.5.6", "resolved": "https://registry.npmjs.org/@parcel/watcher-win32-ia32/-/watcher-win32-ia32-2.5.6.tgz", "integrity": "sha512-k35yLp1ZMwwee3Ez/pxBi5cf4AoBKYXj00CZ80jUz5h8prpiaQsiRPKQMxoLstNuqe2vR4RNPEAEcjEFzhEz/g==", "cpu": [ "ia32" ], "dev": true, "license": "MIT", "optional": true, "os": [ "win32" ], "engines": { "node": ">= 10.0.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/parcel" } }, "node_modules/@parcel/watcher-win32-x64": { "version": "2.5.6", "resolved": "https://registry.npmjs.org/@parcel/watcher-win32-x64/-/watcher-win32-x64-2.5.6.tgz", "integrity": "sha512-hbQlYcCq5dlAX9Qx+kFb0FHue6vbjlf0FrNzSKdYK2APUf7tGfGxQCk2ihEREmbR6ZMc0MVAD5RIX/41gpUzTw==", "cpu": [ "x64" ], "dev": true, "license": "MIT", "optional": true, "os": [ "win32" ], "engines": { "node": ">= 10.0.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/parcel" } }, "node_modules/@parcel/watcher/node_modules/picomatch": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.3.tgz", "integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==", "dev": true, "license": "MIT", "engines": { "node": ">=12" }, "funding": { "url": "https://github.com/sponsors/jonschlinkert" } }, "node_modules/@smithy/abort-controller": { "version": "4.2.12", "resolved": "https://registry.npmjs.org/@smithy/abort-controller/-/abort-controller-4.2.12.tgz", "integrity": "sha512-xolrFw6b+2iYGl6EcOL7IJY71vvyZ0DJ3mcKtpykqPe2uscwtzDZJa1uVQXyP7w9Dd+kGwYnPbMsJrGISKiY/Q==", "optional": true, "dependencies": { "@smithy/types": "^4.13.1", "tslib": "^2.6.2" }, "engines": { "node": ">=18.0.0" } }, "node_modules/@smithy/config-resolver": { "version": "4.4.11", "resolved": "https://registry.npmjs.org/@smithy/config-resolver/-/config-resolver-4.4.11.tgz", "integrity": "sha512-YxFiiG4YDAtX7WMN7RuhHZLeTmRRAOyCbr+zB8e3AQzHPnUhS8zXjB1+cniPVQI3xbWsQPM0X2aaIkO/ME0ymw==", "optional": true, "dependencies": { "@smithy/node-config-provider": "^4.3.12", "@smithy/types": "^4.13.1", "@smithy/util-config-provider": "^4.2.2", "@smithy/util-endpoints": "^3.3.3", "@smithy/util-middleware": "^4.2.12", "tslib": "^2.6.2" }, "engines": { "node": ">=18.0.0" } }, "node_modules/@smithy/core": { "version": "3.23.11", "resolved": "https://registry.npmjs.org/@smithy/core/-/core-3.23.11.tgz", "integrity": "sha512-952rGf7hBRnhUIaeLp6q4MptKW8sPFe5VvkoZ5qIzFAtx6c/QZ/54FS3yootsyUSf9gJX/NBqEBNdNR7jMIlpQ==", "optional": true, "dependencies": { "@smithy/protocol-http": "^5.3.12", "@smithy/types": "^4.13.1", "@smithy/url-parser": "^4.2.12", "@smithy/util-base64": "^4.3.2", "@smithy/util-body-length-browser": "^4.2.2", "@smithy/util-middleware": "^4.2.12", "@smithy/util-stream": "^4.5.19", "@smithy/util-utf8": "^4.2.2", "@smithy/uuid": "^1.1.2", "tslib": "^2.6.2" }, "engines": { "node": ">=18.0.0" } }, "node_modules/@smithy/credential-provider-imds": { "version": "4.2.12", "resolved": "https://registry.npmjs.org/@smithy/credential-provider-imds/-/credential-provider-imds-4.2.12.tgz", "integrity": "sha512-cr2lR792vNZcYMriSIj+Um3x9KWrjcu98kn234xA6reOAFMmbRpQMOv8KPgEmLLtx3eldU6c5wALKFqNOhugmg==", "optional": true, "dependencies": { "@smithy/node-config-provider": "^4.3.12", "@smithy/property-provider": "^4.2.12", "@smithy/types": "^4.13.1", "@smithy/url-parser": "^4.2.12", "tslib": "^2.6.2" }, "engines": { "node": ">=18.0.0" } }, "node_modules/@smithy/fetch-http-handler": { "version": "5.3.15", "resolved": "https://registry.npmjs.org/@smithy/fetch-http-handler/-/fetch-http-handler-5.3.15.tgz", "integrity": "sha512-T4jFU5N/yiIfrtrsb9uOQn7RdELdM/7HbyLNr6uO/mpkj1ctiVs7CihVr51w4LyQlXWDpXFn4BElf1WmQvZu/A==", "optional": true, "dependencies": { "@smithy/protocol-http": "^5.3.12", "@smithy/querystring-builder": "^4.2.12", "@smithy/types": "^4.13.1", "@smithy/util-base64": "^4.3.2", "tslib": "^2.6.2" }, "engines": { "node": ">=18.0.0" } }, "node_modules/@smithy/hash-node": { "version": "4.2.12", "resolved": "https://registry.npmjs.org/@smithy/hash-node/-/hash-node-4.2.12.tgz", "integrity": "sha512-QhBYbGrbxTkZ43QoTPrK72DoYviDeg6YKDrHTMJbbC+A0sml3kSjzFtXP7BtbyJnXojLfTQldGdUR0RGD8dA3w==", "optional": true, "dependencies": { "@smithy/types": "^4.13.1", "@smithy/util-buffer-from": "^4.2.2", "@smithy/util-utf8": "^4.2.2", "tslib": "^2.6.2" }, "engines": { "node": ">=18.0.0" } }, "node_modules/@smithy/invalid-dependency": { "version": "4.2.12", "resolved": "https://registry.npmjs.org/@smithy/invalid-dependency/-/invalid-dependency-4.2.12.tgz", "integrity": "sha512-/4F1zb7Z8LOu1PalTdESFHR0RbPwHd3FcaG1sI3UEIriQTWakysgJr65lc1jj6QY5ye7aFsisajotH6UhWfm/g==", "optional": true, "dependencies": { "@smithy/types": "^4.13.1", "tslib": "^2.6.2" }, "engines": { "node": ">=18.0.0" } }, "node_modules/@smithy/is-array-buffer": { "version": "4.2.2", "resolved": "https://registry.npmjs.org/@smithy/is-array-buffer/-/is-array-buffer-4.2.2.tgz", "integrity": "sha512-n6rQ4N8Jj4YTQO3YFrlgZuwKodf4zUFs7EJIWH86pSCWBaAtAGBFfCM7Wx6D2bBJ2xqFNxGBSrUWswT3M0VJow==", "optional": true, "dependencies": { "tslib": "^2.6.2" }, "engines": { "node": ">=18.0.0" } }, "node_modules/@smithy/middleware-content-length": { "version": "4.2.12", "resolved": "https://registry.npmjs.org/@smithy/middleware-content-length/-/middleware-content-length-4.2.12.tgz", "integrity": "sha512-YE58Yz+cvFInWI/wOTrB+DbvUVz/pLn5mC5MvOV4fdRUc6qGwygyngcucRQjAhiCEbmfLOXX0gntSIcgMvAjmA==", "optional": true, "dependencies": { "@smithy/protocol-http": "^5.3.12", "@smithy/types": "^4.13.1", "tslib": "^2.6.2" }, "engines": { "node": ">=18.0.0" } }, "node_modules/@smithy/middleware-endpoint": { "version": "4.4.25", "resolved": "https://registry.npmjs.org/@smithy/middleware-endpoint/-/middleware-endpoint-4.4.25.tgz", "integrity": "sha512-dqjLwZs2eBxIUG6Qtw8/YZ4DvzHGIf0DA18wrgtfP6a50UIO7e2nY0FPdcbv5tVJKqWCCU5BmGMOUwT7Puan+A==", "optional": true, "dependencies": { "@smithy/core": "^3.23.11", "@smithy/middleware-serde": "^4.2.14", "@smithy/node-config-provider": "^4.3.12", "@smithy/shared-ini-file-loader": "^4.4.7", "@smithy/types": "^4.13.1", "@smithy/url-parser": "^4.2.12", "@smithy/util-middleware": "^4.2.12", "tslib": "^2.6.2" }, "engines": { "node": ">=18.0.0" } }, "node_modules/@smithy/middleware-retry": { "version": "4.4.42", "resolved": "https://registry.npmjs.org/@smithy/middleware-retry/-/middleware-retry-4.4.42.tgz", "integrity": "sha512-vbwyqHRIpIZutNXZpLAozakzamcINaRCpEy1MYmK6xBeW3xN+TyPRA123GjXnuxZIjc9848MRRCugVMTXxC4Eg==", "optional": true, "dependencies": { "@smithy/node-config-provider": "^4.3.12", "@smithy/protocol-http": "^5.3.12", "@smithy/service-error-classification": "^4.2.12", "@smithy/smithy-client": "^4.12.5", "@smithy/types": "^4.13.1", "@smithy/util-middleware": "^4.2.12", "@smithy/util-retry": "^4.2.12", "@smithy/uuid": "^1.1.2", "tslib": "^2.6.2" }, "engines": { "node": ">=18.0.0" } }, "node_modules/@smithy/middleware-serde": { "version": "4.2.14", "resolved": "https://registry.npmjs.org/@smithy/middleware-serde/-/middleware-serde-4.2.14.tgz", "integrity": "sha512-+CcaLoLa5apzSRtloOyG7lQvkUw2ZDml3hRh4QiG9WyEPfW5Ke/3tPOPiPjUneuT59Tpn8+c3RVaUvvkkwqZwg==", "optional": true, "dependencies": { "@smithy/core": "^3.23.11", "@smithy/protocol-http": "^5.3.12", "@smithy/types": "^4.13.1", "tslib": "^2.6.2" }, "engines": { "node": ">=18.0.0" } }, "node_modules/@smithy/middleware-stack": { "version": "4.2.12", "resolved": "https://registry.npmjs.org/@smithy/middleware-stack/-/middleware-stack-4.2.12.tgz", "integrity": "sha512-kruC5gRHwsCOuyCd4ouQxYjgRAym2uDlCvQ5acuMtRrcdfg7mFBg6blaxcJ09STpt3ziEkis6bhg1uwrWU7txw==", "optional": true, "dependencies": { "@smithy/types": "^4.13.1", "tslib": "^2.6.2" }, "engines": { "node": ">=18.0.0" } }, "node_modules/@smithy/node-config-provider": { "version": "4.3.12", "resolved": "https://registry.npmjs.org/@smithy/node-config-provider/-/node-config-provider-4.3.12.tgz", "integrity": "sha512-tr2oKX2xMcO+rBOjobSwVAkV05SIfUKz8iI53rzxEmgW3GOOPOv0UioSDk+J8OpRQnpnhsO3Af6IEBabQBVmiw==", "optional": true, "dependencies": { "@smithy/property-provider": "^4.2.12", "@smithy/shared-ini-file-loader": "^4.4.7", "@smithy/types": "^4.13.1", "tslib": "^2.6.2" }, "engines": { "node": ">=18.0.0" } }, "node_modules/@smithy/node-http-handler": { "version": "4.4.16", "resolved": "https://registry.npmjs.org/@smithy/node-http-handler/-/node-http-handler-4.4.16.tgz", "integrity": "sha512-ULC8UCS/HivdCB3jhi+kLFYe4B5gxH2gi9vHBfEIiRrT2jfKiZNiETJSlzRtE6B26XbBHjPtc8iZKSNqMol9bw==", "optional": true, "dependencies": { "@smithy/abort-controller": "^4.2.12", "@smithy/protocol-http": "^5.3.12", "@smithy/querystring-builder": "^4.2.12", "@smithy/types": "^4.13.1", "tslib": "^2.6.2" }, "engines": { "node": ">=18.0.0" } }, "node_modules/@smithy/property-provider": { "version": "4.2.12", "resolved": "https://registry.npmjs.org/@smithy/property-provider/-/property-provider-4.2.12.tgz", "integrity": "sha512-jqve46eYU1v7pZ5BM+fmkbq3DerkSluPr5EhvOcHxygxzD05ByDRppRwRPPpFrsFo5yDtCYLKu+kreHKVrvc7A==", "optional": true, "dependencies": { "@smithy/types": "^4.13.1", "tslib": "^2.6.2" }, "engines": { "node": ">=18.0.0" } }, "node_modules/@smithy/protocol-http": { "version": "5.3.12", "resolved": "https://registry.npmjs.org/@smithy/protocol-http/-/protocol-http-5.3.12.tgz", "integrity": "sha512-fit0GZK9I1xoRlR4jXmbLhoN0OdEpa96ul8M65XdmXnxXkuMxM0Y8HDT0Fh0Xb4I85MBvBClOzgSrV1X2s1Hxw==", "optional": true, "dependencies": { "@smithy/types": "^4.13.1", "tslib": "^2.6.2" }, "engines": { "node": ">=18.0.0" } }, "node_modules/@smithy/querystring-builder": { "version": "4.2.12", "resolved": "https://registry.npmjs.org/@smithy/querystring-builder/-/querystring-builder-4.2.12.tgz", "integrity": "sha512-6wTZjGABQufekycfDGMEB84BgtdOE/rCVTov+EDXQ8NHKTUNIp/j27IliwP7tjIU9LR+sSzyGBOXjeEtVgzCHg==", "optional": true, "dependencies": { "@smithy/types": "^4.13.1", "@smithy/util-uri-escape": "^4.2.2", "tslib": "^2.6.2" }, "engines": { "node": ">=18.0.0" } }, "node_modules/@smithy/querystring-parser": { "version": "4.2.12", "resolved": "https://registry.npmjs.org/@smithy/querystring-parser/-/querystring-parser-4.2.12.tgz", "integrity": "sha512-P2OdvrgiAKpkPNKlKUtWbNZKB1XjPxM086NeVhK+W+wI46pIKdWBe5QyXvhUm3MEcyS/rkLvY8rZzyUdmyDZBw==", "optional": true, "dependencies": { "@smithy/types": "^4.13.1", "tslib": "^2.6.2" }, "engines": { "node": ">=18.0.0" } }, "node_modules/@smithy/service-error-classification": { "version": "4.2.12", "resolved": "https://registry.npmjs.org/@smithy/service-error-classification/-/service-error-classification-4.2.12.tgz", "integrity": "sha512-LlP29oSQN0Tw0b6D0Xo6BIikBswuIiGYbRACy5ujw/JgWSzTdYj46U83ssf6Ux0GyNJVivs2uReU8pt7Eu9okQ==", "optional": true, "dependencies": { "@smithy/types": "^4.13.1" }, "engines": { "node": ">=18.0.0" } }, "node_modules/@smithy/shared-ini-file-loader": { "version": "4.4.7", "resolved": "https://registry.npmjs.org/@smithy/shared-ini-file-loader/-/shared-ini-file-loader-4.4.7.tgz", "integrity": "sha512-HrOKWsUb+otTeo1HxVWeEb99t5ER1XrBi/xka2Wv6NVmTbuCUC1dvlrksdvxFtODLBjsC+PHK+fuy2x/7Ynyiw==", "optional": true, "dependencies": { "@smithy/types": "^4.13.1", "tslib": "^2.6.2" }, "engines": { "node": ">=18.0.0" } }, "node_modules/@smithy/signature-v4": { "version": "5.3.12", "resolved": "https://registry.npmjs.org/@smithy/signature-v4/-/signature-v4-5.3.12.tgz", "integrity": "sha512-B/FBwO3MVOL00DaRSXfXfa/TRXRheagt/q5A2NM13u7q+sHS59EOVGQNfG7DkmVtdQm5m3vOosoKAXSqn/OEgw==", "optional": true, "dependencies": { "@smithy/is-array-buffer": "^4.2.2", "@smithy/protocol-http": "^5.3.12", "@smithy/types": "^4.13.1", "@smithy/util-hex-encoding": "^4.2.2", "@smithy/util-middleware": "^4.2.12", "@smithy/util-uri-escape": "^4.2.2", "@smithy/util-utf8": "^4.2.2", "tslib": "^2.6.2" }, "engines": { "node": ">=18.0.0" } }, "node_modules/@smithy/smithy-client": { "version": "4.12.5", "resolved": "https://registry.npmjs.org/@smithy/smithy-client/-/smithy-client-4.12.5.tgz", "integrity": "sha512-UqwYawyqSr/aog8mnLnfbPurS0gi4G7IYDcD28cUIBhsvWs1+rQcL2IwkUQ+QZ7dibaoRzhNF99fAQ9AUcO00w==", "optional": true, "dependencies": { "@smithy/core": "^3.23.11", "@smithy/middleware-endpoint": "^4.4.25", "@smithy/middleware-stack": "^4.2.12", "@smithy/protocol-http": "^5.3.12", "@smithy/types": "^4.13.1", "@smithy/util-stream": "^4.5.19", "tslib": "^2.6.2" }, "engines": { "node": ">=18.0.0" } }, "node_modules/@smithy/types": { "version": "4.13.1", "resolved": "https://registry.npmjs.org/@smithy/types/-/types-4.13.1.tgz", "integrity": "sha512-787F3yzE2UiJIQ+wYW1CVg2odHjmaWLGksnKQHUrK/lYZSEcy1msuLVvxaR/sI2/aDe9U+TBuLsXnr3vod1g0g==", "optional": true, "dependencies": { "tslib": "^2.6.2" }, "engines": { "node": ">=18.0.0" } }, "node_modules/@smithy/url-parser": { "version": "4.2.12", "resolved": "https://registry.npmjs.org/@smithy/url-parser/-/url-parser-4.2.12.tgz", "integrity": "sha512-wOPKPEpso+doCZGIlr+e1lVI6+9VAKfL4kZWFgzVgGWY2hZxshNKod4l2LXS3PRC9otH/JRSjtEHqQ/7eLciRA==", "optional": true, "dependencies": { "@smithy/querystring-parser": "^4.2.12", "@smithy/types": "^4.13.1", "tslib": "^2.6.2" }, "engines": { "node": ">=18.0.0" } }, "node_modules/@smithy/util-base64": { "version": "4.3.2", "resolved": "https://registry.npmjs.org/@smithy/util-base64/-/util-base64-4.3.2.tgz", "integrity": "sha512-XRH6b0H/5A3SgblmMa5ErXQ2XKhfbQB+Fm/oyLZ2O2kCUrwgg55bU0RekmzAhuwOjA9qdN5VU2BprOvGGUkOOQ==", "optional": true, "dependencies": { "@smithy/util-buffer-from": "^4.2.2", "@smithy/util-utf8": "^4.2.2", "tslib": "^2.6.2" }, "engines": { "node": ">=18.0.0" } }, "node_modules/@smithy/util-body-length-browser": { "version": "4.2.2", "resolved": "https://registry.npmjs.org/@smithy/util-body-length-browser/-/util-body-length-browser-4.2.2.tgz", "integrity": "sha512-JKCrLNOup3OOgmzeaKQwi4ZCTWlYR5H4Gm1r2uTMVBXoemo1UEghk5vtMi1xSu2ymgKVGW631e2fp9/R610ZjQ==", "optional": true, "dependencies": { "tslib": "^2.6.2" }, "engines": { "node": ">=18.0.0" } }, "node_modules/@smithy/util-body-length-node": { "version": "4.2.3", "resolved": "https://registry.npmjs.org/@smithy/util-body-length-node/-/util-body-length-node-4.2.3.tgz", "integrity": "sha512-ZkJGvqBzMHVHE7r/hcuCxlTY8pQr1kMtdsVPs7ex4mMU+EAbcXppfo5NmyxMYi2XU49eqaz56j2gsk4dHHPG/g==", "optional": true, "dependencies": { "tslib": "^2.6.2" }, "engines": { "node": ">=18.0.0" } }, "node_modules/@smithy/util-buffer-from": { "version": "4.2.2", "resolved": "https://registry.npmjs.org/@smithy/util-buffer-from/-/util-buffer-from-4.2.2.tgz", "integrity": "sha512-FDXD7cvUoFWwN6vtQfEta540Y/YBe5JneK3SoZg9bThSoOAC/eGeYEua6RkBgKjGa/sz6Y+DuBZj3+YEY21y4Q==", "optional": true, "dependencies": { "@smithy/is-array-buffer": "^4.2.2", "tslib": "^2.6.2" }, "engines": { "node": ">=18.0.0" } }, "node_modules/@smithy/util-config-provider": { "version": "4.2.2", "resolved": "https://registry.npmjs.org/@smithy/util-config-provider/-/util-config-provider-4.2.2.tgz", "integrity": "sha512-dWU03V3XUprJwaUIFVv4iOnS1FC9HnMHDfUrlNDSh4315v0cWyaIErP8KiqGVbf5z+JupoVpNM7ZB3jFiTejvQ==", "optional": true, "dependencies": { "tslib": "^2.6.2" }, "engines": { "node": ">=18.0.0" } }, "node_modules/@smithy/util-defaults-mode-browser": { "version": "4.3.41", "resolved": "https://registry.npmjs.org/@smithy/util-defaults-mode-browser/-/util-defaults-mode-browser-4.3.41.tgz", "integrity": "sha512-M1w1Ux0rSVvBOxIIiqbxvZvhnjQ+VUjJrugtORE90BbadSTH+jsQL279KRL3Hv0w69rE7EuYkV/4Lepz/NBW9g==", "optional": true, "dependencies": { "@smithy/property-provider": "^4.2.12", "@smithy/smithy-client": "^4.12.5", "@smithy/types": "^4.13.1", "tslib": "^2.6.2" }, "engines": { "node": ">=18.0.0" } }, "node_modules/@smithy/util-defaults-mode-node": { "version": "4.2.44", "resolved": "https://registry.npmjs.org/@smithy/util-defaults-mode-node/-/util-defaults-mode-node-4.2.44.tgz", "integrity": "sha512-YPze3/lD1KmWuZsl9JlfhcgGLX7AXhSoaCDtiPntUjNW5/YY0lOHjkcgxyE9x/h5vvS1fzDifMGjzqnNlNiqOQ==", "optional": true, "dependencies": { "@smithy/config-resolver": "^4.4.11", "@smithy/credential-provider-imds": "^4.2.12", "@smithy/node-config-provider": "^4.3.12", "@smithy/property-provider": "^4.2.12", "@smithy/smithy-client": "^4.12.5", "@smithy/types": "^4.13.1", "tslib": "^2.6.2" }, "engines": { "node": ">=18.0.0" } }, "node_modules/@smithy/util-endpoints": { "version": "3.3.3", "resolved": "https://registry.npmjs.org/@smithy/util-endpoints/-/util-endpoints-3.3.3.tgz", "integrity": "sha512-VACQVe50j0HZPjpwWcjyT51KUQ4AnsvEaQ2lKHOSL4mNLD0G9BjEniQ+yCt1qqfKfiAHRAts26ud7hBjamrwig==", "optional": true, "dependencies": { "@smithy/node-config-provider": "^4.3.12", "@smithy/types": "^4.13.1", "tslib": "^2.6.2" }, "engines": { "node": ">=18.0.0" } }, "node_modules/@smithy/util-hex-encoding": { "version": "4.2.2", "resolved": "https://registry.npmjs.org/@smithy/util-hex-encoding/-/util-hex-encoding-4.2.2.tgz", "integrity": "sha512-Qcz3W5vuHK4sLQdyT93k/rfrUwdJ8/HZ+nMUOyGdpeGA1Wxt65zYwi3oEl9kOM+RswvYq90fzkNDahPS8K0OIg==", "optional": true, "dependencies": { "tslib": "^2.6.2" }, "engines": { "node": ">=18.0.0" } }, "node_modules/@smithy/util-middleware": { "version": "4.2.12", "resolved": "https://registry.npmjs.org/@smithy/util-middleware/-/util-middleware-4.2.12.tgz", "integrity": "sha512-Er805uFUOvgc0l8nv0e0su0VFISoxhJ/AwOn3gL2NWNY2LUEldP5WtVcRYSQBcjg0y9NfG8JYrCJaYDpupBHJQ==", "optional": true, "dependencies": { "@smithy/types": "^4.13.1", "tslib": "^2.6.2" }, "engines": { "node": ">=18.0.0" } }, "node_modules/@smithy/util-retry": { "version": "4.2.12", "resolved": "https://registry.npmjs.org/@smithy/util-retry/-/util-retry-4.2.12.tgz", "integrity": "sha512-1zopLDUEOwumjcHdJ1mwBHddubYF8GMQvstVCLC54Y46rqoHwlIU+8ZzUeaBcD+WCJHyDGSeZ2ml9YSe9aqcoQ==", "optional": true, "dependencies": { "@smithy/service-error-classification": "^4.2.12", "@smithy/types": "^4.13.1", "tslib": "^2.6.2" }, "engines": { "node": ">=18.0.0" } }, "node_modules/@smithy/util-stream": { "version": "4.5.19", "resolved": "https://registry.npmjs.org/@smithy/util-stream/-/util-stream-4.5.19.tgz", "integrity": "sha512-v4sa+3xTweL1CLO2UP0p7tvIMH/Rq1X4KKOxd568mpe6LSLMQCnDHs4uv7m3ukpl3HvcN2JH6jiCS0SNRXKP/w==", "optional": true, "dependencies": { "@smithy/fetch-http-handler": "^5.3.15", "@smithy/node-http-handler": "^4.4.16", "@smithy/types": "^4.13.1", "@smithy/util-base64": "^4.3.2", "@smithy/util-buffer-from": "^4.2.2", "@smithy/util-hex-encoding": "^4.2.2", "@smithy/util-utf8": "^4.2.2", "tslib": "^2.6.2" }, "engines": { "node": ">=18.0.0" } }, "node_modules/@smithy/util-uri-escape": { "version": "4.2.2", "resolved": "https://registry.npmjs.org/@smithy/util-uri-escape/-/util-uri-escape-4.2.2.tgz", "integrity": "sha512-2kAStBlvq+lTXHyAZYfJRb/DfS3rsinLiwb+69SstC9Vb0s9vNWkRwpnj918Pfi85mzi42sOqdV72OLxWAISnw==", "optional": true, "dependencies": { "tslib": "^2.6.2" }, "engines": { "node": ">=18.0.0" } }, "node_modules/@smithy/util-utf8": { "version": "4.2.2", "resolved": "https://registry.npmjs.org/@smithy/util-utf8/-/util-utf8-4.2.2.tgz", "integrity": "sha512-75MeYpjdWRe8M5E3AW0O4Cx3UadweS+cwdXjwYGBW5h/gxxnbeZ877sLPX/ZJA9GVTlL/qG0dXP29JWFCD1Ayw==", "optional": true, "dependencies": { "@smithy/util-buffer-from": "^4.2.2", "tslib": "^2.6.2" }, "engines": { "node": ">=18.0.0" } }, "node_modules/@smithy/uuid": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/@smithy/uuid/-/uuid-1.1.2.tgz", "integrity": "sha512-O/IEdcCUKkubz60tFbGA7ceITTAJsty+lBjNoorP4Z6XRqaFb/OjQjZODophEcuq68nKm6/0r+6/lLQ+XVpk8g==", "optional": true, "dependencies": { "tslib": "^2.6.2" }, "engines": { "node": ">=18.0.0" } }, "node_modules/@tailwindcss/cli": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/@tailwindcss/cli/-/cli-4.2.1.tgz", "integrity": "sha512-b7MGn51IA80oSG+7fuAgzfQ+7pZBgjzbqwmiv6NO7/+a1sev32cGqnwhscT7h0EcAvMa9r7gjRylqOH8Xhc4DA==", "dev": true, "license": "MIT", "dependencies": { "@parcel/watcher": "^2.5.1", "@tailwindcss/node": "4.2.1", "@tailwindcss/oxide": "4.2.1", "enhanced-resolve": "^5.19.0", "mri": "^1.2.0", "picocolors": "^1.1.1", "tailwindcss": "4.2.1" }, "bin": { "tailwindcss": "dist/index.mjs" } }, "node_modules/@tailwindcss/forms": { "version": "0.5.11", "resolved": "https://registry.npmjs.org/@tailwindcss/forms/-/forms-0.5.11.tgz", "integrity": "sha512-h9wegbZDPurxG22xZSoWtdzc41/OlNEUQERNqI/0fOwa2aVlWGu7C35E/x6LDyD3lgtztFSSjKZyuVM0hxhbgA==", "dev": true, "license": "MIT", "dependencies": { "mini-svg-data-uri": "^1.2.3" }, "peerDependencies": { "tailwindcss": ">=3.0.0 || >= 3.0.0-alpha.1 || >= 4.0.0-alpha.20 || >= 4.0.0-beta.1" } }, "node_modules/@tailwindcss/node": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/@tailwindcss/node/-/node-4.2.1.tgz", "integrity": "sha512-jlx6sLk4EOwO6hHe1oCGm1Q4AN/s0rSrTTPBGPM0/RQ6Uylwq17FuU8IeJJKEjtc6K6O07zsvP+gDO6MMWo7pg==", "dev": true, "license": "MIT", "dependencies": { "@jridgewell/remapping": "^2.3.5", "enhanced-resolve": "^5.19.0", "jiti": "^2.6.1", "lightningcss": "1.31.1", "magic-string": "^0.30.21", "source-map-js": "^1.2.1", "tailwindcss": "4.2.1" } }, "node_modules/@tailwindcss/oxide": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/@tailwindcss/oxide/-/oxide-4.2.1.tgz", "integrity": "sha512-yv9jeEFWnjKCI6/T3Oq50yQEOqmpmpfzG1hcZsAOaXFQPfzWprWrlHSdGPEF3WQTi8zu8ohC9Mh9J470nT5pUw==", "dev": true, "license": "MIT", "engines": { "node": ">= 20" }, "optionalDependencies": { "@tailwindcss/oxide-android-arm64": "4.2.1", "@tailwindcss/oxide-darwin-arm64": "4.2.1", "@tailwindcss/oxide-darwin-x64": "4.2.1", "@tailwindcss/oxide-freebsd-x64": "4.2.1", "@tailwindcss/oxide-linux-arm-gnueabihf": "4.2.1", "@tailwindcss/oxide-linux-arm64-gnu": "4.2.1", "@tailwindcss/oxide-linux-arm64-musl": "4.2.1", "@tailwindcss/oxide-linux-x64-gnu": "4.2.1", "@tailwindcss/oxide-linux-x64-musl": "4.2.1", "@tailwindcss/oxide-wasm32-wasi": "4.2.1", "@tailwindcss/oxide-win32-arm64-msvc": "4.2.1", "@tailwindcss/oxide-win32-x64-msvc": "4.2.1" } }, "node_modules/@tailwindcss/oxide-android-arm64": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-android-arm64/-/oxide-android-arm64-4.2.1.tgz", "integrity": "sha512-eZ7G1Zm5EC8OOKaesIKuw77jw++QJ2lL9N+dDpdQiAB/c/B2wDh0QPFHbkBVrXnwNugvrbJFk1gK2SsVjwWReg==", "cpu": [ "arm64" ], "dev": true, "license": "MIT", "optional": true, "os": [ "android" ], "engines": { "node": ">= 20" } }, "node_modules/@tailwindcss/oxide-darwin-arm64": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-darwin-arm64/-/oxide-darwin-arm64-4.2.1.tgz", "integrity": "sha512-q/LHkOstoJ7pI1J0q6djesLzRvQSIfEto148ppAd+BVQK0JYjQIFSK3JgYZJa+Yzi0DDa52ZsQx2rqytBnf8Hw==", "cpu": [ "arm64" ], "dev": true, "license": "MIT", "optional": true, "os": [ "darwin" ], "engines": { "node": ">= 20" } }, "node_modules/@tailwindcss/oxide-darwin-x64": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-darwin-x64/-/oxide-darwin-x64-4.2.1.tgz", "integrity": "sha512-/f/ozlaXGY6QLbpvd/kFTro2l18f7dHKpB+ieXz+Cijl4Mt9AI2rTrpq7V+t04nK+j9XBQHnSMdeQRhbGyt6fw==", "cpu": [ "x64" ], "dev": true, "license": "MIT", "optional": true, "os": [ "darwin" ], "engines": { "node": ">= 20" } }, "node_modules/@tailwindcss/oxide-freebsd-x64": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-freebsd-x64/-/oxide-freebsd-x64-4.2.1.tgz", "integrity": "sha512-5e/AkgYJT/cpbkys/OU2Ei2jdETCLlifwm7ogMC7/hksI2fC3iiq6OcXwjibcIjPung0kRtR3TxEITkqgn0TcA==", "cpu": [ "x64" ], "dev": true, "license": "MIT", "optional": true, "os": [ "freebsd" ], "engines": { "node": ">= 20" } }, "node_modules/@tailwindcss/oxide-linux-arm-gnueabihf": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-linux-arm-gnueabihf/-/oxide-linux-arm-gnueabihf-4.2.1.tgz", "integrity": "sha512-Uny1EcVTTmerCKt/1ZuKTkb0x8ZaiuYucg2/kImO5A5Y/kBz41/+j0gxUZl+hTF3xkWpDmHX+TaWhOtba2Fyuw==", "cpu": [ "arm" ], "dev": true, "license": "MIT", "optional": true, "os": [ "linux" ], "engines": { "node": ">= 20" } }, "node_modules/@tailwindcss/oxide-linux-arm64-gnu": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-linux-arm64-gnu/-/oxide-linux-arm64-gnu-4.2.1.tgz", "integrity": "sha512-CTrwomI+c7n6aSSQlsPL0roRiNMDQ/YzMD9EjcR+H4f0I1SQ8QqIuPnsVp7QgMkC1Qi8rtkekLkOFjo7OlEFRQ==", "cpu": [ "arm64" ], "dev": true, "license": "MIT", "optional": true, "os": [ "linux" ], "engines": { "node": ">= 20" } }, "node_modules/@tailwindcss/oxide-linux-arm64-musl": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-linux-arm64-musl/-/oxide-linux-arm64-musl-4.2.1.tgz", "integrity": "sha512-WZA0CHRL/SP1TRbA5mp9htsppSEkWuQ4KsSUumYQnyl8ZdT39ntwqmz4IUHGN6p4XdSlYfJwM4rRzZLShHsGAQ==", "cpu": [ "arm64" ], "dev": true, "license": "MIT", "optional": true, "os": [ "linux" ], "engines": { "node": ">= 20" } }, "node_modules/@tailwindcss/oxide-linux-x64-gnu": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-linux-x64-gnu/-/oxide-linux-x64-gnu-4.2.1.tgz", "integrity": "sha512-qMFzxI2YlBOLW5PhblzuSWlWfwLHaneBE0xHzLrBgNtqN6mWfs+qYbhryGSXQjFYB1Dzf5w+LN5qbUTPhW7Y5g==", "cpu": [ "x64" ], "dev": true, "license": "MIT", "optional": true, "os": [ "linux" ], "engines": { "node": ">= 20" } }, "node_modules/@tailwindcss/oxide-linux-x64-musl": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-linux-x64-musl/-/oxide-linux-x64-musl-4.2.1.tgz", "integrity": "sha512-5r1X2FKnCMUPlXTWRYpHdPYUY6a1Ar/t7P24OuiEdEOmms5lyqjDRvVY1yy9Rmioh+AunQ0rWiOTPE8F9A3v5g==", "cpu": [ "x64" ], "dev": true, "license": "MIT", "optional": true, "os": [ "linux" ], "engines": { "node": ">= 20" } }, "node_modules/@tailwindcss/oxide-wasm32-wasi": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-wasm32-wasi/-/oxide-wasm32-wasi-4.2.1.tgz", "integrity": "sha512-MGFB5cVPvshR85MTJkEvqDUnuNoysrsRxd6vnk1Lf2tbiqNlXpHYZqkqOQalydienEWOHHFyyuTSYRsLfxFJ2Q==", "bundleDependencies": [ "@napi-rs/wasm-runtime", "@emnapi/core", "@emnapi/runtime", "@tybys/wasm-util", "@emnapi/wasi-threads", "tslib" ], "cpu": [ "wasm32" ], "dev": true, "license": "MIT", "optional": true, "dependencies": { "@emnapi/core": "^1.8.1", "@emnapi/runtime": "^1.8.1", "@emnapi/wasi-threads": "^1.1.0", "@napi-rs/wasm-runtime": "^1.1.1", "@tybys/wasm-util": "^0.10.1", "tslib": "^2.8.1" }, "engines": { "node": ">=14.0.0" } }, "node_modules/@tailwindcss/oxide-win32-arm64-msvc": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-win32-arm64-msvc/-/oxide-win32-arm64-msvc-4.2.1.tgz", "integrity": "sha512-YlUEHRHBGnCMh4Nj4GnqQyBtsshUPdiNroZj8VPkvTZSoHsilRCwXcVKnG9kyi0ZFAS/3u+qKHBdDc81SADTRA==", "cpu": [ "arm64" ], "dev": true, "license": "MIT", "optional": true, "os": [ "win32" ], "engines": { "node": ">= 20" } }, "node_modules/@tailwindcss/oxide-win32-x64-msvc": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-win32-x64-msvc/-/oxide-win32-x64-msvc-4.2.1.tgz", "integrity": "sha512-rbO34G5sMWWyrN/idLeVxAZgAKWrn5LiR3/I90Q9MkA67s6T1oB0xtTe+0heoBvHSpbU9Mk7i6uwJnpo4u21XQ==", "cpu": [ "x64" ], "dev": true, "license": "MIT", "optional": true, "os": [ "win32" ], "engines": { "node": ">= 20" } }, "node_modules/@types/accepts": { "version": "1.3.7", "resolved": "https://registry.npmjs.org/@types/accepts/-/accepts-1.3.7.tgz", "integrity": "sha512-Pay9fq2lM2wXPWbteBsRAGiWH2hig4ZE2asK+mm7kUzlxRTfL961rj89I6zV/E3PcIkDqyuBEcMxFT7rccugeQ==", "dev": true, "dependencies": { "@types/node": "*" } }, "node_modules/@types/body-parser": { "version": "1.19.6", "resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.6.tgz", "integrity": "sha512-HLFeCYgz89uk22N5Qg3dvGvsv46B8GLvKKo1zKG4NybA8U2DiEO3w9lqGg29t/tfLRJpJ6iQxnVw4OnB7MoM9g==", "dev": true, "dependencies": { "@types/connect": "*", "@types/node": "*" } }, "node_modules/@types/connect": { "version": "3.4.38", "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.38.tgz", "integrity": "sha512-K6uROf1LD88uDQqJCktA4yzL1YYAK6NgfsI0v/mTgyPKWsX1CnJ0XPSDhViejru1GcRkLWb8RlzFYJRqGUbaug==", "dev": true, "dependencies": { "@types/node": "*" } }, "node_modules/@types/content-disposition": { "version": "0.5.9", "resolved": "https://registry.npmjs.org/@types/content-disposition/-/content-disposition-0.5.9.tgz", "integrity": "sha512-8uYXI3Gw35MhiVYhG3s295oihrxRyytcRHjSjqnqZVDDy/xcGBRny7+Xj1Wgfhv5QzRtN2hB2dVRBUX9XW3UcQ==", "dev": true }, "node_modules/@types/cookies": { "version": "0.9.2", "resolved": "https://registry.npmjs.org/@types/cookies/-/cookies-0.9.2.tgz", "integrity": "sha512-1AvkDdZM2dbyFybL4fxpuNCaWyv//0AwsuUk2DWeXyM1/5ZKm6W3z6mQi24RZ4l2ucY+bkSHzbDVpySqPGuV8A==", "dev": true, "dependencies": { "@types/connect": "*", "@types/express": "*", "@types/keygrip": "*", "@types/node": "*" } }, "node_modules/@types/esrecurse": { "version": "4.3.1", "resolved": "https://registry.npmjs.org/@types/esrecurse/-/esrecurse-4.3.1.tgz", "integrity": "sha512-xJBAbDifo5hpffDBuHl0Y8ywswbiAp/Wi7Y/GtAgSlZyIABppyurxVueOPE8LUQOxdlgi6Zqce7uoEpqNTeiUw==", "dev": true, "license": "MIT" }, "node_modules/@types/estree": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.8.tgz", "integrity": "sha512-dWHzHa2WqEXI/O1E9OjrocMTKJl2mSrEolh1Iomrv6U+JuNwaHXsXx9bLu5gG7BUWFIN0skIQJQ/L1rIex4X6w==", "dev": true, "license": "MIT" }, "node_modules/@types/express": { "version": "5.0.6", "resolved": "https://registry.npmjs.org/@types/express/-/express-5.0.6.tgz", "integrity": "sha512-sKYVuV7Sv9fbPIt/442koC7+IIwK5olP1KWeD88e/idgoJqDm3JV/YUiPwkoKK92ylff2MGxSz1CSjsXelx0YA==", "dev": true, "dependencies": { "@types/body-parser": "*", "@types/express-serve-static-core": "^5.0.0", "@types/serve-static": "^2" } }, "node_modules/@types/express-serve-static-core": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-5.1.1.tgz", "integrity": "sha512-v4zIMr/cX7/d2BpAEX3KNKL/JrT1s43s96lLvvdTmza1oEvDudCqK9aF/djc/SWgy8Yh0h30TZx5VpzqFCxk5A==", "dev": true, "dependencies": { "@types/node": "*", "@types/qs": "*", "@types/range-parser": "*", "@types/send": "*" } }, "node_modules/@types/http-assert": { "version": "1.5.6", "resolved": "https://registry.npmjs.org/@types/http-assert/-/http-assert-1.5.6.tgz", "integrity": "sha512-TTEwmtjgVbYAzZYWyeHPrrtWnfVkm8tQkP8P21uQifPgMRgjrow3XDEYqucuC8SKZJT7pUnhU/JymvjggxO9vw==", "dev": true }, "node_modules/@types/http-errors": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/@types/http-errors/-/http-errors-2.0.5.tgz", "integrity": "sha512-r8Tayk8HJnX0FztbZN7oVqGccWgw98T/0neJphO91KkmOzug1KkofZURD4UaD5uH8AqcFLfdPErnBod0u71/qg==", "dev": true }, "node_modules/@types/json-schema": { "version": "7.0.15", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz", "integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==", "dev": true, "license": "MIT" }, "node_modules/@types/jsonwebtoken": { "version": "9.0.10", "resolved": "https://registry.npmjs.org/@types/jsonwebtoken/-/jsonwebtoken-9.0.10.tgz", "integrity": "sha512-asx5hIG9Qmf/1oStypjanR7iKTv0gXQ1Ov/jfrX6kS/EO0OFni8orbmGCn0672NHR3kXHwpAwR+B368ZGN/2rA==", "dev": true, "dependencies": { "@types/ms": "*", "@types/node": "*" } }, "node_modules/@types/keygrip": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/@types/keygrip/-/keygrip-1.0.6.tgz", "integrity": "sha512-lZuNAY9xeJt7Bx4t4dx0rYCDqGPW8RXhQZK1td7d4H6E9zYbLoOtjBvfwdTKpsyxQI/2jv+armjX/RW+ZNpXOQ==", "dev": true }, "node_modules/@types/koa": { "version": "2.15.0", "resolved": "https://registry.npmjs.org/@types/koa/-/koa-2.15.0.tgz", "integrity": "sha512-7QFsywoE5URbuVnG3loe03QXuGajrnotr3gQkXcEBShORai23MePfFYdhz90FEtBBpkyIYQbVD+evKtloCgX3g==", "dev": true, "dependencies": { "@types/accepts": "*", "@types/content-disposition": "*", "@types/cookies": "*", "@types/http-assert": "*", "@types/http-errors": "*", "@types/keygrip": "*", "@types/koa-compose": "*", "@types/node": "*" } }, "node_modules/@types/koa-compose": { "version": "3.2.9", "resolved": "https://registry.npmjs.org/@types/koa-compose/-/koa-compose-3.2.9.tgz", "integrity": "sha512-BroAZ9FTvPiCy0Pi8tjD1OfJ7bgU1gQf0eR6e1Vm+JJATy9eKOG3hQMFtMciMawiSOVnLMdmUOC46s7HBhSTsA==", "dev": true, "dependencies": { "@types/koa": "*" } }, "node_modules/@types/koa-compress": { "version": "4.0.7", "resolved": "https://registry.npmjs.org/@types/koa-compress/-/koa-compress-4.0.7.tgz", "integrity": "sha512-NqP9qCBfXCu2+RYkGzEENBkqXWExOPeBEsvj3F0xtVxKDwwdfRRtVdpxJeTRAq2Ml3qlUnDbK8bKHWwe6V1kkg==", "dev": true, "dependencies": { "@types/koa": "*", "@types/node": "*" } }, "node_modules/@types/mithril": { "version": "2.2.7", "resolved": "https://registry.npmjs.org/@types/mithril/-/mithril-2.2.7.tgz", "integrity": "sha512-uetxoYizBMHPELl6DSZUfO6Q/aOm+h0NUCv9bVAX2iAxfrdBSOvU9KKFl+McTtxR13F+BReYLY814pJsZvnSxg==", "dev": true }, "node_modules/@types/ms": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/@types/ms/-/ms-2.1.0.tgz", "integrity": "sha512-GsCCIZDE/p3i96vtEqx+7dBUGXrc7zeSK3wwPHIaRThS+9OhWIXRqzs4d6k1SVU8g91DrNRWxWUGhp5KXQb2VA==", "dev": true }, "node_modules/@types/node": { "version": "25.5.0", "resolved": "https://registry.npmjs.org/@types/node/-/node-25.5.0.tgz", "integrity": "sha512-jp2P3tQMSxWugkCUKLRPVUpGaL5MVFwF8RDuSRztfwgN1wmqJeMSbKlnEtQqU8UrhTmzEmZdu2I6v2dpp7XIxw==", "license": "MIT", "dependencies": { "undici-types": "~7.18.0" } }, "node_modules/@types/qs": { "version": "6.15.0", "resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.15.0.tgz", "integrity": "sha512-JawvT8iBVWpzTrz3EGw9BTQFg3BQNmwERdKE22vlTxawwtbyUSlMppvZYKLZzB5zgACXdXxbD3m1bXaMqP/9ow==", "dev": true }, "node_modules/@types/range-parser": { "version": "1.2.7", "resolved": "https://registry.npmjs.org/@types/range-parser/-/range-parser-1.2.7.tgz", "integrity": "sha512-hKormJbkJqzQGhziax5PItDUTMAM9uE2XXQmM37dyd4hVM+5aVl7oVxMVUiVQn2oCQFN/LKCZdvSM0pFRqbSmQ==", "dev": true }, "node_modules/@types/seedrandom": { "version": "3.0.8", "resolved": "https://registry.npmjs.org/@types/seedrandom/-/seedrandom-3.0.8.tgz", "integrity": "sha512-TY1eezMU2zH2ozQoAFAQFOPpvP15g+ZgSfTZt31AUUH/Rxtnz3H+A/Sv1Snw2/amp//omibc+AEkTaA8KUeOLQ==", "dev": true }, "node_modules/@types/send": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/@types/send/-/send-1.2.1.tgz", "integrity": "sha512-arsCikDvlU99zl1g69TcAB3mzZPpxgw0UQnaHeC1Nwb015xp8bknZv5rIfri9xTOcMuaVgvabfIRA7PSZVuZIQ==", "dev": true, "dependencies": { "@types/node": "*" } }, "node_modules/@types/serve-static": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-2.2.0.tgz", "integrity": "sha512-8mam4H1NHLtu7nmtalF7eyBH14QyOASmcxHhSfEoRyr0nP/YdoesEtU+uSRvMe96TW/HPTtkoKqQLl53N7UXMQ==", "dev": true, "dependencies": { "@types/http-errors": "*", "@types/node": "*" } }, "node_modules/@types/webidl-conversions": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-7.0.3.tgz", "integrity": "sha512-CiJJvcRtIgzadHCYXw7dqEnMNRjhGZlYK05Mj9OyktqV8uVT8fD2BFOB7S1uwBE3Kj2Z+4UyPmFw/Ixgw/LAlA==" }, "node_modules/@types/whatwg-url": { "version": "8.2.2", "resolved": "https://registry.npmjs.org/@types/whatwg-url/-/whatwg-url-8.2.2.tgz", "integrity": "sha512-FtQu10RWgn3D9U4aazdwIE2yzphmTJREDqNdODHrbrZmmMqI0vMheC/6NE/J1Yveaj8H+ela+YwWTjq5PGmuhA==", "dependencies": { "@types/node": "*", "@types/webidl-conversions": "*" } }, "node_modules/@typescript-eslint/project-service": { "version": "8.56.1", "resolved": "https://registry.npmjs.org/@typescript-eslint/project-service/-/project-service-8.56.1.tgz", "integrity": "sha512-TAdqQTzHNNvlVFfR+hu2PDJrURiwKsUvxFn1M0h95BB8ah5jejas08jUWG4dBA68jDMI988IvtfdAI53JzEHOQ==", "dev": true, "license": "MIT", "dependencies": { "@typescript-eslint/tsconfig-utils": "^8.56.1", "@typescript-eslint/types": "^8.56.1", "debug": "^4.4.3" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/typescript-eslint" }, "peerDependencies": { "typescript": ">=4.8.4 <6.0.0" } }, "node_modules/@typescript-eslint/project-service/node_modules/@typescript-eslint/types": { "version": "8.57.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.57.0.tgz", "integrity": "sha512-dTLI8PEXhjUC7B9Kre+u0XznO696BhXcTlOn0/6kf1fHaQW8+VjJAVHJ3eTI14ZapTxdkOmc80HblPQLaEeJdg==", "dev": true, "license": "MIT", "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/typescript-eslint" } }, "node_modules/@typescript-eslint/tsconfig-utils": { "version": "8.56.1", "resolved": "https://registry.npmjs.org/@typescript-eslint/tsconfig-utils/-/tsconfig-utils-8.56.1.tgz", "integrity": "sha512-qOtCYzKEeyr3aR9f28mPJqBty7+DBqsdd63eO0yyDwc6vgThj2UjWfJIcsFeSucYydqcuudMOprZ+x1SpF3ZuQ==", "dev": true, "license": "MIT", "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/typescript-eslint" }, "peerDependencies": { "typescript": ">=4.8.4 <6.0.0" } }, "node_modules/accepts": { "version": "1.3.8", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", "integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==", "dependencies": { "mime-types": "~2.1.34", "negotiator": "0.6.3" }, "engines": { "node": ">= 0.6" } }, "node_modules/acorn": { "version": "8.16.0", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.16.0.tgz", "integrity": "sha512-UVJyE9MttOsBQIDKw1skb9nAwQuR5wuGD3+82K6JgJlm/Y+KI92oNsMNGZCYdDsVtRHSak0pcV5Dno5+4jh9sw==", "dev": true, "license": "MIT", "bin": { "acorn": "bin/acorn" }, "engines": { "node": ">=0.4.0" } }, "node_modules/acorn-jsx": { "version": "5.3.2", "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.2.tgz", "integrity": "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==", "dev": true, "license": "MIT", "peerDependencies": { "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" } }, "node_modules/aggregate-error": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/aggregate-error/-/aggregate-error-3.1.0.tgz", "integrity": "sha512-4I7Td01quW/RpocfNayFdFVk1qSuoh0E7JrbRJ16nH01HhKFQ88INq9Sd+nd72zqRySlr9BmDA8xlEJ6vJMrYA==", "dependencies": { "clean-stack": "^2.0.0", "indent-string": "^4.0.0" }, "engines": { "node": ">=8" } }, "node_modules/ajv": { "version": "6.14.0", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.14.0.tgz", "integrity": "sha512-IWrosm/yrn43eiKqkfkHis7QioDleaXQHdDVPKg0FSwwd/DuvyX79TZnFOnYpB7dcsFAMmtFztZuXPDvSePkFw==", "dev": true, "license": "MIT", "dependencies": { "fast-deep-equal": "^3.1.1", "fast-json-stable-stringify": "^2.0.0", "json-schema-traverse": "^0.4.1", "uri-js": "^4.2.2" }, "funding": { "type": "github", "url": "https://github.com/sponsors/epoberezkin" } }, "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", "dev": true }, "node_modules/base64-js": { "version": "1.5.1", "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", "funding": [ { "type": "github", "url": "https://github.com/sponsors/feross" }, { "type": "patreon", "url": "https://www.patreon.com/feross" }, { "type": "consulting", "url": "https://feross.org/support" } ] }, "node_modules/boolbase": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/boolbase/-/boolbase-1.0.0.tgz", "integrity": "sha512-JZOSA7Mo9sNGB8+UjSgzdLtokWAky1zbztM3WRLCbZ70/3cTANmQmOdR7y2g+J0e2WXywy1yS468tY+IruqEww==", "dev": true }, "node_modules/bowser": { "version": "2.14.1", "resolved": "https://registry.npmjs.org/bowser/-/bowser-2.14.1.tgz", "integrity": "sha512-tzPjzCxygAKWFOJP011oxFHs57HzIhOEracIgAePE4pqB3LikALKnSzUyU4MGs9/iCEUuHlAJTjTc5M+u7YEGg==", "optional": true }, "node_modules/bson": { "version": "4.7.2", "resolved": "https://registry.npmjs.org/bson/-/bson-4.7.2.tgz", "integrity": "sha512-Ry9wCtIZ5kGqkJoi6aD8KjxFZEx78guTQDnpXWiNthsxzrxAK/i8E6pCHAIZTbaEFWcOCvbecMukfK7XUvyLpQ==", "dependencies": { "buffer": "^5.6.0" }, "engines": { "node": ">=6.9.0" } }, "node_modules/buffer": { "version": "5.7.1", "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz", "integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==", "funding": [ { "type": "github", "url": "https://github.com/sponsors/feross" }, { "type": "patreon", "url": "https://www.patreon.com/feross" }, { "type": "consulting", "url": "https://feross.org/support" } ], "dependencies": { "base64-js": "^1.3.1", "ieee754": "^1.1.13" } }, "node_modules/buffer-equal-constant-time": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz", "integrity": "sha512-zRpUiDwd/xk6ADqPMATG8vc9VPrkck7T07OIx0gnjmJAnHnTVXNQG3vfvWNuiZIkwu9KrKdA1iJKfsfTVxE6NA==" }, "node_modules/bytes": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==", "engines": { "node": ">= 0.8" } }, "node_modules/cache-content-type": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/cache-content-type/-/cache-content-type-1.0.1.tgz", "integrity": "sha512-IKufZ1o4Ut42YUrZSo8+qnMTrFuKkvyoLXUywKz9GJ5BrhOFGhLdkx9sG4KAnVvbY6kEcSFjLQul+DVmBm2bgA==", "dependencies": { "mime-types": "^2.1.18", "ylru": "^1.2.0" }, "engines": { "node": ">= 6.0.0" } }, "node_modules/call-bind-apply-helpers": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==", "dependencies": { "es-errors": "^1.3.0", "function-bind": "^1.1.2" }, "engines": { "node": ">= 0.4" } }, "node_modules/call-bound": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz", "integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==", "dependencies": { "call-bind-apply-helpers": "^1.0.2", "get-intrinsic": "^1.3.0" }, "engines": { "node": ">= 0.4" }, "funding": { "url": "https://github.com/sponsors/ljharb" } }, "node_modules/clean-stack": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/clean-stack/-/clean-stack-2.2.0.tgz", "integrity": "sha512-4diC9HaTE+KRAMWhDhrGOECgWZxoevMc5TlkObMqNSsVU62PYzXZ/SMTjzyGAFF1YusgxGcSWTEXBhp0CPwQ1A==", "engines": { "node": ">=6" } }, "node_modules/co": { "version": "4.6.0", "resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz", "integrity": "sha512-QVb0dM5HvG+uaxitm8wONl7jltx8dqhfU33DcqtOZcLSVIKSDDLDi7+0LbAKiyI8hD9u42m2YxXSkMGWThaecQ==", "engines": { "iojs": ">= 1.0.0", "node": ">= 0.12.0" } }, "node_modules/co-body": { "version": "6.1.0", "resolved": "https://registry.npmjs.org/co-body/-/co-body-6.1.0.tgz", "integrity": "sha512-m7pOT6CdLN7FuXUcpuz/8lfQ/L77x8SchHCF4G0RBTJO20Wzmhn5Sp4/5WsKy8OSpifBSUrmg83qEqaDHdyFuQ==", "dependencies": { "inflation": "^2.0.0", "qs": "^6.5.2", "raw-body": "^2.3.3", "type-is": "^1.6.16" } }, "node_modules/commander": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/commander/-/commander-7.2.0.tgz", "integrity": "sha512-QrWXB+ZQSVPmIWIhtEO9H+gwHaMGYiF5ChvoJ+K9ZGHG/sVsa6yiesAD1GC/x46sET00Xlwo1u49RVVVzvcSkw==", "dev": true, "engines": { "node": ">= 10" } }, "node_modules/compressible": { "version": "2.0.18", "resolved": "https://registry.npmjs.org/compressible/-/compressible-2.0.18.tgz", "integrity": "sha512-AF3r7P5dWxL8MxyITRMlORQNaOA2IkAFaTr4k7BUumjPtRpGDTZpl0Pb1XCO6JeDCBdp126Cgs9sMxqSjgYyRg==", "dependencies": { "mime-db": ">= 1.43.0 < 2" }, "engines": { "node": ">= 0.6" } }, "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", "dev": true, "license": "MIT" }, "node_modules/content-disposition": { "version": "0.5.4", "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz", "integrity": "sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==", "dependencies": { "safe-buffer": "5.2.1" }, "engines": { "node": ">= 0.6" } }, "node_modules/content-type": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz", "integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==", "engines": { "node": ">= 0.6" } }, "node_modules/cookies": { "version": "0.9.1", "resolved": "https://registry.npmjs.org/cookies/-/cookies-0.9.1.tgz", "integrity": "sha512-TG2hpqe4ELx54QER/S3HQ9SRVnQnGBtKUz5bLQWtYAQ+o6GpgMs6sYUvaiJjVxb+UXwhRhAEP3m7LbsIZ77Hmw==", "dependencies": { "depd": "~2.0.0", "keygrip": "~1.1.0" }, "engines": { "node": ">= 0.8" } }, "node_modules/crelt": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/crelt/-/crelt-1.0.6.tgz", "integrity": "sha512-VQ2MBenTq1fWZUH9DJNGti7kKv6EeAuYr3cLwxUWhIu1baTaXh4Ib5W2CqHVqib4/MqbYGJqiL3Zb8GJZr3l4g==", "dev": true }, "node_modules/cross-spawn": { "version": "7.0.6", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", "dev": true, "license": "MIT", "dependencies": { "path-key": "^3.1.0", "shebang-command": "^2.0.0", "which": "^2.0.1" }, "engines": { "node": ">= 8" } }, "node_modules/css-select": { "version": "5.2.2", "resolved": "https://registry.npmjs.org/css-select/-/css-select-5.2.2.tgz", "integrity": "sha512-TizTzUddG/xYLA3NXodFM0fSbNizXjOKhqiQQwvhlspadZokn1KDy0NZFS0wuEubIYAV5/c1/lAr0TaaFXEXzw==", "dev": true, "dependencies": { "boolbase": "^1.0.0", "css-what": "^6.1.0", "domhandler": "^5.0.2", "domutils": "^3.0.1", "nth-check": "^2.0.1" }, "funding": { "url": "https://github.com/sponsors/fb55" } }, "node_modules/css-tree": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/css-tree/-/css-tree-2.3.1.tgz", "integrity": "sha512-6Fv1DV/TYw//QF5IzQdqsNDjx/wc8TrMBZsqjL9eW01tWb7R7k/mq+/VXfJCl7SoD5emsJop9cOByJZfs8hYIw==", "dev": true, "dependencies": { "mdn-data": "2.0.30", "source-map-js": "^1.0.1" }, "engines": { "node": "^10 || ^12.20.0 || ^14.13.0 || >=15.0.0" } }, "node_modules/css-what": { "version": "6.2.2", "resolved": "https://registry.npmjs.org/css-what/-/css-what-6.2.2.tgz", "integrity": "sha512-u/O3vwbptzhMs3L1fQE82ZSLHQQfto5gyZzwteVIEyeaY5Fc7R4dapF/BvRoSYFeqfBk4m0V1Vafq5Pjv25wvA==", "dev": true, "engines": { "node": ">= 6" }, "funding": { "url": "https://github.com/sponsors/fb55" } }, "node_modules/csso": { "version": "5.0.5", "resolved": "https://registry.npmjs.org/csso/-/csso-5.0.5.tgz", "integrity": "sha512-0LrrStPOdJj+SPCCrGhzryycLjwcgUSHBtxNA8aIDxf0GLsRh1cKYhB00Gd1lDOS4yGH69+SNn13+TWbVHETFQ==", "dev": true, "dependencies": { "css-tree": "~2.2.0" }, "engines": { "node": "^10 || ^12.20.0 || ^14.13.0 || >=15.0.0", "npm": ">=7.0.0" } }, "node_modules/csso/node_modules/css-tree": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/css-tree/-/css-tree-2.2.1.tgz", "integrity": "sha512-OA0mILzGc1kCOCSJerOeqDxDQ4HOh+G8NbOJFOTgOCzpw7fCBubk0fEyxp8AgOL/jvLgYA/uV0cMbe43ElF1JA==", "dev": true, "dependencies": { "mdn-data": "2.0.28", "source-map-js": "^1.0.1" }, "engines": { "node": "^10 || ^12.20.0 || ^14.13.0 || >=15.0.0", "npm": ">=7.0.0" } }, "node_modules/csso/node_modules/mdn-data": { "version": "2.0.28", "resolved": "https://registry.npmjs.org/mdn-data/-/mdn-data-2.0.28.tgz", "integrity": "sha512-aylIc7Z9y4yzHYAJNuESG3hfhC+0Ibp/MAMiaOZgNv4pmEdFyfZhhhny4MNiAfWdBQ1RQ2mfDWmM1x8SvGyp8g==", "dev": true }, "node_modules/debug": { "version": "4.4.3", "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", "dependencies": { "ms": "^2.1.3" }, "engines": { "node": ">=6.0" }, "peerDependenciesMeta": { "supports-color": { "optional": true } } }, "node_modules/deep-equal": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-1.0.1.tgz", "integrity": "sha512-bHtC0iYvWhyaTzvV3CZgPeZQqCOBGyGsVV7v4eevpdkLHfiSrXUdBG+qAuSz4RI70sszvjQ1QSZ98An1yNwpSw==" }, "node_modules/deep-is": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz", "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==", "dev": true }, "node_modules/delegates": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz", "integrity": "sha512-bd2L678uiWATM6m5Z1VzNCErI3jiGzt6HGY8OVICs40JQq/HALfbyNJmp0UDakEY4pMMaN0Ly5om/B1VI/+xfQ==" }, "node_modules/depd": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==", "engines": { "node": ">= 0.8" } }, "node_modules/destroy": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz", "integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==", "engines": { "node": ">= 0.8", "npm": "1.2.8000 || >= 1.4.16" } }, "node_modules/detect-libc": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz", "integrity": "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==", "dev": true, "license": "Apache-2.0", "engines": { "node": ">=8" } }, "node_modules/dom-serializer": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-2.0.0.tgz", "integrity": "sha512-wIkAryiqt/nV5EQKqQpo3SToSOV9J0DnbJqwK7Wv/Trc92zIAYZ4FlMu+JPFW1DfGFt81ZTCGgDEabffXeLyJg==", "dev": true, "dependencies": { "domelementtype": "^2.3.0", "domhandler": "^5.0.2", "entities": "^4.2.0" }, "funding": { "url": "https://github.com/cheeriojs/dom-serializer?sponsor=1" } }, "node_modules/domelementtype": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-2.3.0.tgz", "integrity": "sha512-OLETBj6w0OsagBwdXnPdN0cnMfF9opN69co+7ZrbfPGrdpPVNBUj02spi6B1N7wChLQiPn4CSH/zJvXw56gmHw==", "dev": true, "funding": [ { "type": "github", "url": "https://github.com/sponsors/fb55" } ] }, "node_modules/domhandler": { "version": "5.0.3", "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-5.0.3.tgz", "integrity": "sha512-cgwlv/1iFQiFnU96XXgROh8xTeetsnJiDsTc7TYCLFd9+/WNkIqPTxiM/8pSd8VIrhXGTf1Ny1q1hquVqDJB5w==", "dev": true, "dependencies": { "domelementtype": "^2.3.0" }, "engines": { "node": ">= 4" }, "funding": { "url": "https://github.com/fb55/domhandler?sponsor=1" } }, "node_modules/domutils": { "version": "3.2.2", "resolved": "https://registry.npmjs.org/domutils/-/domutils-3.2.2.tgz", "integrity": "sha512-6kZKyUajlDuqlHKVX1w7gyslj9MPIXzIFiz/rGu35uC1wMi+kMhQwGhl4lt9unC9Vb9INnY9Z3/ZA3+FhASLaw==", "dev": true, "dependencies": { "dom-serializer": "^2.0.0", "domelementtype": "^2.3.0", "domhandler": "^5.0.3" }, "funding": { "url": "https://github.com/fb55/domutils?sponsor=1" } }, "node_modules/dunder-proto": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==", "dependencies": { "call-bind-apply-helpers": "^1.0.1", "es-errors": "^1.3.0", "gopd": "^1.2.0" }, "engines": { "node": ">= 0.4" } }, "node_modules/ecdsa-sig-formatter": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz", "integrity": "sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ==", "dependencies": { "safe-buffer": "^5.0.1" } }, "node_modules/ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==" }, "node_modules/encodeurl": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", "integrity": "sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w==", "engines": { "node": ">= 0.8" } }, "node_modules/enhanced-resolve": { "version": "5.20.0", "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.20.0.tgz", "integrity": "sha512-/ce7+jQ1PQ6rVXwe+jKEg5hW5ciicHwIQUagZkp6IufBoY3YDgdTTY1azVs0qoRgVmvsNB+rbjLJxDAeHHtwsQ==", "dev": true, "license": "MIT", "dependencies": { "graceful-fs": "^4.2.4", "tapable": "^2.3.0" }, "engines": { "node": ">=10.13.0" } }, "node_modules/entities": { "version": "4.5.0", "resolved": "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz", "integrity": "sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==", "dev": true, "engines": { "node": ">=0.12" }, "funding": { "url": "https://github.com/fb55/entities?sponsor=1" } }, "node_modules/es-define-property": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", "engines": { "node": ">= 0.4" } }, "node_modules/es-errors": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", "engines": { "node": ">= 0.4" } }, "node_modules/es-object-atoms": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz", "integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==", "dependencies": { "es-errors": "^1.3.0" }, "engines": { "node": ">= 0.4" } }, "node_modules/esbuild": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.27.4.tgz", "integrity": "sha512-Rq4vbHnYkK5fws5NF7MYTU68FPRE1ajX7heQ/8QXXWqNgqqJ/GkmmyxIzUnf2Sr/bakf8l54716CcMGHYhMrrQ==", "dev": true, "hasInstallScript": true, "license": "MIT", "bin": { "esbuild": "bin/esbuild" }, "engines": { "node": ">=18" }, "optionalDependencies": { "@esbuild/aix-ppc64": "0.27.4", "@esbuild/android-arm": "0.27.4", "@esbuild/android-arm64": "0.27.4", "@esbuild/android-x64": "0.27.4", "@esbuild/darwin-arm64": "0.27.4", "@esbuild/darwin-x64": "0.27.4", "@esbuild/freebsd-arm64": "0.27.4", "@esbuild/freebsd-x64": "0.27.4", "@esbuild/linux-arm": "0.27.4", "@esbuild/linux-arm64": "0.27.4", "@esbuild/linux-ia32": "0.27.4", "@esbuild/linux-loong64": "0.27.4", "@esbuild/linux-mips64el": "0.27.4", "@esbuild/linux-ppc64": "0.27.4", "@esbuild/linux-riscv64": "0.27.4", "@esbuild/linux-s390x": "0.27.4", "@esbuild/linux-x64": "0.27.4", "@esbuild/netbsd-arm64": "0.27.4", "@esbuild/netbsd-x64": "0.27.4", "@esbuild/openbsd-arm64": "0.27.4", "@esbuild/openbsd-x64": "0.27.4", "@esbuild/openharmony-arm64": "0.27.4", "@esbuild/sunos-x64": "0.27.4", "@esbuild/win32-arm64": "0.27.4", "@esbuild/win32-ia32": "0.27.4", "@esbuild/win32-x64": "0.27.4" } }, "node_modules/escape-html": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==" }, "node_modules/escape-string-regexp": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", "dev": true, "engines": { "node": ">=10" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/eslint": { "version": "10.0.3", "resolved": "https://registry.npmjs.org/eslint/-/eslint-10.0.3.tgz", "integrity": "sha512-COV33RzXZkqhG9P2rZCFl9ZmJ7WL+gQSCRzE7RhkbclbQPtLAWReL7ysA0Sh4c8Im2U9ynybdR56PV0XcKvqaQ==", "dev": true, "license": "MIT", "dependencies": { "@eslint-community/eslint-utils": "^4.8.0", "@eslint-community/regexpp": "^4.12.2", "@eslint/config-array": "^0.23.3", "@eslint/config-helpers": "^0.5.2", "@eslint/core": "^1.1.1", "@eslint/plugin-kit": "^0.6.1", "@humanfs/node": "^0.16.6", "@humanwhocodes/module-importer": "^1.0.1", "@humanwhocodes/retry": "^0.4.2", "@types/estree": "^1.0.6", "ajv": "^6.14.0", "cross-spawn": "^7.0.6", "debug": "^4.3.2", "escape-string-regexp": "^4.0.0", "eslint-scope": "^9.1.2", "eslint-visitor-keys": "^5.0.1", "espree": "^11.1.1", "esquery": "^1.7.0", "esutils": "^2.0.2", "fast-deep-equal": "^3.1.3", "file-entry-cache": "^8.0.0", "find-up": "^5.0.0", "glob-parent": "^6.0.2", "ignore": "^5.2.0", "imurmurhash": "^0.1.4", "is-glob": "^4.0.0", "json-stable-stringify-without-jsonify": "^1.0.1", "minimatch": "^10.2.4", "natural-compare": "^1.4.0", "optionator": "^0.9.3" }, "bin": { "eslint": "bin/eslint.js" }, "engines": { "node": "^20.19.0 || ^22.13.0 || >=24" }, "funding": { "url": "https://eslint.org/donate" }, "peerDependencies": { "jiti": "*" }, "peerDependenciesMeta": { "jiti": { "optional": true } } }, "node_modules/eslint-config-prettier": { "version": "10.1.8", "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-10.1.8.tgz", "integrity": "sha512-82GZUjRS0p/jganf6q1rEO25VSoHH0hKPCTrgillPjdI/3bgBhAE1QzHrHTizjpRvy6pGAvKjDJtk2pF9NDq8w==", "dev": true, "license": "MIT", "bin": { "eslint-config-prettier": "bin/cli.js" }, "funding": { "url": "https://opencollective.com/eslint-config-prettier" }, "peerDependencies": { "eslint": ">=7.0.0" } }, "node_modules/eslint-scope": { "version": "9.1.2", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-9.1.2.tgz", "integrity": "sha512-xS90H51cKw0jltxmvmHy2Iai1LIqrfbw57b79w/J7MfvDfkIkFZ+kj6zC3BjtUwh150HsSSdxXZcsuv72miDFQ==", "dev": true, "license": "BSD-2-Clause", "dependencies": { "@types/esrecurse": "^4.3.1", "@types/estree": "^1.0.8", "esrecurse": "^4.3.0", "estraverse": "^5.2.0" }, "engines": { "node": "^20.19.0 || ^22.13.0 || >=24" }, "funding": { "url": "https://opencollective.com/eslint" } }, "node_modules/eslint-visitor-keys": { "version": "3.4.3", "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.4.3.tgz", "integrity": "sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag==", "dev": true, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" }, "funding": { "url": "https://opencollective.com/eslint" } }, "node_modules/eslint/node_modules/balanced-match": { "version": "4.0.4", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-4.0.4.tgz", "integrity": "sha512-BLrgEcRTwX2o6gGxGOCNyMvGSp35YofuYzw9h1IMTRmKqttAZZVU67bdb9Pr2vUHA8+j3i2tJfjO6C6+4myGTA==", "dev": true, "license": "MIT", "engines": { "node": "18 || 20 || >=22" } }, "node_modules/eslint/node_modules/brace-expansion": { "version": "5.0.4", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.4.tgz", "integrity": "sha512-h+DEnpVvxmfVefa4jFbCf5HdH5YMDXRsmKflpf1pILZWRFlTbJpxeU55nJl4Smt5HQaGzg1o6RHFPJaOqnmBDg==", "dev": true, "license": "MIT", "dependencies": { "balanced-match": "^4.0.2" }, "engines": { "node": "18 || 20 || >=22" } }, "node_modules/eslint/node_modules/eslint-visitor-keys": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-5.0.1.tgz", "integrity": "sha512-tD40eHxA35h0PEIZNeIjkHoDR4YjjJp34biM0mDvplBe//mB+IHCqHDGV7pxF+7MklTvighcCPPZC7ynWyjdTA==", "dev": true, "license": "Apache-2.0", "engines": { "node": "^20.19.0 || ^22.13.0 || >=24" }, "funding": { "url": "https://opencollective.com/eslint" } }, "node_modules/eslint/node_modules/minimatch": { "version": "10.2.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.2.4.tgz", "integrity": "sha512-oRjTw/97aTBN0RHbYCdtF1MQfvusSIBQM0IZEgzl6426+8jSC0nF1a/GmnVLpfB9yyr6g6FTqWqiZVbxrtaCIg==", "dev": true, "license": "BlueOak-1.0.0", "dependencies": { "brace-expansion": "^5.0.2" }, "engines": { "node": "18 || 20 || >=22" }, "funding": { "url": "https://github.com/sponsors/isaacs" } }, "node_modules/espree": { "version": "11.2.0", "resolved": "https://registry.npmjs.org/espree/-/espree-11.2.0.tgz", "integrity": "sha512-7p3DrVEIopW1B1avAGLuCSh1jubc01H2JHc8B4qqGblmg5gI9yumBgACjWo4JlIc04ufug4xJ3SQI8HkS/Rgzw==", "dev": true, "license": "BSD-2-Clause", "dependencies": { "acorn": "^8.16.0", "acorn-jsx": "^5.3.2", "eslint-visitor-keys": "^5.0.1" }, "engines": { "node": "^20.19.0 || ^22.13.0 || >=24" }, "funding": { "url": "https://opencollective.com/eslint" } }, "node_modules/espree/node_modules/eslint-visitor-keys": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-5.0.1.tgz", "integrity": "sha512-tD40eHxA35h0PEIZNeIjkHoDR4YjjJp34biM0mDvplBe//mB+IHCqHDGV7pxF+7MklTvighcCPPZC7ynWyjdTA==", "dev": true, "license": "Apache-2.0", "engines": { "node": "^20.19.0 || ^22.13.0 || >=24" }, "funding": { "url": "https://opencollective.com/eslint" } }, "node_modules/espresso-iisojs": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/espresso-iisojs/-/espresso-iisojs-1.0.8.tgz", "integrity": "sha512-S3D62BA/jBUCIQJ3VlBGMSxGwPyyV7ttduiJvyaD4dWyhiC/9TnJTaiurx4r8bqcYZ1J0KELliub4xo8neKjSA==" }, "node_modules/esquery": { "version": "1.7.0", "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.7.0.tgz", "integrity": "sha512-Ap6G0WQwcU/LHsvLwON1fAQX9Zp0A2Y6Y/cJBl9r/JbW90Zyg4/zbG6zzKa2OTALELarYHmKu0GhpM5EO+7T0g==", "dev": true, "license": "BSD-3-Clause", "dependencies": { "estraverse": "^5.1.0" }, "engines": { "node": ">=0.10" } }, "node_modules/esrecurse": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.3.0.tgz", "integrity": "sha512-KmfKL3b6G+RXvP8N1vr3Tq1kL/oCFgn2NYXEtqP8/L3pKapUA4G8cFVaoF3SU323CD4XypR/ffioHmkti6/Tag==", "dev": true, "license": "BSD-2-Clause", "dependencies": { "estraverse": "^5.2.0" }, "engines": { "node": ">=4.0" } }, "node_modules/estraverse": { "version": "5.3.0", "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz", "integrity": "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==", "dev": true, "license": "BSD-2-Clause", "engines": { "node": ">=4.0" } }, "node_modules/esutils": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", "integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==", "dev": true, "license": "BSD-2-Clause", "engines": { "node": ">=0.10.0" } }, "node_modules/fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", "dev": true, "license": "MIT" }, "node_modules/fast-json-stable-stringify": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==", "dev": true, "license": "MIT" }, "node_modules/fast-levenshtein": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", "integrity": "sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==", "dev": true }, "node_modules/fast-xml-builder": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/fast-xml-builder/-/fast-xml-builder-1.1.2.tgz", "integrity": "sha512-NJAmiuVaJEjVa7TjLZKlYd7RqmzOC91EtPFXHvlTcqBVo50Qh7XV5IwvXi1c7NRz2Q/majGX9YLcwJtWgHjtkA==", "funding": [ { "type": "github", "url": "https://github.com/sponsors/NaturalIntelligence" } ], "optional": true, "dependencies": { "path-expression-matcher": "^1.1.3" } }, "node_modules/fast-xml-parser": { "version": "5.4.1", "resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-5.4.1.tgz", "integrity": "sha512-BQ30U1mKkvXQXXkAGcuyUA/GA26oEB7NzOtsxCDtyu62sjGw5QraKFhx2Em3WQNjPw9PG6MQ9yuIIgkSDfGu5A==", "funding": [ { "type": "github", "url": "https://github.com/sponsors/NaturalIntelligence" } ], "optional": true, "dependencies": { "fast-xml-builder": "^1.0.0", "strnum": "^2.1.2" }, "bin": { "fxparser": "src/cli/cli.js" } }, "node_modules/file-entry-cache": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-8.0.0.tgz", "integrity": "sha512-XXTUwCvisa5oacNGRP9SfNtYBNAMi+RPwBFmblZEF7N7swHYQS6/Zfk7SRwx4D5j3CH211YNRco1DEMNVfZCnQ==", "dev": true, "license": "MIT", "dependencies": { "flat-cache": "^4.0.0" }, "engines": { "node": ">=16.0.0" } }, "node_modules/find-up": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz", "integrity": "sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==", "dev": true, "dependencies": { "locate-path": "^6.0.0", "path-exists": "^4.0.0" }, "engines": { "node": ">=10" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/flat-cache": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-4.0.1.tgz", "integrity": "sha512-f7ccFPK3SXFHpx15UIGyRJ/FJQctuKZ0zVuN3frBo4HnK3cay9VEW0R6yPYFHC0AgqhukPzKjq22t5DmAyqGyw==", "dev": true, "license": "MIT", "dependencies": { "flatted": "^3.2.9", "keyv": "^4.5.4" }, "engines": { "node": ">=16" } }, "node_modules/flatted": { "version": "3.4.1", "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.4.1.tgz", "integrity": "sha512-IxfVbRFVlV8V/yRaGzk0UVIcsKKHMSfYw66T/u4nTwlWteQePsxe//LjudR1AMX4tZW3WFCh3Zqa/sjlqpbURQ==", "dev": true }, "node_modules/fresh": { "version": "0.5.2", "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", "integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==", "engines": { "node": ">= 0.6" } }, "node_modules/function-bind": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", "funding": { "url": "https://github.com/sponsors/ljharb" } }, "node_modules/generator-function": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/generator-function/-/generator-function-2.0.1.tgz", "integrity": "sha512-SFdFmIJi+ybC0vjlHN0ZGVGHc3lgE0DxPAT0djjVg+kjOnSqclqmj0KQ7ykTOLP6YxoqOvuAODGdcHJn+43q3g==", "engines": { "node": ">= 0.4" } }, "node_modules/get-intrinsic": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz", "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==", "dependencies": { "call-bind-apply-helpers": "^1.0.2", "es-define-property": "^1.0.1", "es-errors": "^1.3.0", "es-object-atoms": "^1.1.1", "function-bind": "^1.1.2", "get-proto": "^1.0.1", "gopd": "^1.2.0", "has-symbols": "^1.1.0", "hasown": "^2.0.2", "math-intrinsics": "^1.1.0" }, "engines": { "node": ">= 0.4" }, "funding": { "url": "https://github.com/sponsors/ljharb" } }, "node_modules/get-proto": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz", "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==", "dependencies": { "dunder-proto": "^1.0.1", "es-object-atoms": "^1.0.0" }, "engines": { "node": ">= 0.4" } }, "node_modules/glob-parent": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz", "integrity": "sha512-XxwI8EOhVQgWp6iDL+3b0r86f4d6AX6zSU55HfB4ydCEuXLXc5FcYeOu+nnGftS4TEju/11rt4KJPTMgbfmv4A==", "dev": true, "dependencies": { "is-glob": "^4.0.3" }, "engines": { "node": ">=10.13.0" } }, "node_modules/globals": { "version": "17.4.0", "resolved": "https://registry.npmjs.org/globals/-/globals-17.4.0.tgz", "integrity": "sha512-hjrNztw/VajQwOLsMNT1cbJiH2muO3OROCHnbehc8eY5JyD2gqz4AcMHPqgaOR59DjgUjYAYLeH699g/eWi2jw==", "dev": true, "license": "MIT", "engines": { "node": ">=18" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/gopd": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", "engines": { "node": ">= 0.4" }, "funding": { "url": "https://github.com/sponsors/ljharb" } }, "node_modules/graceful-fs": { "version": "4.2.11", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==", "dev": true, "license": "ISC" }, "node_modules/has-symbols": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==", "engines": { "node": ">= 0.4" }, "funding": { "url": "https://github.com/sponsors/ljharb" } }, "node_modules/has-tostringtag": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz", "integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==", "dependencies": { "has-symbols": "^1.0.3" }, "engines": { "node": ">= 0.4" }, "funding": { "url": "https://github.com/sponsors/ljharb" } }, "node_modules/hasown": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==", "dependencies": { "function-bind": "^1.1.2" }, "engines": { "node": ">= 0.4" } }, "node_modules/http-assert": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/http-assert/-/http-assert-1.5.0.tgz", "integrity": "sha512-uPpH7OKX4H25hBmU6G1jWNaqJGpTXxey+YOUizJUAgu0AjLUeC8D73hTrhvDS5D+GJN1DN1+hhc/eF/wpxtp0w==", "dependencies": { "deep-equal": "~1.0.1", "http-errors": "~1.8.0" }, "engines": { "node": ">= 0.8" } }, "node_modules/http-assert/node_modules/depd": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", "integrity": "sha512-7emPTl6Dpo6JRXOXjLRxck+FlLRX5847cLKEn00PLAgc3g2hTZZgr+e4c2v6QpSmLeFP3n5yUo7ft6avBK/5jQ==", "engines": { "node": ">= 0.6" } }, "node_modules/http-assert/node_modules/http-errors": { "version": "1.8.1", "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.8.1.tgz", "integrity": "sha512-Kpk9Sm7NmI+RHhnj6OIWDI1d6fIoFAtFt9RLaTMRlg/8w49juAStsrBgp0Dp4OdxdVbRIeKhtCUvoi/RuAhO4g==", "dependencies": { "depd": "~1.1.2", "inherits": "2.0.4", "setprototypeof": "1.2.0", "statuses": ">= 1.5.0 < 2", "toidentifier": "1.0.1" }, "engines": { "node": ">= 0.6" } }, "node_modules/http-assert/node_modules/statuses": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", "integrity": "sha512-OpZ3zP+jT1PI7I8nemJX4AKmAX070ZkYPVWV/AaKTJl+tXCTGyVdC1a4SL8RUQYEwk/f34ZX8UTykN68FwrqAA==", "engines": { "node": ">= 0.6" } }, "node_modules/http-errors": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.1.tgz", "integrity": "sha512-4FbRdAX+bSdmo4AUFuS0WNiPz8NgFt+r8ThgNWmlrjQjt1Q7ZR9+zTlce2859x4KSXrwIsaeTqDoKQmtP8pLmQ==", "dependencies": { "depd": "~2.0.0", "inherits": "~2.0.4", "setprototypeof": "~1.2.0", "statuses": "~2.0.2", "toidentifier": "~1.0.1" }, "engines": { "node": ">= 0.8" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/express" } }, "node_modules/iconv-lite": { "version": "0.6.3", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", "dependencies": { "safer-buffer": ">= 2.1.2 < 3.0.0" }, "engines": { "node": ">=0.10.0" } }, "node_modules/ieee754": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", "funding": [ { "type": "github", "url": "https://github.com/sponsors/feross" }, { "type": "patreon", "url": "https://www.patreon.com/feross" }, { "type": "consulting", "url": "https://feross.org/support" } ] }, "node_modules/ignore": { "version": "5.3.2", "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz", "integrity": "sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g==", "dev": true, "engines": { "node": ">= 4" } }, "node_modules/imurmurhash": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", "integrity": "sha512-JmXMZ6wuvDmLiHEml9ykzqO6lwFbof0GG4IkcGaENdCRDDmMVnny7s5HsIgHCbaq0w2MyPhDqkhTUgS2LU2PHA==", "dev": true, "engines": { "node": ">=0.8.19" } }, "node_modules/indent-string": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/indent-string/-/indent-string-4.0.0.tgz", "integrity": "sha512-EdDDZu4A2OyIK7Lr/2zG+w5jmbuk1DVBnEwREQvBzspBJkCEbRa8GxU1lghYcaGJCnRWibjDXlq779X1/y5xwg==", "engines": { "node": ">=8" } }, "node_modules/inflation": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/inflation/-/inflation-2.1.0.tgz", "integrity": "sha512-t54PPJHG1Pp7VQvxyVCJ9mBbjG3Hqryges9bXoOO6GExCPa+//i/d5GSuFtpx3ALLd7lgIAur6zrIlBQyJuMlQ==", "engines": { "node": ">= 0.8.0" } }, "node_modules/inherits": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" }, "node_modules/ip-address": { "version": "10.1.0", "resolved": "https://registry.npmjs.org/ip-address/-/ip-address-10.1.0.tgz", "integrity": "sha512-XXADHxXmvT9+CRxhXg56LJovE+bmWnEWB78LB83VZTprKTmaC5QfruXocxzTZ2Kl0DNwKuBdlIhjL8LeY8Sf8Q==", "engines": { "node": ">= 12" } }, "node_modules/ipaddr.js": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-2.3.0.tgz", "integrity": "sha512-Zv/pA+ciVFbCSBBjGfaKUya/CcGmUHzTydLMaTwrUUEM2DIEO3iZvueGxmacvmN50fGpGVKeTXpb2LcYQxeVdg==", "engines": { "node": ">= 10" } }, "node_modules/is-extglob": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", "dev": true, "engines": { "node": ">=0.10.0" } }, "node_modules/is-generator-function": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/is-generator-function/-/is-generator-function-1.1.2.tgz", "integrity": "sha512-upqt1SkGkODW9tsGNG5mtXTXtECizwtS2kA161M+gJPc1xdb/Ax629af6YrTwcOeQHbewrPNlE5Dx7kzvXTizA==", "dependencies": { "call-bound": "^1.0.4", "generator-function": "^2.0.0", "get-proto": "^1.0.1", "has-tostringtag": "^1.0.2", "safe-regex-test": "^1.1.0" }, "engines": { "node": ">= 0.4" }, "funding": { "url": "https://github.com/sponsors/ljharb" } }, "node_modules/is-glob": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", "dev": true, "dependencies": { "is-extglob": "^2.1.1" }, "engines": { "node": ">=0.10.0" } }, "node_modules/is-regex": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.2.1.tgz", "integrity": "sha512-MjYsKHO5O7mCsmRGxWcLWheFqN9DJ/2TmngvjKXihe6efViPqc274+Fx/4fYj/r03+ESvBdTXK0V6tA3rgez1g==", "dependencies": { "call-bound": "^1.0.2", "gopd": "^1.2.0", "has-tostringtag": "^1.0.2", "hasown": "^2.0.2" }, "engines": { "node": ">= 0.4" }, "funding": { "url": "https://github.com/sponsors/ljharb" } }, "node_modules/isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", "dev": true, "license": "ISC" }, "node_modules/jiti": { "version": "2.6.1", "resolved": "https://registry.npmjs.org/jiti/-/jiti-2.6.1.tgz", "integrity": "sha512-ekilCSN1jwRvIbgeg/57YFh8qQDNbwDb9xT/qu2DAHbFFZUicIl4ygVaAvzveMhMVr3LnpSKTNnwt8PoOfmKhQ==", "dev": true, "license": "MIT", "bin": { "jiti": "lib/jiti-cli.mjs" } }, "node_modules/json-buffer": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.1.tgz", "integrity": "sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ==", "dev": true, "license": "MIT" }, "node_modules/json-schema-traverse": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", "dev": true, "license": "MIT" }, "node_modules/json-stable-stringify-without-jsonify": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz", "integrity": "sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==", "dev": true }, "node_modules/jsonwebtoken": { "version": "9.0.3", "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-9.0.3.tgz", "integrity": "sha512-MT/xP0CrubFRNLNKvxJ2BYfy53Zkm++5bX9dtuPbqAeQpTVe0MQTFhao8+Cp//EmJp244xt6Drw/GVEGCUj40g==", "dependencies": { "jws": "^4.0.1", "lodash.includes": "^4.3.0", "lodash.isboolean": "^3.0.3", "lodash.isinteger": "^4.0.4", "lodash.isnumber": "^3.0.3", "lodash.isplainobject": "^4.0.6", "lodash.isstring": "^4.0.1", "lodash.once": "^4.0.0", "ms": "^2.1.1", "semver": "^7.5.4" }, "engines": { "node": ">=12", "npm": ">=6" } }, "node_modules/jwa": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/jwa/-/jwa-2.0.1.tgz", "integrity": "sha512-hRF04fqJIP8Abbkq5NKGN0Bbr3JxlQ+qhZufXVr0DvujKy93ZCbXZMHDL4EOtodSbCWxOqR8MS1tXA5hwqCXDg==", "dependencies": { "buffer-equal-constant-time": "^1.0.1", "ecdsa-sig-formatter": "1.0.11", "safe-buffer": "^5.0.1" } }, "node_modules/jws": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/jws/-/jws-4.0.1.tgz", "integrity": "sha512-EKI/M/yqPncGUUh44xz0PxSidXFr/+r0pA70+gIYhjv+et7yxM+s29Y+VGDkovRofQem0fs7Uvf4+YmAdyRduA==", "dependencies": { "jwa": "^2.0.1", "safe-buffer": "^5.0.1" } }, "node_modules/keygrip": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/keygrip/-/keygrip-1.1.0.tgz", "integrity": "sha512-iYSchDJ+liQ8iwbSI2QqsQOvqv58eJCEanyJPJi+Khyu8smkcKSFUCbPwzFcL7YVtZ6eONjqRX/38caJ7QjRAQ==", "dependencies": { "tsscmp": "1.0.6" }, "engines": { "node": ">= 0.6" } }, "node_modules/keyv": { "version": "4.5.4", "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz", "integrity": "sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==", "dev": true, "license": "MIT", "dependencies": { "json-buffer": "3.0.1" } }, "node_modules/koa": { "version": "2.16.4", "resolved": "https://registry.npmjs.org/koa/-/koa-2.16.4.tgz", "integrity": "sha512-3An0GCLDSR34tsCO4H8Tef8Pp2ngtaZDAZnsWJYelqXUK5wyiHvGItgK/xcSkmHLSTn1Jcho1mRQs2ehRzvKKw==", "dependencies": { "accepts": "^1.3.5", "cache-content-type": "^1.0.0", "content-disposition": "~0.5.2", "content-type": "^1.0.4", "cookies": "~0.9.0", "debug": "^4.3.2", "delegates": "^1.0.0", "depd": "^2.0.0", "destroy": "^1.0.4", "encodeurl": "^1.0.2", "escape-html": "^1.0.3", "fresh": "~0.5.2", "http-assert": "^1.3.0", "http-errors": "^1.6.3", "is-generator-function": "^1.0.7", "koa-compose": "^4.1.0", "koa-convert": "^2.0.0", "on-finished": "^2.3.0", "only": "~0.0.2", "parseurl": "^1.3.2", "statuses": "^1.5.0", "type-is": "^1.6.16", "vary": "^1.1.2" }, "engines": { "node": "^4.8.4 || ^6.10.1 || ^7.10.1 || >= 8.1.4" } }, "node_modules/koa-compose": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/koa-compose/-/koa-compose-4.1.0.tgz", "integrity": "sha512-8ODW8TrDuMYvXRwra/Kh7/rJo9BtOfPc6qO8eAfC80CnCvSjSl0bkRM24X6/XBBEyj0v1nRUQ1LyOy3dbqOWXw==" }, "node_modules/koa-compress": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/koa-compress/-/koa-compress-5.2.0.tgz", "integrity": "sha512-RsRnI+v+/rs1lYpcAUcxowUzHYssf71qbMr0Mpdq1wktbtXDZmxBIgxJHtaEsBjSe4jiWYELpGFbASa2AemmOg==", "dependencies": { "bytes": "^3.1.2", "compressible": "^2.0.18", "http-errors": "^2.0.1", "koa-is-json": "^1.0.0", "negotiator": "^1.0.0" }, "engines": { "node": ">= 12" } }, "node_modules/koa-compress/node_modules/negotiator": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-1.0.0.tgz", "integrity": "sha512-8Ofs/AUQh8MaEcrlq5xOX0CQ9ypTF5dl78mjlMNfOK08fzpgTHQRQPBxcPlEtIw0yRpws+Zo/3r+5WRby7u3Gg==", "engines": { "node": ">= 0.6" } }, "node_modules/koa-convert": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/koa-convert/-/koa-convert-2.0.0.tgz", "integrity": "sha512-asOvN6bFlSnxewce2e/DK3p4tltyfC4VM7ZwuTuepI7dEQVcvpyFuBcEARu1+Hxg8DIwytce2n7jrZtRlPrARA==", "dependencies": { "co": "^4.6.0", "koa-compose": "^4.1.0" }, "engines": { "node": ">= 10" } }, "node_modules/koa-is-json": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/koa-is-json/-/koa-is-json-1.0.0.tgz", "integrity": "sha512-+97CtHAlWDx0ndt0J8y3P12EWLwTLMXIfMnYDev3wOTwH/RpBGMlfn4bDXlMEg1u73K6XRE9BbUp+5ZAYoRYWw==" }, "node_modules/koa-jwt": { "version": "4.0.4", "resolved": "https://registry.npmjs.org/koa-jwt/-/koa-jwt-4.0.4.tgz", "integrity": "sha512-Tid9BQfpVtUG/8YZV38a+hDKll0pfVhfl7A/2cNaYThS1cxMFXylZzfARqHQqvNhHy9qM+qkxd4/z6EaIV4SAQ==", "dependencies": { "jsonwebtoken": "^9.0.0", "koa-unless": "^1.0.7", "p-any": "^2.1.0" }, "engines": { "node": ">= 8" } }, "node_modules/koa-send": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/koa-send/-/koa-send-5.0.1.tgz", "integrity": "sha512-tmcyQ/wXXuxpDxyNXv5yNNkdAMdFRqwtegBXUaowiQzUKqJehttS0x2j0eOZDQAyloAth5w6wwBImnFzkUz3pQ==", "dependencies": { "debug": "^4.1.1", "http-errors": "^1.7.3", "resolve-path": "^1.4.0" }, "engines": { "node": ">= 8" } }, "node_modules/koa-send/node_modules/depd": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", "integrity": "sha512-7emPTl6Dpo6JRXOXjLRxck+FlLRX5847cLKEn00PLAgc3g2hTZZgr+e4c2v6QpSmLeFP3n5yUo7ft6avBK/5jQ==", "engines": { "node": ">= 0.6" } }, "node_modules/koa-send/node_modules/http-errors": { "version": "1.8.1", "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.8.1.tgz", "integrity": "sha512-Kpk9Sm7NmI+RHhnj6OIWDI1d6fIoFAtFt9RLaTMRlg/8w49juAStsrBgp0Dp4OdxdVbRIeKhtCUvoi/RuAhO4g==", "dependencies": { "depd": "~1.1.2", "inherits": "2.0.4", "setprototypeof": "1.2.0", "statuses": ">= 1.5.0 < 2", "toidentifier": "1.0.1" }, "engines": { "node": ">= 0.6" } }, "node_modules/koa-send/node_modules/statuses": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", "integrity": "sha512-OpZ3zP+jT1PI7I8nemJX4AKmAX070ZkYPVWV/AaKTJl+tXCTGyVdC1a4SL8RUQYEwk/f34ZX8UTykN68FwrqAA==", "engines": { "node": ">= 0.6" } }, "node_modules/koa-unless": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/koa-unless/-/koa-unless-1.0.7.tgz", "integrity": "sha512-NKiz+nk4KxSJFskiJMuJvxeA41Lcnx3d8Zy+8QETgifm4ab4aOeGD3RgR6bIz0FGNWwo3Fz0DtnK77mEIqHWxA==" }, "node_modules/koa/node_modules/http-errors": { "version": "1.8.1", "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.8.1.tgz", "integrity": "sha512-Kpk9Sm7NmI+RHhnj6OIWDI1d6fIoFAtFt9RLaTMRlg/8w49juAStsrBgp0Dp4OdxdVbRIeKhtCUvoi/RuAhO4g==", "dependencies": { "depd": "~1.1.2", "inherits": "2.0.4", "setprototypeof": "1.2.0", "statuses": ">= 1.5.0 < 2", "toidentifier": "1.0.1" }, "engines": { "node": ">= 0.6" } }, "node_modules/koa/node_modules/http-errors/node_modules/depd": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", "integrity": "sha512-7emPTl6Dpo6JRXOXjLRxck+FlLRX5847cLKEn00PLAgc3g2hTZZgr+e4c2v6QpSmLeFP3n5yUo7ft6avBK/5jQ==", "engines": { "node": ">= 0.6" } }, "node_modules/koa/node_modules/statuses": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", "integrity": "sha512-OpZ3zP+jT1PI7I8nemJX4AKmAX070ZkYPVWV/AaKTJl+tXCTGyVdC1a4SL8RUQYEwk/f34ZX8UTykN68FwrqAA==", "engines": { "node": ">= 0.6" } }, "node_modules/levn": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz", "integrity": "sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==", "dev": true, "dependencies": { "prelude-ls": "^1.2.1", "type-check": "~0.4.0" }, "engines": { "node": ">= 0.8.0" } }, "node_modules/lightningcss": { "version": "1.31.1", "resolved": "https://registry.npmjs.org/lightningcss/-/lightningcss-1.31.1.tgz", "integrity": "sha512-l51N2r93WmGUye3WuFoN5k10zyvrVs0qfKBhyC5ogUQ6Ew6JUSswh78mbSO+IU3nTWsyOArqPCcShdQSadghBQ==", "dev": true, "license": "MPL-2.0", "dependencies": { "detect-libc": "^2.0.3" }, "engines": { "node": ">= 12.0.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/parcel" }, "optionalDependencies": { "lightningcss-android-arm64": "1.31.1", "lightningcss-darwin-arm64": "1.31.1", "lightningcss-darwin-x64": "1.31.1", "lightningcss-freebsd-x64": "1.31.1", "lightningcss-linux-arm-gnueabihf": "1.31.1", "lightningcss-linux-arm64-gnu": "1.31.1", "lightningcss-linux-arm64-musl": "1.31.1", "lightningcss-linux-x64-gnu": "1.31.1", "lightningcss-linux-x64-musl": "1.31.1", "lightningcss-win32-arm64-msvc": "1.31.1", "lightningcss-win32-x64-msvc": "1.31.1" } }, "node_modules/lightningcss-android-arm64": { "version": "1.31.1", "resolved": "https://registry.npmjs.org/lightningcss-android-arm64/-/lightningcss-android-arm64-1.31.1.tgz", "integrity": "sha512-HXJF3x8w9nQ4jbXRiNppBCqeZPIAfUo8zE/kOEGbW5NZvGc/K7nMxbhIr+YlFlHW5mpbg/YFPdbnCh1wAXCKFg==", "cpu": [ "arm64" ], "dev": true, "license": "MPL-2.0", "optional": true, "os": [ "android" ], "engines": { "node": ">= 12.0.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/parcel" } }, "node_modules/lightningcss-darwin-arm64": { "version": "1.31.1", "resolved": "https://registry.npmjs.org/lightningcss-darwin-arm64/-/lightningcss-darwin-arm64-1.31.1.tgz", "integrity": "sha512-02uTEqf3vIfNMq3h/z2cJfcOXnQ0GRwQrkmPafhueLb2h7mqEidiCzkE4gBMEH65abHRiQvhdcQ+aP0D0g67sg==", "cpu": [ "arm64" ], "dev": true, "license": "MPL-2.0", "optional": true, "os": [ "darwin" ], "engines": { "node": ">= 12.0.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/parcel" } }, "node_modules/lightningcss-darwin-x64": { "version": "1.31.1", "resolved": "https://registry.npmjs.org/lightningcss-darwin-x64/-/lightningcss-darwin-x64-1.31.1.tgz", "integrity": "sha512-1ObhyoCY+tGxtsz1lSx5NXCj3nirk0Y0kB/g8B8DT+sSx4G9djitg9ejFnjb3gJNWo7qXH4DIy2SUHvpoFwfTA==", "cpu": [ "x64" ], "dev": true, "license": "MPL-2.0", "optional": true, "os": [ "darwin" ], "engines": { "node": ">= 12.0.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/parcel" } }, "node_modules/lightningcss-freebsd-x64": { "version": "1.31.1", "resolved": "https://registry.npmjs.org/lightningcss-freebsd-x64/-/lightningcss-freebsd-x64-1.31.1.tgz", "integrity": "sha512-1RINmQKAItO6ISxYgPwszQE1BrsVU5aB45ho6O42mu96UiZBxEXsuQ7cJW4zs4CEodPUioj/QrXW1r9pLUM74A==", "cpu": [ "x64" ], "dev": true, "license": "MPL-2.0", "optional": true, "os": [ "freebsd" ], "engines": { "node": ">= 12.0.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/parcel" } }, "node_modules/lightningcss-linux-arm-gnueabihf": { "version": "1.31.1", "resolved": "https://registry.npmjs.org/lightningcss-linux-arm-gnueabihf/-/lightningcss-linux-arm-gnueabihf-1.31.1.tgz", "integrity": "sha512-OOCm2//MZJ87CdDK62rZIu+aw9gBv4azMJuA8/KB74wmfS3lnC4yoPHm0uXZ/dvNNHmnZnB8XLAZzObeG0nS1g==", "cpu": [ "arm" ], "dev": true, "license": "MPL-2.0", "optional": true, "os": [ "linux" ], "engines": { "node": ">= 12.0.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/parcel" } }, "node_modules/lightningcss-linux-arm64-gnu": { "version": "1.31.1", "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-gnu/-/lightningcss-linux-arm64-gnu-1.31.1.tgz", "integrity": "sha512-WKyLWztD71rTnou4xAD5kQT+982wvca7E6QoLpoawZ1gP9JM0GJj4Tp5jMUh9B3AitHbRZ2/H3W5xQmdEOUlLg==", "cpu": [ "arm64" ], "dev": true, "license": "MPL-2.0", "optional": true, "os": [ "linux" ], "engines": { "node": ">= 12.0.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/parcel" } }, "node_modules/lightningcss-linux-arm64-musl": { "version": "1.31.1", "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-musl/-/lightningcss-linux-arm64-musl-1.31.1.tgz", "integrity": "sha512-mVZ7Pg2zIbe3XlNbZJdjs86YViQFoJSpc41CbVmKBPiGmC4YrfeOyz65ms2qpAobVd7WQsbW4PdsSJEMymyIMg==", "cpu": [ "arm64" ], "dev": true, "license": "MPL-2.0", "optional": true, "os": [ "linux" ], "engines": { "node": ">= 12.0.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/parcel" } }, "node_modules/lightningcss-linux-x64-gnu": { "version": "1.31.1", "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-gnu/-/lightningcss-linux-x64-gnu-1.31.1.tgz", "integrity": "sha512-xGlFWRMl+0KvUhgySdIaReQdB4FNudfUTARn7q0hh/V67PVGCs3ADFjw+6++kG1RNd0zdGRlEKa+T13/tQjPMA==", "cpu": [ "x64" ], "dev": true, "license": "MPL-2.0", "optional": true, "os": [ "linux" ], "engines": { "node": ">= 12.0.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/parcel" } }, "node_modules/lightningcss-linux-x64-musl": { "version": "1.31.1", "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-musl/-/lightningcss-linux-x64-musl-1.31.1.tgz", "integrity": "sha512-eowF8PrKHw9LpoZii5tdZwnBcYDxRw2rRCyvAXLi34iyeYfqCQNA9rmUM0ce62NlPhCvof1+9ivRaTY6pSKDaA==", "cpu": [ "x64" ], "dev": true, "license": "MPL-2.0", "optional": true, "os": [ "linux" ], "engines": { "node": ">= 12.0.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/parcel" } }, "node_modules/lightningcss-win32-arm64-msvc": { "version": "1.31.1", "resolved": "https://registry.npmjs.org/lightningcss-win32-arm64-msvc/-/lightningcss-win32-arm64-msvc-1.31.1.tgz", "integrity": "sha512-aJReEbSEQzx1uBlQizAOBSjcmr9dCdL3XuC/6HLXAxmtErsj2ICo5yYggg1qOODQMtnjNQv2UHb9NpOuFtYe4w==", "cpu": [ "arm64" ], "dev": true, "license": "MPL-2.0", "optional": true, "os": [ "win32" ], "engines": { "node": ">= 12.0.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/parcel" } }, "node_modules/lightningcss-win32-x64-msvc": { "version": "1.31.1", "resolved": "https://registry.npmjs.org/lightningcss-win32-x64-msvc/-/lightningcss-win32-x64-msvc-1.31.1.tgz", "integrity": "sha512-I9aiFrbd7oYHwlnQDqr1Roz+fTz61oDDJX7n9tYF9FJymH1cIN1DtKw3iYt6b8WZgEjoNwVSncwF4wx/ZedMhw==", "cpu": [ "x64" ], "dev": true, "license": "MPL-2.0", "optional": true, "os": [ "win32" ], "engines": { "node": ">= 12.0.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/parcel" } }, "node_modules/locate-path": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", "integrity": "sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==", "dev": true, "dependencies": { "p-locate": "^5.0.0" }, "engines": { "node": ">=10" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/lodash.includes": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz", "integrity": "sha512-W3Bx6mdkRTGtlJISOvVD/lbqjTlPPUDTMnlXZFnVwi9NKJ6tiAk6LVdlhZMm17VZisqhKcgzpO5Wz91PCt5b0w==" }, "node_modules/lodash.isboolean": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/lodash.isboolean/-/lodash.isboolean-3.0.3.tgz", "integrity": "sha512-Bz5mupy2SVbPHURB98VAcw+aHh4vRV5IPNhILUCsOzRmsTmSQ17jIuqopAentWoehktxGd9e/hbIXq980/1QJg==" }, "node_modules/lodash.isinteger": { "version": "4.0.4", "resolved": "https://registry.npmjs.org/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz", "integrity": "sha512-DBwtEWN2caHQ9/imiNeEA5ys1JoRtRfY3d7V9wkqtbycnAmTvRRmbHKDV4a0EYc678/dia0jrte4tjYwVBaZUA==" }, "node_modules/lodash.isnumber": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz", "integrity": "sha512-QYqzpfwO3/CWf3XP+Z+tkQsfaLL/EnUlXWVkIk5FUPc4sBdTehEqZONuyRt2P67PXAk+NXmTBcc97zw9t1FQrw==" }, "node_modules/lodash.isplainobject": { "version": "4.0.6", "resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz", "integrity": "sha512-oSXzaWypCMHkPC3NvBEaPHf0KsA5mvPrOPgQWDsbg8n7orZ290M0BmC/jgRZ4vcJ6DTAhjrsSYgdsW/F+MFOBA==" }, "node_modules/lodash.isstring": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz", "integrity": "sha512-0wJxfxH1wgO3GrbuP+dTTk7op+6L41QCXbGINEmD+ny/G/eCqGzxyCsh7159S+mgDDcoarnBw6PC1PS5+wUGgw==" }, "node_modules/lodash.merge": { "version": "4.6.2", "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==" }, "node_modules/lodash.once": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz", "integrity": "sha512-Sb487aTOCr9drQVL8pIxOzVhafOjZN9UU54hiN8PU3uAiSV7lx1yYNpbNmex2PK6dSJoNTSJUUswT651yww3Mg==" }, "node_modules/magic-string": { "version": "0.30.21", "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.21.tgz", "integrity": "sha512-vd2F4YUyEXKGcLHoq+TEyCjxueSeHnFxyyjNp80yg0XV4vUhnDer/lvvlqM/arB5bXQN5K2/3oinyCRyx8T2CQ==", "dev": true, "license": "MIT", "dependencies": { "@jridgewell/sourcemap-codec": "^1.5.5" } }, "node_modules/math-intrinsics": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==", "engines": { "node": ">= 0.4" } }, "node_modules/mdn-data": { "version": "2.0.30", "resolved": "https://registry.npmjs.org/mdn-data/-/mdn-data-2.0.30.tgz", "integrity": "sha512-GaqWWShW4kv/G9IEucWScBx9G1/vsFZZJUO+tD26M8J8z3Kw5RDQjaoZe03YAClgeS/SWPOcb4nkFBTEi5DUEA==", "dev": true }, "node_modules/media-typer": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", "integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==", "engines": { "node": ">= 0.6" } }, "node_modules/memory-pager": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/memory-pager/-/memory-pager-1.5.0.tgz", "integrity": "sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg==", "optional": true }, "node_modules/mime-db": { "version": "1.54.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.54.0.tgz", "integrity": "sha512-aU5EJuIN2WDemCcAp2vFBfp/m4EAhWJnUNSSw0ixs7/kXbd6Pg64EmwJkNdFhB8aWt1sH2CTXrLxo/iAGV3oPQ==", "engines": { "node": ">= 0.6" } }, "node_modules/mime-types": { "version": "2.1.35", "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", "dependencies": { "mime-db": "1.52.0" }, "engines": { "node": ">= 0.6" } }, "node_modules/mime-types/node_modules/mime-db": { "version": "1.52.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", "engines": { "node": ">= 0.6" } }, "node_modules/mini-svg-data-uri": { "version": "1.4.4", "resolved": "https://registry.npmjs.org/mini-svg-data-uri/-/mini-svg-data-uri-1.4.4.tgz", "integrity": "sha512-r9deDe9p5FJUPZAk3A59wGH7Ii9YrjjWw0jmw/liSbHl2CHiyXj6FcDXDu2K3TjVAXqiJdaw3xxwlZZr9E6nHg==", "dev": true, "license": "MIT", "bin": { "mini-svg-data-uri": "cli.js" } }, "node_modules/mithril": { "version": "2.3.8", "resolved": "https://registry.npmjs.org/mithril/-/mithril-2.3.8.tgz", "integrity": "sha512-za/Yo7qXEckjm5syrSfaaI9Utf4tCUT3T1IOIYqH6Lrj7G0OZuYYLAY9SV4ygoaAf0+CNqU92MBt+7pmo53JVQ==", "dev": true }, "node_modules/mongodb": { "version": "4.17.2", "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-4.17.2.tgz", "integrity": "sha512-mLV7SEiov2LHleRJPMPrK2PMyhXFZt2UQLC4VD4pnth3jMjYKHhtqfwwkkvS/NXuo/Fp3vbhaNcXrIDaLRb9Tg==", "dependencies": { "bson": "^4.7.2", "mongodb-connection-string-url": "^2.6.0", "socks": "^2.7.1" }, "engines": { "node": ">=12.9.0" }, "optionalDependencies": { "@aws-sdk/credential-providers": "^3.186.0", "@mongodb-js/saslprep": "^1.1.0" } }, "node_modules/mongodb-connection-string-url": { "version": "2.6.0", "resolved": "https://registry.npmjs.org/mongodb-connection-string-url/-/mongodb-connection-string-url-2.6.0.tgz", "integrity": "sha512-WvTZlI9ab0QYtTYnuMLgobULWhokRjtC7db9LtcVfJ+Hsnyr5eo6ZtNAt3Ly24XZScGMelOcGtm7lSn0332tPQ==", "dependencies": { "@types/whatwg-url": "^8.2.1", "whatwg-url": "^11.0.0" } }, "node_modules/mri": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/mri/-/mri-1.2.0.tgz", "integrity": "sha512-tzzskb3bG8LvYGFF/mDTpq3jpI6Q9wc3LEmBaghu+DdCssd1FakN7Bc0hVNmEyGq1bq3RgfkCb3cmQLpNPOroA==", "dev": true, "license": "MIT", "engines": { "node": ">=4" } }, "node_modules/ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" }, "node_modules/natural-compare": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", "integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==", "dev": true }, "node_modules/negotiator": { "version": "0.6.3", "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==", "engines": { "node": ">= 0.6" } }, "node_modules/node-addon-api": { "version": "7.1.1", "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-7.1.1.tgz", "integrity": "sha512-5m3bsyrjFWE1xf7nz7YXdN4udnVtXK6/Yfgn5qnahL6bCkf2yKt4k3nuTKAtT4r3IG8JNR2ncsIMdZuAzJjHQQ==", "dev": true, "license": "MIT" }, "node_modules/nth-check": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/nth-check/-/nth-check-2.1.1.tgz", "integrity": "sha512-lqjrjmaOoAnWfMmBPL+XNnynZh2+swxiX3WUE0s4yEHI6m+AwrK2UZOimIRl3X/4QctVqS8AiZjFqyOGrMXb/w==", "dev": true, "dependencies": { "boolbase": "^1.0.0" }, "funding": { "url": "https://github.com/fb55/nth-check?sponsor=1" } }, "node_modules/object-inspect": { "version": "1.13.4", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz", "integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==", "engines": { "node": ">= 0.4" }, "funding": { "url": "https://github.com/sponsors/ljharb" } }, "node_modules/on-finished": { "version": "2.4.1", "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz", "integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==", "dependencies": { "ee-first": "1.1.1" }, "engines": { "node": ">= 0.8" } }, "node_modules/only": { "version": "0.0.2", "resolved": "https://registry.npmjs.org/only/-/only-0.0.2.tgz", "integrity": "sha512-Fvw+Jemq5fjjyWz6CpKx6w9s7xxqo3+JCyM0WXWeCSOboZ8ABkyvP8ID4CZuChA/wxSx+XSJmdOm8rGVyJ1hdQ==" }, "node_modules/optionator": { "version": "0.9.4", "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.4.tgz", "integrity": "sha512-6IpQ7mKUxRcZNLIObR0hz7lxsapSSIYNZJwXPGeF0mTVqGKFIXj1DQcMoT22S3ROcLyY/rz0PWaWZ9ayWmad9g==", "dev": true, "dependencies": { "deep-is": "^0.1.3", "fast-levenshtein": "^2.0.6", "levn": "^0.4.1", "prelude-ls": "^1.2.1", "type-check": "^0.4.0", "word-wrap": "^1.2.5" }, "engines": { "node": ">= 0.8.0" } }, "node_modules/p-any": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/p-any/-/p-any-2.1.0.tgz", "integrity": "sha512-JAERcaMBLYKMq+voYw36+x5Dgh47+/o7yuv2oQYuSSUml4YeqJEFznBrY2UeEkoSHqBua6hz518n/PsowTYLLg==", "dependencies": { "p-cancelable": "^2.0.0", "p-some": "^4.0.0", "type-fest": "^0.3.0" }, "engines": { "node": ">=8" } }, "node_modules/p-any/node_modules/type-fest": { "version": "0.3.1", "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.3.1.tgz", "integrity": "sha512-cUGJnCdr4STbePCgqNFbpVNCepa+kAVohJs1sLhxzdH+gnEoOd8VhbYa7pD3zZYGiURWM2xzEII3fQcRizDkYQ==", "engines": { "node": ">=6" } }, "node_modules/p-cancelable": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-2.1.1.tgz", "integrity": "sha512-BZOr3nRQHOntUjTrH8+Lh54smKHoHyur8We1V8DSMVrl5A2malOOwuJRnKRDjSnkoeBh4at6BwEnb5I7Jl31wg==", "engines": { "node": ">=8" } }, "node_modules/p-limit": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", "integrity": "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==", "dev": true, "dependencies": { "yocto-queue": "^0.1.0" }, "engines": { "node": ">=10" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/p-locate": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-5.0.0.tgz", "integrity": "sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==", "dev": true, "dependencies": { "p-limit": "^3.0.2" }, "engines": { "node": ">=10" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/p-some": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/p-some/-/p-some-4.1.0.tgz", "integrity": "sha512-MF/HIbq6GeBqTrTIl5OJubzkGU+qfFhAFi0gnTAK6rgEIJIknEiABHOTtQu4e6JiXjIwuMPMUFQzyHh5QjCl1g==", "dependencies": { "aggregate-error": "^3.0.0", "p-cancelable": "^2.0.0" }, "engines": { "node": ">=8" } }, "node_modules/parseurl": { "version": "1.3.3", "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==", "engines": { "node": ">= 0.8" } }, "node_modules/path-exists": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", "dev": true, "engines": { "node": ">=8" } }, "node_modules/path-expression-matcher": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/path-expression-matcher/-/path-expression-matcher-1.1.3.tgz", "integrity": "sha512-qdVgY8KXmVdJZRSS1JdEPOKPdTiEK/pi0RkcT2sw1RhXxohdujUlJFPuS1TSkevZ9vzd3ZlL7ULl1MHGTApKzQ==", "funding": [ { "type": "github", "url": "https://github.com/sponsors/NaturalIntelligence" } ], "optional": true, "engines": { "node": ">=14.0.0" } }, "node_modules/path-is-absolute": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==", "engines": { "node": ">=0.10.0" } }, "node_modules/path-key": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", "dev": true, "license": "MIT", "engines": { "node": ">=8" } }, "node_modules/path-to-regexp": { "version": "6.3.0", "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-6.3.0.tgz", "integrity": "sha512-Yhpw4T9C6hPpgPeA28us07OJeqZ5EzQTkbfwuhsUg0c237RomFoETJgmp2sa3F/41gfLE6G5cqcYwznmeEeOlQ==", "license": "MIT" }, "node_modules/picocolors": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==", "dev": true }, "node_modules/prelude-ls": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==", "dev": true, "engines": { "node": ">= 0.8.0" } }, "node_modules/prettier": { "version": "3.8.1", "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.8.1.tgz", "integrity": "sha512-UOnG6LftzbdaHZcKoPFtOcCKztrQ57WkHDeRD9t/PTQtmT0NHSeWWepj6pS0z/N7+08BHFDQVUrfmfMRcZwbMg==", "dev": true, "license": "MIT", "bin": { "prettier": "bin/prettier.cjs" }, "engines": { "node": ">=14" }, "funding": { "url": "https://github.com/prettier/prettier?sponsor=1" } }, "node_modules/punycode": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==", "engines": { "node": ">=6" } }, "node_modules/qs": { "version": "6.15.0", "resolved": "https://registry.npmjs.org/qs/-/qs-6.15.0.tgz", "integrity": "sha512-mAZTtNCeetKMH+pSjrb76NAM8V9a05I9aBZOHztWy/UqcJdQYNsf59vrRKWnojAT9Y+GbIvoTBC++CPHqpDBhQ==", "dependencies": { "side-channel": "^1.1.0" }, "engines": { "node": ">=0.6" }, "funding": { "url": "https://github.com/sponsors/ljharb" } }, "node_modules/raw-body": { "version": "2.5.3", "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.3.tgz", "integrity": "sha512-s4VSOf6yN0rvbRZGxs8Om5CWj6seneMwK3oDb4lWDH0UPhWcxwOWw5+qk24bxq87szX1ydrwylIOp2uG1ojUpA==", "dependencies": { "bytes": "~3.1.2", "http-errors": "~2.0.1", "iconv-lite": "~0.4.24", "unpipe": "~1.0.0" }, "engines": { "node": ">= 0.8" } }, "node_modules/raw-body/node_modules/iconv-lite": { "version": "0.4.24", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", "dependencies": { "safer-buffer": ">= 2.1.2 < 3" }, "engines": { "node": ">=0.10.0" } }, "node_modules/resolve-path": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/resolve-path/-/resolve-path-1.4.0.tgz", "integrity": "sha512-i1xevIst/Qa+nA9olDxLWnLk8YZbi8R/7JPbCMcgyWaFR6bKWaexgJgEB5oc2PKMjYdrHynyz0NY+if+H98t1w==", "dependencies": { "http-errors": "~1.6.2", "path-is-absolute": "1.0.1" }, "engines": { "node": ">= 0.8" } }, "node_modules/resolve-path/node_modules/depd": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", "integrity": "sha512-7emPTl6Dpo6JRXOXjLRxck+FlLRX5847cLKEn00PLAgc3g2hTZZgr+e4c2v6QpSmLeFP3n5yUo7ft6avBK/5jQ==", "engines": { "node": ">= 0.6" } }, "node_modules/resolve-path/node_modules/http-errors": { "version": "1.6.3", "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.6.3.tgz", "integrity": "sha512-lks+lVC8dgGyh97jxvxeYTWQFvh4uw4yC12gVl63Cg30sjPX4wuGcdkICVXDAESr6OJGjqGA8Iz5mkeN6zlD7A==", "dependencies": { "depd": "~1.1.2", "inherits": "2.0.3", "setprototypeof": "1.1.0", "statuses": ">= 1.4.0 < 2" }, "engines": { "node": ">= 0.6" } }, "node_modules/resolve-path/node_modules/inherits": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", "integrity": "sha512-x00IRNXNy63jwGkJmzPigoySHbaqpNuzKbBOmzK+g2OdZpQ9w+sxCN+VSB3ja7IAge2OP2qpfxTjeNcyjmW1uw==" }, "node_modules/resolve-path/node_modules/setprototypeof": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.0.tgz", "integrity": "sha512-BvE/TwpZX4FXExxOxZyRGQQv651MSwmWKZGqvmPcRIjDqWub67kTKuIMx43cZZrS/cBBzwBcNDWoFxt2XEFIpQ==" }, "node_modules/resolve-path/node_modules/statuses": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", "integrity": "sha512-OpZ3zP+jT1PI7I8nemJX4AKmAX070ZkYPVWV/AaKTJl+tXCTGyVdC1a4SL8RUQYEwk/f34ZX8UTykN68FwrqAA==", "engines": { "node": ">= 0.6" } }, "node_modules/safe-buffer": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", "funding": [ { "type": "github", "url": "https://github.com/sponsors/feross" }, { "type": "patreon", "url": "https://www.patreon.com/feross" }, { "type": "consulting", "url": "https://feross.org/support" } ] }, "node_modules/safe-regex-test": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/safe-regex-test/-/safe-regex-test-1.1.0.tgz", "integrity": "sha512-x/+Cz4YrimQxQccJf5mKEbIa1NzeCRNI5Ecl/ekmlYaampdNLPalVyIcCZNNH3MvmqBugV5TMYZXv0ljslUlaw==", "dependencies": { "call-bound": "^1.0.2", "es-errors": "^1.3.0", "is-regex": "^1.2.1" }, "engines": { "node": ">= 0.4" }, "funding": { "url": "https://github.com/sponsors/ljharb" } }, "node_modules/safer-buffer": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, "node_modules/sax": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/sax/-/sax-1.5.0.tgz", "integrity": "sha512-21IYA3Q5cQf089Z6tgaUTr7lDAyzoTPx5HRtbhsME8Udispad8dC/+sziTNugOEx54ilvatQ9YCzl4KQLPcRHA==", "dev": true, "engines": { "node": ">=11.0.0" } }, "node_modules/seedrandom": { "version": "3.0.5", "resolved": "https://registry.npmjs.org/seedrandom/-/seedrandom-3.0.5.tgz", "integrity": "sha512-8OwmbklUNzwezjGInmZ+2clQmExQPvomqjL7LFqOYqtmuxRgQYqOD3mHaU+MvZn5FLUeVxVfQjwLZW/n/JFuqg==" }, "node_modules/semver": { "version": "7.7.4", "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.4.tgz", "integrity": "sha512-vFKC2IEtQnVhpT78h1Yp8wzwrf8CM+MzKMHGJZfBtzhZNycRFnXsHk6E5TxIkkMsgNS7mdX3AGB7x2QM2di4lA==", "bin": { "semver": "bin/semver.js" }, "engines": { "node": ">=10" } }, "node_modules/setprototypeof": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==" }, "node_modules/shebang-command": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", "dev": true, "license": "MIT", "dependencies": { "shebang-regex": "^3.0.0" }, "engines": { "node": ">=8" } }, "node_modules/shebang-regex": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", "dev": true, "license": "MIT", "engines": { "node": ">=8" } }, "node_modules/side-channel": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.0.tgz", "integrity": "sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw==", "dependencies": { "es-errors": "^1.3.0", "object-inspect": "^1.13.3", "side-channel-list": "^1.0.0", "side-channel-map": "^1.0.1", "side-channel-weakmap": "^1.0.2" }, "engines": { "node": ">= 0.4" }, "funding": { "url": "https://github.com/sponsors/ljharb" } }, "node_modules/side-channel-list": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.0.tgz", "integrity": "sha512-FCLHtRD/gnpCiCHEiJLOwdmFP+wzCmDEkc9y7NsYxeF4u7Btsn1ZuwgwJGxImImHicJArLP4R0yX4c2KCrMrTA==", "dependencies": { "es-errors": "^1.3.0", "object-inspect": "^1.13.3" }, "engines": { "node": ">= 0.4" }, "funding": { "url": "https://github.com/sponsors/ljharb" } }, "node_modules/side-channel-map": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz", "integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==", "dependencies": { "call-bound": "^1.0.2", "es-errors": "^1.3.0", "get-intrinsic": "^1.2.5", "object-inspect": "^1.13.3" }, "engines": { "node": ">= 0.4" }, "funding": { "url": "https://github.com/sponsors/ljharb" } }, "node_modules/side-channel-weakmap": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz", "integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==", "dependencies": { "call-bound": "^1.0.2", "es-errors": "^1.3.0", "get-intrinsic": "^1.2.5", "object-inspect": "^1.13.3", "side-channel-map": "^1.0.1" }, "engines": { "node": ">= 0.4" }, "funding": { "url": "https://github.com/sponsors/ljharb" } }, "node_modules/smart-buffer": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.2.0.tgz", "integrity": "sha512-94hK0Hh8rPqQl2xXc3HsaBoOXKV20MToPkcXvwbISWLEs+64sBq5kFgn2kJDHb1Pry9yrP0dxrCI9RRci7RXKg==", "engines": { "node": ">= 6.0.0", "npm": ">= 3.0.0" } }, "node_modules/socks": { "version": "2.8.7", "resolved": "https://registry.npmjs.org/socks/-/socks-2.8.7.tgz", "integrity": "sha512-HLpt+uLy/pxB+bum/9DzAgiKS8CX1EvbWxI4zlmgGCExImLdiad2iCwXT5Z4c9c3Eq8rP2318mPW2c+QbtjK8A==", "dependencies": { "ip-address": "^10.0.1", "smart-buffer": "^4.2.0" }, "engines": { "node": ">= 10.0.0", "npm": ">= 3.0.0" } }, "node_modules/source-map-js": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.1.tgz", "integrity": "sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==", "dev": true, "license": "BSD-3-Clause", "engines": { "node": ">=0.10.0" } }, "node_modules/sparse-bitfield": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/sparse-bitfield/-/sparse-bitfield-3.0.3.tgz", "integrity": "sha512-kvzhi7vqKTfkh0PZU+2D2PIllw2ymqJKujUcyPMd9Y75Nv4nPbGJZXNhxsgdQab2BmlDct1YnfQCguEvHr7VsQ==", "optional": true, "dependencies": { "memory-pager": "^1.0.2" } }, "node_modules/sql.js": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/sql.js/-/sql.js-1.14.1.tgz", "integrity": "sha512-gcj8zBWU5cFsi9WUP+4bFNXAyF1iRpA3LLyS/DP5xlrNzGmPIizUeBggKa8DbDwdqaKwUcTEnChtd2grWo/x/A==", "dev": true }, "node_modules/statuses": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz", "integrity": "sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw==", "engines": { "node": ">= 0.8" } }, "node_modules/strnum": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/strnum/-/strnum-2.2.0.tgz", "integrity": "sha512-Y7Bj8XyJxnPAORMZj/xltsfo55uOiyHcU2tnAVzHUnSJR/KsEX+9RoDeXEnsXtl/CX4fAcrt64gZ13aGaWPeBg==", "funding": [ { "type": "github", "url": "https://github.com/sponsors/NaturalIntelligence" } ], "optional": true }, "node_modules/style-mod": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/style-mod/-/style-mod-4.1.2.tgz", "integrity": "sha512-wnD1HyVqpJUI2+eKZ+eo1UwghftP6yuFheBqqe+bWCotBjC2K1YnteJILRMs3SM4V/0dLEW1SC27MWP5y+mwmw==", "dev": true }, "node_modules/svgo": { "version": "3.3.3", "resolved": "https://registry.npmjs.org/svgo/-/svgo-3.3.3.tgz", "integrity": "sha512-+wn7I4p7YgJhHs38k2TNjy1vCfPIfLIJWR5MnCStsN8WuuTcBnRKcMHQLMM2ijxGZmDoZwNv8ipl5aTTen62ng==", "dev": true, "dependencies": { "commander": "^7.2.0", "css-select": "^5.1.0", "css-tree": "^2.3.1", "css-what": "^6.1.0", "csso": "^5.0.5", "picocolors": "^1.0.0", "sax": "^1.5.0" }, "bin": { "svgo": "bin/svgo" }, "engines": { "node": ">=14.0.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/svgo" } }, "node_modules/tailwindcss": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-4.2.1.tgz", "integrity": "sha512-/tBrSQ36vCleJkAOsy9kbNTgaxvGbyOamC30PRePTQe/o1MFwEKHQk4Cn7BNGaPtjp+PuUrByJehM1hgxfq4sw==", "dev": true, "license": "MIT" }, "node_modules/tapable": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/tapable/-/tapable-2.3.0.tgz", "integrity": "sha512-g9ljZiwki/LfxmQADO3dEY1CbpmXT5Hm2fJ+QaGKwSXUylMybePR7/67YW7jOrrvjEgL1Fmz5kzyAjWVWLlucg==", "dev": true, "license": "MIT", "engines": { "node": ">=6" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/webpack" } }, "node_modules/tinyglobby": { "version": "0.2.15", "resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.15.tgz", "integrity": "sha512-j2Zq4NyQYG5XMST4cbs02Ak8iJUdxRM0XI5QyxXuZOzKOINmWurp3smXu3y5wDcJrptwpSjgXHzIQxR0omXljQ==", "dev": true, "license": "MIT", "dependencies": { "fdir": "^6.5.0", "picomatch": "^4.0.3" }, "engines": { "node": ">=12.0.0" }, "funding": { "url": "https://github.com/sponsors/SuperchupuDev" } }, "node_modules/tinyglobby/node_modules/fdir": { "version": "6.5.0", "resolved": "https://registry.npmjs.org/fdir/-/fdir-6.5.0.tgz", "integrity": "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg==", "dev": true, "license": "MIT", "engines": { "node": ">=12.0.0" }, "peerDependencies": { "picomatch": "^3 || ^4" }, "peerDependenciesMeta": { "picomatch": { "optional": true } } }, "node_modules/tinyglobby/node_modules/picomatch": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.3.tgz", "integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==", "dev": true, "license": "MIT", "engines": { "node": ">=12" }, "funding": { "url": "https://github.com/sponsors/jonschlinkert" } }, "node_modules/toidentifier": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==", "engines": { "node": ">=0.6" } }, "node_modules/tr46": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/tr46/-/tr46-3.0.0.tgz", "integrity": "sha512-l7FvfAHlcmulp8kr+flpQZmVwtu7nfRV7NZujtN0OqES8EL4O4e0qqzL0DC5gAvx/ZC/9lk6rhcUwYvkBnBnYA==", "dependencies": { "punycode": "^2.1.1" }, "engines": { "node": ">=12" } }, "node_modules/tslib": { "version": "2.8.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz", "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==", "optional": true }, "node_modules/tsscmp": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/tsscmp/-/tsscmp-1.0.6.tgz", "integrity": "sha512-LxhtAkPDTkVCMQjt2h6eBVY28KCjikZqZfMcC15YBeNjkgUpdCfBu5HoiOTDu86v6smE8yOjyEktJ8hlbANHQA==", "engines": { "node": ">=0.6.x" } }, "node_modules/type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", "integrity": "sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==", "dev": true, "dependencies": { "prelude-ls": "^1.2.1" }, "engines": { "node": ">= 0.8.0" } }, "node_modules/type-is": { "version": "1.6.18", "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", "integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==", "dependencies": { "media-typer": "0.3.0", "mime-types": "~2.1.24" }, "engines": { "node": ">= 0.6" } }, "node_modules/typescript": { "version": "5.9.3", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", "dev": true, "license": "Apache-2.0", "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" }, "engines": { "node": ">=14.17" } }, "node_modules/typescript-eslint": { "version": "8.56.1", "resolved": "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-8.56.1.tgz", "integrity": "sha512-U4lM6pjmBX7J5wk4szltF7I1cGBHXZopnAXCMXb3+fZ3B/0Z3hq3wS/CCUB2NZBNAExK92mCU2tEohWuwVMsDQ==", "dev": true, "license": "MIT", "dependencies": { "@typescript-eslint/eslint-plugin": "8.56.1", "@typescript-eslint/parser": "8.56.1", "@typescript-eslint/typescript-estree": "8.56.1", "@typescript-eslint/utils": "8.56.1" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/typescript-eslint" }, "peerDependencies": { "eslint": "^8.57.0 || ^9.0.0 || ^10.0.0", "typescript": ">=4.8.4 <6.0.0" } }, "node_modules/typescript-eslint/node_modules/@typescript-eslint/eslint-plugin": { "version": "8.56.1", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.56.1.tgz", "integrity": "sha512-Jz9ZztpB37dNC+HU2HI28Bs9QXpzCz+y/twHOwhyrIRdbuVDxSytJNDl6z/aAKlaRIwC7y8wJdkBv7FxYGgi0A==", "dev": true, "license": "MIT", "dependencies": { "@eslint-community/regexpp": "^4.12.2", "@typescript-eslint/scope-manager": "8.56.1", "@typescript-eslint/type-utils": "8.56.1", "@typescript-eslint/utils": "8.56.1", "@typescript-eslint/visitor-keys": "8.56.1", "ignore": "^7.0.5", "natural-compare": "^1.4.0", "ts-api-utils": "^2.4.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/typescript-eslint" }, "peerDependencies": { "@typescript-eslint/parser": "^8.56.1", "eslint": "^8.57.0 || ^9.0.0 || ^10.0.0", "typescript": ">=4.8.4 <6.0.0" } }, "node_modules/typescript-eslint/node_modules/@typescript-eslint/parser": { "version": "8.56.1", "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.56.1.tgz", "integrity": "sha512-klQbnPAAiGYFyI02+znpBRLyjL4/BrBd0nyWkdC0s/6xFLkXYQ8OoRrSkqacS1ddVxf/LDyODIKbQ5TgKAf/Fg==", "dev": true, "license": "MIT", "dependencies": { "@typescript-eslint/scope-manager": "8.56.1", "@typescript-eslint/types": "8.56.1", "@typescript-eslint/typescript-estree": "8.56.1", "@typescript-eslint/visitor-keys": "8.56.1", "debug": "^4.4.3" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/typescript-eslint" }, "peerDependencies": { "eslint": "^8.57.0 || ^9.0.0 || ^10.0.0", "typescript": ">=4.8.4 <6.0.0" } }, "node_modules/typescript-eslint/node_modules/@typescript-eslint/scope-manager": { "version": "8.56.1", "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.56.1.tgz", "integrity": "sha512-YAi4VDKcIZp0O4tz/haYKhmIDZFEUPOreKbfdAN3SzUDMcPhJ8QI99xQXqX+HoUVq8cs85eRKnD+rne2UAnj2w==", "dev": true, "license": "MIT", "dependencies": { "@typescript-eslint/types": "8.56.1", "@typescript-eslint/visitor-keys": "8.56.1" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/typescript-eslint" } }, "node_modules/typescript-eslint/node_modules/@typescript-eslint/type-utils": { "version": "8.56.1", "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.56.1.tgz", "integrity": "sha512-yB/7dxi7MgTtGhZdaHCemf7PuwrHMenHjmzgUW1aJpO+bBU43OycnM3Wn+DdvDO/8zzA9HlhaJ0AUGuvri4oGg==", "dev": true, "license": "MIT", "dependencies": { "@typescript-eslint/types": "8.56.1", "@typescript-eslint/typescript-estree": "8.56.1", "@typescript-eslint/utils": "8.56.1", "debug": "^4.4.3", "ts-api-utils": "^2.4.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/typescript-eslint" }, "peerDependencies": { "eslint": "^8.57.0 || ^9.0.0 || ^10.0.0", "typescript": ">=4.8.4 <6.0.0" } }, "node_modules/typescript-eslint/node_modules/@typescript-eslint/types": { "version": "8.56.1", "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.56.1.tgz", "integrity": "sha512-dbMkdIUkIkchgGDIv7KLUpa0Mda4IYjo4IAMJUZ+3xNoUXxMsk9YtKpTHSChRS85o+H9ftm51gsK1dZReY9CVw==", "dev": true, "license": "MIT", "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/typescript-eslint" } }, "node_modules/typescript-eslint/node_modules/@typescript-eslint/typescript-estree": { "version": "8.56.1", "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.56.1.tgz", "integrity": "sha512-qzUL1qgalIvKWAf9C1HpvBjif+Vm6rcT5wZd4VoMb9+Km3iS3Cv9DY6dMRMDtPnwRAFyAi7YXJpTIEXLvdfPxg==", "dev": true, "license": "MIT", "dependencies": { "@typescript-eslint/project-service": "8.56.1", "@typescript-eslint/tsconfig-utils": "8.56.1", "@typescript-eslint/types": "8.56.1", "@typescript-eslint/visitor-keys": "8.56.1", "debug": "^4.4.3", "minimatch": "^10.2.2", "semver": "^7.7.3", "tinyglobby": "^0.2.15", "ts-api-utils": "^2.4.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/typescript-eslint" }, "peerDependencies": { "typescript": ">=4.8.4 <6.0.0" } }, "node_modules/typescript-eslint/node_modules/@typescript-eslint/utils": { "version": "8.56.1", "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.56.1.tgz", "integrity": "sha512-HPAVNIME3tABJ61siYlHzSWCGtOoeP2RTIaHXFMPqjrQKCGB9OgUVdiNgH7TJS2JNIQ5qQ4RsAUDuGaGme/KOA==", "dev": true, "license": "MIT", "dependencies": { "@eslint-community/eslint-utils": "^4.9.1", "@typescript-eslint/scope-manager": "8.56.1", "@typescript-eslint/types": "8.56.1", "@typescript-eslint/typescript-estree": "8.56.1" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/typescript-eslint" }, "peerDependencies": { "eslint": "^8.57.0 || ^9.0.0 || ^10.0.0", "typescript": ">=4.8.4 <6.0.0" } }, "node_modules/typescript-eslint/node_modules/@typescript-eslint/visitor-keys": { "version": "8.56.1", "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.56.1.tgz", "integrity": "sha512-KiROIzYdEV85YygXw6BI/Dx4fnBlFQu6Mq4QE4MOH9fFnhohw6wX/OAvDY2/C+ut0I3RSPKenvZJIVYqJNkhEw==", "dev": true, "license": "MIT", "dependencies": { "@typescript-eslint/types": "8.56.1", "eslint-visitor-keys": "^5.0.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/typescript-eslint" } }, "node_modules/typescript-eslint/node_modules/balanced-match": { "version": "4.0.4", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-4.0.4.tgz", "integrity": "sha512-BLrgEcRTwX2o6gGxGOCNyMvGSp35YofuYzw9h1IMTRmKqttAZZVU67bdb9Pr2vUHA8+j3i2tJfjO6C6+4myGTA==", "dev": true, "license": "MIT", "engines": { "node": "18 || 20 || >=22" } }, "node_modules/typescript-eslint/node_modules/brace-expansion": { "version": "5.0.4", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.4.tgz", "integrity": "sha512-h+DEnpVvxmfVefa4jFbCf5HdH5YMDXRsmKflpf1pILZWRFlTbJpxeU55nJl4Smt5HQaGzg1o6RHFPJaOqnmBDg==", "dev": true, "license": "MIT", "dependencies": { "balanced-match": "^4.0.2" }, "engines": { "node": "18 || 20 || >=22" } }, "node_modules/typescript-eslint/node_modules/eslint-visitor-keys": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-5.0.1.tgz", "integrity": "sha512-tD40eHxA35h0PEIZNeIjkHoDR4YjjJp34biM0mDvplBe//mB+IHCqHDGV7pxF+7MklTvighcCPPZC7ynWyjdTA==", "dev": true, "license": "Apache-2.0", "engines": { "node": "^20.19.0 || ^22.13.0 || >=24" }, "funding": { "url": "https://opencollective.com/eslint" } }, "node_modules/typescript-eslint/node_modules/ignore": { "version": "7.0.5", "resolved": "https://registry.npmjs.org/ignore/-/ignore-7.0.5.tgz", "integrity": "sha512-Hs59xBNfUIunMFgWAbGX5cq6893IbWg4KnrjbYwX3tx0ztorVgTDA6B2sxf8ejHJ4wz8BqGUMYlnzNBer5NvGg==", "dev": true, "license": "MIT", "engines": { "node": ">= 4" } }, "node_modules/typescript-eslint/node_modules/minimatch": { "version": "10.2.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.2.4.tgz", "integrity": "sha512-oRjTw/97aTBN0RHbYCdtF1MQfvusSIBQM0IZEgzl6426+8jSC0nF1a/GmnVLpfB9yyr6g6FTqWqiZVbxrtaCIg==", "dev": true, "license": "BlueOak-1.0.0", "dependencies": { "brace-expansion": "^5.0.2" }, "engines": { "node": "18 || 20 || >=22" }, "funding": { "url": "https://github.com/sponsors/isaacs" } }, "node_modules/typescript-eslint/node_modules/ts-api-utils": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-2.4.0.tgz", "integrity": "sha512-3TaVTaAv2gTiMB35i3FiGJaRfwb3Pyn/j3m/bfAvGe8FB7CF6u+LMYqYlDh7reQf7UNvoTvdfAqHGmPGOSsPmA==", "dev": true, "license": "MIT", "engines": { "node": ">=18.12" }, "peerDependencies": { "typescript": ">=4.8.4" } }, "node_modules/undici-types": { "version": "7.18.2", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.18.2.tgz", "integrity": "sha512-AsuCzffGHJybSaRrmr5eHr81mwJU3kjw6M+uprWvCXiNeN9SOGwQ3Jn8jb8m3Z6izVgknn1R0FTCEAP2QrLY/w==", "license": "MIT" }, "node_modules/unpipe": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==", "engines": { "node": ">= 0.8" } }, "node_modules/uri-js": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", "integrity": "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==", "dev": true, "license": "BSD-2-Clause", "dependencies": { "punycode": "^2.1.0" } }, "node_modules/vary": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==", "engines": { "node": ">= 0.8" } }, "node_modules/w3c-keyname": { "version": "2.2.8", "resolved": "https://registry.npmjs.org/w3c-keyname/-/w3c-keyname-2.2.8.tgz", "integrity": "sha512-dpojBhNsCNN7T82Tm7k26A6G9ML3NkhDsnw9n/eoxSRlVBB4CEtIQ/KTCLI2Fwf3ataSXRhYFkQi3SlnFwPvPQ==", "dev": true }, "node_modules/webidl-conversions": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", "integrity": "sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==", "engines": { "node": ">=12" } }, "node_modules/whatwg-url": { "version": "11.0.0", "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-11.0.0.tgz", "integrity": "sha512-RKT8HExMpoYx4igMiVMY83lN6UeITKJlBQ+vR/8ZJ8OCdSiN3RwCq+9gH0+Xzj0+5IrM6i4j/6LuvzbZIQgEcQ==", "dependencies": { "tr46": "^3.0.0", "webidl-conversions": "^7.0.0" }, "engines": { "node": ">=12" } }, "node_modules/which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", "dev": true, "license": "ISC", "dependencies": { "isexe": "^2.0.0" }, "bin": { "node-which": "bin/node-which" }, "engines": { "node": ">= 8" } }, "node_modules/word-wrap": { "version": "1.2.5", "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz", "integrity": "sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==", "dev": true, "engines": { "node": ">=0.10.0" } }, "node_modules/yaml": { "version": "1.10.2", "resolved": "https://registry.npmjs.org/yaml/-/yaml-1.10.2.tgz", "integrity": "sha512-r3vXyErRCYJ7wg28yvBY5VSoAF8ZvlcW9/BwUzEtUsjvX/DKs24dIkuwjtuprwJJHsbyUbLApepYTR1BN4uHrg==", "dev": true, "engines": { "node": ">= 6" } }, "node_modules/ylru": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/ylru/-/ylru-1.4.0.tgz", "integrity": "sha512-2OQsPNEmBCvXuFlIni/a+Rn+R2pHW9INm0BxXJ4hVDA8TirqMj+J/Rp9ItLatT/5pZqWwefVrTQcHpixsxnVlA==", "engines": { "node": ">= 4.0.0" } }, "node_modules/yocto-queue": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==", "dev": true, "engines": { "node": ">=10" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" } } }, "dependencies": { "@aws-crypto/sha256-browser": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/@aws-crypto/sha256-browser/-/sha256-browser-5.2.0.tgz", "integrity": "sha512-AXfN/lGotSQwu6HNcEsIASo7kWXZ5HYWvfOmSNKDsEqC4OashTp8alTmaz+F7TC2L083SFv5RdB+qU3Vs1kZqw==", "optional": true, "requires": { "@aws-crypto/sha256-js": "^5.2.0", "@aws-crypto/supports-web-crypto": "^5.2.0", "@aws-crypto/util": "^5.2.0", "@aws-sdk/types": "^3.222.0", "@aws-sdk/util-locate-window": "^3.0.0", "@smithy/util-utf8": "^2.0.0", "tslib": "^2.6.2" }, "dependencies": { "@smithy/is-array-buffer": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/@smithy/is-array-buffer/-/is-array-buffer-2.2.0.tgz", "integrity": "sha512-GGP3O9QFD24uGeAXYUjwSTXARoqpZykHadOmA8G5vfJPK0/DC67qa//0qvqrJzL1xc8WQWX7/yc7fwudjPHPhA==", "optional": true, "requires": { "tslib": "^2.6.2" } }, "@smithy/util-buffer-from": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/@smithy/util-buffer-from/-/util-buffer-from-2.2.0.tgz", "integrity": "sha512-IJdWBbTcMQ6DA0gdNhh/BwrLkDR+ADW5Kr1aZmd4k3DIF6ezMV4R2NIAmT08wQJ3yUK82thHWmC/TnK/wpMMIA==", "optional": true, "requires": { "@smithy/is-array-buffer": "^2.2.0", "tslib": "^2.6.2" } }, "@smithy/util-utf8": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/@smithy/util-utf8/-/util-utf8-2.3.0.tgz", "integrity": "sha512-R8Rdn8Hy72KKcebgLiv8jQcQkXoLMOGGv5uI1/k0l+snqkOzQ1R0ChUBCxWMlBsFMekWjq0wRudIweFs7sKT5A==", "optional": true, "requires": { "@smithy/util-buffer-from": "^2.2.0", "tslib": "^2.6.2" } } } }, "@aws-crypto/sha256-js": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/@aws-crypto/sha256-js/-/sha256-js-5.2.0.tgz", "integrity": "sha512-FFQQyu7edu4ufvIZ+OadFpHHOt+eSTBaYaki44c+akjg7qZg9oOQeLlk77F6tSYqjDAFClrHJk9tMf0HdVyOvA==", "optional": true, "requires": { "@aws-crypto/util": "^5.2.0", "@aws-sdk/types": "^3.222.0", "tslib": "^2.6.2" } }, "@aws-crypto/supports-web-crypto": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/@aws-crypto/supports-web-crypto/-/supports-web-crypto-5.2.0.tgz", "integrity": "sha512-iAvUotm021kM33eCdNfwIN//F77/IADDSs58i+MDaOqFrVjZo9bAal0NK7HurRuWLLpF1iLX7gbWrjHjeo+YFg==", "optional": true, "requires": { "tslib": "^2.6.2" } }, "@aws-crypto/util": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/@aws-crypto/util/-/util-5.2.0.tgz", "integrity": "sha512-4RkU9EsI6ZpBve5fseQlGNUWKMa1RLPQ1dnjnQoe07ldfIzcsGb5hC5W0Dm7u423KWzawlrpbjXBrXCEv9zazQ==", "optional": true, "requires": { "@aws-sdk/types": "^3.222.0", "@smithy/util-utf8": "^2.0.0", "tslib": "^2.6.2" }, "dependencies": { "@smithy/is-array-buffer": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/@smithy/is-array-buffer/-/is-array-buffer-2.2.0.tgz", "integrity": "sha512-GGP3O9QFD24uGeAXYUjwSTXARoqpZykHadOmA8G5vfJPK0/DC67qa//0qvqrJzL1xc8WQWX7/yc7fwudjPHPhA==", "optional": true, "requires": { "tslib": "^2.6.2" } }, "@smithy/util-buffer-from": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/@smithy/util-buffer-from/-/util-buffer-from-2.2.0.tgz", "integrity": "sha512-IJdWBbTcMQ6DA0gdNhh/BwrLkDR+ADW5Kr1aZmd4k3DIF6ezMV4R2NIAmT08wQJ3yUK82thHWmC/TnK/wpMMIA==", "optional": true, "requires": { "@smithy/is-array-buffer": "^2.2.0", "tslib": "^2.6.2" } }, "@smithy/util-utf8": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/@smithy/util-utf8/-/util-utf8-2.3.0.tgz", "integrity": "sha512-R8Rdn8Hy72KKcebgLiv8jQcQkXoLMOGGv5uI1/k0l+snqkOzQ1R0ChUBCxWMlBsFMekWjq0wRudIweFs7sKT5A==", "optional": true, "requires": { "@smithy/util-buffer-from": "^2.2.0", "tslib": "^2.6.2" } } } }, "@aws-sdk/client-cognito-identity": { "version": "3.1008.0", "resolved": "https://registry.npmjs.org/@aws-sdk/client-cognito-identity/-/client-cognito-identity-3.1008.0.tgz", "integrity": "sha512-zzHnrTImR1JJ/Sq90y35UiFiriwge6W8qZQxIBJCgAMwEGkQAqHEAc3d6ptLmwdntcid3dx7wvauOXbpiMVbAQ==", "optional": true, "requires": { "@aws-crypto/sha256-browser": "5.2.0", "@aws-crypto/sha256-js": "5.2.0", "@aws-sdk/core": "^3.973.19", "@aws-sdk/credential-provider-node": "^3.972.20", "@aws-sdk/middleware-host-header": "^3.972.7", "@aws-sdk/middleware-logger": "^3.972.7", "@aws-sdk/middleware-recursion-detection": "^3.972.7", "@aws-sdk/middleware-user-agent": "^3.972.20", "@aws-sdk/region-config-resolver": "^3.972.7", "@aws-sdk/types": "^3.973.5", "@aws-sdk/util-endpoints": "^3.996.4", "@aws-sdk/util-user-agent-browser": "^3.972.7", "@aws-sdk/util-user-agent-node": "^3.973.6", "@smithy/config-resolver": "^4.4.10", "@smithy/core": "^3.23.9", "@smithy/fetch-http-handler": "^5.3.13", "@smithy/hash-node": "^4.2.11", "@smithy/invalid-dependency": "^4.2.11", "@smithy/middleware-content-length": "^4.2.11", "@smithy/middleware-endpoint": "^4.4.23", "@smithy/middleware-retry": "^4.4.40", "@smithy/middleware-serde": "^4.2.12", "@smithy/middleware-stack": "^4.2.11", "@smithy/node-config-provider": "^4.3.11", "@smithy/node-http-handler": "^4.4.14", "@smithy/protocol-http": "^5.3.11", "@smithy/smithy-client": "^4.12.3", "@smithy/types": "^4.13.0", "@smithy/url-parser": "^4.2.11", "@smithy/util-base64": "^4.3.2", "@smithy/util-body-length-browser": "^4.2.2", "@smithy/util-body-length-node": "^4.2.3", "@smithy/util-defaults-mode-browser": "^4.3.39", "@smithy/util-defaults-mode-node": "^4.2.42", "@smithy/util-endpoints": "^3.3.2", "@smithy/util-middleware": "^4.2.11", "@smithy/util-retry": "^4.2.11", "@smithy/util-utf8": "^4.2.2", "tslib": "^2.6.2" } }, "@aws-sdk/core": { "version": "3.973.19", "resolved": "https://registry.npmjs.org/@aws-sdk/core/-/core-3.973.19.tgz", "integrity": "sha512-56KePyOcZnKTWCd89oJS1G6j3HZ9Kc+bh/8+EbvtaCCXdP6T7O7NzCiPuHRhFLWnzXIaXX3CxAz0nI5My9spHQ==", "optional": true, "requires": { "@aws-sdk/types": "^3.973.5", "@aws-sdk/xml-builder": "^3.972.10", "@smithy/core": "^3.23.9", "@smithy/node-config-provider": "^4.3.11", "@smithy/property-provider": "^4.2.11", "@smithy/protocol-http": "^5.3.11", "@smithy/signature-v4": "^5.3.11", "@smithy/smithy-client": "^4.12.3", "@smithy/types": "^4.13.0", "@smithy/util-base64": "^4.3.2", "@smithy/util-middleware": "^4.2.11", "@smithy/util-utf8": "^4.2.2", "tslib": "^2.6.2" } }, "@aws-sdk/credential-provider-cognito-identity": { "version": "3.972.12", "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-cognito-identity/-/credential-provider-cognito-identity-3.972.12.tgz", "integrity": "sha512-0R7EKJBd19VGoYMrp7ozikwRh6KpapIO3T/Vf9tMrAVxrUNd5V+A6V1gxypY7iJv9GwVR1ZWL/nFt/m0KvcjIQ==", "optional": true, "requires": { "@aws-sdk/nested-clients": "^3.996.9", "@aws-sdk/types": "^3.973.5", "@smithy/property-provider": "^4.2.11", "@smithy/types": "^4.13.0", "tslib": "^2.6.2" } }, "@aws-sdk/credential-provider-env": { "version": "3.972.17", "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-env/-/credential-provider-env-3.972.17.tgz", "integrity": "sha512-MBAMW6YELzE1SdkOniqr51mrjapQUv8JXSGxtwRjQV0mwVDutVsn22OPAUt4RcLRvdiHQmNBDEFP9iTeSVCOlA==", "optional": true, "requires": { "@aws-sdk/core": "^3.973.19", "@aws-sdk/types": "^3.973.5", "@smithy/property-provider": "^4.2.11", "@smithy/types": "^4.13.0", "tslib": "^2.6.2" } }, "@aws-sdk/credential-provider-http": { "version": "3.972.19", "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-http/-/credential-provider-http-3.972.19.tgz", "integrity": "sha512-9EJROO8LXll5a7eUFqu48k6BChrtokbmgeMWmsH7lBb6lVbtjslUYz/ShLi+SHkYzTomiGBhmzTW7y+H4BxsnA==", "optional": true, "requires": { "@aws-sdk/core": "^3.973.19", "@aws-sdk/types": "^3.973.5", "@smithy/fetch-http-handler": "^5.3.13", "@smithy/node-http-handler": "^4.4.14", "@smithy/property-provider": "^4.2.11", "@smithy/protocol-http": "^5.3.11", "@smithy/smithy-client": "^4.12.3", "@smithy/types": "^4.13.0", "@smithy/util-stream": "^4.5.17", "tslib": "^2.6.2" } }, "@aws-sdk/credential-provider-ini": { "version": "3.972.19", "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-ini/-/credential-provider-ini-3.972.19.tgz", "integrity": "sha512-pVJVjWqVrPqjpFq7o0mCmeZu1Y0c94OCHSYgivdCD2wfmYVtBbwQErakruhgOD8pcMcx9SCqRw1pzHKR7OGBcA==", "optional": true, "requires": { "@aws-sdk/core": "^3.973.19", "@aws-sdk/credential-provider-env": "^3.972.17", "@aws-sdk/credential-provider-http": "^3.972.19", "@aws-sdk/credential-provider-login": "^3.972.19", "@aws-sdk/credential-provider-process": "^3.972.17", "@aws-sdk/credential-provider-sso": "^3.972.19", "@aws-sdk/credential-provider-web-identity": "^3.972.19", "@aws-sdk/nested-clients": "^3.996.9", "@aws-sdk/types": "^3.973.5", "@smithy/credential-provider-imds": "^4.2.11", "@smithy/property-provider": "^4.2.11", "@smithy/shared-ini-file-loader": "^4.4.6", "@smithy/types": "^4.13.0", "tslib": "^2.6.2" } }, "@aws-sdk/credential-provider-login": { "version": "3.972.19", "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-login/-/credential-provider-login-3.972.19.tgz", "integrity": "sha512-jOXdZ1o+CywQKr6gyxgxuUmnGwTTnY2Kxs1PM7fI6AYtDWDnmW/yKXayNqkF8KjP1unflqMWKVbVt5VgmE3L0g==", "optional": true, "requires": { "@aws-sdk/core": "^3.973.19", "@aws-sdk/nested-clients": "^3.996.9", "@aws-sdk/types": "^3.973.5", "@smithy/property-provider": "^4.2.11", "@smithy/protocol-http": "^5.3.11", "@smithy/shared-ini-file-loader": "^4.4.6", "@smithy/types": "^4.13.0", "tslib": "^2.6.2" } }, "@aws-sdk/credential-provider-node": { "version": "3.972.20", "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-node/-/credential-provider-node-3.972.20.tgz", "integrity": "sha512-0xHca2BnPY0kzjDYPH7vk8YbfdBPpWVS67rtqQMalYDQUCBYS37cZ55K6TuFxCoIyNZgSCFrVKr9PXC5BVvQQw==", "optional": true, "requires": { "@aws-sdk/credential-provider-env": "^3.972.17", "@aws-sdk/credential-provider-http": "^3.972.19", "@aws-sdk/credential-provider-ini": "^3.972.19", "@aws-sdk/credential-provider-process": "^3.972.17", "@aws-sdk/credential-provider-sso": "^3.972.19", "@aws-sdk/credential-provider-web-identity": "^3.972.19", "@aws-sdk/types": "^3.973.5", "@smithy/credential-provider-imds": "^4.2.11", "@smithy/property-provider": "^4.2.11", "@smithy/shared-ini-file-loader": "^4.4.6", "@smithy/types": "^4.13.0", "tslib": "^2.6.2" } }, "@aws-sdk/credential-provider-process": { "version": "3.972.17", "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-process/-/credential-provider-process-3.972.17.tgz", "integrity": "sha512-c8G8wT1axpJDgaP3xzcy+q8Y1fTi9A2eIQJvyhQ9xuXrUZhlCfXbC0vM9bM1CUXiZppFQ1p7g0tuUMvil/gCPg==", "optional": true, "requires": { "@aws-sdk/core": "^3.973.19", "@aws-sdk/types": "^3.973.5", "@smithy/property-provider": "^4.2.11", "@smithy/shared-ini-file-loader": "^4.4.6", "@smithy/types": "^4.13.0", "tslib": "^2.6.2" } }, "@aws-sdk/credential-provider-sso": { "version": "3.972.19", "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-sso/-/credential-provider-sso-3.972.19.tgz", "integrity": "sha512-kVjQsEU3b///q7EZGrUzol9wzwJFKbEzqJKSq82A9ShrUTEO7FNylTtby3sPV19ndADZh1H3FB3+5ZrvKtEEeg==", "optional": true, "requires": { "@aws-sdk/core": "^3.973.19", "@aws-sdk/nested-clients": "^3.996.9", "@aws-sdk/token-providers": "3.1008.0", "@aws-sdk/types": "^3.973.5", "@smithy/property-provider": "^4.2.11", "@smithy/shared-ini-file-loader": "^4.4.6", "@smithy/types": "^4.13.0", "tslib": "^2.6.2" } }, "@aws-sdk/credential-provider-web-identity": { "version": "3.972.19", "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-web-identity/-/credential-provider-web-identity-3.972.19.tgz", "integrity": "sha512-BV1BlTFdG4w4tAihxN7iXDBoNcNewXD4q8uZlNQiUrnqxwGWUhKHODIQVSPlQGxXClEj+63m+cqZskw+ESmeZg==", "optional": true, "requires": { "@aws-sdk/core": "^3.973.19", "@aws-sdk/nested-clients": "^3.996.9", "@aws-sdk/types": "^3.973.5", "@smithy/property-provider": "^4.2.11", "@smithy/shared-ini-file-loader": "^4.4.6", "@smithy/types": "^4.13.0", "tslib": "^2.6.2" } }, "@aws-sdk/credential-providers": { "version": "3.1008.0", "resolved": "https://registry.npmjs.org/@aws-sdk/credential-providers/-/credential-providers-3.1008.0.tgz", "integrity": "sha512-JPjsKAYpuaDwmeE2WvrrfTb27FYa6kIe0gj1JCazHWGteQ6LDycBddsDsRSgq2MfqAqdcHnrgnfGzY1+j8AxoQ==", "optional": true, "requires": { "@aws-sdk/client-cognito-identity": "3.1008.0", "@aws-sdk/core": "^3.973.19", "@aws-sdk/credential-provider-cognito-identity": "^3.972.12", "@aws-sdk/credential-provider-env": "^3.972.17", "@aws-sdk/credential-provider-http": "^3.972.19", "@aws-sdk/credential-provider-ini": "^3.972.19", "@aws-sdk/credential-provider-login": "^3.972.19", "@aws-sdk/credential-provider-node": "^3.972.20", "@aws-sdk/credential-provider-process": "^3.972.17", "@aws-sdk/credential-provider-sso": "^3.972.19", "@aws-sdk/credential-provider-web-identity": "^3.972.19", "@aws-sdk/nested-clients": "^3.996.9", "@aws-sdk/types": "^3.973.5", "@smithy/config-resolver": "^4.4.10", "@smithy/core": "^3.23.9", "@smithy/credential-provider-imds": "^4.2.11", "@smithy/node-config-provider": "^4.3.11", "@smithy/property-provider": "^4.2.11", "@smithy/types": "^4.13.0", "tslib": "^2.6.2" } }, "@aws-sdk/middleware-host-header": { "version": "3.972.7", "resolved": "https://registry.npmjs.org/@aws-sdk/middleware-host-header/-/middleware-host-header-3.972.7.tgz", "integrity": "sha512-aHQZgztBFEpDU1BB00VWCIIm85JjGjQW1OG9+98BdmaOpguJvzmXBGbnAiYcciCd+IS4e9BEq664lhzGnWJHgQ==", "optional": true, "requires": { "@aws-sdk/types": "^3.973.5", "@smithy/protocol-http": "^5.3.11", "@smithy/types": "^4.13.0", "tslib": "^2.6.2" } }, "@aws-sdk/middleware-logger": { "version": "3.972.7", "resolved": "https://registry.npmjs.org/@aws-sdk/middleware-logger/-/middleware-logger-3.972.7.tgz", "integrity": "sha512-LXhiWlWb26txCU1vcI9PneESSeRp/RYY/McuM4SpdrimQR5NgwaPb4VJCadVeuGWgh6QmqZ6rAKSoL1ob16W6w==", "optional": true, "requires": { "@aws-sdk/types": "^3.973.5", "@smithy/types": "^4.13.0", "tslib": "^2.6.2" } }, "@aws-sdk/middleware-recursion-detection": { "version": "3.972.7", "resolved": "https://registry.npmjs.org/@aws-sdk/middleware-recursion-detection/-/middleware-recursion-detection-3.972.7.tgz", "integrity": "sha512-l2VQdcBcYLzIzykCHtXlbpiVCZ94/xniLIkAj0jpnpjY4xlgZx7f56Ypn+uV1y3gG0tNVytJqo3K9bfMFee7SQ==", "optional": true, "requires": { "@aws-sdk/types": "^3.973.5", "@aws/lambda-invoke-store": "^0.2.2", "@smithy/protocol-http": "^5.3.11", "@smithy/types": "^4.13.0", "tslib": "^2.6.2" } }, "@aws-sdk/middleware-user-agent": { "version": "3.972.20", "resolved": "https://registry.npmjs.org/@aws-sdk/middleware-user-agent/-/middleware-user-agent-3.972.20.tgz", "integrity": "sha512-3kNTLtpUdeahxtnJRnj/oIdLAUdzTfr9N40KtxNhtdrq+Q1RPMdCJINRXq37m4t5+r3H70wgC3opW46OzFcZYA==", "optional": true, "requires": { "@aws-sdk/core": "^3.973.19", "@aws-sdk/types": "^3.973.5", "@aws-sdk/util-endpoints": "^3.996.4", "@smithy/core": "^3.23.9", "@smithy/protocol-http": "^5.3.11", "@smithy/types": "^4.13.0", "@smithy/util-retry": "^4.2.11", "tslib": "^2.6.2" } }, "@aws-sdk/nested-clients": { "version": "3.996.9", "resolved": "https://registry.npmjs.org/@aws-sdk/nested-clients/-/nested-clients-3.996.9.tgz", "integrity": "sha512-+RpVtpmQbbtzFOKhMlsRcXM/3f1Z49qTOHaA8gEpHOYruERmog6f2AUtf/oTRLCWjR9H2b3roqryV/hI7QMW8w==", "optional": true, "requires": { "@aws-crypto/sha256-browser": "5.2.0", "@aws-crypto/sha256-js": "5.2.0", "@aws-sdk/core": "^3.973.19", "@aws-sdk/middleware-host-header": "^3.972.7", "@aws-sdk/middleware-logger": "^3.972.7", "@aws-sdk/middleware-recursion-detection": "^3.972.7", "@aws-sdk/middleware-user-agent": "^3.972.20", "@aws-sdk/region-config-resolver": "^3.972.7", "@aws-sdk/types": "^3.973.5", "@aws-sdk/util-endpoints": "^3.996.4", "@aws-sdk/util-user-agent-browser": "^3.972.7", "@aws-sdk/util-user-agent-node": "^3.973.6", "@smithy/config-resolver": "^4.4.10", "@smithy/core": "^3.23.9", "@smithy/fetch-http-handler": "^5.3.13", "@smithy/hash-node": "^4.2.11", "@smithy/invalid-dependency": "^4.2.11", "@smithy/middleware-content-length": "^4.2.11", "@smithy/middleware-endpoint": "^4.4.23", "@smithy/middleware-retry": "^4.4.40", "@smithy/middleware-serde": "^4.2.12", "@smithy/middleware-stack": "^4.2.11", "@smithy/node-config-provider": "^4.3.11", "@smithy/node-http-handler": "^4.4.14", "@smithy/protocol-http": "^5.3.11", "@smithy/smithy-client": "^4.12.3", "@smithy/types": "^4.13.0", "@smithy/url-parser": "^4.2.11", "@smithy/util-base64": "^4.3.2", "@smithy/util-body-length-browser": "^4.2.2", "@smithy/util-body-length-node": "^4.2.3", "@smithy/util-defaults-mode-browser": "^4.3.39", "@smithy/util-defaults-mode-node": "^4.2.42", "@smithy/util-endpoints": "^3.3.2", "@smithy/util-middleware": "^4.2.11", "@smithy/util-retry": "^4.2.11", "@smithy/util-utf8": "^4.2.2", "tslib": "^2.6.2" } }, "@aws-sdk/region-config-resolver": { "version": "3.972.7", "resolved": "https://registry.npmjs.org/@aws-sdk/region-config-resolver/-/region-config-resolver-3.972.7.tgz", "integrity": "sha512-/Ev/6AI8bvt4HAAptzSjThGUMjcWaX3GX8oERkB0F0F9x2dLSBdgFDiyrRz3i0u0ZFZFQ1b28is4QhyqXTUsVA==", "optional": true, "requires": { "@aws-sdk/types": "^3.973.5", "@smithy/config-resolver": "^4.4.10", "@smithy/node-config-provider": "^4.3.11", "@smithy/types": "^4.13.0", "tslib": "^2.6.2" } }, "@aws-sdk/token-providers": { "version": "3.1008.0", "resolved": "https://registry.npmjs.org/@aws-sdk/token-providers/-/token-providers-3.1008.0.tgz", "integrity": "sha512-TulwlHQBWcJs668kNUDMZHN51DeLrDsYT59Ux4a/nbvr025gM6HjKJJ3LvnZccam7OS/ZKUVkWomCneRQKJbBg==", "optional": true, "requires": { "@aws-sdk/core": "^3.973.19", "@aws-sdk/nested-clients": "^3.996.9", "@aws-sdk/types": "^3.973.5", "@smithy/property-provider": "^4.2.11", "@smithy/shared-ini-file-loader": "^4.4.6", "@smithy/types": "^4.13.0", "tslib": "^2.6.2" } }, "@aws-sdk/types": { "version": "3.973.5", "resolved": "https://registry.npmjs.org/@aws-sdk/types/-/types-3.973.5.tgz", "integrity": "sha512-hl7BGwDCWsjH8NkZfx+HgS7H2LyM2lTMAI7ba9c8O0KqdBLTdNJivsHpqjg9rNlAlPyREb6DeDRXUl0s8uFdmQ==", "optional": true, "requires": { "@smithy/types": "^4.13.0", "tslib": "^2.6.2" } }, "@aws-sdk/util-endpoints": { "version": "3.996.4", "resolved": "https://registry.npmjs.org/@aws-sdk/util-endpoints/-/util-endpoints-3.996.4.tgz", "integrity": "sha512-Hek90FBmd4joCFj+Vc98KLJh73Zqj3s2W56gjAcTkrNLMDI5nIFkG9YpfcJiVI1YlE2Ne1uOQNe+IgQ/Vz2XRA==", "optional": true, "requires": { "@aws-sdk/types": "^3.973.5", "@smithy/types": "^4.13.0", "@smithy/url-parser": "^4.2.11", "@smithy/util-endpoints": "^3.3.2", "tslib": "^2.6.2" } }, "@aws-sdk/util-locate-window": { "version": "3.965.5", "resolved": "https://registry.npmjs.org/@aws-sdk/util-locate-window/-/util-locate-window-3.965.5.tgz", "integrity": "sha512-WhlJNNINQB+9qtLtZJcpQdgZw3SCDCpXdUJP7cToGwHbCWCnRckGlc6Bx/OhWwIYFNAn+FIydY8SZ0QmVu3xTQ==", "optional": true, "requires": { "tslib": "^2.6.2" } }, "@aws-sdk/util-user-agent-browser": { "version": "3.972.7", "resolved": "https://registry.npmjs.org/@aws-sdk/util-user-agent-browser/-/util-user-agent-browser-3.972.7.tgz", "integrity": "sha512-7SJVuvhKhMF/BkNS1n0QAJYgvEwYbK2QLKBrzDiwQGiTRU6Yf1f3nehTzm/l21xdAOtWSfp2uWSddPnP2ZtsVw==", "optional": true, "requires": { "@aws-sdk/types": "^3.973.5", "@smithy/types": "^4.13.0", "bowser": "^2.11.0", "tslib": "^2.6.2" } }, "@aws-sdk/util-user-agent-node": { "version": "3.973.6", "resolved": "https://registry.npmjs.org/@aws-sdk/util-user-agent-node/-/util-user-agent-node-3.973.6.tgz", "integrity": "sha512-iF7G0prk7AvmOK64FcLvc/fW+Ty1H+vttajL7PvJFReU8urMxfYmynTTuFKDTA76Wgpq3FzTPKwabMQIXQHiXQ==", "optional": true, "requires": { "@aws-sdk/middleware-user-agent": "^3.972.20", "@aws-sdk/types": "^3.973.5", "@smithy/node-config-provider": "^4.3.11", "@smithy/types": "^4.13.0", "@smithy/util-config-provider": "^4.2.2", "tslib": "^2.6.2" } }, "@aws-sdk/xml-builder": { "version": "3.972.10", "resolved": "https://registry.npmjs.org/@aws-sdk/xml-builder/-/xml-builder-3.972.10.tgz", "integrity": "sha512-OnejAIVD+CxzyAUrVic7lG+3QRltyja9LoNqCE/1YVs8ichoTbJlVSaZ9iSMcnHLyzrSNtvaOGjSDRP+d/ouFA==", "optional": true, "requires": { "@smithy/types": "^4.13.0", "fast-xml-parser": "5.4.1", "tslib": "^2.6.2" } }, "@aws/lambda-invoke-store": { "version": "0.2.4", "resolved": "https://registry.npmjs.org/@aws/lambda-invoke-store/-/lambda-invoke-store-0.2.4.tgz", "integrity": "sha512-iY8yvjE0y651BixKNPgmv1WrQc+GZ142sb0z4gYnChDDY2YqI4P/jsSopBWrKfAt7LOJAkOXt7rC/hms+WclQQ==", "optional": true }, "@breejs/later": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/@breejs/later/-/later-4.2.0.tgz", "integrity": "sha512-EVMD0SgJtOuFeg0lAVbCwa+qeTKILb87jqvLyUtQswGD9+ce2nB52Y5zbTF1Hc0MDFfbydcMcxb47jSdhikVHA==" }, "@codemirror/autocomplete": { "version": "6.16.3", "resolved": "https://registry.npmjs.org/@codemirror/autocomplete/-/autocomplete-6.16.3.tgz", "integrity": "sha512-Vl/tIeRVVUCRDuOG48lttBasNQu8usGgXQawBXI7WJAiUDSFOfzflmEsZFZo48mAvAaa4FZ/4/yLLxFtdJaKYA==", "dev": true, "requires": { "@codemirror/language": "^6.0.0", "@codemirror/state": "^6.0.0", "@codemirror/view": "^6.17.0", "@lezer/common": "^1.0.0" } }, "@codemirror/commands": { "version": "6.10.2", "resolved": "https://registry.npmjs.org/@codemirror/commands/-/commands-6.10.2.tgz", "integrity": "sha512-vvX1fsih9HledO1c9zdotZYUZnE4xV0m6i3m25s5DIfXofuprk6cRcLUZvSk3CASUbwjQX21tOGbkY2BH8TpnQ==", "dev": true, "requires": { "@codemirror/language": "^6.0.0", "@codemirror/state": "^6.4.0", "@codemirror/view": "^6.27.0", "@lezer/common": "^1.1.0" } }, "@codemirror/lang-javascript": { "version": "6.2.5", "resolved": "https://registry.npmjs.org/@codemirror/lang-javascript/-/lang-javascript-6.2.5.tgz", "integrity": "sha512-zD4e5mS+50htS7F+TYjBPsiIFGanfVqg4HyUz6WNFikgOPf2BgKlx+TQedI1w6n/IqRBVBbBWmGFdLB/7uxO4A==", "dev": true, "requires": { "@codemirror/autocomplete": "^6.0.0", "@codemirror/language": "^6.6.0", "@codemirror/lint": "^6.0.0", "@codemirror/state": "^6.0.0", "@codemirror/view": "^6.17.0", "@lezer/common": "^1.0.0", "@lezer/javascript": "^1.0.0" } }, "@codemirror/lang-yaml": { "version": "6.1.2", "resolved": "https://registry.npmjs.org/@codemirror/lang-yaml/-/lang-yaml-6.1.2.tgz", "integrity": "sha512-dxrfG8w5Ce/QbT7YID7mWZFKhdhsaTNOYjOkSIMt1qmC4VQnXSDSYVHHHn8k6kJUfIhtLo8t1JJgltlxWdsITw==", "dev": true, "requires": { "@codemirror/autocomplete": "^6.0.0", "@codemirror/language": "^6.0.0", "@codemirror/state": "^6.0.0", "@lezer/common": "^1.2.0", "@lezer/highlight": "^1.2.0", "@lezer/lr": "^1.0.0", "@lezer/yaml": "^1.0.0" } }, "@codemirror/language": { "version": "6.12.2", "resolved": "https://registry.npmjs.org/@codemirror/language/-/language-6.12.2.tgz", "integrity": "sha512-jEPmz2nGGDxhRTg3lTpzmIyGKxz3Gp3SJES4b0nAuE5SWQoKdT5GoQ69cwMmFd+wvFUhYirtDTr0/DRHpQAyWg==", "dev": true, "requires": { "@codemirror/state": "^6.0.0", "@codemirror/view": "^6.23.0", "@lezer/common": "^1.5.0", "@lezer/highlight": "^1.0.0", "@lezer/lr": "^1.0.0", "style-mod": "^4.0.0" } }, "@codemirror/lint": { "version": "6.8.1", "resolved": "https://registry.npmjs.org/@codemirror/lint/-/lint-6.8.1.tgz", "integrity": "sha512-IZ0Y7S4/bpaunwggW2jYqwLuHj0QtESf5xcROewY6+lDNwZ/NzvR4t+vpYgg9m7V8UXLPYqG+lu3DF470E5Oxg==", "dev": true, "requires": { "@codemirror/state": "^6.0.0", "@codemirror/view": "^6.0.0", "crelt": "^1.0.5" } }, "@codemirror/state": { "version": "6.5.4", "resolved": "https://registry.npmjs.org/@codemirror/state/-/state-6.5.4.tgz", "integrity": "sha512-8y7xqG/hpB53l25CIoit9/ngxdfoG+fx+V3SHBrinnhOtLvKHRyAJJuHzkWrR4YXXLX8eXBsejgAAxHUOdW1yw==", "dev": true, "requires": { "@marijn/find-cluster-break": "^1.0.0" } }, "@codemirror/view": { "version": "6.39.16", "resolved": "https://registry.npmjs.org/@codemirror/view/-/view-6.39.16.tgz", "integrity": "sha512-m6S22fFpKtOWhq8HuhzsI1WzUP/hB9THbDj0Tl5KX4gbO6Y91hwBl7Yky33NdvB6IffuRFiBxf1R8kJMyXmA4Q==", "dev": true, "requires": { "@codemirror/state": "^6.5.0", "crelt": "^1.0.6", "style-mod": "^4.1.0", "w3c-keyname": "^2.2.4" } }, "@esbuild/aix-ppc64": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.27.4.tgz", "integrity": "sha512-cQPwL2mp2nSmHHJlCyoXgHGhbEPMrEEU5xhkcy3Hs/O7nGZqEpZ2sUtLaL9MORLtDfRvVl2/3PAuEkYZH0Ty8Q==", "dev": true, "optional": true }, "@esbuild/android-arm": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.27.4.tgz", "integrity": "sha512-X9bUgvxiC8CHAGKYufLIHGXPJWnr0OCdR0anD2e21vdvgCI8lIfqFbnoeOz7lBjdrAGUhqLZLcQo6MLhTO2DKQ==", "dev": true, "optional": true }, "@esbuild/android-arm64": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.27.4.tgz", "integrity": "sha512-gdLscB7v75wRfu7QSm/zg6Rx29VLdy9eTr2t44sfTW7CxwAtQghZ4ZnqHk3/ogz7xao0QAgrkradbBzcqFPasw==", "dev": true, "optional": true }, "@esbuild/android-x64": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.27.4.tgz", "integrity": "sha512-PzPFnBNVF292sfpfhiyiXCGSn9HZg5BcAz+ivBuSsl6Rk4ga1oEXAamhOXRFyMcjwr2DVtm40G65N3GLeH1Lvw==", "dev": true, "optional": true }, "@esbuild/darwin-arm64": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.27.4.tgz", "integrity": "sha512-b7xaGIwdJlht8ZFCvMkpDN6uiSmnxxK56N2GDTMYPr2/gzvfdQN8rTfBsvVKmIVY/X7EM+/hJKEIbbHs9oA4tQ==", "dev": true, "optional": true }, "@esbuild/darwin-x64": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.27.4.tgz", "integrity": "sha512-sR+OiKLwd15nmCdqpXMnuJ9W2kpy0KigzqScqHI3Hqwr7IXxBp3Yva+yJwoqh7rE8V77tdoheRYataNKL4QrPw==", "dev": true, "optional": true }, "@esbuild/freebsd-arm64": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.27.4.tgz", "integrity": "sha512-jnfpKe+p79tCnm4GVav68A7tUFeKQwQyLgESwEAUzyxk/TJr4QdGog9sqWNcUbr/bZt/O/HXouspuQDd9JxFSw==", "dev": true, "optional": true }, "@esbuild/freebsd-x64": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.27.4.tgz", "integrity": "sha512-2kb4ceA/CpfUrIcTUl1wrP/9ad9Atrp5J94Lq69w7UwOMolPIGrfLSvAKJp0RTvkPPyn6CIWrNy13kyLikZRZQ==", "dev": true, "optional": true }, "@esbuild/linux-arm": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.27.4.tgz", "integrity": "sha512-aBYgcIxX/wd5n2ys0yESGeYMGF+pv6g0DhZr3G1ZG4jMfruU9Tl1i2Z+Wnj9/KjGz1lTLCcorqE2viePZqj4Eg==", "dev": true, "optional": true }, "@esbuild/linux-arm64": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.27.4.tgz", "integrity": "sha512-7nQOttdzVGth1iz57kxg9uCz57dxQLHWxopL6mYuYthohPKEK0vU0C3O21CcBK6KDlkYVcnDXY099HcCDXd9dA==", "dev": true, "optional": true }, "@esbuild/linux-ia32": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.27.4.tgz", "integrity": "sha512-oPtixtAIzgvzYcKBQM/qZ3R+9TEUd1aNJQu0HhGyqtx6oS7qTpvjheIWBbes4+qu1bNlo2V4cbkISr8q6gRBFA==", "dev": true, "optional": true }, "@esbuild/linux-loong64": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.27.4.tgz", "integrity": "sha512-8mL/vh8qeCoRcFH2nM8wm5uJP+ZcVYGGayMavi8GmRJjuI3g1v6Z7Ni0JJKAJW+m0EtUuARb6Lmp4hMjzCBWzA==", "dev": true, "optional": true }, "@esbuild/linux-mips64el": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.27.4.tgz", "integrity": "sha512-1RdrWFFiiLIW7LQq9Q2NES+HiD4NyT8Itj9AUeCl0IVCA459WnPhREKgwrpaIfTOe+/2rdntisegiPWn/r/aAw==", "dev": true, "optional": true }, "@esbuild/linux-ppc64": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.27.4.tgz", "integrity": "sha512-tLCwNG47l3sd9lpfyx9LAGEGItCUeRCWeAx6x2Jmbav65nAwoPXfewtAdtbtit/pJFLUWOhpv0FpS6GQAmPrHA==", "dev": true, "optional": true }, "@esbuild/linux-riscv64": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.27.4.tgz", "integrity": "sha512-BnASypppbUWyqjd1KIpU4AUBiIhVr6YlHx/cnPgqEkNoVOhHg+YiSVxM1RLfiy4t9cAulbRGTNCKOcqHrEQLIw==", "dev": true, "optional": true }, "@esbuild/linux-s390x": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.27.4.tgz", "integrity": "sha512-+eUqgb/Z7vxVLezG8bVB9SfBie89gMueS+I0xYh2tJdw3vqA/0ImZJ2ROeWwVJN59ihBeZ7Tu92dF/5dy5FttA==", "dev": true, "optional": true }, "@esbuild/linux-x64": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.27.4.tgz", "integrity": "sha512-S5qOXrKV8BQEzJPVxAwnryi2+Iq5pB40gTEIT69BQONqR7JH1EPIcQ/Uiv9mCnn05jff9umq/5nqzxlqTOg9NA==", "dev": true, "optional": true }, "@esbuild/netbsd-arm64": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.27.4.tgz", "integrity": "sha512-xHT8X4sb0GS8qTqiwzHqpY00C95DPAq7nAwX35Ie/s+LO9830hrMd3oX0ZMKLvy7vsonee73x0lmcdOVXFzd6Q==", "dev": true, "optional": true }, "@esbuild/netbsd-x64": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.27.4.tgz", "integrity": "sha512-RugOvOdXfdyi5Tyv40kgQnI0byv66BFgAqjdgtAKqHoZTbTF2QqfQrFwa7cHEORJf6X2ht+l9ABLMP0dnKYsgg==", "dev": true, "optional": true }, "@esbuild/openbsd-arm64": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.27.4.tgz", "integrity": "sha512-2MyL3IAaTX+1/qP0O1SwskwcwCoOI4kV2IBX1xYnDDqthmq5ArrW94qSIKCAuRraMgPOmG0RDTA74mzYNQA9ow==", "dev": true, "optional": true }, "@esbuild/openbsd-x64": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.27.4.tgz", "integrity": "sha512-u8fg/jQ5aQDfsnIV6+KwLOf1CmJnfu1ShpwqdwC0uA7ZPwFws55Ngc12vBdeUdnuWoQYx/SOQLGDcdlfXhYmXQ==", "dev": true, "optional": true }, "@esbuild/openharmony-arm64": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/openharmony-arm64/-/openharmony-arm64-0.27.4.tgz", "integrity": "sha512-JkTZrl6VbyO8lDQO3yv26nNr2RM2yZzNrNHEsj9bm6dOwwu9OYN28CjzZkH57bh4w0I2F7IodpQvUAEd1mbWXg==", "dev": true, "optional": true }, "@esbuild/sunos-x64": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.27.4.tgz", "integrity": "sha512-/gOzgaewZJfeJTlsWhvUEmUG4tWEY2Spp5M20INYRg2ZKl9QPO3QEEgPeRtLjEWSW8FilRNacPOg8R1uaYkA6g==", "dev": true, "optional": true }, "@esbuild/win32-arm64": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.27.4.tgz", "integrity": "sha512-Z9SExBg2y32smoDQdf1HRwHRt6vAHLXcxD2uGgO/v2jK7Y718Ix4ndsbNMU/+1Qiem9OiOdaqitioZwxivhXYg==", "dev": true, "optional": true }, "@esbuild/win32-ia32": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.27.4.tgz", "integrity": "sha512-DAyGLS0Jz5G5iixEbMHi5KdiApqHBWMGzTtMiJ72ZOLhbu/bzxgAe8Ue8CTS3n3HbIUHQz/L51yMdGMeoxXNJw==", "dev": true, "optional": true }, "@esbuild/win32-x64": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.27.4.tgz", "integrity": "sha512-+knoa0BDoeXgkNvvV1vvbZX4+hizelrkwmGJBdT17t8FNPwG2lKemmuMZlmaNQ3ws3DKKCxpb4zRZEIp3UxFCg==", "dev": true, "optional": true }, "@eslint-community/eslint-utils": { "version": "4.9.1", "resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.9.1.tgz", "integrity": "sha512-phrYmNiYppR7znFEdqgfWHXR6NCkZEK7hwWDHZUjit/2/U0r6XvkDl0SYnoM51Hq7FhCGdLDT6zxCCOY1hexsQ==", "dev": true, "requires": { "eslint-visitor-keys": "^3.4.3" } }, "@eslint-community/regexpp": { "version": "4.12.2", "resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.12.2.tgz", "integrity": "sha512-EriSTlt5OC9/7SXkRSCAhfSxxoSUgBm33OH+IkwbdpgoqsSsUg7y3uh+IICI/Qg4BBWr3U2i39RpmycbxMq4ew==", "dev": true }, "@eslint/config-array": { "version": "0.23.3", "resolved": "https://registry.npmjs.org/@eslint/config-array/-/config-array-0.23.3.tgz", "integrity": "sha512-j+eEWmB6YYLwcNOdlwQ6L2OsptI/LO6lNBuLIqe5R7RetD658HLoF+Mn7LzYmAWWNNzdC6cqP+L6r8ujeYXWLw==", "dev": true, "requires": { "@eslint/object-schema": "^3.0.3", "debug": "^4.3.1", "minimatch": "^10.2.4" }, "dependencies": { "balanced-match": { "version": "4.0.4", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-4.0.4.tgz", "integrity": "sha512-BLrgEcRTwX2o6gGxGOCNyMvGSp35YofuYzw9h1IMTRmKqttAZZVU67bdb9Pr2vUHA8+j3i2tJfjO6C6+4myGTA==", "dev": true }, "brace-expansion": { "version": "5.0.4", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.4.tgz", "integrity": "sha512-h+DEnpVvxmfVefa4jFbCf5HdH5YMDXRsmKflpf1pILZWRFlTbJpxeU55nJl4Smt5HQaGzg1o6RHFPJaOqnmBDg==", "dev": true, "requires": { "balanced-match": "^4.0.2" } }, "minimatch": { "version": "10.2.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.2.4.tgz", "integrity": "sha512-oRjTw/97aTBN0RHbYCdtF1MQfvusSIBQM0IZEgzl6426+8jSC0nF1a/GmnVLpfB9yyr6g6FTqWqiZVbxrtaCIg==", "dev": true, "requires": { "brace-expansion": "^5.0.2" } } } }, "@eslint/config-helpers": { "version": "0.5.3", "resolved": "https://registry.npmjs.org/@eslint/config-helpers/-/config-helpers-0.5.3.tgz", "integrity": "sha512-lzGN0onllOZCGroKJmRwY6QcEHxbjBw1gwB8SgRSqK8YbbtEXMvKynsXc3553ckIEBxsbMBU7oOZXKIPGZNeZw==", "dev": true, "requires": { "@eslint/core": "^1.1.1" } }, "@eslint/core": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/@eslint/core/-/core-1.1.1.tgz", "integrity": "sha512-QUPblTtE51/7/Zhfv8BDwO0qkkzQL7P/aWWbqcf4xWLEYn1oKjdO0gglQBB4GAsu7u6wjijbCmzsUTy6mnk6oQ==", "dev": true, "requires": { "@types/json-schema": "^7.0.15" } }, "@eslint/js": { "version": "10.0.1", "resolved": "https://registry.npmjs.org/@eslint/js/-/js-10.0.1.tgz", "integrity": "sha512-zeR9k5pd4gxjZ0abRoIaxdc7I3nDktoXZk2qOv9gCNWx3mVwEn32VRhyLaRsDiJjTs0xq/T8mfPtyuXu7GWBcA==", "dev": true, "requires": {} }, "@eslint/object-schema": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/@eslint/object-schema/-/object-schema-3.0.3.tgz", "integrity": "sha512-iM869Pugn9Nsxbh/YHRqYiqd23AmIbxJOcpUMOuWCVNdoQJ5ZtwL6h3t0bcZzJUlC3Dq9jCFCESBZnX0GTv7iQ==", "dev": true }, "@eslint/plugin-kit": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/@eslint/plugin-kit/-/plugin-kit-0.6.1.tgz", "integrity": "sha512-iH1B076HoAshH1mLpHMgwdGeTs0CYwL0SPMkGuSebZrwBp16v415e9NZXg2jtrqPVQjf6IANe2Vtlr5KswtcZQ==", "dev": true, "requires": { "@humanwhocodes/object-schema": "^2.0.3", "debug": "^4.3.1", "minimatch": "^3.0.5" }, "dependencies": { "brace-expansion": { "version": "1.1.12", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.12.tgz", "integrity": "sha512-9T9UjW3r0UW5c1Q7GTwllptXwhvYmEzFhzMfZ9H7FQWt+uZePjZPjBP/W1ZEyZ1twGWom5/56TF4lPcqjnDHcg==", "dev": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" } }, "minimatch": { "version": "3.1.5", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.5.tgz", "integrity": "sha512-VgjWUsnnT6n+NUk6eZq77zeFdpW2LWDzP6zFGrCbHXiYNul5Dzqk2HHQ5uFH2DNW5Xbp8+jVzaeNt94ssEEl4w==", "dev": true, "requires": { "brace-expansion": "^1.1.7" } } } }, "@humanfs/core": { "version": "0.19.1", "resolved": "https://registry.npmjs.org/@humanfs/core/-/core-0.19.1.tgz", "integrity": "sha512-5DyQ4+1JEUzejeK1JGICcideyfUbGixgS9jNgex5nqkW+cY7WZhxBigmieN5Qnw9ZosSNVC9KQKyb+GUaGyKUA==", "dev": true }, "@humanfs/node": { "version": "0.16.7", "resolved": "https://registry.npmjs.org/@humanfs/node/-/node-0.16.7.tgz", "integrity": "sha512-/zUx+yOsIrG4Y43Eh2peDeKCxlRt/gET6aHfaKpuq267qXdYDFViVHfMaLyygZOnl0kGWxFIgsBy8QFuTLUXEQ==", "dev": true, "requires": { "@humanfs/core": "^0.19.1", "@humanwhocodes/retry": "^0.4.0" } }, "@humanwhocodes/module-importer": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/@humanwhocodes/module-importer/-/module-importer-1.0.1.tgz", "integrity": "sha512-bxveV4V8v5Yb4ncFTT3rPSgZBOpCkjfK0y4oVVVJwIuDVBRMDXrPyXRL988i5ap9m9bnyEEjWfm5WkBmtffLfA==", "dev": true }, "@humanwhocodes/object-schema": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-2.0.3.tgz", "integrity": "sha512-93zYdMES/c1D69yZiKDBj0V24vqNzB/koF26KPaagAfd3P/4gUlh3Dys5ogAK+Exi9QyzlD8x/08Zt7wIKcDcA==", "dev": true }, "@humanwhocodes/retry": { "version": "0.4.3", "resolved": "https://registry.npmjs.org/@humanwhocodes/retry/-/retry-0.4.3.tgz", "integrity": "sha512-bV0Tgo9K4hfPCek+aMAn81RppFKv2ySDQeMoSZuvTASywNTnVJCArCZE2FWqpvIatKu7VMRLWlR1EazvVhDyhQ==", "dev": true }, "@jridgewell/gen-mapping": { "version": "0.3.13", "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.13.tgz", "integrity": "sha512-2kkt/7niJ6MgEPxF0bYdQ6etZaA+fQvDcLKckhy1yIQOzaoKjBBjSj63/aLVjYE3qhRt5dvM+uUyfCg6UKCBbA==", "dev": true, "requires": { "@jridgewell/sourcemap-codec": "^1.5.0", "@jridgewell/trace-mapping": "^0.3.24" } }, "@jridgewell/remapping": { "version": "2.3.5", "resolved": "https://registry.npmjs.org/@jridgewell/remapping/-/remapping-2.3.5.tgz", "integrity": "sha512-LI9u/+laYG4Ds1TDKSJW2YPrIlcVYOwi2fUC6xB43lueCjgxV4lffOCZCtYFiH6TNOX+tQKXx97T4IKHbhyHEQ==", "dev": true, "requires": { "@jridgewell/gen-mapping": "^0.3.5", "@jridgewell/trace-mapping": "^0.3.24" } }, "@jridgewell/resolve-uri": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.2.tgz", "integrity": "sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==", "dev": true }, "@jridgewell/sourcemap-codec": { "version": "1.5.5", "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.5.tgz", "integrity": "sha512-cYQ9310grqxueWbl+WuIUIaiUaDcj7WOq5fVhEljNVgRfOUhY9fy2zTvfoqWsnebh8Sl70VScFbICvJnLKB0Og==", "dev": true }, "@jridgewell/trace-mapping": { "version": "0.3.31", "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.31.tgz", "integrity": "sha512-zzNR+SdQSDJzc8joaeP8QQoCQr8NuYx2dIIytl1QeBEZHJ9uW6hebsrYgbz8hJwUQao3TWCMtmfV8Nu1twOLAw==", "dev": true, "requires": { "@jridgewell/resolve-uri": "^3.1.0", "@jridgewell/sourcemap-codec": "^1.4.14" } }, "@koa/bodyparser": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/@koa/bodyparser/-/bodyparser-5.1.2.tgz", "integrity": "sha512-eGJm9/66iUX+LUH03Cz0e94unbSKrmSPCick4MO5UorAAomcjC5Kl+SkoZ6CSyPew3neMYjj7n+djnlGYBSJAg==", "requires": { "co-body": "^6.1.0", "lodash.merge": "^4.6.2", "type-is": "^1.6.18" } }, "@koa/router": { "version": "13.1.1", "resolved": "https://registry.npmjs.org/@koa/router/-/router-13.1.1.tgz", "integrity": "sha512-JQEuMANYRVHs7lm7KY9PCIjkgJk73h4m4J+g2mkw2Vo1ugPZ17UJVqEH8F+HeAdjKz5do1OaLe7ArDz+z308gw==", "requires": { "debug": "^4.4.1", "http-errors": "^2.0.0", "koa-compose": "^4.1.0", "path-to-regexp": "^6.3.0" } }, "@lezer/common": { "version": "1.5.1", "resolved": "https://registry.npmjs.org/@lezer/common/-/common-1.5.1.tgz", "integrity": "sha512-6YRVG9vBkaY7p1IVxL4s44n5nUnaNnGM2/AckNgYOnxTG2kWh1vR8BMxPseWPjRNpb5VtXnMpeYAEAADoRV1Iw==", "dev": true }, "@lezer/highlight": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/@lezer/highlight/-/highlight-1.2.3.tgz", "integrity": "sha512-qXdH7UqTvGfdVBINrgKhDsVTJTxactNNxLk7+UMwZhU13lMHaOBlJe9Vqp907ya56Y3+ed2tlqzys7jDkTmW0g==", "dev": true, "requires": { "@lezer/common": "^1.3.0" } }, "@lezer/javascript": { "version": "1.5.4", "resolved": "https://registry.npmjs.org/@lezer/javascript/-/javascript-1.5.4.tgz", "integrity": "sha512-vvYx3MhWqeZtGPwDStM2dwgljd5smolYD2lR2UyFcHfxbBQebqx8yjmFmxtJ/E6nN6u1D9srOiVWm3Rb4tmcUA==", "dev": true, "requires": { "@lezer/common": "^1.2.0", "@lezer/highlight": "^1.1.3", "@lezer/lr": "^1.3.0" } }, "@lezer/lr": { "version": "1.4.8", "resolved": "https://registry.npmjs.org/@lezer/lr/-/lr-1.4.8.tgz", "integrity": "sha512-bPWa0Pgx69ylNlMlPvBPryqeLYQjyJjqPx+Aupm5zydLIF3NE+6MMLT8Yi23Bd9cif9VS00aUebn+6fDIGBcDA==", "dev": true, "requires": { "@lezer/common": "^1.0.0" } }, "@lezer/yaml": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/@lezer/yaml/-/yaml-1.0.4.tgz", "integrity": "sha512-2lrrHqxalACEbxIbsjhqGpSW8kWpUKuY6RHgnSAFZa6qK62wvnPxA8hGOwOoDbwHcOFs5M4o27mjGu+P7TvBmw==", "dev": true, "requires": { "@lezer/common": "^1.2.0", "@lezer/highlight": "^1.0.0", "@lezer/lr": "^1.4.0" } }, "@marijn/find-cluster-break": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/@marijn/find-cluster-break/-/find-cluster-break-1.0.2.tgz", "integrity": "sha512-l0h88YhZFyKdXIFNfSWpyjStDjGHwZ/U7iobcK1cQQD8sejsONdQtTVU+1wVN1PBw40PiiHB1vA5S7VTfQiP9g==", "dev": true }, "@mongodb-js/saslprep": { "version": "1.4.6", "resolved": "https://registry.npmjs.org/@mongodb-js/saslprep/-/saslprep-1.4.6.tgz", "integrity": "sha512-y+x3H1xBZd38n10NZF/rEBlvDOOMQ6LKUTHqr8R9VkJ+mmQOYtJFxIlkkK8fZrtOiL6VixbOBWMbZGBdal3Z1g==", "optional": true, "requires": { "sparse-bitfield": "^3.0.3" } }, "@parcel/watcher": { "version": "2.5.6", "resolved": "https://registry.npmjs.org/@parcel/watcher/-/watcher-2.5.6.tgz", "integrity": "sha512-tmmZ3lQxAe/k/+rNnXQRawJ4NjxO2hqiOLTHvWchtGZULp4RyFeh6aU4XdOYBFe2KE1oShQTv4AblOs2iOrNnQ==", "dev": true, "requires": { "@parcel/watcher-android-arm64": "2.5.6", "@parcel/watcher-darwin-arm64": "2.5.6", "@parcel/watcher-darwin-x64": "2.5.6", "@parcel/watcher-freebsd-x64": "2.5.6", "@parcel/watcher-linux-arm-glibc": "2.5.6", "@parcel/watcher-linux-arm-musl": "2.5.6", "@parcel/watcher-linux-arm64-glibc": "2.5.6", "@parcel/watcher-linux-arm64-musl": "2.5.6", "@parcel/watcher-linux-x64-glibc": "2.5.6", "@parcel/watcher-linux-x64-musl": "2.5.6", "@parcel/watcher-win32-arm64": "2.5.6", "@parcel/watcher-win32-ia32": "2.5.6", "@parcel/watcher-win32-x64": "2.5.6", "detect-libc": "^2.0.3", "is-glob": "^4.0.3", "node-addon-api": "^7.0.0", "picomatch": "^4.0.3" }, "dependencies": { "picomatch": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.3.tgz", "integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==", "dev": true } } }, "@parcel/watcher-android-arm64": { "version": "2.5.6", "resolved": "https://registry.npmjs.org/@parcel/watcher-android-arm64/-/watcher-android-arm64-2.5.6.tgz", "integrity": "sha512-YQxSS34tPF/6ZG7r/Ih9xy+kP/WwediEUsqmtf0cuCV5TPPKw/PQHRhueUo6JdeFJaqV3pyjm0GdYjZotbRt/A==", "dev": true, "optional": true }, "@parcel/watcher-darwin-arm64": { "version": "2.5.6", "resolved": "https://registry.npmjs.org/@parcel/watcher-darwin-arm64/-/watcher-darwin-arm64-2.5.6.tgz", "integrity": "sha512-Z2ZdrnwyXvvvdtRHLmM4knydIdU9adO3D4n/0cVipF3rRiwP+3/sfzpAwA/qKFL6i1ModaabkU7IbpeMBgiVEA==", "dev": true, "optional": true }, "@parcel/watcher-darwin-x64": { "version": "2.5.6", "resolved": "https://registry.npmjs.org/@parcel/watcher-darwin-x64/-/watcher-darwin-x64-2.5.6.tgz", "integrity": "sha512-HgvOf3W9dhithcwOWX9uDZyn1lW9R+7tPZ4sug+NGrGIo4Rk1hAXLEbcH1TQSqxts0NYXXlOWqVpvS1SFS4fRg==", "dev": true, "optional": true }, "@parcel/watcher-freebsd-x64": { "version": "2.5.6", "resolved": "https://registry.npmjs.org/@parcel/watcher-freebsd-x64/-/watcher-freebsd-x64-2.5.6.tgz", "integrity": "sha512-vJVi8yd/qzJxEKHkeemh7w3YAn6RJCtYlE4HPMoVnCpIXEzSrxErBW5SJBgKLbXU3WdIpkjBTeUNtyBVn8TRng==", "dev": true, "optional": true }, "@parcel/watcher-linux-arm-glibc": { "version": "2.5.6", "resolved": "https://registry.npmjs.org/@parcel/watcher-linux-arm-glibc/-/watcher-linux-arm-glibc-2.5.6.tgz", "integrity": "sha512-9JiYfB6h6BgV50CCfasfLf/uvOcJskMSwcdH1PHH9rvS1IrNy8zad6IUVPVUfmXr+u+Km9IxcfMLzgdOudz9EQ==", "dev": true, "optional": true }, "@parcel/watcher-linux-arm-musl": { "version": "2.5.6", "resolved": "https://registry.npmjs.org/@parcel/watcher-linux-arm-musl/-/watcher-linux-arm-musl-2.5.6.tgz", "integrity": "sha512-Ve3gUCG57nuUUSyjBq/MAM0CzArtuIOxsBdQ+ftz6ho8n7s1i9E1Nmk/xmP323r2YL0SONs1EuwqBp2u1k5fxg==", "dev": true, "optional": true }, "@parcel/watcher-linux-arm64-glibc": { "version": "2.5.6", "resolved": "https://registry.npmjs.org/@parcel/watcher-linux-arm64-glibc/-/watcher-linux-arm64-glibc-2.5.6.tgz", "integrity": "sha512-f2g/DT3NhGPdBmMWYoxixqYr3v/UXcmLOYy16Bx0TM20Tchduwr4EaCbmxh1321TABqPGDpS8D/ggOTaljijOA==", "dev": true, "optional": true }, "@parcel/watcher-linux-arm64-musl": { "version": "2.5.6", "resolved": "https://registry.npmjs.org/@parcel/watcher-linux-arm64-musl/-/watcher-linux-arm64-musl-2.5.6.tgz", "integrity": "sha512-qb6naMDGlbCwdhLj6hgoVKJl2odL34z2sqkC7Z6kzir8b5W65WYDpLB6R06KabvZdgoHI/zxke4b3zR0wAbDTA==", "dev": true, "optional": true }, "@parcel/watcher-linux-x64-glibc": { "version": "2.5.6", "resolved": "https://registry.npmjs.org/@parcel/watcher-linux-x64-glibc/-/watcher-linux-x64-glibc-2.5.6.tgz", "integrity": "sha512-kbT5wvNQlx7NaGjzPFu8nVIW1rWqV780O7ZtkjuWaPUgpv2NMFpjYERVi0UYj1msZNyCzGlaCWEtzc+exjMGbQ==", "dev": true, "optional": true }, "@parcel/watcher-linux-x64-musl": { "version": "2.5.6", "resolved": "https://registry.npmjs.org/@parcel/watcher-linux-x64-musl/-/watcher-linux-x64-musl-2.5.6.tgz", "integrity": "sha512-1JRFeC+h7RdXwldHzTsmdtYR/Ku8SylLgTU/reMuqdVD7CtLwf0VR1FqeprZ0eHQkO0vqsbvFLXUmYm/uNKJBg==", "dev": true, "optional": true }, "@parcel/watcher-win32-arm64": { "version": "2.5.6", "resolved": "https://registry.npmjs.org/@parcel/watcher-win32-arm64/-/watcher-win32-arm64-2.5.6.tgz", "integrity": "sha512-3ukyebjc6eGlw9yRt678DxVF7rjXatWiHvTXqphZLvo7aC5NdEgFufVwjFfY51ijYEWpXbqF5jtrK275z52D4Q==", "dev": true, "optional": true }, "@parcel/watcher-win32-ia32": { "version": "2.5.6", "resolved": "https://registry.npmjs.org/@parcel/watcher-win32-ia32/-/watcher-win32-ia32-2.5.6.tgz", "integrity": "sha512-k35yLp1ZMwwee3Ez/pxBi5cf4AoBKYXj00CZ80jUz5h8prpiaQsiRPKQMxoLstNuqe2vR4RNPEAEcjEFzhEz/g==", "dev": true, "optional": true }, "@parcel/watcher-win32-x64": { "version": "2.5.6", "resolved": "https://registry.npmjs.org/@parcel/watcher-win32-x64/-/watcher-win32-x64-2.5.6.tgz", "integrity": "sha512-hbQlYcCq5dlAX9Qx+kFb0FHue6vbjlf0FrNzSKdYK2APUf7tGfGxQCk2ihEREmbR6ZMc0MVAD5RIX/41gpUzTw==", "dev": true, "optional": true }, "@smithy/abort-controller": { "version": "4.2.12", "resolved": "https://registry.npmjs.org/@smithy/abort-controller/-/abort-controller-4.2.12.tgz", "integrity": "sha512-xolrFw6b+2iYGl6EcOL7IJY71vvyZ0DJ3mcKtpykqPe2uscwtzDZJa1uVQXyP7w9Dd+kGwYnPbMsJrGISKiY/Q==", "optional": true, "requires": { "@smithy/types": "^4.13.1", "tslib": "^2.6.2" } }, "@smithy/config-resolver": { "version": "4.4.11", "resolved": "https://registry.npmjs.org/@smithy/config-resolver/-/config-resolver-4.4.11.tgz", "integrity": "sha512-YxFiiG4YDAtX7WMN7RuhHZLeTmRRAOyCbr+zB8e3AQzHPnUhS8zXjB1+cniPVQI3xbWsQPM0X2aaIkO/ME0ymw==", "optional": true, "requires": { "@smithy/node-config-provider": "^4.3.12", "@smithy/types": "^4.13.1", "@smithy/util-config-provider": "^4.2.2", "@smithy/util-endpoints": "^3.3.3", "@smithy/util-middleware": "^4.2.12", "tslib": "^2.6.2" } }, "@smithy/core": { "version": "3.23.11", "resolved": "https://registry.npmjs.org/@smithy/core/-/core-3.23.11.tgz", "integrity": "sha512-952rGf7hBRnhUIaeLp6q4MptKW8sPFe5VvkoZ5qIzFAtx6c/QZ/54FS3yootsyUSf9gJX/NBqEBNdNR7jMIlpQ==", "optional": true, "requires": { "@smithy/protocol-http": "^5.3.12", "@smithy/types": "^4.13.1", "@smithy/url-parser": "^4.2.12", "@smithy/util-base64": "^4.3.2", "@smithy/util-body-length-browser": "^4.2.2", "@smithy/util-middleware": "^4.2.12", "@smithy/util-stream": "^4.5.19", "@smithy/util-utf8": "^4.2.2", "@smithy/uuid": "^1.1.2", "tslib": "^2.6.2" } }, "@smithy/credential-provider-imds": { "version": "4.2.12", "resolved": "https://registry.npmjs.org/@smithy/credential-provider-imds/-/credential-provider-imds-4.2.12.tgz", "integrity": "sha512-cr2lR792vNZcYMriSIj+Um3x9KWrjcu98kn234xA6reOAFMmbRpQMOv8KPgEmLLtx3eldU6c5wALKFqNOhugmg==", "optional": true, "requires": { "@smithy/node-config-provider": "^4.3.12", "@smithy/property-provider": "^4.2.12", "@smithy/types": "^4.13.1", "@smithy/url-parser": "^4.2.12", "tslib": "^2.6.2" } }, "@smithy/fetch-http-handler": { "version": "5.3.15", "resolved": "https://registry.npmjs.org/@smithy/fetch-http-handler/-/fetch-http-handler-5.3.15.tgz", "integrity": "sha512-T4jFU5N/yiIfrtrsb9uOQn7RdELdM/7HbyLNr6uO/mpkj1ctiVs7CihVr51w4LyQlXWDpXFn4BElf1WmQvZu/A==", "optional": true, "requires": { "@smithy/protocol-http": "^5.3.12", "@smithy/querystring-builder": "^4.2.12", "@smithy/types": "^4.13.1", "@smithy/util-base64": "^4.3.2", "tslib": "^2.6.2" } }, "@smithy/hash-node": { "version": "4.2.12", "resolved": "https://registry.npmjs.org/@smithy/hash-node/-/hash-node-4.2.12.tgz", "integrity": "sha512-QhBYbGrbxTkZ43QoTPrK72DoYviDeg6YKDrHTMJbbC+A0sml3kSjzFtXP7BtbyJnXojLfTQldGdUR0RGD8dA3w==", "optional": true, "requires": { "@smithy/types": "^4.13.1", "@smithy/util-buffer-from": "^4.2.2", "@smithy/util-utf8": "^4.2.2", "tslib": "^2.6.2" } }, "@smithy/invalid-dependency": { "version": "4.2.12", "resolved": "https://registry.npmjs.org/@smithy/invalid-dependency/-/invalid-dependency-4.2.12.tgz", "integrity": "sha512-/4F1zb7Z8LOu1PalTdESFHR0RbPwHd3FcaG1sI3UEIriQTWakysgJr65lc1jj6QY5ye7aFsisajotH6UhWfm/g==", "optional": true, "requires": { "@smithy/types": "^4.13.1", "tslib": "^2.6.2" } }, "@smithy/is-array-buffer": { "version": "4.2.2", "resolved": "https://registry.npmjs.org/@smithy/is-array-buffer/-/is-array-buffer-4.2.2.tgz", "integrity": "sha512-n6rQ4N8Jj4YTQO3YFrlgZuwKodf4zUFs7EJIWH86pSCWBaAtAGBFfCM7Wx6D2bBJ2xqFNxGBSrUWswT3M0VJow==", "optional": true, "requires": { "tslib": "^2.6.2" } }, "@smithy/middleware-content-length": { "version": "4.2.12", "resolved": "https://registry.npmjs.org/@smithy/middleware-content-length/-/middleware-content-length-4.2.12.tgz", "integrity": "sha512-YE58Yz+cvFInWI/wOTrB+DbvUVz/pLn5mC5MvOV4fdRUc6qGwygyngcucRQjAhiCEbmfLOXX0gntSIcgMvAjmA==", "optional": true, "requires": { "@smithy/protocol-http": "^5.3.12", "@smithy/types": "^4.13.1", "tslib": "^2.6.2" } }, "@smithy/middleware-endpoint": { "version": "4.4.25", "resolved": "https://registry.npmjs.org/@smithy/middleware-endpoint/-/middleware-endpoint-4.4.25.tgz", "integrity": "sha512-dqjLwZs2eBxIUG6Qtw8/YZ4DvzHGIf0DA18wrgtfP6a50UIO7e2nY0FPdcbv5tVJKqWCCU5BmGMOUwT7Puan+A==", "optional": true, "requires": { "@smithy/core": "^3.23.11", "@smithy/middleware-serde": "^4.2.14", "@smithy/node-config-provider": "^4.3.12", "@smithy/shared-ini-file-loader": "^4.4.7", "@smithy/types": "^4.13.1", "@smithy/url-parser": "^4.2.12", "@smithy/util-middleware": "^4.2.12", "tslib": "^2.6.2" } }, "@smithy/middleware-retry": { "version": "4.4.42", "resolved": "https://registry.npmjs.org/@smithy/middleware-retry/-/middleware-retry-4.4.42.tgz", "integrity": "sha512-vbwyqHRIpIZutNXZpLAozakzamcINaRCpEy1MYmK6xBeW3xN+TyPRA123GjXnuxZIjc9848MRRCugVMTXxC4Eg==", "optional": true, "requires": { "@smithy/node-config-provider": "^4.3.12", "@smithy/protocol-http": "^5.3.12", "@smithy/service-error-classification": "^4.2.12", "@smithy/smithy-client": "^4.12.5", "@smithy/types": "^4.13.1", "@smithy/util-middleware": "^4.2.12", "@smithy/util-retry": "^4.2.12", "@smithy/uuid": "^1.1.2", "tslib": "^2.6.2" } }, "@smithy/middleware-serde": { "version": "4.2.14", "resolved": "https://registry.npmjs.org/@smithy/middleware-serde/-/middleware-serde-4.2.14.tgz", "integrity": "sha512-+CcaLoLa5apzSRtloOyG7lQvkUw2ZDml3hRh4QiG9WyEPfW5Ke/3tPOPiPjUneuT59Tpn8+c3RVaUvvkkwqZwg==", "optional": true, "requires": { "@smithy/core": "^3.23.11", "@smithy/protocol-http": "^5.3.12", "@smithy/types": "^4.13.1", "tslib": "^2.6.2" } }, "@smithy/middleware-stack": { "version": "4.2.12", "resolved": "https://registry.npmjs.org/@smithy/middleware-stack/-/middleware-stack-4.2.12.tgz", "integrity": "sha512-kruC5gRHwsCOuyCd4ouQxYjgRAym2uDlCvQ5acuMtRrcdfg7mFBg6blaxcJ09STpt3ziEkis6bhg1uwrWU7txw==", "optional": true, "requires": { "@smithy/types": "^4.13.1", "tslib": "^2.6.2" } }, "@smithy/node-config-provider": { "version": "4.3.12", "resolved": "https://registry.npmjs.org/@smithy/node-config-provider/-/node-config-provider-4.3.12.tgz", "integrity": "sha512-tr2oKX2xMcO+rBOjobSwVAkV05SIfUKz8iI53rzxEmgW3GOOPOv0UioSDk+J8OpRQnpnhsO3Af6IEBabQBVmiw==", "optional": true, "requires": { "@smithy/property-provider": "^4.2.12", "@smithy/shared-ini-file-loader": "^4.4.7", "@smithy/types": "^4.13.1", "tslib": "^2.6.2" } }, "@smithy/node-http-handler": { "version": "4.4.16", "resolved": "https://registry.npmjs.org/@smithy/node-http-handler/-/node-http-handler-4.4.16.tgz", "integrity": "sha512-ULC8UCS/HivdCB3jhi+kLFYe4B5gxH2gi9vHBfEIiRrT2jfKiZNiETJSlzRtE6B26XbBHjPtc8iZKSNqMol9bw==", "optional": true, "requires": { "@smithy/abort-controller": "^4.2.12", "@smithy/protocol-http": "^5.3.12", "@smithy/querystring-builder": "^4.2.12", "@smithy/types": "^4.13.1", "tslib": "^2.6.2" } }, "@smithy/property-provider": { "version": "4.2.12", "resolved": "https://registry.npmjs.org/@smithy/property-provider/-/property-provider-4.2.12.tgz", "integrity": "sha512-jqve46eYU1v7pZ5BM+fmkbq3DerkSluPr5EhvOcHxygxzD05ByDRppRwRPPpFrsFo5yDtCYLKu+kreHKVrvc7A==", "optional": true, "requires": { "@smithy/types": "^4.13.1", "tslib": "^2.6.2" } }, "@smithy/protocol-http": { "version": "5.3.12", "resolved": "https://registry.npmjs.org/@smithy/protocol-http/-/protocol-http-5.3.12.tgz", "integrity": "sha512-fit0GZK9I1xoRlR4jXmbLhoN0OdEpa96ul8M65XdmXnxXkuMxM0Y8HDT0Fh0Xb4I85MBvBClOzgSrV1X2s1Hxw==", "optional": true, "requires": { "@smithy/types": "^4.13.1", "tslib": "^2.6.2" } }, "@smithy/querystring-builder": { "version": "4.2.12", "resolved": "https://registry.npmjs.org/@smithy/querystring-builder/-/querystring-builder-4.2.12.tgz", "integrity": "sha512-6wTZjGABQufekycfDGMEB84BgtdOE/rCVTov+EDXQ8NHKTUNIp/j27IliwP7tjIU9LR+sSzyGBOXjeEtVgzCHg==", "optional": true, "requires": { "@smithy/types": "^4.13.1", "@smithy/util-uri-escape": "^4.2.2", "tslib": "^2.6.2" } }, "@smithy/querystring-parser": { "version": "4.2.12", "resolved": "https://registry.npmjs.org/@smithy/querystring-parser/-/querystring-parser-4.2.12.tgz", "integrity": "sha512-P2OdvrgiAKpkPNKlKUtWbNZKB1XjPxM086NeVhK+W+wI46pIKdWBe5QyXvhUm3MEcyS/rkLvY8rZzyUdmyDZBw==", "optional": true, "requires": { "@smithy/types": "^4.13.1", "tslib": "^2.6.2" } }, "@smithy/service-error-classification": { "version": "4.2.12", "resolved": "https://registry.npmjs.org/@smithy/service-error-classification/-/service-error-classification-4.2.12.tgz", "integrity": "sha512-LlP29oSQN0Tw0b6D0Xo6BIikBswuIiGYbRACy5ujw/JgWSzTdYj46U83ssf6Ux0GyNJVivs2uReU8pt7Eu9okQ==", "optional": true, "requires": { "@smithy/types": "^4.13.1" } }, "@smithy/shared-ini-file-loader": { "version": "4.4.7", "resolved": "https://registry.npmjs.org/@smithy/shared-ini-file-loader/-/shared-ini-file-loader-4.4.7.tgz", "integrity": "sha512-HrOKWsUb+otTeo1HxVWeEb99t5ER1XrBi/xka2Wv6NVmTbuCUC1dvlrksdvxFtODLBjsC+PHK+fuy2x/7Ynyiw==", "optional": true, "requires": { "@smithy/types": "^4.13.1", "tslib": "^2.6.2" } }, "@smithy/signature-v4": { "version": "5.3.12", "resolved": "https://registry.npmjs.org/@smithy/signature-v4/-/signature-v4-5.3.12.tgz", "integrity": "sha512-B/FBwO3MVOL00DaRSXfXfa/TRXRheagt/q5A2NM13u7q+sHS59EOVGQNfG7DkmVtdQm5m3vOosoKAXSqn/OEgw==", "optional": true, "requires": { "@smithy/is-array-buffer": "^4.2.2", "@smithy/protocol-http": "^5.3.12", "@smithy/types": "^4.13.1", "@smithy/util-hex-encoding": "^4.2.2", "@smithy/util-middleware": "^4.2.12", "@smithy/util-uri-escape": "^4.2.2", "@smithy/util-utf8": "^4.2.2", "tslib": "^2.6.2" } }, "@smithy/smithy-client": { "version": "4.12.5", "resolved": "https://registry.npmjs.org/@smithy/smithy-client/-/smithy-client-4.12.5.tgz", "integrity": "sha512-UqwYawyqSr/aog8mnLnfbPurS0gi4G7IYDcD28cUIBhsvWs1+rQcL2IwkUQ+QZ7dibaoRzhNF99fAQ9AUcO00w==", "optional": true, "requires": { "@smithy/core": "^3.23.11", "@smithy/middleware-endpoint": "^4.4.25", "@smithy/middleware-stack": "^4.2.12", "@smithy/protocol-http": "^5.3.12", "@smithy/types": "^4.13.1", "@smithy/util-stream": "^4.5.19", "tslib": "^2.6.2" } }, "@smithy/types": { "version": "4.13.1", "resolved": "https://registry.npmjs.org/@smithy/types/-/types-4.13.1.tgz", "integrity": "sha512-787F3yzE2UiJIQ+wYW1CVg2odHjmaWLGksnKQHUrK/lYZSEcy1msuLVvxaR/sI2/aDe9U+TBuLsXnr3vod1g0g==", "optional": true, "requires": { "tslib": "^2.6.2" } }, "@smithy/url-parser": { "version": "4.2.12", "resolved": "https://registry.npmjs.org/@smithy/url-parser/-/url-parser-4.2.12.tgz", "integrity": "sha512-wOPKPEpso+doCZGIlr+e1lVI6+9VAKfL4kZWFgzVgGWY2hZxshNKod4l2LXS3PRC9otH/JRSjtEHqQ/7eLciRA==", "optional": true, "requires": { "@smithy/querystring-parser": "^4.2.12", "@smithy/types": "^4.13.1", "tslib": "^2.6.2" } }, "@smithy/util-base64": { "version": "4.3.2", "resolved": "https://registry.npmjs.org/@smithy/util-base64/-/util-base64-4.3.2.tgz", "integrity": "sha512-XRH6b0H/5A3SgblmMa5ErXQ2XKhfbQB+Fm/oyLZ2O2kCUrwgg55bU0RekmzAhuwOjA9qdN5VU2BprOvGGUkOOQ==", "optional": true, "requires": { "@smithy/util-buffer-from": "^4.2.2", "@smithy/util-utf8": "^4.2.2", "tslib": "^2.6.2" } }, "@smithy/util-body-length-browser": { "version": "4.2.2", "resolved": "https://registry.npmjs.org/@smithy/util-body-length-browser/-/util-body-length-browser-4.2.2.tgz", "integrity": "sha512-JKCrLNOup3OOgmzeaKQwi4ZCTWlYR5H4Gm1r2uTMVBXoemo1UEghk5vtMi1xSu2ymgKVGW631e2fp9/R610ZjQ==", "optional": true, "requires": { "tslib": "^2.6.2" } }, "@smithy/util-body-length-node": { "version": "4.2.3", "resolved": "https://registry.npmjs.org/@smithy/util-body-length-node/-/util-body-length-node-4.2.3.tgz", "integrity": "sha512-ZkJGvqBzMHVHE7r/hcuCxlTY8pQr1kMtdsVPs7ex4mMU+EAbcXppfo5NmyxMYi2XU49eqaz56j2gsk4dHHPG/g==", "optional": true, "requires": { "tslib": "^2.6.2" } }, "@smithy/util-buffer-from": { "version": "4.2.2", "resolved": "https://registry.npmjs.org/@smithy/util-buffer-from/-/util-buffer-from-4.2.2.tgz", "integrity": "sha512-FDXD7cvUoFWwN6vtQfEta540Y/YBe5JneK3SoZg9bThSoOAC/eGeYEua6RkBgKjGa/sz6Y+DuBZj3+YEY21y4Q==", "optional": true, "requires": { "@smithy/is-array-buffer": "^4.2.2", "tslib": "^2.6.2" } }, "@smithy/util-config-provider": { "version": "4.2.2", "resolved": "https://registry.npmjs.org/@smithy/util-config-provider/-/util-config-provider-4.2.2.tgz", "integrity": "sha512-dWU03V3XUprJwaUIFVv4iOnS1FC9HnMHDfUrlNDSh4315v0cWyaIErP8KiqGVbf5z+JupoVpNM7ZB3jFiTejvQ==", "optional": true, "requires": { "tslib": "^2.6.2" } }, "@smithy/util-defaults-mode-browser": { "version": "4.3.41", "resolved": "https://registry.npmjs.org/@smithy/util-defaults-mode-browser/-/util-defaults-mode-browser-4.3.41.tgz", "integrity": "sha512-M1w1Ux0rSVvBOxIIiqbxvZvhnjQ+VUjJrugtORE90BbadSTH+jsQL279KRL3Hv0w69rE7EuYkV/4Lepz/NBW9g==", "optional": true, "requires": { "@smithy/property-provider": "^4.2.12", "@smithy/smithy-client": "^4.12.5", "@smithy/types": "^4.13.1", "tslib": "^2.6.2" } }, "@smithy/util-defaults-mode-node": { "version": "4.2.44", "resolved": "https://registry.npmjs.org/@smithy/util-defaults-mode-node/-/util-defaults-mode-node-4.2.44.tgz", "integrity": "sha512-YPze3/lD1KmWuZsl9JlfhcgGLX7AXhSoaCDtiPntUjNW5/YY0lOHjkcgxyE9x/h5vvS1fzDifMGjzqnNlNiqOQ==", "optional": true, "requires": { "@smithy/config-resolver": "^4.4.11", "@smithy/credential-provider-imds": "^4.2.12", "@smithy/node-config-provider": "^4.3.12", "@smithy/property-provider": "^4.2.12", "@smithy/smithy-client": "^4.12.5", "@smithy/types": "^4.13.1", "tslib": "^2.6.2" } }, "@smithy/util-endpoints": { "version": "3.3.3", "resolved": "https://registry.npmjs.org/@smithy/util-endpoints/-/util-endpoints-3.3.3.tgz", "integrity": "sha512-VACQVe50j0HZPjpwWcjyT51KUQ4AnsvEaQ2lKHOSL4mNLD0G9BjEniQ+yCt1qqfKfiAHRAts26ud7hBjamrwig==", "optional": true, "requires": { "@smithy/node-config-provider": "^4.3.12", "@smithy/types": "^4.13.1", "tslib": "^2.6.2" } }, "@smithy/util-hex-encoding": { "version": "4.2.2", "resolved": "https://registry.npmjs.org/@smithy/util-hex-encoding/-/util-hex-encoding-4.2.2.tgz", "integrity": "sha512-Qcz3W5vuHK4sLQdyT93k/rfrUwdJ8/HZ+nMUOyGdpeGA1Wxt65zYwi3oEl9kOM+RswvYq90fzkNDahPS8K0OIg==", "optional": true, "requires": { "tslib": "^2.6.2" } }, "@smithy/util-middleware": { "version": "4.2.12", "resolved": "https://registry.npmjs.org/@smithy/util-middleware/-/util-middleware-4.2.12.tgz", "integrity": "sha512-Er805uFUOvgc0l8nv0e0su0VFISoxhJ/AwOn3gL2NWNY2LUEldP5WtVcRYSQBcjg0y9NfG8JYrCJaYDpupBHJQ==", "optional": true, "requires": { "@smithy/types": "^4.13.1", "tslib": "^2.6.2" } }, "@smithy/util-retry": { "version": "4.2.12", "resolved": "https://registry.npmjs.org/@smithy/util-retry/-/util-retry-4.2.12.tgz", "integrity": "sha512-1zopLDUEOwumjcHdJ1mwBHddubYF8GMQvstVCLC54Y46rqoHwlIU+8ZzUeaBcD+WCJHyDGSeZ2ml9YSe9aqcoQ==", "optional": true, "requires": { "@smithy/service-error-classification": "^4.2.12", "@smithy/types": "^4.13.1", "tslib": "^2.6.2" } }, "@smithy/util-stream": { "version": "4.5.19", "resolved": "https://registry.npmjs.org/@smithy/util-stream/-/util-stream-4.5.19.tgz", "integrity": "sha512-v4sa+3xTweL1CLO2UP0p7tvIMH/Rq1X4KKOxd568mpe6LSLMQCnDHs4uv7m3ukpl3HvcN2JH6jiCS0SNRXKP/w==", "optional": true, "requires": { "@smithy/fetch-http-handler": "^5.3.15", "@smithy/node-http-handler": "^4.4.16", "@smithy/types": "^4.13.1", "@smithy/util-base64": "^4.3.2", "@smithy/util-buffer-from": "^4.2.2", "@smithy/util-hex-encoding": "^4.2.2", "@smithy/util-utf8": "^4.2.2", "tslib": "^2.6.2" } }, "@smithy/util-uri-escape": { "version": "4.2.2", "resolved": "https://registry.npmjs.org/@smithy/util-uri-escape/-/util-uri-escape-4.2.2.tgz", "integrity": "sha512-2kAStBlvq+lTXHyAZYfJRb/DfS3rsinLiwb+69SstC9Vb0s9vNWkRwpnj918Pfi85mzi42sOqdV72OLxWAISnw==", "optional": true, "requires": { "tslib": "^2.6.2" } }, "@smithy/util-utf8": { "version": "4.2.2", "resolved": "https://registry.npmjs.org/@smithy/util-utf8/-/util-utf8-4.2.2.tgz", "integrity": "sha512-75MeYpjdWRe8M5E3AW0O4Cx3UadweS+cwdXjwYGBW5h/gxxnbeZ877sLPX/ZJA9GVTlL/qG0dXP29JWFCD1Ayw==", "optional": true, "requires": { "@smithy/util-buffer-from": "^4.2.2", "tslib": "^2.6.2" } }, "@smithy/uuid": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/@smithy/uuid/-/uuid-1.1.2.tgz", "integrity": "sha512-O/IEdcCUKkubz60tFbGA7ceITTAJsty+lBjNoorP4Z6XRqaFb/OjQjZODophEcuq68nKm6/0r+6/lLQ+XVpk8g==", "optional": true, "requires": { "tslib": "^2.6.2" } }, "@tailwindcss/cli": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/@tailwindcss/cli/-/cli-4.2.1.tgz", "integrity": "sha512-b7MGn51IA80oSG+7fuAgzfQ+7pZBgjzbqwmiv6NO7/+a1sev32cGqnwhscT7h0EcAvMa9r7gjRylqOH8Xhc4DA==", "dev": true, "requires": { "@parcel/watcher": "^2.5.1", "@tailwindcss/node": "4.2.1", "@tailwindcss/oxide": "4.2.1", "enhanced-resolve": "^5.19.0", "mri": "^1.2.0", "picocolors": "^1.1.1", "tailwindcss": "4.2.1" } }, "@tailwindcss/forms": { "version": "0.5.11", "resolved": "https://registry.npmjs.org/@tailwindcss/forms/-/forms-0.5.11.tgz", "integrity": "sha512-h9wegbZDPurxG22xZSoWtdzc41/OlNEUQERNqI/0fOwa2aVlWGu7C35E/x6LDyD3lgtztFSSjKZyuVM0hxhbgA==", "dev": true, "requires": { "mini-svg-data-uri": "^1.2.3" } }, "@tailwindcss/node": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/@tailwindcss/node/-/node-4.2.1.tgz", "integrity": "sha512-jlx6sLk4EOwO6hHe1oCGm1Q4AN/s0rSrTTPBGPM0/RQ6Uylwq17FuU8IeJJKEjtc6K6O07zsvP+gDO6MMWo7pg==", "dev": true, "requires": { "@jridgewell/remapping": "^2.3.5", "enhanced-resolve": "^5.19.0", "jiti": "^2.6.1", "lightningcss": "1.31.1", "magic-string": "^0.30.21", "source-map-js": "^1.2.1", "tailwindcss": "4.2.1" } }, "@tailwindcss/oxide": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/@tailwindcss/oxide/-/oxide-4.2.1.tgz", "integrity": "sha512-yv9jeEFWnjKCI6/T3Oq50yQEOqmpmpfzG1hcZsAOaXFQPfzWprWrlHSdGPEF3WQTi8zu8ohC9Mh9J470nT5pUw==", "dev": true, "requires": { "@tailwindcss/oxide-android-arm64": "4.2.1", "@tailwindcss/oxide-darwin-arm64": "4.2.1", "@tailwindcss/oxide-darwin-x64": "4.2.1", "@tailwindcss/oxide-freebsd-x64": "4.2.1", "@tailwindcss/oxide-linux-arm-gnueabihf": "4.2.1", "@tailwindcss/oxide-linux-arm64-gnu": "4.2.1", "@tailwindcss/oxide-linux-arm64-musl": "4.2.1", "@tailwindcss/oxide-linux-x64-gnu": "4.2.1", "@tailwindcss/oxide-linux-x64-musl": "4.2.1", "@tailwindcss/oxide-wasm32-wasi": "4.2.1", "@tailwindcss/oxide-win32-arm64-msvc": "4.2.1", "@tailwindcss/oxide-win32-x64-msvc": "4.2.1" } }, "@tailwindcss/oxide-android-arm64": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-android-arm64/-/oxide-android-arm64-4.2.1.tgz", "integrity": "sha512-eZ7G1Zm5EC8OOKaesIKuw77jw++QJ2lL9N+dDpdQiAB/c/B2wDh0QPFHbkBVrXnwNugvrbJFk1gK2SsVjwWReg==", "dev": true, "optional": true }, "@tailwindcss/oxide-darwin-arm64": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-darwin-arm64/-/oxide-darwin-arm64-4.2.1.tgz", "integrity": "sha512-q/LHkOstoJ7pI1J0q6djesLzRvQSIfEto148ppAd+BVQK0JYjQIFSK3JgYZJa+Yzi0DDa52ZsQx2rqytBnf8Hw==", "dev": true, "optional": true }, "@tailwindcss/oxide-darwin-x64": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-darwin-x64/-/oxide-darwin-x64-4.2.1.tgz", "integrity": "sha512-/f/ozlaXGY6QLbpvd/kFTro2l18f7dHKpB+ieXz+Cijl4Mt9AI2rTrpq7V+t04nK+j9XBQHnSMdeQRhbGyt6fw==", "dev": true, "optional": true }, "@tailwindcss/oxide-freebsd-x64": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-freebsd-x64/-/oxide-freebsd-x64-4.2.1.tgz", "integrity": "sha512-5e/AkgYJT/cpbkys/OU2Ei2jdETCLlifwm7ogMC7/hksI2fC3iiq6OcXwjibcIjPung0kRtR3TxEITkqgn0TcA==", "dev": true, "optional": true }, "@tailwindcss/oxide-linux-arm-gnueabihf": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-linux-arm-gnueabihf/-/oxide-linux-arm-gnueabihf-4.2.1.tgz", "integrity": "sha512-Uny1EcVTTmerCKt/1ZuKTkb0x8ZaiuYucg2/kImO5A5Y/kBz41/+j0gxUZl+hTF3xkWpDmHX+TaWhOtba2Fyuw==", "dev": true, "optional": true }, "@tailwindcss/oxide-linux-arm64-gnu": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-linux-arm64-gnu/-/oxide-linux-arm64-gnu-4.2.1.tgz", "integrity": "sha512-CTrwomI+c7n6aSSQlsPL0roRiNMDQ/YzMD9EjcR+H4f0I1SQ8QqIuPnsVp7QgMkC1Qi8rtkekLkOFjo7OlEFRQ==", "dev": true, "optional": true }, "@tailwindcss/oxide-linux-arm64-musl": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-linux-arm64-musl/-/oxide-linux-arm64-musl-4.2.1.tgz", "integrity": "sha512-WZA0CHRL/SP1TRbA5mp9htsppSEkWuQ4KsSUumYQnyl8ZdT39ntwqmz4IUHGN6p4XdSlYfJwM4rRzZLShHsGAQ==", "dev": true, "optional": true }, "@tailwindcss/oxide-linux-x64-gnu": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-linux-x64-gnu/-/oxide-linux-x64-gnu-4.2.1.tgz", "integrity": "sha512-qMFzxI2YlBOLW5PhblzuSWlWfwLHaneBE0xHzLrBgNtqN6mWfs+qYbhryGSXQjFYB1Dzf5w+LN5qbUTPhW7Y5g==", "dev": true, "optional": true }, "@tailwindcss/oxide-linux-x64-musl": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-linux-x64-musl/-/oxide-linux-x64-musl-4.2.1.tgz", "integrity": "sha512-5r1X2FKnCMUPlXTWRYpHdPYUY6a1Ar/t7P24OuiEdEOmms5lyqjDRvVY1yy9Rmioh+AunQ0rWiOTPE8F9A3v5g==", "dev": true, "optional": true }, "@tailwindcss/oxide-wasm32-wasi": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-wasm32-wasi/-/oxide-wasm32-wasi-4.2.1.tgz", "integrity": "sha512-MGFB5cVPvshR85MTJkEvqDUnuNoysrsRxd6vnk1Lf2tbiqNlXpHYZqkqOQalydienEWOHHFyyuTSYRsLfxFJ2Q==", "dev": true, "optional": true, "requires": { "@emnapi/core": "^1.8.1", "@emnapi/runtime": "^1.8.1", "@emnapi/wasi-threads": "^1.1.0", "@napi-rs/wasm-runtime": "^1.1.1", "@tybys/wasm-util": "^0.10.1", "tslib": "^2.8.1" } }, "@tailwindcss/oxide-win32-arm64-msvc": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-win32-arm64-msvc/-/oxide-win32-arm64-msvc-4.2.1.tgz", "integrity": "sha512-YlUEHRHBGnCMh4Nj4GnqQyBtsshUPdiNroZj8VPkvTZSoHsilRCwXcVKnG9kyi0ZFAS/3u+qKHBdDc81SADTRA==", "dev": true, "optional": true }, "@tailwindcss/oxide-win32-x64-msvc": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/@tailwindcss/oxide-win32-x64-msvc/-/oxide-win32-x64-msvc-4.2.1.tgz", "integrity": "sha512-rbO34G5sMWWyrN/idLeVxAZgAKWrn5LiR3/I90Q9MkA67s6T1oB0xtTe+0heoBvHSpbU9Mk7i6uwJnpo4u21XQ==", "dev": true, "optional": true }, "@types/accepts": { "version": "1.3.7", "resolved": "https://registry.npmjs.org/@types/accepts/-/accepts-1.3.7.tgz", "integrity": "sha512-Pay9fq2lM2wXPWbteBsRAGiWH2hig4ZE2asK+mm7kUzlxRTfL961rj89I6zV/E3PcIkDqyuBEcMxFT7rccugeQ==", "dev": true, "requires": { "@types/node": "*" } }, "@types/body-parser": { "version": "1.19.6", "resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.6.tgz", "integrity": "sha512-HLFeCYgz89uk22N5Qg3dvGvsv46B8GLvKKo1zKG4NybA8U2DiEO3w9lqGg29t/tfLRJpJ6iQxnVw4OnB7MoM9g==", "dev": true, "requires": { "@types/connect": "*", "@types/node": "*" } }, "@types/connect": { "version": "3.4.38", "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.38.tgz", "integrity": "sha512-K6uROf1LD88uDQqJCktA4yzL1YYAK6NgfsI0v/mTgyPKWsX1CnJ0XPSDhViejru1GcRkLWb8RlzFYJRqGUbaug==", "dev": true, "requires": { "@types/node": "*" } }, "@types/content-disposition": { "version": "0.5.9", "resolved": "https://registry.npmjs.org/@types/content-disposition/-/content-disposition-0.5.9.tgz", "integrity": "sha512-8uYXI3Gw35MhiVYhG3s295oihrxRyytcRHjSjqnqZVDDy/xcGBRny7+Xj1Wgfhv5QzRtN2hB2dVRBUX9XW3UcQ==", "dev": true }, "@types/cookies": { "version": "0.9.2", "resolved": "https://registry.npmjs.org/@types/cookies/-/cookies-0.9.2.tgz", "integrity": "sha512-1AvkDdZM2dbyFybL4fxpuNCaWyv//0AwsuUk2DWeXyM1/5ZKm6W3z6mQi24RZ4l2ucY+bkSHzbDVpySqPGuV8A==", "dev": true, "requires": { "@types/connect": "*", "@types/express": "*", "@types/keygrip": "*", "@types/node": "*" } }, "@types/esrecurse": { "version": "4.3.1", "resolved": "https://registry.npmjs.org/@types/esrecurse/-/esrecurse-4.3.1.tgz", "integrity": "sha512-xJBAbDifo5hpffDBuHl0Y8ywswbiAp/Wi7Y/GtAgSlZyIABppyurxVueOPE8LUQOxdlgi6Zqce7uoEpqNTeiUw==", "dev": true }, "@types/estree": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.8.tgz", "integrity": "sha512-dWHzHa2WqEXI/O1E9OjrocMTKJl2mSrEolh1Iomrv6U+JuNwaHXsXx9bLu5gG7BUWFIN0skIQJQ/L1rIex4X6w==", "dev": true }, "@types/express": { "version": "5.0.6", "resolved": "https://registry.npmjs.org/@types/express/-/express-5.0.6.tgz", "integrity": "sha512-sKYVuV7Sv9fbPIt/442koC7+IIwK5olP1KWeD88e/idgoJqDm3JV/YUiPwkoKK92ylff2MGxSz1CSjsXelx0YA==", "dev": true, "requires": { "@types/body-parser": "*", "@types/express-serve-static-core": "^5.0.0", "@types/serve-static": "^2" } }, "@types/express-serve-static-core": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-5.1.1.tgz", "integrity": "sha512-v4zIMr/cX7/d2BpAEX3KNKL/JrT1s43s96lLvvdTmza1oEvDudCqK9aF/djc/SWgy8Yh0h30TZx5VpzqFCxk5A==", "dev": true, "requires": { "@types/node": "*", "@types/qs": "*", "@types/range-parser": "*", "@types/send": "*" } }, "@types/http-assert": { "version": "1.5.6", "resolved": "https://registry.npmjs.org/@types/http-assert/-/http-assert-1.5.6.tgz", "integrity": "sha512-TTEwmtjgVbYAzZYWyeHPrrtWnfVkm8tQkP8P21uQifPgMRgjrow3XDEYqucuC8SKZJT7pUnhU/JymvjggxO9vw==", "dev": true }, "@types/http-errors": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/@types/http-errors/-/http-errors-2.0.5.tgz", "integrity": "sha512-r8Tayk8HJnX0FztbZN7oVqGccWgw98T/0neJphO91KkmOzug1KkofZURD4UaD5uH8AqcFLfdPErnBod0u71/qg==", "dev": true }, "@types/json-schema": { "version": "7.0.15", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz", "integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==", "dev": true }, "@types/jsonwebtoken": { "version": "9.0.10", "resolved": "https://registry.npmjs.org/@types/jsonwebtoken/-/jsonwebtoken-9.0.10.tgz", "integrity": "sha512-asx5hIG9Qmf/1oStypjanR7iKTv0gXQ1Ov/jfrX6kS/EO0OFni8orbmGCn0672NHR3kXHwpAwR+B368ZGN/2rA==", "dev": true, "requires": { "@types/ms": "*", "@types/node": "*" } }, "@types/keygrip": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/@types/keygrip/-/keygrip-1.0.6.tgz", "integrity": "sha512-lZuNAY9xeJt7Bx4t4dx0rYCDqGPW8RXhQZK1td7d4H6E9zYbLoOtjBvfwdTKpsyxQI/2jv+armjX/RW+ZNpXOQ==", "dev": true }, "@types/koa": { "version": "2.15.0", "resolved": "https://registry.npmjs.org/@types/koa/-/koa-2.15.0.tgz", "integrity": "sha512-7QFsywoE5URbuVnG3loe03QXuGajrnotr3gQkXcEBShORai23MePfFYdhz90FEtBBpkyIYQbVD+evKtloCgX3g==", "dev": true, "requires": { "@types/accepts": "*", "@types/content-disposition": "*", "@types/cookies": "*", "@types/http-assert": "*", "@types/http-errors": "*", "@types/keygrip": "*", "@types/koa-compose": "*", "@types/node": "*" } }, "@types/koa-compose": { "version": "3.2.9", "resolved": "https://registry.npmjs.org/@types/koa-compose/-/koa-compose-3.2.9.tgz", "integrity": "sha512-BroAZ9FTvPiCy0Pi8tjD1OfJ7bgU1gQf0eR6e1Vm+JJATy9eKOG3hQMFtMciMawiSOVnLMdmUOC46s7HBhSTsA==", "dev": true, "requires": { "@types/koa": "*" } }, "@types/koa-compress": { "version": "4.0.7", "resolved": "https://registry.npmjs.org/@types/koa-compress/-/koa-compress-4.0.7.tgz", "integrity": "sha512-NqP9qCBfXCu2+RYkGzEENBkqXWExOPeBEsvj3F0xtVxKDwwdfRRtVdpxJeTRAq2Ml3qlUnDbK8bKHWwe6V1kkg==", "dev": true, "requires": { "@types/koa": "*", "@types/node": "*" } }, "@types/mithril": { "version": "2.2.7", "resolved": "https://registry.npmjs.org/@types/mithril/-/mithril-2.2.7.tgz", "integrity": "sha512-uetxoYizBMHPELl6DSZUfO6Q/aOm+h0NUCv9bVAX2iAxfrdBSOvU9KKFl+McTtxR13F+BReYLY814pJsZvnSxg==", "dev": true }, "@types/ms": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/@types/ms/-/ms-2.1.0.tgz", "integrity": "sha512-GsCCIZDE/p3i96vtEqx+7dBUGXrc7zeSK3wwPHIaRThS+9OhWIXRqzs4d6k1SVU8g91DrNRWxWUGhp5KXQb2VA==", "dev": true }, "@types/node": { "version": "25.5.0", "resolved": "https://registry.npmjs.org/@types/node/-/node-25.5.0.tgz", "integrity": "sha512-jp2P3tQMSxWugkCUKLRPVUpGaL5MVFwF8RDuSRztfwgN1wmqJeMSbKlnEtQqU8UrhTmzEmZdu2I6v2dpp7XIxw==", "requires": { "undici-types": "~7.18.0" } }, "@types/qs": { "version": "6.15.0", "resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.15.0.tgz", "integrity": "sha512-JawvT8iBVWpzTrz3EGw9BTQFg3BQNmwERdKE22vlTxawwtbyUSlMppvZYKLZzB5zgACXdXxbD3m1bXaMqP/9ow==", "dev": true }, "@types/range-parser": { "version": "1.2.7", "resolved": "https://registry.npmjs.org/@types/range-parser/-/range-parser-1.2.7.tgz", "integrity": "sha512-hKormJbkJqzQGhziax5PItDUTMAM9uE2XXQmM37dyd4hVM+5aVl7oVxMVUiVQn2oCQFN/LKCZdvSM0pFRqbSmQ==", "dev": true }, "@types/seedrandom": { "version": "3.0.8", "resolved": "https://registry.npmjs.org/@types/seedrandom/-/seedrandom-3.0.8.tgz", "integrity": "sha512-TY1eezMU2zH2ozQoAFAQFOPpvP15g+ZgSfTZt31AUUH/Rxtnz3H+A/Sv1Snw2/amp//omibc+AEkTaA8KUeOLQ==", "dev": true }, "@types/send": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/@types/send/-/send-1.2.1.tgz", "integrity": "sha512-arsCikDvlU99zl1g69TcAB3mzZPpxgw0UQnaHeC1Nwb015xp8bknZv5rIfri9xTOcMuaVgvabfIRA7PSZVuZIQ==", "dev": true, "requires": { "@types/node": "*" } }, "@types/serve-static": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-2.2.0.tgz", "integrity": "sha512-8mam4H1NHLtu7nmtalF7eyBH14QyOASmcxHhSfEoRyr0nP/YdoesEtU+uSRvMe96TW/HPTtkoKqQLl53N7UXMQ==", "dev": true, "requires": { "@types/http-errors": "*", "@types/node": "*" } }, "@types/webidl-conversions": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-7.0.3.tgz", "integrity": "sha512-CiJJvcRtIgzadHCYXw7dqEnMNRjhGZlYK05Mj9OyktqV8uVT8fD2BFOB7S1uwBE3Kj2Z+4UyPmFw/Ixgw/LAlA==" }, "@types/whatwg-url": { "version": "8.2.2", "resolved": "https://registry.npmjs.org/@types/whatwg-url/-/whatwg-url-8.2.2.tgz", "integrity": "sha512-FtQu10RWgn3D9U4aazdwIE2yzphmTJREDqNdODHrbrZmmMqI0vMheC/6NE/J1Yveaj8H+ela+YwWTjq5PGmuhA==", "requires": { "@types/node": "*", "@types/webidl-conversions": "*" } }, "@typescript-eslint/project-service": { "version": "8.56.1", "resolved": "https://registry.npmjs.org/@typescript-eslint/project-service/-/project-service-8.56.1.tgz", "integrity": "sha512-TAdqQTzHNNvlVFfR+hu2PDJrURiwKsUvxFn1M0h95BB8ah5jejas08jUWG4dBA68jDMI988IvtfdAI53JzEHOQ==", "dev": true, "requires": { "@typescript-eslint/tsconfig-utils": "^8.56.1", "@typescript-eslint/types": "^8.56.1", "debug": "^4.4.3" }, "dependencies": { "@typescript-eslint/types": { "version": "8.57.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.57.0.tgz", "integrity": "sha512-dTLI8PEXhjUC7B9Kre+u0XznO696BhXcTlOn0/6kf1fHaQW8+VjJAVHJ3eTI14ZapTxdkOmc80HblPQLaEeJdg==", "dev": true } } }, "@typescript-eslint/tsconfig-utils": { "version": "8.56.1", "resolved": "https://registry.npmjs.org/@typescript-eslint/tsconfig-utils/-/tsconfig-utils-8.56.1.tgz", "integrity": "sha512-qOtCYzKEeyr3aR9f28mPJqBty7+DBqsdd63eO0yyDwc6vgThj2UjWfJIcsFeSucYydqcuudMOprZ+x1SpF3ZuQ==", "dev": true, "requires": {} }, "accepts": { "version": "1.3.8", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", "integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==", "requires": { "mime-types": "~2.1.34", "negotiator": "0.6.3" } }, "acorn": { "version": "8.16.0", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.16.0.tgz", "integrity": "sha512-UVJyE9MttOsBQIDKw1skb9nAwQuR5wuGD3+82K6JgJlm/Y+KI92oNsMNGZCYdDsVtRHSak0pcV5Dno5+4jh9sw==", "dev": true }, "acorn-jsx": { "version": "5.3.2", "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.2.tgz", "integrity": "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==", "dev": true, "requires": {} }, "aggregate-error": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/aggregate-error/-/aggregate-error-3.1.0.tgz", "integrity": "sha512-4I7Td01quW/RpocfNayFdFVk1qSuoh0E7JrbRJ16nH01HhKFQ88INq9Sd+nd72zqRySlr9BmDA8xlEJ6vJMrYA==", "requires": { "clean-stack": "^2.0.0", "indent-string": "^4.0.0" } }, "ajv": { "version": "6.14.0", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.14.0.tgz", "integrity": "sha512-IWrosm/yrn43eiKqkfkHis7QioDleaXQHdDVPKg0FSwwd/DuvyX79TZnFOnYpB7dcsFAMmtFztZuXPDvSePkFw==", "dev": true, "requires": { "fast-deep-equal": "^3.1.1", "fast-json-stable-stringify": "^2.0.0", "json-schema-traverse": "^0.4.1", "uri-js": "^4.2.2" } }, "balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", "dev": true }, "base64-js": { "version": "1.5.1", "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==" }, "boolbase": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/boolbase/-/boolbase-1.0.0.tgz", "integrity": "sha512-JZOSA7Mo9sNGB8+UjSgzdLtokWAky1zbztM3WRLCbZ70/3cTANmQmOdR7y2g+J0e2WXywy1yS468tY+IruqEww==", "dev": true }, "bowser": { "version": "2.14.1", "resolved": "https://registry.npmjs.org/bowser/-/bowser-2.14.1.tgz", "integrity": "sha512-tzPjzCxygAKWFOJP011oxFHs57HzIhOEracIgAePE4pqB3LikALKnSzUyU4MGs9/iCEUuHlAJTjTc5M+u7YEGg==", "optional": true }, "bson": { "version": "4.7.2", "resolved": "https://registry.npmjs.org/bson/-/bson-4.7.2.tgz", "integrity": "sha512-Ry9wCtIZ5kGqkJoi6aD8KjxFZEx78guTQDnpXWiNthsxzrxAK/i8E6pCHAIZTbaEFWcOCvbecMukfK7XUvyLpQ==", "requires": { "buffer": "^5.6.0" } }, "buffer": { "version": "5.7.1", "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz", "integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==", "requires": { "base64-js": "^1.3.1", "ieee754": "^1.1.13" } }, "buffer-equal-constant-time": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz", "integrity": "sha512-zRpUiDwd/xk6ADqPMATG8vc9VPrkck7T07OIx0gnjmJAnHnTVXNQG3vfvWNuiZIkwu9KrKdA1iJKfsfTVxE6NA==" }, "bytes": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==" }, "cache-content-type": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/cache-content-type/-/cache-content-type-1.0.1.tgz", "integrity": "sha512-IKufZ1o4Ut42YUrZSo8+qnMTrFuKkvyoLXUywKz9GJ5BrhOFGhLdkx9sG4KAnVvbY6kEcSFjLQul+DVmBm2bgA==", "requires": { "mime-types": "^2.1.18", "ylru": "^1.2.0" } }, "call-bind-apply-helpers": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==", "requires": { "es-errors": "^1.3.0", "function-bind": "^1.1.2" } }, "call-bound": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz", "integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==", "requires": { "call-bind-apply-helpers": "^1.0.2", "get-intrinsic": "^1.3.0" } }, "clean-stack": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/clean-stack/-/clean-stack-2.2.0.tgz", "integrity": "sha512-4diC9HaTE+KRAMWhDhrGOECgWZxoevMc5TlkObMqNSsVU62PYzXZ/SMTjzyGAFF1YusgxGcSWTEXBhp0CPwQ1A==" }, "co": { "version": "4.6.0", "resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz", "integrity": "sha512-QVb0dM5HvG+uaxitm8wONl7jltx8dqhfU33DcqtOZcLSVIKSDDLDi7+0LbAKiyI8hD9u42m2YxXSkMGWThaecQ==" }, "co-body": { "version": "6.1.0", "resolved": "https://registry.npmjs.org/co-body/-/co-body-6.1.0.tgz", "integrity": "sha512-m7pOT6CdLN7FuXUcpuz/8lfQ/L77x8SchHCF4G0RBTJO20Wzmhn5Sp4/5WsKy8OSpifBSUrmg83qEqaDHdyFuQ==", "requires": { "inflation": "^2.0.0", "qs": "^6.5.2", "raw-body": "^2.3.3", "type-is": "^1.6.16" } }, "commander": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/commander/-/commander-7.2.0.tgz", "integrity": "sha512-QrWXB+ZQSVPmIWIhtEO9H+gwHaMGYiF5ChvoJ+K9ZGHG/sVsa6yiesAD1GC/x46sET00Xlwo1u49RVVVzvcSkw==", "dev": true }, "compressible": { "version": "2.0.18", "resolved": "https://registry.npmjs.org/compressible/-/compressible-2.0.18.tgz", "integrity": "sha512-AF3r7P5dWxL8MxyITRMlORQNaOA2IkAFaTr4k7BUumjPtRpGDTZpl0Pb1XCO6JeDCBdp126Cgs9sMxqSjgYyRg==", "requires": { "mime-db": ">= 1.43.0 < 2" } }, "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", "dev": true }, "content-disposition": { "version": "0.5.4", "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz", "integrity": "sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==", "requires": { "safe-buffer": "5.2.1" } }, "content-type": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz", "integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==" }, "cookies": { "version": "0.9.1", "resolved": "https://registry.npmjs.org/cookies/-/cookies-0.9.1.tgz", "integrity": "sha512-TG2hpqe4ELx54QER/S3HQ9SRVnQnGBtKUz5bLQWtYAQ+o6GpgMs6sYUvaiJjVxb+UXwhRhAEP3m7LbsIZ77Hmw==", "requires": { "depd": "~2.0.0", "keygrip": "~1.1.0" } }, "crelt": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/crelt/-/crelt-1.0.6.tgz", "integrity": "sha512-VQ2MBenTq1fWZUH9DJNGti7kKv6EeAuYr3cLwxUWhIu1baTaXh4Ib5W2CqHVqib4/MqbYGJqiL3Zb8GJZr3l4g==", "dev": true }, "cross-spawn": { "version": "7.0.6", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", "dev": true, "requires": { "path-key": "^3.1.0", "shebang-command": "^2.0.0", "which": "^2.0.1" } }, "css-select": { "version": "5.2.2", "resolved": "https://registry.npmjs.org/css-select/-/css-select-5.2.2.tgz", "integrity": "sha512-TizTzUddG/xYLA3NXodFM0fSbNizXjOKhqiQQwvhlspadZokn1KDy0NZFS0wuEubIYAV5/c1/lAr0TaaFXEXzw==", "dev": true, "requires": { "boolbase": "^1.0.0", "css-what": "^6.1.0", "domhandler": "^5.0.2", "domutils": "^3.0.1", "nth-check": "^2.0.1" } }, "css-tree": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/css-tree/-/css-tree-2.3.1.tgz", "integrity": "sha512-6Fv1DV/TYw//QF5IzQdqsNDjx/wc8TrMBZsqjL9eW01tWb7R7k/mq+/VXfJCl7SoD5emsJop9cOByJZfs8hYIw==", "dev": true, "requires": { "mdn-data": "2.0.30", "source-map-js": "^1.0.1" } }, "css-what": { "version": "6.2.2", "resolved": "https://registry.npmjs.org/css-what/-/css-what-6.2.2.tgz", "integrity": "sha512-u/O3vwbptzhMs3L1fQE82ZSLHQQfto5gyZzwteVIEyeaY5Fc7R4dapF/BvRoSYFeqfBk4m0V1Vafq5Pjv25wvA==", "dev": true }, "csso": { "version": "5.0.5", "resolved": "https://registry.npmjs.org/csso/-/csso-5.0.5.tgz", "integrity": "sha512-0LrrStPOdJj+SPCCrGhzryycLjwcgUSHBtxNA8aIDxf0GLsRh1cKYhB00Gd1lDOS4yGH69+SNn13+TWbVHETFQ==", "dev": true, "requires": { "css-tree": "~2.2.0" }, "dependencies": { "css-tree": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/css-tree/-/css-tree-2.2.1.tgz", "integrity": "sha512-OA0mILzGc1kCOCSJerOeqDxDQ4HOh+G8NbOJFOTgOCzpw7fCBubk0fEyxp8AgOL/jvLgYA/uV0cMbe43ElF1JA==", "dev": true, "requires": { "mdn-data": "2.0.28", "source-map-js": "^1.0.1" } }, "mdn-data": { "version": "2.0.28", "resolved": "https://registry.npmjs.org/mdn-data/-/mdn-data-2.0.28.tgz", "integrity": "sha512-aylIc7Z9y4yzHYAJNuESG3hfhC+0Ibp/MAMiaOZgNv4pmEdFyfZhhhny4MNiAfWdBQ1RQ2mfDWmM1x8SvGyp8g==", "dev": true } } }, "debug": { "version": "4.4.3", "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", "requires": { "ms": "^2.1.3" } }, "deep-equal": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-1.0.1.tgz", "integrity": "sha512-bHtC0iYvWhyaTzvV3CZgPeZQqCOBGyGsVV7v4eevpdkLHfiSrXUdBG+qAuSz4RI70sszvjQ1QSZ98An1yNwpSw==" }, "deep-is": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz", "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==", "dev": true }, "delegates": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz", "integrity": "sha512-bd2L678uiWATM6m5Z1VzNCErI3jiGzt6HGY8OVICs40JQq/HALfbyNJmp0UDakEY4pMMaN0Ly5om/B1VI/+xfQ==" }, "depd": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==" }, "destroy": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz", "integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==" }, "detect-libc": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz", "integrity": "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==", "dev": true }, "dom-serializer": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-2.0.0.tgz", "integrity": "sha512-wIkAryiqt/nV5EQKqQpo3SToSOV9J0DnbJqwK7Wv/Trc92zIAYZ4FlMu+JPFW1DfGFt81ZTCGgDEabffXeLyJg==", "dev": true, "requires": { "domelementtype": "^2.3.0", "domhandler": "^5.0.2", "entities": "^4.2.0" } }, "domelementtype": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-2.3.0.tgz", "integrity": "sha512-OLETBj6w0OsagBwdXnPdN0cnMfF9opN69co+7ZrbfPGrdpPVNBUj02spi6B1N7wChLQiPn4CSH/zJvXw56gmHw==", "dev": true }, "domhandler": { "version": "5.0.3", "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-5.0.3.tgz", "integrity": "sha512-cgwlv/1iFQiFnU96XXgROh8xTeetsnJiDsTc7TYCLFd9+/WNkIqPTxiM/8pSd8VIrhXGTf1Ny1q1hquVqDJB5w==", "dev": true, "requires": { "domelementtype": "^2.3.0" } }, "domutils": { "version": "3.2.2", "resolved": "https://registry.npmjs.org/domutils/-/domutils-3.2.2.tgz", "integrity": "sha512-6kZKyUajlDuqlHKVX1w7gyslj9MPIXzIFiz/rGu35uC1wMi+kMhQwGhl4lt9unC9Vb9INnY9Z3/ZA3+FhASLaw==", "dev": true, "requires": { "dom-serializer": "^2.0.0", "domelementtype": "^2.3.0", "domhandler": "^5.0.3" } }, "dunder-proto": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==", "requires": { "call-bind-apply-helpers": "^1.0.1", "es-errors": "^1.3.0", "gopd": "^1.2.0" } }, "ecdsa-sig-formatter": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz", "integrity": "sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ==", "requires": { "safe-buffer": "^5.0.1" } }, "ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==" }, "encodeurl": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", "integrity": "sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w==" }, "enhanced-resolve": { "version": "5.20.0", "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.20.0.tgz", "integrity": "sha512-/ce7+jQ1PQ6rVXwe+jKEg5hW5ciicHwIQUagZkp6IufBoY3YDgdTTY1azVs0qoRgVmvsNB+rbjLJxDAeHHtwsQ==", "dev": true, "requires": { "graceful-fs": "^4.2.4", "tapable": "^2.3.0" } }, "entities": { "version": "4.5.0", "resolved": "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz", "integrity": "sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==", "dev": true }, "es-define-property": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==" }, "es-errors": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==" }, "es-object-atoms": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz", "integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==", "requires": { "es-errors": "^1.3.0" } }, "esbuild": { "version": "0.27.4", "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.27.4.tgz", "integrity": "sha512-Rq4vbHnYkK5fws5NF7MYTU68FPRE1ajX7heQ/8QXXWqNgqqJ/GkmmyxIzUnf2Sr/bakf8l54716CcMGHYhMrrQ==", "dev": true, "requires": { "@esbuild/aix-ppc64": "0.27.4", "@esbuild/android-arm": "0.27.4", "@esbuild/android-arm64": "0.27.4", "@esbuild/android-x64": "0.27.4", "@esbuild/darwin-arm64": "0.27.4", "@esbuild/darwin-x64": "0.27.4", "@esbuild/freebsd-arm64": "0.27.4", "@esbuild/freebsd-x64": "0.27.4", "@esbuild/linux-arm": "0.27.4", "@esbuild/linux-arm64": "0.27.4", "@esbuild/linux-ia32": "0.27.4", "@esbuild/linux-loong64": "0.27.4", "@esbuild/linux-mips64el": "0.27.4", "@esbuild/linux-ppc64": "0.27.4", "@esbuild/linux-riscv64": "0.27.4", "@esbuild/linux-s390x": "0.27.4", "@esbuild/linux-x64": "0.27.4", "@esbuild/netbsd-arm64": "0.27.4", "@esbuild/netbsd-x64": "0.27.4", "@esbuild/openbsd-arm64": "0.27.4", "@esbuild/openbsd-x64": "0.27.4", "@esbuild/openharmony-arm64": "0.27.4", "@esbuild/sunos-x64": "0.27.4", "@esbuild/win32-arm64": "0.27.4", "@esbuild/win32-ia32": "0.27.4", "@esbuild/win32-x64": "0.27.4" } }, "escape-html": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==" }, "escape-string-regexp": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", "dev": true }, "eslint": { "version": "10.0.3", "resolved": "https://registry.npmjs.org/eslint/-/eslint-10.0.3.tgz", "integrity": "sha512-COV33RzXZkqhG9P2rZCFl9ZmJ7WL+gQSCRzE7RhkbclbQPtLAWReL7ysA0Sh4c8Im2U9ynybdR56PV0XcKvqaQ==", "dev": true, "requires": { "@eslint-community/eslint-utils": "^4.8.0", "@eslint-community/regexpp": "^4.12.2", "@eslint/config-array": "^0.23.3", "@eslint/config-helpers": "^0.5.2", "@eslint/core": "^1.1.1", "@eslint/plugin-kit": "^0.6.1", "@humanfs/node": "^0.16.6", "@humanwhocodes/module-importer": "^1.0.1", "@humanwhocodes/retry": "^0.4.2", "@types/estree": "^1.0.6", "ajv": "^6.14.0", "cross-spawn": "^7.0.6", "debug": "^4.3.2", "escape-string-regexp": "^4.0.0", "eslint-scope": "^9.1.2", "eslint-visitor-keys": "^5.0.1", "espree": "^11.1.1", "esquery": "^1.7.0", "esutils": "^2.0.2", "fast-deep-equal": "^3.1.3", "file-entry-cache": "^8.0.0", "find-up": "^5.0.0", "glob-parent": "^6.0.2", "ignore": "^5.2.0", "imurmurhash": "^0.1.4", "is-glob": "^4.0.0", "json-stable-stringify-without-jsonify": "^1.0.1", "minimatch": "^10.2.4", "natural-compare": "^1.4.0", "optionator": "^0.9.3" }, "dependencies": { "balanced-match": { "version": "4.0.4", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-4.0.4.tgz", "integrity": "sha512-BLrgEcRTwX2o6gGxGOCNyMvGSp35YofuYzw9h1IMTRmKqttAZZVU67bdb9Pr2vUHA8+j3i2tJfjO6C6+4myGTA==", "dev": true }, "brace-expansion": { "version": "5.0.4", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.4.tgz", "integrity": "sha512-h+DEnpVvxmfVefa4jFbCf5HdH5YMDXRsmKflpf1pILZWRFlTbJpxeU55nJl4Smt5HQaGzg1o6RHFPJaOqnmBDg==", "dev": true, "requires": { "balanced-match": "^4.0.2" } }, "eslint-visitor-keys": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-5.0.1.tgz", "integrity": "sha512-tD40eHxA35h0PEIZNeIjkHoDR4YjjJp34biM0mDvplBe//mB+IHCqHDGV7pxF+7MklTvighcCPPZC7ynWyjdTA==", "dev": true }, "minimatch": { "version": "10.2.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.2.4.tgz", "integrity": "sha512-oRjTw/97aTBN0RHbYCdtF1MQfvusSIBQM0IZEgzl6426+8jSC0nF1a/GmnVLpfB9yyr6g6FTqWqiZVbxrtaCIg==", "dev": true, "requires": { "brace-expansion": "^5.0.2" } } } }, "eslint-config-prettier": { "version": "10.1.8", "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-10.1.8.tgz", "integrity": "sha512-82GZUjRS0p/jganf6q1rEO25VSoHH0hKPCTrgillPjdI/3bgBhAE1QzHrHTizjpRvy6pGAvKjDJtk2pF9NDq8w==", "dev": true, "requires": {} }, "eslint-scope": { "version": "9.1.2", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-9.1.2.tgz", "integrity": "sha512-xS90H51cKw0jltxmvmHy2Iai1LIqrfbw57b79w/J7MfvDfkIkFZ+kj6zC3BjtUwh150HsSSdxXZcsuv72miDFQ==", "dev": true, "requires": { "@types/esrecurse": "^4.3.1", "@types/estree": "^1.0.8", "esrecurse": "^4.3.0", "estraverse": "^5.2.0" } }, "eslint-visitor-keys": { "version": "3.4.3", "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.4.3.tgz", "integrity": "sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag==", "dev": true }, "espree": { "version": "11.2.0", "resolved": "https://registry.npmjs.org/espree/-/espree-11.2.0.tgz", "integrity": "sha512-7p3DrVEIopW1B1avAGLuCSh1jubc01H2JHc8B4qqGblmg5gI9yumBgACjWo4JlIc04ufug4xJ3SQI8HkS/Rgzw==", "dev": true, "requires": { "acorn": "^8.16.0", "acorn-jsx": "^5.3.2", "eslint-visitor-keys": "^5.0.1" }, "dependencies": { "eslint-visitor-keys": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-5.0.1.tgz", "integrity": "sha512-tD40eHxA35h0PEIZNeIjkHoDR4YjjJp34biM0mDvplBe//mB+IHCqHDGV7pxF+7MklTvighcCPPZC7ynWyjdTA==", "dev": true } } }, "espresso-iisojs": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/espresso-iisojs/-/espresso-iisojs-1.0.8.tgz", "integrity": "sha512-S3D62BA/jBUCIQJ3VlBGMSxGwPyyV7ttduiJvyaD4dWyhiC/9TnJTaiurx4r8bqcYZ1J0KELliub4xo8neKjSA==" }, "esquery": { "version": "1.7.0", "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.7.0.tgz", "integrity": "sha512-Ap6G0WQwcU/LHsvLwON1fAQX9Zp0A2Y6Y/cJBl9r/JbW90Zyg4/zbG6zzKa2OTALELarYHmKu0GhpM5EO+7T0g==", "dev": true, "requires": { "estraverse": "^5.1.0" } }, "esrecurse": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.3.0.tgz", "integrity": "sha512-KmfKL3b6G+RXvP8N1vr3Tq1kL/oCFgn2NYXEtqP8/L3pKapUA4G8cFVaoF3SU323CD4XypR/ffioHmkti6/Tag==", "dev": true, "requires": { "estraverse": "^5.2.0" } }, "estraverse": { "version": "5.3.0", "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz", "integrity": "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==", "dev": true }, "esutils": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", "integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==", "dev": true }, "fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", "dev": true }, "fast-json-stable-stringify": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==", "dev": true }, "fast-levenshtein": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", "integrity": "sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==", "dev": true }, "fast-xml-builder": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/fast-xml-builder/-/fast-xml-builder-1.1.2.tgz", "integrity": "sha512-NJAmiuVaJEjVa7TjLZKlYd7RqmzOC91EtPFXHvlTcqBVo50Qh7XV5IwvXi1c7NRz2Q/majGX9YLcwJtWgHjtkA==", "optional": true, "requires": { "path-expression-matcher": "^1.1.3" } }, "fast-xml-parser": { "version": "5.4.1", "resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-5.4.1.tgz", "integrity": "sha512-BQ30U1mKkvXQXXkAGcuyUA/GA26oEB7NzOtsxCDtyu62sjGw5QraKFhx2Em3WQNjPw9PG6MQ9yuIIgkSDfGu5A==", "optional": true, "requires": { "fast-xml-builder": "^1.0.0", "strnum": "^2.1.2" } }, "file-entry-cache": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-8.0.0.tgz", "integrity": "sha512-XXTUwCvisa5oacNGRP9SfNtYBNAMi+RPwBFmblZEF7N7swHYQS6/Zfk7SRwx4D5j3CH211YNRco1DEMNVfZCnQ==", "dev": true, "requires": { "flat-cache": "^4.0.0" } }, "find-up": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz", "integrity": "sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==", "dev": true, "requires": { "locate-path": "^6.0.0", "path-exists": "^4.0.0" } }, "flat-cache": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-4.0.1.tgz", "integrity": "sha512-f7ccFPK3SXFHpx15UIGyRJ/FJQctuKZ0zVuN3frBo4HnK3cay9VEW0R6yPYFHC0AgqhukPzKjq22t5DmAyqGyw==", "dev": true, "requires": { "flatted": "^3.2.9", "keyv": "^4.5.4" } }, "flatted": { "version": "3.4.1", "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.4.1.tgz", "integrity": "sha512-IxfVbRFVlV8V/yRaGzk0UVIcsKKHMSfYw66T/u4nTwlWteQePsxe//LjudR1AMX4tZW3WFCh3Zqa/sjlqpbURQ==", "dev": true }, "fresh": { "version": "0.5.2", "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", "integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==" }, "function-bind": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==" }, "generator-function": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/generator-function/-/generator-function-2.0.1.tgz", "integrity": "sha512-SFdFmIJi+ybC0vjlHN0ZGVGHc3lgE0DxPAT0djjVg+kjOnSqclqmj0KQ7ykTOLP6YxoqOvuAODGdcHJn+43q3g==" }, "get-intrinsic": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz", "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==", "requires": { "call-bind-apply-helpers": "^1.0.2", "es-define-property": "^1.0.1", "es-errors": "^1.3.0", "es-object-atoms": "^1.1.1", "function-bind": "^1.1.2", "get-proto": "^1.0.1", "gopd": "^1.2.0", "has-symbols": "^1.1.0", "hasown": "^2.0.2", "math-intrinsics": "^1.1.0" } }, "get-proto": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz", "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==", "requires": { "dunder-proto": "^1.0.1", "es-object-atoms": "^1.0.0" } }, "glob-parent": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz", "integrity": "sha512-XxwI8EOhVQgWp6iDL+3b0r86f4d6AX6zSU55HfB4ydCEuXLXc5FcYeOu+nnGftS4TEju/11rt4KJPTMgbfmv4A==", "dev": true, "requires": { "is-glob": "^4.0.3" } }, "globals": { "version": "17.4.0", "resolved": "https://registry.npmjs.org/globals/-/globals-17.4.0.tgz", "integrity": "sha512-hjrNztw/VajQwOLsMNT1cbJiH2muO3OROCHnbehc8eY5JyD2gqz4AcMHPqgaOR59DjgUjYAYLeH699g/eWi2jw==", "dev": true }, "gopd": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==" }, "graceful-fs": { "version": "4.2.11", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==", "dev": true }, "has-symbols": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==" }, "has-tostringtag": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz", "integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==", "requires": { "has-symbols": "^1.0.3" } }, "hasown": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==", "requires": { "function-bind": "^1.1.2" } }, "http-assert": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/http-assert/-/http-assert-1.5.0.tgz", "integrity": "sha512-uPpH7OKX4H25hBmU6G1jWNaqJGpTXxey+YOUizJUAgu0AjLUeC8D73hTrhvDS5D+GJN1DN1+hhc/eF/wpxtp0w==", "requires": { "deep-equal": "~1.0.1", "http-errors": "~1.8.0" }, "dependencies": { "depd": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", "integrity": "sha512-7emPTl6Dpo6JRXOXjLRxck+FlLRX5847cLKEn00PLAgc3g2hTZZgr+e4c2v6QpSmLeFP3n5yUo7ft6avBK/5jQ==" }, "http-errors": { "version": "1.8.1", "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.8.1.tgz", "integrity": "sha512-Kpk9Sm7NmI+RHhnj6OIWDI1d6fIoFAtFt9RLaTMRlg/8w49juAStsrBgp0Dp4OdxdVbRIeKhtCUvoi/RuAhO4g==", "requires": { "depd": "~1.1.2", "inherits": "2.0.4", "setprototypeof": "1.2.0", "statuses": ">= 1.5.0 < 2", "toidentifier": "1.0.1" } }, "statuses": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", "integrity": "sha512-OpZ3zP+jT1PI7I8nemJX4AKmAX070ZkYPVWV/AaKTJl+tXCTGyVdC1a4SL8RUQYEwk/f34ZX8UTykN68FwrqAA==" } } }, "http-errors": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.1.tgz", "integrity": "sha512-4FbRdAX+bSdmo4AUFuS0WNiPz8NgFt+r8ThgNWmlrjQjt1Q7ZR9+zTlce2859x4KSXrwIsaeTqDoKQmtP8pLmQ==", "requires": { "depd": "~2.0.0", "inherits": "~2.0.4", "setprototypeof": "~1.2.0", "statuses": "~2.0.2", "toidentifier": "~1.0.1" } }, "iconv-lite": { "version": "0.6.3", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", "requires": { "safer-buffer": ">= 2.1.2 < 3.0.0" } }, "ieee754": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==" }, "ignore": { "version": "5.3.2", "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz", "integrity": "sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g==", "dev": true }, "imurmurhash": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", "integrity": "sha512-JmXMZ6wuvDmLiHEml9ykzqO6lwFbof0GG4IkcGaENdCRDDmMVnny7s5HsIgHCbaq0w2MyPhDqkhTUgS2LU2PHA==", "dev": true }, "indent-string": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/indent-string/-/indent-string-4.0.0.tgz", "integrity": "sha512-EdDDZu4A2OyIK7Lr/2zG+w5jmbuk1DVBnEwREQvBzspBJkCEbRa8GxU1lghYcaGJCnRWibjDXlq779X1/y5xwg==" }, "inflation": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/inflation/-/inflation-2.1.0.tgz", "integrity": "sha512-t54PPJHG1Pp7VQvxyVCJ9mBbjG3Hqryges9bXoOO6GExCPa+//i/d5GSuFtpx3ALLd7lgIAur6zrIlBQyJuMlQ==" }, "inherits": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" }, "ip-address": { "version": "10.1.0", "resolved": "https://registry.npmjs.org/ip-address/-/ip-address-10.1.0.tgz", "integrity": "sha512-XXADHxXmvT9+CRxhXg56LJovE+bmWnEWB78LB83VZTprKTmaC5QfruXocxzTZ2Kl0DNwKuBdlIhjL8LeY8Sf8Q==" }, "ipaddr.js": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-2.3.0.tgz", "integrity": "sha512-Zv/pA+ciVFbCSBBjGfaKUya/CcGmUHzTydLMaTwrUUEM2DIEO3iZvueGxmacvmN50fGpGVKeTXpb2LcYQxeVdg==" }, "is-extglob": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", "dev": true }, "is-generator-function": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/is-generator-function/-/is-generator-function-1.1.2.tgz", "integrity": "sha512-upqt1SkGkODW9tsGNG5mtXTXtECizwtS2kA161M+gJPc1xdb/Ax629af6YrTwcOeQHbewrPNlE5Dx7kzvXTizA==", "requires": { "call-bound": "^1.0.4", "generator-function": "^2.0.0", "get-proto": "^1.0.1", "has-tostringtag": "^1.0.2", "safe-regex-test": "^1.1.0" } }, "is-glob": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", "dev": true, "requires": { "is-extglob": "^2.1.1" } }, "is-regex": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.2.1.tgz", "integrity": "sha512-MjYsKHO5O7mCsmRGxWcLWheFqN9DJ/2TmngvjKXihe6efViPqc274+Fx/4fYj/r03+ESvBdTXK0V6tA3rgez1g==", "requires": { "call-bound": "^1.0.2", "gopd": "^1.2.0", "has-tostringtag": "^1.0.2", "hasown": "^2.0.2" } }, "isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", "dev": true }, "jiti": { "version": "2.6.1", "resolved": "https://registry.npmjs.org/jiti/-/jiti-2.6.1.tgz", "integrity": "sha512-ekilCSN1jwRvIbgeg/57YFh8qQDNbwDb9xT/qu2DAHbFFZUicIl4ygVaAvzveMhMVr3LnpSKTNnwt8PoOfmKhQ==", "dev": true }, "json-buffer": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.1.tgz", "integrity": "sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ==", "dev": true }, "json-schema-traverse": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", "dev": true }, "json-stable-stringify-without-jsonify": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz", "integrity": "sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==", "dev": true }, "jsonwebtoken": { "version": "9.0.3", "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-9.0.3.tgz", "integrity": "sha512-MT/xP0CrubFRNLNKvxJ2BYfy53Zkm++5bX9dtuPbqAeQpTVe0MQTFhao8+Cp//EmJp244xt6Drw/GVEGCUj40g==", "requires": { "jws": "^4.0.1", "lodash.includes": "^4.3.0", "lodash.isboolean": "^3.0.3", "lodash.isinteger": "^4.0.4", "lodash.isnumber": "^3.0.3", "lodash.isplainobject": "^4.0.6", "lodash.isstring": "^4.0.1", "lodash.once": "^4.0.0", "ms": "^2.1.1", "semver": "^7.5.4" } }, "jwa": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/jwa/-/jwa-2.0.1.tgz", "integrity": "sha512-hRF04fqJIP8Abbkq5NKGN0Bbr3JxlQ+qhZufXVr0DvujKy93ZCbXZMHDL4EOtodSbCWxOqR8MS1tXA5hwqCXDg==", "requires": { "buffer-equal-constant-time": "^1.0.1", "ecdsa-sig-formatter": "1.0.11", "safe-buffer": "^5.0.1" } }, "jws": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/jws/-/jws-4.0.1.tgz", "integrity": "sha512-EKI/M/yqPncGUUh44xz0PxSidXFr/+r0pA70+gIYhjv+et7yxM+s29Y+VGDkovRofQem0fs7Uvf4+YmAdyRduA==", "requires": { "jwa": "^2.0.1", "safe-buffer": "^5.0.1" } }, "keygrip": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/keygrip/-/keygrip-1.1.0.tgz", "integrity": "sha512-iYSchDJ+liQ8iwbSI2QqsQOvqv58eJCEanyJPJi+Khyu8smkcKSFUCbPwzFcL7YVtZ6eONjqRX/38caJ7QjRAQ==", "requires": { "tsscmp": "1.0.6" } }, "keyv": { "version": "4.5.4", "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz", "integrity": "sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==", "dev": true, "requires": { "json-buffer": "3.0.1" } }, "koa": { "version": "2.16.4", "resolved": "https://registry.npmjs.org/koa/-/koa-2.16.4.tgz", "integrity": "sha512-3An0GCLDSR34tsCO4H8Tef8Pp2ngtaZDAZnsWJYelqXUK5wyiHvGItgK/xcSkmHLSTn1Jcho1mRQs2ehRzvKKw==", "requires": { "accepts": "^1.3.5", "cache-content-type": "^1.0.0", "content-disposition": "~0.5.2", "content-type": "^1.0.4", "cookies": "~0.9.0", "debug": "^4.3.2", "delegates": "^1.0.0", "depd": "^2.0.0", "destroy": "^1.0.4", "encodeurl": "^1.0.2", "escape-html": "^1.0.3", "fresh": "~0.5.2", "http-assert": "^1.3.0", "http-errors": "^1.6.3", "is-generator-function": "^1.0.7", "koa-compose": "^4.1.0", "koa-convert": "^2.0.0", "on-finished": "^2.3.0", "only": "~0.0.2", "parseurl": "^1.3.2", "statuses": "^1.5.0", "type-is": "^1.6.16", "vary": "^1.1.2" }, "dependencies": { "http-errors": { "version": "1.8.1", "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.8.1.tgz", "integrity": "sha512-Kpk9Sm7NmI+RHhnj6OIWDI1d6fIoFAtFt9RLaTMRlg/8w49juAStsrBgp0Dp4OdxdVbRIeKhtCUvoi/RuAhO4g==", "requires": { "depd": "~1.1.2", "inherits": "2.0.4", "setprototypeof": "1.2.0", "statuses": ">= 1.5.0 < 2", "toidentifier": "1.0.1" }, "dependencies": { "depd": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", "integrity": "sha512-7emPTl6Dpo6JRXOXjLRxck+FlLRX5847cLKEn00PLAgc3g2hTZZgr+e4c2v6QpSmLeFP3n5yUo7ft6avBK/5jQ==" } } }, "statuses": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", "integrity": "sha512-OpZ3zP+jT1PI7I8nemJX4AKmAX070ZkYPVWV/AaKTJl+tXCTGyVdC1a4SL8RUQYEwk/f34ZX8UTykN68FwrqAA==" } } }, "koa-compose": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/koa-compose/-/koa-compose-4.1.0.tgz", "integrity": "sha512-8ODW8TrDuMYvXRwra/Kh7/rJo9BtOfPc6qO8eAfC80CnCvSjSl0bkRM24X6/XBBEyj0v1nRUQ1LyOy3dbqOWXw==" }, "koa-compress": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/koa-compress/-/koa-compress-5.2.0.tgz", "integrity": "sha512-RsRnI+v+/rs1lYpcAUcxowUzHYssf71qbMr0Mpdq1wktbtXDZmxBIgxJHtaEsBjSe4jiWYELpGFbASa2AemmOg==", "requires": { "bytes": "^3.1.2", "compressible": "^2.0.18", "http-errors": "^2.0.1", "koa-is-json": "^1.0.0", "negotiator": "^1.0.0" }, "dependencies": { "negotiator": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-1.0.0.tgz", "integrity": "sha512-8Ofs/AUQh8MaEcrlq5xOX0CQ9ypTF5dl78mjlMNfOK08fzpgTHQRQPBxcPlEtIw0yRpws+Zo/3r+5WRby7u3Gg==" } } }, "koa-convert": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/koa-convert/-/koa-convert-2.0.0.tgz", "integrity": "sha512-asOvN6bFlSnxewce2e/DK3p4tltyfC4VM7ZwuTuepI7dEQVcvpyFuBcEARu1+Hxg8DIwytce2n7jrZtRlPrARA==", "requires": { "co": "^4.6.0", "koa-compose": "^4.1.0" } }, "koa-is-json": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/koa-is-json/-/koa-is-json-1.0.0.tgz", "integrity": "sha512-+97CtHAlWDx0ndt0J8y3P12EWLwTLMXIfMnYDev3wOTwH/RpBGMlfn4bDXlMEg1u73K6XRE9BbUp+5ZAYoRYWw==" }, "koa-jwt": { "version": "4.0.4", "resolved": "https://registry.npmjs.org/koa-jwt/-/koa-jwt-4.0.4.tgz", "integrity": "sha512-Tid9BQfpVtUG/8YZV38a+hDKll0pfVhfl7A/2cNaYThS1cxMFXylZzfARqHQqvNhHy9qM+qkxd4/z6EaIV4SAQ==", "requires": { "jsonwebtoken": "^9.0.0", "koa-unless": "^1.0.7", "p-any": "^2.1.0" } }, "koa-send": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/koa-send/-/koa-send-5.0.1.tgz", "integrity": "sha512-tmcyQ/wXXuxpDxyNXv5yNNkdAMdFRqwtegBXUaowiQzUKqJehttS0x2j0eOZDQAyloAth5w6wwBImnFzkUz3pQ==", "requires": { "debug": "^4.1.1", "http-errors": "^1.7.3", "resolve-path": "^1.4.0" }, "dependencies": { "depd": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", "integrity": "sha512-7emPTl6Dpo6JRXOXjLRxck+FlLRX5847cLKEn00PLAgc3g2hTZZgr+e4c2v6QpSmLeFP3n5yUo7ft6avBK/5jQ==" }, "http-errors": { "version": "1.8.1", "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.8.1.tgz", "integrity": "sha512-Kpk9Sm7NmI+RHhnj6OIWDI1d6fIoFAtFt9RLaTMRlg/8w49juAStsrBgp0Dp4OdxdVbRIeKhtCUvoi/RuAhO4g==", "requires": { "depd": "~1.1.2", "inherits": "2.0.4", "setprototypeof": "1.2.0", "statuses": ">= 1.5.0 < 2", "toidentifier": "1.0.1" } }, "statuses": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", "integrity": "sha512-OpZ3zP+jT1PI7I8nemJX4AKmAX070ZkYPVWV/AaKTJl+tXCTGyVdC1a4SL8RUQYEwk/f34ZX8UTykN68FwrqAA==" } } }, "koa-unless": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/koa-unless/-/koa-unless-1.0.7.tgz", "integrity": "sha512-NKiz+nk4KxSJFskiJMuJvxeA41Lcnx3d8Zy+8QETgifm4ab4aOeGD3RgR6bIz0FGNWwo3Fz0DtnK77mEIqHWxA==" }, "levn": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz", "integrity": "sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==", "dev": true, "requires": { "prelude-ls": "^1.2.1", "type-check": "~0.4.0" } }, "lightningcss": { "version": "1.31.1", "resolved": "https://registry.npmjs.org/lightningcss/-/lightningcss-1.31.1.tgz", "integrity": "sha512-l51N2r93WmGUye3WuFoN5k10zyvrVs0qfKBhyC5ogUQ6Ew6JUSswh78mbSO+IU3nTWsyOArqPCcShdQSadghBQ==", "dev": true, "requires": { "detect-libc": "^2.0.3", "lightningcss-android-arm64": "1.31.1", "lightningcss-darwin-arm64": "1.31.1", "lightningcss-darwin-x64": "1.31.1", "lightningcss-freebsd-x64": "1.31.1", "lightningcss-linux-arm-gnueabihf": "1.31.1", "lightningcss-linux-arm64-gnu": "1.31.1", "lightningcss-linux-arm64-musl": "1.31.1", "lightningcss-linux-x64-gnu": "1.31.1", "lightningcss-linux-x64-musl": "1.31.1", "lightningcss-win32-arm64-msvc": "1.31.1", "lightningcss-win32-x64-msvc": "1.31.1" } }, "lightningcss-android-arm64": { "version": "1.31.1", "resolved": "https://registry.npmjs.org/lightningcss-android-arm64/-/lightningcss-android-arm64-1.31.1.tgz", "integrity": "sha512-HXJF3x8w9nQ4jbXRiNppBCqeZPIAfUo8zE/kOEGbW5NZvGc/K7nMxbhIr+YlFlHW5mpbg/YFPdbnCh1wAXCKFg==", "dev": true, "optional": true }, "lightningcss-darwin-arm64": { "version": "1.31.1", "resolved": "https://registry.npmjs.org/lightningcss-darwin-arm64/-/lightningcss-darwin-arm64-1.31.1.tgz", "integrity": "sha512-02uTEqf3vIfNMq3h/z2cJfcOXnQ0GRwQrkmPafhueLb2h7mqEidiCzkE4gBMEH65abHRiQvhdcQ+aP0D0g67sg==", "dev": true, "optional": true }, "lightningcss-darwin-x64": { "version": "1.31.1", "resolved": "https://registry.npmjs.org/lightningcss-darwin-x64/-/lightningcss-darwin-x64-1.31.1.tgz", "integrity": "sha512-1ObhyoCY+tGxtsz1lSx5NXCj3nirk0Y0kB/g8B8DT+sSx4G9djitg9ejFnjb3gJNWo7qXH4DIy2SUHvpoFwfTA==", "dev": true, "optional": true }, "lightningcss-freebsd-x64": { "version": "1.31.1", "resolved": "https://registry.npmjs.org/lightningcss-freebsd-x64/-/lightningcss-freebsd-x64-1.31.1.tgz", "integrity": "sha512-1RINmQKAItO6ISxYgPwszQE1BrsVU5aB45ho6O42mu96UiZBxEXsuQ7cJW4zs4CEodPUioj/QrXW1r9pLUM74A==", "dev": true, "optional": true }, "lightningcss-linux-arm-gnueabihf": { "version": "1.31.1", "resolved": "https://registry.npmjs.org/lightningcss-linux-arm-gnueabihf/-/lightningcss-linux-arm-gnueabihf-1.31.1.tgz", "integrity": "sha512-OOCm2//MZJ87CdDK62rZIu+aw9gBv4azMJuA8/KB74wmfS3lnC4yoPHm0uXZ/dvNNHmnZnB8XLAZzObeG0nS1g==", "dev": true, "optional": true }, "lightningcss-linux-arm64-gnu": { "version": "1.31.1", "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-gnu/-/lightningcss-linux-arm64-gnu-1.31.1.tgz", "integrity": "sha512-WKyLWztD71rTnou4xAD5kQT+982wvca7E6QoLpoawZ1gP9JM0GJj4Tp5jMUh9B3AitHbRZ2/H3W5xQmdEOUlLg==", "dev": true, "optional": true }, "lightningcss-linux-arm64-musl": { "version": "1.31.1", "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-musl/-/lightningcss-linux-arm64-musl-1.31.1.tgz", "integrity": "sha512-mVZ7Pg2zIbe3XlNbZJdjs86YViQFoJSpc41CbVmKBPiGmC4YrfeOyz65ms2qpAobVd7WQsbW4PdsSJEMymyIMg==", "dev": true, "optional": true }, "lightningcss-linux-x64-gnu": { "version": "1.31.1", "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-gnu/-/lightningcss-linux-x64-gnu-1.31.1.tgz", "integrity": "sha512-xGlFWRMl+0KvUhgySdIaReQdB4FNudfUTARn7q0hh/V67PVGCs3ADFjw+6++kG1RNd0zdGRlEKa+T13/tQjPMA==", "dev": true, "optional": true }, "lightningcss-linux-x64-musl": { "version": "1.31.1", "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-musl/-/lightningcss-linux-x64-musl-1.31.1.tgz", "integrity": "sha512-eowF8PrKHw9LpoZii5tdZwnBcYDxRw2rRCyvAXLi34iyeYfqCQNA9rmUM0ce62NlPhCvof1+9ivRaTY6pSKDaA==", "dev": true, "optional": true }, "lightningcss-win32-arm64-msvc": { "version": "1.31.1", "resolved": "https://registry.npmjs.org/lightningcss-win32-arm64-msvc/-/lightningcss-win32-arm64-msvc-1.31.1.tgz", "integrity": "sha512-aJReEbSEQzx1uBlQizAOBSjcmr9dCdL3XuC/6HLXAxmtErsj2ICo5yYggg1qOODQMtnjNQv2UHb9NpOuFtYe4w==", "dev": true, "optional": true }, "lightningcss-win32-x64-msvc": { "version": "1.31.1", "resolved": "https://registry.npmjs.org/lightningcss-win32-x64-msvc/-/lightningcss-win32-x64-msvc-1.31.1.tgz", "integrity": "sha512-I9aiFrbd7oYHwlnQDqr1Roz+fTz61oDDJX7n9tYF9FJymH1cIN1DtKw3iYt6b8WZgEjoNwVSncwF4wx/ZedMhw==", "dev": true, "optional": true }, "locate-path": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", "integrity": "sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==", "dev": true, "requires": { "p-locate": "^5.0.0" } }, "lodash.includes": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz", "integrity": "sha512-W3Bx6mdkRTGtlJISOvVD/lbqjTlPPUDTMnlXZFnVwi9NKJ6tiAk6LVdlhZMm17VZisqhKcgzpO5Wz91PCt5b0w==" }, "lodash.isboolean": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/lodash.isboolean/-/lodash.isboolean-3.0.3.tgz", "integrity": "sha512-Bz5mupy2SVbPHURB98VAcw+aHh4vRV5IPNhILUCsOzRmsTmSQ17jIuqopAentWoehktxGd9e/hbIXq980/1QJg==" }, "lodash.isinteger": { "version": "4.0.4", "resolved": "https://registry.npmjs.org/lodash.isinteger/-/lodash.isinteger-4.0.4.tgz", "integrity": "sha512-DBwtEWN2caHQ9/imiNeEA5ys1JoRtRfY3d7V9wkqtbycnAmTvRRmbHKDV4a0EYc678/dia0jrte4tjYwVBaZUA==" }, "lodash.isnumber": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz", "integrity": "sha512-QYqzpfwO3/CWf3XP+Z+tkQsfaLL/EnUlXWVkIk5FUPc4sBdTehEqZONuyRt2P67PXAk+NXmTBcc97zw9t1FQrw==" }, "lodash.isplainobject": { "version": "4.0.6", "resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz", "integrity": "sha512-oSXzaWypCMHkPC3NvBEaPHf0KsA5mvPrOPgQWDsbg8n7orZ290M0BmC/jgRZ4vcJ6DTAhjrsSYgdsW/F+MFOBA==" }, "lodash.isstring": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/lodash.isstring/-/lodash.isstring-4.0.1.tgz", "integrity": "sha512-0wJxfxH1wgO3GrbuP+dTTk7op+6L41QCXbGINEmD+ny/G/eCqGzxyCsh7159S+mgDDcoarnBw6PC1PS5+wUGgw==" }, "lodash.merge": { "version": "4.6.2", "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==" }, "lodash.once": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz", "integrity": "sha512-Sb487aTOCr9drQVL8pIxOzVhafOjZN9UU54hiN8PU3uAiSV7lx1yYNpbNmex2PK6dSJoNTSJUUswT651yww3Mg==" }, "magic-string": { "version": "0.30.21", "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.21.tgz", "integrity": "sha512-vd2F4YUyEXKGcLHoq+TEyCjxueSeHnFxyyjNp80yg0XV4vUhnDer/lvvlqM/arB5bXQN5K2/3oinyCRyx8T2CQ==", "dev": true, "requires": { "@jridgewell/sourcemap-codec": "^1.5.5" } }, "math-intrinsics": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==" }, "mdn-data": { "version": "2.0.30", "resolved": "https://registry.npmjs.org/mdn-data/-/mdn-data-2.0.30.tgz", "integrity": "sha512-GaqWWShW4kv/G9IEucWScBx9G1/vsFZZJUO+tD26M8J8z3Kw5RDQjaoZe03YAClgeS/SWPOcb4nkFBTEi5DUEA==", "dev": true }, "media-typer": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", "integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==" }, "memory-pager": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/memory-pager/-/memory-pager-1.5.0.tgz", "integrity": "sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg==", "optional": true }, "mime-db": { "version": "1.54.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.54.0.tgz", "integrity": "sha512-aU5EJuIN2WDemCcAp2vFBfp/m4EAhWJnUNSSw0ixs7/kXbd6Pg64EmwJkNdFhB8aWt1sH2CTXrLxo/iAGV3oPQ==" }, "mime-types": { "version": "2.1.35", "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", "requires": { "mime-db": "1.52.0" }, "dependencies": { "mime-db": { "version": "1.52.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==" } } }, "mini-svg-data-uri": { "version": "1.4.4", "resolved": "https://registry.npmjs.org/mini-svg-data-uri/-/mini-svg-data-uri-1.4.4.tgz", "integrity": "sha512-r9deDe9p5FJUPZAk3A59wGH7Ii9YrjjWw0jmw/liSbHl2CHiyXj6FcDXDu2K3TjVAXqiJdaw3xxwlZZr9E6nHg==", "dev": true }, "mithril": { "version": "2.3.8", "resolved": "https://registry.npmjs.org/mithril/-/mithril-2.3.8.tgz", "integrity": "sha512-za/Yo7qXEckjm5syrSfaaI9Utf4tCUT3T1IOIYqH6Lrj7G0OZuYYLAY9SV4ygoaAf0+CNqU92MBt+7pmo53JVQ==", "dev": true }, "mongodb": { "version": "4.17.2", "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-4.17.2.tgz", "integrity": "sha512-mLV7SEiov2LHleRJPMPrK2PMyhXFZt2UQLC4VD4pnth3jMjYKHhtqfwwkkvS/NXuo/Fp3vbhaNcXrIDaLRb9Tg==", "requires": { "@aws-sdk/credential-providers": "^3.186.0", "@mongodb-js/saslprep": "^1.1.0", "bson": "^4.7.2", "mongodb-connection-string-url": "^2.6.0", "socks": "^2.7.1" } }, "mongodb-connection-string-url": { "version": "2.6.0", "resolved": "https://registry.npmjs.org/mongodb-connection-string-url/-/mongodb-connection-string-url-2.6.0.tgz", "integrity": "sha512-WvTZlI9ab0QYtTYnuMLgobULWhokRjtC7db9LtcVfJ+Hsnyr5eo6ZtNAt3Ly24XZScGMelOcGtm7lSn0332tPQ==", "requires": { "@types/whatwg-url": "^8.2.1", "whatwg-url": "^11.0.0" } }, "mri": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/mri/-/mri-1.2.0.tgz", "integrity": "sha512-tzzskb3bG8LvYGFF/mDTpq3jpI6Q9wc3LEmBaghu+DdCssd1FakN7Bc0hVNmEyGq1bq3RgfkCb3cmQLpNPOroA==", "dev": true }, "ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" }, "natural-compare": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", "integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==", "dev": true }, "negotiator": { "version": "0.6.3", "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==" }, "node-addon-api": { "version": "7.1.1", "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-7.1.1.tgz", "integrity": "sha512-5m3bsyrjFWE1xf7nz7YXdN4udnVtXK6/Yfgn5qnahL6bCkf2yKt4k3nuTKAtT4r3IG8JNR2ncsIMdZuAzJjHQQ==", "dev": true }, "nth-check": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/nth-check/-/nth-check-2.1.1.tgz", "integrity": "sha512-lqjrjmaOoAnWfMmBPL+XNnynZh2+swxiX3WUE0s4yEHI6m+AwrK2UZOimIRl3X/4QctVqS8AiZjFqyOGrMXb/w==", "dev": true, "requires": { "boolbase": "^1.0.0" } }, "object-inspect": { "version": "1.13.4", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz", "integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==" }, "on-finished": { "version": "2.4.1", "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz", "integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==", "requires": { "ee-first": "1.1.1" } }, "only": { "version": "0.0.2", "resolved": "https://registry.npmjs.org/only/-/only-0.0.2.tgz", "integrity": "sha512-Fvw+Jemq5fjjyWz6CpKx6w9s7xxqo3+JCyM0WXWeCSOboZ8ABkyvP8ID4CZuChA/wxSx+XSJmdOm8rGVyJ1hdQ==" }, "optionator": { "version": "0.9.4", "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.4.tgz", "integrity": "sha512-6IpQ7mKUxRcZNLIObR0hz7lxsapSSIYNZJwXPGeF0mTVqGKFIXj1DQcMoT22S3ROcLyY/rz0PWaWZ9ayWmad9g==", "dev": true, "requires": { "deep-is": "^0.1.3", "fast-levenshtein": "^2.0.6", "levn": "^0.4.1", "prelude-ls": "^1.2.1", "type-check": "^0.4.0", "word-wrap": "^1.2.5" } }, "p-any": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/p-any/-/p-any-2.1.0.tgz", "integrity": "sha512-JAERcaMBLYKMq+voYw36+x5Dgh47+/o7yuv2oQYuSSUml4YeqJEFznBrY2UeEkoSHqBua6hz518n/PsowTYLLg==", "requires": { "p-cancelable": "^2.0.0", "p-some": "^4.0.0", "type-fest": "^0.3.0" }, "dependencies": { "type-fest": { "version": "0.3.1", "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.3.1.tgz", "integrity": "sha512-cUGJnCdr4STbePCgqNFbpVNCepa+kAVohJs1sLhxzdH+gnEoOd8VhbYa7pD3zZYGiURWM2xzEII3fQcRizDkYQ==" } } }, "p-cancelable": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-2.1.1.tgz", "integrity": "sha512-BZOr3nRQHOntUjTrH8+Lh54smKHoHyur8We1V8DSMVrl5A2malOOwuJRnKRDjSnkoeBh4at6BwEnb5I7Jl31wg==" }, "p-limit": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", "integrity": "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==", "dev": true, "requires": { "yocto-queue": "^0.1.0" } }, "p-locate": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-5.0.0.tgz", "integrity": "sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==", "dev": true, "requires": { "p-limit": "^3.0.2" } }, "p-some": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/p-some/-/p-some-4.1.0.tgz", "integrity": "sha512-MF/HIbq6GeBqTrTIl5OJubzkGU+qfFhAFi0gnTAK6rgEIJIknEiABHOTtQu4e6JiXjIwuMPMUFQzyHh5QjCl1g==", "requires": { "aggregate-error": "^3.0.0", "p-cancelable": "^2.0.0" } }, "parseurl": { "version": "1.3.3", "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==" }, "path-exists": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", "dev": true }, "path-expression-matcher": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/path-expression-matcher/-/path-expression-matcher-1.1.3.tgz", "integrity": "sha512-qdVgY8KXmVdJZRSS1JdEPOKPdTiEK/pi0RkcT2sw1RhXxohdujUlJFPuS1TSkevZ9vzd3ZlL7ULl1MHGTApKzQ==", "optional": true }, "path-is-absolute": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==" }, "path-key": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", "dev": true }, "path-to-regexp": { "version": "6.3.0", "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-6.3.0.tgz", "integrity": "sha512-Yhpw4T9C6hPpgPeA28us07OJeqZ5EzQTkbfwuhsUg0c237RomFoETJgmp2sa3F/41gfLE6G5cqcYwznmeEeOlQ==" }, "picocolors": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==", "dev": true }, "prelude-ls": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==", "dev": true }, "prettier": { "version": "3.8.1", "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.8.1.tgz", "integrity": "sha512-UOnG6LftzbdaHZcKoPFtOcCKztrQ57WkHDeRD9t/PTQtmT0NHSeWWepj6pS0z/N7+08BHFDQVUrfmfMRcZwbMg==", "dev": true }, "punycode": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==" }, "qs": { "version": "6.15.0", "resolved": "https://registry.npmjs.org/qs/-/qs-6.15.0.tgz", "integrity": "sha512-mAZTtNCeetKMH+pSjrb76NAM8V9a05I9aBZOHztWy/UqcJdQYNsf59vrRKWnojAT9Y+GbIvoTBC++CPHqpDBhQ==", "requires": { "side-channel": "^1.1.0" } }, "raw-body": { "version": "2.5.3", "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.3.tgz", "integrity": "sha512-s4VSOf6yN0rvbRZGxs8Om5CWj6seneMwK3oDb4lWDH0UPhWcxwOWw5+qk24bxq87szX1ydrwylIOp2uG1ojUpA==", "requires": { "bytes": "~3.1.2", "http-errors": "~2.0.1", "iconv-lite": "~0.4.24", "unpipe": "~1.0.0" }, "dependencies": { "iconv-lite": { "version": "0.4.24", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", "requires": { "safer-buffer": ">= 2.1.2 < 3" } } } }, "resolve-path": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/resolve-path/-/resolve-path-1.4.0.tgz", "integrity": "sha512-i1xevIst/Qa+nA9olDxLWnLk8YZbi8R/7JPbCMcgyWaFR6bKWaexgJgEB5oc2PKMjYdrHynyz0NY+if+H98t1w==", "requires": { "http-errors": "~1.6.2", "path-is-absolute": "1.0.1" }, "dependencies": { "depd": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", "integrity": "sha512-7emPTl6Dpo6JRXOXjLRxck+FlLRX5847cLKEn00PLAgc3g2hTZZgr+e4c2v6QpSmLeFP3n5yUo7ft6avBK/5jQ==" }, "http-errors": { "version": "1.6.3", "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.6.3.tgz", "integrity": "sha512-lks+lVC8dgGyh97jxvxeYTWQFvh4uw4yC12gVl63Cg30sjPX4wuGcdkICVXDAESr6OJGjqGA8Iz5mkeN6zlD7A==", "requires": { "depd": "~1.1.2", "inherits": "2.0.3", "setprototypeof": "1.1.0", "statuses": ">= 1.4.0 < 2" } }, "inherits": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", "integrity": "sha512-x00IRNXNy63jwGkJmzPigoySHbaqpNuzKbBOmzK+g2OdZpQ9w+sxCN+VSB3ja7IAge2OP2qpfxTjeNcyjmW1uw==" }, "setprototypeof": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.0.tgz", "integrity": "sha512-BvE/TwpZX4FXExxOxZyRGQQv651MSwmWKZGqvmPcRIjDqWub67kTKuIMx43cZZrS/cBBzwBcNDWoFxt2XEFIpQ==" }, "statuses": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", "integrity": "sha512-OpZ3zP+jT1PI7I8nemJX4AKmAX070ZkYPVWV/AaKTJl+tXCTGyVdC1a4SL8RUQYEwk/f34ZX8UTykN68FwrqAA==" } } }, "safe-buffer": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==" }, "safe-regex-test": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/safe-regex-test/-/safe-regex-test-1.1.0.tgz", "integrity": "sha512-x/+Cz4YrimQxQccJf5mKEbIa1NzeCRNI5Ecl/ekmlYaampdNLPalVyIcCZNNH3MvmqBugV5TMYZXv0ljslUlaw==", "requires": { "call-bound": "^1.0.2", "es-errors": "^1.3.0", "is-regex": "^1.2.1" } }, "safer-buffer": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, "sax": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/sax/-/sax-1.5.0.tgz", "integrity": "sha512-21IYA3Q5cQf089Z6tgaUTr7lDAyzoTPx5HRtbhsME8Udispad8dC/+sziTNugOEx54ilvatQ9YCzl4KQLPcRHA==", "dev": true }, "seedrandom": { "version": "3.0.5", "resolved": "https://registry.npmjs.org/seedrandom/-/seedrandom-3.0.5.tgz", "integrity": "sha512-8OwmbklUNzwezjGInmZ+2clQmExQPvomqjL7LFqOYqtmuxRgQYqOD3mHaU+MvZn5FLUeVxVfQjwLZW/n/JFuqg==" }, "semver": { "version": "7.7.4", "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.4.tgz", "integrity": "sha512-vFKC2IEtQnVhpT78h1Yp8wzwrf8CM+MzKMHGJZfBtzhZNycRFnXsHk6E5TxIkkMsgNS7mdX3AGB7x2QM2di4lA==" }, "setprototypeof": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==" }, "shebang-command": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", "dev": true, "requires": { "shebang-regex": "^3.0.0" } }, "shebang-regex": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", "dev": true }, "side-channel": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.0.tgz", "integrity": "sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw==", "requires": { "es-errors": "^1.3.0", "object-inspect": "^1.13.3", "side-channel-list": "^1.0.0", "side-channel-map": "^1.0.1", "side-channel-weakmap": "^1.0.2" } }, "side-channel-list": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.0.tgz", "integrity": "sha512-FCLHtRD/gnpCiCHEiJLOwdmFP+wzCmDEkc9y7NsYxeF4u7Btsn1ZuwgwJGxImImHicJArLP4R0yX4c2KCrMrTA==", "requires": { "es-errors": "^1.3.0", "object-inspect": "^1.13.3" } }, "side-channel-map": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz", "integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==", "requires": { "call-bound": "^1.0.2", "es-errors": "^1.3.0", "get-intrinsic": "^1.2.5", "object-inspect": "^1.13.3" } }, "side-channel-weakmap": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz", "integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==", "requires": { "call-bound": "^1.0.2", "es-errors": "^1.3.0", "get-intrinsic": "^1.2.5", "object-inspect": "^1.13.3", "side-channel-map": "^1.0.1" } }, "smart-buffer": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.2.0.tgz", "integrity": "sha512-94hK0Hh8rPqQl2xXc3HsaBoOXKV20MToPkcXvwbISWLEs+64sBq5kFgn2kJDHb1Pry9yrP0dxrCI9RRci7RXKg==" }, "socks": { "version": "2.8.7", "resolved": "https://registry.npmjs.org/socks/-/socks-2.8.7.tgz", "integrity": "sha512-HLpt+uLy/pxB+bum/9DzAgiKS8CX1EvbWxI4zlmgGCExImLdiad2iCwXT5Z4c9c3Eq8rP2318mPW2c+QbtjK8A==", "requires": { "ip-address": "^10.0.1", "smart-buffer": "^4.2.0" } }, "source-map-js": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.1.tgz", "integrity": "sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==", "dev": true }, "sparse-bitfield": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/sparse-bitfield/-/sparse-bitfield-3.0.3.tgz", "integrity": "sha512-kvzhi7vqKTfkh0PZU+2D2PIllw2ymqJKujUcyPMd9Y75Nv4nPbGJZXNhxsgdQab2BmlDct1YnfQCguEvHr7VsQ==", "optional": true, "requires": { "memory-pager": "^1.0.2" } }, "sql.js": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/sql.js/-/sql.js-1.14.1.tgz", "integrity": "sha512-gcj8zBWU5cFsi9WUP+4bFNXAyF1iRpA3LLyS/DP5xlrNzGmPIizUeBggKa8DbDwdqaKwUcTEnChtd2grWo/x/A==", "dev": true }, "statuses": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz", "integrity": "sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw==" }, "strnum": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/strnum/-/strnum-2.2.0.tgz", "integrity": "sha512-Y7Bj8XyJxnPAORMZj/xltsfo55uOiyHcU2tnAVzHUnSJR/KsEX+9RoDeXEnsXtl/CX4fAcrt64gZ13aGaWPeBg==", "optional": true }, "style-mod": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/style-mod/-/style-mod-4.1.2.tgz", "integrity": "sha512-wnD1HyVqpJUI2+eKZ+eo1UwghftP6yuFheBqqe+bWCotBjC2K1YnteJILRMs3SM4V/0dLEW1SC27MWP5y+mwmw==", "dev": true }, "svgo": { "version": "3.3.3", "resolved": "https://registry.npmjs.org/svgo/-/svgo-3.3.3.tgz", "integrity": "sha512-+wn7I4p7YgJhHs38k2TNjy1vCfPIfLIJWR5MnCStsN8WuuTcBnRKcMHQLMM2ijxGZmDoZwNv8ipl5aTTen62ng==", "dev": true, "requires": { "commander": "^7.2.0", "css-select": "^5.1.0", "css-tree": "^2.3.1", "css-what": "^6.1.0", "csso": "^5.0.5", "picocolors": "^1.0.0", "sax": "^1.5.0" } }, "tailwindcss": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-4.2.1.tgz", "integrity": "sha512-/tBrSQ36vCleJkAOsy9kbNTgaxvGbyOamC30PRePTQe/o1MFwEKHQk4Cn7BNGaPtjp+PuUrByJehM1hgxfq4sw==", "dev": true }, "tapable": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/tapable/-/tapable-2.3.0.tgz", "integrity": "sha512-g9ljZiwki/LfxmQADO3dEY1CbpmXT5Hm2fJ+QaGKwSXUylMybePR7/67YW7jOrrvjEgL1Fmz5kzyAjWVWLlucg==", "dev": true }, "tinyglobby": { "version": "0.2.15", "resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.15.tgz", "integrity": "sha512-j2Zq4NyQYG5XMST4cbs02Ak8iJUdxRM0XI5QyxXuZOzKOINmWurp3smXu3y5wDcJrptwpSjgXHzIQxR0omXljQ==", "dev": true, "requires": { "fdir": "^6.5.0", "picomatch": "^4.0.3" }, "dependencies": { "fdir": { "version": "6.5.0", "resolved": "https://registry.npmjs.org/fdir/-/fdir-6.5.0.tgz", "integrity": "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg==", "dev": true, "requires": {} }, "picomatch": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.3.tgz", "integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==", "dev": true } } }, "toidentifier": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==" }, "tr46": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/tr46/-/tr46-3.0.0.tgz", "integrity": "sha512-l7FvfAHlcmulp8kr+flpQZmVwtu7nfRV7NZujtN0OqES8EL4O4e0qqzL0DC5gAvx/ZC/9lk6rhcUwYvkBnBnYA==", "requires": { "punycode": "^2.1.1" } }, "tslib": { "version": "2.8.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz", "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==", "optional": true }, "tsscmp": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/tsscmp/-/tsscmp-1.0.6.tgz", "integrity": "sha512-LxhtAkPDTkVCMQjt2h6eBVY28KCjikZqZfMcC15YBeNjkgUpdCfBu5HoiOTDu86v6smE8yOjyEktJ8hlbANHQA==" }, "type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", "integrity": "sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==", "dev": true, "requires": { "prelude-ls": "^1.2.1" } }, "type-is": { "version": "1.6.18", "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", "integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==", "requires": { "media-typer": "0.3.0", "mime-types": "~2.1.24" } }, "typescript": { "version": "5.9.3", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", "dev": true }, "typescript-eslint": { "version": "8.56.1", "resolved": "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-8.56.1.tgz", "integrity": "sha512-U4lM6pjmBX7J5wk4szltF7I1cGBHXZopnAXCMXb3+fZ3B/0Z3hq3wS/CCUB2NZBNAExK92mCU2tEohWuwVMsDQ==", "dev": true, "requires": { "@typescript-eslint/eslint-plugin": "8.56.1", "@typescript-eslint/parser": "8.56.1", "@typescript-eslint/typescript-estree": "8.56.1", "@typescript-eslint/utils": "8.56.1" }, "dependencies": { "@typescript-eslint/eslint-plugin": { "version": "8.56.1", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.56.1.tgz", "integrity": "sha512-Jz9ZztpB37dNC+HU2HI28Bs9QXpzCz+y/twHOwhyrIRdbuVDxSytJNDl6z/aAKlaRIwC7y8wJdkBv7FxYGgi0A==", "dev": true, "requires": { "@eslint-community/regexpp": "^4.12.2", "@typescript-eslint/scope-manager": "8.56.1", "@typescript-eslint/type-utils": "8.56.1", "@typescript-eslint/utils": "8.56.1", "@typescript-eslint/visitor-keys": "8.56.1", "ignore": "^7.0.5", "natural-compare": "^1.4.0", "ts-api-utils": "^2.4.0" } }, "@typescript-eslint/parser": { "version": "8.56.1", "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.56.1.tgz", "integrity": "sha512-klQbnPAAiGYFyI02+znpBRLyjL4/BrBd0nyWkdC0s/6xFLkXYQ8OoRrSkqacS1ddVxf/LDyODIKbQ5TgKAf/Fg==", "dev": true, "requires": { "@typescript-eslint/scope-manager": "8.56.1", "@typescript-eslint/types": "8.56.1", "@typescript-eslint/typescript-estree": "8.56.1", "@typescript-eslint/visitor-keys": "8.56.1", "debug": "^4.4.3" } }, "@typescript-eslint/scope-manager": { "version": "8.56.1", "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.56.1.tgz", "integrity": "sha512-YAi4VDKcIZp0O4tz/haYKhmIDZFEUPOreKbfdAN3SzUDMcPhJ8QI99xQXqX+HoUVq8cs85eRKnD+rne2UAnj2w==", "dev": true, "requires": { "@typescript-eslint/types": "8.56.1", "@typescript-eslint/visitor-keys": "8.56.1" } }, "@typescript-eslint/type-utils": { "version": "8.56.1", "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.56.1.tgz", "integrity": "sha512-yB/7dxi7MgTtGhZdaHCemf7PuwrHMenHjmzgUW1aJpO+bBU43OycnM3Wn+DdvDO/8zzA9HlhaJ0AUGuvri4oGg==", "dev": true, "requires": { "@typescript-eslint/types": "8.56.1", "@typescript-eslint/typescript-estree": "8.56.1", "@typescript-eslint/utils": "8.56.1", "debug": "^4.4.3", "ts-api-utils": "^2.4.0" } }, "@typescript-eslint/types": { "version": "8.56.1", "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.56.1.tgz", "integrity": "sha512-dbMkdIUkIkchgGDIv7KLUpa0Mda4IYjo4IAMJUZ+3xNoUXxMsk9YtKpTHSChRS85o+H9ftm51gsK1dZReY9CVw==", "dev": true }, "@typescript-eslint/typescript-estree": { "version": "8.56.1", "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.56.1.tgz", "integrity": "sha512-qzUL1qgalIvKWAf9C1HpvBjif+Vm6rcT5wZd4VoMb9+Km3iS3Cv9DY6dMRMDtPnwRAFyAi7YXJpTIEXLvdfPxg==", "dev": true, "requires": { "@typescript-eslint/project-service": "8.56.1", "@typescript-eslint/tsconfig-utils": "8.56.1", "@typescript-eslint/types": "8.56.1", "@typescript-eslint/visitor-keys": "8.56.1", "debug": "^4.4.3", "minimatch": "^10.2.2", "semver": "^7.7.3", "tinyglobby": "^0.2.15", "ts-api-utils": "^2.4.0" } }, "@typescript-eslint/utils": { "version": "8.56.1", "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.56.1.tgz", "integrity": "sha512-HPAVNIME3tABJ61siYlHzSWCGtOoeP2RTIaHXFMPqjrQKCGB9OgUVdiNgH7TJS2JNIQ5qQ4RsAUDuGaGme/KOA==", "dev": true, "requires": { "@eslint-community/eslint-utils": "^4.9.1", "@typescript-eslint/scope-manager": "8.56.1", "@typescript-eslint/types": "8.56.1", "@typescript-eslint/typescript-estree": "8.56.1" } }, "@typescript-eslint/visitor-keys": { "version": "8.56.1", "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.56.1.tgz", "integrity": "sha512-KiROIzYdEV85YygXw6BI/Dx4fnBlFQu6Mq4QE4MOH9fFnhohw6wX/OAvDY2/C+ut0I3RSPKenvZJIVYqJNkhEw==", "dev": true, "requires": { "@typescript-eslint/types": "8.56.1", "eslint-visitor-keys": "^5.0.0" } }, "balanced-match": { "version": "4.0.4", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-4.0.4.tgz", "integrity": "sha512-BLrgEcRTwX2o6gGxGOCNyMvGSp35YofuYzw9h1IMTRmKqttAZZVU67bdb9Pr2vUHA8+j3i2tJfjO6C6+4myGTA==", "dev": true }, "brace-expansion": { "version": "5.0.4", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.4.tgz", "integrity": "sha512-h+DEnpVvxmfVefa4jFbCf5HdH5YMDXRsmKflpf1pILZWRFlTbJpxeU55nJl4Smt5HQaGzg1o6RHFPJaOqnmBDg==", "dev": true, "requires": { "balanced-match": "^4.0.2" } }, "eslint-visitor-keys": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-5.0.1.tgz", "integrity": "sha512-tD40eHxA35h0PEIZNeIjkHoDR4YjjJp34biM0mDvplBe//mB+IHCqHDGV7pxF+7MklTvighcCPPZC7ynWyjdTA==", "dev": true }, "ignore": { "version": "7.0.5", "resolved": "https://registry.npmjs.org/ignore/-/ignore-7.0.5.tgz", "integrity": "sha512-Hs59xBNfUIunMFgWAbGX5cq6893IbWg4KnrjbYwX3tx0ztorVgTDA6B2sxf8ejHJ4wz8BqGUMYlnzNBer5NvGg==", "dev": true }, "minimatch": { "version": "10.2.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.2.4.tgz", "integrity": "sha512-oRjTw/97aTBN0RHbYCdtF1MQfvusSIBQM0IZEgzl6426+8jSC0nF1a/GmnVLpfB9yyr6g6FTqWqiZVbxrtaCIg==", "dev": true, "requires": { "brace-expansion": "^5.0.2" } }, "ts-api-utils": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-2.4.0.tgz", "integrity": "sha512-3TaVTaAv2gTiMB35i3FiGJaRfwb3Pyn/j3m/bfAvGe8FB7CF6u+LMYqYlDh7reQf7UNvoTvdfAqHGmPGOSsPmA==", "dev": true, "requires": {} } } }, "undici-types": { "version": "7.18.2", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.18.2.tgz", "integrity": "sha512-AsuCzffGHJybSaRrmr5eHr81mwJU3kjw6M+uprWvCXiNeN9SOGwQ3Jn8jb8m3Z6izVgknn1R0FTCEAP2QrLY/w==" }, "unpipe": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==" }, "uri-js": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", "integrity": "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==", "dev": true, "requires": { "punycode": "^2.1.0" } }, "vary": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==" }, "w3c-keyname": { "version": "2.2.8", "resolved": "https://registry.npmjs.org/w3c-keyname/-/w3c-keyname-2.2.8.tgz", "integrity": "sha512-dpojBhNsCNN7T82Tm7k26A6G9ML3NkhDsnw9n/eoxSRlVBB4CEtIQ/KTCLI2Fwf3ataSXRhYFkQi3SlnFwPvPQ==", "dev": true }, "webidl-conversions": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", "integrity": "sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==" }, "whatwg-url": { "version": "11.0.0", "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-11.0.0.tgz", "integrity": "sha512-RKT8HExMpoYx4igMiVMY83lN6UeITKJlBQ+vR/8ZJ8OCdSiN3RwCq+9gH0+Xzj0+5IrM6i4j/6LuvzbZIQgEcQ==", "requires": { "tr46": "^3.0.0", "webidl-conversions": "^7.0.0" } }, "which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", "dev": true, "requires": { "isexe": "^2.0.0" } }, "word-wrap": { "version": "1.2.5", "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz", "integrity": "sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==", "dev": true }, "yaml": { "version": "1.10.2", "resolved": "https://registry.npmjs.org/yaml/-/yaml-1.10.2.tgz", "integrity": "sha512-r3vXyErRCYJ7wg28yvBY5VSoAF8ZvlcW9/BwUzEtUsjvX/DKs24dIkuwjtuprwJJHsbyUbLApepYTR1BN4uHrg==", "dev": true }, "ylru": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/ylru/-/ylru-1.4.0.tgz", "integrity": "sha512-2OQsPNEmBCvXuFlIni/a+Rn+R2pHW9INm0BxXJ4hVDA8TirqMj+J/Rp9ItLatT/5pZqWwefVrTQcHpixsxnVlA==" }, "yocto-queue": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==", "dev": true } } } ================================================ FILE: package.json ================================================ { "name": "genieacs", "version": "1.3.0-dev", "description": "A TR-069 Auto Configuration Server (ACS)", "repository": { "type": "git", "url": "https://github.com/genieacs/genieacs.git" }, "homepage": "https://genieacs.com", "keywords": [ "TR-069", "CWMP", "ACS" ], "author": { "name": "GenieACS Inc.", "url": "https://genieacs.com" }, "license": "AGPL-3.0", "private": true, "bin": { "genieacs-cwmp": "bin/genieacs-cwmp", "genieacs-fs": "bin/genieacs-fs", "genieacs-nbi": "bin/genieacs-nbi", "genieacs-ui": "bin/genieacs-ui" }, "dependencies": { "@breejs/later": "^4.2.0", "@koa/bodyparser": "^5.1.2", "@koa/router": "^13.1.1", "bson": "^4.7.2", "espresso-iisojs": "^1.0.8", "iconv-lite": "^0.6.3", "ipaddr.js": "^2.3.0", "jsonwebtoken": "^9.0.3", "koa": "^2.16.4", "koa-compress": "^5.2.0", "koa-jwt": "^4.0.3", "koa-send": "^5.0.1", "mongodb": "^4.16.0", "seedrandom": "^3.0.5" }, "devDependencies": { "@codemirror/commands": "^6.10.2", "@codemirror/lang-javascript": "^6.2.5", "@codemirror/lang-yaml": "^6.1.2", "@codemirror/language": "^6.12.2", "@codemirror/state": "^6.5.4", "@codemirror/view": "^6.39.16", "@eslint/js": "^10.0.1", "@tailwindcss/cli": "^4.2.1", "@tailwindcss/forms": "^0.5.11", "@types/jsonwebtoken": "^9.0.10", "@types/koa": "^2.15.0", "@types/koa-compress": "^4.0.7", "@types/mithril": "^2.2.7", "@types/node": "^25.3.5", "@types/seedrandom": "^3.0.8", "esbuild": "^0.27.4", "eslint": "^10.0.3", "eslint-config-prettier": "^10.1.8", "globals": "^17.4.0", "mithril": "^2.3.8", "prettier": "^3.8.1", "sql.js": "^1.14.1", "svgo": "^3.3.3", "tailwindcss": "^4.2.1", "typescript": "^5.9.3", "typescript-eslint": "^8.56.1", "yaml": "^1.10.2" }, "engines": { "node": ">=12.13.0" }, "scripts": { "test": "esbuild build/test.ts --bundle --platform=node --target=node18 --packages=external | node && node --test --enable-source-maps test/*.js && rm test/*.js", "lint": "esbuild build/lint.ts --bundle --platform=node --target=node16 --packages=external | node", "build": "esbuild build/build.ts --bundle --platform=node --target=node12 --packages=external | node" } } ================================================ FILE: seed/bootstrap.js ================================================ const now = Date.now(); // Clear cached data model to force a refresh clear("Device", now); clear("InternetGatewayDevice", now); ================================================ FILE: seed/datamodel-explorer.jsx ================================================ // Interactive explorer for browsing and searching device data model parameters. // // Attributes: // device - Device object containing parameter data // // Example: // const device = node.attributes.device.get(); const deviceId = device["DeviceID.ID"]; const taskCmd = new Signal.State(null); const queryString = new Signal.State(""); const allKeys = []; for (const key of Object.keys(device)) { if (key.includes(":")) { if (key.endsWith(":object")) { const baseKey = key.slice(0, -7); const depth = baseKey.split(".").length - 1; while (allKeys.length <= depth) allKeys.push([]); allKeys[depth].push(baseKey); } continue; } const depth = key.split(".").length - 1; while (allKeys.length <= depth) allKeys.push([]); allKeys[depth].push(key); } const flatKeys = allKeys.flat(); const renderRow = (row) => { const writable = device[`${row}:writable`]; const object = device[`${row}:object`]; const isInstance = /\.[0-9]+$/.test(row); return ( {row} {!object && } {object && writable && ( )} ); }; const explorer = new Signal.Computed(() => { const query = queryString.get(); const regExp = query && new RegExp( query .split(" ") .filter(Boolean) .map((s) => s.replace(/[-[\]/{}()*+?.\\^$|]/g, "\\$&")) .join(".*"), "i", ); const filtered = regExp ? flatKeys.filter((k) => { const value = device[k]; if (!device[`${k}:object`] && !value) return false; return regExp.test(value ? `${k} ${value}` : k); }) : flatKeys; const sorted = filtered.sort().slice(0, 100); return ( <>
{sorted.map(renderRow)}
Displaying {sorted.length} of{" "} {filtered.length} parameters Download
); }); let debounceTimer = null; // @ts-expect-error: top-level return (script is wrapped in a function at runtime) return ( <>
{ clearTimeout(debounceTimer); debounceTimer = setTimeout( () => queryString.set(e.target.value), 500, ); }} placeholder="Search parameters" class="appearance-none border-0 block w-full px-4 py-3 border-stone-300 placeholder-stone-500 text-stone-900 focus:ring-cyan-500 text-sm rounded-t-lg font-mono focus:ring-2" /> {explorer}
); ================================================ FILE: seed/default.js ================================================ 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, }); ================================================ FILE: seed/device-page-tr098.jsx ================================================ // Device page for TR-098 (InternetGatewayDevice) data model. // // Displays device information, parameters, LAN hosts, faults, and data model. // Customize the 'parameters' array below to change displayed fields. // // Attributes: // device - Device object from the parent router const device = node.attributes.device.get(); const deviceId = device["DeviceID.ID"]; const taskCmd = new Signal.State(null); const deviceFaults = new Signal.State(null); const delCmd = new Signal.State(null); const delStatus = new Signal.State(null); const delMessage = new Signal.Computed(() => { const s = delStatus.get(); if (s === true) return { type: "success", message: "Deleted successfully" }; if (s instanceof Error) return { type: "error", message: s.message }; return null; }); const pingResult = new Signal.State(null); const pingDisplay = new Signal.Computed(() => { const r = pingResult.get(); if (r == null) return null; if (r instanceof Error) return "Error!"; if (typeof r === "number") return `${Math.trunc(r)} ms`; return "Unreachable"; }); const connectionUrl = device["InternetGatewayDevice.ManagementServer.ConnectionRequestURL"]; const hostIp = connectionUrl ? new URL(connectionUrl).hostname : null; // Device parameters to display const parameters = [ { label: "Serial number", param: "DeviceID.SerialNumber" }, { label: "Product class", param: "DeviceID.ProductClass" }, { label: "OUI", param: "DeviceID.OUI" }, { label: "Manufacturer", param: "DeviceID.Manufacturer" }, { label: "Hardware version", param: "InternetGatewayDevice.DeviceInfo.HardwareVersion", }, { label: "Software version", param: "InternetGatewayDevice.DeviceInfo.SoftwareVersion", }, { label: "MAC", param: "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.MACAddress", }, { label: "IP", param: "InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.ExternalIPAddress", }, { label: "WLAN SSID", param: "InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.SSID", }, { label: "WLAN passphrase", param: "InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.PreSharedKey.1.KeyPassphrase", }, ]; const hostsRoot = "InternetGatewayDevice.LANDevice.1.Hosts.Host"; const hostsColumns = [ { label: "Host name", param: "HostName" }, { label: "IP", param: "IPAddress" }, { label: "MAC", param: "MACAddress" }, ]; // Parameters to refresh when summoning the device const summonParams = [ ...parameters.map((p) => p.param).filter((p) => !p.startsWith("DeviceID.")), ...hostsColumns.map((c) => `${hostsRoot}.*.${c.param}`), ]; const parameterRows = parameters .filter(({ param }) => device[param]) .map(({ label, param }) => ( {label} )); const FIVE_MINUTES = 5 * 60 * 1000; const ONE_DAY = 24 * 60 * 60 * 1000; const informTime = device["Events.Inform"]; const now = Date.now(); const [onlineStatus, statusColor] = informTime > now - FIVE_MINUTES ? ["Online", "#31a354"] : informTime > now - FIVE_MINUTES - ONE_DAY ? ["Past 24 Hours", "#a1d99b"] : ["Others", "#e5f5e0"]; const faultsTable = new Signal.Computed(() => { const faults = deviceFaults.get(); if (!faults?.length) return ( No faults ); return faults.map((f) => { const yamlOut = new Signal.State(""); return ( {f.channel} {f.code} { e.target.title = f.message; }} > {f.message} { e.target.title = e.target.textContent; }} > {yamlOut} {f.retries} {new Date(f.timestamp).toLocaleString()} ); }); }); // @ts-expect-error: top-level return (script is wrapped in a function at runtime) return ( <>

{deviceId}

Pinging {hostIp}: {pingDisplay}
{parameterRows}
Last inform {onlineStatus}

LAN Hosts

{hostsColumns.map((c) => ( ))} '${deviceId}:' AND _id < '${deviceId}:\xff'`, }} res={deviceFaults} />

Faults

{faultsTable}
Channel Code Message Detail Retries Timestamp

Data model

{[ { label: "Reboot", title: "Reboot device", task: { name: "reboot", device: deviceId }, }, { label: "Reset", title: "Factory reset device", task: { name: "factoryReset", device: deviceId }, }, { label: "Push file", title: "Push a firmware or config file", task: { name: "download", devices: [deviceId] }, }, { label: "Delete", title: "Delete device", action: () => { if (confirm(`Delete device ${deviceId}?`)) delCmd.set({ resource: "devices", id: deviceId }); }, }, ].map(({ label, title, task: t, action }) => ( ))}
); ================================================ FILE: seed/device-page-tr181.jsx ================================================ // Device page for TR-181 (Device:2) data model. // // Displays device information, parameters, LAN hosts, faults, and data model. // Customize the 'parameters' array below to change displayed fields. // // Attributes: // device - Device object from the parent router const device = node.attributes.device.get(); const deviceId = device["DeviceID.ID"]; const taskCmd = new Signal.State(null); const deviceFaults = new Signal.State(null); const delCmd = new Signal.State(null); const delStatus = new Signal.State(null); const delMessage = new Signal.Computed(() => { const s = delStatus.get(); if (s === true) return { type: "success", message: "Deleted successfully" }; if (s instanceof Error) return { type: "error", message: s.message }; return null; }); const pingResult = new Signal.State(null); const pingDisplay = new Signal.Computed(() => { const r = pingResult.get(); if (r == null) return null; if (r instanceof Error) return "Error!"; if (typeof r === "number") return `${Math.trunc(r)} ms`; return "Unreachable"; }); const connectionUrl = device["Device.ManagementServer.ConnectionRequestURL"]; const hostIp = connectionUrl ? new URL(connectionUrl).hostname : null; // Device parameters to display const parameters = [ { label: "Serial number", param: "DeviceID.SerialNumber" }, { label: "Product class", param: "DeviceID.ProductClass" }, { label: "OUI", param: "DeviceID.OUI" }, { label: "Manufacturer", param: "DeviceID.Manufacturer" }, { label: "Hardware version", param: "Device.DeviceInfo.HardwareVersion", }, { label: "Software version", param: "Device.DeviceInfo.SoftwareVersion", }, { label: "MAC", param: "Device.Ethernet.Interface.1.MACAddress", }, { label: "IP", param: "Device.IP.Interface.1.IPv4Address.1.IPAddress", }, { label: "WLAN SSID", param: "Device.WiFi.SSID.1.SSID", }, { label: "WLAN passphrase", param: "Device.WiFi.AccessPoint.1.Security.KeyPassphrase", }, ]; const hostsRoot = "Device.Hosts.Host"; const hostsColumns = [ { label: "Host name", param: "HostName" }, { label: "IP", param: "IPAddress" }, { label: "MAC", param: "PhysAddress" }, ]; // Parameters to refresh when summoning the device const summonParams = [ ...parameters.map((p) => p.param).filter((p) => !p.startsWith("DeviceID.")), ...hostsColumns.map((c) => `${hostsRoot}.*.${c.param}`), ]; const parameterRows = parameters .filter(({ param }) => device[param]) .map(({ label, param }) => ( {label} )); const FIVE_MINUTES = 5 * 60 * 1000; const ONE_DAY = 24 * 60 * 60 * 1000; const informTime = device["Events.Inform"]; const now = Date.now(); const [onlineStatus, statusColor] = informTime > now - FIVE_MINUTES ? ["Online", "#31a354"] : informTime > now - FIVE_MINUTES - ONE_DAY ? ["Past 24 Hours", "#a1d99b"] : ["Others", "#e5f5e0"]; const faultsTable = new Signal.Computed(() => { const faults = deviceFaults.get(); if (!faults?.length) return ( No faults ); return faults.map((f) => { const yamlOut = new Signal.State(""); return ( {f.channel} {f.code} { e.target.title = f.message; }} > {f.message} { e.target.title = e.target.textContent; }} > {yamlOut} {f.retries} {new Date(f.timestamp).toLocaleString()} ); }); }); // @ts-expect-error: top-level return (script is wrapped in a function at runtime) return ( <>

{deviceId}

Pinging {hostIp}: {pingDisplay}
{parameterRows}
Last inform {onlineStatus}

LAN Hosts

{hostsColumns.map((c) => ( ))} '${deviceId}:' AND _id < '${deviceId}:\xff'`, }} res={deviceFaults} />

Faults

{faultsTable}
Channel Code Message Detail Retries Timestamp

Data model

{[ { label: "Reboot", title: "Reboot device", task: { name: "reboot", device: deviceId }, }, { label: "Reset", title: "Factory reset device", task: { name: "factoryReset", device: deviceId }, }, { label: "Push file", title: "Push a firmware or config file", task: { name: "download", devices: [deviceId] }, }, { label: "Delete", title: "Delete device", action: () => { if (confirm(`Delete device ${deviceId}?`)) delCmd.set({ resource: "devices", id: deviceId }); }, }, ].map(({ label, title, task: t, action }) => ( ))}
); ================================================ FILE: seed/device-page.jsx ================================================ // Router that delegates to the appropriate data model-specific device page. // // Automatically detects device data model (TR-098 or TR-181) and renders // the corresponding device page component. // // Attributes: // deviceId - Device identifier string const deviceId = node.attributes.deviceId.get(); const device = new Signal.State(null); const page = new Signal.Computed(() => { const dev = device.get()?.[0]; if (dev?.["Device:object"]) { return ; } else if (dev?.["InternetGatewayDevice:object"]) { return ; } }); // @ts-expect-error: top-level return (script is wrapped in a function at runtime) return ( <> {page} ); ================================================ FILE: seed/icon.jsx ================================================ // SVG icon library component. // // Attributes: // name - Icon name (see available icons below) // class - CSS classes to apply to the SVG element // // Available icons: // add, add-instance, close, delete-instance, edit, menu, // refresh, remove, retry, sorted-asc, sorted-dsc, unsorted // // Example: // const iconName = node.attributes.name.get(); const icons = { "add-instance": [ , , ], add: [], close: [], "delete-instance": [ , , ], edit: [], menu: [], refresh: [ , , ], remove: [], retry: [ , , , ], "sorted-asc": [], "sorted-dsc": [], unsorted: [], }; const content = icons[iconName]; // @ts-expect-error: top-level return (script is wrapped in a function at runtime) if (!content) return null; const attrs = { xmlns: "http://www.w3.org/2000/svg", fill: "none", stroke: "currentColor", "stroke-width": "2", class: node.attributes.class?.get(), "aria-hidden": "true", viewBox: "0 0 24 24", }; // @ts-expect-error: top-level return (script is wrapped in a function at runtime) return {content}; ================================================ FILE: seed/inform.js ================================================ // 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 }, ); ================================================ FILE: seed/instance-table.jsx ================================================ // Table component for displaying object instances with configurable columns. // // Attributes: // device - Device object containing parameter data // root - Object path to display instances from (e.g., "Device.Hosts.Host") // // Children: // elements defining columns: // label - Column header text // param - Parameter name relative to instance (e.g., "HostName") // // Example: // // // // const device = node.attributes.device.get(); const deviceId = device["DeviceID.ID"]; const root = node.attributes.root.get(); const taskCmd = new Signal.State(null); const columns = node.children .map((c) => c.get()) .filter((c) => c.name === "param") .map(({ attributes: { label, param } }) => ({ label, param })); const instances = [ ...new Set( Object.keys(device) .filter((k) => k.startsWith(`${root}.`) && !k.includes(":")) .map((k) => { const dot = k.indexOf(".", root.length + 1); return dot === -1 ? k : k.slice(0, dot); }), ), ]; // @ts-expect-error: top-level return (script is wrapped in a function at runtime) return ( <>
{columns.map(({ label }, i) => ( ))} {instances.length ? ( instances.map((inst) => ( {columns.map(({ param }, i) => ( ))} )) ) : ( )} {device[`${root}:writable`] && ( )}
{label}
{device[`${inst}:writable`] && ( )}
No instances
); ================================================ FILE: seed/overview-page.jsx ================================================ // Dashboard page displaying device online status statistics. // // This is the default overview page shown on the main dashboard. // Customize the pie chart slices below to show different device groupings. const FIVE_MINUTES = 5 * 60 * 1000; const ONE_DAY = 24 * 60 * 60 * 1000; // @ts-expect-error: top-level return (script is wrapped in a function at runtime) return (
NOW() - ${FIVE_MINUTES}`} /> NOW() - ${FIVE_MINUTES} - ${ONE_DAY} AND Events.Inform < NOW() - ${FIVE_MINUTES}`} />
); ================================================ FILE: seed/parameter.jsx ================================================ // Displays a device parameter value with optional inline editing. // // Attributes: // device - Device object containing parameter data // param - Parameter path (e.g., "DeviceID.SerialNumber") // // Example: // const device = node.attributes.device.get(); const deviceId = device["DeviceID.ID"]; const param = node.attributes.param.get(); const taskCmd = new Signal.State(null); const timeAgo = (ts) => { const units = [ { label: "year", ms: 31536000000 }, { label: "month", ms: 2592000000 }, { label: "day", ms: 86400000 }, { label: "hour", ms: 3600000 }, { label: "minute", ms: 60000 }, { label: "second", ms: 1000 }, ]; let diff = Date.now() - ts; const parts = []; for (const { label, ms } of units) { if (diff >= ms) { const n = Math.floor(diff / ms); diff %= ms; parts.push(`${n} ${label}${n > 1 ? "s" : ""}`); if (parts.length === 2) break; } } return `${new Date(ts).toLocaleString()} (${parts.join(" ")} ago)`; }; const value = device[param]; const type = device[`${param}:type`] || ""; const writable = device[`${param}:writable`]; const timestamp = device[`${param}:valueTimestamp`]; const displayValue = typeof value === "number" && type === "xsd:dateTime" ? new Date(value).toLocaleString() : String(value); // @ts-expect-error: top-level return (script is wrapped in a function at runtime) return ( <> timestamp && (e.target.title = timeAgo(timestamp))} > {displayValue} {writable && ( )} ); ================================================ FILE: seed/pie-chart.jsx ================================================ // Pie chart component that displays device counts by filter criteria. // // Attributes: // label - Chart title displayed above the pie chart // // Children: // elements with the following attributes: // label - Slice label shown in the legend // color - Fill color (e.g., "#31a354") // filter - Device filter expression for counting devices // // Example: // // // // const getCoordinates = (percent) => { const angle = 2 * Math.PI * percent; const x = Math.cos(angle) * 100; const y = Math.sin(angle) * 100; return [x, y]; }; const slices = node.children .map((c) => c.get()) .filter((c) => c.name === "slice") .map(({ attributes: { filter, label, color } }) => ({ count: new Signal.State(0), filter, label, color, })); const chart = new Signal.Computed(() => { let total = 0; let cumulative = 0; for (const slice of slices) total += slice.count.get(); const renderSlice = (slice) => { const percent = (slice.count.get() || 0) / total; const [startX, startY] = getCoordinates(cumulative); cumulative += percent; const [endX, endY] = getCoordinates(cumulative); const largeArc = percent > 0.5 ? 1 : 0; const d = ` M ${startX} ${startY} A 100 100 0 ${largeArc} 1 ${endX} ${endY} L 0 0 Z `; const midAngle = cumulative - percent / 2; const percentageX = Math.cos(2 * Math.PI * midAngle) * 50; const percentageY = Math.sin(2 * Math.PI * midAngle) * 50; return ( <> {Math.round(percent * 100)}% ); }; return ( <> {slices.map(renderSlice)} {slices.map((slice) => ( ))}
{slice.label} {Math.round((slice.count.get() * 100) / total) || 0}% {slice.count}
Total {total}
); }); // @ts-expect-error: top-level return (script is wrapped in a function at runtime) return (

{node.attributes.label}

{slices.map((s) => ( ))} {chart}
); ================================================ FILE: seed/provisions.d.ts ================================================ 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 { 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): 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; } ================================================ FILE: seed/summon-button.jsx ================================================ // Button that initiates a device session and refreshes parameters. // // Attributes: // deviceId - Device identifier string // params - Array of parameter paths to refresh (optional) // // Example: // const taskCmd = new Signal.State(null); const status = new Signal.State(null); const deviceId = node.attributes.deviceId.get(); // @ts-expect-error: top-level return (script is wrapped in a function at runtime) return ( <> { const s = status.get(); if (s === "stale" || s === "fault") return { type: "error", message: `${deviceId}: ${s}` }; if (s === "done") return { type: "success", message: `${deviceId}: Summoned` }; return null; }) } /> ); ================================================ FILE: seed/tags.jsx ================================================ // Displays and manages device tags with add/remove functionality. // // Attributes: // device - Device object containing tag data // writable - Whether to show add/remove buttons (default: true) // // Example: // const device = node.attributes.device.get(); const deviceId = device["DeviceID.ID"]; const tagCmd = new Signal.State(null); const writable = node.attributes.writable.get() ?? true; const tags = Object.keys(device) .filter((key) => key.startsWith("Tags.") && !key.includes(":")) .map((key) => decodeURIComponent(key.slice(5).replace(/0x(?=[0-9A-Z]{2})/g, "%")), ) .sort(); // @ts-expect-error: top-level return (script is wrapped in a function at runtime) return ( <> {tags.map((t) => ( {t} {writable && ( )} ))} {writable && ( )} ); ================================================ FILE: seed/tsconfig.json ================================================ { "compilerOptions": { "allowJs": true, "checkJs": true, "noEmit": true, "target": "ES2022", "jsx": "react", "jsxFactory": "h", "jsxFragmentFactory": "Fragment", "types": [], "moduleDetection": "force" }, "include": ["./*.js", "./*.jsx", "./*.d.ts"] } ================================================ FILE: seed/views.d.ts ================================================ interface Signal { get(): T; } interface StateSignal extends Signal { set(value: T): void; } // eslint-disable-next-line @typescript-eslint/no-empty-object-type interface ComputedSignal extends Signal {} // eslint-disable-next-line @typescript-eslint/no-empty-object-type interface ConstSignal extends Signal {} interface SignalConstructors { State: new (value: T) => StateSignal; Computed: new (callback: () => T) => ComputedSignal; Const: new (value: T) => ConstSignal; } declare const Signal: SignalConstructors; type ViewElement = ViewNode | string | number | Signal | ViewElement[]; declare class ViewNode { name: string | null; attributes: Record; children: ViewElement[]; } interface SignalizedViewNode { name: Signal; attributes: Record; children: Signal[]; } declare const node: SignalizedViewNode; declare function h( name: string | null, attributes: Record | null, ...children: ViewElement[] ): ViewNode; declare const Fragment: null; ================================================ FILE: test/auth.ts ================================================ import test from "node:test"; import assert from "node:assert"; import { randomBytes } from "node:crypto"; import * as auth from "../lib/auth.ts"; void test("digest", () => { const username = "test"; const password = "test"; const uri = "/"; const method = "POST"; const realm = "GeniceACS"; const nonce = randomBytes(16).toString("hex"); const body = randomBytes(128).toString(); const challenges = [ `Digest realm="${realm}",nonce="${nonce}"`, `Digest realm="${realm}",nonce="${nonce}",qop="auth"`, `Digest realm="${realm}",nonce="${nonce}",qop="auth-int"`, ]; for (const challenge of challenges) { const wwwAuthHeader = auth.parseWwwAuthenticateHeader(challenge); const solution = auth.solveDigest( username, password, uri, method, body, wwwAuthHeader, ); const authHeader = auth.parseAuthorizationHeader(solution); assert.strictEqual( authHeader["response"], auth.digest( username, realm, password, nonce, method, uri, authHeader["qop"], body, authHeader["cnonce"], authHeader["nc"], ), ); } }); ================================================ FILE: test/db.ts ================================================ import test from "node:test"; import assert from "node:assert"; import { EJSON } from "bson"; import { Filter } from "mongodb"; import Expression from "../lib/common/expression.ts"; import { convertOldPrecondition } from "../lib/db/util.ts"; import { toMongoQuery } from "../lib/db/synth.ts"; void test("convertOldPrecondition", () => { const tests = [ [{}, "TRUE"], [{ test: "test" }, 'test = "test"'], [{ test: { $eq: "test" } }, 'test = "test"'], [{ test: { $ne: "test" } }, 'test <> "test" OR test IS NULL'], [{ test: { $gte: "test" } }, 'test >= "test"'], [{ "Tags.test": true }, "Tags.test IS NOT NULL"], [{ "Tags.test": false }, "Tags.test IS NULL"], [{ "Tags.test": { $exists: true } }, "Tags.test IS NOT NULL"], [{ "Tags.test": { $exists: false } }, "Tags.test IS NULL"], [{ "Tags.test": { $ne: true } }, "Tags.test IS NULL"], [{ "Tags.test": { $ne: false } }, "Tags.test IS NOT NULL"], [{ "Tags.test": { $eq: true } }, "Tags.test IS NOT NULL"], [{ "Tags.test": { $eq: false } }, "Tags.test IS NULL"], [{ _tags: "test" }, "Tags.test IS NOT NULL"], [{ _tags: { $ne: "test" } }, "Tags.test IS NULL"], [{ _tags: { $eq: "test" } }, "Tags.test IS NOT NULL"], [ { $and: [{ test: "test" }, { test: { $ne: "test" } }] }, 'test = "test" AND (test <> "test" OR test IS NULL)', ], [{ test: "test", test2: "test2" }, 'test = "test" AND test2 = "test2"'], [ { $or: [{ test: "test" }, { test: { $ne: "test" } }] }, 'test = "test" OR test <> "test" OR test IS NULL', ], [ { test: { $gte: "test1", $ne: "test2" } }, 'test >= "test1" AND (test <> "test2" OR test IS NULL)', ], [ { test: "test", test2: { $ne: "test2" } }, 'test = "test" AND (test2 <> "test2" OR test2 IS NULL)', ], ]; const shouldFailTests = [ [{ test: { $gee: "test" } }, "Operator $gee not supported"], [{ test: [] }, "Invalid type"], [{ "Tags.test": { $gt: true } }, "Invalid tag query"], [{ _tags: [] }, "Invalid type"], [{ _tags: { $gt: "test" } }, "Invalid tag query"], [{ $nor: [] }, "Operator $nor not supported"], ] as [Filter, string][]; for (const t of tests) { assert.strictEqual( convertOldPrecondition(t[0] as Record).toString(), t[1], ); } for (const t of shouldFailTests) { const func = (): void => { convertOldPrecondition(t[0]); }; assert.throws(func, new Error(t[1])); } }); void test("toMongoQuery", async () => { const queries: [string, Filter | false][] = [ ["true", {}], ["Tags.tag1 = true", { _tags: { $eq: "tag1" } }], ["Tags.tag1 <> false", { _tags: { $eq: "tag1" } }], ["Tags.tag1 IS NULL", { _tags: { $ne: "tag1" } }], ["Tags.tag1 = 123", false], ["Param1 = 'value1'", { "Param1._value": { $eq: "value1" } }], [ "Param1 <> 'value1'", { "Param1._value": { $ne: "value1" }, $and: [{ "Param1._value": { $ne: null } }], }, ], [ "Param1 <> 1657844103524", { "Param1._value": { $ne: 1657844103524 }, $and: [ { "Param1._value": { $ne: { $date: "2022-07-15T00:15:03.524Z" } }, }, { "Param1._value": { $ne: null } }, ], }, ], [ "Param1 = 1657844103524", { $or: [ { "Param1._value": { $eq: { $date: "2022-07-15T00:15:03.524Z" } } }, { "Param1._value": { $eq: 1657844103524 } }, ], }, ], ["Param1 > 'value'", { "Param1._value": { $gt: "value" } }], ["Param1 IS NOT NULL", { "Param1._value": { $ne: null } }], [ "Param1 LIKE 'value'", { "Param1._value": { $regularExpression: { options: "s", pattern: "^value$" }, }, }, ], [ "LOWER(Param1) LIKE 'value'", { "Param1._value": { $regularExpression: { options: "is", pattern: "^value$" }, }, }, ], [ "Param1 <> 'value2' OR NOT (Param2 = 'value1' OR Param1 < 'value2')", { $or: [ { "Param2._value": { $ne: null }, $and: [{ "Param2._value": { $ne: "value1" } }], "Param1._value": { $eq: "value2" }, }, { "Param1._value": { $ne: "value2" }, $and: [{ "Param1._value": { $ne: null } }], }, ], }, ], [ "Param1 <> 'value2' OR Param1 IS NULL", { "Param1._value": { $ne: "value2" } }, ], ]; for (const [expStr, expect] of queries) { const exp = Expression.parse(expStr); let query = toMongoQuery(exp, "devices"); if (query) query = EJSON.serialize(query); assert.deepStrictEqual(query, expect); } const failQueries: [any, string][] = [ ["Param1 = Param2", "Right-hand operand must be a literal value"], ["Param1 LIKE Param2", "Right-hand operand of 'LIKE' must be a string"], ["NOW() = 1", "Left-hand operand must be a parameter"], ]; for (const [expStr, err] of failQueries) { const exp = Expression.parse(expStr); assert.throws(() => toMongoQuery(exp, "devices"), { message: err, }); } }); ================================================ FILE: test/device.ts ================================================ import test from "node:test"; import assert from "node:assert"; import Path from "../lib/common/path.ts"; import * as device from "../lib/device.ts"; import PathSet from "../lib/common/path-set.ts"; import VersionedMap from "../lib/versioned-map.ts"; import { Attributes } from "../lib/types.ts"; void test("getAliasDeclarations", () => { const path = Path.parse("a.[aa = 10 AND bb.[aaa = 100].cc = 1].b"); const decs = device.getAliasDeclarations(path, 99); const expected = ["a.*.b", "a.*.aa", "a.*.bb.*.cc", "a.*.bb.*.aaa"]; for (const [i, d] of decs.entries()) { assert.strictEqual(d.path.toString(), expected[i]); assert.strictEqual(d.pathGet, 99); assert.strictEqual(d.pathSet, null); assert.deepStrictEqual(d.attrGet, i ? { value: 99 } : null); assert.strictEqual(d.attrSet, null); assert.strictEqual(d.defer, true); } }); void test("unpack", () => { const now = Date.now(); const deviceData = { paths: new PathSet(), timestamps: new VersionedMap(), attributes: new VersionedMap(), trackers: new Map(), changes: new Set(), }; device.set(deviceData, "a.1.b", now, { value: [now, ["b", "xsd:string"]], }); device.set(deviceData, "a.1.c", now, { value: [now, ["c", "xsd:string"]], }); device.set(deviceData, "a.1.a.1.a", now, { value: [now, ["", "xsd:string"]], }); device.set(deviceData, "a.1.a.1.b", now, { value: [now, ["b1", "xsd:string"]], }); device.set(deviceData, "a.1.a.1.c", now, { value: [now, ["c1", "xsd:string"]], }); device.set(deviceData, "a.1.a.2.a", now, { value: [now, ["", "xsd:string"]], }); device.set(deviceData, "a.1.a.2.b", now, { value: [now, ["b2", "xsd:string"]], }); device.set(deviceData, "a.1.a.2.c", now, { value: [now, ["c2", "xsd:string"]], }); device.set(deviceData, "a.2.b", now, { value: [now, ["b", "xsd:string"]], }); device.set(deviceData, "a.2.c", now, { value: [now, ["c", "xsd:string"]], }); device.set(deviceData, "a.2.a.1.a", now, { value: [now, ["", "xsd:string"]], }); device.set(deviceData, "a.2.a.1.b", now, { value: [now, ["b1", "xsd:string"]], }); device.set(deviceData, "a.2.a.1.c", now, { value: [now, ["c1", "xsd:string"]], }); device.set(deviceData, "a.2.a.2.a", now, { value: [now, ["", "xsd:string"]], }); device.set(deviceData, "a.2.a.2.b", now, { value: [now, ["c1", "xsd:string"]], }); device.set(deviceData, "a.2.a.2.c", now, { value: [now, ["b1", "xsd:string"]], }); let unpacked: Path[]; unpacked = device.unpack( deviceData, Path.parse("a.[b='b' AND c='c'].a.[b='b1' AND c='c1'].a"), ); assert.strictEqual(unpacked.length, 2); assert.strictEqual(unpacked[0].toString(), "a.1.a.1.a"); assert.strictEqual(unpacked[1].toString(), "a.2.a.1.a"); unpacked = device.unpack( deviceData, Path.parse("a.*.a.[b='c1' AND c='b1'].a"), ); assert.strictEqual(unpacked.length, 1); assert.strictEqual(unpacked[0].toString(), "a.2.a.2.a"); }); ================================================ FILE: test/mocks/store.ts ================================================ // Mock implementation of ui/store.ts for testing (substituted via esbuild alias) import Expression from "../../lib/common/expression.ts"; // Provide window.clockSkew for reactive-store.ts in Node.js test environment if (typeof globalThis.window === "undefined") { (globalThis as any).window = { clockSkew: 0 }; } else { (globalThis.window as any).clockSkew = 0; } // Clock skew is always 0 in tests export function getClockSkew(): number { return 0; } // Mock request handler type type MockHandler = (options: XhrRequestOptions) => unknown | Promise; // Store mock handlers const mockHandlers: MockHandler[] = []; // Track all requests for test assertions interface RequestRecord { url: string; method: string; timestamp: number; } const requestLog: RequestRecord[] = []; // Options type matching mithril's RequestOptions interface XhrRequestOptions { url: string; method?: string; body?: unknown; extract?: (xhr: MockXhr) => unknown; deserialize?: (text: string) => unknown; background?: boolean; } // Mock XMLHttpRequest for extract functions interface MockXhr { status: number; responseText: string; getResponseHeader(name: string): string | null; } function parseQueryParams(url: string): Record { const params: Record = {}; const queryStart = url.indexOf("?"); if (queryStart === -1) return params; const queryString = url.slice(queryStart + 1); for (const pair of queryString.split("&")) { const [key, value] = pair.split("="); if (key && value !== undefined) { params[decodeURIComponent(key)] = decodeURIComponent(value); } } return params; } function evaluate( exp: Expression, obj: Record, timestamp: number, ): Expression { return exp.evaluate((e) => { if (e instanceof Expression.Literal) return e; else if (e instanceof Expression.FunctionCall) { if (e.name === "NOW") return new Expression.Literal(timestamp); } else if (e instanceof Expression.Parameter && obj) { let v = obj[e.path.toString()]; if (v == null) return new Expression.Literal(null); if (typeof v === "object") v = (v as Record)["value"]?.[0]; return new Expression.Literal(v as string | number | boolean | null); } return e; }); } function filterData(data: unknown[], filterStr: string | undefined): unknown[] { if (!filterStr) return data; const filterExpr = Expression.parse(filterStr); if (filterExpr == null) return data; const now = Date.now(); return data.filter((obj) => { const result = evaluate(filterExpr, obj as Record, now); return result instanceof Expression.Literal && !!result.value; }); } export async function xhrRequest(options: XhrRequestOptions): Promise { // Log the request requestLog.push({ url: options.url, method: options.method || "GET", timestamp: Date.now(), }); for (const handler of mockHandlers) { const result = handler(options); if (result !== undefined) { return result instanceof Promise ? result : Promise.resolve(result); } } // Default: return empty result based on method if (options.method === "HEAD") { if (options.extract) { const mockXhr: MockXhr = { status: 200, responseText: "", getResponseHeader: (name: string) => { if (name.toLowerCase() === "x-total-count") return "0"; return null; }, }; return options.extract(mockXhr); } return 0; } // GET returns empty array by default return []; } export function mockRegisterHandler(handler: MockHandler): void { mockHandlers.push(handler); } export function mockClearHandlers(): void { mockHandlers.length = 0; requestLog.length = 0; } export function mockGetRequestLog(): RequestRecord[] { return [...requestLog]; } export function mockClearRequestLog(): void { requestLog.length = 0; } export function mockUrlHandler( urlPattern: string | RegExp, response: unknown | ((options: XhrRequestOptions) => unknown), ): MockHandler { return (options: XhrRequestOptions) => { const matches = typeof urlPattern === "string" ? options.url.includes(urlPattern) : urlPattern.test(options.url); if (matches) { return typeof response === "function" ? response(options) : response; } return undefined; }; } export function mockCountHandler( urlPattern: string | RegExp, data: unknown[], delayMs = 0, ): MockHandler { return (options: XhrRequestOptions) => { if (options.method !== "HEAD") return undefined; const matches = typeof urlPattern === "string" ? options.url.includes(urlPattern) : urlPattern.test(options.url); if (matches && options.extract) { const params = parseQueryParams(options.url); const filtered = filterData(data, params.filter); const count = filtered.length; const mockXhr: MockXhr = { status: 200, responseText: "", getResponseHeader: (name: string) => { if (name.toLowerCase() === "x-total-count") return String(count); return null; }, }; if (delayMs > 0) { return new Promise((resolve) => { setTimeout(() => resolve(options.extract!(mockXhr)), delayMs); }); } return options.extract(mockXhr); } return undefined; }; } export function mockFetchHandler( urlPattern: string | RegExp, data: unknown[], delayMs = 0, ): MockHandler { return (options: XhrRequestOptions) => { if (options.method && options.method !== "GET") return undefined; const matches = typeof urlPattern === "string" ? options.url.includes(urlPattern) : urlPattern.test(options.url); if (matches) { const params = parseQueryParams(options.url); const filtered = filterData(data, params.filter); if (delayMs > 0) { return new Promise((resolve) => { setTimeout(() => resolve(filtered), delayMs); }); } return filtered; } return undefined; }; } ================================================ FILE: test/pagination.ts ================================================ import test from "node:test"; import assert from "node:assert"; import initSqlJs from "sql.js/dist/sql-asm.js"; import { bookmarkToExpression, paginate, toBookmark, } from "../lib/common/expression/pagination.ts"; import Expression from "../lib/common/expression.ts"; import { covers, minimize } from "../lib/common/expression/synth.ts"; const VALUES = [null, -1, false, "a"]; const PARAMS = ["param1", "param2"]; let db; async function query(filter: string): Promise<{ id: string }[]> { if (!db) { const sql = await initSqlJs(); db = new sql.Database(); db.run(`CREATE TABLE test (id INTEGER PRIMARY KEY, ${PARAMS.join(", ")})`); const stmt = db.prepare( `INSERT INTO test (${PARAMS.join(", ")}) VALUES (${PARAMS.map( () => "?", ).join(", ")})`, ); const count = VALUES.length ** PARAMS.length; for (let i = 0; i < count; ++i) { const values: (boolean | number | string)[] = []; for (let j = 0; j < PARAMS.length; ++j) values.push(VALUES[Math.trunc(i / VALUES.length ** j) % VALUES.length]); stmt.run(values); } stmt.free(); } const res = db.exec(`SELECT * FROM test WHERE ${filter}`); if (!res.length) return []; return res[0].values.map((row) => Object.fromEntries(row.map((v, i) => [res[0].columns[i], v])), ); } function getAllSortOrders(columns: string[]): Array> { const sortOrders: Array> = []; function generateOrders( remaining: string[], current: Record, ): void { if (remaining.length === 0) { sortOrders.push({ ...current }); return; } for (const column of remaining) { const newRemaining = remaining.filter((c) => c !== column); current[column] = -1; generateOrders(newRemaining, current); current[column] = 1; generateOrders(newRemaining, current); delete current[column]; } } generateOrders(columns, {}); return sortOrders; } async function testPaginate( q1: Expression, q2: Expression, sort: Record, ): Promise { const orderBy = Object.entries(sort) .map(([k, v]) => `${k} ${v > 0 ? "ASC" : "DESC"}`) .join(", "); const allMatches = await query(`${q2.toString()} ORDER BY ${orderBy}`); const [fulfilled, diff] = paginate(q1, q2, sort); assert.ok(covers(q1, fulfilled)); const fulfilledMatches = await query( `${fulfilled.toString()} ORDER BY ${orderBy}`, ); const diffMatches = await query(`${diff.toString()} ORDER BY ${orderBy}`); assert.deepStrictEqual(allMatches, [...fulfilledMatches, ...diffMatches]); if (allMatches.length === fulfilledMatches.length) return; const nextMatches = allMatches.slice( fulfilledMatches.length, fulfilledMatches.length + 1, ); const bookmark = toBookmark(sort, nextMatches[nextMatches.length - 1]); const bookmarkFilter = bookmarkToExpression(bookmark, sort); const capped = Expression.and(q2, bookmarkFilter); assert.ok(!covers(q1, capped)); const cappedMatches = await query( `(${capped.toString()}) ORDER BY ${orderBy}`, ); assert.deepStrictEqual(cappedMatches, [...fulfilledMatches, ...nextMatches]); const min = minimize(Expression.or(q1, capped)); await testPaginate(min, q2, sort); } void test("paginate", async () => { const cases: [string, string][] = [["param2 < 'a'", "param1 >= 'a'"]]; const params = ["id", ...PARAMS]; const sortOrders = getAllSortOrders(params); for (const [q1, q2] of cases) for (const sort of sortOrders) { await testPaginate(Expression.parse(q1), Expression.parse(q2), sort); } }); ================================================ FILE: test/path-set.ts ================================================ import test from "node:test"; import assert from "node:assert"; import Path from "../lib/common/path.ts"; import PathSet from "../lib/common/path-set.ts"; void test("add", () => { const pathSet = new PathSet(); pathSet.add("a"); pathSet.add("a"); assert.strictEqual( pathSet.findCompat(Path.parse("a"), true, true, 99).length, 1, ); }); void test("get", () => { const pathSet = new PathSet(); pathSet.add("a.*"); pathSet.add("a.a"); pathSet.add("*.*"); assert.strictEqual(pathSet.get("a.*").toString(), "a.*"); assert.equal(pathSet.get("*.a"), null); }); void test("find", () => { const pathSet = new PathSet(); pathSet.add("a"); pathSet.add("a.*"); pathSet.add("a.a"); pathSet.add("*.a"); pathSet.add("*.*"); assert.deepStrictEqual( pathSet.findCompat(Path.root, true, true, 1).map((p) => p.toString()), ["a"], ); assert.deepStrictEqual( pathSet.findCompat(Path.root, false, false, 2).map((p) => p.toString()), ["a", "a.*", "a.a", "*.a", "*.*"], ); assert.deepStrictEqual( pathSet .findCompat(Path.parse("a.*"), false, false) .map((p) => p.toString()), ["a.*"], ); assert.deepStrictEqual( pathSet.findCompat(Path.parse("a.*"), false, true).map((p) => p.toString()), ["a.*", "a.a"], ); assert.deepStrictEqual( pathSet.findCompat(Path.parse("a.*"), true, false).map((p) => p.toString()), ["a.*", "*.*"], ); assert.deepStrictEqual( pathSet.findCompat(Path.parse("a.*"), true, true).map((p) => p.toString()), ["a.*", "a.a", "*.a", "*.*"], ); }); ================================================ FILE: test/path.ts ================================================ import test from "node:test"; import assert from "node:assert"; import Path from "../lib/common/path.ts"; void test("parse", () => { assert.throws(() => Path.parse(".")); assert.throws(() => Path.parse("a ")); assert.throws(() => Path.parse(".a")); assert.throws(() => Path.parse("a.")); assert.throws(() => Path.parse("a..b")); assert.doesNotThrow(() => Path.parse("b*")); assert.doesNotThrow(() => Path.parse("*b")); assert.throws(() => Path.parse("a.b c.d")); assert.throws(() => Path.parse("a[")); assert.throws(() => Path.parse("a[b")); assert.throws(() => Path.parse("a[b:")); assert.throws(() => Path.parse('a[b:"waef]')); assert.doesNotThrow(() => Path.parse("*")); assert.throws(() => Path.parse("")); }); void test("toString", () => { const path1 = Path.parse('abc.[ abc=123 and def=" abc " ].123'); const path2 = Path.parse('abc.[abc = 123 AND def = " abc "].123'); assert.strictEqual(path1.toString(), path2.toString()); }); void test("slice", () => { const path = Path.parse(`a.*.b.[x = "y"].c`); const sliced = path.slice(1, -1); assert.strictEqual(sliced.toString(), '*.b.[x = "y"]'); assert.strictEqual(sliced.alias, 0b100); assert.strictEqual(sliced.wildcard, 0b1); const path2 = Path.parse("a.b:c.d"); // Trim from right into colon region assert.strictEqual(path2.slice(0, 3).toString(), "a.b:c"); assert.strictEqual(path2.slice(0, 3).colon, 1); // Trim from right past colon region assert.strictEqual(path2.slice(0, 2).toString(), "a.b"); assert.strictEqual(path2.slice(0, 2).colon, 0); // Start exactly at colon boundary (all-colon result) assert.strictEqual(path2.slice(2, 4).toString(), ":c.d"); assert.strictEqual(path2.slice(2, 4).colon, 2); // Start past colon boundary (colon dropped) assert.strictEqual(path2.slice(3, 4).toString(), "d"); assert.strictEqual(path2.slice(3, 4).colon, 0); // Span across boundary from both sides assert.strictEqual(path2.slice(1, 3).toString(), "b:c"); assert.strictEqual(path2.slice(1, 3).colon, 1); }); void test("concat", () => { // Alias and wildcard propagation const c0 = Path.parse("a").concat(Path.parse('*.[a = "b"]')); assert.strictEqual(c0.toString(), 'a.*.[a = "b"]'); assert.strictEqual(c0.alias, 0b100); assert.strictEqual(c0.wildcard, 0b10); // Left plain, right all-colon const allColon = Path.parse("a:b.c").slice(1, 3); const c1 = Path.parse("a.b").concat(allColon); assert.strictEqual(c1.toString(), "a.b:b.c"); assert.strictEqual(c1.colon, 2); // Left colon, right all-colon const c2 = Path.parse("a:b").concat(Path.parse("a.b:c.d").slice(2, 4)); assert.strictEqual(c2.toString(), "a:b.c.d"); assert.strictEqual(c2.colon, 3); // Both have mixed colon — should throw assert.throws(() => Path.parse("a:b").concat(Path.parse("c:d"))); }); void test("old alias format", () => { // Empty brackets const empty = Path.parse("a.[].b"); assert.strictEqual(empty.alias, 0b10); assert.strictEqual(empty.toString(), "a.[TRUE].b"); // Single key-value const single = Path.parse("a.[b:c].d"); assert.strictEqual(single.alias, 0b10); assert.strictEqual(single.toString(), 'a.[b = "c"].d'); // Multiple key-value pairs const multi = Path.parse("a.[b:1,c:2].d"); assert.strictEqual(multi.alias, 0b10); assert.strictEqual(multi.toString(), 'a.[b = "1" AND c = "2"].d'); // Key with empty value const emptyVal = Path.parse("a.[b:].d"); assert.strictEqual(emptyVal.toString(), 'a.[b = ""].d'); // Value containing colons (split on first : only) const colonVal = Path.parse("a.[b:c:d].e"); assert.strictEqual(colonVal.toString(), 'a.[b = "c:d"].e'); // Value containing spaces (trimmed) const spaceVal = Path.parse("a.[b:hello world].c"); assert.strictEqual(spaceVal.toString(), 'a.[b = "hello world"].c'); // Unquoted values are trimmed const trimmed = Path.parse("a.[b: hello ].c"); assert.strictEqual(trimmed.toString(), 'a.[b = "hello"].c'); // Whitespace around keys is trimmed const keySpace = Path.parse("a.[ b : c ].d"); assert.strictEqual(keySpace.toString(), 'a.[b = "c"].d'); // Equivalence with new format const oldFmt = Path.parse("x.[a:1,b:2].y"); const newFmt = Path.parse('x.[a = "1" AND b = "2"].y'); assert.strictEqual(oldFmt.toString(), newFmt.toString()); // Nested old-format alias const nested = Path.parse("a.[b.[x:1].c:2].d"); assert.strictEqual(nested.toString(), 'a.[b.[x = "1"].c = "2"].d'); // New SQL format still works const sql = Path.parse("a.[b = 1 AND c = 2].d"); assert.strictEqual(sql.toString(), "a.[b = 1 AND c = 2].d"); // Double-quoted value containing closing bracket const quotedBracket = Path.parse('a.[b:"hello]world"].c'); assert.strictEqual(quotedBracket.toString(), 'a.[b = "hello]world"].c'); // Double-quoted value containing comma const quotedComma = Path.parse('a.[b:"hello,world"].c'); assert.strictEqual(quotedComma.toString(), 'a.[b = "hello,world"].c'); // Double-quoted value with escape sequences (JSON semantics) const escaped = Path.parse('a.[b:"hello\\"world"].c'); assert.strictEqual(escaped.toString(), 'a.[b = "hello\\"world"].c'); // Single-quoted value const singleQuoted = Path.parse("a.[b:'value'].c"); assert.strictEqual(singleQuoted.toString(), 'a.[b = "value"].c'); // Invalid old format (no colon) still throws assert.throws(() => Path.parse("[abc]")); }); void test("slice concat round-trip", () => { const path = Path.parse("a.b:c.d"); // Round-trips at every split position up to and including the boundary for (let i = 1; i <= path.paramLength; i++) { const rejoined = path.slice(0, i).concat(path.slice(i)); assert.strictEqual(rejoined.toString(), path.toString()); assert.strictEqual(rejoined.colon, path.colon); } // Split inside the colon region: right half loses colon, // but concat still extends the left's attr region const left = path.slice(0, 3); const right = path.slice(3); assert.strictEqual(left.colon, 1); assert.strictEqual(right.colon, 0); const rejoined = left.concat(right); assert.strictEqual(rejoined.toString(), "a.b:c.d"); assert.strictEqual(rejoined.colon, 2); }); ================================================ FILE: test/ping.ts ================================================ import test from "node:test"; import assert from "node:assert"; import { parsePing } from "../lib/ping.ts"; void test("linux Case-1", () => { const platform = "linux"; const stdout = "PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data\n64 bytes from 8.8.8.8: icmp_seq=1 ttl=118 time=6.66 ms\n64 bytes from 8.8.8.8: icmp_seq=2 ttl=118 time=6.50 ms\n64 bytes from 8.8.8.8: icmp_seq=3 ttl=118 time=6.38 ms\n\n--- 8.8.8.8 ping statistics ---\n3 packets transmitted, 3 received, 0% packet loss, time 402ms\nrtt min/avg/max/mdev = 6.381/6.511/6.656/0.112 ms"; const parsedResult = { packetsTransmitted: 3, packetsReceived: 3, packetLoss: 0, min: 6.381, avg: 6.511, max: 6.656, mdev: 0.112, }; const parsed = parsePing(platform, stdout); assert.deepStrictEqual(parsedResult, parsed); }); void test("linux Case-2", () => { const platform = "linux"; const stdout = "PING 10.251.9.108 (10.251.9.108): 56 data bytes\n64 bytes from 10.251.9.108: icmp_seq=0 ttl=57 time=36.758 ms\n64 bytes from 10.251.9.108: icmp_seq=1 ttl=57 time=69.094 ms\n64 bytes from 10.251.9.108: icmp_seq=2 ttl=57 time=28.868 ms\n--- 10.251.9.108 ping statistics ---3 packets transmitted, 3 packets received, 0% packet loss\nround-trip min/avg/max/stddev = 28.868/44.907/69.094/17.404 ms"; const parsedResult = { packetsTransmitted: 3, packetsReceived: 3, packetLoss: 0, min: 28.868, avg: 44.907, max: 69.094, mdev: 17.404, }; const parsed = parsePing(platform, stdout); assert.deepStrictEqual(parsedResult, parsed); }); ================================================ FILE: test/reactive-store.ts ================================================ import test from "node:test"; import assert from "node:assert"; import { ComputedSignal } from "../ui/signals.ts"; import Expression from "../lib/common/expression.ts"; import { covers, subtract, areEquivalent, } from "../lib/common/expression/synth.ts"; // Import actual reactive-store exports (using mocked store.ts via esbuild plugin) import { fetch as reactiveStoreFetch, count as reactiveStoreCount, createBookmark as reactiveStoreCreateBookmark, invalidate, QuerySignal, Bookmark, } from "../ui/reactive-store.ts"; // Test-only exports added by build/test.ts plugin at build time import * as reactiveStore from "../ui/reactive-store.ts"; const compareFunction = (reactiveStore as Record)[ "_testCompareFunction" ] as (sort: Record) => (a: unknown, b: unknown) => number; const getObjectId = (reactiveStore as Record)[ "_testGetObjectId" ] as (resourceType: string, obj: unknown) => string; const applyDefaultSort = (reactiveStore as Record)[ "_testApplyDefaultSort" ] as ( resourceType: string, sort?: Record, ) => Record; const stores = (reactiveStore as Record)["_testStores"] as Map< string, unknown >; const getStore = (reactiveStore as Record)[ "_testGetStore" ] as (resource: string) => unknown; interface FetchedRegion { filter: Expression; timestamp: number; filterStr: string; } interface ResourceCache { objects: Map; counts: Map; bookmarks: Map; fetchedRegions: FetchedRegion[]; } function getCacheState(resource: string): { objectCount: number; regionCount: number; regions: Array<{ filter: Expression; timestamp: number }>; fetchQueryCount: number; } { const store = getStore(resource); const cache = (store as { cache: ResourceCache }).cache; const fetchQueries = ( store as { fetchQueries: Map< string, { weakRef: globalThis.WeakRef> } >; } ).fetchQueries; let activeFetchQueries = 0; for (const [, entry] of fetchQueries) { if (entry.weakRef.deref()) activeFetchQueries++; } return { objectCount: cache.objects.size, regionCount: cache.fetchedRegions.length, regions: cache.fetchedRegions.map((r) => ({ filter: r.filter, timestamp: r.timestamp, })), fetchQueryCount: activeFetchQueries, }; } function clearStores(): void { stores.clear(); } function forcePruneCache(resource: string): void { const store = getStore(resource); (store as { pruneCache: () => void }).pruneCache(); } // Import mock utilities for controlling xhrRequest behavior in tests import { mockRegisterHandler, mockClearHandlers, mockFetchHandler, mockCountHandler, mockGetRequestLog, mockClearRequestLog, } from "./mocks/store.ts"; // ============================================================================= // compareFunction Tests // ============================================================================= void test("compareFunction sorts by multiple fields with mixed asc/desc", () => { const sort = { category: 1, priority: -1, name: 1 }; const compare = compareFunction(sort); const items = [ { category: "b", priority: 1, name: "z" }, { category: "a", priority: 2, name: "y" }, { category: "a", priority: 2, name: "x" }, { category: "a", priority: 1, name: "w" }, ]; items.sort(compare); assert.deepStrictEqual(items, [ { category: "a", priority: 2, name: "x" }, { category: "a", priority: 2, name: "y" }, { category: "a", priority: 1, name: "w" }, { category: "b", priority: 1, name: "z" }, ]); }); void test("compareFunction handles DeviceID.ID nested value objects", () => { const sort = { "DeviceID.ID": 1 }; const compare = compareFunction(sort); const items = [ { "DeviceID.ID": { value: ["device-c"] } }, { "DeviceID.ID": { value: ["device-a"] } }, { "DeviceID.ID": {} }, // missing value array treated as null { "DeviceID.ID": { value: ["device-b"] } }, ]; items.sort(compare); // null/missing comes first due to type weight ordering assert.strictEqual( (items[0]["DeviceID.ID"] as { value?: string[] }).value, undefined, ); assert.strictEqual( (items[1]["DeviceID.ID"] as { value: string[] }).value[0], "device-a", ); }); void test("compareFunction handles mixed types with correct ordering", () => { const sort = { value: 1 }; const compare = compareFunction(sort); // Test that type weights work: null=1, number=2, string=3 const items = [{ value: "z" }, { value: 5 }, { value: null }]; items.sort(compare); assert.strictEqual(items[0].value, null); assert.strictEqual(items[1].value, 5); assert.strictEqual(items[2].value, "z"); }); // ============================================================================= // getObjectId Tests // ============================================================================= void test("getObjectId extracts correct ID based on resource type", () => { const device = { "DeviceID.ID": "device-123", _id: "should-not-use", }; const preset = { _id: "preset-123", name: "My Preset" }; assert.strictEqual(getObjectId("devices", device), "device-123"); assert.strictEqual(getObjectId("presets", preset), "preset-123"); assert.strictEqual(getObjectId("faults", {}), ""); }); // ============================================================================= // applyDefaultSort Tests // ============================================================================= void test("applyDefaultSort adds correct default key without overriding", () => { assert.deepStrictEqual(applyDefaultSort("devices"), { "DeviceID.ID": 1 }); assert.deepStrictEqual(applyDefaultSort("presets"), { _id: 1 }); assert.deepStrictEqual(applyDefaultSort("devices", { name: -1 }), { name: -1, "DeviceID.ID": 1, }); assert.deepStrictEqual(applyDefaultSort("devices", { "DeviceID.ID": -1 }), { "DeviceID.ID": -1, }); // Does not mutate original const original = { name: 1 }; applyDefaultSort("devices", original); assert.deepStrictEqual(original, { name: 1 }); }); // ============================================================================= // QuerySignal Tests // ============================================================================= void test("QuerySignal state management and disposal", () => { const signal = new QuerySignal(0); let state = signal.get(); assert.strictEqual(state.value, 0); assert.strictEqual(state.timestamp, 0); assert.strictEqual(state.loading, true); const now = Date.now(); signal._update(42, now, false); state = signal.get(); assert.strictEqual(state.value, 42); assert.strictEqual(state.loading, false); const stateBefore = signal.get(); signal._update(42, now, false); assert.strictEqual(signal.get(), stateBefore); signal[Symbol.dispose](); assert.throws(() => signal.get(), { message: "Cannot read disposed signal" }); signal[Symbol.dispose](); // Double disposal is safe }); void test("QuerySignal registers dependency when read by ComputedSignal", () => { const querySignal = new QuerySignal(0); let computeCount = 0; const computed = new ComputedSignal(() => { computeCount++; return querySignal.get().value * 2; }); assert.strictEqual(computed.get(), 0); assert.strictEqual(computeCount, 1); querySignal._update(21, Date.now(), false); assert.strictEqual(computed.get(), 42); assert.strictEqual(computeCount, 2); }); // ============================================================================= // fetch() Tests // ============================================================================= void test("fetch() returns QuerySignal and populates data", async () => { mockClearHandlers(); const testData = [ { _id: "preset-1", name: "First Preset" }, { _id: "preset-2", name: "Second Preset" }, ]; mockRegisterHandler(mockFetchHandler("api/presets/", testData)); const filter: Expression = new Expression.Literal(true); const signal = reactiveStoreFetch("presets", filter); assert.ok(signal instanceof QuerySignal); await new Promise((resolve) => setTimeout(resolve, 50)); const state = signal.get(); assert.strictEqual(state.loading, false); assert.strictEqual(state.value.length, 2); assert.strictEqual((state.value[0] as { _id: string })._id, "preset-1"); }); void test("fetch() applies default sort based on resource type", async () => { mockClearHandlers(); const deviceData = [ { "DeviceID.ID": { value: ["device-b"] } }, { "DeviceID.ID": { value: ["device-a"] } }, ]; mockRegisterHandler(mockFetchHandler("api/devices/", deviceData)); const signal = reactiveStoreFetch("devices", new Expression.Literal(true)); await new Promise((resolve) => setTimeout(resolve, 50)); const state = signal.get(); assert.strictEqual(state.value.length, 2); const firstDevice = state.value[0] as { "DeviceID.ID": { value: string[] }; }; assert.strictEqual(firstDevice["DeviceID.ID"].value[0], "device-a"); }); void test("fetch() returns same signal for same query", () => { mockClearHandlers(); const testData = [ { _id: "fault-1", type: "test" }, { _id: "fault-2", type: "other" }, { _id: "fault-3", type: "test" }, ]; mockRegisterHandler(mockFetchHandler("api/faults/", testData)); const filter: Expression = Expression.parse('type = "test"'); const signal1 = reactiveStoreFetch("faults", filter); const signal2 = reactiveStoreFetch("faults", filter); assert.strictEqual(signal1, signal2); }); void test("fetch() with custom sort option", async () => { mockClearHandlers(); const testData = [ { _id: "3", priority: 1 }, { _id: "1", priority: 3 }, { _id: "2", priority: 2 }, ]; mockRegisterHandler(mockFetchHandler("api/faults/", testData)); const signal = reactiveStoreFetch("faults", new Expression.Literal(true), { sort: { priority: -1 }, }); await new Promise((resolve) => setTimeout(resolve, 50)); const state = signal.get(); assert.strictEqual((state.value[0] as { priority: number }).priority, 3); assert.strictEqual((state.value[1] as { priority: number }).priority, 2); assert.strictEqual((state.value[2] as { priority: number }).priority, 1); }); void test("fetch() filters data correctly", async () => { mockClearHandlers(); clearStores(); const testData = [ { _id: "task-1", status: "pending", priority: 1 }, { _id: "task-2", status: "completed", priority: 2 }, { _id: "task-3", status: "pending", priority: 3 }, { _id: "task-4", status: "completed", priority: 1 }, { _id: "task-5", status: "pending", priority: 2 }, ]; mockRegisterHandler(mockFetchHandler("api/faults/", testData)); const filter: Expression = Expression.parse('status = "pending"'); const signal = reactiveStoreFetch("faults", filter); await new Promise((resolve) => setTimeout(resolve, 50)); const state = signal.get(); assert.strictEqual(state.value.length, 3, "Should return 3 pending tasks"); assert.ok( state.value.every( (item) => (item as { status: string }).status === "pending", ), "All returned items should have status 'pending'", ); const ids = state.value.map((item) => (item as { _id: string })._id).sort(); assert.deepStrictEqual(ids, ["task-1", "task-3", "task-5"]); }); // ============================================================================= // count() Tests // ============================================================================= void test("count() returns QuerySignal with count value", async () => { mockClearHandlers(); const testData = Array.from({ length: 42 }, (_, i) => ({ _id: `preset-${i}`, name: `Preset ${i}`, active: i < 15, })); mockRegisterHandler(mockCountHandler("api/presets/", testData)); const filter: Expression = Expression.parse("active = true"); const signal = reactiveStoreCount("presets", filter); assert.ok(signal instanceof QuerySignal); await new Promise((resolve) => setTimeout(resolve, 50)); const state = signal.get(); assert.strictEqual(state.loading, false); assert.strictEqual(state.value, 15); }); void test("count() returns same signal for same query", () => { mockClearHandlers(); const testData = [ ...Array.from({ length: 10 }, (_, i) => ({ _id: `ui.config-${i}` })), ...Array.from({ length: 5 }, (_, i) => ({ _id: `api.config-${i}` })), ]; mockRegisterHandler(mockCountHandler("api/config/", testData)); const filter: Expression = Expression.parse('_id LIKE "ui.%"'); const signal1 = reactiveStoreCount("config", filter); const signal2 = reactiveStoreCount("config", filter); assert.strictEqual(signal1, signal2); }); // ============================================================================= // createBookmark() Tests // ============================================================================= void test("createBookmark() returns QuerySignal with Bookmark", async () => { mockClearHandlers(); const rowAtOffset = [{ _id: "preset-5", name: "Fifth" }]; mockRegisterHandler(mockFetchHandler("api/presets/", rowAtOffset)); const filter: Expression = new Expression.Literal(true); const sort = { _id: 1 }; const signal = reactiveStoreCreateBookmark("presets", filter, sort, 5); assert.ok(signal instanceof QuerySignal); await new Promise((resolve) => setTimeout(resolve, 50)); const state = signal.get(); assert.strictEqual(state.loading, false); assert.ok(state.value instanceof Bookmark); }); void test("createBookmark() returns null when offset is beyond result count", async () => { mockClearHandlers(); mockRegisterHandler(mockFetchHandler("api/presets/", [])); const filter: Expression = new Expression.Literal(true); const sort = { _id: 1 }; const signal = reactiveStoreCreateBookmark("presets", filter, sort, 1000); await new Promise((resolve) => setTimeout(resolve, 50)); const state = signal.get(); assert.strictEqual(state.loading, false); assert.strictEqual(state.value, null); }); void test("Bookmark.applySkip() and applyLimit() modify filter correctly", async () => { mockClearHandlers(); const rowAtOffset = [{ _id: "preset-10", active: true }]; mockRegisterHandler(mockFetchHandler("api/presets/", rowAtOffset)); const filter: Expression = Expression.parse("active = true"); const sort = { _id: 1 }; const signal = reactiveStoreCreateBookmark("presets", filter, sort, 10); await new Promise((resolve) => setTimeout(resolve, 50)); const state = signal.get(); assert.ok(state.value instanceof Bookmark); const skipFilter = state.value!.applySkip(filter); assert.ok( skipFilter instanceof Expression, "skipFilter should be an Expression", ); // applySkip returns AND(filter, bookmarkCondition) assert.ok( skipFilter instanceof Expression.Binary && skipFilter.operator === "AND", "skipFilter should be an AND expression", ); const limitFilter = state.value!.applyLimit(filter); assert.ok( limitFilter instanceof Expression, "limitFilter should be an Expression", ); // applyLimit returns AND(filter, NOT(bookmarkCondition)) assert.ok( limitFilter instanceof Expression.Binary && limitFilter.operator === "AND", "limitFilter should be an AND expression", ); }); // ============================================================================= // Caching Tests - fetch() results caching // ============================================================================= void test("fetch() uses cached data without making new request", async () => { mockClearHandlers(); const testData = [ { _id: "item-1", name: "First" }, { _id: "item-2", name: "Second" }, ]; mockRegisterHandler(mockFetchHandler("api/provisions/", testData)); const filter: Expression = new Expression.Literal(true); const signal1 = reactiveStoreFetch("provisions", filter); await new Promise((resolve) => setTimeout(resolve, 50)); const state1 = signal1.get(); assert.strictEqual(state1.loading, false); assert.strictEqual(state1.value.length, 2); mockClearRequestLog(); const signal2 = reactiveStoreFetch("provisions", filter); assert.strictEqual(signal1, signal2); const log = mockGetRequestLog(); assert.strictEqual( log.length, 0, "Should not make new request for cached query", ); }); void test("fetch() with freshness=0 uses cached objects without refetch", async () => { mockClearHandlers(); const testData = [ { _id: "cached-1", value: "original" }, { _id: "cached-2", value: "original" }, ]; mockRegisterHandler(mockFetchHandler("api/config/", testData)); const signal1 = reactiveStoreFetch("config", new Expression.Literal(true)); await new Promise((resolve) => setTimeout(resolve, 50)); const state1 = signal1.get(); assert.strictEqual(state1.value.length, 2); mockClearRequestLog(); const filter2: Expression = Expression.parse('_id = "cached-1"'); const signal2 = reactiveStoreFetch("config", filter2, { freshness: 0 }); await new Promise((resolve) => setTimeout(resolve, 50)); const state2 = signal2.get(); assert.strictEqual(state2.value.length, 1); assert.strictEqual((state2.value[0] as { _id: string })._id, "cached-1"); }); // ============================================================================= // Stale Data Tests - show old data while fetching new data // ============================================================================= void test("fetch() shows stale data with loading=true while fetching fresh data", async () => { mockClearHandlers(); const staleData = [{ _id: "stale-item", name: "Stale Data" }]; const freshData = [ { _id: "stale-item", name: "Fresh Data" }, { _id: "new-item", name: "New Item" }, ]; mockRegisterHandler(mockFetchHandler("api/users/", staleData)); const filter: Expression = new Expression.Literal(true); const signal = reactiveStoreFetch("users", filter); await new Promise((resolve) => setTimeout(resolve, 50)); const staleState = signal.get(); assert.strictEqual(staleState.loading, false); assert.strictEqual(staleState.value.length, 1); const staleTimestamp = staleState.timestamp; mockClearHandlers(); mockRegisterHandler(mockFetchHandler("api/users/", freshData, 100)); const futureTimestamp = Date.now() + 100000; const signal2 = reactiveStoreFetch("users", filter, { freshness: futureTimestamp, }); assert.strictEqual(signal, signal2); const loadingState = signal.get(); assert.strictEqual( loadingState.loading, true, "Should be loading while fetching fresh data", ); assert.strictEqual( loadingState.value.length, 1, "Should show stale data while loading", ); assert.strictEqual( loadingState.timestamp, staleTimestamp, "Timestamp should be from stale data", ); await new Promise((resolve) => setTimeout(resolve, 150)); const freshState = signal.get(); assert.strictEqual( freshState.loading, false, "Should not be loading after fetch completes", ); assert.strictEqual(freshState.value.length, 2, "Should have fresh data"); assert.ok( freshState.timestamp > staleTimestamp, "Timestamp should be updated", ); }); void test("count() shows stale count with loading=true while fetching fresh count", async () => { mockClearHandlers(); const staleData = Array.from({ length: 10 }, (_, i) => ({ _id: `perm-${i}`, })); mockRegisterHandler(mockCountHandler("api/permissions/", staleData)); const filter: Expression = new Expression.Literal(true); const signal = reactiveStoreCount("permissions", filter); await new Promise((resolve) => setTimeout(resolve, 50)); const staleState = signal.get(); assert.strictEqual(staleState.loading, false); assert.strictEqual(staleState.value, 10); const staleTimestamp = staleState.timestamp; mockClearHandlers(); const freshData = Array.from({ length: 25 }, (_, i) => ({ _id: `perm-${i}`, })); mockRegisterHandler(mockCountHandler("api/permissions/", freshData, 100)); const futureTimestamp = Date.now() + 100000; const signal2 = reactiveStoreCount("permissions", filter, { freshness: futureTimestamp, }); assert.strictEqual(signal, signal2); const loadingState = signal.get(); assert.strictEqual( loadingState.loading, true, "Should be loading while fetching fresh count", ); assert.strictEqual( loadingState.value, 10, "Should show stale count while loading", ); await new Promise((resolve) => setTimeout(resolve, 150)); const freshState = signal.get(); assert.strictEqual( freshState.loading, false, "Should not be loading after fetch completes", ); assert.strictEqual(freshState.value, 25, "Should have fresh count"); assert.ok( freshState.timestamp > staleTimestamp, "Timestamp should be updated", ); }); // ============================================================================= // Partial Data / Overlapping Query Tests // ============================================================================= void test("fetch() fetches only missing data for partially covered query", async () => { mockClearHandlers(); clearStores(); const allData = [ { _id: "file-1", region: "A" }, { _id: "file-2", region: "A" }, { _id: "file-3", region: "B" }, { _id: "file-4", region: "B" }, ]; mockRegisterHandler(mockFetchHandler("api/files/", allData)); const filterA: Expression = Expression.parse('region = "A"'); const signalA = reactiveStoreFetch("files", filterA); await new Promise((resolve) => setTimeout(resolve, 50)); const stateA = signalA.get(); assert.strictEqual(stateA.value.length, 2); assert.ok( stateA.value.every((item) => (item as { region: string }).region === "A"), ); mockClearRequestLog(); const filterB: Expression = Expression.parse('region = "B"'); const signalB = reactiveStoreFetch("files", filterB); await new Promise((resolve) => setTimeout(resolve, 50)); const stateB = signalB.get(); assert.strictEqual(stateB.value.length, 2); assert.ok( stateB.value.every((item) => (item as { region: string }).region === "B"), ); const log = mockGetRequestLog(); assert.ok(log.length > 0, "Should make request for uncached region"); }); void test("overlapping queries use and share cached objects", async () => { mockClearHandlers(); const allItems = [ { _id: "shared-1", type: "X", priority: 1 }, { _id: "shared-2", type: "X", priority: 2 }, { _id: "shared-3", type: "Y", priority: 1 }, { _id: "shared-4", type: "Y", priority: 2 }, ]; mockRegisterHandler(mockFetchHandler("api/permissions/", allItems)); const signalAll = reactiveStoreFetch( "permissions", new Expression.Literal(true), ); await new Promise((resolve) => setTimeout(resolve, 50)); const stateAll = signalAll.get(); assert.strictEqual(stateAll.value.length, 4); mockClearRequestLog(); // Subset queries should use cached objects const filterX: Expression = Expression.parse('type = "X"'); const signalX = reactiveStoreFetch("permissions", filterX, { freshness: 0 }); const filterP1: Expression = Expression.parse("priority = 1"); const signalP1 = reactiveStoreFetch("permissions", filterP1, { freshness: 0, }); await new Promise((resolve) => setTimeout(resolve, 50)); const stateX = signalX.get(); const stateP1 = signalP1.get(); // Verify filtering works correctly assert.strictEqual(stateX.value.length, 2); assert.ok( stateX.value.every((item) => (item as { type: string }).type === "X"), "All items should have type X", ); assert.strictEqual(stateP1.value.length, 2); assert.ok( stateP1.value.every( (item) => (item as { priority: number }).priority === 1, ), "All items should have priority 1", ); // Verify same object reference is shared across queries const itemFromX = stateX.value.find( (i) => (i as { _id: string })._id === "shared-1", ); const itemFromP1 = stateP1.value.find( (i) => (i as { _id: string })._id === "shared-1", ); assert.strictEqual( itemFromX, itemFromP1, "Same cached object should be shared across queries", ); }); // ============================================================================= // Non-Overlapping FetchedRegions Tests // ============================================================================= void test("fetching subset with newer timestamp replaces overlapping region", async () => { mockClearHandlers(); clearStores(); const resource = "views"; const allData = [ { _id: "item-1", category: "X" }, { _id: "item-2", category: "X" }, { _id: "item-3", category: "Y" }, ]; mockRegisterHandler(mockFetchHandler(`api/${resource}/`, allData)); const signalAll = reactiveStoreFetch(resource, new Expression.Literal(true)); await new Promise((resolve) => setTimeout(resolve, 50)); let state = getCacheState(resource); assert.strictEqual( state.regionCount, 1, "Should have 1 region after first fetch", ); assert.strictEqual(state.objectCount, 3, "Should have 3 objects cached"); mockClearHandlers(); const subsetData = [ { _id: "item-1", category: "X" }, { _id: "item-2", category: "X" }, ]; mockRegisterHandler(mockFetchHandler(`api/${resource}/`, subsetData)); const futureTimestamp = Date.now() + 100000; const filterX: Expression = Expression.parse('category = "X"'); const signalX = reactiveStoreFetch(resource, filterX, { freshness: futureTimestamp, }); await new Promise((resolve) => setTimeout(resolve, 50)); state = getCacheState(resource); assert.strictEqual( state.regionCount, 2, "Should have 2 non-overlapping regions", ); const [region1, region2] = state.regions.map((r) => r.filter); const oneCoversX = covers(region1, filterX) || covers(region2, filterX); assert.ok(oneCoversX, "One region should cover filterX (category = X)"); const unionOfRegions = Expression.or(region1, region2); assert.ok( covers(unionOfRegions, new Expression.Literal(true)), "Union of regions should cover the original filter (true)", ); assert.ok( covers(new Expression.Literal(false), Expression.and(region1, region2)), "Regions should not overlap (areDisjoint should return true)", ); const diff = subtract(region1, region2); assert.ok( areEquivalent(diff, region2), "Regions should not overlap (diff should equal region2)", ); void signalAll; void signalX; }); void test("fetching same region with newer timestamp replaces old region entirely", async () => { mockClearHandlers(); clearStores(); const resource = "config"; const data = [{ _id: "cfg-1", value: "test" }]; mockRegisterHandler(mockFetchHandler(`api/${resource}/`, data)); const filterA: Expression = Expression.parse('_id = "cfg-1"'); const signal1 = reactiveStoreFetch(resource, filterA); await new Promise((resolve) => setTimeout(resolve, 50)); let state = getCacheState(resource); const firstTimestamp = state.regions[0]?.timestamp; assert.strictEqual(state.regionCount, 1, "Should have 1 region"); await new Promise((resolve) => setTimeout(resolve, 10)); mockClearHandlers(); mockRegisterHandler(mockFetchHandler(`api/${resource}/`, data)); const futureTimestamp = Date.now() + 100000; const signal2 = reactiveStoreFetch(resource, filterA, { freshness: futureTimestamp, }); await new Promise((resolve) => setTimeout(resolve, 50)); state = getCacheState(resource); assert.strictEqual( state.regionCount, 1, "Should still have 1 region after refresh", ); assert.ok( state.regions[0].timestamp > firstTimestamp, "Region timestamp should be updated", ); void signal1; void signal2; }); void test("multiple overlapping fetches result in non-overlapping regions", async () => { mockClearHandlers(); clearStores(); const resource = "faults"; const allData = [ { _id: "fault-1", type: "A" }, { _id: "fault-2", type: "B" }, { _id: "fault-3", type: "C" }, ]; mockRegisterHandler(mockFetchHandler(`api/${resource}/`, allData)); const filterA: Expression = Expression.parse('type = "A"'); const filterB: Expression = Expression.parse('type = "B"'); const filterC: Expression = Expression.parse('type = "C"'); const signalA = reactiveStoreFetch(resource, filterA); await new Promise((resolve) => setTimeout(resolve, 50)); const signalB = reactiveStoreFetch(resource, filterB); await new Promise((resolve) => setTimeout(resolve, 50)); const signalC = reactiveStoreFetch(resource, filterC); await new Promise((resolve) => setTimeout(resolve, 50)); const state = getCacheState(resource); assert.strictEqual( state.regionCount, 3, "Should have 3 non-overlapping regions", ); assert.strictEqual(state.objectCount, 3, "Should have 3 objects cached"); assert.strictEqual(signalA.get().value.length, 1); assert.strictEqual((signalA.get().value[0] as { type: string }).type, "A"); assert.strictEqual(signalB.get().value.length, 1); assert.strictEqual((signalB.get().value[0] as { type: string }).type, "B"); assert.strictEqual(signalC.get().value.length, 1); assert.strictEqual((signalC.get().value[0] as { type: string }).type, "C"); const regionFilters = state.regions.map((r) => r.filter); assert.ok( regionFilters.some((rf) => covers(rf, filterA)), "One region should cover filterA", ); assert.ok( regionFilters.some((rf) => covers(rf, filterB)), "One region should cover filterB", ); assert.ok( regionFilters.some((rf) => covers(rf, filterC)), "One region should cover filterC", ); for (let i = 0; i < regionFilters.length; i++) { for (let j = i + 1; j < regionFilters.length; j++) { assert.ok( covers( new Expression.Literal(false), Expression.and(regionFilters[i], regionFilters[j]), ), `Regions ${i} and ${j} should not overlap (areDisjoint)`, ); } } }); // ============================================================================= // Cache Pruning Tests // ============================================================================= void test("cache is cleared when all fetch signals are disposed", async () => { mockClearHandlers(); clearStores(); const resource = "users"; const data = [ { _id: "user-1", name: "Alice" }, { _id: "user-2", name: "Bob" }, ]; mockRegisterHandler(mockFetchHandler(`api/${resource}/`, data)); const signal = reactiveStoreFetch(resource, new Expression.Literal(true)); await new Promise((resolve) => setTimeout(resolve, 50)); const state = getCacheState(resource); assert.strictEqual(state.objectCount, 2, "Should have 2 objects cached"); assert.strictEqual(state.regionCount, 1, "Should have 1 region"); assert.strictEqual(state.fetchQueryCount, 1, "Should have 1 active query"); signal[Symbol.dispose](); void signal; forcePruneCache(resource); void getCacheState(resource); }); void test("regions not serving active queries are pruned", async () => { mockClearHandlers(); clearStores(); const resource = "provisions"; const allData = [ { _id: "prov-1", category: "X" }, { _id: "prov-2", category: "X" }, { _id: "prov-3", category: "Y" }, { _id: "prov-4", category: "Y" }, ]; mockRegisterHandler(mockFetchHandler(`api/${resource}/`, allData)); const filterX: Expression = Expression.parse('category = "X"'); const filterY: Expression = Expression.parse('category = "Y"'); const signalX = reactiveStoreFetch(resource, filterX); await new Promise((resolve) => setTimeout(resolve, 50)); assert.strictEqual(signalX.get().value.length, 2); assert.ok( signalX .get() .value.every((item) => (item as { category: string }).category === "X"), ); const signalY = reactiveStoreFetch(resource, filterY); await new Promise((resolve) => setTimeout(resolve, 50)); assert.strictEqual(signalY.get().value.length, 2); assert.ok( signalY .get() .value.every((item) => (item as { category: string }).category === "Y"), ); let state = getCacheState(resource); assert.strictEqual(state.regionCount, 2, "Should have 2 regions"); assert.strictEqual(state.objectCount, 4, "Should have 4 objects"); assert.strictEqual(state.fetchQueryCount, 2, "Should have 2 active queries"); signalY[Symbol.dispose](); forcePruneCache(resource); state = getCacheState(resource); assert.strictEqual( state.regionCount, 1, "Should have 1 region after pruning (only X)", ); assert.strictEqual( state.objectCount, 2, "Should have 2 objects after pruning (only X)", ); const remainingRegion = state.regions[0].filter; assert.ok( covers(remainingRegion, filterX), "Remaining region should cover filterX", ); void signalX; }); void test("overlapping regions are consolidated after pruning", async () => { mockClearHandlers(); clearStores(); const resource = "virtualParameters"; const allData = [ { _id: "vp-1", type: "A" }, { _id: "vp-2", type: "B" }, ]; mockRegisterHandler(mockFetchHandler(`api/${resource}/`, allData)); const signalAll = reactiveStoreFetch(resource, new Expression.Literal(true)); await new Promise((resolve) => setTimeout(resolve, 50)); let state = getCacheState(resource); assert.strictEqual(state.regionCount, 1, "Should have 1 region"); assert.strictEqual(signalAll.get().value.length, 2); const futureTimestamp = Date.now() + 100000; const filterA: Expression = Expression.parse('type = "A"'); mockClearHandlers(); mockRegisterHandler(mockFetchHandler(`api/${resource}/`, allData)); const signalA = reactiveStoreFetch(resource, filterA, { freshness: futureTimestamp, }); await new Promise((resolve) => setTimeout(resolve, 50)); state = getCacheState(resource); assert.strictEqual( state.regionCount, 2, "Should have 2 regions after subset fetch", ); signalAll[Symbol.dispose](); forcePruneCache(resource); state = getCacheState(resource); assert.strictEqual( state.regionCount, 1, "Should have 1 region after pruning", ); assert.strictEqual( state.objectCount, 1, "Should have 1 object (only type A)", ); const remainingRegion = state.regions[0].filter; assert.ok( covers(remainingRegion, filterA), "Remaining region should cover filterA", ); void signalA; }); // ============================================================================= // invalidate() Tests // ============================================================================= void test("invalidate() triggers re-fetch for stale fetch queries", async () => { mockClearHandlers(); clearStores(); const resource = "presets"; const staleData = [{ _id: "p-1", name: "Old" }]; const freshData = [ { _id: "p-1", name: "Updated" }, { _id: "p-2", name: "New" }, ]; mockRegisterHandler(mockFetchHandler(`api/${resource}/`, staleData)); const signal = reactiveStoreFetch(resource, new Expression.Literal(true)); await new Promise((resolve) => setTimeout(resolve, 50)); const staleState = signal.get(); assert.strictEqual(staleState.loading, false); assert.strictEqual(staleState.value.length, 1); assert.strictEqual((staleState.value[0] as { name: string }).name, "Old"); // Replace handler with fresh data mockClearHandlers(); mockRegisterHandler(mockFetchHandler(`api/${resource}/`, freshData)); // Invalidate with a future timestamp so all current data is stale invalidate(Date.now() + 100000); // Wait for re-fetch to complete await new Promise((resolve) => setTimeout(resolve, 50)); const freshState = signal.get(); assert.strictEqual(freshState.loading, false, "Should finish loading"); assert.strictEqual(freshState.value.length, 2, "Should have fresh data"); const freshNames = freshState.value .map((item) => (item as { name: string }).name) .sort(); assert.deepStrictEqual( freshNames, ["New", "Updated"], "Should have updated data", ); }); void test("invalidate() triggers re-fetch for stale count queries", async () => { mockClearHandlers(); clearStores(); const resource = "faults"; const staleData = Array.from({ length: 5 }, (_, i) => ({ _id: `f-${i}` })); const freshData = Array.from({ length: 12 }, (_, i) => ({ _id: `f-${i}` })); mockRegisterHandler(mockCountHandler(`api/${resource}/`, staleData)); const signal = reactiveStoreCount(resource, new Expression.Literal(true)); await new Promise((resolve) => setTimeout(resolve, 50)); const staleState = signal.get(); assert.strictEqual(staleState.loading, false); assert.strictEqual(staleState.value, 5); // Replace handler with fresh data mockClearHandlers(); mockRegisterHandler(mockCountHandler(`api/${resource}/`, freshData)); invalidate(Date.now() + 100000); await new Promise((resolve) => setTimeout(resolve, 50)); const freshState = signal.get(); assert.strictEqual(freshState.loading, false, "Should finish loading"); assert.strictEqual(freshState.value, 12, "Should have fresh count"); }); void test("invalidate() preserves stale data while loading", async () => { mockClearHandlers(); clearStores(); const resource = "provisions"; const staleData = [{ _id: "item-1", value: "stale" }]; const freshData = [{ _id: "item-1", value: "fresh" }]; mockRegisterHandler(mockFetchHandler(`api/${resource}/`, staleData)); const signal = reactiveStoreFetch(resource, new Expression.Literal(true)); await new Promise((resolve) => setTimeout(resolve, 50)); const staleState = signal.get(); assert.strictEqual(staleState.loading, false); assert.strictEqual(staleState.value.length, 1); // Use a delayed handler so we can observe the loading state mockClearHandlers(); mockRegisterHandler(mockFetchHandler(`api/${resource}/`, freshData, 100)); invalidate(Date.now() + 100000); // Immediately after invalidate, should be loading with stale data const loadingState = signal._peek(); assert.strictEqual( loadingState.loading, true, "Should be loading after invalidate", ); assert.strictEqual( loadingState.value.length, 1, "Should still have stale data while loading", ); assert.strictEqual( (loadingState.value[0] as { value: string }).value, "stale", "Stale data should be preserved while loading", ); // Wait for re-fetch to complete await new Promise((resolve) => setTimeout(resolve, 150)); const freshState = signal.get(); assert.strictEqual(freshState.loading, false, "Should finish loading"); assert.strictEqual( (freshState.value[0] as { value: string }).value, "fresh", "Should have fresh data after loading completes", ); }); void test("invalidate() skips queries that are already loading", async () => { mockClearHandlers(); clearStores(); const resource = "config"; const data = [{ _id: "cfg-1", value: "test" }]; // Use a slow handler so initial fetch is still in-flight mockRegisterHandler(mockFetchHandler(`api/${resource}/`, data, 200)); const signal = reactiveStoreFetch(resource, new Expression.Literal(true)); // Signal should still be loading from initial fetch const state = signal._peek(); assert.strictEqual( state.loading, true, "Should be loading from initial fetch", ); mockClearRequestLog(); // Invalidate while still loading — should be a no-op invalidate(Date.now() + 100000); const log = mockGetRequestLog(); assert.strictEqual( log.length, 0, "Should not trigger additional request while already loading", ); // Wait for original fetch to complete await new Promise((resolve) => setTimeout(resolve, 250)); const finalState = signal.get(); assert.strictEqual(finalState.loading, false); assert.strictEqual(finalState.value.length, 1); }); void test("invalidate() skips queries newer than the given timestamp", async () => { mockClearHandlers(); clearStores(); const resource = "files"; const data = [{ _id: "file-1", name: "Test" }]; mockRegisterHandler(mockFetchHandler(`api/${resource}/`, data)); const signal = reactiveStoreFetch(resource, new Expression.Literal(true)); await new Promise((resolve) => setTimeout(resolve, 50)); const state = signal.get(); assert.strictEqual(state.loading, false); assert.strictEqual(state.value.length, 1); mockClearRequestLog(); // Invalidate with a timestamp in the past (older than fetched data) invalidate(1); const log = mockGetRequestLog(); assert.strictEqual( log.length, 0, "Should not trigger request when data is newer than invalidation timestamp", ); // Signal state should be unchanged const unchanged = signal.get(); assert.strictEqual(unchanged.loading, false, "Should not be loading"); assert.strictEqual(unchanged.value.length, 1, "Data should be unchanged"); }); void test("invalidate() refreshes queries across multiple resource stores", async () => { mockClearHandlers(); clearStores(); const presetsData = [{ _id: "preset-1", name: "P1" }]; const faultsData = [{ _id: "fault-1", type: "error" }]; mockRegisterHandler(mockFetchHandler("api/presets/", presetsData)); mockRegisterHandler(mockFetchHandler("api/faults/", faultsData)); mockRegisterHandler(mockCountHandler("api/faults/", faultsData)); const presetSignal = reactiveStoreFetch( "presets", new Expression.Literal(true), ); const faultSignal = reactiveStoreFetch( "faults", new Expression.Literal(true), ); const faultCount = reactiveStoreCount("faults", new Expression.Literal(true)); await new Promise((resolve) => setTimeout(resolve, 50)); assert.strictEqual(presetSignal.get().value.length, 1); assert.strictEqual(faultSignal.get().value.length, 1); assert.strictEqual(faultCount.get().value, 1); // Replace with fresh data mockClearHandlers(); const freshPresets = [ { _id: "preset-1", name: "P1" }, { _id: "preset-2", name: "P2" }, ]; const freshFaults = [ { _id: "fault-1", type: "error" }, { _id: "fault-2", type: "warning" }, { _id: "fault-3", type: "error" }, ]; mockRegisterHandler(mockFetchHandler("api/presets/", freshPresets)); mockRegisterHandler(mockFetchHandler("api/faults/", freshFaults)); mockRegisterHandler(mockCountHandler("api/faults/", freshFaults)); invalidate(Date.now() + 100000); await new Promise((resolve) => setTimeout(resolve, 50)); assert.strictEqual( presetSignal.get().value.length, 2, "Presets should be refreshed", ); assert.strictEqual( faultSignal.get().value.length, 3, "Faults fetch should be refreshed", ); assert.strictEqual( faultCount.get().value, 3, "Faults count should be refreshed", ); }); void test("fetch() removes deleted records from cache on refresh", async () => { mockClearHandlers(); clearStores(); const resource = "presets"; const initialData = [ { _id: "p-1", name: "First" }, { _id: "p-2", name: "Second" }, { _id: "p-3", name: "Third" }, ]; mockRegisterHandler(mockFetchHandler(`api/${resource}/`, initialData)); const signal = reactiveStoreFetch(resource, new Expression.Literal(true)); await new Promise((resolve) => setTimeout(resolve, 50)); const initialState = signal.get(); assert.strictEqual(initialState.value.length, 3); // Simulate server-side deletion: p-2 is deleted const afterDeleteData = [ { _id: "p-1", name: "First" }, { _id: "p-3", name: "Third" }, ]; mockClearHandlers(); mockRegisterHandler(mockFetchHandler(`api/${resource}/`, afterDeleteData)); invalidate(Date.now() + 100000); await new Promise((resolve) => setTimeout(resolve, 50)); const afterState = signal.get(); assert.strictEqual( afterState.value.length, 2, "Deleted record should be removed", ); const ids = afterState.value .map((item) => (item as { _id: string })._id) .sort(); assert.deepStrictEqual( ids, ["p-1", "p-3"], "Only non-deleted records remain", ); }); ================================================ FILE: test/signals.ts ================================================ import test from "node:test"; import assert from "node:assert"; import { ConstSignal, SignalBase, StateSignal, ComputedSignal, Watcher, setTimeout, setInterval, } from "../ui/signals.ts"; // ============================================================================= // ConstSignal Tests // ============================================================================= void test("ConstSignal returns constant value", () => { const signal = new ConstSignal(42); assert.strictEqual(signal.get(), 42); assert.strictEqual(signal.get(), 42); // Works with different types const strSignal = new ConstSignal("hello"); assert.strictEqual(strSignal.get(), "hello"); const objSignal = new ConstSignal({ a: 1 }); assert.strictEqual(objSignal.get().a, 1); assert.strictEqual(objSignal.get(), objSignal.get()); // Same reference }); void test("ConstSignal extends SignalBase but doesn't allocate _sinks", () => { const constant = new ConstSignal(42); // ConstSignal extends SignalBase for proper type hierarchy assert.strictEqual(constant instanceof SignalBase, true); // But doesn't allocate _sinks (optimization) assert.strictEqual((constant as any)._sinks, undefined); }); // ============================================================================= // StateSignal Tests // ============================================================================= void test("StateSignal get and set", () => { const signal = new StateSignal(42); assert.strictEqual(signal.get(), 42); signal.set(100); assert.strictEqual(signal.get(), 100); }); void test("StateSignal.set() with same value (Object.is) doesn't trigger updates", () => { const signal = new StateSignal(1); let computeCount = 0; const computed = new ComputedSignal(() => { computeCount++; return signal.get() * 2; }); assert.strictEqual(computed.get(), 2); assert.strictEqual(computeCount, 1); // Set to same value signal.set(1); assert.strictEqual(computed.get(), 2); assert.strictEqual(computeCount, 1); // Object.is(NaN, NaN) is true const nanSignal = new StateSignal(NaN); let nanComputeCount = 0; const nanComputed = new ComputedSignal(() => { nanComputeCount++; return nanSignal.get(); }); nanComputed.get(); nanSignal.set(NaN); nanComputed.get(); assert.strictEqual(nanComputeCount, 1); }); void test("Can subclass StateSignal", () => { class Counter extends StateSignal { increment(): void { this.set(this.get() + 1); } } const counter = new Counter(0); counter.increment(); counter.increment(); assert.strictEqual(counter.get(), 2); }); // ============================================================================= // ComputedSignal Tests // ============================================================================= void test("ComputedSignal is lazy and memoized", () => { let computeCount = 0; const computed = new ComputedSignal(() => { computeCount++; return 1 + 2; }); // Lazy: callback not called until get() assert.strictEqual(computeCount, 0); // First get() computes assert.strictEqual(computed.get(), 3); assert.strictEqual(computeCount, 1); // Memoized: second get() returns cached value assert.strictEqual(computed.get(), 3); assert.strictEqual(computeCount, 1); }); void test("ComputedSignal tracks dependencies", () => { // StateSignal dependencies const a = new StateSignal(1); const b = new StateSignal(2); const sum = new ComputedSignal(() => a.get() + b.get()); assert.strictEqual(sum.get(), 3); a.set(10); assert.strictEqual(sum.get(), 12); b.set(20); assert.strictEqual(sum.get(), 30); // ComputedSignal dependencies (chained) const c = new StateSignal(2); const doubled = new ComputedSignal(() => c.get() * 2); const quadrupled = new ComputedSignal(() => doubled.get() * 2); assert.strictEqual(quadrupled.get(), 8); c.set(3); assert.strictEqual(quadrupled.get(), 12); }); void test("Dependencies can change between evaluations", () => { const condition = new StateSignal(true); const a = new StateSignal(1); const b = new StateSignal(2); let computeCount = 0; const computed = new ComputedSignal(() => { computeCount++; return condition.get() ? a.get() : b.get(); }); assert.strictEqual(computed.get(), 1); assert.strictEqual(computeCount, 1); // Changing a should trigger recompute a.set(10); assert.strictEqual(computed.get(), 10); assert.strictEqual(computeCount, 2); // Changing b should NOT trigger recompute (not a dependency) b.set(20); assert.strictEqual(computed.get(), 10); assert.strictEqual(computeCount, 2); // Switch condition - now b is dependency, a is not condition.set(false); assert.strictEqual(computed.get(), 20); assert.strictEqual(computeCount, 3); // Now changing a should NOT trigger recompute a.set(100); assert.strictEqual(computed.get(), 20); assert.strictEqual(computeCount, 3); // But changing b should b.set(200); assert.strictEqual(computed.get(), 200); assert.strictEqual(computeCount, 4); }); void test("Diamond dependency pattern (glitch-free with Checking optimization)", () => { // A // / \ // B C // \ / // D const a = new StateSignal(1); let bCount = 0; const b = new ComputedSignal(() => { bCount++; // Returns 10 for positive, 0 for non-positive return a.get() > 0 ? 10 : 0; }); let cCount = 0; const c = new ComputedSignal(() => { cCount++; // Returns 20 for positive, 0 for non-positive return a.get() > 0 ? 20 : 0; }); let dCount = 0; const d = new ComputedSignal(() => { dCount++; return b.get() + c.get(); }); // Initial computation assert.strictEqual(d.get(), 30); assert.strictEqual(bCount, 1); assert.strictEqual(cCount, 1); assert.strictEqual(dCount, 1); // Change a, but b and c return same values - d should NOT recompute (Checking optimization) a.set(2); assert.strictEqual(d.get(), 30); assert.strictEqual(bCount, 2); assert.strictEqual(cCount, 2); assert.strictEqual(dCount, 1); // d NOT recomputed // Change a to negative - b and c return different values, d MUST recompute a.set(-1); assert.strictEqual(d.get(), 0); assert.strictEqual(bCount, 3); assert.strictEqual(cCount, 3); assert.strictEqual(dCount, 2); }); void test("Deeply nested computeds", () => { const state = new StateSignal(1); // Create a chain of 100 computeds let current: StateSignal | ComputedSignal = state; for (let i = 0; i < 100; i++) { const prev = current; current = new ComputedSignal(() => prev.get() + 1); } assert.strictEqual(current.get(), 101); state.set(0); assert.strictEqual(current.get(), 100); }); // ============================================================================= // Error Handling // ============================================================================= void test("ComputedSignal caches and rethrows errors", () => { let computeCount = 0; const computed = new ComputedSignal(() => { computeCount++; throw new Error("test error"); }); // First call throws assert.throws(() => computed.get(), { message: "test error" }); assert.strictEqual(computeCount, 1); // Second call throws cached error without recomputing assert.throws(() => computed.get(), { message: "test error" }); assert.strictEqual(computeCount, 1); }); void test("Error cache is cleared on dependency change", () => { const trigger = new StateSignal(0); let shouldThrow = true; let computeCount = 0; const computed = new ComputedSignal(() => { computeCount++; trigger.get(); if (shouldThrow) throw new Error("test error"); return 42; }); // First call throws assert.throws(() => computed.get(), { message: "test error" }); assert.strictEqual(computeCount, 1); // Change dependency and fix the error condition shouldThrow = false; trigger.set(1); // Now should succeed assert.strictEqual(computed.get(), 42); assert.strictEqual(computeCount, 2); }); void test("Circular dependency throws error", () => { // Direct: a -> b -> a // eslint-disable-next-line prefer-const let aRef: ComputedSignal; const b = new ComputedSignal(() => aRef.get() + 1); const a = new ComputedSignal(() => b.get() + 1); aRef = a; assert.throws(() => a.get(), { message: "Circular dependency detected" }); // Self-reference // eslint-disable-next-line prefer-const let selfRef: ComputedSignal; const self = new ComputedSignal(() => selfRef.get() + 1); selfRef = self; assert.throws(() => self.get(), { message: "Circular dependency detected" }); }); // ============================================================================= // setTimeout Tests // ============================================================================= void test("setTimeout outside computed behaves like regular setTimeout", async () => { let called = false; setTimeout(() => { called = true; }, 10); assert.strictEqual(called, false); await new Promise((r) => globalThis.setTimeout(r, 50)); assert.strictEqual(called, true); }); void test("setTimeout inside computed fires when signal stays clean", async () => { const state = new StateSignal(1); let callCount = 0; const computed = new ComputedSignal(() => { state.get(); setTimeout(() => { callCount++; }, 10); return "done"; }); computed.get(); assert.strictEqual(callCount, 0); await new Promise((r) => globalThis.setTimeout(r, 50)); assert.strictEqual(callCount, 1); }); void test("setTimeout inside computed cancelled when signal becomes dirty", async () => { const state = new StateSignal(1); let callCount = 0; const computed = new ComputedSignal(() => { state.get(); setTimeout(() => { callCount++; }, 50); return "done"; }); computed.get(); // Make the signal dirty before timeout fires - callback skipped via _isValid state.set(2); await new Promise((r) => globalThis.setTimeout(r, 100)); assert.strictEqual(callCount, 0); // Recompute schedules a new timeout, old one was already skipped computed.get(); await new Promise((r) => globalThis.setTimeout(r, 100)); assert.strictEqual(callCount, 1); }); void test("setTimeout with Checking state", async () => { // Test: fires when Checking resolves to Clean (sources unchanged) const stateA = new StateSignal(1); const stateB = new StateSignal(100); const intermediate = new ComputedSignal(() => { stateA.get(); return "constant"; // Always returns same value }); let callCount = 0; const computed = new ComputedSignal(() => { intermediate.get(); stateB.get(); setTimeout(() => { callCount++; }, 10); return "done"; }); computed.get(); stateA.set(2); // intermediate recomputes but returns same value await new Promise((r) => globalThis.setTimeout(r, 50)); assert.strictEqual(callCount, 1); // Fires: Checking -> Clean // Test: cancelled when Checking resolves to Dirty (sources changed) const stateC = new StateSignal(1); const intermediate2 = new ComputedSignal(() => stateC.get() * 2); let callCount2 = 0; const computed2 = new ComputedSignal(() => { intermediate2.get(); setTimeout(() => { callCount2++; }, 10); return "done"; }); computed2.get(); stateC.set(2); // intermediate2 returns different value await new Promise((r) => globalThis.setTimeout(r, 50)); assert.strictEqual(callCount2, 0); // Cancelled: Checking -> Dirty }); void test("setTimeout passes arguments and can be manually cleared", async () => { // Test argument passing let receivedArgs: unknown[] = []; const computed = new ComputedSignal(() => { setTimeout( (a: number, b: string) => { receivedArgs = [a, b]; }, 10, 42, "hello", ); return "done"; }); computed.get(); await new Promise((r) => globalThis.setTimeout(r, 50)); assert.deepStrictEqual(receivedArgs, [42, "hello"]); // Test manual clearing let called = false; const computed2 = new ComputedSignal(() => { const id = setTimeout(() => { called = true; }, 50); globalThis.clearTimeout(id); return "done"; }); computed2.get(); await new Promise((r) => globalThis.setTimeout(r, 100)); assert.strictEqual(called, false); }); // ============================================================================= // setInterval Tests // ============================================================================= void test("setInterval outside computed behaves like regular setInterval", async () => { let callCount = 0; const id = setInterval(() => { callCount++; }, 20); await new Promise((r) => globalThis.setTimeout(r, 70)); globalThis.clearInterval(id); assert.ok(callCount >= 2, `Expected at least 2 calls, got ${callCount}`); }); void test("setInterval inside computed stops when signal becomes dirty", async () => { const state = new StateSignal(1); let callCount = 0; const computed = new ComputedSignal(() => { state.get(); setInterval(() => { callCount++; }, 20); return "done"; }); computed.get(); // Let it fire once await new Promise((r) => globalThis.setTimeout(r, 30)); const countAfterFirst = callCount; assert.ok(countAfterFirst >= 1, "Should have fired at least once"); // Make the signal dirty state.set(2); // Wait for more potential intervals await new Promise((r) => globalThis.setTimeout(r, 60)); // Should not have fired again (or at most once more if timing is tight) assert.ok( callCount <= countAfterFirst + 1, `Expected no more than ${countAfterFirst + 1} calls, got ${callCount}`, ); }); void test("setInterval inside computed stops and restarts on recompute", async () => { const state = new StateSignal(1); let callCount = 0; let intervalId: ReturnType; const computed = new ComputedSignal(() => { const val = state.get(); intervalId = setInterval(() => { callCount++; }, 20); return val; }); computed.get(); // Let it fire a couple times await new Promise((r) => globalThis.setTimeout(r, 50)); const countBeforeRecompute = callCount; // Recompute - old interval should stop, new one should start state.set(2); computed.get(); await new Promise((r) => globalThis.setTimeout(r, 50)); globalThis.clearInterval(intervalId!); // New interval should have fired assert.ok( callCount > countBeforeRecompute, "New interval should have fired after recompute", ); }); void test("setInterval passes arguments and can be manually cleared", async () => { // Test argument passing let receivedArgs: unknown[] = []; const id = setInterval( (a: number, b: string) => { receivedArgs = [a, b]; }, 10, 42, "hello", ); await new Promise((r) => globalThis.setTimeout(r, 30)); globalThis.clearInterval(id); assert.deepStrictEqual(receivedArgs, [42, "hello"]); // Test manual clearing let callCount = 0; const computed = new ComputedSignal(() => { const intervalId = setInterval(() => { callCount++; }, 20); globalThis.clearInterval(intervalId); return "done"; }); computed.get(); await new Promise((r) => globalThis.setTimeout(r, 70)); assert.strictEqual(callCount, 0); }); // ============================================================================= // Disposal Tests // ============================================================================= void test("ConstSignal disposal", () => { const signal = new ConstSignal(42); assert.strictEqual(signal.get(), 42); signal[Symbol.dispose](); // Reading after disposal throws assert.throws(() => signal.get(), { message: "Cannot read disposed signal" }); // Disposing again is a no-op (doesn't throw) signal[Symbol.dispose](); }); void test("StateSignal disposal", () => { const signal = new StateSignal(42); assert.strictEqual(signal.get(), 42); signal[Symbol.dispose](); // Reading after disposal throws assert.throws(() => signal.get(), { message: "Cannot read disposed signal" }); // Writing after disposal throws assert.throws(() => signal.set(100), { message: "Cannot write to disposed signal", }); // Disposing again is a no-op (doesn't throw) signal[Symbol.dispose](); }); void test("ComputedSignal disposal", () => { const state = new StateSignal(1); let computeCount = 0; const computed = new ComputedSignal(() => { computeCount++; return state.get() * 2; }); assert.strictEqual(computed.get(), 2); assert.strictEqual(computeCount, 1); computed[Symbol.dispose](); // Reading after disposal throws assert.throws(() => computed.get(), { message: "Cannot read disposed signal", }); // Disposing again is a no-op (doesn't throw) computed[Symbol.dispose](); // Source state still works assert.strictEqual(state.get(), 1); }); void test("ComputedSignal disposal detaches from sources", () => { const state = new StateSignal(1); let computeCount = 0; const computed = new ComputedSignal(() => { computeCount++; return state.get() * 2; }); assert.strictEqual(computed.get(), 2); assert.strictEqual(computeCount, 1); // Verify sink is registered assert.strictEqual((state as any)._sinks.size, 1); computed[Symbol.dispose](); // Sink should be removed after disposal assert.strictEqual((state as any)._sinks.size, 0); }); void test("ComputedSignal disposal runs cleanups", async () => { let timeoutFired = false; let intervalFired = false; const computed = new ComputedSignal(() => { setTimeout(() => { timeoutFired = true; }, 10); setInterval(() => { intervalFired = true; }, 10); return "done"; }); computed.get(); computed[Symbol.dispose](); // Wait for timers that would have fired await new Promise((r) => globalThis.setTimeout(r, 50)); // Neither should have fired because disposal cleared them assert.strictEqual(timeoutFired, false); assert.strictEqual(intervalFired, false); }); void test("Disposal cascades to nested signals of all types", () => { let innerState: StateSignal | null = null; let innerConst: ConstSignal | null = null; let innerComputed: ComputedSignal | null = null; const outer = new ComputedSignal(() => { innerState = new StateSignal(10); innerConst = new ConstSignal(20); innerComputed = new ComputedSignal(() => 30); return innerState.get() + innerConst.get() + innerComputed.get(); }); assert.strictEqual(outer.get(), 60); outer[Symbol.dispose](); assert.throws(() => innerState!.get(), { message: "Cannot read disposed signal", }); assert.throws(() => innerConst!.get(), { message: "Cannot read disposed signal", }); assert.throws(() => innerComputed!.get(), { message: "Cannot read disposed signal", }); }); // ============================================================================= // Watcher Tests // ============================================================================= void test("Watcher notifies on state change and at most once per batch", () => { const state = new StateSignal(1); let notifyCount = 0; const watcher = new Watcher(() => { notifyCount++; }); watcher.watch(state); // Fires on change state.set(2); assert.strictEqual(notifyCount, 1); // At-most-once: second change in same batch does not fire again state.set(3); assert.strictEqual(notifyCount, 1); // watch() resets the flag, allowing notification again watcher.watch(state); state.set(4); assert.strictEqual(notifyCount, 2); watcher[Symbol.dispose](); }); void test("Watcher notifies on transitive dependency change", () => { const state = new StateSignal(1); const computed = new ComputedSignal(() => state.get() * 2); let notifyCount = 0; const watcher = new Watcher(() => { notifyCount++; }); // Prime the computed so it registers dependencies and is Clean computed.get(); watcher.watch(computed); // Changing the root state propagates through the computed to the watcher state.set(2); assert.strictEqual(notifyCount, 1); watcher[Symbol.dispose](); }); void test("Watcher unwatch and disposal stop notifications", () => { const a = new StateSignal(1); const b = new StateSignal(1); let notifyCount = 0; const watcher = new Watcher(() => { notifyCount++; }); watcher.watch(a, b); // Unwatch a, changes to a no longer notify watcher.unwatch(a); a.set(2); assert.strictEqual(notifyCount, 0); // b still notifies b.set(2); assert.strictEqual(notifyCount, 1); // After disposal, nothing notifies watcher.watch(b); // reset notified flag watcher[Symbol.dispose](); b.set(3); assert.strictEqual(notifyCount, 1); }); void test("Watcher getPending returns dirty computed signals", () => { const state = new StateSignal(1); const computed = new ComputedSignal(() => state.get() * 2); // Prime the computed so it has registered dependencies computed.get(); const watcher = new Watcher(() => {}); watcher.watch(computed); // Before any change, nothing is pending assert.deepStrictEqual(watcher.getPending(), []); // After change, computed is pending state.set(2); assert.deepStrictEqual(watcher.getPending(), [computed]); // After reading, no longer pending computed.get(); assert.deepStrictEqual(watcher.getPending(), []); watcher[Symbol.dispose](); }); ================================================ FILE: test/synth.ts ================================================ import test from "node:test"; import assert from "node:assert"; import initSqlJs from "sql.js/dist/sql-asm.js"; import { covers, minimize, unionDiff, subtract, areEquivalent, } from "../lib/common/expression/synth.ts"; import Expression from "../lib/common/expression.ts"; function isFalse(expr: Expression): boolean { return expr instanceof Expression.Literal && expr.value === false; } const STRING_VALUES = [null, "", "a", "ab", "ab10", "ab-10"]; const DECIMAL_VALUES = [null, 0, -10, 10]; let db; async function query(filter: string): Promise> { if (!db) { const sql = await initSqlJs(); db = new sql.Database(); db.run( "CREATE TABLE test (id INTEGER PRIMARY KEY, string STRING, decimal DECIMAL(4,2))", ); const stmt = db.prepare("INSERT INTO test (string, decimal) VALUES (?, ?)"); const count = STRING_VALUES.length * DECIMAL_VALUES.length; for (let i = 0; i < count; ++i) { const str = i % STRING_VALUES.length; const dec = Math.trunc(i / STRING_VALUES.length) % DECIMAL_VALUES.length; stmt.run([STRING_VALUES[str], DECIMAL_VALUES[dec]]); } stmt.free(); } const res = db.exec(`SELECT id FROM test WHERE ${filter}`); if (!res.length) return new Set(); return new Set(res[0].values.flat()); } function setsEqual(set1: Set, set2: Set): boolean { if (set1.size !== set2.size) return false; for (const s of set1) if (!set2.has(s)) return false; return true; } function getPermutations(...arrs: any[][]): any[][] { const count = arrs.reduce((total, arr) => total * arr.length, 1); const res = []; for (let i = 0; i < count; ++i) { let j = i; const row = []; for (const arr of arrs) { const v = arr[j % arr.length]; j = Math.trunc(j / arr.length); row.push(v); } res.push(row); } return res; } void test("minimize", async () => { const cases: string[] = []; cases.push("null"); cases.push("false"); cases.push("true"); cases.push("string"); cases.push("(string + decimal) IS NULL"); cases.push("(string + decimal) = NULL"); cases.push("COALESCE(string, decimal) = 0"); for (const [s1, s2, s3, op1, op2] of getPermutations( STRING_VALUES.filter((s) => s), STRING_VALUES.filter((s) => s), STRING_VALUES.filter((s) => s), [">", "=", "<"], ["<>", ">="], )) { cases.push( `string ${op1} "${s1}" OR string ='${s2}' OR NOT string ${op2} '${s3}'`, ); } for (const [s1, s2] of getPermutations( STRING_VALUES.filter((s) => s), STRING_VALUES.filter((s) => s), )) cases.push(`string > "${s1}" AND string < '${s2}'`); for (const c of cases) { const res1 = await query(c); const min = minimize(Expression.parse(c), true).toString(); const res2 = await query(min); assert.strictEqual(setsEqual(res1, res2), true); } }); void test("unionDiff", async () => { const cases = [ "true", "decimal > 0", "decimal > 10", "UPPER(string || decimal) LIKE 'AB10'", "COALESCE(string, decimal) = 0", ]; for (const [c1, c2] of getPermutations(cases, cases)) { const res1 = await query(c1); const res2 = await query(c2); const [union, diff] = unionDiff(Expression.parse(c1), Expression.parse(c2)); const res3 = await query(union.toString()); const res4 = await query(diff.toString()); const unionSet = new Set([...res1, ...res2]); const diffSet = new Set(Array.from(res2).filter((r) => !res1.has(r))); assert.strictEqual(setsEqual(res3, unionSet), true); assert.strictEqual(setsEqual(res4, diffSet), true); } }); void test("covers", async () => { assert.strictEqual( covers(Expression.parse("false"), Expression.parse("false")), true, ); assert.strictEqual( covers( Expression.parse("false"), Expression.parse("decimal > 5 AND decimal < 3"), ), true, ); assert.strictEqual( covers(Expression.parse("true"), Expression.parse("decimal > 0")), true, ); assert.strictEqual( covers(Expression.parse("true"), Expression.parse("false")), true, ); assert.strictEqual( covers(Expression.parse("false"), Expression.parse("decimal > 0")), false, ); assert.strictEqual( covers(Expression.parse("decimal >= 0"), Expression.parse("decimal > 0")), true, ); assert.strictEqual( covers(Expression.parse("decimal > 0"), Expression.parse("decimal >= 0")), false, ); const cases = [ ["decimal >= 0", "decimal > 0"], ["decimal > 0", "decimal > 5"], ["string IS NOT NULL", "string = 'a'"], ["true", "decimal > 0"], ]; for (const [c1, c2] of cases) { const res1 = await query(c1); const res2 = await query(c2); const coversResult = covers(Expression.parse(c1), Expression.parse(c2)); const actuallyCovers = Array.from(res2).every((r) => res1.has(r)); assert.strictEqual( coversResult, actuallyCovers, `covers(${c1}, ${c2}) should match actual coverage`, ); } }); void test("LIKE-Compare DC set relationships", () => { const likeExpr = Expression.parse("string LIKE 'a%'"); const eqExpr = Expression.parse("string = 'a'"); const conjExpr: Expression = new Expression.Binary("AND", eqExpr, likeExpr); assert.strictEqual( isFalse(minimize(conjExpr, true)), false, "(string = 'a') AND (string LIKE 'a%') should NOT minimize to false", ); const nonMatchingExpr = Expression.parse("string = 'b'"); const conjNonMatch: Expression = new Expression.Binary( "AND", nonMatchingExpr, likeExpr, ); assert.strictEqual( isFalse(minimize(conjNonMatch, true)), true, "(string = 'b') AND (string LIKE 'a%') should minimize to false", ); }); void test("LIKE-Compare DC set with range operators", () => { const likeExpr = Expression.parse("string LIKE 'abc%'"); const ltExpr = Expression.parse("string < 'abc'"); const ltConj: Expression = new Expression.Binary("AND", ltExpr, likeExpr); assert.strictEqual( isFalse(minimize(ltConj, true)), true, "(string < 'abc') AND (string LIKE 'abc%') should be false", ); const ltExpr2 = Expression.parse("string < 'abd'"); const ltConj2: Expression = new Expression.Binary("AND", ltExpr2, likeExpr); assert.strictEqual( isFalse(minimize(ltConj2, true)), false, "(string < 'abd') AND (string LIKE 'abc%') should NOT be false", ); const gtExpr = Expression.parse("string > 'abd'"); const gtConj: Expression = new Expression.Binary("AND", gtExpr, likeExpr); assert.strictEqual( isFalse(minimize(gtConj, true)), true, "(string > 'abd') AND (string LIKE 'abc%') should be false", ); const gtExpr2 = Expression.parse("string > 'abc'"); const gtConj2: Expression = new Expression.Binary("AND", gtExpr2, likeExpr); assert.strictEqual( isFalse(minimize(gtConj2, true)), false, "(string > 'abc') AND (string LIKE 'abc%') should NOT be false", ); }); void test("subtract returns same result as unionDiff diff", async () => { const cases = [ "true", "decimal > 0", "decimal > 10", "UPPER(string || decimal) LIKE 'AB10'", "COALESCE(string, decimal) = 0", ]; for (const [c1, c2] of getPermutations(cases, cases)) { const res1 = await query(c1); const res2 = await query(c2); const diffExpr = subtract(Expression.parse(c1), Expression.parse(c2)); const resDiff = await query(diffExpr.toString()); const expectedDiff = new Set(Array.from(res2).filter((r) => !res1.has(r))); assert.strictEqual( setsEqual(resDiff, expectedDiff), true, `subtract(${c1}, ${c2}) should equal expr2 - expr1`, ); } }); void test("areEquivalent", async () => { // Equivalent expressions assert.strictEqual( areEquivalent(Expression.parse("true"), Expression.parse("true")), true, ); assert.strictEqual( areEquivalent(Expression.parse("false"), Expression.parse("false")), true, ); assert.strictEqual( areEquivalent( Expression.parse("decimal > 0"), Expression.parse("decimal > 0"), ), true, ); // Logically equivalent but syntactically different assert.strictEqual( areEquivalent( Expression.parse("NOT decimal <= 0"), Expression.parse("decimal > 0"), ), true, ); assert.strictEqual( areEquivalent( Expression.parse("decimal > 0 OR decimal = 0"), Expression.parse("decimal >= 0"), ), true, ); // Non-equivalent expressions assert.strictEqual( areEquivalent( Expression.parse("decimal > 0"), Expression.parse("decimal >= 0"), ), false, ); assert.strictEqual( areEquivalent(Expression.parse("true"), Expression.parse("false")), false, ); // Nullable expression tests - these test sanitization // decimal > 0 implies decimal IS NOT NULL assert.strictEqual( areEquivalent( Expression.parse("decimal > 0"), Expression.parse("decimal > 0 AND decimal IS NOT NULL"), ), true, "decimal > 0 should be equivalent to (decimal > 0 AND decimal IS NOT NULL)", ); // Non-equivalent nullable expressions assert.strictEqual( areEquivalent( Expression.parse("decimal > 0"), Expression.parse("decimal > 0 OR decimal IS NULL"), ), false, "decimal > 0 should NOT be equivalent to (decimal > 0 OR decimal IS NULL)", ); // Complex nullable expression - De Morgan with nullable assert.strictEqual( areEquivalent( Expression.parse("NOT (decimal > 0 OR decimal IS NULL)"), Expression.parse("decimal <= 0 AND decimal IS NOT NULL"), ), true, "De Morgan with nullable should work", ); }); ================================================ FILE: test/util.ts ================================================ import test from "node:test"; import assert from "node:assert"; import * as common from "../lib/util.ts"; void test("generateDeviceId", () => { const space = [" ", "%20"]; const special = [";", "%3B"]; const cases = [ [ { ProductClass: "TestProductClass", OUI: "TestOUI", SerialNumber: "TestSerialNumber", }, "TestOUI-TestProductClass-TestSerialNumber", ], [ { OUI: "TestOUI", SerialNumber: "TestSerialNumber", }, "TestOUI-TestSerialNumber", ], [ { OUI: `TestOUIWith${space[0]}_${special[0]}2912`, SerialNumber: `TestSerialNumberWith${space[0]}_${special[0]}2912`, }, `TestOUIWith${space[1]}_${special[1]}2912-TestSerialNumberWith${space[1]}_${special[1]}2912`, ], ]; for (const c of cases) assert.strictEqual( common.generateDeviceId(c[0] as Record), c[1], ); }); void test("escapeRegExp", () => { assert.strictEqual( common.escapeRegExp("\\ ^ $ * + ? . ( ) | { } [ ]"), "\\\\ \\^ \\$ \\* \\+ \\? \\. \\( \\) \\| \\{ \\} \\[ \\]", ); }); ================================================ FILE: test/xml-parser.ts ================================================ import test from "node:test"; import assert from "node:assert"; import { parseXmlDeclaration, decodeEntities, parseXml, } from "../lib/xml-parser.ts"; void test("parseXmlDeclaration", () => { const buf = Buffer.from( '\n', ); const attrs = parseXmlDeclaration(buf); assert.deepStrictEqual(attrs, [ { name: "version", namespace: "", localName: "version", value: "1.0", }, { name: "encoding", namespace: "", localName: "encoding", value: "UTF-8", }, ]); }); void test("decodeEntities", () => { assert.strictEqual( decodeEntities("&&<>"'>§��;"), "&&<>\"'>§𠮷;", ); }); void test("parse", () => { const xml = '\ni'; const parsed = parseXml(xml); assert.deepStrictEqual(parsed, { name: "root", namespace: "", localName: "root", attrs: "", text: "", bodyIndex: 0, children: [ { name: "a-b:c", namespace: "a-b", localName: "c", attrs: "", text: "", bodyIndex: 29, children: [ { name: "d", namespace: "", localName: "d", attrs: 'f="1"', text: "", bodyIndex: 42, children: [], }, { name: "h", namespace: "", localName: "h", attrs: "", text: "i", bodyIndex: 62, children: [], }, ], }, ], }); }); ================================================ FILE: test/yaml-tests.json ================================================ [ [ { "name": "Mark McGwire", "hr": 65, "avg": 0.278 }, { "name": "Sammy Sosa", "hr": 63, "avg": 0.288 } ], { "top1": { "key1": "scalar1" }, "top2": { "key2": "scalar2" }, "top3": { "scalar1": "scalar3" }, "top4": { "scalar2": "scalar4" }, "top5": "scalar5", "top6": { "key6": "scalar6" } }, "text", ["a", "b", 42, "d"], { "a!\"#$%&'()*+,-./09:;<=>?@AZ[\\]^_`az{|}~": "safe", "?foo": "safe question mark", ":foo": "safe colon", "-foo": "safe dash", "this is#not": "a comment" }, { "": "a" }, "foo", { "key": "value", "foo": "key" }, [1, -2, 33], { "plain": "a b\nc" }, [["s1_i1", "s1_i2"], "s2"], { "First occurrence": "Foo", "Second occurrence": "Foo", "Override anchor": "Bar", "Reuse anchor": "Bar" }, "k:#foo &a !t s", ["a"], { "escaped slash": "a/b" }, { "plain": "This unquoted scalar spans many lines.", "quoted": "So does this quoted scalar.\n" }, "here's to \"quotes\"", { "foo": "bar" }, "ab cd\nef\n\ngh\n", ["detected\n", "\n\n# detected\n", " explicit\n", "detected\n"], "foo: bar\": baz", "plain\\value\\with\\backslashes", { "plain": "text lines", "quoted": "text lines", "block": "text\n \tlines\n" }, "a", { "foo": "you", "bar": "far" }, { "sequence": ["entry", ["nested"]], "mapping": { "foo": "bar" } }, { "literal": "some\ntext\n", "folded": "some text\n" }, [ { "one": "two", "three": "four" }, { "five": "six", "seven": "eight" } ], { "Folding": "Empty line\nas a line feed", "Chomping": "Clipped empty lines\n" }, [ ["one", "two"], ["three", "four"] ], { "foo": "bar" }, { "key": "value" }, { "explicit key": null, "block key\n": ["one", "two"] }, ["foo"], [ { "foo": "bar" }, ["baz", "baz"] ], "ab\n\n \n", { "foo: bar\\": "baz'" }, { "Not indented": { "By one space": "By four\n spaces\n", "Flow style": ["By two", "Also by two", "Still by two"] } }, "\\//||\\/||\n// || ||__\n", { "foo": [ "a", { "key": "value" } ] }, { "a": null, "b": null }, "foo", { "a": "b", "": "a" }, { "foo\nbar:baz\tx \\$%^&*()x": 23, "x\\ny:z\\tx $%^&*()x": 24 }, "Sammy Sosa completed another fine season with great stats.\n\n 63 Home Runs\n 0.288 Batting Average\n\nWhat a year!\n", " foo\nbar\nbaz ", { "matches %": 20 }, [ "flow in block", "Block scalar\n", { "foo": "bar" } ], { "a": "b", "c": 42, "e": "f", "g": "h", "23": false }, "ab", " 1st non-empty\n2nd non-empty 3rd non-empty ", { "top1": { "key1": "one" }, "top2": { "key2": "two" }, "top3": { "key3": "three" }, "top4": { "key4": "four" }, "top5": { "key5": "five" }, "top6": "six", "top7": "seven" }, { "hr": ["Mark McGwire", "Sammy Sosa"], "rbi": ["Sammy Sosa", "Ken Griffey"] }, "\nfolded line\nnext line\n * bullet\n\n * list\n * lines\n\nlast line\n", ["word1", "word2"], { "a": null, "b": null, "c": null }, { "nested sequences": [[[[]]], [[{}]]], "key1": [], "key2": {} }, "---word1 word2", { "implicit block key": [ { "implicit flow key": "value" } ] }, { "key ends with two colons::": "value" }, [ { "single line": null, "a": "b" }, { "multi line": null, "a": "b" } ], "a", { "key": ["item1", "item2"] }, [ "double quoted", "single quoted", "plain text", ["nested"], { "single": "pair" } ], ["unicode anchor"], [ { "key": "value", "key2": "value2" }, { "key3": "value3" } ], "trimmed\n\n\nas space", "Mark McGwire's year was crippled by a knee injury.\n", [ { "single line": null, "a": "b" }, { "multi line": null, "a": "b" } ], { "a": { "b": { "c": "d" }, "e": { "f": "g" } }, "h": "i" }, { "foo": { "bar": "baz" } }, [ { "single line": "value" }, { "multi line": "value" } ], { "single": "text", "double": "text" }, " 1st non-empty\n2nd non-empty 3rd non-empty ", [ { "item": "Super Hoop", "quantity": 1 }, { "item": "Basketball", "quantity": 4 }, { "item": "Big Shoes", "quantity": 1 } ], "a b c d\ne", { "a": ["b", ["c", "d"]] }, { "strip": "text", "clip": "text\n", "keep": "text\n" }, { "a": "b c", "d": "e f" }, ["single multiline - sequence entry"], { "1": [2, 3], "4": 5 }, [ { "bla\"keks": "foo" }, { "bla]keks": "foo" } ], "folded text\n", "foo", { "key": { "a": "b" } }, { "adjacent": "value", "readable": "value", "empty": null }, [ { "a": "b" }, { "c": "d" }, { "e": "f" }, { "g": "h" } ], { "tab": "\tstring" }, [ { "foo bar": "baz" } ], { "anchored": "value", "alias": "value" }, ["explicit indent and chomp", "chomp and explicit indent"], { "a": ["b", "c"] }, { "foo": "bar" }, [ "::vector", ": - ()", "Up, up, and away!", -123, "http://example.com/foo#bar", [ "::vector", ": - ()", "Up, up and away!", -123, "http://example.com/foo#bar" ] ], { "a": "b", "seq": ["a"], "c": "d" }, ["foo", "bar", 42], "line1 # no comment line3\n", "\n\nliteral\n \n\ntext\n", { "a": "b" }, { "k": ["a", "b"] }, "a b c d\ne", "---word1 word2", ["a", 2, 4, "d"], { "a": [ "b", "c", { "d": ["e", "f"] } ] }, { "a": " more indented\nregular\n", "b": "\n\n more indented\nregular\n" }, { "strip": "# text", "clip": "# text\n", "keep": "# text\n\n" }, { "safe": "a!\"#$%&'()*+,-./09:;<=>?@AZ[\\]^_`az{|}~ !\"#$%&'()*+,-./09:;<=>?@AZ[\\]^_`az{|}~", "safe question mark": "?foo", "safe colon": ":foo", "safe dash": "-foo" }, "line1 line2 line3\n", ["Mark McGwire", "Sammy Sosa", "Ken Griffey"], ["a"], ["a", ["b", "c"]], { "unicode": "Sosa did fine.☺", "control": "\b1998\t1999\t2000\n", "hex esc": "\r\n is \r\n", "single": "\"Howdy!\" he cried.", "quoted": " # Not a 'comment'.", "tie-fighter": "|\\-*-/|" }, [["-", "-"]], "folded text\n", { "a": 13, "1.5": "d" }, { "foo": 1, "bar": 2, "text": "a\n \nb\n\nc\n\nd\n" }, { "wanted": "love ♥ and peace ☮" }, { "name": "Mark McGwire", "accomplishment": "Mark set a major league home run record in 1998.\n", "stats": "65 Home Runs\n0.278 Batting Average\n" }, { "foo": "bar", "baz": "foo" }, "1st non-empty\n2nd non-empty 3rd non-empty", { "quoted": "Quoted \t", "block": "void main() {\n\tprintf(\"Hello, world!\\n\");\n}\n" }, { "foo": "blue", "bar": "arrr", "baz": "jazz" }, [ { "Mark McGwire": 65 }, { "Sammy Sosa": 63 }, { "Ken Griffy": 58 } ], { "1": 2, "3": 4 }, { "hr": ["Mark McGwire", "Sammy Sosa"], "rbi": ["Sammy Sosa", "Ken Griffey"] }, "k:#foo &a !t s", { "block sequence": [ "one", { "two": "three" } ] }, { "First occurrence": "Value", "Second occurrence": "Value" }, { "a true": "null d", "e 42": null }, { "foo": "bar" }, ["foo", "bar", 42], "trimmed\n\n\nas space", "scalar", { "strip": "", "clip": "", "keep": "\n" }, { "foo": { "bar": 1 }, "baz": 2 }, { "a": 47, "c": "d" }, { "implicit block key": [ { "implicit flow key": "value" } ] }, ["a", "b", "c", "c", ""], [ ["a", "b", "c"], { "a": "b", "c": "d", "e": "f" }, [] ], { "implicit block key": [ { "implicit flow key": "value" } ] }, { "a": "ab\n\ncd\nef\n" }, { "literal": "value\n", "folded": "value\n" }, { "a": [ "b", "c", { "d": ["e", "f"] } ] }, "literal\n\ttext\n", "foo \n\n\t bar\n\nbaz\n", [ { "a": "b" } ], "ab", ["plain", "double quoted", "single quoted", "block\n", "plain again"], { "a": " ", "b": " ", "c": " ", "d": " ", "e": "\n", "f": "\n", "g": "\n\n", "h": "\n\n" }, { "key": "value with\ntabs" }, { "": null }, [ { "single line": "value" }, { "multi line": "value" } ], "folded to a space,\nto a line feed, or \t \tnon-content", ["literal\n", " folded\n", "keep\n\n", " strip"], { "key": "value" }, { "american": ["Boston Red Sox", "Detroit Tigers", "New York Yankees"], "national": ["New York Mets", "Chicago Cubs", "Atlanta Braves"] }, " 1st non-empty\n2nd non-empty 3rd non-empty ", {}, [ ["a", "b"], { "a": "b" }, "a", "b", "c" ], "folded to a space,\nto a line feed, or \t \tnon-content", [ { "foo": "bar" } ], ["detected\n", "\n\n# detected\n", " explicit\n", "\t\ndetected\n"], { "top1": [ "item1", { "key2": "value2" }, "item3" ], "top2": "value2" }, { "foo": [42], "bar": [44] }, { "23": "d", "a": 4.2 }, "Document", { "Date": "2001-11-23 15:03:17 -5", "User": "ed", "Fatal": "Unknown variable \"bar\"", "Stack": [ { "file": "TopClass.py", "line": 23, "code": "x = MoreObject(\"345\\n\")\n" }, { "file": "MoreClass.py", "line": 58, "code": "foo = bar" } ] }, { "plain key": "in-line value", "": null, "quoted key": ["entry"] }, ["12", 12, "12"], { "aaa": "bbb" }, [":,"], { "sequence": ["one", "two"], "mapping": { "sky": "blue", "sea": "green" } }, { "seq": ["a", "b"] }, "here's to \"quotes\"", { "hr": 65, "avg": 0.278, "rbi": 147 }, "\n\nliteral\n \n\ntext\n", " 1st non-empty\n2nd non-empty 3rd non-empty ", "literal\n\ttext\n", { "block mapping": { "key": "value" } }, " foo\nbar\nbaz ", "ab cd\nef\n\ngh\n", "foo", { "top1": { "key1": "one" }, "top2": { "key2": "two" }, "top3": { "key3": "three" }, "top4": { "key4": "four" }, "top5": { "key5": "five" }, "top6": "six", "top7": "seven" }, [ { "url": "http://example.org" } ], { "sequence": ["one", "two"], "mapping": { "sky": "blue", "sea": "green" } }, { "invoice": 34843, "date": "2001-01-23", "bill-to": { "given": "Chris", "family": "Dumars", "address": { "lines": "458 Walkman Dr.\nSuite #292\n", "city": "Royal Oak", "state": "MI", "postal": 48046 } }, "ship-to": { "given": "Chris", "family": "Dumars", "address": { "lines": "458 Walkman Dr.\nSuite #292\n", "city": "Royal Oak", "state": "MI", "postal": 48046 } }, "product": [ { "sku": "BL394D", "quantity": 4, "description": "Basketball", "price": 450 }, { "sku": "BL4438H", "quantity": 1, "description": "Super Hoop", "price": 2392 } ], "tax": 251.42, "total": 4443.52, "comments": "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338." }, ["a", "b", "a", "b"], [ null, "block node\n", ["one", "two"], { "one": "two" } ], { "a": "scalar a", "b": "scalar a" }, { "foo": "", "": "bar" }, { "key": "value" }, "scalar %YAML 1.2", { "Folding": "Empty line\nas a line feed", "Chomping": "Clipped empty lines\n" }, { "key": "value" }, [ ["name", "hr", "avg"], ["Mark McGwire", 65, 0.278], ["Sammy Sosa", 63, 0.288] ], { "literal": "value\n", "folded": "value\n" }, { "Mark McGwire": { "hr": 65, "avg": 0.278 }, "Sammy Sosa": { "hr": 63, "avg": 0.288 } }, { "a": "b", "c": "d" }, { "key": [[["value"]]] }, { "a": 1, "b": null, "c": 3 }, { "event": "outgoing HTTP response", "timestamp": "2021-01-21T18:44:57.116Z", "remoteAddress": "127.0.0.1", "deviceId": "202BC1-BM632w-000000", "connection": "2021-01-21T18:44:57.105Z", "statusCode": 200, "headers": { "content-length": 528, "server": "GenieACS/1.2.3+20210121000910", "soapserver": "GenieACS/1.2.3+20210121000910", "content-type": "text/xml; charset=\"utf-8\"", "set-cookie": "session=ea31d97ccf6832fb" }, "body": "\nwdsx50vq1" } ] ================================================ FILE: test/yaml.ts ================================================ import test from "node:test"; import assert from "node:assert"; import * as yaml from "yaml"; import { stringify } from "../lib/common/yaml.ts"; import testCases from "./yaml-tests.json"; void test("stringify", () => { for (const testCase of testCases) { let str = stringify(testCase); if (str.startsWith(">2")) str = ">3" + str.slice(2); if (str.startsWith("|2")) str = "|3" + str.slice(2); assert.deepStrictEqual( yaml.parse(yaml.stringify(testCase)), yaml.parse(str), ); } }); ================================================ FILE: tsconfig.json ================================================ { "compilerOptions": { "lib": ["ES2022", "dom"], "module": "Preserve", "moduleResolution": "bundler", "target": "ES2022", "resolveJsonModule": true, "allowSyntheticDefaultImports": true, "alwaysStrict": true, "noImplicitReturns": true, "strictFunctionTypes": true, "isolatedModules": true, "noEmit": true, "allowImportingTsExtensions": true, "skipLibCheck": true, "jsx": "react", "jsxFactory": "m" }, "include": [ "./bin/*.ts", "./lib/**/*", "./ui/**/*", "./test/**/*", "./build/**/*" ] } ================================================ FILE: ui/app.ts ================================================ import m, { RouteResolver } from "mithril"; import layout from "./layout.tsx"; import * as store from "./store.ts"; import { invalidate } from "./reactive-store.ts"; import * as wizardPage from "./wizard-page.ts"; import * as loginPage from "./login-page.tsx"; import * as overviewPage from "./overview-page.ts"; import * as devicesPage from "./devices-page.ts"; import * as devicePage from "./device-page.ts"; import * as errorPage from "./error-page.ts"; import * as faultsPage from "./faults-page.ts"; import * as presetsPage from "./presets-page.ts"; import * as provisionsPage from "./provisions-page.ts"; import * as virtualParametersPage from "./virtual-parameters-page.ts"; import * as filesPage from "./files-page.ts"; import * as configPage from "./config-page.ts"; import * as permissionsPage from "./permissions-page.ts"; import * as usersPage from "./users-page.ts"; import Authorizer from "../lib//common/authorizer.ts"; import { contextifyComponent } from "./components.ts"; import { PermissionSet, UiConfig } from "../lib/types.ts"; import drawerComponent from "./drawer-component.ts"; import { render as renderOverlay } from "./overlay.ts"; import Expression from "../lib/common/expression.ts"; import * as viewsPage from "./views-page.ts"; export { ViewNode } from "./views.ts"; export { Signal } from "./signals.ts"; declare global { interface Window { authorizer: Authorizer; permissionSets: { [resource: string]: { access: number; validate: string; filter: string }; }[][]; username: string; clientConfig: UiConfig; configSnapshot: string; genieacsVersion: string; clockSkew: number; } } const permissionSets: PermissionSet[] = window.permissionSets.map((p) => p.map((s) => Object.fromEntries( Object.entries(s).map(([resource, { access, validate, filter }]) => [ resource, { access, validate: Expression.parse(validate), filter: Expression.parse(filter), }, ]), ), ), ); window.authorizer = new Authorizer(permissionSets); let state; function pagify(pageName, page): RouteResolver { const component: RouteResolver = { render: () => { const lastRenderTimestamp = Date.now(); let p; if (state?.error) p = m(errorPage.component, state); else p = m(contextifyComponent(page.component), state); const attrs = { page: pageName, oncreate: () => { store.fulfill(lastRenderTimestamp); }, onupdate: () => { store.fulfill(lastRenderTimestamp); }, }; return m(layout, attrs, p); }, onmatch: null, }; component.onmatch = (args, requestedPath) => { store.setTimestamp(Date.now()); invalidate(Date.now()); if (!page.init) { state = null; return null; } return new Promise((resolve) => { page .init(args) .then((st) => { if (!st) return void m.route.set("/"); state = st; resolve(); }) .catch((err) => { if (!window.username && err.message.indexOf("authorized") >= 0) m.route.set("/login", { continue: requestedPath }); state = { error: err.message }; resolve(); }); }); }; return component; } m.route(document.body, "/overview", { "/wizard": pagify("wizard", wizardPage), "/overview": pagify("overview", overviewPage), "/devices": pagify("devices", devicesPage), "/devices/:id": pagify("devices", devicePage), "/faults": pagify("faults", faultsPage), "/presets": pagify("presets", presetsPage), "/provisions": pagify("provisions", provisionsPage), "/virtualParameters": pagify("virtualParameters", virtualParametersPage), "/files": pagify("files", filesPage), "/config": pagify("config", configPage), "/users": pagify("users", usersPage), "/permissions": pagify("permissions", permissionsPage), "/views": pagify("views", viewsPage), "/login": { render: () => [m(loginPage.component), renderOverlay(), m(drawerComponent)], }, }); ================================================ FILE: ui/autocomplete-compnent.ts ================================================ type AutocompleteCallback = ( value: string, callback: (suggestions: { value: string; tip?: string }[]) => void, ) => void; export default class Autocomplete { declare private callback: AutocompleteCallback; declare private element: HTMLInputElement; declare private hideTimeout: NodeJS.Timeout; declare private visible: boolean; declare private default: string; declare private selection: number; declare private container: HTMLElement; public constructor(callback: AutocompleteCallback) { this.callback = callback; this.element = null; this.hideTimeout = null; this.visible = false; this.default = null; this.selection = null; this.container = document.createElement("div"); this.container.style.position = "absolute"; this.container.style.display = "block"; this.container.style.opacity = "0"; this.container.className = "absolute py-1 mt-2 rounded-md shadow-lg bg-white"; } public attach(el: HTMLInputElement): void { el.setAttribute("autocomplete", "off"); el.addEventListener("focus", () => { this.element = el; this.update(); this.reposition(); }); el.addEventListener("blur", () => { if (this.element !== el) return; if (!this.visible) return; this.hide(); }); el.addEventListener("keydown", (e) => { if (this.element !== el) return; if (e.key === "Escape") { if (this.visible) this.hide(); } else if (e.key === "Enter") { if (this.default != null) { el.value = this.default; e.stopImmediatePropagation(); el.dispatchEvent(new InputEvent("input")); this.update(); } } else if (e.key === "ArrowDown") { e.preventDefault(); if (this.selection == null) this.selection = 0; else ++this.selection; this.update(); } else if (e.key === "ArrowUp") { e.preventDefault(); --this.selection; this.update(); } }); el.addEventListener("input", () => { if (this.element !== el) return; this.selection = null; this.update(); }); } public reposition(): void { if (!this.element) return; const domRect = this.element.getBoundingClientRect(); if (!domRect.width) { // Element has been removed if (this.visible) this.hide(); return; } this.container.style.left = `${domRect.left + window.scrollX}px`; this.container.style.width = `${domRect.width}px`; this.container.style.top = `${domRect.bottom + window.scrollY}px`; } private hide(): void { this.container.style.opacity = "0"; this.visible = false; this.default = null; this.selection = null; clearTimeout(this.hideTimeout); this.hideTimeout = setTimeout(() => { this.hideTimeout = null; while (this.container.firstChild) this.container.removeChild(this.container.firstChild); document.body.removeChild(this.container); }, 500); } private update(): void { const el = this.element; this.callback(el.value, (suggestions) => { if (this.element !== el) return; this.default = null; if (!suggestions.length) { if (this.visible) this.hide(); return; } while (this.container.firstChild) this.container.removeChild(this.container.firstChild); if (!this.visible) { if (!this.hideTimeout) { document.body.appendChild(this.container); // Force style recalc so the initial opacity is resolved before // setting it to "1", allowing the CSS transition to play. void window.getComputedStyle(this.container).opacity; } else { clearTimeout(this.hideTimeout); this.hideTimeout = null; } this.container.style.opacity = "1"; this.visible = true; } if (this.selection != null) { this.selection = ((this.selection % suggestions.length) + suggestions.length) % suggestions.length; this.default = suggestions[this.selection].value; } else { this.default = suggestions[0].value; } let selectedElement; for (const [idx, suggestion] of suggestions.entries()) { const e = document.createElement("div"); if (suggestion.tip) e.title = suggestion.tip; e.className = "text-stone-700 block px-4 py-2 text-sm hover:bg-stone-100 hover:text-stone-900"; if (idx === this.selection) { e.classList.add("bg-stone-100", "text-stone-900"); selectedElement = e; } const t = document.createTextNode(suggestion.value); e.appendChild(t); e.addEventListener("mousedown", (ev) => { ev.preventDefault(); el.value = suggestion.value; el.dispatchEvent(new InputEvent("input")); if (this.element === el) this.update(); }); this.container.appendChild(e); } // Ensure selected element is in view if (selectedElement) { this.container.scrollTop = Math.min( this.container.scrollTop, selectedElement.offsetTop, ); this.container.scrollTop = Math.max( this.container.scrollTop, selectedElement.offsetTop + selectedElement.scrollHeight - this.container.clientHeight, ); } }); } } ================================================ FILE: ui/change-password-component.ts ================================================ import { VnodeDOM, ClosureComponent } from "mithril"; import * as notifications from "./notifications.ts"; import { changePassword } from "./store.ts"; import { m } from "./components.ts"; interface Attrs { noAuth?: boolean; username?: string; onPasswordChange: () => void; } const component: ClosureComponent = () => { return { view: (vnode) => { const onPasswordChange = vnode.attrs.onPasswordChange; const enforceAuth = !vnode.attrs.noAuth; const username = vnode.attrs.username; if (username) vnode.state["username"] = username; const form = [ m( "p", m( "label.block text-sm font-semibold text-stone-700 mt-2 mb-1", { for: "username" }, "Username", ), m( "input.shadow-sm focus:ring-cyan-500 focus:border-cyan-500 block sm:text-sm border-stone-300 rounded-md", { name: "username", type: "text", value: vnode.state["username"], disabled: !!username, oninput: (e) => { vnode.state["username"] = e.target.value; }, oncreate: (_vnode) => { (_vnode.dom as HTMLSelectElement).focus(); }, }, ), ), ]; let fields = { newPassword: "New password", confirmPassword: "Confirm password", }; if (enforceAuth) fields = Object.assign({ authPassword: "Your password" }, fields); for (const [f, l] of Object.entries(fields)) { form.push( m( "p", m( "label.block text-sm font-semibold text-stone-700 mt-2 mb-1", { for: f }, l, ), m( "input.shadow-sm focus:ring-cyan-500 focus:border-cyan-500 block sm:text-sm border-stone-300 rounded-md", { name: f, type: "password", value: vnode.state[f], oninput: (e) => { vnode.state[f] = e.target.value; }, }, ), ), ); } const submit = m( "button.ml-3 inline-flex justify-center py-2 px-4 border border-transparent shadow-xs text-sm font-medium rounded-md text-white bg-cyan-600 hover:bg-cyan-700 focus:outline-hidden focus:ring-2 focus:ring-offset-2 focus:ring-cyan-500", { type: "submit", }, "Change password", ) as VnodeDOM; form.push(m("div.flex justify-end mt-5", submit)); const children = [ m("h2.text-lg leading-6 font-medium text-stone-900", "Change password"), m( "form", { onsubmit: (e) => { e.redraw = false; e.preventDefault(); if ( !vnode.state["username"] || !vnode.state["newPassword"] || (enforceAuth && !vnode.state["authPassword"]) ) { notifications.push("error", "Please fill all fields"); } else if ( vnode.state["newPassword"] !== vnode.state["confirmPassword"] ) { notifications.push( "error", "Password confirm doesn't match new password", ); } else { (submit.dom as HTMLFormElement).disabled = true; changePassword( vnode.state["username"], vnode.state["newPassword"], vnode.state["authPassword"], ) .then(() => { notifications.push( "success", "Password updated successfully", ); if (onPasswordChange) onPasswordChange(); (submit.dom as HTMLFormElement).disabled = false; }) .catch((err) => { notifications.push("error", err.message); (submit.dom as HTMLFormElement).disabled = false; }); } }, }, form, ), ]; return m("div.put-form", children); }, }; }; export default component; ================================================ FILE: ui/code-editor-component.ts ================================================ import { ClosureComponent } from "mithril"; import { m } from "./components.ts"; import { codeMirror } from "./dynamic-loader.ts"; interface Attrs { id: string; value: string; mode: string; readOnly?: boolean; focus?: boolean; onSubmit?: (dom: Element) => void; onChange?: (value: string) => void; } const component: ClosureComponent = () => { return { view: (vnode) => { return m("div.font-mono text-sm", { oncreate: (_vnode) => { const theme = codeMirror.EditorView.theme({ "&.cm-editor": { display: "block", width: "50rem", height: "30rem", "max-width": "100%", "border-radius": "0.375rem", "border-width": "1px", "border-color": "var(--color-stone-300)", "box-shadow": "var(--tw-ring-shadow, 0 0 #0000), 0 1px 2px 0 rgb(0 0 0 / 0.05)", overflow: "hidden", "& > .cm-scroller": { "font-family": "inherit", "line-height": "inherit", }, }, "&.cm-editor.cm-focused": { outline: "none", "border-color": "var(--color-cyan-500)", "--tw-ring-shadow": "0 0 0 1px var(--color-cyan-500)", }, }); const extensions = [ theme, codeMirror.lineNumbers(), codeMirror.history(), codeMirror.syntaxHighlighting(codeMirror.defaultHighlightStyle), codeMirror.keymap.of([ ...codeMirror.defaultKeymap, ...codeMirror.historyKeymap, ]), codeMirror.EditorState.readOnly.of(!!vnode.attrs.readOnly), codeMirror.EditorView.updateListener.of((update) => { if (update.docChanged && vnode.attrs.onChange) vnode.attrs.onChange(update.state.doc.toString()); }), ]; if (vnode.attrs.mode === "javascript") extensions.push(codeMirror.javascript()); else if (vnode.attrs.mode === "jsx") extensions.push(codeMirror.javascript({ jsx: true })); else if (vnode.attrs.mode === "yaml") extensions.push(codeMirror.yaml()); const editor = new codeMirror.EditorView({ state: codeMirror.EditorState.create({ doc: vnode.attrs.value, extensions, }), parent: _vnode.dom as HTMLTextAreaElement, }); if (vnode.attrs.focus) editor.focus(); }, }); }, }; }; export default component; ================================================ FILE: ui/codemirror-loader.ts ================================================ export { EditorView, keymap, lineNumbers } from "@codemirror/view"; export { EditorState } from "@codemirror/state"; export { history, historyKeymap, defaultKeymap } from "@codemirror/commands"; export { syntaxHighlighting, defaultHighlightStyle, } from "@codemirror/language"; export { javascript } from "@codemirror/lang-javascript"; export { yaml } from "@codemirror/lang-yaml"; ================================================ FILE: ui/components/all-parameters.ts ================================================ import { ClosureComponent } from "mithril"; import { m } from "../components.ts"; import * as taskQueue from "../task-queue.ts"; import memoize from "../../lib/common/memoize.ts"; import { icon } from "../tailwind-utility-components.ts"; import { QueryResponse, evaluateExpression } from "../store.ts"; import debounce from "../../lib/common/debounce.ts"; import Expression, { Value } from "../../lib/common/expression.ts"; import { FlatDevice } from "../../lib/ui/db.ts"; import Path from "../../lib/common/path.ts"; function escapeRegExp(str): string { return str.replace(/[-[\]/{}()*+?.\\^$|]/g, "\\$&"); } interface Parameter { path: Expression.Parameter; value?: Value; writable?: boolean; object?: boolean; } const prepareParams = memoize((device: FlatDevice): Parameter[][] => { const map = new Map(); for (const [k, v] of Object.entries(device)) { const [param, attr] = k.split(":"); let attrs = map.get(param); if (!attrs) map.set( param, (attrs = { path: new Expression.Parameter(Path.parse(param)) }), ); attrs[attr || "value"] = v; } const res: Parameter[][] = []; for (const [key, attrs] of map) { let count = 0; for ( let i = key.lastIndexOf(".", key.length - 2); i >= 0; i = key.lastIndexOf(".", i - 1) ) ++count; while (res.length <= count) res.push([]); res[count].push(attrs); } return res; }); interface Attrs { device: FlatDevice; limit: Expression; deviceQuery: QueryResponse; } const component: ClosureComponent = () => { let queryString: string; const formQueryString = debounce((args: string[]) => { queryString = args[args.length - 1]; m.redraw(); }, 500); return { view: (vnode) => { const device = vnode.attrs.device; const allParams = prepareParams(device); let limit = 100; if (vnode.attrs.limit) { const l = evaluateExpression(vnode.attrs.limit, device); if (typeof l.value === "number") limit = l.value; } const search = m( "input.appearance-none border-0 block w-full px-4 py-3 border-stone-300 placeholder-stone-500 text-stone-900 focus:ring-cyan-500 text-sm rounded-t-lg font-mono focus:ring-2", { type: "text", placeholder: "Search parameters", oninput: (e) => { formQueryString(e.target.value); e.redraw = false; }, }, ); const instanceRegex = /\.[0-9]+$/; let re; if (queryString) { const keywords = queryString.split(" ").filter((s) => s); if (keywords.length) re = new RegExp(keywords.map((s) => escapeRegExp(s)).join(".*"), "i"); } const filteredParams: Parameter[] = []; let count = 0; for (const keys of allParams) { let c = 0; for (const k of keys) { const str = k.value ? `${k.path.toString()} ${k.value}` : k; if (re && !re.test(str)) continue; ++c; if (count < limit) filteredParams.push(k); } count += c; } filteredParams.sort((a, b) => { if (a.path < b.path) return -1; if (a.path > b.path) return 1; return 0; }); const rows = filteredParams.map((p) => { const val = []; if (p.value) { val.push( m( "parameter", Object.assign({ device: device, parameter: p.path }), ), ); } else if (p.object && p.writable) { if (instanceRegex.test(p.path.toString())) { val.push( m( "button", { title: "Delete this instance", onclick: () => { taskQueue.queueTask({ name: "deleteObject", device: device["DeviceID.ID"] as string, objectName: p.path.toString(), }); }, }, m(icon, { name: "delete-instance", class: "inline h-4 w-4 ml-1 text-cyan-700 hover:text-cyan-900", }), ), ); } else { val.push( m( "button", { title: "Create a new instance", onclick: () => { taskQueue.queueTask({ name: "addObject", device: device["DeviceID.ID"] as string, objectName: p.path.toString(), }); }, }, m(icon, { name: "add-instance", class: "inline h-4 w-4 ml-1 text-cyan-700 hover:text-cyan-900", }), ), ); } } val.push( m( "button", { title: "Refresh tree", onclick: () => { taskQueue.queueTask({ name: "getParameterValues", device: device["DeviceID.ID"] as string, parameterNames: [p.path.toString()], }); }, }, m(icon, { name: "refresh", class: "inline h-4 w-4 ml-1 text-cyan-700 hover:text-cyan-900", }), ), ); return m( "tr", m( "td.pl-4 pr-2 py-2 truncate", m("long-text", { text: p.path.toString() }), ), m("td.pr-4 py-2 text-right flex justify-end", val), ); }); return m( "loading", { queries: [vnode.attrs.deviceQuery] }, m( ".bg-white shadow-sm rounded-lg", search, m( ".overflow-hidden", m( ".overflow-y-scroll h-96 shadow-inner", m( "table.w-full table-fixed font-mono text-xs text-stone-900", m("tbody.divide-y divide-stone-200", rows), ), ), m( "div.text-stone-700 px-4 py-3 flex justify-between items-end", m( "span.text-xs", "Displaying ", m("span.font-medium", "" + filteredParams.length), " out of ", m("span.font-medium", "" + count), " parameters", ), m( "a.text-cyan-700 hover:text-cyan-900 text-sm font-medium", { href: `api/devices/${encodeURIComponent( device["DeviceID.ID"], )}.csv`, download: "", }, "Download", ), ), ), ), ); }, }; }; export default component; ================================================ FILE: ui/components/container.ts ================================================ import { Attributes, ClosureComponent } from "mithril"; import memoize from "../../lib/common/memoize.ts"; import Expression from "../../lib/common/expression.ts"; import { m } from "../components.ts"; import { evaluateExpression, getTimestamp } from "../store.ts"; import { FlatDevice } from "../../lib/ui/db.ts"; const evaluateAttributes = memoize( ( attrs: Record, obj: Record, now: number, // eslint-disable-line @typescript-eslint/no-unused-vars ): Attributes => { const res: Attributes = {}; for (const [k, v] of Object.entries(attrs)) { const vv = v.evaluate((e) => { if (e instanceof Expression.Literal) return e; else if (e instanceof Expression.FunctionCall) { if (e.name === "ENCODEURICOMPONENT") { const a = evaluateExpression(e.args[0], obj); if (a instanceof Expression.Literal) { if (a.value == null) return new Expression.Literal(null); return new Expression.Literal(encodeURIComponent(a.value)); } } } return e; }); res[k] = evaluateExpression(vv, obj); } return res; }, ); interface Attrs { device: FlatDevice; filter: Expression; components: unknown; } const component: ClosureComponent = () => { return { view: (vnode) => { const device = vnode.attrs.device; if ("filter" in vnode.attrs) { if (!evaluateExpression(vnode.attrs.filter, device || {}).value) return null; } const children = Object.values(vnode.attrs.components).map((c) => { if (c instanceof Expression) c = evaluateExpression(c, device || {}).value; if (typeof c !== "object") return `${c}`; const type = evaluateExpression(c["type"], device || {}).value; if (!type) return null; return m(type as string, c); }); let el = vnode.attrs["element"]; if (el == null) return children; let attrs: Attributes; if (el instanceof Expression) { el = evaluateExpression(el, device || {}).value; } else if (typeof el === "object") { if (el["attributes"] != null) { attrs = evaluateAttributes( el["attributes"], device || {}, getTimestamp(), ); } el = evaluateExpression(el["tag"], device || {}).value; } return m(el, attrs, children); }, }; }; export default component; ================================================ FILE: ui/components/device-actions.ts ================================================ import { ClosureComponent, Component } from "mithril"; import { m } from "../components.ts"; import * as taskQueue from "../task-queue.ts"; import * as notifications from "../notifications.ts"; import * as store from "../store.ts"; const component: ClosureComponent = (): Component => { return { view: (vnode) => { const device = vnode.attrs["device"]; const buttons = []; buttons.push( m( "button.px-4 py-2 border border-stone-300 shadow-xs text-sm font-medium rounded-md text-stone-700 bg-white hover:bg-stone-50 focus:outline-hidden focus:ring-2 focus:ring-offset-2 focus:ring-cyan-500 disabled:opacity-50 disabled:cursor-not-allowed", { title: "Reboot device", onclick: () => { taskQueue.queueTask({ name: "reboot", device: device["DeviceID.ID"], }); }, }, "Reboot", ), ); buttons.push( m( "button.px-4 py-2 border border-stone-300 shadow-xs text-sm font-medium rounded-md text-stone-700 bg-white hover:bg-stone-50 focus:outline-hidden focus:ring-2 focus:ring-offset-2 focus:ring-cyan-500 disabled:opacity-50 disabled:cursor-not-allowed", { title: "Factory reset device", onclick: () => { taskQueue.queueTask({ name: "factoryReset", device: device["DeviceID.ID"], }); }, }, "Reset", ), ); buttons.push( m( "button.px-4 py-2 border border-stone-300 shadow-xs text-sm font-medium rounded-md text-stone-700 bg-white hover:bg-stone-50 focus:outline-hidden focus:ring-2 focus:ring-offset-2 focus:ring-cyan-500 disabled:opacity-50 disabled:cursor-not-allowed", { title: "Push a firmware or a config file", onclick: () => { taskQueue.stageDownload({ name: "download", devices: [device["DeviceID.ID"]], }); }, }, "Push file", ), ); buttons.push( m( "button.px-4 py-2 border border-stone-300 shadow-xs text-sm font-medium rounded-md text-stone-700 bg-white hover:bg-stone-50 focus:outline-hidden focus:ring-2 focus:ring-offset-2 focus:ring-cyan-500 disabled:opacity-50 disabled:cursor-not-allowed", { title: "Delete device", onclick: () => { if (!confirm("Deleting this device. Are you sure?")) return; const deviceId = device["DeviceID.ID"]; store .deleteResource("devices", deviceId) .then(() => { notifications.push("success", `${deviceId}: Device deleted`); m.route.set("/devices"); }) .catch((err) => { notifications.push("error", err.message); }); }, }, "Delete", ), ); return m("div.flex gap-3 mt-4", buttons); }, }; }; export default component; ================================================ FILE: ui/components/device-faults.ts ================================================ import { ClosureComponent, Component } from "mithril"; import { m } from "../components.ts"; import * as store from "../store.ts"; import { invalidate } from "../reactive-store.ts"; import * as notifications from "../notifications.ts"; import { stringify } from "../../lib/common/yaml.ts"; import Expression from "../../lib/common/expression.ts"; import Path from "../../lib/common/path.ts"; const component: ClosureComponent = (): Component => { return { view: (vnode) => { const device = vnode.attrs["device"]; const deviceId = device["DeviceID.ID"]; const p = new Expression.Parameter(Path.parse("_id")); const exp = Expression.and( new Expression.Binary(">", p, new Expression.Literal(`${deviceId}:`)), new Expression.Binary( "<", p, new Expression.Literal(`${deviceId}:zzzz`), ), ); const faults = store.fetch("faults", exp); const headers = [ "Channel", "Code", "Message", "Detail", "Retries", "Timestamp", "", ].map((l, i) => { let padding: string; if (i === 0) padding = "pl-6 pr-3"; else if (i === 6) padding = "pl-3"; else padding = "px-3"; return m( "th", { scope: "col", class: "py-3.5 text-left text-sm font-semibold text-stone-500 " + padding, }, l, ); }); const thead = m("thead.bg-stone-50", m("tr", headers)); const rows = []; for (const f of faults.value) { rows.push( m( "tr", m( "td.whitespace-nowrap pl-6 pr-3 py-4 text-sm text-stone-900", f["channel"], ), m( "td.whitespace-nowrap px-3 py-4 text-sm text-stone-900", f["code"], ), m( "td.whitespace-nowrap px-3 py-4 text-sm text-stone-900", m("long-text", { text: f["message"], class: "max-w-xs" }), ), m( "td.whitespace-nowrap px-3 py-4 text-sm text-stone-900", m("long-text", { text: stringify(f["detail"]), class: "max-w-xs", }), ), m( "td.whitespace-nowrap px-3 py-4 text-sm text-stone-900", f["retries"], ), m( "td.whitespace-nowrap px-3 py-4 text-sm text-stone-900", new Date(f["timestamp"]).toLocaleString(), ), m( "td.whitespace-nowrap pl-3 pr-6 py-4 text-sm text-stone-900", m( "button", { class: "text-cyan-700 hover:text-cyan-900 font-medium", title: "Delete fault", onclick: (e) => { e.redraw = false; store .deleteResource("faults", f["_id"]) .then(() => { notifications.push("success", "Fault deleted"); store.setTimestamp(Date.now()); invalidate(Date.now()); m.redraw(); }) .catch((err) => { notifications.push("error", err.message); store.setTimestamp(Date.now()); invalidate(Date.now()); }); }, }, "Delete", ), ), ), ); } if (!rows.length) { rows.push( m( "tr", m( "td.bg-stripes text-sm font-medium text-center text-stone-500 p-4", { colspan: headers.length }, "No faults", ), ), ); } return m( "loading", { queries: [faults] }, m( "div.shadow-sm overflow-hidden rounded-lg w-max", m( "table.divide-y divide-stone-200", thead, m("tbody.divide-y divide-stone-200 bg-white", rows), ), ), ); }, }; }; export default component; ================================================ FILE: ui/components/device-link.ts ================================================ import { ClosureComponent, Component } from "mithril"; import { m } from "../components.ts"; import { evaluateExpression } from "../store.ts"; import Expression from "../../lib/common/expression.ts"; const component: ClosureComponent = (): Component => { return { view: (vnode) => { let deviceId; const device = vnode.attrs["device"]; if (device) deviceId = device["DeviceID.ID"]; const children = Object.values(vnode.attrs["components"]).map((c) => { if (c instanceof Expression) c = evaluateExpression(c, device ?? {}).value; if (typeof c !== "object") return `${c}`; const type = evaluateExpression(c["type"], device ?? {}).value; if (!type) return null; const attrs = Object.assign({}, vnode.attrs, c); return m(type as string, attrs); }); if (deviceId) { return m( "a.text-cyan-700 hover:text-cyan-900 font-medium", { href: `#!/devices/${encodeURIComponent(deviceId)}` }, children, ); } else { return children; } }, }; }; export default component; ================================================ FILE: ui/components/loading.ts ================================================ import { VnodeDOM, ClosureComponent, Component } from "mithril"; const component: ClosureComponent = (): Component => { let overlay: HTMLElement; let dom: Element; let loading = false; function apply(vnode: VnodeDOM): void { if (!loading) { if (overlay) overlay.parentElement.remove(); if (dom) dom.classList.remove("loading"); overlay = null; dom = null; return; } if (dom && dom !== vnode.dom) dom.classList.remove("loading"); dom = vnode.dom; dom.classList.add("loading"); if (!overlay) { const wrapper = document.createElement("div"); wrapper.style.position = "relative"; wrapper.style.pointerEvents = "none"; overlay = document.createElement("div"); overlay.classList.add("loading-overlay"); overlay.style.position = "absolute"; wrapper.appendChild(overlay); } const wrapper = overlay.parentElement; if (wrapper.parentElement !== dom.parentElement) dom.parentNode.appendChild(wrapper); const wrapperRect = wrapper.getBoundingClientRect(); const domRect = dom.getBoundingClientRect(); overlay.style.width = `${dom.scrollWidth}px`; overlay.style.height = `${dom.scrollHeight}px`; overlay.style.left = `${domRect.left - wrapperRect.left}px`; overlay.style.top = `${domRect.top - wrapperRect.top}px`; } return { view: (vnode) => { const queries = vnode.attrs["queries"]; loading = queries.some((q) => q.fulfilling); return vnode.children; }, oncreate: apply, onupdate: apply, onremove: () => { if (overlay) overlay.parentElement.remove(); if (dom) dom.classList.remove("loading"); overlay = null; dom = null; }, }; }; export default component; ================================================ FILE: ui/components/overview-dot.ts ================================================ import { ClosureComponent, Component } from "mithril"; import { m } from "../components.ts"; import { overview } from "../config.ts"; import { evaluateExpression } from "../store.ts"; const CHARTS = overview.charts; const component: ClosureComponent = (): Component => { return { view: (vnode) => { const device = vnode.attrs["device"]; const chartName = evaluateExpression( vnode.attrs["chart"], device ?? {}, ).value; const chart = CHARTS[chartName as string]; if (!chart) return null; for (const slice of chart.slices) { const filter = slice.filter; if (evaluateExpression(filter, device ?? {}).value) { const dot = m( "svg.inline", { width: "1em", height: "1em", style: "margin: 0 0.2em 0.2em", xmlns: "http://www.w3.org/2000/svg", "xmlns:xlink": "http://www.w3.org/1999/xlink", }, m("circle.stroke-stone-200 stroke-1", { cx: "0.5em", cy: "0.5em", r: "0.4em", fill: slice.color, }), ); return m("span", dot, slice.label); } } return null; }, }; }; export default component; ================================================ FILE: ui/components/parameter-list.ts ================================================ import { ClosureComponent, VnodeDOM } from "mithril"; import { m } from "../components.ts"; import { QueryResponse, evaluateExpression } from "../store.ts"; import { FlatDevice } from "../../lib/ui/db.ts"; import Expression from "../../lib/common/expression.ts"; interface Attrs { device: FlatDevice; parameters: Record< string, { type?: Expression; label: Expression; parameter: Expression } >; deviceQuery: QueryResponse; } const component: ClosureComponent = () => { return { view: (vnode) => { const device = vnode.attrs.device; const rows = Object.values(vnode.attrs.parameters).map((parameter) => { let type = "parameter"; if (parameter.type) { const t = evaluateExpression(parameter.type, device); if (typeof t.value === "string") type = t.value; } const p = m.context( { device: device, parameter: parameter.parameter, }, (type as string) || "parameter", parameter, ); return m( "div.py-3 grid grid-cols-3 gap-4 px-6", { oncreate: (vn) => { (vn.dom as HTMLElement).style.display = (p as VnodeDOM).dom ? "" : "none"; }, onupdate: (vn) => { (vn.dom as HTMLElement).style.display = (p as VnodeDOM).dom ? "" : "none"; }, }, m( "dt.text-sm font-medium text-stone-500", evaluateExpression(parameter["label"], device).value, ), m("dd.text-sm text-stone-900 col-span-2", p), ); }); return m( "loading", { queries: [vnode.attrs.deviceQuery] }, m( "dl.bg-white shadow-sm overflow-hidden rounded-lg w-max py-1", { class: "[&>*+*]:border-t [&>*+*]:border-stone-200" }, rows, ), ); }, }; }; export default component; ================================================ FILE: ui/components/parameter-table.ts ================================================ import { ClosureComponent } from "mithril"; import { m } from "../components.ts"; import * as taskQueue from "../task-queue.ts"; import { QueryResponse, evaluateExpression } from "../store.ts"; import { icon } from "../tailwind-utility-components.ts"; import { FlatDevice } from "../../lib/ui/db.ts"; import Expression from "../../lib/common/expression.ts"; import Path from "../../lib/common/path.ts"; interface Attrs { device: FlatDevice; parameter: Expression; label: Expression; childParameters: Record; filter?: Expression; deviceQuery: QueryResponse; } const component: ClosureComponent = () => { let object: Path; let parameters: { label: Expression; parameter: Expression }[]; return { oninit: (vnode) => { const obj = vnode.attrs.parameter; if (!(obj instanceof Expression.Parameter)) throw new Error("Object must be a parameter path"); object = obj.path; parameters = Object.values(vnode.attrs.childParameters); }, view: (vnode) => { const device = vnode.attrs.device; const instances: Set = new Set(); const prefix = `${object.toString()}.`; for (const p in device) { if (!p.startsWith(prefix)) continue; if (p.lastIndexOf(":") !== -1) continue; const i = p.indexOf(".", prefix.length); if (i === -1) instances.add(p); else instances.add(p.slice(0, i)); } const headers = parameters.map((p, i) => { const padding = i ? "px-3" : "pl-6 pr-3"; return m( "th", { scope: "col", class: "py-3.5 text-left text-sm font-semibold text-stone-500 " + padding, }, evaluateExpression(p.label, device).value, ); }); headers.push(m("th.pl-3", { scope: "col" })); const thead = m("thead.bg-stone-50", m("tr", headers)); const rows = []; for (const i of instances) { let filter: Expression = "filter" in vnode.attrs ? vnode.attrs.filter : new Expression.Literal(true); const root = Path.parse(i); filter = filter.evaluate((e) => { if (e instanceof Expression.Parameter) return new Expression.Parameter(root.concat(e.path)); return e; }); if (!evaluateExpression(filter, device).value) continue; const row = parameters.map((p, j) => { const padding = j ? "px-3" : "pl-6 pr-3"; const param = p.parameter.evaluate((e) => { if (e instanceof Expression.Parameter) return new Expression.Parameter(root.concat(e.path)); return e; }); let type = "parameter"; if (p["type"] instanceof Expression) type = evaluateExpression(p["type"], device).value + ""; return m( "td", { class: "whitespace-nowrap py-4 text-sm text-stone-900 " + padding, }, m.context( { device: device, parameter: param, }, type, Object.assign({}, p, { device: device, parameter: param, label: null, }), ), ); }); if (device[i + ":writable"]) { row.push( m( "td", { class: "whitespace-nowrap pl-3 pr-6 py-4 text-sm text-stone-900", }, m( "button", { title: "Delete this instance", onclick: () => { taskQueue.queueTask({ name: "deleteObject", device: device["DeviceID.ID"] as string, objectName: i, }); }, }, m(icon, { name: "delete-instance", class: "inline h-4 w-4 text-cyan-700 hover:text-cyan-900", }), ), ), ); } else { row.push(m("td")); } rows.push(m("tr", row)); } if (!rows.length) { rows.push( m( "tr", m( "td.bg-stripes text-sm font-medium text-center text-stone-500 p-4", { colspan: headers.length }, "No instances", ), ), ); } if (device[object.toString() + ":writable"]) { rows.push( m( "tr", m("td", { colspan: headers.length }), m( "td", m( "button", { title: "Create a new instance", onclick: () => { taskQueue.queueTask({ name: "addObject", device: device["DeviceID.ID"] as string, objectName: object.toString(), }); }, }, m(icon, { name: "add-instance", class: "inline h-4 w-4 ml-1 text-cyan-700 hover:text-cyan-900", }), ), ), ), ); } let label; const l = evaluateExpression(vnode.attrs.label, device).value; if (l != null) label = m("h2", l); return [ label, m( "loading", { queries: [vnode.attrs.deviceQuery] }, m( "div.shadow-sm overflow-hidden rounded-lg w-max", m( "table.divide-y divide-stone-200", thead, m("tbody.divide-y divide-stone-200 bg-white", rows), ), ), ), ]; }, }; }; export default component; ================================================ FILE: ui/components/parameter.ts ================================================ import { ClosureComponent, Component, VnodeDOM } from "mithril"; import { m } from "../components.ts"; import * as taskQueue from "../task-queue.ts"; import { getTimestamp } from "../store.ts"; import { getClockSkew } from "../skewed-date.ts"; import Expression, { Value } from "../../lib/common/expression.ts"; import memoize from "../../lib/common/memoize.ts"; import timeAgo from "../timeago.ts"; import { icon } from "../tailwind-utility-components.ts"; const evaluateParam = memoize( ( exp: Expression, obj: any, now: number, ): { value: Value; timestamp: number; parameter: string } => { let timestamp = now; const valueMap: Map = new Map(); const lit = exp.evaluate((e): Expression.Literal => { if (e instanceof Expression.Literal) return e; if (e instanceof Expression.Parameter) { let v = obj[e.path.toString()]; if (v) { timestamp = Math.min( timestamp, obj[e.path.toString() + ":valueTimestamp"] ?? 0, ); const t = obj[e.path.toString() + ":type"]; if (t === "xsd:dateTime" && typeof v === "number") v = new Date(v).toLocaleString(); const val = new Expression.Literal(v); valueMap.set(val, e.path.toString()); return val; } } else if (e instanceof Expression.FunctionCall) { if (e.name === "NOW") return new Expression.Literal(now); else if (e.name === "DATE_STRING") { const v = e.args[0]; if (v instanceof Expression.Literal) { return new Expression.Literal( new Date(v.value as string | number).toLocaleString(), ); } } } return new Expression.Literal(null); }); return { value: lit.value, timestamp, parameter: valueMap.get(lit) }; }, ); const component: ClosureComponent = (): Component => { return { view: (vnode) => { const device = vnode.attrs["device"]; const { value, timestamp, parameter } = evaluateParam( vnode.attrs["parameter"], device, getTimestamp() + getClockSkew(), ); if (value == null) return null; let edit; if (device[parameter + ":writable"]) { edit = m( "button", { title: "Edit parameter value", onclick: () => { taskQueue.stageSpv({ name: "setParameterValues", devices: [device["DeviceID.ID"]], parameterValues: [ [parameter, device[parameter], device[parameter + ":type"]], ], }); }, }, m(icon, { name: "edit", class: "inline h-4 w-4 ml-1 text-cyan-700 hover:text-cyan-900", }), ); } const el = m("long-text", { text: `${value}` }); return m( "span.inline-flex overflow-hidden align-top", { onmouseover: (e) => { e.redraw = false; // Don't update any child element if (e.target === (el as VnodeDOM).dom) { const now = Date.now() + getClockSkew(); const localeString = new Date(timestamp).toLocaleString(); e.target.title = `${localeString} (${timeAgo(now - timestamp)})`; } }, }, m("span.truncate", el), edit, ); }, }; }; export default component; ================================================ FILE: ui/components/ping.ts ================================================ import { ClosureComponent, Component, VnodeDOM } from "mithril"; import { m } from "../components.ts"; import * as store from "../store.ts"; const REFRESH_INTERVAL = 3000; const component: ClosureComponent = (vn): Component => { let interval: ReturnType; let host: string; const refresh = (): void => { if (!host) { const dom = (vn as VnodeDOM).dom; if (dom) dom.innerHTML = ""; return; } let status = ""; store .ping(host) .then((res) => { if (res["avg"] != null) status = `${Math.trunc(res["avg"])} ms`; else status = "Unreachable"; }) .catch(() => { status = "Error!"; clearInterval(interval); }) .finally(() => { const dom = (vn as VnodeDOM).dom; if (dom) dom.innerHTML = `Pinging ${host}: ${status}`; }); }; return { onremove: () => { clearInterval(interval); }, view: (vnode) => { const device = vnode.attrs["device"]; let param = device["InternetGatewayDevice.ManagementServer.ConnectionRequestURL"]; if (!param) param = device["Device.ManagementServer.ConnectionRequestURL"]; let h; try { const url = new URL(param.value[0]); h = url.hostname; } catch { // Ignore } if (host !== h) { host = h; clearInterval(interval); if (host) { refresh(); interval = setInterval(refresh, REFRESH_INTERVAL); } } return m("div.text-sm my-4", host ? `Pinging ${host}:` : ""); }, }; }; export default component; ================================================ FILE: ui/components/summon-button.ts ================================================ import { ClosureComponent } from "mithril"; import { m } from "../components.ts"; import * as taskQueue from "../task-queue.ts"; import * as store from "../store.ts"; import { invalidate } from "../reactive-store.ts"; import * as notifications from "../notifications.ts"; import Expression from "../../lib/common/expression.ts"; import { FlatDevice } from "../../lib/ui/db.ts"; interface Attrs { device: FlatDevice; parameters: Record; } const component: ClosureComponent = () => { return { view: (vnode) => { const device = vnode.attrs.device; return m( "button", { class: "px-2.5 py-1.5 border border-transparent text-xs font-medium rounded-sm shadow-xs text-white bg-cyan-600 hover:bg-cyan-700 focus:outline-hidden focus:ring-2 focus:ring-offset-2 focus:ring-cyan-500", title: "Initiate session and refresh basic parameters", onclick: (e) => { e.target.disabled = true; const params = Object.values(vnode.attrs["parameters"]) .map((exp) => { if (exp instanceof Expression.Parameter) return exp.path.toString(); return null; }) .filter((exp) => !!exp); const task = { name: "getParameterValues", parameterNames: params, device: device["DeviceID.ID"] as string, }; taskQueue .commit( [task], (deviceId, err, connectionRequestStatus, tasks2) => { if (err) { notifications.push("error", `${deviceId}: ${err.message}`); return; } for (const t of tasks2) if (t.status === "stale") taskQueue.deleteTask(t); if (connectionRequestStatus !== "OK") { notifications.push( "error", `${deviceId}: ${connectionRequestStatus}`, ); } else if (tasks2[0].status === "stale") { notifications.push( "error", `${deviceId}: No contact from device`, ); } else if (tasks2[0].status === "fault") { notifications.push("error", `${deviceId}: Refresh faulted`); } else { notifications.push("success", `${deviceId}: Summoned`); } }, ) .then(() => { e.target.disabled = false; store.setTimestamp(Date.now()); invalidate(Date.now()); }) .catch((err) => { e.target.disabled = false; notifications.push("error", err.message); }); }, }, "Summon", ); }, }; }; export default component; ================================================ FILE: ui/components/tags.ts ================================================ import { ClosureComponent } from "mithril"; import { m } from "../components.ts"; import * as notifications from "../notifications.ts"; import * as store from "../store.ts"; import { invalidate } from "../reactive-store.ts"; import { icon } from "../tailwind-utility-components.ts"; import { decodeTag } from "../../lib/util.ts"; import Expression from "../../lib/common/expression.ts"; import { FlatDevice } from "../../lib/ui/db.ts"; interface Attrs { device: FlatDevice; writable?: Expression; } const component: ClosureComponent = () => { return { view: (vnode) => { const device = vnode.attrs.device; let writable = true; if ("writable" in vnode.attrs) writable = !!store.evaluateExpression(vnode.attrs.writable, device) .value; const tags = []; for (const p of Object.keys(device)) if (p.startsWith("Tags.") && p.lastIndexOf(":") === -1) tags.push(decodeTag(p.slice(5))); tags.sort(); if (!writable) { return m( "div", tags.map((t) => m( "span", { class: "inline-flex items-center px-3 py-0.5 rounded-full text-sm font-medium bg-yellow-100 text-yellow-800 mr-2 -my-0.5 ring-1 ring-yellow-200", }, t, ), ), ); } return m( "div", tags.map((tag) => m( "span", { class: "inline-flex items-center pl-3 pr-1 py-0.5 rounded-full text-sm font-medium bg-yellow-100 text-yellow-800 mr-2 ring-1 ring-yellow-200", }, tag, m( "button", { title: "Remove tag", class: "flex-shrink-0 ml-0.5 h-4 w-4 rounded-full inline-flex items-center justify-center text-yellow-400 hover:bg-yellow-200 hover:text-yellow-500 focus:outline-hidden focus:bg-yellow-500 focus:text-white", onclick: (e) => { e.target.disabled = true; const deviceId = device["DeviceID.ID"] as string; store .updateTags(deviceId, { [tag]: false }) .then(() => { e.target.disabled = false; notifications.push( "success", `${deviceId}: Tags updated`, ); store.setTimestamp(Date.now()); invalidate(Date.now()); }) .catch((err) => { e.target.disabled = false; notifications.push( "error", `${deviceId}: ${err.message}`, ); }); }, }, m("span.sr-only", "Remove tag"), m(icon, { name: "remove", class: "h-4 w-4", }), ), ), ), m( "span", { class: "inline-flex items-center pl-1 pr-1 py-0.5 rounded-full text-sm font-medium bg-yellow-50 ring-1 ring-yellow-200", }, m.trust("​"), m( "button", { title: "Add tag", class: "flex-shrink-0 h-4 w-4 rounded-full inline-flex items-center justify-center text-yellow-400 hover:bg-yellow-200 hover:text-yellow-500 focus:outline-hidden focus:bg-yellow-500 focus:text-white", onclick: (e) => { e.target.disabled = true; const deviceId = device["DeviceID.ID"] as string; const tag = prompt(`Enter tag to assign to device:`); if (!tag) { e.target.disabled = false; return; } store .updateTags(deviceId, { [tag]: true }) .then(() => { e.target.disabled = false; notifications.push("success", `${deviceId}: Tags updated`); store.setTimestamp(Date.now()); invalidate(Date.now()); }) .catch((err) => { e.target.disabled = false; notifications.push("error", `${deviceId}: ${err.message}`); }); }, }, m("span.sr-only", "Add tag"), m(icon, { name: "add", class: "h-4 w-4", }), ), ), ); }, }; }; export default component; ================================================ FILE: ui/components.ts ================================================ import m, { Static, Attributes, Children, ComponentTypes, CommonAttributes, ClosureComponent, Vnode, } from "mithril"; import parameter from "./components/parameter.ts"; import parameterList from "./components/parameter-list.ts"; import parameterTable from "./components/parameter-table.ts"; import overviewDot from "./components/overview-dot.ts"; import container from "./components/container.ts"; import summonButton from "./components/summon-button.ts"; import deviceFaults from "./components/device-faults.ts"; import allParameters from "./components/all-parameters.ts"; import deviceActions from "./components/device-actions.ts"; import tags from "./components/tags.ts"; import ping from "./components/ping.ts"; import deviceLink from "./components/device-link.ts"; import longTextComponent from "./long-text-component.ts"; import loading from "./components/loading.ts"; const comps = { parameter, "parameter-list": parameterList, "parameter-table": parameterTable, "overview-dot": overviewDot, container, "summon-button": summonButton, "device-faults": deviceFaults, "all-parameters": allParameters, "device-actions": deviceActions, tags, ping, "device-link": deviceLink, "long-text": longTextComponent, loading: loading, }; const contextifiedComponents = new WeakMap(); const vnodeContext = new WeakMap(); interface MC extends Static { context: { ( ctx: Attributes, selector: string, ...children: Children[] ): Vnode; ( ctx: Attributes, selector: string, attributes: Attributes, ...children: Children[] ): Vnode; ( ctx: Attributes, component: ComponentTypes, ...args: Children[] ): Vnode; ( ctx: Attributes, component: ComponentTypes, attributes: Attrs & CommonAttributes, ...args: Children[] ): Vnode; }; } const M = new Proxy(m, { apply: (target, thisArg, argumentsList) => { const c = argumentsList[0]; if (typeof c !== "string") argumentsList[0] = contextifyComponent(c); else if (comps[c]) argumentsList[0] = contextifyComponent(comps[c]); return Reflect.apply(target, undefined, argumentsList); }, get: (target, prop) => { if (prop === "context") return contextFn; else return Reflect.get(target, prop); }, }) as MC; function contextFn(context, ...argumentsList): Vnode { const vnode = Reflect.apply(M, undefined, argumentsList); vnodeContext.set(vnode, context); return vnode; } function applyContext(vnode, parentContext): void { if (Array.isArray(vnode)) { for (const c of vnode) applyContext(c, parentContext); } else if (vnode && typeof vnode === "object" && vnode.tag) { const vc = Object.assign({}, parentContext, vnodeContext.get(vnode)); if (typeof vnode.tag !== "string") { vnodeContext.set(vnode, vc); vnode.attrs = Object.assign({}, vc, vnode.attrs); } if (vnode.children?.length) for (const c of vnode.children) applyContext(c, vc); } } export function contextifyComponent(component: ComponentTypes): ComponentTypes { let c = contextifiedComponents.get(component); if (!c) { if (typeof component !== "function") { c = Object.assign({}, component); const view = component.view; c.view = function (vnode) { const context = vnodeContext.get(vnode) || {}; const res = Reflect.apply(view, this, [vnode]); applyContext(res, context); return res; }; } else if (!component.prototype?.view) { c = (initialNode) => { const state = (component as ClosureComponent)(initialNode); const view = state.view; state.view = function (vnode) { const context = vnodeContext.get(vnode) || {}; try { const res = Reflect.apply(view, this, [vnode]); applyContext(res, context); return res; } catch (err) { return m( "p.text-sm font-bold text-red-500 cursor-pointer", { title: "Click to print stack trace to console", onclick: () => console.error(err), }, "Error!", ); } }; return state; }; } else { // TODO support class components throw new Error("Class components not supported"); } contextifiedComponents.set(component, c); } return c; } export { M as m }; ================================================ FILE: ui/config-functions.ts ================================================ interface Config { _id: string; value: string; } interface Diff { add: Config[]; remove: string[]; } export function flattenConfig(config: Record): any { const flatten = {}; const recuresive = (obj: any, root: string): void => { for (const [k, v] of Object.entries(obj)) { const key = root ? `${root}.${k}` : k; if (v === undefined) continue; if (v === null || typeof v !== "object") flatten[key] = v; else recuresive(v, key); } }; if (config !== null && typeof config === "object") recuresive(config, ""); return flatten; } // Order keys such that nested objects come last function orderKeys(config: any): number { let res = 1; if (config == null || typeof config !== "object") return res; if (Array.isArray(config)) { for (const c of config) res += orderKeys(c); return res; } const weights: [string, number][] = Object.entries(config).map(([k, v]) => [ k, orderKeys(v), ]); weights.sort((a, b) => { if (a[1] !== b[1]) return a[1] - b[1]; if (b[0] > a[0]) return -1; else return 1; }); for (const [k, w] of weights) { res += w; const v = config[k]; delete config[k]; config[k] = v; } return res; } export function structureConfig(config: Config[]): any { config.sort((a, b) => (a._id > b._id ? 1 : a._id < b._id ? -1 : 0)); const _config = {}; for (const c of config) { const keys = c._id.split("."); let ref = _config; while (keys.length > 1) { const k = keys.shift(); if (ref[k] == null || typeof ref[k] !== "object") ref[k] = {}; ref = ref[k]; } ref[keys[0]] = c.value; } const toArray = function (object): any { const MAX_BITS = 30; const MAX_ARRAY_SIZE = MAX_BITS * 10; if (object == null || typeof object !== "object") return object; if (Object.keys(object).length <= MAX_ARRAY_SIZE) { let indexes = []; for (const key of Object.keys(object)) { const idx = Math.floor(+key); if (idx >= 0 && idx < MAX_ARRAY_SIZE && String(idx) === key) { const pos = Math.floor(idx / MAX_BITS); if (!indexes[pos]) indexes[pos] = 0; indexes[pos] |= 1 << (idx % MAX_BITS); } else { indexes = []; break; } } let index = 0; while (indexes.length && (index = indexes.shift()) === 1073741823); if (index && (~index & (index + 1)) === index + 1) { // its an array const array = []; for (let i = 0; i < Object.keys(object).length; i++) array[i] = object[i]; object = array; } } for (const [k, v] of Object.entries(object)) object[k] = toArray(v); return object; }; const res = toArray(_config); orderKeys(res); return res; } export function diffConfig( current: Record, target: Record, ): Diff { const diff = { add: [], remove: [], }; for (const [k, v] of Object.entries(target)) if (v && current[k] !== v) diff.add.push({ _id: k, value: v }); for (const k of Object.keys(current)) if (!target[k]) diff.remove.push(k); return diff; } ================================================ FILE: ui/config-page.ts ================================================ import { ClosureComponent, Component, Children } from "mithril"; import { m } from "./components.ts"; import * as store from "./store.ts"; import * as notifications from "./notifications.ts"; import putFormComponent from "./put-form-component.ts"; import uiConfigComponent from "./ui-config-component.ts"; import * as overlay from "./overlay.ts"; import Expression from "../lib/common/expression.ts"; import { loadCodeMirror, loadYaml } from "./dynamic-loader.ts"; import { icon } from "./tailwind-utility-components.ts"; const attributes = [ { id: "_id", label: "Key" }, { id: "value", label: "Value", type: "textarea" }, ]; interface ValidationErrors { [prop: string]: string; } function putActionHandler(action, _object, isNew?): Promise { return new Promise((resolve, reject) => { const object = Object.assign({}, _object); if (action === "save") { let id = object["_id"] || ""; delete object["_id"]; const regex = /^[0-9a-zA-Z_.-]+$/; id = id.trim(); if (!id.match(regex)) return void resolve({ _id: "Invalid ID" }); try { object.value = Expression.parse(object.value || "").toString(); } catch { return void resolve({ value: "Config value must be valid expression", }); } store .resourceExists("config", id) .then((exists) => { if (exists && isNew) { store.setTimestamp(Date.now()); return void resolve({ _id: "Config already exists" }); } if (!exists && !isNew) { store.setTimestamp(Date.now()); return void resolve({ _id: "Config does not exist" }); } store .putResource("config", id, object) .then(() => { notifications.push( "success", `Config ${exists ? "updated" : "created"}`, ); store.setTimestamp(Date.now()); resolve(null); }) .catch(reject); }) .catch(reject); } else if (action === "delete") { if (!confirm("Deleting config. Are you sure?")) return void resolve(null); store .deleteResource("config", object["_id"]) .then(() => { notifications.push("success", "Config deleted"); store.setTimestamp(Date.now()); resolve(null); }) .catch((err) => { store.setTimestamp(Date.now()); reject(err); }); } else { reject(new Error("Undefined action")); } }); } const formData = { resource: "config", attributes: attributes, }; function escapeRegExp(str): string { return str.replace(/[-[\]/{}()*+?.\\^$|]/g, "\\$&"); } export function init(): Promise> { if (!window.authorizer.hasAccess("config", 2)) { return Promise.reject( new Error("You are not authorized to view this page"), ); } return new Promise((resolve, reject) => { Promise.all([loadCodeMirror(), loadYaml()]) .then(() => { resolve({}); }) .catch(reject); }); } function renderTable(confsResponse, searchString): Children { const confs = confsResponse.value.sort((a, b) => { return a._id < b._id ? -1 : 1; }); let regex; if (searchString) { const keywords = searchString.split(" ").filter((s) => s); if (keywords.length) regex = new RegExp(keywords.map((s) => escapeRegExp(s)).join(".*"), "i"); } const rows = []; for (const conf of confs) { const attrs = {}; if (regex && !regex.test(conf._id) && !regex.test(conf.value)) attrs["style"] = "display: none;"; const edit = m( "button", { title: "Edit config value", onclick: () => { let cb: () => Children = null; const comp = m( putFormComponent, Object.assign( { base: conf, actionHandler: (action, object) => { return new Promise((resolve) => { putActionHandler(action, object, false) .then((errors) => { const ErrorList = errors ? Object.values(errors) : []; if (ErrorList.length) { for (const err of ErrorList) notifications.push("error", err); } else { overlay.close(cb); } resolve(); }) .catch((err) => { notifications.push("error", err.message); resolve(); }); }); }, }, formData, ), ); cb = () => comp; overlay.open( cb, () => !comp.state["current"]["modified"] || confirm("You have unsaved changes. Close anyway?"), ); }, }, m(icon, { name: "edit", class: "inline h-4 w-4 ml-1 text-cyan-700 hover:text-cyan-900", }), ); const del = m( "button", { title: "Delete config", onclick: () => { if (!confirm(`Deleting ${conf._id} config. Are you sure?`)) return; putActionHandler("delete", conf).catch((err) => { throw err; }); }, }, m(icon, { name: "remove", class: "inline h-4 w-4 ml-1 text-cyan-700 hover:text-cyan-900", }), ); rows.push( m( "tr", attrs, m("td.pl-4 pr-2 py-2 truncate", m("long-text", { text: conf._id })), m( "td.px-2 py-2 text-right truncate", m("long-text", { text: `${conf.value}` }), ), m("td.pl-2 pr-4 py-2 w-max", edit, del), ), ); } if (!rows.length) rows.push(m("tr", m("td", { colspan: 3 }, "No config"))); return m( "table.w-full table-fixed font-mono text-sm text-stone-700", m("tbody.bg-white divide-y divide-stone-200", rows), ); } export const component: ClosureComponent = (): Component => { return { view: (vnode) => { document.title = "Config - GenieACS"; const search = m( "input.appearance-none block w-full px-3 py-2 border-stone-300 placeholder-stone-500 text-stone-900 focus:ring-cyan-500 focus:border-cyan-500 sm:text-sm rounded-md mt-1 max-w-screen-sm shadow-sm mb-5", { type: "text", placeholder: "Search config", oninput: (e) => { vnode.state["searchString"] = e.target.value; e.redraw = false; clearTimeout(vnode.state["timeout"]); vnode.state["timeout"] = setTimeout(m.redraw, 250); }, }, ); const confs = store.fetch("config", new Expression.Literal(true)); let newConfig; const subs = []; if (window.authorizer.hasAccess("config", 3)) { newConfig = m( "button.mr-4 px-4 py-2 border border-stone-300 shadow-xs text-sm font-medium rounded-md text-stone-700 bg-white hover:bg-stone-50 focus:outline-hidden focus:ring-2 focus:ring-offset-2 focus:ring-cyan-500", { title: "Create new config", onclick: () => { let cb: () => Children = null; const comp = m( putFormComponent, Object.assign( { actionHandler: (action, object) => { return new Promise((resolve) => { putActionHandler(action, object, true) .then((errors) => { const errorList = errors ? Object.values(errors) : []; if (errorList.length) { for (const err of errorList) notifications.push("error", err); } else { overlay.close(cb); } resolve(null); }) .catch((err) => { notifications.push("error", err.message); resolve(); }); }); }, }, formData, ), ); cb = () => comp; overlay.open( cb, () => !comp.state["current"]["modified"] || confirm("You have unsaved changes. Close anyway?"), ); }, }, "New config", ); const subsData = [ { name: "overview", prefix: "ui.overview.groups.", data: [] }, { name: "charts", prefix: "ui.overview.charts.", data: [] }, { name: "filters", prefix: "ui.filters.", data: [] }, { name: "index page", prefix: "ui.index.", data: [] }, { name: "device page", prefix: "ui.device.", data: [] }, ]; if (confs.fulfilled) { for (const conf of confs.value) { for (const sub of subsData) { if (conf["_id"].startsWith(sub["prefix"])) { sub["data"].push(conf); break; } } } } for (const sub of subsData) { const attrs = { prefix: sub.prefix, name: sub.name, data: sub.data }; subs.push( m( "button.mr-4 px-4 py-2 border border-stone-300 shadow-xs text-sm font-medium rounded-md text-stone-700 bg-white hover:bg-stone-50 focus:outline-hidden focus:ring-2 focus:ring-offset-2 focus:ring-cyan-500", { onclick: () => { let cb: () => Children = null; const comp = m( uiConfigComponent, Object.assign( { onUpdate: (errs: Record) => { const errors = errs ? Object.values(errs) : []; if (errors.length) { for (const err of errors) notifications.push("error", err); } else { notifications.push( "success", `${sub.name.replace( /^[a-z]/, sub.name[0].toUpperCase(), )} config updated`, ); overlay.close(cb); } store.setTimestamp(Date.now()); }, onError: (err) => { notifications.push("error", err.message); store.setTimestamp(Date.now()); overlay.close(cb); }, }, attrs, ), ); cb = () => comp; overlay.open( cb, () => !comp.state["modified"] || confirm("You have unsaved changes. Close anyway?"), ); }, }, `Edit ${sub.name}`, ), ); } } return [ m("h1.text-xl font-medium text-stone-900 mb-5", "Listing config"), m( "loading", { queries: [confs] }, m( "div", search, m( ".shadow-sm overflow-hidden border-b border-stone-200 rounded-lg bg-white", m( ".overflow-y-scroll h-96", renderTable(confs, vnode.state["searchString"]), ), ), m(".mt-5", [newConfig].concat(subs)), ), ), ]; }, }; }; ================================================ FILE: ui/config.ts ================================================ import Expression from "../lib/common/expression.ts"; export const configSnapshot = window.configSnapshot; export const genieacsVersion = window.genieacsVersion; type Filters = { label: string; parameter: Expression; type: string }[]; type pageSize = number; type overview = { charts: { [name: string]: { label: string; slices: { label: string; filter: Expression; color: string; }[]; }; }; groups: { label: string; charts: string[]; }[]; }; type Index = { label: string; type?: string; parameter: Expression; unsortable: boolean; raw: NestedRecord; }[]; type NestedRecord = { [k: string]: Expression | NestedRecord }; const conf: NestedRecord = {}; for (const [key, value] of Object.entries(window.clientConfig)) { const exp = Expression.parse(value).evaluate((e) => e); let ref = conf; const keyParts = key.split("."); while (keyParts.length > 1) { const k = keyParts.shift(); if (ref[k] == null || typeof ref[k] !== "object") ref[k] = {}; ref = ref[k] as NestedRecord; } ref[keyParts[0]] = exp; } export const filters: Filters = []; export let pageSize: number = 10; export const overview: overview = { charts: {}, groups: [] }; export const index: Index = []; export let device: NestedRecord = {}; for (const obj of Object.values(conf["filters"] || {})) { let label = ""; let parameter: Expression = new Expression.Literal(false); let type = "string"; if (obj["label"] instanceof Expression.Literal) label = obj["label"].value as string; if (obj["parameter"] instanceof Expression) parameter = obj["parameter"]; if (obj["type"] instanceof Expression.Literal) type = obj["type"].value as string; filters.push({ label, parameter, type }); } for (const obj of Object.values(conf["index"] || {})) { let label = ""; let parameter: Expression = new Expression.Literal(null); let unsortable = false; let type = ""; if (obj["label"] instanceof Expression.Literal) label = obj["label"].value as string; if (obj["type"] instanceof Expression.Literal) type = obj["type"].value as string; if (obj["parameter"] instanceof Expression) parameter = obj["parameter"]; if (obj["unsortable"] instanceof Expression.Literal) unsortable = obj["unsortable"].value as boolean; index.push({ label, type, parameter, unsortable, raw: obj }); } for (const obj of Object.values(conf["overview"]?.["groups"] || {})) { let label = ""; const charts: string[] = []; if (obj["label"] instanceof Expression.Literal) label = obj["label"].value as string; for (const chart of Object.values(obj["charts"] || {})) { if (chart instanceof Expression.Literal) charts.push(chart.value as string); } overview.groups.push({ label, charts }); } for (const [name, obj] of Object.entries(conf["overview"]?.["charts"] || {})) { const slices: { label: string; filter: Expression; color: string }[] = []; for (const slice of Object.values(obj["slices"] || {})) { let label = ""; let filter: Expression = new Expression.Literal(false); let color = ""; if (slice["label"] instanceof Expression.Literal) label = slice["label"].value as string; if (slice["filter"] instanceof Expression) filter = slice["filter"]; if (slice["color"] instanceof Expression.Literal) color = slice["color"].value as string; slices.push({ label, filter, color }); } let label = ""; if (obj["label"] instanceof Expression.Literal) label = obj["label"].value as string; overview.charts[name] = { label, slices }; } if (conf["pageSize"] instanceof Expression.Literal) pageSize = +conf["pageSize"].value || 10; device = conf["device"] as NestedRecord; // Raw config values for checking if views are configured export const rawConf = conf; ================================================ FILE: ui/css/app.css ================================================ @import "tailwindcss"; @plugin "@tailwindcss/forms"; @source inline("h-full bg-stone-100"); @source "../../ui/**/*.{ts,tsx}"; @theme { --font-sans: "Inter", ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; --font-mono: "Roboto Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; /* Reset default color palette to match v3 exclusive palette */ --color-*: initial; --color-black: #000; --color-white: #fff; --color-cyan-50: #edfdfe; --color-cyan-100: #d3f7fa; --color-cyan-200: #aceef5; --color-cyan-300: #72e0ee; --color-cyan-400: #31c8df; --color-cyan-500: #15abc5; --color-cyan-600: #1589a5; --color-cyan-700: #186e86; --color-cyan-800: #1c5a6e; --color-cyan-900: #1c4b5d; --color-stone-50: #faf8f8; --color-stone-100: #f5f2f0; --color-stone-200: #e7e4e2; --color-stone-300: #d6d3d1; --color-stone-400: #a8a29e; --color-stone-500: #78716c; --color-stone-600: #57534e; --color-stone-700: #44403c; --color-stone-800: #292524; --color-stone-900: #1c1917; --color-red-50: #fdf3f3; --color-red-100: #fce4e4; --color-red-200: #facece; --color-red-300: #f5acac; --color-red-400: #ee7b7b; --color-red-500: #e25151; --color-red-600: #ce3434; --color-red-700: #ad2828; --color-red-800: #902424; --color-red-900: #782424; --color-emerald-50: #edfcf5; --color-emerald-100: #d4f7e5; --color-emerald-200: #adedd0; --color-emerald-300: #77deb5; --color-emerald-400: #40c796; --color-emerald-500: #1dac7d; --color-emerald-600: #108b65; --color-emerald-700: #0d6f53; --color-emerald-800: #0d5843; --color-emerald-900: #0b4938; --color-yellow-50: #fcfbea; --color-yellow-100: #faf5c7; --color-yellow-200: #f5e993; --color-yellow-300: #efd755; --color-yellow-400: #e9c226; --color-yellow-500: #d9aa19; --color-yellow-600: #bb8513; --color-yellow-700: #956013; --color-yellow-800: #7c4c17; --color-yellow-900: #6a3f19; --color-blue-50: #f0f6fe; --color-blue-100: #deeafb; --color-blue-200: #c4dcf9; --color-blue-300: #9bc5f5; --color-blue-400: #6ca6ee; --color-blue-500: #4985e8; --color-blue-600: #3469dc; --color-blue-700: #2b55ca; --color-blue-800: #2946a4; --color-blue-900: #263e82; --background-image-stripes: repeating-linear-gradient( -45deg, transparent, transparent 10px, rgba(0, 0, 0, 0.02) 10px, rgba(0, 0, 0, 0.02) 20px ); } @supports (font-variation-settings: normal) { @font-face { font-family: "Roboto Mono"; src: url("RobotoMono.woff2") format("woff2-variations"); font-weight: 100 700; font-style: normal; unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; font-display: swap; } @font-face { font-family: "Inter"; font-weight: 100 900; font-display: swap; font-style: normal; font-named-instance: "Regular"; src: url("InterVariable.woff2") format("woff2-variations"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; } @font-face { font-family: "Inter"; font-weight: 100 900; font-display: swap; font-style: italic; font-named-instance: "Italic"; src: url("InterVariable-Italic.woff2") format("woff2-variations"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; } } .device-page { h1 { @apply text-xl font-medium text-stone-900 mb-5; } h2 { @apply text-lg font-semibold text-stone-900 mb-5 mt-8; } h3 { @apply text-lg font-medium text-stone-900 mb-5 mt-8; } span.inform { @apply flex gap-3; & > button { @apply -my-1.5; } } } @layer base { button:not(:disabled), [role="button"]:not(:disabled) { cursor: pointer; } :focus-visible { @apply outline-2 outline-cyan-500; } } ================================================ FILE: ui/datalist.ts ================================================ import m, { ClosureComponent, Component, Vnode } from "mithril"; const elements: Map = new Map(); // Source: https://werxltd.com/wp/2010/05/13/javascript-implementation-of-javas-string-hashcode-method/ function hash(str: string): number { let res = 0; for (let i = 0; i < str.length; ++i) { const c = str.charCodeAt(i); res = (res << 5) - res + c; res |= 0; } return res; } export function getDatalistId(options: string[]): string { const id = "datalist" + options.reduce((acc, cur) => acc ^ hash(cur), 0); if (!elements.has(id)) { const n = m( "datalist", { id }, options.map((o) => m("option", { value: o })), ); elements.set(id, n); } return id; } const component: ClosureComponent = (): Component => { return { view: () => { return [...elements.values()]; }, onupdate: () => { for (const id of elements.keys()) { const used = document.querySelector(`[list='${id}']`); if (!used) elements.delete(id); } }, }; }; export default component; ================================================ FILE: ui/device-page.ts ================================================ import { ClosureComponent } from "mithril"; import { m } from "./components.ts"; import { device as deviceConfig } from "./config.ts"; import * as store from "./store.ts"; import Expression from "../lib/common/expression.ts"; import Path from "../lib/common/path.ts"; import { ViewComponent } from "./views.ts"; export function init( args: Record, ): Promise> { if (!window.authorizer.hasAccess("devices", 2)) { return Promise.reject( new Error("You are not authorized to view this page"), ); } return Promise.resolve({ deviceId: args.id, deviceFilter: new Expression.Binary( "=", new Expression.Parameter(Path.parse("DeviceID.ID")), new Expression.Literal(args.id as string), ), }); } interface Attrs { deviceId: string; deviceFilter: Expression; } export const component: ClosureComponent = () => { return { view: (vnode) => { document.title = `${vnode.attrs.deviceId} - Devices - GenieACS`; const dev = store.fetch("devices", vnode.attrs.deviceFilter); if (!dev.value.length) { if (!dev.fulfilling) { return m( "p.text-sm font-bold text-red-500", `No such device ${vnode.attrs["deviceId"]}`, ); } return m( "loading", { queries: [dev] }, m("div", { style: "height: 100px;" }), ); } const conf = deviceConfig; if ( conf instanceof Expression.Literal && typeof conf.value === "string" ) { return m(ViewComponent, { name: conf.value, attrs: { deviceId: vnode.attrs["deviceId"] }, }); } const cmps = []; for (const c of Object.values(conf)) { cmps.push( m.context( { device: dev.value[0], deviceQuery: dev }, store.evaluateExpression(c["type"], {}).value as string, c as any, ), ); } return m("div.device-page", m("h1", vnode.attrs["deviceId"]), cmps); }, }; }; ================================================ FILE: ui/devices-page.ts ================================================ import { ClosureComponent, Children } from "mithril"; import { m } from "./components.ts"; import { pageSize as PAGE_SIZE, index as indexConfig } from "./config.ts"; import indexTableComponent from "./index-table-component.ts"; import filterComponent from "./filter-component.ts"; import * as store from "./store.ts"; import { invalidate } from "./reactive-store.ts"; import { queueTask, stageDownload } from "./task-queue.ts"; import * as notifications from "./notifications.ts"; import Expression, { extractPaths } from "../lib/common/expression.ts"; import memoize from "../lib/common/memoize.ts"; import * as smartQuery from "./smart-query.ts"; import { ViewComponent } from "./views.ts"; const memoizedGetSortable = memoize((p: Expression) => { const expressionParams = extractPaths(p); if (expressionParams.length === 1) return expressionParams[0]; return null; }); const getDownloadUrl = memoize( ( filter: Expression, indexParameters: { label: string; parameter: Expression }[], ) => { const columns = {}; for (const p of indexParameters) columns[p.label] = p.parameter.toString(); return `api/devices.csv?${m.buildQueryString({ filter: filter.toString(), columns: JSON.stringify(columns), })}`; }, ); const unpackSmartQuery = memoize((query: Expression) => { return query.evaluate((e) => { if (e instanceof Expression.FunctionCall) { if (e.name === "Q") { if ( e.args[0] instanceof Expression.Literal && e.args[1] instanceof Expression.Literal ) { return smartQuery.unpack( "devices", e.args[0].value as string, e.args[1].value as string, ); } } } return e; }); }); export function init(args: Record): Promise { return new Promise((resolve, reject) => { if (!window.authorizer.hasAccess("devices", 2)) return void reject(new Error("You are not authorized to view this page")); let filter: Expression = null; let sort: Record = null; if (args.hasOwnProperty("filter")) filter = Expression.parse(args["filter"] as string); if (args.hasOwnProperty("sort")) sort = JSON.parse(args["sort"] as string); const indexParameters = indexConfig; if (!indexParameters.length) { indexParameters.push({ label: "ID", parameter: Expression.parse("DeviceID.ID"), unsortable: false, raw: {}, }); } resolve({ filter, indexParameters, sort }); }); } function renderActions(selected: Set): Children { const buttons = []; buttons.push( m( "button.px-4 py-2 border border-stone-300 shadow-xs text-sm font-medium rounded-md text-stone-700 bg-white hover:bg-stone-50 focus:outline-hidden focus:ring-2 focus:ring-offset-2 focus:ring-cyan-500 disabled:opacity-50 disabled:cursor-not-allowed", { title: "Reboot selected devices", disabled: !selected.size, onclick: () => { const tasks = [...selected].map((s) => ({ name: "reboot", device: s, })); queueTask(...tasks); }, }, "Reboot", ), ); buttons.push( m( "button.px-4 py-2 border border-stone-300 shadow-xs text-sm font-medium rounded-md text-stone-700 bg-white hover:bg-stone-50 focus:outline-hidden focus:ring-2 focus:ring-offset-2 focus:ring-cyan-500 disabled:opacity-50 disabled:cursor-not-allowed", { title: "Factory reset selected devices", disabled: !selected.size, onclick: () => { const tasks = [...selected].map((s) => ({ name: "factoryReset", device: s, })); queueTask(...tasks); }, }, "Reset", ), ); buttons.push( m( "button.px-4 py-2 border border-stone-300 shadow-xs text-sm font-medium rounded-md text-stone-700 bg-white hover:bg-stone-50 focus:outline-hidden focus:ring-2 focus:ring-offset-2 focus:ring-cyan-500 disabled:opacity-50 disabled:cursor-not-allowed", { title: "Push a firmware or a config file", disabled: !selected.size, onclick: () => { stageDownload({ name: "download", devices: [...selected], }); }, }, "Push file", ), ); buttons.push( m( "button.px-4 py-2 border border-stone-300 shadow-xs text-sm font-medium rounded-md text-stone-700 bg-white hover:bg-stone-50 focus:outline-hidden focus:ring-2 focus:ring-offset-2 focus:ring-cyan-500 disabled:opacity-50 disabled:cursor-not-allowed", { title: "Delete selected devices", disabled: !selected.size, onclick: () => { const ids = Array.from(selected); if (!confirm(`Deleting ${ids.length} devices. Are you sure?`)) return; let counter = 1; for (const id of ids) { ++counter; store .deleteResource("devices", id) .then(() => { notifications.push("success", `${id}: Deleted`); if (--counter === 0) { store.setTimestamp(Date.now()); invalidate(Date.now()); } }) .catch((err) => { notifications.push("error", `${id}: ${err.message}`); if (--counter === 0) { store.setTimestamp(Date.now()); invalidate(Date.now()); } }); } if (--counter === 0) { store.setTimestamp(Date.now()); invalidate(Date.now()); } }, }, "Delete", ), ); buttons.push( m( "button.px-4 py-2 border border-stone-300 shadow-xs text-sm font-medium rounded-md text-stone-700 bg-white hover:bg-stone-50 focus:outline-hidden focus:ring-2 focus:ring-offset-2 focus:ring-cyan-500 disabled:opacity-50 disabled:cursor-not-allowed", { title: "Tag selected devices", disabled: !selected.size, onclick: () => { const ids = Array.from(selected); const tag = prompt(`Enter tag to assign to ${ids.length} devices:`); if (!tag) return; let counter = 1; for (const id of ids) { ++counter; store .updateTags(id, { [tag]: true }) .then(() => { notifications.push("success", `${id}: Tags updated`); if (--counter === 0) { store.setTimestamp(Date.now()); invalidate(Date.now()); } }) .catch((err) => { notifications.push("error", `${id}: ${err.message}`); if (--counter === 0) { store.setTimestamp(Date.now()); invalidate(Date.now()); } }); } if (--counter === 0) { store.setTimestamp(Date.now()); invalidate(Date.now()); } }, }, "Tag", ), ); buttons.push( m( "button.px-4 py-2 border border-stone-300 shadow-xs text-sm font-medium rounded-md text-stone-700 bg-white hover:bg-stone-50 focus:outline-hidden focus:ring-2 focus:ring-offset-2 focus:ring-cyan-500 disabled:opacity-50 disabled:cursor-not-allowed", { title: "Untag selected devices", disabled: !selected.size, onclick: () => { const ids = Array.from(selected); const tag = prompt( `Enter tag to unassign from ${ids.length} devices:`, ); if (!tag) return; let counter = 1; for (const id of ids) { ++counter; store .updateTags(id, { [tag]: false }) .then(() => { notifications.push("success", `${id}: Tags updated`); if (--counter === 0) { store.setTimestamp(Date.now()); invalidate(Date.now()); } }) .catch((err) => { notifications.push("error", `${id}: ${err.message}`); if (--counter === 0) { store.setTimestamp(Date.now()); invalidate(Date.now()); } }); } if (--counter === 0) { store.setTimestamp(Date.now()); invalidate(Date.now()); } }, }, "Untag", ), ); return buttons; } interface Attrs { indexParameters: typeof indexConfig; filter?: Expression; sort?: Record; } export const component: ClosureComponent = () => { return { view: (vnode) => { document.title = "Devices - GenieACS"; const attributes = vnode.attrs.indexParameters; function showMore(): void { vnode.state["showCount"] = (vnode.state["showCount"] || PAGE_SIZE) + PAGE_SIZE; m.redraw(); } function onFilterChanged(filter: Expression): void { const ops = {}; if (!(filter instanceof Expression.Literal && filter.value)) ops["filter"] = filter.toString(); if (vnode.attrs.sort) ops["sort"] = vnode.attrs.sort; m.route.set("/devices", ops); } const sort = vnode.attrs.sort || {}; const sortAttributes = {}; for (let i = 0; i < attributes.length; i++) { const attr = attributes[i]; if (attr.unsortable) continue; const param = memoizedGetSortable(attr.parameter); if (param) sortAttributes[i] = sort[param.toString()] || 0; } function onSortChange(sortedAttrs): void { const _sort = {}; for (const index of sortedAttrs) { const param = memoizedGetSortable( attributes[Math.abs(index) - 1].parameter, ); _sort[param.toString()] = Math.sign(index); } const ops = { sort: JSON.stringify(_sort) }; if (vnode.attrs["filter"]) ops["filter"] = vnode.attrs["filter"]; m.route.set("/devices", ops); } const filter = unpackSmartQuery( vnode.attrs["filter"] ?? new Expression.Literal(true), ); const devs = store.fetch("devices", filter, { limit: vnode.state["showCount"] || PAGE_SIZE, sort: sort, }); const count = store.count("devices", filter); const downloadUrl = getDownloadUrl(filter, attributes); const valueCallback = (attr, device): Children => { if (!attr.type && !attr.components && attr.component) { return m(ViewComponent, { name: attr.component, attrs: { ...attr, deviceId: device["DeviceID.ID"], }, }); } else { return m.context( { device: device, parameter: attr.parameter }, attr.type || "parameter", attr.raw, ); } }; const attrs = {}; attrs["attributes"] = attributes.map((a) => ({ ...a, label: a.label, type: a.type, })); attrs["data"] = devs.value; attrs["total"] = count.value; attrs["showMoreCallback"] = showMore; attrs["sortAttributes"] = sortAttributes; attrs["onSortChange"] = onSortChange; attrs["downloadUrl"] = downloadUrl; attrs["valueCallback"] = valueCallback; attrs["recordActionsCallback"] = (device): Children => { return m( "a.text-cyan-700 hover:text-cyan-900", { href: `#!/devices/${encodeURIComponent(device["DeviceID.ID"])}`, }, "Show", ); }; if (window.authorizer.hasAccess("devices", 3)) attrs["actionsCallback"] = renderActions; const filterAttrs = { resource: "devices", filter: vnode.attrs["filter"], onChange: onFilterChanged, }; return [ m("h1.text-xl font-medium text-stone-900 mb-5", "Listing devices"), m(filterComponent, filterAttrs), m("loading", { queries: [devs, count] }, m(indexTableComponent, attrs)), ]; }, }; }; ================================================ FILE: ui/drawer-component.ts ================================================ import m, { Children, Child, ClosureComponent, Component, VnodeDOM, } from "mithril"; import * as store from "./store.ts"; import { invalidate } from "./reactive-store.ts"; import * as notifications from "./notifications.ts"; import { icon } from "./tailwind-utility-components.ts"; import { clear, commit, deleteTask, getQueue, getStaging, QueueTask, queueTask, StageTask, } from "./task-queue.ts"; import Expression from "../lib/common/expression.ts"; const invalid: WeakSet = new WeakSet(); function renderStagingSpv(task: StageTask, queueFunc, cancelFunc): Children { function keydown(e: KeyboardEvent): void { if (e.key === "Enter") queueFunc(); else if (e.key === "Escape") cancelFunc(); else e["redraw"] = false; } let input; if (task.parameterValues[0][2] === "xsd:boolean") { input = m( "select.mt-1 w-full block pl-3 pr-10 py-2 text-base border-stone-300 focus:outline-hidden focus:ring-cyan-500 focus:border-cyan-500 sm:text-sm rounded-md", { value: task.parameterValues[0][1].toString(), onchange: (e) => { e.redraw = false; task.parameterValues[0][1] = input.dom.value; }, onkeydown: keydown, oncreate: (vnode) => { (vnode.dom as HTMLSelectElement).focus(); }, }, [ m("option", { value: "true" }, "true"), m("option", { value: "false" }, "false"), ], ); } else { const type = task.parameterValues[0][2]; let value = task.parameterValues[0][1]; if (type === "xsd:dateTime" && typeof value === "number") value = new Date(value).toJSON() || value; input = m( "input.mt-1 w-full shadow-xs focus:ring-cyan-500 focus:border-cyan-500 block sm:text-sm border-stone-300 rounded-md", { type: ["xsd:int", "xsd:unsignedInt"].includes(type) ? "number" : "text", value: value, oninput: (e) => { e.redraw = false; task.parameterValues[0][1] = input.dom.value; }, onkeydown: keydown, oncreate: (vnode) => { (vnode.dom as HTMLInputElement).focus(); (vnode.dom as HTMLInputElement).select(); // Need to prevent scrolling on focus because // we're animating height and using overflow: hidden (vnode.dom.parentNode.parentNode as Element).scrollTop = 0; }, }, ); } return [ m( "span.text-sm text-stone-700 inline-flex max-w-full gap-2", "Editing", m( "span", { title: task.parameterValues[0][0], dir: "rtl", class: "italic pr-1 min-w-0 truncate", }, task.parameterValues[0][0], ), ), input, ]; } function renderStagingDownload(task: StageTask): Children { if (!task.fileName || !task.fileType) invalid.add(task); else invalid.delete(task); const files = store.fetch("files", new Expression.Literal(true)); let oui = ""; let productClass = ""; for (const d of task.devices) { const parts = d.split("-"); if (oui === "") oui = parts[0]; else if (oui !== parts[0]) oui = null; if (parts.length === 3) { if (productClass === "") productClass = parts[1]; else if (productClass !== parts[1]) productClass = null; } } if (oui) oui = decodeURIComponent(oui); if (productClass) productClass = decodeURIComponent(productClass); const typesList = [ ...new Set([ "", "1 Firmware Upgrade Image", "2 Web Content", "3 Vendor Configuration File", "4 Tone File", "5 Ringer File", ...files.value.map((f) => f["metadata.fileType"]).filter((f) => f), ]), ].map((t) => m( "option", { disabled: !t, value: t, selected: (task.fileType || "") === t }, t, ), ); const filesList = [""] .concat( files.value .filter( (f) => (!f["metadata.oui"] || f["metadata.oui"] === oui) && (!f["metadata.productClass"] || f["metadata.productClass"] === productClass), ) .map((f) => f._id), ) .map((f) => m( "option", { disabled: !f, value: f, selected: (task.fileName || "") === f }, f, ), ); return m("div.flex items-center gap-2 text-sm text-stone-700 max-w-full", [ "Push", m( "select", { class: "min-w-0 pl-3 pr-10 py-2 text-base border-stone-300 focus:outline-hidden focus:ring-cyan-500 focus:border-cyan-500 sm:text-sm rounded-md", onchange: (e) => { const f = e.target.value; task.fileName = f; task.fileType = ""; for (const file of files.value) if (file._id === f) task.fileType = file["metadata.fileType"]; }, disabled: files.fulfilling, }, filesList, ), "as", m( "select", { class: "min-w-0 pl-3 pr-10 py-2 text-base border-stone-300 focus:outline-hidden focus:ring-cyan-500 focus:border-cyan-500 sm:text-sm rounded-md", onchange: (e) => { task.fileType = e.target.value; }, }, typesList, ), ]); } function renderStaging(staging: Set): Child[] { const elements: Child[] = []; for (const s of staging) { const queueFunc = (): void => { staging.delete(s); for (const d of s.devices) { const t = Object.assign({ device: d }, s); delete t.devices; queueTask(t); } }; const cancelFunc = (): void => { staging.delete(s); }; let elms; if (s.name === "setParameterValues") elms = renderStagingSpv(s, queueFunc, cancelFunc); else if (s.name === "download") elms = renderStagingDownload(s); const queue = m( "button", { class: "px-2.5 py-1.5 border border-transparent text-xs font-medium rounded-sm shadow-xs text-white bg-cyan-600 hover:bg-cyan-700 focus:outline-hidden focus:ring-2 focus:ring-offset-2 focus:ring-cyan-500 disabled:cursor-not-allowed disabled:opacity-50", title: "Queue task", onclick: queueFunc, disabled: invalid.has(s), }, "Queue", ); const cancel = m( "button", { class: "px-2.5 py-1.5 border border-stone-300 shadow-xs text-xs font-medium rounded-sm text-stone-700 bg-white hover:bg-stone-50 focus:outline-hidden focus:ring-2 focus:ring-offset-2 focus:ring-cyan-500 disabled:cursor-not-allowed disabled:opacity-50", title: "Cancel edit", onclick: cancelFunc, }, "Cancel", ); elements.push( m( "div.p-4", elms, m("div.flex mt-4 justify-center gap-4", cancel, queue), ), ); } return elements; } function renderQueue(queue: Set): Child[] { const details: Child[] = []; const devices: { [deviceId: string]: any[] } = {}; for (const t of queue) { devices[t.device] = devices[t.device] || []; devices[t.device].push(t); } for (const [k, v] of Object.entries(devices)) { details.push(m("h3.font-semibold text-stone-700", k)); for (const t of v) { const actions: ReturnType[] = []; let task: ReturnType; if (t.status === "fault" || t.status === "stale") { actions.push( m( "button", { title: "Retry this task", onclick: () => { queueTask(t); }, }, m(icon, { name: "retry", class: "inline h-4 w-4 text-cyan-700 hover:text-cyan-900", }), ), ); } actions.push( m( "button", { title: "Remove this task", onclick: () => { deleteTask(t); }, }, m(icon, { name: "remove", class: "inline h-4 w-4 text-cyan-700 hover:text-cyan-900", }), ), ); if (t.name === "setParameterValues") { task = m( "span.text-stone-900 inline-flex max-w-full gap-2", "Set", m( "span", { title: t.parameterValues[0][0], dir: "rtl", class: "italic pr-1 min-w-0 truncate", }, t.parameterValues[0][0], ), "to", m( "span", { title: t.parameterValues[0][1], class: "min-w-0 truncate", }, t.parameterValues[0][1], ), ); } else if (t.name === "refreshObject") { task = m( "span.text-stone-900 inline-flex max-w-full gap-2", "Refresh", m( "span", { title: t.parameterName, dir: "rtl", class: "italic pr-1 min-w-0 truncate", }, t.parameterName, ), ); } else if (t.name === "reboot") { task = m("span.text-stone-900", "Reboot"); } else if (t.name === "factoryReset") { task = m("span.text-stone-900", "Factory reset"); } else if (t.name === "addObject") { task = m( "span.text-stone-900 inline-flex max-w-full gap-2", "Add", m( "span", { title: t.objectName, dir: "rtl", class: "italic pr-1 min-w-0 truncate", }, t.objectName, ), ); } else if (t.name === "deleteObject") { task = m( "span.text-stone-900 inline-flex max-w-full gap-2", "Delete", m( "span", { title: t.objectName, dir: "rtl", class: "italic pr-1 min-w-0 truncate", }, t.objectName, ), ); } else if (t.name === "getParameterValues") { task = m( "span.text-stone-900", `Refresh ${t.parameterNames.length} parameters`, ); } else if (t.name === "download") { task = m( "span.text-stone-900", `Push file: ${t.fileName} (${t.fileType})`, ); } else { task = m("span.text-stone-900", t.name); } let bgDiv: ReturnType; if (t.status === "pending") { bgDiv = m( "div.block absolute inset-0 bg-emerald-200 rounded-sm animate-pulse", "", ); } else if (t.status === "fault") { bgDiv = m("div.block absolute inset-0 bg-red-200 rounded-sm", ""); } else if (t.status === "stale") { bgDiv = m("div.block absolute inset-0 bg-stone-200 rounded-sm", ""); } details.push( m( "div.flex justify-between w-full rounded-sm items-center relative", bgDiv, m("div.overflow-hidden relative", task), m("div.flex whitespace-nowrap gap-2 ml-2 relative", actions), ), ); } } return details; } function renderNotifications(notifs): Child[] { const notificationElements: Child[] = []; for (const n of notifs) { let notifColors = "", buttonColors = ""; if (n.type === "success") { notifColors = "bg-emerald-50 text-emerald-800 border-emerald-100"; buttonColors = "hover:bg-emerald-100 text-emerald-800 focus:ring-offset-emerald-50 focus:ring-emerald-600"; } else if (n.type === "error") { notifColors = "bg-red-50 text-red-800 border-red-100"; buttonColors = "hover:bg-red-100 text-red-800 focus:ring-offset-red-50 focus:ring-red-600"; } else if (n.type === "warning") { notifColors = "bg-yellow-50 text-yellow-800 border-yellow-100"; buttonColors = "hover:bg-yellow-100 text-yellow-800 focus:ring-offset-yellow-50 focus:ring-yellow-600"; } let buttons; if (n.actions) { const btns = Object.entries(n.actions).map(([label, onclick]) => m( "button", { class: "ml-2 px-2 py-1.5 -my-1.5 rounded-md text-sm font-medium focus:outline-hidden focus:ring-2 focus:ring-offset-2 " + buttonColors, onclick: onclick, }, label, ), ); if (btns.length) buttons = m("div", btns); } notificationElements.push( m( "div", { class: "absolute flex justify-between rounded-md w-full text-sm shadow-md p-4 border transition-[top,opacity] " + notifColors, style: "opacity: 0", oncreate: (vnode) => { (vnode.dom as HTMLDivElement).style.opacity = "1"; }, onbeforeremove: (vnode) => { (vnode.dom as HTMLDivElement).style.opacity = "0"; return new Promise((resolve) => { setTimeout(() => { resolve(); }, 500); }); }, key: n.timestamp, }, n.message, buttons, ), ); } return notificationElements; } const component: ClosureComponent = (): Component => { return { view: (vnode) => { const queue = getQueue(); const staging = getStaging(); const notifs = notifications.getNotifications(); let drawerElement, statusElement; const notificationElements = renderNotifications(notifs); const stagingElements = renderStaging(staging); const queueElements = renderQueue(queue); function repositionNotifications(): void { let top = 16; for (const c of notificationElements as VnodeDOM[]) { (c.dom as HTMLDivElement).style.top = `${top}px`; top += (c.dom as HTMLDivElement).offsetHeight + 16; } } function resizeDrawer(): void { let height = statusElement.dom.offsetTop + statusElement.dom.offsetHeight; if (stagingElements.length) { for (const s of stagingElements as VnodeDOM[]) { height = Math.max( height, (s.dom as HTMLDivElement).offsetTop + (s.dom as HTMLDivElement).offsetHeight, ); } } else if (vnode.state["mouseIn"]) { for (const c of drawerElement.children) height = Math.max(height, c.dom.offsetTop + c.dom.offsetHeight); } drawerElement.dom.style.height = height + "px"; } if (stagingElements.length + queueElements.length) { const statusCount = { queued: 0, pending: 0, fault: 0, stale: 0 }; for (const t of queue) statusCount[t["status"]] += 1; const actions = m( "div.flex ml-auto gap-2", m( "button", { class: "px-2.5 py-1.5 -my-1.5 border border-stone-300 shadow-xs text-xs font-medium rounded-sm text-stone-700 bg-white hover:bg-stone-50 focus:outline-hidden focus:ring-2 focus:ring-offset-2 focus:ring-cyan-500 disabled:opacity-50 disabled:cursor-not-allowed", title: "Clear tasks", onclick: clear, disabled: !queueElements.length, }, "Clear", ), m( "button", { class: "px-2.5 py-1.5 -my-1.5 border border-transparent text-xs font-medium rounded-sm shadow-xs text-white bg-cyan-600 hover:bg-cyan-700 focus:outline-hidden focus:ring-2 focus:ring-offset-2 focus:ring-cyan-500 disabled:opacity-50 disabled:cursor-not-allowed", title: "Commit queued tasks", disabled: !statusCount.queued, onclick: () => { const tasks = Array.from(getQueue()).filter( (t) => t["status"] === "queued", ); commit( tasks, (deviceId, err, connectionRequestStatus, tasks2) => { if (err) { notifications.push( "error", `${deviceId}: ${err.message}`, ); return; } if (connectionRequestStatus !== "OK") { notifications.push( "error", `${deviceId}: ${connectionRequestStatus}`, ); return; } for (const t of tasks2) { if (t.status === "stale") { notifications.push( "error", `${deviceId}: No contact from device`, ); return; } else if (t.status === "fault") { notifications.push( "error", `${deviceId}: Task(s) faulted`, ); return; } } notifications.push( "success", `${deviceId}: Task(s) committed`, ); }, ) .then(() => { store.setTimestamp(Date.now()); invalidate(Date.now()); }) .catch((err) => { notifications.push("error", err.message); }); }, }, "Commit", ), ); statusElement = m( "div.flex p-4 gap-5 items-center text-sm", m( "span.text-stone-700 -mx-1 px-1", { class: statusCount.queued ? "font-semibold" : "" }, `Queued: ${statusCount.queued}`, ), m( "span.text-stone-700 relative", statusCount.pending ? m( "div.block absolute -inset-x-1 inset-y-0 rounded-sm bg-emerald-200 animate-pulse", "", ) : null, m("span.relative", `Pending: ${statusCount.pending}`), ), m( "span.text-stone-700 relative", m("span.relative", `Fault: ${statusCount.fault}`), ), m( "span.text-stone-700 relative", statusCount.stale ? m( "div.block absolute -inset-x-1 inset-y-0 rounded-sm bg-stone-200", "", ) : null, m("span.relative", `Stale: ${statusCount.stale}`), ), actions, ); drawerElement = m( "div", { class: "w-[48rem] mx-auto pointer-events-auto bg-white rounded-b-lg border-stone-300 border-x border-b shadow-md overflow-hidden transition-[height] -mt-px", key: "drawer", style: "opacity: 0;height: 0;", oncreate: (vnode2) => { vnode.state["mouseIn"] = false; (vnode2.dom as HTMLDivElement).style.opacity = "1"; resizeDrawer(); }, onmouseenter: (e) => { if (drawerElement.dom.style.opacity === "0") return; vnode.state["mouseIn"] = true; resizeDrawer(); e.redraw = false; }, onmouseleave: (e) => { if (drawerElement.dom.style.opacity === "0") return; vnode.state["mouseIn"] = false; resizeDrawer(); e.redraw = false; }, onupdate: resizeDrawer, onbeforeremove: (vnode2) => { (vnode2.dom as HTMLDivElement).style.opacity = "0"; (vnode2.dom as HTMLDivElement).style.height = "0"; return new Promise((resolve) => { setTimeout(resolve, 500); }); }, }, statusElement, stagingElements.length ? stagingElements : m("div.px-4 pb-4 text-sm", queueElements), ); } return m( "div.fixed pointer-events-none inset-0 z-30", drawerElement, m( "div", { class: "relative w-[48rem] mx-auto pointer-events-auto", key: "notifications", onupdate: repositionNotifications, oncreate: repositionNotifications, }, notificationElements, ), ); }, }; }; export default component; ================================================ FILE: ui/dynamic-loader.ts ================================================ import * as notifications from "./notifications.ts"; export let codeMirror: typeof import("./codemirror-loader"); export let yaml: typeof import("./yaml-loader"); let note; function onError(): void { if (!note) { note = notifications.push( "error", "Error loading JS resource, please reload the page", { Reload: () => { window.location.reload(); }, }, ); } } export function loadCodeMirror(): Promise { if (codeMirror) return Promise.resolve(); return new Promise((resolve, reject) => { import("./codemirror-loader") .then((module) => { codeMirror = module; resolve(); }) .catch((err) => { onError(); reject(err); }); }); } export function loadYaml(): Promise { if (yaml) return Promise.resolve(); return new Promise((resolve, reject) => { import("./yaml-loader") .then((module) => { yaml = module; resolve(); }) .catch((err) => { onError(); reject(err); }); }); } ================================================ FILE: ui/error-page.ts ================================================ import { ClosureComponent, Component } from "mithril"; import { m } from "./components.ts"; export const component: ClosureComponent = (): Component => { return { view: function (vnode) { document.title = "Error! - GenieACS"; return m("p.text-sm font-bold text-red-500", vnode.attrs["error"]); }, }; }; ================================================ FILE: ui/faults-page.ts ================================================ import { ClosureComponent, Component, Children } from "mithril"; import { m } from "./components.ts"; import { pageSize as PAGE_SIZE } from "./config.ts"; import indexTableComponent from "./index-table-component.ts"; import filterComponent from "./filter-component.ts"; import * as store from "./store.ts"; import * as notifications from "./notifications.ts"; import memoize from "../lib/common/memoize.ts"; import * as smartQuery from "./smart-query.ts"; import { stringify as yamlStringify } from "../lib/common/yaml.ts"; import Expression from "../lib/common/expression.ts"; const memoizedJsonParse = memoize(JSON.parse); const attributes = [ { id: "device", label: "Device" }, { id: "channel", label: "Channel" }, { id: "code", label: "Code" }, { id: "message", label: "Message" }, { id: "detail", label: "Detail" }, { id: "retries", label: "Retries" }, { id: "timestamp", label: "Timestamp" }, ]; const getDownloadUrl = memoize((filter) => { const cols = {}; for (const attr of attributes) { cols[attr.label] = attr.id === "timestamp" ? `DATE_STRING(${attr.id})` : attr.id; } return `api/faults.csv?${m.buildQueryString({ filter: filter.toString(), columns: JSON.stringify(cols), })}`; }); const unpackSmartQuery = memoize((query: Expression) => { return query.evaluate((e) => { if (e instanceof Expression.FunctionCall) { if (e.name === "Q") { if ( e.args[0] instanceof Expression.Literal && e.args[1] instanceof Expression.Literal ) { return smartQuery.unpack( "faults", e.args[0].value as string, e.args[1].value as string, ); } } } return e; }); }); async function deleteFaults(faults: Iterable): Promise { const proms: Map> = new Map(); for (const f of faults) { const deviceId = f.split(":", 1)[0]; let p = proms.get(deviceId); if (p == null) p = store.deleteResource("faults", f); else p = p.then(() => store.deleteResource("faults", f)); proms.set(deviceId, p); } await Promise.all(proms.values()); } export function init( args: Record, ): Promise> { if (!window.authorizer.hasAccess("faults", 2)) { return Promise.reject( new Error("You are not authorized to view this page"), ); } let filter: Expression = null; let sort: Record = null; if (args.hasOwnProperty("filter")) filter = Expression.parse(args["filter"] as string); if (args.hasOwnProperty("sort")) sort = JSON.parse(args["sort"] as string); return Promise.resolve({ filter, sort }); } export const component: ClosureComponent = (): Component => { return { view: (vnode) => { document.title = "Faults - GenieACS"; function showMore(): void { vnode.state["showCount"] = (vnode.state["showCount"] || PAGE_SIZE) + PAGE_SIZE; m.redraw(); } function onFilterChanged(filter): void { const ops = {}; if (!(filter instanceof Expression.Literal && filter.value)) ops["filter"] = filter.toString(); if (vnode.attrs["sort"]) ops["sort"] = vnode.attrs["sort"]; m.route.set("/faults", ops); } const sort = vnode.attrs["sort"] ? memoizedJsonParse(vnode.attrs["sort"]) : {}; const sortAttributes = {}; for (let i = 0; i < attributes.length; i++) { const attr = attributes[i]; if (attr.id !== "detail") sortAttributes[i] = sort[attr.id] || 0; } function onSortChange(sortAttrs): void { const _sort = {}; for (const index of sortAttrs) _sort[attributes[Math.abs(index) - 1].id] = Math.sign(index); const ops = { sort: JSON.stringify(_sort) }; if (vnode.attrs["filter"]) ops["filter"] = vnode.attrs["filter"]; m.route.set("/faults", ops); } const filter = unpackSmartQuery( vnode.attrs["filter"] ?? new Expression.Literal(true), ); const faults = store.fetch("faults", filter, { limit: vnode.state["showCount"] || PAGE_SIZE, sort: sort, }); const count = store.count("faults", filter); const downloadUrl = getDownloadUrl(filter); const valueCallback = (attr, fault): Children => { if (attr.id === "device") { const deviceHref = `#!/devices/${encodeURIComponent( fault["device"], )}`; return m( "a.text-cyan-700 hover:text-cyan-900 font-medium", { href: deviceHref }, fault["device"], ); } if (attr.id === "message") return m("long-text", { text: fault["message"], class: "max-w-xs" }); if (attr.id === "detail") { return m("long-text", { text: yamlStringify(fault["detail"]), class: "max-w-xs", }); } if (attr.id === "timestamp") return new Date(fault["timestamp"]).toLocaleString(); return fault[attr.id]; }; const attrs = {}; attrs["attributes"] = attributes; attrs["data"] = faults.value; attrs["valueCallback"] = valueCallback; attrs["total"] = count.value; attrs["showMoreCallback"] = showMore; attrs["sortAttributes"] = sortAttributes; attrs["onSortChange"] = onSortChange; attrs["downloadUrl"] = downloadUrl; if (window.authorizer.hasAccess("faults", 3)) { attrs["actionsCallback"] = (selected: Set): Children => { return m( "button.px-4 py-2 border border-stone-300 shadow-xs text-sm font-medium rounded-md text-stone-700 bg-white hover:bg-stone-50 focus:outline-hidden focus:ring-2 focus:ring-offset-2 focus:ring-cyan-500 disabled:opacity-50 disabled:cursor-not-allowed", { disabled: selected.size === 0, title: "Delete selected faults", onclick: (e) => { e.redraw = false; e.target.disabled = true; if (!confirm(`Deleting ${selected.size} faults. Are you sure?`)) return; const c = selected.size; deleteFaults(selected) .then(() => { notifications.push("success", `${c} faults deleted`); store.setTimestamp(Date.now()); }) .catch((err) => { notifications.push("error", err.message); store.setTimestamp(Date.now()); }); }, }, "Delete", ); }; } const filterAttrs = { resource: "faults", filter: vnode.attrs["filter"], onChange: onFilterChanged, }; return [ m("h1.text-xl font-medium text-stone-900 mb-5", "Listing faults"), m(filterComponent, filterAttrs), m( "loading", { queries: [faults, count] }, m(indexTableComponent, attrs), ), ]; }, }; }; ================================================ FILE: ui/files-page.ts ================================================ import { ClosureComponent, Component, Children } from "mithril"; import { m } from "./components.ts"; import { pageSize as PAGE_SIZE } from "./config.ts"; import filterComponent from "./filter-component.ts"; import * as store from "./store.ts"; import * as notifications from "./notifications.ts"; import memoize from "../lib/common/memoize.ts"; import putFormComponent from "./put-form-component.ts"; import indexTableComponent from "./index-table-component.ts"; import * as overlay from "./overlay.ts"; import * as smartQuery from "./smart-query.ts"; import Expression from "../lib/common/expression.ts"; const memoizedJsonParse = memoize(JSON.parse); const attributes: { id: string; label: string; type?: string; options?: any; }[] = [ { id: "_id", label: "Name" }, { id: "metadata.fileType", label: "Type", options: [ "1 Firmware Upgrade Image", "2 Web Content", "3 Vendor Configuration File", "4 Tone File", "5 Ringer File", ], }, { id: "metadata.oui", label: "OUI" }, { id: "metadata.productClass", label: "Product Class" }, { id: "metadata.version", label: "Version" }, ]; const formData = { resource: "files", attributes: attributes .slice(1) // remove _id from new object form .concat([{ id: "file", label: "File", type: "file" }]), }; const unpackSmartQuery = memoize((query: Expression) => { return query.evaluate((e) => { if (e instanceof Expression.FunctionCall) { if (e.name === "Q") { if ( e.args[0] instanceof Expression.Literal && e.args[1] instanceof Expression.Literal ) { return smartQuery.unpack( "files", e.args[0].value as string, e.args[1].value as string, ); } } } return e; }); }); function upload( file: File, headers: Record, abortSignal?: AbortSignal, progressListener?: (e: ProgressEvent) => void, ): Promise { headers = Object.assign( { "Content-Type": "application/octet-stream", }, headers, ); return store.xhrRequest({ method: "PUT", headers: headers, url: `api/files/${encodeURIComponent(file.name)}`, serialize: (body) => body, // Identity function to prevent JSON.parse on blob data body: file, config: (xhr) => { if (progressListener) xhr.upload.addEventListener("progress", progressListener); if (abortSignal) { if (abortSignal.aborted) xhr.abort(); abortSignal.addEventListener("abort", () => xhr.abort()); } }, }); } const getDownloadUrl = memoize((filter) => { const cols = {}; for (const attr of attributes) cols[attr.label] = attr.id; return `api/files.csv?${m.buildQueryString({ filter: filter.toString(), columns: JSON.stringify(cols), })}`; }); export function init( args: Record, ): Promise> { if (!window.authorizer.hasAccess("files", 2)) { return Promise.reject( new Error("You are not authorized to view this page"), ); } let filter: Expression = null; let sort: Record = null; if (args.hasOwnProperty("filter")) filter = Expression.parse(args["filter"] as string); if (args.hasOwnProperty("sort")) sort = JSON.parse(args["sort"] as string); return Promise.resolve({ filter, sort }); } export const component: ClosureComponent = (): Component => { return { view: (vnode) => { document.title = "Files - GenieACS"; function showMore(): void { vnode.state["showCount"] = (vnode.state["showCount"] || PAGE_SIZE) + PAGE_SIZE; m.redraw(); } function onFilterChanged(filter): void { const ops = {}; if (!(filter instanceof Expression.Literal && filter.value)) ops["filter"] = filter.toString(); if (vnode.attrs["sort"]) ops["sort"] = vnode.attrs["sort"]; m.route.set("/files", ops); } const sort = vnode.attrs["sort"] ? memoizedJsonParse(vnode.attrs["sort"]) : {}; const sortAttributes = {}; for (let i = 0; i < attributes.length; i++) sortAttributes[i] = sort[attributes[i].id] || 0; function onSortChange(sortAttrs): void { const _sort = {}; for (const index of sortAttrs) _sort[attributes[Math.abs(index) - 1].id] = Math.sign(index); const ops = { sort: JSON.stringify(_sort) }; if (vnode.attrs["filter"]) ops["filter"] = vnode.attrs["filter"]; m.route.set("/files", ops); } const filter = unpackSmartQuery( vnode.attrs["filter"] ?? new Expression.Literal(true), ); const files = store.fetch("files", filter, { limit: vnode.state["showCount"] || PAGE_SIZE, sort: sort, }); const count = store.count("files", filter); const downloadUrl = getDownloadUrl(filter); const attrs = {}; attrs["attributes"] = attributes; attrs["data"] = files.value; attrs["total"] = count.value; attrs["showMoreCallback"] = showMore; attrs["sortAttributes"] = sortAttributes; attrs["onSortChange"] = onSortChange; attrs["downloadUrl"] = downloadUrl; attrs["recordActionsCallback"] = (file) => { return [ m( "a.text-cyan-700 hover:text-cyan-900", { href: "api/blob/files/" + file["_id"] }, "Download", ), ]; }; if (window.authorizer.hasAccess("files", 3)) { attrs["actionsCallback"] = (selected: Set): Children => { return [ m( "button.px-4 py-2 border border-stone-300 shadow-xs text-sm font-medium rounded-md text-stone-700 bg-white hover:bg-stone-50 focus:outline-hidden focus:ring-2 focus:ring-offset-2 focus:ring-cyan-500 disabled:opacity-50 disabled:cursor-not-allowed", { title: "Create new file", onclick: () => { let cb: () => Children = null; const abortController = new AbortController(); let progress = -1; const comp = m( putFormComponent, Object.assign( { actionHandler: async (action, obj) => { if (action !== "save") throw new Error("Undefined action"); const file = obj["file"]?.[0]; // nginx strips out headers with dot, so replace with dash const headers = { "metadata-fileType": obj["metadata.fileType"] || "", "metadata-oui": obj["metadata.oui"] || "", "metadata-productclass": obj["metadata.productClass"] || "", "metadata-version": obj["metadata.version"] || "", }; if (!file) { notifications.push("error", "File not selected"); return; } if (await store.resourceExists("files", file.name)) { store.setTimestamp(Date.now()); notifications.push("error", "File already exists"); return; } const progressListener = (e: ProgressEvent): void => { progress = e.loaded / e.total; m.redraw(); }; progress = 0; try { await upload( file, headers, abortController.signal, progressListener, ); store.setTimestamp(Date.now()); notifications.push("success", "File created"); overlay.close(cb); } catch (err) { notifications.push("error", err.message); } progress = -1; }, }, formData, ), ); cb = () => { if (progress < 0) return [null, comp]; return [ m( "div.progress", m("div.progress-bar", { style: `width: ${Math.trunc(progress * 100)}%`, }), ), comp, ]; }; overlay.open(cb, () => { if ( comp.state["current"]["modified"] && !confirm("You have unsaved changes. Close anyway?") ) return false; abortController.abort(); return true; }); }, }, "New", ), m( "button.px-4 py-2 border border-stone-300 shadow-xs text-sm font-medium rounded-md text-stone-700 bg-white hover:bg-stone-50 focus:outline-hidden focus:ring-2 focus:ring-offset-2 focus:ring-cyan-500 disabled:opacity-50 disabled:cursor-not-allowed", { title: "Delete selected files", disabled: !selected.size, onclick: (e) => { if ( !confirm(`Deleting ${selected.size} files. Are you sure?`) ) return; e.redraw = false; e.target.disabled = true; Promise.all( Array.from(selected).map((id) => store.deleteResource("files", id), ), ) .then((res) => { notifications.push( "success", `${res.length} files deleted`, ); store.setTimestamp(Date.now()); }) .catch((err) => { notifications.push("error", err.message); store.setTimestamp(Date.now()); }); }, }, "Delete", ), ]; }; } const filterAttrs = { resource: "files", filter: vnode.attrs["filter"], onChange: onFilterChanged, }; return [ m("h1.text-xl font-medium text-stone-900 mb-5", "Listing files"), m(filterComponent, filterAttrs), m( "loading", { queries: [files, count] }, m(indexTableComponent, attrs), ), ]; }, }; }; ================================================ FILE: ui/filter-component.ts ================================================ import m, { ClosureComponent } from "mithril"; import memoize from "../lib/common/memoize.ts"; import Autocomplete from "./autocomplete-compnent.ts"; import * as smartQuery from "./smart-query.ts"; import { validQuery } from "../lib/db/synth.ts"; import Expression from "../lib/common/expression.ts"; const getAutocomplete = memoize((resource) => { const labels = smartQuery.getLabels(resource); const autocomplete = new Autocomplete((txt, cb) => { txt = txt.toLowerCase(); cb( labels .filter((s) => s.toLowerCase().includes(txt)) .map((s) => ({ value: `${s}: `, tip: smartQuery.getTip(resource, s), })), ); }); return autocomplete; }); function parseFilter(resource: string, f: string): Expression { let exp; if (/^[\s0-9a-zA-Z]+:/.test(f)) { const k = f.split(":", 1)[0]; const v = f.slice(k.length + 1).trim(); exp = new Expression.FunctionCall("Q", [ new Expression.Literal(k.trim()), new Expression.Literal(v), ]); } else { exp = Expression.parse(f); } const unpacked = exp.evaluate((e) => { if (e instanceof Expression.FunctionCall) { if (e.name === "NOW") return new Expression.Literal(Date.now()); else if (e.name === "Q") { if ( e.args[0] instanceof Expression.Literal && e.args[1] instanceof Expression.Literal ) { const r = smartQuery.unpack( resource, e.args[0].value as string, e.args[1].value as string, ); return r; } } } return e; }); // Throws exception if invalid Mongo query validQuery(unpacked, resource); return exp; } function splitFilter(filter: Expression): string[] { if (!filter) return [""]; if (filter instanceof Expression.Literal && filter.value) return [""]; const list: Expression[] = [filter]; const res: string[] = []; while (list.length) { const f = list.pop(); if (f instanceof Expression.Binary && f.operator === "AND") { list.push(f.right); list.push(f.left); } else if (f instanceof Expression.FunctionCall && f.name === "Q") { const l = f.args[0] as Expression.Literal; const r = f.args[1] as Expression.Literal; res.push(`${l.value}: ${r.value}`); } else { res.push(f.toString()); } } res.push(""); return res; } interface Attrs { resource: string; filter?: Expression; onChange: (filter: Expression) => void; } const component: ClosureComponent = (initialVnode) => { let filterList = splitFilter(initialVnode.attrs.filter); let filterInvalid = 0; let filterTouched = false; let attrs: Attrs = initialVnode.attrs; function onChange(): void { filterTouched = false; filterInvalid = 0; filterList = filterList.filter((f) => f); let filter: Expression = new Expression.Literal(true); for (const [idx, f] of filterList.entries()) { try { filter = Expression.and(filter, parseFilter(attrs.resource, f)); } catch { filterInvalid |= 1 << idx; } } filterList.push(""); if (filterInvalid) { m.redraw(); return; } if (!filterList.length) attrs.onChange(null); else attrs.onChange(filter); } return { onupdate: (vnode) => { getAutocomplete(vnode.attrs.resource).reposition(); }, view: (vnode) => { if (attrs.filter !== vnode.attrs.filter) { filterInvalid = 0; filterList = splitFilter(vnode.attrs.filter); } attrs = vnode.attrs; return m("div.mb-5", [ m("label.text-sm font-semibold text-stone-700", "Filter"), m( "div.shadow-sm rounded-md mt-1 max-w-screen-sm -space-y-px", ...filterList.map((fltr, idx) => { let classNames = "appearance-none rounded-none relative block w-full px-3 py-2 border-stone-300 placeholder-stone-500 text-stone-900 focus:ring-cyan-500 focus:border-cyan-500 focus:z-10 sm:text-sm"; if (idx === 0) classNames += " rounded-t-md"; if (idx === filterList.length - 1) classNames += " rounded-b-md"; if (filterInvalid & (1 << idx)) classNames += " !text-red-700"; return m(`input`, { type: "text", class: classNames, value: fltr, oninput: (e) => { e.redraw = false; filterList[idx] = e.target.value; filterTouched = true; }, oncreate: (vn) => { const el = vn.dom as HTMLInputElement; getAutocomplete(vnode.attrs.resource).attach(el); el.addEventListener("blur", () => { if (filterTouched) onChange(); }); el.addEventListener("keydown", (e) => { if (e.key === "Enter" && filterTouched) onChange(); }); }, }); }), ), ]); }, }; }; export default component; ================================================ FILE: ui/index-table-component.ts ================================================ import { ClosureComponent, Component, Children } from "mithril"; import { m } from "./components.ts"; import { icon } from "./tailwind-utility-components.ts"; import debounce from "../lib/common/debounce.ts"; interface Attribute { id?: string; label: string; type?: string; } const MAX_PAGE_SIZE = 200; function getExcerpt(text: string, maxLength = 80, maxLines = 10): string[] { let lines: string[] = text?.split("\n", maxLines + 1) ?? [""]; if (lines.length > maxLines) { lines.pop(); lines[maxLines - 1] = "\ufe19"; } lines = lines.map((l) => { if (l.length <= maxLength) return l; return l.slice(0, maxLength - 1) + "\u2026"; }); return lines; } function renderTable( attributes: Attribute[], data: Record[], total: number, showMoreCallback: () => void, selected: Set, sortAttributes: Record, onSort: (i: number) => void, downloadUrl?: string, valueCallback?: (attr: Attribute, record: Record) => Children, actionsCallback?: Children | ((sel: Set) => Children), recordActionsCallback?: | Children | ((record: Record) => Children), ): Children { const records = data || []; // Actions bar let buttons: Children = []; if (typeof actionsCallback === "function") { buttons = actionsCallback(selected); if (!Array.isArray(buttons)) buttons = [buttons]; } else if (Array.isArray(actionsCallback)) { buttons = actionsCallback; } // Table header const labels = []; if (buttons.length) { const selectAll = m( "input.focus:ring-cyan-500 h-4 w-4 text-cyan-700 border-stone-300 rounded-sm", { type: "checkbox", checked: records.length && selected.size === records.length, onchange: (e) => { for (const record of records) { const id = record["_id"] ?? record["DeviceID.ID"]; if (e.target.checked) selected.add(id); else selected.delete(id); } }, disabled: !total, }, ); labels.push( m( "th", { class: "px-6 py-3.5 w-0", scope: "col" }, m("span.sr-only", "Select"), selectAll, ), ); } for (const [i, attr] of attributes.entries()) { let padding: string; if (i === 0) padding = buttons.length ? "pr-3" : "pl-6 pr-3"; else if (i === attributes.length - +!recordActionsCallback) padding = "pl-3 pr-6"; else padding = "px-3"; const label = attr.label; if (!sortAttributes.hasOwnProperty(i)) { labels.push( m( "th", { class: "py-3.5 text-left text-sm font-semibold text-stone-500 " + padding, scope: "col", }, label, ), ); continue; } let symbol: Children; if (sortAttributes[i] > 0) { symbol = m(icon, { name: "sorted-asc", class: "inline h-4 w-4 ml-1" }); } else if (sortAttributes[i] < 0) { symbol = m(icon, { name: "sorted-dsc", class: "inline h-4 w-4 ml-1" }); } else { symbol = m(icon, { name: "unsorted", class: "inline h-4 w-4 ml-1 opacity-50 hover:opacity-100", }); } const sortable = m( "button", { onclick: (e) => { e.redraw = false; onSort(i); }, }, symbol, ); labels.push( m( "th", { class: "py-3.5 text-left text-sm font-semibold text-stone-500 whitespace-nowrap " + padding, scope: "col", }, [label, sortable], ), ); } if (recordActionsCallback) labels.push(m("th", { class: "pl-3 pr-6 py-3.5 w-0", scope: "col" })); // Table rows const rows = []; for (const record of records) { const id = record["_id"] ?? record["DeviceID.ID"]; const tds = []; const isSelected = selected.has(id); if (buttons.length) { const checkbox = m( "input.focus:ring-cyan-500 h-4 w-4 text-cyan-700 border-stone-300 rounded-sm", { type: "checkbox", checked: isSelected, onchange: (e) => { if (e.target.checked) selected.add(id); else selected.delete(id); }, onclick: (e) => { e.stopPropagation(); e.redraw = false; }, }, ); tds.push( m("td.px-6 py-4 whitespace-nowrap text-sm text-stone-500", checkbox), ); } for (const [i, attr] of attributes.entries()) { let padding: string; if (i === 0) padding = buttons.length ? "pr-3" : "pl-6 pr-3"; else if (i === attributes.length - +!recordActionsCallback) padding = "pl-3 pr-6"; else padding = "px-3"; const attrs = { class: "py-4 whitespace-nowrap text-sm text-stone-900 " + padding, }; let valueComponent; if (typeof valueCallback === "function") { valueComponent = valueCallback(attr, record); } else if (attr.type === "code") { const excerpt = getExcerpt(record[attr.id]); valueComponent = m( "span.font-mono", { title: excerpt.join("\n") }, excerpt[0], ); } else { valueComponent = record[attr.id]; } // TODO automatically add long text component on long values tds.push(m("td", attrs, valueComponent)); } let recordButtons: Children = []; if (typeof recordActionsCallback === "function") { recordButtons = recordActionsCallback(record); if (!Array.isArray(recordButtons)) recordButtons = [recordButtons]; } else if (Array.isArray(recordActionsCallback)) { recordButtons = recordActionsCallback; } for (const button of recordButtons) { tds.push( m( "td.pl-3 pr-6 py-4 whitespace-nowrap text-right text-sm font-medium", button, ), ); } rows.push( m( "tr", { class: isSelected ? "bg-stone-50" : "", onclick: (e) => { if (e.target.closest("input, button, a")) { e.redraw = false; return; } if (!selected.delete(id)) selected.add(id); }, }, tds, ), ); } if (!rows.length) { rows.push( m( "tr", m( "td.bg-stripes text-sm font-medium text-center text-stone-500 p-4", { colspan: labels.length }, "No records", ), ), ); } // Table footer const pagination = []; if (total != null) pagination.push(`${records.length} / ${total}`); else pagination.push(`${records.length}`); pagination.push( m( "button.px-4 py-2 border border-stone-300 rounded-md text-stone-700 bg-white hover:bg-stone-50 ml-4 disabled:opacity-50 disabled:cursor-not-allowed", { title: "Show more records", onclick: showMoreCallback, disabled: !data.length || records.length >= Math.min(MAX_PAGE_SIZE, total), }, "More", ), ); let download: Children; if (downloadUrl) { download = m( "a.text-cyan-700 hover:text-cyan-900", { href: downloadUrl, download: "" }, "Download", ); } const tfoot = m( "tfoot.bg-white", m( "tr", m( "td.px-6 py-3 text-sm font-medium text-stone-700", { colspan: labels.length }, m( "div.flex items-center justify-between", m("div", pagination), download, ), ), ), ); const children = [ m( "div.flex flex-col", m( "div.-my-2 overflow-x-auto sm:-mx-6 lg:-mx-8", m( "div.py-2 align-middle inline-block min-w-full sm:px-6 lg:px-8", m( "div.shadow-sm overflow-hidden border-b border-stone-200 sm:rounded-lg", m( "table.min-w-full divide-y divide-stone-200", m("thead.bg-stone-50", m("tr", labels)), m("tbody.bg-white divide-y divide-stone-200", rows), tfoot, ), ), ), ), ), ]; if (buttons.length) children.push(m("div.flex gap-3 mt-4", buttons)); return children; } const component: ClosureComponent = (): Component => { let selected = new Set(); let sortingfunction: (events: number[]) => void; const onSort = debounce((events: number[]) => { sortingfunction(events); }, 500); return { view: (vnode) => { const attributes = vnode.attrs["attributes"]; const data = vnode.attrs["data"]; const valueCallback = vnode.attrs["valueCallback"]; const total = vnode.attrs["total"]; const showMoreCallback = vnode.attrs["showMoreCallback"]; const sortAttributes = vnode.attrs["sortAttributes"]; const onSortChange = vnode.attrs["onSortChange"]; const downloadUrl = vnode.attrs["downloadUrl"]; const actionsCallback = vnode.attrs["actionsCallback"]; const recordActionsCallback = vnode.attrs["recordActionsCallback"]; const _selected = new Set(); for (const record of data) { const id = record["_id"] ?? record["DeviceID.ID"]; if (selected.has(id)) _selected.add(id); } sortingfunction = (events) => { const sortArray = new Set( Object.keys(sortAttributes) .map((x) => (parseInt(x) + 1) * sortAttributes[x]) .filter((x) => x), ); for (const num of events) { if (sortArray.delete(num + 1)) sortArray.add(-(num + 1)); else if (!sortArray.delete((num + 1) * -1)) sortArray.add(num + 1); } onSortChange(Array.from(sortArray).reverse()); }; selected = _selected; return renderTable( attributes, data, total, showMoreCallback, selected, sortAttributes, onSort, downloadUrl, valueCallback, actionsCallback, recordActionsCallback, ); }, }; }; export default component; ================================================ FILE: ui/layout.tsx ================================================ import m, { ClosureComponent } from "mithril"; import drawerComponent from "./drawer-component.ts"; import * as overlay from "./overlay.ts"; import { version as VERSION } from "../package.json"; import datalist from "./datalist.ts"; import { transitionRoot, transitionChild, dialog, dialogOverlay, icon, } from "./tailwind-utility-components.ts"; import * as store from "./store.ts"; import * as notifications from "./notifications.ts"; import { LOGO_SVG } from "../build/assets.ts"; function tsxComponent( c: ClosureComponent, ): (attrs: T) => ReturnType { return c as any; } const TransitionRoot = tsxComponent(transitionRoot); const TransitionChild = tsxComponent(transitionChild); const Dialog = tsxComponent(dialog); const DialogOverlay = tsxComponent(dialogOverlay); const Icon = tsxComponent(icon); function classNames(...classes: string[]): string { return classes.filter(Boolean).join(" "); } interface Attrs { page: string; } const component: ClosureComponent = () => { let sidebarOpen = false; function setSidebarOpen(open: boolean): void { sidebarOpen = open; setTimeout(m.redraw); } return { view: (vnode) => { const navigation = [ { name: "Overview", href: "#!/overview", enabled: window.authorizer.hasAccess("devices", 1), }, { name: "Devices", href: "#!/devices", enabled: window.authorizer.hasAccess("devices", 2), }, { name: "Faults", href: "#!/faults", enabled: window.authorizer.hasAccess("faults", 2), }, { name: "Presets", href: "#!/presets", enabled: window.authorizer.hasAccess("presets", 2), }, { name: "Provisions", href: "#!/provisions", enabled: window.authorizer.hasAccess("provisions", 2), }, { name: "Virtual Parameters", href: "#!/virtualParameters", enabled: window.authorizer.hasAccess("virtualParameters", 2), }, { name: "Files", href: "#!/files", enabled: window.authorizer.hasAccess("files", 2), }, { name: "Config", href: "#!/config", enabled: window.authorizer.hasAccess("config", 2), }, { name: "Permissions", href: "#!/permissions", enabled: window.authorizer.hasAccess("permissions", 2), }, { name: "Users", href: "#!/users", enabled: window.authorizer.hasAccess("users", 2), }, { name: "Views", href: "#!/views", enabled: window.authorizer.hasAccess("views", 2), }, ] .filter((item) => item.enabled) .map(({ name, href }) => { const n = href.slice(3); return { name, href, active: vnode.attrs["page"] === n }; }); return [
setSidebarOpen(false)} >
{window.username ? (
{window.username}
) : ( )}
v{VERSION}
{/* Force sidebar to shrink to fit close icon */}
{/* Static sidebar for desktop */}
{m(drawerComponent)} {vnode.children}
, overlay.render(), m(datalist), ]; }, }; }; export default component; ================================================ FILE: ui/login-page.tsx ================================================ import { ClosureComponent, Component, Children } from "mithril"; import { m } from "./components.ts"; import * as store from "./store.ts"; import * as notifications from "./notifications.ts"; import * as overlay from "./overlay.ts"; import changePasswordComponent from "./change-password-component.ts"; export function init( args: Record, ): Promise> { return Promise.resolve(args); } export const component: ClosureComponent = (): Component => { let username = ""; let password = ""; let remember = false; function logIn(e: MouseEvent): boolean { e.target["disabled"] = true; store .logIn(username, password, remember) .then(() => { location.reload(); }) .catch((err) => { notifications.push("error", err.response || err.message); e.target["disabled"] = false; }); return false; } function changePassword(): void { const cb = (): Children => { const attrs = { onPasswordChange: () => { overlay.close(cb); m.redraw(); }, }; return m(changePasswordComponent, attrs); }; overlay.open(cb); } return { view: (vnode) => { if (window.username) m.route.set(vnode.attrs["continue"] || "/"); document.title = "Login - GenieACS"; return (

Log in to continue

{ username = e.target.value; }} />
{ password = e.target.value; }} />
{ remember = e.target.checked; }} />
); }, }; }; ================================================ FILE: ui/long-text-component.ts ================================================ import m, { ClosureComponent, Component } from "mithril"; import * as overlay from "./overlay.ts"; const component: ClosureComponent = (): Component => { return { view: (vnode) => { const text = vnode.attrs["text"]; const element = vnode.attrs["element"] || "span"; const className = vnode.attrs["class"] || ""; function overflowed(_vnode): void { _vnode.dom.classList.add("cursor-pointer", "hover:underline"); _vnode.dom.setAttribute("title", text); _vnode.dom.onclick = (e) => { overlay.open(() => { return m( "textarea.font-mono text-sm focus:ring-cyan-500 focus:border-cyan-500 border border-stone-300 rounded-md", { value: text, cols: 80, rows: 24, readonly: "", oncreate: (vnode2) => { (vnode2.dom as HTMLTextAreaElement).focus(); }, }, ); }); // prevent index page selection e.stopPropagation(); m.redraw(); }; } return m( element, { oncreate: (vnode2) => { const w = Math.round(vnode2.dom.getBoundingClientRect().width); if (w !== vnode2.dom.scrollWidth) overflowed(vnode2); }, onupdate: (vnode2) => { const w = Math.round(vnode2.dom.getBoundingClientRect().width); if (w === vnode2.dom.scrollWidth) { (vnode2.dom as HTMLElement).classList.remove( "cursor-pointer", "hover:underline", ); (vnode2.dom as HTMLElement).onclick = null; (vnode2.dom as HTMLElement).removeAttribute("title"); } else { overflowed(vnode2); } }, class: "block truncate decoration-dotted max-w-full " + className, }, text, ); }, }; }; export default component; ================================================ FILE: ui/notifications.ts ================================================ import m from "mithril"; interface Notification { type: string; message: string; timestamp: number; actions?: { [label: string]: () => void }; } const notifications = new Set(); export function push( type: string, message: string, actions?: { [label: string]: () => void }, ): Notification { const n: Notification = { type: type, message: message, timestamp: Date.now(), actions: actions, }; notifications.add(n); m.redraw(); if (!actions) { setTimeout(() => { dismiss(n); }, 4000); } return n; } export function dismiss(n: Notification): void { notifications.delete(n); m.redraw(); } export function getNotifications(): Set { return notifications; } ================================================ FILE: ui/overlay.ts ================================================ import m, { Children } from "mithril"; import { dialog, dialogOverlay, icon } from "./tailwind-utility-components.ts"; type OverlayCallback = () => Children; type CloseCallback = () => boolean; let overlayCallback: OverlayCallback = null; let closeCallback: CloseCallback = null; export function open( callback: OverlayCallback, closeCb: CloseCallback = null, ): void { overlayCallback = callback; closeCallback = closeCb; } export function close(callback: OverlayCallback, force = true): boolean { if (callback === overlayCallback) { if (!force && closeCallback && !closeCallback()) return false; overlayCallback = null; closeCallback = null; return true; } return false; } export function render(): Children { if (overlayCallback) { return m( dialog, { as: "div", class: "fixed z-10 inset-0 overflow-y-auto", onClose: () => close(overlayCallback, false), }, m("div.flex items-center justify-center min-h-screen p-4 text-center", [ m(dialogOverlay, { class: "fixed inset-0 bg-black/50", }), m( "div.relative z-10 bg-white rounded-lg px-4 pt-5 pb-4 text-left overflow-hidden shadow-xl transform max-w-full", m( "div.block absolute top-0 right-0 pt-4 pr-4", m( "button.bg-white rounded-md text-stone-400 hover:text-stone-500 focus:outline-hidden focus:ring-2 focus:ring-offset-2 focus:ring-cyan-500", { type: "button", onclick: () => close(overlayCallback, false), }, m("span.sr-only", "Close"), m(icon, { name: "close", class: "h-6 w-6" }), ), ), overlayCallback(), ), ]), ); } return null; } document.addEventListener("keydown", (e) => { if (overlayCallback && e.key === "Escape" && close(overlayCallback, false)) m.redraw(); }); window.addEventListener("popstate", () => { if (close(overlayCallback, false)) m.redraw(); }); ================================================ FILE: ui/overview-page.ts ================================================ import { ClosureComponent } from "mithril"; import { m } from "./components.ts"; import { overview, rawConf } from "./config.ts"; import * as store from "./store.ts"; import pieChartComponent from "./pie-chart-component.ts"; import Expression from "../lib/common/expression.ts"; import { ViewComponent } from "./views.ts"; const GROUPS = overview.groups; const CHARTS: typeof overview.charts = {}; for (const group of GROUPS) { for (const chartName of group.charts) CHARTS[chartName] = overview.charts[chartName]; } function queryCharts(charts: typeof overview.charts): typeof charts { charts = Object.assign({}, charts); for (let [chartName, chart] of Object.entries(charts)) { charts[chartName] = chart = { ...chart }; chart.slices = chart.slices.map((s) => ({ ...s })); for (const slice of chart.slices) { slice["count"] = store.count("devices", slice.filter); } } return charts; } export function init(): Promise<{ charts: typeof overview.charts }> { if (!window.authorizer.hasAccess("devices", 1)) { return Promise.reject( new Error("You are not authorized to view this page"), ); } return Promise.resolve({ charts: queryCharts(CHARTS) }); } interface Attrs { charts: typeof overview.charts; } export const component: ClosureComponent = () => { return { view: (vnode) => { document.title = "Overview - GenieACS"; const children = []; if ( rawConf["overview"] instanceof Expression.Literal && typeof rawConf["overview"].value === "string" ) { return m(ViewComponent, { name: rawConf["overview"].value, attrs: {}, }); } for (const group of GROUPS) { if (group.label) { children.push( m("h1.text-xl font-medium text-stone-900 mb-5", group["label"]), ); } const groupChildren = []; for (const chartName of group.charts) { const chart = vnode.attrs.charts[chartName]; const chartChildren = []; if (chart.label) { chartChildren.push( m( "h2.text-lg font-semibold text-stone-700 truncate mb-5 text-center", chart.label, ), ); } chartChildren.push(m(pieChartComponent, { chart })); groupChildren.push( m( "div.p-4 bg-white shadow-sm rounded-lg sm:p-6 sm:px-8", chartChildren, ), ); } children.push( m("div.flex justify-center mt-5 mb-10 gap-x-10", groupChildren), ); } return children; }, }; }; ================================================ FILE: ui/permissions-page.ts ================================================ import { Children, ClosureComponent, Component } from "mithril"; import { m } from "./components.ts"; import { pageSize as PAGE_SIZE } from "./config.ts"; import * as store from "./store.ts"; import * as notifications from "./notifications.ts"; import memoize from "../lib/common/memoize.ts"; import putFormComponent from "./put-form-component.ts"; import indexTableComponent from "./index-table-component.ts"; import * as overlay from "./overlay.ts"; import * as smartQuery from "./smart-query.ts"; import Expression from "../lib/common/expression.ts"; import filterComponent from "./filter-component.ts"; const memoizedParse = memoize((str) => Expression.parse(str)); const memoizedJsonParse = memoize(JSON.parse); const attributes = [ { id: "role", label: "Role" }, { id: "resource", label: "Resource", type: "combo", options: [ "config", "devices", "faults", "files", "permissions", "users", "presets", "provisions", "virtualParameters", "views", ], }, { id: "filter", label: "Filter", type: "textarea" }, { id: "access", label: "Access", type: "combo", options: ["1: count", "2: read", "3: write"], }, { id: "validate", label: "Validate", type: "textarea" }, ]; function getExcerpt(text: string, maxLength = 80, maxLines = 10): string[] { let lines: string[] = text?.split("\n", maxLines + 1) ?? [""]; if (lines.length > maxLines) { lines.pop(); lines[maxLines - 1] = "\ufe19"; } lines = lines.map((l) => { if (l.length <= maxLength) return l; return l.slice(0, maxLength - 1) + "\u2026"; }); return lines; } const unpackSmartQuery = memoize((query: Expression) => { return query.evaluate((e) => { if (e instanceof Expression.FunctionCall) { if (e.name === "Q") { if ( e.args[0] instanceof Expression.Literal && e.args[1] instanceof Expression.Literal ) { return smartQuery.unpack( "permissions", e.args[0].value as string, e.args[1].value as string, ); } } } return e; }); }); interface ValidationErrors { [prop: string]: string; } function putActionHandler(action, _object, isNew): Promise { return new Promise((resolve, reject) => { const object = Object.assign({}, _object); if (action === "save") { if (!object.role) return void resolve({ role: "Role can not be empty" }); if (!object.resource) return void resolve({ resource: "Resource can not be empty" }); if (!object.access) return void resolve({ access: "Access can not be empty" }); if (object.access === "3: write") object.access = 3; else if (object.access === "2: read") object.access = 2; else if (object.access === "1: count") object.access = 1; else return void resolve({ access: "Invalid access level" }); if (object.filter) { try { object.filter = memoizedParse(object.filter).toString(); } catch { return void resolve({ filter: "Filter must be valid expression", }); } } if (object.validate) { try { object.validate = memoizedParse(object.validate).toString(); } catch { return void resolve({ validate: "Validate must be valid expression", }); } } const id = `${object.role}:${object.resource}:${object.access}`; store .resourceExists("permissions", id) .then((exists) => { if (exists && isNew) { store.setTimestamp(Date.now()); return void resolve({ _id: "Permission already exists" }); } if (!exists && !isNew) { store.setTimestamp(Date.now()); return void resolve({ _id: "Permission does not exist" }); } store .putResource("permissions", id, object) .then(() => { notifications.push( "success", `Permission ${exists ? "updated" : "created"}`, ); store.setTimestamp(Date.now()); resolve(null); }) .catch(reject); }) .catch(reject); } else if (action === "delete") { if (!confirm("Deleting permission. Are you sure?")) return void resolve(null); store .deleteResource("permissions", object["_id"]) .then(() => { notifications.push("success", "Permission deleted"); store.setTimestamp(Date.now()); resolve(null); }) .catch((err) => { store.setTimestamp(Date.now()); reject(err); }); } else { reject(new Error("Undefined action")); } }); } const formData = { resource: "permissions", attributes: attributes, }; const getDownloadUrl = memoize((filter) => { const cols = {}; for (const attr of attributes) cols[attr.label] = attr.id; return `api/permissions.csv?${m.buildQueryString({ filter: filter.toString(), columns: JSON.stringify(cols), })}`; }); export function init( args: Record, ): Promise> { if (!window.authorizer.hasAccess("permissions", 2)) { return Promise.reject( new Error("You are not authorized to view this page"), ); } let filter: Expression = null; let sort: Record = null; if (args.hasOwnProperty("filter")) filter = Expression.parse(args["filter"] as string); if (args.hasOwnProperty("sort")) sort = JSON.parse(args["sort"] as string); return Promise.resolve({ filter, sort }); } export const component: ClosureComponent = (): Component => { return { view: (vnode) => { document.title = "Permissions - GenieACS"; function showMore(): void { vnode.state["showCount"] = (vnode.state["showCount"] || PAGE_SIZE) + PAGE_SIZE; m.redraw(); } function onFilterChanged(filter): void { const ops = {}; if (!(filter instanceof Expression.Literal && filter.value)) ops["filter"] = filter.toString(); if (vnode.attrs["sort"]) ops["sort"] = vnode.attrs["sort"]; m.route.set("/permissions", ops); } const sort = vnode.attrs["sort"] ? memoizedJsonParse(vnode.attrs["sort"]) : {}; const sortAttributes = {}; for (let i = 0; i < attributes.length; i++) { const attr = attributes[i]; if (!(attr.id === "filter" || attr.id === "validate")) sortAttributes[i] = sort[attr.id] || 0; } function onSortChange(sortAttrs): void { const _sort = {}; for (const index of sortAttrs) _sort[attributes[Math.abs(index) - 1].id] = Math.sign(index); const ops = { sort: JSON.stringify(_sort) }; if (vnode.attrs["filter"]) ops["filter"] = vnode.attrs["filter"]; m.route.set("/permissions", ops); } const filter = unpackSmartQuery( vnode.attrs["filter"] ?? new Expression.Literal(true), ); const permissions = store.fetch("permissions", filter, { limit: vnode.state["showCount"] || PAGE_SIZE, sort: sort, }); const count = store.count("permissions", filter); const downloadUrl = getDownloadUrl(filter); const valueCallback = (attr, permission): Children => { if (attr.id === "access") { const val = permission["access"]; if (val === 1) return "1: count"; else if (val === 2) return "2: read"; else if (val === 3) return "3: write"; return val; } else if (attr.id === "validate" || attr.id === "filter") { const except = getExcerpt(permission[attr.id], 80, 1); return m("span.font-mono", { title: permission[attr.id] }, except[0]); } return permission[attr.id]; }; const attrs = {}; attrs["attributes"] = attributes; attrs["data"] = permissions.value; attrs["total"] = count.value; attrs["valueCallback"] = valueCallback; attrs["showMoreCallback"] = showMore; attrs["sortAttributes"] = sortAttributes; attrs["onSortChange"] = onSortChange; attrs["downloadUrl"] = downloadUrl; if (window.authorizer.hasAccess("permissions", 3)) { attrs["recordActionsCallback"] = (permission) => { const val = permission["access"]; if (val === 1) permission["access"] = "1: count"; if (val === 2) permission["access"] = "2: read"; if (val === 3) permission["access"] = "3: write"; return [ m( "button.text-cyan-700 hover:text-cyan-900 font-medium", { onclick: () => { let cb: () => Children = null; const comp = m( putFormComponent, Object.assign( { base: permission, oncreate: (_vnode) => { _vnode.dom.querySelector( "input[name='role']", ).disabled = true; _vnode.dom.querySelector( "select[name='access']", ).disabled = true; _vnode.dom.querySelector( "select[name='resource']", ).disabled = true; }, actionHandler: (action, object) => { return new Promise((resolve) => { putActionHandler(action, object, false) .then((errors) => { const errorList = errors ? Object.values(errors) : []; if (errorList.length) { for (const err of errorList) notifications.push("error", err); } else { overlay.close(cb); } resolve(); }) .catch((err) => { notifications.push("error", err.message); resolve(); }); }); }, }, formData, ), ); cb = () => comp; overlay.open( cb, () => !comp.state["current"]["modified"] || confirm("You have unsaved changes. Close anyway?"), ); }, }, "Show", ), ]; }; attrs["actionsCallback"] = (selected: Set): Children => { return [ m( "button.px-4 py-2 border border-stone-300 shadow-xs text-sm font-medium rounded-md text-stone-700 bg-white hover:bg-stone-50 focus:outline-hidden focus:ring-2 focus:ring-offset-2 focus:ring-cyan-500 disabled:opacity-50 disabled:cursor-not-allowed", { title: "Create new permission", onclick: () => { let cb: () => Children = null; const comp = m( putFormComponent, Object.assign( { actionHandler: (action, object) => { return new Promise((resolve) => { putActionHandler(action, object, true) .then((errors) => { const errorList = errors ? Object.values(errors) : []; if (errorList.length) { for (const err of errorList) notifications.push("error", err); } else { overlay.close(cb); } resolve(); }) .catch((err) => { notifications.push("error", err.message); resolve(); }); }); }, }, formData, ), ); cb = () => comp; overlay.open( cb, () => !comp.state["current"]["modified"] || confirm("You have unsaved changes. Close anyway?"), ); }, }, "New", ), m( "button.px-4 py-2 border border-stone-300 shadow-xs text-sm font-medium rounded-md text-stone-700 bg-white hover:bg-stone-50 focus:outline-hidden focus:ring-2 focus:ring-offset-2 focus:ring-cyan-500 disabled:opacity-50 disabled:cursor-not-allowed", { title: "Delete selected permissions", disabled: !selected.size, onclick: (e) => { if ( !confirm( `Deleting ${selected.size} permissions. Are you sure?`, ) ) return; e.redraw = false; e.target.disabled = true; Promise.all( Array.from(selected).map((id) => store.deleteResource("permissions", id), ), ) .then((res) => { notifications.push( "success", `${res.length} permissions deleted`, ); store.setTimestamp(Date.now()); }) .catch((err) => { notifications.push("error", err.message); store.setTimestamp(Date.now()); }); }, }, "Delete", ), ]; }; } const filterAttrs = { resource: "permissions", filter: vnode.attrs["filter"], onChange: onFilterChanged, }; return [ m("h1.text-xl font-medium text-stone-900 mb-5", "Listing permissions"), m(filterComponent, filterAttrs), m( "loading", { queries: [permissions, count] }, m(indexTableComponent, attrs), ), ]; }, }; }; ================================================ FILE: ui/pie-chart-component.ts ================================================ import { ClosureComponent, Children } from "mithril"; import { m } from "./components.ts"; import Expression from "../lib/common/expression.ts"; function drawChart(chartData: Attrs["chart"]): Children { const slices = chartData.slices; const total: number = Array.from(Object.values(chartData.slices)).reduce( (a: number, s) => a + (s["count"]["value"] || 0), 0, ); const legend = []; const paths = []; const links = []; let currentProgressPercentage = 0; let startX = Math.cos(2 * Math.PI * currentProgressPercentage) * 100; let startY = Math.sin(2 * Math.PI * currentProgressPercentage) * 100; let endX, endY; for (const slice of Object.values(slices)) { const percent = total > 0 ? (slice["count"]["value"] || 0) / total : 0; legend.push( m("tr", [ m( "td", m("span.inline-block w-3 h-3 border border-stone-200 mr-1", { style: `background-color: ${slice.color} !important;`, }), ), m("td.w-full", slice.label), m( "td.text-stone-500 text-right tabular-nums", `${Math.round(percent * 100)}%`, ), m( "td.text-right tabular-nums", m( "a.text-cyan-700 hover:text-cyan-900 font-medium ml-2", { href: `#!/devices/?${m.buildQueryString({ filter: slice.filter.toString(), })}`, }, slice["count"]["value"] || 0, ), ), ]), ); if (percent > 0) { currentProgressPercentage += percent; endX = Math.cos(2 * Math.PI * currentProgressPercentage) * 100; endY = Math.sin(2 * Math.PI * currentProgressPercentage) * 100; const isBigArc = percent > 0.5 ? 1 : 0; const sketch = `M ${startX} ${startY} ` + // Move to the starting point `A 100 100 0 ${isBigArc} 1 ${endX} ${endY} ` + // Draw an Arc from starting point to ending point `L 0 0 z`; // complete the shape by drawing a line to the center of circle startX = endX; startY = endY; paths.push( m("path.stroke-white stroke-1", { d: sketch, fill: slice.color, }), ); const percentageX = Math.cos(2 * Math.PI * (currentProgressPercentage - percent / 2)) * 50; const percentageY = Math.sin(2 * Math.PI * (currentProgressPercentage - percent / 2)) * 50; links.push( m( "a.opacity-0 hover:opacity-100 focus-visible:opacity-100 outline-hidden", { "xlink:href": `#!/devices/?${m.buildQueryString({ filter: slice.filter.toString(), })}`, }, [ m("path.stroke-cyan-500 stroke-1", { d: sketch, "fill-opacity": 0, }), m( "text.opacity-40 font-medium fill-black", { x: percentageX, y: percentageY, "dominant-baseline": "middle", "text-anchor": "middle", }, `${Math.round(percent * 100)}%`, ), ], ), ); } } legend.push( m( "tr", m("td", ""), m("td", { colspan: 2 }, "Total"), m("td.text-right tabular-nums", total), ), ); return m( "loading", { queries: Object.values(chartData.slices).map((s) => s["count"]), }, m("div", [ m( "svg.m-4", { // Adding 2 as padding; strokes must not be more than 2 viewBox: "-102 -102 204 204", width: "204px", height: "204px", xmlns: "http://www.w3.org/2000/svg", "xmlns:xlink": "http://www.w3.org/1999/xlink", }, paths.concat(links), ), m("table.mt-8 text-sm", legend), ]), ); } interface Attrs { chart: { label: string; slices: { label: string; filter: Expression; color: string; }[]; }; } const component: ClosureComponent = () => { return { view: (vnode) => { return drawChart(vnode.attrs.chart); }, }; }; export default component; ================================================ FILE: ui/presets-page.ts ================================================ import { ClosureComponent, Component, Children, Vnode } from "mithril"; import { m } from "./components.ts"; import { pageSize as PAGE_SIZE } from "./config.ts"; import filterComponent from "./filter-component.ts"; import * as overlay from "./overlay.ts"; import * as store from "./store.ts"; import * as notifications from "./notifications.ts"; import putFormComponent from "./put-form-component.ts"; import indexTableComponent from "./index-table-component.ts"; import memoize from "../lib/common/memoize.ts"; import * as smartQuery from "./smart-query.ts"; import Expression from "../lib/common/expression.ts"; const memoizedParse = memoize((str) => Expression.parse(str)); const memoizedJsonParse = memoize(JSON.parse); const attributes = [ { id: "_id", label: "Name" }, { id: "channel", label: "Channel" }, { id: "weight", label: "Weight" }, { id: "schedule", label: "Schedule" }, { id: "events", label: "Events" }, { id: "precondition", label: "Precondition", type: "textarea" }, { id: "provision", label: "Provision", type: "combo" }, { id: "provisionArgs", label: "Arguments", type: "textarea" }, ]; const unpackSmartQuery = memoize((query: Expression) => { return query.evaluate((e) => { if (e instanceof Expression.FunctionCall) { if (e.name === "Q") { if ( e.args[0] instanceof Expression.Literal && e.args[1] instanceof Expression.Literal ) { return smartQuery.unpack( "presets", e.args[0].value as string, e.args[1].value as string, ); } } } return e; }); }); interface ValidationErrors { [prop: string]: string; } function getExcerpt(text: string, maxLength = 80, maxLines = 10): string[] { let lines: string[] = text?.split("\n", maxLines + 1) ?? [""]; if (lines.length > maxLines) { lines.pop(); lines[maxLines - 1] = "\ufe19"; } lines = lines.map((l) => { if (l.length <= maxLength) return l; return l.slice(0, maxLength - 1) + "\u2026"; }); return lines; } function putActionHandler(action, _object, isNew): Promise { return new Promise((resolve, reject) => { const object = Object.assign({}, _object); if (action === "save") { const id = object["_id"]; delete object["_id"]; const errors = {}; if (!id) errors["_id"] = "ID can not be empty"; if (!object.provision) errors["provision"] = "Provision not selected"; if (Object.keys(errors).length) return void resolve(errors); if (object.precondition) { try { object.precondition = memoizedParse(object.precondition).toString(); } catch { return void resolve({ precondition: "Precondition must be valid expression", }); } } store .resourceExists("presets", id) .then((exists) => { if (exists && isNew) { store.setTimestamp(Date.now()); return void resolve({ _id: "Preset already exists" }); } if (!exists && !isNew) { store.setTimestamp(Date.now()); return void resolve({ _id: "Preset does not exist" }); } store .putResource("presets", id, object) .then(() => { notifications.push( "success", `Preset ${exists ? "updated" : "created"}`, ); store.setTimestamp(Date.now()); resolve(null); }) .catch(reject); }) .catch(reject); } else if (action === "delete") { if (!confirm("Deleting preset. Are you sure?")) return void resolve(null); store .deleteResource("presets", object["_id"]) .then(() => { notifications.push("success", "Preset deleted"); store.setTimestamp(Date.now()); resolve(null); }) .catch((err) => { reject(err); store.setTimestamp(Date.now()); }); } else { reject(new Error("Undefined action")); } }); } const formData = { resource: "presets", attributes: attributes, }; const getDownloadUrl = memoize((filter) => { const cols = {}; for (const attr of attributes) cols[attr.label] = attr.id; return `api/presets.csv?${m.buildQueryString({ filter: filter.toString(), columns: JSON.stringify(cols), })}`; }); export function init( args: Record, ): Promise> { if (!window.authorizer.hasAccess("presets", 2)) { return Promise.reject( new Error("You are not authorized to view this page"), ); } let filter: Expression = null; let sort: Record = null; if (args.hasOwnProperty("filter")) filter = Expression.parse(args["filter"] as string); if (args.hasOwnProperty("sort")) sort = JSON.parse(args["sort"] as string); return Promise.resolve({ filter, sort }); } export const component: ClosureComponent = (): Component => { return { view: (vnode) => { document.title = "Presets - GenieACS"; function showMore(): void { vnode.state["showCount"] = (vnode.state["showCount"] || PAGE_SIZE) + PAGE_SIZE; m.redraw(); } function onFilterChanged(filter): void { const ops = {}; if (!(filter instanceof Expression.Literal && filter.value)) ops["filter"] = filter.toString(); if (vnode.attrs["sort"]) ops["sort"] = vnode.attrs["sort"]; m.route.set("/presets", ops); } const sort = vnode.attrs["sort"] ? memoizedJsonParse(vnode.attrs["sort"]) : {}; const sortAttributes = {}; for (let i = 0; i < attributes.length; i++) { const attr = attributes[i]; if ( !( attr.id === "events" || attr.id === "precondition" || attr.id === "provision" || attr.id === "provisionArgs" ) ) sortAttributes[i] = sort[attr.id] || 0; } function onSortChange(sortAttrs): void { const _sort = {}; for (const index of sortAttrs) _sort[attributes[Math.abs(index) - 1].id] = Math.sign(index); const ops = { sort: JSON.stringify(_sort) }; if (vnode.attrs["filter"]) ops["filter"] = vnode.attrs["filter"]; m.route.set("/presets", ops); } const filter = unpackSmartQuery( vnode.attrs["filter"] ?? new Expression.Literal(true), ); const presets = store.fetch("presets", filter, { limit: vnode.state["showCount"] || PAGE_SIZE, sort: sort, }); const count = store.count("presets", filter); const userDefinedProvisions: Set = new Set(); const provisionIds = new Set([ "refresh", "value", "tag", "reboot", "reset", "download", "instances", ]); const provisions = store.fetch( "provisions", new Expression.Literal(true), ); if (provisions.fulfilled) { for (const p of provisions.value) { userDefinedProvisions.add(p["_id"]); provisionIds.add(p["_id"]); } } const provisionAttr = attributes.find((attr) => { return attr.id === "provision"; }); provisionAttr["options"] = Array.from(provisionIds); const downloadUrl = getDownloadUrl(filter); const valueCallback = (attr, preset): Vnode => { if (attr.id === "precondition") { let devicesUrl = "#!/devices"; if (preset["precondition"].length) { devicesUrl += `?${m.buildQueryString({ filter: preset["precondition"], })}`; } return m( "a.text-cyan-700 hover:text-cyan-900 font-mono", { href: devicesUrl, title: preset["precondition"] }, getExcerpt(preset["precondition"], 80, 1)[0], ); } else if (attr.id === "provisionArgs") { return m( "span.font-mono", { title: preset["provisionArgs"] }, getExcerpt(preset["provisionArgs"], 80, 1)[0], ); } else if ( attr.id === "provision" && userDefinedProvisions.has(preset[attr.id]) ) { return m( "a.text-cyan-700 hover:text-cyan-900", { href: `#!/provisions?${m.buildQueryString({ filter: `Q("ID", "${preset["provision"]}")`, })}`, }, preset["provision"], ); } else { return preset[attr.id]; } }; const attrs = {}; attrs["attributes"] = attributes; attrs["data"] = presets.value; attrs["total"] = count.value; attrs["showMoreCallback"] = showMore; attrs["sortAttributes"] = sortAttributes; attrs["onSortChange"] = onSortChange; attrs["downloadUrl"] = downloadUrl; attrs["valueCallback"] = valueCallback; attrs["recordActionsCallback"] = (preset) => { return [ m( "button.text-cyan-700 hover:text-cyan-900 font-medium", { onclick: () => { let cb: () => Children = null; const comp = m( putFormComponent, Object.assign( { base: preset, actionHandler: (action, object) => { return new Promise((resolve) => { putActionHandler(action, object, false) .then((errors) => { const errorList = errors ? Object.values(errors) : []; if (errorList.length) { for (const err of errorList) notifications.push("error", err); } else { overlay.close(cb); } resolve(); }) .catch((err) => { notifications.push("error", err.message); resolve(); }); }); }, }, formData, ), ); cb = (): Children => { if (!preset.provision) { return m( "div", { style: "margin:20px" }, "This UI only supports presets with a single 'provision' configuration. If this preset was originally created from the old UI (genieacs-gui), you must edit it there.", ); } return comp; }; overlay.open( cb, () => !comp.state?.["current"]["modified"] || confirm("You have unsaved changes. Close anyway?"), ); }, }, "Show", ), ]; }; if (window.authorizer.hasAccess("presets", 3)) { attrs["actionsCallback"] = (selected: Set): Children => { return [ m( "button.px-4 py-2 border border-stone-300 shadow-xs text-sm font-medium rounded-md text-stone-700 bg-white hover:bg-stone-50 focus:outline-hidden focus:ring-2 focus:ring-offset-2 focus:ring-cyan-500 disabled:opacity-50 disabled:cursor-not-allowed", { title: "Create new preset", onclick: () => { let cb: () => Children = null; const comp = m( putFormComponent, Object.assign( { actionHandler: (action, object) => { return new Promise((resolve) => { putActionHandler(action, object, true) .then((errors) => { const errorList = errors ? Object.values(errors) : []; if (errorList.length) { for (const err of errorList) notifications.push("error", err); } else { overlay.close(cb); } resolve(); }) .catch((err) => { notifications.push("error", err.message); resolve(); }); }); }, }, formData, ), ); cb = () => comp; overlay.open( cb, () => !comp.state["current"]["modified"] || confirm("You have unsaved changes. Close anyway?"), ); }, }, "New", ), m( "button.px-4 py-2 border border-stone-300 shadow-xs text-sm font-medium rounded-md text-stone-700 bg-white hover:bg-stone-50 focus:outline-hidden focus:ring-2 focus:ring-offset-2 focus:ring-cyan-500 disabled:opacity-50 disabled:cursor-not-allowed", { title: "Delete selected presets", disabled: !selected.size, onclick: (e) => { if ( !confirm(`Deleting ${selected.size} presets. Are you sure?`) ) return; e.redraw = false; e.target.disabled = true; Promise.all( Array.from(selected).map((id) => store.deleteResource("presets", id), ), ) .then((res) => { notifications.push( "success", `${res.length} presets deleted`, ); store.setTimestamp(Date.now()); }) .catch((err) => { notifications.push("error", err.message); store.setTimestamp(Date.now()); }); }, }, "Delete", ), ]; }; } const filterAttrs = { resource: "presets", filter: vnode.attrs["filter"], onChange: onFilterChanged, }; return [ m("h1.text-xl font-medium text-stone-900 mb-5", "Listing presets"), m(filterComponent, filterAttrs), m( "loading", { queries: [presets, count] }, m(indexTableComponent, attrs), ), ]; }, }; }; ================================================ FILE: ui/provisions-page.ts ================================================ import { ClosureComponent, Component, Children } from "mithril"; import { m } from "./components.ts"; import { pageSize as PAGE_SIZE } from "./config.ts"; import filterComponent from "./filter-component.ts"; import * as store from "./store.ts"; import * as notifications from "./notifications.ts"; import memoize from "../lib/common/memoize.ts"; import putFormComponent from "./put-form-component.ts"; import indexTableComponent from "./index-table-component.ts"; import * as overlay from "./overlay.ts"; import * as smartQuery from "./smart-query.ts"; import Expression from "../lib/common/expression.ts"; import { loadCodeMirror } from "./dynamic-loader.ts"; const memoizedJsonParse = memoize(JSON.parse); const attributes = [ { id: "_id", label: "Name" }, { id: "script", label: "Script", type: "code", mode: "javascript" }, ]; const unpackSmartQuery = memoize((query: Expression) => { return query.evaluate((e) => { if (e instanceof Expression.FunctionCall) { if (e.name === "Q") { if ( e.args[0] instanceof Expression.Literal && e.args[1] instanceof Expression.Literal ) { return smartQuery.unpack( "provisions", e.args[0].value as string, e.args[1].value as string, ); } } } return e; }); }); interface ValidationErrors { [prop: string]: string; } function putActionHandler(action, _object, isNew): Promise { return new Promise((resolve, reject) => { const object = Object.assign({}, _object); if (action === "save") { const id = object["_id"]; delete object["_id"]; if (!id) return void resolve({ _id: "ID can not be empty" }); store .resourceExists("provisions", id) .then((exists) => { if (exists && isNew) { store.setTimestamp(Date.now()); return void resolve({ _id: "Provision already exists" }); } if (!exists && !isNew) { store.setTimestamp(Date.now()); return void resolve({ _id: "Provision does not exist" }); } store .putResource("provisions", id, object) .then(() => { notifications.push( "success", `Provision ${exists ? "updated" : "created"}`, ); store.setTimestamp(Date.now()); resolve(null); }) .catch((err) => { if (err["code"] === 400 && err["response"]) { reject(new Error(err["response"])); return; } reject(err); }); }) .catch(reject); } else if (action === "delete") { if (!confirm("Deleting provision. Are you sure?")) return void resolve(null); store .deleteResource("provisions", object["_id"]) .then(() => { notifications.push("success", "Provision deleted"); store.setTimestamp(Date.now()); resolve(null); }) .catch((err) => { store.setTimestamp(Date.now()); reject(err); }); } else { reject(new Error("Undefined action")); } }); } const formData = { resource: "provisions", attributes: attributes, }; const getDownloadUrl = memoize((filter) => { const cols = {}; for (const attr of attributes) cols[attr.label] = attr.id; return `api/provisions.csv?${m.buildQueryString({ filter: filter.toString(), columns: JSON.stringify(cols), })}`; }); export function init( args: Record, ): Promise> { if (!window.authorizer.hasAccess("provisions", 2)) { return Promise.reject( new Error("You are not authorized to view this page"), ); } let filter: Expression = null; let sort: Record = null; if (args.hasOwnProperty("filter")) filter = Expression.parse(args["filter"] as string); if (args.hasOwnProperty("sort")) sort = JSON.parse(args["sort"] as string); return new Promise((resolve, reject) => { loadCodeMirror() .then(() => { resolve({ filter, sort }); }) .catch(reject); }); } export const component: ClosureComponent = (): Component => { return { view: (vnode) => { document.title = "Provisions - GenieACS"; function showMore(): void { vnode.state["showCount"] = (vnode.state["showCount"] || PAGE_SIZE) + PAGE_SIZE; m.redraw(); } function onFilterChanged(filter): void { const ops = {}; if (!(filter instanceof Expression.Literal && filter.value)) ops["filter"] = filter.toString(); if (vnode.attrs["sort"]) ops["sort"] = vnode.attrs["sort"]; m.route.set("/provisions", ops); } const sort = vnode.attrs["sort"] ? memoizedJsonParse(vnode.attrs["sort"]) : {}; const sortAttributes = {}; for (let i = 0; i < attributes.length; i++) sortAttributes[i] = sort[attributes[i].id] || 0; function onSortChange(sortAttrs): void { const _sort = {}; for (const index of sortAttrs) _sort[attributes[Math.abs(index) - 1].id] = Math.sign(index); const ops = { sort: JSON.stringify(_sort) }; if (vnode.attrs["filter"]) ops["filter"] = vnode.attrs["filter"]; m.route.set("/provisions", ops); } const filter = unpackSmartQuery( vnode.attrs["filter"] ?? new Expression.Literal(true), ); const provisions = store.fetch("provisions", filter, { limit: vnode.state["showCount"] || PAGE_SIZE, sort: sort, }); const count = store.count("provisions", filter); const downloadUrl = getDownloadUrl(filter); const attrs = {}; attrs["attributes"] = attributes; attrs["data"] = provisions.value; attrs["total"] = count.value; attrs["showMoreCallback"] = showMore; attrs["sortAttributes"] = sortAttributes; attrs["onSortChange"] = onSortChange; attrs["downloadUrl"] = downloadUrl; attrs["recordActionsCallback"] = (provision) => { return [ m( "button.text-cyan-700 hover:text-cyan-900 font-medium", { onclick: () => { let cb: () => Children = null; const comp = m( putFormComponent, Object.assign( { base: provision, actionHandler: (action, object) => { return new Promise((resolve) => { putActionHandler(action, object, false) .then((errors) => { const errorList = errors ? Object.values(errors) : []; if (errorList.length) { for (const err of errorList) notifications.push("error", err); } else { overlay.close(cb); } resolve(); }) .catch((err) => { notifications.push("error", err.message); resolve(); }); }); }, }, formData, ), ); cb = () => comp; overlay.open( cb, () => !comp.state["current"]["modified"] || confirm("You have unsaved changes. Close anyway?"), ); }, }, "Show", ), ]; }; if (window.authorizer.hasAccess("provisions", 3)) { attrs["actionsCallback"] = (selected: Set): Children => { return [ m( "button.px-4 py-2 border border-stone-300 shadow-xs text-sm font-medium rounded-md text-stone-700 bg-white hover:bg-stone-50 focus:outline-hidden focus:ring-2 focus:ring-offset-2 focus:ring-cyan-500 disabled:opacity-50 disabled:cursor-not-allowed", { title: "Create new provision", onclick: () => { let cb: () => Children = null; const comp = m( putFormComponent, Object.assign( { actionHandler: (action, object) => { return new Promise((resolve) => { putActionHandler(action, object, true) .then((errors) => { const errorList = errors ? Object.values(errors) : []; if (errorList.length) { for (const err of errorList) notifications.push("error", err); } else { overlay.close(cb); } resolve(); }) .catch((err) => { notifications.push("error", err.message); resolve(); }); }); }, }, formData, ), ); cb = () => comp; overlay.open( cb, () => !comp.state["current"]["modified"] || confirm("You have unsaved changes. Close anyway?"), ); }, }, "New", ), m( "button.px-4 py-2 border border-stone-300 shadow-xs text-sm font-medium rounded-md text-stone-700 bg-white hover:bg-stone-50 focus:outline-hidden focus:ring-2 focus:ring-offset-2 focus:ring-cyan-500 disabled:opacity-50 disabled:cursor-not-allowed", { title: "Delete selected provisions", disabled: !selected.size, onclick: (e) => { if ( !confirm( `Deleting ${selected.size} provisions. Are you sure?`, ) ) return; e.redraw = false; e.target.disabled = true; Promise.all( Array.from(selected).map((id) => store.deleteResource("provisions", id), ), ) .then((res) => { notifications.push( "success", `${res.length} provisions deleted`, ); store.setTimestamp(Date.now()); }) .catch((err) => { notifications.push("error", err.message); store.setTimestamp(Date.now()); }); }, }, "Delete", ), ]; }; } const filterAttrs = { resource: "provisions", filter: vnode.attrs["filter"], onChange: onFilterChanged, }; return [ m("h1.text-xl font-medium text-stone-900 mb-5", "Listing provisions"), m(filterComponent, filterAttrs), m( "loading", { queries: [provisions, count] }, m(indexTableComponent, attrs), ), ]; }, }; }; ================================================ FILE: ui/put-form-component.ts ================================================ import { VnodeDOM, ClosureComponent, Children } from "mithril"; import { m } from "./components.ts"; import codeEditorComponent from "./code-editor-component.ts"; import { getDatalistId } from "./datalist.ts"; const singular = { presets: "preset", provisions: "provision", virtualParameters: "virtual parameter", files: "file", users: "user", permissions: "permission", views: "view", }; function createField(current, attr, focus): Children { if (attr.type === "combo") { let selected = ""; let optionsValues = attr.options; if (current.object[attr.id] != null) { if (!optionsValues.includes(current.object[attr.id])) optionsValues = optionsValues.concat([current.object[attr.id]]); selected = current.object[attr.id]; } const options = [m("option", { value: "" }, "")]; for (const op of optionsValues) options.push(m("option", { value: op }, op)); return m( "select.mt-1 block pl-3 pr-10 py-2 text-base border-stone-300 focus:outline-hidden focus:ring-cyan-500 focus:border-cyan-500 sm:text-sm rounded-md", { name: attr.id, value: selected, oncreate: focus ? (_vnode) => { (_vnode.dom as HTMLSelectElement).focus(); } : null, onchange: (e) => { current.object[attr.id] = e.target.value; current.modified = true; e.redraw = false; }, }, options, ); } else if (attr.type === "multi") { const optionsValues = Array.from( new Set(attr.options.concat(current.object[attr.id] || [])), ); const currentSelected = new Set(current.object[attr.id]); const options = optionsValues.map((op) => { const id = `${attr.id}-${op}`; const opts = { type: "checkbox", id: id, value: op, oncreate: (_vnode) => { if (focus && !options.length) _vnode.dom.focus(); if (currentSelected.has(op)) _vnode.dom.checked = true; }, onchange: (e) => { if (e.target.checked) currentSelected.add(op); else currentSelected.delete(op); current.object[attr.id] = Array.from(currentSelected); current.modified = true; e.redraw = false; }, }; return m("tr", [ m( "td", m( "input.focus:ring-cyan-500 h-4 w-4 text-cyan-700 border-stone-300 rounded-sm", opts, ), ), m("td", op), ]); }); return m("table", options); } else if (attr.type === "code") { const attrs = { id: attr.id, value: current.object[attr.id], mode: attr.mode || "javascript", onSubmit: (dom) => { dom.form.querySelector("button[type=submit]").click(); }, onChange: (value) => { current.object[attr.id] = value; current.modified = true; }, }; return m(codeEditorComponent, attrs); } else if (attr.type === "file") { return m("input", { type: "file", name: attr.id, oncreate: focus ? (_vnode) => { (_vnode.dom as HTMLInputElement).focus(); } : null, onchange: (e) => { current.object[attr.id] = e.target.files; current.modified = true; e.redraw = false; }, }); } else if (attr.type === "textarea") { return m( "textarea.shadow-xs block focus:ring-cyan-500 focus:border-cyan-500 sm:text-sm border border-stone-300 rounded-md", { name: attr.id, value: current.object[attr.id], readonly: attr.id === "_id" && !current.isNew, cols: attr.cols || 80, rows: attr.rows || 4, style: "resize: none;", oncreate: focus ? (_vnode) => { const dom = _vnode.dom as HTMLInputElement; dom.focus(); dom.setSelectionRange(dom.value.length, dom.value.length); } : null, oninput: (e) => { current.object[attr.id] = e.target.value; current.modified = true; e.redraw = false; }, onkeypress: (e) => { e.redraw = false; if (e.which === 13 && !e.shiftKey) { const dom = e.target; dom.form.querySelector("button[type=submit]").click(); return false; } return true; }, }, ); } let datalist: string = null; if (attr.options) datalist = getDatalistId(attr.options); return m( "input.shadow-xs focus:ring-cyan-500 focus:border-cyan-500 block sm:text-sm border-stone-300 rounded-md", { type: attr.type === "password" ? "password" : "text", name: attr.id, list: datalist, autocomplete: datalist ? "off" : null, disabled: attr.id === "_id" && !current.isNew, value: current.object[attr.id], oncreate: focus ? (_vnode) => { (_vnode.dom as HTMLInputElement).focus(); } : null, oninput: (e) => { current.object[attr.id] = e.target.value; current.modified = true; e.redraw = false; }, }, ); } interface Attrs { base?: Record; actionHandler: (action: string, object: any) => Promise; resource: string; attributes: { id: string; label: string; type?: string; options?: string[]; }[]; } const component: ClosureComponent = () => { return { view: (vnode) => { const actionHandler = vnode.attrs.actionHandler; const attributes = vnode.attrs.attributes; const resource = vnode.attrs.resource; const base = vnode.attrs.base || {}; if (!vnode.state["current"]) { vnode.state["current"] = { isNew: !base["_id"], object: Object.assign({}, base), modified: false, }; } const current = vnode.state["current"]; const form = []; let focused = false; for (const attr of attributes) { let focus = false; if (!focused && (current.isNew || attr.id !== "_id")) focus = focused = true; form.push( m( "p", m( "label.block text-sm font-semibold text-stone-700 mt-2 mb-1", { for: attr.id }, attr.label || attr.id, ), createField(current, attr, focus), ), ); } const buttons: VnodeDOM[] = []; if (!current.isNew) { buttons.push( m( "button.ml-3 inline-flex justify-center py-2 px-4 border border-transparent shadow-xs text-sm font-medium rounded-md text-white bg-red-600 hover:bg-red-700 focus:outline-hidden focus:ring-2 focus:ring-offset-2 focus:ring-red-500", { type: "button", title: `Delete ${singular[resource] || resource}`, onclick: (e) => { e.redraw = false; e.target.disabled = true; void actionHandler("delete", current.object).finally(() => { e.target.disabled = false; }); }, }, "Delete", ) as VnodeDOM, ); } const submit = m( "button.ml-3 inline-flex justify-center py-2 px-4 border border-transparent shadow-xs text-sm font-medium rounded-md text-white bg-cyan-600 hover:bg-cyan-700 focus:outline-hidden focus:ring-2 focus:ring-offset-2 focus:ring-cyan-500", { type: "submit" }, "Save", ) as VnodeDOM; buttons.push(submit); form.push(m("div.flex justify-end mt-5", buttons)); const children = [ m( "h2.text-lg leading-6 font-medium text-stone-900", `${current.isNew ? "New" : "Editing"} ${ singular[resource] || resource }`, ), m( "form", { onsubmit: (e) => { e.redraw = false; // const onsubmit = e.target.onsubmit; e.preventDefault(); // e.target.onsubmit = null; (submit.dom as HTMLFormElement).disabled = true; // submit.dom.textContent = "Loading ..."; void actionHandler("save", current.object).finally(() => { // submit.dom.textContent = "Save"; // e.target.onsubmit = onsubmit; (submit.dom as HTMLFormElement).disabled = false; }); }, }, form, ), ]; return m("div", children); }, }; }; export default component; ================================================ FILE: ui/reactive-store.ts ================================================ import m from "mithril"; import { SignalBase, ComputedSignal, ComputedState, Watcher, registerDependency, } from "./signals.ts"; import { xhrRequest } from "./store.ts"; import { SkewedDate } from "./skewed-date.ts"; import { subtract, covers } from "../lib/common/expression/synth.ts"; import { bookmarkToExpression, toBookmark, } from "../lib/common/expression/pagination.ts"; import Expression from "../lib/common/expression.ts"; import memoize from "../lib/common/memoize.ts"; const memoizedStringify = memoize((e: Expression) => e.toString()); function evaluate( exp: Expression, timestamp: number, obj: Record, ): Expression { return exp.evaluate((e) => { if (e instanceof Expression.Literal) return e; else if (e instanceof Expression.FunctionCall) { if (e.name === "NOW") return new Expression.Literal(timestamp); } else if (e instanceof Expression.Parameter && obj) { let v = obj[e.path.toString()]; if (v == null) return new Expression.Literal(null); if (typeof v === "object") v = (v as Record)["value"]?.[0]; return new Expression.Literal(v as string | number | boolean | null); } return e; }); } type BookmarkData = Record; export interface QueryState { value: T; timestamp: number; // 0 means never fetched loading: boolean; } interface FetchedRegion { filter: Expression; timestamp: number; filterStr: string; } interface CachedCount { value: number; timestamp: number; } interface CachedBookmark { data: BookmarkData | null; timestamp: number; } interface ResourceCache { objects: Map; // Cached objects by ID counts: Map; // Count cache keyed by stringified filter bookmarks: Map; // Bookmark cache keyed by (filter, sort, offset) fetchedRegions: FetchedRegion[]; // Tracks what filter regions were fetched when } export class Bookmark { constructor( private _data: BookmarkData, private _sort: Record, ) {} // bookmarkToExpression returns condition for rows <= bookmark position applySkip(filter: Expression): Expression { const condition = bookmarkToExpression(this._data, this._sort); return Expression.and(filter, condition); } // NOT(rows <= bookmark) = rows > bookmark applyLimit(filter: Expression): Expression { const condition = bookmarkToExpression(this._data, this._sort); return Expression.and(filter, new Expression.Unary("NOT", condition)); } } export class QuerySignal extends SignalBase> { declare _sinks: Set | Watcher>>; private _state: QueryState; constructor(initialValue: T) { super(); this._sinks = new Set(); this._state = { value: initialValue, timestamp: 0, loading: true, }; } get(): QueryState { if (this._disposed) throw new Error("Cannot read disposed signal"); registerDependency(this); return this._state; } // Returns the state without registering a dependency _peek(): QueryState { if (this._disposed) throw new Error("Cannot read disposed signal"); return this._state; } _update(value: T, timestamp: number, loading: boolean): void { const changed = !Object.is(this._state.value, value) || this._state.timestamp !== timestamp || this._state.loading !== loading; if (changed) { this._state = { value, timestamp, loading }; this._markSinksDirty(); } } private _markSinksDirty(): void { for (const weakRef of this._sinks) { const sink = weakRef.deref(); if (sink === undefined) { this._sinks.delete(weakRef); continue; } if (sink instanceof Watcher) { sink._notify(); continue; } sink._state = ComputedState.Dirty; this._markSinksChecking(sink._sinks); } } private _markSinksChecking( sinks: Set | Watcher>>, ): void { for (const weakRef of sinks) { const sink = weakRef.deref(); if (sink === undefined) { sinks.delete(weakRef); continue; } if (sink instanceof Watcher) { sink._notify(); continue; } if ((sink as { _state: ComputedState })._state === ComputedState.Clean) { (sink as { _state: ComputedState })._state = ComputedState.Checking; this._markSinksChecking((sink as ComputedSignal)._sinks); } } } [Symbol.dispose](): void { if (this._disposed) return; this._disposed = true; this._sinks.clear(); } } function compareFunction( sort: Record, ): (a: unknown, b: unknown) => number { return (a, b) => { for (const [param, asc] of Object.entries(sort)) { let v1 = (a as Record)[param]; let v2 = (b as Record)[param]; if (v1 != null && typeof v1 === "object") { const v1Obj = v1 as { value?: unknown[] }; if (v1Obj.value) v1 = v1Obj.value[0]; else v1 = null; } if (v2 != null && typeof v2 === "object") { const v2Obj = v2 as { value?: unknown[] }; if (v2Obj.value) v2 = v2Obj.value[0]; else v2 = null; } if (v1 > v2) { return asc; } else if (v1 < v2) { return asc * -1; } else if (v1 !== v2) { const w: Record = { null: 1, number: 2, string: 3, }; const w1 = w[v1 == null ? "null" : typeof v1] || 4; const w2 = w[v2 == null ? "null" : typeof v2] || 4; return Math.max(-1, Math.min(1, w1 - w2)) * asc; } } return 0; }; } function getObjectId(resourceType: string, obj: unknown): string { const record = obj as Record; if (resourceType === "devices") return (record["DeviceID.ID"] as string) ?? ""; return (record["_id"] as string) ?? ""; } interface FetchQueryEntry { weakRef: globalThis.WeakRef>; filter: Expression; sort: Record; } interface CountQueryEntry { weakRef: globalThis.WeakRef>; filter: Expression; } interface BookmarkQueryEntry { weakRef: globalThis.WeakRef>; filter: Expression; sort: Record; offset: number; } class ResourceStore { private cache: ResourceCache; private fetchQueries: Map; private countQueries: Map; private bookmarkQueries: Map; private registry: globalThis.FinalizationRegistry<{ type: string; key: string; }>; constructor(private resourceType: string) { this.cache = { objects: new Map(), counts: new Map(), bookmarks: new Map(), fetchedRegions: [], }; this.fetchQueries = new Map(); this.countQueries = new Map(); this.bookmarkQueries = new Map(); this.registry = new globalThis.FinalizationRegistry(({ type, key }) => { this.onQueryDisposed(type, key); }); } fetch( filter: Expression, sort: Record, freshness: number, ): QuerySignal { const filterStr = memoizedStringify(filter); const key = `${filterStr}:${JSON.stringify(sort)}`; const existingEntry = this.fetchQueries.get(key); if (existingEntry) { const existing = existingEntry.weakRef.deref(); if (existing) { // Use _peek() to avoid registering a dependency on the caller const state = existing._peek(); if (state.timestamp < freshness && !state.loading) { existing._update(state.value, state.timestamp, true); this.triggerFetchRefresh(filter, sort, existing, freshness); } return existing; } } const signal = new QuerySignal([]); const weakRef = new globalThis.WeakRef(signal); this.fetchQueries.set(key, { weakRef, filter, sort }); this.registry.register(signal, { type: "fetch", key }); const cachedData = this.findMatchingObjects(filter, sort); const { covered, oldestTimestamp } = this.checkCoverage(filter, freshness); if (cachedData.length > 0) { signal._update(cachedData, oldestTimestamp, !covered); } if (!covered) { this.triggerFetchRefresh(filter, sort, signal, freshness); } else { signal._update(cachedData, oldestTimestamp, false); } return signal; } count(filter: Expression, freshness: number): QuerySignal { const filterStr = memoizedStringify(filter); const existingEntry = this.countQueries.get(filterStr); if (existingEntry) { const existing = existingEntry.weakRef.deref(); if (existing) { // Use _peek() to avoid registering a dependency on the caller const state = existing._peek(); if (state.timestamp < freshness && !state.loading) { existing._update(state.value, state.timestamp, true); this.triggerCountRefresh(filter, existing); } return existing; } } const signal = new QuerySignal(0); const weakRef = new globalThis.WeakRef(signal); this.countQueries.set(filterStr, { weakRef, filter }); this.registry.register(signal, { type: "count", key: filterStr }); const cached = this.cache.counts.get(filterStr); if (cached && cached.timestamp >= freshness) { signal._update(cached.value, cached.timestamp, false); } else { if (cached) { signal._update(cached.value, cached.timestamp, true); } this.triggerCountRefresh(filter, signal); } return signal; } createBookmark( filter: Expression, sort: Record, offset: number, freshness: number, after?: Bookmark, ): QuerySignal { const effectiveFilter = after ? after.applySkip(filter) : filter; const filterStr = memoizedStringify(effectiveFilter); const key = `${filterStr}:${JSON.stringify(sort)}:${offset}`; const existingEntry = this.bookmarkQueries.get(key); if (existingEntry) { const existing = existingEntry.weakRef.deref(); if (existing) { // Use _peek() to avoid registering a dependency on the caller const state = existing._peek(); if (state.timestamp < freshness && !state.loading) { this.triggerBookmarkRefresh(effectiveFilter, sort, offset, existing); } return existing; } } const signal = new QuerySignal(null); const weakRef = new globalThis.WeakRef(signal); this.bookmarkQueries.set(key, { weakRef, filter: effectiveFilter, sort, offset, }); this.registry.register(signal, { type: "bookmark", key }); const cached = this.cache.bookmarks.get(key); if (cached && cached.timestamp >= freshness) { const bookmark = cached.data ? new Bookmark(cached.data, sort) : null; signal._update(bookmark, cached.timestamp, false); } else { if (cached) { const bookmark = cached.data ? new Bookmark(cached.data, sort) : null; signal._update(bookmark, cached.timestamp, true); } this.triggerBookmarkRefresh(effectiveFilter, sort, offset, signal); } return signal; } private getCombinedFilter(minTimestamp: number): Expression { return this.cache.fetchedRegions .filter((region) => region.timestamp >= minTimestamp) .reduce( (acc, region) => Expression.or(acc, region.filter), new Expression.Literal(false) as Expression, ); } private checkCoverage( filter: Expression, freshness: number, ): { covered: boolean; diff: Expression; oldestTimestamp: number } { const freshRegions = this.cache.fetchedRegions.filter( (region) => region.timestamp >= freshness, ); if (freshRegions.length === 0) { return { covered: false, diff: filter, oldestTimestamp: 0 }; } const combined = freshRegions.reduce( (acc, region) => Expression.or(acc, region.filter), new Expression.Literal(false) as Expression, ); const oldestTimestamp = Math.min(...freshRegions.map((r) => r.timestamp)); const diff = subtract(combined, filter); return { covered: diff instanceof Expression.Literal && !diff.value, diff, oldestTimestamp, }; } private findMatchingObjects( filter: Expression, sort: Record, ): unknown[] { const now = SkewedDate.now(); const matches: unknown[] = []; for (const obj of this.cache.objects.values()) { const result = evaluate(filter, now, obj as Record); if (result instanceof Expression.Literal && !!result.value) { matches.push(obj); } } return matches.sort(compareFunction(sort)); } // Subtract new region from existing regions to maintain non-overlapping regions private addFetchedRegion(filter: Expression, timestamp: number): void { const filterStr = memoizedStringify(filter); const updatedRegions: FetchedRegion[] = []; for (const region of this.cache.fetchedRegions) { const remainder = subtract(filter, region.filter); if (!(remainder instanceof Expression.Literal && !remainder.value)) { updatedRegions.push({ filter: remainder, timestamp: region.timestamp, filterStr: memoizedStringify(remainder), }); } } updatedRegions.push({ filter, timestamp, filterStr, }); this.cache.fetchedRegions = updatedRegions; } // TODO: Consider batching concurrent fetch requests for the same resource. // Currently each query issues its own XHR. When multiple queries are // triggered at the same time (e.g. after invalidation), they race and // fetch overlapping data independently. A batching mechanism could combine // them into fewer requests by deferring execution to the next microtask and // merging the filters. private triggerFetchRefresh( filter: Expression, sort: Record, signal: QuerySignal, freshness: number, ): void { const doFetch = async (retryCount = 0): Promise => { try { const combined = this.getCombinedFilter(freshness); const diff = subtract(combined, filter); if (diff instanceof Expression.Literal && !diff.value) { const data = this.findMatchingObjects(filter, sort); signal._update(data, Date.now(), false); return; } const filterStr = memoizedStringify(diff); const res = await xhrRequest({ method: "GET", url: `api/${this.resourceType}/?` + m.buildQueryString({ filter: filterStr, }), background: true, }); const returnedIds = new Set(); for (const obj of res as unknown[]) { const id = getObjectId(this.resourceType, obj); if (id) { this.cache.objects.set(id, obj); returnedIds.add(id); } } for (const obj of this.findMatchingObjects(filter, {})) { const id = getObjectId(this.resourceType, obj); if (!returnedIds.has(id)) this.cache.objects.delete(id); } const now = Date.now(); this.addFetchedRegion(diff, now); const data = this.findMatchingObjects(filter, sort); signal._update(data, now, false); } catch (err) { console.error( `Error fetching ${this.resourceType}:`, (err as Error).message, ); if (retryCount < 1) { await new Promise((resolve) => globalThis.setTimeout(resolve, 1000)); return doFetch(retryCount + 1); } const state = signal.get(); signal._update(state.value, state.timestamp, false); } }; void doFetch(); } private triggerCountRefresh( filter: Expression, signal: QuerySignal, ): void { const doCount = async (retryCount = 0): Promise => { try { const filterStr = memoizedStringify(filter); const countValue = await xhrRequest({ method: "HEAD", url: `api/${this.resourceType}/?` + m.buildQueryString({ filter: filterStr, }), extract: (xhr: XMLHttpRequest) => { if (xhr.status === 403) throw new Error("Not authorized"); if (!xhr.status) throw new Error("Server is unreachable"); if (xhr.status !== 200) { throw new Error(`Unexpected response status code ${xhr.status}`); } return +xhr.getResponseHeader("x-total-count")!; }, background: true, }); const now = Date.now(); this.cache.counts.set(filterStr, { value: countValue, timestamp: now }); signal._update(countValue, now, false); } catch (err) { console.error( `Error counting ${this.resourceType}:`, (err as Error).message, ); if (retryCount < 1) { await new Promise((resolve) => globalThis.setTimeout(resolve, 1000)); return doCount(retryCount + 1); } const state = signal.get(); signal._update(state.value, state.timestamp, false); } }; void doCount(); } private triggerBookmarkRefresh( filter: Expression, sort: Record, offset: number, signal: QuerySignal, ): void { const doBookmark = async (retryCount = 0): Promise => { try { const filterStr = memoizedStringify(filter); const projection = Object.keys(sort).join(","); const res = await xhrRequest({ method: "GET", url: `api/${this.resourceType}/?` + m.buildQueryString({ filter: filterStr, skip: offset, limit: 1, sort: JSON.stringify(sort), projection, }), background: true, }); const now = Date.now(); const key = `${filterStr}:${JSON.stringify(sort)}:${offset}`; let bookmarkData: BookmarkData | null = null; if ((res as unknown[]).length > 0) { bookmarkData = toBookmark(sort, (res as unknown[])[0]); } this.cache.bookmarks.set(key, { data: bookmarkData, timestamp: now }); const bookmark = bookmarkData ? new Bookmark(bookmarkData, sort) : null; signal._update(bookmark, now, false); } catch (err) { console.error( `Error creating bookmark for ${this.resourceType}:`, (err as Error).message, ); if (retryCount < 1) { await new Promise((resolve) => globalThis.setTimeout(resolve, 1000)); return doBookmark(retryCount + 1); } const state = signal.get(); signal._update(state.value, state.timestamp, false); } }; void doBookmark(); } invalidate(timestamp: number): void { // Invalidate queries whose data was fetched strictly before the given // timestamp. The timestamp is exclusive: data fetched at exactly the // given timestamp is considered fresh. for (const [, entry] of this.fetchQueries) { const signal = entry.weakRef.deref(); if (!signal || signal._disposed) continue; const state = signal._peek(); if (state.timestamp < timestamp && !state.loading) { signal._update(state.value, state.timestamp, true); this.triggerFetchRefresh(entry.filter, entry.sort, signal, timestamp); } } // Invalidate count queries for (const [, entry] of this.countQueries) { const signal = entry.weakRef.deref(); if (!signal || signal._disposed) continue; const state = signal._peek(); if (state.timestamp < timestamp && !state.loading) { signal._update(state.value, state.timestamp, true); this.triggerCountRefresh(entry.filter, signal); } } // Invalidate bookmark queries for (const [, entry] of this.bookmarkQueries) { const signal = entry.weakRef.deref(); if (!signal || signal._disposed) continue; const state = signal._peek(); if (state.timestamp < timestamp && !state.loading) { signal._update(state.value, state.timestamp, true); this.triggerBookmarkRefresh( entry.filter, entry.sort, entry.offset, signal, ); } } } private onQueryDisposed(type: string, key: string): void { if (type === "fetch") { this.fetchQueries.delete(key); this.pruneCache(); } else if (type === "count") { this.countQueries.delete(key); this.cache.counts.delete(key); } else if (type === "bookmark") { this.bookmarkQueries.delete(key); this.cache.bookmarks.delete(key); } } private pruneCache(): void { const neededFilters: Expression[] = []; for (const [key, entry] of this.fetchQueries) { const signal = entry.weakRef.deref(); if (!signal || signal._disposed) { this.fetchQueries.delete(key); continue; } neededFilters.push(entry.filter); } if (neededFilters.length === 0) { this.cache.objects.clear(); this.cache.fetchedRegions = []; return; } const combinedNeeded = neededFilters.reduce( (acc, filter) => Expression.or(acc, filter), new Expression.Literal(false) as Expression, ); const keptRegions: FetchedRegion[] = []; for (const region of this.cache.fetchedRegions) { const intersection = Expression.and(region.filter, combinedNeeded); if (!covers(new Expression.Literal(false), intersection)) { keptRegions.push(region); } } this.cache.fetchedRegions = keptRegions; if (keptRegions.length === 0) { this.cache.objects.clear(); } else { const keptCombined = keptRegions.reduce( (acc, region) => Expression.or(acc, region.filter), new Expression.Literal(false) as Expression, ); const now = SkewedDate.now(); for (const [id, obj] of this.cache.objects) { const result = evaluate( keptCombined, now, obj as Record, ); if (!(result instanceof Expression.Literal && !!result.value)) { this.cache.objects.delete(id); } } } } } const stores: Map = new Map(); function getStore(resource: string): ResourceStore { let store = stores.get(resource); if (!store) { store = new ResourceStore(resource); stores.set(resource, store); } return store; } function applyDefaultSort( resourceType: string, sort?: Record, ): Record { const result = Object.assign({}, sort); if (resourceType === "devices") { result["DeviceID.ID"] = result["DeviceID.ID"] || 1; } else { result["_id"] = result["_id"] || 1; } return result; } export function fetch( resource: string, filter: Expression, options: { sort?: Record; freshness?: number; } = {}, ): QuerySignal { const sort = applyDefaultSort(resource, options.sort); const freshness = options.freshness ?? 0; return getStore(resource).fetch(filter, sort, freshness); } export function count( resource: string, filter: Expression, options: { freshness?: number } = {}, ): QuerySignal { const freshness = options.freshness ?? 0; return getStore(resource).count(filter, freshness); } export function createBookmark( resource: string, filter: Expression, sort: Record, offset: number, options: { freshness?: number; after?: Bookmark; } = {}, ): QuerySignal { const normalizedSort = applyDefaultSort(resource, sort); const freshness = options.freshness ?? 0; return getStore(resource).createBookmark( filter, normalizedSort, offset, freshness, options.after, ); } export function invalidate(timestamp: number): void { for (const store of stores.values()) { store.invalidate(timestamp); } } ================================================ FILE: ui/signals.ts ================================================ // Reactive signals system based on the TC39 Signals proposal. // https://github.com/tc39/proposal-signals export const enum ComputedState { Clean, Computing, Checking, Dirty, } // Creates a Proxy that hides underscore-prefixed properties function createSafeProxy(target: T): T { return new Proxy(target, { get(obj, prop) { if (typeof prop === "string" && prop.startsWith("_")) { return undefined; } const value = Reflect.get(obj, prop, obj); if (typeof value === "function") { return value.bind(obj); } return value; }, set(obj, prop, value) { if (typeof prop === "string" && prop.startsWith("_")) { return false; } return Reflect.set(obj, prop, value, obj); }, ownKeys(obj) { return Reflect.ownKeys(obj).filter( (key) => typeof key !== "string" || !key.startsWith("_"), ); }, getOwnPropertyDescriptor(obj, prop) { if (typeof prop === "string" && prop.startsWith("_")) { return undefined; } return Reflect.getOwnPropertyDescriptor(obj, prop); }, }); } // Tracks the currently computing signal for automatic dependency registration let computing: ComputedSignal | null = null; export function registerDependency(source: SignalBase): void { if (computing !== null) { source._sinks.add(computing._selfRef); computing._sources.add(source); } } function registerCleanup(cleanup: () => void): void { if (computing !== null) { computing._cleanups.add(cleanup); } } function runCleanups(signal: ComputedSignal): void { for (const cleanup of signal._cleanups) { cleanup(); } signal._cleanups.clear(); } // Type for sinks: can be ComputedSignal or Watcher. type Sink = ComputedSignal | Watcher; function markSinksChecking(sinks: Set>): void { for (const weakRef of sinks) { const sink = weakRef.deref(); if (sink === undefined) { sinks.delete(weakRef); continue; } // eslint-disable-next-line @typescript-eslint/no-use-before-define if (sink instanceof Watcher) { sink._notify(); continue; } // Only promote Clean to Checking (Dirty/Checking stay as-is) if (sink._state === ComputedState.Clean) { sink._state = ComputedState.Checking; markSinksChecking(sink._sinks); } } } function markSinksDirty(sinks: Set>): void { for (const weakRef of sinks) { const sink = weakRef.deref(); if (sink === undefined) { sinks.delete(weakRef); continue; } // eslint-disable-next-line @typescript-eslint/no-use-before-define if (sink instanceof Watcher) { sink._notify(); continue; } // Promote Clean or Checking to Dirty if ( sink._state === ComputedState.Clean || sink._state === ComputedState.Checking ) { runCleanups(sink); sink._state = ComputedState.Dirty; markSinksChecking(sink._sinks); // Indirect dependents become Checking } } } export abstract class SignalBase implements Disposable { declare _sinks: Set>; _disposed: boolean = false; abstract get(): T; abstract [Symbol.dispose](): void; } export class ConstSignal extends SignalBase { private _value: T; constructor(value: T) { super(); this._value = value; // Register disposal if created inside a computation if (computing !== null) { registerCleanup(() => this[Symbol.dispose]()); } } get(): T { if (this._disposed) throw new Error("Cannot read disposed signal"); return this._value; } [Symbol.dispose](): void { if (this._disposed) return; this._disposed = true; this._value = undefined as T; } } export class StateSignal extends SignalBase { private _value: T; constructor(initialValue: T) { super(); this._sinks = new Set(); this._value = initialValue; // Register disposal if created inside a computation if (computing !== null) { registerCleanup(() => this[Symbol.dispose]()); } } get(): T { if (this._disposed) throw new Error("Cannot read disposed signal"); registerDependency(this); return this._value; } set(newValue: T): void { if (this._disposed) throw new Error("Cannot write to disposed signal"); if (Object.is(this._value, newValue)) return; this._value = newValue; markSinksDirty(this._sinks); } [Symbol.dispose](): void { if (this._disposed) return; this._disposed = true; this._value = undefined as T; this._sinks.clear(); } } export class ComputedSignal extends SignalBase { private _callback: () => T; private _value: T | undefined; private _error: unknown; private _hasError: boolean = false; _state: ComputedState = ComputedState.Dirty; _sources: Set> = new Set(); _cleanups: Set<() => void> = new Set(); // Single WeakRef reused when registering with sources for memory efficiency readonly _selfRef: WeakRef>; constructor(callback: () => T) { super(); this._sinks = new Set(); this._callback = callback; this._selfRef = new WeakRef(this as ComputedSignal); // Register disposal if created inside a computation if (computing !== null) { registerCleanup(() => this[Symbol.dispose]()); } } get(): T { if (this._disposed) throw new Error("Cannot read disposed signal"); registerDependency(this); if (this._state === ComputedState.Computing) { throw new Error("Circular dependency detected"); } if (!this._isValid()) return this._recompute(); if (this._hasError) throw this._error; return this._value as T; } _isValid(): boolean { if (this._state === ComputedState.Clean) return true; if (this._state !== ComputedState.Checking) return false; // Checking: verify if sources have changed for (const source of this._sources) { if (source instanceof ComputedSignal) { source.get(); // Triggers recomputation if source is Dirty/Checking // If source's value changed, it would have marked us Dirty if ((this._state as ComputedState) === ComputedState.Dirty) return false; } } // All sources unchanged, we're clean this._state = ComputedState.Clean; return true; } private _recompute(): T { // Clear old dependencies for (const source of this._sources) { source._sinks.delete(this._selfRef); } this._sources.clear(); const prevComputing = computing; computing = this as ComputedSignal; this._state = ComputedState.Computing; try { const oldValue = this._value; const hadError = this._hasError; this._value = this._callback(); this._hasError = false; this._state = ComputedState.Clean; // If value changed, mark sinks dirty (for Checking optimization) if (hadError || !Object.is(oldValue, this._value)) { markSinksDirty(this._sinks); } return this._value; } catch (e) { const oldError = this._error; const hadError = this._hasError; this._error = e; this._hasError = true; this._state = ComputedState.Clean; // If error changed, mark sinks dirty if (!hadError || !Object.is(oldError, e)) { markSinksDirty(this._sinks); } throw e; } finally { computing = prevComputing; } } [Symbol.dispose](): void { if (this._disposed) return; this._disposed = true; // Run all registered cleanups (clears timeouts/intervals and disposes // nested signals) runCleanups(this as ComputedSignal); // Detach from sources for (const source of this._sources) { source._sinks?.delete(this._selfRef); } this._sources.clear(); // Clear sinks this._sinks.clear(); // Release references for GC this._value = undefined; this._error = undefined; } } // Observes signal changes from outside the reactive graph. // Based on the TC39 Signals proposal's Signal.subtle.Watcher. // The notify callback fires synchronously and should be lightweight // (e.g., just schedule a redraw). export class Watcher implements Disposable { private _callback: () => void; private _notified: boolean = false; private _disposed: boolean = false; private _watching: Set> = new Set(); readonly _selfRef: WeakRef; constructor(notify: () => void) { this._callback = notify; this._selfRef = new WeakRef(this); } // Also resets the notified flag, allowing the callback to fire again. watch(...signals: SignalBase[]): void { for (const signal of signals) { if (!signal._sinks) continue; // ConstSignal has no sinks signal._sinks.add(this._selfRef); this._watching.add(signal); } this._notified = false; } unwatch(...signals: SignalBase[]): void { for (const signal of signals) { if (!signal._sinks) continue; signal._sinks.delete(this._selfRef); this._watching.delete(signal); } } // Only ComputedSignals can be dirty/checking; StateSignals are always current. getPending(): SignalBase[] { const pending: SignalBase[] = []; for (const signal of this._watching) { if (signal instanceof ComputedSignal) { if (signal._state !== ComputedState.Clean) { pending.push(signal); } } } return pending; } _notify(): void { if (this._disposed || this._notified) return; this._notified = true; this._callback(); } [Symbol.dispose](): void { if (this._disposed) return; this._disposed = true; for (const signal of this._watching) { signal._sinks?.delete(this._selfRef); } this._watching.clear(); } } // Safe signal wrappers that hide internal properties via Proxy. // Exposed to user scripts as Signal.State, Signal.Computed, and Signal.Const. class SafeConstSignal extends ConstSignal { static [Symbol.hasInstance](instance: unknown): boolean { return instance instanceof ConstSignal; } constructor(value: T) { super(value); return createSafeProxy(this); } } class SafeStateSignal extends StateSignal { static [Symbol.hasInstance](instance: unknown): boolean { return instance instanceof StateSignal; } constructor(initialValue: T) { super(initialValue); return createSafeProxy(this); } } class SafeComputedSignal extends ComputedSignal { static [Symbol.hasInstance](instance: unknown): boolean { return instance instanceof ComputedSignal; } constructor(callback: () => T) { super(callback); return createSafeProxy(this); } } export const Signal = { Const: SafeConstSignal, State: SafeStateSignal, Computed: SafeComputedSignal, [Symbol.hasInstance](instance: unknown): boolean { return instance instanceof SignalBase; }, }; // setTimeout wrapper that skips the callback if the enclosing computed // signal is no longer valid when the timeout fires. Outside a computed // signal, behaves exactly like globalThis.setTimeout. export function setTimeout( callback: (...callbackArgs: TArgs) => void, delay?: number, ...args: TArgs ): ReturnType { const signal = computing; if (signal === null) { return globalThis.setTimeout(callback, delay, ...args); } const timeoutId = globalThis.setTimeout( (...callbackArgs: TArgs) => { if (signal._isValid()) { callback(...callbackArgs); } }, delay, ...args, ); registerCleanup(() => globalThis.clearTimeout(timeoutId)); return timeoutId; } // setInterval wrapper that clears the interval when the enclosing computed // signal becomes dirty or is recomputed. Outside a computed signal, behaves // exactly like globalThis.setInterval. export function setInterval( callback: (...callbackArgs: TArgs) => void, delay?: number, ...args: TArgs ): ReturnType { const signal = computing; if (signal === null) { return globalThis.setInterval(callback, delay, ...args); } const intervalId = globalThis.setInterval( (...callbackArgs: TArgs) => { if (signal._isValid()) { callback(...callbackArgs); } else { globalThis.clearInterval(intervalId); } }, delay, ...args, ); registerCleanup(() => globalThis.clearInterval(intervalId)); return intervalId; } ================================================ FILE: ui/skewed-date.ts ================================================ export function getClockSkew(): number { return window.clockSkew; } export class SkewedDate extends Date { constructor(...args: unknown[]) { if (args.length === 0) { super(Date.now() + getClockSkew()); } else { super(...(args as [any])); } } static override now(): number { return Date.now() + getClockSkew(); } } ================================================ FILE: ui/smart-query.ts ================================================ import { filters } from "./config.ts"; import Expression from "../lib/common/expression.ts"; import { encodeTag } from "../lib/util.ts"; import Path from "../lib/common/path.ts"; const resources = { devices: {}, faults: { Device: { parameter: new Expression.Parameter(Path.parse("device")), type: "string", }, Channel: { parameter: new Expression.Parameter(Path.parse("channel")), type: "string", }, Code: { parameter: new Expression.Parameter(Path.parse("code")), type: "string", }, Retries: { parameter: new Expression.Parameter(Path.parse("retries")), type: "number", }, Timestamp: { parameter: new Expression.Parameter(Path.parse("timestamp")), type: "timestamp", }, }, presets: { ID: { parameter: new Expression.Parameter(Path.parse("_id")), type: "string", }, Channel: { parameter: new Expression.Parameter(Path.parse("channel")), type: "string", }, Weight: { parameter: new Expression.Parameter(Path.parse("weight")), type: "number", }, }, provisions: { ID: { parameter: new Expression.Parameter(Path.parse("_id")), type: "string", }, }, virtualParameters: { ID: { parameter: new Expression.Parameter(Path.parse("_id")), type: "string", }, }, files: { ID: { parameter: new Expression.Parameter(Path.parse("_id")), type: "string", }, Type: { parameter: new Expression.Parameter(Path.parse("metadata.fileType")), type: "string", }, OUI: { parameter: new Expression.Parameter(Path.parse("metadata.oui")), type: "string", }, "Product class": { parameter: new Expression.Parameter(Path.parse("metadata.productClass")), type: "string", }, Version: { parameter: new Expression.Parameter(Path.parse("metadata.version")), type: "string", }, }, permissions: { Role: { parameter: new Expression.Parameter(Path.parse("role")), type: "string", }, Resource: { parameter: new Expression.Parameter(Path.parse("resource")), type: "string", }, Access: { parameter: new Expression.Parameter(Path.parse("access")), type: "number", }, }, users: { Username: { parameter: new Expression.Parameter(Path.parse("_id")), type: "string", }, }, views: { ID: { parameter: new Expression.Parameter(Path.parse("_id")), type: "string", }, }, }; for (const v of filters) { resources.devices[v.label] = { parameter: v.parameter, type: (v.type || "").split(",").map((s) => s.trim()), }; } export function getLabels(resource: string): string[] { if (!resources[resource]) return []; return Object.keys(resources[resource]); } function queryNumber(param: Expression, value: string): Expression { let op = "="; for (const o of ["<>", "=", "<=", "<", ">=", ">"]) { if (value.startsWith(o)) { op = o; value = value.slice(o.length).trim(); break; } } const v = parseInt(value); if (v !== +value) return null; return new Expression.Binary(op, param, new Expression.Literal(v)); } function queryTimestamp(param: Expression, value: string): Expression { let op = "="; for (const o of ["<>", "=", "<=", "<", ">=", ">"]) { if (value.startsWith(o)) { op = o; value = value.slice(o.length).trim(); break; } } let v = parseInt(value); if (v !== +value) v = Date.parse(value); if (isNaN(v)) return null; return new Expression.Binary(op, param, new Expression.Literal(v)); } function queryString(param: Expression, value: string): Expression { return new Expression.Binary( "LIKE", new Expression.FunctionCall("LOWER", [param]), new Expression.Literal(value.toLowerCase()), ); } function queryStringCaseSensitive( param: Expression, value: string, ): Expression { return new Expression.Binary("LIKE", param, new Expression.Literal(value)); } function queryStringMonoCase(param: Expression, value: string): Expression { return Expression.or( new Expression.Binary( "LIKE", param, new Expression.Literal(value.toLowerCase()), ), new Expression.Binary( "LIKE", param, new Expression.Literal(value.toUpperCase()), ), ); } function queryMac(param: Expression, value: string): Expression { value = value.replace(/[^a-f0-9]/gi, "").toLowerCase(); if (!value) return null; if (value.length === 12) { value = value.replace(/(..)(?!$)/g, "$1:"); return Expression.or( new Expression.Binary( "=", param, new Expression.Literal(value.toLowerCase()), ), new Expression.Binary( "=", param, new Expression.Literal(value.toUpperCase()), ), ); } param = new Expression.FunctionCall("LOWER", [param]); return Expression.or( new Expression.Binary( "LIKE", param, new Expression.Literal(`%${value.replace(/(..)(?!$)/g, "$1:")}%`), ), new Expression.Binary( "LIKE", param, new Expression.Literal(`%${value.replace(/(.)(.)/g, "$1:$2")}%`), ), ); } function queryMacWildcard(param: Expression, value: string): Expression { if (!/^[a-f0-9%]+$/i.test(value)) return queryStringMonoCase(param, value); const parts = value.split("%"); const groups = parts.map((p) => [ p.replace(/..(?=.)/gi, "$&:"), p.replace(/(.)(.)/gi, "$1:$2"), ]); const set = new Set(); for (let i = 0; i < 2 ** groups.length; ++i) { const r = groups.map((g, j) => g[(i >> j) & 1]).join("%"); if (/^[a-f0-9]:/i.test(r) || /:[a-f0-9]$/i.test(r)) continue; set.add(r.toLocaleLowerCase()); set.add(r.toUpperCase()); } if (!set.size) return queryStringMonoCase(param, value); let res: Expression = new Expression.Literal(false); for (const s of set) { res = Expression.or( res, new Expression.Binary("LIKE", param, new Expression.Literal(s)), ); } return res; } function queryTag(tag: string): Expression { const t = encodeTag(tag); return new Expression.Unary( "IS NOT NULL", new Expression.Parameter(Path.parse(`Tags.${t}`)), ); } export function getTip(resource: string, label: string): string { let tip; if (resources[resource]?.[label]) { const param = resources[resource][label]; const types = resource === "devices" ? param["type"] : param["type"].split(","); const tips = []; for (const type of types) { switch (type.trim()) { case "string": tips.push("case insensitive string pattern"); break; case "string-casesensitive": tips.push("case sensitive string pattern"); break; case "string-monocase": tips.push("case insensitive string pattern"); break; case "number": tips.push("numeric value"); break; case "timestamp": tips.push( "Unix timestamp or string in the form YYYY-MM-DDTHH:mm:ss.sssZ", ); break; case "mac": tips.push("partial case insensitive MAC address"); break; case "mac-wildcard": tips.push("case insensitive MAC address"); break; case "tag": tips.push("case sensitive string"); break; } } if (tips.length) tip = `${label}: ${tips.join(", ")}`; } return tip; } export function unpack( resource: string, label: string, value: string, ): Expression { if (!resources[resource]) return null; const type = resources[resource][label].type; value = value.trim(); let res: Expression = new Expression.Literal(false); if (type.length === 0 || type.includes("number")) { const q = queryNumber(resources[resource][label].parameter, value); if (q) res = Expression.or(res, q); } if (type.length === 0 || type.includes("string")) { const q = queryString(resources[resource][label].parameter, value); if (q) res = Expression.or(res, q); } if (type.length === 0 || type.includes("timestamp")) { const q = queryTimestamp(resources[resource][label].parameter, value); if (q) res = Expression.or(res, q); } if (type.includes("string-casesensitive")) { const q = queryStringCaseSensitive( resources[resource][label].parameter, value, ); if (q) res = Expression.or(res, q); } if (type.includes("string-monocase")) { const q = queryStringMonoCase(resources[resource][label].parameter, value); if (q) res = Expression.or(res, q); } if (type.includes("mac")) { const q = queryMac(resources[resource][label].parameter, value); if (q) res = Expression.or(res, q); } if (type.includes("mac-wildcard")) { const q = queryMacWildcard(resources[resource][label].parameter, value); if (q) res = Expression.or(res, q); } if (type.includes("tag")) { const q = queryTag(value); if (q) res = Expression.or(res, q); } return res; } ================================================ FILE: ui/store.ts ================================================ import m from "mithril"; import Expression from "../lib/common/expression.ts"; import Path from "../lib/common/path.ts"; import memoize from "../lib/common/memoize.ts"; import { Task } from "../lib/types.ts"; import * as notifications from "./notifications.ts"; import { configSnapshot, genieacsVersion } from "./config.ts"; import { QueueTask } from "./task-queue.ts"; import { PingResult } from "../lib/ping.ts"; import { unionDiff } from "../lib/common/expression/synth.ts"; import { bookmarkToExpression, paginate, toBookmark, } from "../lib/common/expression/pagination.ts"; import { getClockSkew } from "./skewed-date.ts"; function evaluate(exp: Expression, timestamp: number): Expression; function evaluate( exp: Expression, timestamp: number, obj: Record, ): Expression.Literal; function evaluate( exp: Expression, timestamp: number, obj?: Record, ): Expression { return exp.evaluate((e) => { if (e instanceof Expression.Literal) return e; else if (e instanceof Expression.FunctionCall) { if (e.name === "NOW") return new Expression.Literal(timestamp); } else if (e instanceof Expression.Parameter && obj) { let v = obj[e.path.toString()]; if (v == null) return new Expression.Literal(null); if (typeof v === "object") v = v["value"]?.[0]; return new Expression.Literal(v as any); } return e; }); } const memoizedEvaluate = memoize(evaluate); let fulfillTimestamp = 0; let connectionNotification, configNotification, versionNotification, skewNotification; const queries = { filter: new WeakMap(), bookmark: new WeakMap(), limit: new WeakMap(), sort: new WeakMap(), fulfilled: new WeakMap(), fulfilling: new WeakSet(), accessed: new WeakMap(), value: new WeakMap(), unsatisfied: new WeakMap(), }; interface Resources { [resource: string]: { objects: Map; count: Map; fetch: Map; combinedFilter: Expression; }; } const resources: Resources = {}; for (const r of [ "devices", "faults", "presets", "provisions", "virtualParameters", "files", "config", "users", "permissions", "views", ]) { resources[r] = { objects: new Map(), count: new Map(), fetch: new Map(), combinedFilter: new Expression.Literal(false) as Expression, }; } export class QueryResponse { public get fulfilled(): number { queries.accessed.set(this, Date.now()); return queries.fulfilled.get(this) || 0; } public get fulfilling(): boolean { queries.accessed.set(this, Date.now()); return !(queries.fulfilled.get(this) >= fulfillTimestamp); } public get value(): any { queries.accessed.set(this, Date.now()); return queries.value.get(this); } } function checkConnection(): void { m.request({ url: "health", method: "GET", background: true, extract: (xhr) => { if (xhr.status !== 200) { if (!connectionNotification) { connectionNotification = notifications.push( "warning", "Server is unreachable", {}, ); } return; } if (connectionNotification) { notifications.dismiss(connectionNotification); connectionNotification = null; } const body = JSON.parse(xhr.responseText); const skew = body.timestamp - Date.now(); const skewDrifted = Math.abs(skew - getClockSkew()) > 5000; if (!skewNotification !== !skewDrifted) { if (skewNotification) { notifications.dismiss(skewNotification); skewNotification = null; } else { skewNotification = notifications.push( "warning", "Clock drift detected, please reload the page", { Reload: () => { window.location.reload(); }, }, ); } } const configChanged = body.configSnapshot !== configSnapshot; const versionChanged = body.version !== genieacsVersion; if (!configNotification !== !configChanged) { if (configNotification) { notifications.dismiss(configNotification); configNotification = null; } else { configNotification = notifications.push( "warning", "Configuration has been modified, please reload the page", { Reload: () => { window.location.reload(); }, }, ); } } if (!versionNotification !== !versionChanged) { if (versionNotification) { notifications.dismiss(versionNotification); versionNotification = null; } else { versionNotification = notifications.push( "warning", "Server has been updated, please reload the page", { Reload: () => { window.location.reload(); }, }, ); } } }, }).catch((err) => { notifications.push("error", err.message); }); } setInterval(checkConnection, 3000); export async function xhrRequest( options: { url: string } & m.RequestOptions, ): Promise { const extract = options.extract; const deserialize = options.deserialize; options.extract = ( xhr: XMLHttpRequest, _options?: { url: string } & m.RequestOptions, ): any => { if (typeof extract === "function") return extract(xhr, _options); // https://mithril.js.org/request.html#error-handling if (xhr.status !== 304 && Math.floor(xhr.status / 100) !== 2) { if (xhr.status === 403) throw new Error("Not authorized"); const err = new Error(); err["message"] = xhr.status === 0 ? "Server is unreachable" : `Unexpected response status code ${xhr.status}`; err["code"] = xhr.status; err["response"] = xhr.responseText; throw err; } let response: any; if (typeof deserialize === "function") { response = deserialize(xhr.responseText); } else if ( (xhr.getResponseHeader("content-type") || "").startsWith( "application/json", ) ) { try { response = xhr.responseText ? JSON.parse(xhr.responseText) : null; } catch (err) { throw new Error("Invalid JSON: " + xhr.responseText.slice(0, 80), { cause: err, }); } } else { response = xhr.responseText; } return response; }; return m.request(options); } export function unpackExpression(exp: Expression): Expression { return memoizedEvaluate(exp, fulfillTimestamp + getClockSkew()); } export function count(resourceType: string, filter: Expression): QueryResponse { const filterStr = filter.toString(); let queryResponse = resources[resourceType].count.get(filterStr); if (queryResponse) return queryResponse; queryResponse = new QueryResponse(); resources[resourceType].count.set(filterStr, queryResponse); queries.filter.set(queryResponse, filter); return queryResponse; } function compareFunction(sort: { [param: string]: number; }): (a: any, b: any) => number { return (a, b) => { for (const [param, asc] of Object.entries(sort)) { let v1 = a[param]; let v2 = b[param]; if (v1 != null && typeof v1 === "object") { if (v1.value) v1 = v1.value[0]; else v1 = null; } if (v2 != null && typeof v2 === "object") { if (v2.value) v2 = v2.value[0]; else v2 = null; } if (v1 > v2) { return asc; } else if (v1 < v2) { return asc * -1; } else if (v1 !== v2) { const w = { null: 1, number: 2, string: 3, }; const w1 = w[v1 == null ? "null" : typeof v1] || 4; const w2 = w[v2 == null ? "null" : typeof v2] || 4; return Math.max(-1, Math.min(1, w1 - w2)) * asc; } } return 0; }; } function findMatches(resourceType, filter, sort, limit): any[] { let value = []; for (const obj of resources[resourceType].objects.values()) if (evaluate(filter, fulfillTimestamp + getClockSkew(), obj).value) value.push(obj); value = value.sort(compareFunction(sort)); if (limit) value = value.slice(0, limit); return value; } export function fetch( resourceType: string, filter: Expression, options: { limit?: number; sort?: { [param: string]: number } } = {}, ): QueryResponse { const sort = Object.assign({}, options.sort); const limit = options.limit || 0; if (resourceType === "devices") sort["DeviceID.ID"] = sort["DeviceID.ID"] || 1; else sort["_id"] = sort["_id"] || 1; const key = `${filter.toString()}:${limit}:${JSON.stringify(sort)}`; let queryResponse = resources[resourceType].fetch.get(key); if (queryResponse) return queryResponse; queryResponse = new QueryResponse(); resources[resourceType].fetch.set(key, queryResponse); queries.filter.set(queryResponse, filter); queries.limit.set(queryResponse, limit); queries.sort.set(queryResponse, sort); const [satisfied, diff] = paginate( resources[resourceType].combinedFilter, unpackExpression(filter), sort, ); const matches = findMatches(resourceType, satisfied, sort, limit); queries.value.set(queryResponse, matches); if ( (diff instanceof Expression.Literal && !diff.value) || (limit && matches.length >= limit) ) queries.fulfilled.set(queryResponse, fulfillTimestamp); else queries.unsatisfied.set(queryResponse, diff); return queryResponse; } export function fulfill(accessTimestamp: number): void { const allPromises = []; for (const [resourceType, resource] of Object.entries(resources)) { for (const [queryResponseKey, queryResponse] of resource.count) { if (!(queries.accessed.get(queryResponse) >= accessTimestamp)) { resource.count.delete(queryResponseKey); continue; } if (queries.fulfilling.has(queryResponse)) continue; if (!(fulfillTimestamp <= queries.fulfilled.get(queryResponse))) { queries.fulfilling.add(queryResponse); let filter = queries.filter.get(queryResponse); filter = unpackExpression(filter); allPromises.push( xhrRequest({ method: "HEAD", url: `api/${resourceType}/?` + m.buildQueryString({ filter: filter.toString(), }), extract: (xhr) => { if (xhr.status === 403) throw new Error("Not authorized"); if (!xhr.status) { throw new Error("Server is unreachable"); } else if (xhr.status !== 200) { throw new Error( `Unexpected response status code ${xhr.status}`, ); } return +xhr.getResponseHeader("x-total-count"); }, background: false, }).then((c) => { queries.value.set(queryResponse, c); queries.fulfilled.set(queryResponse, fulfillTimestamp); queries.fulfilling.delete(queryResponse); }), ); } } } const toFetchAll: { [resourceType: string]: QueryResponse[] } = {}; for (const [resourceType, resource] of Object.entries(resources)) { for (const [queryResponseKey, queryResponse] of resource.fetch) { if (!(queries.accessed.get(queryResponse) >= accessTimestamp)) { resource.fetch.delete(queryResponseKey); continue; } if (queries.fulfilling.has(queryResponse)) continue; if (!(fulfillTimestamp <= queries.fulfilled.get(queryResponse))) { queries.fulfilling.add(queryResponse); toFetchAll[resourceType] = toFetchAll[resourceType] || []; toFetchAll[resourceType].push(queryResponse); let limit = queries.limit.get(queryResponse); const sort = queries.sort.get(queryResponse); if (limit) { let filter = queries.filter.get(queryResponse); filter = unpackExpression(filter); const unsatisfied = queries.unsatisfied.get(queryResponse); if (unsatisfied) { limit -= queries.value.get(queryResponse).length; filter = unsatisfied; } allPromises.push( xhrRequest({ method: "GET", url: `api/${resourceType}/?` + m.buildQueryString({ filter: filter.toString(), limit: 1, skip: limit - 1, sort: JSON.stringify(sort), projection: Object.keys(sort).join(","), }), background: true, }).then((res) => { queries.unsatisfied.delete(queryResponse); if ((res as any[]).length) { queries.bookmark.set(queryResponse, toBookmark(sort, res[0])); } else { queries.bookmark.delete(queryResponse); } }), ); } } } } Promise.all(allPromises) .then(() => { let updated = false; const allPromises2 = []; for (const [resourceType, toFetch] of Object.entries(toFetchAll)) { let combinedFilter = new Expression.Literal(false) as Expression; for (const queryResponse of toFetch) { let filter = queries.filter.get(queryResponse); filter = memoizedEvaluate(filter, fulfillTimestamp + getClockSkew()); const bookmark = queries.bookmark.get(queryResponse); const sort = queries.sort.get(queryResponse); if (bookmark) filter = Expression.and( filter, bookmarkToExpression(bookmark, sort), ); combinedFilter = Expression.or(combinedFilter, filter); } const [union, diff] = unionDiff( resources[resourceType].combinedFilter, combinedFilter, ); if (diff instanceof Expression.Literal && !diff.value) { for (const queryResponse of toFetch) { let filter = queries.filter.get(queryResponse); filter = memoizedEvaluate( filter, fulfillTimestamp + getClockSkew(), ); const limit = queries.limit.get(queryResponse); const bookmark = queries.bookmark.get(queryResponse); const sort = queries.sort.get(queryResponse); if (bookmark) filter = Expression.and( filter, bookmarkToExpression(bookmark, sort), ); queries.value.set( queryResponse, findMatches(resourceType, filter, sort, limit), ); queries.fulfilled.set(queryResponse, fulfillTimestamp); queries.fulfilling.delete(queryResponse); updated = true; } continue; } let deleted = new Set(); const cf = resources[resourceType].combinedFilter; if (cf instanceof Expression.Literal && !cf.value) deleted = new Set(resources[resourceType].objects.keys()); const combinedFilterDiff = diff; resources[resourceType].combinedFilter = union; allPromises2.push( xhrRequest({ method: "GET", url: `api/${resourceType}/?` + m.buildQueryString({ filter: combinedFilterDiff.toString(), }), background: false, }).then((res) => { for (const r of res as any[]) { const id = r["DeviceID.ID"] ?? r["_id"]; resources[resourceType].objects.set(id, r); deleted.delete(id); } for (const d of deleted) { const obj = resources[resourceType].objects.get(d); if ( evaluate( combinedFilterDiff, fulfillTimestamp + getClockSkew(), obj, ).value ) resources[resourceType].objects.delete(d); } for (const queryResponse of toFetch) { let filter = queries.filter.get(queryResponse); filter = unpackExpression(filter); const limit = queries.limit.get(queryResponse); const bookmark = queries.bookmark.get(queryResponse); const sort = queries.sort.get(queryResponse); if (bookmark) filter = Expression.and( filter, bookmarkToExpression(bookmark, sort), ); queries.value.set( queryResponse, findMatches(resourceType, filter, sort, limit), ); queries.fulfilled.set(queryResponse, fulfillTimestamp); queries.fulfilling.delete(queryResponse); } }), ); } if (updated) m.redraw(); return Promise.all(allPromises2); }) .catch((err) => { notifications.push("error", err.message); }); } export function getTimestamp(): number { return fulfillTimestamp; } export function setTimestamp(t: number): void { if (t > fulfillTimestamp) { fulfillTimestamp = t; for (const resource of Object.values(resources)) resource.combinedFilter = new Expression.Literal(false); } } export function postTasks( deviceId: string, tasks: QueueTask[], ): Promise { const tasks2: Task[] = []; for (const t of tasks) { t.status = "pending"; const t2 = Object.assign({}, t); delete t2.device; delete t2.status; tasks2.push(t2); } return xhrRequest({ method: "POST", url: `api/devices/${encodeURIComponent(deviceId)}/tasks`, body: tasks2, extract: (xhr) => { if (xhr.status === 403) throw new Error("Not authorized"); if (!xhr.status) throw new Error("Server is unreachable"); if (xhr.status !== 200) throw new Error(xhr.response); const connectionRequestStatus = xhr.getResponseHeader("Connection-Request"); const st = JSON.parse(xhr.response); for (const [i, t] of st.entries()) { tasks[i]._id = t._id; tasks[i].status = t.status; } return connectionRequestStatus; }, }); } export function updateTags( deviceId: string, tags: Record, ): Promise { return xhrRequest({ method: "POST", url: `api/devices/${encodeURIComponent(deviceId)}/tags`, body: tags, }); } export function deleteResource( resourceType: string, id: string, ): Promise { return xhrRequest({ method: "DELETE", url: `api/${resourceType}/${encodeURIComponent(id)}`, }); } export function putResource( resourceType: string, id: string, object: Record, ): Promise { for (const k in object) if (object[k] === undefined) object[k] = null; return xhrRequest({ method: "PUT", url: `api/${resourceType}/${encodeURIComponent(id)}`, body: object, }); } export function queryConfig(pattern = "%"): Promise { const filter = new Expression.Binary( "LIKE", new Expression.Parameter(Path.parse("_id")), new Expression.Literal(pattern), ); return xhrRequest({ method: "GET", url: `api/config/?${m.buildQueryString({ filter: filter.toString() })}`, background: true, }); } export function resourceExists(resource: string, id: string): Promise { const param = resource === "devices" ? "DeviceID.ID" : "_id"; const filter = new Expression.Binary( "=", new Expression.Parameter(Path.parse(param)), new Expression.Literal(id), ); return xhrRequest({ method: "HEAD", url: `api/${resource}/?` + m.buildQueryString({ filter: filter.toString(), }), extract: (xhr) => { if (xhr.status === 403) throw new Error("Not authorized"); if (!xhr.status) throw new Error("Server is unreachable"); else if (xhr.status !== 200) throw new Error(`Unexpected response status code ${xhr.status}`); return +xhr.getResponseHeader("x-total-count"); }, background: true, }); } export function evaluateExpression(exp: Expression): Expression; export function evaluateExpression( exp: Expression, obj: Record, ): Expression.Literal; export function evaluateExpression( exp: Expression, obj?: Record, ): Expression { return memoizedEvaluate(exp, fulfillTimestamp + getClockSkew(), obj); } export function changePassword( username: string, newPassword: string, authPassword?: string, ): Promise { const body = { newPassword }; if (authPassword) body["authPassword"] = authPassword; return xhrRequest({ method: "PUT", url: `api/users/${username}/password`, background: true, body, }); } export function logIn( username: string, password: string, remember = false, ): Promise { return xhrRequest({ method: "POST", url: "login", background: true, body: { username, password, remember }, }); } export function logOut(): Promise { return xhrRequest({ method: "POST", url: "logout", }); } export function ping(host: string): Promise { return xhrRequest({ url: `api/ping/${encodeURIComponent(host)}`, background: true, }); } ================================================ FILE: ui/tailwind-utility-components.ts ================================================ import m, { ChildArrayOrPrimitive, ClosureComponent, mount, Vnode, VnodeDOM, } from "mithril"; import { ICONS_SVG } from "../build/assets.ts"; export const portal: ClosureComponent = () => { let rootElement: HTMLElement; let children: ChildArrayOrPrimitive; return { oncreate: (vnode) => { children = vnode.children; rootElement = document.createElement("div"); document.body.appendChild(rootElement); mount(rootElement, { view: () => children }); }, onupdate: (vnode) => { children = vnode.children; }, onremove: () => { if (document.body.contains(rootElement)) { mount(rootElement, null); document.body.removeChild(rootElement); } }, view: () => { return null; }, }; }; interface DialogAttrs { onClose?: () => void; as: string; class?: string; } export const dialog: ClosureComponent = () => { return { view(vnode) { return m( portal, m( vnode.attrs.as, { class: vnode.attrs.class, role: "dialog", "aria-modal": "true" }, vnode.children, ), ); }, }; }; interface DialogOverlayAttrs { class?: string; } export const dialogOverlay: ClosureComponent = () => { return { view(vnode) { return m( "div", { class: vnode.attrs.class, "aria-hidden": "true" }, vnode.children, ); }, }; }; let transitionShow = false; let transitionTimeout = 0; interface TransitionRootAttrs { show: boolean; duration: number; } export const transitionRoot: ClosureComponent = ( initialVnode, ) => { let show = initialVnode.attrs.show; let transitionTimestamp = 0; let timeout: ReturnType; return { view(vnode: Vnode) { if (show !== vnode.attrs.show) { const now = Date.now(); transitionTimestamp = now; show = vnode.attrs.show; clearTimeout(timeout); timeout = setTimeout(() => m.redraw(), vnode.attrs.duration); } transitionShow = show; transitionTimeout = Math.max( 0, vnode.attrs.duration - (Date.now() - transitionTimestamp), ); if (!transitionShow && !transitionTimeout) return null; return vnode.children; }, }; }; interface TransitionChildAttrs { enter: string; enterFrom: string; enterTo: string; leave: string; leaveFrom: string; leaveTo: string; } export const transitionChild: ClosureComponent = () => { let show: boolean; let timeout: number; let firstFrame: boolean; function updateCssClasses(vnode: VnodeDOM): void { const dom = vnode.dom as HTMLElement; const enter = vnode.attrs.enter.split(" "); const enterFrom = vnode.attrs.enterFrom.split(" "); const enterTo = vnode.attrs.enterTo.split(" "); const leave = vnode.attrs.leave.split(" "); const leaveFrom = vnode.attrs.leaveFrom.split(" "); const leaveTo = vnode.attrs.leaveTo.split(" "); if (show) { dom.classList.remove(...leave, ...leaveFrom, ...leaveTo); if (firstFrame) { dom.classList.add(...enterFrom); void dom.getBoundingClientRect(); dom.classList.remove(...enterFrom); } if (timeout) dom.classList.add(...enter); else dom.classList.remove(...enter); dom.classList.add(...enterTo); } else { dom.classList.remove(...enter, ...enterFrom, ...enterTo); if (firstFrame) { dom.classList.add(...leaveFrom); void dom.getBoundingClientRect(); dom.classList.remove(...leaveFrom); } if (timeout) dom.classList.add(...leave); else dom.classList.remove(...leave); dom.classList.add(...leaveTo); } } return { view(vnode: Vnode) { firstFrame = show !== transitionShow; show = transitionShow; timeout = transitionTimeout; return vnode.children; }, oncreate(vnode: VnodeDOM) { updateCssClasses(vnode); }, onupdate(vnode: VnodeDOM) { updateCssClasses(vnode); }, }; }; interface IconAttrs { name: string; class?: string; } export const icon: ClosureComponent = () => { return { view(vnode) { return m( `svg`, { xmlns: "http://www.w3.org/2000/svg", fill: "none", stroke: "currentColor", "stroke-width": "2", class: vnode.attrs.class, "aria-hidden": "true", }, m("use", { href: `${ICONS_SVG}#icon-${vnode.attrs.name}` }), ); }, }; }; ================================================ FILE: ui/task-queue.ts ================================================ import m from "mithril"; import * as store from "./store.ts"; import { Task } from "../lib/types.ts"; import * as notifications from "./notifications.ts"; export interface QueueTask extends Task { status?: string; device: string; } export interface StageTask extends Task { devices: string[]; } const MAX_QUEUE = 100; const queue: Set = new Set(); const staging: Set = new Set(); function canQueue(tasks: QueueTask[]): boolean { let count = queue.size; for (const task of tasks) if (!queue.has(task)) ++count; return count <= MAX_QUEUE; } export function queueTask(...tasks: QueueTask[]): void { if (!canQueue(tasks)) { notifications.push("error", "Too many tasks in queue"); return; } for (const task of tasks) { task.status = "queued"; queue.add(task); } m.redraw(); } export function deleteTask(task: QueueTask): void { queue.delete(task); } export function getQueue(): Set { return queue; } export function clear(): void { queue.clear(); } export function getStaging(): Set { return staging; } export function clearStaging(): void { staging.clear(); } export function stageSpv(task: StageTask): void { if (queue.size + task.devices.length > MAX_QUEUE) { notifications.push("error", "Too many tasks in queue"); return; } staging.add(task); m.redraw(); } export function stageDownload(task: StageTask): void { if (queue.size + task.devices.length > MAX_QUEUE) { notifications.push("error", "Too many tasks in queue"); return; } staging.add(task); m.redraw(); } export function commit( tasks: QueueTask[], callback: ( deviceId: string, err: Error, conReqStatus: string, _tasks: QueueTask[], ) => void, ): Promise { const devices: { [deviceId: string]: QueueTask[] } = {}; if (!canQueue(tasks)) return Promise.reject(new Error("Too many tasks in queue")); for (const t of tasks) { devices[t.device] = devices[t.device] || []; devices[t.device].push(t); t.status = "queued"; queue.add(t); } return new Promise((resolve) => { let counter = 1; for (const [deviceId, tasks2] of Object.entries(devices)) { ++counter; store .postTasks(deviceId, tasks2) .then((connectionRequestStatus) => { for (const t of tasks2) { if (t.status === "pending") t.status = "stale"; else if (t.status === "done") queue.delete(t); } callback(deviceId, null, connectionRequestStatus, tasks2); if (--counter === 0) resolve(); }) .catch((err) => { for (const t of tasks2) t.status = "stale"; callback(deviceId, err, null, tasks2); if (--counter === 0) resolve(); }); } if (--counter === 0) resolve(); }); } ================================================ FILE: ui/timeago.ts ================================================ const UNITS = { year: 12 * 30 * 24 * 60 * 60 * 1000, month: 30 * 24 * 60 * 60 * 1000, day: 24 * 60 * 60 * 1000, hour: 60 * 60 * 1000, minute: 60 * 1000, second: 1000, }; export default function timeAgo(dtime: number): string { let res = ""; let level = 2; for (const [u, t] of Object.entries(UNITS)) { if (dtime >= t) { let n; if (level > 1) { n = Math.floor(dtime / t); dtime -= n * t; } else { n = Math.round(dtime / t); } if (n > 1) res += `${n} ${u}s `; else res += `${n} ${u} `; if (!--level) break; } } return res + "ago"; } ================================================ FILE: ui/ui-config-component.ts ================================================ import { ClosureComponent } from "mithril"; import { m } from "./components.ts"; import * as store from "./store.ts"; import { yaml } from "./dynamic-loader.ts"; import * as configFunctions from "./config-functions.ts"; import codeEditorComponent from "./code-editor-component.ts"; import Expression from "../lib/common/expression.ts"; function putActionHandler(prefix: string[], dataYaml: string): Promise { return new Promise((resolve, reject) => { try { let updated = yaml.parse(dataYaml, { schema: "failsafe" }); if (updated) { const config = {}; let ref = config; prefix.forEach((seg, index) => { if (index < prefix.length - 1) { ref[seg] = {}; ref = ref[seg]; } else { ref[seg] = updated; } }); updated = configFunctions.flattenConfig(config); } else { updated = {}; } // Try parse to ensure valid expressions for (const v of Object.values(updated)) Expression.parse(v as string); store .queryConfig(`${prefix.join(".")}.%`) .then((res) => { const current = {}; for (const f of res) current[f._id] = f.value; const diff = configFunctions.diffConfig(current, updated); if (!diff.add.length && !diff.remove.length) return void resolve(null); const promises = []; for (const obj of diff.add) { promises.push( store.putResource( "config", obj._id, obj as unknown as Record, ), ); } for (const id of diff.remove) promises.push(store.deleteResource("config", id)); Promise.all(promises) .then(() => { resolve(null); }) .catch(reject); }) .catch(reject); } catch (error) { resolve({ config: error.message }); } }); } interface Attrs { prefix: string; name: string; data: { _id: string; value: string }[]; onUpdate: (errs: Record) => void; onError: (err: Error) => void; } const component: ClosureComponent = () => { return { view: (vnode) => { const prefix = vnode.attrs.prefix.split("."); const name = vnode.attrs.name; const data = vnode.attrs.data; if (prefix[prefix.length - 1] === "") prefix.pop(); let config; if (data.length) { config = configFunctions.structureConfig(data); for (const seg of prefix) config = config[seg]; } const yamlString = config && Object.values(config).length ? yaml.stringify(config, { schema: "failsafe" }) : ""; const attrs = { id: `${name}-ui-config`, value: yamlString, mode: "yaml", focus: true, onSubmit: (dom) => { dom.form.querySelector("button[type=submit]").click(); }, onChange: (value) => { vnode.state["updatedYaml"] = value; vnode.state["modified"] = true; }, }; const code = m(codeEditorComponent, attrs); const submit = m( "button.ml-3 inline-flex justify-center py-2 px-4 border border-transparent shadow-xs text-sm font-medium rounded-md text-white bg-cyan-600 hover:bg-cyan-700 focus:outline-hidden focus:ring-2 focus:ring-offset-2 focus:ring-cyan-500", { type: "submit" }, "Save", ); return m("div", [ m( "h2.mb-5 text-lg leading-6 font-medium text-stone-900", `Editing ${name}`, ), m( "form", { onsubmit: (e) => { e.redraw = false; e.preventDefault(); if (vnode.state["updatedYaml"] == null) vnode.state["updatedYaml"] = yamlString; putActionHandler(prefix, vnode.state["updatedYaml"]) .then(vnode.attrs.onUpdate) .catch(vnode.attrs.onError); }, }, [code, m(".flex justify-end mt-5", [submit])], ), ]); }, }; }; export default component; ================================================ FILE: ui/users-page.ts ================================================ import { Children, ClosureComponent, Component } from "mithril"; import { m } from "./components.ts"; import { pageSize as PAGE_SIZE } from "./config.ts"; import * as store from "./store.ts"; import * as notifications from "./notifications.ts"; import memoize from "../lib/common/memoize.ts"; import putFormComponent from "./put-form-component.ts"; import indexTableComponent from "./index-table-component.ts"; import * as overlay from "./overlay.ts"; import * as smartQuery from "./smart-query.ts"; import Expression from "../lib/common/expression.ts"; import filterComponent from "./filter-component.ts"; import changePasswordComponent from "./change-password-component.ts"; const memoizedJsonParse = memoize(JSON.parse); const attributes = [ { id: "_id", label: "Username" }, { id: "roles", label: "Roles", type: "multi", options: [] }, ]; const unpackSmartQuery = memoize((query: Expression) => { return query.evaluate((e) => { if (e instanceof Expression.FunctionCall) { if (e.name === "Q") { if ( e.args[0] instanceof Expression.Literal && e.args[1] instanceof Expression.Literal ) { return smartQuery.unpack( "users", e.args[0].value as string, e.args[1].value as string, ); } } } return e; }); }); interface ValidationErrors { [prop: string]: string; } function putActionHandler(action, _object, isNew): Promise { return new Promise((resolve, reject) => { const object = Object.assign({}, _object); if (action === "save") { const id = object["_id"]; const password = object["password"]; const confirm = object["confirm"]; delete object["_id"]; delete object["password"]; delete object["confirm"]; if (!id) return void resolve({ _id: "ID can not be empty" }); if (isNew) { if (!password) { return void resolve({ password: "Password can not be empty" }); } else if (password !== confirm) { return void resolve({ confirm: "Confirm password doesn't match password", }); } } if (!Array.isArray(object.roles) || !object.roles.length) return void resolve({ roles: "Role(s) must be selected" }); object.roles = object.roles.join(","); store .resourceExists("users", id) .then((exists) => { if (exists && isNew) { store.setTimestamp(Date.now()); return void resolve({ _id: "User already exists" }); } if (!exists && !isNew) { store.setTimestamp(Date.now()); return void resolve({ _id: "User does not exist" }); } store .putResource("users", id, object) .then(() => { if (isNew) { store .changePassword(id, password) .then(() => { notifications.push("success", "User created"); store.setTimestamp(Date.now()); resolve(null); }) .catch(reject); } else { notifications.push("success", "User updated"); store.setTimestamp(Date.now()); resolve(null); } }) .catch(reject); }) .catch(reject); } else if (action === "delete") { if (!confirm("Deleting user. Are you sure?")) return void resolve(null); store .deleteResource("users", object["_id"]) .then(() => { notifications.push("success", "User deleted"); store.setTimestamp(Date.now()); resolve(null); }) .catch((err) => { store.setTimestamp(Date.now()); reject(err); }); } else { reject(new Error("Undefined action")); } }); } const getDownloadUrl = memoize((filter) => { const cols = {}; for (const attr of attributes) cols[attr.label] = attr.id; return `api/users.csv?${m.buildQueryString({ filter: filter.toString(), columns: JSON.stringify(cols), })}`; }); export function init( args: Record, ): Promise> { if (!window.authorizer.hasAccess("users", 2)) { return Promise.reject( new Error("You are not authorized to view this page"), ); } let filter: Expression = null; let sort: Record = null; if (args.hasOwnProperty("filter")) filter = Expression.parse(args["filter"] as string); if (args.hasOwnProperty("sort")) sort = JSON.parse(args["sort"] as string); return Promise.resolve({ filter, sort }); } export const component: ClosureComponent = (): Component => { return { view: (vnode) => { document.title = "Users - GenieACS"; function showMore(): void { vnode.state["showCount"] = (vnode.state["showCount"] || PAGE_SIZE) + PAGE_SIZE; m.redraw(); } function onFilterChanged(filter): void { const ops = {}; if (!(filter instanceof Expression.Literal && filter.value)) ops["filter"] = filter.toString(); if (vnode.attrs["sort"]) ops["sort"] = vnode.attrs["sort"]; m.route.set("/users", ops); } const sort = vnode.attrs["sort"] ? memoizedJsonParse(vnode.attrs["sort"]) : {}; const sortAttributes = {}; for (let i = 0; i < attributes.length; i++) { const attr = attributes[i]; if (attr.id !== "roles") sortAttributes[i] = sort[attributes[i].id] || 0; } function onSortChange(sortAttrs): void { const _sort = {}; for (const index of sortAttrs) _sort[attributes[Math.abs(index) - 1].id] = Math.sign(index); const ops = { sort: JSON.stringify(_sort) }; if (vnode.attrs["filter"]) ops["filter"] = vnode.attrs["filter"]; m.route.set("/users", ops); } const filter = unpackSmartQuery( vnode.attrs["filter"] ?? new Expression.Literal(true), ); const users = store.fetch("users", filter, { limit: vnode.state["showCount"] || PAGE_SIZE, sort: sort, }); const count = store.count("users", filter); // Getting the roles const permissions = store.fetch( "permissions", new Expression.Literal(true), ); if (permissions.fulfilled) { for (const attr of attributes) { if (attr.id === "roles") attr.options = [...new Set(permissions.value.map((p) => p.role))]; } } const downloadUrl = getDownloadUrl(filter); const canWrite = window.authorizer.hasAccess("users", 3); const attrs = {}; attrs["attributes"] = attributes; attrs["data"] = users.value; attrs["total"] = count.value; attrs["showMoreCallback"] = showMore; attrs["sortAttributes"] = sortAttributes; attrs["onSortChange"] = onSortChange; attrs["downloadUrl"] = downloadUrl; attrs["recordActionsCallback"] = (user) => { return [ m( "button.text-cyan-700 hover:text-cyan-900 font-medium", { onclick: () => { let cb: () => Children = null; const comp = m( putFormComponent, Object.assign( { base: { _id: user._id, roles: user.roles.split(","), }, actionHandler: (action, object) => { return new Promise((resolve) => { putActionHandler(action, object, false) .then((errors) => { const errorList = errors ? Object.values(errors) : []; if (errorList.length) { for (const err of errorList) notifications.push("error", err); } else { overlay.close(cb); } resolve(); }) .catch((err) => { notifications.push("error", err.message); resolve(); }); }); }, }, { resource: "users", attributes: attributes, }, ), ); cb = () => { const children: Children = [comp]; if (canWrite) { children.push(m("hr")); const _attrs = { noAuth: true, username: user._id, onPasswordChange: () => { overlay.close(cb); m.redraw(); }, }; children.push(m(changePasswordComponent, _attrs)); } return children; }; overlay.open( cb, () => !comp.state["current"]["modified"] || confirm("You have unsaved changes. Close anyway?"), ); }, }, "Show", ), ]; }; if (canWrite) { const formData = { resource: "users", attributes: [ attributes[0], { id: "password", label: "Password", type: "password" }, { id: "confirm", label: "Confirm password", type: "password" }, attributes[1], ], }; attrs["actionsCallback"] = (selected: Set): Children => { return [ m( "button.px-4 py-2 border border-stone-300 shadow-xs text-sm font-medium rounded-md text-stone-700 bg-white hover:bg-stone-50 focus:outline-hidden focus:ring-2 focus:ring-offset-2 focus:ring-cyan-500 disabled:opacity-50 disabled:cursor-not-allowed", { title: "Create new user", onclick: () => { let cb: () => Children = null; const comp = m( putFormComponent, Object.assign( { actionHandler: (action, object) => { return new Promise((resolve) => { putActionHandler(action, object, true) .then((errors) => { const errorList = errors ? Object.values(errors) : []; if (errorList.length) { for (const err of errorList) notifications.push("error", err); } else { overlay.close(cb); } resolve(); }) .catch((err) => { notifications.push("error", err.message); resolve(); }); }); }, }, formData, ), ); cb = () => comp; overlay.open( cb, () => !comp.state["current"]["modified"] || confirm("You have unsaved changes. Close anyway?"), ); }, }, "New", ), m( "button.px-4 py-2 border border-stone-300 shadow-xs text-sm font-medium rounded-md text-stone-700 bg-white hover:bg-stone-50 focus:outline-hidden focus:ring-2 focus:ring-offset-2 focus:ring-cyan-500 disabled:opacity-50 disabled:cursor-not-allowed", { title: "Delete selected users", disabled: !selected.size, onclick: (e) => { if ( !confirm(`Deleting ${selected.size} users. Are you sure?`) ) return; e.redraw = false; e.target.disabled = true; Promise.all( Array.from(selected).map((id) => store.deleteResource("users", id), ), ) .then((res) => { notifications.push( "success", `${res.length} users deleted`, ); store.setTimestamp(Date.now()); }) .catch((err) => { notifications.push("error", err.message); store.setTimestamp(Date.now()); }); }, }, "Delete", ), ]; }; } const filterAttrs = { resource: "users", filter: vnode.attrs["filter"], onChange: onFilterChanged, }; return [ m("h1.text-xl font-medium text-stone-900 mb-5", "Listing users"), m(filterComponent, filterAttrs), m( "loading", { queries: [users, count] }, m(indexTableComponent, attrs), ), ]; }, }; }; ================================================ FILE: ui/views-bundle-placeholder.ts ================================================ declare module "views-bundle" { const views: Record unknown>; export default views; } ================================================ FILE: ui/views-page.ts ================================================ import { ClosureComponent, Component, Children } from "mithril"; import { m } from "./components.ts"; import * as config from "./config.ts"; import filterComponent from "./filter-component.ts"; import * as store from "./store.ts"; import * as notifications from "./notifications.ts"; import memoize from "../lib/common/memoize.ts"; import putFormComponent from "./put-form-component.ts"; import indexTableComponent from "./index-table-component.ts"; import * as overlay from "./overlay.ts"; import * as smartQuery from "./smart-query.ts"; import Expression from "../lib/common/expression.ts"; import { loadCodeMirror } from "./dynamic-loader.ts"; const PAGE_SIZE = config.pageSize || 10; const memoizedParse = memoize(Expression.parse); const memoizedJsonParse = memoize(JSON.parse); const attributes = [ { id: "_id", label: "Name" }, { id: "script", label: "Script", type: "code", mode: "jsx" }, ]; const unpackSmartQuery = memoize((query: Expression) => { return query.map((e) => { if ( e instanceof Expression.FunctionCall && e.name === "Q" && e.args.length >= 2 ) { const arg0 = e.args[0] instanceof Expression.Literal ? e.args[0].value : null; const arg1 = e.args[1] instanceof Expression.Literal ? e.args[1].value : null; return smartQuery.unpack("views", arg0 as string, arg1 as string); } return e; }); }); interface ValidationErrors { [prop: string]: string; } function putActionHandler(action, _object, isNew): Promise { return new Promise((resolve, reject) => { const object = Object.assign({}, _object); if (action === "save") { const id = object["_id"]; delete object["_id"]; if (!id) return void resolve({ _id: "ID can not be empty" }); store .resourceExists("views", id) .then((exists) => { if (exists && isNew) { store.setTimestamp(Date.now()); return void resolve({ _id: "View already exists" }); } if (!exists && !isNew) { store.setTimestamp(Date.now()); return void resolve({ _id: "View does not exist" }); } store .putResource("views", id, object) .then(() => { notifications.push( "success", `View ${exists ? "updated" : "created"}`, ); store.setTimestamp(Date.now()); resolve(null); }) .catch((err) => { if (err["code"] === 400 && err["response"]) { reject(new Error(err["response"])); return; } reject(err); }); }) .catch(reject); } else if (action === "delete") { if (!confirm("Deleting view. Are you sure?")) return void resolve(null); store .deleteResource("views", object["_id"]) .then(() => { notifications.push("success", "View deleted"); store.setTimestamp(Date.now()); resolve(null); }) .catch((err) => { store.setTimestamp(Date.now()); reject(err); }); } else { reject(new Error("Undefined action")); } }); } const formData = { resource: "views", attributes: attributes, }; const getDownloadUrl = memoize((filter: Expression) => { const cols = {}; for (const attr of attributes) cols[attr.label] = attr.id; return `api/views.csv?${m.buildQueryString({ filter: filter.toString(), columns: JSON.stringify(cols), })}`; }); export function init( args: Record, ): Promise> { if (!window.authorizer.hasAccess("views", 2)) { return Promise.reject( new Error("You are not authorized to view this page"), ); } const sort = args.hasOwnProperty("sort") ? "" + args["sort"] : ""; const filter = args.hasOwnProperty("filter") ? "" + args["filter"] : ""; return new Promise((resolve, reject) => { loadCodeMirror() .then(() => { resolve({ filter, sort }); }) .catch(reject); }); } export const component: ClosureComponent = (): Component => { return { view: (vnode) => { document.title = "Views - GenieACS"; function showMore(): void { vnode.state["showCount"] = (vnode.state["showCount"] || PAGE_SIZE) + PAGE_SIZE; m.redraw(); } function onFilterChanged(filter): void { const ops = { filter }; if (vnode.attrs["sort"]) ops["sort"] = vnode.attrs["sort"]; m.route.set("/views", ops); } const sort = vnode.attrs["sort"] ? memoizedJsonParse(vnode.attrs["sort"]) : {}; const sortAttributes = {}; for (let i = 0; i < attributes.length; i++) sortAttributes[i] = sort[attributes[i].id] || 0; function onSortChange(sortAttrs): void { const _sort = {}; for (const index of sortAttrs) _sort[attributes[Math.abs(index) - 1].id] = Math.sign(index); const ops = { sort: JSON.stringify(_sort) }; if (vnode.attrs["filter"]) ops["filter"] = vnode.attrs["filter"]; m.route.set("/views", ops); } let filter: Expression = vnode.attrs["filter"] ? memoizedParse(vnode.attrs["filter"]) : new Expression.Literal(true); filter = unpackSmartQuery(filter); const views = store.fetch("views", filter, { limit: vnode.state["showCount"] || PAGE_SIZE, sort: sort, }); const count = store.count("views", filter); const downloadUrl = getDownloadUrl(filter); const attrs = {}; attrs["attributes"] = attributes; attrs["data"] = views.value; attrs["total"] = count.value; attrs["showMoreCallback"] = showMore; attrs["sortAttributes"] = sortAttributes; attrs["onSortChange"] = onSortChange; attrs["downloadUrl"] = downloadUrl; attrs["recordActionsCallback"] = (cmp) => { return [ m( "button.text-cyan-700 hover:text-cyan-900 font-medium", { onclick: () => { let cb: () => Children = null; const comp = m( putFormComponent, Object.assign( { base: cmp, actionHandler: (action, object) => { return new Promise((resolve) => { putActionHandler(action, object, false) .then((errors) => { const errorList = errors ? Object.values(errors) : []; if (errorList.length) { for (const err of errorList) notifications.push("error", err); } else { overlay.close(cb); } resolve(); }) .catch((err) => { notifications.push("error", err.message); resolve(); }); }); }, }, formData, ), ); cb = () => comp; overlay.open( cb, () => !comp.state["current"]["modified"] || confirm("You have unsaved changes. Close anyway?"), ); }, }, "Show", ), ]; }; if (window.authorizer.hasAccess("views", 3)) { attrs["actionsCallback"] = (selected: Set): Children => { return [ m( "button.px-4 py-2 border border-stone-300 shadow-sm text-sm font-medium rounded-md text-stone-700 bg-white hover:bg-stone-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-cyan-500 disabled:opacity-50 disabled:cursor-not-allowed", { title: "Create new view", onclick: () => { let cb: () => Children = null; const comp = m( putFormComponent, Object.assign( { actionHandler: (action, object) => { return new Promise((resolve) => { putActionHandler(action, object, true) .then((errors) => { const errorList = errors ? Object.values(errors) : []; if (errorList.length) { for (const err of errorList) notifications.push("error", err); } else { overlay.close(cb); } resolve(); }) .catch((err) => { notifications.push("error", err.message); resolve(); }); }); }, }, formData, ), ); cb = () => comp; overlay.open( cb, () => !comp.state["current"]["modified"] || confirm("You have unsaved changes. Close anyway?"), ); }, }, "New", ), m( "button.px-4 py-2 border border-stone-300 shadow-sm text-sm font-medium rounded-md text-stone-700 bg-white hover:bg-stone-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-cyan-500 disabled:opacity-50 disabled:cursor-not-allowed", { title: "Delete selected views", disabled: !selected.size, onclick: (e) => { if ( !confirm(`Deleting ${selected.size} views. Are you sure?`) ) return; e.redraw = false; e.target.disabled = true; Promise.all( Array.from(selected).map((id) => store.deleteResource("views", id), ), ) .then((res) => { notifications.push( "success", `${res.length} views deleted`, ); store.setTimestamp(Date.now()); }) .catch((err) => { notifications.push("error", err.message); store.setTimestamp(Date.now()); }); }, }, "Delete", ), ]; }; } const filterAttrs = { resource: "views", filter: vnode.attrs["filter"], onChange: onFilterChanged, }; return [ m("h1.text-xl font-medium text-stone-900 mb-5", "Listing views"), m(filterComponent, filterAttrs), m( "loading", { queries: [views, count] }, m(indexTableComponent, attrs), ), ]; }, }; }; ================================================ FILE: ui/views.ts ================================================ import m, { ClosureComponent, ChildArray } from "mithril"; import { ComputedSignal, ConstSignal, SignalBase, StateSignal, Watcher, setTimeout as _setTimeout, setInterval as _setInterval, } from "./signals.ts"; import views from "views-bundle"; import { count, fetch, invalidate } from "./reactive-store.ts"; import { SkewedDate, getClockSkew } from "./skewed-date.ts"; import Expression from "../lib/common/expression.ts"; import * as taskQueue from "./task-queue.ts"; import * as notifications from "./notifications.ts"; import { deleteResource, ping, updateTags } from "./store.ts"; import { stringify } from "../lib/common/yaml.ts"; type ViewElement = | ViewNode | string | number | SignalBase | ViewElement[]; export class ViewNode { name: string | null; attributes: Record; children: ViewElement[]; constructor( name: string, attributes: Record, children: ViewElement[], ) { this.name = name; this.attributes = attributes ?? {}; this.children = children; } } // A signalized version of ViewNode where all properties are wrapped in signals. // If the original value is already a Signal, it's used as-is. // Otherwise, a ConstSignal is created to wrap the value. export interface SignalizedViewNode { name: SignalBase; attributes: Record>; children: SignalBase[]; } // Wraps a value in a ConstSignal if it's not already a Signal. function toSignal(value: T | SignalBase): SignalBase { if (value instanceof SignalBase) return value; return new ConstSignal(value); } // Converts a ViewNode to a SignalizedViewNode where all properties are signals. function signalizeNode(node: ViewNode): SignalizedViewNode { const signalizedAttrs: Record> = {}; for (const [key, value] of Object.entries(node.attributes)) { signalizedAttrs[key] = toSignal(value); } return { name: toSignal(node.name), attributes: signalizedAttrs, children: node.children.map((child) => toSignal(child)), }; } function doCount(node: SignalizedViewNode): ViewElement { return new ComputedSignal(() => { const arg = node.attributes["arg"]?.get() as { resource: string; filter: string; freshness?: number; } | null; if (!arg) return null; const res = node.attributes["res"] as StateSignal; // View scripts see server-adjusted time (via SkewedDate), but cache // timestamps use local time, so convert back to local time. const localFreshness = arg.freshness ? arg.freshness - getClockSkew() : 0; const querySignal = count(arg.resource, Expression.parse(arg.filter), { freshness: localFreshness, }); const sig = new ComputedSignal(() => { if (res) res.set(querySignal.get().value); return null; }); return sig; }); } function doFetch(node: SignalizedViewNode): ViewElement { return new ComputedSignal(() => { const arg = node.attributes["arg"]?.get() as { resource: string; filter: string; freshness?: number; } | null; if (!arg) return null; const res = node.attributes["res"] as StateSignal; const localFreshness = arg.freshness ? arg.freshness - getClockSkew() : 0; const querySignal = fetch(arg.resource, Expression.parse(arg.filter), { freshness: localFreshness, }); const sig = new ComputedSignal(() => { if (res) res.set(querySignal.get().value); return null; }); return sig; }); } function doTask(node: SignalizedViewNode): ViewElement { return new ComputedSignal(() => { const arg = node.attributes["arg"]?.get() as { name: string; device: string; commit?: boolean; parameterNames?: string[]; parameterValues?: unknown[]; objectName?: string; } | null; if (!arg) return null; const res = node.attributes["res"] as StateSignal; const task: any = Object.assign({}, arg); if (arg.commit) { if (res) res.set("pending"); taskQueue .commit([task], (_, err, conReq, tasks2) => { for (const t of tasks2) if (t.status === "stale") taskQueue.deleteTask(t); if (err) { if (res) res.set("stale"); } else if (conReq !== "OK") { if (res) res.set("stale"); } else if (tasks2[0]?.status === "stale") { if (res) res.set("stale"); } else if (tasks2[0]?.status === "fault") { if (res) res.set("fault"); } else { if (res) res.set("done"); } }) .then(() => invalidate(Date.now())) .catch(() => { if (res) res.set("stale"); }); } else if (task.name === "setParameterValues" || task.name === "download") { if (task.name === "download") taskQueue.stageDownload(task); else taskQueue.stageSpv(task); if (res) res.set("staging"); } else { taskQueue.queueTask(task); if (res) res.set("queued"); } return null; }); } function doNotify(node: SignalizedViewNode): ViewElement { return new ComputedSignal(() => { const arg = node.attributes["arg"]?.get() as { type: string; message: string; actions?: Record void>; } | null; if (!arg?.type || !arg?.message) return null; notifications.push(arg.type, arg.message, arg.actions); return null; }); } function doDelete(node: SignalizedViewNode): ViewElement { return new ComputedSignal(() => { const arg = node.attributes["arg"]?.get() as { resource: string; id: string; } | null; if (!arg?.resource || !arg?.id) return null; const res = node.attributes["res"] as StateSignal; deleteResource(arg.resource, arg.id) .then(() => { invalidate(Date.now()); if (res) res.set(true); }) .catch((err) => { if (res) res.set(err instanceof Error ? err : new Error(String(err))); }); return null; }); } function doYamlStringify(node: SignalizedViewNode): ViewElement { return new ComputedSignal(() => { const arg = node.attributes["arg"]?.get(); const res = node.attributes["res"] as StateSignal; if (arg === undefined || !res) return null; res.set(stringify(arg)); return null; }); } function doUpdateTags(node: SignalizedViewNode): ViewElement { return new ComputedSignal(() => { const arg = node.attributes["arg"]?.get() as { deviceId: string; tags: Record; } | null; if (!arg?.deviceId || !arg?.tags) return null; const res = node.attributes["res"] as StateSignal; updateTags(arg.deviceId, arg.tags) .then(() => { invalidate(Date.now()); if (res) res.set(true); }) .catch((err) => { if (res) res.set(err instanceof Error ? err : new Error(String(err))); }); return null; }); } function doPing(node: SignalizedViewNode): ViewElement { return new ComputedSignal(() => { const arg = node.attributes["arg"]?.get() as string | null; const res = node.attributes["res"] as StateSignal; if (!arg || !res) return null; const refresh = (): void => { ping(arg) .then((r) => { res.set(r["avg"] != null ? r["avg"] : null); }) .catch((err) => { res.set(err instanceof Error ? err : new Error(String(err))); }); }; refresh(); _setInterval(refresh, 3000); return null; }); } function initView(context: RenderContext, node: ViewElement): ViewElement { if (node instanceof SignalBase) { return new ComputedSignal(() => { const v = initView(context, node.get()); if (v instanceof SignalBase) return v.get(); return v; }); } if (Array.isArray(node)) return node.map((n) => initView(context, n)); if (!(node instanceof ViewNode)) return node; const script = context.getView(node.name); if (script) { const context2 = context.popView(node.name).pushDeferred(node.children); const signalizedNode = signalizeNode(node); return new ComputedSignal(() => { const res = script( signalizedNode, _setTimeout as any, _setInterval as any, SkewedDate as unknown as DateConstructorLike, ); return initView(context2, res); }); } if (node.name === "do-count") return doCount(signalizeNode(node)); if (node.name === "do-fetch") return doFetch(signalizeNode(node)); if (node.name === "do-task") return doTask(signalizeNode(node)); if (node.name === "do-notify") return doNotify(signalizeNode(node)); if (node.name === "do-delete") return doDelete(signalizeNode(node)); if (node.name === "do-ping") return doPing(signalizeNode(node)); if (node.name === "do-yaml-stringify") return doYamlStringify(signalizeNode(node)); if (node.name === "do-update-tags") return doUpdateTags(signalizeNode(node)); const children = node.children.map((child) => initView(context, child)); return new ViewNode(node.name, node.attributes, children); } type SetTimeout = typeof setTimeout; type DateConstructorLike = typeof globalThis.Date; type ViewFunc = ( node: SignalizedViewNode, setTimeout: SetTimeout, setInterval: SetTimeout, Date: DateConstructorLike, ) => ViewElement; class RenderContext { private viewStacks: Record; private deferredStack: ChildArray[]; constructor(clone?: RenderContext) { if (clone) { this.viewStacks = clone.viewStacks; this.deferredStack = clone.deferredStack; } else { this.viewStacks = {}; this.deferredStack = []; } } getView(name: string): ViewFunc { const stack = this.viewStacks[name]; if (!stack) return null; return stack[stack.length - 1]; } pushViews(_views: Record): RenderContext { const clone = new RenderContext(this); for (const [name, view] of Object.entries(_views)) { clone.viewStacks[name] = [...(clone.viewStacks[name] ?? []), view]; } return clone; } popView(name: string): RenderContext { const stack = this.viewStacks[name]; if (!stack?.length) return this; const clone = new RenderContext(this); clone.viewStacks = { ...this.viewStacks, [name]: stack.slice(0, -1) }; return clone; } getDeferred(): (ViewNode | SignalBase | any)[] { if (!this.deferredStack.length) return null; return this.deferredStack[this.deferredStack.length - 1]; } popDeferred(): RenderContext { const clone = new RenderContext(this); clone.deferredStack = this.deferredStack.slice(0, -1); return clone; } pushDeferred(deferred: (ViewNode | SignalBase | any)[]): RenderContext { const clone = new RenderContext(this); clone.deferredStack = [...this.deferredStack, deferred]; return clone; } } function renderNode(node: ViewElement): ReturnType { if (node instanceof SignalBase) { return renderNode(node.get()); } if (node instanceof ViewNode) { const attrs: Record = {}; for (const [k, v] of Object.entries(node.attributes)) { attrs[k] = v instanceof SignalBase ? v.get() : v; } if (!node.name) return m.fragment(attrs, node.children.map(renderNode)); return m(node.name, attrs, node.children.map(renderNode)); } if (Array.isArray(node)) return m.fragment( {}, node.map((n) => renderNode(n)), ); return m.fragment({}, node); } export const ViewComponent: ClosureComponent<{ name: string; attrs: Record; }> = (vnode) => { const context = new RenderContext().pushViews( views as Record, ); const node = initView( context, new ViewNode(vnode.attrs.name, vnode.attrs.attrs, []), ); const signal = new ComputedSignal>(() => { return renderNode(node); }); const watcher = new Watcher(() => { requestAnimationFrame(() => { watcher.watch(); // Reset notification state m.redraw(); }); }); watcher.watch(signal); return { view: () => signal.get(), onremove: () => { watcher[Symbol.dispose](); if (node[Symbol.dispose]) node[Symbol.dispose](); }, }; }; ================================================ FILE: ui/virtual-parameters-page.ts ================================================ import { ClosureComponent, Component, Children } from "mithril"; import { m } from "./components.ts"; import { pageSize as PAGE_SIZE } from "./config.ts"; import filterComponent from "./filter-component.ts"; import * as store from "./store.ts"; import * as notifications from "./notifications.ts"; import memoize from "../lib/common/memoize.ts"; import putFormComponent from "./put-form-component.ts"; import indexTableComponent from "./index-table-component.ts"; import * as overlay from "./overlay.ts"; import * as smartQuery from "./smart-query.ts"; import Expression from "../lib/common/expression.ts"; import { loadCodeMirror } from "./dynamic-loader.ts"; const memoizedJsonParse = memoize(JSON.parse); const attributes = [ { id: "_id", label: "Name" }, { id: "script", label: "Script", type: "code", mode: "javascript" }, ]; const unpackSmartQuery = memoize((query: Expression) => { return query.evaluate((e) => { if (e instanceof Expression.FunctionCall) { if (e.name === "Q") { if ( e.args[0] instanceof Expression.Literal && e.args[1] instanceof Expression.Literal ) { return smartQuery.unpack( "virtualParameters", e.args[0].value as string, e.args[1].value as string, ); } } } return e; }); }); interface ValidationErrors { [prop: string]: string; } function putActionHandler(action, _object, isNew): Promise { return new Promise((resolve, reject) => { const object = Object.assign({}, _object); if (action === "save") { const id = object["_id"]; delete object["_id"]; if (!id) return void resolve({ _id: "ID can not be empty" }); store .resourceExists("virtualParameters", id) .then((exists) => { if (exists && isNew) { store.setTimestamp(Date.now()); return void resolve({ _id: "Virtual parameter already exists" }); } if (!exists && !isNew) { store.setTimestamp(Date.now()); return void resolve({ _id: "Virtual parameter does not exist" }); } store .putResource("virtualParameters", id, object) .then(() => { notifications.push( "success", `Virtual parameter ${exists ? "updated" : "created"}`, ); store.setTimestamp(Date.now()); resolve(null); }) .catch((err) => { if (err["code"] === 400 && err["response"]) { reject(new Error(err["response"])); return; } reject(err); }); }) .catch(reject); } else if (action === "delete") { if (!confirm("Deleting virtual parameter. Are you sure?")) return void resolve(null); store .deleteResource("virtualParameters", object["_id"]) .then(() => { notifications.push("success", "Virtual parameter deleted"); store.setTimestamp(Date.now()); resolve(null); }) .catch((err) => { store.setTimestamp(Date.now()); reject(err); }); } else { reject(new Error("Undefined action")); } }); } const formData = { resource: "virtualParameters", attributes: attributes, }; const getDownloadUrl = memoize((filter) => { const cols = {}; for (const attr of attributes) cols[attr.label] = attr.id; return `api/virtualParameters.csv?${m.buildQueryString({ filter: filter.toString(), columns: JSON.stringify(cols), })}`; }); export function init( args: Record, ): Promise> { if (!window.authorizer.hasAccess("virtualParameters", 2)) { return Promise.reject( new Error("You are not authorized to view this page"), ); } let filter: Expression = null; let sort: Record = null; if (args.hasOwnProperty("filter")) filter = Expression.parse(args["filter"] as string); if (args.hasOwnProperty("sort")) sort = JSON.parse(args["sort"] as string); return new Promise((resolve, reject) => { loadCodeMirror() .then(() => { resolve({ filter, sort }); }) .catch(reject); }); } export const component: ClosureComponent = (): Component => { return { view: (vnode) => { document.title = "Virtual Parameters - GenieACS"; function showMore(): void { vnode.state["showCount"] = (vnode.state["showCount"] || PAGE_SIZE) + PAGE_SIZE; m.redraw(); } function onFilterChanged(filter): void { const ops = {}; if (!(filter instanceof Expression.Literal && filter.value)) ops["filter"] = filter.toString(); if (vnode.attrs["sort"]) ops["sort"] = vnode.attrs["sort"]; m.route.set("/virtualParameters", ops); } const sort = vnode.attrs["sort"] ? memoizedJsonParse(vnode.attrs["sort"]) : {}; const sortAttributes = {}; for (let i = 0; i < attributes.length; i++) sortAttributes[i] = sort[attributes[i].id] || 0; function onSortChange(sortAttrs): void { const _sort = {}; for (const index of sortAttrs) _sort[attributes[Math.abs(index) - 1].id] = Math.sign(index); const ops = { sort: JSON.stringify(_sort) }; if (vnode.attrs["filter"]) ops["filter"] = vnode.attrs["filter"]; m.route.set("/virtualParameters", ops); } const filter = unpackSmartQuery( vnode.attrs["filter"] ?? new Expression.Literal(true), ); const virtualParameters = store.fetch("virtualParameters", filter, { limit: vnode.state["showCount"] || PAGE_SIZE, sort: sort, }); const count = store.count("virtualParameters", filter); const downloadUrl = getDownloadUrl(filter); const attrs = {}; attrs["attributes"] = attributes; attrs["data"] = virtualParameters.value; attrs["total"] = count.value; attrs["showMoreCallback"] = showMore; attrs["sortAttributes"] = sortAttributes; attrs["onSortChange"] = onSortChange; attrs["downloadUrl"] = downloadUrl; attrs["recordActionsCallback"] = (virtualParameter) => { return [ m( "button.text-cyan-700 hover:text-cyan-900 font-medium", { onclick: () => { let cb: () => Children = null; const comp = m( putFormComponent, Object.assign( { base: virtualParameter, actionHandler: (action, object) => { return new Promise((resolve) => { putActionHandler(action, object, false) .then((errors) => { const errorList = errors ? Object.values(errors) : []; if (errorList.length) { for (const err of errorList) notifications.push("error", err); } else { overlay.close(cb); } resolve(); }) .catch((err) => { notifications.push("error", err.message); resolve(); }); }); }, }, formData, ), ); cb = () => comp; overlay.open( cb, () => !comp.state["current"]["modified"] || confirm("You have unsaved changes. Close anyway?"), ); }, }, "Show", ), ]; }; if (window.authorizer.hasAccess("virtualParameters", 3)) { attrs["actionsCallback"] = (selected: Set): Children => { return [ m( "button.px-4 py-2 border border-stone-300 shadow-xs text-sm font-medium rounded-md text-stone-700 bg-white hover:bg-stone-50 focus:outline-hidden focus:ring-2 focus:ring-offset-2 focus:ring-cyan-500 disabled:opacity-50 disabled:cursor-not-allowed", { title: "Create new virtual parameter", onclick: () => { let cb: () => Children = null; const comp = m( putFormComponent, Object.assign( { actionHandler: (action, object) => { return new Promise((resolve) => { putActionHandler(action, object, true) .then((errors) => { const errorList = errors ? Object.values(errors) : []; if (errorList.length) { for (const err of errorList) notifications.push("error", err); } else { overlay.close(cb); } resolve(); }) .catch((err) => { notifications.push("error", err.message); resolve(); }); }); }, }, formData, ), ); cb = () => comp; overlay.open( cb, () => !comp.state["current"]["modified"] || confirm("You have unsaved changes. Close anyway?"), ); }, }, "New", ), m( "button.px-4 py-2 border border-stone-300 shadow-xs text-sm font-medium rounded-md text-stone-700 bg-white hover:bg-stone-50 focus:outline-hidden focus:ring-2 focus:ring-offset-2 focus:ring-cyan-500 disabled:opacity-50 disabled:cursor-not-allowed", { title: "Delete selected virtual parameters", disabled: !selected.size, onclick: (e) => { if ( !confirm( `Deleting ${selected.size} virtual parameters. Are you sure?`, ) ) return; e.redraw = false; e.target.disabled = true; Promise.all( Array.from(selected).map((id) => store.deleteResource("virtualParameters", id), ), ) .then((res) => { notifications.push( "success", `${res.length} virtual parameters deleted`, ); store.setTimestamp(Date.now()); }) .catch((err) => { notifications.push("error", err.message); store.setTimestamp(Date.now()); }); }, }, "Delete", ), ]; }; } const filterAttrs = { resource: "virtualParameters", filter: vnode.attrs["filter"], onChange: onFilterChanged, }; return [ m( "h1.text-xl font-medium text-stone-900 mb-5", "Listing virtual parameters", ), m(filterComponent, filterAttrs), m( "loading", { queries: [virtualParameters, count] }, m(indexTableComponent, attrs), ), ]; }, }; }; ================================================ FILE: ui/wizard-page.ts ================================================ import { ClosureComponent, Component } from "mithril"; import { m } from "./components.ts"; import * as notifications from "./notifications.ts"; export async function init(): Promise> { return m.request({ url: "init" }); } export const component: ClosureComponent = (vnode): Component => { let options = vnode.attrs; const selected = new Set(); for (const [k, v] of Object.entries(options)) if (v) selected.add(k); return { view: () => { document.title = "Initialization wizard - GenieACS"; const items = [ { key: "users", label: "Users, roles and permissions" }, { key: "presets", label: "Presets and provisions" }, { key: "filters", label: "Devices predefined search filters" }, { key: "device", label: "Device details page" }, { key: "index", label: "Devices listing page" }, { key: "overview", label: "Overview page" }, ]; return [ m( "h1.text-xl font-medium text-stone-900 mb-5", "Initialization wizard", ), m(".bg-white shadow-sm rounded-lg p-6 sm:p-8 max-w-lg", [ m( "p.text-sm text-stone-600 mb-6", "This wizard will seed the database with a minimal initial configuration to serve as a starting point. Select what you want to initialize and click the button below.", ), m( ".flex flex-col gap-3 mb-6", items.map((item) => { if (!options[item.key]) selected.delete(item.key); return m( "label.flex items-center text-sm text-stone-700", { class: options[item.key] ? "" : "opacity-50" }, m( "input.focus:ring-cyan-500 h-4 w-4 text-cyan-700 border-stone-300 rounded-sm", { type: "checkbox", checked: selected.has(item.key), disabled: !options[item.key], onclick: (e) => { if (e.target.checked) selected.add(item.key); else selected.delete(item.key); }, }, ), m("span.ml-2", item.label), ); }), ), m( "button.inline-flex justify-center py-2 px-4 border border-transparent shadow-xs text-sm font-medium rounded-md text-white bg-cyan-600 hover:bg-cyan-700 focus:outline-hidden focus:ring-2 focus:ring-offset-2 focus:ring-cyan-500 disabled:opacity-50 disabled:cursor-not-allowed", { disabled: selected.size === 0, onclick: (e) => { e.target.disabled = true; const opts = {}; for (const s of selected) opts[s] = true; m.request({ method: "POST", url: "init", body: opts, }) .then(() => { setTimeout(() => { m.request({ url: "init" }) .then((o) => { e.target.disabled = false; options = o; notifications.push( "success", "Initialization complete", { "Open Sesame!": () => { m.route.set("/login"); window.location.reload(); }, }, ); }) .catch((err) => { notifications.push("error", err.message); }); }, 3000); if (opts["users"]) { alert( "An administrator user has been created for you. Use admin/admin to log in. Don't forget to change the default password.", ); } }) .catch((err) => { notifications.push("error", err.message); }); }, }, "ABRACADABRA!", ), ]), ]; }, }; }; ================================================ FILE: ui/yaml-loader.ts ================================================ export { parse, stringify } from "yaml";