@jitsu/js 0.0.1-alpha.136 → 0.0.1-alpha.183

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.
@@ -1,15 +1,33 @@
1
- @jitsu/js:build: cache hit, replaying output 28c829c71eac02d2
2
- @jitsu/js:build: 
3
- @jitsu/js:build: > @jitsu/js@0.0.0 build /Users/ildarnurislamov/Projects/onetag/libs/jitsu-js
4
- @jitsu/js:build: > tsc -p . && rollup -c && cp compiled/src/*.d.ts dist
5
- @jitsu/js:build: 
6
- @jitsu/js:build: 
7
- @jitsu/js:build: ./compiled/src/browser.js → dist/web/p.js.txt...
8
- @jitsu/js:build: (!) Circular dependency
9
- @jitsu/js:build: compiled/src/index.js -> compiled/src/analytics-plugin.js -> compiled/src/index.js
10
- @jitsu/js:build: created dist/web/p.js.txt in 321ms
11
- @jitsu/js:build: 
12
- @jitsu/js:build: ./compiled/src/index.js, ./compiled/src/jitsu.js, ./compiled/src/analytics-plugin.js → dist/jitsu.es.js, dist/jitsu.cjs.js...
13
- @jitsu/js:build: (!) Circular dependency
14
- @jitsu/js:build: compiled/src/index.js -> compiled/src/analytics-plugin.js -> compiled/src/index.js
15
- @jitsu/js:build: created dist/jitsu.es.js, dist/jitsu.cjs.js in 169ms
1
+ @jitsu/js:build: cache hit, replaying output 8244893c54c61c31
2
+ @jitsu/js:build: 
3
+ @jitsu/js:build: > @jitsu/js@0.0.0 build /Users/ildarnurislamov/Projects/onetag/libs/jitsu-js
4
+ @jitsu/js:build: > tsc -p . && rollup -c && cp compiled/src/*.d.ts dist
5
+ @jitsu/js:build: 
6
+ @jitsu/js:build: 
7
+ @jitsu/js:build: ./compiled/src/browser.js → dist/web/p.js.txt...
8
+ @jitsu/js:build: (!) Circular dependency
9
+ @jitsu/js:build: compiled/src/index.js -> compiled/src/analytics-plugin.js -> compiled/src/index.js
10
+ @jitsu/js:build: (!) Use of eval is strongly discouraged
11
+ @jitsu/js:build: https://rollupjs.org/guide/en/#avoiding-eval
12
+ @jitsu/js:build: compiled/src/analytics-plugin.js
13
+ @jitsu/js:build: 258: })()`;
14
+ @jitsu/js:build: 259: try {
15
+ @jitsu/js:build: 260: eval(iif);
16
+ @jitsu/js:build:  ^
17
+ @jitsu/js:build: 261: }
18
+ @jitsu/js:build: 262: catch (e) {
19
+ @jitsu/js:build: created dist/web/p.js.txt in 214ms
20
+ @jitsu/js:build: 
21
+ @jitsu/js:build: ./compiled/src/index.js, ./compiled/src/jitsu.js, ./compiled/src/analytics-plugin.js → dist/jitsu.es.js, dist/jitsu.cjs.js...
22
+ @jitsu/js:build: (!) Circular dependency
23
+ @jitsu/js:build: compiled/src/index.js -> compiled/src/analytics-plugin.js -> compiled/src/index.js
24
+ @jitsu/js:build: (!) Use of eval is strongly discouraged
25
+ @jitsu/js:build: https://rollupjs.org/guide/en/#avoiding-eval
26
+ @jitsu/js:build: compiled/src/analytics-plugin.js
27
+ @jitsu/js:build: 258: })()`;
28
+ @jitsu/js:build: 259: try {
29
+ @jitsu/js:build: 260: eval(iif);
30
+ @jitsu/js:build:  ^
31
+ @jitsu/js:build: 261: }
32
+ @jitsu/js:build: 262: catch (e) {
33
+ @jitsu/js:build: created dist/jitsu.es.js, dist/jitsu.cjs.js in 145ms
@@ -1,5 +1,5 @@
1
- @jitsu/js:clean: cache hit, replaying output 4b09f8b5fadef595
2
- @jitsu/js:clean: 
3
- @jitsu/js:clean: > @jitsu/js@0.0.0 clean /Users/ildarnurislamov/Projects/onetag/libs/jitsu-js
4
- @jitsu/js:clean: > rm -rf ./dist
5
- @jitsu/js:clean: 
1
+ @jitsu/js:clean: cache hit, replaying output e08f10d98a117543
2
+ @jitsu/js:clean: 
3
+ @jitsu/js:clean: > @jitsu/js@0.0.0 clean /Users/ildarnurislamov/Projects/onetag/libs/jitsu-js
4
+ @jitsu/js:clean: > rm -rf ./dist
5
+ @jitsu/js:clean: 
@@ -90,9 +90,15 @@ function generateX509Certificate(altNames: { type: number; value: string }[]) {
90
90
 
91
91
  function shutdownFunction(server): Promise<void> {
92
92
  return new Promise<void>(resolve => {
93
- server.close(() => {
94
- resolve();
95
- });
93
+ let resolved = false;
94
+ const resolveIfNeeded = () => {
95
+ if (!resolved) {
96
+ resolved = true;
97
+ resolve();
98
+ }
99
+ };
100
+ setTimeout(resolveIfNeeded, 5000);
101
+ server.close(resolveIfNeeded);
96
102
  });
97
103
  }
98
104
 
package/dist/jitsu.cjs.js CHANGED
@@ -317,6 +317,61 @@ function adjustPayload(payload, config, storage) {
317
317
  delete withContext.options;
318
318
  return withContext;
319
319
  }
320
+ function execJs(code, event) {
321
+ const varName = `jitsu_event_${randomId()}`;
322
+ window[varName] = event;
323
+ const iif = `(function(){
324
+ ${code}
325
+ onEvent(${varName});
326
+ })()`;
327
+ try {
328
+ eval(iif);
329
+ }
330
+ catch (e) {
331
+ console.error(`[JITSU] Error executing JS code: ${e.message}`);
332
+ }
333
+ finally {
334
+ delete window[varName];
335
+ }
336
+ return iif;
337
+ }
338
+ function replaceMacro(code, event) {
339
+ return code.replace(/{{\s*event\s*}}/g, JSON.stringify(event));
340
+ }
341
+ function insertTags(tags, event, opts = {}) {
342
+ const debug = opts.debug || false;
343
+ if (isInBrowser()) {
344
+ Object.values(tags).forEach(tag => {
345
+ if (tag.mode === "javascript") {
346
+ execJs(tag.code, event);
347
+ }
348
+ else {
349
+ const codeHolder = document.createElement("span");
350
+ codeHolder.innerHTML = replaceMacro(tag.code, event);
351
+ document.body.insertAdjacentElement("beforeend", codeHolder);
352
+ const scripts = codeHolder.querySelectorAll("script");
353
+ scripts.forEach(script => {
354
+ const scriptClone = document.createElement("script");
355
+ scriptClone.type = scriptClone.type || "text/javascript";
356
+ if (script.hasAttribute("src")) {
357
+ scriptClone.src = script.src;
358
+ }
359
+ scriptClone.text = script.text;
360
+ if (debug) {
361
+ console.log(`Executing script${script.hasAttribute("src") ? ` ${script.src}` : ""}`, scriptClone.text);
362
+ }
363
+ document.head.appendChild(scriptClone);
364
+ document.head.removeChild(scriptClone);
365
+ });
366
+ }
367
+ });
368
+ }
369
+ else {
370
+ if (debug) {
371
+ console.log(`insertTags: cannot insert tags in non-browser environment`);
372
+ }
373
+ }
374
+ }
320
375
  function send(method, payload, jitsuConfig, store) {
321
376
  if (jitsuConfig.echoEvents) {
322
377
  console.log(`[JITSU] sending '${method}' event:`, payload);
@@ -329,9 +384,9 @@ function send(method, payload, jitsuConfig, store) {
329
384
  }
330
385
  const authHeader = {};
331
386
  const debugHeader = jitsuConfig.debug ? { "X-Enable-Debug": "true" } : {};
332
- if (jitsuConfig.debug) {
333
- console.log(`Sending jitsu event to ${url}: `, JSON.stringify(payload, null, 2));
334
- }
387
+ // if (jitsuConfig.debug) {
388
+ // console.log(`[JITSU] Sending event to ${url}: `, JSON.stringify(payload, null, 2));
389
+ // }
335
390
  const adjustedPayload = adjustPayload(payload, jitsuConfig, store);
336
391
  return fetch(url, {
337
392
  method: "POST",
@@ -340,7 +395,27 @@ function send(method, payload, jitsuConfig, store) {
340
395
  })
341
396
  .then(res => {
342
397
  if (jitsuConfig.debug) {
343
- console.debug(`Jitsu ${url} replied ${res.status}. Original payload: `, JSON.stringify(adjustedPayload, null, 2));
398
+ console.log(`[JITSU] ${url} replied ${res.status}. Original payload: `, JSON.stringify(adjustedPayload, null, 2));
399
+ }
400
+ if (res.ok) {
401
+ return res.text();
402
+ }
403
+ else {
404
+ return Promise.reject(res.text());
405
+ }
406
+ })
407
+ .then(responseText => {
408
+ try {
409
+ const response = JSON.parse(responseText);
410
+ if (response.tags) {
411
+ if (jitsuConfig.debug) {
412
+ console.log(`[JITSU] Response Tags: `, JSON.stringify(response.tags, null, 2));
413
+ }
414
+ insertTags(response.tags, payload, { debug: jitsuConfig.debug });
415
+ }
416
+ }
417
+ catch (e) {
418
+ return Promise.reject(`Can't parse JSON: ${responseText}: ${e === null || e === void 0 ? void 0 : e.message}`);
344
419
  }
345
420
  })
346
421
  .catch(err => {
package/dist/jitsu.es.js CHANGED
@@ -315,6 +315,61 @@ function adjustPayload(payload, config, storage) {
315
315
  delete withContext.options;
316
316
  return withContext;
317
317
  }
318
+ function execJs(code, event) {
319
+ const varName = `jitsu_event_${randomId()}`;
320
+ window[varName] = event;
321
+ const iif = `(function(){
322
+ ${code}
323
+ onEvent(${varName});
324
+ })()`;
325
+ try {
326
+ eval(iif);
327
+ }
328
+ catch (e) {
329
+ console.error(`[JITSU] Error executing JS code: ${e.message}`);
330
+ }
331
+ finally {
332
+ delete window[varName];
333
+ }
334
+ return iif;
335
+ }
336
+ function replaceMacro(code, event) {
337
+ return code.replace(/{{\s*event\s*}}/g, JSON.stringify(event));
338
+ }
339
+ function insertTags(tags, event, opts = {}) {
340
+ const debug = opts.debug || false;
341
+ if (isInBrowser()) {
342
+ Object.values(tags).forEach(tag => {
343
+ if (tag.mode === "javascript") {
344
+ execJs(tag.code, event);
345
+ }
346
+ else {
347
+ const codeHolder = document.createElement("span");
348
+ codeHolder.innerHTML = replaceMacro(tag.code, event);
349
+ document.body.insertAdjacentElement("beforeend", codeHolder);
350
+ const scripts = codeHolder.querySelectorAll("script");
351
+ scripts.forEach(script => {
352
+ const scriptClone = document.createElement("script");
353
+ scriptClone.type = scriptClone.type || "text/javascript";
354
+ if (script.hasAttribute("src")) {
355
+ scriptClone.src = script.src;
356
+ }
357
+ scriptClone.text = script.text;
358
+ if (debug) {
359
+ console.log(`Executing script${script.hasAttribute("src") ? ` ${script.src}` : ""}`, scriptClone.text);
360
+ }
361
+ document.head.appendChild(scriptClone);
362
+ document.head.removeChild(scriptClone);
363
+ });
364
+ }
365
+ });
366
+ }
367
+ else {
368
+ if (debug) {
369
+ console.log(`insertTags: cannot insert tags in non-browser environment`);
370
+ }
371
+ }
372
+ }
318
373
  function send(method, payload, jitsuConfig, store) {
319
374
  if (jitsuConfig.echoEvents) {
320
375
  console.log(`[JITSU] sending '${method}' event:`, payload);
@@ -327,9 +382,9 @@ function send(method, payload, jitsuConfig, store) {
327
382
  }
328
383
  const authHeader = {};
329
384
  const debugHeader = jitsuConfig.debug ? { "X-Enable-Debug": "true" } : {};
330
- if (jitsuConfig.debug) {
331
- console.log(`Sending jitsu event to ${url}: `, JSON.stringify(payload, null, 2));
332
- }
385
+ // if (jitsuConfig.debug) {
386
+ // console.log(`[JITSU] Sending event to ${url}: `, JSON.stringify(payload, null, 2));
387
+ // }
333
388
  const adjustedPayload = adjustPayload(payload, jitsuConfig, store);
334
389
  return fetch(url, {
335
390
  method: "POST",
@@ -338,7 +393,27 @@ function send(method, payload, jitsuConfig, store) {
338
393
  })
339
394
  .then(res => {
340
395
  if (jitsuConfig.debug) {
341
- console.debug(`Jitsu ${url} replied ${res.status}. Original payload: `, JSON.stringify(adjustedPayload, null, 2));
396
+ console.log(`[JITSU] ${url} replied ${res.status}. Original payload: `, JSON.stringify(adjustedPayload, null, 2));
397
+ }
398
+ if (res.ok) {
399
+ return res.text();
400
+ }
401
+ else {
402
+ return Promise.reject(res.text());
403
+ }
404
+ })
405
+ .then(responseText => {
406
+ try {
407
+ const response = JSON.parse(responseText);
408
+ if (response.tags) {
409
+ if (jitsuConfig.debug) {
410
+ console.log(`[JITSU] Response Tags: `, JSON.stringify(response.tags, null, 2));
411
+ }
412
+ insertTags(response.tags, payload, { debug: jitsuConfig.debug });
413
+ }
414
+ }
415
+ catch (e) {
416
+ return Promise.reject(`Can't parse JSON: ${responseText}: ${e === null || e === void 0 ? void 0 : e.message}`);
342
417
  }
343
418
  })
344
419
  .catch(err => {
package/dist/web/p.js.txt CHANGED
@@ -318,6 +318,61 @@
318
318
  delete withContext.options;
319
319
  return withContext;
320
320
  }
321
+ function execJs(code, event) {
322
+ const varName = `jitsu_event_${randomId()}`;
323
+ window[varName] = event;
324
+ const iif = `(function(){
325
+ ${code}
326
+ onEvent(${varName});
327
+ })()`;
328
+ try {
329
+ eval(iif);
330
+ }
331
+ catch (e) {
332
+ console.error(`[JITSU] Error executing JS code: ${e.message}`);
333
+ }
334
+ finally {
335
+ delete window[varName];
336
+ }
337
+ return iif;
338
+ }
339
+ function replaceMacro(code, event) {
340
+ return code.replace(/{{\s*event\s*}}/g, JSON.stringify(event));
341
+ }
342
+ function insertTags(tags, event, opts = {}) {
343
+ const debug = opts.debug || false;
344
+ if (isInBrowser()) {
345
+ Object.values(tags).forEach(tag => {
346
+ if (tag.mode === "javascript") {
347
+ execJs(tag.code, event);
348
+ }
349
+ else {
350
+ const codeHolder = document.createElement("span");
351
+ codeHolder.innerHTML = replaceMacro(tag.code, event);
352
+ document.body.insertAdjacentElement("beforeend", codeHolder);
353
+ const scripts = codeHolder.querySelectorAll("script");
354
+ scripts.forEach(script => {
355
+ const scriptClone = document.createElement("script");
356
+ scriptClone.type = scriptClone.type || "text/javascript";
357
+ if (script.hasAttribute("src")) {
358
+ scriptClone.src = script.src;
359
+ }
360
+ scriptClone.text = script.text;
361
+ if (debug) {
362
+ console.log(`Executing script${script.hasAttribute("src") ? ` ${script.src}` : ""}`, scriptClone.text);
363
+ }
364
+ document.head.appendChild(scriptClone);
365
+ document.head.removeChild(scriptClone);
366
+ });
367
+ }
368
+ });
369
+ }
370
+ else {
371
+ if (debug) {
372
+ console.log(`insertTags: cannot insert tags in non-browser environment`);
373
+ }
374
+ }
375
+ }
321
376
  function send(method, payload, jitsuConfig, store) {
322
377
  if (jitsuConfig.echoEvents) {
323
378
  console.log(`[JITSU] sending '${method}' event:`, payload);
@@ -330,9 +385,9 @@
330
385
  }
331
386
  const authHeader = {};
332
387
  const debugHeader = jitsuConfig.debug ? { "X-Enable-Debug": "true" } : {};
333
- if (jitsuConfig.debug) {
334
- console.log(`Sending jitsu event to ${url}: `, JSON.stringify(payload, null, 2));
335
- }
388
+ // if (jitsuConfig.debug) {
389
+ // console.log(`[JITSU] Sending event to ${url}: `, JSON.stringify(payload, null, 2));
390
+ // }
336
391
  const adjustedPayload = adjustPayload(payload, jitsuConfig, store);
337
392
  return fetch(url, {
338
393
  method: "POST",
@@ -341,7 +396,27 @@
341
396
  })
342
397
  .then(res => {
343
398
  if (jitsuConfig.debug) {
344
- console.debug(`Jitsu ${url} replied ${res.status}. Original payload: `, JSON.stringify(adjustedPayload, null, 2));
399
+ console.log(`[JITSU] ${url} replied ${res.status}. Original payload: `, JSON.stringify(adjustedPayload, null, 2));
400
+ }
401
+ if (res.ok) {
402
+ return res.text();
403
+ }
404
+ else {
405
+ return Promise.reject(res.text());
406
+ }
407
+ })
408
+ .then(responseText => {
409
+ try {
410
+ const response = JSON.parse(responseText);
411
+ if (response.tags) {
412
+ if (jitsuConfig.debug) {
413
+ console.log(`[JITSU] Response Tags: `, JSON.stringify(response.tags, null, 2));
414
+ }
415
+ insertTags(response.tags, payload, { debug: jitsuConfig.debug });
416
+ }
417
+ }
418
+ catch (e) {
419
+ return Promise.reject(`Can't parse JSON: ${responseText}: ${e === null || e === void 0 ? void 0 : e.message}`);
345
420
  }
346
421
  })
347
422
  .catch(err => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jitsu/js",
3
- "version": "0.0.1-alpha.136",
3
+ "version": "0.0.1-alpha.183",
4
4
  "description": "",
5
5
  "author": "Jitsu Dev Team <dev@jitsu.com>",
6
6
  "main": "dist/jitsu.cjs.js",
@@ -36,7 +36,7 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "analytics": "^0.8.1",
39
- "@jitsu/protocols": "0.0.1-alpha.136"
39
+ "@jitsu/protocols": "0.0.1-alpha.183"
40
40
  },
41
41
  "scripts": {
42
42
  "clean": "rm -rf ./dist",
@@ -285,6 +285,64 @@ function adjustPayload(payload: any, config: JitsuOptions, storage: PersistentSt
285
285
  return withContext;
286
286
  }
287
287
 
288
+ function execJs(code: string, event: any) {
289
+ const varName = `jitsu_event_${randomId()}`;
290
+ window[varName] = event;
291
+ const iif = `(function(){
292
+ ${code}
293
+ onEvent(${varName});
294
+ })()`;
295
+ try {
296
+ eval(iif);
297
+ } catch (e) {
298
+ console.error(`[JITSU] Error executing JS code: ${e.message}`);
299
+ } finally {
300
+ delete window[varName];
301
+ }
302
+ return iif;
303
+ }
304
+
305
+ function replaceMacro(code, event) {
306
+ return code.replace(/{{\s*event\s*}}/g, JSON.stringify(event));
307
+ }
308
+
309
+ function insertTags(
310
+ tags: Record<string, { mode: "javascript" | "html"; code }>,
311
+ event: any,
312
+ opts: { debug?: boolean } = {}
313
+ ) {
314
+ const debug = opts.debug || false;
315
+ if (isInBrowser()) {
316
+ Object.values(tags).forEach(tag => {
317
+ if (tag.mode === "javascript") {
318
+ execJs(tag.code, event);
319
+ } else {
320
+ const codeHolder = document.createElement("span");
321
+ codeHolder.innerHTML = replaceMacro(tag.code, event);
322
+ document.body.insertAdjacentElement("beforeend", codeHolder);
323
+ const scripts = codeHolder.querySelectorAll("script");
324
+ scripts.forEach(script => {
325
+ const scriptClone = document.createElement("script");
326
+ scriptClone.type = scriptClone.type || "text/javascript";
327
+ if (script.hasAttribute("src")) {
328
+ scriptClone.src = script.src;
329
+ }
330
+ scriptClone.text = script.text;
331
+ if (debug) {
332
+ console.log(`Executing script${script.hasAttribute("src") ? ` ${script.src}` : ""}`, scriptClone.text);
333
+ }
334
+ document.head.appendChild(scriptClone);
335
+ document.head.removeChild(scriptClone);
336
+ });
337
+ }
338
+ });
339
+ } else {
340
+ if (debug) {
341
+ console.log(`insertTags: cannot insert tags in non-browser environment`);
342
+ }
343
+ }
344
+ }
345
+
288
346
  function send(method, payload, jitsuConfig: Required<JitsuOptions>, store: PersistentStorage): Promise<void> {
289
347
  if (jitsuConfig.echoEvents) {
290
348
  console.log(`[JITSU] sending '${method}' event:`, payload);
@@ -301,9 +359,9 @@ function send(method, payload, jitsuConfig: Required<JitsuOptions>, store: Persi
301
359
  const authHeader = {};
302
360
  const debugHeader = jitsuConfig.debug ? { "X-Enable-Debug": "true" } : {};
303
361
 
304
- if (jitsuConfig.debug) {
305
- console.log(`Sending jitsu event to ${url}: `, JSON.stringify(payload, null, 2));
306
- }
362
+ // if (jitsuConfig.debug) {
363
+ // console.log(`[JITSU] Sending event to ${url}: `, JSON.stringify(payload, null, 2));
364
+ // }
307
365
  const adjustedPayload = adjustPayload(payload, jitsuConfig, store);
308
366
  return fetch(url, {
309
367
  method: "POST",
@@ -317,11 +375,29 @@ function send(method, payload, jitsuConfig: Required<JitsuOptions>, store: Persi
317
375
  })
318
376
  .then(res => {
319
377
  if (jitsuConfig.debug) {
320
- console.debug(
321
- `Jitsu ${url} replied ${res.status}. Original payload: `,
378
+ console.log(
379
+ `[JITSU] ${url} replied ${res.status}. Original payload: `,
322
380
  JSON.stringify(adjustedPayload, null, 2)
323
381
  );
324
382
  }
383
+ if (res.ok) {
384
+ return res.text();
385
+ } else {
386
+ return Promise.reject(res.text());
387
+ }
388
+ })
389
+ .then(responseText => {
390
+ try {
391
+ const response = JSON.parse(responseText);
392
+ if (response.tags) {
393
+ if (jitsuConfig.debug) {
394
+ console.log(`[JITSU] Response Tags: `, JSON.stringify(response.tags, null, 2));
395
+ }
396
+ insertTags(response.tags, payload, { debug: jitsuConfig.debug });
397
+ }
398
+ } catch (e) {
399
+ return Promise.reject(`Can't parse JSON: ${responseText}: ${e?.message}`);
400
+ }
325
401
  })
326
402
  .catch(err => {
327
403
  if (jitsuConfig.debug) {