0.0.21 • Published 2 years ago

cadawada-client v0.0.21

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

Account Module

Account Model Description

class Account { 
    /**
    * Allows users to signup to Cadawada by inputing a some information about themselves such as their business name, first and last name, email address, phone number and a password
     **/ 
    static async initiateOnboarding(body: InitiateOnboadingPayloadType): Promise<InitiateOnboardingResponseType>

    /**
   * Get the Users account details from the backend
   **/
    static getAccount(): UserProfileType

    /**
   *  Authorize a User credential and store the auth token for the session
   **/
    static async login(auth: UserIdentityType & { password: string }): Promise<LoginType>

    /**
   *  Update a user credential
   */
    static async updateOnboarding(body: UserIdentityType): Promise<InitiateOnboardingResponseType>

    /**
   *  Verify a users Phone Number using the Otp sent to the users phone during registration
   */
    static async verifyPhoneNumber(body: { otpCode: string }): Promise<any>    

   /**
   *  Verify a users Email using the Otp sent to the users email address during registration
   */
    static async verifyEmailAddress(body: { otpCode: string }): Promise<any>
}

Account Interface Description

interface InitiateOnboadingPayloadType {
  countryCode: string;
  emailAddress: string;
  firstName: string;
  lastName: string;
  accountType: ACCOUNT_TYPE;
  phoneNumber: string;
  businessName?: string;
  password: string;
}

type ACCOUNT_TYPE = "Business" | "Personal";

interface InitiateOnboardingResponseType extends UserProfileType {
  role: AccountRoleType;
  token: AuthTokenType;
}

type AccountRoleType = {
    id: number;
    name: string;
}

type AuthTokenType = {
    accessToken: string;
    expiresIn: number;
    refreshToken: string;
}

type UserProfileType = {
    user: UserType;
    account: AccountType;
    country: CountryType;
    currency: CurrencyType;
}

interface UserType {
  status: string;
  dateOfBirth?: string;
  firstName: string;
  lastName: string;
  selfie?: string;
}

type CountryType = {
    imageUrl: string,
    id: number,
    shortCode: string,
    name: string,
    diallingCode: string
}

type CurrencyType = {
    id: number,
    name: string,
    code: string
    countryCode: string
    countryId: string
    countryImageUrl: string
    countryName: string
    currencyIconUrl: null
}


type LoginType = {
    login: {
        user: UserProfileType
        account: AccountType
        token: AuthTokenType
        country: CountryType
        currency: CurrencyType
        pendingOnboarding: any
        pendingKyc: any
    }
}

type UserProfileType = {
  user: UserType;
  account: AccountType;
  country: CountryType;
  currency: CurrencyType;
};

 type AuthTokenType = {
    accessToken: string
    expiresIn: number,
    refreshToken: string
}

interface UserIdentityType {
  countryCode?: string;
  userIdentity: string;
}

AuthService Module

AuthService Model Description

class AuthService { 

    /**
     * the below properties are the static properties 
     * of Auth service Class 
    */
    private static phoneNumber: string
    private static diallingCode: string
    private static authToken: Partial<AuthTokenType> = {}
    private static userIdentity: UserIdentityType
    private static password: string
    private static environment: AuthEnvironmentType = 'production'
    private static isAuthorized: boolean = false;
    private static clientCredential: Partial<Record<AuthEnvironmentType, ClientCredentialType>> | ClientCredentialType = {}

    static setAuth(auth: CadawadaAuthType): void

    /**
     * Set the credentials that will be used by request to 
     * Authorize this users api call.
     * Should be called first to register the sessions Auth credentials
     * Any api transaction before this call will always fail
     */
    static setAuth(auth: CadawadaAuthType): void    


    /**
     * Stores the users auth token passed to it in session 
     */
    static setToken(token: AuthTokenType): void

    /**
     * Gets the users auth token stored in session 
     */ 
    static getToken(): Partial<AuthTokenType>

    /***
     * Gets the environment in which cadawada is running on whether
     * its development, staging or production 
     */
    static getEnvironment(): AuthEnvironmentType

    /**
     *  Gets the optional parameter of Type AuthEnvironmentType
     *  and returns the client id
    */
    static getClientId(env?: AuthEnvironmentType | undefined): any

    /**
     *  Gets the optional parameter of Type AuthEnvironmentType
     *  and returns the client Api key
    */
    static getClientApiKey(env?: AuthEnvironmentType | undefined): any
}

AuthService Interface Description

type AuthEnvironmentType = "production" | "development" | "staging";

type ClientCredentialType = {
  clientId: string;
  clientApiKey: string;
};

interface CadawadaAuthType {
  userIdentity?: UserIdentityType;
  password?: string;
  accessToken?: string;
  refreshToken?: string;
  environment?: AuthEnvironmentType;
  clientCredential?:
    | Partial<Record<AuthEnvironmentType, ClientCredentialType>>
    | ClientCredentialType;
}

type AuthTokenType = {
  accessToken: string;
  expiresIn: number;
  refreshToken: string;
};

type LoginType = {
  login: {
    user: UserProfileType;
    account: AccountType;
    token: AuthTokenType;
    country: CountryType;
    currency: CurrencyType;
    pendingOnboarding: any;
    pendingKyc: any;
  };
};

Currency Module

Currency Model description

class Currency {
  /**
   * Get and return the list of currencies from server.
  */
  static async getCurrencies({ environment }: RequestPayloadType = {}): Promise<CadawadaResponseType<CurrencyType[]>>

  /**
   * Get and return the exchange rate of currencies from server.
  */
  static getExchangeRate({amount = 1, ...others}: {
    sourceCurrencyCode: string;
    destinationCurrencyCode: string;
    amount?: number;
  }): 

}

Currency Interface Description

type ExchangeRateType = {
    destinationCurrencyCode: string
    exchangeRate: number
    sourceCurrencyCode: string
    transferCharges:number
    sourceAmount:number
    destinationAmount:number
}

type CurrencyType = {
    id: number,
    name: string,
    code: string
    countryCode: string
    countryId: string
    countryImageUrl: string
    countryName: string
    currencyIconUrl: null
}

type RequestPayloadType<T = unknown> = {environment?: AuthEnvironmentType} & T  

Platform Module

Platform Model description

class Platform {
  /**
   * Get and return the list of currencies from server.
  */
  static async getCurrencies({ environment }: RequestPayloadType = {}): Promise<CadawadaResponseType<CurrencyType[]>>

  /**
   * send otp to a users phone number for verification
  */
  static async sendOtp(body: Partial<UserIdentityType> & { destination: UserIdentityNameType }): Promise<CadawadaResponseType<{countDown: number}>>

}

Platform Interface Description

interface UserIdentityType {
  countryCode?: string;
  userIdentity: string;
}


type UserIdentityNameType = "PhoneNumber" | "Email";

type CountryType = {
    imageUrl: string,
    id: number,
    shortCode: string,
    name: string,
    diallingCode: string
}

type RequestPayloadType<T = unknown> = {environment?: AuthEnvironmentType} & T  

CadawadaRequest Module

CadawadaRequest Model description

class CadawadaRequest {
  /**
   * Get and return the list of currencies from server.
  */
  static async request<T = any>(req: CadawadaRequestType): Promise<CadawadaResponseType<T>>
}

CadawadaRequest Interface Description

type RequestPayloadType<T = unknown> = {environment?: AuthEnvironmentType} & T  

type AuthEnvironmentType = "production" | "development" | "staging";

Payment Module

Payment Model description

class Payment {
  /**
   * Get and return the list of countries that money can be transfered to.
  */
 static getTransferCountries(): Promise<CadawadaResponseType<TransferCountriesType>>
}

Payment Interface Description

type TransferCountriesType = {
    sourceCountries: Array<{
        country: CountryType
        currency: CurrencyType
        lowerTransferLimit: number

    }>
    destinationCountries: Array<{
        country: CountryType
        currency: CurrencyType
        lowerTransferLimit: number
    }>
}

Transfer Module

Transfer Model description

class Transfer {
  /*
   * Gets the different currencies that can be transfered to a particular country
  */
  static getCurrencyCatalog(): Promise<CadawadaResponseType<TransferCountryCurrencyCatalogType>>

  /*
   * Gets the different currencies that can be transfered to a particular country
  */
  static getTransferTypes(countryCode: string): Promise<CadawadaResponseType<TransferBeneficiaryType[]>>

  /**
   * 
   */
  static getBeneficiaryTransferForm({ beneficiaryTypeId, countryCode, currencyCode }: TransferBeneficiaryFormProps): Promise<CadawadaResponseType<TransferBeneficiaryFormType>>
 
  /*
  * 
  */
  static validateBeneficiary(body: any): Promise<CadawadaResponseType<TransferBeneficiaryFormType>>

  static validateBeneficiaryManual(body: any): Promise<CadawadaResponseType<TransferBeneficiaryFormType>>

}

Transfer Interface Description

type TransferCurrencyType = {
    currency: CurrencyType,
    transferLimit: {
        localLowerLimit: number,
        internationalLowerLimit: number
    }
}

type TransferCountryCurrencyCatalogType = {
    source: {
        country: CountryType
        currencies: Array<TransferCurrencyType>
    }
    destinations: Array<{
        country: CountryType
        currencies: Array<TransferCurrencyType>
    }>
}

type TransferBeneficiaryType = {
    name: string
    id: number
}

type TransferBeneficiaryFormProps = {
    beneficiaryTypeId: string, 
    countryCode: string,
    currencyCode: string
}

type TransferBeneficiaryFormType = {
    form: FormType[]
    beneficiaryType: TransferBeneficiaryType
    countryCode: string
    currencyCode: string
    transactionRoute: "Local" | "International"
}
0.0.20

2 years ago

0.0.21

2 years ago

0.0.14

2 years ago

0.0.16

2 years ago

0.0.17

2 years ago

0.0.19

2 years ago

0.0.11

2 years ago

0.0.12

2 years ago

0.0.13

2 years ago

0.0.10

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.4

3 years ago

0.0.1

3 years ago