@kosha-ai/server 0.4.2 → 0.5.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.
|
@@ -38,9 +38,13 @@ export declare class ConfigurationsService {
|
|
|
38
38
|
*/
|
|
39
39
|
getWithCredentials(provider: string, configurationId: string): Promise<ConfigurationWithCredentials>;
|
|
40
40
|
/**
|
|
41
|
-
* Refuses a
|
|
42
|
-
*
|
|
43
|
-
*
|
|
41
|
+
* Refuses a value an operator should be told about now rather than by a
|
|
42
|
+
* failure later: a URL that would have the server fetch cloud metadata, or
|
|
43
|
+
* a value the package says is malformed.
|
|
44
|
+
*
|
|
45
|
+
* Both are checked again at the point of use. A hostname can resolve
|
|
46
|
+
* somewhere else tomorrow, and a value saved before a pattern was added has
|
|
47
|
+
* never been through it.
|
|
44
48
|
*/
|
|
45
49
|
private checkedFields;
|
|
46
50
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configurations.service.d.ts","sourceRoot":"","sources":["../../src/configurations/configurations.service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"configurations.service.d.ts","sourceRoot":"","sources":["../../src/configurations/configurations.service.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAC9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAC9E,OAAO,EACL,aAAa,EACb,KAAK,qBAAqB,EAC1B,KAAK,2BAA2B,EACjC,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAChF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAEhF,kFAAkF;AAClF,MAAM,MAAM,sBAAsB,GAAG,2BAA2B,GAAG;IACjE,QAAQ,EAAE,MAAM,CAAC;IAC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AAE,MAAM,GACT,OAAO,CAAC,IAAI,CAAC;IAMhB;;;OAGG;IACG,kBAAkB,CACtB,QAAQ,EAAE,MAAM,EAChB,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,4BAA4B,CAAC;IAmBxC;;;;;;;;OAQG;YACW,aAAa;IAkC3B;;;;;OAKG;IACH,OAAO,CAAC,eAAe;CA2BxB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
2
|
import { BadRequestException, ConflictException, Injectable, NotFoundException, } from '@nestjs/common';
|
|
3
|
-
import {
|
|
3
|
+
import { assertAllowedHost, assertAllowedUrl } 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';
|
|
@@ -99,24 +99,33 @@ let ConfigurationsService = class ConfigurationsService {
|
|
|
99
99
|
};
|
|
100
100
|
}
|
|
101
101
|
/**
|
|
102
|
-
* Refuses a
|
|
103
|
-
*
|
|
104
|
-
*
|
|
102
|
+
* Refuses a value an operator should be told about now rather than by a
|
|
103
|
+
* failure later: a URL that would have the server fetch cloud metadata, or
|
|
104
|
+
* a value the package says is malformed.
|
|
105
|
+
*
|
|
106
|
+
* Both are checked again at the point of use. A hostname can resolve
|
|
107
|
+
* somewhere else tomorrow, and a value saved before a pattern was added has
|
|
108
|
+
* never been through it.
|
|
105
109
|
*/
|
|
106
110
|
async checkedFields(integration, fields) {
|
|
107
111
|
for (const field of integration.configFields ?? []) {
|
|
108
112
|
const value = fields?.[field.key];
|
|
109
113
|
if (typeof value !== 'string')
|
|
110
114
|
continue;
|
|
115
|
+
// Anchored here rather than trusting the package to have done it: an
|
|
116
|
+
// unanchored `[a-z]+` matches inside `acme/evil`, so a pattern meant to
|
|
117
|
+
// constrain a value would quietly accept one that escapes it.
|
|
118
|
+
if (field.pattern !== undefined &&
|
|
119
|
+
!new RegExp(`^(?:${field.pattern})$`, 'v').test(value)) {
|
|
120
|
+
throw new BadRequestException(`${field.label} is not in the expected format`);
|
|
121
|
+
}
|
|
111
122
|
if (field.type !== 'url' && field.type !== 'host')
|
|
112
123
|
continue;
|
|
113
124
|
try {
|
|
114
125
|
if (field.type === 'url')
|
|
115
|
-
await
|
|
116
|
-
else if (integration.key === 'postgres')
|
|
117
|
-
await assertResolvableHost(value);
|
|
126
|
+
await assertAllowedUrl(value);
|
|
118
127
|
else
|
|
119
|
-
await
|
|
128
|
+
await assertAllowedHost(value);
|
|
120
129
|
}
|
|
121
130
|
catch (error) {
|
|
122
131
|
throw new BadRequestException(error instanceof Error ? error.message : `${field.label} is invalid`);
|
|
@@ -174,7 +183,9 @@ function declaredFields(integration, supplied, options = {}) {
|
|
|
174
183
|
const fields = {};
|
|
175
184
|
for (const field of declared) {
|
|
176
185
|
const value = supplied?.[field.key];
|
|
177
|
-
if (value === undefined ||
|
|
186
|
+
if (value === undefined ||
|
|
187
|
+
value === '' ||
|
|
188
|
+
(Array.isArray(value) && value.length === 0)) {
|
|
178
189
|
// On create a required field must be there; on update, absent means
|
|
179
190
|
// "leave what is stored".
|
|
180
191
|
if (options.required && field.required) {
|
|
@@ -182,6 +193,13 @@ function declaredFields(integration, supplied, options = {}) {
|
|
|
182
193
|
}
|
|
183
194
|
continue;
|
|
184
195
|
}
|
|
196
|
+
if (field.type === 'select') {
|
|
197
|
+
const allowed = new Set((field.options ?? []).map((option) => option.value));
|
|
198
|
+
const values = Array.isArray(value) ? value : [value];
|
|
199
|
+
if (values.some((option) => typeof option !== 'string' || !allowed.has(option))) {
|
|
200
|
+
throw new BadRequestException(`${field.label} contains an unsupported option`);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
185
203
|
fields[field.key] = value;
|
|
186
204
|
}
|
|
187
205
|
return Object.keys(fields).length > 0 ? fields : undefined;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
|
-
import {
|
|
2
|
+
import { assertAllowedUrl } from '@kosha-ai/integration-sdk';
|
|
3
3
|
import { BadGatewayException, BadRequestException, Injectable, NotFoundException, } from '@nestjs/common';
|
|
4
4
|
import { CredentialsService } from '../credentials/credentials.service.js';
|
|
5
5
|
import { EnvironmentsService } from '../environments/environments.service.js';
|
|
@@ -87,9 +87,9 @@ let ProxyService = class ProxyService {
|
|
|
87
87
|
throw new BadGatewayException('Provider has no resolvable base URL for this connection');
|
|
88
88
|
}
|
|
89
89
|
// Re-resolved per call, not only when saved: a host that answered
|
|
90
|
-
//
|
|
90
|
+
// elsewhere yesterday can point at cloud metadata today.
|
|
91
91
|
if (resolved)
|
|
92
|
-
await
|
|
92
|
+
await assertAllowedUrl(baseUrl);
|
|
93
93
|
const targetUrl = this.buildTargetUrl(baseUrl, request);
|
|
94
94
|
/*
|
|
95
95
|
* Header names are compared lowercased, and the integration's headers are
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kosha-ai/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.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.5.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-
|
|
121
|
-
"@kosha-ai/integration-
|
|
120
|
+
"@kosha-ai/integration-github": "0.5.1",
|
|
121
|
+
"@kosha-ai/integration-slack": "0.5.1"
|
|
122
122
|
}
|
|
123
123
|
}
|