NoClick

class NoClick

Connection settings for the platform API. Most code never builds one: the default client reads NOCLICK_API_KEY / NOCLICK_API_URL (inside a deployed app without a key, it signs in as the app with NOCLICK_DEPLOYMENT_TOKEN). Pass { client } to any method to use another account or endpoint.

Attributes
baseUrlstring
timeoutMsnumber
maxRetriesnumber
backoffMsnumber
maxBackoffMsnumber
apiKeystring | ApiKeyProvider | undefined
inAppboolean

Whether this client signs in as a deployed app's own code (its deployment's credential), where fromName resolves names in the app's own namespace for the environment it runs in.

Types
/** Returns the bearer for one attempt; called again on every retry. */
type ApiKeyProvider = () => string | Promise<string>;

forSessionstatic

static forSession(
  session: string | { token: string; baseUrl?: string },
  options?: Omit<ClientOptions, "apiKey">,
): NoClick

A client that authenticates with a user session (a Session or its nk_sess_... token): every call acts for the session's user with its scopes. The same as new NoClick({ apiKey: token }).

Parameters
sessionstring | { token: string; baseUrl?: string }required
options.baseUrlstring

Defaults to NOCLICK_API_URL, then https://api.noclick.com.

options.timeoutMsnumber

Per-attempt request timeout (default 60s).

options.maxRetriesnumber

Retries for 408/429/5xx (never a POST's 500, which is replayed) and network errors (default 3).

options.backoffMsnumber

First backoff step; doubles per attempt with jitter (default 500ms).

options.maxBackoffMsnumber
options.headersRecord<string, string>
options.fetchtypeof fetch

A custom fetch (a proxy agent, a test double). Defaults to the global one.

Returns

A client for that session, on the session's own API endpoint unless you pass base_url.

request

request(method: string, path: string, options?: RequestOptions): Promise<T>

Send one API call and return its decoded body. Writes carry an Idempotency-Key reused on every retry, so a retried POST can't do the work twice.

Parameters
methodstringrequired
pathstringrequired
options.jsonunknown
options.userUserOption

undefined = the ambient user, null = the account.

(defaults to the current user)
options.idempotencyKeystring

Reused on every retry; generated for each write when omitted.

options.bodystring | Uint8Array | ArrayBuffer | Blob

A raw body (bytes or text) instead of json.

options.contentTypestringdefault "application/octet-stream"
options.queryRecord<string, QueryValue>
options.timeoutMsnumber
options.signalAbortSignal
options.responseType"json" | "bytes"

bytes returns a Uint8Array instead of decoded JSON.

Returns

The response's decoded JSON (None for an empty body), or its raw bytes with binary=True. An error response raises its noclick.Error instead.

Types
type QueryValue = string | number | boolean | null | undefined;

/** `undefined` = the ambient user (from `asUser`), `null` = the account itself. */
type UserOption = UserRef | null | undefined;

/** A `User` or your own id for the user. */
type UserRef = string | UserLike;

/** Anything that can name a user lazily (a `User`). */
interface UserLike {
  _userId(): Promise<string>;
}

consoleUrl

consoleUrl(section: string, id: string): string | null

The developer console page for an object (operations?op=, agents/, users/), or null when this client doesn't talk to the hosted API.

Parameters
sectionstringrequired
idstringrequired
Returns

The page's URL, or None when this client doesn't talk to the hosted API.

asUserTypeScript only

asUser(user: UserRef | null, fn: () => T | Promise<T>): Promise<T>

Run fn acting for user; the same as the module-level asUser.

Parameters
userUserRef | nullrequired
fn() => T | Promise<T>required
Types
/** A `User` or your own id for the user. */
type UserRef = string | UserLike;

/** Anything that can name a user lazily (a `User`). */
interface UserLike {
  _userId(): Promise<string>;
}

configure

function configure(options?: ClientOptions): NoClick

Replace the default client, e.g. configure({ apiKey: "nk_live_..." }).

Parameters
options.apiKeystring | ApiKeyProvider

A key, or a function returning one per attempt (a refreshing token). Defaults to NOCLICK_API_KEY (inside a deployed app without a key, its deployment's own credential, NOCLICK_DEPLOYMENT_TOKEN).

options.baseUrlstring

Defaults to NOCLICK_API_URL, then https://api.noclick.com.

options.timeoutMsnumber

Per-attempt request timeout (default 60s).

options.maxRetriesnumber

Retries for 408/429/5xx (never a POST's 500, which is replayed) and network errors (default 3).

options.backoffMsnumber

First backoff step; doubles per attempt with jitter (default 500ms).

options.maxBackoffMsnumber
options.headersRecord<string, string>
options.fetchtypeof fetch

A custom fetch (a proxy agent, a test double). Defaults to the global one.

Returns

The new default client, which every call without client= now uses.

Types
/** Returns the bearer for one attempt; called again on every retry. */
type ApiKeyProvider = () => string | Promise<string>;

defaultClient

function defaultClient(): NoClick

The client used when no { client } is given (built from the environment).

Returns

The shared default client: the one configure last set, else one built from NOCLICK_API_KEY and NOCLICK_API_URL (inside a deployed app without a key, signed in as the app with NOCLICK_DEPLOYMENT_TOKEN).

VERSION

const VERSION: "0.2.2"

This client's version.

DEFAULT_BASE_URL

const DEFAULT_BASE_URL: "https://api.noclick.com"

The hosted API; NOCLICK_API_URL (or base_url=) points a client elsewhere.

CONSOLE_BASE_URL

const CONSOLE_BASE_URL: "https://noclick.com/dashboard/developers"

Where the hosted API's objects are shown (only for the hosted base URL).