@openbkn/bkn-sdk 0.1.1-alpha.10 → 0.1.1-alpha.12

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.
@@ -9,12 +9,15 @@ var HttpError = class extends Error {
9
9
  status;
10
10
  statusText;
11
11
  body;
12
- constructor(status2, statusText, body) {
12
+ /** Optional next-step guidance, overriding the status default (e.g. AppKey re-issue). */
13
+ hint;
14
+ constructor(status2, statusText, body, hint) {
13
15
  super(`HTTP ${status2} ${statusText}`);
14
16
  this.name = "HttpError";
15
17
  this.status = status2;
16
18
  this.statusText = statusText;
17
19
  this.body = body;
20
+ this.hint = hint;
18
21
  }
19
22
  };
20
23
  var InputError = class extends Error {
@@ -35,7 +38,8 @@ function formatError(err) {
35
38
  if (err instanceof HttpError) {
36
39
  const serverMsg = serverError(err.body);
37
40
  if (err.status === 401) {
38
- return `Not authorized (HTTP 401)${serverMsg ? `: ${serverMsg}` : ""}. Run \`openbkn auth login\` and retry.`;
41
+ const next = err.hint ?? "Run `openbkn auth login` and retry.";
42
+ return `Not authorized (HTTP 401)${serverMsg ? `: ${serverMsg}` : ""}. ${next}`;
39
43
  }
40
44
  if (err.status === 403) {
41
45
  return `Forbidden (HTTP 403)${serverMsg ? `: ${serverMsg}` : " \u2014 admin privileges required"}.`;
@@ -313,12 +317,18 @@ async function request(ctx, path, init = {}) {
313
317
  res = await send();
314
318
  }
315
319
  const text = await res.text();
316
- if (!res.ok) throw new HttpError(res.status, res.statusText, text);
320
+ if (!res.ok) throw new HttpError(res.status, res.statusText, text, hintFor(ctx, res.status));
317
321
  return text ? JSON.parse(text) : void 0;
318
322
  } finally {
319
323
  clearTimeout(timer);
320
324
  }
321
325
  }
326
+ function hintFor(ctx, status2) {
327
+ if (status2 === 401 && ctx.token.startsWith("bak_")) {
328
+ return "AppKey invalid / expired / revoked / owner disabled \u2014 re-issue with `openbkn appkey create` (or `appkey regenerate <id>`). Do not auto-retry.";
329
+ }
330
+ return void 0;
331
+ }
322
332
  async function tryRefresh(ctx) {
323
333
  if (!ctx.refresh) return false;
324
334
  try {
@@ -2886,6 +2896,9 @@ async function getBuildTask(ctx, taskId) {
2886
2896
  const res = await request(ctx, `${VEGA_BASE}/build-tasks/${encodeURIComponent(taskId)}`);
2887
2897
  return BuildTask.parse(res);
2888
2898
  }
2899
+ function runSql(ctx, body) {
2900
+ return request(ctx, `${VEGA_BASE}/resources/query`, { method: "POST", body });
2901
+ }
2889
2902
  async function listCatalogs(ctx, opts = {}) {
2890
2903
  return request(ctx, `${VEGA_BASE}/catalogs`, {
2891
2904
  query: { limit: opts.limit, offset: opts.offset }
@@ -4929,6 +4942,8 @@ function vega(ctx) {
4929
4942
  catalogHealth: (ids) => catalogHealthStatus(ctx, ids),
4930
4943
  connectorTypes: () => listConnectorTypes(ctx),
4931
4944
  connectorType: (type) => getConnectorType(ctx, type),
4945
+ /** Run SQL / OpenSearch DSL directly against a data source. */
4946
+ sql: (body) => runSql(ctx, body),
4932
4947
  /** Build a resource's index. With `wait`, polls until terminal. */
4933
4948
  build: async (req, opts = {}) => {
4934
4949
  const task = await createBuildTask(ctx, req);
@@ -5008,6 +5023,53 @@ async function rawCall(ctx, path, opts = {}) {
5008
5023
  }
5009
5024
  }
5010
5025
 
5026
+ // src/api/app-keys.ts
5027
+ var ME = "/api/safe/v1/me/api-keys";
5028
+ var ADMIN2 = "/api/safe/v1/admin/api-keys";
5029
+ function listMyApiKeys(ctx) {
5030
+ return request(ctx, ME);
5031
+ }
5032
+ function createMyApiKey(ctx, input) {
5033
+ return request(ctx, ME, {
5034
+ method: "POST",
5035
+ body: {
5036
+ name: input.name,
5037
+ ...input.expiresAt ? { expires_at: input.expiresAt } : {},
5038
+ ...input.neverExpire ? { never_expire: true } : {}
5039
+ }
5040
+ });
5041
+ }
5042
+ async function revokeMyApiKey(ctx, id) {
5043
+ await request(ctx, `${ME}/${encodeURIComponent(id)}`, { method: "DELETE" });
5044
+ }
5045
+ function regenerateMyApiKey(ctx, id) {
5046
+ return request(ctx, `${ME}/${encodeURIComponent(id)}/regenerate`, { method: "POST" });
5047
+ }
5048
+ function listApiKeysAdmin(ctx, ownerId) {
5049
+ return request(ctx, ADMIN2, { query: { owner_id: ownerId || void 0 } });
5050
+ }
5051
+ async function revokeApiKeyAdmin(ctx, id) {
5052
+ await request(ctx, `${ADMIN2}/${encodeURIComponent(id)}`, { method: "DELETE" });
5053
+ }
5054
+
5055
+ // src/resources/app-keys.ts
5056
+ function appKeys(ctx) {
5057
+ return {
5058
+ /** List the caller's own keys (no secrets). */
5059
+ list: () => listMyApiKeys(ctx),
5060
+ /** Issue a key — the result's `key` is the plaintext, shown only once. */
5061
+ create: (input) => createMyApiKey(ctx, input),
5062
+ /** Revoke one of the caller's keys (immediate). */
5063
+ revoke: (id) => revokeMyApiKey(ctx, id),
5064
+ /** Rotate a key in place — new plaintext (shown once); old secret dies now. */
5065
+ regenerate: (id) => regenerateMyApiKey(ctx, id),
5066
+ /** Admin: list all keys, or one owner's (adds `owner_user_id`). */
5067
+ adminList: (ownerId) => listApiKeysAdmin(ctx, ownerId),
5068
+ /** Admin: revoke any key. */
5069
+ adminRevoke: (id) => revokeApiKeyAdmin(ctx, id)
5070
+ };
5071
+ }
5072
+
5011
5073
  // src/client.ts
5012
5074
  function createClient(opts = {}) {
5013
5075
  const ctx = resolveContext(opts);
@@ -5023,6 +5085,7 @@ function createClient(opts = {}) {
5023
5085
  toolboxes: toolboxes(ctx),
5024
5086
  trace: trace(ctx),
5025
5087
  admin: admin(ctx),
5088
+ appKeys: appKeys(ctx),
5026
5089
  vega: vega(ctx),
5027
5090
  call: (path, callOpts) => rawCall(ctx, path, callOpts)
5028
5091
  };
@@ -5245,4 +5308,4 @@ export {
5245
5308
  exportCreds,
5246
5309
  auth_exports
5247
5310
  };
5248
- //# sourceMappingURL=chunk-GNL6Z5VF.js.map
5311
+ //# sourceMappingURL=chunk-3FVB6VFQ.js.map