UNPKG

the-wireguard-effect

Version:

Cross platform wireguard api client for nodejs built on wireguard-go with effect-ts

327 lines 14.8 kB
import type * as CommandExecutor from "@effect/platform/CommandExecutor"; import type * as PlatformError from "@effect/platform/Error"; import type * as Socket from "@effect/platform/Socket"; import type * as Cause from "effect/Cause"; import type * as Scope from "effect/Scope"; import * as FileSystem from "@effect/platform/FileSystem"; import * as Path from "@effect/platform/Path"; import * as Effect from "effect/Effect"; import * as ParseResult from "effect/ParseResult"; import * as Schema from "effect/Schema"; import * as Stream from "effect/Stream"; import * as InternetSchemas from "../InternetSchemas.js"; import * as WireguardControl from "../WireguardControl.js"; import * as WireguardErrors from "../WireguardErrors.js"; import * as WireguardPeer from "../WireguardPeer.js"; declare const WireguardConfig_base: import("@effect/experimental/VariantSchema").Class<WireguardConfig, { /** The Address of this peer. */ readonly Address: InternetSchemas.$CidrBlockFromString; /** DNS for this peer. */ readonly Dns: Schema.optional<InternetSchemas.$Address>; /** * The value for this is a decimal-string integer corresponding to the * listening port of the interface. */ readonly ListenPort: Schema.Union<[InternetSchemas.$Port, Schema.transformOrFail<typeof Schema.String, InternetSchemas.$Port, never>]>; /** * The value for this is a decimal-string integer corresponding to the * fwmark of the interface. The value may 0 in the case of a set operation, * in which case it indicates that the fwmark should be removed. */ readonly FirewallMark: Schema.optionalWith<typeof Schema.Number, { nullable: true; }>; /** * The value for this key should be a lowercase hex-encoded private key of * the interface. The value may be an all zero string in the case of a set * operation, in which case it indicates that the private key should be * removed. */ readonly PrivateKey: Schema.brand<Schema.refine<string, typeof Schema.String>, "WireguardKey">; /** List of peers to add. */ readonly Peers: import("@effect/experimental/VariantSchema").Field<{ readonly json: Schema.optionalWith<Schema.Array$<typeof WireguardPeer.WireguardPeer>, { default: () => never[]; nullable: true; }>; readonly uapi: Schema.optionalWith<Schema.Array$<Schema.Struct<{ readonly PersistentKeepalive: Schema.optionalWith<typeof InternetSchemas.DurationFromSeconds, { as: "Option"; nullable: true; }>; readonly AllowedIPs: Schema.optionalWith<Schema.ReadonlySetFromSelf<InternetSchemas.$CidrBlockFromString>, { nullable: true; default: () => Set<never>; }>; readonly Endpoint: Schema.optionalWith<InternetSchemas.$Endpoint, { nullable: true; }>; readonly PublicKey: Schema.brand<Schema.refine<string, typeof Schema.String>, "WireguardKey">; readonly PresharedKey: Schema.optionalWith<Schema.brand<Schema.refine<string, typeof Schema.String>, "WireguardKey">, { nullable: true; as: "Option"; }>; readonly rxBytes: typeof Schema.NumberFromString; readonly txBytes: typeof Schema.NumberFromString; readonly lastHandshake: Schema.transform<Schema.transform<typeof Schema.NumberFromString, Schema.transform<typeof Schema.Number, typeof Schema.Number>>, typeof Schema.DateTimeUtcFromNumber>; }>>, { default: () => never[]; nullable: true; }>; }>; }, { readonly Address: InternetSchemas.$CidrBlockFromString; readonly Dns: Schema.optional<InternetSchemas.$Address>; readonly ListenPort: Schema.Union<[InternetSchemas.$Port, Schema.transformOrFail<typeof Schema.String, InternetSchemas.$Port, never>]>; readonly FirewallMark: Schema.optionalWith<typeof Schema.Number, { nullable: true; }>; readonly PrivateKey: Schema.brand<Schema.refine<string, typeof Schema.String>, "WireguardKey">; readonly Peers: Schema.optionalWith<Schema.Array$<typeof WireguardPeer.WireguardPeer>, { default: () => never[]; nullable: true; }>; }, { readonly Address: InternetSchemas.CidrBlockBase<"ipv4"> | InternetSchemas.CidrBlockBase<"ipv6">; } & { readonly Dns?: { readonly family: "ipv4"; readonly ip: InternetSchemas.IPv4Brand; } | { readonly family: "ipv6"; readonly ip: InternetSchemas.IPv6Brand; } | undefined; } & { readonly ListenPort: InternetSchemas.PortBrand; } & { readonly Peers: readonly WireguardPeer.WireguardPeer[]; } & { readonly FirewallMark?: number | undefined; } & { readonly PrivateKey: string & import("effect/Brand").Brand<"WireguardKey">; }, Schema.Struct.Encoded<{ readonly Address: InternetSchemas.$CidrBlockFromString; readonly Dns: Schema.optional<InternetSchemas.$Address>; readonly ListenPort: Schema.Union<[InternetSchemas.$Port, Schema.transformOrFail<typeof Schema.String, InternetSchemas.$Port, never>]>; readonly FirewallMark: Schema.optionalWith<typeof Schema.Number, { nullable: true; }>; readonly PrivateKey: Schema.brand<Schema.refine<string, typeof Schema.String>, "WireguardKey">; readonly Peers: Schema.optionalWith<Schema.Array$<typeof WireguardPeer.WireguardPeer>, { default: () => never[]; nullable: true; }>; }>, never, { readonly Address: InternetSchemas.CidrBlockBase<"ipv4"> | InternetSchemas.CidrBlockBase<"ipv6">; } & { readonly Dns?: { readonly family: "ipv4"; readonly ip: InternetSchemas.IPv4Brand; } | { readonly family: "ipv6"; readonly ip: InternetSchemas.IPv6Brand; } | undefined; } & { readonly ListenPort: InternetSchemas.PortBrand; } & { readonly Peers?: readonly WireguardPeer.WireguardPeer[]; } & { readonly FirewallMark?: number | undefined; } & { readonly PrivateKey: string & import("effect/Brand").Brand<"WireguardKey">; }> & { readonly json: Schema.Struct<{ readonly Address: InternetSchemas.$CidrBlockFromString; readonly Dns: Schema.optional<InternetSchemas.$Address>; readonly ListenPort: Schema.Union<[InternetSchemas.$Port, Schema.transformOrFail<typeof Schema.String, InternetSchemas.$Port, never>]>; readonly FirewallMark: Schema.optionalWith<typeof Schema.Number, { nullable: true; }>; readonly PrivateKey: Schema.brand<Schema.refine<string, typeof Schema.String>, "WireguardKey">; readonly Peers: Schema.optionalWith<Schema.Array$<typeof WireguardPeer.WireguardPeer>, { default: () => never[]; nullable: true; }>; }>; readonly uapi: Schema.Struct<{ readonly Address: InternetSchemas.$CidrBlockFromString; readonly Dns: Schema.optional<InternetSchemas.$Address>; readonly ListenPort: Schema.Union<[InternetSchemas.$Port, Schema.transformOrFail<typeof Schema.String, InternetSchemas.$Port, never>]>; readonly FirewallMark: Schema.optionalWith<typeof Schema.Number, { nullable: true; }>; readonly PrivateKey: Schema.brand<Schema.refine<string, typeof Schema.String>, "WireguardKey">; readonly Peers: Schema.optionalWith<Schema.Array$<Schema.Struct<{ readonly PersistentKeepalive: Schema.optionalWith<typeof InternetSchemas.DurationFromSeconds, { as: "Option"; nullable: true; }>; readonly AllowedIPs: Schema.optionalWith<Schema.ReadonlySetFromSelf<InternetSchemas.$CidrBlockFromString>, { nullable: true; default: () => Set<never>; }>; readonly Endpoint: Schema.optionalWith<InternetSchemas.$Endpoint, { nullable: true; }>; readonly PublicKey: Schema.brand<Schema.refine<string, typeof Schema.String>, "WireguardKey">; readonly PresharedKey: Schema.optionalWith<Schema.brand<Schema.refine<string, typeof Schema.String>, "WireguardKey">, { nullable: true; as: "Option"; }>; readonly rxBytes: typeof Schema.NumberFromString; readonly txBytes: typeof Schema.NumberFromString; readonly lastHandshake: Schema.transform<Schema.transform<typeof Schema.NumberFromString, Schema.transform<typeof Schema.Number, typeof Schema.Number>>, typeof Schema.DateTimeUtcFromNumber>; }>>, { default: () => never[]; nullable: true; }>; }>; }; export declare class WireguardConfig extends WireguardConfig_base { /** * Writes a wireguard interface configuration to an INI file. * * @since 1.0.0 * @category Constructors * @param file - The path to the INI file. */ writeToFile: { (file: string): Effect.Effect<void, ParseResult.ParseError | PlatformError.PlatformError, FileSystem.FileSystem | Path.Path>; }; /** * Starts a wireguard tunnel that will continue to run and serve traffic * even after the nodejs process exits. * * @since 1.0.0 * @category Wireguard */ up: { (wireguardInterface?: WireguardInterface | undefined): Effect.Effect<WireguardInterface, Socket.SocketError | ParseResult.ParseError | Cause.TimeoutException | PlatformError.PlatformError | WireguardErrors.WireguardError, FileSystem.FileSystem | Path.Path | CommandExecutor.CommandExecutor | WireguardControl.WireguardControl>; }; /** * Starts a wireguard tunnel that will be gracefully shutdown and stop * serving traffic once the scope is closed. * * @since 1.0.0 * @category Wireguard */ upScoped: { (wireguardInterface?: WireguardInterface | undefined): Effect.Effect<WireguardInterface, Socket.SocketError | ParseResult.ParseError | Cause.TimeoutException | PlatformError.PlatformError | WireguardErrors.WireguardError, FileSystem.FileSystem | Path.Path | CommandExecutor.CommandExecutor | WireguardControl.WireguardControl | Scope.Scope>; }; } declare const WireguardIniConfig_base: Schema.transformOrFail<typeof WireguardConfig, typeof Schema.String, never>; export declare class WireguardIniConfig extends WireguardIniConfig_base { } declare const WireguardInterface_base: Schema.Class<WireguardInterface, { /** * Ensures the interface name matches the platform's interface name regex. * These functions need to be fully typed as we are accessing a static * method on this same class and otherwise typescript really complains about * inference. */ Name: Schema.transformOrFail<typeof Schema.String, typeof Schema.String, never>; }, Schema.Struct.Encoded<{ /** * Ensures the interface name matches the platform's interface name regex. * These functions need to be fully typed as we are accessing a static * method on this same class and otherwise typescript really complains about * inference. */ Name: Schema.transformOrFail<typeof Schema.String, typeof Schema.String, never>; }>, never, { readonly Name: string; }, {}, {}>; /** * A wireguard interface name. * * @since 1.0.0 * @category Datatypes */ export declare class WireguardInterface extends WireguardInterface_base { /** * @since 1.0.0 * @category Constructors */ static getNextAvailableInterface: Effect.Effect<WireguardInterface, WireguardErrors.WireguardError, never>; static InterfaceRegExpForPlatform: Effect.Effect<RegExp, WireguardErrors.WireguardError, never>; /** * @since 1.0.0 * @category Userspace api */ readonly SocketLocation: string; /** * Starts a wireguard tunnel that will be gracefully shutdown and stop * serving traffic once the scope is closed. * * @since 1.0.0 * @category Wireguard control */ upScoped: { (config: WireguardConfig): Effect.Effect<WireguardInterface, Socket.SocketError | ParseResult.ParseError | PlatformError.PlatformError | Cause.TimeoutException, FileSystem.FileSystem | Path.Path | Scope.Scope | CommandExecutor.CommandExecutor | WireguardControl.WireguardControl>; }; /** * Starts a wireguard tunnel that will continue to run and serve traffic * even after the nodejs process exits. * * @since 1.0.0 * @category Wireguard control */ up: { (config: WireguardConfig): Effect.Effect<WireguardInterface, Socket.SocketError | ParseResult.ParseError | PlatformError.PlatformError | Cause.TimeoutException, FileSystem.FileSystem | Path.Path | CommandExecutor.CommandExecutor | WireguardControl.WireguardControl>; }; /** * Stops a previously started wireguard tunnel. * * @since 1.0.0 * @category Wireguard control */ down: { (config: WireguardConfig): Effect.Effect<WireguardInterface, PlatformError.PlatformError | ParseResult.ParseError | Cause.TimeoutException, FileSystem.FileSystem | Path.Path | CommandExecutor.CommandExecutor | WireguardControl.WireguardControl>; }; /** * Sets the config for this wireguard interface. * * @since 1.0.0 * @category Wireguard control */ setConfig: { (wireguardConfig: WireguardConfig): Effect.Effect<WireguardInterface, Socket.SocketError | ParseResult.ParseError, never>; }; /** * Retrieves the config from this wireguard interface. * * @since 1.0.0 */ getConfig: { (address: InternetSchemas.CidrBlockFromStringEncoded): Effect.Effect<Schema.Schema.Type<(typeof WireguardConfig)["uapi"]>, Socket.SocketError | ParseResult.ParseError, never>; }; /** * Adds a peer to this interface. * * @since 1.0.0 * @category Wireguard control */ addPeer: { (peer: WireguardPeer.WireguardPeer): Effect.Effect<void, Socket.SocketError | ParseResult.ParseError, never>; }; /** * Removes a peer from this interface. * * @since 1.0.0 * @category Wireguard control */ removePeer: { (peer: WireguardPeer.WireguardPeer): Effect.Effect<void, Socket.SocketError | ParseResult.ParseError, never>; }; /** * Streams the stats from all the peers on this interface. * * @since 1.0.0 * @category Wireguard control */ streamPeerStats: { (): Stream.Stream<ReadonlyArray<Schema.Schema.Type<(typeof WireguardPeer.WireguardPeer)["uapi"]>>, Socket.SocketError | ParseResult.ParseError, never>; }; } export {}; //# sourceMappingURL=circular.d.ts.map