import {AcceptableInput, MsLivenessCreateSessionResponse, SetupInfo, UploadReadyData, UploadSampleBasicInfo} from "../../core/generated/zenid-types.generated.js"; import {DocumentCodes, PageCodes, SampleType} from "../../core/generated/zenid-enums.generated.js"; function isEnumValue>( enumObj: E, val: unknown ): val is E[keyof E] { return Object.values(enumObj).includes(val as any); } export class SampleToUpload { file: Uint8Array; sampleType?: SampleType; documentCode?: DocumentCodes; pageCode?: PageCodes; async?: boolean; acceptableInput?: AcceptableInput; constructor(file: Uint8Array) { this.file = file; } makeAsync(): this { this.async = true; return this; } // Overload signatures set(sampleType: SampleType): this; set(documentCode: DocumentCodes): this; set(pageCode: PageCodes): this; set(acceptableInput: AcceptableInput): this; // Single implementation set(value: SampleType | DocumentCodes | PageCodes | AcceptableInput): this { if (value instanceof AcceptableInput) { this.acceptableInput = value; } else if (isEnumValue(SampleType, value)) { this.sampleType = value; } else if (isEnumValue(DocumentCodes, value)) { this.documentCode = value; } else if (isEnumValue(PageCodes, value)) { this.pageCode = value; } else { throw new Error("Invalid type for set()"); } return this; } getUrlParams(): string { let parms= []; if (this.sampleType) { parms.push(`expectedSampleType=${encodeURIComponent(SampleType[this.sampleType])}`); } if (this.documentCode) { parms.push(`documentCode=${encodeURIComponent(DocumentCodes[this.documentCode])}`); } if (this.pageCode) { parms.push(`pageCode=${encodeURIComponent(PageCodes[this.pageCode])}`); } if (this.acceptableInput) { parms.push(`acceptableInput=${encodeURIComponent(JSON.stringify(this.acceptableInput))}`); } if (this.async) { parms.push(`async=${encodeURIComponent(this.async)}`); } return parms.length > 0 ? '?' + parms.join('&') : ''; } } export interface BackendApi { getSetupInfo(): Promise; initSdk(token: string): Promise; uploadSample(sampleToUpload: SampleToUpload): Promise; getSample(sampleId: string): Promise; investigateSamples(sampleIDs: string[], async: boolean): Promise; getBackendUrl(): string; msLivenessCreateSession(deviceCorrelationId: string): Promise; msLivenessGetSessionResult(sessionId: string): Promise; msLivenessGetSessionImage(sessionImageId: string): Promise; }