@hotwax/dxp-components 1.5.2 → 1.5.3

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.
@@ -1,10 +1,9 @@
1
- declare const _default: import("vue").DefineComponent<{}, {}, {
2
- errorMsg: string;
3
- authStore: {};
4
- router: {};
5
- route: {};
6
- }, {}, {
7
- handleUserFlow(token: any, oms: any, expirationTime: any): 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;
10
- //# sourceMappingURL=Login.d.ts.map
1
+ declare const _default: import("vue").DefineComponent<{}, {}, {
2
+ errorMsg: string;
3
+ authStore: any;
4
+ router: any;
5
+ route: 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,87 @@
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 _luxon = require("luxon");
10
+ var _default = (0, _vue.defineComponent)({
11
+ template: `
12
+ <div style='position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);'>
13
+ <h4 v-if='errorMsg.length'>
14
+ {{ errorMsg }}
15
+ </h4>
16
+ </div>
17
+ `,
18
+ data() {
19
+ return {
20
+ errorMsg: '',
21
+ authStore: {},
22
+ router: {},
23
+ route: {}
24
+ };
25
+ },
26
+ async mounted() {
27
+ this.authStore = (0, _index.useAuthStore)();
28
+ this.router = _index.appContext.config.globalProperties.$router;
29
+ this.route = _index.appContext.config.globalProperties.$route;
30
+ if (!Object.keys(this.route.query).length) {
31
+ window.location.href = _index.loginContext.appLoginUrl;
32
+ return;
33
+ }
34
+ const {
35
+ token,
36
+ oms,
37
+ expirationTime
38
+ } = this.route.query;
39
+ this.handleUserFlow(token, oms, expirationTime);
40
+ },
41
+ methods: {
42
+ async handleUserFlow(token, oms, expirationTime) {
43
+ // fetch the current config for the user
44
+ const appConfig = _index.loginContext.getConfig();
45
+
46
+ // logout to clear current user state, don't mark the user as logout as we just want to clear the user data
47
+ await _index.loginContext.logout({
48
+ isUserUnauthorised: true
49
+ });
50
+
51
+ // reset the config that we got from the oms-api, as on logout we clear the config of oms-api
52
+ await _index.loginContext.initialise(appConfig);
53
+
54
+ // checking if token from launchpad has expired and redirecting there only
55
+ if (+expirationTime < _luxon.DateTime.now().toMillis()) {
56
+ console.error('User token has expired, redirecting to launchpad.');
57
+ this.errorMsg = 'User token has expired, redirecting to launchpad.';
58
+ const redirectUrl = window.location.origin + '/login'; // current app URL
59
+ window.location.href = `${_index.loginContext.appLoginUrl}?isLoggedOut=true&redirectUrl=${redirectUrl}`;
60
+ return;
61
+ }
62
+
63
+ // update the previously set values if the user opts ending the previous session
64
+ this.authStore.$patch({
65
+ token: {
66
+ value: token,
67
+ expiration: expirationTime
68
+ },
69
+ oms
70
+ });
71
+ _index.loginContext.loader.present('Logging in');
72
+ try {
73
+ await _index.loginContext.login({
74
+ token,
75
+ oms
76
+ });
77
+ this.router.push('/');
78
+ } catch (error) {
79
+ console.error(error);
80
+ this.errorMsg = 'Unable to login. Please contact the administrator';
81
+ } finally {
82
+ _index.loginContext.loader.dismiss();
83
+ }
84
+ }
85
+ }
86
+ });
87
+ exports.default = _default;
@@ -1,18 +1,17 @@
1
- declare const _default: import("vue").DefineComponent<Readonly<{
2
- src?: any;
3
- size?: any;
4
- }>, unknown, {
5
- imageUrl: any;
6
- }, {}, {
7
- prepareImgUrl(src: any, size: any): any;
8
- checkIfImageExists(src: any): 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
- src?: any;
12
- size?: any;
13
- }>>>, {
14
- readonly src?: any;
15
- readonly size?: any;
16
- }, {}>;
17
- export default _default;
18
- //# sourceMappingURL=ShopifyImg.d.ts.map
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,14 +1,13 @@
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: {};
7
- declare let shopifyImgContext: {};
8
- declare let appContext: {};
9
- declare let productIdentificationContext: {};
10
- export declare let dxpComponents: {
11
- install(app: any, options: any): void;
12
- };
13
- export { useProductIdentificationStore, useAuthStore, Login, loginContext, shopifyImgContext, ShopifyImg, goToOms, appContext, productIdentificationContext };
14
- //# sourceMappingURL=index.d.ts.map
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;
8
+ declare let appContext: any;
9
+ declare let productIdentificationContext: any;
10
+ export declare let dxpComponents: {
11
+ install(app: any, options: any): void;
12
+ };
13
+ export { useProductIdentificationStore, useAuthStore, Login, loginContext, shopifyImgContext, ShopifyImg, goToOms, appContext, productIdentificationContext };