@spinajs/rbac 2.0.481 → 2.0.484
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/lib/cjs/actions.d.ts.map +1 -1
- package/lib/cjs/actions.js +38 -7
- package/lib/cjs/actions.js.map +1 -1
- package/lib/cjs/auth.d.ts.map +1 -1
- package/lib/cjs/auth.js +8 -4
- package/lib/cjs/auth.js.map +1 -1
- package/lib/cjs/cli/ActivateUser.js +1 -1
- package/lib/cjs/cli/ActivateUser.js.map +1 -1
- package/lib/cjs/cli/BanUser.js +1 -1
- package/lib/cjs/cli/BanUser.js.map +1 -1
- package/lib/cjs/config/rbac.d.ts +11 -1
- package/lib/cjs/config/rbac.d.ts.map +1 -1
- package/lib/cjs/config/rbac.js +12 -3
- package/lib/cjs/config/rbac.js.map +1 -1
- package/lib/cjs/cron/DeactivatePasswords.d.ts.map +1 -1
- package/lib/cjs/cron/DeactivatePasswords.js +6 -2
- package/lib/cjs/cron/DeactivatePasswords.js.map +1 -1
- package/lib/cjs/index.d.ts +6 -0
- package/lib/cjs/index.d.ts.map +1 -1
- package/lib/cjs/index.js +6 -0
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/interfaces.d.ts +87 -37
- package/lib/cjs/interfaces.d.ts.map +1 -1
- package/lib/cjs/interfaces.js +47 -1
- package/lib/cjs/interfaces.js.map +1 -1
- package/lib/cjs/middleware.d.ts +24 -1
- package/lib/cjs/middleware.d.ts.map +1 -1
- package/lib/cjs/middleware.js +204 -104
- package/lib/cjs/middleware.js.map +1 -1
- package/lib/cjs/models/User.d.ts.map +1 -1
- package/lib/cjs/models/User.js +23 -4
- package/lib/cjs/models/User.js.map +1 -1
- package/lib/cjs/models/UserMetadata.d.ts.map +1 -1
- package/lib/cjs/models/UserMetadata.js +6 -0
- package/lib/cjs/models/UserMetadata.js.map +1 -1
- package/lib/cjs/ownership.d.ts +2 -0
- package/lib/cjs/ownership.d.ts.map +1 -0
- package/lib/cjs/ownership.js +46 -0
- package/lib/cjs/ownership.js.map +1 -0
- package/lib/cjs/session-codec.d.ts +15 -0
- package/lib/cjs/session-codec.d.ts.map +1 -0
- package/lib/cjs/session-codec.js +59 -0
- package/lib/cjs/session-codec.js.map +1 -0
- package/lib/cjs/session-expiration.d.ts +40 -0
- package/lib/cjs/session-expiration.d.ts.map +1 -0
- package/lib/cjs/session-expiration.js +93 -0
- package/lib/cjs/session-expiration.js.map +1 -0
- package/lib/cjs/session.d.ts +38 -18
- package/lib/cjs/session.d.ts.map +1 -1
- package/lib/cjs/session.js +91 -50
- package/lib/cjs/session.js.map +1 -1
- package/lib/mjs/actions.d.ts.map +1 -1
- package/lib/mjs/actions.js +38 -7
- package/lib/mjs/actions.js.map +1 -1
- package/lib/mjs/auth.d.ts.map +1 -1
- package/lib/mjs/auth.js +8 -4
- package/lib/mjs/auth.js.map +1 -1
- package/lib/mjs/cli/ActivateUser.js +1 -1
- package/lib/mjs/cli/ActivateUser.js.map +1 -1
- package/lib/mjs/cli/BanUser.js +1 -1
- package/lib/mjs/cli/BanUser.js.map +1 -1
- package/lib/mjs/config/rbac.d.ts +11 -1
- package/lib/mjs/config/rbac.d.ts.map +1 -1
- package/lib/mjs/config/rbac.js +12 -3
- package/lib/mjs/config/rbac.js.map +1 -1
- package/lib/mjs/cron/DeactivatePasswords.d.ts.map +1 -1
- package/lib/mjs/cron/DeactivatePasswords.js +6 -2
- package/lib/mjs/cron/DeactivatePasswords.js.map +1 -1
- package/lib/mjs/index.d.ts +6 -0
- package/lib/mjs/index.d.ts.map +1 -1
- package/lib/mjs/index.js +6 -0
- package/lib/mjs/index.js.map +1 -1
- package/lib/mjs/interfaces.d.ts +87 -37
- package/lib/mjs/interfaces.d.ts.map +1 -1
- package/lib/mjs/interfaces.js +45 -0
- package/lib/mjs/interfaces.js.map +1 -1
- package/lib/mjs/middleware.d.ts +24 -1
- package/lib/mjs/middleware.d.ts.map +1 -1
- package/lib/mjs/middleware.js +204 -104
- package/lib/mjs/middleware.js.map +1 -1
- package/lib/mjs/models/User.d.ts.map +1 -1
- package/lib/mjs/models/User.js +24 -5
- package/lib/mjs/models/User.js.map +1 -1
- package/lib/mjs/models/UserMetadata.d.ts.map +1 -1
- package/lib/mjs/models/UserMetadata.js +6 -0
- package/lib/mjs/models/UserMetadata.js.map +1 -1
- package/lib/mjs/ownership.d.ts +2 -0
- package/lib/mjs/ownership.d.ts.map +1 -0
- package/lib/mjs/ownership.js +44 -0
- package/lib/mjs/ownership.js.map +1 -0
- package/lib/mjs/session-codec.d.ts +15 -0
- package/lib/mjs/session-codec.d.ts.map +1 -0
- package/lib/mjs/session-codec.js +55 -0
- package/lib/mjs/session-codec.js.map +1 -0
- package/lib/mjs/session-expiration.d.ts +40 -0
- package/lib/mjs/session-expiration.d.ts.map +1 -0
- package/lib/mjs/session-expiration.js +90 -0
- package/lib/mjs/session-expiration.js.map +1 -0
- package/lib/mjs/session.d.ts +38 -18
- package/lib/mjs/session.d.ts.map +1 -1
- package/lib/mjs/session.js +89 -47
- package/lib/mjs/session.js.map +1 -1
- package/lib/tsconfig.cjs.tsbuildinfo +1 -1
- package/lib/tsconfig.mjs.tsbuildinfo +1 -1
- package/package.json +15 -12
package/lib/cjs/interfaces.d.ts
CHANGED
|
@@ -39,28 +39,39 @@ export interface ISession {
|
|
|
39
39
|
*/
|
|
40
40
|
SessionId: string;
|
|
41
41
|
/**
|
|
42
|
-
*
|
|
42
|
+
* User id that owns this session. Single source of truth for ownership.
|
|
43
|
+
* 0 / -1 = anonymous.
|
|
43
44
|
*/
|
|
44
|
-
|
|
45
|
+
UserId: number;
|
|
45
46
|
/**
|
|
46
|
-
* Session creation date.
|
|
47
|
+
* Session creation date.
|
|
47
48
|
*/
|
|
48
49
|
Creation: DateTime;
|
|
50
|
+
/**
|
|
51
|
+
* Absolute expiration instant. After that date session is invalid.
|
|
52
|
+
* `undefined` = never expires.
|
|
53
|
+
*/
|
|
54
|
+
Expiration?: DateTime;
|
|
49
55
|
/**
|
|
50
56
|
* Data holds by session
|
|
51
57
|
*/
|
|
52
58
|
Data: Map<string, unknown>;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Configurable session expiration strategy. Resolved by config service name at
|
|
62
|
+
* `rbac.session.expiration.service`, mirroring the `rbac.password` pattern.
|
|
63
|
+
*
|
|
64
|
+
* Units for all shipped strategies are MINUTES.
|
|
65
|
+
*/
|
|
66
|
+
export declare abstract class SessionExpirationProvider {
|
|
53
67
|
/**
|
|
54
|
-
*
|
|
68
|
+
* Expiration to set when a session is first created. `undefined` = never expires.
|
|
55
69
|
*/
|
|
56
|
-
|
|
70
|
+
abstract initial(session: ISession): DateTime | undefined;
|
|
57
71
|
/**
|
|
58
|
-
*
|
|
59
|
-
* Extends session lifetime
|
|
60
|
-
*
|
|
61
|
-
* @param seconds - how mutch to extend, if value not provided, default value from config is used
|
|
72
|
+
* Expiration to set when a session is renewed (touch).
|
|
62
73
|
*/
|
|
63
|
-
|
|
74
|
+
abstract renew(session: ISession): DateTime | undefined;
|
|
64
75
|
}
|
|
65
76
|
/**
|
|
66
77
|
* Service used for generating random password & for hash raw string
|
|
@@ -180,56 +191,71 @@ export declare abstract class FederatedAuthProvider<C, U = User> {
|
|
|
180
191
|
*/
|
|
181
192
|
abstract authenticate(credentials: C): Promise<U>;
|
|
182
193
|
}
|
|
183
|
-
export declare abstract class SessionProvider<T = ISession> extends AsyncService {
|
|
194
|
+
export declare abstract class SessionProvider<T extends ISession = ISession> extends AsyncService {
|
|
184
195
|
/**
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
* @param sessionId - session identifier
|
|
196
|
+
* Expiration strategy, resolved by config service name at
|
|
197
|
+
* `rbac.session.expiration`. Every store shares the same strategy so
|
|
198
|
+
* expiration semantics are uniform across providers.
|
|
189
199
|
*/
|
|
190
|
-
|
|
200
|
+
protected Expiration: SessionExpirationProvider;
|
|
191
201
|
/**
|
|
202
|
+
* Load session from store. Returns `null` when the session is missing OR
|
|
203
|
+
* expired — providers MUST treat an expired row as absent.
|
|
192
204
|
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
* @param sessionId - session to delete
|
|
205
|
+
* @param sessionId - session identifier
|
|
196
206
|
*/
|
|
197
|
-
abstract
|
|
207
|
+
abstract restore(sessionId: string): Promise<T | null>;
|
|
198
208
|
/**
|
|
199
|
-
*
|
|
200
|
-
*
|
|
209
|
+
* Upsert a session. MUST persist `session.Expiration` verbatim (never
|
|
210
|
+
* recompute it for an already-scheduled session). A brand-new session with
|
|
211
|
+
* no expiration set yet is given its initial expiration via the strategy.
|
|
201
212
|
*
|
|
202
213
|
* @param session - session to update / insert
|
|
203
214
|
*/
|
|
204
215
|
abstract save(session: ISession): Promise<void>;
|
|
205
216
|
/**
|
|
217
|
+
* Recompute `Expiration` via the strategy; if it changed, persist and report
|
|
218
|
+
* `true` so the caller refreshes the cookie. If unchanged (e.g. under
|
|
219
|
+
* `AbsoluteExpiration`), skip the write and return `false`.
|
|
206
220
|
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
* @param id - session id
|
|
210
|
-
* @param data - key - value pair of data
|
|
221
|
+
* @param session - session to renew
|
|
211
222
|
*/
|
|
212
|
-
abstract
|
|
223
|
+
abstract touch(session: ISession): Promise<boolean>;
|
|
213
224
|
/**
|
|
225
|
+
* Deletes a single session from store.
|
|
214
226
|
*
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
* @param session - session to update
|
|
227
|
+
* @param sessionId - session to delete
|
|
218
228
|
*/
|
|
219
|
-
abstract
|
|
229
|
+
abstract delete(sessionId: string): Promise<void>;
|
|
220
230
|
/**
|
|
231
|
+
* Log a user out of all devices. Keyed on numeric `UserId` in every store.
|
|
221
232
|
*
|
|
222
|
-
*
|
|
233
|
+
* @param userId - numeric owner id
|
|
234
|
+
*/
|
|
235
|
+
abstract deleteByUser(userId: number): Promise<void>;
|
|
236
|
+
/**
|
|
237
|
+
* All live (non-expired) sessions for a user — powers "active devices" and
|
|
238
|
+
* selective revoke.
|
|
223
239
|
*
|
|
240
|
+
* @param userId - numeric owner id
|
|
241
|
+
*/
|
|
242
|
+
abstract listByUser(userId: number): Promise<ISession[]>;
|
|
243
|
+
/**
|
|
244
|
+
* Deletes all session table data.
|
|
224
245
|
*/
|
|
225
246
|
abstract truncate(): Promise<void>;
|
|
226
247
|
/**
|
|
227
|
-
*
|
|
228
|
-
* Deletes all sessions for given user ( logs out user from all devices )
|
|
229
|
-
*
|
|
230
|
-
* @param user
|
|
248
|
+
* Sets the initial expiration on a freshly created session.
|
|
231
249
|
*/
|
|
232
|
-
|
|
250
|
+
protected applyInitialExpiration(s: ISession): void;
|
|
251
|
+
/**
|
|
252
|
+
* Sets the renewed expiration on a session being touched.
|
|
253
|
+
*/
|
|
254
|
+
protected applyRenewedExpiration(s: ISession): void;
|
|
255
|
+
/**
|
|
256
|
+
* True when the session carries an expiration in the past.
|
|
257
|
+
*/
|
|
258
|
+
protected isExpired(s: ISession): boolean;
|
|
233
259
|
}
|
|
234
260
|
export declare enum AthenticationErrorCodes {
|
|
235
261
|
E_USER_BANNED = 1,
|
|
@@ -238,6 +264,30 @@ export declare enum AthenticationErrorCodes {
|
|
|
238
264
|
E_LOGIN_ATTEMPTS_EXCEEDED = 4
|
|
239
265
|
}
|
|
240
266
|
export type PermissionType = 'readAny' | 'readOwn' | 'updateAny' | 'updateOwn' | 'deleteAny' | 'deleteOwn' | 'createAny' | 'createOwn';
|
|
267
|
+
/**
|
|
268
|
+
* Static a model may declare to constrain ONE operation, checked by
|
|
269
|
+
* `RbacModelPermissionMiddleware` before the generic `rbac` fallback.
|
|
270
|
+
*
|
|
271
|
+
* The hook receives the query builder as `this` and the acting user as its only argument,
|
|
272
|
+
* and is called only on the `:own` path — an `:any` grant short-circuits before it.
|
|
273
|
+
*
|
|
274
|
+
* ```ts
|
|
275
|
+
* class Entry extends ModelBase<Entry> {
|
|
276
|
+
* // fallback for whichever of read / update / delete has no specific hook
|
|
277
|
+
* static rbac(this: IWhereBuilder<Entry>, user: User) { ... }
|
|
278
|
+
* static rbacDelete(this: DeleteQueryBuilder<Entry>, user: User) { ... }
|
|
279
|
+
* }
|
|
280
|
+
* ```
|
|
281
|
+
*
|
|
282
|
+
* `rbacCreate` is deliberately excluded from the `rbac` fallback: `rbac` has only ever run
|
|
283
|
+
* on builders with a WHERE clause, so every existing implementation is where-shaped and
|
|
284
|
+
* `InsertQueryBuilder` has no `where`. See {@link RBAC_HOOK_FALLBACK}.
|
|
285
|
+
*/
|
|
286
|
+
export type RbacHookName = 'rbacRead' | 'rbacUpdate' | 'rbacDelete' | 'rbacCreate';
|
|
287
|
+
/**
|
|
288
|
+
* Name of the generic hook every operation except create falls back to.
|
|
289
|
+
*/
|
|
290
|
+
export declare const RBAC_HOOK_FALLBACK = "rbac";
|
|
241
291
|
export interface IRbacModelDescriptor extends IModelDescriptor {
|
|
242
292
|
RbacResource: string;
|
|
243
293
|
OwnerField: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../src/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../src/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,aAAa,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzI,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEjC,OAAO,QAAQ,cAAc,CAAC;IAC5B,UAAiB,YAAY;QAC3B;;;;;;;WA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GAAG,UAAU,GAAG,YAAY,GAAG,YAAY,GAAG,YAAY,CAAC;AAEnF;;GAEG;AACH,eAAO,MAAM,kBAAkB,SAAS,CAAC;AAEzC,MAAM,WAAW,oBAAqB,SAAQ,gBAAgB;IAC5D,YAAY,EAAE,MAAM,CAAC;IAErB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,8BAAsB,0BAA0B;aAC9B,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;CACjD;AAGD,qBAAa,WAAW,CAAC,CAAC;IACjB,IAAI,EAAE,IAAI,CAAC;IACX,cAAc,CAAC,EAAE,CAAC,CAAC;gBAEP,IAAI,EAAG,IAAI,EAAE,IAAI,CAAC,EAAI,CAAC;CAI3C;AAED;;;;;GAKG;AACH,8BAAsB,mBAAmB;aACvB,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAG,MAAM,GAAG,MAAM,GAAI,IAAI,GAAI,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;CACtF;AAGD,MAAM,WAAW,iBAAiB,CAAC,CAAC,GAAG,IAAI;IACzC,IAAI,CAAC,EAAE,CAAC,CAAC;IAET,OAAO,CAAC,EAAE,QAAQ,CAAC;IAEnB;;;;;KAKC;IACD,eAAe,CAAC,EAAE,cAAc,CAAC;IAEjC;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;OAIG;IACH,YAAY,CAAC,EAAE,CAAC,CAAC;IAEjB;;;;;OAKG;IACH,wBAAwB,CAAC,EAAE,OAAO,CAAC;CACpC"}
|
package/lib/cjs/interfaces.js
CHANGED
|
@@ -1,7 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UserProfileProvider = exports.UserProfile = exports.PasswordValidationProvider = exports.AthenticationErrorCodes = exports.SessionProvider = exports.FederatedAuthProvider = exports.AuthProvider = exports.PasswordProvider = void 0;
|
|
12
|
+
exports.UserProfileProvider = exports.UserProfile = exports.PasswordValidationProvider = exports.RBAC_HOOK_FALLBACK = exports.AthenticationErrorCodes = exports.SessionProvider = exports.FederatedAuthProvider = exports.AuthProvider = exports.PasswordProvider = exports.SessionExpirationProvider = void 0;
|
|
4
13
|
const di_1 = require("@spinajs/di");
|
|
14
|
+
const configuration_1 = require("@spinajs/configuration");
|
|
15
|
+
const luxon_1 = require("luxon");
|
|
16
|
+
/**
|
|
17
|
+
* Configurable session expiration strategy. Resolved by config service name at
|
|
18
|
+
* `rbac.session.expiration.service`, mirroring the `rbac.password` pattern.
|
|
19
|
+
*
|
|
20
|
+
* Units for all shipped strategies are MINUTES.
|
|
21
|
+
*/
|
|
22
|
+
class SessionExpirationProvider {
|
|
23
|
+
}
|
|
24
|
+
exports.SessionExpirationProvider = SessionExpirationProvider;
|
|
5
25
|
/**
|
|
6
26
|
* Service used for generating random password & for hash raw string
|
|
7
27
|
*/
|
|
@@ -28,8 +48,30 @@ class FederatedAuthProvider {
|
|
|
28
48
|
}
|
|
29
49
|
exports.FederatedAuthProvider = FederatedAuthProvider;
|
|
30
50
|
class SessionProvider extends di_1.AsyncService {
|
|
51
|
+
/**
|
|
52
|
+
* Sets the initial expiration on a freshly created session.
|
|
53
|
+
*/
|
|
54
|
+
applyInitialExpiration(s) {
|
|
55
|
+
s.Expiration = this.Expiration.initial(s);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Sets the renewed expiration on a session being touched.
|
|
59
|
+
*/
|
|
60
|
+
applyRenewedExpiration(s) {
|
|
61
|
+
s.Expiration = this.Expiration.renew(s);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* True when the session carries an expiration in the past.
|
|
65
|
+
*/
|
|
66
|
+
isExpired(s) {
|
|
67
|
+
return !!s.Expiration && s.Expiration <= luxon_1.DateTime.now();
|
|
68
|
+
}
|
|
31
69
|
}
|
|
32
70
|
exports.SessionProvider = SessionProvider;
|
|
71
|
+
__decorate([
|
|
72
|
+
(0, configuration_1.AutoinjectService)('rbac.session.expiration'),
|
|
73
|
+
__metadata("design:type", SessionExpirationProvider)
|
|
74
|
+
], SessionProvider.prototype, "Expiration", void 0);
|
|
33
75
|
var AthenticationErrorCodes;
|
|
34
76
|
(function (AthenticationErrorCodes) {
|
|
35
77
|
AthenticationErrorCodes[AthenticationErrorCodes["E_USER_BANNED"] = 1] = "E_USER_BANNED";
|
|
@@ -37,6 +79,10 @@ var AthenticationErrorCodes;
|
|
|
37
79
|
AthenticationErrorCodes[AthenticationErrorCodes["E_INVALID_CREDENTIALS"] = 3] = "E_INVALID_CREDENTIALS";
|
|
38
80
|
AthenticationErrorCodes[AthenticationErrorCodes["E_LOGIN_ATTEMPTS_EXCEEDED"] = 4] = "E_LOGIN_ATTEMPTS_EXCEEDED";
|
|
39
81
|
})(AthenticationErrorCodes || (exports.AthenticationErrorCodes = AthenticationErrorCodes = {}));
|
|
82
|
+
/**
|
|
83
|
+
* Name of the generic hook every operation except create falls back to.
|
|
84
|
+
*/
|
|
85
|
+
exports.RBAC_HOOK_FALLBACK = 'rbac';
|
|
40
86
|
/**
|
|
41
87
|
* Interface to provide implementation of password rule validation
|
|
42
88
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../src/interfaces.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../src/interfaces.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,oCAA2C;AAC3C,0DAA2D;AAE3D,iCAAiC;AAkEjC;;;;;GAKG;AACH,MAAsB,yBAAyB;CAU9C;AAVD,8DAUC;AAED;;GAEG;AACH,MAAsB,gBAAgB;CAsBrC;AAtBD,4CAsBC;AAED;;;;;GAKG;AACH,MAAsB,YAAY;CAgEjC;AAhED,oCAgEC;AAED;;;;;;GAMG;AACH,MAAsB,qBAAqB;CAwB1C;AAxBD,sDAwBC;AAED,MAAsB,eAA+C,SAAQ,iBAAY;IA8DvF;;OAEG;IACO,sBAAsB,CAAC,CAAW;QAC1C,CAAC,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAC5C,CAAC;IAED;;OAEG;IACO,sBAAsB,CAAC,CAAW;QAC1C,CAAC,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC1C,CAAC;IAED;;OAEG;IACO,SAAS,CAAC,CAAW;QAC7B,OAAO,CAAC,CAAC,CAAC,CAAC,UAAU,IAAI,CAAC,CAAC,UAAU,IAAI,gBAAQ,CAAC,GAAG,EAAE,CAAC;IAC1D,CAAC;CACF;AAlFD,0CAkFC;AA3EW;IADT,IAAA,iCAAiB,EAAC,yBAAyB,CAAC;8BACtB,yBAAyB;mDAAC;AA6EnD,IAAY,uBAKX;AALD,WAAY,uBAAuB;IACjC,uFAAiB,CAAA;IACjB,+FAAqB,CAAA;IACrB,uGAAyB,CAAA;IACzB,+GAA6B,CAAA;AAC/B,CAAC,EALW,uBAAuB,uCAAvB,uBAAuB,QAKlC;AAyBD;;GAEG;AACU,QAAA,kBAAkB,GAAG,MAAM,CAAC;AAQzC;;GAEG;AACH,MAAsB,0BAA0B;CAE/C;AAFD,gEAEC;AAGD,MAAa,WAAW;IAItB,YAAmB,IAAW,EAAE,IAAU;QACxC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;IAC7B,CAAC;CACF;AARD,kCAQC;AAED;;;;;GAKG;AACH,MAAsB,mBAAmB;CAExC;AAFD,kDAEC"}
|
package/lib/cjs/middleware.d.ts
CHANGED
|
@@ -1,10 +1,33 @@
|
|
|
1
1
|
import { QueryBuilder, QueryMiddleware } from '@spinajs/orm';
|
|
2
|
+
import { IRbacModelDescriptor, RbacHookName } from './interfaces.js';
|
|
2
3
|
import { AccessControl } from 'accesscontrol';
|
|
3
4
|
import { Log } from '@spinajs/log-common';
|
|
4
5
|
export declare class RbacModelPermissionMiddleware extends QueryMiddleware {
|
|
5
6
|
protected Log: Log;
|
|
6
7
|
protected Ac: AccessControl;
|
|
7
|
-
|
|
8
|
+
/**
|
|
9
|
+
* INSERT is enforced here rather than in `afterQueryCreation` because the row payload does
|
|
10
|
+
* not exist at construction time — `values()` is called afterwards and would overwrite an
|
|
11
|
+
* owner column stamped earlier. Reads and writes keep their where-clause injection at
|
|
12
|
+
* construction, where it has always been.
|
|
13
|
+
*/
|
|
14
|
+
beforeQueryExecution(builder: QueryBuilder<any>): Promise<void>;
|
|
8
15
|
afterQueryCreation(builder: QueryBuilder): void;
|
|
16
|
+
/**
|
|
17
|
+
* Everything both hooks need, or `undefined` when this query is not subject to a check.
|
|
18
|
+
*
|
|
19
|
+
* Shared so the two hooks cannot drift on who is exempt: no async context, no user, an
|
|
20
|
+
* explicit skip flag, a model with no `@Resource()`, or a declared `PermissionScope` that
|
|
21
|
+
* does not match this builder type.
|
|
22
|
+
*/
|
|
23
|
+
protected context(builder: QueryBuilder): {
|
|
24
|
+
descriptor: IRbacModelDescriptor;
|
|
25
|
+
resource: string;
|
|
26
|
+
canOwn: boolean;
|
|
27
|
+
canAny: boolean;
|
|
28
|
+
action: string;
|
|
29
|
+
hook: RbacHookName;
|
|
30
|
+
user: import("./index.js").User;
|
|
31
|
+
} | undefined;
|
|
9
32
|
}
|
|
10
33
|
//# sourceMappingURL=middleware.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/middleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAgF,YAAY,EAAE,eAAe,EAA0C,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/middleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAgF,YAAY,EAAE,eAAe,EAA0C,MAAM,cAAc,CAAC;AAEnL,OAAO,EAAqB,oBAAoB,EAAsC,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC5H,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C,OAAO,EAAE,GAAG,EAAU,MAAM,qBAAqB,CAAC;AAuFlD,qBACa,6BAA8B,SAAQ,eAAe;IAGhE,SAAS,CAAC,GAAG,EAAG,GAAG,CAAC;IAGpB,SAAS,CAAC,EAAE,EAAG,aAAa,CAAC;IAE7B;;;;;OAKG;IACG,oBAAoB,CAAC,OAAO,EAAE,YAAY,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IA8CrE,kBAAkB,CAAC,OAAO,EAAE,YAAY;IA8CxC;;;;;;OAMG;IACH,SAAS,CAAC,OAAO,CAAC,OAAO,EAAE,YAAY;;;;;;;;;CAoExC"}
|