Memco

Interface MemcoOptions

Settings for a Memco, every one of them optional.

An argument always wins over the environment, and the environment over the built-in default. The credential is either a token or an API client's clientId and clientSecret: token reads MEMCO_API_TOKEN — falling back to the deprecated MEMCO_API_KEY, which warns — and the pair reads MEMCO_CLIENT_ID and MEMCO_CLIENT_SECRET, which win over MEMCO_API_TOKEN when both are set and no credential is passed. host reads MEMCO_API_HOST, tls reads MEMCO_API_TLS — TLS stays on unless one of them turns it off — and logLevel reads MEMCO_LOG. The rest have no variable: timeout defaults to DEFAULT_TIMEOUT seconds, the deadline every call inherits, and tokenLifetime to the service's own. The credential is the one connection setting with no default at all: a client that finds none is refused rather than left to fail on its first call.

All of it is resolved by the constructor, before a socket is opened, so a blank host, an unparseable port, half a client pair or a timeout that is not a positive number is a MemcoConfigError out of new Memco(...) rather than a transport failure later on.

MemcoOptions.logLevel is the odd one out: everything else here configures this client, and that configures the process.

interface MemcoOptions {
    logLevel?: string;
    token?: string;
    clientId?: string;
    clientSecret?: string;
    tokenLifetime?: number;
    host?: string;
    tls?: boolean;
    timeout?: number;
    env?: Readonly<Record<string, string | undefined>>;
}

Hierarchy

  • ResolveOptions
    • MemcoOptions
Index
logLevel?: string

Log level to apply before anything else happens, one of critical, error, warning, info, debug, or none to silence the SDK.

Setting it is process-wide, because a logger is. Prefer the MEMCO_LOG environment variable in an application that has its own logging: it says the same thing without a library reaching into global state on the application's behalf.

MemcoConfigError If it does not name a level. A bad MEMCO_LOG warns and falls back; a bad argument here is the caller's own code.

token?: string

Credential to authenticate with: a Memco API key or a session token. When omitted, and the environment holds no client credentials, MEMCO_API_TOKEN is used, falling back to the deprecated MEMCO_API_KEY with a warning. A blank value is refused rather than treated as absent. Passing it with ResolveOptions.clientId or ResolveOptions.clientSecret is refused.

clientId?: string

An API client's id, passed with ResolveOptions.clientSecret instead of a token. The client exchanges the two for a token and renews it before it expires. When neither they nor a token is passed, and both MEMCO_CLIENT_ID and MEMCO_CLIENT_SECRET are set, those are used — even if MEMCO_API_TOKEN is set too.

clientSecret?: string

The API client's secret, passed with ResolveOptions.clientId. It is sent only to exchange for a token, and never logged.

tokenLifetime?: number

Lifetime in seconds to ask for on each token issued for the client credentials. Omitted, the service's default applies. The service owns the maximum, and refuses a longer lifetime itself.

host?: string

Service endpoint, optionally including a port such as localhost:50051 or [2001:db8::1]:50051. When omitted, MEMCO_API_HOST is used, falling back to DEFAULT_HOST. A host without a port gets DEFAULT_PORT. A blank value is refused rather than treated as absent.

tls?: boolean

Whether to dial over TLS with the system trust store. Set to false only for a plaintext endpoint, such as a local server. When omitted, MEMCO_API_TLS decides — true or false — falling back to true.

timeout?: number

Default per-call deadline in seconds.

env?: Readonly<Record<string, string | undefined>>

Environment to read from. Defaults to process.env; supplying one is mainly useful in tests.

On this page