/** * A simple typed description of the RTM api surface. This interface * is the source of truth that is used to type check the rest of the SDK * * @public */ declare interface ApiMethods { "rtm.test.login": { requestArgs: Record; responseArgs: { user: { /** * The id of the user */ id: string; /** * The username of the user */ username: string; }; } & Record; }; "rtm.test.echo": { requestArgs: Record; responseArgs: { method: string; } & Record; }; "rtm.auth.checkToken": { requestArgs: { /** * The auth token to check */ auth_token: string; }; responseArgs: { auth: { token: string; perms: string; user: User; }; }; }; "rtm.auth.getToken": { requestArgs: { frob: string; }; responseArgs: { auth: { token: string; perms: string; user: User; }; }; }; "rtm.auth.getFrob": { requestArgs: Record; responseArgs: { frob: string; }; }; "rtm.tasks.getList": { requestArgs: { list_id?: string; filter?: string; last_sync?: string; callback?: string; }; responseArgs: { tasks: { list: TaskList[]; }; }; }; } /** * Authentication methods * * @public */ export declare interface Auth { /** * Returns the credentials attached to an authentication token. * * @see {@link https://www.rememberthemilk.com/services/api/methods/rtm.auth.checkToken.rtm|RTM Api Documentation} for more information * * @returns {@link SuccessResponse} * @throws {@link RtmApiFailedResponseError} if the API responds with a failure * @throws {@link RtmHttpError} if the API responds with a non 200 response */ checkToken: (args: CheckTokenParams) => Promise["rsp"]>; /** * Returns the auth token for the given frob, if one has been attached. * * @see {@link https://www.rememberthemilk.com/services/api/methods/rtm.auth.getToken.rtm|RTM Api Documentation} for more information * * @param param - Paramaters to be supplied with this method call * @returns {@link SuccessResponse} * @throws {@link RtmApiFailedResponseError} if the API responds with a failure * @throws {@link RtmHttpError} if the API responds with a non 200 response */ getToken: (args: GetTokenParams) => Promise["rsp"]>; /** * * Returns a frob for use during authentication * * @see {@link https://www.rememberthemilk.com/services/api/methods/rtm.auth.getFrob.rtm|RTM Api Documentation} for more information * * @returns Remember the milk API response * @throws {@link RtmApiFailedResponseError} if the API responds with a failure * @throws {@link RtmHttpError} if the API responds with a non 200 response */ getFrob: () => Promise["rsp"]>; } /** * Parameters that can be passed with rtm.auth.checkToken * * @public */ export declare interface CheckTokenParams { /** * The authentication token to check */ auth_token: string; } /** * The Remember The Milk API has 3 permission levels. * A permission level is usually requested during the authentication process with the perms parameter. * * @public */ export declare enum ClientPermissions { /** * Gives the ability to read task, contact, group and list details and contents. */ Read = "read", /** * Gives the ability to add and modify task, contact, group and list details and contents (also allows you to read). */ Write = "write", /** * Gives the ability to delete tasks, contacts, groups and lists (also allows you to read and write). */ Delete = "delete" } /** * A helper type that expands types so that they resolve to their final forma * in editor tooltips * * @public */ export declare type ExpandRecursively = T extends object ? T extends infer O ? { [K in keyof O]: ExpandRecursively; } : never : T; /** * Parameters that can be sent with rtm.tasks.getList * * @public */ export declare interface GetListParams { /** * The id of the list to perform an action on. */ list_id?: string; /** * If specified, only tasks matching the desired criteria are returned. See here for more details. */ filter?: string; /** * An ISO 8601 formatted time value. If last_sync is provided, only tasks modified since last_sync will be returned, and each element will have an attribute, current, equal to last_sync. */ last_sync?: string; /** * Optional callback to wrap JSON response in */ callback?: string; } /** * Parameters that can be passed with rtm.auth.getToken * * @public */ export declare interface GetTokenParams { /** * Frob argument previously returned via a * call to rtm.auth.getFrob */ frob: string; } /** * Entry point to the API. Calling it with valid credentials will initialise and return an instantiated {@link IRememberTheMilkApi} * * @example * ```TypeScript * import { initialiseApi, ClientPermissions } from "rtm-typescript"; * * const key = "my-api-key"; * const secret = "my-shared-secret"; * * const myAsyncFunction = async () => { * * const client = initialiseApi({ * key, * secret, * permissions: ClientPermissions.Read, * }); * * const result = await client.tasks.getList({ list_id: "2"}); * } * ``` * * @param config - Configuration object for the API * @public */ export declare const initialiseApi: (config: RtmApiConfig) => IRememberTheMilkApi; /** * This is the public API surface for this package. At the present time it only exposes a small number of methods from the RTM API; in future it will be comprehensive. * * @example * ```TypeScript * import { initialiseApi, ClientPermissions } from "rtm-typescript"; * * const key = "my-api-key"; * const secret = "my-shared-secret"; * * const myAsyncFunction = async () => { * * const client = initialiseApi({ * key, * secret, * permissions: ClientPermissions.Read, * }); * * const result = await client.tasks.getList({ list_id: "2"}); * } * * ``` * * @public */ export declare interface IRememberTheMilkApi { /** * Methods attached to the rtm.auth namespace */ auth: Auth; /** * Methods attached to the rtm.tasks namespace */ tasks: Tasks; /** * Methods attached to the rtm.test namespace */ test: Test; /** * Return a valid authentication URL for the RTM API * * @see {@link https://www.rememberthemilk.com/services/api/authentication.rtm |RTM Api Documentation} for more information * * @returns A URL in the form of a string */ getAuthUrl: (frob?: string) => string; } declare interface Note { id: string; created: string; modified: string; title: string; $t: string; } /** * Configuration object for the API * * @public */ export declare interface RtmApiConfig { /** * Remember the Milk API key */ key: string; /** * Remember the Milk API shared secret */ secret: string; /** * What permissions your client needs access to on the API */ permissions: ClientPermissions; /** * Previously authenticated request token */ token?: string; /** * Throttle requests to the API to avoid hitting rate limits * */ throttle?: boolean; } /** * Thrown if the API returns an error response * * @see {@link https://www.rememberthemilk.com/services/api/response.rtm | RTM Api documentation} for more information * @public */ export declare class RtmApiFailedResponseError extends RtmTypescriptError { /** * The response code returned from the RTM Api */ readonly code: number; /** * The error message returned from the RTM Api */ readonly message: string; /** * @param code - The response code returned from the RTM Api * @param message - The error message returned from the RTM Api */ constructor(code: number, message: string); } /** * Raised when the API returns a non 200 HTTP response * * @public */ export declare class RtmHttpError extends RtmTypescriptError { /** * The HTTP status code that was returned */ readonly statusCode: number; /** * The response body of the error message */ readonly body: string; /** * @param statusCode - The HTTP status code that was returned * @param body - The response body of the error message */ constructor(statusCode: number, body: string); } /** * Base error type thrown by this package * * @public */ export declare class RtmTypescriptError extends Error { } /** * A successful response from the API * * @public */ export declare interface SuccessResponse, M extends keyof T> { rsp: ExpandRecursively<{ stat: "ok"; api_key?: string; callback: string; } & T[M]["responseArgs"]>; } declare interface Task { id: string; due: string; has_due_time: string; added: string; completed: string; deleted: string; priority: string; postponed: string; estimate: string; } declare interface TaskList { id: string; taskseries: TaskSeries[]; } /** * API methods related to tasks * * @public */ export declare interface Tasks { /** * Retrieves a list of tasks. * * If list_id is not specified, all tasks are retrieved, unless filter is specified. * If last_sync is provided, only tasks modified since last_sync will be returned, and each element will have an attribute, current, equal to last_sync. * * @returns {@link SuccessResponse} * @throws {@link RtmApiFailedResponseError} if the API responds with a failure * @throws {@link RtmHttpError} if the API responds with a non 200 response */ getList: (params: GetListParams) => Promise["rsp"]>; } declare interface TaskSeries { id: string; created: string; modified: string; name: string; source: string; url: string; location_id: string; tags: { tag: string[]; }; participants: never[]; notes: { note: Note[]; }; task: Task[] | undefined; } /** * Methods used for testing the API * * @public */ export declare interface Test { /** * * A testing method which echos all parameters back in the response. * * @see {@link https://www.rememberthemilk.com/services/api/methods/rtm.test.echo.rtm|RTM Api Documentation} for more information * * @returns {@link SuccessResponse} * @throws {@link RtmApiFailedResponseError} if the API responds with a failure * @throws {@link RtmHttpError} if the API responds with a non 200 response */ echo: (args: Record) => Promise["rsp"]>; /** * * A testing method which checks if the caller is logged in. * * @see {@link https://www.rememberthemilk.com/services/api/methods/rtm.test.echo.rtm|RTM Api Documentation} for more information * * @returns {@link SuccessResponse} * @throws {@link RtmApiFailedResponseError} if the API responds with a failure * @throws {@link RtmHttpError} if the API responds with a non 200 response */ login: () => Promise["rsp"]>; } declare interface User { id: string; username: string; fullname: string; } export { }