@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
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
var CredentialsService_1;
|
|
2
2
|
import { __decorate, __metadata, __param } from "tslib";
|
|
3
|
-
import { Injectable, Logger, UnauthorizedException } from '@nestjs/common';
|
|
3
|
+
import { ForbiddenException, Injectable, Logger, UnauthorizedException, } from '@nestjs/common';
|
|
4
4
|
import { Inject } from '@nestjs/common';
|
|
5
5
|
import { KOSHA_CONFIG } from '../config/tokens.js';
|
|
6
|
-
import {
|
|
6
|
+
import { clientContextFor } from '../integrations/client-context.js';
|
|
7
|
+
import { ENVELOPE_VERSION, expiryOf, storedSecondaryToken, } from '../crypto/credential-envelope.js';
|
|
7
8
|
import { CryptoService } from '../crypto/crypto.service.js';
|
|
8
9
|
import { CredentialsRepository } from './credentials.repository.js';
|
|
9
10
|
let CredentialsService = CredentialsService_1 = class CredentialsService {
|
|
@@ -24,11 +25,16 @@ let CredentialsService = CredentialsService_1 = class CredentialsService {
|
|
|
24
25
|
* the whole consent flow again for a token the provider was willing to
|
|
25
26
|
* renew.
|
|
26
27
|
*/
|
|
27
|
-
async resolve(account, integration, configuration) {
|
|
28
|
+
async resolve(account, integration, configuration, tokenKind) {
|
|
28
29
|
if (!account.accessToken) {
|
|
29
30
|
throw new UnauthorizedException('Connection has no stored credential');
|
|
30
31
|
}
|
|
31
32
|
const envelope = this.crypto.openEnvelope(account.accessToken);
|
|
33
|
+
// The integration lists its primary token first; any other kind is a
|
|
34
|
+
// secondary one stored beside it.
|
|
35
|
+
if (tokenKind && tokenKind !== integration.auth.tokenKinds?.[0]) {
|
|
36
|
+
return this.resolveSecondary(account, integration, configuration, envelope, tokenKind);
|
|
37
|
+
}
|
|
32
38
|
const expiresAt = expiryOf(envelope);
|
|
33
39
|
const expired = expiresAt !== null && expiresAt <= new Date();
|
|
34
40
|
if (!expired)
|
|
@@ -38,35 +44,23 @@ let CredentialsService = CredentialsService_1 = class CredentialsService {
|
|
|
38
44
|
if (!canRefresh) {
|
|
39
45
|
throw new UnauthorizedException('Connection token expired; the end user must reconnect');
|
|
40
46
|
}
|
|
41
|
-
return this.refresh(account, integration, configuration, refreshToken);
|
|
47
|
+
return this.refresh(account, integration, configuration, refreshToken, envelope.type === 'oauth2' ? envelope : undefined);
|
|
42
48
|
}
|
|
43
|
-
async refresh(account, integration, configuration, refreshToken) {
|
|
44
|
-
const credentials = this.openCredentials(configuration);
|
|
49
|
+
async refresh(account, integration, configuration, refreshToken, previous) {
|
|
45
50
|
try {
|
|
46
|
-
const tokens = await
|
|
47
|
-
client: {
|
|
48
|
-
clientId: String(credentials['clientId'] ?? ''),
|
|
49
|
-
clientSecret: String(credentials['clientSecret'] ?? ''),
|
|
50
|
-
redirectUri: this.callbackUrlFor(integration.key),
|
|
51
|
-
// The refresh_token grant carries no scope; the provider returns
|
|
52
|
-
// whatever the original consent granted.
|
|
53
|
-
scopes: [],
|
|
54
|
-
},
|
|
55
|
-
refreshToken,
|
|
56
|
-
});
|
|
57
|
-
if (!tokens)
|
|
58
|
-
throw new Error('Refresh returned no tokens');
|
|
51
|
+
const tokens = await this.requestRefresh(integration, configuration, refreshToken);
|
|
59
52
|
const envelope = {
|
|
60
53
|
v: ENVELOPE_VERSION,
|
|
61
54
|
type: 'oauth2',
|
|
62
55
|
accessToken: tokens.accessToken,
|
|
63
|
-
|
|
56
|
+
refreshToken: tokens.refreshToken ?? refreshToken,
|
|
64
57
|
...(tokens.tokenType ? { tokenType: tokens.tokenType } : {}),
|
|
65
58
|
...(tokens.expiresInSeconds
|
|
66
59
|
? {
|
|
67
60
|
expiresAt: new Date(Date.now() + tokens.expiresInSeconds * 1000).toISOString(),
|
|
68
61
|
}
|
|
69
62
|
: {}),
|
|
63
|
+
...carriedSecondary(previous),
|
|
70
64
|
};
|
|
71
65
|
const expiresAt = expiryOf(envelope);
|
|
72
66
|
await this.credentials.replaceEnvelope(account.id, this.crypto.sealEnvelope(envelope), expiresAt, tokens.scope ?? undefined);
|
|
@@ -74,14 +68,72 @@ let CredentialsService = CredentialsService_1 = class CredentialsService {
|
|
|
74
68
|
return this.usable(envelope, expiresAt, true);
|
|
75
69
|
}
|
|
76
70
|
catch (error) {
|
|
77
|
-
this.
|
|
78
|
-
|
|
71
|
+
throw this.refreshFailed(integration, error);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* A secondary token expires and refreshes on its own, with its own refresh
|
|
76
|
+
* token. Renewing it leaves the primary, and its expiry, as they were.
|
|
77
|
+
*/
|
|
78
|
+
async resolveSecondary(account, integration, configuration, envelope, tokenKind) {
|
|
79
|
+
const credential = envelope.type === 'oauth2' ? envelope.secondary?.[tokenKind] : undefined;
|
|
80
|
+
if (envelope.type !== 'oauth2' || !credential) {
|
|
81
|
+
throw new ForbiddenException(`Connection has no ${tokenKind} token`);
|
|
82
|
+
}
|
|
83
|
+
const parsed = credential.expiresAt ? new Date(credential.expiresAt) : null;
|
|
84
|
+
const expiresAt = parsed && !Number.isNaN(parsed.getTime()) ? parsed : null;
|
|
85
|
+
if (!expiresAt || expiresAt > new Date()) {
|
|
86
|
+
return {
|
|
87
|
+
accessToken: credential.accessToken,
|
|
88
|
+
tokenType: credential.tokenType ?? null,
|
|
89
|
+
expiresAt,
|
|
90
|
+
refreshed: false,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
if (!credential.refreshToken || !integration.auth.refresh) {
|
|
94
|
+
throw new UnauthorizedException(`Connection ${tokenKind} token expired; the end user must reconnect`);
|
|
95
|
+
}
|
|
96
|
+
try {
|
|
97
|
+
const tokens = await this.requestRefresh(integration, configuration, credential.refreshToken);
|
|
98
|
+
const renewed = storedSecondaryToken(tokens);
|
|
99
|
+
await this.credentials.replaceEnvelope(account.id, this.crypto.sealEnvelope({
|
|
100
|
+
...envelope,
|
|
101
|
+
secondary: { ...envelope.secondary, [tokenKind]: renewed },
|
|
102
|
+
}), expiryOf(envelope));
|
|
103
|
+
// No onTokenRefreshed here: the hook is handed tokens with nothing to
|
|
104
|
+
// say which kind they are, so a listener would take them for the primary.
|
|
105
|
+
return {
|
|
106
|
+
accessToken: renewed.accessToken,
|
|
107
|
+
tokenType: renewed.tokenType ?? null,
|
|
108
|
+
expiresAt: renewed.expiresAt ? new Date(renewed.expiresAt) : null,
|
|
109
|
+
refreshed: true,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
throw this.refreshFailed(integration, error);
|
|
79
114
|
}
|
|
80
115
|
}
|
|
81
|
-
/**
|
|
82
|
-
|
|
83
|
-
const
|
|
84
|
-
|
|
116
|
+
/** The refresh_token grant, for whichever stored token is being renewed. */
|
|
117
|
+
async requestRefresh(integration, configuration, refreshToken) {
|
|
118
|
+
const tokens = await integration.auth.refresh?.({
|
|
119
|
+
client: clientContextFor({
|
|
120
|
+
integration,
|
|
121
|
+
configuration,
|
|
122
|
+
credentials: this.openCredentials(configuration),
|
|
123
|
+
server: this.config.server,
|
|
124
|
+
// The refresh_token grant carries no scope; the provider returns
|
|
125
|
+
// whatever the original consent granted.
|
|
126
|
+
scopes: [],
|
|
127
|
+
}),
|
|
128
|
+
refreshToken,
|
|
129
|
+
});
|
|
130
|
+
if (!tokens)
|
|
131
|
+
throw new Error('Refresh returned no tokens');
|
|
132
|
+
return tokens;
|
|
133
|
+
}
|
|
134
|
+
refreshFailed(integration, error) {
|
|
135
|
+
this.logger.warn(`Refresh failed for ${integration.key}: ${error instanceof Error ? error.message : error}`);
|
|
136
|
+
return new UnauthorizedException('Connection token expired and could not be refreshed; the end user must reconnect');
|
|
85
137
|
}
|
|
86
138
|
openCredentials(configuration) {
|
|
87
139
|
if (!configuration.credentials)
|
|
@@ -109,6 +161,15 @@ let CredentialsService = CredentialsService_1 = class CredentialsService {
|
|
|
109
161
|
expiresAt: null,
|
|
110
162
|
refreshed,
|
|
111
163
|
};
|
|
164
|
+
// Encoded here rather than in the package: `authHeaders` is handed one
|
|
165
|
+
// string, and base64("user:pass") is what Basic auth puts on the wire.
|
|
166
|
+
case 'basic':
|
|
167
|
+
return {
|
|
168
|
+
accessToken: Buffer.from(`${envelope.username}:${envelope.password}`).toString('base64'),
|
|
169
|
+
tokenType: 'Basic',
|
|
170
|
+
expiresAt: null,
|
|
171
|
+
refreshed,
|
|
172
|
+
};
|
|
112
173
|
case 'app':
|
|
113
174
|
return {
|
|
114
175
|
accessToken: envelope.installationId,
|
|
@@ -144,3 +205,7 @@ CredentialsService = CredentialsService_1 = __decorate([
|
|
|
144
205
|
CredentialsRepository, Object])
|
|
145
206
|
], CredentialsService);
|
|
146
207
|
export { CredentialsService };
|
|
208
|
+
/** A refresh replaces the primary token. Secondary tokens stay as they were. */
|
|
209
|
+
function carriedSecondary(previous) {
|
|
210
|
+
return previous?.secondary ? { secondary: previous.secondary } : {};
|
|
211
|
+
}
|
|
@@ -10,6 +10,24 @@ export declare const ENVELOPE_VERSION = 1;
|
|
|
10
10
|
interface Versioned {
|
|
11
11
|
v: typeof ENVELOPE_VERSION;
|
|
12
12
|
}
|
|
13
|
+
/** A token beyond the primary one, from the same exchange. */
|
|
14
|
+
export interface OAuth2SecondaryToken {
|
|
15
|
+
accessToken: string;
|
|
16
|
+
refreshToken?: string;
|
|
17
|
+
tokenType?: string;
|
|
18
|
+
/** ISO 8601. */
|
|
19
|
+
expiresAt?: string;
|
|
20
|
+
/** What the provider granted for this token. */
|
|
21
|
+
scope?: string;
|
|
22
|
+
}
|
|
23
|
+
/** A secondary token as the envelope stores it, from what the provider sent. */
|
|
24
|
+
export declare function storedSecondaryToken(token: {
|
|
25
|
+
accessToken: string;
|
|
26
|
+
refreshToken?: string;
|
|
27
|
+
tokenType?: string;
|
|
28
|
+
expiresInSeconds?: number;
|
|
29
|
+
scope?: string;
|
|
30
|
+
}): OAuth2SecondaryToken;
|
|
13
31
|
/** A token pair from an authorization-code flow. */
|
|
14
32
|
export interface OAuth2Envelope extends Versioned {
|
|
15
33
|
type: 'oauth2';
|
|
@@ -18,12 +36,20 @@ export interface OAuth2Envelope extends Versioned {
|
|
|
18
36
|
tokenType?: string;
|
|
19
37
|
/** ISO 8601. Mirrored into `account.accessTokenExpiresAt` on write. */
|
|
20
38
|
expiresAt?: string;
|
|
39
|
+
/** The exchange's other tokens, by kind. The primary is not repeated here. */
|
|
40
|
+
secondary?: Record<string, OAuth2SecondaryToken>;
|
|
21
41
|
}
|
|
22
42
|
/** A key the end user pasted, such as Apollo's. */
|
|
23
43
|
export interface ApiKeyEnvelope extends Versioned {
|
|
24
44
|
type: 'api_key';
|
|
25
45
|
key: string;
|
|
26
46
|
}
|
|
47
|
+
/** A username and password the end user supplied, for an API behind Basic auth. */
|
|
48
|
+
export interface BasicEnvelope extends Versioned {
|
|
49
|
+
type: 'basic';
|
|
50
|
+
username: string;
|
|
51
|
+
password: string;
|
|
52
|
+
}
|
|
27
53
|
/** A GitHub App install: tokens are minted per call from the installation. */
|
|
28
54
|
export interface AppEnvelope extends Versioned {
|
|
29
55
|
type: 'app';
|
|
@@ -36,7 +62,7 @@ export interface AppEnvelope extends Versioned {
|
|
|
36
62
|
export interface ClientCredentialsEnvelope extends Versioned {
|
|
37
63
|
type: 'oauth2_cc';
|
|
38
64
|
}
|
|
39
|
-
export type CredentialEnvelope = OAuth2Envelope | ApiKeyEnvelope | AppEnvelope | ClientCredentialsEnvelope;
|
|
65
|
+
export type CredentialEnvelope = OAuth2Envelope | ApiKeyEnvelope | BasicEnvelope | AppEnvelope | ClientCredentialsEnvelope;
|
|
40
66
|
export type CredentialEnvelopeType = CredentialEnvelope['type'];
|
|
41
67
|
export declare class InvalidEnvelopeError extends Error {
|
|
42
68
|
constructor(reason: string);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"credential-envelope.d.ts","sourceRoot":"","sources":["../../src/crypto/credential-envelope.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAElC,UAAU,SAAS;IACjB,CAAC,EAAE,OAAO,gBAAgB,CAAC;CAC5B;AAED,oDAAoD;AACpD,MAAM,WAAW,cAAe,SAAQ,SAAS;IAC/C,IAAI,EAAE,QAAQ,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,uEAAuE;IACvE,SAAS,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"credential-envelope.d.ts","sourceRoot":"","sources":["../../src/crypto/credential-envelope.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAElC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KAAK,CAAC;IACZ,cAAc,EAAE,MAAM,CAAC;CACxB;AAED;;;GAGG;AACH,MAAM,WAAW,yBAA0B,SAAQ,SAAS;IAC1D,IAAI,EAAE,WAAW,CAAC;CACnB;AAED,MAAM,MAAM,kBAAkB,GAC1B,cAAc,GACd,cAAc,GACd,aAAa,GACb,WAAW,GACX,yBAAyB,CAAC;AAE9B,MAAM,MAAM,sBAAsB,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;AAEhE,qBAAa,oBAAqB,SAAQ,KAAK;gBACjC,MAAM,EAAE,MAAM;CAI3B;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,CA2D9D;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,kBAAkB,GAAG,IAAI,GAAG,IAAI,CAKlE"}
|
|
@@ -7,6 +7,20 @@
|
|
|
7
7
|
* different fields needs no migration.
|
|
8
8
|
*/
|
|
9
9
|
export const ENVELOPE_VERSION = 1;
|
|
10
|
+
/** A secondary token as the envelope stores it, from what the provider sent. */
|
|
11
|
+
export function storedSecondaryToken(token) {
|
|
12
|
+
return {
|
|
13
|
+
accessToken: token.accessToken,
|
|
14
|
+
...(token.refreshToken ? { refreshToken: token.refreshToken } : {}),
|
|
15
|
+
...(token.tokenType ? { tokenType: token.tokenType } : {}),
|
|
16
|
+
...(token.scope ? { scope: token.scope } : {}),
|
|
17
|
+
...(token.expiresInSeconds
|
|
18
|
+
? {
|
|
19
|
+
expiresAt: new Date(Date.now() + token.expiresInSeconds * 1000).toISOString(),
|
|
20
|
+
}
|
|
21
|
+
: {}),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
10
24
|
export class InvalidEnvelopeError extends Error {
|
|
11
25
|
constructor(reason) {
|
|
12
26
|
super(`Stored credential is unusable: ${reason}`);
|
|
@@ -38,12 +52,25 @@ export function parseEnvelope(json) {
|
|
|
38
52
|
if (!isNonEmptyString(envelope.accessToken)) {
|
|
39
53
|
throw new InvalidEnvelopeError('oauth2 envelope has no accessToken');
|
|
40
54
|
}
|
|
55
|
+
assertSecondary(envelope.secondary);
|
|
41
56
|
return envelope;
|
|
42
57
|
case 'api_key':
|
|
43
58
|
if (!isNonEmptyString(envelope.key)) {
|
|
44
59
|
throw new InvalidEnvelopeError('api_key envelope has no key');
|
|
45
60
|
}
|
|
46
61
|
return envelope;
|
|
62
|
+
case 'basic': {
|
|
63
|
+
const basic = envelope;
|
|
64
|
+
// A blank password is a real choice for some APIs; a blank username is
|
|
65
|
+
// not, since the header would then carry nothing identifying.
|
|
66
|
+
if (!isNonEmptyString(basic.username)) {
|
|
67
|
+
throw new InvalidEnvelopeError('basic envelope has no username');
|
|
68
|
+
}
|
|
69
|
+
if (typeof basic.password !== 'string') {
|
|
70
|
+
throw new InvalidEnvelopeError('basic envelope has no password');
|
|
71
|
+
}
|
|
72
|
+
return basic;
|
|
73
|
+
}
|
|
47
74
|
case 'app':
|
|
48
75
|
if (!isNonEmptyString(envelope.installationId)) {
|
|
49
76
|
throw new InvalidEnvelopeError('app envelope has no installationId');
|
|
@@ -68,3 +95,19 @@ export function expiryOf(envelope) {
|
|
|
68
95
|
function isNonEmptyString(value) {
|
|
69
96
|
return typeof value === 'string' && value.length > 0;
|
|
70
97
|
}
|
|
98
|
+
function assertSecondary(secondary) {
|
|
99
|
+
if (secondary === undefined)
|
|
100
|
+
return;
|
|
101
|
+
if (typeof secondary !== 'object' ||
|
|
102
|
+
secondary === null ||
|
|
103
|
+
Array.isArray(secondary)) {
|
|
104
|
+
throw new InvalidEnvelopeError('oauth2 secondary must be an object');
|
|
105
|
+
}
|
|
106
|
+
for (const [kind, credential] of Object.entries(secondary)) {
|
|
107
|
+
if (!credential ||
|
|
108
|
+
typeof credential !== 'object' ||
|
|
109
|
+
!isNonEmptyString(credential.accessToken)) {
|
|
110
|
+
throw new InvalidEnvelopeError(`oauth2 secondary.${kind} has no accessToken`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -32,9 +32,9 @@ let HostRulesService = class HostRulesService {
|
|
|
32
32
|
}
|
|
33
33
|
rules() {
|
|
34
34
|
// The registry is fixed for the life of the process.
|
|
35
|
-
this.compiled ??= this.registry.list().flatMap((integration) => (integration.api
|
|
35
|
+
this.compiled ??= this.registry.list().flatMap((integration) => (integration.api?.egress ?? []).map((rule) => ({
|
|
36
36
|
headers: rule.headers?.bind(rule) ??
|
|
37
|
-
((credential) => integration.api
|
|
37
|
+
((credential) => integration.api?.authHeaders(credential) ?? {}),
|
|
38
38
|
hosts: rule.hosts.map((host) => host.toLowerCase()),
|
|
39
39
|
providerKey: integration.key,
|
|
40
40
|
})));
|
package/dist/index.d.ts
CHANGED
|
@@ -36,5 +36,7 @@ export { HostRulesService, type ResolvedHostRule, } from './egress/host-rules.se
|
|
|
36
36
|
export { ProxyModule } from './proxy/proxy.module.js';
|
|
37
37
|
export { ProxyService, type ProxyRequest, type ProxyResult, } from './proxy/proxy.service.js';
|
|
38
38
|
export { splitUpstreamTarget } from './proxy/proxy.controller.js';
|
|
39
|
+
export { QueryModule } from './query/query.module.js';
|
|
40
|
+
export { QueryService, type QueryRequest, type QueryTarget, } from './query/query.service.js';
|
|
39
41
|
export { HealthController, type HealthResponse, } from './health/health.controller.js';
|
|
40
42
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,YAAY,EACZ,qBAAqB,EACrB,mBAAmB,EACnB,sBAAsB,EACtB,KAAK,WAAW,EAChB,KAAK,mBAAmB,EACxB,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,iBAAiB,GACvB,MAAM,0BAA0B,CAAC;AA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CAAC;AACzD,OAAO,EACL,aAAa,EACb,KAAK,KAAK,EACV,KAAK,cAAc,EACnB,KAAK,WAAW,GACjB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,gBAAgB,EAChB,KAAK,gBAAgB,GACtB,MAAM,gCAAgC,CAAC;AAExC,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EACL,YAAY,EACZ,KAAK,YAAY,EACjB,KAAK,WAAW,GACjB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAElE,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EACL,YAAY,EACZ,KAAK,YAAY,EACjB,KAAK,WAAW,GACjB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,gBAAgB,EAChB,KAAK,cAAc,GACpB,MAAM,+BAA+B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -36,4 +36,6 @@ export { HostRulesService, } from './egress/host-rules.service.js';
|
|
|
36
36
|
export { ProxyModule } from './proxy/proxy.module.js';
|
|
37
37
|
export { ProxyService, } from './proxy/proxy.service.js';
|
|
38
38
|
export { splitUpstreamTarget } from './proxy/proxy.controller.js';
|
|
39
|
+
export { QueryModule } from './query/query.module.js';
|
|
40
|
+
export { QueryService, } from './query/query.service.js';
|
|
39
41
|
export { HealthController, } from './health/health.controller.js';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { KoshaIntegration, OAuthClientContext } from '@kosha-ai/integration-sdk';
|
|
2
|
+
import type { ResolvedKoshaConfig } from '../config/kosha-config.js';
|
|
3
|
+
import type { ProviderConfiguration } from './provider-store.js';
|
|
4
|
+
/**
|
|
5
|
+
* What a package is given to talk to its provider, built from one
|
|
6
|
+
* configuration.
|
|
7
|
+
*
|
|
8
|
+
* One builder for connecting and for refreshing. They were two, and drifted:
|
|
9
|
+
* a refresh that omits something a connect passes fails only once the first
|
|
10
|
+
* token expires, which is long after anyone is watching.
|
|
11
|
+
*/
|
|
12
|
+
export declare function clientContextFor(args: {
|
|
13
|
+
integration: KoshaIntegration;
|
|
14
|
+
configuration: ProviderConfiguration;
|
|
15
|
+
credentials: Record<string, unknown>;
|
|
16
|
+
server: ResolvedKoshaConfig['server'];
|
|
17
|
+
/** The refresh_token grant carries none; the provider returns what it granted. */
|
|
18
|
+
scopes: string[];
|
|
19
|
+
}): OAuthClientContext;
|
|
20
|
+
//# sourceMappingURL=client-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-context.d.ts","sourceRoot":"","sources":["../../src/integrations/client-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,kBAAkB,EACnB,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAEjE;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE;IACrC,WAAW,EAAE,gBAAgB,CAAC;IAC9B,aAAa,EAAE,qBAAqB,CAAC;IACrC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,MAAM,EAAE,mBAAmB,CAAC,QAAQ,CAAC,CAAC;IACtC,kFAAkF;IAClF,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,GAAG,kBAAkB,CAerB"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a package is given to talk to its provider, built from one
|
|
3
|
+
* configuration.
|
|
4
|
+
*
|
|
5
|
+
* One builder for connecting and for refreshing. They were two, and drifted:
|
|
6
|
+
* a refresh that omits something a connect passes fails only once the first
|
|
7
|
+
* token expires, which is long after anyone is watching.
|
|
8
|
+
*/
|
|
9
|
+
export function clientContextFor(args) {
|
|
10
|
+
const { publicUrl, globalPrefix } = args.server;
|
|
11
|
+
const secret = args.credentials['clientSecret'];
|
|
12
|
+
return {
|
|
13
|
+
clientId: String(args.credentials['clientId'] ?? ''),
|
|
14
|
+
// Absent rather than '': a provider that issued no secret can reject a
|
|
15
|
+
// request that carries one.
|
|
16
|
+
clientSecret: typeof secret === 'string' ? secret : '',
|
|
17
|
+
redirectUri: `${publicUrl}/${globalPrefix}/connect/callback/${args.integration.key}`,
|
|
18
|
+
scopes: args.scopes,
|
|
19
|
+
// The package's own columns, for a provider whose endpoints are not
|
|
20
|
+
// knowable from the package alone.
|
|
21
|
+
fields: args.configuration.fields,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -17,6 +17,10 @@ export interface IntegrationSummary {
|
|
|
17
17
|
/** What this integration asks for. What an operator must grant. */
|
|
18
18
|
scopesRequested: string[];
|
|
19
19
|
pkce: boolean;
|
|
20
|
+
/** False for a provider with no OAuth app, so a configuration needs no client id. */
|
|
21
|
+
requiresClientCredentials: boolean;
|
|
22
|
+
/** What the end user supplies, for a provider whose credential they already hold. */
|
|
23
|
+
credentialFields: NonNullable<KoshaIntegration['auth']['credentialFields']>;
|
|
20
24
|
configFields: NonNullable<KoshaIntegration['configFields']>;
|
|
21
25
|
supportsWebhooks: boolean;
|
|
22
26
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"integrations.controller.d.ts","sourceRoot":"","sources":["../../src/integrations/integrations.controller.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAEhE;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,+EAA+E;IAC/E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,mEAAmE;IACnE,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,IAAI,EAAE,OAAO,CAAC;IACd,YAAY,EAAE,WAAW,CAAC,gBAAgB,CAAC,cAAc,CAAC,CAAC,CAAC;IAC5D,gBAAgB,EAAE,OAAO,CAAC;CAC3B;AAED,qBACa,sBAAsB;IACrB,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAAR,QAAQ,EAAE,mBAAmB;IAG1D,IAAI,IAAI,kBAAkB,EAAE;IAK5B,GAAG,CAAe,GAAG,EAAE,MAAM,GAAG,kBAAkB;CAGnD"}
|
|
1
|
+
{"version":3,"file":"integrations.controller.d.ts","sourceRoot":"","sources":["../../src/integrations/integrations.controller.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAEhE;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,+EAA+E;IAC/E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,mEAAmE;IACnE,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,IAAI,EAAE,OAAO,CAAC;IACd,qFAAqF;IACrF,yBAAyB,EAAE,OAAO,CAAC;IACnC,qFAAqF;IACrF,gBAAgB,EAAE,WAAW,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC;IAC5E,YAAY,EAAE,WAAW,CAAC,gBAAgB,CAAC,cAAc,CAAC,CAAC,CAAC;IAC5D,gBAAgB,EAAE,OAAO,CAAC;CAC3B;AAED,qBACa,sBAAsB;IACrB,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAAR,QAAQ,EAAE,mBAAmB;IAG1D,IAAI,IAAI,kBAAkB,EAAE;IAK5B,GAAG,CAAe,GAAG,EAAE,MAAM,GAAG,kBAAkB;CAGnD"}
|
|
@@ -38,10 +38,12 @@ function toSummary(integration) {
|
|
|
38
38
|
logo: integration.logo,
|
|
39
39
|
docsUrl: integration.docsUrl,
|
|
40
40
|
authType: integration.auth.type,
|
|
41
|
-
apiBaseUrl: integration.api
|
|
41
|
+
apiBaseUrl: integration.api?.baseUrl,
|
|
42
42
|
scopesAvailable: integration.auth.scopesAvailable,
|
|
43
43
|
scopesRequested: integration.auth.scopesRequested,
|
|
44
44
|
pkce: integration.auth.pkce,
|
|
45
|
+
requiresClientCredentials: integration.auth.requiresClientCredentials ?? true,
|
|
46
|
+
credentialFields: integration.auth.credentialFields ?? [],
|
|
45
47
|
configFields: integration.configFields ?? [],
|
|
46
48
|
supportsWebhooks: Boolean(integration.webhooks),
|
|
47
49
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type OnApplicationBootstrap } from '@nestjs/common';
|
|
2
|
-
import type { KoshaIntegration } from '@kosha-ai/integration-sdk';
|
|
2
|
+
import type { ConfigurationFields, KoshaIntegration } from '@kosha-ai/integration-sdk';
|
|
3
3
|
import { Prisma } from '../generated/prisma/client.js';
|
|
4
4
|
import { PrismaService } from '../prisma/prisma.service.js';
|
|
5
5
|
import { IntegrationRegistry } from './integration.registry.js';
|
|
6
|
-
/** The columns every provider's configuration table has.
|
|
6
|
+
/** The columns every provider's configuration table has. */
|
|
7
7
|
export interface ProviderConfiguration {
|
|
8
8
|
id: string;
|
|
9
9
|
environmentId: string;
|
|
@@ -13,6 +13,8 @@ export interface ProviderConfiguration {
|
|
|
13
13
|
credentials: string | null;
|
|
14
14
|
createdAt: Date;
|
|
15
15
|
updatedAt: Date;
|
|
16
|
+
/** Whatever else this provider's own table holds, by column name. */
|
|
17
|
+
fields: ConfigurationFields;
|
|
16
18
|
}
|
|
17
19
|
/** A configuration as a client may see it: everything but the secrets. */
|
|
18
20
|
export type PublicProviderConfiguration = Omit<ProviderConfiguration, 'credentials'>;
|
|
@@ -29,12 +31,16 @@ export interface CreateConfiguration {
|
|
|
29
31
|
environmentId: string;
|
|
30
32
|
name: string;
|
|
31
33
|
slug: string;
|
|
34
|
+
/** This provider's own columns, already checked against its configFields. */
|
|
35
|
+
fields?: ConfigurationFields;
|
|
32
36
|
credentials?: string | null;
|
|
33
37
|
}
|
|
34
38
|
/** Only what is given is written; anything absent is left alone. */
|
|
35
39
|
export interface UpdateConfiguration {
|
|
36
40
|
name?: string;
|
|
37
41
|
credentials?: string | null;
|
|
42
|
+
/** Only the columns given are written; the rest keep what they hold. */
|
|
43
|
+
fields?: ConfigurationFields;
|
|
38
44
|
}
|
|
39
45
|
export interface StoreConnection {
|
|
40
46
|
accountId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider-store.d.ts","sourceRoot":"","sources":["../../src/integrations/provider-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,sBAAsB,EAC5B,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"provider-store.d.ts","sourceRoot":"","sources":["../../src/integrations/provider-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,sBAAsB,EAC5B,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EACV,mBAAmB,EACnB,gBAAgB,EACjB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAEhE,4DAA4D;AAC5D,MAAM,WAAW,qBAAqB;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