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

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,15 @@
1
- @jitsu/js:build: cache hit, replaying output 0263d5983323ab5a
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 613ms
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 532ms
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,5 +1,5 @@
1
- @jitsu/js:clean: cache hit, replaying output e0930b6eea397172
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 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: 
package/dist/jitsu.cjs.js CHANGED
@@ -75,6 +75,7 @@ const config = {
75
75
  host: null,
76
76
  debug: false,
77
77
  fetch: null,
78
+ echoEvents: false,
78
79
  };
79
80
  const parseQuery = (qs) => {
80
81
  if (!qs) {
@@ -311,18 +312,22 @@ function adjustPayload(payload, config, storage) {
311
312
  },
312
313
  campaign: parseUtms(query),
313
314
  };
314
- const withContext = Object.assign(Object.assign({}, payload), { timestamp: new Date().toISOString(), sentAt: new Date().toISOString(), messageId: randomId(properties.path || (parsedUrl && parsedUrl.pathname)), context: deepMerge(context, customContext) });
315
+ const withContext = Object.assign(Object.assign({}, payload), { timestamp: new Date().toISOString(), sentAt: new Date().toISOString(), messageId: randomId(properties.path || (parsedUrl && parsedUrl.pathname)), writeKey: config.writeKey, context: deepMerge(context, customContext) });
315
316
  delete withContext.meta;
316
317
  delete withContext.options;
317
318
  return withContext;
318
319
  }
319
320
  function send(method, payload, jitsuConfig, store) {
321
+ if (jitsuConfig.echoEvents) {
322
+ console.log(`[JITSU] sending '${method}' event:`, payload);
323
+ return;
324
+ }
320
325
  const url = `${jitsuConfig.host}/api/s/${method}`;
321
326
  const fetch = jitsuConfig.fetch || globalThis.fetch;
322
327
  if (!fetch) {
323
328
  throw new Error("Please specify fetch function in jitsu plugin initialization, fetch isn't available in global scope");
324
329
  }
325
- const authHeader = jitsuConfig.writeKey ? { Authorization: `Bearer ${jitsuConfig.writeKey}` } : {};
330
+ const authHeader = {};
326
331
  const debugHeader = jitsuConfig.debug ? { "X-Enable-Debug": "true" } : {};
327
332
  if (jitsuConfig.debug) {
328
333
  console.log(`Sending jitsu event to ${url}: `, JSON.stringify(payload, null, 2));
@@ -370,8 +375,8 @@ const jitsuAnalyticsPlugin = (pluginConfig = {}) => {
370
375
  if (config.debug) {
371
376
  console.debug("Initializing Jitsu plugin with config: ", JSON.stringify(config));
372
377
  }
373
- if (!config.host) {
374
- throw new Error("Please specify host variable in jitsu plugin initialization");
378
+ if (!config.host && !config.echoEvents) {
379
+ throw new Error("Please specify host variable in jitsu plugin initialization, or set echoEvents to true");
375
380
  }
376
381
  },
377
382
  page: args => {
package/dist/jitsu.d.ts CHANGED
@@ -10,10 +10,33 @@ type JitsuOptions = {
10
10
  * API Host. Default value: same host as script origin
11
11
  */
12
12
  host?: string;
13
+ /**
14
+ * To enable debug logging
15
+ */
13
16
  debug?: boolean;
17
+ /**
18
+ * Explicitely specify cookie domain. If not set, cookie domain will be set to top level
19
+ * of the current domain. Example: if JS lives on "app.example.com", cookie domain will be
20
+ * set to ".example.com". If it lives on "example.com", cookie domain will be set to ".example.com" too
21
+ */
14
22
  cookieDomain?: string;
23
+ /**
24
+ * Provide fetch implementation. It is required if you want to use Jitsu in NodeJS
25
+ */
15
26
  fetch?: typeof fetch;
27
+ /**
28
+ * Which runtime to use. Runtime is used for obtaining context of the event: cookes,
29
+ * url, etc. At the moment, Jitsu supports browser runtime and NodeJS runtime, but you
30
+ * can provide your own implementation.
31
+ *
32
+ * If it's not set, the runtime will be detected automatically by presense of `window` object
33
+ */
16
34
  runtime?: RuntimeFacade;
35
+ /**
36
+ * If set to true, jitsu will output events in console. In this case you don't need to set
37
+ * writeKey / host. It's useful for debugging development environment
38
+ */
39
+ echoEvents?: boolean;
17
40
  };
18
41
  type PersistentStorage = {
19
42
  getItem: (key: string, options?: any) => any;
package/dist/jitsu.es.js CHANGED
@@ -73,6 +73,7 @@ const config = {
73
73
  host: null,
74
74
  debug: false,
75
75
  fetch: null,
76
+ echoEvents: false,
76
77
  };
77
78
  const parseQuery = (qs) => {
78
79
  if (!qs) {
@@ -309,18 +310,22 @@ function adjustPayload(payload, config, storage) {
309
310
  },
310
311
  campaign: parseUtms(query),
311
312
  };
312
- const withContext = Object.assign(Object.assign({}, payload), { timestamp: new Date().toISOString(), sentAt: new Date().toISOString(), messageId: randomId(properties.path || (parsedUrl && parsedUrl.pathname)), context: deepMerge(context, customContext) });
313
+ const withContext = Object.assign(Object.assign({}, payload), { timestamp: new Date().toISOString(), sentAt: new Date().toISOString(), messageId: randomId(properties.path || (parsedUrl && parsedUrl.pathname)), writeKey: config.writeKey, context: deepMerge(context, customContext) });
313
314
  delete withContext.meta;
314
315
  delete withContext.options;
315
316
  return withContext;
316
317
  }
317
318
  function send(method, payload, jitsuConfig, store) {
319
+ if (jitsuConfig.echoEvents) {
320
+ console.log(`[JITSU] sending '${method}' event:`, payload);
321
+ return;
322
+ }
318
323
  const url = `${jitsuConfig.host}/api/s/${method}`;
319
324
  const fetch = jitsuConfig.fetch || globalThis.fetch;
320
325
  if (!fetch) {
321
326
  throw new Error("Please specify fetch function in jitsu plugin initialization, fetch isn't available in global scope");
322
327
  }
323
- const authHeader = jitsuConfig.writeKey ? { Authorization: `Bearer ${jitsuConfig.writeKey}` } : {};
328
+ const authHeader = {};
324
329
  const debugHeader = jitsuConfig.debug ? { "X-Enable-Debug": "true" } : {};
325
330
  if (jitsuConfig.debug) {
326
331
  console.log(`Sending jitsu event to ${url}: `, JSON.stringify(payload, null, 2));
@@ -368,8 +373,8 @@ const jitsuAnalyticsPlugin = (pluginConfig = {}) => {
368
373
  if (config.debug) {
369
374
  console.debug("Initializing Jitsu plugin with config: ", JSON.stringify(config));
370
375
  }
371
- if (!config.host) {
372
- throw new Error("Please specify host variable in jitsu plugin initialization");
376
+ if (!config.host && !config.echoEvents) {
377
+ throw new Error("Please specify host variable in jitsu plugin initialization, or set echoEvents to true");
373
378
  }
374
379
  },
375
380
  page: args => {
package/dist/web/p.js.txt CHANGED
@@ -76,6 +76,7 @@
76
76
  host: null,
77
77
  debug: false,
78
78
  fetch: null,
79
+ echoEvents: false,
79
80
  };
80
81
  const parseQuery = (qs) => {
81
82
  if (!qs) {
@@ -312,18 +313,22 @@
312
313
  },
313
314
  campaign: parseUtms(query),
314
315
  };
315
- const withContext = Object.assign(Object.assign({}, payload), { timestamp: new Date().toISOString(), sentAt: new Date().toISOString(), messageId: randomId(properties.path || (parsedUrl && parsedUrl.pathname)), context: deepMerge(context, customContext) });
316
+ const withContext = Object.assign(Object.assign({}, payload), { timestamp: new Date().toISOString(), sentAt: new Date().toISOString(), messageId: randomId(properties.path || (parsedUrl && parsedUrl.pathname)), writeKey: config.writeKey, context: deepMerge(context, customContext) });
316
317
  delete withContext.meta;
317
318
  delete withContext.options;
318
319
  return withContext;
319
320
  }
320
321
  function send(method, payload, jitsuConfig, store) {
322
+ if (jitsuConfig.echoEvents) {
323
+ console.log(`[JITSU] sending '${method}' event:`, payload);
324
+ return;
325
+ }
321
326
  const url = `${jitsuConfig.host}/api/s/${method}`;
322
327
  const fetch = jitsuConfig.fetch || globalThis.fetch;
323
328
  if (!fetch) {
324
329
  throw new Error("Please specify fetch function in jitsu plugin initialization, fetch isn't available in global scope");
325
330
  }
326
- const authHeader = jitsuConfig.writeKey ? { Authorization: `Bearer ${jitsuConfig.writeKey}` } : {};
331
+ const authHeader = {};
327
332
  const debugHeader = jitsuConfig.debug ? { "X-Enable-Debug": "true" } : {};
328
333
  if (jitsuConfig.debug) {
329
334
  console.log(`Sending jitsu event to ${url}: `, JSON.stringify(payload, null, 2));
@@ -371,8 +376,8 @@
371
376
  if (config.debug) {
372
377
  console.debug("Initializing Jitsu plugin with config: ", JSON.stringify(config));
373
378
  }
374
- if (!config.host) {
375
- throw new Error("Please specify host variable in jitsu plugin initialization");
379
+ if (!config.host && !config.echoEvents) {
380
+ throw new Error("Please specify host variable in jitsu plugin initialization, or set echoEvents to true");
376
381
  }
377
382
  },
378
383
  page: args => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jitsu/js",
3
- "version": "0.0.1-alpha.127",
3
+ "version": "0.0.1-alpha.136",
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.127"
39
+ "@jitsu/protocols": "0.0.1-alpha.136"
40
40
  },
41
41
  "scripts": {
42
42
  "clean": "rm -rf ./dist",
@@ -12,6 +12,7 @@ const config: JitsuOptions = {
12
12
  host: null,
13
13
  debug: false,
14
14
  fetch: null,
15
+ echoEvents: false,
15
16
  };
16
17
 
17
18
  export const parseQuery = (qs?: string): Record<string, string> => {
@@ -276,6 +277,7 @@ function adjustPayload(payload: any, config: JitsuOptions, storage: PersistentSt
276
277
  timestamp: new Date().toISOString(),
277
278
  sentAt: new Date().toISOString(),
278
279
  messageId: randomId(properties.path || (parsedUrl && parsedUrl.pathname)),
280
+ writeKey: config.writeKey,
279
281
  context: deepMerge(context, customContext),
280
282
  };
281
283
  delete withContext.meta;
@@ -284,6 +286,11 @@ function adjustPayload(payload: any, config: JitsuOptions, storage: PersistentSt
284
286
  }
285
287
 
286
288
  function send(method, payload, jitsuConfig: Required<JitsuOptions>, store: PersistentStorage): Promise<void> {
289
+ if (jitsuConfig.echoEvents) {
290
+ console.log(`[JITSU] sending '${method}' event:`, payload);
291
+ return;
292
+ }
293
+
287
294
  const url = `${jitsuConfig.host}/api/s/${method}`;
288
295
  const fetch = jitsuConfig.fetch || globalThis.fetch;
289
296
  if (!fetch) {
@@ -291,7 +298,7 @@ function send(method, payload, jitsuConfig: Required<JitsuOptions>, store: Persi
291
298
  "Please specify fetch function in jitsu plugin initialization, fetch isn't available in global scope"
292
299
  );
293
300
  }
294
- const authHeader = jitsuConfig.writeKey ? { Authorization: `Bearer ${jitsuConfig.writeKey}` } : {};
301
+ const authHeader = {};
295
302
  const debugHeader = jitsuConfig.debug ? { "X-Enable-Debug": "true" } : {};
296
303
 
297
304
  if (jitsuConfig.debug) {
@@ -352,8 +359,8 @@ const jitsuAnalyticsPlugin = (pluginConfig: JitsuOptions = {}): AnalyticsPlugin
352
359
  if (config.debug) {
353
360
  console.debug("Initializing Jitsu plugin with config: ", JSON.stringify(config));
354
361
  }
355
- if (!config.host) {
356
- throw new Error("Please specify host variable in jitsu plugin initialization");
362
+ if (!config.host && !config.echoEvents) {
363
+ throw new Error("Please specify host variable in jitsu plugin initialization, or set echoEvents to true");
357
364
  }
358
365
  },
359
366
  page: args => {
package/src/jitsu.ts CHANGED
@@ -11,10 +11,33 @@ type JitsuOptions = {
11
11
  * API Host. Default value: same host as script origin
12
12
  */
13
13
  host?: string;
14
+ /**
15
+ * To enable debug logging
16
+ */
14
17
  debug?: boolean;
18
+ /**
19
+ * Explicitely specify cookie domain. If not set, cookie domain will be set to top level
20
+ * of the current domain. Example: if JS lives on "app.example.com", cookie domain will be
21
+ * set to ".example.com". If it lives on "example.com", cookie domain will be set to ".example.com" too
22
+ */
15
23
  cookieDomain?: string;
24
+ /**
25
+ * Provide fetch implementation. It is required if you want to use Jitsu in NodeJS
26
+ */
16
27
  fetch?: typeof fetch;
28
+ /**
29
+ * Which runtime to use. Runtime is used for obtaining context of the event: cookes,
30
+ * url, etc. At the moment, Jitsu supports browser runtime and NodeJS runtime, but you
31
+ * can provide your own implementation.
32
+ *
33
+ * If it's not set, the runtime will be detected automatically by presense of `window` object
34
+ */
17
35
  runtime?: RuntimeFacade;
36
+ /**
37
+ * If set to true, jitsu will output events in console. In this case you don't need to set
38
+ * writeKey / host. It's useful for debugging development environment
39
+ */
40
+ echoEvents?: boolean;
18
41
  };
19
42
 
20
43
  type PersistentStorage = {