@atomic-solutions/wordpress-api-client 0.1.0 → 0.1.1

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.
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var axios = require('axios');
4
- var zod = require('zod');
4
+ var wordpress = require('@atomic-solutions/schemas/wordpress');
5
5
 
6
6
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
7
7
 
@@ -698,316 +698,13 @@ var setupErrorInterceptor = (axiosInstance, config, client) => {
698
698
  }
699
699
  );
700
700
  };
701
- var paginationParamsSchema = zod.z.object({
702
- /** Current page number */
703
- page: zod.z.number().int().positive().optional(),
704
- /** Items per page */
705
- per_page: zod.z.number().int().positive().max(100).optional(),
706
- /** Offset for pagination */
707
- offset: zod.z.number().int().nonnegative().optional(),
708
- /** Sort order */
709
- order: zod.z.enum(["asc", "desc"]).optional(),
710
- /** Field to sort by */
711
- orderby: zod.z.string().optional()
712
- });
713
- zod.z.object({
714
- /** Total number of items */
715
- total: zod.z.number(),
716
- /** Total number of pages */
717
- totalPages: zod.z.number(),
718
- /** Current page */
719
- currentPage: zod.z.number(),
720
- /** Items per page */
721
- perPage: zod.z.number()
722
- });
723
- zod.z.object({
724
- username: zod.z.string(),
725
- password: zod.z.string()
726
- });
727
- var JwtTokenResponseSchema = zod.z.object({
728
- token: zod.z.string(),
729
- user_email: zod.z.string(),
730
- user_nicename: zod.z.string(),
731
- user_display_name: zod.z.string()
732
- });
733
- zod.z.object({
734
- code: zod.z.string(),
735
- data: zod.z.object({
736
- status: zod.z.number()
737
- })
738
- });
739
- zod.z.object({
740
- code: zod.z.string(),
741
- message: zod.z.string(),
742
- data: zod.z.object({
743
- status: zod.z.number()
744
- }).optional()
745
- });
746
- var RenderedContentSchema = zod.z.object({
747
- rendered: zod.z.string(),
748
- protected: zod.z.boolean().optional()
749
- });
750
- var GuidSchema = zod.z.object({
751
- rendered: zod.z.string()
752
- });
753
- zod.z.enum([
754
- "publish",
755
- "future",
756
- "draft",
757
- "pending",
758
- "private",
759
- "trash",
760
- "auto-draft",
761
- "inherit"
762
- ]);
763
- var HalLinkItemSchema = zod.z.object({
764
- href: zod.z.string(),
765
- embeddable: zod.z.boolean().optional(),
766
- templated: zod.z.boolean().optional()
767
- });
768
- var HalLinksSchema = zod.z.object({
769
- self: zod.z.array(HalLinkItemSchema).optional(),
770
- collection: zod.z.array(HalLinkItemSchema).optional(),
771
- about: zod.z.array(HalLinkItemSchema).optional(),
772
- author: zod.z.array(HalLinkItemSchema).optional(),
773
- replies: zod.z.array(HalLinkItemSchema).optional(),
774
- "wp:featuredmedia": zod.z.array(HalLinkItemSchema).optional(),
775
- "wp:attachment": zod.z.array(HalLinkItemSchema).optional(),
776
- "wp:term": zod.z.array(HalLinkItemSchema).optional(),
777
- "wp:post_type": zod.z.array(HalLinkItemSchema).optional(),
778
- curies: zod.z.array(
779
- zod.z.object({
780
- name: zod.z.string(),
781
- href: zod.z.string(),
782
- templated: zod.z.boolean()
783
- })
784
- ).optional()
785
- }).passthrough();
786
- zod.z.object({
787
- id: zod.z.number(),
788
- date: zod.z.string(),
789
- date_gmt: zod.z.string(),
790
- modified: zod.z.string(),
791
- modified_gmt: zod.z.string(),
792
- slug: zod.z.string(),
793
- status: zod.z.string(),
794
- type: zod.z.string(),
795
- link: zod.z.string(),
796
- _links: HalLinksSchema.optional()
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
1004
701
  var createAuthAPI = (axios2, options) => ({
1005
702
  /**
1006
703
  * Login with username/password and get JWT token
1007
704
  */
1008
705
  async login(input) {
1009
706
  const response = await axios2.post(ENDPOINTS.JWT_TOKEN, input);
1010
- return handleApiResponse(response, JwtTokenResponseSchema, options);
707
+ return handleApiResponse(response, wordpress.JwtTokenResponseSchema, options);
1011
708
  },
1012
709
  /**
1013
710
  * Validate current JWT token
@@ -1023,51 +720,45 @@ var createAuthAPI = (axios2, options) => ({
1023
720
  }
1024
721
  }
1025
722
  });
1026
-
1027
- // src/api/categories.ts
1028
723
  var createCategoriesAPI = (axios2, options) => ({
1029
724
  /**
1030
725
  * Get list of categories with pagination
1031
726
  */
1032
727
  async list(params) {
1033
728
  const response = await axios2.get(ENDPOINTS.CATEGORIES, { params });
1034
- return handlePaginatedApiResponse(response, CategoriesListSchema, params, options);
729
+ return handlePaginatedApiResponse(response, wordpress.CategoriesListSchema, params, options);
1035
730
  },
1036
731
  /**
1037
732
  * Get single category by ID
1038
733
  */
1039
734
  async get(id) {
1040
735
  const response = await axios2.get(ENDPOINTS.CATEGORY(id));
1041
- return handleApiResponse(response, CategorySchema, options);
736
+ return handleApiResponse(response, wordpress.CategorySchema, options);
1042
737
  }
1043
738
  });
1044
-
1045
- // src/api/media.ts
1046
739
  var createMediaAPI = (axios2, options) => ({
1047
740
  /**
1048
741
  * Get single media item by ID
1049
742
  */
1050
743
  async get(id) {
1051
744
  const response = await axios2.get(ENDPOINTS.MEDIA_ITEM(id));
1052
- return handleApiResponse(response, MediaSchema, options);
745
+ return handleApiResponse(response, wordpress.MediaSchema, options);
1053
746
  }
1054
747
  });
1055
-
1056
- // src/api/posts.ts
1057
748
  var createPostsAPI = (axios2, options) => ({
1058
749
  /**
1059
750
  * Get list of posts with pagination
1060
751
  */
1061
752
  async list(params) {
1062
753
  const response = await axios2.get(ENDPOINTS.POSTS, { params });
1063
- return handlePaginatedApiResponse(response, PostsListSchema, params, options);
754
+ return handlePaginatedApiResponse(response, wordpress.PostsListSchema, params, options);
1064
755
  },
1065
756
  /**
1066
757
  * Get single post by ID
1067
758
  */
1068
759
  async get(id) {
1069
760
  const response = await axios2.get(ENDPOINTS.POST(id));
1070
- return handleApiResponse(response, PostSchema, options);
761
+ return handleApiResponse(response, wordpress.PostSchema, options);
1071
762
  },
1072
763
  /**
1073
764
  * Get single post by slug
@@ -1076,26 +767,24 @@ var createPostsAPI = (axios2, options) => ({
1076
767
  const response = await axios2.get(ENDPOINTS.POSTS, {
1077
768
  params: { slug, per_page: 1 }
1078
769
  });
1079
- const posts = handleApiResponse(response, PostsListSchema, options);
770
+ const posts = handleApiResponse(response, wordpress.PostsListSchema, options);
1080
771
  return posts[0] || null;
1081
772
  }
1082
773
  });
1083
-
1084
- // src/api/users.ts
1085
774
  var createUsersAPI = (axios2, options) => ({
1086
775
  /**
1087
776
  * Get current authenticated user
1088
777
  */
1089
778
  async me() {
1090
779
  const response = await axios2.get(ENDPOINTS.USERS_ME);
1091
- return handleApiResponse(response, CurrentUserSchema, options);
780
+ return handleApiResponse(response, wordpress.CurrentUserSchema, options);
1092
781
  },
1093
782
  /**
1094
783
  * Get user by ID
1095
784
  */
1096
785
  async get(id) {
1097
786
  const response = await axios2.get(ENDPOINTS.USER(id));
1098
- return handleApiResponse(response, UserSchema, options);
787
+ return handleApiResponse(response, wordpress.UserSchema, options);
1099
788
  }
1100
789
  });
1101
790