@superhero/eventflow-db 4.0.2 → 4.0.3

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/README.md CHANGED
@@ -481,6 +481,10 @@ npm test
481
481
  ▶ Revoke a persisted certificate
482
482
  ✔ Reading a revoked certificate should reject with an error (3.894204ms)
483
483
  ✔ Revoke a persisted certificate (14.21005ms)
484
+
485
+ ▶ Revoke certificates that past there validity period
486
+ ✔ Reading a revoked certificate should reject with an error (2.925027ms)
487
+ ✔ Revoke certificates that past there validity period (13.092224ms)
484
488
  ✔ Certificate management (44.130336ms)
485
489
  ✔ Persist a hub (339.721847ms)
486
490
 
package/index.js CHANGED
@@ -739,4 +739,20 @@ export default class DB
739
739
  throw error
740
740
  }
741
741
  }
742
+
743
+ async revokeCertificatesPastValidityPeriod()
744
+ {
745
+ try
746
+ {
747
+ const result = await this.gateway.query('certificate/revoke-past-validity')
748
+ return result.affectedRows
749
+ }
750
+ catch(reason)
751
+ {
752
+ const error = new Error('could not revoke certificates past validity period')
753
+ error.code = 'E_EVENTFLOW_DB_CERTIFICATE_REVOKE_PAST_VALIDITY'
754
+ error.cause = reason
755
+ throw error
756
+ }
757
+ }
742
758
  }
package/index.test.js CHANGED
@@ -280,8 +280,8 @@ suite('@superhero/eventflow-db', async () =>
280
280
 
281
281
  await sub.test('Persisting a duplicate certificate should return false', async () =>
282
282
  {
283
- const duplicatePersisted = await db.persistCertificate(crt)
284
- assert.equal(duplicatePersisted, false, 'Duplicate certificate should not be persisted')
283
+ const isPersisted = await db.persistCertificate(crt)
284
+ assert.equal(isPersisted, false, 'Duplicate certificate should not be persisted')
285
285
  })
286
286
 
287
287
  await sub.test('Read a persisted certificate by id', async () =>
@@ -316,6 +316,21 @@ suite('@superhero/eventflow-db', async () =>
316
316
  )
317
317
  })
318
318
  })
319
+
320
+ await sub.test('Revoke certificates that past there validity period', async (sub) =>
321
+ {
322
+ await db.persistCertificate(crt)
323
+ const revoked = await db.revokeCertificatesPastValidityPeriod()
324
+ assert.ok(revoked, 'Certificates should be revoked')
325
+ await sub.test('Reading a revoked certificate should reject with an error', async () =>
326
+ {
327
+ await assert.rejects(
328
+ db.readCertificate(id),
329
+ { code: 'E_EVENTFLOW_DB_CERTIFICATE_NOT_FOUND' },
330
+ 'Revoked certificate should not be readable'
331
+ )
332
+ })
333
+ })
319
334
  })
320
335
  })
321
336
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superhero/eventflow-db",
3
- "version": "4.0.2",
3
+ "version": "4.0.3",
4
4
  "description": "Eventflow db is a set of common database logic in the eventflow ecosystem.",
5
5
  "keywords": [
6
6
  "eventflow"
@@ -0,0 +1,12 @@
1
+ UPDATE certificate AS c
2
+ LEFT JOIN
3
+ (
4
+ SELECT id, COUNT(*) AS new_version
5
+ FROM certificate
6
+ GROUP BY id
7
+ ) sub
8
+ ON c.id = sub.id
9
+ SET c.revoked = UTC_TIMESTAMP(),
10
+ c.version = sub.new_version
11
+ WHERE c.version = 0
12
+ AND c.validity < UTC_TIMESTAMP()