@agenticcli/shipguard 0.4.0 → 0.4.1

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.
@@ -1,7 +1,7 @@
1
1
  {
2
- "secrets": "cf2f74188b62c5b15dff3e9b16f768503e51e1a7584a9a63bfc35d884cf04180",
3
- "auth": "cf2f74188b62c5b15dff3e9b16f768503e51e1a7584a9a63bfc35d884cf04180",
4
- "database": "cf2f74188b62c5b15dff3e9b16f768503e51e1a7584a9a63bfc35d884cf04180",
5
- "deployment": "cf2f74188b62c5b15dff3e9b16f768503e51e1a7584a9a63bfc35d884cf04180",
6
- "payments": "cf2f74188b62c5b15dff3e9b16f768503e51e1a7584a9a63bfc35d884cf04180"
2
+ "secrets": "d1e2738188921adf423972a736eda2df1d0ad92eae0b376ced4ec7bea6b8f3e8",
3
+ "auth": "d1e2738188921adf423972a736eda2df1d0ad92eae0b376ced4ec7bea6b8f3e8",
4
+ "database": "d1e2738188921adf423972a736eda2df1d0ad92eae0b376ced4ec7bea6b8f3e8",
5
+ "deployment": "d1e2738188921adf423972a736eda2df1d0ad92eae0b376ced4ec7bea6b8f3e8",
6
+ "payments": "d1e2738188921adf423972a736eda2df1d0ad92eae0b376ced4ec7bea6b8f3e8"
7
7
  }
@@ -101,8 +101,69 @@ function clearCredentials() {
101
101
  function isTokenExpired(creds) {
102
102
  return creds.expiresAt < Date.now();
103
103
  }
104
- async function getAuthToken() {
105
- if (process.env.SHIPGUARD_API_KEY) return process.env.SHIPGUARD_API_KEY;
104
+ var DEFAULT_API_URL = "https://agenticcli.dev";
105
+ var cachedExchangedToken = null;
106
+ async function exchangeApiKeyForToken(apiKey, apiUrl) {
107
+ assertTrustedApiUrl(apiUrl);
108
+ let res;
109
+ try {
110
+ res = await fetch(`${apiUrl}/api/agent/exchange`, {
111
+ method: "POST",
112
+ headers: { Authorization: `Bearer ${apiKey}` }
113
+ });
114
+ } catch (err) {
115
+ const msg = err instanceof Error ? err.message : String(err);
116
+ console.error(`[shipguard] SHIPGUARD_API_KEY exchange request to ${apiUrl} failed: ${msg}`);
117
+ throw new Error(
118
+ `Could not reach ${apiUrl}/api/agent/exchange to exchange SHIPGUARD_API_KEY: ${msg}`
119
+ );
120
+ }
121
+ if (res.status === 401) {
122
+ console.error("[shipguard] SHIPGUARD_API_KEY exchange rejected \u2014 invalid or revoked key");
123
+ throw new Error(
124
+ "SHIPGUARD_API_KEY is invalid or has been revoked. Check the key value or generate a new one at https://agenticcli.dev/dashboard."
125
+ );
126
+ }
127
+ if (res.status === 402) {
128
+ console.error("[shipguard] SHIPGUARD_API_KEY exchange rejected \u2014 monthly budget exhausted");
129
+ throw new Error(
130
+ "SHIPGUARD_API_KEY has exhausted its monthly credit budget. Buy more at https://agenticcli.dev/dashboard/billing"
131
+ );
132
+ }
133
+ if (!res.ok) {
134
+ let detail = res.statusText;
135
+ try {
136
+ const body2 = await res.json();
137
+ detail = body2?.error_description ?? body2?.error ?? detail;
138
+ } catch {
139
+ }
140
+ console.error(`[shipguard] SHIPGUARD_API_KEY exchange failed (${res.status}): ${detail}`);
141
+ throw new Error(`SHIPGUARD_API_KEY exchange failed (${res.status}): ${detail}`);
142
+ }
143
+ const body = await res.json();
144
+ if (!body.access_token) {
145
+ console.error("[shipguard] SHIPGUARD_API_KEY exchange returned 200 with no access_token");
146
+ throw new Error("SHIPGUARD_API_KEY exchange succeeded but the server returned no access_token.");
147
+ }
148
+ cachedExchangedToken = {
149
+ apiKey,
150
+ apiUrl,
151
+ accessToken: body.access_token,
152
+ // Refresh 30s ahead of actual expiry so a long-running scan never races a
153
+ // mid-request expiry against the server's 15-minute access-token TTL.
154
+ expiresAt: Date.now() + (body.expires_in ?? 900) * 1e3 - 3e4
155
+ };
156
+ return body.access_token;
157
+ }
158
+ async function getAuthToken(apiUrl) {
159
+ const apiKey = process.env.SHIPGUARD_API_KEY;
160
+ if (apiKey) {
161
+ const targetApiUrl = apiUrl ?? loadCredentials()?.apiUrl ?? DEFAULT_API_URL;
162
+ if (cachedExchangedToken && cachedExchangedToken.apiKey === apiKey && cachedExchangedToken.apiUrl === targetApiUrl && Date.now() < cachedExchangedToken.expiresAt) {
163
+ return cachedExchangedToken.accessToken;
164
+ }
165
+ return exchangeApiKeyForToken(apiKey, targetApiUrl);
166
+ }
106
167
  const creds = loadCredentials();
107
168
  if (!creds) return null;
108
169
  if (!isTokenExpired(creds)) return creds.accessToken;
@@ -2818,7 +2879,7 @@ var NoRulesAppliedError = class extends Error {
2818
2879
  };
2819
2880
  async function fetchProRules(frameworks, categories, apiUrl, scanId, floorPath) {
2820
2881
  assertTrustedApiUrl(apiUrl);
2821
- const token = await getAuthToken();
2882
+ const token = await getAuthToken(apiUrl);
2822
2883
  if (!token) throw new Error("Not authenticated. Run `shipguard login` first.");
2823
2884
  const res = await fetch(`${apiUrl}/api/rules/fetch`, {
2824
2885
  method: "POST",
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.4.0",
2
+ "version": "0.4.1",
3
3
  "packageName": "@agenticcli/shipguard",
4
4
  "nodeEngine": ">=20",
5
5
  "exitCodes": {
@@ -97,5 +97,5 @@
97
97
  ],
98
98
  "installSnippet": "npx @agenticcli/shipguard scan --changed --strict --json",
99
99
  "re2Engine": true,
100
- "generatedAt": "2026-06-25T23:16:56.961Z"
100
+ "generatedAt": "2026-07-06T13:46:08.246Z"
101
101
  }
package/dist/cli.js CHANGED
@@ -14,7 +14,7 @@ import {
14
14
  runProRulesWithDispatch,
15
15
  saveCredentials,
16
16
  secretsCheck
17
- } from "./chunk-XOWMKGOE.js";
17
+ } from "./chunk-5UMQEPDN.js";
18
18
  import {
19
19
  DEFAULT_MAX_FILES,
20
20
  DEFAULT_MAX_FILE_SIZE_BYTES,
@@ -1176,7 +1176,7 @@ function sendTelemetry(payload) {
1176
1176
 
1177
1177
  // src/commands/scan.ts
1178
1178
  var LEARN_MORE = "Docs https://agenticcli.dev/docs \xB7 Site https://agenticcli.dev \xB7 Pricing https://agenticcli.dev/pricing \xB7 Issues https://github.com/agenticcli/shipguard/issues";
1179
- var CLI_VERSION = true ? "0.4.0" : process.env.npm_package_version ?? "0.0.0-dev";
1179
+ var CLI_VERSION = true ? "0.4.1" : process.env.npm_package_version ?? "0.0.0-dev";
1180
1180
  function resolveExitCode(opts) {
1181
1181
  if (opts.strict && opts.blockingCount > 0) {
1182
1182
  return EXIT_CODES.BLOCKED;
@@ -1283,7 +1283,7 @@ async function runScan(ctx) {
1283
1283
  }
1284
1284
  try {
1285
1285
  const { detectFrameworks } = await import("./framework-PA6RVE7G.js");
1286
- const { fetchProRules } = await import("./pro-scanner-ENFCTA4R.js");
1286
+ const { fetchProRules } = await import("./pro-scanner-HI5OGQYR.js");
1287
1287
  const { hasConfig, generateConfig } = await import("./config-generator-RMWNQQHW.js");
1288
1288
  const detectedResult = detectFrameworks(cwd);
1289
1289
  const { frameworks } = detectedResult;
@@ -1627,9 +1627,16 @@ function statusCommand() {
1627
1627
  import { Command as Command6 } from "commander";
1628
1628
  function feedbackCommand() {
1629
1629
  return new Command6("feedback").description("Send feedback about your last scan").argument("<text>", "Your feedback text").action(async (text) => {
1630
- const token = await getAuthToken();
1631
- if (!token) {
1632
- logger.error("Not authenticated. Run `shipguard login` first.");
1630
+ let token;
1631
+ try {
1632
+ const t = await getAuthToken();
1633
+ if (!t) {
1634
+ logger.error("Not authenticated. Run `shipguard login` first.");
1635
+ return;
1636
+ }
1637
+ token = t;
1638
+ } catch (err) {
1639
+ logger.error(`Authentication failed: ${err instanceof Error ? err.message : String(err)}`);
1633
1640
  return;
1634
1641
  }
1635
1642
  const creds = loadCredentials();
@@ -1669,9 +1676,16 @@ function rateCommand() {
1669
1676
  logger.error('Rating must be "helpful" or "not-helpful".');
1670
1677
  return;
1671
1678
  }
1672
- const token = await getAuthToken();
1673
- if (!token) {
1674
- logger.error("Not authenticated. Run `shipguard login` first.");
1679
+ let token;
1680
+ try {
1681
+ const t = await getAuthToken();
1682
+ if (!t) {
1683
+ logger.error("Not authenticated. Run `shipguard login` first.");
1684
+ return;
1685
+ }
1686
+ token = t;
1687
+ } catch (err) {
1688
+ logger.error(`Authentication failed: ${err instanceof Error ? err.message : String(err)}`);
1675
1689
  return;
1676
1690
  }
1677
1691
  const creds = loadCredentials();
@@ -1742,7 +1756,7 @@ if (rawArgs[0] === "?") {
1742
1756
  process.argv = [process.argv[0], process.argv[1], "help"];
1743
1757
  }
1744
1758
  program.name("shipguard").description("CLI-first release gate for AI-built apps").version(
1745
- true ? "0.4.0" : process.env.npm_package_version ?? "0.0.0-dev"
1759
+ true ? "0.4.1" : process.env.npm_package_version ?? "0.0.0-dev"
1746
1760
  ).helpCommand(false).addHelpText("after", `
1747
1761
  Learn more:
1748
1762
  Docs https://agenticcli.dev/docs
@@ -5,7 +5,7 @@ import {
5
5
  runProRules,
6
6
  runProRulesWithDispatch,
7
7
  validateBundleCompile
8
- } from "./chunk-XOWMKGOE.js";
8
+ } from "./chunk-5UMQEPDN.js";
9
9
  import "./chunk-ANTCYKRO.js";
10
10
  export {
11
11
  NoRulesAppliedError,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agenticcli/shipguard",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "CLI-first release gate for AI-built apps",
5
5
  "type": "module",
6
6
  "main": "./dist/cli.js",
@@ -13,6 +13,15 @@
13
13
  "docs",
14
14
  "README.md"
15
15
  ],
16
+ "scripts": {
17
+ "build": "tsup",
18
+ "dev": "tsup --watch",
19
+ "lint": "eslint src --ext .ts",
20
+ "prepublishOnly": "bash \"$(git rev-parse --show-toplevel)/scripts/release-gate.sh\"",
21
+ "test": "vitest run",
22
+ "test:watch": "vitest",
23
+ "clean": "rm -rf dist"
24
+ },
16
25
  "dependencies": {
17
26
  "@noble/hashes": "^2.2.0",
18
27
  "chalk": "^5.4.0",
@@ -24,15 +33,15 @@
24
33
  "yaml": "^2.7.0"
25
34
  },
26
35
  "devDependencies": {
36
+ "@agenticcli/matcher-contract": "workspace:*",
37
+ "@agenticcli/shared": "workspace:*",
27
38
  "@types/node": "^22.0.0",
28
39
  "@typescript-eslint/eslint-plugin": "^7",
29
40
  "@typescript-eslint/parser": "^7",
30
41
  "eslint": "^8",
31
42
  "tsup": "^8.5.1",
32
43
  "typescript": "^5.8.0",
33
- "vitest": "^3.2.0",
34
- "@agenticcli/matcher-contract": "0.5.0",
35
- "@agenticcli/shared": "0.1.0"
44
+ "vitest": "^3.2.0"
36
45
  },
37
46
  "keywords": [
38
47
  "shipguard",
@@ -65,13 +74,5 @@
65
74
  },
66
75
  "publishConfig": {
67
76
  "access": "public"
68
- },
69
- "scripts": {
70
- "build": "tsup",
71
- "dev": "tsup --watch",
72
- "lint": "eslint src --ext .ts",
73
- "test": "vitest run",
74
- "test:watch": "vitest",
75
- "clean": "rm -rf dist"
76
77
  }
77
- }
78
+ }