@kosha-ai/server 0.0.2 → 0.0.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.
Files changed (42) hide show
  1. package/dist/admin-proxy.d.ts +32 -0
  2. package/dist/admin-proxy.d.ts.map +1 -0
  3. package/dist/admin-proxy.js +88 -0
  4. package/dist/auth/api-key.guard.d.ts +10 -0
  5. package/dist/auth/api-key.guard.d.ts.map +1 -1
  6. package/dist/auth/api-key.guard.js +36 -5
  7. package/dist/auth/auth.factory.d.ts +5 -0
  8. package/dist/auth/auth.factory.d.ts.map +1 -1
  9. package/dist/auth/auth.factory.js +31 -2
  10. package/dist/bootstrap.d.ts.map +1 -1
  11. package/dist/bootstrap.js +6 -1
  12. package/dist/configurations/configurations.controller.d.ts +32 -28
  13. package/dist/configurations/configurations.controller.d.ts.map +1 -1
  14. package/dist/configurations/configurations.service.d.ts +41 -35
  15. package/dist/configurations/configurations.service.d.ts.map +1 -1
  16. package/dist/configurations/configurations.service.js +12 -0
  17. package/dist/connect/connect.controller.d.ts +8 -10
  18. package/dist/connect/connect.controller.d.ts.map +1 -1
  19. package/dist/connect/connect.controller.js +8 -6
  20. package/dist/connect/connect.service.d.ts +2 -1
  21. package/dist/connect/connect.service.d.ts.map +1 -1
  22. package/dist/connect/connect.service.js +8 -3
  23. package/dist/connections/connections.controller.d.ts +16 -16
  24. package/dist/connections/connections.controller.d.ts.map +1 -1
  25. package/dist/connections/connections.controller.js +14 -12
  26. package/dist/connections/connections.service.d.ts +12 -12
  27. package/dist/generated/prisma/internal/class.js +4 -4
  28. package/dist/generated/prisma/internal/prismaNamespace.d.ts +1 -0
  29. package/dist/generated/prisma/internal/prismaNamespace.d.ts.map +1 -1
  30. package/dist/generated/prisma/internal/prismaNamespace.js +1 -0
  31. package/dist/generated/prisma/internal/prismaNamespaceBrowser.d.ts +1 -0
  32. package/dist/generated/prisma/internal/prismaNamespaceBrowser.d.ts.map +1 -1
  33. package/dist/generated/prisma/internal/prismaNamespaceBrowser.js +1 -0
  34. package/dist/generated/prisma/models/Configuration.d.ts +56 -2
  35. package/dist/generated/prisma/models/Configuration.d.ts.map +1 -1
  36. package/dist/index.d.ts +1 -1
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +1 -1
  39. package/dist/integrations/integration.registry.d.ts.map +1 -1
  40. package/package.json +4 -4
  41. package/prisma/migrations/20260916000000_add_configuration_slug/migration.sql +15 -0
  42. package/prisma/schema.prisma +2 -0
@@ -0,0 +1,32 @@
1
+ import type { IncomingHttpHeaders, IncomingMessage, ServerResponse } from 'node:http';
2
+ /**
3
+ * Drops per-connection headers, plus any header that `Connection` itself
4
+ * names. A sender uses that list to mark a header as meant for the next
5
+ * recipient only, so honouring it keeps internal headers from leaking through
6
+ * the proxy.
7
+ */
8
+ export declare function stripHopByHopHeaders(headers: IncomingHttpHeaders): IncomingHttpHeaders;
9
+ export interface AdminProxyOptions {
10
+ /** Port the admin UI listens on, on the loopback interface. */
11
+ adminPort: number;
12
+ /** The server's own prefix. Everything under it stays with Nest. */
13
+ globalPrefix: string;
14
+ }
15
+ type Next = (error?: unknown) => void;
16
+ /**
17
+ * Lets the server answer for the whole app on one port.
18
+ *
19
+ * `kosha start` runs the Nest server and the admin UI on two ports. Without
20
+ * this, deploying meant either two hostnames or a reverse proxy in front of
21
+ * both. Here `/api/*` stays with Nest and everything else is piped to the
22
+ * admin over loopback, so a single URL serves the API and the UI.
23
+ *
24
+ * One origin also keeps the session cookie same-site, so it survives without
25
+ * `SameSite=None` or https, and CORS never comes up.
26
+ *
27
+ * ponytail: no WebSocket upgrade handling. The admin's production build never
28
+ * opens one. Forward the server's `upgrade` event if that changes.
29
+ */
30
+ export declare function createAdminProxy(options: AdminProxyOptions): (req: IncomingMessage, res: ServerResponse, next: Next) => void;
31
+ export {};
32
+ //# sourceMappingURL=admin-proxy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"admin-proxy.d.ts","sourceRoot":"","sources":["../src/admin-proxy.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,mBAAmB,EACnB,eAAe,EACf,cAAc,EACf,MAAM,WAAW,CAAC;AAmBnB;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,mBAAmB,GAC3B,mBAAmB,CAmBrB;AAED,MAAM,WAAW,iBAAiB;IAChC,+DAA+D;IAC/D,SAAS,EAAE,MAAM,CAAC;IAClB,oEAAoE;IACpE,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,KAAK,IAAI,GAAG,CAAC,KAAK,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;AAEtC;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,iBAAiB,IAIvD,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,MAAM,IAAI,KACT,IAAI,CAyCR"}
@@ -0,0 +1,88 @@
1
+ import { request as httpRequest } from 'node:http';
2
+ /**
3
+ * Headers that belong to one connection rather than to the message, so they
4
+ * must not be forwarded (RFC 9110 §7.6.1). `transfer-encoding` is the one that
5
+ * causes real damage: Node frames the forwarded response itself, and setting
6
+ * upstream's framing on top of that corrupts the body.
7
+ */
8
+ const HOP_BY_HOP_HEADERS = new Set([
9
+ 'connection',
10
+ 'keep-alive',
11
+ 'proxy-authenticate',
12
+ 'proxy-authorization',
13
+ 'te',
14
+ 'trailer',
15
+ 'transfer-encoding',
16
+ 'upgrade',
17
+ ]);
18
+ /**
19
+ * Drops per-connection headers, plus any header that `Connection` itself
20
+ * names. A sender uses that list to mark a header as meant for the next
21
+ * recipient only, so honouring it keeps internal headers from leaking through
22
+ * the proxy.
23
+ */
24
+ export function stripHopByHopHeaders(headers) {
25
+ const connection = headers.connection;
26
+ const named = typeof connection === 'string'
27
+ ? connection
28
+ .split(',')
29
+ .map((token) => token.trim().toLowerCase())
30
+ .filter(Boolean)
31
+ : [];
32
+ const forwarded = {};
33
+ for (const [name, value] of Object.entries(headers)) {
34
+ const lower = name.toLowerCase();
35
+ if (HOP_BY_HOP_HEADERS.has(lower) || named.includes(lower))
36
+ continue;
37
+ forwarded[name] = value;
38
+ }
39
+ return forwarded;
40
+ }
41
+ /**
42
+ * Lets the server answer for the whole app on one port.
43
+ *
44
+ * `kosha start` runs the Nest server and the admin UI on two ports. Without
45
+ * this, deploying meant either two hostnames or a reverse proxy in front of
46
+ * both. Here `/api/*` stays with Nest and everything else is piped to the
47
+ * admin over loopback, so a single URL serves the API and the UI.
48
+ *
49
+ * One origin also keeps the session cookie same-site, so it survives without
50
+ * `SameSite=None` or https, and CORS never comes up.
51
+ *
52
+ * ponytail: no WebSocket upgrade handling. The admin's production build never
53
+ * opens one. Forward the server's `upgrade` event if that changes.
54
+ */
55
+ export function createAdminProxy(options) {
56
+ const apiPrefix = `/${options.globalPrefix}`;
57
+ return function adminProxy(req, res, next) {
58
+ const url = req.url ?? '/';
59
+ // Match on a boundary so a path like `/apidocs` is not taken for the API.
60
+ const isApi = url === apiPrefix ||
61
+ url.startsWith(`${apiPrefix}/`) ||
62
+ url.startsWith(`${apiPrefix}?`);
63
+ if (isApi) {
64
+ next();
65
+ return;
66
+ }
67
+ const upstream = httpRequest({
68
+ host: '127.0.0.1',
69
+ port: options.adminPort,
70
+ method: req.method,
71
+ path: url,
72
+ // `host` is forwarded on purpose, so the admin builds absolute URLs
73
+ // from the public hostname instead of loopback.
74
+ headers: stripHopByHopHeaders(req.headers),
75
+ });
76
+ upstream.on('response', (adminRes) => {
77
+ res.writeHead(adminRes.statusCode ?? 502, stripHopByHopHeaders(adminRes.headers));
78
+ adminRes.pipe(res);
79
+ });
80
+ upstream.on('error', () => {
81
+ if (!res.headersSent) {
82
+ res.writeHead(502, { 'content-type': 'text/plain' });
83
+ }
84
+ res.end('Kosha admin UI is not reachable.');
85
+ });
86
+ req.pipe(upstream);
87
+ };
88
+ }
@@ -4,6 +4,11 @@ import type { Request } from 'express';
4
4
  import type { KoshaAuth } from './auth.factory.js';
5
5
  export interface ApiKeyRequest extends Request {
6
6
  organizationId: string;
7
+ session?: {
8
+ session?: {
9
+ activeOrganizationId?: string | null;
10
+ };
11
+ } | null;
7
12
  }
8
13
  /**
9
14
  * Authenticates machine-to-machine calls with `x-api-key` and puts the owning
@@ -15,4 +20,9 @@ export declare class ApiKeyGuard implements CanActivate {
15
20
  constructor(authService: AuthService<KoshaAuth>);
16
21
  canActivate(context: ExecutionContext): Promise<boolean>;
17
22
  }
23
+ export declare class OrgAuthGuard implements CanActivate {
24
+ private readonly authService;
25
+ constructor(authService: AuthService<KoshaAuth>);
26
+ canActivate(context: ExecutionContext): Promise<boolean>;
27
+ }
18
28
  //# sourceMappingURL=api-key.guard.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"api-key.guard.d.ts","sourceRoot":"","sources":["../../src/auth/api-key.guard.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,gBAAgB,EAIjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,MAAM,WAAW,aAAc,SAAQ,OAAO;IAC5C,cAAc,EAAE,MAAM,CAAC;CACxB;AAED;;;;GAIG;AACH,qBACa,WAAY,YAAW,WAAW;IAG3C,OAAO,CAAC,QAAQ,CAAC,WAAW;gBAAX,WAAW,EAAE,WAAW,CAAC,SAAS,CAAC;IAGhD,WAAW,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;CAgB/D"}
1
+ {"version":3,"file":"api-key.guard.d.ts","sourceRoot":"","sources":["../../src/auth/api-key.guard.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,gBAAgB,EAIjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,MAAM,WAAW,aAAc,SAAQ,OAAO;IAC5C,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE;YAAE,oBAAoB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;SAAE,CAAA;KAAE,GAAG,IAAI,CAAC;CACzE;AAiBD;;;;GAIG;AACH,qBACa,WAAY,YAAW,WAAW;IAG3C,OAAO,CAAC,QAAQ,CAAC,WAAW;gBAAX,WAAW,EAAE,WAAW,CAAC,SAAS,CAAC;IAGhD,WAAW,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;CAc/D;AAED,qBACa,YAAa,YAAW,WAAW;IAG5C,OAAO,CAAC,QAAQ,CAAC,WAAW;gBAAX,WAAW,EAAE,WAAW,CAAC,SAAS,CAAC;IAGhD,WAAW,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;CAsB/D"}
@@ -1,6 +1,15 @@
1
1
  import { __decorate, __metadata, __param } from "tslib";
2
2
  import { Inject, Injectable, UnauthorizedException, } from '@nestjs/common';
3
3
  import { AuthService } from '@thallesp/nestjs-better-auth';
4
+ /** Verifies an org-scoped API key. Throws rather than returning false. */
5
+ async function organizationIdForApiKey(authService, key) {
6
+ const result = await authService.api.verifyApiKey({ body: { key } });
7
+ if (!result.valid || !result.key?.referenceId) {
8
+ const code = result.error?.code;
9
+ throw new UnauthorizedException(code ? `API key rejected: ${code}` : 'Invalid API key');
10
+ }
11
+ return result.key.referenceId;
12
+ }
4
13
  /**
5
14
  * Authenticates machine-to-machine calls with `x-api-key` and puts the owning
6
15
  * organization on the request. Keys are org-scoped: Better Auth's API-key
@@ -17,11 +26,7 @@ let ApiKeyGuard = class ApiKeyGuard {
17
26
  if (!key || typeof key !== 'string') {
18
27
  throw new UnauthorizedException('Missing x-api-key header');
19
28
  }
20
- const result = await this.authService.api.verifyApiKey({ body: { key } });
21
- if (!result.valid || !result.key?.referenceId) {
22
- throw new UnauthorizedException('Invalid API key');
23
- }
24
- request.organizationId = result.key.referenceId;
29
+ request.organizationId = await organizationIdForApiKey(this.authService, key);
25
30
  return true;
26
31
  }
27
32
  };
@@ -31,3 +36,29 @@ ApiKeyGuard = __decorate([
31
36
  __metadata("design:paramtypes", [AuthService])
32
37
  ], ApiKeyGuard);
33
38
  export { ApiKeyGuard };
39
+ let OrgAuthGuard = class OrgAuthGuard {
40
+ authService;
41
+ constructor(authService) {
42
+ this.authService = authService;
43
+ }
44
+ async canActivate(context) {
45
+ const request = context.switchToHttp().getRequest();
46
+ const key = request.headers['x-api-key'];
47
+ if (typeof key === 'string' && key.length > 0) {
48
+ request.organizationId = await organizationIdForApiKey(this.authService, key);
49
+ return true;
50
+ }
51
+ const organizationId = request.session?.session?.activeOrganizationId;
52
+ if (!organizationId) {
53
+ throw new UnauthorizedException('Send an x-api-key header, or sign in and select an organization');
54
+ }
55
+ request.organizationId = organizationId;
56
+ return true;
57
+ }
58
+ };
59
+ OrgAuthGuard = __decorate([
60
+ Injectable(),
61
+ __param(0, Inject(AuthService)),
62
+ __metadata("design:paramtypes", [AuthService])
63
+ ], OrgAuthGuard);
64
+ export { OrgAuthGuard };
@@ -26,6 +26,11 @@ export interface KoshaAuthApi {
26
26
  export type KoshaAuth = Auth & {
27
27
  api: Auth['api'] & KoshaAuthApi;
28
28
  };
29
+ export declare function resolveAuthBaseURL(config: ResolvedKoshaConfig): string;
30
+ export declare function crossSiteCookieAttributes(config: ResolvedKoshaConfig): {
31
+ sameSite: 'none';
32
+ secure: true;
33
+ } | undefined;
29
34
  /**
30
35
  * A factory rather than a module-level singleton: the framework is a library
31
36
  * now, so nothing may read `process.env` at import time — the consuming app
@@ -1 +1 @@
1
- {"version":3,"file":"auth.factory.d.ts","sourceRoot":"","sources":["../../src/auth/auth.factory.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAc,KAAK,IAAI,EAAE,MAAM,aAAa,CAAC;AAGpD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAErE,gFAAgF;AAChF,MAAM,WAAW,YAAY;IAC3B,YAAY,CAAC,KAAK,EAAE;QAAE,IAAI,EAAE;YAAE,GAAG,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,GAAG,OAAO,CAAC;QACtD,KAAK,EAAE,OAAO,CAAC;QACf,GAAG,CAAC,EAAE;YAAE,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;SAAE,GAAG,IAAI,CAAC;QAC7C,KAAK,CAAC,EAAE,OAAO,CAAC;KACjB,CAAC,CAAC;CACJ;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,SAAS,GAAG,IAAI,GAAG;IAAE,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,YAAY,CAAA;CAAE,CAAC;AAEnE;;;;GAIG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,mBAAmB,EAC3B,MAAM,EAAE,YAAY,GACnB,SAAS,CAoBX"}
1
+ {"version":3,"file":"auth.factory.d.ts","sourceRoot":"","sources":["../../src/auth/auth.factory.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAc,KAAK,IAAI,EAAE,MAAM,aAAa,CAAC;AAGpD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAErE,gFAAgF;AAChF,MAAM,WAAW,YAAY;IAC3B,YAAY,CAAC,KAAK,EAAE;QAAE,IAAI,EAAE;YAAE,GAAG,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,GAAG,OAAO,CAAC;QACtD,KAAK,EAAE,OAAO,CAAC;QACf,GAAG,CAAC,EAAE;YAAE,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;SAAE,GAAG,IAAI,CAAC;QAC7C,KAAK,CAAC,EAAE,OAAO,CAAC;KACjB,CAAC,CAAC;CACJ;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,SAAS,GAAG,IAAI,GAAG;IAAE,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,YAAY,CAAA;CAAE,CAAC;AAEnE,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,mBAAmB,GAAG,MAAM,CAEtE;AAUD,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,mBAAmB,GAC1B;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,IAAI,CAAA;CAAE,GAAG,SAAS,CAYhD;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,mBAAmB,EAC3B,MAAM,EAAE,YAAY,GACnB,SAAS,CAyBX"}
@@ -2,6 +2,30 @@ import { apiKey } from '@better-auth/api-key';
2
2
  import { betterAuth } from 'better-auth';
3
3
  import { prismaAdapter } from 'better-auth/adapters/prisma';
4
4
  import { organization } from 'better-auth/plugins';
5
+ export function resolveAuthBaseURL(config) {
6
+ return config.auth.baseURL ?? `http://localhost:${config.server.port}`;
7
+ }
8
+ function hostnameOf(url) {
9
+ try {
10
+ return new URL(url).hostname;
11
+ }
12
+ catch {
13
+ return undefined;
14
+ }
15
+ }
16
+ export function crossSiteCookieAttributes(config) {
17
+ const baseURL = resolveAuthBaseURL(config);
18
+ if (!baseURL.startsWith('https://'))
19
+ return undefined;
20
+ const host = hostnameOf(baseURL);
21
+ const crossSite = (config.auth.trustedOrigins ?? []).some((origin) => {
22
+ if (!origin.startsWith('https://'))
23
+ return false;
24
+ const other = hostnameOf(origin);
25
+ return other !== undefined && other !== host;
26
+ });
27
+ return crossSite ? { sameSite: 'none', secure: true } : undefined;
28
+ }
5
29
  /**
6
30
  * A factory rather than a module-level singleton: the framework is a library
7
31
  * now, so nothing may read `process.env` at import time — the consuming app
@@ -11,15 +35,20 @@ export function createAuth(config, prisma) {
11
35
  const auth = betterAuth({
12
36
  database: prismaAdapter(prisma, { provider: 'postgresql' }),
13
37
  secret: config.auth.secret,
14
- baseURL: config.auth.baseURL ?? `http://localhost:${config.server.port}`,
38
+ baseURL: resolveAuthBaseURL(config),
15
39
  basePath: `/${config.server.globalPrefix}/auth`,
16
40
  emailAndPassword: {
17
41
  enabled: config.auth.emailAndPassword?.enabled ?? true,
18
42
  },
19
43
  trustedOrigins: config.auth.trustedOrigins ?? [],
44
+ advanced: { defaultCookieAttributes: crossSiteCookieAttributes(config) },
20
45
  plugins: [
21
46
  organization(),
22
- apiKey({ references: 'organization', requireName: true }),
47
+ apiKey({
48
+ references: 'organization',
49
+ requireName: true,
50
+ rateLimit: { enabled: true, maxRequests: 600, timeWindow: 60_000 },
51
+ }),
23
52
  ],
24
53
  });
25
54
  // Better Auth's instance type is parameterised by the exact options object,
@@ -1 +1 @@
1
- {"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAE/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAI5D;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC,gBAAgB,CAAC,CAgB3B;AAED,gCAAgC;AAChC,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC,gBAAgB,CAAC,CAW3B"}
1
+ {"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAG/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAI5D;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC,gBAAgB,CAAC,CAgB3B;AAED,gCAAgC;AAChC,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC,gBAAgB,CAAC,CAkB3B"}
package/dist/bootstrap.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { Logger } from '@nestjs/common';
2
2
  import { NestFactory } from '@nestjs/core';
3
+ import { createAdminProxy } from './admin-proxy.js';
3
4
  import { resolveConfig } from './config/kosha-config.js';
4
5
  import { KoshaModule } from './kosha.module.js';
5
6
  /**
@@ -27,7 +28,11 @@ export async function createKoshaServer(config) {
27
28
  export async function startKoshaServer(config) {
28
29
  const resolved = resolveConfig(config);
29
30
  const app = await createKoshaServer(resolved);
31
+ app.use(createAdminProxy({
32
+ adminPort: resolved.admin.port,
33
+ globalPrefix: resolved.server.globalPrefix,
34
+ }));
30
35
  await app.listen(resolved.server.port);
31
- Logger.log(`🚀 Kosha is running on http://localhost:${resolved.server.port}/${resolved.server.globalPrefix}`, 'Bootstrap');
36
+ Logger.log(`🚀 Kosha is running on ${resolved.server.publicUrl} (API under /${resolved.server.globalPrefix})`, 'Bootstrap');
32
37
  return app;
33
38
  }
@@ -9,12 +9,12 @@ export declare class ConfigurationsController {
9
9
  constructor(configurations: ConfigurationsService);
10
10
  list(session: UserSession): import("../generated/prisma/internal/prismaNamespace.js").PrismaPromise<({
11
11
  provider: {
12
+ name: string;
12
13
  key: string;
13
14
  id: string;
14
- name: string;
15
- authType: import("../generated/prisma/enums.js").AuthType;
16
15
  createdAt: Date;
17
16
  updatedAt: Date;
17
+ authType: import("../generated/prisma/enums.js").AuthType;
18
18
  authorizationUrl: string | null;
19
19
  tokenUrl: string | null;
20
20
  revokeUrl: string | null;
@@ -25,28 +25,29 @@ export declare class ConfigurationsController {
25
25
  isActive: boolean;
26
26
  };
27
27
  } & {
28
+ name: string;
28
29
  id: string;
30
+ createdAt: Date;
31
+ updatedAt: Date;
32
+ metadata: import("@prisma/client/runtime/client").JsonValue | null;
33
+ scopes: string[];
34
+ slug: string;
29
35
  organizationId: string;
30
36
  providerId: string;
31
- name: string;
32
37
  environment: import("../generated/prisma/enums.js").ConnectionEnvironment;
33
38
  authType: import("../generated/prisma/enums.js").AuthType;
34
39
  clientId: string | null;
35
40
  redirectUri: string | null;
36
- scopes: string[];
37
41
  isEnabled: boolean;
38
- metadata: import("@prisma/client/runtime/client").JsonValue | null;
39
- createdAt: Date;
40
- updatedAt: Date;
41
42
  })[]>;
42
43
  get(session: UserSession, id: string): Promise<{
43
44
  provider: {
45
+ name: string;
44
46
  key: string;
45
47
  id: string;
46
- name: string;
47
- authType: import("../generated/prisma/enums.js").AuthType;
48
48
  createdAt: Date;
49
49
  updatedAt: Date;
50
+ authType: import("../generated/prisma/enums.js").AuthType;
50
51
  authorizationUrl: string | null;
51
52
  tokenUrl: string | null;
52
53
  revokeUrl: string | null;
@@ -57,28 +58,29 @@ export declare class ConfigurationsController {
57
58
  isActive: boolean;
58
59
  };
59
60
  } & {
61
+ name: string;
60
62
  id: string;
63
+ createdAt: Date;
64
+ updatedAt: Date;
65
+ metadata: import("@prisma/client/runtime/client").JsonValue | null;
66
+ scopes: string[];
67
+ slug: string;
61
68
  organizationId: string;
62
69
  providerId: string;
63
- name: string;
64
70
  environment: import("../generated/prisma/enums.js").ConnectionEnvironment;
65
71
  authType: import("../generated/prisma/enums.js").AuthType;
66
72
  clientId: string | null;
67
73
  redirectUri: string | null;
68
- scopes: string[];
69
74
  isEnabled: boolean;
70
- metadata: import("@prisma/client/runtime/client").JsonValue | null;
71
- createdAt: Date;
72
- updatedAt: Date;
73
75
  }>;
74
76
  create(session: UserSession, body: CreateConfigurationInput): Promise<{
75
77
  provider: {
78
+ name: string;
76
79
  key: string;
77
80
  id: string;
78
- name: string;
79
- authType: import("../generated/prisma/enums.js").AuthType;
80
81
  createdAt: Date;
81
82
  updatedAt: Date;
83
+ authType: import("../generated/prisma/enums.js").AuthType;
82
84
  authorizationUrl: string | null;
83
85
  tokenUrl: string | null;
84
86
  revokeUrl: string | null;
@@ -89,28 +91,29 @@ export declare class ConfigurationsController {
89
91
  isActive: boolean;
90
92
  };
91
93
  } & {
94
+ name: string;
92
95
  id: string;
96
+ createdAt: Date;
97
+ updatedAt: Date;
98
+ metadata: import("@prisma/client/runtime/client").JsonValue | null;
99
+ scopes: string[];
100
+ slug: string;
93
101
  organizationId: string;
94
102
  providerId: string;
95
- name: string;
96
103
  environment: import("../generated/prisma/enums.js").ConnectionEnvironment;
97
104
  authType: import("../generated/prisma/enums.js").AuthType;
98
105
  clientId: string | null;
99
106
  redirectUri: string | null;
100
- scopes: string[];
101
107
  isEnabled: boolean;
102
- metadata: import("@prisma/client/runtime/client").JsonValue | null;
103
- createdAt: Date;
104
- updatedAt: Date;
105
108
  }>;
106
109
  update(session: UserSession, id: string, body: UpdateConfigurationInput): Promise<{
107
110
  provider: {
111
+ name: string;
108
112
  key: string;
109
113
  id: string;
110
- name: string;
111
- authType: import("../generated/prisma/enums.js").AuthType;
112
114
  createdAt: Date;
113
115
  updatedAt: Date;
116
+ authType: import("../generated/prisma/enums.js").AuthType;
114
117
  authorizationUrl: string | null;
115
118
  tokenUrl: string | null;
116
119
  revokeUrl: string | null;
@@ -121,19 +124,20 @@ export declare class ConfigurationsController {
121
124
  isActive: boolean;
122
125
  };
123
126
  } & {
127
+ name: string;
124
128
  id: string;
129
+ createdAt: Date;
130
+ updatedAt: Date;
131
+ metadata: import("@prisma/client/runtime/client").JsonValue | null;
132
+ scopes: string[];
133
+ slug: string;
125
134
  organizationId: string;
126
135
  providerId: string;
127
- name: string;
128
136
  environment: import("../generated/prisma/enums.js").ConnectionEnvironment;
129
137
  authType: import("../generated/prisma/enums.js").AuthType;
130
138
  clientId: string | null;
131
139
  redirectUri: string | null;
132
- scopes: string[];
133
140
  isEnabled: boolean;
134
- metadata: import("@prisma/client/runtime/client").JsonValue | null;
135
- createdAt: Date;
136
- updatedAt: Date;
137
141
  }>;
138
142
  remove(session: UserSession, id: string): Promise<{
139
143
  id: string;
@@ -1 +1 @@
1
- {"version":3,"file":"configurations.controller.d.ts","sourceRoot":"","sources":["../../src/configurations/configurations.controller.ts"],"names":[],"mappings":"AASA,OAAO,EAAW,KAAK,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAEzE,OAAO,EACL,qBAAqB,EACrB,KAAK,wBAAwB,EAC7B,KAAK,wBAAwB,EAC9B,MAAM,6BAA6B,CAAC;AAErC;;;GAGG;AACH,qBACa,wBAAwB;IACvB,OAAO,CAAC,QAAQ,CAAC,cAAc;gBAAd,cAAc,EAAE,qBAAqB;IAGlE,IAAI,CAAY,OAAO,EAAE,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAKpC,GAAG,CAAY,OAAO,EAAE,WAAW,EAAe,EAAE,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAK5D,MAAM,CACO,OAAO,EAAE,WAAW,EACvB,IAAI,EAAE,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAMxC,MAAM,CACO,OAAO,EAAE,WAAW,EAClB,EAAE,EAAE,MAAM,EACf,IAAI,EAAE,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAUlC,MAAM,CAAY,OAAO,EAAE,WAAW,EAAe,EAAE,EAAE,MAAM;;;;CAItE"}
1
+ {"version":3,"file":"configurations.controller.d.ts","sourceRoot":"","sources":["../../src/configurations/configurations.controller.ts"],"names":[],"mappings":"AASA,OAAO,EAAW,KAAK,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAEzE,OAAO,EACL,qBAAqB,EACrB,KAAK,wBAAwB,EAC7B,KAAK,wBAAwB,EAC9B,MAAM,6BAA6B,CAAC;AAErC;;;GAGG;AACH,qBACa,wBAAwB;IACvB,OAAO,CAAC,QAAQ,CAAC,cAAc;gBAAd,cAAc,EAAE,qBAAqB;IAGlE,IAAI,CAAY,OAAO,EAAE,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAKpC,GAAG,CAAY,OAAO,EAAE,WAAW,EAAe,EAAE,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAK5D,MAAM,CACO,OAAO,EAAE,WAAW,EACvB,IAAI,EAAE,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAMxC,MAAM,CACO,OAAO,EAAE,WAAW,EAClB,EAAE,EAAE,MAAM,EACf,IAAI,EAAE,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAUlC,MAAM,CAAY,OAAO,EAAE,WAAW,EAAe,EAAE,EAAE,MAAM;;;;CAItE"}
@@ -7,6 +7,7 @@ export interface CreateConfigurationInput {
7
7
  /** Provider key, e.g. "github". */
8
8
  provider: string;
9
9
  name: string;
10
+ slug?: string;
10
11
  clientId: string;
11
12
  clientSecret: string;
12
13
  scopes?: string[];
@@ -35,12 +36,12 @@ export declare class ConfigurationsService {
35
36
  callbackUrlFor(providerKey: string): string;
36
37
  list(organizationId: string): Prisma.PrismaPromise<({
37
38
  provider: {
39
+ name: string;
38
40
  key: string;
39
41
  id: string;
40
- name: string;
41
- authType: import("../generated/prisma/enums.js").AuthType;
42
42
  createdAt: Date;
43
43
  updatedAt: Date;
44
+ authType: import("../generated/prisma/enums.js").AuthType;
44
45
  authorizationUrl: string | null;
45
46
  tokenUrl: string | null;
46
47
  revokeUrl: string | null;
@@ -51,28 +52,29 @@ export declare class ConfigurationsService {
51
52
  isActive: boolean;
52
53
  };
53
54
  } & {
55
+ name: string;
54
56
  id: string;
57
+ createdAt: Date;
58
+ updatedAt: Date;
59
+ metadata: import("@prisma/client/runtime/client").JsonValue | null;
60
+ scopes: string[];
61
+ slug: string;
55
62
  organizationId: string;
56
63
  providerId: string;
57
- name: string;
58
64
  environment: import("../generated/prisma/enums.js").ConnectionEnvironment;
59
65
  authType: import("../generated/prisma/enums.js").AuthType;
60
66
  clientId: string | null;
61
67
  redirectUri: string | null;
62
- scopes: string[];
63
68
  isEnabled: boolean;
64
- metadata: import("@prisma/client/runtime/client").JsonValue | null;
65
- createdAt: Date;
66
- updatedAt: Date;
67
69
  })[]>;
68
70
  get(organizationId: string, id: string): Promise<{
69
71
  provider: {
72
+ name: string;
70
73
  key: string;
71
74
  id: string;
72
- name: string;
73
- authType: import("../generated/prisma/enums.js").AuthType;
74
75
  createdAt: Date;
75
76
  updatedAt: Date;
77
+ authType: import("../generated/prisma/enums.js").AuthType;
76
78
  authorizationUrl: string | null;
77
79
  tokenUrl: string | null;
78
80
  revokeUrl: string | null;
@@ -83,28 +85,29 @@ export declare class ConfigurationsService {
83
85
  isActive: boolean;
84
86
  };
85
87
  } & {
88
+ name: string;
86
89
  id: string;
90
+ createdAt: Date;
91
+ updatedAt: Date;
92
+ metadata: import("@prisma/client/runtime/client").JsonValue | null;
93
+ scopes: string[];
94
+ slug: string;
87
95
  organizationId: string;
88
96
  providerId: string;
89
- name: string;
90
97
  environment: import("../generated/prisma/enums.js").ConnectionEnvironment;
91
98
  authType: import("../generated/prisma/enums.js").AuthType;
92
99
  clientId: string | null;
93
100
  redirectUri: string | null;
94
- scopes: string[];
95
101
  isEnabled: boolean;
96
- metadata: import("@prisma/client/runtime/client").JsonValue | null;
97
- createdAt: Date;
98
- updatedAt: Date;
99
102
  }>;
100
103
  create(organizationId: string, input: CreateConfigurationInput): Promise<{
101
104
  provider: {
105
+ name: string;
102
106
  key: string;
103
107
  id: string;
104
- name: string;
105
- authType: import("../generated/prisma/enums.js").AuthType;
106
108
  createdAt: Date;
107
109
  updatedAt: Date;
110
+ authType: import("../generated/prisma/enums.js").AuthType;
108
111
  authorizationUrl: string | null;
109
112
  tokenUrl: string | null;
110
113
  revokeUrl: string | null;
@@ -115,28 +118,29 @@ export declare class ConfigurationsService {
115
118
  isActive: boolean;
116
119
  };
117
120
  } & {
121
+ name: string;
118
122
  id: string;
123
+ createdAt: Date;
124
+ updatedAt: Date;
125
+ metadata: import("@prisma/client/runtime/client").JsonValue | null;
126
+ scopes: string[];
127
+ slug: string;
119
128
  organizationId: string;
120
129
  providerId: string;
121
- name: string;
122
130
  environment: import("../generated/prisma/enums.js").ConnectionEnvironment;
123
131
  authType: import("../generated/prisma/enums.js").AuthType;
124
132
  clientId: string | null;
125
133
  redirectUri: string | null;
126
- scopes: string[];
127
134
  isEnabled: boolean;
128
- metadata: import("@prisma/client/runtime/client").JsonValue | null;
129
- createdAt: Date;
130
- updatedAt: Date;
131
135
  }>;
132
136
  update(organizationId: string, id: string, input: UpdateConfigurationInput): Promise<{
133
137
  provider: {
138
+ name: string;
134
139
  key: string;
135
140
  id: string;
136
- name: string;
137
- authType: import("../generated/prisma/enums.js").AuthType;
138
141
  createdAt: Date;
139
142
  updatedAt: Date;
143
+ authType: import("../generated/prisma/enums.js").AuthType;
140
144
  authorizationUrl: string | null;
141
145
  tokenUrl: string | null;
142
146
  revokeUrl: string | null;
@@ -147,19 +151,20 @@ export declare class ConfigurationsService {
147
151
  isActive: boolean;
148
152
  };
149
153
  } & {
154
+ name: string;
150
155
  id: string;
156
+ createdAt: Date;
157
+ updatedAt: Date;
158
+ metadata: import("@prisma/client/runtime/client").JsonValue | null;
159
+ scopes: string[];
160
+ slug: string;
151
161
  organizationId: string;
152
162
  providerId: string;
153
- name: string;
154
163
  environment: import("../generated/prisma/enums.js").ConnectionEnvironment;
155
164
  authType: import("../generated/prisma/enums.js").AuthType;
156
165
  clientId: string | null;
157
166
  redirectUri: string | null;
158
- scopes: string[];
159
167
  isEnabled: boolean;
160
- metadata: import("@prisma/client/runtime/client").JsonValue | null;
161
- createdAt: Date;
162
- updatedAt: Date;
163
168
  }>;
164
169
  remove(organizationId: string, id: string): Promise<void>;
165
170
  /**
@@ -169,12 +174,12 @@ export declare class ConfigurationsService {
169
174
  getWithDecryptedSecret(configurationId: string): Promise<{
170
175
  clientSecret: string;
171
176
  provider: {
177
+ name: string;
172
178
  key: string;
173
179
  id: string;
174
- name: string;
175
- authType: import("../generated/prisma/enums.js").AuthType;
176
180
  createdAt: Date;
177
181
  updatedAt: Date;
182
+ authType: import("../generated/prisma/enums.js").AuthType;
178
183
  authorizationUrl: string | null;
179
184
  tokenUrl: string | null;
180
185
  revokeUrl: string | null;
@@ -184,20 +189,21 @@ export declare class ConfigurationsService {
184
189
  logoUrl: string | null;
185
190
  isActive: boolean;
186
191
  };
192
+ name: string;
187
193
  id: string;
194
+ createdAt: Date;
195
+ updatedAt: Date;
196
+ metadata: import("@prisma/client/runtime/client").JsonValue | null;
197
+ scopes: string[];
198
+ slug: string;
188
199
  organizationId: string;
189
200
  providerId: string;
190
- name: string;
191
201
  environment: import("../generated/prisma/enums.js").ConnectionEnvironment;
192
202
  authType: import("../generated/prisma/enums.js").AuthType;
193
203
  clientId: string | null;
194
204
  encryptedClientSecret: string | null;
195
205
  redirectUri: string | null;
196
- scopes: string[];
197
206
  isEnabled: boolean;
198
- metadata: import("@prisma/client/runtime/client").JsonValue | null;
199
- createdAt: Date;
200
- updatedAt: Date;
201
207
  }>;
202
208
  private validateScopes;
203
209
  /**