@hasna/switcher 0.2.1 → 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.1",
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"
@@ -1232,6 +1338,29 @@
1232
1338
  "api-key"
1233
1339
  ]
1234
1340
  },
1341
+ "credentialCheck": {
1342
+ "type": "object",
1343
+ "properties": {
1344
+ "method": {
1345
+ "type": "string",
1346
+ "enum": [
1347
+ "GET",
1348
+ "HEAD"
1349
+ ],
1350
+ "default": "GET"
1351
+ },
1352
+ "path": {
1353
+ "type": "string",
1354
+ "minLength": 1,
1355
+ "maxLength": 200,
1356
+ "pattern": "^[a-zA-Z0-9_~!$&'()*+,;=:@%./-]+$"
1357
+ }
1358
+ },
1359
+ "required": [
1360
+ "path"
1361
+ ],
1362
+ "additionalProperties": false
1363
+ },
1235
1364
  "catalogBaseUrl": {
1236
1365
  "type": "string",
1237
1366
  "maxLength": 2000
@@ -1341,6 +1470,29 @@
1341
1470
  ],
1342
1471
  "default": "bearer"
1343
1472
  },
1473
+ "credentialCheck": {
1474
+ "type": "object",
1475
+ "properties": {
1476
+ "method": {
1477
+ "type": "string",
1478
+ "enum": [
1479
+ "GET",
1480
+ "HEAD"
1481
+ ],
1482
+ "default": "GET"
1483
+ },
1484
+ "path": {
1485
+ "type": "string",
1486
+ "minLength": 1,
1487
+ "maxLength": 200,
1488
+ "pattern": "^[a-zA-Z0-9_~!$&'()*+,;=:@%./-]+$"
1489
+ }
1490
+ },
1491
+ "required": [
1492
+ "path"
1493
+ ],
1494
+ "additionalProperties": false
1495
+ },
1344
1496
  "catalogBaseUrl": {
1345
1497
  "type": "string",
1346
1498
  "maxLength": 2000
@@ -1619,6 +1771,29 @@
1619
1771
  ],
1620
1772
  "default": "bearer"
1621
1773
  },
1774
+ "credentialCheck": {
1775
+ "type": "object",
1776
+ "properties": {
1777
+ "method": {
1778
+ "type": "string",
1779
+ "enum": [
1780
+ "GET",
1781
+ "HEAD"
1782
+ ],
1783
+ "default": "GET"
1784
+ },
1785
+ "path": {
1786
+ "type": "string",
1787
+ "minLength": 1,
1788
+ "maxLength": 200,
1789
+ "pattern": "^[a-zA-Z0-9_~!$&'()*+,;=:@%./-]+$"
1790
+ }
1791
+ },
1792
+ "required": [
1793
+ "path"
1794
+ ],
1795
+ "additionalProperties": false
1796
+ },
1622
1797
  "catalogBaseUrl": {
1623
1798
  "type": "string",
1624
1799
  "maxLength": 2000
@@ -2680,10 +2855,12 @@
2680
2855
  "name"
2681
2856
  ],
2682
2857
  "additionalProperties": false
2683
- }
2858
+ },
2859
+ "maxItems": 10000
2684
2860
  },
2685
2861
  "refreshedAt": {
2686
- "type": "string"
2862
+ "type": "string",
2863
+ "format": "date-time"
2687
2864
  },
2688
2865
  "source": {
2689
2866
  "type": "string",
@@ -2741,6 +2918,29 @@
2741
2918
  ],
2742
2919
  "default": "bearer"
2743
2920
  },
2921
+ "credentialCheck": {
2922
+ "type": "object",
2923
+ "properties": {
2924
+ "method": {
2925
+ "type": "string",
2926
+ "enum": [
2927
+ "GET",
2928
+ "HEAD"
2929
+ ],
2930
+ "default": "GET"
2931
+ },
2932
+ "path": {
2933
+ "type": "string",
2934
+ "minLength": 1,
2935
+ "maxLength": 200,
2936
+ "pattern": "^[a-zA-Z0-9_~!$&'()*+,;=:@%./-]+$"
2937
+ }
2938
+ },
2939
+ "required": [
2940
+ "path"
2941
+ ],
2942
+ "additionalProperties": false
2943
+ },
2744
2944
  "catalogBaseUrl": {
2745
2945
  "type": "string",
2746
2946
  "maxLength": 2000
@@ -3245,10 +3445,12 @@
3245
3445
  "name"
3246
3446
  ],
3247
3447
  "additionalProperties": false
3248
- }
3448
+ },
3449
+ "maxItems": 10000
3249
3450
  },
3250
3451
  "refreshedAt": {
3251
- "type": "string"
3452
+ "type": "string",
3453
+ "format": "date-time"
3252
3454
  },
3253
3455
  "source": {
3254
3456
  "type": "string",
@@ -3874,15 +4076,31 @@
3874
4076
  "Ready": {
3875
4077
  "type": "object",
3876
4078
  "properties": {
3877
- "ready": {
3878
- "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
+ ]
3879
4095
  },
3880
4096
  "reason": {
3881
4097
  "type": "string"
3882
4098
  }
3883
4099
  },
3884
4100
  "required": [
3885
- "ready"
4101
+ "status",
4102
+ "version",
4103
+ "backend"
3886
4104
  ],
3887
4105
  "additionalProperties": false
3888
4106
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hasna/switcher",
3
- "version": "0.2.1",
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",