@brightchain/brightchain-api-lib 0.18.2 → 0.21.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.
Files changed (160) hide show
  1. package/package.json +8 -3
  2. package/src/index.d.ts +0 -1
  3. package/src/index.d.ts.map +1 -1
  4. package/src/index.js +0 -1
  5. package/src/index.js.map +1 -1
  6. package/src/lib/application.d.ts +12 -3
  7. package/src/lib/application.d.ts.map +1 -1
  8. package/src/lib/application.js +153 -7
  9. package/src/lib/application.js.map +1 -1
  10. package/src/lib/availability/gossipService.d.ts +59 -1
  11. package/src/lib/availability/gossipService.d.ts.map +1 -1
  12. package/src/lib/availability/gossipService.js +125 -1
  13. package/src/lib/availability/gossipService.js.map +1 -1
  14. package/src/lib/availability/index.d.ts +1 -0
  15. package/src/lib/availability/index.d.ts.map +1 -1
  16. package/src/lib/availability/index.js +1 -0
  17. package/src/lib/availability/index.js.map +1 -1
  18. package/src/lib/availability/quorumGossipHandler.d.ts +126 -0
  19. package/src/lib/availability/quorumGossipHandler.d.ts.map +1 -0
  20. package/src/lib/availability/quorumGossipHandler.js +246 -0
  21. package/src/lib/availability/quorumGossipHandler.js.map +1 -0
  22. package/src/lib/constants.d.ts.map +1 -1
  23. package/src/lib/constants.js +4 -0
  24. package/src/lib/constants.js.map +1 -1
  25. package/src/lib/controllers/api/quorum.d.ts +110 -2
  26. package/src/lib/controllers/api/quorum.d.ts.map +1 -1
  27. package/src/lib/controllers/api/quorum.js +389 -0
  28. package/src/lib/controllers/api/quorum.js.map +1 -1
  29. package/src/lib/controllers/api/user.d.ts +12 -15
  30. package/src/lib/controllers/api/user.d.ts.map +1 -1
  31. package/src/lib/controllers/api/user.js +312 -94
  32. package/src/lib/controllers/api/user.js.map +1 -1
  33. package/src/lib/databaseInit.d.ts +3 -2
  34. package/src/lib/databaseInit.d.ts.map +1 -1
  35. package/src/lib/databaseInit.js +24 -12
  36. package/src/lib/databaseInit.js.map +1 -1
  37. package/src/lib/datastore/index.d.ts +0 -1
  38. package/src/lib/datastore/index.d.ts.map +1 -1
  39. package/src/lib/datastore/index.js +0 -1
  40. package/src/lib/datastore/index.js.map +1 -1
  41. package/src/lib/environment.d.ts +6 -0
  42. package/src/lib/environment.d.ts.map +1 -1
  43. package/src/lib/environment.js +14 -0
  44. package/src/lib/environment.js.map +1 -1
  45. package/src/lib/hydration/energyAccountHydration.d.ts +17 -0
  46. package/src/lib/hydration/energyAccountHydration.d.ts.map +1 -0
  47. package/src/lib/hydration/energyAccountHydration.js +24 -0
  48. package/src/lib/hydration/energyAccountHydration.js.map +1 -0
  49. package/src/lib/hydration/index.d.ts +13 -0
  50. package/src/lib/hydration/index.d.ts.map +1 -0
  51. package/src/lib/hydration/index.js +21 -0
  52. package/src/lib/hydration/index.js.map +1 -0
  53. package/src/lib/hydration/rbacHydration.d.ts +28 -0
  54. package/src/lib/hydration/rbacHydration.d.ts.map +1 -0
  55. package/src/lib/hydration/rbacHydration.js +56 -0
  56. package/src/lib/hydration/rbacHydration.js.map +1 -0
  57. package/src/lib/interfaces/environment.d.ts +7 -1
  58. package/src/lib/interfaces/environment.d.ts.map +1 -1
  59. package/src/lib/interfaces/responses/api-backup-codes-response.d.ts +1 -1
  60. package/src/lib/interfaces/responses/api-code-count-response.d.ts +1 -1
  61. package/src/lib/interfaces/responses/api-password-change-response.d.ts +9 -0
  62. package/src/lib/interfaces/responses/api-password-change-response.d.ts.map +1 -0
  63. package/src/lib/interfaces/responses/api-password-change-response.js +3 -0
  64. package/src/lib/interfaces/responses/api-password-change-response.js.map +1 -0
  65. package/src/lib/interfaces/responses/api-recovery-response.d.ts +9 -0
  66. package/src/lib/interfaces/responses/api-recovery-response.d.ts.map +1 -0
  67. package/src/lib/interfaces/responses/api-recovery-response.js +3 -0
  68. package/src/lib/interfaces/responses/api-recovery-response.js.map +1 -0
  69. package/src/lib/interfaces/responses/index.d.ts +2 -0
  70. package/src/lib/interfaces/responses/index.d.ts.map +1 -1
  71. package/src/lib/interfaces/storage/client-session.d.ts +1 -1
  72. package/src/lib/interfaces/storage/client-session.d.ts.map +1 -1
  73. package/src/lib/interfaces/storage/collection.d.ts +1 -1
  74. package/src/lib/interfaces/storage/collection.d.ts.map +1 -1
  75. package/src/lib/interfaces/storage/database-lifecycle-hooks.d.ts +1 -1
  76. package/src/lib/interfaces/storage/database-lifecycle-hooks.d.ts.map +1 -1
  77. package/src/lib/interfaces/storage/database.d.ts +1 -1
  78. package/src/lib/interfaces/storage/database.d.ts.map +1 -1
  79. package/src/lib/interfaces/storage/document-types.d.ts +1 -1
  80. package/src/lib/interfaces/storage/document-types.d.ts.map +1 -1
  81. package/src/lib/interfaces/storage/index.d.ts +1 -0
  82. package/src/lib/interfaces/storage/index.d.ts.map +1 -1
  83. package/src/lib/interfaces/storage/index.js.map +1 -1
  84. package/src/lib/interfaces/storage/storedDocumentTypes.d.ts +73 -0
  85. package/src/lib/interfaces/storage/storedDocumentTypes.d.ts.map +1 -0
  86. package/src/lib/interfaces/storage/storedDocumentTypes.js +15 -0
  87. package/src/lib/interfaces/storage/storedDocumentTypes.js.map +1 -0
  88. package/src/lib/plugins/brightchain-database-plugin.d.ts +31 -21
  89. package/src/lib/plugins/brightchain-database-plugin.d.ts.map +1 -1
  90. package/src/lib/plugins/brightchain-database-plugin.js +103 -53
  91. package/src/lib/plugins/brightchain-database-plugin.js.map +1 -1
  92. package/src/lib/plugins/configure-brightchain-app.d.ts.map +1 -1
  93. package/src/lib/plugins/configure-brightchain-app.js +5 -0
  94. package/src/lib/plugins/configure-brightchain-app.js.map +1 -1
  95. package/src/lib/services/auth.d.ts +6 -2
  96. package/src/lib/services/auth.d.ts.map +1 -1
  97. package/src/lib/services/auth.js +43 -7
  98. package/src/lib/services/auth.js.map +1 -1
  99. package/src/lib/services/backupCodeService.d.ts +35 -0
  100. package/src/lib/services/backupCodeService.d.ts.map +1 -0
  101. package/src/lib/services/backupCodeService.js +109 -0
  102. package/src/lib/services/backupCodeService.js.map +1 -0
  103. package/src/lib/services/brightchain-authentication-provider.d.ts.map +1 -1
  104. package/src/lib/services/brightchain-authentication-provider.js +28 -9
  105. package/src/lib/services/brightchain-authentication-provider.js.map +1 -1
  106. package/src/lib/services/brightchain-member-init.service.d.ts +39 -20
  107. package/src/lib/services/brightchain-member-init.service.d.ts.map +1 -1
  108. package/src/lib/services/brightchain-member-init.service.js +139 -53
  109. package/src/lib/services/brightchain-member-init.service.js.map +1 -1
  110. package/src/lib/services/cliOperatorPrompt.d.ts +81 -0
  111. package/src/lib/services/cliOperatorPrompt.d.ts.map +1 -0
  112. package/src/lib/services/cliOperatorPrompt.js +177 -0
  113. package/src/lib/services/cliOperatorPrompt.js.map +1 -0
  114. package/src/lib/services/contentAwareBlocksService.d.ts +92 -0
  115. package/src/lib/services/contentAwareBlocksService.d.ts.map +1 -0
  116. package/src/lib/services/contentAwareBlocksService.js +102 -0
  117. package/src/lib/services/contentAwareBlocksService.js.map +1 -0
  118. package/src/lib/services/contentIngestionService.d.ts +68 -0
  119. package/src/lib/services/contentIngestionService.d.ts.map +1 -0
  120. package/src/lib/services/contentIngestionService.js +139 -0
  121. package/src/lib/services/contentIngestionService.js.map +1 -0
  122. package/src/lib/services/identityExpirationScheduler.d.ts +77 -0
  123. package/src/lib/services/identityExpirationScheduler.d.ts.map +1 -0
  124. package/src/lib/services/identityExpirationScheduler.js +157 -0
  125. package/src/lib/services/identityExpirationScheduler.js.map +1 -0
  126. package/src/lib/services/index.d.ts +7 -0
  127. package/src/lib/services/index.d.ts.map +1 -1
  128. package/src/lib/services/index.js +7 -0
  129. package/src/lib/services/index.js.map +1 -1
  130. package/src/lib/services/quorumDatabaseAdapter.d.ts +60 -0
  131. package/src/lib/services/quorumDatabaseAdapter.d.ts.map +1 -0
  132. package/src/lib/services/quorumDatabaseAdapter.js +652 -0
  133. package/src/lib/services/quorumDatabaseAdapter.js.map +1 -0
  134. package/src/lib/services/secureKeyStorage.js +3 -3
  135. package/src/lib/services/secureKeyStorage.js.map +1 -1
  136. package/src/lib/services/sessionAdapter.d.ts +62 -0
  137. package/src/lib/services/sessionAdapter.d.ts.map +1 -0
  138. package/src/lib/services/sessionAdapter.js +105 -0
  139. package/src/lib/services/sessionAdapter.js.map +1 -0
  140. package/src/lib/utils/rehydration.d.ts +31 -0
  141. package/src/lib/utils/rehydration.d.ts.map +1 -0
  142. package/src/lib/utils/rehydration.js +111 -0
  143. package/src/lib/utils/rehydration.js.map +1 -0
  144. package/src/lib/utils/serialization.d.ts +21 -0
  145. package/src/lib/utils/serialization.d.ts.map +1 -0
  146. package/src/lib/utils/serialization.js +41 -0
  147. package/src/lib/utils/serialization.js.map +1 -0
  148. package/src/lib/validation/userValidation.d.ts +17 -0
  149. package/src/lib/validation/userValidation.d.ts.map +1 -1
  150. package/src/lib/validation/userValidation.js +77 -0
  151. package/src/lib/validation/userValidation.js.map +1 -1
  152. package/src/lib/adapters/brightChainDbDocumentStoreAdapter.d.ts +0 -24
  153. package/src/lib/adapters/brightChainDbDocumentStoreAdapter.d.ts.map +0 -1
  154. package/src/lib/adapters/brightChainDbDocumentStoreAdapter.js +0 -53
  155. package/src/lib/adapters/brightChainDbDocumentStoreAdapter.js.map +0 -1
  156. package/src/lib/datastore/document-model-adapter.d.ts +0 -48
  157. package/src/lib/datastore/document-model-adapter.d.ts.map +0 -1
  158. package/src/lib/datastore/document-model-adapter.js +0 -178
  159. package/src/lib/datastore/document-model-adapter.js.map +0 -1
  160. /package/{brightchain-api-lib/README.md → README.md} +0 -0
@@ -1,22 +1,19 @@
1
1
  import { CoreLanguageCode } from '@digitaldefiance/i18n-lib';
2
2
  import { PlatformID } from '@digitaldefiance/node-ecies-lib';
3
- import { ApiErrorResponse, ApiRequestHandler, IApiMessageResponse, TypedHandlers } from '@digitaldefiance/node-express-suite';
3
+ import { ApiErrorResponse, DecoratorBaseController, IApiMessageResponse, IStatusCodeResponse } from '@digitaldefiance/node-express-suite';
4
+ import type { NextFunction, Request, Response } from 'express';
4
5
  import { IBrightChainApplication } from '../../interfaces/application';
5
6
  import { DefaultBackendIdType } from '../../shared-types';
6
- import { BaseController } from '../base';
7
- interface IUserHandlers extends TypedHandlers {
8
- register: ApiRequestHandler<IApiMessageResponse | ApiErrorResponse>;
9
- login: ApiRequestHandler<IApiMessageResponse | ApiErrorResponse>;
10
- profile: ApiRequestHandler<IApiMessageResponse | ApiErrorResponse>;
11
- updateProfile: ApiRequestHandler<IApiMessageResponse | ApiErrorResponse>;
12
- }
13
- export declare class UserController<TID extends PlatformID = DefaultBackendIdType> extends BaseController<TID, IApiMessageResponse | ApiErrorResponse, IUserHandlers, CoreLanguageCode> {
7
+ export declare class UserController<TID extends PlatformID = DefaultBackendIdType> extends DecoratorBaseController<CoreLanguageCode, TID, IBrightChainApplication<TID>> {
14
8
  constructor(application: IBrightChainApplication<TID>);
15
- protected initRouteDefinitions(): void;
16
- private handleRegister;
17
- private handleLogin;
18
- private handleProfile;
19
- private handleUpdateProfile;
9
+ register(req: Request, _res: Response, _next: NextFunction): Promise<IStatusCodeResponse<IApiMessageResponse | ApiErrorResponse>>;
10
+ login(req: Request, _res: Response, _next: NextFunction): Promise<IStatusCodeResponse<IApiMessageResponse | ApiErrorResponse>>;
11
+ getProfile(req: Request, _res: Response, _next: NextFunction): Promise<IStatusCodeResponse<IApiMessageResponse | ApiErrorResponse>>;
12
+ updateProfile(req: Request, _res: Response, _next: NextFunction): Promise<IStatusCodeResponse<IApiMessageResponse | ApiErrorResponse>>;
13
+ changePassword(req: Request, _res: Response, _next: NextFunction): Promise<IStatusCodeResponse<IApiMessageResponse | ApiErrorResponse>>;
14
+ generateBackupCodes(req: Request, _res: Response, _next: NextFunction): Promise<IStatusCodeResponse<IApiMessageResponse | ApiErrorResponse>>;
15
+ getBackupCodeCount(req: Request, _res: Response, _next: NextFunction): Promise<IStatusCodeResponse<IApiMessageResponse | ApiErrorResponse>>;
16
+ recover(req: Request, _res: Response, _next: NextFunction): Promise<IStatusCodeResponse<IApiMessageResponse | ApiErrorResponse>>;
17
+ logout(req: Request, _res: Response, _next: NextFunction): Promise<IStatusCodeResponse<IApiMessageResponse | ApiErrorResponse>>;
20
18
  }
21
- export {};
22
19
  //# sourceMappingURL=user.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../../../../../brightchain-api-lib/src/lib/controllers/api/user.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EAEnB,aAAa,EAEd,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAMvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAK1D,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEzC,UAAU,aAAc,SAAQ,aAAa;IAC3C,QAAQ,EAAE,iBAAiB,CAAC,mBAAmB,GAAG,gBAAgB,CAAC,CAAC;IACpE,KAAK,EAAE,iBAAiB,CAAC,mBAAmB,GAAG,gBAAgB,CAAC,CAAC;IACjE,OAAO,EAAE,iBAAiB,CAAC,mBAAmB,GAAG,gBAAgB,CAAC,CAAC;IACnE,aAAa,EAAE,iBAAiB,CAAC,mBAAmB,GAAG,gBAAgB,CAAC,CAAC;CAC1E;AAWD,qBAAa,cAAc,CACzB,GAAG,SAAS,UAAU,GAAG,oBAAoB,CAC7C,SAAQ,cAAc,CACtB,GAAG,EACH,mBAAmB,GAAG,gBAAgB,EACtC,aAAa,EACb,gBAAgB,CACjB;gBACa,WAAW,EAAE,uBAAuB,CAAC,GAAG,CAAC;IAIrD,SAAS,CAAC,oBAAoB,IAAI,IAAI;YAgCxB,cAAc;YAsDd,WAAW;YAmDX,aAAa;YA8Fb,mBAAmB;CA2GlC"}
1
+ {"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../../../../../brightchain-api-lib/src/lib/controllers/api/user.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,gBAAgB,EAAmB,MAAM,2BAA2B,CAAC;AAC9E,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EACL,gBAAgB,EAEhB,uBAAuB,EAEvB,mBAAmB,EACnB,mBAAmB,EAGpB,MAAM,qCAAqC,CAAC;AAK7C,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAgBvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAiB1D,qBACa,cAAc,CACzB,GAAG,SAAS,UAAU,GAAG,oBAAoB,CAC7C,SAAQ,uBAAuB,CAC/B,gBAAgB,EAChB,GAAG,EACH,uBAAuB,CAAC,GAAG,CAAC,CAC7B;gBACa,WAAW,EAAE,uBAAuB,CAAC,GAAG,CAAC;IAK/C,QAAQ,CACZ,GAAG,EAAE,OAAO,EACZ,IAAI,EAAE,QAAQ,EACd,KAAK,EAAE,YAAY,GAClB,OAAO,CAAC,mBAAmB,CAAC,mBAAmB,GAAG,gBAAgB,CAAC,CAAC;IAwDjE,KAAK,CACT,GAAG,EAAE,OAAO,EACZ,IAAI,EAAE,QAAQ,EACd,KAAK,EAAE,YAAY,GAClB,OAAO,CAAC,mBAAmB,CAAC,mBAAmB,GAAG,gBAAgB,CAAC,CAAC;IAoDjE,UAAU,CACd,GAAG,EAAE,OAAO,EACZ,IAAI,EAAE,QAAQ,EACd,KAAK,EAAE,YAAY,GAClB,OAAO,CAAC,mBAAmB,CAAC,mBAAmB,GAAG,gBAAgB,CAAC,CAAC;IA6FjE,aAAa,CACjB,GAAG,EAAE,OAAO,EACZ,IAAI,EAAE,QAAQ,EACd,KAAK,EAAE,YAAY,GAClB,OAAO,CAAC,mBAAmB,CAAC,mBAAmB,GAAG,gBAAgB,CAAC,CAAC;IA4GjE,cAAc,CAClB,GAAG,EAAE,OAAO,EACZ,IAAI,EAAE,QAAQ,EACd,KAAK,EAAE,YAAY,GAClB,OAAO,CAAC,mBAAmB,CAAC,mBAAmB,GAAG,gBAAgB,CAAC,CAAC;IAiFjE,mBAAmB,CACvB,GAAG,EAAE,OAAO,EACZ,IAAI,EAAE,QAAQ,EACd,KAAK,EAAE,YAAY,GAClB,OAAO,CAAC,mBAAmB,CAAC,mBAAmB,GAAG,gBAAgB,CAAC,CAAC;IAiDjE,kBAAkB,CACtB,GAAG,EAAE,OAAO,EACZ,IAAI,EAAE,QAAQ,EACd,KAAK,EAAE,YAAY,GAClB,OAAO,CAAC,mBAAmB,CAAC,mBAAmB,GAAG,gBAAgB,CAAC,CAAC;IAiDjE,OAAO,CACX,GAAG,EAAE,OAAO,EACZ,IAAI,EAAE,QAAQ,EACd,KAAK,EAAE,YAAY,GAClB,OAAO,CAAC,mBAAmB,CAAC,mBAAmB,GAAG,gBAAgB,CAAC,CAAC;IAsEjE,MAAM,CACV,GAAG,EAAE,OAAO,EACZ,IAAI,EAAE,QAAQ,EACd,KAAK,EAAE,YAAY,GAClB,OAAO,CAAC,mBAAmB,CAAC,mBAAmB,GAAG,gBAAgB,CAAC,CAAC;CA+DxE"}
@@ -1,59 +1,29 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.UserController = void 0;
4
+ const tslib_1 = require("tslib");
4
5
  const brightchain_lib_1 = require("@brightchain/brightchain-lib");
5
6
  const ecies_lib_1 = require("@digitaldefiance/ecies-lib");
7
+ const i18n_lib_1 = require("@digitaldefiance/i18n-lib");
6
8
  const node_express_suite_1 = require("@digitaldefiance/node-express-suite");
9
+ const suite_core_lib_1 = require("@digitaldefiance/suite-core-lib");
7
10
  const userValidation_1 = require("../../validation/userValidation");
8
- const base_1 = require("../base");
9
- class UserController extends base_1.BaseController {
11
+ let UserController = class UserController extends node_express_suite_1.DecoratorBaseController {
10
12
  constructor(application) {
11
13
  super(application);
12
14
  }
13
- initRouteDefinitions() {
14
- this.routeDefinitions = [
15
- (0, node_express_suite_1.routeConfig)('post', '/register', {
16
- handlerKey: 'register',
17
- useAuthentication: false,
18
- useCryptoAuthentication: false,
19
- }),
20
- (0, node_express_suite_1.routeConfig)('post', '/login', {
21
- handlerKey: 'login',
22
- useAuthentication: false,
23
- useCryptoAuthentication: false,
24
- }),
25
- (0, node_express_suite_1.routeConfig)('get', '/profile', {
26
- handlerKey: 'profile',
27
- useAuthentication: true,
28
- useCryptoAuthentication: false,
29
- }),
30
- (0, node_express_suite_1.routeConfig)('put', '/profile', {
31
- handlerKey: 'updateProfile',
32
- useAuthentication: true,
33
- useCryptoAuthentication: false,
34
- }),
35
- ];
36
- this.handlers = {
37
- register: this.handleRegister.bind(this),
38
- login: this.handleLogin.bind(this),
39
- profile: this.handleProfile.bind(this),
40
- updateProfile: this.handleUpdateProfile.bind(this),
41
- };
42
- }
43
- async handleRegister(req) {
44
- // Validate request body before processing
15
+ async register(req, _res, _next) {
45
16
  const validation = (0, userValidation_1.validateRegistration)(req.body);
46
17
  if (!validation.valid) {
47
18
  return {
48
19
  statusCode: 400,
49
20
  response: {
50
- message: 'Validation failed',
21
+ message: (0, suite_core_lib_1.getSuiteCoreTranslation)(suite_core_lib_1.SuiteCoreStringKey.Validation_MissingValidatedData),
51
22
  errors: validation.errors,
52
23
  },
53
24
  };
54
25
  }
55
26
  try {
56
- // Validation already confirmed these fields exist and are valid strings
57
27
  const { username, email, password } = req.body;
58
28
  const authService = this.application.services.get('auth');
59
29
  const result = await authService.register(username, email, new ecies_lib_1.SecureString(password));
@@ -65,35 +35,36 @@ class UserController extends base_1.BaseController {
65
35
  return {
66
36
  statusCode: 201,
67
37
  response: {
68
- message: 'Registration successful',
38
+ message: (0, suite_core_lib_1.getSuiteCoreTranslation)(suite_core_lib_1.SuiteCoreStringKey.Registration_Success),
69
39
  data: authResponse,
70
40
  },
71
41
  };
72
42
  }
73
43
  catch (error) {
44
+ const errorMessage = error instanceof Error
45
+ ? error.message
46
+ : (0, suite_core_lib_1.getSuiteCoreTranslation)(suite_core_lib_1.SuiteCoreStringKey.Common_UnexpectedError);
74
47
  return {
75
48
  statusCode: 400,
76
49
  response: {
77
- message: error instanceof Error ? error.message : 'Registration failed',
78
- error: error instanceof Error ? error.message : 'Registration failed',
50
+ message: errorMessage,
51
+ error: errorMessage,
79
52
  },
80
53
  };
81
54
  }
82
55
  }
83
- async handleLogin(req) {
84
- // Validate request body before processing
56
+ async login(req, _res, _next) {
85
57
  const validation = (0, userValidation_1.validateLogin)(req.body);
86
58
  if (!validation.valid) {
87
59
  return {
88
60
  statusCode: 400,
89
61
  response: {
90
- message: 'Validation failed',
62
+ message: (0, suite_core_lib_1.getSuiteCoreTranslation)(suite_core_lib_1.SuiteCoreStringKey.Validation_MissingValidatedData),
91
63
  errors: validation.errors,
92
64
  },
93
65
  };
94
66
  }
95
67
  try {
96
- // Validation already confirmed these fields exist and are valid strings
97
68
  const { username, password } = req.body;
98
69
  const authService = this.application.services.get('auth');
99
70
  const result = await authService.login({
@@ -108,7 +79,7 @@ class UserController extends base_1.BaseController {
108
79
  return {
109
80
  statusCode: 200,
110
81
  response: {
111
- message: 'Login successful',
82
+ message: (0, suite_core_lib_1.getSuiteCoreTranslation)(suite_core_lib_1.SuiteCoreStringKey.LoggedIn_Success),
112
83
  data: authResponse,
113
84
  },
114
85
  };
@@ -117,46 +88,40 @@ class UserController extends base_1.BaseController {
117
88
  return {
118
89
  statusCode: 401,
119
90
  response: {
120
- message: 'Invalid credentials',
121
- error: 'Invalid credentials',
91
+ message: (0, suite_core_lib_1.getSuiteCoreTranslation)(suite_core_lib_1.SuiteCoreStringKey.Validation_InvalidCredentials),
92
+ error: (0, suite_core_lib_1.getSuiteCoreTranslation)(suite_core_lib_1.SuiteCoreStringKey.Validation_InvalidCredentials),
122
93
  },
123
94
  };
124
95
  }
125
96
  }
126
- async handleProfile(req) {
127
- const user = req
128
- .user;
97
+ async getProfile(req, _res, _next) {
98
+ const user = req.user;
129
99
  if (!user) {
130
- return {
131
- statusCode: 401,
132
- response: {
133
- message: 'Not authenticated',
134
- error: 'Not authenticated',
135
- },
136
- };
100
+ throw new i18n_lib_1.HandleableError(new Error((0, suite_core_lib_1.getSuiteCoreTranslation)(suite_core_lib_1.SuiteCoreStringKey.Common_NoUserOnRequest)), { statusCode: 401 });
137
101
  }
138
102
  try {
139
- // Get energy account for balance and reputation
103
+ // Deserialize the GUID string back to typed ID (round-trips with idToString)
104
+ const sp = brightchain_lib_1.ServiceProvider.getInstance();
105
+ const typedId = sp.idProvider.idFromString(user.id);
106
+ const idRawBytes = sp.idProvider.toBytes(typedId);
107
+ const memberChecksum = sp.checksumService.calculateChecksum(idRawBytes);
140
108
  const energyStore = this.application.services.get('energyStore');
141
- const memberChecksum = brightchain_lib_1.Checksum.fromHex(user.memberId);
142
109
  const energyAccount = await energyStore.getOrCreate(memberChecksum);
143
- // Try to get member email from MemberStore
144
110
  let email = '';
145
111
  const memberStore = this.application.services.get('memberStore');
146
112
  try {
147
113
  if (memberStore) {
148
- const member = await memberStore.getMember(memberChecksum.toUint8Array());
114
+ const member = await memberStore.getMember(typedId);
149
115
  email = member.email.toString();
150
116
  }
151
117
  }
152
118
  catch {
153
119
  // Member lookup failed, continue with empty email
154
120
  }
155
- // Try to get member profile metadata from MemberStore if available
156
121
  let memberProfile;
157
122
  try {
158
123
  if (memberStore) {
159
- const profile = await memberStore.getMemberProfile(memberChecksum.toUint8Array());
124
+ const profile = await memberStore.getMemberProfile(typedId);
160
125
  if (profile.publicProfile) {
161
126
  memberProfile = {
162
127
  status: profile.publicProfile.status,
@@ -169,10 +134,10 @@ class UserController extends base_1.BaseController {
169
134
  }
170
135
  }
171
136
  catch {
172
- // MemberStore profile not available, continue without profile metadata
137
+ // MemberStore profile not available
173
138
  }
174
139
  const userProfile = {
175
- memberId: user.memberId,
140
+ memberId: user.id,
176
141
  username: user.username,
177
142
  email,
178
143
  energyBalance: energyAccount.balance,
@@ -188,7 +153,7 @@ class UserController extends base_1.BaseController {
188
153
  return {
189
154
  statusCode: 200,
190
155
  response: {
191
- message: 'Profile retrieved',
156
+ message: (0, suite_core_lib_1.getSuiteCoreTranslation)(suite_core_lib_1.SuiteCoreStringKey.Settings_RetrievedSuccess),
192
157
  data: userProfile,
193
158
  },
194
159
  };
@@ -197,29 +162,24 @@ class UserController extends base_1.BaseController {
197
162
  return {
198
163
  statusCode: 500,
199
164
  response: {
200
- message: 'Failed to retrieve profile',
201
- error: 'Failed to retrieve profile',
165
+ message: (0, suite_core_lib_1.getSuiteCoreTranslation)(suite_core_lib_1.SuiteCoreStringKey.Common_UnexpectedError),
166
+ error: (0, suite_core_lib_1.getSuiteCoreTranslation)(suite_core_lib_1.SuiteCoreStringKey.Common_UnexpectedError),
202
167
  },
203
168
  };
204
169
  }
205
170
  }
206
- async handleUpdateProfile(req) {
207
- const user = req
208
- .user;
171
+ async updateProfile(req, _res, _next) {
172
+ const user = req.user;
209
173
  if (!user) {
210
- return {
211
- statusCode: 401,
212
- response: {
213
- message: 'Not authenticated',
214
- error: 'Not authenticated',
215
- },
216
- };
174
+ throw new i18n_lib_1.HandleableError(new Error((0, suite_core_lib_1.getSuiteCoreTranslation)(suite_core_lib_1.SuiteCoreStringKey.Common_NoUserOnRequest)), { statusCode: 401 });
217
175
  }
218
176
  try {
219
177
  const updateData = req.body;
220
- const memberChecksum = brightchain_lib_1.Checksum.fromHex(user.memberId);
221
- const memberIdBytes = memberChecksum.toUint8Array();
222
- // Persist settings via MemberStore — let errors propagate to return 500
178
+ // Deserialize the GUID string back to typed ID (round-trips with idToString)
179
+ const sp = brightchain_lib_1.ServiceProvider.getInstance();
180
+ const typedId = sp.idProvider.idFromString(user.id);
181
+ const idRawBytes = sp.idProvider.toBytes(typedId);
182
+ const memberChecksum = sp.checksumService.calculateChecksum(idRawBytes);
223
183
  const memberStore = this.application.services.get('memberStore');
224
184
  if (memberStore && updateData.settings) {
225
185
  const completeSettings = {
@@ -227,32 +187,29 @@ class UserController extends base_1.BaseController {
227
187
  minRedundancy: updateData.settings.minRedundancy ?? 3,
228
188
  preferredRegions: updateData.settings.preferredRegions ?? [],
229
189
  };
230
- await memberStore.updateMember(memberIdBytes, {
231
- id: memberIdBytes,
190
+ await memberStore.updateMember(typedId, {
191
+ id: typedId,
232
192
  privateChanges: {
233
193
  settings: completeSettings,
234
194
  },
235
195
  });
236
196
  }
237
- // Get updated energy account for response
238
197
  const energyStore = this.application.services.get('energyStore');
239
198
  const energyAccount = await energyStore.getOrCreate(memberChecksum);
240
- // Try to get member email from MemberStore
241
199
  let email = '';
242
200
  try {
243
201
  if (memberStore) {
244
- const member = await memberStore.getMember(memberIdBytes);
202
+ const member = await memberStore.getMember(typedId);
245
203
  email = member.email.toString();
246
204
  }
247
205
  }
248
206
  catch {
249
- // Member lookup failed, continue with empty email
207
+ // Member lookup failed
250
208
  }
251
- // Try to get member profile metadata from MemberStore
252
209
  let memberProfile;
253
210
  try {
254
211
  if (memberStore) {
255
- const profile = await memberStore.getMemberProfile(memberIdBytes);
212
+ const profile = await memberStore.getMemberProfile(typedId);
256
213
  if (profile.publicProfile) {
257
214
  memberProfile = {
258
215
  status: profile.publicProfile.status,
@@ -265,10 +222,10 @@ class UserController extends base_1.BaseController {
265
222
  }
266
223
  }
267
224
  catch {
268
- // MemberStore profile not available, continue without profile metadata
225
+ // MemberStore profile not available
269
226
  }
270
227
  const userProfile = {
271
- memberId: user.memberId,
228
+ memberId: user.id,
272
229
  username: user.username,
273
230
  email,
274
231
  energyBalance: energyAccount.balance,
@@ -284,7 +241,7 @@ class UserController extends base_1.BaseController {
284
241
  return {
285
242
  statusCode: 200,
286
243
  response: {
287
- message: 'Profile updated successfully',
244
+ message: (0, suite_core_lib_1.getSuiteCoreTranslation)(suite_core_lib_1.SuiteCoreStringKey.Settings_SaveSuccess),
288
245
  data: userProfile,
289
246
  },
290
247
  };
@@ -293,12 +250,273 @@ class UserController extends base_1.BaseController {
293
250
  return {
294
251
  statusCode: 500,
295
252
  response: {
296
- message: 'Failed to update profile',
297
- error: 'Failed to update profile',
253
+ message: (0, suite_core_lib_1.getSuiteCoreTranslation)(suite_core_lib_1.SuiteCoreStringKey.Common_UnexpectedError),
254
+ error: (0, suite_core_lib_1.getSuiteCoreTranslation)(suite_core_lib_1.SuiteCoreStringKey.Common_UnexpectedError),
255
+ },
256
+ };
257
+ }
258
+ }
259
+ async changePassword(req, _res, _next) {
260
+ const validation = (0, userValidation_1.validatePasswordChange)(req.body);
261
+ if (!validation.valid) {
262
+ return {
263
+ statusCode: 400,
264
+ response: {
265
+ message: (0, suite_core_lib_1.getSuiteCoreTranslation)(suite_core_lib_1.SuiteCoreStringKey.Validation_MissingValidatedData),
266
+ errors: validation.errors,
267
+ },
268
+ };
269
+ }
270
+ const user = req.user;
271
+ if (!user) {
272
+ throw new i18n_lib_1.HandleableError(new Error((0, suite_core_lib_1.getSuiteCoreTranslation)(suite_core_lib_1.SuiteCoreStringKey.Common_NoUserOnRequest)), { statusCode: 401 });
273
+ }
274
+ try {
275
+ const { currentPassword, newPassword } = req.body;
276
+ // Deserialize the GUID string back to typed ID (round-trips with idToString)
277
+ const sp = brightchain_lib_1.ServiceProvider.getInstance();
278
+ const typedId = sp.idProvider.idFromString(user.id);
279
+ const authService = this.application.services.get('auth');
280
+ await authService.changePassword(typedId, currentPassword, newPassword);
281
+ return {
282
+ statusCode: 200,
283
+ response: {
284
+ message: (0, suite_core_lib_1.getSuiteCoreTranslation)(suite_core_lib_1.SuiteCoreStringKey.PasswordChange_Success),
285
+ data: {
286
+ memberId: user.id,
287
+ success: true,
288
+ },
289
+ },
290
+ };
291
+ }
292
+ catch (error) {
293
+ const errorMessage = error instanceof Error
294
+ ? error.message
295
+ : (0, suite_core_lib_1.getSuiteCoreTranslation)(suite_core_lib_1.SuiteCoreStringKey.Error_PasswordChange);
296
+ if (errorMessage === 'Invalid credentials') {
297
+ return {
298
+ statusCode: 401,
299
+ response: {
300
+ message: (0, suite_core_lib_1.getSuiteCoreTranslation)(suite_core_lib_1.SuiteCoreStringKey.Validation_InvalidCredentials),
301
+ error: (0, suite_core_lib_1.getSuiteCoreTranslation)(suite_core_lib_1.SuiteCoreStringKey.Validation_InvalidCredentials),
302
+ },
303
+ };
304
+ }
305
+ return {
306
+ statusCode: 500,
307
+ response: {
308
+ message: (0, suite_core_lib_1.getSuiteCoreTranslation)(suite_core_lib_1.SuiteCoreStringKey.Error_PasswordChange),
309
+ error: errorMessage,
310
+ },
311
+ };
312
+ }
313
+ }
314
+ async generateBackupCodes(req, _res, _next) {
315
+ const user = req.user;
316
+ if (!user) {
317
+ throw new i18n_lib_1.HandleableError(new Error((0, suite_core_lib_1.getSuiteCoreTranslation)(suite_core_lib_1.SuiteCoreStringKey.Common_NoUserOnRequest)), { statusCode: 401 });
318
+ }
319
+ try {
320
+ // Deserialize the GUID string back to typed ID (round-trips with idToString)
321
+ const sp = brightchain_lib_1.ServiceProvider.getInstance();
322
+ const typedId = sp.idProvider.idFromString(user.id);
323
+ const backupCodeService = this.application.services.get('backupCodeService');
324
+ const codes = await backupCodeService.generateCodes(typedId);
325
+ return {
326
+ statusCode: 200,
327
+ response: {
328
+ message: (0, suite_core_lib_1.getSuiteCoreTranslation)(suite_core_lib_1.SuiteCoreStringKey.BackupCodeRecovery_YourNewCodes),
329
+ backupCodes: codes,
330
+ },
331
+ };
332
+ }
333
+ catch (error) {
334
+ return {
335
+ statusCode: 500,
336
+ response: {
337
+ message: (0, suite_core_lib_1.getSuiteCoreTranslation)(suite_core_lib_1.SuiteCoreStringKey.BackupCodes_FailedToGenerate),
338
+ error: error instanceof Error
339
+ ? error.message
340
+ : (0, suite_core_lib_1.getSuiteCoreTranslation)(suite_core_lib_1.SuiteCoreStringKey.BackupCodes_FailedToGenerate),
341
+ },
342
+ };
343
+ }
344
+ }
345
+ async getBackupCodeCount(req, _res, _next) {
346
+ const user = req.user;
347
+ if (!user) {
348
+ throw new i18n_lib_1.HandleableError(new Error((0, suite_core_lib_1.getSuiteCoreTranslation)(suite_core_lib_1.SuiteCoreStringKey.Common_NoUserOnRequest)), { statusCode: 401 });
349
+ }
350
+ try {
351
+ // Deserialize the GUID string back to typed ID (round-trips with idToString)
352
+ const sp = brightchain_lib_1.ServiceProvider.getInstance();
353
+ const typedId = sp.idProvider.idFromString(user.id);
354
+ const backupCodeService = this.application.services.get('backupCodeService');
355
+ const count = await backupCodeService.getCodeCount(typedId);
356
+ return {
357
+ statusCode: 200,
358
+ response: {
359
+ message: (0, suite_core_lib_1.getSuiteCoreTranslation)(suite_core_lib_1.SuiteCoreStringKey.BackupCodes_RetrievedSuccess),
360
+ codeCount: count,
361
+ },
362
+ };
363
+ }
364
+ catch (error) {
365
+ return {
366
+ statusCode: 500,
367
+ response: {
368
+ message: (0, suite_core_lib_1.getSuiteCoreTranslation)(suite_core_lib_1.SuiteCoreStringKey.BackupCodes_FailedToFetch),
369
+ error: error instanceof Error
370
+ ? error.message
371
+ : (0, suite_core_lib_1.getSuiteCoreTranslation)(suite_core_lib_1.SuiteCoreStringKey.BackupCodes_FailedToFetch),
372
+ },
373
+ };
374
+ }
375
+ }
376
+ async recover(req, _res, _next) {
377
+ const validation = (0, userValidation_1.validateRecovery)(req.body);
378
+ if (!validation.valid) {
379
+ return {
380
+ statusCode: 400,
381
+ response: {
382
+ message: (0, suite_core_lib_1.getSuiteCoreTranslation)(suite_core_lib_1.SuiteCoreStringKey.Validation_MissingValidatedData),
383
+ errors: validation.errors,
384
+ },
385
+ };
386
+ }
387
+ try {
388
+ const { email, mnemonic, newPassword } = req.body;
389
+ const authService = this.application.services.get('auth');
390
+ const result = await authService.recoverWithMnemonic(email, new ecies_lib_1.SecureString(mnemonic), newPassword);
391
+ return {
392
+ statusCode: 200,
393
+ response: {
394
+ message: (0, suite_core_lib_1.getSuiteCoreTranslation)(suite_core_lib_1.SuiteCoreStringKey.MnemonicRecovery_Success),
395
+ data: result,
396
+ },
397
+ };
398
+ }
399
+ catch (error) {
400
+ const errorMessage = error instanceof Error
401
+ ? error.message
402
+ : (0, suite_core_lib_1.getSuiteCoreTranslation)(suite_core_lib_1.SuiteCoreStringKey.Common_UnexpectedError);
403
+ if (errorMessage === 'Invalid credentials' ||
404
+ errorMessage === 'Invalid mnemonic') {
405
+ return {
406
+ statusCode: 401,
407
+ response: {
408
+ message: (0, suite_core_lib_1.getSuiteCoreTranslation)(suite_core_lib_1.SuiteCoreStringKey.Validation_InvalidCredentials),
409
+ error: (0, suite_core_lib_1.getSuiteCoreTranslation)(suite_core_lib_1.SuiteCoreStringKey.Validation_InvalidCredentials),
410
+ },
411
+ };
412
+ }
413
+ return {
414
+ statusCode: 500,
415
+ response: {
416
+ message: (0, suite_core_lib_1.getSuiteCoreTranslation)(suite_core_lib_1.SuiteCoreStringKey.Common_UnexpectedError),
417
+ error: errorMessage,
418
+ },
419
+ };
420
+ }
421
+ }
422
+ async logout(req, _res, _next) {
423
+ const user = req.user;
424
+ if (!user) {
425
+ throw new i18n_lib_1.HandleableError(new Error((0, suite_core_lib_1.getSuiteCoreTranslation)(suite_core_lib_1.SuiteCoreStringKey.Common_NoUserOnRequest)), { statusCode: 401 });
426
+ }
427
+ try {
428
+ const authHeader = String(req.headers
429
+ ?.authorization ?? '');
430
+ if (!authHeader.startsWith('Bearer ')) {
431
+ return {
432
+ statusCode: 401,
433
+ response: {
434
+ message: (0, suite_core_lib_1.getSuiteCoreTranslation)(suite_core_lib_1.SuiteCoreStringKey.Validation_TokenMissing),
435
+ error: (0, suite_core_lib_1.getSuiteCoreTranslation)(suite_core_lib_1.SuiteCoreStringKey.Validation_TokenMissing),
436
+ },
437
+ };
438
+ }
439
+ const token = authHeader.slice('Bearer '.length);
440
+ const sessionAdapter = this.application.services.get('sessionAdapter');
441
+ const session = await sessionAdapter.validateToken(token);
442
+ if (session) {
443
+ await sessionAdapter.deleteSession(session.sessionId);
444
+ }
445
+ return {
446
+ statusCode: 200,
447
+ response: {
448
+ message: (0, suite_core_lib_1.getSuiteCoreTranslation)(suite_core_lib_1.SuiteCoreStringKey.Common_Success),
449
+ },
450
+ };
451
+ }
452
+ catch {
453
+ return {
454
+ statusCode: 500,
455
+ response: {
456
+ message: (0, suite_core_lib_1.getSuiteCoreTranslation)(suite_core_lib_1.SuiteCoreStringKey.Common_UnexpectedError),
457
+ error: (0, suite_core_lib_1.getSuiteCoreTranslation)(suite_core_lib_1.SuiteCoreStringKey.Common_UnexpectedError),
298
458
  },
299
459
  };
300
460
  }
301
461
  }
302
- }
462
+ };
303
463
  exports.UserController = UserController;
464
+ tslib_1.__decorate([
465
+ (0, node_express_suite_1.Post)('/register'),
466
+ tslib_1.__metadata("design:type", Function),
467
+ tslib_1.__metadata("design:paramtypes", [Object, Object, Function]),
468
+ tslib_1.__metadata("design:returntype", Promise)
469
+ ], UserController.prototype, "register", null);
470
+ tslib_1.__decorate([
471
+ (0, node_express_suite_1.Post)('/login'),
472
+ tslib_1.__metadata("design:type", Function),
473
+ tslib_1.__metadata("design:paramtypes", [Object, Object, Function]),
474
+ tslib_1.__metadata("design:returntype", Promise)
475
+ ], UserController.prototype, "login", null);
476
+ tslib_1.__decorate([
477
+ (0, node_express_suite_1.Get)('/profile', { auth: true }),
478
+ tslib_1.__metadata("design:type", Function),
479
+ tslib_1.__metadata("design:paramtypes", [Object, Object, Function]),
480
+ tslib_1.__metadata("design:returntype", Promise)
481
+ ], UserController.prototype, "getProfile", null);
482
+ tslib_1.__decorate([
483
+ (0, node_express_suite_1.Put)('/profile', { auth: true }),
484
+ tslib_1.__metadata("design:type", Function),
485
+ tslib_1.__metadata("design:paramtypes", [Object, Object, Function]),
486
+ tslib_1.__metadata("design:returntype", Promise)
487
+ ], UserController.prototype, "updateProfile", null);
488
+ tslib_1.__decorate([
489
+ (0, node_express_suite_1.Post)('/change-password', { auth: true }),
490
+ tslib_1.__metadata("design:type", Function),
491
+ tslib_1.__metadata("design:paramtypes", [Object, Object, Function]),
492
+ tslib_1.__metadata("design:returntype", Promise)
493
+ ], UserController.prototype, "changePassword", null);
494
+ tslib_1.__decorate([
495
+ (0, node_express_suite_1.Post)('/backup-codes', { auth: true }),
496
+ tslib_1.__metadata("design:type", Function),
497
+ tslib_1.__metadata("design:paramtypes", [Object, Object, Function]),
498
+ tslib_1.__metadata("design:returntype", Promise)
499
+ ], UserController.prototype, "generateBackupCodes", null);
500
+ tslib_1.__decorate([
501
+ (0, node_express_suite_1.Get)('/backup-codes', { auth: true }),
502
+ tslib_1.__metadata("design:type", Function),
503
+ tslib_1.__metadata("design:paramtypes", [Object, Object, Function]),
504
+ tslib_1.__metadata("design:returntype", Promise)
505
+ ], UserController.prototype, "getBackupCodeCount", null);
506
+ tslib_1.__decorate([
507
+ (0, node_express_suite_1.Post)('/recover'),
508
+ tslib_1.__metadata("design:type", Function),
509
+ tslib_1.__metadata("design:paramtypes", [Object, Object, Function]),
510
+ tslib_1.__metadata("design:returntype", Promise)
511
+ ], UserController.prototype, "recover", null);
512
+ tslib_1.__decorate([
513
+ (0, node_express_suite_1.Post)('/logout', { auth: true }),
514
+ tslib_1.__metadata("design:type", Function),
515
+ tslib_1.__metadata("design:paramtypes", [Object, Object, Function]),
516
+ tslib_1.__metadata("design:returntype", Promise)
517
+ ], UserController.prototype, "logout", null);
518
+ exports.UserController = UserController = tslib_1.__decorate([
519
+ (0, node_express_suite_1.Controller)(),
520
+ tslib_1.__metadata("design:paramtypes", [Object])
521
+ ], UserController);
304
522
  //# sourceMappingURL=user.js.map