@proveanything/smartlinks
Version:
Official JavaScript/TypeScript SDK for the Smartlinks API
97 lines (96 loc) • 2.95 kB
TypeScript
import type { UserAccountRegistrationRequest } from "../types/auth";
export type LoginResponse = {
id: string;
name: string;
email: string;
bearerToken: string;
account: Record<string, any>;
};
export type VerifyTokenResponse = {
valid: boolean;
id?: string;
name?: string;
email?: string;
account?: Record<string, any>;
};
export type AccountInfoResponse = {
accessType: string;
analyticsCode: string;
analyticsId: string;
auth_time: number;
baseCollectionId: string;
clientType: string;
email: string;
email_verified: boolean;
features: {
actionLogger: boolean;
adminCollections: boolean;
adminApps: boolean;
apiKeys: boolean;
adminUsers: boolean;
[key: string]: boolean;
};
iat: number;
id: string;
iss: string;
location: string | null;
name: string;
picture: string;
sites: {
[siteName: string]: boolean;
};
sub: string;
uid: string;
user_id: string;
whitelabel: {
[key: string]: any;
};
};
export declare namespace auth {
/**
* Login with email and password.
* Sets the bearerToken for subsequent API calls.
*/
function login(email: string, password: string): Promise<LoginResponse>;
/**
* Logout (clears bearerToken for future API calls).
*/
function logout(): void;
/**
* Verifies the current bearerToken (or a provided token).
* Returns user/account info if valid.
*/
function verifyToken(token?: string): Promise<VerifyTokenResponse>;
/**
* Requests an admin JWT for the current user and a specific collection
* Returns JWT if valid.
*/
function requestAdminJWT(collectionId: string): Promise<string>;
/**
* Requests a JWT for the current user and a specific collection/product/proof
* Validates if the user has access to the resource, and returns a JWT
*/
function requestPublicJWT(collectionId: string, productId: string, proofId: string): Promise<string>;
/**
* Tries to register a new user account. Can return a bearer token, or a Firebase token
*/
function registerUser(user: UserAccountRegistrationRequest): Promise<LoginResponse>;
/**
* Admin: Get a user bearer token (impersonation/automation).
* POST /admin/auth/userToken
* All fields are optional; at least one identifier should be provided.
*/
function getUserToken(opts?: {
email?: string;
collectionId?: string;
userId?: string;
expiry?: string;
}): Promise<{
bearerToken: string;
}>;
/**
* Gets current account information for the logged in user.
* Returns user, owner, account, and location objects.
*/
function getAccount(): Promise<AccountInfoResponse>;
}