godeep-states 1.0.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.
Files changed (65) hide show
  1. package/README.md +158 -0
  2. package/dist/module.d.mts +8 -0
  3. package/dist/module.json +9 -0
  4. package/dist/module.mjs +28 -0
  5. package/dist/runtime/composables/useHeader.d.ts +2 -0
  6. package/dist/runtime/composables/useHeader.js +33 -0
  7. package/dist/runtime/plugin.d.ts +2 -0
  8. package/dist/runtime/plugin.js +3 -0
  9. package/dist/runtime/server/api/[...slug].d.ts +2 -0
  10. package/dist/runtime/server/api/[...slug].js +66 -0
  11. package/dist/runtime/server/routes/robots.d.ts +2 -0
  12. package/dist/runtime/server/routes/robots.js +37 -0
  13. package/dist/runtime/server/routes/robots.txt.d.ts +2 -0
  14. package/dist/runtime/server/routes/robots.txt.js +37 -0
  15. package/dist/runtime/server/tsconfig.json +3 -0
  16. package/dist/runtime/stores/.vscode/settings.json +3 -0
  17. package/dist/runtime/stores/avaliacoes.d.ts +53 -0
  18. package/dist/runtime/stores/avaliacoes.js +63 -0
  19. package/dist/runtime/stores/banner.d.ts +6 -0
  20. package/dist/runtime/stores/banner.js +88 -0
  21. package/dist/runtime/stores/busca.d.ts +8 -0
  22. package/dist/runtime/stores/busca.js +51 -0
  23. package/dist/runtime/stores/cadastro.d.ts +6 -0
  24. package/dist/runtime/stores/cadastro.js +117 -0
  25. package/dist/runtime/stores/carrinho.d.ts +8 -0
  26. package/dist/runtime/stores/carrinho.js +219 -0
  27. package/dist/runtime/stores/categoria.d.ts +10 -0
  28. package/dist/runtime/stores/categoria.js +137 -0
  29. package/dist/runtime/stores/configuracoes.d.ts +16 -0
  30. package/dist/runtime/stores/configuracoes.js +85 -0
  31. package/dist/runtime/stores/dados-cadastrais.d.ts +7 -0
  32. package/dist/runtime/stores/dados-cadastrais.js +89 -0
  33. package/dist/runtime/stores/enderecos.d.ts +7 -0
  34. package/dist/runtime/stores/enderecos.js +217 -0
  35. package/dist/runtime/stores/favoritos.d.ts +7 -0
  36. package/dist/runtime/stores/favoritos.js +120 -0
  37. package/dist/runtime/stores/filtros.d.ts +9 -0
  38. package/dist/runtime/stores/filtros.js +63 -0
  39. package/dist/runtime/stores/home.d.ts +5 -0
  40. package/dist/runtime/stores/home.js +59 -0
  41. package/dist/runtime/stores/login.d.ts +13 -0
  42. package/dist/runtime/stores/login.js +195 -0
  43. package/dist/runtime/stores/menus.d.ts +5 -0
  44. package/dist/runtime/stores/menus.js +35 -0
  45. package/dist/runtime/stores/newsletter.d.ts +6 -0
  46. package/dist/runtime/stores/newsletter.js +80 -0
  47. package/dist/runtime/stores/pagamentos.d.ts +5 -0
  48. package/dist/runtime/stores/pagamentos.js +35 -0
  49. package/dist/runtime/stores/paginas.d.ts +5 -0
  50. package/dist/runtime/stores/paginas.js +35 -0
  51. package/dist/runtime/stores/pedidos.d.ts +7 -0
  52. package/dist/runtime/stores/pedidos.js +59 -0
  53. package/dist/runtime/stores/produto.d.ts +9 -0
  54. package/dist/runtime/stores/produto.js +141 -0
  55. package/dist/runtime/stores/redes-sociais.d.ts +5 -0
  56. package/dist/runtime/stores/redes-sociais.js +38 -0
  57. package/dist/runtime/stores/vitrine.d.ts +13 -0
  58. package/dist/runtime/stores/vitrine.js +192 -0
  59. package/dist/runtime/types.d.ts +7 -0
  60. package/dist/runtime/utils/alerta.d.ts +10 -0
  61. package/dist/runtime/utils/alerta.js +7 -0
  62. package/dist/runtime/utils/erros.d.ts +15 -0
  63. package/dist/runtime/utils/erros.js +20 -0
  64. package/dist/types.d.mts +3 -0
  65. package/package.json +73 -0
@@ -0,0 +1,192 @@
1
+ import { traduzirVitrineListagem } from "godeep-types/translate";
2
+ import { defineStore } from "pinia";
3
+ function normalizarSlug(slug) {
4
+ const limpado = slug.startsWith("/") ? slug.slice(1) : slug;
5
+ const partes = limpado.split("/").filter(Boolean);
6
+ const base = partes[0] ?? "";
7
+ const subvitrine = partes.length > 1 ? partes[partes.length - 1] : "";
8
+ const completo = subvitrine ? `${base}/${subvitrine}` : base;
9
+ return { base, subvitrine, completo };
10
+ }
11
+ export const storeVitrine = defineStore("vitrine", {
12
+ state: () => ({
13
+ vitrine: {},
14
+ vitrinesCache: {},
15
+ carregando: false,
16
+ paginaAtual: 1,
17
+ ordenacao: "",
18
+ filtrosAtivos: {},
19
+ slugBase: "",
20
+ subvitrineAtiva: ""
21
+ }),
22
+ getters: {
23
+ recuperarVitrine: (state) => state.vitrine,
24
+ vitrineCarregando: (state) => state.carregando,
25
+ recuperarProdutos: (state) => state.vitrine?.produtos ?? [],
26
+ totalPaginas: (state) => state.vitrine?.paginador?.ultimaPagina ?? 1,
27
+ recuperarPaginaAtual: (state) => state.vitrine?.paginador?.paginaAtual ?? state.paginaAtual,
28
+ recuperarOrdenacao: (state) => state.ordenacao,
29
+ recuperarFiltros: (state) => state.filtrosAtivos,
30
+ recuperarSlugCompleto: (state) => state.subvitrineAtiva ? `${state.slugBase}/${state.subvitrineAtiva}` : state.slugBase,
31
+ recuperarSubvitrine: (state) => state.subvitrineAtiva
32
+ },
33
+ actions: {
34
+ resetarVitrine() {
35
+ this.vitrine = {};
36
+ this.carregando = false;
37
+ this.paginaAtual = 1;
38
+ this.ordenacao = "";
39
+ this.filtrosAtivos = {};
40
+ this.slugBase = "";
41
+ this.subvitrineAtiva = "";
42
+ },
43
+ definirSlug(slug) {
44
+ const { base, subvitrine, completo } = normalizarSlug(slug);
45
+ this.slugBase = base;
46
+ this.subvitrineAtiva = subvitrine ?? "";
47
+ if (subvitrine) {
48
+ this.filtrosAtivos = {
49
+ ...this.filtrosAtivos,
50
+ subvitrine: [subvitrine]
51
+ };
52
+ } else if (this.filtrosAtivos.subvitrine) {
53
+ const { subvitrine: _, ...resto } = this.filtrosAtivos;
54
+ this.filtrosAtivos = resto;
55
+ }
56
+ return completo;
57
+ },
58
+ definirPagina(pagina) {
59
+ this.paginaAtual = pagina > 0 ? pagina : 1;
60
+ },
61
+ definirOrdenacao(ordenacao) {
62
+ this.ordenacao = ordenacao;
63
+ this.paginaAtual = 1;
64
+ },
65
+ alternarFiltro(secaoId, valor) {
66
+ if (secaoId === "subvitrine") {
67
+ const ativa = this.subvitrineAtiva === valor;
68
+ this.subvitrineAtiva = ativa ? "" : valor;
69
+ this.filtrosAtivos = {
70
+ ...this.filtrosAtivos,
71
+ subvitrine: this.subvitrineAtiva ? [this.subvitrineAtiva] : []
72
+ };
73
+ if (!this.subvitrineAtiva) {
74
+ const { subvitrine: _, ...resto } = this.filtrosAtivos;
75
+ this.filtrosAtivos = resto;
76
+ }
77
+ this.paginaAtual = 1;
78
+ return;
79
+ }
80
+ const existentes = this.filtrosAtivos[secaoId] ?? [];
81
+ const jaTem = existentes.includes(valor);
82
+ const novos = jaTem ? existentes.filter((item) => item !== valor) : [...existentes, valor];
83
+ this.filtrosAtivos = {
84
+ ...this.filtrosAtivos,
85
+ [secaoId]: novos
86
+ };
87
+ if (this.filtrosAtivos[secaoId]?.length === 0) {
88
+ const { [secaoId]: _, ...resto } = this.filtrosAtivos;
89
+ this.filtrosAtivos = resto;
90
+ }
91
+ this.paginaAtual = 1;
92
+ },
93
+ aplicarFiltroPreco(min, max) {
94
+ this.filtrosAtivos = {
95
+ ...this.filtrosAtivos,
96
+ preco: [`${min}:${max}`]
97
+ };
98
+ this.paginaAtual = 1;
99
+ },
100
+ limparFiltros() {
101
+ this.filtrosAtivos = {};
102
+ this.subvitrineAtiva = "";
103
+ this.paginaAtual = 1;
104
+ },
105
+ carregarFiltrosDaUrl(query, slug) {
106
+ this.definirSlug(slug);
107
+ const filtros = {};
108
+ const processar = (chave, destino) => {
109
+ const valor = query[chave];
110
+ if (!valor) return;
111
+ const lista = Array.isArray(valor) ? valor : [valor];
112
+ const strings = lista.filter(
113
+ (item) => typeof item === "string"
114
+ );
115
+ if (strings.length > 0) {
116
+ filtros[destino] = strings;
117
+ }
118
+ };
119
+ processar("precos", "preco");
120
+ processar("marcas", "marca");
121
+ processar("filtro", "filtro");
122
+ const pagina = query.page;
123
+ if (pagina && typeof pagina === "string") {
124
+ const numero = Number.parseInt(pagina);
125
+ if (!Number.isNaN(numero) && numero > 0) {
126
+ this.paginaAtual = numero;
127
+ }
128
+ }
129
+ const order = query.order;
130
+ if (order && typeof order === "string") {
131
+ this.ordenacao = order;
132
+ }
133
+ if (this.subvitrineAtiva) {
134
+ filtros.subvitrine = [this.subvitrineAtiva];
135
+ }
136
+ this.filtrosAtivos = filtros;
137
+ },
138
+ construirParametros(slugCompleto) {
139
+ const parametros = {
140
+ slug: slugCompleto,
141
+ page: this.paginaAtual
142
+ };
143
+ if (this.ordenacao) {
144
+ parametros.order = this.ordenacao;
145
+ }
146
+ Object.entries(this.filtrosAtivos).forEach(([secao, valores]) => {
147
+ if (!valores || valores.length === 0) return;
148
+ if (secao === "preco") {
149
+ parametros.precos = valores;
150
+ } else if (secao === "marca") {
151
+ parametros.marcas = valores;
152
+ } else if (secao === "filtro") {
153
+ parametros.filtro = valores;
154
+ } else if (secao === "subvitrine") {
155
+ }
156
+ });
157
+ return parametros;
158
+ },
159
+ async buscarVitrine(slug, usarCache = true) {
160
+ try {
161
+ this.carregando = true;
162
+ if (usarCache && this.vitrinesCache[slug]) {
163
+ this.vitrine = this.vitrinesCache[slug];
164
+ this.carregando = false;
165
+ return;
166
+ }
167
+ const slugCompleto = this.definirSlug(slug);
168
+ const parametros = this.construirParametros(slugCompleto);
169
+ const url = "/mocks/vitrine-mock.json";
170
+ const resposta = await $fetch(url, {
171
+ method: "GET",
172
+ params: parametros
173
+ });
174
+ const vitrineTraduzida = resposta ? traduzirVitrineListagem(resposta) : {};
175
+ this.vitrine = vitrineTraduzida;
176
+ if (usarCache) {
177
+ this.vitrinesCache[slug] = vitrineTraduzida;
178
+ }
179
+ } catch {
180
+ this.vitrine = {};
181
+ } finally {
182
+ this.carregando = false;
183
+ }
184
+ },
185
+ recuperarVitrineDoCache(slug) {
186
+ return this.vitrinesCache[slug];
187
+ }
188
+ },
189
+ persist: {
190
+ storage: piniaPluginPersistedstate.sessionStorage()
191
+ }
192
+ });
@@ -0,0 +1,7 @@
1
+ import type { PersistedStateFactory } from 'pinia-plugin-persistedstate'
2
+
3
+ declare global {
4
+ const piniaPluginPersistedstate: PersistedStateFactory
5
+ }
6
+
7
+ export {}
@@ -0,0 +1,10 @@
1
+ interface AlertaOpcoes {
2
+ titulo: string;
3
+ descricao?: string;
4
+ cor?: 'success' | 'error' | 'warning' | 'info';
5
+ variantes?: string[];
6
+ }
7
+ export declare const alerta: {
8
+ adicionar(opcoes: AlertaOpcoes): void;
9
+ };
10
+ export {};
@@ -0,0 +1,7 @@
1
+ export const alerta = {
2
+ adicionar(opcoes) {
3
+ if (import.meta.dev) {
4
+ console.log("[Alerta]", opcoes);
5
+ }
6
+ }
7
+ };
@@ -0,0 +1,15 @@
1
+ interface ErroResposta {
2
+ mensagem?: string;
3
+ mensagens?: Record<string, string[]>;
4
+ message?: string;
5
+ errors?: Record<string, string[]>;
6
+ data?: {
7
+ mensagens?: Record<string, string[]>;
8
+ };
9
+ }
10
+ interface MensagensErro {
11
+ mensagemGeral: string;
12
+ mensagensErro: Record<string, string[]>;
13
+ }
14
+ export declare function extrairMensagensErro(erro: ErroResposta, mensagemPadrao?: string): MensagensErro;
15
+ export {};
@@ -0,0 +1,20 @@
1
+ export function extrairMensagensErro(erro, mensagemPadrao = "Erro ao processar requisi\xE7\xE3o") {
2
+ const mensagensErro = {};
3
+ let mensagemGeral = mensagemPadrao;
4
+ if (erro.mensagem) {
5
+ mensagemGeral = erro.mensagem;
6
+ } else if (erro.message) {
7
+ mensagemGeral = erro.message;
8
+ }
9
+ if (erro.mensagens) {
10
+ Object.assign(mensagensErro, erro.mensagens);
11
+ } else if (erro.errors) {
12
+ Object.assign(mensagensErro, erro.errors);
13
+ } else if (erro.data?.mensagens) {
14
+ Object.assign(mensagensErro, erro.data.mensagens);
15
+ }
16
+ return {
17
+ mensagemGeral,
18
+ mensagensErro
19
+ };
20
+ }
@@ -0,0 +1,3 @@
1
+ export { default } from './module.mjs'
2
+
3
+ export { type ModuleOptions } from './module.mjs'
package/package.json ADDED
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "godeep-states",
3
+ "version": "1.0.0",
4
+ "description": "Stores Pinia e rotas de servidor para integração GoDeep com Nuxt",
5
+ "keywords": [
6
+ "nuxt",
7
+ "godeep",
8
+ "pinia",
9
+ "stores",
10
+ "state-management",
11
+ "server-routes"
12
+ ],
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/lucasagliardi-dev/godeep-states.git"
16
+ },
17
+ "bugs": {
18
+ "url": "https://github.com/lucasagliardi-dev/godeep-states/issues"
19
+ },
20
+ "homepage": "https://github.com/lucasagliardi-dev/godeep-states#readme",
21
+ "license": "MIT",
22
+ "type": "module",
23
+ "exports": {
24
+ ".": {
25
+ "types": "./dist/types.d.mts",
26
+ "import": "./dist/module.mjs"
27
+ }
28
+ },
29
+ "main": "./dist/module.mjs",
30
+ "typesVersions": {
31
+ "*": {
32
+ ".": [
33
+ "./dist/types.d.mts"
34
+ ]
35
+ }
36
+ },
37
+ "files": [
38
+ "dist"
39
+ ],
40
+ "scripts": {
41
+ "prepack": "nuxt-module-build build",
42
+ "dev": "npm run dev:prepare && nuxi dev playground",
43
+ "dev:build": "nuxi build playground",
44
+ "dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
45
+ "release": "npm run lint && npm run test && npm run prepack && changelogen --release && npm publish && git push --follow-tags",
46
+ "lint": "eslint .",
47
+ "lint:fix": "eslint . --fix",
48
+ "test": "vitest run",
49
+ "test:watch": "vitest watch",
50
+ "test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit",
51
+ "typecheck": "vue-tsc --noEmit"
52
+ },
53
+ "dependencies": {
54
+ "@nuxt/kit": "^4.2.2",
55
+ "godeep-types": "^1.0.0",
56
+ "pinia": "^2.2.0",
57
+ "pinia-plugin-persistedstate": "^3.2.0"
58
+ },
59
+ "devDependencies": {
60
+ "@nuxt/devtools": "^3.1.1",
61
+ "@nuxt/eslint-config": "^1.12.1",
62
+ "@nuxt/module-builder": "^1.0.2",
63
+ "@nuxt/schema": "^4.2.2",
64
+ "@nuxt/test-utils": "^3.22.0",
65
+ "@types/node": "latest",
66
+ "changelogen": "^0.6.2",
67
+ "eslint": "^9.39.2",
68
+ "nuxt": "^4.2.2",
69
+ "typescript": "~5.9.3",
70
+ "vitest": "^4.0.16",
71
+ "vue-tsc": "^3.2.2"
72
+ }
73
+ }