Skip to content

Commit f8ea7fa

Browse files
mishushakovclaude
andcommitted
feat(js-sdk): accept Map for network.rules
SandboxNetworkRules now accepts both a plain object and a Map. The helper normalizes either form to a Map for the selector context and serializes via Object.fromEntries for the wire body. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 5a5f885 commit f8ea7fa

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

packages/js-sdk/src/sandbox/sandboxApi.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,13 @@ export type SandboxNetworkRule = {
5555

5656
/**
5757
* Map of host (or CIDR / IP) to ordered list of rules applied to outbound
58-
* requests for that host. Registering a host here does not allow egress on
59-
* its own — the host must also appear in {@link SandboxNetworkOpts.allowOut}.
58+
* requests for that host. Accepts either a plain object or a `Map`.
59+
* Registering a host here does not allow egress on its own — the host must
60+
* also appear in {@link SandboxNetworkOpts.allowOut}.
6061
*/
61-
export type SandboxNetworkRules = Record<string, SandboxNetworkRule[]>
62+
export type SandboxNetworkRules =
63+
| Record<string, SandboxNetworkRule[]>
64+
| Map<string, SandboxNetworkRule[]>
6265

6366
/**
6467
* Context passed to {@link SandboxNetworkOpts.allowOut} and
@@ -519,14 +522,19 @@ function buildNetworkBody(
519522
return undefined
520523
}
521524

522-
const rules = new Map(Object.entries(network.rules ?? {}))
525+
const rules =
526+
network.rules instanceof Map
527+
? network.rules
528+
: new Map(Object.entries(network.rules ?? {}))
523529
const allowOut = resolveNetworkSelector(network.allowOut, rules)
524530
const denyOut = resolveNetworkSelector(network.denyOut, rules)
525531

526532
return {
527533
...(allowOut !== undefined ? { allowOut } : {}),
528534
...(denyOut !== undefined ? { denyOut } : {}),
529-
...(network.rules !== undefined ? { rules: network.rules } : {}),
535+
...(network.rules !== undefined
536+
? { rules: Object.fromEntries(rules) }
537+
: {}),
530538
...(network.allowPublicTraffic !== undefined
531539
? { allowPublicTraffic: network.allowPublicTraffic }
532540
: {}),

0 commit comments

Comments
 (0)