@salla.sa/twilight 2.0.217 → 2.0.218
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/main.js +2 -2
- package/dist/cjs/main.js.map +1 -1
- package/dist/esm/main.js +2 -2
- package/dist/esm/main.js.map +1 -1
- package/package.json +1 -1
- 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.js +70 -0
- package/types/api/loyalty.js +50 -0
- package/types/api/offer.d.ts +43 -0
- package/types/api/order.js +94 -0
- package/types/api/product.d.ts +29 -0
- package/types/api/scope.js +54 -0
- package/types/api/search.d.ts +22 -0
- package/types/api/twilight.js +39 -0
- package/types/api/wishlist.d.ts +7 -0
- package/types/common.d.ts +40 -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.js +33 -0
- package/types/event/infiniteScroll.d.ts +12 -0
- package/types/event/loyalty.js +28 -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/scope.js +14 -0
- package/types/event/search.d.ts +7 -0
- package/types/event/twilight.js +32 -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 +1 -1
- package/types/index.d.ts +49 -29
- package/types/infinite-scroll.d.ts +19 -0
package/package.json
CHANGED
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,70 @@
|
|
|
1
|
+
import baseApi from './baseApi'
|
|
2
|
+
|
|
3
|
+
class GiftApi extends baseApi {
|
|
4
|
+
constructor(parent) {
|
|
5
|
+
super(parent);
|
|
6
|
+
this.namespace = 'gift';
|
|
7
|
+
this.endpoints = {
|
|
8
|
+
buy : '{id}/buy-as-gift',
|
|
9
|
+
};
|
|
10
|
+
this.webEndpoints = ['buy'];
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @see Object.prototype.canEventFireHook
|
|
14
|
+
*/
|
|
15
|
+
this.hooksSelectores = {
|
|
16
|
+
buy : 'gift::buy',
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
this.after_init();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Add item to cart
|
|
24
|
+
* 💡 If Quantity not passed will use 'quickAdd' ednpoint.
|
|
25
|
+
*
|
|
26
|
+
* @param {int|{element: Element, data: {}}|FormData|Object} prod_id
|
|
27
|
+
*/
|
|
28
|
+
buy(prodId) {
|
|
29
|
+
let data = this.getGiftRequestData(prodId);
|
|
30
|
+
|
|
31
|
+
if (!data.id) {
|
|
32
|
+
salla.gift.event.buyingFailed('There is no "id"!');
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return this.request(['buy', data.id], data.formData)
|
|
37
|
+
.then(function (response) {
|
|
38
|
+
salla.gift.event.buyingSucceeded(response, data.id);
|
|
39
|
+
return response;
|
|
40
|
+
})
|
|
41
|
+
.catch(function (error) {
|
|
42
|
+
salla.gift.event.buyingFailed(error, data.id);
|
|
43
|
+
throw error;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Extract ProductId & formData from Passed Object
|
|
50
|
+
* @param {int|Object|{element: Element, data: {}}} prodId
|
|
51
|
+
* @return {{formData: *, id: *}}
|
|
52
|
+
*/
|
|
53
|
+
getGiftRequestData(prodId) {
|
|
54
|
+
/**
|
|
55
|
+
* if prodId is Object, get data from it;
|
|
56
|
+
* @see Object.prototype.getElementSallaData
|
|
57
|
+
*/
|
|
58
|
+
let formData = prodId.data || (typeof prodId == 'object' ? prodId : undefined);
|
|
59
|
+
|
|
60
|
+
//try to get prodId from formData if it's existed
|
|
61
|
+
prodId = formData ? this.getPossibleValue(formData, ['prod_id', 'item_id', 'id']) : prodId;
|
|
62
|
+
formData = typeof formData == 'object' ? formData : undefined;
|
|
63
|
+
return {
|
|
64
|
+
id : prodId,
|
|
65
|
+
formData: formData,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export default GiftApi;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import baseApi from './baseApi'
|
|
2
|
+
|
|
3
|
+
class LoyalityApi extends baseApi {
|
|
4
|
+
constructor(parent) {
|
|
5
|
+
super(parent);
|
|
6
|
+
this.namespace = 'loyalty';
|
|
7
|
+
this.endpoints = {
|
|
8
|
+
exchange : 'cart/prize/exchange_loyalty_point',
|
|
9
|
+
};
|
|
10
|
+
this.webEndpoints = ['exchange'];
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @see Object.prototype.canEventFireHook
|
|
14
|
+
*/
|
|
15
|
+
// prefix will be added dynamically, for example 'data-'
|
|
16
|
+
this.hooksSelectores = {
|
|
17
|
+
exchange : 'loyalty::exchange',
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
this.after_init();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Add item to cart
|
|
25
|
+
* 💡 If Quantity not passed will use 'quickAdd' ednpoint.
|
|
26
|
+
*
|
|
27
|
+
* @param {int|{element: Element, data: {}}|FormData|Object} prod_id
|
|
28
|
+
*/
|
|
29
|
+
exchange(id) {
|
|
30
|
+
let data = id.data||{id : id};
|
|
31
|
+
|
|
32
|
+
if (!data.id) {
|
|
33
|
+
salla.loyalty.event.exchangeFailed('There is no "id"!');
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
data.loyalty_prize_id = data.id;
|
|
37
|
+
return this.request('exchange', data)
|
|
38
|
+
.then(function (response) {
|
|
39
|
+
salla.loyalty.event.exchangeSucceeded(response, data.id);
|
|
40
|
+
return response;
|
|
41
|
+
})
|
|
42
|
+
.catch(function (error) {
|
|
43
|
+
salla.loyalty.event.exchangeFailed(error, data.id);
|
|
44
|
+
throw error;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export default LoyalityApi;
|
|
@@ -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,94 @@
|
|
|
1
|
+
import baseApi from './baseApi'
|
|
2
|
+
|
|
3
|
+
class OrderApi extends baseApi {
|
|
4
|
+
constructor(parent) {
|
|
5
|
+
super(parent);
|
|
6
|
+
this.namespace = 'order';
|
|
7
|
+
this.endpoints = {
|
|
8
|
+
cancel : 'orders/cancel/{id}',
|
|
9
|
+
reOrder: 'reorder/{id}',
|
|
10
|
+
send : 'orders/send/{id}'
|
|
11
|
+
};
|
|
12
|
+
this.endpointsMethods = {
|
|
13
|
+
reOrder: 'get',
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @see Object.prototype.canEventFireHook
|
|
18
|
+
*/
|
|
19
|
+
this.hooksSelectores = {
|
|
20
|
+
cancel : 'order::cancel',
|
|
21
|
+
reOrder: 'order::re.order',
|
|
22
|
+
show : 'order::show',
|
|
23
|
+
send : 'order::send',
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
this.after_init();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @param orderId
|
|
31
|
+
* @param url
|
|
32
|
+
*/
|
|
33
|
+
show(orderId, url = null) {
|
|
34
|
+
//important for mobile apps
|
|
35
|
+
salla.event.dispatch('mobile::order.placed', {order_id: orderId || salla.config.get('page.id')});
|
|
36
|
+
location.href = url || location.href.replace('thankyou', 'order');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @param {int} orderId
|
|
41
|
+
* @return {Promise}
|
|
42
|
+
*/
|
|
43
|
+
cancel(orderId) {
|
|
44
|
+
orderId = orderId || salla.config.get('page.id');
|
|
45
|
+
return this.request(['cancel', orderId], {params: {has_apple_pay: !!window.ApplePaySession}})
|
|
46
|
+
.then(function (response) {
|
|
47
|
+
salla.event.order.canceled(response, orderId);
|
|
48
|
+
return response;
|
|
49
|
+
})
|
|
50
|
+
.catch(function (error) {
|
|
51
|
+
salla.event.order.notCanceled(error, orderId);
|
|
52
|
+
throw error;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @param {int} orderId
|
|
58
|
+
* @return {Promise}
|
|
59
|
+
*/
|
|
60
|
+
reOrder(orderId) {
|
|
61
|
+
orderId = orderId || salla.config.get('page.id');
|
|
62
|
+
return this.request(['reOrder', orderId])
|
|
63
|
+
.then(function (response) {
|
|
64
|
+
salla.storage.set('cart', {id: response.data.cart_id, user_id: salla.config.get('user.id')});
|
|
65
|
+
salla.event.order.reOrdered(response, orderId);
|
|
66
|
+
window.location.href = response.data.url;
|
|
67
|
+
return response;
|
|
68
|
+
})
|
|
69
|
+
.catch(function (error) {
|
|
70
|
+
salla.event.order.reOrderFailed(error, orderId);
|
|
71
|
+
throw error;
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
send(data) {
|
|
76
|
+
let order_id = this.getPossibleValue(data, ['id']) || salla.config.get('page.id');
|
|
77
|
+
if (!order_id || isNaN(order_id)) {
|
|
78
|
+
let message = 'There is no id!';
|
|
79
|
+
salla.order.event.notSent(message);
|
|
80
|
+
return this.errorPromise(message);
|
|
81
|
+
}
|
|
82
|
+
return this.request(['send', order_id], data)
|
|
83
|
+
.then(res => {
|
|
84
|
+
salla.event.order.sent(res, order_id);
|
|
85
|
+
return res;
|
|
86
|
+
}).catch(error => {
|
|
87
|
+
salla.event.order.notSent(error, order_id);
|
|
88
|
+
throw error;
|
|
89
|
+
})
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export default OrderApi;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {Nullable, TwilightResponse} from "../common";
|
|
2
|
+
|
|
3
|
+
type ProductOption = { [key: number]: [value: 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,54 @@
|
|
|
1
|
+
import baseApi from './baseApi';
|
|
2
|
+
|
|
3
|
+
class ScopeApi extends baseApi {
|
|
4
|
+
constructor(parent) {
|
|
5
|
+
super(parent);
|
|
6
|
+
this.namespace = 'scope';
|
|
7
|
+
this.endpoints = {
|
|
8
|
+
getAll : '/scopes',
|
|
9
|
+
submit : '/scope',
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
this.webEndpoints = ['getAll','submit'];
|
|
13
|
+
|
|
14
|
+
this.endpointsMethods = {
|
|
15
|
+
getAll : 'get',
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
this.after_init();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Getting All Shipment Scopes Data
|
|
23
|
+
*
|
|
24
|
+
* @return {Promise}
|
|
25
|
+
*/
|
|
26
|
+
getAll() {
|
|
27
|
+
return this.request('getAll', {'from' : 'header'})
|
|
28
|
+
.then(function (response) {
|
|
29
|
+
console.log(response);
|
|
30
|
+
return response;
|
|
31
|
+
})
|
|
32
|
+
.catch(function (error) {
|
|
33
|
+
throw error;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Submit Chosen scope
|
|
39
|
+
*
|
|
40
|
+
* @return {Promise}
|
|
41
|
+
*/
|
|
42
|
+
submit(param) {
|
|
43
|
+
return this.request('submit', param)
|
|
44
|
+
.then(function (response) {
|
|
45
|
+
console.log(response);
|
|
46
|
+
return response;
|
|
47
|
+
})
|
|
48
|
+
.catch(function (error) {
|
|
49
|
+
throw error;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export default ScopeApi;
|
|
@@ -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,39 @@
|
|
|
1
|
+
import baseApi from './baseApi'
|
|
2
|
+
import SallaInit from '../lib/salla-init'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* This class is different than other classes in api,
|
|
6
|
+
* the purpose of this class is to be able calling in method in it be firing an event from backend ex: twilight::init
|
|
7
|
+
*/
|
|
8
|
+
class TwilightApi extends baseApi {
|
|
9
|
+
constructor(parent) {
|
|
10
|
+
super(parent);
|
|
11
|
+
this.namespace = 'twilight';
|
|
12
|
+
|
|
13
|
+
this.hooksSelectores = {
|
|
14
|
+
init: 'twilight::init',
|
|
15
|
+
api : 'twilight::api', //will be fired almost in every request to backend via ajax
|
|
16
|
+
};
|
|
17
|
+
this.after_init();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @param {TwilightConfig} config
|
|
22
|
+
*/
|
|
23
|
+
init(config) {
|
|
24
|
+
|
|
25
|
+
let events = config?.events;
|
|
26
|
+
if (!this.initiated) {
|
|
27
|
+
delete config.events;
|
|
28
|
+
new SallaInit(config);
|
|
29
|
+
}
|
|
30
|
+
events && salla.event.dispatchEvents(events);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
api(payload) {
|
|
34
|
+
let events = payload?.events;
|
|
35
|
+
events && salla.event.dispatchEvents(events);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export default TwilightApi;
|
|
@@ -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,43 @@ 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
|
+
name: string;
|
|
32
|
+
code: string | 'SAR';
|
|
33
|
+
symbol: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface Product {
|
|
37
|
+
id: number;
|
|
38
|
+
name: string;
|
|
39
|
+
type: ProductType;
|
|
40
|
+
promotion: {
|
|
41
|
+
title: Nullable<string>;
|
|
42
|
+
sub_title: Nullable<string>;
|
|
43
|
+
};
|
|
44
|
+
price: Price;
|
|
45
|
+
sale_price: Nullable<Price>;
|
|
46
|
+
regular_price: Price;
|
|
47
|
+
has_special_price: boolean;
|
|
48
|
+
status: 'sale' | 'out';
|
|
49
|
+
is_available: boolean;
|
|
50
|
+
sku: Nullable<string>;
|
|
51
|
+
currency: string | 'SAR';
|
|
52
|
+
url: string;
|
|
53
|
+
thumbnail: string;
|
|
54
|
+
calories: Nullable<number>;
|
|
55
|
+
}
|
|
24
56
|
|
|
25
|
-
|
|
57
|
+
export interface Category {
|
|
58
|
+
id: number;
|
|
59
|
+
name: string;
|
|
60
|
+
url: string;
|
|
61
|
+
}
|
|
@@ -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
|
+
}
|