@certd/lib-server 1.41.4 → 1.42.0

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,5 +1,5 @@
1
- import type { IMidwayContainer } from '@midwayjs/core';
2
- import * as koa from '@midwayjs/koa';
1
+ import type { IMidwayContainer } from "@midwayjs/core";
2
+ import * as koa from "@midwayjs/koa";
3
3
  export declare abstract class BaseController {
4
4
  ctx: koa.Context;
5
5
  applicationContext: IMidwayContainer;
@@ -7,10 +7,10 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  var __metadata = (this && this.__metadata) || function (k, v) {
8
8
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
9
  };
10
- import { ApplicationContext, Inject } from '@midwayjs/core';
11
- import * as koa from '@midwayjs/koa';
12
- import { Constants } from './constants.js';
13
- import { isEnterprise } from './mode.js';
10
+ import { ApplicationContext, Inject } from "@midwayjs/core";
11
+ import * as koa from "@midwayjs/koa";
12
+ import { Constants } from "./constants.js";
13
+ import { isEnterprise } from "./mode.js";
14
14
  export class BaseController {
15
15
  ctx;
16
16
  applicationContext;
@@ -42,14 +42,14 @@ export class BaseController {
42
42
  getUserId() {
43
43
  const userId = this.ctx.user?.id;
44
44
  if (userId == null) {
45
- throw new Error('Token已过期');
45
+ throw new Error("Token已过期");
46
46
  }
47
47
  return userId;
48
48
  }
49
49
  getLoginUser() {
50
50
  const user = this.ctx.user;
51
51
  if (user == null) {
52
- throw new Error('Token已过期');
52
+ throw new Error("Token已过期");
53
53
  }
54
54
  return user;
55
55
  }
@@ -83,7 +83,8 @@ export class BaseController {
83
83
  userId = -1; // 企业管理模式下,用户id固定-1
84
84
  }
85
85
  return {
86
- projectId, userId
86
+ projectId,
87
+ userId,
87
88
  };
88
89
  }
89
90
  async getProjectUserIdRead() {
@@ -105,7 +106,7 @@ export class BaseController {
105
106
  * @param id
106
107
  */
107
108
  async checkOwner(service, id, permission, allowAdmin = false) {
108
- let { projectId, userId } = await this.getProjectUserId(permission);
109
+ const { projectId, userId } = await this.getProjectUserId(permission);
109
110
  const authService = await this.applicationContext.getAsync("authService");
110
111
  if (projectId) {
111
112
  await authService.checkProjectId(service, id, projectId);
@@ -1,7 +1,7 @@
1
- import { EntityTarget, FindOneOptions, Repository, SelectQueryBuilder } from 'typeorm';
2
- import { TypeORMDataSourceManager } from '@midwayjs/typeorm';
3
- import { EntityManager } from 'typeorm/entity-manager/EntityManager.js';
4
- import { FindManyOptions } from 'typeorm';
1
+ import { EntityTarget, FindOneOptions, Repository, SelectQueryBuilder } from "typeorm";
2
+ import { TypeORMDataSourceManager } from "@midwayjs/typeorm";
3
+ import { EntityManager } from "typeorm/entity-manager/EntityManager.js";
4
+ import { FindManyOptions } from "typeorm";
5
5
  export type PageReq<T = any> = {
6
6
  page?: {
7
7
  offset: number;
@@ -32,7 +32,7 @@ export declare abstract class BaseService<T> {
32
32
  */
33
33
  protected transactionWithCtx<T>(ctx: ServiceContext, callback: (manager: EntityManager) => Promise<T>): Promise<T>;
34
34
  protected getRepo<E>(ctx: ServiceContext, entity: EntityTarget<E>): Repository<E>;
35
- protected buildUserProjectQuery(userId: number, projectId?: number): {
35
+ buildUserProjectQuery(userId: number, projectId?: number): {
36
36
  [key: string]: any;
37
37
  userId: number;
38
38
  projectId?: number;
@@ -70,7 +70,8 @@ export declare abstract class BaseService<T> {
70
70
  * @param param 数据
71
71
  */
72
72
  add(param: any): Promise<{
73
- id: any;
73
+ id: number;
74
+ [key: string]: any;
74
75
  }>;
75
76
  /**
76
77
  * 修改
@@ -7,18 +7,18 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  var __metadata = (this && this.__metadata) || function (k, v) {
8
8
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
9
  };
10
- import { PermissionException, ValidateException } from './exception/index.js';
11
- import { In } from 'typeorm';
12
- import { Inject } from '@midwayjs/core';
13
- import { TypeORMDataSourceManager } from '@midwayjs/typeorm';
14
- import { Constants } from './constants.js';
10
+ import { PermissionException, ValidateException } from "./exception/index.js";
11
+ import { In } from "typeorm";
12
+ import { Inject } from "@midwayjs/core";
13
+ import { TypeORMDataSourceManager } from "@midwayjs/typeorm";
14
+ import { Constants } from "./constants.js";
15
15
  /**
16
16
  * 服务基类
17
17
  */
18
18
  export class BaseService {
19
19
  dataSourceManager;
20
20
  async transaction(callback) {
21
- const dataSource = this.dataSourceManager.getDataSource('default');
21
+ const dataSource = this.dataSourceManager.getDataSource("default");
22
22
  return await dataSource.transaction(callback);
23
23
  }
24
24
  /**
@@ -34,7 +34,7 @@ export class BaseService {
34
34
  if (ctx.manager) {
35
35
  return ctx.manager.getRepository(entity);
36
36
  }
37
- const dataSource = this.dataSourceManager.getDataSource('default');
37
+ const dataSource = this.dataSourceManager.getDataSource("default");
38
38
  return dataSource.getRepository(entity);
39
39
  }
40
40
  buildUserProjectQuery(userId, projectId) {
@@ -53,7 +53,7 @@ export class BaseService {
53
53
  */
54
54
  async info(id, infoIgnoreProperty) {
55
55
  if (!id) {
56
- throw new ValidateException('id不能为空');
56
+ throw new ValidateException("id不能为空");
57
57
  }
58
58
  const info = await this.getRepository().findOneBy({ id });
59
59
  if (info && infoIgnoreProperty) {
@@ -99,10 +99,10 @@ export class BaseService {
99
99
  }
100
100
  resolveIdArr(ids) {
101
101
  if (!ids) {
102
- throw new ValidateException('ids不能为空');
102
+ throw new ValidateException("ids不能为空");
103
103
  }
104
- if (typeof ids === 'string') {
105
- return ids.split(',');
104
+ if (typeof ids === "string") {
105
+ return ids.split(",");
106
106
  }
107
107
  else if (!Array.isArray(ids)) {
108
108
  return [ids];
@@ -138,7 +138,7 @@ export class BaseService {
138
138
  */
139
139
  async update(param) {
140
140
  if (!param.id)
141
- throw new ValidateException('id 不能为空');
141
+ throw new ValidateException("id 不能为空");
142
142
  param.updateTime = new Date();
143
143
  await this.addOrUpdate(param);
144
144
  await this.modifyAfter(param);
@@ -173,7 +173,7 @@ export class BaseService {
173
173
  }
174
174
  buildListQuery(listReq) {
175
175
  const { query, sort, buildQuery, select } = listReq;
176
- const qb = this.getRepository().createQueryBuilder('main');
176
+ const qb = this.getRepository().createQueryBuilder("main");
177
177
  if (select) {
178
178
  qb.setFindOptions({ select });
179
179
  }
@@ -194,10 +194,10 @@ export class BaseService {
194
194
  }
195
195
  });
196
196
  if (found) {
197
- qb.addOrderBy('main.' + sort.prop, sort.asc ? 'ASC' : 'DESC');
197
+ qb.addOrderBy("main." + sort.prop, sort.asc ? "ASC" : "DESC");
198
198
  }
199
199
  }
200
- qb.addOrderBy('id', 'DESC');
200
+ qb.addOrderBy("id", "DESC");
201
201
  //自定义query
202
202
  if (buildQuery) {
203
203
  buildQuery(qb);
@@ -211,12 +211,12 @@ export class BaseService {
211
211
  const qb = this.buildListQuery(listReq);
212
212
  return await qb.getMany();
213
213
  }
214
- async checkUserId(ids = 0, userId, userKey = 'userId') {
214
+ async checkUserId(ids = 0, userId, userKey = "userId") {
215
215
  if (ids == null) {
216
- throw new ValidateException('id不能为空');
216
+ throw new ValidateException("id不能为空");
217
217
  }
218
218
  if (userId == null) {
219
- throw new ValidateException('userId不能为空');
219
+ throw new ValidateException("userId不能为空");
220
220
  }
221
221
  if (!Array.isArray(ids)) {
222
222
  ids = [ids];
@@ -236,13 +236,13 @@ export class BaseService {
236
236
  if (!res || res.length === ids.length) {
237
237
  return;
238
238
  }
239
- throw new PermissionException('权限不足');
239
+ throw new PermissionException("权限不足");
240
240
  }
241
241
  filterIds(ids) {
242
242
  if (!ids) {
243
- throw new ValidateException('ids不能为空');
243
+ throw new ValidateException("ids不能为空");
244
244
  }
245
- return ids.filter((item) => {
245
+ return ids.filter(item => {
246
246
  return item != null && item != "";
247
247
  });
248
248
  }
@@ -273,7 +273,7 @@ __decorate([
273
273
  export function checkUserProjectParam(userId, projectId) {
274
274
  if (projectId != null) {
275
275
  if (userId !== Constants.enterpriseUserId) {
276
- throw new ValidateException('userId projectId 错误');
276
+ throw new ValidateException("userId projectId 错误");
277
277
  }
278
278
  return true;
279
279
  }
@@ -281,6 +281,6 @@ export function checkUserProjectParam(userId, projectId) {
281
281
  if (userId != null) {
282
282
  return true;
283
283
  }
284
- throw new ValidateException('userId不能为空');
284
+ throw new ValidateException("userId不能为空");
285
285
  }
286
286
  }
@@ -1,6 +1,6 @@
1
- import { PlusRequestService } from '@certd/plus-core';
2
- import { HttpRequestConfig } from '@certd/basic';
3
- import { SysSettingsService } from '../../settings/index.js';
1
+ import { PlusRequestService } from "@certd/plus-core";
2
+ import { HttpRequestConfig } from "@certd/basic";
3
+ import { SysSettingsService } from "../../settings/index.js";
4
4
  export declare class PlusService {
5
5
  sysSettingsService: SysSettingsService;
6
6
  plusRequestService: PlusRequestService;
@@ -7,12 +7,12 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  var __metadata = (this && this.__metadata) || function (k, v) {
8
8
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
9
  };
10
- import { Inject, Provide, Scope, ScopeEnum } from '@midwayjs/core';
11
- import { AppKey, PlusRequestService } from '@certd/plus-core';
12
- import { cache, http, logger } from '@certd/basic';
13
- import { SysInstallInfo, SysLicenseInfo, SysSettingsService } from '../../settings/index.js';
14
- import { merge } from 'lodash-es';
15
- import fs from 'fs';
10
+ import { Inject, Provide, Scope, ScopeEnum } from "@midwayjs/core";
11
+ import { AppKey, PlusRequestService } from "@certd/plus-core";
12
+ import { cache, http, logger } from "@certd/basic";
13
+ import { SysInstallInfo, SysLicenseInfo, SysSettingsService } from "../../settings/index.js";
14
+ import { merge } from "lodash-es";
15
+ import fs from "fs";
16
16
  let PlusService = class PlusService {
17
17
  sysSettingsService;
18
18
  plusRequestService;
@@ -63,15 +63,15 @@ let PlusService = class PlusService {
63
63
  const licenseInfo = await this.sysSettingsService.getSetting(SysLicenseInfo);
64
64
  if (!licenseInfo.license) {
65
65
  await plusRequestService.register();
66
- logger.info('站点注册成功');
66
+ logger.info("站点注册成功");
67
67
  this.plusRequestService = null;
68
68
  }
69
69
  }
70
70
  async userPreBind(userId) {
71
71
  const plusRequestService = await this.getPlusRequestService();
72
72
  await plusRequestService.requestWithoutSign({
73
- url: '/activation/subject/preBind',
74
- method: 'POST',
73
+ url: "/activation/subject/preBind",
74
+ method: "POST",
75
75
  data: {
76
76
  userId,
77
77
  appKey: AppKey,
@@ -85,9 +85,9 @@ let PlusService = class PlusService {
85
85
  if (attachments.length > 0) {
86
86
  const newAttachments = [];
87
87
  attachments.forEach((item) => {
88
- const name = item.filename || item.path.split('/').pop();
88
+ const name = item.filename || item.path.split("/").pop();
89
89
  const body = item.content || fs.readFileSync(item.path);
90
- const bodyBase64 = Buffer.from(body).toString('base64');
90
+ const bodyBase64 = Buffer.from(body).toString("base64");
91
91
  item = {
92
92
  name,
93
93
  body: bodyBase64,
@@ -97,7 +97,7 @@ let PlusService = class PlusService {
97
97
  attachments = newAttachments;
98
98
  }
99
99
  await plusRequestService.request({
100
- url: '/activation/emailSend',
100
+ url: "/activation/emailSend",
101
101
  data: {
102
102
  subject: email.subject,
103
103
  to: email.receivers,
@@ -108,7 +108,7 @@ let PlusService = class PlusService {
108
108
  });
109
109
  }
110
110
  async getAccessToken() {
111
- const cacheKey = 'certd:subject:access_token';
111
+ const cacheKey = "certd:subject:access_token";
112
112
  const token = cache.get(cacheKey);
113
113
  if (token) {
114
114
  return token;
@@ -126,11 +126,11 @@ let PlusService = class PlusService {
126
126
  await this.register();
127
127
  const plusRequestService = await this.getPlusRequestService();
128
128
  const res = await plusRequestService.request({
129
- url: '/activation/subject/vip/trialGet',
130
- method: 'POST',
129
+ url: "/activation/subject/vip/trialGet",
130
+ method: "POST",
131
131
  data: {
132
- vipType
133
- }
132
+ vipType,
133
+ },
134
134
  });
135
135
  if (res.license) {
136
136
  await this.updateLicense(res.license);
@@ -139,7 +139,7 @@ let PlusService = class PlusService {
139
139
  };
140
140
  }
141
141
  else {
142
- throw new Error('您已经领取过VIP试用了');
142
+ throw new Error("您已经领取过VIP试用了");
143
143
  }
144
144
  }
145
145
  async getTodayOrderCount() {
@@ -152,7 +152,7 @@ let PlusService = class PlusService {
152
152
  const token = await this.getAccessToken();
153
153
  merge(config, {
154
154
  baseURL: plusRequestService.getBaseURL(),
155
- method: 'post',
155
+ method: "post",
156
156
  headers: {
157
157
  Authorization: `Berear ${token}`,
158
158
  },
@@ -7,7 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  var __metadata = (this && this.__metadata) || function (k, v) {
8
8
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
9
  };
10
- import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
10
+ import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
11
11
  /**
12
12
  */
13
13
  let SysSettingsEntity = class SysSettingsEntity {
@@ -25,38 +25,38 @@ __decorate([
25
25
  __metadata("design:type", Number)
26
26
  ], SysSettingsEntity.prototype, "id", void 0);
27
27
  __decorate([
28
- Column({ comment: 'key', length: 100 }),
28
+ Column({ comment: "key", length: 100 }),
29
29
  __metadata("design:type", String)
30
30
  ], SysSettingsEntity.prototype, "key", void 0);
31
31
  __decorate([
32
- Column({ comment: '名称', length: 100 }),
32
+ Column({ comment: "名称", length: 100 }),
33
33
  __metadata("design:type", String)
34
34
  ], SysSettingsEntity.prototype, "title", void 0);
35
35
  __decorate([
36
- Column({ name: 'setting', comment: '设置', length: 1024, nullable: true }),
36
+ Column({ name: "setting", comment: "设置", length: 1024, nullable: true }),
37
37
  __metadata("design:type", String)
38
38
  ], SysSettingsEntity.prototype, "setting", void 0);
39
39
  __decorate([
40
- Column({ name: 'access', comment: '访问权限' }),
40
+ Column({ name: "access", comment: "访问权限" }),
41
41
  __metadata("design:type", String)
42
42
  ], SysSettingsEntity.prototype, "access", void 0);
43
43
  __decorate([
44
44
  Column({
45
- name: 'create_time',
46
- comment: '创建时间',
47
- default: () => 'CURRENT_TIMESTAMP',
45
+ name: "create_time",
46
+ comment: "创建时间",
47
+ default: () => "CURRENT_TIMESTAMP",
48
48
  }),
49
49
  __metadata("design:type", Date)
50
50
  ], SysSettingsEntity.prototype, "createTime", void 0);
51
51
  __decorate([
52
52
  Column({
53
- name: 'update_time',
54
- comment: '修改时间',
55
- default: () => 'CURRENT_TIMESTAMP',
53
+ name: "update_time",
54
+ comment: "修改时间",
55
+ default: () => "CURRENT_TIMESTAMP",
56
56
  }),
57
57
  __metadata("design:type", Date)
58
58
  ], SysSettingsEntity.prototype, "updateTime", void 0);
59
59
  SysSettingsEntity = __decorate([
60
- Entity('sys_settings')
60
+ Entity("sys_settings")
61
61
  ], SysSettingsEntity);
62
62
  export { SysSettingsEntity };
@@ -1,16 +1,16 @@
1
- import { cloneDeep } from 'lodash-es';
1
+ import { cloneDeep } from "lodash-es";
2
2
  export class BaseSettings {
3
3
  static __key__;
4
4
  static __title__;
5
- static __access__ = 'private';
5
+ static __access__ = "private";
6
6
  static getCacheKey() {
7
- return 'settings.' + this.__key__;
7
+ return "settings." + this.__key__;
8
8
  }
9
9
  }
10
10
  export class SysPublicSettings extends BaseSettings {
11
- static __key__ = 'sys.public';
12
- static __title__ = '系统公共设置';
13
- static __access__ = 'public';
11
+ static __key__ = "sys.public";
12
+ static __title__ = "系统公共设置";
13
+ static __access__ = "public";
14
14
  registerEnabled = false;
15
15
  userValidTimeEnabled = false;
16
16
  passwordLoginEnabled = true;
@@ -50,24 +50,24 @@ export class SysPublicSettings extends BaseSettings {
50
50
  adminMode = "saas";
51
51
  }
52
52
  export class SysPrivateSettings extends BaseSettings {
53
- static __title__ = '系统私有设置';
54
- static __access__ = 'private';
55
- static __key__ = 'sys.private';
53
+ static __title__ = "系统私有设置";
54
+ static __access__ = "private";
55
+ static __key__ = "sys.private";
56
56
  jwtKey;
57
57
  encryptSecret;
58
- httpsProxy = '';
59
- httpProxy = '';
60
- noProxy = '';
61
- commonHeaders = '';
58
+ httpsProxy = "";
59
+ httpProxy = "";
60
+ noProxy = "";
61
+ commonHeaders = "";
62
62
  reverseProxies = {};
63
- dnsResultOrder = '';
63
+ dnsResultOrder = "";
64
64
  commonCnameEnabled = true;
65
65
  httpRequestTimeout = 30;
66
66
  pipelineMaxRunningCount;
67
- environmentVars = '';
67
+ environmentVars = "";
68
68
  acmeWalkFromAuthoritative = true;
69
69
  sms = {
70
- type: 'aliyun',
70
+ type: "aliyun",
71
71
  config: {},
72
72
  };
73
73
  removeSecret() {
@@ -78,9 +78,9 @@ export class SysPrivateSettings extends BaseSettings {
78
78
  }
79
79
  }
80
80
  export class SysInstallInfo extends BaseSettings {
81
- static __title__ = '系统安装信息';
82
- static __key__ = 'sys.install';
83
- static __access__ = 'private';
81
+ static __title__ = "系统安装信息";
82
+ static __key__ = "sys.install";
83
+ static __access__ = "private";
84
84
  installTime;
85
85
  siteId;
86
86
  bindUserId;
@@ -90,15 +90,15 @@ export class SysInstallInfo extends BaseSettings {
90
90
  appKey;
91
91
  }
92
92
  export class SysLicenseInfo extends BaseSettings {
93
- static __title__ = '授权许可信息';
94
- static __key__ = 'sys.license';
95
- static __access__ = 'private';
93
+ static __title__ = "授权许可信息";
94
+ static __key__ = "sys.license";
95
+ static __access__ = "private";
96
96
  license;
97
97
  }
98
98
  export class SysEmailConf extends BaseSettings {
99
- static __title__ = '邮箱配置';
100
- static __key__ = 'sys.email';
101
- static __access__ = 'private';
99
+ static __title__ = "邮箱配置";
100
+ static __key__ = "sys.email";
101
+ static __access__ = "private";
102
102
  host;
103
103
  port;
104
104
  auth;
@@ -109,18 +109,18 @@ export class SysEmailConf extends BaseSettings {
109
109
  templates;
110
110
  }
111
111
  export class SysSiteInfo extends BaseSettings {
112
- static __title__ = '站点信息';
113
- static __key__ = 'sys.site';
114
- static __access__ = 'public';
112
+ static __title__ = "站点信息";
113
+ static __key__ = "sys.site";
114
+ static __access__ = "public";
115
115
  title;
116
116
  slogan;
117
117
  logo;
118
118
  loginLogo;
119
119
  }
120
120
  export class SysSecretBackup extends BaseSettings {
121
- static __title__ = '密钥信息备份';
122
- static __key__ = 'sys.secret.backup';
123
- static __access__ = 'private';
121
+ static __title__ = "密钥信息备份";
122
+ static __key__ = "sys.secret.backup";
123
+ static __access__ = "private";
124
124
  siteId;
125
125
  encryptSecret;
126
126
  }
@@ -128,9 +128,9 @@ export class SysSecretBackup extends BaseSettings {
128
128
  * 不要修改
129
129
  */
130
130
  export class SysSecret extends BaseSettings {
131
- static __title__ = '密钥信息';
132
- static __key__ = 'sys.secret';
133
- static __access__ = 'private';
131
+ static __title__ = "密钥信息";
132
+ static __key__ = "sys.secret";
133
+ static __access__ = "private";
134
134
  siteId;
135
135
  encryptSecret;
136
136
  }
@@ -138,38 +138,38 @@ export class SysSiteEnv {
138
138
  agent;
139
139
  }
140
140
  export class SysHeaderMenus extends BaseSettings {
141
- static __title__ = '顶部菜单';
142
- static __key__ = 'sys.header.menus';
143
- static __access__ = 'public';
141
+ static __title__ = "顶部菜单";
142
+ static __key__ = "sys.header.menus";
143
+ static __access__ = "public";
144
144
  menus;
145
145
  }
146
146
  export class SysPaymentSetting extends BaseSettings {
147
- static __title__ = '支付设置';
148
- static __key__ = 'sys.payment';
149
- static __access__ = 'private';
147
+ static __title__ = "支付设置";
148
+ static __key__ = "sys.payment";
149
+ static __access__ = "private";
150
150
  yizhifu = { enabled: false };
151
151
  alipay = { enabled: false };
152
152
  wxpay = { enabled: false };
153
153
  }
154
154
  export class SysSuiteSetting extends BaseSettings {
155
- static __title__ = '套餐设置';
156
- static __key__ = 'sys.suite';
157
- static __access__ = 'private';
155
+ static __title__ = "套餐设置";
156
+ static __key__ = "sys.suite";
157
+ static __access__ = "private";
158
158
  enabled = false;
159
159
  allowSuiteStack = false;
160
160
  registerGift;
161
161
  intro;
162
162
  }
163
163
  export class SysAutoFixSetting extends BaseSettings {
164
- static __title__ = '自动修复记录';
165
- static __key__ = 'sys.auto.fix';
166
- static __access__ = 'private';
164
+ static __title__ = "自动修复记录";
165
+ static __key__ = "sys.auto.fix";
166
+ static __access__ = "private";
167
167
  fixed = {};
168
168
  }
169
169
  export class SysSafeSetting extends BaseSettings {
170
- static __title__ = '站点安全设置';
171
- static __key__ = 'sys.safe';
172
- static __access__ = 'private';
170
+ static __title__ = "站点安全设置";
171
+ static __key__ = "sys.safe";
172
+ static __access__ = "private";
173
173
  // 站点隐藏
174
174
  hidden = {
175
175
  enabled: false,
@@ -1,9 +1,11 @@
1
- import { IAccessService } from "@certd/pipeline";
1
+ import { IAccessService, IRuntimeDepsService } from "@certd/pipeline";
2
+ export type AccessRuntimeDepsService = IRuntimeDepsService;
2
3
  export declare class AccessGetter implements IAccessService {
3
4
  userId: number;
4
5
  projectId?: number;
5
- getter: <T>(id: any, userId?: number, projectId?: number, ignorePermission?: boolean) => Promise<T>;
6
- constructor(userId: number, projectId: number, getter: (id: any, userId: number, projectId?: number, ignorePermission?: boolean) => Promise<any>);
6
+ runtimeDepsService?: AccessRuntimeDepsService;
7
+ getter: <T>(id: any, userId?: number, projectId?: number, ignorePermission?: boolean, runtimeDepsService?: AccessRuntimeDepsService) => Promise<T>;
8
+ constructor(userId: number, projectId: number, getter: (id: any, userId: number, projectId?: number, ignorePermission?: boolean, runtimeDepsService?: AccessRuntimeDepsService) => Promise<any>, runtimeDepsService?: AccessRuntimeDepsService);
7
9
  getById<T = any>(id: any): Promise<T>;
8
10
  getCommonById<T = any>(id: any): Promise<T>;
9
11
  }
@@ -1,16 +1,18 @@
1
1
  export class AccessGetter {
2
2
  userId;
3
3
  projectId;
4
+ runtimeDepsService;
4
5
  getter;
5
- constructor(userId, projectId, getter) {
6
+ constructor(userId, projectId, getter, runtimeDepsService) {
6
7
  this.userId = userId;
7
8
  this.projectId = projectId;
8
9
  this.getter = getter;
10
+ this.runtimeDepsService = runtimeDepsService;
9
11
  }
10
12
  async getById(id) {
11
- return await this.getter(id, this.userId, this.projectId);
13
+ return await this.getter(id, this.userId, this.projectId, false, this.runtimeDepsService);
12
14
  }
13
15
  async getCommonById(id) {
14
- return await this.getter(id, 0, null);
16
+ return await this.getter(id, 0, null, false, this.runtimeDepsService);
15
17
  }
16
18
  }
@@ -1,5 +1,6 @@
1
1
  import { Repository } from "typeorm";
2
2
  import { BaseService, PageReq } from "../../../index.js";
3
+ import type { AccessRuntimeDepsService } from "./access-getter.js";
3
4
  import { AccessEntity } from "../entity/access.js";
4
5
  import { EncryptService } from "./encrypt-service.js";
5
6
  /**
@@ -16,7 +17,8 @@ export declare class AccessService extends BaseService<AccessEntity> {
16
17
  limit: number;
17
18
  }>;
18
19
  add(param: any): Promise<{
19
- id: any;
20
+ id: number;
21
+ [key: string]: any;
20
22
  }>;
21
23
  encryptSetting(param: any, oldSettingEntity?: AccessEntity): void;
22
24
  /**
@@ -33,8 +35,8 @@ export declare class AccessService extends BaseService<AccessEntity> {
33
35
  userId: number;
34
36
  projectId: number;
35
37
  }>;
36
- getAccessById(id: any, checkUserId: boolean, userId?: number, projectId?: number): Promise<any>;
37
- getById(id: any, userId: number, projectId?: number): Promise<any>;
38
+ getAccessById(id: any, checkUserId: boolean, userId?: number, projectId?: number, runtimeDepsService?: AccessRuntimeDepsService): Promise<any>;
39
+ getById(id: any, userId: number, projectId?: number, _ignorePermission?: boolean, runtimeDepsService?: AccessRuntimeDepsService): Promise<any>;
38
40
  decryptAccessEntity(entity: AccessEntity): any;
39
41
  getDefineList(): {
40
42
  key: string;
@@ -14,7 +14,7 @@ import { AccessGetter, BaseService, PermissionException, ValidateException } fro
14
14
  import { AccessEntity } from "../entity/access.js";
15
15
  import { accessRegistry, newAccess } from "@certd/pipeline";
16
16
  import { EncryptService } from "./encrypt-service.js";
17
- import { logger, utils } from "@certd/basic";
17
+ import { http, logger, utils } from "@certd/basic";
18
18
  /**
19
19
  * 授权
20
20
  */
@@ -154,7 +154,7 @@ let AccessService = class AccessService extends BaseService {
154
154
  projectId: entity.projectId,
155
155
  };
156
156
  }
157
- async getAccessById(id, checkUserId, userId, projectId) {
157
+ async getAccessById(id, checkUserId, userId, projectId, runtimeDepsService) {
158
158
  const entity = await this.info(id);
159
159
  if (entity == null) {
160
160
  throw new Error(`该授权配置不存在,请确认是否已被删除:id=${id}`);
@@ -176,11 +176,19 @@ let AccessService = class AccessService extends BaseService {
176
176
  id: entity.id,
177
177
  ...setting,
178
178
  };
179
- const accessGetter = new AccessGetter(userId, projectId, this.getById.bind(this));
180
- return await newAccess(entity.type, input, accessGetter);
179
+ const getAccessById = this.getById.bind(this);
180
+ const accessGetter = new AccessGetter(userId, projectId, getAccessById, runtimeDepsService);
181
+ const accessContext = {
182
+ logger,
183
+ http,
184
+ utils,
185
+ accessService: accessGetter,
186
+ };
187
+ const access = await newAccess(entity.type, input, accessGetter, accessContext);
188
+ return access;
181
189
  }
182
- async getById(id, userId, projectId) {
183
- return await this.getAccessById(id, true, userId, projectId);
190
+ async getById(id, userId, projectId, _ignorePermission, runtimeDepsService) {
191
+ return await this.getAccessById(id, true, userId, projectId, runtimeDepsService);
184
192
  }
185
193
  decryptAccessEntity(entity) {
186
194
  let setting = {};
@@ -1,5 +1,5 @@
1
1
  import { HttpClient, ILogger, utils } from "@certd/basic";
2
- import { FormItemProps, IServiceGetter, PluginRequestHandleReq, Registrable } from "@certd/pipeline";
2
+ import { FormItemProps, IRuntimeDepsService, IServiceGetter, PluginRequestHandleReq, Registrable } from "@certd/pipeline";
3
3
  export type AddonRequestHandleReqInput<T = any> = {
4
4
  id?: number;
5
5
  title?: string;
@@ -15,6 +15,8 @@ export type AddonInputDefine = FormItemProps & {
15
15
  export type AddonDefine = Registrable & {
16
16
  addonType: string;
17
17
  needPlus?: boolean;
18
+ dependPlugins?: Record<string, string>;
19
+ dependPackages?: Record<string, string>;
18
20
  input?: {
19
21
  [key: string]: AddonInputDefine;
20
22
  };
@@ -46,10 +48,12 @@ export declare abstract class BaseAddon implements IAddon {
46
48
  ctx: AddonContext;
47
49
  http: HttpClient;
48
50
  logger: ILogger;
51
+ runtimeDepsService?: IRuntimeDepsService;
52
+ importRuntime(specifier: string): Promise<any>;
49
53
  title: string;
50
54
  onInstance(): Promise<void>;
51
55
  getAccess<T = any>(accessId: string | number, isCommon?: boolean): Promise<T>;
52
- setCtx(ctx: AddonContext): void;
56
+ setCtx(ctx: AddonContext): Promise<void>;
53
57
  setDefine: (define: AddonDefine) => void;
54
58
  onRequest(req: AddonRequestHandleReq): Promise<any>;
55
59
  }
@@ -5,6 +5,13 @@ export class BaseAddon {
5
5
  ctx;
6
6
  http;
7
7
  logger;
8
+ runtimeDepsService;
9
+ async importRuntime(specifier) {
10
+ if (!this.runtimeDepsService) {
11
+ return await import(specifier);
12
+ }
13
+ return await this.runtimeDepsService.importRuntime(specifier, this.logger);
14
+ }
8
15
  title;
9
16
  // eslint-disable-next-line @typescript-eslint/no-empty-function
10
17
  async onInstance() { }
@@ -40,10 +47,16 @@ export class BaseAddon {
40
47
  }
41
48
  return res;
42
49
  }
43
- setCtx(ctx) {
50
+ async setCtx(ctx) {
44
51
  this.ctx = ctx;
45
52
  this.http = ctx.http;
46
53
  this.logger = ctx.logger;
54
+ if (!this.runtimeDepsService && this.ctx.serviceGetter) {
55
+ this.runtimeDepsService = await this.ctx.serviceGetter.get("runtimeDepsService");
56
+ }
57
+ if (this.runtimeDepsService && this.define?.addonType && this.define?.name) {
58
+ await this.runtimeDepsService.ensureRuntimeDependencies({ pluginKeys: `addon:${this.define.addonType}:${this.define.name}`, logger: this.logger });
59
+ }
47
60
  }
48
61
  setDefine = (define) => {
49
62
  this.define = define;
@@ -57,7 +57,7 @@ export async function newAddon(addonType, type, input, ctx) {
57
57
  throw new Error("ctx is required");
58
58
  }
59
59
  plugin.setDefine(register.define);
60
- plugin.setCtx(ctx);
60
+ await plugin.setCtx(ctx);
61
61
  await plugin.onInstance();
62
62
  return plugin;
63
63
  }
@@ -14,7 +14,8 @@ export declare class AddonService extends BaseService<AddonEntity> {
14
14
  limit: number;
15
15
  }>;
16
16
  add(param: any): Promise<{
17
- id: any;
17
+ [key: string]: any;
18
+ id: number;
18
19
  }>;
19
20
  /**
20
21
  * 修改
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@certd/lib-server",
3
- "version": "1.41.4",
3
+ "version": "1.42.0",
4
4
  "description": "midway with flyway, sql upgrade way ",
5
5
  "private": false,
6
6
  "type": "module",
@@ -15,11 +15,11 @@
15
15
  "test:unit": "cross-env NODE_ENV=unittest mocha --no-config --node-option no-warnings --node-option loader=ts-node/esm \"src/**/*.test.ts\"",
16
16
  "test1": "midway-bin test --ts -V -f test/blank.test.ts -t 'hash-check'",
17
17
  "cov": "midway-bin cov --ts",
18
- "lint": "mwts check",
19
- "lint:fix": "mwts fix",
20
18
  "prepublish": "npm run build",
21
19
  "pub": "npm publish",
22
- "compile": "tsc --skipLibCheck --watch"
20
+ "compile": "tsc --skipLibCheck --watch",
21
+ "format": "prettier --write src",
22
+ "lint": "eslint --fix"
23
23
  },
24
24
  "keywords": [],
25
25
  "author": "greper",
@@ -29,11 +29,11 @@
29
29
  ],
30
30
  "license": "AGPL",
31
31
  "dependencies": {
32
- "@certd/acme-client": "^1.41.4",
33
- "@certd/basic": "^1.41.4",
34
- "@certd/pipeline": "^1.41.4",
35
- "@certd/plugin-lib": "^1.41.4",
36
- "@certd/plus-core": "^1.41.4",
32
+ "@certd/acme-client": "^1.42.0",
33
+ "@certd/basic": "^1.42.0",
34
+ "@certd/pipeline": "^1.42.0",
35
+ "@certd/plugin-lib": "^1.42.0",
36
+ "@certd/plus-core": "^1.42.0",
37
37
  "@midwayjs/cache": "3.14.0",
38
38
  "@midwayjs/core": "3.20.11",
39
39
  "@midwayjs/i18n": "3.20.13",
@@ -46,28 +46,28 @@
46
46
  "better-sqlite3": "^11.1.2",
47
47
  "dayjs": "^1.11.7",
48
48
  "lodash-es": "^4.17.21",
49
- "mwts": "^1.3.0",
50
- "mwtsc": "^1.4.0",
51
49
  "typeorm": "^0.3.20"
52
50
  },
53
51
  "devDependencies": {
54
- "@types/chai": "^4.3.3",
55
- "@types/mocha": "^10.0.1",
52
+ "@types/chai": "^4.3.12",
53
+ "@types/mocha": "^10.0.6",
56
54
  "@types/node": "^18",
57
55
  "@typescript-eslint/eslint-plugin": "^8.26.1",
58
56
  "@typescript-eslint/parser": "^8.26.1",
59
57
  "cross-env": "^7.0.3",
60
- "eslint": "^8.24.0",
61
- "eslint-config-prettier": "^8.5.0",
62
- "eslint-plugin-prettier": "^4.2.1",
58
+ "eslint": "^8.57.0",
59
+ "eslint-config-prettier": "^9.1.0",
60
+ "eslint-plugin-prettier": "^5.1.3",
63
61
  "esmock": "^2.7.5",
64
- "mocha": "^10.2.0",
65
- "prettier": "^2.8.8",
62
+ "mocha": "^10.6.0",
63
+ "mwts": "^1.3.0",
64
+ "mwtsc": "^1.4.0",
65
+ "prettier": "3.3.3",
66
66
  "rimraf": "^5.0.5",
67
67
  "ts-node": "^10.9.2",
68
68
  "tslib": "^2.8.1",
69
- "typeorm": "^0.3.11",
69
+ "typeorm": "^0.3.20",
70
70
  "typescript": "^5.4.2"
71
71
  },
72
- "gitHead": "bc731e4fb119787930e816a7d57c808b1b5cd66a"
72
+ "gitHead": "b46948c0ba67069ebcd2bb71b21b6c289d99f1b8"
73
73
  }