@blimu/nestjs 1.1.0 → 1.1.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.
- package/dist/__tests__/example.test.cjs +17135 -0
- package/dist/__tests__/example.test.cjs.map +1 -0
- package/dist/__tests__/example.test.d.cts +2 -0
- package/dist/__tests__/example.test.d.ts +2 -0
- package/dist/__tests__/example.test.mjs +17134 -0
- package/dist/__tests__/example.test.mjs.map +1 -0
- package/dist/config/blimu.config.cjs +31 -0
- package/dist/config/blimu.config.cjs.map +1 -0
- package/dist/config/blimu.config.d.cts +11 -0
- package/dist/config/blimu.config.d.ts +8 -6
- package/dist/config/blimu.config.mjs +6 -0
- package/dist/config/blimu.config.mjs.map +1 -0
- package/dist/decorators/entitlement.decorator.cjs +178 -0
- package/dist/decorators/entitlement.decorator.cjs.map +1 -0
- package/dist/decorators/entitlement.decorator.d.cts +9 -0
- package/dist/decorators/entitlement.decorator.d.ts +9 -4
- package/dist/decorators/entitlement.decorator.mjs +161 -0
- package/dist/decorators/entitlement.decorator.mjs.map +1 -0
- package/dist/exceptions/blimu-forbidden.exception.cjs +86 -0
- package/dist/exceptions/blimu-forbidden.exception.cjs.map +1 -0
- package/dist/exceptions/blimu-forbidden.exception.d.cts +14 -0
- package/dist/exceptions/blimu-forbidden.exception.d.ts +6 -4
- package/dist/exceptions/blimu-forbidden.exception.mjs +61 -0
- package/dist/exceptions/blimu-forbidden.exception.mjs.map +1 -0
- package/dist/guards/entitlement.guard.cjs +174 -0
- package/dist/guards/entitlement.guard.cjs.map +1 -0
- package/dist/guards/entitlement.guard.d.cts +24 -0
- package/dist/guards/entitlement.guard.d.ts +12 -12
- package/dist/guards/entitlement.guard.mjs +154 -0
- package/dist/guards/entitlement.guard.mjs.map +1 -0
- package/dist/index.cjs +445 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +9 -0
- package/dist/index.d.ts +9 -7
- package/dist/index.mjs +420 -0
- package/dist/index.mjs.map +1 -0
- package/dist/modules/blimu.module.cjs +413 -0
- package/dist/modules/blimu.module.cjs.map +1 -0
- package/dist/modules/blimu.module.d.cts +14 -0
- package/dist/modules/blimu.module.d.ts +11 -8
- package/dist/modules/blimu.module.mjs +398 -0
- package/dist/modules/blimu.module.mjs.map +1 -0
- package/dist/services/index.cjs +93 -0
- package/dist/services/index.cjs.map +1 -0
- package/dist/services/index.d.cts +2 -0
- package/dist/services/index.d.ts +2 -2
- package/dist/services/index.mjs +69 -0
- package/dist/services/index.mjs.map +1 -0
- package/dist/services/jwk.service.cjs +91 -0
- package/dist/services/jwk.service.cjs.map +1 -0
- package/dist/services/jwk.service.d.cts +12 -0
- package/dist/services/jwk.service.d.ts +5 -3
- package/dist/services/jwk.service.mjs +69 -0
- package/dist/services/jwk.service.mjs.map +1 -0
- package/package.json +37 -16
- package/dist/config/blimu.config.d.ts.map +0 -1
- package/dist/config/blimu.config.js +0 -5
- package/dist/config/blimu.config.js.map +0 -1
- package/dist/decorators/entitlement.decorator.d.ts.map +0 -1
- package/dist/decorators/entitlement.decorator.js +0 -10
- package/dist/decorators/entitlement.decorator.js.map +0 -1
- package/dist/exceptions/blimu-forbidden.exception.d.ts.map +0 -1
- package/dist/exceptions/blimu-forbidden.exception.js +0 -38
- package/dist/exceptions/blimu-forbidden.exception.js.map +0 -1
- package/dist/guards/entitlement.guard.d.ts.map +0 -1
- package/dist/guards/entitlement.guard.js +0 -82
- package/dist/guards/entitlement.guard.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -23
- package/dist/index.js.map +0 -1
- package/dist/modules/blimu.module.d.ts.map +0 -1
- package/dist/modules/blimu.module.js +0 -91
- package/dist/modules/blimu.module.js.map +0 -1
- package/dist/services/index.d.ts.map +0 -1
- package/dist/services/index.js +0 -18
- package/dist/services/index.js.map +0 -1
- package/dist/services/jwk.service.d.ts.map +0 -1
- package/dist/services/jwk.service.js +0 -59
- package/dist/services/jwk.service.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
|
@@ -0,0 +1,413 @@
|
|
|
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/modules/blimu.module.ts
|
|
30
|
+
var blimu_module_exports = {};
|
|
31
|
+
__export(blimu_module_exports, {
|
|
32
|
+
BlimuModule: () => BlimuModule
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(blimu_module_exports);
|
|
35
|
+
var import_common4 = require("@nestjs/common");
|
|
36
|
+
|
|
37
|
+
// src/config/blimu.config.ts
|
|
38
|
+
var BLIMU_CONFIG = /* @__PURE__ */ Symbol("BLIMU_CONFIG");
|
|
39
|
+
|
|
40
|
+
// src/guards/entitlement.guard.ts
|
|
41
|
+
var import_common2 = require("@nestjs/common");
|
|
42
|
+
var import_reflect_metadata = require("reflect-metadata");
|
|
43
|
+
|
|
44
|
+
// src/exceptions/blimu-forbidden.exception.ts
|
|
45
|
+
var import_common = require("@nestjs/common");
|
|
46
|
+
var BlimuForbiddenException = class _BlimuForbiddenException extends import_common.ForbiddenException {
|
|
47
|
+
/**
|
|
48
|
+
* The entitlement check result containing detailed failure information
|
|
49
|
+
*/
|
|
50
|
+
entitlementResult;
|
|
51
|
+
/**
|
|
52
|
+
* The entitlement key that was checked
|
|
53
|
+
*/
|
|
54
|
+
entitlementKey;
|
|
55
|
+
/**
|
|
56
|
+
* The resource ID that was checked
|
|
57
|
+
*/
|
|
58
|
+
resourceId;
|
|
59
|
+
/**
|
|
60
|
+
* The user ID that was checked
|
|
61
|
+
*/
|
|
62
|
+
userId;
|
|
63
|
+
constructor(entitlementResult, entitlementKey, resourceId, userId) {
|
|
64
|
+
const message = _BlimuForbiddenException.buildMessage(entitlementResult, entitlementKey);
|
|
65
|
+
super({
|
|
66
|
+
message,
|
|
67
|
+
entitlementResult,
|
|
68
|
+
entitlementKey,
|
|
69
|
+
resourceId,
|
|
70
|
+
userId
|
|
71
|
+
});
|
|
72
|
+
this.entitlementResult = entitlementResult;
|
|
73
|
+
this.entitlementKey = entitlementKey;
|
|
74
|
+
this.resourceId = resourceId;
|
|
75
|
+
this.userId = userId;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Builds a user-friendly error message from the entitlement check result
|
|
79
|
+
*/
|
|
80
|
+
static buildMessage(result, entitlementKey) {
|
|
81
|
+
const reasons = [];
|
|
82
|
+
if (result.roles && !result.roles.allowed) {
|
|
83
|
+
reasons.push(
|
|
84
|
+
`Insufficient roles. Required: ${result.roles.allowedRoles?.join(", ") || "unknown"}. User has: ${result.roles.userRoles?.join(", ") || "none"}.`
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
if (result.plans && !result.plans.allowed) {
|
|
88
|
+
reasons.push(
|
|
89
|
+
`Plan restriction. Required plans: ${result.plans.allowedPlans?.join(", ") || "unknown"}. Current plan: ${result.plans.plan || "none"}.`
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
if (result.limit && !result.limit.allowed) {
|
|
93
|
+
reasons.push(`Usage limit exceeded. ${result.limit.reason || "Limit has been reached"}.`);
|
|
94
|
+
}
|
|
95
|
+
if (reasons.length === 0) {
|
|
96
|
+
return `Access denied for entitlement: ${entitlementKey}`;
|
|
97
|
+
}
|
|
98
|
+
return `Access denied for entitlement "${entitlementKey}": ${reasons.join(" ")}`;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
// src/guards/entitlement.guard.ts
|
|
103
|
+
var import_backend = require("@blimu/backend");
|
|
104
|
+
var ENTITLEMENT_METADATA_KEY = /* @__PURE__ */ Symbol("entitlement");
|
|
105
|
+
var EntitlementGuard = class {
|
|
106
|
+
constructor(config, runtime) {
|
|
107
|
+
this.config = config;
|
|
108
|
+
this.runtime = runtime;
|
|
109
|
+
}
|
|
110
|
+
async canActivate(context) {
|
|
111
|
+
const request = context.switchToHttp().getRequest();
|
|
112
|
+
const handler = context.getHandler();
|
|
113
|
+
const metadata = Reflect.getMetadata(ENTITLEMENT_METADATA_KEY, handler);
|
|
114
|
+
if (!metadata) {
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
let userId;
|
|
118
|
+
try {
|
|
119
|
+
userId = await this.config.getUserId(request);
|
|
120
|
+
} catch {
|
|
121
|
+
throw new import_common2.ForbiddenException("Failed to extract user ID from request");
|
|
122
|
+
}
|
|
123
|
+
if (!userId) {
|
|
124
|
+
throw new import_common2.ForbiddenException("User ID is required for entitlement check");
|
|
125
|
+
}
|
|
126
|
+
const entitlementInfo = await metadata.getEntitlementInfo(request);
|
|
127
|
+
if (!entitlementInfo?.resourceId) {
|
|
128
|
+
throw new import_common2.ForbiddenException("Resource ID is required for entitlement check");
|
|
129
|
+
}
|
|
130
|
+
try {
|
|
131
|
+
const result = await this.runtime.entitlements.checkEntitlement({
|
|
132
|
+
userId,
|
|
133
|
+
entitlement: metadata.entitlementKey,
|
|
134
|
+
resourceId: entitlementInfo.resourceId,
|
|
135
|
+
...entitlementInfo.amount !== void 0 ? { amount: entitlementInfo.amount } : {}
|
|
136
|
+
});
|
|
137
|
+
if (!result.allowed) {
|
|
138
|
+
throw new BlimuForbiddenException(
|
|
139
|
+
result,
|
|
140
|
+
metadata.entitlementKey,
|
|
141
|
+
entitlementInfo.resourceId,
|
|
142
|
+
userId
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
return true;
|
|
146
|
+
} catch (error) {
|
|
147
|
+
if (error instanceof BlimuForbiddenException || error instanceof import_common2.ForbiddenException) {
|
|
148
|
+
throw error;
|
|
149
|
+
}
|
|
150
|
+
console.error("Entitlement check failed:", error);
|
|
151
|
+
throw new import_common2.ForbiddenException("Failed to verify entitlements");
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
EntitlementGuard = __decorateClass([
|
|
156
|
+
(0, import_common2.Injectable)(),
|
|
157
|
+
__decorateParam(0, (0, import_common2.Inject)(BLIMU_CONFIG)),
|
|
158
|
+
__decorateParam(1, (0, import_common2.Inject)(import_backend.Blimu))
|
|
159
|
+
], EntitlementGuard);
|
|
160
|
+
|
|
161
|
+
// src/services/jwk.service.ts
|
|
162
|
+
var import_common3 = require("@nestjs/common");
|
|
163
|
+
var import_backend2 = require("@blimu/backend");
|
|
164
|
+
var JWKService = class {
|
|
165
|
+
constructor(config) {
|
|
166
|
+
this.config = config;
|
|
167
|
+
this.tokenVerifier = new import_backend2.TokenVerifier({
|
|
168
|
+
runtimeApiUrl: this.config.baseURL
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
logger = new import_common3.Logger(JWKService.name);
|
|
172
|
+
tokenVerifier;
|
|
173
|
+
/**
|
|
174
|
+
* Verify JWT token using JWKs from runtime-api
|
|
175
|
+
*/
|
|
176
|
+
async verifyToken(token) {
|
|
177
|
+
try {
|
|
178
|
+
this.logger.debug(
|
|
179
|
+
`\u{1F50D} Verifying token. Runtime API URL: ${this.config.baseURL}, API Key prefix: ${this.config.apiKey?.substring(0, 10)}...`
|
|
180
|
+
);
|
|
181
|
+
const result = await this.tokenVerifier.verifyToken({
|
|
182
|
+
secretKey: this.config.apiKey,
|
|
183
|
+
token,
|
|
184
|
+
runtimeApiUrl: this.config.baseURL
|
|
185
|
+
});
|
|
186
|
+
this.logger.debug(`\u2705 Token verified successfully`);
|
|
187
|
+
return result;
|
|
188
|
+
} catch (error) {
|
|
189
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
190
|
+
this.logger.error(`\u274C Token verification failed: ${errorMessage}`);
|
|
191
|
+
if (error instanceof Error && error.stack) {
|
|
192
|
+
this.logger.error(`Stack trace: ${error.stack}`);
|
|
193
|
+
}
|
|
194
|
+
throw error;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Clear cache (useful for testing or key rotation)
|
|
199
|
+
*/
|
|
200
|
+
clearCache() {
|
|
201
|
+
this.tokenVerifier.clearCache(this.config.apiKey);
|
|
202
|
+
this.logger.debug("JWK cache cleared");
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
JWKService = __decorateClass([
|
|
206
|
+
(0, import_common3.Injectable)(),
|
|
207
|
+
__decorateParam(0, (0, import_common3.Inject)(BLIMU_CONFIG))
|
|
208
|
+
], JWKService);
|
|
209
|
+
|
|
210
|
+
// src/modules/blimu.module.ts
|
|
211
|
+
var import_backend3 = require("@blimu/backend");
|
|
212
|
+
var DEFAULT_BASE_URL = "https://api.blimu.dev";
|
|
213
|
+
var BlimuModule = class {
|
|
214
|
+
/**
|
|
215
|
+
* Configure the Blimu module with static configuration
|
|
216
|
+
*
|
|
217
|
+
* @param config - The Blimu configuration object
|
|
218
|
+
* @returns A configured dynamic module
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* Basic usage with default Request type:
|
|
222
|
+
* ```typescript
|
|
223
|
+
* @Module({
|
|
224
|
+
* imports: [
|
|
225
|
+
* BlimuModule.forRoot({
|
|
226
|
+
* apiKey: 'your-api-secret-key',
|
|
227
|
+
* baseURL: 'https://api.blimu.dev', // optional
|
|
228
|
+
* environmentId: 'your-environment-id', // optional
|
|
229
|
+
* timeoutMs: 30000, // optional
|
|
230
|
+
* getUserId: (req) => req.user?.id, // required
|
|
231
|
+
* }),
|
|
232
|
+
* ],
|
|
233
|
+
* })
|
|
234
|
+
* export class AppModule {}
|
|
235
|
+
* ```
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* Usage with custom request type:
|
|
239
|
+
* ```typescript
|
|
240
|
+
* interface AuthenticatedRequest {
|
|
241
|
+
* user: { id: string; email: string };
|
|
242
|
+
* }
|
|
243
|
+
*
|
|
244
|
+
* @Module({
|
|
245
|
+
* imports: [
|
|
246
|
+
* BlimuModule.forRoot<AuthenticatedRequest>({
|
|
247
|
+
* apiKey: 'your-api-secret-key',
|
|
248
|
+
* getUserId: (req) => req.user.id, // req is typed as AuthenticatedRequest
|
|
249
|
+
* }),
|
|
250
|
+
* ],
|
|
251
|
+
* })
|
|
252
|
+
* export class AppModule {}
|
|
253
|
+
* ```
|
|
254
|
+
*/
|
|
255
|
+
static forRoot(config) {
|
|
256
|
+
return {
|
|
257
|
+
...config.global ? { global: true } : {},
|
|
258
|
+
module: BlimuModule,
|
|
259
|
+
providers: [
|
|
260
|
+
// Register factory providers first so dependencies are available
|
|
261
|
+
{
|
|
262
|
+
provide: BLIMU_CONFIG,
|
|
263
|
+
useValue: {
|
|
264
|
+
apiKey: config.apiKey,
|
|
265
|
+
baseURL: config.baseURL ?? DEFAULT_BASE_URL,
|
|
266
|
+
environmentId: config.environmentId,
|
|
267
|
+
timeoutMs: config.timeoutMs ?? 3e4,
|
|
268
|
+
getUserId: config.getUserId
|
|
269
|
+
}
|
|
270
|
+
},
|
|
271
|
+
{
|
|
272
|
+
provide: import_backend3.Blimu,
|
|
273
|
+
useFactory: (config2) => {
|
|
274
|
+
return new import_backend3.Blimu({
|
|
275
|
+
apiKey: config2.apiKey,
|
|
276
|
+
baseURL: config2.baseURL ?? DEFAULT_BASE_URL,
|
|
277
|
+
timeoutMs: config2.timeoutMs ?? 3e4
|
|
278
|
+
});
|
|
279
|
+
},
|
|
280
|
+
inject: [BLIMU_CONFIG]
|
|
281
|
+
},
|
|
282
|
+
// Register class providers after their dependencies are available
|
|
283
|
+
EntitlementGuard,
|
|
284
|
+
JWKService
|
|
285
|
+
],
|
|
286
|
+
exports: [EntitlementGuard, import_backend3.Blimu, BLIMU_CONFIG, JWKService]
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Configure the Blimu module with async configuration
|
|
291
|
+
*
|
|
292
|
+
* This is useful when you need to load configuration from environment variables,
|
|
293
|
+
* configuration services, or other async sources.
|
|
294
|
+
*
|
|
295
|
+
* @param options - Async configuration options
|
|
296
|
+
* @returns A configured dynamic module
|
|
297
|
+
*
|
|
298
|
+
* @example
|
|
299
|
+
* Using with ConfigService:
|
|
300
|
+
* ```typescript
|
|
301
|
+
* @Module({
|
|
302
|
+
* imports: [
|
|
303
|
+
* ConfigModule.forRoot(),
|
|
304
|
+
* BlimuModule.forRootAsync({
|
|
305
|
+
* useFactory: (configService: ConfigService) => ({
|
|
306
|
+
* apiKey: configService.get('BLIMU_API_SECRET_KEY'),
|
|
307
|
+
* baseURL: configService.get('BLIMU_BASE_URL'),
|
|
308
|
+
* environmentId: configService.get('BLIMU_ENVIRONMENT_ID'),
|
|
309
|
+
* timeoutMs: configService.get('BLIMU_TIMEOUT_MS'),
|
|
310
|
+
* getUserId: (req) => req.user?.id,
|
|
311
|
+
* }),
|
|
312
|
+
* inject: [ConfigService],
|
|
313
|
+
* }),
|
|
314
|
+
* ],
|
|
315
|
+
* })
|
|
316
|
+
* export class AppModule {}
|
|
317
|
+
* ```
|
|
318
|
+
*
|
|
319
|
+
* @example
|
|
320
|
+
* Using with custom request type:
|
|
321
|
+
* ```typescript
|
|
322
|
+
* interface AuthenticatedRequest {
|
|
323
|
+
* user: { id: string; email: string };
|
|
324
|
+
* }
|
|
325
|
+
*
|
|
326
|
+
* @Module({
|
|
327
|
+
* imports: [
|
|
328
|
+
* BlimuModule.forRootAsync<AuthenticatedRequest>({
|
|
329
|
+
* useFactory: (configService: ConfigService) => ({
|
|
330
|
+
* apiKey: configService.get('BLIMU_API_SECRET_KEY'),
|
|
331
|
+
* getUserId: (req) => req.user.id, // req is typed as AuthenticatedRequest
|
|
332
|
+
* }),
|
|
333
|
+
* inject: [ConfigService],
|
|
334
|
+
* }),
|
|
335
|
+
* ],
|
|
336
|
+
* })
|
|
337
|
+
* export class AppModule {}
|
|
338
|
+
* ```
|
|
339
|
+
*
|
|
340
|
+
* @example
|
|
341
|
+
* Using with custom provider:
|
|
342
|
+
* ```typescript
|
|
343
|
+
* @Module({
|
|
344
|
+
* imports: [
|
|
345
|
+
* BlimuModule.forRootAsync({
|
|
346
|
+
* imports: [MyConfigModule],
|
|
347
|
+
* useFactory: async (myConfigService: MyConfigService) => {
|
|
348
|
+
* const config = await myConfigService.getBlimuConfig();
|
|
349
|
+
* return {
|
|
350
|
+
* apiKey: config.apiKey,
|
|
351
|
+
* baseURL: config.baseUrl,
|
|
352
|
+
* environmentId: config.environmentId,
|
|
353
|
+
* getUserId: (req) => req.user?.id,
|
|
354
|
+
* };
|
|
355
|
+
* },
|
|
356
|
+
* inject: [MyConfigService],
|
|
357
|
+
* }),
|
|
358
|
+
* ],
|
|
359
|
+
* })
|
|
360
|
+
* export class AppModule {}
|
|
361
|
+
* ```
|
|
362
|
+
*/
|
|
363
|
+
static forRootAsync(options) {
|
|
364
|
+
const additionalImports = options.imports ?? [];
|
|
365
|
+
const module2 = {
|
|
366
|
+
...options.global ? { global: true } : {},
|
|
367
|
+
module: BlimuModule,
|
|
368
|
+
imports: [...additionalImports],
|
|
369
|
+
providers: [
|
|
370
|
+
// Register factory providers first so dependencies are available
|
|
371
|
+
{
|
|
372
|
+
provide: BLIMU_CONFIG,
|
|
373
|
+
useFactory: async (...args) => {
|
|
374
|
+
const configResult = options.useFactory(...args);
|
|
375
|
+
const config = configResult instanceof Promise ? await configResult : configResult;
|
|
376
|
+
return {
|
|
377
|
+
apiKey: config.apiKey,
|
|
378
|
+
baseURL: config.baseURL ?? DEFAULT_BASE_URL,
|
|
379
|
+
environmentId: config.environmentId,
|
|
380
|
+
timeoutMs: config.timeoutMs ?? 3e4,
|
|
381
|
+
getUserId: config.getUserId
|
|
382
|
+
};
|
|
383
|
+
},
|
|
384
|
+
...options.inject ? { inject: options.inject } : {}
|
|
385
|
+
},
|
|
386
|
+
{
|
|
387
|
+
provide: import_backend3.Blimu,
|
|
388
|
+
useFactory: (config) => {
|
|
389
|
+
return new import_backend3.Blimu({
|
|
390
|
+
apiKey: config.apiKey,
|
|
391
|
+
baseURL: config.baseURL ?? DEFAULT_BASE_URL,
|
|
392
|
+
timeoutMs: config.timeoutMs ?? 3e4
|
|
393
|
+
});
|
|
394
|
+
},
|
|
395
|
+
inject: [BLIMU_CONFIG]
|
|
396
|
+
},
|
|
397
|
+
// Register class providers after their dependencies are available
|
|
398
|
+
EntitlementGuard,
|
|
399
|
+
JWKService
|
|
400
|
+
],
|
|
401
|
+
exports: [EntitlementGuard, import_backend3.Blimu, BLIMU_CONFIG, JWKService]
|
|
402
|
+
};
|
|
403
|
+
return module2;
|
|
404
|
+
}
|
|
405
|
+
};
|
|
406
|
+
BlimuModule = __decorateClass([
|
|
407
|
+
(0, import_common4.Module)({})
|
|
408
|
+
], BlimuModule);
|
|
409
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
410
|
+
0 && (module.exports = {
|
|
411
|
+
BlimuModule
|
|
412
|
+
});
|
|
413
|
+
//# sourceMappingURL=blimu.module.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/modules/blimu.module.ts","../../src/config/blimu.config.ts","../../src/guards/entitlement.guard.ts","../../src/exceptions/blimu-forbidden.exception.ts","../../src/services/jwk.service.ts"],"sourcesContent":["import {\n Module,\n type DynamicModule,\n type Type,\n type ForwardReference,\n type InjectionToken,\n type OptionalFactoryDependency,\n} from '@nestjs/common';\n\nimport { BLIMU_CONFIG, type BlimuConfig } from '../config/blimu.config';\nimport { EntitlementGuard } from 'guards/entitlement.guard';\nimport { JWKService } from 'services/jwk.service';\nimport { Blimu } from '@blimu/backend';\n\nconst DEFAULT_BASE_URL = 'https://api.blimu.dev';\n\n/**\n * Blimu NestJS Module\n *\n * This module provides entitlement checking capabilities and Blimu Runtime SDK integration\n * for NestJS applications. It can be configured synchronously or asynchronously.\n */\n@Module({})\nexport class BlimuModule {\n /**\n * Configure the Blimu module with static configuration\n *\n * @param config - The Blimu configuration object\n * @returns A configured dynamic module\n *\n * @example\n * Basic usage with default Request type:\n * ```typescript\n * @Module({\n * imports: [\n * BlimuModule.forRoot({\n * apiKey: 'your-api-secret-key',\n * baseURL: 'https://api.blimu.dev', // optional\n * environmentId: 'your-environment-id', // optional\n * timeoutMs: 30000, // optional\n * getUserId: (req) => req.user?.id, // required\n * }),\n * ],\n * })\n * export class AppModule {}\n * ```\n *\n * @example\n * Usage with custom request type:\n * ```typescript\n * interface AuthenticatedRequest {\n * user: { id: string; email: string };\n * }\n *\n * @Module({\n * imports: [\n * BlimuModule.forRoot<AuthenticatedRequest>({\n * apiKey: 'your-api-secret-key',\n * getUserId: (req) => req.user.id, // req is typed as AuthenticatedRequest\n * }),\n * ],\n * })\n * export class AppModule {}\n * ```\n */\n static forRoot<TRequest = unknown>(config: BlimuConfig<TRequest>): DynamicModule {\n return {\n ...(config.global ? { global: true } : {}),\n module: BlimuModule,\n providers: [\n // Register factory providers first so dependencies are available\n {\n provide: BLIMU_CONFIG,\n useValue: {\n apiKey: config.apiKey,\n baseURL: config.baseURL ?? DEFAULT_BASE_URL,\n environmentId: config.environmentId,\n timeoutMs: config.timeoutMs ?? 30000,\n getUserId: config.getUserId,\n },\n },\n {\n provide: Blimu,\n useFactory: (config: BlimuConfig) => {\n return new Blimu({\n apiKey: config.apiKey,\n baseURL: config.baseURL ?? DEFAULT_BASE_URL,\n timeoutMs: config.timeoutMs ?? 30000,\n });\n },\n inject: [BLIMU_CONFIG],\n },\n // Register class providers after their dependencies are available\n EntitlementGuard,\n JWKService,\n ],\n exports: [EntitlementGuard, Blimu, BLIMU_CONFIG, JWKService],\n };\n }\n\n /**\n * Configure the Blimu module with async configuration\n *\n * This is useful when you need to load configuration from environment variables,\n * configuration services, or other async sources.\n *\n * @param options - Async configuration options\n * @returns A configured dynamic module\n *\n * @example\n * Using with ConfigService:\n * ```typescript\n * @Module({\n * imports: [\n * ConfigModule.forRoot(),\n * BlimuModule.forRootAsync({\n * useFactory: (configService: ConfigService) => ({\n * apiKey: configService.get('BLIMU_API_SECRET_KEY'),\n * baseURL: configService.get('BLIMU_BASE_URL'),\n * environmentId: configService.get('BLIMU_ENVIRONMENT_ID'),\n * timeoutMs: configService.get('BLIMU_TIMEOUT_MS'),\n * getUserId: (req) => req.user?.id,\n * }),\n * inject: [ConfigService],\n * }),\n * ],\n * })\n * export class AppModule {}\n * ```\n *\n * @example\n * Using with custom request type:\n * ```typescript\n * interface AuthenticatedRequest {\n * user: { id: string; email: string };\n * }\n *\n * @Module({\n * imports: [\n * BlimuModule.forRootAsync<AuthenticatedRequest>({\n * useFactory: (configService: ConfigService) => ({\n * apiKey: configService.get('BLIMU_API_SECRET_KEY'),\n * getUserId: (req) => req.user.id, // req is typed as AuthenticatedRequest\n * }),\n * inject: [ConfigService],\n * }),\n * ],\n * })\n * export class AppModule {}\n * ```\n *\n * @example\n * Using with custom provider:\n * ```typescript\n * @Module({\n * imports: [\n * BlimuModule.forRootAsync({\n * imports: [MyConfigModule],\n * useFactory: async (myConfigService: MyConfigService) => {\n * const config = await myConfigService.getBlimuConfig();\n * return {\n * apiKey: config.apiKey,\n * baseURL: config.baseUrl,\n * environmentId: config.environmentId,\n * getUserId: (req) => req.user?.id,\n * };\n * },\n * inject: [MyConfigService],\n * }),\n * ],\n * })\n * export class AppModule {}\n * ```\n */\n static forRootAsync<TRequest = unknown>(options: {\n global?: boolean | undefined;\n useFactory: (...args: unknown[]) => Promise<BlimuConfig<TRequest>> | BlimuConfig<TRequest>;\n inject?: (InjectionToken | OptionalFactoryDependency)[];\n imports?: (\n | Type<unknown>\n | DynamicModule\n | Promise<DynamicModule>\n | ForwardReference<() => Type<unknown>>\n )[];\n }): DynamicModule {\n const additionalImports = options.imports ?? [];\n\n const module = {\n ...(options.global ? { global: true } : {}),\n module: BlimuModule,\n imports: [...additionalImports] as (\n | Type<unknown>\n | DynamicModule\n | Promise<DynamicModule>\n | ForwardReference\n )[],\n providers: [\n // Register factory providers first so dependencies are available\n {\n provide: BLIMU_CONFIG,\n useFactory: async (...args: unknown[]) => {\n const configResult = options.useFactory(...args);\n const config = configResult instanceof Promise ? await configResult : configResult;\n return {\n apiKey: config.apiKey,\n baseURL: config.baseURL ?? DEFAULT_BASE_URL,\n environmentId: config.environmentId,\n timeoutMs: config.timeoutMs ?? 30000,\n getUserId: config.getUserId,\n };\n },\n ...(options.inject ? { inject: options.inject } : {}),\n },\n {\n provide: Blimu,\n useFactory: (config: BlimuConfig) => {\n return new Blimu({\n apiKey: config.apiKey,\n baseURL: config.baseURL ?? DEFAULT_BASE_URL,\n timeoutMs: config.timeoutMs ?? 30000,\n });\n },\n inject: [BLIMU_CONFIG],\n },\n // Register class providers after their dependencies are available\n EntitlementGuard,\n JWKService,\n ],\n exports: [EntitlementGuard, Blimu, BLIMU_CONFIG, JWKService],\n };\n return module;\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","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","import { Inject, Injectable, Logger } from '@nestjs/common';\nimport { TokenVerifier } from '@blimu/backend';\nimport { BLIMU_CONFIG, type BlimuConfig } from '../config/blimu.config';\n\n@Injectable()\nexport class JWKService {\n private readonly logger = new Logger(JWKService.name);\n private readonly tokenVerifier: TokenVerifier;\n\n constructor(@Inject(BLIMU_CONFIG) private readonly config: BlimuConfig) {\n this.tokenVerifier = new TokenVerifier({\n runtimeApiUrl: this.config.baseURL,\n });\n }\n\n /**\n * Verify JWT token using JWKs from runtime-api\n */\n async verifyToken<T = unknown>(token: string): Promise<T> {\n try {\n this.logger.debug(\n `🔍 Verifying token. Runtime API URL: ${this.config.baseURL}, API Key prefix: ${this.config.apiKey?.substring(0, 10)}...`,\n );\n\n const result = await this.tokenVerifier.verifyToken<T>({\n secretKey: this.config.apiKey,\n token,\n runtimeApiUrl: this.config.baseURL,\n });\n\n this.logger.debug(`✅ Token verified successfully`);\n return result;\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n this.logger.error(`❌ Token verification failed: ${errorMessage}`);\n if (error instanceof Error && error.stack) {\n this.logger.error(`Stack trace: ${error.stack}`);\n }\n throw error;\n }\n }\n\n /**\n * Clear cache (useful for testing or key rotation)\n */\n clearCache(): void {\n this.tokenVerifier.clearCache(this.config.apiKey);\n this.logger.debug('JWK cache cleared');\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,iBAO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":["import_common","import_common","import_common","import_backend","import_backend","config","module"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DynamicModule, InjectionToken, OptionalFactoryDependency, Type, ForwardReference } from '@nestjs/common';
|
|
2
|
+
import { BlimuConfig } from '../config/blimu.config.cjs';
|
|
3
|
+
|
|
4
|
+
declare class BlimuModule {
|
|
5
|
+
static forRoot<TRequest = unknown>(config: BlimuConfig<TRequest>): DynamicModule;
|
|
6
|
+
static forRootAsync<TRequest = unknown>(options: {
|
|
7
|
+
global?: boolean | undefined;
|
|
8
|
+
useFactory: (...args: unknown[]) => Promise<BlimuConfig<TRequest>> | BlimuConfig<TRequest>;
|
|
9
|
+
inject?: (InjectionToken | OptionalFactoryDependency)[];
|
|
10
|
+
imports?: (Type<unknown> | DynamicModule | Promise<DynamicModule> | ForwardReference<() => Type<unknown>>)[];
|
|
11
|
+
}): DynamicModule;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { BlimuModule };
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { DynamicModule,
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
static
|
|
1
|
+
import { DynamicModule, InjectionToken, OptionalFactoryDependency, Type, ForwardReference } from '@nestjs/common';
|
|
2
|
+
import { BlimuConfig } from '../config/blimu.config.js';
|
|
3
|
+
|
|
4
|
+
declare class BlimuModule {
|
|
5
|
+
static forRoot<TRequest = unknown>(config: BlimuConfig<TRequest>): DynamicModule;
|
|
6
|
+
static forRootAsync<TRequest = unknown>(options: {
|
|
7
|
+
global?: boolean | undefined;
|
|
6
8
|
useFactory: (...args: unknown[]) => Promise<BlimuConfig<TRequest>> | BlimuConfig<TRequest>;
|
|
7
|
-
inject?:
|
|
8
|
-
imports?:
|
|
9
|
+
inject?: (InjectionToken | OptionalFactoryDependency)[];
|
|
10
|
+
imports?: (Type<unknown> | DynamicModule | Promise<DynamicModule> | ForwardReference<() => Type<unknown>>)[];
|
|
9
11
|
}): DynamicModule;
|
|
10
12
|
}
|
|
11
|
-
|
|
13
|
+
|
|
14
|
+
export { BlimuModule };
|