@kosha-ai/server 0.1.0 → 0.2.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.
- package/dist/auth/api-key.guard.d.ts +7 -2
- package/dist/auth/api-key.guard.d.ts.map +1 -1
- package/dist/auth/api-key.guard.js +28 -8
- package/dist/auth/auth.factory.d.ts +15 -1
- package/dist/auth/auth.factory.d.ts.map +1 -1
- package/dist/auth/auth.factory.js +48 -2
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +24 -6
- package/dist/configurations/configurations.controller.d.ts +11 -136
- package/dist/configurations/configurations.controller.d.ts.map +1 -1
- package/dist/configurations/configurations.controller.js +58 -25
- package/dist/configurations/configurations.module.d.ts.map +1 -1
- package/dist/configurations/configurations.module.js +4 -1
- package/dist/configurations/configurations.repository.d.ts +43 -0
- package/dist/configurations/configurations.repository.d.ts.map +1 -0
- package/dist/configurations/configurations.repository.js +76 -0
- package/dist/configurations/configurations.service.d.ts +38 -194
- package/dist/configurations/configurations.service.d.ts.map +1 -1
- package/dist/configurations/configurations.service.js +118 -110
- package/dist/configurations/dto/create-configuration.dto.d.ts +8 -0
- package/dist/configurations/dto/create-configuration.dto.d.ts.map +1 -0
- package/dist/configurations/dto/create-configuration.dto.js +54 -0
- package/dist/configurations/dto/update-configuration.dto.d.ts +7 -0
- package/dist/configurations/dto/update-configuration.dto.d.ts.map +1 -0
- package/dist/configurations/dto/update-configuration.dto.js +39 -0
- package/dist/connect/connect.controller.d.ts +6 -8
- package/dist/connect/connect.controller.d.ts.map +1 -1
- package/dist/connect/connect.controller.js +45 -15
- package/dist/connect/connect.module.d.ts.map +1 -1
- package/dist/connect/connect.module.js +4 -2
- package/dist/connect/connect.repository.d.ts +78 -0
- package/dist/connect/connect.repository.d.ts.map +1 -0
- package/dist/connect/connect.repository.js +146 -0
- package/dist/connect/connect.service.d.ts +28 -19
- package/dist/connect/connect.service.d.ts.map +1 -1
- package/dist/connect/connect.service.js +149 -163
- package/dist/connect/dto/create-connect-session.dto.d.ts +8 -0
- package/dist/connect/dto/create-connect-session.dto.d.ts.map +1 -0
- package/dist/connect/dto/create-connect-session.dto.js +55 -0
- package/dist/connect/dto/create-test-session.dto.d.ts +10 -0
- package/dist/connect/dto/create-test-session.dto.d.ts.map +1 -0
- package/dist/connect/dto/create-test-session.dto.js +34 -0
- package/dist/connections/connections.controller.d.ts +8 -61
- package/dist/connections/connections.controller.d.ts.map +1 -1
- package/dist/connections/connections.controller.js +31 -9
- package/dist/connections/connections.module.d.ts.map +1 -1
- package/dist/connections/connections.module.js +4 -1
- package/dist/connections/connections.repository.d.ts +24 -0
- package/dist/connections/connections.repository.d.ts.map +1 -0
- package/dist/connections/connections.repository.js +66 -0
- package/dist/connections/connections.service.d.ts +24 -69
- package/dist/connections/connections.service.d.ts.map +1 -1
- package/dist/connections/connections.service.js +59 -56
- package/dist/connections/dto/list-connections.dto.d.ts +5 -0
- package/dist/connections/dto/list-connections.dto.d.ts.map +1 -0
- package/dist/connections/dto/list-connections.dto.js +25 -0
- package/dist/connections/environment-connections.controller.d.ts +26 -0
- package/dist/connections/environment-connections.controller.d.ts.map +1 -0
- package/dist/connections/environment-connections.controller.js +81 -0
- package/dist/connections/environment-connections.module.d.ts +11 -0
- package/dist/connections/environment-connections.module.d.ts.map +1 -0
- package/dist/connections/environment-connections.module.js +21 -0
- package/dist/credentials/credentials.module.js +3 -3
- package/dist/credentials/credentials.repository.d.ts +8 -0
- package/dist/credentials/credentials.repository.d.ts.map +1 -0
- package/dist/credentials/credentials.repository.js +21 -0
- package/dist/credentials/credentials.service.d.ts +19 -29
- package/dist/credentials/credentials.service.d.ts.map +1 -1
- package/dist/credentials/credentials.service.js +84 -57
- package/dist/crypto/credential-envelope.d.ts +56 -0
- package/dist/crypto/credential-envelope.d.ts.map +1 -0
- package/dist/crypto/credential-envelope.js +70 -0
- package/dist/crypto/crypto.service.d.ts +8 -0
- package/dist/crypto/crypto.service.d.ts.map +1 -1
- package/dist/crypto/crypto.service.js +12 -0
- package/dist/egress/dto/mint-grant.dto.d.ts +7 -0
- package/dist/egress/dto/mint-grant.dto.d.ts.map +1 -0
- package/dist/egress/dto/mint-grant.dto.js +44 -0
- package/dist/egress/egress.controller.d.ts +2 -8
- package/dist/egress/egress.controller.d.ts.map +1 -1
- package/dist/egress/egress.controller.js +27 -6
- package/dist/egress/egress.listener.d.ts +3 -1
- package/dist/egress/egress.listener.d.ts.map +1 -1
- package/dist/egress/egress.listener.js +12 -8
- package/dist/egress/egress.module.d.ts.map +1 -1
- package/dist/egress/egress.module.js +10 -2
- package/dist/egress/egress.repository.d.ts +58 -0
- package/dist/egress/egress.repository.d.ts.map +1 -0
- package/dist/egress/egress.repository.js +116 -0
- package/dist/egress/grants.service.d.ts +23 -78
- package/dist/egress/grants.service.d.ts.map +1 -1
- package/dist/egress/grants.service.js +44 -104
- package/dist/environments/dto/create-environment.dto.d.ts +6 -0
- package/dist/environments/dto/create-environment.dto.d.ts.map +1 -0
- package/dist/environments/dto/create-environment.dto.js +34 -0
- package/dist/environments/dto/update-environment.dto.d.ts +5 -0
- package/dist/environments/dto/update-environment.dto.d.ts.map +1 -0
- package/dist/environments/dto/update-environment.dto.js +24 -0
- package/dist/environments/environments.controller.d.ts +53 -0
- package/dist/environments/environments.controller.d.ts.map +1 -0
- package/dist/environments/environments.controller.js +101 -0
- package/dist/environments/environments.module.d.ts +3 -0
- package/dist/environments/environments.module.d.ts.map +1 -0
- package/dist/environments/environments.module.js +15 -0
- package/dist/environments/environments.repository.d.ts +37 -0
- package/dist/environments/environments.repository.d.ts.map +1 -0
- package/dist/environments/environments.repository.js +82 -0
- package/dist/environments/environments.service.d.ts +43 -0
- package/dist/environments/environments.service.d.ts.map +1 -0
- package/dist/environments/environments.service.js +124 -0
- package/dist/generated/prisma/browser.d.ts +14 -37
- package/dist/generated/prisma/browser.d.ts.map +1 -1
- package/dist/generated/prisma/client.d.ts +14 -37
- package/dist/generated/prisma/client.d.ts.map +1 -1
- package/dist/generated/prisma/commonInputTypes.d.ts +104 -145
- package/dist/generated/prisma/commonInputTypes.d.ts.map +1 -1
- package/dist/generated/prisma/enums.d.ts +1 -21
- package/dist/generated/prisma/enums.d.ts.map +1 -1
- package/dist/generated/prisma/enums.js +1 -18
- package/dist/generated/prisma/internal/class.d.ts +20 -53
- package/dist/generated/prisma/internal/class.d.ts.map +1 -1
- package/dist/generated/prisma/internal/class.js +4 -4
- package/dist/generated/prisma/internal/prismaNamespace.d.ts +215 -519
- package/dist/generated/prisma/internal/prismaNamespace.d.ts.map +1 -1
- package/dist/generated/prisma/internal/prismaNamespace.js +38 -90
- package/dist/generated/prisma/internal/prismaNamespaceBrowser.d.ts +37 -92
- package/dist/generated/prisma/internal/prismaNamespaceBrowser.d.ts.map +1 -1
- package/dist/generated/prisma/internal/prismaNamespaceBrowser.js +38 -90
- package/dist/generated/prisma/models/Account.d.ts +344 -26
- package/dist/generated/prisma/models/Account.d.ts.map +1 -1
- package/dist/generated/prisma/models/Configuration.d.ts +218 -851
- package/dist/generated/prisma/models/Configuration.d.ts.map +1 -1
- package/dist/generated/prisma/models/EgressGrant.d.ts +131 -134
- package/dist/generated/prisma/models/EgressGrant.d.ts.map +1 -1
- package/dist/generated/prisma/models/Environment.d.ts +1644 -0
- package/dist/generated/prisma/models/Environment.d.ts.map +1 -0
- package/dist/generated/prisma/models/Invitation.d.ts +42 -1
- package/dist/generated/prisma/models/Invitation.d.ts.map +1 -1
- package/dist/generated/prisma/models/Organization.d.ts +122 -408
- package/dist/generated/prisma/models/Organization.d.ts.map +1 -1
- package/dist/generated/prisma/models/Session.d.ts +36 -1
- package/dist/generated/prisma/models/Session.d.ts.map +1 -1
- package/dist/generated/prisma/models/Team.d.ts +1498 -0
- package/dist/generated/prisma/models/Team.d.ts.map +1 -0
- package/dist/generated/prisma/models/TeamMember.d.ts +1281 -0
- package/dist/generated/prisma/models/TeamMember.d.ts.map +1 -0
- package/dist/generated/prisma/models/User.d.ts +338 -2
- package/dist/generated/prisma/models/User.d.ts.map +1 -1
- package/dist/generated/prisma/models.d.ts +3 -6
- package/dist/generated/prisma/models.d.ts.map +1 -1
- package/dist/index.d.ts +15 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -2
- package/dist/integrations/integrations.controller.d.ts +2 -1
- package/dist/integrations/integrations.controller.d.ts.map +1 -1
- package/dist/integrations/integrations.module.d.ts.map +1 -1
- package/dist/integrations/integrations.module.js +0 -2
- package/dist/kosha.module.d.ts.map +1 -1
- package/dist/kosha.module.js +9 -3
- package/dist/proxy/proxy.controller.d.ts +8 -3
- package/dist/proxy/proxy.controller.d.ts.map +1 -1
- package/dist/proxy/proxy.controller.js +26 -10
- package/dist/proxy/proxy.module.d.ts.map +1 -1
- package/dist/proxy/proxy.module.js +5 -2
- package/dist/proxy/proxy.repository.d.ts +24 -0
- package/dist/proxy/proxy.repository.d.ts.map +1 -0
- package/dist/proxy/proxy.repository.js +47 -0
- package/dist/proxy/proxy.service.d.ts +17 -5
- package/dist/proxy/proxy.service.d.ts.map +1 -1
- package/dist/proxy/proxy.service.js +58 -27
- package/package.json +7 -4
- package/prisma/migrations/20260929101936_init/migration.sql +345 -0
- package/prisma/migrations/20260930102529_connection_config/migration.sql +2 -0
- package/prisma/schema.prisma +93 -198
- package/dist/generated/prisma/models/ConnectSession.d.ts +0 -1606
- package/dist/generated/prisma/models/ConnectSession.d.ts.map +0 -1
- package/dist/generated/prisma/models/Connection.d.ts +0 -1949
- package/dist/generated/prisma/models/Connection.d.ts.map +0 -1
- package/dist/generated/prisma/models/ConnectionCredential.d.ts +0 -1293
- package/dist/generated/prisma/models/ConnectionCredential.d.ts.map +0 -1
- package/dist/generated/prisma/models/EndUser.d.ts +0 -1666
- package/dist/generated/prisma/models/EndUser.d.ts.map +0 -1
- package/dist/generated/prisma/models/EndUser.js +0 -1
- package/dist/generated/prisma/models/OAuthState.d.ts +0 -1404
- package/dist/generated/prisma/models/OAuthState.d.ts.map +0 -1
- package/dist/generated/prisma/models/OAuthState.js +0 -1
- package/dist/generated/prisma/models/Provider.d.ts +0 -1462
- package/dist/generated/prisma/models/Provider.d.ts.map +0 -1
- package/dist/generated/prisma/models/Provider.js +0 -1
- package/dist/integrations/provider-sync.service.d.ts +0 -24
- package/dist/integrations/provider-sync.service.d.ts.map +0 -1
- package/dist/integrations/provider-sync.service.js +0 -74
- package/prisma/migrations/20260908000000_init/migration.sql +0 -209
- package/prisma/migrations/20260908161813_add_connect_domain/migration.sql +0 -173
- package/prisma/migrations/20260916000000_add_configuration_slug/migration.sql +0 -15
- package/prisma/migrations/20260921000000_add_egress_grant/migration.sql +0 -31
- /package/dist/generated/prisma/models/{ConnectSession.js → Environment.js} +0 -0
- /package/dist/generated/prisma/models/{Connection.js → Team.js} +0 -0
- /package/dist/generated/prisma/models/{ConnectionCredential.js → TeamMember.js} +0 -0
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { CanActivate, ExecutionContext } from '@nestjs/common';
|
|
2
2
|
import { AuthService } from '@thallesp/nestjs-better-auth';
|
|
3
3
|
import type { Request } from 'express';
|
|
4
|
+
import { EnvironmentsService } from '../environments/environments.service.js';
|
|
4
5
|
import type { KoshaAuth } from './auth.factory.js';
|
|
5
6
|
export interface ApiKeyRequest extends Request {
|
|
6
7
|
organizationId: string;
|
|
8
|
+
/** Set whenever the caller authenticated with a key, never from the body. */
|
|
9
|
+
environmentId?: string;
|
|
7
10
|
session?: {
|
|
8
11
|
session?: {
|
|
9
12
|
activeOrganizationId?: string | null;
|
|
@@ -17,12 +20,14 @@ export interface ApiKeyRequest extends Request {
|
|
|
17
20
|
*/
|
|
18
21
|
export declare class ApiKeyGuard implements CanActivate {
|
|
19
22
|
private readonly authService;
|
|
20
|
-
|
|
23
|
+
private readonly environments;
|
|
24
|
+
constructor(authService: AuthService<KoshaAuth>, environments: EnvironmentsService);
|
|
21
25
|
canActivate(context: ExecutionContext): Promise<boolean>;
|
|
22
26
|
}
|
|
23
27
|
export declare class OrgAuthGuard implements CanActivate {
|
|
24
28
|
private readonly authService;
|
|
25
|
-
|
|
29
|
+
private readonly environments;
|
|
30
|
+
constructor(authService: AuthService<KoshaAuth>, environments: EnvironmentsService);
|
|
26
31
|
canActivate(context: ExecutionContext): Promise<boolean>;
|
|
27
32
|
}
|
|
28
33
|
//# sourceMappingURL=api-key.guard.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-key.guard.d.ts","sourceRoot":"","sources":["../../src/auth/api-key.guard.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,gBAAgB,EAIjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,MAAM,WAAW,aAAc,SAAQ,OAAO;IAC5C,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE;YAAE,oBAAoB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;SAAE,CAAA;KAAE,GAAG,IAAI,CAAC;CACzE;
|
|
1
|
+
{"version":3,"file":"api-key.guard.d.ts","sourceRoot":"","sources":["../../src/auth/api-key.guard.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,gBAAgB,EAIjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAC9E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,MAAM,WAAW,aAAc,SAAQ,OAAO;IAC5C,cAAc,EAAE,MAAM,CAAC;IACvB,6EAA6E;IAC7E,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE;YAAE,oBAAoB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;SAAE,CAAA;KAAE,GAAG,IAAI,CAAC;CACzE;AA6BD;;;;GAIG;AACH,qBACa,WAAY,YAAW,WAAW;IAG3C,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,YAAY;gBADZ,WAAW,EAAE,WAAW,CAAC,SAAS,CAAC,EACnC,YAAY,EAAE,mBAAmB;IAG9C,WAAW,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;CAqB/D;AAED,qBACa,YAAa,YAAW,WAAW;IAG5C,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,YAAY;gBADZ,WAAW,EAAE,WAAW,CAAC,SAAS,CAAC,EACnC,YAAY,EAAE,mBAAmB;IAG9C,WAAW,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;CA0B/D"}
|
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
import { __decorate, __metadata, __param } from "tslib";
|
|
2
2
|
import { Inject, Injectable, UnauthorizedException, } from '@nestjs/common';
|
|
3
3
|
import { AuthService } from '@thallesp/nestjs-better-auth';
|
|
4
|
+
import { EnvironmentsService } from '../environments/environments.service.js';
|
|
4
5
|
/** Verifies an org-scoped API key. Throws rather than returning false. */
|
|
5
|
-
async function
|
|
6
|
+
async function verifyApiKey(authService, key) {
|
|
6
7
|
const result = await authService.api.verifyApiKey({ body: { key } });
|
|
7
8
|
if (!result.valid || !result.key?.referenceId) {
|
|
8
9
|
const code = result.error?.code;
|
|
9
10
|
throw new UnauthorizedException(code ? `API key rejected: ${code}` : 'Invalid API key');
|
|
10
11
|
}
|
|
11
|
-
|
|
12
|
+
const metadata = result.key
|
|
13
|
+
.metadata;
|
|
14
|
+
return {
|
|
15
|
+
organizationId: result.key.referenceId,
|
|
16
|
+
environmentId: metadata?.['environmentId'],
|
|
17
|
+
};
|
|
12
18
|
}
|
|
13
19
|
/**
|
|
14
20
|
* Authenticates machine-to-machine calls with `x-api-key` and puts the owning
|
|
@@ -17,8 +23,10 @@ async function organizationIdForApiKey(authService, key) {
|
|
|
17
23
|
*/
|
|
18
24
|
let ApiKeyGuard = class ApiKeyGuard {
|
|
19
25
|
authService;
|
|
20
|
-
|
|
26
|
+
environments;
|
|
27
|
+
constructor(authService, environments) {
|
|
21
28
|
this.authService = authService;
|
|
29
|
+
this.environments = environments;
|
|
22
30
|
}
|
|
23
31
|
async canActivate(context) {
|
|
24
32
|
const request = context.switchToHttp().getRequest();
|
|
@@ -26,26 +34,37 @@ let ApiKeyGuard = class ApiKeyGuard {
|
|
|
26
34
|
if (!key || typeof key !== 'string') {
|
|
27
35
|
throw new UnauthorizedException('Missing x-api-key header');
|
|
28
36
|
}
|
|
29
|
-
|
|
37
|
+
const verified = await verifyApiKey(this.authService, key);
|
|
38
|
+
// Re-checked rather than trusted: the metadata was written when the key
|
|
39
|
+
// was issued, and the environment may have moved or gone since.
|
|
40
|
+
const environment = await this.environments.resolveForOrganization(verified.organizationId, verified.environmentId);
|
|
41
|
+
request.organizationId = verified.organizationId;
|
|
42
|
+
request.environmentId = environment.id;
|
|
30
43
|
return true;
|
|
31
44
|
}
|
|
32
45
|
};
|
|
33
46
|
ApiKeyGuard = __decorate([
|
|
34
47
|
Injectable(),
|
|
35
48
|
__param(0, Inject(AuthService)),
|
|
36
|
-
__metadata("design:paramtypes", [AuthService
|
|
49
|
+
__metadata("design:paramtypes", [AuthService,
|
|
50
|
+
EnvironmentsService])
|
|
37
51
|
], ApiKeyGuard);
|
|
38
52
|
export { ApiKeyGuard };
|
|
39
53
|
let OrgAuthGuard = class OrgAuthGuard {
|
|
40
54
|
authService;
|
|
41
|
-
|
|
55
|
+
environments;
|
|
56
|
+
constructor(authService, environments) {
|
|
42
57
|
this.authService = authService;
|
|
58
|
+
this.environments = environments;
|
|
43
59
|
}
|
|
44
60
|
async canActivate(context) {
|
|
45
61
|
const request = context.switchToHttp().getRequest();
|
|
46
62
|
const key = request.headers['x-api-key'];
|
|
47
63
|
if (typeof key === 'string' && key.length > 0) {
|
|
48
|
-
|
|
64
|
+
const verified = await verifyApiKey(this.authService, key);
|
|
65
|
+
const environment = await this.environments.resolveForOrganization(verified.organizationId, verified.environmentId);
|
|
66
|
+
request.organizationId = verified.organizationId;
|
|
67
|
+
request.environmentId = environment.id;
|
|
49
68
|
return true;
|
|
50
69
|
}
|
|
51
70
|
const organizationId = request.session?.session?.activeOrganizationId;
|
|
@@ -59,6 +78,7 @@ let OrgAuthGuard = class OrgAuthGuard {
|
|
|
59
78
|
OrgAuthGuard = __decorate([
|
|
60
79
|
Injectable(),
|
|
61
80
|
__param(0, Inject(AuthService)),
|
|
62
|
-
__metadata("design:paramtypes", [AuthService
|
|
81
|
+
__metadata("design:paramtypes", [AuthService,
|
|
82
|
+
EnvironmentsService])
|
|
63
83
|
], OrgAuthGuard);
|
|
64
84
|
export { OrgAuthGuard };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { PrismaClient } from '../generated/prisma/client.js';
|
|
2
2
|
import { type Auth } from 'better-auth';
|
|
3
3
|
import type { ResolvedKoshaConfig } from '../config/kosha-config.js';
|
|
4
|
+
import type { EnvironmentsService } from '../environments/environments.service.js';
|
|
4
5
|
/** The API-key endpoints Kosha itself calls. The instance exposes many more. */
|
|
5
6
|
export interface KoshaAuthApi {
|
|
6
7
|
verifyApiKey(input: {
|
|
@@ -11,9 +12,22 @@ export interface KoshaAuthApi {
|
|
|
11
12
|
valid: boolean;
|
|
12
13
|
key?: {
|
|
13
14
|
referenceId?: string | null;
|
|
15
|
+
/** Carries `environmentId`. Only present with `enableMetadata`. */
|
|
16
|
+
metadata?: Record<string, unknown> | null;
|
|
14
17
|
} | null;
|
|
15
18
|
error?: unknown;
|
|
16
19
|
}>;
|
|
20
|
+
createApiKey(input: {
|
|
21
|
+
body: {
|
|
22
|
+
name?: string;
|
|
23
|
+
organizationId?: string;
|
|
24
|
+
userId?: string;
|
|
25
|
+
metadata?: Record<string, unknown>;
|
|
26
|
+
};
|
|
27
|
+
}): Promise<{
|
|
28
|
+
key: string;
|
|
29
|
+
id: string;
|
|
30
|
+
}>;
|
|
17
31
|
}
|
|
18
32
|
/**
|
|
19
33
|
* The auth instance as the rest of the framework sees it: Better Auth's public
|
|
@@ -36,5 +50,5 @@ export declare function crossSiteCookieAttributes(config: ResolvedKoshaConfig):
|
|
|
36
50
|
* now, so nothing may read `process.env` at import time — the consuming app
|
|
37
51
|
* owns where secrets come from.
|
|
38
52
|
*/
|
|
39
|
-
export declare function createAuth(config: ResolvedKoshaConfig, prisma: PrismaClient): KoshaAuth;
|
|
53
|
+
export declare function createAuth(config: ResolvedKoshaConfig, prisma: PrismaClient, environments: EnvironmentsService): KoshaAuth;
|
|
40
54
|
//# sourceMappingURL=auth.factory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.factory.d.ts","sourceRoot":"","sources":["../../src/auth/auth.factory.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAc,KAAK,IAAI,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"auth.factory.d.ts","sourceRoot":"","sources":["../../src/auth/auth.factory.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAc,KAAK,IAAI,EAAE,MAAM,aAAa,CAAC;AAIpD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAEnF,gFAAgF;AAChF,MAAM,WAAW,YAAY;IAC3B,YAAY,CAAC,KAAK,EAAE;QAAE,IAAI,EAAE;YAAE,GAAG,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,GAAG,OAAO,CAAC;QACtD,KAAK,EAAE,OAAO,CAAC;QACf,GAAG,CAAC,EAAE;YACJ,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;YAC5B,mEAAmE;YACnE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;SAC3C,GAAG,IAAI,CAAC;QACT,KAAK,CAAC,EAAE,OAAO,CAAC;KACjB,CAAC,CAAC;IACH,YAAY,CAAC,KAAK,EAAE;QAClB,IAAI,EAAE;YACJ,IAAI,CAAC,EAAE,MAAM,CAAC;YACd,cAAc,CAAC,EAAE,MAAM,CAAC;YACxB,MAAM,CAAC,EAAE,MAAM,CAAC;YAChB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;SACpC,CAAC;KACH,GAAG,OAAO,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC1C;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,SAAS,GAAG,IAAI,GAAG;IAAE,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,YAAY,CAAA;CAAE,CAAC;AAEnE,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,mBAAmB,GAAG,MAAM,CAEtE;AAUD,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,mBAAmB,GAC1B;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,IAAI,CAAA;CAAE,GAAG,SAAS,CAYhD;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,mBAAmB,EAC3B,MAAM,EAAE,YAAY,EACpB,YAAY,EAAE,mBAAmB,GAChC,SAAS,CA6EX"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { apiKey } from '@better-auth/api-key';
|
|
2
2
|
import { betterAuth } from 'better-auth';
|
|
3
|
+
import { APIError, createAuthMiddleware } from 'better-auth/api';
|
|
3
4
|
import { prismaAdapter } from 'better-auth/adapters/prisma';
|
|
4
5
|
import { organization } from 'better-auth/plugins';
|
|
5
6
|
export function resolveAuthBaseURL(config) {
|
|
@@ -31,7 +32,7 @@ export function crossSiteCookieAttributes(config) {
|
|
|
31
32
|
* now, so nothing may read `process.env` at import time — the consuming app
|
|
32
33
|
* owns where secrets come from.
|
|
33
34
|
*/
|
|
34
|
-
export function createAuth(config, prisma) {
|
|
35
|
+
export function createAuth(config, prisma, environments) {
|
|
35
36
|
const auth = betterAuth({
|
|
36
37
|
database: prismaAdapter(prisma, { provider: 'postgresql' }),
|
|
37
38
|
secret: config.auth.secret,
|
|
@@ -40,13 +41,58 @@ export function createAuth(config, prisma) {
|
|
|
40
41
|
emailAndPassword: {
|
|
41
42
|
enabled: config.auth.emailAndPassword?.enabled ?? true,
|
|
42
43
|
},
|
|
44
|
+
user: {
|
|
45
|
+
additionalFields: {
|
|
46
|
+
externalId: { type: 'string', required: false, input: false },
|
|
47
|
+
},
|
|
48
|
+
},
|
|
43
49
|
trustedOrigins: config.auth.trustedOrigins ?? [],
|
|
44
50
|
advanced: { defaultCookieAttributes: crossSiteCookieAttributes(config) },
|
|
51
|
+
hooks: {
|
|
52
|
+
// The admin creates keys through Better Auth directly, so this is the
|
|
53
|
+
// only place the environment on a key can be checked before it is
|
|
54
|
+
// written. `apikey.metadata` is a soft reference — the plugin's
|
|
55
|
+
// `references` is the whole "user" | "organization" union, so a key
|
|
56
|
+
// cannot foreign-key to an environment.
|
|
57
|
+
before: createAuthMiddleware(async (ctx) => {
|
|
58
|
+
if (!ctx.path.endsWith('/api-key/create'))
|
|
59
|
+
return;
|
|
60
|
+
const body = ctx.body;
|
|
61
|
+
if (!body?.organizationId) {
|
|
62
|
+
throw new APIError('BAD_REQUEST', {
|
|
63
|
+
message: 'organizationId is required to issue an API key',
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
await environments.resolveForOrganization(body.organizationId, body.metadata?.environmentId);
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
throw new APIError('BAD_REQUEST', {
|
|
71
|
+
message: error instanceof Error
|
|
72
|
+
? error.message
|
|
73
|
+
: 'Invalid environment for this API key',
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}),
|
|
77
|
+
},
|
|
45
78
|
plugins: [
|
|
46
|
-
organization(
|
|
79
|
+
organization({
|
|
80
|
+
teams: { enabled: true },
|
|
81
|
+
organizationHooks: {
|
|
82
|
+
// Sandbox and production exist from the first moment, so nothing
|
|
83
|
+
// has to cope with an organization that has no environment.
|
|
84
|
+
afterCreateOrganization: async ({ organization: created }) => {
|
|
85
|
+
await environments.seedDefaults(created.id);
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
}),
|
|
47
89
|
apiKey({
|
|
48
90
|
references: 'organization',
|
|
49
91
|
requireName: true,
|
|
92
|
+
// Off by default, and without it the plugin refuses a key carrying
|
|
93
|
+
// metadata — which is where a key's environment lives, since its
|
|
94
|
+
// `references` cannot point at one.
|
|
95
|
+
enableMetadata: true,
|
|
50
96
|
rateLimit: { enabled: true, maxRequests: 600, timeWindow: 60_000 },
|
|
51
97
|
}),
|
|
52
98
|
],
|
package/dist/bootstrap.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,KAAK,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAK/E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAI5D;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC,gBAAgB,CAAC,CA6D3B;AAED,gCAAgC;AAChC,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC,gBAAgB,CAAC,CAkB3B"}
|
package/dist/bootstrap.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Logger } from '@nestjs/common';
|
|
1
|
+
import { Logger, ValidationPipe } from '@nestjs/common';
|
|
2
2
|
import { NestFactory } from '@nestjs/core';
|
|
3
|
+
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
|
|
3
4
|
import express from 'express';
|
|
4
5
|
import { createAdminProxy } from './admin-proxy.js';
|
|
5
6
|
import { resolveConfig } from './config/kosha-config.js';
|
|
@@ -16,18 +17,35 @@ export async function createKoshaServer(config) {
|
|
|
16
17
|
const app = await NestFactory.create(KoshaModule.forRoot(resolved), {
|
|
17
18
|
bodyParser: false,
|
|
18
19
|
});
|
|
20
|
+
// Must run before mounting the docs static middleware below: Express
|
|
21
|
+
// dispatches middleware in registration order, so a route registered
|
|
22
|
+
// ahead of enableCors's middleware never reaches it and gets no CORS
|
|
23
|
+
// headers, regardless of origin config.
|
|
24
|
+
const cors = resolved.server.cors;
|
|
25
|
+
app.enableCors({
|
|
26
|
+
origin: cors?.origin ?? resolved.auth.trustedOrigins ?? [],
|
|
27
|
+
credentials: cors?.credentials ?? true,
|
|
28
|
+
});
|
|
19
29
|
const expressApp = app.getHttpAdapter().getInstance();
|
|
20
30
|
for (const integration of resolved.integrations) {
|
|
21
31
|
if (integration.docsPath) {
|
|
22
32
|
expressApp.use(`/${resolved.server.globalPrefix}/integrations/${integration.key}/docs`, express.static(integration.docsPath));
|
|
23
33
|
}
|
|
24
34
|
}
|
|
25
|
-
const cors = resolved.server.cors;
|
|
26
|
-
app.enableCors({
|
|
27
|
-
origin: cors?.origin ?? resolved.auth.trustedOrigins ?? [],
|
|
28
|
-
credentials: cors?.credentials ?? true,
|
|
29
|
-
});
|
|
30
35
|
app.setGlobalPrefix(resolved.server.globalPrefix);
|
|
36
|
+
// `whitelist` strips properties no DTO declares, so an endpoint can only
|
|
37
|
+
// ever see what it asked for. Better Auth's own routes are mounted by the
|
|
38
|
+
// auth module and never reach a Nest pipe.
|
|
39
|
+
app.useGlobalPipes(new ValidationPipe({
|
|
40
|
+
whitelist: true,
|
|
41
|
+
transform: true,
|
|
42
|
+
transformOptions: { enableImplicitConversion: false },
|
|
43
|
+
}));
|
|
44
|
+
SwaggerModule.setup(`${resolved.server.globalPrefix}/docs`, app, SwaggerModule.createDocument(app, new DocumentBuilder()
|
|
45
|
+
.setTitle('Kosha')
|
|
46
|
+
.setDescription('Connect providers on behalf of a consuming app and proxy calls to them.')
|
|
47
|
+
.addApiKey({ type: 'apiKey', name: 'x-api-key', in: 'header' }, 'x-api-key')
|
|
48
|
+
.build()));
|
|
31
49
|
app.enableShutdownHooks();
|
|
32
50
|
return app;
|
|
33
51
|
}
|
|
@@ -1,145 +1,20 @@
|
|
|
1
1
|
import { type UserSession } from '@thallesp/nestjs-better-auth';
|
|
2
|
-
import { ConfigurationsService
|
|
2
|
+
import { ConfigurationsService } from './configurations.service.js';
|
|
3
|
+
import { CreateConfigurationDto } from './dto/create-configuration.dto.js';
|
|
4
|
+
import { UpdateConfigurationDto } from './dto/update-configuration.dto.js';
|
|
3
5
|
/**
|
|
4
|
-
* Admin-facing
|
|
5
|
-
*
|
|
6
|
+
* Admin-facing, and nested under the environment a configuration belongs to.
|
|
7
|
+
* Session authenticated: the organization comes from the session, never from
|
|
8
|
+
* the request, and the environment is checked against it.
|
|
6
9
|
*/
|
|
7
10
|
export declare class ConfigurationsController {
|
|
8
11
|
private readonly configurations;
|
|
9
12
|
constructor(configurations: ConfigurationsService);
|
|
10
|
-
list(session: UserSession): import("
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
createdAt: Date;
|
|
16
|
-
updatedAt: Date;
|
|
17
|
-
authType: import("../generated/prisma/enums.js").AuthType;
|
|
18
|
-
authorizationUrl: string | null;
|
|
19
|
-
tokenUrl: string | null;
|
|
20
|
-
revokeUrl: string | null;
|
|
21
|
-
apiBaseUrl: string | null;
|
|
22
|
-
scopesAvailable: string[];
|
|
23
|
-
docsUrl: string | null;
|
|
24
|
-
logoUrl: string | null;
|
|
25
|
-
isActive: boolean;
|
|
26
|
-
};
|
|
27
|
-
} & {
|
|
28
|
-
name: string;
|
|
29
|
-
id: string;
|
|
30
|
-
createdAt: Date;
|
|
31
|
-
updatedAt: Date;
|
|
32
|
-
metadata: import("@prisma/client/runtime/client").JsonValue | null;
|
|
33
|
-
scopes: string[];
|
|
34
|
-
slug: string;
|
|
35
|
-
organizationId: string;
|
|
36
|
-
providerId: string;
|
|
37
|
-
environment: import("../generated/prisma/enums.js").ConnectionEnvironment;
|
|
38
|
-
authType: import("../generated/prisma/enums.js").AuthType;
|
|
39
|
-
clientId: string | null;
|
|
40
|
-
redirectUri: string | null;
|
|
41
|
-
isEnabled: boolean;
|
|
42
|
-
})[]>;
|
|
43
|
-
get(session: UserSession, id: string): Promise<{
|
|
44
|
-
provider: {
|
|
45
|
-
name: string;
|
|
46
|
-
key: string;
|
|
47
|
-
id: string;
|
|
48
|
-
createdAt: Date;
|
|
49
|
-
updatedAt: Date;
|
|
50
|
-
authType: import("../generated/prisma/enums.js").AuthType;
|
|
51
|
-
authorizationUrl: string | null;
|
|
52
|
-
tokenUrl: string | null;
|
|
53
|
-
revokeUrl: string | null;
|
|
54
|
-
apiBaseUrl: string | null;
|
|
55
|
-
scopesAvailable: string[];
|
|
56
|
-
docsUrl: string | null;
|
|
57
|
-
logoUrl: string | null;
|
|
58
|
-
isActive: boolean;
|
|
59
|
-
};
|
|
60
|
-
} & {
|
|
61
|
-
name: string;
|
|
62
|
-
id: string;
|
|
63
|
-
createdAt: Date;
|
|
64
|
-
updatedAt: Date;
|
|
65
|
-
metadata: import("@prisma/client/runtime/client").JsonValue | null;
|
|
66
|
-
scopes: string[];
|
|
67
|
-
slug: string;
|
|
68
|
-
organizationId: string;
|
|
69
|
-
providerId: string;
|
|
70
|
-
environment: import("../generated/prisma/enums.js").ConnectionEnvironment;
|
|
71
|
-
authType: import("../generated/prisma/enums.js").AuthType;
|
|
72
|
-
clientId: string | null;
|
|
73
|
-
redirectUri: string | null;
|
|
74
|
-
isEnabled: boolean;
|
|
75
|
-
}>;
|
|
76
|
-
create(session: UserSession, body: CreateConfigurationInput): Promise<{
|
|
77
|
-
provider: {
|
|
78
|
-
name: string;
|
|
79
|
-
key: string;
|
|
80
|
-
id: string;
|
|
81
|
-
createdAt: Date;
|
|
82
|
-
updatedAt: Date;
|
|
83
|
-
authType: import("../generated/prisma/enums.js").AuthType;
|
|
84
|
-
authorizationUrl: string | null;
|
|
85
|
-
tokenUrl: string | null;
|
|
86
|
-
revokeUrl: string | null;
|
|
87
|
-
apiBaseUrl: string | null;
|
|
88
|
-
scopesAvailable: string[];
|
|
89
|
-
docsUrl: string | null;
|
|
90
|
-
logoUrl: string | null;
|
|
91
|
-
isActive: boolean;
|
|
92
|
-
};
|
|
93
|
-
} & {
|
|
94
|
-
name: string;
|
|
95
|
-
id: string;
|
|
96
|
-
createdAt: Date;
|
|
97
|
-
updatedAt: Date;
|
|
98
|
-
metadata: import("@prisma/client/runtime/client").JsonValue | null;
|
|
99
|
-
scopes: string[];
|
|
100
|
-
slug: string;
|
|
101
|
-
organizationId: string;
|
|
102
|
-
providerId: string;
|
|
103
|
-
environment: import("../generated/prisma/enums.js").ConnectionEnvironment;
|
|
104
|
-
authType: import("../generated/prisma/enums.js").AuthType;
|
|
105
|
-
clientId: string | null;
|
|
106
|
-
redirectUri: string | null;
|
|
107
|
-
isEnabled: boolean;
|
|
108
|
-
}>;
|
|
109
|
-
update(session: UserSession, id: string, body: UpdateConfigurationInput): Promise<{
|
|
110
|
-
provider: {
|
|
111
|
-
name: string;
|
|
112
|
-
key: string;
|
|
113
|
-
id: string;
|
|
114
|
-
createdAt: Date;
|
|
115
|
-
updatedAt: Date;
|
|
116
|
-
authType: import("../generated/prisma/enums.js").AuthType;
|
|
117
|
-
authorizationUrl: string | null;
|
|
118
|
-
tokenUrl: string | null;
|
|
119
|
-
revokeUrl: string | null;
|
|
120
|
-
apiBaseUrl: string | null;
|
|
121
|
-
scopesAvailable: string[];
|
|
122
|
-
docsUrl: string | null;
|
|
123
|
-
logoUrl: string | null;
|
|
124
|
-
isActive: boolean;
|
|
125
|
-
};
|
|
126
|
-
} & {
|
|
127
|
-
name: string;
|
|
128
|
-
id: string;
|
|
129
|
-
createdAt: Date;
|
|
130
|
-
updatedAt: Date;
|
|
131
|
-
metadata: import("@prisma/client/runtime/client").JsonValue | null;
|
|
132
|
-
scopes: string[];
|
|
133
|
-
slug: string;
|
|
134
|
-
organizationId: string;
|
|
135
|
-
providerId: string;
|
|
136
|
-
environment: import("../generated/prisma/enums.js").ConnectionEnvironment;
|
|
137
|
-
authType: import("../generated/prisma/enums.js").AuthType;
|
|
138
|
-
clientId: string | null;
|
|
139
|
-
redirectUri: string | null;
|
|
140
|
-
isEnabled: boolean;
|
|
141
|
-
}>;
|
|
142
|
-
remove(session: UserSession, id: string): Promise<{
|
|
13
|
+
list(session: UserSession, environmentId: string): Promise<import("./configurations.repository.js").PublicConfiguration[]>;
|
|
14
|
+
get(session: UserSession, environmentId: string, id: string): Promise<import("./configurations.repository.js").PublicConfiguration>;
|
|
15
|
+
create(session: UserSession, environmentId: string, body: CreateConfigurationDto): Promise<import("./configurations.repository.js").PublicConfiguration>;
|
|
16
|
+
update(session: UserSession, environmentId: string, id: string, body: UpdateConfigurationDto): Promise<import("./configurations.repository.js").PublicConfiguration>;
|
|
17
|
+
remove(session: UserSession, environmentId: string, id: string): Promise<{
|
|
143
18
|
id: string;
|
|
144
19
|
deleted: boolean;
|
|
145
20
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configurations.controller.d.ts","sourceRoot":"","sources":["../../src/configurations/configurations.controller.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"configurations.controller.d.ts","sourceRoot":"","sources":["../../src/configurations/configurations.controller.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAW,KAAK,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAEzE,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAC3E,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAE3E;;;;GAIG;AACH,qBAEa,wBAAwB;IACvB,OAAO,CAAC,QAAQ,CAAC,cAAc;gBAAd,cAAc,EAAE,qBAAqB;IAKlE,IAAI,CACS,OAAO,EAAE,WAAW,EACP,aAAa,EAAE,MAAM;IAY/C,GAAG,CACU,OAAO,EAAE,WAAW,EACP,aAAa,EAAE,MAAM,EAChC,EAAE,EAAE,MAAM;IAqBzB,MAAM,CACO,OAAO,EAAE,WAAW,EACP,aAAa,EAAE,MAAM,EACrC,IAAI,EAAE,sBAAsB;IAatC,MAAM,CACO,OAAO,EAAE,WAAW,EACP,aAAa,EAAE,MAAM,EAChC,EAAE,EAAE,MAAM,EACf,IAAI,EAAE,sBAAsB;IAqBhC,MAAM,CACC,OAAO,EAAE,WAAW,EACP,aAAa,EAAE,MAAM,EAChC,EAAE,EAAE,MAAM;;;;CAU1B"}
|
|
@@ -1,76 +1,109 @@
|
|
|
1
1
|
import { __decorate, __metadata, __param } from "tslib";
|
|
2
|
-
import { Body, Controller, Delete, Get, Param, Patch, Post, } from '@nestjs/common';
|
|
2
|
+
import { Body, Controller, Delete, Get, HttpCode, HttpStatus, Param, Patch, Post, } from '@nestjs/common';
|
|
3
|
+
import { ApiConflictResponse, ApiCreatedResponse, ApiNotFoundResponse, ApiOkResponse, ApiOperation, ApiTags, } from '@nestjs/swagger';
|
|
3
4
|
import { Session } from '@thallesp/nestjs-better-auth';
|
|
4
5
|
import { getActiveOrganizationId } from '../common/active-organization.js';
|
|
5
|
-
import { ConfigurationsService
|
|
6
|
+
import { ConfigurationsService } from './configurations.service.js';
|
|
7
|
+
import { CreateConfigurationDto } from './dto/create-configuration.dto.js';
|
|
8
|
+
import { UpdateConfigurationDto } from './dto/update-configuration.dto.js';
|
|
6
9
|
/**
|
|
7
|
-
* Admin-facing
|
|
8
|
-
*
|
|
10
|
+
* Admin-facing, and nested under the environment a configuration belongs to.
|
|
11
|
+
* Session authenticated: the organization comes from the session, never from
|
|
12
|
+
* the request, and the environment is checked against it.
|
|
9
13
|
*/
|
|
10
14
|
let ConfigurationsController = class ConfigurationsController {
|
|
11
15
|
configurations;
|
|
12
16
|
constructor(configurations) {
|
|
13
17
|
this.configurations = configurations;
|
|
14
18
|
}
|
|
15
|
-
list(session) {
|
|
16
|
-
return this.configurations.list(getActiveOrganizationId(session));
|
|
19
|
+
list(session, environmentId) {
|
|
20
|
+
return this.configurations.list(getActiveOrganizationId(session), session.user.id, environmentId);
|
|
17
21
|
}
|
|
18
|
-
get(session, id) {
|
|
19
|
-
return this.configurations.get(getActiveOrganizationId(session), id);
|
|
22
|
+
get(session, environmentId, id) {
|
|
23
|
+
return this.configurations.get(getActiveOrganizationId(session), session.user.id, environmentId, id);
|
|
20
24
|
}
|
|
21
|
-
create(session, body) {
|
|
22
|
-
return this.configurations.create(getActiveOrganizationId(session), body);
|
|
25
|
+
create(session, environmentId, body) {
|
|
26
|
+
return this.configurations.create(getActiveOrganizationId(session), session.user.id, environmentId, body);
|
|
23
27
|
}
|
|
24
|
-
update(session, id, body) {
|
|
25
|
-
return this.configurations.update(getActiveOrganizationId(session), id, body);
|
|
28
|
+
update(session, environmentId, id, body) {
|
|
29
|
+
return this.configurations.update(getActiveOrganizationId(session), session.user.id, environmentId, id, body);
|
|
26
30
|
}
|
|
27
|
-
async remove(session, id) {
|
|
28
|
-
await this.configurations.remove(getActiveOrganizationId(session), id);
|
|
31
|
+
async remove(session, environmentId, id) {
|
|
32
|
+
await this.configurations.remove(getActiveOrganizationId(session), session.user.id, environmentId, id);
|
|
29
33
|
return { id, deleted: true };
|
|
30
34
|
}
|
|
31
35
|
};
|
|
32
36
|
__decorate([
|
|
33
37
|
Get(),
|
|
38
|
+
ApiOperation({ summary: 'List the configurations in one environment' }),
|
|
39
|
+
ApiOkResponse({ description: 'Configurations, newest first.' }),
|
|
34
40
|
__param(0, Session()),
|
|
41
|
+
__param(1, Param('environmentId')),
|
|
35
42
|
__metadata("design:type", Function),
|
|
36
|
-
__metadata("design:paramtypes", [Object]),
|
|
43
|
+
__metadata("design:paramtypes", [Object, String]),
|
|
37
44
|
__metadata("design:returntype", void 0)
|
|
38
45
|
], ConfigurationsController.prototype, "list", null);
|
|
39
46
|
__decorate([
|
|
40
47
|
Get(':id'),
|
|
48
|
+
ApiOperation({ summary: 'Get one configuration' }),
|
|
49
|
+
ApiNotFoundResponse({ description: 'No such configuration here.' }),
|
|
41
50
|
__param(0, Session()),
|
|
42
|
-
__param(1, Param('
|
|
51
|
+
__param(1, Param('environmentId')),
|
|
52
|
+
__param(2, Param('id')),
|
|
43
53
|
__metadata("design:type", Function),
|
|
44
|
-
__metadata("design:paramtypes", [Object, String]),
|
|
54
|
+
__metadata("design:paramtypes", [Object, String, String]),
|
|
45
55
|
__metadata("design:returntype", void 0)
|
|
46
56
|
], ConfigurationsController.prototype, "get", null);
|
|
47
57
|
__decorate([
|
|
48
58
|
Post(),
|
|
59
|
+
HttpCode(HttpStatus.CREATED),
|
|
60
|
+
ApiOperation({
|
|
61
|
+
summary: 'Set up a provider in this environment',
|
|
62
|
+
description: 'The integration key names an installed package; the auth type comes from it rather than from the request.',
|
|
63
|
+
}),
|
|
64
|
+
ApiCreatedResponse({ description: 'The created configuration.' }),
|
|
65
|
+
ApiConflictResponse({
|
|
66
|
+
description: 'That slug is taken in this environment.',
|
|
67
|
+
}),
|
|
49
68
|
__param(0, Session()),
|
|
50
|
-
__param(1,
|
|
69
|
+
__param(1, Param('environmentId')),
|
|
70
|
+
__param(2, Body()),
|
|
51
71
|
__metadata("design:type", Function),
|
|
52
|
-
__metadata("design:paramtypes", [Object,
|
|
72
|
+
__metadata("design:paramtypes", [Object, String, CreateConfigurationDto]),
|
|
53
73
|
__metadata("design:returntype", void 0)
|
|
54
74
|
], ConfigurationsController.prototype, "create", null);
|
|
55
75
|
__decorate([
|
|
56
76
|
Patch(':id'),
|
|
77
|
+
ApiOperation({ summary: 'Update a configuration' }),
|
|
78
|
+
ApiOkResponse({ description: 'The updated configuration.' }),
|
|
57
79
|
__param(0, Session()),
|
|
58
|
-
__param(1, Param('
|
|
59
|
-
__param(2,
|
|
80
|
+
__param(1, Param('environmentId')),
|
|
81
|
+
__param(2, Param('id')),
|
|
82
|
+
__param(3, Body()),
|
|
60
83
|
__metadata("design:type", Function),
|
|
61
|
-
__metadata("design:paramtypes", [Object, String,
|
|
84
|
+
__metadata("design:paramtypes", [Object, String, String, UpdateConfigurationDto]),
|
|
62
85
|
__metadata("design:returntype", void 0)
|
|
63
86
|
], ConfigurationsController.prototype, "update", null);
|
|
64
87
|
__decorate([
|
|
65
88
|
Delete(':id'),
|
|
89
|
+
ApiOperation({
|
|
90
|
+
summary: 'Delete a configuration',
|
|
91
|
+
description: 'Refused while connections still use it, since nothing in the database would stop those credentials being orphaned.',
|
|
92
|
+
}),
|
|
93
|
+
ApiOkResponse({ description: 'The deleted configuration id.' }),
|
|
94
|
+
ApiConflictResponse({
|
|
95
|
+
description: 'Connections still use this configuration.',
|
|
96
|
+
}),
|
|
66
97
|
__param(0, Session()),
|
|
67
|
-
__param(1, Param('
|
|
98
|
+
__param(1, Param('environmentId')),
|
|
99
|
+
__param(2, Param('id')),
|
|
68
100
|
__metadata("design:type", Function),
|
|
69
|
-
__metadata("design:paramtypes", [Object, String]),
|
|
101
|
+
__metadata("design:paramtypes", [Object, String, String]),
|
|
70
102
|
__metadata("design:returntype", Promise)
|
|
71
103
|
], ConfigurationsController.prototype, "remove", null);
|
|
72
104
|
ConfigurationsController = __decorate([
|
|
73
|
-
|
|
105
|
+
ApiTags('configurations'),
|
|
106
|
+
Controller('environments/:environmentId/configurations'),
|
|
74
107
|
__metadata("design:paramtypes", [ConfigurationsService])
|
|
75
108
|
], ConfigurationsController);
|
|
76
109
|
export { ConfigurationsController };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configurations.module.d.ts","sourceRoot":"","sources":["../../src/configurations/configurations.module.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"configurations.module.d.ts","sourceRoot":"","sources":["../../src/configurations/configurations.module.ts"],"names":[],"mappings":"AAMA,qBAMa,oBAAoB;CAAG"}
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { __decorate } from "tslib";
|
|
2
2
|
import { Module } from '@nestjs/common';
|
|
3
|
+
import { EnvironmentsModule } from '../environments/environments.module.js';
|
|
3
4
|
import { ConfigurationsController } from './configurations.controller.js';
|
|
5
|
+
import { ConfigurationsRepository } from './configurations.repository.js';
|
|
4
6
|
import { ConfigurationsService } from './configurations.service.js';
|
|
5
7
|
let ConfigurationsModule = class ConfigurationsModule {
|
|
6
8
|
};
|
|
7
9
|
ConfigurationsModule = __decorate([
|
|
8
10
|
Module({
|
|
11
|
+
imports: [EnvironmentsModule],
|
|
9
12
|
controllers: [ConfigurationsController],
|
|
10
|
-
providers: [ConfigurationsService],
|
|
13
|
+
providers: [ConfigurationsService, ConfigurationsRepository],
|
|
11
14
|
exports: [ConfigurationsService],
|
|
12
15
|
})
|
|
13
16
|
], ConfigurationsModule);
|