@blimu/nestjs 1.1.1 → 1.1.4

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 (80) hide show
  1. package/dist/__tests__/example.test.cjs +17135 -0
  2. package/dist/__tests__/example.test.cjs.map +1 -0
  3. package/dist/__tests__/example.test.d.cts +2 -0
  4. package/dist/__tests__/example.test.d.ts +2 -0
  5. package/dist/__tests__/example.test.mjs +17134 -0
  6. package/dist/__tests__/example.test.mjs.map +1 -0
  7. package/dist/config/blimu.config.cjs +31 -0
  8. package/dist/config/blimu.config.cjs.map +1 -0
  9. package/dist/config/blimu.config.d.cts +11 -0
  10. package/dist/config/blimu.config.d.ts +8 -6
  11. package/dist/config/blimu.config.mjs +6 -0
  12. package/dist/config/blimu.config.mjs.map +1 -0
  13. package/dist/decorators/entitlement.decorator.cjs +178 -0
  14. package/dist/decorators/entitlement.decorator.cjs.map +1 -0
  15. package/dist/decorators/entitlement.decorator.d.cts +9 -0
  16. package/dist/decorators/entitlement.decorator.d.ts +9 -4
  17. package/dist/decorators/entitlement.decorator.mjs +161 -0
  18. package/dist/decorators/entitlement.decorator.mjs.map +1 -0
  19. package/dist/exceptions/blimu-forbidden.exception.cjs +86 -0
  20. package/dist/exceptions/blimu-forbidden.exception.cjs.map +1 -0
  21. package/dist/exceptions/blimu-forbidden.exception.d.cts +14 -0
  22. package/dist/exceptions/blimu-forbidden.exception.d.ts +6 -4
  23. package/dist/exceptions/blimu-forbidden.exception.mjs +61 -0
  24. package/dist/exceptions/blimu-forbidden.exception.mjs.map +1 -0
  25. package/dist/guards/entitlement.guard.cjs +174 -0
  26. package/dist/guards/entitlement.guard.cjs.map +1 -0
  27. package/dist/guards/entitlement.guard.d.cts +24 -0
  28. package/dist/guards/entitlement.guard.d.ts +12 -12
  29. package/dist/guards/entitlement.guard.mjs +154 -0
  30. package/dist/guards/entitlement.guard.mjs.map +1 -0
  31. package/dist/index.cjs +445 -0
  32. package/dist/index.cjs.map +1 -0
  33. package/dist/index.d.cts +9 -0
  34. package/dist/index.d.ts +9 -7
  35. package/dist/index.mjs +420 -0
  36. package/dist/index.mjs.map +1 -0
  37. package/dist/modules/blimu.module.cjs +413 -0
  38. package/dist/modules/blimu.module.cjs.map +1 -0
  39. package/dist/modules/blimu.module.d.cts +14 -0
  40. package/dist/modules/blimu.module.d.ts +11 -8
  41. package/dist/modules/blimu.module.mjs +398 -0
  42. package/dist/modules/blimu.module.mjs.map +1 -0
  43. package/dist/services/index.cjs +93 -0
  44. package/dist/services/index.cjs.map +1 -0
  45. package/dist/services/index.d.cts +2 -0
  46. package/dist/services/index.d.ts +2 -2
  47. package/dist/services/index.mjs +69 -0
  48. package/dist/services/index.mjs.map +1 -0
  49. package/dist/services/jwk.service.cjs +91 -0
  50. package/dist/services/jwk.service.cjs.map +1 -0
  51. package/dist/services/jwk.service.d.cts +12 -0
  52. package/dist/services/jwk.service.d.ts +5 -3
  53. package/dist/services/jwk.service.mjs +69 -0
  54. package/dist/services/jwk.service.mjs.map +1 -0
  55. package/package.json +34 -13
  56. package/dist/config/blimu.config.d.ts.map +0 -1
  57. package/dist/config/blimu.config.js +0 -5
  58. package/dist/config/blimu.config.js.map +0 -1
  59. package/dist/decorators/entitlement.decorator.d.ts.map +0 -1
  60. package/dist/decorators/entitlement.decorator.js +0 -10
  61. package/dist/decorators/entitlement.decorator.js.map +0 -1
  62. package/dist/exceptions/blimu-forbidden.exception.d.ts.map +0 -1
  63. package/dist/exceptions/blimu-forbidden.exception.js +0 -38
  64. package/dist/exceptions/blimu-forbidden.exception.js.map +0 -1
  65. package/dist/guards/entitlement.guard.d.ts.map +0 -1
  66. package/dist/guards/entitlement.guard.js +0 -82
  67. package/dist/guards/entitlement.guard.js.map +0 -1
  68. package/dist/index.d.ts.map +0 -1
  69. package/dist/index.js +0 -23
  70. package/dist/index.js.map +0 -1
  71. package/dist/modules/blimu.module.d.ts.map +0 -1
  72. package/dist/modules/blimu.module.js +0 -91
  73. package/dist/modules/blimu.module.js.map +0 -1
  74. package/dist/services/index.d.ts.map +0 -1
  75. package/dist/services/index.js +0 -18
  76. package/dist/services/index.js.map +0 -1
  77. package/dist/services/jwk.service.d.ts.map +0 -1
  78. package/dist/services/jwk.service.js +0 -59
  79. package/dist/services/jwk.service.js.map +0 -1
  80. package/dist/tsconfig.tsbuildinfo +0 -1
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/config/blimu.config.ts
21
+ var blimu_config_exports = {};
22
+ __export(blimu_config_exports, {
23
+ BLIMU_CONFIG: () => BLIMU_CONFIG
24
+ });
25
+ module.exports = __toCommonJS(blimu_config_exports);
26
+ var BLIMU_CONFIG = /* @__PURE__ */ Symbol("BLIMU_CONFIG");
27
+ // Annotate the CommonJS export names for ESM import in node:
28
+ 0 && (module.exports = {
29
+ BLIMU_CONFIG
30
+ });
31
+ //# sourceMappingURL=blimu.config.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/config/blimu.config.ts"],"sourcesContent":["/**\n * Configuration interface for Blimu NestJS integration\n */\nexport interface BlimuConfig<TRequest = unknown> {\n global?: boolean | undefined;\n /**\n * The API secret key for authenticating with Blimu Runtime API\n */\n apiKey: string;\n\n /**\n * The base URL for the Blimu Runtime API\n * @default 'https://api.blimu.dev'\n */\n baseURL?: string | undefined;\n\n /**\n * Environment ID for the Blimu environment\n * This will be used in future versions for environment-specific configurations\n */\n environmentId?: string | undefined;\n\n /**\n * Request timeout in milliseconds\n * @default 30000\n */\n timeoutMs?: number | undefined;\n\n /**\n * Function to extract user ID from the request\n *\n * This function is called by the EntitlementGuard to determine which user\n * to check entitlements for. It should return the user ID as a string.\n *\n * @param request - The incoming HTTP request\n * @returns The user ID as a string, or a Promise that resolves to the user ID\n *\n * @example\n * ```typescript\n * // Extract from JWT token in Authorization header\n * getUserId: (req) => {\n * const token = req.headers.authorization?.replace('Bearer ', '');\n * const decoded = jwt.verify(token, secret);\n * return decoded.sub;\n * }\n *\n * // Extract from request.user (common with Passport.js)\n * getUserId: (req) => req.user?.id\n *\n * // Extract from custom header\n * getUserId: (req) => req.headers['x-user-id']\n * ```\n */\n getUserId: (request: TRequest) => string | Promise<string>;\n}\n\n/**\n * Injection token for Blimu configuration\n */\nexport const BLIMU_CONFIG = Symbol('BLIMU_CONFIG');\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA2DO,IAAM,eAAe,uBAAO,cAAc;","names":[]}
@@ -0,0 +1,11 @@
1
+ interface BlimuConfig<TRequest = unknown> {
2
+ global?: boolean | undefined;
3
+ apiKey: string;
4
+ baseURL?: string | undefined;
5
+ environmentId?: string | undefined;
6
+ timeoutMs?: number | undefined;
7
+ getUserId: (request: TRequest) => string | Promise<string>;
8
+ }
9
+ declare const BLIMU_CONFIG: unique symbol;
10
+
11
+ export { BLIMU_CONFIG, type BlimuConfig };
@@ -1,9 +1,11 @@
1
- export interface BlimuConfig<TRequest = any> {
1
+ interface BlimuConfig<TRequest = unknown> {
2
+ global?: boolean | undefined;
2
3
  apiKey: string;
3
- baseURL?: string;
4
- environmentId?: string;
5
- timeoutMs?: number;
4
+ baseURL?: string | undefined;
5
+ environmentId?: string | undefined;
6
+ timeoutMs?: number | undefined;
6
7
  getUserId: (request: TRequest) => string | Promise<string>;
7
8
  }
8
- export declare const BLIMU_CONFIG: unique symbol;
9
- //# sourceMappingURL=blimu.config.d.ts.map
9
+ declare const BLIMU_CONFIG: unique symbol;
10
+
11
+ export { BLIMU_CONFIG, type BlimuConfig };
@@ -0,0 +1,6 @@
1
+ // src/config/blimu.config.ts
2
+ var BLIMU_CONFIG = /* @__PURE__ */ Symbol("BLIMU_CONFIG");
3
+ export {
4
+ BLIMU_CONFIG
5
+ };
6
+ //# sourceMappingURL=blimu.config.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/config/blimu.config.ts"],"sourcesContent":["/**\n * Configuration interface for Blimu NestJS integration\n */\nexport interface BlimuConfig<TRequest = unknown> {\n global?: boolean | undefined;\n /**\n * The API secret key for authenticating with Blimu Runtime API\n */\n apiKey: string;\n\n /**\n * The base URL for the Blimu Runtime API\n * @default 'https://api.blimu.dev'\n */\n baseURL?: string | undefined;\n\n /**\n * Environment ID for the Blimu environment\n * This will be used in future versions for environment-specific configurations\n */\n environmentId?: string | undefined;\n\n /**\n * Request timeout in milliseconds\n * @default 30000\n */\n timeoutMs?: number | undefined;\n\n /**\n * Function to extract user ID from the request\n *\n * This function is called by the EntitlementGuard to determine which user\n * to check entitlements for. It should return the user ID as a string.\n *\n * @param request - The incoming HTTP request\n * @returns The user ID as a string, or a Promise that resolves to the user ID\n *\n * @example\n * ```typescript\n * // Extract from JWT token in Authorization header\n * getUserId: (req) => {\n * const token = req.headers.authorization?.replace('Bearer ', '');\n * const decoded = jwt.verify(token, secret);\n * return decoded.sub;\n * }\n *\n * // Extract from request.user (common with Passport.js)\n * getUserId: (req) => req.user?.id\n *\n * // Extract from custom header\n * getUserId: (req) => req.headers['x-user-id']\n * ```\n */\n getUserId: (request: TRequest) => string | Promise<string>;\n}\n\n/**\n * Injection token for Blimu configuration\n */\nexport const BLIMU_CONFIG = Symbol('BLIMU_CONFIG');\n"],"mappings":";AA2DO,IAAM,eAAe,uBAAO,cAAc;","names":[]}
@@ -0,0 +1,178 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var __decorateClass = (decorators, target, key, kind) => {
20
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
21
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
22
+ if (decorator = decorators[i])
23
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
24
+ if (kind && result) __defProp(target, key, result);
25
+ return result;
26
+ };
27
+ var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
28
+
29
+ // src/decorators/entitlement.decorator.ts
30
+ var entitlement_decorator_exports = {};
31
+ __export(entitlement_decorator_exports, {
32
+ Entitlement: () => Entitlement
33
+ });
34
+ module.exports = __toCommonJS(entitlement_decorator_exports);
35
+ var import_common3 = require("@nestjs/common");
36
+
37
+ // src/guards/entitlement.guard.ts
38
+ var import_common2 = require("@nestjs/common");
39
+ var import_reflect_metadata = require("reflect-metadata");
40
+
41
+ // src/exceptions/blimu-forbidden.exception.ts
42
+ var import_common = require("@nestjs/common");
43
+ var BlimuForbiddenException = class _BlimuForbiddenException extends import_common.ForbiddenException {
44
+ /**
45
+ * The entitlement check result containing detailed failure information
46
+ */
47
+ entitlementResult;
48
+ /**
49
+ * The entitlement key that was checked
50
+ */
51
+ entitlementKey;
52
+ /**
53
+ * The resource ID that was checked
54
+ */
55
+ resourceId;
56
+ /**
57
+ * The user ID that was checked
58
+ */
59
+ userId;
60
+ constructor(entitlementResult, entitlementKey, resourceId, userId) {
61
+ const message = _BlimuForbiddenException.buildMessage(entitlementResult, entitlementKey);
62
+ super({
63
+ message,
64
+ entitlementResult,
65
+ entitlementKey,
66
+ resourceId,
67
+ userId
68
+ });
69
+ this.entitlementResult = entitlementResult;
70
+ this.entitlementKey = entitlementKey;
71
+ this.resourceId = resourceId;
72
+ this.userId = userId;
73
+ }
74
+ /**
75
+ * Builds a user-friendly error message from the entitlement check result
76
+ */
77
+ static buildMessage(result, entitlementKey) {
78
+ const reasons = [];
79
+ if (result.roles && !result.roles.allowed) {
80
+ reasons.push(
81
+ `Insufficient roles. Required: ${result.roles.allowedRoles?.join(", ") || "unknown"}. User has: ${result.roles.userRoles?.join(", ") || "none"}.`
82
+ );
83
+ }
84
+ if (result.plans && !result.plans.allowed) {
85
+ reasons.push(
86
+ `Plan restriction. Required plans: ${result.plans.allowedPlans?.join(", ") || "unknown"}. Current plan: ${result.plans.plan || "none"}.`
87
+ );
88
+ }
89
+ if (result.limit && !result.limit.allowed) {
90
+ reasons.push(`Usage limit exceeded. ${result.limit.reason || "Limit has been reached"}.`);
91
+ }
92
+ if (reasons.length === 0) {
93
+ return `Access denied for entitlement: ${entitlementKey}`;
94
+ }
95
+ return `Access denied for entitlement "${entitlementKey}": ${reasons.join(" ")}`;
96
+ }
97
+ };
98
+
99
+ // src/guards/entitlement.guard.ts
100
+ var import_backend = require("@blimu/backend");
101
+
102
+ // src/config/blimu.config.ts
103
+ var BLIMU_CONFIG = /* @__PURE__ */ Symbol("BLIMU_CONFIG");
104
+
105
+ // src/guards/entitlement.guard.ts
106
+ var ENTITLEMENT_METADATA_KEY = /* @__PURE__ */ Symbol("entitlement");
107
+ var SetEntitlementMetadata = (entitlementKey, getEntitlementInfo) => (0, import_common2.SetMetadata)(ENTITLEMENT_METADATA_KEY, {
108
+ entitlementKey,
109
+ getEntitlementInfo
110
+ });
111
+ var EntitlementGuard = class {
112
+ constructor(config, runtime) {
113
+ this.config = config;
114
+ this.runtime = runtime;
115
+ }
116
+ async canActivate(context) {
117
+ const request = context.switchToHttp().getRequest();
118
+ const handler = context.getHandler();
119
+ const metadata = Reflect.getMetadata(ENTITLEMENT_METADATA_KEY, handler);
120
+ if (!metadata) {
121
+ return true;
122
+ }
123
+ let userId;
124
+ try {
125
+ userId = await this.config.getUserId(request);
126
+ } catch {
127
+ throw new import_common2.ForbiddenException("Failed to extract user ID from request");
128
+ }
129
+ if (!userId) {
130
+ throw new import_common2.ForbiddenException("User ID is required for entitlement check");
131
+ }
132
+ const entitlementInfo = await metadata.getEntitlementInfo(request);
133
+ if (!entitlementInfo?.resourceId) {
134
+ throw new import_common2.ForbiddenException("Resource ID is required for entitlement check");
135
+ }
136
+ try {
137
+ const result = await this.runtime.entitlements.checkEntitlement({
138
+ userId,
139
+ entitlement: metadata.entitlementKey,
140
+ resourceId: entitlementInfo.resourceId,
141
+ ...entitlementInfo.amount !== void 0 ? { amount: entitlementInfo.amount } : {}
142
+ });
143
+ if (!result.allowed) {
144
+ throw new BlimuForbiddenException(
145
+ result,
146
+ metadata.entitlementKey,
147
+ entitlementInfo.resourceId,
148
+ userId
149
+ );
150
+ }
151
+ return true;
152
+ } catch (error) {
153
+ if (error instanceof BlimuForbiddenException || error instanceof import_common2.ForbiddenException) {
154
+ throw error;
155
+ }
156
+ console.error("Entitlement check failed:", error);
157
+ throw new import_common2.ForbiddenException("Failed to verify entitlements");
158
+ }
159
+ }
160
+ };
161
+ EntitlementGuard = __decorateClass([
162
+ (0, import_common2.Injectable)(),
163
+ __decorateParam(0, (0, import_common2.Inject)(BLIMU_CONFIG)),
164
+ __decorateParam(1, (0, import_common2.Inject)(import_backend.Blimu))
165
+ ], EntitlementGuard);
166
+
167
+ // src/decorators/entitlement.decorator.ts
168
+ var Entitlement = (entitlementKey, getEntitlementInfo) => {
169
+ return (0, import_common3.applyDecorators)(
170
+ SetEntitlementMetadata(entitlementKey, getEntitlementInfo),
171
+ (0, import_common3.UseGuards)(EntitlementGuard)
172
+ );
173
+ };
174
+ // Annotate the CommonJS export names for ESM import in node:
175
+ 0 && (module.exports = {
176
+ Entitlement
177
+ });
178
+ //# sourceMappingURL=entitlement.decorator.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/decorators/entitlement.decorator.ts","../../src/guards/entitlement.guard.ts","../../src/exceptions/blimu-forbidden.exception.ts","../../src/config/blimu.config.ts"],"sourcesContent":["import { applyDecorators, UseGuards } from '@nestjs/common';\nimport {\n EntitlementGuard,\n SetEntitlementMetadata,\n type EntitlementInfo,\n} from '../guards/entitlement.guard';\nimport type { EntitlementType } from '@blimu/types';\n\n/**\n * Decorator to check if the authenticated user has a specific entitlement on a resource.\n *\n * This decorator combines the entitlement metadata setting and guard application\n * to provide a clean, declarative way to protect routes with entitlement checks.\n *\n * @param entitlementKey - The entitlement key to check (e.g., 'brand:read', 'organization:create_workspace')\n * @param getEntitlementInfo - Function that returns entitlement information including resourceId and optionally amount for usage limits\n *\n * @example\n * Basic usage with path parameter:\n * ```typescript\n * @Get('/:resourceId')\n * @Entitlement('brand:read', (req) => ({ resourceId: req.params.resourceId }))\n * async getBrand(@Param('resourceId') resourceId: string) {\n * // User is guaranteed to have 'brand:read' entitlement on this resource\n * }\n * ```\n *\n * @example\n * Using with typed parameters:\n * ```typescript\n * @Get('/:resourceType/:resourceId')\n * @Entitlement('workspace:delete', (req) => ({ resourceId: req.params.resourceId }))\n * async deleteResource(@Param() params: ResourceParamsDto) {\n * // User is guaranteed to have 'workspace:delete' entitlement\n * }\n * ```\n *\n * @example\n * Complex resource ID extraction:\n * ```typescript\n * @Post('/organizations/:orgId/workspaces')\n * @Entitlement('organization:create_workspace', (req) => {\n * const params = req.params as { orgId: string };\n * return { resourceId: params.orgId };\n * })\n * async createWorkspace(@Param() params: CreateWorkspaceParamsDto, @Body() body: CreateWorkspaceDto) {\n * // User is guaranteed to have 'organization:create_workspace' entitlement on the organization\n * }\n * ```\n *\n * @example\n * With usage limit consumption:\n * ```typescript\n * @Post('/api-calls')\n * @Entitlement('organization:make_api_call', (req) => ({\n * resourceId: req.params.orgId,\n * amount: req.body.apiCallsCount, // Amount to consume from usage limit\n * }))\n * async makeApiCalls(@Param('orgId') orgId: string, @Body() body: { apiCallsCount: number }) {\n * // User is guaranteed to have 'organization:make_api_call' entitlement\n * // and sufficient usage limit balance\n * }\n * ```\n *\n * @example\n * Async entitlement info extraction (e.g., from database):\n * ```typescript\n * @Delete('/items/:itemId')\n * @Entitlement('workspace:delete_item', async (req) => {\n * // You could fetch the workspace ID from your database\n * const item = await itemService.findById(req.params.itemId);\n * return { resourceId: item.workspaceId };\n * })\n * async deleteItem(@Param('itemId') itemId: string) {\n * // User is guaranteed to have 'workspace:delete_item' entitlement on the item's workspace\n * }\n * ```\n *\n * @example\n * Using with custom request type:\n * ```typescript\n * interface AuthenticatedRequest {\n * user: { id: string; email: string };\n * }\n *\n * @Get('/:resourceId')\n * @Entitlement<AuthenticatedRequest>('brand:read', (req) => {\n * // req is typed as AuthenticatedRequest, so req.user is properly typed\n * console.log(req.user.email); // TypeScript knows this exists\n * return { resourceId: req.params.resourceId };\n * })\n * async getBrand(@Param('resourceId') resourceId: string) {\n * // User is guaranteed to have 'brand:read' entitlement on this resource\n * }\n * ```\n */\nexport const Entitlement = <TRequest = unknown>(\n entitlementKey: EntitlementType,\n getEntitlementInfo: (request: TRequest) => EntitlementInfo | Promise<EntitlementInfo>,\n): MethodDecorator => {\n return applyDecorators(\n SetEntitlementMetadata<TRequest>(entitlementKey, getEntitlementInfo),\n UseGuards(EntitlementGuard),\n );\n};\n","import {\n type CanActivate,\n type ExecutionContext,\n ForbiddenException,\n Injectable,\n SetMetadata,\n Inject,\n} from '@nestjs/common';\nimport 'reflect-metadata';\n\nimport type { EntitlementType } from '@blimu/types';\nimport { BlimuForbiddenException } from '../exceptions/blimu-forbidden.exception';\nimport { Blimu } from '@blimu/backend';\nimport { BLIMU_CONFIG, type BlimuConfig } from 'config/blimu.config';\n\nexport const ENTITLEMENT_KEY = 'entitlement';\nexport const ENTITLEMENT_METADATA_KEY = Symbol('entitlement');\n\n/**\n * Entitlement information returned by the getEntitlementInfo callback\n */\nexport interface EntitlementInfo {\n resourceId: string;\n amount?: number; // Amount to check against usage limit (for consumption)\n}\n\n/**\n * Metadata interface for entitlement checks\n */\nexport interface EntitlementMetadata<TRequest = unknown> {\n entitlementKey: EntitlementType;\n getEntitlementInfo: (request: TRequest) => EntitlementInfo | Promise<EntitlementInfo>;\n}\n\n/**\n * Sets entitlement metadata for a route handler\n * @internal This is used internally by the @Entitlement decorator\n */\nexport const SetEntitlementMetadata = <TRequest = unknown>(\n entitlementKey: string,\n getEntitlementInfo: (request: TRequest) => EntitlementInfo | Promise<EntitlementInfo>,\n): MethodDecorator =>\n SetMetadata(ENTITLEMENT_METADATA_KEY, {\n entitlementKey,\n getEntitlementInfo,\n } as EntitlementMetadata<TRequest>);\n\n/**\n * Guard that checks if the authenticated user has the required entitlement on a resource\n *\n * This guard automatically:\n * 1. Extracts the user from the request\n * 2. Extracts the resource ID using the provided extractor function\n * 3. Calls the Blimu Runtime API to check entitlements\n * 4. Allows or denies access based on the result\n */\n@Injectable()\nexport class EntitlementGuard<TRequest = unknown> implements CanActivate {\n constructor(\n @Inject(BLIMU_CONFIG)\n private readonly config: BlimuConfig<TRequest>,\n @Inject(Blimu)\n private readonly runtime: Blimu,\n ) {}\n\n async canActivate(context: ExecutionContext): Promise<boolean> {\n const request = context.switchToHttp().getRequest<TRequest>();\n const handler = context.getHandler();\n const metadata = Reflect.getMetadata(ENTITLEMENT_METADATA_KEY, handler) as\n | EntitlementMetadata<TRequest>\n | undefined;\n\n if (!metadata) {\n // No entitlement check required\n return true;\n }\n\n // Extract user ID using the configured getUserId function\n let userId: string;\n try {\n userId = await this.config.getUserId(request);\n } catch {\n throw new ForbiddenException('Failed to extract user ID from request');\n }\n\n if (!userId) {\n throw new ForbiddenException('User ID is required for entitlement check');\n }\n\n // Extract entitlement info from request\n const entitlementInfo = await metadata.getEntitlementInfo(request);\n\n if (!entitlementInfo?.resourceId) {\n throw new ForbiddenException('Resource ID is required for entitlement check');\n }\n\n try {\n // Check entitlement\n const result = await this.runtime.entitlements.checkEntitlement({\n userId,\n entitlement: metadata.entitlementKey,\n resourceId: entitlementInfo.resourceId,\n ...(entitlementInfo.amount !== undefined ? { amount: entitlementInfo.amount } : {}),\n });\n\n if (!result.allowed) {\n throw new BlimuForbiddenException(\n result,\n metadata.entitlementKey,\n entitlementInfo.resourceId,\n userId,\n );\n }\n\n return true;\n } catch (error) {\n if (error instanceof BlimuForbiddenException || error instanceof ForbiddenException) {\n throw error;\n }\n\n // Log the error for debugging but don't expose internal details\n console.error('Entitlement check failed:', error);\n throw new ForbiddenException('Failed to verify entitlements');\n }\n }\n}\n","import { ForbiddenException } from '@nestjs/common';\nimport type { Schema } from '@blimu/backend';\nimport type { EntitlementType } from '@blimu/types';\n/**\n * Custom exception for Blimu entitlement check failures\n *\n * This exception extends NestJS's ForbiddenException and includes\n * the typed EntitlementCheckResult, providing detailed information\n * about why the entitlement check failed (roles, plans, limits, etc.)\n */\nexport class BlimuForbiddenException extends ForbiddenException {\n /**\n * The entitlement check result containing detailed failure information\n */\n public readonly entitlementResult: Schema.EntitlementCheckResult;\n\n /**\n * The entitlement key that was checked\n */\n public readonly entitlementKey: EntitlementType;\n\n /**\n * The resource ID that was checked\n */\n public readonly resourceId: string;\n\n /**\n * The user ID that was checked\n */\n public readonly userId: string;\n\n constructor(\n entitlementResult: Schema.EntitlementCheckResult,\n entitlementKey: EntitlementType,\n resourceId: string,\n userId: string,\n ) {\n // Create a user-friendly message based on the failure reason\n const message = BlimuForbiddenException.buildMessage(entitlementResult, entitlementKey);\n\n super({\n message,\n entitlementResult,\n entitlementKey,\n resourceId,\n userId,\n });\n\n this.entitlementResult = entitlementResult;\n this.entitlementKey = entitlementKey;\n this.resourceId = resourceId;\n this.userId = userId;\n }\n\n /**\n * Builds a user-friendly error message from the entitlement check result\n */\n private static buildMessage(\n result: Schema.EntitlementCheckResult,\n entitlementKey: EntitlementType,\n ): string {\n const reasons: string[] = [];\n\n if (result.roles && !result.roles.allowed) {\n reasons.push(\n `Insufficient roles. Required: ${result.roles.allowedRoles?.join(', ') || 'unknown'}. User has: ${result.roles.userRoles?.join(', ') || 'none'}.`,\n );\n }\n\n if (result.plans && !result.plans.allowed) {\n reasons.push(\n `Plan restriction. Required plans: ${result.plans.allowedPlans?.join(', ') || 'unknown'}. Current plan: ${result.plans.plan || 'none'}.`,\n );\n }\n\n if (result.limit && !result.limit.allowed) {\n reasons.push(`Usage limit exceeded. ${result.limit.reason || 'Limit has been reached'}.`);\n }\n\n if (reasons.length === 0) {\n return `Access denied for entitlement: ${entitlementKey}`;\n }\n\n return `Access denied for entitlement \"${entitlementKey}\": ${reasons.join(' ')}`;\n }\n}\n","/**\n * Configuration interface for Blimu NestJS integration\n */\nexport interface BlimuConfig<TRequest = unknown> {\n global?: boolean | undefined;\n /**\n * The API secret key for authenticating with Blimu Runtime API\n */\n apiKey: string;\n\n /**\n * The base URL for the Blimu Runtime API\n * @default 'https://api.blimu.dev'\n */\n baseURL?: string | undefined;\n\n /**\n * Environment ID for the Blimu environment\n * This will be used in future versions for environment-specific configurations\n */\n environmentId?: string | undefined;\n\n /**\n * Request timeout in milliseconds\n * @default 30000\n */\n timeoutMs?: number | undefined;\n\n /**\n * Function to extract user ID from the request\n *\n * This function is called by the EntitlementGuard to determine which user\n * to check entitlements for. It should return the user ID as a string.\n *\n * @param request - The incoming HTTP request\n * @returns The user ID as a string, or a Promise that resolves to the user ID\n *\n * @example\n * ```typescript\n * // Extract from JWT token in Authorization header\n * getUserId: (req) => {\n * const token = req.headers.authorization?.replace('Bearer ', '');\n * const decoded = jwt.verify(token, secret);\n * return decoded.sub;\n * }\n *\n * // Extract from request.user (common with Passport.js)\n * getUserId: (req) => req.user?.id\n *\n * // Extract from custom header\n * getUserId: (req) => req.headers['x-user-id']\n * ```\n */\n getUserId: (request: TRequest) => string | Promise<string>;\n}\n\n/**\n * Injection token for Blimu configuration\n */\nexport const BLIMU_CONFIG = Symbol('BLIMU_CONFIG');\n"],"mappings":"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","names":["import_common","import_common"]}
@@ -0,0 +1,9 @@
1
+ import { EntitlementInfo } from '../guards/entitlement.guard.cjs';
2
+ import { EntitlementType } from '@blimu/types';
3
+ import '@nestjs/common';
4
+ import '@blimu/backend';
5
+ import '../config/blimu.config.cjs';
6
+
7
+ declare const Entitlement: <TRequest = unknown>(entitlementKey: EntitlementType, getEntitlementInfo: (request: TRequest) => EntitlementInfo | Promise<EntitlementInfo>) => MethodDecorator;
8
+
9
+ export { Entitlement };
@@ -1,4 +1,9 @@
1
- import { EntitlementInfo } from '../guards/entitlement.guard';
2
- import type { EntitlementType } from '@blimu/types';
3
- export declare const Entitlement: <TRequest = any>(entitlementKey: EntitlementType, getEntitlementInfo: (request: TRequest) => EntitlementInfo | Promise<EntitlementInfo>) => <TFunction extends Function, Y>(target: TFunction | object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
4
- //# sourceMappingURL=entitlement.decorator.d.ts.map
1
+ import { EntitlementInfo } from '../guards/entitlement.guard.js';
2
+ import { EntitlementType } from '@blimu/types';
3
+ import '@nestjs/common';
4
+ import '@blimu/backend';
5
+ import '../config/blimu.config.js';
6
+
7
+ declare const Entitlement: <TRequest = unknown>(entitlementKey: EntitlementType, getEntitlementInfo: (request: TRequest) => EntitlementInfo | Promise<EntitlementInfo>) => MethodDecorator;
8
+
9
+ export { Entitlement };
@@ -0,0 +1,161 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __decorateClass = (decorators, target, key, kind) => {
4
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
5
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
6
+ if (decorator = decorators[i])
7
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
8
+ if (kind && result) __defProp(target, key, result);
9
+ return result;
10
+ };
11
+ var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
12
+
13
+ // src/decorators/entitlement.decorator.ts
14
+ import { applyDecorators, UseGuards } from "@nestjs/common";
15
+
16
+ // src/guards/entitlement.guard.ts
17
+ import {
18
+ ForbiddenException as ForbiddenException2,
19
+ Injectable,
20
+ SetMetadata,
21
+ Inject
22
+ } from "@nestjs/common";
23
+ import "reflect-metadata";
24
+
25
+ // src/exceptions/blimu-forbidden.exception.ts
26
+ import { ForbiddenException } from "@nestjs/common";
27
+ var BlimuForbiddenException = class _BlimuForbiddenException extends ForbiddenException {
28
+ /**
29
+ * The entitlement check result containing detailed failure information
30
+ */
31
+ entitlementResult;
32
+ /**
33
+ * The entitlement key that was checked
34
+ */
35
+ entitlementKey;
36
+ /**
37
+ * The resource ID that was checked
38
+ */
39
+ resourceId;
40
+ /**
41
+ * The user ID that was checked
42
+ */
43
+ userId;
44
+ constructor(entitlementResult, entitlementKey, resourceId, userId) {
45
+ const message = _BlimuForbiddenException.buildMessage(entitlementResult, entitlementKey);
46
+ super({
47
+ message,
48
+ entitlementResult,
49
+ entitlementKey,
50
+ resourceId,
51
+ userId
52
+ });
53
+ this.entitlementResult = entitlementResult;
54
+ this.entitlementKey = entitlementKey;
55
+ this.resourceId = resourceId;
56
+ this.userId = userId;
57
+ }
58
+ /**
59
+ * Builds a user-friendly error message from the entitlement check result
60
+ */
61
+ static buildMessage(result, entitlementKey) {
62
+ const reasons = [];
63
+ if (result.roles && !result.roles.allowed) {
64
+ reasons.push(
65
+ `Insufficient roles. Required: ${result.roles.allowedRoles?.join(", ") || "unknown"}. User has: ${result.roles.userRoles?.join(", ") || "none"}.`
66
+ );
67
+ }
68
+ if (result.plans && !result.plans.allowed) {
69
+ reasons.push(
70
+ `Plan restriction. Required plans: ${result.plans.allowedPlans?.join(", ") || "unknown"}. Current plan: ${result.plans.plan || "none"}.`
71
+ );
72
+ }
73
+ if (result.limit && !result.limit.allowed) {
74
+ reasons.push(`Usage limit exceeded. ${result.limit.reason || "Limit has been reached"}.`);
75
+ }
76
+ if (reasons.length === 0) {
77
+ return `Access denied for entitlement: ${entitlementKey}`;
78
+ }
79
+ return `Access denied for entitlement "${entitlementKey}": ${reasons.join(" ")}`;
80
+ }
81
+ };
82
+
83
+ // src/guards/entitlement.guard.ts
84
+ import { Blimu } from "@blimu/backend";
85
+
86
+ // src/config/blimu.config.ts
87
+ var BLIMU_CONFIG = /* @__PURE__ */ Symbol("BLIMU_CONFIG");
88
+
89
+ // src/guards/entitlement.guard.ts
90
+ var ENTITLEMENT_METADATA_KEY = /* @__PURE__ */ Symbol("entitlement");
91
+ var SetEntitlementMetadata = (entitlementKey, getEntitlementInfo) => SetMetadata(ENTITLEMENT_METADATA_KEY, {
92
+ entitlementKey,
93
+ getEntitlementInfo
94
+ });
95
+ var EntitlementGuard = class {
96
+ constructor(config, runtime) {
97
+ this.config = config;
98
+ this.runtime = runtime;
99
+ }
100
+ async canActivate(context) {
101
+ const request = context.switchToHttp().getRequest();
102
+ const handler = context.getHandler();
103
+ const metadata = Reflect.getMetadata(ENTITLEMENT_METADATA_KEY, handler);
104
+ if (!metadata) {
105
+ return true;
106
+ }
107
+ let userId;
108
+ try {
109
+ userId = await this.config.getUserId(request);
110
+ } catch {
111
+ throw new ForbiddenException2("Failed to extract user ID from request");
112
+ }
113
+ if (!userId) {
114
+ throw new ForbiddenException2("User ID is required for entitlement check");
115
+ }
116
+ const entitlementInfo = await metadata.getEntitlementInfo(request);
117
+ if (!entitlementInfo?.resourceId) {
118
+ throw new ForbiddenException2("Resource ID is required for entitlement check");
119
+ }
120
+ try {
121
+ const result = await this.runtime.entitlements.checkEntitlement({
122
+ userId,
123
+ entitlement: metadata.entitlementKey,
124
+ resourceId: entitlementInfo.resourceId,
125
+ ...entitlementInfo.amount !== void 0 ? { amount: entitlementInfo.amount } : {}
126
+ });
127
+ if (!result.allowed) {
128
+ throw new BlimuForbiddenException(
129
+ result,
130
+ metadata.entitlementKey,
131
+ entitlementInfo.resourceId,
132
+ userId
133
+ );
134
+ }
135
+ return true;
136
+ } catch (error) {
137
+ if (error instanceof BlimuForbiddenException || error instanceof ForbiddenException2) {
138
+ throw error;
139
+ }
140
+ console.error("Entitlement check failed:", error);
141
+ throw new ForbiddenException2("Failed to verify entitlements");
142
+ }
143
+ }
144
+ };
145
+ EntitlementGuard = __decorateClass([
146
+ Injectable(),
147
+ __decorateParam(0, Inject(BLIMU_CONFIG)),
148
+ __decorateParam(1, Inject(Blimu))
149
+ ], EntitlementGuard);
150
+
151
+ // src/decorators/entitlement.decorator.ts
152
+ var Entitlement = (entitlementKey, getEntitlementInfo) => {
153
+ return applyDecorators(
154
+ SetEntitlementMetadata(entitlementKey, getEntitlementInfo),
155
+ UseGuards(EntitlementGuard)
156
+ );
157
+ };
158
+ export {
159
+ Entitlement
160
+ };
161
+ //# sourceMappingURL=entitlement.decorator.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/decorators/entitlement.decorator.ts","../../src/guards/entitlement.guard.ts","../../src/exceptions/blimu-forbidden.exception.ts","../../src/config/blimu.config.ts"],"sourcesContent":["import { applyDecorators, UseGuards } from '@nestjs/common';\nimport {\n EntitlementGuard,\n SetEntitlementMetadata,\n type EntitlementInfo,\n} from '../guards/entitlement.guard';\nimport type { EntitlementType } from '@blimu/types';\n\n/**\n * Decorator to check if the authenticated user has a specific entitlement on a resource.\n *\n * This decorator combines the entitlement metadata setting and guard application\n * to provide a clean, declarative way to protect routes with entitlement checks.\n *\n * @param entitlementKey - The entitlement key to check (e.g., 'brand:read', 'organization:create_workspace')\n * @param getEntitlementInfo - Function that returns entitlement information including resourceId and optionally amount for usage limits\n *\n * @example\n * Basic usage with path parameter:\n * ```typescript\n * @Get('/:resourceId')\n * @Entitlement('brand:read', (req) => ({ resourceId: req.params.resourceId }))\n * async getBrand(@Param('resourceId') resourceId: string) {\n * // User is guaranteed to have 'brand:read' entitlement on this resource\n * }\n * ```\n *\n * @example\n * Using with typed parameters:\n * ```typescript\n * @Get('/:resourceType/:resourceId')\n * @Entitlement('workspace:delete', (req) => ({ resourceId: req.params.resourceId }))\n * async deleteResource(@Param() params: ResourceParamsDto) {\n * // User is guaranteed to have 'workspace:delete' entitlement\n * }\n * ```\n *\n * @example\n * Complex resource ID extraction:\n * ```typescript\n * @Post('/organizations/:orgId/workspaces')\n * @Entitlement('organization:create_workspace', (req) => {\n * const params = req.params as { orgId: string };\n * return { resourceId: params.orgId };\n * })\n * async createWorkspace(@Param() params: CreateWorkspaceParamsDto, @Body() body: CreateWorkspaceDto) {\n * // User is guaranteed to have 'organization:create_workspace' entitlement on the organization\n * }\n * ```\n *\n * @example\n * With usage limit consumption:\n * ```typescript\n * @Post('/api-calls')\n * @Entitlement('organization:make_api_call', (req) => ({\n * resourceId: req.params.orgId,\n * amount: req.body.apiCallsCount, // Amount to consume from usage limit\n * }))\n * async makeApiCalls(@Param('orgId') orgId: string, @Body() body: { apiCallsCount: number }) {\n * // User is guaranteed to have 'organization:make_api_call' entitlement\n * // and sufficient usage limit balance\n * }\n * ```\n *\n * @example\n * Async entitlement info extraction (e.g., from database):\n * ```typescript\n * @Delete('/items/:itemId')\n * @Entitlement('workspace:delete_item', async (req) => {\n * // You could fetch the workspace ID from your database\n * const item = await itemService.findById(req.params.itemId);\n * return { resourceId: item.workspaceId };\n * })\n * async deleteItem(@Param('itemId') itemId: string) {\n * // User is guaranteed to have 'workspace:delete_item' entitlement on the item's workspace\n * }\n * ```\n *\n * @example\n * Using with custom request type:\n * ```typescript\n * interface AuthenticatedRequest {\n * user: { id: string; email: string };\n * }\n *\n * @Get('/:resourceId')\n * @Entitlement<AuthenticatedRequest>('brand:read', (req) => {\n * // req is typed as AuthenticatedRequest, so req.user is properly typed\n * console.log(req.user.email); // TypeScript knows this exists\n * return { resourceId: req.params.resourceId };\n * })\n * async getBrand(@Param('resourceId') resourceId: string) {\n * // User is guaranteed to have 'brand:read' entitlement on this resource\n * }\n * ```\n */\nexport const Entitlement = <TRequest = unknown>(\n entitlementKey: EntitlementType,\n getEntitlementInfo: (request: TRequest) => EntitlementInfo | Promise<EntitlementInfo>,\n): MethodDecorator => {\n return applyDecorators(\n SetEntitlementMetadata<TRequest>(entitlementKey, getEntitlementInfo),\n UseGuards(EntitlementGuard),\n );\n};\n","import {\n type CanActivate,\n type ExecutionContext,\n ForbiddenException,\n Injectable,\n SetMetadata,\n Inject,\n} from '@nestjs/common';\nimport 'reflect-metadata';\n\nimport type { EntitlementType } from '@blimu/types';\nimport { BlimuForbiddenException } from '../exceptions/blimu-forbidden.exception';\nimport { Blimu } from '@blimu/backend';\nimport { BLIMU_CONFIG, type BlimuConfig } from 'config/blimu.config';\n\nexport const ENTITLEMENT_KEY = 'entitlement';\nexport const ENTITLEMENT_METADATA_KEY = Symbol('entitlement');\n\n/**\n * Entitlement information returned by the getEntitlementInfo callback\n */\nexport interface EntitlementInfo {\n resourceId: string;\n amount?: number; // Amount to check against usage limit (for consumption)\n}\n\n/**\n * Metadata interface for entitlement checks\n */\nexport interface EntitlementMetadata<TRequest = unknown> {\n entitlementKey: EntitlementType;\n getEntitlementInfo: (request: TRequest) => EntitlementInfo | Promise<EntitlementInfo>;\n}\n\n/**\n * Sets entitlement metadata for a route handler\n * @internal This is used internally by the @Entitlement decorator\n */\nexport const SetEntitlementMetadata = <TRequest = unknown>(\n entitlementKey: string,\n getEntitlementInfo: (request: TRequest) => EntitlementInfo | Promise<EntitlementInfo>,\n): MethodDecorator =>\n SetMetadata(ENTITLEMENT_METADATA_KEY, {\n entitlementKey,\n getEntitlementInfo,\n } as EntitlementMetadata<TRequest>);\n\n/**\n * Guard that checks if the authenticated user has the required entitlement on a resource\n *\n * This guard automatically:\n * 1. Extracts the user from the request\n * 2. Extracts the resource ID using the provided extractor function\n * 3. Calls the Blimu Runtime API to check entitlements\n * 4. Allows or denies access based on the result\n */\n@Injectable()\nexport class EntitlementGuard<TRequest = unknown> implements CanActivate {\n constructor(\n @Inject(BLIMU_CONFIG)\n private readonly config: BlimuConfig<TRequest>,\n @Inject(Blimu)\n private readonly runtime: Blimu,\n ) {}\n\n async canActivate(context: ExecutionContext): Promise<boolean> {\n const request = context.switchToHttp().getRequest<TRequest>();\n const handler = context.getHandler();\n const metadata = Reflect.getMetadata(ENTITLEMENT_METADATA_KEY, handler) as\n | EntitlementMetadata<TRequest>\n | undefined;\n\n if (!metadata) {\n // No entitlement check required\n return true;\n }\n\n // Extract user ID using the configured getUserId function\n let userId: string;\n try {\n userId = await this.config.getUserId(request);\n } catch {\n throw new ForbiddenException('Failed to extract user ID from request');\n }\n\n if (!userId) {\n throw new ForbiddenException('User ID is required for entitlement check');\n }\n\n // Extract entitlement info from request\n const entitlementInfo = await metadata.getEntitlementInfo(request);\n\n if (!entitlementInfo?.resourceId) {\n throw new ForbiddenException('Resource ID is required for entitlement check');\n }\n\n try {\n // Check entitlement\n const result = await this.runtime.entitlements.checkEntitlement({\n userId,\n entitlement: metadata.entitlementKey,\n resourceId: entitlementInfo.resourceId,\n ...(entitlementInfo.amount !== undefined ? { amount: entitlementInfo.amount } : {}),\n });\n\n if (!result.allowed) {\n throw new BlimuForbiddenException(\n result,\n metadata.entitlementKey,\n entitlementInfo.resourceId,\n userId,\n );\n }\n\n return true;\n } catch (error) {\n if (error instanceof BlimuForbiddenException || error instanceof ForbiddenException) {\n throw error;\n }\n\n // Log the error for debugging but don't expose internal details\n console.error('Entitlement check failed:', error);\n throw new ForbiddenException('Failed to verify entitlements');\n }\n }\n}\n","import { ForbiddenException } from '@nestjs/common';\nimport type { Schema } from '@blimu/backend';\nimport type { EntitlementType } from '@blimu/types';\n/**\n * Custom exception for Blimu entitlement check failures\n *\n * This exception extends NestJS's ForbiddenException and includes\n * the typed EntitlementCheckResult, providing detailed information\n * about why the entitlement check failed (roles, plans, limits, etc.)\n */\nexport class BlimuForbiddenException extends ForbiddenException {\n /**\n * The entitlement check result containing detailed failure information\n */\n public readonly entitlementResult: Schema.EntitlementCheckResult;\n\n /**\n * The entitlement key that was checked\n */\n public readonly entitlementKey: EntitlementType;\n\n /**\n * The resource ID that was checked\n */\n public readonly resourceId: string;\n\n /**\n * The user ID that was checked\n */\n public readonly userId: string;\n\n constructor(\n entitlementResult: Schema.EntitlementCheckResult,\n entitlementKey: EntitlementType,\n resourceId: string,\n userId: string,\n ) {\n // Create a user-friendly message based on the failure reason\n const message = BlimuForbiddenException.buildMessage(entitlementResult, entitlementKey);\n\n super({\n message,\n entitlementResult,\n entitlementKey,\n resourceId,\n userId,\n });\n\n this.entitlementResult = entitlementResult;\n this.entitlementKey = entitlementKey;\n this.resourceId = resourceId;\n this.userId = userId;\n }\n\n /**\n * Builds a user-friendly error message from the entitlement check result\n */\n private static buildMessage(\n result: Schema.EntitlementCheckResult,\n entitlementKey: EntitlementType,\n ): string {\n const reasons: string[] = [];\n\n if (result.roles && !result.roles.allowed) {\n reasons.push(\n `Insufficient roles. Required: ${result.roles.allowedRoles?.join(', ') || 'unknown'}. User has: ${result.roles.userRoles?.join(', ') || 'none'}.`,\n );\n }\n\n if (result.plans && !result.plans.allowed) {\n reasons.push(\n `Plan restriction. Required plans: ${result.plans.allowedPlans?.join(', ') || 'unknown'}. Current plan: ${result.plans.plan || 'none'}.`,\n );\n }\n\n if (result.limit && !result.limit.allowed) {\n reasons.push(`Usage limit exceeded. ${result.limit.reason || 'Limit has been reached'}.`);\n }\n\n if (reasons.length === 0) {\n return `Access denied for entitlement: ${entitlementKey}`;\n }\n\n return `Access denied for entitlement \"${entitlementKey}\": ${reasons.join(' ')}`;\n }\n}\n","/**\n * Configuration interface for Blimu NestJS integration\n */\nexport interface BlimuConfig<TRequest = unknown> {\n global?: boolean | undefined;\n /**\n * The API secret key for authenticating with Blimu Runtime API\n */\n apiKey: string;\n\n /**\n * The base URL for the Blimu Runtime API\n * @default 'https://api.blimu.dev'\n */\n baseURL?: string | undefined;\n\n /**\n * Environment ID for the Blimu environment\n * This will be used in future versions for environment-specific configurations\n */\n environmentId?: string | undefined;\n\n /**\n * Request timeout in milliseconds\n * @default 30000\n */\n timeoutMs?: number | undefined;\n\n /**\n * Function to extract user ID from the request\n *\n * This function is called by the EntitlementGuard to determine which user\n * to check entitlements for. It should return the user ID as a string.\n *\n * @param request - The incoming HTTP request\n * @returns The user ID as a string, or a Promise that resolves to the user ID\n *\n * @example\n * ```typescript\n * // Extract from JWT token in Authorization header\n * getUserId: (req) => {\n * const token = req.headers.authorization?.replace('Bearer ', '');\n * const decoded = jwt.verify(token, secret);\n * return decoded.sub;\n * }\n *\n * // Extract from request.user (common with Passport.js)\n * getUserId: (req) => req.user?.id\n *\n * // Extract from custom header\n * getUserId: (req) => req.headers['x-user-id']\n * ```\n */\n getUserId: (request: TRequest) => string | Promise<string>;\n}\n\n/**\n * Injection token for Blimu configuration\n */\nexport const BLIMU_CONFIG = Symbol('BLIMU_CONFIG');\n"],"mappings":"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","names":["ForbiddenException","ForbiddenException"]}
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/exceptions/blimu-forbidden.exception.ts
21
+ var blimu_forbidden_exception_exports = {};
22
+ __export(blimu_forbidden_exception_exports, {
23
+ BlimuForbiddenException: () => BlimuForbiddenException
24
+ });
25
+ module.exports = __toCommonJS(blimu_forbidden_exception_exports);
26
+ var import_common = require("@nestjs/common");
27
+ var BlimuForbiddenException = class _BlimuForbiddenException extends import_common.ForbiddenException {
28
+ /**
29
+ * The entitlement check result containing detailed failure information
30
+ */
31
+ entitlementResult;
32
+ /**
33
+ * The entitlement key that was checked
34
+ */
35
+ entitlementKey;
36
+ /**
37
+ * The resource ID that was checked
38
+ */
39
+ resourceId;
40
+ /**
41
+ * The user ID that was checked
42
+ */
43
+ userId;
44
+ constructor(entitlementResult, entitlementKey, resourceId, userId) {
45
+ const message = _BlimuForbiddenException.buildMessage(entitlementResult, entitlementKey);
46
+ super({
47
+ message,
48
+ entitlementResult,
49
+ entitlementKey,
50
+ resourceId,
51
+ userId
52
+ });
53
+ this.entitlementResult = entitlementResult;
54
+ this.entitlementKey = entitlementKey;
55
+ this.resourceId = resourceId;
56
+ this.userId = userId;
57
+ }
58
+ /**
59
+ * Builds a user-friendly error message from the entitlement check result
60
+ */
61
+ static buildMessage(result, entitlementKey) {
62
+ const reasons = [];
63
+ if (result.roles && !result.roles.allowed) {
64
+ reasons.push(
65
+ `Insufficient roles. Required: ${result.roles.allowedRoles?.join(", ") || "unknown"}. User has: ${result.roles.userRoles?.join(", ") || "none"}.`
66
+ );
67
+ }
68
+ if (result.plans && !result.plans.allowed) {
69
+ reasons.push(
70
+ `Plan restriction. Required plans: ${result.plans.allowedPlans?.join(", ") || "unknown"}. Current plan: ${result.plans.plan || "none"}.`
71
+ );
72
+ }
73
+ if (result.limit && !result.limit.allowed) {
74
+ reasons.push(`Usage limit exceeded. ${result.limit.reason || "Limit has been reached"}.`);
75
+ }
76
+ if (reasons.length === 0) {
77
+ return `Access denied for entitlement: ${entitlementKey}`;
78
+ }
79
+ return `Access denied for entitlement "${entitlementKey}": ${reasons.join(" ")}`;
80
+ }
81
+ };
82
+ // Annotate the CommonJS export names for ESM import in node:
83
+ 0 && (module.exports = {
84
+ BlimuForbiddenException
85
+ });
86
+ //# sourceMappingURL=blimu-forbidden.exception.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/exceptions/blimu-forbidden.exception.ts"],"sourcesContent":["import { ForbiddenException } from '@nestjs/common';\nimport type { Schema } from '@blimu/backend';\nimport type { EntitlementType } from '@blimu/types';\n/**\n * Custom exception for Blimu entitlement check failures\n *\n * This exception extends NestJS's ForbiddenException and includes\n * the typed EntitlementCheckResult, providing detailed information\n * about why the entitlement check failed (roles, plans, limits, etc.)\n */\nexport class BlimuForbiddenException extends ForbiddenException {\n /**\n * The entitlement check result containing detailed failure information\n */\n public readonly entitlementResult: Schema.EntitlementCheckResult;\n\n /**\n * The entitlement key that was checked\n */\n public readonly entitlementKey: EntitlementType;\n\n /**\n * The resource ID that was checked\n */\n public readonly resourceId: string;\n\n /**\n * The user ID that was checked\n */\n public readonly userId: string;\n\n constructor(\n entitlementResult: Schema.EntitlementCheckResult,\n entitlementKey: EntitlementType,\n resourceId: string,\n userId: string,\n ) {\n // Create a user-friendly message based on the failure reason\n const message = BlimuForbiddenException.buildMessage(entitlementResult, entitlementKey);\n\n super({\n message,\n entitlementResult,\n entitlementKey,\n resourceId,\n userId,\n });\n\n this.entitlementResult = entitlementResult;\n this.entitlementKey = entitlementKey;\n this.resourceId = resourceId;\n this.userId = userId;\n }\n\n /**\n * Builds a user-friendly error message from the entitlement check result\n */\n private static buildMessage(\n result: Schema.EntitlementCheckResult,\n entitlementKey: EntitlementType,\n ): string {\n const reasons: string[] = [];\n\n if (result.roles && !result.roles.allowed) {\n reasons.push(\n `Insufficient roles. Required: ${result.roles.allowedRoles?.join(', ') || 'unknown'}. User has: ${result.roles.userRoles?.join(', ') || 'none'}.`,\n );\n }\n\n if (result.plans && !result.plans.allowed) {\n reasons.push(\n `Plan restriction. Required plans: ${result.plans.allowedPlans?.join(', ') || 'unknown'}. Current plan: ${result.plans.plan || 'none'}.`,\n );\n }\n\n if (result.limit && !result.limit.allowed) {\n reasons.push(`Usage limit exceeded. ${result.limit.reason || 'Limit has been reached'}.`);\n }\n\n if (reasons.length === 0) {\n return `Access denied for entitlement: ${entitlementKey}`;\n }\n\n return `Access denied for entitlement \"${entitlementKey}\": ${reasons.join(' ')}`;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAmC;AAU5B,IAAM,0BAAN,MAAM,iCAAgC,iCAAmB;AAAA;AAAA;AAAA;AAAA,EAI9C;AAAA;AAAA;AAAA;AAAA,EAKA;AAAA;AAAA;AAAA;AAAA,EAKA;AAAA;AAAA;AAAA;AAAA,EAKA;AAAA,EAEhB,YACE,mBACA,gBACA,YACA,QACA;AAEA,UAAM,UAAU,yBAAwB,aAAa,mBAAmB,cAAc;AAEtF,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAED,SAAK,oBAAoB;AACzB,SAAK,iBAAiB;AACtB,SAAK,aAAa;AAClB,SAAK,SAAS;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA,EAKA,OAAe,aACb,QACA,gBACQ;AACR,UAAM,UAAoB,CAAC;AAE3B,QAAI,OAAO,SAAS,CAAC,OAAO,MAAM,SAAS;AACzC,cAAQ;AAAA,QACN,iCAAiC,OAAO,MAAM,cAAc,KAAK,IAAI,KAAK,SAAS,eAAe,OAAO,MAAM,WAAW,KAAK,IAAI,KAAK,MAAM;AAAA,MAChJ;AAAA,IACF;AAEA,QAAI,OAAO,SAAS,CAAC,OAAO,MAAM,SAAS;AACzC,cAAQ;AAAA,QACN,qCAAqC,OAAO,MAAM,cAAc,KAAK,IAAI,KAAK,SAAS,mBAAmB,OAAO,MAAM,QAAQ,MAAM;AAAA,MACvI;AAAA,IACF;AAEA,QAAI,OAAO,SAAS,CAAC,OAAO,MAAM,SAAS;AACzC,cAAQ,KAAK,yBAAyB,OAAO,MAAM,UAAU,wBAAwB,GAAG;AAAA,IAC1F;AAEA,QAAI,QAAQ,WAAW,GAAG;AACxB,aAAO,kCAAkC,cAAc;AAAA,IACzD;AAEA,WAAO,kCAAkC,cAAc,MAAM,QAAQ,KAAK,GAAG,CAAC;AAAA,EAChF;AACF;","names":[]}
@@ -0,0 +1,14 @@
1
+ import { ForbiddenException } from '@nestjs/common';
2
+ import { Schema } from '@blimu/backend';
3
+ import { EntitlementType } from '@blimu/types';
4
+
5
+ declare class BlimuForbiddenException extends ForbiddenException {
6
+ readonly entitlementResult: Schema.EntitlementCheckResult;
7
+ readonly entitlementKey: EntitlementType;
8
+ readonly resourceId: string;
9
+ readonly userId: string;
10
+ constructor(entitlementResult: Schema.EntitlementCheckResult, entitlementKey: EntitlementType, resourceId: string, userId: string);
11
+ private static buildMessage;
12
+ }
13
+
14
+ export { BlimuForbiddenException };