@jitsu/js 1.1.0-canary.388.20230519133920 → 1.1.0-canary.404.20230526224724

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/dist/web/p.js.txt CHANGED
@@ -111,7 +111,7 @@
111
111
  });
112
112
  }
113
113
 
114
- var __awaiter$3 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
114
+ var __awaiter$1 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
115
115
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
116
116
  return new (P || (P = Promise))(function (resolve, reject) {
117
117
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -120,10 +120,18 @@
120
120
  step((generator = generator.apply(thisArg, _arguments || [])).next());
121
121
  });
122
122
  };
123
+ function satisfyFilter(filter, subject) {
124
+ return filter === "*" || filter.toLowerCase().trim() === (subject || "").trim().toLowerCase();
125
+ }
126
+ function applyFilters(event, creds) {
127
+ const { hosts = ["*"], events = ["*"] } = creds;
128
+ return (!!hosts.find(hostFilter => { var _a; return satisfyFilter(hostFilter, (_a = event.context) === null || _a === void 0 ? void 0 : _a.host); }) &&
129
+ !!events.find(eventFilter => satisfyFilter(eventFilter, event.type)));
130
+ }
123
131
  const tagPlugin = {
124
132
  id: "tag",
125
133
  handle(config, payload) {
126
- return __awaiter$3(this, void 0, void 0, function* () {
134
+ return __awaiter$1(this, void 0, void 0, function* () {
127
135
  if (!applyFilters(payload, config)) {
128
136
  return;
129
137
  }
@@ -131,96 +139,6 @@
131
139
  });
132
140
  },
133
141
  };
134
- function insertTags(code, event, opts = {}) {
135
- let tag;
136
- try {
137
- tag = JSON.parse(code);
138
- }
139
- catch (e) {
140
- tag = { code, lang: "javascript" };
141
- }
142
- const debug = opts.debug || false;
143
- if (isInBrowser()) {
144
- if (tag.lang === "javascript") {
145
- execJs(tag.code, event);
146
- }
147
- else {
148
- const codeHolder = document.createElement("span");
149
- codeHolder.innerHTML = replaceMacro(tag.code, event);
150
- document.body.insertAdjacentElement("beforeend", codeHolder);
151
- const scripts = codeHolder.querySelectorAll("script");
152
- scripts.forEach(script => {
153
- const scriptClone = document.createElement("script");
154
- scriptClone.type = scriptClone.type || "text/javascript";
155
- if (script.hasAttribute("src")) {
156
- scriptClone.src = script.src;
157
- }
158
- scriptClone.text = script.text;
159
- if (debug) {
160
- console.log(`[JITSU] Executing script${script.hasAttribute("src") ? ` ${script.src}` : ""}`, scriptClone.text);
161
- }
162
- document.head.appendChild(scriptClone);
163
- document.head.removeChild(scriptClone);
164
- });
165
- }
166
- }
167
- else {
168
- if (debug) {
169
- console.log(`[JITSU] insertTags(): cannot insert tags in non-browser environment`);
170
- }
171
- }
172
- }
173
- function execJs(code, event) {
174
- const varName = `jitsu_event_${randomId()}`;
175
- window[varName] = event;
176
- const iif = `(function(){
177
- const event = ${varName};
178
- ${code}
179
- })()`;
180
- try {
181
- eval(iif);
182
- }
183
- catch (e) {
184
- console.error(`[JITSU] Error executing JS code: ${e.message}. Code: `, iif);
185
- }
186
- finally {
187
- delete window[varName];
188
- }
189
- return iif;
190
- }
191
- function replaceMacro(code, event) {
192
- return code.replace(/{{\s*event\s*}}/g, JSON.stringify(event));
193
- }
194
-
195
- var __awaiter$2 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
196
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
197
- return new (P || (P = Promise))(function (resolve, reject) {
198
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
199
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
200
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
201
- step((generator = generator.apply(thisArg, _arguments || [])).next());
202
- });
203
- };
204
- const logrocketPlugin = {
205
- id: "logrocket",
206
- handle(config, payload) {
207
- return __awaiter$2(this, void 0, void 0, function* () {
208
- if (!applyFilters(payload, config)) {
209
- return;
210
- }
211
- initLogrocketIfNeeded(config.appId);
212
- const action = logRocket => {
213
- if (payload.type === "identify" && payload.userId) {
214
- logRocket.identify(payload.userId, payload.traits || {});
215
- }
216
- };
217
- getLogRocketQueue().push(action);
218
- if (getLogRocketState() === "loaded") {
219
- flushLogRocketQueue(window["LogRocket"]);
220
- }
221
- });
222
- },
223
- };
224
142
  function getLogRocketState() {
225
143
  return window["__jitsuLrState"] || "fresh";
226
144
  }
@@ -246,7 +164,7 @@
246
164
  }
247
165
  }
248
166
  function initLogrocketIfNeeded(appId) {
249
- return __awaiter$2(this, void 0, void 0, function* () {
167
+ return __awaiter$1(this, void 0, void 0, function* () {
250
168
  if (getLogRocketState() !== "fresh") {
251
169
  return;
252
170
  }
@@ -271,113 +189,94 @@
271
189
  });
272
190
  });
273
191
  }
274
-
275
- var __awaiter$1 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
276
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
277
- return new (P || (P = Promise))(function (resolve, reject) {
278
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
279
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
280
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
281
- step((generator = generator.apply(thisArg, _arguments || [])).next());
282
- });
283
- };
284
- const defaultScriptSrc = "https://www.googletagmanager.com/gtag/js";
285
- const gtmPlugin = {
286
- id: "gtm",
192
+ const logrocketPlugin = {
193
+ id: "logrocket",
287
194
  handle(config, payload) {
288
195
  return __awaiter$1(this, void 0, void 0, function* () {
289
196
  if (!applyFilters(payload, config)) {
290
197
  return;
291
198
  }
292
- yield initGtmIfNeeded(config);
293
- const dataLayer = window[config.dataLayerName || "dataLayer"];
294
- switch (payload.type) {
295
- case "page":
296
- const { properties: pageProperties } = payload;
297
- const pageEvent = Object.assign({ event: "page_view" }, pageProperties);
298
- if (config.debug) {
299
- console.log("gtag push", pageEvent);
300
- }
301
- dataLayer.push(pageEvent);
302
- break;
303
- case "track":
304
- const { properties: trackProperties } = payload;
305
- const trackEvent = Object.assign({ event: payload.event }, trackProperties);
306
- if (config.debug) {
307
- console.log("gtag push", trackEvent);
308
- }
309
- dataLayer.push(trackEvent);
310
- break;
311
- case "identify":
312
- const { anonymousId, userId, traits } = payload;
313
- const user = traits;
314
- if (userId) {
315
- user.userId = userId;
316
- }
317
- if (anonymousId) {
318
- user.anonymousId = anonymousId;
319
- }
320
- const identifyEvent = { event: "identify", user: user };
321
- if (config.debug) {
322
- console.log("gtag push", identifyEvent);
323
- }
324
- dataLayer.push(identifyEvent);
325
- break;
199
+ initLogrocketIfNeeded(config.appId);
200
+ const action = logRocket => {
201
+ if (payload.type === "identify" && payload.userId) {
202
+ logRocket.identify(payload.userId, payload.traits || {});
203
+ }
204
+ };
205
+ getLogRocketQueue().push(action);
206
+ if (getLogRocketState() === "loaded") {
207
+ flushLogRocketQueue(window["LogRocket"]);
326
208
  }
327
209
  });
328
210
  },
329
211
  };
330
- function getGtmState() {
331
- return window["__jitsuGtmState"] || "fresh";
332
- }
333
- function setGtmState(s) {
334
- window["__jitsuGtmState"] = s;
335
- }
336
- function initGtmIfNeeded(config) {
337
- return __awaiter$1(this, void 0, void 0, function* () {
338
- if (getGtmState() !== "fresh") {
339
- return;
212
+ function insertTags(code, event, opts = {}) {
213
+ let tag;
214
+ try {
215
+ tag = JSON.parse(code);
216
+ }
217
+ catch (e) {
218
+ tag = { code, lang: "javascript" };
219
+ }
220
+ const debug = opts.debug || false;
221
+ if (isInBrowser()) {
222
+ if (tag.lang === "javascript") {
223
+ execJs(tag.code, event);
340
224
  }
341
- setGtmState("loading");
342
- const dlName = config.dataLayerName || "dataLayer";
343
- const dlParam = dlName !== "dataLayer" ? "&l=" + dlName : "";
344
- const previewParams = config.preview
345
- ? `&gtm_preview=${config.preview}&gtm_auth=${config.auth}&gtm_cookies_win=x`
346
- : "";
347
- const scriptSrc = `${config.customScriptSrc || defaultScriptSrc}?id=${config.containerId}${dlParam}${previewParams}`;
348
- window[dlName] = window[dlName] || [];
349
- const gtag = function () {
350
- window[dlName].push(arguments);
351
- };
352
- // @ts-ignore
353
- gtag("js", new Date());
354
- // @ts-ignore
355
- gtag("config", config.containerId);
356
- loadScript(scriptSrc)
357
- .then(() => {
358
- setGtmState("loaded");
359
- })
360
- .catch(e => {
361
- console.warn(`GTM (containerId=${config.containerId}) init failed: ${e.message}`, e);
362
- setGtmState("failed");
363
- });
364
- });
225
+ else {
226
+ const codeHolder = document.createElement("span");
227
+ codeHolder.innerHTML = replaceMacro(tag.code, event);
228
+ document.body.insertAdjacentElement("beforeend", codeHolder);
229
+ const scripts = codeHolder.querySelectorAll("script");
230
+ scripts.forEach(script => {
231
+ const scriptClone = document.createElement("script");
232
+ scriptClone.type = scriptClone.type || "text/javascript";
233
+ if (script.hasAttribute("src")) {
234
+ scriptClone.src = script.src;
235
+ }
236
+ scriptClone.text = script.text;
237
+ if (debug) {
238
+ console.log(`[JITSU] Executing script${script.hasAttribute("src") ? ` ${script.src}` : ""}`, scriptClone.text);
239
+ }
240
+ document.head.appendChild(scriptClone);
241
+ document.head.removeChild(scriptClone);
242
+ });
243
+ }
244
+ }
245
+ else {
246
+ if (debug) {
247
+ console.log(`[JITSU] insertTags(): cannot insert tags in non-browser environment`);
248
+ }
249
+ }
365
250
  }
366
-
367
- function satisfyFilter(filter, subject) {
368
- return filter === "*" || filter.toLowerCase().trim() === (subject || "").trim().toLowerCase();
251
+ function execJs(code, event) {
252
+ const varName = `jitsu_event_${randomId()}`;
253
+ window[varName] = event;
254
+ const iif = `(function(){
255
+ const event = ${varName};
256
+ ${code}
257
+ })()`;
258
+ try {
259
+ eval(iif);
260
+ }
261
+ catch (e) {
262
+ console.error(`[JITSU] Error executing JS code: ${e.message}. Code: `, iif);
263
+ }
264
+ finally {
265
+ delete window[varName];
266
+ }
267
+ return iif;
369
268
  }
370
- function applyFilters(event, creds) {
371
- const { hosts = ["*"], events = ["*"] } = creds;
372
- return (!!hosts.find(hostFilter => { var _a; return satisfyFilter(hostFilter, (_a = event.context) === null || _a === void 0 ? void 0 : _a.host); }) &&
373
- !!events.find(eventFilter => satisfyFilter(eventFilter, event.type)));
269
+ function replaceMacro(code, event) {
270
+ return code.replace(/{{\s*event\s*}}/g, JSON.stringify(event));
374
271
  }
375
272
  const internalDestinationPlugins = {
376
273
  [tagPlugin.id]: tagPlugin,
377
- [gtmPlugin.id]: gtmPlugin,
378
274
  [logrocketPlugin.id]: logrocketPlugin,
379
275
  };
380
276
 
277
+ var name = "@jitsu/js";
278
+ var version = "0.0.0";
279
+
381
280
  /* global analytics */
382
281
  var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
383
282
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
@@ -615,8 +514,8 @@
615
514
  const referrer = runtime.referrer();
616
515
  const context = {
617
516
  library: {
618
- name: "jitsu-js",
619
- version: "1.0.0",
517
+ name: name,
518
+ version: version,
620
519
  },
621
520
  userAgent: runtime.userAgent(),
622
521
  locale: runtime.language(),
@@ -634,7 +533,7 @@
634
533
  },
635
534
  campaign: parseUtms(query),
636
535
  };
637
- 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) });
536
+ const withContext = Object.assign(Object.assign({}, payload), { timestamp: new Date().toISOString(), sentAt: new Date().toISOString(), messageId: randomId(properties.path || (parsedUrl && parsedUrl.pathname)), writeKey: validateWriteKey(config.writeKey), context: deepMerge(context, customContext) });
638
537
  delete withContext.meta;
639
538
  delete withContext.options;
640
539
  return withContext;
@@ -643,12 +542,11 @@
643
542
  return __awaiter(this, void 0, void 0, function* () {
644
543
  const promises = [];
645
544
  for (const destination of destinations) {
545
+ const credentials = Object.assign(Object.assign({}, destination.credentials), destination.options);
646
546
  if (destination.deviceOptions.type === "internal-plugin") {
647
547
  const plugin = internalDestinationPlugins[destination.deviceOptions.name];
648
548
  if (plugin) {
649
549
  try {
650
- //to support old versions, where credentials were stored in root
651
- const credentials = destination.credentials || destination;
652
550
  promises.push(plugin.handle(credentials, event));
653
551
  }
654
552
  catch (e) {
@@ -668,7 +566,7 @@
668
566
  else {
669
567
  let pluginInstance;
670
568
  try {
671
- pluginInstance = (typeof plugin === "function" ? plugin : plugin.init)(destination.credentials);
569
+ pluginInstance = (typeof plugin === "function" ? plugin : plugin.init)(credentials);
672
570
  }
673
571
  catch (e) {
674
572
  console.warn(`[JITSU] Error creating plugin '${destination.deviceOptions.moduleVarName}@${destination.deviceOptions.packageCdn}' for destination '${destination.id}': ${e === null || e === void 0 ? void 0 : e.message}`, e);
@@ -696,6 +594,15 @@
696
594
  }
697
595
  });
698
596
  }
597
+ function validateWriteKey(writeKey) {
598
+ if (writeKey) {
599
+ const [, secret] = writeKey.split(":", 2);
600
+ if (!secret) {
601
+ throw new Error(`Legacy write key detected - ${writeKey}! This format doesn't work anymore, it should be 'key:secret'. Please download a new key from Jitsu UI`);
602
+ }
603
+ }
604
+ return writeKey;
605
+ }
699
606
  function send(method, payload, jitsuConfig, instance, store) {
700
607
  if (jitsuConfig.echoEvents) {
701
608
  console.log(`[JITSU] sending '${method}' event:`, payload);
@@ -711,7 +618,7 @@
711
618
  // console.log(`[JITSU] Sending event to ${url}: `, JSON.stringify(payload, null, 2));
712
619
  // }
713
620
  const adjustedPayload = adjustPayload(payload, jitsuConfig, store);
714
- const authHeader = adjustedPayload.writeKey ? { "X-Write-Key": adjustedPayload.writeKey } : {};
621
+ const authHeader = config.writeKey ? { "X-Write-Key": validateWriteKey(config.writeKey) } : {};
715
622
  return fetch(url, {
716
623
  method: "POST",
717
624
  headers: Object.assign(Object.assign({ "Content-Type": "application/json" }, authHeader), debugHeader),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jitsu/js",
3
- "version": "1.1.0-canary.388.20230519133920",
3
+ "version": "1.1.0-canary.404.20230526224724",
4
4
  "description": "",
5
5
  "author": "Jitsu Dev Team <dev@jitsu.com>",
6
6
  "main": "dist/jitsu.cjs.js",
@@ -12,7 +12,7 @@
12
12
  "license": "MIT",
13
13
  "private": false,
14
14
  "devDependencies": {
15
- "@playwright/test": "1.31.2",
15
+ "@playwright/test": "1.30.0",
16
16
  "@rollup/plugin-commonjs": "^23.0.2",
17
17
  "@rollup/plugin-json": "^5.0.1",
18
18
  "@rollup/plugin-multi-entry": "^6.0.0",
@@ -34,7 +34,7 @@
34
34
  "rollup": "^3.2.5",
35
35
  "ts-jest": "29.0.5",
36
36
  "typescript": "^4.9.5",
37
- "@jitsu/protocols": "1.1.0-canary.388.20230519133920"
37
+ "@jitsu/protocols": "1.1.0-canary.404.20230526224724"
38
38
  },
39
39
  "dependencies": {
40
40
  "analytics": "^0.8.1"
@@ -6,6 +6,7 @@ import parse from "./index";
6
6
  import { AnalyticsInstance, AnalyticsPlugin } from "analytics";
7
7
  import { loadScript } from "./script-loader";
8
8
  import { internalDestinationPlugins } from "./destination-plugins";
9
+ import { jitsuLibraryName, jitsuVersion } from "./version";
9
10
 
10
11
  const config: Required<JitsuOptions> = {
11
12
  /* Your segment writeKey */
@@ -257,8 +258,8 @@ function adjustPayload(payload: any, config: JitsuOptions, storage: PersistentSt
257
258
  const referrer = runtime.referrer();
258
259
  const context = {
259
260
  library: {
260
- name: "jitsu-js",
261
- version: "1.0.0",
261
+ name: jitsuLibraryName,
262
+ version: jitsuVersion,
262
263
  },
263
264
  userAgent: runtime.userAgent(),
264
265
  locale: runtime.language(),
@@ -281,7 +282,7 @@ function adjustPayload(payload: any, config: JitsuOptions, storage: PersistentSt
281
282
  timestamp: new Date().toISOString(),
282
283
  sentAt: new Date().toISOString(),
283
284
  messageId: randomId(properties.path || (parsedUrl && parsedUrl.pathname)),
284
- writeKey: config.writeKey,
285
+ writeKey: validateWriteKey(config.writeKey),
285
286
  context: deepMerge(context, customContext),
286
287
  };
287
288
  delete withContext.meta;
@@ -293,6 +294,7 @@ export type DestinationDescriptor = {
293
294
  id: string;
294
295
  destinationType: string;
295
296
  credentials: any;
297
+ options: any;
296
298
  deviceOptions: DeviceOptions;
297
299
  };
298
300
  export type AnalyticsPluginDescriptor = {
@@ -317,12 +319,12 @@ async function processDestinations(
317
319
  ) {
318
320
  const promises: Promise<any>[] = [];
319
321
  for (const destination of destinations) {
322
+ const credentials = { ...destination.credentials, ...destination.options };
323
+
320
324
  if (destination.deviceOptions.type === "internal-plugin") {
321
325
  const plugin = internalDestinationPlugins[destination.deviceOptions.name];
322
326
  if (plugin) {
323
327
  try {
324
- //to support old versions, where credentials were stored in root
325
- const credentials = destination.credentials || destination;
326
328
  promises.push(plugin.handle(credentials, event));
327
329
  } catch (e) {
328
330
  console.warn(
@@ -345,7 +347,7 @@ async function processDestinations(
345
347
  } else {
346
348
  let pluginInstance: any;
347
349
  try {
348
- pluginInstance = (typeof plugin === "function" ? plugin : plugin.init)(destination.credentials);
350
+ pluginInstance = (typeof plugin === "function" ? plugin : plugin.init)(credentials);
349
351
  } catch (e) {
350
352
  console.warn(
351
353
  `[JITSU] Error creating plugin '${destination.deviceOptions.moduleVarName}@${destination.deviceOptions.packageCdn}' for destination '${destination.id}': ${e?.message}`,
@@ -385,6 +387,18 @@ async function processDestinations(
385
387
  }
386
388
  }
387
389
 
390
+ function validateWriteKey(writeKey?: string): string | undefined {
391
+ if (writeKey) {
392
+ const [, secret] = writeKey.split(":", 2);
393
+ if (!secret) {
394
+ throw new Error(
395
+ `Legacy write key detected - ${writeKey}! This format doesn't work anymore, it should be 'key:secret'. Please download a new key from Jitsu UI`
396
+ );
397
+ }
398
+ }
399
+ return writeKey;
400
+ }
401
+
388
402
  function send(
389
403
  method,
390
404
  payload,
@@ -410,7 +424,7 @@ function send(
410
424
  // console.log(`[JITSU] Sending event to ${url}: `, JSON.stringify(payload, null, 2));
411
425
  // }
412
426
  const adjustedPayload = adjustPayload(payload, jitsuConfig, store);
413
- const authHeader = adjustedPayload.writeKey ? { "X-Write-Key": adjustedPayload.writeKey } : {};
427
+ const authHeader = config.writeKey ? { "X-Write-Key": validateWriteKey(config.writeKey) } : {};
414
428
  return fetch(url, {
415
429
  method: "POST",
416
430
  headers: {
@@ -25,8 +25,13 @@ export const gtmPlugin: InternalPlugin<GtmDestinationCredentials> = {
25
25
 
26
26
  switch (payload.type) {
27
27
  case "page":
28
- const { properties: pageProperties } = payload;
29
- const pageEvent = { event: "page_view", ...pageProperties };
28
+ const { properties: pageProperties, context } = payload;
29
+ const pageEvent = {
30
+ event: "page_view",
31
+ url: pageProperties.url,
32
+ title: pageProperties.title,
33
+ referer: context?.page?.referrer ?? "",
34
+ };
30
35
  if (config.debug) {
31
36
  console.log("gtag push", pageEvent);
32
37
  }
@@ -34,22 +39,27 @@ export const gtmPlugin: InternalPlugin<GtmDestinationCredentials> = {
34
39
  break;
35
40
  case "track":
36
41
  const { properties: trackProperties } = payload;
37
- const trackEvent = { event: payload.event, ...trackProperties };
42
+ const trackEvent: any = { event: payload.event, ...trackProperties };
43
+ if (payload.userId) {
44
+ trackEvent.userId = payload.userId;
45
+ }
46
+ if (payload.anonymousId) {
47
+ trackEvent.anonymousId = payload.anonymousId;
48
+ }
38
49
  if (config.debug) {
39
50
  console.log("gtag push", trackEvent);
40
51
  }
41
52
  dataLayer.push(trackEvent);
42
53
  break;
43
54
  case "identify":
44
- const { anonymousId, userId, traits } = payload;
45
- const user = traits;
46
- if (userId) {
47
- user.userId = userId;
55
+ const { traits } = payload;
56
+ const identifyEvent: any = { event: "identify", ...traits };
57
+ if (payload.userId) {
58
+ identifyEvent.userId = payload.userId;
48
59
  }
49
- if (anonymousId) {
50
- user.anonymousId = anonymousId;
60
+ if (payload.anonymousId) {
61
+ identifyEvent.anonymousId = payload.anonymousId;
51
62
  }
52
- const identifyEvent = { event: "identify", user: user };
53
63
  if (config.debug) {
54
64
  console.log("gtag push", identifyEvent);
55
65
  }
@@ -9,19 +9,34 @@ export type InternalPlugin<T> = {
9
9
  };
10
10
 
11
11
  export type CommonDestinationCredentials = {
12
- hosts?: string[];
13
- events?: string[];
12
+ hosts?: string;
13
+ events?: string;
14
14
  };
15
15
 
16
16
  export function satisfyFilter(filter: string, subject: string | undefined): boolean {
17
17
  return filter === "*" || filter.toLowerCase().trim() === (subject || "").trim().toLowerCase();
18
18
  }
19
19
 
20
+ export function satisfyDomainFilter(filter: string, subject: string | undefined): boolean {
21
+ if (filter === "*") {
22
+ return true;
23
+ }
24
+ subject = subject || "";
25
+
26
+ if (filter.startsWith("*.")) {
27
+ return subject.endsWith(filter.substring(1));
28
+ } else {
29
+ return filter === subject;
30
+ }
31
+ }
32
+
20
33
  export function applyFilters(event: AnalyticsClientEvent, creds: CommonDestinationCredentials): boolean {
21
- const { hosts = ["*"], events = ["*"] } = creds;
34
+ const { hosts = "*", events = "*" } = creds;
35
+ const eventsArray = events.split("\n");
22
36
  return (
23
- !!hosts.find(hostFilter => satisfyFilter(hostFilter, event.context?.host)) &&
24
- !!events.find(eventFilter => satisfyFilter(eventFilter, event.type))
37
+ !!hosts.split("\n").find(hostFilter => satisfyDomainFilter(hostFilter, event.context?.host)) &&
38
+ (!!eventsArray.find(eventFilter => satisfyFilter(eventFilter, event.type)) ||
39
+ !!eventsArray.find(eventFilter => satisfyFilter(eventFilter, event.event)))
25
40
  );
26
41
  }
27
42
 
package/src/version.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { name as jitsuLibraryName, version as jitsuVersion } from "../package.json";
2
+
3
+ export { jitsuVersion, jitsuLibraryName };
package/tsconfig.json CHANGED
@@ -5,6 +5,7 @@
5
5
  "declaration": true,
6
6
  "esModuleInterop": true,
7
7
  "moduleResolution": "Node",
8
+ "resolveJsonModule": true,
8
9
  "target": "ES2015",
9
10
  "lib": ["es2017", "dom"],
10
11
  //this makes typescript igore @types/node during compilation
package/.pnpm-debug.log DELETED
@@ -1,23 +0,0 @@
1
- {
2
- "0 debug pnpm:scope": {
3
- "selected": 1,
4
- "workspacePrefix": "/Users/ildarnurislamov/Projects/onetag"
5
- },
6
- "1 error pnpm": {
7
- "code": "ELIFECYCLE",
8
- "errno": "ENOENT",
9
- "syscall": "spawn",
10
- "file": "sh",
11
- "pkgid": "@jitsu/js@0.0.0",
12
- "stage": "build",
13
- "script": "tsc -p . && rollup -c && cp src/jitsu.d.ts dist",
14
- "pkgname": "@jitsu/js",
15
- "err": {
16
- "name": "pnpm",
17
- "message": "@jitsu/js@0.0.0 build: `tsc -p . && rollup -c && cp src/jitsu.d.ts dist`\nspawn ENOENT",
18
- "code": "ELIFECYCLE",
19
- "stack": "pnpm: @jitsu/js@0.0.0 build: `tsc -p . && rollup -c && cp src/jitsu.d.ts dist`\nspawn ENOENT\n at ChildProcess.<anonymous> (/opt/homebrew/lib/node_modules/pnpm/dist/pnpm.cjs:93535:22)\n at ChildProcess.emit (node:events:527:28)\n at maybeClose (node:internal/child_process:1092:16)\n at Process.ChildProcess._handle.onexit (node:internal/child_process:302:5)"
20
- }
21
- },
22
- "2 warn pnpm:global": " Local package.json exists, but node_modules missing, did you mean to install?"
23
- }