@prismicio/client 7.0.0-alpha.0 → 7.0.0-alpha.2

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 (396) hide show
  1. package/README.md +4 -4
  2. package/dist/buildQueryURL.cjs +26 -8
  3. package/dist/buildQueryURL.cjs.map +1 -1
  4. package/dist/buildQueryURL.d.ts +207 -130
  5. package/dist/buildQueryURL.js +25 -7
  6. package/dist/buildQueryURL.js.map +1 -1
  7. package/dist/cookie.cjs +1 -1
  8. package/dist/cookie.cjs.map +1 -1
  9. package/dist/cookie.d.ts +5 -5
  10. package/dist/cookie.js.map +1 -1
  11. package/dist/createClient.cjs +1142 -0
  12. package/dist/createClient.cjs.map +1 -0
  13. package/dist/{client.d.ts → createClient.d.ts} +980 -908
  14. package/dist/createClient.js +1142 -0
  15. package/dist/createClient.js.map +1 -0
  16. package/dist/{ForbiddenError.cjs → errors/ForbiddenError.cjs} +1 -1
  17. package/dist/errors/ForbiddenError.cjs.map +1 -0
  18. package/dist/{ForbiddenError.d.ts → errors/ForbiddenError.d.ts} +11 -11
  19. package/dist/errors/ForbiddenError.js.map +1 -0
  20. package/dist/{NotFoundError.cjs → errors/NotFoundError.cjs} +1 -1
  21. package/dist/errors/NotFoundError.cjs.map +1 -0
  22. package/dist/{NotFoundError.d.ts → errors/NotFoundError.d.ts} +3 -3
  23. package/dist/errors/NotFoundError.js.map +1 -0
  24. package/dist/{ParsingError.cjs → errors/ParsingError.cjs} +1 -1
  25. package/dist/errors/ParsingError.cjs.map +1 -0
  26. package/dist/{ParsingError.d.ts → errors/ParsingError.d.ts} +12 -12
  27. package/dist/errors/ParsingError.js.map +1 -0
  28. package/dist/{PrismicError.cjs → errors/PrismicError.cjs} +1 -1
  29. package/dist/errors/PrismicError.cjs.map +1 -0
  30. package/dist/{PrismicError.d.ts → errors/PrismicError.d.ts} +5 -5
  31. package/dist/errors/PrismicError.js.map +1 -0
  32. package/dist/filter.cjs +247 -0
  33. package/dist/filter.cjs.map +1 -0
  34. package/dist/filter.d.ts +209 -0
  35. package/dist/filter.js +247 -0
  36. package/dist/filter.js.map +1 -0
  37. package/dist/getGraphQLEndpoint.cjs +2 -2
  38. package/dist/getGraphQLEndpoint.cjs.map +1 -1
  39. package/dist/getGraphQLEndpoint.d.ts +9 -9
  40. package/dist/getGraphQLEndpoint.js +1 -1
  41. package/dist/getGraphQLEndpoint.js.map +1 -1
  42. package/dist/getRepositoryEndpoint.cjs +2 -2
  43. package/dist/getRepositoryEndpoint.cjs.map +1 -1
  44. package/dist/getRepositoryEndpoint.d.ts +10 -10
  45. package/dist/getRepositoryEndpoint.js +1 -1
  46. package/dist/getRepositoryEndpoint.js.map +1 -1
  47. package/dist/getRepositoryName.cjs +2 -2
  48. package/dist/getRepositoryName.cjs.map +1 -1
  49. package/dist/getRepositoryName.d.ts +13 -13
  50. package/dist/getRepositoryName.js +1 -1
  51. package/dist/getRepositoryName.js.map +1 -1
  52. package/dist/getToolbarSrc.cjs +13 -0
  53. package/dist/getToolbarSrc.cjs.map +1 -0
  54. package/dist/getToolbarSrc.d.ts +34 -0
  55. package/dist/getToolbarSrc.js +13 -0
  56. package/dist/getToolbarSrc.js.map +1 -0
  57. package/dist/helpers/asDate.cjs +1 -1
  58. package/dist/helpers/asDate.cjs.map +1 -1
  59. package/dist/helpers/asDate.d.ts +16 -16
  60. package/dist/helpers/asDate.js.map +1 -1
  61. package/dist/helpers/asHTML.cjs +7 -6
  62. package/dist/helpers/asHTML.cjs.map +1 -1
  63. package/dist/helpers/asHTML.d.ts +77 -20
  64. package/dist/helpers/asHTML.js +6 -5
  65. package/dist/helpers/asHTML.js.map +1 -1
  66. package/dist/helpers/asImagePixelDensitySrcSet.cjs +1 -1
  67. package/dist/helpers/asImagePixelDensitySrcSet.cjs.map +1 -1
  68. package/dist/helpers/asImagePixelDensitySrcSet.d.ts +52 -52
  69. package/dist/helpers/asImagePixelDensitySrcSet.js.map +1 -1
  70. package/dist/helpers/asImageSrc.cjs +1 -1
  71. package/dist/helpers/asImageSrc.cjs.map +1 -1
  72. package/dist/helpers/asImageSrc.d.ts +27 -27
  73. package/dist/helpers/asImageSrc.js.map +1 -1
  74. package/dist/helpers/asImageWidthSrcSet.cjs +19 -14
  75. package/dist/helpers/asImageWidthSrcSet.cjs.map +1 -1
  76. package/dist/helpers/asImageWidthSrcSet.d.ts +60 -60
  77. package/dist/helpers/asImageWidthSrcSet.js +18 -13
  78. package/dist/helpers/asImageWidthSrcSet.js.map +1 -1
  79. package/dist/helpers/asLink.cjs +8 -2
  80. package/dist/helpers/asLink.cjs.map +1 -1
  81. package/dist/helpers/asLink.d.ts +34 -24
  82. package/dist/helpers/asLink.js +7 -1
  83. package/dist/helpers/asLink.js.map +1 -1
  84. package/dist/helpers/asLinkAttrs.cjs +28 -0
  85. package/dist/helpers/asLinkAttrs.cjs.map +1 -0
  86. package/dist/helpers/asLinkAttrs.d.ts +63 -0
  87. package/dist/helpers/asLinkAttrs.js +28 -0
  88. package/dist/helpers/asLinkAttrs.js.map +1 -0
  89. package/dist/helpers/asText.cjs +1 -1
  90. package/dist/helpers/asText.cjs.map +1 -1
  91. package/dist/helpers/asText.d.ts +16 -16
  92. package/dist/helpers/asText.js.map +1 -1
  93. package/dist/helpers/documentToLinkField.cjs +12 -5
  94. package/dist/helpers/documentToLinkField.cjs.map +1 -1
  95. package/dist/helpers/documentToLinkField.d.ts +15 -15
  96. package/dist/helpers/documentToLinkField.js +11 -4
  97. package/dist/helpers/documentToLinkField.js.map +1 -1
  98. package/dist/helpers/isFilled.cjs +1 -1
  99. package/dist/helpers/isFilled.cjs.map +1 -1
  100. package/dist/helpers/isFilled.d.ts +172 -175
  101. package/dist/helpers/isFilled.js.map +1 -1
  102. package/dist/index.cjs +20 -14
  103. package/dist/index.cjs.map +1 -1
  104. package/dist/index.d.ts +139 -92
  105. package/dist/index.js +12 -6
  106. package/dist/index.js.map +1 -1
  107. package/dist/isRepositoryEndpoint.cjs +1 -1
  108. package/dist/isRepositoryEndpoint.cjs.map +1 -1
  109. package/dist/isRepositoryEndpoint.d.ts +10 -10
  110. package/dist/isRepositoryEndpoint.js.map +1 -1
  111. package/dist/isRepositoryName.cjs +1 -1
  112. package/dist/isRepositoryName.cjs.map +1 -1
  113. package/dist/isRepositoryName.d.ts +9 -9
  114. package/dist/isRepositoryName.js.map +1 -1
  115. package/dist/lib/appendFilters.cjs +11 -0
  116. package/dist/lib/appendFilters.cjs.map +1 -0
  117. package/dist/lib/appendFilters.d.ts +18 -0
  118. package/dist/lib/appendFilters.js +11 -0
  119. package/dist/lib/appendFilters.js.map +1 -0
  120. package/dist/lib/castArray.cjs +4 -2
  121. package/dist/lib/castArray.cjs.map +1 -1
  122. package/dist/lib/castArray.d.ts +11 -11
  123. package/dist/lib/castArray.js +3 -1
  124. package/dist/lib/castArray.js.map +1 -1
  125. package/dist/lib/castThunk.cjs +4 -2
  126. package/dist/lib/castThunk.cjs.map +1 -1
  127. package/dist/lib/castThunk.d.ts +10 -10
  128. package/dist/lib/castThunk.js +3 -1
  129. package/dist/lib/castThunk.js.map +1 -1
  130. package/dist/lib/devMsg.cjs +8 -0
  131. package/dist/lib/devMsg.cjs.map +1 -0
  132. package/dist/lib/devMsg.d.ts +16 -0
  133. package/dist/lib/devMsg.js +8 -0
  134. package/dist/lib/devMsg.js.map +1 -0
  135. package/dist/lib/escapeHTML.cjs +43 -0
  136. package/dist/lib/escapeHTML.cjs.map +1 -0
  137. package/dist/lib/escapeHTML.d.ts +1 -0
  138. package/dist/lib/escapeHTML.js +43 -0
  139. package/dist/lib/escapeHTML.js.map +1 -0
  140. package/dist/lib/everyTagFilter.cjs +9 -0
  141. package/dist/lib/everyTagFilter.cjs.map +1 -0
  142. package/dist/lib/everyTagFilter.d.ts +9 -0
  143. package/dist/lib/everyTagFilter.js +9 -0
  144. package/dist/lib/everyTagFilter.js.map +1 -0
  145. package/dist/lib/findMasterRef.cjs +1 -1
  146. package/dist/lib/findMasterRef.cjs.map +1 -1
  147. package/dist/lib/findMasterRef.d.ts +10 -10
  148. package/dist/lib/findMasterRef.js.map +1 -1
  149. package/dist/lib/findRef.cjs +4 -4
  150. package/dist/lib/findRef.cjs.map +1 -1
  151. package/dist/lib/findRef.d.ts +13 -13
  152. package/dist/lib/findRef.js +3 -3
  153. package/dist/lib/findRef.js.map +1 -1
  154. package/dist/lib/findRefByID.cjs +1 -1
  155. package/dist/lib/findRefByID.cjs.map +1 -1
  156. package/dist/lib/findRefByID.d.ts +11 -11
  157. package/dist/lib/findRefByID.js.map +1 -1
  158. package/dist/lib/findRefByLabel.cjs +1 -1
  159. package/dist/lib/findRefByLabel.cjs.map +1 -1
  160. package/dist/lib/findRefByLabel.d.ts +11 -11
  161. package/dist/lib/findRefByLabel.js.map +1 -1
  162. package/dist/lib/getPreviewCookie.cjs +1 -1
  163. package/dist/lib/getPreviewCookie.cjs.map +1 -1
  164. package/dist/lib/getPreviewCookie.d.ts +9 -9
  165. package/dist/lib/getPreviewCookie.js.map +1 -1
  166. package/dist/lib/isInternalURL.cjs +9 -0
  167. package/dist/lib/isInternalURL.cjs.map +1 -0
  168. package/dist/lib/isInternalURL.d.ts +8 -0
  169. package/dist/lib/isInternalURL.js +9 -0
  170. package/dist/lib/isInternalURL.js.map +1 -0
  171. package/dist/lib/minifyGraphQLQuery.cjs +1 -1
  172. package/dist/lib/minifyGraphQLQuery.cjs.map +1 -1
  173. package/dist/lib/minifyGraphQLQuery.d.ts +8 -8
  174. package/dist/lib/minifyGraphQLQuery.js.map +1 -1
  175. package/dist/lib/serializerHelpers.cjs +7 -9
  176. package/dist/lib/serializerHelpers.cjs.map +1 -1
  177. package/dist/lib/serializerHelpers.d.ts +9 -9
  178. package/dist/lib/serializerHelpers.js +6 -6
  179. package/dist/lib/serializerHelpers.js.map +1 -1
  180. package/dist/lib/someTagsFilter.cjs +9 -0
  181. package/dist/lib/someTagsFilter.cjs.map +1 -0
  182. package/dist/lib/someTagsFilter.d.ts +9 -0
  183. package/dist/lib/someTagsFilter.js +9 -0
  184. package/dist/lib/someTagsFilter.js.map +1 -0
  185. package/dist/lib/typeFilter.cjs +8 -0
  186. package/dist/lib/typeFilter.cjs.map +1 -0
  187. package/dist/lib/typeFilter.d.ts +8 -0
  188. package/dist/lib/typeFilter.js +8 -0
  189. package/dist/lib/typeFilter.js.map +1 -0
  190. package/dist/package.json.cjs +5 -0
  191. package/dist/package.json.cjs.map +1 -0
  192. package/dist/package.json.js +5 -0
  193. package/dist/package.json.js.map +1 -0
  194. package/dist/types/api/query.d.ts +42 -42
  195. package/dist/types/api/ref.d.ts +32 -32
  196. package/dist/types/api/release.d.ts +10 -10
  197. package/dist/types/api/repository.d.ts +100 -100
  198. package/dist/types/api/tags.d.ts +8 -8
  199. package/dist/types/model/boolean.d.ts +15 -15
  200. package/dist/types/model/color.d.ts +13 -13
  201. package/dist/types/model/contentRelationship.d.ts +18 -18
  202. package/dist/types/model/customType.d.ts +42 -42
  203. package/dist/types/model/date.d.ts +14 -14
  204. package/dist/types/model/embed.d.ts +13 -13
  205. package/dist/types/model/geoPoint.d.ts +12 -12
  206. package/dist/types/model/group.d.ts +15 -15
  207. package/dist/types/model/image.d.ts +31 -31
  208. package/dist/types/model/integrationFields.d.ts +14 -14
  209. package/dist/types/model/keyText.d.ts +13 -13
  210. package/dist/types/model/link.cjs +1 -1
  211. package/dist/types/model/link.cjs.map +1 -1
  212. package/dist/types/model/link.d.ts +27 -27
  213. package/dist/types/model/link.js.map +1 -1
  214. package/dist/types/model/linkToMedia.d.ts +16 -16
  215. package/dist/types/model/number.d.ts +15 -15
  216. package/dist/types/model/range.d.ts +14 -14
  217. package/dist/types/model/richText.d.ts +35 -35
  218. package/dist/types/model/select.d.ts +18 -18
  219. package/dist/types/model/separator.d.ts +10 -10
  220. package/dist/types/model/sharedSlice.d.ts +16 -19
  221. package/dist/types/model/sharedSliceVariation.d.ts +19 -22
  222. package/dist/types/model/slice.cjs +1 -1
  223. package/dist/types/model/slice.cjs.map +1 -1
  224. package/dist/types/model/slice.d.ts +33 -33
  225. package/dist/types/model/slice.js.map +1 -1
  226. package/dist/types/model/sliceZone.cjs +1 -1
  227. package/dist/types/model/sliceZone.cjs.map +1 -1
  228. package/dist/types/model/sliceZone.d.ts +41 -44
  229. package/dist/types/model/sliceZone.js.map +1 -1
  230. package/dist/types/model/timestamp.d.ts +14 -14
  231. package/dist/types/model/title.d.ts +7 -7
  232. package/dist/types/model/types.cjs +10 -1
  233. package/dist/types/model/types.cjs.map +1 -1
  234. package/dist/types/model/types.d.ts +62 -62
  235. package/dist/types/model/types.js +9 -0
  236. package/dist/types/model/types.js.map +1 -1
  237. package/dist/types/model/uid.d.ts +13 -13
  238. package/dist/types/value/boolean.d.ts +6 -6
  239. package/dist/types/value/color.d.ts +8 -8
  240. package/dist/types/value/contentRelationship.d.ts +29 -29
  241. package/dist/types/value/date.d.ts +8 -8
  242. package/dist/types/value/document.d.ts +113 -113
  243. package/dist/types/value/embed.cjs +1 -1
  244. package/dist/types/value/embed.cjs.map +1 -1
  245. package/dist/types/value/embed.d.ts +167 -167
  246. package/dist/types/value/embed.js.map +1 -1
  247. package/dist/types/value/geoPoint.d.ts +11 -11
  248. package/dist/types/value/group.d.ts +7 -7
  249. package/dist/types/value/image.d.ts +36 -36
  250. package/dist/types/value/integrationFields.d.ts +9 -9
  251. package/dist/types/value/keyText.d.ts +8 -8
  252. package/dist/types/value/link.cjs +1 -1
  253. package/dist/types/value/link.cjs.map +1 -1
  254. package/dist/types/value/link.d.ts +40 -40
  255. package/dist/types/value/link.js.map +1 -1
  256. package/dist/types/value/linkToMedia.d.ts +20 -20
  257. package/dist/types/value/number.d.ts +8 -8
  258. package/dist/types/value/richText.cjs +1 -1
  259. package/dist/types/value/richText.cjs.map +1 -1
  260. package/dist/types/value/richText.d.ts +203 -203
  261. package/dist/types/value/richText.js.map +1 -1
  262. package/dist/types/value/select.d.ts +9 -9
  263. package/dist/types/value/sharedSlice.d.ts +11 -11
  264. package/dist/types/value/sharedSliceVariation.d.ts +7 -7
  265. package/dist/types/value/slice.d.ts +13 -13
  266. package/dist/types/value/sliceZone.d.ts +12 -12
  267. package/dist/types/value/timestamp.d.ts +8 -8
  268. package/dist/types/value/title.d.ts +12 -12
  269. package/dist/types/value/types.d.ts +40 -40
  270. package/dist/types/webhook/apiUpdate.d.ts +52 -52
  271. package/dist/types/webhook/testTrigger.d.ts +9 -9
  272. package/dist/types/webhook/types.cjs +1 -1
  273. package/dist/types/webhook/types.cjs.map +1 -1
  274. package/dist/types/webhook/types.d.ts +18 -18
  275. package/dist/types/webhook/types.js.map +1 -1
  276. package/package.json +23 -24
  277. package/src/buildQueryURL.ts +179 -33
  278. package/src/{client.ts → createClient.ts} +214 -110
  279. package/src/filter.ts +356 -0
  280. package/src/getGraphQLEndpoint.ts +2 -1
  281. package/src/getRepositoryEndpoint.ts +2 -1
  282. package/src/getRepositoryName.ts +1 -1
  283. package/src/getToolbarSrc.ts +50 -0
  284. package/src/helpers/asDate.ts +3 -3
  285. package/src/helpers/asHTML.ts +122 -27
  286. package/src/helpers/asImagePixelDensitySrcSet.ts +1 -1
  287. package/src/helpers/asImageSrc.ts +1 -1
  288. package/src/helpers/asImageWidthSrcSet.ts +1 -1
  289. package/src/helpers/asLink.ts +37 -18
  290. package/src/helpers/asLinkAttrs.ts +127 -0
  291. package/src/helpers/asText.ts +4 -4
  292. package/src/helpers/documentToLinkField.ts +3 -3
  293. package/src/helpers/isFilled.ts +9 -11
  294. package/src/index.ts +60 -29
  295. package/src/lib/appendFilters.ts +26 -0
  296. package/src/lib/castArray.ts +3 -1
  297. package/src/lib/castThunk.ts +3 -2
  298. package/src/lib/devMsg.ts +20 -0
  299. package/src/lib/escapeHTML.ts +51 -0
  300. package/src/lib/everyTagFilter.ts +15 -0
  301. package/src/lib/findRef.ts +5 -5
  302. package/src/lib/isInternalURL.ts +14 -0
  303. package/src/lib/serializerHelpers.ts +20 -15
  304. package/src/lib/someTagsFilter.ts +15 -0
  305. package/src/lib/typeFilter.ts +12 -0
  306. package/src/types/api/query.ts +1 -1
  307. package/src/types/api/ref.ts +2 -2
  308. package/src/types/api/release.ts +1 -1
  309. package/src/types/api/repository.ts +1 -1
  310. package/src/types/api/tags.ts +1 -1
  311. package/src/types/model/boolean.ts +1 -1
  312. package/src/types/model/color.ts +1 -1
  313. package/src/types/model/contentRelationship.ts +2 -1
  314. package/src/types/model/date.ts +1 -1
  315. package/src/types/model/embed.ts +1 -1
  316. package/src/types/model/geoPoint.ts +1 -1
  317. package/src/types/model/group.ts +2 -2
  318. package/src/types/model/image.ts +3 -3
  319. package/src/types/model/integrationFields.ts +1 -1
  320. package/src/types/model/keyText.ts +1 -1
  321. package/src/types/model/link.ts +3 -3
  322. package/src/types/model/linkToMedia.ts +2 -1
  323. package/src/types/model/number.ts +1 -1
  324. package/src/types/model/richText.ts +3 -3
  325. package/src/types/model/select.ts +1 -1
  326. package/src/types/model/sharedSlice.ts +2 -5
  327. package/src/types/model/sharedSliceVariation.ts +1 -4
  328. package/src/types/model/slice.ts +5 -4
  329. package/src/types/model/sliceZone.ts +5 -7
  330. package/src/types/model/timestamp.ts +1 -1
  331. package/src/types/model/title.ts +1 -1
  332. package/src/types/model/types.ts +12 -16
  333. package/src/types/model/uid.ts +1 -1
  334. package/src/types/value/boolean.ts +1 -1
  335. package/src/types/value/color.ts +1 -1
  336. package/src/types/value/contentRelationship.ts +8 -9
  337. package/src/types/value/date.ts +1 -1
  338. package/src/types/value/document.ts +6 -5
  339. package/src/types/value/embed.ts +2 -2
  340. package/src/types/value/geoPoint.ts +1 -1
  341. package/src/types/value/group.ts +2 -2
  342. package/src/types/value/image.ts +1 -1
  343. package/src/types/value/integrationFields.ts +1 -1
  344. package/src/types/value/keyText.ts +1 -1
  345. package/src/types/value/link.ts +8 -8
  346. package/src/types/value/linkToMedia.ts +2 -1
  347. package/src/types/value/number.ts +1 -1
  348. package/src/types/value/richText.ts +6 -5
  349. package/src/types/value/select.ts +1 -1
  350. package/src/types/value/sharedSlice.ts +1 -1
  351. package/src/types/value/slice.ts +1 -1
  352. package/src/types/value/sliceZone.ts +2 -1
  353. package/src/types/value/timestamp.ts +1 -0
  354. package/src/types/value/title.ts +2 -1
  355. package/src/types/value/types.ts +9 -11
  356. package/src/types/webhook/apiUpdate.ts +4 -4
  357. package/src/types/webhook/testTrigger.ts +1 -1
  358. package/src/types/webhook/types.ts +2 -2
  359. package/dist/ForbiddenError.cjs.map +0 -1
  360. package/dist/ForbiddenError.js.map +0 -1
  361. package/dist/NotFoundError.cjs.map +0 -1
  362. package/dist/NotFoundError.js.map +0 -1
  363. package/dist/ParsingError.cjs.map +0 -1
  364. package/dist/ParsingError.js.map +0 -1
  365. package/dist/PrismicError.cjs.map +0 -1
  366. package/dist/PrismicError.js.map +0 -1
  367. package/dist/client.cjs +0 -414
  368. package/dist/client.cjs.map +0 -1
  369. package/dist/client.js +0 -414
  370. package/dist/client.js.map +0 -1
  371. package/dist/lib/appendPredicates.cjs +0 -14
  372. package/dist/lib/appendPredicates.cjs.map +0 -1
  373. package/dist/lib/appendPredicates.d.ts +0 -18
  374. package/dist/lib/appendPredicates.js +0 -14
  375. package/dist/lib/appendPredicates.js.map +0 -1
  376. package/dist/predicate.cjs +0 -68
  377. package/dist/predicate.cjs.map +0 -1
  378. package/dist/predicate.d.ts +0 -209
  379. package/dist/predicate.js +0 -68
  380. package/dist/predicate.js.map +0 -1
  381. package/dist/types/client.d.ts +0 -128
  382. package/dist/types/helpers.d.ts +0 -63
  383. package/dist/types/utils.d.ts +0 -28
  384. package/src/lib/appendPredicates.ts +0 -29
  385. package/src/predicate.ts +0 -359
  386. package/src/types/client.ts +0 -157
  387. package/src/types/helpers.ts +0 -103
  388. package/src/types/utils.ts +0 -34
  389. /package/dist/{ForbiddenError.js → errors/ForbiddenError.js} +0 -0
  390. /package/dist/{NotFoundError.js → errors/NotFoundError.js} +0 -0
  391. /package/dist/{ParsingError.js → errors/ParsingError.js} +0 -0
  392. /package/dist/{PrismicError.js → errors/PrismicError.js} +0 -0
  393. /package/src/{ForbiddenError.ts → errors/ForbiddenError.ts} +0 -0
  394. /package/src/{NotFoundError.ts → errors/NotFoundError.ts} +0 -0
  395. /package/src/{ParsingError.ts → errors/ParsingError.ts} +0 -0
  396. /package/src/{PrismicError.ts → errors/PrismicError.ts} +0 -0
@@ -0,0 +1,1142 @@
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
+ const appendFilters = require("./lib/appendFilters.cjs");
10
+ const castThunk = require("./lib/castThunk.cjs");
11
+ const everyTagFilter = require("./lib/everyTagFilter.cjs");
12
+ const findMasterRef = require("./lib/findMasterRef.cjs");
13
+ const findRefByID = require("./lib/findRefByID.cjs");
14
+ const findRefByLabel = require("./lib/findRefByLabel.cjs");
15
+ const getPreviewCookie = require("./lib/getPreviewCookie.cjs");
16
+ const minifyGraphQLQuery = require("./lib/minifyGraphQLQuery.cjs");
17
+ const someTagsFilter = require("./lib/someTagsFilter.cjs");
18
+ const typeFilter = require("./lib/typeFilter.cjs");
19
+ const ForbiddenError = require("./errors/ForbiddenError.cjs");
20
+ const NotFoundError = require("./errors/NotFoundError.cjs");
21
+ const ParsingError = require("./errors/ParsingError.cjs");
22
+ const PrismicError = require("./errors/PrismicError.cjs");
23
+ const asLink = require("./helpers/asLink.cjs");
24
+ const buildQueryURL = require("./buildQueryURL.cjs");
25
+ const filter = require("./filter.cjs");
26
+ const getRepositoryEndpoint = require("./getRepositoryEndpoint.cjs");
27
+ const isRepositoryEndpoint = require("./isRepositoryEndpoint.cjs");
28
+ const MAX_PAGE_SIZE = 100;
29
+ const REPOSITORY_CACHE_TTL = 5e3;
30
+ const GET_ALL_QUERY_DELAY = 500;
31
+ var RefStateMode;
32
+ (function(RefStateMode2) {
33
+ RefStateMode2["Master"] = "Master";
34
+ RefStateMode2["ReleaseID"] = "ReleaseID";
35
+ RefStateMode2["ReleaseLabel"] = "ReleaseLabel";
36
+ RefStateMode2["Manual"] = "Manual";
37
+ })(RefStateMode || (RefStateMode = {}));
38
+ const createClient = (repositoryNameOrEndpoint, options) => new Client(repositoryNameOrEndpoint, options);
39
+ class Client {
40
+ /**
41
+ * Creates a Prismic client that can be used to query a repository.
42
+ *
43
+ * If used in an environment where a global `fetch` function is unavailable,
44
+ * such as Node.js, the `fetch` option must be provided as part of the
45
+ * `options` parameter.
46
+ *
47
+ * @param repositoryNameOrEndpoint - The Prismic repository name or full Rest
48
+ * API V2 endpoint for the repository.
49
+ * @param options - Configuration that determines how content will be queried
50
+ * from the Prismic repository.
51
+ *
52
+ * @returns A client that can query content from the repository.
53
+ */
54
+ constructor(repositoryNameOrEndpoint, options = {}) {
55
+ /**
56
+ * The Prismic REST API V2 endpoint for the repository (use
57
+ * `prismic.getRepositoryEndpoint` for the default endpoint).
58
+ */
59
+ __publicField(this, "endpoint");
60
+ /**
61
+ * The secure token for accessing the API (only needed if your repository is
62
+ * set to private).
63
+ *
64
+ * {@link https://user-guides.prismic.io/en/articles/1036153-generating-an-access-token}
65
+ */
66
+ __publicField(this, "accessToken");
67
+ /**
68
+ * A list of Route Resolver objects that define how a document's `url` field
69
+ * is resolved.
70
+ *
71
+ * {@link https://prismic.io/docs/route-resolver}
72
+ */
73
+ __publicField(this, "routes");
74
+ /**
75
+ * The `brokenRoute` option allows you to define the route populated in the
76
+ * `url` property for broken Link or Content Relationship fields. A broken
77
+ * link is a Link or Content Relationship field whose linked document has been
78
+ * unpublished or deleted.
79
+ *
80
+ * {@link https://prismic.io/docs/route-resolver}
81
+ */
82
+ __publicField(this, "brokenRoute");
83
+ /**
84
+ * The function used to make network requests to the Prismic REST API. In
85
+ * environments where a global `fetch` function does not exist, such as
86
+ * Node.js, this function must be provided.
87
+ */
88
+ __publicField(this, "fetchFn");
89
+ /**
90
+ * Default parameters that will be sent with each query. These parameters can
91
+ * be overridden on each query if needed.
92
+ */
93
+ __publicField(this, "defaultParams");
94
+ /**
95
+ * The client's ref mode state. This determines which ref is used during
96
+ * queries.
97
+ */
98
+ __publicField(this, "refState", {
99
+ mode: RefStateMode.Master,
100
+ autoPreviewsEnabled: true
101
+ });
102
+ /**
103
+ * Cached repository value.
104
+ */
105
+ __publicField(this, "cachedRepository");
106
+ /**
107
+ * Timestamp at which the cached repository data is considered stale.
108
+ */
109
+ __publicField(this, "cachedRepositoryExpiration", 0);
110
+ /**
111
+ * Active `fetch()` jobs keyed by URL and AbortSignal (if it exists).
112
+ */
113
+ __publicField(this, "fetchJobs", {});
114
+ if (isRepositoryEndpoint.isRepositoryEndpoint(repositoryNameOrEndpoint)) {
115
+ if (process.env.NODE_ENV === "development" && /\.prismic\.io\/(?!api\/v2\/?)/.test(repositoryNameOrEndpoint)) {
116
+ throw new PrismicError.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);
117
+ }
118
+ this.endpoint = repositoryNameOrEndpoint;
119
+ } else {
120
+ this.endpoint = getRepositoryEndpoint.getRepositoryEndpoint(repositoryNameOrEndpoint);
121
+ }
122
+ this.accessToken = options.accessToken;
123
+ this.routes = options.routes;
124
+ this.brokenRoute = options.brokenRoute;
125
+ this.defaultParams = options.defaultParams;
126
+ if (options.ref) {
127
+ this.queryContentFromRef(options.ref);
128
+ }
129
+ if (typeof options.fetch === "function") {
130
+ this.fetchFn = options.fetch;
131
+ } else if (typeof globalThis.fetch === "function") {
132
+ this.fetchFn = globalThis.fetch;
133
+ } else {
134
+ throw new PrismicError.PrismicError("A valid fetch implementation was not provided. In environments where fetch is not available (including Node.js), a fetch implementation must be provided via a polyfill or the `fetch` option.", void 0, void 0);
135
+ }
136
+ if (this.fetchFn === globalThis.fetch) {
137
+ this.fetchFn = this.fetchFn.bind(globalThis);
138
+ }
139
+ this.graphQLFetch = this.graphQLFetch.bind(this);
140
+ }
141
+ /**
142
+ * Enables the client to automatically query content from a preview session if
143
+ * one is active in browser environments. This is enabled by default in the
144
+ * browser.
145
+ *
146
+ * For server environments, use `enableAutoPreviewsFromReq`.
147
+ *
148
+ * @example
149
+ *
150
+ * ```ts
151
+ * client.enableAutoPreviews();
152
+ * ```
153
+ *
154
+ * @see enableAutoPreviewsFromReq
155
+ */
156
+ enableAutoPreviews() {
157
+ this.refState.autoPreviewsEnabled = true;
158
+ }
159
+ /**
160
+ * Enables the client to automatically query content from a preview session if
161
+ * one is active in server environments. This is disabled by default on the
162
+ * server.
163
+ *
164
+ * For browser environments, use `enableAutoPreviews`.
165
+ *
166
+ * @example
167
+ *
168
+ * ```ts
169
+ * // In an express app
170
+ * app.get("/", function (req, res) {
171
+ * client.enableAutoPreviewsFromReq(req);
172
+ * });
173
+ * ```
174
+ *
175
+ * @param req - An HTTP server request object containing the request's
176
+ * cookies.
177
+ */
178
+ enableAutoPreviewsFromReq(req) {
179
+ this.refState.httpRequest = req;
180
+ this.refState.autoPreviewsEnabled = true;
181
+ }
182
+ /**
183
+ * Disables the client from automatically querying content from a preview
184
+ * session if one is active.
185
+ *
186
+ * Automatic preview content querying is enabled by default unless this method
187
+ * is called.
188
+ *
189
+ * @example
190
+ *
191
+ * ```ts
192
+ * client.disableAutoPreviews();
193
+ * ```
194
+ */
195
+ disableAutoPreviews() {
196
+ this.refState.autoPreviewsEnabled = false;
197
+ }
198
+ /**
199
+ * Queries content from the Prismic repository.
200
+ *
201
+ * @example
202
+ *
203
+ * ```ts
204
+ * const response = await client.get();
205
+ * ```
206
+ *
207
+ * @typeParam TDocument - Type of Prismic documents returned.
208
+ * @param params - Parameters to filter, sort, and paginate results.
209
+ *
210
+ * @returns A paginated response containing the result of the query.
211
+ */
212
+ async get(params) {
213
+ const url = await this.buildQueryURL(params);
214
+ return await this.fetch(url, params);
215
+ }
216
+ /**
217
+ * Queries content from the Prismic repository and returns only the first
218
+ * result, if any.
219
+ *
220
+ * @example
221
+ *
222
+ * ```ts
223
+ * const document = await client.getFirst();
224
+ * ```
225
+ *
226
+ * @typeParam TDocument - Type of the Prismic document returned.
227
+ * @param params - Parameters to filter, sort, and paginate results. @returns
228
+ * The first result of the query, if any.
229
+ */
230
+ async getFirst(params) {
231
+ var _a, _b;
232
+ const actualParams = { ...params };
233
+ if (!(params && params.page) && !(params == null ? void 0 : params.pageSize)) {
234
+ actualParams.pageSize = ((_a = this.defaultParams) == null ? void 0 : _a.pageSize) == null ? 1 : (_b = this.defaultParams) == null ? void 0 : _b.pageSize;
235
+ }
236
+ const url = await this.buildQueryURL(actualParams);
237
+ const result = await this.fetch(url, params);
238
+ const firstResult = result.results[0];
239
+ if (firstResult) {
240
+ return firstResult;
241
+ }
242
+ throw new PrismicError.PrismicError("No documents were returned", url, void 0);
243
+ }
244
+ /**
245
+ * **IMPORTANT**: Avoid using `dangerouslyGetAll` as it may be slower and
246
+ * require more resources than other methods. Prefer using other methods that
247
+ * filter by filters such as `getAllByType`.
248
+ *
249
+ * Queries content from the Prismic repository and returns all matching
250
+ * content. If no filters are provided, all documents will be fetched.
251
+ *
252
+ * This method may make multiple network requests to query all matching
253
+ * content.
254
+ *
255
+ * @example
256
+ *
257
+ * ```ts
258
+ * const response = await client.dangerouslyGetAll();
259
+ * ```
260
+ *
261
+ * @typeParam TDocument - Type of Prismic documents returned.
262
+ * @param params - Parameters to filter, sort, and paginate results.
263
+ *
264
+ * @returns A list of documents matching the query.
265
+ */
266
+ async dangerouslyGetAll(params = {}) {
267
+ var _a;
268
+ const { limit = Infinity, ...actualParams } = params;
269
+ const resolvedParams = {
270
+ ...actualParams,
271
+ pageSize: Math.min(limit, actualParams.pageSize || ((_a = this.defaultParams) == null ? void 0 : _a.pageSize) || MAX_PAGE_SIZE)
272
+ };
273
+ const documents = [];
274
+ let latestResult;
275
+ while ((!latestResult || latestResult.next_page) && documents.length < limit) {
276
+ const page = latestResult ? latestResult.page + 1 : void 0;
277
+ latestResult = await this.get({ ...resolvedParams, page });
278
+ documents.push(...latestResult.results);
279
+ if (latestResult.next_page) {
280
+ await new Promise((res) => setTimeout(res, GET_ALL_QUERY_DELAY));
281
+ }
282
+ }
283
+ return documents.slice(0, limit);
284
+ }
285
+ /**
286
+ * Queries a document from the Prismic repository with a specific ID.
287
+ *
288
+ * @remarks
289
+ * A document's UID is different from its ID. An ID is automatically generated
290
+ * for all documents and is made available on its `id` property. A UID is
291
+ * provided in the Prismic editor and is unique among all documents of its
292
+ * Custom Type.
293
+ * @example
294
+ *
295
+ * ```ts
296
+ * const document = await client.getByID("WW4bKScAAMAqmluX");
297
+ * ```
298
+ *
299
+ * @typeParam TDocument- Type of the Prismic document returned.
300
+ * @param id - ID of the document.
301
+ * @param params - Parameters to filter, sort, and paginate the results.
302
+ *
303
+ * @returns The document with an ID matching the `id` parameter, if a matching
304
+ * document exists.
305
+ */
306
+ async getByID(id, params) {
307
+ return await this.getFirst(appendFilters.appendFilters(params, filter.filter.at("document.id", id)));
308
+ }
309
+ /**
310
+ * Queries documents from the Prismic repository with specific IDs.
311
+ *
312
+ * @remarks
313
+ * A document's UID is different from its ID. An ID is automatically generated
314
+ * for all documents and is made available on its `id` property. A UID is
315
+ * provided in the Prismic editor and is unique among all documents of its
316
+ * Custom Type.
317
+ * @example
318
+ *
319
+ * ```ts
320
+ * const response = await client.getByIDs([
321
+ * "WW4bKScAAMAqmluX",
322
+ * "U1kTRgEAAC8A5ldS",
323
+ * ]);
324
+ * ```
325
+ *
326
+ * @typeParam TDocument - Type of Prismic documents returned.
327
+ * @param ids - A list of document IDs.
328
+ * @param params - Parameters to filter, sort, and paginate the results.
329
+ *
330
+ * @returns A paginated response containing documents with IDs matching the
331
+ * `ids` parameter.
332
+ */
333
+ async getByIDs(ids, params) {
334
+ return await this.get(appendFilters.appendFilters(params, filter.filter.in("document.id", ids)));
335
+ }
336
+ /**
337
+ * Queries all documents from the Prismic repository with specific IDs.
338
+ *
339
+ * This method may make multiple network requests to query all matching
340
+ * content.
341
+ *
342
+ * @remarks
343
+ * A document's UID is different from its ID. An ID is automatically generated
344
+ * for all documents and is made available on its `id` property. A UID is
345
+ * provided in the Prismic editor and is unique among all documents of its
346
+ * Custom Type.
347
+ * @example
348
+ *
349
+ * ```ts
350
+ * const response = await client.getAllByIDs([
351
+ * "WW4bKScAAMAqmluX",
352
+ * "U1kTRgEAAC8A5ldS",
353
+ * ]);
354
+ * ```
355
+ *
356
+ * @typeParam TDocument - Type of Prismic documents returned.
357
+ * @param ids - A list of document IDs.
358
+ * @param params - Parameters to filter, sort, and paginate the results.
359
+ *
360
+ * @returns A list of documents with IDs matching the `ids` parameter.
361
+ */
362
+ async getAllByIDs(ids, params) {
363
+ return await this.dangerouslyGetAll(appendFilters.appendFilters(params, filter.filter.in("document.id", ids)));
364
+ }
365
+ /**
366
+ * Queries a document from the Prismic repository with a specific UID and
367
+ * Custom Type.
368
+ *
369
+ * @remarks
370
+ * A document's UID is different from its ID. An ID is automatically generated
371
+ * for all documents and is made available on its `id` property. A UID is
372
+ * provided in the Prismic editor and is unique among all documents of its
373
+ * Custom Type.
374
+ * @example
375
+ *
376
+ * ```ts
377
+ * const document = await client.getByUID("blog_post", "my-first-post");
378
+ * ```
379
+ *
380
+ * @typeParam TDocument - Type of the Prismic document returned.
381
+ * @param documentType - The API ID of the document's Custom Type.
382
+ * @param uid - UID of the document.
383
+ * @param params - Parameters to filter, sort, and paginate the results.
384
+ *
385
+ * @returns The document with a UID matching the `uid` parameter, if a
386
+ * matching document exists.
387
+ */
388
+ async getByUID(documentType, uid, params) {
389
+ return await this.getFirst(appendFilters.appendFilters(params, [
390
+ typeFilter.typeFilter(documentType),
391
+ filter.filter.at(`my.${documentType}.uid`, uid)
392
+ ]));
393
+ }
394
+ /**
395
+ * Queries document from the Prismic repository with specific UIDs and Custom
396
+ * Type.
397
+ *
398
+ * @remarks
399
+ * A document's UID is different from its ID. An ID is automatically generated
400
+ * for all documents and is made available on its `id` property. A UID is
401
+ * provided in the Prismic editor and is unique among all documents of its
402
+ * Custom Type.
403
+ * @example
404
+ *
405
+ * ```ts
406
+ * const document = await client.getByUIDs("blog_post", [
407
+ * "my-first-post",
408
+ * "my-second-post",
409
+ * ]);
410
+ * ```
411
+ *
412
+ * @typeParam TDocument - Type of the Prismic document returned.
413
+ * @param documentType - The API ID of the document's Custom Type.
414
+ * @param uids - A list of document UIDs.
415
+ * @param params - Parameters to filter, sort, and paginate the results.
416
+ *
417
+ * @returns A paginated response containing documents with UIDs matching the
418
+ * `uids` parameter.
419
+ */
420
+ async getByUIDs(documentType, uids, params) {
421
+ return await this.get(appendFilters.appendFilters(params, [
422
+ typeFilter.typeFilter(documentType),
423
+ filter.filter.in(`my.${documentType}.uid`, uids)
424
+ ]));
425
+ }
426
+ /**
427
+ * Queries all documents from the Prismic repository with specific UIDs and
428
+ * Custom Type.
429
+ *
430
+ * This method may make multiple network requests to query all matching
431
+ * content.
432
+ *
433
+ * @remarks
434
+ * A document's UID is different from its ID. An ID is automatically generated
435
+ * for all documents and is made available on its `id` property. A UID is
436
+ * provided in the Prismic editor and is unique among all documents of its
437
+ * Custom Type.
438
+ * @example
439
+ *
440
+ * ```ts
441
+ * const response = await client.getAllByUIDs([
442
+ * "my-first-post",
443
+ * "my-second-post",
444
+ * ]);
445
+ * ```
446
+ *
447
+ * @typeParam TDocument - Type of Prismic documents returned.
448
+ * @param documentType - The API ID of the document's Custom Type.
449
+ * @param uids - A list of document UIDs.
450
+ * @param params - Parameters to filter, sort, and paginate the results.
451
+ *
452
+ * @returns A list of documents with UIDs matching the `uids` parameter.
453
+ */
454
+ async getAllByUIDs(documentType, uids, params) {
455
+ return await this.dangerouslyGetAll(appendFilters.appendFilters(params, [
456
+ typeFilter.typeFilter(documentType),
457
+ filter.filter.in(`my.${documentType}.uid`, uids)
458
+ ]));
459
+ }
460
+ /**
461
+ * Queries a singleton document from the Prismic repository for a specific
462
+ * Custom Type.
463
+ *
464
+ * @remarks
465
+ * A singleton document is one that is configured in Prismic to only allow one
466
+ * instance. For example, a repository may be configured to contain just one
467
+ * Settings document. This is in contrast to a repeatable Custom Type which
468
+ * allows multiple instances of itself.
469
+ * @example
470
+ *
471
+ * ```ts
472
+ * const document = await client.getSingle("settings");
473
+ * ```
474
+ *
475
+ * @typeParam TDocument - Type of the Prismic document returned.
476
+ * @param documentType - The API ID of the singleton Custom Type.
477
+ * @param params - Parameters to filter, sort, and paginate the results.
478
+ *
479
+ * @returns The singleton document for the Custom Type, if a matching document
480
+ * exists.
481
+ */
482
+ async getSingle(documentType, params) {
483
+ return await this.getFirst(appendFilters.appendFilters(params, typeFilter.typeFilter(documentType)));
484
+ }
485
+ /**
486
+ * Queries documents from the Prismic repository for a specific Custom Type.
487
+ *
488
+ * Use `getAllByType` instead if you need to query all documents for a
489
+ * specific Custom Type.
490
+ *
491
+ * @example
492
+ *
493
+ * ```ts
494
+ * const response = await client.getByType("blog_post");
495
+ * ```
496
+ *
497
+ * @typeParam TDocument - Type of Prismic documents returned.
498
+ * @param documentType - The API ID of the Custom Type.
499
+ * @param params - Parameters to filter, sort, and paginate the results.
500
+ *
501
+ * @returns A paginated response containing documents of the Custom Type.
502
+ */
503
+ async getByType(documentType, params) {
504
+ return await this.get(appendFilters.appendFilters(params, typeFilter.typeFilter(documentType)));
505
+ }
506
+ /**
507
+ * Queries all documents from the Prismic repository for a specific Custom
508
+ * Type.
509
+ *
510
+ * This method may make multiple network requests to query all matching
511
+ * content.
512
+ *
513
+ * @example
514
+ *
515
+ * ```ts
516
+ * const response = await client.getByType("blog_post");
517
+ * ```
518
+ *
519
+ * @typeParam TDocument - Type of Prismic documents returned.
520
+ * @param documentType - The API ID of the Custom Type.
521
+ * @param params - Parameters to filter, sort, and paginate the results.
522
+ *
523
+ * @returns A list of all documents of the Custom Type.
524
+ */
525
+ async getAllByType(documentType, params) {
526
+ return await this.dangerouslyGetAll(appendFilters.appendFilters(params, typeFilter.typeFilter(documentType)));
527
+ }
528
+ /**
529
+ * Queries documents from the Prismic repository with a specific tag.
530
+ *
531
+ * Use `getAllByTag` instead if you need to query all documents with a
532
+ * specific tag.
533
+ *
534
+ * @example
535
+ *
536
+ * ```ts
537
+ * const response = await client.getByTag("food");
538
+ * ```
539
+ *
540
+ * @typeParam TDocument - Type of Prismic documents returned.
541
+ * @param tag - The tag that must be included on a document.
542
+ * @param params - Parameters to filter, sort, and paginate the results.
543
+ *
544
+ * @returns A paginated response containing documents with the tag.
545
+ */
546
+ async getByTag(tag, params) {
547
+ return await this.get(appendFilters.appendFilters(params, someTagsFilter.someTagsFilter(tag)));
548
+ }
549
+ /**
550
+ * Queries all documents from the Prismic repository with a specific tag.
551
+ *
552
+ * This method may make multiple network requests to query all matching
553
+ * content.
554
+ *
555
+ * @example
556
+ *
557
+ * ```ts
558
+ * const response = await client.getAllByTag("food");
559
+ * ```
560
+ *
561
+ * @typeParam TDocument - Type of Prismic documents returned.
562
+ * @param tag - The tag that must be included on a document.
563
+ * @param params - Parameters to filter, sort, and paginate the results.
564
+ *
565
+ * @returns A list of all documents with the tag.
566
+ */
567
+ async getAllByTag(tag, params) {
568
+ return await this.dangerouslyGetAll(appendFilters.appendFilters(params, someTagsFilter.someTagsFilter(tag)));
569
+ }
570
+ /**
571
+ * Queries documents from the Prismic repository with specific tags. A
572
+ * document must be tagged with all of the queried tags to be included.
573
+ *
574
+ * @example
575
+ *
576
+ * ```ts
577
+ * const response = await client.getByEveryTag(["food", "fruit"]);
578
+ * ```
579
+ *
580
+ * @typeParam TDocument - Type of Prismic documents returned.
581
+ * @param tags - A list of tags that must be included on a document.
582
+ * @param params - Parameters to filter, sort, and paginate the results.
583
+ *
584
+ * @returns A paginated response containing documents with the tags.
585
+ */
586
+ async getByEveryTag(tags, params) {
587
+ return await this.get(appendFilters.appendFilters(params, everyTagFilter.everyTagFilter(tags)));
588
+ }
589
+ /**
590
+ * Queries documents from the Prismic repository with specific tags. A
591
+ * document must be tagged with all of the queried tags to be included.
592
+ *
593
+ * This method may make multiple network requests to query all matching
594
+ * content.
595
+ *
596
+ * @example
597
+ *
598
+ * ```ts
599
+ * const response = await client.getAllByEveryTag(["food", "fruit"]);
600
+ * ```
601
+ *
602
+ * @typeParam TDocument - Type of Prismic documents returned.
603
+ * @param tags - A list of tags that must be included on a document.
604
+ * @param params - Parameters to filter, sort, and paginate the results.
605
+ *
606
+ * @returns A list of all documents with the tags.
607
+ */
608
+ async getAllByEveryTag(tags, params) {
609
+ return await this.dangerouslyGetAll(appendFilters.appendFilters(params, everyTagFilter.everyTagFilter(tags)));
610
+ }
611
+ /**
612
+ * Queries documents from the Prismic repository with specific tags. A
613
+ * document must be tagged with at least one of the queried tags to be
614
+ * included.
615
+ *
616
+ * @example
617
+ *
618
+ * ```ts
619
+ * const response = await client.getByEveryTag(["food", "fruit"]);
620
+ * ```
621
+ *
622
+ * @typeParam TDocument - Type of Prismic documents returned.
623
+ * @param tags - A list of tags that must be included on a document.
624
+ * @param params - Parameters to filter, sort, and paginate the results.
625
+ *
626
+ * @returns A paginated response containing documents with at least one of the
627
+ * tags.
628
+ */
629
+ async getBySomeTags(tags, params) {
630
+ return await this.get(appendFilters.appendFilters(params, someTagsFilter.someTagsFilter(tags)));
631
+ }
632
+ /**
633
+ * Queries documents from the Prismic repository with specific tags. A
634
+ * document must be tagged with at least one of the queried tags to be
635
+ * included.
636
+ *
637
+ * This method may make multiple network requests to query all matching
638
+ * content.
639
+ *
640
+ * @example
641
+ *
642
+ * ```ts
643
+ * const response = await client.getAllBySomeTags(["food", "fruit"]);
644
+ * ```
645
+ *
646
+ * @typeParam TDocument - Type of Prismic documents returned.
647
+ * @param tags - A list of tags that must be included on a document.
648
+ * @param params - Parameters to filter, sort, and paginate the results.
649
+ *
650
+ * @returns A list of all documents with at least one of the tags.
651
+ */
652
+ async getAllBySomeTags(tags, params) {
653
+ return await this.dangerouslyGetAll(appendFilters.appendFilters(params, someTagsFilter.someTagsFilter(tags)));
654
+ }
655
+ /**
656
+ * Returns metadata about the Prismic repository, such as its refs, releases,
657
+ * and custom types.
658
+ *
659
+ * @returns Repository metadata.
660
+ */
661
+ async getRepository(params) {
662
+ const url = new URL(this.endpoint);
663
+ if (this.accessToken) {
664
+ url.searchParams.set("access_token", this.accessToken);
665
+ }
666
+ return await this.fetch(url.toString(), params);
667
+ }
668
+ /**
669
+ * Returns a list of all refs for the Prismic repository.
670
+ *
671
+ * Refs are used to identify which version of the repository's content should
672
+ * be queried. All repositories will have at least one ref pointing to the
673
+ * latest published content called the "master ref".
674
+ *
675
+ * @returns A list of all refs for the Prismic repository.
676
+ */
677
+ async getRefs(params) {
678
+ const repository = await this.getRepository(params);
679
+ return repository.refs;
680
+ }
681
+ /**
682
+ * Returns a ref for the Prismic repository with a matching ID.
683
+ *
684
+ * @param id - ID of the ref.
685
+ *
686
+ * @returns The ref with a matching ID, if it exists.
687
+ */
688
+ async getRefByID(id, params) {
689
+ const refs = await this.getRefs(params);
690
+ return findRefByID.findRefByID(refs, id);
691
+ }
692
+ /**
693
+ * Returns a ref for the Prismic repository with a matching label.
694
+ *
695
+ * @param label - Label of the ref.
696
+ *
697
+ * @returns The ref with a matching label, if it exists.
698
+ */
699
+ async getRefByLabel(label, params) {
700
+ const refs = await this.getRefs(params);
701
+ return findRefByLabel.findRefByLabel(refs, label);
702
+ }
703
+ /**
704
+ * Returns the master ref for the Prismic repository. The master ref points to
705
+ * the repository's latest published content.
706
+ *
707
+ * @returns The repository's master ref.
708
+ */
709
+ async getMasterRef(params) {
710
+ const refs = await this.getRefs(params);
711
+ return findMasterRef.findMasterRef(refs);
712
+ }
713
+ /**
714
+ * Returns a list of all Releases for the Prismic repository. Releases are
715
+ * used to group content changes before publishing.
716
+ *
717
+ * @returns A list of all Releases for the Prismic repository.
718
+ */
719
+ async getReleases(params) {
720
+ const refs = await this.getRefs(params);
721
+ return refs.filter((ref) => !ref.isMasterRef);
722
+ }
723
+ /**
724
+ * Returns a Release for the Prismic repository with a matching ID.
725
+ *
726
+ * @param id - ID of the Release.
727
+ *
728
+ * @returns The Release with a matching ID, if it exists.
729
+ */
730
+ async getReleaseByID(id, params) {
731
+ const releases = await this.getReleases(params);
732
+ return findRefByID.findRefByID(releases, id);
733
+ }
734
+ /**
735
+ * Returns a Release for the Prismic repository with a matching label.
736
+ *
737
+ * @param label - Label of the ref.
738
+ *
739
+ * @returns The ref with a matching label, if it exists.
740
+ */
741
+ async getReleaseByLabel(label, params) {
742
+ const releases = await this.getReleases(params);
743
+ return findRefByLabel.findRefByLabel(releases, label);
744
+ }
745
+ /**
746
+ * Returns a list of all tags used in the Prismic repository.
747
+ *
748
+ * @returns A list of all tags used in the repository.
749
+ */
750
+ async getTags(params) {
751
+ try {
752
+ const tagsForm = await this.getCachedRepositoryForm("tags", params);
753
+ const url = new URL(tagsForm.action);
754
+ if (this.accessToken) {
755
+ url.searchParams.set("access_token", this.accessToken);
756
+ }
757
+ return await this.fetch(url.toString(), params);
758
+ } catch {
759
+ const repository = await this.getRepository(params);
760
+ return repository.tags;
761
+ }
762
+ }
763
+ /**
764
+ * Builds a URL used to query content from the Prismic repository.
765
+ *
766
+ * @param params - Parameters to filter, sort, and paginate the results.
767
+ *
768
+ * @returns A URL string that can be requested to query content.
769
+ */
770
+ async buildQueryURL({ signal, ...params } = {}) {
771
+ const ref = params.ref || await this.getResolvedRefString();
772
+ const integrationFieldsRef = params.integrationFieldsRef || (await this.getCachedRepository({ signal })).integrationFieldsRef || void 0;
773
+ return buildQueryURL.buildQueryURL(this.endpoint, {
774
+ ...this.defaultParams,
775
+ ...params,
776
+ ref,
777
+ integrationFieldsRef,
778
+ routes: params.routes || this.routes,
779
+ brokenRoute: params.brokenRoute || this.brokenRoute,
780
+ accessToken: params.accessToken || this.accessToken
781
+ });
782
+ }
783
+ /**
784
+ * Determines the URL for a previewed document during an active preview
785
+ * session. The result of this method should be used to redirect the user to
786
+ * the document's URL.
787
+ *
788
+ * @example
789
+ *
790
+ * ```ts
791
+ * const url = client.resolvePreviewURL({
792
+ * linkResolver: (document) => `/${document.uid}`
793
+ * defaultURL: '/'
794
+ * })
795
+ * ```
796
+ *
797
+ * @param args - Arguments to configure the URL resolving.
798
+ *
799
+ * @returns The URL for the previewed document during an active preview
800
+ * session. The user should be redirected to this URL.
801
+ */
802
+ async resolvePreviewURL(args) {
803
+ var _a, _b;
804
+ let documentID = args.documentID;
805
+ let previewToken = args.previewToken;
806
+ if (typeof globalThis.location !== "undefined") {
807
+ const searchParams = new URLSearchParams(globalThis.location.search);
808
+ documentID = documentID || searchParams.get("documentId");
809
+ previewToken = previewToken || searchParams.get("token");
810
+ } else if (this.refState.httpRequest) {
811
+ if ("query" in this.refState.httpRequest) {
812
+ documentID = documentID || ((_a = this.refState.httpRequest.query) == null ? void 0 : _a.documentId);
813
+ previewToken = previewToken || ((_b = this.refState.httpRequest.query) == null ? void 0 : _b.token);
814
+ } else if ("url" in this.refState.httpRequest && this.refState.httpRequest.url) {
815
+ const searchParams = new URL(this.refState.httpRequest.url).searchParams;
816
+ documentID = documentID || searchParams.get("documentId");
817
+ previewToken = previewToken || searchParams.get("token");
818
+ }
819
+ }
820
+ if (documentID != null && previewToken != null) {
821
+ const document = await this.getByID(documentID, {
822
+ signal: args.signal,
823
+ ref: previewToken,
824
+ lang: "*"
825
+ });
826
+ const url = asLink.asLink(document, args.linkResolver);
827
+ if (typeof url === "string") {
828
+ return url;
829
+ }
830
+ }
831
+ return args.defaultURL;
832
+ }
833
+ /**
834
+ * Configures the client to query the latest published content for all future
835
+ * queries.
836
+ *
837
+ * If the `ref` parameter is provided during a query, it takes priority for
838
+ * that query.
839
+ *
840
+ * @example
841
+ *
842
+ * ```ts
843
+ * await client.queryLatestContent();
844
+ * const document = await client.getByID("WW4bKScAAMAqmluX");
845
+ * ```
846
+ */
847
+ queryLatestContent() {
848
+ this.refState.mode = RefStateMode.Master;
849
+ }
850
+ /**
851
+ * Configures the client to query content from a specific Release identified
852
+ * by its ID for all future queries.
853
+ *
854
+ * If the `ref` parameter is provided during a query, it takes priority for
855
+ * that query.
856
+ *
857
+ * @example
858
+ *
859
+ * ```ts
860
+ * await client.queryContentFromReleaseByID("YLB7OBAAACMA7Cpa");
861
+ * const document = await client.getByID("WW4bKScAAMAqmluX");
862
+ * ```
863
+ *
864
+ * @param releaseID - The ID of the Release.
865
+ */
866
+ queryContentFromReleaseByID(releaseID) {
867
+ this.refState = {
868
+ ...this.refState,
869
+ mode: RefStateMode.ReleaseID,
870
+ releaseID
871
+ };
872
+ }
873
+ /**
874
+ * Configures the client to query content from a specific Release identified
875
+ * by its label for all future queries.
876
+ *
877
+ * If the `ref` parameter is provided during a query, it takes priority for
878
+ * that query.
879
+ *
880
+ * @example
881
+ *
882
+ * ```ts
883
+ * await client.queryContentFromReleaseByLabel("My Release");
884
+ * const document = await client.getByID("WW4bKScAAMAqmluX");
885
+ * ```
886
+ *
887
+ * @param releaseLabel - The label of the Release.
888
+ */
889
+ queryContentFromReleaseByLabel(releaseLabel) {
890
+ this.refState = {
891
+ ...this.refState,
892
+ mode: RefStateMode.ReleaseLabel,
893
+ releaseLabel
894
+ };
895
+ }
896
+ /**
897
+ * Configures the client to query content from a specific ref. The ref can be
898
+ * provided as a string or a function.
899
+ *
900
+ * If a function is provided, the ref is fetched lazily before each query. The
901
+ * function may also be asynchronous.
902
+ *
903
+ * @example
904
+ *
905
+ * ```ts
906
+ * await client.queryContentFromRef("my-ref");
907
+ * const document = await client.getByID("WW4bKScAAMAqmluX");
908
+ * ```
909
+ *
910
+ * @param ref - The ref or a function that returns the ref from which to query
911
+ * content.
912
+ */
913
+ queryContentFromRef(ref) {
914
+ this.refState = {
915
+ ...this.refState,
916
+ mode: RefStateMode.Manual,
917
+ ref
918
+ };
919
+ }
920
+ /**
921
+ * A `fetch()` function to be used with GraphQL clients configured for
922
+ * Prismic's GraphQL API. It automatically applies the necessary `prismic-ref`
923
+ * and Authorization headers. Queries will automatically be minified by
924
+ * removing whitespace where possible.
925
+ *
926
+ * @example
927
+ *
928
+ * ```ts
929
+ * const graphQLClient = new ApolloClient({
930
+ * link: new HttpLink({
931
+ * uri: prismic.getGraphQLEndpoint(repositoryName),
932
+ * // Provide `client.graphQLFetch` as the fetch implementation.
933
+ * fetch: client.graphQLFetch,
934
+ * // Using GET is required.
935
+ * useGETForQueries: true,
936
+ * }),
937
+ * cache: new InMemoryCache(),
938
+ * });
939
+ * ```
940
+ *
941
+ * @param input - The `fetch()` `input` parameter. Only strings are supported.
942
+ * @param init - The `fetch()` `init` parameter. Only plain objects are
943
+ * supported.
944
+ *
945
+ * @returns The `fetch()` Response for the request.
946
+ * @experimental
947
+ */
948
+ async graphQLFetch(input, init) {
949
+ const cachedRepository = await this.getCachedRepository();
950
+ const ref = await this.getResolvedRefString();
951
+ const unsanitizedHeaders = {
952
+ "Prismic-ref": ref,
953
+ Authorization: this.accessToken ? `Token ${this.accessToken}` : "",
954
+ // Asserting `init.headers` is a Record since popular GraphQL
955
+ // libraries pass this as a Record. Header objects as input
956
+ // are unsupported.
957
+ ...init ? init.headers : {}
958
+ };
959
+ if (cachedRepository.integrationFieldsRef) {
960
+ unsanitizedHeaders["Prismic-integration-field-ref"] = cachedRepository.integrationFieldsRef;
961
+ }
962
+ const headers = {};
963
+ for (const key in unsanitizedHeaders) {
964
+ if (unsanitizedHeaders[key]) {
965
+ headers[key.toLowerCase()] = unsanitizedHeaders[key];
966
+ }
967
+ }
968
+ const url = new URL(
969
+ // Asserting `input` is a string since popular GraphQL
970
+ // libraries pass this as a string. Request objects as
971
+ // input are unsupported.
972
+ input
973
+ );
974
+ url.searchParams.set("ref", ref);
975
+ const query = url.searchParams.get("query");
976
+ if (query) {
977
+ url.searchParams.set(
978
+ "query",
979
+ // Compress the GraphQL query (if it exists) by
980
+ // removing whitespace. This is done to
981
+ // optimize the query size and avoid
982
+ // hitting the upper limit of GET requests
983
+ // (2048 characters).
984
+ minifyGraphQLQuery.minifyGraphQLQuery(query)
985
+ );
986
+ }
987
+ return await this.fetchFn(url.toString(), {
988
+ ...init,
989
+ headers
990
+ });
991
+ }
992
+ /**
993
+ * Returns a cached version of `getRepository` with a TTL.
994
+ *
995
+ * @returns Cached repository metadata.
996
+ */
997
+ async getCachedRepository(params) {
998
+ if (!this.cachedRepository || Date.now() >= this.cachedRepositoryExpiration) {
999
+ this.cachedRepositoryExpiration = Date.now() + REPOSITORY_CACHE_TTL;
1000
+ this.cachedRepository = await this.getRepository(params);
1001
+ }
1002
+ return this.cachedRepository;
1003
+ }
1004
+ /**
1005
+ * Returns a cached Prismic repository form. Forms are used to determine API
1006
+ * endpoints for types of repository data.
1007
+ *
1008
+ * @param name - Name of the form.
1009
+ *
1010
+ * @returns The repository form.
1011
+ * @throws If a matching form cannot be found.
1012
+ */
1013
+ async getCachedRepositoryForm(name, params) {
1014
+ const cachedRepository = await this.getCachedRepository(params);
1015
+ const form = cachedRepository.forms[name];
1016
+ if (!form) {
1017
+ throw new PrismicError.PrismicError(`Form with name "${name}" could not be found`, void 0, void 0);
1018
+ }
1019
+ return form;
1020
+ }
1021
+ /**
1022
+ * Returns the ref needed to query based on the client's current state. This
1023
+ * method may make a network request to fetch a ref or resolve the user's ref
1024
+ * thunk.
1025
+ *
1026
+ * If auto previews are enabled, the preview ref takes priority if available.
1027
+ *
1028
+ * The following strategies are used depending on the client's state:
1029
+ *
1030
+ * - If the user called `queryLatestContent`: Use the repository's master ref.
1031
+ * The ref is cached for 5 seconds. After 5 seconds, a new master ref is
1032
+ * fetched.
1033
+ * - If the user called `queryContentFromReleaseByID`: Use the release's ref.
1034
+ * The ref is cached for 5 seconds. After 5 seconds, a new ref for the
1035
+ * release is fetched.
1036
+ * - If the user called `queryContentFromReleaseByLabel`: Use the release's ref.
1037
+ * The ref is cached for 5 seconds. After 5 seconds, a new ref for the
1038
+ * release is fetched.
1039
+ * - If the user called `queryContentFromRef`: Use the provided ref. Fall back
1040
+ * to the master ref if the ref is not a string.
1041
+ *
1042
+ * @returns The ref to use during a query.
1043
+ */
1044
+ async getResolvedRefString(params) {
1045
+ var _a, _b;
1046
+ if (this.refState.autoPreviewsEnabled) {
1047
+ let previewRef;
1048
+ let cookieJar;
1049
+ if ((_a = this.refState.httpRequest) == null ? void 0 : _a.headers) {
1050
+ if ("get" in this.refState.httpRequest.headers && typeof this.refState.httpRequest.headers.get === "function") {
1051
+ cookieJar = this.refState.httpRequest.headers.get("cookie");
1052
+ } else if ("cookie" in this.refState.httpRequest.headers) {
1053
+ cookieJar = this.refState.httpRequest.headers.cookie;
1054
+ }
1055
+ } else if ((_b = globalThis.document) == null ? void 0 : _b.cookie) {
1056
+ cookieJar = globalThis.document.cookie;
1057
+ }
1058
+ if (cookieJar) {
1059
+ previewRef = getPreviewCookie.getPreviewCookie(cookieJar);
1060
+ }
1061
+ if (previewRef) {
1062
+ return previewRef;
1063
+ }
1064
+ }
1065
+ const cachedRepository = await this.getCachedRepository(params);
1066
+ const refModeType = this.refState.mode;
1067
+ if (refModeType === RefStateMode.ReleaseID) {
1068
+ return findRefByID.findRefByID(cachedRepository.refs, this.refState.releaseID).ref;
1069
+ } else if (refModeType === RefStateMode.ReleaseLabel) {
1070
+ return findRefByLabel.findRefByLabel(cachedRepository.refs, this.refState.releaseLabel).ref;
1071
+ } else if (refModeType === RefStateMode.Manual) {
1072
+ const res = await castThunk.castThunk(this.refState.ref)();
1073
+ if (typeof res === "string") {
1074
+ return res;
1075
+ }
1076
+ }
1077
+ return findMasterRef.findMasterRef(cachedRepository.refs).ref;
1078
+ }
1079
+ /**
1080
+ * Performs a network request using the configured `fetch` function. It
1081
+ * assumes all successful responses will have a JSON content type. It also
1082
+ * normalizes unsuccessful network requests.
1083
+ *
1084
+ * @typeParam T - The JSON response.
1085
+ * @param url - URL to the resource to fetch.
1086
+ * @param params - Prismic REST API parameters for the network request.
1087
+ *
1088
+ * @returns The JSON response from the network request.
1089
+ */
1090
+ async fetch(url, params = {}) {
1091
+ let job;
1092
+ if (this.fetchJobs[url] && this.fetchJobs[url].has(params.signal)) {
1093
+ job = this.fetchJobs[url].get(params.signal);
1094
+ } else {
1095
+ this.fetchJobs[url] = this.fetchJobs[url] || /* @__PURE__ */ new Map();
1096
+ job = this.fetchFn(url, {
1097
+ signal: params.signal
1098
+ }).then(async (res2) => {
1099
+ let json = void 0;
1100
+ try {
1101
+ json = await res2.json();
1102
+ } catch {
1103
+ }
1104
+ return {
1105
+ status: res2.status,
1106
+ json
1107
+ };
1108
+ }).finally(() => {
1109
+ this.fetchJobs[url].delete(params.signal);
1110
+ if (this.fetchJobs[url].size === 0) {
1111
+ delete this.fetchJobs[url];
1112
+ }
1113
+ });
1114
+ this.fetchJobs[url].set(params.signal, job);
1115
+ }
1116
+ const res = await job;
1117
+ if (res.status !== 404 && res.json == null) {
1118
+ throw new PrismicError.PrismicError(void 0, url, res.json);
1119
+ }
1120
+ switch (res.status) {
1121
+ case 200: {
1122
+ return res.json;
1123
+ }
1124
+ case 400: {
1125
+ throw new ParsingError.ParsingError(res.json.message, url, res.json);
1126
+ }
1127
+ case 401:
1128
+ case 403: {
1129
+ throw new ForbiddenError.ForbiddenError("error" in res.json ? res.json.error : res.json.message, url, res.json);
1130
+ }
1131
+ case 404: {
1132
+ throw new NotFoundError.NotFoundError(`Prismic repository not found. Check that "${this.endpoint}" is pointing to the correct repository.`, url, void 0);
1133
+ }
1134
+ }
1135
+ throw new PrismicError.PrismicError(void 0, url, res.json);
1136
+ }
1137
+ }
1138
+ exports.Client = Client;
1139
+ exports.GET_ALL_QUERY_DELAY = GET_ALL_QUERY_DELAY;
1140
+ exports.REPOSITORY_CACHE_TTL = REPOSITORY_CACHE_TTL;
1141
+ exports.createClient = createClient;
1142
+ //# sourceMappingURL=createClient.cjs.map