Skip to content

Commit

Permalink
feat(RequestToken): add request_token support to all methods
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelscr committed Aug 5, 2024
1 parent 15f0212 commit 8b3c85b
Show file tree
Hide file tree
Showing 3 changed files with 275 additions and 34 deletions.
51 changes: 32 additions & 19 deletions src/incogniaApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ export class IncogniaApi {
** Resources
*/
async registerSignup(props: RegisterSignupProps): Promise<SignupResponse> {
const { installationId } = props || {}
if (!installationId) {
throw new IncogniaError('No installationId provided')
const { installationId, requestToken } = props || {}
if (!installationId && !requestToken) {
throw new IncogniaError('No installationId or requestToken provided')
}

return this.#registerBaseSignup(props)
Expand All @@ -86,18 +86,21 @@ export class IncogniaApi {
async registerWebSignup(
props: RegisterWebSignupProps
): Promise<WebSignupResponse> {
const { sessionToken } = props || {}
if (!sessionToken) {
throw new IncogniaError('No sessionToken provided')
const { sessionToken, requestToken } = props || {}
if (!sessionToken && !requestToken) {
throw new IncogniaError('No sessionToken or requestToken provided')
}

return this.#registerBaseSignup(props)
}

async registerLogin(props: RegisterLoginProps): Promise<TransactionResponse> {
const { installationId, accountId } = props || {}
if (!installationId || !accountId) {
throw new IncogniaError('No installationId or accountId provided')
const { installationId, requestToken, accountId } = props || {}
if (!installationId && !requestToken) {
throw new IncogniaError('No installationId or requestToken provided')
}
if (!accountId) {
throw new IncogniaError('No accountId provided')
}

return this.#registerTransaction({ ...props, type: TransactionType.Login })
Expand All @@ -106,19 +109,26 @@ export class IncogniaApi {
async registerWebLogin(
props: RegisterWebLoginProps
): Promise<WebTransactionResponse> {
const { sessionToken, accountId } = props || {}
if (!sessionToken || !accountId) {
throw new IncogniaError('No sessionToken or accountId provided')
const { sessionToken, requestToken, accountId } = props || {}
if (!sessionToken && !requestToken) {
throw new IncogniaError('No sessionToken or requestToken provided')
}
if (!accountId) {
throw new IncogniaError('No accountId provided')
}

return this.#registerTransaction({ ...props, type: TransactionType.Login })
}

async registerPayment(
props: RegisterPaymentProps
): Promise<TransactionResponse> {
const { installationId, accountId } = props || {}
if (!installationId || !accountId) {
throw new IncogniaError('No installationId or accountId provided')
const { installationId, requestToken, accountId } = props || {}
if (!installationId && !requestToken) {
throw new IncogniaError('No installationId or requestToken provided')
}
if (!accountId) {
throw new IncogniaError('No accountId provided')
}

return this.#registerTransaction({
Expand All @@ -130,17 +140,20 @@ export class IncogniaApi {
async registerWebPayment(
props: RegisterWebPaymentProps
): Promise<WebTransactionResponse> {
const { sessionToken, accountId } = props || {}
if (!sessionToken || !accountId) {
throw new IncogniaError('No sessionToken or accountId provided')
const { sessionToken, requestToken, accountId } = props || {}
if (!sessionToken && !requestToken) {
throw new IncogniaError('No sessionToken or requestToken provided')
}
if (!accountId) {
throw new IncogniaError('No accountId provided')
}

return this.#registerTransaction({
...props,
type: TransactionType.Payment
})
}


async registerFeedback(
bodyParams: RegisterFeedbackBodyProps,
queryParams?: RegisterFeedbackParamsProps
Expand Down
15 changes: 9 additions & 6 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,22 @@ export enum TransactionAddressType {
}

export type RegisterSignupBaseProps = {
requestToken?: string
accountId?: string
policyId?: string
[x: string]: any
}

export type RegisterSignupProps = RegisterSignupBaseProps & {
installationId: string
installationId?: string
addressCoordinates?: AddressCoordinates
addressLine?: string
structuredAddress?: StructuredAddress
externalId?: string
}

export type RegisterWebSignupProps = RegisterSignupBaseProps & {
sessionToken: string
sessionToken?: string
}

export type SignupBaseResponse = {
Expand All @@ -48,12 +49,13 @@ export type WebSignupEvidenceSummary = WebEvidenceSummary

type RegisterLoginBaseProps = {
accountId: string
requestToken?: string
policyId?: string
[x: string]: any
}

export type RegisterLoginProps = RegisterLoginBaseProps & {
installationId: string
installationId?: string
relatedAccountId?: string
location?: TransactionLocation
paymentMethodIdentifier?: string
Expand All @@ -62,11 +64,12 @@ export type RegisterLoginProps = RegisterLoginBaseProps & {
}

export type RegisterWebLoginProps = RegisterLoginBaseProps & {
sessionToken: string
sessionToken?: string
}

export type RegisterPaymentBaseProps = {
accountId: string
requestToken?: string
policyId?: string
externalId?: string
addresses?: Array<TransactionAddress>
Expand All @@ -77,12 +80,12 @@ export type RegisterPaymentBaseProps = {
}

export type RegisterPaymentProps = RegisterPaymentBaseProps & {
installationId: string
installationId?: string
relatedAccountId?: string
}

export type RegisterWebPaymentProps = RegisterPaymentBaseProps & {
sessionToken: string
sessionToken?: string
}

export type TransactionBaseResponse = {
Expand Down
Loading

0 comments on commit 8b3c85b

Please sign in to comment.