@reyaxyz/athena-logger 0.2.5 → 0.2.7

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 (41) hide show
  1. package/dist/index.js +14 -5
  2. package/dist/index.js.map +1 -1
  3. package/dist/logger.js +1 -1
  4. package/dist/logger.js.map +1 -1
  5. package/dist/{error.js → modules/error/index.js} +2 -2
  6. package/dist/modules/error/index.js.map +1 -0
  7. package/dist/modules/user-journey/index.js +98 -0
  8. package/dist/modules/user-journey/index.js.map +1 -0
  9. package/dist/modules/user-journey/state.js +30 -0
  10. package/dist/modules/user-journey/state.js.map +1 -0
  11. package/dist/shared.js +1 -3
  12. package/dist/shared.js.map +1 -1
  13. package/dist/types/index.d.ts +8 -1
  14. package/dist/types/index.d.ts.map +1 -1
  15. package/dist/types/{error.d.ts → modules/error/index.d.ts} +1 -1
  16. package/dist/types/modules/error/index.d.ts.map +1 -0
  17. package/dist/types/modules/user-journey/index.d.ts +22 -0
  18. package/dist/types/modules/user-journey/index.d.ts.map +1 -0
  19. package/dist/types/modules/user-journey/state.d.ts +8 -0
  20. package/dist/types/modules/user-journey/state.d.ts.map +1 -0
  21. package/dist/types/shared.d.ts +0 -1
  22. package/dist/types/shared.d.ts.map +1 -1
  23. package/package.json +3 -3
  24. package/src/index.ts +3 -3
  25. package/src/logger.ts +1 -1
  26. package/src/{error.ts → modules/error/index.ts} +1 -1
  27. package/src/modules/user-journey/index.ts +129 -0
  28. package/src/modules/user-journey/state.ts +39 -0
  29. package/src/shared.ts +0 -1
  30. package/dist/action.js +0 -20
  31. package/dist/action.js.map +0 -1
  32. package/dist/error.js.map +0 -1
  33. package/dist/types/action.d.ts +0 -9
  34. package/dist/types/action.d.ts.map +0 -1
  35. package/dist/types/error.d.ts.map +0 -1
  36. package/dist/types/utils/checkWalletAddress/index.d.ts +0 -2
  37. package/dist/types/utils/checkWalletAddress/index.d.ts.map +0 -1
  38. package/dist/utils/checkWalletAddress/index.js +0 -8
  39. package/dist/utils/checkWalletAddress/index.js.map +0 -1
  40. package/src/action.ts +0 -35
  41. 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 action_1 = require("./action");
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":";;;AAAA,mCAAkC;AAClC,iCAAgC;AAChC,mCAAsC;AAEzB,QAAA,MAAM,GAAG;IACpB,UAAU,qBAAA;IACV,WAAW,EAAE;QACX,MAAM,iBAAA;KACP;IACD,KAAK,EAAE;QACL,KAAK,eAAA;KACN;CACF,CAAC","sourcesContent":["import { action } from './action';\nimport { error } from './error';\nimport { initialize } from './logger';\n\nexport const Athena = {\n initialize,\n UserJourney: {\n action,\n },\n Error: {\n error,\n },\n};\n"]}
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
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.initialize = void 0;
4
4
  var browser_logs_1 = require("@datadog/browser-logs");
5
5
  var shared_1 = require("./shared");
6
- var error_1 = require("./error");
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';
@@ -1 +1 @@
1
- {"version":3,"file":"logger.js","sourceRoot":"/","sources":["logger.ts"],"names":[],"mappings":";;;AAAA,sDAAoD;AACpD,mCAA2D;AAC3D,iCAAgC;AASzB,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 './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"]}
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,7 +13,7 @@ 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 shared_1 = require("./shared");
16
+ var shared_1 = require("../../shared");
17
17
  var error = function (_a) {
18
18
  var context = _a.context, message = _a.message, metadata = _a.metadata, walletAddress = _a.walletAddress, error = _a.error;
19
19
  if (!(0, shared_1.isLoggerInitialized)()) {
@@ -23,4 +23,4 @@ var error = function (_a) {
23
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=error.js.map
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,98 @@
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, 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
+ } }));
38
+ };
39
+ var error = function (_a) {
40
+ var action = _a.action, error = _a.error, message = _a.message, payload = _a.payload;
41
+ var walletAddress = (0, state_1.getWalletAddress)();
42
+ var chainId = (0, state_1.getChainId)();
43
+ if (!walletAddress) {
44
+ console.warn('Logger missing wallet address');
45
+ return;
46
+ }
47
+ if (!chainId) {
48
+ console.warn('Logger missing chainId');
49
+ return;
50
+ }
51
+ if (!(0, shared_1.isLoggerInitialized)()) {
52
+ console.warn('Logger not initialized');
53
+ return;
54
+ }
55
+ browser_logs_1.datadogLogs.logger.error("athena.user_journey/".concat(action).concat(message ? ": ".concat(message) : ''), __assign(__assign({}, payload), { user: {
56
+ walletAddress: walletAddress,
57
+ chainId: chainId,
58
+ } }), error);
59
+ };
60
+ var start = function (_a) {
61
+ var address = _a.address, chainId = _a.chainId;
62
+ if (!(0, shared_1.isLoggerInitialized)()) {
63
+ console.warn('Logger not initialized');
64
+ return;
65
+ }
66
+ (0, state_1.initialize)(address, chainId);
67
+ action({
68
+ action: 'wallet_connected',
69
+ });
70
+ };
71
+ var switchChain = function (chainId) {
72
+ if (!(0, shared_1.isLoggerInitialized)()) {
73
+ console.warn('Logger not initialized');
74
+ return;
75
+ }
76
+ (0, state_1.setChainId)(chainId);
77
+ action({
78
+ action: "chain_changed",
79
+ });
80
+ };
81
+ var stop = function () {
82
+ if (!(0, shared_1.isLoggerInitialized)()) {
83
+ console.warn('Logger not initialized');
84
+ return;
85
+ }
86
+ action({
87
+ action: 'wallet_disconnected',
88
+ });
89
+ (0, state_1.clear)();
90
+ };
91
+ exports.userJourney = {
92
+ action: action,
93
+ error: error,
94
+ start: start,
95
+ switchChain: switchChain,
96
+ stop: stop,
97
+ };
98
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["modules/user-journey/index.ts"],"names":[],"mappings":"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","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 action: string;\n message?: string;\n payload?: Record<string, unknown>;\n};\n\nexport type UserJourneyErrorParams = {\n action: string;\n error: Error | unknown;\n message?: string;\n payload?: Record<string, unknown>;\n};\n\nconst action = ({ action, message, payload }: 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 );\n};\n\nconst error = ({ action, error, message, payload }: UserJourneyErrorParams) => {\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.error(\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, chainId }: { address: string; chainId: number }) => {\n if (!isLoggerInitialized()) {\n console.warn('Logger not initialized');\n return;\n }\n\n initialize(address, chainId);\n action({\n action: 'wallet_connected',\n });\n};\n\nconst switchChain = (chainId: number) => {\n if (!isLoggerInitialized()) {\n console.warn('Logger not initialized');\n return;\n }\n\n setChainId(chainId);\n action({\n action: `chain_changed`,\n });\n};\n\nconst stop = () => {\n if (!isLoggerInitialized()) {\n console.warn('Logger not initialized');\n return;\n }\n\n action({\n action: 'wallet_disconnected',\n });\n clear();\n};\n\nexport const userJourney = {\n action,\n error,\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: number | null;\n};\n\nconst state: UserJourneyState = {\n walletAddress: null,\n chainId: null,\n};\n\nconst initialize = (walletAddress: string, chainId: number) => {\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: number) => {\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 CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isLoggingAllowed = exports.isLoggerInitialized = exports.setAllowLogging = exports.setInitialized = exports.allowLogging = exports.initialized = void 0;
3
+ exports.isLoggerInitialized = exports.setAllowLogging = exports.setInitialized = exports.allowLogging = exports.initialized = void 0;
4
4
  exports.initialized = false;
5
5
  exports.allowLogging = false;
6
6
  var setInitialized = function (value) {
@@ -13,6 +13,4 @@ var setAllowLogging = function (value) {
13
13
  exports.setAllowLogging = setAllowLogging;
14
14
  var isLoggerInitialized = function () { return exports.initialized; };
15
15
  exports.isLoggerInitialized = isLoggerInitialized;
16
- var isLoggingAllowed = function () { return exports.allowLogging; };
17
- exports.isLoggingAllowed = isLoggingAllowed;
18
16
  //# sourceMappingURL=shared.js.map
@@ -1 +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;AAC9C,IAAM,gBAAgB,GAAG,cAAM,OAAA,oBAAY,EAAZ,CAAY,CAAC;AAAtC,QAAA,gBAAgB,oBAAsB","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;\nexport const isLoggingAllowed = () => allowLogging;\n"]}
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"]}
@@ -6,7 +6,14 @@ export declare const Athena: {
6
6
  version: string;
7
7
  }) => void;
8
8
  UserJourney: {
9
- action: ({ walletAddress, action, error, message, payload, }: import("./action").UserJourneyActionParams) => void;
9
+ action: ({ action, message, payload }: import("./modules/user-journey").UserJourneyActionParams) => void;
10
+ error: ({ action, error, message, payload }: import("./modules/user-journey").UserJourneyErrorParams) => void;
11
+ start: ({ address, chainId }: {
12
+ address: string;
13
+ chainId: number;
14
+ }) => void;
15
+ switchChain: (chainId: number) => void;
16
+ stop: () => void;
10
17
  };
11
18
  Error: {
12
19
  error: ({ context, message, metadata, walletAddress, error, }: {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;CAQlB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;CAQlB,CAAC"}
@@ -7,4 +7,4 @@ type LogErrorParams = {
7
7
  };
8
8
  export declare const error: ({ context, message, metadata, walletAddress, error, }: LogErrorParams) => void;
9
9
  export {};
10
- //# sourceMappingURL=error.d.ts.map
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,22 @@
1
+ export type UserJourneyActionParams = {
2
+ action: string;
3
+ message?: string;
4
+ payload?: Record<string, unknown>;
5
+ };
6
+ export type UserJourneyErrorParams = {
7
+ action: string;
8
+ error: Error | unknown;
9
+ message?: string;
10
+ payload?: Record<string, unknown>;
11
+ };
12
+ export declare const userJourney: {
13
+ action: ({ action, message, payload }: UserJourneyActionParams) => void;
14
+ error: ({ action, error, message, payload }: UserJourneyErrorParams) => void;
15
+ start: ({ address, chainId }: {
16
+ address: string;
17
+ chainId: number;
18
+ }) => void;
19
+ switchChain: (chainId: number) => void;
20
+ stop: () => void;
21
+ };
22
+ //# 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,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC,CAAC;AAqGF,eAAO,MAAM,WAAW;2CAnGsB,uBAAuB;iDA+BjB,sBAAsB;;iBAgC1B,MAAM;iBAAW,MAAM;;2BAYzC,MAAM;;CA8BnC,CAAC"}
@@ -0,0 +1,8 @@
1
+ declare const initialize: (walletAddress: string, chainId: number) => void;
2
+ declare const getWalletAddress: () => string | null;
3
+ declare const getChainId: () => number | null;
4
+ declare const setWalletAddress: (walletAddress: string) => void;
5
+ declare const setChainId: (chainId: number) => 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"}
@@ -3,5 +3,4 @@ export declare let allowLogging: boolean;
3
3
  export declare const setInitialized: (value: boolean) => void;
4
4
  export declare const setAllowLogging: (value: boolean) => void;
5
5
  export declare const isLoggerInitialized: () => boolean;
6
- export declare const isLoggingAllowed: () => boolean;
7
6
  //# sourceMappingURL=shared.d.ts.map
@@ -1 +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;AACrD,eAAO,MAAM,gBAAgB,eAAqB,CAAC"}
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.5",
3
+ "version": "0.2.7",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "registry": "https://registry.npmjs.org"
@@ -33,7 +33,7 @@
33
33
  "generate:coverage-badges": "npx istanbul-badges-readme --silent"
34
34
  },
35
35
  "dependencies": {
36
- "@reyaxyz/common": "0.114.0"
36
+ "@reyaxyz/common": "0.115.0"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@datadog/browser-logs": "5.17.1",
@@ -43,5 +43,5 @@
43
43
  "@datadog/browser-logs": "5.17.1"
44
44
  },
45
45
  "packageManager": "pnpm@8.3.1",
46
- "gitHead": "93c8205da61e548a36cee49c6ac36df26fe34907"
46
+ "gitHead": "caf5873970c9e5504155ac492f124d81a63e9d39"
47
47
  }
package/src/index.ts CHANGED
@@ -1,11 +1,11 @@
1
- import { action } from './action';
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
- action,
8
+ ...userJourney,
9
9
  },
10
10
  Error: {
11
11
  error,
package/src/logger.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { datadogLogs } from '@datadog/browser-logs';
2
2
  import { setInitialized, setAllowLogging } from './shared';
3
- import { error } from './error';
3
+ import { error } from './modules/error';
4
4
 
5
5
  type InitializeParams = {
6
6
  clientToken: string;
@@ -1,5 +1,5 @@
1
1
  import { datadogLogs } from '@datadog/browser-logs';
2
- import { isLoggerInitialized } from './shared';
2
+ import { isLoggerInitialized } from '../../shared';
3
3
 
4
4
  type LogErrorParams = {
5
5
  context: string;
@@ -0,0 +1,129 @@
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
+ action: string;
13
+ message?: string;
14
+ payload?: Record<string, unknown>;
15
+ };
16
+
17
+ export type UserJourneyErrorParams = {
18
+ action: string;
19
+ error: Error | unknown;
20
+ message?: string;
21
+ payload?: Record<string, unknown>;
22
+ };
23
+
24
+ const action = ({ action, message, payload }: 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
+ );
53
+ };
54
+
55
+ const error = ({ action, error, message, payload }: UserJourneyErrorParams) => {
56
+ const walletAddress = getWalletAddress();
57
+ const chainId = getChainId();
58
+
59
+ if (!walletAddress) {
60
+ console.warn('Logger missing wallet address');
61
+ return;
62
+ }
63
+
64
+ if (!chainId) {
65
+ console.warn('Logger missing chainId');
66
+ return;
67
+ }
68
+
69
+ if (!isLoggerInitialized()) {
70
+ console.warn('Logger not initialized');
71
+ return;
72
+ }
73
+
74
+ datadogLogs.logger.error(
75
+ `athena.user_journey/${action}${message ? `: ${message}` : ''}`,
76
+ {
77
+ ...payload,
78
+ user: {
79
+ walletAddress,
80
+ chainId,
81
+ },
82
+ },
83
+ error as Error,
84
+ );
85
+ };
86
+
87
+ const start = ({ address, chainId }: { address: string; chainId: number }) => {
88
+ if (!isLoggerInitialized()) {
89
+ console.warn('Logger not initialized');
90
+ return;
91
+ }
92
+
93
+ initialize(address, chainId);
94
+ action({
95
+ action: 'wallet_connected',
96
+ });
97
+ };
98
+
99
+ const switchChain = (chainId: number) => {
100
+ if (!isLoggerInitialized()) {
101
+ console.warn('Logger not initialized');
102
+ return;
103
+ }
104
+
105
+ setChainId(chainId);
106
+ action({
107
+ action: `chain_changed`,
108
+ });
109
+ };
110
+
111
+ const stop = () => {
112
+ if (!isLoggerInitialized()) {
113
+ console.warn('Logger not initialized');
114
+ return;
115
+ }
116
+
117
+ action({
118
+ action: 'wallet_disconnected',
119
+ });
120
+ clear();
121
+ };
122
+
123
+ export const userJourney = {
124
+ action,
125
+ error,
126
+ start,
127
+ switchChain,
128
+ stop,
129
+ };
@@ -0,0 +1,39 @@
1
+ type UserJourneyState = {
2
+ walletAddress: string | null;
3
+ chainId: number | null;
4
+ };
5
+
6
+ const state: UserJourneyState = {
7
+ walletAddress: null,
8
+ chainId: null,
9
+ };
10
+
11
+ const initialize = (walletAddress: string, chainId: number) => {
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: number) => {
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 CHANGED
@@ -10,4 +10,3 @@ export const setAllowLogging = (value: boolean) => {
10
10
  };
11
11
 
12
12
  export const isLoggerInitialized = () => initialized;
13
- export const isLoggingAllowed = () => allowLogging;
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 shared_1 = require("./shared");
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, shared_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
@@ -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 './shared';\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,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"]}
@@ -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"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"error.d.ts","sourceRoot":"/","sources":["error.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"}
@@ -1,2 +0,0 @@
1
- export declare const isWalletAddressProvided: (walletAddress: string) => boolean;
2
- //# sourceMappingURL=index.d.ts.map
@@ -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 './shared';
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
- };
@@ -1,2 +0,0 @@
1
- export const isWalletAddressProvided = (walletAddress: string) =>
2
- Boolean(walletAddress);