@salla.sa/twilight 2.0.208 → 2.0.210

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salla.sa/twilight",
3
- "version": "2.0.208",
3
+ "version": "2.0.210",
4
4
  "description": "Salla Theme Toolkit, Webcomponents, Events, Requests, Utils",
5
5
  "main": "dist/cjs/main.js",
6
6
  "module": "dist/esm/main.js",
@@ -9,7 +9,7 @@
9
9
  "postinstall": "node ./postInstall.js",
10
10
  "prepublishOnly": "rollup --config",
11
11
  "build": "npx rollup --config",
12
- "watch": "npx rollup --watch -config"
12
+ "watch": "npx rollup --watch --config"
13
13
  },
14
14
  "keywords": [
15
15
  "salla",
@@ -1,5 +1,5 @@
1
1
  import {Price} from "../../common";
2
- import {CartItem} from "../../cartItem";
2
+ import {CartItem} from "./item";
3
3
 
4
4
  export interface CartDetailsResponse {
5
5
  status: number;
File without changes
File without changes
@@ -0,0 +1,70 @@
1
+ import {CartDetailsResponse} from "./cart/cart-details-response";
2
+ import {Nullable} from "../common";
3
+
4
+ export interface itemOffer {
5
+ discount: number,
6
+ is_free: boolean,
7
+ names: string
8
+ }
9
+
10
+ export interface CartItem {
11
+ id: number,
12
+ product_id: number,
13
+ product_price: number,
14
+ price: number,
15
+ total: number,
16
+ is_available: true,
17
+ offer: Nullable<itemOffer>,
18
+ quantity: number,
19
+ total_special_price: number,
20
+ special_price: number
21
+ }
22
+
23
+ export interface CartSummary {
24
+ real_shipping_cost: number,
25
+ free_shipping_bar: {
26
+ minimum_amount: number,
27
+ has_free_shipping: boolean,
28
+ percent: number | 0 | 100,
29
+ remaining: number
30
+ },
31
+ sub_total: number,
32
+ discount: number,
33
+ total: number,
34
+ count: number,
35
+ items: Nullable<CartItem[]>,
36
+ }
37
+
38
+ export interface OfferSummary {
39
+ id: number,
40
+ product_id: number,
41
+ }
42
+
43
+ export interface CartUpdatedData {
44
+ product_id: Nullable<number>,
45
+ offer: Nullable<OfferSummary>,
46
+ googleTags: string,
47
+ cart: CartSummary
48
+ }
49
+
50
+ export interface CartUpdateResponse {
51
+ data: CartUpdatedData,
52
+ status: 200,
53
+ success: boolean,
54
+ message: string,
55
+ }
56
+
57
+ export interface AddToCartResponse extends CartUpdateResponse {
58
+ }
59
+
60
+ export interface UpdateCartItemResponse extends CartUpdateResponse {
61
+ }
62
+
63
+ export interface DeleteCartItemResponse extends CartUpdateResponse {
64
+ }
65
+
66
+ export default interface CartApi {
67
+ latest: () => Promise<{ status: number; success: boolean; data: { cart_id: number }; message: string; } | any>,
68
+ generate: () => Promise<any>,
69
+ details: () => Promise<CartDetailsResponse | any>,
70
+ }
@@ -0,0 +1,12 @@
1
+ import {CartUpdateResponse} from "./cart";
2
+
3
+ export interface AddCouponResponse extends CartUpdateResponse {
4
+ }
5
+
6
+ export interface RemoveCouponResponse extends CartUpdateResponse {
7
+ }
8
+
9
+ export default interface CouponApi {
10
+ add: (coupon: string) => Promise<AddCouponResponse>;
11
+ remove: () => Promise<RemoveCouponResponse>;
12
+ }
package/types/common.d.ts CHANGED
@@ -1,4 +1,8 @@
1
1
  export interface Price {
2
2
  amount: string;
3
3
  currency: string;
4
- }
4
+ }
5
+
6
+ type Nullable<T> = T | undefined | null;
7
+
8
+ type RequestError = Error & { response: any }
@@ -0,0 +1,13 @@
1
+ import {
2
+ CartSummary,
3
+ AddToCartResponse,
4
+ UpdateCartItemResponse,
5
+ DeleteCartItemResponse
6
+ } from "../api/cart/responses";
7
+
8
+ export default interface CartEvent {
9
+ onUpdated: (callback: (cartSummery: CartSummary) => void) => void,
10
+ onItemAdded: (callback: (response: AddToCartResponse, product_id: number) => void) => void,
11
+ onItemUpdated: (callback: (response: UpdateCartItemResponse, product_id: number) => void) => void,
12
+ onItemDeleted: (callback: (response: DeleteCartItemResponse, product_id: number) => void) => void,
13
+ }
@@ -0,0 +1,9 @@
1
+ import {AddCouponResponse, RemoveCouponResponse} from "../api/coupon";
2
+ import {Nullable, RequestError} from "../common";
3
+
4
+ export default interface CouponEvent {
5
+ onAdded: (callback: (response: AddCouponResponse, cart_id: number) => void) => void,
6
+ onRemoved: (callback: (response: RemoveCouponResponse, cart_id: number) => void) => void,
7
+ onAddedFailed: (callback: (error: RequestError, cart_id: Nullable<number>) => void) => void,
8
+ onRemovedFailed: (callback: (error: RequestError, cart_id: Nullable<number>) => void) => void,
9
+ }
@@ -0,0 +1,21 @@
1
+ import {Price} from "../common";
2
+
3
+ export interface SallaHelpers {
4
+ //Numbers helpers
5
+ digitsOnly: (num: string | number) => number,
6
+ inputDigitsOnly: (input: string | HTMLInputElement) => number,
7
+ number: () => number,
8
+ money: (num: number | Price) => string,
9
+
10
+ //Nested objects helpers
11
+ setNested: () => number,
12
+ getNested: () => number,
13
+ inputData: () => number,
14
+
15
+ //Url helpers
16
+ url: () => string,
17
+ addParamToUrl: () => string,
18
+
19
+ //other
20
+ debounce: () => number,
21
+ }
package/types/index.d.ts CHANGED
@@ -1,7 +1,11 @@
1
- import CartApi from "./api/cart-api";
1
+ import CartApi from "./api/cart";
2
2
  import {SallaConfig} from "./lib/salla-config";
3
3
  import {Axios} from "axios";
4
4
  import {Price} from "./common";
5
+ import {SallaHelpers} from "./helpers/salla-helpers";
6
+ import CartEvent from "./event/cart";
7
+ import CouponEvent from "./event/coupon";
8
+ import CouponApi from "./api/coupon";
5
9
 
6
10
  export * from "./all";
7
11
 
@@ -14,7 +18,7 @@ export interface salla {
14
18
  order: any;
15
19
  offer: any;
16
20
  search: any;
17
- coupon: any;
21
+ coupon: CouponApi;
18
22
  comment: any;
19
23
  loyalty: any;
20
24
  product: any;
@@ -26,18 +30,18 @@ export interface salla {
26
30
  };
27
31
  event: string;
28
32
  infiniteScroll: string;
29
- helpers: string;
33
+ helpers: SallaHelpers;
30
34
  config: SallaConfig;
31
35
  localStore: string;
32
36
 
33
37
  //Aliases
34
- cart: { api: CartApi, event: any };
38
+ cart: { api: CartApi, event: CartEvent };
35
39
  auth: { api: any, event: any };
36
40
  gift: { api: any, event: any };
37
41
  order: { api: any, event: any };
38
42
  offer: { api: any, event: any };
39
43
  search: { api: any, event: any };
40
- coupon: { api: any, event: any };
44
+ coupon: { api: CouponApi, event: CouponEvent };
41
45
  comment: { api: any, event: any };
42
46
  loyalty: { api: any, event: any };
43
47
  product: { api: any, event: any };
@@ -1,57 +0,0 @@
1
- import {Price} from "../../common";
2
-
3
- export interface Offer {
4
- discount: number;
5
- price_after_discount: Price;
6
- is_free: boolean;
7
- names: string;
8
- total_product_after_discount: Price;
9
- offer_names: string;
10
- total_product_after_discount_formatted: string;
11
- }
12
-
13
- export interface Item {
14
- id: number;
15
- url: string;
16
- cart_id: number;
17
- quantity: number;
18
- isAvailable: boolean;
19
- onSale: boolean;
20
- options_data: any[];
21
- notes: string;
22
- product_id: number;
23
- product_name: string;
24
- product_currency: string;
25
- isCustomized: boolean;
26
- product_image: string;
27
- product_quantity: number;
28
- product_maximum_quantity_per_order?: any;
29
- product_available_quantity: number;
30
- uploaded_files?: any;
31
- currency: string;
32
- enable_upload_image: boolean;
33
- enable_note: boolean;
34
- has_options: boolean;
35
- offer: Offer;
36
- has_special_price: boolean;
37
- selectedOptions: any[];
38
- active_advance: number;
39
- type: string;
40
- source?: any;
41
- hide_quantity: boolean;
42
- total_special_price: Price;
43
- special_price: Price;
44
- product_price: Price;
45
- product_price_formatted: string;
46
- price: Price;
47
- formated_price: string;
48
- total_product_price: Price;
49
- total_product_price_formatted: string;
50
- total: number;
51
- special_price_formatted: string;
52
- total_special_price_formatted: string;
53
- display_total_price: string;
54
- display_price: string;
55
- _product_price: number;
56
- _total_product_price: number;
57
- }
@@ -1,7 +0,0 @@
1
- import {CartDetailsResponse} from "./cart/cart-details-response";
2
-
3
- export default interface CartApi {
4
- latest: () => Promise<{ status: number; success: boolean; data: { cart_id: number }; message: string; } | any>,
5
- generate: () => Promise<any>,
6
- details: () => Promise<CartDetailsResponse | any>,
7
- }
@@ -1,59 +0,0 @@
1
- export interface OptionsData {
2
- [key: number]: number;
3
- }
4
-
5
- export interface Money {
6
- amount: string;
7
- currency: string;
8
- }
9
-
10
- export default interface Offer {
11
- discount: Money;
12
- price_after_discount: string;
13
- is_free: boolean;
14
- names: string;
15
- }
16
- export interface CartItem {
17
- id: number;
18
- url: string;
19
- quantity: number;
20
- isAvailable: boolean;
21
- onSale: boolean;
22
- options_data: OptionsData;
23
- notes: string;
24
- product_id: number;
25
- product_name: string;
26
- product_currency: string;
27
- isCustomized: boolean;
28
- product_image: string;
29
- product_quantity: number;
30
- product_maximum_quantity_per_order?: any;
31
- product_available_quantity: number;
32
- uploaded_files?: any;
33
- currency: string;
34
- enable_upload_image: boolean;
35
- enable_note: boolean;
36
- has_options: boolean;
37
- offer?: Offer;
38
- has_special_price: boolean;
39
- selectedOptions: number[];
40
- active_advance: number;
41
- type: string;
42
- source?: any;
43
- hide_quantity: boolean;
44
- total_special_price: Money;
45
- special_price: Money;
46
- product_price: Money;
47
- product_price_formatted: string;
48
- price: Money;
49
- formated_price: string;
50
- total_product_price: Money;
51
- total_product_price_formatted: string;
52
- total: number;
53
- special_price_formatted: string;
54
- total_special_price_formatted: string;
55
- display_total_price: string;
56
- display_price: string;
57
- _product_price: number;
58
- _total_product_price: number;
59
- }
@@ -1,29 +0,0 @@
1
- // @ts-ignore
2
- import CartItem from "./cartItem";
3
- type Nullable<T> = T | undefined | null;
4
- interface Data {
5
- items: CartItem[];
6
- count: number;
7
- total: string;
8
- total_before_discount?: any;
9
- coupon_discount: number;
10
- total_discount: number;
11
- sub_total: string;
12
- final_total: string;
13
- shipping_cost: number;
14
- }
15
-
16
- interface Sections {
17
- ['free-shipping-bar']: Nullable<string>;
18
- }
19
-
20
- export interface UpdateCartItemResponse {
21
- status: number;
22
- success: boolean;
23
- data: Data;
24
- message: string;
25
- message_code: string;
26
- sections: Sections;
27
- events: string;
28
- }
29
-