@open-wa/session-sync 5.0.0-alpha.7 → 5.0.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/LICENSE.md +2 -2
- package/README.md +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +3 -4
- package/dist/index.d.cts.map +1 -1
- package/package.json +13 -9
- package/.turbo/turbo-build.log +0 -15
- package/.turbo/turbo-lint.log +0 -26
- package/.turbo/turbo-test.log +0 -12
- package/CHANGELOG.md +0 -63
- package/src/index.ts +0 -4
- package/src/local-compression.ts +0 -127
- package/src/s3-sync.ts +0 -131
- package/test/manual_validation.ts +0 -59
- package/tsconfig.json +0 -10
package/LICENSE.md
CHANGED
|
@@ -55,9 +55,9 @@ Licensor hereby grants permission by this license ("License"), free of charge,
|
|
|
55
55
|
4. Compliance with Human Rights Laws and Human Rights Principles:
|
|
56
56
|
|
|
57
57
|
a. **Human Rights Laws**. The Software shall not be used by any person or entity for any systems, activities, or other uses that violate any applicable laws, regulations, or rules that protect human, civil, labor, privacy, political, environmental, security, economic, due process, or similar rights (the "Human Rights Laws"). Where the Human Rights Laws of more than one jurisdiction are applicable to the use of the Software, the Human Rights Laws that are most protective of the individuals or groups harmed shall apply.
|
|
58
|
-
|
|
58
|
+
|
|
59
59
|
b. **Human Rights Principles**. Licensee is advised to consult the articles of the United Nations Universal Declaration of Human Rights (https://www.un.org/en/universal-declaration-human-rights/) and the United Nations Global Compact (https://www.unglobalcompact.org/ what-is-gc/mission/principles) that define recognized principles of international human rights (the "Human Rights Principles"). It is Licensor's express intent that all use of the Software be consistent with Human Rights Principles. If Licensor receives notification or otherwise learns of an alleged violation of any Human Rights Principles relating to Licensee's use of the Software, Licensor may in its discretion and without obligation (i) (a) notify Licensee of such allegation and (b) allow Licensee 90 days from notification under (i)(a) to investigate and respond to Licensor regarding the allegation and (ii) (a) after the earlier of 90 days from notification under (i)(a), or Licensee's response under (i)(b), notify Licensee of License termination and (b) allow Licensee an additional 90 days from notification under (ii)(a) to cease use of the Software.
|
|
60
|
-
|
|
60
|
+
|
|
61
61
|
c. **Indemnity**. Licensee shall hold harmless and indemnify Licensor against all losses, damages, liabilities, deficiencies, claims, actions, judgments, settlements, interest, awards, penalties, fines, costs, or expenses of whatever kind, including Licensor's reasonable attorneys' fees, arising out of or relating to Licensee's non-compliance with this License or use of the Software in violation of Human Rights Laws or Human Rights Principles.
|
|
62
62
|
|
|
63
63
|
5. Enforceability: If any portion or provision of this License is determined to be invalid, illegal, or unenforceable by a court of competent jurisdiction, then such invalidity, illegality, or unenforceability shall not affect any other term or provision of this License or invalidate or render unenforceable such term or provision in any other jurisdiction. Upon a determination that any term or provision is invalid, illegal, or unenforceable, to the extent permitted by applicable law, the court may modify this License to affect the original intent of the parties as closely as possible. The section headings are for convenience only and are not intended to affect the construction or interpretation of this License. Any rule of construction to the effect that ambiguities are to be resolved against the drafting party shall not apply in interpreting this License. The language in this License shall be interpreted as to its fair meaning and not strictly for or against any party.
|
package/README.md
CHANGED
|
@@ -12,8 +12,8 @@ pnpm add @open-wa/session-sync
|
|
|
12
12
|
|
|
13
13
|
## Documentation
|
|
14
14
|
|
|
15
|
-
See the [docs site](https://
|
|
15
|
+
See the [docs site](https://openwa.dev).
|
|
16
16
|
|
|
17
17
|
## License
|
|
18
18
|
|
|
19
|
-
[H-DNH
|
|
19
|
+
[H-DNH 1.1](https://github.com/open-wa/wa-automate-nodejs/blob/master/LICENSE.md) — Hippocratic + Do Not Harm
|
package/dist/index.cjs
CHANGED
|
@@ -16,7 +16,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
}
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
20
20
|
value: mod,
|
|
21
21
|
enumerable: true
|
|
22
22
|
}) : target, mod));
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { EventEmitter } from "events";
|
|
2
|
-
|
|
3
2
|
//#region src/local-compression.d.ts
|
|
4
3
|
interface CompressionOptions {
|
|
5
4
|
sessionPath: string;
|
|
@@ -7,7 +6,7 @@ interface CompressionOptions {
|
|
|
7
6
|
outputPath?: string;
|
|
8
7
|
intervalMs?: number;
|
|
9
8
|
}
|
|
10
|
-
declare class LocalSessionCompression extends EventEmitter {
|
|
9
|
+
export declare class LocalSessionCompression extends EventEmitter {
|
|
11
10
|
private watcher;
|
|
12
11
|
private isCompressing;
|
|
13
12
|
private lastCompressionTime;
|
|
@@ -30,7 +29,7 @@ interface S3Config {
|
|
|
30
29
|
host?: string;
|
|
31
30
|
url?: string;
|
|
32
31
|
}
|
|
33
|
-
declare class S3SyncManager {
|
|
32
|
+
export declare class S3SyncManager {
|
|
34
33
|
private p3;
|
|
35
34
|
private config;
|
|
36
35
|
constructor(config: S3Config);
|
|
@@ -41,5 +40,5 @@ declare class S3SyncManager {
|
|
|
41
40
|
deleteSession(filename: string): Promise<boolean>;
|
|
42
41
|
}
|
|
43
42
|
//#endregion
|
|
44
|
-
export {
|
|
43
|
+
export type { CompressionOptions, S3Config };
|
|
45
44
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/local-compression.ts","../src/s3-sync.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/local-compression.ts","../src/s3-sync.ts"],"mappings":";;UAOiB;EACb;EACA;EACA;EACA;;qBAGS,gCAAgC;UACjC;UACA;UACA;UACA;UACA;EAER,YAAY,QAAQ;EAMb;EAqBA;UAWC;EAoBK,YAAQ;;;;UCxER;EACb;EACA;EACA;EACA;EACA;EACA;EACA;;qBAGS;UACD;UACA;EAER,YAAY,QAAQ;EAaP,cAAc,wBAAwB,0BAA0B;EAoBhE,eAAe,kBAAkB,qBAAqB;EA2CtD,eAAe,kBAAkB,sBAA0B;EAU3D,cAAc,mBAAmB;EAWjC,cAAc,mBAAmB"}
|
package/package.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-wa/session-sync",
|
|
3
|
-
"version": "5.0.0
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"main": "dist/index.cjs",
|
|
5
5
|
"types": "dist/index.d.cts",
|
|
6
6
|
"dependencies": {
|
|
7
|
+
"@open-wa/schema": "5.0.0",
|
|
8
|
+
"chokidar": "^5.0.0",
|
|
7
9
|
"pico-s3": "^2.11.0",
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"chokidar": "^4.0.0",
|
|
11
|
-
"@open-wa/schema": "5.0.0-alpha.7"
|
|
10
|
+
"simple-zstd": "^2.1.0",
|
|
11
|
+
"tar-fs": "^3.1.3"
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
14
|
+
"@types/node": "^26.6.3",
|
|
15
|
+
"@types/tar-fs": "^2.0.4",
|
|
16
|
+
"typescript": "^7.0.2",
|
|
17
|
+
"vitest": "5.0.2"
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|
|
@@ -28,6 +28,10 @@
|
|
|
28
28
|
"default": "./dist/index.cjs"
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
|
+
"license": "SEE LICENSE IN LICENSE.md",
|
|
32
|
+
"files": [
|
|
33
|
+
"dist"
|
|
34
|
+
],
|
|
31
35
|
"scripts": {
|
|
32
36
|
"build": "tsdown src/index.ts --format cjs",
|
|
33
37
|
"dev": "tsdown src/index.ts --format cjs --watch",
|
package/.turbo/turbo-build.log
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
> @open-wa/session-sync@5.0.0-alpha.7 build /Users/Mohammed/projects/tools/wa/packages/session-sync
|
|
3
|
-
> tsdown src/index.ts --format cjs
|
|
4
|
-
|
|
5
|
-
ℹ tsdown v0.21.7 powered by rolldown v1.0.0-rc.12
|
|
6
|
-
ℹ entry: src/index.ts
|
|
7
|
-
ℹ tsconfig: tsconfig.json
|
|
8
|
-
ℹ Build start
|
|
9
|
-
ℹ Cleaning 3 files
|
|
10
|
-
ℹ dist/index.cjs 6.71 kB │ gzip: 2.26 kB
|
|
11
|
-
ℹ 1 files, total: 6.71 kB
|
|
12
|
-
ℹ dist/index.d.cts.map 0.73 kB │ gzip: 0.33 kB
|
|
13
|
-
ℹ dist/index.d.cts 1.29 kB │ gzip: 0.53 kB
|
|
14
|
-
ℹ 2 files, total: 2.03 kB
|
|
15
|
-
✔ Build complete in 2194ms
|
package/.turbo/turbo-lint.log
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
> @open-wa/session-sync@1.0.0 lint /Users/Mohammed/projects/tools/wa/packages/session-sync
|
|
3
|
-
> oxlint src
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
! eslint-plugin-import(no-named-as-default-member): "chokidar" also has a named export "watch"
|
|
7
|
-
,-[src/local-compression.ts:33:24]
|
|
8
|
-
32 | // We ignore existing .zst files to prevent infinite loops
|
|
9
|
-
33 | this.watcher = chokidar.watch(this.config.sessionPath, {
|
|
10
|
-
: ^^^^^^^^^^^^^^
|
|
11
|
-
34 | ignored: /(^|[\/\\])\..|.*\.zst$/,
|
|
12
|
-
`----
|
|
13
|
-
help: Check if you meant to write `import { watch } from "chokidar"`
|
|
14
|
-
|
|
15
|
-
x eslint(no-useless-escape): Unnecessary escape character '/'
|
|
16
|
-
,-[src/local-compression.ts:34:27]
|
|
17
|
-
33 | this.watcher = chokidar.watch(this.config.sessionPath, {
|
|
18
|
-
34 | ignored: /(^|[\/\\])\..|.*\.zst$/,
|
|
19
|
-
: ^^
|
|
20
|
-
35 | persistent: true,
|
|
21
|
-
`----
|
|
22
|
-
help: Replace `\/` with `/`.
|
|
23
|
-
|
|
24
|
-
Found 1 warning and 1 error.
|
|
25
|
-
Finished in 52ms on 3 files with 93 rules using 8 threads.
|
|
26
|
-
ELIFECYCLE Command failed with exit code 1.
|
package/.turbo/turbo-test.log
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
> @open-wa/session-sync@5.0.0-alpha.0 test /Users/Mohammed/projects/tools/wa/packages/session-sync
|
|
3
|
-
> vitest run --passWithNoTests
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
[1m[46m RUN [49m[22m [36mv4.1.2 [39m[90m/Users/Mohammed/projects/tools/wa/packages/session-sync[39m
|
|
7
|
-
|
|
8
|
-
No test files found, exiting with code 0
|
|
9
|
-
|
|
10
|
-
[2minclude: [22m[33m**/*.{test,spec}.?(c|m)[jt]s?(x)[39m
|
|
11
|
-
[2mexclude: [22m[33m**/node_modules/**[2m, [22m**/.git/**[39m
|
|
12
|
-
|
package/CHANGELOG.md
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
# @open-wa/session-sync
|
|
2
|
-
|
|
3
|
-
## 5.0.0-alpha.7
|
|
4
|
-
|
|
5
|
-
### Patch Changes
|
|
6
|
-
|
|
7
|
-
- Updated dependencies []:
|
|
8
|
-
- @open-wa/schema@5.0.0-alpha.7
|
|
9
|
-
|
|
10
|
-
## 5.0.0-alpha.6
|
|
11
|
-
|
|
12
|
-
### Patch Changes
|
|
13
|
-
|
|
14
|
-
- Updated dependencies []:
|
|
15
|
-
- @open-wa/schema@5.0.0-alpha.6
|
|
16
|
-
|
|
17
|
-
## 5.0.0-alpha.5
|
|
18
|
-
|
|
19
|
-
### Patch Changes
|
|
20
|
-
|
|
21
|
-
- Updated dependencies []:
|
|
22
|
-
- @open-wa/schema@5.0.0-alpha.5
|
|
23
|
-
|
|
24
|
-
## 5.0.0-alpha.4
|
|
25
|
-
|
|
26
|
-
### Patch Changes
|
|
27
|
-
|
|
28
|
-
- Updated dependencies []:
|
|
29
|
-
- @open-wa/schema@5.0.0-alpha.4
|
|
30
|
-
|
|
31
|
-
## 5.0.0-alpha.3
|
|
32
|
-
|
|
33
|
-
### Patch Changes
|
|
34
|
-
|
|
35
|
-
- Updated dependencies []:
|
|
36
|
-
- @open-wa/schema@5.0.0-alpha.3
|
|
37
|
-
|
|
38
|
-
## 5.0.0-alpha.2
|
|
39
|
-
|
|
40
|
-
### Patch Changes
|
|
41
|
-
|
|
42
|
-
- Updated dependencies []:
|
|
43
|
-
- @open-wa/schema@5.0.0-alpha.2
|
|
44
|
-
|
|
45
|
-
## 6.0.0-alpha.2
|
|
46
|
-
|
|
47
|
-
### Minor Changes
|
|
48
|
-
|
|
49
|
-
- Dry run minor bump
|
|
50
|
-
|
|
51
|
-
### Patch Changes
|
|
52
|
-
|
|
53
|
-
- Updated dependencies []:
|
|
54
|
-
- @open-wa/schema@6.0.0-alpha.2
|
|
55
|
-
|
|
56
|
-
## 5.0.1-alpha.2
|
|
57
|
-
|
|
58
|
-
### Patch Changes
|
|
59
|
-
|
|
60
|
-
- Dry run patch bump
|
|
61
|
-
|
|
62
|
-
- Updated dependencies []:
|
|
63
|
-
- @open-wa/schema@5.0.1-alpha.2
|
package/src/index.ts
DELETED
package/src/local-compression.ts
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import chokidar from 'chokidar';
|
|
2
|
-
import tar from 'tar-fs';
|
|
3
|
-
const zstd = require('simple-zstd');
|
|
4
|
-
import fs from 'fs';
|
|
5
|
-
import path from 'path';
|
|
6
|
-
import { EventEmitter } from 'events';
|
|
7
|
-
|
|
8
|
-
export interface CompressionOptions {
|
|
9
|
-
sessionPath: string;
|
|
10
|
-
sessionId: string;
|
|
11
|
-
outputPath?: string; // Defaults to sessionPath/session.data.zst
|
|
12
|
-
intervalMs?: number; // Throttle interval, default 10 mins (600000ms)
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export class LocalSessionCompression extends EventEmitter {
|
|
16
|
-
private watcher: any = null;
|
|
17
|
-
private isCompressing: boolean = false;
|
|
18
|
-
private lastCompressionTime: number = 0;
|
|
19
|
-
private throttleTimer: NodeJS.Timeout | null = null;
|
|
20
|
-
private config: CompressionOptions;
|
|
21
|
-
|
|
22
|
-
constructor(config: CompressionOptions) {
|
|
23
|
-
super();
|
|
24
|
-
this.config = config;
|
|
25
|
-
this.config.intervalMs = this.config.intervalMs || 600000;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
public start() {
|
|
29
|
-
if (this.watcher) return;
|
|
30
|
-
|
|
31
|
-
// Watch for changes in the directory
|
|
32
|
-
// We ignore existing .zst files to prevent infinite loops
|
|
33
|
-
this.watcher = chokidar.watch(this.config.sessionPath, {
|
|
34
|
-
ignored: /(^|[\/\\])\..|.*\.zst$/,
|
|
35
|
-
persistent: true,
|
|
36
|
-
awaitWriteFinish: {
|
|
37
|
-
stabilityThreshold: 2000,
|
|
38
|
-
pollInterval: 100
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
this.watcher.on('add', () => this.scheduleCompression());
|
|
43
|
-
this.watcher.on('change', () => this.scheduleCompression());
|
|
44
|
-
this.watcher.on('unlink', () => this.scheduleCompression());
|
|
45
|
-
|
|
46
|
-
console.log(`Session compression started for: ${this.config.sessionPath}`);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
public stop() {
|
|
50
|
-
if (this.watcher) {
|
|
51
|
-
this.watcher.close();
|
|
52
|
-
this.watcher = null;
|
|
53
|
-
}
|
|
54
|
-
if (this.throttleTimer) {
|
|
55
|
-
clearTimeout(this.throttleTimer);
|
|
56
|
-
this.throttleTimer = null;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
private scheduleCompression() {
|
|
61
|
-
if (this.isCompressing) return;
|
|
62
|
-
|
|
63
|
-
const now = Date.now();
|
|
64
|
-
const timeSinceLast = now - this.lastCompressionTime;
|
|
65
|
-
|
|
66
|
-
if (timeSinceLast >= (this.config.intervalMs || 600000)) {
|
|
67
|
-
this.compress();
|
|
68
|
-
} else {
|
|
69
|
-
if (!this.throttleTimer) {
|
|
70
|
-
const waitTime = (this.config.intervalMs || 600000) - timeSinceLast;
|
|
71
|
-
console.log(`Scheduling compression in ${Math.round(waitTime / 1000)}s`);
|
|
72
|
-
this.throttleTimer = setTimeout(() => {
|
|
73
|
-
this.compress();
|
|
74
|
-
this.throttleTimer = null;
|
|
75
|
-
}, waitTime);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
public async compress() {
|
|
81
|
-
if (this.isCompressing) return;
|
|
82
|
-
this.isCompressing = true;
|
|
83
|
-
|
|
84
|
-
const outputPath = this.config.outputPath || path.join(path.dirname(this.config.sessionPath), 'session.data.zst');
|
|
85
|
-
const start = Date.now();
|
|
86
|
-
|
|
87
|
-
try {
|
|
88
|
-
console.log('Starting compression...');
|
|
89
|
-
|
|
90
|
-
const sessionDir = this.config.sessionPath;
|
|
91
|
-
|
|
92
|
-
// Ensure output dir exists
|
|
93
|
-
fs.mkdirSync(path.dirname(outputPath), { recursive: true });
|
|
94
|
-
|
|
95
|
-
// Create write stream
|
|
96
|
-
const dest = fs.createWriteStream(outputPath);
|
|
97
|
-
|
|
98
|
-
// Pack -> Compress -> Write
|
|
99
|
-
const pack = tar.pack(sessionDir);
|
|
100
|
-
|
|
101
|
-
// Zstandard compression
|
|
102
|
-
// simple-zstd compress returns a Transform stream
|
|
103
|
-
// @ts-ignore
|
|
104
|
-
const zstdStream = zstd.ZSTDCompress(3); // Level 3 is default, good speed/ratio
|
|
105
|
-
|
|
106
|
-
await new Promise<void>((resolve, reject) => {
|
|
107
|
-
pack.pipe(zstdStream).pipe(dest)
|
|
108
|
-
.on('finish', () => resolve())
|
|
109
|
-
.on('error', (err: any) => reject(err));
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
const size = fs.statSync(outputPath).size;
|
|
113
|
-
const duration = Date.now() - start;
|
|
114
|
-
const metrics = { size, duration, path: outputPath };
|
|
115
|
-
|
|
116
|
-
this.lastCompressionTime = Date.now();
|
|
117
|
-
this.emit('compressed', metrics);
|
|
118
|
-
console.log(`Compression complete: ${(size / 1024 / 1024).toFixed(2)}MB in ${duration}ms`);
|
|
119
|
-
|
|
120
|
-
} catch (error) {
|
|
121
|
-
console.error('Compression failed:', error);
|
|
122
|
-
this.emit('error', error);
|
|
123
|
-
} finally {
|
|
124
|
-
this.isCompressing = false;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
package/src/s3-sync.ts
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import tar from 'tar-fs';
|
|
4
|
-
const PicoS3 = require('pico-s3');
|
|
5
|
-
const zstd = require('simple-zstd');
|
|
6
|
-
import { Readable } from 'stream';
|
|
7
|
-
|
|
8
|
-
export interface S3Config {
|
|
9
|
-
bucket: string;
|
|
10
|
-
region: string;
|
|
11
|
-
accessKeyId: string;
|
|
12
|
-
secretAccessKey: string;
|
|
13
|
-
endpoint?: string;
|
|
14
|
-
host?: string;
|
|
15
|
-
url?: string; // For compatibility
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export class S3SyncManager {
|
|
19
|
-
private p3: any; // PicoS3 types might be loose
|
|
20
|
-
private config: S3Config;
|
|
21
|
-
|
|
22
|
-
constructor(config: S3Config) {
|
|
23
|
-
this.config = config;
|
|
24
|
-
// @ts-ignore
|
|
25
|
-
this.p3 = new PicoS3.PicoS3({
|
|
26
|
-
bucket: config.bucket,
|
|
27
|
-
region: config.region,
|
|
28
|
-
accessKeyId: config.accessKeyId,
|
|
29
|
-
secretAccessKey: config.secretAccessKey,
|
|
30
|
-
endpoint: config.endpoint || config.host || config.url,
|
|
31
|
-
host: config.host // Explicit host support for some providers
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
public async backupSession(sessionZstPath: string, remoteFilename?: string): Promise<string> {
|
|
36
|
-
const filename = remoteFilename || path.basename(sessionZstPath);
|
|
37
|
-
|
|
38
|
-
console.log(`Reading session file for backup: ${sessionZstPath}`);
|
|
39
|
-
// Read file to buffer - PicoS3 requires buffer for upload
|
|
40
|
-
const buffer = await fs.promises.readFile(sessionZstPath);
|
|
41
|
-
|
|
42
|
-
console.log(`Uploading ${filename} (${buffer.length} bytes) to S3...`);
|
|
43
|
-
|
|
44
|
-
const result = await this.p3.upload({
|
|
45
|
-
file: buffer,
|
|
46
|
-
filename: filename,
|
|
47
|
-
directory: '_sessionData',
|
|
48
|
-
public: false
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
console.log(`Backup completed: ${result}`);
|
|
52
|
-
return filename;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
public async restoreSession(filename: string, targetPath: string): Promise<boolean> {
|
|
56
|
-
try {
|
|
57
|
-
console.log(`Restoring session ${filename} to ${targetPath}...`);
|
|
58
|
-
|
|
59
|
-
// Download buffer
|
|
60
|
-
const buffer = await this.p3.getObjectBuffer({
|
|
61
|
-
filename,
|
|
62
|
-
directory: '_sessionData'
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
if (!buffer || buffer.length === 0) {
|
|
66
|
-
throw new Error('Downloaded buffer is empty');
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
console.log(`Downloaded ${buffer.length} bytes. Extracting...`);
|
|
70
|
-
|
|
71
|
-
// Ensure target directory exists
|
|
72
|
-
await fs.promises.mkdir(targetPath, { recursive: true });
|
|
73
|
-
|
|
74
|
-
// Convert buffer to readable stream
|
|
75
|
-
const readStream = Readable.from(buffer);
|
|
76
|
-
|
|
77
|
-
// Decompress logic
|
|
78
|
-
// @ts-ignore
|
|
79
|
-
const zstdDecompress = zstd.ZSTDDecompress();
|
|
80
|
-
const extract = tar.extract(targetPath);
|
|
81
|
-
|
|
82
|
-
await new Promise<void>((resolve, reject) => {
|
|
83
|
-
readStream
|
|
84
|
-
.pipe(zstdDecompress)
|
|
85
|
-
.pipe(extract)
|
|
86
|
-
.on('finish', () => resolve())
|
|
87
|
-
.on('error', (err: any) => reject(err));
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
console.log('Session restored successfully.');
|
|
91
|
-
return true;
|
|
92
|
-
} catch (error) {
|
|
93
|
-
console.error('Session restore failed:', error);
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
public async getDownloadUrl(filename: string, _expiresIn: number = 60): Promise<string> {
|
|
99
|
-
// PicoS3 doesn't have a direct getSignedUrl equivalent in standard interface easily accessible purely from this wrapper usually,
|
|
100
|
-
// but let's check if we can simulate it or if p3 exposes it.
|
|
101
|
-
// Checking pico-s3 docs/source (simulated): It usually constructs a public URL.
|
|
102
|
-
// For private buckets, we might be limited here without AWS SDK.
|
|
103
|
-
// However, for this task, we'll try to return the direct link assuming logic handles auth or it's just the URL structure.
|
|
104
|
-
// FUTURE: Implement proper signed URL if needed using crypto manual signing.
|
|
105
|
-
return `https://${this.config.bucket}.s3.${this.config.region}.amazonaws.com/_sessionData/${filename}`;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
public async sessionExists(filename: string): Promise<boolean> {
|
|
109
|
-
try {
|
|
110
|
-
return await this.p3.objectExists({
|
|
111
|
-
filename,
|
|
112
|
-
directory: '_sessionData'
|
|
113
|
-
});
|
|
114
|
-
} catch (error) {
|
|
115
|
-
return false;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
public async deleteSession(filename: string): Promise<boolean> {
|
|
120
|
-
try {
|
|
121
|
-
await this.p3.deleteObject({
|
|
122
|
-
filename,
|
|
123
|
-
directory: '_sessionData'
|
|
124
|
-
});
|
|
125
|
-
return true;
|
|
126
|
-
} catch (error) {
|
|
127
|
-
console.error('Failed to delete session:', error);
|
|
128
|
-
return false;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { LocalSessionCompression } from '../src/local-compression';
|
|
2
|
-
import { S3SyncManager } from '../src/s3-sync';
|
|
3
|
-
import fs from 'fs';
|
|
4
|
-
import path from 'path';
|
|
5
|
-
|
|
6
|
-
async function validateSessionSync() {
|
|
7
|
-
console.log('Starting Phase 4 Validation: Session Sync');
|
|
8
|
-
|
|
9
|
-
const testDir = path.resolve(__dirname, 'test-session');
|
|
10
|
-
if (!fs.existsSync(testDir)) fs.mkdirSync(testDir, { recursive: true });
|
|
11
|
-
|
|
12
|
-
// Create dummy subdirectories
|
|
13
|
-
fs.mkdirSync(path.join(testDir, 'Default', 'IndexedDB'), { recursive: true });
|
|
14
|
-
|
|
15
|
-
// Create dummy session data
|
|
16
|
-
fs.writeFileSync(path.join(testDir, 'Default', 'session.lock'), 'dummy-lock');
|
|
17
|
-
fs.writeFileSync(path.join(testDir, 'Default', 'IndexedDB', 'dummy.ldb'), 'dummy-db-content');
|
|
18
|
-
|
|
19
|
-
console.log('1. Testing Local Compression...');
|
|
20
|
-
const compressor = new LocalSessionCompression({
|
|
21
|
-
sessionPath: testDir,
|
|
22
|
-
outputPath: path.join(__dirname, 'test-session.zst'),
|
|
23
|
-
intervalMs: 1000
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
// Manually trigger compression
|
|
27
|
-
await compressor.compress();
|
|
28
|
-
|
|
29
|
-
if (fs.existsSync(path.join(__dirname, 'test-session.zst'))) {
|
|
30
|
-
console.log('✅ Compression successful: file created');
|
|
31
|
-
} else {
|
|
32
|
-
console.error('❌ Compression failed: no file created');
|
|
33
|
-
process.exit(1);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
console.log('2. Testing S3 Sync (Mocked by config validation)...');
|
|
37
|
-
const s3 = new S3SyncManager({
|
|
38
|
-
bucket: 'test-bucket',
|
|
39
|
-
region: 'us-east-1',
|
|
40
|
-
accessKeyId: 'test',
|
|
41
|
-
secretAccessKey: 'test',
|
|
42
|
-
endpoint: 'http://localhost:9000'
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
try {
|
|
46
|
-
// We expect this to fail connection but pass construction
|
|
47
|
-
await s3.sessionExists('test.zst');
|
|
48
|
-
} catch (e) {
|
|
49
|
-
console.log('✅ S3 Manager instantiated correctly (connection failed as expected)');
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Cleanup
|
|
53
|
-
fs.rmSync(testDir, { recursive: true, force: true });
|
|
54
|
-
fs.rmSync(path.join(__dirname, 'test-session.zst'), { force: true });
|
|
55
|
-
|
|
56
|
-
console.log('Phase 4 Validation Passed');
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
validateSessionSync();
|