All files / src/services EmailIssuerService.ts

50% Statements 7/14
100% Branches 0/0
25% Functions 1/4
45.45% Lines 5/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 811x           1x                         1x       92x     92x                                                                                                            
import {
  DefaultApiFp as Api,
  InlineResponse200 as _InitiateResponse,
  InlineResponse2001 as _VerifyResponse,
} from '@affinidi/issuer-email-ses-client'
import { VCEmailPersonV1 } from '@affinidi/vc-data'
import { profile } from '@affinidi/tools-common'
 
type Awaited<T> = T extends PromiseLike<infer U> ? U : never
type ApiInitiatePostPromise = ReturnType<ReturnType<typeof Api>['apiInitiatePost']>
type ApiInitiatePostResult = Awaited<ApiInitiatePostPromise>
type AxiosInstance = Parameters<ApiInitiatePostResult>[0]
 
export type VerifyResponse = Omit<_VerifyResponse, 'vcs'> & {
  vcs: VCEmailPersonV1[]
}
 
export type InitiateResponse = _InitiateResponse
@profile()
export class EmailIssuerService {
  private readonly basePath: string
 
  constructor({ basePath }: { basePath: string }) {
    this.basePath = basePath
  }
 
  private readonly getApi = (apiKey: string) => Api({ apiKey, basePath: this.basePath })
 
  async initiate({
    apiKey,
    emailAddress,
    id,
    holder,
    axios,
  }: {
    apiKey: string
    emailAddress: string
    id: string
    holder: string
    axios?: AxiosInstance
  }): Promise<InitiateResponse> {
    const apicall = await this.getApi(apiKey).apiInitiatePost({
      payload: {
        id,
        holder,
        type: [],
        data: {
          emailAddress,
        },
      },
    })
    const result = await apicall(axios, this.basePath)
    return result.data
  }
 
  async verify({
    apiKey,
    code,
    id,
    holder,
    axios,
  }: {
    apiKey: string
    code: string
    id: string
    holder: string
    axios?: AxiosInstance
  }): Promise<VerifyResponse> {
    const apicall = await this.getApi(apiKey).apiVerifyPost({
      payload: {
        id,
        holder,
        type: [],
        data: { code },
      },
    })
    const result = await apicall(axios, this.basePath)
    return result.data as VerifyResponse
  }
}