@nest-boot/auth 8.0.7-beta.2 → 8.0.7-beta.3

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 (53) hide show
  1. package/README.md +16 -2
  2. package/dist/{abilities/auth.ability.d.ts → auth.ability.d.ts} +3 -1
  3. package/dist/auth.ability.js +23 -0
  4. package/dist/auth.ability.js.map +1 -0
  5. package/dist/auth.guard.js +3 -3
  6. package/dist/auth.guard.js.map +1 -1
  7. package/dist/features/invitations/invitation.service.js +13 -13
  8. package/dist/features/invitations/invitation.service.js.map +1 -1
  9. package/dist/index.d.ts +4 -4
  10. package/dist/index.js +4 -4
  11. package/dist/index.js.map +1 -1
  12. package/dist/infrastructure/auth-ability.factory.d.ts +1 -1
  13. package/dist/infrastructure/auth-ability.factory.js +1 -1
  14. package/dist/infrastructure/auth-ability.factory.js.map +1 -1
  15. package/dist/infrastructure/request-identity.js +1 -1
  16. package/dist/infrastructure/request-identity.js.map +1 -1
  17. package/dist/resolvers/auth.resolver.js +2 -2
  18. package/dist/resolvers/auth.resolver.js.map +1 -1
  19. package/dist/services/member.service.js +24 -24
  20. package/dist/services/member.service.js.map +1 -1
  21. package/dist/services/session.service.js +9 -9
  22. package/dist/services/session.service.js.map +1 -1
  23. package/dist/services/user-api-key.service.js +11 -11
  24. package/dist/services/user-api-key.service.js.map +1 -1
  25. package/dist/services/user.service.js +26 -26
  26. package/dist/services/user.service.js.map +1 -1
  27. package/dist/services/workspace-api-key.service.js +11 -11
  28. package/dist/services/workspace-api-key.service.js.map +1 -1
  29. package/dist/services/workspace.service.js +10 -10
  30. package/dist/services/workspace.service.js.map +1 -1
  31. package/dist/tsconfig.tsbuildinfo +1 -1
  32. package/dist/utils/authorize.util.d.ts +3 -0
  33. package/dist/utils/authorize.util.js +6 -0
  34. package/dist/utils/authorize.util.js.map +1 -0
  35. package/dist/utils/build-request-ability.util.d.ts +1 -1
  36. package/dist/utils/can.util.d.ts +1 -1
  37. package/dist/utils/can.util.js +3 -5
  38. package/dist/utils/can.util.js.map +1 -1
  39. package/dist/utils/get-auth-ability.util.d.ts +6 -0
  40. package/dist/utils/get-auth-ability.util.js +19 -0
  41. package/dist/utils/get-auth-ability.util.js.map +1 -0
  42. package/package.json +10 -10
  43. package/dist/abilities/auth.ability.js +0 -13
  44. package/dist/abilities/auth.ability.js.map +0 -1
  45. package/dist/abilities/index.d.ts +0 -1
  46. package/dist/abilities/index.js +0 -2
  47. package/dist/abilities/index.js.map +0 -1
  48. package/dist/utils/assert-can.util.d.ts +0 -3
  49. package/dist/utils/assert-can.util.js +0 -8
  50. package/dist/utils/assert-can.util.js.map +0 -1
  51. package/dist/utils/get-ability.util.d.ts +0 -5
  52. package/dist/utils/get-ability.util.js +0 -20
  53. package/dist/utils/get-ability.util.js.map +0 -1
@@ -0,0 +1,3 @@
1
+ import type { Subject } from "@casl/ability";
2
+ /** Throws ForbiddenException unless the current request permits the action. */
3
+ export declare function authorize(action: string, subject: Subject, field?: string): void;
@@ -0,0 +1,6 @@
1
+ import { getAuthAbility } from "./get-auth-ability.util.js";
2
+ /** Throws ForbiddenException unless the current request permits the action. */
3
+ export function authorize(action, subject, field) {
4
+ getAuthAbility().authorize(action, subject, field);
5
+ }
6
+ //# sourceMappingURL=authorize.util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authorize.util.js","sourceRoot":"","sources":["../../src/utils/authorize.util.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAE5D,+EAA+E;AAC/E,MAAM,UAAU,SAAS,CACvB,MAAc,EACd,OAAgB,EAChB,KAAc;IAEd,cAAc,EAAE,CAAC,SAAS,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;AACrD,CAAC"}
@@ -1,4 +1,4 @@
1
- import type { AuthAbility } from "../abilities/auth.ability.js";
1
+ import type { AuthAbility } from "../auth.ability.js";
2
2
  import type { AuthModuleOptions } from "../auth-module-options.interface.js";
3
3
  /** Builds one ability from the current identity and credential-limited permission snapshot. */
4
4
  export declare function buildRequestAbility(options: AuthModuleOptions): AuthAbility;
@@ -1,3 +1,3 @@
1
1
  import type { Subject } from "@casl/ability";
2
- /** Checks an action, object, or field against the current request ability. */
2
+ /** Checks the current request's ability on every call. */
3
3
  export declare function can(action: string, subject: Subject, field?: string): boolean;
@@ -1,9 +1,7 @@
1
- import { readRequestAbility } from "./get-ability.util.js";
2
- /** Checks an action, object, or field against the current request ability. */
1
+ import { getAuthAbility } from "./get-auth-ability.util.js";
2
+ /** Checks the current request's ability on every call. */
3
3
  export function can(action, subject, field) {
4
- const ability = readRequestAbility();
5
- if (!ability)
6
- return false;
4
+ const ability = getAuthAbility();
7
5
  return field === undefined
8
6
  ? ability.can(action, subject)
9
7
  : ability.can(action, subject, field);
@@ -1 +1 @@
1
- {"version":3,"file":"can.util.js","sourceRoot":"","sources":["../../src/utils/can.util.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAE3D,8EAA8E;AAC9E,MAAM,UAAU,GAAG,CAAC,MAAc,EAAE,OAAgB,EAAE,KAAc;IAClE,MAAM,OAAO,GAAG,kBAAkB,EAAE,CAAC;IACrC,IAAI,CAAC,OAAO;QAAE,OAAO,KAAK,CAAC;IAC3B,OAAO,KAAK,KAAK,SAAS;QACxB,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC;QAC9B,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;AAC1C,CAAC"}
1
+ {"version":3,"file":"can.util.js","sourceRoot":"","sources":["../../src/utils/can.util.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAE5D,0DAA0D;AAC1D,MAAM,UAAU,GAAG,CAAC,MAAc,EAAE,OAAgB,EAAE,KAAc;IAClE,MAAM,OAAO,GAAG,cAAc,EAAE,CAAC;IACjC,OAAO,KAAK,KAAK,SAAS;QACxB,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC;QAC9B,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;AAC1C,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { AuthAbility } from "../auth.ability.js";
2
+ /**
3
+ * Returns the current request's prepared ability or throws ForbiddenException.
4
+ * Retrieve the instance again after identity changes; do not cache it across requests.
5
+ */
6
+ export declare function getAuthAbility(): AuthAbility;
@@ -0,0 +1,19 @@
1
+ import { RequestContext } from "@nest-boot/request-context";
2
+ import { ForbiddenException } from "@nestjs/common";
3
+ import { AuthAbility } from "../auth.ability.js";
4
+ import { User } from "../entities/user.entity.js";
5
+ import { getCurrentApiKey } from "./get-current-api-key.util.js";
6
+ /**
7
+ * Returns the current request's prepared ability or throws ForbiddenException.
8
+ * Retrieve the instance again after identity changes; do not cache it across requests.
9
+ */
10
+ export function getAuthAbility() {
11
+ if (!RequestContext.isActive() ||
12
+ (!RequestContext.get(User) && !getCurrentApiKey()))
13
+ throw new ForbiddenException("Permission ability is not available");
14
+ const ability = RequestContext.get(AuthAbility);
15
+ if (!ability)
16
+ throw new ForbiddenException("Permission ability is not available");
17
+ return ability;
18
+ }
19
+ //# sourceMappingURL=get-auth-ability.util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-auth-ability.util.js","sourceRoot":"","sources":["../../src/utils/get-auth-ability.util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAEjE;;;GAGG;AACH,MAAM,UAAU,cAAc;IAC5B,IACE,CAAC,cAAc,CAAC,QAAQ,EAAE;QAC1B,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAElD,MAAM,IAAI,kBAAkB,CAAC,qCAAqC,CAAC,CAAC;IACtE,MAAM,OAAO,GAAG,cAAc,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAChD,IAAI,CAAC,OAAO;QACV,MAAM,IAAI,kBAAkB,CAAC,qCAAqC,CAAC,CAAC;IACtE,OAAO,OAAO,CAAC;AACjB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nest-boot/auth",
3
- "version": "8.0.7-beta.2",
3
+ "version": "8.0.7-beta.3",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/nest-boot/nest-boot.git",
@@ -52,15 +52,15 @@
52
52
  "graphql": "^16.11.0",
53
53
  "zod": "^4.3.6",
54
54
  "@nest-boot/eslint-config": "^8.0.2-beta.0",
55
- "@nest-boot/graphql-connection": "^8.0.2-beta.1",
56
- "@nest-boot/mailer": "^8.0.2-beta.0",
57
- "@nest-boot/hash": "^8.0.2-beta.0",
58
55
  "@nest-boot/eslint-plugin": "^8.0.1-beta.1",
59
- "@nest-boot/middleware": "^8.0.2-beta.0",
56
+ "@nest-boot/graphql-connection": "^8.0.2-beta.1",
60
57
  "@nest-boot/tsconfig": "^8.0.0-beta.4",
58
+ "@nest-boot/graphql": "^8.0.2-beta.0",
61
59
  "@nest-boot/request-context": "^8.0.2-beta.0",
62
60
  "@nest-boot/validator": "^8.0.5-beta.0",
63
- "@nest-boot/graphql": "^8.0.2-beta.0"
61
+ "@nest-boot/hash": "^8.0.2-beta.0",
62
+ "@nest-boot/mailer": "^8.0.2-beta.0",
63
+ "@nest-boot/middleware": "^8.0.2-beta.0"
64
64
  },
65
65
  "peerDependencies": {
66
66
  "@casl/ability": "^7.0.0",
@@ -77,12 +77,12 @@
77
77
  "graphql": "^16.0.0",
78
78
  "zod": "^4.0.0",
79
79
  "@nest-boot/graphql-connection": "^8.0.2-beta.1",
80
- "@nest-boot/middleware": "^8.0.2-beta.0",
81
- "@nest-boot/hash": "^8.0.2-beta.0",
82
80
  "@nest-boot/mailer": "^8.0.2-beta.0",
81
+ "@nest-boot/hash": "^8.0.2-beta.0",
82
+ "@nest-boot/request-context": "^8.0.2-beta.0",
83
83
  "@nest-boot/validator": "^8.0.5-beta.0",
84
- "@nest-boot/graphql": "^8.0.2-beta.0",
85
- "@nest-boot/request-context": "^8.0.2-beta.0"
84
+ "@nest-boot/middleware": "^8.0.2-beta.0",
85
+ "@nest-boot/graphql": "^8.0.2-beta.0"
86
86
  },
87
87
  "publishConfig": {
88
88
  "access": "public"
@@ -1,13 +0,0 @@
1
- import { Ability, fieldPatternMatcher, mongoQueryMatcher, } from "@casl/ability";
2
- /** CASL ability for the authenticated request and its selected workspace. */
3
- export class AuthAbility extends Ability {
4
- /** Creates an ability with CASL's Mongo-style condition matching. */
5
- constructor(rules = [], options = {}) {
6
- super(rules, {
7
- conditionsMatcher: mongoQueryMatcher,
8
- fieldMatcher: fieldPatternMatcher,
9
- ...options,
10
- });
11
- }
12
- }
13
- //# sourceMappingURL=auth.ability.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"auth.ability.js","sourceRoot":"","sources":["../../src/abilities/auth.ability.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAGP,mBAAmB,EAEnB,iBAAiB,GAElB,MAAM,eAAe,CAAC;AAEvB,6EAA6E;AAC7E,MAAM,OAAO,WAAY,SAAQ,OAAiC;IAChE,qEAAqE;IACrE,YACE,QAAiD,EAAE,EACnD,UAAoD,EAAE;QAEtD,KAAK,CAAC,KAAK,EAAE;YACX,iBAAiB,EAAE,iBAAiB;YACpC,YAAY,EAAE,mBAAmB;YACjC,GAAG,OAAO;SACX,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -1 +0,0 @@
1
- export * from "./auth.ability.js";
@@ -1,2 +0,0 @@
1
- export * from "./auth.ability.js";
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/abilities/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
@@ -1,3 +0,0 @@
1
- import type { Subject } from "@casl/ability";
2
- /** Throws unless the current request ability permits the action, object, or field. */
3
- export declare function assertCan(action: string, subject: Subject, field?: string): void;
@@ -1,8 +0,0 @@
1
- import { ForbiddenException } from "@nestjs/common";
2
- import { can } from "./can.util.js";
3
- /** Throws unless the current request ability permits the action, object, or field. */
4
- export function assertCan(action, subject, field) {
5
- if (!can(action, subject, field))
6
- throw new ForbiddenException(`You are not allowed to ${action} this resource`);
7
- }
8
- //# sourceMappingURL=assert-can.util.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"assert-can.util.js","sourceRoot":"","sources":["../../src/utils/assert-can.util.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC,sFAAsF;AACtF,MAAM,UAAU,SAAS,CACvB,MAAc,EACd,OAAgB,EAChB,KAAc;IAEd,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC;QAC9B,MAAM,IAAI,kBAAkB,CAC1B,0BAA0B,MAAM,gBAAgB,CACjD,CAAC;AACN,CAAC"}
@@ -1,5 +0,0 @@
1
- import { AuthAbility } from "../abilities/auth.ability.js";
2
- /** Reads the prepared ability only while its authenticated identity is available. @internal */
3
- export declare function readRequestAbility(): AuthAbility | null;
4
- /** Reads the current request ability, rejecting missing identity or authorization context. */
5
- export declare function getAbility(): AuthAbility;
@@ -1,20 +0,0 @@
1
- import { RequestContext } from "@nest-boot/request-context";
2
- import { ForbiddenException } from "@nestjs/common";
3
- import { AuthAbility } from "../abilities/auth.ability.js";
4
- import { User } from "../entities/user.entity.js";
5
- import { getCurrentApiKey } from "./get-current-api-key.util.js";
6
- /** Reads the prepared ability only while its authenticated identity is available. @internal */
7
- export function readRequestAbility() {
8
- if (!RequestContext.isActive() ||
9
- (!RequestContext.get(User) && !getCurrentApiKey()))
10
- return null;
11
- return RequestContext.get(AuthAbility) ?? null;
12
- }
13
- /** Reads the current request ability, rejecting missing identity or authorization context. */
14
- export function getAbility() {
15
- const ability = readRequestAbility();
16
- if (!ability)
17
- throw new ForbiddenException("Permission ability is not available");
18
- return ability;
19
- }
20
- //# sourceMappingURL=get-ability.util.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-ability.util.js","sourceRoot":"","sources":["../../src/utils/get-ability.util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAEjE,+FAA+F;AAC/F,MAAM,UAAU,kBAAkB;IAChC,IACE,CAAC,cAAc,CAAC,QAAQ,EAAE;QAC1B,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAElD,OAAO,IAAI,CAAC;IACd,OAAO,cAAc,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,IAAI,CAAC;AACjD,CAAC;AAED,8FAA8F;AAC9F,MAAM,UAAU,UAAU;IACxB,MAAM,OAAO,GAAG,kBAAkB,EAAE,CAAC;IACrC,IAAI,CAAC,OAAO;QACV,MAAM,IAAI,kBAAkB,CAAC,qCAAqC,CAAC,CAAC;IACtE,OAAO,OAAO,CAAC;AACjB,CAAC"}