@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.
- package/dist/auth/auth.factory.d.ts.map +1 -1
- package/dist/auth/auth.factory.js +0 -5
- package/dist/configurations/configurations.controller.d.ts +6 -5
- package/dist/configurations/configurations.controller.d.ts.map +1 -1
- package/dist/configurations/configurations.controller.js +22 -18
- package/dist/configurations/configurations.module.d.ts.map +1 -1
- package/dist/configurations/configurations.module.js +1 -2
- package/dist/configurations/configurations.service.d.ts +29 -35
- package/dist/configurations/configurations.service.d.ts.map +1 -1
- package/dist/configurations/configurations.service.js +126 -149
- package/dist/configurations/dto/create-configuration.dto.d.ts +2 -2
- package/dist/configurations/dto/create-configuration.dto.d.ts.map +1 -1
- package/dist/configurations/dto/create-configuration.dto.js +6 -6
- package/dist/configurations/dto/update-configuration.dto.d.ts +1 -2
- package/dist/configurations/dto/update-configuration.dto.d.ts.map +1 -1
- package/dist/configurations/dto/update-configuration.dto.js +7 -13
- package/dist/connect/connect.controller.d.ts +12 -2
- package/dist/connect/connect.controller.d.ts.map +1 -1
- package/dist/connect/connect.controller.js +108 -18
- package/dist/connect/connect.module.d.ts.map +1 -1
- package/dist/connect/connect.module.js +1 -2
- package/dist/connect/connect.repository.d.ts +34 -25
- package/dist/connect/connect.repository.d.ts.map +1 -1
- package/dist/connect/connect.repository.js +45 -52
- package/dist/connect/connect.service.d.ts +54 -8
- package/dist/connect/connect.service.d.ts.map +1 -1
- package/dist/connect/connect.service.js +312 -68
- package/dist/connect/dto/connect-credential.dto.d.ts +8 -0
- package/dist/connect/dto/connect-credential.dto.d.ts.map +1 -0
- package/dist/connect/dto/connect-credential.dto.js +54 -0
- package/dist/connect/dto/create-connect-session.dto.d.ts +1 -1
- package/dist/connect/dto/create-connect-session.dto.d.ts.map +1 -1
- package/dist/connect/dto/create-connect-session.dto.js +7 -8
- package/dist/connect/dto/create-test-session.dto.d.ts +8 -0
- package/dist/connect/dto/create-test-session.dto.d.ts.map +1 -1
- package/dist/connect/dto/create-test-session.dto.js +45 -3
- package/dist/connections/connections.controller.d.ts +4 -3
- package/dist/connections/connections.controller.d.ts.map +1 -1
- package/dist/connections/connections.controller.js +13 -11
- package/dist/connections/connections.repository.d.ts +24 -17
- package/dist/connections/connections.repository.d.ts.map +1 -1
- package/dist/connections/connections.repository.js +21 -43
- package/dist/connections/connections.service.d.ts +48 -13
- package/dist/connections/connections.service.d.ts.map +1 -1
- package/dist/connections/connections.service.js +111 -32
- package/dist/connections/dto/list-connections.dto.d.ts +3 -1
- package/dist/connections/dto/list-connections.dto.d.ts.map +1 -1
- package/dist/connections/dto/list-connections.dto.js +26 -4
- package/dist/connections/environment-connections.controller.d.ts +4 -3
- package/dist/connections/environment-connections.controller.d.ts.map +1 -1
- package/dist/connections/environment-connections.controller.js +14 -12
- package/dist/credentials/credentials.module.d.ts.map +1 -1
- package/dist/credentials/credentials.module.js +0 -2
- package/dist/credentials/credentials.repository.d.ts +5 -2
- package/dist/credentials/credentials.repository.d.ts.map +1 -1
- package/dist/credentials/credentials.repository.js +10 -3
- package/dist/credentials/credentials.service.d.ts +14 -4
- package/dist/credentials/credentials.service.d.ts.map +1 -1
- package/dist/credentials/credentials.service.js +106 -30
- package/dist/crypto/credential-envelope.d.ts +27 -1
- package/dist/crypto/credential-envelope.d.ts.map +1 -1
- package/dist/crypto/credential-envelope.js +43 -0
- package/dist/egress/egress.listener.d.ts +1 -3
- package/dist/egress/egress.listener.d.ts.map +1 -1
- package/dist/egress/egress.listener.js +3 -7
- package/dist/egress/egress.repository.d.ts +13 -6
- package/dist/egress/egress.repository.d.ts.map +1 -1
- package/dist/egress/egress.repository.js +31 -44
- package/dist/generated/prisma/browser.d.ts +0 -5
- package/dist/generated/prisma/browser.d.ts.map +1 -1
- package/dist/generated/prisma/client.d.ts +0 -5
- package/dist/generated/prisma/client.d.ts.map +1 -1
- package/dist/generated/prisma/commonInputTypes.d.ts +0 -55
- package/dist/generated/prisma/commonInputTypes.d.ts.map +1 -1
- package/dist/generated/prisma/internal/class.d.ts +0 -11
- package/dist/generated/prisma/internal/class.d.ts.map +1 -1
- package/dist/generated/prisma/internal/class.js +4 -4
- package/dist/generated/prisma/internal/prismaNamespace.d.ts +1 -114
- package/dist/generated/prisma/internal/prismaNamespace.d.ts.map +1 -1
- package/dist/generated/prisma/internal/prismaNamespace.js +2 -29
- package/dist/generated/prisma/internal/prismaNamespaceBrowser.d.ts +0 -30
- package/dist/generated/prisma/internal/prismaNamespaceBrowser.d.ts.map +1 -1
- package/dist/generated/prisma/internal/prismaNamespaceBrowser.js +2 -29
- package/dist/generated/prisma/models/Account.d.ts +26 -344
- package/dist/generated/prisma/models/Account.d.ts.map +1 -1
- package/dist/generated/prisma/models/Environment.d.ts +0 -258
- package/dist/generated/prisma/models/Environment.d.ts.map +1 -1
- package/dist/generated/prisma/models/User.d.ts +2 -60
- package/dist/generated/prisma/models/User.d.ts.map +1 -1
- package/dist/generated/prisma/models.d.ts +0 -1
- package/dist/generated/prisma/models.d.ts.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/integrations/client-context.d.ts +20 -0
- package/dist/integrations/client-context.d.ts.map +1 -0
- package/dist/integrations/client-context.js +23 -0
- package/dist/integrations/integrations.controller.d.ts +6 -0
- package/dist/integrations/integrations.controller.d.ts.map +1 -1
- package/dist/integrations/integrations.controller.js +3 -0
- package/dist/integrations/integrations.module.d.ts.map +1 -1
- package/dist/integrations/integrations.module.js +3 -1
- package/dist/integrations/provider-store.d.ts +110 -0
- package/dist/integrations/provider-store.d.ts.map +1 -0
- package/dist/integrations/provider-store.js +302 -0
- package/dist/proxy/proxy.controller.d.ts +17 -5
- package/dist/proxy/proxy.controller.d.ts.map +1 -1
- package/dist/proxy/proxy.controller.js +46 -17
- package/dist/proxy/proxy.module.d.ts.map +1 -1
- package/dist/proxy/proxy.module.js +1 -2
- package/dist/proxy/proxy.repository.d.ts +11 -14
- package/dist/proxy/proxy.repository.d.ts.map +1 -1
- package/dist/proxy/proxy.repository.js +17 -27
- package/dist/proxy/proxy.service.d.ts +6 -8
- package/dist/proxy/proxy.service.d.ts.map +1 -1
- package/dist/proxy/proxy.service.js +72 -31
- package/package.json +4 -4
- package/prisma/migrations/{20260929101936_init → 20261008090000_init}/migration.sql +5 -58
- package/prisma/schema.prisma +2 -43
- package/dist/configurations/configurations.repository.d.ts +0 -43
- package/dist/configurations/configurations.repository.d.ts.map +0 -1
- package/dist/configurations/configurations.repository.js +0 -76
- package/dist/generated/prisma/models/Configuration.d.ts +0 -1385
- package/dist/generated/prisma/models/Configuration.d.ts.map +0 -1
- package/dist/generated/prisma/models/Configuration.js +0 -1
- package/prisma/migrations/20260930102529_connection_config/migration.sql +0 -2
|
@@ -1,106 +1,94 @@
|
|
|
1
|
-
import { __decorate, __metadata
|
|
2
|
-
import { BadRequestException, ConflictException,
|
|
3
|
-
import {
|
|
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 {
|
|
7
|
+
import { ProviderStore, } from '../integrations/provider-store.js';
|
|
8
8
|
let ConfigurationsService = class ConfigurationsService {
|
|
9
|
-
|
|
9
|
+
store;
|
|
10
10
|
environments;
|
|
11
11
|
crypto;
|
|
12
12
|
registry;
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
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
|
-
|
|
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
|
|
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
|
|
51
|
-
//
|
|
52
|
-
const integration = this.registry.get(input.
|
|
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
|
-
|
|
59
|
-
|
|
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
|
|
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
|
-
|
|
69
|
-
|
|
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
|
-
|
|
74
|
-
|
|
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(
|
|
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
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
|
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
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
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
|
-
|
|
120
|
-
const integration
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
-
|
|
129
|
-
return null;
|
|
130
|
-
return this.crypto.encrypt(JSON.stringify(provided));
|
|
118
|
+
return fields;
|
|
131
119
|
}
|
|
132
120
|
/**
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
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
|
-
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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
|
-
|
|
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
|
-
|
|
183
|
-
__metadata("design:paramtypes", [ConfigurationsRepository,
|
|
145
|
+
__metadata("design:paramtypes", [ProviderStore,
|
|
184
146
|
EnvironmentsService,
|
|
185
147
|
CryptoService,
|
|
186
|
-
IntegrationRegistry
|
|
148
|
+
IntegrationRegistry])
|
|
187
149
|
], ConfigurationsService);
|
|
188
150
|
export { ConfigurationsService };
|
|
189
|
-
/**
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
function
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
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
|
-
|
|
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
|
-
*
|
|
220
|
-
*
|
|
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
|
|
223
|
-
return
|
|
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
|
-
|
|
2
|
+
provider: string;
|
|
3
3
|
name: string;
|
|
4
4
|
slug?: string;
|
|
5
5
|
credentials?: Record<string, unknown>;
|
|
6
|
-
|
|
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,
|
|
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
|
-
|
|
5
|
+
provider;
|
|
6
6
|
name;
|
|
7
7
|
slug;
|
|
8
8
|
credentials;
|
|
9
|
-
|
|
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, "
|
|
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: '
|
|
49
|
-
example: {
|
|
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, "
|
|
54
|
+
], CreateConfigurationDto.prototype, "fields", void 0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update-configuration.dto.d.ts","sourceRoot":"","sources":["../../../src/configurations/dto/update-configuration.dto.ts"],"names":[],"mappings":"
|
|
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 {
|
|
3
|
+
import { IsObject, IsOptional, IsString, MaxLength, MinLength, } from 'class-validator';
|
|
4
4
|
export class UpdateConfigurationDto {
|
|
5
5
|
name;
|
|
6
6
|
credentials;
|
|
7
|
-
|
|
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: '
|
|
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
|
-
|
|
38
|
-
__metadata("design:type",
|
|
39
|
-
], UpdateConfigurationDto.prototype, "
|
|
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(
|
|
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,
|
|
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"}
|