@salla.sa/twilight 2.0.278 → 2.0.280
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 +1 -1
- package/dist/@salla.sa/twilight.min.js.map +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/package.json +4 -3
- package/types/api/auth/index.d.ts +2 -2
- package/types/api/auth/response.d.ts +2 -2
- package/types/event/auth.d.ts +12 -11
- package/types/event/product.d.ts +1 -1
- package/watcher.js +31 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salla.sa/twilight",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.280",
|
|
4
4
|
"description": "Salla Theme Toolkit, Webcomponents, Events, Requests, Utils",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -41,7 +41,9 @@
|
|
|
41
41
|
"lang.js": "^1.1.14",
|
|
42
42
|
"rollup-plugin-json": "^4.0.0",
|
|
43
43
|
"rollup-plugin-node-resolve": "^5.2.0",
|
|
44
|
-
"store": "^2.0.12"
|
|
44
|
+
"store": "^2.0.12",
|
|
45
|
+
"dotenv": "^16.0.1",
|
|
46
|
+
"websocket": "^1.0.34"
|
|
45
47
|
},
|
|
46
48
|
"devDependencies": {
|
|
47
49
|
"@babel/core": "^7.17.7",
|
|
@@ -54,7 +56,6 @@
|
|
|
54
56
|
"rollup": "^2.70.1",
|
|
55
57
|
"rollup-plugin-cleaner": "^1.0.0",
|
|
56
58
|
"rollup-plugin-terser": "^7.0.2",
|
|
57
|
-
"rollup-plugin-uglify": "^6.0.4",
|
|
58
59
|
"webpack": "^5.64.2",
|
|
59
60
|
"webpack-build-notifier": "^2.3.0",
|
|
60
61
|
"webpack-cli": "^4.9.1"
|
|
@@ -8,10 +8,10 @@ import {AuthResponse} from "./response";
|
|
|
8
8
|
export default interface AuthApi {
|
|
9
9
|
canRedirect: () => boolean; //change it to false when you don't want page to reload or redirect automatically after logged in, use `salla.auth.event.onLoggedIn(response=>{...})`
|
|
10
10
|
setCanRedirect: (canRedirect: boolean) => void;
|
|
11
|
-
login: (data: AuthRequest.loginByMobile | AuthRequest.loginByEmail) => Promise<
|
|
11
|
+
login: (data: AuthRequest.loginByMobile | AuthRequest.loginByEmail) => Promise<AuthResponse.loginOrResendCode>;
|
|
12
12
|
logout: () => Promise<SuccessResponse>;
|
|
13
13
|
verify: (data: AuthRequest.verifyByMobile | AuthRequest.verifyByEmail, supportWebAuth: boolean) => Promise<AuthResponse.verify>;
|
|
14
|
-
resend: (data: AuthRequest.resend) => Promise<AuthResponse.
|
|
14
|
+
resend: (data: AuthRequest.resend) => Promise<AuthResponse.loginOrResendCode>;
|
|
15
15
|
register: (data: AuthRequest.register) => Promise<AuthResponse.verify>;
|
|
16
16
|
refresh: () => Promise<AuthResponse.verify>;
|
|
17
17
|
}
|
|
@@ -14,9 +14,9 @@ export namespace AuthResponse {
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export interface
|
|
17
|
+
export interface loginOrResendCode extends SuccessResponse {
|
|
18
18
|
data: {
|
|
19
|
-
resend_counter
|
|
19
|
+
resend_counter?: 2 | 3 | 4;//when resend code
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
}
|
package/types/event/auth.d.ts
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {SuccessResponse} from "../common";
|
|
1
|
+
import {AuthResponse} from "../api/auth";
|
|
2
|
+
import {RequestError, SuccessResponse} from "../common";
|
|
3
3
|
|
|
4
4
|
export default interface AuthEvent {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
onCodeReSent: (callback: (response: AuthResponse.resend, data: AuthRequest.resend) => void) => void;
|
|
8
|
-
onCodeNotReSent: (callback: (error: SuccessResponse | string, data: AuthRequest.resend) => void) => void;
|
|
5
|
+
//Success Responses
|
|
6
|
+
onCodeSent: (callback: (response: AuthResponse.loginOrResendCode, type?: 'mobile' | 'email') => void) => void;
|
|
9
7
|
onVerified: (callback: (response: AuthResponse.verify, type?: 'mobile' | 'email') => void) => void;
|
|
10
|
-
onVerificationFailed: (callback: (error: SuccessResponse | string, type?: 'mobile' | 'email') => void) => void;
|
|
11
8
|
onRegistered: (callback: (response: AuthResponse.verify) => void) => void;
|
|
12
|
-
onRegistrationFailed: (callback: (error: SuccessResponse) => void) => void;
|
|
13
|
-
onLoggedOut: (callback: (response: SuccessResponse) => void) => void;
|
|
14
9
|
onLoggedIn: (callback: (response: AuthResponse.verify) => void) => void;
|
|
15
|
-
|
|
10
|
+
onLoggedOut: (callback: (response: SuccessResponse) => void) => void;
|
|
16
11
|
onTokenFetched: (callback: (token: string) => void) => void;
|
|
17
|
-
|
|
12
|
+
|
|
13
|
+
//Error Responses
|
|
14
|
+
onCodeNotSent: (callback: (error: RequestError | string, type?: 'mobile' | 'email') => void) => void;
|
|
15
|
+
onVerificationFailed: (callback: (error: RequestError | string, type?: 'mobile' | 'email') => void) => void;
|
|
16
|
+
onRegistrationFailed: (callback: (error: RequestError) => void) => void;
|
|
17
|
+
onFailedLogout: (callback: (error: RequestError) => void) => void;
|
|
18
|
+
onRefreshFailed: (callback: (error: RequestError) => void) => void;
|
|
18
19
|
}
|
package/types/event/product.d.ts
CHANGED
|
@@ -13,6 +13,6 @@ export default interface ProductEvent {
|
|
|
13
13
|
onSearchFailed: RequestErrorEventWithData</*query*/string|undefined>;
|
|
14
14
|
|
|
15
15
|
onOfferExisted: (callback: (offer: OfferSummary) => void) => void;
|
|
16
|
-
|
|
16
|
+
onOffersFetched: (callback: (response: ProductResponse.offers) => void) => void;
|
|
17
17
|
onFetchOffersFailed: RequestErrorEvent;
|
|
18
18
|
}
|
package/watcher.js
CHANGED
|
@@ -2,6 +2,10 @@ const path = require('path');
|
|
|
2
2
|
const glob = require("glob");
|
|
3
3
|
const color = {normal: "\x1b[0m", red: "\x1b[31m", green: "\x1b[32m", yellow: "\x1b[33m", cyan: "\x1b[36m",}
|
|
4
4
|
const {execSync} = require("child_process");
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const env = require("dotenv");
|
|
7
|
+
const WebSocketClient = require('websocket').client;
|
|
8
|
+
|
|
5
9
|
//const webpack = require("webpack");
|
|
6
10
|
/**
|
|
7
11
|
* @callback HookCallback
|
|
@@ -48,8 +52,24 @@ const {execSync} = require("child_process");
|
|
|
48
52
|
* @property {boolean} isWin
|
|
49
53
|
*/
|
|
50
54
|
class WatcherPlugin {
|
|
51
|
-
constructor(sallaCli =
|
|
52
|
-
|
|
55
|
+
constructor({port = 8000,sallaCli = "salla",theme_id}) {
|
|
56
|
+
|
|
57
|
+
this.sallaCli = sallaCli;
|
|
58
|
+
this.theme_id = theme_id;
|
|
59
|
+
|
|
60
|
+
let client = new WebSocketClient();
|
|
61
|
+
|
|
62
|
+
client.on('connectFailed', function(error) {
|
|
63
|
+
console.error('[x] Oops! Hot reload is currently not working. Check the error message for details: ',error.toString());
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
client.on('connect', (connection)=> {
|
|
67
|
+
this.connection = connection;
|
|
68
|
+
console.log(color.green, `✓ Performing hot reload on port ws://localhost:${port}`, color.normal);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
client.connect(`ws://localhost:${port}`, 'echo-protocol');
|
|
72
|
+
|
|
53
73
|
}
|
|
54
74
|
|
|
55
75
|
/**
|
|
@@ -76,8 +96,13 @@ class WatcherPlugin {
|
|
|
76
96
|
let files = this.isWebpack5
|
|
77
97
|
? Array.from(compiler_.modifiedFiles || [])
|
|
78
98
|
: Object.keys(compiler_.watchFileSystem.watcher.mtimes);
|
|
79
|
-
|
|
80
|
-
|
|
99
|
+
|
|
100
|
+
files.map((file)=>{
|
|
101
|
+
if(file.toLowerCase().endsWith('.twig'))
|
|
102
|
+
execSync(`${this.sallaCli} theme sync -f "${file}" -id ${this.theme_id}`, {stdio: 'inherit'});
|
|
103
|
+
|
|
104
|
+
if(this.connection) this.connection.sendUTF(JSON.stringify({msg:"reload"}));
|
|
105
|
+
});
|
|
81
106
|
}
|
|
82
107
|
);
|
|
83
108
|
}
|
|
@@ -103,20 +128,12 @@ class WatcherPlugin {
|
|
|
103
128
|
* @param {{mode:'development'|'none'|'production', watch:boolean, ...}} options - @see https://webpack.js.org/configuration
|
|
104
129
|
* @return {boolean}
|
|
105
130
|
*/
|
|
106
|
-
|
|
131
|
+
canWatch(options) {
|
|
107
132
|
if (options.mode !== 'development' || !options.watch) {
|
|
108
133
|
console.log(color.green, `✓ Skipping Watching Theme files in production.`, color.normal);
|
|
109
134
|
return false;
|
|
110
135
|
}
|
|
111
|
-
|
|
112
|
-
try {
|
|
113
|
-
this.draftId = require(path.resolve(process.cwd(), 'theme.json')).draft_id
|
|
114
|
-
return !!this.draftId;
|
|
115
|
-
} catch (e) {
|
|
116
|
-
let command = color.cyan + this.sallaCli + ' theme watch' + color.red
|
|
117
|
-
console.log(color.red, `X Theme files won't sync! if you want to sync them, run: ${command}`, color.normal);
|
|
118
|
-
return false;
|
|
119
|
-
}
|
|
136
|
+
return true;
|
|
120
137
|
}
|
|
121
138
|
}
|
|
122
139
|
|