mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-22 22:59:35 +02:00
createClient(): throw if userAgent is one of the documented ones 💥📝
related: #286 fixes #286
This commit is contained in:
parent
5910d62535
commit
e7602e6c84
2 changed files with 12 additions and 1 deletions
10
index.js
10
index.js
|
@ -8,6 +8,13 @@ import {INVALID_REQUEST} from './lib/errors.js'
|
|||
import {sliceLeg} from './lib/slice-leg.js'
|
||||
import {HafasError} from './lib/errors.js'
|
||||
|
||||
// background info: https://github.com/public-transport/hafas-client/issues/286
|
||||
const FORBIDDEN_USER_AGENTS = [
|
||||
'my-awesome-program', // previously used in readme.md, p/*/readme.md & docs/*.md
|
||||
'hafas-client-example', // previously used in p/*/example.js
|
||||
'link-to-your-project-or-email', // now used throughout
|
||||
]
|
||||
|
||||
const isNonEmptyString = str => 'string' === typeof str && str.length > 0
|
||||
|
||||
const validateLocation = (loc, name = 'location') => {
|
||||
|
@ -35,6 +42,9 @@ const createClient = (profile, userAgent, opt = {}) => {
|
|||
if ('string' !== typeof userAgent) {
|
||||
throw new TypeError('userAgent must be a string');
|
||||
}
|
||||
if (FORBIDDEN_USER_AGENTS.includes(userAgent.toLowerCase())) {
|
||||
throw new TypeError(`userAgent should tell the HAFAS API operators how to contact you. If you have copied "${userAgent}" value from the documentation, please adapt it.`);
|
||||
}
|
||||
|
||||
const _stationBoard = async (station, type, resultsField, parse, opt = {}) => {
|
||||
if (isObj(station)) station = profile.formatStation(station.id)
|
||||
|
|
|
@ -53,7 +53,8 @@ Because the operatores of the HAFAS endpoint should be able to contact you about
|
|||
import {createClient} from 'hafas-client'
|
||||
import {profile as dbProfile} from 'hafas-client/p/db/index.js'
|
||||
|
||||
const userAgent = 'link-to-your-project-or-email' // adapt this to your project!
|
||||
// Adapt this to your project! createClient() won't work with this string.
|
||||
const userAgent = 'link-to-your-project-or-email'
|
||||
|
||||
// create a client with the Deutsche Bahn profile
|
||||
const client = createClient(dbProfile, userAgent)
|
||||
|
|
Loading…
Add table
Reference in a new issue