@openbat/cli 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.
@@ -32,7 +32,7 @@ __export(api_client_exports, {
32
32
  });
33
33
  module.exports = __toCommonJS(api_client_exports);
34
34
  var import_node_url = require("url");
35
- var CLI_VERSION = "0.1.1";
35
+ var CLI_VERSION = "0.2.3";
36
36
  var KEY_REGEX = /ob_(?:live|read|admin|pat)_[0-9a-f]{32}/g;
37
37
  function redact(s) {
38
38
  return s.replace(KEY_REGEX, (k) => `${k.slice(0, 16)}\u2026<hidden>`);
@@ -82,7 +82,7 @@ var ApiClient = class {
82
82
  const msg = err instanceof Error ? err.message : String(err);
83
83
  throw new Error(`Request to ${redact(url)} failed: ${redact(msg)}`);
84
84
  }
85
- return parseResponse(res, url);
85
+ return parseResponse(res, url, "GET");
86
86
  }
87
87
  /** Issue a POST with a JSON body. */
88
88
  async post(path, body) {
@@ -144,12 +144,12 @@ mutate_fn = async function(method, path, body) {
144
144
  const msg = err instanceof Error ? err.message : String(err);
145
145
  throw new Error(`Request to ${redact(url)} failed: ${redact(msg)}`);
146
146
  }
147
- return parseResponse(res, url);
147
+ return parseResponse(res, url, method);
148
148
  };
149
- async function parseResponse(res, url) {
149
+ async function parseResponse(res, url, method) {
150
150
  if (res.status === 401) {
151
151
  throw new Error(
152
- "Unauthorized. The API key was rejected (invalid, wrong kind for this endpoint, expired, or revoked)."
152
+ "Unauthorized. The API key was rejected (invalid, wrong kind for this endpoint, expired, or revoked). Run `openbat login` to refresh credentials."
153
153
  );
154
154
  }
155
155
  if (res.status === 403) {
@@ -170,7 +170,7 @@ async function parseResponse(res, url) {
170
170
  } catch {
171
171
  }
172
172
  throw new Error(
173
- `GET ${redact(url)} \u2192 ${res.status} ${res.statusText}${errBody?.error ? `: ${redact(errBody.error)}` : ""}`
173
+ `${method} ${redact(url)} \u2192 ${res.status} ${res.statusText}${errBody?.error ? `: ${redact(errBody.error)}` : ""}`
174
174
  );
175
175
  }
176
176
  try {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  ApiClient
3
- } from "./chunk-NYKJTHHK.mjs";
3
+ } from "./chunk-HBSCN3HV.mjs";
4
4
  export {
5
5
  ApiClient
6
6
  };
@@ -9,7 +9,7 @@ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "acce
9
9
 
10
10
  // src/api-client.ts
11
11
  import { URL } from "url";
12
- var CLI_VERSION = "0.1.1";
12
+ var CLI_VERSION = "0.2.3";
13
13
  var KEY_REGEX = /ob_(?:live|read|admin|pat)_[0-9a-f]{32}/g;
14
14
  function redact(s) {
15
15
  return s.replace(KEY_REGEX, (k) => `${k.slice(0, 16)}\u2026<hidden>`);
@@ -59,7 +59,7 @@ var ApiClient = class {
59
59
  const msg = err instanceof Error ? err.message : String(err);
60
60
  throw new Error(`Request to ${redact(url)} failed: ${redact(msg)}`);
61
61
  }
62
- return parseResponse(res, url);
62
+ return parseResponse(res, url, "GET");
63
63
  }
64
64
  /** Issue a POST with a JSON body. */
65
65
  async post(path, body) {
@@ -121,12 +121,12 @@ mutate_fn = async function(method, path, body) {
121
121
  const msg = err instanceof Error ? err.message : String(err);
122
122
  throw new Error(`Request to ${redact(url)} failed: ${redact(msg)}`);
123
123
  }
124
- return parseResponse(res, url);
124
+ return parseResponse(res, url, method);
125
125
  };
126
- async function parseResponse(res, url) {
126
+ async function parseResponse(res, url, method) {
127
127
  if (res.status === 401) {
128
128
  throw new Error(
129
- "Unauthorized. The API key was rejected (invalid, wrong kind for this endpoint, expired, or revoked)."
129
+ "Unauthorized. The API key was rejected (invalid, wrong kind for this endpoint, expired, or revoked). Run `openbat login` to refresh credentials."
130
130
  );
131
131
  }
132
132
  if (res.status === 403) {
@@ -147,7 +147,7 @@ async function parseResponse(res, url) {
147
147
  } catch {
148
148
  }
149
149
  throw new Error(
150
- `GET ${redact(url)} \u2192 ${res.status} ${res.statusText}${errBody?.error ? `: ${redact(errBody.error)}` : ""}`
150
+ `${method} ${redact(url)} \u2192 ${res.status} ${res.statusText}${errBody?.error ? `: ${redact(errBody.error)}` : ""}`
151
151
  );
152
152
  }
153
153
  try {