UNPKG

ttf-api

Version:

The TrueToForm API SDK

193 lines (173 loc) 4.65 kB
declare module "ttf-api" { export default function ttfApi(apiKey: string): ApiInstance; type PostResponse<R, T> = { id: string; type: T; results: R; }; type GenericResults<P, R, T> = { clientId: string; createdAt: number; id: string; params: P; results: R; retrievalAttempts: number; type: T; }; type Gender = "female" | "male" | "neutral"; type Points2d = { [index: number]: { coords: number[]; }; }; type Metric = { indicatorPoints: number[]; level: number; points2d: Points2d; value: number; }; type GarmentLength = Metric & { category: string; }; type LengthResults = null | { // key is the size label [key: string]: GarmentLength; }; type BaseApiResults = { avatar_img_base64: string; betas: number[]; fitMetrics: { floorLevel: number; metrics: { Bust: Metric; Hip: Metric; Underbust: Metric; Waist: Metric; }; version: string; }; length_results: LengthResults; gender: Gender; render_parameters: { far: number; near: number; bottom: number; top: number; left: number; right: number; }; version: string; }; type SurveyParams = { age: number; height: number; weight: number; gender: Gender; }; type SurveyResponse = BaseApiResults; type ScanParams = { scan: string; }; type ScanResponse = BaseApiResults & { scanData: { name: string; }; }; type PredictionParams = { garmentId: string; sessionId?: string; }; type PredictionFitResults = { category: string[]; text_cm: string[]; text_in: string[]; }; type PredictionResponse = { size_options: string[]; size_recommendation: { index: number; label: string; }; version: string; fit_results: { Bust: PredictionFitResults; Hip: PredictionFitResults; Underbust: PredictionFitResults; Waist: PredictionFitResults; }; }; type PredictionBaseResults<P, R, T> = GenericResults<P, R, T> & { createdBy: "scan" | "survey"; creatorId: string; garmentId: string; }; export type SurveyResults = GenericResults< SurveyParams, SurveyResponse, "survey" >; export type ScanResults = GenericResults<ScanParams, ScanResponse, "scan">; export type PredictionResults = PredictionBaseResults< PredictionParams, PredictionResponse, "prediction" >; export type Garment = { image: string; title: string; sizeOptions: string[]; }; export type ProgressCallback = (progress: string) => void; export type SessionReadyCallback = (sessionId: string) => void; export type FailureCallback = (error: { type: string; message: string; }) => void; export interface RealtimeSession { onProgressChange: (callback: ProgressCallback) => void; onSessionReady: (callback: SessionReadyCallback) => void; onFailure: (callback: FailureCallback) => void; } export interface ApiInstance { isStale: Promise<boolean>; // decides if the current Prediction is outdated and should be removed initAnalytics(): Promise<Object>; getGarment(id: string): Promise<Garment>; getSurvey(id: string): Promise<SurveyResults>; getMeasurements(id: string): Promise<SurveyResults>; getScan(id: string): Promise<ScanResults>; getPrediction(id: string): Promise<PredictionResults>; createSession(): Promise<object>; createSurvey( surveyData: SurveyParams ): Promise<PostResponse<SurveyResponse, "survey">>; createMeasurements( surveyData: SurveyParams ): Promise<PostResponse<SurveyResponse, "survey">>; createScan(sessionId: string): Promise<PostResponse<ScanResponse, "scan">>; createScanPrediction( garmentId: string, sessionId: string ): Promise<PostResponse<ScanResponse, "scan">>; createSurveyPrediction( garmentId: string, surveyData: SurveyParams ): Promise<PostResponse<SurveyResponse, "survey">>; createMeasurementsPrediction( garmentId: string, surveyData: SurveyParams ): Promise<PostResponse<SurveyResponse, "survey">>; createPredictionFromId( garmentId: string, creatorId: string ): Promise<PostResponse<PredictionResponse, "prediction">>; getRealtimeSession( sessionId: string, options: { onChange: ProgressCallback; onSuccess: SessionReadyCallback; onError: FailureCallback; } ): () => void; getSessionStatus(sessionId: string): Promise<object>; } }