From 93947f2adbe3e4295a8d2aaf3782f27505a201eb Mon Sep 17 00:00:00 2001 From: Yash Maheshwari Date: Fri, 26 Aug 2022 15:53:12 +0530 Subject: [PATCH 1/3] Implemented: support for oms api package and updated the code to set the token and instance url(#2rby5m5) --- package-lock.json | 82 +++++++++++++++++++++++----- package.json | 1 + src/App.vue | 14 ++++- src/main.ts | 2 + src/store/modules/product/actions.ts | 15 ++--- src/store/modules/user/actions.ts | 8 ++- 6 files changed, 98 insertions(+), 24 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9c9b7ed..86b3b25 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1389,6 +1389,31 @@ "@hapi/hoek": "^8.3.0" } }, + "@hotwax/oms-api": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/@hotwax/oms-api/-/oms-api-0.0.1.tgz", + "integrity": "sha512-htc77HZc4mif9zBZY2534K1WxedNAm5Q632REnfdWt5spsckJ9N1I/3X+z0D448YdGBJC1gbOPsHNhSRQ0FGxw==", + "requires": { + "@types/node-json-transform": "^1.0.0", + "axios": "^0.21.1", + "axios-cache-adapter": "^2.7.3", + "http-status-codes": "^2.2.0", + "mitt": "^3.0.0", + "node-json-transform": "^1.1.2" + }, + "dependencies": { + "http-status-codes": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/http-status-codes/-/http-status-codes-2.2.0.tgz", + "integrity": "sha512-feERVo9iWxvnejp3SEfm/+oNG517npqL2/PIA8ORjyOZjGC7TwCRQsZylciLS64i6pJ0wRYz3rkXLRwbtFa8Ng==" + }, + "mitt": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/mitt/-/mitt-3.0.0.tgz", + "integrity": "sha512-7dX2/10ITVyqh4aOSVI9gdape+t9l2/8QxHrFmUXu4EEUpdlxl6RudZUPZoc+zuY2hk1j7XxVroIVIan/pD/SQ==" + } + } + }, "@intervolga/optimize-cssnano-plugin": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/@intervolga/optimize-cssnano-plugin/-/optimize-cssnano-plugin-1.0.6.tgz", @@ -1796,7 +1821,8 @@ "dev": true, "optional": true, "requires": { - "bindings": "^1.5.0" + "bindings": "^1.5.0", + "nan": "^2.12.1" } }, "is-ci": { @@ -2176,7 +2202,8 @@ "dev": true, "optional": true, "requires": { - "bindings": "^1.5.0" + "bindings": "^1.5.0", + "nan": "^2.12.1" } }, "is-ci": { @@ -2616,7 +2643,8 @@ "dev": true, "optional": true, "requires": { - "bindings": "^1.5.0" + "bindings": "^1.5.0", + "nan": "^2.12.1" } }, "is-ci": { @@ -3019,7 +3047,8 @@ "dev": true, "optional": true, "requires": { - "bindings": "^1.5.0" + "bindings": "^1.5.0", + "nan": "^2.12.1" } }, "is-ci": { @@ -3399,6 +3428,11 @@ "resolved": "https://registry.npmjs.org/@types/node/-/node-15.12.1.tgz", "integrity": "sha512-zyxJM8I1c9q5sRMtVF+zdd13Jt6RU4r4qfhTd7lQubyThvLfx6yYekWSQjGCGV2Tkecgxnlpl/DNlb6Hg+dmEw==" }, + "@types/node-json-transform": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@types/node-json-transform/-/node-json-transform-1.0.0.tgz", + "integrity": "sha512-M238h06PCWOjfR7gFP+/r2lQwviJgcLx8vwD/ontGAHeSz0Zwc6dXgD8871/TtfXZgQ05m7rEhnpQP56Bqgpyg==" + }, "@types/normalize-package-data": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/@types/normalize-package-data/-/normalize-package-data-2.4.0.tgz", @@ -4283,7 +4317,8 @@ "dev": true, "optional": true, "requires": { - "bindings": "^1.5.0" + "bindings": "^1.5.0", + "nan": "^2.12.1" } }, "is-ci": { @@ -11743,7 +11778,8 @@ "dev": true, "optional": true, "requires": { - "bindings": "^1.5.0" + "bindings": "^1.5.0", + "nan": "^2.12.1" } }, "is-ci": { @@ -13039,7 +13075,8 @@ "dev": true, "optional": true, "requires": { - "bindings": "^1.5.0" + "bindings": "^1.5.0", + "nan": "^2.12.1" } }, "is-ci": { @@ -13386,7 +13423,8 @@ "dev": true, "optional": true, "requires": { - "bindings": "^1.5.0" + "bindings": "^1.5.0", + "nan": "^2.12.1" } }, "is-ci": { @@ -14089,7 +14127,7 @@ "json-stable-stringify-without-jsonify": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz", - "integrity": "sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==", + "integrity": "sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE=", "dev": true }, "json-stringify-safe": { @@ -14573,8 +14611,7 @@ "lodash": { "version": "4.17.21", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", - "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", - "dev": true + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" }, "lodash.camelcase": { "version": "4.3.0", @@ -15076,6 +15113,13 @@ "thenify-all": "^1.0.0" } }, + "nan": { + "version": "2.16.0", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.16.0.tgz", + "integrity": "sha512-UdAqHyFngu7TfQKsCBgAA6pWDkT8MAO7d0jyOecVhN5354xbLqdn8mV9Tat9gepAupm0bt2DbeaSC8vS52MuFA==", + "dev": true, + "optional": true + }, "nanoid": { "version": "3.1.23", "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.1.23.tgz", @@ -15208,6 +15252,14 @@ "js-queue": "2.0.2" } }, + "node-json-transform": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/node-json-transform/-/node-json-transform-1.1.2.tgz", + "integrity": "sha512-Y3twjldHF1htCiCu6elGwQDdNp5PD54U66waWa2XNKh+g2lXSnWo3nq9SZnZOV3odFAqkM/roiNZx078RE2new==", + "requires": { + "lodash": "^4.17.15" + } + }, "node-libs-browser": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/node-libs-browser/-/node-libs-browser-2.2.1.tgz", @@ -18817,7 +18869,7 @@ "text-table": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", - "integrity": "sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==", + "integrity": "sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=", "dev": true }, "thenify": { @@ -19975,7 +20027,8 @@ "dev": true, "optional": true, "requires": { - "bindings": "^1.5.0" + "bindings": "^1.5.0", + "nan": "^2.12.1" } }, "is-binary-path": { @@ -20538,7 +20591,8 @@ "dev": true, "optional": true, "requires": { - "bindings": "^1.5.0" + "bindings": "^1.5.0", + "nan": "^2.12.1" } }, "http-proxy-middleware": { diff --git a/package.json b/package.json index 70c40aa..e5242b4 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "dependencies": { "@capacitor/android": "^2.4.7", "@capacitor/core": "^2.4.7", + "@hotwax/oms-api": "0.0.1", "@ionic/vue": "^5.4.0", "@ionic/vue-router": "^5.4.0", "@types/file-saver": "^2.0.4", diff --git a/src/App.vue b/src/App.vue index b8fac1c..b4bfccb 100644 --- a/src/App.vue +++ b/src/App.vue @@ -8,8 +8,10 @@ import { IonApp, IonRouterOutlet } from '@ionic/vue'; import { defineComponent } from 'vue'; import { loadingController, alertController } from '@ionic/vue'; -import { useStore } from "./store"; import emitter from "@/event-bus" +import { mapGetters, useStore } from 'vuex'; +import { updateInstanceUrl, updateToken } from '@hotwax/oms-api'; + export default defineComponent({ name: 'App', components: { @@ -49,10 +51,14 @@ export default defineComponent({ }); emitter.on('presentLoader', this.presentLoader); emitter.on('dismissLoader', this.dismissLoader); + updateToken(this.userToken) + updateInstanceUrl(this.instanceUrl) }, unmounted() { emitter.off('presentLoader', this.presentLoader); emitter.off('dismissLoader', this.dismissLoader); + updateToken('') + updateInstanceUrl('') }, setup(){ const store = useStore(); @@ -60,5 +66,11 @@ export default defineComponent({ store, } }, + computed: { + ...mapGetters({ + userToken: 'user/getUserToken', + instanceUrl: 'user/getInstanceUrl' + }) + } }); \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index 78f2f19..40ec8af 100644 --- a/src/main.ts +++ b/src/main.ts @@ -27,6 +27,7 @@ import './theme/variables.css'; import i18n from './i18n' import store from './store' import { DateTime } from 'luxon'; +import { init } from '@hotwax/oms-api'; const app = createApp(App) .use(IonicVue, { @@ -62,6 +63,7 @@ app.config.globalProperties.$filters = { } } +init(store.getters['user/getUserToken'], store.getters['user/getInstanceUrl'], 3000) router.isReady().then(() => { app.mount('#app'); diff --git a/src/store/modules/product/actions.ts b/src/store/modules/product/actions.ts index f3f7a3c..e0bb59e 100644 --- a/src/store/modules/product/actions.ts +++ b/src/store/modules/product/actions.ts @@ -1,11 +1,11 @@ -import { ProductService } from "@/services/ProductService"; import { ActionTree } from 'vuex' import RootState from '@/store/RootState' import ProductState from './ProductState' import * as types from './mutation-types' -import { hasError, showToast } from '@/utils' +import { showToast } from '@/utils' import { translate } from '@/i18n' import emitter from '@/event-bus' +import { fetchProducts, isError } from "@hotwax/oms-api"; const actions: ActionTree = { @@ -19,17 +19,18 @@ const actions: ActionTree = { let resp; try { - resp = await ProductService.fetchProducts({ + resp = await fetchProducts({ // used sku as we are currently only using sku to search for the product - "filters": ['sku: ' + payload.queryString], + "queryString": payload.queryString, + "queryFields": "sku", "viewSize": payload.viewSize, "viewIndex": payload.viewIndex }) // resp.data.response.numFound tells the number of items in the response - if (resp.status === 200 && resp.data.response.numFound > 0 && !hasError(resp)) { - let products = resp.data.response.docs; - const totalProductsCount = resp.data.response.numFound; + if (!isError(resp) && resp.total > 0) { + let products = resp.products; + const totalProductsCount = resp.total; if (payload.viewIndex && payload.viewIndex > 0) products = state.products.list.concat(products) commit(types.PRODUCT_SEARCH_UPDATED, { products: products, totalProductsCount: totalProductsCount }) diff --git a/src/store/modules/user/actions.ts b/src/store/modules/user/actions.ts index d599340..4ba6b0e 100644 --- a/src/store/modules/user/actions.ts +++ b/src/store/modules/user/actions.ts @@ -7,6 +7,7 @@ import { hasError, showToast } from '@/utils' import { translate } from '@/i18n' import emitter from '@/event-bus' import { DateTime } from 'luxon'; +import { updateInstanceUrl, updateToken } from '@hotwax/oms-api' const actions: ActionTree = { @@ -32,6 +33,7 @@ const actions: ActionTree = { if (checkPermissionResponse.status === 200 && !hasError(checkPermissionResponse) && checkPermissionResponse.data && checkPermissionResponse.data.hasPermission) { commit(types.USER_TOKEN_CHANGED, { newToken: resp.data.token }) + updateToken(resp.data.token) dispatch('getProfile') if (resp.data._EVENT_MESSAGE_ && resp.data._EVENT_MESSAGE_.startsWith("Alert:")) { // TODO Internationalise text @@ -73,7 +75,8 @@ const actions: ActionTree = { async logout ({ commit }) { // TODO add any other tasks if need commit(types.USER_END_SESSION) - + updateToken('') + updateInstanceUrl('') }, /** @@ -109,8 +112,9 @@ const actions: ActionTree = { /** * Set User Instance Url */ - setUserInstanceUrl ({ state, commit }, payload){ + setUserInstanceUrl ({ commit }, payload){ commit(types.USER_INSTANCE_URL_UPDATED, payload) + updateInstanceUrl(payload) } } From f5d6f0c569fe9723b62302539048a14ed9ccfd94 Mon Sep 17 00:00:00 2001 From: Yash Maheshwari Date: Fri, 26 Aug 2022 16:47:01 +0530 Subject: [PATCH 2/3] Improved: list item component to use the update schema and defined a utility method to get the product feature(#2rby5m5) --- src/components/ProductListItem.vue | 6 ++++-- src/utils/index.ts | 11 ++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/components/ProductListItem.vue b/src/components/ProductListItem.vue index e312f8f..9c6f847 100644 --- a/src/components/ProductListItem.vue +++ b/src/components/ProductListItem.vue @@ -1,12 +1,12 @@ @@ -20,6 +20,7 @@ import { } from '@ionic/vue' import { useRouter } from 'vue-router' import { useStore } from 'vuex'; +import { getFeature } from '@/utils'; export default defineComponent({ name: "ProductListItem", @@ -41,6 +42,7 @@ export default defineComponent({ const store = useStore(); return { + getFeature, router, store } diff --git a/src/utils/index.ts b/src/utils/index.ts index 3904faf..b5bafba 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -19,6 +19,15 @@ const showToast = async (message: string) => { return toast.present(); } +const getFeature = (features: any, key: string) => { + let featureValue = '' + if (features) { + featureValue = features.find((feature: any) => feature.desc === key)?.value + } + // returning 0th index as the featureValue is an array + return featureValue[0]; +} + // Utility for parsing CSV file // Package Used : PapaParse (Link to Documentation : https://www.papaparse.com/docs#config) @@ -117,4 +126,4 @@ const jsonToCsv = (file: any, options: JsonToCsvOption = {}) => { return blob; } -export { showToast, hasError , parseCsv , jsonToCsv, JsonToCsvOption } +export { showToast, hasError, getFeature, parseCsv , jsonToCsv, JsonToCsvOption } From def28d99dfbfacdad4abcbd6f36e8ab4f70c5a99 Mon Sep 17 00:00:00 2001 From: Yash Maheshwari Date: Fri, 26 Aug 2022 16:50:52 +0530 Subject: [PATCH 3/3] Improved: the return for the getFeature utility function(#2rby5m5) --- src/utils/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/index.ts b/src/utils/index.ts index b5bafba..a849610 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -25,7 +25,7 @@ const getFeature = (features: any, key: string) => { featureValue = features.find((feature: any) => feature.desc === key)?.value } // returning 0th index as the featureValue is an array - return featureValue[0]; + return featureValue ? featureValue[0] : ''; } // Utility for parsing CSV file