@openbkn/bkn-sdk 0.1.1-alpha.1 → 0.1.1-alpha.11

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/index.d.ts CHANGED
@@ -14,11 +14,25 @@ interface ClientOptions {
14
14
  insecure?: boolean;
15
15
  }
16
16
  /** Fully resolved request context — every field is known. */
17
+ interface RefreshableTokens {
18
+ accessToken: string;
19
+ refreshToken?: string;
20
+ idToken?: string;
21
+ }
17
22
  interface RequestContext {
18
23
  baseUrl: string;
19
24
  token: string;
20
25
  businessDomain: string;
21
26
  insecure: boolean;
27
+ /**
28
+ * Stored-credential refresh: on a 401, swap the refresh token for a fresh
29
+ * access token, persist it, and retry once. Absent for explicit `--token`/env.
30
+ */
31
+ refresh?: {
32
+ refreshToken: string;
33
+ clientId?: string;
34
+ persist: (tokens: RefreshableTokens) => void;
35
+ };
22
36
  }
23
37
  declare const DEFAULT_BUSINESS_DOMAIN = "bd_public";
24
38
  /** Default list/query limits — see AGENTS.md conventions. */
@@ -112,42 +126,64 @@ interface AuditListOptions {
112
126
  }
113
127
  type MemberType = "user" | "department" | "group" | "app";
114
128
 
115
- /** Build / render a department hierarchy from flat ISF search entries. */
116
-
117
- interface OrgNode {
118
- id: string;
119
- name: string;
120
- children: OrgNode[];
121
- }
122
-
123
129
  declare function admin(ctx: RequestContext): {
124
130
  orgList: (opts?: AdminListOptions) => Promise<unknown>;
125
131
  orgGet: (deptId: string) => Promise<unknown>;
126
- orgMembers: (deptId: string, opts?: {
127
- role?: string;
128
- offset?: number;
129
- limit?: number;
130
- }) => Promise<unknown>;
131
- orgTree: (role?: string) => Promise<OrgNode[]>;
132
- orgCreate: (input: CreateOrgInput) => Promise<unknown>;
132
+ orgTree: (_role?: string) => Promise<unknown[]>;
133
+ orgMembers: (deptId: string, _opts?: unknown) => Promise<unknown>;
134
+ orgCreate: (input: CreateOrgInput) => Promise<{
135
+ id: string;
136
+ }>;
133
137
  orgUpdate: (deptId: string, input: UpdateOrgInput) => Promise<unknown>;
134
- orgDelete: (deptId: string) => Promise<unknown>;
138
+ orgDelete: (deptId: string) => Promise<{
139
+ ok: true;
140
+ }>;
135
141
  userList: (opts?: AdminListOptions) => Promise<unknown>;
136
142
  userGet: (userId: string) => Promise<unknown>;
137
- userRoles: (userId: string) => Promise<unknown>;
138
- userCreate: (input: CreateUserInput) => Promise<unknown>;
143
+ userRoles: (userId: string) => Promise<{
144
+ roles: {
145
+ name: string;
146
+ id: string;
147
+ }[];
148
+ }>;
149
+ userCreate: (input: CreateUserInput) => Promise<{
150
+ id: string;
151
+ }>;
139
152
  userUpdate: (userId: string, input: UpdateUserInput) => Promise<unknown>;
140
- userDelete: (userId: string) => Promise<unknown>;
141
- userResetPassword: (userId: string, newPassword: string) => Promise<unknown>;
142
- roleList: (opts?: ListRolesOptions) => Promise<unknown>;
153
+ userDelete: (userId: string) => Promise<{
154
+ ok: true;
155
+ }>;
156
+ userResetPassword: (userId: string, newPassword: string) => Promise<{
157
+ ok: true;
158
+ }>;
159
+ roleList: (_opts?: ListRolesOptions) => Promise<unknown>;
143
160
  roleGet: (roleId: string) => Promise<unknown>;
144
- roleMembers: (roleId: string, opts?: {
145
- keyword?: string;
146
- limit?: number;
161
+ roleMembers: (roleId: string, _opts?: unknown) => Promise<{
162
+ members: {
163
+ account: string;
164
+ id: string;
165
+ }[];
166
+ }>;
167
+ addRoleMember: (roleId: string, id: string, _type?: MemberType) => Promise<{
168
+ ok: true;
169
+ }>;
170
+ removeRoleMember: (roleId: string, id: string, _type?: MemberType) => Promise<{
171
+ ok: true;
172
+ }>;
173
+ roleCreate: (name: string, description?: string) => Promise<{
174
+ id: string;
175
+ }>;
176
+ roleUpdate: (roleId: string, input: {
177
+ name?: string;
178
+ description?: string;
147
179
  }) => Promise<unknown>;
148
- addRoleMember: (roleId: string, id: string, type?: MemberType) => Promise<unknown>;
149
- removeRoleMember: (roleId: string, id: string, type?: MemberType) => Promise<unknown>;
150
- auditList: (opts?: AuditListOptions) => Promise<unknown>;
180
+ roleDelete: (roleId: string) => Promise<{
181
+ ok: true;
182
+ }>;
183
+ rolePermission: (roleId: string, grant: boolean, resourceType: string, resourceId: string, operations: string[]) => Promise<{
184
+ ok: true;
185
+ }>;
186
+ auditList: (_opts?: AuditListOptions) => never;
151
187
  };
152
188
 
153
189
  interface ChatResult {
@@ -209,6 +245,61 @@ declare function agents(ctx: RequestContext): {
209
245
  }) => Promise<ChatResult>;
210
246
  };
211
247
 
248
+ /**
249
+ * AppKey API (`/api/safe/v1/{me,admin}/api-keys`, OAuth-token-gated). AppKeys
250
+ * are user-issued long-lived credentials (prefix `bak_`) that authenticate AS
251
+ * their owner — downstream authorization is identical to that owner's OAuth
252
+ * token. Issuing/managing them needs a real OAuth session (an AppKey itself
253
+ * cannot mint AppKeys). The plaintext `key` is returned ONCE, on create.
254
+ * Usage of an AppKey is drop-in: pass it as the bearer `--token` against the
255
+ * Context Loader (agent-retrieval) MCP/REST surface. See issue #75.
256
+ */
257
+
258
+ /** A key's public metadata — never carries the secret. */
259
+ interface ApiKey {
260
+ id: string;
261
+ key_id: string;
262
+ name: string;
263
+ enabled: boolean;
264
+ /** `null` = never expires. */
265
+ expires_at: string | null;
266
+ /** `null` = never used (zombie-key signal). */
267
+ last_used_at: string | null;
268
+ created_at: string;
269
+ /** Present only on the admin list. */
270
+ owner_user_id?: string;
271
+ }
272
+ /** Create response — `key` is the full plaintext, shown only this once. */
273
+ interface CreatedApiKey extends ApiKey {
274
+ key: string;
275
+ }
276
+ interface CreateApiKeyInput {
277
+ name: string;
278
+ /** RFC3339; omit = backend default (1 year). Must be in the future. */
279
+ expiresAt?: string;
280
+ /** `true` = never expire (wins over `expiresAt`). */
281
+ neverExpire?: boolean;
282
+ }
283
+
284
+ declare function appKeys(ctx: RequestContext): {
285
+ /** List the caller's own keys (no secrets). */
286
+ list: () => Promise<{
287
+ keys: ApiKey[];
288
+ }>;
289
+ /** Issue a key — the result's `key` is the plaintext, shown only once. */
290
+ create: (input: CreateApiKeyInput) => Promise<CreatedApiKey>;
291
+ /** Revoke one of the caller's keys (immediate). */
292
+ revoke: (id: string) => Promise<void>;
293
+ /** Rotate a key in place — new plaintext (shown once); old secret dies now. */
294
+ regenerate: (id: string) => Promise<CreatedApiKey>;
295
+ /** Admin: list all keys, or one owner's (adds `owner_user_id`). */
296
+ adminList: (ownerId?: string) => Promise<{
297
+ keys: ApiKey[];
298
+ }>;
299
+ /** Admin: revoke any key. */
300
+ adminRevoke: (id: string) => Promise<void>;
301
+ };
302
+
212
303
  /**
213
304
  * Context-loader client over the agent-retrieval MCP endpoint (JSON-RPC).
214
305
  * Reimplemented slim from kweaver-sdk: initialize → session id →
@@ -227,8 +318,10 @@ declare function context(ctx: RequestContext): {
227
318
  searchSchema: (knId: string, query: string, opts?: SearchSchemaOptions) => Promise<unknown>;
228
319
  queryObjectInstance: (knId: string, args: Record<string, unknown>) => Promise<unknown>;
229
320
  findSkills: (knId: string, objectTypeId: string, topK?: number) => Promise<unknown>;
321
+ info: () => Promise<unknown>;
230
322
  tools: (knId: string) => Promise<unknown>;
231
323
  toolCall: (knId: string, name: string, args: Record<string, unknown>) => Promise<unknown>;
324
+ callMethod: (knId: string, method: string, params?: Record<string, unknown>) => Promise<unknown>;
232
325
  queryInstanceSubgraph: (knId: string, args: Record<string, unknown>) => Promise<unknown>;
233
326
  logicProperties: (knId: string, args: Record<string, unknown>) => Promise<unknown>;
234
327
  actionInfo: (knId: string, args: Record<string, unknown>) => Promise<unknown>;
@@ -790,6 +883,22 @@ declare const BuildTask: z.ZodObject<{
790
883
  model_dimensions: z.ZodOptional<z.ZodNumber>;
791
884
  }, z.ZodTypeAny, "passthrough">>;
792
885
  type BuildTask = z.infer<typeof BuildTask>;
886
+ interface SqlQueryRequest {
887
+ /** SQL string (MySQL/MariaDB/PostgreSQL) or an OpenSearch DSL object. */
888
+ query: string | Record<string, unknown>;
889
+ /**
890
+ * Source type (mysql | mariadb | postgresql | opensearch …). Optional — when
891
+ * the query carries a `{{<resource-id>}}` placeholder the backend infers the
892
+ * type from that resource's Catalog connector. Pass it only to override.
893
+ */
894
+ resource_type?: string;
895
+ /** Streaming batch size (100–10000, default server-side). */
896
+ stream_size?: number;
897
+ /** Query timeout in seconds (1–3600). */
898
+ query_timeout?: number;
899
+ /** Cursor session id for paged streaming. */
900
+ query_id?: string;
901
+ }
793
902
  interface ListCatalogsOptions {
794
903
  limit?: number;
795
904
  offset?: number;
@@ -814,6 +923,8 @@ declare function vega(ctx: RequestContext): {
814
923
  catalogHealth: (ids: string[]) => Promise<unknown>;
815
924
  connectorTypes: () => Promise<unknown>;
816
925
  connectorType: (type: string) => Promise<unknown>;
926
+ /** Run SQL / OpenSearch DSL directly against a data source. */
927
+ sql: (body: SqlQueryRequest) => Promise<unknown>;
817
928
  /** Build a resource's index. With `wait`, polls until terminal. */
818
929
  build: (req: CreateBuildTaskRequest, opts?: {
819
930
  wait?: boolean;
@@ -848,6 +959,7 @@ interface BknClient {
848
959
  readonly toolboxes: ReturnType<typeof toolboxes>;
849
960
  readonly trace: ReturnType<typeof trace>;
850
961
  readonly admin: ReturnType<typeof admin>;
962
+ readonly appKeys: ReturnType<typeof appKeys>;
851
963
  readonly vega: ReturnType<typeof vega>;
852
964
  /** Raw API passthrough (the `call` escape hatch). */
853
965
  call(path: string, opts?: RawCallOptions): Promise<RawCallResult>;
@@ -860,7 +972,9 @@ declare class HttpError extends Error {
860
972
  readonly status: number;
861
973
  readonly statusText: string;
862
974
  readonly body: string;
863
- constructor(status: number, statusText: string, body: string);
975
+ /** Optional next-step guidance, overriding the status default (e.g. AppKey re-issue). */
976
+ readonly hint?: string;
977
+ constructor(status: number, statusText: string, body: string, hint?: string);
864
978
  }
865
979
  /** Raised for bad CLI/SDK input before any request is made. */
866
980
  declare class InputError extends Error {
@@ -889,6 +1003,8 @@ interface TokenConfig {
889
1003
  expiresAt?: string;
890
1004
  /** Skip TLS verification for this platform (saved by `auth login -k`). */
891
1005
  tlsInsecure?: boolean;
1006
+ /** Platform has no auth stack (no bkn-safe) — requests carry no token. */
1007
+ noAuth?: boolean;
892
1008
  /** Login name persisted at login time (fallback when JWT lacks claims). */
893
1009
  username?: string;
894
1010
  /** Human-readable name from userinfo. */
@@ -914,11 +1030,19 @@ declare function attachToken(baseUrl: string, accessToken: string, opts?: {
914
1030
  refreshToken?: string;
915
1031
  idToken?: string;
916
1032
  insecure?: boolean;
1033
+ username?: string;
917
1034
  }): {
918
1035
  baseUrl: string;
919
1036
  userId: string;
920
1037
  username?: string;
921
1038
  };
1039
+ /** Register a no-auth platform session (no token; the platform has no bkn-safe). */
1040
+ declare function attachNoAuth(baseUrl: string, opts?: {
1041
+ insecure?: boolean;
1042
+ }): {
1043
+ baseUrl: string;
1044
+ noAuth: true;
1045
+ };
922
1046
  interface AuthStatus {
923
1047
  baseUrl?: string;
924
1048
  userId?: string;
@@ -928,7 +1052,22 @@ interface AuthStatus {
928
1052
  }
929
1053
  declare function status(): AuthStatus;
930
1054
  declare function currentToken(): string;
931
- declare function whoami(): JwtClaims;
1055
+ /**
1056
+ * Like {@link currentToken} but proactively refreshes an expired access token
1057
+ * when a refresh token is stored, persisting the result. API requests already
1058
+ * refresh on a 401 (see api/http.ts); this covers the `auth token` getter,
1059
+ * whose output is copied out and used elsewhere where no 401 retry can help.
1060
+ */
1061
+ declare function currentTokenFresh(): Promise<string>;
1062
+ interface WhoamiResult extends JwtClaims {
1063
+ /** Platform the active session belongs to. */
1064
+ baseUrl?: string;
1065
+ /** Stored user id (UUID) for the active session. */
1066
+ userId?: string;
1067
+ /** Resolved account/login name — what `auth login` looked up and stored. */
1068
+ username?: string;
1069
+ }
1070
+ declare function whoami(): WhoamiResult;
932
1071
  interface PlatformListItem {
933
1072
  baseUrl: string;
934
1073
  userId: string;
@@ -941,10 +1080,14 @@ declare function listPlatforms(): PlatformListItem[];
941
1080
  declare function use(baseUrl: string): void;
942
1081
  declare function logout(): boolean;
943
1082
  declare function deletePlatform(baseUrl: string, userId?: string): boolean;
944
- /** Switch the active user for a platform (token must already be saved). */
945
- declare function switchUser(baseUrl: string, userId: string): {
1083
+ /**
1084
+ * Switch the active user for a platform. Accepts a stored user id OR a username
1085
+ * (the account stored at login), so callers need not know the UUID.
1086
+ */
1087
+ declare function switchUser(baseUrl: string, userOrName: string): {
946
1088
  baseUrl: string;
947
1089
  userId: string;
1090
+ username?: string;
948
1091
  };
949
1092
  /** List saved user profiles for one platform. */
950
1093
  declare function usersOf(baseUrl: string): PlatformUser[];
@@ -958,8 +1101,11 @@ declare function exportCreds(): {
958
1101
 
959
1102
  type auth_AuthStatus = AuthStatus;
960
1103
  type auth_PlatformListItem = PlatformListItem;
1104
+ type auth_WhoamiResult = WhoamiResult;
1105
+ declare const auth_attachNoAuth: typeof attachNoAuth;
961
1106
  declare const auth_attachToken: typeof attachToken;
962
1107
  declare const auth_currentToken: typeof currentToken;
1108
+ declare const auth_currentTokenFresh: typeof currentTokenFresh;
963
1109
  declare const auth_deletePlatform: typeof deletePlatform;
964
1110
  declare const auth_exportCreds: typeof exportCreds;
965
1111
  declare const auth_hostOf: typeof hostOf;
@@ -972,14 +1118,9 @@ declare const auth_userIdFromToken: typeof userIdFromToken;
972
1118
  declare const auth_usersOf: typeof usersOf;
973
1119
  declare const auth_whoami: typeof whoami;
974
1120
  declare namespace auth {
975
- export { type auth_AuthStatus as AuthStatus, type auth_PlatformListItem as PlatformListItem, auth_attachToken as attachToken, auth_currentToken as currentToken, auth_deletePlatform as deletePlatform, auth_exportCreds as exportCreds, auth_hostOf as hostOf, auth_listPlatforms as listPlatforms, auth_logout as logout, auth_status as status, auth_switchUser as switchUser, auth_use as use, auth_userIdFromToken as userIdFromToken, auth_usersOf as usersOf, auth_whoami as whoami };
1121
+ export { type auth_AuthStatus as AuthStatus, type auth_PlatformListItem as PlatformListItem, type auth_WhoamiResult as WhoamiResult, auth_attachNoAuth as attachNoAuth, auth_attachToken as attachToken, auth_currentToken as currentToken, auth_currentTokenFresh as currentTokenFresh, auth_deletePlatform as deletePlatform, auth_exportCreds as exportCreds, auth_hostOf as hostOf, auth_listPlatforms as listPlatforms, auth_logout as logout, auth_status as status, auth_switchUser as switchUser, auth_use as use, auth_userIdFromToken as userIdFromToken, auth_usersOf as usersOf, auth_whoami as whoami };
976
1122
  }
977
1123
 
978
- /**
979
- * Thin fetch wrapper: explicit timeout, auth headers, JSON in/out, typed errors.
980
- * The single choke point for every backend call — resources build on this.
981
- */
982
-
983
1124
  interface RequestInitEx {
984
1125
  method?: string;
985
1126
  /** JSON body — serialized and Content-Type set automatically. */
package/dist/index.js CHANGED
@@ -19,7 +19,7 @@ import {
19
19
  toolboxes,
20
20
  trace,
21
21
  vega
22
- } from "./chunk-ADZ23DPF.js";
22
+ } from "./chunk-SEKM54NB.js";
23
23
  export {
24
24
  DEFAULT_BUSINESS_DOMAIN,
25
25
  DEFAULT_LIST_LIMIT,
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@openbkn/bkn-sdk",
3
- "version": "0.1.1-alpha.1",
3
+ "version": "0.1.1-alpha.11",
4
4
  "description": "Unified TypeScript SDK + CLI for the BKN (Business Knowledge Network) platform.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
7
7
  "engines": {
8
- "node": ">=22"
8
+ "node": ">=18"
9
9
  },
10
10
  "bin": {
11
11
  "openbkn": "./dist/cli.js"
@@ -40,6 +40,7 @@
40
40
  },
41
41
  "dependencies": {
42
42
  "@clack/prompts": "^0.9.1",
43
+ "@openbkn/bkn-sdk": "^0.1.1-alpha.3",
43
44
  "chalk": "^5.4.1",
44
45
  "commander": "^13.1.0",
45
46
  "csv-parse": "^6.2.1",