-
Notifications
You must be signed in to change notification settings - Fork 53
feat: Add Radar to Node SDK #1596
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gjtorikian
wants to merge
1
commit into
main
Choose a base branch
from
add-radar
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/radar/fixtures/radar-list-entry-already-present-response.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "message": "Entry already present in list" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "ip_address": "49.78.240.97", | ||
| "user_agent": "Mozilla/5.0", | ||
| "email": "user@example.com", | ||
| "auth_method": "Password", | ||
| "action": "sign-in" | ||
| } |
3 changes: 3 additions & 0 deletions
3
src/radar/fixtures/radar-standalone-delete-radar-list-entry-request.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "entry": "198.51.100.42" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "verdict": "block", | ||
| "reason": "Detected enabled Radar control", | ||
| "attempt_id": "radar_att_01HZBC6N1EB1ZY7KG32X", | ||
| "control": "bot_detection", | ||
| "blocklist_type": "ip_address" | ||
| } |
4 changes: 4 additions & 0 deletions
4
src/radar/fixtures/radar-standalone-update-radar-attempt-request.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "challenge_status": "success", | ||
| "attempt_status": "success" | ||
| } |
3 changes: 3 additions & 0 deletions
3
src/radar/fixtures/radar-standalone-update-radar-list-request.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "entry": "198.51.100.42" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // This file is auto-generated by oagen. Do not edit. | ||
|
|
||
| export * from './radar-list-action.interface'; | ||
| export * from './radar-list-entry-already-present-response.interface'; | ||
| export * from './radar-standalone-assess-request-action.interface'; | ||
| export * from './radar-standalone-assess-request-auth-method.interface'; | ||
| export * from './radar-standalone-assess-request.interface'; | ||
| export * from './radar-standalone-delete-radar-list-entry-request.interface'; | ||
| export * from './radar-standalone-response-blocklist-type.interface'; | ||
| export * from './radar-standalone-response-control.interface'; | ||
| export * from './radar-standalone-response-verdict.interface'; | ||
| export * from './radar-standalone-response.interface'; | ||
| export * from './radar-standalone-update-radar-attempt-request.interface'; | ||
| export * from './radar-standalone-update-radar-list-request.interface'; | ||
| export * from './radar-type.interface'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| // This file is auto-generated by oagen. Do not edit. | ||
|
|
||
| export const RadarListAction = { | ||
| Block: 'block', | ||
| Allow: 'allow', | ||
| } as const; | ||
|
|
||
| export type RadarListAction = | ||
| (typeof RadarListAction)[keyof typeof RadarListAction]; |
10 changes: 10 additions & 0 deletions
10
src/radar/interfaces/radar-list-entry-already-present-response.interface.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // This file is auto-generated by oagen. Do not edit. | ||
|
|
||
| export interface RadarListEntryAlreadyPresentResponse { | ||
| /** A message indicating the entry already exists. */ | ||
| message: string; | ||
| } | ||
|
|
||
| export interface RadarListEntryAlreadyPresentResponseWire { | ||
| message: string; | ||
| } |
9 changes: 9 additions & 0 deletions
9
src/radar/interfaces/radar-standalone-assess-request-action.interface.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| // This file is auto-generated by oagen. Do not edit. | ||
|
|
||
| export const RadarStandaloneAssessRequestAction = { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we narrow this to just be "sign-up" and "sign-in"? I'm also looking at the public docs, and we support like a lot of different variations, but I think that's just iterations. Wonder if we can only show these two options publicly to try and get users to send the right one. |
||
| SignUp: 'sign-up', | ||
| SignIn: 'sign-in', | ||
| } as const; | ||
|
|
||
| export type RadarStandaloneAssessRequestAction = | ||
| (typeof RadarStandaloneAssessRequestAction)[keyof typeof RadarStandaloneAssessRequestAction]; | ||
15 changes: 15 additions & 0 deletions
15
src/radar/interfaces/radar-standalone-assess-request-auth-method.interface.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // This file is auto-generated by oagen. Do not edit. | ||
|
|
||
| export const RadarStandaloneAssessRequestAuthMethod = { | ||
| Password: 'Password', | ||
| Passkey: 'Passkey', | ||
| Authenticator: 'Authenticator', | ||
| SmsOtp: 'SMS_OTP', | ||
| EmailOtp: 'Email_OTP', | ||
| Social: 'Social', | ||
| SSO: 'SSO', | ||
| Other: 'Other', | ||
| } as const; | ||
|
|
||
| export type RadarStandaloneAssessRequestAuthMethod = | ||
| (typeof RadarStandaloneAssessRequestAuthMethod)[keyof typeof RadarStandaloneAssessRequestAuthMethod]; |
25 changes: 25 additions & 0 deletions
25
src/radar/interfaces/radar-standalone-assess-request.interface.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| // This file is auto-generated by oagen. Do not edit. | ||
|
|
||
| import type { RadarStandaloneAssessRequestAuthMethod } from './radar-standalone-assess-request-auth-method.interface'; | ||
| import type { RadarStandaloneAssessRequestAction } from './radar-standalone-assess-request-action.interface'; | ||
|
|
||
| export interface RadarStandaloneAssessRequest { | ||
| /** The IP address of the request to assess. */ | ||
| ipAddress: string; | ||
| /** The user agent string of the request to assess. */ | ||
| userAgent: string; | ||
| /** The email address of the user making the request. */ | ||
| email: string; | ||
| /** The authentication method being used. */ | ||
| authMethod: RadarStandaloneAssessRequestAuthMethod; | ||
| /** The action being performed. */ | ||
| action: RadarStandaloneAssessRequestAction; | ||
| } | ||
|
|
||
| export interface RadarStandaloneAssessRequestResponse { | ||
| ip_address: string; | ||
| user_agent: string; | ||
| email: string; | ||
| auth_method: RadarStandaloneAssessRequestAuthMethod; | ||
| action: RadarStandaloneAssessRequestAction; | ||
| } |
10 changes: 10 additions & 0 deletions
10
src/radar/interfaces/radar-standalone-delete-radar-list-entry-request.interface.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // This file is auto-generated by oagen. Do not edit. | ||
|
|
||
| export interface RadarStandaloneDeleteRadarListEntryRequest { | ||
| /** The value to remove from the list. Must match an existing entry. */ | ||
| entry: string; | ||
| } | ||
|
|
||
| export interface RadarStandaloneDeleteRadarListEntryRequestResponse { | ||
| entry: string; | ||
| } |
14 changes: 14 additions & 0 deletions
14
src/radar/interfaces/radar-standalone-response-blocklist-type.interface.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // This file is auto-generated by oagen. Do not edit. | ||
|
|
||
| export const RadarStandaloneResponseBlocklistType = { | ||
| IpAddress: 'ip_address', | ||
| Domain: 'domain', | ||
| Email: 'email', | ||
| Device: 'device', | ||
| UserAgent: 'user_agent', | ||
| DeviceFingerprint: 'device_fingerprint', | ||
| Country: 'country', | ||
| } as const; | ||
|
gjtorikian marked this conversation as resolved.
|
||
|
|
||
| export type RadarStandaloneResponseBlocklistType = | ||
| (typeof RadarStandaloneResponseBlocklistType)[keyof typeof RadarStandaloneResponseBlocklistType]; | ||
15 changes: 15 additions & 0 deletions
15
src/radar/interfaces/radar-standalone-response-control.interface.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // This file is auto-generated by oagen. Do not edit. | ||
|
|
||
| export const RadarStandaloneResponseControl = { | ||
| BotDetection: 'bot_detection', | ||
| BruteForceAttack: 'brute_force_attack', | ||
| DomainSignUpRateLimit: 'domain_sign_up_rate_limit', | ||
| ImpossibleTravel: 'impossible_travel', | ||
| RepeatSignUp: 'repeat_sign_up', | ||
| StaleAccount: 'stale_account', | ||
| UnrecognizedDevice: 'unrecognized_device', | ||
| Restriction: 'restriction', | ||
| } as const; | ||
|
|
||
| export type RadarStandaloneResponseControl = | ||
| (typeof RadarStandaloneResponseControl)[keyof typeof RadarStandaloneResponseControl]; |
10 changes: 10 additions & 0 deletions
10
src/radar/interfaces/radar-standalone-response-verdict.interface.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // This file is auto-generated by oagen. Do not edit. | ||
|
|
||
| export const RadarStandaloneResponseVerdict = { | ||
| Allow: 'allow', | ||
| Block: 'block', | ||
| Challenge: 'challenge', | ||
| } as const; | ||
|
|
||
| export type RadarStandaloneResponseVerdict = | ||
| (typeof RadarStandaloneResponseVerdict)[keyof typeof RadarStandaloneResponseVerdict]; |
26 changes: 26 additions & 0 deletions
26
src/radar/interfaces/radar-standalone-response.interface.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // This file is auto-generated by oagen. Do not edit. | ||
|
|
||
| import type { RadarStandaloneResponseVerdict } from './radar-standalone-response-verdict.interface'; | ||
| import type { RadarStandaloneResponseControl } from './radar-standalone-response-control.interface'; | ||
| import type { RadarStandaloneResponseBlocklistType } from './radar-standalone-response-blocklist-type.interface'; | ||
|
|
||
| export interface RadarStandaloneResponse { | ||
| /** The verdict of the risk assessment. */ | ||
| verdict: RadarStandaloneResponseVerdict; | ||
| /** A human-readable reason for the verdict. */ | ||
| reason: string; | ||
| /** Unique identifier of the authentication attempt. */ | ||
| attemptId: string; | ||
| /** The Radar control that triggered the verdict. Only present if the verdict is `block` or `challenge`. */ | ||
| control?: RadarStandaloneResponseControl; | ||
| /** The type of blocklist entry that triggered the verdict. Only present if the control is `restriction`. */ | ||
| blocklistType?: RadarStandaloneResponseBlocklistType; | ||
| } | ||
|
|
||
| export interface RadarStandaloneResponseWire { | ||
| verdict: RadarStandaloneResponseVerdict; | ||
| reason: string; | ||
| attempt_id: string; | ||
| control?: RadarStandaloneResponseControl; | ||
| blocklist_type?: RadarStandaloneResponseBlocklistType; | ||
| } |
13 changes: 13 additions & 0 deletions
13
src/radar/interfaces/radar-standalone-update-radar-attempt-request.interface.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| // This file is auto-generated by oagen. Do not edit. | ||
|
|
||
| export interface RadarStandaloneUpdateRadarAttemptRequest { | ||
| /** Set to `"success"` to mark the challenge as completed. */ | ||
| challengeStatus?: 'success'; | ||
| /** Set to `"success"` to mark the authentication attempt as successful. */ | ||
| attemptStatus?: 'success'; | ||
| } | ||
|
|
||
| export interface RadarStandaloneUpdateRadarAttemptRequestResponse { | ||
| challenge_status?: 'success'; | ||
| attempt_status?: 'success'; | ||
| } |
10 changes: 10 additions & 0 deletions
10
src/radar/interfaces/radar-standalone-update-radar-list-request.interface.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // This file is auto-generated by oagen. Do not edit. | ||
|
|
||
| export interface RadarStandaloneUpdateRadarListRequest { | ||
| /** The value to add to the list. Must match the format of the list type (e.g. a valid IP address for `ip_address`, a valid email for `email`). */ | ||
| entry: string; | ||
| } | ||
|
|
||
| export interface RadarStandaloneUpdateRadarListRequestResponse { | ||
| entry: string; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| // This file is auto-generated by oagen. Do not edit. | ||
|
|
||
| export const RadarType = { | ||
| IpAddress: 'ip_address', | ||
| Domain: 'domain', | ||
| Email: 'email', | ||
| Device: 'device', | ||
| UserAgent: 'user_agent', | ||
| DeviceFingerprint: 'device_fingerprint', | ||
| Country: 'country', | ||
| } as const; | ||
|
|
||
| export type RadarType = (typeof RadarType)[keyof typeof RadarType]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| // This file is auto-generated by oagen. Do not edit. | ||
|
|
||
| import fetch from 'jest-fetch-mock'; | ||
| import { | ||
| fetchOnce, | ||
| fetchURL, | ||
| fetchMethod, | ||
| fetchBody, | ||
| } from '../common/utils/test-utils'; | ||
| import { WorkOS } from '../workos'; | ||
|
|
||
| import radarStandaloneResponseFixture from './fixtures/radar-standalone-response.json'; | ||
| import radarListEntryAlreadyPresentResponseFixture from './fixtures/radar-list-entry-already-present-response.json'; | ||
|
|
||
| const workos = new WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU'); | ||
|
|
||
| describe('Radar', () => { | ||
| beforeEach(() => fetch.resetMocks()); | ||
|
|
||
| describe('createAttempt', () => { | ||
| it('sends the correct request and returns result', async () => { | ||
| fetchOnce(radarStandaloneResponseFixture); | ||
|
|
||
| const result = await workos.radar.createAttempt({ | ||
| ipAddress: 'test_ip_address', | ||
| userAgent: 'test_user_agent', | ||
| email: 'test@example.com', | ||
| authMethod: 'Password', | ||
| action: 'sign-up', | ||
| }); | ||
|
|
||
| expect(fetchMethod()).toBe('POST'); | ||
| expect(new URL(String(fetchURL())).pathname).toBe('/radar/attempts'); | ||
| expect(fetchBody()).toEqual( | ||
| expect.objectContaining({ | ||
| ip_address: 'test_ip_address', | ||
| user_agent: 'test_user_agent', | ||
| email: 'test@example.com', | ||
| auth_method: 'Password', | ||
| action: 'sign-up', | ||
| }), | ||
| ); | ||
| expect(result.verdict).toBe('block'); | ||
| expect(result.reason).toBe('Detected enabled Radar control'); | ||
| expect(result.attemptId).toBe('radar_att_01HZBC6N1EB1ZY7KG32X'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('updateAttempt', () => { | ||
| it('sends the request', async () => { | ||
| fetchOnce({}); | ||
|
|
||
| await workos.radar.updateAttempt('test_id', { | ||
| challengeStatus: 'success', | ||
| attemptStatus: 'success', | ||
| }); | ||
|
|
||
| expect(fetchMethod()).toBe('PUT'); | ||
| expect(new URL(String(fetchURL())).pathname).toBe( | ||
| '/radar/attempts/test_id', | ||
| ); | ||
| expect(fetchBody()).toEqual( | ||
| expect.objectContaining({ | ||
| challenge_status: 'success', | ||
| attempt_status: 'success', | ||
| }), | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe('addListEntry', () => { | ||
| it('sends the correct request and returns result', async () => { | ||
| fetchOnce(radarListEntryAlreadyPresentResponseFixture); | ||
|
|
||
| const result = await workos.radar.addListEntry('ip_address', 'block', { | ||
| entry: 'test_entry', | ||
| }); | ||
|
|
||
| expect(fetchMethod()).toBe('POST'); | ||
| expect(new URL(String(fetchURL())).pathname).toBe( | ||
| '/radar/lists/ip_address/block', | ||
| ); | ||
| expect(fetchBody()).toEqual( | ||
| expect.objectContaining({ entry: 'test_entry' }), | ||
| ); | ||
| expect(result.message).toBe('Entry already present in list'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('removeListEntry', () => { | ||
| it('sends a DELETE request', async () => { | ||
| fetchOnce({}, { status: 204 }); | ||
|
|
||
| await workos.radar.removeListEntry('ip_address', 'block', { | ||
| entry: 'test_entry', | ||
| }); | ||
|
|
||
| expect(fetchMethod()).toBe('DELETE'); | ||
| expect(new URL(String(fetchURL())).pathname).toBe( | ||
| '/radar/lists/ip_address/block', | ||
| ); | ||
| expect(fetchBody()).toEqual( | ||
| expect.objectContaining({ entry: 'test_entry' }), | ||
| ); | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.