@rhino-dev/rhino-nestjs 0.2.5
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/LICENSE +21 -0
- package/README.md +427 -0
- package/dist/blueprint/blueprint-parser.d.ts +130 -0
- package/dist/blueprint/blueprint-parser.js +276 -0
- package/dist/blueprint/blueprint-parser.js.map +1 -0
- package/dist/blueprint/blueprint-runner.d.ts +51 -0
- package/dist/blueprint/blueprint-runner.js +238 -0
- package/dist/blueprint/blueprint-runner.js.map +1 -0
- package/dist/blueprint/blueprint-validator.d.ts +19 -0
- package/dist/blueprint/blueprint-validator.js +163 -0
- package/dist/blueprint/blueprint-validator.js.map +1 -0
- package/dist/blueprint/generators/policy-generator.d.ts +40 -0
- package/dist/blueprint/generators/policy-generator.js +157 -0
- package/dist/blueprint/generators/policy-generator.js.map +1 -0
- package/dist/blueprint/generators/prisma-schema-generator.d.ts +43 -0
- package/dist/blueprint/generators/prisma-schema-generator.js +197 -0
- package/dist/blueprint/generators/prisma-schema-generator.js.map +1 -0
- package/dist/blueprint/generators/resource-definition-generator.d.ts +52 -0
- package/dist/blueprint/generators/resource-definition-generator.js +229 -0
- package/dist/blueprint/generators/resource-definition-generator.js.map +1 -0
- package/dist/blueprint/generators/seeder-generator.d.ts +21 -0
- package/dist/blueprint/generators/seeder-generator.js +135 -0
- package/dist/blueprint/generators/seeder-generator.js.map +1 -0
- package/dist/blueprint/generators/test-generator.d.ts +28 -0
- package/dist/blueprint/generators/test-generator.js +275 -0
- package/dist/blueprint/generators/test-generator.js.map +1 -0
- package/dist/blueprint/manifest-manager.d.ts +58 -0
- package/dist/blueprint/manifest-manager.js +137 -0
- package/dist/blueprint/manifest-manager.js.map +1 -0
- package/dist/cli/commands/blueprint.command.d.ts +16 -0
- package/dist/cli/commands/blueprint.command.js +35 -0
- package/dist/cli/commands/blueprint.command.js.map +1 -0
- package/dist/cli/commands/export-postman.command.d.ts +5 -0
- package/dist/cli/commands/export-postman.command.js +39 -0
- package/dist/cli/commands/export-postman.command.js.map +1 -0
- package/dist/cli/commands/export-types.command.d.ts +4 -0
- package/dist/cli/commands/export-types.command.js +36 -0
- package/dist/cli/commands/export-types.command.js.map +1 -0
- package/dist/cli/commands/generate.command.d.ts +6 -0
- package/dist/cli/commands/generate.command.js +212 -0
- package/dist/cli/commands/generate.command.js.map +1 -0
- package/dist/cli/commands/install.command.d.ts +8 -0
- package/dist/cli/commands/install.command.js +205 -0
- package/dist/cli/commands/install.command.js.map +1 -0
- package/dist/cli/index.d.ts +17 -0
- package/dist/cli/index.js +123 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/utils/io.d.ts +12 -0
- package/dist/cli/utils/io.js +74 -0
- package/dist/cli/utils/io.js.map +1 -0
- package/dist/cli/utils/prompt.d.ts +12 -0
- package/dist/cli/utils/prompt.js +78 -0
- package/dist/cli/utils/prompt.js.map +1 -0
- package/dist/constants/tokens.d.ts +3 -0
- package/dist/constants/tokens.js +7 -0
- package/dist/constants/tokens.js.map +1 -0
- package/dist/controllers/auth.controller.d.ts +59 -0
- package/dist/controllers/auth.controller.js +121 -0
- package/dist/controllers/auth.controller.js.map +1 -0
- package/dist/controllers/global.controller.d.ts +44 -0
- package/dist/controllers/global.controller.js +357 -0
- package/dist/controllers/global.controller.js.map +1 -0
- package/dist/controllers/invitation.controller.d.ts +30 -0
- package/dist/controllers/invitation.controller.js +111 -0
- package/dist/controllers/invitation.controller.js.map +1 -0
- package/dist/controllers/nested.controller.d.ts +12 -0
- package/dist/controllers/nested.controller.js +69 -0
- package/dist/controllers/nested.controller.js.map +1 -0
- package/dist/decorators/index.d.ts +33 -0
- package/dist/decorators/index.js +79 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/errors/rhino-exception.d.ts +24 -0
- package/dist/errors/rhino-exception.js +47 -0
- package/dist/errors/rhino-exception.js.map +1 -0
- package/dist/exporters/postman-exporter.d.ts +21 -0
- package/dist/exporters/postman-exporter.js +396 -0
- package/dist/exporters/postman-exporter.js.map +1 -0
- package/dist/exporters/typescript-exporter.d.ts +23 -0
- package/dist/exporters/typescript-exporter.js +129 -0
- package/dist/exporters/typescript-exporter.js.map +1 -0
- package/dist/guards/jwt-auth.guard.d.ts +16 -0
- package/dist/guards/jwt-auth.guard.js +61 -0
- package/dist/guards/jwt-auth.guard.js.map +1 -0
- package/dist/guards/resource-policy.guard.d.ts +12 -0
- package/dist/guards/resource-policy.guard.js +111 -0
- package/dist/guards/resource-policy.guard.js.map +1 -0
- package/dist/index.d.ts +60 -0
- package/dist/index.js +171 -0
- package/dist/index.js.map +1 -0
- package/dist/interceptors/hidden-columns.interceptor.d.ts +18 -0
- package/dist/interceptors/hidden-columns.interceptor.js +66 -0
- package/dist/interceptors/hidden-columns.interceptor.js.map +1 -0
- package/dist/interceptors/response.interceptor.d.ts +19 -0
- package/dist/interceptors/response.interceptor.js +47 -0
- package/dist/interceptors/response.interceptor.js.map +1 -0
- package/dist/interfaces/rhino-config.interface.d.ts +103 -0
- package/dist/interfaces/rhino-config.interface.js +3 -0
- package/dist/interfaces/rhino-config.interface.js.map +1 -0
- package/dist/interfaces/rhino-request.interface.d.ts +12 -0
- package/dist/interfaces/rhino-request.interface.js +3 -0
- package/dist/interfaces/rhino-request.interface.js.map +1 -0
- package/dist/middleware/resolve-organization.middleware.d.ts +15 -0
- package/dist/middleware/resolve-organization.middleware.js +38 -0
- package/dist/middleware/resolve-organization.middleware.js.map +1 -0
- package/dist/middleware/route-group.middleware.d.ts +17 -0
- package/dist/middleware/route-group.middleware.js +60 -0
- package/dist/middleware/route-group.middleware.js.map +1 -0
- package/dist/middleware/tenant-route-rewrite.d.ts +76 -0
- package/dist/middleware/tenant-route-rewrite.js +124 -0
- package/dist/middleware/tenant-route-rewrite.js.map +1 -0
- package/dist/policies/resource-policy.d.ts +25 -0
- package/dist/policies/resource-policy.js +77 -0
- package/dist/policies/resource-policy.js.map +1 -0
- package/dist/prisma/prisma-soft-delete.extension.d.ts +16 -0
- package/dist/prisma/prisma-soft-delete.extension.js +57 -0
- package/dist/prisma/prisma-soft-delete.extension.js.map +1 -0
- package/dist/prisma/prisma-uuid.extension.d.ts +9 -0
- package/dist/prisma/prisma-uuid.extension.js +28 -0
- package/dist/prisma/prisma-uuid.extension.js.map +1 -0
- package/dist/prisma/prisma.service.d.ts +38 -0
- package/dist/prisma/prisma.service.js +100 -0
- package/dist/prisma/prisma.service.js.map +1 -0
- package/dist/rhino.config.d.ts +43 -0
- package/dist/rhino.config.js +130 -0
- package/dist/rhino.config.js.map +1 -0
- package/dist/rhino.module.d.ts +61 -0
- package/dist/rhino.module.js +268 -0
- package/dist/rhino.module.js.map +1 -0
- package/dist/services/audit.service.d.ts +35 -0
- package/dist/services/audit.service.js +92 -0
- package/dist/services/audit.service.js.map +1 -0
- package/dist/services/auth.service.d.ts +33 -0
- package/dist/services/auth.service.js +157 -0
- package/dist/services/auth.service.js.map +1 -0
- package/dist/services/invitation.service.d.ts +37 -0
- package/dist/services/invitation.service.js +143 -0
- package/dist/services/invitation.service.js.map +1 -0
- package/dist/services/nested.service.d.ts +34 -0
- package/dist/services/nested.service.js +163 -0
- package/dist/services/nested.service.js.map +1 -0
- package/dist/services/organization.service.d.ts +13 -0
- package/dist/services/organization.service.js +60 -0
- package/dist/services/organization.service.js.map +1 -0
- package/dist/services/query-builder.service.d.ts +31 -0
- package/dist/services/query-builder.service.js +151 -0
- package/dist/services/query-builder.service.js.map +1 -0
- package/dist/services/resource.service.d.ts +38 -0
- package/dist/services/resource.service.js +230 -0
- package/dist/services/resource.service.js.map +1 -0
- package/dist/services/route-registration.service.d.ts +40 -0
- package/dist/services/route-registration.service.js +68 -0
- package/dist/services/route-registration.service.js.map +1 -0
- package/dist/services/scope.service.d.ts +16 -0
- package/dist/services/scope.service.js +32 -0
- package/dist/services/scope.service.js.map +1 -0
- package/dist/services/serializer.service.d.ts +36 -0
- package/dist/services/serializer.service.js +90 -0
- package/dist/services/serializer.service.js.map +1 -0
- package/dist/services/validation.service.d.ts +50 -0
- package/dist/services/validation.service.js +203 -0
- package/dist/services/validation.service.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/utils/fk-chain-walker.d.ts +30 -0
- package/dist/utils/fk-chain-walker.js +23 -0
- package/dist/utils/fk-chain-walker.js.map +1 -0
- package/dist/utils/format.d.ts +7 -0
- package/dist/utils/format.js +28 -0
- package/dist/utils/format.js.map +1 -0
- package/dist/utils/model-builder.d.ts +64 -0
- package/dist/utils/model-builder.js +67 -0
- package/dist/utils/model-builder.js.map +1 -0
- package/dist/utils/permission-matcher.d.ts +46 -0
- package/dist/utils/permission-matcher.js +120 -0
- package/dist/utils/permission-matcher.js.map +1 -0
- package/dist/utils/scope-discovery.d.ts +34 -0
- package/dist/utils/scope-discovery.js +102 -0
- package/dist/utils/scope-discovery.js.map +1 -0
- package/package.json +64 -0
- package/stubs/skills/rhino-audit.md +184 -0
- package/stubs/skills/rhino-bugfix.md +117 -0
- package/stubs/skills/rhino-deploy.md +5 -0
- package/stubs/skills/rhino-docs.md +147 -0
- package/stubs/skills/rhino-feature.md +146 -0
- package/stubs/skills/rhino-migrate.md +181 -0
- package/stubs/skills/rhino-model.md +180 -0
- package/stubs/skills/rhino-plan.md +5 -0
- package/stubs/skills/rhino-policy.md +183 -0
- package/stubs/skills/rhino-refactor.md +147 -0
- package/stubs/skills/rhino-review.md +113 -0
- package/stubs/skills/rhino-scope.md +140 -0
- package/stubs/skills/rhino-test.md +233 -0
|
@@ -0,0 +1,268 @@
|
|
|
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
|
+
var RhinoModule_1;
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.RhinoModule = void 0;
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const core_1 = require("@nestjs/core");
|
|
19
|
+
const rhino_config_1 = require("./rhino.config");
|
|
20
|
+
const tokens_1 = require("./constants/tokens");
|
|
21
|
+
const prisma_service_1 = require("./prisma/prisma.service");
|
|
22
|
+
const resource_service_1 = require("./services/resource.service");
|
|
23
|
+
const query_builder_service_1 = require("./services/query-builder.service");
|
|
24
|
+
const serializer_service_1 = require("./services/serializer.service");
|
|
25
|
+
const validation_service_1 = require("./services/validation.service");
|
|
26
|
+
const organization_service_1 = require("./services/organization.service");
|
|
27
|
+
const audit_service_1 = require("./services/audit.service");
|
|
28
|
+
const nested_service_1 = require("./services/nested.service");
|
|
29
|
+
const scope_service_1 = require("./services/scope.service");
|
|
30
|
+
const auth_service_1 = require("./services/auth.service");
|
|
31
|
+
const invitation_service_1 = require("./services/invitation.service");
|
|
32
|
+
const jwt_auth_guard_1 = require("./guards/jwt-auth.guard");
|
|
33
|
+
const resource_policy_guard_1 = require("./guards/resource-policy.guard");
|
|
34
|
+
const global_controller_1 = require("./controllers/global.controller");
|
|
35
|
+
const auth_controller_1 = require("./controllers/auth.controller");
|
|
36
|
+
const invitation_controller_1 = require("./controllers/invitation.controller");
|
|
37
|
+
const nested_controller_1 = require("./controllers/nested.controller");
|
|
38
|
+
const route_group_middleware_1 = require("./middleware/route-group.middleware");
|
|
39
|
+
const resolve_organization_middleware_1 = require("./middleware/resolve-organization.middleware");
|
|
40
|
+
const ACTION_TO_METHOD = {
|
|
41
|
+
index: common_1.RequestMethod.GET,
|
|
42
|
+
show: common_1.RequestMethod.GET,
|
|
43
|
+
store: common_1.RequestMethod.POST,
|
|
44
|
+
update: common_1.RequestMethod.PUT,
|
|
45
|
+
destroy: common_1.RequestMethod.DELETE,
|
|
46
|
+
trashed: common_1.RequestMethod.GET,
|
|
47
|
+
restore: common_1.RequestMethod.POST,
|
|
48
|
+
forceDelete: common_1.RequestMethod.DELETE,
|
|
49
|
+
};
|
|
50
|
+
function actionPath(slug, action) {
|
|
51
|
+
switch (action) {
|
|
52
|
+
case 'index':
|
|
53
|
+
case 'store':
|
|
54
|
+
return slug;
|
|
55
|
+
case 'trashed':
|
|
56
|
+
return `${slug}/trashed`;
|
|
57
|
+
case 'show':
|
|
58
|
+
case 'update':
|
|
59
|
+
case 'destroy':
|
|
60
|
+
return `${slug}/:id`;
|
|
61
|
+
case 'restore':
|
|
62
|
+
return `${slug}/:id/restore`;
|
|
63
|
+
case 'forceDelete':
|
|
64
|
+
return `${slug}/:id/force-delete`;
|
|
65
|
+
default:
|
|
66
|
+
return slug;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Rhino NestJS dynamic module.
|
|
71
|
+
*
|
|
72
|
+
* Example (synchronous):
|
|
73
|
+
*
|
|
74
|
+
* RhinoModule.forRoot({
|
|
75
|
+
* prismaClient: new PrismaClient(),
|
|
76
|
+
* models: {
|
|
77
|
+
* posts: { model: 'post', policy: PostPolicy, belongsToOrganization: true },
|
|
78
|
+
* },
|
|
79
|
+
* });
|
|
80
|
+
*
|
|
81
|
+
* Example (async — reading from a ConfigService):
|
|
82
|
+
*
|
|
83
|
+
* RhinoModule.forRootAsync({
|
|
84
|
+
* imports: [ConfigModule],
|
|
85
|
+
* inject: [ConfigService, PrismaService],
|
|
86
|
+
* middleware: [MyRateLimitMw], // <-- list middleware classes here
|
|
87
|
+
* useFactory: (cfg, prisma) => ({
|
|
88
|
+
* prismaClient: prisma,
|
|
89
|
+
* models: { ... },
|
|
90
|
+
* }),
|
|
91
|
+
* });
|
|
92
|
+
*/
|
|
93
|
+
let RhinoModule = RhinoModule_1 = class RhinoModule {
|
|
94
|
+
config;
|
|
95
|
+
options;
|
|
96
|
+
constructor(config, options) {
|
|
97
|
+
this.config = config;
|
|
98
|
+
this.options = options;
|
|
99
|
+
}
|
|
100
|
+
configure(consumer) {
|
|
101
|
+
const opts = this.options ?? {};
|
|
102
|
+
const cfg = this.config;
|
|
103
|
+
if (!cfg)
|
|
104
|
+
return;
|
|
105
|
+
if (opts.autoRouteGroupMiddleware !== false) {
|
|
106
|
+
consumer.apply(route_group_middleware_1.RouteGroupMiddleware).forRoutes('*');
|
|
107
|
+
}
|
|
108
|
+
if (opts.autoModelMiddleware !== false) {
|
|
109
|
+
for (const [slug, reg] of Object.entries(cfg.models ?? {})) {
|
|
110
|
+
const baseMw = (reg.middleware ?? []);
|
|
111
|
+
if (baseMw.length > 0) {
|
|
112
|
+
consumer.apply(...baseMw).forRoutes({ path: slug, method: common_1.RequestMethod.ALL }, { path: `${slug}/*`, method: common_1.RequestMethod.ALL });
|
|
113
|
+
}
|
|
114
|
+
for (const [action, mwList] of Object.entries(reg.actionMiddleware ?? {})) {
|
|
115
|
+
const list = (mwList ?? []);
|
|
116
|
+
if (list.length === 0)
|
|
117
|
+
continue;
|
|
118
|
+
const method = ACTION_TO_METHOD[action] ?? common_1.RequestMethod.ALL;
|
|
119
|
+
consumer.apply(...list).forRoutes({ path: actionPath(slug, action), method });
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (opts.autoTenantMiddleware !== false &&
|
|
124
|
+
(cfg.multiTenant?.organizationIdentifierColumn || cfg.multiTenant?.enabled)) {
|
|
125
|
+
consumer.apply(resolve_organization_middleware_1.ResolveOrganizationMiddleware).forRoutes('*');
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Synchronous registration. All middleware classes are collected from the
|
|
130
|
+
* passed config at build time, so no extra `middleware` option is needed.
|
|
131
|
+
*/
|
|
132
|
+
static forRoot(config, options = {}) {
|
|
133
|
+
const normalized = (0, rhino_config_1.normalizeConfig)(config);
|
|
134
|
+
const middlewareFromConfig = RhinoModule_1.collectModelMiddleware(normalized);
|
|
135
|
+
return RhinoModule_1.build({
|
|
136
|
+
configProviders: [
|
|
137
|
+
{ provide: tokens_1.RHINO_CONFIG, useValue: normalized },
|
|
138
|
+
{
|
|
139
|
+
provide: tokens_1.RHINO_PRISMA_CLIENT,
|
|
140
|
+
useValue: normalized.prismaClient ?? null,
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
imports: [],
|
|
144
|
+
options,
|
|
145
|
+
middlewareClasses: middlewareFromConfig,
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Asynchronous registration. Middleware classes referenced by models must
|
|
150
|
+
* be declared via `options.middleware` because NestJS providers cannot be
|
|
151
|
+
* resolved from an async useFactory.
|
|
152
|
+
*/
|
|
153
|
+
static forRootAsync(options) {
|
|
154
|
+
const configProvider = {
|
|
155
|
+
provide: tokens_1.RHINO_CONFIG,
|
|
156
|
+
useFactory: async (...args) => (0, rhino_config_1.normalizeConfig)(await options.useFactory(...args)),
|
|
157
|
+
inject: options.inject ?? [],
|
|
158
|
+
};
|
|
159
|
+
const prismaProvider = {
|
|
160
|
+
provide: tokens_1.RHINO_PRISMA_CLIENT,
|
|
161
|
+
useFactory: (cfg) => cfg.prismaClient ?? null,
|
|
162
|
+
inject: [tokens_1.RHINO_CONFIG],
|
|
163
|
+
};
|
|
164
|
+
return RhinoModule_1.build({
|
|
165
|
+
configProviders: [configProvider, prismaProvider],
|
|
166
|
+
imports: options.imports ?? [],
|
|
167
|
+
options,
|
|
168
|
+
middlewareClasses: (options.middleware ?? []),
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
static build(args) {
|
|
172
|
+
const opts = args.options;
|
|
173
|
+
const guardProviders = [];
|
|
174
|
+
if (opts.autoAuthGuard)
|
|
175
|
+
guardProviders.push({ provide: core_1.APP_GUARD, useClass: jwt_auth_guard_1.JwtAuthGuard });
|
|
176
|
+
if (opts.autoPolicyGuard)
|
|
177
|
+
guardProviders.push({ provide: core_1.APP_GUARD, useClass: resource_policy_guard_1.ResourcePolicyGuard });
|
|
178
|
+
return {
|
|
179
|
+
module: RhinoModule_1,
|
|
180
|
+
imports: args.imports,
|
|
181
|
+
controllers: opts.registerControllers !== false
|
|
182
|
+
? [global_controller_1.GlobalController, auth_controller_1.AuthController, invitation_controller_1.InvitationController, nested_controller_1.NestedController]
|
|
183
|
+
: [],
|
|
184
|
+
providers: [
|
|
185
|
+
...args.configProviders,
|
|
186
|
+
{ provide: tokens_1.RHINO_MODULE_OPTIONS, useValue: opts },
|
|
187
|
+
...RhinoModule_1.coreProviders(),
|
|
188
|
+
jwt_auth_guard_1.JwtAuthGuard,
|
|
189
|
+
resource_policy_guard_1.ResourcePolicyGuard,
|
|
190
|
+
route_group_middleware_1.RouteGroupMiddleware,
|
|
191
|
+
resolve_organization_middleware_1.ResolveOrganizationMiddleware,
|
|
192
|
+
...dedupeTypes(args.middlewareClasses),
|
|
193
|
+
...guardProviders,
|
|
194
|
+
],
|
|
195
|
+
exports: RhinoModule_1.coreExports(),
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
static collectModelMiddleware(config) {
|
|
199
|
+
const set = new Set();
|
|
200
|
+
for (const reg of Object.values(config.models ?? {})) {
|
|
201
|
+
for (const mw of (reg.middleware ?? []))
|
|
202
|
+
set.add(mw);
|
|
203
|
+
for (const mws of Object.values(reg.actionMiddleware ?? {})) {
|
|
204
|
+
for (const mw of (mws ?? []))
|
|
205
|
+
set.add(mw);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return Array.from(set);
|
|
209
|
+
}
|
|
210
|
+
static coreProviders() {
|
|
211
|
+
return [
|
|
212
|
+
rhino_config_1.RhinoConfigService,
|
|
213
|
+
prisma_service_1.PrismaService,
|
|
214
|
+
resource_service_1.ResourceService,
|
|
215
|
+
query_builder_service_1.QueryBuilderService,
|
|
216
|
+
serializer_service_1.SerializerService,
|
|
217
|
+
validation_service_1.ValidationService,
|
|
218
|
+
organization_service_1.OrganizationService,
|
|
219
|
+
audit_service_1.AuditService,
|
|
220
|
+
nested_service_1.NestedService,
|
|
221
|
+
scope_service_1.ScopeService,
|
|
222
|
+
auth_service_1.AuthService,
|
|
223
|
+
invitation_service_1.InvitationService,
|
|
224
|
+
];
|
|
225
|
+
}
|
|
226
|
+
static coreExports() {
|
|
227
|
+
return [
|
|
228
|
+
// Injection tokens (BP-010 — surfaced for consumer middleware/services)
|
|
229
|
+
tokens_1.RHINO_CONFIG,
|
|
230
|
+
tokens_1.RHINO_PRISMA_CLIENT,
|
|
231
|
+
tokens_1.RHINO_MODULE_OPTIONS,
|
|
232
|
+
rhino_config_1.RhinoConfigService,
|
|
233
|
+
prisma_service_1.PrismaService,
|
|
234
|
+
resource_service_1.ResourceService,
|
|
235
|
+
query_builder_service_1.QueryBuilderService,
|
|
236
|
+
serializer_service_1.SerializerService,
|
|
237
|
+
validation_service_1.ValidationService,
|
|
238
|
+
organization_service_1.OrganizationService,
|
|
239
|
+
audit_service_1.AuditService,
|
|
240
|
+
nested_service_1.NestedService,
|
|
241
|
+
scope_service_1.ScopeService,
|
|
242
|
+
auth_service_1.AuthService,
|
|
243
|
+
invitation_service_1.InvitationService,
|
|
244
|
+
jwt_auth_guard_1.JwtAuthGuard,
|
|
245
|
+
resource_policy_guard_1.ResourcePolicyGuard,
|
|
246
|
+
];
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
exports.RhinoModule = RhinoModule;
|
|
250
|
+
exports.RhinoModule = RhinoModule = RhinoModule_1 = __decorate([
|
|
251
|
+
(0, common_1.Global)(),
|
|
252
|
+
(0, common_1.Module)({}),
|
|
253
|
+
__param(0, (0, common_1.Inject)(tokens_1.RHINO_CONFIG)),
|
|
254
|
+
__param(1, (0, common_1.Inject)(tokens_1.RHINO_MODULE_OPTIONS)),
|
|
255
|
+
__metadata("design:paramtypes", [Object, Object])
|
|
256
|
+
], RhinoModule);
|
|
257
|
+
function dedupeTypes(list) {
|
|
258
|
+
const seen = new Set();
|
|
259
|
+
const out = [];
|
|
260
|
+
for (const t of list) {
|
|
261
|
+
if (!seen.has(t)) {
|
|
262
|
+
seen.add(t);
|
|
263
|
+
out.push(t);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return out;
|
|
267
|
+
}
|
|
268
|
+
//# sourceMappingURL=rhino.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rhino.module.js","sourceRoot":"","sources":["../src/rhino.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAUwB;AACxB,uCAAyC;AACzC,iDAAqE;AACrE,+CAI4B;AAK5B,4DAAwD;AACxD,kEAA8D;AAC9D,4EAAuE;AACvE,sEAAkE;AAClE,sEAAkE;AAClE,0EAAsE;AACtE,4DAAwD;AACxD,8DAA0D;AAC1D,4DAAwD;AACxD,0DAAsD;AACtD,sEAAkE;AAClE,4DAAuD;AACvD,0EAAqE;AACrE,uEAAmE;AACnE,mEAA+D;AAC/D,+EAA2E;AAC3E,uEAAmE;AACnE,gFAA2E;AAC3E,kGAA6F;AAE7F,MAAM,gBAAgB,GAAkC;IACtD,KAAK,EAAE,sBAAa,CAAC,GAAG;IACxB,IAAI,EAAE,sBAAa,CAAC,GAAG;IACvB,KAAK,EAAE,sBAAa,CAAC,IAAI;IACzB,MAAM,EAAE,sBAAa,CAAC,GAAG;IACzB,OAAO,EAAE,sBAAa,CAAC,MAAM;IAC7B,OAAO,EAAE,sBAAa,CAAC,GAAG;IAC1B,OAAO,EAAE,s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AE,CAAC;YACjB,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YACZ,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACd,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { PrismaService } from '../prisma/prisma.service';
|
|
2
|
+
import type { ModelRegistration } from '../interfaces/rhino-config.interface';
|
|
3
|
+
export interface AuditContext {
|
|
4
|
+
user?: any;
|
|
5
|
+
organization?: any;
|
|
6
|
+
ipAddress?: string;
|
|
7
|
+
userAgent?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Writes audit log entries. One audit row per CRUD mutation with
|
|
11
|
+
* action ∈ {created, updated, deleted, forceDeleted, restored}.
|
|
12
|
+
*/
|
|
13
|
+
export declare class AuditService {
|
|
14
|
+
private readonly prisma;
|
|
15
|
+
private readonly logger;
|
|
16
|
+
constructor(prisma: PrismaService);
|
|
17
|
+
private delegate;
|
|
18
|
+
log(params: {
|
|
19
|
+
auditableType: string;
|
|
20
|
+
auditableId: any;
|
|
21
|
+
action: 'created' | 'updated' | 'deleted' | 'forceDeleted' | 'restored';
|
|
22
|
+
oldValues?: any;
|
|
23
|
+
newValues?: any;
|
|
24
|
+
ctx?: AuditContext;
|
|
25
|
+
excludeFields?: string[];
|
|
26
|
+
}): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Return the subset of changed fields from a Prisma update.
|
|
29
|
+
* Returns null if no meaningful changes (beyond excluded fields).
|
|
30
|
+
*/
|
|
31
|
+
diff(oldRecord: any, newRecord: any, reg: ModelRegistration): {
|
|
32
|
+
old: any;
|
|
33
|
+
new: any;
|
|
34
|
+
} | null;
|
|
35
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
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 AuditService_1;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.AuditService = void 0;
|
|
14
|
+
const common_1 = require("@nestjs/common");
|
|
15
|
+
const prisma_service_1 = require("../prisma/prisma.service");
|
|
16
|
+
const BASE_AUDIT_EXCLUDE = ['password', 'rememberToken', 'remember_token'];
|
|
17
|
+
/**
|
|
18
|
+
* Writes audit log entries. One audit row per CRUD mutation with
|
|
19
|
+
* action ∈ {created, updated, deleted, forceDeleted, restored}.
|
|
20
|
+
*/
|
|
21
|
+
let AuditService = AuditService_1 = class AuditService {
|
|
22
|
+
prisma;
|
|
23
|
+
logger = new common_1.Logger(AuditService_1.name);
|
|
24
|
+
constructor(prisma) {
|
|
25
|
+
this.prisma = prisma;
|
|
26
|
+
}
|
|
27
|
+
delegate() {
|
|
28
|
+
return this.prisma.model('auditLog');
|
|
29
|
+
}
|
|
30
|
+
async log(params) {
|
|
31
|
+
const excluded = new Set([...(params.excludeFields ?? []), ...BASE_AUDIT_EXCLUDE]);
|
|
32
|
+
const filterExcluded = (obj) => {
|
|
33
|
+
if (!obj)
|
|
34
|
+
return obj;
|
|
35
|
+
const out = {};
|
|
36
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
37
|
+
if (!excluded.has(k))
|
|
38
|
+
out[k] = v;
|
|
39
|
+
}
|
|
40
|
+
return out;
|
|
41
|
+
};
|
|
42
|
+
try {
|
|
43
|
+
await this.delegate().create({
|
|
44
|
+
data: {
|
|
45
|
+
auditableType: params.auditableType,
|
|
46
|
+
auditableId: params.auditableId,
|
|
47
|
+
action: params.action,
|
|
48
|
+
oldValues: filterExcluded(params.oldValues),
|
|
49
|
+
newValues: filterExcluded(params.newValues),
|
|
50
|
+
userId: params.ctx?.user?.id ?? null,
|
|
51
|
+
organizationId: params.ctx?.organization?.id ?? null,
|
|
52
|
+
ipAddress: params.ctx?.ipAddress ?? null,
|
|
53
|
+
userAgent: params.ctx?.userAgent ?? null,
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
this.logger.warn(`AuditService: failed to write audit entry for ${params.auditableType}#${params.auditableId} (${params.action}): ${err.message}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Return the subset of changed fields from a Prisma update.
|
|
63
|
+
* Returns null if no meaningful changes (beyond excluded fields).
|
|
64
|
+
*/
|
|
65
|
+
diff(oldRecord, newRecord, reg) {
|
|
66
|
+
if (!oldRecord || !newRecord)
|
|
67
|
+
return null;
|
|
68
|
+
const excluded = new Set([...(reg.auditExclude ?? []), ...BASE_AUDIT_EXCLUDE, 'updatedAt', 'updated_at']);
|
|
69
|
+
const oldOut = {};
|
|
70
|
+
const newOut = {};
|
|
71
|
+
const keys = new Set([...Object.keys(oldRecord), ...Object.keys(newRecord)]);
|
|
72
|
+
for (const k of keys) {
|
|
73
|
+
if (excluded.has(k))
|
|
74
|
+
continue;
|
|
75
|
+
const o = oldRecord[k];
|
|
76
|
+
const n = newRecord[k];
|
|
77
|
+
if (JSON.stringify(o) !== JSON.stringify(n)) {
|
|
78
|
+
oldOut[k] = o;
|
|
79
|
+
newOut[k] = n;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (Object.keys(newOut).length === 0)
|
|
83
|
+
return null;
|
|
84
|
+
return { old: oldOut, new: newOut };
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
exports.AuditService = AuditService;
|
|
88
|
+
exports.AuditService = AuditService = AuditService_1 = __decorate([
|
|
89
|
+
(0, common_1.Injectable)(),
|
|
90
|
+
__metadata("design:paramtypes", [prisma_service_1.PrismaService])
|
|
91
|
+
], AuditService);
|
|
92
|
+
//# sourceMappingURL=audit.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit.service.js","sourceRoot":"","sources":["../../src/services/audit.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAoD;AACpD,6DAAyD;AAUzD,MAAM,kBAAkB,GAAG,CAAC,UAAU,EAAE,eAAe,EAAE,gBAAgB,CAAC,CAAC;AAE3E;;;GAGG;AAEI,IAAM,YAAY,oBAAlB,MAAM,YAAY;IAGM;IAFZ,MAAM,GAAG,IAAI,eAAM,CAAC,cAAY,CAAC,IAAI,CAAC,CAAC;IAExD,YAA6B,MAAqB;QAArB,WAAM,GAAN,MAAM,CAAe;IAAG,CAAC;IAE9C,QAAQ;QACd,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACvC,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,MAQT;QACC,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,aAAa,IAAI,EAAE,CAAC,EAAE,GAAG,kBAAkB,CAAC,CAAC,CAAC;QACnF,MAAM,cAAc,GAAG,CAAC,GAAQ,EAAE,EAAE;YAClC,IAAI,CAAC,GAAG;gBAAE,OAAO,GAAG,CAAC;YACrB,MAAM,GAAG,GAAQ,EAAE,CAAC;YACpB,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;gBACzC,IAAI,CAAC,QAAQ,CAAC,GAAG,C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,CAAC;QAC1G,MAAM,MAAM,GAAQ,EAAE,CAAC;QACvB,MAAM,MAAM,GAAQ,EAAE,CAAC;QACvB,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QAC7E,KAAK,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC;YACrB,IAAI,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;gBAAE,SAAS;YAC9B,MAAM,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;YACvB,MAAM,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;YACvB,IAAI,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC5C,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;gBACd,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;YAChB,CAAC;QACH,CAAC;QACD,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC;QAClD,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC;IACtC,CAAC;CACF,CAAA;AAtEY,oCAAY;uBAAZ,YAAY;IADxB,IAAA,mBAAU,GAAE;qCAI0B,8BAAa;GAHvC,YAAY,CAsExB"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { PrismaService } from '../prisma/prisma.service';
|
|
2
|
+
import { RhinoConfigService } from '../rhino.config';
|
|
3
|
+
export interface LoginResult {
|
|
4
|
+
token: string;
|
|
5
|
+
organizationSlug?: string;
|
|
6
|
+
user: any;
|
|
7
|
+
}
|
|
8
|
+
export interface TokenPayload {
|
|
9
|
+
sub: number | string;
|
|
10
|
+
email?: string;
|
|
11
|
+
iat?: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Authentication primitives: login, logout, password hashing,
|
|
15
|
+
* token issuance, password recovery flow.
|
|
16
|
+
*/
|
|
17
|
+
export declare class AuthService {
|
|
18
|
+
private readonly prisma;
|
|
19
|
+
private readonly config;
|
|
20
|
+
private readonly logger;
|
|
21
|
+
constructor(prisma: PrismaService, config: RhinoConfigService);
|
|
22
|
+
private userDelegate;
|
|
23
|
+
hashPassword(plain: string): Promise<string>;
|
|
24
|
+
checkPassword(plain: string, hashed: string): Promise<boolean>;
|
|
25
|
+
signToken(payload: TokenPayload): string;
|
|
26
|
+
verifyToken(token: string): TokenPayload;
|
|
27
|
+
login(email: string, password: string): Promise<LoginResult>;
|
|
28
|
+
logout(_user: any): Promise<void>;
|
|
29
|
+
requestPasswordRecovery(email: string): Promise<{
|
|
30
|
+
token: string;
|
|
31
|
+
} | null>;
|
|
32
|
+
resetPassword(email: string, token: string, newPassword: string): Promise<void>;
|
|
33
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
+
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;
|
|
22
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
+
};
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
42
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
43
|
+
};
|
|
44
|
+
var AuthService_1;
|
|
45
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
+
exports.AuthService = void 0;
|
|
47
|
+
const common_1 = require("@nestjs/common");
|
|
48
|
+
const rhino_exception_1 = require("../errors/rhino-exception");
|
|
49
|
+
const bcrypt = __importStar(require("bcryptjs"));
|
|
50
|
+
const jwt = __importStar(require("jsonwebtoken"));
|
|
51
|
+
const crypto_1 = require("crypto");
|
|
52
|
+
const prisma_service_1 = require("../prisma/prisma.service");
|
|
53
|
+
const rhino_config_1 = require("../rhino.config");
|
|
54
|
+
/**
|
|
55
|
+
* Authentication primitives: login, logout, password hashing,
|
|
56
|
+
* token issuance, password recovery flow.
|
|
57
|
+
*/
|
|
58
|
+
let AuthService = AuthService_1 = class AuthService {
|
|
59
|
+
prisma;
|
|
60
|
+
config;
|
|
61
|
+
logger = new common_1.Logger(AuthService_1.name);
|
|
62
|
+
constructor(prisma, config) {
|
|
63
|
+
this.prisma = prisma;
|
|
64
|
+
this.config = config;
|
|
65
|
+
}
|
|
66
|
+
userDelegate() {
|
|
67
|
+
const modelName = this.config.authConfig().userModel;
|
|
68
|
+
return this.prisma.model(modelName);
|
|
69
|
+
}
|
|
70
|
+
async hashPassword(plain) {
|
|
71
|
+
return bcrypt.hash(plain, 10);
|
|
72
|
+
}
|
|
73
|
+
async checkPassword(plain, hashed) {
|
|
74
|
+
if (!hashed)
|
|
75
|
+
return false;
|
|
76
|
+
return bcrypt.compare(plain, hashed);
|
|
77
|
+
}
|
|
78
|
+
signToken(payload) {
|
|
79
|
+
const { jwtSecret, jwtExpiresIn } = this.config.authConfig();
|
|
80
|
+
return jwt.sign(payload, jwtSecret, { expiresIn: jwtExpiresIn });
|
|
81
|
+
}
|
|
82
|
+
verifyToken(token) {
|
|
83
|
+
const { jwtSecret } = this.config.authConfig();
|
|
84
|
+
try {
|
|
85
|
+
return jwt.verify(token, jwtSecret);
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
throw rhino_exception_1.RhinoException.unauthorized('Invalid or expired token');
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
async login(email, password) {
|
|
92
|
+
const auth = this.config.authConfig();
|
|
93
|
+
const user = await this.userDelegate().findFirst({
|
|
94
|
+
where: { [auth.emailField]: email },
|
|
95
|
+
include: { userRoles: { include: { organization: true, role: true } } },
|
|
96
|
+
}).catch(() => null);
|
|
97
|
+
if (!user)
|
|
98
|
+
throw rhino_exception_1.RhinoException.unauthorized('Invalid credentials');
|
|
99
|
+
const hashed = user[auth.passwordField];
|
|
100
|
+
const ok = await this.checkPassword(password, hashed);
|
|
101
|
+
if (!ok)
|
|
102
|
+
throw rhino_exception_1.RhinoException.unauthorized('Invalid credentials');
|
|
103
|
+
const token = this.signToken({ sub: user.id, email });
|
|
104
|
+
const organizationSlug = user.userRoles?.[0]?.organization?.slug;
|
|
105
|
+
return { token, organizationSlug, user };
|
|
106
|
+
}
|
|
107
|
+
async logout(_user) {
|
|
108
|
+
// JWT stateless; consumer can add blacklist logic via hooks.
|
|
109
|
+
}
|
|
110
|
+
async requestPasswordRecovery(email) {
|
|
111
|
+
const user = await this.userDelegate().findFirst({ where: { email } }).catch(() => null);
|
|
112
|
+
if (!user)
|
|
113
|
+
return null;
|
|
114
|
+
const token = (0, crypto_1.randomBytes)(32).toString('hex');
|
|
115
|
+
try {
|
|
116
|
+
await this.prisma.model('passwordResetToken').upsert({
|
|
117
|
+
where: { email },
|
|
118
|
+
update: { token, createdAt: new Date() },
|
|
119
|
+
create: { email, token, createdAt: new Date() },
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
catch (err) {
|
|
123
|
+
this.logger.warn(`AuthService: could not persist password reset token (${err.message}). ` +
|
|
124
|
+
'Add a `PasswordResetToken` model to your Prisma schema to enable this feature.');
|
|
125
|
+
}
|
|
126
|
+
return { token };
|
|
127
|
+
}
|
|
128
|
+
async resetPassword(email, token, newPassword) {
|
|
129
|
+
let reset = null;
|
|
130
|
+
try {
|
|
131
|
+
reset = await this.prisma.model('passwordResetToken').findFirst({
|
|
132
|
+
where: { email, token },
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
throw new common_1.BadRequestException('Password reset not available');
|
|
137
|
+
}
|
|
138
|
+
if (!reset)
|
|
139
|
+
throw new common_1.BadRequestException('Invalid token');
|
|
140
|
+
const hashed = await this.hashPassword(newPassword);
|
|
141
|
+
await this.userDelegate().update({
|
|
142
|
+
where: { email },
|
|
143
|
+
data: { password: hashed },
|
|
144
|
+
});
|
|
145
|
+
try {
|
|
146
|
+
await this.prisma.model('passwordResetToken').delete({ where: { email } });
|
|
147
|
+
}
|
|
148
|
+
catch { /* ignore */ }
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
exports.AuthService = AuthService;
|
|
152
|
+
exports.AuthService = AuthService = AuthService_1 = __decorate([
|
|
153
|
+
(0, common_1.Injectable)(),
|
|
154
|
+
__metadata("design:paramtypes", [prisma_service_1.PrismaService,
|
|
155
|
+
rhino_config_1.RhinoConfigService])
|
|
156
|
+
], AuthService);
|
|
157
|
+
//# sourceMappingURL=auth.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.service.js","sourceRoot":"","sources":["../../src/services/auth.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAIwB;AACxB,+DAA2D;AAC3D,iDAAmC;AACnC,kDAAoC;AACpC,mCAAqC;AACrC,6DAAyD;AACzD,kDAAqD;AAcrD;;;GAGG;AAEI,IAAM,WAAW,mBAAjB,MAAM,WAAW;IAIH;IACA;IAJF,MAAM,GAAG,IAAI,eAAM,CAAC,aAAW,CAAC,IAAI,CAAC,CAAC;IAEvD,YACmB,MAAqB,EACrB,MAA0B;QAD1B,WAAM,GAAN,MAAM,CAAe;QACrB,WAAM,GAAN,MAAM,CAAoB;IAC1C,CAAC;IAEI,YAAY;QAClB,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC,SAAS,CAAC;QACrD,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IACtC,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,KAAa;QAC9B,OAAO,MAAM,CAAC,IAAI,CAAC,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Aa;QACb,iCAAkB;GALlC,WAAW,CA+FvB"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { PrismaService } from '../prisma/prisma.service';
|
|
2
|
+
import { RhinoConfigService } from '../rhino.config';
|
|
3
|
+
export interface CreateInvitationInput {
|
|
4
|
+
email: string;
|
|
5
|
+
roleId: number;
|
|
6
|
+
organization: any;
|
|
7
|
+
invitedBy: any;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Invitation lifecycle: create/resend/cancel/accept with token-based acceptance.
|
|
11
|
+
* Mirrors Laravel's InvitationController + OrganizationInvitation model.
|
|
12
|
+
*/
|
|
13
|
+
export declare class InvitationService {
|
|
14
|
+
private readonly prisma;
|
|
15
|
+
private readonly config;
|
|
16
|
+
constructor(prisma: PrismaService, config: RhinoConfigService);
|
|
17
|
+
private delegate;
|
|
18
|
+
private generateToken;
|
|
19
|
+
private expiresAt;
|
|
20
|
+
list(organizationId: number, status?: string): Promise<any>;
|
|
21
|
+
create(input: CreateInvitationInput): Promise<any>;
|
|
22
|
+
resend(id: number): Promise<any>;
|
|
23
|
+
cancel(id: number): Promise<any>;
|
|
24
|
+
accept(token: string, userId?: number): Promise<{
|
|
25
|
+
requiresRegistration: boolean;
|
|
26
|
+
organization: any;
|
|
27
|
+
role: any;
|
|
28
|
+
email: any;
|
|
29
|
+
accepted?: undefined;
|
|
30
|
+
} | {
|
|
31
|
+
accepted: boolean;
|
|
32
|
+
organization: any;
|
|
33
|
+
requiresRegistration?: undefined;
|
|
34
|
+
role?: undefined;
|
|
35
|
+
email?: undefined;
|
|
36
|
+
}>;
|
|
37
|
+
}
|