@seedgrid/fe-commons 0.2.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.
@@ -0,0 +1,18 @@
1
+ export type ViaCepResponse = {
2
+ cep: string;
3
+ logradouro: string;
4
+ complemento: string;
5
+ bairro: string;
6
+ localidade: string;
7
+ uf: string;
8
+ ibge: string;
9
+ gia: string;
10
+ ddd: string;
11
+ siafi: string;
12
+ erro?: boolean;
13
+ };
14
+ export type CepLookupOptions = {
15
+ signal?: AbortSignal;
16
+ };
17
+ export declare function buscarCep(cep: string, options?: CepLookupOptions): Promise<ViaCepResponse>;
18
+ //# sourceMappingURL=viacep.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"viacep.d.ts","sourceRoot":"","sources":["../../src/cep/viacep.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GAAG;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB,CAAC;AAMF,wBAAsB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,gBAAqB,GAAG,OAAO,CAAC,cAAc,CAAC,CAoBpG"}
@@ -0,0 +1,20 @@
1
+ function normalizeCep(value) {
2
+ return value.replace(/\D/g, "");
3
+ }
4
+ export async function buscarCep(cep, options = {}) {
5
+ const normalized = normalizeCep(cep);
6
+ if (normalized.length !== 8) {
7
+ throw new Error("CEP deve ter 8 dígitos.");
8
+ }
9
+ const response = await fetch(`https://viacep.com.br/ws/${normalized}/json/`, {
10
+ signal: options.signal
11
+ });
12
+ if (!response.ok) {
13
+ throw new Error(`Falha ao consultar CEP (${response.status}).`);
14
+ }
15
+ const data = (await response.json());
16
+ if (data.erro) {
17
+ throw new Error("CEP não encontrado.");
18
+ }
19
+ return data;
20
+ }
@@ -0,0 +1,136 @@
1
+ export type PublicaCnpjResponse = {
2
+ cnpj_raiz: string;
3
+ razao_social: string;
4
+ capital_social: string;
5
+ responsavel_federativo: string;
6
+ atualizado_em: string;
7
+ porte: {
8
+ id: string;
9
+ descricao: string;
10
+ };
11
+ natureza_juridica: {
12
+ id: string;
13
+ descricao: string;
14
+ };
15
+ qualificacao_do_responsavel: {
16
+ id: number;
17
+ descricao: string;
18
+ };
19
+ socios: Array<{
20
+ cpf_cnpj_socio: string;
21
+ nome: string;
22
+ tipo: string;
23
+ data_entrada: string;
24
+ cpf_representante_legal: string;
25
+ nome_representante: string | null;
26
+ faixa_etaria: string;
27
+ atualizado_em: string;
28
+ pais_id: string;
29
+ qualificacao_socio: {
30
+ id: number;
31
+ descricao: string;
32
+ };
33
+ qualificacao_representante: {
34
+ id: number;
35
+ descricao: string;
36
+ } | null;
37
+ pais: {
38
+ id: string;
39
+ iso2: string;
40
+ iso3: string;
41
+ nome: string;
42
+ comex_id: string;
43
+ };
44
+ }>;
45
+ simples: {
46
+ mei: string;
47
+ simples: string;
48
+ data_opcao_mei: string | null;
49
+ data_exclusao_mei: string | null;
50
+ data_opcao_simples: string | null;
51
+ data_exclusao_simples: string | null;
52
+ atualizado_em: string;
53
+ };
54
+ estabelecimento: {
55
+ cnpj: string;
56
+ atividades_secundarias: Array<{
57
+ id: string;
58
+ secao: string;
59
+ divisao: string;
60
+ grupo: string;
61
+ classe: string;
62
+ subclasse: string;
63
+ descricao: string;
64
+ }>;
65
+ cnpj_raiz: string;
66
+ cnpj_ordem: string;
67
+ cnpj_digito_verificador: string;
68
+ tipo: string;
69
+ nome_fantasia: string;
70
+ situacao_cadastral: string;
71
+ data_situacao_cadastral: string;
72
+ data_inicio_atividade: string;
73
+ nome_cidade_exterior: string | null;
74
+ tipo_logradouro: string;
75
+ logradouro: string;
76
+ numero: string;
77
+ complemento: string | null;
78
+ bairro: string;
79
+ cep: string;
80
+ ddd1: string;
81
+ telefone1: string;
82
+ ddd2: string | null;
83
+ telefone2: string | null;
84
+ ddd_fax: string | null;
85
+ fax: string | null;
86
+ email: string | null;
87
+ situacao_especial: string | null;
88
+ data_situacao_especial: string | null;
89
+ atualizado_em: string;
90
+ atividade_principal: {
91
+ id: string;
92
+ secao: string;
93
+ divisao: string;
94
+ grupo: string;
95
+ classe: string;
96
+ subclasse: string;
97
+ descricao: string;
98
+ };
99
+ pais: {
100
+ id: string;
101
+ iso2: string;
102
+ iso3: string;
103
+ nome: string;
104
+ comex_id: string;
105
+ };
106
+ estado: {
107
+ id: number;
108
+ nome: string;
109
+ sigla: string;
110
+ ibge_id: number;
111
+ };
112
+ cidade: {
113
+ id: number;
114
+ nome: string;
115
+ ibge_id: number;
116
+ siafi_id: string;
117
+ };
118
+ motivo_situacao_cadastral: string | null;
119
+ inscricoes_estaduais: Array<{
120
+ inscricao_estadual: string;
121
+ ativo: boolean;
122
+ atualizado_em: string;
123
+ estado: {
124
+ id: number;
125
+ nome: string;
126
+ sigla: string;
127
+ ibge_id: number;
128
+ };
129
+ }>;
130
+ };
131
+ };
132
+ export type CnpjLookupOptions = {
133
+ signal?: AbortSignal;
134
+ };
135
+ export declare function buscarCnpj(cnpj: string, options?: CnpjLookupOptions): Promise<PublicaCnpjResponse | null>;
136
+ //# sourceMappingURL=publica.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publica.d.ts","sourceRoot":"","sources":["../../src/cnpj/publica.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,mBAAmB,GAAG;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,E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B,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB,CAAC;AAMF,wBAAsB,UAAU,CAC9B,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,iBAAsB,GAC9B,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC,CAmBrC"}
@@ -0,0 +1,21 @@
1
+ function normalizeCnpj(value) {
2
+ return value.replace(/\D/g, "");
3
+ }
4
+ export async function buscarCnpj(cnpj, options = {}) {
5
+ const normalized = normalizeCnpj(cnpj);
6
+ if (normalized.length !== 14) {
7
+ throw new Error("CNPJ deve ter 14 dígitos.");
8
+ }
9
+ try {
10
+ const response = await fetch(`https://publica.cnpj.ws/cnpj/${normalized}`, {
11
+ signal: options.signal
12
+ });
13
+ if (!response.ok) {
14
+ return null;
15
+ }
16
+ return (await response.json());
17
+ }
18
+ catch {
19
+ return null;
20
+ }
21
+ }
@@ -0,0 +1,8 @@
1
+ export type HttpClientOptions = {
2
+ baseUrl: string;
3
+ getAccessToken?: () => string | null;
4
+ };
5
+ export declare function createHttpClient(opts: HttpClientOptions): {
6
+ request: <T>(path: string, init?: RequestInit) => Promise<T>;
7
+ };
8
+ //# sourceMappingURL=httpClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"httpClient.d.ts","sourceRoot":"","sources":["../../src/http/httpClient.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;CACtC,CAAC;AAEF,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,iBAAiB;cAC/B,CAAC,QAAQ,MAAM,SAAS,WAAW,KAAG,OAAO,CAAC,CAAC,CAAC;EAqBxE"}
@@ -0,0 +1,20 @@
1
+ export function createHttpClient(opts) {
2
+ async function request(path, init) {
3
+ const headers = new Headers(init?.headers);
4
+ if (!headers.has("Content-Type")) {
5
+ headers.set("Content-Type", "application/json");
6
+ }
7
+ const token = opts.getAccessToken?.();
8
+ if (token)
9
+ headers.set("Authorization", `Bearer ${token}`);
10
+ const res = await fetch(`${opts.baseUrl}${path}`, { ...init, headers });
11
+ if (!res.ok) {
12
+ const text = await res.text().catch(() => "");
13
+ throw new Error(`HTTP ${res.status} ${res.statusText}: ${text}`);
14
+ }
15
+ if (res.status === 204)
16
+ return undefined;
17
+ return (await res.json());
18
+ }
19
+ return { request };
20
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "commons.nav.dashboard": "Dashboard",
3
+ "commons.nav.login": "Entrar"
4
+ }
@@ -0,0 +1,4 @@
1
+ export * from "./http/httpClient";
2
+ export * from "./cep/viacep";
3
+ export * from "./cnpj/publica";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from "./http/httpClient";
2
+ export * from "./cep/viacep";
3
+ export * from "./cnpj/publica";
@@ -0,0 +1,3 @@
1
+ import type { SeedGridModuleManifest } from "@seedgrid/fe-core";
2
+ export declare const commonsManifest: SeedGridModuleManifest;
3
+ //# sourceMappingURL=manifest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../src/manifest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAoB,MAAM,mBAAmB,CAAC;AAGlF,eAAO,MAAM,eAAe,EAAE,sBA+B7B,CAAC"}
@@ -0,0 +1,32 @@
1
+ import ptBr from "./i18n/pt-BR.json";
2
+ export const commonsManifest = {
3
+ id: "seedgrid-fe-commons",
4
+ name: "SeedGrid FE Commons",
5
+ version: "0.2.0",
6
+ i18n: {
7
+ defaultLocale: "pt-BR",
8
+ bundles: [
9
+ {
10
+ namespace: "commons",
11
+ resources: ptBr,
12
+ distPath: "dist/i18n/pt-BR.json"
13
+ }
14
+ ]
15
+ },
16
+ register(registry) {
17
+ registry.addNavItem({
18
+ id: "login",
19
+ labelKey: "commons.nav.login",
20
+ href: "/login",
21
+ requiresAuth: false,
22
+ order: 1
23
+ });
24
+ registry.addNavItem({
25
+ id: "dashboard",
26
+ labelKey: "commons.nav.dashboard",
27
+ href: "/dashboard",
28
+ requiresAuth: true,
29
+ order: 10
30
+ });
31
+ }
32
+ };
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@seedgrid/fe-commons",
3
+ "version": "0.2.0",
4
+ "type": "module",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "default": "./dist/index.js"
11
+ }
12
+ },
13
+ "files": ["dist"],
14
+ "scripts": {
15
+ "build": "tsc -p tsconfig.json",
16
+ "typecheck": "tsc -p tsconfig.json --noEmit"
17
+ },
18
+ "dependencies": {
19
+ "@seedgrid/fe-core": "workspace:*"
20
+ },
21
+ "peerDependencies": {
22
+ "react": "^18.2.0 || ^19.0.0"
23
+ },
24
+ "devDependencies": {
25
+ "fs-extra": "^11.2.0"
26
+ }
27
+ }