0.12.3 • Published 5 months ago

@e-mc/request v0.12.3

Weekly downloads
-
License
BSD-3-Clause
Repository
github
Last release
5 months ago

@e-mc/request

  • NodeJS 18
  • ES2022

General Usage

Interface

import type { IModule, ModuleConstructor } from "./index";
import type { HttpAgentSettings, HttpProtocolVersion, HttpRequestClient, InternetProtocolVersion } from "./http";
import type { ApplyOptions, Aria2Options, FormDataPart, HeadersOnCallback, HostConfig, IHttpAdapter, OpenOptions, PostOptions, ProxySettings, PutOptions, RcloneOptions, ReadExpectType, RequestInit, StatusOnCallback } from "./request";
import type { DnsLookupSettings, RequestModule, RequestSettings } from "./settings";

import type { ClientRequest, OutgoingHttpHeaders } from "node:http";
import type { LookupFunction } from "node:net";
import type { Writable } from "node:stream";

interface IRequest extends IModule {
    module: RequestModule;
    startTime: number;
    acceptEncoding: boolean;
    keepAlive: boolean | null;
    readTimeout: number;
    readExpect: ReadExpectType;
    proxy: ProxySettings | null;
    init(config?: RequestInit): this;
    apply(options: ApplyOptions): this;
    addDns(hostname: string, address: string, timeout: number): void;
    addDns(hostname: string, address: string, family?: string, timeout?: number): void;
    lookupDns(hostname: string): LookupFunction;
    proxyOf(uri: string, localhost?: boolean): ProxySettings | undefined;
    statusOn(name: number | number[], callback: StatusOnCallback): void;
    statusOn(name: number | number[], globUrl: string, callback: StatusOnCallback): void;
    headersOn(name: string | string[], callback: HeadersOnCallback): void;
    headersOn(name: string | string[], globUrl: string, callback: HeadersOnCallback): void;
    headersOf(uri: string): OutgoingHttpHeaders | undefined;
    aria2c(uri: string | URL, pathname: string): Promise<string[]>;
    aria2c(uri: string | URL, options?: Aria2Options): Promise<string[]>;
    rclone(uri: string | URL, pathname: string): Promise<string[]>;
    rclone(uri: string | URL, options?: RcloneOptions): Promise<string[]>;
    json(uri: string | URL, options?: OpenOptions): Promise<object | null>;
    pipe(uri: string | URL, to: Writable, options?: OpenOptions): Promise<null>;
    opts(url: string | URL, options?: OpenOptions): HostConfig;
    open(uri: string | URL, options: OpenOptions): HttpRequestClient;
    head(uri: string | URL, options?: OpenOptions): ClientRequest;
    put(uri: string | URL, data: unknown, options: PutOptions): Promise<Buffer | string | null>;
    put(uri: string | URL, data: unknown, contentType?: string, options?: PutOptions): Promise<Buffer | string | null>;
    post(uri: string | URL, parts: FormDataPart[]): Promise<Buffer | string | null>;
    post(uri: string | URL, form: Record<string, unknown>, parts: FormDataPart[]): Promise<Buffer | string | null>;
    post(uri: string | URL, data: unknown, options: PostOptions): Promise<Buffer | string | null>;
    post(uri: string | URL, data: unknown, contentType?: string, options?: PostOptions): Promise<Buffer | string | null>;
    get(uri: string | URL, options?: OpenOptions): Promise<Buffer | object | string | null>;
    detach(singleton?: boolean): void;
    reset(adapter?: IHttpAdapter): void;
    close(): void;
    set adapter(value: unknown);
    set agentTimeout(value);
    get agentTimeout(): number;
    set httpVersion(value);
    get httpVersion(): HttpProtocolVersion | null;
    set ipVersion(value);
    get ipVersion(): InternetProtocolVersion;
    get settings(): RequestSettings;
}

interface RequestConstructor extends ModuleConstructor {
    readCACert(value: string, cache?: boolean): string;
    readTLSKey(value: string, cache?: boolean): string;
    readTLSCert(value: string, cache?: boolean): string;
    isCert(value: string): boolean;
    /** @deprecated @e-mc/request/util */
    fromURL(url: URL, value: string): string;
    /** @deprecated @e-mc/request/util */
    fromStatusCode(value: number | string): string;
    defineHttpAgent(options: HttpAgentSettings): void;
    defineDnsLookup(options: DnsLookupSettings, clear?: boolean): void;
    defineHttpAdapter(module: unknown): void;
    isRclone(value: string | URL): boolean;
    getAria2Path(): string;
    getRclonePath(): string;
    readonly prototype: IRequest;
    new(module?: RequestModule): IRequest;
}

Settings

import type { PermittedDirectories } from "./core";
import type { SecureConfig } from "./http";
import type { PurgeComponent } from "./settings";

import type { LookupAddress } from "dns";
import type { OutgoingHttpHeaders } from "http";

interface RequestModule {
    handler: "@e-mc/request";
    timeout?: number | string;
    read_timeout?: number | string;
    agent?: {
        keep_alive?: boolean;
        timeout?: number | string;
    };
    connect?: {
        timeout?: number | string;
        retry_wait?: number | string;
        retry_after?: number | string;
        retry_limit?: number;
        redirect_limit?: number;
    };
    dns?: {
        family?: number;
        expires?: number | string;
        resolve?: Record<string, Partial<LookupAddress>>;
    };
    use?: {
        http_version?: 1 | 2;
        accept_encoding?: boolean;
    };
    proxy?: {
        address?: string;
        port?: number;
        origin?: string;
        username?: string;
        password?: string;
        include?: string[];
        exclude?: string[];
        keep_alive?: boolean;
    };
    headers: Record<string, OutgoingHttpHeaders>;
    certs?: Record<string, SecureConfig<string | string[]>>;
    localhost?: string[];
    protocol?: {
        "http/1.1"?: string[];
        h2c?: string[];
        h2?: string[];
    };
    write_stream?: Record<string, number | string>;
    post_limit?: number | string;
    settings?: {
        broadcast_id?: string | string[];
        time_format?: "readable" | "relative" | "none";
        purge?: PurgeComponent;
    }
}

interface DownloadModule {
    expires?: number | string;
    aria2?: {
        bin?: string | false;
        exec?: {
            uid?: number;
            gid?: number;
        };
        update_status?: number | { interval?: number; broadcast_only?: boolean };
        max_concurrent_downloads?: number;
        max_connection_per_server?: number;
        check_integrity?: boolean;
        bt_stop_timeout?: number;
        bt_tracker_connect_timeout?: number;
        bt_tracker_timeout?: number;
        min_split_size?: string;
        disk_cache?: number | string;
        lowest_speed_limit?: number | string;
        always_resume?: boolean;
        file_allocation?: "none" | "prealloc" | "trunc" | "falloc";
        conf_path?: string;
    };
    rclone?: {
        bin?: string | false;
        exec?: {
            uid?: number;
            gid?: number;
        };
        /* Copy */
        check_first?: boolean;
        checksum?: boolean;
        cutoff_mode?: "HARD" | "SOFT" | "CAUTIOUS";
        ignore_case_sync?: boolean;
        ignore_checksum?: boolean;
        ignore_existing?: boolean;
        ignore_size?: boolean;
        ignore_times?: boolean;
        immutable?: boolean;
        inplace?: boolean;
        max_backlog?: number;
        max_duration?: string;
        max_transfer?: string;
        metadata?: boolean;
        modify_window?: string;
        multi_thread_chunk_size?: string;
        multi_thread_cutoff?: string;
        multi_thread_streams?: number;
        multi_thread_write_buffer_size?: string;
        no_check_dest?: boolean;
        no_traverse?: boolean;
        no_update_dir_modtime?: boolean;
        refresh_times?: boolean;
        size_only?: boolean;
        update?: boolean;
        /* Listing */
        fast_list?: boolean;
        /* Networking */
        bind?: string;
        contimeout?: string;
        disable_http2?: boolean;
        timeout?: string;
        /* Config */
        config?: string;
    };
}

Example usage

const Request = require("@e-mc/request");

const instance = new Request({
    read_timeout: 30,
    connect: {
        timeout: 20, // Seconds
        retry_wait: 1,
        retry_after: 30,
        retry_limit: 3, // Max attempts
        redirect_limit: 10
    },
    use: {
        http_version: 2,
        accept_encoding: true
    },
    dns: {
        family: 4 // ipVersion
    },
    agent: { keep_alive: true }
});
request.init({ ipVersion: 6 });

const options = {
    format: "yaml",
    httpVersion: 1,
    silent: true,
    headers: { "x-goog-user-project": "project-1" }
};
instance.get("http://hostname/path/config.yml", options).then(data => {
    console.log(data.property);
});

References

LICENSE

BSD 3-Clause

0.5.18

6 months ago

0.5.19

6 months ago

0.5.17

7 months ago

0.7.22

5 months ago

0.7.21

6 months ago

0.7.20

6 months ago

0.7.19

7 months ago

0.7.18

9 months ago

0.10.9

6 months ago

0.10.4

10 months ago

0.10.5

10 months ago

0.10.6

10 months ago

0.10.7

9 months ago

0.10.8

7 months ago

0.9.20

5 months ago

0.9.14

10 months ago

0.9.15

10 months ago

0.9.16

9 months ago

0.9.17

7 months ago

0.9.18

6 months ago

0.9.19

6 months ago

0.11.8

6 months ago

0.11.0

10 months ago

0.11.1

10 months ago

0.11.2

9 months ago

0.11.3

7 months ago

0.10.10

6 months ago

0.11.4

6 months ago

0.10.11

6 months ago

0.11.5

6 months ago

0.10.12

5 months ago

0.11.7

6 months ago

0.6.18

5 months ago

0.6.17

6 months ago

0.6.16

6 months ago

0.6.15

7 months ago

0.8.23

7 months ago

0.8.22

9 months ago

0.8.25

6 months ago

0.8.24

6 months ago

0.8.26

5 months ago

0.12.0

5 months ago

0.12.1

5 months ago

0.12.2

5 months ago

0.12.3

5 months ago

0.5.20

5 months ago

0.5.10

1 year ago

0.5.11

1 year ago

0.5.16

12 months ago

0.5.14

1 year ago

0.5.15

12 months ago

0.5.12

1 year ago

0.5.13

1 year ago

0.9.8

1 year ago

0.7.11

1 year ago

0.9.7

1 year ago

0.7.10

1 year ago

0.7.13

1 year ago

0.9.9

1 year ago

0.7.12

1 year ago

0.9.4

1 year ago

0.5.8

1 year ago

0.9.3

1 year ago

0.5.7

1 year ago

0.9.6

1 year ago

0.5.9

1 year ago

0.9.5

1 year ago

0.7.15

1 year ago

0.7.14

1 year ago

0.7.17

12 months ago

0.7.16

12 months ago

0.10.1

1 year ago

0.10.2

1 year ago

0.10.3

12 months ago

0.10.0

1 year ago

0.9.12

12 months ago

0.9.13

12 months ago

0.6.7

1 year ago

0.6.6

1 year ago

0.9.10

1 year ago

0.6.9

1 year ago

0.9.11

1 year ago

0.6.8

1 year ago

0.6.10

1 year ago

0.6.12

1 year ago

0.6.11

1 year ago

0.6.14

12 months ago

0.6.13

12 months ago

0.9.2

1 year ago

0.7.9

1 year ago

0.8.21

12 months ago

0.7.8

1 year ago

0.8.20

12 months ago

0.7.7

1 year ago

0.8.12

1 year ago

0.8.11

1 year ago

0.8.14

1 year ago

0.8.13

1 year ago

0.8.19

1 year ago

0.8.16

1 year ago

0.8.15

1 year ago

0.8.18

1 year ago

0.8.17

1 year ago

0.6.5

1 year ago

0.6.4

1 year ago

0.8.9

1 year ago

0.8.8

1 year ago

0.7.6

1 year ago

0.7.5

1 year ago

0.8.10

1 year ago

0.6.3

1 year ago

0.7.4

1 year ago

0.5.6

1 year ago

0.9.1

1 year ago

0.9.0

1 year ago

0.8.7

2 years ago

0.6.2

2 years ago

0.7.3

2 years ago

0.5.5

2 years ago

0.8.6

2 years ago

0.7.2

2 years ago

0.5.4

2 years ago

0.6.1

2 years ago

0.8.5

2 years ago

0.8.4

2 years ago

0.8.3

2 years ago

0.8.2

2 years ago

0.8.1

2 years ago

0.8.0

2 years ago

0.7.1

2 years ago

0.7.0

2 years ago

0.6.0

2 years ago

0.5.3

2 years ago

0.5.2

2 years ago

0.5.1

2 years ago

0.5.0

2 years ago

0.4.2

2 years ago

0.4.1

2 years ago

0.4.0

3 years ago

0.3.3

3 years ago

0.3.2

3 years ago

0.3.1

3 years ago

0.3.0

3 years ago

0.2.0

3 years ago

0.1.0

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago