cdp-edge 2.6.0 → 2.6.1

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": "cdp-edge",
3
- "version": "2.6.0",
3
+ "version": "2.6.1",
4
4
  "description": "CDP Edge - Quantum Tracking - Sistema multi-agente para tracking digital Cloudflare Native (Workers + D1)",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -12,3 +12,8 @@ SITE_DOMAIN=seudominio.com.br
12
12
  META_PIXEL_ID=
13
13
  GA4_MEASUREMENT_ID=
14
14
  TIKTOK_PIXEL_ID=
15
+
16
+ # ZapMan SDR (opcional)
17
+ ZAPMAN_API_URL=
18
+ ZAPMAN_CRM_INSTANCE=
19
+ ZAPMAN_WEBHOOK_URL=
@@ -1,39 +1,39 @@
1
1
  #!/usr/bin/env node
2
2
  /**
3
- * CDP Edge deploy-client.js
3
+ * CDP Edge - deploy-client.js
4
4
  *
5
- * Deploy do Worker com variáveis reais do cliente, sem commitar credenciais no repo.
6
- * de .client.env (gitignored) e gera um wrangler.deploy.toml temporário.
5
+ * Deploy the Worker with client-specific values without committing credentials.
6
+ * Reads .client.env (gitignored) and writes a temporary wrangler.deploy.toml.
7
7
  *
8
- * Uso:
9
- * node deploy-client.js deploy completo
10
- * node deploy-client.js --dry-run valida sem subir ao Cloudflare
8
+ * Usage:
9
+ * node deploy-client.cjs -> full deploy
10
+ * node deploy-client.cjs --dry-run -> validate without deploying
11
11
  *
12
12
  * Setup:
13
13
  * cp .client.env.example .client.env
14
- * # edite .client.env com os valores do cliente
15
- * node deploy-client.js
14
+ * # edit .client.env with the client values
15
+ * node deploy-client.cjs --dry-run
16
16
  */
17
17
 
18
- const fs = require('fs');
18
+ const fs = require('fs');
19
19
  const path = require('path');
20
20
  const { execSync } = require('child_process');
21
21
 
22
- const ROOT = __dirname;
23
- const TOML = path.join(ROOT, 'wrangler.toml');
24
- const DEPLOY = path.join(ROOT, 'wrangler.deploy.toml');
25
- const ENV = path.join(ROOT, '.client.env');
22
+ const ROOT = __dirname;
23
+ const TOML = path.join(ROOT, 'wrangler.toml');
24
+ const DEPLOY = path.join(ROOT, 'wrangler.deploy.toml');
25
+ const ENV = path.join(ROOT, '.client.env');
26
26
  const DRY_RUN = process.argv.includes('--dry-run');
27
27
 
28
- // ── Carregar .client.env ──────────────────────────────────────────────────────
29
28
  if (!fs.existsSync(ENV)) {
30
- console.error('\n❌ .client.env não encontrado.');
31
- console.error(' cp .client.env.example .client.env e preencha os valores do cliente.\n');
29
+ console.error('\nERROR: .client.env not found.');
30
+ console.error('Run: cp .client.env.example .client.env');
31
+ console.error('Then fill in the client values.\n');
32
32
  process.exit(1);
33
33
  }
34
34
 
35
35
  const env = {};
36
- fs.readFileSync(ENV, 'utf8').split('\n').forEach(line => {
36
+ fs.readFileSync(ENV, 'utf8').split('\n').forEach((line) => {
37
37
  const trimmed = line.trim();
38
38
  if (!trimmed || trimmed.startsWith('#')) return;
39
39
  const [key, ...rest] = trimmed.split('=');
@@ -41,36 +41,52 @@ fs.readFileSync(ENV, 'utf8').split('\n').forEach(line => {
41
41
  });
42
42
 
43
43
  const required = ['DATABASE_ID', 'SITE_DOMAIN'];
44
- const missing = required.filter(k => !env[k]);
44
+ const missing = required.filter((key) => !env[key]);
45
45
  if (missing.length > 0) {
46
- console.error(`\n❌ Variáveis obrigatórias faltando no .client.env: ${missing.join(', ')}\n`);
46
+ console.error(`\nERROR: missing required .client.env values: ${missing.join(', ')}\n`);
47
47
  process.exit(1);
48
48
  }
49
49
 
50
- // ── Substituir placeholders no wrangler.toml → wrangler.deploy.toml ───────────
50
+ const invalid = [];
51
+ if (env.DATABASE_ID === 'SEU_DATABASE_ID') invalid.push('DATABASE_ID');
52
+ if (env.SITE_DOMAIN === 'SEU_DOMINIO' || env.SITE_DOMAIN === 'seudominio.com.br') {
53
+ invalid.push('SITE_DOMAIN');
54
+ }
55
+
56
+ if (invalid.length > 0) {
57
+ console.error(`\nERROR: placeholder values remain in .client.env: ${invalid.join(', ')}\n`);
58
+ process.exit(1);
59
+ }
60
+
61
+ function tomlString(value) {
62
+ return String(value || '').replace(/\\/g, '\\\\').replace(/"/g, '\\"');
63
+ }
64
+
51
65
  let toml = fs.readFileSync(TOML, 'utf8');
52
66
 
53
67
  toml = toml
54
- .replace(/SEU_DATABASE_ID/g, env.DATABASE_ID)
55
- .replace(/SEU_DOMINIO/g, env.SITE_DOMAIN)
56
- .replace(/META_PIXEL_ID\s*=\s*""/, `META_PIXEL_ID = "${env.META_PIXEL_ID || ''}"`)
57
- .replace(/GA4_MEASUREMENT_ID\s*=\s*""/, `GA4_MEASUREMENT_ID = "${env.GA4_MEASUREMENT_ID || ''}"`)
58
- .replace(/TIKTOK_PIXEL_ID\s*=\s*""/, `TIKTOK_PIXEL_ID = "${env.TIKTOK_PIXEL_ID || ''}"`);
68
+ .replace(/database_id\s*=\s*"[^"]*"/, `database_id = "${tomlString(env.DATABASE_ID)}"`)
69
+ .replace(/SEU_DATABASE_ID/g, tomlString(env.DATABASE_ID))
70
+ .replace(/SEU_DOMINIO/g, tomlString(env.SITE_DOMAIN))
71
+ .replace(/META_PIXEL_ID\s*=\s*"[^"]*"/, `META_PIXEL_ID = "${tomlString(env.META_PIXEL_ID)}"`)
72
+ .replace(/GA4_MEASUREMENT_ID\s*=\s*"[^"]*"/, `GA4_MEASUREMENT_ID = "${tomlString(env.GA4_MEASUREMENT_ID)}"`)
73
+ .replace(/TIKTOK_PIXEL_ID\s*=\s*"[^"]*"/, `TIKTOK_PIXEL_ID = "${tomlString(env.TIKTOK_PIXEL_ID)}"`)
74
+ .replace(/ZAPMAN_API_URL\s*=\s*"[^"]*"/, `ZAPMAN_API_URL = "${tomlString(env.ZAPMAN_API_URL)}"`)
75
+ .replace(/ZAPMAN_CRM_INSTANCE\s*=\s*"[^"]*"/, `ZAPMAN_CRM_INSTANCE = "${tomlString(env.ZAPMAN_CRM_INSTANCE)}"`)
76
+ .replace(/ZAPMAN_WEBHOOK_URL\s*=\s*"[^"]*"/, `ZAPMAN_WEBHOOK_URL = "${tomlString(env.ZAPMAN_WEBHOOK_URL)}"`);
59
77
 
60
78
  fs.writeFileSync(DEPLOY, toml);
61
79
 
62
- // ── Executar wrangler deploy ──────────────────────────────────────────────────
63
80
  const cmd = `wrangler deploy --config wrangler.deploy.toml${DRY_RUN ? ' --dry-run' : ''}`;
64
- console.log(`\n🚀 ${DRY_RUN ? '[DRY-RUN] ' : ''}Deploying com config do cliente...\n`);
81
+ console.log(`\n${DRY_RUN ? '[DRY-RUN] ' : ''}Deploying with client config...\n`);
65
82
 
66
83
  try {
67
84
  execSync(cmd, { stdio: 'inherit', cwd: ROOT });
68
- console.log(`\n✅ Deploy ${DRY_RUN ? '(dry-run) ' : ''}concluído.\n`);
85
+ console.log(`\nDeploy ${DRY_RUN ? '(dry-run) ' : ''}completed.\n`);
69
86
  } catch (err) {
70
- console.error('\n❌ Deploy falhou.\n');
87
+ console.error('\nDeploy failed.\n');
71
88
  process.exit(1);
72
89
  } finally {
73
- // sempre remove o arquivo temporário
74
90
  if (fs.existsSync(DEPLOY)) fs.unlinkSync(DEPLOY);
75
- console.log('🧹 wrangler.deploy.toml removido.\n');
91
+ console.log('Removed temporary wrangler.deploy.toml.\n');
76
92
  }