@garuhq/cli 0.4.1 → 0.4.2

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/CHANGELOG.md CHANGED
@@ -3,6 +3,32 @@
3
3
  All notable changes to `@garuhq/cli` are documented in this file. Format:
4
4
  [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). Versioning: [SemVer](https://semver.org/).
5
5
 
6
+ ## [0.4.2] — 2026-05-19
7
+
8
+ ### Fixed
9
+
10
+ - **Error codes**: HTTP 403 responses (valid key, not your resource —
11
+ e.g. retrying a webhook event that belongs to another seller) were
12
+ previously surfaced as `auth_error`, which read like "your key is
13
+ bad". They now surface as `permission_error`. `auth_error` is now
14
+ reserved for HTTP 401 (bad/missing key).
15
+ - **`garu --version`** correctly reports `0.4.2`. The `0.4.1` release
16
+ shipped with `src/version.ts:CLI_VERSION` still pinned to `'0.4.0'`
17
+ because that file was missed during the bump. A new `scripts/
18
+ check-version-sync.mjs` runs as part of `prepublishOnly` and fails
19
+ the build if `package.json:version` and `src/version.ts:CLI_VERSION`
20
+ drift apart.
21
+
22
+ ### Changed
23
+
24
+ - **Error output**: `printErrorAndExit` now includes `status` and
25
+ `body` from `GaruAPIError`-derived failures.
26
+ - In `--json` mode, the payload gains optional `status` and `body`
27
+ fields: `{"error":{"code","message","status","body"}}`. Allows
28
+ self-diagnosis of 4xx responses without dropping to `curl`.
29
+ - In pretty mode, the HTTP status is shown as a dimmed line below
30
+ the existing `code:` line.
31
+
6
32
  ## [0.4.1] — 2026-05-19
7
33
 
8
34
  ### Fixed
package/dist/index.cjs CHANGED
@@ -15,19 +15,28 @@ var pc__default = /*#__PURE__*/_interopDefault(pc);
15
15
  // src/index.ts
16
16
 
17
17
  // src/version.ts
18
- var CLI_VERSION = "0.4.0";
18
+ var CLI_VERSION = "0.4.2";
19
19
  var CliError = class extends Error {
20
20
  code;
21
21
  exitCode;
22
- constructor(code, message, exitCode = 1) {
22
+ /** HTTP status code when the error came from a `GaruAPIError`, else `null`. */
23
+ status;
24
+ /** Raw backend response body when the error came from a `GaruAPIError`, else `undefined`. */
25
+ body;
26
+ constructor(code, message, exitCode = 1, status = null, body = void 0) {
23
27
  super(message);
24
28
  this.name = "CliError";
25
29
  this.code = code;
26
30
  this.exitCode = exitCode;
31
+ this.status = status;
32
+ this.body = body;
27
33
  }
28
34
  };
29
35
  function toCliError(err) {
30
36
  if (err instanceof CliError) return err;
37
+ if (err instanceof node.GaruAPIError) {
38
+ return new CliError(mapSdkCodeToCliCode(err.code), err.message, 1, err.status, err.body);
39
+ }
31
40
  if (err instanceof node.GaruError) {
32
41
  return new CliError(mapSdkCodeToCliCode(err.code), err.message, 1);
33
42
  }
@@ -37,8 +46,9 @@ function toCliError(err) {
37
46
  function mapSdkCodeToCliCode(sdkCode) {
38
47
  switch (sdkCode) {
39
48
  case "authentication_error":
40
- case "permission_error":
41
49
  return "auth_error";
50
+ case "permission_error":
51
+ return "permission_error";
42
52
  case "not_found":
43
53
  return "not_found";
44
54
  case "validation_error":
@@ -154,6 +164,8 @@ function printSuccess(message, opts = {}) {
154
164
  function printErrorAndExit(err, opts = {}) {
155
165
  const cliErr = toCliError(err);
156
166
  const payload = { error: { code: cliErr.code, message: cliErr.message } };
167
+ if (cliErr.status !== null) payload.error.status = cliErr.status;
168
+ if (cliErr.body !== void 0) payload.error.body = cliErr.body;
157
169
  if (resolveMode(opts) === "json") {
158
170
  process.stdout.write(`${JSON.stringify(payload)}
159
171
  `);
@@ -162,6 +174,10 @@ function printErrorAndExit(err, opts = {}) {
162
174
  `);
163
175
  if (cliErr.code !== "unknown_error") {
164
176
  process.stderr.write(`${pc__default.default.dim(` code: ${cliErr.code}`)}
177
+ `);
178
+ }
179
+ if (cliErr.status !== null) {
180
+ process.stderr.write(`${pc__default.default.dim(` status: ${cliErr.status}`)}
165
181
  `);
166
182
  }
167
183
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@garuhq/cli",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "Official command-line interface for the Garu payment gateway.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://garu.com.br",
@@ -42,7 +42,8 @@
42
42
  "typecheck": "tsc --noEmit",
43
43
  "test": "vitest run",
44
44
  "test:watch": "vitest",
45
- "prepublishOnly": "npm run typecheck && npm test && npm run build"
45
+ "check:version-sync": "node scripts/check-version-sync.mjs",
46
+ "prepublishOnly": "npm run check:version-sync && npm run typecheck && npm test && npm run build"
46
47
  },
47
48
  "dependencies": {
48
49
  "@garuhq/node": "0.11.1",