@szymonpiatek/nextwordpress 0.0.1 → 0.0.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.
package/dist/index.d.ts CHANGED
@@ -4,32 +4,6 @@ interface NextWordpressConfig {
4
4
  /** Used in browser / client components (e.g., public domain). */
5
5
  clientURL: string;
6
6
  }
7
- interface WordPressPaginationHeaders {
8
- total: number;
9
- totalPages: number;
10
- }
11
- interface WordPressResponse<T> {
12
- data: T;
13
- headers: WordPressPaginationHeaders;
14
- }
15
- declare class WordPressAPIError extends Error {
16
- status: number;
17
- endpoint: string;
18
- constructor(message: string, status: number, endpoint: string);
19
- }
20
-
21
- declare function resolveBaseUrl(config: NextWordpressConfig): string;
22
- declare function buildUrl(config: NextWordpressConfig, path: string, query?: Record<string, unknown>): string;
23
-
24
- declare function createFetcher(config: NextWordpressConfig): {
25
- wpFetch: <T>(path: string, query?: Record<string, unknown>, tags?: string[]) => Promise<T>;
26
- wpFetchGraceful: <T>(path: string, fallback: T, query?: Record<string, unknown>, tags?: string[]) => Promise<T>;
27
- wpFetchPaginated: <T>(path: string, query?: Record<string, unknown>, tags?: string[]) => Promise<WordPressResponse<T[]>>;
28
- wpFetchPaginatedGraceful: <T>(path: string, query?: Record<string, unknown>, tags?: string[]) => Promise<WordPressResponse<T[]>>;
29
- wpMutate: <T>(path: string, body: unknown, method?: "POST" | "PUT" | "PATCH" | "DELETE") => Promise<T>;
30
- };
31
- type WordPressFetcher = ReturnType<typeof createFetcher>;
32
-
33
7
  interface WPEntity {
34
8
  id: number;
35
9
  date: string;
@@ -60,6 +34,17 @@ interface Taxonomy {
60
34
  meta: Record<string, unknown>;
61
35
  }
62
36
 
37
+ declare function resolveBaseUrl(config: NextWordpressConfig): string;
38
+
39
+ interface WordPressPaginationHeaders {
40
+ total: number;
41
+ totalPages: number;
42
+ }
43
+ interface WordPressResponse<T> {
44
+ data: T;
45
+ headers: WordPressPaginationHeaders;
46
+ }
47
+
63
48
  interface MediaSize {
64
49
  file: string;
65
50
  width: number;
@@ -694,4 +679,408 @@ declare function createWooCommerceClient(config: WooCommerceConfig): {
694
679
  getProductVariationById: (productId: number, variationId: number) => Promise<WCProductVariation>;
695
680
  };
696
681
 
697
- export { type Author, type BlockType, type Category, type EditorBlock, type EmbeddedAuthor, type EmbeddedTerm, type FeaturedMedia, type MediaDetails, type MediaSize, type NextWordpressConfig, type OmnibusPriceEntry, type OmnibusProductData, type Page, type Post, type PostEmbedded, type RenderedContent, type RenderedTitle, type SearchResult, type Tag, type Taxonomy, type TemplatePart, type WCAddress, type WCCoupon, type WCCreateOrderInput, type WCCustomer, type WCDimensions, type WCImage, type WCOrder, type WCOrderLineItem, type WCProduct, type WCProductAttribute, type WCProductCategory, type WCProductDefaultAttribute, type WCProductFilterParams, type WCProductTag, type WCProductVariation, type WCProductVariationWithOmnibus, type WCProductWithOmnibus, type WCShippingLine, type WPEntity, type WooCommerceConfig, type WooCommerceFetcher, type WooCommercePaginationHeaders, type WooCommerceResponse, WordPressAPIError, type WordPressFetcher, type WordPressPaginationHeaders, type WordPressResponse, buildUrl, createFetcher, createWooCommerceClient, createWooCommerceFetcher, createWordPressClient, extractOmnibusData, resolveBaseUrl, withOmnibus, withOmnibusVariation };
682
+ type WPGraphQLConfig = NextWordpressConfig;
683
+ interface GQLPageInfo {
684
+ hasNextPage: boolean;
685
+ hasPreviousPage: boolean;
686
+ startCursor?: string;
687
+ endCursor?: string;
688
+ }
689
+ interface GQLConnection<T> {
690
+ nodes: T[];
691
+ pageInfo: GQLPageInfo;
692
+ }
693
+ interface GQLError {
694
+ message: string;
695
+ locations?: Array<{
696
+ line: number;
697
+ column: number;
698
+ }>;
699
+ path?: string[];
700
+ }
701
+ declare class WPGraphQLError extends Error {
702
+ readonly status: number;
703
+ readonly endpoint: string;
704
+ readonly gqlErrors?: GQLError[] | undefined;
705
+ constructor(message: string, status: number, endpoint: string, gqlErrors?: GQLError[] | undefined);
706
+ }
707
+
708
+ declare function createWPGraphQLFetcher(config: WPGraphQLConfig): {
709
+ gqlFetch: <TData>(document: string, variables?: Record<string, unknown>, tags?: string[]) => Promise<TData>;
710
+ gqlFetchGraceful: <TData>(document: string, fallback: TData, variables?: Record<string, unknown>, tags?: string[]) => Promise<TData>;
711
+ };
712
+ type WPGraphQLFetcher = ReturnType<typeof createWPGraphQLFetcher>;
713
+
714
+ interface GQLPostFilter {
715
+ authorName?: string;
716
+ categoryName?: string;
717
+ tag?: string;
718
+ search?: string;
719
+ status?: string;
720
+ }
721
+ interface GQLPost {
722
+ id: string;
723
+ databaseId: number;
724
+ slug: string;
725
+ title: string;
726
+ content: string;
727
+ excerpt: string;
728
+ date: string;
729
+ modified: string;
730
+ status: string;
731
+ uri: string;
732
+ author?: {
733
+ node: {
734
+ databaseId: number;
735
+ name: string;
736
+ slug: string;
737
+ avatar?: {
738
+ url: string;
739
+ };
740
+ };
741
+ };
742
+ featuredImage?: {
743
+ node: {
744
+ sourceUrl: string;
745
+ altText: string;
746
+ mediaDetails?: {
747
+ width: number;
748
+ height: number;
749
+ };
750
+ };
751
+ };
752
+ categories?: {
753
+ nodes: Array<{
754
+ databaseId: number;
755
+ name: string;
756
+ slug: string;
757
+ }>;
758
+ };
759
+ tags?: {
760
+ nodes: Array<{
761
+ databaseId: number;
762
+ name: string;
763
+ slug: string;
764
+ }>;
765
+ };
766
+ }
767
+
768
+ interface GQLPage {
769
+ id: string;
770
+ databaseId: number;
771
+ slug: string;
772
+ title: string;
773
+ content: string;
774
+ date: string;
775
+ modified: string;
776
+ status: string;
777
+ uri: string;
778
+ featuredImage?: {
779
+ node: {
780
+ sourceUrl: string;
781
+ altText: string;
782
+ mediaDetails?: {
783
+ width: number;
784
+ height: number;
785
+ };
786
+ };
787
+ };
788
+ }
789
+
790
+ interface GQLCategory {
791
+ id: string;
792
+ databaseId: number;
793
+ name: string;
794
+ slug: string;
795
+ description: string;
796
+ count: number | null;
797
+ uri: string;
798
+ parent?: {
799
+ node: {
800
+ databaseId: number;
801
+ name: string;
802
+ slug: string;
803
+ };
804
+ };
805
+ }
806
+
807
+ interface GQLTag {
808
+ id: string;
809
+ databaseId: number;
810
+ name: string;
811
+ slug: string;
812
+ description: string;
813
+ count: number;
814
+ uri: string;
815
+ }
816
+
817
+ interface GQLAuthor {
818
+ id: string;
819
+ databaseId: number;
820
+ name: string;
821
+ slug: string;
822
+ description: string;
823
+ email: string;
824
+ uri: string;
825
+ avatar?: {
826
+ url: string;
827
+ width: number;
828
+ height: number;
829
+ };
830
+ }
831
+
832
+ declare function createWPGraphQLCoreClient(config: WPGraphQLConfig): {
833
+ getAuthors: (first?: number, after?: string) => Promise<GQLConnection<GQLAuthor>>;
834
+ getAuthorBySlug: (slug: string) => Promise<GQLAuthor | null>;
835
+ getTags: (first?: number, after?: string) => Promise<GQLConnection<GQLTag>>;
836
+ getTagBySlug: (slug: string) => Promise<GQLTag | null>;
837
+ getCategories: (first?: number, after?: string) => Promise<GQLConnection<GQLCategory>>;
838
+ getCategoryBySlug: (slug: string) => Promise<GQLCategory | null>;
839
+ getCategoryByDatabaseId: (id: number) => Promise<GQLCategory | null>;
840
+ getPages: (first?: number, after?: string) => Promise<GQLConnection<GQLPage>>;
841
+ getPageBySlug: (slug: string) => Promise<GQLPage | null>;
842
+ getPageByUri: (uri: string) => Promise<GQLPage | null>;
843
+ getAllPageUris: () => Promise<{
844
+ uri: string;
845
+ }[]>;
846
+ getPosts: (first?: number, after?: string, filter?: GQLPostFilter) => Promise<GQLConnection<GQLPost>>;
847
+ getPostBySlug: (slug: string) => Promise<GQLPost | null>;
848
+ getPostByDatabaseId: (id: number) => Promise<GQLPost | null>;
849
+ getRecentPosts: (first?: number) => Promise<GQLPost[]>;
850
+ getAllPostSlugs: () => Promise<{
851
+ slug: string;
852
+ }[]>;
853
+ getAllPostsForSitemap: () => Promise<{
854
+ slug: string;
855
+ modified: string;
856
+ }[]>;
857
+ };
858
+
859
+ interface GQLYoastSEO {
860
+ title: string;
861
+ metaDesc: string;
862
+ canonical: string;
863
+ opengraphTitle: string;
864
+ opengraphDescription: string;
865
+ opengraphImage?: {
866
+ sourceUrl: string;
867
+ altText: string;
868
+ };
869
+ twitterTitle: string;
870
+ twitterDescription: string;
871
+ twitterImage?: {
872
+ sourceUrl: string;
873
+ };
874
+ schema?: {
875
+ raw: string;
876
+ };
877
+ }
878
+ interface GQLPostWithSEO extends GQLPost {
879
+ seo: GQLYoastSEO;
880
+ }
881
+ interface GQLPageWithSEO extends GQLPage {
882
+ seo: GQLYoastSEO;
883
+ }
884
+
885
+ declare function createYoastQueries(fetcher: WPGraphQLFetcher): {
886
+ getPostWithSEO: (slug: string) => Promise<GQLPostWithSEO | null>;
887
+ getPageWithSEO: (slug: string) => Promise<GQLPageWithSEO | null>;
888
+ getPageWithSEOByUri: (uri: string) => Promise<GQLPageWithSEO | null>;
889
+ };
890
+
891
+ interface GQLACFFieldGroup {
892
+ [key: string]: unknown;
893
+ }
894
+
895
+ declare function buildACFFragment(fieldGroupName: string, fields: string[]): string;
896
+ declare function buildPostWithACFQuery(fieldGroupName: string, fields: string[]): string;
897
+ declare function buildPageWithACFQuery(fieldGroupName: string, fields: string[]): string;
898
+ declare function buildPostsWithACFQuery(fieldGroupName: string, fields: string[]): string;
899
+
900
+ interface GQLProductFilter {
901
+ search?: string;
902
+ categoryId?: number;
903
+ tagId?: number;
904
+ onSale?: boolean;
905
+ featured?: boolean;
906
+ stockStatus?: 'IN_STOCK' | 'OUT_OF_STOCK' | 'ON_BACKORDER';
907
+ minPrice?: string;
908
+ maxPrice?: string;
909
+ }
910
+ interface GQLProductVariation {
911
+ id: string;
912
+ databaseId: number;
913
+ slug: string;
914
+ sku: string;
915
+ price: string;
916
+ regularPrice: string;
917
+ salePrice?: string;
918
+ onSale: boolean;
919
+ stockStatus: 'IN_STOCK' | 'OUT_OF_STOCK' | 'ON_BACKORDER';
920
+ stockQuantity?: number;
921
+ image?: {
922
+ sourceUrl: string;
923
+ altText: string;
924
+ };
925
+ attributes?: {
926
+ nodes: Array<{
927
+ name: string;
928
+ value: string;
929
+ }>;
930
+ };
931
+ }
932
+ interface GQLProduct {
933
+ id: string;
934
+ databaseId: number;
935
+ slug: string;
936
+ name: string;
937
+ description: string;
938
+ shortDescription: string;
939
+ sku: string;
940
+ price: string;
941
+ regularPrice: string;
942
+ salePrice?: string;
943
+ onSale: boolean;
944
+ stockStatus: 'IN_STOCK' | 'OUT_OF_STOCK' | 'ON_BACKORDER';
945
+ stockQuantity?: number;
946
+ manageStock: boolean;
947
+ type: 'SIMPLE' | 'VARIABLE' | 'GROUPED' | 'EXTERNAL';
948
+ featuredImage?: {
949
+ node: {
950
+ sourceUrl: string;
951
+ altText: string;
952
+ };
953
+ };
954
+ galleryImages?: {
955
+ nodes: Array<{
956
+ sourceUrl: string;
957
+ altText: string;
958
+ }>;
959
+ };
960
+ productCategories?: {
961
+ nodes: Array<{
962
+ databaseId: number;
963
+ name: string;
964
+ slug: string;
965
+ }>;
966
+ };
967
+ productTags?: {
968
+ nodes: Array<{
969
+ databaseId: number;
970
+ name: string;
971
+ slug: string;
972
+ }>;
973
+ };
974
+ variations?: {
975
+ nodes: GQLProductVariation[];
976
+ };
977
+ }
978
+
979
+ interface GQLLineItem {
980
+ productId: number;
981
+ variationId?: number;
982
+ quantity: number;
983
+ subtotal: string;
984
+ total: string;
985
+ product?: {
986
+ node: {
987
+ databaseId: number;
988
+ name: string;
989
+ slug: string;
990
+ };
991
+ };
992
+ }
993
+ interface GQLOrderAddress {
994
+ firstName: string;
995
+ lastName: string;
996
+ address1: string;
997
+ address2?: string;
998
+ city: string;
999
+ postcode: string;
1000
+ country: string;
1001
+ email?: string;
1002
+ phone?: string;
1003
+ }
1004
+ interface GQLOrder {
1005
+ id: string;
1006
+ databaseId: number;
1007
+ orderNumber: string;
1008
+ status: string;
1009
+ date: string;
1010
+ modified: string;
1011
+ total: string;
1012
+ subtotal: string;
1013
+ totalTax: string;
1014
+ shippingTotal: string;
1015
+ currency: string;
1016
+ billing?: GQLOrderAddress;
1017
+ shipping?: GQLOrderAddress;
1018
+ lineItems?: {
1019
+ nodes: GQLLineItem[];
1020
+ };
1021
+ }
1022
+
1023
+ interface GQLCustomer {
1024
+ id: string;
1025
+ databaseId: number;
1026
+ email: string;
1027
+ firstName: string;
1028
+ lastName: string;
1029
+ username: string;
1030
+ billing?: {
1031
+ firstName: string;
1032
+ lastName: string;
1033
+ address1: string;
1034
+ address2?: string;
1035
+ city: string;
1036
+ postcode: string;
1037
+ country: string;
1038
+ phone?: string;
1039
+ };
1040
+ shipping?: {
1041
+ firstName: string;
1042
+ lastName: string;
1043
+ address1: string;
1044
+ address2?: string;
1045
+ city: string;
1046
+ postcode: string;
1047
+ country: string;
1048
+ };
1049
+ }
1050
+
1051
+ declare function createWPGraphQLWooCommerceClient(config: WPGraphQLConfig): {
1052
+ getCustomer: () => Promise<GQLCustomer | null>;
1053
+ getCustomerById: (id: number) => Promise<GQLCustomer | null>;
1054
+ getOrder: (id: number) => Promise<GQLOrder | null>;
1055
+ getMyOrders: (first?: number, after?: string) => Promise<GQLConnection<GQLOrder>>;
1056
+ getProducts: (first?: number, after?: string, filter?: GQLProductFilter) => Promise<GQLConnection<GQLProduct>>;
1057
+ getProductBySlug: (slug: string) => Promise<GQLProduct | null>;
1058
+ getProductByDatabaseId: (id: number) => Promise<GQLProduct | null>;
1059
+ getFeaturedProducts: (first?: number) => Promise<GQLProduct[]>;
1060
+ getOnSaleProducts: (first?: number) => Promise<GQLProduct[]>;
1061
+ getAllProductSlugs: () => Promise<{
1062
+ slug: string;
1063
+ }[]>;
1064
+ };
1065
+
1066
+ interface GQLCPTNode {
1067
+ id: string;
1068
+ databaseId: number;
1069
+ slug: string;
1070
+ title: string;
1071
+ date: string;
1072
+ modified: string;
1073
+ status: string;
1074
+ uri: string;
1075
+ [key: string]: unknown;
1076
+ }
1077
+
1078
+ declare function createCPTQueries(fetcher: WPGraphQLFetcher, typeName: string, singularTypeName: string, extraFields?: string): {
1079
+ getItems: (first?: number, after?: string) => Promise<GQLConnection<GQLCPTNode>>;
1080
+ getItemBySlug: (slug: string) => Promise<GQLCPTNode | null>;
1081
+ getAllSlugs: () => Promise<{
1082
+ slug: string;
1083
+ }[]>;
1084
+ };
1085
+
1086
+ export { type Author, type BlockType, type Category, type EditorBlock, type EmbeddedAuthor, type EmbeddedTerm, type FeaturedMedia, type GQLACFFieldGroup, type GQLAuthor, type GQLCPTNode, type GQLCategory, type GQLConnection, type GQLCustomer, type GQLError, type GQLLineItem, type GQLOrder, type GQLOrderAddress, type GQLPage, type GQLPageInfo, type GQLPageWithSEO, type GQLPost, type GQLPostFilter, type GQLPostWithSEO, type GQLProduct, type GQLProductFilter, type GQLProductVariation, type GQLTag, type GQLYoastSEO, type MediaDetails, type MediaSize, type NextWordpressConfig, type OmnibusPriceEntry, type OmnibusProductData, type Page, type Post, type PostEmbedded, type RenderedContent, type RenderedTitle, type SearchResult, type Tag, type Taxonomy, type TemplatePart, type WCAddress, type WCCoupon, type WCCreateOrderInput, type WCCustomer, type WCDimensions, type WCImage, type WCOrder, type WCOrderLineItem, type WCProduct, type WCProductAttribute, type WCProductCategory, type WCProductDefaultAttribute, type WCProductFilterParams, type WCProductTag, type WCProductVariation, type WCProductVariationWithOmnibus, type WCProductWithOmnibus, type WCShippingLine, type WPEntity, type WPGraphQLConfig, WPGraphQLError, type WPGraphQLFetcher, type WooCommerceConfig, type WooCommerceFetcher, type WooCommercePaginationHeaders, type WooCommerceResponse, buildACFFragment, buildPageWithACFQuery, buildPostWithACFQuery, buildPostsWithACFQuery, createCPTQueries, createWPGraphQLCoreClient as createWPGraphQLClient, createWPGraphQLCoreClient, createWPGraphQLFetcher, createWPGraphQLWooCommerceClient, createWooCommerceClient, createWooCommerceFetcher, createWordPressClient, createYoastQueries, extractOmnibusData, resolveBaseUrl, withOmnibus, withOmnibusVariation };