@synap-core/sdk 1.0.0 → 1.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synap-core/sdk",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "description": "Type-safe tRPC client SDK for Synap data pods",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -11,12 +11,28 @@
11
11
  "types": "./dist/index.d.ts",
12
12
  "import": "./dist/index.js",
13
13
  "require": "./dist/index.cjs"
14
+ },
15
+ "./public": {
16
+ "types": "./dist/public.d.ts",
17
+ "import": "./dist/public.js",
18
+ "require": "./dist/public.cjs"
19
+ },
20
+ "./testing": {
21
+ "types": "./dist/testing.d.ts",
22
+ "import": "./dist/testing.js",
23
+ "require": "./dist/testing.cjs"
14
24
  }
15
25
  },
16
26
  "files": [
17
27
  "dist",
18
- "src"
28
+ "src",
29
+ "!src/__tests__"
19
30
  ],
31
+ "scripts": {
32
+ "build": "tsup",
33
+ "typecheck": "tsc --noEmit",
34
+ "test": "vitest run"
35
+ },
20
36
  "keywords": [
21
37
  "synap",
22
38
  "sdk",
@@ -24,7 +40,7 @@
24
40
  "data-pod"
25
41
  ],
26
42
  "dependencies": {
27
- "@synap-core/api-types": "^1.23.3",
43
+ "@synap-core/api-types": "^1.25.7",
28
44
  "@trpc/client": "^11.10.0",
29
45
  "superjson": "^2.2.6"
30
46
  },
@@ -48,9 +64,5 @@
48
64
  "url": "https://github.com/synap/synap-app.git",
49
65
  "directory": "packages/sdk"
50
66
  },
51
- "license": "MIT",
52
- "scripts": {
53
- "build": "tsup",
54
- "typecheck": "tsc --noEmit"
55
- }
56
- }
67
+ "license": "MIT"
68
+ }
package/src/client.ts CHANGED
@@ -7,7 +7,7 @@
7
7
  *
8
8
  * const synap = createSynapClient({
9
9
  * podUrl: "https://pod.example.com",
10
- * apiKey: "sk_live_...",
10
+ * sessionToken: "<Kratos session token>",
11
11
  * workspaceId: "ws_...",
12
12
  * });
13
13
  *
@@ -33,8 +33,8 @@ export interface SynapClientOptions {
33
33
  podUrl: string;
34
34
 
35
35
  /**
36
- * Ory Kratos session token (for example, from the Pod's
37
- * `/api/federation/exchange` endpoint).
36
+ * Ory Kratos session token (the `session_token` a Kratos API / native
37
+ * login flow returns).
38
38
  * Sent as `X-Session-Token` header — preferred for non-browser clients
39
39
  * like extensions, CLI tools, and mobile apps.
40
40
  * @example "oathkeeper_token_..."
@@ -42,10 +42,13 @@ export interface SynapClientOptions {
42
42
  sessionToken?: string;
43
43
 
44
44
  /**
45
- * API key for authentication (Bearer token).
46
- * Generate one in your workspace developer settings.
45
+ * LOCAL_MODE token only (the desktop host's `LOCAL_AUTH_TOKEN`), sent as
46
+ * `Authorization: Bearer`. `/trpc` sits behind Ory session auth, so a real
47
+ * pod refuses hub / user API keys (`synap_hub_*`, `synap_user_*`) with a 401;
48
+ * this client throws early if given one. Use `@synap-core/hub-rest-client`
49
+ * against `/api/hub/*` for hub / user API keys, or `sessionToken` / cookies
50
+ * for a signed-in user.
47
51
  * If omitted, the client falls back to cookie-based Kratos session auth.
48
- * @example "sk_live_abc123..."
49
52
  */
50
53
  apiKey?: string;
51
54
 
@@ -75,6 +78,13 @@ export interface SynapClientOptions {
75
78
  onAuthError?: (error: { status: number; message: string }) => void;
76
79
  }
77
80
 
81
+ /**
82
+ * Prefixes of hub / user API keys (SSOT: `KEY_PREFIXES` in synap-backend
83
+ * `packages/database/src/schema/api-keys.ts`; hub_inbound keys use `synap_hub_`).
84
+ * The LOCAL_MODE token is random bytes and never starts with these.
85
+ */
86
+ const HUB_KEY_PREFIXES = ["synap_hub_", "synap_user_"] as const;
87
+
78
88
  /**
79
89
  * Creates a fully-typed tRPC client connected to a Synap data pod.
80
90
  *
@@ -86,6 +96,13 @@ export function createSynapClient(
86
96
  ): CreateTRPCClient<AppRouter> {
87
97
  const { podUrl, apiKey, workspaceId, extraHeaders, onAuthError } = options;
88
98
 
99
+ if (apiKey && HUB_KEY_PREFIXES.some((p) => apiKey.startsWith(p))) {
100
+ throw new Error(
101
+ "createSynapClient: this is a hub/user API key; /trpc only accepts a session or the local-mode token. " +
102
+ "Use @synap-core/hub-rest-client against /api/hub/* instead.",
103
+ );
104
+ }
105
+
89
106
  const url = `${podUrl.replace(/\/$/, "")}/trpc`;
90
107
 
91
108
  // Base fetch: always include credentials so session cookies are sent in
@@ -177,7 +194,7 @@ export function createSynapClient(
177
194
  headers: () => ({
178
195
  // Session token mode (Kratos, preferred for non-browser clients)
179
196
  ...(options.sessionToken ? { "x-session-token": options.sessionToken } : {}),
180
- // API key mode (Bearer, for legacy SDK usage)
197
+ // LOCAL_MODE token (Bearer); hub/user API keys are rejected above
181
198
  ...(apiKey && !options.sessionToken ? { Authorization: `Bearer ${apiKey}` } : {}),
182
199
  ...(workspaceId ? { "x-workspace-id": workspaceId } : {}),
183
200
  ...extraHeaders,
package/src/index.ts CHANGED
@@ -1,2 +1,15 @@
1
1
  export { createSynapClient } from "./client";
2
2
  export type { SynapClient, SynapClientOptions, AppRouter } from "./client";
3
+ export {
4
+ ensureTemplate,
5
+ ensuredWorkspaceId,
6
+ parseEnsureTemplateResult,
7
+ } from "./templates";
8
+ export type {
9
+ EnsureTemplateClient,
10
+ EnsureTemplateInput,
11
+ EnsureTemplateMissingTemplate,
12
+ EnsureTemplateOptions,
13
+ EnsureTemplateResult,
14
+ EnsureTemplateStatus,
15
+ } from "./templates";