@salla.sa/twilight 2.6.0 → 2.6.6
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/README.md +1 -0
- 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 +4 -4
- package/dist/esm/index.js.map +1 -1
- package/package.json +2 -1
- package/types/api/index.d.ts +4 -4
- package/types/api/product/index.d.ts +2 -1
- package/types/event/index.d.ts +6 -5
- package/watcher.js +50 -59
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salla.sa/twilight",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.6",
|
|
4
4
|
"description": "Salla Theme Toolkit, Webcomponents, Events, Requests, Utils",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
"homepage": "https://salla.dev",
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@salla.sa/applepay": "~1.0",
|
|
37
|
+
"@salla.sa/twilight-tailwind-theme": "~1.0",
|
|
37
38
|
"axios": "^0.27.2",
|
|
38
39
|
"eventemitter2": "^6.4.7",
|
|
39
40
|
"infinite-scroll": "^4.0.1",
|
package/types/api/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Axios } from "axios";
|
|
2
2
|
import CartApi from "./cart";
|
|
3
3
|
import AuthApi from "./auth";
|
|
4
|
-
import GiftApi from "./gift";
|
|
5
4
|
import OrderApi from "./order";
|
|
6
5
|
import RatingApi from "./rating";
|
|
7
6
|
import CommentApi from "./comment";
|
|
@@ -17,7 +16,6 @@ import ScopeApi from "./scope";
|
|
|
17
16
|
export {
|
|
18
17
|
CartApi,
|
|
19
18
|
AuthApi,
|
|
20
|
-
GiftApi,
|
|
21
19
|
OrderApi,
|
|
22
20
|
RatingApi,
|
|
23
21
|
CommentApi,
|
|
@@ -48,7 +46,6 @@ export type ApiActionName =
|
|
|
48
46
|
| 'cart.status'
|
|
49
47
|
| 'cart.addCoupon'
|
|
50
48
|
| 'cart.deleteCoupon'
|
|
51
|
-
| 'gift.buy'
|
|
52
49
|
| 'loyalty.exchange'
|
|
53
50
|
| 'loyalty.getProgram'
|
|
54
51
|
| 'loyalty.reset'
|
|
@@ -62,6 +59,10 @@ export type ApiActionName =
|
|
|
62
59
|
| 'product.categories'
|
|
63
60
|
| 'product.offers'
|
|
64
61
|
| 'profile.update'
|
|
62
|
+
| 'profile.getSizeGuides'
|
|
63
|
+
| 'profile.getGiftDetails'
|
|
64
|
+
| 'profile.addGiftToCart'
|
|
65
|
+
| 'profile.uploadGiftImage'
|
|
65
66
|
| 'comment.add'
|
|
66
67
|
| 'currency.change'
|
|
67
68
|
| 'currency.list'
|
|
@@ -78,7 +79,6 @@ export type ApiActionName =
|
|
|
78
79
|
export default interface SallaApi extends Axios {
|
|
79
80
|
cart: CartApi;
|
|
80
81
|
auth: AuthApi;
|
|
81
|
-
gift: GiftApi;
|
|
82
82
|
order: OrderApi;
|
|
83
83
|
rating: RatingApi;
|
|
84
84
|
comment: CommentApi;
|
|
@@ -12,5 +12,6 @@ export default interface ProductApi {
|
|
|
12
12
|
categories: (categoryId?: number) => Promise<ProductResponse.categories>; //get all categories or sub_categories
|
|
13
13
|
offers: (product_id: number) => Promise<ProductResponse.offers>; //get all categories or sub_categories
|
|
14
14
|
getGiftDetails: (product_id: number) => Promise<ProductResponse.giftResponse>;
|
|
15
|
-
addGiftToCart: (product_id: number, payload: Object, withRedirect: boolean)
|
|
15
|
+
addGiftToCart: (product_id: number, payload: Object, withRedirect: boolean) => Promise<ProductResponse.giftToCart>;
|
|
16
|
+
uploadGiftImage: (multiPartData: FormData) => Promise<ProductResponse.giftImageUpload>;
|
|
16
17
|
}
|
package/types/event/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import AuthEvent from "./auth";
|
|
2
2
|
import CartEvent from "./cart";
|
|
3
|
-
import GiftEvent from "./gift";
|
|
4
3
|
import OrderEvent from "./order";
|
|
5
4
|
import RatingEvent from "./rating";
|
|
6
5
|
import CommentEvent from "./comment";
|
|
@@ -52,8 +51,6 @@ export type EventName = string
|
|
|
52
51
|
| 'cart::coupon.deleted'
|
|
53
52
|
| 'cart::coupon.addition.failed'
|
|
54
53
|
| 'cart::coupon.deletion.failed'
|
|
55
|
-
| 'gift::buying.succeeded'
|
|
56
|
-
| 'gift::buying.failed'
|
|
57
54
|
| 'loyalty::exchange.succeeded'
|
|
58
55
|
| 'loyalty::exchange.failed'
|
|
59
56
|
| 'loyalty::program.fetched'
|
|
@@ -85,6 +82,12 @@ export type EventName = string
|
|
|
85
82
|
| 'product::offers.fetched'
|
|
86
83
|
| 'product::categories.fetched'
|
|
87
84
|
| 'product::categories.failed'
|
|
85
|
+
| 'product::gift.fetched'
|
|
86
|
+
| 'product::gift.failed'
|
|
87
|
+
| 'product::gift.add-to-cart.succeeded'
|
|
88
|
+
| 'product::gift.add-to-cart.failed'
|
|
89
|
+
| 'product::gift.image-upload.succeeded'
|
|
90
|
+
| 'product::gift.image-upload.failed'
|
|
88
91
|
| 'profile::updated'
|
|
89
92
|
| 'profile::update.failed'
|
|
90
93
|
| 'profile::mobile.updated'
|
|
@@ -120,7 +123,6 @@ export type EventName = string
|
|
|
120
123
|
export {
|
|
121
124
|
AuthEvent,
|
|
122
125
|
CartEvent,
|
|
123
|
-
GiftEvent,
|
|
124
126
|
OrderEvent,
|
|
125
127
|
RatingEvent,
|
|
126
128
|
CommentEvent,
|
|
@@ -138,7 +140,6 @@ export {
|
|
|
138
140
|
export default interface SallaEvent extends EventEmitter2 {
|
|
139
141
|
auth: AuthEvent;
|
|
140
142
|
cart: CartEvent;
|
|
141
|
-
gift: GiftEvent;
|
|
142
143
|
order: OrderEvent;
|
|
143
144
|
rating: RatingEvent;
|
|
144
145
|
comment: CommentEvent;
|
package/watcher.js
CHANGED
|
@@ -4,7 +4,8 @@ const color = {normal: "\x1b[0m", red: "\x1b[31m", green: "\x1b[32m", yellow: "\
|
|
|
4
4
|
const {execSync} = require("child_process");
|
|
5
5
|
const fs = require("fs");
|
|
6
6
|
const WebSocketClient = require('websocket').client;
|
|
7
|
-
|
|
7
|
+
const WebSocketServer = require("websocket").server;
|
|
8
|
+
const http = require("http");
|
|
8
9
|
//const webpack = require("webpack");
|
|
9
10
|
/**
|
|
10
11
|
* @callback HookCallback
|
|
@@ -51,9 +52,16 @@ const WebSocketClient = require('websocket').client;
|
|
|
51
52
|
* @property {boolean} isWin
|
|
52
53
|
*/
|
|
53
54
|
class WatcherPlugin {
|
|
54
|
-
constructor(params) {
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
constructor(params = {}) {
|
|
56
|
+
try{
|
|
57
|
+
if(!params.theme_id){
|
|
58
|
+
// this is another way to get params from cli
|
|
59
|
+
let cachePath = path.join(process.cwd(), "/node_modules/.salla-cli");
|
|
60
|
+
if(fs.existsSync(cachePath)) params = JSON.parse(fs.readFileSync(cachePath, 'utf8'));
|
|
61
|
+
}
|
|
62
|
+
}catch(err){}
|
|
63
|
+
|
|
64
|
+
let {wsport = 8001, sallaCli = "salla", theme_id, upload_url, store_id, draft_id} = params;
|
|
57
65
|
|
|
58
66
|
this.sallaCli = sallaCli;
|
|
59
67
|
this.theme_id = theme_id;
|
|
@@ -61,40 +69,10 @@ class WatcherPlugin {
|
|
|
61
69
|
this.store_id = store_id;
|
|
62
70
|
this.draft_id = draft_id;
|
|
63
71
|
|
|
64
|
-
|
|
65
|
-
// a hacky way to get args from process.env.npm_lifecycle_script
|
|
66
|
-
let args = parseNpmScriptsPassedArgs(process.env.npm_lifecycle_script);
|
|
67
|
-
this.theme_id = args.theme_id;
|
|
68
|
-
this.upload_url = args.upload_url;
|
|
69
|
-
this.store_id = args.store_id;
|
|
70
|
-
this.draft_id = args.draft_id;
|
|
71
|
-
port = args.port || 8000;
|
|
72
|
-
}
|
|
73
|
-
// try to connect to ws server
|
|
74
|
-
this.wsConnectingTries = 1;
|
|
75
|
-
this.tryConnectWebsocket(port);
|
|
72
|
+
this.startWebsocketServer(wsport);
|
|
76
73
|
|
|
77
74
|
}
|
|
78
75
|
|
|
79
|
-
tryConnectWebsocket(port){
|
|
80
|
-
let client = new WebSocketClient();
|
|
81
|
-
client.on('connectFailed', (error)=> {
|
|
82
|
-
if(this.wsConnectingTries===10){
|
|
83
|
-
console.error('[x] Oops! Hot reload is currently not working. Check the error message for details: ',error.toString());
|
|
84
|
-
}else{
|
|
85
|
-
this.wsConnectingTries++;
|
|
86
|
-
setTimeout(()=>{
|
|
87
|
-
this.tryConnectWebsocket(port);
|
|
88
|
-
},1000);
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
client.on('connect', (connection)=> {
|
|
93
|
-
this.connection = connection;
|
|
94
|
-
console.log(color.green, `✓ Performing hot reload on port ws://localhost:${port}`, color.normal);
|
|
95
|
-
});
|
|
96
|
-
client.connect(`ws://localhost:${port}`, 'echo-protocol');
|
|
97
|
-
}
|
|
98
76
|
/**
|
|
99
77
|
* @param {Compiler} compiler
|
|
100
78
|
*/
|
|
@@ -126,7 +104,7 @@ class WatcherPlugin {
|
|
|
126
104
|
changes = true;
|
|
127
105
|
}
|
|
128
106
|
});
|
|
129
|
-
if(changes) this.connection.sendUTF(JSON.stringify({msg:"reload"}));
|
|
107
|
+
if(changes && this.connection ) this.connection.sendUTF(JSON.stringify({msg:"reload"}));
|
|
130
108
|
}
|
|
131
109
|
);
|
|
132
110
|
}
|
|
@@ -160,29 +138,42 @@ class WatcherPlugin {
|
|
|
160
138
|
|
|
161
139
|
return !!this.theme_id;
|
|
162
140
|
}
|
|
141
|
+
startWebsocketServer(wsport){
|
|
142
|
+
// start the live reload ws server
|
|
143
|
+
const wsServer = new WebSocketServer({
|
|
144
|
+
httpServer: http.createServer().listen(wsport),
|
|
145
|
+
});
|
|
146
|
+
let users = [];
|
|
147
|
+
wsServer.on("request", function (request) {
|
|
148
|
+
let connection = request.accept("echo-protocol", request.origin);
|
|
149
|
+
users.push(connection);
|
|
150
|
+
|
|
151
|
+
connection.on("error", function (message) {
|
|
152
|
+
console.log("error", message);
|
|
153
|
+
});
|
|
154
|
+
connection.on("message", function (message) {
|
|
155
|
+
// mirror to all users
|
|
156
|
+
users.map((user) => {
|
|
157
|
+
// check user
|
|
158
|
+
if(user.connected)
|
|
159
|
+
user.sendUTF(message.utf8Data);
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
// connect to live reload server
|
|
165
|
+
let client = new WebSocketClient();
|
|
166
|
+
client.on('connectFailed', (error)=> {
|
|
167
|
+
console.error('[x] Oops! Hot reload is currently not working. Check the error message for details: ',error.toString());
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
client.on('connect', (connection)=> {
|
|
171
|
+
this.connection = connection;
|
|
172
|
+
console.log(color.green, `✓ Performing hot reload on port ws://localhost:${wsport}`, color.normal);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
client.connect(`ws://localhost:${wsport}`, 'echo-protocol');
|
|
176
|
+
}
|
|
163
177
|
}
|
|
164
|
-
function parseNpmScriptsPassedArgs(str){
|
|
165
|
-
// get all strings between equal sign
|
|
166
|
-
let strs = str.match(/"([^"]*)"/g);
|
|
167
178
|
|
|
168
|
-
if(strs===null) return {};
|
|
169
|
-
// remove quotes
|
|
170
|
-
strs = strs.map(str => str.replace(/"/g, ''));
|
|
171
|
-
|
|
172
|
-
// split by =
|
|
173
|
-
strs = strs.map(str => str.split('='));
|
|
174
|
-
// to be object
|
|
175
|
-
strs = strs.map(str => {
|
|
176
|
-
let obj = {};
|
|
177
|
-
let key = str[0];
|
|
178
|
-
// remove index 0
|
|
179
|
-
str.shift();
|
|
180
|
-
obj[key] = str.join('=');
|
|
181
|
-
return obj;
|
|
182
|
-
});
|
|
183
|
-
// reduce to one object
|
|
184
|
-
return strs.reduce((acc, curr) => {
|
|
185
|
-
return {...acc, ...curr};
|
|
186
|
-
})
|
|
187
|
-
}
|
|
188
179
|
module.exports = WatcherPlugin;
|