funifier-mcp 0.3.19 → 0.3.20

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "funifier-mcp",
3
- "version": "0.3.19",
3
+ "version": "0.3.20",
4
4
  "description": "Funifier AI toolkit — MCP server, API client, and Claude Code skills for the Funifier gamification platform",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -65,19 +65,39 @@ If search returns insufficient results, read these directly:
65
65
 
66
66
  ## Steps
67
67
 
68
- ## ⚠ Regra crítica: triggers não impedem persistência via throw
68
+ ## ⚠ Regra crítica: quando `throw` interrompe a operação
69
69
 
70
- O Funifier **sempre salva o documento** antes de executar o trigger.
70
+ **dois modos**, e qual vale depende de onde a trigger roda:
71
71
 
72
- - `before_create` enriquecimento apenas (normalizar, preencher defaults)
73
- - Rejeitar criação usar `after_create`: validar se inválido:
72
+ - **Modo A — estrito (`throw` aborta):** SÓ em `before_create`/`before_update`/`before_delete` de **coleções de banco** via Database API (`POST`/`PUT`/`DELETE /v3/database/{collection}`). O `DatabaseRest` roda via `TriggerManager.executeStrict`: qualquer exceção aborta a operação — o documento não é gravado/removido e a API responde **HTTP 500** `{ "message": "<msg>", "statusCode": 500 }`. ⚠️ **Recurso version-dependent** — nem toda instância recebeu a atualização. **Sonde antes de depender** (ver bloco de detecção abaixo) ou use o Modo B.
73
+ - **Modo B persistência garantida (`throw` NÃO cancela):** todo o resto (player, action, swap, quiz, achievement pelos managers, eventos `after_*`, `*_bulk`/`csv_*`). O documento é salvo antes do trigger rodar. Rejeitar = `after_create`:
74
74
  ```java
75
- database.delete(entity._id, "collection__c");
75
+ database.delete(entity.id, "collection__c");
76
76
  entity.clear();
77
77
  entity.put("message", "motivo");
78
78
  return;
79
79
  ```
80
- - Para lógica complexa, use `BusinessException` interna (capturada dentro do trigger, não propaga para a plataforma).
80
+ Para lógica complexa, use `BusinessException` interna (capturada dentro do trigger).
81
+
82
+ **Regra de ouro:** se o suporte ao Modo A não for confirmado, **gere código no Modo B** e diga ao usuário que o Modo A exige instância atualizada. Detalhes e exemplos: `funifier_read_doc path=guides/triggers-guide` §8.
83
+
84
+ ## 🔎 Detectar suporte ao Modo A (sonda)
85
+
86
+ Antes de entregar uma trigger que aborta via `throw`, confirme na instância conectada:
87
+
88
+ ```
89
+ # 1. cria trigger-sonda que sempre lança exceção
90
+ funifier_save type=trigger payload={"name":"__probe_strict_mode__","entity":"probe_strict__c","event":"before_create","active":true,"script":"void trigger(event, entity, player, database){ throw new RuntimeException(\"__STRICT_PROBE_BLOCKED__\"); }"}
91
+ # 2. tenta inserir (passa por DatabaseRest.insert → executeStrict)
92
+ funifier_database action=insert collection=probe_strict__c payload={"probe":true}
93
+ # → erro 500 com "__STRICT_PROBE_BLOCKED__" = Modo A SUPORTADO
94
+ # → insert bem-sucedido = Modo A NÃO suportado (use Modo B)
95
+ # 3. limpeza (sempre)
96
+ funifier_database action=delete collection=probe_strict__c filter={"probe":true}
97
+ funifier_delete type=trigger id=<_id da sonda>
98
+ ```
99
+
100
+ Sem permissão de escrita / produção sensível → **assuma o Modo B** e avise o usuário.
81
101
 
82
102
  ---
83
103
 
@@ -129,8 +149,8 @@ Perguntar (ou inferir do contexto):
129
149
  | `achievement` | `before_create` | Enriquecer conquista com dados de origem (`context.extra`) |
130
150
  | `player` | `after_create` | Inicializar campos customizados ao criar jogador |
131
151
  | `player` | `before_update` | Normalizar campos antes de salvar atualização |
132
- | `custom__c` | `before_create` | Normalizar/enriquecer documento customizado |
133
- | `custom__c` | `after_create` | Validar e rejeitar se inválido (delete + message) |
152
+ | `custom__c` | `before_create` | Normalizar/enriquecer documento; **rejeitar via `throw` no Modo A** (instância atualizada — sondar antes) |
153
+ | `custom__c` | `after_create` | Validar e rejeitar se inválido (delete + message) — **portável, qualquer instância** |
134
154
  | `custom__c` | `after_bulk` | Processar import em lote (entity é uma List) |
135
155
 
136
156
  ### 2. Verificar se já existe
@@ -183,11 +203,3 @@ funifier_logs type=trigger id=<_id>
183
203
  ```
184
204
 
185
205
  Confirme que não há erros de compilação ou execução. Se houver, leia o stack trace e corrija o script.
186
-
187
- ## Verified References
188
-
189
- | Claim | Status | Evidence |
190
- |-------|--------|----------|
191
- | Achievement constants TYPE_POINT=0, TYPE_CHALLENGE=1, TYPE_VIRTUAL_GOOD=2, TYPE_LEVEL=3 are defined in the Achievement class | ✓ verified | Class:src/main/java/com/funifier/engine/achievement/Achievement.java:Achievement |
192
- | ActionLog is the entity class for action triggers with fields actionId, userId, attributes (Map), time, and id | ✓ verified | Class:src/main/java/com/funifier/engine/action/ActionLog.java:ActionLog |
193
- | TriggerManager is the class that manages trigger script execution and lifecycle in funifier-service | ✓ verified | Class:src/main/java/com/funifier/engine/integration/trigger/TriggerManager.java:TriggerManager |
@@ -90,9 +90,3 @@ Leia o arquivo de doc específico para o módulo com problema:
90
90
  - Scheduler → `funifier_read_doc path=modules/scheduler`
91
91
  - Aggregate → `funifier_read_doc path=guides/aggregates`
92
92
  - Security/Auth → `funifier_read_doc path=modules/security`
93
-
94
- ## Verified References
95
-
96
- | Claim | Status | Evidence |
97
- |-------|--------|----------|
98
- | TriggerManager is the entry point for trigger script execution and error capture in funifier-service | ✓ verified | Class:src/main/java/com/funifier/engine/integration/trigger/TriggerManager.java:TriggerManager |