@reyaxyz/athena-logger 0.2.6 → 0.2.8
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/modules/user-journey/index.js +34 -2
- package/dist/modules/user-journey/index.js.map +1 -1
- package/dist/modules/user-journey/state.js.map +1 -1
- package/dist/types/index.d.ts +7 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/modules/user-journey/index.d.ts +13 -5
- package/dist/types/modules/user-journey/index.d.ts.map +1 -1
- package/dist/types/modules/user-journey/state.d.ts +3 -3
- package/package.json +3 -3
- package/src/modules/user-journey/index.ts +51 -10
- package/src/modules/user-journey/state.ts +3 -3
|
@@ -16,7 +16,7 @@ var browser_logs_1 = require("@datadog/browser-logs");
|
|
|
16
16
|
var shared_1 = require("../../shared");
|
|
17
17
|
var state_1 = require("./state");
|
|
18
18
|
var action = function (_a) {
|
|
19
|
-
var action = _a.action,
|
|
19
|
+
var action = _a.action, message = _a.message, payload = _a.payload;
|
|
20
20
|
var walletAddress = (0, state_1.getWalletAddress)();
|
|
21
21
|
var chainId = (0, state_1.getChainId)();
|
|
22
22
|
if (!walletAddress) {
|
|
@@ -34,14 +34,39 @@ var action = function (_a) {
|
|
|
34
34
|
browser_logs_1.datadogLogs.logger.info("athena.user_journey/".concat(action).concat(message ? ": ".concat(message) : ''), __assign(__assign({}, payload), { user: {
|
|
35
35
|
walletAddress: walletAddress,
|
|
36
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,
|
|
37
58
|
} }), error);
|
|
38
59
|
};
|
|
39
|
-
var start = function (
|
|
60
|
+
var start = function (_a) {
|
|
61
|
+
var address = _a.address, chainId = _a.chainId;
|
|
40
62
|
if (!(0, shared_1.isLoggerInitialized)()) {
|
|
41
63
|
console.warn('Logger not initialized');
|
|
42
64
|
return;
|
|
43
65
|
}
|
|
44
66
|
(0, state_1.initialize)(address, chainId);
|
|
67
|
+
action({
|
|
68
|
+
action: 'wallet_connected',
|
|
69
|
+
});
|
|
45
70
|
};
|
|
46
71
|
var switchChain = function (chainId) {
|
|
47
72
|
if (!(0, shared_1.isLoggerInitialized)()) {
|
|
@@ -49,16 +74,23 @@ var switchChain = function (chainId) {
|
|
|
49
74
|
return;
|
|
50
75
|
}
|
|
51
76
|
(0, state_1.setChainId)(chainId);
|
|
77
|
+
action({
|
|
78
|
+
action: "chain_changed",
|
|
79
|
+
});
|
|
52
80
|
};
|
|
53
81
|
var stop = function () {
|
|
54
82
|
if (!(0, shared_1.isLoggerInitialized)()) {
|
|
55
83
|
console.warn('Logger not initialized');
|
|
56
84
|
return;
|
|
57
85
|
}
|
|
86
|
+
action({
|
|
87
|
+
action: 'wallet_disconnected',
|
|
88
|
+
});
|
|
58
89
|
(0, state_1.clear)();
|
|
59
90
|
};
|
|
60
91
|
exports.userJourney = {
|
|
61
92
|
action: action,
|
|
93
|
+
error: error,
|
|
62
94
|
start: start,
|
|
63
95
|
switchChain: switchChain,
|
|
64
96
|
stop: stop,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["modules/user-journey/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,sDAAoD;AACpD,uCAAmD;AACnD,iCAMiB;
|
|
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"]}
|
|
@@ -1 +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:
|
|
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/types/index.d.ts
CHANGED
|
@@ -6,9 +6,13 @@ export declare const Athena: {
|
|
|
6
6
|
version: string;
|
|
7
7
|
}) => void;
|
|
8
8
|
UserJourney: {
|
|
9
|
-
action: ({ action,
|
|
10
|
-
|
|
11
|
-
|
|
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;
|
|
12
16
|
stop: () => void;
|
|
13
17
|
};
|
|
14
18
|
Error: {
|
|
@@ -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"}
|
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
export type UserJourneyActionParams = {
|
|
2
|
-
walletAddress: string;
|
|
3
2
|
action: string;
|
|
4
|
-
|
|
3
|
+
message?: string;
|
|
4
|
+
payload?: Record<string, unknown>;
|
|
5
|
+
};
|
|
6
|
+
export type UserJourneyErrorParams = {
|
|
7
|
+
action: string;
|
|
8
|
+
error: Error | unknown;
|
|
5
9
|
message?: string;
|
|
6
10
|
payload?: Record<string, unknown>;
|
|
7
11
|
};
|
|
8
12
|
export declare const userJourney: {
|
|
9
|
-
action: ({ action,
|
|
10
|
-
|
|
11
|
-
|
|
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;
|
|
12
20
|
stop: () => void;
|
|
13
21
|
};
|
|
14
22
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["modules/user-journey/index.ts"],"names":[],"mappings":"AAUA,MAAM,MAAM,uBAAuB,GAAG;IACpC,
|
|
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"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
declare const initialize: (walletAddress: string, chainId:
|
|
1
|
+
declare const initialize: (walletAddress: string, chainId: number) => void;
|
|
2
2
|
declare const getWalletAddress: () => string | null;
|
|
3
|
-
declare const getChainId: () =>
|
|
3
|
+
declare const getChainId: () => number | null;
|
|
4
4
|
declare const setWalletAddress: (walletAddress: string) => void;
|
|
5
|
-
declare const setChainId: (chainId:
|
|
5
|
+
declare const setChainId: (chainId: number) => void;
|
|
6
6
|
declare const clear: () => void;
|
|
7
7
|
export { initialize, getWalletAddress, getChainId, setWalletAddress, setChainId, clear, };
|
|
8
8
|
//# sourceMappingURL=state.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reyaxyz/athena-logger",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.8",
|
|
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.
|
|
36
|
+
"@reyaxyz/common": "0.116.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": "
|
|
46
|
+
"gitHead": "451f5ad174f0ba7adb3404c5e5660e6c1bdbf6cd"
|
|
47
47
|
}
|
|
@@ -9,19 +9,19 @@ import {
|
|
|
9
9
|
} from './state';
|
|
10
10
|
|
|
11
11
|
export type UserJourneyActionParams = {
|
|
12
|
-
walletAddress: string;
|
|
13
12
|
action: string;
|
|
14
|
-
error?: Error | unknown;
|
|
15
13
|
message?: string;
|
|
16
14
|
payload?: Record<string, unknown>;
|
|
17
15
|
};
|
|
18
16
|
|
|
19
|
-
|
|
20
|
-
action
|
|
21
|
-
error
|
|
22
|
-
message
|
|
23
|
-
payload,
|
|
24
|
-
}
|
|
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
25
|
const walletAddress = getWalletAddress();
|
|
26
26
|
const chainId = getChainId();
|
|
27
27
|
|
|
@@ -49,26 +49,63 @@ const action = ({
|
|
|
49
49
|
chainId,
|
|
50
50
|
},
|
|
51
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
|
+
},
|
|
52
83
|
error as Error,
|
|
53
84
|
);
|
|
54
85
|
};
|
|
55
86
|
|
|
56
|
-
const start = (address: string
|
|
87
|
+
const start = ({ address, chainId }: { address: string; chainId: number }) => {
|
|
57
88
|
if (!isLoggerInitialized()) {
|
|
58
89
|
console.warn('Logger not initialized');
|
|
59
90
|
return;
|
|
60
91
|
}
|
|
61
92
|
|
|
62
93
|
initialize(address, chainId);
|
|
94
|
+
action({
|
|
95
|
+
action: 'wallet_connected',
|
|
96
|
+
});
|
|
63
97
|
};
|
|
64
98
|
|
|
65
|
-
const switchChain = (chainId:
|
|
99
|
+
const switchChain = (chainId: number) => {
|
|
66
100
|
if (!isLoggerInitialized()) {
|
|
67
101
|
console.warn('Logger not initialized');
|
|
68
102
|
return;
|
|
69
103
|
}
|
|
70
104
|
|
|
71
105
|
setChainId(chainId);
|
|
106
|
+
action({
|
|
107
|
+
action: `chain_changed`,
|
|
108
|
+
});
|
|
72
109
|
};
|
|
73
110
|
|
|
74
111
|
const stop = () => {
|
|
@@ -77,11 +114,15 @@ const stop = () => {
|
|
|
77
114
|
return;
|
|
78
115
|
}
|
|
79
116
|
|
|
117
|
+
action({
|
|
118
|
+
action: 'wallet_disconnected',
|
|
119
|
+
});
|
|
80
120
|
clear();
|
|
81
121
|
};
|
|
82
122
|
|
|
83
123
|
export const userJourney = {
|
|
84
124
|
action,
|
|
125
|
+
error,
|
|
85
126
|
start,
|
|
86
127
|
switchChain,
|
|
87
128
|
stop,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
type UserJourneyState = {
|
|
2
2
|
walletAddress: string | null;
|
|
3
|
-
chainId:
|
|
3
|
+
chainId: number | null;
|
|
4
4
|
};
|
|
5
5
|
|
|
6
6
|
const state: UserJourneyState = {
|
|
@@ -8,7 +8,7 @@ const state: UserJourneyState = {
|
|
|
8
8
|
chainId: null,
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
-
const initialize = (walletAddress: string, chainId:
|
|
11
|
+
const initialize = (walletAddress: string, chainId: number) => {
|
|
12
12
|
state.walletAddress = walletAddress;
|
|
13
13
|
state.chainId = chainId;
|
|
14
14
|
};
|
|
@@ -20,7 +20,7 @@ const setWalletAddress = (walletAddress: string) => {
|
|
|
20
20
|
state.walletAddress = walletAddress;
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
-
const setChainId = (chainId:
|
|
23
|
+
const setChainId = (chainId: number) => {
|
|
24
24
|
state.chainId = chainId;
|
|
25
25
|
};
|
|
26
26
|
|