@prismicio/client 6.0.0-beta.5 → 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 +92 -59
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +98 -31
- package/dist/index.js +92 -60
- package/dist/index.js.map +1 -1
- package/package.json +20 -16
- package/src/buildQueryURL.ts +1 -3
- package/src/client.ts +177 -59
- package/src/getGraphQLEndpoint.ts +12 -0
- package/src/index.ts +1 -0
- package/src/lib/minifyGraphQLQuery.ts +13 -0
- package/src/types.ts +42 -0
package/dist/index.d.ts
CHANGED
|
@@ -11,15 +11,41 @@ import * as prismicH from '@prismicio/helpers';
|
|
|
11
11
|
*/
|
|
12
12
|
declare const getEndpoint: <RepositoryName extends string>(repositoryName: RepositoryName) => `https://${RepositoryName}.cdn.prismic.io/api/v2`;
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Get a repository's Prismic GraphQL endpoint.
|
|
16
|
+
*
|
|
17
|
+
* @typeParam RepositoryName - Name of the Prismic repository.
|
|
18
|
+
* @param repositoryName - Name of the repository.
|
|
19
|
+
*
|
|
20
|
+
* @returns The repository's Prismic REST API V2 endpoint
|
|
21
|
+
*/
|
|
22
|
+
declare const getGraphQLEndpoint: <RepositoryName extends string>(repositoryName: RepositoryName) => `https://${RepositoryName}.cdn.prismic.io/graphql`;
|
|
23
|
+
|
|
14
24
|
/**
|
|
15
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}
|
|
16
28
|
*/
|
|
17
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
|
+
};
|
|
18
43
|
/**
|
|
19
44
|
* The minimum required properties from RequestInit.
|
|
20
45
|
*/
|
|
21
46
|
interface RequestInitLike {
|
|
22
47
|
headers?: Record<string, string>;
|
|
48
|
+
signal?: AbortSignalLike | null;
|
|
23
49
|
}
|
|
24
50
|
/**
|
|
25
51
|
* The minimum required properties from Response.
|
|
@@ -224,6 +250,19 @@ declare type ClientConfig = {
|
|
|
224
250
|
*/
|
|
225
251
|
fetch?: FetchLike;
|
|
226
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
|
+
};
|
|
227
266
|
/**
|
|
228
267
|
* Parameters specific to client methods that fetch all documents. These methods
|
|
229
268
|
* start with `getAll` (for example, `getAllByType`).
|
|
@@ -397,7 +436,7 @@ declare class Client {
|
|
|
397
436
|
*
|
|
398
437
|
* @returns A paginated response containing the result of the query.
|
|
399
438
|
*/
|
|
400
|
-
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>>;
|
|
401
440
|
/**
|
|
402
441
|
* Queries content from the Prismic repository.
|
|
403
442
|
*
|
|
@@ -412,7 +451,7 @@ declare class Client {
|
|
|
412
451
|
*
|
|
413
452
|
* @returns A paginated response containing the result of the query.
|
|
414
453
|
*/
|
|
415
|
-
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>>;
|
|
416
455
|
/**
|
|
417
456
|
* Queries content from the Prismic repository and returns only the first
|
|
418
457
|
* result, if any.
|
|
@@ -427,7 +466,7 @@ declare class Client {
|
|
|
427
466
|
* @param params - Parameters to filter, sort, and paginate results. @returns
|
|
428
467
|
* The first result of the query, if any.
|
|
429
468
|
*/
|
|
430
|
-
getFirst<TDocument extends prismicT.PrismicDocument>(params?: Partial<BuildQueryURLArgs>): Promise<TDocument>;
|
|
469
|
+
getFirst<TDocument extends prismicT.PrismicDocument>(params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<TDocument>;
|
|
431
470
|
/**
|
|
432
471
|
* **IMPORTANT**: Avoid using `dangerouslyGetAll` as it may be slower and
|
|
433
472
|
* require more resources than other methods. Prefer using other methods that
|
|
@@ -449,7 +488,7 @@ declare class Client {
|
|
|
449
488
|
*
|
|
450
489
|
* @returns A list of documents matching the query.
|
|
451
490
|
*/
|
|
452
|
-
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[]>;
|
|
453
492
|
/**
|
|
454
493
|
* Queries a document from the Prismic repository with a specific ID.
|
|
455
494
|
*
|
|
@@ -470,7 +509,7 @@ declare class Client {
|
|
|
470
509
|
* @returns The document with an ID matching the `id` parameter, if a matching
|
|
471
510
|
* document exists.
|
|
472
511
|
*/
|
|
473
|
-
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>;
|
|
474
513
|
/**
|
|
475
514
|
* Queries documents from the Prismic repository with specific IDs.
|
|
476
515
|
*
|
|
@@ -494,7 +533,7 @@ declare class Client {
|
|
|
494
533
|
* @returns A paginated response containing documents with IDs matching the
|
|
495
534
|
* `ids` parameter.
|
|
496
535
|
*/
|
|
497
|
-
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>>;
|
|
498
537
|
/**
|
|
499
538
|
* Queries all documents from the Prismic repository with specific IDs.
|
|
500
539
|
*
|
|
@@ -519,7 +558,7 @@ declare class Client {
|
|
|
519
558
|
*
|
|
520
559
|
* @returns A list of documents with IDs matching the `ids` parameter.
|
|
521
560
|
*/
|
|
522
|
-
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[]>;
|
|
523
562
|
/**
|
|
524
563
|
* Queries a document from the Prismic repository with a specific UID and Custom Type.
|
|
525
564
|
*
|
|
@@ -541,7 +580,7 @@ declare class Client {
|
|
|
541
580
|
* @returns The document with a UID matching the `uid` parameter, if a
|
|
542
581
|
* matching document exists.
|
|
543
582
|
*/
|
|
544
|
-
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>;
|
|
545
584
|
/**
|
|
546
585
|
* Queries document from the Prismic repository with specific UIDs and Custom Type.
|
|
547
586
|
*
|
|
@@ -566,7 +605,7 @@ declare class Client {
|
|
|
566
605
|
* @returns A paginated response containing documents with UIDs matching the
|
|
567
606
|
* `uids` parameter.
|
|
568
607
|
*/
|
|
569
|
-
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>>;
|
|
570
609
|
/**
|
|
571
610
|
* Queries all documents from the Prismic repository with specific UIDs and Custom Type.
|
|
572
611
|
*
|
|
@@ -592,7 +631,7 @@ declare class Client {
|
|
|
592
631
|
*
|
|
593
632
|
* @returns A list of documents with UIDs matching the `uids` parameter.
|
|
594
633
|
*/
|
|
595
|
-
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[]>;
|
|
596
635
|
/**
|
|
597
636
|
* Queries a singleton document from the Prismic repository for a specific Custom Type.
|
|
598
637
|
*
|
|
@@ -613,7 +652,7 @@ declare class Client {
|
|
|
613
652
|
*
|
|
614
653
|
* @returns The singleton document for the Custom Type, if a matching document exists.
|
|
615
654
|
*/
|
|
616
|
-
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>;
|
|
617
656
|
/**
|
|
618
657
|
* Queries documents from the Prismic repository for a specific Custom Type.
|
|
619
658
|
*
|
|
@@ -632,7 +671,7 @@ declare class Client {
|
|
|
632
671
|
*
|
|
633
672
|
* @returns A paginated response containing documents of the Custom Type.
|
|
634
673
|
*/
|
|
635
|
-
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>>;
|
|
636
675
|
/**
|
|
637
676
|
* Queries all documents from the Prismic repository for a specific Custom Type.
|
|
638
677
|
*
|
|
@@ -650,7 +689,7 @@ declare class Client {
|
|
|
650
689
|
*
|
|
651
690
|
* @returns A list of all documents of the Custom Type.
|
|
652
691
|
*/
|
|
653
|
-
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[]>;
|
|
654
693
|
/**
|
|
655
694
|
* Queries documents from the Prismic repository with a specific tag.
|
|
656
695
|
*
|
|
@@ -668,7 +707,7 @@ declare class Client {
|
|
|
668
707
|
*
|
|
669
708
|
* @returns A paginated response containing documents with the tag.
|
|
670
709
|
*/
|
|
671
|
-
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>>;
|
|
672
711
|
/**
|
|
673
712
|
* Queries all documents from the Prismic repository with a specific tag.
|
|
674
713
|
*
|
|
@@ -686,7 +725,7 @@ declare class Client {
|
|
|
686
725
|
*
|
|
687
726
|
* @returns A list of all documents with the tag.
|
|
688
727
|
*/
|
|
689
|
-
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[]>;
|
|
690
729
|
/**
|
|
691
730
|
* Queries documents from the Prismic repository with specific tags. A
|
|
692
731
|
* document must be tagged with all of the queried tags to be included.
|
|
@@ -703,7 +742,7 @@ declare class Client {
|
|
|
703
742
|
*
|
|
704
743
|
* @returns A paginated response containing documents with the tags.
|
|
705
744
|
*/
|
|
706
|
-
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>>;
|
|
707
746
|
/**
|
|
708
747
|
* Queries documents from the Prismic repository with specific tags. A
|
|
709
748
|
* document must be tagged with all of the queried tags to be included.
|
|
@@ -722,7 +761,7 @@ declare class Client {
|
|
|
722
761
|
*
|
|
723
762
|
* @returns A list of all documents with the tags.
|
|
724
763
|
*/
|
|
725
|
-
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[]>;
|
|
726
765
|
/**
|
|
727
766
|
* Queries documents from the Prismic repository with specific tags. A
|
|
728
767
|
* document must be tagged with at least one of the queried tags to be included.
|
|
@@ -739,7 +778,7 @@ declare class Client {
|
|
|
739
778
|
*
|
|
740
779
|
* @returns A paginated response containing documents with at least one of the tags.
|
|
741
780
|
*/
|
|
742
|
-
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>>;
|
|
743
782
|
/**
|
|
744
783
|
* Queries documents from the Prismic repository with specific tags. A
|
|
745
784
|
* document must be tagged with at least one of the queried tags to be included.
|
|
@@ -758,14 +797,14 @@ declare class Client {
|
|
|
758
797
|
*
|
|
759
798
|
* @returns A list of all documents with at least one of the tags.
|
|
760
799
|
*/
|
|
761
|
-
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[]>;
|
|
762
801
|
/**
|
|
763
802
|
* Returns metadata about the Prismic repository, such as its refs, releases,
|
|
764
803
|
* and custom types.
|
|
765
804
|
*
|
|
766
805
|
* @returns Repository metadata.
|
|
767
806
|
*/
|
|
768
|
-
getRepository(): Promise<prismicT.Repository>;
|
|
807
|
+
getRepository(params?: FetchParams): Promise<prismicT.Repository>;
|
|
769
808
|
/**
|
|
770
809
|
* Returns a list of all refs for the Prismic repository.
|
|
771
810
|
*
|
|
@@ -775,7 +814,7 @@ declare class Client {
|
|
|
775
814
|
*
|
|
776
815
|
* @returns A list of all refs for the Prismic repository.
|
|
777
816
|
*/
|
|
778
|
-
getRefs(): Promise<prismicT.Ref[]>;
|
|
817
|
+
getRefs(params?: FetchParams): Promise<prismicT.Ref[]>;
|
|
779
818
|
/**
|
|
780
819
|
* Returns a ref for the Prismic repository with a matching ID.
|
|
781
820
|
*
|
|
@@ -783,7 +822,7 @@ declare class Client {
|
|
|
783
822
|
*
|
|
784
823
|
* @returns The ref with a matching ID, if it exists.
|
|
785
824
|
*/
|
|
786
|
-
getRefByID(id: string): Promise<prismicT.Ref>;
|
|
825
|
+
getRefByID(id: string, params?: FetchParams): Promise<prismicT.Ref>;
|
|
787
826
|
/**
|
|
788
827
|
* Returns a ref for the Prismic repository with a matching label.
|
|
789
828
|
*
|
|
@@ -791,21 +830,21 @@ declare class Client {
|
|
|
791
830
|
*
|
|
792
831
|
* @returns The ref with a matching label, if it exists.
|
|
793
832
|
*/
|
|
794
|
-
getRefByLabel(label: string): Promise<prismicT.Ref>;
|
|
833
|
+
getRefByLabel(label: string, params?: FetchParams): Promise<prismicT.Ref>;
|
|
795
834
|
/**
|
|
796
835
|
* Returns the master ref for the Prismic repository. The master ref points to
|
|
797
836
|
* the repository's latest published content.
|
|
798
837
|
*
|
|
799
838
|
* @returns The repository's master ref.
|
|
800
839
|
*/
|
|
801
|
-
getMasterRef(): Promise<prismicT.Ref>;
|
|
840
|
+
getMasterRef(params?: FetchParams): Promise<prismicT.Ref>;
|
|
802
841
|
/**
|
|
803
842
|
* Returns a list of all Releases for the Prismic repository. Releases are
|
|
804
843
|
* used to group content changes before publishing.
|
|
805
844
|
*
|
|
806
845
|
* @returns A list of all Releases for the Prismic repository.
|
|
807
846
|
*/
|
|
808
|
-
getReleases(): Promise<prismicT.Ref[]>;
|
|
847
|
+
getReleases(params?: FetchParams): Promise<prismicT.Ref[]>;
|
|
809
848
|
/**
|
|
810
849
|
* Returns a Release for the Prismic repository with a matching ID.
|
|
811
850
|
*
|
|
@@ -813,7 +852,7 @@ declare class Client {
|
|
|
813
852
|
*
|
|
814
853
|
* @returns The Release with a matching ID, if it exists.
|
|
815
854
|
*/
|
|
816
|
-
getReleaseByID(id: string): Promise<prismicT.Ref>;
|
|
855
|
+
getReleaseByID(id: string, params?: FetchParams): Promise<prismicT.Ref>;
|
|
817
856
|
/**
|
|
818
857
|
* Returns a Release for the Prismic repository with a matching label.
|
|
819
858
|
*
|
|
@@ -821,13 +860,13 @@ declare class Client {
|
|
|
821
860
|
*
|
|
822
861
|
* @returns The ref with a matching label, if it exists.
|
|
823
862
|
*/
|
|
824
|
-
getReleaseByLabel(label: string): Promise<prismicT.Ref>;
|
|
863
|
+
getReleaseByLabel(label: string, params?: FetchParams): Promise<prismicT.Ref>;
|
|
825
864
|
/**
|
|
826
865
|
* Returns a list of all tags used in the Prismic repository.
|
|
827
866
|
*
|
|
828
867
|
* @returns A list of all tags used in the repository.
|
|
829
868
|
*/
|
|
830
|
-
getTags(): Promise<string[]>;
|
|
869
|
+
getTags(params?: FetchParams): Promise<string[]>;
|
|
831
870
|
/**
|
|
832
871
|
* Builds a URL used to query content from the Prismic repository.
|
|
833
872
|
*
|
|
@@ -835,7 +874,7 @@ declare class Client {
|
|
|
835
874
|
*
|
|
836
875
|
* @returns A URL string that can be requested to query content.
|
|
837
876
|
*/
|
|
838
|
-
buildQueryURL(params?: Partial<BuildQueryURLArgs>): Promise<string>;
|
|
877
|
+
buildQueryURL({ signal, ...params }?: Partial<BuildQueryURLArgs> & FetchParams): Promise<string>;
|
|
839
878
|
/**
|
|
840
879
|
* Determines the URL for a previewed document during an active preview
|
|
841
880
|
* session. The result of this method should be used to redirect the user to
|
|
@@ -855,7 +894,7 @@ declare class Client {
|
|
|
855
894
|
* @returns The URL for the previewed document during an active preview
|
|
856
895
|
* session. The user should be redirected to this URL.
|
|
857
896
|
*/
|
|
858
|
-
resolvePreviewURL(args: ResolvePreviewArgs): Promise<string>;
|
|
897
|
+
resolvePreviewURL(args: ResolvePreviewArgs & FetchParams): Promise<string>;
|
|
859
898
|
/**
|
|
860
899
|
* Configures the client to query the latest published content for all future queries.
|
|
861
900
|
*
|
|
@@ -918,6 +957,34 @@ declare class Client {
|
|
|
918
957
|
* @param ref - The ref or a function that returns the ref from which to query content.
|
|
919
958
|
*/
|
|
920
959
|
queryContentFromRef(ref: RefStringOrThunk): void;
|
|
960
|
+
/**
|
|
961
|
+
* A `fetch()` function to be used with GraphQL clients configured for
|
|
962
|
+
* Prismic's GraphQL API. It automatically applies the necessary `prismic-ref`
|
|
963
|
+
* and Authorization headers. Queries will automatically be minified by
|
|
964
|
+
* removing whitespace where possible.
|
|
965
|
+
*
|
|
966
|
+
* @example
|
|
967
|
+
*
|
|
968
|
+
* ```ts
|
|
969
|
+
* const graphqlClient = new ApolloClient({
|
|
970
|
+
* link: new HttpLink({
|
|
971
|
+
* uri: prismic.getGraphQLEndpoint(repositoryName),
|
|
972
|
+
* // Provide `client.graphqlFetch` as the fetch implementation.
|
|
973
|
+
* fetch: client.graphqlFetch,
|
|
974
|
+
* // Using GET is required.
|
|
975
|
+
* useGETForQueries: true,
|
|
976
|
+
* }),
|
|
977
|
+
* cache: new InMemoryCache(),
|
|
978
|
+
* });
|
|
979
|
+
* ```
|
|
980
|
+
*
|
|
981
|
+
* @param input - The `fetch()` `input` parameter. Only strings are supported.
|
|
982
|
+
* @param init - The `fetch()` `init` parameter. Only plain objects are supported.
|
|
983
|
+
*
|
|
984
|
+
* @returns The `fetch()` Response for the request.
|
|
985
|
+
* @experimental
|
|
986
|
+
*/
|
|
987
|
+
graphqlFetch(input: RequestInfo, init?: RequestInit): Promise<Response>;
|
|
921
988
|
/**
|
|
922
989
|
* Returns a cached version of `getRepository` with a TTL.
|
|
923
990
|
*
|
|
@@ -1289,4 +1356,4 @@ declare const Predicates: {
|
|
|
1289
1356
|
dateHourBefore: (path: string, hour: number) => string;
|
|
1290
1357
|
};
|
|
1291
1358
|
|
|
1292
|
-
export { BuildQueryURLArgs, Client, ClientConfig, FetchLike, ForbiddenError, HttpRequestLike, NotFoundError, Ordering, ParsingError, Predicates, PrismicError, QueryParams, RequestInitLike, ResponseLike, Route, buildQueryURL, cookie, createClient, getEndpoint, predicate, predicates };
|
|
1359
|
+
export { BuildQueryURLArgs, Client, ClientConfig, FetchLike, ForbiddenError, HttpRequestLike, NotFoundError, Ordering, ParsingError, Predicates, PrismicError, QueryParams, RequestInitLike, ResponseLike, Route, buildQueryURL, cookie, createClient, getEndpoint, getGraphQLEndpoint, predicate, predicates };
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,8 @@ import * as prismicH from '@prismicio/helpers';
|
|
|
2
2
|
|
|
3
3
|
const getEndpoint = (repositoryName) => `https://${repositoryName}.cdn.prismic.io/api/v2`;
|
|
4
4
|
|
|
5
|
+
const getGraphQLEndpoint = (repositoryName) => `https://${repositoryName}.cdn.prismic.io/graphql`;
|
|
6
|
+
|
|
5
7
|
const castArray = (a) => Array.isArray(a) ? a : [a];
|
|
6
8
|
|
|
7
9
|
const RENAMED_PARAMS = {
|
|
@@ -98,9 +100,23 @@ const parse = (cookieString) => {
|
|
|
98
100
|
const getAll = (cookieStore) => parse(cookieStore);
|
|
99
101
|
const getCookie = (name, cookieStore) => getAll(cookieStore)[name];
|
|
100
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
|
+
|
|
101
114
|
class ForbiddenError extends PrismicError {
|
|
102
115
|
}
|
|
103
116
|
|
|
117
|
+
class NotFoundError extends PrismicError {
|
|
118
|
+
}
|
|
119
|
+
|
|
104
120
|
class ParsingError extends PrismicError {
|
|
105
121
|
}
|
|
106
122
|
|
|
@@ -169,34 +185,17 @@ const predicate = {
|
|
|
169
185
|
dateHourBefore: pathWithArgsPredicate("date.hour-before")
|
|
170
186
|
};
|
|
171
187
|
|
|
172
|
-
const preview = "io.prismic.preview";
|
|
173
|
-
|
|
174
|
-
var cookie = /*#__PURE__*/Object.freeze({
|
|
175
|
-
__proto__: null,
|
|
176
|
-
preview: preview
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
class NotFoundError extends PrismicError {
|
|
180
|
-
}
|
|
181
|
-
|
|
182
188
|
const MAX_PAGE_SIZE = 100;
|
|
183
189
|
const REPOSITORY_CACHE_TTL = 5e3;
|
|
184
190
|
const GET_ALL_QUERY_DELAY = 500;
|
|
185
|
-
var RefStateMode;
|
|
186
|
-
(function(RefStateMode2) {
|
|
187
|
-
RefStateMode2["Master"] = "Master";
|
|
188
|
-
RefStateMode2["ReleaseID"] = "ReleaseID";
|
|
189
|
-
RefStateMode2["ReleaseLabel"] = "ReleaseLabel";
|
|
190
|
-
RefStateMode2["Manual"] = "Manual";
|
|
191
|
-
})(RefStateMode || (RefStateMode = {}));
|
|
192
191
|
const typePredicate = (documentType) => predicate.at("document.type", documentType);
|
|
193
|
-
const everyTagPredicate = (tags) => predicate.at("document.tags", tags);
|
|
194
|
-
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));
|
|
195
194
|
const createClient = (...args) => new Client(...args);
|
|
196
195
|
class Client {
|
|
197
196
|
constructor(endpoint, options = {}) {
|
|
198
197
|
this.refState = {
|
|
199
|
-
mode:
|
|
198
|
+
mode: "Master" /* Master */,
|
|
200
199
|
autoPreviewsEnabled: true
|
|
201
200
|
};
|
|
202
201
|
this.cachedRepositoryExpiration = 0;
|
|
@@ -220,6 +219,7 @@ class Client {
|
|
|
220
219
|
if (this.fetchFn === globalThis.fetch) {
|
|
221
220
|
this.fetchFn = this.fetchFn.bind(globalThis);
|
|
222
221
|
}
|
|
222
|
+
this.graphqlFetch = this.graphqlFetch.bind(this);
|
|
223
223
|
}
|
|
224
224
|
enableAutoPreviews() {
|
|
225
225
|
this.refState.autoPreviewsEnabled = true;
|
|
@@ -303,10 +303,10 @@ class Client {
|
|
|
303
303
|
return await this.dangerouslyGetAll(appendPredicates(params, typePredicate(documentType)));
|
|
304
304
|
}
|
|
305
305
|
async getByTag(tag, params) {
|
|
306
|
-
return await this.get(appendPredicates(params,
|
|
306
|
+
return await this.get(appendPredicates(params, someTagsPredicate(tag)));
|
|
307
307
|
}
|
|
308
308
|
async getAllByTag(tag, params) {
|
|
309
|
-
return await this.dangerouslyGetAll(appendPredicates(params,
|
|
309
|
+
return await this.dangerouslyGetAll(appendPredicates(params, someTagsPredicate(tag)));
|
|
310
310
|
}
|
|
311
311
|
async getByEveryTag(tags, params) {
|
|
312
312
|
return await this.get(appendPredicates(params, everyTagPredicate(tags)));
|
|
@@ -320,53 +320,56 @@ class Client {
|
|
|
320
320
|
async getAllBySomeTags(tags, params) {
|
|
321
321
|
return await this.dangerouslyGetAll(appendPredicates(params, someTagsPredicate(tags)));
|
|
322
322
|
}
|
|
323
|
-
async getRepository() {
|
|
323
|
+
async getRepository(params) {
|
|
324
324
|
const url = new URL(this.endpoint);
|
|
325
325
|
if (this.accessToken) {
|
|
326
326
|
url.searchParams.set("access_token", this.accessToken);
|
|
327
327
|
}
|
|
328
|
-
return await this.fetch(url.toString());
|
|
328
|
+
return await this.fetch(url.toString(), params);
|
|
329
329
|
}
|
|
330
|
-
async getRefs() {
|
|
331
|
-
const repository = await this.getRepository();
|
|
330
|
+
async getRefs(params) {
|
|
331
|
+
const repository = await this.getRepository(params);
|
|
332
332
|
return repository.refs;
|
|
333
333
|
}
|
|
334
|
-
async getRefByID(id) {
|
|
335
|
-
const refs = await this.getRefs();
|
|
334
|
+
async getRefByID(id, params) {
|
|
335
|
+
const refs = await this.getRefs(params);
|
|
336
336
|
return findRefByID(refs, id);
|
|
337
337
|
}
|
|
338
|
-
async getRefByLabel(label) {
|
|
339
|
-
const refs = await this.getRefs();
|
|
338
|
+
async getRefByLabel(label, params) {
|
|
339
|
+
const refs = await this.getRefs(params);
|
|
340
340
|
return findRefByLabel(refs, label);
|
|
341
341
|
}
|
|
342
|
-
async getMasterRef() {
|
|
343
|
-
const refs = await this.getRefs();
|
|
342
|
+
async getMasterRef(params) {
|
|
343
|
+
const refs = await this.getRefs(params);
|
|
344
344
|
return findMasterRef(refs);
|
|
345
345
|
}
|
|
346
|
-
async getReleases() {
|
|
347
|
-
const refs = await this.getRefs();
|
|
346
|
+
async getReleases(params) {
|
|
347
|
+
const refs = await this.getRefs(params);
|
|
348
348
|
return refs.filter((ref) => !ref.isMasterRef);
|
|
349
349
|
}
|
|
350
|
-
async getReleaseByID(id) {
|
|
351
|
-
const releases = await this.getReleases();
|
|
350
|
+
async getReleaseByID(id, params) {
|
|
351
|
+
const releases = await this.getReleases(params);
|
|
352
352
|
return findRefByID(releases, id);
|
|
353
353
|
}
|
|
354
|
-
async getReleaseByLabel(label) {
|
|
355
|
-
const releases = await this.getReleases();
|
|
354
|
+
async getReleaseByLabel(label, params) {
|
|
355
|
+
const releases = await this.getReleases(params);
|
|
356
356
|
return findRefByLabel(releases, label);
|
|
357
357
|
}
|
|
358
|
-
async getTags() {
|
|
358
|
+
async getTags(params) {
|
|
359
359
|
try {
|
|
360
|
-
const tagsForm = await this.getCachedRepositoryForm("tags");
|
|
360
|
+
const tagsForm = await this.getCachedRepositoryForm("tags", params);
|
|
361
361
|
return await this.fetch(tagsForm.action);
|
|
362
362
|
} catch (e) {
|
|
363
|
-
const repository = await this.getRepository();
|
|
363
|
+
const repository = await this.getRepository(params);
|
|
364
364
|
return repository.tags;
|
|
365
365
|
}
|
|
366
366
|
}
|
|
367
|
-
async buildQueryURL(
|
|
367
|
+
async buildQueryURL({
|
|
368
|
+
signal,
|
|
369
|
+
...params
|
|
370
|
+
} = {}) {
|
|
368
371
|
const ref = params.ref || await this.getResolvedRefString();
|
|
369
|
-
const integrationFieldsRef = params.integrationFieldsRef || (await this.getCachedRepository()).integrationFieldsRef || void 0;
|
|
372
|
+
const integrationFieldsRef = params.integrationFieldsRef || (await this.getCachedRepository({ signal })).integrationFieldsRef || void 0;
|
|
370
373
|
return buildQueryURL(this.endpoint, {
|
|
371
374
|
...this.defaultParams,
|
|
372
375
|
...params,
|
|
@@ -390,7 +393,9 @@ class Client {
|
|
|
390
393
|
}
|
|
391
394
|
if (documentID != null) {
|
|
392
395
|
const document = await this.getByID(documentID, {
|
|
393
|
-
|
|
396
|
+
signal: args.signal,
|
|
397
|
+
ref: previewToken,
|
|
398
|
+
lang: "*"
|
|
394
399
|
});
|
|
395
400
|
return prismicH.asLink(document, args.linkResolver);
|
|
396
401
|
} else {
|
|
@@ -398,45 +403,70 @@ class Client {
|
|
|
398
403
|
}
|
|
399
404
|
}
|
|
400
405
|
queryLatestContent() {
|
|
401
|
-
this.refState.mode =
|
|
406
|
+
this.refState.mode = "Master" /* Master */;
|
|
402
407
|
}
|
|
403
408
|
queryContentFromReleaseByID(releaseID) {
|
|
404
409
|
this.refState = {
|
|
405
410
|
...this.refState,
|
|
406
|
-
mode:
|
|
411
|
+
mode: "ReleaseID" /* ReleaseID */,
|
|
407
412
|
releaseID
|
|
408
413
|
};
|
|
409
414
|
}
|
|
410
415
|
queryContentFromReleaseByLabel(releaseLabel) {
|
|
411
416
|
this.refState = {
|
|
412
417
|
...this.refState,
|
|
413
|
-
mode:
|
|
418
|
+
mode: "ReleaseLabel" /* ReleaseLabel */,
|
|
414
419
|
releaseLabel
|
|
415
420
|
};
|
|
416
421
|
}
|
|
417
422
|
queryContentFromRef(ref) {
|
|
418
423
|
this.refState = {
|
|
419
424
|
...this.refState,
|
|
420
|
-
mode:
|
|
425
|
+
mode: "Manual" /* Manual */,
|
|
421
426
|
ref
|
|
422
427
|
};
|
|
423
428
|
}
|
|
424
|
-
async
|
|
429
|
+
async graphqlFetch(input, init) {
|
|
430
|
+
const cachedRepository = await this.getCachedRepository();
|
|
431
|
+
const ref = await this.getResolvedRefString();
|
|
432
|
+
const unsanitizedHeaders = {
|
|
433
|
+
"Prismic-ref": ref,
|
|
434
|
+
"Prismic-integration-field-ref": cachedRepository.integrationFieldsRef || "",
|
|
435
|
+
Authorization: this.accessToken ? `Token ${this.accessToken}` : "",
|
|
436
|
+
...init ? init.headers : {}
|
|
437
|
+
};
|
|
438
|
+
const headers = {};
|
|
439
|
+
for (const key in unsanitizedHeaders) {
|
|
440
|
+
if (unsanitizedHeaders[key]) {
|
|
441
|
+
headers[key.toLowerCase()] = unsanitizedHeaders[key];
|
|
442
|
+
}
|
|
443
|
+
}
|
|
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(), {
|
|
450
|
+
...init,
|
|
451
|
+
headers
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
async getCachedRepository(params) {
|
|
425
455
|
if (!this.cachedRepository || Date.now() >= this.cachedRepositoryExpiration) {
|
|
426
456
|
this.cachedRepositoryExpiration = Date.now() + REPOSITORY_CACHE_TTL;
|
|
427
|
-
this.cachedRepository = await this.getRepository();
|
|
457
|
+
this.cachedRepository = await this.getRepository(params);
|
|
428
458
|
}
|
|
429
459
|
return this.cachedRepository;
|
|
430
460
|
}
|
|
431
|
-
async getCachedRepositoryForm(name) {
|
|
432
|
-
const cachedRepository = await this.getCachedRepository();
|
|
461
|
+
async getCachedRepositoryForm(name, params) {
|
|
462
|
+
const cachedRepository = await this.getCachedRepository(params);
|
|
433
463
|
const form = cachedRepository.forms[name];
|
|
434
464
|
if (!form) {
|
|
435
465
|
throw new PrismicError(`Form with name "${name}" could not be found`, void 0, void 0);
|
|
436
466
|
}
|
|
437
467
|
return form;
|
|
438
468
|
}
|
|
439
|
-
async getResolvedRefString() {
|
|
469
|
+
async getResolvedRefString(params) {
|
|
440
470
|
var _a, _b, _c;
|
|
441
471
|
if (this.refState.autoPreviewsEnabled) {
|
|
442
472
|
let previewRef = void 0;
|
|
@@ -449,13 +479,13 @@ class Client {
|
|
|
449
479
|
return previewRef;
|
|
450
480
|
}
|
|
451
481
|
}
|
|
452
|
-
const cachedRepository = await this.getCachedRepository();
|
|
482
|
+
const cachedRepository = await this.getCachedRepository(params);
|
|
453
483
|
const refModeType = this.refState.mode;
|
|
454
|
-
if (refModeType ===
|
|
484
|
+
if (refModeType === "ReleaseID" /* ReleaseID */) {
|
|
455
485
|
return findRefByID(cachedRepository.refs, this.refState.releaseID).ref;
|
|
456
|
-
} else if (refModeType ===
|
|
486
|
+
} else if (refModeType === "ReleaseLabel" /* ReleaseLabel */) {
|
|
457
487
|
return findRefByLabel(cachedRepository.refs, this.refState.releaseLabel).ref;
|
|
458
|
-
} else if (refModeType ===
|
|
488
|
+
} else if (refModeType === "Manual" /* Manual */) {
|
|
459
489
|
const res = await castThunk(this.refState.ref)();
|
|
460
490
|
if (typeof res === "string") {
|
|
461
491
|
return res;
|
|
@@ -463,8 +493,10 @@ class Client {
|
|
|
463
493
|
}
|
|
464
494
|
return findMasterRef(cachedRepository.refs).ref;
|
|
465
495
|
}
|
|
466
|
-
async fetch(url,
|
|
467
|
-
const res = await this.fetchFn(url
|
|
496
|
+
async fetch(url, params = {}) {
|
|
497
|
+
const res = await this.fetchFn(url, {
|
|
498
|
+
signal: params.signal
|
|
499
|
+
});
|
|
468
500
|
let json;
|
|
469
501
|
try {
|
|
470
502
|
json = await res.json();
|
|
@@ -494,5 +526,5 @@ class Client {
|
|
|
494
526
|
const predicates = predicate;
|
|
495
527
|
const Predicates = predicate;
|
|
496
528
|
|
|
497
|
-
export { Client, ForbiddenError, NotFoundError, ParsingError, Predicates, PrismicError, buildQueryURL, cookie, createClient, getEndpoint, predicate, predicates };
|
|
529
|
+
export { Client, ForbiddenError, NotFoundError, ParsingError, Predicates, PrismicError, buildQueryURL, cookie, createClient, getEndpoint, getGraphQLEndpoint, predicate, predicates };
|
|
498
530
|
//# sourceMappingURL=index.js.map
|