@navservice/assinatura 1.37.0 → 1.41.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,10 +10,15 @@ 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
  }
16
- declare class contexto_assinatura {
21
+ export declare const contexto_assinatura: {
17
22
  api: {
18
23
  criar: (props: t.Controller.Assinatura.Criar.Input) => Promise<t.Controller.Assinatura.Criar.Output | null>;
19
24
  buscar_pelo_id: (props: t.Controller.Assinatura.BuscarPeloId.Input) => Promise<t.Controller.Assinatura.BuscarPeloId.Output | null>;
@@ -22,10 +27,10 @@ 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;
28
34
  set_state: (updater: (state: AssinaturaState) => void) => void;
29
- }
30
- declare const _default: contexto_assinatura;
31
- export default _default;
35
+ };
36
+ export {};
@@ -1,2 +1,3 @@
1
- export { CheckoutStripe } from "./componentes/checkout/Stype";
1
+ export { CheckoutStripe } from "./componentes/checkout/Stripe";
2
2
  export { CheckoutAssinaturaStripe } from "./componentes/checkout/CheckoutAssinaturaStripe";
3
+ export { contexto_assinatura } from "./contexto/contexto_assinatura";
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,
@@ -19319,7 +19333,7 @@ const criar_estado_inicial = ()=>({
19319
19333
  const contexto_assinatura_store = react_create()(immer_immer(()=>({
19320
19334
  states: criar_estado_inicial()
19321
19335
  })));
19322
- class contexto_assinatura {
19336
+ const contexto_assinatura = new class {
19323
19337
  api = {
19324
19338
  criar: async (props)=>{
19325
19339
  try {
@@ -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() {
@@ -19495,17 +19533,17 @@ class contexto_assinatura {
19495
19533
  updater(s.states);
19496
19534
  });
19497
19535
  };
19498
- }
19499
- const contexto_contexto_assinatura = new contexto_assinatura();
19500
- function ButtonGerarUrl({ input, label = "Gerar link de pagamento" }) {
19536
+ };
19537
+ function ButtonGerarUrl({ input, label = "Gerar link de pagamento", setUpgradePlano }) {
19501
19538
  const [isLoading, setIsLoading] = (0, external_React_.useState)(false);
19502
19539
  const [hasError, setHasError] = (0, external_React_.useState)(false);
19540
+ const [openConfirm, setOpenConfirm] = (0, external_React_.useState)(false);
19503
19541
  async function handleClick() {
19504
19542
  if (isLoading) return;
19505
19543
  try {
19506
19544
  setIsLoading(true);
19507
19545
  setHasError(false);
19508
- const resultado = await contexto_contexto_assinatura.api.criar_checkout_session(input);
19546
+ const resultado = await contexto_assinatura.api.criar_checkout_session(input);
19509
19547
  const url = resultado?.data?.checkout?.url;
19510
19548
  if (resultado?.data?.checkout?.tipo_evento === "upgrade") return window.location.reload();
19511
19549
  if ("string" == typeof url && url.length > 0) window.location.href = url;
@@ -19516,28 +19554,72 @@ function ButtonGerarUrl({ input, label = "Gerar link de pagamento" }) {
19516
19554
  setIsLoading(false);
19517
19555
  }
19518
19556
  }
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
- `,
19557
+ function onButtonClick() {
19558
+ if (setUpgradePlano) return void setOpenConfirm(true);
19559
+ handleClick();
19560
+ }
19561
+ return /*#__PURE__*/ (0, jsx_runtime.jsxs)(jsx_runtime.Fragment, {
19530
19562
  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"
19563
+ /*#__PURE__*/ (0, jsx_runtime.jsxs)("button", {
19564
+ type: "button",
19565
+ onClick: onButtonClick,
19566
+ disabled: isLoading,
19567
+ className: `
19568
+ inline-flex items-center justify-center min-w-[180px] gap-2
19569
+ px-5 py-2.5 rounded-full font-semibold text-sm
19570
+ transition-all duration-200 ease-out
19571
+ ${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"}
19572
+ relative select-none active:scale-95
19573
+ `,
19574
+ children: [
19575
+ /*#__PURE__*/ (0, jsx_runtime.jsx)("span", {
19576
+ children: isLoading ? "Processando..." : label
19577
+ }),
19578
+ isLoading && /*#__PURE__*/ (0, jsx_runtime.jsx)("span", {
19579
+ className: "w-4 h-4 rounded-full border-2 border-default-300 border-t-primary-600 animate-spin"
19580
+ }),
19581
+ hasError && !isLoading && /*#__PURE__*/ (0, jsx_runtime.jsx)("span", {
19582
+ className: "text-error-200 text-xs ml-2 font-medium bg-white/10 px-1.5 py-0.5 rounded-sm",
19583
+ children: "Erro ao gerar"
19584
+ })
19585
+ ]
19536
19586
  }),
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
- })
19587
+ openConfirm && /*#__PURE__*/ createPortal(/*#__PURE__*/ (0, jsx_runtime.jsx)("div", {
19588
+ className: "fixed inset-0 z-[9999] flex items-center justify-center bg-black/60",
19589
+ children: /*#__PURE__*/ (0, jsx_runtime.jsxs)("div", {
19590
+ className: "bg-white rounded-xl p-6 w-full max-w-sm shadow-2xl",
19591
+ children: [
19592
+ /*#__PURE__*/ (0, jsx_runtime.jsx)("h3", {
19593
+ className: "text-lg font-semibold text-default-900 mb-2",
19594
+ children: "Confirmar atualiza\xe7\xe3o de plano"
19595
+ }),
19596
+ /*#__PURE__*/ (0, jsx_runtime.jsx)("p", {
19597
+ className: "text-sm text-default-600 mb-6",
19598
+ children: "Voc\xea tem certeza que deseja prosseguir com a atualiza\xe7\xe3o do seu plano?"
19599
+ }),
19600
+ /*#__PURE__*/ (0, jsx_runtime.jsxs)("div", {
19601
+ className: "flex justify-end gap-3",
19602
+ children: [
19603
+ /*#__PURE__*/ (0, jsx_runtime.jsx)("button", {
19604
+ type: "button",
19605
+ onClick: ()=>setOpenConfirm(false),
19606
+ className: "px-4 py-2 rounded-lg text-sm font-medium bg-default-100 hover:bg-default-200",
19607
+ children: "Cancelar"
19608
+ }),
19609
+ /*#__PURE__*/ (0, jsx_runtime.jsx)("button", {
19610
+ type: "button",
19611
+ onClick: ()=>{
19612
+ setOpenConfirm(false);
19613
+ handleClick();
19614
+ },
19615
+ className: "px-4 py-2 rounded-lg text-sm font-semibold bg-primary-600 text-white hover:bg-primary-700",
19616
+ children: "Confirmar"
19617
+ })
19618
+ ]
19619
+ })
19620
+ ]
19621
+ })
19622
+ }), document.body)
19541
19623
  ]
19542
19624
  });
19543
19625
  }
@@ -19550,11 +19632,11 @@ function labelPeriodo(interval, count) {
19550
19632
  return `${count} ${interval}`;
19551
19633
  }
19552
19634
  function CheckoutAssinaturaStripe() {
19553
- const { data, loading, periodo_selecionado, produto_id, periodos } = contexto_contexto_assinatura.get_jsx.produto;
19635
+ const { data, loading, periodo_selecionado, produto_id, periodos } = contexto_assinatura.get_jsx.produto;
19554
19636
  const isMobile = src_utils.hooks.use_is_mobile();
19555
19637
  const selecionadoManual = (0, external_React_.useRef)(false);
19556
19638
  (0, external_React_.useEffect)(()=>{
19557
- contexto_contexto_assinatura.api.buscar_produto_stripe();
19639
+ contexto_assinatura.api.buscar_produto_stripe();
19558
19640
  }, []);
19559
19641
  const planoAtualPriceId = data?.plano_atual?.price_id ?? null;
19560
19642
  const planoAtualEhFree = null === planoAtualPriceId;
@@ -19576,12 +19658,12 @@ function CheckoutAssinaturaStripe() {
19576
19658
  (0, external_React_.useEffect)(()=>{
19577
19659
  if (!data?.produtos?.length) return;
19578
19660
  if (selecionadoManual.current) return;
19579
- if (!planoAtualEhFree && planoAtualPriceId) return void contexto_contexto_assinatura.set_state((store)=>{
19661
+ if (!planoAtualEhFree && planoAtualPriceId) return void contexto_assinatura.set_state((store)=>{
19580
19662
  store.produto.produto_id = planoAtualPriceId;
19581
19663
  });
19582
19664
  if (planoAtualEhFree) {
19583
19665
  const primeiroZero = data.produtos.flatMap((p)=>p.precos).find((p)=>0 === p.unit_amount);
19584
- if (primeiroZero) contexto_contexto_assinatura.set_state((store)=>{
19666
+ if (primeiroZero) contexto_assinatura.set_state((store)=>{
19585
19667
  store.produto.produto_id = primeiroZero.id;
19586
19668
  });
19587
19669
  }
@@ -19639,7 +19721,7 @@ function CheckoutAssinaturaStripe() {
19639
19721
  const ativo = periodo_selecionado === id;
19640
19722
  return /*#__PURE__*/ (0, jsx_runtime.jsx)("button", {
19641
19723
  type: "button",
19642
- onClick: ()=>contexto_contexto_assinatura.set_state((store)=>{
19724
+ onClick: ()=>contexto_assinatura.set_state((store)=>{
19643
19725
  store.produto.periodo_selecionado = id;
19644
19726
  store.produto.produto_id = null;
19645
19727
  selecionadoManual.current = false;
@@ -19669,7 +19751,7 @@ function CheckoutAssinaturaStripe() {
19669
19751
  return /*#__PURE__*/ (0, jsx_runtime.jsxs)("article", {
19670
19752
  onClick: ()=>{
19671
19753
  selecionadoManual.current = true;
19672
- contexto_contexto_assinatura.set_state((store)=>{
19754
+ contexto_assinatura.set_state((store)=>{
19673
19755
  store.produto.produto_id = precoAtivo.id;
19674
19756
  });
19675
19757
  },
@@ -19752,11 +19834,13 @@ function CheckoutAssinaturaStripe() {
19752
19834
  /*#__PURE__*/ (0, jsx_runtime.jsx)("div", {
19753
19835
  className: "w-full flex justify-center",
19754
19836
  children: /*#__PURE__*/ (0, jsx_runtime.jsx)(ButtonGerarUrl, {
19755
- label: "Ir para Pagamento Seguro",
19837
+ setUpgradePlano: true,
19838
+ label: planoAtualEhFree && "Ir Para Pagamento Seguro" || "Atualizar Meu Plano",
19756
19839
  input: {
19757
19840
  data: {
19758
19841
  checkout: {
19759
- price_id: produto_id
19842
+ price_id: produto_id,
19843
+ success_url: window.location.origin
19760
19844
  }
19761
19845
  }
19762
19846
  }
@@ -19867,4 +19951,4 @@ function CheckoutAssinaturaStripe() {
19867
19951
  ]
19868
19952
  });
19869
19953
  }
19870
- export { CheckoutAssinaturaStripe, CheckoutStripe };
19954
+ export { CheckoutAssinaturaStripe, CheckoutStripe, contexto_assinatura };
@@ -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.37.0",
3
+ "version": "1.41.0",
4
4
  "description": "Service de autenticação de usuários unificado",
5
5
  "type": "module",
6
6
  "main": "./build/lib/index.js",