node-avo-inspector 1.2.0 → 2.0.0-beta.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.
Files changed (132) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/README.md +270 -4
  3. package/dist/AvoBatchQueue.d.ts +73 -0
  4. package/dist/AvoBatchQueue.js +239 -0
  5. package/dist/AvoDeduplicator.d.ts +15 -6
  6. package/dist/AvoDeduplicator.js +46 -24
  7. package/dist/AvoInspector.d.ts +136 -23
  8. package/dist/AvoInspector.js +777 -109
  9. package/dist/AvoInspectorVersion.d.ts +3 -0
  10. package/dist/AvoInspectorVersion.js +10 -0
  11. package/dist/AvoLog.d.ts +52 -0
  12. package/dist/AvoLog.js +246 -0
  13. package/dist/AvoNetworkCallsHandler.d.ts +55 -8
  14. package/dist/AvoNetworkCallsHandler.js +266 -92
  15. package/dist/AvoSchemaParser.d.ts +6 -0
  16. package/dist/AvoSchemaParser.js +138 -33
  17. package/dist/AvoStreamId.d.ts +2 -1
  18. package/dist/AvoStreamId.js +21 -2
  19. package/dist/eventSpec/AvoEventSpecCache.d.ts +28 -5
  20. package/dist/eventSpec/AvoEventSpecCache.js +66 -11
  21. package/dist/eventSpec/AvoEventSpecFetchTypes.d.ts +50 -18
  22. package/dist/eventSpec/AvoEventSpecFetcher.d.ts +29 -6
  23. package/dist/eventSpec/AvoEventSpecFetcher.js +279 -69
  24. package/dist/eventSpec/EventValidator.d.ts +16 -10
  25. package/dist/eventSpec/EventValidator.js +351 -38
  26. package/dist/index.d.ts +2 -0
  27. package/dist/index.js +4 -1
  28. package/dist/utils.d.ts +29 -1
  29. package/dist/utils.js +86 -10
  30. package/package.json +18 -1
  31. package/.claude/scheduled_tasks.lock +0 -1
  32. package/.claude/settings.local.json +0 -11
  33. package/.claude/worktrees/release-1.1.1/LICENSE +0 -21
  34. package/.claude/worktrees/release-1.1.1/README.md +0 -69
  35. package/.claude/worktrees/release-1.1.1/examples/node-inspector-js/index.js +0 -30
  36. package/.claude/worktrees/release-1.1.1/examples/node-inspector-js/package.json +0 -15
  37. package/.claude/worktrees/release-1.1.1/examples/node-inspector-js/yarn.lock +0 -6
  38. package/.claude/worktrees/release-1.1.1/examples/node-inspector-ts/dist/index.js +0 -34
  39. package/.claude/worktrees/release-1.1.1/examples/node-inspector-ts/index.ts +0 -30
  40. package/.claude/worktrees/release-1.1.1/examples/node-inspector-ts/package.json +0 -18
  41. package/.claude/worktrees/release-1.1.1/examples/node-inspector-ts/tsconfig.json +0 -15
  42. package/.claude/worktrees/release-1.1.1/examples/node-inspector-ts/yarn.lock +0 -11
  43. package/.claude/worktrees/release-1.1.1/package-lock.json +0 -4039
  44. package/.claude/worktrees/release-1.1.1/package.json +0 -48
  45. package/.claude/worktrees/release-1.1.1/reason/AvoInspector.rei +0 -11
  46. package/.claude/worktrees/release-1.1.1/reason/NodeAvoInspector.re +0 -27
  47. package/.claude/worktrees/release-1.1.1/src/AvoDeduplicator.ts +0 -146
  48. package/.claude/worktrees/release-1.1.1/src/AvoEncryption.ts +0 -90
  49. package/.claude/worktrees/release-1.1.1/src/AvoGuid.ts +0 -9
  50. package/.claude/worktrees/release-1.1.1/src/AvoInspector.ts +0 -383
  51. package/.claude/worktrees/release-1.1.1/src/AvoInspectorEnv.ts +0 -8
  52. package/.claude/worktrees/release-1.1.1/src/AvoNetworkCallsHandler.ts +0 -267
  53. package/.claude/worktrees/release-1.1.1/src/AvoSchemaParser.ts +0 -115
  54. package/.claude/worktrees/release-1.1.1/src/AvoStreamId.ts +0 -16
  55. package/.claude/worktrees/release-1.1.1/src/__tests__/TestAvoEncryption.ts +0 -515
  56. package/.claude/worktrees/release-1.1.1/src/__tests__/TestAvoEventSpecCache.ts +0 -242
  57. package/.claude/worktrees/release-1.1.1/src/__tests__/TestAvoEventSpecFetcher.ts +0 -241
  58. package/.claude/worktrees/release-1.1.1/src/__tests__/TestAvoInspector.ts +0 -360
  59. package/.claude/worktrees/release-1.1.1/src/__tests__/TestAvoStreamId.ts +0 -72
  60. package/.claude/worktrees/release-1.1.1/src/__tests__/TestDeduplicator.ts +0 -191
  61. package/.claude/worktrees/release-1.1.1/src/__tests__/TestEventValidator.ts +0 -231
  62. package/.claude/worktrees/release-1.1.1/src/__tests__/TestNetworkCallsHandler.ts +0 -179
  63. package/.claude/worktrees/release-1.1.1/src/__tests__/TestNetworkCallsHandlerPublic.ts +0 -208
  64. package/.claude/worktrees/release-1.1.1/src/__tests__/TestParsing.ts +0 -153
  65. package/.claude/worktrees/release-1.1.1/src/__tests__/constants.ts +0 -63
  66. package/.claude/worktrees/release-1.1.1/src/eventSpec/AvoEventSpecCache.ts +0 -109
  67. package/.claude/worktrees/release-1.1.1/src/eventSpec/AvoEventSpecFetchTypes.ts +0 -47
  68. package/.claude/worktrees/release-1.1.1/src/eventSpec/AvoEventSpecFetcher.ts +0 -106
  69. package/.claude/worktrees/release-1.1.1/src/eventSpec/EventValidator.ts +0 -74
  70. package/.claude/worktrees/release-1.1.1/src/index.ts +0 -2
  71. package/.claude/worktrees/release-1.1.1/src/utils.ts +0 -49
  72. package/.claude/worktrees/release-1.1.1/tsconfig.json +0 -13
  73. package/.claude/worktrees/release-1.1.1/yarn.lock +0 -2310
  74. package/.github/workflows/claude.yml +0 -55
  75. package/dist/__tests__/TestAvoEncryption.d.ts +0 -1
  76. package/dist/__tests__/TestAvoEncryption.js +0 -288
  77. package/dist/__tests__/TestAvoEventSpecCache.d.ts +0 -1
  78. package/dist/__tests__/TestAvoEventSpecCache.js +0 -194
  79. package/dist/__tests__/TestAvoEventSpecFetcher.d.ts +0 -1
  80. package/dist/__tests__/TestAvoEventSpecFetcher.js +0 -219
  81. package/dist/__tests__/TestAvoInspector.d.ts +0 -1
  82. package/dist/__tests__/TestAvoInspector.js +0 -291
  83. package/dist/__tests__/TestAvoStreamId.d.ts +0 -1
  84. package/dist/__tests__/TestAvoStreamId.js +0 -55
  85. package/dist/__tests__/TestDeduplicator.d.ts +0 -1
  86. package/dist/__tests__/TestDeduplicator.js +0 -102
  87. package/dist/__tests__/TestEventValidator.d.ts +0 -1
  88. package/dist/__tests__/TestEventValidator.js +0 -196
  89. package/dist/__tests__/TestNetworkCallsHandler.d.ts +0 -1
  90. package/dist/__tests__/TestNetworkCallsHandler.js +0 -86
  91. package/dist/__tests__/TestNetworkCallsHandlerPublic.d.ts +0 -1
  92. package/dist/__tests__/TestNetworkCallsHandlerPublic.js +0 -160
  93. package/dist/__tests__/TestParsing.d.ts +0 -1
  94. package/dist/__tests__/TestParsing.js +0 -128
  95. package/dist/__tests__/constants.d.ts +0 -42
  96. package/dist/__tests__/constants.js +0 -53
  97. package/examples/node-inspector-js/index.js +0 -30
  98. package/examples/node-inspector-js/package.json +0 -15
  99. package/examples/node-inspector-js/yarn.lock +0 -6
  100. package/examples/node-inspector-ts/dist/index.js +0 -34
  101. package/examples/node-inspector-ts/index.ts +0 -30
  102. package/examples/node-inspector-ts/package.json +0 -18
  103. package/examples/node-inspector-ts/tsconfig.json +0 -15
  104. package/examples/node-inspector-ts/yarn.lock +0 -11
  105. package/reason/AvoInspector.rei +0 -11
  106. package/reason/NodeAvoInspector.re +0 -27
  107. package/src/AvoDeduplicator.ts +0 -150
  108. package/src/AvoEncryption.ts +0 -90
  109. package/src/AvoGuid.ts +0 -9
  110. package/src/AvoInspector.ts +0 -498
  111. package/src/AvoInspectorEnv.ts +0 -8
  112. package/src/AvoNetworkCallsHandler.ts +0 -340
  113. package/src/AvoSchemaParser.ts +0 -115
  114. package/src/AvoStreamId.ts +0 -16
  115. package/src/__tests__/TestAvoEncryption.ts +0 -515
  116. package/src/__tests__/TestAvoEventSpecCache.ts +0 -242
  117. package/src/__tests__/TestAvoEventSpecFetcher.ts +0 -279
  118. package/src/__tests__/TestAvoInspector.ts +0 -376
  119. package/src/__tests__/TestAvoStreamId.ts +0 -72
  120. package/src/__tests__/TestDeduplicator.ts +0 -191
  121. package/src/__tests__/TestEventValidator.ts +0 -231
  122. package/src/__tests__/TestNetworkCallsHandler.ts +0 -181
  123. package/src/__tests__/TestNetworkCallsHandlerPublic.ts +0 -208
  124. package/src/__tests__/TestParsing.ts +0 -153
  125. package/src/__tests__/constants.ts +0 -63
  126. package/src/eventSpec/AvoEventSpecCache.ts +0 -119
  127. package/src/eventSpec/AvoEventSpecFetchTypes.ts +0 -47
  128. package/src/eventSpec/AvoEventSpecFetcher.ts +0 -186
  129. package/src/eventSpec/EventValidator.ts +0 -74
  130. package/src/index.ts +0 -2
  131. package/src/utils.ts +0 -49
  132. package/tsconfig.json +0 -13
@@ -1,53 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.trackingEndpoint = exports.type = exports.sessionTimeMs = exports.requestMsg = exports.networkCallType = exports.mockedReturns = exports.error = exports.defaultOptions = void 0;
4
- const AvoInspectorEnv_1 = require("../AvoInspectorEnv");
5
- const defaultOptions = {
6
- apiKey: "api-key-xxx",
7
- env: AvoInspectorEnv_1.AvoInspectorEnv.Dev,
8
- version: "1",
9
- shouldLog: true,
10
- appName: "my-test-app",
11
- };
12
- exports.defaultOptions = defaultOptions;
13
- const error = {
14
- API_KEY: "[Avo Inspector] No API key provided. Inspector can't operate without API key.",
15
- VERSION: "[Avo Inspector] No version provided. Many features of Inspector rely on versioning. Please provide comparable string version, i.e. integer or semantic.",
16
- };
17
- exports.error = error;
18
- const mockedReturns = {
19
- INSTALLATION_ID: "avo-instalation-id",
20
- GUID: "generated-guid",
21
- SESSION_ID: "session-id",
22
- };
23
- exports.mockedReturns = mockedReturns;
24
- const networkCallType = {
25
- EVENT: "event",
26
- SESSION_STARTED: "sessionStarted",
27
- };
28
- exports.networkCallType = networkCallType;
29
- const requestMsg = {
30
- ERROR: "Request failed",
31
- TIMEOUT: "Request timed out",
32
- };
33
- exports.requestMsg = requestMsg;
34
- const trackingEndpoint = "https://api.avo.app/inspector/v1/track";
35
- exports.trackingEndpoint = trackingEndpoint;
36
- const sessionTimeMs = 5 * 60 * 1000;
37
- exports.sessionTimeMs = sessionTimeMs;
38
- const type = {
39
- STRING: "string",
40
- STRINGLIST: "list(string)",
41
- INT: "int",
42
- INTLIST: "list(int)",
43
- OBJECT: "object",
44
- OBJECTLIST: "list(object)",
45
- FLOAT: "float",
46
- FLOATLIST: "list(float)",
47
- BOOL: "boolean",
48
- BOOLLIST: "list(boolean)",
49
- NULL: "null",
50
- UNKNOWN: "unknown",
51
- UNKNOWNLIST: "list(unknown)",
52
- };
53
- exports.type = type;
@@ -1,30 +0,0 @@
1
- const Inspector = require("node-avo-inspector");
2
-
3
- const inspector = new Inspector.AvoInspector({
4
- apiKey: "My Api Key",
5
- env: Inspector.AvoInspectorEnv.Prod,
6
- version: "1.0.0",
7
- appName: "My App"
8
- });
9
-
10
- let eventName = "App Launched";
11
- let eventParams = {
12
- "userId": "odsbet455d",
13
- "isAdmin": true,
14
- "answer": 42,
15
- "pi": 3.14,
16
- "void": null,
17
- "shoppingList": ["Bread", "Butter", "Salt"],
18
- "birthdayGift": {
19
- "name": "pool",
20
- "radius": 7,
21
- "depth": 2.1
22
- }
23
- }
24
-
25
- inspector.enableLogging(true) // default is true for dev and false for prod
26
-
27
- inspector.trackSchemaFromEvent(eventName, eventParams).then((eventSchema) => {
28
- console.log("Event schema sent to Avo Inspector", eventSchema)
29
- })
30
-
@@ -1,15 +0,0 @@
1
- {
2
- "name": "node-inspector-js-example",
3
- "version": "1.0.0",
4
- "description": "example app for avo inspector on node",
5
- "main": "index.js",
6
- "private": true,
7
- "scripts": {
8
- "test": "echo \"Error: no test specified\" && exit 1"
9
- },
10
- "author": "Avo (https://www.avo.app)",
11
- "license": "MIT",
12
- "dependencies": {
13
- "node-avo-inspector": "file:../../"
14
- }
15
- }
@@ -1,6 +0,0 @@
1
- # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2
- # yarn lockfile v1
3
-
4
-
5
- "node-avo-inspector@file:../..":
6
- version "1.0.4-beta.0"
@@ -1,34 +0,0 @@
1
- "use strict";
2
- var __importStar = (this && this.__importStar) || function (mod) {
3
- if (mod && mod.__esModule) return mod;
4
- var result = {};
5
- if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
6
- result["default"] = mod;
7
- return result;
8
- };
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- const Inspector = __importStar(require("node-avo-inspector"));
11
- const inspector = new Inspector.AvoInspector({
12
- apiKey: "My Api Key",
13
- env: Inspector.AvoInspectorEnv.Prod,
14
- version: "1.0.0",
15
- appName: "My App"
16
- });
17
- let eventName = "App Launched";
18
- let eventParams = {
19
- "userId": "odsbet455d",
20
- "isAdmin": true,
21
- "answer": 42,
22
- "pi": 3.14,
23
- "void": null,
24
- "shoppingList": ["Bread", "Butter", "Salt"],
25
- "birthdayGift": {
26
- "name": "pool",
27
- "radius": 7,
28
- "depth": 2.1
29
- }
30
- };
31
- inspector.enableLogging(true); // default is true for dev and false for prod
32
- inspector.trackSchemaFromEvent(eventName, eventParams).then((eventSchema) => {
33
- console.log("Event schema sent to Avo Inspector", eventSchema);
34
- });
@@ -1,30 +0,0 @@
1
- import * as Inspector from "node-avo-inspector";
2
-
3
- const inspector = new Inspector.AvoInspector({
4
- apiKey: "My Api Key",
5
- env: Inspector.AvoInspectorEnv.Prod,
6
- version: "1.0.0",
7
- appName: "My App"
8
- });
9
-
10
- let eventName = "App Launched";
11
- let eventParams = {
12
- "userId": "odsbet455d",
13
- "isAdmin": true,
14
- "answer": 42,
15
- "pi": 3.14,
16
- "void": null,
17
- "shoppingList": ["Bread", "Butter", "Salt"],
18
- "birthdayGift": {
19
- "name": "pool",
20
- "radius": 7,
21
- "depth": 2.1
22
- }
23
- }
24
-
25
- inspector.enableLogging(true) // default is true for dev and false for prod
26
-
27
- inspector.trackSchemaFromEvent(eventName, eventParams).then((eventSchema) => {
28
- console.log("Event schema sent to Avo Inspector", eventSchema)
29
- })
30
-
@@ -1,18 +0,0 @@
1
- {
2
- "name": "node-inspector-ts-example",
3
- "version": "1.0.0",
4
- "description": "example app for avo inspector on node",
5
- "main": "index.ts",
6
- "private": true,
7
- "scripts": {
8
- "test": "echo \"Error: no test specified\" && exit 1"
9
- },
10
- "author": "Avo (https://www.avo.app)",
11
- "license": "MIT",
12
- "dependencies": {
13
- "node-avo-inspector": "file:../../"
14
- },
15
- "devDependencies": {
16
- "typescript": "^4.1.2"
17
- }
18
- }
@@ -1,15 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2015",
4
- "module": "commonjs",
5
- "lib": [
6
- "ES6"
7
- ],
8
- "outDir": "./dist",
9
- "strict": true,
10
- "esModuleInterop": true,
11
- "skipLibCheck": true,
12
- "forceConsistentCasingInFileNames": true
13
- }
14
- }
15
-
@@ -1,11 +0,0 @@
1
- # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2
- # yarn lockfile v1
3
-
4
-
5
- "node-avo-inspector@file:../..":
6
- version "0.1.0"
7
-
8
- typescript@^4.1.2:
9
- version "4.1.2"
10
- resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.1.2.tgz#6369ef22516fe5e10304aae5a5c4862db55380e9"
11
- integrity sha512-thGloWsGH3SOxv1SoY7QojKi0tc+8FnOmiarEGMbd/lar7QOEd3hvlx3Fp5y6FlDUGl9L+pd4n2e+oToGMmhRQ==
@@ -1,11 +0,0 @@
1
- type t;
2
-
3
- type env = [
4
- | `Dev
5
- | `Staging
6
- | `Prod
7
- ];
8
-
9
- let make: (~apiKey: string, ~env: env, ~version: string, , ~appName: string, unit) => t;
10
-
11
- let trackSchemaFromEvent: t => string => Js.Json.t => Js.Promise.t(unit);
@@ -1,27 +0,0 @@
1
- type t;
2
-
3
- [@bs.deriving jsConverter]
4
- type env = [
5
- | [@bs.as "dev"] `Dev
6
- | [@bs.as "staging"] `Staging
7
- | [@bs.as "prod"] `Prod
8
- ];
9
-
10
- [@bs.deriving abstract]
11
- type options = {
12
- apiKey: string,
13
- env: string,
14
- version: string,
15
- appName: string,
16
- };
17
-
18
- [@bs.new] [@bs.module "node-avo-inspector"]
19
- external make: options => t = "AvoInspector";
20
-
21
- let make = (~apiKey, ~env, ~version, ~appName, ()) => {
22
- make(options(~apiKey, ~env=envToJs(env), ~version, ~appName));
23
- };
24
-
25
- [@bs.send]
26
- external trackSchemaFromEvent: (t, string, Js.Json.t) => Js.Promise.t(unit) =
27
- "trackSchemaFromEvent";
@@ -1,150 +0,0 @@
1
- import { deepEquals } from "./utils";
2
-
3
- export class AvoDeduplicator {
4
- avoFunctionsEvents: { [time: number]: string } = {};
5
- manualEvents: { [time: number]: string } = {};
6
- private msToConsiderOld = 500;
7
-
8
- // Keyed by streamId\0eventName to prevent cross-stream suppression on server
9
- avoFunctionsEventsParams: {
10
- [key: string]: { [propName: string]: any };
11
- } = {};
12
- manualEventsParams: { [key: string]: { [propName: string]: any } } = {};
13
-
14
- private static dedupKey(eventName: string, streamId: string): string {
15
- return streamId + "\0" + eventName;
16
- }
17
-
18
- shouldRegisterEvent(
19
- eventName: string,
20
- params: { [propName: string]: any },
21
- fromAvoFunction: boolean,
22
- streamId: string = ""
23
- ): boolean {
24
- this.clearOldEvents();
25
-
26
- const key = AvoDeduplicator.dedupKey(eventName, streamId);
27
-
28
- if (fromAvoFunction) {
29
- this.avoFunctionsEvents[Date.now()] = key;
30
- this.avoFunctionsEventsParams[key] = params;
31
- } else {
32
- this.manualEvents[Date.now()] = key;
33
- this.manualEventsParams[key] = params;
34
- }
35
-
36
- let checkInAvoFunctions = !fromAvoFunction;
37
-
38
- return !this.hasSameEventAs(key, params, checkInAvoFunctions);
39
- }
40
-
41
- private hasSameEventAs(
42
- key: string,
43
- params: { [propName: string]: any },
44
- checkInAvoFunctions: boolean
45
- ): boolean {
46
- let result = false;
47
-
48
- if (checkInAvoFunctions) {
49
- if (
50
- this.lookForEventIn(key, params, this.avoFunctionsEventsParams)
51
- ) {
52
- result = true;
53
- }
54
- } else {
55
- if (this.lookForEventIn(key, params, this.manualEventsParams)) {
56
- result = true;
57
- }
58
- }
59
-
60
- if (result) {
61
- delete this.avoFunctionsEventsParams[key];
62
- delete this.manualEventsParams[key];
63
- }
64
-
65
- return result;
66
- }
67
-
68
- private lookForEventIn(
69
- key: string,
70
- params: { [propName: string]: any },
71
- eventsStorage: { [key: string]: { [propName: string]: any } }
72
- ): boolean {
73
- if (eventsStorage.hasOwnProperty(key)) {
74
- const otherParams = eventsStorage[key];
75
- if (otherParams && deepEquals(params, otherParams)) {
76
- return true;
77
- }
78
- }
79
- return false;
80
- }
81
-
82
- hasSeenEventParams(
83
- params: { [propName: string]: any },
84
- checkInAvoFunctions: boolean
85
- ) {
86
- let result = false;
87
-
88
- if (checkInAvoFunctions) {
89
- if (this.lookForEventParamsIn(params, this.avoFunctionsEventsParams)) {
90
- result = true;
91
- }
92
- } else {
93
- if (this.lookForEventParamsIn(params, this.manualEventsParams)) {
94
- result = true;
95
- }
96
- }
97
-
98
- return result;
99
- }
100
-
101
- private lookForEventParamsIn(
102
- params: { [propName: string]: any },
103
- eventsStorage: { [eventName: string]: { [propName: string]: any } }
104
- ): boolean {
105
- for (const otherEventName in eventsStorage) {
106
- if (eventsStorage.hasOwnProperty(otherEventName)) {
107
- const otherParams = eventsStorage[otherEventName];
108
- if (otherParams && deepEquals(params, otherParams)) {
109
- return true;
110
- }
111
- }
112
- }
113
- return false;
114
- }
115
-
116
- private clearOldEvents() {
117
- const now = Date.now();
118
-
119
- for (const time in this.avoFunctionsEvents) {
120
- if (this.avoFunctionsEvents.hasOwnProperty(time)) {
121
- const timestamp = Number(time) || 0;
122
- if (now - timestamp > this.msToConsiderOld) {
123
- const key = this.avoFunctionsEvents[time];
124
- delete this.avoFunctionsEvents[time];
125
- delete this.avoFunctionsEventsParams[key];
126
- }
127
- }
128
- }
129
-
130
- for (const time in this.manualEvents) {
131
- if (this.manualEvents.hasOwnProperty(time)) {
132
- const timestamp = Number(time) || 0;
133
- if (now - timestamp > this.msToConsiderOld) {
134
- const key = this.manualEvents[time];
135
- delete this.manualEvents[time];
136
- delete this.manualEventsParams[key];
137
- }
138
- }
139
- }
140
- }
141
-
142
- // used in tests
143
- private _clearEvents() {
144
- this.avoFunctionsEvents = {};
145
- this.manualEvents = {};
146
-
147
- this.avoFunctionsEventsParams = {};
148
- this.manualEventsParams = {};
149
- }
150
- }
@@ -1,90 +0,0 @@
1
- import * as crypto from "crypto";
2
-
3
- export class AvoEncryption {
4
- /**
5
- * Determines whether encryption should be applied.
6
- *
7
- * Truth table:
8
- * dev + key => true
9
- * staging + key => true
10
- * prod + key => false
11
- * dev + null => false
12
- * dev + "" => false
13
- */
14
- static shouldEncrypt(
15
- env: string,
16
- publicEncryptionKey: string | undefined | null
17
- ): boolean {
18
- if (!publicEncryptionKey || publicEncryptionKey.length === 0) {
19
- return false;
20
- }
21
- if (env === "prod") {
22
- return false;
23
- }
24
- return true;
25
- }
26
-
27
- /**
28
- * Returns true if the propertyType represents a list type (e.g. "list(string)").
29
- */
30
- static isListType(propertyType: string): boolean {
31
- return propertyType.startsWith("list(");
32
- }
33
-
34
- /**
35
- * Encrypts a string value using ECIES with prime256v1.
36
- *
37
- * Wire format: [0x00][65-byte ephemeral pubkey][16-byte IV][16-byte auth tag][ciphertext]
38
- * Output is base64-encoded.
39
- *
40
- * Returns null on failure, logging a warning.
41
- */
42
- static encryptValue(
43
- value: string,
44
- recipientPubKeyHex: string
45
- ): string | null {
46
- try {
47
- const recipientPubKey = Buffer.from(recipientPubKeyHex, "hex");
48
-
49
- // Generate ephemeral key pair
50
- const ecdh = crypto.createECDH("prime256v1");
51
- ecdh.generateKeys();
52
- const ephemeralPubKey = ecdh.getPublicKey(); // 65 bytes, uncompressed
53
-
54
- // Compute shared secret (raw 32-byte X-coordinate)
55
- const sharedSecret = ecdh.computeSecret(recipientPubKey);
56
-
57
- // Derive AES key via SHA-256
58
- const aesKey = crypto.createHash("sha256").update(sharedSecret).digest();
59
-
60
- // Generate random 16-byte IV
61
- const iv = crypto.randomBytes(16);
62
-
63
- // Encrypt with AES-256-GCM
64
- const cipher = crypto.createCipheriv("aes-256-gcm", aesKey, iv, {
65
- authTagLength: 16,
66
- });
67
- const encrypted = Buffer.concat([
68
- cipher.update(value, "utf8"),
69
- cipher.final(),
70
- ]);
71
- const authTag = cipher.getAuthTag(); // 16 bytes
72
-
73
- // Assemble wire format: [version][ephemeralPubKey][IV][authTag][ciphertext]
74
- const wire = Buffer.concat([
75
- Buffer.from([0x00]), // version byte
76
- ephemeralPubKey, // 65 bytes
77
- iv, // 16 bytes
78
- authTag, // 16 bytes
79
- encrypted, // variable length
80
- ]);
81
-
82
- return wire.toString("base64");
83
- } catch (e) {
84
- console.warn(
85
- `[Avo Inspector] Warning: encryption failed for value, omitting property. ${e}`
86
- );
87
- return null;
88
- }
89
- }
90
- }
package/src/AvoGuid.ts DELETED
@@ -1,9 +0,0 @@
1
- export class AvoGuid {
2
- static newGuid(): string {
3
- return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
4
- var r = (Math.random() * 16) | 0,
5
- v = c == "x" ? r : (r & 0x3) | 0x8;
6
- return v.toString(16);
7
- });
8
- }
9
- }