@ethanfly/sshx 1.0.0 → 1.1.0
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/README.md +119 -0
- package/dist/cli/connect.d.ts +1 -0
- package/dist/cli/connect.d.ts.map +1 -1
- package/dist/cli/connect.js +7 -8
- package/dist/cli/connect.js.map +1 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +7 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/sync.d.ts +15 -0
- package/dist/cli/sync.d.ts.map +1 -0
- package/dist/cli/sync.js +220 -0
- package/dist/cli/sync.js.map +1 -0
- package/dist/core/config.d.ts +8 -0
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +15 -8
- package/dist/core/config.js.map +1 -1
- package/dist/core/metrics.d.ts +62 -0
- package/dist/core/metrics.d.ts.map +1 -0
- package/dist/core/metrics.js +207 -0
- package/dist/core/metrics.js.map +1 -0
- package/dist/core/split-session.d.ts +42 -0
- package/dist/core/split-session.d.ts.map +1 -0
- package/dist/core/split-session.js +223 -0
- package/dist/core/split-session.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/sync/crypto.d.ts +25 -0
- package/dist/sync/crypto.d.ts.map +1 -0
- package/dist/sync/crypto.js +69 -0
- package/dist/sync/crypto.js.map +1 -0
- package/dist/sync/manager.d.ts +54 -0
- package/dist/sync/manager.d.ts.map +1 -0
- package/dist/sync/manager.js +140 -0
- package/dist/sync/manager.js.map +1 -0
- package/dist/sync/provider.d.ts +63 -0
- package/dist/sync/provider.d.ts.map +1 -0
- package/dist/sync/provider.js +216 -0
- package/dist/sync/provider.js.map +1 -0
- package/dist/tui/app.d.ts +1 -0
- package/dist/tui/app.d.ts.map +1 -1
- package/dist/tui/app.js +22 -0
- package/dist/tui/app.js.map +1 -1
- package/dist/tui/screen.d.ts.map +1 -1
- package/dist/tui/screen.js +13 -3
- package/dist/tui/screen.js.map +1 -1
- package/dist/tui/screens/hosts.js +1 -1
- package/dist/tui/screens/hosts.js.map +1 -1
- package/dist/tui/sidebar.d.ts +19 -0
- package/dist/tui/sidebar.d.ts.map +1 -0
- package/dist/tui/sidebar.js +122 -0
- package/dist/tui/sidebar.js.map +1 -0
- package/package.json +11 -12
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { InteractiveSession } from './session.js';
|
|
2
|
+
import { MetricsCollector } from './metrics.js';
|
|
3
|
+
import { SidebarRenderer, defaultSidebarTheme } from '../tui/sidebar.js';
|
|
4
|
+
/**
|
|
5
|
+
* Manages an interactive split-pane SSH session:
|
|
6
|
+
* - Left pane: interactive remote PTY shell
|
|
7
|
+
* - Right pane: live server resource monitor (IP, user, CPU, RAM, Disk, Net, GPU)
|
|
8
|
+
* - Hotkeys: F2 or Ctrl+O to toggle sidebar expand/collapse
|
|
9
|
+
*/
|
|
10
|
+
export class SplitSession {
|
|
11
|
+
session;
|
|
12
|
+
collector;
|
|
13
|
+
client;
|
|
14
|
+
options;
|
|
15
|
+
sidebarVisible;
|
|
16
|
+
sidebarWidth;
|
|
17
|
+
lastMetrics;
|
|
18
|
+
isDestroyed = false;
|
|
19
|
+
enteredAltScreen = false;
|
|
20
|
+
constructor(client, options = {}) {
|
|
21
|
+
this.client = client;
|
|
22
|
+
this.options = options;
|
|
23
|
+
const totalCols = process.stdout.columns || 80;
|
|
24
|
+
this.sidebarWidth = options.sidebarWidth || 34;
|
|
25
|
+
// Default to visible if terminal is wide enough (>= 90 cols)
|
|
26
|
+
const wantsSidebar = options.enableSidebar !== false;
|
|
27
|
+
this.sidebarVisible = wantsSidebar && totalCols >= 90;
|
|
28
|
+
const leftCols = this.computeShellCols(totalCols);
|
|
29
|
+
const rows = process.stdout.rows || 24;
|
|
30
|
+
this.session = new InteractiveSession(client, {
|
|
31
|
+
...options,
|
|
32
|
+
cols: leftCols,
|
|
33
|
+
rows
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
getSession() {
|
|
37
|
+
return this.session;
|
|
38
|
+
}
|
|
39
|
+
computeShellCols(totalCols) {
|
|
40
|
+
if (!this.sidebarVisible) {
|
|
41
|
+
return totalCols;
|
|
42
|
+
}
|
|
43
|
+
// Shell takes remaining columns minus 1 for margin/separator
|
|
44
|
+
return Math.max(30, totalCols - this.sidebarWidth - 1);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Start the interactive split session
|
|
48
|
+
*/
|
|
49
|
+
async start() {
|
|
50
|
+
await this.session.start();
|
|
51
|
+
// Start background metrics collector over multiplexed SSH channel
|
|
52
|
+
try {
|
|
53
|
+
this.collector = new MetricsCollector(this.client, 2500);
|
|
54
|
+
this.collector.on('update', (metrics) => {
|
|
55
|
+
this.lastMetrics = metrics;
|
|
56
|
+
if (this.sidebarVisible && !this.isDestroyed) {
|
|
57
|
+
this.drawSidebar();
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
this.collector.start();
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
// Metrics collector is non-fatal; continue shell
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Attach terminal stdin and stdout with split-pane multiplexing
|
|
68
|
+
*/
|
|
69
|
+
attachToLocalProcess() {
|
|
70
|
+
const stdin = process.stdin;
|
|
71
|
+
const stdout = process.stdout;
|
|
72
|
+
const totalCols = stdout.columns || 80;
|
|
73
|
+
const totalRows = stdout.rows || 24;
|
|
74
|
+
if (this.sidebarVisible && stdout.isTTY) {
|
|
75
|
+
// Enter alternate screen buffer & clear to prevent previous terminal scrollback from showing
|
|
76
|
+
stdout.write('\x1b[?1049h\x1b[2J\x1b[H');
|
|
77
|
+
this.enteredAltScreen = true;
|
|
78
|
+
this.drawSidebar();
|
|
79
|
+
this.enableTerminalMargins();
|
|
80
|
+
}
|
|
81
|
+
// Set raw mode
|
|
82
|
+
if (stdin.isTTY) {
|
|
83
|
+
stdin.setRawMode(true);
|
|
84
|
+
stdin.resume();
|
|
85
|
+
}
|
|
86
|
+
// Handle terminal resize
|
|
87
|
+
const onResize = () => {
|
|
88
|
+
const cols = stdout.columns || 80;
|
|
89
|
+
const rows = stdout.rows || 24;
|
|
90
|
+
if (this.sidebarVisible && cols < 85) {
|
|
91
|
+
// Automatically hide sidebar on narrow terminals
|
|
92
|
+
this.sidebarVisible = false;
|
|
93
|
+
this.disableTerminalMargins();
|
|
94
|
+
}
|
|
95
|
+
const leftCols = this.computeShellCols(cols);
|
|
96
|
+
this.session.resize(leftCols, rows);
|
|
97
|
+
if (this.sidebarVisible) {
|
|
98
|
+
this.drawSidebar();
|
|
99
|
+
this.enableTerminalMargins();
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
this.disableTerminalMargins();
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
if (stdout.isTTY) {
|
|
106
|
+
stdout.on('resize', onResize);
|
|
107
|
+
}
|
|
108
|
+
// Stdin interceptor: listen for F2 or Ctrl+O to toggle sidebar
|
|
109
|
+
const onStdinData = (chunk) => {
|
|
110
|
+
const str = chunk.toString('utf8');
|
|
111
|
+
// F2: \x1bOQ or \x1b[12~ | Ctrl+O: \x0f
|
|
112
|
+
if (str === '\x1bOQ' || str === '\x1b[12~' || str === '\x0f') {
|
|
113
|
+
this.toggleSidebar();
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
this.session.write(chunk);
|
|
117
|
+
};
|
|
118
|
+
stdin.on('data', onStdinData);
|
|
119
|
+
// Shell output to stdout
|
|
120
|
+
this.session.on('data', (chunk) => {
|
|
121
|
+
stdout.write(chunk);
|
|
122
|
+
});
|
|
123
|
+
// Cleanup on session close
|
|
124
|
+
this.session.once('close', () => {
|
|
125
|
+
this.isDestroyed = true;
|
|
126
|
+
if (this.collector) {
|
|
127
|
+
this.collector.stop();
|
|
128
|
+
}
|
|
129
|
+
this.disableTerminalMargins();
|
|
130
|
+
if (this.enteredAltScreen && stdout.isTTY) {
|
|
131
|
+
// Exit alternate screen buffer, cleanly restoring user's original terminal
|
|
132
|
+
stdout.write('\x1b[?1049l');
|
|
133
|
+
this.enteredAltScreen = false;
|
|
134
|
+
}
|
|
135
|
+
if (stdin.isTTY) {
|
|
136
|
+
stdin.setRawMode(false);
|
|
137
|
+
stdin.pause();
|
|
138
|
+
}
|
|
139
|
+
stdin.removeListener('data', onStdinData);
|
|
140
|
+
if (stdout.isTTY) {
|
|
141
|
+
stdout.removeListener('resize', onResize);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
toggleSidebar() {
|
|
146
|
+
const stdout = process.stdout;
|
|
147
|
+
const totalCols = stdout.columns || 80;
|
|
148
|
+
const totalRows = stdout.rows || 24;
|
|
149
|
+
if (!this.sidebarVisible) {
|
|
150
|
+
// Cannot enable if terminal is too narrow
|
|
151
|
+
if (totalCols < 75) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
this.sidebarVisible = true;
|
|
155
|
+
const leftCols = this.computeShellCols(totalCols);
|
|
156
|
+
if (!this.enteredAltScreen && stdout.isTTY) {
|
|
157
|
+
stdout.write('\x1b[?1049h');
|
|
158
|
+
this.enteredAltScreen = true;
|
|
159
|
+
}
|
|
160
|
+
stdout.write('\x1b[2J\x1b[H');
|
|
161
|
+
this.drawSidebar();
|
|
162
|
+
this.enableTerminalMargins();
|
|
163
|
+
this.session.resize(leftCols, totalRows);
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
this.sidebarVisible = false;
|
|
167
|
+
this.disableTerminalMargins();
|
|
168
|
+
// Clear screen and resize shell to 100%
|
|
169
|
+
stdout.write('\x1b[2J\x1b[H');
|
|
170
|
+
this.session.resize(totalCols, totalRows);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
enableTerminalMargins() {
|
|
174
|
+
if (!process.stdout.isTTY)
|
|
175
|
+
return;
|
|
176
|
+
const totalCols = process.stdout.columns || 80;
|
|
177
|
+
const totalRows = process.stdout.rows || 24;
|
|
178
|
+
const leftCols = this.computeShellCols(totalCols);
|
|
179
|
+
// DECLRMM enable (\x1b[?69h), set vertical margin (\x1b[1;{totalRows}r), set horizontal margin (\x1b[1;{leftCols}s)
|
|
180
|
+
process.stdout.write(`\x1b[?69h\x1b[1;${totalRows}r\x1b[1;${leftCols}s`);
|
|
181
|
+
}
|
|
182
|
+
disableTerminalMargins() {
|
|
183
|
+
if (!process.stdout.isTTY)
|
|
184
|
+
return;
|
|
185
|
+
// DECLRMM disable (\x1b[?69l), reset scrolling region (\x1b[r)
|
|
186
|
+
process.stdout.write(`\x1b[?69l\x1b[r`);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Draw the right-hand sidebar at its fixed column offset without moving the shell cursor
|
|
190
|
+
*/
|
|
191
|
+
drawSidebar() {
|
|
192
|
+
if (!this.sidebarVisible || this.isDestroyed || !process.stdout.isTTY)
|
|
193
|
+
return;
|
|
194
|
+
const stdout = process.stdout;
|
|
195
|
+
const totalCols = stdout.columns || 80;
|
|
196
|
+
const totalRows = stdout.rows || 24;
|
|
197
|
+
const leftCols = this.computeShellCols(totalCols);
|
|
198
|
+
const sideStartCol = leftCols + 2; // +1 separator, +2 content
|
|
199
|
+
if (sideStartCol > totalCols - 10)
|
|
200
|
+
return;
|
|
201
|
+
const lines = SidebarRenderer.render(this.lastMetrics, this.sidebarWidth, totalRows, defaultSidebarTheme);
|
|
202
|
+
let buf = '';
|
|
203
|
+
// 1. Save cursor & hide cursor while updating sidebar
|
|
204
|
+
buf += '\x1b7\x1b[?25l';
|
|
205
|
+
// 2. Temporarily disable horizontal margin so cursor can move outside leftCols
|
|
206
|
+
buf += '\x1b[?69l';
|
|
207
|
+
// 3. Temporarily disable auto-wrap mode (DECAWM) to guarantee zero wrap-around to column 1
|
|
208
|
+
buf += '\x1b[?7l';
|
|
209
|
+
for (let r = 1; r <= Math.min(lines.length, totalRows); r++) {
|
|
210
|
+
const line = lines[r - 1];
|
|
211
|
+
// Position cursor at row r, column sideStartCol
|
|
212
|
+
buf += `\x1b[${r};${sideStartCol}H${line}`;
|
|
213
|
+
}
|
|
214
|
+
// 4. Re-enable auto-wrap mode for shell
|
|
215
|
+
buf += '\x1b[?7h';
|
|
216
|
+
// 5. Re-enable horizontal margin for shell
|
|
217
|
+
buf += `\x1b[?69h\x1b[1;${totalRows}r\x1b[1;${leftCols}s`;
|
|
218
|
+
// 6. Restore cursor & show cursor
|
|
219
|
+
buf += '\x1b8\x1b[?25h';
|
|
220
|
+
stdout.write(buf);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
//# sourceMappingURL=split-session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"split-session.js","sourceRoot":"","sources":["../../src/core/split-session.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAkB,MAAM,cAAc,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAiB,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAOzE;;;;;GAKG;AACH,MAAM,OAAO,YAAY;IACf,OAAO,CAAqB;IAC5B,SAAS,CAAoB;IAC7B,MAAM,CAAS;IACf,OAAO,CAAsB;IAE7B,cAAc,CAAU;IACxB,YAAY,CAAS;IACrB,WAAW,CAAiB;IAC5B,WAAW,GAAG,KAAK,CAAC;IACpB,gBAAgB,GAAG,KAAK,CAAC;IAEjC,YAAY,MAAc,EAAE,OAAO,GAAwB,EAAE;QAC3D,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAEvB,MAAM,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,IAAI,EAAE,CAAC;QAC/C,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,EAAE,CAAC;QAE/C,6DAA6D;QAC7D,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AE,CAAC;QAEpC,MAAM,QAAQ,GAAG,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;QAClD,MAAM,YAAY,GAAG,QAAQ,GAAG,CAAC,CAAC,CAAC,2BAA2B;QAC9D,IAAI,YAAY,GAAG,SAAS,GAAG,EAAE;YAAE,OAAO;QAE1C,MAAM,KAAK,GAAG,eAAe,CAAC,MAAM,CAClC,IAAI,CAAC,WAAW,EAChB,IAAI,CAAC,YAAY,EACjB,SAAS,EACT,mBAAmB,CACpB,CAAC;QAEF,IAAI,GAAG,GAAG,EAAE,CAAC;QACb,sDAAsD;QACtD,GAAG,IAAI,gBAAgB,CAAC;QACxB,+EAA+E;QAC/E,GAAG,IAAI,WAAW,CAAC;QACnB,2FAA2F;QAC3F,GAAG,IAAI,UAAU,CAAC;QAElB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;YAC5D,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YAC1B,gDAAgD;YAChD,GAAG,IAAI,QAAQ,CAAC,IAAI,YAAY,IAAI,IAAI,EAAE,CAAC;QAC7C,CAAC;QAED,wCAAwC;QACxC,GAAG,IAAI,UAAU,CAAC;QAClB,2CAA2C;QAC3C,GAAG,IAAI,mBAAmB,SAAS,WAAW,QAAQ,GAAG,CAAC;QAC1D,kCAAkC;QAClC,GAAG,IAAI,gBAAgB,CAAC;QAExB,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACpB,CAAC;CACF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,12 @@ export * from './core/keygen.js';
|
|
|
4
4
|
export * from './core/client.js';
|
|
5
5
|
export * from './core/exec.js';
|
|
6
6
|
export * from './core/session.js';
|
|
7
|
+
export * from './core/split-session.js';
|
|
8
|
+
export * from './core/metrics.js';
|
|
7
9
|
export * from './core/sftp.js';
|
|
8
10
|
export * from './core/tunnel.js';
|
|
11
|
+
export * from './sync/crypto.js';
|
|
12
|
+
export * from './sync/provider.js';
|
|
13
|
+
export * from './sync/manager.js';
|
|
14
|
+
export * from './tui/sidebar.js';
|
|
9
15
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,12 @@ export * from './core/keygen.js';
|
|
|
4
4
|
export * from './core/client.js';
|
|
5
5
|
export * from './core/exec.js';
|
|
6
6
|
export * from './core/session.js';
|
|
7
|
+
export * from './core/split-session.js';
|
|
8
|
+
export * from './core/metrics.js';
|
|
7
9
|
export * from './core/sftp.js';
|
|
8
10
|
export * from './core/tunnel.js';
|
|
11
|
+
export * from './sync/crypto.js';
|
|
12
|
+
export * from './sync/provider.js';
|
|
13
|
+
export * from './sync/manager.js';
|
|
14
|
+
export * from './tui/sidebar.js';
|
|
9
15
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface EncryptedPayload {
|
|
2
|
+
version: 1;
|
|
3
|
+
algorithm: 'aes-256-gcm';
|
|
4
|
+
kdf: 'scrypt';
|
|
5
|
+
salt: string;
|
|
6
|
+
iv: string;
|
|
7
|
+
tag: string;
|
|
8
|
+
ciphertext: string;
|
|
9
|
+
updatedAt: string;
|
|
10
|
+
itemCount?: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Encrypt plaintext data using AES-256-GCM with a user-supplied passphrase.
|
|
14
|
+
* Key derivation uses scrypt with a unique random salt per encryption.
|
|
15
|
+
*/
|
|
16
|
+
export declare function encryptPayload(plaintext: string, passphrase: string, itemCount?: number): string;
|
|
17
|
+
/**
|
|
18
|
+
* Decrypt an AES-256-GCM encrypted payload back into plaintext string.
|
|
19
|
+
* Throws friendly error on incorrect passphrase or tampered data.
|
|
20
|
+
*/
|
|
21
|
+
export declare function decryptPayload(encryptedJson: string, passphrase: string): {
|
|
22
|
+
plaintext: string;
|
|
23
|
+
payload: EncryptedPayload;
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=crypto.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../src/sync/crypto.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,CAAC,CAAC;IACX,SAAS,EAAE,aAAa,CAAC;IACzB,GAAG,EAAE,QAAQ,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CA8BhG;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,aAAa,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,gBAAgB,CAAA;CAAE,CAmC1H"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
/**
|
|
3
|
+
* Encrypt plaintext data using AES-256-GCM with a user-supplied passphrase.
|
|
4
|
+
* Key derivation uses scrypt with a unique random salt per encryption.
|
|
5
|
+
*/
|
|
6
|
+
export function encryptPayload(plaintext, passphrase, itemCount) {
|
|
7
|
+
if (!passphrase || passphrase.length < 4) {
|
|
8
|
+
throw new Error('Passphrase must be at least 4 characters long.');
|
|
9
|
+
}
|
|
10
|
+
const salt = crypto.randomBytes(16);
|
|
11
|
+
// scrypt: N=16384, r=8, p=1, keylen=32
|
|
12
|
+
const key = crypto.scryptSync(passphrase, salt, 32, { N: 16384, r: 8, p: 1 });
|
|
13
|
+
const iv = crypto.randomBytes(12); // standard 96-bit IV for AES-GCM
|
|
14
|
+
const cipher = crypto.createCipheriv('aes-256-gcm', key, iv);
|
|
15
|
+
const ciphertext = Buffer.concat([
|
|
16
|
+
cipher.update(plaintext, 'utf8'),
|
|
17
|
+
cipher.final()
|
|
18
|
+
]);
|
|
19
|
+
const tag = cipher.getAuthTag();
|
|
20
|
+
const payload = {
|
|
21
|
+
version: 1,
|
|
22
|
+
algorithm: 'aes-256-gcm',
|
|
23
|
+
kdf: 'scrypt',
|
|
24
|
+
salt: salt.toString('hex'),
|
|
25
|
+
iv: iv.toString('hex'),
|
|
26
|
+
tag: tag.toString('hex'),
|
|
27
|
+
ciphertext: ciphertext.toString('hex'),
|
|
28
|
+
updatedAt: new Date().toISOString(),
|
|
29
|
+
itemCount
|
|
30
|
+
};
|
|
31
|
+
return JSON.stringify(payload, null, 2);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Decrypt an AES-256-GCM encrypted payload back into plaintext string.
|
|
35
|
+
* Throws friendly error on incorrect passphrase or tampered data.
|
|
36
|
+
*/
|
|
37
|
+
export function decryptPayload(encryptedJson, passphrase) {
|
|
38
|
+
if (!passphrase) {
|
|
39
|
+
throw new Error('Passphrase is required to decrypt.');
|
|
40
|
+
}
|
|
41
|
+
let payload;
|
|
42
|
+
try {
|
|
43
|
+
payload = JSON.parse(encryptedJson);
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
throw new Error('Invalid encrypted payload format: expected JSON.');
|
|
47
|
+
}
|
|
48
|
+
if (payload.version !== 1 || payload.algorithm !== 'aes-256-gcm') {
|
|
49
|
+
throw new Error(`Unsupported encryption version or algorithm: ${payload.algorithm || 'unknown'}`);
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
const salt = Buffer.from(payload.salt, 'hex');
|
|
53
|
+
const iv = Buffer.from(payload.iv, 'hex');
|
|
54
|
+
const tag = Buffer.from(payload.tag, 'hex');
|
|
55
|
+
const ciphertext = Buffer.from(payload.ciphertext, 'hex');
|
|
56
|
+
const key = crypto.scryptSync(passphrase, salt, 32, { N: 16384, r: 8, p: 1 });
|
|
57
|
+
const decipher = crypto.createDecipheriv('aes-256-gcm', key, iv);
|
|
58
|
+
decipher.setAuthTag(tag);
|
|
59
|
+
const plaintext = Buffer.concat([
|
|
60
|
+
decipher.update(ciphertext),
|
|
61
|
+
decipher.final()
|
|
62
|
+
]).toString('utf8');
|
|
63
|
+
return { plaintext, payload };
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
throw new Error('Decryption failed. Incorrect passphrase or corrupted encrypted data.');
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=crypto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.js","sourceRoot":"","sources":["../../src/sync/crypto.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AAcjC;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,SAAiB,EAAE,UAAkB,EAAE,SAAkB;IACtF,IAAI,CAAC,UAAU,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACzC,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IACpE,CAAC;IAED,MAAM,IAAI,GAAG,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC,CAA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CAAC,CAAC;QAEpB,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC;IAChC,CAAC;IAAC,OAAO,GAAQ,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CAAC,sEAAsE,CAAC,CAAC;IAC1F,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { ConfigManager } from '../core/config.js';
|
|
2
|
+
import { SyncProvider, WebDavConfig, GistConfig } from './provider.js';
|
|
3
|
+
export interface SyncConfig {
|
|
4
|
+
provider: 'webdav' | 'gist';
|
|
5
|
+
passphrase?: string;
|
|
6
|
+
savePassphrase?: boolean;
|
|
7
|
+
lastSync?: string;
|
|
8
|
+
webdav?: WebDavConfig;
|
|
9
|
+
gist?: GistConfig;
|
|
10
|
+
}
|
|
11
|
+
export interface SyncPushResult {
|
|
12
|
+
ok: boolean;
|
|
13
|
+
count: number;
|
|
14
|
+
remoteId?: string;
|
|
15
|
+
updatedAt: string;
|
|
16
|
+
}
|
|
17
|
+
export interface SyncPullResult {
|
|
18
|
+
ok: boolean;
|
|
19
|
+
imported: number;
|
|
20
|
+
updated: number;
|
|
21
|
+
total: number;
|
|
22
|
+
remoteUpdatedAt?: string;
|
|
23
|
+
}
|
|
24
|
+
export declare class SyncManager {
|
|
25
|
+
private configManager;
|
|
26
|
+
private syncFilePath;
|
|
27
|
+
constructor(configManager?: ConfigManager);
|
|
28
|
+
getConfig(): SyncConfig | null;
|
|
29
|
+
saveConfig(config: SyncConfig): void;
|
|
30
|
+
getProvider(overrideConfig?: SyncConfig): SyncProvider;
|
|
31
|
+
/**
|
|
32
|
+
* Push encrypted host profiles to cloud provider
|
|
33
|
+
*/
|
|
34
|
+
push(passphrase?: string): Promise<SyncPushResult>;
|
|
35
|
+
/**
|
|
36
|
+
* Pull and decrypt host profiles from cloud provider
|
|
37
|
+
*/
|
|
38
|
+
pull(passphrase?: string, mode?: 'merge' | 'overwrite'): Promise<SyncPullResult>;
|
|
39
|
+
/**
|
|
40
|
+
* Get sync status and connectivity check
|
|
41
|
+
*/
|
|
42
|
+
getStatus(): Promise<{
|
|
43
|
+
configured: boolean;
|
|
44
|
+
provider?: string;
|
|
45
|
+
lastSync?: string;
|
|
46
|
+
localHostsCount: number;
|
|
47
|
+
connectivity?: {
|
|
48
|
+
ok: boolean;
|
|
49
|
+
message: string;
|
|
50
|
+
};
|
|
51
|
+
}>;
|
|
52
|
+
}
|
|
53
|
+
export declare const defaultSyncManager: SyncManager;
|
|
54
|
+
//# sourceMappingURL=manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../src/sync/manager.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAwB,MAAM,mBAAmB,CAAC;AAExE,OAAO,EAAE,YAAY,EAAgC,YAAY,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAErG,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAAC;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,IAAI,CAAC,EAAE,UAAU,CAAC;CACnB;AAED,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,OAAO,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,OAAO,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,qBAAa,WAAW;IAGV,OAAO,CAAC,aAAa;IAFjC,OAAO,CAAC,YAAY,CAAS;IAE7B,YAAoB,aAAa,GAAE,aAAoC,EAEtE;IAEM,SAAS,IAAI,UAAU,GAAG,IAAI,CAUpC;IAEM,UAAU,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI,CAM1C;IAEM,WAAW,CAAC,cAAc,CAAC,EAAE,UAAU,GAAG,YAAY,CAmB5D;IAED;;OAEG;IACU,IAAI,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAkC9D;IAED;;OAEG;IACU,IAAI,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,IAAI,GAAE,OAAO,GAAG,WAAqB,GAAG,OAAO,CAAC,cAAc,CAAC,CA2BrG;IAED;;OAEG;IACU,SAAS,IAAI,OAAO,CAAC;QAChC,UAAU,EAAE,OAAO,CAAC;QACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,eAAe,EAAE,MAAM,CAAC;QACxB,YAAY,CAAC,EAAE;YAAE,EAAE,EAAE,OAAO,CAAC;YAAC,OAAO,EAAE,MAAM,CAAA;SAAE,CAAC;KACjD,CAAC,CA0BD;CACF;AAED,eAAO,MAAM,kBAAkB,aAAoB,CAAC"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { defaultConfigManager } from '../core/config.js';
|
|
4
|
+
import { encryptPayload, decryptPayload } from './crypto.js';
|
|
5
|
+
import { WebDavProvider, GistProvider } from './provider.js';
|
|
6
|
+
export class SyncManager {
|
|
7
|
+
configManager;
|
|
8
|
+
syncFilePath;
|
|
9
|
+
constructor(configManager = defaultConfigManager) {
|
|
10
|
+
this.configManager = configManager;
|
|
11
|
+
this.syncFilePath = path.join(this.configManager.getConfigDir(), 'sync.json');
|
|
12
|
+
}
|
|
13
|
+
getConfig() {
|
|
14
|
+
if (!fs.existsSync(this.syncFilePath)) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
try {
|
|
18
|
+
const data = fs.readFileSync(this.syncFilePath, 'utf8');
|
|
19
|
+
return JSON.parse(data);
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
saveConfig(config) {
|
|
26
|
+
const dir = path.dirname(this.syncFilePath);
|
|
27
|
+
if (!fs.existsSync(dir)) {
|
|
28
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
29
|
+
}
|
|
30
|
+
fs.writeFileSync(this.syncFilePath, JSON.stringify(config, null, 2), { mode: 0o600 });
|
|
31
|
+
}
|
|
32
|
+
getProvider(overrideConfig) {
|
|
33
|
+
const config = overrideConfig || this.getConfig();
|
|
34
|
+
if (!config) {
|
|
35
|
+
throw new Error('Sync is not configured yet. Run "sshx sync setup" first.');
|
|
36
|
+
}
|
|
37
|
+
if (config.provider === 'webdav') {
|
|
38
|
+
if (!config.webdav || !config.webdav.url || !config.webdav.username) {
|
|
39
|
+
throw new Error('Incomplete WebDAV configuration.');
|
|
40
|
+
}
|
|
41
|
+
return new WebDavProvider(config.webdav);
|
|
42
|
+
}
|
|
43
|
+
else if (config.provider === 'gist') {
|
|
44
|
+
if (!config.gist || !config.gist.token) {
|
|
45
|
+
throw new Error('Incomplete GitHub Gist configuration (missing token).');
|
|
46
|
+
}
|
|
47
|
+
return new GistProvider(config.gist);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
throw new Error(`Unsupported sync provider: ${config.provider}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Push encrypted host profiles to cloud provider
|
|
55
|
+
*/
|
|
56
|
+
async push(passphrase) {
|
|
57
|
+
const config = this.getConfig();
|
|
58
|
+
if (!config) {
|
|
59
|
+
throw new Error('Sync is not configured. Run "sshx sync setup" to get started.');
|
|
60
|
+
}
|
|
61
|
+
const resolvedPassphrase = passphrase || config.passphrase;
|
|
62
|
+
if (!resolvedPassphrase) {
|
|
63
|
+
throw new Error('Passphrase is required to encrypt your host profiles.');
|
|
64
|
+
}
|
|
65
|
+
const hosts = this.configManager.getHosts();
|
|
66
|
+
const exportJson = this.configManager.exportHosts();
|
|
67
|
+
const encryptedBlob = encryptPayload(exportJson, resolvedPassphrase, hosts.length);
|
|
68
|
+
const provider = this.getProvider(config);
|
|
69
|
+
const pushRes = await provider.push(encryptedBlob);
|
|
70
|
+
// If Gist provider auto-created a gistId, save it back
|
|
71
|
+
if (config.provider === 'gist' && pushRes.remoteId && (!config.gist?.gistId || config.gist.gistId !== pushRes.remoteId)) {
|
|
72
|
+
config.gist = { ...config.gist, gistId: pushRes.remoteId };
|
|
73
|
+
}
|
|
74
|
+
const updatedAt = new Date().toISOString();
|
|
75
|
+
config.lastSync = updatedAt;
|
|
76
|
+
this.saveConfig(config);
|
|
77
|
+
return {
|
|
78
|
+
ok: true,
|
|
79
|
+
count: hosts.length,
|
|
80
|
+
remoteId: pushRes.remoteId,
|
|
81
|
+
updatedAt
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Pull and decrypt host profiles from cloud provider
|
|
86
|
+
*/
|
|
87
|
+
async pull(passphrase, mode = 'merge') {
|
|
88
|
+
const config = this.getConfig();
|
|
89
|
+
if (!config) {
|
|
90
|
+
throw new Error('Sync is not configured. Run "sshx sync setup" to get started.');
|
|
91
|
+
}
|
|
92
|
+
const resolvedPassphrase = passphrase || config.passphrase;
|
|
93
|
+
if (!resolvedPassphrase) {
|
|
94
|
+
throw new Error('Passphrase is required to decrypt your host profiles.');
|
|
95
|
+
}
|
|
96
|
+
const provider = this.getProvider(config);
|
|
97
|
+
const encryptedBlob = await provider.pull();
|
|
98
|
+
const { plaintext, payload } = decryptPayload(encryptedBlob, resolvedPassphrase);
|
|
99
|
+
const importRes = this.configManager.importHostsFromJson(plaintext, mode);
|
|
100
|
+
config.lastSync = new Date().toISOString();
|
|
101
|
+
this.saveConfig(config);
|
|
102
|
+
return {
|
|
103
|
+
ok: true,
|
|
104
|
+
imported: importRes.imported,
|
|
105
|
+
updated: importRes.updated,
|
|
106
|
+
total: importRes.total,
|
|
107
|
+
remoteUpdatedAt: payload.updatedAt
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Get sync status and connectivity check
|
|
112
|
+
*/
|
|
113
|
+
async getStatus() {
|
|
114
|
+
const config = this.getConfig();
|
|
115
|
+
const hostsCount = this.configManager.getHosts().length;
|
|
116
|
+
if (!config) {
|
|
117
|
+
return {
|
|
118
|
+
configured: false,
|
|
119
|
+
localHostsCount: hostsCount
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
let connectivity;
|
|
123
|
+
try {
|
|
124
|
+
const provider = this.getProvider(config);
|
|
125
|
+
connectivity = await provider.test();
|
|
126
|
+
}
|
|
127
|
+
catch (err) {
|
|
128
|
+
connectivity = { ok: false, message: err.message || String(err) };
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
configured: true,
|
|
132
|
+
provider: config.provider,
|
|
133
|
+
lastSync: config.lastSync,
|
|
134
|
+
localHostsCount: hostsCount,
|
|
135
|
+
connectivity
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
export const defaultSyncManager = new SyncManager();
|
|
140
|
+
//# sourceMappingURL=manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager.js","sourceRoot":"","sources":["../../src/sync/manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAiB,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAgB,cAAc,EAAE,YAAY,EAA4B,MAAM,eAAe,CAAC;AA0BrG,MAAM,OAAO,WAA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,GAAG,CAAC,EAAE,CAAC;QACpE,CAAC;QAED,OAAO;YACL,UAAU,EAAE,IAAI;YAChB,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,eAAe,EAAE,UAAU;YAC3B,YAAY;SACb,CAAC;IACJ,CAAC;CACF;AAED,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export interface SyncProvider {
|
|
2
|
+
name: string;
|
|
3
|
+
test(): Promise<{
|
|
4
|
+
ok: boolean;
|
|
5
|
+
message: string;
|
|
6
|
+
}>;
|
|
7
|
+
pull(): Promise<string>;
|
|
8
|
+
push(encryptedBlob: string): Promise<{
|
|
9
|
+
remoteId?: string;
|
|
10
|
+
}>;
|
|
11
|
+
}
|
|
12
|
+
export interface WebDavConfig {
|
|
13
|
+
url: string;
|
|
14
|
+
username: string;
|
|
15
|
+
password: string;
|
|
16
|
+
filename?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface GistConfig {
|
|
19
|
+
token: string;
|
|
20
|
+
gistId?: string;
|
|
21
|
+
description?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* WebDAV Provider (compatible with Jianguoyun, Nextcloud, ownCloud, Synology, Alist, etc.)
|
|
25
|
+
*/
|
|
26
|
+
export declare class WebDavProvider implements SyncProvider {
|
|
27
|
+
private config;
|
|
28
|
+
name: string;
|
|
29
|
+
private baseUrl;
|
|
30
|
+
private authHeader;
|
|
31
|
+
private filename;
|
|
32
|
+
constructor(config: WebDavConfig);
|
|
33
|
+
private get fileUrl();
|
|
34
|
+
test(): Promise<{
|
|
35
|
+
ok: boolean;
|
|
36
|
+
message: string;
|
|
37
|
+
}>;
|
|
38
|
+
private ensureDirectory;
|
|
39
|
+
pull(): Promise<string>;
|
|
40
|
+
push(encryptedBlob: string): Promise<{
|
|
41
|
+
remoteId?: string;
|
|
42
|
+
}>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* GitHub Secret Gist Provider
|
|
46
|
+
*/
|
|
47
|
+
export declare class GistProvider implements SyncProvider {
|
|
48
|
+
private config;
|
|
49
|
+
name: string;
|
|
50
|
+
private static GIST_FILENAME;
|
|
51
|
+
constructor(config: GistConfig);
|
|
52
|
+
private get headers();
|
|
53
|
+
test(): Promise<{
|
|
54
|
+
ok: boolean;
|
|
55
|
+
message: string;
|
|
56
|
+
}>;
|
|
57
|
+
pull(): Promise<string>;
|
|
58
|
+
push(encryptedBlob: string): Promise<{
|
|
59
|
+
remoteId?: string;
|
|
60
|
+
}>;
|
|
61
|
+
private findSshxGistId;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/sync/provider.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,IAAI,OAAO,CAAC;QAAE,EAAE,EAAE,OAAO,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAClD,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IACxB,IAAI,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC7D;AAED,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,qBAAa,c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