@eventvisor/sdk 0.23.0 → 0.24.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eventvisor/sdk",
3
- "version": "0.23.0",
3
+ "version": "0.24.0",
4
4
  "description": "Eventvisor SDK for Node.js and the browser",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.mjs",
@@ -39,7 +39,7 @@
39
39
  },
40
40
  "license": "MIT",
41
41
  "dependencies": {
42
- "@eventvisor/types": "0.23.0"
42
+ "@eventvisor/types": "0.24.0"
43
43
  },
44
- "gitHead": "8e89c74cde2a35ab0cf76b00f964cf8e606d9b22"
44
+ "gitHead": "096858717cd056853c26ee059702dbb7c5d7c5ec"
45
45
  }
@@ -39,6 +39,9 @@ describe("SourceResolver", () => {
39
39
  destinations: {},
40
40
  effects: {
41
41
  effect1: {
42
+ on: {
43
+ event_tracked: ["event1"],
44
+ },
42
45
  state: {
43
46
  nested: {
44
47
  value: "effect1 value",
@@ -46,6 +49,9 @@ describe("SourceResolver", () => {
46
49
  },
47
50
  },
48
51
  effect2: {
52
+ on: {
53
+ event_tracked: ["event2"],
54
+ },
49
55
  state: 123,
50
56
  },
51
57
  },
@@ -165,6 +171,12 @@ describe("SourceResolver", () => {
165
171
  },
166
172
  ),
167
173
  ).toEqual(25);
174
+
175
+ expect(
176
+ await sourceResolver.resolve("payload.screen.width", {
177
+ payload: {},
178
+ }),
179
+ ).toEqual(undefined);
168
180
  });
169
181
 
170
182
  it("should resolve attributes", async () => {
@@ -27,7 +27,13 @@ export type SourceOrigin = SourcePath & {
27
27
  };
28
28
 
29
29
  function findValueAtPath(obj: any, path: string[]): any {
30
- return path.reduce((acc, part) => acc[part], obj);
30
+ return path.reduce((acc, part) => {
31
+ if (acc === null || acc === undefined) {
32
+ return undefined;
33
+ }
34
+
35
+ return acc[part];
36
+ }, obj);
31
37
  }
32
38
 
33
39
  // @TODO: redo it with a better approach
@@ -93,7 +93,7 @@ export class Transformer {
93
93
  if (transform.type === "set") {
94
94
  if ("value" in transform) {
95
95
  result = Transformer.setValueAtPath(result, target, transform.value);
96
- } else {
96
+ } else if (sourceValue !== null && sourceValue !== undefined) {
97
97
  result = Transformer.setValueAtPath(result, target, sourceValue);
98
98
  }
99
99
  }
@@ -406,6 +406,25 @@ describe("Transformer types", () => {
406
406
  lastName: "Baggins",
407
407
  });
408
408
  });
409
+
410
+ it("does not set target when resolved source is missing", async () => {
411
+ expect(
412
+ await transformer.applyAll(
413
+ {
414
+ firstName: "Bilbo",
415
+ },
416
+ [
417
+ {
418
+ type: "set",
419
+ target: "profile.lastName",
420
+ lookup: "browser.user.lastName",
421
+ },
422
+ ],
423
+ ),
424
+ ).toEqual({
425
+ firstName: "Bilbo",
426
+ });
427
+ });
409
428
  });
410
429
 
411
430
  /**