@kosha-ai/server 0.2.0 → 0.4.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 (125) 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 +29 -35
  9. package/dist/configurations/configurations.service.d.ts.map +1 -1
  10. package/dist/configurations/configurations.service.js +126 -149
  11. package/dist/configurations/dto/create-configuration.dto.d.ts +2 -2
  12. package/dist/configurations/dto/create-configuration.dto.d.ts.map +1 -1
  13. package/dist/configurations/dto/create-configuration.dto.js +6 -6
  14. package/dist/configurations/dto/update-configuration.dto.d.ts +1 -2
  15. package/dist/configurations/dto/update-configuration.dto.d.ts.map +1 -1
  16. package/dist/configurations/dto/update-configuration.dto.js +7 -13
  17. package/dist/connect/connect.controller.d.ts +12 -2
  18. package/dist/connect/connect.controller.d.ts.map +1 -1
  19. package/dist/connect/connect.controller.js +108 -18
  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 +34 -25
  23. package/dist/connect/connect.repository.d.ts.map +1 -1
  24. package/dist/connect/connect.repository.js +45 -52
  25. package/dist/connect/connect.service.d.ts +54 -8
  26. package/dist/connect/connect.service.d.ts.map +1 -1
  27. package/dist/connect/connect.service.js +312 -68
  28. package/dist/connect/dto/connect-credential.dto.d.ts +8 -0
  29. package/dist/connect/dto/connect-credential.dto.d.ts.map +1 -0
  30. package/dist/connect/dto/connect-credential.dto.js +54 -0
  31. package/dist/connect/dto/create-connect-session.dto.d.ts +1 -1
  32. package/dist/connect/dto/create-connect-session.dto.d.ts.map +1 -1
  33. package/dist/connect/dto/create-connect-session.dto.js +7 -8
  34. package/dist/connect/dto/create-test-session.dto.d.ts +8 -0
  35. package/dist/connect/dto/create-test-session.dto.d.ts.map +1 -1
  36. package/dist/connect/dto/create-test-session.dto.js +45 -3
  37. package/dist/connections/connections.controller.d.ts +4 -3
  38. package/dist/connections/connections.controller.d.ts.map +1 -1
  39. package/dist/connections/connections.controller.js +13 -11
  40. package/dist/connections/connections.repository.d.ts +24 -17
  41. package/dist/connections/connections.repository.d.ts.map +1 -1
  42. package/dist/connections/connections.repository.js +21 -43
  43. package/dist/connections/connections.service.d.ts +48 -13
  44. package/dist/connections/connections.service.d.ts.map +1 -1
  45. package/dist/connections/connections.service.js +111 -32
  46. package/dist/connections/dto/list-connections.dto.d.ts +3 -1
  47. package/dist/connections/dto/list-connections.dto.d.ts.map +1 -1
  48. package/dist/connections/dto/list-connections.dto.js +26 -4
  49. package/dist/connections/environment-connections.controller.d.ts +4 -3
  50. package/dist/connections/environment-connections.controller.d.ts.map +1 -1
  51. package/dist/connections/environment-connections.controller.js +14 -12
  52. package/dist/credentials/credentials.module.d.ts.map +1 -1
  53. package/dist/credentials/credentials.module.js +0 -2
  54. package/dist/credentials/credentials.repository.d.ts +5 -2
  55. package/dist/credentials/credentials.repository.d.ts.map +1 -1
  56. package/dist/credentials/credentials.repository.js +10 -3
  57. package/dist/credentials/credentials.service.d.ts +14 -4
  58. package/dist/credentials/credentials.service.d.ts.map +1 -1
  59. package/dist/credentials/credentials.service.js +106 -30
  60. package/dist/crypto/credential-envelope.d.ts +27 -1
  61. package/dist/crypto/credential-envelope.d.ts.map +1 -1
  62. package/dist/crypto/credential-envelope.js +43 -0
  63. package/dist/egress/egress.listener.d.ts +1 -3
  64. package/dist/egress/egress.listener.d.ts.map +1 -1
  65. package/dist/egress/egress.listener.js +3 -7
  66. package/dist/egress/egress.repository.d.ts +13 -6
  67. package/dist/egress/egress.repository.d.ts.map +1 -1
  68. package/dist/egress/egress.repository.js +31 -44
  69. package/dist/generated/prisma/browser.d.ts +0 -5
  70. package/dist/generated/prisma/browser.d.ts.map +1 -1
  71. package/dist/generated/prisma/client.d.ts +0 -5
  72. package/dist/generated/prisma/client.d.ts.map +1 -1
  73. package/dist/generated/prisma/commonInputTypes.d.ts +0 -55
  74. package/dist/generated/prisma/commonInputTypes.d.ts.map +1 -1
  75. package/dist/generated/prisma/internal/class.d.ts +0 -11
  76. package/dist/generated/prisma/internal/class.d.ts.map +1 -1
  77. package/dist/generated/prisma/internal/class.js +4 -4
  78. package/dist/generated/prisma/internal/prismaNamespace.d.ts +1 -114
  79. package/dist/generated/prisma/internal/prismaNamespace.d.ts.map +1 -1
  80. package/dist/generated/prisma/internal/prismaNamespace.js +2 -29
  81. package/dist/generated/prisma/internal/prismaNamespaceBrowser.d.ts +0 -30
  82. package/dist/generated/prisma/internal/prismaNamespaceBrowser.d.ts.map +1 -1
  83. package/dist/generated/prisma/internal/prismaNamespaceBrowser.js +2 -29
  84. package/dist/generated/prisma/models/Account.d.ts +26 -344
  85. package/dist/generated/prisma/models/Account.d.ts.map +1 -1
  86. package/dist/generated/prisma/models/Environment.d.ts +0 -258
  87. package/dist/generated/prisma/models/Environment.d.ts.map +1 -1
  88. package/dist/generated/prisma/models/User.d.ts +2 -60
  89. package/dist/generated/prisma/models/User.d.ts.map +1 -1
  90. package/dist/generated/prisma/models.d.ts +0 -1
  91. package/dist/generated/prisma/models.d.ts.map +1 -1
  92. package/dist/index.d.ts +1 -2
  93. package/dist/index.d.ts.map +1 -1
  94. package/dist/integrations/client-context.d.ts +20 -0
  95. package/dist/integrations/client-context.d.ts.map +1 -0
  96. package/dist/integrations/client-context.js +23 -0
  97. package/dist/integrations/integrations.controller.d.ts +6 -0
  98. package/dist/integrations/integrations.controller.d.ts.map +1 -1
  99. package/dist/integrations/integrations.controller.js +3 -0
  100. package/dist/integrations/integrations.module.d.ts.map +1 -1
  101. package/dist/integrations/integrations.module.js +3 -1
  102. package/dist/integrations/provider-store.d.ts +110 -0
  103. package/dist/integrations/provider-store.d.ts.map +1 -0
  104. package/dist/integrations/provider-store.js +302 -0
  105. package/dist/proxy/proxy.controller.d.ts +17 -5
  106. package/dist/proxy/proxy.controller.d.ts.map +1 -1
  107. package/dist/proxy/proxy.controller.js +46 -17
  108. package/dist/proxy/proxy.module.d.ts.map +1 -1
  109. package/dist/proxy/proxy.module.js +1 -2
  110. package/dist/proxy/proxy.repository.d.ts +11 -14
  111. package/dist/proxy/proxy.repository.d.ts.map +1 -1
  112. package/dist/proxy/proxy.repository.js +17 -27
  113. package/dist/proxy/proxy.service.d.ts +6 -8
  114. package/dist/proxy/proxy.service.d.ts.map +1 -1
  115. package/dist/proxy/proxy.service.js +72 -31
  116. package/package.json +4 -4
  117. package/prisma/migrations/{20260929101936_init → 20261008090000_init}/migration.sql +5 -58
  118. package/prisma/schema.prisma +2 -43
  119. package/dist/configurations/configurations.repository.d.ts +0 -43
  120. package/dist/configurations/configurations.repository.d.ts.map +0 -1
  121. package/dist/configurations/configurations.repository.js +0 -76
  122. package/dist/generated/prisma/models/Configuration.d.ts +0 -1385
  123. package/dist/generated/prisma/models/Configuration.d.ts.map +0 -1
  124. package/dist/generated/prisma/models/Configuration.js +0 -1
  125. package/prisma/migrations/20260930102529_connection_config/migration.sql +0 -2
@@ -1,106 +1,94 @@
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';
3
+ import { assertPublicUrl } from '@kosha-ai/integration-sdk';
4
4
  import { CryptoService } from '../crypto/crypto.service.js';
5
5
  import { EnvironmentsService } from '../environments/environments.service.js';
6
6
  import { IntegrationRegistry } from '../integrations/integration.registry.js';
7
- import { ConfigurationsRepository } from './configurations.repository.js';
7
+ import { ProviderStore, } from '../integrations/provider-store.js';
8
8
  let ConfigurationsService = class ConfigurationsService {
9
- configurations;
9
+ store;
10
10
  environments;
11
11
  crypto;
12
12
  registry;
13
- config;
14
- constructor(configurations, environments, crypto, registry, config) {
15
- this.configurations = configurations;
13
+ constructor(store, environments, crypto, registry) {
14
+ this.store = store;
16
15
  this.environments = environments;
17
16
  this.crypto = crypto;
18
17
  this.registry = registry;
19
- this.config = config;
20
18
  }
21
19
  /**
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.
20
+ * Every configuration in an environment, across every installed provider.
21
+ *
22
+ * Kosha owns no table that lists them, so this asks each provider in turn.
23
+ * An environment holds a handful, and each read is an index lookup.
25
24
  */
26
- callbackUrlFor(integrationKey) {
27
- const { publicUrl, globalPrefix } = this.config.server;
28
- return `${publicUrl}/${globalPrefix}/connect/callback/${integrationKey}`;
29
- }
30
25
  async list(organizationId, userId, environmentId) {
31
26
  await this.environments.getForMember(organizationId, userId, environmentId);
32
- return this.configurations.findManyByEnvironment(environmentId);
27
+ const perProvider = await Promise.all(this.registry.list().map(async (integration) => {
28
+ const rows = await this.store.listConfigurations(integration, environmentId);
29
+ return rows.map((row) => describe(row, integration));
30
+ }));
31
+ return perProvider
32
+ .flat()
33
+ .sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
33
34
  }
34
- async get(organizationId, userId, environmentId, id) {
35
+ async get(organizationId, userId, environmentId, provider, id) {
35
36
  await this.environments.getForMember(organizationId, userId, environmentId);
36
- const configuration = await this.configurations.findById(environmentId, id);
37
+ const integration = this.registry.get(provider);
38
+ const configuration = await this.store.findConfigurationById(integration, environmentId, id);
37
39
  if (!configuration)
38
40
  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);
44
- if (!configuration)
45
- throw new NotFoundException('Configuration not found');
46
- return configuration;
41
+ return describe(configuration, integration);
47
42
  }
48
43
  async create(organizationId, userId, environmentId, input) {
49
44
  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);
45
+ // The registry is the authority on what Kosha can talk to. There is no
46
+ // provider table to consult.
47
+ const integration = this.registry.get(input.provider);
53
48
  const name = input.name.trim();
54
49
  const slug = slugify(input.slug ?? name);
55
50
  if (!slug) {
56
51
  throw new BadRequestException('slug must contain at least one letter or digit');
57
52
  }
58
- if (await this.configurations.findBySlug(environmentId, slug)) {
59
- throw new ConflictException(`A configuration with slug "${slug}" already exists in this environment`);
53
+ // Read first: the unique index is per provider, so this is the only place
54
+ // a clash can be reported against the slug the caller actually sent.
55
+ const clash = await this.store.findConfigurationBySlug(integration, environmentId, slug);
56
+ if (clash) {
57
+ throw new ConflictException(`A ${integration.key} configuration with slug "${slug}" already exists in this environment`);
60
58
  }
61
- const settings = this.validateSettings(input.integrationKey, input.settings);
62
- return this.configurations.create({
59
+ const created = await this.store.createConfiguration(integration, {
63
60
  environmentId,
64
- integrationKey: integration.key,
65
- authType: integration.auth.type,
66
61
  name,
67
62
  slug,
68
- credentials: this.sealCredentials(input.integrationKey, input.credentials),
69
- settings: toJsonInput(settings),
63
+ fields: await this.checkedFields(integration, declaredFields(integration, input.fields, { required: true })),
64
+ credentials: this.sealCredentials(integration, input.credentials),
70
65
  });
66
+ return describe(created, integration);
71
67
  }
72
- async update(organizationId, userId, environmentId, id, input) {
73
- const existing = await this.get(organizationId, userId, environmentId, id);
74
- return this.configurations.update(id, {
68
+ async update(organizationId, userId, environmentId, provider, id, input) {
69
+ await this.get(organizationId, userId, environmentId, provider, id);
70
+ const integration = this.registry.get(provider);
71
+ const updated = await this.store.updateConfiguration(integration, id, {
75
72
  name: input.name?.trim(),
73
+ fields: await this.checkedFields(integration, declaredFields(integration, input.fields)),
76
74
  credentials: input.credentials
77
- ? this.sealCredentials(existing.integrationKey, input.credentials)
78
- : undefined,
79
- settings: input.settings
80
- ? toJsonInput(this.validateSettings(existing.integrationKey, input.settings))
75
+ ? this.sealCredentials(integration, input.credentials)
81
76
  : undefined,
82
- isEnabled: input.isEnabled,
83
77
  });
78
+ return describe(updated, integration);
84
79
  }
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);
80
+ /** Refused while connections still point at this row. */
81
+ async remove(organizationId, userId, environmentId, provider, id) {
82
+ await this.get(organizationId, userId, environmentId, provider, id);
83
+ await this.store.deleteConfiguration(this.registry.get(provider), id);
97
84
  }
98
85
  /**
99
86
  * Opens the secret half, for the connect and proxy paths only. Never
100
87
  * reachable from a controller.
101
88
  */
102
- async getWithCredentials(configurationId) {
103
- const configuration = await this.configurations.findAnyById(configurationId);
89
+ async getWithCredentials(provider, configurationId) {
90
+ const integration = this.registry.get(provider);
91
+ const configuration = await this.store.findConfigurationWithCredentials(integration, configurationId);
104
92
  if (!configuration)
105
93
  throw new NotFoundException('Configuration not found');
106
94
  return {
@@ -111,114 +99,103 @@ let ConfigurationsService = class ConfigurationsService {
111
99
  };
112
100
  }
113
101
  /**
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.
102
+ * Refuses a URL the server would later be made to fetch from inside its own
103
+ * network. Checked when saved so an operator sees why, and again on every
104
+ * proxied call, since what a hostname resolves to can change.
118
105
  */
119
- sealCredentials(integrationKey, credentials) {
120
- const integration = this.registry.get(integrationKey);
121
- const provided = credentials ?? {};
122
- if (integration.auth.type === 'OAUTH2') {
123
- const missing = ['clientId', 'clientSecret'].filter((field) => typeof provided[field] !== 'string' || !provided[field]);
124
- if (missing.length > 0) {
125
- throw new BadRequestException(`${integrationKey} is an OAuth2 integration and needs ${missing.join(' and ')}`);
106
+ async checkedFields(integration, fields) {
107
+ for (const field of integration.configFields ?? []) {
108
+ const value = fields?.[field.key];
109
+ if (field.type !== 'url' || typeof value !== 'string')
110
+ continue;
111
+ try {
112
+ await assertPublicUrl(value);
113
+ }
114
+ catch (error) {
115
+ throw new BadRequestException(error instanceof Error ? error.message : `${field.label} is invalid`);
126
116
  }
127
117
  }
128
- if (Object.keys(provided).length === 0)
129
- return null;
130
- return this.crypto.encrypt(JSON.stringify(provided));
118
+ return fields;
131
119
  }
132
120
  /**
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.
121
+ * Seals the whole credential set as one blob, so the shape is the auth
122
+ * type's business rather than the schema's: an OAuth2 provider stores a
123
+ * client id and secret, and a provider whose end users bring their own key
124
+ * stores nothing at all.
137
125
  */
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;
126
+ sealCredentials(integration, credentials) {
127
+ const provided = credentials ?? {};
128
+ // False for a provider with no fixed OAuth app to register — e.g. one
129
+ // that discovers its client dynamically per configuration — so there is
130
+ // nothing here for an operator to supply.
131
+ if (integration.auth.type === 'OAUTH2' &&
132
+ integration.auth.requiresClientCredentials !== false) {
133
+ const missing = ['clientId', 'clientSecret'].filter((key) => !provided[key]);
134
+ if (missing.length > 0) {
135
+ throw new BadRequestException(`${integration.key} is an OAuth2 integration and needs ${missing.join(' and ')}`);
160
136
  }
161
- problems.push(...describeTypeMismatch(field, value));
162
- }
163
- if (problems.length > 0) {
164
- throw new BadRequestException(`Invalid settings for ${integrationKey}: ${problems.join('; ')}`);
165
137
  }
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)];
138
+ return Object.keys(provided).length > 0
139
+ ? this.crypto.encrypt(JSON.stringify(provided))
140
+ : null;
178
141
  }
179
142
  };
180
143
  ConfigurationsService = __decorate([
181
144
  Injectable(),
182
- __param(4, Inject(KOSHA_CONFIG)),
183
- __metadata("design:paramtypes", [ConfigurationsRepository,
145
+ __metadata("design:paramtypes", [ProviderStore,
184
146
  EnvironmentsService,
185
147
  CryptoService,
186
- IntegrationRegistry, Object])
148
+ IntegrationRegistry])
187
149
  ], ConfigurationsService);
188
150
  export { ConfigurationsService };
189
- /** Lowercase, digits and single dashes. Empty if the input has no word chars. */
190
- function slugify(value) {
191
- return value
192
- .toLowerCase()
193
- .replace(/[^a-z0-9]+/g, '-')
194
- .replace(/^-+|-+$/g, '');
195
- }
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(', ')}`];
151
+ /**
152
+ * The values an operator supplied, checked against what the package declared.
153
+ *
154
+ * A key the package never declared is refused rather than ignored: it would
155
+ * otherwise name a column that does not exist, and the failure would surface
156
+ * as a driver error on insert.
157
+ */
158
+ function declaredFields(integration, supplied, options = {}) {
159
+ const declared = integration.configFields ?? [];
160
+ if (declared.length === 0 && !supplied)
161
+ return undefined;
162
+ const known = new Set(declared.map((field) => field.key));
163
+ const unknown = Object.keys(supplied ?? {}).filter((key) => !known.has(key));
164
+ if (unknown.length > 0) {
165
+ throw new BadRequestException(`${integration.key} declares no field named ${unknown.join(' or ')}`);
166
+ }
167
+ const fields = {};
168
+ for (const field of declared) {
169
+ const value = supplied?.[field.key];
170
+ if (value === undefined || value === '') {
171
+ // On create a required field must be there; on update, absent means
172
+ // "leave what is stored".
173
+ if (options.required && field.required) {
174
+ throw new BadRequestException(`${field.label} is required`);
175
+ }
176
+ continue;
211
177
  }
212
- default:
213
- return typeof value === 'string'
214
- ? []
215
- : [`"${field.key}" must be a string`];
178
+ fields[field.key] = value;
216
179
  }
180
+ return Object.keys(fields).length > 0 ? fields : undefined;
217
181
  }
218
182
  /**
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.
183
+ * The provider and its auth type come from the registry rather than from the
184
+ * row: both are facts about the installed package, and a copy in the database
185
+ * would be one more thing to keep in step.
221
186
  */
222
- function toJsonInput(value) {
223
- return value;
187
+ function describe(configuration, integration) {
188
+ return {
189
+ ...configuration,
190
+ provider: integration.key,
191
+ authType: integration.auth.type,
192
+ };
193
+ }
194
+ /** The handle a caller quotes in a proxy URL, so it has to be URL-safe. */
195
+ function slugify(value) {
196
+ return value
197
+ .toLowerCase()
198
+ .trim()
199
+ .replace(/[^a-z0-9]+/g, '-')
200
+ .replace(/^-+|-+$/g, '');
224
201
  }
@@ -1,8 +1,8 @@
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>;
6
+ fields?: Record<string, unknown>;
7
7
  }
8
8
  //# 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;IAStC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC"}
@@ -2,11 +2,11 @@ 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;
9
+ fields;
10
10
  }
11
11
  __decorate([
12
12
  ApiProperty({
@@ -16,7 +16,7 @@ __decorate([
16
16
  IsString(),
17
17
  MinLength(1),
18
18
  __metadata("design:type", String)
19
- ], CreateConfigurationDto.prototype, "integrationKey", void 0);
19
+ ], CreateConfigurationDto.prototype, "provider", void 0);
20
20
  __decorate([
21
21
  ApiProperty({ example: 'GitHub' }),
22
22
  IsString(),
@@ -45,10 +45,10 @@ __decorate([
45
45
  ], CreateConfigurationDto.prototype, "credentials", void 0);
46
46
  __decorate([
47
47
  ApiPropertyOptional({
48
- description: 'Non-secret half: scopes, and whatever the integration declares as configFields.',
49
- example: { scopes: ['repo', 'read:user'] },
48
+ description: 'What this provider declares in configFields, by key. Not secret: these become columns on its own table.',
49
+ example: { subdomain: 'acme' },
50
50
  }),
51
51
  IsOptional(),
52
52
  IsObject(),
53
53
  __metadata("design:type", Object)
54
- ], CreateConfigurationDto.prototype, "settings", void 0);
54
+ ], CreateConfigurationDto.prototype, "fields", void 0);
@@ -1,7 +1,6 @@
1
1
  export declare class UpdateConfigurationDto {
2
2
  name?: string;
3
3
  credentials?: Record<string, unknown>;
4
- settings?: Record<string, unknown>;
5
- isEnabled?: boolean;
4
+ fields?: Record<string, unknown>;
6
5
  }
7
6
  //# 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;IAStC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC"}
@@ -1,11 +1,10 @@
1
1
  import { __decorate, __metadata } from "tslib";
2
2
  import { ApiPropertyOptional } from '@nestjs/swagger';
3
- import { IsBoolean, IsObject, IsOptional, IsString, MaxLength, MinLength, } from 'class-validator';
3
+ import { IsObject, IsOptional, IsString, MaxLength, MinLength, } from 'class-validator';
4
4
  export class UpdateConfigurationDto {
5
5
  name;
6
6
  credentials;
7
- settings;
8
- isEnabled;
7
+ fields;
9
8
  }
10
9
  __decorate([
11
10
  ApiPropertyOptional({ example: 'GitHub' }),
@@ -23,17 +22,12 @@ __decorate([
23
22
  IsObject(),
24
23
  __metadata("design:type", Object)
25
24
  ], UpdateConfigurationDto.prototype, "credentials", void 0);
26
- __decorate([
27
- ApiPropertyOptional({ example: { scopes: ['repo'] } }),
28
- IsOptional(),
29
- IsObject(),
30
- __metadata("design:type", Object)
31
- ], UpdateConfigurationDto.prototype, "settings", void 0);
32
25
  __decorate([
33
26
  ApiPropertyOptional({
34
- description: 'Disable without deleting; stored credentials stay put.',
27
+ description: 'What this provider declares in configFields, by key. Not secret: these become columns on its own table.',
28
+ example: { subdomain: 'acme' },
35
29
  }),
36
30
  IsOptional(),
37
- IsBoolean(),
38
- __metadata("design:type", Boolean)
39
- ], UpdateConfigurationDto.prototype, "isEnabled", void 0);
31
+ IsObject(),
32
+ __metadata("design:type", Object)
33
+ ], UpdateConfigurationDto.prototype, "fields", void 0);
@@ -2,8 +2,9 @@ import { type UserSession } from '@thallesp/nestjs-better-auth';
2
2
  import type { Response } from 'express';
3
3
  import { type ApiKeyRequest } from '../auth/api-key.guard.js';
4
4
  import { ConnectService } from './connect.service.js';
5
+ import { ConnectWithCredentialDto } from './dto/connect-credential.dto.js';
5
6
  import { CreateConnectSessionDto } from './dto/create-connect-session.dto.js';
6
- import { CreateTestSessionDto } from './dto/create-test-session.dto.js';
7
+ import { CreateTestSessionDto, TestCredentialDto } from './dto/create-test-session.dto.js';
7
8
  export declare class ConnectController {
8
9
  private readonly connect;
9
10
  private readonly logger;
@@ -15,15 +16,24 @@ export declare class ConnectController {
15
16
  * can authenticate either way.
16
17
  */
17
18
  createSession(request: ApiKeyRequest, body: CreateConnectSessionDto): Promise<import("./connect.service.js").ConnectSessionResult>;
19
+ /**
20
+ * The counterpart for a provider whose end user already holds the key:
21
+ * the app collects it and posts it here, and a connection exists at once.
22
+ */
23
+ connectWithCredential(request: ApiKeyRequest, body: ConnectWithCredentialDto): Promise<import("./connect.service.js").CallbackResult>;
18
24
  /**
19
25
  * Admin-only: runs the same flow with the signed-in admin standing in for an
20
26
  * end user, so an operator can verify a configuration without wiring up
21
27
  * their backend first.
22
28
  */
23
29
  createTestSession(session: UserSession, environmentId: string, body: CreateTestSessionDto): Promise<import("./connect.service.js").ConnectSessionResult>;
30
+ /** The same, for a provider whose credential the operator pastes in. */
31
+ testCredential(session: UserSession, environmentId: string, body: TestCredentialDto): Promise<import("./connect.service.js").CallbackResult>;
24
32
  /** The URL the end user's browser opens. Redirects to the provider. */
25
33
  start(token: string, res: Response): Promise<void>;
34
+ /** A decline at the provider; never fails the response it is answering. */
35
+ private denied;
26
36
  /** Where the provider sends the end user back. */
27
- callback(integrationKey: string, code: string | undefined, state: string | undefined, providerError: string | undefined, providerErrorDescription: string | undefined, res: Response): Promise<void>;
37
+ callback(provider: string, code: string | undefined, state: string | undefined, providerError: string | undefined, providerErrorDescription: string | undefined, res: Response): Promise<void>;
28
38
  }
29
39
  //# sourceMappingURL=connect.controller.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"connect.controller.d.ts","sourceRoot":"","sources":["../../src/connect/connect.controller.ts"],"names":[],"mappings":"AAsBA,OAAO,EAGL,KAAK,WAAW,EACjB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,KAAK,aAAa,EAAgB,MAAM,0BAA0B,CAAC;AAE5E,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAC9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAExE,qBAEa,iBAAiB;IAGhB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAFpC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAsC;gBAEhC,OAAO,EAAE,cAAc;IAEpD;;;;;OAKG;IAcH,aAAa,CACJ,OAAO,EAAE,aAAa,EACrB,IAAI,EAAE,uBAAuB;IAevC;;;;OAIG;IAOH,iBAAiB,CACJ,OAAO,EAAE,WAAW,EACP,aAAa,EAAE,MAAM,EACrC,IAAI,EAAE,oBAAoB;IAcpC,uEAAuE;IAIjE,KAAK,CAAiB,KAAK,EAAE,MAAM,EAAS,GAAG,EAAE,QAAQ;IAY/D,kDAAkD;IAI5C,QAAQ,CACa,cAAc,EAAE,MAAM,EAChC,IAAI,EAAE,MAAM,GAAG,SAAS,EACvB,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,aAAa,EAAE,MAAM,GAAG,SAAS,EACrB,wBAAwB,EAAE,MAAM,GAAG,SAAS,EACjE,GAAG,EAAE,QAAQ;CAuDvB"}
1
+ {"version":3,"file":"connect.controller.d.ts","sourceRoot":"","sources":["../../src/connect/connect.controller.ts"],"names":[],"mappings":"AAsBA,OAAO,EAGL,KAAK,WAAW,EACjB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,KAAK,aAAa,EAAgB,MAAM,0BAA0B,CAAC;AAE5E,OAAO,EAEL,cAAc,EAEf,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAC3E,OAAO,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAC9E,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EAClB,MAAM,kCAAkC,CAAC;AAE1C,qBAEa,iBAAiB;IAGhB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAFpC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAsC;gBAEhC,OAAO,EAAE,cAAc;IAEpD;;;;;OAKG;IAcH,aAAa,CACJ,OAAO,EAAE,aAAa,EACrB,IAAI,EAAE,uBAAuB;IAevC;;;OAGG;IAcH,qBAAqB,CACZ,OAAO,EAAE,aAAa,EACrB,IAAI,EAAE,wBAAwB;IAexC;;;;OAIG;IAOH,iBAAiB,CACJ,OAAO,EAAE,WAAW,EACP,aAAa,EAAE,MAAM,EACrC,IAAI,EAAE,oBAAoB;IAepC,wEAAwE;IAOxE,cAAc,CACD,OAAO,EAAE,WAAW,EACP,aAAa,EAAE,MAAM,EACrC,IAAI,EAAE,iBAAiB;IAejC,uEAAuE;IAIjE,KAAK,CAAiB,KAAK,EAAE,MAAM,EAAS,GAAG,EAAE,QAAQ;IAkB/D,2EAA2E;YAC7D,MAAM;IAiBpB,kDAAkD;IAI5C,QAAQ,CACO,QAAQ,EAAE,MAAM,EACpB,IAAI,EAAE,MAAM,GAAG,SAAS,EACvB,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,aAAa,EAAE,MAAM,GAAG,SAAS,EACrB,wBAAwB,EAAE,MAAM,GAAG,SAAS,EACjE,GAAG,EAAE,QAAQ;CAyDvB"}