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