@kosha-ai/server 0.0.6 → 1.0.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.
Files changed (210) hide show
  1. package/dist/auth/api-key.guard.d.ts +7 -2
  2. package/dist/auth/api-key.guard.d.ts.map +1 -1
  3. package/dist/auth/api-key.guard.js +28 -8
  4. package/dist/auth/auth.factory.d.ts +15 -1
  5. package/dist/auth/auth.factory.d.ts.map +1 -1
  6. package/dist/auth/auth.factory.js +48 -2
  7. package/dist/bootstrap.d.ts.map +1 -1
  8. package/dist/bootstrap.js +24 -6
  9. package/dist/config/kosha-config.d.ts +21 -0
  10. package/dist/config/kosha-config.d.ts.map +1 -1
  11. package/dist/config/kosha-config.js +31 -2
  12. package/dist/configurations/configurations.controller.d.ts +11 -136
  13. package/dist/configurations/configurations.controller.d.ts.map +1 -1
  14. package/dist/configurations/configurations.controller.js +58 -25
  15. package/dist/configurations/configurations.module.d.ts.map +1 -1
  16. package/dist/configurations/configurations.module.js +4 -1
  17. package/dist/configurations/configurations.repository.d.ts +43 -0
  18. package/dist/configurations/configurations.repository.d.ts.map +1 -0
  19. package/dist/configurations/configurations.repository.js +76 -0
  20. package/dist/configurations/configurations.service.d.ts +38 -194
  21. package/dist/configurations/configurations.service.d.ts.map +1 -1
  22. package/dist/configurations/configurations.service.js +118 -110
  23. package/dist/configurations/dto/create-configuration.dto.d.ts +8 -0
  24. package/dist/configurations/dto/create-configuration.dto.d.ts.map +1 -0
  25. package/dist/configurations/dto/create-configuration.dto.js +54 -0
  26. package/dist/configurations/dto/update-configuration.dto.d.ts +7 -0
  27. package/dist/configurations/dto/update-configuration.dto.d.ts.map +1 -0
  28. package/dist/configurations/dto/update-configuration.dto.js +39 -0
  29. package/dist/connect/connect.controller.d.ts +6 -8
  30. package/dist/connect/connect.controller.d.ts.map +1 -1
  31. package/dist/connect/connect.controller.js +45 -15
  32. package/dist/connect/connect.module.d.ts.map +1 -1
  33. package/dist/connect/connect.module.js +4 -2
  34. package/dist/connect/connect.repository.d.ts +78 -0
  35. package/dist/connect/connect.repository.d.ts.map +1 -0
  36. package/dist/connect/connect.repository.js +146 -0
  37. package/dist/connect/connect.service.d.ts +28 -19
  38. package/dist/connect/connect.service.d.ts.map +1 -1
  39. package/dist/connect/connect.service.js +149 -163
  40. package/dist/connect/dto/create-connect-session.dto.d.ts +8 -0
  41. package/dist/connect/dto/create-connect-session.dto.d.ts.map +1 -0
  42. package/dist/connect/dto/create-connect-session.dto.js +55 -0
  43. package/dist/connect/dto/create-test-session.dto.d.ts +10 -0
  44. package/dist/connect/dto/create-test-session.dto.d.ts.map +1 -0
  45. package/dist/connect/dto/create-test-session.dto.js +34 -0
  46. package/dist/connections/connections.controller.d.ts +8 -61
  47. package/dist/connections/connections.controller.d.ts.map +1 -1
  48. package/dist/connections/connections.controller.js +31 -9
  49. package/dist/connections/connections.module.d.ts.map +1 -1
  50. package/dist/connections/connections.module.js +4 -1
  51. package/dist/connections/connections.repository.d.ts +24 -0
  52. package/dist/connections/connections.repository.d.ts.map +1 -0
  53. package/dist/connections/connections.repository.js +66 -0
  54. package/dist/connections/connections.service.d.ts +24 -69
  55. package/dist/connections/connections.service.d.ts.map +1 -1
  56. package/dist/connections/connections.service.js +59 -56
  57. package/dist/connections/dto/list-connections.dto.d.ts +5 -0
  58. package/dist/connections/dto/list-connections.dto.d.ts.map +1 -0
  59. package/dist/connections/dto/list-connections.dto.js +25 -0
  60. package/dist/connections/environment-connections.controller.d.ts +26 -0
  61. package/dist/connections/environment-connections.controller.d.ts.map +1 -0
  62. package/dist/connections/environment-connections.controller.js +81 -0
  63. package/dist/connections/environment-connections.module.d.ts +11 -0
  64. package/dist/connections/environment-connections.module.d.ts.map +1 -0
  65. package/dist/connections/environment-connections.module.js +21 -0
  66. package/dist/credentials/credentials.module.d.ts +3 -0
  67. package/dist/credentials/credentials.module.d.ts.map +1 -0
  68. package/dist/credentials/credentials.module.js +15 -0
  69. package/dist/credentials/credentials.repository.d.ts +8 -0
  70. package/dist/credentials/credentials.repository.d.ts.map +1 -0
  71. package/dist/credentials/credentials.repository.js +21 -0
  72. package/dist/credentials/credentials.service.d.ts +45 -0
  73. package/dist/credentials/credentials.service.d.ts.map +1 -0
  74. package/dist/credentials/credentials.service.js +135 -0
  75. package/dist/crypto/credential-envelope.d.ts +56 -0
  76. package/dist/crypto/credential-envelope.d.ts.map +1 -0
  77. package/dist/crypto/credential-envelope.js +70 -0
  78. package/dist/crypto/crypto.service.d.ts +8 -0
  79. package/dist/crypto/crypto.service.d.ts.map +1 -1
  80. package/dist/crypto/crypto.service.js +12 -0
  81. package/dist/egress/ca.service.d.ts +36 -0
  82. package/dist/egress/ca.service.d.ts.map +1 -0
  83. package/dist/egress/ca.service.js +117 -0
  84. package/dist/egress/dto/mint-grant.dto.d.ts +7 -0
  85. package/dist/egress/dto/mint-grant.dto.d.ts.map +1 -0
  86. package/dist/egress/dto/mint-grant.dto.js +44 -0
  87. package/dist/egress/egress.controller.d.ts +18 -0
  88. package/dist/egress/egress.controller.d.ts.map +1 -0
  89. package/dist/egress/egress.controller.js +80 -0
  90. package/dist/egress/egress.listener.d.ts +39 -0
  91. package/dist/egress/egress.listener.d.ts.map +1 -0
  92. package/dist/egress/egress.listener.js +328 -0
  93. package/dist/egress/egress.module.d.ts +7 -0
  94. package/dist/egress/egress.module.d.ts.map +1 -0
  95. package/dist/egress/egress.module.js +31 -0
  96. package/dist/egress/egress.repository.d.ts +58 -0
  97. package/dist/egress/egress.repository.d.ts.map +1 -0
  98. package/dist/egress/egress.repository.js +116 -0
  99. package/dist/egress/grants.service.d.ts +77 -0
  100. package/dist/egress/grants.service.d.ts.map +1 -0
  101. package/dist/egress/grants.service.js +159 -0
  102. package/dist/egress/host-rules.service.d.ts +35 -0
  103. package/dist/egress/host-rules.service.d.ts.map +1 -0
  104. package/dist/egress/host-rules.service.js +48 -0
  105. package/dist/environments/dto/create-environment.dto.d.ts +6 -0
  106. package/dist/environments/dto/create-environment.dto.d.ts.map +1 -0
  107. package/dist/environments/dto/create-environment.dto.js +34 -0
  108. package/dist/environments/dto/update-environment.dto.d.ts +5 -0
  109. package/dist/environments/dto/update-environment.dto.d.ts.map +1 -0
  110. package/dist/environments/dto/update-environment.dto.js +24 -0
  111. package/dist/environments/environments.controller.d.ts +53 -0
  112. package/dist/environments/environments.controller.d.ts.map +1 -0
  113. package/dist/environments/environments.controller.js +101 -0
  114. package/dist/environments/environments.module.d.ts +3 -0
  115. package/dist/environments/environments.module.d.ts.map +1 -0
  116. package/dist/environments/environments.module.js +15 -0
  117. package/dist/environments/environments.repository.d.ts +37 -0
  118. package/dist/environments/environments.repository.d.ts.map +1 -0
  119. package/dist/environments/environments.repository.js +82 -0
  120. package/dist/environments/environments.service.d.ts +43 -0
  121. package/dist/environments/environments.service.d.ts.map +1 -0
  122. package/dist/environments/environments.service.js +124 -0
  123. package/dist/generated/prisma/browser.d.ts +17 -35
  124. package/dist/generated/prisma/browser.d.ts.map +1 -1
  125. package/dist/generated/prisma/client.d.ts +17 -35
  126. package/dist/generated/prisma/client.d.ts.map +1 -1
  127. package/dist/generated/prisma/commonInputTypes.d.ts +104 -145
  128. package/dist/generated/prisma/commonInputTypes.d.ts.map +1 -1
  129. package/dist/generated/prisma/enums.d.ts +1 -21
  130. package/dist/generated/prisma/enums.d.ts.map +1 -1
  131. package/dist/generated/prisma/enums.js +1 -18
  132. package/dist/generated/prisma/internal/class.d.ts +24 -46
  133. package/dist/generated/prisma/internal/class.d.ts.map +1 -1
  134. package/dist/generated/prisma/internal/class.js +4 -4
  135. package/dist/generated/prisma/internal/prismaNamespace.d.ts +258 -472
  136. package/dist/generated/prisma/internal/prismaNamespace.d.ts.map +1 -1
  137. package/dist/generated/prisma/internal/prismaNamespace.js +45 -83
  138. package/dist/generated/prisma/internal/prismaNamespaceBrowser.d.ts +45 -85
  139. package/dist/generated/prisma/internal/prismaNamespaceBrowser.d.ts.map +1 -1
  140. package/dist/generated/prisma/internal/prismaNamespaceBrowser.js +45 -83
  141. package/dist/generated/prisma/models/Account.d.ts +344 -26
  142. package/dist/generated/prisma/models/Account.d.ts.map +1 -1
  143. package/dist/generated/prisma/models/Configuration.d.ts +218 -851
  144. package/dist/generated/prisma/models/Configuration.d.ts.map +1 -1
  145. package/dist/generated/prisma/models/EgressGrant.d.ts +1535 -0
  146. package/dist/generated/prisma/models/EgressGrant.d.ts.map +1 -0
  147. package/dist/generated/prisma/models/Environment.d.ts +1644 -0
  148. package/dist/generated/prisma/models/Environment.d.ts.map +1 -0
  149. package/dist/generated/prisma/models/Invitation.d.ts +42 -1
  150. package/dist/generated/prisma/models/Invitation.d.ts.map +1 -1
  151. package/dist/generated/prisma/models/Organization.d.ts +183 -322
  152. package/dist/generated/prisma/models/Organization.d.ts.map +1 -1
  153. package/dist/generated/prisma/models/Session.d.ts +36 -1
  154. package/dist/generated/prisma/models/Session.d.ts.map +1 -1
  155. package/dist/generated/prisma/models/Team.d.ts +1498 -0
  156. package/dist/generated/prisma/models/Team.d.ts.map +1 -0
  157. package/dist/generated/prisma/models/TeamMember.d.ts +1281 -0
  158. package/dist/generated/prisma/models/TeamMember.d.ts.map +1 -0
  159. package/dist/generated/prisma/models/User.d.ts +338 -2
  160. package/dist/generated/prisma/models/User.d.ts.map +1 -1
  161. package/dist/generated/prisma/models.d.ts +4 -6
  162. package/dist/generated/prisma/models.d.ts.map +1 -1
  163. package/dist/index.d.ts +20 -5
  164. package/dist/index.d.ts.map +1 -1
  165. package/dist/index.js +17 -3
  166. package/dist/integrations/integrations.controller.d.ts +2 -1
  167. package/dist/integrations/integrations.controller.d.ts.map +1 -1
  168. package/dist/integrations/integrations.module.d.ts.map +1 -1
  169. package/dist/integrations/integrations.module.js +0 -2
  170. package/dist/kosha.module.d.ts.map +1 -1
  171. package/dist/kosha.module.js +13 -3
  172. package/dist/proxy/proxy.controller.d.ts +8 -3
  173. package/dist/proxy/proxy.controller.d.ts.map +1 -1
  174. package/dist/proxy/proxy.controller.js +26 -10
  175. package/dist/proxy/proxy.module.d.ts.map +1 -1
  176. package/dist/proxy/proxy.module.js +5 -3
  177. package/dist/proxy/proxy.repository.d.ts +24 -0
  178. package/dist/proxy/proxy.repository.d.ts.map +1 -0
  179. package/dist/proxy/proxy.repository.js +47 -0
  180. package/dist/proxy/proxy.service.d.ts +17 -21
  181. package/dist/proxy/proxy.service.d.ts.map +1 -1
  182. package/dist/proxy/proxy.service.js +61 -110
  183. package/package.json +9 -4
  184. package/prisma/migrations/20260929101936_init/migration.sql +345 -0
  185. package/prisma/migrations/20260930102529_connection_config/migration.sql +2 -0
  186. package/prisma/schema.prisma +103 -178
  187. package/dist/generated/prisma/models/ConnectSession.d.ts +0 -1606
  188. package/dist/generated/prisma/models/ConnectSession.d.ts.map +0 -1
  189. package/dist/generated/prisma/models/Connection.d.ts +0 -1949
  190. package/dist/generated/prisma/models/Connection.d.ts.map +0 -1
  191. package/dist/generated/prisma/models/ConnectionCredential.d.ts +0 -1293
  192. package/dist/generated/prisma/models/ConnectionCredential.d.ts.map +0 -1
  193. package/dist/generated/prisma/models/EndUser.d.ts +0 -1539
  194. package/dist/generated/prisma/models/EndUser.d.ts.map +0 -1
  195. package/dist/generated/prisma/models/OAuthState.d.ts +0 -1404
  196. package/dist/generated/prisma/models/OAuthState.d.ts.map +0 -1
  197. package/dist/generated/prisma/models/OAuthState.js +0 -1
  198. package/dist/generated/prisma/models/Provider.d.ts +0 -1462
  199. package/dist/generated/prisma/models/Provider.d.ts.map +0 -1
  200. package/dist/generated/prisma/models/Provider.js +0 -1
  201. package/dist/integrations/provider-sync.service.d.ts +0 -24
  202. package/dist/integrations/provider-sync.service.d.ts.map +0 -1
  203. package/dist/integrations/provider-sync.service.js +0 -74
  204. package/prisma/migrations/20260908000000_init/migration.sql +0 -209
  205. package/prisma/migrations/20260908161813_add_connect_domain/migration.sql +0 -173
  206. package/prisma/migrations/20260916000000_add_configuration_slug/migration.sql +0 -15
  207. /package/dist/generated/prisma/models/{ConnectSession.js → EgressGrant.js} +0 -0
  208. /package/dist/generated/prisma/models/{Connection.js → Environment.js} +0 -0
  209. /package/dist/generated/prisma/models/{ConnectionCredential.js → Team.js} +0 -0
  210. /package/dist/generated/prisma/models/{EndUser.js → TeamMember.js} +0 -0
@@ -0,0 +1,15 @@
1
+ import { __decorate } from "tslib";
2
+ import { Module } from '@nestjs/common';
3
+ import { ConfigurationsModule } from '../configurations/configurations.module.js';
4
+ import { CredentialsRepository } from './credentials.repository.js';
5
+ import { CredentialsService } from './credentials.service.js';
6
+ let CredentialsModule = class CredentialsModule {
7
+ };
8
+ CredentialsModule = __decorate([
9
+ Module({
10
+ imports: [ConfigurationsModule],
11
+ providers: [CredentialsService, CredentialsRepository],
12
+ exports: [CredentialsService],
13
+ })
14
+ ], CredentialsModule);
15
+ export { CredentialsModule };
@@ -0,0 +1,8 @@
1
+ import { PrismaService } from '../prisma/prisma.service.js';
2
+ export declare class CredentialsRepository {
3
+ private readonly prisma;
4
+ constructor(prisma: PrismaService);
5
+ /** Replaces the envelope in place, after a refresh minted a new token. */
6
+ replaceEnvelope(id: string, accessToken: string, accessTokenExpiresAt: Date | null): Promise<void>;
7
+ }
8
+ //# sourceMappingURL=credentials.repository.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credentials.repository.d.ts","sourceRoot":"","sources":["../../src/credentials/credentials.repository.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAE5D,qBACa,qBAAqB;IACpB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,aAAa;IAElD,0EAA0E;IACpE,eAAe,CACnB,EAAE,EAAE,MAAM,EACV,WAAW,EAAE,MAAM,EACnB,oBAAoB,EAAE,IAAI,GAAG,IAAI,GAChC,OAAO,CAAC,IAAI,CAAC;CAMjB"}
@@ -0,0 +1,21 @@
1
+ import { __decorate, __metadata } from "tslib";
2
+ import { Injectable } from '@nestjs/common';
3
+ import { PrismaService } from '../prisma/prisma.service.js';
4
+ let CredentialsRepository = class CredentialsRepository {
5
+ prisma;
6
+ constructor(prisma) {
7
+ this.prisma = prisma;
8
+ }
9
+ /** Replaces the envelope in place, after a refresh minted a new token. */
10
+ async replaceEnvelope(id, accessToken, accessTokenExpiresAt) {
11
+ await this.prisma.account.update({
12
+ where: { id },
13
+ data: { accessToken, accessTokenExpiresAt },
14
+ });
15
+ }
16
+ };
17
+ CredentialsRepository = __decorate([
18
+ Injectable(),
19
+ __metadata("design:paramtypes", [PrismaService])
20
+ ], CredentialsRepository);
21
+ export { CredentialsRepository };
@@ -0,0 +1,45 @@
1
+ import type { KoshaIntegration } from '@kosha-ai/integration-sdk';
2
+ import { ConfigurationsService } from '../configurations/configurations.service.js';
3
+ import { CryptoService } from '../crypto/crypto.service.js';
4
+ import type { Account } from '../generated/prisma/client.js';
5
+ import { CredentialsRepository } from './credentials.repository.js';
6
+ /**
7
+ * Turning a stored credential into something that can sign an outbound
8
+ * request.
9
+ *
10
+ * Its own service rather than a private method on the proxy, because the REST
11
+ * proxy and the egress broker both need this and two copies could disagree
12
+ * about when a credential is dead.
13
+ */
14
+ export interface ResolvedCredential {
15
+ accessToken: string;
16
+ tokenType: string | null;
17
+ expiresAt: Date | null;
18
+ /** True when we minted a new token, so the old one is now dead. */
19
+ refreshed: boolean;
20
+ }
21
+ export declare class CredentialsService {
22
+ private readonly crypto;
23
+ private readonly credentials;
24
+ private readonly configurations;
25
+ private readonly logger;
26
+ constructor(crypto: CryptoService, credentials: CredentialsRepository, configurations: ConfigurationsService);
27
+ /**
28
+ * Returns a usable access token, refreshing first when the stored one has
29
+ * expired and the provider supports it.
30
+ *
31
+ * Without this an expired token is a dead end for the end user: they walk
32
+ * the whole consent flow again for a token the provider was willing to
33
+ * renew.
34
+ */
35
+ resolve(account: Account, integration: KoshaIntegration): Promise<ResolvedCredential>;
36
+ private refresh;
37
+ /**
38
+ * What an outbound request needs, whatever the credential's shape. A
39
+ * client-credentials provider carries no token of its own: the integration
40
+ * signs from its configuration, so there is nothing to hand it here.
41
+ */
42
+ private usable;
43
+ private runTokenRefreshedHook;
44
+ }
45
+ //# sourceMappingURL=credentials.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credentials.service.d.ts","sourceRoot":"","sources":["../../src/credentials/credentials.service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,6CAA6C,CAAC;AAMpF,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAEpE;;;;;;;GAOG;AACH,MAAM,WAAW,kBAAkB;IACjC,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,SAAS,EAAE,IAAI,GAAG,IAAI,CAAC;IACvB,mEAAmE;IACnE,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,qBACa,kBAAkB;IAI3B,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,cAAc;IALjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuC;gBAG3C,MAAM,EAAE,aAAa,EACrB,WAAW,EAAE,qBAAqB,EAClC,cAAc,EAAE,qBAAqB;IAGxD;;;;;;;OAOG;IACG,OAAO,CACX,OAAO,EAAE,OAAO,EAChB,WAAW,EAAE,gBAAgB,GAC5B,OAAO,CAAC,kBAAkB,CAAC;YAyBhB,OAAO;IAgErB;;;;OAIG;IACH,OAAO,CAAC,MAAM;YAqCA,qBAAqB;CAoBpC"}
@@ -0,0 +1,135 @@
1
+ var CredentialsService_1;
2
+ import { __decorate, __metadata } from "tslib";
3
+ import { Injectable, Logger, UnauthorizedException } from '@nestjs/common';
4
+ import { ConfigurationsService } from '../configurations/configurations.service.js';
5
+ import { ENVELOPE_VERSION, expiryOf, } from '../crypto/credential-envelope.js';
6
+ import { CryptoService } from '../crypto/crypto.service.js';
7
+ import { CredentialsRepository } from './credentials.repository.js';
8
+ let CredentialsService = CredentialsService_1 = class CredentialsService {
9
+ crypto;
10
+ credentials;
11
+ configurations;
12
+ logger = new Logger(CredentialsService_1.name);
13
+ constructor(crypto, credentials, configurations) {
14
+ this.crypto = crypto;
15
+ this.credentials = credentials;
16
+ this.configurations = configurations;
17
+ }
18
+ /**
19
+ * Returns a usable access token, refreshing first when the stored one has
20
+ * expired and the provider supports it.
21
+ *
22
+ * Without this an expired token is a dead end for the end user: they walk
23
+ * the whole consent flow again for a token the provider was willing to
24
+ * renew.
25
+ */
26
+ async resolve(account, integration) {
27
+ if (!account.accessToken) {
28
+ throw new UnauthorizedException('Connection has no stored credential');
29
+ }
30
+ const envelope = this.crypto.openEnvelope(account.accessToken);
31
+ const expiresAt = expiryOf(envelope);
32
+ const expired = expiresAt !== null && expiresAt <= new Date();
33
+ if (!expired)
34
+ return this.usable(envelope, expiresAt, false);
35
+ const refreshToken = envelope.type === 'oauth2' ? envelope.refreshToken : undefined;
36
+ const canRefresh = typeof integration.auth.refresh === 'function' && refreshToken;
37
+ if (!canRefresh) {
38
+ throw new UnauthorizedException('Connection token expired; the end user must reconnect');
39
+ }
40
+ return this.refresh(account, integration, refreshToken);
41
+ }
42
+ async refresh(account, integration, refreshToken) {
43
+ const { configuration, credentials } = await this.configurations.getWithCredentials(account.providerId);
44
+ const settings = (configuration.settings ?? {});
45
+ try {
46
+ const tokens = await integration.auth.refresh?.({
47
+ client: {
48
+ clientId: String(credentials['clientId'] ?? ''),
49
+ clientSecret: String(credentials['clientSecret'] ?? ''),
50
+ redirectUri: settings.redirectUri ??
51
+ this.configurations.callbackUrlFor(configuration.integrationKey),
52
+ scopes: settings.scopes ?? [],
53
+ },
54
+ refreshToken,
55
+ });
56
+ if (!tokens)
57
+ throw new Error('Refresh returned no tokens');
58
+ const envelope = {
59
+ v: ENVELOPE_VERSION,
60
+ type: 'oauth2',
61
+ accessToken: tokens.accessToken,
62
+ ...(tokens.refreshToken ? { refreshToken: tokens.refreshToken } : {}),
63
+ ...(tokens.tokenType ? { tokenType: tokens.tokenType } : {}),
64
+ ...(tokens.expiresInSeconds
65
+ ? {
66
+ expiresAt: new Date(Date.now() + tokens.expiresInSeconds * 1000).toISOString(),
67
+ }
68
+ : {}),
69
+ };
70
+ const expiresAt = expiryOf(envelope);
71
+ await this.credentials.replaceEnvelope(account.id, this.crypto.sealEnvelope(envelope), expiresAt);
72
+ await this.runTokenRefreshedHook(account.id, integration, tokens);
73
+ return this.usable(envelope, expiresAt, true);
74
+ }
75
+ catch (error) {
76
+ this.logger.warn(`Refresh failed for ${integration.key}: ${error instanceof Error ? error.message : error}`);
77
+ throw new UnauthorizedException('Connection token expired and could not be refreshed; the end user must reconnect');
78
+ }
79
+ }
80
+ /**
81
+ * What an outbound request needs, whatever the credential's shape. A
82
+ * client-credentials provider carries no token of its own: the integration
83
+ * signs from its configuration, so there is nothing to hand it here.
84
+ */
85
+ usable(envelope, expiresAt, refreshed) {
86
+ switch (envelope.type) {
87
+ case 'oauth2':
88
+ return {
89
+ accessToken: envelope.accessToken,
90
+ tokenType: envelope.tokenType ?? null,
91
+ expiresAt,
92
+ refreshed,
93
+ };
94
+ case 'api_key':
95
+ return {
96
+ accessToken: envelope.key,
97
+ tokenType: null,
98
+ expiresAt: null,
99
+ refreshed,
100
+ };
101
+ case 'app':
102
+ return {
103
+ accessToken: envelope.installationId,
104
+ tokenType: null,
105
+ expiresAt: null,
106
+ refreshed,
107
+ };
108
+ case 'oauth2_cc':
109
+ return {
110
+ accessToken: '',
111
+ tokenType: null,
112
+ expiresAt: null,
113
+ refreshed,
114
+ };
115
+ }
116
+ }
117
+ async runTokenRefreshedHook(connectionId, integration, tokens) {
118
+ const hook = integration.hooks?.onTokenRefreshed;
119
+ if (!hook)
120
+ return;
121
+ try {
122
+ await hook({ connectionId, tokens });
123
+ }
124
+ catch (error) {
125
+ this.logger.error(`onTokenRefreshed hook failed for "${integration.key}": ${error instanceof Error ? error.message : error}`);
126
+ }
127
+ }
128
+ };
129
+ CredentialsService = CredentialsService_1 = __decorate([
130
+ Injectable(),
131
+ __metadata("design:paramtypes", [CryptoService,
132
+ CredentialsRepository,
133
+ ConfigurationsService])
134
+ ], CredentialsService);
135
+ export { CredentialsService };
@@ -0,0 +1,56 @@
1
+ /**
2
+ * What a stored credential actually is.
3
+ *
4
+ * `account.accessToken` holds one of these, encrypted — not a bare token. The
5
+ * database knows nothing about auth types, so the discriminator travels with
6
+ * the secret rather than sitting in a column, and a provider that needs
7
+ * different fields needs no migration.
8
+ */
9
+ export declare const ENVELOPE_VERSION = 1;
10
+ interface Versioned {
11
+ v: typeof ENVELOPE_VERSION;
12
+ }
13
+ /** A token pair from an authorization-code flow. */
14
+ export interface OAuth2Envelope extends Versioned {
15
+ type: 'oauth2';
16
+ accessToken: string;
17
+ refreshToken?: string;
18
+ tokenType?: string;
19
+ /** ISO 8601. Mirrored into `account.accessTokenExpiresAt` on write. */
20
+ expiresAt?: string;
21
+ }
22
+ /** A key the end user pasted, such as Apollo's. */
23
+ export interface ApiKeyEnvelope extends Versioned {
24
+ type: 'api_key';
25
+ key: string;
26
+ }
27
+ /** A GitHub App install: tokens are minted per call from the installation. */
28
+ export interface AppEnvelope extends Versioned {
29
+ type: 'app';
30
+ installationId: string;
31
+ }
32
+ /**
33
+ * Client credentials, like Zoom's. The secret lives entirely in the
34
+ * configuration, so the connection records nothing but its own existence.
35
+ */
36
+ export interface ClientCredentialsEnvelope extends Versioned {
37
+ type: 'oauth2_cc';
38
+ }
39
+ export type CredentialEnvelope = OAuth2Envelope | ApiKeyEnvelope | AppEnvelope | ClientCredentialsEnvelope;
40
+ export type CredentialEnvelopeType = CredentialEnvelope['type'];
41
+ export declare class InvalidEnvelopeError extends Error {
42
+ constructor(reason: string);
43
+ }
44
+ /**
45
+ * Rejects rather than guesses. A credential we cannot read is a connection the
46
+ * end user must redo, and that is a better outcome than sending a provider
47
+ * something we mis-parsed.
48
+ */
49
+ export declare function parseEnvelope(json: string): CredentialEnvelope;
50
+ /**
51
+ * The expiry to mirror into `account.accessTokenExpiresAt`, so the refresh
52
+ * sweep can find expiring credentials without decrypting any of them.
53
+ */
54
+ export declare function expiryOf(envelope: CredentialEnvelope): Date | null;
55
+ export {};
56
+ //# sourceMappingURL=credential-envelope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"credential-envelope.d.ts","sourceRoot":"","sources":["../../src/crypto/credential-envelope.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAElC,UAAU,SAAS;IACjB,CAAC,EAAE,OAAO,gBAAgB,CAAC;CAC5B;AAED,oDAAoD;AACpD,MAAM,WAAW,cAAe,SAAQ,SAAS;IAC/C,IAAI,EAAE,QAAQ,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,uEAAuE;IACvE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,mDAAmD;AACnD,MAAM,WAAW,cAAe,SAAQ,SAAS;IAC/C,IAAI,EAAE,SAAS,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;CACb;AAED,8EAA8E;AAC9E,MAAM,WAAW,WAAY,SAAQ,SAAS;IAC5C,IAAI,EAAE,KAAK,CAAC;IACZ,cAAc,EAAE,MAAM,CAAC;CACxB;AAED;;;GAGG;AACH,MAAM,WAAW,yBAA0B,SAAQ,SAAS;IAC1D,IAAI,EAAE,WAAW,CAAC;CACnB;AAED,MAAM,MAAM,kBAAkB,GAC5B,cAAc,GAAG,cAAc,GAAG,WAAW,GAAG,yBAAyB,CAAC;AAE5E,MAAM,MAAM,sBAAsB,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;AAEhE,qBAAa,oBAAqB,SAAQ,KAAK;gBACjC,MAAM,EAAE,MAAM;CAI3B;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,CA6C9D;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,kBAAkB,GAAG,IAAI,GAAG,IAAI,CAKlE"}
@@ -0,0 +1,70 @@
1
+ /**
2
+ * What a stored credential actually is.
3
+ *
4
+ * `account.accessToken` holds one of these, encrypted — not a bare token. The
5
+ * database knows nothing about auth types, so the discriminator travels with
6
+ * the secret rather than sitting in a column, and a provider that needs
7
+ * different fields needs no migration.
8
+ */
9
+ export const ENVELOPE_VERSION = 1;
10
+ export class InvalidEnvelopeError extends Error {
11
+ constructor(reason) {
12
+ super(`Stored credential is unusable: ${reason}`);
13
+ this.name = 'InvalidEnvelopeError';
14
+ }
15
+ }
16
+ /**
17
+ * Rejects rather than guesses. A credential we cannot read is a connection the
18
+ * end user must redo, and that is a better outcome than sending a provider
19
+ * something we mis-parsed.
20
+ */
21
+ export function parseEnvelope(json) {
22
+ let value;
23
+ try {
24
+ value = JSON.parse(json);
25
+ }
26
+ catch {
27
+ throw new InvalidEnvelopeError('not JSON');
28
+ }
29
+ if (typeof value !== 'object' || value === null) {
30
+ throw new InvalidEnvelopeError('not an object');
31
+ }
32
+ const envelope = value;
33
+ if (envelope.v !== ENVELOPE_VERSION) {
34
+ throw new InvalidEnvelopeError(`version ${String(envelope.v)} is not supported, expected ${ENVELOPE_VERSION}`);
35
+ }
36
+ switch (envelope.type) {
37
+ case 'oauth2':
38
+ if (!isNonEmptyString(envelope.accessToken)) {
39
+ throw new InvalidEnvelopeError('oauth2 envelope has no accessToken');
40
+ }
41
+ return envelope;
42
+ case 'api_key':
43
+ if (!isNonEmptyString(envelope.key)) {
44
+ throw new InvalidEnvelopeError('api_key envelope has no key');
45
+ }
46
+ return envelope;
47
+ case 'app':
48
+ if (!isNonEmptyString(envelope.installationId)) {
49
+ throw new InvalidEnvelopeError('app envelope has no installationId');
50
+ }
51
+ return envelope;
52
+ case 'oauth2_cc':
53
+ return envelope;
54
+ default:
55
+ throw new InvalidEnvelopeError(`unknown type "${String(envelope.type)}"`);
56
+ }
57
+ }
58
+ /**
59
+ * The expiry to mirror into `account.accessTokenExpiresAt`, so the refresh
60
+ * sweep can find expiring credentials without decrypting any of them.
61
+ */
62
+ export function expiryOf(envelope) {
63
+ if (envelope.type !== 'oauth2' || !envelope.expiresAt)
64
+ return null;
65
+ const expiry = new Date(envelope.expiresAt);
66
+ return Number.isNaN(expiry.getTime()) ? null : expiry;
67
+ }
68
+ function isNonEmptyString(value) {
69
+ return typeof value === 'string' && value.length > 0;
70
+ }
@@ -1,4 +1,5 @@
1
1
  import type { ResolvedKoshaConfig } from '../config/kosha-config.js';
2
+ import { type CredentialEnvelope } from './credential-envelope.js';
2
3
  export declare class MissingEncryptionKeyError extends Error {
3
4
  constructor();
4
5
  }
@@ -16,6 +17,13 @@ export declare class CryptoService {
16
17
  /** `iv.authTag.ciphertext`, each part base64. */
17
18
  encrypt(plaintext: string): string;
18
19
  decrypt(payload: string): string;
20
+ /**
21
+ * A credential goes to rest as an encrypted envelope carrying its own type
22
+ * and version, so the column it lives in needs to know neither.
23
+ */
24
+ sealEnvelope(envelope: CredentialEnvelope): string;
25
+ /** Throws rather than returning a half-understood credential. */
26
+ openEnvelope(payload: string): CredentialEnvelope;
19
27
  private requireKey;
20
28
  }
21
29
  //# sourceMappingURL=crypto.service.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"crypto.service.d.ts","sourceRoot":"","sources":["../../src/crypto/crypto.service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAOrE,qBAAa,yBAA0B,SAAQ,KAAK;;CAOnD;AAED;;;;;;GAMG;AACH,qBACa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAS;gBAEI,MAAM,EAAE,mBAAmB;IAgB7D,IAAI,YAAY,IAAI,OAAO,CAE1B;IAED,iDAAiD;IACjD,OAAO,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM;IAgBlC,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAoBhC,OAAO,CAAC,UAAU;CAInB"}
1
+ {"version":3,"file":"crypto.service.d.ts","sourceRoot":"","sources":["../../src/crypto/crypto.service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAErE,OAAO,EAEL,KAAK,kBAAkB,EACxB,MAAM,0BAA0B,CAAC;AAMlC,qBAAa,yBAA0B,SAAQ,KAAK;;CAOnD;AAED;;;;;;GAMG;AACH,qBACa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAS;gBAEI,MAAM,EAAE,mBAAmB;IAgB7D,IAAI,YAAY,IAAI,OAAO,CAE1B;IAED,iDAAiD;IACjD,OAAO,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM;IAgBlC,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAoBhC;;;OAGG;IACH,YAAY,CAAC,QAAQ,EAAE,kBAAkB,GAAG,MAAM;IAIlD,iEAAiE;IACjE,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,kBAAkB;IAIjD,OAAO,CAAC,UAAU;CAInB"}
@@ -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,36 @@
1
+ import type { ResolvedKoshaConfig } from '../config/kosha-config.js';
2
+ /**
3
+ * The per-grant certificate authority, and the leaf certificates it signs.
4
+ *
5
+ * Injecting a credential means terminating TLS, which means presenting a
6
+ * certificate for a host we are not. So each grant gets a CA of its own, stored
7
+ * in its row and worthless once it is revoked. One shared CA would let a key
8
+ * extracted from any sandbox forge certificates for every other sandbox.
9
+ */
10
+ export interface CertificateAuthority {
11
+ readonly certPem: string;
12
+ readonly keyPem: string;
13
+ }
14
+ export interface LeafCertificate {
15
+ readonly cert: string;
16
+ readonly key: string;
17
+ }
18
+ export declare class CaService {
19
+ private readonly config;
20
+ private readonly leaves;
21
+ constructor(config: ResolvedKoshaConfig);
22
+ /**
23
+ * A fresh CA. 2048-bit because this runs synchronously on the request that
24
+ * mints a grant and 4096 costs seconds there, for a key discarded in hours.
25
+ */
26
+ createCertificateAuthority(): CertificateAuthority;
27
+ /** A leaf for `host`, signed by this grant's CA. Cached per grant and host. */
28
+ leafFor(grant: {
29
+ id: string;
30
+ caPem: string;
31
+ caKeyPem: string;
32
+ }, host: string): LeafCertificate;
33
+ /** Drops every leaf a grant's CA signed. Called when the grant is revoked. */
34
+ forgetLeaves(grantId: string): void;
35
+ }
36
+ //# sourceMappingURL=ca.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ca.service.d.ts","sourceRoot":"","sources":["../../src/egress/ca.service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAGrE;;;;;;;GAOG;AAEH,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAaD,qBACa,SAAS;IAOI,OAAO,CAAC,QAAQ,CAAC,MAAM;IAH/C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAsC;gBAGpB,MAAM,EAAE,mBAAmB;IAGpE;;;OAGG;IACH,0BAA0B,IAAI,oBAAoB;IAiClD,+EAA+E;IAC/E,OAAO,CACL,KAAK,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,EACtD,IAAI,EAAE,MAAM,GACX,eAAe;IAyDlB,8EAA8E;IAC9E,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;CAKpC"}
@@ -0,0 +1,117 @@
1
+ import { __decorate, __metadata, __param } from "tslib";
2
+ import { Inject, Injectable } from '@nestjs/common';
3
+ import forge from 'node-forge';
4
+ import { KOSHA_CONFIG } from '../config/tokens.js';
5
+ /** Bounded so a long-lived process cannot accumulate one entry per host seen. */
6
+ const MAX_LEAVES = 512;
7
+ /**
8
+ * Picks the SAN type for the leaf. Node rejects a certificate whose only SAN is
9
+ * a DNS entry when the client connected to an address.
10
+ */
11
+ function isIpLiteral(host) {
12
+ return /^[0-9.]+$/.test(host) || host.includes(':');
13
+ }
14
+ let CaService = class CaService {
15
+ config;
16
+ // Signing is ~10ms of RSA and git opens a connection per operation, so a
17
+ // clone would pay for it repeatedly. Keyed by grant and host, because a leaf
18
+ // from one grant's CA is worthless under another's.
19
+ leaves = new Map();
20
+ constructor(config) {
21
+ this.config = config;
22
+ }
23
+ /**
24
+ * A fresh CA. 2048-bit because this runs synchronously on the request that
25
+ * mints a grant and 4096 costs seconds there, for a key discarded in hours.
26
+ */
27
+ createCertificateAuthority() {
28
+ const keys = forge.pki.rsa.generateKeyPair(2048);
29
+ const cert = forge.pki.createCertificate();
30
+ cert.publicKey = keys.publicKey;
31
+ cert.serialNumber = `00${forge.util.bytesToHex(forge.random.getBytesSync(16))}`;
32
+ cert.validity.notBefore = new Date(Date.now() - 5 * 60_000);
33
+ cert.validity.notAfter = new Date(Date.now() + 30 * 24 * 60 * 60_000);
34
+ const attrs = [
35
+ { name: 'commonName', value: 'Kosha Egress Broker' },
36
+ { name: 'organizationName', value: 'Kosha' },
37
+ ];
38
+ cert.setSubject(attrs);
39
+ cert.setIssuer(attrs);
40
+ cert.setExtensions([
41
+ {
42
+ cA: true,
43
+ critical: true,
44
+ name: 'basicConstraints',
45
+ pathLenConstraint: 0,
46
+ },
47
+ { critical: true, keyCertSign: true, name: 'keyUsage' },
48
+ ]);
49
+ cert.sign(keys.privateKey, forge.md.sha256.create());
50
+ return {
51
+ certPem: forge.pki.certificateToPem(cert),
52
+ keyPem: forge.pki.privateKeyToPem(keys.privateKey),
53
+ };
54
+ }
55
+ /** A leaf for `host`, signed by this grant's CA. Cached per grant and host. */
56
+ leafFor(grant, host) {
57
+ const cacheKey = `${grant.id}:${host}`;
58
+ const hit = this.leaves.get(cacheKey);
59
+ if (hit !== undefined)
60
+ return hit;
61
+ const caCert = forge.pki.certificateFromPem(grant.caPem);
62
+ const caKey = forge.pki.privateKeyFromPem(grant.caKeyPem);
63
+ const keys = forge.pki.rsa.generateKeyPair(2048);
64
+ const cert = forge.pki.createCertificate();
65
+ cert.publicKey = keys.publicKey;
66
+ cert.serialNumber = `00${forge.util.bytesToHex(forge.random.getBytesSync(16))}`;
67
+ cert.validity.notBefore = new Date(Date.now() - 5 * 60_000);
68
+ cert.validity.notAfter = new Date(Date.now() + this.config.egress.leafCertDays * 24 * 60 * 60_000);
69
+ cert.setSubject([{ name: 'commonName', value: host }]);
70
+ cert.setIssuer(caCert.subject.attributes);
71
+ cert.setExtensions([
72
+ { cA: false, critical: true, name: 'basicConstraints' },
73
+ {
74
+ critical: true,
75
+ digitalSignature: true,
76
+ keyEncipherment: true,
77
+ name: 'keyUsage',
78
+ },
79
+ { name: 'extKeyUsage', serverAuth: true },
80
+ {
81
+ // The SAN is what clients actually check; commonName alone has not
82
+ // been accepted for years.
83
+ altNames: [
84
+ isIpLiteral(host) ? { ip: host, type: 7 } : { type: 2, value: host },
85
+ ],
86
+ name: 'subjectAltName',
87
+ },
88
+ ]);
89
+ cert.sign(caKey, forge.md.sha256.create());
90
+ const leaf = {
91
+ cert: forge.pki.certificateToPem(cert),
92
+ key: forge.pki.privateKeyToPem(keys.privateKey),
93
+ };
94
+ // Map preserves insertion order, so dropping the oldest is enough to bound
95
+ // a cache.
96
+ if (this.leaves.size >= MAX_LEAVES) {
97
+ const oldest = this.leaves.keys().next();
98
+ if (!oldest.done)
99
+ this.leaves.delete(oldest.value);
100
+ }
101
+ this.leaves.set(cacheKey, leaf);
102
+ return leaf;
103
+ }
104
+ /** Drops every leaf a grant's CA signed. Called when the grant is revoked. */
105
+ forgetLeaves(grantId) {
106
+ for (const key of this.leaves.keys()) {
107
+ if (key.startsWith(`${grantId}:`))
108
+ this.leaves.delete(key);
109
+ }
110
+ }
111
+ };
112
+ CaService = __decorate([
113
+ Injectable(),
114
+ __param(0, Inject(KOSHA_CONFIG)),
115
+ __metadata("design:paramtypes", [Object])
116
+ ], CaService);
117
+ export { CaService };
@@ -0,0 +1,7 @@
1
+ export declare class MintGrantDto {
2
+ externalUserId: string;
3
+ providerKeys?: string[];
4
+ expiresAt: string;
5
+ label?: string;
6
+ }
7
+ //# sourceMappingURL=mint-grant.dto.d.ts.map
@@ -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);
@@ -0,0 +1,18 @@
1
+ import { type ApiKeyRequest } from '../auth/api-key.guard.js';
2
+ import { MintGrantDto } from './dto/mint-grant.dto.js';
3
+ import { GrantsService } from './grants.service.js';
4
+ /**
5
+ * Minting and revoking egress grants. `ApiKeyGuard` rather than `OrgAuthGuard`
6
+ * because handing a sandbox an identity is an errand for an app's backend, not
7
+ * for a browser session.
8
+ */
9
+ export declare class EgressController {
10
+ private readonly grants;
11
+ constructor(grants: GrantsService);
12
+ mint(request: ApiKeyRequest, body: MintGrantDto): Promise<import("./grants.service.js").MintedGrant>;
13
+ revoke(request: ApiKeyRequest, id: string): Promise<{
14
+ grantId: string;
15
+ revoked: boolean;
16
+ }>;
17
+ }
18
+ //# sourceMappingURL=egress.controller.d.ts.map
@@ -0,0 +1 @@
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"}