Skip to content

Commit

Permalink
Merge pull request #79 from inloco/remove-get-method
Browse files Browse the repository at this point in the history
Remove getSignupAssessment method
  • Loading branch information
FranciscoGileno authored Jul 8, 2024
2 parents de56aa7 + dca5cfb commit 5bd0dd5
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 153 deletions.
27 changes: 0 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,6 @@ try {
}
```


### Getting a Mobile Signup

This method allows you to retrieve the latest assessment for a given signup event, returning a signup assessment, containing the risk assessment and supporting evidence:

```js
try {
const signupAssessment = await incogniaApi.getSignupAssessment(signupId)
} catch (error) {
console.log(error.message)
}
```

### Registering a Mobile Login

This method registers a new mobile login for the given installation and account, returning a transaction assessment, containing the risk assessment and supporting evidence.
Expand Down Expand Up @@ -177,20 +164,6 @@ try {
}
```

### Searching for accounts

This method fetches every account associated with a specific installation, returning the number of accounts and an array containing the account IDs and related timestamps. Use this API to map the relationship between user accounts and devices.

```js
try {
const accounts = await incogniaApi.searchAccounts({
installationId: 'installation_id'
})
} catch (error) {
console.log(error.message)
}
```

## Typescript enabled

Thanks to Typescript, all methods attributes and data response are typed, meaning any typescript-enabled editor can take advantage of intellisense and auto-complete:
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "@incognia/api",
"author": "Incognia (https://us.incognia.com)",
"author": "Incognia (https://incognia.com)",
"repository": "https://github.com/inloco/incognia-node",
"version": "4.5.1",
"version": "5.0.0",
"license": "MIT",
"type": "module",
"main": "dist/index.cjs.js",
Expand Down
34 changes: 1 addition & 33 deletions src/incogniaApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import {
RegisterTransactionProps,
RegisterWebLoginProps,
RegisterWebSignupProps,
SearchAccountsBodyProps,
SearchAccountsResponse,
SignupResponse,
TransactionResponse,
TransactionType,
Expand All @@ -46,7 +44,6 @@ type ApiEndpoints = {
SIGNUPS: string
TRANSACTIONS: string
FEEDBACKS: string
ACCOUNTS: string
}

const BASE_ENDPOINT = 'https://api.incognia.com/api'
Expand All @@ -55,8 +52,7 @@ export const apiEndpoints: ApiEndpoints = {
TOKEN: `${BASE_ENDPOINT}/v2/token`,
SIGNUPS: `${BASE_ENDPOINT}/v2/onboarding/signups`,
TRANSACTIONS: `${BASE_ENDPOINT}/v2/authentication/transactions`,
FEEDBACKS: `${BASE_ENDPOINT}/v2/feedbacks`,
ACCOUNTS: `${BASE_ENDPOINT}/v2/accounts/search`
FEEDBACKS: `${BASE_ENDPOINT}/v2/feedbacks`
}

export class IncogniaApi {
Expand All @@ -77,17 +73,6 @@ export class IncogniaApi {
/*
** Resources
*/
async getSignupAssessment(signupId: string): Promise<SignupResponse> {
if (!signupId) {
throw new IncogniaError('No signupId provided')
}

return this.resourceRequest({
url: `${apiEndpoints.SIGNUPS}/${signupId}`,
method: Method.Get
})
}

async registerSignup(props: RegisterSignupProps): Promise<SignupResponse> {
const { installationId } = props || {}
if (!installationId) {
Expand Down Expand Up @@ -181,23 +166,6 @@ export class IncogniaApi {
})
}

// Search Accounts
async searchAccounts(
props: SearchAccountsBodyProps
): Promise<SearchAccountsResponse> {
const { installationId } = props || {}
if (!installationId) {
throw new IncogniaError('No installationId provided')
}
const data = convertObjectToSnakeCase(props)

return this.resourceRequest({
url: apiEndpoints.ACCOUNTS,
method: Method.Post,
data
})
}

async resourceRequest(options: AxiosRequestConfig) {
await this.updateAccessToken()
try {
Expand Down
15 changes: 0 additions & 15 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,18 +472,3 @@ export enum FeedbackEvent {
SignupDeclined = 'signup_declined',
Verified = 'verified'
}

export type SearchAccountsBodyProps = {
installationId: string
}

export type SearchAccountsResponse = {
count: number
data: Array<AccountData>
}

type AccountData = {
accountId: string
firstEventAt: string
lastEventAt: string
}
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// Generated by genversion.
export const version = '4.5.1'
export const version = '5.0.0'
85 changes: 10 additions & 75 deletions test/incogniaApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,30 +75,6 @@ describe('API', () => {
})
})

it('gets signup assessment', async () => {
const apiResponse = {
id: '5e76a7ca-577c-4f47-a752-9e1e0cee9e49',
request_id: '8afc84a7-f1d4-488d-bd69-36d9a37168b7',
risk_assessment: 'low_risk'
}

const expectedResponse = {
id: '5e76a7ca-577c-4f47-a752-9e1e0cee9e49',
requestId: '8afc84a7-f1d4-488d-bd69-36d9a37168b7',
riskAssessment: 'low_risk'
}

nock(BASE_ENDPOINT_URL)
.get(`/v2/onboarding/signups/${apiResponse.id}`)
.reply(200, apiResponse)

const signupAssessment = await incogniaApi.getSignupAssessment(
apiResponse.id
)

expect(signupAssessment).toEqual(expectedResponse)
})

it('registers signup', async () => {
const apiResponse = {
id: '5e76a7ca-577c-4f47-a752-9e1e0cee9e49',
Expand Down Expand Up @@ -281,51 +257,6 @@ describe('API', () => {
})
})
})

it('retrieves accounts', async () => {
const timestamp = '2022-06-02T22:25:30.885104Z'

const apiResponse = {
count: 2,
data: [
{
account_id: '1',
first_event_at: timestamp,
last_event_at: timestamp
},
{
account_id: '2',
first_event_at: timestamp,
last_event_at: timestamp
}
]
}

const expectedResponse = {
count: 2,
data: [
{
accountId: '1',
firstEventAt: timestamp,
lastEventAt: timestamp
},
{
accountId: '2',
firstEventAt: timestamp,
lastEventAt: timestamp
}
]
}

nock(BASE_ENDPOINT_URL)
.post(`/v2/accounts/search`)
.reply(200, apiResponse)

const accounts = await incogniaApi.searchAccounts({
installationId: 'installation_id'
})
expect(accounts).toEqual(expectedResponse)
})
})

describe('Access token managament', () => {
Expand Down Expand Up @@ -366,25 +297,29 @@ describe('API', () => {

describe('when calling the api ', () => {
it('calls access token endpoint only at the first time', async () => {
const signupId = '123'
const accessTokenEndpointFirstCall = nock(BASE_ENDPOINT_URL)
.post('/v2/token')
.reply(200, accessTokenExample)
const signupEndpointGet = nock(BASE_ENDPOINT_URL)
const signupEndpointRegister = nock(BASE_ENDPOINT_URL)
.persist()
.get(`/v2/onboarding/signups/${signupId}`)
.post(`/v2/onboarding/signups`)
.reply(200)
const accessTokenEndpointSecondCall = nock(BASE_ENDPOINT_URL)
.post('/v2/token')
.reply(200, accessTokenExample)

const payload = {
installationId: 'installation_id',
policyId: 'policy_id'
}

//call resource for the first time
await incogniaApi.getSignupAssessment(signupId)
await incogniaApi.registerSignup(payload)
expect(accessTokenEndpointFirstCall.isDone()).toBeTruthy()
expect(signupEndpointGet.isDone()).toBeTruthy()
expect(signupEndpointRegister.isDone()).toBeTruthy()

//call resource for the second time
await incogniaApi.getSignupAssessment(signupId)
await incogniaApi.registerSignup(payload)
expect(accessTokenEndpointSecondCall.isDone()).toBeFalsy()
})
})
Expand Down

0 comments on commit 5bd0dd5

Please sign in to comment.