@oliveiratco1/n8n-nodes-grid402 1.0.0 → 1.0.2

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.
@@ -60,6 +60,18 @@ class Grid402Api {
60
60
  },
61
61
  },
62
62
  },
63
+ {
64
+ displayName: 'RapidAPI Host',
65
+ name: 'rapidApiHost',
66
+ type: 'string',
67
+ default: 'grid402-open-data-kyb-ai-utilities.p.rapidapi.com',
68
+ description: 'Host proxy da API assinada no RapidAPI Hub (ex.: grid402-open-data-kyb-ai-utilities.p.rapidapi.com)',
69
+ displayOptions: {
70
+ show: {
71
+ authMode: ['rapidApi'],
72
+ },
73
+ },
74
+ },
63
75
  {
64
76
  displayName: 'Endpoint Base',
65
77
  name: 'baseUrl',
@@ -31,11 +31,11 @@ class Grid402 {
31
31
  default: 'dossier',
32
32
  options: [
33
33
  { name: 'Dossiê 360º KYB Brasil + Veredito IA (10 cr)', value: 'dossier', description: 'Receita Federal CNPJ + Simples/MEI + Sanções CGU CEIS/CNEP + Score 0-100 e Veredito IA (APPROVED/FLAGGED/REJECTED)' },
34
- { name: 'Consultar CNPJ Receita Federal (4 cr)', value: 'cnpj', description: 'Dados cadastrais públicos de Pessoa Jurídica (Zero-PII: sem QSA/CPF)' },
34
+ { name: 'Consultar CNPJ Receita Federal (2 cr)', value: 'cnpj', description: 'Dados cadastrais públicos de Pessoa Jurídica (Zero-PII: sem QSA/CPF)' },
35
35
  { name: 'Simples Nacional e MEI por CNPJ (2 cr)', value: 'simples', description: 'Verifica opção pelo Simples Nacional e enquadramento SIMEI (MEI)' },
36
36
  { name: 'Sanções CGU CEIS e CNEP por CNPJ (2 cr)', value: 'sanctions', description: 'Consulta Cadastro de Empresas Inidôneas e Suspensas (CEIS) e Punidas (CNEP)' },
37
37
  { name: 'Compliance Score 360 por CNPJ (6 cr)', value: 'compliance', description: 'Score de integridade corporativa 0-100 cruzando Receita Federal e CGU' },
38
- { name: 'Auditoria KYB Global: CNPJ + OFAC + LEI (4 cr)', value: 'kyb-audit', description: 'Receita Federal CNPJ + Sanções OFAC/ONU + Identidade Global GLEIF LEI' },
38
+ { name: 'Auditoria KYB Global: CNPJ + OFAC + LEI (5 cr)', value: 'kyb-audit', description: 'Receita Federal CNPJ + Sanções OFAC/ONU + Identidade Global GLEIF LEI' },
39
39
  { name: 'Verificar E-mail Corporativo B2B Zero-PII (1 cr)', value: 'email-verify', description: 'Valida sintaxe RFC, DNS MX, SPF, DMARC, domínio descartável e score 0-100 sem reter PII' },
40
40
  { name: 'Extrair Site para Markdown Limpo / RAG (1 cr)', value: 'extract', description: 'Converte URL pública HTTP/HTTPS em Markdown limpo para LLMs com proteção anti-SSRF' },
41
41
  { name: 'Consultar CEP Brasileiro + Código IBGE (1 cr)', value: 'cep', description: 'Logradouro, bairro, município, UF e código oficial IBGE' },
@@ -50,7 +50,7 @@ class Grid402 {
50
50
  { name: 'Inspeção de Certificado TLS/SSL (1 cr)', value: 'ssl', description: 'Emissor, validade, SANs e dias restantes até expirar na porta 443' },
51
51
  { name: 'Inteligência BGP e ASN de IP (1 cr)', value: 'asn', description: 'Número ASN, bloco CIDR, organização e país de origem' },
52
52
  { name: 'Auditoria Completa de Domínio: DNS + SSL + ASN (3 cr)', value: 'domain-audit', description: 'Auditoria técnica consolidada de domínio em 1 chamada' },
53
- { name: 'Identidade Corporativa Global GLEIF LEI (4 cr)', value: 'lei', description: 'Consulta código ISO 17442 LEI em 200+ jurisdições (CC0 1.0)' },
53
+ { name: 'Identidade Corporativa Global GLEIF LEI (2 cr)', value: 'lei', description: 'Consulta código ISO 17442 LEI em 200+ jurisdições (CC0 1.0)' },
54
54
  { name: 'Triagem Global OFAC SDN / ONU e AML Web3 (4 cr)', value: 'ofac', description: 'Triagem de sanções internacionais para carteiras 0x ou entidades' },
55
55
  { name: 'Notarização Criptográfica SHA-256 + ECDSA (1 cr)', value: 'notarize', description: 'Carimbo do tempo M2M e prova de existência Zero-Retention' },
56
56
  { name: 'Consultar Saldo do Session Pass (Gratuito)', value: 'pass-balance', description: 'Verifica créditos restantes, validade e Spend Controls do seu pass_g402_...' },
@@ -263,7 +263,13 @@ class Grid402 {
263
263
  }
264
264
 
265
265
  const baseUrl = String(creds.baseUrl || 'https://grid402.online').replace(/\/$/, '');
266
- const authMode = creds.authMode || (creds.sessionPass ? 'sessionPass' : 'sandbox');
266
+ const defaultRapidApiHost = 'grid402-open-data-kyb-ai-utilities.p.rapidapi.com';
267
+ const rapidApiHost = String(creds.rapidApiHost || defaultRapidApiHost)
268
+ .replace(/^https?:\/\//i, '')
269
+ .replace(/\/.*$/, '')
270
+ .trim() || defaultRapidApiHost;
271
+ const authMode = creds.authMode || '';
272
+ const canContinueOnFail = () => Boolean(typeof this.continueOnFail === 'function' && this.continueOnFail());
267
273
 
268
274
  for (let i = 0; i < items.length; i++) {
269
275
  const getParam = (name, fallback = '') => {
@@ -278,6 +284,7 @@ class Grid402 {
278
284
  };
279
285
 
280
286
  const operation = getParam('operation', 'dossier');
287
+ const isFreeOperation = operation === 'summary' || operation === 'pass-balance';
281
288
  const qs = new URLSearchParams();
282
289
  let path = `/api/v1/${operation}`;
283
290
 
@@ -327,22 +334,62 @@ class Grid402 {
327
334
  qs.set('market', String(getParam('market', 'US')).trim());
328
335
  }
329
336
 
330
- const queryString = qs.toString();
331
- const fullUrl = `${baseUrl}${path}${queryString ? '?' + queryString : ''}`;
332
-
333
337
  const headers = {
334
338
  'Accept': 'application/json',
335
- 'User-Agent': 'n8n-nodes-grid402/1.0.0',
339
+ 'User-Agent': 'n8n-nodes-grid402/1.1.0',
336
340
  };
337
341
 
338
- if (authMode === 'sessionPass' && creds.sessionPass) {
339
- headers['X-Payment'] = String(creds.sessionPass).trim();
340
- } else if (authMode === 'rapidApi' && creds.rapidApiKey) {
341
- headers['X-RapidAPI-Key'] = String(creds.rapidApiKey).trim();
342
- } else {
343
- headers['X-Payment'] = 'demo';
342
+ let effectiveBaseUrl = baseUrl;
343
+
344
+ if (!isFreeOperation) {
345
+ if (authMode === 'sessionPass') {
346
+ const token = String(creds.sessionPass || '').trim();
347
+ if (!token) {
348
+ const errMsg = 'Credencial Grid402 incompleta: modo Session Pass selecionado, mas o token pass_g402_... está vazio. Adquira via Pix/Cartão em https://grid402.online/pass?tier=starter&autopix=1 ou selecione explicitamente o modo Sandbox.';
349
+ if (canContinueOnFail()) {
350
+ returnData.push({ json: { error: 'MissingSessionPass', message: errMsg }, pairedItem: { item: i } });
351
+ continue;
352
+ }
353
+ throw new Error(errMsg);
354
+ }
355
+ headers['X-Payment'] = token;
356
+ } else if (authMode === 'rapidApi') {
357
+ const key = String(creds.rapidApiKey || '').trim();
358
+ if (!key) {
359
+ const errMsg = 'Credencial Grid402 incompleta: modo RapidAPI selecionado, mas a X-RapidAPI-Key está vazia. Informe sua chave RapidAPI Hub ou troque o modo de autenticação.';
360
+ if (canContinueOnFail()) {
361
+ returnData.push({ json: { error: 'MissingRapidApiKey', message: errMsg }, pairedItem: { item: i } });
362
+ continue;
363
+ }
364
+ throw new Error(errMsg);
365
+ }
366
+ let hostHeader = rapidApiHost;
367
+ if (baseUrl.includes('.p.rapidapi.com')) {
368
+ try {
369
+ hostHeader = new URL(baseUrl).host;
370
+ } catch (_) {
371
+ hostHeader = rapidApiHost;
372
+ }
373
+ } else {
374
+ effectiveBaseUrl = `https://${rapidApiHost}`;
375
+ }
376
+ headers['X-RapidAPI-Key'] = key;
377
+ headers['X-RapidAPI-Host'] = hostHeader;
378
+ } else if (authMode === 'sandbox') {
379
+ headers['X-Payment'] = 'demo';
380
+ } else {
381
+ const errMsg = 'Credencial Grid402 não configurada para operação paga. Configure Grid402 API com Session Pass (https://grid402.online/pass), RapidAPI Hub ou selecione explicitamente o modo Sandbox (3 req/dia).';
382
+ if (canContinueOnFail()) {
383
+ returnData.push({ json: { error: 'MissingCredentials', message: errMsg }, pairedItem: { item: i } });
384
+ continue;
385
+ }
386
+ throw new Error(errMsg);
387
+ }
344
388
  }
345
389
 
390
+ const queryString = qs.toString();
391
+ const fullUrl = `${effectiveBaseUrl}${path}${queryString ? '?' + queryString : ''}`;
392
+
346
393
  const response = await fetch(fullUrl, { method: 'GET', headers });
347
394
  const data = await response.json().catch(() => ({ status: response.status }));
348
395
 
@@ -352,9 +399,25 @@ class Grid402 {
352
399
  rapidapi_card_usd: 'https://rapidapi.com/oliveiratc/api/grid402-open-data-kyb-ai-utilities',
353
400
  how_to_configure: 'Copie seu token pass_g402_... após pagar o Pix e cole na credencial Grid402 API do n8n.',
354
401
  };
402
+ const statusLabel = response.status === 402 ? 'HTTP 402 Payment Required' : 'HTTP 429 Rate Limit Exceeded';
403
+ const actionableMsg = `[Grid402 ${statusLabel}] ${data.message || data.reason || data.error || 'Créditos ou assinatura necessários.'} — Adquira Session Pass via Pix/Cartão em https://grid402.online/pass?tier=starter&autopix=1 ou assine no RapidAPI Hub.`;
404
+ if (canContinueOnFail()) {
405
+ returnData.push({ json: { ...data, http_status: response.status, error_message: actionableMsg }, pairedItem: { item: i } });
406
+ continue;
407
+ }
408
+ throw new Error(actionableMsg);
409
+ }
410
+
411
+ if (response.status >= 400) {
412
+ const errMsg = `[Grid402 HTTP ${response.status}] ${data.message || data.error || 'Falha na requisição'}`;
413
+ if (canContinueOnFail()) {
414
+ returnData.push({ json: { ...data, http_status: response.status, error_message: errMsg }, pairedItem: { item: i } });
415
+ continue;
416
+ }
417
+ throw new Error(errMsg);
355
418
  }
356
419
 
357
- returnData.push({ json: data });
420
+ returnData.push({ json: data, pairedItem: { item: i } });
358
421
  }
359
422
 
360
423
  return [returnData];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oliveiratco1/n8n-nodes-grid402",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },