import { BaseTraktClient } from './base-trakt-client.js'; import * as _dvcol_common_utils from '@dvcol/common-utils'; import { TraktDeviceAuthentication, TraktClientAuthentication, TraktAuthenticationCodeRequest, TraktAuthenticationRefreshRequest, TraktAuthenticationRevokeRequest, TraktAuthentication, CancellablePolling, TraktAuthenticationApprove } from '../models/trakt-authentication.model.js'; import { TraktClientOptions, ITraktApi, TraktApiResponse } from '../models/trakt-client.model.js'; import '@dvcol/base-http-client'; import '../api/trakt-api.endpoints.js'; import '../models/trakt-stats.model.js'; import '../models/trakt-favorite.model.js'; import '../models/trakt-entity.model.js'; import '@dvcol/common-utils/common/models'; import '../models/trakt-id.model.js'; import '@dvcol/common-utils/http/fetch'; import '../api/trakt-api.filters.js'; import '../trakt-list.model-CeURmxQs.js'; import '../models/trakt-episode.model.js'; import '../models/trakt-image.model.js'; import '../models/trakt-people.model.js'; import '../models/trakt-movie.model.js'; import '../models/trakt-season.model.js'; import '../models/trakt-show.model.js'; import '../models/trakt-sync.model.js'; import '../models/trakt-watchlist.model.js'; import '../models/trakt-rating.model.js'; import '../models/trakt-history.model.js'; import '../models/trakt-watched.model.js'; import '../models/trakt-collection.model.js'; import '../models/trakt-progress.model.js'; import '../models/trakt-search.model.js'; import '../models/trakt-scrobble.model.js'; import '../models/trakt-note.model.js'; import '../models/trakt-like.model.js'; import '../models/trakt-checkin.model.js'; import '../models/trakt-calendar.model.js'; /** * TraktClient is a wrapper around the TraktApi to provide basic authentication and state management. * * @class TraktClient * * @extends {BaseTraktClient} */ declare class TraktClient extends BaseTraktClient { protected polling: ReturnType | undefined; protected poll: TraktDeviceAuthentication | undefined; /** * Indicates if the current environment is a staging environment. */ get isStaging(): boolean; /** * The url to redirect to after the user has authorized the application. */ get redirectUri(): string; /** * Creates an instance of TraktClient, with the necessary endpoints and settings. * @param settings - The settings for the client. * @param authentication - The authentication for the client. * @param api - The API endpoints for the client. */ constructor(settings: TraktClientOptions, authentication?: TraktClientAuthentication, api?: ITraktApi); /** * Exchanges an authorization code or refresh token for an access token. * * @param request - The request object containing the code or refresh token. * * @returns A promise resolving to the updated Trakt authentication information. * * @throws Error Throws an error if the exchange fails or an error is received from the server. * * @see handleError */ protected _exchange(request: Pick | Pick): Promise; /** * Revokes the current authentication by invalidating the access token. * * @paramrequest - Additional parameters for revoking authentication. * * @returns A promise resolving when the authentication is successfully revoked. * * @throws Error Throws an error if no access token is found. * * @see isResponseOk */ protected _revoke(request?: Partial): Promise>; /** * Initiates device authentication and retrieves the device code. * * @template T - The type of the authentication information to be returned (string means auth token, null means codes). * * @param {T extends string | null} code - The device code (if polling) or null to initiate a new device authentication. * * @returns A promise resolving to the authentication information. * * @throws Error Throws an error if the device authentication fails. * * @see handleError */ protected _device(code: T): Promise; protected _clearPolling(): void; protected _clearPoll(): void; /** * Polls the device authentication endpoint to complete the authentication. * If the timeout is reached, the polling is cancelled and an error is thrown. * If the authentication is successful, the polling is cancelled and the authentication information is returned. * * @param poll - The device authentication information. * @param timeout - The timeout in milliseconds. * * @returns A promise resolving to the authentication information if successful */ protected _devicePolling(poll: TraktDeviceAuthentication, timeout: number): Promise; /** * Gets the device code for initiating device authentication. * * The code should then be used in conjunction with the {@link pollWithDeviceCode} method to finish authentication. * * @returns A promise resolving to the device authentication information. */ getDeviceCode(): Promise; /** * Initiates polling with the code obtained by {@link getDeviceCode} to complete device authentication. * * @param poll - The device authentication information. * * @returns A promise resolving to the completed authentication information or `undefined`. */ pollWithDeviceCode(poll?: TraktDeviceAuthentication): CancellablePolling; /** * Initiates the OAuth process by generating a URL to the Trakt website. * Users will be prompted to sign in and authorize the application. * * Once redirected back to the application, the code should be exchanged for an access token using {@link exchangeCodeForToken}. * * @param redirect - The type of redirect to use (defaults to manual). * @param redirect_uri - The URL to redirect to after the user has authorized the application (defaults to client settings). * @param request - Additional parameters for the authorization request. * @returns A promise resolving to the response from the Trakt website. * * @see [authorize]{@link https://trakt.docs.apiary.io/#reference/authentication-oauth/authorize} */ redirectToAuthentication({ redirect, redirect_uri, ...request }?: TraktAuthenticationApprove): _dvcol_common_utils.CancellablePromise>; /** * Initiates the OAuth process by generating a URL to the Trakt website. * Users will be prompted to sign in and authorize the application. * * Once redirected back to the application, the code should be exchanged for an access token using {@link exchangeCodeForToken}. * * @param redirect_uri - The URL to redirect to after the user has authorized the application (defaults to client settings). * @param request - Additional parameters for the authorization request. * @returns A promise resolving to the url to authorize the application. * * @see [authorize]{@link https://trakt.docs.apiary.io/#reference/authentication-oauth/authorize} */ redirectToAuthenticationUrl({ redirect_uri, ...request }?: Omit): string; /** * Exchanges the authorization code obtained after the user has authorized the application with {@link redirectToAuthentication}. * * @param code - The authorization code obtained from the user. * @param state - The optional CSRF token to verify the state. * * @returns A promise resolving to the Trakt authentication information. * * @throws Error Throws an error if the CSRF token is invalid. */ exchangeCodeForToken(code: string, state?: string): Promise; /** * Refreshes the access token using the refresh token. * * @returns A promise resolving to the updated Trakt authentication information. * * @throws Error Throws an error if no refresh token is found. */ refreshToken(refresh_token?: string): Promise; /** * Revokes the current authentication by invalidating the access token. * * @returns A promise resolving when the authentication is successfully revoked. * * @throws Error Throws an error if no access token is found. */ revokeAuthentication(): Promise; /** * Imports the provided Trakt authentication information into the client. * If the access token is expired, it attempts to refresh it. * * @param auth - The Trakt authentication information to import. * * @returns A promise resolving to the imported Trakt authentication information. */ importAuthentication(auth?: TraktClientAuthentication): Promise; } export { TraktClient };