herdr-remote 0.2.39 → 0.3.31

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.
Files changed (203) hide show
  1. package/dist/chunks/353DMT35.js +3 -0
  2. package/dist/chunks/42KARAL4.js +31 -0
  3. package/dist/chunks/7AUQHB3O.js +10 -0
  4. package/dist/chunks/7SMZ43LI.js +9 -0
  5. package/dist/chunks/AM3OEMFK.js +16 -0
  6. package/dist/chunks/ANNJESOL.js +10 -0
  7. package/dist/chunks/AWB4A65P.js +63 -0
  8. package/dist/chunks/C2UUZY6J.js +2 -0
  9. package/dist/chunks/DGUZCGQN.js +3 -0
  10. package/dist/chunks/H24ZP5D5.js +16 -0
  11. package/dist/chunks/I6NRCYLI.js +3 -0
  12. package/dist/chunks/JJGEV4EZ.js +3 -0
  13. package/dist/chunks/KRSURB5L.js +5 -0
  14. package/dist/chunks/KRVF37OW.js +3 -0
  15. package/dist/chunks/KUDCC7ZO.js +6 -0
  16. package/dist/chunks/M3NRPJK2.js +77 -0
  17. package/dist/chunks/M4AFZHKH.js +3 -0
  18. package/dist/chunks/M52LJEES.js +6 -0
  19. package/dist/chunks/O2LNVFUT.js +3 -0
  20. package/dist/chunks/OJPBI7KB.js +3 -0
  21. package/dist/chunks/OMN6C7J6.js +3 -0
  22. package/dist/chunks/PBMBFWLQ.js +3 -0
  23. package/dist/chunks/PBRQ3HEG.js +3 -0
  24. package/dist/chunks/PFFVGFPL.js +45 -0
  25. package/dist/chunks/QRGNEKME.js +5 -0
  26. package/dist/chunks/TNLCNVA2.js +3 -0
  27. package/dist/chunks/U27JJKJ6.js +3 -0
  28. package/dist/chunks/U6QAYG3E.js +3 -0
  29. package/dist/chunks/UEOQE77N.js +4 -0
  30. package/dist/chunks/WSACSE45.js +4 -0
  31. package/dist/chunks/WY7WHEJ4.js +3 -0
  32. package/dist/chunks/XJKWLK43.js +4 -0
  33. package/dist/chunks/XN6D5S55.js +3 -0
  34. package/dist/chunks/YD3MIP7B.js +5 -0
  35. package/dist/chunks/YXDQ62BB.js +4 -0
  36. package/dist/cli.js +21 -294
  37. package/dist/connector/admin-broker.js +3 -303
  38. package/dist/connector/main.js +20 -18
  39. package/dist/harfbuzz-subset.wasm +0 -0
  40. package/dist/postinstall.js +17 -0
  41. package/herdr-plugin.toml +1 -1
  42. package/node_modules/herdr-remote-relay/bin/herdr-remote-relay.js +33 -92
  43. package/node_modules/herdr-remote-relay/package.json +3 -46
  44. package/package.json +8 -27
  45. package/dist/agent-status.js +0 -130
  46. package/dist/binary-plist.js +0 -157
  47. package/dist/config.js +0 -278
  48. package/dist/connector/admin-broker-setup.js +0 -40
  49. package/dist/connector/admin-shell.js +0 -67
  50. package/dist/connector/admin-tab.js +0 -90
  51. package/dist/connector/adminBrokerEndpoint.js +0 -68
  52. package/dist/connector/agent-watch.js +0 -123
  53. package/dist/connector/elevatedPty.js +0 -141
  54. package/dist/connector/font-server.js +0 -165
  55. package/dist/connector/herdr-prefix-keys.js +0 -28
  56. package/dist/connector/host-connector.js +0 -433
  57. package/dist/connector/host-hello.js +0 -32
  58. package/dist/connector/lock.js +0 -73
  59. package/dist/connector/sessions.js +0 -381
  60. package/dist/connector/update-report.js +0 -70
  61. package/dist/connector/wire.js +0 -42
  62. package/dist/exit-codes.js +0 -13
  63. package/dist/font-subset.js +0 -116
  64. package/dist/herdr-api.js +0 -254
  65. package/dist/herdr-command.js +0 -245
  66. package/dist/herdr-plugin.js +0 -120
  67. package/dist/herdr-server.js +0 -190
  68. package/dist/i18n/en.js +0 -257
  69. package/dist/i18n/index.js +0 -48
  70. package/dist/i18n/zh.js +0 -256
  71. package/dist/keepalive/detached.js +0 -97
  72. package/dist/keepalive/environment.js +0 -44
  73. package/dist/keepalive/index.js +0 -129
  74. package/dist/keepalive/launchd.js +0 -117
  75. package/dist/keepalive/systemd.js +0 -112
  76. package/dist/keepalive/types.js +0 -1
  77. package/dist/keepalive/windows-service-setup.js +0 -138
  78. package/dist/keepalive/windows-service.js +0 -272
  79. package/dist/keepalive/windows-task.js +0 -191
  80. package/dist/lib/process.js +0 -132
  81. package/dist/lifecycle.js +0 -79
  82. package/dist/net-interfaces.js +0 -82
  83. package/dist/node-pty-loader.js +0 -80
  84. package/dist/pasted-files.js +0 -115
  85. package/dist/paths.js +0 -74
  86. package/dist/pty-session.js +0 -133
  87. package/dist/relay-client.js +0 -106
  88. package/dist/relay-urls.js +0 -99
  89. package/dist/runtime.js +0 -107
  90. package/dist/service.js +0 -267
  91. package/dist/settings-model.js +0 -298
  92. package/dist/socket-discovery.js +0 -70
  93. package/dist/supervisor.js +0 -323
  94. package/dist/terminal-font/deps.js +0 -83
  95. package/dist/terminal-font/files.js +0 -357
  96. package/dist/terminal-font/formats.js +0 -355
  97. package/dist/terminal-font/index.js +0 -187
  98. package/dist/terminal-font/readers.js +0 -373
  99. package/dist/terminal-font/terminals.js +0 -147
  100. package/dist/terminal-palette.js +0 -399
  101. package/dist/tui/App.js +0 -199
  102. package/dist/tui/api.js +0 -91
  103. package/dist/tui/components/TextField.js +0 -50
  104. package/dist/tui/components/common.js +0 -80
  105. package/dist/tui/index.js +0 -36
  106. package/dist/tui/mouse/index.js +0 -164
  107. package/dist/tui/mouse/protocol.js +0 -96
  108. package/dist/tui/mouse/source.js +0 -79
  109. package/dist/tui/screens/About.js +0 -172
  110. package/dist/tui/screens/Herdr.js +0 -75
  111. package/dist/tui/screens/Keepalive.js +0 -141
  112. package/dist/tui/screens/Overview.js +0 -36
  113. package/dist/tui/screens/Pair.js +0 -74
  114. package/dist/tui/screens/Relay.js +0 -243
  115. package/dist/tui/screens/Services.js +0 -63
  116. package/dist/tui/screens/Wizard.js +0 -241
  117. package/dist/tui/terminal.js +0 -39
  118. package/dist/tui/theme.js +0 -33
  119. package/dist/update-command.js +0 -118
  120. package/dist/updater/in-place.js +0 -83
  121. package/dist/updater/npm.js +0 -62
  122. package/dist/updater.js +0 -401
  123. package/node_modules/herdr-remote-relay/README.md +0 -76
  124. package/node_modules/herdr-remote-relay/README.zh-CN.md +0 -76
  125. package/node_modules/herdr-remote-relay/config.example.json +0 -18
  126. package/node_modules/herdr-remote-relay/deploy/cloudflared/config.yml.example +0 -9
  127. package/node_modules/herdr-remote-relay/deploy/docker/compose.yaml +0 -23
  128. package/node_modules/herdr-remote-relay/deploy/nginx/herdr-remote-relay.conf.example +0 -49
  129. package/node_modules/herdr-remote-relay/deploy/systemd/herdr-remote-relay.service +0 -41
  130. package/node_modules/herdr-remote-relay/deploy/systemd/relay.env.example +0 -25
  131. package/node_modules/herdr-remote-relay/dist/auth-store.d.ts +0 -114
  132. package/node_modules/herdr-remote-relay/dist/auth-store.js +0 -289
  133. package/node_modules/herdr-remote-relay/dist/metrics.d.ts +0 -76
  134. package/node_modules/herdr-remote-relay/dist/metrics.js +0 -249
  135. package/node_modules/herdr-remote-relay/dist/protocol/frames.d.ts +0 -27
  136. package/node_modules/herdr-remote-relay/dist/protocol/frames.js +0 -110
  137. package/node_modules/herdr-remote-relay/dist/protocol/herdr-keys.d.ts +0 -8
  138. package/node_modules/herdr-remote-relay/dist/protocol/herdr-keys.js +0 -34
  139. package/node_modules/herdr-remote-relay/dist/protocol/http.d.ts +0 -165
  140. package/node_modules/herdr-remote-relay/dist/protocol/http.js +0 -3
  141. package/node_modules/herdr-remote-relay/dist/protocol/index.d.ts +0 -7
  142. package/node_modules/herdr-remote-relay/dist/protocol/index.js +0 -9
  143. package/node_modules/herdr-remote-relay/dist/protocol/messages.d.ts +0 -362
  144. package/node_modules/herdr-remote-relay/dist/protocol/messages.js +0 -20
  145. package/node_modules/herdr-remote-relay/dist/protocol/paste.d.ts +0 -14
  146. package/node_modules/herdr-remote-relay/dist/protocol/paste.js +0 -50
  147. package/node_modules/herdr-remote-relay/dist/protocol/release.d.ts +0 -8
  148. package/node_modules/herdr-remote-relay/dist/protocol/release.js +0 -17
  149. package/node_modules/herdr-remote-relay/dist/protocol/terminal.d.ts +0 -79
  150. package/node_modules/herdr-remote-relay/dist/protocol/terminal.js +0 -150
  151. package/node_modules/herdr-remote-relay/dist/relay-config.d.ts +0 -74
  152. package/node_modules/herdr-remote-relay/dist/relay-config.js +0 -316
  153. package/node_modules/herdr-remote-relay/dist/relay-server.d.ts +0 -67
  154. package/node_modules/herdr-remote-relay/dist/relay-server.js +0 -196
  155. package/node_modules/herdr-remote-relay/dist/scroll-input.d.ts +0 -17
  156. package/node_modules/herdr-remote-relay/dist/scroll-input.js +0 -124
  157. package/node_modules/herdr-remote-relay/dist/server/client-channel.d.ts +0 -3
  158. package/node_modules/herdr-remote-relay/dist/server/client-channel.js +0 -396
  159. package/node_modules/herdr-remote-relay/dist/server/font-proxy.d.ts +0 -19
  160. package/node_modules/herdr-remote-relay/dist/server/font-proxy.js +0 -155
  161. package/node_modules/herdr-remote-relay/dist/server/host-broadcasts.d.ts +0 -27
  162. package/node_modules/herdr-remote-relay/dist/server/host-broadcasts.js +0 -83
  163. package/node_modules/herdr-remote-relay/dist/server/host-channel.d.ts +0 -3
  164. package/node_modules/herdr-remote-relay/dist/server/host-channel.js +0 -271
  165. package/node_modules/herdr-remote-relay/dist/server/http-api.d.ts +0 -4
  166. package/node_modules/herdr-remote-relay/dist/server/http-api.js +0 -219
  167. package/node_modules/herdr-remote-relay/dist/server/maintenance.d.ts +0 -5
  168. package/node_modules/herdr-remote-relay/dist/server/maintenance.js +0 -64
  169. package/node_modules/herdr-remote-relay/dist/server/requests.d.ts +0 -34
  170. package/node_modules/herdr-remote-relay/dist/server/requests.js +0 -142
  171. package/node_modules/herdr-remote-relay/dist/server/sessions.d.ts +0 -36
  172. package/node_modules/herdr-remote-relay/dist/server/sessions.js +0 -230
  173. package/node_modules/herdr-remote-relay/dist/server/sockets.d.ts +0 -12
  174. package/node_modules/herdr-remote-relay/dist/server/sockets.js +0 -64
  175. package/node_modules/herdr-remote-relay/dist/server/status.d.ts +0 -11
  176. package/node_modules/herdr-remote-relay/dist/server/status.js +0 -99
  177. package/node_modules/herdr-remote-relay/dist/server/transport.d.ts +0 -16
  178. package/node_modules/herdr-remote-relay/dist/server/transport.js +0 -110
  179. package/node_modules/herdr-remote-relay/dist/server/types.d.ts +0 -133
  180. package/node_modules/herdr-remote-relay/dist/server/types.js +0 -3
  181. package/node_modules/herdr-remote-relay/dist/server/version.d.ts +0 -2
  182. package/node_modules/herdr-remote-relay/dist/server/version.js +0 -5
  183. package/node_modules/herdr-remote-relay/dist/state.d.ts +0 -6
  184. package/node_modules/herdr-remote-relay/dist/state.js +0 -47
  185. package/node_modules/ws/LICENSE +0 -20
  186. package/node_modules/ws/README.md +0 -548
  187. package/node_modules/ws/browser.js +0 -8
  188. package/node_modules/ws/index.js +0 -22
  189. package/node_modules/ws/lib/buffer-util.js +0 -131
  190. package/node_modules/ws/lib/constants.js +0 -19
  191. package/node_modules/ws/lib/event-target.js +0 -292
  192. package/node_modules/ws/lib/extension.js +0 -203
  193. package/node_modules/ws/lib/limiter.js +0 -55
  194. package/node_modules/ws/lib/permessage-deflate.js +0 -530
  195. package/node_modules/ws/lib/receiver.js +0 -743
  196. package/node_modules/ws/lib/sender.js +0 -607
  197. package/node_modules/ws/lib/stream.js +0 -161
  198. package/node_modules/ws/lib/subprotocol.js +0 -62
  199. package/node_modules/ws/lib/validation.js +0 -152
  200. package/node_modules/ws/lib/websocket-server.js +0 -562
  201. package/node_modules/ws/lib/websocket.js +0 -1407
  202. package/node_modules/ws/package.json +0 -74
  203. package/node_modules/ws/wrapper.mjs +0 -21
@@ -1,110 +0,0 @@
1
- // Sending to windows and hosts: terminal output with back-pressure, JSON
2
- // broadcasts, and the development-only latency queue.
3
- import { detachClient } from './sessions.js';
4
- import { isOpen, jsonSend } from './sockets.js';
5
- /** Notify the host whether any browser currently needs business telemetry. */
6
- export function notifyHostClientCount(host) {
7
- if (!host || !isOpen(host.ws))
8
- return;
9
- jsonSend(host.ws, { type: 'client_count', clientCount: host.clients.size });
10
- }
11
- /**
12
- * Forward output without allowing one slow browser to grow an unbounded ws
13
- * queue. Closing only that browser preserves low latency for the other views.
14
- */
15
- export function sendClientBinary(relay, host, client, payload) {
16
- if (!client || !isOpen(client.ws))
17
- return false;
18
- const limit = relay.config.relay.maxBufferedBytesPerClient;
19
- const buffered = Number(client.ws.bufferedAmount) || 0;
20
- if (buffered + payload.length > limit) {
21
- relay.metrics.recordCleanup('slowClientsDropped');
22
- detachClient(relay, client, { notify: true, reason: 'slow_client', closeCode: 1013 });
23
- return false;
24
- }
25
- let sent = false;
26
- const doSend = () => {
27
- if (!isOpen(client.ws))
28
- return;
29
- try {
30
- client.ws.send(payload);
31
- client.bytesSent += payload.length;
32
- relay.metrics.recordOut(payload.length, host.id);
33
- sent = true;
34
- }
35
- catch {
36
- detachClient(relay, client, { notify: false, reason: 'client_send_failed', closeCode: 1011 });
37
- }
38
- };
39
- if (relay.devLatencyMs > 0)
40
- enqueueDelayedSend(relay, client.ws, doSend);
41
- else
42
- doSend();
43
- return relay.devLatencyMs > 0 ? true : sent;
44
- }
45
- /**
46
- * Queue artificial delay per-socket rather than using naked setTimeout calls.
47
- * Concurrent timers experience event loop jitter that can deliver frames out of order;
48
- * a single FIFO queue per socket guarantees strict in-order delivery of terminal frames.
49
- */
50
- export function enqueueDelayedSend(relay, socket, task) {
51
- let queue = relay.sendQueues.get(socket);
52
- if (!queue) {
53
- const created = { items: [], timer: null };
54
- queue = created;
55
- relay.sendQueues.set(socket, created);
56
- socket.once('close', () => {
57
- if (created.timer) {
58
- clearTimeout(created.timer);
59
- relay.activeDelayTimers.delete(created.timer);
60
- created.timer = null;
61
- }
62
- created.items = [];
63
- });
64
- }
65
- const sendAt = Date.now() + relay.devDelayMs;
66
- queue.items.push({ sendAt, task });
67
- if (!queue.timer) {
68
- const pending = queue;
69
- const timer = setTimeout(() => flushSendQueue(relay, socket, pending), relay.devDelayMs);
70
- queue.timer = timer;
71
- relay.activeDelayTimers.add(timer);
72
- }
73
- }
74
- /**
75
- * Drain ready frames in FIFO order up to the current timestamp, then schedule the
76
- * single next timer if items remain. Ensures only one timer runs per socket at a time.
77
- */
78
- function flushSendQueue(relay, socket, queue) {
79
- if (queue.timer) {
80
- relay.activeDelayTimers.delete(queue.timer);
81
- queue.timer = null;
82
- }
83
- const now = Date.now();
84
- while (queue.items.length > 0 && queue.items[0].sendAt <= now) {
85
- const item = queue.items.shift();
86
- try {
87
- item?.task();
88
- }
89
- catch {
90
- // A send to a socket that closed while queued is dropped like any other.
91
- }
92
- }
93
- if (queue.items.length > 0 && !queue.timer) {
94
- const nextDelay = Math.max(0, queue.items[0].sendAt - Date.now());
95
- const timer = setTimeout(() => flushSendQueue(relay, socket, queue), nextDelay);
96
- queue.timer = timer;
97
- relay.activeDelayTimers.add(timer);
98
- }
99
- }
100
- /** Send one JSON message to every browser attached to `host`. */
101
- export function broadcastToClients(relay, host, build) {
102
- for (const clientId of [...host.clients]) {
103
- const client = relay.clients.get(clientId);
104
- if (!client)
105
- continue;
106
- const payload = build(client);
107
- if (payload)
108
- jsonSend(client.ws, payload);
109
- }
110
- }
@@ -1,133 +0,0 @@
1
- import type { WebSocket } from 'ws';
2
- import type { AuthStore } from '../auth-store.js';
3
- import type { RelayMetrics } from '../metrics.js';
4
- import type { ClientRole, HostPtySummary, ServerAgentStatusMessage, ServerUpdateStatusMessage, HostShellProfile } from '../protocol/messages.js';
5
- import type { HostTerminalFont, HostTerminalPalette } from '../protocol/terminal.js';
6
- import type { RelayConfig } from '../relay-config.js';
7
- /** A WebSocket plus the liveness flag the heartbeat keeps on it. */
8
- export type RelaySocket = WebSocket & {
9
- isAlive?: boolean;
10
- };
11
- /** One browser window's PTY stream on its host. */
12
- interface ClientSession {
13
- streamId: string;
14
- /** The v2 frame index, when the host negotiated v2 frames and one was free. */
15
- streamIndex: number | null;
16
- cols: number;
17
- rows: number;
18
- ready: boolean;
19
- }
20
- /** A connected workstation. */
21
- export interface RelayHost {
22
- id: string;
23
- ws: RelaySocket | null;
24
- hostname: string;
25
- platform: string;
26
- shellProfile?: HostShellProfile;
27
- /** The host can open an administrator terminal as a Herdr tab. */
28
- adminTabsAvailable: boolean;
29
- arch: string;
30
- connectedAt: string;
31
- connectedAtMs: number;
32
- terminalPalette: HostTerminalPalette | null;
33
- terminalFont: HostTerminalFont | null;
34
- /** Sanitized `keys.prefix` of the host's Herdr; absent when the host did not say. */
35
- herdrPrefixKeys?: string[];
36
- /** The latest agent summary, replayed to a window that joins late. */
37
- agentStatus: ServerAgentStatusMessage | null;
38
- /** Whether the workstation's herdr-remote is behind; replayed the same way. */
39
- updateStatus: ServerUpdateStatusMessage | null;
40
- /** The herdr-remote release the host runs; null when its hello did not say. */
41
- version: string | null;
42
- lastSeenAt: number;
43
- /** Ids of the windows attached to this host. */
44
- clients: Set<string>;
45
- controllerId: null;
46
- load: Record<string, unknown>;
47
- ptys: HostPtySummary[];
48
- reconnecting: boolean;
49
- reconnectTimer: NodeJS.Timeout | null;
50
- reconnectStartedAt?: number;
51
- connectionGeneration: string;
52
- handoffCapable: boolean;
53
- binaryFrameV2: boolean;
54
- /** v2 stream index → client id. */
55
- streamIndices: Map<number, string>;
56
- nextStreamIndex: number;
57
- shutdownRequested: boolean;
58
- }
59
- /** A connected browser window. */
60
- export interface RelayClient {
61
- id: string;
62
- ws: RelaySocket | null;
63
- hostId: string;
64
- deviceId: string;
65
- /** Stable per browser profile, supplied by the browser itself. */
66
- browserClientId: string | null;
67
- handoffCapable: boolean;
68
- session: ClientSession | null;
69
- role: ClientRole;
70
- controllerId: null;
71
- connectedAt: string;
72
- connectedAtMs: number;
73
- lastSeenAt: number;
74
- lastPingAt: string | null;
75
- bytesReceived: number;
76
- bytesSent: number;
77
- ip: string | null;
78
- userAgent: string;
79
- cols: number;
80
- rows: number;
81
- herdrStartAt?: number;
82
- adminTabAt?: number;
83
- fontRefreshAt?: number;
84
- /** When each outstanding font chunk request was sent. */
85
- fontChunkRequests?: number[];
86
- fontSubsetRequests?: number[];
87
- /** Cut fonts this window may pull by hash, with their sizes. */
88
- fontSubsets?: Map<string, number>;
89
- }
90
- /** Requests from one address within the current minute. */
91
- export interface AttemptWindow {
92
- startedAt: number;
93
- count: number;
94
- }
95
- /** Frames held back by the development latency switch, in order. */
96
- export interface SendQueue {
97
- items: {
98
- sendAt: number;
99
- task: () => void;
100
- }[];
101
- timer: NodeJS.Timeout | null;
102
- }
103
- /** What the server modules share: the relay's state and two of its methods. */
104
- export interface RelayContext {
105
- config: RelayConfig;
106
- relayMode: 'local' | 'remote';
107
- hosts: Map<string, RelayHost>;
108
- clients: Map<string, RelayClient>;
109
- /** Stream id → client id. */
110
- streams: Map<string, string>;
111
- pairAttempts: Map<string, AttemptWindow>;
112
- clientHandshakeAttempts: Map<string, AttemptWindow>;
113
- hostHandshakeAttempts: Map<string, AttemptWindow>;
114
- startedAt: number;
115
- metrics: RelayMetrics;
116
- auth: AuthStore;
117
- adminToken: string | null;
118
- trustProxy: boolean;
119
- devLatencyMs: number;
120
- devDelayMs: number;
121
- /** Where the built web client is served from. */
122
- publicDir: string;
123
- sendQueues: WeakMap<RelaySocket, SendQueue>;
124
- activeDelayTimers: Set<NodeJS.Timeout>;
125
- finishHandshake(ws: RelaySocket): void;
126
- address(): {
127
- host: string;
128
- port: number;
129
- } | {
130
- path: string;
131
- } | null;
132
- }
133
- export {};
@@ -1,3 +0,0 @@
1
- // The relay's records for connected hosts and browser windows, and the state
2
- // every server module works on.
3
- export {};
@@ -1,2 +0,0 @@
1
- /** This relay's release, as its package.json names it. */
2
- export declare const VERSION: string;
@@ -1,5 +0,0 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
- import { PACKAGE_ROOT } from '../relay-config.js';
4
- /** This relay's release, as its package.json names it. */
5
- export const VERSION = JSON.parse(fs.readFileSync(path.join(PACKAGE_ROOT, 'package.json'), 'utf8')).version;
@@ -1,6 +0,0 @@
1
- declare function ensureDir(dirPath: string): void;
2
- declare function writeJsonAtomic(filePath: string, value: unknown): void;
3
- /** Parsed JSON at `filePath`, or `fallback` when it is missing or unreadable. */
4
- declare function readJson<T>(filePath: string, fallback: T): T;
5
- declare function randomToken(bytes?: number): string;
6
- export { ensureDir, writeJsonAtomic, readJson, randomToken };
@@ -1,47 +0,0 @@
1
- import crypto from 'node:crypto';
2
- import fs from 'node:fs';
3
- import path from 'node:path';
4
- function ensureDir(dirPath) {
5
- fs.mkdirSync(dirPath, { recursive: true, mode: 0o700 });
6
- try {
7
- fs.chmodSync(dirPath, 0o700);
8
- }
9
- catch {
10
- // Some filesystems (Windows, some mounts) ignore modes; mkdir already asked for 0700.
11
- }
12
- }
13
- function writeJsonAtomic(filePath, value) {
14
- ensureDir(path.dirname(filePath));
15
- const tempPath = `${filePath}.${process.pid}.${crypto.randomBytes(4).toString('hex')}.tmp`;
16
- fs.writeFileSync(tempPath, `${JSON.stringify(value, null, 2)}\n`, { mode: 0o600 });
17
- try {
18
- fs.chmodSync(tempPath, 0o600);
19
- }
20
- catch {
21
- // Some filesystems ignore modes; the file was written with 0600 already.
22
- }
23
- fs.renameSync(tempPath, filePath);
24
- try {
25
- fs.chmodSync(filePath, 0o600);
26
- }
27
- catch {
28
- // Some filesystems ignore modes; the file was written with 0600 already.
29
- }
30
- }
31
- /** Parsed JSON at `filePath`, or `fallback` when it is missing or unreadable. */
32
- function readJson(filePath, fallback) {
33
- try {
34
- return JSON.parse(fs.readFileSync(filePath, 'utf8'));
35
- }
36
- catch (error) {
37
- const { code, message } = error;
38
- if (code !== 'ENOENT') {
39
- process.stderr.write(`herdr-remote: invalid state at ${filePath}: ${message}\n`);
40
- }
41
- return fallback;
42
- }
43
- }
44
- function randomToken(bytes = 32) {
45
- return crypto.randomBytes(bytes).toString('base64url');
46
- }
47
- export { ensureDir, writeJsonAtomic, readJson, randomToken };
@@ -1,20 +0,0 @@
1
- Copyright (c) 2011 Einar Otto Stangvik <einaros@gmail.com>
2
- Copyright (c) 2013 Arnout Kazemier and contributors
3
- Copyright (c) 2016 Luigi Pinca and contributors
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy of
6
- this software and associated documentation files (the "Software"), to deal in
7
- the Software without restriction, including without limitation the rights to
8
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
- the Software, and to permit persons to whom the Software is furnished to do so,
10
- subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
- FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
- COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
- IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.