@astral/features 4.2.0 → 4.2.2

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 (17) hide show
  1. package/node/productSwitcher/components/AstralProductSwitcher/AstralProductSwitcher.js +3 -12
  2. package/node/productSwitcher/components/IdentityProductSwitcher/IdentityProductSwitcher.js +1 -1
  3. package/node/productSwitcher/components/IdentityProductSwitcher/hooks/useLogic/useLogic.js +6 -15
  4. package/node/productSwitcher/components/IdentityProductSwitcher/utils/getIdentityTenants/getIdentityTenants.js +2 -11
  5. package/node/productSwitcher/components/IdentityProductSwitcher/utils/getTenantsProducts/getTenantsProducts.js +6 -15
  6. package/node/productSwitcher/utils/formatIdentityProducts/formatIdentityProducts.js +2 -2
  7. package/node/productSwitcher/utils/getGroupsProducts/getGroupsProducts.js +2 -11
  8. package/node/productSwitcher/utils/getIdentityProducts/getIdentityProducts.js +2 -11
  9. package/package.json +2 -2
  10. package/productSwitcher/components/AstralProductSwitcher/AstralProductSwitcher.js +3 -12
  11. package/productSwitcher/components/IdentityProductSwitcher/IdentityProductSwitcher.js +1 -1
  12. package/productSwitcher/components/IdentityProductSwitcher/hooks/useLogic/useLogic.js +6 -15
  13. package/productSwitcher/components/IdentityProductSwitcher/utils/getIdentityTenants/getIdentityTenants.js +2 -11
  14. package/productSwitcher/components/IdentityProductSwitcher/utils/getTenantsProducts/getTenantsProducts.js +6 -15
  15. package/productSwitcher/utils/formatIdentityProducts/formatIdentityProducts.js +2 -2
  16. package/productSwitcher/utils/getGroupsProducts/getGroupsProducts.js +2 -11
  17. package/productSwitcher/utils/getIdentityProducts/getIdentityProducts.js +2 -11
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.AstralProductSwitcher = void 0;
13
4
  const jsx_runtime_1 = require("react/jsx-runtime");
@@ -17,14 +8,14 @@ const enums_1 = require("./enums");
17
8
  const utils_1 = require("./utils");
18
9
  const AstralProductSwitcher = ({ identityUrl, filterBy = enums_1.ProductFilterType.Tenant, code = 'astral', filter, }) => {
19
10
  const [products, setProducts] = (0, react_1.useState)([]);
20
- const handleGetProducts = () => __awaiter(void 0, void 0, void 0, function* () {
11
+ const handleGetProducts = async () => {
21
12
  if (products.length) {
22
13
  return products;
23
14
  }
24
- const filteredProductsList = yield (0, utils_1.getFilteredProducts)(identityUrl, filterBy, code);
15
+ const filteredProductsList = await (0, utils_1.getFilteredProducts)(identityUrl, filterBy, code);
25
16
  setProducts(filteredProductsList);
26
17
  return filteredProductsList;
27
- });
18
+ };
28
19
  return (0, jsx_runtime_1.jsx)(ui_1.ProductSwitcher, { getProducts: handleGetProducts, filter: filter });
29
20
  };
30
21
  exports.AstralProductSwitcher = AstralProductSwitcher;
@@ -13,7 +13,7 @@ const IdentityProductSwitcher = ({ identityUrl, }) => {
13
13
  imgAlt: 'Что-то пошло не так',
14
14
  title: ((0, jsx_runtime_1.jsxs)(styles_1.ErrorContainer, { container: true, component: "span", children: [(0, jsx_runtime_1.jsx)(ui_1.ErrorFillSm, { color: "inherit" }), (0, jsx_runtime_1.jsx)(ui_1.Typography, { variant: "h6", color: "grey", colorIntensity: "900", children: "\u0427\u0442\u043E-\u0442\u043E \u043F\u043E\u0448\u043B\u043E \u043D\u0435 \u0442\u0430\u043A" })] })),
15
15
  description: 'Произошла ошибка. Повторите попытку позже.',
16
- }, children: [isShowToggleButton && ((0, jsx_runtime_1.jsx)(styles_1.TenantsToggleButtonGroup, { exclusive: true, onChange: handleChangeTenant, value: tenantId, children: tenants === null || tenants === void 0 ? void 0 : tenants.map(({ id, name }) => ((0, jsx_runtime_1.jsx)(styles_1.TenantToggleButton, { value: id, children: name }, id))) })), productList === null || productList === void 0 ? void 0 : productList.map((product) => {
16
+ }, children: [isShowToggleButton && ((0, jsx_runtime_1.jsx)(styles_1.TenantsToggleButtonGroup, { exclusive: true, onChange: handleChangeTenant, value: tenantId, children: tenants?.map(({ id, name }) => ((0, jsx_runtime_1.jsx)(styles_1.TenantToggleButton, { value: id, children: name }, id))) })), productList?.map((product) => {
17
17
  return ((0, jsx_runtime_1.jsxs)(styles_1.StyledMenuItem, { component: "a", href: product.url, children: [(0, jsx_runtime_1.jsx)(styles_1.Logo, { src: product.logoUrl, color: product.color }), (0, jsx_runtime_1.jsx)(ui_1.Typography, { variant: "body1", color: "grey", colorIntensity: "900", children: product.name })] }, product.id));
18
18
  })] }) }) })] }));
19
19
  };
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.useLogic = void 0;
13
4
  const ui_1 = require("@astral/ui");
@@ -21,12 +12,12 @@ const useLogic = (identityUrl, openMenu) => {
21
12
  const [tenantId, setTenantId] = (0, react_1.useState)(IdentityProductSwitcher_1.ASTRAL_IDENTITY_DEFAULT_TENANT);
22
13
  const [isLoading, setIsLoading] = (0, react_1.useState)(false);
23
14
  const [isError, setIsError] = (0, react_1.useState)(false);
24
- const productList = (0, react_1.useMemo)(() => tenantsProductsMap === null || tenantsProductsMap === void 0 ? void 0 : tenantsProductsMap[tenantId], [tenantsProductsMap, tenantId]);
25
- const loadProducts = () => __awaiter(void 0, void 0, void 0, function* () {
15
+ const productList = (0, react_1.useMemo)(() => tenantsProductsMap?.[tenantId], [tenantsProductsMap, tenantId]);
16
+ const loadProducts = async () => {
26
17
  try {
27
- const tenantsInfo = yield (0, utils_1.getIdentityTenants)(identityUrl);
18
+ const tenantsInfo = await (0, utils_1.getIdentityTenants)(identityUrl);
28
19
  const tenantsIds = tenantsInfo.map(({ id }) => id);
29
- const tenantsProducts = yield (0, utils_1.getTenantsProducts)(identityUrl, tenantsIds);
20
+ const tenantsProducts = await (0, utils_1.getTenantsProducts)(identityUrl, tenantsIds);
30
21
  if (tenantsIds[0] !== tenantId) {
31
22
  setTenantId(tenantsIds[0]);
32
23
  }
@@ -40,7 +31,7 @@ const useLogic = (identityUrl, openMenu) => {
40
31
  finally {
41
32
  setIsLoading(false);
42
33
  }
43
- });
34
+ };
44
35
  const handleShowProducts = () => {
45
36
  setIsError(false);
46
37
  openMenu();
@@ -54,7 +45,7 @@ const useLogic = (identityUrl, openMenu) => {
54
45
  setTenantId(selectedValue);
55
46
  }
56
47
  };
57
- const isShowToggleButton = Boolean(tenants === null || tenants === void 0 ? void 0 : tenants.length) && Number(tenants === null || tenants === void 0 ? void 0 : tenants.length) > 1;
48
+ const isShowToggleButton = Boolean(tenants?.length) && Number(tenants?.length) > 1;
58
49
  return {
59
50
  handleShowProducts,
60
51
  isLoading,
@@ -1,25 +1,16 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.getIdentityTenants = void 0;
13
4
  /**
14
5
  * Получение данных из identity
15
6
  * @param identityUrl - адрес identity
16
7
  */
17
- const getIdentityTenants = (identityUrl) => __awaiter(void 0, void 0, void 0, function* () {
8
+ const getIdentityTenants = async (identityUrl) => {
18
9
  return fetch(`${identityUrl}/api/tenants/widget`).then((response) => {
19
10
  if (!response.ok) {
20
11
  throw new Error(response.statusText);
21
12
  }
22
13
  return response.json();
23
14
  });
24
- });
15
+ };
25
16
  exports.getIdentityTenants = getIdentityTenants;
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.getTenantsProducts = void 0;
13
4
  const utils_1 = require("../../../../utils");
@@ -16,13 +7,13 @@ const utils_1 = require("../../../../utils");
16
7
  * @param identityUrl - ссылка на identity
17
8
  * @param tenants - список экосистем, чтобы была возможность не все экосистемы показывать в виджете.
18
9
  */
19
- const getTenantsProducts = (identityUrl, tenants) => __awaiter(void 0, void 0, void 0, function* () {
10
+ const getTenantsProducts = async (identityUrl, tenants) => {
20
11
  const { hostname } = new URL(window.origin);
21
- const tenantsProducts = tenants.map((tenant) => __awaiter(void 0, void 0, void 0, function* () {
22
- const products = yield (0, utils_1.getIdentityProducts)(identityUrl, tenant).then((tenantProducts) => tenantProducts.filter((product) => new URL(product.url).hostname !== hostname));
12
+ const tenantsProducts = tenants.map(async (tenant) => {
13
+ const products = await (0, utils_1.getIdentityProducts)(identityUrl, tenant).then((tenantProducts) => tenantProducts.filter((product) => new URL(product.url).hostname !== hostname));
23
14
  return [tenant, products];
24
- }));
25
- const products = yield Promise.all(tenantsProducts);
15
+ });
16
+ const products = await Promise.all(tenantsProducts);
26
17
  return Object.fromEntries(products);
27
- });
18
+ };
28
19
  exports.getTenantsProducts = getTenantsProducts;
@@ -6,7 +6,7 @@ exports.formatIdentityProducts = void 0;
6
6
  * @param identityProducts - список продуктов от identity
7
7
  * @param identityUrl - Url адрес identity
8
8
  */
9
- const formatIdentityProducts = (identityUrl, identityProducts = []) => (identityProducts === null || identityProducts === void 0 ? void 0 : identityProducts.map(({ id, productUrl = '', name = '', logoUrl, iconFileId, backgroundHexColor = '', }) => {
9
+ const formatIdentityProducts = (identityUrl, identityProducts = []) => identityProducts?.map(({ id, productUrl = '', name = '', logoUrl, iconFileId, backgroundHexColor = '', }) => {
10
10
  return {
11
11
  id,
12
12
  url: productUrl,
@@ -14,5 +14,5 @@ const formatIdentityProducts = (identityUrl, identityProducts = []) => (identity
14
14
  logoUrl: logoUrl || `${identityUrl}/api/files/${iconFileId}`,
15
15
  color: backgroundHexColor,
16
16
  };
17
- })) || [];
17
+ }) || [];
18
18
  exports.formatIdentityProducts = formatIdentityProducts;
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.getGroupsProducts = void 0;
13
4
  const formatIdentityProducts_1 = require("../formatIdentityProducts");
@@ -16,7 +7,7 @@ const formatIdentityProducts_1 = require("../formatIdentityProducts");
16
7
  * @param identityUrl - адрес identity
17
8
  * @param group - код группы
18
9
  */
19
- const getGroupsProducts = (identityUrl, group) => __awaiter(void 0, void 0, void 0, function* () {
10
+ const getGroupsProducts = async (identityUrl, group) => {
20
11
  return fetch(`${identityUrl}/api/products/group?groupId=${group}`)
21
12
  .then((response) => {
22
13
  if (!response.ok) {
@@ -27,5 +18,5 @@ const getGroupsProducts = (identityUrl, group) => __awaiter(void 0, void 0, void
27
18
  .then(({ data }) => {
28
19
  return (0, formatIdentityProducts_1.formatIdentityProducts)(identityUrl, data);
29
20
  });
30
- });
21
+ };
31
22
  exports.getGroupsProducts = getGroupsProducts;
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.getIdentityProducts = void 0;
13
4
  const formatIdentityProducts_1 = require("../formatIdentityProducts");
@@ -16,7 +7,7 @@ const formatIdentityProducts_1 = require("../formatIdentityProducts");
16
7
  * @param identityUrl - адрес identity
17
8
  * @param tenant - код экосистемы
18
9
  */
19
- const getIdentityProducts = (identityUrl, tenant = 'astral') => __awaiter(void 0, void 0, void 0, function* () {
10
+ const getIdentityProducts = async (identityUrl, tenant = 'astral') => {
20
11
  return fetch(`${identityUrl}/api/products/widget?tenantId=${tenant}`)
21
12
  .then((response) => {
22
13
  if (!response.ok) {
@@ -27,5 +18,5 @@ const getIdentityProducts = (identityUrl, tenant = 'astral') => __awaiter(void 0
27
18
  .then(({ data }) => {
28
19
  return (0, formatIdentityProducts_1.formatIdentityProducts)(identityUrl, data);
29
20
  });
30
- });
21
+ };
31
22
  exports.getIdentityProducts = getIdentityProducts;
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@astral/features",
3
3
  "main": "./node/index.js",
4
- "version": "4.2.0",
4
+ "version": "4.2.2",
5
5
  "dependencies": {
6
- "@astral/ui": "4.2.0",
6
+ "@astral/ui": "4.2.2",
7
7
  "mobx": "^6.8.0",
8
8
  "mobx-react-lite": "^3.4.0",
9
9
  "@astral/cryptopro-cades": "^1.5.1"
@@ -1,12 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import { jsx as _jsx } from "react/jsx-runtime";
11
2
  import { ProductSwitcher, } from '@astral/ui';
12
3
  import { useState } from 'react';
@@ -14,13 +5,13 @@ import { ProductFilterType } from './enums';
14
5
  import { getFilteredProducts } from './utils';
15
6
  export const AstralProductSwitcher = ({ identityUrl, filterBy = ProductFilterType.Tenant, code = 'astral', filter, }) => {
16
7
  const [products, setProducts] = useState([]);
17
- const handleGetProducts = () => __awaiter(void 0, void 0, void 0, function* () {
8
+ const handleGetProducts = async () => {
18
9
  if (products.length) {
19
10
  return products;
20
11
  }
21
- const filteredProductsList = yield getFilteredProducts(identityUrl, filterBy, code);
12
+ const filteredProductsList = await getFilteredProducts(identityUrl, filterBy, code);
22
13
  setProducts(filteredProductsList);
23
14
  return filteredProductsList;
24
- });
15
+ };
25
16
  return _jsx(ProductSwitcher, { getProducts: handleGetProducts, filter: filter });
26
17
  };
@@ -10,7 +10,7 @@ export const IdentityProductSwitcher = ({ identityUrl, }) => {
10
10
  imgAlt: 'Что-то пошло не так',
11
11
  title: (_jsxs(ErrorContainer, { container: true, component: "span", children: [_jsx(ErrorFillSm, { color: "inherit" }), _jsx(Typography, { variant: "h6", color: "grey", colorIntensity: "900", children: "\u0427\u0442\u043E-\u0442\u043E \u043F\u043E\u0448\u043B\u043E \u043D\u0435 \u0442\u0430\u043A" })] })),
12
12
  description: 'Произошла ошибка. Повторите попытку позже.',
13
- }, children: [isShowToggleButton && (_jsx(TenantsToggleButtonGroup, { exclusive: true, onChange: handleChangeTenant, value: tenantId, children: tenants === null || tenants === void 0 ? void 0 : tenants.map(({ id, name }) => (_jsx(TenantToggleButton, { value: id, children: name }, id))) })), productList === null || productList === void 0 ? void 0 : productList.map((product) => {
13
+ }, children: [isShowToggleButton && (_jsx(TenantsToggleButtonGroup, { exclusive: true, onChange: handleChangeTenant, value: tenantId, children: tenants?.map(({ id, name }) => (_jsx(TenantToggleButton, { value: id, children: name }, id))) })), productList?.map((product) => {
14
14
  return (_jsxs(StyledMenuItem, { component: "a", href: product.url, children: [_jsx(Logo, { src: product.logoUrl, color: product.color }), _jsx(Typography, { variant: "body1", color: "grey", colorIntensity: "900", children: product.name })] }, product.id));
15
15
  })] }) }) })] }));
16
16
  };
@@ -1,12 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import { ConfigContext } from '@astral/ui';
11
2
  import { useContext, useMemo, useState } from 'react';
12
3
  import { ASTRAL_IDENTITY_DEFAULT_TENANT } from '../../IdentityProductSwitcher';
@@ -18,12 +9,12 @@ export const useLogic = (identityUrl, openMenu) => {
18
9
  const [tenantId, setTenantId] = useState(ASTRAL_IDENTITY_DEFAULT_TENANT);
19
10
  const [isLoading, setIsLoading] = useState(false);
20
11
  const [isError, setIsError] = useState(false);
21
- const productList = useMemo(() => tenantsProductsMap === null || tenantsProductsMap === void 0 ? void 0 : tenantsProductsMap[tenantId], [tenantsProductsMap, tenantId]);
22
- const loadProducts = () => __awaiter(void 0, void 0, void 0, function* () {
12
+ const productList = useMemo(() => tenantsProductsMap?.[tenantId], [tenantsProductsMap, tenantId]);
13
+ const loadProducts = async () => {
23
14
  try {
24
- const tenantsInfo = yield getIdentityTenants(identityUrl);
15
+ const tenantsInfo = await getIdentityTenants(identityUrl);
25
16
  const tenantsIds = tenantsInfo.map(({ id }) => id);
26
- const tenantsProducts = yield getTenantsProducts(identityUrl, tenantsIds);
17
+ const tenantsProducts = await getTenantsProducts(identityUrl, tenantsIds);
27
18
  if (tenantsIds[0] !== tenantId) {
28
19
  setTenantId(tenantsIds[0]);
29
20
  }
@@ -37,7 +28,7 @@ export const useLogic = (identityUrl, openMenu) => {
37
28
  finally {
38
29
  setIsLoading(false);
39
30
  }
40
- });
31
+ };
41
32
  const handleShowProducts = () => {
42
33
  setIsError(false);
43
34
  openMenu();
@@ -51,7 +42,7 @@ export const useLogic = (identityUrl, openMenu) => {
51
42
  setTenantId(selectedValue);
52
43
  }
53
44
  };
54
- const isShowToggleButton = Boolean(tenants === null || tenants === void 0 ? void 0 : tenants.length) && Number(tenants === null || tenants === void 0 ? void 0 : tenants.length) > 1;
45
+ const isShowToggleButton = Boolean(tenants?.length) && Number(tenants?.length) > 1;
55
46
  return {
56
47
  handleShowProducts,
57
48
  isLoading,
@@ -1,21 +1,12 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  /**
11
2
  * Получение данных из identity
12
3
  * @param identityUrl - адрес identity
13
4
  */
14
- export const getIdentityTenants = (identityUrl) => __awaiter(void 0, void 0, void 0, function* () {
5
+ export const getIdentityTenants = async (identityUrl) => {
15
6
  return fetch(`${identityUrl}/api/tenants/widget`).then((response) => {
16
7
  if (!response.ok) {
17
8
  throw new Error(response.statusText);
18
9
  }
19
10
  return response.json();
20
11
  });
21
- });
12
+ };
@@ -1,24 +1,15 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import { getIdentityProducts } from '../../../../utils';
11
2
  /**
12
3
  * Получение всех продуктов из разных экосистем и группировка в единую мапу
13
4
  * @param identityUrl - ссылка на identity
14
5
  * @param tenants - список экосистем, чтобы была возможность не все экосистемы показывать в виджете.
15
6
  */
16
- export const getTenantsProducts = (identityUrl, tenants) => __awaiter(void 0, void 0, void 0, function* () {
7
+ export const getTenantsProducts = async (identityUrl, tenants) => {
17
8
  const { hostname } = new URL(window.origin);
18
- const tenantsProducts = tenants.map((tenant) => __awaiter(void 0, void 0, void 0, function* () {
19
- const products = yield getIdentityProducts(identityUrl, tenant).then((tenantProducts) => tenantProducts.filter((product) => new URL(product.url).hostname !== hostname));
9
+ const tenantsProducts = tenants.map(async (tenant) => {
10
+ const products = await getIdentityProducts(identityUrl, tenant).then((tenantProducts) => tenantProducts.filter((product) => new URL(product.url).hostname !== hostname));
20
11
  return [tenant, products];
21
- }));
22
- const products = yield Promise.all(tenantsProducts);
12
+ });
13
+ const products = await Promise.all(tenantsProducts);
23
14
  return Object.fromEntries(products);
24
- });
15
+ };
@@ -3,7 +3,7 @@
3
3
  * @param identityProducts - список продуктов от identity
4
4
  * @param identityUrl - Url адрес identity
5
5
  */
6
- export const formatIdentityProducts = (identityUrl, identityProducts = []) => (identityProducts === null || identityProducts === void 0 ? void 0 : identityProducts.map(({ id, productUrl = '', name = '', logoUrl, iconFileId, backgroundHexColor = '', }) => {
6
+ export const formatIdentityProducts = (identityUrl, identityProducts = []) => identityProducts?.map(({ id, productUrl = '', name = '', logoUrl, iconFileId, backgroundHexColor = '', }) => {
7
7
  return {
8
8
  id,
9
9
  url: productUrl,
@@ -11,4 +11,4 @@ export const formatIdentityProducts = (identityUrl, identityProducts = []) => (i
11
11
  logoUrl: logoUrl || `${identityUrl}/api/files/${iconFileId}`,
12
12
  color: backgroundHexColor,
13
13
  };
14
- })) || [];
14
+ }) || [];
@@ -1,19 +1,10 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import { formatIdentityProducts } from '../formatIdentityProducts';
11
2
  /**
12
3
  * Получение данных из identity
13
4
  * @param identityUrl - адрес identity
14
5
  * @param group - код группы
15
6
  */
16
- export const getGroupsProducts = (identityUrl, group) => __awaiter(void 0, void 0, void 0, function* () {
7
+ export const getGroupsProducts = async (identityUrl, group) => {
17
8
  return fetch(`${identityUrl}/api/products/group?groupId=${group}`)
18
9
  .then((response) => {
19
10
  if (!response.ok) {
@@ -24,4 +15,4 @@ export const getGroupsProducts = (identityUrl, group) => __awaiter(void 0, void
24
15
  .then(({ data }) => {
25
16
  return formatIdentityProducts(identityUrl, data);
26
17
  });
27
- });
18
+ };
@@ -1,19 +1,10 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import { formatIdentityProducts } from '../formatIdentityProducts';
11
2
  /**
12
3
  * Получение данных из identity
13
4
  * @param identityUrl - адрес identity
14
5
  * @param tenant - код экосистемы
15
6
  */
16
- export const getIdentityProducts = (identityUrl, tenant = 'astral') => __awaiter(void 0, void 0, void 0, function* () {
7
+ export const getIdentityProducts = async (identityUrl, tenant = 'astral') => {
17
8
  return fetch(`${identityUrl}/api/products/widget?tenantId=${tenant}`)
18
9
  .then((response) => {
19
10
  if (!response.ok) {
@@ -24,4 +15,4 @@ export const getIdentityProducts = (identityUrl, tenant = 'astral') => __awaiter
24
15
  .then(({ data }) => {
25
16
  return formatIdentityProducts(identityUrl, data);
26
17
  });
27
- });
18
+ };