@mojaloop/central-services-shared 18.8.0-snapshot.0 → 18.9.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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ## [18.9.0](https://github.com/mojaloop/central-services-shared/compare/v18.8.0...v18.9.0) (2024-09-18)
6
+
7
+
8
+ ### Features
9
+
10
+ * ulid generator ([#401](https://github.com/mojaloop/central-services-shared/issues/401)) ([080f55b](https://github.com/mojaloop/central-services-shared/commit/080f55b1f2782b4797f72ebfbe17d77a18094f2a))
11
+
12
+ ## [18.8.0](https://github.com/mojaloop/central-services-shared/compare/v18.7.6...v18.8.0) (2024-09-17)
13
+
14
+
15
+ ### Features
16
+
17
+ * **csi/643:** add fx-notify event for patch fxTransfer updates ([#400](https://github.com/mojaloop/central-services-shared/issues/400)) ([8be247a](https://github.com/mojaloop/central-services-shared/commit/8be247a8b3258838fae590ea4572ef5f5237e5bb))
18
+
5
19
  ### [18.7.6](https://github.com/mojaloop/central-services-shared/compare/v18.7.5...v18.7.6) (2024-09-12)
6
20
 
7
21
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mojaloop/central-services-shared",
3
- "version": "18.8.0-snapshot.0",
3
+ "version": "18.9.0",
4
4
  "description": "Shared code for mojaloop central services",
5
5
  "license": "Apache-2.0",
6
6
  "author": "ModusBox",
@@ -71,6 +71,7 @@
71
71
  "rc": "1.2.8",
72
72
  "shins": "2.6.0",
73
73
  "uuid4": "2.0.3",
74
+ "ulidx": "2.4.1",
74
75
  "widdershins": "^4.0.1",
75
76
  "yaml": "2.5.1"
76
77
  },
@@ -80,7 +81,7 @@
80
81
  "audit-ci": "^7.1.0",
81
82
  "base64url": "3.0.1",
82
83
  "chance": "1.1.12",
83
- "npm-check-updates": "17.1.1",
84
+ "npm-check-updates": "17.1.2",
84
85
  "nyc": "17.0.0",
85
86
  "pre-commit": "1.2.2",
86
87
  "proxyquire": "2.1.3",
package/src/util/id.js CHANGED
@@ -24,6 +24,7 @@
24
24
  ******/
25
25
 
26
26
  const crypto = require('crypto')
27
+ const { monotonicFactory, ulid } = require('ulidx')
27
28
 
28
29
  const generators = {
29
30
  // generate UUID compliant with https://datatracker.ietf.org/doc/html/rfc9562
@@ -34,7 +35,9 @@ const generators = {
34
35
  const random = crypto.randomUUID()
35
36
  return `${timestamp.substring(0, 8)}-${timestamp.substring(8, 12)}-7${random.substring(15, 36)}`
36
37
  }
37
- })[version]
38
+ })[version],
39
+ // monotonic parameter ensures ULIDs are generated in order when called at the same or older seed millisecond
40
+ ulid: ({ monotonic = true }) => monotonic ? monotonicFactory() : ulid
38
41
  }
39
42
 
40
43
  module.exports = ({ type = 'uuid', ...config } = {}) => generators[type](config)
@@ -27,6 +27,7 @@ const Test = require('tapes')(require('tape'))
27
27
  const Sinon = require('sinon')
28
28
  const idGenerator = require('../../../src/util/id')
29
29
  const uuidRegex = version => new RegExp(`[a-f0-9]{8}-[a-f0-9]{4}-${version}[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}`)
30
+ const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/
30
31
 
31
32
  Test('Id util', idTest => {
32
33
  let sandbox
@@ -52,6 +53,20 @@ Test('Id util', idTest => {
52
53
  test.match(uuid7(), uuidRegex(7))
53
54
  test.end()
54
55
  })
56
+ generateSha256Test.test('generate ULID monotonic by default', test => {
57
+ const ulid = idGenerator({ type: 'ulid' })
58
+ test.match(ulid(), ulidRegex)
59
+ const idList = Array.from({ length: 100 }, () => ulid())
60
+ test.ok(idList.slice().sort().join('') === idList.join(''), 'ULIDs should be monotonic')
61
+ test.end()
62
+ })
63
+ generateSha256Test.test('generate ULID non-monotonic', test => {
64
+ const ulid = idGenerator({ type: 'ulid', monotonic: false })
65
+ test.match(ulid(), ulidRegex)
66
+ const idList = Array.from({ length: 100 }, () => ulid())
67
+ test.ok(idList.slice().sort().join('') !== idList.join(''), 'ULIDs should not be monotonic')
68
+ test.end()
69
+ })
55
70
  generateSha256Test.test('generate UUID v7 by default', test => {
56
71
  const uuid = idGenerator()
57
72
  test.match(uuid(), uuidRegex(7))