@greatapps/greatagents 0.1.20 → 0.1.22

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/CLAUDE.md ADDED
@@ -0,0 +1,97 @@
1
+ # gagents-schemas — Agente de Schemas
2
+
3
+ Pacote NPM `@greatapps/greatagents`: definições de schema compartilhadas por todos os serviços.
4
+
5
+ ## Comandos
6
+
7
+ ```bash
8
+ # Após alterar schemas, atualizar version e publicar:
9
+ npm version patch # ou minor/major
10
+ npm publish # Publica no registry
11
+ ```
12
+
13
+ **IMPORTANTE**: Após publicar, atualizar a versão em `gagents-r1-api-postgresql/package.json` e `gagents-r3-api/package.json`, rodar `npm install` em ambos, e fazer deploy.
14
+
15
+ ## Estrutura
16
+
17
+ ```
18
+ src/
19
+ ├── product.js # Export principal (importado como @greatapps/greatagents)
20
+ ├── shared/
21
+ │ ├── parameters.js # Params de rota (language, id_wl, id_account)
22
+ │ └── responses.js # Respostas HTTP padrão (400, 401, 403, 404, 500)
23
+ └── modules/
24
+ ├── accounts/ # params: [] (global)
25
+ ├── users/ # params: ["id_account"]
26
+ ├── agents/ # params: ["id_account"]
27
+ ├── objectives/ # params: ["id_account", "id_agent"]
28
+ ├── contacts/ # params: ["id_account"]
29
+ ├── conversations/ # params: ["id_account"]
30
+ ├── prompt_versions/ # params: ["id_account", "id_agent"]
31
+ ├── tools/ # params: ["id_account"]
32
+ ├── agent_tools/ # params: ["id_account", "id_agent"]
33
+ ├── tool_credentials/ # params: ["id_account"]
34
+ └── contact_users/ # params: ["id_account"]
35
+ ```
36
+
37
+ Cada módulo tem `index.js` (definição) e `properties.js` (propriedades/colunas).
38
+
39
+ ## Padrão de Módulo
40
+
41
+ ```javascript
42
+ // modules/agents/index.js
43
+ export default {
44
+ product: "greatagents",
45
+ name: "agents", // Nome da tabela no banco
46
+ cache: { ttlView: 30, ttlList: 0 },
47
+ params: ["id_account"], // Params obrigatórios em WHERE (multi-tenancy)
48
+ properties: properties,
49
+ routes: {}
50
+ };
51
+ ```
52
+
53
+ ## Padrão de Propriedade
54
+
55
+ ```javascript
56
+ // modules/agents/properties.js
57
+ title: {
58
+ type: "string", // string | number | boolean | date | image
59
+ required: true, // Obrigatório em INSERT
60
+ filterable: true, // Pode ser usado em WHERE
61
+ searchable: true, // Full-text search
62
+ updatable: true, // Pode ser modificado (false = imutável)
63
+ unique: false, // Constraint unique no banco
64
+ validation: { maxLength: 255 },
65
+ interface: { // Metadata para UI
66
+ label: { "pt-br": "Título", "en": "Title" },
67
+ component: "string",
68
+ placeholder: { "pt-br": "..." }
69
+ },
70
+ reference: { // FK para outro módulo
71
+ module: "accounts",
72
+ label: "name",
73
+ value: "id"
74
+ }
75
+ }
76
+ ```
77
+
78
+ ### Propriedades de sistema (presentes em todos os módulos)
79
+ - `id` — autoIncrement, unique, index
80
+ - `deleted` — boolean (schema), **INTEGER no banco** (ver regra abaixo)
81
+ - `datetime_add` — date, updatable: false
82
+ - `datetime_alt` — date, updatable: true
83
+ - `datetime_del` — date
84
+
85
+ ## `params` Array — Multi-Tenancy
86
+
87
+ O array `params` define quais campos são obrigatórios em WHERE clauses:
88
+ - `params: ["id_account"]` → buildWhere.js exige `id_account` em toda query
89
+ - `params: ["id_account", "id_agent"]` → exige ambos (hierárquico)
90
+ - `params: []` → sem restrição (ex: accounts)
91
+
92
+ ## Regras Críticas
93
+
94
+ - **Coluna `deleted`**: Schema define como `boolean`, mas no PostgreSQL DEVE ser INTEGER (buildWhere.js appends `AND deleted = 0`)
95
+ - **`contacts.identifier`**: Tem constraint UNIQUE global, não per-account
96
+ - **Versionamento**: Sempre bumpar version antes de publicar — consumers usam versão fixa
97
+ - **Impacto cross-service**: Mudanças em schemas afetam gagents-r1-api-postgresql (validação, queries) e gagents-r3-api (serviços, lógica)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@greatapps/greatagents",
3
- "version": "0.1.20",
3
+ "version": "0.1.22",
4
4
  "description": "Schemas para GreatAgents",
5
5
  "main": "./src/product.js",
6
6
  "type": "module"
7
- }
7
+ }
@@ -2,10 +2,9 @@ import { properties } from "./properties.js";
2
2
 
3
3
  export default {
4
4
  product: "greatagents",
5
- name: "users",
6
- cache: { ttlView: 3600, ttlList: 0 },
7
- summary: "Armazena informações de usuários do sistema",
5
+ name: "contact_users",
6
+ cache: { ttlView: 30, ttlList: 0 },
8
7
  params: [ "id_account" ],
9
8
  properties: properties,
10
9
  routes: {}
11
- };
10
+ };
@@ -0,0 +1,119 @@
1
+ export const properties = {
2
+ id: {
3
+ type: "number",
4
+ filterable: true,
5
+ unique: true,
6
+ autoIncrement: true,
7
+ index: true
8
+ },
9
+ deleted: {
10
+ type: "boolean",
11
+ default: false,
12
+ filterable: true
13
+ },
14
+ datetime_add: {
15
+ type: "date",
16
+ filterable: true,
17
+ updatable: false
18
+ },
19
+ datetime_alt: {
20
+ type: "date",
21
+ filterable: true,
22
+ updatable: true
23
+ },
24
+ datetime_del: {
25
+ type: "date",
26
+ filterable: true
27
+ },
28
+ id_account: {
29
+ type: "number",
30
+ required: true,
31
+ updatable: false,
32
+ filterable: true,
33
+ reference: {
34
+ module: "accounts",
35
+ label: "name",
36
+ value: "id",
37
+ disabled: true
38
+ },
39
+ interface: {
40
+ label: {
41
+ "pt-br": "Conta",
42
+ "en": "Account"
43
+ },
44
+ component: "select",
45
+ disabled: true
46
+ }
47
+ },
48
+ contact_identifier: {
49
+ type: "string",
50
+ required: true,
51
+ filterable: true,
52
+ index: true,
53
+ validation: {
54
+ maxLength: 255
55
+ },
56
+ interface: {
57
+ label: {
58
+ "pt-br": "Identificador do Contato",
59
+ "en": "Contact Identifier"
60
+ },
61
+ component: "input",
62
+ placeholder: {
63
+ "pt-br": "Identificador normalizado do contato (telefone, email, username)",
64
+ "en": "Normalized contact identifier (phone, email, username)"
65
+ }
66
+ }
67
+ },
68
+ id_user: {
69
+ type: "number",
70
+ required: true,
71
+ filterable: true,
72
+ index: true,
73
+ reference: {
74
+ module: "users",
75
+ label: "name",
76
+ value: "id"
77
+ },
78
+ interface: {
79
+ label: {
80
+ "pt-br": "Usuário",
81
+ "en": "User"
82
+ },
83
+ component: "select"
84
+ }
85
+ },
86
+ target_account_id: {
87
+ type: "number",
88
+ required: true,
89
+ filterable: true,
90
+ index: true,
91
+ reference: {
92
+ module: "accounts",
93
+ label: "name",
94
+ value: "id"
95
+ },
96
+ interface: {
97
+ label: {
98
+ "pt-br": "Conta Alvo",
99
+ "en": "Target Account"
100
+ },
101
+ component: "select"
102
+ }
103
+ },
104
+ role: {
105
+ type: "string",
106
+ default: "admin",
107
+ filterable: true,
108
+ validation: {
109
+ maxLength: 50
110
+ },
111
+ interface: {
112
+ label: {
113
+ "pt-br": "Papel",
114
+ "en": "Role"
115
+ },
116
+ component: "select"
117
+ }
118
+ }
119
+ };
package/src/product.js CHANGED
@@ -1,7 +1,5 @@
1
1
  /* Modules */
2
2
 
3
- import accounts from './modules/accounts/index.js';
4
- import users from './modules/users/index.js';
5
3
  import agents from './modules/agents/index.js';
6
4
  import objectives from './modules/objectives/index.js';
7
5
  import contacts from './modules/contacts/index.js';
@@ -10,6 +8,7 @@ import prompt_versions from './modules/prompt_versions/index.js';
10
8
  import tools from './modules/tools/index.js';
11
9
  import agent_tools from './modules/agent_tools/index.js';
12
10
  import tool_credentials from './modules/tool_credentials/index.js';
11
+ import contact_users from './modules/contact_users/index.js';
13
12
 
14
13
  /* Shared */
15
14
 
@@ -34,8 +33,6 @@ export default {
34
33
  },
35
34
  },
36
35
  modules: {
37
- accounts,
38
- users,
39
36
  agents,
40
37
  objectives,
41
38
  contacts,
@@ -43,7 +40,8 @@ export default {
43
40
  prompt_versions,
44
41
  tools,
45
42
  agent_tools,
46
- tool_credentials
43
+ tool_credentials,
44
+ contact_users
47
45
  },
48
46
  documentation: {
49
47
  title: "GreatAgents API",
@@ -1,11 +0,0 @@
1
- import { properties } from "./properties.js";
2
-
3
- export default {
4
- product: "gagents",
5
- name: "accounts",
6
- cache: { ttlView: 3600, ttlList: 0 },
7
- summary: "Armazena informações de contas de usuários e suas configurações",
8
- params: [],
9
- properties: properties,
10
- routes: {}
11
- };
@@ -1,46 +0,0 @@
1
- export const properties = {
2
- id: {
3
- type: "number",
4
- filterable: true,
5
- unique: true,
6
- autoIncrement: true,
7
- index: true
8
- },
9
- name: {
10
- type: "string",
11
- searchable: true,
12
- maxLength: 100,
13
- interface: {
14
- label: {
15
- "pt-br": "Nome",
16
- en: "Name"
17
- },
18
- description: {
19
- "pt-br": "Informe seu nome",
20
- en: "Enter your name"
21
- },
22
- placeholder: {
23
- "pt-br": "Nome",
24
- en: "Name"
25
- },
26
- component: "input"
27
- }
28
- },
29
- deleted: {
30
- type: "boolean",
31
- default: false
32
- },
33
- datetime_alt: {
34
- type: "date",
35
- filterable: true,
36
- updatable: false
37
- },
38
- datetime_del: {
39
- type: "date",
40
- filterable: true
41
- },
42
- datetime_add: {
43
- type: "date",
44
- filterable: true
45
- }
46
- };
@@ -1,156 +0,0 @@
1
- export const properties = {
2
- id: {
3
- type: "number",
4
- filterable: true,
5
- unique: true,
6
- autoIncrement: true,
7
- index: true
8
- },
9
- id_account: {
10
- type: "number",
11
- required: true,
12
- updatable: false,
13
- filterable: true,
14
- reference: {
15
- module: "accounts",
16
- label: "name",
17
- value: "id",
18
- disabled: true
19
- },
20
- interface: {
21
- label: {
22
- "pt-br": "Conta",
23
- en: "Account"
24
- },
25
- component: "select",
26
- disabled: true
27
- }
28
- },
29
- name: {
30
- type: "string",
31
- searchable: true,
32
- maxLength: 50,
33
- interface: {
34
- label: {
35
- "pt-br": "Nome",
36
- "en": "Name"
37
- },
38
- component: "input"
39
- }
40
- },
41
- last_name: {
42
- type: "string",
43
- searchable: true,
44
- interface: {
45
- label: {
46
- "pt-br": "Sobrenome",
47
- en: "Lastname"
48
- },
49
- component: "input"
50
- }
51
- },
52
- email: {
53
- type: "string",
54
- required: true,
55
- searchable: true,
56
- filterable: true,
57
- interface: {
58
- label: {
59
- "pt-br": "E-mail",
60
- en: "E-mail"
61
- },
62
- component: "input",
63
- format: "email"
64
- }
65
- },
66
- profile: {
67
- type: "string",
68
- default: "collaborator",
69
- options: [
70
- {
71
- value: "viewer",
72
- icon: "",
73
- title: {
74
- "pt-br": "Visualizador",
75
- en: "Viewer"
76
- },
77
- description: "",
78
- style: ""
79
- },
80
- {
81
- value: "collaborator",
82
- icon: "",
83
- title: {
84
- "pt-br": "Colaborador",
85
- en: "Collaborator"
86
- },
87
- description: "",
88
- style: ""
89
- },
90
- {
91
- value: "admin",
92
- icon: "",
93
- title: {
94
- "pt-br": "Administrador",
95
- en: "Admin"
96
- }
97
- },
98
- {
99
- value: "owner",
100
- icon: "",
101
- title: {
102
- "pt-br": "Proprietário",
103
- en: "Owner"
104
- }
105
- },
106
- {
107
- value: "attendant",
108
- icon: "",
109
- title: {
110
- "pt-br": "Atendente",
111
- en: "Attendant"
112
- }
113
- }
114
- ],
115
- interface: {
116
- label: {
117
- "pt-br": "Perfil de acesso",
118
- en: "Profile"
119
- },
120
- component: "select"
121
- }
122
- },
123
- photo: {
124
- type: "image",
125
- interface: {
126
- label: {
127
- "pt-br": "Foto",
128
- en: "Photo"
129
- },
130
- component: "image"
131
- },
132
- file: {
133
- types: ["png", "jpg", "jpeg", "gif", "svg", "webp"],
134
- storage: "gapps-r1-storage",
135
- width: 160,
136
- height: 160
137
- }
138
- },
139
- deleted: {
140
- type: "boolean",
141
- default: false
142
- },
143
- datetime_alt: {
144
- type: "date",
145
- filterable: true,
146
- updatable: false
147
- },
148
- datetime_del: {
149
- type: "date",
150
- filterable: true
151
- },
152
- datetime_add: {
153
- type: "date",
154
- filterable: true
155
- }
156
- };