Skip to content

Commit

Permalink
feat: migrate to GoogleSafeBrowsing class instead of functions (#22)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Replaced functions with the GoogleSafeBrowsing class for cleaner and more structured code. Updated relevant tests and import statements to align with the new class-based implementation. Adjusted documentation in README to reflect these changes, providing examples and updated descriptions for using the new class.
  • Loading branch information
hckhanh authored Dec 1, 2024
1 parent 9861848 commit 1fa6322
Show file tree
Hide file tree
Showing 14 changed files with 412 additions and 519 deletions.
3 changes: 3 additions & 0 deletions .codacy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
exclude_paths:
- 'src/**/*.test.ts'
4 changes: 1 addition & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install jq
uses: dcarbone/install-jq-action@v2
- name: Setup pnpm
uses: pnpm/action-setup@v3
uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2
- name: Setup Node.js
uses: actions/setup-node@v4
with:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Setup pnpm
uses: pnpm/action-setup@v3
uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2
- uses: actions/setup-node@v4
with:
node-version: 'lts/*'
Expand All @@ -36,7 +36,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Setup pnpm
uses: pnpm/action-setup@v3
uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2
- name: Set up Node.js ${{matrix.node}}
uses: actions/setup-node@v4
with:
Expand All @@ -55,7 +55,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Setup pnpm
uses: pnpm/action-setup@v3
uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2
- name: Set up Node.js
uses: actions/setup-node@v4
with:
Expand All @@ -74,6 +74,6 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Install Deno
uses: denoland/setup-deno@v1
uses: denoland/setup-deno@4606d5cc6fb3f673efd4f594850e3f4b3e9d29cd
- name: Type-check the dependencies
run: deno check src/index.ts
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ node_modules/

# macOS
.DS_Store

# environment variables
.env*
19 changes: 13 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# google-safe-browsing

[![JSR](https://jsr.io/badges/@hckhanh/google-safe-browsing)](https://jsr.io/@hckhanh/google-safe-browsing)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/be4f5f8019a743f3878358399c110a36)](https://app.codacy.com/gh/hckhanh/google-safe-browsing/dashboard)

A JavaScript client for [Google Safe Browsing](https://safebrowsing.google.com) [API](https://developers.google.com/safe-browsing)
Expand All @@ -9,19 +10,21 @@ A JavaScript client for [Google Safe Browsing](https://safebrowsing.google.com)
- [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
- Supports some common cases
- Fully documented

## APIs

### findThreadMatches
### threatMatches.find

Finds the threat entries that match the Safe Browsing lists.

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

const result = await findThreadMatches('apiKey', {
const client = new GoogleSafeBrowsing('apiKey')

const result = await client.findThreatMatches({
client: {
clientId: 'uniqueClientId',
clientVersion: '1.0.0',
Expand All @@ -44,5 +47,9 @@ const hasRisk = result.matches !== undefined && result.matches.length > 0
You can go to the [Releases](https://github.com/hckhanh/google-safe-browsing/releases) page to see the release notes.

> [!NOTE]
> The Safe Browsing API is for non-commercial use only. If you need to use APIs to detect malicious URLs for commercial
> purposes - meaning 'for sale or revenue-generating purposes' - please refer to the [Web Risk API](https://github.com/hckhanh/google-web-risk).
> Enables client applications to check web resources (most commonly URLs)
> against Google-generated lists of unsafe web resources.
> The Safe Browsing APIs are for non-commercial use only.
> If you need to use APIs to detect malicious URLs for commercial purposes –
> meaning “for sale or revenue-generating purposes” –
> please refer to the [Web Risk API](https://github.com/hckhanh/google-web-risk).
6 changes: 4 additions & 2 deletions jsr.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"name": "@hckhanh/google-safe-browsing",
"version": "0.0.0-development",
"exports": "./src/index.ts",
"include": ["src/**", "README.md", "jsr.json", "LICENSE"],
"exclude": ["src/**/*.test.ts"]
"publish": {
"include": ["src/**", "README.md", "jsr.json", "LICENSE"],
"exclude": ["src/**/*.test.ts"]
}
}
19 changes: 10 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
"sideEffects": false,
"scripts": {
"test": "vitest related src/*.ts",
"test:prettier": "prettier --check ."
"test:prettier": "prettier --check .",
"test:types": "deno check src/index.ts"
},
"author": {
"name": "Khánh Hoàng",
"email": "hi@khanh.sh",
"url": "https://khanh.sh"
"email": "hi@khanh.id",
"url": "https://khanh.id"
},
"license": "MIT",
"keywords": [
Expand All @@ -24,11 +25,11 @@
"url"
],
"devDependencies": {
"@edge-runtime/vm": "3.2.0",
"@types/node": "22.10.0",
"prettier": "3.2.5",
"typescript": "5.4.3",
"vitest": "1.3.1"
"@edge-runtime/vm": "4.0.4",
"@types/node": "22.10.1",
"prettier": "3.4.1",
"typescript": "5.7.2",
"vitest": "2.1.6"
},
"packageManager": "[email protected].3"
"packageManager": "[email protected].4"
}
Loading

0 comments on commit 1fa6322

Please sign in to comment.