@knolo/cli 5.2.1 → 5.2.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.
@@ -1,53 +1,57 @@
1
- import { RegistryError, RegistryNetworkError, registryErrorMessage } from './errors.mjs';
1
+ import {
2
+ RegistryError,
3
+ RegistryNetworkError,
4
+ registryErrorMessage,
5
+ } from './errors.mjs';
2
6
 
3
- export async function getJson(url, { fetchImpl = globalThis.fetch, headers = {} } = {}) {
7
+ export async function getJson(
8
+ url,
9
+ { fetchImpl = globalThis.fetch, headers = {} } = {}
10
+ ) {
4
11
  return requestJson(url, { fetchImpl, headers, method: 'GET' });
5
12
  }
6
13
 
7
- export async function postJson(url, body, { fetchImpl = globalThis.fetch, headers = {} } = {}) {
14
+ export async function postJson(
15
+ url,
16
+ body,
17
+ { fetchImpl = globalThis.fetch, headers = {} } = {}
18
+ ) {
8
19
  return requestJson(url, { fetchImpl, headers, method: 'POST', body });
9
20
  }
10
21
 
11
- export async function putBytes(url, bytes, { fetchImpl = globalThis.fetch, headers = {} } = {}) {
12
- if (typeof fetchImpl !== 'function') throw new Error('This Node runtime does not provide fetch.');
13
-
14
- let response;
15
- try {
16
- response = await fetchImpl(url, {
17
- method: 'PUT',
18
- redirect: 'follow',
19
- headers: { 'content-type': 'application/octet-stream', ...headers },
20
- body: bytes,
21
- });
22
- } catch (error) {
23
- throw new RegistryNetworkError(`Could not upload artifact to ${new URL(url).origin}.`, { url: String(url), cause: error });
24
- }
25
-
26
- if (!response.ok) {
27
- const detail = await readResponseText(response, url);
28
- throw new RegistryError(`Blob upload failed with HTTP ${response.status}${detail ? `: ${detail}` : '.'}`, {
29
- status: response.status,
30
- url: String(url),
31
- body: detail,
32
- });
33
- }
34
-
35
- return { status: response.status, url: response.url || String(url) };
36
- }
37
-
38
- async function requestJson(url, { fetchImpl = globalThis.fetch, headers = {}, method = 'GET', body: requestBody } = {}) {
39
- if (typeof fetchImpl !== 'function') throw new Error('This Node runtime does not provide fetch.');
22
+ async function requestJson(
23
+ url,
24
+ {
25
+ fetchImpl = globalThis.fetch,
26
+ headers = {},
27
+ method = 'GET',
28
+ body: requestBody,
29
+ } = {}
30
+ ) {
31
+ if (typeof fetchImpl !== 'function')
32
+ throw new Error('This Node runtime does not provide fetch.');
40
33
 
41
34
  let response;
42
35
  try {
43
36
  response = await fetchImpl(url, {
44
37
  method,
45
38
  redirect: 'follow',
46
- headers: { accept: 'application/json', ...(requestBody !== undefined ? { 'content-type': 'application/json' } : {}), ...headers },
47
- ...(requestBody !== undefined ? { body: JSON.stringify(requestBody) } : {}),
39
+ headers: {
40
+ accept: 'application/json',
41
+ ...(requestBody !== undefined
42
+ ? { 'content-type': 'application/json' }
43
+ : {}),
44
+ ...headers,
45
+ },
46
+ ...(requestBody !== undefined
47
+ ? { body: JSON.stringify(requestBody) }
48
+ : {}),
48
49
  });
49
50
  } catch (error) {
50
- throw new RegistryNetworkError(`Could not reach registry at ${new URL(url).origin}.`, { url: String(url), cause: error });
51
+ throw new RegistryNetworkError(
52
+ `Could not reach registry at ${new URL(url).origin}.`,
53
+ { url: String(url), cause: error }
54
+ );
51
55
  }
52
56
 
53
57
  const text = await readResponseText(response, url);
@@ -57,11 +61,14 @@ async function requestJson(url, { fetchImpl = globalThis.fetch, headers = {}, me
57
61
  body = JSON.parse(text);
58
62
  } catch {
59
63
  if (!response.ok) {
60
- throw new RegistryError(`Registry returned HTTP ${response.status} with a non-JSON response.`, {
61
- status: response.status,
62
- url: String(url),
63
- body: text.slice(0, 240),
64
- });
64
+ throw new RegistryError(
65
+ `Registry returned HTTP ${response.status} with a non-JSON response.`,
66
+ {
67
+ status: response.status,
68
+ url: String(url),
69
+ body: text.slice(0, 240),
70
+ }
71
+ );
65
72
  }
66
73
  throw new RegistryError('Registry returned invalid JSON.', {
67
74
  status: response.status,
@@ -74,12 +81,20 @@ async function requestJson(url, { fetchImpl = globalThis.fetch, headers = {}, me
74
81
 
75
82
  if (!response.ok) {
76
83
  const code = typeof body?.code === 'string' ? body.code : undefined;
77
- throw new RegistryError(registryErrorMessage({ status: response.status, code, body, url: String(url) }), {
78
- status: response.status,
79
- code,
80
- url: String(url),
81
- body,
82
- });
84
+ throw new RegistryError(
85
+ registryErrorMessage({
86
+ status: response.status,
87
+ code,
88
+ body,
89
+ url: String(url),
90
+ }),
91
+ {
92
+ status: response.status,
93
+ code,
94
+ url: String(url),
95
+ body,
96
+ }
97
+ );
83
98
  }
84
99
 
85
100
  return body;
@@ -89,6 +104,9 @@ async function readResponseText(response, url) {
89
104
  try {
90
105
  return await response.text();
91
106
  } catch (error) {
92
- throw new RegistryNetworkError(`Could not read registry response from ${new URL(url).origin}.`, { url: String(url), cause: error });
107
+ throw new RegistryNetworkError(
108
+ `Could not read registry response from ${new URL(url).origin}.`,
109
+ { url: String(url), cause: error }
110
+ );
93
111
  }
94
112
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knolo/cli",
3
- "version": "5.2.1",
3
+ "version": "5.2.2",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "knolo": "bin/knolo.mjs"
@@ -32,7 +32,8 @@
32
32
  "test:hub": "node --test test/hub.integration.test.mjs"
33
33
  },
34
34
  "dependencies": {
35
- "@knolo/core": "^5.1.0"
35
+ "@knolo/core": "^5.1.0",
36
+ "@vercel/blob": "2.8.0"
36
37
  },
37
38
  "private": false
38
39
  }