@prismicio/client 6.1.1 → 6.2.0
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.
- package/README.md +1 -1
- package/dist/index.cjs +59 -44
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +61 -31
- package/dist/index.js +59 -44
- package/dist/index.js.map +1 -1
- package/package.json +14 -14
- package/src/buildQueryURL.ts +1 -3
- package/src/client.ts +117 -66
- package/src/lib/minifyGraphQLQuery.ts +13 -0
- package/src/types.ts +42 -0
package/dist/index.d.ts
CHANGED
|
@@ -23,13 +23,29 @@ declare const getGraphQLEndpoint: <RepositoryName extends string>(repositoryName
|
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* A universal API to make network requests. A subset of the `fetch()` API.
|
|
26
|
+
*
|
|
27
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/API/fetch}
|
|
26
28
|
*/
|
|
27
29
|
declare type FetchLike = (input: string, init?: RequestInitLike) => Promise<ResponseLike>;
|
|
30
|
+
/**
|
|
31
|
+
* An object that allows you to abort a `fetch()` request if needed via an
|
|
32
|
+
* `AbortController` object
|
|
33
|
+
*
|
|
34
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal}
|
|
35
|
+
*/
|
|
36
|
+
declare type AbortSignalLike = {
|
|
37
|
+
aborted: any;
|
|
38
|
+
addEventListener: any;
|
|
39
|
+
removeEventListener: any;
|
|
40
|
+
dispatchEvent: any;
|
|
41
|
+
onabort: any;
|
|
42
|
+
};
|
|
28
43
|
/**
|
|
29
44
|
* The minimum required properties from RequestInit.
|
|
30
45
|
*/
|
|
31
46
|
interface RequestInitLike {
|
|
32
47
|
headers?: Record<string, string>;
|
|
48
|
+
signal?: AbortSignalLike | null;
|
|
33
49
|
}
|
|
34
50
|
/**
|
|
35
51
|
* The minimum required properties from Response.
|
|
@@ -234,6 +250,19 @@ declare type ClientConfig = {
|
|
|
234
250
|
*/
|
|
235
251
|
fetch?: FetchLike;
|
|
236
252
|
};
|
|
253
|
+
/**
|
|
254
|
+
* Parameters for any client method that use `fetch()`. Only a subset of
|
|
255
|
+
* `fetch()` parameters are exposed.
|
|
256
|
+
*/
|
|
257
|
+
declare type FetchParams = {
|
|
258
|
+
/**
|
|
259
|
+
* An `AbortSignal` provided by an `AbortController`. This allows the network
|
|
260
|
+
* request to be cancelled if necessary.
|
|
261
|
+
*
|
|
262
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal}
|
|
263
|
+
*/
|
|
264
|
+
signal?: AbortSignalLike;
|
|
265
|
+
};
|
|
237
266
|
/**
|
|
238
267
|
* Parameters specific to client methods that fetch all documents. These methods
|
|
239
268
|
* start with `getAll` (for example, `getAllByType`).
|
|
@@ -407,7 +436,7 @@ declare class Client {
|
|
|
407
436
|
*
|
|
408
437
|
* @returns A paginated response containing the result of the query.
|
|
409
438
|
*/
|
|
410
|
-
query<TDocument extends prismicT.PrismicDocument>(predicates: NonNullable<BuildQueryURLArgs["predicates"]>, params?: Partial<Omit<BuildQueryURLArgs, "predicates">>): Promise<prismicT.Query<TDocument>>;
|
|
439
|
+
query<TDocument extends prismicT.PrismicDocument>(predicates: NonNullable<BuildQueryURLArgs["predicates"]>, params?: Partial<Omit<BuildQueryURLArgs, "predicates">> & FetchParams): Promise<prismicT.Query<TDocument>>;
|
|
411
440
|
/**
|
|
412
441
|
* Queries content from the Prismic repository.
|
|
413
442
|
*
|
|
@@ -422,7 +451,7 @@ declare class Client {
|
|
|
422
451
|
*
|
|
423
452
|
* @returns A paginated response containing the result of the query.
|
|
424
453
|
*/
|
|
425
|
-
get<TDocument extends prismicT.PrismicDocument>(params?: Partial<BuildQueryURLArgs>): Promise<prismicT.Query<TDocument>>;
|
|
454
|
+
get<TDocument extends prismicT.PrismicDocument>(params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<prismicT.Query<TDocument>>;
|
|
426
455
|
/**
|
|
427
456
|
* Queries content from the Prismic repository and returns only the first
|
|
428
457
|
* result, if any.
|
|
@@ -437,7 +466,7 @@ declare class Client {
|
|
|
437
466
|
* @param params - Parameters to filter, sort, and paginate results. @returns
|
|
438
467
|
* The first result of the query, if any.
|
|
439
468
|
*/
|
|
440
|
-
getFirst<TDocument extends prismicT.PrismicDocument>(params?: Partial<BuildQueryURLArgs>): Promise<TDocument>;
|
|
469
|
+
getFirst<TDocument extends prismicT.PrismicDocument>(params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<TDocument>;
|
|
441
470
|
/**
|
|
442
471
|
* **IMPORTANT**: Avoid using `dangerouslyGetAll` as it may be slower and
|
|
443
472
|
* require more resources than other methods. Prefer using other methods that
|
|
@@ -459,7 +488,7 @@ declare class Client {
|
|
|
459
488
|
*
|
|
460
489
|
* @returns A list of documents matching the query.
|
|
461
490
|
*/
|
|
462
|
-
dangerouslyGetAll<TDocument extends prismicT.PrismicDocument>(params?: Partial<Omit<BuildQueryURLArgs, "page">> & GetAllParams): Promise<TDocument[]>;
|
|
491
|
+
dangerouslyGetAll<TDocument extends prismicT.PrismicDocument>(params?: Partial<Omit<BuildQueryURLArgs, "page">> & GetAllParams & FetchParams): Promise<TDocument[]>;
|
|
463
492
|
/**
|
|
464
493
|
* Queries a document from the Prismic repository with a specific ID.
|
|
465
494
|
*
|
|
@@ -480,7 +509,7 @@ declare class Client {
|
|
|
480
509
|
* @returns The document with an ID matching the `id` parameter, if a matching
|
|
481
510
|
* document exists.
|
|
482
511
|
*/
|
|
483
|
-
getByID<TDocument extends prismicT.PrismicDocument>(id: string, params?: Partial<BuildQueryURLArgs>): Promise<TDocument>;
|
|
512
|
+
getByID<TDocument extends prismicT.PrismicDocument>(id: string, params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<TDocument>;
|
|
484
513
|
/**
|
|
485
514
|
* Queries documents from the Prismic repository with specific IDs.
|
|
486
515
|
*
|
|
@@ -504,7 +533,7 @@ declare class Client {
|
|
|
504
533
|
* @returns A paginated response containing documents with IDs matching the
|
|
505
534
|
* `ids` parameter.
|
|
506
535
|
*/
|
|
507
|
-
getByIDs<TDocument extends prismicT.PrismicDocument>(ids: string[], params?: Partial<BuildQueryURLArgs>): Promise<prismicT.Query<TDocument>>;
|
|
536
|
+
getByIDs<TDocument extends prismicT.PrismicDocument>(ids: string[], params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<prismicT.Query<TDocument>>;
|
|
508
537
|
/**
|
|
509
538
|
* Queries all documents from the Prismic repository with specific IDs.
|
|
510
539
|
*
|
|
@@ -529,7 +558,7 @@ declare class Client {
|
|
|
529
558
|
*
|
|
530
559
|
* @returns A list of documents with IDs matching the `ids` parameter.
|
|
531
560
|
*/
|
|
532
|
-
getAllByIDs<TDocument extends prismicT.PrismicDocument>(ids: string[], params?: Partial<BuildQueryURLArgs>): Promise<TDocument[]>;
|
|
561
|
+
getAllByIDs<TDocument extends prismicT.PrismicDocument>(ids: string[], params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<TDocument[]>;
|
|
533
562
|
/**
|
|
534
563
|
* Queries a document from the Prismic repository with a specific UID and Custom Type.
|
|
535
564
|
*
|
|
@@ -551,7 +580,7 @@ declare class Client {
|
|
|
551
580
|
* @returns The document with a UID matching the `uid` parameter, if a
|
|
552
581
|
* matching document exists.
|
|
553
582
|
*/
|
|
554
|
-
getByUID<TDocument extends prismicT.PrismicDocument>(documentType: string, uid: string, params?: Partial<BuildQueryURLArgs>): Promise<TDocument>;
|
|
583
|
+
getByUID<TDocument extends prismicT.PrismicDocument>(documentType: string, uid: string, params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<TDocument>;
|
|
555
584
|
/**
|
|
556
585
|
* Queries document from the Prismic repository with specific UIDs and Custom Type.
|
|
557
586
|
*
|
|
@@ -576,7 +605,7 @@ declare class Client {
|
|
|
576
605
|
* @returns A paginated response containing documents with UIDs matching the
|
|
577
606
|
* `uids` parameter.
|
|
578
607
|
*/
|
|
579
|
-
getByUIDs<TDocument extends prismicT.PrismicDocument>(documentType: string, uids: string[], params?: Partial<BuildQueryURLArgs>): Promise<prismicT.Query<TDocument>>;
|
|
608
|
+
getByUIDs<TDocument extends prismicT.PrismicDocument>(documentType: string, uids: string[], params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<prismicT.Query<TDocument>>;
|
|
580
609
|
/**
|
|
581
610
|
* Queries all documents from the Prismic repository with specific UIDs and Custom Type.
|
|
582
611
|
*
|
|
@@ -602,7 +631,7 @@ declare class Client {
|
|
|
602
631
|
*
|
|
603
632
|
* @returns A list of documents with UIDs matching the `uids` parameter.
|
|
604
633
|
*/
|
|
605
|
-
getAllByUIDs<TDocument extends prismicT.PrismicDocument>(documentType: string, uids: string[], params?: Partial<BuildQueryURLArgs>): Promise<TDocument[]>;
|
|
634
|
+
getAllByUIDs<TDocument extends prismicT.PrismicDocument>(documentType: string, uids: string[], params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<TDocument[]>;
|
|
606
635
|
/**
|
|
607
636
|
* Queries a singleton document from the Prismic repository for a specific Custom Type.
|
|
608
637
|
*
|
|
@@ -623,7 +652,7 @@ declare class Client {
|
|
|
623
652
|
*
|
|
624
653
|
* @returns The singleton document for the Custom Type, if a matching document exists.
|
|
625
654
|
*/
|
|
626
|
-
getSingle<TDocument extends prismicT.PrismicDocument>(documentType: string, params?: Partial<BuildQueryURLArgs>): Promise<TDocument>;
|
|
655
|
+
getSingle<TDocument extends prismicT.PrismicDocument>(documentType: string, params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<TDocument>;
|
|
627
656
|
/**
|
|
628
657
|
* Queries documents from the Prismic repository for a specific Custom Type.
|
|
629
658
|
*
|
|
@@ -642,7 +671,7 @@ declare class Client {
|
|
|
642
671
|
*
|
|
643
672
|
* @returns A paginated response containing documents of the Custom Type.
|
|
644
673
|
*/
|
|
645
|
-
getByType<TDocument extends prismicT.PrismicDocument>(documentType: string, params?: Partial<BuildQueryURLArgs>): Promise<prismicT.Query<TDocument>>;
|
|
674
|
+
getByType<TDocument extends prismicT.PrismicDocument>(documentType: string, params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<prismicT.Query<TDocument>>;
|
|
646
675
|
/**
|
|
647
676
|
* Queries all documents from the Prismic repository for a specific Custom Type.
|
|
648
677
|
*
|
|
@@ -660,7 +689,7 @@ declare class Client {
|
|
|
660
689
|
*
|
|
661
690
|
* @returns A list of all documents of the Custom Type.
|
|
662
691
|
*/
|
|
663
|
-
getAllByType<TDocument extends prismicT.PrismicDocument>(documentType: string, params?: Partial<Omit<BuildQueryURLArgs, "page">>): Promise<TDocument[]>;
|
|
692
|
+
getAllByType<TDocument extends prismicT.PrismicDocument>(documentType: string, params?: Partial<Omit<BuildQueryURLArgs, "page">> & FetchParams): Promise<TDocument[]>;
|
|
664
693
|
/**
|
|
665
694
|
* Queries documents from the Prismic repository with a specific tag.
|
|
666
695
|
*
|
|
@@ -678,7 +707,7 @@ declare class Client {
|
|
|
678
707
|
*
|
|
679
708
|
* @returns A paginated response containing documents with the tag.
|
|
680
709
|
*/
|
|
681
|
-
getByTag<TDocument extends prismicT.PrismicDocument>(tag: string, params?: Partial<BuildQueryURLArgs>): Promise<prismicT.Query<TDocument>>;
|
|
710
|
+
getByTag<TDocument extends prismicT.PrismicDocument>(tag: string, params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<prismicT.Query<TDocument>>;
|
|
682
711
|
/**
|
|
683
712
|
* Queries all documents from the Prismic repository with a specific tag.
|
|
684
713
|
*
|
|
@@ -696,7 +725,7 @@ declare class Client {
|
|
|
696
725
|
*
|
|
697
726
|
* @returns A list of all documents with the tag.
|
|
698
727
|
*/
|
|
699
|
-
getAllByTag<TDocument extends prismicT.PrismicDocument>(tag: string, params?: Partial<Omit<BuildQueryURLArgs, "page">>): Promise<TDocument[]>;
|
|
728
|
+
getAllByTag<TDocument extends prismicT.PrismicDocument>(tag: string, params?: Partial<Omit<BuildQueryURLArgs, "page">> & FetchParams): Promise<TDocument[]>;
|
|
700
729
|
/**
|
|
701
730
|
* Queries documents from the Prismic repository with specific tags. A
|
|
702
731
|
* document must be tagged with all of the queried tags to be included.
|
|
@@ -713,7 +742,7 @@ declare class Client {
|
|
|
713
742
|
*
|
|
714
743
|
* @returns A paginated response containing documents with the tags.
|
|
715
744
|
*/
|
|
716
|
-
getByEveryTag<TDocument extends prismicT.PrismicDocument>(tags: string[], params?: Partial<BuildQueryURLArgs>): Promise<prismicT.Query<TDocument>>;
|
|
745
|
+
getByEveryTag<TDocument extends prismicT.PrismicDocument>(tags: string[], params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<prismicT.Query<TDocument>>;
|
|
717
746
|
/**
|
|
718
747
|
* Queries documents from the Prismic repository with specific tags. A
|
|
719
748
|
* document must be tagged with all of the queried tags to be included.
|
|
@@ -732,7 +761,7 @@ declare class Client {
|
|
|
732
761
|
*
|
|
733
762
|
* @returns A list of all documents with the tags.
|
|
734
763
|
*/
|
|
735
|
-
getAllByEveryTag<TDocument extends prismicT.PrismicDocument>(tags: string[], params?: Partial<Omit<BuildQueryURLArgs, "page">>): Promise<TDocument[]>;
|
|
764
|
+
getAllByEveryTag<TDocument extends prismicT.PrismicDocument>(tags: string[], params?: Partial<Omit<BuildQueryURLArgs, "page">> & FetchParams): Promise<TDocument[]>;
|
|
736
765
|
/**
|
|
737
766
|
* Queries documents from the Prismic repository with specific tags. A
|
|
738
767
|
* document must be tagged with at least one of the queried tags to be included.
|
|
@@ -749,7 +778,7 @@ declare class Client {
|
|
|
749
778
|
*
|
|
750
779
|
* @returns A paginated response containing documents with at least one of the tags.
|
|
751
780
|
*/
|
|
752
|
-
getBySomeTags<TDocument extends prismicT.PrismicDocument>(tags: string[], params?: Partial<BuildQueryURLArgs>): Promise<prismicT.Query<TDocument>>;
|
|
781
|
+
getBySomeTags<TDocument extends prismicT.PrismicDocument>(tags: string[], params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<prismicT.Query<TDocument>>;
|
|
753
782
|
/**
|
|
754
783
|
* Queries documents from the Prismic repository with specific tags. A
|
|
755
784
|
* document must be tagged with at least one of the queried tags to be included.
|
|
@@ -768,14 +797,14 @@ declare class Client {
|
|
|
768
797
|
*
|
|
769
798
|
* @returns A list of all documents with at least one of the tags.
|
|
770
799
|
*/
|
|
771
|
-
getAllBySomeTags<TDocument extends prismicT.PrismicDocument>(tags: string[], params?: Partial<Omit<BuildQueryURLArgs, "page">>): Promise<TDocument[]>;
|
|
800
|
+
getAllBySomeTags<TDocument extends prismicT.PrismicDocument>(tags: string[], params?: Partial<Omit<BuildQueryURLArgs, "page">> & FetchParams): Promise<TDocument[]>;
|
|
772
801
|
/**
|
|
773
802
|
* Returns metadata about the Prismic repository, such as its refs, releases,
|
|
774
803
|
* and custom types.
|
|
775
804
|
*
|
|
776
805
|
* @returns Repository metadata.
|
|
777
806
|
*/
|
|
778
|
-
getRepository(): Promise<prismicT.Repository>;
|
|
807
|
+
getRepository(params?: FetchParams): Promise<prismicT.Repository>;
|
|
779
808
|
/**
|
|
780
809
|
* Returns a list of all refs for the Prismic repository.
|
|
781
810
|
*
|
|
@@ -785,7 +814,7 @@ declare class Client {
|
|
|
785
814
|
*
|
|
786
815
|
* @returns A list of all refs for the Prismic repository.
|
|
787
816
|
*/
|
|
788
|
-
getRefs(): Promise<prismicT.Ref[]>;
|
|
817
|
+
getRefs(params?: FetchParams): Promise<prismicT.Ref[]>;
|
|
789
818
|
/**
|
|
790
819
|
* Returns a ref for the Prismic repository with a matching ID.
|
|
791
820
|
*
|
|
@@ -793,7 +822,7 @@ declare class Client {
|
|
|
793
822
|
*
|
|
794
823
|
* @returns The ref with a matching ID, if it exists.
|
|
795
824
|
*/
|
|
796
|
-
getRefByID(id: string): Promise<prismicT.Ref>;
|
|
825
|
+
getRefByID(id: string, params?: FetchParams): Promise<prismicT.Ref>;
|
|
797
826
|
/**
|
|
798
827
|
* Returns a ref for the Prismic repository with a matching label.
|
|
799
828
|
*
|
|
@@ -801,21 +830,21 @@ declare class Client {
|
|
|
801
830
|
*
|
|
802
831
|
* @returns The ref with a matching label, if it exists.
|
|
803
832
|
*/
|
|
804
|
-
getRefByLabel(label: string): Promise<prismicT.Ref>;
|
|
833
|
+
getRefByLabel(label: string, params?: FetchParams): Promise<prismicT.Ref>;
|
|
805
834
|
/**
|
|
806
835
|
* Returns the master ref for the Prismic repository. The master ref points to
|
|
807
836
|
* the repository's latest published content.
|
|
808
837
|
*
|
|
809
838
|
* @returns The repository's master ref.
|
|
810
839
|
*/
|
|
811
|
-
getMasterRef(): Promise<prismicT.Ref>;
|
|
840
|
+
getMasterRef(params?: FetchParams): Promise<prismicT.Ref>;
|
|
812
841
|
/**
|
|
813
842
|
* Returns a list of all Releases for the Prismic repository. Releases are
|
|
814
843
|
* used to group content changes before publishing.
|
|
815
844
|
*
|
|
816
845
|
* @returns A list of all Releases for the Prismic repository.
|
|
817
846
|
*/
|
|
818
|
-
getReleases(): Promise<prismicT.Ref[]>;
|
|
847
|
+
getReleases(params?: FetchParams): Promise<prismicT.Ref[]>;
|
|
819
848
|
/**
|
|
820
849
|
* Returns a Release for the Prismic repository with a matching ID.
|
|
821
850
|
*
|
|
@@ -823,7 +852,7 @@ declare class Client {
|
|
|
823
852
|
*
|
|
824
853
|
* @returns The Release with a matching ID, if it exists.
|
|
825
854
|
*/
|
|
826
|
-
getReleaseByID(id: string): Promise<prismicT.Ref>;
|
|
855
|
+
getReleaseByID(id: string, params?: FetchParams): Promise<prismicT.Ref>;
|
|
827
856
|
/**
|
|
828
857
|
* Returns a Release for the Prismic repository with a matching label.
|
|
829
858
|
*
|
|
@@ -831,13 +860,13 @@ declare class Client {
|
|
|
831
860
|
*
|
|
832
861
|
* @returns The ref with a matching label, if it exists.
|
|
833
862
|
*/
|
|
834
|
-
getReleaseByLabel(label: string): Promise<prismicT.Ref>;
|
|
863
|
+
getReleaseByLabel(label: string, params?: FetchParams): Promise<prismicT.Ref>;
|
|
835
864
|
/**
|
|
836
865
|
* Returns a list of all tags used in the Prismic repository.
|
|
837
866
|
*
|
|
838
867
|
* @returns A list of all tags used in the repository.
|
|
839
868
|
*/
|
|
840
|
-
getTags(): Promise<string[]>;
|
|
869
|
+
getTags(params?: FetchParams): Promise<string[]>;
|
|
841
870
|
/**
|
|
842
871
|
* Builds a URL used to query content from the Prismic repository.
|
|
843
872
|
*
|
|
@@ -845,7 +874,7 @@ declare class Client {
|
|
|
845
874
|
*
|
|
846
875
|
* @returns A URL string that can be requested to query content.
|
|
847
876
|
*/
|
|
848
|
-
buildQueryURL(params?: Partial<BuildQueryURLArgs>): Promise<string>;
|
|
877
|
+
buildQueryURL({ signal, ...params }?: Partial<BuildQueryURLArgs> & FetchParams): Promise<string>;
|
|
849
878
|
/**
|
|
850
879
|
* Determines the URL for a previewed document during an active preview
|
|
851
880
|
* session. The result of this method should be used to redirect the user to
|
|
@@ -865,7 +894,7 @@ declare class Client {
|
|
|
865
894
|
* @returns The URL for the previewed document during an active preview
|
|
866
895
|
* session. The user should be redirected to this URL.
|
|
867
896
|
*/
|
|
868
|
-
resolvePreviewURL(args: ResolvePreviewArgs): Promise<string>;
|
|
897
|
+
resolvePreviewURL(args: ResolvePreviewArgs & FetchParams): Promise<string>;
|
|
869
898
|
/**
|
|
870
899
|
* Configures the client to query the latest published content for all future queries.
|
|
871
900
|
*
|
|
@@ -931,7 +960,8 @@ declare class Client {
|
|
|
931
960
|
/**
|
|
932
961
|
* A `fetch()` function to be used with GraphQL clients configured for
|
|
933
962
|
* Prismic's GraphQL API. It automatically applies the necessary `prismic-ref`
|
|
934
|
-
* and Authorization headers.
|
|
963
|
+
* and Authorization headers. Queries will automatically be minified by
|
|
964
|
+
* removing whitespace where possible.
|
|
935
965
|
*
|
|
936
966
|
* @example
|
|
937
967
|
*
|
package/dist/index.js
CHANGED
|
@@ -100,9 +100,23 @@ const parse = (cookieString) => {
|
|
|
100
100
|
const getAll = (cookieStore) => parse(cookieStore);
|
|
101
101
|
const getCookie = (name, cookieStore) => getAll(cookieStore)[name];
|
|
102
102
|
|
|
103
|
+
const minifyGraphQLQuery = (query) => {
|
|
104
|
+
return query.replace(/(\n| )*( |{|})(\n| )*/gm, (_chars, _spaces, brackets) => brackets);
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const preview = "io.prismic.preview";
|
|
108
|
+
|
|
109
|
+
var cookie = /*#__PURE__*/Object.freeze({
|
|
110
|
+
__proto__: null,
|
|
111
|
+
preview: preview
|
|
112
|
+
});
|
|
113
|
+
|
|
103
114
|
class ForbiddenError extends PrismicError {
|
|
104
115
|
}
|
|
105
116
|
|
|
117
|
+
class NotFoundError extends PrismicError {
|
|
118
|
+
}
|
|
119
|
+
|
|
106
120
|
class ParsingError extends PrismicError {
|
|
107
121
|
}
|
|
108
122
|
|
|
@@ -171,22 +185,12 @@ const predicate = {
|
|
|
171
185
|
dateHourBefore: pathWithArgsPredicate("date.hour-before")
|
|
172
186
|
};
|
|
173
187
|
|
|
174
|
-
const preview = "io.prismic.preview";
|
|
175
|
-
|
|
176
|
-
var cookie = /*#__PURE__*/Object.freeze({
|
|
177
|
-
__proto__: null,
|
|
178
|
-
preview: preview
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
class NotFoundError extends PrismicError {
|
|
182
|
-
}
|
|
183
|
-
|
|
184
188
|
const MAX_PAGE_SIZE = 100;
|
|
185
189
|
const REPOSITORY_CACHE_TTL = 5e3;
|
|
186
190
|
const GET_ALL_QUERY_DELAY = 500;
|
|
187
191
|
const typePredicate = (documentType) => predicate.at("document.type", documentType);
|
|
188
|
-
const everyTagPredicate = (tags) => predicate.at("document.tags", tags);
|
|
189
|
-
const someTagsPredicate = (tags) => predicate.any("document.tags", tags);
|
|
192
|
+
const everyTagPredicate = (tags) => predicate.at("document.tags", castArray(tags));
|
|
193
|
+
const someTagsPredicate = (tags) => predicate.any("document.tags", castArray(tags));
|
|
190
194
|
const createClient = (...args) => new Client(...args);
|
|
191
195
|
class Client {
|
|
192
196
|
constructor(endpoint, options = {}) {
|
|
@@ -299,10 +303,10 @@ class Client {
|
|
|
299
303
|
return await this.dangerouslyGetAll(appendPredicates(params, typePredicate(documentType)));
|
|
300
304
|
}
|
|
301
305
|
async getByTag(tag, params) {
|
|
302
|
-
return await this.get(appendPredicates(params,
|
|
306
|
+
return await this.get(appendPredicates(params, someTagsPredicate(tag)));
|
|
303
307
|
}
|
|
304
308
|
async getAllByTag(tag, params) {
|
|
305
|
-
return await this.dangerouslyGetAll(appendPredicates(params,
|
|
309
|
+
return await this.dangerouslyGetAll(appendPredicates(params, someTagsPredicate(tag)));
|
|
306
310
|
}
|
|
307
311
|
async getByEveryTag(tags, params) {
|
|
308
312
|
return await this.get(appendPredicates(params, everyTagPredicate(tags)));
|
|
@@ -316,53 +320,56 @@ class Client {
|
|
|
316
320
|
async getAllBySomeTags(tags, params) {
|
|
317
321
|
return await this.dangerouslyGetAll(appendPredicates(params, someTagsPredicate(tags)));
|
|
318
322
|
}
|
|
319
|
-
async getRepository() {
|
|
323
|
+
async getRepository(params) {
|
|
320
324
|
const url = new URL(this.endpoint);
|
|
321
325
|
if (this.accessToken) {
|
|
322
326
|
url.searchParams.set("access_token", this.accessToken);
|
|
323
327
|
}
|
|
324
|
-
return await this.fetch(url.toString());
|
|
328
|
+
return await this.fetch(url.toString(), params);
|
|
325
329
|
}
|
|
326
|
-
async getRefs() {
|
|
327
|
-
const repository = await this.getRepository();
|
|
330
|
+
async getRefs(params) {
|
|
331
|
+
const repository = await this.getRepository(params);
|
|
328
332
|
return repository.refs;
|
|
329
333
|
}
|
|
330
|
-
async getRefByID(id) {
|
|
331
|
-
const refs = await this.getRefs();
|
|
334
|
+
async getRefByID(id, params) {
|
|
335
|
+
const refs = await this.getRefs(params);
|
|
332
336
|
return findRefByID(refs, id);
|
|
333
337
|
}
|
|
334
|
-
async getRefByLabel(label) {
|
|
335
|
-
const refs = await this.getRefs();
|
|
338
|
+
async getRefByLabel(label, params) {
|
|
339
|
+
const refs = await this.getRefs(params);
|
|
336
340
|
return findRefByLabel(refs, label);
|
|
337
341
|
}
|
|
338
|
-
async getMasterRef() {
|
|
339
|
-
const refs = await this.getRefs();
|
|
342
|
+
async getMasterRef(params) {
|
|
343
|
+
const refs = await this.getRefs(params);
|
|
340
344
|
return findMasterRef(refs);
|
|
341
345
|
}
|
|
342
|
-
async getReleases() {
|
|
343
|
-
const refs = await this.getRefs();
|
|
346
|
+
async getReleases(params) {
|
|
347
|
+
const refs = await this.getRefs(params);
|
|
344
348
|
return refs.filter((ref) => !ref.isMasterRef);
|
|
345
349
|
}
|
|
346
|
-
async getReleaseByID(id) {
|
|
347
|
-
const releases = await this.getReleases();
|
|
350
|
+
async getReleaseByID(id, params) {
|
|
351
|
+
const releases = await this.getReleases(params);
|
|
348
352
|
return findRefByID(releases, id);
|
|
349
353
|
}
|
|
350
|
-
async getReleaseByLabel(label) {
|
|
351
|
-
const releases = await this.getReleases();
|
|
354
|
+
async getReleaseByLabel(label, params) {
|
|
355
|
+
const releases = await this.getReleases(params);
|
|
352
356
|
return findRefByLabel(releases, label);
|
|
353
357
|
}
|
|
354
|
-
async getTags() {
|
|
358
|
+
async getTags(params) {
|
|
355
359
|
try {
|
|
356
|
-
const tagsForm = await this.getCachedRepositoryForm("tags");
|
|
360
|
+
const tagsForm = await this.getCachedRepositoryForm("tags", params);
|
|
357
361
|
return await this.fetch(tagsForm.action);
|
|
358
362
|
} catch (e) {
|
|
359
|
-
const repository = await this.getRepository();
|
|
363
|
+
const repository = await this.getRepository(params);
|
|
360
364
|
return repository.tags;
|
|
361
365
|
}
|
|
362
366
|
}
|
|
363
|
-
async buildQueryURL(
|
|
367
|
+
async buildQueryURL({
|
|
368
|
+
signal,
|
|
369
|
+
...params
|
|
370
|
+
} = {}) {
|
|
364
371
|
const ref = params.ref || await this.getResolvedRefString();
|
|
365
|
-
const integrationFieldsRef = params.integrationFieldsRef || (await this.getCachedRepository()).integrationFieldsRef || void 0;
|
|
372
|
+
const integrationFieldsRef = params.integrationFieldsRef || (await this.getCachedRepository({ signal })).integrationFieldsRef || void 0;
|
|
366
373
|
return buildQueryURL(this.endpoint, {
|
|
367
374
|
...this.defaultParams,
|
|
368
375
|
...params,
|
|
@@ -386,6 +393,7 @@ class Client {
|
|
|
386
393
|
}
|
|
387
394
|
if (documentID != null) {
|
|
388
395
|
const document = await this.getByID(documentID, {
|
|
396
|
+
signal: args.signal,
|
|
389
397
|
ref: previewToken,
|
|
390
398
|
lang: "*"
|
|
391
399
|
});
|
|
@@ -433,27 +441,32 @@ class Client {
|
|
|
433
441
|
headers[key.toLowerCase()] = unsanitizedHeaders[key];
|
|
434
442
|
}
|
|
435
443
|
}
|
|
436
|
-
|
|
444
|
+
const url = new URL(input);
|
|
445
|
+
const query = url.searchParams.get("query");
|
|
446
|
+
if (query) {
|
|
447
|
+
url.searchParams.set("query", minifyGraphQLQuery(query));
|
|
448
|
+
}
|
|
449
|
+
return await this.fetchFn(url.toString(), {
|
|
437
450
|
...init,
|
|
438
451
|
headers
|
|
439
452
|
});
|
|
440
453
|
}
|
|
441
|
-
async getCachedRepository() {
|
|
454
|
+
async getCachedRepository(params) {
|
|
442
455
|
if (!this.cachedRepository || Date.now() >= this.cachedRepositoryExpiration) {
|
|
443
456
|
this.cachedRepositoryExpiration = Date.now() + REPOSITORY_CACHE_TTL;
|
|
444
|
-
this.cachedRepository = await this.getRepository();
|
|
457
|
+
this.cachedRepository = await this.getRepository(params);
|
|
445
458
|
}
|
|
446
459
|
return this.cachedRepository;
|
|
447
460
|
}
|
|
448
|
-
async getCachedRepositoryForm(name) {
|
|
449
|
-
const cachedRepository = await this.getCachedRepository();
|
|
461
|
+
async getCachedRepositoryForm(name, params) {
|
|
462
|
+
const cachedRepository = await this.getCachedRepository(params);
|
|
450
463
|
const form = cachedRepository.forms[name];
|
|
451
464
|
if (!form) {
|
|
452
465
|
throw new PrismicError(`Form with name "${name}" could not be found`, void 0, void 0);
|
|
453
466
|
}
|
|
454
467
|
return form;
|
|
455
468
|
}
|
|
456
|
-
async getResolvedRefString() {
|
|
469
|
+
async getResolvedRefString(params) {
|
|
457
470
|
var _a, _b, _c;
|
|
458
471
|
if (this.refState.autoPreviewsEnabled) {
|
|
459
472
|
let previewRef = void 0;
|
|
@@ -466,7 +479,7 @@ class Client {
|
|
|
466
479
|
return previewRef;
|
|
467
480
|
}
|
|
468
481
|
}
|
|
469
|
-
const cachedRepository = await this.getCachedRepository();
|
|
482
|
+
const cachedRepository = await this.getCachedRepository(params);
|
|
470
483
|
const refModeType = this.refState.mode;
|
|
471
484
|
if (refModeType === "ReleaseID" /* ReleaseID */) {
|
|
472
485
|
return findRefByID(cachedRepository.refs, this.refState.releaseID).ref;
|
|
@@ -480,8 +493,10 @@ class Client {
|
|
|
480
493
|
}
|
|
481
494
|
return findMasterRef(cachedRepository.refs).ref;
|
|
482
495
|
}
|
|
483
|
-
async fetch(url,
|
|
484
|
-
const res = await this.fetchFn(url
|
|
496
|
+
async fetch(url, params = {}) {
|
|
497
|
+
const res = await this.fetchFn(url, {
|
|
498
|
+
signal: params.signal
|
|
499
|
+
});
|
|
485
500
|
let json;
|
|
486
501
|
try {
|
|
487
502
|
json = await res.json();
|