baja-lite 1.3.25 → 1.3.27
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/.eslintignore +7 -0
- package/.eslintrc.cjs +89 -0
- package/.prettierrc +4 -0
- package/.vscode/settings.json +8 -0
- package/ci.js +29 -0
- package/package-cjs.json +17 -0
- package/package.json +2 -2
- package/{boot-remote.js → src/boot-remote.ts} +7 -6
- package/{boot.js → src/boot.ts} +38 -31
- package/{code.js → src/code.ts} +66 -71
- package/{convert-xml.js → src/convert-xml.ts} +155 -105
- package/src/enum.ts +71 -0
- package/src/error.ts +11 -0
- package/src/fn.ts +295 -0
- package/{index.d.ts → src/index.ts} +12 -11
- package/{list.js → src/list.ts} +9 -8
- package/src/math.ts +405 -0
- package/src/object.ts +247 -0
- package/{snowflake.js → src/snowflake.ts} +52 -33
- package/src/sql.ts +5023 -0
- package/{sqlite.js → src/sqlite.ts} +52 -53
- package/src/string.ts +111 -0
- package/src/test-mysql.ts +144 -0
- package/{test-postgresql.js → src/test-postgresql.ts} +80 -91
- package/{test-sqlite.js → src/test-sqlite.ts} +80 -90
- package/{test-xml.js → src/test-xml.ts} +1 -1
- package/{test.js → src/test.ts} +3 -2
- package/src/wx/base.ts +76 -0
- package/src/wx/mini.ts +147 -0
- package/src/wx/organ.ts +290 -0
- package/{wx/types.d.ts → src/wx/types.ts} +10 -21
- package/tsconfig.cjs.json +42 -0
- package/tsconfig.json +44 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/xml/event-report.xml +13 -0
- package/yarn.lock +1757 -0
- package/boot-remote.d.ts +0 -2
- package/boot.d.ts +0 -2
- package/code.d.ts +0 -2
- package/convert-xml.d.ts +0 -10
- package/enum.d.ts +0 -18
- package/enum.js +0 -59
- package/error.d.ts +0 -5
- package/error.js +0 -13
- package/fn.d.ts +0 -128
- package/fn.js +0 -172
- package/index.js +0 -11
- package/list.d.ts +0 -10
- package/math.d.ts +0 -83
- package/math.js +0 -451
- package/object.d.ts +0 -83
- package/object.js +0 -221
- package/snowflake.d.ts +0 -12
- package/sql.d.ts +0 -1788
- package/sql.js +0 -4765
- package/sqlite.d.ts +0 -32
- package/string.d.ts +0 -17
- package/string.js +0 -105
- package/test-mysql.d.ts +0 -2
- package/test-mysql.js +0 -109
- package/test-postgresql.d.ts +0 -2
- package/test-sqlite.d.ts +0 -1
- package/test-xml.d.ts +0 -1
- package/test.d.ts +0 -1
- package/wx/base.d.ts +0 -11
- package/wx/base.js +0 -78
- package/wx/mini.d.ts +0 -52
- package/wx/mini.js +0 -112
- package/wx/organ.d.ts +0 -65
- package/wx/organ.js +0 -171
- package/wx/types.js +0 -1
- package/wx.js +0 -3
- /package/{README.md → Readme.md} +0 -0
- /package/{wx.d.ts → src/wx.ts} +0 -0
package/sqlite.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { SqliteRemoteInterface } from './sql.js';
|
|
2
|
-
export declare abstract class SqliteRemoteClass implements SqliteRemoteInterface {
|
|
3
|
-
private dbList;
|
|
4
|
-
/** 原始存放路径 */
|
|
5
|
-
abstract getStoreName(dbName: string): string;
|
|
6
|
-
/** 导入时,备份源文件路径 */
|
|
7
|
-
abstract getBackName(dbName: string): string;
|
|
8
|
-
abstract BetterSqlite3: any;
|
|
9
|
-
/** 实现复制 */
|
|
10
|
-
abstract cpSync(from: string, to: string, option?: {
|
|
11
|
-
force: true;
|
|
12
|
-
}): void;
|
|
13
|
-
/**
|
|
14
|
-
* 设置可执行权限
|
|
15
|
-
```
|
|
16
|
-
const fd = openSync(dbPath, 1);
|
|
17
|
-
fchmodSync(fd, 777);
|
|
18
|
-
closeSync(fd);
|
|
19
|
-
```
|
|
20
|
-
*/
|
|
21
|
-
abstract setMod(name: string): void;
|
|
22
|
-
abstract trace: boolean;
|
|
23
|
-
execute(inData: Uint8Array): Promise<Uint8Array>;
|
|
24
|
-
pluck(inData: Uint8Array): Promise<Uint8Array>;
|
|
25
|
-
get(inData: Uint8Array): Promise<Uint8Array>;
|
|
26
|
-
raw(inData: Uint8Array): Promise<Uint8Array>;
|
|
27
|
-
query(inData: Uint8Array): Promise<Uint8Array>;
|
|
28
|
-
initDB(dbName: string): void;
|
|
29
|
-
export(dbName: string, exportPath: string): Promise<void>;
|
|
30
|
-
restore(dbName: string, importPath: string): void;
|
|
31
|
-
close(dbName?: string): void;
|
|
32
|
-
}
|
package/string.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 通过uri获取key
|
|
3
|
-
* @param uri
|
|
4
|
-
*/
|
|
5
|
-
export declare const getPicKey: (uri: string) => string;
|
|
6
|
-
export declare const emptyString: (source: any, skipEmptyString?: boolean) => boolean;
|
|
7
|
-
export declare const notEmptyString: (source: any, skipEmptyString?: boolean) => boolean;
|
|
8
|
-
export declare const safeString: (source?: string) => string;
|
|
9
|
-
export declare const trimObject: <T>(data: any) => T;
|
|
10
|
-
export declare const randomNumber: (len: number) => string;
|
|
11
|
-
export declare const randomString: (len: number) => string;
|
|
12
|
-
export declare const randomString2: (len: number) => string;
|
|
13
|
-
export declare const randomString3: (len: number) => string;
|
|
14
|
-
export declare const buildWxStr: (data: {
|
|
15
|
-
[key: string]: string;
|
|
16
|
-
}, maxLabelLength: number, ...titles: string[]) => string;
|
|
17
|
-
export declare const replaceChineseCode: (str: string) => string;
|
package/string.js
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 通过uri获取key
|
|
3
|
-
* @param uri
|
|
4
|
-
*/
|
|
5
|
-
export const getPicKey = (uri) => {
|
|
6
|
-
const arr = /key=([0-9a-zA-Z.]+)/.exec(uri);
|
|
7
|
-
if (arr && arr.length === 2) {
|
|
8
|
-
return arr[1];
|
|
9
|
-
}
|
|
10
|
-
return uri;
|
|
11
|
-
};
|
|
12
|
-
export const emptyString = (source, skipEmptyString = true) => {
|
|
13
|
-
return (source === null ||
|
|
14
|
-
source === undefined ||
|
|
15
|
-
(skipEmptyString === true && (source === '' || `${source}`.replace(/\s/g, '') === '')));
|
|
16
|
-
};
|
|
17
|
-
export const notEmptyString = (source, skipEmptyString = true) => {
|
|
18
|
-
return emptyString(source, skipEmptyString) === false;
|
|
19
|
-
};
|
|
20
|
-
export const safeString = (source) => {
|
|
21
|
-
if (source) {
|
|
22
|
-
return `${source}`.replace(/'/g, '');
|
|
23
|
-
}
|
|
24
|
-
return '';
|
|
25
|
-
};
|
|
26
|
-
export const trimObject = (data) => {
|
|
27
|
-
if (data) {
|
|
28
|
-
for (const k in data) {
|
|
29
|
-
if (typeof data[k] === 'string') {
|
|
30
|
-
data[k] = data[k].trim();
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return data;
|
|
35
|
-
};
|
|
36
|
-
export const randomNumber = (len) => {
|
|
37
|
-
return `${parseInt(`${(Math.random() * 9 + 1) * Math.pow(10, (len - 1))}`, 10)}`;
|
|
38
|
-
};
|
|
39
|
-
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
40
|
-
const charLen = chars.length;
|
|
41
|
-
export const randomString = (len) => {
|
|
42
|
-
return Array.from(new Array(len)).map(() => chars.charAt(Math.floor(Math.random() * charLen))).join('');
|
|
43
|
-
};
|
|
44
|
-
const chars2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
|
45
|
-
const charLen2 = chars2.length;
|
|
46
|
-
export const randomString2 = (len) => {
|
|
47
|
-
return Array.from(new Array(len)).map(() => chars2.charAt(Math.floor(Math.random() * charLen2))).join('');
|
|
48
|
-
};
|
|
49
|
-
const chars3 = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
50
|
-
const charLen3 = chars3.length;
|
|
51
|
-
export const randomString3 = (len) => {
|
|
52
|
-
return Array.from(new Array(len)).map(() => chars3.charAt(Math.floor(Math.random() * charLen3))).join('');
|
|
53
|
-
};
|
|
54
|
-
export const buildWxStr = (data, maxLabelLength, ...titles) => {
|
|
55
|
-
let str = titles.join('\r\n');
|
|
56
|
-
str += '\r\n\r\n';
|
|
57
|
-
const items = new Array();
|
|
58
|
-
// const maxLength = maxLabelLength * 2;
|
|
59
|
-
for (const [key, value] of Object.entries(data)) {
|
|
60
|
-
if (notEmptyString(value)) {
|
|
61
|
-
const len = maxLabelLength - key.length;
|
|
62
|
-
items.push(`${key}:${''.padEnd(len * 3 + (len > 0 ? 1 : 0), ' ')}${value}`);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
str += items.join('\r\n');
|
|
66
|
-
return str;
|
|
67
|
-
};
|
|
68
|
-
const chinese = /[\u3002|\uff1f|\uff01|\uff0c|\u3001|\uff1b|\uff1a|\u201c|\u201d|\u2018|\u2019|\uff08|\uff09|\u300a|\u300b|\u3008|\u3009|\u3010|\u3011|\u300e|\u300f|\u300c|\u300d|\ufe43|\ufe44|\u3014|\u3015|\u2026|\u2014|\uff5e|\ufe4f|\uffe5]/g;
|
|
69
|
-
const table = {
|
|
70
|
-
'!': '!',
|
|
71
|
-
'¥': '$',
|
|
72
|
-
'…': '.',
|
|
73
|
-
'(': '(',
|
|
74
|
-
')': ')',
|
|
75
|
-
'《': '<',
|
|
76
|
-
'》': '>',
|
|
77
|
-
'?': '?',
|
|
78
|
-
':': ':',
|
|
79
|
-
'“': `'`,
|
|
80
|
-
'”': `'`,
|
|
81
|
-
'’': `'`,
|
|
82
|
-
'‘': `'`,
|
|
83
|
-
',': ',',
|
|
84
|
-
'。': '.',
|
|
85
|
-
'、': '/',
|
|
86
|
-
';': ';',
|
|
87
|
-
'〈': '<',
|
|
88
|
-
'〉': '>',
|
|
89
|
-
'【': '[',
|
|
90
|
-
'】': ']',
|
|
91
|
-
'『': '[',
|
|
92
|
-
'』': ']',
|
|
93
|
-
'「': '[',
|
|
94
|
-
'」': ']',
|
|
95
|
-
'﹃': '[',
|
|
96
|
-
'﹄': ']',
|
|
97
|
-
'〔': '(',
|
|
98
|
-
'〕': ')',
|
|
99
|
-
'—': '-',
|
|
100
|
-
'~': '~',
|
|
101
|
-
'﹏': '~'
|
|
102
|
-
};
|
|
103
|
-
export const replaceChineseCode = (str) => {
|
|
104
|
-
return str.replace(chinese, (a) => table[a] || '');
|
|
105
|
-
};
|
package/test-mysql.d.ts
DELETED
package/test-mysql.js
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
import { Field, SqlType } from 'baja-lite-field';
|
|
11
|
-
import 'reflect-metadata';
|
|
12
|
-
import { Boot } from './boot.js';
|
|
13
|
-
import { ColumnMode, DB, SqlService } from './sql.js';
|
|
14
|
-
class BaseAuditUser {
|
|
15
|
-
}
|
|
16
|
-
__decorate([
|
|
17
|
-
Field({ type: SqlType.varchar, length: 32, id: true, notNull: true, uuidShort: true }),
|
|
18
|
-
__metadata("design:type", String)
|
|
19
|
-
], BaseAuditUser.prototype, "auditId", void 0);
|
|
20
|
-
__decorate([
|
|
21
|
-
Field({ type: SqlType.varchar, length: 32, comment: '密码' }),
|
|
22
|
-
__metadata("design:type", String)
|
|
23
|
-
], BaseAuditUser.prototype, "password", void 0);
|
|
24
|
-
__decorate([
|
|
25
|
-
Field({ type: SqlType.varchar, length: 255, comment: '省' }),
|
|
26
|
-
__metadata("design:type", String)
|
|
27
|
-
], BaseAuditUser.prototype, "userProvinceCode", void 0);
|
|
28
|
-
__decorate([
|
|
29
|
-
Field({ type: SqlType.varchar, length: 255, comment: '省' }),
|
|
30
|
-
__metadata("design:type", String)
|
|
31
|
-
], BaseAuditUser.prototype, "userProvince", void 0);
|
|
32
|
-
__decorate([
|
|
33
|
-
Field({ type: SqlType.varchar, length: 32, comment: '显示名称' }),
|
|
34
|
-
__metadata("design:type", String)
|
|
35
|
-
], BaseAuditUser.prototype, "labelName", void 0);
|
|
36
|
-
__decorate([
|
|
37
|
-
Field({ type: SqlType.varchar, length: 32, comment: '备注名称' }),
|
|
38
|
-
__metadata("design:type", String)
|
|
39
|
-
], BaseAuditUser.prototype, "remarkName", void 0);
|
|
40
|
-
__decorate([
|
|
41
|
-
Field({ type: SqlType.varchar, length: 32, comment: '初始密码' }),
|
|
42
|
-
__metadata("design:type", String)
|
|
43
|
-
], BaseAuditUser.prototype, "upassword", void 0);
|
|
44
|
-
__decorate([
|
|
45
|
-
Field({ type: SqlType.char, length: 1, def: 0, comment: '是否中心' }),
|
|
46
|
-
__metadata("design:type", String)
|
|
47
|
-
], BaseAuditUser.prototype, "baseType", void 0);
|
|
48
|
-
__decorate([
|
|
49
|
-
Field({ type: SqlType.varchar, length: 32 }),
|
|
50
|
-
__metadata("design:type", String)
|
|
51
|
-
], BaseAuditUser.prototype, "userId", void 0);
|
|
52
|
-
__decorate([
|
|
53
|
-
Field({ type: SqlType.varchar, length: 32 }),
|
|
54
|
-
__metadata("design:type", String)
|
|
55
|
-
], BaseAuditUser.prototype, "companyId", void 0);
|
|
56
|
-
__decorate([
|
|
57
|
-
Field({ type: SqlType.varchar, length: 32 }),
|
|
58
|
-
__metadata("design:type", String)
|
|
59
|
-
], BaseAuditUser.prototype, "username", void 0);
|
|
60
|
-
__decorate([
|
|
61
|
-
Field({ type: SqlType.char, length: 1, def: 0, comment: '状态' }),
|
|
62
|
-
__metadata("design:type", String)
|
|
63
|
-
], BaseAuditUser.prototype, "userStatus", void 0);
|
|
64
|
-
__decorate([
|
|
65
|
-
Field({ type: SqlType.char, length: 1, def: 0, comment: '账户分组' }),
|
|
66
|
-
__metadata("design:type", String)
|
|
67
|
-
], BaseAuditUser.prototype, "groupId", void 0);
|
|
68
|
-
__decorate([
|
|
69
|
-
Field({ type: SqlType.varchar, length: 10 }),
|
|
70
|
-
__metadata("design:type", String)
|
|
71
|
-
], BaseAuditUser.prototype, "startDate", void 0);
|
|
72
|
-
__decorate([
|
|
73
|
-
Field({ type: SqlType.varchar, length: 10 }),
|
|
74
|
-
__metadata("design:type", String)
|
|
75
|
-
], BaseAuditUser.prototype, "endDate", void 0);
|
|
76
|
-
let BaseAuditUserService = class BaseAuditUserService extends SqlService {
|
|
77
|
-
};
|
|
78
|
-
BaseAuditUserService = __decorate([
|
|
79
|
-
DB({ tableName: 'base_audit_user', clz: BaseAuditUser })
|
|
80
|
-
], BaseAuditUserService);
|
|
81
|
-
export async function go2() {
|
|
82
|
-
await Boot({
|
|
83
|
-
Mysql: {
|
|
84
|
-
host: '127.0.0.1',
|
|
85
|
-
port: 3306,
|
|
86
|
-
user: 'root',
|
|
87
|
-
password: 'abcd1234',
|
|
88
|
-
// 数据库名
|
|
89
|
-
database: 'sportevent',
|
|
90
|
-
debug: false
|
|
91
|
-
},
|
|
92
|
-
log: 'trace',
|
|
93
|
-
columnMode: ColumnMode.HUMP,
|
|
94
|
-
sqlDir: 'E:/pro/baja-lite/xml',
|
|
95
|
-
sqlMap: {
|
|
96
|
-
['test.test']: `SELECT * FROM cp_user {{#username}} WHERE username = :username {{/username}}`
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
const service = new BaseAuditUserService();
|
|
100
|
-
const list = await service.transaction({
|
|
101
|
-
fn: async (conn) => {
|
|
102
|
-
await service.stream().eq('baseType', '0').in('auditId', ['162400829591265280', '162201628882247680']).excuteSelect();
|
|
103
|
-
const data = await service.stream().in('auditId', ['162400829591265280', '162201628882247680']).update('labelName', '333').excuteUpdate({ conn });
|
|
104
|
-
return data;
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
console.log(11, list);
|
|
108
|
-
}
|
|
109
|
-
go2();
|
package/test-postgresql.d.ts
DELETED
package/test-sqlite.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
package/test-xml.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/wx/base.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export declare abstract class BaseWx {
|
|
2
|
-
protected authErrorCodes: number[];
|
|
3
|
-
protected name: string;
|
|
4
|
-
protected tokenUrl: string;
|
|
5
|
-
private tokenData;
|
|
6
|
-
protected mock: boolean;
|
|
7
|
-
protected getToken(force?: boolean): Promise<string>;
|
|
8
|
-
protected fetch(uri: (token: string) => string, method: 'get' | 'post', data: {
|
|
9
|
-
[key: string]: any;
|
|
10
|
-
}, needToken?: boolean, buffer?: boolean): Promise<any>;
|
|
11
|
-
}
|
package/wx/base.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
|
2
|
-
import * as rp from 'request-promise';
|
|
3
|
-
import { Throw } from '../error.js';
|
|
4
|
-
import pino from 'pino';
|
|
5
|
-
const logger = process.env['NODE_ENV'] !== 'production' ? pino({
|
|
6
|
-
name: 'wx',
|
|
7
|
-
transport: {
|
|
8
|
-
target: 'pino-pretty'
|
|
9
|
-
}
|
|
10
|
-
}) : pino({ name: 'wx' });
|
|
11
|
-
export class BaseWx {
|
|
12
|
-
constructor() {
|
|
13
|
-
this.authErrorCodes = [40001, 40014, 41001, 42001];
|
|
14
|
-
this.name = '';
|
|
15
|
-
this.tokenUrl = '';
|
|
16
|
-
this.tokenData = '';
|
|
17
|
-
this.mock = false;
|
|
18
|
-
}
|
|
19
|
-
async getToken(force) {
|
|
20
|
-
let token = '';
|
|
21
|
-
const now = +new Date();
|
|
22
|
-
let need = force === true;
|
|
23
|
-
if (this.tokenData) {
|
|
24
|
-
const datas = this.tokenData.split('^_^');
|
|
25
|
-
token = datas[0];
|
|
26
|
-
const lastTime = datas[1];
|
|
27
|
-
const spliceTime = datas[2];
|
|
28
|
-
if (now - parseInt(lastTime, 10) - parseInt(spliceTime, 10) > 0) {
|
|
29
|
-
need = true;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
need = true;
|
|
34
|
-
}
|
|
35
|
-
if (need === true) {
|
|
36
|
-
const data = await this.fetch(() => this.tokenUrl, 'get', {}, false);
|
|
37
|
-
token = data.access_token;
|
|
38
|
-
this.tokenData = `${token}^_^${now}^_^${data.expires_in * 1000}`;
|
|
39
|
-
}
|
|
40
|
-
return token;
|
|
41
|
-
}
|
|
42
|
-
async fetch(uri, method, data, needToken = true, buffer = false) {
|
|
43
|
-
if (this.mock === true) {
|
|
44
|
-
return {};
|
|
45
|
-
}
|
|
46
|
-
let token = needToken ? await this.getToken() : '';
|
|
47
|
-
if (!needToken || token) {
|
|
48
|
-
const start = +new Date();
|
|
49
|
-
let url = uri(token);
|
|
50
|
-
const param = method === 'get' ? {
|
|
51
|
-
method,
|
|
52
|
-
json: buffer ? false : true,
|
|
53
|
-
qs: data,
|
|
54
|
-
encoding: buffer ? null : undefined
|
|
55
|
-
} : {
|
|
56
|
-
json: data,
|
|
57
|
-
method,
|
|
58
|
-
encoding: buffer ? null : undefined
|
|
59
|
-
};
|
|
60
|
-
let response = await rp.default({
|
|
61
|
-
uri: url,
|
|
62
|
-
...param
|
|
63
|
-
});
|
|
64
|
-
if (this.authErrorCodes.includes(response.errcode)) {
|
|
65
|
-
token = await this.getToken(true);
|
|
66
|
-
url = uri(token);
|
|
67
|
-
response = await rp.default({
|
|
68
|
-
uri: url,
|
|
69
|
-
...param
|
|
70
|
-
});
|
|
71
|
-
Throw.if(response.errcode && response.errcode - 0 !== 0, `${url}-${response.errcode}-${response.errmsg}`);
|
|
72
|
-
}
|
|
73
|
-
Throw.if(response.errcode && response.errcode - 0 !== 0, `${url}-${response.errcode}-${response.errmsg}`);
|
|
74
|
-
logger.info(`fetch data ${+new Date() - start} ms`);
|
|
75
|
-
return response;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
package/wx/mini.d.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { BaseWx } from './base.js';
|
|
2
|
-
import { WxLiveInfo, WxLiveReplay, WxMiniConfig } from './types.js';
|
|
3
|
-
export declare class WxMini extends BaseWx {
|
|
4
|
-
protected name: string;
|
|
5
|
-
private config;
|
|
6
|
-
private templNameCache;
|
|
7
|
-
private templKeyCache;
|
|
8
|
-
constructor(config: WxMiniConfig);
|
|
9
|
-
getUnlimited({ scene, model, page, fullpath, png, width, lineColor }: {
|
|
10
|
-
scene: string;
|
|
11
|
-
model?: string;
|
|
12
|
-
page?: string;
|
|
13
|
-
fullpath?: string;
|
|
14
|
-
png?: '0' | '1' | 0 | 1 | true | false | 'true' | 'false';
|
|
15
|
-
width?: number;
|
|
16
|
-
lineColor?: {
|
|
17
|
-
r: number;
|
|
18
|
-
g: number;
|
|
19
|
-
b: number;
|
|
20
|
-
};
|
|
21
|
-
}): Promise<any>;
|
|
22
|
-
sendMs({ openids, name, data, scene }: {
|
|
23
|
-
openids: string[];
|
|
24
|
-
name: string;
|
|
25
|
-
data: {
|
|
26
|
-
[key: string]: string | number;
|
|
27
|
-
};
|
|
28
|
-
scene: string;
|
|
29
|
-
}): Promise<void>;
|
|
30
|
-
code2session(code: string): Promise<{
|
|
31
|
-
openid: string;
|
|
32
|
-
session_key: string;
|
|
33
|
-
unionid?: string;
|
|
34
|
-
}>;
|
|
35
|
-
getTemplIds(): {
|
|
36
|
-
[key: string]: string[];
|
|
37
|
-
};
|
|
38
|
-
decrypt<T>({ sessionKey, encryptedData, iv }: {
|
|
39
|
-
iv: string;
|
|
40
|
-
sessionKey: string;
|
|
41
|
-
encryptedData: string;
|
|
42
|
-
}): T | undefined;
|
|
43
|
-
getLiveInfo(start: number, limit: number): Promise<WxLiveInfo[]>;
|
|
44
|
-
getLiveReplay(room_id: number, start: number, limit: number): Promise<WxLiveReplay[]>;
|
|
45
|
-
getPhone(code: string, openid: string): Promise<{
|
|
46
|
-
phoneNumber: any;
|
|
47
|
-
purePhoneNumber: any;
|
|
48
|
-
countryCode: any;
|
|
49
|
-
timestamp: any;
|
|
50
|
-
appid: any;
|
|
51
|
-
}>;
|
|
52
|
-
}
|
package/wx/mini.js
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import crypto from 'crypto';
|
|
2
|
-
import { Throw } from '../error.js';
|
|
3
|
-
import { BaseWx } from './base.js';
|
|
4
|
-
export class WxMini extends BaseWx {
|
|
5
|
-
constructor(config) {
|
|
6
|
-
super();
|
|
7
|
-
this.name = 'wxMini';
|
|
8
|
-
this.config = config;
|
|
9
|
-
this.tokenUrl = `https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=${this.config.appId}&secret=${this.config.appSecret}`;
|
|
10
|
-
this.templNameCache = {};
|
|
11
|
-
this.templKeyCache = {};
|
|
12
|
-
if (this.config.messages) {
|
|
13
|
-
for (const item of this.config.messages) {
|
|
14
|
-
if (!this.templNameCache[item.name]) {
|
|
15
|
-
this.templNameCache[item.name] = [];
|
|
16
|
-
}
|
|
17
|
-
this.templNameCache[item.name].push({
|
|
18
|
-
tmplId: item.tmplId,
|
|
19
|
-
page: `pages/${item.model}/${item.page}/${item.page}`
|
|
20
|
-
});
|
|
21
|
-
for (const key of item.keys) {
|
|
22
|
-
if (!this.templKeyCache[key]) {
|
|
23
|
-
this.templKeyCache[key] = [];
|
|
24
|
-
}
|
|
25
|
-
this.templKeyCache[key].push(item.tmplId);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
async getUnlimited({ scene, model, page, fullpath, png, width, lineColor }) {
|
|
31
|
-
Throw.if(!fullpath && (!model || !page), '路径不完整,fullpath或者model+page必须传一个');
|
|
32
|
-
const pageto = fullpath ?? `pages/${model}/${page}/${page}`;
|
|
33
|
-
return await this.fetch((token) => `https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=${token}`, 'post', {
|
|
34
|
-
scene,
|
|
35
|
-
page: pageto,
|
|
36
|
-
line_color: lineColor ?? this.config.qrcode?.lineColor,
|
|
37
|
-
is_hyaline: png === 'true' || png === '1' || png === true || png === 1,
|
|
38
|
-
width: width ?? this.config.qrcode?.width ?? 500
|
|
39
|
-
}, true, true);
|
|
40
|
-
}
|
|
41
|
-
async sendMs({ openids, name, data, scene }) {
|
|
42
|
-
const temps = this.templNameCache[name];
|
|
43
|
-
const dataSend = {};
|
|
44
|
-
for (const [key, value] of Object.entries(data)) {
|
|
45
|
-
dataSend[key] = { value: value ?? '' };
|
|
46
|
-
}
|
|
47
|
-
if (scene) {
|
|
48
|
-
scene = `?${scene}`;
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
scene = '';
|
|
52
|
-
}
|
|
53
|
-
for (const temp of temps) {
|
|
54
|
-
for (const touser of openids) {
|
|
55
|
-
await this.fetch((token) => `https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=${token}`, 'post', {
|
|
56
|
-
touser,
|
|
57
|
-
data: dataSend,
|
|
58
|
-
template_id: temp.tmplId,
|
|
59
|
-
page: `${temp.page}${scene}`
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
async code2session(code) {
|
|
65
|
-
const data = await this.fetch(() => `https://api.weixin.qq.com/sns/jscode2session?appid=${this.config.appId}&secret=${this.config.appSecret}&js_code=${code}&grant_type=authorization_code`, 'get', {}, false);
|
|
66
|
-
return {
|
|
67
|
-
openid: data.openid,
|
|
68
|
-
session_key: data.session_key,
|
|
69
|
-
unionid: data.unionid
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
getTemplIds() {
|
|
73
|
-
return this.templKeyCache;
|
|
74
|
-
}
|
|
75
|
-
decrypt({ sessionKey, encryptedData, iv }) {
|
|
76
|
-
Throw.if(!sessionKey, '会话过期,请重新登陆!');
|
|
77
|
-
const sessionKeyBuf = Buffer.from(sessionKey, 'base64');
|
|
78
|
-
const encryptedDataBuf = Buffer.from(encryptedData, 'base64');
|
|
79
|
-
const ivBuf = Buffer.from(iv, 'base64');
|
|
80
|
-
try {
|
|
81
|
-
// 解密
|
|
82
|
-
const decipher = crypto.createDecipheriv('aes-128-cbc', sessionKeyBuf, ivBuf);
|
|
83
|
-
// 设置自动 padding 为 true,删除填充补位
|
|
84
|
-
decipher.setAutoPadding(true);
|
|
85
|
-
const decoded = decipher.update(encryptedDataBuf, undefined, 'utf8') + decipher.final('utf8');
|
|
86
|
-
const decodedData = JSON.parse(decoded);
|
|
87
|
-
Throw.if(decodedData.watermark.appid !== this.config.appId, '加密验证失败');
|
|
88
|
-
return decodedData;
|
|
89
|
-
}
|
|
90
|
-
catch (err) {
|
|
91
|
-
throw new Error('加密验证失败');
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
async getLiveInfo(start, limit) {
|
|
95
|
-
const data = await this.fetch((token) => `https://api.weixin.qq.com/wxa/business/getliveinfo?access_token=${token}`, 'post', { start, limit });
|
|
96
|
-
return data.room_info;
|
|
97
|
-
}
|
|
98
|
-
async getLiveReplay(room_id, start, limit) {
|
|
99
|
-
const data = await this.fetch((token) => `https://api.weixin.qq.com/wxa/business/getliveinfo?access_token=${token}`, 'post', { room_id, start, limit, action: 'get_replay' });
|
|
100
|
-
return data.live_replay;
|
|
101
|
-
}
|
|
102
|
-
async getPhone(code, openid) {
|
|
103
|
-
const data = await this.fetch((token) => `https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=${token}`, 'post', { code, openid });
|
|
104
|
-
return {
|
|
105
|
-
phoneNumber: data.phone_info.phoneNumber,
|
|
106
|
-
purePhoneNumber: data.phone_info.purePhoneNumber,
|
|
107
|
-
countryCode: data.phone_info.countryCode,
|
|
108
|
-
timestamp: data.phone_info.watermark.timestamp,
|
|
109
|
-
appid: data.phone_info.watermark.appid
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
}
|
package/wx/organ.d.ts
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { BaseWx } from './base.js';
|
|
2
|
-
import { WxDepartment, WxOrganConfig, WxOrganFile, WxOrganImage, WxOrganMarkDown, WxOrganMini, WxOrganMpNews, WxOrganNews, WxOrganTaskCard, WxOrganText, WxOrganTextCard, WxOrganUser, WxOrganUserSimply, WxOrganVideo, WxOrganVoice } from './types.js';
|
|
3
|
-
export declare class WxOrgan extends BaseWx {
|
|
4
|
-
protected name: string;
|
|
5
|
-
private config;
|
|
6
|
-
private miniMessCache;
|
|
7
|
-
private messCache;
|
|
8
|
-
constructor(config: WxOrganConfig);
|
|
9
|
-
createDepartment(param: WxDepartment): Promise<number>;
|
|
10
|
-
updateDepartment(param: WxDepartment): Promise<void>;
|
|
11
|
-
deleteDepartment(id: number): Promise<void>;
|
|
12
|
-
getDepartmentList(id?: number): Promise<WxDepartment[]>;
|
|
13
|
-
createUser(param: WxOrganUser): Promise<string | number>;
|
|
14
|
-
getUser(userid: number | string): Promise<WxOrganUser>;
|
|
15
|
-
updateUser(param: WxOrganUser): Promise<void>;
|
|
16
|
-
deleteUser(userid: number | string): Promise<void>;
|
|
17
|
-
batchDeleteUser(useridlist: Array<number | string>): Promise<void>;
|
|
18
|
-
getDeptUserSimply(department_id: number, fetch_child: boolean): Promise<WxOrganUserSimply[]>;
|
|
19
|
-
getDeptUser(department_id: number, fetch_child: boolean): Promise<WxOrganUser[]>;
|
|
20
|
-
userid2openid(userid: number | string): Promise<string>;
|
|
21
|
-
openid2userid(openid: string): Promise<number | string>;
|
|
22
|
-
authsucc(userid: string): Promise<void>;
|
|
23
|
-
inviteUsers({ user, party, tag }: {
|
|
24
|
-
user?: Array<number | string>;
|
|
25
|
-
party?: number[];
|
|
26
|
-
tag?: number[];
|
|
27
|
-
}): Promise<{
|
|
28
|
-
invaliduser?: Array<number | string>;
|
|
29
|
-
invalidparty?: number[];
|
|
30
|
-
invalidtag?: number[];
|
|
31
|
-
}>;
|
|
32
|
-
createTag(tagname: string, tagid: number): Promise<number>;
|
|
33
|
-
updateTag(tagname: string, tagid: number): Promise<void>;
|
|
34
|
-
deleteTag(tagid: number): Promise<void>;
|
|
35
|
-
createTagUser(tagid: number, userlist: Array<string | number>): Promise<void>;
|
|
36
|
-
deleteTagUser(tagid: number, userlist: Array<string | number>): Promise<void>;
|
|
37
|
-
getTagUser(tagid: number): Promise<{
|
|
38
|
-
tagname: string;
|
|
39
|
-
userlist: Array<{
|
|
40
|
-
userid: string | number;
|
|
41
|
-
name: string;
|
|
42
|
-
}>;
|
|
43
|
-
partylist: number[];
|
|
44
|
-
}>;
|
|
45
|
-
getTag(): Promise<Array<{
|
|
46
|
-
tagid: number;
|
|
47
|
-
tagname: string;
|
|
48
|
-
}>>;
|
|
49
|
-
updateTaskCard(userids: Array<string | number>, task_id: string, clicked_key: string): Promise<void>;
|
|
50
|
-
sendMiniMs({ touser, toparty, totag, name, scene, ms }: {
|
|
51
|
-
touser?: Array<number | string>;
|
|
52
|
-
toparty?: number[];
|
|
53
|
-
totag?: number[];
|
|
54
|
-
name: string;
|
|
55
|
-
scene?: string;
|
|
56
|
-
ms: WxOrganMini;
|
|
57
|
-
}): Promise<void>;
|
|
58
|
-
sendMs({ touser, toparty, totag, name, ms }: {
|
|
59
|
-
touser?: Array<number | string>;
|
|
60
|
-
toparty?: number[];
|
|
61
|
-
totag?: number[];
|
|
62
|
-
name: string;
|
|
63
|
-
ms: WxOrganText | WxOrganImage | WxOrganVoice | WxOrganVideo | WxOrganFile | WxOrganTextCard | WxOrganNews | WxOrganMpNews | WxOrganMarkDown | WxOrganTaskCard;
|
|
64
|
-
}): Promise<void>;
|
|
65
|
-
}
|