@abtnode/certificate-manager 1.16.8-beta-186fd5aa → 1.16.8-next-d1e52353

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.
@@ -34,7 +34,7 @@ class Manager extends EventEmitter {
34
34
  this.getJobId = (job) => (job ? md5(`${job.domain}-${job.challenge}`) : '');
35
35
  this.queue = createQueue({
36
36
  name: 'create-cert-queue',
37
- dataDir,
37
+ model: states.job,
38
38
  onJob: async (data) => {
39
39
  if (process.env.NODE_ENV === 'test') {
40
40
  logger.info('skip in test environment');
@@ -64,7 +64,7 @@ class Manager extends EventEmitter {
64
64
  async pushToJobQueue(domain) {
65
65
  const jobData = { domain, subscriberEmail: this.maintainerEmail };
66
66
 
67
- const job = await this.queue.getJob(this.getJobId(jobData));
67
+ const job = await this.queue.get(this.getJobId(jobData));
68
68
 
69
69
  if (!job) {
70
70
  this.queue.push(jobData);
@@ -115,10 +115,9 @@ class AcmeWrapper extends EventEmitter {
115
115
  accountKey,
116
116
  });
117
117
 
118
- await states.account.update(
118
+ await states.account.upsert(
119
119
  { directoryUrl: this.directoryUrl },
120
- { directoryUrl: this.directoryUrl, private_key: accountKey, account, maintainer_email: this.maintainerEmail },
121
- { upsert: true }
120
+ { directoryUrl: this.directoryUrl, private_key: accountKey, account, maintainer_email: this.maintainerEmail }
122
121
  );
123
122
 
124
123
  logger.info('account was created', { directoryUrl: this.directoryUrl, maintainerEmail: this.maintainerEmail });
package/libs/http-01.js CHANGED
@@ -18,7 +18,7 @@ const create = () => {
18
18
  const ch = data.challenge;
19
19
  const key = ch.token;
20
20
  logger.info('set key:', { key });
21
- await states.httpChallenge.update({ key }, { key, value: ch.keyAuthorization }, { upsert: true });
21
+ await states.httpChallenge.upsert({ key }, { value: ch.keyAuthorization });
22
22
  logger.info('setted key:', { key });
23
23
 
24
24
  return null;
package/libs/queue.js CHANGED
@@ -1,23 +1,12 @@
1
- const path = require('path');
2
1
  const createQueue = require('@abtnode/queue');
2
+ const QueueStore = require('@abtnode/queue/lib/store/sequelize');
3
3
 
4
- module.exports = ({ name, dataDir, onJob, options = {} }) => {
4
+ module.exports = ({ name, model, onJob, options = {} }) => {
5
5
  const queue = createQueue({
6
- file: path.join(dataDir, `${name}.db`),
6
+ store: new QueueStore(model, name),
7
7
  onJob,
8
8
  options,
9
9
  });
10
10
 
11
- queue.getJob = (id) =>
12
- new Promise((resolve, reject) => {
13
- queue.store.getJob(id, (error, job) => {
14
- if (error) {
15
- return reject(error);
16
- }
17
-
18
- return resolve(job);
19
- });
20
- });
21
-
22
11
  return queue;
23
12
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abtnode/certificate-manager",
3
- "version": "1.16.8-beta-186fd5aa",
3
+ "version": "1.16.8-next-d1e52353",
4
4
  "description": "Manage ABT Node SSL certificates",
5
5
  "author": "polunzh <polunzh@gmail.com>",
6
6
  "homepage": "https://github.com/ArcBlock/blocklet-server#readme",
@@ -32,11 +32,11 @@
32
32
  "url": "https://github.com/ArcBlock/blocklet-server/issues"
33
33
  },
34
34
  "dependencies": {
35
- "@abtnode/cron": "1.16.8-beta-186fd5aa",
36
- "@abtnode/db": "1.16.8-beta-186fd5aa",
37
- "@abtnode/logger": "1.16.8-beta-186fd5aa",
38
- "@abtnode/queue": "1.16.8-beta-186fd5aa",
39
- "@abtnode/util": "1.16.8-beta-186fd5aa",
35
+ "@abtnode/cron": "1.16.8-next-d1e52353",
36
+ "@abtnode/logger": "1.16.8-next-d1e52353",
37
+ "@abtnode/models": "1.16.8-next-d1e52353",
38
+ "@abtnode/queue": "1.16.8-next-d1e52353",
39
+ "@abtnode/util": "1.16.8-next-d1e52353",
40
40
  "@fidm/x509": "^1.2.1",
41
41
  "@greenlock/manager": "^3.1.0",
42
42
  "@root/acme": "^3.1.0",
@@ -50,5 +50,5 @@
50
50
  "moment": "^2.29.4",
51
51
  "punycode": "^2.1.1"
52
52
  },
53
- "gitHead": "3150c3a5c3e041fe7f5a3902418d9d62adee3173"
53
+ "gitHead": "d357376aa3df9ef789befc7f548629deecb04d96"
54
54
  }
package/sdk/manager.js CHANGED
@@ -146,13 +146,13 @@ class Manager extends EventEmitter {
146
146
  data.source = CERT_SOURCE.upload;
147
147
  }
148
148
 
149
- return states.certificate.update({ domain: data.domain }, data, { upsert: true });
149
+ return states.certificate.upsert({ domain: data.domain }, data);
150
150
  }
151
151
 
152
152
  async update(id, data) {
153
153
  await validateUpdate(data);
154
154
 
155
- const existed = await states.certificate.findOne({ _id: id });
155
+ const existed = await states.certificate.findOne({ id });
156
156
  if (!existed) {
157
157
  throw new Error(`The name ${data.name} does not exists`);
158
158
  }
@@ -161,16 +161,16 @@ class Manager extends EventEmitter {
161
161
  throw new Error('Can not update non-upload certificate');
162
162
  }
163
163
 
164
- return states.certificate.update({ _id: id }, { $set: data });
164
+ return states.certificate.update({ id }, { $set: data });
165
165
  }
166
166
 
167
167
  async remove(id) {
168
- const existed = await states.certificate.findOne({ _id: id });
168
+ const existed = await states.certificate.findOne({ id });
169
169
  if (!existed) {
170
170
  throw new Error(`The certificate ${id} does not exists!`);
171
171
  }
172
172
 
173
- return states.certificate.remove({ _id: id });
173
+ return states.certificate.remove({ id });
174
174
  }
175
175
 
176
176
  addWithoutValidations(data) {
@@ -178,7 +178,7 @@ class Manager extends EventEmitter {
178
178
  }
179
179
 
180
180
  updateWithoutValidations(id, data) {
181
- return states.certificate.update({ _id: id }, { $set: data });
181
+ return states.certificate.update({ id }, { $set: data });
182
182
  }
183
183
  }
184
184
 
package/states/account.js CHANGED
@@ -1,9 +1,8 @@
1
- const BaseSate = require('./base');
1
+ const { BaseState } = require('@abtnode/models');
2
2
 
3
- class Account extends BaseSate {
4
- constructor(dataDir) {
5
- super(dataDir, { filename: 'account.db' });
6
- }
7
- }
3
+ /**
4
+ * @extends BaseState<import('@abtnode/models').AccountState>
5
+ */
6
+ class Account extends BaseState {}
8
7
 
9
8
  module.exports = Account;
@@ -1,14 +1,13 @@
1
1
  const get = require('lodash.get');
2
+ const { BaseState } = require('@abtnode/models');
2
3
 
3
4
  const { CERT_STATUS } = require('../libs/constant');
4
- const BaseSate = require('./base');
5
5
  const { getCertInfo } = require('../libs/util');
6
6
 
7
- class Certificate extends BaseSate {
8
- constructor(dataDir) {
9
- super(dataDir, { filename: 'certificate.db' });
10
- }
11
-
7
+ /**
8
+ * @extends BaseState<import('@abtnode/models').CertificateState>
9
+ */
10
+ class Certificate extends BaseState {
12
11
  async updateStatus(domain, status) {
13
12
  if (!Object.values(CERT_STATUS).includes(status)) {
14
13
  throw new Error('invalid domain status');
@@ -25,14 +24,14 @@ class Certificate extends BaseSate {
25
24
  return super.insert(data);
26
25
  }
27
26
 
28
- async update(condition, data, options) {
27
+ async update(condition, data) {
29
28
  if (data.certificate) {
30
29
  data.meta = getCertInfo(data.certificate);
31
30
  } else if (get(data, '$set.certificate')) {
32
31
  data.$set.meta = getCertInfo(get(data, '$set.certificate'));
33
32
  }
34
33
 
35
- return super.update(condition, data, options);
34
+ return super.update(condition, data);
36
35
  }
37
36
  }
38
37
 
@@ -1,9 +1,8 @@
1
- const BaseSate = require('./base');
1
+ const { BaseState } = require('@abtnode/models');
2
2
 
3
- class HttpChallenge extends BaseSate {
4
- constructor(dataDir) {
5
- super(dataDir, { filename: 'http-challenge.db' });
6
- }
7
- }
3
+ /**
4
+ * @extends BaseState<import('@abtnode/models').HttpChallengeState>
5
+ */
6
+ class HttpChallenge extends BaseState {}
8
7
 
9
8
  module.exports = HttpChallenge;
package/states/index.js CHANGED
@@ -1,26 +1,33 @@
1
1
  const path = require('path');
2
- const fs = require('fs');
3
- const stateFactory = require('@abtnode/db/lib/factory');
2
+ const { createSequelize, createStateFactory, getCertificateManagerModels, setupModels } = require('@abtnode/models');
4
3
 
5
4
  const Account = require('./account');
6
5
  const Certificate = require('./certificate');
7
6
  const HttpChallenge = require('./http-challenge');
7
+ const Job = require('./job');
8
+
9
+ const models = getCertificateManagerModels();
10
+
11
+ const getDbFilePath = (filePath) => (process.env.NODE_ENV === 'test' ? `${filePath}:memory:` : filePath);
8
12
 
9
13
  const init = (dataDir) => {
10
- const dbDir = path.join(dataDir, 'db');
11
- if (!fs.existsSync(dbDir)) {
12
- fs.mkdirSync(dbDir, { recursive: true });
13
- }
14
+ const dbPath = getDbFilePath(path.join(dataDir, 'module.db'));
15
+
16
+ const sequelize = createSequelize(dbPath);
17
+ setupModels(models, sequelize);
18
+ console.info(`Init certificate manager states in ${dbPath}`); // eslint-disable-line
14
19
 
15
- const account = new Account(dbDir);
16
- const certificate = new Certificate(dbDir);
17
- const httpChallenge = new HttpChallenge(dbDir);
20
+ const account = new Account(models.Account);
21
+ const certificate = new Certificate(models.Certificate);
22
+ const httpChallenge = new HttpChallenge(models.HttpChallenge);
23
+ const job = new Job(models.Job);
18
24
 
19
25
  return {
20
26
  account,
21
27
  certificate,
22
28
  httpChallenge,
29
+ job,
23
30
  };
24
31
  };
25
32
 
26
- module.exports = stateFactory(init);
33
+ module.exports = createStateFactory(init, models);
package/states/job.js ADDED
@@ -0,0 +1,8 @@
1
+ const { BaseState } = require('@abtnode/models');
2
+
3
+ /**
4
+ * @extends BaseState<import('@abtnode/models').JobState>
5
+ */
6
+ class Job extends BaseState {}
7
+
8
+ module.exports = Job;
package/states/base.js DELETED
@@ -1,15 +0,0 @@
1
- const DB = require('@abtnode/db');
2
-
3
- module.exports = class BaseDB extends DB {
4
- async find(...args) {
5
- const dbEntity = await super.find(...args);
6
-
7
- return DB.renameIdFiledName(dbEntity);
8
- }
9
-
10
- async findOne(...args) {
11
- const dbEntity = await super.findOne(...args);
12
-
13
- return DB.renameIdFiledName(dbEntity);
14
- }
15
- };