@flusys/nestjs-auth 8.1.5 → 9.0.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/fesm/24.js CHANGED
@@ -3913,9 +3913,7 @@ class UserService extends _flusys_nestjs_shared_classes__rspack_import_1.ApiServ
3913
3913
  if (key === 'actionCode' || key === 'isActive') {
3914
3914
  continue; // real continue
3915
3915
  }
3916
- query.andWhere(`${this.entityName}.${key} = :value`, {
3917
- value
3918
- });
3916
+ this.applyEqualsFilter(query, key, value);
3919
3917
  }
3920
3918
  return {
3921
3919
  query,
package/fesm/index.js CHANGED
@@ -699,6 +699,7 @@ __webpack_require__.d(__webpack_exports__, {
699
699
  $h: () => (/* reexport */ dtos/* .ChangePasswordDto */.$h),
700
700
  t7: () => (/* reexport */ interceptors/* .ClearToken */.t),
701
701
  CC: () => (/* reexport */ entities/* .Company */.CC),
702
+ ht: () => (/* reexport */ services/* .CompanyAccessResolverAdapter */.ht),
702
703
  At: () => (/* reexport */ entities/* .CompanyBranch */.At),
703
704
  ET: () => (/* reexport */ dtos/* .CompanyBranchResponseDto */.ET),
704
705
  wD: () => (/* reexport */ controllers/* .CompanyController */.wD),
@@ -814,8 +815,8 @@ var social_provider_registry = __webpack_require__(6928);
814
815
  ;// CONCATENATED MODULE: ./projects/nestjs-auth/src/providers/index.ts
815
816
 
816
817
 
817
- // EXTERNAL MODULE: ./projects/nestjs-auth/src/services/index.ts
818
- var services = __webpack_require__(8811);
818
+ // EXTERNAL MODULE: ./projects/nestjs-auth/src/services/index.ts + 1 modules
819
+ var services = __webpack_require__(2991);
819
820
  // EXTERNAL MODULE: ./projects/nestjs-auth/src/strategies/jwt.strategy.ts + 1 modules
820
821
  var jwt_strategy = __webpack_require__(5389);
821
822
  ;// CONCATENATED MODULE: ./projects/nestjs-auth/src/index.ts
@@ -872,6 +873,8 @@ __webpack_require__.d(__webpack_exports__, {
872
873
  r: () => (/* reexport */ AuthModule)
873
874
  });
874
875
 
876
+ // EXTERNAL MODULE: external "@flusys/nestjs-shared/interfaces"
877
+ var interfaces_ = __webpack_require__(5103);
875
878
  // EXTERNAL MODULE: external "@flusys/nestjs-shared/modules"
876
879
  var modules_ = __webpack_require__(1236);
877
880
  // EXTERNAL MODULE: external "@nestjs/common"
@@ -892,8 +895,8 @@ var entities = __webpack_require__(5180);
892
895
  var clear_token_interceptor = __webpack_require__(5207);
893
896
  // EXTERNAL MODULE: ./projects/nestjs-auth/src/interceptors/set-token.interceptor.ts + 1 modules
894
897
  var set_token_interceptor = __webpack_require__(8359);
895
- // EXTERNAL MODULE: ./projects/nestjs-auth/src/services/index.ts
896
- var services = __webpack_require__(8811);
898
+ // EXTERNAL MODULE: ./projects/nestjs-auth/src/services/index.ts + 1 modules
899
+ var services = __webpack_require__(2991);
897
900
  // EXTERNAL MODULE: ./projects/nestjs-auth/src/services/auth-config.service.ts + 1 modules
898
901
  var auth_config_service = __webpack_require__(6514);
899
902
  // EXTERNAL MODULE: ./projects/nestjs-auth/src/services/auth-datasource.provider.ts
@@ -928,6 +931,7 @@ function _ts_decorate(decorators, target, key, desc) {
928
931
 
929
932
 
930
933
 
934
+
931
935
  class AuthModule {
932
936
  static forRoot(options) {
933
937
  const optionsProvider = {
@@ -1014,7 +1018,10 @@ class AuthModule {
1014
1018
  providers.push(services/* .AuthEmailService */.Gw);
1015
1019
  }
1016
1020
  if (flags.enableCompanyFeature) {
1017
- providers.push(services/* .CompanySelectionSessionService */.vB, services/* .CompanyService */.Bl, services/* .BranchService */.O_, services/* .UserPermissionService */.OE);
1021
+ providers.push(services/* .CompanySelectionSessionService */.vB, services/* .CompanyService */.Bl, services/* .BranchService */.O_, services/* .UserPermissionService */.OE, {
1022
+ provide: interfaces_.COMPANY_ACCESS_RESOLVER,
1023
+ useClass: services/* .CompanyAccessResolverAdapter */.ht
1024
+ });
1018
1025
  }
1019
1026
  return providers;
1020
1027
  }
@@ -1035,7 +1042,7 @@ class AuthModule {
1035
1042
  exports.push(services/* .AuthEmailService */.Gw);
1036
1043
  }
1037
1044
  if (flags.enableCompanyFeature) {
1038
- exports.push(services/* .CompanySelectionSessionService */.vB, services/* .CompanyService */.Bl, services/* .BranchService */.O_, services/* .UserPermissionService */.OE);
1045
+ exports.push(services/* .CompanySelectionSessionService */.vB, services/* .CompanyService */.Bl, services/* .BranchService */.O_, services/* .UserPermissionService */.OE, interfaces_.COMPANY_ACCESS_RESOLVER);
1039
1046
  }
1040
1047
  return exports;
1041
1048
  }
@@ -1112,18 +1119,131 @@ AuthModule = _ts_decorate([
1112
1119
 
1113
1120
 
1114
1121
  },
1115
- 8811(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
1116
- /* import */ var _authentication_service_js__rspack_import_0 = __webpack_require__(4722);
1117
- /* import */ var _auth_email_service_js__rspack_import_1 = __webpack_require__(3221);
1118
- /* import */ var _company_selection_session_service_js__rspack_import_2 = __webpack_require__(5811);
1119
- /* import */ var _social_auth_service_js__rspack_import_3 = __webpack_require__(2786);
1120
- /* import */ var _social_auth_config_service_js__rspack_import_4 = __webpack_require__(8275);
1121
- /* import */ var _user_service_js__rspack_import_5 = __webpack_require__(7229);
1122
- /* import */ var _company_service_js__rspack_import_6 = __webpack_require__(9201);
1123
- /* import */ var _branch_service_js__rspack_import_7 = __webpack_require__(5402);
1124
- /* import */ var _user_permission_service_js__rspack_import_8 = __webpack_require__(5291);
1125
- /* import */ var _auth_config_service_js__rspack_import_9 = __webpack_require__(6514);
1126
- /* import */ var _auth_datasource_provider_js__rspack_import_10 = __webpack_require__(2732);
1122
+ 2991(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
1123
+
1124
+ // EXPORTS
1125
+ __webpack_require__.d(__webpack_exports__, {
1126
+ WE: () => (/* reexport */ auth_config_service/* .AuthConfigService */.W),
1127
+ vS: () => (/* reexport */ auth_datasource_provider/* .AuthDataSourceProvider */.v),
1128
+ Gw: () => (/* reexport */ auth_email_service/* .AuthEmailService */.G),
1129
+ kX: () => (/* reexport */ authentication_service/* .AuthenticationService */.k),
1130
+ O_: () => (/* reexport */ branch_service/* .BranchService */.O),
1131
+ ht: () => (/* reexport */ CompanyAccessResolverAdapter),
1132
+ vB: () => (/* reexport */ company_selection_session_service/* .CompanySelectionSessionService */.v),
1133
+ Bl: () => (/* reexport */ company_service/* .CompanyService */.B),
1134
+ t_: () => (/* reexport */ social_auth_config_service/* .SocialAuthConfigService */.t),
1135
+ Jn: () => (/* reexport */ social_auth_service/* .SocialAuthService */.J),
1136
+ OE: () => (/* reexport */ user_permission_service/* .UserPermissionService */.O),
1137
+ DL: () => (/* reexport */ user_service/* .UserService */.D)
1138
+ });
1139
+
1140
+ // EXTERNAL MODULE: ./projects/nestjs-auth/src/services/authentication.service.ts + 1 modules
1141
+ var authentication_service = __webpack_require__(4722);
1142
+ // EXTERNAL MODULE: ./projects/nestjs-auth/src/services/auth-email.service.ts
1143
+ var auth_email_service = __webpack_require__(3221);
1144
+ // EXTERNAL MODULE: ./projects/nestjs-auth/src/services/company-selection-session.service.ts
1145
+ var company_selection_session_service = __webpack_require__(5811);
1146
+ // EXTERNAL MODULE: ./projects/nestjs-auth/src/services/social-auth.service.ts
1147
+ var social_auth_service = __webpack_require__(2786);
1148
+ // EXTERNAL MODULE: ./projects/nestjs-auth/src/services/social-auth-config.service.ts
1149
+ var social_auth_config_service = __webpack_require__(8275);
1150
+ // EXTERNAL MODULE: ./projects/nestjs-auth/src/services/user.service.ts
1151
+ var user_service = __webpack_require__(7229);
1152
+ // EXTERNAL MODULE: ./projects/nestjs-auth/src/services/company.service.ts
1153
+ var company_service = __webpack_require__(9201);
1154
+ // EXTERNAL MODULE: ./projects/nestjs-auth/src/services/branch.service.ts
1155
+ var branch_service = __webpack_require__(5402);
1156
+ // EXTERNAL MODULE: ./projects/nestjs-auth/src/services/user-permission.service.ts
1157
+ var user_permission_service = __webpack_require__(5291);
1158
+ // EXTERNAL MODULE: ./projects/nestjs-auth/src/services/auth-config.service.ts + 1 modules
1159
+ var auth_config_service = __webpack_require__(6514);
1160
+ // EXTERNAL MODULE: ./projects/nestjs-auth/src/services/auth-datasource.provider.ts
1161
+ var auth_datasource_provider = __webpack_require__(2732);
1162
+ // EXTERNAL MODULE: external "@nestjs/common"
1163
+ var common_ = __webpack_require__(6157);
1164
+ // EXTERNAL MODULE: external "@nestjs/core"
1165
+ var core_ = __webpack_require__(3075);
1166
+ ;// CONCATENATED MODULE: ./projects/nestjs-auth/src/services/company-access-resolver.adapter.ts
1167
+ function _ts_decorate(decorators, target, key, desc) {
1168
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1169
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1170
+ r = Reflect.decorate(decorators, target, key, desc);
1171
+ } else {
1172
+ for(var i = decorators.length - 1; i >= 0; i--){
1173
+ if (d = decorators[i]) {
1174
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1175
+ }
1176
+ }
1177
+ }
1178
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1179
+ }
1180
+ function _ts_metadata(metadataKey, metadataValue) {
1181
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1182
+ return Reflect.metadata(metadataKey, metadataValue);
1183
+ }
1184
+ }
1185
+ function _ts_param(paramIndex, decorator) {
1186
+ return function(target, key) {
1187
+ decorator(target, key, paramIndex);
1188
+ };
1189
+ }
1190
+
1191
+
1192
+
1193
+ const byName = (a, b)=>a.name.localeCompare(b.name);
1194
+ /** Users of grants that still count: the grant is active and its user is active and not deleted. */ const activeUserIds = (grants)=>grants.filter((grant)=>grant.isActive && grant.user?.isActive && !grant.user.deletedAt).map((grant)=>grant.userId);
1195
+ class CompanyAccessResolverAdapter {
1196
+ moduleRef;
1197
+ constructor(moduleRef){
1198
+ this.moduleRef = moduleRef;
1199
+ }
1200
+ async getUserAccess(userId) {
1201
+ const permissions = await this.moduleRef.resolve(user_permission_service/* .UserPermissionService */.O, core_.ContextIdFactory.create(), {
1202
+ strict: false
1203
+ });
1204
+ const [companyGrants, branchGrants] = await Promise.all([
1205
+ permissions.findUserCompanies(userId),
1206
+ permissions.findUserBranches(userId)
1207
+ ]);
1208
+ const companies = companyGrants.map((grant)=>grant.company).filter((company)=>!!company?.isActive).sort(byName);
1209
+ const companyIds = new Set(companies.map((company)=>company.id));
1210
+ const branches = branchGrants.map((grant)=>grant.branch).filter((branch)=>!!branch?.isActive && companyIds.has(branch.companyId)).sort((a, b)=>(a.serial ?? 0) - (b.serial ?? 0) || byName(a, b));
1211
+ return {
1212
+ companies: companies.map(({ id, name })=>({
1213
+ id,
1214
+ name
1215
+ })),
1216
+ branches: branches.map(({ id, companyId, name })=>({
1217
+ id,
1218
+ companyId,
1219
+ name
1220
+ }))
1221
+ };
1222
+ }
1223
+ async getCompanyMembers(companyId, branchIds = []) {
1224
+ const permissions = await this.moduleRef.resolve(user_permission_service/* .UserPermissionService */.O, core_.ContextIdFactory.create(), {
1225
+ strict: false
1226
+ });
1227
+ const members = activeUserIds(await permissions.findUsersForCompany(companyId));
1228
+ if (!branchIds.length) return [
1229
+ ...new Set(members)
1230
+ ];
1231
+ const inBranches = new Set(activeUserIds((await Promise.all(branchIds.map((branchId)=>permissions.findUsersForBranch(branchId)))).flat()));
1232
+ return [
1233
+ ...new Set(members.filter((userId)=>inBranches.has(userId)))
1234
+ ];
1235
+ }
1236
+ }
1237
+ CompanyAccessResolverAdapter = _ts_decorate([
1238
+ (0,common_.Injectable)(),
1239
+ _ts_param(0, (0,common_.Inject)(core_.ModuleRef)),
1240
+ _ts_metadata("design:type", Function),
1241
+ _ts_metadata("design:paramtypes", [
1242
+ typeof core_.ModuleRef === "undefined" ? Object : core_.ModuleRef
1243
+ ])
1244
+ ], CompanyAccessResolverAdapter);
1245
+
1246
+ ;// CONCATENATED MODULE: ./projects/nestjs-auth/src/services/index.ts
1127
1247
 
1128
1248
 
1129
1249
 
@@ -1136,19 +1256,6 @@ AuthModule = _ts_decorate([
1136
1256
 
1137
1257
 
1138
1258
 
1139
- __webpack_require__.d(__webpack_exports__, {
1140
- Bl: () => (/* reexport safe */ _company_service_js__rspack_import_6.B),
1141
- DL: () => (/* reexport safe */ _user_service_js__rspack_import_5.D),
1142
- Gw: () => (/* reexport safe */ _auth_email_service_js__rspack_import_1.G),
1143
- Jn: () => (/* reexport safe */ _social_auth_service_js__rspack_import_3.J),
1144
- OE: () => (/* reexport safe */ _user_permission_service_js__rspack_import_8.O),
1145
- O_: () => (/* reexport safe */ _branch_service_js__rspack_import_7.O),
1146
- WE: () => (/* reexport safe */ _auth_config_service_js__rspack_import_9.W),
1147
- kX: () => (/* reexport safe */ _authentication_service_js__rspack_import_0.k),
1148
- t_: () => (/* reexport safe */ _social_auth_config_service_js__rspack_import_4.t),
1149
- vB: () => (/* reexport safe */ _company_selection_session_service_js__rspack_import_2.v),
1150
- vS: () => (/* reexport safe */ _auth_datasource_provider_js__rspack_import_10.v)
1151
- });
1152
1259
 
1153
1260
 
1154
1261
  },
@@ -1367,6 +1474,7 @@ var __webpack_exports__COMPANY_MESSAGES = __webpack_exports__.hg;
1367
1474
  var __webpack_exports__ChangePasswordDto = __webpack_exports__.$h;
1368
1475
  var __webpack_exports__ClearToken = __webpack_exports__.t7;
1369
1476
  var __webpack_exports__Company = __webpack_exports__.CC;
1477
+ var __webpack_exports__CompanyAccessResolverAdapter = __webpack_exports__.ht;
1370
1478
  var __webpack_exports__CompanyBranch = __webpack_exports__.At;
1371
1479
  var __webpack_exports__CompanyBranchResponseDto = __webpack_exports__.ET;
1372
1480
  var __webpack_exports__CompanyController = __webpack_exports__.wD;
@@ -1455,4 +1563,4 @@ var __webpack_exports__parseExpiryToMs = __webpack_exports__.om;
1455
1563
  var __webpack_exports__toBranchInfo = __webpack_exports__.QH;
1456
1564
  var __webpack_exports__toCompanyInfo = __webpack_exports__.$C;
1457
1565
  var __webpack_exports__toUserInfo = __webpack_exports__.FV;
1458
- export { __webpack_exports__AUTH_EMAIL_PROVIDER as AUTH_EMAIL_PROVIDER, __webpack_exports__AUTH_EVENT_ACTIONS as AUTH_EVENT_ACTIONS, __webpack_exports__AUTH_EVENT_ENTITIES as AUTH_EVENT_ENTITIES, __webpack_exports__AUTH_EVENT_MODULE as AUTH_EVENT_MODULE, __webpack_exports__AUTH_MESSAGES as AUTH_MESSAGES, __webpack_exports__AUTH_MODULE_OPTIONS as AUTH_MODULE_OPTIONS, __webpack_exports__AppUser as AppUser, __webpack_exports__AssignUserBranchDto as AssignUserBranchDto, __webpack_exports__AssignUserCompanyDto as AssignUserCompanyDto, __webpack_exports__AuthConfigService as AuthConfigService, __webpack_exports__AuthDataSourceProvider as AuthDataSourceProvider, __webpack_exports__AuthEmailService as AuthEmailService, __webpack_exports__AuthModule as AuthModule, __webpack_exports__AuthenticationController as AuthenticationController, __webpack_exports__AuthenticationService as AuthenticationService, __webpack_exports__BCRYPT_SALT_ROUNDS as BCRYPT_SALT_ROUNDS, __webpack_exports__BRANCH_MESSAGES as BRANCH_MESSAGES, __webpack_exports__BranchController as BranchController, __webpack_exports__BranchInfoDto as BranchInfoDto, __webpack_exports__BranchPermittedUserDto as BranchPermittedUserDto, __webpack_exports__BranchPermittedUsersResponseDto as BranchPermittedUsersResponseDto, __webpack_exports__BranchSelectionInfoDto as BranchSelectionInfoDto, __webpack_exports__BranchService as BranchService, __webpack_exports__COMPANY_MESSAGES as COMPANY_MESSAGES, __webpack_exports__ChangePasswordDto as ChangePasswordDto, __webpack_exports__ClearToken as ClearToken, __webpack_exports__Company as Company, __webpack_exports__CompanyBranch as CompanyBranch, __webpack_exports__CompanyBranchResponseDto as CompanyBranchResponseDto, __webpack_exports__CompanyController as CompanyController, __webpack_exports__CompanyInfoDto as CompanyInfoDto, __webpack_exports__CompanyPermittedUserDto as CompanyPermittedUserDto, __webpack_exports__CompanyPermittedUsersResponseDto as CompanyPermittedUsersResponseDto, __webpack_exports__CompanyResponseDto as CompanyResponseDto, __webpack_exports__CompanySelectionController as CompanySelectionController, __webpack_exports__CompanySelectionResponseDto as CompanySelectionResponseDto, __webpack_exports__CompanySelectionSessionService as CompanySelectionSessionService, __webpack_exports__CompanyService as CompanyService, __webpack_exports__CompanyWithBranchesDto as CompanyWithBranchesDto, __webpack_exports__CreateCompanyBranchDto as CreateCompanyBranchDto, __webpack_exports__CreateCompanyDto as CreateCompanyDto, __webpack_exports__CreateSocialAuthConfigDto as CreateSocialAuthConfigDto, __webpack_exports__CreateUserDto as CreateUserDto, __webpack_exports__DEFAULT_COOKIE_NAME as DEFAULT_COOKIE_NAME, __webpack_exports__EMAIL_VERIFICATION_MESSAGES as EMAIL_VERIFICATION_MESSAGES, __webpack_exports__EmailVerificationController as EmailVerificationController, __webpack_exports__ForgotPasswordDto as ForgotPasswordDto, __webpack_exports__GetBranchUsersDto as GetBranchUsersDto, __webpack_exports__GetCompanyUsersDto as GetCompanyUsersDto, __webpack_exports__JwtStrategy as JwtStrategy, __webpack_exports__LoginDto as LoginDto, __webpack_exports__LoginResponseDto as LoginResponseDto, __webpack_exports__LoginResponseRequiresEmailVerificationDto as LoginResponseRequiresEmailVerificationDto, __webpack_exports__MAX_COOKIE_BYTES as MAX_COOKIE_BYTES, __webpack_exports__MeResponseDto as MeResponseDto, __webpack_exports__PendingRegistration as PendingRegistration, __webpack_exports__PermissionItemDto as PermissionItemDto, __webpack_exports__PermissionType as PermissionType, __webpack_exports__RefreshTokenDto as RefreshTokenDto, __webpack_exports__RegistrationDto as RegistrationDto, __webpack_exports__RegistrationResponseDto as RegistrationResponseDto, __webpack_exports__ResendVerificationDto as ResendVerificationDto, __webpack_exports__ResetPasswordDto as ResetPasswordDto, __webpack_exports__SESSION_CACHE_PREFIX as SESSION_CACHE_PREFIX, __webpack_exports__SOCIAL_AUTH_CONFIG_MESSAGES as SOCIAL_AUTH_CONFIG_MESSAGES, __webpack_exports__SOCIAL_AUTH_MESSAGES as SOCIAL_AUTH_MESSAGES, __webpack_exports__SOCIAL_STATE_PREFIX as SOCIAL_STATE_PREFIX, __webpack_exports__SOCIAL_STATE_TTL_MS as SOCIAL_STATE_TTL_MS, __webpack_exports__SelectDto as SelectDto, __webpack_exports__SetToken as SetToken, __webpack_exports__SocialAuthConfig as SocialAuthConfig, __webpack_exports__SocialAuthConfigController as SocialAuthConfigController, __webpack_exports__SocialAuthConfigResponseDto as SocialAuthConfigResponseDto, __webpack_exports__SocialAuthConfigService as SocialAuthConfigService, __webpack_exports__SocialAuthController as SocialAuthController, __webpack_exports__SocialAuthService as SocialAuthService, __webpack_exports__SocialAuthorizeDto as SocialAuthorizeDto, __webpack_exports__SocialAuthorizeResponseDto as SocialAuthorizeResponseDto, __webpack_exports__SocialCallbackDto as SocialCallbackDto, __webpack_exports__SocialProviderInfoDto as SocialProviderInfoDto, __webpack_exports__SocialProviderTypeEnum as SocialProviderTypeEnum, __webpack_exports__SocialProvidersDto as SocialProvidersDto, __webpack_exports__SwitchCompanyDto as SwitchCompanyDto, __webpack_exports__TOKEN_REVOKED_PREFIX as TOKEN_REVOKED_PREFIX, __webpack_exports__TokenType as TokenType, __webpack_exports__USER_ENRICHER as USER_ENRICHER, __webpack_exports__USER_MESSAGES as USER_MESSAGES, __webpack_exports__USER_PERMISSION_MESSAGES as USER_PERMISSION_MESSAGES, __webpack_exports__UpdateCompanyBranchDto as UpdateCompanyBranchDto, __webpack_exports__UpdateCompanyDto as UpdateCompanyDto, __webpack_exports__UpdateSocialAuthConfigDto as UpdateSocialAuthConfigDto, __webpack_exports__UpdateUserDto as UpdateUserDto, __webpack_exports__UserBranchPermissionDto as UserBranchPermissionDto, __webpack_exports__UserBranchesResponseDto as UserBranchesResponseDto, __webpack_exports__UserCompaniesResponseDto as UserCompaniesResponseDto, __webpack_exports__UserCompanyPermission as UserCompanyPermission, __webpack_exports__UserCompanyPermissionDto as UserCompanyPermissionDto, __webpack_exports__UserController as UserController, __webpack_exports__UserInfoDto as UserInfoDto, __webpack_exports__UserLookupResponseDto as UserLookupResponseDto, __webpack_exports__UserPermissionController as UserPermissionController, __webpack_exports__UserPermissionService as UserPermissionService, __webpack_exports__UserResponseDto as UserResponseDto, __webpack_exports__UserService as UserService, __webpack_exports__UserToken as UserToken, __webpack_exports__VerifyEmailDto as VerifyEmailDto, __webpack_exports__authSwaggerConfig as authSwaggerConfig, __webpack_exports__generateAccessToken as generateAccessToken, __webpack_exports__generateTokens as generateTokens, __webpack_exports__getAuthEntitiesByConfig as getAuthEntitiesByConfig, __webpack_exports__getSocialProvider as getSocialProvider, __webpack_exports__parseExpiryToMs as parseExpiryToMs, __webpack_exports__toBranchInfo as toBranchInfo, __webpack_exports__toCompanyInfo as toCompanyInfo, __webpack_exports__toUserInfo as toUserInfo };
1566
+ export { __webpack_exports__AUTH_EMAIL_PROVIDER as AUTH_EMAIL_PROVIDER, __webpack_exports__AUTH_EVENT_ACTIONS as AUTH_EVENT_ACTIONS, __webpack_exports__AUTH_EVENT_ENTITIES as AUTH_EVENT_ENTITIES, __webpack_exports__AUTH_EVENT_MODULE as AUTH_EVENT_MODULE, __webpack_exports__AUTH_MESSAGES as AUTH_MESSAGES, __webpack_exports__AUTH_MODULE_OPTIONS as AUTH_MODULE_OPTIONS, __webpack_exports__AppUser as AppUser, __webpack_exports__AssignUserBranchDto as AssignUserBranchDto, __webpack_exports__AssignUserCompanyDto as AssignUserCompanyDto, __webpack_exports__AuthConfigService as AuthConfigService, __webpack_exports__AuthDataSourceProvider as AuthDataSourceProvider, __webpack_exports__AuthEmailService as AuthEmailService, __webpack_exports__AuthModule as AuthModule, __webpack_exports__AuthenticationController as AuthenticationController, __webpack_exports__AuthenticationService as AuthenticationService, __webpack_exports__BCRYPT_SALT_ROUNDS as BCRYPT_SALT_ROUNDS, __webpack_exports__BRANCH_MESSAGES as BRANCH_MESSAGES, __webpack_exports__BranchController as BranchController, __webpack_exports__BranchInfoDto as BranchInfoDto, __webpack_exports__BranchPermittedUserDto as BranchPermittedUserDto, __webpack_exports__BranchPermittedUsersResponseDto as BranchPermittedUsersResponseDto, __webpack_exports__BranchSelectionInfoDto as BranchSelectionInfoDto, __webpack_exports__BranchService as BranchService, __webpack_exports__COMPANY_MESSAGES as COMPANY_MESSAGES, __webpack_exports__ChangePasswordDto as ChangePasswordDto, __webpack_exports__ClearToken as ClearToken, __webpack_exports__Company as Company, __webpack_exports__CompanyAccessResolverAdapter as CompanyAccessResolverAdapter, __webpack_exports__CompanyBranch as CompanyBranch, __webpack_exports__CompanyBranchResponseDto as CompanyBranchResponseDto, __webpack_exports__CompanyController as CompanyController, __webpack_exports__CompanyInfoDto as CompanyInfoDto, __webpack_exports__CompanyPermittedUserDto as CompanyPermittedUserDto, __webpack_exports__CompanyPermittedUsersResponseDto as CompanyPermittedUsersResponseDto, __webpack_exports__CompanyResponseDto as CompanyResponseDto, __webpack_exports__CompanySelectionController as CompanySelectionController, __webpack_exports__CompanySelectionResponseDto as CompanySelectionResponseDto, __webpack_exports__CompanySelectionSessionService as CompanySelectionSessionService, __webpack_exports__CompanyService as CompanyService, __webpack_exports__CompanyWithBranchesDto as CompanyWithBranchesDto, __webpack_exports__CreateCompanyBranchDto as CreateCompanyBranchDto, __webpack_exports__CreateCompanyDto as CreateCompanyDto, __webpack_exports__CreateSocialAuthConfigDto as CreateSocialAuthConfigDto, __webpack_exports__CreateUserDto as CreateUserDto, __webpack_exports__DEFAULT_COOKIE_NAME as DEFAULT_COOKIE_NAME, __webpack_exports__EMAIL_VERIFICATION_MESSAGES as EMAIL_VERIFICATION_MESSAGES, __webpack_exports__EmailVerificationController as EmailVerificationController, __webpack_exports__ForgotPasswordDto as ForgotPasswordDto, __webpack_exports__GetBranchUsersDto as GetBranchUsersDto, __webpack_exports__GetCompanyUsersDto as GetCompanyUsersDto, __webpack_exports__JwtStrategy as JwtStrategy, __webpack_exports__LoginDto as LoginDto, __webpack_exports__LoginResponseDto as LoginResponseDto, __webpack_exports__LoginResponseRequiresEmailVerificationDto as LoginResponseRequiresEmailVerificationDto, __webpack_exports__MAX_COOKIE_BYTES as MAX_COOKIE_BYTES, __webpack_exports__MeResponseDto as MeResponseDto, __webpack_exports__PendingRegistration as PendingRegistration, __webpack_exports__PermissionItemDto as PermissionItemDto, __webpack_exports__PermissionType as PermissionType, __webpack_exports__RefreshTokenDto as RefreshTokenDto, __webpack_exports__RegistrationDto as RegistrationDto, __webpack_exports__RegistrationResponseDto as RegistrationResponseDto, __webpack_exports__ResendVerificationDto as ResendVerificationDto, __webpack_exports__ResetPasswordDto as ResetPasswordDto, __webpack_exports__SESSION_CACHE_PREFIX as SESSION_CACHE_PREFIX, __webpack_exports__SOCIAL_AUTH_CONFIG_MESSAGES as SOCIAL_AUTH_CONFIG_MESSAGES, __webpack_exports__SOCIAL_AUTH_MESSAGES as SOCIAL_AUTH_MESSAGES, __webpack_exports__SOCIAL_STATE_PREFIX as SOCIAL_STATE_PREFIX, __webpack_exports__SOCIAL_STATE_TTL_MS as SOCIAL_STATE_TTL_MS, __webpack_exports__SelectDto as SelectDto, __webpack_exports__SetToken as SetToken, __webpack_exports__SocialAuthConfig as SocialAuthConfig, __webpack_exports__SocialAuthConfigController as SocialAuthConfigController, __webpack_exports__SocialAuthConfigResponseDto as SocialAuthConfigResponseDto, __webpack_exports__SocialAuthConfigService as SocialAuthConfigService, __webpack_exports__SocialAuthController as SocialAuthController, __webpack_exports__SocialAuthService as SocialAuthService, __webpack_exports__SocialAuthorizeDto as SocialAuthorizeDto, __webpack_exports__SocialAuthorizeResponseDto as SocialAuthorizeResponseDto, __webpack_exports__SocialCallbackDto as SocialCallbackDto, __webpack_exports__SocialProviderInfoDto as SocialProviderInfoDto, __webpack_exports__SocialProviderTypeEnum as SocialProviderTypeEnum, __webpack_exports__SocialProvidersDto as SocialProvidersDto, __webpack_exports__SwitchCompanyDto as SwitchCompanyDto, __webpack_exports__TOKEN_REVOKED_PREFIX as TOKEN_REVOKED_PREFIX, __webpack_exports__TokenType as TokenType, __webpack_exports__USER_ENRICHER as USER_ENRICHER, __webpack_exports__USER_MESSAGES as USER_MESSAGES, __webpack_exports__USER_PERMISSION_MESSAGES as USER_PERMISSION_MESSAGES, __webpack_exports__UpdateCompanyBranchDto as UpdateCompanyBranchDto, __webpack_exports__UpdateCompanyDto as UpdateCompanyDto, __webpack_exports__UpdateSocialAuthConfigDto as UpdateSocialAuthConfigDto, __webpack_exports__UpdateUserDto as UpdateUserDto, __webpack_exports__UserBranchPermissionDto as UserBranchPermissionDto, __webpack_exports__UserBranchesResponseDto as UserBranchesResponseDto, __webpack_exports__UserCompaniesResponseDto as UserCompaniesResponseDto, __webpack_exports__UserCompanyPermission as UserCompanyPermission, __webpack_exports__UserCompanyPermissionDto as UserCompanyPermissionDto, __webpack_exports__UserController as UserController, __webpack_exports__UserInfoDto as UserInfoDto, __webpack_exports__UserLookupResponseDto as UserLookupResponseDto, __webpack_exports__UserPermissionController as UserPermissionController, __webpack_exports__UserPermissionService as UserPermissionService, __webpack_exports__UserResponseDto as UserResponseDto, __webpack_exports__UserService as UserService, __webpack_exports__UserToken as UserToken, __webpack_exports__VerifyEmailDto as VerifyEmailDto, __webpack_exports__authSwaggerConfig as authSwaggerConfig, __webpack_exports__generateAccessToken as generateAccessToken, __webpack_exports__generateTokens as generateTokens, __webpack_exports__getAuthEntitiesByConfig as getAuthEntitiesByConfig, __webpack_exports__getSocialProvider as getSocialProvider, __webpack_exports__parseExpiryToMs as parseExpiryToMs, __webpack_exports__toBranchInfo as toBranchInfo, __webpack_exports__toCompanyInfo as toCompanyInfo, __webpack_exports__toUserInfo as toUserInfo };
@@ -74,6 +74,8 @@ __webpack_require__.d(__webpack_exports__, {
74
74
  r: () => (/* reexport */ AuthModule)
75
75
  });
76
76
 
77
+ // EXTERNAL MODULE: external "@flusys/nestjs-shared/interfaces"
78
+ var interfaces_ = __webpack_require__(5103);
77
79
  // EXTERNAL MODULE: external "@flusys/nestjs-shared/modules"
78
80
  var modules_ = __webpack_require__(1236);
79
81
  // EXTERNAL MODULE: external "@nestjs/common"
@@ -94,8 +96,8 @@ var entities = __webpack_require__(5180);
94
96
  var clear_token_interceptor = __webpack_require__(5207);
95
97
  // EXTERNAL MODULE: ./projects/nestjs-auth/src/interceptors/set-token.interceptor.ts + 1 modules
96
98
  var set_token_interceptor = __webpack_require__(8359);
97
- // EXTERNAL MODULE: ./projects/nestjs-auth/src/services/index.ts
98
- var services = __webpack_require__(8811);
99
+ // EXTERNAL MODULE: ./projects/nestjs-auth/src/services/index.ts + 1 modules
100
+ var services = __webpack_require__(2991);
99
101
  // EXTERNAL MODULE: ./projects/nestjs-auth/src/services/auth-config.service.ts + 1 modules
100
102
  var auth_config_service = __webpack_require__(6514);
101
103
  // EXTERNAL MODULE: ./projects/nestjs-auth/src/services/auth-datasource.provider.ts
@@ -130,6 +132,7 @@ function _ts_decorate(decorators, target, key, desc) {
130
132
 
131
133
 
132
134
 
135
+
133
136
  class AuthModule {
134
137
  static forRoot(options) {
135
138
  const optionsProvider = {
@@ -216,7 +219,10 @@ class AuthModule {
216
219
  providers.push(services/* .AuthEmailService */.Gw);
217
220
  }
218
221
  if (flags.enableCompanyFeature) {
219
- providers.push(services/* .CompanySelectionSessionService */.vB, services/* .CompanyService */.Bl, services/* .BranchService */.O_, services/* .UserPermissionService */.OE);
222
+ providers.push(services/* .CompanySelectionSessionService */.vB, services/* .CompanyService */.Bl, services/* .BranchService */.O_, services/* .UserPermissionService */.OE, {
223
+ provide: interfaces_.COMPANY_ACCESS_RESOLVER,
224
+ useClass: services/* .CompanyAccessResolverAdapter */.ht
225
+ });
220
226
  }
221
227
  return providers;
222
228
  }
@@ -237,7 +243,7 @@ class AuthModule {
237
243
  exports.push(services/* .AuthEmailService */.Gw);
238
244
  }
239
245
  if (flags.enableCompanyFeature) {
240
- exports.push(services/* .CompanySelectionSessionService */.vB, services/* .CompanyService */.Bl, services/* .BranchService */.O_, services/* .UserPermissionService */.OE);
246
+ exports.push(services/* .CompanySelectionSessionService */.vB, services/* .CompanyService */.Bl, services/* .BranchService */.O_, services/* .UserPermissionService */.OE, interfaces_.COMPANY_ACCESS_RESOLVER);
241
247
  }
242
248
  return exports;
243
249
  }
@@ -314,18 +320,131 @@ AuthModule = _ts_decorate([
314
320
 
315
321
 
316
322
  },
317
- 8811(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
318
- /* import */ var _authentication_service_js__rspack_import_0 = __webpack_require__(4722);
319
- /* import */ var _auth_email_service_js__rspack_import_1 = __webpack_require__(3221);
320
- /* import */ var _company_selection_session_service_js__rspack_import_2 = __webpack_require__(5811);
321
- /* import */ var _social_auth_service_js__rspack_import_3 = __webpack_require__(2786);
322
- /* import */ var _social_auth_config_service_js__rspack_import_4 = __webpack_require__(8275);
323
- /* import */ var _user_service_js__rspack_import_5 = __webpack_require__(7229);
324
- /* import */ var _company_service_js__rspack_import_6 = __webpack_require__(9201);
325
- /* import */ var _branch_service_js__rspack_import_7 = __webpack_require__(5402);
326
- /* import */ var _user_permission_service_js__rspack_import_8 = __webpack_require__(5291);
327
- /* import */ var _auth_config_service_js__rspack_import_9 = __webpack_require__(6514);
328
- /* import */ var _auth_datasource_provider_js__rspack_import_10 = __webpack_require__(2732);
323
+ 2991(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
324
+
325
+ // EXPORTS
326
+ __webpack_require__.d(__webpack_exports__, {
327
+ WE: () => (/* reexport */ auth_config_service/* .AuthConfigService */.W),
328
+ vS: () => (/* reexport */ auth_datasource_provider/* .AuthDataSourceProvider */.v),
329
+ Gw: () => (/* reexport */ auth_email_service/* .AuthEmailService */.G),
330
+ kX: () => (/* reexport */ authentication_service/* .AuthenticationService */.k),
331
+ O_: () => (/* reexport */ branch_service/* .BranchService */.O),
332
+ ht: () => (/* reexport */ CompanyAccessResolverAdapter),
333
+ vB: () => (/* reexport */ company_selection_session_service/* .CompanySelectionSessionService */.v),
334
+ Bl: () => (/* reexport */ company_service/* .CompanyService */.B),
335
+ t_: () => (/* reexport */ social_auth_config_service/* .SocialAuthConfigService */.t),
336
+ Jn: () => (/* reexport */ social_auth_service/* .SocialAuthService */.J),
337
+ OE: () => (/* reexport */ user_permission_service/* .UserPermissionService */.O),
338
+ DL: () => (/* reexport */ user_service/* .UserService */.D)
339
+ });
340
+
341
+ // EXTERNAL MODULE: ./projects/nestjs-auth/src/services/authentication.service.ts + 1 modules
342
+ var authentication_service = __webpack_require__(4722);
343
+ // EXTERNAL MODULE: ./projects/nestjs-auth/src/services/auth-email.service.ts
344
+ var auth_email_service = __webpack_require__(3221);
345
+ // EXTERNAL MODULE: ./projects/nestjs-auth/src/services/company-selection-session.service.ts
346
+ var company_selection_session_service = __webpack_require__(5811);
347
+ // EXTERNAL MODULE: ./projects/nestjs-auth/src/services/social-auth.service.ts
348
+ var social_auth_service = __webpack_require__(2786);
349
+ // EXTERNAL MODULE: ./projects/nestjs-auth/src/services/social-auth-config.service.ts
350
+ var social_auth_config_service = __webpack_require__(8275);
351
+ // EXTERNAL MODULE: ./projects/nestjs-auth/src/services/user.service.ts
352
+ var user_service = __webpack_require__(7229);
353
+ // EXTERNAL MODULE: ./projects/nestjs-auth/src/services/company.service.ts
354
+ var company_service = __webpack_require__(9201);
355
+ // EXTERNAL MODULE: ./projects/nestjs-auth/src/services/branch.service.ts
356
+ var branch_service = __webpack_require__(5402);
357
+ // EXTERNAL MODULE: ./projects/nestjs-auth/src/services/user-permission.service.ts
358
+ var user_permission_service = __webpack_require__(5291);
359
+ // EXTERNAL MODULE: ./projects/nestjs-auth/src/services/auth-config.service.ts + 1 modules
360
+ var auth_config_service = __webpack_require__(6514);
361
+ // EXTERNAL MODULE: ./projects/nestjs-auth/src/services/auth-datasource.provider.ts
362
+ var auth_datasource_provider = __webpack_require__(2732);
363
+ // EXTERNAL MODULE: external "@nestjs/common"
364
+ var common_ = __webpack_require__(6157);
365
+ // EXTERNAL MODULE: external "@nestjs/core"
366
+ var core_ = __webpack_require__(3075);
367
+ ;// CONCATENATED MODULE: ./projects/nestjs-auth/src/services/company-access-resolver.adapter.ts
368
+ function _ts_decorate(decorators, target, key, desc) {
369
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
370
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
371
+ r = Reflect.decorate(decorators, target, key, desc);
372
+ } else {
373
+ for(var i = decorators.length - 1; i >= 0; i--){
374
+ if (d = decorators[i]) {
375
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
376
+ }
377
+ }
378
+ }
379
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
380
+ }
381
+ function _ts_metadata(metadataKey, metadataValue) {
382
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
383
+ return Reflect.metadata(metadataKey, metadataValue);
384
+ }
385
+ }
386
+ function _ts_param(paramIndex, decorator) {
387
+ return function(target, key) {
388
+ decorator(target, key, paramIndex);
389
+ };
390
+ }
391
+
392
+
393
+
394
+ const byName = (a, b)=>a.name.localeCompare(b.name);
395
+ /** Users of grants that still count: the grant is active and its user is active and not deleted. */ const activeUserIds = (grants)=>grants.filter((grant)=>grant.isActive && grant.user?.isActive && !grant.user.deletedAt).map((grant)=>grant.userId);
396
+ class CompanyAccessResolverAdapter {
397
+ moduleRef;
398
+ constructor(moduleRef){
399
+ this.moduleRef = moduleRef;
400
+ }
401
+ async getUserAccess(userId) {
402
+ const permissions = await this.moduleRef.resolve(user_permission_service/* .UserPermissionService */.O, core_.ContextIdFactory.create(), {
403
+ strict: false
404
+ });
405
+ const [companyGrants, branchGrants] = await Promise.all([
406
+ permissions.findUserCompanies(userId),
407
+ permissions.findUserBranches(userId)
408
+ ]);
409
+ const companies = companyGrants.map((grant)=>grant.company).filter((company)=>!!company?.isActive).sort(byName);
410
+ const companyIds = new Set(companies.map((company)=>company.id));
411
+ const branches = branchGrants.map((grant)=>grant.branch).filter((branch)=>!!branch?.isActive && companyIds.has(branch.companyId)).sort((a, b)=>(a.serial ?? 0) - (b.serial ?? 0) || byName(a, b));
412
+ return {
413
+ companies: companies.map(({ id, name })=>({
414
+ id,
415
+ name
416
+ })),
417
+ branches: branches.map(({ id, companyId, name })=>({
418
+ id,
419
+ companyId,
420
+ name
421
+ }))
422
+ };
423
+ }
424
+ async getCompanyMembers(companyId, branchIds = []) {
425
+ const permissions = await this.moduleRef.resolve(user_permission_service/* .UserPermissionService */.O, core_.ContextIdFactory.create(), {
426
+ strict: false
427
+ });
428
+ const members = activeUserIds(await permissions.findUsersForCompany(companyId));
429
+ if (!branchIds.length) return [
430
+ ...new Set(members)
431
+ ];
432
+ const inBranches = new Set(activeUserIds((await Promise.all(branchIds.map((branchId)=>permissions.findUsersForBranch(branchId)))).flat()));
433
+ return [
434
+ ...new Set(members.filter((userId)=>inBranches.has(userId)))
435
+ ];
436
+ }
437
+ }
438
+ CompanyAccessResolverAdapter = _ts_decorate([
439
+ (0,common_.Injectable)(),
440
+ _ts_param(0, (0,common_.Inject)(core_.ModuleRef)),
441
+ _ts_metadata("design:type", Function),
442
+ _ts_metadata("design:paramtypes", [
443
+ typeof core_.ModuleRef === "undefined" ? Object : core_.ModuleRef
444
+ ])
445
+ ], CompanyAccessResolverAdapter);
446
+
447
+ ;// CONCATENATED MODULE: ./projects/nestjs-auth/src/services/index.ts
329
448
 
330
449
 
331
450
 
@@ -338,19 +457,6 @@ AuthModule = _ts_decorate([
338
457
 
339
458
 
340
459
 
341
- __webpack_require__.d(__webpack_exports__, {
342
- Bl: () => (/* reexport safe */ _company_service_js__rspack_import_6.B),
343
- DL: () => (/* reexport safe */ _user_service_js__rspack_import_5.D),
344
- Gw: () => (/* reexport safe */ _auth_email_service_js__rspack_import_1.G),
345
- Jn: () => (/* reexport safe */ _social_auth_service_js__rspack_import_3.J),
346
- OE: () => (/* reexport safe */ _user_permission_service_js__rspack_import_8.O),
347
- O_: () => (/* reexport safe */ _branch_service_js__rspack_import_7.O),
348
- WE: () => (/* reexport safe */ _auth_config_service_js__rspack_import_9.W),
349
- kX: () => (/* reexport safe */ _authentication_service_js__rspack_import_0.k),
350
- t_: () => (/* reexport safe */ _social_auth_config_service_js__rspack_import_4.t),
351
- vB: () => (/* reexport safe */ _company_selection_session_service_js__rspack_import_2.v),
352
- vS: () => (/* reexport safe */ _auth_datasource_provider_js__rspack_import_10.v)
353
- });
354
460
 
355
461
 
356
462
  },
@@ -1,18 +1,131 @@
1
1
  export const __rspack_esm_id = 995;
2
2
  export const __rspack_esm_ids = [995];
3
3
  export const __webpack_modules__ = {
4
- 8811(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
5
- /* import */ var _authentication_service_js__rspack_import_0 = __webpack_require__(4722);
6
- /* import */ var _auth_email_service_js__rspack_import_1 = __webpack_require__(3221);
7
- /* import */ var _company_selection_session_service_js__rspack_import_2 = __webpack_require__(5811);
8
- /* import */ var _social_auth_service_js__rspack_import_3 = __webpack_require__(2786);
9
- /* import */ var _social_auth_config_service_js__rspack_import_4 = __webpack_require__(8275);
10
- /* import */ var _user_service_js__rspack_import_5 = __webpack_require__(7229);
11
- /* import */ var _company_service_js__rspack_import_6 = __webpack_require__(9201);
12
- /* import */ var _branch_service_js__rspack_import_7 = __webpack_require__(5402);
13
- /* import */ var _user_permission_service_js__rspack_import_8 = __webpack_require__(5291);
14
- /* import */ var _auth_config_service_js__rspack_import_9 = __webpack_require__(6514);
15
- /* import */ var _auth_datasource_provider_js__rspack_import_10 = __webpack_require__(2732);
4
+ 2991(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
5
+
6
+ // EXPORTS
7
+ __webpack_require__.d(__webpack_exports__, {
8
+ WE: () => (/* reexport */ auth_config_service/* .AuthConfigService */.W),
9
+ vS: () => (/* reexport */ auth_datasource_provider/* .AuthDataSourceProvider */.v),
10
+ Gw: () => (/* reexport */ auth_email_service/* .AuthEmailService */.G),
11
+ kX: () => (/* reexport */ authentication_service/* .AuthenticationService */.k),
12
+ O_: () => (/* reexport */ branch_service/* .BranchService */.O),
13
+ ht: () => (/* reexport */ CompanyAccessResolverAdapter),
14
+ vB: () => (/* reexport */ company_selection_session_service/* .CompanySelectionSessionService */.v),
15
+ Bl: () => (/* reexport */ company_service/* .CompanyService */.B),
16
+ t_: () => (/* reexport */ social_auth_config_service/* .SocialAuthConfigService */.t),
17
+ Jn: () => (/* reexport */ social_auth_service/* .SocialAuthService */.J),
18
+ OE: () => (/* reexport */ user_permission_service/* .UserPermissionService */.O),
19
+ DL: () => (/* reexport */ user_service/* .UserService */.D)
20
+ });
21
+
22
+ // EXTERNAL MODULE: ./projects/nestjs-auth/src/services/authentication.service.ts + 1 modules
23
+ var authentication_service = __webpack_require__(4722);
24
+ // EXTERNAL MODULE: ./projects/nestjs-auth/src/services/auth-email.service.ts
25
+ var auth_email_service = __webpack_require__(3221);
26
+ // EXTERNAL MODULE: ./projects/nestjs-auth/src/services/company-selection-session.service.ts
27
+ var company_selection_session_service = __webpack_require__(5811);
28
+ // EXTERNAL MODULE: ./projects/nestjs-auth/src/services/social-auth.service.ts
29
+ var social_auth_service = __webpack_require__(2786);
30
+ // EXTERNAL MODULE: ./projects/nestjs-auth/src/services/social-auth-config.service.ts
31
+ var social_auth_config_service = __webpack_require__(8275);
32
+ // EXTERNAL MODULE: ./projects/nestjs-auth/src/services/user.service.ts
33
+ var user_service = __webpack_require__(7229);
34
+ // EXTERNAL MODULE: ./projects/nestjs-auth/src/services/company.service.ts
35
+ var company_service = __webpack_require__(9201);
36
+ // EXTERNAL MODULE: ./projects/nestjs-auth/src/services/branch.service.ts
37
+ var branch_service = __webpack_require__(5402);
38
+ // EXTERNAL MODULE: ./projects/nestjs-auth/src/services/user-permission.service.ts
39
+ var user_permission_service = __webpack_require__(5291);
40
+ // EXTERNAL MODULE: ./projects/nestjs-auth/src/services/auth-config.service.ts + 1 modules
41
+ var auth_config_service = __webpack_require__(6514);
42
+ // EXTERNAL MODULE: ./projects/nestjs-auth/src/services/auth-datasource.provider.ts
43
+ var auth_datasource_provider = __webpack_require__(2732);
44
+ // EXTERNAL MODULE: external "@nestjs/common"
45
+ var common_ = __webpack_require__(6157);
46
+ // EXTERNAL MODULE: external "@nestjs/core"
47
+ var core_ = __webpack_require__(3075);
48
+ ;// CONCATENATED MODULE: ./projects/nestjs-auth/src/services/company-access-resolver.adapter.ts
49
+ function _ts_decorate(decorators, target, key, desc) {
50
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
51
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
52
+ r = Reflect.decorate(decorators, target, key, desc);
53
+ } else {
54
+ for(var i = decorators.length - 1; i >= 0; i--){
55
+ if (d = decorators[i]) {
56
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
57
+ }
58
+ }
59
+ }
60
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
61
+ }
62
+ function _ts_metadata(metadataKey, metadataValue) {
63
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
64
+ return Reflect.metadata(metadataKey, metadataValue);
65
+ }
66
+ }
67
+ function _ts_param(paramIndex, decorator) {
68
+ return function(target, key) {
69
+ decorator(target, key, paramIndex);
70
+ };
71
+ }
72
+
73
+
74
+
75
+ const byName = (a, b)=>a.name.localeCompare(b.name);
76
+ /** Users of grants that still count: the grant is active and its user is active and not deleted. */ const activeUserIds = (grants)=>grants.filter((grant)=>grant.isActive && grant.user?.isActive && !grant.user.deletedAt).map((grant)=>grant.userId);
77
+ class CompanyAccessResolverAdapter {
78
+ moduleRef;
79
+ constructor(moduleRef){
80
+ this.moduleRef = moduleRef;
81
+ }
82
+ async getUserAccess(userId) {
83
+ const permissions = await this.moduleRef.resolve(user_permission_service/* .UserPermissionService */.O, core_.ContextIdFactory.create(), {
84
+ strict: false
85
+ });
86
+ const [companyGrants, branchGrants] = await Promise.all([
87
+ permissions.findUserCompanies(userId),
88
+ permissions.findUserBranches(userId)
89
+ ]);
90
+ const companies = companyGrants.map((grant)=>grant.company).filter((company)=>!!company?.isActive).sort(byName);
91
+ const companyIds = new Set(companies.map((company)=>company.id));
92
+ const branches = branchGrants.map((grant)=>grant.branch).filter((branch)=>!!branch?.isActive && companyIds.has(branch.companyId)).sort((a, b)=>(a.serial ?? 0) - (b.serial ?? 0) || byName(a, b));
93
+ return {
94
+ companies: companies.map(({ id, name })=>({
95
+ id,
96
+ name
97
+ })),
98
+ branches: branches.map(({ id, companyId, name })=>({
99
+ id,
100
+ companyId,
101
+ name
102
+ }))
103
+ };
104
+ }
105
+ async getCompanyMembers(companyId, branchIds = []) {
106
+ const permissions = await this.moduleRef.resolve(user_permission_service/* .UserPermissionService */.O, core_.ContextIdFactory.create(), {
107
+ strict: false
108
+ });
109
+ const members = activeUserIds(await permissions.findUsersForCompany(companyId));
110
+ if (!branchIds.length) return [
111
+ ...new Set(members)
112
+ ];
113
+ const inBranches = new Set(activeUserIds((await Promise.all(branchIds.map((branchId)=>permissions.findUsersForBranch(branchId)))).flat()));
114
+ return [
115
+ ...new Set(members.filter((userId)=>inBranches.has(userId)))
116
+ ];
117
+ }
118
+ }
119
+ CompanyAccessResolverAdapter = _ts_decorate([
120
+ (0,common_.Injectable)(),
121
+ _ts_param(0, (0,common_.Inject)(core_.ModuleRef)),
122
+ _ts_metadata("design:type", Function),
123
+ _ts_metadata("design:paramtypes", [
124
+ typeof core_.ModuleRef === "undefined" ? Object : core_.ModuleRef
125
+ ])
126
+ ], CompanyAccessResolverAdapter);
127
+
128
+ ;// CONCATENATED MODULE: ./projects/nestjs-auth/src/services/index.ts
16
129
 
17
130
 
18
131
 
@@ -25,19 +138,6 @@ export const __webpack_modules__ = {
25
138
 
26
139
 
27
140
 
28
- __webpack_require__.d(__webpack_exports__, {
29
- Bl: () => (/* reexport safe */ _company_service_js__rspack_import_6.B),
30
- DL: () => (/* reexport safe */ _user_service_js__rspack_import_5.D),
31
- Gw: () => (/* reexport safe */ _auth_email_service_js__rspack_import_1.G),
32
- Jn: () => (/* reexport safe */ _social_auth_service_js__rspack_import_3.J),
33
- OE: () => (/* reexport safe */ _user_permission_service_js__rspack_import_8.O),
34
- O_: () => (/* reexport safe */ _branch_service_js__rspack_import_7.O),
35
- WE: () => (/* reexport safe */ _auth_config_service_js__rspack_import_9.W),
36
- kX: () => (/* reexport safe */ _authentication_service_js__rspack_import_0.k),
37
- t_: () => (/* reexport safe */ _social_auth_config_service_js__rspack_import_4.t),
38
- vB: () => (/* reexport safe */ _company_selection_session_service_js__rspack_import_2.v),
39
- vS: () => (/* reexport safe */ _auth_datasource_provider_js__rspack_import_10.v)
40
- });
41
141
 
42
142
 
43
143
  },
@@ -53,15 +153,16 @@ import * as __rspack_chunk_3 from '../24.js';
53
153
  __webpack_require__.C(__rspack_chunk_3);
54
154
  import * as __rspack_chunk_4 from './index.js';
55
155
  __webpack_require__.C(__rspack_chunk_4);
56
- var __webpack_exports__ = __webpack_exec__(8811);var __webpack_exports__AuthConfigService = __webpack_exports__.WE;
156
+ var __webpack_exports__ = __webpack_exec__(2991);var __webpack_exports__AuthConfigService = __webpack_exports__.WE;
57
157
  var __webpack_exports__AuthDataSourceProvider = __webpack_exports__.vS;
58
158
  var __webpack_exports__AuthEmailService = __webpack_exports__.Gw;
59
159
  var __webpack_exports__AuthenticationService = __webpack_exports__.kX;
60
160
  var __webpack_exports__BranchService = __webpack_exports__.O_;
161
+ var __webpack_exports__CompanyAccessResolverAdapter = __webpack_exports__.ht;
61
162
  var __webpack_exports__CompanySelectionSessionService = __webpack_exports__.vB;
62
163
  var __webpack_exports__CompanyService = __webpack_exports__.Bl;
63
164
  var __webpack_exports__SocialAuthConfigService = __webpack_exports__.t_;
64
165
  var __webpack_exports__SocialAuthService = __webpack_exports__.Jn;
65
166
  var __webpack_exports__UserPermissionService = __webpack_exports__.OE;
66
167
  var __webpack_exports__UserService = __webpack_exports__.DL;
67
- export { __webpack_exports__AuthConfigService as AuthConfigService, __webpack_exports__AuthDataSourceProvider as AuthDataSourceProvider, __webpack_exports__AuthEmailService as AuthEmailService, __webpack_exports__AuthenticationService as AuthenticationService, __webpack_exports__BranchService as BranchService, __webpack_exports__CompanySelectionSessionService as CompanySelectionSessionService, __webpack_exports__CompanyService as CompanyService, __webpack_exports__SocialAuthConfigService as SocialAuthConfigService, __webpack_exports__SocialAuthService as SocialAuthService, __webpack_exports__UserPermissionService as UserPermissionService, __webpack_exports__UserService as UserService };
168
+ export { __webpack_exports__AuthConfigService as AuthConfigService, __webpack_exports__AuthDataSourceProvider as AuthDataSourceProvider, __webpack_exports__AuthEmailService as AuthEmailService, __webpack_exports__AuthenticationService as AuthenticationService, __webpack_exports__BranchService as BranchService, __webpack_exports__CompanyAccessResolverAdapter as CompanyAccessResolverAdapter, __webpack_exports__CompanySelectionSessionService as CompanySelectionSessionService, __webpack_exports__CompanyService as CompanyService, __webpack_exports__SocialAuthConfigService as SocialAuthConfigService, __webpack_exports__SocialAuthService as SocialAuthService, __webpack_exports__UserPermissionService as UserPermissionService, __webpack_exports__UserService as UserService };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flusys/nestjs-auth",
3
- "version": "8.1.5",
3
+ "version": "9.0.0",
4
4
  "description": "Authentication and authorization infrastructure for NestJS applications",
5
5
  "type": "module",
6
6
  "main": "./fesm/index.js",
@@ -78,6 +78,7 @@
78
78
  "@nestjs/jwt": "^12.0.0",
79
79
  "@nestjs/passport": "^12.0.0",
80
80
  "@nestjs/swagger": "^12.0.0",
81
+ "@nestjs/throttler": "^6.5.0",
81
82
  "@nestjs/typeorm": "^12.0.0",
82
83
  "bcrypt": "^6.0.0",
83
84
  "class-transformer": "^0.5.1",
@@ -91,7 +92,7 @@
91
92
  "rxjs": "^7.8.0"
92
93
  },
93
94
  "dependencies": {
94
- "@flusys/nestjs-core": "8.1.5",
95
- "@flusys/nestjs-shared": "8.1.5"
95
+ "@flusys/nestjs-core": "9.0.0",
96
+ "@flusys/nestjs-shared": "9.0.0"
96
97
  }
97
98
  }
@@ -0,0 +1,8 @@
1
+ import { type ICompanyAccessResolver, type IUserCompanyAccess } from '@flusys/nestjs-shared/interfaces';
2
+ import { ModuleRef } from '@nestjs/core';
3
+ export declare class CompanyAccessResolverAdapter implements ICompanyAccessResolver {
4
+ private readonly moduleRef;
5
+ constructor(moduleRef: ModuleRef);
6
+ getUserAccess(userId: string): Promise<IUserCompanyAccess>;
7
+ getCompanyMembers(companyId: string, branchIds?: string[]): Promise<string[]>;
8
+ }
@@ -9,3 +9,4 @@ export * from './branch.service.js';
9
9
  export * from './user-permission.service.js';
10
10
  export * from './auth-config.service.js';
11
11
  export * from './auth-datasource.provider.js';
12
+ export * from './company-access-resolver.adapter.js';