@hotwax/dxp-components 1.0.0 → 1.1.1
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/ShopifyImg.d.ts +17 -0
- package/lib/components/ShopifyImg.js +56 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.js +44 -0
- package/lib/store/productIdentification.d.ts +43 -0
- package/lib/store/productIdentification.js +51 -0
- package/lib/utils/index.d.ts +2 -0
- package/lib/utils/index.js +11 -0
- package/package.json +5 -1
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare const _default: import("vue").DefineComponent<Readonly<{
|
|
2
|
+
size?: any;
|
|
3
|
+
src?: any;
|
|
4
|
+
}>, unknown, {
|
|
5
|
+
imageUrl: string;
|
|
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.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
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { useProductIdentificationStore } from "./store/productIdentification";
|
|
2
|
+
import ShopifyImg from "./components/ShopifyImg";
|
|
3
|
+
import { goToOms } from "./utils";
|
|
4
|
+
declare let defaultImgUrl: string;
|
|
5
|
+
export declare let dxpComponents: {
|
|
6
|
+
install(app: any, options: any): void;
|
|
7
|
+
};
|
|
8
|
+
export { useProductIdentificationStore, defaultImgUrl, ShopifyImg, goToOms };
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "ShopifyImg", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _ShopifyImg.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
exports.dxpComponents = exports.defaultImgUrl = void 0;
|
|
13
|
+
Object.defineProperty(exports, "goToOms", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () {
|
|
16
|
+
return _utils.goToOms;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports, "useProductIdentificationStore", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () {
|
|
22
|
+
return _productIdentification.useProductIdentificationStore;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
var _pinia = require("pinia");
|
|
26
|
+
var _productIdentification = require("./store/productIdentification");
|
|
27
|
+
var _ShopifyImg = _interopRequireDefault(require("./components/ShopifyImg"));
|
|
28
|
+
var _utils = require("./utils");
|
|
29
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
30
|
+
// TODO: handle cases when the store from app or pinia store are not available
|
|
31
|
+
// creating a pinia store for the plugin
|
|
32
|
+
const pinia = (0, _pinia.createPinia)();
|
|
33
|
+
let defaultImgUrl;
|
|
34
|
+
// executed on app initialization
|
|
35
|
+
exports.defaultImgUrl = defaultImgUrl;
|
|
36
|
+
let dxpComponents = {
|
|
37
|
+
install(app, options) {
|
|
38
|
+
// registering pinia in the app
|
|
39
|
+
app.use(pinia);
|
|
40
|
+
app.component('ShopifyImg', _ShopifyImg.default);
|
|
41
|
+
exports.defaultImgUrl = defaultImgUrl = options.defaultImgUrl;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
exports.dxpComponents = dxpComponents;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export declare const useProductIdentificationStore: import("pinia").StoreDefinition<"productIdentification", {
|
|
2
|
+
productIdentificationPref: {
|
|
3
|
+
primaryId: string;
|
|
4
|
+
secondaryId: string;
|
|
5
|
+
};
|
|
6
|
+
productIdentificationOptions: string[];
|
|
7
|
+
}, {
|
|
8
|
+
getProductIdentificationPref: (state: {
|
|
9
|
+
productIdentificationPref: {
|
|
10
|
+
primaryId: string;
|
|
11
|
+
secondaryId: string;
|
|
12
|
+
};
|
|
13
|
+
productIdentificationOptions: string[];
|
|
14
|
+
} & import("pinia").PiniaCustomStateProperties<{
|
|
15
|
+
productIdentificationPref: {
|
|
16
|
+
primaryId: string;
|
|
17
|
+
secondaryId: string;
|
|
18
|
+
};
|
|
19
|
+
productIdentificationOptions: string[];
|
|
20
|
+
}>) => {
|
|
21
|
+
primaryId: string;
|
|
22
|
+
secondaryId: string;
|
|
23
|
+
};
|
|
24
|
+
getProductIdentificationOptions: (state: {
|
|
25
|
+
productIdentificationPref: {
|
|
26
|
+
primaryId: string;
|
|
27
|
+
secondaryId: string;
|
|
28
|
+
};
|
|
29
|
+
productIdentificationOptions: string[];
|
|
30
|
+
} & import("pinia").PiniaCustomStateProperties<{
|
|
31
|
+
productIdentificationPref: {
|
|
32
|
+
primaryId: string;
|
|
33
|
+
secondaryId: string;
|
|
34
|
+
};
|
|
35
|
+
productIdentificationOptions: string[];
|
|
36
|
+
}>) => string[];
|
|
37
|
+
}, {
|
|
38
|
+
setProductIdentificationPref(id: string, value: string, eComStoreId: string): Promise<void>;
|
|
39
|
+
getIdentificationPref(eComStoreId: string): Promise<{
|
|
40
|
+
primaryId: string;
|
|
41
|
+
secondaryId: string;
|
|
42
|
+
} | undefined>;
|
|
43
|
+
}>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useProductIdentificationStore = void 0;
|
|
7
|
+
var _omsApi = require("@hotwax/oms-api");
|
|
8
|
+
var _pinia = require("pinia");
|
|
9
|
+
const useProductIdentificationStore = (0, _pinia.defineStore)('productIdentification', {
|
|
10
|
+
state: () => {
|
|
11
|
+
return {
|
|
12
|
+
productIdentificationPref: {
|
|
13
|
+
primaryId: 'productId',
|
|
14
|
+
secondaryId: ''
|
|
15
|
+
},
|
|
16
|
+
productIdentificationOptions: ["productId", "groupId", "groupName", "internalName", "parentProductName", "primaryProductCategoryName", "productId", "sku", "title", "SHOPIFY_PROD_SKU"]
|
|
17
|
+
};
|
|
18
|
+
},
|
|
19
|
+
getters: {
|
|
20
|
+
getProductIdentificationPref: state => state.productIdentificationPref,
|
|
21
|
+
getProductIdentificationOptions: state => state.productIdentificationOptions
|
|
22
|
+
},
|
|
23
|
+
actions: {
|
|
24
|
+
async setProductIdentificationPref(id, value, eComStoreId) {
|
|
25
|
+
const productIdentificationPref = JSON.parse(JSON.stringify(this.getProductIdentificationPref));
|
|
26
|
+
|
|
27
|
+
// When eComStoreId is not available then make the values change to what selected previously
|
|
28
|
+
if (!eComStoreId) {
|
|
29
|
+
this.productIdentificationPref = productIdentificationPref;
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
productIdentificationPref[id] = value;
|
|
33
|
+
try {
|
|
34
|
+
this.productIdentificationPref = await (0, _omsApi.setProductIdentificationPref)(eComStoreId, productIdentificationPref);
|
|
35
|
+
} catch (err) {
|
|
36
|
+
console.log('error', err);
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
async getIdentificationPref(eComStoreId) {
|
|
40
|
+
// when selecting none as ecom store, not fetching the pref as it returns all the entries with the pref id
|
|
41
|
+
if (!eComStoreId) {
|
|
42
|
+
return this.productIdentificationPref = {
|
|
43
|
+
primaryId: 'productId',
|
|
44
|
+
secondaryId: ''
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
this.productIdentificationPref = await (0, _omsApi.getProductIdentificationPref)(eComStoreId);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
exports.useProductIdentificationStore = useProductIdentificationStore;
|
|
@@ -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.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -22,9 +22,13 @@
|
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@babel/cli": "^7.21.5",
|
|
24
24
|
"@babel/core": "^7.22.1",
|
|
25
|
+
"@babel/plugin-syntax-jsx": "^7.22.5",
|
|
25
26
|
"@babel/preset-env": "^7.22.4",
|
|
26
27
|
"@babel/preset-typescript": "^7.21.5",
|
|
28
|
+
"@vue/babel-plugin-jsx": "^1.1.1",
|
|
29
|
+
"@vue/babel-plugin-transform-vue-jsx": "^1.4.0",
|
|
27
30
|
"babel-plugin-module-resolver": "^4.1.0",
|
|
31
|
+
"babel-preset-vue": "^2.0.2",
|
|
28
32
|
"eslint": "^8.16.0",
|
|
29
33
|
"typescript": "^5.0.4"
|
|
30
34
|
},
|