@atomic-solutions/wordpress-api-client 0.1.1 → 0.1.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/client/index.cjs +321 -10
- package/dist/client/index.cjs.map +1 -1
- package/dist/client/index.js +312 -1
- package/dist/client/index.js.map +1 -1
- package/dist/index.cjs +438 -137
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +403 -4
- package/dist/index.js.map +1 -1
- package/dist/testing/index.cjs +321 -10
- package/dist/testing/index.cjs.map +1 -1
- package/dist/testing/index.js +312 -1
- package/dist/testing/index.js.map +1 -1
- package/package.json +4 -6
package/dist/client/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var axios = require('axios');
|
|
4
|
-
var
|
|
4
|
+
var zod = require('zod');
|
|
5
5
|
|
|
6
6
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
7
|
|
|
@@ -698,13 +698,316 @@ var setupErrorInterceptor = (axiosInstance, config, client) => {
|
|
|
698
698
|
}
|
|
699
699
|
);
|
|
700
700
|
};
|
|
701
|
+
zod.z.object({
|
|
702
|
+
username: zod.z.string(),
|
|
703
|
+
password: zod.z.string()
|
|
704
|
+
});
|
|
705
|
+
var JwtTokenResponseSchema = zod.z.object({
|
|
706
|
+
token: zod.z.string(),
|
|
707
|
+
user_email: zod.z.string(),
|
|
708
|
+
user_nicename: zod.z.string(),
|
|
709
|
+
user_display_name: zod.z.string()
|
|
710
|
+
});
|
|
711
|
+
zod.z.object({
|
|
712
|
+
code: zod.z.string(),
|
|
713
|
+
data: zod.z.object({
|
|
714
|
+
status: zod.z.number()
|
|
715
|
+
})
|
|
716
|
+
});
|
|
717
|
+
zod.z.object({
|
|
718
|
+
code: zod.z.string(),
|
|
719
|
+
message: zod.z.string(),
|
|
720
|
+
data: zod.z.object({
|
|
721
|
+
status: zod.z.number()
|
|
722
|
+
}).optional()
|
|
723
|
+
});
|
|
724
|
+
var RenderedContentSchema = zod.z.object({
|
|
725
|
+
rendered: zod.z.string(),
|
|
726
|
+
protected: zod.z.boolean().optional()
|
|
727
|
+
});
|
|
728
|
+
var GuidSchema = zod.z.object({
|
|
729
|
+
rendered: zod.z.string()
|
|
730
|
+
});
|
|
731
|
+
zod.z.enum([
|
|
732
|
+
"publish",
|
|
733
|
+
"future",
|
|
734
|
+
"draft",
|
|
735
|
+
"pending",
|
|
736
|
+
"private",
|
|
737
|
+
"trash",
|
|
738
|
+
"auto-draft",
|
|
739
|
+
"inherit"
|
|
740
|
+
]);
|
|
741
|
+
var HalLinkItemSchema = zod.z.object({
|
|
742
|
+
href: zod.z.string(),
|
|
743
|
+
embeddable: zod.z.boolean().optional(),
|
|
744
|
+
templated: zod.z.boolean().optional()
|
|
745
|
+
});
|
|
746
|
+
var HalLinksSchema = zod.z.object({
|
|
747
|
+
self: zod.z.array(HalLinkItemSchema).optional(),
|
|
748
|
+
collection: zod.z.array(HalLinkItemSchema).optional(),
|
|
749
|
+
about: zod.z.array(HalLinkItemSchema).optional(),
|
|
750
|
+
author: zod.z.array(HalLinkItemSchema).optional(),
|
|
751
|
+
replies: zod.z.array(HalLinkItemSchema).optional(),
|
|
752
|
+
"wp:featuredmedia": zod.z.array(HalLinkItemSchema).optional(),
|
|
753
|
+
"wp:attachment": zod.z.array(HalLinkItemSchema).optional(),
|
|
754
|
+
"wp:term": zod.z.array(HalLinkItemSchema).optional(),
|
|
755
|
+
"wp:post_type": zod.z.array(HalLinkItemSchema).optional(),
|
|
756
|
+
curies: zod.z.array(
|
|
757
|
+
zod.z.object({
|
|
758
|
+
name: zod.z.string(),
|
|
759
|
+
href: zod.z.string(),
|
|
760
|
+
templated: zod.z.boolean()
|
|
761
|
+
})
|
|
762
|
+
).optional()
|
|
763
|
+
}).passthrough();
|
|
764
|
+
zod.z.object({
|
|
765
|
+
id: zod.z.number(),
|
|
766
|
+
date: zod.z.string(),
|
|
767
|
+
date_gmt: zod.z.string(),
|
|
768
|
+
modified: zod.z.string(),
|
|
769
|
+
modified_gmt: zod.z.string(),
|
|
770
|
+
slug: zod.z.string(),
|
|
771
|
+
status: zod.z.string(),
|
|
772
|
+
type: zod.z.string(),
|
|
773
|
+
link: zod.z.string(),
|
|
774
|
+
_links: HalLinksSchema.optional()
|
|
775
|
+
});
|
|
776
|
+
var paginationParamsSchema = zod.z.object({
|
|
777
|
+
/** Current page number */
|
|
778
|
+
page: zod.z.number().int().positive().optional(),
|
|
779
|
+
/** Items per page */
|
|
780
|
+
per_page: zod.z.number().int().positive().max(100).optional(),
|
|
781
|
+
/** Offset for pagination */
|
|
782
|
+
offset: zod.z.number().int().nonnegative().optional(),
|
|
783
|
+
/** Sort order */
|
|
784
|
+
order: zod.z.enum(["asc", "desc"]).optional(),
|
|
785
|
+
/** Field to sort by */
|
|
786
|
+
orderby: zod.z.string().optional()
|
|
787
|
+
});
|
|
788
|
+
zod.z.object({
|
|
789
|
+
/** Total number of items */
|
|
790
|
+
total: zod.z.number(),
|
|
791
|
+
/** Total number of pages */
|
|
792
|
+
totalPages: zod.z.number(),
|
|
793
|
+
/** Current page */
|
|
794
|
+
currentPage: zod.z.number(),
|
|
795
|
+
/** Items per page */
|
|
796
|
+
perPage: zod.z.number()
|
|
797
|
+
});
|
|
798
|
+
var CategorySchema = zod.z.object({
|
|
799
|
+
id: zod.z.number(),
|
|
800
|
+
count: zod.z.number(),
|
|
801
|
+
description: zod.z.string().optional(),
|
|
802
|
+
link: zod.z.string(),
|
|
803
|
+
name: zod.z.string(),
|
|
804
|
+
slug: zod.z.string(),
|
|
805
|
+
taxonomy: zod.z.string(),
|
|
806
|
+
parent: zod.z.number(),
|
|
807
|
+
meta: zod.z.any().optional(),
|
|
808
|
+
_links: HalLinksSchema.optional()
|
|
809
|
+
});
|
|
810
|
+
var CategoriesListSchema = zod.z.array(CategorySchema);
|
|
811
|
+
paginationParamsSchema.extend({
|
|
812
|
+
context: zod.z.enum(["view", "embed", "edit"]).optional(),
|
|
813
|
+
search: zod.z.string().optional(),
|
|
814
|
+
exclude: zod.z.array(zod.z.number()).optional(),
|
|
815
|
+
include: zod.z.array(zod.z.number()).optional(),
|
|
816
|
+
hide_empty: zod.z.boolean().optional(),
|
|
817
|
+
parent: zod.z.number().optional(),
|
|
818
|
+
post: zod.z.number().optional(),
|
|
819
|
+
slug: zod.z.string().optional()
|
|
820
|
+
});
|
|
821
|
+
var TagSchema = zod.z.object({
|
|
822
|
+
id: zod.z.number(),
|
|
823
|
+
count: zod.z.number(),
|
|
824
|
+
description: zod.z.string().optional(),
|
|
825
|
+
link: zod.z.string(),
|
|
826
|
+
name: zod.z.string(),
|
|
827
|
+
slug: zod.z.string(),
|
|
828
|
+
taxonomy: zod.z.string(),
|
|
829
|
+
meta: zod.z.any().optional(),
|
|
830
|
+
_links: HalLinksSchema.optional()
|
|
831
|
+
});
|
|
832
|
+
zod.z.array(TagSchema);
|
|
833
|
+
var MediaSizeSchema = zod.z.object({
|
|
834
|
+
file: zod.z.string(),
|
|
835
|
+
width: zod.z.number(),
|
|
836
|
+
height: zod.z.number(),
|
|
837
|
+
filesize: zod.z.number().optional(),
|
|
838
|
+
mime_type: zod.z.string(),
|
|
839
|
+
source_url: zod.z.string()
|
|
840
|
+
});
|
|
841
|
+
var MediaSizesSchema = zod.z.object({
|
|
842
|
+
thumbnail: MediaSizeSchema.optional(),
|
|
843
|
+
medium: MediaSizeSchema.optional(),
|
|
844
|
+
medium_large: MediaSizeSchema.optional(),
|
|
845
|
+
large: MediaSizeSchema.optional(),
|
|
846
|
+
full: MediaSizeSchema.optional()
|
|
847
|
+
}).passthrough();
|
|
848
|
+
var ImageMetaSchema = zod.z.object({
|
|
849
|
+
aperture: zod.z.string().optional(),
|
|
850
|
+
credit: zod.z.string().optional(),
|
|
851
|
+
camera: zod.z.string().optional(),
|
|
852
|
+
caption: zod.z.string().optional(),
|
|
853
|
+
created_timestamp: zod.z.string().optional(),
|
|
854
|
+
copyright: zod.z.string().optional(),
|
|
855
|
+
focal_length: zod.z.string().optional(),
|
|
856
|
+
iso: zod.z.string().optional(),
|
|
857
|
+
shutter_speed: zod.z.string().optional(),
|
|
858
|
+
title: zod.z.string().optional(),
|
|
859
|
+
orientation: zod.z.string().optional(),
|
|
860
|
+
keywords: zod.z.array(zod.z.string()).optional()
|
|
861
|
+
});
|
|
862
|
+
var MediaDetailsSchema = zod.z.object({
|
|
863
|
+
width: zod.z.number(),
|
|
864
|
+
height: zod.z.number(),
|
|
865
|
+
file: zod.z.string(),
|
|
866
|
+
filesize: zod.z.number().optional(),
|
|
867
|
+
sizes: MediaSizesSchema,
|
|
868
|
+
image_meta: ImageMetaSchema.optional()
|
|
869
|
+
});
|
|
870
|
+
var MediaSchema = zod.z.object({
|
|
871
|
+
id: zod.z.number(),
|
|
872
|
+
date: zod.z.string(),
|
|
873
|
+
date_gmt: zod.z.string(),
|
|
874
|
+
guid: GuidSchema,
|
|
875
|
+
modified: zod.z.string(),
|
|
876
|
+
modified_gmt: zod.z.string(),
|
|
877
|
+
slug: zod.z.string(),
|
|
878
|
+
status: zod.z.string(),
|
|
879
|
+
type: zod.z.string(),
|
|
880
|
+
link: zod.z.string(),
|
|
881
|
+
title: RenderedContentSchema,
|
|
882
|
+
author: zod.z.number(),
|
|
883
|
+
comment_status: zod.z.string(),
|
|
884
|
+
ping_status: zod.z.string(),
|
|
885
|
+
template: zod.z.string().optional(),
|
|
886
|
+
meta: zod.z.any().optional(),
|
|
887
|
+
description: RenderedContentSchema,
|
|
888
|
+
caption: RenderedContentSchema,
|
|
889
|
+
alt_text: zod.z.string(),
|
|
890
|
+
media_type: zod.z.string(),
|
|
891
|
+
mime_type: zod.z.string(),
|
|
892
|
+
media_details: MediaDetailsSchema,
|
|
893
|
+
post: zod.z.number().nullable(),
|
|
894
|
+
source_url: zod.z.string(),
|
|
895
|
+
_links: HalLinksSchema.optional()
|
|
896
|
+
});
|
|
897
|
+
zod.z.array(MediaSchema);
|
|
898
|
+
var PostSchema = zod.z.object({
|
|
899
|
+
id: zod.z.number(),
|
|
900
|
+
date: zod.z.string(),
|
|
901
|
+
date_gmt: zod.z.string(),
|
|
902
|
+
guid: GuidSchema,
|
|
903
|
+
modified: zod.z.string(),
|
|
904
|
+
modified_gmt: zod.z.string(),
|
|
905
|
+
slug: zod.z.string(),
|
|
906
|
+
status: zod.z.string(),
|
|
907
|
+
type: zod.z.string(),
|
|
908
|
+
link: zod.z.string(),
|
|
909
|
+
title: RenderedContentSchema,
|
|
910
|
+
content: RenderedContentSchema,
|
|
911
|
+
excerpt: RenderedContentSchema,
|
|
912
|
+
author: zod.z.number(),
|
|
913
|
+
featured_media: zod.z.number(),
|
|
914
|
+
comment_status: zod.z.string(),
|
|
915
|
+
ping_status: zod.z.string(),
|
|
916
|
+
sticky: zod.z.boolean(),
|
|
917
|
+
template: zod.z.string(),
|
|
918
|
+
format: zod.z.string(),
|
|
919
|
+
meta: zod.z.any().optional(),
|
|
920
|
+
categories: zod.z.array(zod.z.number()),
|
|
921
|
+
tags: zod.z.array(zod.z.number()).optional(),
|
|
922
|
+
_links: HalLinksSchema.optional()
|
|
923
|
+
});
|
|
924
|
+
var PostsListSchema = zod.z.array(PostSchema);
|
|
925
|
+
paginationParamsSchema.extend({
|
|
926
|
+
context: zod.z.enum(["view", "embed", "edit"]).optional(),
|
|
927
|
+
search: zod.z.string().optional(),
|
|
928
|
+
after: zod.z.string().optional(),
|
|
929
|
+
before: zod.z.string().optional(),
|
|
930
|
+
author: zod.z.union([zod.z.number(), zod.z.array(zod.z.number())]).optional(),
|
|
931
|
+
author_exclude: zod.z.array(zod.z.number()).optional(),
|
|
932
|
+
exclude: zod.z.array(zod.z.number()).optional(),
|
|
933
|
+
include: zod.z.array(zod.z.number()).optional(),
|
|
934
|
+
categories: zod.z.union([zod.z.number(), zod.z.array(zod.z.number())]).optional(),
|
|
935
|
+
categories_exclude: zod.z.array(zod.z.number()).optional(),
|
|
936
|
+
tags: zod.z.union([zod.z.number(), zod.z.array(zod.z.number())]).optional(),
|
|
937
|
+
tags_exclude: zod.z.array(zod.z.number()).optional(),
|
|
938
|
+
sticky: zod.z.boolean().optional()
|
|
939
|
+
});
|
|
940
|
+
var EmbeddedPostSchema = zod.z.object({
|
|
941
|
+
id: zod.z.number(),
|
|
942
|
+
title: zod.z.string(),
|
|
943
|
+
content: zod.z.string(),
|
|
944
|
+
featured_image: zod.z.string().optional(),
|
|
945
|
+
published_date: zod.z.string(),
|
|
946
|
+
categories: zod.z.array(
|
|
947
|
+
zod.z.object({
|
|
948
|
+
id: zod.z.number(),
|
|
949
|
+
name: zod.z.string(),
|
|
950
|
+
slug: zod.z.string(),
|
|
951
|
+
taxonomy: zod.z.string().optional(),
|
|
952
|
+
description: zod.z.string().optional(),
|
|
953
|
+
parent: zod.z.number().optional(),
|
|
954
|
+
count: zod.z.number().optional()
|
|
955
|
+
})
|
|
956
|
+
).optional()
|
|
957
|
+
});
|
|
958
|
+
zod.z.array(EmbeddedPostSchema);
|
|
959
|
+
var AvatarUrlsSchema = zod.z.object({
|
|
960
|
+
"24": zod.z.string().optional(),
|
|
961
|
+
"48": zod.z.string().optional(),
|
|
962
|
+
"96": zod.z.string().optional()
|
|
963
|
+
});
|
|
964
|
+
var UserSchema = zod.z.object({
|
|
965
|
+
id: zod.z.number(),
|
|
966
|
+
username: zod.z.string().optional(),
|
|
967
|
+
// Only in edit context
|
|
968
|
+
name: zod.z.string(),
|
|
969
|
+
first_name: zod.z.string().optional(),
|
|
970
|
+
last_name: zod.z.string().optional(),
|
|
971
|
+
email: zod.z.string().optional(),
|
|
972
|
+
// Only for current user or admin
|
|
973
|
+
url: zod.z.string(),
|
|
974
|
+
description: zod.z.string(),
|
|
975
|
+
link: zod.z.string(),
|
|
976
|
+
locale: zod.z.string().optional(),
|
|
977
|
+
// Only for current user
|
|
978
|
+
nickname: zod.z.string().optional(),
|
|
979
|
+
// Only in edit context
|
|
980
|
+
slug: zod.z.string(),
|
|
981
|
+
registered_date: zod.z.string().optional(),
|
|
982
|
+
// Only in edit context
|
|
983
|
+
roles: zod.z.array(zod.z.string()).optional(),
|
|
984
|
+
// Only in edit context
|
|
985
|
+
capabilities: zod.z.record(zod.z.boolean()).optional(),
|
|
986
|
+
// Only in edit context
|
|
987
|
+
extra_capabilities: zod.z.record(zod.z.boolean()).optional(),
|
|
988
|
+
// Only in edit context
|
|
989
|
+
avatar_urls: AvatarUrlsSchema.optional(),
|
|
990
|
+
meta: zod.z.any().optional(),
|
|
991
|
+
_links: HalLinksSchema.optional()
|
|
992
|
+
});
|
|
993
|
+
zod.z.array(UserSchema);
|
|
994
|
+
var CurrentUserSchema = UserSchema.extend({
|
|
995
|
+
username: zod.z.string(),
|
|
996
|
+
email: zod.z.string(),
|
|
997
|
+
locale: zod.z.string(),
|
|
998
|
+
nickname: zod.z.string(),
|
|
999
|
+
registered_date: zod.z.string(),
|
|
1000
|
+
roles: zod.z.array(zod.z.string())
|
|
1001
|
+
});
|
|
1002
|
+
|
|
1003
|
+
// src/api/auth.ts
|
|
701
1004
|
var createAuthAPI = (axios2, options) => ({
|
|
702
1005
|
/**
|
|
703
1006
|
* Login with username/password and get JWT token
|
|
704
1007
|
*/
|
|
705
1008
|
async login(input) {
|
|
706
1009
|
const response = await axios2.post(ENDPOINTS.JWT_TOKEN, input);
|
|
707
|
-
return handleApiResponse(response,
|
|
1010
|
+
return handleApiResponse(response, JwtTokenResponseSchema, options);
|
|
708
1011
|
},
|
|
709
1012
|
/**
|
|
710
1013
|
* Validate current JWT token
|
|
@@ -720,45 +1023,51 @@ var createAuthAPI = (axios2, options) => ({
|
|
|
720
1023
|
}
|
|
721
1024
|
}
|
|
722
1025
|
});
|
|
1026
|
+
|
|
1027
|
+
// src/api/categories.ts
|
|
723
1028
|
var createCategoriesAPI = (axios2, options) => ({
|
|
724
1029
|
/**
|
|
725
1030
|
* Get list of categories with pagination
|
|
726
1031
|
*/
|
|
727
1032
|
async list(params) {
|
|
728
1033
|
const response = await axios2.get(ENDPOINTS.CATEGORIES, { params });
|
|
729
|
-
return handlePaginatedApiResponse(response,
|
|
1034
|
+
return handlePaginatedApiResponse(response, CategoriesListSchema, params, options);
|
|
730
1035
|
},
|
|
731
1036
|
/**
|
|
732
1037
|
* Get single category by ID
|
|
733
1038
|
*/
|
|
734
1039
|
async get(id) {
|
|
735
1040
|
const response = await axios2.get(ENDPOINTS.CATEGORY(id));
|
|
736
|
-
return handleApiResponse(response,
|
|
1041
|
+
return handleApiResponse(response, CategorySchema, options);
|
|
737
1042
|
}
|
|
738
1043
|
});
|
|
1044
|
+
|
|
1045
|
+
// src/api/media.ts
|
|
739
1046
|
var createMediaAPI = (axios2, options) => ({
|
|
740
1047
|
/**
|
|
741
1048
|
* Get single media item by ID
|
|
742
1049
|
*/
|
|
743
1050
|
async get(id) {
|
|
744
1051
|
const response = await axios2.get(ENDPOINTS.MEDIA_ITEM(id));
|
|
745
|
-
return handleApiResponse(response,
|
|
1052
|
+
return handleApiResponse(response, MediaSchema, options);
|
|
746
1053
|
}
|
|
747
1054
|
});
|
|
1055
|
+
|
|
1056
|
+
// src/api/posts.ts
|
|
748
1057
|
var createPostsAPI = (axios2, options) => ({
|
|
749
1058
|
/**
|
|
750
1059
|
* Get list of posts with pagination
|
|
751
1060
|
*/
|
|
752
1061
|
async list(params) {
|
|
753
1062
|
const response = await axios2.get(ENDPOINTS.POSTS, { params });
|
|
754
|
-
return handlePaginatedApiResponse(response,
|
|
1063
|
+
return handlePaginatedApiResponse(response, PostsListSchema, params, options);
|
|
755
1064
|
},
|
|
756
1065
|
/**
|
|
757
1066
|
* Get single post by ID
|
|
758
1067
|
*/
|
|
759
1068
|
async get(id) {
|
|
760
1069
|
const response = await axios2.get(ENDPOINTS.POST(id));
|
|
761
|
-
return handleApiResponse(response,
|
|
1070
|
+
return handleApiResponse(response, PostSchema, options);
|
|
762
1071
|
},
|
|
763
1072
|
/**
|
|
764
1073
|
* Get single post by slug
|
|
@@ -767,24 +1076,26 @@ var createPostsAPI = (axios2, options) => ({
|
|
|
767
1076
|
const response = await axios2.get(ENDPOINTS.POSTS, {
|
|
768
1077
|
params: { slug, per_page: 1 }
|
|
769
1078
|
});
|
|
770
|
-
const posts = handleApiResponse(response,
|
|
1079
|
+
const posts = handleApiResponse(response, PostsListSchema, options);
|
|
771
1080
|
return posts[0] || null;
|
|
772
1081
|
}
|
|
773
1082
|
});
|
|
1083
|
+
|
|
1084
|
+
// src/api/users.ts
|
|
774
1085
|
var createUsersAPI = (axios2, options) => ({
|
|
775
1086
|
/**
|
|
776
1087
|
* Get current authenticated user
|
|
777
1088
|
*/
|
|
778
1089
|
async me() {
|
|
779
1090
|
const response = await axios2.get(ENDPOINTS.USERS_ME);
|
|
780
|
-
return handleApiResponse(response,
|
|
1091
|
+
return handleApiResponse(response, CurrentUserSchema, options);
|
|
781
1092
|
},
|
|
782
1093
|
/**
|
|
783
1094
|
* Get user by ID
|
|
784
1095
|
*/
|
|
785
1096
|
async get(id) {
|
|
786
1097
|
const response = await axios2.get(ENDPOINTS.USER(id));
|
|
787
|
-
return handleApiResponse(response,
|
|
1098
|
+
return handleApiResponse(response, UserSchema, options);
|
|
788
1099
|
}
|
|
789
1100
|
});
|
|
790
1101
|
|