@lingo.dev/_sdk 0.16.1 → 0.16.2

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/build/index.cjs CHANGED
@@ -35,10 +35,10 @@ function trackEvent(apiKey, apiUrl, event, properties) {
35
35
  );
36
36
  }
37
37
  async function resolveIdentityAndCapture(apiKey, apiUrl, event, properties) {
38
- const identityInfo = await getDistinctId(apiKey, apiUrl);
38
+ const { identity, email } = await getDistinctId(apiKey, apiUrl);
39
39
  if (process.env.DEBUG === "true") {
40
40
  console.log(
41
- `[Tracking] Event: ${event}, ID: ${identityInfo.distinct_id}, Source: ${identityInfo.distinct_id_source}`
41
+ `[Tracking] Event: ${event}, ID: ${identity.distinct_id}, Source: ${identity.distinct_id_source}`
42
42
  );
43
43
  }
44
44
  const { PostHog } = await Promise.resolve().then(() => _interopRequireWildcard(require("posthog-node")));
@@ -47,17 +47,27 @@ async function resolveIdentityAndCapture(apiKey, apiUrl, event, properties) {
47
47
  flushAt: 1,
48
48
  flushInterval: 0
49
49
  });
50
- await posthog.capture({
51
- distinctId: identityInfo.distinct_id,
52
- event,
53
- properties: {
54
- ...properties,
55
- tracking_version: TRACKING_VERSION,
56
- sdk_package: SDK_PACKAGE,
57
- distinct_id_source: identityInfo.distinct_id_source
50
+ try {
51
+ await posthog.capture({
52
+ distinctId: identity.distinct_id,
53
+ event,
54
+ properties: {
55
+ ...properties,
56
+ $set: { ..._optionalChain([properties, 'optionalAccess', _ => _.$set]) || {}, ...email ? { email } : {} },
57
+ tracking_version: TRACKING_VERSION,
58
+ sdk_package: SDK_PACKAGE,
59
+ distinct_id_source: identity.distinct_id_source
60
+ }
61
+ });
62
+ if (email) {
63
+ await posthog.alias({
64
+ distinctId: identity.distinct_id,
65
+ alias: email
66
+ });
58
67
  }
59
- });
60
- await posthog.shutdown();
68
+ } finally {
69
+ await posthog.shutdown();
70
+ }
61
71
  }
62
72
  async function getDistinctId(apiKey, apiUrl) {
63
73
  const cached = identityCache.get(apiKey);
@@ -72,24 +82,27 @@ async function getDistinctId(apiKey, apiUrl) {
72
82
  });
73
83
  if (res.ok) {
74
84
  const payload = await res.json();
75
- if (_optionalChain([payload, 'optionalAccess', _ => _.email])) {
76
- const identity2 = {
77
- distinct_id: payload.email,
78
- distinct_id_source: "email"
85
+ if (_optionalChain([payload, 'optionalAccess', _2 => _2.id])) {
86
+ const result = {
87
+ identity: {
88
+ distinct_id: payload.id,
89
+ distinct_id_source: "database_id"
90
+ },
91
+ email: payload.email || void 0
79
92
  };
80
- identityCache.set(apiKey, identity2);
81
- return identity2;
93
+ identityCache.set(apiKey, result);
94
+ return result;
82
95
  }
83
96
  }
84
97
  } catch (e) {
85
98
  }
86
99
  const hash = _crypto.createHash.call(void 0, "sha256").update(apiKey).digest("hex").slice(0, 16);
87
- const identity = {
88
- distinct_id: `apikey-${hash}`,
89
- distinct_id_source: "api_key_hash"
100
+ return {
101
+ identity: {
102
+ distinct_id: `apikey-${hash}`,
103
+ distinct_id_source: "api_key_hash"
104
+ }
90
105
  };
91
- identityCache.set(apiKey, identity);
92
- return identity;
93
106
  }
94
107
 
95
108
  // src/index.ts
@@ -128,7 +141,7 @@ var LingoDotDevEngine = (_class = class _LingoDotDevEngine {
128
141
  if (parsed && typeof parsed.message === "string") {
129
142
  return parsed.message;
130
143
  }
131
- if (_optionalChain([parsed, 'optionalAccess', _2 => _2._tag]) === "NotFoundError") {
144
+ if (_optionalChain([parsed, 'optionalAccess', _3 => _3._tag]) === "NotFoundError") {
132
145
  return `${parsed.entityType} not found: ${parsed.id}`;
133
146
  }
134
147
  return text;
@@ -562,7 +575,7 @@ var LingoDotDevEngine = (_class = class _LingoDotDevEngine {
562
575
  break;
563
576
  }
564
577
  const siblings = Array.from(parent.childNodes).filter(
565
- (n) => n.nodeType === 1 || n.nodeType === 3 && _optionalChain([n, 'access', _3 => _3.textContent, 'optionalAccess', _4 => _4.trim, 'call', _5 => _5()])
578
+ (n) => n.nodeType === 1 || n.nodeType === 3 && _optionalChain([n, 'access', _4 => _4.textContent, 'optionalAccess', _5 => _5.trim, 'call', _6 => _6()])
566
579
  );
567
580
  const index = siblings.indexOf(current);
568
581
  if (index !== -1) {
@@ -582,7 +595,7 @@ var LingoDotDevEngine = (_class = class _LingoDotDevEngine {
582
595
  parent = parent.parentElement;
583
596
  }
584
597
  if (node.nodeType === 3) {
585
- const text = _optionalChain([node, 'access', _6 => _6.textContent, 'optionalAccess', _7 => _7.trim, 'call', _8 => _8()]) || "";
598
+ const text = _optionalChain([node, 'access', _7 => _7.textContent, 'optionalAccess', _8 => _8.trim, 'call', _9 => _9()]) || "";
586
599
  if (text) {
587
600
  extractedContent[getPath(node)] = text;
588
601
  }
@@ -597,15 +610,15 @@ var LingoDotDevEngine = (_class = class _LingoDotDevEngine {
597
610
  }
598
611
  });
599
612
  Array.from(element.childNodes).filter(
600
- (n) => n.nodeType === 1 || n.nodeType === 3 && _optionalChain([n, 'access', _9 => _9.textContent, 'optionalAccess', _10 => _10.trim, 'call', _11 => _11()])
613
+ (n) => n.nodeType === 1 || n.nodeType === 3 && _optionalChain([n, 'access', _10 => _10.textContent, 'optionalAccess', _11 => _11.trim, 'call', _12 => _12()])
601
614
  ).forEach(processNode);
602
615
  }
603
616
  };
604
617
  Array.from(document.head.childNodes).filter(
605
- (n) => n.nodeType === 1 || n.nodeType === 3 && _optionalChain([n, 'access', _12 => _12.textContent, 'optionalAccess', _13 => _13.trim, 'call', _14 => _14()])
618
+ (n) => n.nodeType === 1 || n.nodeType === 3 && _optionalChain([n, 'access', _13 => _13.textContent, 'optionalAccess', _14 => _14.trim, 'call', _15 => _15()])
606
619
  ).forEach(processNode);
607
620
  Array.from(document.body.childNodes).filter(
608
- (n) => n.nodeType === 1 || n.nodeType === 3 && _optionalChain([n, 'access', _15 => _15.textContent, 'optionalAccess', _16 => _16.trim, 'call', _17 => _17()])
621
+ (n) => n.nodeType === 1 || n.nodeType === 3 && _optionalChain([n, 'access', _16 => _16.textContent, 'optionalAccess', _17 => _17.trim, 'call', _18 => _18()])
609
622
  ).forEach(processNode);
610
623
  const localizedContent = await this._localizeRaw(
611
624
  extractedContent,
@@ -621,10 +634,10 @@ var LingoDotDevEngine = (_class = class _LingoDotDevEngine {
621
634
  let current = parent;
622
635
  for (const index of indices) {
623
636
  const siblings = Array.from(parent.childNodes).filter(
624
- (n) => n.nodeType === 1 || n.nodeType === 3 && _optionalChain([n, 'access', _18 => _18.textContent, 'optionalAccess', _19 => _19.trim, 'call', _20 => _20()])
637
+ (n) => n.nodeType === 1 || n.nodeType === 3 && _optionalChain([n, 'access', _19 => _19.textContent, 'optionalAccess', _20 => _20.trim, 'call', _21 => _21()])
625
638
  );
626
639
  current = siblings[parseInt(index)] || null;
627
- if (_optionalChain([current, 'optionalAccess', _21 => _21.nodeType]) === 1) {
640
+ if (_optionalChain([current, 'optionalAccess', _22 => _22.nodeType]) === 1) {
628
641
  parent = current;
629
642
  }
630
643
  }
@@ -713,7 +726,7 @@ var LingoDotDevEngine = (_class = class _LingoDotDevEngine {
713
726
  });
714
727
  if (res.ok) {
715
728
  const payload = await res.json();
716
- if (!_optionalChain([payload, 'optionalAccess', _22 => _22.email])) {
729
+ if (!_optionalChain([payload, 'optionalAccess', _23 => _23.email])) {
717
730
  return null;
718
731
  }
719
732
  return {
package/build/index.mjs CHANGED
@@ -35,10 +35,10 @@ function trackEvent(apiKey, apiUrl, event, properties) {
35
35
  );
36
36
  }
37
37
  async function resolveIdentityAndCapture(apiKey, apiUrl, event, properties) {
38
- const identityInfo = await getDistinctId(apiKey, apiUrl);
38
+ const { identity, email } = await getDistinctId(apiKey, apiUrl);
39
39
  if (process.env.DEBUG === "true") {
40
40
  console.log(
41
- `[Tracking] Event: ${event}, ID: ${identityInfo.distinct_id}, Source: ${identityInfo.distinct_id_source}`
41
+ `[Tracking] Event: ${event}, ID: ${identity.distinct_id}, Source: ${identity.distinct_id_source}`
42
42
  );
43
43
  }
44
44
  const { PostHog } = await import("posthog-node");
@@ -47,17 +47,27 @@ async function resolveIdentityAndCapture(apiKey, apiUrl, event, properties) {
47
47
  flushAt: 1,
48
48
  flushInterval: 0
49
49
  });
50
- await posthog.capture({
51
- distinctId: identityInfo.distinct_id,
52
- event,
53
- properties: {
54
- ...properties,
55
- tracking_version: TRACKING_VERSION,
56
- sdk_package: SDK_PACKAGE,
57
- distinct_id_source: identityInfo.distinct_id_source
50
+ try {
51
+ await posthog.capture({
52
+ distinctId: identity.distinct_id,
53
+ event,
54
+ properties: {
55
+ ...properties,
56
+ $set: { ...properties?.$set || {}, ...email ? { email } : {} },
57
+ tracking_version: TRACKING_VERSION,
58
+ sdk_package: SDK_PACKAGE,
59
+ distinct_id_source: identity.distinct_id_source
60
+ }
61
+ });
62
+ if (email) {
63
+ await posthog.alias({
64
+ distinctId: identity.distinct_id,
65
+ alias: email
66
+ });
58
67
  }
59
- });
60
- await posthog.shutdown();
68
+ } finally {
69
+ await posthog.shutdown();
70
+ }
61
71
  }
62
72
  async function getDistinctId(apiKey, apiUrl) {
63
73
  const cached = identityCache.get(apiKey);
@@ -72,24 +82,27 @@ async function getDistinctId(apiKey, apiUrl) {
72
82
  });
73
83
  if (res.ok) {
74
84
  const payload = await res.json();
75
- if (payload?.email) {
76
- const identity2 = {
77
- distinct_id: payload.email,
78
- distinct_id_source: "email"
85
+ if (payload?.id) {
86
+ const result = {
87
+ identity: {
88
+ distinct_id: payload.id,
89
+ distinct_id_source: "database_id"
90
+ },
91
+ email: payload.email || void 0
79
92
  };
80
- identityCache.set(apiKey, identity2);
81
- return identity2;
93
+ identityCache.set(apiKey, result);
94
+ return result;
82
95
  }
83
96
  }
84
97
  } catch {
85
98
  }
86
99
  const hash = createHash("sha256").update(apiKey).digest("hex").slice(0, 16);
87
- const identity = {
88
- distinct_id: `apikey-${hash}`,
89
- distinct_id_source: "api_key_hash"
100
+ return {
101
+ identity: {
102
+ distinct_id: `apikey-${hash}`,
103
+ distinct_id_source: "api_key_hash"
104
+ }
90
105
  };
91
- identityCache.set(apiKey, identity);
92
- return identity;
93
106
  }
94
107
 
95
108
  // src/index.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingo.dev/_sdk",
3
- "version": "0.16.1",
3
+ "version": "0.16.2",
4
4
  "description": "Lingo.dev JS SDK",
5
5
  "private": false,
6
6
  "repository": {