@kosha-ai/server 0.3.0 → 0.4.1
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/configurations/configurations.service.d.ts +6 -0
- package/dist/configurations/configurations.service.d.ts.map +1 -1
- package/dist/configurations/configurations.service.js +63 -1
- package/dist/configurations/dto/create-configuration.dto.d.ts +1 -0
- package/dist/configurations/dto/create-configuration.dto.d.ts.map +1 -1
- package/dist/configurations/dto/create-configuration.dto.js +10 -0
- package/dist/configurations/dto/update-configuration.dto.d.ts +1 -0
- package/dist/configurations/dto/update-configuration.dto.d.ts.map +1 -1
- package/dist/configurations/dto/update-configuration.dto.js +10 -0
- package/dist/connect/connect.controller.d.ts +11 -1
- package/dist/connect/connect.controller.d.ts.map +1 -1
- package/dist/connect/connect.controller.js +102 -13
- package/dist/connect/connect.repository.d.ts +11 -2
- package/dist/connect/connect.repository.d.ts.map +1 -1
- package/dist/connect/connect.repository.js +8 -3
- package/dist/connect/connect.service.d.ts +47 -0
- package/dist/connect/connect.service.d.ts.map +1 -1
- package/dist/connect/connect.service.js +269 -28
- 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-test-session.dto.d.ts +7 -0
- package/dist/connect/dto/create-test-session.dto.d.ts.map +1 -1
- package/dist/connect/dto/create-test-session.dto.js +36 -1
- package/dist/credentials/credentials.service.d.ts +9 -3
- package/dist/credentials/credentials.service.d.ts.map +1 -1
- package/dist/credentials/credentials.service.js +91 -26
- 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/host-rules.service.js +2 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- 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 +4 -0
- package/dist/integrations/integrations.controller.d.ts.map +1 -1
- package/dist/integrations/integrations.controller.js +3 -1
- package/dist/integrations/provider-store.d.ts +8 -2
- package/dist/integrations/provider-store.d.ts.map +1 -1
- package/dist/integrations/provider-store.js +82 -14
- package/dist/kosha.module.d.ts.map +1 -1
- package/dist/kosha.module.js +2 -0
- package/dist/proxy/proxy.controller.d.ts +9 -1
- package/dist/proxy/proxy.controller.d.ts.map +1 -1
- package/dist/proxy/proxy.controller.js +34 -10
- package/dist/proxy/proxy.module.d.ts.map +1 -1
- package/dist/proxy/proxy.module.js +4 -0
- package/dist/proxy/proxy.service.d.ts.map +1 -1
- package/dist/proxy/proxy.service.js +44 -4
- package/dist/query/dto/run-query.dto.d.ts +5 -0
- package/dist/query/dto/run-query.dto.d.ts.map +1 -0
- package/dist/query/dto/run-query.dto.js +26 -0
- package/dist/query/query.controller.d.ts +15 -0
- package/dist/query/query.controller.d.ts.map +1 -0
- package/dist/query/query.controller.js +52 -0
- package/dist/query/query.module.d.ts +3 -0
- package/dist/query/query.module.d.ts.map +1 -0
- package/dist/query/query.module.js +19 -0
- package/dist/query/query.service.d.ts +32 -0
- package/dist/query/query.service.d.ts.map +1 -0
- package/dist/query/query.service.js +83 -0
- package/package.json +4 -4
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { Injectable, NotFoundException } from '@nestjs/common';
|
|
3
|
+
import { CredentialsService } from '../credentials/credentials.service.js';
|
|
4
|
+
import { EnvironmentsService } from '../environments/environments.service.js';
|
|
5
|
+
import { IntegrationRegistry } from '../integrations/integration.registry.js';
|
|
6
|
+
import { ProviderStore } from '../integrations/provider-store.js';
|
|
7
|
+
import { ProxyRepository } from '../proxy/proxy.repository.js';
|
|
8
|
+
/**
|
|
9
|
+
* The direct-connection counterpart to `ProxyService`: a query-shaped
|
|
10
|
+
* integration (declares `query`, not `api`) has no REST API to forward an
|
|
11
|
+
* HTTP request to, so the credential is handed to the integration's own
|
|
12
|
+
* `query.run` instead of signing a `fetch`.
|
|
13
|
+
*/
|
|
14
|
+
let QueryService = class QueryService {
|
|
15
|
+
proxy;
|
|
16
|
+
environments;
|
|
17
|
+
store;
|
|
18
|
+
registry;
|
|
19
|
+
resolver;
|
|
20
|
+
constructor(proxy, environments, store, registry, resolver) {
|
|
21
|
+
this.proxy = proxy;
|
|
22
|
+
this.environments = environments;
|
|
23
|
+
this.store = store;
|
|
24
|
+
this.registry = registry;
|
|
25
|
+
this.resolver = resolver;
|
|
26
|
+
}
|
|
27
|
+
async run(organizationId, environmentId, target, request) {
|
|
28
|
+
const environment = await this.environments.get(organizationId, environmentId);
|
|
29
|
+
// Every miss below answers the same 404: a caller learns nothing about
|
|
30
|
+
// what exists in another environment, or under another owner.
|
|
31
|
+
const integration = this.registry.find(target.provider);
|
|
32
|
+
if (!integration)
|
|
33
|
+
throw new NotFoundException('Connection not found');
|
|
34
|
+
if (!integration.query) {
|
|
35
|
+
throw new NotFoundException(`${target.provider} has no query capability.`);
|
|
36
|
+
}
|
|
37
|
+
const [configuration, userId] = await Promise.all([
|
|
38
|
+
this.store.findConfigurationBySlugWithCredentials(integration, environment.id, target.configurationSlug),
|
|
39
|
+
this.proxy.findUserId(environment.slug, target.owner),
|
|
40
|
+
]);
|
|
41
|
+
if (!configuration || !userId) {
|
|
42
|
+
throw new NotFoundException('Connection not found');
|
|
43
|
+
}
|
|
44
|
+
const connection = await this.store.findConnection(integration, environment.id, configuration.id, userId);
|
|
45
|
+
if (!connection)
|
|
46
|
+
throw new NotFoundException('Connection not found');
|
|
47
|
+
const account = await this.proxy.findAccount(connection.accountId);
|
|
48
|
+
if (!account)
|
|
49
|
+
throw new NotFoundException('Connection not found');
|
|
50
|
+
const credential = await this.resolver.resolve(account, integration, configuration);
|
|
51
|
+
return integration.query.run({
|
|
52
|
+
credential: {
|
|
53
|
+
accessToken: credential.accessToken,
|
|
54
|
+
tokenType: credential.tokenType,
|
|
55
|
+
},
|
|
56
|
+
fields: configuration.fields,
|
|
57
|
+
metadata: asMetadata(connection.metadata),
|
|
58
|
+
sql: request.sql,
|
|
59
|
+
params: request.params,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
QueryService = __decorate([
|
|
64
|
+
Injectable(),
|
|
65
|
+
__metadata("design:paramtypes", [ProxyRepository,
|
|
66
|
+
EnvironmentsService,
|
|
67
|
+
ProviderStore,
|
|
68
|
+
IntegrationRegistry,
|
|
69
|
+
CredentialsService])
|
|
70
|
+
], QueryService);
|
|
71
|
+
export { QueryService };
|
|
72
|
+
/**
|
|
73
|
+
* Stored metadata is free-form JSON, so it may be an array, a number or null.
|
|
74
|
+
* Only an object is a metadata bag; anything else is treated as absent rather
|
|
75
|
+
* than handed to an integration that expects to index it.
|
|
76
|
+
*/
|
|
77
|
+
function asMetadata(metadata) {
|
|
78
|
+
return metadata !== null &&
|
|
79
|
+
typeof metadata === 'object' &&
|
|
80
|
+
!Array.isArray(metadata)
|
|
81
|
+
? metadata
|
|
82
|
+
: undefined;
|
|
83
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kosha-ai/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Kosha server: OAuth handshake, encrypted credential storage, token refresh, and an authenticated request proxy for third-party integrations",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"kosha",
|
|
@@ -109,7 +109,7 @@
|
|
|
109
109
|
"rxjs": "^7.8.0",
|
|
110
110
|
"tslib": "^2.3.0",
|
|
111
111
|
"zod": "4.5.4",
|
|
112
|
-
"@kosha-ai/integration-sdk": "0.
|
|
112
|
+
"@kosha-ai/integration-sdk": "0.4.1"
|
|
113
113
|
},
|
|
114
114
|
"devDependencies": {
|
|
115
115
|
"@nestjs/testing": "^11.0.0",
|
|
@@ -117,7 +117,7 @@
|
|
|
117
117
|
"@types/node-forge": "^1.3.14",
|
|
118
118
|
"@types/pg": "^8.23.1",
|
|
119
119
|
"prisma": "^7.10.0",
|
|
120
|
-
"@kosha-ai/integration-github": "0.
|
|
121
|
-
"@kosha-ai/integration-slack": "0.
|
|
120
|
+
"@kosha-ai/integration-github": "0.4.1",
|
|
121
|
+
"@kosha-ai/integration-slack": "0.4.1"
|
|
122
122
|
}
|
|
123
123
|
}
|