@hasna/switcher 0.2.2 → 0.2.3

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/dist/server.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { CatalogCredentialResolver } from "./catalog";
2
2
  export type ServerOptions = {
3
- apiKey: string;
3
+ apiKey?: string;
4
+ signingSecret?: string;
4
5
  databaseUrl?: string;
5
6
  sqlitePath?: string;
6
7
  hostname?: string;
package/dist/service.d.ts CHANGED
@@ -1,3 +1,10 @@
1
+ import { type ApiKeyStatus, type AuthAuditHook } from "@hasna/contracts/auth";
1
2
  import { Store } from "./store";
2
3
  import { type CatalogCredentialResolver } from "./catalog";
3
- export declare function createHandler(store: Store, apiKey: string, providerEnv?: Record<string, string | undefined>, resolveCredential?: CatalogCredentialResolver): (request: Request) => Promise<Response>;
4
+ export type ServiceAuthentication = string | {
5
+ kind: "signed-api-key";
6
+ signingSecret: string | Buffer;
7
+ keyStatus: (kid: string) => ApiKeyStatus | Promise<ApiKeyStatus>;
8
+ audit?: AuthAuditHook;
9
+ };
10
+ export declare function createHandler(store: Store, authentication: ServiceAuthentication, providerEnv?: Record<string, string | undefined>, resolveCredential?: CatalogCredentialResolver): (request: Request) => Promise<Response>;
package/dist/store.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { SQL } from "bun";
2
+ import { type AuthQueryClient } from "@hasna/contracts/auth";
2
3
  type Connection = Pick<SQL, "unsafe">;
3
4
  export type Resource = "providers" | "profiles" | "runs" | "catalogs";
4
5
  export type RecordValue = {
@@ -16,9 +17,12 @@ export declare class Store {
16
17
  static open(config: {
17
18
  databaseUrl?: string;
18
19
  sqlitePath?: string;
20
+ migrate?: boolean;
19
21
  }): Promise<Store>;
20
22
  private migrate;
23
+ private verifySchema;
21
24
  ready(): Promise<void>;
25
+ authQueryClient(): AuthQueryClient;
22
26
  close(): Promise<void>;
23
27
  get<T>(kind: Resource, id: string, db?: Connection): Promise<T>;
24
28
  private read;
@@ -5,14 +5,15 @@
5
5
  "class": "cli-with-store",
6
6
  "contractVersion": "v1",
7
7
  "kitVersion": "1.0.2",
8
- "description": "Universal provider and model switcher for coding harnesses with an API, SDK and self-hosted storage",
8
+ "description": "Universal provider and model switcher with API-first local and hosted operation. CLI, MCP and SDK resolve one authenticated HTTP authority through @hasna/contracts and fail closed when hosted configuration is missing or invalid. HASNA_SWITCHER_LOCAL=1 deliberately selects an owned loopback API backed by SQLite; hosted https://api.hasna.com/switcher uses PostgreSQL and signed revocable API keys. Provider credentials remain local to the launcher and are never stored or returned by the service.",
9
9
  "bins": [
10
10
  "switcher",
11
11
  "switcher-mcp",
12
12
  "switcher-serve"
13
13
  ],
14
14
  "hosting": [
15
- "user-hosted"
15
+ "user-hosted",
16
+ "hasna-saas"
16
17
  ],
17
18
  "serviceSurfaces": [
18
19
  {
@@ -37,7 +38,7 @@
37
38
  "public": true
38
39
  },
39
40
  "apiBasePath": "/v1",
40
- "openApiPath": "/v1/openapi.json"
41
+ "openApiPath": "/openapi.json"
41
42
  },
42
43
  {
43
44
  "name": "package-sdk",
@@ -45,7 +46,7 @@
45
46
  "status": "supported",
46
47
  "authMode": "api-key",
47
48
  "exportSubpath": "./sdk",
48
- "generatedFrom": "/v1/openapi.json"
49
+ "generatedFrom": "/openapi.json"
49
50
  },
50
51
  {
51
52
  "name": "mcp",
@@ -63,7 +64,7 @@
63
64
  }
64
65
  ],
65
66
  "storage": {
66
- "backend": "postgresql",
67
+ "backend": "sqlite",
67
68
  "engines": [
68
69
  "sqlite",
69
70
  "postgresql"
@@ -88,7 +89,20 @@
88
89
  "sqlite",
89
90
  "postgresql"
90
91
  ],
91
- "scope": "Only switcher HTTP server; all CLI, SDK and MCP data access remains authenticated HTTP. PostgreSQL remains canonical backend."
92
+ "scope": "The owned local HTTP API uses SQLite; the hosted HTTP API uses PostgreSQL. CLI, SDK and MCP always use authenticated HTTP, and a selected hosted authority never falls back to local storage."
93
+ },
94
+ "service": {
95
+ "port": 8080,
96
+ "healthPath": "/health",
97
+ "readyPath": "/ready",
98
+ "versionPath": "/version",
99
+ "openapiPath": "/openapi.json",
100
+ "apiVersion": "v1",
101
+ "auth": "api-key"
102
+ },
103
+ "client": {
104
+ "apiUrlEnv": "HASNA_SWITCHER_API_URL",
105
+ "apiKeyEnv": "HASNA_SWITCHER_API_KEY"
92
106
  }
93
107
  }
94
108
  }
package/openapi.json CHANGED
@@ -2,10 +2,13 @@
2
2
  "openapi": "3.0.3",
3
3
  "info": {
4
4
  "title": "Switcher API",
5
- "version": "0.2.2",
5
+ "version": "0.2.3",
6
6
  "description": "Authenticated provider/profile/catalog control plane. Launches run locally; the API never returns provider credentials."
7
7
  },
8
8
  "security": [
9
+ {
10
+ "apiKeyAuth": []
11
+ },
9
12
  {
10
13
  "bearerAuth": []
11
14
  }
@@ -759,6 +762,73 @@
759
762
  }
760
763
  }
761
764
  },
765
+ "responses": {
766
+ "200": {
767
+ "description": "Success",
768
+ "content": {
769
+ "application/json": {
770
+ "schema": {
771
+ "$ref": "#/components/schemas/Catalog"
772
+ }
773
+ }
774
+ }
775
+ },
776
+ "default": {
777
+ "description": "Structured error",
778
+ "content": {
779
+ "application/json": {
780
+ "schema": {
781
+ "$ref": "#/components/schemas/Error"
782
+ }
783
+ }
784
+ }
785
+ }
786
+ },
787
+ "description": "Self-hosted/local server refresh. Hosted clients discover locally and commit catalog metadata through the version-checked catalog endpoint."
788
+ }
789
+ },
790
+ "/v1/providers/{id}/catalog": {
791
+ "put": {
792
+ "operationId": "saveCatalog",
793
+ "parameters": [
794
+ {
795
+ "name": "id",
796
+ "in": "path",
797
+ "required": true,
798
+ "schema": {
799
+ "type": "string"
800
+ }
801
+ },
802
+ {
803
+ "name": "Idempotency-Key",
804
+ "in": "header",
805
+ "required": true,
806
+ "schema": {
807
+ "type": "string",
808
+ "minLength": 8,
809
+ "maxLength": 128
810
+ }
811
+ },
812
+ {
813
+ "name": "If-Match",
814
+ "in": "header",
815
+ "required": true,
816
+ "schema": {
817
+ "type": "integer",
818
+ "minimum": 1
819
+ }
820
+ }
821
+ ],
822
+ "requestBody": {
823
+ "required": true,
824
+ "content": {
825
+ "application/json": {
826
+ "schema": {
827
+ "$ref": "#/components/schemas/Catalog"
828
+ }
829
+ }
830
+ }
831
+ },
762
832
  "responses": {
763
833
  "200": {
764
834
  "description": "Success",
@@ -1146,6 +1216,36 @@
1146
1216
  }
1147
1217
  },
1148
1218
  "/v1/openapi.json": {
1219
+ "get": {
1220
+ "operationId": "openApiV1",
1221
+ "parameters": [],
1222
+ "responses": {
1223
+ "200": {
1224
+ "description": "Success",
1225
+ "content": {
1226
+ "application/json": {
1227
+ "schema": {
1228
+ "type": "object",
1229
+ "additionalProperties": true
1230
+ }
1231
+ }
1232
+ }
1233
+ },
1234
+ "default": {
1235
+ "description": "Structured error",
1236
+ "content": {
1237
+ "application/json": {
1238
+ "schema": {
1239
+ "$ref": "#/components/schemas/Error"
1240
+ }
1241
+ }
1242
+ }
1243
+ }
1244
+ },
1245
+ "security": []
1246
+ }
1247
+ },
1248
+ "/openapi.json": {
1149
1249
  "get": {
1150
1250
  "operationId": "openApi",
1151
1251
  "parameters": [],
@@ -1171,12 +1271,18 @@
1171
1271
  }
1172
1272
  }
1173
1273
  }
1174
- }
1274
+ },
1275
+ "security": []
1175
1276
  }
1176
1277
  }
1177
1278
  },
1178
1279
  "components": {
1179
1280
  "securitySchemes": {
1281
+ "apiKeyAuth": {
1282
+ "type": "apiKey",
1283
+ "in": "header",
1284
+ "name": "x-api-key"
1285
+ },
1180
1286
  "bearerAuth": {
1181
1287
  "type": "http",
1182
1288
  "scheme": "bearer"
@@ -2749,10 +2855,12 @@
2749
2855
  "name"
2750
2856
  ],
2751
2857
  "additionalProperties": false
2752
- }
2858
+ },
2859
+ "maxItems": 10000
2753
2860
  },
2754
2861
  "refreshedAt": {
2755
- "type": "string"
2862
+ "type": "string",
2863
+ "format": "date-time"
2756
2864
  },
2757
2865
  "source": {
2758
2866
  "type": "string",
@@ -3337,10 +3445,12 @@
3337
3445
  "name"
3338
3446
  ],
3339
3447
  "additionalProperties": false
3340
- }
3448
+ },
3449
+ "maxItems": 10000
3341
3450
  },
3342
3451
  "refreshedAt": {
3343
- "type": "string"
3452
+ "type": "string",
3453
+ "format": "date-time"
3344
3454
  },
3345
3455
  "source": {
3346
3456
  "type": "string",
@@ -3966,15 +4076,31 @@
3966
4076
  "Ready": {
3967
4077
  "type": "object",
3968
4078
  "properties": {
3969
- "ready": {
3970
- "type": "boolean"
4079
+ "status": {
4080
+ "type": "string",
4081
+ "enum": [
4082
+ "ready",
4083
+ "unavailable"
4084
+ ]
4085
+ },
4086
+ "version": {
4087
+ "type": "string"
4088
+ },
4089
+ "backend": {
4090
+ "type": "string",
4091
+ "enum": [
4092
+ "sqlite",
4093
+ "postgresql"
4094
+ ]
3971
4095
  },
3972
4096
  "reason": {
3973
4097
  "type": "string"
3974
4098
  }
3975
4099
  },
3976
4100
  "required": [
3977
- "ready"
4101
+ "status",
4102
+ "version",
4103
+ "backend"
3978
4104
  ],
3979
4105
  "additionalProperties": false
3980
4106
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hasna/switcher",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "type": "module",
5
5
  "description": "Universal provider and model switcher for coding harnesses with an API, SDK and self-hosted storage",
6
6
  "license": "Apache-2.0",
@@ -68,14 +68,17 @@
68
68
  "@types/bun": "1.3.14",
69
69
  "typescript": "5.6.3",
70
70
  "openapi-typescript": "7.13.0",
71
- "zod-to-json-schema": "3.25.2"
71
+ "zod-to-json-schema": "3.25.2",
72
+ "@types/pg": "8.23.1"
72
73
  },
73
74
  "dependencies": {
74
75
  "@hasna/contracts": "1.0.2",
75
76
  "@modelcontextprotocol/sdk": "^1.29.0",
76
77
  "jsonc-parser": "3.3.1",
77
78
  "yaml": "2.9.0",
78
- "zod": "3.25.76"
79
+ "zod": "3.25.76",
80
+ "@aws-sdk/client-secrets-manager": "3.1127.0",
81
+ "pg": "8.23.0"
79
82
  },
80
83
  "repository": {
81
84
  "type": "git",