@hotwax/dxp-components 1.0.2 → 1.2.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/lib/components/Login.d.ts +9 -0
- package/lib/components/Login.js +90 -0
- package/lib/components/ShopifyImg.d.ts +17 -0
- package/lib/components/ShopifyImg.js +56 -0
- package/lib/index.d.ts +8 -2
- package/lib/index.js +44 -1
- package/lib/store/auth.d.ts +52 -0
- package/lib/store/auth.js +43 -0
- package/lib/utils/index.d.ts +2 -0
- package/lib/utils/index.js +11 -0
- package/package.json +10 -3
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare const _default: import("vue").DefineComponent<{}, {}, {
|
|
2
|
+
errorMsg: string;
|
|
3
|
+
router: any;
|
|
4
|
+
route: any;
|
|
5
|
+
authStore: any;
|
|
6
|
+
}, {}, {
|
|
7
|
+
handleUserFlow(token: string, oms: string, expirationTime: string): Promise<void>;
|
|
8
|
+
}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}>;
|
|
9
|
+
export default _default;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _vue = require("vue");
|
|
8
|
+
var _index = require("../index");
|
|
9
|
+
var _default = (0, _vue.defineComponent)({
|
|
10
|
+
template: `
|
|
11
|
+
<div style='position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);'>
|
|
12
|
+
<h4 v-if='errorMsg.length'>
|
|
13
|
+
{{ errorMsg }}
|
|
14
|
+
</h4>
|
|
15
|
+
</div>
|
|
16
|
+
`,
|
|
17
|
+
data() {
|
|
18
|
+
return {
|
|
19
|
+
errorMsg: '',
|
|
20
|
+
router: {},
|
|
21
|
+
route: {},
|
|
22
|
+
authStore: {}
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
async mounted() {
|
|
26
|
+
// exporting the same from index.ts through globalProperties does not work as expected
|
|
27
|
+
const instance = (0, _vue.getCurrentInstance)();
|
|
28
|
+
this.route = instance.appContext.config.globalProperties.$route;
|
|
29
|
+
this.router = instance.appContext.config.globalProperties.$router;
|
|
30
|
+
this.authStore = (0, _index.useAuthStore)();
|
|
31
|
+
if (!Object.keys(this.route.query).length) {
|
|
32
|
+
this.errorMsg = 'Unable to login. Could not authenticate the user';
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const {
|
|
36
|
+
token,
|
|
37
|
+
oms,
|
|
38
|
+
expirationTime
|
|
39
|
+
} = this.route.query;
|
|
40
|
+
const appToken = this.authStore.token.value;
|
|
41
|
+
const appOms = this.authStore.oms;
|
|
42
|
+
const appExpirationTime = this.authStore.token.expiration;
|
|
43
|
+
|
|
44
|
+
// show alert if token/oms are different from the app's
|
|
45
|
+
if (appToken && token && (appToken != token || appOms != oms)) {
|
|
46
|
+
// for backward compatibility
|
|
47
|
+
this.authStore.$patch({
|
|
48
|
+
token: {
|
|
49
|
+
value: appToken,
|
|
50
|
+
expiration: appExpirationTime
|
|
51
|
+
},
|
|
52
|
+
oms: appOms
|
|
53
|
+
});
|
|
54
|
+
await _index.loginContext.confirmSessionEnd('dev-oms').then(isConfirmed => {
|
|
55
|
+
isConfirmed ? this.handleUserFlow(token, oms, expirationTime) : this.router.push('/');
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
methods: {
|
|
60
|
+
async handleUserFlow(token, oms, expirationTime) {
|
|
61
|
+
// logout to clear current user state
|
|
62
|
+
await _index.loginContext.logout();
|
|
63
|
+
|
|
64
|
+
// update the previously set values if the user opts ending the previous session
|
|
65
|
+
this.authStore.$patch({
|
|
66
|
+
token: {
|
|
67
|
+
value: token,
|
|
68
|
+
expiration: expirationTime
|
|
69
|
+
},
|
|
70
|
+
oms
|
|
71
|
+
});
|
|
72
|
+
_index.loginContext.loader.present('Logging in');
|
|
73
|
+
try {
|
|
74
|
+
await _index.loginContext.login({
|
|
75
|
+
token,
|
|
76
|
+
oms
|
|
77
|
+
});
|
|
78
|
+
this.router.replace({
|
|
79
|
+
path: '/'
|
|
80
|
+
});
|
|
81
|
+
} catch (error) {
|
|
82
|
+
console.error(error);
|
|
83
|
+
this.errorMsg = 'Unable to login. Please contact the administrator';
|
|
84
|
+
} finally {
|
|
85
|
+
_index.loginContext.loader.dismiss();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
exports.default = _default;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare const _default: import("vue").DefineComponent<Readonly<{
|
|
2
|
+
size?: any;
|
|
3
|
+
src?: any;
|
|
4
|
+
}>, unknown, {
|
|
5
|
+
imageUrl: any;
|
|
6
|
+
}, {}, {
|
|
7
|
+
prepareImgUrl(src: string, size?: string): string;
|
|
8
|
+
checkIfImageExists(src: string): Promise<unknown>;
|
|
9
|
+
setImageUrl(): void;
|
|
10
|
+
}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<Readonly<{
|
|
11
|
+
size?: any;
|
|
12
|
+
src?: any;
|
|
13
|
+
}>>>, {
|
|
14
|
+
readonly size?: any;
|
|
15
|
+
readonly src?: any;
|
|
16
|
+
}, {}>;
|
|
17
|
+
export default _default;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _vue = require("vue");
|
|
8
|
+
var _index = require("../index");
|
|
9
|
+
var _default = (0, _vue.defineComponent)({
|
|
10
|
+
template: `
|
|
11
|
+
<img :src="imageUrl"/>
|
|
12
|
+
`,
|
|
13
|
+
data() {
|
|
14
|
+
return {
|
|
15
|
+
imageUrl: _index.shopifyImgContext.defaultImgUrl
|
|
16
|
+
};
|
|
17
|
+
},
|
|
18
|
+
props: ['src', 'size'],
|
|
19
|
+
mounted() {
|
|
20
|
+
this.setImageUrl();
|
|
21
|
+
},
|
|
22
|
+
updated() {
|
|
23
|
+
this.setImageUrl();
|
|
24
|
+
},
|
|
25
|
+
methods: {
|
|
26
|
+
prepareImgUrl(src, size) {
|
|
27
|
+
// return original size if no size is given
|
|
28
|
+
if (!size) return src;
|
|
29
|
+
// remove any current image size then add the new image size
|
|
30
|
+
return src.replace(/_(pico|icon|thumb|small|compact|medium|large|grande|original|1024x1024|2048x2048|master)+\./g, '.').replace(/\.jpg|\.png|\.gif|\.jpeg/g, function (match) {
|
|
31
|
+
return '_' + size + match;
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
checkIfImageExists(src) {
|
|
35
|
+
return new Promise((resolve, reject) => {
|
|
36
|
+
const img = new Image();
|
|
37
|
+
img.onload = function () {
|
|
38
|
+
resolve(true);
|
|
39
|
+
};
|
|
40
|
+
img.onerror = function () {
|
|
41
|
+
reject(false);
|
|
42
|
+
};
|
|
43
|
+
img.src = src;
|
|
44
|
+
});
|
|
45
|
+
},
|
|
46
|
+
setImageUrl() {
|
|
47
|
+
if (this.src) {
|
|
48
|
+
const src = this.prepareImgUrl(this.src, this.size);
|
|
49
|
+
this.checkIfImageExists(src).then(() => {
|
|
50
|
+
this.imageUrl = src;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
exports.default = _default;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { useProductIdentificationStore } from "./store/productIdentification";
|
|
2
|
+
import { useAuthStore } from "./store/auth";
|
|
3
|
+
import Login from "./components/Login";
|
|
4
|
+
import ShopifyImg from "./components/ShopifyImg";
|
|
5
|
+
import { goToOms } from "./utils";
|
|
6
|
+
declare let loginContext: any;
|
|
7
|
+
declare let shopifyImgContext: any;
|
|
2
8
|
export declare let dxpComponents: {
|
|
3
|
-
install(app: any): void;
|
|
9
|
+
install(app: any, options: any): void;
|
|
4
10
|
};
|
|
5
|
-
export { useProductIdentificationStore };
|
|
11
|
+
export { useProductIdentificationStore, useAuthStore, Login, loginContext, shopifyImgContext, ShopifyImg, goToOms };
|
package/lib/index.js
CHANGED
|
@@ -3,7 +3,32 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
Object.defineProperty(exports, "Login", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _Login.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "ShopifyImg", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _ShopifyImg.default;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
6
18
|
exports.dxpComponents = void 0;
|
|
19
|
+
Object.defineProperty(exports, "goToOms", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () {
|
|
22
|
+
return _utils.goToOms;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
exports.shopifyImgContext = exports.loginContext = void 0;
|
|
26
|
+
Object.defineProperty(exports, "useAuthStore", {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
get: function () {
|
|
29
|
+
return _auth.useAuthStore;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
7
32
|
Object.defineProperty(exports, "useProductIdentificationStore", {
|
|
8
33
|
enumerable: true,
|
|
9
34
|
get: function () {
|
|
@@ -12,15 +37,33 @@ Object.defineProperty(exports, "useProductIdentificationStore", {
|
|
|
12
37
|
});
|
|
13
38
|
var _pinia = require("pinia");
|
|
14
39
|
var _productIdentification = require("./store/productIdentification");
|
|
40
|
+
var _auth = require("./store/auth");
|
|
41
|
+
var _Login = _interopRequireDefault(require("./components/Login"));
|
|
42
|
+
var _ShopifyImg = _interopRequireDefault(require("./components/ShopifyImg"));
|
|
43
|
+
var _utils = require("./utils");
|
|
44
|
+
var _piniaPluginPersistedstate = _interopRequireDefault(require("pinia-plugin-persistedstate"));
|
|
45
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
46
|
// TODO: handle cases when the store from app or pinia store are not available
|
|
16
47
|
// creating a pinia store for the plugin
|
|
17
48
|
const pinia = (0, _pinia.createPinia)();
|
|
49
|
+
pinia.use(_piniaPluginPersistedstate.default);
|
|
50
|
+
let loginContext = {};
|
|
51
|
+
exports.loginContext = loginContext;
|
|
52
|
+
let shopifyImgContext = {};
|
|
18
53
|
|
|
19
54
|
// executed on app initialization
|
|
55
|
+
exports.shopifyImgContext = shopifyImgContext;
|
|
20
56
|
let dxpComponents = {
|
|
21
|
-
install(app) {
|
|
57
|
+
install(app, options) {
|
|
22
58
|
// registering pinia in the app
|
|
23
59
|
app.use(pinia);
|
|
60
|
+
app.component('Login', _Login.default);
|
|
61
|
+
app.component('ShopifyImg', _ShopifyImg.default);
|
|
62
|
+
loginContext.login = options.login;
|
|
63
|
+
loginContext.confirmSessionEnd = options.confirmSessionEnd;
|
|
64
|
+
loginContext.logout = options.logout;
|
|
65
|
+
loginContext.loader = options.loader;
|
|
66
|
+
shopifyImgContext.defaultImgUrl = options.defaultImgUrl;
|
|
24
67
|
}
|
|
25
68
|
};
|
|
26
69
|
exports.dxpComponents = dxpComponents;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export declare const useAuthStore: import("pinia").StoreDefinition<"userAuth", {
|
|
2
|
+
token: {
|
|
3
|
+
value: string;
|
|
4
|
+
expiration: undefined;
|
|
5
|
+
};
|
|
6
|
+
oms: string;
|
|
7
|
+
}, {
|
|
8
|
+
getToken: (state: {
|
|
9
|
+
token: {
|
|
10
|
+
value: string;
|
|
11
|
+
expiration: undefined;
|
|
12
|
+
};
|
|
13
|
+
oms: string;
|
|
14
|
+
} & import("pinia").PiniaCustomStateProperties<{
|
|
15
|
+
token: {
|
|
16
|
+
value: string;
|
|
17
|
+
expiration: undefined;
|
|
18
|
+
};
|
|
19
|
+
oms: string;
|
|
20
|
+
}>) => {
|
|
21
|
+
value: string;
|
|
22
|
+
expiration: undefined;
|
|
23
|
+
};
|
|
24
|
+
getOms: (state: {
|
|
25
|
+
token: {
|
|
26
|
+
value: string;
|
|
27
|
+
expiration: undefined;
|
|
28
|
+
};
|
|
29
|
+
oms: string;
|
|
30
|
+
} & import("pinia").PiniaCustomStateProperties<{
|
|
31
|
+
token: {
|
|
32
|
+
value: string;
|
|
33
|
+
expiration: undefined;
|
|
34
|
+
};
|
|
35
|
+
oms: string;
|
|
36
|
+
}>) => string;
|
|
37
|
+
isAuthenticated: (state: {
|
|
38
|
+
token: {
|
|
39
|
+
value: string;
|
|
40
|
+
expiration: undefined;
|
|
41
|
+
};
|
|
42
|
+
oms: string;
|
|
43
|
+
} & import("pinia").PiniaCustomStateProperties<{
|
|
44
|
+
token: {
|
|
45
|
+
value: string;
|
|
46
|
+
expiration: undefined;
|
|
47
|
+
};
|
|
48
|
+
oms: string;
|
|
49
|
+
}>) => boolean | "";
|
|
50
|
+
}, {
|
|
51
|
+
authenticate(): Promise<void>;
|
|
52
|
+
}>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useAuthStore = void 0;
|
|
7
|
+
var _pinia = require("pinia");
|
|
8
|
+
var _luxon = require("luxon");
|
|
9
|
+
const useAuthStore = (0, _pinia.defineStore)('userAuth', {
|
|
10
|
+
state: () => {
|
|
11
|
+
return {
|
|
12
|
+
token: {
|
|
13
|
+
value: '',
|
|
14
|
+
expiration: undefined
|
|
15
|
+
},
|
|
16
|
+
oms: ''
|
|
17
|
+
};
|
|
18
|
+
},
|
|
19
|
+
getters: {
|
|
20
|
+
getToken: state => state.token,
|
|
21
|
+
getOms: state => state.oms,
|
|
22
|
+
isAuthenticated: state => {
|
|
23
|
+
let isTokenExpired = false;
|
|
24
|
+
if (state.token.expiration) {
|
|
25
|
+
const currTime = _luxon.DateTime.now().toMillis();
|
|
26
|
+
isTokenExpired = state.token.expiration < currTime;
|
|
27
|
+
}
|
|
28
|
+
return state.token.value && !isTokenExpired;
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
actions: {
|
|
32
|
+
// TODO will be done once backend support is there
|
|
33
|
+
async authenticate() {
|
|
34
|
+
// try {
|
|
35
|
+
// // authenticate through cookies
|
|
36
|
+
// return this.token
|
|
37
|
+
// } catch (error) {
|
|
38
|
+
// console.log(error)
|
|
39
|
+
// }
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
exports.useAuthStore = useAuthStore;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.goToOms = void 0;
|
|
7
|
+
const goToOms = (token, oms) => {
|
|
8
|
+
const link = (oms.startsWith('http') ? oms.replace('api/', "") : `https://${oms}.hotwax.io/`) + `?token=${token}`;
|
|
9
|
+
window.open(link, '_blank', 'noopener, noreferrer');
|
|
10
|
+
};
|
|
11
|
+
exports.goToOms = goToOms;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hotwax/dxp-components",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -16,17 +16,24 @@
|
|
|
16
16
|
"license": "Apache-2.0",
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@hotwax/oms-api": "^1.8.1",
|
|
19
|
+
"luxon": "^3.3.0",
|
|
19
20
|
"pinia": "2.0.36",
|
|
21
|
+
"pinia-plugin-persistedstate": "^3.1.0",
|
|
20
22
|
"vue": "^3.3.4"
|
|
21
23
|
},
|
|
22
24
|
"devDependencies": {
|
|
23
25
|
"@babel/cli": "^7.21.5",
|
|
24
26
|
"@babel/core": "^7.22.1",
|
|
27
|
+
"@babel/plugin-syntax-jsx": "^7.22.5",
|
|
25
28
|
"@babel/preset-env": "^7.22.4",
|
|
26
29
|
"@babel/preset-typescript": "^7.21.5",
|
|
30
|
+
"@types/luxon": "^3.3.0",
|
|
31
|
+
"@vue/babel-plugin-jsx": "^1.1.1",
|
|
32
|
+
"@vue/babel-plugin-transform-vue-jsx": "^1.4.0",
|
|
27
33
|
"babel-plugin-module-resolver": "^4.1.0",
|
|
28
|
-
"
|
|
29
|
-
"
|
|
34
|
+
"babel-preset-vue": "^2.0.2",
|
|
35
|
+
"eslint": "^7.32.0",
|
|
36
|
+
"typescript": "~4.7.4"
|
|
30
37
|
},
|
|
31
38
|
"repository": {
|
|
32
39
|
"type": "git",
|