@kosha-ai/server 0.0.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/LICENSE +21 -0
- package/dist/auth/api-key.guard.d.ts +18 -0
- package/dist/auth/api-key.guard.d.ts.map +1 -0
- package/dist/auth/api-key.guard.js +33 -0
- package/dist/auth/auth.factory.d.ts +35 -0
- package/dist/auth/auth.factory.d.ts.map +1 -0
- package/dist/auth/auth.factory.js +29 -0
- package/dist/bootstrap.d.ts +13 -0
- package/dist/bootstrap.d.ts.map +1 -0
- package/dist/bootstrap.js +33 -0
- package/dist/common/active-organization.d.ts +3 -0
- package/dist/common/active-organization.d.ts.map +1 -0
- package/dist/common/active-organization.js +8 -0
- package/dist/config/kosha-config.d.ts +80 -0
- package/dist/config/kosha-config.d.ts.map +1 -0
- package/dist/config/kosha-config.js +69 -0
- package/dist/config/tokens.d.ts +4 -0
- package/dist/config/tokens.d.ts.map +1 -0
- package/dist/config/tokens.js +3 -0
- package/dist/configurations/configurations.controller.d.ts +143 -0
- package/dist/configurations/configurations.controller.d.ts.map +1 -0
- package/dist/configurations/configurations.controller.js +76 -0
- package/dist/configurations/configurations.module.d.ts +3 -0
- package/dist/configurations/configurations.module.d.ts.map +1 -0
- package/dist/configurations/configurations.module.js +14 -0
- package/dist/configurations/configurations.service.d.ts +210 -0
- package/dist/configurations/configurations.service.d.ts.map +1 -0
- package/dist/configurations/configurations.service.js +204 -0
- package/dist/connect/connect.controller.d.ts +33 -0
- package/dist/connect/connect.controller.d.ts.map +1 -0
- package/dist/connect/connect.controller.js +123 -0
- package/dist/connect/connect.module.d.ts +3 -0
- package/dist/connect/connect.module.d.ts.map +1 -0
- package/dist/connect/connect.module.js +16 -0
- package/dist/connect/connect.service.d.ts +54 -0
- package/dist/connect/connect.service.d.ts.map +1 -0
- package/dist/connect/connect.service.js +248 -0
- package/dist/connections/connections.controller.d.ts +71 -0
- package/dist/connections/connections.controller.d.ts.map +1 -0
- package/dist/connections/connections.controller.js +51 -0
- package/dist/connections/connections.module.d.ts +3 -0
- package/dist/connections/connections.module.d.ts.map +1 -0
- package/dist/connections/connections.module.js +14 -0
- package/dist/connections/connections.service.d.ts +76 -0
- package/dist/connections/connections.service.d.ts.map +1 -0
- package/dist/connections/connections.service.js +71 -0
- package/dist/crypto/crypto.module.d.ts +3 -0
- package/dist/crypto/crypto.module.d.ts.map +1 -0
- package/dist/crypto/crypto.module.js +13 -0
- package/dist/crypto/crypto.service.d.ts +21 -0
- package/dist/crypto/crypto.service.d.ts.map +1 -0
- package/dist/crypto/crypto.service.js +77 -0
- package/dist/generated/prisma/browser.d.ts +88 -0
- package/dist/generated/prisma/browser.d.ts.map +1 -0
- package/dist/generated/prisma/browser.js +17 -0
- package/dist/generated/prisma/client.d.ts +107 -0
- package/dist/generated/prisma/client.d.ts.map +1 -0
- package/dist/generated/prisma/client.js +34 -0
- package/dist/generated/prisma/commonInputTypes.d.ts +478 -0
- package/dist/generated/prisma/commonInputTypes.d.ts.map +1 -0
- package/dist/generated/prisma/commonInputTypes.js +10 -0
- package/dist/generated/prisma/enums.d.ts +22 -0
- package/dist/generated/prisma/enums.d.ts.map +1 -0
- package/dist/generated/prisma/enums.js +27 -0
- package/dist/generated/prisma/internal/class.d.ts +287 -0
- package/dist/generated/prisma/internal/class.d.ts.map +1 -0
- package/dist/generated/prisma/internal/class.js +49 -0
- package/dist/generated/prisma/internal/prismaNamespace.d.ts +1905 -0
- package/dist/generated/prisma/internal/prismaNamespace.d.ts.map +1 -0
- package/dist/generated/prisma/internal/prismaNamespace.js +299 -0
- package/dist/generated/prisma/internal/prismaNamespaceBrowser.d.ts +277 -0
- package/dist/generated/prisma/internal/prismaNamespaceBrowser.d.ts.map +1 -0
- package/dist/generated/prisma/internal/prismaNamespaceBrowser.js +270 -0
- package/dist/generated/prisma/models/Account.d.ts +1459 -0
- package/dist/generated/prisma/models/Account.d.ts.map +1 -0
- package/dist/generated/prisma/models/Account.js +1 -0
- package/dist/generated/prisma/models/Apikey.d.ts +1552 -0
- package/dist/generated/prisma/models/Apikey.d.ts.map +1 -0
- package/dist/generated/prisma/models/Apikey.js +1 -0
- package/dist/generated/prisma/models/Configuration.d.ts +1964 -0
- package/dist/generated/prisma/models/Configuration.d.ts.map +1 -0
- package/dist/generated/prisma/models/Configuration.js +1 -0
- package/dist/generated/prisma/models/ConnectSession.d.ts +1606 -0
- package/dist/generated/prisma/models/ConnectSession.d.ts.map +1 -0
- package/dist/generated/prisma/models/ConnectSession.js +1 -0
- package/dist/generated/prisma/models/Connection.d.ts +1949 -0
- package/dist/generated/prisma/models/Connection.d.ts.map +1 -0
- package/dist/generated/prisma/models/Connection.js +1 -0
- package/dist/generated/prisma/models/ConnectionCredential.d.ts +1293 -0
- package/dist/generated/prisma/models/ConnectionCredential.d.ts.map +1 -0
- package/dist/generated/prisma/models/ConnectionCredential.js +1 -0
- package/dist/generated/prisma/models/EndUser.d.ts +1539 -0
- package/dist/generated/prisma/models/EndUser.d.ts.map +1 -0
- package/dist/generated/prisma/models/EndUser.js +1 -0
- package/dist/generated/prisma/models/Invitation.d.ts +1404 -0
- package/dist/generated/prisma/models/Invitation.d.ts.map +1 -0
- package/dist/generated/prisma/models/Invitation.js +1 -0
- package/dist/generated/prisma/models/Member.d.ts +1281 -0
- package/dist/generated/prisma/models/Member.d.ts.map +1 -0
- package/dist/generated/prisma/models/Member.js +1 -0
- package/dist/generated/prisma/models/OAuthState.d.ts +1404 -0
- package/dist/generated/prisma/models/OAuthState.d.ts.map +1 -0
- package/dist/generated/prisma/models/OAuthState.js +1 -0
- package/dist/generated/prisma/models/Organization.d.ts +1807 -0
- package/dist/generated/prisma/models/Organization.d.ts.map +1 -0
- package/dist/generated/prisma/models/Organization.js +1 -0
- package/dist/generated/prisma/models/Provider.d.ts +1462 -0
- package/dist/generated/prisma/models/Provider.d.ts.map +1 -0
- package/dist/generated/prisma/models/Provider.js +1 -0
- package/dist/generated/prisma/models/Session.d.ts +1316 -0
- package/dist/generated/prisma/models/Session.d.ts.map +1 -0
- package/dist/generated/prisma/models/Session.js +1 -0
- package/dist/generated/prisma/models/User.d.ts +1593 -0
- package/dist/generated/prisma/models/User.d.ts.map +1 -0
- package/dist/generated/prisma/models/User.js +1 -0
- package/dist/generated/prisma/models/Verification.d.ts +1026 -0
- package/dist/generated/prisma/models/Verification.d.ts.map +1 -0
- package/dist/generated/prisma/models/Verification.js +1 -0
- package/dist/generated/prisma/models.d.ts +17 -0
- package/dist/generated/prisma/models.d.ts.map +1 -0
- package/dist/generated/prisma/models.js +1 -0
- package/dist/health/health.controller.d.ts +12 -0
- package/dist/health/health.controller.d.ts.map +1 -0
- package/dist/health/health.controller.js +36 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/integrations/integration.registry.d.ts +19 -0
- package/dist/integrations/integration.registry.d.ts.map +1 -0
- package/dist/integrations/integration.registry.js +45 -0
- package/dist/integrations/integrations.controller.d.ts +26 -0
- package/dist/integrations/integrations.controller.d.ts.map +1 -0
- package/dist/integrations/integrations.controller.js +47 -0
- package/dist/integrations/integrations.module.d.ts +6 -0
- package/dist/integrations/integrations.module.d.ts.map +1 -0
- package/dist/integrations/integrations.module.js +26 -0
- package/dist/integrations/provider-sync.service.d.ts +24 -0
- package/dist/integrations/provider-sync.service.d.ts.map +1 -0
- package/dist/integrations/provider-sync.service.js +74 -0
- package/dist/kosha.module.d.ts +11 -0
- package/dist/kosha.module.d.ts.map +1 -0
- package/dist/kosha.module.js +48 -0
- package/dist/prisma/prisma.module.d.ts +11 -0
- package/dist/prisma/prisma.module.d.ts.map +1 -0
- package/dist/prisma/prisma.module.js +24 -0
- package/dist/prisma/prisma.service.d.ts +10 -0
- package/dist/prisma/prisma.service.d.ts.map +1 -0
- package/dist/prisma/prisma.service.js +25 -0
- package/dist/proxy/proxy.controller.d.ts +17 -0
- package/dist/proxy/proxy.controller.d.ts.map +1 -0
- package/dist/proxy/proxy.controller.js +64 -0
- package/dist/proxy/proxy.module.d.ts +3 -0
- package/dist/proxy/proxy.module.d.ts.map +1 -0
- package/dist/proxy/proxy.module.js +16 -0
- package/dist/proxy/proxy.service.d.ts +40 -0
- package/dist/proxy/proxy.service.d.ts.map +1 -0
- package/dist/proxy/proxy.service.js +186 -0
- package/package.json +118 -0
- package/prisma/migrations/20260908000000_init/migration.sql +209 -0
- package/prisma/migrations/20260908161813_add_connect_domain/migration.sql +173 -0
- package/prisma/migrations/migration_lock.toml +3 -0
- package/prisma/schema.prisma +347 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Codemancers
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { CanActivate, ExecutionContext } from '@nestjs/common';
|
|
2
|
+
import { AuthService } from '@thallesp/nestjs-better-auth';
|
|
3
|
+
import type { Request } from 'express';
|
|
4
|
+
import type { KoshaAuth } from './auth.factory.js';
|
|
5
|
+
export interface ApiKeyRequest extends Request {
|
|
6
|
+
organizationId: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Authenticates machine-to-machine calls with `x-api-key` and puts the owning
|
|
10
|
+
* organization on the request. Keys are org-scoped: Better Auth's API-key
|
|
11
|
+
* plugin is configured with `references: 'organization'`.
|
|
12
|
+
*/
|
|
13
|
+
export declare class ApiKeyGuard implements CanActivate {
|
|
14
|
+
private readonly authService;
|
|
15
|
+
constructor(authService: AuthService<KoshaAuth>);
|
|
16
|
+
canActivate(context: ExecutionContext): Promise<boolean>;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=api-key.guard.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { __decorate, __metadata, __param } from "tslib";
|
|
2
|
+
import { Inject, Injectable, UnauthorizedException, } from '@nestjs/common';
|
|
3
|
+
import { AuthService } from '@thallesp/nestjs-better-auth';
|
|
4
|
+
/**
|
|
5
|
+
* Authenticates machine-to-machine calls with `x-api-key` and puts the owning
|
|
6
|
+
* organization on the request. Keys are org-scoped: Better Auth's API-key
|
|
7
|
+
* plugin is configured with `references: 'organization'`.
|
|
8
|
+
*/
|
|
9
|
+
let ApiKeyGuard = class ApiKeyGuard {
|
|
10
|
+
authService;
|
|
11
|
+
constructor(authService) {
|
|
12
|
+
this.authService = authService;
|
|
13
|
+
}
|
|
14
|
+
async canActivate(context) {
|
|
15
|
+
const request = context.switchToHttp().getRequest();
|
|
16
|
+
const key = request.headers['x-api-key'];
|
|
17
|
+
if (!key || typeof key !== 'string') {
|
|
18
|
+
throw new UnauthorizedException('Missing x-api-key header');
|
|
19
|
+
}
|
|
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;
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
ApiKeyGuard = __decorate([
|
|
29
|
+
Injectable(),
|
|
30
|
+
__param(0, Inject(AuthService)),
|
|
31
|
+
__metadata("design:paramtypes", [AuthService])
|
|
32
|
+
], ApiKeyGuard);
|
|
33
|
+
export { ApiKeyGuard };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { PrismaClient } from '../generated/prisma/client.js';
|
|
2
|
+
import { type Auth } from 'better-auth';
|
|
3
|
+
import type { ResolvedKoshaConfig } from '../config/kosha-config.js';
|
|
4
|
+
/** The API-key endpoints Kosha itself calls. The instance exposes many more. */
|
|
5
|
+
export interface KoshaAuthApi {
|
|
6
|
+
verifyApiKey(input: {
|
|
7
|
+
body: {
|
|
8
|
+
key: string;
|
|
9
|
+
};
|
|
10
|
+
}): Promise<{
|
|
11
|
+
valid: boolean;
|
|
12
|
+
key?: {
|
|
13
|
+
referenceId?: string | null;
|
|
14
|
+
} | null;
|
|
15
|
+
error?: unknown;
|
|
16
|
+
}>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The auth instance as the rest of the framework sees it: Better Auth's public
|
|
20
|
+
* surface plus the plugin endpoints Kosha depends on.
|
|
21
|
+
*
|
|
22
|
+
* Not `ReturnType<typeof betterAuth>`: with the organization and API-key
|
|
23
|
+
* plugins applied, that inferred type is too large for TypeScript to serialize
|
|
24
|
+
* into a `.d.ts` (TS7056), and this package is published.
|
|
25
|
+
*/
|
|
26
|
+
export type KoshaAuth = Auth & {
|
|
27
|
+
api: Auth['api'] & KoshaAuthApi;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* A factory rather than a module-level singleton: the framework is a library
|
|
31
|
+
* now, so nothing may read `process.env` at import time — the consuming app
|
|
32
|
+
* owns where secrets come from.
|
|
33
|
+
*/
|
|
34
|
+
export declare function createAuth(config: ResolvedKoshaConfig, prisma: PrismaClient): KoshaAuth;
|
|
35
|
+
//# sourceMappingURL=auth.factory.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { apiKey } from '@better-auth/api-key';
|
|
2
|
+
import { betterAuth } from 'better-auth';
|
|
3
|
+
import { prismaAdapter } from 'better-auth/adapters/prisma';
|
|
4
|
+
import { organization } from 'better-auth/plugins';
|
|
5
|
+
/**
|
|
6
|
+
* A factory rather than a module-level singleton: the framework is a library
|
|
7
|
+
* now, so nothing may read `process.env` at import time — the consuming app
|
|
8
|
+
* owns where secrets come from.
|
|
9
|
+
*/
|
|
10
|
+
export function createAuth(config, prisma) {
|
|
11
|
+
const auth = betterAuth({
|
|
12
|
+
database: prismaAdapter(prisma, { provider: 'postgresql' }),
|
|
13
|
+
secret: config.auth.secret,
|
|
14
|
+
baseURL: config.auth.baseURL ?? `http://localhost:${config.server.port}`,
|
|
15
|
+
basePath: `/${config.server.globalPrefix}/auth`,
|
|
16
|
+
emailAndPassword: {
|
|
17
|
+
enabled: config.auth.emailAndPassword?.enabled ?? true,
|
|
18
|
+
},
|
|
19
|
+
trustedOrigins: config.auth.trustedOrigins ?? [],
|
|
20
|
+
plugins: [
|
|
21
|
+
organization(),
|
|
22
|
+
apiKey({ references: 'organization', requireName: true }),
|
|
23
|
+
],
|
|
24
|
+
});
|
|
25
|
+
// Better Auth's instance type is parameterised by the exact options object,
|
|
26
|
+
// so it is not assignable to the base `Auth`. This is the single boundary
|
|
27
|
+
// where the plugin-inferred type is traded for a nameable one.
|
|
28
|
+
return auth;
|
|
29
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type INestApplication } from '@nestjs/common';
|
|
2
|
+
import type { KoshaConfig } from './config/kosha-config.js';
|
|
3
|
+
/**
|
|
4
|
+
* Doesn't listen — `startKoshaServer` does that once this resolves.
|
|
5
|
+
*
|
|
6
|
+
* Body parsing is off here: Better Auth reads the raw request, and
|
|
7
|
+
* `@thallesp/nestjs-better-auth` re-adds the default parsers for every other
|
|
8
|
+
* route.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createKoshaServer(config: KoshaConfig): Promise<INestApplication>;
|
|
11
|
+
/** What `kosha start` calls. */
|
|
12
|
+
export declare function startKoshaServer(config: KoshaConfig): Promise<INestApplication>;
|
|
13
|
+
//# sourceMappingURL=bootstrap.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Logger } from '@nestjs/common';
|
|
2
|
+
import { NestFactory } from '@nestjs/core';
|
|
3
|
+
import { resolveConfig } from './config/kosha-config.js';
|
|
4
|
+
import { KoshaModule } from './kosha.module.js';
|
|
5
|
+
/**
|
|
6
|
+
* Doesn't listen — `startKoshaServer` does that once this resolves.
|
|
7
|
+
*
|
|
8
|
+
* Body parsing is off here: Better Auth reads the raw request, and
|
|
9
|
+
* `@thallesp/nestjs-better-auth` re-adds the default parsers for every other
|
|
10
|
+
* route.
|
|
11
|
+
*/
|
|
12
|
+
export async function createKoshaServer(config) {
|
|
13
|
+
const resolved = resolveConfig(config);
|
|
14
|
+
const app = await NestFactory.create(KoshaModule.forRoot(resolved), {
|
|
15
|
+
bodyParser: false,
|
|
16
|
+
});
|
|
17
|
+
const cors = resolved.server.cors;
|
|
18
|
+
app.enableCors({
|
|
19
|
+
origin: cors?.origin ?? resolved.auth.trustedOrigins ?? [],
|
|
20
|
+
credentials: cors?.credentials ?? true,
|
|
21
|
+
});
|
|
22
|
+
app.setGlobalPrefix(resolved.server.globalPrefix);
|
|
23
|
+
app.enableShutdownHooks();
|
|
24
|
+
return app;
|
|
25
|
+
}
|
|
26
|
+
/** What `kosha start` calls. */
|
|
27
|
+
export async function startKoshaServer(config) {
|
|
28
|
+
const resolved = resolveConfig(config);
|
|
29
|
+
const app = await createKoshaServer(resolved);
|
|
30
|
+
await app.listen(resolved.server.port);
|
|
31
|
+
Logger.log(`🚀 Kosha is running on http://localhost:${resolved.server.port}/${resolved.server.globalPrefix}`, 'Bootstrap');
|
|
32
|
+
return app;
|
|
33
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"active-organization.d.ts","sourceRoot":"","sources":["../../src/common/active-organization.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAEhE,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,WAAW,GAAG,MAAM,CAMpE"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BadRequestException } from '@nestjs/common';
|
|
2
|
+
export function getActiveOrganizationId(session) {
|
|
3
|
+
const organizationId = session.session.activeOrganizationId;
|
|
4
|
+
if (!organizationId) {
|
|
5
|
+
throw new BadRequestException('No active organization selected');
|
|
6
|
+
}
|
|
7
|
+
return organizationId;
|
|
8
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { KoshaIntegration } from '@kosha-ai/integration-sdk';
|
|
2
|
+
export interface KoshaDatabaseConfig {
|
|
3
|
+
/** Postgres connection string. */
|
|
4
|
+
url: string;
|
|
5
|
+
}
|
|
6
|
+
export interface KoshaAuthConfig {
|
|
7
|
+
/** Signing secret for sessions and tokens. Must not be a build-time literal. */
|
|
8
|
+
secret: string;
|
|
9
|
+
/**
|
|
10
|
+
* Public URL the server is reached at. Better Auth needs it to build
|
|
11
|
+
* callback and redirect URLs; without it they are derived per-request.
|
|
12
|
+
*/
|
|
13
|
+
baseURL?: string;
|
|
14
|
+
/** Origins allowed to hold a session, e.g. the admin URL. */
|
|
15
|
+
trustedOrigins?: string[];
|
|
16
|
+
emailAndPassword?: {
|
|
17
|
+
enabled?: boolean;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export interface KoshaServerConfig {
|
|
21
|
+
port?: number;
|
|
22
|
+
globalPrefix?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Public URL the server is reachable at. OAuth redirect URIs are built from
|
|
25
|
+
* it, so providers must be able to reach it — in production this is the
|
|
26
|
+
* deployed hostname, not localhost.
|
|
27
|
+
*/
|
|
28
|
+
publicUrl?: string;
|
|
29
|
+
/** Origins allowed to make credentialed cross-origin calls. */
|
|
30
|
+
cors?: {
|
|
31
|
+
origin: string | string[];
|
|
32
|
+
credentials?: boolean;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export interface KoshaAdminConfig {
|
|
36
|
+
port?: number;
|
|
37
|
+
}
|
|
38
|
+
export interface KoshaEncryptionConfig {
|
|
39
|
+
/**
|
|
40
|
+
* Base64-encoded 32-byte key for AES-256-GCM. Every provider token and
|
|
41
|
+
* client secret is encrypted with it at rest, so rotating it strands
|
|
42
|
+
* existing credentials.
|
|
43
|
+
*/
|
|
44
|
+
key: string;
|
|
45
|
+
}
|
|
46
|
+
export interface KoshaConfig {
|
|
47
|
+
database: KoshaDatabaseConfig;
|
|
48
|
+
auth: KoshaAuthConfig;
|
|
49
|
+
/** Required once any integration stores credentials. */
|
|
50
|
+
encryption?: KoshaEncryptionConfig;
|
|
51
|
+
server?: KoshaServerConfig;
|
|
52
|
+
/** The Next.js admin UI `kosha start` boots alongside the server. */
|
|
53
|
+
admin?: KoshaAdminConfig;
|
|
54
|
+
integrations?: KoshaIntegration[];
|
|
55
|
+
}
|
|
56
|
+
/** A config with every optional section filled in. */
|
|
57
|
+
export interface ResolvedKoshaConfig extends KoshaConfig {
|
|
58
|
+
server: Required<Pick<KoshaServerConfig, 'port' | 'globalPrefix' | 'publicUrl'>> & KoshaServerConfig;
|
|
59
|
+
admin: Required<Pick<KoshaAdminConfig, 'port'>> & KoshaAdminConfig;
|
|
60
|
+
integrations: KoshaIntegration[];
|
|
61
|
+
}
|
|
62
|
+
export declare class KoshaConfigError extends Error {
|
|
63
|
+
constructor(message: string);
|
|
64
|
+
}
|
|
65
|
+
export declare const DEFAULT_PORT = 3333;
|
|
66
|
+
export declare const DEFAULT_GLOBAL_PREFIX = "api";
|
|
67
|
+
export declare const DEFAULT_ADMIN_PORT = 3000;
|
|
68
|
+
/**
|
|
69
|
+
* Identity function that gives an app's `kosha.config.ts` its types. Validation
|
|
70
|
+
* is deliberately deferred to {@link resolveConfig} at boot, so editing a
|
|
71
|
+
* config file never runs checks against a half-populated environment.
|
|
72
|
+
*/
|
|
73
|
+
export declare function defineConfig(config: KoshaConfig): KoshaConfig;
|
|
74
|
+
/**
|
|
75
|
+
* Validates and normalises a config. Throws on anything that would otherwise
|
|
76
|
+
* fail later as a confusing runtime error — a missing secret, a duplicated
|
|
77
|
+
* integration key, an unreachable-looking database URL.
|
|
78
|
+
*/
|
|
79
|
+
export declare function resolveConfig(config: KoshaConfig): ResolvedKoshaConfig;
|
|
80
|
+
//# sourceMappingURL=kosha-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kosha-config.d.ts","sourceRoot":"","sources":["../../src/config/kosha-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAElE,MAAM,WAAW,mBAAmB;IAClC,kCAAkC;IAClC,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,eAAe;IAC9B,gFAAgF;IAChF,MAAM,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,6DAA6D;IAC7D,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,gBAAgB,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;CAC1C;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+DAA+D;IAC/D,IAAI,CAAC,EAAE;QAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;QAAC,WAAW,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;CAC7D;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,qBAAqB;IACpC;;;;OAIG;IACH,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,mBAAmB,CAAC;IAC9B,IAAI,EAAE,eAAe,CAAC;IACtB,wDAAwD;IACxD,UAAU,CAAC,EAAE,qBAAqB,CAAC;IACnC,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAC3B,qEAAqE;IACrE,KAAK,CAAC,EAAE,gBAAgB,CAAC;IACzB,YAAY,CAAC,EAAE,gBAAgB,EAAE,CAAC;CACnC;AAED,sDAAsD;AACtD,MAAM,WAAW,mBAAoB,SAAQ,WAAW;IACtD,MAAM,EAAE,QAAQ,CACd,IAAI,CAAC,iBAAiB,EAAE,MAAM,GAAG,cAAc,GAAG,WAAW,CAAC,CAC/D,GACC,iBAAiB,CAAC;IACpB,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC,GAAG,gBAAgB,CAAC;IACnE,YAAY,EAAE,gBAAgB,EAAE,CAAC;CAClC;AAED,qBAAa,gBAAiB,SAAQ,KAAK;gBAC7B,OAAO,EAAE,MAAM;CAI5B;AAED,eAAO,MAAM,YAAY,OAAO,CAAC;AACjC,eAAO,MAAM,qBAAqB,QAAQ,CAAC;AAC3C,eAAO,MAAM,kBAAkB,OAAO,CAAC;AAEvC;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,WAAW,GAAG,WAAW,CAE7D;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,WAAW,GAAG,mBAAmB,CAoEtE"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
export class KoshaConfigError extends Error {
|
|
2
|
+
constructor(message) {
|
|
3
|
+
super(message);
|
|
4
|
+
this.name = 'KoshaConfigError';
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export const DEFAULT_PORT = 3333;
|
|
8
|
+
export const DEFAULT_GLOBAL_PREFIX = 'api';
|
|
9
|
+
export const DEFAULT_ADMIN_PORT = 3000;
|
|
10
|
+
/**
|
|
11
|
+
* Identity function that gives an app's `kosha.config.ts` its types. Validation
|
|
12
|
+
* is deliberately deferred to {@link resolveConfig} at boot, so editing a
|
|
13
|
+
* config file never runs checks against a half-populated environment.
|
|
14
|
+
*/
|
|
15
|
+
export function defineConfig(config) {
|
|
16
|
+
return config;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Validates and normalises a config. Throws on anything that would otherwise
|
|
20
|
+
* fail later as a confusing runtime error — a missing secret, a duplicated
|
|
21
|
+
* integration key, an unreachable-looking database URL.
|
|
22
|
+
*/
|
|
23
|
+
export function resolveConfig(config) {
|
|
24
|
+
const problems = [];
|
|
25
|
+
if (!config?.database?.url) {
|
|
26
|
+
problems.push('database.url is required (usually process.env.DATABASE_URL)');
|
|
27
|
+
}
|
|
28
|
+
else if (!/^postgres(ql)?:\/\//.test(config.database.url)) {
|
|
29
|
+
problems.push('database.url must be a postgresql:// connection string; Kosha only supports Postgres');
|
|
30
|
+
}
|
|
31
|
+
if (!config?.auth?.secret) {
|
|
32
|
+
problems.push('auth.secret is required (usually process.env.KOSHA_SECRET)');
|
|
33
|
+
}
|
|
34
|
+
else if (config.auth.secret.length < 32) {
|
|
35
|
+
problems.push(`auth.secret must be at least 32 characters, got ${config.auth.secret.length}`);
|
|
36
|
+
}
|
|
37
|
+
if (config?.encryption?.key !== undefined) {
|
|
38
|
+
const decoded = Buffer.from(config.encryption.key, 'base64');
|
|
39
|
+
if (decoded.length !== 32) {
|
|
40
|
+
problems.push(`encryption.key must be a base64-encoded 32-byte key, got ${decoded.length} bytes`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (config?.server?.publicUrl &&
|
|
44
|
+
!/^https?:\/\//.test(config.server.publicUrl)) {
|
|
45
|
+
problems.push(`server.publicUrl must be an absolute http(s) URL, got ${config.server.publicUrl}`);
|
|
46
|
+
}
|
|
47
|
+
const integrations = config?.integrations ?? [];
|
|
48
|
+
const seen = new Map();
|
|
49
|
+
for (const integration of integrations) {
|
|
50
|
+
seen.set(integration.key, (seen.get(integration.key) ?? 0) + 1);
|
|
51
|
+
}
|
|
52
|
+
for (const [key, count] of seen) {
|
|
53
|
+
if (count > 1) {
|
|
54
|
+
problems.push(`integration "${key}" is registered ${count} times`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (problems.length > 0) {
|
|
58
|
+
throw new KoshaConfigError(`Invalid kosha.config:\n - ${problems.join('\n - ')}`);
|
|
59
|
+
}
|
|
60
|
+
const port = config.server?.port ?? DEFAULT_PORT;
|
|
61
|
+
const globalPrefix = config.server?.globalPrefix ?? DEFAULT_GLOBAL_PREFIX;
|
|
62
|
+
const publicUrl = (config.server?.publicUrl ?? `http://localhost:${port}`).replace(/\/$/, '');
|
|
63
|
+
return {
|
|
64
|
+
...config,
|
|
65
|
+
integrations,
|
|
66
|
+
server: { ...config.server, port, globalPrefix, publicUrl },
|
|
67
|
+
admin: { ...config.admin, port: config.admin?.port ?? DEFAULT_ADMIN_PORT },
|
|
68
|
+
};
|
|
69
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../../src/config/tokens.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,eAAO,MAAM,YAAY,eAAyB,CAAC;AACnD,eAAO,MAAM,kBAAkB,eAA+B,CAAC"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { type UserSession } from '@thallesp/nestjs-better-auth';
|
|
2
|
+
import { ConfigurationsService, type CreateConfigurationInput, type UpdateConfigurationInput } from './configurations.service.js';
|
|
3
|
+
/**
|
|
4
|
+
* Admin-facing. Session authenticated and scoped to the caller's active
|
|
5
|
+
* organization — never accepts an organizationId from the request.
|
|
6
|
+
*/
|
|
7
|
+
export declare class ConfigurationsController {
|
|
8
|
+
private readonly configurations;
|
|
9
|
+
constructor(configurations: ConfigurationsService);
|
|
10
|
+
list(session: UserSession): import("../generated/prisma/internal/prismaNamespace.js").PrismaPromise<({
|
|
11
|
+
provider: {
|
|
12
|
+
key: string;
|
|
13
|
+
id: string;
|
|
14
|
+
name: string;
|
|
15
|
+
authType: import("../generated/prisma/enums.js").AuthType;
|
|
16
|
+
createdAt: Date;
|
|
17
|
+
updatedAt: Date;
|
|
18
|
+
authorizationUrl: string | null;
|
|
19
|
+
tokenUrl: string | null;
|
|
20
|
+
revokeUrl: string | null;
|
|
21
|
+
apiBaseUrl: string | null;
|
|
22
|
+
scopesAvailable: string[];
|
|
23
|
+
docsUrl: string | null;
|
|
24
|
+
logoUrl: string | null;
|
|
25
|
+
isActive: boolean;
|
|
26
|
+
};
|
|
27
|
+
} & {
|
|
28
|
+
id: string;
|
|
29
|
+
organizationId: string;
|
|
30
|
+
providerId: string;
|
|
31
|
+
name: string;
|
|
32
|
+
environment: import("../generated/prisma/enums.js").ConnectionEnvironment;
|
|
33
|
+
authType: import("../generated/prisma/enums.js").AuthType;
|
|
34
|
+
clientId: string | null;
|
|
35
|
+
redirectUri: string | null;
|
|
36
|
+
scopes: string[];
|
|
37
|
+
isEnabled: boolean;
|
|
38
|
+
metadata: import("@prisma/client/runtime/client").JsonValue | null;
|
|
39
|
+
createdAt: Date;
|
|
40
|
+
updatedAt: Date;
|
|
41
|
+
})[]>;
|
|
42
|
+
get(session: UserSession, id: string): Promise<{
|
|
43
|
+
provider: {
|
|
44
|
+
key: string;
|
|
45
|
+
id: string;
|
|
46
|
+
name: string;
|
|
47
|
+
authType: import("../generated/prisma/enums.js").AuthType;
|
|
48
|
+
createdAt: Date;
|
|
49
|
+
updatedAt: Date;
|
|
50
|
+
authorizationUrl: string | null;
|
|
51
|
+
tokenUrl: string | null;
|
|
52
|
+
revokeUrl: string | null;
|
|
53
|
+
apiBaseUrl: string | null;
|
|
54
|
+
scopesAvailable: string[];
|
|
55
|
+
docsUrl: string | null;
|
|
56
|
+
logoUrl: string | null;
|
|
57
|
+
isActive: boolean;
|
|
58
|
+
};
|
|
59
|
+
} & {
|
|
60
|
+
id: string;
|
|
61
|
+
organizationId: string;
|
|
62
|
+
providerId: string;
|
|
63
|
+
name: string;
|
|
64
|
+
environment: import("../generated/prisma/enums.js").ConnectionEnvironment;
|
|
65
|
+
authType: import("../generated/prisma/enums.js").AuthType;
|
|
66
|
+
clientId: string | null;
|
|
67
|
+
redirectUri: string | null;
|
|
68
|
+
scopes: string[];
|
|
69
|
+
isEnabled: boolean;
|
|
70
|
+
metadata: import("@prisma/client/runtime/client").JsonValue | null;
|
|
71
|
+
createdAt: Date;
|
|
72
|
+
updatedAt: Date;
|
|
73
|
+
}>;
|
|
74
|
+
create(session: UserSession, body: CreateConfigurationInput): Promise<{
|
|
75
|
+
provider: {
|
|
76
|
+
key: string;
|
|
77
|
+
id: string;
|
|
78
|
+
name: string;
|
|
79
|
+
authType: import("../generated/prisma/enums.js").AuthType;
|
|
80
|
+
createdAt: Date;
|
|
81
|
+
updatedAt: Date;
|
|
82
|
+
authorizationUrl: string | null;
|
|
83
|
+
tokenUrl: string | null;
|
|
84
|
+
revokeUrl: string | null;
|
|
85
|
+
apiBaseUrl: string | null;
|
|
86
|
+
scopesAvailable: string[];
|
|
87
|
+
docsUrl: string | null;
|
|
88
|
+
logoUrl: string | null;
|
|
89
|
+
isActive: boolean;
|
|
90
|
+
};
|
|
91
|
+
} & {
|
|
92
|
+
id: string;
|
|
93
|
+
organizationId: string;
|
|
94
|
+
providerId: string;
|
|
95
|
+
name: string;
|
|
96
|
+
environment: import("../generated/prisma/enums.js").ConnectionEnvironment;
|
|
97
|
+
authType: import("../generated/prisma/enums.js").AuthType;
|
|
98
|
+
clientId: string | null;
|
|
99
|
+
redirectUri: string | null;
|
|
100
|
+
scopes: string[];
|
|
101
|
+
isEnabled: boolean;
|
|
102
|
+
metadata: import("@prisma/client/runtime/client").JsonValue | null;
|
|
103
|
+
createdAt: Date;
|
|
104
|
+
updatedAt: Date;
|
|
105
|
+
}>;
|
|
106
|
+
update(session: UserSession, id: string, body: UpdateConfigurationInput): Promise<{
|
|
107
|
+
provider: {
|
|
108
|
+
key: string;
|
|
109
|
+
id: string;
|
|
110
|
+
name: string;
|
|
111
|
+
authType: import("../generated/prisma/enums.js").AuthType;
|
|
112
|
+
createdAt: Date;
|
|
113
|
+
updatedAt: Date;
|
|
114
|
+
authorizationUrl: string | null;
|
|
115
|
+
tokenUrl: string | null;
|
|
116
|
+
revokeUrl: string | null;
|
|
117
|
+
apiBaseUrl: string | null;
|
|
118
|
+
scopesAvailable: string[];
|
|
119
|
+
docsUrl: string | null;
|
|
120
|
+
logoUrl: string | null;
|
|
121
|
+
isActive: boolean;
|
|
122
|
+
};
|
|
123
|
+
} & {
|
|
124
|
+
id: string;
|
|
125
|
+
organizationId: string;
|
|
126
|
+
providerId: string;
|
|
127
|
+
name: string;
|
|
128
|
+
environment: import("../generated/prisma/enums.js").ConnectionEnvironment;
|
|
129
|
+
authType: import("../generated/prisma/enums.js").AuthType;
|
|
130
|
+
clientId: string | null;
|
|
131
|
+
redirectUri: string | null;
|
|
132
|
+
scopes: string[];
|
|
133
|
+
isEnabled: boolean;
|
|
134
|
+
metadata: import("@prisma/client/runtime/client").JsonValue | null;
|
|
135
|
+
createdAt: Date;
|
|
136
|
+
updatedAt: Date;
|
|
137
|
+
}>;
|
|
138
|
+
remove(session: UserSession, id: string): Promise<{
|
|
139
|
+
id: string;
|
|
140
|
+
deleted: boolean;
|
|
141
|
+
}>;
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=configurations.controller.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { __decorate, __metadata, __param } from "tslib";
|
|
2
|
+
import { Body, Controller, Delete, Get, Param, Patch, Post, } from '@nestjs/common';
|
|
3
|
+
import { Session } from '@thallesp/nestjs-better-auth';
|
|
4
|
+
import { getActiveOrganizationId } from '../common/active-organization.js';
|
|
5
|
+
import { ConfigurationsService, } from './configurations.service.js';
|
|
6
|
+
/**
|
|
7
|
+
* Admin-facing. Session authenticated and scoped to the caller's active
|
|
8
|
+
* organization — never accepts an organizationId from the request.
|
|
9
|
+
*/
|
|
10
|
+
let ConfigurationsController = class ConfigurationsController {
|
|
11
|
+
configurations;
|
|
12
|
+
constructor(configurations) {
|
|
13
|
+
this.configurations = configurations;
|
|
14
|
+
}
|
|
15
|
+
list(session) {
|
|
16
|
+
return this.configurations.list(getActiveOrganizationId(session));
|
|
17
|
+
}
|
|
18
|
+
get(session, id) {
|
|
19
|
+
return this.configurations.get(getActiveOrganizationId(session), id);
|
|
20
|
+
}
|
|
21
|
+
create(session, body) {
|
|
22
|
+
return this.configurations.create(getActiveOrganizationId(session), body);
|
|
23
|
+
}
|
|
24
|
+
update(session, id, body) {
|
|
25
|
+
return this.configurations.update(getActiveOrganizationId(session), id, body);
|
|
26
|
+
}
|
|
27
|
+
async remove(session, id) {
|
|
28
|
+
await this.configurations.remove(getActiveOrganizationId(session), id);
|
|
29
|
+
return { id, deleted: true };
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
__decorate([
|
|
33
|
+
Get(),
|
|
34
|
+
__param(0, Session()),
|
|
35
|
+
__metadata("design:type", Function),
|
|
36
|
+
__metadata("design:paramtypes", [Object]),
|
|
37
|
+
__metadata("design:returntype", void 0)
|
|
38
|
+
], ConfigurationsController.prototype, "list", null);
|
|
39
|
+
__decorate([
|
|
40
|
+
Get(':id'),
|
|
41
|
+
__param(0, Session()),
|
|
42
|
+
__param(1, Param('id')),
|
|
43
|
+
__metadata("design:type", Function),
|
|
44
|
+
__metadata("design:paramtypes", [Object, String]),
|
|
45
|
+
__metadata("design:returntype", void 0)
|
|
46
|
+
], ConfigurationsController.prototype, "get", null);
|
|
47
|
+
__decorate([
|
|
48
|
+
Post(),
|
|
49
|
+
__param(0, Session()),
|
|
50
|
+
__param(1, Body()),
|
|
51
|
+
__metadata("design:type", Function),
|
|
52
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
53
|
+
__metadata("design:returntype", void 0)
|
|
54
|
+
], ConfigurationsController.prototype, "create", null);
|
|
55
|
+
__decorate([
|
|
56
|
+
Patch(':id'),
|
|
57
|
+
__param(0, Session()),
|
|
58
|
+
__param(1, Param('id')),
|
|
59
|
+
__param(2, Body()),
|
|
60
|
+
__metadata("design:type", Function),
|
|
61
|
+
__metadata("design:paramtypes", [Object, String, Object]),
|
|
62
|
+
__metadata("design:returntype", void 0)
|
|
63
|
+
], ConfigurationsController.prototype, "update", null);
|
|
64
|
+
__decorate([
|
|
65
|
+
Delete(':id'),
|
|
66
|
+
__param(0, Session()),
|
|
67
|
+
__param(1, Param('id')),
|
|
68
|
+
__metadata("design:type", Function),
|
|
69
|
+
__metadata("design:paramtypes", [Object, String]),
|
|
70
|
+
__metadata("design:returntype", Promise)
|
|
71
|
+
], ConfigurationsController.prototype, "remove", null);
|
|
72
|
+
ConfigurationsController = __decorate([
|
|
73
|
+
Controller('configurations'),
|
|
74
|
+
__metadata("design:paramtypes", [ConfigurationsService])
|
|
75
|
+
], ConfigurationsController);
|
|
76
|
+
export { ConfigurationsController };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configurations.module.d.ts","sourceRoot":"","sources":["../../src/configurations/configurations.module.ts"],"names":[],"mappings":"AAIA,qBAKa,oBAAoB;CAAG"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import { Module } from '@nestjs/common';
|
|
3
|
+
import { ConfigurationsController } from './configurations.controller.js';
|
|
4
|
+
import { ConfigurationsService } from './configurations.service.js';
|
|
5
|
+
let ConfigurationsModule = class ConfigurationsModule {
|
|
6
|
+
};
|
|
7
|
+
ConfigurationsModule = __decorate([
|
|
8
|
+
Module({
|
|
9
|
+
controllers: [ConfigurationsController],
|
|
10
|
+
providers: [ConfigurationsService],
|
|
11
|
+
exports: [ConfigurationsService],
|
|
12
|
+
})
|
|
13
|
+
], ConfigurationsModule);
|
|
14
|
+
export { ConfigurationsModule };
|