node-avo-inspector 1.2.0 → 2.0.0-beta.1
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/CHANGELOG.md +46 -0
- package/README.md +268 -4
- package/package.json +17 -1
- package/.claude/scheduled_tasks.lock +0 -1
- package/.claude/settings.local.json +0 -11
- package/.claude/worktrees/release-1.1.1/LICENSE +0 -21
- package/.claude/worktrees/release-1.1.1/README.md +0 -69
- package/.claude/worktrees/release-1.1.1/examples/node-inspector-js/index.js +0 -30
- package/.claude/worktrees/release-1.1.1/examples/node-inspector-js/package.json +0 -15
- package/.claude/worktrees/release-1.1.1/examples/node-inspector-js/yarn.lock +0 -6
- package/.claude/worktrees/release-1.1.1/examples/node-inspector-ts/dist/index.js +0 -34
- package/.claude/worktrees/release-1.1.1/examples/node-inspector-ts/index.ts +0 -30
- package/.claude/worktrees/release-1.1.1/examples/node-inspector-ts/package.json +0 -18
- package/.claude/worktrees/release-1.1.1/examples/node-inspector-ts/tsconfig.json +0 -15
- package/.claude/worktrees/release-1.1.1/examples/node-inspector-ts/yarn.lock +0 -11
- package/.claude/worktrees/release-1.1.1/package-lock.json +0 -4039
- package/.claude/worktrees/release-1.1.1/package.json +0 -48
- package/.claude/worktrees/release-1.1.1/reason/AvoInspector.rei +0 -11
- package/.claude/worktrees/release-1.1.1/reason/NodeAvoInspector.re +0 -27
- package/.claude/worktrees/release-1.1.1/src/AvoDeduplicator.ts +0 -146
- package/.claude/worktrees/release-1.1.1/src/AvoEncryption.ts +0 -90
- package/.claude/worktrees/release-1.1.1/src/AvoGuid.ts +0 -9
- package/.claude/worktrees/release-1.1.1/src/AvoInspector.ts +0 -383
- package/.claude/worktrees/release-1.1.1/src/AvoInspectorEnv.ts +0 -8
- package/.claude/worktrees/release-1.1.1/src/AvoNetworkCallsHandler.ts +0 -267
- package/.claude/worktrees/release-1.1.1/src/AvoSchemaParser.ts +0 -115
- package/.claude/worktrees/release-1.1.1/src/AvoStreamId.ts +0 -16
- package/.claude/worktrees/release-1.1.1/src/__tests__/TestAvoEncryption.ts +0 -515
- package/.claude/worktrees/release-1.1.1/src/__tests__/TestAvoEventSpecCache.ts +0 -242
- package/.claude/worktrees/release-1.1.1/src/__tests__/TestAvoEventSpecFetcher.ts +0 -241
- package/.claude/worktrees/release-1.1.1/src/__tests__/TestAvoInspector.ts +0 -360
- package/.claude/worktrees/release-1.1.1/src/__tests__/TestAvoStreamId.ts +0 -72
- package/.claude/worktrees/release-1.1.1/src/__tests__/TestDeduplicator.ts +0 -191
- package/.claude/worktrees/release-1.1.1/src/__tests__/TestEventValidator.ts +0 -231
- package/.claude/worktrees/release-1.1.1/src/__tests__/TestNetworkCallsHandler.ts +0 -179
- package/.claude/worktrees/release-1.1.1/src/__tests__/TestNetworkCallsHandlerPublic.ts +0 -208
- package/.claude/worktrees/release-1.1.1/src/__tests__/TestParsing.ts +0 -153
- package/.claude/worktrees/release-1.1.1/src/__tests__/constants.ts +0 -63
- package/.claude/worktrees/release-1.1.1/src/eventSpec/AvoEventSpecCache.ts +0 -109
- package/.claude/worktrees/release-1.1.1/src/eventSpec/AvoEventSpecFetchTypes.ts +0 -47
- package/.claude/worktrees/release-1.1.1/src/eventSpec/AvoEventSpecFetcher.ts +0 -106
- package/.claude/worktrees/release-1.1.1/src/eventSpec/EventValidator.ts +0 -74
- package/.claude/worktrees/release-1.1.1/src/index.ts +0 -2
- package/.claude/worktrees/release-1.1.1/src/utils.ts +0 -49
- package/.claude/worktrees/release-1.1.1/tsconfig.json +0 -13
- package/.claude/worktrees/release-1.1.1/yarn.lock +0 -2310
- package/.github/workflows/claude.yml +0 -55
- package/dist/__tests__/TestAvoEncryption.d.ts +0 -1
- package/dist/__tests__/TestAvoEncryption.js +0 -288
- package/dist/__tests__/TestAvoEventSpecCache.d.ts +0 -1
- package/dist/__tests__/TestAvoEventSpecCache.js +0 -194
- package/dist/__tests__/TestAvoEventSpecFetcher.d.ts +0 -1
- package/dist/__tests__/TestAvoEventSpecFetcher.js +0 -219
- package/dist/__tests__/TestAvoInspector.d.ts +0 -1
- package/dist/__tests__/TestAvoInspector.js +0 -291
- package/dist/__tests__/TestAvoStreamId.d.ts +0 -1
- package/dist/__tests__/TestAvoStreamId.js +0 -55
- package/dist/__tests__/TestDeduplicator.d.ts +0 -1
- package/dist/__tests__/TestDeduplicator.js +0 -102
- package/dist/__tests__/TestEventValidator.d.ts +0 -1
- package/dist/__tests__/TestEventValidator.js +0 -196
- package/dist/__tests__/TestNetworkCallsHandler.d.ts +0 -1
- package/dist/__tests__/TestNetworkCallsHandler.js +0 -86
- package/dist/__tests__/TestNetworkCallsHandlerPublic.d.ts +0 -1
- package/dist/__tests__/TestNetworkCallsHandlerPublic.js +0 -160
- package/dist/__tests__/TestParsing.d.ts +0 -1
- package/dist/__tests__/TestParsing.js +0 -128
- package/dist/__tests__/constants.d.ts +0 -42
- package/dist/__tests__/constants.js +0 -53
- package/examples/node-inspector-js/index.js +0 -30
- package/examples/node-inspector-js/package.json +0 -15
- package/examples/node-inspector-js/yarn.lock +0 -6
- package/examples/node-inspector-ts/dist/index.js +0 -34
- package/examples/node-inspector-ts/index.ts +0 -30
- package/examples/node-inspector-ts/package.json +0 -18
- package/examples/node-inspector-ts/tsconfig.json +0 -15
- package/examples/node-inspector-ts/yarn.lock +0 -11
- package/reason/AvoInspector.rei +0 -11
- package/reason/NodeAvoInspector.re +0 -27
- package/src/AvoDeduplicator.ts +0 -150
- package/src/AvoEncryption.ts +0 -90
- package/src/AvoGuid.ts +0 -9
- package/src/AvoInspector.ts +0 -498
- package/src/AvoInspectorEnv.ts +0 -8
- package/src/AvoNetworkCallsHandler.ts +0 -340
- package/src/AvoSchemaParser.ts +0 -115
- package/src/AvoStreamId.ts +0 -16
- package/src/__tests__/TestAvoEncryption.ts +0 -515
- package/src/__tests__/TestAvoEventSpecCache.ts +0 -242
- package/src/__tests__/TestAvoEventSpecFetcher.ts +0 -279
- package/src/__tests__/TestAvoInspector.ts +0 -376
- package/src/__tests__/TestAvoStreamId.ts +0 -72
- package/src/__tests__/TestDeduplicator.ts +0 -191
- package/src/__tests__/TestEventValidator.ts +0 -231
- package/src/__tests__/TestNetworkCallsHandler.ts +0 -181
- package/src/__tests__/TestNetworkCallsHandlerPublic.ts +0 -208
- package/src/__tests__/TestParsing.ts +0 -153
- package/src/__tests__/constants.ts +0 -63
- package/src/eventSpec/AvoEventSpecCache.ts +0 -119
- package/src/eventSpec/AvoEventSpecFetchTypes.ts +0 -47
- package/src/eventSpec/AvoEventSpecFetcher.ts +0 -186
- package/src/eventSpec/EventValidator.ts +0 -74
- package/src/index.ts +0 -2
- package/src/utils.ts +0 -49
- 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,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,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==
|
package/reason/AvoInspector.rei
DELETED
|
@@ -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";
|
package/src/AvoDeduplicator.ts
DELETED
|
@@ -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
|
-
}
|
package/src/AvoEncryption.ts
DELETED
|
@@ -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