Skip to content

Commit

Permalink
fix(docs): Refactor Safe Browsing API documentation and code sample
Browse files Browse the repository at this point in the history
The commit fixes missing block endings in sample code found in `lookup.ts` and `README.md`. The consistency and clarity of code are now improved. Moreover, detailed explanations about function `findThreadMatches` and adjustments to its request and response types have been added to the documentation section.
  • Loading branch information
hckhanh committed Mar 1, 2024
1 parent ad491c7 commit 1106a41
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 28 deletions.
29 changes: 28 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,39 @@ A JavaScript client for [Google Safe Browsing](https://safebrowsing.google.com)

## Features

- [Zero dependency](https://jsr.io/@hckhanh/google-safe-browsing/dependencies)
- [Zero dependencies](https://jsr.io/@hckhanh/google-safe-browsing/dependencies)
- Built-in support for Edge runtime
- Typesafe with TypeScript
- Supports all Google Safe Browsing API v4 endpoints
- Fully documented

## APIs

### findThreadMatches

Finds the threat entries that match the Safe Browsing lists.

```ts
import { findThreadMatches } from '@hckhanh/google-safe-browsing'

const result = await findThreadMatches('apiKey', {
client: {
clientId: 'uniqueClientId',
clientVersion: '1.0.0',
},
threatInfo: {
threatTypes: ['MALWARE', 'SOCIAL_ENGINEERING'],
platformTypes: ['ALL_PLATFORMS'],
threatEntryTypes: ['URL'],
threatEntries: [
{ url: 'http://malware.testing.google.test/testing/malware/' },
],
},
})

const hasRisk = result.matches !== undefined && result.matches.length > 0
```

## Release Notes

You can go to [Releases](https://github.com/hckhanh/google-safe-browsing/releases) page to see the release notes.
Expand Down
47 changes: 20 additions & 27 deletions src/lookup.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,6 @@
import type { ClientInfo, ThreatInfo, ThreatMatch } from './types.ts'
import { endpoint } from './configs.ts'

/**
* @module
* The Lookup API lets your client applications send requests to the Safe Browsing
* servers to check if URLs are included on any of the Safe Browsing lists.
* If a URL is found on one or more lists, the matching information is returned.
*
* @example
* ```ts
* import { findThreadMatches } from '@hckhanh/google-safe-browsing'
*
* const result = await findThreadMatches('apiKey', {
* client: {
* clientId: 'uniqueClientId',
* clientVersion: '1.0.0',
* },
* threatInfo: {
* threatTypes: ['MALWARE', 'SOCIAL_ENGINEERING'],
* platformTypes: ['ALL_PLATFORMS'],
* threatEntryTypes: ['URL'],
* threatEntries: [
* { url: 'http://malware.testing.google.test/testing/malware/' },
* ],
* },
* })
* ```
*/

/**
* The request object containing the parameters for finding thread matches.
*/
Expand Down Expand Up @@ -55,6 +28,26 @@ export type FindThreadMatchesResponse = {
/**
* Finds threat matches using Google Safe Browsing API.
*
* @example
* ```ts
* const result = await findThreadMatches('apiKey', {
* client: {
* clientId: 'uniqueClientId',
* clientVersion: '1.0.0',
* },
* threatInfo: {
* threatTypes: ['MALWARE', 'SOCIAL_ENGINEERING'],
* platformTypes: ['ALL_PLATFORMS'],
* threatEntryTypes: ['URL'],
* threatEntries: [
* { url: 'http://malware.testing.google.test/testing/malware/' },
* ],
* },
* })
*
* const hasRisk = result.matches !== undefined && result.matches.length > 0
* ```
*
* @param apiKey The API key for accessing the Google Safe Browsing API. You should follow the instruction to get the API key at https://developers.google.com/safe-browsing/v4/get-started.
* @param request The request object containing the parameters for finding thread matches.
*
Expand Down

0 comments on commit 1106a41

Please sign in to comment.