import type { RequestInit, RequestInfo } from "./internal/builtin-types.js"; import type { PromiseOrValue, MergedRequestInit, FinalizedRequestInit } from "./internal/types.js"; export type { Logger, LogLevel } from "./internal/utils/log.js"; import * as Opts from "./internal/request-options.js"; import * as Errors from "./core/error.js"; import * as Pagination from "./core/pagination.js"; import { type EntriesCursorParams, EntriesCursorResponse, type ItemsCursorParams, ItemsCursorResponse, type MsTeamsPaginationParams, MsTeamsPaginationResponse, type SlackChannelsCursorParams, SlackChannelsCursorResponse } from "./core/pagination.js"; import * as Uploads from "./core/uploads.js"; import * as API from "./resources/index.js"; import { APIPromise } from "./core/api-promise.js"; import { AudienceAddMembersParams, AudienceAddMembersResponse, AudienceListMembersResponse, AudienceMember, AudienceRemoveMembersParams, AudienceRemoveMembersResponse, Audiences } from "./resources/audiences.js"; import { BulkOperation, BulkOperations } from "./resources/bulk-operations.js"; import { Condition, PageInfo, Shared } from "./resources/shared.js"; import { WorkflowCancelParams, WorkflowCancelResponse, WorkflowTriggerParams, WorkflowTriggerResponse, Workflows } from "./resources/workflows.js"; import { Channels } from "./resources/channels/channels.js"; import { Integrations } from "./resources/integrations/integrations.js"; import { ActivitiesItemsCursor, Activity, Message, MessageDeliveryLog, MessageDeliveryLogsItemsCursor, MessageEvent, MessageEventsItemsCursor, MessageGetContentResponse, MessageListActivitiesParams, MessageListDeliveryLogsParams, MessageListEventsParams, MessageListParams, MessageMarkAsInteractedParams, Messages, MessagesItemsCursor } from "./resources/messages/messages.js"; import { InlineObjectRequest, Object, ObjectAddSubscriptionsParams, ObjectAddSubscriptionsResponse, ObjectDeleteResponse, ObjectDeleteSubscriptionsParams, ObjectDeleteSubscriptionsResponse, ObjectListMessagesParams, ObjectListParams, ObjectListPreferencesResponse, ObjectListSchedulesParams, ObjectListSubscriptionsParams, ObjectSetChannelDataParams, ObjectSetParams, ObjectSetPreferencesParams, ObjectUnsetChannelDataResponse, Objects, ObjectsEntriesCursor } from "./resources/objects/objects.js"; import { Providers } from "./resources/providers/providers.js"; import { Recipient, RecipientReference, RecipientRequest, Recipients } from "./resources/recipients/recipients.js"; import { Schedule, ScheduleCreateParams, ScheduleCreateResponse, ScheduleDeleteParams, ScheduleDeleteResponse, ScheduleListParams, ScheduleRepeatRule, ScheduleUpdateParams, ScheduleUpdateResponse, Schedules, SchedulesEntriesCursor } from "./resources/schedules/schedules.js"; import { InlineTenantRequest, Tenant, TenantDeleteResponse, TenantListParams, TenantRequest, TenantSetParams, Tenants, TenantsEntriesCursor } from "./resources/tenants/tenants.js"; import { IdentifyUserRequest, InlineIdentifyUserRequest, User, UserDeleteResponse, UserGetPreferencesParams, UserListMessagesParams, UserListParams, UserListPreferencesResponse, UserListSchedulesParams, UserListSubscriptionsParams, UserMergeParams, UserSetChannelDataParams, UserSetPreferencesParams, UserUnsetChannelDataResponse, UserUpdateParams, Users, UsersEntriesCursor } from "./resources/users/users.js"; import { type Fetch } from "./internal/builtin-types.js"; import { HeadersLike, NullableHeaders } from "./internal/headers.js"; import { FinalRequestOptions, RequestOptions } from "./internal/request-options.js"; import { type LogLevel, type Logger } from "./internal/utils/log.js"; export interface ClientOptions { /** * Defaults to process.env['KNOCK_API_KEY']. */ apiKey?: string | undefined; /** * Override the default base URL for the API, e.g., "https://api.example.com/v2/" * * Defaults to process.env['KNOCK_BASE_URL']. */ baseURL?: string | null | undefined; /** * The maximum amount of time (in milliseconds) that the client should wait for a response * from the server before timing out a single request. * * Note that request timeouts are retried by default, so in a worst-case scenario you may wait * much longer than this timeout before the promise succeeds or fails. */ timeout?: number | undefined; /** * Additional `RequestInit` options to be passed to `fetch` calls. * Properties will be overridden by per-request `fetchOptions`. */ fetchOptions?: MergedRequestInit | undefined; /** * Specify a custom `fetch` function implementation. * * If not provided, we expect that `fetch` is defined globally. */ fetch?: Fetch | undefined; /** * The maximum number of times that the client will retry a request in case of a * temporary failure, like a network error or a 5XX error from the server. * * @default 2 */ maxRetries?: number | undefined; /** * Default headers to include with every request to the API. * * These can be removed in individual requests by explicitly setting the * header to `null` in request options. */ defaultHeaders?: HeadersLike | undefined; /** * Default query parameters to include with every request to the API. * * These can be removed in individual requests by explicitly setting the * param to `undefined` in request options. */ defaultQuery?: Record | undefined; /** * Set the log level. * * Defaults to process.env['KNOCK_LOG'] or 'warn' if it isn't set. */ logLevel?: LogLevel | undefined; /** * Set the logger. * * Defaults to globalThis.console. */ logger?: Logger | undefined; } /** * API Client for interfacing with the Knock API. */ export declare class Knock { #private; apiKey: string; baseURL: string; maxRetries: number; timeout: number; logger: Logger | undefined; logLevel: LogLevel | undefined; fetchOptions: MergedRequestInit | undefined; private fetch; protected idempotencyHeader?: string; private _options; /** * API Client for interfacing with the Knock API. * * @param {string | undefined} [opts.apiKey=process.env['KNOCK_API_KEY'] ?? undefined] * @param {string} [opts.baseURL=process.env['KNOCK_BASE_URL'] ?? https://api.knock.app] - Override the default base URL for the API. * @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out. * @param {MergedRequestInit} [opts.fetchOptions] - Additional `RequestInit` options to be passed to `fetch` calls. * @param {Fetch} [opts.fetch] - Specify a custom `fetch` function implementation. * @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request. * @param {HeadersLike} opts.defaultHeaders - Default headers to include with every request to the API. * @param {Record} opts.defaultQuery - Default query parameters to include with every request to the API. */ constructor({ baseURL, apiKey, ...opts }?: ClientOptions); /** * Create a new client instance re-using the same options given to the current client with optional overriding. */ withOptions(options: Partial): this; protected defaultQuery(): Record | undefined; protected validateHeaders({ values, nulls }: NullableHeaders): void; protected authHeaders(opts: FinalRequestOptions): NullableHeaders | undefined; protected stringifyQuery(query: Record): string; private getUserAgent; protected defaultIdempotencyKey(): string; protected makeStatusError(status: number, error: Object, message: string | undefined, headers: Headers): Errors.APIError; buildURL(path: string, query: Record | null | undefined, defaultBaseURL?: string | undefined): string; /** * Used as a callback for mutating the given `FinalRequestOptions` object. */ protected prepareOptions(options: FinalRequestOptions): Promise; /** * Used as a callback for mutating the given `RequestInit` object. * * This is useful for cases where you want to add certain headers based off of * the request properties, e.g. `method` or `url`. */ protected prepareRequest(request: RequestInit, { url, options }: { url: string; options: FinalRequestOptions; }): Promise; get(path: string, opts?: PromiseOrValue): APIPromise; post(path: string, opts?: PromiseOrValue): APIPromise; patch(path: string, opts?: PromiseOrValue): APIPromise; put(path: string, opts?: PromiseOrValue): APIPromise; delete(path: string, opts?: PromiseOrValue): APIPromise; private methodRequest; request(options: PromiseOrValue, remainingRetries?: number | null): APIPromise; private makeRequest; getAPIList = Pagination.AbstractPage>(path: string, Page: new (...args: any[]) => PageClass, opts?: RequestOptions): Pagination.PagePromise; requestAPIList = Pagination.AbstractPage>(Page: new (...args: ConstructorParameters) => PageClass, options: FinalRequestOptions): Pagination.PagePromise; fetchWithTimeout(url: RequestInfo, init: RequestInit | undefined, ms: number, controller: AbortController): Promise; private shouldRetry; private retryRequest; private calculateDefaultRetryTimeoutMillis; buildRequest(inputOptions: FinalRequestOptions, { retryCount }?: { retryCount?: number; }): { req: FinalizedRequestInit; url: string; timeout: number; }; private buildHeaders; private buildBody; static Knock: typeof Knock; static DEFAULT_TIMEOUT: number; static KnockError: typeof Errors.KnockError; static APIError: typeof Errors.APIError; static APIConnectionError: typeof Errors.APIConnectionError; static APIConnectionTimeoutError: typeof Errors.APIConnectionTimeoutError; static APIUserAbortError: typeof Errors.APIUserAbortError; static NotFoundError: typeof Errors.NotFoundError; static ConflictError: typeof Errors.ConflictError; static RateLimitError: typeof Errors.RateLimitError; static BadRequestError: typeof Errors.BadRequestError; static AuthenticationError: typeof Errors.AuthenticationError; static InternalServerError: typeof Errors.InternalServerError; static PermissionDeniedError: typeof Errors.PermissionDeniedError; static UnprocessableEntityError: typeof Errors.UnprocessableEntityError; static toFile: typeof Uploads.toFile; shared: API.Shared; recipients: API.Recipients; users: API.Users; objects: API.Objects; tenants: API.Tenants; bulkOperations: API.BulkOperations; messages: API.Messages; providers: API.Providers; integrations: API.Integrations; workflows: API.Workflows; schedules: API.Schedules; channels: API.Channels; audiences: API.Audiences; } export declare namespace Knock { export type RequestOptions = Opts.RequestOptions; export import EntriesCursor = Pagination.EntriesCursor; export { type EntriesCursorParams as EntriesCursorParams, type EntriesCursorResponse as EntriesCursorResponse, }; export import ItemsCursor = Pagination.ItemsCursor; export { type ItemsCursorParams as ItemsCursorParams, type ItemsCursorResponse as ItemsCursorResponse }; export import SlackChannelsCursor = Pagination.SlackChannelsCursor; export { type SlackChannelsCursorParams as SlackChannelsCursorParams, type SlackChannelsCursorResponse as SlackChannelsCursorResponse, }; export import MsTeamsPagination = Pagination.MsTeamsPagination; export { type MsTeamsPaginationParams as MsTeamsPaginationParams, type MsTeamsPaginationResponse as MsTeamsPaginationResponse, }; export { Shared as Shared, type Condition as Condition, type PageInfo as PageInfo }; export { Recipients as Recipients, type Recipient as Recipient, type RecipientReference as RecipientReference, type RecipientRequest as RecipientRequest, }; export { Users as Users, type IdentifyUserRequest as IdentifyUserRequest, type InlineIdentifyUserRequest as InlineIdentifyUserRequest, type User as User, type UserDeleteResponse as UserDeleteResponse, type UserListPreferencesResponse as UserListPreferencesResponse, type UserUnsetChannelDataResponse as UserUnsetChannelDataResponse, type UsersEntriesCursor as UsersEntriesCursor, type UserUpdateParams as UserUpdateParams, type UserListParams as UserListParams, type UserGetPreferencesParams as UserGetPreferencesParams, type UserListMessagesParams as UserListMessagesParams, type UserListSchedulesParams as UserListSchedulesParams, type UserListSubscriptionsParams as UserListSubscriptionsParams, type UserMergeParams as UserMergeParams, type UserSetChannelDataParams as UserSetChannelDataParams, type UserSetPreferencesParams as UserSetPreferencesParams, }; export { Objects as Objects, type InlineObjectRequest as InlineObjectRequest, type Object as Object, type ObjectDeleteResponse as ObjectDeleteResponse, type ObjectAddSubscriptionsResponse as ObjectAddSubscriptionsResponse, type ObjectDeleteSubscriptionsResponse as ObjectDeleteSubscriptionsResponse, type ObjectListPreferencesResponse as ObjectListPreferencesResponse, type ObjectUnsetChannelDataResponse as ObjectUnsetChannelDataResponse, type ObjectsEntriesCursor as ObjectsEntriesCursor, type ObjectListParams as ObjectListParams, type ObjectAddSubscriptionsParams as ObjectAddSubscriptionsParams, type ObjectDeleteSubscriptionsParams as ObjectDeleteSubscriptionsParams, type ObjectListMessagesParams as ObjectListMessagesParams, type ObjectListSchedulesParams as ObjectListSchedulesParams, type ObjectListSubscriptionsParams as ObjectListSubscriptionsParams, type ObjectSetParams as ObjectSetParams, type ObjectSetChannelDataParams as ObjectSetChannelDataParams, type ObjectSetPreferencesParams as ObjectSetPreferencesParams, }; export { Tenants as Tenants, type InlineTenantRequest as InlineTenantRequest, type Tenant as Tenant, type TenantRequest as TenantRequest, type TenantDeleteResponse as TenantDeleteResponse, type TenantsEntriesCursor as TenantsEntriesCursor, type TenantListParams as TenantListParams, type TenantSetParams as TenantSetParams, }; export { BulkOperations as BulkOperations, type BulkOperation as BulkOperation }; export { Messages as Messages, type Activity as Activity, type Message as Message, type MessageDeliveryLog as MessageDeliveryLog, type MessageEvent as MessageEvent, type MessageGetContentResponse as MessageGetContentResponse, type MessagesItemsCursor as MessagesItemsCursor, type ActivitiesItemsCursor as ActivitiesItemsCursor, type MessageDeliveryLogsItemsCursor as MessageDeliveryLogsItemsCursor, type MessageEventsItemsCursor as MessageEventsItemsCursor, type MessageListParams as MessageListParams, type MessageListActivitiesParams as MessageListActivitiesParams, type MessageListDeliveryLogsParams as MessageListDeliveryLogsParams, type MessageListEventsParams as MessageListEventsParams, type MessageMarkAsInteractedParams as MessageMarkAsInteractedParams, }; export { Providers as Providers }; export { Integrations as Integrations }; export { Workflows as Workflows, type WorkflowCancelResponse as WorkflowCancelResponse, type WorkflowTriggerResponse as WorkflowTriggerResponse, type WorkflowCancelParams as WorkflowCancelParams, type WorkflowTriggerParams as WorkflowTriggerParams, }; export { Schedules as Schedules, type Schedule as Schedule, type ScheduleRepeatRule as ScheduleRepeatRule, type ScheduleCreateResponse as ScheduleCreateResponse, type ScheduleUpdateResponse as ScheduleUpdateResponse, type ScheduleDeleteResponse as ScheduleDeleteResponse, type SchedulesEntriesCursor as SchedulesEntriesCursor, type ScheduleCreateParams as ScheduleCreateParams, type ScheduleUpdateParams as ScheduleUpdateParams, type ScheduleListParams as ScheduleListParams, type ScheduleDeleteParams as ScheduleDeleteParams, }; export { Channels as Channels }; export { Audiences as Audiences, type AudienceMember as AudienceMember, type AudienceAddMembersResponse as AudienceAddMembersResponse, type AudienceListMembersResponse as AudienceListMembersResponse, type AudienceRemoveMembersResponse as AudienceRemoveMembersResponse, type AudienceAddMembersParams as AudienceAddMembersParams, type AudienceRemoveMembersParams as AudienceRemoveMembersParams, }; } //# sourceMappingURL=client.d.ts.map