@wandzai/utils 1.0.16-platform-and-auth-logic-5 → 1.0.16-platform-and-auth-logic-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.
- package/package.json +2 -2
- package/src/date.d.ts +6 -0
- package/src/date.js +16 -0
- package/src/date.js.map +1 -0
- package/src/gzip.d.ts +1 -0
- package/src/gzip.js +19 -0
- package/src/gzip.js.map +1 -0
- package/src/hash.js +5 -5
- package/src/hash.js.map +1 -1
- package/src/http.d.ts +4 -0
- package/src/http.js +32 -0
- package/src/http.js.map +1 -0
- package/src/snowflake.d.ts +4 -0
- package/src/snowflake.js +25 -0
- package/src/snowflake.js.map +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wandzai/utils",
|
|
3
|
-
"version": "1.0.16-platform-and-auth-logic-
|
|
3
|
+
"version": "1.0.16-platform-and-auth-logic-7",
|
|
4
4
|
"description": "Common used utilities library",
|
|
5
5
|
"main": "src/index",
|
|
6
6
|
"scripts": {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"author": "wandz-ai-team",
|
|
10
10
|
"license": "ISC",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"
|
|
12
|
+
"crypto-js": "^4.2.0",
|
|
13
13
|
"querystring": "^0.2.1"
|
|
14
14
|
}
|
|
15
15
|
}
|
package/src/date.d.ts
ADDED
package/src/date.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calcDatesRange = exports.formatDateYearMonthDay = void 0;
|
|
4
|
+
const formatDateYearMonthDay = (date) => new Date(date).toLocaleDateString('en-CA', { year: 'numeric', month: '2-digit', day: '2-digit' });
|
|
5
|
+
exports.formatDateYearMonthDay = formatDateYearMonthDay;
|
|
6
|
+
const calcDatesRange = (range) => {
|
|
7
|
+
const today = new Date();
|
|
8
|
+
const startDate = new Date(today);
|
|
9
|
+
startDate.setDate(today.getDate() - range);
|
|
10
|
+
return {
|
|
11
|
+
startDate: (0, exports.formatDateYearMonthDay)(startDate),
|
|
12
|
+
endDate: (0, exports.formatDateYearMonthDay)(today),
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
exports.calcDatesRange = calcDatesRange;
|
|
16
|
+
//# sourceMappingURL=date.js.map
|
package/src/date.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date.js","sourceRoot":"","sources":["../../../../libs/utils/src/date.ts"],"names":[],"mappings":";;;AAEO,MAAM,sBAAsB,GAAG,CAAC,IAAmB,EAAE,EAAE,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,kBAAkB,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC,CAAC;AAApJ,QAAA,sBAAsB,0BAA8H;AAE1J,MAAM,cAAc,GAAG,CAC1B,KAAiB,EACnB,EAAE;IACA,MAAM,KAAK,GAAG,IAAI,IAAI,EAAE,CAAC;IACzB,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC;IAClC,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,KAAK,CAAC,CAAC;IAE3C,OAAO;QACH,SAAS,EAAE,IAAA,8BAAsB,EAAC,SAAS,CAAC;QAC5C,OAAO,EAAE,IAAA,8BAAsB,EAAC,KAAK,CAAC;KACzC,CAAC;AACN,CAAC,CAAA;AAXY,QAAA,cAAc,kBAW1B"}
|
package/src/gzip.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function gzipFile(fileIn: string, fileOut: string): Promise<void>;
|
package/src/gzip.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.gzipFile = void 0;
|
|
4
|
+
const zlib_1 = require("zlib");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
function gzipFile(fileIn, fileOut) {
|
|
7
|
+
return new Promise((resolve, reject) => {
|
|
8
|
+
const inp = (0, fs_1.createReadStream)(fileIn);
|
|
9
|
+
const out = (0, fs_1.createWriteStream)(fileOut);
|
|
10
|
+
const gzip = (0, zlib_1.createGzip)();
|
|
11
|
+
inp.pipe(gzip).pipe(out).on('finish', function () {
|
|
12
|
+
resolve();
|
|
13
|
+
}).on('error', function (err) {
|
|
14
|
+
reject(err);
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
exports.gzipFile = gzipFile;
|
|
19
|
+
//# sourceMappingURL=gzip.js.map
|
package/src/gzip.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gzip.js","sourceRoot":"","sources":["../../../../libs/utils/src/gzip.ts"],"names":[],"mappings":";;;AAKA,+BAAgC;AAChC,2BAAuD;AAOvD,SAAgB,QAAQ,CAAC,MAAc,EAAE,OAAe;IACpD,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACzC,MAAM,GAAG,GAAG,IAAA,qBAAgB,EAAC,MAAM,CAAC,CAAC;QACrC,MAAM,GAAG,GAAG,IAAA,sBAAiB,EAAC,OAAO,CAAC,CAAC;QACvC,MAAM,IAAI,GAAG,IAAA,iBAAU,GAAE,CAAC;QAE1B,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,QAAQ,EAAE;YAClC,OAAO,EAAE,CAAC;QACd,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,EAAE,UAAU,GAAG;YACxB,MAAM,CAAC,GAAG,CAAC,CAAC;QAChB,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC;AAZD,4BAYC"}
|
package/src/hash.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.hashData = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const hmacSHA512 = require('crypto-js/hmac-sha512');
|
|
5
|
+
const Base64 = require('crypto-js/enc-base64');
|
|
6
|
+
const hashData = (strToHash, specificSalt) => {
|
|
6
7
|
try {
|
|
7
8
|
const saltPrefix = 'YvSmHe0x5FC90fmk';
|
|
8
|
-
const salt =
|
|
9
|
-
|
|
10
|
-
return hashedPassword.split(',p=')[1];
|
|
9
|
+
const salt = `${saltPrefix}-${specificSalt}`;
|
|
10
|
+
return Base64.stringify(hmacSHA512(strToHash, salt));
|
|
11
11
|
}
|
|
12
12
|
catch (error) {
|
|
13
13
|
console.error('Error:', error.message);
|
package/src/hash.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hash.js","sourceRoot":"","sources":["../../../../libs/utils/src/hash.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"hash.js","sourceRoot":"","sources":["../../../../libs/utils/src/hash.ts"],"names":[],"mappings":";;;AAAA,MAAO,UAAU,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAC;AACrD,MAAM,MAAM,GAAG,OAAO,CAAE,sBAAsB,CAAC,CAAC;AAEzC,MAAM,QAAQ,GAAG,CACtB,SAAiB,EACjB,YAAoB,EACH,EAAE;IACnB,IAAI,CAAC;QACH,MAAM,UAAU,GAAW,kBAAkB,CAAC;QAC9C,MAAM,IAAI,GAAW,GAAG,UAAU,IAAI,YAAY,EAAE,CAAC;QACrD,OAAO,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC;IACvD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IACzC,CAAC;AACH,CAAC,CAAC;AAXW,QAAA,QAAQ,YAWnB"}
|
package/src/http.d.ts
ADDED
package/src/http.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getEncodedQueryParams = exports.buildUriBodyString = exports.getIpFromHttpRequest = void 0;
|
|
4
|
+
const querystring = require("querystring");
|
|
5
|
+
function getIpFromHttpRequest(req) {
|
|
6
|
+
return req.headers['x-forwarded-for']
|
|
7
|
+
? String(req.headers['x-forwarded-for']).split(',')[0].trim()
|
|
8
|
+
: req.socket.remoteAddress;
|
|
9
|
+
}
|
|
10
|
+
exports.getIpFromHttpRequest = getIpFromHttpRequest;
|
|
11
|
+
;
|
|
12
|
+
function buildUriBodyString(json) {
|
|
13
|
+
return Object.entries(json)
|
|
14
|
+
.map(([key, val]) => `${encodeURIComponent(key)}=${encodeURIComponent(val)}`)
|
|
15
|
+
.join('&');
|
|
16
|
+
}
|
|
17
|
+
exports.buildUriBodyString = buildUriBodyString;
|
|
18
|
+
;
|
|
19
|
+
function getEncodedQueryParams(fullUrl) {
|
|
20
|
+
const queryStringStartIndex = fullUrl.indexOf('?');
|
|
21
|
+
if (queryStringStartIndex === -1) {
|
|
22
|
+
return {};
|
|
23
|
+
}
|
|
24
|
+
const queryString = fullUrl.substring(queryStringStartIndex + 1);
|
|
25
|
+
const data = querystring.parse(queryString);
|
|
26
|
+
return Object.keys(data).reduce((acc, key) => {
|
|
27
|
+
acc[key] = JSON.parse(data[key]);
|
|
28
|
+
return acc;
|
|
29
|
+
}, {});
|
|
30
|
+
}
|
|
31
|
+
exports.getEncodedQueryParams = getEncodedQueryParams;
|
|
32
|
+
//# sourceMappingURL=http.js.map
|
package/src/http.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../../../libs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,CAAC,EAAE,EAAE,CAAC,CAAC;AACR,CAAC;AAbD,sDAaC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const buildProcedureJsonString: (procedure: string, params: Record<string, any>, paramValueWrappingOverride?: Record<string, (value: string) => string>) => string;
|
|
2
|
+
export declare const buildComplexTypedProcedure: (procedure: string, params: {
|
|
3
|
+
[paramName: string]: any;
|
|
4
|
+
}) => string;
|
package/src/snowflake.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildComplexTypedProcedure = exports.buildProcedureJsonString = void 0;
|
|
4
|
+
const buildProcedureJsonString = (procedure, params, paramValueWrappingOverride = {}) => {
|
|
5
|
+
return `CALL ${procedure}(${Object.entries(params)
|
|
6
|
+
.map(([k, v]) => {
|
|
7
|
+
const wrapMethod = paramValueWrappingOverride[k];
|
|
8
|
+
const valuePart = wrapMethod ? wrapMethod(v) : `\'${v}\'`;
|
|
9
|
+
return `${k} => ${valuePart}`;
|
|
10
|
+
})
|
|
11
|
+
.join(',')});`;
|
|
12
|
+
};
|
|
13
|
+
exports.buildProcedureJsonString = buildProcedureJsonString;
|
|
14
|
+
const formatParamValue = (value) => Array.isArray(value)
|
|
15
|
+
? `[${value.map(formatParamValue).join(', ')}]`
|
|
16
|
+
: typeof value === 'boolean'
|
|
17
|
+
? value ? 'TRUE' : 'FALSE'
|
|
18
|
+
: typeof value === 'number'
|
|
19
|
+
? value.toString()
|
|
20
|
+
: typeof value === 'object'
|
|
21
|
+
? `{${Object.entries(value).map(([key, val]) => `${key} => ${formatParamValue(val)}`).join(', ')}}`
|
|
22
|
+
: `'${value}'`;
|
|
23
|
+
const buildComplexTypedProcedure = (procedure, params) => `CALL ${procedure}(${Object.entries(params).map(([paramName, paramValue]) => `${paramName} => ${formatParamValue(paramValue)}`).join(', ')})`;
|
|
24
|
+
exports.buildComplexTypedProcedure = buildComplexT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