@back23/promptly-sdk 1.1.0 → 1.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/dist/index.d.mts +66 -34
- package/dist/index.d.ts +66 -34
- package/dist/index.js +88 -21
- package/dist/index.mjs +88 -21
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -13,6 +13,31 @@ interface ApiResponse<T> {
|
|
|
13
13
|
data: T;
|
|
14
14
|
message?: string;
|
|
15
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Pagination metadata
|
|
18
|
+
*/
|
|
19
|
+
interface PaginationMeta {
|
|
20
|
+
current_page: number;
|
|
21
|
+
last_page: number;
|
|
22
|
+
per_page: number;
|
|
23
|
+
total: number;
|
|
24
|
+
from: number | null;
|
|
25
|
+
to: number | null;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Unified list response - ALWAYS returns this structure for list APIs
|
|
29
|
+
* - data is ALWAYS an array (never null/undefined)
|
|
30
|
+
* - meta contains pagination info
|
|
31
|
+
*/
|
|
32
|
+
interface ListResponse<T> {
|
|
33
|
+
/** Array of items - guaranteed to be an array (empty if no data) */
|
|
34
|
+
data: T[];
|
|
35
|
+
/** Pagination metadata */
|
|
36
|
+
meta: PaginationMeta;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* @deprecated Use ListResponse<T> instead. Kept for backward compatibility.
|
|
40
|
+
*/
|
|
16
41
|
interface PaginatedResponse<T> {
|
|
17
42
|
data: T[];
|
|
18
43
|
meta: {
|
|
@@ -644,6 +669,11 @@ declare class HttpClient {
|
|
|
644
669
|
* GET request
|
|
645
670
|
*/
|
|
646
671
|
get<T>(endpoint: string, params?: Record<string, any>): Promise<T>;
|
|
672
|
+
/**
|
|
673
|
+
* GET request for list endpoints - ALWAYS returns normalized ListResponse
|
|
674
|
+
* Guarantees: data is always an array, meta is always present
|
|
675
|
+
*/
|
|
676
|
+
getList<T>(endpoint: string, params?: Record<string, any>): Promise<ListResponse<T>>;
|
|
647
677
|
/**
|
|
648
678
|
* POST request
|
|
649
679
|
*/
|
|
@@ -740,16 +770,18 @@ declare class BoardsResource {
|
|
|
740
770
|
constructor(http: HttpClient);
|
|
741
771
|
/**
|
|
742
772
|
* List all boards
|
|
773
|
+
* @returns ListResponse with data array (always defined) and pagination meta
|
|
743
774
|
*/
|
|
744
|
-
list(params?: BoardListParams): Promise<Board
|
|
775
|
+
list(params?: BoardListParams): Promise<ListResponse<Board>>;
|
|
745
776
|
/**
|
|
746
777
|
* Get board by ID or slug
|
|
747
778
|
*/
|
|
748
779
|
get(idOrSlug: number | string): Promise<Board>;
|
|
749
780
|
/**
|
|
750
781
|
* List posts in a board
|
|
782
|
+
* @returns ListResponse with data array and pagination meta
|
|
751
783
|
*/
|
|
752
|
-
listPosts(boardIdOrSlug: number | string, params?: PostListParams): Promise<
|
|
784
|
+
listPosts(boardIdOrSlug: number | string, params?: PostListParams): Promise<ListResponse<BoardPost>>;
|
|
753
785
|
/**
|
|
754
786
|
* Get post by ID
|
|
755
787
|
*/
|
|
@@ -768,6 +800,7 @@ declare class BoardsResource {
|
|
|
768
800
|
deletePost(postId: number): Promise<void>;
|
|
769
801
|
/**
|
|
770
802
|
* List comments for a post
|
|
803
|
+
* @returns Array of comments (always an array, never null/undefined)
|
|
771
804
|
*/
|
|
772
805
|
listComments(postId: number): Promise<BoardComment[]>;
|
|
773
806
|
/**
|
|
@@ -793,8 +826,9 @@ declare class BlogResource {
|
|
|
793
826
|
constructor(http: HttpClient);
|
|
794
827
|
/**
|
|
795
828
|
* List blog posts
|
|
829
|
+
* @returns ListResponse with data array (always defined) and pagination meta
|
|
796
830
|
*/
|
|
797
|
-
list(params?: BlogListParams): Promise<
|
|
831
|
+
list(params?: BlogListParams): Promise<ListResponse<BlogPost>>;
|
|
798
832
|
/**
|
|
799
833
|
* Get blog post by slug
|
|
800
834
|
*/
|
|
@@ -805,26 +839,32 @@ declare class BlogResource {
|
|
|
805
839
|
getById(id: number): Promise<BlogPost>;
|
|
806
840
|
/**
|
|
807
841
|
* Get featured blog posts
|
|
842
|
+
* @returns Array of featured posts (always an array, never null/undefined)
|
|
808
843
|
*/
|
|
809
844
|
featured(limit?: number): Promise<BlogPost[]>;
|
|
810
845
|
/**
|
|
811
846
|
* Get blog posts by category
|
|
847
|
+
* @returns ListResponse with data array and pagination meta
|
|
812
848
|
*/
|
|
813
|
-
byCategory(category: string, params?: Omit<BlogListParams, 'category'>): Promise<
|
|
849
|
+
byCategory(category: string, params?: Omit<BlogListParams, 'category'>): Promise<ListResponse<BlogPost>>;
|
|
814
850
|
/**
|
|
815
851
|
* Get blog posts by tag
|
|
852
|
+
* @returns ListResponse with data array and pagination meta
|
|
816
853
|
*/
|
|
817
|
-
byTag(tag: string, params?: Omit<BlogListParams, 'tag'>): Promise<
|
|
854
|
+
byTag(tag: string, params?: Omit<BlogListParams, 'tag'>): Promise<ListResponse<BlogPost>>;
|
|
818
855
|
/**
|
|
819
856
|
* Search blog posts
|
|
857
|
+
* @returns ListResponse with data array and pagination meta
|
|
820
858
|
*/
|
|
821
|
-
search(query: string, params?: Omit<BlogListParams, 'search'>): Promise<
|
|
859
|
+
search(query: string, params?: Omit<BlogListParams, 'search'>): Promise<ListResponse<BlogPost>>;
|
|
822
860
|
/**
|
|
823
861
|
* Get blog categories
|
|
862
|
+
* @returns Array of category names (always an array)
|
|
824
863
|
*/
|
|
825
864
|
categories(): Promise<string[]>;
|
|
826
865
|
/**
|
|
827
866
|
* Get blog tags
|
|
867
|
+
* @returns Array of tag names (always an array)
|
|
828
868
|
*/
|
|
829
869
|
tags(): Promise<string[]>;
|
|
830
870
|
}
|
|
@@ -838,8 +878,9 @@ declare class FormsResource {
|
|
|
838
878
|
constructor(http: HttpClient);
|
|
839
879
|
/**
|
|
840
880
|
* List all forms
|
|
881
|
+
* @returns ListResponse with data array and pagination meta
|
|
841
882
|
*/
|
|
842
|
-
list(params?: FormListParams): Promise<Form
|
|
883
|
+
list(params?: FormListParams): Promise<ListResponse<Form>>;
|
|
843
884
|
/**
|
|
844
885
|
* Get form by ID or slug
|
|
845
886
|
*/
|
|
@@ -850,8 +891,9 @@ declare class FormsResource {
|
|
|
850
891
|
submit(formIdOrSlug: number | string, data: SubmitFormData): Promise<FormSubmission>;
|
|
851
892
|
/**
|
|
852
893
|
* Get my form submissions
|
|
894
|
+
* @returns ListResponse with data array and pagination meta
|
|
853
895
|
*/
|
|
854
|
-
mySubmissions(params?: SubmissionListParams): Promise<
|
|
896
|
+
mySubmissions(params?: SubmissionListParams): Promise<ListResponse<FormSubmission>>;
|
|
855
897
|
/**
|
|
856
898
|
* Get specific submission
|
|
857
899
|
*/
|
|
@@ -867,22 +909,26 @@ declare class ShopResource {
|
|
|
867
909
|
constructor(http: HttpClient);
|
|
868
910
|
/**
|
|
869
911
|
* List products
|
|
912
|
+
* @returns ListResponse with data array and pagination meta
|
|
870
913
|
*/
|
|
871
|
-
listProducts(params?: ProductListParams): Promise<
|
|
914
|
+
listProducts(params?: ProductListParams): Promise<ListResponse<Product>>;
|
|
872
915
|
/**
|
|
873
916
|
* Get product by ID or slug
|
|
874
917
|
*/
|
|
875
918
|
getProduct(idOrSlug: number | string): Promise<Product>;
|
|
876
919
|
/**
|
|
877
920
|
* Get featured products
|
|
921
|
+
* @returns Array of featured products (always an array)
|
|
878
922
|
*/
|
|
879
923
|
featuredProducts(limit?: number): Promise<Product[]>;
|
|
880
924
|
/**
|
|
881
925
|
* Search products
|
|
926
|
+
* @returns ListResponse with data array and pagination meta
|
|
882
927
|
*/
|
|
883
|
-
searchProducts(query: string, params?: Omit<ProductListParams, 'search'>): Promise<
|
|
928
|
+
searchProducts(query: string, params?: Omit<ProductListParams, 'search'>): Promise<ListResponse<Product>>;
|
|
884
929
|
/**
|
|
885
930
|
* List product categories
|
|
931
|
+
* @returns Array of categories (always an array)
|
|
886
932
|
*/
|
|
887
933
|
listCategories(): Promise<ProductCategory[]>;
|
|
888
934
|
/**
|
|
@@ -891,8 +937,9 @@ declare class ShopResource {
|
|
|
891
937
|
getCategory(idOrSlug: number | string): Promise<ProductCategory>;
|
|
892
938
|
/**
|
|
893
939
|
* Get products in category
|
|
940
|
+
* @returns ListResponse with data array and pagination meta
|
|
894
941
|
*/
|
|
895
|
-
categoryProducts(categoryIdOrSlug: number | string, params?: Omit<ProductListParams, 'category'>): Promise<
|
|
942
|
+
categoryProducts(categoryIdOrSlug: number | string, params?: Omit<ProductListParams, 'category'>): Promise<ListResponse<Product>>;
|
|
896
943
|
/**
|
|
897
944
|
* Get current cart
|
|
898
945
|
*/
|
|
@@ -915,8 +962,9 @@ declare class ShopResource {
|
|
|
915
962
|
clearCart(): Promise<void>;
|
|
916
963
|
/**
|
|
917
964
|
* List my orders
|
|
965
|
+
* @returns ListResponse with data array and pagination meta
|
|
918
966
|
*/
|
|
919
|
-
listOrders(params?: OrderListParams): Promise<
|
|
967
|
+
listOrders(params?: OrderListParams): Promise<ListResponse<Order>>;
|
|
920
968
|
/**
|
|
921
969
|
* Get order by ID or order number
|
|
922
970
|
*/
|
|
@@ -954,6 +1002,7 @@ declare class ShopResource {
|
|
|
954
1002
|
validateCoupon(code: string, orderAmount: number): Promise<CouponValidation>;
|
|
955
1003
|
/**
|
|
956
1004
|
* Get available coupons for current user
|
|
1005
|
+
* @returns Array of coupons (always an array)
|
|
957
1006
|
*/
|
|
958
1007
|
myCoupons(): Promise<Coupon[]>;
|
|
959
1008
|
}
|
|
@@ -990,19 +1039,12 @@ declare class MediaResource {
|
|
|
990
1039
|
delete(mediaId: number): Promise<void>;
|
|
991
1040
|
}
|
|
992
1041
|
|
|
993
|
-
/**
|
|
994
|
-
* Custom Entities Resource for Promptly SDK
|
|
995
|
-
*
|
|
996
|
-
* Provides access to dynamically created data structures.
|
|
997
|
-
* AI can create custom entities through MCP, and this SDK allows
|
|
998
|
-
* frontend applications to interact with them.
|
|
999
|
-
*/
|
|
1000
|
-
|
|
1001
1042
|
declare class EntitiesResource {
|
|
1002
1043
|
private http;
|
|
1003
1044
|
constructor(http: HttpClient);
|
|
1004
1045
|
/**
|
|
1005
1046
|
* List all active custom entities
|
|
1047
|
+
* @returns Array of entities (always an array)
|
|
1006
1048
|
*
|
|
1007
1049
|
* @example
|
|
1008
1050
|
* ```typescript
|
|
@@ -1023,6 +1065,7 @@ declare class EntitiesResource {
|
|
|
1023
1065
|
getSchema(slug: string): Promise<EntitySchema>;
|
|
1024
1066
|
/**
|
|
1025
1067
|
* List records for an entity
|
|
1068
|
+
* @returns ListResponse with data array and pagination meta
|
|
1026
1069
|
*
|
|
1027
1070
|
* @example
|
|
1028
1071
|
* ```typescript
|
|
@@ -1042,7 +1085,7 @@ declare class EntitiesResource {
|
|
|
1042
1085
|
* });
|
|
1043
1086
|
* ```
|
|
1044
1087
|
*/
|
|
1045
|
-
listRecords(slug: string, params?: EntityListParams): Promise<
|
|
1088
|
+
listRecords(slug: string, params?: EntityListParams): Promise<ListResponse<EntityRecord>>;
|
|
1046
1089
|
/**
|
|
1047
1090
|
* Get a single record by ID
|
|
1048
1091
|
*
|
|
@@ -1123,18 +1166,7 @@ declare class EntitiesResource {
|
|
|
1123
1166
|
data: Array<Omit<EntityRecord, "data"> & {
|
|
1124
1167
|
data: T;
|
|
1125
1168
|
}>;
|
|
1126
|
-
meta:
|
|
1127
|
-
current_page: number;
|
|
1128
|
-
last_page: number;
|
|
1129
|
-
per_page: number;
|
|
1130
|
-
total: number;
|
|
1131
|
-
};
|
|
1132
|
-
links?: {
|
|
1133
|
-
first: string;
|
|
1134
|
-
last: string;
|
|
1135
|
-
prev: string | null;
|
|
1136
|
-
next: string | null;
|
|
1137
|
-
};
|
|
1169
|
+
meta: PaginationMeta;
|
|
1138
1170
|
}>;
|
|
1139
1171
|
get: (id: number) => Promise<Omit<EntityRecord, "data"> & {
|
|
1140
1172
|
data: T;
|
|
@@ -1218,4 +1250,4 @@ declare class Promptly {
|
|
|
1218
1250
|
getToken(): string | null;
|
|
1219
1251
|
}
|
|
1220
1252
|
|
|
1221
|
-
export { type AddToCartData, type ApiError, type ApiResponse, type ApplyCouponData, type AuthResponse, type BlogListParams, type BlogPost, type Board, type BoardComment, type BoardListParams, type BoardPost, type BoardSettings, type Cart, type CartItem, type Coupon, type CouponType, type CouponValidation, type CreateCommentData, type CreateEntityRecordData, type CreateOrderData, type CreatePostData, type CustomEntity, type EntityField, type EntityListParams, type EntityRecord, type EntitySchema, type ForgotPasswordData, type Form, type FormField, type FormFieldOption, type FormFieldType, type FormFieldValidation, type FormListParams, type FormSettings, type FormSubmission, type ListParams, type LoginCredentials, type Media, type Member, type Order, type OrderItem, type OrderListParams, type OrderStatus, type PaginatedResponse, type Payment, type PaymentCancelData, type PaymentConfirmData, type PaymentMethod, type PaymentReadyData, type PaymentStatus, type PostListParams, type Product, type ProductCategory, type ProductListParams, type ProductOption, type ProductOptionValue, type ProductStatus, type ProductVariant, Promptly, type PromptlyConfig, PromptlyError, type RegisterData, type ResetPasswordData, type SocialAuthUrl, type SocialProvider, type SubmissionListParams, type SubmitFormData, type UpdateCartItemData, type UpdateCommentData, type UpdateEntityRecordData, type UpdatePostData, type UpdateProfileData, Promptly as default };
|
|
1253
|
+
export { type AddToCartData, type ApiError, type ApiResponse, type ApplyCouponData, type AuthResponse, type BlogListParams, type BlogPost, type Board, type BoardComment, type BoardListParams, type BoardPost, type BoardSettings, type Cart, type CartItem, type Coupon, type CouponType, type CouponValidation, type CreateCommentData, type CreateEntityRecordData, type CreateOrderData, type CreatePostData, type CustomEntity, type EntityField, type EntityListParams, type EntityRecord, type EntitySchema, type ForgotPasswordData, type Form, type FormField, type FormFieldOption, type FormFieldType, type FormFieldValidation, type FormListParams, type FormSettings, type FormSubmission, type ListParams, type ListResponse, type LoginCredentials, type Media, type Member, type Order, type OrderItem, type OrderListParams, type OrderStatus, type PaginatedResponse, type PaginationMeta, type Payment, type PaymentCancelData, type PaymentConfirmData, type PaymentMethod, type PaymentReadyData, type PaymentStatus, type PostListParams, type Product, type ProductCategory, type ProductListParams, type ProductOption, type ProductOptionValue, type ProductStatus, type ProductVariant, Promptly, type PromptlyConfig, PromptlyError, type RegisterData, type ResetPasswordData, type SocialAuthUrl, type SocialProvider, type SubmissionListParams, type SubmitFormData, type UpdateCartItemData, type UpdateCommentData, type UpdateEntityRecordData, type UpdatePostData, type UpdateProfileData, Promptly as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -13,6 +13,31 @@ interface ApiResponse<T> {
|
|
|
13
13
|
data: T;
|
|
14
14
|
message?: string;
|
|
15
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Pagination metadata
|
|
18
|
+
*/
|
|
19
|
+
interface PaginationMeta {
|
|
20
|
+
current_page: number;
|
|
21
|
+
last_page: number;
|
|
22
|
+
per_page: number;
|
|
23
|
+
total: number;
|
|
24
|
+
from: number | null;
|
|
25
|
+
to: number | null;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Unified list response - ALWAYS returns this structure for list APIs
|
|
29
|
+
* - data is ALWAYS an array (never null/undefined)
|
|
30
|
+
* - meta contains pagination info
|
|
31
|
+
*/
|
|
32
|
+
interface ListResponse<T> {
|
|
33
|
+
/** Array of items - guaranteed to be an array (empty if no data) */
|
|
34
|
+
data: T[];
|
|
35
|
+
/** Pagination metadata */
|
|
36
|
+
meta: PaginationMeta;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* @deprecated Use ListResponse<T> instead. Kept for backward compatibility.
|
|
40
|
+
*/
|
|
16
41
|
interface PaginatedResponse<T> {
|
|
17
42
|
data: T[];
|
|
18
43
|
meta: {
|
|
@@ -644,6 +669,11 @@ declare class HttpClient {
|
|
|
644
669
|
* GET request
|
|
645
670
|
*/
|
|
646
671
|
get<T>(endpoint: string, params?: Record<string, any>): Promise<T>;
|
|
672
|
+
/**
|
|
673
|
+
* GET request for list endpoints - ALWAYS returns normalized ListResponse
|
|
674
|
+
* Guarantees: data is always an array, meta is always present
|
|
675
|
+
*/
|
|
676
|
+
getList<T>(endpoint: string, params?: Record<string, any>): Promise<ListResponse<T>>;
|
|
647
677
|
/**
|
|
648
678
|
* POST request
|
|
649
679
|
*/
|
|
@@ -740,16 +770,18 @@ declare class BoardsResource {
|
|
|
740
770
|
constructor(http: HttpClient);
|
|
741
771
|
/**
|
|
742
772
|
* List all boards
|
|
773
|
+
* @returns ListResponse with data array (always defined) and pagination meta
|
|
743
774
|
*/
|
|
744
|
-
list(params?: BoardListParams): Promise<Board
|
|
775
|
+
list(params?: BoardListParams): Promise<ListResponse<Board>>;
|
|
745
776
|
/**
|
|
746
777
|
* Get board by ID or slug
|
|
747
778
|
*/
|
|
748
779
|
get(idOrSlug: number | string): Promise<Board>;
|
|
749
780
|
/**
|
|
750
781
|
* List posts in a board
|
|
782
|
+
* @returns ListResponse with data array and pagination meta
|
|
751
783
|
*/
|
|
752
|
-
listPosts(boardIdOrSlug: number | string, params?: PostListParams): Promise<
|
|
784
|
+
listPosts(boardIdOrSlug: number | string, params?: PostListParams): Promise<ListResponse<BoardPost>>;
|
|
753
785
|
/**
|
|
754
786
|
* Get post by ID
|
|
755
787
|
*/
|
|
@@ -768,6 +800,7 @@ declare class BoardsResource {
|
|
|
768
800
|
deletePost(postId: number): Promise<void>;
|
|
769
801
|
/**
|
|
770
802
|
* List comments for a post
|
|
803
|
+
* @returns Array of comments (always an array, never null/undefined)
|
|
771
804
|
*/
|
|
772
805
|
listComments(postId: number): Promise<BoardComment[]>;
|
|
773
806
|
/**
|
|
@@ -793,8 +826,9 @@ declare class BlogResource {
|
|
|
793
826
|
constructor(http: HttpClient);
|
|
794
827
|
/**
|
|
795
828
|
* List blog posts
|
|
829
|
+
* @returns ListResponse with data array (always defined) and pagination meta
|
|
796
830
|
*/
|
|
797
|
-
list(params?: BlogListParams): Promise<
|
|
831
|
+
list(params?: BlogListParams): Promise<ListResponse<BlogPost>>;
|
|
798
832
|
/**
|
|
799
833
|
* Get blog post by slug
|
|
800
834
|
*/
|
|
@@ -805,26 +839,32 @@ declare class BlogResource {
|
|
|
805
839
|
getById(id: number): Promise<BlogPost>;
|
|
806
840
|
/**
|
|
807
841
|
* Get featured blog posts
|
|
842
|
+
* @returns Array of featured posts (always an array, never null/undefined)
|
|
808
843
|
*/
|
|
809
844
|
featured(limit?: number): Promise<BlogPost[]>;
|
|
810
845
|
/**
|
|
811
846
|
* Get blog posts by category
|
|
847
|
+
* @returns ListResponse with data array and pagination meta
|
|
812
848
|
*/
|
|
813
|
-
byCategory(category: string, params?: Omit<BlogListParams, 'category'>): Promise<
|
|
849
|
+
byCategory(category: string, params?: Omit<BlogListParams, 'category'>): Promise<ListResponse<BlogPost>>;
|
|
814
850
|
/**
|
|
815
851
|
* Get blog posts by tag
|
|
852
|
+
* @returns ListResponse with data array and pagination meta
|
|
816
853
|
*/
|
|
817
|
-
byTag(tag: string, params?: Omit<BlogListParams, 'tag'>): Promise<
|
|
854
|
+
byTag(tag: string, params?: Omit<BlogListParams, 'tag'>): Promise<ListResponse<BlogPost>>;
|
|
818
855
|
/**
|
|
819
856
|
* Search blog posts
|
|
857
|
+
* @returns ListResponse with data array and pagination meta
|
|
820
858
|
*/
|
|
821
|
-
search(query: string, params?: Omit<BlogListParams, 'search'>): Promise<
|
|
859
|
+
search(query: string, params?: Omit<BlogListParams, 'search'>): Promise<ListResponse<BlogPost>>;
|
|
822
860
|
/**
|
|
823
861
|
* Get blog categories
|
|
862
|
+
* @returns Array of category names (always an array)
|
|
824
863
|
*/
|
|
825
864
|
categories(): Promise<string[]>;
|
|
826
865
|
/**
|
|
827
866
|
* Get blog tags
|
|
867
|
+
* @returns Array of tag names (always an array)
|
|
828
868
|
*/
|
|
829
869
|
tags(): Promise<string[]>;
|
|
830
870
|
}
|
|
@@ -838,8 +878,9 @@ declare class FormsResource {
|
|
|
838
878
|
constructor(http: HttpClient);
|
|
839
879
|
/**
|
|
840
880
|
* List all forms
|
|
881
|
+
* @returns ListResponse with data array and pagination meta
|
|
841
882
|
*/
|
|
842
|
-
list(params?: FormListParams): Promise<Form
|
|
883
|
+
list(params?: FormListParams): Promise<ListResponse<Form>>;
|
|
843
884
|
/**
|
|
844
885
|
* Get form by ID or slug
|
|
845
886
|
*/
|
|
@@ -850,8 +891,9 @@ declare class FormsResource {
|
|
|
850
891
|
submit(formIdOrSlug: number | string, data: SubmitFormData): Promise<FormSubmission>;
|
|
851
892
|
/**
|
|
852
893
|
* Get my form submissions
|
|
894
|
+
* @returns ListResponse with data array and pagination meta
|
|
853
895
|
*/
|
|
854
|
-
mySubmissions(params?: SubmissionListParams): Promise<
|
|
896
|
+
mySubmissions(params?: SubmissionListParams): Promise<ListResponse<FormSubmission>>;
|
|
855
897
|
/**
|
|
856
898
|
* Get specific submission
|
|
857
899
|
*/
|
|
@@ -867,22 +909,26 @@ declare class ShopResource {
|
|
|
867
909
|
constructor(http: HttpClient);
|
|
868
910
|
/**
|
|
869
911
|
* List products
|
|
912
|
+
* @returns ListResponse with data array and pagination meta
|
|
870
913
|
*/
|
|
871
|
-
listProducts(params?: ProductListParams): Promise<
|
|
914
|
+
listProducts(params?: ProductListParams): Promise<ListResponse<Product>>;
|
|
872
915
|
/**
|
|
873
916
|
* Get product by ID or slug
|
|
874
917
|
*/
|
|
875
918
|
getProduct(idOrSlug: number | string): Promise<Product>;
|
|
876
919
|
/**
|
|
877
920
|
* Get featured products
|
|
921
|
+
* @returns Array of featured products (always an array)
|
|
878
922
|
*/
|
|
879
923
|
featuredProducts(limit?: number): Promise<Product[]>;
|
|
880
924
|
/**
|
|
881
925
|
* Search products
|
|
926
|
+
* @returns ListResponse with data array and pagination meta
|
|
882
927
|
*/
|
|
883
|
-
searchProducts(query: string, params?: Omit<ProductListParams, 'search'>): Promise<
|
|
928
|
+
searchProducts(query: string, params?: Omit<ProductListParams, 'search'>): Promise<ListResponse<Product>>;
|
|
884
929
|
/**
|
|
885
930
|
* List product categories
|
|
931
|
+
* @returns Array of categories (always an array)
|
|
886
932
|
*/
|
|
887
933
|
listCategories(): Promise<ProductCategory[]>;
|
|
888
934
|
/**
|
|
@@ -891,8 +937,9 @@ declare class ShopResource {
|
|
|
891
937
|
getCategory(idOrSlug: number | string): Promise<ProductCategory>;
|
|
892
938
|
/**
|
|
893
939
|
* Get products in category
|
|
940
|
+
* @returns ListResponse with data array and pagination meta
|
|
894
941
|
*/
|
|
895
|
-
categoryProducts(categoryIdOrSlug: number | string, params?: Omit<ProductListParams, 'category'>): Promise<
|
|
942
|
+
categoryProducts(categoryIdOrSlug: number | string, params?: Omit<ProductListParams, 'category'>): Promise<ListResponse<Product>>;
|
|
896
943
|
/**
|
|
897
944
|
* Get current cart
|
|
898
945
|
*/
|
|
@@ -915,8 +962,9 @@ declare class ShopResource {
|
|
|
915
962
|
clearCart(): Promise<void>;
|
|
916
963
|
/**
|
|
917
964
|
* List my orders
|
|
965
|
+
* @returns ListResponse with data array and pagination meta
|
|
918
966
|
*/
|
|
919
|
-
listOrders(params?: OrderListParams): Promise<
|
|
967
|
+
listOrders(params?: OrderListParams): Promise<ListResponse<Order>>;
|
|
920
968
|
/**
|
|
921
969
|
* Get order by ID or order number
|
|
922
970
|
*/
|
|
@@ -954,6 +1002,7 @@ declare class ShopResource {
|
|
|
954
1002
|
validateCoupon(code: string, orderAmount: number): Promise<CouponValidation>;
|
|
955
1003
|
/**
|
|
956
1004
|
* Get available coupons for current user
|
|
1005
|
+
* @returns Array of coupons (always an array)
|
|
957
1006
|
*/
|
|
958
1007
|
myCoupons(): Promise<Coupon[]>;
|
|
959
1008
|
}
|
|
@@ -990,19 +1039,12 @@ declare class MediaResource {
|
|
|
990
1039
|
delete(mediaId: number): Promise<void>;
|
|
991
1040
|
}
|
|
992
1041
|
|
|
993
|
-
/**
|
|
994
|
-
* Custom Entities Resource for Promptly SDK
|
|
995
|
-
*
|
|
996
|
-
* Provides access to dynamically created data structures.
|
|
997
|
-
* AI can create custom entities through MCP, and this SDK allows
|
|
998
|
-
* frontend applications to interact with them.
|
|
999
|
-
*/
|
|
1000
|
-
|
|
1001
1042
|
declare class EntitiesResource {
|
|
1002
1043
|
private http;
|
|
1003
1044
|
constructor(http: HttpClient);
|
|
1004
1045
|
/**
|
|
1005
1046
|
* List all active custom entities
|
|
1047
|
+
* @returns Array of entities (always an array)
|
|
1006
1048
|
*
|
|
1007
1049
|
* @example
|
|
1008
1050
|
* ```typescript
|
|
@@ -1023,6 +1065,7 @@ declare class EntitiesResource {
|
|
|
1023
1065
|
getSchema(slug: string): Promise<EntitySchema>;
|
|
1024
1066
|
/**
|
|
1025
1067
|
* List records for an entity
|
|
1068
|
+
* @returns ListResponse with data array and pagination meta
|
|
1026
1069
|
*
|
|
1027
1070
|
* @example
|
|
1028
1071
|
* ```typescript
|
|
@@ -1042,7 +1085,7 @@ declare class EntitiesResource {
|
|
|
1042
1085
|
* });
|
|
1043
1086
|
* ```
|
|
1044
1087
|
*/
|
|
1045
|
-
listRecords(slug: string, params?: EntityListParams): Promise<
|
|
1088
|
+
listRecords(slug: string, params?: EntityListParams): Promise<ListResponse<EntityRecord>>;
|
|
1046
1089
|
/**
|
|
1047
1090
|
* Get a single record by ID
|
|
1048
1091
|
*
|
|
@@ -1123,18 +1166,7 @@ declare class EntitiesResource {
|
|
|
1123
1166
|
data: Array<Omit<EntityRecord, "data"> & {
|
|
1124
1167
|
data: T;
|
|
1125
1168
|
}>;
|
|
1126
|
-
meta:
|
|
1127
|
-
current_page: number;
|
|
1128
|
-
last_page: number;
|
|
1129
|
-
per_page: number;
|
|
1130
|
-
total: number;
|
|
1131
|
-
};
|
|
1132
|
-
links?: {
|
|
1133
|
-
first: string;
|
|
1134
|
-
last: string;
|
|
1135
|
-
prev: string | null;
|
|
1136
|
-
next: string | null;
|
|
1137
|
-
};
|
|
1169
|
+
meta: PaginationMeta;
|
|
1138
1170
|
}>;
|
|
1139
1171
|
get: (id: number) => Promise<Omit<EntityRecord, "data"> & {
|
|
1140
1172
|
data: T;
|
|
@@ -1218,4 +1250,4 @@ declare class Promptly {
|
|
|
1218
1250
|
getToken(): string | null;
|
|
1219
1251
|
}
|
|
1220
1252
|
|
|
1221
|
-
export { type AddToCartData, type ApiError, type ApiResponse, type ApplyCouponData, type AuthResponse, type BlogListParams, type BlogPost, type Board, type BoardComment, type BoardListParams, type BoardPost, type BoardSettings, type Cart, type CartItem, type Coupon, type CouponType, type CouponValidation, type CreateCommentData, type CreateEntityRecordData, type CreateOrderData, type CreatePostData, type CustomEntity, type EntityField, type EntityListParams, type EntityRecord, type EntitySchema, type ForgotPasswordData, type Form, type FormField, type FormFieldOption, type FormFieldType, type FormFieldValidation, type FormListParams, type FormSettings, type FormSubmission, type ListParams, type LoginCredentials, type Media, type Member, type Order, type OrderItem, type OrderListParams, type OrderStatus, type PaginatedResponse, type Payment, type PaymentCancelData, type PaymentConfirmData, type PaymentMethod, type PaymentReadyData, type PaymentStatus, type PostListParams, type Product, type ProductCategory, type ProductListParams, type ProductOption, type ProductOptionValue, type ProductStatus, type ProductVariant, Promptly, type PromptlyConfig, PromptlyError, type RegisterData, type ResetPasswordData, type SocialAuthUrl, type SocialProvider, type SubmissionListParams, type SubmitFormData, type UpdateCartItemData, type UpdateCommentData, type UpdateEntityRecordData, type UpdatePostData, type UpdateProfileData, Promptly as default };
|
|
1253
|
+
export { type AddToCartData, type ApiError, type ApiResponse, type ApplyCouponData, type AuthResponse, type BlogListParams, type BlogPost, type Board, type BoardComment, type BoardListParams, type BoardPost, type BoardSettings, type Cart, type CartItem, type Coupon, type CouponType, type CouponValidation, type CreateCommentData, type CreateEntityRecordData, type CreateOrderData, type CreatePostData, type CustomEntity, type EntityField, type EntityListParams, type EntityRecord, type EntitySchema, type ForgotPasswordData, type Form, type FormField, type FormFieldOption, type FormFieldType, type FormFieldValidation, type FormListParams, type FormSettings, type FormSubmission, type ListParams, type ListResponse, type LoginCredentials, type Media, type Member, type Order, type OrderItem, type OrderListParams, type OrderStatus, type PaginatedResponse, type PaginationMeta, type Payment, type PaymentCancelData, type PaymentConfirmData, type PaymentMethod, type PaymentReadyData, type PaymentStatus, type PostListParams, type Product, type ProductCategory, type ProductListParams, type ProductOption, type ProductOptionValue, type ProductStatus, type ProductVariant, Promptly, type PromptlyConfig, PromptlyError, type RegisterData, type ResetPasswordData, type SocialAuthUrl, type SocialProvider, type SubmissionListParams, type SubmitFormData, type UpdateCartItemData, type UpdateCommentData, type UpdateEntityRecordData, type UpdatePostData, type UpdateProfileData, Promptly as default };
|
package/dist/index.js
CHANGED
|
@@ -27,6 +27,38 @@ __export(index_exports, {
|
|
|
27
27
|
module.exports = __toCommonJS(index_exports);
|
|
28
28
|
|
|
29
29
|
// src/http.ts
|
|
30
|
+
var DEFAULT_META = {
|
|
31
|
+
current_page: 1,
|
|
32
|
+
last_page: 1,
|
|
33
|
+
per_page: 15,
|
|
34
|
+
total: 0,
|
|
35
|
+
from: null,
|
|
36
|
+
to: null
|
|
37
|
+
};
|
|
38
|
+
function normalizeListResponse(response) {
|
|
39
|
+
if (response == null) {
|
|
40
|
+
return { data: [], meta: { ...DEFAULT_META } };
|
|
41
|
+
}
|
|
42
|
+
if (Array.isArray(response)) {
|
|
43
|
+
return {
|
|
44
|
+
data: response,
|
|
45
|
+
meta: { ...DEFAULT_META, total: response.length, from: response.length > 0 ? 1 : null, to: response.length > 0 ? response.length : null }
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
if (typeof response === "object") {
|
|
49
|
+
const data = Array.isArray(response.data) ? response.data : [];
|
|
50
|
+
const meta = {
|
|
51
|
+
current_page: response.meta?.current_page ?? response.current_page ?? 1,
|
|
52
|
+
last_page: response.meta?.last_page ?? response.last_page ?? 1,
|
|
53
|
+
per_page: response.meta?.per_page ?? response.per_page ?? 15,
|
|
54
|
+
total: response.meta?.total ?? response.total ?? data.length,
|
|
55
|
+
from: response.meta?.from ?? response.from ?? (data.length > 0 ? 1 : null),
|
|
56
|
+
to: response.meta?.to ?? response.to ?? (data.length > 0 ? data.length : null)
|
|
57
|
+
};
|
|
58
|
+
return { data, meta };
|
|
59
|
+
}
|
|
60
|
+
return { data: [], meta: { ...DEFAULT_META } };
|
|
61
|
+
}
|
|
30
62
|
var PromptlyError = class extends Error {
|
|
31
63
|
constructor(message, status, errors) {
|
|
32
64
|
super(message);
|
|
@@ -134,6 +166,14 @@ var HttpClient = class {
|
|
|
134
166
|
get(endpoint, params) {
|
|
135
167
|
return this.request(endpoint, { method: "GET", params });
|
|
136
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* GET request for list endpoints - ALWAYS returns normalized ListResponse
|
|
171
|
+
* Guarantees: data is always an array, meta is always present
|
|
172
|
+
*/
|
|
173
|
+
async getList(endpoint, params) {
|
|
174
|
+
const response = await this.request(endpoint, { method: "GET", params });
|
|
175
|
+
return normalizeListResponse(response);
|
|
176
|
+
}
|
|
137
177
|
/**
|
|
138
178
|
* POST request
|
|
139
179
|
*/
|
|
@@ -317,9 +357,10 @@ var BoardsResource = class {
|
|
|
317
357
|
// ============================================
|
|
318
358
|
/**
|
|
319
359
|
* List all boards
|
|
360
|
+
* @returns ListResponse with data array (always defined) and pagination meta
|
|
320
361
|
*/
|
|
321
362
|
async list(params) {
|
|
322
|
-
return this.http.
|
|
363
|
+
return this.http.getList("/public/boards", params);
|
|
323
364
|
}
|
|
324
365
|
/**
|
|
325
366
|
* Get board by ID or slug
|
|
@@ -332,9 +373,10 @@ var BoardsResource = class {
|
|
|
332
373
|
// ============================================
|
|
333
374
|
/**
|
|
334
375
|
* List posts in a board
|
|
376
|
+
* @returns ListResponse with data array and pagination meta
|
|
335
377
|
*/
|
|
336
378
|
async listPosts(boardIdOrSlug, params) {
|
|
337
|
-
return this.http.
|
|
379
|
+
return this.http.getList(`/public/boards/${boardIdOrSlug}/posts`, params);
|
|
338
380
|
}
|
|
339
381
|
/**
|
|
340
382
|
* Get post by ID
|
|
@@ -368,9 +410,11 @@ var BoardsResource = class {
|
|
|
368
410
|
// ============================================
|
|
369
411
|
/**
|
|
370
412
|
* List comments for a post
|
|
413
|
+
* @returns Array of comments (always an array, never null/undefined)
|
|
371
414
|
*/
|
|
372
415
|
async listComments(postId) {
|
|
373
|
-
|
|
416
|
+
const response = await this.http.getList(`/public/posts/${postId}/comments`);
|
|
417
|
+
return response.data;
|
|
374
418
|
}
|
|
375
419
|
/**
|
|
376
420
|
* Create comment on a post
|
|
@@ -399,9 +443,10 @@ var BlogResource = class {
|
|
|
399
443
|
}
|
|
400
444
|
/**
|
|
401
445
|
* List blog posts
|
|
446
|
+
* @returns ListResponse with data array (always defined) and pagination meta
|
|
402
447
|
*/
|
|
403
448
|
async list(params) {
|
|
404
|
-
return this.http.
|
|
449
|
+
return this.http.getList("/public/blog", params);
|
|
405
450
|
}
|
|
406
451
|
/**
|
|
407
452
|
* Get blog post by slug
|
|
@@ -417,9 +462,10 @@ var BlogResource = class {
|
|
|
417
462
|
}
|
|
418
463
|
/**
|
|
419
464
|
* Get featured blog posts
|
|
465
|
+
* @returns Array of featured posts (always an array, never null/undefined)
|
|
420
466
|
*/
|
|
421
467
|
async featured(limit = 5) {
|
|
422
|
-
const response = await this.http.
|
|
468
|
+
const response = await this.http.getList("/public/blog", {
|
|
423
469
|
per_page: limit,
|
|
424
470
|
featured: true
|
|
425
471
|
});
|
|
@@ -427,42 +473,49 @@ var BlogResource = class {
|
|
|
427
473
|
}
|
|
428
474
|
/**
|
|
429
475
|
* Get blog posts by category
|
|
476
|
+
* @returns ListResponse with data array and pagination meta
|
|
430
477
|
*/
|
|
431
478
|
async byCategory(category, params) {
|
|
432
|
-
return this.http.
|
|
479
|
+
return this.http.getList("/public/blog", {
|
|
433
480
|
...params,
|
|
434
481
|
category
|
|
435
482
|
});
|
|
436
483
|
}
|
|
437
484
|
/**
|
|
438
485
|
* Get blog posts by tag
|
|
486
|
+
* @returns ListResponse with data array and pagination meta
|
|
439
487
|
*/
|
|
440
488
|
async byTag(tag, params) {
|
|
441
|
-
return this.http.
|
|
489
|
+
return this.http.getList("/public/blog", {
|
|
442
490
|
...params,
|
|
443
491
|
tag
|
|
444
492
|
});
|
|
445
493
|
}
|
|
446
494
|
/**
|
|
447
495
|
* Search blog posts
|
|
496
|
+
* @returns ListResponse with data array and pagination meta
|
|
448
497
|
*/
|
|
449
498
|
async search(query, params) {
|
|
450
|
-
return this.http.
|
|
499
|
+
return this.http.getList("/public/blog", {
|
|
451
500
|
...params,
|
|
452
501
|
search: query
|
|
453
502
|
});
|
|
454
503
|
}
|
|
455
504
|
/**
|
|
456
505
|
* Get blog categories
|
|
506
|
+
* @returns Array of category names (always an array)
|
|
457
507
|
*/
|
|
458
508
|
async categories() {
|
|
459
|
-
|
|
509
|
+
const response = await this.http.get("/public/blog/categories");
|
|
510
|
+
return Array.isArray(response) ? response : response?.data ?? [];
|
|
460
511
|
}
|
|
461
512
|
/**
|
|
462
513
|
* Get blog tags
|
|
514
|
+
* @returns Array of tag names (always an array)
|
|
463
515
|
*/
|
|
464
516
|
async tags() {
|
|
465
|
-
|
|
517
|
+
const response = await this.http.get("/public/blog/tags");
|
|
518
|
+
return Array.isArray(response) ? response : response?.data ?? [];
|
|
466
519
|
}
|
|
467
520
|
};
|
|
468
521
|
|
|
@@ -473,9 +526,10 @@ var FormsResource = class {
|
|
|
473
526
|
}
|
|
474
527
|
/**
|
|
475
528
|
* List all forms
|
|
529
|
+
* @returns ListResponse with data array and pagination meta
|
|
476
530
|
*/
|
|
477
531
|
async list(params) {
|
|
478
|
-
return this.http.
|
|
532
|
+
return this.http.getList("/public/forms", params);
|
|
479
533
|
}
|
|
480
534
|
/**
|
|
481
535
|
* Get form by ID or slug
|
|
@@ -494,9 +548,10 @@ var FormsResource = class {
|
|
|
494
548
|
// ============================================
|
|
495
549
|
/**
|
|
496
550
|
* Get my form submissions
|
|
551
|
+
* @returns ListResponse with data array and pagination meta
|
|
497
552
|
*/
|
|
498
553
|
async mySubmissions(params) {
|
|
499
|
-
return this.http.
|
|
554
|
+
return this.http.getList("/form-submissions", params);
|
|
500
555
|
}
|
|
501
556
|
/**
|
|
502
557
|
* Get specific submission
|
|
@@ -516,9 +571,10 @@ var ShopResource = class {
|
|
|
516
571
|
// ============================================
|
|
517
572
|
/**
|
|
518
573
|
* List products
|
|
574
|
+
* @returns ListResponse with data array and pagination meta
|
|
519
575
|
*/
|
|
520
576
|
async listProducts(params) {
|
|
521
|
-
return this.http.
|
|
577
|
+
return this.http.getList("/public/products", params);
|
|
522
578
|
}
|
|
523
579
|
/**
|
|
524
580
|
* Get product by ID or slug
|
|
@@ -528,9 +584,10 @@ var ShopResource = class {
|
|
|
528
584
|
}
|
|
529
585
|
/**
|
|
530
586
|
* Get featured products
|
|
587
|
+
* @returns Array of featured products (always an array)
|
|
531
588
|
*/
|
|
532
589
|
async featuredProducts(limit = 8) {
|
|
533
|
-
const response = await this.http.
|
|
590
|
+
const response = await this.http.getList("/public/products", {
|
|
534
591
|
per_page: limit,
|
|
535
592
|
is_featured: true
|
|
536
593
|
});
|
|
@@ -538,9 +595,10 @@ var ShopResource = class {
|
|
|
538
595
|
}
|
|
539
596
|
/**
|
|
540
597
|
* Search products
|
|
598
|
+
* @returns ListResponse with data array and pagination meta
|
|
541
599
|
*/
|
|
542
600
|
async searchProducts(query, params) {
|
|
543
|
-
return this.http.
|
|
601
|
+
return this.http.getList("/public/products", {
|
|
544
602
|
...params,
|
|
545
603
|
search: query
|
|
546
604
|
});
|
|
@@ -550,9 +608,11 @@ var ShopResource = class {
|
|
|
550
608
|
// ============================================
|
|
551
609
|
/**
|
|
552
610
|
* List product categories
|
|
611
|
+
* @returns Array of categories (always an array)
|
|
553
612
|
*/
|
|
554
613
|
async listCategories() {
|
|
555
|
-
|
|
614
|
+
const response = await this.http.getList("/public/categories");
|
|
615
|
+
return response.data;
|
|
556
616
|
}
|
|
557
617
|
/**
|
|
558
618
|
* Get category by ID or slug
|
|
@@ -562,9 +622,10 @@ var ShopResource = class {
|
|
|
562
622
|
}
|
|
563
623
|
/**
|
|
564
624
|
* Get products in category
|
|
625
|
+
* @returns ListResponse with data array and pagination meta
|
|
565
626
|
*/
|
|
566
627
|
async categoryProducts(categoryIdOrSlug, params) {
|
|
567
|
-
return this.http.
|
|
628
|
+
return this.http.getList(`/public/categories/${categoryIdOrSlug}/products`, params);
|
|
568
629
|
}
|
|
569
630
|
// ============================================
|
|
570
631
|
// Cart
|
|
@@ -604,9 +665,10 @@ var ShopResource = class {
|
|
|
604
665
|
// ============================================
|
|
605
666
|
/**
|
|
606
667
|
* List my orders
|
|
668
|
+
* @returns ListResponse with data array and pagination meta
|
|
607
669
|
*/
|
|
608
670
|
async listOrders(params) {
|
|
609
|
-
return this.http.
|
|
671
|
+
return this.http.getList("/orders", params);
|
|
610
672
|
}
|
|
611
673
|
/**
|
|
612
674
|
* Get order by ID or order number
|
|
@@ -667,9 +729,11 @@ var ShopResource = class {
|
|
|
667
729
|
}
|
|
668
730
|
/**
|
|
669
731
|
* Get available coupons for current user
|
|
732
|
+
* @returns Array of coupons (always an array)
|
|
670
733
|
*/
|
|
671
734
|
async myCoupons() {
|
|
672
|
-
|
|
735
|
+
const response = await this.http.getList("/coupons");
|
|
736
|
+
return response.data;
|
|
673
737
|
}
|
|
674
738
|
};
|
|
675
739
|
|
|
@@ -725,6 +789,7 @@ var EntitiesResource = class {
|
|
|
725
789
|
// ============================================
|
|
726
790
|
/**
|
|
727
791
|
* List all active custom entities
|
|
792
|
+
* @returns Array of entities (always an array)
|
|
728
793
|
*
|
|
729
794
|
* @example
|
|
730
795
|
* ```typescript
|
|
@@ -733,7 +798,8 @@ var EntitiesResource = class {
|
|
|
733
798
|
* ```
|
|
734
799
|
*/
|
|
735
800
|
async list() {
|
|
736
|
-
|
|
801
|
+
const response = await this.http.getList("/public/entities");
|
|
802
|
+
return response.data;
|
|
737
803
|
}
|
|
738
804
|
/**
|
|
739
805
|
* Get entity schema by slug
|
|
@@ -752,6 +818,7 @@ var EntitiesResource = class {
|
|
|
752
818
|
// ============================================
|
|
753
819
|
/**
|
|
754
820
|
* List records for an entity
|
|
821
|
+
* @returns ListResponse with data array and pagination meta
|
|
755
822
|
*
|
|
756
823
|
* @example
|
|
757
824
|
* ```typescript
|
|
@@ -772,7 +839,7 @@ var EntitiesResource = class {
|
|
|
772
839
|
* ```
|
|
773
840
|
*/
|
|
774
841
|
async listRecords(slug, params) {
|
|
775
|
-
return this.http.
|
|
842
|
+
return this.http.getList(`/public/entities/${slug}`, params);
|
|
776
843
|
}
|
|
777
844
|
/**
|
|
778
845
|
* Get a single record by ID
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,36 @@
|
|
|
1
1
|
// src/http.ts
|
|
2
|
+
var DEFAULT_META = {
|
|
3
|
+
current_page: 1,
|
|
4
|
+
last_page: 1,
|
|
5
|
+
per_page: 15,
|
|
6
|
+
total: 0,
|
|
7
|
+
from: null,
|
|
8
|
+
to: null
|
|
9
|
+
};
|
|
10
|
+
function normalizeListResponse(response) {
|
|
11
|
+
if (response == null) {
|
|
12
|
+
return { data: [], meta: { ...DEFAULT_META } };
|
|
13
|
+
}
|
|
14
|
+
if (Array.isArray(response)) {
|
|
15
|
+
return {
|
|
16
|
+
data: response,
|
|
17
|
+
meta: { ...DEFAULT_META, total: response.length, from: response.length > 0 ? 1 : null, to: response.length > 0 ? response.length : null }
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
if (typeof response === "object") {
|
|
21
|
+
const data = Array.isArray(response.data) ? response.data : [];
|
|
22
|
+
const meta = {
|
|
23
|
+
current_page: response.meta?.current_page ?? response.current_page ?? 1,
|
|
24
|
+
last_page: response.meta?.last_page ?? response.last_page ?? 1,
|
|
25
|
+
per_page: response.meta?.per_page ?? response.per_page ?? 15,
|
|
26
|
+
total: response.meta?.total ?? response.total ?? data.length,
|
|
27
|
+
from: response.meta?.from ?? response.from ?? (data.length > 0 ? 1 : null),
|
|
28
|
+
to: response.meta?.to ?? response.to ?? (data.length > 0 ? data.length : null)
|
|
29
|
+
};
|
|
30
|
+
return { data, meta };
|
|
31
|
+
}
|
|
32
|
+
return { data: [], meta: { ...DEFAULT_META } };
|
|
33
|
+
}
|
|
2
34
|
var PromptlyError = class extends Error {
|
|
3
35
|
constructor(message, status, errors) {
|
|
4
36
|
super(message);
|
|
@@ -106,6 +138,14 @@ var HttpClient = class {
|
|
|
106
138
|
get(endpoint, params) {
|
|
107
139
|
return this.request(endpoint, { method: "GET", params });
|
|
108
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* GET request for list endpoints - ALWAYS returns normalized ListResponse
|
|
143
|
+
* Guarantees: data is always an array, meta is always present
|
|
144
|
+
*/
|
|
145
|
+
async getList(endpoint, params) {
|
|
146
|
+
const response = await this.request(endpoint, { method: "GET", params });
|
|
147
|
+
return normalizeListResponse(response);
|
|
148
|
+
}
|
|
109
149
|
/**
|
|
110
150
|
* POST request
|
|
111
151
|
*/
|
|
@@ -289,9 +329,10 @@ var BoardsResource = class {
|
|
|
289
329
|
// ============================================
|
|
290
330
|
/**
|
|
291
331
|
* List all boards
|
|
332
|
+
* @returns ListResponse with data array (always defined) and pagination meta
|
|
292
333
|
*/
|
|
293
334
|
async list(params) {
|
|
294
|
-
return this.http.
|
|
335
|
+
return this.http.getList("/public/boards", params);
|
|
295
336
|
}
|
|
296
337
|
/**
|
|
297
338
|
* Get board by ID or slug
|
|
@@ -304,9 +345,10 @@ var BoardsResource = class {
|
|
|
304
345
|
// ============================================
|
|
305
346
|
/**
|
|
306
347
|
* List posts in a board
|
|
348
|
+
* @returns ListResponse with data array and pagination meta
|
|
307
349
|
*/
|
|
308
350
|
async listPosts(boardIdOrSlug, params) {
|
|
309
|
-
return this.http.
|
|
351
|
+
return this.http.getList(`/public/boards/${boardIdOrSlug}/posts`, params);
|
|
310
352
|
}
|
|
311
353
|
/**
|
|
312
354
|
* Get post by ID
|
|
@@ -340,9 +382,11 @@ var BoardsResource = class {
|
|
|
340
382
|
// ============================================
|
|
341
383
|
/**
|
|
342
384
|
* List comments for a post
|
|
385
|
+
* @returns Array of comments (always an array, never null/undefined)
|
|
343
386
|
*/
|
|
344
387
|
async listComments(postId) {
|
|
345
|
-
|
|
388
|
+
const response = await this.http.getList(`/public/posts/${postId}/comments`);
|
|
389
|
+
return response.data;
|
|
346
390
|
}
|
|
347
391
|
/**
|
|
348
392
|
* Create comment on a post
|
|
@@ -371,9 +415,10 @@ var BlogResource = class {
|
|
|
371
415
|
}
|
|
372
416
|
/**
|
|
373
417
|
* List blog posts
|
|
418
|
+
* @returns ListResponse with data array (always defined) and pagination meta
|
|
374
419
|
*/
|
|
375
420
|
async list(params) {
|
|
376
|
-
return this.http.
|
|
421
|
+
return this.http.getList("/public/blog", params);
|
|
377
422
|
}
|
|
378
423
|
/**
|
|
379
424
|
* Get blog post by slug
|
|
@@ -389,9 +434,10 @@ var BlogResource = class {
|
|
|
389
434
|
}
|
|
390
435
|
/**
|
|
391
436
|
* Get featured blog posts
|
|
437
|
+
* @returns Array of featured posts (always an array, never null/undefined)
|
|
392
438
|
*/
|
|
393
439
|
async featured(limit = 5) {
|
|
394
|
-
const response = await this.http.
|
|
440
|
+
const response = await this.http.getList("/public/blog", {
|
|
395
441
|
per_page: limit,
|
|
396
442
|
featured: true
|
|
397
443
|
});
|
|
@@ -399,42 +445,49 @@ var BlogResource = class {
|
|
|
399
445
|
}
|
|
400
446
|
/**
|
|
401
447
|
* Get blog posts by category
|
|
448
|
+
* @returns ListResponse with data array and pagination meta
|
|
402
449
|
*/
|
|
403
450
|
async byCategory(category, params) {
|
|
404
|
-
return this.http.
|
|
451
|
+
return this.http.getList("/public/blog", {
|
|
405
452
|
...params,
|
|
406
453
|
category
|
|
407
454
|
});
|
|
408
455
|
}
|
|
409
456
|
/**
|
|
410
457
|
* Get blog posts by tag
|
|
458
|
+
* @returns ListResponse with data array and pagination meta
|
|
411
459
|
*/
|
|
412
460
|
async byTag(tag, params) {
|
|
413
|
-
return this.http.
|
|
461
|
+
return this.http.getList("/public/blog", {
|
|
414
462
|
...params,
|
|
415
463
|
tag
|
|
416
464
|
});
|
|
417
465
|
}
|
|
418
466
|
/**
|
|
419
467
|
* Search blog posts
|
|
468
|
+
* @returns ListResponse with data array and pagination meta
|
|
420
469
|
*/
|
|
421
470
|
async search(query, params) {
|
|
422
|
-
return this.http.
|
|
471
|
+
return this.http.getList("/public/blog", {
|
|
423
472
|
...params,
|
|
424
473
|
search: query
|
|
425
474
|
});
|
|
426
475
|
}
|
|
427
476
|
/**
|
|
428
477
|
* Get blog categories
|
|
478
|
+
* @returns Array of category names (always an array)
|
|
429
479
|
*/
|
|
430
480
|
async categories() {
|
|
431
|
-
|
|
481
|
+
const response = await this.http.get("/public/blog/categories");
|
|
482
|
+
return Array.isArray(response) ? response : response?.data ?? [];
|
|
432
483
|
}
|
|
433
484
|
/**
|
|
434
485
|
* Get blog tags
|
|
486
|
+
* @returns Array of tag names (always an array)
|
|
435
487
|
*/
|
|
436
488
|
async tags() {
|
|
437
|
-
|
|
489
|
+
const response = await this.http.get("/public/blog/tags");
|
|
490
|
+
return Array.isArray(response) ? response : response?.data ?? [];
|
|
438
491
|
}
|
|
439
492
|
};
|
|
440
493
|
|
|
@@ -445,9 +498,10 @@ var FormsResource = class {
|
|
|
445
498
|
}
|
|
446
499
|
/**
|
|
447
500
|
* List all forms
|
|
501
|
+
* @returns ListResponse with data array and pagination meta
|
|
448
502
|
*/
|
|
449
503
|
async list(params) {
|
|
450
|
-
return this.http.
|
|
504
|
+
return this.http.getList("/public/forms", params);
|
|
451
505
|
}
|
|
452
506
|
/**
|
|
453
507
|
* Get form by ID or slug
|
|
@@ -466,9 +520,10 @@ var FormsResource = class {
|
|
|
466
520
|
// ============================================
|
|
467
521
|
/**
|
|
468
522
|
* Get my form submissions
|
|
523
|
+
* @returns ListResponse with data array and pagination meta
|
|
469
524
|
*/
|
|
470
525
|
async mySubmissions(params) {
|
|
471
|
-
return this.http.
|
|
526
|
+
return this.http.getList("/form-submissions", params);
|
|
472
527
|
}
|
|
473
528
|
/**
|
|
474
529
|
* Get specific submission
|
|
@@ -488,9 +543,10 @@ var ShopResource = class {
|
|
|
488
543
|
// ============================================
|
|
489
544
|
/**
|
|
490
545
|
* List products
|
|
546
|
+
* @returns ListResponse with data array and pagination meta
|
|
491
547
|
*/
|
|
492
548
|
async listProducts(params) {
|
|
493
|
-
return this.http.
|
|
549
|
+
return this.http.getList("/public/products", params);
|
|
494
550
|
}
|
|
495
551
|
/**
|
|
496
552
|
* Get product by ID or slug
|
|
@@ -500,9 +556,10 @@ var ShopResource = class {
|
|
|
500
556
|
}
|
|
501
557
|
/**
|
|
502
558
|
* Get featured products
|
|
559
|
+
* @returns Array of featured products (always an array)
|
|
503
560
|
*/
|
|
504
561
|
async featuredProducts(limit = 8) {
|
|
505
|
-
const response = await this.http.
|
|
562
|
+
const response = await this.http.getList("/public/products", {
|
|
506
563
|
per_page: limit,
|
|
507
564
|
is_featured: true
|
|
508
565
|
});
|
|
@@ -510,9 +567,10 @@ var ShopResource = class {
|
|
|
510
567
|
}
|
|
511
568
|
/**
|
|
512
569
|
* Search products
|
|
570
|
+
* @returns ListResponse with data array and pagination meta
|
|
513
571
|
*/
|
|
514
572
|
async searchProducts(query, params) {
|
|
515
|
-
return this.http.
|
|
573
|
+
return this.http.getList("/public/products", {
|
|
516
574
|
...params,
|
|
517
575
|
search: query
|
|
518
576
|
});
|
|
@@ -522,9 +580,11 @@ var ShopResource = class {
|
|
|
522
580
|
// ============================================
|
|
523
581
|
/**
|
|
524
582
|
* List product categories
|
|
583
|
+
* @returns Array of categories (always an array)
|
|
525
584
|
*/
|
|
526
585
|
async listCategories() {
|
|
527
|
-
|
|
586
|
+
const response = await this.http.getList("/public/categories");
|
|
587
|
+
return response.data;
|
|
528
588
|
}
|
|
529
589
|
/**
|
|
530
590
|
* Get category by ID or slug
|
|
@@ -534,9 +594,10 @@ var ShopResource = class {
|
|
|
534
594
|
}
|
|
535
595
|
/**
|
|
536
596
|
* Get products in category
|
|
597
|
+
* @returns ListResponse with data array and pagination meta
|
|
537
598
|
*/
|
|
538
599
|
async categoryProducts(categoryIdOrSlug, params) {
|
|
539
|
-
return this.http.
|
|
600
|
+
return this.http.getList(`/public/categories/${categoryIdOrSlug}/products`, params);
|
|
540
601
|
}
|
|
541
602
|
// ============================================
|
|
542
603
|
// Cart
|
|
@@ -576,9 +637,10 @@ var ShopResource = class {
|
|
|
576
637
|
// ============================================
|
|
577
638
|
/**
|
|
578
639
|
* List my orders
|
|
640
|
+
* @returns ListResponse with data array and pagination meta
|
|
579
641
|
*/
|
|
580
642
|
async listOrders(params) {
|
|
581
|
-
return this.http.
|
|
643
|
+
return this.http.getList("/orders", params);
|
|
582
644
|
}
|
|
583
645
|
/**
|
|
584
646
|
* Get order by ID or order number
|
|
@@ -639,9 +701,11 @@ var ShopResource = class {
|
|
|
639
701
|
}
|
|
640
702
|
/**
|
|
641
703
|
* Get available coupons for current user
|
|
704
|
+
* @returns Array of coupons (always an array)
|
|
642
705
|
*/
|
|
643
706
|
async myCoupons() {
|
|
644
|
-
|
|
707
|
+
const response = await this.http.getList("/coupons");
|
|
708
|
+
return response.data;
|
|
645
709
|
}
|
|
646
710
|
};
|
|
647
711
|
|
|
@@ -697,6 +761,7 @@ var EntitiesResource = class {
|
|
|
697
761
|
// ============================================
|
|
698
762
|
/**
|
|
699
763
|
* List all active custom entities
|
|
764
|
+
* @returns Array of entities (always an array)
|
|
700
765
|
*
|
|
701
766
|
* @example
|
|
702
767
|
* ```typescript
|
|
@@ -705,7 +770,8 @@ var EntitiesResource = class {
|
|
|
705
770
|
* ```
|
|
706
771
|
*/
|
|
707
772
|
async list() {
|
|
708
|
-
|
|
773
|
+
const response = await this.http.getList("/public/entities");
|
|
774
|
+
return response.data;
|
|
709
775
|
}
|
|
710
776
|
/**
|
|
711
777
|
* Get entity schema by slug
|
|
@@ -724,6 +790,7 @@ var EntitiesResource = class {
|
|
|
724
790
|
// ============================================
|
|
725
791
|
/**
|
|
726
792
|
* List records for an entity
|
|
793
|
+
* @returns ListResponse with data array and pagination meta
|
|
727
794
|
*
|
|
728
795
|
* @example
|
|
729
796
|
* ```typescript
|
|
@@ -744,7 +811,7 @@ var EntitiesResource = class {
|
|
|
744
811
|
* ```
|
|
745
812
|
*/
|
|
746
813
|
async listRecords(slug, params) {
|
|
747
|
-
return this.http.
|
|
814
|
+
return this.http.getList(`/public/entities/${slug}`, params);
|
|
748
815
|
}
|
|
749
816
|
/**
|
|
750
817
|
* Get a single record by ID
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@back23/promptly-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Promptly AI CMS SDK for JavaScript/TypeScript",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"license": "MIT",
|
|
33
33
|
"repository": {
|
|
34
34
|
"type": "git",
|
|
35
|
-
"url": "https://github.com/kingofecommerce/promptly-sdk.git"
|
|
35
|
+
"url": "https://github.com/kingofecommerce/back23-promptly-sdk.git"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"tsup": "^8.0.0",
|