Skip to content

Commit 8a2df31

Browse files
authored
Add support for Risk Intelligence Retrieve endpoint (#12)
* Bump version, add response types, reorganize files * wip client * Add support for Risk Intelligence retrieve, add tests * Call risk intelligence retrieve regardless of captcha state in example * Simplify example in readme * Make example print error on missing risk intelligence * Update to Node 22.x in CI * Add missing API error codes
1 parent 4616694 commit 8a2df31

23 files changed

Lines changed: 2339 additions & 1832 deletions

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ jobs:
1616
steps:
1717
- uses: actions/checkout@v3
1818

19-
- name: Use Node.js 18.x
19+
- name: Use Node.js 22.x
2020
uses: actions/setup-node@v3
2121
with:
22-
node-version: 18.x
22+
node-version: 22.x
2323
cache: "npm"
2424
cache-dependency-path: "package-lock.json"
2525

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- uses: actions/checkout@v4
1515
- uses: actions/setup-node@v3
1616
with:
17-
node-version: '20.x'
17+
node-version: '22.x'
1818
registry-url: 'https://registry.npmjs.org'
1919
- run: npm install -g npm@latest
2020
- run: npm ci

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## 0.3.0
4+
5+
* Adds support for the Risk Intelligence Retrieve API.
6+
* Update dev dependencies.
7+
* Internal rename of `SiteverifyErrorCode` to `APIErrorCode`.
8+
* Rename of `VerifyClientErrorCode` to `ClientErrorCode`.
9+
310
## 0.2.0
411

512
* Add support for *Risk Intelligence* data in siteverify responses.

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,34 @@ console.log(result.wasAbleToVerify()); // false
7979
console.log(result.shouldAccept()); // false
8080
```
8181

82+
### Retrieving Risk Intelligence
83+
84+
You can retrieve risk intelligence data for a given token. This provides detailed information about the risk profile of a request, including network data, geolocation, browser details, and risk scores.
85+
86+
```javascript
87+
const result = await frcClient.retrieveRiskIntelligence("RISK_INTELLIGENCE_TOKEN_HERE");
88+
89+
// Check if we were able to retrieve the risk intelligence data
90+
if (result.wasAbleToRetrieve()) {
91+
// Check if the token is valid and data was retrieved successfully
92+
if (result.isValid()) {
93+
const response = result.getResponse();
94+
console.log("Risk Intelligence Data:", response.data);
95+
} else {
96+
// Token was invalid or expired
97+
const error = result.getResponseError();
98+
console.log("Error:", error?.error_code, error?.detail);
99+
}
100+
} else {
101+
// Network issue or configuration problem
102+
if (result.isClientError()) {
103+
console.log("Configuration error - check your API key");
104+
} else {
105+
console.log("Network issue or service temporarily unavailable");
106+
}
107+
}
108+
```
109+
82110
### Configuration
83111
84112
### Configuration

etc/server-sdk.api.md

Lines changed: 88 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
55
```ts
66

7+
// @public (undocumented)
8+
export type ClientErrorCode = typeof FAILED_TO_ENCODE_ERROR_CODE | typeof REQUEST_FAILED_ERROR_CODE | typeof REQUEST_FAILED_TIMEOUT_ERROR_CODE | typeof FAILED_DUE_TO_CLIENT_ERROR_CODE | typeof FAILED_TO_DECODE_RESPONSE_ERROR_CODE;
9+
710
// @public
811
export const FAILED_DUE_TO_CLIENT_ERROR_CODE = "request_failed_due_to_client_error";
912

@@ -16,6 +19,12 @@ export const FAILED_TO_ENCODE_ERROR_CODE = "failed_to_encode_request";
1619
// @public
1720
export class FriendlyCaptchaClient {
1821
constructor(opts: FriendlyCaptchaOptions);
22+
// @internal
23+
getSiteverifyEndpoint(): string;
24+
retrieveRiskIntelligence(token: string, opts?: {
25+
timeout?: number;
26+
sitekey?: string;
27+
}): Promise<RiskIntelligenceRetrieveResult>;
1928
verifyCaptchaResponse(response: string, opts?: {
2029
timeout?: number;
2130
sitekey?: string;
@@ -24,10 +33,12 @@ export class FriendlyCaptchaClient {
2433

2534
// @public
2635
export interface FriendlyCaptchaOptions {
36+
apiEndpoint?: string;
2737
apiKey: string;
2838
fetch?: typeof globalThis.fetch;
2939
// (undocumented)
3040
sitekey?: string;
41+
// @deprecated (undocumented)
3142
siteverifyEndpoint?: string;
3243
strict?: boolean;
3344
}
@@ -38,6 +49,76 @@ export const REQUEST_FAILED_ERROR_CODE = "request_failed";
3849
// @public
3950
export const REQUEST_FAILED_TIMEOUT_ERROR_CODE = "request_failed_due_to_timeout";
4051

52+
// @public (undocumented)
53+
export interface RiskIntelligenceRetrieveErrorResponse {
54+
// (undocumented)
55+
error: RiskIntelligenceRetrieveErrorResponseErrorData;
56+
// (undocumented)
57+
success: false;
58+
}
59+
60+
// @public (undocumented)
61+
export interface RiskIntelligenceRetrieveErrorResponseErrorData {
62+
// (undocumented)
63+
detail: string;
64+
// Warning: (ae-forgotten-export) The symbol "APIErrorCode" needs to be exported by the entry point index.d.ts
65+
//
66+
// (undocumented)
67+
error_code: APIErrorCode;
68+
}
69+
70+
// Warning: (ae-internal-missing-underscore) The name "RiskIntelligenceRetrieveRequest" should be prefixed with an underscore because the declaration is marked as @internal
71+
//
72+
// @internal
73+
export interface RiskIntelligenceRetrieveRequest {
74+
sitekey?: string;
75+
token: string;
76+
}
77+
78+
// @public (undocumented)
79+
export type RiskIntelligenceRetrieveResponse = RiskIntelligenceRetrieveSuccessResponse | RiskIntelligenceRetrieveErrorResponse;
80+
81+
// @public
82+
export interface RiskIntelligenceRetrieveResponseData {
83+
// (undocumented)
84+
event_id: string;
85+
// Warning: (ae-forgotten-export) The symbol "RiskIntelligenceData" needs to be exported by the entry point index.d.ts
86+
risk_intelligence: RiskIntelligenceData;
87+
token: RiskIntelligenceTokenData;
88+
}
89+
90+
// @public
91+
export class RiskIntelligenceRetrieveResult {
92+
// (undocumented)
93+
clientErrorType: ClientErrorCode | null;
94+
// (undocumented)
95+
getResponse(): RiskIntelligenceRetrieveResponse | null;
96+
// (undocumented)
97+
getResponseError(): RiskIntelligenceRetrieveErrorResponseErrorData | null;
98+
isClientError(): boolean;
99+
// (undocumented)
100+
isValid(): boolean;
101+
response: RiskIntelligenceRetrieveResponse | null;
102+
status: number;
103+
wasAbleToRetrieve(): boolean;
104+
}
105+
106+
// @public (undocumented)
107+
export interface RiskIntelligenceRetrieveSuccessResponse {
108+
// (undocumented)
109+
data: RiskIntelligenceRetrieveResponseData;
110+
// (undocumented)
111+
success: true;
112+
}
113+
114+
// @public
115+
export interface RiskIntelligenceTokenData {
116+
expires_at: string;
117+
num_uses: number;
118+
origin: string;
119+
timestamp: string;
120+
}
121+
41122
// @public (undocumented)
42123
export interface SiteverifyErrorResponse {
43124
// (undocumented)
@@ -50,10 +131,8 @@ export interface SiteverifyErrorResponse {
50131
export interface SiteverifyErrorResponseErrorData {
51132
// (undocumented)
52133
detail: string;
53-
// Warning: (ae-forgotten-export) The symbol "SiteverifyErrorCode" needs to be exported by the entry point index.d.ts
54-
//
55134
// (undocumented)
56-
error_code: SiteverifyErrorCode;
135+
error_code: APIErrorCode;
57136
}
58137

59138
// Warning: (ae-internal-missing-underscore) The name "SiteverifyRequest" should be prefixed with an underscore because the declaration is marked as @internal
@@ -75,8 +154,9 @@ export interface SiteverifyResponseChallengeData {
75154

76155
// @public (undocumented)
77156
export interface SiteverifyResponseData {
78-
// (undocumented)
79157
challenge: SiteverifyResponseChallengeData;
158+
event_id: string;
159+
risk_intelligence: RiskIntelligenceData | null;
80160
}
81161

82162
// @public (undocumented)
@@ -87,16 +167,16 @@ export interface SiteverifySuccessResponse {
87167
success: true;
88168
}
89169

90-
// @public (undocumented)
91-
export type VerifyClientErrorCode = typeof FAILED_TO_ENCODE_ERROR_CODE | typeof REQUEST_FAILED_ERROR_CODE | typeof REQUEST_FAILED_TIMEOUT_ERROR_CODE | typeof FAILED_DUE_TO_CLIENT_ERROR_CODE | typeof FAILED_TO_DECODE_RESPONSE_ERROR_CODE;
170+
// @public @deprecated (undocumented)
171+
export type VerifyClientErrorCode = ClientErrorCode;
92172

93173
// @public
94174
export class VerifyResult {
95175
constructor(strict: boolean);
96176
// (undocumented)
97-
clientErrorType: VerifyClientErrorCode | null;
177+
clientErrorType: ClientErrorCode | null;
98178
// (undocumented)
99-
getErrorCode(): VerifyClientErrorCode | null;
179+
getErrorCode(): ClientErrorCode | null;
100180
// (undocumented)
101181
getResponse(): SiteverifyResponse | null;
102182
// (undocumented)

0 commit comments

Comments
 (0)