@ogcio/o11y-sdk-react 0.2.0 → 0.4.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.
@@ -0,0 +1,79 @@
1
+ import { TransportItemType } from "@grafana/faro-web-sdk";
2
+ import { beforeEach, describe, expect, it, vi } from "vitest";
3
+ import { _cleanStringPII } from "../../lib/internals/redaction/pii-detection";
4
+
5
+ // Mock faro.api.pushMeasurement
6
+ vi.mock("@grafana/faro-web-sdk", async () => {
7
+ const actual = await vi.importActual<any>("@grafana/faro-web-sdk");
8
+ return {
9
+ ...actual,
10
+ faro: {
11
+ api: {
12
+ pushMeasurement: vi.fn(),
13
+ },
14
+ },
15
+ };
16
+ });
17
+
18
+ import { faro } from "@grafana/faro-web-sdk";
19
+ import { redactors } from "../../lib/internals/redaction/redactors";
20
+
21
+ describe("_cleanStringPII", () => {
22
+ beforeEach(() => {
23
+ vi.clearAllMocks();
24
+ });
25
+
26
+ it("should redact email and call pushMeasurement", () => {
27
+ const input = "Contact me at alice@example.com.";
28
+ const result = _cleanStringPII(input, TransportItemType.LOG, [
29
+ redactors.email,
30
+ ]);
31
+
32
+ expect(result).toBe("Contact me at [REDACTED EMAIL].");
33
+ expect(faro.api.pushMeasurement).toHaveBeenCalledOnce();
34
+ expect(faro.api.pushMeasurement).toHaveBeenCalledWith(
35
+ {
36
+ type: "faro_o11y_pii_redaction",
37
+ values: { redacted: 1 },
38
+ },
39
+ {
40
+ context: {
41
+ pii_type: "email",
42
+ redaction_source: TransportItemType.LOG,
43
+ pii_email_domain: "example.com",
44
+ pii_format: "string",
45
+ },
46
+ },
47
+ );
48
+ });
49
+
50
+ it("should decode and redact URI-encoded emails", () => {
51
+ const encoded = "mailto%3Ajohn.doe%40gmail.com";
52
+ const result = _cleanStringPII(encoded, TransportItemType.EXCEPTION, [
53
+ redactors.email,
54
+ ]);
55
+
56
+ expect(result).toBe("mailto:[REDACTED EMAIL]");
57
+ expect(faro.api.pushMeasurement).toHaveBeenCalledOnce();
58
+ });
59
+
60
+ it("should return same string when no email present", () => {
61
+ const input = "Just a normal message.";
62
+ const result = _cleanStringPII(input, TransportItemType.LOG, [
63
+ redactors.email,
64
+ ]);
65
+
66
+ expect(result).toBe(input);
67
+ expect(faro.api.pushMeasurement).not.toHaveBeenCalled();
68
+ });
69
+
70
+ it("should return same string when decodeURIComponent fail", () => {
71
+ const input = "mailto%john.doe%4gmail.com";
72
+ const result = _cleanStringPII(input, TransportItemType.LOG, [
73
+ redactors.email,
74
+ ]);
75
+
76
+ expect(result).toBe(input);
77
+ expect(faro.api.pushMeasurement).not.toHaveBeenCalled();
78
+ });
79
+ });
package/vitest.config.ts CHANGED
@@ -4,7 +4,7 @@ export default defineConfig({
4
4
  test: {
5
5
  globals: true,
6
6
  watch: false,
7
- include: ["**/test/*.test.ts"],
7
+ include: ["**/*.test.ts"],
8
8
  exclude: ["**/fixtures/**", "**/dist/**"],
9
9
  poolOptions: {
10
10
  threads: {
@@ -1,28 +0,0 @@
1
- import { describe, test, expect, vi } from "vitest";
2
- import { FaroSDKConfig } from "../lib";
3
- import { instrumentFaro } from "../index";
4
-
5
- vi.mock("../lib/instrumentation.faro", () => ({
6
- default: vi.fn(),
7
- }));
8
-
9
- describe("instrumentFaro", () => {
10
- test("should call buildFaroInstrumentation with the provided config", async () => {
11
- const config: FaroSDKConfig = {
12
- serviceName: "custom-service",
13
- collectorUrl: "http://custom-collector.com",
14
- };
15
-
16
- const buildFaroInstrumentation = await import(
17
- "../lib/instrumentation.faro"
18
- );
19
-
20
- instrumentFaro(config);
21
-
22
- expect(buildFaroInstrumentation.default).toHaveBeenCalledWith(config);
23
- });
24
-
25
- test("should not throw when called without arguments", () => {
26
- expect(() => instrumentFaro()).not.toThrow();
27
- });
28
- });