@salla.sa/twilight 2.0.217 → 2.0.219
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/@salla.sa/twilight.min.js +2 -2
- package/dist/@salla.sa/twilight.min.js.map +1 -1
- package/dist/cjs/index.js +13 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/main.js +2 -2
- package/dist/cjs/main.js.map +1 -1
- package/dist/esm/index.js +13 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/main.js +2 -2
- package/dist/esm/main.js.map +1 -1
- package/package.json +1 -1
- package/types/actions.d.ts +50 -0
- package/types/api/cart.d.ts +4 -6
- package/types/api/comment.d.ts +12 -0
- package/types/api/currency.d.ts +17 -0
- package/types/api/document.d.ts +3 -0
- package/types/api/feedback.d.ts +56 -0
- package/types/api/gift.d.ts +26 -0
- package/types/api/index.d.ts +103 -0
- package/types/api/offer.d.ts +43 -0
- package/types/api/product.d.ts +29 -0
- package/types/api/search.d.ts +22 -0
- package/types/api/twilight.d.ts +6 -0
- package/types/api/wishlist.d.ts +7 -0
- package/types/common.d.ts +42 -4
- package/types/event/comment.d.ts +7 -0
- package/types/event/currency.d.ts +9 -0
- package/types/event/document.d.ts +21 -0
- package/types/event/feedback.d.ts +18 -0
- package/types/event/gift.d.ts +7 -0
- package/types/event/index.d.ts +56 -0
- package/types/event/infiniteScroll.d.ts +12 -0
- package/types/event/offer.d.ts +9 -0
- package/types/event/product.d.ts +9 -0
- package/types/event/profile.d.ts +2 -5
- package/types/event/search.d.ts +7 -0
- package/types/event/twilight.d.ts +5 -0
- package/types/event/wishlist.d.ts +8 -0
- package/types/helpers/app-helpers.d.ts +31 -0
- package/types/helpers/salla-helpers.d.ts +17 -9
- package/types/index.d.ts +30 -89
- package/types/lib/salla-config.ts +43 -5
- package/types/lib/salla-cookie.d.ts +5 -0
- package/types/lib/salla-form.d.ts +3 -0
- package/types/lib/salla-lang.d.ts +14 -0
- package/types/lib/salla-notify.d.ts +14 -0
- package/types/lib/salla-storage.d.ts +13 -0
- package/types/tiwlight-config.d.ts +57 -57
- package/types/all.d.ts +0 -5
package/package.json
CHANGED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AuthApi, CartApi, CommentApi, CouponApi, CurrencyApi, DocumentApi, FeedbackApi, GiftApi, OfferApi, OrderApi,
|
|
3
|
+
ProductApi, ProfileApi, SearchApi, TwilightApi, WishlistApi
|
|
4
|
+
} from "./api";
|
|
5
|
+
import {
|
|
6
|
+
AuthEvent, CartEvent, CommentEvent, CouponEvent, CurrencyEvent, DocumentEvent, FeedbackEvent, GiftEvent,
|
|
7
|
+
InfiniteScrollEvent, OfferEvent, OrderEvent, ProductEvent, ProfileEvent, SearchEvent, TwilightEvent, WishlistEvent
|
|
8
|
+
} from "./event";
|
|
9
|
+
|
|
10
|
+
export default interface SallaActions {
|
|
11
|
+
cart: CartApi & { api: CartApi, event: CartEvent };
|
|
12
|
+
auth: AuthApi & { api: AuthApi, event: AuthEvent };
|
|
13
|
+
gift: GiftApi & { api: GiftApi, event: GiftEvent };
|
|
14
|
+
order: OrderApi & { api: OrderApi, event: OrderEvent };
|
|
15
|
+
offer: OfferApi & { api: OfferApi, event: OfferEvent };
|
|
16
|
+
search: SearchApi & { api: SearchApi, event: SearchEvent };
|
|
17
|
+
coupon: CouponApi & { api: CouponApi, event: CouponEvent };
|
|
18
|
+
comment: CommentApi & { api: CommentApi, event: CommentEvent };
|
|
19
|
+
loyalty: { api: any, event: any }; //todo:: support it
|
|
20
|
+
product: ProductApi & { api: ProductApi, event: ProductEvent };
|
|
21
|
+
profile: ProfileApi & { api: ProfileApi, event: ProfileEvent };
|
|
22
|
+
currency: CurrencyApi & { api: CurrencyApi, event: CurrencyEvent };
|
|
23
|
+
document: DocumentApi & { api: DocumentApi, event: DocumentEvent };
|
|
24
|
+
feedback: FeedbackApi & { api: FeedbackApi, event: FeedbackEvent };
|
|
25
|
+
twilight: TwilightApi & { api: TwilightApi, event: TwilightEvent };
|
|
26
|
+
wishlist: WishlistApi & { api: WishlistApi, event: WishlistEvent };
|
|
27
|
+
infiniteScroll: InfiniteScroll & { api: null, event: InfiniteScrollEvent };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
/********************* Infinite Scroll *********************/
|
|
32
|
+
/**
|
|
33
|
+
* @see https://infinite-scroll.com/options.html
|
|
34
|
+
*/
|
|
35
|
+
export interface InfiniteScrollOptions {
|
|
36
|
+
path: '.infinite-scroll-btn' | string;
|
|
37
|
+
history: 'push' | false;
|
|
38
|
+
status: ".infinite-scroll-status" | string;
|
|
39
|
+
append: ".list-block" | string;
|
|
40
|
+
button: ".infinite-scroll-btn" | string;
|
|
41
|
+
next_page: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @see https://infinite-scroll.com/api.html
|
|
46
|
+
*/
|
|
47
|
+
export interface InfiniteScroll {
|
|
48
|
+
//💡 when there is no need to pass options, but there is need to change append selector, just pass it as string as second argument
|
|
49
|
+
initiate: (selector: string | HTMLElement, append?: string | InfiniteScrollOptions, customOptions?: InfiniteScrollOptions) => Object;
|
|
50
|
+
}
|
package/types/api/cart.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {Nullable, TwilightResponse} from "../common";
|
|
2
|
+
import {ProductPayload} from "./product";
|
|
2
3
|
|
|
3
4
|
export interface itemOffer {
|
|
4
5
|
discount: number,
|
|
@@ -80,12 +81,9 @@ export interface CartStatusResponse extends TwilightResponse {
|
|
|
80
81
|
}
|
|
81
82
|
}
|
|
82
83
|
|
|
83
|
-
export interface AddItemPayload {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
options: Nullable<{ [key: number]: [value: number | string | Array<{ [key: number]: [value: number] }>] }>;
|
|
87
|
-
notes: Nullable<string>;
|
|
88
|
-
file: Nullable<BinaryType | string>;
|
|
84
|
+
export interface AddItemPayload extends ProductPayload {
|
|
85
|
+
notes?: Nullable<string>;
|
|
86
|
+
file?: Nullable<BinaryType | string>;
|
|
89
87
|
}
|
|
90
88
|
|
|
91
89
|
export default interface CartApi {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {TwilightResponse} from "../common";
|
|
2
|
+
|
|
3
|
+
export interface SendCommentResponse extends TwilightResponse {
|
|
4
|
+
data: {
|
|
5
|
+
case: 'success' | 'error',
|
|
6
|
+
message: string,
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export default interface CommentApi {
|
|
11
|
+
send: (data: { id: number, comment: string, type: 'product' | 'page' }) => Promise<SendCommentResponse>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {Currency, TwilightResponse} from "../common";
|
|
2
|
+
|
|
3
|
+
export interface ChangeCurrencyResponse extends TwilightResponse {
|
|
4
|
+
data: {
|
|
5
|
+
code: 'SAR' | string,
|
|
6
|
+
symbol: string,
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface ListCurrenciesResponse extends TwilightResponse {
|
|
11
|
+
data: Array<Currency>
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default interface CurrencyApi {
|
|
15
|
+
change: (currency_code: 'SAR' | 'USD' | string) => Promise<ChangeCurrencyResponse>;
|
|
16
|
+
list: () => Promise<ListCurrenciesResponse>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {Nullable, Product, Rating, TwilightResponse} from "../common";
|
|
2
|
+
|
|
3
|
+
export interface SuccessFeedbackResponse extends TwilightResponse {
|
|
4
|
+
data: {
|
|
5
|
+
case: "success";
|
|
6
|
+
message: string;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface OrderDetailsResponse extends TwilightResponse {
|
|
11
|
+
data: {
|
|
12
|
+
id: number;
|
|
13
|
+
store: Nullable<{ feedback: FeedbackContent }>;
|
|
14
|
+
shipping: Nullable<{
|
|
15
|
+
feedback: FeedbackContent;
|
|
16
|
+
company: {
|
|
17
|
+
id: number;
|
|
18
|
+
name: string;
|
|
19
|
+
logo: Nullable<string>;
|
|
20
|
+
}
|
|
21
|
+
}>;
|
|
22
|
+
products: Array<{ feedback: FeedbackContent; product: Product; }>;
|
|
23
|
+
testimonials_enabled: boolean;
|
|
24
|
+
shipping_enabled: boolean;
|
|
25
|
+
products_enabled: boolean;
|
|
26
|
+
thanks_message: string;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface FeedbackContent {
|
|
31
|
+
content: string,
|
|
32
|
+
rating: Rating;
|
|
33
|
+
status?: 'approved' | 'pending';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface FeedbackStorePayload {
|
|
37
|
+
comment: string;
|
|
38
|
+
order_id: number;
|
|
39
|
+
rating: Rating;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface FeedbackProductsPayload {
|
|
43
|
+
products: Array<{ product_id: number; comment: string; rating: Rating; }>
|
|
44
|
+
order_id: number;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface FeedbackShippingPayload extends FeedbackStorePayload {
|
|
48
|
+
shipping_company_id: number;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export default interface FeedbackApi {
|
|
52
|
+
order: (order_id: number) => Promise<OrderDetailsResponse>;
|
|
53
|
+
store: (data: FeedbackStorePayload) => Promise<SuccessFeedbackResponse>;
|
|
54
|
+
products: (data: FeedbackProductsPayload) => Promise<SuccessFeedbackResponse>;
|
|
55
|
+
shipping: (data: FeedbackShippingPayload) => Promise<SuccessFeedbackResponse>;
|
|
56
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {TwilightResponse} from "../common";
|
|
2
|
+
|
|
3
|
+
export interface GiftPayload {
|
|
4
|
+
id: number;
|
|
5
|
+
image?: BinaryType;
|
|
6
|
+
image_url_id?: number;
|
|
7
|
+
text_id?: number;//required if text not provided
|
|
8
|
+
text?: string;//required if text_id not provided
|
|
9
|
+
sender_name?: string;
|
|
10
|
+
receiver: {
|
|
11
|
+
name: string;
|
|
12
|
+
mobile: number;
|
|
13
|
+
country_code: string | 'SA';
|
|
14
|
+
email?: string;
|
|
15
|
+
};
|
|
16
|
+
deliver_at: string | '2022-02-22 02:22 pm';
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface GiftResponse extends TwilightResponse {
|
|
20
|
+
redirect: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default interface GiftApi {
|
|
24
|
+
buy: (GiftPayload) => Promise<GiftResponse>;
|
|
25
|
+
|
|
26
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import {Axios} from "axios";
|
|
2
|
+
import CartApi from "./cart";
|
|
3
|
+
import AuthApi from "./auth";
|
|
4
|
+
import GiftApi from "./gift";
|
|
5
|
+
import OrderApi from "./order";
|
|
6
|
+
import OfferApi from "./offer";
|
|
7
|
+
import SearchApi from "./search";
|
|
8
|
+
import CouponApi from "./coupon";
|
|
9
|
+
import CommentApi from "./comment";
|
|
10
|
+
import ProductApi from "./product";
|
|
11
|
+
import ProfileApi from "./profile";
|
|
12
|
+
import CurrencyApi from "./currency";
|
|
13
|
+
import DocumentApi from "./document";
|
|
14
|
+
import FeedbackApi from "./feedback";
|
|
15
|
+
import WishlistApi from "./wishlist";
|
|
16
|
+
import TwilightApi from "./twilight";
|
|
17
|
+
|
|
18
|
+
export {
|
|
19
|
+
CartApi,
|
|
20
|
+
AuthApi,
|
|
21
|
+
GiftApi,
|
|
22
|
+
OrderApi,
|
|
23
|
+
OfferApi,
|
|
24
|
+
SearchApi,
|
|
25
|
+
CouponApi,
|
|
26
|
+
CommentApi,
|
|
27
|
+
ProductApi,
|
|
28
|
+
ProfileApi,
|
|
29
|
+
CurrencyApi,
|
|
30
|
+
DocumentApi,
|
|
31
|
+
TwilightApi,
|
|
32
|
+
FeedbackApi,
|
|
33
|
+
WishlistApi,
|
|
34
|
+
};
|
|
35
|
+
export type ApiActionName =
|
|
36
|
+
'auth.login'
|
|
37
|
+
| 'auth.resend'
|
|
38
|
+
| 'auth.verify'
|
|
39
|
+
| 'auth.register'
|
|
40
|
+
| 'auth.logout'
|
|
41
|
+
| 'auth.refresh'
|
|
42
|
+
| 'cart.latest'
|
|
43
|
+
| 'cart.details'
|
|
44
|
+
| 'cart.summary'
|
|
45
|
+
| 'cart.quickAdd'
|
|
46
|
+
| 'cart.addItem'
|
|
47
|
+
| 'cart.deleteItem'
|
|
48
|
+
| 'cart.updateItem'
|
|
49
|
+
| 'cart.deleteImage'
|
|
50
|
+
| 'cart.status'
|
|
51
|
+
| 'gift.buy'
|
|
52
|
+
| 'loyalty.exchange'
|
|
53
|
+
| 'order.cancel'
|
|
54
|
+
| 'order.reOrder'
|
|
55
|
+
| 'order.send'
|
|
56
|
+
| 'offer.increase'
|
|
57
|
+
| 'offer.details'
|
|
58
|
+
| 'search.search'
|
|
59
|
+
| 'coupon.add'
|
|
60
|
+
| 'coupon.remove'
|
|
61
|
+
| 'product.getPrice'
|
|
62
|
+
| 'product.availabilitySubscribe'
|
|
63
|
+
| 'product.purchaseNow'
|
|
64
|
+
| 'profile.update'
|
|
65
|
+
| 'comment.send'
|
|
66
|
+
| 'currency.change'
|
|
67
|
+
| 'currency.list'
|
|
68
|
+
| 'feedback.store'
|
|
69
|
+
| 'feedback.products'
|
|
70
|
+
| 'feedback.shipping'
|
|
71
|
+
| 'feedback.order'
|
|
72
|
+
| 'wishlist.add'
|
|
73
|
+
| 'wishlist.remove'
|
|
74
|
+
| 'scope.getAll'
|
|
75
|
+
| 'scope.submit';
|
|
76
|
+
|
|
77
|
+
export default interface SallaApi extends Axios {
|
|
78
|
+
cart: CartApi;
|
|
79
|
+
auth: AuthApi;
|
|
80
|
+
gift: GiftApi;
|
|
81
|
+
order: OrderApi;
|
|
82
|
+
offer: OfferApi;
|
|
83
|
+
search: SearchApi;
|
|
84
|
+
coupon: CouponApi;
|
|
85
|
+
comment: CommentApi;
|
|
86
|
+
loyalty: any;//TODO::add types
|
|
87
|
+
product: ProductApi;
|
|
88
|
+
profile: ProfileApi;
|
|
89
|
+
currency: CurrencyApi;
|
|
90
|
+
document: DocumentApi;
|
|
91
|
+
feedback: FeedbackApi;
|
|
92
|
+
twilight: TwilightApi;
|
|
93
|
+
wishlist: WishlistApi;
|
|
94
|
+
getHeaders: () => {
|
|
95
|
+
Accept: string | 'application/json, text/plain, */*',
|
|
96
|
+
"X-Requested-With": 'XMLHttpRequest',
|
|
97
|
+
"S-SOURCE": 'twilight',
|
|
98
|
+
"Store-Identifier"?: number,
|
|
99
|
+
currency?: string | 'SAR',
|
|
100
|
+
"accept-language"?: string | 'ar',
|
|
101
|
+
Authorization?: string
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {Category, Product, TwilightResponse} from "../common";
|
|
2
|
+
|
|
3
|
+
type offerType = 'buy_x_get_y' | 'percentage' | 'fixed_amount';
|
|
4
|
+
type paymentMethod = {
|
|
5
|
+
id: number;
|
|
6
|
+
slug: 'bank';
|
|
7
|
+
name: 'BankTransfer';
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export interface Offer {
|
|
11
|
+
id: number;
|
|
12
|
+
name: string;
|
|
13
|
+
message: string;
|
|
14
|
+
expiry_date: string | '2022-02-22 00:00:00';
|
|
15
|
+
formatted_date: string;
|
|
16
|
+
offer_type: offerType;
|
|
17
|
+
applied_to: 'order' | 'category' | 'product' | 'paymentMethod';
|
|
18
|
+
buy: {
|
|
19
|
+
type: 'product' | 'category';
|
|
20
|
+
quantity: number;
|
|
21
|
+
products?: Product[];
|
|
22
|
+
categories?: Category[];
|
|
23
|
+
min_amount?: number; //when offer_type != 'buy_x_get_y'
|
|
24
|
+
min_items?: number; //when offer_type != 'buy_x_get_y'
|
|
25
|
+
payment_methods: paymentMethod[];
|
|
26
|
+
},
|
|
27
|
+
get: {
|
|
28
|
+
products?: Product[];
|
|
29
|
+
categories?: Category[];
|
|
30
|
+
type: 'product' | 'category';
|
|
31
|
+
discount_type: 'free-product' | 'percentage';
|
|
32
|
+
quantity?: number;//when discount_type == 'percentage'
|
|
33
|
+
discount_amount?: number; //when offer_type != 'buy_x_get_y' or get.discount_type !='free-product'
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface OfferDetailsResponse extends TwilightResponse {
|
|
38
|
+
data: Offer[] | [];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export default interface OfferApi {
|
|
42
|
+
details: (product_id: number) => Promise<OfferDetailsResponse>;
|
|
43
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {Nullable, TwilightResponse} from "../common";
|
|
2
|
+
|
|
3
|
+
type ProductOption = { [key: number]: number | string | number[] };
|
|
4
|
+
|
|
5
|
+
export interface ProductPayload {
|
|
6
|
+
id: number;
|
|
7
|
+
quantity: 1 | number;
|
|
8
|
+
options?: Nullable<ProductOption>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface AvailabilityPayload {
|
|
12
|
+
id: number;
|
|
13
|
+
//💡 Following properties required for guests
|
|
14
|
+
email?: string;//required when request without mobile
|
|
15
|
+
country_code?: string | 'SA';//required when request without email
|
|
16
|
+
mobile?: string | '555555555';//required when request without email
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface GetPriceResponse extends TwilightResponse {
|
|
20
|
+
data: {
|
|
21
|
+
price: number;
|
|
22
|
+
regular_price: number; // you can check if regular_price > price means there is a special price for this product.
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default interface ProductApi {
|
|
27
|
+
getPrice: (data: /*product_id*/number | ProductPayload) => Promise<GetPriceResponse>;
|
|
28
|
+
availabilitySubscribe: (product_id: number | AvailabilityPayload) => Promise<TwilightResponse>;
|
|
29
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {Nullable, Product, TwilightResponse} from "../common";
|
|
2
|
+
|
|
3
|
+
type SortOption = {
|
|
4
|
+
id: "ourSuggest" | "bestSell" | "topRated" | "priceFromTopToLow" | "priceFromLowToTop";
|
|
5
|
+
name: string
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export interface SearchResponse extends TwilightResponse {
|
|
9
|
+
data: Product[];
|
|
10
|
+
cursor: {
|
|
11
|
+
current: number;
|
|
12
|
+
previous: Nullable<string>;
|
|
13
|
+
next: Nullable<string>;
|
|
14
|
+
count: number;
|
|
15
|
+
};
|
|
16
|
+
features?: { sorting?: true };
|
|
17
|
+
sort_options: SortOption[];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default interface SearchApi {
|
|
21
|
+
search: (query: string) => Promise<SearchResponse>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import {TwilightResponse} from "../common";
|
|
2
|
+
|
|
3
|
+
export default interface WishlistApi {
|
|
4
|
+
add: (product_id: number) => Promise<TwilightResponse>;
|
|
5
|
+
remove: (product_id: number) => Promise<TwilightResponse>;
|
|
6
|
+
toggle: (product_id: number) => Promise<TwilightResponse>;
|
|
7
|
+
}
|
package/types/common.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
type Nullable<T> = T | undefined | null | '';
|
|
2
|
+
type ProductType = 'product' | 'service' | 'group_products' | 'codes' | 'digital' | 'food' | 'donating';
|
|
3
|
+
type Rating = 1 | 2 | 3 | 4 | 5;
|
|
4
|
+
type RequestError = Error & { response: any }
|
|
5
|
+
type RequestErrorEvent = (callback: (error: RequestError | string) => void) => void;
|
|
6
|
+
type RequestErrorEventWithData<data> = (callback: (error: RequestError | string, data) => void) => void;
|
|
7
|
+
|
|
1
8
|
export interface Price {
|
|
2
9
|
amount: string;
|
|
3
10
|
currency: string;
|
|
@@ -12,14 +19,45 @@ export interface TwilightResponse {
|
|
|
12
19
|
error: Nullable<{
|
|
13
20
|
message: Nullable<string | 'alert.invalid_fields'>,
|
|
14
21
|
code: Nullable<any>
|
|
15
|
-
case: Nullable<string|'resend_counter'|'invalid_code'>
|
|
16
|
-
events:Nullable<string>
|
|
22
|
+
case: Nullable<string | 'resend_counter' | 'invalid_code'>
|
|
23
|
+
events: Nullable<string>
|
|
17
24
|
fields: Nullable<{
|
|
18
25
|
[key: string]: Array<string>
|
|
19
26
|
}>
|
|
20
27
|
}>
|
|
21
28
|
}
|
|
22
29
|
|
|
23
|
-
|
|
30
|
+
export interface Currency {
|
|
31
|
+
code: string| 'SAR';
|
|
32
|
+
name: string;
|
|
33
|
+
symbol: string;
|
|
34
|
+
amount?: number;
|
|
35
|
+
country_code?: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface Product {
|
|
39
|
+
id: number;
|
|
40
|
+
name: string;
|
|
41
|
+
type: ProductType;
|
|
42
|
+
promotion: {
|
|
43
|
+
title: Nullable<string>;
|
|
44
|
+
sub_title: Nullable<string>;
|
|
45
|
+
};
|
|
46
|
+
price: Price;
|
|
47
|
+
sale_price: Nullable<Price>;
|
|
48
|
+
regular_price: Price;
|
|
49
|
+
has_special_price: boolean;
|
|
50
|
+
status: 'sale' | 'out';
|
|
51
|
+
is_available: boolean;
|
|
52
|
+
sku: Nullable<string>;
|
|
53
|
+
currency: string | 'SAR';
|
|
54
|
+
url: string;
|
|
55
|
+
thumbnail: string;
|
|
56
|
+
calories: Nullable<number>;
|
|
57
|
+
}
|
|
24
58
|
|
|
25
|
-
|
|
59
|
+
export interface Category {
|
|
60
|
+
id: number;
|
|
61
|
+
name: string;
|
|
62
|
+
url: string;
|
|
63
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import {RequestError} from "../common";
|
|
2
|
+
import {SendCommentResponse} from "../api/comment";
|
|
3
|
+
|
|
4
|
+
export default interface CommentEvent {
|
|
5
|
+
onAdded: (callback: (response: SendCommentResponse) => void) => void;
|
|
6
|
+
onAdditionFailed: (callback: (error: RequestError) => void) => void;
|
|
7
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import {ChangeCurrencyResponse, ListCurrenciesResponse} from "../api/currency";
|
|
2
|
+
import {RequestErrorEvent} from "../common";
|
|
3
|
+
|
|
4
|
+
export default interface CurrencyEvent {
|
|
5
|
+
changed: (callback: (response: ChangeCurrencyResponse, currency: 'SAR' | string) => void) => void;
|
|
6
|
+
fetched: (callback: (response: ListCurrenciesResponse, currency: 'SAR' | string) => void) => void,
|
|
7
|
+
failed: RequestErrorEvent,
|
|
8
|
+
failedToFetch: RequestErrorEvent,
|
|
9
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {Nullable, RequestError} from "../common";
|
|
2
|
+
|
|
3
|
+
export interface requestPayload {
|
|
4
|
+
namespace: string | 'cart',
|
|
5
|
+
action: string | 'latest',
|
|
6
|
+
hook: string | 'latest',
|
|
7
|
+
url: string | 'cart/latest',
|
|
8
|
+
payload: {} | { params: {} },
|
|
9
|
+
method: 'get' | 'post' | 'put' | 'delete',
|
|
10
|
+
headers: Nullable<{}>,
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export default interface DocumentEvent {
|
|
14
|
+
onClick: (selector: string | ((event) => void), callback?: (event) => void) => void;
|
|
15
|
+
onChange: (selector: string | ((event) => void), callback?: (event) => void) => void;
|
|
16
|
+
onSubmit: (selector: string | ((event) => void), callback?: (event) => void) => void;
|
|
17
|
+
onKeyup: (selector: string | ((event) => void), callback?: (event) => void) => void;
|
|
18
|
+
onLeaving: (event: BeforeUnloadEvent) => boolean; //return false to show alert 'Changes you made may not be saved.'
|
|
19
|
+
onRequest: (payload: requestPayload) => void; //💡handy when there is need to prevent request by throwing an error `throw 'stop the request';`.
|
|
20
|
+
onRequestFailed: (payload: requestPayload, error?: RequestError) => void;
|
|
21
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SuccessFeedbackResponse,
|
|
3
|
+
OrderDetailsResponse,
|
|
4
|
+
FeedbackStorePayload,
|
|
5
|
+
FeedbackProductsPayload, FeedbackShippingPayload
|
|
6
|
+
} from "../api/feedback";
|
|
7
|
+
import {RequestErrorEventWithData} from "../common";
|
|
8
|
+
|
|
9
|
+
export default interface FeedbackEvent {
|
|
10
|
+
onOrderFetched: (callback: (response: OrderDetailsResponse, order_id: number) => void) => void;
|
|
11
|
+
onOrderNotFetched: RequestErrorEventWithData</*order_id*/number>;
|
|
12
|
+
onStoreRated: (callback: (response: SuccessFeedbackResponse, data: FeedbackStorePayload) => void) => void;
|
|
13
|
+
onStoreFailed: RequestErrorEventWithData</*data*/FeedbackStorePayload>;
|
|
14
|
+
onProductRated: (callback: (response: SuccessFeedbackResponse, data: FeedbackProductsPayload) => void) => void;
|
|
15
|
+
onProductFailed: RequestErrorEventWithData</*data*/FeedbackProductsPayload>;
|
|
16
|
+
onShippingRated: (callback: (response: SuccessFeedbackResponse, data: FeedbackShippingPayload) => void) => void;
|
|
17
|
+
onShippingFailed: RequestErrorEventWithData</*data*/FeedbackShippingPayload>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import {Nullable, RequestErrorEventWithData} from "../common";
|
|
2
|
+
import {GiftResponse} from "../api/gift";
|
|
3
|
+
|
|
4
|
+
export default interface GiftEvent {
|
|
5
|
+
onBuyingSucceeded: (callback: (response: GiftResponse, product_id: number) => void) => void;
|
|
6
|
+
onBuyingFailed: RequestErrorEventWithData</*product_id*/Nullable<number>>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import AuthEvent from "./auth";
|
|
2
|
+
import CartEvent from "./cart";
|
|
3
|
+
import GiftEvent from "./gift";
|
|
4
|
+
import OrderEvent from "./order";
|
|
5
|
+
import OfferEvent from "./offer";
|
|
6
|
+
import SearchEvent from "./search";
|
|
7
|
+
import CouponEvent from "./coupon";
|
|
8
|
+
import CommentEvent from "./comment";
|
|
9
|
+
import ProductEvent from "./product";
|
|
10
|
+
import ProfileEvent from "./profile";
|
|
11
|
+
import CurrencyEvent from "./currency";
|
|
12
|
+
import DocumentEvent from "./document";
|
|
13
|
+
import FeedbackEvent from "./feedback";
|
|
14
|
+
import WishlistEvent from "./wishlist";
|
|
15
|
+
import InfiniteScrollEvent from "./infiniteScroll";
|
|
16
|
+
import {EventEmitter2} from "eventemitter2";
|
|
17
|
+
import TwilightEvent from "./twilight";
|
|
18
|
+
|
|
19
|
+
export {
|
|
20
|
+
AuthEvent,
|
|
21
|
+
CartEvent,
|
|
22
|
+
GiftEvent,
|
|
23
|
+
OrderEvent,
|
|
24
|
+
OfferEvent,
|
|
25
|
+
SearchEvent,
|
|
26
|
+
CouponEvent,
|
|
27
|
+
CommentEvent,
|
|
28
|
+
ProductEvent,
|
|
29
|
+
ProfileEvent,
|
|
30
|
+
CurrencyEvent,
|
|
31
|
+
DocumentEvent,
|
|
32
|
+
FeedbackEvent,
|
|
33
|
+
TwilightEvent,
|
|
34
|
+
WishlistEvent,
|
|
35
|
+
InfiniteScrollEvent,
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default interface SallaEvent extends EventEmitter2 {
|
|
39
|
+
auth: AuthEvent,
|
|
40
|
+
cart: CartEvent,
|
|
41
|
+
gift: GiftEvent;
|
|
42
|
+
order: OrderEvent;
|
|
43
|
+
offer: OfferEvent;
|
|
44
|
+
search: SearchEvent;
|
|
45
|
+
coupon: CouponEvent;
|
|
46
|
+
comment: CommentEvent;
|
|
47
|
+
loyalty: any;//TODO::add types
|
|
48
|
+
product: ProductEvent;
|
|
49
|
+
profile: ProfileEvent;
|
|
50
|
+
currency: CurrencyEvent;
|
|
51
|
+
document: DocumentEvent;
|
|
52
|
+
feedback: FeedbackEvent;
|
|
53
|
+
twilight: TwilightEvent;
|
|
54
|
+
wishlist: WishlistEvent;
|
|
55
|
+
infiniteScroll: InfiniteScrollEvent
|
|
56
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @see https://infinite-scroll.com/events.html
|
|
3
|
+
*/
|
|
4
|
+
export default interface InfiniteScrollEvent {
|
|
5
|
+
onScrollThreshold: (callback: (event: Event) => void) => void;
|
|
6
|
+
onRequest: (callback: (event: Event, path: string, fetchPromise: Promise<any>) => void) => void;
|
|
7
|
+
onLoad: (callback: (event: Event, body: Body, path: string, response: Response) => void) => void;
|
|
8
|
+
onAppend: (callback: (event: Event, body: Body, path: string, items: NodeList, response: Response) => void) => void;
|
|
9
|
+
onError: (callback: (event: Event, error: Error, path: string, response: Response) => void) => void;
|
|
10
|
+
onLast: (callback: (event: Event, body: Body, path: string) => void) => void;
|
|
11
|
+
onHistory: (callback: (event: Event, title: string, path: string) => void) => void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import {OfferDetailsResponse} from "../api/offer";
|
|
2
|
+
import {RequestErrorEvent} from "../common";
|
|
3
|
+
import {OfferSummary} from "../api/cart";
|
|
4
|
+
|
|
5
|
+
export default interface OfferEvent {
|
|
6
|
+
onExisted: (callback: (offer: OfferSummary) => void) => void;
|
|
7
|
+
ondDetailsFetched: (callback: (response: OfferDetailsResponse) => void) => void;
|
|
8
|
+
onFetchDetailsFailed: RequestErrorEvent;
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import {GetPriceResponse} from "../api/product";
|
|
2
|
+
import {RequestErrorEventWithData, TwilightResponse} from "../common";
|
|
3
|
+
|
|
4
|
+
export default interface ProductEvent {
|
|
5
|
+
onPriceUpdated: (callback: (response: GetPriceResponse, product_id: number) => void) => void;
|
|
6
|
+
onPriceUpdateFailed: RequestErrorEventWithData</*product_id*/ number>;
|
|
7
|
+
onAvailabilitySubscribed: (callback: (response: TwilightResponse, product_id: number) => void) => void;
|
|
8
|
+
onAvailabilitySubscribeFailed: RequestErrorEventWithData</*product_id*/ number>;
|
|
9
|
+
}
|
package/types/event/profile.d.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import {UpdateProfileResponse} from "../api/profile";
|
|
2
|
-
import {
|
|
2
|
+
import { RequestErrorEvent} from "../common";
|
|
3
3
|
|
|
4
4
|
export default interface ProfileEvent {
|
|
5
|
-
updated: (response: UpdateProfileResponse) => void; //fire the event
|
|
6
|
-
updateFailed: (RequestError) => void;//fire the event
|
|
7
|
-
|
|
8
5
|
onUpdated: (callback: (response: UpdateProfileResponse) => void) => void;
|
|
9
|
-
onUpdateFailed:
|
|
6
|
+
onUpdateFailed: RequestErrorEvent;
|
|
10
7
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import {Nullable, RequestErrorEventWithData} from "../common";
|
|
2
|
+
import {SearchResponse} from "../api/search";
|
|
3
|
+
|
|
4
|
+
export default interface SearchEvent {
|
|
5
|
+
onFinished: (callback: (response: SearchResponse, query: Nullable<string>) => void) => void;
|
|
6
|
+
onFailed: RequestErrorEventWithData</*query*/Nullable<string>>;
|
|
7
|
+
}
|