Skip to content

fix: resolve positional URL parameter passing in callModularTool - #10

Open
papajade55-debug wants to merge 1 commit into
Pixelworlds:masterfrom
papajade55-debug:master
Open

papajade55-debug wants to merge 1 commit into
Pixelworlds:masterfrom
papajade55-debug:master

Conversation

@papajade55-debug

Copy link
Copy Markdown

Problem

The callModularTool method passes all parameters as a single object to client SDK methods:

const callParams = { ...params, ...otherArgs };
return await method.call(moduleObj, callParams);

But the client SDK (@richard-stovall/opnsense-typescript-client) uses positional URL parameters for methods that embed values in the URL path. For example:

// diagnostics.ts — actual SDK signature
async pingStart(jobid: string, data?, config?): Promise<...> {
    return this.http.post(`/api/diagnostics/ping/start/${jobid}`, data, config);
}

When callModularTool calls method.call(moduleObj, { uuid: "abc" }), the SDK receives jobid = { uuid: "abc" } (an object instead of a string), producing the URL /api/diagnostics/ping/start/[object Object] which fails.

Impact

~200+ methods across all modules are affected, including:

  • pingStart, pingStop, pingRemove — diagnostics ping
  • packetCaptureStart, packetCaptureStop — packet capture
  • firewallDelState, firewallPfStatistics — firewall diagnostics
  • All *DelItem, *GetItem, *SetItem methods — CRUD operations
  • All *Toggle* methods — enable/disable
  • All *DelRule, *GetRule, *SetRule — NAT/filter rule management
  • All *DelServer, *GetServer, *SetServer — server management
  • And many more across all 24 core modules

Fix

The fix detects positional URL methods at runtime by checking two conditions:

  1. The method expects more than 1 argument (method.length > 1)
  2. The params object contains a known URL parameter name (uuid, jobid, stateid, etc.)

When both conditions are met, URL params are extracted positionally from the params object, and remaining params are passed as the data/body object.

Testing

All 13 test cases pass:

  • Body-only methods (pingSet, aliasAddItem, filterAddRule, systemStatus) → pass object as-is ✅
  • URL param methods (pingStart, pingStop, pingRemove, firewallDelState, aliasDelItem, userGet, packetCaptureStart/Stop, firewallPfStatistics) → extract positionally ✅

Files changed

  • src/build.ts — template source for the single-file server
  • index.js — compiled server (patched for immediate use)

The callModularTool method was passing all parameters as a single object
to client SDK methods, but many methods expect positional URL parameters
(e.g. pingStart(jobid, data, config) → POST /api/diagnostics/ping/start/${jobid}).

This caused all methods with URL-embedded parameters to fail silently:
- pingStart, pingStop, pingRemove
- packetCaptureStart, packetCaptureStop
- firewallDelState, firewallPfStatistics
- All *DelItem, *GetItem, *SetItem methods across all modules
- All *Toggle* methods
- And ~200+ other methods with URL parameters

The fix detects positional URL methods by checking if callParams contains
known URL parameter names (uuid, jobid, stateid, etc.) AND the method
expects more than 1 argument. When detected, URL params are extracted
positionally and remaining params are passed as the data object.

Fixes Pixelworlds#1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant