@reyaxyz/athena-logger 0.2.4 → 0.2.6
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/dist/index.js +14 -5
- package/dist/index.js.map +1 -1
- package/dist/logger.js +31 -15
- package/dist/logger.js.map +1 -1
- package/dist/{error.js → modules/error/index.js} +5 -5
- package/dist/modules/error/index.js.map +1 -0
- package/dist/modules/user-journey/index.js +66 -0
- package/dist/modules/user-journey/index.js.map +1 -0
- package/dist/modules/user-journey/state.js +30 -0
- package/dist/modules/user-journey/state.js.map +1 -0
- package/dist/shared.js +16 -0
- package/dist/shared.js.map +1 -0
- package/dist/types/index.d.ts +6 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/logger.d.ts +0 -2
- package/dist/types/logger.d.ts.map +1 -1
- package/dist/types/modules/error/index.d.ts +10 -0
- package/dist/types/modules/error/index.d.ts.map +1 -0
- package/dist/types/modules/user-journey/index.d.ts +14 -0
- package/dist/types/modules/user-journey/index.d.ts.map +1 -0
- package/dist/types/modules/user-journey/state.d.ts +8 -0
- package/dist/types/modules/user-journey/state.d.ts.map +1 -0
- package/dist/types/shared.d.ts +6 -0
- package/dist/types/shared.d.ts.map +1 -0
- package/package.json +4 -3
- package/src/index.ts +3 -3
- package/src/logger.ts +36 -14
- package/src/{error.ts → modules/error/index.ts} +4 -4
- package/src/modules/user-journey/index.ts +88 -0
- package/src/modules/user-journey/state.ts +39 -0
- package/src/shared.ts +12 -0
- package/dist/action.js +0 -20
- package/dist/action.js.map +0 -1
- package/dist/error.js.map +0 -1
- package/dist/types/action.d.ts +0 -9
- package/dist/types/action.d.ts.map +0 -1
- package/dist/types/error.d.ts +0 -10
- package/dist/types/error.d.ts.map +0 -1
- package/dist/types/utils/checkWalletAddress/index.d.ts +0 -2
- package/dist/types/utils/checkWalletAddress/index.d.ts.map +0 -1
- package/dist/utils/checkWalletAddress/index.js +0 -8
- package/dist/utils/checkWalletAddress/index.js.map +0 -1
- package/src/action.ts +0 -35
- package/src/utils/checkWalletAddress/index.ts +0 -2
package/dist/index.js
CHANGED
|
@@ -1,14 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
2
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
14
|
exports.Athena = void 0;
|
|
4
|
-
var
|
|
5
|
-
var error_1 = require("./error");
|
|
15
|
+
var user_journey_1 = require("./modules/user-journey");
|
|
16
|
+
var error_1 = require("./modules/error");
|
|
6
17
|
var logger_1 = require("./logger");
|
|
7
18
|
exports.Athena = {
|
|
8
19
|
initialize: logger_1.initialize,
|
|
9
|
-
UserJourney: {
|
|
10
|
-
action: action_1.action,
|
|
11
|
-
},
|
|
20
|
+
UserJourney: __assign({}, user_journey_1.userJourney),
|
|
12
21
|
Error: {
|
|
13
22
|
error: error_1.error,
|
|
14
23
|
},
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,uDAAqD;AACrD,yCAAwC;AACxC,mCAAsC;AAEzB,QAAA,MAAM,GAAG;IACpB,UAAU,qBAAA;IACV,WAAW,eACN,0BAAW,CACf;IACD,KAAK,EAAE;QACL,KAAK,eAAA;KACN;CACF,CAAC","sourcesContent":["import { userJourney } from './modules/user-journey';\nimport { error } from './modules/error';\nimport { initialize } from './logger';\n\nexport const Athena = {\n initialize,\n UserJourney: {\n ...userJourney,\n },\n Error: {\n error,\n },\n};\n"]}
|
package/dist/logger.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.initialize = void 0;
|
|
4
4
|
var browser_logs_1 = require("@datadog/browser-logs");
|
|
5
|
-
var
|
|
6
|
-
var
|
|
5
|
+
var shared_1 = require("./shared");
|
|
6
|
+
var error_1 = require("./modules/error");
|
|
7
7
|
var initialize = function (_a) {
|
|
8
8
|
var clientToken = _a.clientToken, environment = _a.environment, service = _a.service, version = _a.version;
|
|
9
9
|
var isLocalhost = environment === 'localhost';
|
|
10
10
|
if (!environment || !clientToken || !service || !version) {
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
(0, shared_1.setInitialized)(false);
|
|
12
|
+
(0, shared_1.setAllowLogging)(false);
|
|
13
13
|
return;
|
|
14
14
|
}
|
|
15
15
|
if (isLocalhost) {
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
(0, shared_1.setInitialized)(true);
|
|
17
|
+
(0, shared_1.setAllowLogging)(false);
|
|
18
18
|
return;
|
|
19
19
|
}
|
|
20
20
|
try {
|
|
@@ -28,17 +28,33 @@ var initialize = function (_a) {
|
|
|
28
28
|
forwardErrorsToLogs: true,
|
|
29
29
|
version: version,
|
|
30
30
|
});
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
// Log rejected Promises without a .catch() handler
|
|
32
|
+
window.addEventListener('unhandledrejection', function (event) {
|
|
33
|
+
event.preventDefault();
|
|
34
|
+
var message = "Promise rejected and uncaught; reason: ".concat(event.reason);
|
|
35
|
+
(0, error_1.error)({
|
|
36
|
+
context: 'window/onunhandledrejection',
|
|
37
|
+
error: new Error(message),
|
|
38
|
+
message: message,
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
// Log rejected Promises that are caught late (handler attached at a later time)
|
|
42
|
+
window.addEventListener('rejectionhandled', function (event) {
|
|
43
|
+
event.preventDefault();
|
|
44
|
+
var message = "Promise rejected and caught late; reason: ".concat(event.reason);
|
|
45
|
+
(0, error_1.error)({
|
|
46
|
+
context: 'window/onrejectionhandled',
|
|
47
|
+
error: new Error(message),
|
|
48
|
+
message: message,
|
|
49
|
+
});
|
|
50
|
+
}, false);
|
|
51
|
+
(0, shared_1.setInitialized)(true);
|
|
52
|
+
(0, shared_1.setAllowLogging)(true);
|
|
33
53
|
}
|
|
34
54
|
catch (err) {
|
|
35
|
-
|
|
36
|
-
|
|
55
|
+
(0, shared_1.setInitialized)(false);
|
|
56
|
+
(0, shared_1.setAllowLogging)(false);
|
|
37
57
|
}
|
|
38
58
|
};
|
|
39
59
|
exports.initialize = initialize;
|
|
40
|
-
var isLoggerInitialized = function () { return initialized; };
|
|
41
|
-
exports.isLoggerInitialized = isLoggerInitialized;
|
|
42
|
-
var isLoggingAllowed = function () { return allowLogging; };
|
|
43
|
-
exports.isLoggingAllowed = isLoggingAllowed;
|
|
44
60
|
//# sourceMappingURL=logger.js.map
|
package/dist/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"/","sources":["logger.ts"],"names":[],"mappings":";;;AAAA,sDAAoD;
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"/","sources":["logger.ts"],"names":[],"mappings":";;;AAAA,sDAAoD;AACpD,mCAA2D;AAC3D,yCAAwC;AASjC,IAAM,UAAU,GAAG,UAAC,EAKR;QAJjB,WAAW,iBAAA,EACX,WAAW,iBAAA,EACX,OAAO,aAAA,EACP,OAAO,aAAA;IAEP,IAAM,WAAW,GAAG,WAAW,KAAK,WAAW,CAAC;IAChD,IAAI,CAAC,WAAW,IAAI,CAAC,WAAW,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;QACzD,IAAA,uBAAc,EAAC,KAAK,CAAC,CAAC;QACtB,IAAA,wBAAe,EAAC,KAAK,CAAC,CAAC;QACvB,OAAO;IACT,CAAC;IAED,IAAI,WAAW,EAAE,CAAC;QAChB,IAAA,uBAAc,EAAC,IAAI,CAAC,CAAC;QACrB,IAAA,wBAAe,EAAC,KAAK,CAAC,CAAC;QACvB,OAAO;IACT,CAAC;IAED,IAAI,CAAC;QACH,0BAAW,CAAC,IAAI,CAAC;YACf,WAAW,aAAA;YACX,GAAG,EAAE,WAAW;YAChB,OAAO,SAAA;YACP,iBAAiB,EAAE,GAAG;YACtB,IAAI,EAAE,cAAc;YACpB,kBAAkB,EAAE,CAAC,OAAO,CAAC;YAC7B,mBAAmB,EAAE,IAAI;YACzB,OAAO,SAAA;SACR,CAAC,CAAC;QAEH,mDAAmD;QACnD,MAAM,CAAC,gBAAgB,CAAC,oBAAoB,EAAE,UAAC,KAAK;YAClD,KAAK,CAAC,cAAc,EAAE,CAAC;YACvB,IAAM,OAAO,GAAG,iDAA0C,KAAK,CAAC,MAAM,CAAE,CAAC;YACzE,IAAA,aAAK,EAAC;gBACJ,OAAO,EAAE,6BAA6B;gBACtC,KAAK,EAAE,IAAI,KAAK,CAAC,OAAO,CAAC;gBACzB,OAAO,SAAA;aACR,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,gFAAgF;QAChF,MAAM,CAAC,gBAAgB,CACrB,kBAAkB,EAClB,UAAC,KAAK;YACJ,KAAK,CAAC,cAAc,EAAE,CAAC;YACvB,IAAM,OAAO,GAAG,oDAA6C,KAAK,CAAC,MAAM,CAAE,CAAC;YAC5E,IAAA,aAAK,EAAC;gBACJ,OAAO,EAAE,2BAA2B;gBACpC,KAAK,EAAE,IAAI,KAAK,CAAC,OAAO,CAAC;gBACzB,OAAO,SAAA;aACR,CAAC,CAAC;QACL,CAAC,EACD,KAAK,CACN,CAAC;QAEF,IAAA,uBAAc,EAAC,IAAI,CAAC,CAAC;QACrB,IAAA,wBAAe,EAAC,IAAI,CAAC,CAAC;IACxB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAA,uBAAc,EAAC,KAAK,CAAC,CAAC;QACtB,IAAA,wBAAe,EAAC,KAAK,CAAC,CAAC;IACzB,CAAC;AACH,CAAC,CAAC;AA/DW,QAAA,UAAU,cA+DrB","sourcesContent":["import { datadogLogs } from '@datadog/browser-logs';\nimport { setInitialized, setAllowLogging } from './shared';\nimport { error } from './modules/error';\n\ntype InitializeParams = {\n clientToken: string;\n environment: string;\n service: string;\n version: string;\n};\n\nexport const initialize = ({\n clientToken,\n environment,\n service,\n version,\n}: InitializeParams) => {\n const isLocalhost = environment === 'localhost';\n if (!environment || !clientToken || !service || !version) {\n setInitialized(false);\n setAllowLogging(false);\n return;\n }\n\n if (isLocalhost) {\n setInitialized(true);\n setAllowLogging(false);\n return;\n }\n\n try {\n datadogLogs.init({\n clientToken,\n env: environment,\n service,\n sessionSampleRate: 100,\n site: 'datadoghq.eu',\n forwardConsoleLogs: ['error'],\n forwardErrorsToLogs: true,\n version,\n });\n\n // Log rejected Promises without a .catch() handler\n window.addEventListener('unhandledrejection', (event) => {\n event.preventDefault();\n const message = `Promise rejected and uncaught; reason: ${event.reason}`;\n error({\n context: 'window/onunhandledrejection',\n error: new Error(message),\n message,\n });\n });\n\n // Log rejected Promises that are caught late (handler attached at a later time)\n window.addEventListener(\n 'rejectionhandled',\n (event) => {\n event.preventDefault();\n const message = `Promise rejected and caught late; reason: ${event.reason}`;\n error({\n context: 'window/onrejectionhandled',\n error: new Error(message),\n message,\n });\n },\n false,\n );\n\n setInitialized(true);\n setAllowLogging(true);\n } catch (err) {\n setInitialized(false);\n setAllowLogging(false);\n }\n};\n"]}
|
|
@@ -13,14 +13,14 @@ var __assign = (this && this.__assign) || function () {
|
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
14
|
exports.error = void 0;
|
|
15
15
|
var browser_logs_1 = require("@datadog/browser-logs");
|
|
16
|
-
var
|
|
16
|
+
var shared_1 = require("../../shared");
|
|
17
17
|
var error = function (_a) {
|
|
18
|
-
var
|
|
19
|
-
if (!(0,
|
|
18
|
+
var context = _a.context, message = _a.message, metadata = _a.metadata, walletAddress = _a.walletAddress, error = _a.error;
|
|
19
|
+
if (!(0, shared_1.isLoggerInitialized)()) {
|
|
20
20
|
console.warn('Logger not initialized');
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
|
-
browser_logs_1.datadogLogs.logger.error("athena.error/".concat(
|
|
23
|
+
browser_logs_1.datadogLogs.logger.error("athena.error/".concat(context).concat(message ? ": ".concat(message) : ''), __assign(__assign({}, metadata), (walletAddress && { user: { walletAddress: walletAddress } })), error);
|
|
24
24
|
};
|
|
25
25
|
exports.error = error;
|
|
26
|
-
//# sourceMappingURL=
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["modules/error/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,sDAAoD;AACpD,uCAAmD;AAW5C,IAAM,KAAK,GAAG,UAAC,EAML;QALf,OAAO,aAAA,EACP,OAAO,aAAA,EACP,QAAQ,cAAA,EACR,aAAa,mBAAA,EACb,KAAK,WAAA;IAEL,IAAI,CAAC,IAAA,4BAAmB,GAAE,EAAE,CAAC;QAC3B,OAAO,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;QACvC,OAAO;IACT,CAAC;IAED,0BAAW,CAAC,MAAM,CAAC,KAAK,CACtB,uBAAgB,OAAO,SAAG,OAAO,CAAC,CAAC,CAAC,YAAK,OAAO,CAAE,CAAC,CAAC,CAAC,EAAE,CAAE,wBACpD,QAAQ,GAAK,CAAC,aAAa,IAAI,EAAE,IAAI,EAAE,EAAE,aAAa,eAAA,EAAE,EAAE,CAAC,GAChE,KAAc,CACf,CAAC;AACJ,CAAC,CAAC;AAjBW,QAAA,KAAK,SAiBhB","sourcesContent":["import { datadogLogs } from '@datadog/browser-logs';\nimport { isLoggerInitialized } from '../../shared';\n\ntype LogErrorParams = {\n context: string;\n error: unknown;\n walletAddress?: string;\n // Optional! If not provided, will try to extract message from Error\n message?: string;\n metadata?: Record<string, unknown>;\n};\n\nexport const error = ({\n context,\n message,\n metadata,\n walletAddress,\n error,\n}: LogErrorParams) => {\n if (!isLoggerInitialized()) {\n console.warn('Logger not initialized');\n return;\n }\n\n datadogLogs.logger.error(\n `athena.error/${context}${message ? `: ${message}` : ''}`,\n { ...metadata, ...(walletAddress && { user: { walletAddress } }) },\n error as Error,\n );\n};\n"]}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.userJourney = void 0;
|
|
15
|
+
var browser_logs_1 = require("@datadog/browser-logs");
|
|
16
|
+
var shared_1 = require("../../shared");
|
|
17
|
+
var state_1 = require("./state");
|
|
18
|
+
var action = function (_a) {
|
|
19
|
+
var action = _a.action, error = _a.error, message = _a.message, payload = _a.payload;
|
|
20
|
+
var walletAddress = (0, state_1.getWalletAddress)();
|
|
21
|
+
var chainId = (0, state_1.getChainId)();
|
|
22
|
+
if (!walletAddress) {
|
|
23
|
+
console.warn('Logger missing wallet address');
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (!chainId) {
|
|
27
|
+
console.warn('Logger missing chainId');
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (!(0, shared_1.isLoggerInitialized)()) {
|
|
31
|
+
console.warn('Logger not initialized');
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
browser_logs_1.datadogLogs.logger.info("athena.user_journey/".concat(action).concat(message ? ": ".concat(message) : ''), __assign(__assign({}, payload), { user: {
|
|
35
|
+
walletAddress: walletAddress,
|
|
36
|
+
chainId: chainId,
|
|
37
|
+
} }), error);
|
|
38
|
+
};
|
|
39
|
+
var start = function (address, chainId) {
|
|
40
|
+
if (!(0, shared_1.isLoggerInitialized)()) {
|
|
41
|
+
console.warn('Logger not initialized');
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
(0, state_1.initialize)(address, chainId);
|
|
45
|
+
};
|
|
46
|
+
var switchChain = function (chainId) {
|
|
47
|
+
if (!(0, shared_1.isLoggerInitialized)()) {
|
|
48
|
+
console.warn('Logger not initialized');
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
(0, state_1.setChainId)(chainId);
|
|
52
|
+
};
|
|
53
|
+
var stop = function () {
|
|
54
|
+
if (!(0, shared_1.isLoggerInitialized)()) {
|
|
55
|
+
console.warn('Logger not initialized');
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
(0, state_1.clear)();
|
|
59
|
+
};
|
|
60
|
+
exports.userJourney = {
|
|
61
|
+
action: action,
|
|
62
|
+
start: start,
|
|
63
|
+
switchChain: switchChain,
|
|
64
|
+
stop: stop,
|
|
65
|
+
};
|
|
66
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["modules/user-journey/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,sDAAoD;AACpD,uCAAmD;AACnD,iCAMiB;AAUjB,IAAM,MAAM,GAAG,UAAC,EAKU;QAJxB,MAAM,YAAA,EACN,KAAK,WAAA,EACL,OAAO,aAAA,EACP,OAAO,aAAA;IAEP,IAAM,aAAa,GAAG,IAAA,wBAAgB,GAAE,CAAC;IACzC,IAAM,OAAO,GAAG,IAAA,kBAAU,GAAE,CAAC;IAE7B,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,OAAO,CAAC,IAAI,CAAC,+BAA+B,CAAC,CAAC;QAC9C,OAAO;IACT,CAAC;IAED,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;QACvC,OAAO;IACT,CAAC;IAED,IAAI,CAAC,IAAA,4BAAmB,GAAE,EAAE,CAAC;QAC3B,OAAO,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;QACvC,OAAO;IACT,CAAC;IAED,0BAAW,CAAC,MAAM,CAAC,IAAI,CACrB,8BAAuB,MAAM,SAAG,OAAO,CAAC,CAAC,CAAC,YAAK,OAAO,CAAE,CAAC,CAAC,CAAC,EAAE,CAAE,wBAE1D,OAAO,KACV,IAAI,EAAE;YACJ,aAAa,eAAA;YACb,OAAO,SAAA;SACR,KAEH,KAAc,CACf,CAAC;AACJ,CAAC,CAAC;AAEF,IAAM,KAAK,GAAG,UAAC,OAAe,EAAE,OAAe;IAC7C,IAAI,CAAC,IAAA,4BAAmB,GAAE,EAAE,CAAC;QAC3B,OAAO,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;QACvC,OAAO;IACT,CAAC;IAED,IAAA,kBAAU,EAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAC/B,CAAC,CAAC;AAEF,IAAM,WAAW,GAAG,UAAC,OAAe;IAClC,IAAI,CAAC,IAAA,4BAAmB,GAAE,EAAE,CAAC;QAC3B,OAAO,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;QACvC,OAAO;IACT,CAAC;IAED,IAAA,kBAAU,EAAC,OAAO,CAAC,CAAC;AACtB,CAAC,CAAC;AAEF,IAAM,IAAI,GAAG;IACX,IAAI,CAAC,IAAA,4BAAmB,GAAE,EAAE,CAAC;QAC3B,OAAO,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;QACvC,OAAO;IACT,CAAC;IAED,IAAA,aAAK,GAAE,CAAC;AACV,CAAC,CAAC;AAEW,QAAA,WAAW,GAAG;IACzB,MAAM,QAAA;IACN,KAAK,OAAA;IACL,WAAW,aAAA;IACX,IAAI,MAAA;CACL,CAAC","sourcesContent":["import { datadogLogs } from '@datadog/browser-logs';\nimport { isLoggerInitialized } from '../../shared';\nimport {\n clear,\n getChainId,\n getWalletAddress,\n initialize,\n setChainId,\n} from './state';\n\nexport type UserJourneyActionParams = {\n walletAddress: string;\n action: string;\n error?: Error | unknown;\n message?: string;\n payload?: Record<string, unknown>;\n};\n\nconst action = ({\n action,\n error,\n message,\n payload,\n}: UserJourneyActionParams) => {\n const walletAddress = getWalletAddress();\n const chainId = getChainId();\n\n if (!walletAddress) {\n console.warn('Logger missing wallet address');\n return;\n }\n\n if (!chainId) {\n console.warn('Logger missing chainId');\n return;\n }\n\n if (!isLoggerInitialized()) {\n console.warn('Logger not initialized');\n return;\n }\n\n datadogLogs.logger.info(\n `athena.user_journey/${action}${message ? `: ${message}` : ''}`,\n {\n ...payload,\n user: {\n walletAddress,\n chainId,\n },\n },\n error as Error,\n );\n};\n\nconst start = (address: string, chainId: string) => {\n if (!isLoggerInitialized()) {\n console.warn('Logger not initialized');\n return;\n }\n\n initialize(address, chainId);\n};\n\nconst switchChain = (chainId: string) => {\n if (!isLoggerInitialized()) {\n console.warn('Logger not initialized');\n return;\n }\n\n setChainId(chainId);\n};\n\nconst stop = () => {\n if (!isLoggerInitialized()) {\n console.warn('Logger not initialized');\n return;\n }\n\n clear();\n};\n\nexport const userJourney = {\n action,\n start,\n switchChain,\n stop,\n};\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.clear = exports.setChainId = exports.setWalletAddress = exports.getChainId = exports.getWalletAddress = exports.initialize = void 0;
|
|
4
|
+
var state = {
|
|
5
|
+
walletAddress: null,
|
|
6
|
+
chainId: null,
|
|
7
|
+
};
|
|
8
|
+
var initialize = function (walletAddress, chainId) {
|
|
9
|
+
state.walletAddress = walletAddress;
|
|
10
|
+
state.chainId = chainId;
|
|
11
|
+
};
|
|
12
|
+
exports.initialize = initialize;
|
|
13
|
+
var getWalletAddress = function () { return state.walletAddress; };
|
|
14
|
+
exports.getWalletAddress = getWalletAddress;
|
|
15
|
+
var getChainId = function () { return state.chainId; };
|
|
16
|
+
exports.getChainId = getChainId;
|
|
17
|
+
var setWalletAddress = function (walletAddress) {
|
|
18
|
+
state.walletAddress = walletAddress;
|
|
19
|
+
};
|
|
20
|
+
exports.setWalletAddress = setWalletAddress;
|
|
21
|
+
var setChainId = function (chainId) {
|
|
22
|
+
state.chainId = chainId;
|
|
23
|
+
};
|
|
24
|
+
exports.setChainId = setChainId;
|
|
25
|
+
var clear = function () {
|
|
26
|
+
state.walletAddress = null;
|
|
27
|
+
state.chainId = null;
|
|
28
|
+
};
|
|
29
|
+
exports.clear = clear;
|
|
30
|
+
//# sourceMappingURL=state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"/","sources":["modules/user-journey/state.ts"],"names":[],"mappings":";;;AAKA,IAAM,KAAK,GAAqB;IAC9B,aAAa,EAAE,IAAI;IACnB,OAAO,EAAE,IAAI;CACd,CAAC;AAEF,IAAM,UAAU,GAAG,UAAC,aAAqB,EAAE,OAAe;IACxD,KAAK,CAAC,aAAa,GAAG,aAAa,CAAC;IACpC,KAAK,CAAC,OAAO,GAAG,OAAO,CAAC;AAC1B,CAAC,CAAC;AAmBA,gCAAU;AAjBZ,IAAM,gBAAgB,GAAG,cAAM,OAAA,KAAK,CAAC,aAAa,EAAnB,CAAmB,CAAC;AAkBjD,4CAAgB;AAjBlB,IAAM,UAAU,GAAG,cAAM,OAAA,KAAK,CAAC,OAAO,EAAb,CAAa,CAAC;AAkBrC,gCAAU;AAhBZ,IAAM,gBAAgB,GAAG,UAAC,aAAqB;IAC7C,KAAK,CAAC,aAAa,GAAG,aAAa,CAAC;AACtC,CAAC,CAAC;AAeA,4CAAgB;AAblB,IAAM,UAAU,GAAG,UAAC,OAAe;IACjC,KAAK,CAAC,OAAO,GAAG,OAAO,CAAC;AAC1B,CAAC,CAAC;AAYA,gCAAU;AAVZ,IAAM,KAAK,GAAG;IACZ,KAAK,CAAC,aAAa,GAAG,IAAI,CAAC;IAC3B,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC;AACvB,CAAC,CAAC;AAQA,sBAAK","sourcesContent":["type UserJourneyState = {\n walletAddress: string | null;\n chainId: string | null;\n};\n\nconst state: UserJourneyState = {\n walletAddress: null,\n chainId: null,\n};\n\nconst initialize = (walletAddress: string, chainId: string) => {\n state.walletAddress = walletAddress;\n state.chainId = chainId;\n};\n\nconst getWalletAddress = () => state.walletAddress;\nconst getChainId = () => state.chainId;\n\nconst setWalletAddress = (walletAddress: string) => {\n state.walletAddress = walletAddress;\n};\n\nconst setChainId = (chainId: string) => {\n state.chainId = chainId;\n};\n\nconst clear = () => {\n state.walletAddress = null;\n state.chainId = null;\n};\n\nexport {\n initialize,\n getWalletAddress,\n getChainId,\n setWalletAddress,\n setChainId,\n clear,\n};\n"]}
|
package/dist/shared.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isLoggerInitialized = exports.setAllowLogging = exports.setInitialized = exports.allowLogging = exports.initialized = void 0;
|
|
4
|
+
exports.initialized = false;
|
|
5
|
+
exports.allowLogging = false;
|
|
6
|
+
var setInitialized = function (value) {
|
|
7
|
+
exports.initialized = value;
|
|
8
|
+
};
|
|
9
|
+
exports.setInitialized = setInitialized;
|
|
10
|
+
var setAllowLogging = function (value) {
|
|
11
|
+
exports.allowLogging = value;
|
|
12
|
+
};
|
|
13
|
+
exports.setAllowLogging = setAllowLogging;
|
|
14
|
+
var isLoggerInitialized = function () { return exports.initialized; };
|
|
15
|
+
exports.isLoggerInitialized = isLoggerInitialized;
|
|
16
|
+
//# sourceMappingURL=shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"/","sources":["shared.ts"],"names":[],"mappings":";;;AAAW,QAAA,WAAW,GAAG,KAAK,CAAC;AACpB,QAAA,YAAY,GAAG,KAAK,CAAC;AAEzB,IAAM,cAAc,GAAG,UAAC,KAAc;IAC3C,mBAAW,GAAG,KAAK,CAAC;AACtB,CAAC,CAAC;AAFW,QAAA,cAAc,kBAEzB;AAEK,IAAM,eAAe,GAAG,UAAC,KAAc;IAC5C,oBAAY,GAAG,KAAK,CAAC;AACvB,CAAC,CAAC;AAFW,QAAA,eAAe,mBAE1B;AAEK,IAAM,mBAAmB,GAAG,cAAM,OAAA,mBAAW,EAAX,CAAW,CAAC;AAAxC,QAAA,mBAAmB,uBAAqB","sourcesContent":["export let initialized = false;\nexport let allowLogging = false;\n\nexport const setInitialized = (value: boolean) => {\n initialized = value;\n};\n\nexport const setAllowLogging = (value: boolean) => {\n allowLogging = value;\n};\n\nexport const isLoggerInitialized = () => initialized;\n"]}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -6,11 +6,14 @@ export declare const Athena: {
|
|
|
6
6
|
version: string;
|
|
7
7
|
}) => void;
|
|
8
8
|
UserJourney: {
|
|
9
|
-
action: ({
|
|
9
|
+
action: ({ action, error, message, payload, }: import("./modules/user-journey").UserJourneyActionParams) => void;
|
|
10
|
+
start: (address: string, chainId: string) => void;
|
|
11
|
+
switchChain: (chainId: string) => void;
|
|
12
|
+
stop: () => void;
|
|
10
13
|
};
|
|
11
14
|
Error: {
|
|
12
|
-
error: ({
|
|
13
|
-
|
|
15
|
+
error: ({ context, message, metadata, walletAddress, error, }: {
|
|
16
|
+
context: string;
|
|
14
17
|
error: unknown;
|
|
15
18
|
walletAddress?: string | undefined;
|
|
16
19
|
message?: string | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,MAAM
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;CAQlB,CAAC"}
|
package/dist/types/logger.d.ts
CHANGED
|
@@ -5,7 +5,5 @@ type InitializeParams = {
|
|
|
5
5
|
version: string;
|
|
6
6
|
};
|
|
7
7
|
export declare const initialize: ({ clientToken, environment, service, version, }: InitializeParams) => void;
|
|
8
|
-
export declare const isLoggerInitialized: () => boolean;
|
|
9
|
-
export declare const isLoggingAllowed: () => boolean;
|
|
10
8
|
export {};
|
|
11
9
|
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"/","sources":["logger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"/","sources":["logger.ts"],"names":[],"mappings":"AAIA,KAAK,gBAAgB,GAAG;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,eAAO,MAAM,UAAU,oDAKpB,gBAAgB,SA0DlB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type LogErrorParams = {
|
|
2
|
+
context: string;
|
|
3
|
+
error: unknown;
|
|
4
|
+
walletAddress?: string;
|
|
5
|
+
message?: string;
|
|
6
|
+
metadata?: Record<string, unknown>;
|
|
7
|
+
};
|
|
8
|
+
export declare const error: ({ context, message, metadata, walletAddress, error, }: LogErrorParams) => void;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["modules/error/index.ts"],"names":[],"mappings":"AAGA,KAAK,cAAc,GAAG;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,OAAO,CAAC;IACf,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC,CAAC;AAEF,eAAO,MAAM,KAAK,0DAMf,cAAc,SAWhB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type UserJourneyActionParams = {
|
|
2
|
+
walletAddress: string;
|
|
3
|
+
action: string;
|
|
4
|
+
error?: Error | unknown;
|
|
5
|
+
message?: string;
|
|
6
|
+
payload?: Record<string, unknown>;
|
|
7
|
+
};
|
|
8
|
+
export declare const userJourney: {
|
|
9
|
+
action: ({ action, error, message, payload, }: UserJourneyActionParams) => void;
|
|
10
|
+
start: (address: string, chainId: string) => void;
|
|
11
|
+
switchChain: (chainId: string) => void;
|
|
12
|
+
stop: () => void;
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["modules/user-journey/index.ts"],"names":[],"mappings":"AAUA,MAAM,MAAM,uBAAuB,GAAG;IACpC,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,KAAK,GAAG,OAAO,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC,CAAC;AAkEF,eAAO,MAAM,WAAW;mDA3DrB,uBAAuB;qBAgCF,MAAM,WAAW,MAAM;2BASjB,MAAM;;CAuBnC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
declare const initialize: (walletAddress: string, chainId: string) => void;
|
|
2
|
+
declare const getWalletAddress: () => string | null;
|
|
3
|
+
declare const getChainId: () => string | null;
|
|
4
|
+
declare const setWalletAddress: (walletAddress: string) => void;
|
|
5
|
+
declare const setChainId: (chainId: string) => void;
|
|
6
|
+
declare const clear: () => void;
|
|
7
|
+
export { initialize, getWalletAddress, getChainId, setWalletAddress, setChainId, clear, };
|
|
8
|
+
//# sourceMappingURL=state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"/","sources":["modules/user-journey/state.ts"],"names":[],"mappings":"AAUA,QAAA,MAAM,UAAU,kBAAmB,MAAM,WAAW,MAAM,SAGzD,CAAC;AAEF,QAAA,MAAM,gBAAgB,qBAA4B,CAAC;AACnD,QAAA,MAAM,UAAU,qBAAsB,CAAC;AAEvC,QAAA,MAAM,gBAAgB,kBAAmB,MAAM,SAE9C,CAAC;AAEF,QAAA,MAAM,UAAU,YAAa,MAAM,SAElC,CAAC;AAEF,QAAA,MAAM,KAAK,YAGV,CAAC;AAEF,OAAO,EACL,UAAU,EACV,gBAAgB,EAChB,UAAU,EACV,gBAAgB,EAChB,UAAU,EACV,KAAK,GACN,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare let initialized: boolean;
|
|
2
|
+
export declare let allowLogging: boolean;
|
|
3
|
+
export declare const setInitialized: (value: boolean) => void;
|
|
4
|
+
export declare const setAllowLogging: (value: boolean) => void;
|
|
5
|
+
export declare const isLoggerInitialized: () => boolean;
|
|
6
|
+
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"/","sources":["shared.ts"],"names":[],"mappings":"AAAA,eAAO,IAAI,WAAW,SAAQ,CAAC;AAC/B,eAAO,IAAI,YAAY,SAAQ,CAAC;AAEhC,eAAO,MAAM,cAAc,UAAW,OAAO,SAE5C,CAAC;AAEF,eAAO,MAAM,eAAe,UAAW,OAAO,SAE7C,CAAC;AAEF,eAAO,MAAM,mBAAmB,eAAoB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reyaxyz/athena-logger",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"registry": "https://registry.npmjs.org"
|
|
@@ -36,11 +36,12 @@
|
|
|
36
36
|
"@reyaxyz/common": "0.114.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@datadog/browser-logs": "5.17.1"
|
|
39
|
+
"@datadog/browser-logs": "5.17.1",
|
|
40
|
+
"@types/node": "20.12.12"
|
|
40
41
|
},
|
|
41
42
|
"peerDependencies": {
|
|
42
43
|
"@datadog/browser-logs": "5.17.1"
|
|
43
44
|
},
|
|
44
45
|
"packageManager": "pnpm@8.3.1",
|
|
45
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "2c92a9602d19642da79d7624d9735f0562352c8f"
|
|
46
47
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { error } from './error';
|
|
1
|
+
import { userJourney } from './modules/user-journey';
|
|
2
|
+
import { error } from './modules/error';
|
|
3
3
|
import { initialize } from './logger';
|
|
4
4
|
|
|
5
5
|
export const Athena = {
|
|
6
6
|
initialize,
|
|
7
7
|
UserJourney: {
|
|
8
|
-
|
|
8
|
+
...userJourney,
|
|
9
9
|
},
|
|
10
10
|
Error: {
|
|
11
11
|
error,
|
package/src/logger.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { datadogLogs } from '@datadog/browser-logs';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
let allowLogging = false;
|
|
2
|
+
import { setInitialized, setAllowLogging } from './shared';
|
|
3
|
+
import { error } from './modules/error';
|
|
5
4
|
|
|
6
5
|
type InitializeParams = {
|
|
7
6
|
clientToken: string;
|
|
@@ -18,14 +17,14 @@ export const initialize = ({
|
|
|
18
17
|
}: InitializeParams) => {
|
|
19
18
|
const isLocalhost = environment === 'localhost';
|
|
20
19
|
if (!environment || !clientToken || !service || !version) {
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
setInitialized(false);
|
|
21
|
+
setAllowLogging(false);
|
|
23
22
|
return;
|
|
24
23
|
}
|
|
25
24
|
|
|
26
25
|
if (isLocalhost) {
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
setInitialized(true);
|
|
27
|
+
setAllowLogging(false);
|
|
29
28
|
return;
|
|
30
29
|
}
|
|
31
30
|
|
|
@@ -41,13 +40,36 @@ export const initialize = ({
|
|
|
41
40
|
version,
|
|
42
41
|
});
|
|
43
42
|
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
// Log rejected Promises without a .catch() handler
|
|
44
|
+
window.addEventListener('unhandledrejection', (event) => {
|
|
45
|
+
event.preventDefault();
|
|
46
|
+
const message = `Promise rejected and uncaught; reason: ${event.reason}`;
|
|
47
|
+
error({
|
|
48
|
+
context: 'window/onunhandledrejection',
|
|
49
|
+
error: new Error(message),
|
|
50
|
+
message,
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// Log rejected Promises that are caught late (handler attached at a later time)
|
|
55
|
+
window.addEventListener(
|
|
56
|
+
'rejectionhandled',
|
|
57
|
+
(event) => {
|
|
58
|
+
event.preventDefault();
|
|
59
|
+
const message = `Promise rejected and caught late; reason: ${event.reason}`;
|
|
60
|
+
error({
|
|
61
|
+
context: 'window/onrejectionhandled',
|
|
62
|
+
error: new Error(message),
|
|
63
|
+
message,
|
|
64
|
+
});
|
|
65
|
+
},
|
|
66
|
+
false,
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
setInitialized(true);
|
|
70
|
+
setAllowLogging(true);
|
|
46
71
|
} catch (err) {
|
|
47
|
-
|
|
48
|
-
|
|
72
|
+
setInitialized(false);
|
|
73
|
+
setAllowLogging(false);
|
|
49
74
|
}
|
|
50
75
|
};
|
|
51
|
-
|
|
52
|
-
export const isLoggerInitialized = () => initialized;
|
|
53
|
-
export const isLoggingAllowed = () => allowLogging;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { datadogLogs } from '@datadog/browser-logs';
|
|
2
|
-
import { isLoggerInitialized } from '
|
|
2
|
+
import { isLoggerInitialized } from '../../shared';
|
|
3
3
|
|
|
4
4
|
type LogErrorParams = {
|
|
5
|
-
|
|
5
|
+
context: string;
|
|
6
6
|
error: unknown;
|
|
7
7
|
walletAddress?: string;
|
|
8
8
|
// Optional! If not provided, will try to extract message from Error
|
|
@@ -11,7 +11,7 @@ type LogErrorParams = {
|
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
export const error = ({
|
|
14
|
-
|
|
14
|
+
context,
|
|
15
15
|
message,
|
|
16
16
|
metadata,
|
|
17
17
|
walletAddress,
|
|
@@ -23,7 +23,7 @@ export const error = ({
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
datadogLogs.logger.error(
|
|
26
|
-
`athena.error/${
|
|
26
|
+
`athena.error/${context}${message ? `: ${message}` : ''}`,
|
|
27
27
|
{ ...metadata, ...(walletAddress && { user: { walletAddress } }) },
|
|
28
28
|
error as Error,
|
|
29
29
|
);
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { datadogLogs } from '@datadog/browser-logs';
|
|
2
|
+
import { isLoggerInitialized } from '../../shared';
|
|
3
|
+
import {
|
|
4
|
+
clear,
|
|
5
|
+
getChainId,
|
|
6
|
+
getWalletAddress,
|
|
7
|
+
initialize,
|
|
8
|
+
setChainId,
|
|
9
|
+
} from './state';
|
|
10
|
+
|
|
11
|
+
export type UserJourneyActionParams = {
|
|
12
|
+
walletAddress: string;
|
|
13
|
+
action: string;
|
|
14
|
+
error?: Error | unknown;
|
|
15
|
+
message?: string;
|
|
16
|
+
payload?: Record<string, unknown>;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const action = ({
|
|
20
|
+
action,
|
|
21
|
+
error,
|
|
22
|
+
message,
|
|
23
|
+
payload,
|
|
24
|
+
}: UserJourneyActionParams) => {
|
|
25
|
+
const walletAddress = getWalletAddress();
|
|
26
|
+
const chainId = getChainId();
|
|
27
|
+
|
|
28
|
+
if (!walletAddress) {
|
|
29
|
+
console.warn('Logger missing wallet address');
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (!chainId) {
|
|
34
|
+
console.warn('Logger missing chainId');
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (!isLoggerInitialized()) {
|
|
39
|
+
console.warn('Logger not initialized');
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
datadogLogs.logger.info(
|
|
44
|
+
`athena.user_journey/${action}${message ? `: ${message}` : ''}`,
|
|
45
|
+
{
|
|
46
|
+
...payload,
|
|
47
|
+
user: {
|
|
48
|
+
walletAddress,
|
|
49
|
+
chainId,
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
error as Error,
|
|
53
|
+
);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const start = (address: string, chainId: string) => {
|
|
57
|
+
if (!isLoggerInitialized()) {
|
|
58
|
+
console.warn('Logger not initialized');
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
initialize(address, chainId);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const switchChain = (chainId: string) => {
|
|
66
|
+
if (!isLoggerInitialized()) {
|
|
67
|
+
console.warn('Logger not initialized');
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
setChainId(chainId);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const stop = () => {
|
|
75
|
+
if (!isLoggerInitialized()) {
|
|
76
|
+
console.warn('Logger not initialized');
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
clear();
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export const userJourney = {
|
|
84
|
+
action,
|
|
85
|
+
start,
|
|
86
|
+
switchChain,
|
|
87
|
+
stop,
|
|
88
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
type UserJourneyState = {
|
|
2
|
+
walletAddress: string | null;
|
|
3
|
+
chainId: string | null;
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
const state: UserJourneyState = {
|
|
7
|
+
walletAddress: null,
|
|
8
|
+
chainId: null,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const initialize = (walletAddress: string, chainId: string) => {
|
|
12
|
+
state.walletAddress = walletAddress;
|
|
13
|
+
state.chainId = chainId;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const getWalletAddress = () => state.walletAddress;
|
|
17
|
+
const getChainId = () => state.chainId;
|
|
18
|
+
|
|
19
|
+
const setWalletAddress = (walletAddress: string) => {
|
|
20
|
+
state.walletAddress = walletAddress;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const setChainId = (chainId: string) => {
|
|
24
|
+
state.chainId = chainId;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const clear = () => {
|
|
28
|
+
state.walletAddress = null;
|
|
29
|
+
state.chainId = null;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export {
|
|
33
|
+
initialize,
|
|
34
|
+
getWalletAddress,
|
|
35
|
+
getChainId,
|
|
36
|
+
setWalletAddress,
|
|
37
|
+
setChainId,
|
|
38
|
+
clear,
|
|
39
|
+
};
|
package/src/shared.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export let initialized = false;
|
|
2
|
+
export let allowLogging = false;
|
|
3
|
+
|
|
4
|
+
export const setInitialized = (value: boolean) => {
|
|
5
|
+
initialized = value;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export const setAllowLogging = (value: boolean) => {
|
|
9
|
+
allowLogging = value;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const isLoggerInitialized = () => initialized;
|
package/dist/action.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.action = void 0;
|
|
4
|
-
var browser_logs_1 = require("@datadog/browser-logs");
|
|
5
|
-
var logger_1 = require("./logger");
|
|
6
|
-
var checkWalletAddress_1 = require("./utils/checkWalletAddress");
|
|
7
|
-
var action = function (_a) {
|
|
8
|
-
var walletAddress = _a.walletAddress, action = _a.action, error = _a.error, message = _a.message, payload = _a.payload;
|
|
9
|
-
if (!(0, checkWalletAddress_1.isWalletAddressProvided)(walletAddress)) {
|
|
10
|
-
console.warn('Logger missing wallet address');
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
if (!(0, logger_1.isLoggerInitialized)()) {
|
|
14
|
-
console.warn('Logger not initialized');
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
browser_logs_1.datadogLogs.logger.info("athena.user_journey/".concat(action).concat(message ? ": ".concat(message) : ''), payload, error);
|
|
18
|
-
};
|
|
19
|
-
exports.action = action;
|
|
20
|
-
//# sourceMappingURL=action.js.map
|
package/dist/action.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"action.js","sourceRoot":"/","sources":["action.ts"],"names":[],"mappings":";;;AAAA,sDAAoD;AACpD,mCAA+C;AAC/C,iEAAqE;AAU9D,IAAM,MAAM,GAAG,UAAC,EAMG;QALxB,aAAa,mBAAA,EACb,MAAM,YAAA,EACN,KAAK,WAAA,EACL,OAAO,aAAA,EACP,OAAO,aAAA;IAEP,IAAI,CAAC,IAAA,4CAAuB,EAAC,aAAa,CAAC,EAAE,CAAC;QAC5C,OAAO,CAAC,IAAI,CAAC,+BAA+B,CAAC,CAAC;QAC9C,OAAO;IACT,CAAC;IAED,IAAI,CAAC,IAAA,4BAAmB,GAAE,EAAE,CAAC;QAC3B,OAAO,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;QACvC,OAAO;IACT,CAAC;IAED,0BAAW,CAAC,MAAM,CAAC,IAAI,CACrB,8BAAuB,MAAM,SAAG,OAAO,CAAC,CAAC,CAAC,YAAK,OAAO,CAAE,CAAC,CAAC,CAAC,EAAE,CAAE,EAC/D,OAAO,EACP,KAAc,CACf,CAAC;AACJ,CAAC,CAAC;AAtBW,QAAA,MAAM,UAsBjB","sourcesContent":["import { datadogLogs } from '@datadog/browser-logs';\nimport { isLoggerInitialized } from './logger';\nimport { isWalletAddressProvided } from './utils/checkWalletAddress';\n\nexport type UserJourneyActionParams = {\n walletAddress: string;\n action: string;\n error?: Error | unknown;\n message?: string;\n payload?: Record<string, unknown>;\n};\n\nexport const action = ({\n walletAddress,\n action,\n error,\n message,\n payload,\n}: UserJourneyActionParams) => {\n if (!isWalletAddressProvided(walletAddress)) {\n console.warn('Logger missing wallet address');\n return;\n }\n\n if (!isLoggerInitialized()) {\n console.warn('Logger not initialized');\n return;\n }\n\n datadogLogs.logger.info(\n `athena.user_journey/${action}${message ? `: ${message}` : ''}`,\n payload,\n error as Error,\n );\n};\n"]}
|
package/dist/error.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","sourceRoot":"/","sources":["error.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,sDAAoD;AACpD,mCAA+C;AAWxC,IAAM,KAAK,GAAG,UAAC,EAML;QALf,MAAM,YAAA,EACN,OAAO,aAAA,EACP,QAAQ,cAAA,EACR,aAAa,mBAAA,EACb,KAAK,WAAA;IAEL,IAAI,CAAC,IAAA,4BAAmB,GAAE,EAAE,CAAC;QAC3B,OAAO,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;QACvC,OAAO;IACT,CAAC;IAED,0BAAW,CAAC,MAAM,CAAC,KAAK,CACtB,uBAAgB,MAAM,SAAG,OAAO,CAAC,CAAC,CAAC,YAAK,OAAO,CAAE,CAAC,CAAC,CAAC,EAAE,CAAE,wBACnD,QAAQ,GAAK,CAAC,aAAa,IAAI,EAAE,IAAI,EAAE,EAAE,aAAa,eAAA,EAAE,EAAE,CAAC,GAChE,KAAc,CACf,CAAC;AACJ,CAAC,CAAC;AAjBW,QAAA,KAAK,SAiBhB","sourcesContent":["import { datadogLogs } from '@datadog/browser-logs';\nimport { isLoggerInitialized } from './logger';\n\ntype LogErrorParams = {\n action: string;\n error: unknown;\n walletAddress?: string;\n // Optional! If not provided, will try to extract message from Error\n message?: string;\n metadata?: Record<string, unknown>;\n};\n\nexport const error = ({\n action,\n message,\n metadata,\n walletAddress,\n error,\n}: LogErrorParams) => {\n if (!isLoggerInitialized()) {\n console.warn('Logger not initialized');\n return;\n }\n\n datadogLogs.logger.error(\n `athena.error/${action}${message ? `: ${message}` : ''}`,\n { ...metadata, ...(walletAddress && { user: { walletAddress } }) },\n error as Error,\n );\n};\n"]}
|
package/dist/types/action.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export type UserJourneyActionParams = {
|
|
2
|
-
walletAddress: string;
|
|
3
|
-
action: string;
|
|
4
|
-
error?: Error | unknown;
|
|
5
|
-
message?: string;
|
|
6
|
-
payload?: Record<string, unknown>;
|
|
7
|
-
};
|
|
8
|
-
export declare const action: ({ walletAddress, action, error, message, payload, }: UserJourneyActionParams) => void;
|
|
9
|
-
//# sourceMappingURL=action.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"action.d.ts","sourceRoot":"/","sources":["action.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,uBAAuB,GAAG;IACpC,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,KAAK,GAAG,OAAO,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC,CAAC;AAEF,eAAO,MAAM,MAAM,wDAMhB,uBAAuB,SAgBzB,CAAC"}
|
package/dist/types/error.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
type LogErrorParams = {
|
|
2
|
-
action: string;
|
|
3
|
-
error: unknown;
|
|
4
|
-
walletAddress?: string;
|
|
5
|
-
message?: string;
|
|
6
|
-
metadata?: Record<string, unknown>;
|
|
7
|
-
};
|
|
8
|
-
export declare const error: ({ action, message, metadata, walletAddress, error, }: LogErrorParams) => void;
|
|
9
|
-
export {};
|
|
10
|
-
//# sourceMappingURL=error.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"error.d.ts","sourceRoot":"/","sources":["error.ts"],"names":[],"mappings":"AAGA,KAAK,cAAc,GAAG;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,OAAO,CAAC;IACf,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC,CAAC;AAEF,eAAO,MAAM,KAAK,yDAMf,cAAc,SAWhB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["utils/checkWalletAddress/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,uBAAuB,kBAAmB,MAAM,YACrC,CAAC"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isWalletAddressProvided = void 0;
|
|
4
|
-
var isWalletAddressProvided = function (walletAddress) {
|
|
5
|
-
return Boolean(walletAddress);
|
|
6
|
-
};
|
|
7
|
-
exports.isWalletAddressProvided = isWalletAddressProvided;
|
|
8
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["utils/checkWalletAddress/index.ts"],"names":[],"mappings":";;;AAAO,IAAM,uBAAuB,GAAG,UAAC,aAAqB;IAC3D,OAAA,OAAO,CAAC,aAAa,CAAC;AAAtB,CAAsB,CAAC;AADZ,QAAA,uBAAuB,2BACX","sourcesContent":["export const isWalletAddressProvided = (walletAddress: string) =>\n Boolean(walletAddress);\n"]}
|
package/src/action.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { datadogLogs } from '@datadog/browser-logs';
|
|
2
|
-
import { isLoggerInitialized } from './logger';
|
|
3
|
-
import { isWalletAddressProvided } from './utils/checkWalletAddress';
|
|
4
|
-
|
|
5
|
-
export type UserJourneyActionParams = {
|
|
6
|
-
walletAddress: string;
|
|
7
|
-
action: string;
|
|
8
|
-
error?: Error | unknown;
|
|
9
|
-
message?: string;
|
|
10
|
-
payload?: Record<string, unknown>;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export const action = ({
|
|
14
|
-
walletAddress,
|
|
15
|
-
action,
|
|
16
|
-
error,
|
|
17
|
-
message,
|
|
18
|
-
payload,
|
|
19
|
-
}: UserJourneyActionParams) => {
|
|
20
|
-
if (!isWalletAddressProvided(walletAddress)) {
|
|
21
|
-
console.warn('Logger missing wallet address');
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (!isLoggerInitialized()) {
|
|
26
|
-
console.warn('Logger not initialized');
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
datadogLogs.logger.info(
|
|
31
|
-
`athena.user_journey/${action}${message ? `: ${message}` : ''}`,
|
|
32
|
-
payload,
|
|
33
|
-
error as Error,
|
|
34
|
-
);
|
|
35
|
-
};
|