unbound-cli 0.8.2 → 0.9.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unbound-cli",
3
- "version": "0.8.2",
3
+ "version": "0.9.1",
4
4
  "description": "CLI tool for Unbound - AI Gateway management",
5
5
  "main": "src/index.js",
6
6
  "bin": {
package/src/api.js CHANGED
@@ -104,10 +104,42 @@ function request(method, path, { body, query, apiKey, baseUrl } = {}) {
104
104
  });
105
105
  }
106
106
 
107
+ // Plain unauthenticated GET to an arbitrary URL. Returns the raw response body
108
+ // as a UTF-8 string. Callers that want JSON must do JSON.parse() themselves.
109
+ // Used by `unbound oacb` to fetch baseline JSONs and hook scripts from GitHub.
110
+ function getRaw(url) {
111
+ return new Promise((resolve, reject) => {
112
+ const parsed = new URL(url);
113
+ const transport = parsed.protocol === 'https:' ? https : http;
114
+ const req = transport.get(url, { headers: { 'User-Agent': USER_AGENT } }, (res) => {
115
+ const chunks = [];
116
+ res.on('data', (chunk) => chunks.push(chunk));
117
+ res.on('end', () => {
118
+ if (res.statusCode >= 200 && res.statusCode < 300) {
119
+ resolve(Buffer.concat(chunks).toString('utf8'));
120
+ } else {
121
+ reject(new ApiError(res.statusCode, { error: `HTTP ${res.statusCode} fetching ${url}` }));
122
+ }
123
+ });
124
+ res.on('error', (err) => {
125
+ reject(new Error(`Network error fetching ${parsed.host}: ${err.message}`));
126
+ });
127
+ });
128
+ req.setTimeout(30000, () => {
129
+ req.destroy();
130
+ reject(new Error(`Request timed out fetching ${parsed.host}`));
131
+ });
132
+ req.on('error', (err) => {
133
+ reject(new Error(`Network error fetching ${parsed.host}: ${err.message}`));
134
+ });
135
+ });
136
+ }
137
+
107
138
  module.exports = {
108
139
  ApiError,
109
140
  get: (path, opts) => request('GET', path, opts),
110
141
  post: (path, opts) => request('POST', path, opts),
111
142
  put: (path, opts) => request('PUT', path, opts),
112
143
  del: (path, opts) => request('DELETE', path, opts),
144
+ getRaw,
113
145
  };