@salla.sa/twilight 2.4.0 → 2.5.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salla.sa/twilight",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
4
4
  "description": "Salla Theme Toolkit, Webcomponents, Events, Requests, Utils",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -1,4 +1,4 @@
1
- import {Axios} from "axios";
1
+ import { Axios } from "axios";
2
2
  import CartApi from "./cart";
3
3
  import AuthApi from "./auth";
4
4
  import GiftApi from "./gift";
@@ -12,6 +12,7 @@ import CurrencyApi from "./currency";
12
12
  import DocumentApi from "./document";
13
13
  import WishlistApi from "./wishlist";
14
14
  import TwilightApi from "./twilight";
15
+ import ScopeApi from "./scope";
15
16
 
16
17
  export {
17
18
  CartApi,
@@ -27,6 +28,7 @@ export {
27
28
  DocumentApi,
28
29
  TwilightApi,
29
30
  WishlistApi,
31
+ ScopeApi,
30
32
  };
31
33
  export type ApiActionName =
32
34
  'auth.login'
@@ -67,8 +69,9 @@ export type ApiActionName =
67
69
  | 'rating.order'
68
70
  | 'wishlist.add'
69
71
  | 'wishlist.remove'
70
- | 'scope.getAll'
71
- | 'scope.submit';
72
+ | 'scope.get'
73
+ | 'scope.change'
74
+ | 'scope.getProductAvailability';
72
75
 
73
76
  export default interface SallaApi extends Axios {
74
77
  cart: CartApi;
@@ -84,6 +87,7 @@ export default interface SallaApi extends Axios {
84
87
  document: DocumentApi;
85
88
  twilight: TwilightApi;
86
89
  wishlist: WishlistApi;
90
+ scope: ScopeApi;
87
91
  getHeaders: () => {
88
92
  Accept: string | 'application/json, text/plain, */*',
89
93
  "X-Requested-With": 'XMLHttpRequest',
@@ -0,0 +1,42 @@
1
+ import { SuccessResponse } from "../common";
2
+
3
+ export interface Scope {
4
+ id: number;
5
+ name: string;
6
+ selected: boolean;
7
+ }
8
+
9
+ export interface ProductAvailability {
10
+ name: string;
11
+ selected: boolean;
12
+ availability: Availability;
13
+ }
14
+
15
+ export interface Availability {
16
+ label: string;
17
+ key: string;
18
+ color: string;
19
+ }
20
+
21
+
22
+ export namespace ScopeApiResponse {
23
+
24
+ export interface scopeList extends SuccessResponse {
25
+ data: Scope[];
26
+ }
27
+
28
+ export interface scopeAddition extends SuccessResponse {
29
+ data: Scope
30
+ }
31
+
32
+ export interface availability extends SuccessResponse {
33
+ data: ProductAvailability[];
34
+ }
35
+ }
36
+
37
+
38
+ export default interface ScopeApi {
39
+ get: () => Promise<ScopeApiResponse.scopeList>
40
+ change: (payload: Object) => Promise<SuccessResponse>
41
+ getProductAvailability: (product_id: number) => Promise<ScopeApiResponse.availability>
42
+ }
@@ -12,7 +12,8 @@ import DocumentEvent from "./document";
12
12
  import TwilightEvent from "./twilight";
13
13
  import WishlistEvent from "./wishlist";
14
14
  import InfiniteScrollEvent from "./infiniteScroll";
15
- import {EventEmitter2} from "eventemitter2";
15
+ import ScopeEvents from "./scope";
16
+ import { EventEmitter2 } from "eventemitter2";
16
17
 
17
18
  export type event = (symbol | string);
18
19
  export type EventName = string
@@ -106,6 +107,12 @@ export type EventName = string
106
107
  | 'wishlist::removed'
107
108
  | 'wishlist::addition.failed'
108
109
  | 'wishlist::removing.failed'
110
+ | 'scope::fetched'
111
+ | 'scope::not.fetched'
112
+ | 'scope::changed'
113
+ | 'scope::not.changed'
114
+ | 'scope::product-availability.fetched'
115
+ | 'scope::product-availability.not.fetched';
109
116
  export {
110
117
  AuthEvent,
111
118
  CartEvent,
@@ -121,6 +128,7 @@ export {
121
128
  TwilightEvent,
122
129
  WishlistEvent,
123
130
  InfiniteScrollEvent,
131
+ ScopeEvents,
124
132
  }
125
133
 
126
134
  export default interface SallaEvent extends EventEmitter2 {
@@ -137,6 +145,7 @@ export default interface SallaEvent extends EventEmitter2 {
137
145
  document: DocumentEvent;
138
146
  twilight: TwilightEvent;
139
147
  wishlist: WishlistEvent;
148
+ scope: ScopeEvents,
140
149
  infiniteScroll: InfiniteScrollEvent;
141
150
  dispatchEvents: (events: { [event_name: string]: any }) => void;
142
151
  dispatch: (event_name: EventName, ...data: undefined | any) => void;
@@ -0,0 +1,15 @@
1
+ import { RequestErrorEvent } from "../common";
2
+ import { ScopeApiResponse } from '../api/scope'
3
+
4
+ export default interface ScopeEvents {
5
+ onFetched: (callback: (response: ScopeApiResponse.scopeList) => void) => void;
6
+ onNotFetched: RequestErrorEvent;
7
+
8
+ // POST
9
+ onChanged: (callback: (response: ScopeApiResponse.scopeAddition) => void) => void;
10
+ onChangeFailed: RequestErrorEvent;
11
+
12
+ // Availability
13
+ onProductAvailabilityFetched: (callback: (response: ScopeApiResponse.availability, product_id: number) => void) => void;
14
+ onProductAvailabilityNotFetched: RequestErrorEvent;
15
+ }