From 0b56b547b3219f9f526e7e85cd075caf5694979d Mon Sep 17 00:00:00 2001 From: Angelo Ashmore Date: Thu, 14 Apr 2022 14:57:40 -1000 Subject: [PATCH] fix: throw when given a non-V2 Prismic Rest API in all non-production environments (#235) --- src/client.ts | 2 +- test/client.test.ts | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/client.ts b/src/client.ts index e833d011..fae896df 100644 --- a/src/client.ts +++ b/src/client.ts @@ -342,7 +342,7 @@ export class Client { constructor(repositoryNameOrEndpoint: string, options: ClientConfig = {}) { if (isRepositoryEndpoint(repositoryNameOrEndpoint)) { if ( - process.env.NODE_ENV === "development" && + process.env.NODE_ENV !== "production" && /\.prismic\.io\/(?!api\/v2\/?)/.test(repositoryNameOrEndpoint) ) { throw new PrismicError( diff --git a/test/client.test.ts b/test/client.test.ts index f88790fb..d6f1f610 100644 --- a/test/client.test.ts +++ b/test/client.test.ts @@ -98,6 +98,23 @@ test.serial( }, ); +test.serial( + "constructor throws if a non-V2 Prismic Rest API endpoint is provided", + (t) => { + t.throws( + () => { + prismic.createClient("https://qwerty.cdn.prismic.io/api/v1", { + fetch: sinon.stub(), + }); + }, + { + instanceOf: prismic.PrismicError, + message: /only supports prismic rest api v2/i, + }, + ); + }, +); + test.serial("constructor throws if fetch is unavailable", (t) => { const endpoint = prismic.getRepositoryEndpoint("qwerty");