@jitsu/js 1.9.18-canary.1269.20250403142744 → 1.9.18-canary.1288.20250415192732

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 (51) hide show
  1. package/.turbo/turbo-build.log +67 -0
  2. package/.turbo/turbo-clean.log +5 -0
  3. package/.turbo/turbo-test.log +2884 -0
  4. package/__tests__/node/method-queue.test.ts +66 -0
  5. package/__tests__/node/nodejs.test.ts +306 -0
  6. package/__tests__/playwright/cases/anonymous-id-bug.html +26 -0
  7. package/__tests__/playwright/cases/basic.html +32 -0
  8. package/__tests__/playwright/cases/callbacks.html +21 -0
  9. package/__tests__/playwright/cases/cookie-names.html +22 -0
  10. package/__tests__/playwright/cases/disable-user-ids.html +23 -0
  11. package/__tests__/playwright/cases/dont-send.html +22 -0
  12. package/__tests__/playwright/cases/ip-policy.html +22 -0
  13. package/__tests__/playwright/cases/reset.html +32 -0
  14. package/__tests__/playwright/cases/segment-reference.html +64 -0
  15. package/__tests__/playwright/cases/url-bug.html +20 -0
  16. package/__tests__/playwright/integration.test.ts +640 -0
  17. package/__tests__/simple-syrup.ts +136 -0
  18. package/dist/jitsu.cjs.js +4 -8
  19. package/dist/jitsu.es.js +4 -8
  20. package/dist/web/p.js.txt +4 -8
  21. package/jest.config.js +13 -0
  22. package/package/README.md +9 -0
  23. package/package/dist/analytics-plugin.d.ts +28 -0
  24. package/package/dist/browser.d.ts +10 -0
  25. package/package/dist/index.d.ts +28 -0
  26. package/package/dist/jitsu.cjs.js +2100 -0
  27. package/package/dist/jitsu.d.ts +78 -0
  28. package/package/dist/jitsu.es.js +2090 -0
  29. package/package/dist/method-queue.d.ts +19 -0
  30. package/package/dist/script-loader.d.ts +8 -0
  31. package/package/dist/tlds.d.ts +3 -0
  32. package/package/dist/version.d.ts +3 -0
  33. package/package/dist/web/p.js.txt +2219 -0
  34. package/package/package.json +56 -0
  35. package/package.json +3 -7
  36. package/playwrite.config.ts +91 -0
  37. package/rollup.config.js +32 -0
  38. package/src/analytics-plugin.ts +989 -0
  39. package/src/browser.ts +163 -0
  40. package/src/destination-plugins/ga4.ts +138 -0
  41. package/src/destination-plugins/gtm.ts +142 -0
  42. package/src/destination-plugins/index.ts +61 -0
  43. package/src/destination-plugins/logrocket.ts +85 -0
  44. package/src/destination-plugins/tag.ts +85 -0
  45. package/src/index.ts +255 -0
  46. package/src/method-queue.ts +70 -0
  47. package/src/script-loader.ts +76 -0
  48. package/src/tlds.ts +27 -0
  49. package/src/version.ts +6 -0
  50. package/tsconfig.json +23 -0
  51. package/tsconfig.test.json +15 -0
@@ -0,0 +1,136 @@
1
+ import type { Application, RequestHandler } from "express";
2
+ import http from "http";
3
+ import https from "https";
4
+
5
+ const express = require("express");
6
+
7
+ const forge = require("node-forge");
8
+
9
+ export type SimpleSyrupOpts = {
10
+ port?: number;
11
+ https?: boolean;
12
+ handlers?: Record<string, RequestHandler>;
13
+ };
14
+
15
+ export type SimpleSyrup = {
16
+ app: Application;
17
+ server: http.Server;
18
+ port: number;
19
+ baseUrl: string;
20
+ close: () => Promise<void>;
21
+ };
22
+
23
+ function getNextAvailablePort(port: number) {
24
+ return new Promise<number>(resolve => {
25
+ const server = http.createServer();
26
+ server.on("error", () => {
27
+ resolve(getNextAvailablePort(port + 1));
28
+ });
29
+ server.on("listening", () => {
30
+ server.close(() => {
31
+ resolve(port);
32
+ });
33
+ });
34
+ server.listen(port);
35
+ });
36
+ }
37
+
38
+ function generateX509Certificate(altNames: { type: number; value: string }[]) {
39
+ const issuer = [
40
+ { name: "commonName", value: "localhost" },
41
+ { name: "organizationName", value: "ACME Corp" },
42
+ { name: "organizationalUnitName", value: "XYZ Department" },
43
+ ];
44
+ const certificateExtensions = [
45
+ { name: "basicConstraints", cA: true },
46
+ {
47
+ name: "keyUsage",
48
+ keyCertSign: true,
49
+ digitalSignature: true,
50
+ nonRepudiation: true,
51
+ keyEncipherment: true,
52
+ dataEncipherment: true,
53
+ },
54
+ {
55
+ name: "extKeyUsage",
56
+ serverAuth: true,
57
+ clientAuth: true,
58
+ codeSigning: true,
59
+ emailProtection: true,
60
+ timeStamping: true,
61
+ },
62
+ {
63
+ name: "nsCertType",
64
+ client: true,
65
+ server: true,
66
+ email: true,
67
+ objsign: true,
68
+ sslCA: true,
69
+ emailCA: true,
70
+ objCA: true,
71
+ },
72
+ { name: "subjectAltName", altNames },
73
+ { name: "subjectKeyIdentifier" },
74
+ ];
75
+ const keys = forge.pki.rsa.generateKeyPair(2048);
76
+ const cert = forge.pki.createCertificate();
77
+ cert.validity.notBefore = new Date();
78
+ cert.validity.notAfter = new Date();
79
+ cert.validity.notAfter.setFullYear(cert.validity.notBefore.getFullYear() + 1);
80
+ cert.publicKey = keys.publicKey;
81
+ cert.setSubject(issuer);
82
+ cert.setIssuer(issuer);
83
+ cert.setExtensions(certificateExtensions);
84
+ cert.sign(keys.privateKey);
85
+ return {
86
+ key: forge.pki.privateKeyToPem(keys.privateKey),
87
+ cert: forge.pki.certificateToPem(cert),
88
+ };
89
+ }
90
+
91
+ function shutdownFunction(server): Promise<void> {
92
+ return new Promise<void>(resolve => {
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);
102
+ });
103
+ }
104
+
105
+ export function createServer(opts: SimpleSyrupOpts = {}): Promise<SimpleSyrup> {
106
+ return new Promise<SimpleSyrup>(async (resolve, reject) => {
107
+ const app: Application = express();
108
+ app.use(express.json());
109
+ const server = opts?.https ? https.createServer(generateX509Certificate([]), app) : http.createServer(app);
110
+ const port = opts?.port ? await getNextAvailablePort(opts.port) : 0;
111
+ server.listen(port, () => {
112
+ const address = server.address();
113
+ if (!address) {
114
+ reject(new Error(`Unable to get server address`));
115
+ return;
116
+ }
117
+ if (typeof address === "string") {
118
+ reject(new Error(`Address is not an of network. This is not supported: ${address} `));
119
+ return;
120
+ }
121
+ const port = address.port;
122
+ if (opts?.handlers) {
123
+ for (const [path, handler] of Object.entries(opts?.handlers)) {
124
+ app.all(path, handler);
125
+ }
126
+ }
127
+ resolve({
128
+ app: app,
129
+ port,
130
+ close: () => shutdownFunction(server),
131
+ baseUrl: `${opts.https ? "https" : "http"}://localhost:${port}`,
132
+ server: server,
133
+ });
134
+ });
135
+ });
136
+ }
package/dist/jitsu.cjs.js CHANGED
@@ -1462,7 +1462,6 @@ function adjustPayload(payload, config, storage, s2s) {
1462
1462
  userAgent: runtime.userAgent(),
1463
1463
  locale: runtime.language(),
1464
1464
  screen: runtime.screen(),
1465
- ip: runtime.ip ? runtime.ip() : undefined,
1466
1465
  traits: payload.type != "identify" && payload.type != "group" ? Object.assign({}, (restoreTraits(storage) || {})) : undefined,
1467
1466
  page: {
1468
1467
  path: properties.path || (parsedUrl && parsedUrl.pathname),
@@ -1609,22 +1608,19 @@ function getErrorHandler(opts) {
1609
1608
  function send(method, payload, jitsuConfig, instance, store) {
1610
1609
  return __awaiter$1(this, void 0, void 0, function* () {
1611
1610
  var _a, _b;
1611
+ const s2s = !!jitsuConfig.s2s;
1612
+ const debugHeader = jitsuConfig.debug ? { "X-Enable-Debug": "true" } : {};
1613
+ const adjustedPayload = adjustPayload(payload, jitsuConfig, store);
1612
1614
  if (jitsuConfig.echoEvents) {
1613
- console.log(`[JITSU DEBUG] sending '${method}' event:`, payload);
1615
+ console.log(`[JITSU DEBUG] sending '${method}' event:`, adjustedPayload);
1614
1616
  return;
1615
1617
  }
1616
- const s2s = !!jitsuConfig.s2s;
1617
1618
  const url = s2s ? `${jitsuConfig.host}/api/s/s2s/${method}` : `${jitsuConfig.host}/api/s/${method}`;
1618
1619
  const fetch = jitsuConfig.fetch || globalThis.fetch;
1619
1620
  if (!fetch) {
1620
1621
  //don't run it through error handler since error is critical and should be addressed
1621
1622
  throw new Error("Please specify fetch function in jitsu plugin initialization, fetch isn't available in global scope");
1622
1623
  }
1623
- const debugHeader = jitsuConfig.debug ? { "X-Enable-Debug": "true" } : {};
1624
- // if (jitsuConfig.debug) {
1625
- // console.log(`[JITSU] Sending event to ${url}: `, JSON.stringify(payload, null, 2));
1626
- // }
1627
- const adjustedPayload = adjustPayload(payload, jitsuConfig, store);
1628
1624
  const abortController = jitsuConfig.fetchTimeoutMs ? new AbortController() : undefined;
1629
1625
  const abortTimeout = jitsuConfig.fetchTimeoutMs
1630
1626
  ? setTimeout(() => {
package/dist/jitsu.es.js CHANGED
@@ -1460,7 +1460,6 @@ function adjustPayload(payload, config, storage, s2s) {
1460
1460
  userAgent: runtime.userAgent(),
1461
1461
  locale: runtime.language(),
1462
1462
  screen: runtime.screen(),
1463
- ip: runtime.ip ? runtime.ip() : undefined,
1464
1463
  traits: payload.type != "identify" && payload.type != "group" ? Object.assign({}, (restoreTraits(storage) || {})) : undefined,
1465
1464
  page: {
1466
1465
  path: properties.path || (parsedUrl && parsedUrl.pathname),
@@ -1607,22 +1606,19 @@ function getErrorHandler(opts) {
1607
1606
  function send(method, payload, jitsuConfig, instance, store) {
1608
1607
  return __awaiter$1(this, void 0, void 0, function* () {
1609
1608
  var _a, _b;
1609
+ const s2s = !!jitsuConfig.s2s;
1610
+ const debugHeader = jitsuConfig.debug ? { "X-Enable-Debug": "true" } : {};
1611
+ const adjustedPayload = adjustPayload(payload, jitsuConfig, store);
1610
1612
  if (jitsuConfig.echoEvents) {
1611
- console.log(`[JITSU DEBUG] sending '${method}' event:`, payload);
1613
+ console.log(`[JITSU DEBUG] sending '${method}' event:`, adjustedPayload);
1612
1614
  return;
1613
1615
  }
1614
- const s2s = !!jitsuConfig.s2s;
1615
1616
  const url = s2s ? `${jitsuConfig.host}/api/s/s2s/${method}` : `${jitsuConfig.host}/api/s/${method}`;
1616
1617
  const fetch = jitsuConfig.fetch || globalThis.fetch;
1617
1618
  if (!fetch) {
1618
1619
  //don't run it through error handler since error is critical and should be addressed
1619
1620
  throw new Error("Please specify fetch function in jitsu plugin initialization, fetch isn't available in global scope");
1620
1621
  }
1621
- const debugHeader = jitsuConfig.debug ? { "X-Enable-Debug": "true" } : {};
1622
- // if (jitsuConfig.debug) {
1623
- // console.log(`[JITSU] Sending event to ${url}: `, JSON.stringify(payload, null, 2));
1624
- // }
1625
- const adjustedPayload = adjustPayload(payload, jitsuConfig, store);
1626
1622
  const abortController = jitsuConfig.fetchTimeoutMs ? new AbortController() : undefined;
1627
1623
  const abortTimeout = jitsuConfig.fetchTimeoutMs
1628
1624
  ? setTimeout(() => {
package/dist/web/p.js.txt CHANGED
@@ -1463,7 +1463,6 @@
1463
1463
  userAgent: runtime.userAgent(),
1464
1464
  locale: runtime.language(),
1465
1465
  screen: runtime.screen(),
1466
- ip: runtime.ip ? runtime.ip() : undefined,
1467
1466
  traits: payload.type != "identify" && payload.type != "group" ? Object.assign({}, (restoreTraits(storage) || {})) : undefined,
1468
1467
  page: {
1469
1468
  path: properties.path || (parsedUrl && parsedUrl.pathname),
@@ -1610,22 +1609,19 @@
1610
1609
  function send(method, payload, jitsuConfig, instance, store) {
1611
1610
  return __awaiter$1(this, void 0, void 0, function* () {
1612
1611
  var _a, _b;
1612
+ const s2s = !!jitsuConfig.s2s;
1613
+ const debugHeader = jitsuConfig.debug ? { "X-Enable-Debug": "true" } : {};
1614
+ const adjustedPayload = adjustPayload(payload, jitsuConfig, store);
1613
1615
  if (jitsuConfig.echoEvents) {
1614
- console.log(`[JITSU DEBUG] sending '${method}' event:`, payload);
1616
+ console.log(`[JITSU DEBUG] sending '${method}' event:`, adjustedPayload);
1615
1617
  return;
1616
1618
  }
1617
- const s2s = !!jitsuConfig.s2s;
1618
1619
  const url = s2s ? `${jitsuConfig.host}/api/s/s2s/${method}` : `${jitsuConfig.host}/api/s/${method}`;
1619
1620
  const fetch = jitsuConfig.fetch || globalThis.fetch;
1620
1621
  if (!fetch) {
1621
1622
  //don't run it through error handler since error is critical and should be addressed
1622
1623
  throw new Error("Please specify fetch function in jitsu plugin initialization, fetch isn't available in global scope");
1623
1624
  }
1624
- const debugHeader = jitsuConfig.debug ? { "X-Enable-Debug": "true" } : {};
1625
- // if (jitsuConfig.debug) {
1626
- // console.log(`[JITSU] Sending event to ${url}: `, JSON.stringify(payload, null, 2));
1627
- // }
1628
- const adjustedPayload = adjustPayload(payload, jitsuConfig, store);
1629
1625
  const abortController = jitsuConfig.fetchTimeoutMs ? new AbortController() : undefined;
1630
1626
  const abortTimeout = jitsuConfig.fetchTimeoutMs
1631
1627
  ? setTimeout(() => {
package/jest.config.js ADDED
@@ -0,0 +1,13 @@
1
+ /** @type {import("ts-jest").JestConfigWithTsJest} */
2
+ module.exports = {
3
+ //preset: "ts-jest",
4
+ preset: "ts-jest",
5
+ testEnvironment: "node",
6
+ runner: "jest-runner",
7
+ rootDir: "./__tests__/node/",
8
+ globals: {
9
+ 'ts-jest': {
10
+ tsConfig: 'tsconfig.test.json'
11
+ }
12
+ }
13
+ };
@@ -0,0 +1,9 @@
1
+ ## Install
2
+
3
+ ```bash
4
+ npm install --save @jitsu/jitsu-js
5
+ ```
6
+
7
+ ## Usage
8
+
9
+ **Please read a documentation on [Jitsu Docs](https://docs.jitsu.com/sending-data/npm)**
@@ -0,0 +1,28 @@
1
+ import { JitsuOptions, PersistentStorage, RuntimeFacade } from "@jitsu/protocols/analytics";
2
+ import { AnalyticsPlugin } from "analytics";
3
+ export declare const parseQuery: (qs?: string) => Record<string, string>;
4
+ export type StorageFactory = (cookieDomain: string, key2Cookie: (key: string) => string) => PersistentStorage;
5
+ export declare function windowRuntime(opts: JitsuOptions): RuntimeFacade;
6
+ export declare const emptyRuntime: (config: JitsuOptions) => RuntimeFacade;
7
+ export declare function isInBrowser(): boolean;
8
+ export type DestinationDescriptor = {
9
+ id: string;
10
+ destinationType: string;
11
+ credentials: any;
12
+ options: any;
13
+ newEvents?: any[];
14
+ deviceOptions: DeviceOptions;
15
+ };
16
+ export type AnalyticsPluginDescriptor = {
17
+ type: "analytics-plugin";
18
+ packageCdn: string;
19
+ moduleVarName: string;
20
+ };
21
+ export type InternalPluginDescriptor = {
22
+ type: "internal-plugin";
23
+ name: string;
24
+ };
25
+ export type DeviceOptions = AnalyticsPluginDescriptor | InternalPluginDescriptor;
26
+ export declare const jitsuAnalyticsPlugin: (jitsuOptions: JitsuOptions, storage: PersistentStorage) => AnalyticsPlugin;
27
+ export declare function randomId(hashString?: string | undefined): string;
28
+ export declare function uuid(): string;
@@ -0,0 +1,10 @@
1
+ import type { JitsuOptions } from "@jitsu/protocols/analytics";
2
+ export type JitsuBrowserOptions = {
3
+ namespace?: string;
4
+ onload?: string;
5
+ initOnly?: boolean;
6
+ } & JitsuOptions;
7
+ export type Parser = {
8
+ path?: (name: string) => string[];
9
+ parse: (arg: string) => any;
10
+ };
@@ -0,0 +1,28 @@
1
+ import {
2
+ Callback,
3
+ DispatchedEvent,
4
+ ID,
5
+ JSONObject,
6
+ Options,
7
+ AnalyticsInterface,
8
+ JitsuOptions,
9
+ PersistentStorage,
10
+ RuntimeFacade,
11
+ DynamicJitsuOptions,
12
+ } from "@jitsu/protocols/analytics";
13
+ export default function parse(input: any): any;
14
+ export declare const emptyAnalytics: AnalyticsInterface;
15
+ export declare function jitsuAnalytics(_opts: JitsuOptions): AnalyticsInterface;
16
+ export {
17
+ Callback,
18
+ DispatchedEvent,
19
+ ID,
20
+ JSONObject,
21
+ Options,
22
+ AnalyticsInterface,
23
+ JitsuOptions,
24
+ PersistentStorage,
25
+ RuntimeFacade,
26
+ DynamicJitsuOptions,
27
+ };
28
+ export * from "./analytics-plugin";