@portive/client
Version:
Client to connect to and use Portive's cloud services for open source components
63 lines (62 loc) • 2.56 kB
TypeScript
import { Resolvable } from "resolvable-value";
import { JsonObject } from "type-fest";
export declare type ClientOptions = {
apiKey?: Resolvable<string>;
authToken?: Resolvable<string>;
apiOrigin?: string;
};
/**
* Create a `Client` object and return it.
*/
export declare function createClient(options: ClientOptions): Client;
/**
* Create a `Client` object that we pass to the API functions.
*
* We enforce the creation of a `Client` object for a few reasons:
*
* 1. It helps us not have to deal with `authTokenable` separately for every
* API function call.
* 2. It makes it easy for any components to support any initialization changes
* by just initializing with `ClienOptions`. For example, if we wanted to
* add a `path` property back in the future, we just have to implement at
* one place.
* 3. It's self documenting on what you should probably accept as part of your
* initialization if you want to fully support all the options. For example,
* we can see here that `apiOrigin` is an option to support. If it's
* part of multiple function signature like in `upload`, then it may not
* be so easy to remember to pass all the values through at each function
* invocation location.
*/
export declare class Client {
/**
* We don't name it `authToken` so that people don't use it expecting it to
* always be a string. It's named to imply that whatever it is can be
* turned into an `authToken`.
*/
unresolvedApiKey: undefined | Resolvable<string>;
unresolvedAuthToken: undefined | Resolvable<string>;
apiOrigin: string;
constructor({ apiKey, authToken, apiOrigin, }: ClientOptions);
/**
* Posts at the given path with the `apiKey` or `authToken`.
*/
post<
/**
* FIXME:
*
* This is a little messy. We don't actually want the `apiKey` or `authToken`
* to be passed in. We just don't want it to collide with the `data`. But
* perhaps this is better done by passing `data` separately.
*/
D extends JsonObject, R extends JsonObject>(path: string, data: D): Promise<R>;
/**
* Gets the apiKey for the client. If it is a function, it gets the return
* value of the function. If that returns a promise, it awaits it.
*/
getApiKey(): Promise<string | undefined>;
/**
* Gets the authToken for the client. If it is a function, it gets the return
* value of the function. If that returns a promise, it awaits it.
*/
getAuthToken(): Promise<string | undefined>;
}