@hugo.ye/common 1.0.56 → 1.0.58

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.
@@ -1,2 +1,3 @@
1
1
  export * from './chat-type.types.ts';
2
+ export * from './response-data-type.ts';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC"}
@@ -1,2 +1,3 @@
1
1
  export * from "./chat-type.types.js";
2
+ export * from "./response-data-type.js";
2
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC"}
@@ -0,0 +1,10 @@
1
+ export interface ResponseDataType<T> {
2
+ data?: null | T;
3
+ success?: string;
4
+ statusCode?: string;
5
+ error?: {
6
+ message?: string;
7
+ code?: string;
8
+ };
9
+ }
10
+ //# sourceMappingURL=response-data-type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response-data-type.d.ts","sourceRoot":"","sources":["../../src/types/response-data-type.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB,CAAC,CAAC;IACjC,IAAI,CAAC,EAAE,IAAI,GAAG,CAAC,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE;QACN,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,CAAC;CACH"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=response-data-type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response-data-type.js","sourceRoot":"","sources":["../../src/types/response-data-type.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export declare function getExpiredDate(seconds: number): Date;
2
+ //# sourceMappingURL=expired.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expired.d.ts","sourceRoot":"","sources":["../../src/utils/expired.ts"],"names":[],"mappings":"AAAA,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,QAI7C"}
@@ -0,0 +1,6 @@
1
+ export function getExpiredDate(seconds) {
2
+ const expires = new Date();
3
+ expires.setSeconds(expires.getSeconds() + seconds);
4
+ return expires;
5
+ }
6
+ //# sourceMappingURL=expired.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expired.js","sourceRoot":"","sources":["../../src/utils/expired.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,cAAc,CAAC,OAAe;IAC5C,MAAM,OAAO,GAAG,IAAI,IAAI,EAAE,CAAC;IAC3B,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,UAAU,EAAE,GAAG,OAAO,CAAC,CAAC;IACnD,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -1,2 +1,5 @@
1
1
  export * from './order.ts';
2
+ export * from './expired.ts';
3
+ export * from './response.ts';
4
+ export * from './security.ts';
2
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC"}
@@ -1,2 +1,5 @@
1
1
  export * from "./order.js";
2
+ export * from "./expired.js";
3
+ export * from "./response.js";
4
+ export * from "./security.js";
2
5
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC"}
@@ -0,0 +1,18 @@
1
+ import type { ResponseDataType } from '../index.js';
2
+ type statusCode = 'SUCCESS' | 'PARAM_MISS' | 'UNAUTHORIZED' | 'INVALID_PASSWORD' | 'RECORD_NOT_FOUND' | 'MEMBER_NOT_FOUND' | 'EMAIL_EXISTS' | 'USERNAME_EXISTS' | 'MOBILE_EXISTS' | 'UNKNOWN_ERROR' | 'BAD_REQUEST' | 'ER_BAD_FIELD_ERROR' | 'ALIPAY_NOTIFY_VERIFY_FAILED';
3
+ export declare const responseData: ({ data, statusCode, errorMessage, errorCode, }: {
4
+ data?: any;
5
+ statusCode?: statusCode;
6
+ errorMessage?: string | null;
7
+ errorCode?: string | null;
8
+ }) => {
9
+ data: any;
10
+ statusCode: statusCode;
11
+ error: {
12
+ message: string | null;
13
+ code: string | null;
14
+ };
15
+ };
16
+ export declare const returnCatchError: (err: any) => ResponseDataType<string>;
17
+ export {};
18
+ //# sourceMappingURL=response.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../../src/utils/response.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAkCpD,KAAK,UAAU,GACX,SAAS,GACT,YAAY,GACZ,cAAc,GACd,kBAAkB,GAClB,kBAAkB,GAClB,kBAAkB,GAClB,cAAc,GACd,iBAAiB,GACjB,eAAe,GACf,eAAe,GACf,aAAa,GACb,oBAAoB,GACpB,6BAA6B,CAAC;AAClC,eAAO,MAAM,YAAY,GAAI,gDAK1B;IACD,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;;;;;;;CASA,CAAC;AACF,eAAO,MAAM,gBAAgB,GAAI,KAAK,GAAG,KAkBjC,gBAAgB,CAAC,MAAM,CAC9B,CAAC"}
@@ -0,0 +1,30 @@
1
+ export const responseData = ({ data = null, statusCode = 'SUCCESS', errorMessage = null, errorCode = null, }) => {
2
+ return {
3
+ data,
4
+ statusCode,
5
+ error: {
6
+ message: errorMessage,
7
+ code: errorCode,
8
+ },
9
+ };
10
+ };
11
+ export const returnCatchError = (err) => {
12
+ const errorCode = err.code
13
+ ? err.code
14
+ : err.response
15
+ ? err.response.status
16
+ : 'UNKNOWN_ERROR';
17
+ const errorMessage = err.response
18
+ ? err.response.statusText
19
+ : err.message
20
+ ? err.message
21
+ : '未知错误';
22
+ return responseData({
23
+ statusCode: errorCode === 401 || errorMessage === 'Unauthorized'
24
+ ? 'UNAUTHORIZED'
25
+ : errorCode,
26
+ errorCode,
27
+ errorMessage,
28
+ });
29
+ };
30
+ //# sourceMappingURL=response.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response.js","sourceRoot":"","sources":["../../src/utils/response.ts"],"names":[],"mappings":"AAgDA,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,EAC3B,IAAI,GAAG,IAAI,EACX,UAAU,GAAG,SAAS,EACtB,YAAY,GAAG,IAAI,EACnB,SAAS,GAAG,IAAI,GAMjB,EAAE,EAAE;IACH,OAAO;QACL,IAAI;QACJ,UAAU;QACV,KAAK,EAAE;YACL,OAAO,EAAE,YAAY;YACrB,IAAI,EAAE,SAAS;SAChB;KACF,CAAC;AACJ,CAAC,CAAC;AACF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,GAAQ,EAAE,EAAE;IAC3C,MAAM,SAAS,GAAG,GAAG,CAAC,IAAI;QACxB,CAAC,CAAC,GAAG,CAAC,IAAI;QACV,CAAC,CAAC,GAAG,CAAC,QAAQ;YACZ,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM;YACrB,CAAC,CAAC,eAAe,CAAC;IACtB,MAAM,YAAY,GAAG,GAAG,CAAC,QAAQ;QAC/B,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,UAAU;QACzB,CAAC,CAAC,GAAG,CAAC,OAAO;YACX,CAAC,CAAC,GAAG,CAAC,OAAO;YACb,CAAC,CAAC,MAAM,CAAC;IACb,OAAO,YAAY,CAAC;QAClB,UAAU,EACR,SAAS,KAAK,GAAG,IAAI,YAAY,KAAK,cAAc;YAClD,CAAC,CAAC,cAAc;YAChB,CAAC,CAAC,SAAS;QACf,SAAS;QACT,YAAY;KACb,CAA6B,CAAC;AACjC,CAAC,CAAC"}
@@ -0,0 +1,8 @@
1
+ export declare function hashPassword(password: string): Promise<string>;
2
+ export declare function verifyPassword(password: string, hashPassword: string): Promise<boolean>;
3
+ export declare const encodeUidSignature: (uid: string, signature: string, JWT_SECRET: string) => string;
4
+ export declare const decodeUidSignature: (uidSignature: string, JWT_SECRET: string) => string;
5
+ export declare const createPostSignature: (data: any, JWT_SECRET: string) => any;
6
+ export declare const getSignature: (pepper: string, ...strings: string[]) => any;
7
+ export declare const verifySignature: (papper: string, signature: string, ...strings: string[]) => boolean;
8
+ //# sourceMappingURL=security.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"security.d.ts","sourceRoot":"","sources":["../../src/utils/security.ts"],"names":[],"mappings":"AAIA,wBAAsB,YAAY,CAAC,QAAQ,EAAE,MAAM,mBAGlD;AAED,wBAAsB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,oBAG1E;AAED,eAAO,MAAM,kBAAkB,GAC7B,KAAK,MAAM,EACX,WAAW,MAAM,EACjB,YAAY,MAAM,WAKnB,CAAC;AACF,eAAO,MAAM,kBAAkB,GAC7B,cAAc,MAAM,EACpB,YAAY,MAAM,WAInB,CAAC;AACF,eAAO,MAAM,mBAAmB,GAAI,MAAM,GAAG,EAAE,YAAY,MAAM,QAYhE,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,QAAQ,MAAM,EAAE,GAAG,SAAS,MAAM,EAAE,QAIhE,CAAA;AAED,eAAO,MAAM,eAAe,GAAI,QAAQ,MAAM,EAAE,WAAW,MAAM,EAAE,GAAG,SAAS,MAAM,EAAE,YAMtF,CAAA"}
@@ -0,0 +1,47 @@
1
+ import * as bcrypt from 'bcryptjs';
2
+ import { Md5 } from 'ts-md5';
3
+ const salt = 'hugo.ye.ltt.netsolution';
4
+ export async function hashPassword(password) {
5
+ const result = await bcrypt.hash(password, salt);
6
+ return result;
7
+ }
8
+ export async function verifyPassword(password, hashPassword) {
9
+ const result = await bcrypt.compare(password, hashPassword);
10
+ return result;
11
+ }
12
+ export const encodeUidSignature = (uid, signature, JWT_SECRET) => {
13
+ const len = JWT_SECRET.length;
14
+ const prefix = uid.substring(0, len);
15
+ return prefix + signature;
16
+ };
17
+ export const decodeUidSignature = (uidSignature, JWT_SECRET) => {
18
+ const len = JWT_SECRET.length;
19
+ return uidSignature.substring(len);
20
+ };
21
+ export const createPostSignature = (data, JWT_SECRET) => {
22
+ if (data.signature)
23
+ delete data.signature;
24
+ const sortKeys = Object.keys(data).sort();
25
+ const result = [];
26
+ sortKeys.map((key) => {
27
+ if (key !== 'file' && key !== 'uid')
28
+ result.push(JSON.stringify(data[key]));
29
+ });
30
+ const signature = Md5.hashStr(`${result.join('')}${JWT_SECRET}`);
31
+ return data['uid']
32
+ ? encodeUidSignature(Md5.hashStr(data['uid']), signature, JWT_SECRET)
33
+ : signature;
34
+ };
35
+ export const getSignature = (pepper, ...strings) => {
36
+ const result = strings.map((str) => Md5.hashStr(str).substring(5, 5));
37
+ const signature = Md5.hashStr(result.sort().join('').concat(pepper).substring(result.length, 10));
38
+ return signature;
39
+ };
40
+ export const verifySignature = (papper, signature, ...strings) => {
41
+ const verifyStr = getSignature(papper, ...strings);
42
+ if (verifyStr === signature)
43
+ return true;
44
+ else
45
+ return false;
46
+ };
47
+ //# sourceMappingURL=security.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"security.js","sourceRoot":"","sources":["../../src/utils/security.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAC7B,MAAM,IAAI,GAAG,yBAAyB,CAAC;AACvC,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,QAAgB;IACjD,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IACjD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,QAAgB,EAAE,YAAoB;IACzE,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;IAC5D,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,GAAW,EACX,SAAiB,EACjB,UAAkB,EAClB,EAAE;IACF,MAAM,GAAG,GAAG,UAAU,CAAC,MAAM,CAAC;IAC9B,MAAM,MAAM,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACrC,OAAO,MAAM,GAAG,SAAS,CAAC;AAC5B,CAAC,CAAC;AACF,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,YAAoB,EACpB,UAAkB,EAClB,EAAE;IACF,MAAM,GAAG,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IAAI,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC;IAClG,OAAO,SAAS,CAAC;AACrB,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,MAAc,EAAE,SAAiB,EAAE,GAAG,OAAiB,EAAE,EAAE;IACvF,MAAM,SAAS,GAAG,YAAY,CAAC,MAAM,EAAE,GAAG,OAAO,CAAC,CAAC;IACnD,IAAI,SAAS,KAAK,SAAS;QACvB,OAAO,IAAI,CAAC;;QAEZ,OAAO,KAAK,CAAC;AACrB,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hugo.ye/common",
3
- "version": "1.0.56",
3
+ "version": "1.0.58",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -26,10 +26,12 @@
26
26
  "@nestjs/config": "^4.0.3",
27
27
  "@nestjs/graphql": "^13.2.4",
28
28
  "@nestjs/typeorm": "^11.0.0",
29
+ "bcryptjs": "^3.0.3",
29
30
  "class-transformer": "^0.5.1",
30
31
  "class-validator": "^0.14.4",
31
32
  "nestjs-paginate": "^12.8.3",
32
33
  "nestjs-pino": "^4.6.0",
34
+ "ts-md5": "^2.0.1",
33
35
  "typeorm": "^0.3.28"
34
36
  }
35
37
  }