vit 0.6.8 → 0.6.9

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": "vit",
3
- "version": "0.6.8",
3
+ "version": "0.6.9",
4
4
  "description": "Social toolkit for personalized software",
5
5
  "license": "MIT",
6
6
  "bin": {
package/src/cmd/beacon.js CHANGED
@@ -2,7 +2,7 @@
2
2
  // Copyright (c) 2026 sol pbc
3
3
 
4
4
  import git from 'isomorphic-git';
5
- import http from 'isomorphic-git/http/node';
5
+ import http from '../lib/git-http.js';
6
6
  import { memfs } from 'memfs';
7
7
  import { beaconToHttps, normalizeBeacon, tryNormalizeBeacon } from '../lib/beacon.js';
8
8
  import { mark } from '../lib/brand.js';
@@ -0,0 +1,105 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 sol pbc
3
+
4
+ const DEFAULT_TIMEOUT_MS = 15_000;
5
+
6
+ function toUint8Array(part) {
7
+ if (part instanceof Uint8Array) return part;
8
+ if (typeof part === 'string') return new TextEncoder().encode(part);
9
+ if (ArrayBuffer.isView(part)) {
10
+ return new Uint8Array(part.buffer, part.byteOffset, part.byteLength);
11
+ }
12
+ return new Uint8Array(part);
13
+ }
14
+
15
+ async function collectBody(body) {
16
+ if (!body) return undefined;
17
+ if (body instanceof Uint8Array || typeof body === 'string' || ArrayBuffer.isView(body)) {
18
+ return toUint8Array(body);
19
+ }
20
+
21
+ const chunks = [];
22
+ let total = 0;
23
+ if (typeof body[Symbol.asyncIterator] === 'function') {
24
+ for await (const part of body) {
25
+ const bytes = toUint8Array(part);
26
+ chunks.push(bytes);
27
+ total += bytes.byteLength;
28
+ }
29
+ } else if (typeof body[Symbol.iterator] === 'function') {
30
+ for (const part of body) {
31
+ const bytes = toUint8Array(part);
32
+ chunks.push(bytes);
33
+ total += bytes.byteLength;
34
+ }
35
+ } else {
36
+ return body;
37
+ }
38
+
39
+ const out = new Uint8Array(total);
40
+ let offset = 0;
41
+ for (const chunk of chunks) {
42
+ out.set(chunk, offset);
43
+ offset += chunk.byteLength;
44
+ }
45
+ return out;
46
+ }
47
+
48
+ async function* readStreamChunks(stream) {
49
+ if (!stream) return;
50
+ const reader = stream.getReader();
51
+ try {
52
+ while (true) {
53
+ const { done, value } = await reader.read();
54
+ if (done) break;
55
+ if (value) yield value;
56
+ }
57
+ } catch (err) {
58
+ if (err?.name === 'TimeoutError' || err?.name === 'AbortError') {
59
+ throw new Error('Request timed out', { cause: err });
60
+ }
61
+ throw err;
62
+ } finally {
63
+ reader.releaseLock();
64
+ }
65
+ }
66
+
67
+ export function createGitHttpClient({ fetchImpl = fetch, timeoutMs = DEFAULT_TIMEOUT_MS } = {}) {
68
+ return {
69
+ async request({ url, method = 'GET', headers = {}, body }) {
70
+ const payload = await collectBody(body);
71
+ let res;
72
+ try {
73
+ res = await fetchImpl(url, {
74
+ method,
75
+ headers,
76
+ body: payload,
77
+ redirect: 'follow',
78
+ signal: AbortSignal.timeout(timeoutMs),
79
+ });
80
+ } catch (err) {
81
+ if (err?.name === 'TimeoutError' || err?.name === 'AbortError') {
82
+ throw new Error('Request timed out', { cause: err });
83
+ }
84
+ throw err;
85
+ }
86
+
87
+ const responseHeaders = {};
88
+ for (const [key, value] of res.headers.entries()) {
89
+ responseHeaders[key.toLowerCase()] = value;
90
+ }
91
+
92
+ return {
93
+ url: res.url || url,
94
+ method,
95
+ statusCode: res.status,
96
+ statusMessage: res.statusText,
97
+ headers: responseHeaders,
98
+ body: readStreamChunks(res.body),
99
+ };
100
+ },
101
+ };
102
+ }
103
+
104
+ const gitHttp = createGitHttpClient();
105
+ export default gitHttp;