@blimu/nestjs 0.1.0

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.
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.EntitlementGuard = exports.SetEntitlementMetadata = exports.ENTITLEMENT_METADATA_KEY = exports.ENTITLEMENT_KEY = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const core_1 = require("@nestjs/core");
18
+ const runtime_sdk_1 = require("@blimu/runtime-sdk");
19
+ const blimu_config_1 = require("../config/blimu.config");
20
+ exports.ENTITLEMENT_KEY = 'entitlement';
21
+ exports.ENTITLEMENT_METADATA_KEY = Symbol('entitlement');
22
+ const SetEntitlementMetadata = (entitlementKey, resourceIdExtractor) => (0, common_1.SetMetadata)(exports.ENTITLEMENT_METADATA_KEY, {
23
+ entitlementKey,
24
+ resourceIdExtractor,
25
+ });
26
+ exports.SetEntitlementMetadata = SetEntitlementMetadata;
27
+ let EntitlementGuard = class EntitlementGuard {
28
+ constructor(reflector, config, runtime) {
29
+ this.reflector = reflector;
30
+ this.config = config;
31
+ this.runtime = runtime;
32
+ }
33
+ async canActivate(context) {
34
+ const request = context.switchToHttp().getRequest();
35
+ const metadata = this.reflector.get(exports.ENTITLEMENT_METADATA_KEY, context.getHandler());
36
+ if (!metadata) {
37
+ return true;
38
+ }
39
+ let userId;
40
+ try {
41
+ userId = await this.config.getUserId(request);
42
+ }
43
+ catch (error) {
44
+ throw new common_1.ForbiddenException('Failed to extract user ID from request');
45
+ }
46
+ if (!userId) {
47
+ throw new common_1.ForbiddenException('User ID is required for entitlement check');
48
+ }
49
+ const resourceId = await metadata.resourceIdExtractor(request);
50
+ if (!resourceId) {
51
+ throw new common_1.ForbiddenException('Resource ID is required for entitlement check');
52
+ }
53
+ try {
54
+ const result = await this.runtime.entitlements.checkEntitlement({
55
+ userId,
56
+ entitlement: metadata.entitlementKey,
57
+ resourceId,
58
+ });
59
+ if (!result.allowed) {
60
+ throw new common_1.ForbiddenException(result.reason || `User does not have required entitlement: ${metadata.entitlementKey}`);
61
+ }
62
+ return true;
63
+ }
64
+ catch (error) {
65
+ if (error instanceof common_1.ForbiddenException) {
66
+ throw error;
67
+ }
68
+ console.error('Entitlement check failed:', error);
69
+ throw new common_1.ForbiddenException('Failed to verify entitlements');
70
+ }
71
+ }
72
+ };
73
+ exports.EntitlementGuard = EntitlementGuard;
74
+ exports.EntitlementGuard = EntitlementGuard = __decorate([
75
+ (0, common_1.Injectable)(),
76
+ __param(1, (0, common_1.Inject)(blimu_config_1.BLIMU_CONFIG)),
77
+ __param(2, (0, common_1.Inject)(runtime_sdk_1.BlimuRuntime)),
78
+ __metadata("design:paramtypes", [core_1.Reflector, Object, runtime_sdk_1.BlimuRuntime])
79
+ ], EntitlementGuard);
80
+ //# sourceMappingURL=entitlement.guard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entitlement.guard.js","sourceRoot":"","sources":["../../src/guards/entitlement.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAOwB;AACxB,uCAAyC;AACzC,oDAA0D;AAE1D,yDAAsD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,CAAC,+CAA+C,CAAC,CAAC;QAChF,CAAC;QAED,IAAI,CAAC;YAEH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,gBAAgB,CAAC;gBAC9D,MAAM;gBACN,WAAW,EAAE,QAAQ,CAAC,cAAc;gBACpC,UAAU;aACX,CAAC,CAAC;YAEH,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;gBACpB,MAAM,IAAI,2BAAkB,CAC1B,MAAM,CAAC,MAAM,IAAI,4CAA4C,QAAQ,CAAC,cAAc,EAAE,CACvF,CAAC;YACJ,CAAC;YAED,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,2BAAkB,EAAE,CAAC;gBACxC,MAAM,KAAK,CAAC;YACd,CAAC;YAGD,OAAO,CAAC,KAAK,CAAC,2BAA2B,EAAE,KAAK,CAAC,CAAC;YAClD,MAAM,IAAI,2BAAkB,CAAC,+BAA+B,CAAC,CAAC;QAChE,CAAC;IACH,CAAC;CACF,CAAA;AAjEY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,mBAAU,GAAE;IAIR,WAAA,IAAA,eAAM,EAAC,2BAAY,CAAC,CAAA;IAEpB,WAAA,IAAA,eAAM,EAAC,0BAAY,CAAC,CAAA;qCAHO,gBAAS,UAIX,0BAAY;GAN7B,gBAAgB,CAiE5B"}
@@ -0,0 +1,6 @@
1
+ export * from './modules/blimu.module';
2
+ export * from './config/blimu.config';
3
+ export * from './guards/entitlement.guard';
4
+ export * from './decorators/entitlement.decorator';
5
+ export * from '@blimu/runtime-sdk';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,wBAAwB,CAAC;AAGvC,cAAc,uBAAuB,CAAC;AAGtC,cAAc,4BAA4B,CAAC;AAG3C,cAAc,oCAAoC,CAAC;AAGnD,cAAc,oBAAoB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./modules/blimu.module"), exports);
18
+ __exportStar(require("./config/blimu.config"), exports);
19
+ __exportStar(require("./guards/entitlement.guard"), exports);
20
+ __exportStar(require("./decorators/entitlement.decorator"), exports);
21
+ __exportStar(require("@blimu/runtime-sdk"), exports);
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AACA,yDAAuC;AAGvC,wDAAsC;AAGtC,6DAA2C;AAG3C,qEAAmD;AAGnD,qDAAmC"}
@@ -0,0 +1,12 @@
1
+ import { DynamicModule, Type, ForwardReference, InjectionToken, OptionalFactoryDependency } from '@nestjs/common';
2
+ import { Request } from 'express';
3
+ import type { BlimuConfig } from '../config/blimu.config';
4
+ export declare class BlimuModule {
5
+ static forRoot<TRequest extends Request = Request>(config: BlimuConfig<TRequest>): DynamicModule;
6
+ static forRootAsync<TRequest extends Request = Request>(options: {
7
+ useFactory: (...args: unknown[]) => Promise<BlimuConfig<TRequest>> | BlimuConfig<TRequest>;
8
+ inject?: Array<InjectionToken | OptionalFactoryDependency>;
9
+ imports?: Array<Type<unknown> | DynamicModule | Promise<DynamicModule> | ForwardReference<() => Type<unknown>>>;
10
+ }): DynamicModule;
11
+ }
12
+ //# sourceMappingURL=blimu.module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blimu.module.d.ts","sourceRoot":"","sources":["../../src/modules/blimu.module.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAEb,IAAI,EACJ,gBAAgB,EAChB,cAAc,EACd,yBAAyB,EAC1B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAU1D,qBACa,WAAW;IA0CtB,MAAM,CAAC,OAAO,CAAC,QAAQ,SAAS,OAAO,GAAG,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,QAAQ,CAAC,GAAG,aAAa;IAyGhG,MAAM,CAAC,YAAY,CAAC,QAAQ,SAAS,OAAO,GAAG,OAAO,EAAE,OAAO,EAAE;QAC/D,UAAU,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC;QAC3F,MAAM,CAAC,EAAE,KAAK,CAAC,cAAc,GAAG,yBAAyB,CAAC,CAAC;QAC3D,OAAO,CAAC,EAAE,KAAK,CACb,IAAI,CAAC,OAAO,CAAC,GAAG,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC,GAAG,gBAAgB,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,CAAC,CAC/F,CAAC;KACH,GAAG,aAAa;CAuClB"}
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var BlimuModule_1;
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.BlimuModule = void 0;
11
+ const common_1 = require("@nestjs/common");
12
+ const entitlement_guard_1 = require("../guards/entitlement.guard");
13
+ const blimu_config_1 = require("../config/blimu.config");
14
+ const runtime_sdk_1 = require("@blimu/runtime-sdk");
15
+ let BlimuModule = BlimuModule_1 = class BlimuModule {
16
+ static forRoot(config) {
17
+ return {
18
+ module: BlimuModule_1,
19
+ global: true,
20
+ providers: [
21
+ {
22
+ provide: blimu_config_1.BLIMU_CONFIG,
23
+ useValue: {
24
+ apiSecretKey: config.apiSecretKey,
25
+ baseURL: config.baseURL || 'https://runtime.blimu.com',
26
+ environmentId: config.environmentId,
27
+ timeoutMs: config.timeoutMs ?? 30000,
28
+ getUserId: config.getUserId,
29
+ },
30
+ },
31
+ entitlement_guard_1.EntitlementGuard,
32
+ {
33
+ provide: runtime_sdk_1.BlimuRuntime,
34
+ useFactory: (config) => new runtime_sdk_1.BlimuRuntime({
35
+ apiKeyAuth: config.apiSecretKey,
36
+ baseURL: config.baseURL || 'https://runtime.blimu.com',
37
+ timeoutMs: config.timeoutMs ?? 30000,
38
+ }),
39
+ inject: [blimu_config_1.BLIMU_CONFIG],
40
+ },
41
+ ],
42
+ exports: [entitlement_guard_1.EntitlementGuard, runtime_sdk_1.BlimuRuntime, blimu_config_1.BLIMU_CONFIG],
43
+ };
44
+ }
45
+ static forRootAsync(options) {
46
+ const additionalImports = options.imports || [];
47
+ return {
48
+ module: BlimuModule_1,
49
+ global: true,
50
+ imports: [...additionalImports],
51
+ providers: [
52
+ {
53
+ provide: blimu_config_1.BLIMU_CONFIG,
54
+ useFactory: async (...args) => {
55
+ const config = await options.useFactory(...args);
56
+ return {
57
+ apiSecretKey: config.apiSecretKey,
58
+ baseURL: config.baseURL || 'https://runtime.blimu.com',
59
+ environmentId: config.environmentId,
60
+ timeoutMs: config.timeoutMs ?? 30000,
61
+ getUserId: config.getUserId,
62
+ };
63
+ },
64
+ inject: options.inject,
65
+ },
66
+ entitlement_guard_1.EntitlementGuard,
67
+ {
68
+ provide: runtime_sdk_1.BlimuRuntime,
69
+ useFactory: (config) => new runtime_sdk_1.BlimuRuntime({
70
+ apiKeyAuth: config.apiSecretKey,
71
+ baseURL: config.baseURL || 'https://runtime.blimu.com',
72
+ timeoutMs: config.timeoutMs ?? 30000,
73
+ }),
74
+ inject: [blimu_config_1.BLIMU_CONFIG],
75
+ },
76
+ ],
77
+ exports: [entitlement_guard_1.EntitlementGuard, runtime_sdk_1.BlimuRuntime, blimu_config_1.BLIMU_CONFIG],
78
+ };
79
+ }
80
+ };
81
+ exports.BlimuModule = BlimuModule;
82
+ exports.BlimuModule = BlimuModule = BlimuModule_1 = __decorate([
83
+ (0, common_1.Module)({})
84
+ ], BlimuModule);
85
+ //# sourceMappingURL=blimu.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blimu.module.js","sourceRoot":"","sources":["../../src/modules/blimu.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAOwB;AAExB,mEAA+D;AAE/D,yDAAsD;AACtD,oDAAkD;AAS3C,IAAM,WAAW,mBAAjB,MAAM,WAAW;IA0CtB,MAAM,CAAC,OAAO,CAAqC,MAA6B;QAC9E,OAAO;YACL,MAAM,EAAE,aAAW;YACnB,MAAM,EAAE,IAAI;YACZ,SAAS,EAAE;gBACT;oBACE,OAAO,EAAE,2BAAY;oBACrB,QAAQ,EAAE;wBACR,YAAY,EAAE,MAAM,CAAC,YAAY;wBACjC,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,2BAA2B;wBACtD,aAA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B;gBAChB;oBACE,OAAO,EAAE,0BAAY;oBACrB,UAAU,EAAE,CAAC,MAAmB,EAAE,EAAE,CAClC,IAAI,0BAAY,CAAC;wBACf,UAAU,EAAE,MAAM,CAAC,YAAY;wBAC/B,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,2BAA2B;wBACtD,SAAS,EAAE,MAAM,CAAC,SAAS,IAAI,KAAK;qBACrC,CAAC;oBACJ,MAAM,EAAE,CAAC,2BAAY,CAAC;iBACvB;aACF;YACD,OAAO,EAAE,CAAC,oCAAgB,EAAE,0BAAY,EAAE,2BAAY,CAAC;SACxD,CAAC;IACJ,CAAC;CACF,CAAA;AAhMY,kCAAW;sBAAX,WAAW;IADvB,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,WAAW,CAgMvB"}
@@ -0,0 +1,149 @@
1
+ import { BlimuRuntime, Schema } from '@blimu/runtime-sdk';
2
+ import type { BlimuConfig } from '../config/blimu.config';
3
+ /**
4
+ * Injectable service that provides access to the Blimu Runtime SDK
5
+ *
6
+ * This service creates and manages a configured instance of the Blimu Runtime client,
7
+ * making it easy to interact with Blimu APIs from within your NestJS services.
8
+ */
9
+ export declare class BlimuRuntimeService {
10
+ private readonly config;
11
+ private readonly client;
12
+ constructor(config: BlimuConfig);
13
+ /**
14
+ * Get the configured Blimu Runtime client
15
+ *
16
+ * @returns The configured BlimuRuntime instance
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * @Injectable()
21
+ * export class MyService {
22
+ * constructor(private readonly blimuRuntime: BlimuRuntimeService) {}
23
+ *
24
+ * async checkUserEntitlement(userId: string, entitlement: string, resourceId: string) {
25
+ * const client = this.blimuRuntime.getClient();
26
+ * return await client.entitlements.checkEntitlement({
27
+ * userId,
28
+ * entitlement,
29
+ * resourceId,
30
+ * });
31
+ * }
32
+ * }
33
+ * ```
34
+ */
35
+ getClient(): BlimuRuntime;
36
+ /**
37
+ * Convenience method to check entitlements
38
+ *
39
+ * @param userId - The user ID to check entitlements for
40
+ * @param entitlement - The entitlement key to check
41
+ * @param resourceId - The resource ID to check entitlements on
42
+ * @returns Promise resolving to the entitlement check result
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * const result = await this.blimuRuntime.checkEntitlement(
47
+ * 'user123',
48
+ * 'workspace:read',
49
+ * 'workspace456'
50
+ * );
51
+ *
52
+ * if (result.allowed) {
53
+ * // User has permission
54
+ * }
55
+ * ```
56
+ */
57
+ checkEntitlement(userId: string, entitlement: Schema.EntitlementType, resourceId: string): Promise<Schema.EntitlementCheckResultDto_Output>;
58
+ /**
59
+ * Convenience method to assign a role to a user on a resource
60
+ *
61
+ * @param userId - The user ID to assign the role to
62
+ * @param role - The role to assign
63
+ * @param resourceType - The type of resource
64
+ * @param resourceId - The ID of the resource
65
+ * @returns Promise resolving to the role assignment result
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * await this.blimuRuntime.assignRole(
70
+ * 'user123',
71
+ * 'admin',
72
+ * 'workspace',
73
+ * 'workspace456'
74
+ * );
75
+ * ```
76
+ */
77
+ assignRole(userId: string, role: string, resourceType: Schema.ResourceType, resourceId: string): Promise<Schema.RoleDto_Output>;
78
+ /**
79
+ * Convenience method to remove a role from a user on a resource
80
+ *
81
+ * @param userId - The user ID to remove the role from
82
+ * @param resourceType - The type of resource
83
+ * @param resourceId - The ID of the resource
84
+ * @returns Promise resolving to the role removal result
85
+ *
86
+ * @example
87
+ * ```typescript
88
+ * await this.blimuRuntime.removeRole(
89
+ * 'user123',
90
+ * 'workspace',
91
+ * 'workspace456'
92
+ * );
93
+ * ```
94
+ */
95
+ removeRole(userId: string, resourceType: Schema.ResourceType, resourceId: string): Promise<unknown>;
96
+ /**
97
+ * Convenience method to create workspace resources in bulk
98
+ *
99
+ * @param resources - Array of workspace resource data to create
100
+ * @returns Promise resolving to the bulk creation result
101
+ *
102
+ * @example
103
+ * ```typescript
104
+ * await this.blimuRuntime.bulkCreateWorkspaces([
105
+ * { id: 'workspace456', extraFields: { name: 'My Workspace' } }
106
+ * ]);
107
+ * ```
108
+ */
109
+ bulkCreateWorkspaces(resources: Schema.WorkspaceBulkCreateBodyDto['resources']): Promise<Schema.ResourceBulkResultDto_Output>;
110
+ /**
111
+ * Convenience method to delete a workspace resource
112
+ *
113
+ * @param resourceId - The ID of the workspace to delete
114
+ * @returns Promise resolving to the deletion result
115
+ *
116
+ * @example
117
+ * ```typescript
118
+ * await this.blimuRuntime.deleteWorkspace('workspace456');
119
+ * ```
120
+ */
121
+ deleteWorkspace(resourceId: string): Promise<unknown>;
122
+ /**
123
+ * Convenience method to create environment resources in bulk
124
+ *
125
+ * @param resources - Array of environment resource data to create
126
+ * @returns Promise resolving to the bulk creation result
127
+ *
128
+ * @example
129
+ * ```typescript
130
+ * await this.blimuRuntime.bulkCreateEnvironments([
131
+ * { id: 'env123', workspaceId: 'workspace456', extraFields: { name: 'Production' } }
132
+ * ]);
133
+ * ```
134
+ */
135
+ bulkCreateEnvironments(resources: Schema.EnvironmentBulkCreateBodyDto['resources']): Promise<Schema.ResourceBulkResultDto_Output>;
136
+ /**
137
+ * Convenience method to delete an environment resource
138
+ *
139
+ * @param resourceId - The ID of the environment to delete
140
+ * @returns Promise resolving to the deletion result
141
+ *
142
+ * @example
143
+ * ```typescript
144
+ * await this.blimuRuntime.deleteEnvironment('env123');
145
+ * ```
146
+ */
147
+ deleteEnvironment(resourceId: string): Promise<unknown>;
148
+ }
149
+ //# sourceMappingURL=blimu-runtime.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blimu-runtime.service.d.ts","sourceRoot":"","sources":["../../src/services/blimu-runtime.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAG1D;;;;;GAKG;AACH,qBACa,mBAAmB;IAK5B,OAAO,CAAC,QAAQ,CAAC,MAAM;IAJzB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAe;gBAInB,MAAM,EAAE,WAAW;IAStC;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,SAAS,IAAI,YAAY;IAIzB;;;;;;;;;;;;;;;;;;;;OAoBG;IACG,gBAAgB,CACpB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,CAAC,eAAe,EACnC,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,MAAM,CAAC,gCAAgC,CAAC;IAQnD;;;;;;;;;;;;;;;;;;OAkBG;IACG,UAAU,CACd,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,MAAM,CAAC,YAAY,EACjC,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC;IAQjC;;;;;;;;;;;;;;;;OAgBG;IACG,UAAU,CACd,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,MAAM,CAAC,YAAY,EACjC,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,OAAO,CAAC;IAInB;;;;;;;;;;;;OAYG;IACG,oBAAoB,CACxB,SAAS,EAAE,MAAM,CAAC,0BAA0B,CAAC,WAAW,CAAC,GACxD,OAAO,CAAC,MAAM,CAAC,4BAA4B,CAAC;IAI/C;;;;;;;;;;OAUG;IACG,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAI3D;;;;;;;;;;;;OAYG;IACG,sBAAsB,CAC1B,SAAS,EAAE,MAAM,CAAC,4BAA4B,CAAC,WAAW,CAAC,GAC1D,OAAO,CAAC,MAAM,CAAC,4BAA4B,CAAC;IAI/C;;;;;;;;;;OAUG;IACG,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAG9D"}
@@ -0,0 +1,199 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
11
+ return function (target, key) { decorator(target, key, paramIndex); }
12
+ };
13
+ import { Injectable, Inject } from '@nestjs/common';
14
+ import { BlimuRuntime } from '@blimu/runtime-sdk';
15
+ import { BLIMU_CONFIG } from '../config/blimu.config';
16
+ /**
17
+ * Injectable service that provides access to the Blimu Runtime SDK
18
+ *
19
+ * This service creates and manages a configured instance of the Blimu Runtime client,
20
+ * making it easy to interact with Blimu APIs from within your NestJS services.
21
+ */
22
+ let BlimuRuntimeService = class BlimuRuntimeService {
23
+ config;
24
+ client;
25
+ constructor(config) {
26
+ this.config = config;
27
+ this.client = new BlimuRuntime({
28
+ apiKeyAuth: this.config.apiSecretKey,
29
+ baseURL: this.config.baseURL || 'https://runtime.blimu.com',
30
+ timeoutMs: this.config.timeoutMs || 30000,
31
+ });
32
+ }
33
+ /**
34
+ * Get the configured Blimu Runtime client
35
+ *
36
+ * @returns The configured BlimuRuntime instance
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * @Injectable()
41
+ * export class MyService {
42
+ * constructor(private readonly blimuRuntime: BlimuRuntimeService) {}
43
+ *
44
+ * async checkUserEntitlement(userId: string, entitlement: string, resourceId: string) {
45
+ * const client = this.blimuRuntime.getClient();
46
+ * return await client.entitlements.checkEntitlement({
47
+ * userId,
48
+ * entitlement,
49
+ * resourceId,
50
+ * });
51
+ * }
52
+ * }
53
+ * ```
54
+ */
55
+ getClient() {
56
+ return this.client;
57
+ }
58
+ /**
59
+ * Convenience method to check entitlements
60
+ *
61
+ * @param userId - The user ID to check entitlements for
62
+ * @param entitlement - The entitlement key to check
63
+ * @param resourceId - The resource ID to check entitlements on
64
+ * @returns Promise resolving to the entitlement check result
65
+ *
66
+ * @example
67
+ * ```typescript
68
+ * const result = await this.blimuRuntime.checkEntitlement(
69
+ * 'user123',
70
+ * 'workspace:read',
71
+ * 'workspace456'
72
+ * );
73
+ *
74
+ * if (result.allowed) {
75
+ * // User has permission
76
+ * }
77
+ * ```
78
+ */
79
+ async checkEntitlement(userId, entitlement, resourceId) {
80
+ return await this.client.entitlements.checkEntitlement({
81
+ userId,
82
+ entitlement,
83
+ resourceId,
84
+ });
85
+ }
86
+ /**
87
+ * Convenience method to assign a role to a user on a resource
88
+ *
89
+ * @param userId - The user ID to assign the role to
90
+ * @param role - The role to assign
91
+ * @param resourceType - The type of resource
92
+ * @param resourceId - The ID of the resource
93
+ * @returns Promise resolving to the role assignment result
94
+ *
95
+ * @example
96
+ * ```typescript
97
+ * await this.blimuRuntime.assignRole(
98
+ * 'user123',
99
+ * 'admin',
100
+ * 'workspace',
101
+ * 'workspace456'
102
+ * );
103
+ * ```
104
+ */
105
+ async assignRole(userId, role, resourceType, resourceId) {
106
+ return await this.client.roles.create(userId, {
107
+ role,
108
+ resourceType,
109
+ resourceId,
110
+ });
111
+ }
112
+ /**
113
+ * Convenience method to remove a role from a user on a resource
114
+ *
115
+ * @param userId - The user ID to remove the role from
116
+ * @param resourceType - The type of resource
117
+ * @param resourceId - The ID of the resource
118
+ * @returns Promise resolving to the role removal result
119
+ *
120
+ * @example
121
+ * ```typescript
122
+ * await this.blimuRuntime.removeRole(
123
+ * 'user123',
124
+ * 'workspace',
125
+ * 'workspace456'
126
+ * );
127
+ * ```
128
+ */
129
+ async removeRole(userId, resourceType, resourceId) {
130
+ return await this.client.roles.delete(userId, resourceType, resourceId);
131
+ }
132
+ /**
133
+ * Convenience method to create workspace resources in bulk
134
+ *
135
+ * @param resources - Array of workspace resource data to create
136
+ * @returns Promise resolving to the bulk creation result
137
+ *
138
+ * @example
139
+ * ```typescript
140
+ * await this.blimuRuntime.bulkCreateWorkspaces([
141
+ * { id: 'workspace456', extraFields: { name: 'My Workspace' } }
142
+ * ]);
143
+ * ```
144
+ */
145
+ async bulkCreateWorkspaces(resources) {
146
+ return await this.client.resources.workspace.bulkCreate({ resources });
147
+ }
148
+ /**
149
+ * Convenience method to delete a workspace resource
150
+ *
151
+ * @param resourceId - The ID of the workspace to delete
152
+ * @returns Promise resolving to the deletion result
153
+ *
154
+ * @example
155
+ * ```typescript
156
+ * await this.blimuRuntime.deleteWorkspace('workspace456');
157
+ * ```
158
+ */
159
+ async deleteWorkspace(resourceId) {
160
+ return await this.client.resources.workspace.delete(resourceId);
161
+ }
162
+ /**
163
+ * Convenience method to create environment resources in bulk
164
+ *
165
+ * @param resources - Array of environment resource data to create
166
+ * @returns Promise resolving to the bulk creation result
167
+ *
168
+ * @example
169
+ * ```typescript
170
+ * await this.blimuRuntime.bulkCreateEnvironments([
171
+ * { id: 'env123', workspaceId: 'workspace456', extraFields: { name: 'Production' } }
172
+ * ]);
173
+ * ```
174
+ */
175
+ async bulkCreateEnvironments(resources) {
176
+ return await this.client.resources.environment.bulkCreate({ resources });
177
+ }
178
+ /**
179
+ * Convenience method to delete an environment resource
180
+ *
181
+ * @param resourceId - The ID of the environment to delete
182
+ * @returns Promise resolving to the deletion result
183
+ *
184
+ * @example
185
+ * ```typescript
186
+ * await this.blimuRuntime.deleteEnvironment('env123');
187
+ * ```
188
+ */
189
+ async deleteEnvironment(resourceId) {
190
+ return await this.client.resources.environment.delete(resourceId);
191
+ }
192
+ };
193
+ BlimuRuntimeService = __decorate([
194
+ Injectable(),
195
+ __param(0, Inject(BLIMU_CONFIG)),
196
+ __metadata("design:paramtypes", [Object])
197
+ ], BlimuRuntimeService);
198
+ export { BlimuRuntimeService };
199
+ //# sourceMappingURL=blimu-runtime.service.js.map
@@ -0,0 +1 @@
1
+ {"version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