cdp-edge 1.25.1 → 1.27.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cdp-edge",
3
- "version": "1.25.1",
3
+ "version": "1.27.0",
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",
@@ -973,15 +973,18 @@ export default {
973
973
  },
974
974
 
975
975
  // ── Queue Consumer — Retry de eventos com falha ───────────────────────────────
976
- async queue(batch: any, env: Env) {
976
+ async queue(batch: any, env: Env, ctx: ExecutionContext) {
977
977
  for (const message of batch.messages) {
978
978
  const { eventType, payload, platform } = message.body as { eventType: string; payload: TrackPayload; platform: string; attempt?: number };
979
979
 
980
-
981
980
  try {
982
- if (platform === 'meta') await sendMetaCapi(env, eventType, payload, null, null);
983
- if (platform === 'ga4') await sendGA4Mp(env, eventType, payload, null);
984
- if (platform === 'tiktok') await sendTikTokApi(env, eventType, payload, null, null);
981
+ if (platform === 'meta') await sendMetaCapi(env, eventType, payload, null, ctx);
982
+ if (platform === 'ga4') await sendGA4Mp(env, eventType, payload, ctx);
983
+ if (platform === 'tiktok') await sendTikTokApi(env, eventType, payload, null, ctx);
984
+ if (platform === 'pinterest') await sendPinterestCapi(env, eventType, payload, null, ctx);
985
+ if (platform === 'reddit') await sendRedditCapi(env, eventType, payload, null, ctx);
986
+ if (platform === 'linkedin') await sendLinkedInCapi(env, eventType, payload, null, ctx);
987
+ if (platform === 'spotify') await sendSpotifyCapi(env, eventType, payload, null, ctx);
985
988
 
986
989
  message.ack();
987
990
  } catch (err: any) {
@@ -62,6 +62,11 @@ export async function sendGA4Mp(env: Env, ga4EventName: string, payload: TrackPa
62
62
  ctx.waitUntil(logApiFailure(env.DB, 'ga4', ga4EventName, 'FETCH_ERROR', err?.message || String(err), '', JSON.stringify(body)));
63
63
  }
64
64
 
65
+ if (env.RETRY_QUEUE) {
66
+ const send = env.RETRY_QUEUE.send({ eventType: ga4EventName, payload, platform: 'ga4' });
67
+ if (ctx) ctx.waitUntil(send); else send.catch(() => {});
68
+ }
69
+
65
70
  return { error: err?.message || String(err) };
66
71
  }
67
72
  }
@@ -133,6 +133,11 @@ export async function sendMetaCapi(env: Env, eventName: string, payload: TrackPa
133
133
  ctx.waitUntil(logApiFailure(env.DB, 'meta', eventName, 'FETCH_ERROR', err?.message || String(err), eventPayload.event_id, JSON.stringify(requestBody)));
134
134
  }
135
135
 
136
+ if (env.RETRY_QUEUE) {
137
+ const send = env.RETRY_QUEUE.send({ eventType: eventName, payload, platform: 'meta' });
138
+ if (ctx) ctx.waitUntil(send); else send.catch(() => {});
139
+ }
140
+
136
141
  return { error: err?.message || String(err) };
137
142
  }
138
143
  }
@@ -65,6 +65,10 @@ export async function sendPinterestCapi(env: Env, eventName: string, payload: Tr
65
65
  } catch (err: any) {
66
66
  console.error('Pinterest CAPI fetch failed:', err?.message || String(err));
67
67
  if (env.DB && ctx) ctx.waitUntil(logApiFailure(env.DB, 'pinterest', eventName, 'FETCH_ERROR', err?.message || String(err), '', JSON.stringify(body)));
68
+ if (env.RETRY_QUEUE) {
69
+ const send = env.RETRY_QUEUE.send({ eventType: eventName, payload, platform: 'pinterest' });
70
+ if (ctx) ctx.waitUntil(send); else send.catch(() => {});
71
+ }
68
72
  return { error: err?.message || String(err) };
69
73
  }
70
74
  }
@@ -123,6 +127,10 @@ export async function sendRedditCapi(env: Env, eventName: string, payload: Track
123
127
  } catch (err: any) {
124
128
  console.error('Reddit CAPI fetch failed:', err?.message || String(err));
125
129
  if (env.DB && ctx) ctx.waitUntil(logApiFailure(env.DB, 'reddit', eventName, 'FETCH_ERROR', err?.message || String(err), '', JSON.stringify(body)));
130
+ if (env.RETRY_QUEUE) {
131
+ const send = env.RETRY_QUEUE.send({ eventType: eventName, payload, platform: 'reddit' });
132
+ if (ctx) ctx.waitUntil(send); else send.catch(() => {});
133
+ }
126
134
  return { error: err?.message || String(err) };
127
135
  }
128
136
  }
@@ -178,6 +186,10 @@ export async function sendLinkedInCapi(env: Env, eventName: string, payload: Tra
178
186
  } catch (err: any) {
179
187
  console.error('LinkedIn CAPI fetch failed:', err?.message || String(err));
180
188
  if (env.DB && ctx) ctx.waitUntil(logApiFailure(env.DB, 'linkedin', eventName, 'FETCH_ERROR', err?.message || String(err), '', JSON.stringify(body)));
189
+ if (env.RETRY_QUEUE) {
190
+ const send = env.RETRY_QUEUE.send({ eventType: eventName, payload, platform: 'linkedin' });
191
+ if (ctx) ctx.waitUntil(send); else send.catch(() => {});
192
+ }
181
193
  return { error: err?.message || String(err) };
182
194
  }
183
195
  }
@@ -234,6 +246,10 @@ export async function sendSpotifyCapi(env: Env, eventName: string, payload: Trac
234
246
  } catch (err: any) {
235
247
  console.error('Spotify CAPI fetch failed:', err?.message || String(err));
236
248
  if (env.DB && ctx) ctx.waitUntil(logApiFailure(env.DB, 'spotify', eventName, 'FETCH_ERROR', err?.message || String(err), '', JSON.stringify(body)));
249
+ if (env.RETRY_QUEUE) {
250
+ const send = env.RETRY_QUEUE.send({ eventType: eventName, payload, platform: 'spotify' });
251
+ if (ctx) ctx.waitUntil(send); else send.catch(() => {});
252
+ }
237
253
  return { error: err?.message || String(err) };
238
254
  }
239
255
  }
@@ -97,6 +97,11 @@ export async function sendTikTokApi(env: Env, eventName: string, payload: TrackP
97
97
  ctx.waitUntil(logApiFailure(env.DB, 'tiktok', eventName, 'FETCH_ERROR', err?.message || String(err), '', JSON.stringify(body)));
98
98
  }
99
99
 
100
+ if (env.RETRY_QUEUE) {
101
+ const send = env.RETRY_QUEUE.send({ eventType: eventName, payload, platform: 'tiktok' });
102
+ if (ctx) ctx.waitUntil(send); else send.catch(() => {});
103
+ }
104
+
100
105
  return { error: err?.message || String(err) };
101
106
  }
102
107
  }
@@ -3,7 +3,7 @@
3
3
  * Tipos para o Cloudflare Worker e bindings
4
4
  */
5
5
 
6
- import { D1Database, KVNamespace, R2Bucket } from '@cloudflare/workers-types';
6
+ import { D1Database, KVNamespace, Queue, R2Bucket } from '@cloudflare/workers-types';
7
7
 
8
8
  // ── Environment Bindings ─────────────────────────────────────────────────────
9
9
  export interface Env {
@@ -22,6 +22,9 @@ export interface Env {
22
22
  // Rate Limiter
23
23
  RATE_LIMITER?: any;
24
24
 
25
+ // Queue — Retry de eventos com falha de rede
26
+ RETRY_QUEUE?: Queue<QueueMessage>;
27
+
25
28
  // Public Variables
26
29
  META_PIXEL_ID?: string;
27
30
  GA4_MEASUREMENT_ID?: string;