@postnord/pn-marketweb-components 1.0.41 → 1.0.44-beta1

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.
Files changed (110) hide show
  1. package/cjs/{MarketWebLoginManager-859590e2.js → MarketWebLoginManager-1282a883.js} +1 -2
  2. package/cjs/{convert-57b3dd5e.js → convert-b8a6d658.js} +55 -0
  3. package/cjs/loader.cjs.js +1 -1
  4. package/cjs/pn-choice-button.cjs.entry.js +39 -0
  5. package/cjs/pn-find-price-result.cjs.entry.js +44 -0
  6. package/cjs/pn-find-price-store-85b100ba.js +23 -0
  7. package/cjs/pn-find-price.cjs.entry.js +260 -0
  8. package/cjs/{pn-choice-button_2.cjs.entry.js → pn-find-service-and-price-result.cjs.entry.js} +0 -33
  9. package/cjs/pn-find-service-and-price.cjs.entry.js +1 -1
  10. package/cjs/pn-language-selector_9.cjs.entry.js +17 -2
  11. package/cjs/pn-market-web-components.cjs.js +1 -1
  12. package/cjs/pn-marketweb-sitefooter.cjs.entry.js +0 -1
  13. package/cjs/pn-marketweb-siteheader.cjs.entry.js +5 -6
  14. package/cjs/pn-product-pricelist.cjs.entry.js +1 -1
  15. package/cjs/pn-profile-selector.cjs.entry.js +1 -1
  16. package/collection/collection-manifest.json +2 -0
  17. package/collection/components/layout-components/pn-marketweb-sitefooter/pn-marketweb-sitefooter.js +0 -1
  18. package/collection/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader-login.js +1 -1
  19. package/collection/components/layout-components/pn-marketweb-siteheader/pn-marketweb-siteheader.js +28 -30
  20. package/collection/components/navigation/pn-language-selector/pn-language-selector.js +15 -0
  21. package/collection/components/widgets/pn-find-price/data.js +68 -0
  22. package/collection/components/widgets/pn-find-price/find-price.stories.js +27 -0
  23. package/collection/components/widgets/pn-find-price/pn-find-price-result.css +3 -0
  24. package/collection/components/widgets/pn-find-price/pn-find-price-result.js +100 -0
  25. package/collection/components/widgets/pn-find-price/pn-find-price-store.js +20 -0
  26. package/collection/components/widgets/pn-find-price/pn-find-price-translations.js +71 -0
  27. package/collection/components/widgets/pn-find-price/pn-find-price-types.js +1 -0
  28. package/collection/components/widgets/pn-find-price/pn-find-price.css +55 -0
  29. package/collection/components/widgets/pn-find-price/pn-find-price.js +212 -0
  30. package/collection/globals/MarketWebLoginManager.js +1 -2
  31. package/collection/globals/shared/productprice/convert.js +55 -1
  32. package/custom-elements/index.d.ts +12 -0
  33. package/custom-elements/index.js +412 -37
  34. package/esm/{MarketWebLoginManager-83f2e86a.js → MarketWebLoginManager-310d2552.js} +1 -2
  35. package/esm/{convert-b49a0857.js → convert-8cce67c4.js} +55 -1
  36. package/esm/loader.js +1 -1
  37. package/esm/{pn-choice-button_2.entry.js → pn-choice-button.entry.js} +1 -39
  38. package/esm/pn-find-price-result.entry.js +40 -0
  39. package/esm/pn-find-price-store-d2053b72.js +21 -0
  40. package/esm/pn-find-price.entry.js +256 -0
  41. package/esm/pn-find-service-and-price-result.entry.js +41 -0
  42. package/esm/pn-find-service-and-price.entry.js +1 -1
  43. package/esm/pn-language-selector_9.entry.js +17 -2
  44. package/esm/pn-market-web-components.js +1 -1
  45. package/esm/pn-marketweb-sitefooter.entry.js +0 -1
  46. package/esm/pn-marketweb-siteheader.entry.js +5 -6
  47. package/esm/pn-product-pricelist.entry.js +1 -1
  48. package/esm/pn-profile-selector.entry.js +1 -1
  49. package/esm-es5/{MarketWebLoginManager-83f2e86a.js → MarketWebLoginManager-310d2552.js} +1 -1
  50. package/esm-es5/{convert-b49a0857.js → convert-8cce67c4.js} +1 -1
  51. package/esm-es5/loader.js +1 -1
  52. package/esm-es5/pn-choice-button.entry.js +1 -0
  53. package/esm-es5/pn-find-price-result.entry.js +1 -0
  54. package/esm-es5/pn-find-price-store-d2053b72.js +1 -0
  55. package/esm-es5/pn-find-price.entry.js +1 -0
  56. package/esm-es5/pn-find-service-and-price-result.entry.js +1 -0
  57. package/esm-es5/pn-find-service-and-price.entry.js +1 -1
  58. package/esm-es5/pn-language-selector_9.entry.js +1 -1
  59. package/esm-es5/pn-market-web-components.js +1 -1
  60. package/esm-es5/pn-marketweb-sitefooter.entry.js +1 -1
  61. package/esm-es5/pn-marketweb-siteheader.entry.js +1 -1
  62. package/esm-es5/pn-product-pricelist.entry.js +1 -1
  63. package/esm-es5/pn-profile-selector.entry.js +1 -1
  64. package/package.json +1 -1
  65. package/pn-market-web-components/{p-e6a209c6.system.entry.js → p-0d0ea574.system.entry.js} +1 -1
  66. package/pn-market-web-components/p-1611123a.system.entry.js +1 -0
  67. package/pn-market-web-components/{p-b8af690a.entry.js → p-22738646.entry.js} +1 -1
  68. package/pn-market-web-components/p-233ca151.system.js +1 -0
  69. package/pn-market-web-components/p-2456901a.js +1 -0
  70. package/pn-market-web-components/p-2e6644ea.system.entry.js +1 -0
  71. package/pn-market-web-components/p-325a7cae.entry.js +1 -0
  72. package/pn-market-web-components/p-38ff23f5.entry.js +1 -0
  73. package/pn-market-web-components/p-4fcabdb8.entry.js +1 -0
  74. package/pn-market-web-components/p-50454694.system.entry.js +1 -0
  75. package/pn-market-web-components/{p-91624bd5.system.js → p-5ce5be4f.system.js} +2 -2
  76. package/pn-market-web-components/p-5f8ef634.entry.js +1 -0
  77. package/pn-market-web-components/p-6ee881ea.system.entry.js +1 -0
  78. package/pn-market-web-components/p-725e4377.entry.js +1 -0
  79. package/pn-market-web-components/{p-21e0e386.js → p-7dd91709.js} +1 -1
  80. package/pn-market-web-components/p-93d8620b.entry.js +1 -0
  81. package/pn-market-web-components/p-a22df959.system.js +1 -1
  82. package/pn-market-web-components/{p-9aca0bae.entry.js → p-a5284c78.entry.js} +1 -1
  83. package/pn-market-web-components/p-b30e348c.system.entry.js +1 -0
  84. package/pn-market-web-components/p-bea2dcc6.entry.js +1 -0
  85. package/pn-market-web-components/p-c30207e6.js +1 -0
  86. package/pn-market-web-components/{p-f4fda846.system.entry.js → p-d133f30d.system.entry.js} +1 -1
  87. package/pn-market-web-components/p-d8882f68.system.entry.js +1 -0
  88. package/pn-market-web-components/p-da370548.system.entry.js +1 -0
  89. package/pn-market-web-components/p-dd4de1a9.entry.js +1 -0
  90. package/pn-market-web-components/{p-e04f8d34.system.entry.js → p-eb75d0cf.system.entry.js} +1 -1
  91. package/pn-market-web-components/{p-58cdf3a6.system.js → p-f1311662.system.js} +1 -1
  92. package/pn-market-web-components/pn-market-web-components.esm.js +1 -1
  93. package/types/components/navigation/pn-language-selector/pn-language-selector.d.ts +1 -0
  94. package/types/components/widgets/pn-find-price/pn-find-price-result.d.ts +9 -0
  95. package/types/components/widgets/pn-find-price/pn-find-price-store.d.ts +33 -0
  96. package/types/components/widgets/pn-find-price/pn-find-price-translations.d.ts +71 -0
  97. package/types/components/widgets/pn-find-price/pn-find-price-types.d.ts +46 -0
  98. package/types/components/widgets/pn-find-price/pn-find-price.d.ts +16 -0
  99. package/types/components.d.ts +37 -0
  100. package/esm-es5/pn-choice-button_2.entry.js +0 -1
  101. package/pn-market-web-components/p-37801e32.entry.js +0 -1
  102. package/pn-market-web-components/p-3f876199.entry.js +0 -1
  103. package/pn-market-web-components/p-4aa3b95d.entry.js +0 -1
  104. package/pn-market-web-components/p-861210ae.entry.js +0 -1
  105. package/pn-market-web-components/p-a924001f.system.entry.js +0 -1
  106. package/pn-market-web-components/p-ac36097e.system.entry.js +0 -1
  107. package/pn-market-web-components/p-b2383083.system.entry.js +0 -1
  108. package/pn-market-web-components/p-c254cfdf.js +0 -1
  109. package/pn-market-web-components/p-e9d8a991.entry.js +0 -1
  110. package/pn-market-web-components/p-ec1127de.system.entry.js +0 -1
@@ -0,0 +1,212 @@
1
+ import { Component, h, Prop, State, Watch } from "@stencil/core";
2
+ import { translations, markets } from "./pn-find-price-translations";
3
+ import { weights, sizeCategories } from "./data.js";
4
+ import { convertFileForSizeCategogy } from "../../../globals/shared/productprice/convert.js";
5
+ import { state } from "./pn-find-price-store";
6
+ export class PnfindPrice {
7
+ constructor() {
8
+ this.source = "https://com-integration.postnord.com/globalassets/global/prices/sv-findprice.xlsx";
9
+ this.language = "sv";
10
+ this.market = "se";
11
+ this.filteredItems = [];
12
+ this.weight = { value: 0, name: "" };
13
+ this.weightvalue = 0;
14
+ this.sourceData = { types: [], data: [] };
15
+ this.sizecategory = { value: "", name: "", icon: "", unit: "" };
16
+ }
17
+ componentWillLoad() {
18
+ this.setState();
19
+ this.getDataSource();
20
+ }
21
+ async getDataSource() {
22
+ const cacheBusting = `?cache=${Math.floor(Math.random() * (10000 - 1) + 1)}`;
23
+ const req = await fetch(this.source + cacheBusting);
24
+ const reqbody = await req.blob();
25
+ try {
26
+ const convertedData = await convertFileForSizeCategogy(reqbody);
27
+ this.sourceData = convertedData;
28
+ this.filterItems();
29
+ }
30
+ catch (e) {
31
+ console.log('Unable to parse data');
32
+ }
33
+ }
34
+ setState() {
35
+ if (this.market) {
36
+ state.market = markets[this.market];
37
+ }
38
+ if (this.language && translations[this.language]) {
39
+ state.i18n = translations[this.language];
40
+ }
41
+ }
42
+ filterItems() {
43
+ var _a;
44
+ if (!((_a = this.sourceData) === null || _a === void 0 ? void 0 : _a.data)) {
45
+ console.log('Data has not yet been loaded');
46
+ return;
47
+ }
48
+ const deliveryScopeData = this.sourceData.data.filter((x) => x.deliveryscope === "Sweden");
49
+ if (!this.sizecategory) {
50
+ return;
51
+ }
52
+ const sizeItemData = deliveryScopeData.filter((x) => x.sizecategory === this.sizecategory.value);
53
+ if (!this.weight || !this.weight.value) {
54
+ return;
55
+ }
56
+ const comparisonWeight = this.weight.value <= 20 ? this.weight.value * 1000 : this.weight.value;
57
+ let weightFilteredData = sizeItemData.filter(x => (x.maxweight <= 20 ? x.maxweight * 1000 : x.maxweight) === comparisonWeight);
58
+ // if no value found select the next available value
59
+ if (weightFilteredData.length === 0) {
60
+ weightFilteredData = sizeItemData.filter(x => (x.maxweight <= 20 ? x.maxweight * 1000 : x.maxweight) >= comparisonWeight);
61
+ if (weightFilteredData.length > 0) {
62
+ //sort based on the maxvalue
63
+ weightFilteredData.sort((a, b) => { return (a.maxweight - b.maxweight); });
64
+ // map to get the next unique item
65
+ const uniqueWeightOptions = [...new Map(weightFilteredData.reverse().map(item => [item["id"], item])).values()];
66
+ if (uniqueWeightOptions.length > 0) {
67
+ weightFilteredData = uniqueWeightOptions;
68
+ }
69
+ }
70
+ }
71
+ this.filteredItems = weightFilteredData;
72
+ }
73
+ render() {
74
+ return (h("div", null,
75
+ h("div", { class: "findprice-form" },
76
+ h("div", null, (h("div", { class: "heading" }, state.i18n.deliveryscopeheading))),
77
+ h("div", null,
78
+ (h("div", { class: "heading" }, state.i18n.componentheading)),
79
+ h("div", { class: "sizecategory" }, sizeCategories.map((sizeCategory) => (h("pn-choice-button", { choiceid: sizeCategory.value, value: sizeCategory.value, name: "sizecategory", type: "radio", checked: sizeCategory.value === this.sizecategory.value, onChange: () => {
80
+ this.sizecategory = sizeCategories.filter(x => x.value === sizeCategory.value)[0];
81
+ if (this.weight.value === 0) {
82
+ this.weight = weights[this.sizecategory.unit][0];
83
+ this.weightvalue = this.weight.value;
84
+ }
85
+ } },
86
+ h("pn-illustration", { illustration: sizeCategory.illustration }),
87
+ " ",
88
+ sizeCategory.name))))),
89
+ (this.sizecategory.value && weights[this.sizecategory.unit]) ? (h("div", null,
90
+ (state.i18n.sizeheading) ? (h("div", { class: "heading" }, state.i18n.sizeheading)) : null,
91
+ h("div", { class: "weightoption" },
92
+ h("div", { class: "weightoption-input" },
93
+ h("pn-input", { inputid: "weightvalue", name: "weightvalue", type: "number", label: state.i18n.weightlabel, value: this.weightvalue, onChange: (e) => {
94
+ if (e && e.target && e.target.value) {
95
+ const weightNum = parseInt(e.target.value, 10);
96
+ if (!isNaN(weightNum)) {
97
+ let matchingWeights = weights[this.sizecategory.unit].filter((x) => {
98
+ let weightInGrams = (x.abbreviation === "kg") ? x.value * 1000 : x.value;
99
+ return weightInGrams >= weightNum;
100
+ });
101
+ if (matchingWeights && matchingWeights.length > 0) {
102
+ this.weight = matchingWeights[0];
103
+ this.weightvalue = this.weight.value;
104
+ }
105
+ }
106
+ }
107
+ } }),
108
+ h("span", { class: "weightoption-input-abbreviation" }, this.weight.abbreviation)),
109
+ h("div", { class: "weightoption-range" },
110
+ h("input", { type: "range", id: "weightrange", name: "weightrange", list: "weightlist", value: (!this.weight.value) ? 0 : weights[this.sizecategory.unit].findIndex((x) => x.value === this.weightvalue), onChange: (e) => {
111
+ const value = e.target.value;
112
+ this.weight = weights[this.sizecategory.unit][value];
113
+ this.weightvalue = this.weight.value;
114
+ }, min: "0",
115
+ // max={ weights[this.postagetype.value][weights[this.postagetype.value].length - 1].value }
116
+ max: weights[this.sizecategory.unit].length - 1 }),
117
+ h("datalist", { id: "weightlist" }, weights[this.sizecategory.unit].map((weight, weightindex) => {
118
+ let labelText = weight.name;
119
+ if (weights[this.sizecategory.unit].length > 6) {
120
+ labelText = (weightindex % 5 === 0 || weightindex === 0 || weightindex === weights[this.sizecategory.unit].length - 1) ? weight.name : '';
121
+ }
122
+ return (h("option", Object.assign({ value: weightindex }, (labelText ? { label: labelText } : {}))));
123
+ })))))) : null),
124
+ (this.filteredItems && this.filteredItems.length > 0) ? (h("div", { class: "resultlist" },
125
+ (state.i18n.resultlistheading) ? (h("div", { class: "heading" }, state.i18n.resultlistheading)) : null,
126
+ this.filteredItems.map((item) => (h("div", null,
127
+ h("pn-find-price-result", { item: item })))))) : null));
128
+ }
129
+ static get is() { return "pn-find-price"; }
130
+ static get originalStyleUrls() { return {
131
+ "$": ["pn-find-price.scss"]
132
+ }; }
133
+ static get styleUrls() { return {
134
+ "$": ["pn-find-price.css"]
135
+ }; }
136
+ static get properties() { return {
137
+ "source": {
138
+ "type": "string",
139
+ "mutable": false,
140
+ "complexType": {
141
+ "original": "string",
142
+ "resolved": "string",
143
+ "references": {}
144
+ },
145
+ "required": false,
146
+ "optional": false,
147
+ "docs": {
148
+ "tags": [],
149
+ "text": ""
150
+ },
151
+ "attribute": "source",
152
+ "reflect": false,
153
+ "defaultValue": "\"https://com-integration.postnord.com/globalassets/global/prices/sv-findprice.xlsx\""
154
+ },
155
+ "language": {
156
+ "type": "string",
157
+ "mutable": true,
158
+ "complexType": {
159
+ "original": "string",
160
+ "resolved": "string",
161
+ "references": {}
162
+ },
163
+ "required": false,
164
+ "optional": false,
165
+ "docs": {
166
+ "tags": [],
167
+ "text": ""
168
+ },
169
+ "attribute": "language",
170
+ "reflect": false,
171
+ "defaultValue": "\"sv\""
172
+ },
173
+ "market": {
174
+ "type": "string",
175
+ "mutable": true,
176
+ "complexType": {
177
+ "original": "string",
178
+ "resolved": "string",
179
+ "references": {}
180
+ },
181
+ "required": false,
182
+ "optional": false,
183
+ "docs": {
184
+ "tags": [],
185
+ "text": ""
186
+ },
187
+ "attribute": "market",
188
+ "reflect": false,
189
+ "defaultValue": "\"se\""
190
+ }
191
+ }; }
192
+ static get states() { return {
193
+ "filteredItems": {},
194
+ "weight": {},
195
+ "weightvalue": {},
196
+ "sourceData": {},
197
+ "sizecategory": {}
198
+ }; }
199
+ static get watchers() { return [{
200
+ "propName": "market",
201
+ "methodName": "setState"
202
+ }, {
203
+ "propName": "language",
204
+ "methodName": "setState"
205
+ }, {
206
+ "propName": "weightvalue",
207
+ "methodName": "filterItems"
208
+ }, {
209
+ "propName": "sizecategory",
210
+ "methodName": "filterItems"
211
+ }]; }
212
+ }
@@ -87,8 +87,7 @@ class MarketWebLoginManager {
87
87
  return `${this.getBaseUrl()}${this.endpoints.authorizationEndpoint}?redirectionUrl=${redirectPage}`;
88
88
  }
89
89
  getLogoutUrl(redirectPage = "") {
90
- const currentPage = window.location.href;
91
- redirectPage = redirectPage ? redirectPage : currentPage;
90
+ redirectPage = window.location.origin + '/logout';
92
91
  return `${this.getBaseUrl()}${this.endpoints.logoutEndpoint}?redirectionUrl=${redirectPage}&authorization=${this.store.get(this.keys.token)}`;
93
92
  }
94
93
  getUserInfo() {
@@ -40,4 +40,58 @@ async function convertFileFromStream(stream, filterColumnNames = ["what", "deliv
40
40
  return fileData;
41
41
  }
42
42
 
43
- export { convertFileFromStream };
43
+ async function convertFileForSizeCategogy(stream, filterColumnNames = ["sizecategory"]) {
44
+ const toFilterValue = (x) => x.toLowerCase().replace(/\s+/g, '');
45
+ const sheets = await readXlsxFile(stream, { getSheets: true })
46
+ let dataRows = [];
47
+ let sizecategoryColumn;
48
+ let sheetsData = await Promise.all(sheets.map(async (sheet) => { return await readXlsxFile(stream, { sheet: sheet.name }) }));
49
+
50
+ let types = {};
51
+ sheetsData.forEach(sheetData => {
52
+ const firstRow = sheetData.shift().map(x => toFilterValue(x));
53
+ // Set up column for adding options
54
+ firstRow.forEach((col, i) => {
55
+ if (typeof types[col] === "undefined" && filterColumnNames.includes(col)) {
56
+ types[col] = [];
57
+ }
58
+ if(col === "sizecategory")
59
+ sizecategoryColumn = i;
60
+ });
61
+
62
+ sheetData.forEach((row, rowindex) => {
63
+ // read sizeCategory column of each row and split it to save data for each item
64
+ const firstColRow = row[sizecategoryColumn];
65
+ const sizeCatColumnValue = firstColRow.split('/');
66
+
67
+ sizeCatColumnValue.forEach((value, j) => {
68
+ const dataRow = {};
69
+
70
+ firstRow.forEach(async (col, i) => {
71
+ const rowVal = (i === sizecategoryColumn) ? value : row[i];
72
+ dataRow[col] = rowVal;
73
+
74
+ // Add to types options
75
+ if (filterColumnNames.includes(col)) {
76
+ const filterVal = toFilterValue(rowVal);
77
+ dataRow[col] = filterVal;
78
+
79
+ if (!types[col].includes(filterVal)) {
80
+ types[col].push(filterVal);
81
+ }
82
+ }
83
+ });
84
+ dataRows.push(dataRow);
85
+ });
86
+ });
87
+ });
88
+
89
+
90
+ const fileData = {
91
+ "types": types,
92
+ "data": dataRows
93
+ };
94
+ return fileData;
95
+ }
96
+
97
+ export { convertFileFromStream, convertFileForSizeCategogy };
@@ -32,6 +32,18 @@ export const PnFilterSearch: {
32
32
  new (): PnFilterSearch;
33
33
  };
34
34
 
35
+ interface PnFindPrice extends Components.PnFindPrice, HTMLElement {}
36
+ export const PnFindPrice: {
37
+ prototype: PnFindPrice;
38
+ new (): PnFindPrice;
39
+ };
40
+
41
+ interface PnFindPriceResult extends Components.PnFindPriceResult, HTMLElement {}
42
+ export const PnFindPriceResult: {
43
+ prototype: PnFindPriceResult;
44
+ new (): PnFindPriceResult;
45
+ };
46
+
35
47
  interface PnFindServiceAndPrice extends Components.PnFindServiceAndPrice, HTMLElement {}
36
48
  export const PnFindServiceAndPrice: {
37
49
  prototype: PnFindServiceAndPrice;