@cdek-it/widget 3.8.2 → 3.9.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/README.md +2 -3
- package/dist/cdek-widget.es.js +82 -42
- package/dist/cdek-widget.umd.js +1 -1
- package/dist/service.php +31 -6
- package/package.json +20 -1
package/README.md
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
[](https://www.jsdelivr.com/package/gh/cdek-it/widget)
|
|
5
5
|
[](https://github.com/cdek-it/widget/releases)
|
|
6
6
|
|
|
7
|
+
[Документация по виджету](https://github.com/cdek-it/widget/blob/main/docs/ru/INTRO.md)
|
|
7
8
|
|
|
8
|
-
[
|
|
9
|
-
|
|
10
|
-
[English version of documentation](docs/en/INTRO.md)
|
|
9
|
+
[English version of documentation](https://github.com/cdek-it/widget/blob/main/docs/en/INTRO.md)
|
package/dist/cdek-widget.es.js
CHANGED
|
@@ -17934,35 +17934,39 @@ class CdekApi extends AbstractApi {
|
|
|
17934
17934
|
const coreStorage = core();
|
|
17935
17935
|
if (coreStorage.params.tariff) {
|
|
17936
17936
|
if (coreStorage.debug) {
|
|
17937
|
-
console.debug(
|
|
17937
|
+
console.debug(
|
|
17938
|
+
"[CDEK] We have fixed price",
|
|
17939
|
+
coreStorage.params.tariff
|
|
17940
|
+
);
|
|
17938
17941
|
}
|
|
17939
17942
|
return this.mapTariffsWithTypes([coreStorage.params.tariff]);
|
|
17940
17943
|
} else if (targetLocation === void 0) {
|
|
17941
|
-
throw new Error(
|
|
17944
|
+
throw new Error(
|
|
17945
|
+
"No location and no fixed tariff was passed to price calc"
|
|
17946
|
+
);
|
|
17942
17947
|
}
|
|
17943
17948
|
if (coreStorage.debug) {
|
|
17944
17949
|
console.debug("[CDEK] Loading prices from service");
|
|
17945
17950
|
}
|
|
17946
17951
|
this.cancelPriceRequest();
|
|
17947
17952
|
this.getPriceAbort = new AbortController();
|
|
17948
|
-
return await axios$1.post(
|
|
17949
|
-
|
|
17950
|
-
|
|
17951
|
-
|
|
17952
|
-
|
|
17953
|
-
|
|
17954
|
-
|
|
17955
|
-
|
|
17956
|
-
|
|
17957
|
-
|
|
17958
|
-
|
|
17959
|
-
|
|
17960
|
-
{
|
|
17961
|
-
signal: this.getPriceAbort.signal
|
|
17962
|
-
}
|
|
17963
|
-
).then((result) => {
|
|
17953
|
+
return await axios$1.post(this.servicePath, {
|
|
17954
|
+
currency: Currency[coreStorage.params.currency],
|
|
17955
|
+
lang: coreStorage.params.lang,
|
|
17956
|
+
from_location: typeof coreStorage.params.from === "string" ? {
|
|
17957
|
+
address: coreStorage.params.from
|
|
17958
|
+
} : coreStorage.params.from,
|
|
17959
|
+
to_location: targetLocation,
|
|
17960
|
+
action: "calculate",
|
|
17961
|
+
packages: coreStorage.params.goods
|
|
17962
|
+
}, {
|
|
17963
|
+
signal: this.getPriceAbort.signal
|
|
17964
|
+
}).then((result) => {
|
|
17964
17965
|
if (coreStorage.debug) {
|
|
17965
|
-
console.debug(
|
|
17966
|
+
console.debug(
|
|
17967
|
+
"[CDEK] Got prices from service",
|
|
17968
|
+
result.data.tariff_codes || []
|
|
17969
|
+
);
|
|
17966
17970
|
}
|
|
17967
17971
|
return this.mapTariffsWithTypes(result.data.tariff_codes || []);
|
|
17968
17972
|
}).catch((e) => {
|
|
@@ -17978,7 +17982,6 @@ class CdekApi extends AbstractApi {
|
|
|
17978
17982
|
}
|
|
17979
17983
|
async getOffices() {
|
|
17980
17984
|
const searchStorage = search();
|
|
17981
|
-
const mapStorage = map();
|
|
17982
17985
|
const coreStorage = core();
|
|
17983
17986
|
searchStorage.loading = true;
|
|
17984
17987
|
if (coreStorage.params.offices !== null || coreStorage.params.officesRaw !== null) {
|
|
@@ -17999,30 +18002,64 @@ class CdekApi extends AbstractApi {
|
|
|
17999
18002
|
}
|
|
18000
18003
|
this.cancelOfficeRequest();
|
|
18001
18004
|
this.getOfficesAbort = new AbortController();
|
|
18002
|
-
|
|
18005
|
+
const firstPageResult = await this.fetchOfficePage(
|
|
18006
|
+
1,
|
|
18007
|
+
additionalParams
|
|
18008
|
+
);
|
|
18009
|
+
let offices = this.formatResult(firstPageResult);
|
|
18010
|
+
const firstPageResultIsArray = Array.isArray(firstPageResult);
|
|
18011
|
+
const totalPages = firstPageResultIsArray ? false : firstPageResult.headers["x-total-pages"];
|
|
18012
|
+
const currentPage = firstPageResultIsArray ? false : firstPageResult.headers["x-current-page"];
|
|
18013
|
+
if (totalPages && currentPage) {
|
|
18014
|
+
const remainingPages = parseInt(totalPages) - parseInt(currentPage);
|
|
18015
|
+
await Promise.all(Array.from(
|
|
18016
|
+
{ length: remainingPages },
|
|
18017
|
+
(_e, i) => this.fetchOfficePage(
|
|
18018
|
+
i,
|
|
18019
|
+
additionalParams
|
|
18020
|
+
).then((r) => {
|
|
18021
|
+
const response = typeof r.data === "string" ? JSON.parse(r.data) : r.data;
|
|
18022
|
+
offices = [
|
|
18023
|
+
...offices,
|
|
18024
|
+
...this.formatOffices(response)
|
|
18025
|
+
];
|
|
18026
|
+
})
|
|
18027
|
+
));
|
|
18028
|
+
} else {
|
|
18029
|
+
const allOffices = await this.fetchOfficePage(0, additionalParams, null);
|
|
18030
|
+
offices = this.formatResult(allOffices);
|
|
18031
|
+
}
|
|
18032
|
+
if (coreStorage.debug) {
|
|
18033
|
+
console.debug("[CDEK] Got points", offices);
|
|
18034
|
+
}
|
|
18035
|
+
searchStorage.loading = false;
|
|
18036
|
+
return offices;
|
|
18037
|
+
}
|
|
18038
|
+
async fetchOfficePage(pageNumber, additionalParams, sizeNumber = 50) {
|
|
18039
|
+
return axios$1.get(this.servicePath, {
|
|
18003
18040
|
params: {
|
|
18004
|
-
...
|
|
18041
|
+
...search().filters,
|
|
18005
18042
|
...additionalParams,
|
|
18006
|
-
action: "offices"
|
|
18043
|
+
action: "offices",
|
|
18044
|
+
page: pageNumber,
|
|
18045
|
+
size: sizeNumber
|
|
18007
18046
|
},
|
|
18008
|
-
signal: this.getOfficesAbort.signal
|
|
18009
|
-
}).then((result) => {
|
|
18010
|
-
const response = typeof result.data === "string" ? JSON.parse(result.data) : result.data;
|
|
18011
|
-
if (coreStorage.debug) {
|
|
18012
|
-
console.debug("[CDEK] Got points", response);
|
|
18013
|
-
}
|
|
18014
|
-
return this.formatOffices(response);
|
|
18047
|
+
signal: this.getOfficesAbort ? this.getOfficesAbort.signal : void 0
|
|
18015
18048
|
}).catch((e) => {
|
|
18016
18049
|
if (axios$1.isCancel(e)) {
|
|
18017
|
-
if (
|
|
18050
|
+
if (core().debug) {
|
|
18018
18051
|
console.debug("[CDEK] Offices request cancelled");
|
|
18019
18052
|
}
|
|
18020
18053
|
throw e;
|
|
18021
18054
|
}
|
|
18022
18055
|
console.error("[CDEK] Service error", e);
|
|
18023
|
-
|
|
18056
|
+
map().mapLoadError = YandexMapErrorCode.SERVICE_ERROR;
|
|
18024
18057
|
return [];
|
|
18025
|
-
})
|
|
18058
|
+
});
|
|
18059
|
+
}
|
|
18060
|
+
formatResult(result) {
|
|
18061
|
+
const response = typeof result.data === "string" ? JSON.parse(result.data) : result.data;
|
|
18062
|
+
return this.formatOffices(response);
|
|
18026
18063
|
}
|
|
18027
18064
|
formatOffices(offices) {
|
|
18028
18065
|
return offices.map((e) => ({
|
|
@@ -18086,12 +18123,8 @@ class CdekApi extends AbstractApi {
|
|
|
18086
18123
|
loadLocalOffices() {
|
|
18087
18124
|
const searchStorage = search();
|
|
18088
18125
|
const coreStorage = core();
|
|
18089
|
-
const offices = coreStorage.params.officesRaw ? this.formatOffices(
|
|
18090
|
-
|
|
18091
|
-
) : coreStorage.params.offices || [];
|
|
18092
|
-
return offices.filter(
|
|
18093
|
-
(office) => (searchStorage.filters.allowed_cod === null || office.allowed_cod === searchStorage.filters.allowed_cod) && (searchStorage.filters.type === null || searchStorage.filters.type === OfficeType.ALL || office.type === searchStorage.filters.type) && (searchStorage.filters.have_cash === null || office.have_cash === searchStorage.filters.have_cash) && (searchStorage.filters.have_cashless === null || office.have_cashless === searchStorage.filters.have_cashless) && (searchStorage.filters.is_dressing_room === null || office.is_dressing_room === searchStorage.filters.is_dressing_room)
|
|
18094
|
-
);
|
|
18126
|
+
const offices = coreStorage.params.officesRaw ? this.formatOffices(Array.isArray(coreStorage.params.officesRaw) ? coreStorage.params.officesRaw : JSON.parse(coreStorage.params.officesRaw) || []) : coreStorage.params.offices || [];
|
|
18127
|
+
return offices.filter((office) => (searchStorage.filters.allowed_cod === null || office.allowed_cod === searchStorage.filters.allowed_cod) && (searchStorage.filters.type === null || searchStorage.filters.type === OfficeType.ALL || office.type === searchStorage.filters.type) && (searchStorage.filters.have_cash === null || office.have_cash === searchStorage.filters.have_cash) && (searchStorage.filters.have_cashless === null || office.have_cashless === searchStorage.filters.have_cashless) && (searchStorage.filters.is_dressing_room === null || office.is_dressing_room === searchStorage.filters.is_dressing_room));
|
|
18095
18128
|
}
|
|
18096
18129
|
}
|
|
18097
18130
|
class Widget {
|
|
@@ -18332,9 +18365,12 @@ class Widget {
|
|
|
18332
18365
|
coreStorage.togglePopup(Popup.INFO);
|
|
18333
18366
|
}
|
|
18334
18367
|
}).finally(coreStorage.unlockUi);
|
|
18335
|
-
const debouncedUpdate = debounce(async (input) => {
|
|
18368
|
+
const debouncedUpdate = debounce(async (input, forceUpdate = false) => {
|
|
18336
18369
|
try {
|
|
18337
|
-
|
|
18370
|
+
if (forceUpdate) {
|
|
18371
|
+
mapStorage.offices = [];
|
|
18372
|
+
mapStorage.offices = await this.cdekApi.getOffices();
|
|
18373
|
+
}
|
|
18338
18374
|
searchStorage.searchResults = (await this.yandexApi.geocodeString(input)).members;
|
|
18339
18375
|
searchStorage.loading = false;
|
|
18340
18376
|
} catch (e) {
|
|
@@ -18346,10 +18382,14 @@ class Widget {
|
|
|
18346
18382
|
if (mutation.storeId !== "search" || mutation.type !== "patch object") {
|
|
18347
18383
|
return;
|
|
18348
18384
|
}
|
|
18385
|
+
let forceUpdate = false;
|
|
18386
|
+
if (mutation.payload.hasOwnProperty("filters")) {
|
|
18387
|
+
forceUpdate = true;
|
|
18388
|
+
}
|
|
18349
18389
|
searchStorage.loading = true;
|
|
18350
18390
|
this.cdekApi.cancelOfficeRequest();
|
|
18351
18391
|
this.yandexApi.cancelGeocodeStringRequest();
|
|
18352
|
-
await debouncedUpdate(state.value);
|
|
18392
|
+
await debouncedUpdate(state.value, forceUpdate);
|
|
18353
18393
|
});
|
|
18354
18394
|
const debouncedSearch = debounce(async (coordinates) => {
|
|
18355
18395
|
try {
|