@navservice/assinatura 1.36.0 → 1.38.0

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.
@@ -2,6 +2,7 @@ import t from "../../../../shared/types";
2
2
  interface ButtonGerarUrlProps {
3
3
  input: t.Controller.Assinatura.CriarCheckoutSession.Input;
4
4
  label?: string;
5
+ setUpgradePlano: boolean;
5
6
  }
6
- export default function ButtonGerarUrl({ input, label }: ButtonGerarUrlProps): import("react/jsx-runtime").JSX.Element;
7
+ export default function ButtonGerarUrl({ input, label, setUpgradePlano }: ButtonGerarUrlProps): import("react/jsx-runtime").JSX.Element;
7
8
  export {};
@@ -10,6 +10,11 @@ interface AssinaturaState {
10
10
  produto_id: string | null;
11
11
  periodos: string[];
12
12
  };
13
+ gerenciar: {
14
+ output: t.Controller.Assinatura.Gerenciar.Output['data']['assinatura'] | undefined;
15
+ response: t.Controller.Assinatura.Gerenciar.Response | undefined;
16
+ loading: boolean;
17
+ };
13
18
  checkout: t.Controller.Assinatura.CriarCheckoutSession.Output | null;
14
19
  loading: boolean;
15
20
  }
@@ -22,6 +27,7 @@ declare class contexto_assinatura {
22
27
  deletar_pelo_id: (props: t.Controller.Assinatura.DeletarPeloId.Input) => Promise<t.Controller.Assinatura.DeletarPeloId.Output | null>;
23
28
  buscar_produto_stripe: () => Promise<void>;
24
29
  criar_checkout_session: (props: t.Controller.Assinatura.CriarCheckoutSession.Input) => Promise<t.Controller.Assinatura.CriarCheckoutSession.Output | null>;
30
+ gerenciar: (props: t.Controller.Assinatura.Gerenciar.Input) => Promise<void>;
25
31
  };
26
32
  get get_jsx(): AssinaturaState;
27
33
  get get_state(): AssinaturaState;
@@ -1,2 +1,2 @@
1
- export { CheckoutStripe } from "./componentes/checkout/Stype";
1
+ export { CheckoutStripe } from "./componentes/checkout/Stripe";
2
2
  export { CheckoutAssinaturaStripe } from "./componentes/checkout/CheckoutAssinaturaStripe";
package/build/es/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  /*! For license information please see index.js.LICENSE.txt */
2
2
  import * as __rspack_external_React from "React";
3
+ import { createPortal } from "react-dom";
3
4
  import { TypesUsuario } from "@navservice/usuario";
4
5
  var __webpack_modules__ = {
5
6
  "../../node_modules/react/cjs/react-jsx-runtime.development.js" (__unused_rspack_module, exports, __webpack_require__) {
@@ -199,6 +200,7 @@ var __webpack_modules__ = {
199
200
  var unknownOwnerDebugStack = React.react_stack_bottom_frame.bind(React, UnknownOwner)();
200
201
  var unknownOwnerDebugTask = createTask(getTaskName(UnknownOwner));
201
202
  var didWarnAboutKeySpread = {};
203
+ exports.Fragment = REACT_FRAGMENT_TYPE;
202
204
  exports.jsx = function(type, config, maybeKey) {
203
205
  var trackActualOwner = 1e4 > ReactSharedInternals.recentlyCreatedOwnerStacks++;
204
206
  return jsxDEVImpl(type, config, maybeKey, !1, trackActualOwner ? Error("react-stack-top-frame") : unknownOwnerDebugStack, trackActualOwner ? createTask(getTaskName(type)) : unknownOwnerDebugTask);
@@ -218,8 +220,7 @@ var __webpack_modules__ = {
218
220
  *
219
221
  * This source code is licensed under the MIT license found in the
220
222
  * LICENSE file in the root directory of this source tree.
221
- */ var REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element");
222
- Symbol.for("react.fragment");
223
+ */ var REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"), REACT_FRAGMENT_TYPE = Symbol.for("react.fragment");
223
224
  function jsxProd(type, config, maybeKey) {
224
225
  var key = null;
225
226
  void 0 !== maybeKey && (key = "" + maybeKey);
@@ -237,6 +238,7 @@ var __webpack_modules__ = {
237
238
  props: maybeKey
238
239
  };
239
240
  }
241
+ exports.Fragment = REACT_FRAGMENT_TYPE;
240
242
  exports.jsx = jsxProd;
241
243
  exports.jsxs = jsxProd;
242
244
  },
@@ -19112,7 +19114,8 @@ const AssinaturaStatusZod = v4["enum"](AssinaturaStatusEnum);
19112
19114
  CriarCheckoutSession.InputSchema = v4.object({
19113
19115
  data: v4.object({
19114
19116
  checkout: v4.object({
19115
- price_id: v4.string()
19117
+ price_id: v4.string(),
19118
+ success_url: v4.url()
19116
19119
  })
19117
19120
  })
19118
19121
  });
@@ -19121,10 +19124,16 @@ const AssinaturaStatusZod = v4["enum"](AssinaturaStatusEnum);
19121
19124
  Cancelar.route = "/api/assinatura";
19122
19125
  Cancelar.InputSchema = v4.object({});
19123
19126
  })(TypeControllerAssinatura.Cancelar || (TypeControllerAssinatura.Cancelar = {}));
19124
- (function(GerenciarAssinatura) {
19125
- GerenciarAssinatura.route = "/api/assinatura/gerenciar";
19126
- GerenciarAssinatura.InputSchema = v4.object({});
19127
- })(TypeControllerAssinatura.GerenciarAssinatura || (TypeControllerAssinatura.GerenciarAssinatura = {}));
19127
+ (function(Gerenciar) {
19128
+ Gerenciar.route = "/api/assinatura/gerenciar";
19129
+ Gerenciar.InputSchema = v4.object({
19130
+ data: v4.object({
19131
+ assinatura: v4.object({
19132
+ success_url: v4.url()
19133
+ })
19134
+ })
19135
+ });
19136
+ })(TypeControllerAssinatura.Gerenciar || (TypeControllerAssinatura.Gerenciar = {}));
19128
19137
  (function(UpgradeEDownGradeAssinatura) {
19129
19138
  UpgradeEDownGradeAssinatura.route = "/api/assinatura/upgrade_downgrade";
19130
19139
  UpgradeEDownGradeAssinatura.InputSchema = v4.object({
@@ -19307,6 +19316,11 @@ const criar_estado_inicial = ()=>({
19307
19316
  produto_id: null,
19308
19317
  periodos: []
19309
19318
  },
19319
+ gerenciar: {
19320
+ loading: false,
19321
+ output: void 0,
19322
+ response: void 0
19323
+ },
19310
19324
  checkout: null,
19311
19325
  paginacao: {
19312
19326
  total_itens: 0,
@@ -19482,6 +19496,30 @@ class contexto_assinatura {
19482
19496
  s.loading = false;
19483
19497
  });
19484
19498
  }
19499
+ },
19500
+ gerenciar: async (props)=>{
19501
+ try {
19502
+ this.set_state((s)=>{
19503
+ s.gerenciar.loading = true;
19504
+ });
19505
+ const response = await src_utils.api.servidor_pricipal.post({
19506
+ baseURLKey: "PUBLIC_BASE_URL_BACKEND_ASSINATURA",
19507
+ url: shared_types.Controller.Assinatura.Gerenciar.route,
19508
+ data: props
19509
+ });
19510
+ const data = response?.data?.results ?? null;
19511
+ if (data?.data?.assinatura) this.set_state((s)=>{
19512
+ s.gerenciar = {
19513
+ loading: false,
19514
+ output: data.data.assinatura,
19515
+ response: response
19516
+ };
19517
+ });
19518
+ } finally{
19519
+ this.set_state((s)=>{
19520
+ if (true === s.gerenciar.loading) s.gerenciar.loading = false;
19521
+ });
19522
+ }
19485
19523
  }
19486
19524
  };
19487
19525
  get get_jsx() {
@@ -19497,9 +19535,10 @@ class contexto_assinatura {
19497
19535
  };
19498
19536
  }
19499
19537
  const contexto_contexto_assinatura = new contexto_assinatura();
19500
- function ButtonGerarUrl({ input, label = "Gerar link de pagamento" }) {
19538
+ function ButtonGerarUrl({ input, label = "Gerar link de pagamento", setUpgradePlano }) {
19501
19539
  const [isLoading, setIsLoading] = (0, external_React_.useState)(false);
19502
19540
  const [hasError, setHasError] = (0, external_React_.useState)(false);
19541
+ const [openConfirm, setOpenConfirm] = (0, external_React_.useState)(false);
19503
19542
  async function handleClick() {
19504
19543
  if (isLoading) return;
19505
19544
  try {
@@ -19516,28 +19555,72 @@ function ButtonGerarUrl({ input, label = "Gerar link de pagamento" }) {
19516
19555
  setIsLoading(false);
19517
19556
  }
19518
19557
  }
19519
- return /*#__PURE__*/ (0, jsx_runtime.jsxs)("button", {
19520
- type: "button",
19521
- onClick: handleClick,
19522
- disabled: isLoading,
19523
- className: `
19524
- inline-flex items-center justify-center min-w-[180px] gap-2
19525
- px-5 py-2.5 rounded-full font-semibold text-sm
19526
- transition-all duration-200 ease-out
19527
- ${isLoading ? "cursor-not-allowed bg-default-100 text-default-400 border border-default-300" : "cursor-pointer bg-primary-600 text-white hover:bg-primary-700 shadow-lg"}
19528
- relative select-none active:scale-95
19529
- `,
19558
+ function onButtonClick() {
19559
+ if (setUpgradePlano) return void setOpenConfirm(true);
19560
+ handleClick();
19561
+ }
19562
+ return /*#__PURE__*/ (0, jsx_runtime.jsxs)(jsx_runtime.Fragment, {
19530
19563
  children: [
19531
- /*#__PURE__*/ (0, jsx_runtime.jsx)("span", {
19532
- children: isLoading ? "Processando..." : label
19533
- }),
19534
- isLoading && /*#__PURE__*/ (0, jsx_runtime.jsx)("span", {
19535
- className: "w-4 h-4 rounded-full border-2 border-default-300 border-t-primary-600 animate-spin"
19564
+ /*#__PURE__*/ (0, jsx_runtime.jsxs)("button", {
19565
+ type: "button",
19566
+ onClick: onButtonClick,
19567
+ disabled: isLoading,
19568
+ className: `
19569
+ inline-flex items-center justify-center min-w-[180px] gap-2
19570
+ px-5 py-2.5 rounded-full font-semibold text-sm
19571
+ transition-all duration-200 ease-out
19572
+ ${isLoading ? "cursor-not-allowed bg-default-100 text-default-400 border border-default-300" : "cursor-pointer bg-primary-600 text-white hover:bg-primary-700 shadow-lg"}
19573
+ relative select-none active:scale-95
19574
+ `,
19575
+ children: [
19576
+ /*#__PURE__*/ (0, jsx_runtime.jsx)("span", {
19577
+ children: isLoading ? "Processando..." : label
19578
+ }),
19579
+ isLoading && /*#__PURE__*/ (0, jsx_runtime.jsx)("span", {
19580
+ className: "w-4 h-4 rounded-full border-2 border-default-300 border-t-primary-600 animate-spin"
19581
+ }),
19582
+ hasError && !isLoading && /*#__PURE__*/ (0, jsx_runtime.jsx)("span", {
19583
+ className: "text-error-200 text-xs ml-2 font-medium bg-white/10 px-1.5 py-0.5 rounded-sm",
19584
+ children: "Erro ao gerar"
19585
+ })
19586
+ ]
19536
19587
  }),
19537
- hasError && !isLoading && /*#__PURE__*/ (0, jsx_runtime.jsx)("span", {
19538
- className: "text-error-200 text-xs ml-2 font-medium bg-white/10 px-1.5 py-0.5 rounded-sm",
19539
- children: "Erro ao gerar"
19540
- })
19588
+ openConfirm && /*#__PURE__*/ createPortal(/*#__PURE__*/ (0, jsx_runtime.jsx)("div", {
19589
+ className: "fixed inset-0 z-[9999] flex items-center justify-center bg-black/60",
19590
+ children: /*#__PURE__*/ (0, jsx_runtime.jsxs)("div", {
19591
+ className: "bg-white rounded-xl p-6 w-full max-w-sm shadow-2xl",
19592
+ children: [
19593
+ /*#__PURE__*/ (0, jsx_runtime.jsx)("h3", {
19594
+ className: "text-lg font-semibold text-default-900 mb-2",
19595
+ children: "Confirmar atualiza\xe7\xe3o de plano"
19596
+ }),
19597
+ /*#__PURE__*/ (0, jsx_runtime.jsx)("p", {
19598
+ className: "text-sm text-default-600 mb-6",
19599
+ children: "Voc\xea tem certeza que deseja prosseguir com a atualiza\xe7\xe3o do seu plano?"
19600
+ }),
19601
+ /*#__PURE__*/ (0, jsx_runtime.jsxs)("div", {
19602
+ className: "flex justify-end gap-3",
19603
+ children: [
19604
+ /*#__PURE__*/ (0, jsx_runtime.jsx)("button", {
19605
+ type: "button",
19606
+ onClick: ()=>setOpenConfirm(false),
19607
+ className: "px-4 py-2 rounded-lg text-sm font-medium bg-default-100 hover:bg-default-200",
19608
+ children: "Cancelar"
19609
+ }),
19610
+ /*#__PURE__*/ (0, jsx_runtime.jsx)("button", {
19611
+ type: "button",
19612
+ onClick: ()=>{
19613
+ setOpenConfirm(false);
19614
+ handleClick();
19615
+ },
19616
+ className: "px-4 py-2 rounded-lg text-sm font-semibold bg-primary-600 text-white hover:bg-primary-700",
19617
+ children: "Confirmar"
19618
+ })
19619
+ ]
19620
+ })
19621
+ ]
19622
+ })
19623
+ }), document.body)
19541
19624
  ]
19542
19625
  });
19543
19626
  }
@@ -19752,11 +19835,13 @@ function CheckoutAssinaturaStripe() {
19752
19835
  /*#__PURE__*/ (0, jsx_runtime.jsx)("div", {
19753
19836
  className: "w-full flex justify-center",
19754
19837
  children: /*#__PURE__*/ (0, jsx_runtime.jsx)(ButtonGerarUrl, {
19755
- label: "Ir para Pagamento Seguro",
19838
+ setUpgradePlano: true,
19839
+ label: planoAtualEhFree && "Ir Para Pagamento Seguro" || "Atualizar Meu Plano",
19756
19840
  input: {
19757
19841
  data: {
19758
19842
  checkout: {
19759
- price_id: produto_id
19843
+ price_id: produto_id,
19844
+ success_url: window.location.origin
19760
19845
  }
19761
19846
  }
19762
19847
  }
@@ -195,6 +195,7 @@ declare namespace TypeControllerAssinatura {
195
195
  data: z4.ZodObject<{
196
196
  checkout: z4.ZodObject<{
197
197
  price_id: z4.ZodString;
198
+ success_url: z4.ZodURL;
198
199
  }, z4.core.$strip>;
199
200
  }, z4.core.$strip>;
200
201
  }, z4.core.$strip>;
@@ -219,9 +220,15 @@ declare namespace TypeControllerAssinatura {
219
220
  };
220
221
  type Response = AxiosResponse<t.Geral.Response.C.Output<Output>>;
221
222
  }
222
- namespace GerenciarAssinatura {
223
+ namespace Gerenciar {
223
224
  const route: "/api/assinatura/gerenciar";
224
- const InputSchema: z4.ZodObject<{}, z4.core.$strip>;
225
+ const InputSchema: z4.ZodObject<{
226
+ data: z4.ZodObject<{
227
+ assinatura: z4.ZodObject<{
228
+ success_url: z4.ZodURL;
229
+ }, z4.core.$strip>;
230
+ }, z4.core.$strip>;
231
+ }, z4.core.$strip>;
225
232
  type Input = z4.infer<typeof InputSchema>;
226
233
  type Output = {
227
234
  data: {
@@ -19,6 +19,7 @@ declare namespace t {
19
19
  STRIPE_PRICES_ID_SERVICE_USUARIO?: string;
20
20
  STRIPE_PRICES_ID_SERVICE_PAGES_AI?: string;
21
21
  STRIPE_SECRET_KEY?: string;
22
+ STRIPE_SECRET_KEY_WEBHOOKS_RESPONSE?: string;
22
23
  PUBLIC_BASE_URL_BACKEND_ASSINATURA?: string;
23
24
  PUBLIC_BASE_URL_FRTONEND_PRINCIPAL?: string;
24
25
  RESEND_API_KEY?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@navservice/assinatura",
3
- "version": "1.36.0",
3
+ "version": "1.38.0",
4
4
  "description": "Service de autenticação de usuários unificado",
5
5
  "type": "module",
6
6
  "main": "./build/lib/index.js",