@prismicio/client 6.7.1 → 6.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/dist/ForbiddenError.cjs +7 -0
  2. package/dist/ForbiddenError.cjs.map +1 -0
  3. package/dist/ForbiddenError.d.ts +11 -0
  4. package/dist/ForbiddenError.js +7 -0
  5. package/dist/ForbiddenError.js.map +1 -0
  6. package/dist/NotFoundError.cjs +7 -0
  7. package/dist/NotFoundError.cjs.map +1 -0
  8. package/dist/NotFoundError.d.ts +3 -0
  9. package/dist/NotFoundError.js +7 -0
  10. package/dist/NotFoundError.js.map +1 -0
  11. package/dist/ParsingError.cjs +7 -0
  12. package/dist/ParsingError.cjs.map +1 -0
  13. package/dist/ParsingError.d.ts +12 -0
  14. package/dist/ParsingError.js +7 -0
  15. package/dist/ParsingError.js.map +1 -0
  16. package/dist/PrismicError.cjs +19 -0
  17. package/dist/PrismicError.cjs.map +1 -0
  18. package/dist/PrismicError.d.ts +5 -0
  19. package/dist/PrismicError.js +19 -0
  20. package/dist/PrismicError.js.map +1 -0
  21. package/dist/buildQueryURL.cjs +40 -0
  22. package/dist/buildQueryURL.cjs.map +1 -0
  23. package/dist/buildQueryURL.d.ts +130 -0
  24. package/dist/buildQueryURL.js +40 -0
  25. package/dist/buildQueryURL.js.map +1 -0
  26. package/dist/client.cjs +436 -0
  27. package/dist/client.cjs.map +1 -0
  28. package/dist/client.d.ts +929 -0
  29. package/dist/client.js +419 -0
  30. package/dist/client.js.map +1 -0
  31. package/dist/cookie.cjs +5 -0
  32. package/dist/cookie.cjs.map +1 -0
  33. package/dist/cookie.d.ts +5 -0
  34. package/dist/cookie.js +5 -0
  35. package/dist/cookie.js.map +1 -0
  36. package/dist/getGraphQLEndpoint.cjs +13 -0
  37. package/dist/getGraphQLEndpoint.cjs.map +1 -0
  38. package/dist/getGraphQLEndpoint.d.ts +9 -0
  39. package/dist/getGraphQLEndpoint.js +13 -0
  40. package/dist/getGraphQLEndpoint.js.map +1 -0
  41. package/dist/getRepositoryEndpoint.cjs +13 -0
  42. package/dist/getRepositoryEndpoint.cjs.map +1 -0
  43. package/dist/getRepositoryEndpoint.d.ts +10 -0
  44. package/dist/getRepositoryEndpoint.js +13 -0
  45. package/dist/getRepositoryEndpoint.js.map +1 -0
  46. package/dist/getRepositoryName.cjs +12 -0
  47. package/dist/getRepositoryName.cjs.map +1 -0
  48. package/dist/getRepositoryName.d.ts +13 -0
  49. package/dist/getRepositoryName.js +12 -0
  50. package/dist/getRepositoryName.js.map +1 -0
  51. package/dist/index.cjs +32 -719
  52. package/dist/index.cjs.map +1 -1
  53. package/dist/index.d.ts +88 -1526
  54. package/dist/index.js +34 -679
  55. package/dist/index.js.map +1 -1
  56. package/dist/isRepositoryEndpoint.cjs +12 -0
  57. package/dist/isRepositoryEndpoint.cjs.map +1 -0
  58. package/dist/isRepositoryEndpoint.d.ts +10 -0
  59. package/dist/isRepositoryEndpoint.js +12 -0
  60. package/dist/isRepositoryEndpoint.js.map +1 -0
  61. package/dist/isRepositoryName.cjs +7 -0
  62. package/dist/isRepositoryName.cjs.map +1 -0
  63. package/dist/isRepositoryName.d.ts +9 -0
  64. package/dist/isRepositoryName.js +7 -0
  65. package/dist/isRepositoryName.js.map +1 -0
  66. package/dist/lib/appendPredicates.cjs +14 -0
  67. package/dist/lib/appendPredicates.cjs.map +1 -0
  68. package/dist/lib/appendPredicates.d.ts +18 -0
  69. package/dist/lib/appendPredicates.js +14 -0
  70. package/dist/lib/appendPredicates.js.map +1 -0
  71. package/dist/lib/castArray.cjs +5 -0
  72. package/dist/lib/castArray.cjs.map +1 -0
  73. package/dist/lib/castArray.d.ts +11 -0
  74. package/dist/lib/castArray.js +5 -0
  75. package/dist/lib/castArray.js.map +1 -0
  76. package/dist/lib/castThunk.cjs +5 -0
  77. package/dist/lib/castThunk.cjs.map +1 -0
  78. package/dist/lib/castThunk.d.ts +10 -0
  79. package/dist/lib/castThunk.js +5 -0
  80. package/dist/lib/castThunk.js.map +1 -0
  81. package/dist/lib/findMasterRef.cjs +8 -0
  82. package/dist/lib/findMasterRef.cjs.map +1 -0
  83. package/dist/lib/findMasterRef.d.ts +10 -0
  84. package/dist/lib/findMasterRef.js +8 -0
  85. package/dist/lib/findMasterRef.js.map +1 -0
  86. package/dist/lib/findRef.cjs +12 -0
  87. package/dist/lib/findRef.cjs.map +1 -0
  88. package/dist/lib/findRef.d.ts +13 -0
  89. package/dist/lib/findRef.js +12 -0
  90. package/dist/lib/findRef.js.map +1 -0
  91. package/dist/lib/findRefByID.cjs +8 -0
  92. package/dist/lib/findRefByID.cjs.map +1 -0
  93. package/dist/lib/findRefByID.d.ts +11 -0
  94. package/dist/lib/findRefByID.js +8 -0
  95. package/dist/lib/findRefByID.js.map +1 -0
  96. package/dist/lib/findRefByLabel.cjs +8 -0
  97. package/dist/lib/findRefByLabel.cjs.map +1 -0
  98. package/dist/lib/findRefByLabel.d.ts +11 -0
  99. package/dist/lib/findRefByLabel.js +8 -0
  100. package/dist/lib/findRefByLabel.js.map +1 -0
  101. package/dist/lib/getPreviewCookie.cjs +21 -0
  102. package/dist/lib/getPreviewCookie.cjs.map +1 -0
  103. package/dist/lib/getPreviewCookie.d.ts +9 -0
  104. package/dist/lib/getPreviewCookie.js +21 -0
  105. package/dist/lib/getPreviewCookie.js.map +1 -0
  106. package/dist/lib/minifyGraphQLQuery.cjs +7 -0
  107. package/dist/lib/minifyGraphQLQuery.cjs.map +1 -0
  108. package/dist/lib/minifyGraphQLQuery.d.ts +8 -0
  109. package/dist/lib/minifyGraphQLQuery.js +7 -0
  110. package/dist/lib/minifyGraphQLQuery.js.map +1 -0
  111. package/dist/lib/orElseThrow.d.ts +11 -0
  112. package/dist/predicate.cjs +68 -0
  113. package/dist/predicate.cjs.map +1 -0
  114. package/dist/predicate.d.ts +209 -0
  115. package/dist/predicate.js +68 -0
  116. package/dist/predicate.js.map +1 -0
  117. package/dist/types.d.ts +156 -0
  118. package/package.json +21 -21
  119. package/src/buildQueryURL.ts +6 -3
  120. package/src/client.ts +71 -36
  121. package/src/cookie.ts +2 -1
  122. package/src/getRepositoryName.ts +4 -2
  123. package/src/isRepositoryEndpoint.ts +2 -1
  124. package/src/isRepositoryName.ts +2 -1
  125. package/src/lib/appendPredicates.ts +2 -1
  126. package/src/lib/getPreviewCookie.ts +2 -1
  127. package/src/predicate.ts +4 -2
  128. package/src/types.ts +3 -3
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const PrismicError = require("./PrismicError.cjs");
4
+ class ForbiddenError extends PrismicError.PrismicError {
5
+ }
6
+ exports.ForbiddenError = ForbiddenError;
7
+ //# sourceMappingURL=ForbiddenError.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ForbiddenError.cjs","sources":["../../src/ForbiddenError.ts"],"sourcesContent":["import { PrismicError } from \"./PrismicError\";\n\ntype ForbiddenErrorRepositoryAPIResponse = {\n\ttype: string;\n\tmessage: string;\n};\n\ntype ForbiddenErrorQueryAPIResponse = {\n\terror: string;\n};\n\nexport class ForbiddenError extends PrismicError<\n\tForbiddenErrorRepositoryAPIResponse | ForbiddenErrorQueryAPIResponse\n> {}\n"],"names":["PrismicError"],"mappings":";;;AAWM,MAAO,uBAAuBA,aAAAA,aAEnC;AAAG;;"}
@@ -0,0 +1,11 @@
1
+ import { PrismicError } from "./PrismicError";
2
+ type ForbiddenErrorRepositoryAPIResponse = {
3
+ type: string;
4
+ message: string;
5
+ };
6
+ type ForbiddenErrorQueryAPIResponse = {
7
+ error: string;
8
+ };
9
+ export declare class ForbiddenError extends PrismicError<ForbiddenErrorRepositoryAPIResponse | ForbiddenErrorQueryAPIResponse> {
10
+ }
11
+ export {};
@@ -0,0 +1,7 @@
1
+ import { PrismicError } from "./PrismicError.js";
2
+ class ForbiddenError extends PrismicError {
3
+ }
4
+ export {
5
+ ForbiddenError
6
+ };
7
+ //# sourceMappingURL=ForbiddenError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ForbiddenError.js","sources":["../../src/ForbiddenError.ts"],"sourcesContent":["import { PrismicError } from \"./PrismicError\";\n\ntype ForbiddenErrorRepositoryAPIResponse = {\n\ttype: string;\n\tmessage: string;\n};\n\ntype ForbiddenErrorQueryAPIResponse = {\n\terror: string;\n};\n\nexport class ForbiddenError extends PrismicError<\n\tForbiddenErrorRepositoryAPIResponse | ForbiddenErrorQueryAPIResponse\n> {}\n"],"names":[],"mappings":";AAWM,MAAO,uBAAuB,aAEnC;AAAG;"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const PrismicError = require("./PrismicError.cjs");
4
+ class NotFoundError extends PrismicError.PrismicError {
5
+ }
6
+ exports.NotFoundError = NotFoundError;
7
+ //# sourceMappingURL=NotFoundError.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NotFoundError.cjs","sources":["../../src/NotFoundError.ts"],"sourcesContent":["import { PrismicError } from \"./PrismicError\";\n\nexport class NotFoundError extends PrismicError<undefined> {}\n"],"names":["PrismicError"],"mappings":";;;AAEM,MAAO,sBAAsBA,aAAAA,aAAuB;AAAG;;"}
@@ -0,0 +1,3 @@
1
+ import { PrismicError } from "./PrismicError";
2
+ export declare class NotFoundError extends PrismicError<undefined> {
3
+ }
@@ -0,0 +1,7 @@
1
+ import { PrismicError } from "./PrismicError.js";
2
+ class NotFoundError extends PrismicError {
3
+ }
4
+ export {
5
+ NotFoundError
6
+ };
7
+ //# sourceMappingURL=NotFoundError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NotFoundError.js","sources":["../../src/NotFoundError.ts"],"sourcesContent":["import { PrismicError } from \"./PrismicError\";\n\nexport class NotFoundError extends PrismicError<undefined> {}\n"],"names":[],"mappings":";AAEM,MAAO,sBAAsB,aAAuB;AAAG;"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const PrismicError = require("./PrismicError.cjs");
4
+ class ParsingError extends PrismicError.PrismicError {
5
+ }
6
+ exports.ParsingError = ParsingError;
7
+ //# sourceMappingURL=ParsingError.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ParsingError.cjs","sources":["../../src/ParsingError.ts"],"sourcesContent":["import { PrismicError } from \"./PrismicError\";\n\ntype ParsingErrorAPIResponse = {\n\ttype: \"parsing-error\";\n\tmessage: string;\n\tline: number;\n\tcolumn: number;\n\tid: number;\n\tlocation: string;\n};\n\nexport class ParsingError extends PrismicError<ParsingErrorAPIResponse> {}\n"],"names":["PrismicError"],"mappings":";;;AAWM,MAAO,qBAAqBA,aAAAA,aAAqC;AAAG;;"}
@@ -0,0 +1,12 @@
1
+ import { PrismicError } from "./PrismicError";
2
+ type ParsingErrorAPIResponse = {
3
+ type: "parsing-error";
4
+ message: string;
5
+ line: number;
6
+ column: number;
7
+ id: number;
8
+ location: string;
9
+ };
10
+ export declare class ParsingError extends PrismicError<ParsingErrorAPIResponse> {
11
+ }
12
+ export {};
@@ -0,0 +1,7 @@
1
+ import { PrismicError } from "./PrismicError.js";
2
+ class ParsingError extends PrismicError {
3
+ }
4
+ export {
5
+ ParsingError
6
+ };
7
+ //# sourceMappingURL=ParsingError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ParsingError.js","sources":["../../src/ParsingError.ts"],"sourcesContent":["import { PrismicError } from \"./PrismicError\";\n\ntype ParsingErrorAPIResponse = {\n\ttype: \"parsing-error\";\n\tmessage: string;\n\tline: number;\n\tcolumn: number;\n\tid: number;\n\tlocation: string;\n};\n\nexport class ParsingError extends PrismicError<ParsingErrorAPIResponse> {}\n"],"names":[],"mappings":";AAWM,MAAO,qBAAqB,aAAqC;AAAG;"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
+ var __publicField = (obj, key, value) => {
5
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
6
+ return value;
7
+ };
8
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
9
+ class PrismicError extends Error {
10
+ constructor(message = "An invalid API response was returned", url, response) {
11
+ super(message);
12
+ __publicField(this, "url");
13
+ __publicField(this, "response");
14
+ this.url = url;
15
+ this.response = response;
16
+ }
17
+ }
18
+ exports.PrismicError = PrismicError;
19
+ //# sourceMappingURL=PrismicError.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PrismicError.cjs","sources":["../../src/PrismicError.ts"],"sourcesContent":["export class PrismicError<Response> extends Error {\n\turl?: string;\n\tresponse: Response;\n\n\tconstructor(\n\t\tmessage = \"An invalid API response was returned\",\n\t\turl: string | undefined,\n\t\tresponse: Response,\n\t) {\n\t\tsuper(message);\n\n\t\tthis.url = url;\n\t\tthis.response = response;\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;AAAM,MAAO,qBAA+B,MAAK;AAAA,EAIhD,YACC,UAAU,wCACV,KACA,UAAkB;AAElB,UAAM,OAAO;AARd;AACA;AASC,SAAK,MAAM;AACX,SAAK,WAAW;AAAA,EACjB;AACA;;"}
@@ -0,0 +1,5 @@
1
+ export declare class PrismicError<Response> extends Error {
2
+ url?: string;
3
+ response: Response;
4
+ constructor(message: string | undefined, url: string | undefined, response: Response);
5
+ }
@@ -0,0 +1,19 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
7
+ class PrismicError extends Error {
8
+ constructor(message = "An invalid API response was returned", url, response) {
9
+ super(message);
10
+ __publicField(this, "url");
11
+ __publicField(this, "response");
12
+ this.url = url;
13
+ this.response = response;
14
+ }
15
+ }
16
+ export {
17
+ PrismicError
18
+ };
19
+ //# sourceMappingURL=PrismicError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PrismicError.js","sources":["../../src/PrismicError.ts"],"sourcesContent":["export class PrismicError<Response> extends Error {\n\turl?: string;\n\tresponse: Response;\n\n\tconstructor(\n\t\tmessage = \"An invalid API response was returned\",\n\t\turl: string | undefined,\n\t\tresponse: Response,\n\t) {\n\t\tsuper(message);\n\n\t\tthis.url = url;\n\t\tthis.response = response;\n\t}\n}\n"],"names":[],"mappings":";;;;;;AAAM,MAAO,qBAA+B,MAAK;AAAA,EAIhD,YACC,UAAU,wCACV,KACA,UAAkB;AAElB,UAAM,OAAO;AARd;AACA;AASC,SAAK,MAAM;AACX,SAAK,WAAW;AAAA,EACjB;AACA;"}
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const castArray = require("./lib/castArray.cjs");
4
+ const RENAMED_PARAMS = {
5
+ accessToken: "access_token"
6
+ };
7
+ const castOrderingToString = (ordering) => typeof ordering === "string" ? ordering : [
8
+ ordering.field,
9
+ ordering.direction === "desc" ? ordering.direction : void 0
10
+ ].filter(Boolean).join(" ");
11
+ const buildQueryURL = (endpoint, args) => {
12
+ const { predicates, ...params } = args;
13
+ const url = new URL(`documents/search`, `${endpoint}/`);
14
+ if (predicates) {
15
+ for (const predicate of castArray.castArray(predicates)) {
16
+ url.searchParams.append("q", `[${predicate}]`);
17
+ }
18
+ }
19
+ for (const k in params) {
20
+ const name = RENAMED_PARAMS[k] ?? k;
21
+ let value = params[k];
22
+ if (name === "orderings") {
23
+ const scopedValue = params[name];
24
+ if (scopedValue != null) {
25
+ const v = castArray.castArray(scopedValue).map((ordering) => castOrderingToString(ordering)).join(",");
26
+ value = `[${v}]`;
27
+ }
28
+ } else if (name === "routes") {
29
+ if (typeof params[name] === "object") {
30
+ value = JSON.stringify(castArray.castArray(params[name]));
31
+ }
32
+ }
33
+ if (value != null) {
34
+ url.searchParams.set(name, castArray.castArray(value).join(","));
35
+ }
36
+ }
37
+ return url.toString();
38
+ };
39
+ exports.buildQueryURL = buildQueryURL;
40
+ //# sourceMappingURL=buildQueryURL.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildQueryURL.cjs","sources":["../../src/buildQueryURL.ts"],"sourcesContent":["import { castArray } from \"./lib/castArray\";\n\nimport { ValueOf, Ordering, Route } from \"./types\";\n\n/**\n * Parameters for the Prismic REST API V2.\n *\n * {@link https://prismic.io/docs/technologies/introduction-to-the-content-query-api}\n */\nexport interface QueryParams {\n\t/**\n\t * The secure token for accessing the API (only needed if your repository is\n\t * set to private).\n\t *\n\t * {@link https://user-guides.prismic.io/en/articles/1036153-generating-an-access-token}\n\t */\n\taccessToken?: string;\n\n\t/**\n\t * The `pageSize` parameter defines the maximum number of documents that the\n\t * API will return for your query.\n\t *\n\t * {@link https://prismic.io/docs/technologies/search-parameters-reference-rest-api#pagesize}\n\t */\n\tpageSize?: number;\n\n\t/**\n\t * The `page` parameter defines the pagination for the result of your query.\n\t *\n\t * {@link https://prismic.io/docs/technologies/search-parameters-reference-rest-api#page}\n\t */\n\tpage?: number;\n\n\t/**\n\t * The `after` parameter can be used along with the orderings option. It will\n\t * remove all the documents except for those after the specified document in\n\t * the list.\n\t *\n\t * {@link https://prismic.io/docs/technologies/search-parameters-reference-rest-api#after}\n\t */\n\tafter?: string;\n\n\t/**\n\t * The `fetch` parameter is used to make queries faster by only retrieving the\n\t * specified field(s).\n\t *\n\t * {@link https://prismic.io/docs/technologies/search-parameters-reference-rest-api#fetch}\n\t */\n\tfetch?: string | string[];\n\n\t/**\n\t * The `fetchLinks` parameter allows you to retrieve a specific content field\n\t * from a linked document and add it to the document response object.\n\t *\n\t * {@link https://prismic.io/docs/technologies/search-parameters-reference-rest-api#fetchlinks}\n\t */\n\tfetchLinks?: string | string[];\n\n\t/**\n\t * The `graphQuery` parameter allows you to specify which fields to retrieve\n\t * and what content to retrieve from Linked Documents / Content\n\t * Relationships.\n\t *\n\t * {@link https://prismic.io/docs/technologies/graphquery-rest-api}\n\t */\n\tgraphQuery?: string;\n\n\t/**\n\t * The `lang` option defines the language code for the results of your query.\n\t *\n\t * {@link https://prismic.io/docs/technologies/search-parameters-reference-rest-api#lang}\n\t */\n\tlang?: string;\n\n\t/**\n\t * The `orderings` parameter orders the results by the specified field(s). You\n\t * can specify as many fields as you want.\n\t *\n\t * {@link https://prismic.io/docs/technologies/search-parameters-reference-rest-api#orderings}\n\t */\n\torderings?: Ordering | string | (Ordering | string)[];\n\n\t/**\n\t * The `routes` option allows you to define how a document's `url` field is\n\t * resolved.\n\t *\n\t * {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#route-resolver}\n\t */\n\troutes?: Route | string | (Route | string)[];\n\n\t/**\n\t * The `brokenRoute` option allows you to define the route populated in the\n\t * `url` property for broken Link or Content Relationship fields. A broken\n\t * link is a Link or Content Relationship field whose linked document has been\n\t * unpublished or deleted.\n\t *\n\t * {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#route-resolver}\n\t */\n\tbrokenRoute?: string;\n}\n\n/**\n * Arguments for `buildQueryURL` to construct a Query URL.\n */\ntype BuildQueryURLParams = {\n\t/**\n\t * Ref used to query documents.\n\t *\n\t * {@link https://prismic.io/docs/technologies/introduction-to-the-content-query-api#prismic-api-ref}\n\t */\n\tref: string;\n\n\t/**\n\t * Ref used to populate Integration Fields with the latest content.\n\t *\n\t * {@link https://prismic.io/docs/core-concepts/integration-fields}\n\t */\n\tintegrationFieldsRef?: string;\n\n\t/**\n\t * One or more predicates to filter documents for the query.\n\t *\n\t * {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api}\n\t */\n\tpredicates?: string | string[];\n};\n\n/**\n * Parameters in this map have been renamed from the official Prismic REST API\n * V2 specification for better developer ergonomics.\n *\n * These parameters are renamed to their mapped value.\n */\nconst RENAMED_PARAMS = {\n\taccessToken: \"access_token\",\n} as const;\n\n/**\n * A valid parameter name for the Prismic REST API V2.\n */\ntype ValidParamName =\n\t| Exclude<\n\t\t\tkeyof QueryParams,\n\t\t\tkeyof typeof RENAMED_PARAMS | keyof BuildQueryURLParams\n\t >\n\t| ValueOf<typeof RENAMED_PARAMS>;\n\n/**\n * Converts an Ordering to a string that is compatible with Prismic's REST API.\n * If the value provided is already a string, no conversion is performed.\n *\n * @param ordering - Ordering to convert.\n *\n * @returns String representation of the Ordering.\n */\nconst castOrderingToString = (ordering: Ordering | string): string =>\n\ttypeof ordering === \"string\"\n\t\t? ordering\n\t\t: [\n\t\t\t\tordering.field,\n\t\t\t\tordering.direction === \"desc\" ? ordering.direction : undefined,\n\t\t ]\n\t\t\t\t.filter(Boolean)\n\t\t\t\t.join(\" \");\n\nexport type BuildQueryURLArgs = QueryParams & BuildQueryURLParams;\n\n/**\n * Build a Prismic REST API V2 URL to request documents from a repository. The\n * paginated response for this URL includes documents matching the parameters.\n *\n * A ref is required to make a request. Request the `endpoint` URL to retrieve a\n * list of available refs.\n *\n * Type the JSON response with `Query`.\n *\n * {@link https://prismic.io/docs/technologies/introduction-to-the-content-query-api#prismic-api-ref}\n * {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api}\n *\n * @param endpoint - URL to the repository's REST API V2.\n * @param args - Arguments to filter and scope the query.\n *\n * @returns URL that can be used to request documents from the repository.\n */\nexport const buildQueryURL = (\n\tendpoint: string,\n\targs: BuildQueryURLArgs,\n): string => {\n\tconst { predicates, ...params } = args;\n\n\tconst url = new URL(`documents/search`, `${endpoint}/`);\n\n\tif (predicates) {\n\t\tfor (const predicate of castArray(predicates)) {\n\t\t\turl.searchParams.append(\"q\", `[${predicate}]`);\n\t\t}\n\t}\n\n\t// Iterate over each parameter and add it to the URL. In some cases, the\n\t// parameter value needs to be transformed to fit the REST API.\n\tfor (const k in params) {\n\t\tconst name = (RENAMED_PARAMS[k as keyof typeof RENAMED_PARAMS] ??\n\t\t\tk) as ValidParamName;\n\n\t\tlet value = params[k as keyof typeof params];\n\n\t\tif (name === \"orderings\") {\n\t\t\tconst scopedValue = params[name];\n\n\t\t\tif (scopedValue != null) {\n\t\t\t\tconst v = castArray(scopedValue)\n\t\t\t\t\t.map((ordering) => castOrderingToString(ordering))\n\t\t\t\t\t.join(\",\");\n\n\t\t\t\tvalue = `[${v}]`;\n\t\t\t}\n\t\t} else if (name === \"routes\") {\n\t\t\tif (typeof params[name] === \"object\") {\n\t\t\t\tvalue = JSON.stringify(castArray(params[name]));\n\t\t\t}\n\t\t}\n\n\t\tif (value != null) {\n\t\t\turl.searchParams.set(name, castArray(value).join(\",\"));\n\t\t}\n\t}\n\n\treturn url.toString();\n};\n"],"names":["castArray"],"mappings":";;;AAqIA,MAAM,iBAAiB;AAAA,EACtB,aAAa;;AAqBd,MAAM,uBAAuB,CAAC,aAC7B,OAAO,aAAa,WACjB,WACA;AAAA,EACA,SAAS;AAAA,EACT,SAAS,cAAc,SAAS,SAAS,YAAY;AACpD,EACA,OAAO,OAAO,EACd,KAAK,GAAG;AAqBA,MAAA,gBAAgB,CAC5B,UACA,SACW;AACL,QAAA,EAAE,eAAe,OAAA,IAAW;AAElC,QAAM,MAAM,IAAI,IAAI,oBAAoB,GAAG,WAAW;AAEtD,MAAI,YAAY;AACJ,eAAA,aAAaA,oBAAU,UAAU,GAAG;AAC9C,UAAI,aAAa,OAAO,KAAK,IAAI,YAAY;AAAA,IAC7C;AAAA,EACD;AAID,aAAW,KAAK,QAAQ;AACjB,UAAA,OAAQ,eAAe,MAC5B;AAED,QAAI,QAAQ,OAAO;AAEnB,QAAI,SAAS,aAAa;AACzB,YAAM,cAAc,OAAO;AAE3B,UAAI,eAAe,MAAM;AACxB,cAAM,IAAIA,UAAAA,UAAU,WAAW,EAC7B,IAAI,CAAC,aAAa,qBAAqB,QAAQ,CAAC,EAChD,KAAK,GAAG;AAEV,gBAAQ,IAAI;AAAA,MACZ;AAAA,IAAA,WACS,SAAS,UAAU;AACzB,UAAA,OAAO,OAAO,UAAU,UAAU;AACrC,gBAAQ,KAAK,UAAUA,UAAAA,UAAU,OAAO,KAAK,CAAC;AAAA,MAC9C;AAAA,IACD;AAED,QAAI,SAAS,MAAM;AACd,UAAA,aAAa,IAAI,MAAMA,UAAAA,UAAU,KAAK,EAAE,KAAK,GAAG,CAAC;AAAA,IACrD;AAAA,EACD;AAED,SAAO,IAAI;AACZ;;"}
@@ -0,0 +1,130 @@
1
+ import { Ordering, Route } from "./types";
2
+ /**
3
+ * Parameters for the Prismic REST API V2.
4
+ *
5
+ * {@link https://prismic.io/docs/technologies/introduction-to-the-content-query-api}
6
+ */
7
+ export interface QueryParams {
8
+ /**
9
+ * The secure token for accessing the API (only needed if your repository is
10
+ * set to private).
11
+ *
12
+ * {@link https://user-guides.prismic.io/en/articles/1036153-generating-an-access-token}
13
+ */
14
+ accessToken?: string;
15
+ /**
16
+ * The `pageSize` parameter defines the maximum number of documents that the
17
+ * API will return for your query.
18
+ *
19
+ * {@link https://prismic.io/docs/technologies/search-parameters-reference-rest-api#pagesize}
20
+ */
21
+ pageSize?: number;
22
+ /**
23
+ * The `page` parameter defines the pagination for the result of your query.
24
+ *
25
+ * {@link https://prismic.io/docs/technologies/search-parameters-reference-rest-api#page}
26
+ */
27
+ page?: number;
28
+ /**
29
+ * The `after` parameter can be used along with the orderings option. It will
30
+ * remove all the documents except for those after the specified document in
31
+ * the list.
32
+ *
33
+ * {@link https://prismic.io/docs/technologies/search-parameters-reference-rest-api#after}
34
+ */
35
+ after?: string;
36
+ /**
37
+ * The `fetch` parameter is used to make queries faster by only retrieving the
38
+ * specified field(s).
39
+ *
40
+ * {@link https://prismic.io/docs/technologies/search-parameters-reference-rest-api#fetch}
41
+ */
42
+ fetch?: string | string[];
43
+ /**
44
+ * The `fetchLinks` parameter allows you to retrieve a specific content field
45
+ * from a linked document and add it to the document response object.
46
+ *
47
+ * {@link https://prismic.io/docs/technologies/search-parameters-reference-rest-api#fetchlinks}
48
+ */
49
+ fetchLinks?: string | string[];
50
+ /**
51
+ * The `graphQuery` parameter allows you to specify which fields to retrieve
52
+ * and what content to retrieve from Linked Documents / Content
53
+ * Relationships.
54
+ *
55
+ * {@link https://prismic.io/docs/technologies/graphquery-rest-api}
56
+ */
57
+ graphQuery?: string;
58
+ /**
59
+ * The `lang` option defines the language code for the results of your query.
60
+ *
61
+ * {@link https://prismic.io/docs/technologies/search-parameters-reference-rest-api#lang}
62
+ */
63
+ lang?: string;
64
+ /**
65
+ * The `orderings` parameter orders the results by the specified field(s). You
66
+ * can specify as many fields as you want.
67
+ *
68
+ * {@link https://prismic.io/docs/technologies/search-parameters-reference-rest-api#orderings}
69
+ */
70
+ orderings?: Ordering | string | (Ordering | string)[];
71
+ /**
72
+ * The `routes` option allows you to define how a document's `url` field is
73
+ * resolved.
74
+ *
75
+ * {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#route-resolver}
76
+ */
77
+ routes?: Route | string | (Route | string)[];
78
+ /**
79
+ * The `brokenRoute` option allows you to define the route populated in the
80
+ * `url` property for broken Link or Content Relationship fields. A broken
81
+ * link is a Link or Content Relationship field whose linked document has been
82
+ * unpublished or deleted.
83
+ *
84
+ * {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#route-resolver}
85
+ */
86
+ brokenRoute?: string;
87
+ }
88
+ /**
89
+ * Arguments for `buildQueryURL` to construct a Query URL.
90
+ */
91
+ type BuildQueryURLParams = {
92
+ /**
93
+ * Ref used to query documents.
94
+ *
95
+ * {@link https://prismic.io/docs/technologies/introduction-to-the-content-query-api#prismic-api-ref}
96
+ */
97
+ ref: string;
98
+ /**
99
+ * Ref used to populate Integration Fields with the latest content.
100
+ *
101
+ * {@link https://prismic.io/docs/core-concepts/integration-fields}
102
+ */
103
+ integrationFieldsRef?: string;
104
+ /**
105
+ * One or more predicates to filter documents for the query.
106
+ *
107
+ * {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api}
108
+ */
109
+ predicates?: string | string[];
110
+ };
111
+ export type BuildQueryURLArgs = QueryParams & BuildQueryURLParams;
112
+ /**
113
+ * Build a Prismic REST API V2 URL to request documents from a repository. The
114
+ * paginated response for this URL includes documents matching the parameters.
115
+ *
116
+ * A ref is required to make a request. Request the `endpoint` URL to retrieve a
117
+ * list of available refs.
118
+ *
119
+ * Type the JSON response with `Query`.
120
+ *
121
+ * {@link https://prismic.io/docs/technologies/introduction-to-the-content-query-api#prismic-api-ref}
122
+ * {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api}
123
+ *
124
+ * @param endpoint - URL to the repository's REST API V2.
125
+ * @param args - Arguments to filter and scope the query.
126
+ *
127
+ * @returns URL that can be used to request documents from the repository.
128
+ */
129
+ export declare const buildQueryURL: (endpoint: string, args: BuildQueryURLArgs) => string;
130
+ export {};
@@ -0,0 +1,40 @@
1
+ import { castArray } from "./lib/castArray.js";
2
+ const RENAMED_PARAMS = {
3
+ accessToken: "access_token"
4
+ };
5
+ const castOrderingToString = (ordering) => typeof ordering === "string" ? ordering : [
6
+ ordering.field,
7
+ ordering.direction === "desc" ? ordering.direction : void 0
8
+ ].filter(Boolean).join(" ");
9
+ const buildQueryURL = (endpoint, args) => {
10
+ const { predicates, ...params } = args;
11
+ const url = new URL(`documents/search`, `${endpoint}/`);
12
+ if (predicates) {
13
+ for (const predicate of castArray(predicates)) {
14
+ url.searchParams.append("q", `[${predicate}]`);
15
+ }
16
+ }
17
+ for (const k in params) {
18
+ const name = RENAMED_PARAMS[k] ?? k;
19
+ let value = params[k];
20
+ if (name === "orderings") {
21
+ const scopedValue = params[name];
22
+ if (scopedValue != null) {
23
+ const v = castArray(scopedValue).map((ordering) => castOrderingToString(ordering)).join(",");
24
+ value = `[${v}]`;
25
+ }
26
+ } else if (name === "routes") {
27
+ if (typeof params[name] === "object") {
28
+ value = JSON.stringify(castArray(params[name]));
29
+ }
30
+ }
31
+ if (value != null) {
32
+ url.searchParams.set(name, castArray(value).join(","));
33
+ }
34
+ }
35
+ return url.toString();
36
+ };
37
+ export {
38
+ buildQueryURL
39
+ };
40
+ //# sourceMappingURL=buildQueryURL.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildQueryURL.js","sources":["../../src/buildQueryURL.ts"],"sourcesContent":["import { castArray } from \"./lib/castArray\";\n\nimport { ValueOf, Ordering, Route } from \"./types\";\n\n/**\n * Parameters for the Prismic REST API V2.\n *\n * {@link https://prismic.io/docs/technologies/introduction-to-the-content-query-api}\n */\nexport interface QueryParams {\n\t/**\n\t * The secure token for accessing the API (only needed if your repository is\n\t * set to private).\n\t *\n\t * {@link https://user-guides.prismic.io/en/articles/1036153-generating-an-access-token}\n\t */\n\taccessToken?: string;\n\n\t/**\n\t * The `pageSize` parameter defines the maximum number of documents that the\n\t * API will return for your query.\n\t *\n\t * {@link https://prismic.io/docs/technologies/search-parameters-reference-rest-api#pagesize}\n\t */\n\tpageSize?: number;\n\n\t/**\n\t * The `page` parameter defines the pagination for the result of your query.\n\t *\n\t * {@link https://prismic.io/docs/technologies/search-parameters-reference-rest-api#page}\n\t */\n\tpage?: number;\n\n\t/**\n\t * The `after` parameter can be used along with the orderings option. It will\n\t * remove all the documents except for those after the specified document in\n\t * the list.\n\t *\n\t * {@link https://prismic.io/docs/technologies/search-parameters-reference-rest-api#after}\n\t */\n\tafter?: string;\n\n\t/**\n\t * The `fetch` parameter is used to make queries faster by only retrieving the\n\t * specified field(s).\n\t *\n\t * {@link https://prismic.io/docs/technologies/search-parameters-reference-rest-api#fetch}\n\t */\n\tfetch?: string | string[];\n\n\t/**\n\t * The `fetchLinks` parameter allows you to retrieve a specific content field\n\t * from a linked document and add it to the document response object.\n\t *\n\t * {@link https://prismic.io/docs/technologies/search-parameters-reference-rest-api#fetchlinks}\n\t */\n\tfetchLinks?: string | string[];\n\n\t/**\n\t * The `graphQuery` parameter allows you to specify which fields to retrieve\n\t * and what content to retrieve from Linked Documents / Content\n\t * Relationships.\n\t *\n\t * {@link https://prismic.io/docs/technologies/graphquery-rest-api}\n\t */\n\tgraphQuery?: string;\n\n\t/**\n\t * The `lang` option defines the language code for the results of your query.\n\t *\n\t * {@link https://prismic.io/docs/technologies/search-parameters-reference-rest-api#lang}\n\t */\n\tlang?: string;\n\n\t/**\n\t * The `orderings` parameter orders the results by the specified field(s). You\n\t * can specify as many fields as you want.\n\t *\n\t * {@link https://prismic.io/docs/technologies/search-parameters-reference-rest-api#orderings}\n\t */\n\torderings?: Ordering | string | (Ordering | string)[];\n\n\t/**\n\t * The `routes` option allows you to define how a document's `url` field is\n\t * resolved.\n\t *\n\t * {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#route-resolver}\n\t */\n\troutes?: Route | string | (Route | string)[];\n\n\t/**\n\t * The `brokenRoute` option allows you to define the route populated in the\n\t * `url` property for broken Link or Content Relationship fields. A broken\n\t * link is a Link or Content Relationship field whose linked document has been\n\t * unpublished or deleted.\n\t *\n\t * {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#route-resolver}\n\t */\n\tbrokenRoute?: string;\n}\n\n/**\n * Arguments for `buildQueryURL` to construct a Query URL.\n */\ntype BuildQueryURLParams = {\n\t/**\n\t * Ref used to query documents.\n\t *\n\t * {@link https://prismic.io/docs/technologies/introduction-to-the-content-query-api#prismic-api-ref}\n\t */\n\tref: string;\n\n\t/**\n\t * Ref used to populate Integration Fields with the latest content.\n\t *\n\t * {@link https://prismic.io/docs/core-concepts/integration-fields}\n\t */\n\tintegrationFieldsRef?: string;\n\n\t/**\n\t * One or more predicates to filter documents for the query.\n\t *\n\t * {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api}\n\t */\n\tpredicates?: string | string[];\n};\n\n/**\n * Parameters in this map have been renamed from the official Prismic REST API\n * V2 specification for better developer ergonomics.\n *\n * These parameters are renamed to their mapped value.\n */\nconst RENAMED_PARAMS = {\n\taccessToken: \"access_token\",\n} as const;\n\n/**\n * A valid parameter name for the Prismic REST API V2.\n */\ntype ValidParamName =\n\t| Exclude<\n\t\t\tkeyof QueryParams,\n\t\t\tkeyof typeof RENAMED_PARAMS | keyof BuildQueryURLParams\n\t >\n\t| ValueOf<typeof RENAMED_PARAMS>;\n\n/**\n * Converts an Ordering to a string that is compatible with Prismic's REST API.\n * If the value provided is already a string, no conversion is performed.\n *\n * @param ordering - Ordering to convert.\n *\n * @returns String representation of the Ordering.\n */\nconst castOrderingToString = (ordering: Ordering | string): string =>\n\ttypeof ordering === \"string\"\n\t\t? ordering\n\t\t: [\n\t\t\t\tordering.field,\n\t\t\t\tordering.direction === \"desc\" ? ordering.direction : undefined,\n\t\t ]\n\t\t\t\t.filter(Boolean)\n\t\t\t\t.join(\" \");\n\nexport type BuildQueryURLArgs = QueryParams & BuildQueryURLParams;\n\n/**\n * Build a Prismic REST API V2 URL to request documents from a repository. The\n * paginated response for this URL includes documents matching the parameters.\n *\n * A ref is required to make a request. Request the `endpoint` URL to retrieve a\n * list of available refs.\n *\n * Type the JSON response with `Query`.\n *\n * {@link https://prismic.io/docs/technologies/introduction-to-the-content-query-api#prismic-api-ref}\n * {@link https://prismic.io/docs/technologies/query-predicates-reference-rest-api}\n *\n * @param endpoint - URL to the repository's REST API V2.\n * @param args - Arguments to filter and scope the query.\n *\n * @returns URL that can be used to request documents from the repository.\n */\nexport const buildQueryURL = (\n\tendpoint: string,\n\targs: BuildQueryURLArgs,\n): string => {\n\tconst { predicates, ...params } = args;\n\n\tconst url = new URL(`documents/search`, `${endpoint}/`);\n\n\tif (predicates) {\n\t\tfor (const predicate of castArray(predicates)) {\n\t\t\turl.searchParams.append(\"q\", `[${predicate}]`);\n\t\t}\n\t}\n\n\t// Iterate over each parameter and add it to the URL. In some cases, the\n\t// parameter value needs to be transformed to fit the REST API.\n\tfor (const k in params) {\n\t\tconst name = (RENAMED_PARAMS[k as keyof typeof RENAMED_PARAMS] ??\n\t\t\tk) as ValidParamName;\n\n\t\tlet value = params[k as keyof typeof params];\n\n\t\tif (name === \"orderings\") {\n\t\t\tconst scopedValue = params[name];\n\n\t\t\tif (scopedValue != null) {\n\t\t\t\tconst v = castArray(scopedValue)\n\t\t\t\t\t.map((ordering) => castOrderingToString(ordering))\n\t\t\t\t\t.join(\",\");\n\n\t\t\t\tvalue = `[${v}]`;\n\t\t\t}\n\t\t} else if (name === \"routes\") {\n\t\t\tif (typeof params[name] === \"object\") {\n\t\t\t\tvalue = JSON.stringify(castArray(params[name]));\n\t\t\t}\n\t\t}\n\n\t\tif (value != null) {\n\t\t\turl.searchParams.set(name, castArray(value).join(\",\"));\n\t\t}\n\t}\n\n\treturn url.toString();\n};\n"],"names":[],"mappings":";AAqIA,MAAM,iBAAiB;AAAA,EACtB,aAAa;;AAqBd,MAAM,uBAAuB,CAAC,aAC7B,OAAO,aAAa,WACjB,WACA;AAAA,EACA,SAAS;AAAA,EACT,SAAS,cAAc,SAAS,SAAS,YAAY;AACpD,EACA,OAAO,OAAO,EACd,KAAK,GAAG;AAqBA,MAAA,gBAAgB,CAC5B,UACA,SACW;AACL,QAAA,EAAE,eAAe,OAAA,IAAW;AAElC,QAAM,MAAM,IAAI,IAAI,oBAAoB,GAAG,WAAW;AAEtD,MAAI,YAAY;AACJ,eAAA,aAAa,UAAU,UAAU,GAAG;AAC9C,UAAI,aAAa,OAAO,KAAK,IAAI,YAAY;AAAA,IAC7C;AAAA,EACD;AAID,aAAW,KAAK,QAAQ;AACjB,UAAA,OAAQ,eAAe,MAC5B;AAED,QAAI,QAAQ,OAAO;AAEnB,QAAI,SAAS,aAAa;AACzB,YAAM,cAAc,OAAO;AAE3B,UAAI,eAAe,MAAM;AACxB,cAAM,IAAI,UAAU,WAAW,EAC7B,IAAI,CAAC,aAAa,qBAAqB,QAAQ,CAAC,EAChD,KAAK,GAAG;AAEV,gBAAQ,IAAI;AAAA,MACZ;AAAA,IAAA,WACS,SAAS,UAAU;AACzB,UAAA,OAAO,OAAO,UAAU,UAAU;AACrC,gBAAQ,KAAK,UAAU,UAAU,OAAO,KAAK,CAAC;AAAA,MAC9C;AAAA,IACD;AAED,QAAI,SAAS,MAAM;AACd,UAAA,aAAa,IAAI,MAAM,UAAU,KAAK,EAAE,KAAK,GAAG,CAAC;AAAA,IACrD;AAAA,EACD;AAED,SAAO,IAAI;AACZ;"}