diff --git a/README.md b/README.md index ce38c594..4da3898d 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Upstash Redis -An HTTP/REST based Redis client built on top of -[Upstash REST API](https://docs.upstash.com/features/restapi). +`@upstash/redis` is an HTTP/REST based Redis client for typescript, built on top +of [Upstash REST API](https://docs.upstash.com/features/restapi). [![Tests](https://github.com/upstash/upstash-redis/actions/workflows/tests.yaml/badge.svg)](https://github.com/upstash/upstash-redis/actions/workflows/tests.yaml) ![npm (scoped)](https://img.shields.io/npm/v/@upstash/redis) diff --git a/mod.ts b/mod.ts index 873826dc..cde13cdc 100644 --- a/mod.ts +++ b/mod.ts @@ -1,5 +1,6 @@ import { HttpClient } from "./pkg/http.ts"; import * as core from "./pkg/redis.ts"; +export type { Requester, UpstashRequest, UpstashResponse } from "./pkg/http.ts"; /** * Connection credentials for upstash redis. @@ -32,6 +33,25 @@ export class Redis extends core.Redis { * ``` */ constructor(config: RedisConfigDeno) { + if ( + config.url.startsWith(" ") || + config.url.endsWith(" ") || + /\r|\n/.test(config.url) + ) { + console.warn( + "The redis url contains whitespace or newline, which can cause errors!", + ); + } + if ( + config.token.startsWith(" ") || + config.token.endsWith(" ") || + /\r|\n/.test(config.token) + ) { + console.warn( + "The redis token contains whitespace or newline, which can cause errors!", + ); + } + const client = new HttpClient({ baseUrl: config.url, headers: { authorization: `Bearer ${config.token}` }, diff --git a/platforms/cloudflare.ts b/platforms/cloudflare.ts index f3d7674c..9683c55b 100644 --- a/platforms/cloudflare.ts +++ b/platforms/cloudflare.ts @@ -38,6 +38,24 @@ export class Redis extends core.Redis { * ``` */ constructor(config: RedisConfigCloudflare) { + if ( + config.url.startsWith(" ") || + config.url.endsWith(" ") || + /\r|\n/.test(config.url) + ) { + console.warn( + "The redis url contains whitespace or newline, which can cause errors!", + ); + } + if ( + config.token.startsWith(" ") || + config.token.endsWith(" ") || + /\r|\n/.test(config.token) + ) { + console.warn( + "The redis token contains whitespace or newline, which can cause errors!", + ); + } const client = defaultRequester({ baseUrl: config.url, headers: { authorization: `Bearer ${config.token}` }, diff --git a/platforms/fastly.ts b/platforms/fastly.ts index 99db0b7e..c906f163 100644 --- a/platforms/fastly.ts +++ b/platforms/fastly.ts @@ -46,6 +46,24 @@ export class Redis extends core.Redis { * ``` */ constructor(config: RedisConfigFastly) { + if ( + config.url.startsWith(" ") || + config.url.endsWith(" ") || + /\r|\n/.test(config.url) + ) { + console.warn( + "The redis url contains whitespace or newline, which can cause errors!", + ); + } + if ( + config.token.startsWith(" ") || + config.token.endsWith(" ") || + /\r|\n/.test(config.token) + ) { + console.warn( + "The redis token contains whitespace or newline, which can cause errors!", + ); + } const client = defaultRequester({ baseUrl: config.url, headers: { authorization: `Bearer ${config.token}` }, diff --git a/platforms/nodejs.ts b/platforms/nodejs.ts index adbf15d7..fcb0c9fc 100644 --- a/platforms/nodejs.ts +++ b/platforms/nodejs.ts @@ -82,6 +82,24 @@ export class Redis extends core.Redis { super(configOrRequester); return; } + if ( + configOrRequester.url.startsWith(" ") || + configOrRequester.url.endsWith(" ") || + /\r|\n/.test(configOrRequester.url) + ) { + console.warn( + "The redis url contains whitespace or newline, which can cause errors!", + ); + } + if ( + configOrRequester.token.startsWith(" ") || + configOrRequester.token.endsWith(" ") || + /\r|\n/.test(configOrRequester.token) + ) { + console.warn( + "The redis token contains whitespace or newline, which can cause errors!", + ); + } const client = defaultRequester({ baseUrl: configOrRequester.url,