Interface IPolicySchema

Interface representing the schema for configuring a policy. Defines how policies enforce rules and manage bans within the swarm.

interface IPolicySchema {
    autoBan?: boolean;
    banMessage?: string;
    callbacks?: IPolicyCallbacks;
    docDescription?: string;
    getBanMessage?: (
        clientId: string,
        policyName: string,
        swarmName: string,
    ) => string | Promise<string>;
    getBannedClients?: (
        policyName: string,
        swarmName: string,
    ) => string[] | Promise<string[]>;
    persist?: boolean;
    policyName: string;
    setBannedClients?: (
        clientIds: string[],
        policyName: string,
        swarmName: string,
    ) => void | Promise<void>;
    validateInput?: (
        incoming: string,
        clientId: string,
        policyName: string,
        swarmName: string,
    ) => boolean | Promise<boolean>;
    validateOutput?: (
        outgoing: string,
        clientId: string,
        policyName: string,
        swarmName: string,
    ) => boolean | Promise<boolean>;
}

Properties

autoBan?: boolean

Optional flag to automatically ban a client immediately after failed validation.

banMessage?: string

Optional default message to display when a client is banned, overridden by getBanMessage if provided.

callbacks?: IPolicyCallbacks

Optional set of callbacks for policy events, allowing customization of validation and ban actions.

docDescription?: string

Optional description for documentation purposes, aiding in policy usage understanding.

getBanMessage?: (
    clientId: string,
    policyName: string,
    swarmName: string,
) => string | Promise<string>

Optional function to retrieve a custom ban message for a client. Overrides the default banMessage if provided.

getBannedClients?: (
    policyName: string,
    swarmName: string,
) => string[] | Promise<string[]>

Retrieves the list of currently banned clients under this policy.

persist?: boolean

Optional flag to enable serialization of banned clients to persistent storage (e.g., hard drive).

policyName: string

The unique name of the policy within the swarm.

setBannedClients?: (
    clientIds: string[],
    policyName: string,
    swarmName: string,
) => void | Promise<void>

Optional function to set the list of banned clients. Overrides default ban list management if provided.

If updating the ban list fails (e.g., due to persistence issues).

validateInput?: (
    incoming: string,
    clientId: string,
    policyName: string,
    swarmName: string,
) => boolean | Promise<boolean>

Optional function to validate incoming messages against custom policy rules. Overrides default validation if provided.

validateOutput?: (
    outgoing: string,
    clientId: string,
    policyName: string,
    swarmName: string,
) => boolean | Promise<boolean>

Optional function to validate outgoing messages against custom policy rules. Overrides default validation if provided.