@kosha-ai/server 0.5.2 → 0.5.4

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.
@@ -1 +1 @@
1
- {"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,KAAK,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAK/E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAI5D;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC,gBAAgB,CAAC,CAiF3B;AAED,gCAAgC;AAChC,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC,gBAAgB,CAAC,CAkB3B"}
1
+ {"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,KAAK,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAM/E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAI5D;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC,gBAAgB,CAAC,CAiF3B;AAED,gCAAgC;AAChC,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC,gBAAgB,CAAC,CAkB3B"}
package/dist/bootstrap.js CHANGED
@@ -3,6 +3,7 @@ import { NestFactory } from '@nestjs/core';
3
3
  import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
4
4
  import express from 'express';
5
5
  import { createAdminProxy } from './admin-proxy.js';
6
+ import { REQUEST_BODY_LIMIT } from './common/body-limit.js';
6
7
  import { resolveConfig } from './config/kosha-config.js';
7
8
  import { KoshaModule } from './kosha.module.js';
8
9
  /**
@@ -45,7 +46,7 @@ export async function createKoshaServer(config) {
45
46
  !contentType.startsWith('application/x-www-form-urlencoded') &&
46
47
  !contentType.startsWith('multipart/form-data'));
47
48
  },
48
- limit: '50mb',
49
+ limit: REQUEST_BODY_LIMIT,
49
50
  }));
50
51
  // `whitelist` strips properties no DTO declares, so an endpoint can only
51
52
  // ever see what it asked for. Better Auth's own routes are mounted by the
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Largest request body Kosha accepts, for raw proxy uploads and for JSON and
3
+ * form bodies alike. Proxied JSON often carries whole files (a Gmail `raw`
4
+ * message is the base64 of a MIME message that itself base64-encodes its
5
+ * attachments), so the parsers' 100 KB default rejects ordinary attachments.
6
+ */
7
+ export declare const REQUEST_BODY_LIMIT = "50mb";
8
+ //# sourceMappingURL=body-limit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"body-limit.d.ts","sourceRoot":"","sources":["../../src/common/body-limit.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,SAAS,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Largest request body Kosha accepts, for raw proxy uploads and for JSON and
3
+ * form bodies alike. Proxied JSON often carries whole files (a Gmail `raw`
4
+ * message is the base64 of a MIME message that itself base64-encodes its
5
+ * attachments), so the parsers' 100 KB default rejects ordinary attachments.
6
+ */
7
+ export const REQUEST_BODY_LIMIT = '50mb';
@@ -1 +1 @@
1
- {"version":3,"file":"kosha.module.d.ts","sourceRoot":"","sources":["../src/kosha.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAU,MAAM,gBAAgB,CAAC;AAGvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAiB5D;;;;GAIG;AACH,qBACa,WAAW;IACtB,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,WAAW,GAAG,aAAa;CAiCnD"}
1
+ {"version":3,"file":"kosha.module.d.ts","sourceRoot":"","sources":["../src/kosha.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAU,MAAM,gBAAgB,CAAC;AAIvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAiB5D;;;;GAIG;AACH,qBACa,WAAW;IACtB,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,WAAW,GAAG,aAAa;CAsCnD"}
@@ -3,6 +3,7 @@ import { __decorate } from "tslib";
3
3
  import { Module } from '@nestjs/common';
4
4
  import { AuthModule } from '@thallesp/nestjs-better-auth';
5
5
  import { createAuth } from './auth/auth.factory.js';
6
+ import { REQUEST_BODY_LIMIT } from './common/body-limit.js';
6
7
  import { resolveConfig } from './config/kosha-config.js';
7
8
  import { ConfigurationsModule } from './configurations/configurations.module.js';
8
9
  import { EnvironmentsModule } from './environments/environments.module.js';
@@ -36,6 +37,11 @@ let KoshaModule = KoshaModule_1 = class KoshaModule {
36
37
  inject: [PrismaService, EnvironmentsService],
37
38
  useFactory: (prisma, environments) => ({
38
39
  auth: createAuth(resolved, prisma, environments),
40
+ // These parsers serve every non-auth route, the proxy included.
41
+ bodyParser: {
42
+ json: { limit: REQUEST_BODY_LIMIT },
43
+ urlencoded: { limit: REQUEST_BODY_LIMIT },
44
+ },
39
45
  }),
40
46
  }),
41
47
  IntegrationsModule.forRoot(resolved.integrations),
@@ -1 +1 @@
1
- {"version":3,"file":"query.controller.d.ts","sourceRoot":"","sources":["../../src/query/query.controller.ts"],"names":[],"mappings":"AAWA,OAAO,EAAe,KAAK,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,qBAEa,eAAe;IACd,OAAO,CAAC,QAAQ,CAAC,KAAK;gBAAL,KAAK,EAAE,YAAY;IAEhD;;;;;OAKG;IAaG,GAAG,CACA,OAAO,EAAE,aAAa,EACV,QAAQ,EAAE,MAAM,EACP,iBAAiB,EAAE,MAAM,EACrC,KAAK,EAAE,MAAM,EACrB,IAAI,EAAE,WAAW;CAe5B"}
1
+ {"version":3,"file":"query.controller.d.ts","sourceRoot":"","sources":["../../src/query/query.controller.ts"],"names":[],"mappings":"AAWA,OAAO,EAAe,KAAK,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAuB,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvE,qBAEa,eAAe;IACd,OAAO,CAAC,QAAQ,CAAC,KAAK;gBAAL,KAAK,EAAE,YAAY;IAEhD;;;;;OAKG;IAaG,GAAG,CACA,OAAO,EAAE,aAAa,EACV,QAAQ,EAAE,MAAM,EACP,iBAAiB,EAAE,MAAM,EACrC,KAAK,EAAE,MAAM,EACrB,IAAI,EAAE,WAAW;CA0B5B"}
@@ -4,7 +4,7 @@ import { ApiOperation, ApiSecurity, ApiTags } from '@nestjs/swagger';
4
4
  import { AllowAnonymous } from '@thallesp/nestjs-better-auth';
5
5
  import { ApiKeyGuard } from '../auth/api-key.guard.js';
6
6
  import { RunQueryDto } from './dto/run-query.dto.js';
7
- import { QueryService } from './query.service.js';
7
+ import { QueryExecutionError, QueryService } from './query.service.js';
8
8
  let QueryController = class QueryController {
9
9
  query;
10
10
  constructor(query) {
@@ -20,7 +20,19 @@ let QueryController = class QueryController {
20
20
  if (!request.environmentId) {
21
21
  throw new BadRequestException('This route needs an API key, which is what names the environment');
22
22
  }
23
- return this.query.run(request.organizationId, request.environmentId, { provider, configurationSlug, owner }, { sql: body.sql, params: body.params });
23
+ try {
24
+ return await this.query.run(request.organizationId, request.environmentId, { provider, configurationSlug, owner }, { sql: body.sql, params: body.params });
25
+ }
26
+ catch (error) {
27
+ // Query integrations execute against external databases. Their driver
28
+ // errors are plain Errors, which Nest otherwise turns into the generic
29
+ // 500 "Internal server error" response. A malformed SQL query is a
30
+ // client error, so expose the driver's message as a 400 response.
31
+ if (error instanceof QueryExecutionError) {
32
+ throw new BadRequestException(error.message);
33
+ }
34
+ throw error;
35
+ }
24
36
  }
25
37
  };
26
38
  __decorate([
@@ -14,6 +14,10 @@ export interface QueryRequest {
14
14
  sql: string;
15
15
  params?: unknown[];
16
16
  }
17
+ /** A query reached the connected provider, but the provider rejected it. */
18
+ export declare class QueryExecutionError extends Error {
19
+ constructor(message: string);
20
+ }
17
21
  /**
18
22
  * The direct-connection counterpart to `ProxyService`: a query-shaped
19
23
  * integration (declares `query`, not `api`) has no REST API to forward an
@@ -1 +1 @@
1
- {"version":3,"file":"query.service.d.ts","sourceRoot":"","sources":["../../src/query/query.service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAC3E,OAAO,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAC9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAC9E,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAE/D,yFAAyF;AACzF,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC;CACpB;AAED;;;;;GAKG;AACH,qBACa,YAAY;IAErB,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAJR,KAAK,EAAE,eAAe,EACtB,YAAY,EAAE,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ACjC,KAAK,EAAE,aAAa,EACpB,QAAQ,EAAE,mBAAmB,EAC7B,QAAQ,EAAE,kBAAkB;IAGzC,GAAG,CACP,cAAc,EAAE,MAAM,EACtB,aAAa,EAAE,MAAM,EACrB,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE,YAAY,GACpB,OAAO,CAAC,WAAW,CAAC;CA8DxB"}
@@ -5,6 +5,13 @@ import { EnvironmentsService } from '../environments/environments.service.js';
5
5
  import { IntegrationRegistry } from '../integrations/integration.registry.js';
6
6
  import { ProviderStore } from '../integrations/provider-store.js';
7
7
  import { ProxyRepository } from '../proxy/proxy.repository.js';
8
+ /** A query reached the connected provider, but the provider rejected it. */
9
+ export class QueryExecutionError extends Error {
10
+ constructor(message) {
11
+ super(message);
12
+ this.name = 'QueryExecutionError';
13
+ }
14
+ }
8
15
  /**
9
16
  * The direct-connection counterpart to `ProxyService`: a query-shaped
10
17
  * integration (declares `query`, not `api`) has no REST API to forward an
@@ -48,16 +55,21 @@ let QueryService = class QueryService {
48
55
  if (!account)
49
56
  throw new NotFoundException('Connection not found');
50
57
  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
- });
58
+ try {
59
+ return await integration.query.run({
60
+ credential: {
61
+ accessToken: credential.accessToken,
62
+ tokenType: credential.tokenType,
63
+ },
64
+ fields: configuration.fields,
65
+ metadata: asMetadata(connection.metadata),
66
+ sql: request.sql,
67
+ params: request.params,
68
+ });
69
+ }
70
+ catch (error) {
71
+ throw new QueryExecutionError(error instanceof Error ? error.message : String(error));
72
+ }
61
73
  }
62
74
  };
63
75
  QueryService = __decorate([
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kosha-ai/server",
3
- "version": "0.5.2",
3
+ "version": "0.5.4",
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.5.2"
112
+ "@kosha-ai/integration-sdk": "0.5.4"
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.5.2",
121
- "@kosha-ai/integration-slack": "0.5.2"
120
+ "@kosha-ai/integration-github": "0.5.4",
121
+ "@kosha-ai/integration-slack": "0.5.4"
122
122
  }
123
123
  }