@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,82 @@
|
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { Injectable } from '@nestjs/common';
|
|
3
|
+
import { PrismaService } from '../prisma/prisma.service.js';
|
|
4
|
+
/**
|
|
5
|
+
* Every database statement about environments. The service above holds the
|
|
6
|
+
* rules and never touches Prisma, so it can be tested without one.
|
|
7
|
+
*/
|
|
8
|
+
let EnvironmentsRepository = class EnvironmentsRepository {
|
|
9
|
+
prisma;
|
|
10
|
+
constructor(prisma) {
|
|
11
|
+
this.prisma = prisma;
|
|
12
|
+
}
|
|
13
|
+
/** Teams within one organization that this user belongs to. */
|
|
14
|
+
async teamIdsFor(organizationId, userId) {
|
|
15
|
+
const rows = await this.prisma.teamMember.findMany({
|
|
16
|
+
where: { userId, team: { organizationId } },
|
|
17
|
+
select: { teamId: true },
|
|
18
|
+
});
|
|
19
|
+
return rows.map((row) => row.teamId);
|
|
20
|
+
}
|
|
21
|
+
/** Open environments, plus those gated by a team the caller is on. */
|
|
22
|
+
findVisible(organizationId, teamIds) {
|
|
23
|
+
return this.prisma.environment.findMany({
|
|
24
|
+
where: {
|
|
25
|
+
organizationId,
|
|
26
|
+
OR: [{ teamId: null }, { teamId: { in: teamIds } }],
|
|
27
|
+
},
|
|
28
|
+
orderBy: { createdAt: 'asc' },
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
findById(organizationId, id) {
|
|
32
|
+
return this.prisma.environment.findFirst({ where: { id, organizationId } });
|
|
33
|
+
}
|
|
34
|
+
/** The same row, but only when this member's teams reach it. */
|
|
35
|
+
findVisibleById(organizationId, id, teamIds) {
|
|
36
|
+
return this.prisma.environment.findFirst({
|
|
37
|
+
where: {
|
|
38
|
+
id,
|
|
39
|
+
organizationId,
|
|
40
|
+
OR: [{ teamId: null }, { teamId: { in: teamIds } }],
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
findBySlug(organizationId, slug) {
|
|
45
|
+
return this.prisma.environment.findFirst({
|
|
46
|
+
where: { organizationId, slug },
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
create(row) {
|
|
50
|
+
return this.prisma.environment.create({
|
|
51
|
+
data: { ...row, teamId: row.teamId ?? null },
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
update(id, changes) {
|
|
55
|
+
return this.prisma.environment.update({ where: { id }, data: changes });
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Configurations and credentials go with it, through the foreign keys. Kosha
|
|
59
|
+
* logins carry no environment and are untouched.
|
|
60
|
+
*/
|
|
61
|
+
async delete(id) {
|
|
62
|
+
await this.prisma.environment.delete({ where: { id } });
|
|
63
|
+
}
|
|
64
|
+
async createMany(rows) {
|
|
65
|
+
await this.prisma.environment.createMany({
|
|
66
|
+
data: rows,
|
|
67
|
+
skipDuplicates: true,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
async teamExists(organizationId, teamId) {
|
|
71
|
+
const team = await this.prisma.team.findFirst({
|
|
72
|
+
where: { id: teamId, organizationId },
|
|
73
|
+
select: { id: true },
|
|
74
|
+
});
|
|
75
|
+
return team !== null;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
EnvironmentsRepository = __decorate([
|
|
79
|
+
Injectable(),
|
|
80
|
+
__metadata("design:paramtypes", [PrismaService])
|
|
81
|
+
], EnvironmentsRepository);
|
|
82
|
+
export { EnvironmentsRepository };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Environment } from '../generated/prisma/client.js';
|
|
2
|
+
import type { CreateEnvironmentDto } from './dto/create-environment.dto.js';
|
|
3
|
+
import type { UpdateEnvironmentDto } from './dto/update-environment.dto.js';
|
|
4
|
+
import { EnvironmentsRepository } from './environments.repository.js';
|
|
5
|
+
export declare class EnvironmentsService {
|
|
6
|
+
private readonly environments;
|
|
7
|
+
constructor(environments: EnvironmentsRepository);
|
|
8
|
+
/**
|
|
9
|
+
* What the member can reach: an environment with no team is open to the
|
|
10
|
+
* whole organization, one with a team needs membership of it.
|
|
11
|
+
*/
|
|
12
|
+
listFor(organizationId: string, userId: string): Promise<Environment[]>;
|
|
13
|
+
/**
|
|
14
|
+
* For machine callers. An API key already names one environment and the
|
|
15
|
+
* guard has checked it belongs to the key's organization; a key is not a
|
|
16
|
+
* person and has no teams.
|
|
17
|
+
*/
|
|
18
|
+
get(organizationId: string, id: string): Promise<Environment>;
|
|
19
|
+
/**
|
|
20
|
+
* For a signed-in person. A team gates the environment itself, not merely
|
|
21
|
+
* its place in a listing — otherwise the id is the whole security of it, and
|
|
22
|
+
* ids travel.
|
|
23
|
+
*
|
|
24
|
+
* Answers "not found" rather than "forbidden", so nobody learns which
|
|
25
|
+
* environments exist by asking.
|
|
26
|
+
*/
|
|
27
|
+
getForMember(organizationId: string, userId: string, id: string): Promise<Environment>;
|
|
28
|
+
/** Resolves the slug a caller quotes, within one organization. */
|
|
29
|
+
getBySlug(organizationId: string, slug: string): Promise<Environment>;
|
|
30
|
+
create(organizationId: string, input: CreateEnvironmentDto): Promise<Environment>;
|
|
31
|
+
update(organizationId: string, userId: string, id: string, input: UpdateEnvironmentDto): Promise<Environment>;
|
|
32
|
+
remove(organizationId: string, userId: string, id: string): Promise<void>;
|
|
33
|
+
/** Called from the organization-creation hook. */
|
|
34
|
+
seedDefaults(organizationId: string): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* The environment an API key names, re-checked against the key's own
|
|
37
|
+
* organization. `apikey.metadata` is a soft reference: nothing stops a key
|
|
38
|
+
* naming an environment that has since moved or gone.
|
|
39
|
+
*/
|
|
40
|
+
resolveForOrganization(organizationId: string, environmentId: unknown): Promise<Environment>;
|
|
41
|
+
private assertTeamBelongs;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=environments.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environments.service.d.ts","sourceRoot":"","sources":["../../src/environments/environments.service.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAC5E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAC5E,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AAWtE,qBACa,mBAAmB;IAClB,OAAO,CAAC,QAAQ,CAAC,YAAY;gBAAZ,YAAY,EAAE,sBAAsB;IAEjE;;;OAGG;IACG,OAAO,CACX,cAAc,EAAE,MAAM,EACtB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,WAAW,EAAE,CAAC;IAKzB;;;;OAIG;IACG,GAAG,CAAC,cAAc,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAMnE;;;;;;;OAOG;IACG,YAAY,CAChB,cAAc,EAAE,MAAM,EACtB,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,MAAM,GACT,OAAO,CAAC,WAAW,CAAC;IAWvB,kEAAkE;IAC5D,SAAS,CAAC,cAAc,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IASrE,MAAM,CACV,cAAc,EAAE,MAAM,EACtB,KAAK,EAAE,oBAAoB,GAC1B,OAAO,CAAC,WAAW,CAAC;IAsBjB,MAAM,CACV,cAAc,EAAE,MAAM,EACtB,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,oBAAoB,GAC1B,OAAO,CAAC,WAAW,CAAC;IAWjB,MAAM,CACV,cAAc,EAAE,MAAM,EACtB,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,MAAM,GACT,OAAO,CAAC,IAAI,CAAC;IAKhB,kDAAkD;IAC5C,YAAY,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAMzD;;;;OAIG;IACG,sBAAsB,CAC1B,cAAc,EAAE,MAAM,EACtB,aAAa,EAAE,OAAO,GACrB,OAAO,CAAC,WAAW,CAAC;YAmBT,iBAAiB;CAUhC"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { BadRequestException, Injectable, NotFoundException, } from '@nestjs/common';
|
|
3
|
+
import { EnvironmentsRepository } from './environments.repository.js';
|
|
4
|
+
/**
|
|
5
|
+
* Every organization starts with these two. Sandbox is first so a new
|
|
6
|
+
* organization does not point at production by omission.
|
|
7
|
+
*/
|
|
8
|
+
const DEFAULTS = [
|
|
9
|
+
{ name: 'Sandbox', slug: 'sandbox' },
|
|
10
|
+
{ name: 'Production', slug: 'production' },
|
|
11
|
+
];
|
|
12
|
+
let EnvironmentsService = class EnvironmentsService {
|
|
13
|
+
environments;
|
|
14
|
+
constructor(environments) {
|
|
15
|
+
this.environments = environments;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* What the member can reach: an environment with no team is open to the
|
|
19
|
+
* whole organization, one with a team needs membership of it.
|
|
20
|
+
*/
|
|
21
|
+
async listFor(organizationId, userId) {
|
|
22
|
+
const teamIds = await this.environments.teamIdsFor(organizationId, userId);
|
|
23
|
+
return this.environments.findVisible(organizationId, teamIds);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* For machine callers. An API key already names one environment and the
|
|
27
|
+
* guard has checked it belongs to the key's organization; a key is not a
|
|
28
|
+
* person and has no teams.
|
|
29
|
+
*/
|
|
30
|
+
async get(organizationId, id) {
|
|
31
|
+
const environment = await this.environments.findById(organizationId, id);
|
|
32
|
+
if (!environment)
|
|
33
|
+
throw new NotFoundException('Environment not found');
|
|
34
|
+
return environment;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* For a signed-in person. A team gates the environment itself, not merely
|
|
38
|
+
* its place in a listing — otherwise the id is the whole security of it, and
|
|
39
|
+
* ids travel.
|
|
40
|
+
*
|
|
41
|
+
* Answers "not found" rather than "forbidden", so nobody learns which
|
|
42
|
+
* environments exist by asking.
|
|
43
|
+
*/
|
|
44
|
+
async getForMember(organizationId, userId, id) {
|
|
45
|
+
const teamIds = await this.environments.teamIdsFor(organizationId, userId);
|
|
46
|
+
const environment = await this.environments.findVisibleById(organizationId, id, teamIds);
|
|
47
|
+
if (!environment)
|
|
48
|
+
throw new NotFoundException('Environment not found');
|
|
49
|
+
return environment;
|
|
50
|
+
}
|
|
51
|
+
/** Resolves the slug a caller quotes, within one organization. */
|
|
52
|
+
async getBySlug(organizationId, slug) {
|
|
53
|
+
const environment = await this.environments.findBySlug(organizationId, slug);
|
|
54
|
+
if (!environment)
|
|
55
|
+
throw new NotFoundException('Environment not found');
|
|
56
|
+
return environment;
|
|
57
|
+
}
|
|
58
|
+
async create(organizationId, input) {
|
|
59
|
+
const name = input.name.trim();
|
|
60
|
+
if (!name)
|
|
61
|
+
throw new BadRequestException('name is required');
|
|
62
|
+
const slug = slugify(input.slug ?? name);
|
|
63
|
+
if (!slug) {
|
|
64
|
+
throw new BadRequestException('slug must contain at least one letter or digit');
|
|
65
|
+
}
|
|
66
|
+
if (input.teamId)
|
|
67
|
+
await this.assertTeamBelongs(organizationId, input.teamId);
|
|
68
|
+
return this.environments.create({
|
|
69
|
+
organizationId,
|
|
70
|
+
name,
|
|
71
|
+
slug,
|
|
72
|
+
teamId: input.teamId ?? null,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
async update(organizationId, userId, id, input) {
|
|
76
|
+
await this.getForMember(organizationId, userId, id);
|
|
77
|
+
if (input.teamId)
|
|
78
|
+
await this.assertTeamBelongs(organizationId, input.teamId);
|
|
79
|
+
return this.environments.update(id, {
|
|
80
|
+
name: input.name?.trim(),
|
|
81
|
+
teamId: input.teamId,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
async remove(organizationId, userId, id) {
|
|
85
|
+
await this.getForMember(organizationId, userId, id);
|
|
86
|
+
await this.environments.delete(id);
|
|
87
|
+
}
|
|
88
|
+
/** Called from the organization-creation hook. */
|
|
89
|
+
async seedDefaults(organizationId) {
|
|
90
|
+
await this.environments.createMany(DEFAULTS.map((environment) => ({ ...environment, organizationId })));
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The environment an API key names, re-checked against the key's own
|
|
94
|
+
* organization. `apikey.metadata` is a soft reference: nothing stops a key
|
|
95
|
+
* naming an environment that has since moved or gone.
|
|
96
|
+
*/
|
|
97
|
+
async resolveForOrganization(organizationId, environmentId) {
|
|
98
|
+
if (typeof environmentId !== 'string' || !environmentId) {
|
|
99
|
+
throw new BadRequestException('This API key names no environment. Re-issue it against one.');
|
|
100
|
+
}
|
|
101
|
+
const environment = await this.environments.findById(organizationId, environmentId);
|
|
102
|
+
if (!environment) {
|
|
103
|
+
throw new BadRequestException('This API key names an environment that does not belong to its organization');
|
|
104
|
+
}
|
|
105
|
+
return environment;
|
|
106
|
+
}
|
|
107
|
+
async assertTeamBelongs(organizationId, teamId) {
|
|
108
|
+
if (!(await this.environments.teamExists(organizationId, teamId))) {
|
|
109
|
+
throw new BadRequestException('That team belongs to another organization');
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
EnvironmentsService = __decorate([
|
|
114
|
+
Injectable(),
|
|
115
|
+
__metadata("design:paramtypes", [EnvironmentsRepository])
|
|
116
|
+
], EnvironmentsService);
|
|
117
|
+
export { EnvironmentsService };
|
|
118
|
+
/** Lowercase, digits and single dashes. Empty if the input has no word chars. */
|
|
119
|
+
function slugify(value) {
|
|
120
|
+
return value
|
|
121
|
+
.toLowerCase()
|
|
122
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
123
|
+
.replace(/^-+|-+$/g, '');
|
|
124
|
+
}
|
|
@@ -38,51 +38,33 @@ export type Member = Prisma.MemberModel;
|
|
|
38
38
|
*/
|
|
39
39
|
export type Invitation = Prisma.InvitationModel;
|
|
40
40
|
/**
|
|
41
|
-
* Model
|
|
41
|
+
* Model Team
|
|
42
42
|
*
|
|
43
43
|
*/
|
|
44
|
-
export type
|
|
44
|
+
export type Team = Prisma.TeamModel;
|
|
45
45
|
/**
|
|
46
|
-
* Model
|
|
47
|
-
*
|
|
48
|
-
* upserted at boot from the installed integration packages, and rows whose
|
|
49
|
-
* package is gone are deactivated rather than deleted.
|
|
50
|
-
*/
|
|
51
|
-
export type Provider = Prisma.ProviderModel;
|
|
52
|
-
/**
|
|
53
|
-
* Model Configuration
|
|
54
|
-
* One organization's setup of one provider: which OAuth app, which scopes,
|
|
55
|
-
* which environment. `metadata` holds the integration's own `configFields`.
|
|
56
|
-
*/
|
|
57
|
-
export type Configuration = Prisma.ConfigurationModel;
|
|
58
|
-
/**
|
|
59
|
-
* Model EndUser
|
|
60
|
-
* The organization's own users, identified by the organization's id for them
|
|
61
|
-
* — never by a Kosha auth user.
|
|
46
|
+
* Model TeamMember
|
|
47
|
+
*
|
|
62
48
|
*/
|
|
63
|
-
export type
|
|
49
|
+
export type TeamMember = Prisma.TeamMemberModel;
|
|
64
50
|
/**
|
|
65
|
-
* Model
|
|
66
|
-
*
|
|
67
|
-
* hold several connections against the same configuration (two GitHub
|
|
68
|
-
* accounts), so uniqueness is per provider account, not per end user.
|
|
51
|
+
* Model Apikey
|
|
52
|
+
*
|
|
69
53
|
*/
|
|
70
|
-
export type
|
|
54
|
+
export type Apikey = Prisma.ApikeyModel;
|
|
71
55
|
/**
|
|
72
|
-
* Model
|
|
73
|
-
*
|
|
74
|
-
* Every token column is AES-256-GCM ciphertext.
|
|
56
|
+
* Model Environment
|
|
57
|
+
*
|
|
75
58
|
*/
|
|
76
|
-
export type
|
|
59
|
+
export type Environment = Prisma.EnvironmentModel;
|
|
77
60
|
/**
|
|
78
|
-
* Model
|
|
79
|
-
*
|
|
80
|
-
* connect flow.
|
|
61
|
+
* Model Configuration
|
|
62
|
+
*
|
|
81
63
|
*/
|
|
82
|
-
export type
|
|
64
|
+
export type Configuration = Prisma.ConfigurationModel;
|
|
83
65
|
/**
|
|
84
|
-
* Model
|
|
85
|
-
*
|
|
66
|
+
* Model EgressGrant
|
|
67
|
+
*
|
|
86
68
|
*/
|
|
87
|
-
export type
|
|
69
|
+
export type EgressGrant = Prisma.EgressGrantModel;
|
|
88
70
|
//# sourceMappingURL=browser.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../../src/generated/prisma/browser.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,MAAM,MAAM,sCAAsC,CAAA;AAC9D,OAAO,EAAE,MAAM,EA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ACvC;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,eAAe,CAAA;AAC/C;;;GAGG;AACH,MAAM,MAAM,IAAI,GAAG,MAAM,CAAC,SAAS,CAAA;AACnC;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,eAAe,CAAA;AAC/C;;;GAGG;AACH,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC,WAAW,CAAA;AACvC;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,gBAAgB,CAAA;AACjD;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,kBAAkB,CAAA;AACrD;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,gBAAgB,CAAA"}
|
|
@@ -57,51 +57,33 @@ export type Member = Prisma.MemberModel;
|
|
|
57
57
|
*/
|
|
58
58
|
export type Invitation = Prisma.InvitationModel;
|
|
59
59
|
/**
|
|
60
|
-
* Model
|
|
60
|
+
* Model Team
|
|
61
61
|
*
|
|
62
62
|
*/
|
|
63
|
-
export type
|
|
63
|
+
export type Team = Prisma.TeamModel;
|
|
64
64
|
/**
|
|
65
|
-
* Model
|
|
66
|
-
*
|
|
67
|
-
* upserted at boot from the installed integration packages, and rows whose
|
|
68
|
-
* package is gone are deactivated rather than deleted.
|
|
69
|
-
*/
|
|
70
|
-
export type Provider = Prisma.ProviderModel;
|
|
71
|
-
/**
|
|
72
|
-
* Model Configuration
|
|
73
|
-
* One organization's setup of one provider: which OAuth app, which scopes,
|
|
74
|
-
* which environment. `metadata` holds the integration's own `configFields`.
|
|
75
|
-
*/
|
|
76
|
-
export type Configuration = Prisma.ConfigurationModel;
|
|
77
|
-
/**
|
|
78
|
-
* Model EndUser
|
|
79
|
-
* The organization's own users, identified by the organization's id for them
|
|
80
|
-
* — never by a Kosha auth user.
|
|
65
|
+
* Model TeamMember
|
|
66
|
+
*
|
|
81
67
|
*/
|
|
82
|
-
export type
|
|
68
|
+
export type TeamMember = Prisma.TeamMemberModel;
|
|
83
69
|
/**
|
|
84
|
-
* Model
|
|
85
|
-
*
|
|
86
|
-
* hold several connections against the same configuration (two GitHub
|
|
87
|
-
* accounts), so uniqueness is per provider account, not per end user.
|
|
70
|
+
* Model Apikey
|
|
71
|
+
*
|
|
88
72
|
*/
|
|
89
|
-
export type
|
|
73
|
+
export type Apikey = Prisma.ApikeyModel;
|
|
90
74
|
/**
|
|
91
|
-
* Model
|
|
92
|
-
*
|
|
93
|
-
* Every token column is AES-256-GCM ciphertext.
|
|
75
|
+
* Model Environment
|
|
76
|
+
*
|
|
94
77
|
*/
|
|
95
|
-
export type
|
|
78
|
+
export type Environment = Prisma.EnvironmentModel;
|
|
96
79
|
/**
|
|
97
|
-
* Model
|
|
98
|
-
*
|
|
99
|
-
* connect flow.
|
|
80
|
+
* Model Configuration
|
|
81
|
+
*
|
|
100
82
|
*/
|
|
101
|
-
export type
|
|
83
|
+
export type Configuration = Prisma.ConfigurationModel;
|
|
102
84
|
/**
|
|
103
|
-
* Model
|
|
104
|
-
*
|
|
85
|
+
* Model EgressGrant
|
|
86
|
+
*
|
|
105
87
|
*/
|
|
106
|
-
export type
|
|
88
|
+
export type EgressGrant = Prisma.EgressGrantModel;
|
|
107
89
|
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/generated/prisma/client.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,OAAO,MAAM,+BAA+B,CAAA;AAExD,OAAO,KAAK,MAAM,MAAM,qBAAqB,CAAA;AAC7C,OAAO,KAAK,MAAM,MAAM,+BAA+B,CAAA;AAEvD,OAAO,KAAK,MAAM,MAAM,YAAY,CAAA;AACpC,cAAc,YAAY,CAAA;AAC1B;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,YAAY,gCAAgC,CAAA;AACzD,MAAM,MAAM,YAAY,CAAC,OAAO,SAAS,MA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