@kosha-ai/integration-basic 0.0.0-stage → 0.4.0

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 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.
package/README.md CHANGED
@@ -1,3 +1,49 @@
1
- # Temporary Holding Version
1
+ # @kosha-ai/integration-basic
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Any API behind HTTP Basic auth.
4
+
5
+ Unlike every other integration there is no provider here: the operator gives a
6
+ base URL per configuration, the end user gives a username and password, and
7
+ Kosha proxies with `Authorization: Basic base64(username:password)`.
8
+
9
+ ```ts
10
+ import { basic } from '@kosha-ai/integration-basic';
11
+
12
+ export default defineConfig({
13
+ integrations: [basic()],
14
+ });
15
+ ```
16
+
17
+ Rename the two fields where the API calls them something else:
18
+
19
+ ```ts
20
+ basic({
21
+ credentialFields: [
22
+ { key: 'username', label: 'Email', type: 'string', required: true },
23
+ {
24
+ key: 'password',
25
+ label: 'API token',
26
+ type: 'string',
27
+ required: true,
28
+ secret: true,
29
+ },
30
+ ],
31
+ });
32
+ ```
33
+
34
+ ## What it does not do
35
+
36
+ **No identity.** An arbitrary API has no endpoint meaning "this credential is
37
+ good", so nothing is checked at connect and a wrong password surfaces on the
38
+ first proxied call. The connection is labelled with the username because that
39
+ is the only identity available.
40
+
41
+ **No refresh.** A password does not expire on a schedule anyone can see.
42
+
43
+ ## The base URL
44
+
45
+ Operator-supplied and called by the server, so it is checked on every proxied
46
+ request: https only, and refused if the hostname resolves to a loopback,
47
+ link-local, private or carrier-grade NAT address. Checked per request rather
48
+ than only when saved, since a hostname that answers publicly today can answer
49
+ privately tomorrow.
@@ -0,0 +1,2 @@
1
+ export { basic, basic as default } from './lib/integration-basic.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,IAAI,OAAO,EAAE,MAAM,4BAA4B,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export { basic, basic as default } from './lib/integration-basic.js';
@@ -0,0 +1,15 @@
1
+ import type { BasicOptions, KoshaIntegration } from '@kosha-ai/integration-sdk';
2
+ export type BasicIntegrationOptions = BasicOptions;
3
+ /**
4
+ * Any API behind HTTP Basic auth.
5
+ *
6
+ * The operator gives a base URL per configuration and the end user gives a
7
+ * username and password, so there is no provider to name here at all.
8
+ *
9
+ * It offers no identity discovery: nothing is known about the account beyond
10
+ * that the credential works, so the person on the connection is provenance
11
+ * rather than a looked-up identity.
12
+ */
13
+ export declare function basic(options?: BasicIntegrationOptions): KoshaIntegration;
14
+ export default basic;
15
+ //# sourceMappingURL=integration-basic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"integration-basic.d.ts","sourceRoot":"","sources":["../../src/lib/integration-basic.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAIhF,MAAM,MAAM,uBAAuB,GAAG,YAAY,CAAC;AAEnD;;;;;;;;;GASG;AACH,wBAAgB,KAAK,CAAC,OAAO,GAAE,uBAA4B,GAAG,gBAAgB,CAyD7E;AAED,eAAe,KAAK,CAAC"}
@@ -0,0 +1,65 @@
1
+ import { basic as basicAuth, defineIntegration, packageDirs, } from '@kosha-ai/integration-sdk';
2
+ const { docsPath, migrationsPath } = packageDirs(import.meta.url);
3
+ /**
4
+ * Any API behind HTTP Basic auth.
5
+ *
6
+ * The operator gives a base URL per configuration and the end user gives a
7
+ * username and password, so there is no provider to name here at all.
8
+ *
9
+ * It offers no identity discovery: nothing is known about the account beyond
10
+ * that the credential works, so the person on the connection is provenance
11
+ * rather than a looked-up identity.
12
+ */
13
+ export function basic(options = {}) {
14
+ return defineIntegration({
15
+ key: 'basic',
16
+ name: 'Basic auth',
17
+ docsPath,
18
+ migrationsPath,
19
+ auth: basicAuth(options),
20
+ configFields: [
21
+ {
22
+ key: 'baseUrl',
23
+ label: 'Base URL',
24
+ type: 'url',
25
+ required: true,
26
+ help: 'The API root, e.g. https://api.acme.test/v1. Must be https.',
27
+ },
28
+ {
29
+ key: 'verifyPath',
30
+ label: 'Verification path',
31
+ type: 'string',
32
+ help: 'Optional. A path returning 200 when the credential works, e.g. /me. Without it a wrong password is only found on the first proxied call.',
33
+ },
34
+ ],
35
+ api: {
36
+ // Per configuration, not per package: this provider is whatever the
37
+ // operator pointed it at.
38
+ resolveBaseUrl: ({ fields }) => typeof fields?.['baseUrl'] === 'string' ? fields['baseUrl'] : undefined,
39
+ authHeaders: ({ accessToken }) => ({
40
+ Authorization: `Basic ${accessToken}`,
41
+ }),
42
+ },
43
+ identity: {
44
+ /**
45
+ * The operator names a path that answers 200 to a working credential,
46
+ * because only they know their API. Given one, a wrong password is
47
+ * refused at connect; without one it surfaces on the first proxied call.
48
+ *
49
+ * There is no account to look up either way, so the username is the
50
+ * identity: it is what the credential says it is.
51
+ */
52
+ async fetchAccount({ accessToken, http, fields }) {
53
+ const verifyPath = fields?.['verifyPath'];
54
+ if (typeof verifyPath === 'string' && verifyPath.trim() !== '') {
55
+ await http.get(verifyPath.trim(), { accessToken });
56
+ }
57
+ const [username] = Buffer.from(accessToken, 'base64')
58
+ .toString()
59
+ .split(':');
60
+ return { externalAccountId: username || 'unknown' };
61
+ },
62
+ },
63
+ });
64
+ }
65
+ export default basic;
package/docs/setup.md ADDED
@@ -0,0 +1,22 @@
1
+ # Basic auth setup
2
+
3
+ There is nothing to register. You need two things.
4
+
5
+ ### 1. The base URL
6
+
7
+ The API root your users will reach, for example `https://api.acme.test/v1`.
8
+ Paste it when you create the configuration.
9
+
10
+ It must be `https`, and it must resolve to a public address. A URL pointing at
11
+ `localhost`, a private range or a link-local address is refused, because Kosha
12
+ would be the one making the request and an operator could otherwise reach
13
+ inside the network Kosha runs in.
14
+
15
+ ### 2. The credentials
16
+
17
+ Each person connecting supplies their own username and password for that API.
18
+ They are encrypted and stored against that connection alone.
19
+
20
+ Kosha cannot check them when they are entered: an arbitrary API has no endpoint
21
+ that means "this credential is good". A wrong password shows up on the first
22
+ proxied call as that API's own 401.
@@ -0,0 +1,54 @@
1
+ CREATE TABLE "basic_configuration" (
2
+ "id" TEXT NOT NULL,
3
+ "environmentId" TEXT NOT NULL,
4
+ "name" TEXT NOT NULL,
5
+ "slug" TEXT NOT NULL,
6
+ -- Encrypted, so TEXT rather than JSONB.
7
+ "credentials" TEXT,
8
+ -- The API this configuration fronts. Operator-supplied, so checked
9
+ -- against private ranges before anything is fetched.
10
+ "baseUrl" TEXT NOT NULL,
11
+ -- Optional: a path that answers 200 to a working credential, so a wrong
12
+ -- one is refused at connect rather than on the first proxied call.
13
+ "verifyPath" TEXT,
14
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
15
+ "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
16
+
17
+ CONSTRAINT "basic_configuration_pkey" PRIMARY KEY ("id")
18
+ );
19
+
20
+ CREATE TABLE "basic_connection" (
21
+ "accountId" TEXT NOT NULL,
22
+ -- Copied from `account` so the unique index below can use it.
23
+ "userId" TEXT NOT NULL,
24
+ "environmentId" TEXT NOT NULL,
25
+ "configurationId" TEXT NOT NULL,
26
+ "metadata" JSONB,
27
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
28
+ "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
29
+
30
+ CONSTRAINT "basic_connection_pkey" PRIMARY KEY ("accountId")
31
+ );
32
+
33
+ CREATE UNIQUE INDEX "basic_configuration_environmentId_slug_key" ON "basic_configuration"("environmentId", "slug");
34
+
35
+ CREATE INDEX "basic_configuration_environmentId_idx" ON "basic_configuration"("environmentId");
36
+
37
+ CREATE UNIQUE INDEX "basic_connection_environmentId_configurationId_userId_key" ON "basic_connection"("environmentId", "configurationId", "userId");
38
+
39
+ CREATE INDEX "basic_connection_environmentId_idx" ON "basic_connection"("environmentId");
40
+
41
+ CREATE INDEX "basic_connection_configurationId_idx" ON "basic_connection"("configurationId");
42
+
43
+ CREATE INDEX "basic_connection_userId_idx" ON "basic_connection"("userId");
44
+
45
+ ALTER TABLE "basic_configuration" ADD CONSTRAINT "basic_configuration_environmentId_fkey" FOREIGN KEY ("environmentId") REFERENCES "environment"("id") ON DELETE CASCADE ON UPDATE CASCADE;
46
+
47
+ ALTER TABLE "basic_connection" ADD CONSTRAINT "basic_connection_accountId_fkey" FOREIGN KEY ("accountId") REFERENCES "account"("id") ON DELETE CASCADE ON UPDATE CASCADE;
48
+
49
+ ALTER TABLE "basic_connection" ADD CONSTRAINT "basic_connection_userId_fkey" FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE CASCADE ON UPDATE CASCADE;
50
+
51
+ ALTER TABLE "basic_connection" ADD CONSTRAINT "basic_connection_environmentId_fkey" FOREIGN KEY ("environmentId") REFERENCES "environment"("id") ON DELETE CASCADE ON UPDATE CASCADE;
52
+
53
+ -- RESTRICT: a configuration that still has connections cannot be deleted.
54
+ ALTER TABLE "basic_connection" ADD CONSTRAINT "basic_connection_configurationId_fkey" FOREIGN KEY ("configurationId") REFERENCES "basic_configuration"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
package/package.json CHANGED
@@ -1,6 +1,55 @@
1
1
  {
2
2
  "name": "@kosha-ai/integration-basic",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.4.0",
4
+ "description": "Basic-auth integration for Kosha: any API behind a username and password",
5
+ "keywords": [
6
+ "kosha",
7
+ "basic-auth",
8
+ "integrations"
9
+ ],
10
+ "license": "MIT",
11
+ "homepage": "https://github.com/codemancers/kosha#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/codemancers/kosha/issues"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/codemancers/kosha.git",
18
+ "directory": "packages/integrations/basic"
19
+ },
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "type": "module",
24
+ "main": "./dist/index.js",
25
+ "module": "./dist/index.js",
26
+ "types": "./dist/index.d.ts",
27
+ "exports": {
28
+ "./package.json": "./package.json",
29
+ ".": {
30
+ "@org/source": "./src/index.ts",
31
+ "types": "./dist/index.d.ts",
32
+ "import": "./dist/index.js",
33
+ "default": "./dist/index.js"
34
+ }
35
+ },
36
+ "files": [
37
+ "dist",
38
+ "docs",
39
+ "migrations",
40
+ "!**/*.tsbuildinfo"
41
+ ],
42
+ "dependencies": {
43
+ "tslib": "^2.3.0"
44
+ },
45
+ "kosha": {
46
+ "kind": "integration",
47
+ "key": "basic"
48
+ },
49
+ "peerDependencies": {
50
+ "@kosha-ai/integration-sdk": "0.4.0"
51
+ },
52
+ "devDependencies": {
53
+ "@kosha-ai/integration-sdk": "0.4.0"
54
+ }
6
55
  }