New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@prismicio/client

Package Overview
Dependencies
Maintainers
19
Versions
114
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@prismicio/client - npm Package Compare versions

Comparing version 6.2.0 to 6.3.0

src/getRepositoryEndpoint.ts

69

dist/index.d.ts

@@ -5,3 +5,3 @@ import * as prismicT from '@prismicio/types';

/**
* Get a repository's Prismic REST API V2 endpoint.
* Get a repository's Prismic Rest API V2 endpoint.
*

@@ -11,7 +11,20 @@ * @typeParam RepositoryName - Name of the Prismic repository.

*
* @returns The repository's Prismic REST API V2 endpoint
* @returns The repository's Prismic Rest API V2 endpoint
* @throws {@link Error} Thrown if an invalid repository name is provided.
*/
declare const getEndpoint: <RepositoryName extends string>(repositoryName: RepositoryName) => `https://${RepositoryName}.cdn.prismic.io/api/v2`;
declare const getRepositoryEndpoint: <RepositoryName extends string>(repositoryName: RepositoryName) => `https://${RepositoryName}.cdn.prismic.io/api/v2`;
/**
* Get a Prismic repository's name from its standard Prismic Rest API V2 or
* GraphQL endpoint.
*
* @typeParam RepositoryEndpoint - Prismic Rest API V2 endpoint for the repository.
* @param repositoryEndpoint - Prismic Rest API V2 endpoint for the repository.
*
* @returns The Prismic repository's name.
* @throws {@link Error} Thrown if an invalid Prismic Rest API V2 endpoint is provided.
*/
declare const getRepositoryName: (repositoryEndpoint: string) => string;
/**
* Get a repository's Prismic GraphQL endpoint.

@@ -27,2 +40,21 @@ *

/**
* Determines if an input is a valid Prismic repository name.
*
* @param input - Input to test.
*
* @returns `true` if `input` is a valid Prismic repository name, `false` otherwise.
*/
declare const isRepositoryName: (input: string) => boolean;
/**
* Determines if a string if a Prismic Rest API V2 endpoint. Note that any valid
* URL is a valid endpoint to support network proxies.
*
* @param input - Input to test.
*
* @returns `true` if `input` is a valid Prismic Rest API V2 endpoint, `false` otherwise.
*/
declare const isRepositoryEndpoint: (input: string) => boolean;
/**
* A universal API to make network requests. A subset of the `fetch()` API.

@@ -305,4 +337,14 @@ *

*
* @param endpoint - The Prismic REST API V2 endpoint for the repository (use
* `prismic.getEndpoint` for the default endpoint).
* @example
*
* ```ts
* // With a repository name.
* createClient("qwerty");
*
* // Or with a full Prismic Rest API V2 endpoint.
* createClient("https://qwerty.cdn.prismic.io/api/v2");
* ```
*
* @param repositoryNameOrEndpoint - The Prismic repository name or full Rest
* API V2 endpoint for the repository.
* @param options - Configuration that determines how content will be queried

@@ -313,3 +355,3 @@ * from the Prismic repository.

*/
declare const createClient: (endpoint: string, options?: ClientConfig | undefined) => Client;
declare const createClient: (repositoryNameOrEndpoint: string, options?: ClientConfig | undefined) => Client;
/**

@@ -325,3 +367,3 @@ * A client that allows querying content from a Prismic repository.

* The Prismic REST API V2 endpoint for the repository (use
* `prismic.getEndpoint` for the default endpoint).
* `prismic.getRepositoryEndpoint` for the default endpoint).
*/

@@ -373,4 +415,4 @@ endpoint: string;

*
* @param endpoint - The Prismic REST API V2 endpoint for the repository (use
* `prismic.getEndpoint` to get the default endpoint).
* @param repositoryNameOrEndpoint - The Prismic repository name or full Rest
* API V2 endpoint for the repository.
* @param options - Configuration that determines how content will be queried

@@ -381,3 +423,3 @@ * from the Prismic repository.

*/
constructor(endpoint: string, options?: ClientConfig);
constructor(repositoryNameOrEndpoint: string, options?: ClientConfig);
/**

@@ -1301,2 +1343,7 @@ * Enables the client to automatically query content from a preview session if

/**
* @deprecated Renamed to `getRepositoryEndpoint`.
*/
declare const getEndpoint: <RepositoryName extends string>(repositoryName: RepositoryName) => `https://${RepositoryName}.cdn.prismic.io/api/v2`;
/**
* @deprecated Renamed to `predicate` (without an "s").

@@ -1368,2 +1415,2 @@ */

export { BuildQueryURLArgs, Client, ClientConfig, FetchLike, ForbiddenError, HttpRequestLike, NotFoundError, Ordering, ParsingError, Predicates, PrismicError, QueryParams, RequestInitLike, ResponseLike, Route, buildQueryURL, cookie, createClient, getEndpoint, getGraphQLEndpoint, predicate, predicates };
export { BuildQueryURLArgs, Client, ClientConfig, FetchLike, ForbiddenError, HttpRequestLike, NotFoundError, Ordering, ParsingError, Predicates, PrismicError, QueryParams, RequestInitLike, ResponseLike, Route, buildQueryURL, cookie, createClient, getEndpoint, getGraphQLEndpoint, getRepositoryEndpoint, getRepositoryName, isRepositoryEndpoint, isRepositoryName, predicate, predicates };

68

dist/index.js
import * as prismicH from '@prismicio/helpers';
const getEndpoint = (repositoryName) => `https://${repositoryName}.cdn.prismic.io/api/v2`;
const isRepositoryName = (input) => {
return /^[a-zA-Z0-9][-a-zA-Z0-9]{2,}[a-zA-Z0-9]$/.test(input);
};
const getGraphQLEndpoint = (repositoryName) => `https://${repositoryName}.cdn.prismic.io/graphql`;
class PrismicError extends Error {
constructor(message = "An invalid API response was returned", url, response) {
super(message);
this.url = url;
this.response = response;
}
}
const getRepositoryEndpoint = (repositoryName) => {
if (isRepositoryName(repositoryName)) {
return `https://${repositoryName}.cdn.prismic.io/api/v2`;
} else {
throw new PrismicError(`An invalid Prismic repository name was given: ${repositoryName}`, void 0, void 0);
}
};
const getRepositoryName = (repositoryEndpoint) => {
try {
return new URL(repositoryEndpoint).hostname.split(".")[0];
} catch (e) {
throw new PrismicError(`An invalid Prismic Rest API V2 endpoint was provided: ${repositoryEndpoint}`, void 0, void 0);
}
};
const getGraphQLEndpoint = (repositoryName) => {
if (isRepositoryName(repositoryName)) {
return `https://${repositoryName}.cdn.prismic.io/graphql`;
} else {
throw new PrismicError(`An invalid Prismic repository name was given: ${repositoryName}`, void 0, void 0);
}
};
const isRepositoryEndpoint = (input) => {
try {
new URL(input);
return true;
} catch (e) {
return false;
}
};
const castArray = (a) => Array.isArray(a) ? a : [a];

@@ -58,10 +99,2 @@

class PrismicError extends Error {
constructor(message = "An invalid API response was returned", url, response) {
super(message);
this.url = url;
this.response = response;
}
}
const findRef = (refs, predicate) => {

@@ -197,3 +230,3 @@ const ref = refs.find((ref2) => predicate(ref2));

class Client {
constructor(endpoint, options = {}) {
constructor(repositoryNameOrEndpoint, options = {}) {
this.refState = {

@@ -204,6 +237,10 @@ mode: "Master" /* Master */,

this.cachedRepositoryExpiration = 0;
if (process.env.NODE_ENV === "development" && /\.prismic\.io\/(?!api\/v2\/?)/.test(endpoint)) {
throw new PrismicError("@prismicio/client only supports Prismic Rest API V2. Please use the getEndpoint helper to generate a valid Rest API V2 endpoint URL.", void 0, void 0);
if (isRepositoryEndpoint(repositoryNameOrEndpoint)) {
if (process.env.NODE_ENV === "development" && /\.prismic\.io\/(?!api\/v2\/?)/.test(repositoryNameOrEndpoint)) {
throw new PrismicError("@prismicio/client only supports Prismic Rest API V2. Please provide only the repository name to the first createClient() parameter or use the getRepositoryEndpoint() helper to generate a valid Rest API V2 endpoint URL.", void 0, void 0);
}
this.endpoint = repositoryNameOrEndpoint;
} else {
this.endpoint = getRepositoryEndpoint(repositoryNameOrEndpoint);
}
this.endpoint = endpoint;
this.accessToken = options.accessToken;

@@ -529,6 +566,7 @@ this.routes = options.routes;

const getEndpoint = getRepositoryEndpoint;
const predicates = predicate;
const Predicates = predicate;
export { Client, ForbiddenError, NotFoundError, ParsingError, Predicates, PrismicError, buildQueryURL, cookie, createClient, getEndpoint, getGraphQLEndpoint, predicate, predicates };
export { Client, ForbiddenError, NotFoundError, ParsingError, Predicates, PrismicError, buildQueryURL, cookie, createClient, getEndpoint, getGraphQLEndpoint, getRepositoryEndpoint, getRepositoryName, isRepositoryEndpoint, isRepositoryName, predicate, predicates };
//# sourceMappingURL=index.js.map
{
"name": "@prismicio/client",
"version": "6.2.0",
"version": "6.3.0",
"description": "The official JavaScript + TypeScript client library for Prismic",

@@ -30,2 +30,3 @@ "keywords": [

"module": "dist/index.js",
"react-native": "dist/index.js",
"types": "dist/index.d.ts",

@@ -52,13 +53,13 @@ "files": [

"@prismicio/helpers": "^2.1.1",
"@prismicio/types": "^0.1.23"
"@prismicio/types": "^0.1.24"
},
"devDependencies": {
"@size-limit/preset-small-lib": "^7.0.8",
"@types/node-fetch": "^2.5.12",
"@types/sinon": "^10.0.10",
"@typescript-eslint/eslint-plugin": "^5.10.2",
"@typescript-eslint/parser": "^5.10.2",
"@types/sinon": "^10.0.11",
"@typescript-eslint/eslint-plugin": "^5.11.0",
"@typescript-eslint/parser": "^5.11.0",
"abort-controller": "^3.0.0",
"ava": "^4.0.1",
"eslint": "^8.8.0",
"esbuild-register": "^3.3.2",
"eslint": "^8.9.0",
"eslint-config-prettier": "^8.3.0",

@@ -68,3 +69,3 @@ "eslint-plugin-prettier": "^4.0.0",

"msw": "^0.36.8",
"node-fetch": "^2.6.7",
"node-fetch": "^3.2.0",
"nyc": "^15.1.0",

@@ -77,3 +78,2 @@ "prettier": "^2.5.1",

"standard-version": "^9.3.2",
"ts-eager": "^2.0.2",
"typescript": "^4.5.5"

@@ -86,4 +86,3 @@ },

"access": "public"
},
"react-native": "dist/index.js"
}
}

@@ -21,4 +21,3 @@ # @prismicio/client

// Create a client
const endpoint = prismic.getEndpoint("my-repository");
const client = prismic.createClient(endpoint);
const client = prismic.createClient("my-repository");

@@ -56,3 +55,3 @@ // Then query for your content

```
Copyright 2013-2021 Prismic <contact@prismic.io> (https://prismic.io)
Copyright 2013-2022 Prismic <contact@prismic.io> (https://prismic.io)

@@ -59,0 +58,0 @@ Licensed under the Apache License, Version 2.0 (the "License");

@@ -20,2 +20,4 @@ import * as prismicT from "@prismicio/types";

import { buildQueryURL, BuildQueryURLArgs } from "./buildQueryURL";
import { getRepositoryEndpoint } from "./getRepositoryEndpoint";
import { isRepositoryEndpoint } from "./isRepositoryEndpoint";
import { predicate } from "./predicate";

@@ -241,4 +243,14 @@

*
* @param endpoint - The Prismic REST API V2 endpoint for the repository (use
* `prismic.getEndpoint` for the default endpoint).
* @example
*
* ```ts
* // With a repository name.
* createClient("qwerty");
*
* // Or with a full Prismic Rest API V2 endpoint.
* createClient("https://qwerty.cdn.prismic.io/api/v2");
* ```
*
* @param repositoryNameOrEndpoint - The Prismic repository name or full Rest
* API V2 endpoint for the repository.
* @param options - Configuration that determines how content will be queried

@@ -263,3 +275,3 @@ * from the Prismic repository.

* The Prismic REST API V2 endpoint for the repository (use
* `prismic.getEndpoint` for the default endpoint).
* `prismic.getRepositoryEndpoint` for the default endpoint).
*/

@@ -325,4 +337,4 @@ endpoint: string;

*
* @param endpoint - The Prismic REST API V2 endpoint for the repository (use
* `prismic.getEndpoint` to get the default endpoint).
* @param repositoryNameOrEndpoint - The Prismic repository name or full Rest
* API V2 endpoint for the repository.
* @param options - Configuration that determines how content will be queried

@@ -333,15 +345,20 @@ * from the Prismic repository.

*/
constructor(endpoint: string, options: ClientConfig = {}) {
if (
process.env.NODE_ENV === "development" &&
/\.prismic\.io\/(?!api\/v2\/?)/.test(endpoint)
) {
throw new PrismicError(
"@prismicio/client only supports Prismic Rest API V2. Please use the getEndpoint helper to generate a valid Rest API V2 endpoint URL.",
undefined,
undefined,
);
constructor(repositoryNameOrEndpoint: string, options: ClientConfig = {}) {
if (isRepositoryEndpoint(repositoryNameOrEndpoint)) {
if (
process.env.NODE_ENV === "development" &&
/\.prismic\.io\/(?!api\/v2\/?)/.test(repositoryNameOrEndpoint)
) {
throw new PrismicError(
"@prismicio/client only supports Prismic Rest API V2. Please provide only the repository name to the first createClient() parameter or use the getRepositoryEndpoint() helper to generate a valid Rest API V2 endpoint URL.",
undefined,
undefined,
);
}
this.endpoint = repositoryNameOrEndpoint;
} else {
this.endpoint = getRepositoryEndpoint(repositoryNameOrEndpoint);
}
this.endpoint = endpoint;
this.accessToken = options.accessToken;

@@ -348,0 +365,0 @@ this.routes = options.routes;

@@ -0,1 +1,4 @@

import { isRepositoryName } from "./isRepositoryName";
import { PrismicError } from "./PrismicError";
/**

@@ -11,3 +14,12 @@ * Get a repository's Prismic GraphQL endpoint.

repositoryName: RepositoryName,
): `https://${RepositoryName}.cdn.prismic.io/graphql` =>
`https://${repositoryName}.cdn.prismic.io/graphql` as const;
): `https://${RepositoryName}.cdn.prismic.io/graphql` => {
if (isRepositoryName(repositoryName)) {
return `https://${repositoryName}.cdn.prismic.io/graphql` as const;
} else {
throw new PrismicError(
`An invalid Prismic repository name was given: ${repositoryName}`,
undefined,
undefined,
);
}
};
// Primary library API.
export * from "./getEndpoint";
export * from "./getGraphQLEndpoint";
export * from "./buildQueryURL";
import { getRepositoryEndpoint } from "./getRepositoryEndpoint";
export { getRepositoryEndpoint };
/**
* @deprecated Renamed to `getRepositoryEndpoint`.
*/
// TODO: Remove in v3.
export const getEndpoint = getRepositoryEndpoint;
export { getRepositoryName } from "./getRepositoryName";
export { getGraphQLEndpoint } from "./getGraphQLEndpoint";
export { isRepositoryName } from "./isRepositoryName";
export { isRepositoryEndpoint } from "./isRepositoryEndpoint";
export { buildQueryURL } from "./buildQueryURL";
export { createClient, Client } from "./client";

@@ -32,2 +41,3 @@

export type { ClientConfig } from "./client";
export type { QueryParams, BuildQueryURLArgs } from "./buildQueryURL";
export type {

@@ -34,0 +44,0 @@ FetchLike,

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc