@salla.sa/twilight 2.0.274 → 2.0.276
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 +2 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +2 -2
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
- package/types/actions.d.ts +2 -3
- package/types/api/cart/response.d.ts +0 -1
- package/types/api/index.d.ts +2 -5
- package/types/api/order.d.ts +1 -0
- package/types/api/product/index.d.ts +14 -0
- package/types/api/product/request.d.ts +35 -0
- package/types/api/{offer.d.ts → product/response.d.ts} +29 -10
- package/types/event/index.d.ts +5 -8
- package/types/event/product.d.ts +10 -5
- package/types/api/product.d.ts +0 -65
- package/types/event/offer.d.ts +0 -9
package/package.json
CHANGED
package/types/actions.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
-
AuthApi, CartApi, CommentApi, CurrencyApi, DocumentApi, RatingApi, GiftApi,
|
|
2
|
+
AuthApi, CartApi, CommentApi, CurrencyApi, DocumentApi, RatingApi, GiftApi, OrderApi,
|
|
3
3
|
ProductApi, ProfileApi, TwilightApi, WishlistApi, LoyaltyApi
|
|
4
4
|
} from "./api";
|
|
5
5
|
import {
|
|
6
|
-
AuthEvent, CartEvent, CommentEvent, CurrencyEvent, DocumentEvent, RatingEvent, GiftEvent,
|
|
6
|
+
AuthEvent, CartEvent, CommentEvent, CurrencyEvent, DocumentEvent, RatingEvent, GiftEvent,
|
|
7
7
|
InfiniteScrollEvent, OrderEvent, ProductEvent, ProfileEvent, TwilightEvent, WishlistEvent, LoyaltyEvent
|
|
8
8
|
} from "./event";
|
|
9
9
|
|
|
@@ -12,7 +12,6 @@ export default interface SallaActions {
|
|
|
12
12
|
auth: AuthApi & { api: AuthApi, event: AuthEvent };
|
|
13
13
|
gift: GiftApi & { api: GiftApi, event: GiftEvent };
|
|
14
14
|
order: OrderApi & { api: OrderApi, event: OrderEvent };
|
|
15
|
-
offer: OfferApi & { api: OfferApi, event: OfferEvent };
|
|
16
15
|
rating: RatingApi & { api: RatingApi, event: RatingEvent };
|
|
17
16
|
comment: CommentApi & { api: CommentApi, event: CommentEvent };
|
|
18
17
|
loyalty: LoyaltyApi & { api: LoyaltyApi, event: LoyaltyEvent };
|
package/types/api/index.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ import CartApi from "./cart";
|
|
|
3
3
|
import AuthApi from "./auth";
|
|
4
4
|
import GiftApi from "./gift";
|
|
5
5
|
import OrderApi from "./order";
|
|
6
|
-
import OfferApi from "./offer";
|
|
7
6
|
import RatingApi from "./rating";
|
|
8
7
|
import CommentApi from "./comment";
|
|
9
8
|
import LoyaltyApi from "./loyalty";
|
|
@@ -19,7 +18,6 @@ export {
|
|
|
19
18
|
AuthApi,
|
|
20
19
|
GiftApi,
|
|
21
20
|
OrderApi,
|
|
22
|
-
OfferApi,
|
|
23
21
|
RatingApi,
|
|
24
22
|
CommentApi,
|
|
25
23
|
LoyaltyApi,
|
|
@@ -53,12 +51,12 @@ export type ApiActionName =
|
|
|
53
51
|
| 'order.cancel'
|
|
54
52
|
| 'order.reOrder'
|
|
55
53
|
| 'order.send'
|
|
56
|
-
| 'offer.increase'
|
|
57
|
-
| 'offer.details'
|
|
58
54
|
| 'product.getPrice'
|
|
59
55
|
| 'product.availabilitySubscribe'
|
|
60
56
|
| 'product.purchaseNow'
|
|
61
57
|
| 'product.search'
|
|
58
|
+
| 'product.categories'
|
|
59
|
+
| 'product.offers'
|
|
62
60
|
| 'profile.update'
|
|
63
61
|
| 'comment.add'
|
|
64
62
|
| 'currency.change'
|
|
@@ -77,7 +75,6 @@ export default interface SallaApi extends Axios {
|
|
|
77
75
|
auth: AuthApi;
|
|
78
76
|
gift: GiftApi;
|
|
79
77
|
order: OrderApi;
|
|
80
|
-
offer: OfferApi;
|
|
81
78
|
rating: RatingApi;
|
|
82
79
|
comment: CommentApi;
|
|
83
80
|
loyalty: LoyaltyApi;
|
package/types/api/order.d.ts
CHANGED
|
@@ -11,4 +11,5 @@ export default interface OrderApi {
|
|
|
11
11
|
createCartFromOrder: (order_id?: number) => Promise<CreateCartFromOrderResponse>;
|
|
12
12
|
cancel: (order_id?: number) => Promise<SuccessResponse>;
|
|
13
13
|
sendInvoice: (order_id?: number) => Promise<SuccessResponse>;
|
|
14
|
+
show: (payload: { order_id: number, url: string }) => Promise<void>; //should be called from thank you page to trigger native order details page in apps
|
|
14
15
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {SuccessResponse} from "../../common";
|
|
2
|
+
import {ProductResponse} from "./response";
|
|
3
|
+
import {ProductRequest} from "./request";
|
|
4
|
+
|
|
5
|
+
export * from "./request";
|
|
6
|
+
export * from "./response";
|
|
7
|
+
|
|
8
|
+
export default interface ProductApi {
|
|
9
|
+
getPrice: (data: /*product_id*/number | ProductRequest.addItem) => Promise<ProductResponse.getPrice>;
|
|
10
|
+
availabilitySubscribe: (product_id: number | ProductRequest.availability) => Promise<SuccessResponse>;
|
|
11
|
+
search: (keyword: string | ProductRequest.search) => Promise<ProductResponse.search>;
|
|
12
|
+
categories: (categoryId?: number) => Promise<ProductResponse.categories>; //get all categories or sub_categories
|
|
13
|
+
offers: (product_id: number) => Promise<ProductResponse.offers>; //get all categories or sub_categories
|
|
14
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export interface Category {
|
|
2
|
+
id: string;
|
|
3
|
+
id_: number;
|
|
4
|
+
name: string;
|
|
5
|
+
url: string;
|
|
6
|
+
sub_categories: Category[];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export type ProductOption = { [key: number]: number | string | number[] };
|
|
10
|
+
|
|
11
|
+
export namespace ProductRequest {
|
|
12
|
+
export interface addItem {
|
|
13
|
+
id: number;
|
|
14
|
+
quantity: 1 | number;
|
|
15
|
+
options?: ProductOption;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface search {
|
|
19
|
+
query: string;
|
|
20
|
+
type?: 'keyword' | 'tag';//default => 'keyword'
|
|
21
|
+
sort_by?: 'ourSuggest' | 'default' | 'bestSell' | 'topRated' | 'priceFromTopToLow' | 'priceFromLowToTop'; //default => 'ourSuggest'
|
|
22
|
+
per_page?: 32 | number;//max 50
|
|
23
|
+
brands?: number[];
|
|
24
|
+
categories?: number[];// max 5 ids
|
|
25
|
+
branches?: number[];// max 5 ids
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface availability {
|
|
29
|
+
id: number;
|
|
30
|
+
//💡 Following properties required for guests
|
|
31
|
+
email?: string;//required when request without mobile
|
|
32
|
+
country_code?: string | 'SA';//required when request without email
|
|
33
|
+
phone?: string | '555555555';//required when request without email
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import {Category, Product, SuccessResponse} from "
|
|
2
|
-
|
|
1
|
+
import {Category as ShortCategory, Product, SuccessResponse} from "../../common";
|
|
2
|
+
import {Category} from "./request";
|
|
3
3
|
type offerType = 'buy_x_get_y' | 'percentage' | 'fixed_amount';
|
|
4
4
|
type paymentMethod = {
|
|
5
5
|
id: number;
|
|
6
6
|
slug: 'bank';
|
|
7
7
|
name: 'BankTransfer';
|
|
8
8
|
};
|
|
9
|
-
|
|
10
9
|
export interface Offer {
|
|
11
10
|
id: number;
|
|
12
11
|
name: string;
|
|
@@ -19,14 +18,14 @@ export interface Offer {
|
|
|
19
18
|
type: 'product' | 'category';
|
|
20
19
|
quantity: number;
|
|
21
20
|
products?: Product[];
|
|
22
|
-
categories?:
|
|
21
|
+
categories?: ShortCategory[];
|
|
23
22
|
min_amount?: number; //when offer_type != 'buy_x_get_y'
|
|
24
23
|
min_items?: number; //when offer_type != 'buy_x_get_y'
|
|
25
24
|
payment_methods: paymentMethod[];
|
|
26
25
|
};
|
|
27
26
|
get: {
|
|
28
27
|
products?: Product[];
|
|
29
|
-
categories?:
|
|
28
|
+
categories?: ShortCategory[];
|
|
30
29
|
type: 'product' | 'category';
|
|
31
30
|
discount_type: 'free-product' | 'percentage';
|
|
32
31
|
quantity?: number;//when discount_type == 'percentage'
|
|
@@ -34,10 +33,30 @@ export interface Offer {
|
|
|
34
33
|
}
|
|
35
34
|
}
|
|
36
35
|
|
|
37
|
-
export
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
export namespace ProductResponse {
|
|
37
|
+
export interface search extends SuccessResponse {
|
|
38
|
+
data: Product[];
|
|
39
|
+
cursor: {
|
|
40
|
+
current: number;
|
|
41
|
+
previous?: string;
|
|
42
|
+
next?: string;
|
|
43
|
+
count: number;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
40
46
|
|
|
41
|
-
export
|
|
42
|
-
|
|
47
|
+
export interface getPrice extends SuccessResponse {
|
|
48
|
+
data: {
|
|
49
|
+
price: number;
|
|
50
|
+
regular_price: number;
|
|
51
|
+
has_sale_price: boolean;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface categories extends SuccessResponse {
|
|
56
|
+
data: Category | Category[]; //single category when getting subCategories by passing categoryId
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface offers extends SuccessResponse {
|
|
60
|
+
data: Offer[] | [];
|
|
61
|
+
}
|
|
43
62
|
}
|
package/types/event/index.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import AuthEvent from "./auth";
|
|
|
2
2
|
import CartEvent from "./cart";
|
|
3
3
|
import GiftEvent from "./gift";
|
|
4
4
|
import OrderEvent from "./order";
|
|
5
|
-
import OfferEvent from "./offer";
|
|
6
5
|
import RatingEvent from "./rating";
|
|
7
6
|
import CommentEvent from "./comment";
|
|
8
7
|
import LoyaltyEvent from "./loyalty";
|
|
@@ -62,11 +61,6 @@ export type EventName = string
|
|
|
62
61
|
| 'order::re.order.failed'
|
|
63
62
|
| 'order::invoice.sent'
|
|
64
63
|
| 'order::invoice.not.sent'
|
|
65
|
-
| 'offer::existed'
|
|
66
|
-
| 'offer::increase'
|
|
67
|
-
| 'offer::increase.failed'
|
|
68
|
-
| 'offer::fetch.details.failed'
|
|
69
|
-
| 'offer::details.fetched'
|
|
70
64
|
| 'rating::order.not.fetched'
|
|
71
65
|
| 'rating::order.fetched'
|
|
72
66
|
| 'rating::store.rated'
|
|
@@ -81,6 +75,11 @@ export type EventName = string
|
|
|
81
75
|
| 'product::availability.subscribe.failed'
|
|
82
76
|
| 'product::search.failed'
|
|
83
77
|
| 'product::search.results'
|
|
78
|
+
| 'product::offers.existed'
|
|
79
|
+
| 'product::fetch.offers.failed'
|
|
80
|
+
| 'product::offers.fetched'
|
|
81
|
+
| 'product::categories.fetched'
|
|
82
|
+
| 'product::categories.failed'
|
|
84
83
|
| 'profile::updated'
|
|
85
84
|
| 'profile::update.failed'
|
|
86
85
|
| 'profile::mobile.updated'
|
|
@@ -112,7 +111,6 @@ export {
|
|
|
112
111
|
CartEvent,
|
|
113
112
|
GiftEvent,
|
|
114
113
|
OrderEvent,
|
|
115
|
-
OfferEvent,
|
|
116
114
|
RatingEvent,
|
|
117
115
|
CommentEvent,
|
|
118
116
|
LoyaltyEvent,
|
|
@@ -130,7 +128,6 @@ export default interface SallaEvent extends EventEmitter2 {
|
|
|
130
128
|
cart: CartEvent;
|
|
131
129
|
gift: GiftEvent;
|
|
132
130
|
order: OrderEvent;
|
|
133
|
-
offer: OfferEvent;
|
|
134
131
|
rating: RatingEvent;
|
|
135
132
|
comment: CommentEvent;
|
|
136
133
|
loyalty: LoyaltyEvent;
|
package/types/event/product.d.ts
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {RequestError, RequestErrorEventWithData, SuccessResponse} from "../common";
|
|
1
|
+
import {ProductResponse} from "../api/product";
|
|
2
|
+
import {RequestError, RequestErrorEvent, RequestErrorEventWithData, SuccessResponse} from "../common";
|
|
3
|
+
import {OfferSummary} from "../api/cart";
|
|
3
4
|
|
|
4
5
|
export default interface ProductEvent {
|
|
5
|
-
onPriceUpdated: (callback: (response:
|
|
6
|
+
onPriceUpdated: (callback: (response: ProductResponse.getPrice, product_id: number) => void) => void;
|
|
6
7
|
onPriceUpdateFailed: RequestErrorEventWithData</*product_id*/ number>;
|
|
7
8
|
onAvailabilitySubscribed: (callback: (response: SuccessResponse, product_id: number) => void) => void;
|
|
8
9
|
onAvailabilitySubscribeFailed: RequestErrorEventWithData</*product_id*/ number>;
|
|
9
|
-
onCategoriesFetched: (callback: (response:
|
|
10
|
+
onCategoriesFetched: (callback: (response: ProductResponse.categories) => void) => void;
|
|
10
11
|
onCategoriesFailed: RequestError;
|
|
11
|
-
onSearchResults: (callback: (response:
|
|
12
|
+
onSearchResults: (callback: (response: ProductResponse.search, query?: string) => void) => void;
|
|
12
13
|
onSearchFailed: RequestErrorEventWithData</*query*/string|undefined>;
|
|
14
|
+
|
|
15
|
+
onOffersExisted: (callback: (offer: OfferSummary) => void) => void;
|
|
16
|
+
ondOffersFetched: (callback: (response: ProductResponse.offers) => void) => void;
|
|
17
|
+
onFetchOffersFailed: RequestErrorEvent;
|
|
13
18
|
}
|
package/types/api/product.d.ts
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import {Product, SuccessResponse} 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?: ProductOption;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface SearchPayload {
|
|
12
|
-
query: string;
|
|
13
|
-
type?: 'keyword' | 'tag';//default => 'keyword'
|
|
14
|
-
sort_by?: 'ourSuggest' | 'default' | 'bestSell' | 'topRated' | 'priceFromTopToLow' | 'priceFromLowToTop'; //default => 'ourSuggest'
|
|
15
|
-
per_page?: 32 | number;//max 50
|
|
16
|
-
brands?: number[];
|
|
17
|
-
categories?: number[];// max 5 ids
|
|
18
|
-
branches?: number[];// max 5 ids
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface AvailabilityPayload {
|
|
22
|
-
id: number;
|
|
23
|
-
//💡 Following properties required for guests
|
|
24
|
-
email?: string;//required when request without mobile
|
|
25
|
-
country_code?: string | 'SA';//required when request without email
|
|
26
|
-
phone?: string | '555555555';//required when request without email
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface ProductsSearchResponse extends SuccessResponse {
|
|
30
|
-
data: Product[];
|
|
31
|
-
cursor: {
|
|
32
|
-
current: number;
|
|
33
|
-
previous?: string;
|
|
34
|
-
next?: string;
|
|
35
|
-
count: number;
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
export interface GetPriceResponse extends SuccessResponse {
|
|
41
|
-
data: {
|
|
42
|
-
price: number;
|
|
43
|
-
regular_price: number;
|
|
44
|
-
has_sale_price: boolean;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export interface Category {
|
|
49
|
-
id: string;
|
|
50
|
-
id_: number;
|
|
51
|
-
name: string;
|
|
52
|
-
url: string;
|
|
53
|
-
sub_categories: Category[];
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export interface GetCategoriesResponse extends SuccessResponse {
|
|
57
|
-
data: Category | Category[]; //single category when getting subCategories by passing categoryId
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export default interface ProductApi {
|
|
61
|
-
getPrice: (data: /*product_id*/number | ProductPayload) => Promise<GetPriceResponse>;
|
|
62
|
-
availabilitySubscribe: (product_id: number | AvailabilityPayload) => Promise<SuccessResponse>;
|
|
63
|
-
search: (keyword: string | SearchPayload) => Promise<ProductsSearchResponse>;
|
|
64
|
-
categories: (categoryId?: number) => Promise<GetCategoriesResponse>; //get all categories or sub_categories
|
|
65
|
-
}
|
package/types/event/offer.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
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
|
-
}
|