@kosha-ai/server 0.1.0 → 0.3.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 +43 -2
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +24 -6
- package/dist/configurations/configurations.controller.d.ts +12 -136
- package/dist/configurations/configurations.controller.d.ts.map +1 -1
- package/dist/configurations/configurations.controller.js +65 -28
- package/dist/configurations/configurations.module.d.ts.map +1 -1
- package/dist/configurations/configurations.module.js +2 -0
- package/dist/configurations/configurations.service.d.ts +32 -200
- package/dist/configurations/configurations.service.d.ts.map +1 -1
- package/dist/configurations/configurations.service.js +98 -170
- package/dist/configurations/dto/create-configuration.dto.d.ts +7 -0
- package/dist/configurations/dto/create-configuration.dto.d.ts.map +1 -0
- package/dist/configurations/dto/create-configuration.dto.js +44 -0
- package/dist/configurations/dto/update-configuration.dto.d.ts +5 -0
- package/dist/configurations/dto/update-configuration.dto.d.ts.map +1 -0
- package/dist/configurations/dto/update-configuration.dto.js +23 -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 +46 -15
- package/dist/connect/connect.module.d.ts.map +1 -1
- package/dist/connect/connect.module.js +4 -3
- 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 +134 -0
- package/dist/connect/connect.service.d.ts +29 -21
- package/dist/connect/connect.service.d.ts.map +1 -1
- package/dist/connect/connect.service.js +157 -168
- 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 +54 -0
- package/dist/connect/dto/create-test-session.dto.d.ts +11 -0
- package/dist/connect/dto/create-test-session.dto.d.ts.map +1 -0
- package/dist/connect/dto/create-test-session.dto.js +41 -0
- package/dist/connections/connections.controller.d.ts +10 -62
- package/dist/connections/connections.controller.d.ts.map +1 -1
- package/dist/connections/connections.controller.js +41 -17
- 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 +31 -0
- package/dist/connections/connections.repository.d.ts.map +1 -0
- package/dist/connections/connections.repository.js +44 -0
- package/dist/connections/connections.service.d.ts +58 -68
- package/dist/connections/connections.service.d.ts.map +1 -1
- package/dist/connections/connections.service.js +137 -55
- package/dist/connections/dto/list-connections.dto.d.ts +7 -0
- package/dist/connections/dto/list-connections.dto.d.ts.map +1 -0
- package/dist/connections/dto/list-connections.dto.js +47 -0
- package/dist/connections/environment-connections.controller.d.ts +27 -0
- package/dist/connections/environment-connections.controller.d.ts.map +1 -0
- package/dist/connections/environment-connections.controller.js +83 -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.map +1 -1
- package/dist/credentials/credentials.module.js +2 -4
- package/dist/credentials/credentials.repository.d.ts +11 -0
- package/dist/credentials/credentials.repository.d.ts.map +1 -0
- package/dist/credentials/credentials.repository.js +28 -0
- package/dist/credentials/credentials.service.d.ts +25 -31
- package/dist/credentials/credentials.service.d.ts.map +1 -1
- package/dist/credentials/credentials.service.js +100 -62
- 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.map +1 -1
- package/dist/egress/egress.listener.js +6 -6
- 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 +65 -0
- package/dist/egress/egress.repository.d.ts.map +1 -0
- package/dist/egress/egress.repository.js +103 -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 +11 -39
- package/dist/generated/prisma/browser.d.ts.map +1 -1
- package/dist/generated/prisma/client.d.ts +11 -39
- package/dist/generated/prisma/client.d.ts.map +1 -1
- package/dist/generated/prisma/commonInputTypes.d.ts +50 -146
- 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 +16 -60
- 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 +166 -583
- package/dist/generated/prisma/internal/prismaNamespace.d.ts.map +1 -1
- package/dist/generated/prisma/internal/prismaNamespace.js +25 -104
- package/dist/generated/prisma/internal/prismaNamespaceBrowser.d.ts +26 -111
- package/dist/generated/prisma/internal/prismaNamespaceBrowser.d.ts.map +1 -1
- package/dist/generated/prisma/internal/prismaNamespaceBrowser.js +25 -104
- 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 +1386 -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 +278 -0
- package/dist/generated/prisma/models/User.d.ts.map +1 -1
- package/dist/generated/prisma/models.d.ts +3 -7
- package/dist/generated/prisma/models.d.ts.map +1 -1
- package/dist/index.d.ts +14 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -2
- package/dist/integrations/integrations.controller.d.ts +4 -1
- package/dist/integrations/integrations.controller.d.ts.map +1 -1
- package/dist/integrations/integrations.controller.js +1 -0
- package/dist/integrations/integrations.module.js +3 -3
- package/dist/integrations/provider-store.d.ts +104 -0
- package/dist/integrations/provider-store.d.ts.map +1 -0
- package/dist/integrations/provider-store.js +234 -0
- package/dist/kosha.module.d.ts.map +1 -1
- package/dist/kosha.module.js +9 -3
- package/dist/proxy/proxy.controller.d.ts +12 -3
- package/dist/proxy/proxy.controller.d.ts.map +1 -1
- package/dist/proxy/proxy.controller.js +31 -10
- package/dist/proxy/proxy.module.d.ts.map +1 -1
- package/dist/proxy/proxy.module.js +4 -2
- package/dist/proxy/proxy.repository.d.ts +21 -0
- package/dist/proxy/proxy.repository.d.ts.map +1 -0
- package/dist/proxy/proxy.repository.js +37 -0
- package/dist/proxy/proxy.service.d.ts +15 -5
- package/dist/proxy/proxy.service.d.ts.map +1 -1
- package/dist/proxy/proxy.service.js +63 -26
- package/package.json +7 -4
- package/prisma/migrations/{20260908000000_init → 20261008090000_init}/migration.sql +99 -16
- package/prisma/schema.prisma +56 -202
- package/dist/generated/prisma/models/Configuration.d.ts +0 -2018
- package/dist/generated/prisma/models/Configuration.d.ts.map +0 -1
- 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/ConnectionCredential.js +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/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/{Configuration.js → Environment.js} +0 -0
- /package/dist/generated/prisma/models/{ConnectSession.js → Team.js} +0 -0
- /package/dist/generated/prisma/models/{Connection.js → TeamMember.js} +0 -0
|
@@ -2,6 +2,7 @@ import { __decorate, __metadata, __param } from "tslib";
|
|
|
2
2
|
import { Inject, Injectable } from '@nestjs/common';
|
|
3
3
|
import { createCipheriv, createDecipheriv, randomBytes } from 'node:crypto';
|
|
4
4
|
import { KOSHA_CONFIG } from '../config/tokens.js';
|
|
5
|
+
import { parseEnvelope, } from './credential-envelope.js';
|
|
5
6
|
const ALGORITHM = 'aes-256-gcm';
|
|
6
7
|
const IV_LENGTH = 12;
|
|
7
8
|
const KEY_LENGTH = 32;
|
|
@@ -63,6 +64,17 @@ let CryptoService = class CryptoService {
|
|
|
63
64
|
decipher.final(),
|
|
64
65
|
]).toString('utf8');
|
|
65
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* A credential goes to rest as an encrypted envelope carrying its own type
|
|
69
|
+
* and version, so the column it lives in needs to know neither.
|
|
70
|
+
*/
|
|
71
|
+
sealEnvelope(envelope) {
|
|
72
|
+
return this.encrypt(JSON.stringify(envelope));
|
|
73
|
+
}
|
|
74
|
+
/** Throws rather than returning a half-understood credential. */
|
|
75
|
+
openEnvelope(payload) {
|
|
76
|
+
return parseEnvelope(this.decrypt(payload));
|
|
77
|
+
}
|
|
66
78
|
requireKey() {
|
|
67
79
|
if (!this.key)
|
|
68
80
|
throw new MissingEncryptionKeyError();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mint-grant.dto.d.ts","sourceRoot":"","sources":["../../../src/egress/dto/mint-grant.dto.ts"],"names":[],"mappings":"AAUA,qBAAa,YAAY;IASvB,cAAc,EAAG,MAAM,CAAC;IAUxB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IAOxB,SAAS,EAAG,MAAM,CAAC;IAMnB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
|
3
|
+
import { IsArray, IsDateString, IsOptional, IsString, MaxLength, MinLength, } from 'class-validator';
|
|
4
|
+
export class MintGrantDto {
|
|
5
|
+
externalUserId;
|
|
6
|
+
providerKeys;
|
|
7
|
+
expiresAt;
|
|
8
|
+
label;
|
|
9
|
+
}
|
|
10
|
+
__decorate([
|
|
11
|
+
ApiProperty({
|
|
12
|
+
example: 'user_9',
|
|
13
|
+
description: 'The app’s own id for the person whose credentials are borrowed.',
|
|
14
|
+
}),
|
|
15
|
+
IsString(),
|
|
16
|
+
MinLength(1),
|
|
17
|
+
MaxLength(255),
|
|
18
|
+
__metadata("design:type", String)
|
|
19
|
+
], MintGrantDto.prototype, "externalUserId", void 0);
|
|
20
|
+
__decorate([
|
|
21
|
+
ApiPropertyOptional({
|
|
22
|
+
example: ['github'],
|
|
23
|
+
description: 'Narrows the grant to these integrations. Omit for every provider this person has connected.',
|
|
24
|
+
}),
|
|
25
|
+
IsOptional(),
|
|
26
|
+
IsArray(),
|
|
27
|
+
IsString({ each: true }),
|
|
28
|
+
__metadata("design:type", Array)
|
|
29
|
+
], MintGrantDto.prototype, "providerKeys", void 0);
|
|
30
|
+
__decorate([
|
|
31
|
+
ApiProperty({
|
|
32
|
+
example: '2026-10-01T12:00:00.000Z',
|
|
33
|
+
description: 'When the grant dies. At most 25 hours away.',
|
|
34
|
+
}),
|
|
35
|
+
IsDateString(),
|
|
36
|
+
__metadata("design:type", String)
|
|
37
|
+
], MintGrantDto.prototype, "expiresAt", void 0);
|
|
38
|
+
__decorate([
|
|
39
|
+
ApiPropertyOptional({ description: 'For reading a grant list later.' }),
|
|
40
|
+
IsOptional(),
|
|
41
|
+
IsString(),
|
|
42
|
+
MaxLength(200),
|
|
43
|
+
__metadata("design:type", String)
|
|
44
|
+
], MintGrantDto.prototype, "label", void 0);
|
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import { type ApiKeyRequest } from '../auth/api-key.guard.js';
|
|
2
|
+
import { MintGrantDto } from './dto/mint-grant.dto.js';
|
|
2
3
|
import { GrantsService } from './grants.service.js';
|
|
3
|
-
export interface MintGrantBody {
|
|
4
|
-
endUserExternalId?: string;
|
|
5
|
-
/** Narrows the grant. Omit for every provider this end user has connected. */
|
|
6
|
-
providerKeys?: string[];
|
|
7
|
-
expiresAt?: string;
|
|
8
|
-
label?: string;
|
|
9
|
-
}
|
|
10
4
|
/**
|
|
11
5
|
* Minting and revoking egress grants. `ApiKeyGuard` rather than `OrgAuthGuard`
|
|
12
6
|
* because handing a sandbox an identity is an errand for an app's backend, not
|
|
@@ -15,7 +9,7 @@ export interface MintGrantBody {
|
|
|
15
9
|
export declare class EgressController {
|
|
16
10
|
private readonly grants;
|
|
17
11
|
constructor(grants: GrantsService);
|
|
18
|
-
mint(request: ApiKeyRequest, body:
|
|
12
|
+
mint(request: ApiKeyRequest, body: MintGrantDto): Promise<import("./grants.service.js").MintedGrant>;
|
|
19
13
|
revoke(request: ApiKeyRequest, id: string): Promise<{
|
|
20
14
|
grantId: string;
|
|
21
15
|
revoked: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"egress.controller.d.ts","sourceRoot":"","sources":["../../src/egress/egress.controller.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"egress.controller.d.ts","sourceRoot":"","sources":["../../src/egress/egress.controller.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAe,KAAK,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD;;;;GAIG;AACH,qBAKa,gBAAgB;IACf,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,aAAa;IAe5C,IAAI,CAAQ,OAAO,EAAE,aAAa,EAAU,IAAI,EAAE,YAAY;IAoB9D,MAAM,CAAQ,OAAO,EAAE,aAAa,EAAe,EAAE,EAAE,MAAM;;;;CAIpE"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { __decorate, __metadata, __param } from "tslib";
|
|
2
2
|
import { BadRequestException, Body, Controller, Delete, HttpCode, Param, Post, Req, UseGuards, } from '@nestjs/common';
|
|
3
|
+
import { ApiCreatedResponse, ApiNotFoundResponse, ApiOperation, ApiSecurity, ApiTags, } from '@nestjs/swagger';
|
|
3
4
|
import { AllowAnonymous } from '@thallesp/nestjs-better-auth';
|
|
4
5
|
import { ApiKeyGuard } from '../auth/api-key.guard.js';
|
|
6
|
+
import { MintGrantDto } from './dto/mint-grant.dto.js';
|
|
5
7
|
import { GrantsService } from './grants.service.js';
|
|
6
8
|
/**
|
|
7
9
|
* Minting and revoking egress grants. `ApiKeyGuard` rather than `OrgAuthGuard`
|
|
@@ -14,15 +16,12 @@ let EgressController = class EgressController {
|
|
|
14
16
|
this.grants = grants;
|
|
15
17
|
}
|
|
16
18
|
async mint(request, body) {
|
|
17
|
-
if (!body?.expiresAt) {
|
|
18
|
-
throw new BadRequestException('expiresAt is required');
|
|
19
|
-
}
|
|
20
19
|
const expiresAt = new Date(body.expiresAt);
|
|
21
20
|
if (Number.isNaN(expiresAt.getTime())) {
|
|
22
21
|
throw new BadRequestException('expiresAt must be an ISO date');
|
|
23
22
|
}
|
|
24
|
-
return this.grants.mint(request.organizationId, {
|
|
25
|
-
|
|
23
|
+
return this.grants.mint(request.organizationId, environmentOf(request), {
|
|
24
|
+
externalUserId: body.externalUserId,
|
|
26
25
|
expiresAt,
|
|
27
26
|
label: body.label,
|
|
28
27
|
providerKeys: body.providerKeys,
|
|
@@ -36,14 +35,28 @@ let EgressController = class EgressController {
|
|
|
36
35
|
__decorate([
|
|
37
36
|
Post('grants'),
|
|
38
37
|
HttpCode(201),
|
|
38
|
+
ApiOperation({
|
|
39
|
+
summary: 'Mint a grant a sandbox can authenticate with',
|
|
40
|
+
description: 'Returns a token and a CA certificate, once. The sandbox trusts that CA and proxies through Kosha; the credentials themselves never leave the server.',
|
|
41
|
+
}),
|
|
42
|
+
ApiCreatedResponse({
|
|
43
|
+
description: 'The grant, its token, and the providers it resolved to.',
|
|
44
|
+
}),
|
|
45
|
+
ApiNotFoundResponse({
|
|
46
|
+
description: 'That person has connected nothing in this environment.',
|
|
47
|
+
}),
|
|
39
48
|
__param(0, Req()),
|
|
40
49
|
__param(1, Body()),
|
|
41
50
|
__metadata("design:type", Function),
|
|
42
|
-
__metadata("design:paramtypes", [Object,
|
|
51
|
+
__metadata("design:paramtypes", [Object, MintGrantDto]),
|
|
43
52
|
__metadata("design:returntype", Promise)
|
|
44
53
|
], EgressController.prototype, "mint", null);
|
|
45
54
|
__decorate([
|
|
46
55
|
Delete('grants/:id'),
|
|
56
|
+
ApiOperation({
|
|
57
|
+
summary: 'Revoke a grant',
|
|
58
|
+
description: 'Takes up to 30 seconds to bite: the broker caches token lookups, since a single git clone makes dozens of them.',
|
|
59
|
+
}),
|
|
47
60
|
__param(0, Req()),
|
|
48
61
|
__param(1, Param('id')),
|
|
49
62
|
__metadata("design:type", Function),
|
|
@@ -51,9 +64,17 @@ __decorate([
|
|
|
51
64
|
__metadata("design:returntype", Promise)
|
|
52
65
|
], EgressController.prototype, "revoke", null);
|
|
53
66
|
EgressController = __decorate([
|
|
67
|
+
ApiTags('egress'),
|
|
68
|
+
ApiSecurity('x-api-key'),
|
|
54
69
|
Controller('egress'),
|
|
55
70
|
AllowAnonymous(),
|
|
56
71
|
UseGuards(ApiKeyGuard),
|
|
57
72
|
__metadata("design:paramtypes", [GrantsService])
|
|
58
73
|
], EgressController);
|
|
59
74
|
export { EgressController };
|
|
75
|
+
function environmentOf(request) {
|
|
76
|
+
if (!request.environmentId) {
|
|
77
|
+
throw new BadRequestException('This route needs an API key, which is what names the environment');
|
|
78
|
+
}
|
|
79
|
+
return request.environmentId;
|
|
80
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"egress.listener.d.ts","sourceRoot":"","sources":["../../src/egress/egress.listener.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC3B,MAAM,gBAAgB,CAAC;AAWxB,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAc,MAAM,qBAAqB,CAAC;AAChE,OAAO,EACL,gBAAgB,EAEjB,MAAM,yBAAyB,CAAC;AAgGjC,qBACa,cACX,YAAW,sBAAsB,EAAE,qBAAqB;IAahC,OAAO,CAAC,QAAQ,CAAC,MAAM;IAC7C,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,EAAE;IACnB,OAAO,CAAC,QAAQ,CAAC,WAAW;IAf9B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAmC;IAC1D,6EAA6E;IAC7E,OAAO,CAAC,QAAQ,CAAC,aAAa,CAG3B;IACH,OAAO,CAAC,MAAM,CAAC,CAAc;IAC7B,OAAO,CAAC,UAAU,CAAC,CAAc;IACjC,OAAO,CAAC,UAAU,CAAC,CAAiB;gBAGK,M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jC,OAAO,CAAC,UAAU,CAAC,CAAiB;gBAGK,MAAM,EAAE,mBAAmB,EACjD,MAAM,EAAE,aAAa,EACrB,SAAS,EAAE,gBAAgB,EAC3B,EAAE,EAAE,SAAS,EACb,WAAW,EAAE,kBAAkB;IAG5C,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC;IA0B7C,qBAAqB,IAAI,IAAI;IAM7B,OAAO,CAAC,iBAAiB;YA6BX,aAAa;IAwD3B,8EAA8E;IAC9E,OAAO,CAAC,MAAM;IAuBd,iFAAiF;IACjF,OAAO,CAAC,SAAS;IA4BjB;;;;;OAKG;IACH,OAAO,CAAC,gBAAgB;YAYV,OAAO;CA8FtB"}
|
|
@@ -174,10 +174,10 @@ let EgressListener = EgressListener_1 = class EgressListener {
|
|
|
174
174
|
// A rule this grant cannot use counts as no rule: the request still gets
|
|
175
175
|
// there, unauthenticated. Failing instead would turn "you have not
|
|
176
176
|
// connected Slack" into "the network is broken".
|
|
177
|
-
const
|
|
177
|
+
const borrowable = rule === undefined
|
|
178
178
|
? null
|
|
179
|
-
: await this.grants.
|
|
180
|
-
if (rule === undefined ||
|
|
179
|
+
: await this.grants.credentialFor(grant, rule.providerKey);
|
|
180
|
+
if (rule === undefined || borrowable === null) {
|
|
181
181
|
this.logger.debug(`Tunnelling ${authority.host}:${authority.port} for grant ${grant.id}`);
|
|
182
182
|
this.tunnel(clientSocket, head, authority, grant.id);
|
|
183
183
|
return;
|
|
@@ -248,11 +248,11 @@ let EgressListener = EgressListener_1 = class EgressListener {
|
|
|
248
248
|
const { grant, host, port, rule } = context;
|
|
249
249
|
let injected;
|
|
250
250
|
try {
|
|
251
|
-
const
|
|
252
|
-
if (
|
|
251
|
+
const borrowable = await this.grants.credentialFor(grant, rule.providerKey);
|
|
252
|
+
if (borrowable === null) {
|
|
253
253
|
throw new Error(`This grant can no longer use ${rule.providerKey}. The connection may have been revoked.`);
|
|
254
254
|
}
|
|
255
|
-
const credential = await this.credentials.
|
|
255
|
+
const credential = await this.credentials.resolve(borrowable.account, borrowable.integration, borrowable.configuration);
|
|
256
256
|
injected = rule.headers({
|
|
257
257
|
accessToken: credential.accessToken,
|
|
258
258
|
tokenType: credential.tokenType,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"egress.module.d.ts","sourceRoot":"","sources":["../../src/egress/egress.module.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"egress.module.d.ts","sourceRoot":"","sources":["../../src/egress/egress.module.ts"],"names":[],"mappings":"AAUA;;;GAGG;AACH,qBAYa,YAAY;CAAG"}
|
|
@@ -2,6 +2,8 @@ import { __decorate } from "tslib";
|
|
|
2
2
|
import { Module } from '@nestjs/common';
|
|
3
3
|
import { CaService } from './ca.service.js';
|
|
4
4
|
import { CredentialsModule } from '../credentials/credentials.module.js';
|
|
5
|
+
import { EgressRepository } from './egress.repository.js';
|
|
6
|
+
import { EnvironmentsModule } from '../environments/environments.module.js';
|
|
5
7
|
import { EgressController } from './egress.controller.js';
|
|
6
8
|
import { EgressListener } from './egress.listener.js';
|
|
7
9
|
import { GrantsService } from './grants.service.js';
|
|
@@ -14,9 +16,15 @@ let EgressModule = class EgressModule {
|
|
|
14
16
|
};
|
|
15
17
|
EgressModule = __decorate([
|
|
16
18
|
Module({
|
|
17
|
-
imports: [CredentialsModule],
|
|
19
|
+
imports: [CredentialsModule, EnvironmentsModule],
|
|
18
20
|
controllers: [EgressController],
|
|
19
|
-
providers: [
|
|
21
|
+
providers: [
|
|
22
|
+
CaService,
|
|
23
|
+
EgressListener,
|
|
24
|
+
EgressRepository,
|
|
25
|
+
GrantsService,
|
|
26
|
+
HostRulesService,
|
|
27
|
+
],
|
|
20
28
|
exports: [GrantsService],
|
|
21
29
|
})
|
|
22
30
|
], EgressModule);
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { KoshaIntegration } from '@kosha-ai/integration-sdk';
|
|
2
|
+
import type { Account } from '../generated/prisma/client.js';
|
|
3
|
+
import { IntegrationRegistry } from '../integrations/integration.registry.js';
|
|
4
|
+
import { ProviderStore, type ProviderConfiguration } from '../integrations/provider-store.js';
|
|
5
|
+
import { PrismaService } from '../prisma/prisma.service.js';
|
|
6
|
+
export interface GrantRow {
|
|
7
|
+
organizationId: string;
|
|
8
|
+
userId: string;
|
|
9
|
+
tokenHash: string;
|
|
10
|
+
providerKeys: string[];
|
|
11
|
+
caPem: string;
|
|
12
|
+
caKey: string;
|
|
13
|
+
label?: string;
|
|
14
|
+
expiresAt: Date;
|
|
15
|
+
}
|
|
16
|
+
/** A credential the broker may borrow, with what it takes to refresh it. */
|
|
17
|
+
export interface BorrowableCredential {
|
|
18
|
+
account: Account;
|
|
19
|
+
configuration: ProviderConfiguration;
|
|
20
|
+
integration: KoshaIntegration;
|
|
21
|
+
}
|
|
22
|
+
export declare class EgressRepository {
|
|
23
|
+
private readonly prisma;
|
|
24
|
+
private readonly store;
|
|
25
|
+
private readonly registry;
|
|
26
|
+
constructor(prisma: PrismaService, store: ProviderStore, registry: IntegrationRegistry);
|
|
27
|
+
/**
|
|
28
|
+
* The person a grant is minted for. A `user` row exists per environment, so
|
|
29
|
+
* finding one by its derived address settles the environment too — which is
|
|
30
|
+
* why a grant needs no environment column of its own.
|
|
31
|
+
*/
|
|
32
|
+
findEndUser(environmentSlug: string, externalUserId: string): Promise<{
|
|
33
|
+
id: string;
|
|
34
|
+
} | null>;
|
|
35
|
+
createGrant(row: GrantRow): Promise<{
|
|
36
|
+
id: string;
|
|
37
|
+
expiresAt: Date;
|
|
38
|
+
}>;
|
|
39
|
+
revokeGrant(organizationId: string, grantId: string): Promise<number>;
|
|
40
|
+
findLiveGrant(tokenHash: string): import("../generated/prisma/models.js").Prisma__EgressGrantClient<{
|
|
41
|
+
id: string;
|
|
42
|
+
userId: string;
|
|
43
|
+
organizationId: string;
|
|
44
|
+
expiresAt: Date;
|
|
45
|
+
providerKeys: string[];
|
|
46
|
+
caPem: string;
|
|
47
|
+
caKey: string;
|
|
48
|
+
} | null, null, import("@prisma/client/runtime/client").DefaultArgs, {
|
|
49
|
+
omit: import("../generated/prisma/internal/prismaNamespace.js").GlobalOmitConfig | undefined;
|
|
50
|
+
}>;
|
|
51
|
+
deleteExpiredBefore(cutoff: Date): Promise<number>;
|
|
52
|
+
/**
|
|
53
|
+
* A credential this person holds for one integration. Scoped by the grant's
|
|
54
|
+
* own user, never by anything in a request — that is what stops a grant
|
|
55
|
+
* reaching another tenant's credential.
|
|
56
|
+
*
|
|
57
|
+
* Starts from the provider's connection row, which an operator's password
|
|
58
|
+
* never has, so a login can never be lent. A person connected through two
|
|
59
|
+
* configurations lends the newest.
|
|
60
|
+
*/
|
|
61
|
+
findCredentialFor(userId: string, integrationKey: string): Promise<BorrowableCredential | null>;
|
|
62
|
+
/** Which of these integrations this person has actually connected. */
|
|
63
|
+
connectedIntegrationKeys(userId: string, integrationKeys: string[]): Promise<string[]>;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=egress.repository.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"egress.repository.d.ts","sourceRoot":"","sources":["../../src/egress/egress.repository.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAElE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAC9E,OAAO,EACL,aAAa,EACb,KAAK,qBAAqB,EAC3B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAE5D,MAAM,WAAW,QAAQ;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd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
|
+
import { Injectable } from '@nestjs/common';
|
|
3
|
+
import { randomUUID } from 'node:crypto';
|
|
4
|
+
import { derivedEmail } from '../connect/connect.repository.js';
|
|
5
|
+
import { IntegrationRegistry } from '../integrations/integration.registry.js';
|
|
6
|
+
import { ProviderStore, } from '../integrations/provider-store.js';
|
|
7
|
+
import { PrismaService } from '../prisma/prisma.service.js';
|
|
8
|
+
let EgressRepository = class EgressRepository {
|
|
9
|
+
prisma;
|
|
10
|
+
store;
|
|
11
|
+
registry;
|
|
12
|
+
constructor(prisma, store, registry) {
|
|
13
|
+
this.prisma = prisma;
|
|
14
|
+
this.store = store;
|
|
15
|
+
this.registry = registry;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The person a grant is minted for. A `user` row exists per environment, so
|
|
19
|
+
* finding one by its derived address settles the environment too — which is
|
|
20
|
+
* why a grant needs no environment column of its own.
|
|
21
|
+
*/
|
|
22
|
+
async findEndUser(environmentSlug, externalUserId) {
|
|
23
|
+
return this.prisma.user.findUnique({
|
|
24
|
+
where: { email: derivedEmail(environmentSlug, externalUserId) },
|
|
25
|
+
select: { id: true },
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
createGrant(row) {
|
|
29
|
+
return this.prisma.egressGrant.create({
|
|
30
|
+
data: { id: randomUUID(), ...row },
|
|
31
|
+
select: { id: true, expiresAt: true },
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
async revokeGrant(organizationId, grantId) {
|
|
35
|
+
const { count } = await this.prisma.egressGrant.updateMany({
|
|
36
|
+
where: { id: grantId, organizationId, revokedAt: null },
|
|
37
|
+
data: { revokedAt: new Date() },
|
|
38
|
+
});
|
|
39
|
+
return count;
|
|
40
|
+
}
|
|
41
|
+
findLiveGrant(tokenHash) {
|
|
42
|
+
return this.prisma.egressGrant.findFirst({
|
|
43
|
+
where: { tokenHash, revokedAt: null, expiresAt: { gt: new Date() } },
|
|
44
|
+
select: {
|
|
45
|
+
id: true,
|
|
46
|
+
organizationId: true,
|
|
47
|
+
userId: true,
|
|
48
|
+
providerKeys: true,
|
|
49
|
+
caPem: true,
|
|
50
|
+
caKey: true,
|
|
51
|
+
expiresAt: true,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
async deleteExpiredBefore(cutoff) {
|
|
56
|
+
const { count } = await this.prisma.egressGrant.deleteMany({
|
|
57
|
+
where: { expiresAt: { lt: cutoff } },
|
|
58
|
+
});
|
|
59
|
+
return count;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* A credential this person holds for one integration. Scoped by the grant's
|
|
63
|
+
* own user, never by anything in a request — that is what stops a grant
|
|
64
|
+
* reaching another tenant's credential.
|
|
65
|
+
*
|
|
66
|
+
* Starts from the provider's connection row, which an operator's password
|
|
67
|
+
* never has, so a login can never be lent. A person connected through two
|
|
68
|
+
* configurations lends the newest.
|
|
69
|
+
*/
|
|
70
|
+
async findCredentialFor(userId, integrationKey) {
|
|
71
|
+
const integration = this.registry.find(integrationKey);
|
|
72
|
+
if (!integration)
|
|
73
|
+
return null;
|
|
74
|
+
const [connection] = await this.store.listConnectionsForUser(integration, userId);
|
|
75
|
+
if (!connection)
|
|
76
|
+
return null;
|
|
77
|
+
const [account, configuration] = await Promise.all([
|
|
78
|
+
this.prisma.account.findUnique({ where: { id: connection.accountId } }),
|
|
79
|
+
this.store.findConfigurationWithCredentials(integration, connection.configurationId),
|
|
80
|
+
]);
|
|
81
|
+
if (!account || !configuration)
|
|
82
|
+
return null;
|
|
83
|
+
return { account, configuration, integration };
|
|
84
|
+
}
|
|
85
|
+
/** Which of these integrations this person has actually connected. */
|
|
86
|
+
async connectedIntegrationKeys(userId, integrationKeys) {
|
|
87
|
+
const connected = await Promise.all(integrationKeys.map(async (key) => {
|
|
88
|
+
const integration = this.registry.find(key);
|
|
89
|
+
if (!integration)
|
|
90
|
+
return null;
|
|
91
|
+
const connections = await this.store.listConnectionsForUser(integration, userId);
|
|
92
|
+
return connections.length > 0 ? key : null;
|
|
93
|
+
}));
|
|
94
|
+
return connected.filter((key) => key !== null);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
EgressRepository = __decorate([
|
|
98
|
+
Injectable(),
|
|
99
|
+
__metadata("design:paramtypes", [PrismaService,
|
|
100
|
+
ProviderStore,
|
|
101
|
+
IntegrationRegistry])
|
|
102
|
+
], EgressRepository);
|
|
103
|
+
export { EgressRepository };
|
|
@@ -1,26 +1,32 @@
|
|
|
1
|
-
import { CaService } from './ca.service.js';
|
|
2
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';
|
|
3
5
|
import { HostRulesService } from './host-rules.service.js';
|
|
4
|
-
import { PrismaService } from '../prisma/prisma.service.js';
|
|
5
6
|
/**
|
|
6
7
|
* Grants: what a sandbox may authenticate as, and for how long.
|
|
7
8
|
*
|
|
8
|
-
* A grant names
|
|
9
|
-
*
|
|
10
|
-
*
|
|
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.
|
|
11
12
|
*/
|
|
12
13
|
export interface Grant {
|
|
13
14
|
readonly id: string;
|
|
14
15
|
readonly organizationId: string;
|
|
15
|
-
|
|
16
|
-
|
|
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. */
|
|
17
23
|
readonly providerKeys: readonly string[];
|
|
18
24
|
readonly caPem: string;
|
|
19
25
|
readonly caKeyPem: string;
|
|
20
26
|
readonly expiresAt: Date;
|
|
21
27
|
}
|
|
22
28
|
export interface MintGrantInput {
|
|
23
|
-
readonly
|
|
29
|
+
readonly externalUserId: string;
|
|
24
30
|
readonly providerKeys?: readonly string[];
|
|
25
31
|
readonly expiresAt: Date;
|
|
26
32
|
readonly label?: string;
|
|
@@ -35,20 +41,21 @@ export interface MintedGrant {
|
|
|
35
41
|
readonly providers: string[];
|
|
36
42
|
}
|
|
37
43
|
export declare class GrantsService {
|
|
38
|
-
private readonly
|
|
44
|
+
private readonly grants;
|
|
39
45
|
private readonly crypto;
|
|
40
46
|
private readonly ca;
|
|
41
47
|
private readonly hostRules;
|
|
48
|
+
private readonly environments;
|
|
42
49
|
private readonly logger;
|
|
43
50
|
private readonly cache;
|
|
44
|
-
constructor(
|
|
51
|
+
constructor(grants: EgressRepository, crypto: CryptoService, ca: CaService, hostRules: HostRulesService, environments: EnvironmentsService);
|
|
45
52
|
/**
|
|
46
53
|
* Unsalted on purpose: the token is 32 random bytes, so there is nothing to
|
|
47
54
|
* brute-force and a per-row salt would only stop the lookup being an index
|
|
48
55
|
* scan.
|
|
49
56
|
*/
|
|
50
57
|
private hashToken;
|
|
51
|
-
mint(organizationId: string, input: MintGrantInput): Promise<MintedGrant>;
|
|
58
|
+
mint(organizationId: string, environmentId: string, input: MintGrantInput): Promise<MintedGrant>;
|
|
52
59
|
revoke(organizationId: string, grantId: string): Promise<boolean>;
|
|
53
60
|
/**
|
|
54
61
|
* The grant a token names, or null for unknown, expired and revoked alike --
|
|
@@ -56,77 +63,15 @@ export declare class GrantsService {
|
|
|
56
63
|
*/
|
|
57
64
|
resolve(token: string): Promise<Grant | null>;
|
|
58
65
|
/**
|
|
59
|
-
* The
|
|
60
|
-
*
|
|
61
|
-
*
|
|
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.
|
|
62
69
|
*/
|
|
63
|
-
|
|
64
|
-
configuration: {
|
|
65
|
-
provider: {
|
|
66
|
-
name: string;
|
|
67
|
-
key: string;
|
|
68
|
-
id: string;
|
|
69
|
-
createdAt: Date;
|
|
70
|
-
updatedAt: Date;
|
|
71
|
-
authType: import("../generated/prisma/enums.js").AuthType;
|
|
72
|
-
authorizationUrl: string | null;
|
|
73
|
-
tokenUrl: string | null;
|
|
74
|
-
revokeUrl: string | null;
|
|
75
|
-
apiBaseUrl: string | null;
|
|
76
|
-
scopesAvailable: string[];
|
|
77
|
-
docsUrl: string | null;
|
|
78
|
-
logoUrl: string | null;
|
|
79
|
-
isActive: boolean;
|
|
80
|
-
};
|
|
81
|
-
} & {
|
|
82
|
-
name: string;
|
|
83
|
-
id: string;
|
|
84
|
-
createdAt: Date;
|
|
85
|
-
updatedAt: Date;
|
|
86
|
-
metadata: import("@prisma/client/runtime/client").JsonValue | null;
|
|
87
|
-
scopes: string[];
|
|
88
|
-
slug: string;
|
|
89
|
-
organizationId: string;
|
|
90
|
-
providerId: string;
|
|
91
|
-
environment: import("../generated/prisma/enums.js").ConnectionEnvironment;
|
|
92
|
-
authType: import("../generated/prisma/enums.js").AuthType;
|
|
93
|
-
clientId: string | null;
|
|
94
|
-
encryptedClientSecret: string | null;
|
|
95
|
-
redirectUri: string | null;
|
|
96
|
-
isEnabled: boolean;
|
|
97
|
-
};
|
|
98
|
-
credential: {
|
|
99
|
-
id: string;
|
|
100
|
-
createdAt: Date;
|
|
101
|
-
updatedAt: Date;
|
|
102
|
-
refreshToken: string | null;
|
|
103
|
-
expiresAt: Date | null;
|
|
104
|
-
idToken: string | null;
|
|
105
|
-
accessToken: string;
|
|
106
|
-
connectionId: string;
|
|
107
|
-
tokenType: string | null;
|
|
108
|
-
refreshTokenExpiresAt: Date | null;
|
|
109
|
-
} | null;
|
|
110
|
-
} & {
|
|
111
|
-
id: string;
|
|
112
|
-
createdAt: Date;
|
|
113
|
-
updatedAt: Date;
|
|
114
|
-
status: import("../generated/prisma/enums.js").ConnectionStatus;
|
|
115
|
-
metadata: import("@prisma/client/runtime/client").JsonValue | null;
|
|
116
|
-
scopes: string[];
|
|
117
|
-
organizationId: string;
|
|
118
|
-
endUserId: string;
|
|
119
|
-
configurationId: string;
|
|
120
|
-
label: string | null;
|
|
121
|
-
externalAccountId: string | null;
|
|
122
|
-
lastSyncedAt: Date | null;
|
|
123
|
-
lastUsedAt: Date | null;
|
|
124
|
-
errorMessage: string | null;
|
|
125
|
-
}) | null>;
|
|
70
|
+
credentialFor(grant: Grant, integrationKey: string): Promise<BorrowableCredential | null>;
|
|
126
71
|
/** Deletes grants that expired a while ago. Housekeeping, nothing depends on it. */
|
|
127
72
|
pruneExpired(): Promise<number>;
|
|
128
73
|
private forget;
|
|
129
|
-
/** Which brokered providers this
|
|
74
|
+
/** Which brokered providers this person has actually connected. */
|
|
130
75
|
private providersFor;
|
|
131
76
|
}
|
|
132
77
|
//# sourceMappingURL=grants.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grants.service.d.ts","sourceRoot":"","sources":["../../src/egress/grants.service.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,
|
|
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;IA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