@agrada_digital/pbm 0.0.68 → 0.0.70

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/dist/index.d.mts CHANGED
@@ -41,6 +41,7 @@ interface IProduct {
41
41
  netPrice?: number;
42
42
  informativeMessage?: string;
43
43
  discountMax?: number;
44
+ industryLogo?: string;
44
45
  }
45
46
 
46
47
  interface PBMStore extends usePBMTypes {
package/dist/index.d.ts CHANGED
@@ -41,6 +41,7 @@ interface IProduct {
41
41
  netPrice?: number;
42
42
  informativeMessage?: string;
43
43
  discountMax?: number;
44
+ industryLogo?: string;
44
45
  }
45
46
 
46
47
  interface PBMStore extends usePBMTypes {
package/dist/index.js CHANGED
@@ -79,17 +79,17 @@ function Header({ originalProductPrice }) {
79
79
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
80
80
  "header",
81
81
  {
82
- className: "flex items-center justify-between w-full p-0.5 rounded-full bg-[#44c2c0]/30 mt-5",
82
+ className: "flex items-center justify-between w-full p-0.5 rounded-xl bg-[#44c2c0]/30 mt-5",
83
83
  id: "header_pbm",
84
84
  children: [
85
85
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
86
86
  "span",
87
87
  {
88
- className: "py-1 px-6 rounded-full bg-[#44c2c0] shrink-0 text-white text-xl font-bold flex items-center justify-start gap-2 relative",
88
+ className: "py-1 px-6 rounded-xl bg-[#44c2c0] shrink-0 text-white text-xl font-bold flex items-center justify-start gap-2 relative",
89
89
  "data-testid": "test_id_header_price",
90
90
  id: "header_price",
91
91
  children: [
92
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "absolute -top-6 left-10 bg-emerald-500 px-4 py-1 rounded-t-2xl text-xs font-medium text-white", children: [
92
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "absolute -top-6 left-10 bg-emerald-500 px-4 py-1 rounded-t-lg text-xs font-medium text-white", children: [
93
93
  targetProduct?.discountMax,
94
94
  "% OFF"
95
95
  ] }),
@@ -130,7 +130,7 @@ function Container({
130
130
  "main",
131
131
  {
132
132
  className: (0, import_classnames.default)({
133
- "border-3 border-[#44c2c0] flex flex-col items-center justify-center min-w-[var(--min-container)] max-w-[var(--max-container)] w-full h-auto rounded-2xl p-4 bg-white gap-4 relative": variant === "main",
133
+ "border-3 border-[#44c2c0] flex flex-col items-center justify-center min-w-[var(--min-container)] max-w-[var(--max-container)] w-full h-auto rounded-xl p-4 bg-white gap-4 relative": variant === "main",
134
134
  "w-full h-auto relative": variant === "simple"
135
135
  }),
136
136
  "data-testid": "test_id_container",
@@ -144,69 +144,20 @@ var Container_default = Container;
144
144
 
145
145
  // src/components/Footer/index.tsx
146
146
  var import_classnames2 = __toESM(require("classnames"));
147
- var import_react2 = require("react");
148
-
149
- // src/services/get-product-by-ean.ts
150
- var import_js_cookie = __toESM(require("js-cookie"));
151
- var import_meta = {};
152
- var GetProductByEAN = async ({ PRODUCT_EAN }) => {
153
- const API_URL = import_meta.env.VITE_API_URL;
154
- const AUTH_TOKEN = import_js_cookie.default.get("pbm-token");
155
- if (!AUTH_TOKEN) {
156
- throw new Error("Token is not defined in cookies or is expired");
157
- }
158
- const response = await fetch(`${API_URL}/products/ean/${PRODUCT_EAN}`, {
159
- method: "GET",
160
- headers: {
161
- Authorization: `Bearer ${AUTH_TOKEN}`,
162
- "Content-Type": "application/json"
163
- }
164
- });
165
- const dataResponse = await response.json();
166
- if (!dataResponse.success) {
167
- throw new Error(dataResponse.message || "Failed to fetch authorization");
168
- }
169
- return dataResponse;
170
- };
171
-
172
- // src/components/Footer/index.tsx
173
147
  var import_jsx_runtime3 = require("react/jsx-runtime");
174
148
  function Footer() {
175
- const [industryLogo, setIndustryLogo] = (0, import_react2.useState)(null);
176
149
  const { targetProduct, setTargetProduct, state } = usePBMStore();
177
- (0, import_react2.useEffect)(() => {
178
- const fetchProductByEan = async () => {
179
- if (!targetProduct?.ean) return;
180
- try {
181
- const response = await GetProductByEAN({ PRODUCT_EAN: targetProduct.ean });
182
- if (response.success && response.data) {
183
- setIndustryLogo(response.data.pbm.imageLink);
184
- const { pbm, sku, ...targetProductNewData } = response.data;
185
- setTargetProduct({
186
- ...targetProduct,
187
- ...targetProductNewData,
188
- productId: Number(targetProductNewData.productId),
189
- informativeMessage: pbm.informativeMessage ?? "",
190
- discountMax: pbm.discountMax ?? 0
191
- });
192
- }
193
- } catch (error) {
194
- console.error(error);
195
- }
196
- };
197
- fetchProductByEan();
198
- }, [targetProduct?.ean]);
199
150
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("footer", { className: "w-full h-auto relative", id: "footer_pbm", children: [
200
151
  state !== "isActivated" && targetProduct?.informativeMessage && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "text-start mb-3 font-semibold text-sm text-amber-500", children: targetProduct?.informativeMessage }),
201
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("section", { className: (0, import_classnames2.default)("flex items-center w-full h-auto gap-4", { "justify-center": industryLogo, "justify-start": !industryLogo }), children: [
152
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("section", { className: (0, import_classnames2.default)("flex items-center w-full h-auto gap-4", { "justify-center": targetProduct?.industryLogo, "justify-start": !targetProduct?.industryLogo }), children: [
202
153
  /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("section", { className: "w-4/5 h-auto", children: [
203
154
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("h3", { className: "text-start font-semibold text-sm", children: "Economize com o benef\xEDcio do laborat\xF3rio." }),
204
155
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "text-start font-normal text-sm", children: "Este produto tem pre\xE7o exclusivo para clientes cadastrados no programa." })
205
156
  ] }),
206
- industryLogo && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
157
+ targetProduct?.industryLogo && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
207
158
  "img",
208
159
  {
209
- src: industryLogo,
160
+ src: targetProduct.industryLogo,
210
161
  alt: "parceiro",
211
162
  className: "w-1/5 min-w-20 h-auto aspect-auto rounded-xl",
212
163
  loading: "eager",
@@ -247,17 +198,17 @@ var import_classnames4 = __toESM(require("classnames"));
247
198
  var import_zod2 = require("@hookform/resolvers/zod");
248
199
  var import_react_hook_form = require("react-hook-form");
249
200
  var import_lucide_react = require("lucide-react");
250
- var import_react3 = require("react");
201
+ var import_react2 = require("react");
251
202
 
252
203
  // src/services/benefits-with-document.ts
253
- var import_js_cookie2 = __toESM(require("js-cookie"));
254
- var import_meta2 = {};
204
+ var import_js_cookie = __toESM(require("js-cookie"));
205
+ var import_meta = {};
255
206
  var BenefitsWithDocument = async ({ document, products }) => {
256
- const API_URL = import_meta2.env.VITE_API_URL;
207
+ const API_URL = import_meta.env.VITE_API_URL;
257
208
  if (!API_URL) {
258
209
  throw new Error("API URL is not defined in environment variables");
259
210
  }
260
- const AUTH_TOKEN = import_js_cookie2.default.get("pbm-token");
211
+ const AUTH_TOKEN = import_js_cookie.default.get("pbm-token");
261
212
  if (!AUTH_TOKEN) {
262
213
  throw new Error("Token is not defined in cookies or is expired");
263
214
  }
@@ -285,7 +236,7 @@ function Button(props) {
285
236
  {
286
237
  ...props,
287
238
  className: (0, import_classnames3.default)(
288
- "w-3xs cursor-pointer h-10 rounded-full bg-emerald-500 hover:bg-emerald-400 text-white text-sm font-semibold transition-colors",
239
+ "w-3xs cursor-pointer h-10 rounded-lg bg-emerald-500 hover:bg-emerald-400 text-white text-sm font-semibold transition-colors",
289
240
  props.className
290
241
  ),
291
242
  children: props.children
@@ -298,7 +249,7 @@ var Button_default = Button;
298
249
  var import_jsx_runtime5 = require("react/jsx-runtime");
299
250
  function Form({ setLoading }) {
300
251
  const { setSecurityNumber, setState, securityNumber, targetProduct, setUrlAcceptTerms, setUrlRegisterIndustry } = usePBMStore();
301
- const [showCoupoField, setShowCoupoField] = (0, import_react3.useState)(false);
252
+ const [showCoupoField, setShowCoupoField] = (0, import_react2.useState)(false);
302
253
  const {
303
254
  handleSubmit,
304
255
  register,
@@ -389,8 +340,8 @@ function Form({ setLoading }) {
389
340
  {
390
341
  type: "text",
391
342
  className: (0, import_classnames4.default)(
392
- "w-full h-8 bg-gray-100 rounded-s-full text-sm font-semibold focus:outline focus:outline-[#339c9b] focus:bg-white text-zinc-600 placeholder:text-zinc-600 px-4 placeholder:text-sm placeholder:font-semibold",
393
- { "outline outline-red-600": errors.securityNumber, "rounded-full": showCoupoField }
343
+ "w-full h-10 bg-gray-100 rounded-s-lg text-sm font-semibold focus:outline focus:outline-[#339c9b] focus:bg-white text-zinc-600 placeholder:text-zinc-600 px-4 placeholder:text-sm placeholder:font-semibold",
344
+ { "outline outline-red-600": errors.securityNumber, "rounded-lg": showCoupoField }
394
345
  ),
395
346
  placeholder: "Digite seu CPF aqui...",
396
347
  required: true,
@@ -423,8 +374,8 @@ function Form({ setLoading }) {
423
374
  {
424
375
  type: "text",
425
376
  className: (0, import_classnames4.default)(
426
- "w-full h-8 bg-[#44c2c0]/20 rounded-s-full text-sm font-semibold focus:outline focus:outline-[#339c9b] focus:bg-[#44c2c0]/30 text-zinc-600 placeholder:text-zinc-600 px-4 placeholder:text-sm placeholder:font-semibold",
427
- { "outline outline-red-600": errors.coupon, "rounded-full": showCoupoField }
377
+ "w-full h-10 bg-gray-100 rounded-s-lg text-sm font-semibold focus:outline focus:outline-[#339c9b] focus:bg-[#44c2c0]/30 text-zinc-600 placeholder:text-zinc-600 px-4 placeholder:text-sm placeholder:font-semibold",
378
+ { "outline outline-red-600": errors.coupon, "rounded-lg": showCoupoField }
428
379
  ),
429
380
  placeholder: "Cupom / ID do Cart\xE3o",
430
381
  ...register("coupon", {
@@ -448,8 +399,8 @@ function Form({ setLoading }) {
448
399
  {
449
400
  type: "submit",
450
401
  className: (0, import_classnames4.default)(
451
- "bg-emerald-500 w-1/5 h-8 flex items-center justify-center rounded-e-full cursor-pointer",
452
- { "rounded-full": showCoupoField }
402
+ "bg-emerald-500 w-1/5 h-10 rounded-e-lg flex items-center justify-center cursor-pointer",
403
+ { "rounded-lg": showCoupoField }
453
404
  ),
454
405
  id: "button_submit_security_number_pbm",
455
406
  children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react.ArrowRight, { size: 24, color: "white", strokeWidth: 2 })
@@ -507,7 +458,7 @@ function Loading({ textColor }) {
507
458
  var Loading_default = Loading;
508
459
 
509
460
  // src/components/BenefitsTable/index.tsx
510
- var import_react5 = require("react");
461
+ var import_react4 = require("react");
511
462
 
512
463
  // src/components/UI/Title/index.tsx
513
464
  var import_classnames5 = __toESM(require("classnames"));
@@ -531,7 +482,7 @@ var Title_default = Title;
531
482
 
532
483
  // src/components/BenefitsTable/Item.tsx
533
484
  var import_lucide_react2 = require("lucide-react");
534
- var import_react4 = require("react");
485
+ var import_react3 = require("react");
535
486
  var import_jsx_runtime8 = require("react/jsx-runtime");
536
487
  function Item({ data, onChange, checked }) {
537
488
  const { setAvailableDiscountSelected, securityNumber } = usePBMStore();
@@ -540,7 +491,7 @@ function Item({ data, onChange, checked }) {
540
491
  const unitDiscountValue = data.grossPrice * decimalDiscount;
541
492
  const discountValue = unitDiscountValue * data.authorizedQuantity;
542
493
  const totalPriceProductWithDiscountBenefit = data.grossPrice * data.authorizedQuantity - discountValue;
543
- const updateStorageData = (0, import_react4.useCallback)(() => {
494
+ const updateStorageData = (0, import_react3.useCallback)(() => {
544
495
  if (checked) {
545
496
  const roundToTwoDecimals = (value) => Math.round(value * 100) / 100;
546
497
  setAvailableDiscountSelected({
@@ -561,14 +512,14 @@ function Item({ data, onChange, checked }) {
561
512
  totalPriceProductWithDiscountBenefit,
562
513
  unitDiscountValue
563
514
  ]);
564
- (0, import_react4.useEffect)(() => {
515
+ (0, import_react3.useEffect)(() => {
565
516
  updateStorageData();
566
517
  }, [updateStorageData]);
567
518
  return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
568
519
  "label",
569
520
  {
570
521
  htmlFor: ID_INPUT,
571
- className: "label_benefits w-full flex items-center justify-start bg-zinc-300/60 border border-zinc-400/50 px-4 py-2 hover:bg-zinc-300 transition-colors cursor-pointer rounded-full gap-1",
522
+ className: "label_benefits w-full flex items-center justify-start bg-zinc-300/60 border border-zinc-400/50 px-4 py-2 hover:bg-zinc-300 transition-colors cursor-pointer rounded-lg gap-1",
572
523
  id: "label_benefits_" + ID_INPUT,
573
524
  children: [
574
525
  /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
@@ -589,7 +540,7 @@ function Item({ data, onChange, checked }) {
589
540
  "un"
590
541
  ] }),
591
542
  /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("section", { className: "ml-auto relative", children: [
592
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("span", { className: "absolute -top-4 text-emerald-900 py-0.5 font-semibold text-xs bg-[#32b316] px-2 w-auto text-nowrap rounded-2xl -right-4", children: [
543
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("span", { className: "absolute -top-4 text-emerald-900 py-0.5 font-semibold text-xs bg-[#32b316] px-2 w-auto text-nowrap rounded-2xl -right-3", children: [
593
544
  discountValue.toLocaleString("pt-BR", {
594
545
  currency: "BRL",
595
546
  currencyDisplay: "symbol",
@@ -613,14 +564,14 @@ function Item({ data, onChange, checked }) {
613
564
  var Item_default = Item;
614
565
 
615
566
  // src/services/benefits-without-document.ts
616
- var import_js_cookie3 = __toESM(require("js-cookie"));
617
- var import_meta3 = {};
567
+ var import_js_cookie2 = __toESM(require("js-cookie"));
568
+ var import_meta2 = {};
618
569
  var CheckBenefistWithoutDocument = async ({ products }) => {
619
- const API_URL = import_meta3.env.VITE_API_URL;
570
+ const API_URL = import_meta2.env.VITE_API_URL;
620
571
  if (!API_URL) {
621
572
  throw new Error("API URL is not defined in environment variables");
622
573
  }
623
- const AUTH_TOKEN = import_js_cookie3.default.get("pbm-token");
574
+ const AUTH_TOKEN = import_js_cookie2.default.get("pbm-token");
624
575
  if (!AUTH_TOKEN) {
625
576
  throw new Error("Token is not defined in cookies or is expired");
626
577
  }
@@ -643,10 +594,10 @@ var CheckBenefistWithoutDocument = async ({ products }) => {
643
594
  var import_jsx_runtime9 = require("react/jsx-runtime");
644
595
  function BenefitsTable() {
645
596
  const { securityNumber, setState, targetProduct } = usePBMStore();
646
- const [selectedDiscout, setSelectedDiscount] = (0, import_react5.useState)(null);
647
- const [loading, setLoading] = (0, import_react5.useState)(true);
648
- const [benefitsItems, setBenefitsItems] = (0, import_react5.useState)();
649
- (0, import_react5.useEffect)(() => {
597
+ const [selectedDiscout, setSelectedDiscount] = (0, import_react4.useState)(null);
598
+ const [loading, setLoading] = (0, import_react4.useState)(true);
599
+ const [benefitsItems, setBenefitsItems] = (0, import_react4.useState)();
600
+ (0, import_react4.useEffect)(() => {
650
601
  const fetchDicountsWithoutDocument = async () => {
651
602
  if (!targetProduct?.productId) {
652
603
  console.error("PBMLOG: Product ID is not defined on targetProduct");
@@ -839,6 +790,7 @@ var getParams = (params) => {
839
790
  // src/components/UI/Link/index.tsx
840
791
  var import_jsx_runtime11 = require("react/jsx-runtime");
841
792
  function Link(props) {
793
+ const { setState } = usePBMStore();
842
794
  return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
843
795
  "a",
844
796
  {
@@ -846,11 +798,12 @@ function Link(props) {
846
798
  target: "_blank",
847
799
  href: typeof props.href === "string" ? props.href : props.href.pathname + getParams(props.href.param),
848
800
  className: (0, import_classnames7.default)(
849
- "w-3xs cursor-pointer h-10 rounded-full bg-emerald-500 hover:bg-emerald-400 text-white text-sm font-semibold transition-colors flex items-center justify-center",
801
+ "w-3xs cursor-pointer h-10 rounded-lg bg-emerald-500 hover:bg-emerald-400 text-white text-sm font-semibold transition-colors flex items-center justify-center",
850
802
  props.className
851
803
  ),
852
804
  "data-testid": "test_id_link",
853
805
  id: "link_pbm",
806
+ onClick: () => setState("isEmpty"),
854
807
  children: props.children
855
808
  }
856
809
  );
@@ -868,8 +821,12 @@ function SecurityNumberInvalid({ textColor }) {
868
821
  className: "flex items-end justify-center gap-2 w-full h-auto flex-col border-y border-zinc-300 py-6",
869
822
  id: "security_number_invalid_container_pbm",
870
823
  children: [
871
- /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Title_default, { className: "w-full", textColor, children: "CPF n\xE3o cadastrado!" }),
872
- /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Text_default, { className: "w-full", textColor, children: "Por favor, conclua seu cadastro para habilitar os benef\xEDcios deste laborat\xF3rio." }),
824
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(Title_default, { className: "w-full", textColor, children: "CPF n\xE3o cadastrado." }),
825
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(Text_default, { className: "w-full", textColor, children: [
826
+ "Conclua seu cadastro para habilitar o benef\xEDcio. ",
827
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("br", {}),
828
+ "Ao clicar em \u201CAceitar os termos\u201D, voc\xEA ir\xE1 para uma p\xE1gina externa. Aceite os termos e volte para continuar."
829
+ ] }),
873
830
  /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
874
831
  Link_default,
875
832
  {
@@ -884,7 +841,7 @@ function SecurityNumberInvalid({ textColor }) {
884
841
  var SecurityNumberInvalid_default = SecurityNumberInvalid;
885
842
 
886
843
  // src/PBM.tsx
887
- var import_react6 = require("react");
844
+ var import_react5 = require("react");
888
845
 
889
846
  // src/components/SecurityNumberRegitered/index.tsx
890
847
  var import_jsx_runtime13 = require("react/jsx-runtime");
@@ -897,8 +854,8 @@ function SecurityNumberRegitered({ textColor }) {
897
854
  className: "flex items-end justify-center gap-2 w-full h-auto flex-col border-y border-zinc-300 py-6",
898
855
  id: "security_number_registered_container_pbm",
899
856
  children: [
900
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Title_default, { className: "w-full", textColor, children: "CPF n\xE3o habilitado no produto!" }),
901
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Text_default, { className: "w-full", textColor, children: "Por favor, conclua seu cadastro para habilitar os benef\xEDcios deste laborat\xF3rio." }),
857
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Title_default, { className: "w-full", textColor, children: "Ops, seu CPF ainda n\xE3o est\xE1 habilitado para este produto." }),
858
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Text_default, { className: "w-full", textColor, children: "Para ativar o benef\xEDcio, clique em \u201CAtivar CPF\u201D e conclua a etapa na p\xE1gina externa. Depois, \xE9 s\xF3 voltar para continuar \u2014 vamos aguardar voc\xEA aqui." }),
902
859
  /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
903
860
  Link_default,
904
861
  {
@@ -913,12 +870,12 @@ function SecurityNumberRegitered({ textColor }) {
913
870
  var SecurityNumberRegitered_default = SecurityNumberRegitered;
914
871
 
915
872
  // src/services/authorization.ts
916
- var import_js_cookie4 = __toESM(require("js-cookie"));
917
- var import_meta4 = {};
873
+ var import_js_cookie3 = __toESM(require("js-cookie"));
874
+ var import_meta3 = {};
918
875
  var GetAuthorization = async ({ clientID }) => {
919
- const API_URL = import_meta4.env.VITE_API_URL;
920
- const STORE_ID = import_meta4.env.VITE_STORE_ID;
921
- const STORE_NAME = import_meta4.env.VITE_STORE_NAME;
876
+ const API_URL = import_meta3.env.VITE_API_URL;
877
+ const STORE_ID = import_meta3.env.VITE_STORE_ID;
878
+ const STORE_NAME = import_meta3.env.VITE_STORE_NAME;
922
879
  if (!API_URL) {
923
880
  throw new Error("API URL is not defined in environment variables");
924
881
  }
@@ -940,12 +897,12 @@ var GetAuthorization = async ({ clientID }) => {
940
897
  if (!dataResponse.success) {
941
898
  throw new Error(dataResponse.message || "Failed to fetch authorization");
942
899
  }
943
- import_js_cookie4.default.set("pbm-token", dataResponse.data.token, {
900
+ import_js_cookie3.default.set("pbm-token", dataResponse.data.token, {
944
901
  expires: dataResponse.data.expiresIn / (60 * 60),
945
902
  secure: true,
946
903
  sameSite: "Strict"
947
904
  });
948
- import_js_cookie4.default.set("pbm-token-refresh", dataResponse.data.refreshToken, {
905
+ import_js_cookie3.default.set("pbm-token-refresh", dataResponse.data.refreshToken, {
949
906
  expires: dataResponse.data.refreshExpiresIn / (60 * 60),
950
907
  secure: true,
951
908
  sameSite: "Strict"
@@ -955,6 +912,31 @@ var GetAuthorization = async ({ clientID }) => {
955
912
 
956
913
  // src/PBM.tsx
957
914
  var import_lucide_react3 = require("lucide-react");
915
+
916
+ // src/services/get-product-by-ean.ts
917
+ var import_js_cookie4 = __toESM(require("js-cookie"));
918
+ var import_meta4 = {};
919
+ var GetProductByEAN = async ({ PRODUCT_EAN }) => {
920
+ const API_URL = import_meta4.env.VITE_API_URL;
921
+ const AUTH_TOKEN = import_js_cookie4.default.get("pbm-token");
922
+ if (!AUTH_TOKEN) {
923
+ throw new Error("Token is not defined in cookies or is expired");
924
+ }
925
+ const response = await fetch(`${API_URL}/products/ean/${PRODUCT_EAN}`, {
926
+ method: "GET",
927
+ headers: {
928
+ Authorization: `Bearer ${AUTH_TOKEN}`,
929
+ "Content-Type": "application/json"
930
+ }
931
+ });
932
+ const dataResponse = await response.json();
933
+ if (!dataResponse.success) {
934
+ throw new Error(dataResponse.message || "Failed to fetch authorization");
935
+ }
936
+ return dataResponse;
937
+ };
938
+
939
+ // src/PBM.tsx
958
940
  var import_jsx_runtime14 = require("react/jsx-runtime");
959
941
  function PBM({
960
942
  originalProductPrice,
@@ -964,24 +946,44 @@ function PBM({
964
946
  const formatedOriginalProductPrice = Number(
965
947
  String(originalProductPrice).replace(",", ".")
966
948
  );
967
- const [loading, setLoading] = (0, import_react6.useState)(false);
968
- const { setState, state, setTargetProduct } = usePBMStore();
969
- (0, import_react6.useEffect)(() => {
970
- if (eanProduct) {
971
- setTargetProduct({ ean: eanProduct });
949
+ const [loading, setLoading] = (0, import_react5.useState)(false);
950
+ const { setState, state, setTargetProduct, targetProduct } = usePBMStore();
951
+ const fetchProductByEan = async () => {
952
+ try {
953
+ if (!eanProduct) {
954
+ console.error("PBMLOG: Ean is not defined.");
955
+ return;
956
+ }
957
+ const response = await GetProductByEAN({ PRODUCT_EAN: eanProduct });
958
+ if (response.success && response.data) {
959
+ const { pbm, sku, ...targetProductNewData } = response.data;
960
+ setTargetProduct({
961
+ ...targetProduct,
962
+ ...targetProductNewData,
963
+ productId: Number(targetProductNewData.productId),
964
+ informativeMessage: pbm.informativeMessage ?? "",
965
+ discountMax: pbm.discountMax ?? 0,
966
+ industryLogo: pbm.imageLink ?? void 0,
967
+ ean: eanProduct
968
+ });
969
+ }
970
+ } catch (error) {
971
+ console.error(error);
972
972
  }
973
- }, [eanProduct, setTargetProduct]);
974
- const handleAuthorizationRequest = (0, import_react6.useCallback)(async () => {
973
+ };
974
+ const handleAuthorizationRequest = (0, import_react5.useCallback)(async () => {
975
975
  try {
976
976
  const response = await GetAuthorization({ clientID });
977
- if (!response.success) {
977
+ if (response.success) {
978
+ fetchProductByEan();
979
+ } else {
978
980
  console.error("PBMLOG: Authorization failed!");
979
981
  }
980
982
  } catch (error) {
981
983
  console.error("Error fetching authorization:", error);
982
984
  }
983
985
  }, [clientID]);
984
- (0, import_react6.useEffect)(() => {
986
+ (0, import_react5.useEffect)(() => {
985
987
  handleAuthorizationRequest();
986
988
  }, [handleAuthorizationRequest]);
987
989
  return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { id: "pbm-library-root", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(Container_default, { variant: "main", children: [