@beworke/pixel 0.1.0-rc.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.
Files changed (123) hide show
  1. package/CHANGELOG.md +194 -0
  2. package/README.md +163 -0
  3. package/RELEASE_CANDIDATE.md +256 -0
  4. package/dist/PixelLogger-B21lEjep.d.mts +8 -0
  5. package/dist/PixelLogger-B21lEjep.d.ts +8 -0
  6. package/dist/StorageFactory-BhpbB6Jj.d.mts +8 -0
  7. package/dist/StorageFactory-CAkJJqVD.d.ts +8 -0
  8. package/dist/config/index.cjs.js +3 -0
  9. package/dist/config/index.cjs.js.map +1 -0
  10. package/dist/config/index.d.mts +19 -0
  11. package/dist/config/index.d.ts +19 -0
  12. package/dist/config/index.esm.js +3 -0
  13. package/dist/config/index.esm.js.map +1 -0
  14. package/dist/events/index.cjs.js +3 -0
  15. package/dist/events/index.cjs.js.map +1 -0
  16. package/dist/events/index.d.mts +1 -0
  17. package/dist/events/index.d.ts +1 -0
  18. package/dist/events/index.esm.js +3 -0
  19. package/dist/events/index.esm.js.map +1 -0
  20. package/dist/examples/html-script/README.md +71 -0
  21. package/dist/examples/html-script/RELEASE_CANDIDATE.md +121 -0
  22. package/dist/examples/html-script/add-payment-info/README.md +46 -0
  23. package/dist/examples/html-script/add-payment-info/example-add-payment-info-card-autocomplete.html +494 -0
  24. package/dist/examples/html-script/add-payment-info/example-add-payment-info-card-disabled.html +478 -0
  25. package/dist/examples/html-script/add-payment-info/example-add-payment-info-card-fields.html +486 -0
  26. package/dist/examples/html-script/add-payment-info/example-add-payment-info-data-track.html +479 -0
  27. package/dist/examples/html-script/add-payment-info/example-add-payment-info-dedupe.html +492 -0
  28. package/dist/examples/html-script/add-payment-info/example-add-payment-info-manual.html +495 -0
  29. package/dist/examples/html-script/add-payment-info/example-add-payment-info-rules-card.html +469 -0
  30. package/dist/examples/html-script/add-payment-info/example-add-payment-info-security.html +489 -0
  31. package/dist/examples/html-script/add-to-cart/README.md +36 -0
  32. package/dist/examples/html-script/add-to-cart/example-add-to-cart-attribute.html +517 -0
  33. package/dist/examples/html-script/add-to-cart/example-add-to-cart-auto.html +512 -0
  34. package/dist/examples/html-script/add-to-cart/example-add-to-cart-click.html +519 -0
  35. package/dist/examples/html-script/add-to-cart/example-add-to-cart-dedupe.html +514 -0
  36. package/dist/examples/html-script/add-to-cart/example-add-to-cart-manual.html +517 -0
  37. package/dist/examples/html-script/add-to-cart/example-add-to-cart-order-bump.html +527 -0
  38. package/dist/examples/html-script/add-to-cart/example-add-to-cart-text.html +524 -0
  39. package/dist/examples/html-script/example-basic.html +350 -0
  40. package/dist/examples/html-script/example-behavior.html +435 -0
  41. package/dist/examples/html-script/example-conversion.html +479 -0
  42. package/dist/examples/html-script/example-integration.html +709 -0
  43. package/dist/examples/html-script/example-transport.html +748 -0
  44. package/dist/examples/html-script/initiate-checkout/README.md +38 -0
  45. package/dist/examples/html-script/initiate-checkout/example-initiate-checkout-attribute.html +485 -0
  46. package/dist/examples/html-script/initiate-checkout/example-initiate-checkout-auto.html +491 -0
  47. package/dist/examples/html-script/initiate-checkout/example-initiate-checkout-click.html +493 -0
  48. package/dist/examples/html-script/initiate-checkout/example-initiate-checkout-manual.html +494 -0
  49. package/dist/examples/html-script/initiate-checkout/example-initiate-checkout-snapshot.html +497 -0
  50. package/dist/examples/html-script/initiate-checkout/example-initiate-checkout-submit.html +502 -0
  51. package/dist/examples/html-script/initiate-checkout/example-initiate-checkout-text.html +496 -0
  52. package/dist/examples/html-script/lead/README.md +25 -0
  53. package/dist/examples/html-script/lead/example-lead-trigger-attribute.html +594 -0
  54. package/dist/examples/html-script/lead/example-lead-trigger-auto.html +431 -0
  55. package/dist/examples/html-script/lead/example-lead-trigger-click.html +587 -0
  56. package/dist/examples/html-script/release-candidate.html +726 -0
  57. package/dist/examples/html-script/remove-from-cart/README.md +36 -0
  58. package/dist/examples/html-script/remove-from-cart/example-remove-from-cart-attribute.html +532 -0
  59. package/dist/examples/html-script/remove-from-cart/example-remove-from-cart-css.html +524 -0
  60. package/dist/examples/html-script/remove-from-cart/example-remove-from-cart-dedupe.html +540 -0
  61. package/dist/examples/html-script/remove-from-cart/example-remove-from-cart-manual.html +533 -0
  62. package/dist/examples/html-script/remove-from-cart/example-remove-from-cart-multi.html +557 -0
  63. package/dist/examples/html-script/remove-from-cart/example-remove-from-cart-state.html +539 -0
  64. package/dist/examples/html-script/remove-from-cart/example-remove-from-cart-text.html +524 -0
  65. package/dist/examples/html-script/search/README.md +41 -0
  66. package/dist/examples/html-script/search/example-search-attribute.html +454 -0
  67. package/dist/examples/html-script/search/example-search-button-sync.html +455 -0
  68. package/dist/examples/html-script/search/example-search-dedupe.html +466 -0
  69. package/dist/examples/html-script/search/example-search-input.html +456 -0
  70. package/dist/examples/html-script/search/example-search-manual.html +473 -0
  71. package/dist/examples/html-script/search/example-search-submit.html +450 -0
  72. package/dist/examples/html-script/search/example-search-text.html +441 -0
  73. package/dist/examples/html-script/view-content/README.md +48 -0
  74. package/dist/examples/html-script/view-content/example-view-content-attribute.html +488 -0
  75. package/dist/examples/html-script/view-content/example-view-content-css.html +467 -0
  76. package/dist/examples/html-script/view-content/example-view-content-dedupe.html +485 -0
  77. package/dist/examples/html-script/view-content/example-view-content-empty.html +469 -0
  78. package/dist/examples/html-script/view-content/example-view-content-manual.html +496 -0
  79. package/dist/examples/html-script/view-content/example-view-content-product-card.html +478 -0
  80. package/dist/examples/html-script/view-content/example-view-content-text.html +473 -0
  81. package/dist/examples/release-candidate/README.md +14 -0
  82. package/dist/examples/v2/README.md +33 -0
  83. package/dist/index-DUfFzniE.d.mts +274 -0
  84. package/dist/index-DUfFzniE.d.ts +274 -0
  85. package/dist/index.cjs.js +3 -0
  86. package/dist/index.cjs.js.map +1 -0
  87. package/dist/index.d.mts +364 -0
  88. package/dist/index.d.ts +364 -0
  89. package/dist/index.esm.js +3 -0
  90. package/dist/index.esm.js.map +1 -0
  91. package/dist/logger/index.cjs.js +3 -0
  92. package/dist/logger/index.cjs.js.map +1 -0
  93. package/dist/logger/index.d.mts +12 -0
  94. package/dist/logger/index.d.ts +12 -0
  95. package/dist/logger/index.esm.js +3 -0
  96. package/dist/logger/index.esm.js.map +1 -0
  97. package/dist/pixel-CbeF25mD.d.mts +555 -0
  98. package/dist/pixel-CbeF25mD.d.ts +555 -0
  99. package/dist/pixel-default-config-1VgLFOiL.d.mts +5 -0
  100. package/dist/pixel-default-config-Bxb-Vdd8.d.ts +5 -0
  101. package/dist/runtime/index.cjs.js +3 -0
  102. package/dist/runtime/index.cjs.js.map +1 -0
  103. package/dist/runtime/index.d.mts +48 -0
  104. package/dist/runtime/index.d.ts +48 -0
  105. package/dist/runtime/index.esm.js +3 -0
  106. package/dist/runtime/index.esm.js.map +1 -0
  107. package/dist/services/index.cjs.js +3 -0
  108. package/dist/services/index.cjs.js.map +1 -0
  109. package/dist/services/index.d.mts +169 -0
  110. package/dist/services/index.d.ts +169 -0
  111. package/dist/services/index.esm.js +3 -0
  112. package/dist/services/index.esm.js.map +1 -0
  113. package/dist/types-CTpRvFKZ.d.ts +71 -0
  114. package/dist/types-DGlBdsAy.d.mts +71 -0
  115. package/dist/v2/global.global.js +3 -0
  116. package/dist/v2/global.global.js.map +1 -0
  117. package/dist/v2/index.cjs.js +3 -0
  118. package/dist/v2/index.cjs.js.map +1 -0
  119. package/dist/v2/index.d.mts +7 -0
  120. package/dist/v2/index.d.ts +7 -0
  121. package/dist/v2/index.esm.js +3 -0
  122. package/dist/v2/index.esm.js.map +1 -0
  123. package/package.json +101 -0
@@ -0,0 +1,469 @@
1
+ <!doctype html>
2
+ <html lang="pt-BR">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>Pixel v2 — ADD_PAYMENT_INFO rules.card</title>
7
+ <style>
8
+ :root {
9
+ --bg: #f8fafc; --card: #fff; --border: #e2e8f0; --text: #0f172a;
10
+ --muted: #64748b; --accent: #0f766e; --accent-soft: #ccfbf1;
11
+ --warn: #9a3412; --warn-soft: #ffedd5;
12
+ }
13
+ * { box-sizing: border-box; }
14
+ body {
15
+ margin: 0;
16
+ font-family: "Segoe UI", system-ui, sans-serif;
17
+ background:
18
+ radial-gradient(circle at top left, #ecfeff 0%, transparent 40%),
19
+ linear-gradient(180deg, #f8fafc 0%, #eef2ff 100%);
20
+ color: var(--text); line-height: 1.45;
21
+ }
22
+ .wrap { max-width: 980px; margin: 0 auto; padding: 1.5rem; }
23
+ h1 { font-size: 1.5rem; margin: 0 0 0.35rem; letter-spacing: -0.02em; }
24
+ h2 { font-size: 1.05rem; margin: 0 0 0.75rem; }
25
+ .sub { color: var(--muted); margin: 0 0 1rem; font-size: 0.92rem; }
26
+ .nav { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 1rem; }
27
+ .nav a {
28
+ text-decoration: none; border: 1px solid var(--border); background: #fff;
29
+ color: var(--text); border-radius: 999px; padding: 0.3rem 0.7rem; font-size: 0.78rem;
30
+ }
31
+ .nav a.active { background: var(--accent); border-color: var(--accent); color: #fff; }
32
+ .grid { display: grid; grid-template-columns: 1.15fr 0.85fr; gap: 1rem; }
33
+ @media (max-width: 860px) { .grid { grid-template-columns: 1fr; } }
34
+ .card {
35
+ background: var(--card); border: 1px solid var(--border); border-radius: 12px;
36
+ padding: 1rem; margin-bottom: 1rem; box-shadow: 0 1px 0 rgba(15,23,42,.03);
37
+ }
38
+ .hint {
39
+ background: var(--accent-soft); border: 1px solid #99f6e4; border-radius: 10px;
40
+ padding: 0.85rem 1rem; font-size: 0.9rem; margin-bottom: 1rem;
41
+ }
42
+ .hint.warn { background: var(--warn-soft); border-color: #fdba74; color: var(--warn); }
43
+ .actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.75rem; }
44
+ button {
45
+ appearance: none; border: 1px solid var(--border); background: #fff; color: var(--text);
46
+ border-radius: 8px; padding: 0.5rem 0.85rem; cursor: pointer; font: inherit;
47
+ }
48
+ button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
49
+ button.danger { background: #7f1d1d; border-color: #7f1d1d; color: #fff; }
50
+ button:disabled { opacity: 0.55; cursor: not-allowed; }
51
+ label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.25rem; }
52
+ input, select {
53
+ width: 100%; border: 1px solid var(--border); border-radius: 8px;
54
+ padding: 0.55rem 0.7rem; font: inherit; background: #fff;
55
+ }
56
+ .row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
57
+ .row-3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 0.75rem; }
58
+ @media (max-width: 560px) {
59
+ .row, .row-3 { grid-template-columns: 1fr; }
60
+ }
61
+ .status, pre {
62
+ background: #0f172a; color: #e2e8f0; border-radius: 8px; padding: 0.75rem;
63
+ font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
64
+ font-size: 0.78rem; white-space: pre-wrap; word-break: break-word;
65
+ max-height: 260px; overflow: auto;
66
+ }
67
+ .pill {
68
+ display: inline-block; border-radius: 999px; padding: 0.15rem 0.55rem;
69
+ font-size: 0.72rem; background: #e2e8f0; color: #334155; margin-left: 0.35rem;
70
+ }
71
+ .pill.ok { background: #bbf7d0; color: #166534; }
72
+ .checklist { margin: 0; padding-left: 1.1rem; font-size: 0.88rem; color: var(--muted); }
73
+ .checklist li { margin: 0.35rem 0; }
74
+ .ctx {
75
+ border-left: 3px solid var(--accent); padding-left: 0.75rem; margin-bottom: 0.85rem;
76
+ color: var(--muted); font-size: 0.88rem;
77
+ }
78
+ code { font-size: 0.85em; }
79
+ </style>
80
+ </head>
81
+ <body>
82
+ <div class="wrap">
83
+ <h1>ADD_PAYMENT_INFO — rules.card.enabled</h1>
84
+ <p class="sub">
85
+ Cenário isolado para validação do Pixel v2.
86
+ <span class="pill" id="init-pill">offline</span>
87
+ </p>
88
+ <div class="nav"><a href="example-add-payment-info-card-autocomplete.html" class="">1. Autocomplete</a>
89
+ <a href="example-add-payment-info-card-fields.html" class="">2. id/name/CVV</a>
90
+ <a href="example-add-payment-info-card-disabled.html" class="">3. Detection off</a>
91
+ <a href="example-add-payment-info-manual.html" class="">4. Manual API</a>
92
+ <a href="example-add-payment-info-dedupe.html" class="">5. Dedupe sessão</a>
93
+ <a href="example-add-payment-info-security.html" class="">6. Segurança</a>
94
+ <a href="example-add-payment-info-rules-card.html" class="active">7. rules.card</a>
95
+ <a href="example-add-payment-info-data-track.html" class="">8. data-track</a></div>
96
+ <div class="hint"><strong>Contexto:</strong> CardDetector via
97
+ <code>conversion.rules.card.enabled</code> (heurística).
98
+ <code>addPaymentInfo.cardDetection</code> fica <strong>false</strong> para não duplicar
99
+ (factory: se rules.card on, não registra via addPaymentInfo).</div>
100
+
101
+ <div class="card">
102
+ <h2>Lifecycle</h2>
103
+ <div class="actions">
104
+ <button id="btn-reinit" class="primary" type="button">Reinitialize</button>
105
+ <button id="btn-destroy" class="danger" type="button">Destroy</button>
106
+ <button id="btn-clear" type="button">Clear logs</button>
107
+ </div>
108
+ <div class="status" id="runtime-status">Aguardando init...</div>
109
+ </div>
110
+
111
+ <div class="grid">
112
+ <div>
113
+ <div class="card">
114
+ <h2>Rules card <span class="pill">heurística</span></h2>
115
+ <div class="ctx">Mesmo CardDetector, origem de registro diferente.</div>
116
+ <div>
117
+ <label for="cc-rules">Número</label>
118
+ <input id="cc-rules" type="text" autocomplete="cc-number" placeholder="4111..." />
119
+ </div>
120
+ <p class="sub">Detector ativo: <code>CardDetector</code>. Evento idêntico.</p>
121
+ </div>
122
+ <div class="card">
123
+ <h2>Checklist</h2>
124
+ <ul class="checklist">
125
+ <li>[ ] Digitar → dispara ADD_PAYMENT_INFO</li>
126
+ <li>[ ] Detector: CardDetector (via rules)</li>
127
+ <li>[ ] paymentMethod CREDIT_CARD</li>
128
+ </ul>
129
+ </div>
130
+ </div>
131
+ <div>
132
+ <div class="card">
133
+ <h2>Event counts</h2>
134
+ <div class="status" id="event-counts">Nenhum evento ainda</div>
135
+ </div>
136
+ <div class="card">
137
+ <h2>Payment payload (último)</h2>
138
+ <div class="status" id="payment-payload">null</div>
139
+ </div>
140
+
141
+ <div class="card">
142
+ <h2>Active detectors</h2>
143
+ <div class="status" id="detectors">—</div>
144
+ </div>
145
+
146
+ <div class="card">
147
+ <h2>Last event JSON</h2>
148
+ <pre id="last-event">null</pre>
149
+ </div>
150
+ <div class="card">
151
+ <h2>Event log</h2>
152
+ <pre id="logs">Aguardando eventos...</pre>
153
+ </div>
154
+ </div>
155
+ </div>
156
+ </div>
157
+
158
+ <script src="../../../dist/v2/global.global.js"></script>
159
+ <script>
160
+ const { Pixel, DEFAULT_PIXEL_CONFIG } = window.PixelV2;
161
+ const API_ENDPOINT =
162
+ 'https://micro-service-pixel-production-4826.up.railway.app';
163
+ const PIXEL_ID = 'pix_7315610';
164
+
165
+ const els = {
166
+ logs: document.getElementById('logs'),
167
+ last: document.getElementById('last-event'),
168
+ counts: document.getElementById('event-counts'),
169
+ payload: document.getElementById('payment-payload'),
170
+ security: document.getElementById('security-check'),
171
+ detectors: document.getElementById('detectors'),
172
+ dedupe: document.getElementById('dedupe-keys'),
173
+ runtime: document.getElementById('runtime-status'),
174
+ pill: document.getElementById('init-pill'),
175
+ };
176
+
177
+ let pixel = null;
178
+ let unsubscribe = null;
179
+ let initCount = 0;
180
+ let destroyCount = 0;
181
+ const counts = {};
182
+
183
+ function addPaymentInfoDetectorConfig() {
184
+ return {
185
+ enabled: true,
186
+ paymentMethod: 'CREDIT_CARD',
187
+ cardDetection: false,
188
+ autoDispatch: true,
189
+ };
190
+ }
191
+
192
+ function rulesConfig() {
193
+ return {
194
+ enabled: true,
195
+ selectors: [],
196
+ texts: [],
197
+ urlPatterns: [],
198
+ checkout: { enabled: false },
199
+ card: { enabled: true },
200
+ };
201
+ }
202
+
203
+ function buildConfig() {
204
+ const base = DEFAULT_PIXEL_CONFIG;
205
+ return {
206
+ ...base,
207
+ app: {
208
+ ...base.app,
209
+ source: 'custom',
210
+ environment: 'development',
211
+ debug: true,
212
+ },
213
+ transport: {
214
+ ...DEFAULT_PIXEL_CONFIG.transport,
215
+ apiEndpoint: API_ENDPOINT,
216
+ timeoutMs: 10000,
217
+ },
218
+ identity: { ...base.identity, pixelId: PIXEL_ID },
219
+ modules: {
220
+ ...base.modules,
221
+ core: {
222
+ ...base.modules.core,
223
+ enabled: false,
224
+ pageView: {
225
+ ...base.modules.core.pageView,
226
+ enabled: false,
227
+ trackInitialPageView: false,
228
+ spa: false,
229
+ },
230
+ },
231
+ behavior: { ...base.modules.behavior, enabled: false },
232
+ privacy: { ...base.modules.privacy, enabled: false },
233
+ transport: {
234
+ enabled: true,
235
+ mockSender: { enabled: false },
236
+ sender: { mode: 'http' },
237
+ persistence: { enabled: true },
238
+ replay: { enabled: true },
239
+ ordering: { enabled: true },
240
+ coordination: { enabled: true },
241
+ circuitBreaker: {
242
+ enabled: true,
243
+ failureThreshold: 5,
244
+ resetTimeoutMs: 30000,
245
+ halfOpenMaxAttempts: 2,
246
+ },
247
+ backpressure: {
248
+ enabled: true,
249
+ maxQueueSize: 500,
250
+ policy: 'drop_oldest',
251
+ sampleRate: 0.5,
252
+ },
253
+ deadLetter: { enabled: true, maxEntries: 200 },
254
+ compression: { enabled: true, strategy: 'identity' },
255
+ retry: {
256
+ enabled: true,
257
+ maxAttempts: 4,
258
+ baseDelayMs: 500,
259
+ maxDelayMs: 4000,
260
+ multiplier: 2,
261
+ },
262
+ batch: {
263
+ enabled: true,
264
+ batchSize: 10,
265
+ flushIntervalMs: 2000,
266
+ maxWaitMs: 5000,
267
+ },
268
+ timeout: { enabled: true, timeoutMs: 10000 },
269
+ offline: { enabled: true },
270
+ flush: {
271
+ enabled: true,
272
+ flushIntervalMs: 2000,
273
+ flushOnDestroy: true,
274
+ prepareUnloadHooks: true,
275
+ },
276
+ },
277
+ integrations: { ...base.modules.integrations, enabled: false },
278
+ conversion: {
279
+ enabled: true,
280
+ commerce: {
281
+ currency: 'BRL',
282
+ catalog: { products: [] },
283
+ checkout: {
284
+ mode: 'single_product',
285
+ selectedItems: [],
286
+ calculateValueFrom: 'selected_items',
287
+ allowDynamicItems: true,
288
+ },
289
+ mappings: {
290
+ attributes: {
291
+ productId: ['data-product-id'],
292
+ productName: ['data-product-name'],
293
+ price: ['data-product-price'],
294
+ quantity: ['data-quantity'],
295
+ currency: ['data-currency'],
296
+ },
297
+ fields: {
298
+ email: ['email'],
299
+ phone: ['phone'],
300
+ productId: ['productId'],
301
+ productName: ['productName'],
302
+ price: ['price'],
303
+ quantity: ['quantity'],
304
+ currency: ['currency'],
305
+ },
306
+ },
307
+ },
308
+ manual: {
309
+ pageView: { enabled: false },
310
+ purchase: { enabled: false },
311
+ lead: { enabled: false },
312
+ addToCart: { enabled: false },
313
+ removeFromCart: { enabled: false },
314
+ initiateCheckout: { enabled: false },
315
+ addPaymentInfo: { enabled: true },
316
+ search: { enabled: false },
317
+ viewContent: { enabled: false },
318
+ },
319
+ auto: {
320
+ enabled: true,
321
+ detectors: {
322
+ lead: { enabled: false },
323
+ purchase: { enabled: false },
324
+ addToCart: { enabled: false },
325
+ removeFromCart: { enabled: false },
326
+ initiateCheckout: { enabled: false },
327
+ addPaymentInfo: addPaymentInfoDetectorConfig(),
328
+ search: { enabled: false },
329
+ viewContent: { enabled: false },
330
+ },
331
+ },
332
+ rules: rulesConfig(),
333
+ },
334
+ },
335
+ };
336
+ }
337
+
338
+ function appendLog(message) {
339
+ const line = '[' + new Date().toISOString() + '] ' + message;
340
+ const prev = els.logs.textContent;
341
+ els.logs.textContent =
342
+ prev === 'Aguardando eventos...' ? line : line + '\n' + prev;
343
+ }
344
+
345
+ function renderCounts() {
346
+ const lines = Object.keys(counts)
347
+ .sort()
348
+ .map(function (type) { return type + ': ' + counts[type]; });
349
+ els.counts.textContent =
350
+ lines.length > 0 ? lines.join('\n') : 'Nenhum evento ainda';
351
+ }
352
+
353
+ function renderPayload(event) {
354
+ if (!els.payload) return;
355
+ if (!event || event.type !== 'ADD_PAYMENT_INFO') {
356
+ els.payload.textContent = 'null';
357
+ return;
358
+ }
359
+ els.payload.textContent = JSON.stringify(event.data || {}, null, 2);
360
+ }
361
+
362
+ function renderSecurity(event) {
363
+ if (!els.security) return;
364
+ if (!event) {
365
+ els.security.textContent = 'Aguardando evento...';
366
+ return;
367
+ }
368
+ var raw = JSON.stringify(event);
369
+ var leaks = [];
370
+ if (/4111/.test(raw)) leaks.push('encontrou "4111" (PAN parcial)');
371
+ if (/111111111111/.test(raw)) leaks.push('encontrou sequência de cartão');
372
+ if (/\b123\b/.test(raw) && /cvv|cvc|csc/i.test(raw)) {
373
+ leaks.push('possível CVV no JSON');
374
+ }
375
+ // valores tipicos de demo
376
+ ['4111111111111111', '4242424242424242', '12/30', '123'].forEach(function (v) {
377
+ if (raw.indexOf(v) !== -1) leaks.push('vazou valor: ' + v);
378
+ });
379
+ els.security.textContent =
380
+ leaks.length === 0
381
+ ? 'OK — nenhum valor sensível no payload/evento'
382
+ : 'FALHA:\n- ' + leaks.join('\n- ');
383
+ }
384
+
385
+ function renderDebug() {
386
+ const detectors =
387
+ pixel && pixel.getDebugActiveDetectors
388
+ ? pixel.getDebugActiveDetectors()
389
+ : [];
390
+ els.detectors.textContent =
391
+ detectors.length > 0 ? detectors.join('\n') : 'Nenhum detector ativo';
392
+ if (els.dedupe) {
393
+ const keys =
394
+ pixel && pixel.getDebugDedupeKeys ? pixel.getDebugDedupeKeys() : [];
395
+ els.dedupe.textContent =
396
+ keys.length > 0 ? keys.join('\n') : 'Nenhuma chave';
397
+ }
398
+ els.runtime.textContent =
399
+ 'initialized: ' +
400
+ (pixel ? pixel.isInitialized() : false) +
401
+ '\ninit count: ' +
402
+ initCount +
403
+ '\ndestroy count: ' +
404
+ destroyCount +
405
+ '\npixelId: ' +
406
+ PIXEL_ID +
407
+ '\nscenario: rules.card.enabled';
408
+ els.pill.textContent =
409
+ pixel && pixel.isInitialized() ? 'ready' : 'offline';
410
+ els.pill.className =
411
+ 'pill' + (pixel && pixel.isInitialized() ? ' ok' : '');
412
+ }
413
+
414
+ function onEvent(event) {
415
+ counts[event.type] = (counts[event.type] || 0) + 1;
416
+ renderCounts();
417
+ renderPayload(event);
418
+ renderSecurity(event);
419
+ els.last.textContent = JSON.stringify(event, null, 2);
420
+ appendLog(event.type + ' ' + JSON.stringify(event.data || {}));
421
+ renderDebug();
422
+ }
423
+
424
+ async function boot() {
425
+ if (unsubscribe) { unsubscribe(); unsubscribe = null; }
426
+ if (pixel) {
427
+ await pixel.destroy();
428
+ destroyCount += 1;
429
+ pixel = null;
430
+ }
431
+ pixel = new Pixel(buildConfig());
432
+ await pixel.init();
433
+ initCount += 1;
434
+ const services = pixel.getDebugServices();
435
+ if (services && services.dispatcher) {
436
+ unsubscribe = services.dispatcher.subscribe(onEvent);
437
+ }
438
+ appendLog('Pixel initialized — rules.card.enabled');
439
+ renderDebug();
440
+ }
441
+
442
+ async function destroyPixel() {
443
+ if (unsubscribe) { unsubscribe(); unsubscribe = null; }
444
+ if (pixel) {
445
+ await pixel.destroy();
446
+ destroyCount += 1;
447
+ pixel = null;
448
+ }
449
+ appendLog('Pixel destroyed');
450
+ renderDebug();
451
+ }
452
+
453
+ document.getElementById('btn-reinit').onclick = function () { boot(); };
454
+ document.getElementById('btn-destroy').onclick = function () { destroyPixel(); };
455
+ document.getElementById('btn-clear').onclick = function () {
456
+ els.logs.textContent = 'Aguardando eventos...';
457
+ els.last.textContent = 'null';
458
+ if (els.payload) els.payload.textContent = 'null';
459
+ if (els.security) els.security.textContent = 'Aguardando evento...';
460
+ Object.keys(counts).forEach(function (k) { delete counts[k]; });
461
+ renderCounts();
462
+ };
463
+
464
+
465
+
466
+ boot();
467
+ </script>
468
+ </body>
469
+ </html>