@kosha-ai/server 0.0.6 → 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/config/kosha-config.d.ts +21 -0
- package/dist/config/kosha-config.d.ts.map +1 -1
- package/dist/config/kosha-config.js +31 -2
- 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.d.ts +3 -0
- package/dist/credentials/credentials.module.d.ts.map +1 -0
- package/dist/credentials/credentials.module.js +15 -0
- 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 +45 -0
- package/dist/credentials/credentials.service.d.ts.map +1 -0
- package/dist/credentials/credentials.service.js +135 -0
- 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/ca.service.d.ts +36 -0
- package/dist/egress/ca.service.d.ts.map +1 -0
- package/dist/egress/ca.service.js +117 -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 +18 -0
- package/dist/egress/egress.controller.d.ts.map +1 -0
- package/dist/egress/egress.controller.js +80 -0
- package/dist/egress/egress.listener.d.ts +39 -0
- package/dist/egress/egress.listener.d.ts.map +1 -0
- package/dist/egress/egress.listener.js +328 -0
- package/dist/egress/egress.module.d.ts +7 -0
- package/dist/egress/egress.module.d.ts.map +1 -0
- package/dist/egress/egress.module.js +31 -0
- 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 +77 -0
- package/dist/egress/grants.service.d.ts.map +1 -0
- package/dist/egress/grants.service.js +159 -0
- package/dist/egress/host-rules.service.d.ts +35 -0
- package/dist/egress/host-rules.service.d.ts.map +1 -0
- package/dist/egress/host-rules.service.js +48 -0
- 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 +17 -35
- package/dist/generated/prisma/browser.d.ts.map +1 -1
- package/dist/generated/prisma/client.d.ts +17 -35
- 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 +24 -46
- 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 +258 -472
- package/dist/generated/prisma/internal/prismaNamespace.d.ts.map +1 -1
- package/dist/generated/prisma/internal/prismaNamespace.js +45 -83
- package/dist/generated/prisma/internal/prismaNamespaceBrowser.d.ts +45 -85
- package/dist/generated/prisma/internal/prismaNamespaceBrowser.d.ts.map +1 -1
- package/dist/generated/prisma/internal/prismaNamespaceBrowser.js +45 -83
- 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 +1535 -0
- package/dist/generated/prisma/models/EgressGrant.d.ts.map +1 -0
- 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 +183 -322
- 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 +4 -6
- package/dist/generated/prisma/models.d.ts.map +1 -1
- package/dist/index.d.ts +20 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -3
- 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 +13 -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 -3
- 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 -21
- package/dist/proxy/proxy.service.d.ts.map +1 -1
- package/dist/proxy/proxy.service.js +61 -110
- package/package.json +9 -4
- package/prisma/migrations/20260929101936_init/migration.sql +345 -0
- package/prisma/migrations/20260930102529_connection_config/migration.sql +2 -0
- package/prisma/schema.prisma +103 -178
- 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 -1539
- package/dist/generated/prisma/models/EndUser.d.ts.map +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/dist/generated/prisma/models/{ConnectSession.js → EgressGrant.js} +0 -0
- /package/dist/generated/prisma/models/{Connection.js → Environment.js} +0 -0
- /package/dist/generated/prisma/models/{ConnectionCredential.js → Team.js} +0 -0
- /package/dist/generated/prisma/models/{EndUser.js → TeamMember.js} +0 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { CryptoService } from '../crypto/crypto.service.js';
|
|
2
|
+
import { EnvironmentsService } from '../environments/environments.service.js';
|
|
3
|
+
import { CaService } from './ca.service.js';
|
|
4
|
+
import { EgressRepository, type BorrowableCredential } from './egress.repository.js';
|
|
5
|
+
import { HostRulesService } from './host-rules.service.js';
|
|
6
|
+
/**
|
|
7
|
+
* Grants: what a sandbox may authenticate as, and for how long.
|
|
8
|
+
*
|
|
9
|
+
* A grant names a person. It is not a provider credential and cannot be turned
|
|
10
|
+
* into one outside this process, so a leaked one buys only the calls that
|
|
11
|
+
* sandbox could already make, until it expires or is revoked.
|
|
12
|
+
*/
|
|
13
|
+
export interface Grant {
|
|
14
|
+
readonly id: string;
|
|
15
|
+
readonly organizationId: string;
|
|
16
|
+
/**
|
|
17
|
+
* The `user` row the grant borrows from. A user exists per environment, so
|
|
18
|
+
* this settles the environment too — a grant cannot reach a credential from
|
|
19
|
+
* another one.
|
|
20
|
+
*/
|
|
21
|
+
readonly userId: string;
|
|
22
|
+
/** Empty means every provider this person has connected. */
|
|
23
|
+
readonly providerKeys: readonly string[];
|
|
24
|
+
readonly caPem: string;
|
|
25
|
+
readonly caKeyPem: string;
|
|
26
|
+
readonly expiresAt: Date;
|
|
27
|
+
}
|
|
28
|
+
export interface MintGrantInput {
|
|
29
|
+
readonly externalUserId: string;
|
|
30
|
+
readonly providerKeys?: readonly string[];
|
|
31
|
+
readonly expiresAt: Date;
|
|
32
|
+
readonly label?: string;
|
|
33
|
+
}
|
|
34
|
+
export interface MintedGrant {
|
|
35
|
+
readonly grantId: string;
|
|
36
|
+
/** Returned exactly once. Nothing can read it back afterwards. */
|
|
37
|
+
readonly token: string;
|
|
38
|
+
readonly caPem: string;
|
|
39
|
+
readonly expiresAt: Date;
|
|
40
|
+
/** The providers this grant actually resolved to, for the caller to report. */
|
|
41
|
+
readonly providers: string[];
|
|
42
|
+
}
|
|
43
|
+
export declare class GrantsService {
|
|
44
|
+
private readonly grants;
|
|
45
|
+
private readonly crypto;
|
|
46
|
+
private readonly ca;
|
|
47
|
+
private readonly hostRules;
|
|
48
|
+
private readonly environments;
|
|
49
|
+
private readonly logger;
|
|
50
|
+
private readonly cache;
|
|
51
|
+
constructor(grants: EgressRepository, crypto: CryptoService, ca: CaService, hostRules: HostRulesService, environments: EnvironmentsService);
|
|
52
|
+
/**
|
|
53
|
+
* Unsalted on purpose: the token is 32 random bytes, so there is nothing to
|
|
54
|
+
* brute-force and a per-row salt would only stop the lookup being an index
|
|
55
|
+
* scan.
|
|
56
|
+
*/
|
|
57
|
+
private hashToken;
|
|
58
|
+
mint(organizationId: string, environmentId: string, input: MintGrantInput): Promise<MintedGrant>;
|
|
59
|
+
revoke(organizationId: string, grantId: string): Promise<boolean>;
|
|
60
|
+
/**
|
|
61
|
+
* The grant a token names, or null for unknown, expired and revoked alike --
|
|
62
|
+
* telling those apart would tell an attacker which guess was once real.
|
|
63
|
+
*/
|
|
64
|
+
resolve(token: string): Promise<Grant | null>;
|
|
65
|
+
/**
|
|
66
|
+
* The credential this grant may borrow for one integration, or null. Scoped
|
|
67
|
+
* by the grant's own user, never by an id in a request -- that is what stops
|
|
68
|
+
* one grant reaching another tenant's credential.
|
|
69
|
+
*/
|
|
70
|
+
credentialFor(grant: Grant, integrationKey: string): Promise<BorrowableCredential | null>;
|
|
71
|
+
/** Deletes grants that expired a while ago. Housekeeping, nothing depends on it. */
|
|
72
|
+
pruneExpired(): Promise<number>;
|
|
73
|
+
private forget;
|
|
74
|
+
/** Which brokered providers this person has actually connected. */
|
|
75
|
+
private providersFor;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=grants.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grants.service.d.ts","sourceRoot":"","sources":["../../src/egress/grants.service.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAC9E,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EACL,gBAAgB,EAChB,KAAK,oBAAoB,EAC1B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D;;;;;;GAMG;AAEH,MAAM,WAAW,KAAK;IACpB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,4DAA4D;IAC5D,QAAQ,CAAC,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;IACzC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC;CAC1B;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1C,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC;IACzB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,kEAAkE;IAClE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC;IACzB,+EAA+E;IAC/E,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,CAAC;CAC9B;AAoBD,qBACa,aAAa;IAKtB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,EAAE;IACnB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,YAAY;IAR/B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAkC;IACzD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAiC;gBAGpC,MAAM,EAAE,gBAAgB,EACxB,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,SAAS,EACb,SAAS,EAAE,gBAAgB,EAC3B,YAAY,EAAE,mBAAmB;IAGpD;;;;OAIG;IACH,OAAO,CAAC,SAAS;IAIX,IAAI,CACR,cAAc,EAAE,MAAM,EACtB,aAAa,EAAE,MAAM,EACrB,KAAK,EAAE,cAAc,GACpB,OAAO,CAAC,WAAW,CAAC;IAkEjB,MAAM,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAUvE;;;OAGG;IACG,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC;IA0BnD;;;;OAIG;IACG,aAAa,CACjB,KAAK,EAAE,KAAK,EACZ,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;IAWvC,oFAAoF;IACpF,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC;IAM/B,OAAO,CAAC,MAAM;IAMd,mEAAmE;YACrD,YAAY;CAU3B"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
var GrantsService_1;
|
|
2
|
+
import { __decorate, __metadata } from "tslib";
|
|
3
|
+
import { BadRequestException, Injectable, Logger, NotFoundException, } from '@nestjs/common';
|
|
4
|
+
import { createHash, randomBytes } from 'node:crypto';
|
|
5
|
+
import { CryptoService } from '../crypto/crypto.service.js';
|
|
6
|
+
import { EnvironmentsService } from '../environments/environments.service.js';
|
|
7
|
+
import { CaService } from './ca.service.js';
|
|
8
|
+
import { EgressRepository, } from './egress.repository.js';
|
|
9
|
+
import { HostRulesService } from './host-rules.service.js';
|
|
10
|
+
/** A ceiling, not a policy: callers pick their own expiry from a task budget. */
|
|
11
|
+
const MAX_LIFETIME_MS = 25 * 60 * 60_000;
|
|
12
|
+
const MAX_LABEL_LENGTH = 200;
|
|
13
|
+
/**
|
|
14
|
+
* How long a revoked grant keeps working. The price of not querying Postgres on
|
|
15
|
+
* every CONNECT, and a git clone makes a great many of those.
|
|
16
|
+
*/
|
|
17
|
+
const CACHE_MS = 30_000;
|
|
18
|
+
const PRUNE_AFTER_MS = 7 * 24 * 60 * 60_000;
|
|
19
|
+
let GrantsService = GrantsService_1 = class GrantsService {
|
|
20
|
+
grants;
|
|
21
|
+
crypto;
|
|
22
|
+
ca;
|
|
23
|
+
hostRules;
|
|
24
|
+
environments;
|
|
25
|
+
logger = new Logger(GrantsService_1.name);
|
|
26
|
+
cache = new Map();
|
|
27
|
+
constructor(grants, crypto, ca, hostRules, environments) {
|
|
28
|
+
this.grants = grants;
|
|
29
|
+
this.crypto = crypto;
|
|
30
|
+
this.ca = ca;
|
|
31
|
+
this.hostRules = hostRules;
|
|
32
|
+
this.environments = environments;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Unsalted on purpose: the token is 32 random bytes, so there is nothing to
|
|
36
|
+
* brute-force and a per-row salt would only stop the lookup being an index
|
|
37
|
+
* scan.
|
|
38
|
+
*/
|
|
39
|
+
hashToken(token) {
|
|
40
|
+
return createHash('sha256').update(token).digest('hex');
|
|
41
|
+
}
|
|
42
|
+
async mint(organizationId, environmentId, input) {
|
|
43
|
+
const externalUserId = input.externalUserId?.trim();
|
|
44
|
+
if (!externalUserId) {
|
|
45
|
+
throw new BadRequestException('externalUserId is required');
|
|
46
|
+
}
|
|
47
|
+
const lifetime = input.expiresAt.getTime() - Date.now();
|
|
48
|
+
if (Number.isNaN(lifetime)) {
|
|
49
|
+
throw new BadRequestException('expiresAt must be an ISO date');
|
|
50
|
+
}
|
|
51
|
+
if (lifetime <= 0) {
|
|
52
|
+
throw new BadRequestException('expiresAt is already past');
|
|
53
|
+
}
|
|
54
|
+
if (lifetime > MAX_LIFETIME_MS) {
|
|
55
|
+
throw new BadRequestException('expiresAt is more than 25h away');
|
|
56
|
+
}
|
|
57
|
+
const environment = await this.environments.get(organizationId, environmentId);
|
|
58
|
+
const user = await this.grants.findEndUser(environment.slug, externalUserId);
|
|
59
|
+
if (!user) {
|
|
60
|
+
throw new NotFoundException(`No end user "${externalUserId}" in this environment. They have to connect a provider before a sandbox can borrow one.`);
|
|
61
|
+
}
|
|
62
|
+
// Narrowing only. An unknown key resolves to nothing, same as the person
|
|
63
|
+
// not having connected it.
|
|
64
|
+
const providerKeys = (input.providerKeys ?? []).map((key) => key.trim());
|
|
65
|
+
const authority = this.ca.createCertificateAuthority();
|
|
66
|
+
const token = randomBytes(32).toString('base64url');
|
|
67
|
+
const grant = await this.grants.createGrant({
|
|
68
|
+
organizationId,
|
|
69
|
+
userId: user.id,
|
|
70
|
+
tokenHash: this.hashToken(token),
|
|
71
|
+
providerKeys,
|
|
72
|
+
caPem: authority.certPem,
|
|
73
|
+
caKey: this.crypto.encrypt(authority.keyPem),
|
|
74
|
+
label: input.label?.slice(0, MAX_LABEL_LENGTH),
|
|
75
|
+
expiresAt: input.expiresAt,
|
|
76
|
+
});
|
|
77
|
+
const providers = await this.providersFor(user.id, providerKeys);
|
|
78
|
+
this.logger.log(`Minted egress grant ${grant.id} for ${externalUserId} in ${environment.slug}` +
|
|
79
|
+
` (${providers.join(', ') || 'no connected provider'}), expires ${grant.expiresAt.toISOString()}`);
|
|
80
|
+
return {
|
|
81
|
+
caPem: authority.certPem,
|
|
82
|
+
expiresAt: grant.expiresAt,
|
|
83
|
+
grantId: grant.id,
|
|
84
|
+
providers,
|
|
85
|
+
token,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
async revoke(organizationId, grantId) {
|
|
89
|
+
const count = await this.grants.revokeGrant(organizationId, grantId);
|
|
90
|
+
this.forget(grantId);
|
|
91
|
+
this.ca.forgetLeaves(grantId);
|
|
92
|
+
this.logger.log(`Revoked egress grant ${grantId} (found: ${count > 0})`);
|
|
93
|
+
return count > 0;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The grant a token names, or null for unknown, expired and revoked alike --
|
|
97
|
+
* telling those apart would tell an attacker which guess was once real.
|
|
98
|
+
*/
|
|
99
|
+
async resolve(token) {
|
|
100
|
+
if (token.length === 0)
|
|
101
|
+
return null;
|
|
102
|
+
const key = this.hashToken(token);
|
|
103
|
+
const hit = this.cache.get(key);
|
|
104
|
+
if (hit !== undefined && Date.now() - hit.at < CACHE_MS)
|
|
105
|
+
return hit.grant;
|
|
106
|
+
const row = await this.grants.findLiveGrant(key);
|
|
107
|
+
const grant = row === null
|
|
108
|
+
? null
|
|
109
|
+
: {
|
|
110
|
+
caKeyPem: this.crypto.decrypt(row.caKey),
|
|
111
|
+
caPem: row.caPem,
|
|
112
|
+
expiresAt: row.expiresAt,
|
|
113
|
+
id: row.id,
|
|
114
|
+
organizationId: row.organizationId,
|
|
115
|
+
providerKeys: row.providerKeys,
|
|
116
|
+
userId: row.userId,
|
|
117
|
+
};
|
|
118
|
+
this.cache.set(key, { at: Date.now(), grant });
|
|
119
|
+
return grant;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* The credential this grant may borrow for one integration, or null. Scoped
|
|
123
|
+
* by the grant's own user, never by an id in a request -- that is what stops
|
|
124
|
+
* one grant reaching another tenant's credential.
|
|
125
|
+
*/
|
|
126
|
+
async credentialFor(grant, integrationKey) {
|
|
127
|
+
if (grant.providerKeys.length > 0 &&
|
|
128
|
+
!grant.providerKeys.includes(integrationKey)) {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
return this.grants.findCredentialFor(grant.userId, integrationKey);
|
|
132
|
+
}
|
|
133
|
+
/** Deletes grants that expired a while ago. Housekeeping, nothing depends on it. */
|
|
134
|
+
pruneExpired() {
|
|
135
|
+
return this.grants.deleteExpiredBefore(new Date(Date.now() - PRUNE_AFTER_MS));
|
|
136
|
+
}
|
|
137
|
+
forget(grantId) {
|
|
138
|
+
for (const [key, entry] of this.cache) {
|
|
139
|
+
if (entry.grant?.id === grantId)
|
|
140
|
+
this.cache.delete(key);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/** Which brokered providers this person has actually connected. */
|
|
144
|
+
async providersFor(userId, providerKeys) {
|
|
145
|
+
const candidates = this.hostRules
|
|
146
|
+
.brokeredProviderKeys()
|
|
147
|
+
.filter((key) => providerKeys.length === 0 || providerKeys.includes(key));
|
|
148
|
+
return this.grants.connectedIntegrationKeys(userId, candidates);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
GrantsService = GrantsService_1 = __decorate([
|
|
152
|
+
Injectable(),
|
|
153
|
+
__metadata("design:paramtypes", [EgressRepository,
|
|
154
|
+
CryptoService,
|
|
155
|
+
CaService,
|
|
156
|
+
HostRulesService,
|
|
157
|
+
EnvironmentsService])
|
|
158
|
+
], GrantsService);
|
|
159
|
+
export { GrantsService };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Credential } from '@kosha-ai/integration-sdk';
|
|
2
|
+
import { IntegrationRegistry } from '../integrations/integration.registry.js';
|
|
3
|
+
/**
|
|
4
|
+
* Which hostnames are brokered, and what gets injected when they are.
|
|
5
|
+
*
|
|
6
|
+
* A host with no rule is tunnelled, not blocked: a sandbox needs npm, PyPI and
|
|
7
|
+
* whatever else its toolchain reaches for, and that list is not knowable in
|
|
8
|
+
* advance. Blocking is a network policy's job.
|
|
9
|
+
*
|
|
10
|
+
* Built from the installed integrations rather than written here, so adding a
|
|
11
|
+
* provider is `api.egress` on its integration and nothing else -- and a host
|
|
12
|
+
* follows its integration's configuration, which is how GitHub Enterprise
|
|
13
|
+
* Server works without this file knowing GHES exists.
|
|
14
|
+
*/
|
|
15
|
+
export interface ResolvedHostRule {
|
|
16
|
+
/** The provider key whose connection authenticates this host. */
|
|
17
|
+
readonly providerKey: string;
|
|
18
|
+
readonly headers: (credential: Credential) => Record<string, string>;
|
|
19
|
+
}
|
|
20
|
+
export declare class HostRulesService {
|
|
21
|
+
private readonly registry;
|
|
22
|
+
private compiled?;
|
|
23
|
+
constructor(registry: IntegrationRegistry);
|
|
24
|
+
/**
|
|
25
|
+
* The rule for a hostname, or undefined for "tunnel this".
|
|
26
|
+
*
|
|
27
|
+
* Exact matches before wildcards: `api.github.com` has a different header
|
|
28
|
+
* shape from `github.com`, and a shadowing wildcard would send the wrong one.
|
|
29
|
+
*/
|
|
30
|
+
ruleFor(host: string): ResolvedHostRule | undefined;
|
|
31
|
+
/** Every provider key that declares at least one brokered host. */
|
|
32
|
+
brokeredProviderKeys(): string[];
|
|
33
|
+
private rules;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=host-rules.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host-rules.service.d.ts","sourceRoot":"","sources":["../../src/egress/host-rules.service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAkB,MAAM,2BAA2B,CAAC;AAC5E,OAAO,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAE9E;;;;;;;;;;;GAWG;AAEH,MAAM,WAAW,gBAAgB;IAC/B,iEAAiE;IACjE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,OAAO,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtE;AAaD,qBACa,gBAAgB;IAGf,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAFrC,OAAO,CAAC,QAAQ,CAAC,CAA0B;gBAEd,QAAQ,EAAE,mBAAmB;IAE1D;;;;;OAKG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS;IAmBnD,mEAAmE;IACnE,oBAAoB,IAAI,MAAM,EAAE;IAIhC,OAAO,CAAC,KAAK;CAed"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { Injectable } from '@nestjs/common';
|
|
3
|
+
import { IntegrationRegistry } from '../integrations/integration.registry.js';
|
|
4
|
+
function hostMatches(pattern, host) {
|
|
5
|
+
// A leading wildcard covers subdomains at any depth but not the apex, which
|
|
6
|
+
// an integration lists separately if it needs it.
|
|
7
|
+
if (pattern.startsWith('*.'))
|
|
8
|
+
return host.endsWith(pattern.slice(1));
|
|
9
|
+
return host === pattern;
|
|
10
|
+
}
|
|
11
|
+
let HostRulesService = class HostRulesService {
|
|
12
|
+
registry;
|
|
13
|
+
compiled;
|
|
14
|
+
constructor(registry) {
|
|
15
|
+
this.registry = registry;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The rule for a hostname, or undefined for "tunnel this".
|
|
19
|
+
*
|
|
20
|
+
* Exact matches before wildcards: `api.github.com` has a different header
|
|
21
|
+
* shape from `github.com`, and a shadowing wildcard would send the wrong one.
|
|
22
|
+
*/
|
|
23
|
+
ruleFor(host) {
|
|
24
|
+
const needle = host.toLowerCase();
|
|
25
|
+
const rules = this.rules();
|
|
26
|
+
return (rules.find((rule) => rule.hosts.some((pattern) => !pattern.startsWith('*.') && hostMatches(pattern, needle))) ??
|
|
27
|
+
rules.find((rule) => rule.hosts.some((pattern) => pattern.startsWith('*.') && hostMatches(pattern, needle))));
|
|
28
|
+
}
|
|
29
|
+
/** Every provider key that declares at least one brokered host. */
|
|
30
|
+
brokeredProviderKeys() {
|
|
31
|
+
return [...new Set(this.rules().map((rule) => rule.providerKey))];
|
|
32
|
+
}
|
|
33
|
+
rules() {
|
|
34
|
+
// The registry is fixed for the life of the process.
|
|
35
|
+
this.compiled ??= this.registry.list().flatMap((integration) => (integration.api.egress ?? []).map((rule) => ({
|
|
36
|
+
headers: rule.headers?.bind(rule) ??
|
|
37
|
+
((credential) => integration.api.authHeaders(credential)),
|
|
38
|
+
hosts: rule.hosts.map((host) => host.toLowerCase()),
|
|
39
|
+
providerKey: integration.key,
|
|
40
|
+
})));
|
|
41
|
+
return this.compiled;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
HostRulesService = __decorate([
|
|
45
|
+
Injectable(),
|
|
46
|
+
__metadata("design:paramtypes", [IntegrationRegistry])
|
|
47
|
+
], HostRulesService);
|
|
48
|
+
export { HostRulesService };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-environment.dto.d.ts","sourceRoot":"","sources":["../../../src/environments/dto/create-environment.dto.ts"],"names":[],"mappings":"AAGA,qBAAa,oBAAoB;IAK/B,IAAI,EAAG,MAAM,CAAC;IASd,IAAI,CAAC,EAAE,MAAM,CAAC;IASd,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
|
3
|
+
import { IsOptional, IsString, MaxLength, MinLength } from 'class-validator';
|
|
4
|
+
export class CreateEnvironmentDto {
|
|
5
|
+
name;
|
|
6
|
+
slug;
|
|
7
|
+
teamId;
|
|
8
|
+
}
|
|
9
|
+
__decorate([
|
|
10
|
+
ApiProperty({ example: 'Production' }),
|
|
11
|
+
IsString(),
|
|
12
|
+
MinLength(1),
|
|
13
|
+
MaxLength(64),
|
|
14
|
+
__metadata("design:type", String)
|
|
15
|
+
], CreateEnvironmentDto.prototype, "name", void 0);
|
|
16
|
+
__decorate([
|
|
17
|
+
ApiPropertyOptional({
|
|
18
|
+
example: 'production',
|
|
19
|
+
description: 'Caller-facing handle. Derived from the name when omitted.',
|
|
20
|
+
}),
|
|
21
|
+
IsOptional(),
|
|
22
|
+
IsString(),
|
|
23
|
+
MaxLength(64),
|
|
24
|
+
__metadata("design:type", String)
|
|
25
|
+
], CreateEnvironmentDto.prototype, "slug", void 0);
|
|
26
|
+
__decorate([
|
|
27
|
+
ApiPropertyOptional({
|
|
28
|
+
description: 'Restricts access to members of this team. Omit to leave the environment open to every member of the organization.',
|
|
29
|
+
nullable: true,
|
|
30
|
+
}),
|
|
31
|
+
IsOptional(),
|
|
32
|
+
IsString(),
|
|
33
|
+
__metadata("design:type", Object)
|
|
34
|
+
], CreateEnvironmentDto.prototype, "teamId", void 0);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update-environment.dto.d.ts","sourceRoot":"","sources":["../../../src/environments/dto/update-environment.dto.ts"],"names":[],"mappings":"AAGA,qBAAa,oBAAoB;IAM/B,IAAI,CAAC,EAAE,MAAM,CAAC;IASd,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { ApiPropertyOptional } from '@nestjs/swagger';
|
|
3
|
+
import { IsOptional, IsString, MaxLength, MinLength } from 'class-validator';
|
|
4
|
+
export class UpdateEnvironmentDto {
|
|
5
|
+
name;
|
|
6
|
+
teamId;
|
|
7
|
+
}
|
|
8
|
+
__decorate([
|
|
9
|
+
ApiPropertyOptional({ example: 'Production' }),
|
|
10
|
+
IsOptional(),
|
|
11
|
+
IsString(),
|
|
12
|
+
MinLength(1),
|
|
13
|
+
MaxLength(64),
|
|
14
|
+
__metadata("design:type", String)
|
|
15
|
+
], UpdateEnvironmentDto.prototype, "name", void 0);
|
|
16
|
+
__decorate([
|
|
17
|
+
ApiPropertyOptional({
|
|
18
|
+
description: 'Restricts access to members of this team. Null opens the environment to every member of the organization.',
|
|
19
|
+
nullable: true,
|
|
20
|
+
}),
|
|
21
|
+
IsOptional(),
|
|
22
|
+
IsString(),
|
|
23
|
+
__metadata("design:type", Object)
|
|
24
|
+
], UpdateEnvironmentDto.prototype, "teamId", void 0);
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { type UserSession } from '@thallesp/nestjs-better-auth';
|
|
2
|
+
import { CreateEnvironmentDto } from './dto/create-environment.dto.js';
|
|
3
|
+
import { UpdateEnvironmentDto } from './dto/update-environment.dto.js';
|
|
4
|
+
import { EnvironmentsService } from './environments.service.js';
|
|
5
|
+
/**
|
|
6
|
+
* Admin-facing. Session authenticated and scoped to the caller's active
|
|
7
|
+
* organization — never accepts an organizationId from the request.
|
|
8
|
+
*/
|
|
9
|
+
export declare class EnvironmentsController {
|
|
10
|
+
private readonly environments;
|
|
11
|
+
constructor(environments: EnvironmentsService);
|
|
12
|
+
list(session: UserSession): Promise<{
|
|
13
|
+
name: string;
|
|
14
|
+
id: string;
|
|
15
|
+
createdAt: Date;
|
|
16
|
+
updatedAt: Date;
|
|
17
|
+
slug: string;
|
|
18
|
+
teamId: string | null;
|
|
19
|
+
organizationId: string;
|
|
20
|
+
}[]>;
|
|
21
|
+
get(session: UserSession, id: string): Promise<{
|
|
22
|
+
name: string;
|
|
23
|
+
id: string;
|
|
24
|
+
createdAt: Date;
|
|
25
|
+
updatedAt: Date;
|
|
26
|
+
slug: string;
|
|
27
|
+
teamId: string | null;
|
|
28
|
+
organizationId: string;
|
|
29
|
+
}>;
|
|
30
|
+
create(session: UserSession, body: CreateEnvironmentDto): Promise<{
|
|
31
|
+
name: string;
|
|
32
|
+
id: string;
|
|
33
|
+
createdAt: Date;
|
|
34
|
+
updatedAt: Date;
|
|
35
|
+
slug: string;
|
|
36
|
+
teamId: string | null;
|
|
37
|
+
organizationId: string;
|
|
38
|
+
}>;
|
|
39
|
+
update(session: UserSession, id: string, body: UpdateEnvironmentDto): Promise<{
|
|
40
|
+
name: string;
|
|
41
|
+
id: string;
|
|
42
|
+
createdAt: Date;
|
|
43
|
+
updatedAt: Date;
|
|
44
|
+
slug: string;
|
|
45
|
+
teamId: string | null;
|
|
46
|
+
organizationId: string;
|
|
47
|
+
}>;
|
|
48
|
+
remove(session: UserSession, id: string): Promise<{
|
|
49
|
+
id: string;
|
|
50
|
+
deleted: boolean;
|
|
51
|
+
}>;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=environments.controller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environments.controller.d.ts","sourceRoot":"","sources":["../../src/environments/environments.controller.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAW,KAAK,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAEzE,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAEhE;;;GAGG;AACH,qBAEa,sBAAsB;IACrB,OAAO,CAAC,QAAQ,CAAC,YAAY;gBAAZ,YAAY,EAAE,mBAAmB;IAS9D,IAAI,CAAY,OAAO,EAAE,WAAW;;;;;;;;;IAYpC,GAAG,CAAY,OAAO,EAAE,WAAW,EAAe,EAAE,EAAE,MAAM;;;;;;;;;IAY5D,MAAM,CAAY,OAAO,EAAE,WAAW,EAAU,IAAI,EAAE,oBAAoB;;;;;;;;;IAS1E,MAAM,CACO,OAAO,EAAE,WAAW,EAClB,EAAE,EAAE,MAAM,EACf,IAAI,EAAE,oBAAoB;;;;;;;;;IAiB9B,MAAM,CAAY,OAAO,EAAE,WAAW,EAAe,EAAE,EAAE,MAAM;;;;CAQtE"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { __decorate, __metadata, __param } from "tslib";
|
|
2
|
+
import { Body, Controller, Delete, Get, HttpCode, HttpStatus, Param, Patch, Post, } from '@nestjs/common';
|
|
3
|
+
import { ApiCreatedResponse, ApiNotFoundResponse, ApiOkResponse, ApiOperation, ApiTags, } from '@nestjs/swagger';
|
|
4
|
+
import { Session } from '@thallesp/nestjs-better-auth';
|
|
5
|
+
import { getActiveOrganizationId } from '../common/active-organization.js';
|
|
6
|
+
import { CreateEnvironmentDto } from './dto/create-environment.dto.js';
|
|
7
|
+
import { UpdateEnvironmentDto } from './dto/update-environment.dto.js';
|
|
8
|
+
import { EnvironmentsService } from './environments.service.js';
|
|
9
|
+
/**
|
|
10
|
+
* Admin-facing. Session authenticated and scoped to the caller's active
|
|
11
|
+
* organization — never accepts an organizationId from the request.
|
|
12
|
+
*/
|
|
13
|
+
let EnvironmentsController = class EnvironmentsController {
|
|
14
|
+
environments;
|
|
15
|
+
constructor(environments) {
|
|
16
|
+
this.environments = environments;
|
|
17
|
+
}
|
|
18
|
+
list(session) {
|
|
19
|
+
return this.environments.listFor(getActiveOrganizationId(session), session.user.id);
|
|
20
|
+
}
|
|
21
|
+
get(session, id) {
|
|
22
|
+
return this.environments.getForMember(getActiveOrganizationId(session), session.user.id, id);
|
|
23
|
+
}
|
|
24
|
+
create(session, body) {
|
|
25
|
+
return this.environments.create(getActiveOrganizationId(session), body);
|
|
26
|
+
}
|
|
27
|
+
update(session, id, body) {
|
|
28
|
+
return this.environments.update(getActiveOrganizationId(session), session.user.id, id, body);
|
|
29
|
+
}
|
|
30
|
+
async remove(session, id) {
|
|
31
|
+
await this.environments.remove(getActiveOrganizationId(session), session.user.id, id);
|
|
32
|
+
return { id, deleted: true };
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
__decorate([
|
|
36
|
+
Get(),
|
|
37
|
+
ApiOperation({
|
|
38
|
+
summary: 'List the environments this member can reach',
|
|
39
|
+
description: 'An environment with no team is open to every member of the organization; one with a team is visible only to that team.',
|
|
40
|
+
}),
|
|
41
|
+
ApiOkResponse({ description: 'Environments, oldest first.' }),
|
|
42
|
+
__param(0, Session()),
|
|
43
|
+
__metadata("design:type", Function),
|
|
44
|
+
__metadata("design:paramtypes", [Object]),
|
|
45
|
+
__metadata("design:returntype", void 0)
|
|
46
|
+
], EnvironmentsController.prototype, "list", null);
|
|
47
|
+
__decorate([
|
|
48
|
+
Get(':id'),
|
|
49
|
+
ApiOperation({ summary: 'Get one environment' }),
|
|
50
|
+
ApiNotFoundResponse({
|
|
51
|
+
description: 'No such environment in this organization.',
|
|
52
|
+
}),
|
|
53
|
+
__param(0, Session()),
|
|
54
|
+
__param(1, Param('id')),
|
|
55
|
+
__metadata("design:type", Function),
|
|
56
|
+
__metadata("design:paramtypes", [Object, String]),
|
|
57
|
+
__metadata("design:returntype", void 0)
|
|
58
|
+
], EnvironmentsController.prototype, "get", null);
|
|
59
|
+
__decorate([
|
|
60
|
+
Post(),
|
|
61
|
+
HttpCode(HttpStatus.CREATED),
|
|
62
|
+
ApiOperation({ summary: 'Create an environment' }),
|
|
63
|
+
ApiCreatedResponse({ description: 'The created environment.' }),
|
|
64
|
+
__param(0, Session()),
|
|
65
|
+
__param(1, Body()),
|
|
66
|
+
__metadata("design:type", Function),
|
|
67
|
+
__metadata("design:paramtypes", [Object, CreateEnvironmentDto]),
|
|
68
|
+
__metadata("design:returntype", void 0)
|
|
69
|
+
], EnvironmentsController.prototype, "create", null);
|
|
70
|
+
__decorate([
|
|
71
|
+
Patch(':id'),
|
|
72
|
+
ApiOperation({
|
|
73
|
+
summary: 'Rename an environment, or change which team gates it',
|
|
74
|
+
}),
|
|
75
|
+
ApiOkResponse({ description: 'The updated environment.' }),
|
|
76
|
+
__param(0, Session()),
|
|
77
|
+
__param(1, Param('id')),
|
|
78
|
+
__param(2, Body()),
|
|
79
|
+
__metadata("design:type", Function),
|
|
80
|
+
__metadata("design:paramtypes", [Object, String, UpdateEnvironmentDto]),
|
|
81
|
+
__metadata("design:returntype", void 0)
|
|
82
|
+
], EnvironmentsController.prototype, "update", null);
|
|
83
|
+
__decorate([
|
|
84
|
+
Delete(':id'),
|
|
85
|
+
ApiOperation({
|
|
86
|
+
summary: 'Delete an environment',
|
|
87
|
+
description: 'Its configurations and stored credentials go with it. Kosha logins carry no environment and are untouched.',
|
|
88
|
+
}),
|
|
89
|
+
ApiOkResponse({ description: 'The deleted environment id.' }),
|
|
90
|
+
__param(0, Session()),
|
|
91
|
+
__param(1, Param('id')),
|
|
92
|
+
__metadata("design:type", Function),
|
|
93
|
+
__metadata("design:paramtypes", [Object, String]),
|
|
94
|
+
__metadata("design:returntype", Promise)
|
|
95
|
+
], EnvironmentsController.prototype, "remove", null);
|
|
96
|
+
EnvironmentsController = __decorate([
|
|
97
|
+
ApiTags('environments'),
|
|
98
|
+
Controller('environments'),
|
|
99
|
+
__metadata("design:paramtypes", [EnvironmentsService])
|
|
100
|
+
], EnvironmentsController);
|
|
101
|
+
export { EnvironmentsController };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environments.module.d.ts","sourceRoot":"","sources":["../../src/environments/environments.module.ts"],"names":[],"mappings":"AAKA,qBAKa,kBAAkB;CAAG"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { Module } from '@nestjs/common';
|
|
3
|
+
import { EnvironmentsController } from './environments.controller.js';
|
|
4
|
+
import { EnvironmentsRepository } from './environments.repository.js';
|
|
5
|
+
import { EnvironmentsService } from './environments.service.js';
|
|
6
|
+
let EnvironmentsModule = class EnvironmentsModule {
|
|
7
|
+
};
|
|
8
|
+
EnvironmentsModule = __decorate([
|
|
9
|
+
Module({
|
|
10
|
+
controllers: [EnvironmentsController],
|
|
11
|
+
providers: [EnvironmentsService, EnvironmentsRepository],
|
|
12
|
+
exports: [EnvironmentsService],
|
|
13
|
+
})
|
|
14
|
+
], EnvironmentsModule);
|
|
15
|
+
export { EnvironmentsModule };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Environment } from '../generated/prisma/client.js';
|
|
2
|
+
import { PrismaService } from '../prisma/prisma.service.js';
|
|
3
|
+
export interface EnvironmentRow {
|
|
4
|
+
organizationId: string;
|
|
5
|
+
name: string;
|
|
6
|
+
slug: string;
|
|
7
|
+
teamId?: string | null;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Every database statement about environments. The service above holds the
|
|
11
|
+
* rules and never touches Prisma, so it can be tested without one.
|
|
12
|
+
*/
|
|
13
|
+
export declare class EnvironmentsRepository {
|
|
14
|
+
private readonly prisma;
|
|
15
|
+
constructor(prisma: PrismaService);
|
|
16
|
+
/** Teams within one organization that this user belongs to. */
|
|
17
|
+
teamIdsFor(organizationId: string, userId: string): Promise<string[]>;
|
|
18
|
+
/** Open environments, plus those gated by a team the caller is on. */
|
|
19
|
+
findVisible(organizationId: string, teamIds: string[]): Promise<Environment[]>;
|
|
20
|
+
findById(organizationId: string, id: string): Promise<Environment | null>;
|
|
21
|
+
/** The same row, but only when this member's teams reach it. */
|
|
22
|
+
findVisibleById(organizationId: string, id: string, teamIds: string[]): Promise<Environment | null>;
|
|
23
|
+
findBySlug(organizationId: string, slug: string): Promise<Environment | null>;
|
|
24
|
+
create(row: EnvironmentRow): Promise<Environment>;
|
|
25
|
+
update(id: string, changes: {
|
|
26
|
+
name?: string;
|
|
27
|
+
teamId?: string | null;
|
|
28
|
+
}): Promise<Environment>;
|
|
29
|
+
/**
|
|
30
|
+
* Configurations and credentials go with it, through the foreign keys. Kosha
|
|
31
|
+
* logins carry no environment and are untouched.
|
|
32
|
+
*/
|
|
33
|
+
delete(id: string): Promise<void>;
|
|
34
|
+
createMany(rows: EnvironmentRow[]): Promise<void>;
|
|
35
|
+
teamExists(organizationId: string, teamId: string): Promise<boolean>;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=environments.repository.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environments.repository.d.ts","sourceRoot":"","sources":["../../src/environments/environments.repository.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAE5D,MAAM,WAAW,cAAc;IAC7B,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB;AAED;;;GAGG;AACH,qBACa,sBAAsB;IACrB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,aAAa;IAElD,+DAA+D;IACzD,UAAU,CAAC,cAAc,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAQ3E,sEAAsE;IACtE,WAAW,CACT,cAAc,EAAE,MAAM,EACtB,OAAO,EAAE,MAAM,EAAE,GAChB,OAAO,CAAC,WAAW,EAAE,CAAC;IAUzB,QAAQ,CAAC,cAAc,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAIzE,gEAAgE;IAChE,eAAe,CACb,cAAc,EAAE,MAAM,EACtB,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,MAAM,EAAE,GAChB,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAU9B,UAAU,CACR,cAAc,EAAE,MAAM,EACtB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAM9B,MAAM,CAAC,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,WAAW,CAAC;IAMjD,MAAM,CACJ,EAAE,EAAE,MAAM,EACV,OAAO,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,GACjD,OAAO,CAAC,WAAW,CAAC;IAIvB;;;OAGG;IACG,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIjC,UAAU,CAAC,IAAI,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAOjD,UAAU,CAAC,cAAc,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAO3E"}
|