@kosha-ai/server 0.2.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.
Files changed (116) hide show
  1. package/dist/auth/auth.factory.d.ts.map +1 -1
  2. package/dist/auth/auth.factory.js +0 -5
  3. package/dist/configurations/configurations.controller.d.ts +6 -5
  4. package/dist/configurations/configurations.controller.d.ts.map +1 -1
  5. package/dist/configurations/configurations.controller.js +22 -18
  6. package/dist/configurations/configurations.module.d.ts.map +1 -1
  7. package/dist/configurations/configurations.module.js +1 -2
  8. package/dist/configurations/configurations.service.d.ts +24 -36
  9. package/dist/configurations/configurations.service.d.ts.map +1 -1
  10. package/dist/configurations/configurations.service.js +71 -151
  11. package/dist/configurations/dto/create-configuration.dto.d.ts +1 -2
  12. package/dist/configurations/dto/create-configuration.dto.d.ts.map +1 -1
  13. package/dist/configurations/dto/create-configuration.dto.js +2 -12
  14. package/dist/configurations/dto/update-configuration.dto.d.ts +0 -2
  15. package/dist/configurations/dto/update-configuration.dto.d.ts.map +1 -1
  16. package/dist/configurations/dto/update-configuration.dto.js +1 -17
  17. package/dist/connect/connect.controller.d.ts +1 -1
  18. package/dist/connect/connect.controller.d.ts.map +1 -1
  19. package/dist/connect/connect.controller.js +7 -6
  20. package/dist/connect/connect.module.d.ts.map +1 -1
  21. package/dist/connect/connect.module.js +1 -2
  22. package/dist/connect/connect.repository.d.ts +23 -23
  23. package/dist/connect/connect.repository.d.ts.map +1 -1
  24. package/dist/connect/connect.repository.js +37 -49
  25. package/dist/connect/connect.service.d.ts +7 -8
  26. package/dist/connect/connect.service.d.ts.map +1 -1
  27. package/dist/connect/connect.service.js +54 -51
  28. package/dist/connect/dto/create-connect-session.dto.d.ts +1 -1
  29. package/dist/connect/dto/create-connect-session.dto.d.ts.map +1 -1
  30. package/dist/connect/dto/create-connect-session.dto.js +7 -8
  31. package/dist/connect/dto/create-test-session.dto.d.ts +1 -0
  32. package/dist/connect/dto/create-test-session.dto.d.ts.map +1 -1
  33. package/dist/connect/dto/create-test-session.dto.js +10 -3
  34. package/dist/connections/connections.controller.d.ts +4 -3
  35. package/dist/connections/connections.controller.d.ts.map +1 -1
  36. package/dist/connections/connections.controller.js +13 -11
  37. package/dist/connections/connections.repository.d.ts +24 -17
  38. package/dist/connections/connections.repository.d.ts.map +1 -1
  39. package/dist/connections/connections.repository.js +21 -43
  40. package/dist/connections/connections.service.d.ts +48 -13
  41. package/dist/connections/connections.service.d.ts.map +1 -1
  42. package/dist/connections/connections.service.js +111 -32
  43. package/dist/connections/dto/list-connections.dto.d.ts +3 -1
  44. package/dist/connections/dto/list-connections.dto.d.ts.map +1 -1
  45. package/dist/connections/dto/list-connections.dto.js +26 -4
  46. package/dist/connections/environment-connections.controller.d.ts +4 -3
  47. package/dist/connections/environment-connections.controller.d.ts.map +1 -1
  48. package/dist/connections/environment-connections.controller.js +14 -12
  49. package/dist/credentials/credentials.module.d.ts.map +1 -1
  50. package/dist/credentials/credentials.module.js +0 -2
  51. package/dist/credentials/credentials.repository.d.ts +5 -2
  52. package/dist/credentials/credentials.repository.d.ts.map +1 -1
  53. package/dist/credentials/credentials.repository.js +10 -3
  54. package/dist/credentials/credentials.service.d.ts +8 -4
  55. package/dist/credentials/credentials.service.d.ts.map +1 -1
  56. package/dist/credentials/credentials.service.js +27 -16
  57. package/dist/egress/egress.listener.d.ts +1 -3
  58. package/dist/egress/egress.listener.d.ts.map +1 -1
  59. package/dist/egress/egress.listener.js +3 -7
  60. package/dist/egress/egress.repository.d.ts +13 -6
  61. package/dist/egress/egress.repository.d.ts.map +1 -1
  62. package/dist/egress/egress.repository.js +31 -44
  63. package/dist/generated/prisma/browser.d.ts +0 -5
  64. package/dist/generated/prisma/browser.d.ts.map +1 -1
  65. package/dist/generated/prisma/client.d.ts +0 -5
  66. package/dist/generated/prisma/client.d.ts.map +1 -1
  67. package/dist/generated/prisma/commonInputTypes.d.ts +0 -55
  68. package/dist/generated/prisma/commonInputTypes.d.ts.map +1 -1
  69. package/dist/generated/prisma/internal/class.d.ts +0 -11
  70. package/dist/generated/prisma/internal/class.d.ts.map +1 -1
  71. package/dist/generated/prisma/internal/class.js +4 -4
  72. package/dist/generated/prisma/internal/prismaNamespace.d.ts +1 -114
  73. package/dist/generated/prisma/internal/prismaNamespace.d.ts.map +1 -1
  74. package/dist/generated/prisma/internal/prismaNamespace.js +2 -29
  75. package/dist/generated/prisma/internal/prismaNamespaceBrowser.d.ts +0 -30
  76. package/dist/generated/prisma/internal/prismaNamespaceBrowser.d.ts.map +1 -1
  77. package/dist/generated/prisma/internal/prismaNamespaceBrowser.js +2 -29
  78. package/dist/generated/prisma/models/Account.d.ts +26 -344
  79. package/dist/generated/prisma/models/Account.d.ts.map +1 -1
  80. package/dist/generated/prisma/models/Environment.d.ts +0 -258
  81. package/dist/generated/prisma/models/Environment.d.ts.map +1 -1
  82. package/dist/generated/prisma/models/User.d.ts +2 -60
  83. package/dist/generated/prisma/models/User.d.ts.map +1 -1
  84. package/dist/generated/prisma/models.d.ts +0 -1
  85. package/dist/generated/prisma/models.d.ts.map +1 -1
  86. package/dist/index.d.ts +1 -2
  87. package/dist/index.d.ts.map +1 -1
  88. package/dist/integrations/integrations.controller.d.ts +2 -0
  89. package/dist/integrations/integrations.controller.d.ts.map +1 -1
  90. package/dist/integrations/integrations.controller.js +1 -0
  91. package/dist/integrations/integrations.module.d.ts.map +1 -1
  92. package/dist/integrations/integrations.module.js +3 -1
  93. package/dist/integrations/provider-store.d.ts +104 -0
  94. package/dist/integrations/provider-store.d.ts.map +1 -0
  95. package/dist/integrations/provider-store.js +234 -0
  96. package/dist/proxy/proxy.controller.d.ts +9 -5
  97. package/dist/proxy/proxy.controller.d.ts.map +1 -1
  98. package/dist/proxy/proxy.controller.js +18 -13
  99. package/dist/proxy/proxy.module.d.ts.map +1 -1
  100. package/dist/proxy/proxy.module.js +1 -2
  101. package/dist/proxy/proxy.repository.d.ts +11 -14
  102. package/dist/proxy/proxy.repository.d.ts.map +1 -1
  103. package/dist/proxy/proxy.repository.js +17 -27
  104. package/dist/proxy/proxy.service.d.ts +6 -8
  105. package/dist/proxy/proxy.service.d.ts.map +1 -1
  106. package/dist/proxy/proxy.service.js +34 -28
  107. package/package.json +4 -4
  108. package/prisma/migrations/{20260929101936_init → 20261008090000_init}/migration.sql +5 -58
  109. package/prisma/schema.prisma +2 -43
  110. package/dist/configurations/configurations.repository.d.ts +0 -43
  111. package/dist/configurations/configurations.repository.d.ts.map +0 -1
  112. package/dist/configurations/configurations.repository.js +0 -76
  113. package/dist/generated/prisma/models/Configuration.d.ts +0 -1385
  114. package/dist/generated/prisma/models/Configuration.d.ts.map +0 -1
  115. package/dist/generated/prisma/models/Configuration.js +0 -1
  116. package/prisma/migrations/20260930102529_connection_config/migration.sql +0 -2
@@ -1 +1 @@
1
- {"version":3,"file":"auth.factory.d.ts","sourceRoot":"","sources":["../../src/auth/auth.factory.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAc,KAAK,IAAI,EAAE,MAAM,aAAa,CAAC;AAIpD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAEnF,gFAAgF;AAChF,MAAM,WAAW,YAAY;IAC3B,YAAY,CAAC,KAAK,EAAE;QAAE,IAAI,EAAE;YAAE,GAAG,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,GAAG,OAAO,CAAC;QACtD,KAAK,EAAE,OAAO,CAAC;QACf,GAAG,CAAC,EAAE;YACJ,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;YAC5B,mEAAmE;YACnE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;SAC3C,GAAG,IAAI,CAAC;QACT,KAAK,CAAC,EAAE,OAAO,CAAC;KAC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auth.emailAndPassword?.enabled ?? true,
43
43
  },
44
- user: {
45
- additionalFields: {
46
- externalId: { type: 'string', required: false, input: false },
47
- },
48
- },
49
44
  trustedOrigins: config.auth.trustedOrigins ?? [],
50
45
  advanced: { defaultCookieAttributes: crossSiteCookieAttributes(config) },
51
46
  hooks: {
@@ -10,11 +10,12 @@ import { UpdateConfigurationDto } from './dto/update-configuration.dto.js';
10
10
  export declare class ConfigurationsController {
11
11
  private readonly configurations;
12
12
  constructor(configurations: ConfigurationsService);
13
- list(session: UserSession, environmentId: string): Promise<import("./configurations.repository.js").PublicConfiguration[]>;
14
- get(session: UserSession, environmentId: string, id: string): Promise<import("./configurations.repository.js").PublicConfiguration>;
15
- create(session: UserSession, environmentId: string, body: CreateConfigurationDto): Promise<import("./configurations.repository.js").PublicConfiguration>;
16
- update(session: UserSession, environmentId: string, id: string, body: UpdateConfigurationDto): Promise<import("./configurations.repository.js").PublicConfiguration>;
17
- remove(session: UserSession, environmentId: string, id: string): Promise<{
13
+ list(session: UserSession, environmentId: string): Promise<import("./configurations.service.js").DescribedConfiguration[]>;
14
+ /** The provider names the table the id lives in, so it is part of the path. */
15
+ get(session: UserSession, environmentId: string, provider: string, id: string): Promise<import("./configurations.service.js").DescribedConfiguration>;
16
+ create(session: UserSession, environmentId: string, body: CreateConfigurationDto): Promise<import("./configurations.service.js").DescribedConfiguration>;
17
+ update(session: UserSession, environmentId: string, provider: string, id: string, body: UpdateConfigurationDto): Promise<import("./configurations.service.js").DescribedConfiguration>;
18
+ remove(session: UserSession, environmentId: string, provider: string, id: string): Promise<{
18
19
  id: string;
19
20
  deleted: boolean;
20
21
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"configurations.controller.d.ts","sourceRoot":"","sources":["../../src/configurations/configurations.controller.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAW,KAAK,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAEzE,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAC3E,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAE3E;;;;GAIG;AACH,qBAEa,wBAAwB;IACvB,OAAO,CAAC,QAAQ,CAAC,cAAc;gBAAd,cAAc,EAAE,qBAAqB;IAKlE,IAAI,CACS,OAAO,EAAE,WAAW,EACP,aAAa,EAAE,MAAM;IAY/C,GAAG,CACU,OAAO,EAAE,WAAW,EACP,aAAa,EAAE,MAAM,EAChC,EAAE,EAAE,MAAM;IAqBzB,MAAM,CACO,OAAO,EAAE,WAAW,EACP,aAAa,EAAE,MAAM,EACrC,IAAI,EAAE,sBAAsB;IAatC,MAAM,CACO,OAAO,EAAE,WAAW,EACP,aAAa,EAAE,MAAM,EAChC,EAAE,EAAE,MAAM,EACf,IAAI,EAAE,sBAAsB;IAqBhC,MAAM,CACC,OAAO,EAAE,WAAW,EACP,aAAa,EAAE,MAAM,EAChC,EAAE,EAAE,MAAM;;;;CAU1B"}
1
+ {"version":3,"file":"configurations.controller.d.ts","sourceRoot":"","sources":["../../src/configurations/configurations.controller.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAW,KAAK,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAEzE,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAC3E,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAE3E;;;;GAIG;AACH,qBAEa,wBAAwB;IACvB,OAAO,CAAC,QAAQ,CAAC,cAAc;gBAAd,cAAc,EAAE,qBAAqB;IAKlE,IAAI,CACS,OAAO,EAAE,WAAW,EACP,aAAa,EAAE,MAAM;IAS/C,+EAA+E;IAI/E,GAAG,CACU,OAAO,EAAE,WAAW,EACP,aAAa,EAAE,MAAM,EAC1B,QAAQ,EAAE,MAAM,EACtB,EAAE,EAAE,MAAM;IAsBzB,MAAM,CACO,OAAO,EAAE,WAAW,EACP,aAAa,EAAE,MAAM,EACrC,IAAI,EAAE,sBAAsB;IAatC,MAAM,CACO,OAAO,EAAE,WAAW,EACP,aAAa,EAAE,MAAM,EAC1B,QAAQ,EAAE,MAAM,EACtB,EAAE,EAAE,MAAM,EACf,IAAI,EAAE,sBAAsB;IAsBhC,MAAM,CACC,OAAO,EAAE,WAAW,EACP,aAAa,EAAE,MAAM,EAC1B,QAAQ,EAAE,MAAM,EACtB,EAAE,EAAE,MAAM;;;;CAW1B"}
@@ -19,17 +19,18 @@ let ConfigurationsController = class ConfigurationsController {
19
19
  list(session, environmentId) {
20
20
  return this.configurations.list(getActiveOrganizationId(session), session.user.id, environmentId);
21
21
  }
22
- get(session, environmentId, id) {
23
- return this.configurations.get(getActiveOrganizationId(session), session.user.id, environmentId, id);
22
+ /** The provider names the table the id lives in, so it is part of the path. */
23
+ get(session, environmentId, provider, id) {
24
+ return this.configurations.get(getActiveOrganizationId(session), session.user.id, environmentId, provider, id);
24
25
  }
25
26
  create(session, environmentId, body) {
26
27
  return this.configurations.create(getActiveOrganizationId(session), session.user.id, environmentId, body);
27
28
  }
28
- update(session, environmentId, id, body) {
29
- return this.configurations.update(getActiveOrganizationId(session), session.user.id, environmentId, id, body);
29
+ update(session, environmentId, provider, id, body) {
30
+ return this.configurations.update(getActiveOrganizationId(session), session.user.id, environmentId, provider, id, body);
30
31
  }
31
- async remove(session, environmentId, id) {
32
- await this.configurations.remove(getActiveOrganizationId(session), session.user.id, environmentId, id);
32
+ async remove(session, environmentId, provider, id) {
33
+ await this.configurations.remove(getActiveOrganizationId(session), session.user.id, environmentId, provider, id);
33
34
  return { id, deleted: true };
34
35
  }
35
36
  };
@@ -44,14 +45,15 @@ __decorate([
44
45
  __metadata("design:returntype", void 0)
45
46
  ], ConfigurationsController.prototype, "list", null);
46
47
  __decorate([
47
- Get(':id'),
48
+ Get(':provider/:id'),
48
49
  ApiOperation({ summary: 'Get one configuration' }),
49
50
  ApiNotFoundResponse({ description: 'No such configuration here.' }),
50
51
  __param(0, Session()),
51
52
  __param(1, Param('environmentId')),
52
- __param(2, Param('id')),
53
+ __param(2, Param('provider')),
54
+ __param(3, Param('id')),
53
55
  __metadata("design:type", Function),
54
- __metadata("design:paramtypes", [Object, String, String]),
56
+ __metadata("design:paramtypes", [Object, String, String, String]),
55
57
  __metadata("design:returntype", void 0)
56
58
  ], ConfigurationsController.prototype, "get", null);
57
59
  __decorate([
@@ -59,7 +61,7 @@ __decorate([
59
61
  HttpCode(HttpStatus.CREATED),
60
62
  ApiOperation({
61
63
  summary: 'Set up a provider in this environment',
62
- description: 'The integration key names an installed package; the auth type comes from it rather than from the request.',
64
+ description: 'The provider names an installed package, and its tables are where the configuration is written.',
63
65
  }),
64
66
  ApiCreatedResponse({ description: 'The created configuration.' }),
65
67
  ApiConflictResponse({
@@ -73,22 +75,23 @@ __decorate([
73
75
  __metadata("design:returntype", void 0)
74
76
  ], ConfigurationsController.prototype, "create", null);
75
77
  __decorate([
76
- Patch(':id'),
78
+ Patch(':provider/:id'),
77
79
  ApiOperation({ summary: 'Update a configuration' }),
78
80
  ApiOkResponse({ description: 'The updated configuration.' }),
79
81
  __param(0, Session()),
80
82
  __param(1, Param('environmentId')),
81
- __param(2, Param('id')),
82
- __param(3, Body()),
83
+ __param(2, Param('provider')),
84
+ __param(3, Param('id')),
85
+ __param(4, Body()),
83
86
  __metadata("design:type", Function),
84
- __metadata("design:paramtypes", [Object, String, String, UpdateConfigurationDto]),
87
+ __metadata("design:paramtypes", [Object, String, String, String, UpdateConfigurationDto]),
85
88
  __metadata("design:returntype", void 0)
86
89
  ], ConfigurationsController.prototype, "update", null);
87
90
  __decorate([
88
- Delete(':id'),
91
+ Delete(':provider/:id'),
89
92
  ApiOperation({
90
93
  summary: 'Delete a configuration',
91
- description: 'Refused while connections still use it, since nothing in the database would stop those credentials being orphaned.',
94
+ description: 'Refused while connections still use it — the foreign key would refuse it anyway, and this reports which.',
92
95
  }),
93
96
  ApiOkResponse({ description: 'The deleted configuration id.' }),
94
97
  ApiConflictResponse({
@@ -96,9 +99,10 @@ __decorate([
96
99
  }),
97
100
  __param(0, Session()),
98
101
  __param(1, Param('environmentId')),
99
- __param(2, Param('id')),
102
+ __param(2, Param('provider')),
103
+ __param(3, Param('id')),
100
104
  __metadata("design:type", Function),
101
- __metadata("design:paramtypes", [Object, String, String]),
105
+ __metadata("design:paramtypes", [Object, String, String, String]),
102
106
  __metadata("design:returntype", Promise)
103
107
  ], ConfigurationsController.prototype, "remove", null);
104
108
  ConfigurationsController = __decorate([
@@ -1 +1 @@
1
- {"version":3,"file":"configurations.module.d.ts","sourceRoot":"","sources":["../../src/configurations/configurations.module.ts"],"names":[],"mappings":"AAMA,qBAMa,oBAAoB;CAAG"}
1
+ {"version":3,"file":"configurations.module.d.ts","sourceRoot":"","sources":["../../src/configurations/configurations.module.ts"],"names":[],"mappings":"AAKA,qBAMa,oBAAoB;CAAG"}
@@ -2,7 +2,6 @@ import { __decorate } from "tslib";
2
2
  import { Module } from '@nestjs/common';
3
3
  import { EnvironmentsModule } from '../environments/environments.module.js';
4
4
  import { ConfigurationsController } from './configurations.controller.js';
5
- import { ConfigurationsRepository } from './configurations.repository.js';
6
5
  import { ConfigurationsService } from './configurations.service.js';
7
6
  let ConfigurationsModule = class ConfigurationsModule {
8
7
  };
@@ -10,7 +9,7 @@ ConfigurationsModule = __decorate([
10
9
  Module({
11
10
  imports: [EnvironmentsModule],
12
11
  controllers: [ConfigurationsController],
13
- providers: [ConfigurationsService, ConfigurationsRepository],
12
+ providers: [ConfigurationsService],
14
13
  exports: [ConfigurationsService],
15
14
  })
16
15
  ], ConfigurationsModule);
@@ -1,60 +1,48 @@
1
- import type { ResolvedKoshaConfig } from '../config/kosha-config.js';
2
1
  import { CryptoService } from '../crypto/crypto.service.js';
3
2
  import { EnvironmentsService } from '../environments/environments.service.js';
4
- import type { Configuration } from '../generated/prisma/client.js';
5
3
  import { IntegrationRegistry } from '../integrations/integration.registry.js';
6
- import { ConfigurationsRepository } from './configurations.repository.js';
4
+ import { ProviderStore, type ProviderConfiguration, type PublicProviderConfiguration } from '../integrations/provider-store.js';
7
5
  import type { CreateConfigurationDto } from './dto/create-configuration.dto.js';
8
6
  import type { UpdateConfigurationDto } from './dto/update-configuration.dto.js';
7
+ /** A configuration with the provider it belongs to named, as a client sees it. */
8
+ export type DescribedConfiguration = PublicProviderConfiguration & {
9
+ provider: string;
10
+ authType: string;
11
+ };
9
12
  /** A configuration with its secrets opened. Never leaves the server. */
10
13
  export interface ConfigurationWithCredentials {
11
- configuration: Configuration;
14
+ configuration: ProviderConfiguration;
12
15
  credentials: Record<string, unknown>;
13
16
  }
14
17
  export declare class ConfigurationsService {
15
- private readonly configurations;
18
+ private readonly store;
16
19
  private readonly environments;
17
20
  private readonly crypto;
18
21
  private readonly registry;
19
- private readonly config;
20
- constructor(configurations: ConfigurationsRepository, environments: EnvironmentsService, crypto: CryptoService, registry: IntegrationRegistry, config: ResolvedKoshaConfig);
22
+ constructor(store: ProviderStore, environments: EnvironmentsService, crypto: CryptoService, registry: IntegrationRegistry);
21
23
  /**
22
- * The redirect URI the provider must be told about. Derived from
23
- * `server.publicUrl` so it is stable and inspectable in the admin, rather
24
- * than being reconstructed per request.
24
+ * Every configuration in an environment, across every installed provider.
25
+ *
26
+ * Kosha owns no table that lists them, so this asks each provider in turn.
27
+ * An environment holds a handful, and each read is an index lookup.
25
28
  */
26
- callbackUrlFor(integrationKey: string): string;
27
- list(organizationId: string, userId: string, environmentId: string): Promise<import("./configurations.repository.js").PublicConfiguration[]>;
28
- get(organizationId: string, userId: string, environmentId: string, id: string): Promise<import("./configurations.repository.js").PublicConfiguration>;
29
- /** How a caller's slug resolves, once a key has named the environment. */
30
- getBySlug(environmentId: string, slug: string): Promise<import("./configurations.repository.js").PublicConfiguration>;
31
- create(organizationId: string, userId: string, environmentId: string, input: CreateConfigurationDto): Promise<import("./configurations.repository.js").PublicConfiguration>;
32
- update(organizationId: string, userId: string, environmentId: string, id: string, input: UpdateConfigurationDto): Promise<import("./configurations.repository.js").PublicConfiguration>;
33
- /**
34
- * Refused while credentials still point at this row. `account.providerId` is
35
- * a plain string, so nothing in the database would stop the delete from
36
- * orphaning them.
37
- */
38
- remove(organizationId: string, userId: string, environmentId: string, id: string): Promise<void>;
29
+ list(organizationId: string, userId: string, environmentId: string): Promise<DescribedConfiguration[]>;
30
+ get(organizationId: string, userId: string, environmentId: string, provider: string, id: string): Promise<DescribedConfiguration>;
31
+ create(organizationId: string, userId: string, environmentId: string, input: CreateConfigurationDto): Promise<DescribedConfiguration>;
32
+ update(organizationId: string, userId: string, environmentId: string, provider: string, id: string, input: UpdateConfigurationDto): Promise<DescribedConfiguration>;
33
+ /** Refused while connections still point at this row. */
34
+ remove(organizationId: string, userId: string, environmentId: string, provider: string, id: string): Promise<void>;
39
35
  /**
40
36
  * Opens the secret half, for the connect and proxy paths only. Never
41
37
  * reachable from a controller.
42
38
  */
43
- getWithCredentials(configurationId: string): Promise<ConfigurationWithCredentials>;
39
+ getWithCredentials(provider: string, configurationId: string): Promise<ConfigurationWithCredentials>;
44
40
  /**
45
- * What the auth type needs, encrypted as one blob rather than a column per
46
- * field — a GitHub App configuration holds an appId and a private key where
47
- * an OAuth2 one holds a client id and secret, and neither should force a
48
- * migration on the other.
41
+ * Seals the whole credential set as one blob, so the shape is the auth
42
+ * type's business rather than the schema's: an OAuth2 provider stores a
43
+ * client id and secret, and a provider whose end users bring their own key
44
+ * stores nothing at all.
49
45
  */
50
46
  private sealCredentials;
51
- /**
52
- * Checks per-organization settings against the integration's declared
53
- * `configFields`, and any scopes against what the provider actually offers.
54
- * Integrations describe their settings as data so the admin can render a
55
- * form; the same description is what validates here.
56
- */
57
- private validateSettings;
58
- private validateScopes;
59
47
  }
60
48
  //# sourceMappingURL=configurations.service.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"configurations.service.d.ts","sourceRoot":"","sources":["../../src/configurations/configurations.service.ts"],"names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aAAa,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IAS7C,MAAM,CACV,cAAc,EAAE,MAAM,EACtB,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,MAAM,EACrB,KAAK,EAAE,sBAAsB;IAyCzB,MAAM,CACV,cAAc,EAAE,MAAM,EACtB,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,MAAM,EACrB,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,sBAAsB;IAkB/B;;;;OAIG;IACG,MAAM,CACV,cAAc,EAAE,MAAM,EACtB,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,MAAM,EACrB,EAAE,EAAE,MAAM;IAcZ;;;OAGG;IACG,kBAAkB,CACtB,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,4BAA4B,CAAC;IAgBxC;;;;;OAKG;IACH,OAAO,CAAC,eAAe;IAsBvB;;;;;OAKG;IACH,OAAO,CAAC,gBAAgB;IA4CxB,OAAO,CAAC,cAAc;CAkBvB"}
1
+ {"version":3,"file":"configurations.service.d.ts","sourceRoot":"","sources":["../../src/configurations/configurations.service.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAC9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAC9E,OAAO,EACL,aAAa,EACb,KAAK,qBAAqB,EAC1B,KAAK,2BAA2B,EACjC,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAChF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAEhF,kFAAkF;AAClF,MAAM,MAAM,sBAAsB,GAAG,2BAA2B,GAAG;IACjE,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,wEAAwE;AACxE,MAAM,W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tB,QAAQ,EAAE,MAAM,EAChB,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,4BAA4B,CAAC;IAmBxC;;;;;OAKG;IACH,OAAO,CAAC,eAAe;CAqBxB"}
@@ -1,106 +1,91 @@
1
- import { __decorate, __metadata, __param } from "tslib";
2
- import { BadRequestException, ConflictException, Inject, Injectable, NotFoundException, } from '@nestjs/common';
3
- import { KOSHA_CONFIG } from '../config/tokens.js';
1
+ import { __decorate, __metadata } from "tslib";
2
+ import { BadRequestException, ConflictException, Injectable, NotFoundException, } from '@nestjs/common';
4
3
  import { CryptoService } from '../crypto/crypto.service.js';
5
4
  import { EnvironmentsService } from '../environments/environments.service.js';
6
5
  import { IntegrationRegistry } from '../integrations/integration.registry.js';
7
- import { ConfigurationsRepository } from './configurations.repository.js';
6
+ import { ProviderStore, } from '../integrations/provider-store.js';
8
7
  let ConfigurationsService = class ConfigurationsService {
9
- configurations;
8
+ store;
10
9
  environments;
11
10
  crypto;
12
11
  registry;
13
- config;
14
- constructor(configurations, environments, crypto, registry, config) {
15
- this.configurations = configurations;
12
+ constructor(store, environments, crypto, registry) {
13
+ this.store = store;
16
14
  this.environments = environments;
17
15
  this.crypto = crypto;
18
16
  this.registry = registry;
19
- this.config = config;
20
17
  }
21
18
  /**
22
- * The redirect URI the provider must be told about. Derived from
23
- * `server.publicUrl` so it is stable and inspectable in the admin, rather
24
- * than being reconstructed per request.
19
+ * Every configuration in an environment, across every installed provider.
20
+ *
21
+ * Kosha owns no table that lists them, so this asks each provider in turn.
22
+ * An environment holds a handful, and each read is an index lookup.
25
23
  */
26
- callbackUrlFor(integrationKey) {
27
- const { publicUrl, globalPrefix } = this.config.server;
28
- return `${publicUrl}/${globalPrefix}/connect/callback/${integrationKey}`;
29
- }
30
24
  async list(organizationId, userId, environmentId) {
31
25
  await this.environments.getForMember(organizationId, userId, environmentId);
32
- return this.configurations.findManyByEnvironment(environmentId);
26
+ const perProvider = await Promise.all(this.registry.list().map(async (integration) => {
27
+ const rows = await this.store.listConfigurations(integration, environmentId);
28
+ return rows.map((row) => describe(row, integration));
29
+ }));
30
+ return perProvider
31
+ .flat()
32
+ .sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
33
33
  }
34
- async get(organizationId, userId, environmentId, id) {
34
+ async get(organizationId, userId, environmentId, provider, id) {
35
35
  await this.environments.getForMember(organizationId, userId, environmentId);
36
- const configuration = await this.configurations.findById(environmentId, id);
37
- if (!configuration)
38
- throw new NotFoundException('Configuration not found');
39
- return configuration;
40
- }
41
- /** How a caller's slug resolves, once a key has named the environment. */
42
- async getBySlug(environmentId, slug) {
43
- const configuration = await this.configurations.findBySlug(environmentId, slug);
36
+ const integration = this.registry.get(provider);
37
+ const configuration = await this.store.findConfigurationById(integration, environmentId, id);
44
38
  if (!configuration)
45
39
  throw new NotFoundException('Configuration not found');
46
- return configuration;
40
+ return describe(configuration, integration);
47
41
  }
48
42
  async create(organizationId, userId, environmentId, input) {
49
43
  await this.environments.getForMember(organizationId, userId, environmentId);
50
- // The registry is the authority on what Kosha can talk to, and on which
51
- // auth type this integration uses. There is no provider table to consult.
52
- const integration = this.registry.get(input.integrationKey);
44
+ // The registry is the authority on what Kosha can talk to. There is no
45
+ // provider table to consult.
46
+ const integration = this.registry.get(input.provider);
53
47
  const name = input.name.trim();
54
48
  const slug = slugify(input.slug ?? name);
55
49
  if (!slug) {
56
50
  throw new BadRequestException('slug must contain at least one letter or digit');
57
51
  }
58
- if (await this.configurations.findBySlug(environmentId, slug)) {
59
- throw new ConflictException(`A configuration with slug "${slug}" already exists in this environment`);
52
+ // Read first: the unique index is per provider, so this is the only place
53
+ // a clash can be reported against the slug the caller actually sent.
54
+ const clash = await this.store.findConfigurationBySlug(integration, environmentId, slug);
55
+ if (clash) {
56
+ throw new ConflictException(`A ${integration.key} configuration with slug "${slug}" already exists in this environment`);
60
57
  }
61
- const settings = this.validateSettings(input.integrationKey, input.settings);
62
- return this.configurations.create({
58
+ const created = await this.store.createConfiguration(integration, {
63
59
  environmentId,
64
- integrationKey: integration.key,
65
- authType: integration.auth.type,
66
60
  name,
67
61
  slug,
68
- credentials: this.sealCredentials(input.integrationKey, input.credentials),
69
- settings: toJsonInput(settings),
62
+ credentials: this.sealCredentials(integration, input.credentials),
70
63
  });
64
+ return describe(created, integration);
71
65
  }
72
- async update(organizationId, userId, environmentId, id, input) {
73
- const existing = await this.get(organizationId, userId, environmentId, id);
74
- return this.configurations.update(id, {
66
+ async update(organizationId, userId, environmentId, provider, id, input) {
67
+ await this.get(organizationId, userId, environmentId, provider, id);
68
+ const integration = this.registry.get(provider);
69
+ const updated = await this.store.updateConfiguration(integration, id, {
75
70
  name: input.name?.trim(),
76
71
  credentials: input.credentials
77
- ? this.sealCredentials(existing.integrationKey, input.credentials)
72
+ ? this.sealCredentials(integration, input.credentials)
78
73
  : undefined,
79
- settings: input.settings
80
- ? toJsonInput(this.validateSettings(existing.integrationKey, input.settings))
81
- : undefined,
82
- isEnabled: input.isEnabled,
83
74
  });
75
+ return describe(updated, integration);
84
76
  }
85
- /**
86
- * Refused while credentials still point at this row. `account.providerId` is
87
- * a plain string, so nothing in the database would stop the delete from
88
- * orphaning them.
89
- */
90
- async remove(organizationId, userId, environmentId, id) {
91
- await this.get(organizationId, userId, environmentId, id);
92
- const credentials = await this.configurations.countCredentials(id);
93
- if (credentials > 0) {
94
- throw new ConflictException(`${credentials} connection(s) still use this configuration. Disconnect them first.`);
95
- }
96
- await this.configurations.delete(id);
77
+ /** Refused while connections still point at this row. */
78
+ async remove(organizationId, userId, environmentId, provider, id) {
79
+ await this.get(organizationId, userId, environmentId, provider, id);
80
+ await this.store.deleteConfiguration(this.registry.get(provider), id);
97
81
  }
98
82
  /**
99
83
  * Opens the secret half, for the connect and proxy paths only. Never
100
84
  * reachable from a controller.
101
85
  */
102
- async getWithCredentials(configurationId) {
103
- const configuration = await this.configurations.findAnyById(configurationId);
86
+ async getWithCredentials(provider, configurationId) {
87
+ const integration = this.registry.get(provider);
88
+ const configuration = await this.store.findConfigurationWithCredentials(integration, configurationId);
104
89
  if (!configuration)
105
90
  throw new NotFoundException('Configuration not found');
106
91
  return {
@@ -111,114 +96,49 @@ let ConfigurationsService = class ConfigurationsService {
111
96
  };
112
97
  }
113
98
  /**
114
- * What the auth type needs, encrypted as one blob rather than a column per
115
- * field — a GitHub App configuration holds an appId and a private key where
116
- * an OAuth2 one holds a client id and secret, and neither should force a
117
- * migration on the other.
99
+ * Seals the whole credential set as one blob, so the shape is the auth
100
+ * type's business rather than the schema's: an OAuth2 provider stores a
101
+ * client id and secret, and a provider whose end users bring their own key
102
+ * stores nothing at all.
118
103
  */
119
- sealCredentials(integrationKey, credentials) {
120
- const integration = this.registry.get(integrationKey);
104
+ sealCredentials(integration, credentials) {
121
105
  const provided = credentials ?? {};
122
106
  if (integration.auth.type === 'OAUTH2') {
123
- const missing = ['clientId', 'clientSecret'].filter((field) => typeof provided[field] !== 'string' || !provided[field]);
107
+ const missing = ['clientId', 'clientSecret'].filter((key) => !provided[key]);
124
108
  if (missing.length > 0) {
125
- throw new BadRequestException(`${integrationKey} is an OAuth2 integration and needs ${missing.join(' and ')}`);
109
+ throw new BadRequestException(`${integration.key} is an OAuth2 integration and needs ${missing.join(' and ')}`);
126
110
  }
127
111
  }
128
- if (Object.keys(provided).length === 0)
129
- return null;
130
- return this.crypto.encrypt(JSON.stringify(provided));
131
- }
132
- /**
133
- * Checks per-organization settings against the integration's declared
134
- * `configFields`, and any scopes against what the provider actually offers.
135
- * Integrations describe their settings as data so the admin can render a
136
- * form; the same description is what validates here.
137
- */
138
- validateSettings(integrationKey, settings) {
139
- const integration = this.registry.get(integrationKey);
140
- const fields = integration.configFields ?? [];
141
- if (!settings && fields.length === 0)
142
- return undefined;
143
- const provided = { ...(settings ?? {}) };
144
- const problems = [];
145
- if ('scopes' in provided) {
146
- provided['scopes'] = this.validateScopes(integrationKey, provided['scopes']);
147
- }
148
- const known = new Map(fields.map((field) => [field.key, field]));
149
- for (const key of Object.keys(provided)) {
150
- if (key !== 'scopes' && !known.has(key)) {
151
- problems.push(`unknown setting "${key}"`);
152
- }
153
- }
154
- for (const field of fields) {
155
- const value = provided[field.key];
156
- if (value === undefined || value === null || value === '') {
157
- if (field.required)
158
- problems.push(`"${field.key}" is required`);
159
- continue;
160
- }
161
- problems.push(...describeTypeMismatch(field, value));
162
- }
163
- if (problems.length > 0) {
164
- throw new BadRequestException(`Invalid settings for ${integrationKey}: ${problems.join('; ')}`);
165
- }
166
- return provided;
167
- }
168
- validateScopes(integrationKey, scopes) {
169
- if (!Array.isArray(scopes) || scopes.some((s) => typeof s !== 'string')) {
170
- throw new BadRequestException('scopes must be an array of strings');
171
- }
172
- const available = new Set(this.registry.get(integrationKey).auth.scopesAvailable);
173
- const unknown = scopes.filter((scope) => !available.has(scope));
174
- if (unknown.length > 0) {
175
- throw new BadRequestException(`Unknown scope(s) for ${integrationKey}: ${unknown.join(', ')}. Available: ${[...available].join(', ')}`);
176
- }
177
- return [...new Set(scopes)];
112
+ return Object.keys(provided).length > 0
113
+ ? this.crypto.encrypt(JSON.stringify(provided))
114
+ : null;
178
115
  }
179
116
  };
180
117
  ConfigurationsService = __decorate([
181
118
  Injectable(),
182
- __param(4, Inject(KOSHA_CONFIG)),
183
- __metadata("design:paramtypes", [ConfigurationsRepository,
119
+ __metadata("design:paramtypes", [ProviderStore,
184
120
  EnvironmentsService,
185
121
  CryptoService,
186
- IntegrationRegistry, Object])
122
+ IntegrationRegistry])
187
123
  ], ConfigurationsService);
188
124
  export { ConfigurationsService };
189
- /** Lowercase, digits and single dashes. Empty if the input has no word chars. */
125
+ /**
126
+ * The provider and its auth type come from the registry rather than from the
127
+ * row: both are facts about the installed package, and a copy in the database
128
+ * would be one more thing to keep in step.
129
+ */
130
+ function describe(configuration, integration) {
131
+ return {
132
+ ...configuration,
133
+ provider: integration.key,
134
+ authType: integration.auth.type,
135
+ };
136
+ }
137
+ /** The handle a caller quotes in a proxy URL, so it has to be URL-safe. */
190
138
  function slugify(value) {
191
139
  return value
192
140
  .toLowerCase()
141
+ .trim()
193
142
  .replace(/[^a-z0-9]+/g, '-')
194
143
  .replace(/^-+|-+$/g, '');
195
144
  }
196
- function describeTypeMismatch(field, value) {
197
- switch (field.type) {
198
- case 'number':
199
- return typeof value === 'number' && Number.isFinite(value)
200
- ? []
201
- : [`"${field.key}" must be a number`];
202
- case 'boolean':
203
- return typeof value === 'boolean'
204
- ? []
205
- : [`"${field.key}" must be a boolean`];
206
- case 'select': {
207
- const allowed = (field.options ?? []).map((option) => option.value);
208
- return allowed.includes(String(value))
209
- ? []
210
- : [`"${field.key}" must be one of: ${allowed.join(', ')}`];
211
- }
212
- default:
213
- return typeof value === 'string'
214
- ? []
215
- : [`"${field.key}" must be a string`];
216
- }
217
- }
218
- /**
219
- * Prisma's Json input type does not accept a plain index signature, so the
220
- * validated settings object is narrowed at the persistence boundary only.
221
- */
222
- function toJsonInput(value) {
223
- return value;
224
- }
@@ -1,8 +1,7 @@
1
1
  export declare class CreateConfigurationDto {
2
- integrationKey: string;
2
+ provider: string;
3
3
  name: string;
4
4
  slug?: string;
5
5
  credentials?: Record<string, unknown>;
6
- settings?: Record<string, unknown>;
7
6
  }
8
7
  //# sourceMappingURL=create-configuration.dto.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"create-configuration.dto.d.ts","sourceRoot":"","sources":["../../../src/configurations/dto/create-configuration.dto.ts"],"names":[],"mappings":"AASA,qBAAa,sBAAsB;IAQjC,cAAc,EAAG,MAAM,CAAC;IAMxB,IAAI,EAAG,MAAM,CAAC;IAUd,IAAI,CAAC,EAAE,MAAM,CAAC;IASd,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAStC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC"}
1
+ {"version":3,"file":"create-configuration.dto.d.ts","sourceRoot":"","sources":["../../../src/configurations/dto/create-configuration.dto.ts"],"names":[],"mappings":"AASA,qBAAa,sBAAsB;IAQjC,QAAQ,EAAG,MAAM,CAAC;IAMlB,IAAI,EAAG,MAAM,CAAC;IAUd,IAAI,CAAC,EAAE,MAAM,CAAC;IASd,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACvC"}
@@ -2,11 +2,10 @@ import { __decorate, __metadata } from "tslib";
2
2
  import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
3
3
  import { IsObject, IsOptional, IsString, MaxLength, MinLength, } from 'class-validator';
4
4
  export class CreateConfigurationDto {
5
- integrationKey;
5
+ provider;
6
6
  name;
7
7
  slug;
8
8
  credentials;
9
- settings;
10
9
  }
11
10
  __decorate([
12
11
  ApiProperty({
@@ -16,7 +15,7 @@ __decorate([
16
15
  IsString(),
17
16
  MinLength(1),
18
17
  __metadata("design:type", String)
19
- ], CreateConfigurationDto.prototype, "integrationKey", void 0);
18
+ ], CreateConfigurationDto.prototype, "provider", void 0);
20
19
  __decorate([
21
20
  ApiProperty({ example: 'GitHub' }),
22
21
  IsString(),
@@ -43,12 +42,3 @@ __decorate([
43
42
  IsObject(),
44
43
  __metadata("design:type", Object)
45
44
  ], CreateConfigurationDto.prototype, "credentials", void 0);
46
- __decorate([
47
- ApiPropertyOptional({
48
- description: 'Non-secret half: scopes, and whatever the integration declares as configFields.',
49
- example: { scopes: ['repo', 'read:user'] },
50
- }),
51
- IsOptional(),
52
- IsObject(),
53
- __metadata("design:type", Object)
54
- ], CreateConfigurationDto.prototype, "settings", void 0);
@@ -1,7 +1,5 @@
1
1
  export declare class UpdateConfigurationDto {
2
2
  name?: string;
3
3
  credentials?: Record<string, unknown>;
4
- settings?: Record<string, unknown>;
5
- isEnabled?: boolean;
6
4
  }
7
5
  //# sourceMappingURL=update-configuration.dto.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"update-configuration.dto.d.ts","sourceRoot":"","sources":["../../../src/configurations/dto/update-configuration.dto.ts"],"names":[],"mappings":"AAUA,qBAAa,sBAAsB;IAMjC,IAAI,CAAC,EAAE,MAAM,CAAC;IAOd,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAKtC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAOnC,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB"}
1
+ {"version":3,"file":"update-configuration.dto.d.ts","sourceRoot":"","sources":["../../../src/configurations/dto/update-configuration.dto.ts"],"names":[],"mappings":"AASA,qBAAa,sBAAsB;IAMjC,IAAI,CAAC,EAAE,MAAM,CAAC;IAOd,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACvC"}