@pairlobby/local-server 0.0.0-stage → 0.20.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 +93 -0
- package/README.md +4 -2
- package/dist/backup.d.ts +79 -0
- package/dist/backup.d.ts.map +1 -0
- package/dist/backup.js +184 -0
- package/dist/backup.js.map +1 -0
- package/dist/check.d.ts +12 -0
- package/dist/check.d.ts.map +1 -0
- package/dist/check.js +102 -0
- package/dist/check.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/network.d.ts +23 -0
- package/dist/network.d.ts.map +1 -0
- package/dist/network.js +143 -0
- package/dist/network.js.map +1 -0
- package/dist/relay-main.d.ts +3 -0
- package/dist/relay-main.d.ts.map +1 -0
- package/dist/relay-main.js +140 -0
- package/dist/relay-main.js.map +1 -0
- package/dist/request-log.d.ts +38 -0
- package/dist/request-log.d.ts.map +1 -0
- package/dist/request-log.js +37 -0
- package/dist/request-log.js.map +1 -0
- package/dist/s3.d.ts +37 -0
- package/dist/s3.d.ts.map +1 -0
- package/dist/s3.js +140 -0
- package/dist/s3.js.map +1 -0
- package/dist/schema.d.ts +3 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +98 -0
- package/dist/schema.js.map +1 -0
- package/dist/server.d.ts +57 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +268 -0
- package/dist/server.js.map +1 -0
- package/dist/settings.d.ts +55 -0
- package/dist/settings.d.ts.map +1 -0
- package/dist/settings.js +152 -0
- package/dist/settings.js.map +1 -0
- package/dist/sqlite-store.d.ts +57 -0
- package/dist/sqlite-store.d.ts.map +1 -0
- package/dist/sqlite-store.js +331 -0
- package/dist/sqlite-store.js.map +1 -0
- package/package.json +43 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
Elastic License 2.0
|
|
2
|
+
|
|
3
|
+
URL: https://www.elastic.co/licensing/elastic-license
|
|
4
|
+
|
|
5
|
+
## Acceptance
|
|
6
|
+
|
|
7
|
+
By using the software, you agree to all of the terms and conditions below.
|
|
8
|
+
|
|
9
|
+
## Copyright License
|
|
10
|
+
|
|
11
|
+
The licensor grants you a non-exclusive, royalty-free, worldwide,
|
|
12
|
+
non-sublicensable, non-transferable license to use, copy, distribute, make
|
|
13
|
+
available, and prepare derivative works of the software, in each case subject to
|
|
14
|
+
the limitations and conditions below.
|
|
15
|
+
|
|
16
|
+
## Limitations
|
|
17
|
+
|
|
18
|
+
You may not provide the software to third parties as a hosted or managed
|
|
19
|
+
service, where the service provides users with access to any substantial set of
|
|
20
|
+
the features or functionality of the software.
|
|
21
|
+
|
|
22
|
+
You may not move, change, disable, or circumvent the license key functionality
|
|
23
|
+
in the software, and you may not remove or obscure any functionality in the
|
|
24
|
+
software that is protected by the license key.
|
|
25
|
+
|
|
26
|
+
You may not alter, remove, or obscure any licensing, copyright, or other notices
|
|
27
|
+
of the licensor in the software. Any use of the licensor’s trademarks is subject
|
|
28
|
+
to applicable law.
|
|
29
|
+
|
|
30
|
+
## Patents
|
|
31
|
+
|
|
32
|
+
The licensor grants you a license, under any patent claims the licensor can
|
|
33
|
+
license, or becomes able to license, to make, have made, use, sell, offer for
|
|
34
|
+
sale, import and have imported the software, in each case subject to the
|
|
35
|
+
limitations and conditions in this license. This license does not cover any
|
|
36
|
+
patent claims that you cause to be infringed by modifications or additions to
|
|
37
|
+
the software. If you or your company make any written claim that the software
|
|
38
|
+
infringes or contributes to infringement of any patent, your patent license for
|
|
39
|
+
the software granted under these terms ends immediately. If your company makes
|
|
40
|
+
such a claim, your patent license ends immediately for work on behalf of your
|
|
41
|
+
company.
|
|
42
|
+
|
|
43
|
+
## Notices
|
|
44
|
+
|
|
45
|
+
You must ensure that anyone who gets a copy of any part of the software from you
|
|
46
|
+
also gets a copy of these terms.
|
|
47
|
+
|
|
48
|
+
If you modify the software, you must include in any modified copies of the
|
|
49
|
+
software prominent notices stating that you have modified the software.
|
|
50
|
+
|
|
51
|
+
## No Other Rights
|
|
52
|
+
|
|
53
|
+
These terms do not imply any licenses other than those expressly granted in
|
|
54
|
+
these terms.
|
|
55
|
+
|
|
56
|
+
## Termination
|
|
57
|
+
|
|
58
|
+
If you use the software in violation of these terms, such use is not licensed,
|
|
59
|
+
and your licenses will automatically terminate. If the licensor provides you
|
|
60
|
+
with a notice of your violation, and you cease all violation of this license no
|
|
61
|
+
later than 30 days after you receive that notice, your licenses will be
|
|
62
|
+
reinstated retroactively. However, if you violate these terms after such
|
|
63
|
+
reinstatement, any additional violation of these terms will cause your licenses
|
|
64
|
+
to terminate automatically and permanently.
|
|
65
|
+
|
|
66
|
+
## No Liability
|
|
67
|
+
|
|
68
|
+
*As far as the law allows, the software comes as is, without any warranty or
|
|
69
|
+
condition, and the licensor will not be liable to you for any damages arising
|
|
70
|
+
out of these terms or the use or nature of the software, under any kind of
|
|
71
|
+
legal claim.*
|
|
72
|
+
|
|
73
|
+
## Definitions
|
|
74
|
+
|
|
75
|
+
The **licensor** is the entity offering these terms, and the **software** is the
|
|
76
|
+
software the licensor makes available under these terms, including any portion
|
|
77
|
+
of it.
|
|
78
|
+
|
|
79
|
+
**you** refers to the individual or entity agreeing to these terms.
|
|
80
|
+
|
|
81
|
+
**your company** is any legal entity, sole proprietorship, or other kind of
|
|
82
|
+
organization that you work for, plus all organizations that have control over,
|
|
83
|
+
are under the control of, or are under common control with that
|
|
84
|
+
organization. **control** means ownership of substantially all the assets of an
|
|
85
|
+
entity, or the power to direct its management and policies by vote, contract, or
|
|
86
|
+
otherwise. Control can be direct or indirect.
|
|
87
|
+
|
|
88
|
+
**your licenses** are all the licenses granted to you for the software under
|
|
89
|
+
these terms.
|
|
90
|
+
|
|
91
|
+
**use** means anything you do with the software requiring one of your licenses.
|
|
92
|
+
|
|
93
|
+
**trademark** means trademarks, service marks, and similar rights.
|
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @pairlobby/local-server
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Part of [PairLobby](https://github.com/PairLobby/app), built from `packages/local-server` at version 0.20.0. See that repository for documentation.
|
|
4
|
+
|
|
5
|
+
Licensed under the [Elastic License 2.0](LICENSE): you may use, copy, modify and distribute it, but may not offer it to others as a hosted or managed service.
|
package/dist/backup.d.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { BackupLocation } from './settings.js';
|
|
2
|
+
import type { S3Client, S3Environment } from './s3.js';
|
|
3
|
+
/** Where copies go. Names are `rooms-<UTC time>.sqlite`, so sorting them sorts them by age. */
|
|
4
|
+
export type BackupTarget = {
|
|
5
|
+
description: string;
|
|
6
|
+
put(name: string, file: string): Promise<void>;
|
|
7
|
+
list(): Promise<string[]>;
|
|
8
|
+
/** Writes the copy to `file`. */
|
|
9
|
+
get(name: string, file: string): Promise<void>;
|
|
10
|
+
remove(name: string): Promise<void>;
|
|
11
|
+
};
|
|
12
|
+
export type BackupInfo = {
|
|
13
|
+
name: string;
|
|
14
|
+
takenAt: string;
|
|
15
|
+
};
|
|
16
|
+
export type RestoreResult = {
|
|
17
|
+
outcome: 'restored';
|
|
18
|
+
backup: BackupInfo;
|
|
19
|
+
} | {
|
|
20
|
+
outcome: 'kept-local-data';
|
|
21
|
+
} | {
|
|
22
|
+
outcome: 'no-backups';
|
|
23
|
+
};
|
|
24
|
+
export type BackupLogLine = {
|
|
25
|
+
ts: string;
|
|
26
|
+
level: 'info' | 'error';
|
|
27
|
+
event: 'backup' | 'restore';
|
|
28
|
+
name?: string;
|
|
29
|
+
bytes?: number;
|
|
30
|
+
ms?: number;
|
|
31
|
+
error?: string;
|
|
32
|
+
};
|
|
33
|
+
export type BackupScheduleOptions = {
|
|
34
|
+
target: BackupTarget;
|
|
35
|
+
/** How often to look for changes; a copy is only taken when something changed. Default one minute. */
|
|
36
|
+
intervalMs?: number;
|
|
37
|
+
/** Copies to keep; older ones are deleted after each new one. Default 48. */
|
|
38
|
+
keep?: number;
|
|
39
|
+
log?: (line: string) => void;
|
|
40
|
+
};
|
|
41
|
+
/** The store a backup schedule copies, as `SqliteRoomStore` provides it. */
|
|
42
|
+
export type BackupSource = {
|
|
43
|
+
changeCount(): number;
|
|
44
|
+
snapshot(destination: string): Promise<void>;
|
|
45
|
+
};
|
|
46
|
+
type BackupScheduleInput = BackupScheduleOptions & {
|
|
47
|
+
source: BackupSource;
|
|
48
|
+
dataFile: string;
|
|
49
|
+
now?: () => Date;
|
|
50
|
+
};
|
|
51
|
+
type RestoreInput = {
|
|
52
|
+
target: BackupTarget;
|
|
53
|
+
dataFile: string;
|
|
54
|
+
log?: (line: string) => void;
|
|
55
|
+
};
|
|
56
|
+
export type BackupSchedule = {
|
|
57
|
+
/** Takes a copy now if anything changed since the last one; null when nothing did. */
|
|
58
|
+
run(): Promise<BackupInfo | null>;
|
|
59
|
+
/** Stops the schedule after one last copy, so a relay that is shut down loses nothing. */
|
|
60
|
+
stop(): Promise<void>;
|
|
61
|
+
};
|
|
62
|
+
export declare const DEFAULT_BACKUP_INTERVAL_MS = 60000;
|
|
63
|
+
export declare const DEFAULT_BACKUP_KEEP = 48;
|
|
64
|
+
export declare function backupName(at: Date): string;
|
|
65
|
+
export declare function folderTarget(directory: string): BackupTarget;
|
|
66
|
+
/** Copies are read into memory whole to upload and download them, which suits a team relay's database. */
|
|
67
|
+
export declare function s3Target(bucket: string, prefix: string, client: S3Client): BackupTarget;
|
|
68
|
+
/** The target for a parsed location. S3 reads its region, credentials and optional endpoint from the environment. */
|
|
69
|
+
export declare function backupTarget(location: BackupLocation, environment?: S3Environment): BackupTarget;
|
|
70
|
+
/**
|
|
71
|
+
* Restores the newest sound copy when the relay has no database yet. A database already on
|
|
72
|
+
* disk always wins, since it is at least as new as any copy. A copy that fails its check is
|
|
73
|
+
* skipped for the one before it; failing to reach the target at all throws, so a relay never
|
|
74
|
+
* starts empty while its rooms sit unreachable in a backup.
|
|
75
|
+
*/
|
|
76
|
+
export declare function restoreLatest({ target, dataFile, log }: RestoreInput): Promise<RestoreResult>;
|
|
77
|
+
export declare function startBackups({ source, dataFile, target, intervalMs, keep, log, now }: BackupScheduleInput): BackupSchedule;
|
|
78
|
+
export {};
|
|
79
|
+
//# sourceMappingURL=backup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backup.d.ts","sourceRoot":"","sources":["../src/backup.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EAAC,QAAQ,EAAE,aAAa,EAAC,MAAM,SAAS,CAAC;AAErD,+FAA+F;AAC/F,MAAM,MAAM,YAAY,GAAG;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/C,IAAI,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAC1B,iCAAiC;IACjC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/C,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACvC,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAC,CAAC;AAEzD,MAAM,MAAM,aAAa,GAAG;IAAC,OAAO,EAAE,UAAU,CAAC;IAAC,MAAM,EAAE,UAAU,CAAA;CAAC,GAAG;IAAC,OAAO,EAAE,iBAAiB,CAAA;CAAC,GAAG;IAAC,OAAO,EAAE,YAAY,CAAA;CAAC,CAAC;AAE/H,MAAM,MAAM,aAAa,GAAG;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,M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AC,EAAE,EAAE,IAAI,GAAG,MAAM,CAE3C;AAOD,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,YAAY,CAkB5D;AAED,0GAA0G;AAC1G,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,GAAG,YAAY,CAoBvF;AAED,qHAAqH;AACrH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,cAAc,EAAE,WAAW,GAAE,aAA2B,GAAG,YAAY,CAO7G;AAoBD;;;;;GAKG;AACH,wBAAsB,aAAa,CAAC,EAAC,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAC,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC,CA8BjG;AAED,wBAAgB,YAAY,CAAC,EAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAuC,EAAE,IAA0B,EAAE,GAAG,EAAE,GAAsB,EAAC,EAAE,mBAAmB,GAAG,cAAc,CA4D9L"}
|
package/dist/backup.js
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
//! Copies of the relay's database in a folder or an S3 bucket, taken while it runs and
|
|
2
|
+
//! restored when it starts on an empty disk, so a replaced container keeps its rooms.
|
|
3
|
+
import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import { dirname, join } from 'node:path';
|
|
5
|
+
import { DatabaseSync } from 'node:sqlite';
|
|
6
|
+
import { s3Client } from './s3.js';
|
|
7
|
+
export const DEFAULT_BACKUP_INTERVAL_MS = 60_000;
|
|
8
|
+
export const DEFAULT_BACKUP_KEEP = 48;
|
|
9
|
+
const NAME = /^rooms-(\d{8})T(\d{6})(\d{3})Z\.sqlite$/;
|
|
10
|
+
export function backupName(at) {
|
|
11
|
+
return `rooms-${at.toISOString().replace(/[-:.]/g, '')}.sqlite`;
|
|
12
|
+
}
|
|
13
|
+
function takenAt(name) {
|
|
14
|
+
const [, day = '', time = '', millis = ''] = NAME.exec(name) ?? [];
|
|
15
|
+
return `${day.slice(0, 4)}-${day.slice(4, 6)}-${day.slice(6)}T${time.slice(0, 2)}:${time.slice(2, 4)}:${time.slice(4)}.${millis}Z`;
|
|
16
|
+
}
|
|
17
|
+
export function folderTarget(directory) {
|
|
18
|
+
return {
|
|
19
|
+
description: directory,
|
|
20
|
+
async put(name, file) {
|
|
21
|
+
mkdirSync(directory, { recursive: true });
|
|
22
|
+
copyFileSync(file, join(directory, `${name}.partial`));
|
|
23
|
+
renameSync(join(directory, `${name}.partial`), join(directory, name));
|
|
24
|
+
},
|
|
25
|
+
async list() {
|
|
26
|
+
return existsSync(directory) ? readdirSync(directory).filter((name) => NAME.test(name)) : [];
|
|
27
|
+
},
|
|
28
|
+
async get(name, file) {
|
|
29
|
+
copyFileSync(join(directory, name), file);
|
|
30
|
+
},
|
|
31
|
+
async remove(name) {
|
|
32
|
+
rmSync(join(directory, name), { force: true });
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/** Copies are read into memory whole to upload and download them, which suits a team relay's database. */
|
|
37
|
+
export function s3Target(bucket, prefix, client) {
|
|
38
|
+
return {
|
|
39
|
+
description: `s3://${bucket}/${prefix}`,
|
|
40
|
+
async put(name, file) {
|
|
41
|
+
await client.putObject(`${prefix}${name}`, readFileSync(file));
|
|
42
|
+
},
|
|
43
|
+
async list() {
|
|
44
|
+
return (await client.listKeys(prefix)).map((key) => key.slice(prefix.length)).filter((name) => NAME.test(name));
|
|
45
|
+
},
|
|
46
|
+
async get(name, file) {
|
|
47
|
+
const bytes = await client.getObject(`${prefix}${name}`);
|
|
48
|
+
if (!bytes) {
|
|
49
|
+
throw new Error(`${prefix}${name} disappeared from s3://${bucket}`);
|
|
50
|
+
}
|
|
51
|
+
writeFileSync(file, bytes);
|
|
52
|
+
},
|
|
53
|
+
async remove(name) {
|
|
54
|
+
await client.deleteObject(`${prefix}${name}`);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/** The target for a parsed location. S3 reads its region, credentials and optional endpoint from the environment. */
|
|
59
|
+
export function backupTarget(location, environment = process.env) {
|
|
60
|
+
if (location.kind === 'folder') {
|
|
61
|
+
return folderTarget(location.path);
|
|
62
|
+
}
|
|
63
|
+
const region = environment['AWS_REGION'] || environment['AWS_DEFAULT_REGION'] || 'us-east-1';
|
|
64
|
+
const endpoint = environment['PAIRLOBBY_BACKUP_S3_ENDPOINT'] || undefined;
|
|
65
|
+
return s3Target(location.bucket, location.prefix, s3Client({ bucket: location.bucket, region, ...(endpoint ? { endpoint } : {}) }));
|
|
66
|
+
}
|
|
67
|
+
function logLine(log, line) {
|
|
68
|
+
log?.(JSON.stringify({ ts: new Date().toISOString(), ...line }));
|
|
69
|
+
}
|
|
70
|
+
function isRelayDatabase(file) {
|
|
71
|
+
try {
|
|
72
|
+
const db = new DatabaseSync(file, { readOnly: true });
|
|
73
|
+
try {
|
|
74
|
+
const check = db.prepare('PRAGMA quick_check').get();
|
|
75
|
+
return check?.quick_check === 'ok' && db.prepare("SELECT value FROM meta WHERE key='schema_version'").get() !== undefined;
|
|
76
|
+
}
|
|
77
|
+
finally {
|
|
78
|
+
db.close();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Restores the newest sound copy when the relay has no database yet. A database already on
|
|
87
|
+
* disk always wins, since it is at least as new as any copy. A copy that fails its check is
|
|
88
|
+
* skipped for the one before it; failing to reach the target at all throws, so a relay never
|
|
89
|
+
* starts empty while its rooms sit unreachable in a backup.
|
|
90
|
+
*/
|
|
91
|
+
export async function restoreLatest({ target, dataFile, log }) {
|
|
92
|
+
if (existsSync(dataFile)) {
|
|
93
|
+
return { outcome: 'kept-local-data' };
|
|
94
|
+
}
|
|
95
|
+
const names = (await target.list()).sort().reverse();
|
|
96
|
+
if (names.length === 0) {
|
|
97
|
+
return { outcome: 'no-backups' };
|
|
98
|
+
}
|
|
99
|
+
mkdirSync(dirname(dataFile), { recursive: true });
|
|
100
|
+
const partial = `${dataFile}.restore`;
|
|
101
|
+
for (const name of names) {
|
|
102
|
+
const started = Date.now();
|
|
103
|
+
await target.get(name, partial);
|
|
104
|
+
const sound = isRelayDatabase(partial);
|
|
105
|
+
// Opening the copy to check it leaves empty journal files beside it.
|
|
106
|
+
rmSync(`${partial}-wal`, { force: true });
|
|
107
|
+
rmSync(`${partial}-shm`, { force: true });
|
|
108
|
+
if (!sound) {
|
|
109
|
+
rmSync(partial, { force: true });
|
|
110
|
+
logLine(log, { level: 'error', event: 'restore', name, error: 'not a sound relay database; trying the copy before it' });
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
// A journal left by some other database would be replayed into this one.
|
|
114
|
+
rmSync(`${dataFile}-wal`, { force: true });
|
|
115
|
+
rmSync(`${dataFile}-shm`, { force: true });
|
|
116
|
+
renameSync(partial, dataFile);
|
|
117
|
+
logLine(log, { level: 'info', event: 'restore', name, bytes: statSync(dataFile).size, ms: Date.now() - started });
|
|
118
|
+
return { outcome: 'restored', backup: { name, takenAt: takenAt(name) } };
|
|
119
|
+
}
|
|
120
|
+
throw new Error(`none of the ${names.length} copies in ${target.description} is a sound relay database`);
|
|
121
|
+
}
|
|
122
|
+
export function startBackups({ source, dataFile, target, intervalMs = DEFAULT_BACKUP_INTERVAL_MS, keep = DEFAULT_BACKUP_KEEP, log, now = () => new Date() }) {
|
|
123
|
+
// What is on disk now is either new or what was just restored; only later changes need a copy.
|
|
124
|
+
let copiedAt = source.changeCount();
|
|
125
|
+
let inFlight = null;
|
|
126
|
+
let timer;
|
|
127
|
+
let stopped = false;
|
|
128
|
+
const partial = `${dataFile}.backup`;
|
|
129
|
+
const once = async () => {
|
|
130
|
+
const changes = source.changeCount();
|
|
131
|
+
if (changes === copiedAt) {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
const at = now();
|
|
135
|
+
const name = backupName(at);
|
|
136
|
+
const started = Date.now();
|
|
137
|
+
try {
|
|
138
|
+
rmSync(partial, { force: true });
|
|
139
|
+
await source.snapshot(partial);
|
|
140
|
+
const bytes = statSync(partial).size;
|
|
141
|
+
await target.put(name, partial);
|
|
142
|
+
copiedAt = changes;
|
|
143
|
+
logLine(log, { level: 'info', event: 'backup', name, bytes, ms: Date.now() - started });
|
|
144
|
+
for (const old of (await target.list()).sort().reverse().slice(keep)) {
|
|
145
|
+
await target.remove(old);
|
|
146
|
+
}
|
|
147
|
+
return { name, takenAt: at.toISOString() };
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
// The next round tries again: the change count only moves once a copy is stored.
|
|
151
|
+
logLine(log, { level: 'error', event: 'backup', name, error: error instanceof Error ? error.message : String(error) });
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
finally {
|
|
155
|
+
rmSync(partial, { force: true });
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
const run = () => {
|
|
159
|
+
inFlight ??= once().finally(() => {
|
|
160
|
+
inFlight = null;
|
|
161
|
+
});
|
|
162
|
+
return inFlight;
|
|
163
|
+
};
|
|
164
|
+
const schedule = () => {
|
|
165
|
+
if (stopped) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
timer = setTimeout(() => {
|
|
169
|
+
void run().finally(schedule);
|
|
170
|
+
}, intervalMs);
|
|
171
|
+
timer.unref();
|
|
172
|
+
};
|
|
173
|
+
schedule();
|
|
174
|
+
return {
|
|
175
|
+
run,
|
|
176
|
+
async stop() {
|
|
177
|
+
stopped = true;
|
|
178
|
+
clearTimeout(timer);
|
|
179
|
+
await inFlight;
|
|
180
|
+
await run();
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
//# sourceMappingURL=backup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backup.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AQ,GAAG,IAAI,CAAC;QACpB,CAAC,CAAC,CAAC;QACH,OAAO,QAAQ,CAAC;IACpB,CAAC,CAAC;IACF,MAAM,QAAQ,GAAG,GAAG,EAAE;QAClB,IAAI,OAAO,EAAE,CAAC;YACV,OAAO;QACX,CAAC;QACD,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;YACpB,KAAK,GAAG,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACjC,CAAC,EAAE,UAAU,CAAC,CAAC;QACf,KAAK,CAAC,KAAK,EAAE,CAAC;IAClB,CAAC,CAAC;IACF,QAAQ,EAAE,CAAC;IACX,OAAO;QACH,GAAG;QACH,KAAK,CAAC,IAAI;YACN,OAAO,GAAG,IAAI,CAAC;YACf,YAAY,CAAC,KAAK,CAAC,CAAC;YACpB,MAAM,QAAQ,CAAC;YACf,MAAM,GAAG,EAAE,CAAC;QAChB,CAAC;KACJ,CAAC;AACN,CAAC"}
|
package/dist/check.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type CheckStep = {
|
|
2
|
+
name: string;
|
|
3
|
+
ok: boolean;
|
|
4
|
+
detail: string;
|
|
5
|
+
};
|
|
6
|
+
export type CheckOptions = {
|
|
7
|
+
/** Sent when creating the room; needed when the relay requires a create token. */
|
|
8
|
+
createToken?: string;
|
|
9
|
+
fetch?: typeof fetch;
|
|
10
|
+
};
|
|
11
|
+
export declare function checkRelay(url: string, { createToken, fetch: fetcher }?: CheckOptions): Promise<CheckStep[]>;
|
|
12
|
+
//# sourceMappingURL=check.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,SAAS,GAAG;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAC,CAAC;AAEpE,MAAM,MAAM,YAAY,GAAG;IACvB,kFAAkF;IAClF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;CACxB,CAAC;AAcF,wBAAsB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,EAAC,WAAW,EAAE,KAAK,EAAE,OAAe,EAAC,GAAE,YAAiB,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,CA+F5H"}
|
package/dist/check.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
//! Checks a deployed relay from the outside, the way a client will use it: health, the
|
|
2
|
+
//! address invites show, whether creating rooms needs the token, then one throwaway room
|
|
3
|
+
//! through create, join, send, read and delete. Nothing is left behind on success.
|
|
4
|
+
import { newCredential, newId } from '@pairlobby/protocol';
|
|
5
|
+
import { CREATE_TOKEN_HEADER } from '@pairlobby/server-core';
|
|
6
|
+
export async function checkRelay(url, { createToken, fetch: fetcher = fetch } = {}) {
|
|
7
|
+
const origin = new URL(url).origin;
|
|
8
|
+
const steps = [];
|
|
9
|
+
let sequence = 0;
|
|
10
|
+
// Each request carries an id the relay writes in its request log, so a failure can be found there.
|
|
11
|
+
const call = (path, init = {}) => {
|
|
12
|
+
const headers = new Headers(init.headers);
|
|
13
|
+
headers.set('x-request-id', `pairlobby-check-${++sequence}`);
|
|
14
|
+
if (init.body) {
|
|
15
|
+
headers.set('content-type', 'application/json');
|
|
16
|
+
}
|
|
17
|
+
return fetcher(`${origin}${path}`, { ...init, headers, signal: AbortSignal.timeout(10_000) });
|
|
18
|
+
};
|
|
19
|
+
const step = (name, ok, detail) => {
|
|
20
|
+
steps.push({ name, ok, detail });
|
|
21
|
+
return ok;
|
|
22
|
+
};
|
|
23
|
+
const attempt = async (name, work) => {
|
|
24
|
+
try {
|
|
25
|
+
return await work();
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
return step(name, false, error instanceof Error ? error.message : String(error));
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const healthy = await attempt('health', async () => {
|
|
32
|
+
const response = await call('/health');
|
|
33
|
+
const body = (await response.json().catch(() => ({})));
|
|
34
|
+
return step('health', response.ok && body.service === 'pairlobby-relay' && body.ready === true, response.ok ? `PairLobby relay ${body.version ?? 'of an unknown version'}` : `GET /health answered ${response.status}; is this the relay, or something in front of it?`);
|
|
35
|
+
});
|
|
36
|
+
if (!healthy) {
|
|
37
|
+
return steps;
|
|
38
|
+
}
|
|
39
|
+
await attempt('invite address', async () => {
|
|
40
|
+
const body = (await (await call('/v1/server')).json());
|
|
41
|
+
const shown = body.shareUrls ?? [];
|
|
42
|
+
return step('invite address', shown.includes(origin), shown.includes(origin) ? `invites show ${origin}` : `invites show ${shown.join(', ') || 'no address'}; start the relay with PAIRLOBBY_PUBLIC_URL=${origin}`);
|
|
43
|
+
});
|
|
44
|
+
const credentials = { controllerCredential: newCredential('controller'), participantCredential: newCredential('participant') };
|
|
45
|
+
const createBody = JSON.stringify({ name: `relay-check-${new Date().toISOString().slice(0, 19)}`, displayName: 'relay-check', kind: 'human', ...credentials });
|
|
46
|
+
let created = null;
|
|
47
|
+
const opened = await attempt('create token', async () => {
|
|
48
|
+
const anonymous = await call('/v1/rooms', { method: 'POST', body: createBody });
|
|
49
|
+
if (anonymous.status === 201) {
|
|
50
|
+
created = (await anonymous.json());
|
|
51
|
+
return step('create token', true, 'not required: anyone who reaches this address can create rooms');
|
|
52
|
+
}
|
|
53
|
+
if (anonymous.status !== 401) {
|
|
54
|
+
return step('create token', false, `creating a room answered ${anonymous.status}`);
|
|
55
|
+
}
|
|
56
|
+
if (!createToken) {
|
|
57
|
+
step('create token', true, 'required, and the relay refused a room without it');
|
|
58
|
+
return step('create room', false, 'set PAIRLOBBY_CREATE_TOKEN to the relay\'s token to check the rest');
|
|
59
|
+
}
|
|
60
|
+
const withToken = await call('/v1/rooms', { method: 'POST', body: createBody, headers: { [CREATE_TOKEN_HEADER]: createToken } });
|
|
61
|
+
if (withToken.status !== 201) {
|
|
62
|
+
return step('create token', false, `required, and the relay answered ${withToken.status} to the token given; is it the same one?`);
|
|
63
|
+
}
|
|
64
|
+
created = (await withToken.json());
|
|
65
|
+
return step('create token', true, 'required, refused without it and accepted with it');
|
|
66
|
+
});
|
|
67
|
+
const room = created;
|
|
68
|
+
if (!opened || !room) {
|
|
69
|
+
return steps;
|
|
70
|
+
}
|
|
71
|
+
const roomPath = `/v1/rooms/${room.room.roomId}`;
|
|
72
|
+
try {
|
|
73
|
+
const joinerCredential = newCredential('participant');
|
|
74
|
+
const joined = await attempt('join', async () => {
|
|
75
|
+
const response = await call('/v1/invites/redeem', { method: 'POST', body: JSON.stringify({ code: room.invite.code, displayName: 'relay-check-joiner', kind: 'agent', participantCredential: joinerCredential, attemptId: newId('attempt'), attemptSecret: newCredential('attempt') }) });
|
|
76
|
+
return step('join', response.ok, response.ok ? 'joined with the invite code' : `redeeming the invite answered ${response.status}`);
|
|
77
|
+
});
|
|
78
|
+
if (!joined) {
|
|
79
|
+
return steps;
|
|
80
|
+
}
|
|
81
|
+
const text = `relay check ${newId('event')}`;
|
|
82
|
+
const sent = await attempt('send', async () => {
|
|
83
|
+
const response = await call(`${roomPath}/events`, { method: 'POST', body: JSON.stringify({ type: 'message', payload: { text }, idempotencyKey: newId('event') }), headers: { authorization: `Bearer ${credentials.participantCredential}` } });
|
|
84
|
+
return step('send', response.status === 201, response.status === 201 ? 'sent a message' : `sending answered ${response.status}`);
|
|
85
|
+
});
|
|
86
|
+
if (sent) {
|
|
87
|
+
await attempt('read', async () => {
|
|
88
|
+
const response = await call(`${roomPath}/events?after=0`, { headers: { authorization: `Bearer ${joinerCredential}` } });
|
|
89
|
+
const found = response.ok && (await response.json()).events.some((event) => event.type === 'message' && event.payload?.text === text);
|
|
90
|
+
return step('read', found, found ? 'the other member read it back' : `reading answered ${response.status} without the message`);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
finally {
|
|
95
|
+
await attempt('delete', async () => {
|
|
96
|
+
const response = await call(roomPath, { method: 'DELETE', headers: { authorization: `Bearer ${credentials.controllerCredential}` } });
|
|
97
|
+
return step('delete', response.status === 204, response.status === 204 ? 'deleted the test room' : `deleting the test room answered ${response.status}; it stays on the relay`);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
return steps;
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=check.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check.js","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":"AAAA,uFAAuF;AACvF,yFAAyF;AACzF,mFAAmF;AAEnF,OAAO,EAAC,aAAa,EAAE,KAAK,EAAC,MAAM,qBAAqB,CAAC;AAEzD,OAAO,EAAC,mBAAmB,EAAC,MAAM,wBAAwB,CAAC;AAsB3D,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,GAAW,EAAE,EAAC,WAAW,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,KAAkB,EAAE;IAClG,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC,MAAM,KAAK,GAAgB,EAAE,CAAC;IAC9B,IAAI,QAAQ,GAAG,CAAC,CAAC;IACjB,mGAAmG;IACnG,MAAM,IAAI,GAAG,CAAC,IAAY,EAAE,OAAoB,EAAE,EAAE,EAAE;QAClD,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC1C,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,mBAAmB,EAAE,QAAQ,EAAE,CAAC,CAAC;QAC7D,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YACZ,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAC;QACpD,CAAC;QACD,OAAO,OAAO,CAAC,GAAG,MAAM,GAAG,IAAI,EAAE,EAAE,EAAC,GAAG,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,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mCAAmC,QAAQ,CAAC,MAAM,yBAAyB,CAAC,CAAC;QACpL,CAAC,CAAC,CAAC;IACP,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './network.js';
|
|
2
|
+
export * from './schema.js';
|
|
3
|
+
export * from './server.js';
|
|
4
|
+
export * from './sqlite-store.js';
|
|
5
|
+
export * from './request-log.js';
|
|
6
|
+
export * from './backup.js';
|
|
7
|
+
export * from './s3.js';
|
|
8
|
+
export * from './settings.js';
|
|
9
|
+
export * from './check.js';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './network.js';
|
|
2
|
+
export * from './schema.js';
|
|
3
|
+
export * from './server.js';
|
|
4
|
+
export * from './sqlite-store.js';
|
|
5
|
+
export * from './request-log.js';
|
|
6
|
+
export * from './backup.js';
|
|
7
|
+
export * from './s3.js';
|
|
8
|
+
export * from './settings.js';
|
|
9
|
+
export * from './check.js';
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Where this device's relay accepts connections from. */
|
|
2
|
+
export type RelayNetwork = 'off' | 'tailscale' | 'lan';
|
|
3
|
+
export declare const RELAY_SERVICE = "_pairlobby._tcp.local";
|
|
4
|
+
/** Tailscale assigns addresses from 100.64.0.0/10 and fd7a:115c:a1e0::/48. */
|
|
5
|
+
export declare function isTailscaleAddress(address: string): boolean;
|
|
6
|
+
export declare function isLoopbackAddress(address: string): boolean;
|
|
7
|
+
/**
|
|
8
|
+
* This device, a private or link-local network address, or a Tailscale address:
|
|
9
|
+
* what may join a room by name when the room allows it. A request through a proxy
|
|
10
|
+
* arrives from the proxy, so a public URL in front of the relay is judged by the
|
|
11
|
+
* proxy's address; keep such rooms closed to the local network.
|
|
12
|
+
*/
|
|
13
|
+
export declare function isLocalNetworkAddress(address: string): boolean;
|
|
14
|
+
/** This machine's non-internal IPv4 addresses, optionally only its Tailscale ones. */
|
|
15
|
+
export declare function ownAddresses(tailscaleOnly?: boolean): string[];
|
|
16
|
+
/**
|
|
17
|
+
* Answers mDNS queries for PairLobby relays with this relay's port and current
|
|
18
|
+
* LAN addresses. Returns a function that stops answering.
|
|
19
|
+
*/
|
|
20
|
+
export declare function advertiseRelay(port: number): () => void;
|
|
21
|
+
/** Relay addresses announced on the local network within `timeoutMs`, as `http://ip:port` URLs. */
|
|
22
|
+
export declare function browseRelays(timeoutMs?: number, signal?: AbortSignal): Promise<string[]>;
|
|
23
|
+
//# sourceMappingURL=network.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../src/network.ts"],"names":[],"mappings":"AASA,0DAA0D;AAC1D,MAAM,MAAM,YAAY,GAAG,KAAK,GAAG,WAAW,GAAG,KAAK,CAAC;AAEvD,eAAO,MAAM,aAAa,0BAA0B,CAAC;AAMrD,8EAA8E;AAC9E,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAO3D;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAG1D;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAW9D;AAED,sFAAsF;AACtF,wBAAgB,YAAY,CAAC,aAAa,UAAQ,GAAG,MAAM,EAAE,CAE5D;AAOD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,IAAI,CA4BvD;AAED,mGAAmG;AACnG,wBAAgB,YAAY,CAAC,SAAS,SAAO,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAwDtF"}
|