-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into feat/add-advanced-f…
…iltering-capabilities Signed-off-by: Avior <git@avior.me>
- Loading branch information
Showing
10 changed files
with
184 additions
and
129 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains 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 |
---|---|---|
@@ -1,30 +1,29 @@ | ||
{ | ||
"name": "@tcgdex/server", | ||
"private": true, | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"compile": "bun compiler/index.ts", | ||
"dev": "bun --watch src/index.ts", | ||
"validate": "tsc --noEmit --project ./tsconfig.json", | ||
"start": "bun src/index.ts" | ||
}, | ||
"license": "MIT", | ||
"dependencies": { | ||
"@dzeio/config": "^1", | ||
"@dzeio/object-util": "^1", | ||
"@sentry/node": "^7", | ||
"@tcgdex/sdk": "^2", | ||
"apicache": "^1", | ||
"express": "^4", | ||
"graphql": "^15", | ||
"graphql-http": "^1.22.1", | ||
"ruru": "^2.0.0-beta.11" | ||
}, | ||
"devDependencies": { | ||
"@types/apicache": "^1", | ||
"@types/express": "^4", | ||
"@types/node": "^20", | ||
"glob": "^10", | ||
"typescript": "^4" | ||
} | ||
"name": "@tcgdex/server", | ||
"private": true, | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"compile": "bun compiler/index.ts", | ||
"dev": "bun --watch src/index.ts", | ||
"validate": "tsc --noEmit --project ./tsconfig.json", | ||
"start": "bun src/index.ts" | ||
}, | ||
"license": "MIT", | ||
"dependencies": { | ||
"@dzeio/config": "^1", | ||
"@dzeio/object-util": "^1", | ||
"@tcgdex/sdk": "^2", | ||
"apicache": "^1", | ||
"express": "^4", | ||
"graphql": "^15", | ||
"graphql-http": "^1.22.1", | ||
"ruru": "^2.0.0-beta.14" | ||
}, | ||
"devDependencies": { | ||
"@types/apicache": "^1", | ||
"@types/express": "^4", | ||
"@types/node": "^20", | ||
"glob": "^10", | ||
"typescript": "^4" | ||
} | ||
} |
Binary file not shown.
This file contains 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,5 @@ | ||
User-agent: * | ||
Disallow: / | ||
|
||
# Please note that this is for Crawlers only | ||
# You can logically use robots to use the API |
This file contains 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 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> | ||
</urlset> |
This file contains 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 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 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,46 @@ | ||
import type { Response } from 'express' | ||
import { languages } from '../util' | ||
import type RFC7807 from './RFCs/RFC7807' | ||
|
||
export enum Errors { | ||
LANGUAGE_INVALID = 'language-invalid', | ||
NOT_FOUND = 'not-found', | ||
|
||
GENERAL = 'general' | ||
} | ||
|
||
const titles: Record<Errors, string> = { | ||
[Errors.LANGUAGE_INVALID]: 'The chosen language is not available in the database', | ||
[Errors.NOT_FOUND]: 'The resource you are trying to reach does not exists', | ||
|
||
[Errors.GENERAL]: 'An unknown error occured, please contact a developper with this message' | ||
} | ||
|
||
const status: Record<Errors, number> = { | ||
[Errors.LANGUAGE_INVALID]: 404, | ||
[Errors.NOT_FOUND]: 404, | ||
|
||
[Errors.GENERAL]: 500 | ||
} | ||
|
||
const details: Partial<Record<Errors, (meta?: Record<string, unknown>) => string>> = { | ||
[Errors.LANGUAGE_INVALID]: (meta) => `You must use one of the following languages (${languages.join(', ')}) while you used "${meta?.lang}"`, | ||
} | ||
|
||
export function sendError(error: Errors, res: Response, metadata?: Record<string, unknown>) { | ||
const json: RFC7807 & Record<string, unknown> = { | ||
type: `https://tcgdex.dev/errors/${error}`, | ||
title: titles[error], | ||
status: status[error], | ||
endpoint: res.req.url, | ||
method: res.req.method, | ||
...metadata | ||
} | ||
|
||
const dt = details[error] | ||
if (dt) { | ||
json.details = dt(metadata) | ||
} | ||
|
||
res.status(json.status ?? 500).json(json).end() | ||
} |
This file contains 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,52 @@ | ||
/** | ||
* Add headers: | ||
* Content-Type: application/problem+json | ||
* | ||
* following https://www.rfc-editor.org/rfc/rfc7807.html | ||
*/ | ||
export default interface RFC7807 { | ||
/** | ||
* A URI reference [RFC3986] that identifies the | ||
* problem type. | ||
* | ||
* This specification encourages that, when | ||
* dereferenced, it provide human-readable documentation for the | ||
* problem type (e.g., using HTML [W3C.REC-html5-20141028]). | ||
* | ||
* When | ||
* this member is not present, its value is assumed to be | ||
* "about:blank" | ||
*/ | ||
type?: string | ||
|
||
/** | ||
* A short, human-readable summary of the problem | ||
* type. | ||
* | ||
* It SHOULD NOT change from occurrence to occurrence of the | ||
* problem, except for purposes of localization (e.g., using | ||
* proactive content negotiation; see [RFC7231], Section 3.4). | ||
*/ | ||
title?: string | ||
|
||
/** | ||
* The HTTP status code ([RFC7231], Section 6) | ||
* generated by the origin server for this occurrence of the problem. | ||
*/ | ||
status?: number | ||
|
||
/** | ||
* A human-readable explanation specific to this | ||
* occurrence of the problem. | ||
*/ | ||
details?: string | ||
|
||
/** | ||
* A URI reference that identifies the specific | ||
* occurrence of the problem. | ||
* | ||
* It may or may not yield further | ||
* information if dereferenced. | ||
*/ | ||
instance?: string | ||
} |
Oops, something went wrong.