Commit 592f79be7b
Unsigned
Layout: unified · split
api/README.md +69 −9
| @@ -1,15 +1,37 @@ | ||
| 1 | 1 | |
| 2 | 2 | # Awesome Privacy API |
| 3 | 3 | |
| 4 | The API allows you to consume the Awesome Privacy data pragmatically. | |
| 5 | It also fetches and exposes additional data for each listing to add context. | |
| 4 | The API allows you to browse awesome-privacy's data programmatically. It also runs some lookups/checks on listings to surface useful insights to add additional context to listings, and save time when comparing software / services. | |
| 6 | 5 | |
| 6 | > [!IMPORTANT] | |
| 7 | > It's very important not to rely on this data for any decision making, as it only gives a very narrow slice of the picture. There's also many real privacy issues which the automated lookups have no way of detecting, as well as the possibility for false positives/negatives. Always do your own research. | |
| 7 | 8 | |
| 8 | ## Usage | |
| 9 | You are free to use the managed instance (`api.awesome-privacy.xyz`) however you like. | |
| 10 | Or, run it locally or deploy your own instance by following the [Deployment](#deployment) steps below. | |
| 9 | These endpoints are used by as part of the website generation, the PR review process and the scheduled listing audits. You're also free to use it for your own purposes. | |
| 11 | 10 | |
| 12 | ### Development | |
| 11 | ## Endpoints | |
| 12 | ||
| 13 | For a full list of endpoints and usage, see the [API Docs](https://api.awesome-privacy.xyz) or download the [`openapi.json`](https://api.awesome-privacy.xyz/openapi.json). | |
| 14 | ||
| 15 | Listing data | |
| 16 | - Categories | |
| 17 | - Sections | |
| 18 | - Listings | |
| 19 | - Search | |
| 20 | - Stats | |
| 21 | ||
| 22 | Enrichment data | |
| 23 | - Privacy policy summary, score and data | |
| 24 | - Known security vulnerabilities and scorecard | |
| 25 | - GitHub repo health, license, versioning, contributors, etc | |
| 26 | - Android trackers, permissions and de-googled compatibility | |
| 27 | - iOS app versioning, size, reviews and info | |
| 28 | - Docker container info | |
| 29 | - Website security and hosting summary | |
| 30 | - Community overview, from Discord, Reddit and Mastadon | |
| 31 | ||
| 32 | --- | |
| 33 | ||
| 34 | ## Development | |
| 13 | 35 | Start by cloning the repo `git clone git@github.com:lissy93/awesome-privacy.git` then `cd awesome-privacy/api` |
| 14 | 36 | |
| 15 | 37 | 1. `bun install` - Install dependencies |
| @@ -20,13 +42,51 @@ Or, to build + run the Docker container, use: | ||
| 20 | 42 | 1. `docker build -t awesome-privacy-api .` |
| 21 | 43 | 2. `docker run -p 8787:8787 --env-file .env awesome-privacy-api` |
| 22 | 44 | |
| 23 | ### Deployment | |
| 45 | Before committing, make sure all checks pass: | |
| 46 | - `bun run lint` - Linting | |
| 47 | - `bun run typecheck` - TS typechecking | |
| 48 | - `bun run format:check` - Check formatting | |
| 49 | - `bun run test` - Run the test suite | |
| 50 | - `bun run smoke` - Quick smoke test | |
| 24 | 51 | |
| 25 | #### Option 1: Docker | |
| 52 | --- | |
| 53 | ||
| 54 | ## Deployment | |
| 26 | 55 | |
| 27 | `docker run lissy93/awesome-privacy-api` | |
| 56 | #### Option 1: Docker | |
| 57 | Use `docker run -p 9000:8787 lissy93/awesome-privacy-api`, then pop open `localhost:9000` | |
| 28 | 58 | |
| 29 | 59 | #### Option 2: Bare Metal |
| 30 | 60 | Follow the [development](#development) setup above, then run `bun start` to start the production server on `:8787` |
| 31 | 61 | |
| 32 | 62 | #### Option 3: Cloudflare |
| 63 | Run `bun run deploy`. You'll need wrangler, and to be authenticated. | |
| 64 | ||
| 65 | <details> | |
| 66 | <summary>authenticating</summary> | |
| 67 | ||
| 68 | I recommend you use API token for this, as then you can scope it as narrowly as possible.<br> | |
| 69 | Head to [dash.cloudflare.com/profile/api-tokens](https://dash.cloudflare.com/profile/api-tokens), then create one just like shown below.<br> | |
| 70 | Then, set `CLOUDFLARE_API_TOKEN` and `CLOUDFLARE_ACCOUNT_ID` env vars in the context you run deploy in. | |
| 71 | ||
| 72 |  | |
| 73 | ||
| 74 | </details> | |
| 75 | ||
| 76 | --- | |
| 77 | ||
| 78 | ## Configuring | |
| 79 | By default no extra config needed. | |
| 80 | ||
| 81 | #### Authentication | |
| 82 | All endpoints are publicly exposed by default. You can change this, by setting an `API_TOKEN` env var, which will then require the `Authorization: Bearer <token>` header on the `/enrich/*` endpoints. | |
| 83 | ||
| 84 | #### Caching | |
| 85 | If a KV is configured, then results from the enrich endpoints can be cached for a configurable amount of time once a success response if returned. This reduces load on upstream services. | |
| 86 | ||
| 87 | #### Third-party fetching | |
| 88 | Some of the enrich endpoints can also fetch from upstream providers to get some additional context. Some of these need API keys, if these keys aren't present, then those checks will just be skipped. | |
| 89 | - `DISCORD_BOT_TOKEN` | |
| 90 | - `APIVOID_API_KEY` | |
| 91 | - `EXODUS_TOKEN` | |
| 92 | - `GITHUB_TOKEN` | |
api/src/app.ts +28 −6
| @@ -87,8 +87,34 @@ export const buildApp = () => { | ||
| 87 | 87 | > There's also many real privacy issues which the automated lookups have no way of detecting, |
| 88 | 88 | > as well as the possibility for false positives/negatives. |
| 89 | 89 | > **Always do your own research**. |
| 90 | ||
| 91 | <details> | |
| 92 | <summary>Authenticating</summary> | |
| 93 | ||
| 94 | By default, no auth is needed. | |
| 95 | If you're self-hosting, you can enable auth by setting the \`API_KEY\` env var. | |
| 96 | Then, add the \`Authorization: Bearer <your-token>\` header when accessing the enrichment endpoints. | |
| 97 | </details> | |
| 98 | ||
| 99 | <details> | |
| 100 | <summary>Caching</summary> | |
| 101 | ||
| 102 | Some responses are cached to reduce load on upstream services. | |
| 103 | When configured, successful enrichment data results are put in KV for upto 7 days. | |
| 104 | </details> | |
| 105 | ||
| 106 | <details> | |
| 107 | <summary>Self-Hosting</summary> | |
| 108 | ||
| 109 | See the [repo](https://github.com/lissy93/awesome-privacy/tree/main/api) for | |
| 110 | deployment and development guides, as well as instructions for self-hosting, contributing and usage. | |
| 111 | </details> | |
| 112 | ||
| 90 | 113 | ` |
| 91 | 114 | |
| 115 | const publicDescription = 'Endpoints to browse the awesome-privacy dataset programatically'; | |
| 116 | const enrichDescription = 'Endpoints to fetch additional data about listings from external sources'; | |
| 117 | ||
| 92 | 118 | // OpenAPI document plus Scalar UI |
| 93 | 119 | app.doc('/openapi.json', { |
| 94 | 120 | openapi: '3.0.0', |
| @@ -99,11 +125,8 @@ export const buildApp = () => { | ||
| 99 | 125 | }, |
| 100 | 126 | servers: [{ url: '/' }], |
| 101 | 127 | tags: [ |
| 102 | { name: 'Public', description: 'Open, cached, served from the local dataset' }, | |
| 103 | { | |
| 104 | name: 'Enrichment', | |
| 105 | description: 'Bearer-auth routes that proxy + cache third-party data', | |
| 106 | }, | |
| 128 | { name: 'Public', description: publicDescription }, | |
| 129 | { name: 'Enrichment', description: enrichDescription }, | |
| 107 | 130 | ], |
| 108 | 131 | }) |
| 109 | 132 | const blurb = 'Browse awesome-privacy data and enrichment insights programmatically.' |
| @@ -115,7 +138,6 @@ export const buildApp = () => { | ||
| 115 | 138 | persistAuth: true, |
| 116 | 139 | favicon: 'https://awesome-privacy.xyz/favicon.svg', |
| 117 | 140 | operationTitleSource: 'summary', |
| 118 | tagsSorter: 'alpha', | |
| 119 | 141 | operationsSorter: 'alpha', |
| 120 | 142 | orderRequiredPropertiesFirst: true, |
| 121 | 143 | mcp: { name: 'Awesome Privacy', url: '/v1/mcp' }, |
api/src/routes/public/categories.ts +3 −3
| @@ -25,7 +25,7 @@ const listCategories = createRoute({ | ||
| 25 | 25 | method: 'get', |
| 26 | 26 | path: '/categories', |
| 27 | 27 | tags: ['Public'], |
| 28 | summary: 'List all categories with section summaries', | |
| 28 | summary: 'List categories', | |
| 29 | 29 | responses: { |
| 30 | 30 | 200: Ok(ListEnvelope(CategorySchema)), |
| 31 | 31 | }, |
| @@ -48,7 +48,7 @@ const oneCategory = createRoute({ | ||
| 48 | 48 | method: 'get', |
| 49 | 49 | path: '/categories/{slug}', |
| 50 | 50 | tags: ['Public'], |
| 51 | summary: 'One category by slug', | |
| 51 | summary: 'Get category', | |
| 52 | 52 | request: { params: z.object({ slug: z.string() }) }, |
| 53 | 53 | responses: { |
| 54 | 54 | 200: Ok(Envelope(CategorySchema)), |
| @@ -76,7 +76,7 @@ const oneSection = createRoute({ | ||
| 76 | 76 | method: 'get', |
| 77 | 77 | path: '/sections/{slug}', |
| 78 | 78 | tags: ['Public'], |
| 79 | summary: 'One section by slug, with services', | |
| 79 | summary: 'Get section', | |
| 80 | 80 | request: { params: z.object({ slug: z.string() }) }, |
| 81 | 81 | responses: { |
| 82 | 82 | 200: Ok(Envelope(SectionSchema)), |
api/src/routes/public/search.ts +1 −1
| @@ -15,7 +15,7 @@ const route = createRoute({ | ||
| 15 | 15 | method: 'get', |
| 16 | 16 | path: '/search', |
| 17 | 17 | tags: ['Public'], |
| 18 | summary: 'Full-text search across services', | |
| 18 | summary: 'Search', | |
| 19 | 19 | request: { query: querySchema }, |
| 20 | 20 | responses: { |
| 21 | 21 | 200: Ok(ListEnvelope(SearchHitSchema)), |
api/src/routes/public/services.ts +2 −2
| @@ -11,7 +11,7 @@ const listRoute = createRoute({ | ||
| 11 | 11 | method: 'get', |
| 12 | 12 | path: '/services', |
| 13 | 13 | tags: ['Public'], |
| 14 | summary: 'List services with filters and pagination', | |
| 14 | summary: 'List services', | |
| 15 | 15 | request: { |
| 16 | 16 | query: z.object({ |
| 17 | 17 | category: z.string().optional(), |
| @@ -48,7 +48,7 @@ const oneRoute = createRoute({ | ||
| 48 | 48 | method: 'get', |
| 49 | 49 | path: '/services/{slug}', |
| 50 | 50 | tags: ['Public'], |
| 51 | summary: 'One service by slug', | |
| 51 | summary: 'Get service', | |
| 52 | 52 | request: { params: z.object({ slug: z.string() }) }, |
| 53 | 53 | responses: { |
| 54 | 54 | 200: Ok(Envelope(FlatServiceSchema)), |
api/src/routes/public/stats.ts +2 −2
| @@ -10,7 +10,7 @@ const statsRoute = createRoute({ | ||
| 10 | 10 | method: 'get', |
| 11 | 11 | path: '/stats', |
| 12 | 12 | tags: ['Public'], |
| 13 | summary: 'Dataset-wide counts', | |
| 13 | summary: 'Stats', | |
| 14 | 14 | responses: { 200: Ok(Envelope(StatsSchema)) }, |
| 15 | 15 | }) |
| 16 | 16 | |
| @@ -20,7 +20,7 @@ const healthRoute = createRoute({ | ||
| 20 | 20 | method: 'get', |
| 21 | 21 | path: '/health', |
| 22 | 22 | tags: ['Public'], |
| 23 | summary: 'Liveness check', | |
| 23 | summary: 'Health', | |
| 24 | 24 | responses: { 200: Ok(Envelope(HealthSchema)) }, |
| 25 | 25 | }) |
| 26 | 26 | |