@wandzai/utils 1.0.33 → 1.0.35-test-encode-uri
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/package.json +1 -1
- package/src/encrypt-decrypt.js +2 -2
- package/src/http.d.ts +1 -1
- package/src/http.js +9 -4
- package/src/http.js.map +1 -1
- package/src/logger.d.ts +12 -0
- package/src/logger.js +46 -0
- package/src/logger.js.map +1 -0
package/package.json
CHANGED
package/src/encrypt-decrypt.js
CHANGED
|
@@ -4,13 +4,13 @@ exports.decryptData = exports.encryptData = void 0;
|
|
|
4
4
|
const CryptoJS = require("crypto-js");
|
|
5
5
|
const key = '66807eb6-f5c0-4245-8e4c-0c5d3f80f203';
|
|
6
6
|
const encryptData = (data) => {
|
|
7
|
-
const encryptedData = CryptoJS.
|
|
7
|
+
const encryptedData = CryptoJS.RC4.encrypt(JSON.stringify(data), key).toString();
|
|
8
8
|
return encodeURIComponent(encryptedData);
|
|
9
9
|
};
|
|
10
10
|
exports.encryptData = encryptData;
|
|
11
11
|
const decryptData = (data) => {
|
|
12
12
|
const decodedEncrypted = decodeURIComponent(data);
|
|
13
|
-
const bytes = CryptoJS.
|
|
13
|
+
const bytes = CryptoJS.RC4.decrypt(decodedEncrypted, key);
|
|
14
14
|
return JSON.parse(bytes.toString(CryptoJS.enc.Utf8));
|
|
15
15
|
};
|
|
16
16
|
exports.decryptData = decryptData;
|
package/src/http.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Request } from 'express';
|
|
2
2
|
export declare function getIpFromHttpRequest(req: Request): string;
|
|
3
|
-
export declare function buildUriBodyString(
|
|
3
|
+
export declare function buildUriBodyString(queryParams: Record<string, any>): string;
|
|
4
4
|
export declare function getEncodedQueryParams(fullUrl: string): object;
|
package/src/http.js
CHANGED
|
@@ -9,9 +9,9 @@ function getIpFromHttpRequest(req) {
|
|
|
9
9
|
}
|
|
10
10
|
exports.getIpFromHttpRequest = getIpFromHttpRequest;
|
|
11
11
|
;
|
|
12
|
-
function buildUriBodyString(
|
|
13
|
-
return Object.
|
|
14
|
-
.map((
|
|
12
|
+
function buildUriBodyString(queryParams) {
|
|
13
|
+
return Object.keys(queryParams)
|
|
14
|
+
.map((key) => `${encodeURIComponent(key)}=${encodeURIComponent(JSON.stringify(queryParams[key]))}`)
|
|
15
15
|
.join('&');
|
|
16
16
|
}
|
|
17
17
|
exports.buildUriBodyString = buildUriBodyString;
|
|
@@ -24,7 +24,12 @@ function getEncodedQueryParams(fullUrl) {
|
|
|
24
24
|
const queryString = fullUrl.substring(queryStringStartIndex + 1);
|
|
25
25
|
const data = querystring.parse(queryString);
|
|
26
26
|
return Object.keys(data).reduce((acc, key) => {
|
|
27
|
-
|
|
27
|
+
try {
|
|
28
|
+
acc[key] = JSON.parse(data[key]);
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
acc[key] = data[key];
|
|
32
|
+
}
|
|
28
33
|
return acc;
|
|
29
34
|
}, {});
|
|
30
35
|
}
|
package/src/http.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../../../libs/utils/src/http.ts"],"names":[],"mappings":";;;AACA,2CAA2C;AAM3C,SAAgB,oBAAoB,CAAC,GAAY;IAChD,OAAO,GAAG,CAAC,OAAO,CAAC,iBAAiB,CAAC;QACpC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE;QAC7D,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,aAAa,CAAC;AAC7B,CAAC;AAJD,oDAIC;AAAA,CAAC;AAEF,SAAgB,kBAAkB,CAAC,
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../../../libs/utils/src/http.ts"],"names":[],"mappings":";;;AACA,2CAA2C;AAM3C,SAAgB,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ACZ,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;QACtB,CAAC;QACD,OAAO,GAAG,CAAC;IACZ,CAAC,EAAE,EAAE,CAAC,CAAC;AACR,CAAC;AAjBD,sDAiBC"}
|
package/src/logger.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Logger } from 'winston';
|
|
2
|
+
export interface IMeta {
|
|
3
|
+
clientTag?: string;
|
|
4
|
+
domain?: string;
|
|
5
|
+
campaignId?: string;
|
|
6
|
+
userId?: string;
|
|
7
|
+
trackingGuid?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface IEnrichedLogger extends Logger {
|
|
10
|
+
createChildLogger(meta?: IMeta): Logger;
|
|
11
|
+
}
|
|
12
|
+
export declare function customLogger(serviceName: string): IEnrichedLogger;
|
package/src/logger.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.customLogger = void 0;
|
|
4
|
+
const uuid_1 = require("uuid");
|
|
5
|
+
const winston = require("winston");
|
|
6
|
+
const { createLogger, format, transports } = winston;
|
|
7
|
+
const createEnrichedLogger = (serviceName) => {
|
|
8
|
+
const logger = createLogger({
|
|
9
|
+
level: 'debug',
|
|
10
|
+
defaultMeta: { service: serviceName },
|
|
11
|
+
transports: [
|
|
12
|
+
process.env.NX_LOG_READABLE === 'true'
|
|
13
|
+
? new transports.Console({
|
|
14
|
+
format: format.simple(),
|
|
15
|
+
})
|
|
16
|
+
: new transports.Console({
|
|
17
|
+
format: format.json(),
|
|
18
|
+
}),
|
|
19
|
+
],
|
|
20
|
+
});
|
|
21
|
+
return {
|
|
22
|
+
getLogger: () => {
|
|
23
|
+
return logger;
|
|
24
|
+
},
|
|
25
|
+
createChildLogger: (meta) => {
|
|
26
|
+
let combinedMeta = { trackingGuid: (0, uuid_1.v4)() };
|
|
27
|
+
if (meta)
|
|
28
|
+
combinedMeta = { ...combinedMeta, ...meta };
|
|
29
|
+
return logger.child(combinedMeta);
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
function customLogger(serviceName) {
|
|
34
|
+
const enrichedLogger = createEnrichedLogger(serviceName);
|
|
35
|
+
const handler = {
|
|
36
|
+
get: function (target, prop, receiver) {
|
|
37
|
+
if (prop === 'createChildLogger') {
|
|
38
|
+
return target.createChildLogger;
|
|
39
|
+
}
|
|
40
|
+
return target.getLogger()[prop];
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
return new Proxy(enrichedLogger, handler);
|
|
44
|
+
}
|
|
45
|
+
exports.customLogger = customLogger;
|
|
46
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../../libs/utils/src/logger.ts"],"names":[],"mappings":";;;AAAA,+BAAkC;AAClC,mCAAmC;AAGnC,MAAM,EAAC,YAAY,EAAE,MAAM,EAAE,UAAU,EAAC,GAAG,OAAO,CAAC;AAcnD,MAAM,oBAAoB,GAAG,CAAC,WAAmB,EAAE,EAAE;IACjD,MAAM,MAAM,GAAG,YAAY,CAAC;QACxB,KAAK,EAAE,OAAO;QACd,WAAW,EAAE,EAAC,OAAO,EAAE,WAAW,EAAC;QACnC,UAAU,EAAE;YACR,OAAO,CAAC,GAAG,CAAC,eAAe,KAAK,MAAM;gBAClC,CAAC,CAAC,IAAI,UAAU,CAAC,OAAO,CAAC;oBACrB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE;iBAC1B,CAAC;gBACF,CAAC,CAAC,IAAI,UAAU,CAAC,OAAO,CAAC;oBACrB,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE;iBACxB,CAAC;SACT;KACJ,CAAC,CAAC;IAEH,OAAO;QACH,SAAS,EAAE,GAAG,EAAE;YACZ,OAAO,MAAM,CAAC;QAClB,CAAC;QACD,iBAAiB,EAAE,CAA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