@flusys/nestjs-auth 9.1.0-rc.1 → 9.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/fesm/370.js CHANGED
@@ -32,6 +32,7 @@ function _ts_metadata(metadataKey, metadataValue) {
32
32
  class LoginDto {
33
33
  email;
34
34
  password;
35
+ rememberMe;
35
36
  }
36
37
  _ts_decorate([
37
38
  (0,_nestjs_swagger__rspack_import_0.ApiProperty)({
@@ -52,6 +53,15 @@ _ts_decorate([
52
53
  (0,class_validator__rspack_import_1.MaxLength)(128),
53
54
  _ts_metadata("design:type", String)
54
55
  ], LoginDto.prototype, "password", void 0);
56
+ _ts_decorate([
57
+ (0,_nestjs_swagger__rspack_import_0.ApiPropertyOptional)({
58
+ default: true,
59
+ description: 'false: the refresh cookie is a session cookie, dropped when the browser closes'
60
+ }),
61
+ (0,class_validator__rspack_import_1.IsOptional)(),
62
+ (0,class_validator__rspack_import_1.IsBoolean)(),
63
+ _ts_metadata("design:type", Boolean)
64
+ ], LoginDto.prototype, "rememberMe", void 0);
55
65
  class RegistrationDto {
56
66
  name;
57
67
  email;
@@ -206,6 +216,7 @@ class SelectDto {
206
216
  sessionId;
207
217
  companyId;
208
218
  branchId;
219
+ rememberMe;
209
220
  }
210
221
  _ts_decorate([
211
222
  (0,_nestjs_swagger__rspack_import_0.ApiProperty)({
@@ -234,6 +245,15 @@ _ts_decorate([
234
245
  (0,class_validator__rspack_import_1.IsNotEmpty)(),
235
246
  _ts_metadata("design:type", String)
236
247
  ], SelectDto.prototype, "branchId", void 0);
248
+ _ts_decorate([
249
+ (0,_nestjs_swagger__rspack_import_0.ApiPropertyOptional)({
250
+ default: true,
251
+ description: 'false: the refresh cookie is a session cookie, dropped when the browser closes'
252
+ }),
253
+ (0,class_validator__rspack_import_1.IsOptional)(),
254
+ (0,class_validator__rspack_import_1.IsBoolean)(),
255
+ _ts_metadata("design:type", Boolean)
256
+ ], SelectDto.prototype, "rememberMe", void 0);
237
257
  class SwitchCompanyDto {
238
258
  companyId;
239
259
  branchId;
@@ -357,6 +377,9 @@ class BranchSelectionInfoDto {
357
377
  name;
358
378
  slug;
359
379
  logoId;
380
+ parentId;
381
+ serial;
382
+ displayParentId;
360
383
  }
361
384
  _ts_decorate([
362
385
  (0,_nestjs_swagger__rspack_import_0.ApiProperty)({
@@ -384,6 +407,33 @@ _ts_decorate([
384
407
  }),
385
408
  _ts_metadata("design:type", Object)
386
409
  ], BranchSelectionInfoDto.prototype, "logoId", void 0);
410
+ _ts_decorate([
411
+ (0,_nestjs_swagger__rspack_import_0.ApiPropertyOptional)({
412
+ description: 'Parent branch ID (null for a root branch)',
413
+ example: null,
414
+ nullable: true,
415
+ type: String
416
+ }),
417
+ _ts_metadata("design:type", Object)
418
+ ], BranchSelectionInfoDto.prototype, "parentId", void 0);
419
+ _ts_decorate([
420
+ (0,_nestjs_swagger__rspack_import_0.ApiPropertyOptional)({
421
+ description: 'Sort order among sibling branches',
422
+ example: 1,
423
+ nullable: true,
424
+ type: Number
425
+ }),
426
+ _ts_metadata("design:type", Object)
427
+ ], BranchSelectionInfoDto.prototype, "serial", void 0);
428
+ _ts_decorate([
429
+ (0,_nestjs_swagger__rspack_import_0.ApiPropertyOptional)({
430
+ description: 'Tree parent within this list: the nearest ancestor that is also listed (granted), null when none is - ungranted branches in between are skipped',
431
+ example: '550e8400-e29b-41d4-a716-446655440003',
432
+ nullable: true,
433
+ type: String
434
+ }),
435
+ _ts_metadata("design:type", Object)
436
+ ], BranchSelectionInfoDto.prototype, "displayParentId", void 0);
387
437
  class CompanyWithBranchesDto {
388
438
  id;
389
439
  name;
@@ -189,7 +189,9 @@ const COMPANY_MESSAGES = {
189
189
  READONLY_DELETE_FORBIDDEN: 'company.readonly.delete.forbidden'
190
190
  };
191
191
  const BRANCH_MESSAGES = {
192
- READONLY_DELETE_FORBIDDEN: 'branch.readonly.delete.forbidden'
192
+ READONLY_DELETE_FORBIDDEN: 'branch.readonly.delete.forbidden',
193
+ INVALID_PARENT: 'branch.invalid.parent',
194
+ CIRCULAR_PARENT: 'branch.circular.parent'
193
195
  };
194
196
  const USER_PERMISSION_MESSAGES = {
195
197
  COMPANY_LIST_SUCCESS: 'user.permission.company.list.success',
@@ -92,7 +92,10 @@ const COMPANY_SCHEMA_EXCLUSIONS = [
92
92
  'id',
93
93
  'name',
94
94
  'slug',
95
- 'logoId'
95
+ 'logoId',
96
+ 'parentId',
97
+ 'serial',
98
+ 'displayParentId'
96
99
  ]
97
100
  },
98
101
  {
@@ -242,7 +245,10 @@ const COMPANY_SCHEMA_EXCLUSIONS = [
242
245
  'branchId',
243
246
  'branchName',
244
247
  'branchSlug',
245
- 'companyId'
248
+ 'companyId',
249
+ 'parentId',
250
+ 'serial',
251
+ 'displayParentId'
246
252
  ]
247
253
  },
248
254
  {
@@ -1,7 +1,109 @@
1
+ import * as __rspack_external__flusys_nestjs_shared_utils_9125c1f1 from "@flusys/nestjs-shared/utils";
2
+ import * as __rspack_external_class_validator_7b99ef4d from "class-validator";
3
+ import * as __rspack_external_typeorm from "typeorm";
1
4
  export const __rspack_esm_id = 468;
2
5
  export const __rspack_esm_ids = [468];
3
6
  export const __webpack_modules__ = {
4
- 2295(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
7
+ 5588(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
8
+ // Injection Tokens
9
+ const AUTH_MODULE_OPTIONS = 'AUTH_MODULE_OPTIONS';
10
+ const USER_ENRICHER = 'USER_ENRICHER';
11
+ // Security
12
+ const BCRYPT_SALT_ROUNDS = 12;
13
+ // Cookie
14
+ const DEFAULT_COOKIE_NAME = 'fsn_refresh_token';
15
+ const MAX_COOKIE_BYTES = 3500;
16
+ // Cache Key Prefixes
17
+ const SESSION_CACHE_PREFIX = 'auth:session';
18
+ const TOKEN_REVOKED_PREFIX = 'auth:revoked';
19
+ const SOCIAL_STATE_PREFIX = 'auth:social:state';
20
+ // Social Login
21
+ const SOCIAL_STATE_TTL_MS = 10 * 60 * 1000; // 10 minutes
22
+
23
+ __webpack_require__.d(__webpack_exports__, {
24
+ }, {
25
+ EV: TOKEN_REVOKED_PREFIX,
26
+ PR: SOCIAL_STATE_PREFIX,
27
+ Vl: SESSION_CACHE_PREFIX,
28
+ jt: USER_ENRICHER,
29
+ rv: DEFAULT_COOKIE_NAME,
30
+ xe: AUTH_MODULE_OPTIONS
31
+ });
32
+
33
+
34
+ },
35
+ 7526(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
36
+ /* import */ var _flusys_nestjs_shared_utils__rspack_import_0 = __webpack_require__(9216);
37
+ /* import */ var class_validator__rspack_import_1 = __webpack_require__(5421);
38
+ /* import */ var typeorm__rspack_import_2 = __webpack_require__(7158);
39
+
40
+
41
+
42
+ /** Every branch of the companies the given branches belong to - a parent never leaves its company. */ async function loadCompanyBranchNodes(repo, branchIds, withDeleted = false) {
43
+ if (!branchIds.length) return [];
44
+ const seeds = await repo.find({
45
+ where: {
46
+ id: (0,typeorm__rspack_import_2.In)([
47
+ ...branchIds
48
+ ])
49
+ },
50
+ select: [
51
+ 'id',
52
+ 'companyId'
53
+ ],
54
+ withDeleted
55
+ });
56
+ const companyIds = [
57
+ ...new Set(seeds.map((b)=>b.companyId))
58
+ ];
59
+ if (!companyIds.length) return [];
60
+ return repo.find({
61
+ where: {
62
+ companyId: (0,typeorm__rspack_import_2.In)(companyIds)
63
+ },
64
+ select: [
65
+ 'id',
66
+ 'parentId'
67
+ ],
68
+ withDeleted
69
+ });
70
+ }
71
+ /**
72
+ * For each listed branch, its nearest ancestor that is listed too, or null when none is - the tree parent
73
+ * inside a list of granted branches. The branches in between are skipped and never sent to the client.
74
+ */ async function loadDisplayParentIds(repo, branchIds) {
75
+ const ids = (0,_flusys_nestjs_shared_utils__rspack_import_0.normalizeBranchIds)(branchIds).filter((id)=>(0,class_validator__rspack_import_1.isUUID)(id));
76
+ const listed = new Set(ids);
77
+ const nodes = await loadCompanyBranchNodes(repo, ids);
78
+ return new Map(ids.map((id)=>[
79
+ id,
80
+ (0,_flusys_nestjs_shared_utils__rspack_import_0.collectBranchAncestorIds)(nodes, id).find((a)=>listed.has(a)) ?? null
81
+ ]));
82
+ }
83
+
84
+ __webpack_require__.d(__webpack_exports__, {
85
+ v: () => (loadCompanyBranchNodes),
86
+ x: () => (loadDisplayParentIds)
87
+ });
88
+
89
+
90
+ },
91
+ 334(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
92
+
93
+ // EXPORTS
94
+ __webpack_require__.d(__webpack_exports__, {
95
+ Vg: () => (/* reexport */ generateAccessToken),
96
+ e: () => (/* reexport */ generateTokens),
97
+ vR: () => (/* reexport */ branch_ancestry_helper/* .loadCompanyBranchNodes */.v),
98
+ xu: () => (/* reexport */ branch_ancestry_helper/* .loadDisplayParentIds */.x),
99
+ om: () => (/* reexport */ parseExpiryToMs),
100
+ XP: () => (/* reexport */ revokeUserSessions),
101
+ QH: () => (/* reexport */ toBranchInfo),
102
+ $C: () => (/* reexport */ toCompanyInfo),
103
+ FV: () => (/* reexport */ toUserInfo)
104
+ });
105
+
106
+ ;// CONCATENATED MODULE: ./projects/nestjs-auth/src/helpers/auth-response.mapper.ts
5
107
  function toUserInfo(user) {
6
108
  return {
7
109
  id: user.id,
@@ -28,32 +130,12 @@ function toBranchInfo(branch) {
28
130
  };
29
131
  }
30
132
 
31
- __webpack_require__.d(__webpack_exports__, {
32
- $C: () => (toCompanyInfo),
33
- FV: () => (toUserInfo),
34
- QH: () => (toBranchInfo)
35
- });
36
-
133
+ // EXTERNAL MODULE: ./projects/nestjs-auth/src/helpers/branch-ancestry.helper.ts
134
+ var branch_ancestry_helper = __webpack_require__(7526);
135
+ // EXTERNAL MODULE: ./projects/nestjs-auth/src/config/auth.constants.ts
136
+ var auth_constants = __webpack_require__(5588);
137
+ ;// CONCATENATED MODULE: ./projects/nestjs-auth/src/helpers/token.helper.ts
37
138
 
38
- },
39
- 892(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
40
- /* import */ var _auth_response_mapper_js__rspack_import_0 = __webpack_require__(2295);
41
- /* import */ var _token_helper_js__rspack_import_1 = __webpack_require__(1379);
42
-
43
-
44
-
45
- __webpack_require__.d(__webpack_exports__, {
46
- $C: () => (/* reexport safe */ _auth_response_mapper_js__rspack_import_0.$C),
47
- FV: () => (/* reexport safe */ _auth_response_mapper_js__rspack_import_0.FV),
48
- QH: () => (/* reexport safe */ _auth_response_mapper_js__rspack_import_0.QH),
49
- Vg: () => (/* reexport safe */ _token_helper_js__rspack_import_1.Vg),
50
- e: () => (/* reexport safe */ _token_helper_js__rspack_import_1.e),
51
- om: () => (/* reexport safe */ _token_helper_js__rspack_import_1.om)
52
- });
53
-
54
-
55
- },
56
- 1379(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
57
139
  function generateAccessToken(jwtService, authConfig, payload) {
58
140
  return jwtService.sign({
59
141
  ...payload,
@@ -97,12 +179,33 @@ function parseExpiryToMs(expiry) {
97
179
  return 7 * 24 * 60 * 60 * 1000;
98
180
  }
99
181
  }
182
+ /** Rejects every token the user holds that was issued before now: checked on refresh and, by JwtStrategy, on every request. */ async function revokeUserSessions(cache, authConfig, userId) {
183
+ const revokedAt = Math.floor(Date.now() / 1000);
184
+ await cache.set(`${auth_constants/* .TOKEN_REVOKED_PREFIX */.EV}:${userId}`, revokedAt, parseExpiryToMs(authConfig.getRefreshTokenExpiration()));
185
+ }
100
186
 
101
- __webpack_require__.d(__webpack_exports__, {
102
- Vg: () => (generateAccessToken),
103
- e: () => (generateTokens),
104
- om: () => (parseExpiryToMs)
105
- });
187
+ ;// CONCATENATED MODULE: ./projects/nestjs-auth/src/helpers/index.ts
188
+
189
+
190
+
191
+
192
+
193
+ },
194
+ 9216(module) {
195
+
196
+ module.exports = __rspack_external__flusys_nestjs_shared_utils_9125c1f1;
197
+
198
+
199
+ },
200
+ 5421(module) {
201
+
202
+ module.exports = __rspack_external_class_validator_7b99ef4d;
203
+
204
+
205
+ },
206
+ 7158(module) {
207
+
208
+ module.exports = __rspack_external_typeorm;
106
209
 
107
210
 
108
211
  },
@@ -112,10 +215,13 @@ import { __webpack_require__ } from '../runtime.js';
112
215
  var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId); }
113
216
  import * as __rspack_chunk_1 from './index.js';
114
217
  __webpack_require__.C(__rspack_chunk_1);
115
- var __webpack_exports__ = __webpack_exec__(892);var __webpack_exports__generateAccessToken = __webpack_exports__.Vg;
218
+ var __webpack_exports__ = __webpack_exec__(334);var __webpack_exports__generateAccessToken = __webpack_exports__.Vg;
116
219
  var __webpack_exports__generateTokens = __webpack_exports__.e;
220
+ var __webpack_exports__loadCompanyBranchNodes = __webpack_exports__.vR;
221
+ var __webpack_exports__loadDisplayParentIds = __webpack_exports__.xu;
117
222
  var __webpack_exports__parseExpiryToMs = __webpack_exports__.om;
223
+ var __webpack_exports__revokeUserSessions = __webpack_exports__.XP;
118
224
  var __webpack_exports__toBranchInfo = __webpack_exports__.QH;
119
225
  var __webpack_exports__toCompanyInfo = __webpack_exports__.$C;
120
226
  var __webpack_exports__toUserInfo = __webpack_exports__.FV;
121
- export { __webpack_exports__generateAccessToken as generateAccessToken, __webpack_exports__generateTokens as generateTokens, __webpack_exports__parseExpiryToMs as parseExpiryToMs, __webpack_exports__toBranchInfo as toBranchInfo, __webpack_exports__toCompanyInfo as toCompanyInfo, __webpack_exports__toUserInfo as toUserInfo };
227
+ export { __webpack_exports__generateAccessToken as generateAccessToken, __webpack_exports__generateTokens as generateTokens, __webpack_exports__loadCompanyBranchNodes as loadCompanyBranchNodes, __webpack_exports__loadDisplayParentIds as loadDisplayParentIds, __webpack_exports__parseExpiryToMs as parseExpiryToMs, __webpack_exports__revokeUserSessions as revokeUserSessions, __webpack_exports__toBranchInfo as toBranchInfo, __webpack_exports__toCompanyInfo as toCompanyInfo, __webpack_exports__toUserInfo as toUserInfo };