Skip to content

Commit

Permalink
Merge branch 'feat/required-policy-id' into release/6.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelscr committed Sep 23, 2024
2 parents f409beb + 7d04bef commit fb2b72e
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 26 deletions.
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ This method registers a new mobile signup for the given request token and addres
try {
const signup = await IncogniaApi.registerSignup({
requestToken: 'request_token',
policyId: 'policy_id',
structuredAddress: {
locale: 'en-US',
countryName: 'United States of America',
Expand All @@ -79,7 +80,8 @@ This method registers a new web signup for the given request token, returning a
```js
try {
const signup = await IncogniaApi.registerWebSignup({
requestToken: 'request_token'
requestToken: 'request_token',
policyId: 'policy_id'
})
} catch (error) {
console.log(error.message)
Expand All @@ -95,6 +97,7 @@ try {
const login = await IncogniaApi.registerLogin({
requestToken: 'request_token',
accountId: 'account_id',
policyId: 'policy_id',
externalId: 'external_id' // optional field
})
} catch (error) {
Expand All @@ -110,7 +113,8 @@ This method registers a new web login for the given request token and account, r
try {
const login = await IncogniaApi.registerWebLogin({
requestToken: 'request_token',
accountId: 'account_id'
accountId: 'account_id',
policyId: 'policy_id'
})
} catch (error) {
console.log(error.message)
Expand All @@ -126,6 +130,7 @@ try {
const payment = await IncogniaApi.registerPayment({
requestToken: 'request_token',
accountId: 'account_id',
policyId: 'policy_id',
addresses: [
{
structuredAddress: {
Expand Down Expand Up @@ -162,7 +167,8 @@ This method registers a new web payment for the given request token and account,
try {
const payment = await IncogniaApi.registerWebPayment({
requestToken: 'request_token',
accountId: 'account_id'
accountId: 'account_id',
policyId: 'policy_id'
})
} catch (error) {
console.log(error.message)
Expand Down Expand Up @@ -272,7 +278,7 @@ const payment = await IncogniaApi.registerPayment({...})
IncogniaApi.registerFeedback({...})
```

Furthermore, the `installationId` and `sessionToken` parameters were removed, and `requestToken` should be used instead. The `requestToken` field can receive the previous `installationId` and `sessionToken` values, as well as the new `requestToken` value from the Mobile and Web SDKs.
Furthermore, the `installationId` and `sessionToken` parameters were removed, and `requestToken` should be used instead. The `requestToken` field can receive the previous `installationId` and `sessionToken` values, as well as the new `requestToken` value from the Mobile and Web SDKs. Also, the `policyId` is now a required parameter and must be used on every assessment.

```js
// Before
Expand All @@ -288,11 +294,13 @@ const webPaymentAssessment = await incogniaApi.registerWebPayment({
// After
const loginAssessment = await IncogniaApi.registerLogin({
requestToken: 'installation_id',
accountId: 'account_id'
accountId: 'account_id',
policyId: 'policy_id'
})
const webPaymentAssessment = await IncogniaApi.registerWebPayment({
requestToken: 'session_token',
accountId: 'account_id'
accountId: 'account_id',
policyId: 'policy_id'
})
```

Expand Down
19 changes: 13 additions & 6 deletions src/incogniaApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const errorMessages = {
CLIENT_SECRET: 'Missing required parameter: clientSecret',
REQUEST_TOKEN: 'Missing required parameter: requestToken',
ACCOUNT_ID: 'Missing required parameter: accountId',
POLICY_ID: 'Missing required parameter: policyId',
EVENT: 'Missing required parameter: event',
INIT: 'IncogniaApi not initialized'
}
Expand Down Expand Up @@ -68,30 +69,33 @@ export class IncogniaApi {
public static async registerSignup(
props: RegisterSignupProps
): Promise<SignupResponse> {
const { requestToken } = props || {}
const { requestToken, policyId } = props || {}
if (!IncogniaApi.instance) throw new IncogniaError(errorMessages.INIT)
if (!requestToken) throw new IncogniaError(errorMessages.REQUEST_TOKEN)
if (!policyId) throw new IncogniaError(errorMessages.POLICY_ID)

return IncogniaApi.instance.#registerSignup(props)
}

public static async registerWebSignup(
props: RegisterWebSignupProps
): Promise<WebSignupResponse> {
const { requestToken } = props || {}
const { requestToken, policyId } = props || {}
if (!IncogniaApi.instance) throw new IncogniaError(errorMessages.INIT)
if (!requestToken) throw new IncogniaError(errorMessages.REQUEST_TOKEN)
if (!policyId) throw new IncogniaError(errorMessages.POLICY_ID)

return IncogniaApi.instance.#registerSignup(props)
}

public static async registerLogin(
props: RegisterLoginProps
): Promise<TransactionResponse> {
const { requestToken, accountId } = props || {}
const { requestToken, accountId, policyId } = props || {}
if (!IncogniaApi.instance) throw new IncogniaError(errorMessages.INIT)
if (!requestToken) throw new IncogniaError(errorMessages.REQUEST_TOKEN)
if (!accountId) throw new IncogniaError(errorMessages.ACCOUNT_ID)
if (!policyId) throw new IncogniaError(errorMessages.POLICY_ID)

return IncogniaApi.instance.#registerTransaction({
...props,
Expand All @@ -102,10 +106,11 @@ export class IncogniaApi {
public static async registerWebLogin(
props: RegisterWebLoginProps
): Promise<WebTransactionResponse> {
const { requestToken, accountId } = props || {}
const { requestToken, accountId, policyId } = props || {}
if (!IncogniaApi.instance) throw new IncogniaError(errorMessages.INIT)
if (!requestToken) throw new IncogniaError(errorMessages.REQUEST_TOKEN)
if (!accountId) throw new IncogniaError(errorMessages.ACCOUNT_ID)
if (!policyId) throw new IncogniaError(errorMessages.POLICY_ID)

return IncogniaApi.instance.#registerTransaction({
...props,
Expand All @@ -116,10 +121,11 @@ export class IncogniaApi {
public static async registerPayment(
props: RegisterPaymentProps
): Promise<TransactionResponse> {
const { requestToken, accountId } = props || {}
const { requestToken, accountId, policyId } = props || {}
if (!IncogniaApi.instance) throw new IncogniaError(errorMessages.INIT)
if (!requestToken) throw new IncogniaError(errorMessages.REQUEST_TOKEN)
if (!accountId) throw new IncogniaError(errorMessages.ACCOUNT_ID)
if (!policyId) throw new IncogniaError(errorMessages.POLICY_ID)

return IncogniaApi.instance.#registerTransaction({
...props,
Expand All @@ -130,10 +136,11 @@ export class IncogniaApi {
public static async registerWebPayment(
props: RegisterWebPaymentProps
): Promise<WebTransactionResponse> {
const { requestToken, accountId } = props || {}
const { requestToken, accountId, policyId } = props || {}
if (!IncogniaApi.instance) throw new IncogniaError(errorMessages.INIT)
if (!requestToken) throw new IncogniaError(errorMessages.REQUEST_TOKEN)
if (!accountId) throw new IncogniaError(errorMessages.ACCOUNT_ID)
if (!policyId) throw new IncogniaError(errorMessages.POLICY_ID)

return IncogniaApi.instance.#registerTransaction({
...props,
Expand Down
6 changes: 3 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export enum TransactionAddressType {

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

Expand Down Expand Up @@ -46,8 +46,8 @@ export type WebSignupEvidenceSummary = WebEvidenceSummary

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

Expand All @@ -63,8 +63,8 @@ export type RegisterWebLoginProps = RegisterLoginBaseProps

export type RegisterPaymentBaseProps = {
requestToken: string
policyId: string
accountId: string
policyId?: string
externalId?: string
addresses?: Array<TransactionAddress>
paymentValue?: PaymentValue
Expand Down
53 changes: 42 additions & 11 deletions test/incogniaApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ describe('Incognia API', () => {
const props = {
accountId: 'id',
requestToken: 'id',
policyId: 'id',
event: FeedbackEvent.AccountTakeover
}

Expand Down Expand Up @@ -66,9 +67,12 @@ describe('Incognia API', () => {
})

it('validates signup', async () => {
expect(() => IncogniaApi.registerSignup({} as any)).rejects.toThrow(
'Missing required parameter: requestToken'
)
expect(() =>
IncogniaApi.registerSignup({ policyId: 'id' } as any)
).rejects.toThrow('Missing required parameter: requestToken')
expect(() =>
IncogniaApi.registerSignup({ requestToken: 'id' } as any)
).rejects.toThrow('Missing required parameter: policyId')
})

it('validates a signup', async () => {
Expand Down Expand Up @@ -115,9 +119,12 @@ describe('Incognia API', () => {
})

it('validates a web signup', async () => {
expect(() => IncogniaApi.registerWebSignup({} as any)).rejects.toThrow(
'Missing required parameter: requestToken'
)
expect(() =>
IncogniaApi.registerWebSignup({ policyId: 'id' } as any)
).rejects.toThrow('Missing required parameter: requestToken')
expect(() =>
IncogniaApi.registerWebSignup({ requestToken: 'token' } as any)
).rejects.toThrow('Missing required parameter: policyId')
})

it('registers a web signup', async () => {
Expand All @@ -135,12 +142,14 @@ describe('Incognia API', () => {

nock(BASE_ENDPOINT)
.post(`/v2/onboarding/signups`, {
request_token: requestToken
request_token: requestToken,
policy_id: 'policy_id'
})
.reply(200, apiResponse)

const webSignup = await IncogniaApi.registerWebSignup({
requestToken
requestToken,
policyId: 'policy_id'
})
expect(webSignup).toEqual(expectedResponse)
})
Expand Down Expand Up @@ -181,7 +190,8 @@ describe('Incognia API', () => {

const login = await IncogniaApi.registerLogin({
requestToken: 'request_token',
accountId: 'account_id'
accountId: 'account_id',
policyId: 'policy_id'
})
expect(login).toEqual(expectedResponse)
})
Expand All @@ -193,6 +203,12 @@ describe('Incognia API', () => {
expect(() =>
IncogniaApi.registerWebLogin({ requestToken: 'token' } as any)
).rejects.toThrow('Missing required parameter: accountId')
expect(() =>
IncogniaApi.registerWebLogin({
accountId: 'id',
requestToken: 'token'
} as any)
).rejects.toThrow('Missing required parameter: policyId')
})

it('registers a web login', async () => {
Expand All @@ -212,7 +228,8 @@ describe('Incognia API', () => {

const webLogin = await IncogniaApi.registerWebLogin({
requestToken: 'request_token',
accountId: 'account_id'
accountId: 'account_id',
policyId: 'policy_id'
})
expect(webLogin).toEqual(expectedResponse)
})
Expand All @@ -224,6 +241,12 @@ describe('Incognia API', () => {
expect(() =>
IncogniaApi.registerPayment({ requestToken: 'token' } as any)
).rejects.toThrow('Missing required parameter: accountId')
expect(() =>
IncogniaApi.registerPayment({
accountId: 'id',
requestToken: 'token'
} as any)
).rejects.toThrow('Missing required parameter: policyId')
})

it('registers payment', async () => {
Expand All @@ -246,6 +269,7 @@ describe('Incognia API', () => {
accountId: 'account_id',
appId: 'app_id',
externalId: 'external_id',
policyId: 'policy_id',
coupon: { type: CouponType.FixedValue, value: 10 }
})
expect(payment).toEqual(expectedResponse)
Expand All @@ -258,6 +282,12 @@ describe('Incognia API', () => {
expect(() =>
IncogniaApi.registerWebPayment({ requestToken: 'token' } as any)
).rejects.toThrow('Missing required parameter: accountId')
expect(() =>
IncogniaApi.registerWebPayment({
accountId: 'id',
requestToken: 'token'
} as any)
).rejects.toThrow('Missing required parameter: policyId')
})

it('registers a web payment', async () => {
Expand All @@ -277,7 +307,8 @@ describe('Incognia API', () => {

const webPayment = await IncogniaApi.registerWebPayment({
requestToken: 'request_token',
accountId: 'account_id'
accountId: 'account_id',
policyId: 'policy_id'
})
expect(webPayment).toEqual(expectedResponse)
})
Expand Down

0 comments on commit fb2b72e

Please sign in to comment.