@verii/fineract-client 1.2.0 → 1.2.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verii/fineract-client",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "Package containing the functions that interact with the fineract system",
5
5
  "repository": "https://github.com/LFDT-Verii/core",
6
6
  "main": "index.js",
@@ -11,7 +11,7 @@
11
11
  "dependencies": {
12
12
  "http-errors": "^2.0.1",
13
13
  "lodash": "^4.18.1",
14
- "@verii/common-functions": "1.2.0"
14
+ "@verii/common-functions": "1.2.1"
15
15
  },
16
16
  "devDependencies": {
17
17
  "date-fns": "^4.4.0",
@@ -27,8 +27,8 @@
27
27
  "globals": "17.7.0",
28
28
  "nock": "15.0.0-beta.14",
29
29
  "prettier": "3.9.6",
30
- "@verii/http-client": "1.2.0",
31
- "@verii/test-regexes": "1.2.0"
30
+ "@verii/http-client": "1.2.1",
31
+ "@verii/test-regexes": "1.2.1"
32
32
  },
33
33
  "nx": {
34
34
  "tags": [
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Copyright 2026 Velocity Team
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ // Fineract clients and accounts provisioned before the registrar switched to
18
+ // Mongo organization IDs carry the organization DID as their external ID,
19
+ // with the same "#escrow-account" / "#stakes-account" suffixes.
20
+ const REGISTRAR_ORGANIZATION_PREFIX = 'registrar:org:';
21
+
22
+ const FINERACT_EXTERNAL_ID_MAX_LENGTH = 100;
23
+
24
+ const buildFineractExternalId = (organizationId, relativeId = '') => {
25
+ if (organizationId == null || organizationId === '') {
26
+ throw new Error(
27
+ 'organizationId is required to build a Fineract external ID',
28
+ );
29
+ }
30
+ const externalId = `${REGISTRAR_ORGANIZATION_PREFIX}${organizationId}${relativeId}`;
31
+ if (externalId.length > FINERACT_EXTERNAL_ID_MAX_LENGTH) {
32
+ throw new Error(
33
+ `Fineract external ID exceeds ${FINERACT_EXTERNAL_ID_MAX_LENGTH} characters: ${externalId}`,
34
+ );
35
+ }
36
+ return externalId;
37
+ };
38
+
39
+ module.exports = { FINERACT_EXTERNAL_ID_MAX_LENGTH, buildFineractExternalId };
@@ -16,13 +16,14 @@
16
16
 
17
17
  const { createCreditsAccount } = require('./fetchers');
18
18
  const { ProductIds } = require('./constants');
19
+ const { buildFineractExternalId } = require('./build-fineract-external-id');
19
20
 
20
21
  const initCreateFineractAccount =
21
- (productId, relativeId) => async (clientId, did, context) => {
22
+ (productId, relativeId) => async (clientId, organizationId, context) => {
22
23
  const { tokenAccountId } = await createCreditsAccount(
23
24
  {
24
25
  clientId,
25
- externalId: `${did}${relativeId}`,
26
+ externalId: buildFineractExternalId(organizationId, relativeId),
26
27
  submittedOnDate: new Date(),
27
28
  productId,
28
29
  },
@@ -19,9 +19,10 @@ const {
19
19
  createStakesAccount,
20
20
  createEscrowAccount,
21
21
  } = require('./create-fineract-account');
22
+ const { buildFineractExternalId } = require('./build-fineract-external-id');
22
23
 
23
24
  const createFineractClient = async (
24
- { profile, didDoc },
25
+ { _id: organizationId, profile },
25
26
  isStakingAccountRequired,
26
27
  context,
27
28
  ) => {
@@ -37,7 +38,7 @@ const createFineractClient = async (
37
38
  {
38
39
  fullName: profile.name,
39
40
  mobileNumber: '',
40
- externalId: didDoc.id,
41
+ externalId: buildFineractExternalId(organizationId),
41
42
  activationDate: now,
42
43
  submittedOnDate: now,
43
44
  },
@@ -48,14 +49,14 @@ const createFineractClient = async (
48
49
 
49
50
  const escrowAccountId = await createEscrowAccount(
50
51
  clientId,
51
- didDoc.id,
52
+ organizationId,
52
53
  context,
53
54
  );
54
55
 
55
56
  if (isStakingAccountRequired) {
56
57
  const stakesAccountId = await createStakesAccount(
57
58
  clientId,
58
- didDoc.id,
59
+ organizationId,
59
60
  context,
60
61
  );
61
62