@peerbit/server 5.8.2 → 5.8.3-9b0640c
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/dist/src/aws.d.ts +1 -0
- package/dist/src/aws.d.ts.map +1 -1
- package/dist/src/aws.js +3 -3
- package/dist/src/aws.js.map +1 -1
- package/dist/src/cli.d.ts.map +1 -1
- package/dist/src/cli.js +17 -5
- package/dist/src/cli.js.map +1 -1
- package/dist/src/domain.d.ts +1 -1
- package/dist/src/domain.d.ts.map +1 -1
- package/dist/src/domain.js +10 -2
- package/dist/src/domain.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +89 -89
- package/src/aws.ts +12 -3
- package/src/cli.ts +19 -7
- package/src/domain.ts +13 -1
package/package.json
CHANGED
|
@@ -1,91 +1,91 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
2
|
+
"name": "@peerbit/server",
|
|
3
|
+
"version": "5.8.3-9b0640c",
|
|
4
|
+
"author": "dao.xyz",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/dao-xyz/peerbit"
|
|
8
|
+
},
|
|
9
|
+
"license": "Apache-2.0",
|
|
10
|
+
"type": "module",
|
|
11
|
+
"sideEffects": false,
|
|
12
|
+
"bin": {
|
|
13
|
+
"peerbit": "./dist/src/bin.js"
|
|
14
|
+
},
|
|
15
|
+
"module": "dist/src/index.js",
|
|
16
|
+
"types": "dist/src/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
"import": "./dist/src/index.js"
|
|
19
|
+
},
|
|
20
|
+
"browser": {
|
|
21
|
+
"./dist/src/server.js": "./dist/src/server.browser.js",
|
|
22
|
+
"./server.js": "./dist/src/server.browser.js",
|
|
23
|
+
"./dist/src/config.js": "./dist/src/config.browser.js",
|
|
24
|
+
"./config.js": "./dist/src/config.browser.js",
|
|
25
|
+
"./dist/src/remotes.js": "./dist/src/remotes.browser.js",
|
|
26
|
+
"./remotes.js": "./dist/src/remotes.browser.js",
|
|
27
|
+
"./dist/src/docker.js": "./dist/src/docker.browser.js",
|
|
28
|
+
"./docker.js": "./dist/src/docker.browser.js",
|
|
29
|
+
"./dist/src/aws.js": "./dist/src/aws.browser.js"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist",
|
|
33
|
+
"src",
|
|
34
|
+
"src/nginx-template.conf",
|
|
35
|
+
"!src/test",
|
|
36
|
+
"!src/**/__tests__",
|
|
37
|
+
"!lib/**/__tests__",
|
|
38
|
+
"patches",
|
|
39
|
+
"LICENSE"
|
|
40
|
+
],
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
},
|
|
44
|
+
"engines": {
|
|
45
|
+
"node": ">=18"
|
|
46
|
+
},
|
|
47
|
+
"eslintConfig": {
|
|
48
|
+
"extends": "peerbit",
|
|
49
|
+
"parserOptions": {
|
|
50
|
+
"project": true,
|
|
51
|
+
"sourceType": "module"
|
|
52
|
+
},
|
|
53
|
+
"ignorePatterns": [
|
|
54
|
+
"!.aegir.js",
|
|
55
|
+
"test/ts-use",
|
|
56
|
+
"*.d.ts"
|
|
57
|
+
]
|
|
58
|
+
},
|
|
59
|
+
"scripts": {
|
|
60
|
+
"clean": "shx rm -rf lib/*",
|
|
61
|
+
"build": "yarn clean && yarn build-lib && yarn build-ui",
|
|
62
|
+
"build-lib": "tsc -p tsconfig.json",
|
|
63
|
+
"build-ui": "cd ../frontend && yarn build && cd ../node",
|
|
64
|
+
"postbuild": "cp src/nginx-template.conf dist/src/ && cp -r ../frontend/dist/. dist/ui",
|
|
65
|
+
"test": "aegir test --t node",
|
|
66
|
+
"lint": "aegir lint"
|
|
67
|
+
},
|
|
68
|
+
"devDependencies": {
|
|
69
|
+
"@peerbit/test-lib": "0.0.1-9b0640c",
|
|
70
|
+
"@peerbit/test-utils": "2.2.1-9b0640c",
|
|
71
|
+
"@types/yargs": "17.0.24",
|
|
72
|
+
"aws-sdk": "^2.1259.0",
|
|
73
|
+
"dotenv": "^16.1.4",
|
|
74
|
+
"@types/tmp": "^0.2.3",
|
|
75
|
+
"@types/tar-stream": "^3.1.3",
|
|
76
|
+
"shx": "^0.3.4"
|
|
77
|
+
},
|
|
78
|
+
"dependencies": {
|
|
79
|
+
"axios": "^1.4.0",
|
|
80
|
+
"chalk": "^5.3.0",
|
|
81
|
+
"peerbit": "4.3.0-9b0640c",
|
|
82
|
+
"yargs": "^17.7.2",
|
|
83
|
+
"tar-stream": "^3.1.7",
|
|
84
|
+
"tmp": "^0.2.1",
|
|
85
|
+
"tty-table": "^4.2.1"
|
|
86
|
+
},
|
|
87
|
+
"optionalDependencies": {
|
|
88
|
+
"@aws-sdk/client-ec2": "^3.390.0",
|
|
89
|
+
"@aws-sdk/client-route-53": "^3.391.0"
|
|
90
|
+
}
|
|
91
91
|
}
|
package/src/aws.ts
CHANGED
|
@@ -52,7 +52,11 @@ export const createRecord = async (options: {
|
|
|
52
52
|
await client.send(cmd);
|
|
53
53
|
};
|
|
54
54
|
|
|
55
|
-
const setupUserData = (
|
|
55
|
+
const setupUserData = (
|
|
56
|
+
email: string,
|
|
57
|
+
grantAccess: PeerId[] = [],
|
|
58
|
+
serverVersion?: string,
|
|
59
|
+
) => {
|
|
56
60
|
const peerIdStrings = grantAccess.map((x) => x.toString());
|
|
57
61
|
|
|
58
62
|
// better-sqlite3 force use to install build-essentials for `make` command, TOOD dont bundle better-sqlite3 by default?
|
|
@@ -63,7 +67,7 @@ curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash - &&\
|
|
|
63
67
|
sudo apt-get install -y nodejs
|
|
64
68
|
sudo apt-get install -y build-essential
|
|
65
69
|
npm install -g @peerbit/server${versionSpec}
|
|
66
|
-
sudo peerbit domain test
|
|
70
|
+
sudo peerbit domain test --email ${email}
|
|
67
71
|
peerbit start ${peerIdStrings.map((key) => `--ga ${key}`)} > log.txt 2>&1 &
|
|
68
72
|
`;
|
|
69
73
|
};
|
|
@@ -106,6 +110,7 @@ export const AWS_LINUX_ARM_AMIs: Record<string, string> = {
|
|
|
106
110
|
};
|
|
107
111
|
export const launchNodes = async (properties: {
|
|
108
112
|
region?: string;
|
|
113
|
+
email: string;
|
|
109
114
|
count?: number;
|
|
110
115
|
size?: "micro" | "small" | "medium" | "large" | "xlarge" | "2xlarge";
|
|
111
116
|
namePrefix?: string;
|
|
@@ -219,7 +224,11 @@ export const launchNodes = async (properties: {
|
|
|
219
224
|
SecurityGroupIds: [securityGroupOut.GroupId!],
|
|
220
225
|
InstanceType: ("t4g." + (properties.size || "micro")) as any, // TODO types
|
|
221
226
|
UserData: Buffer.from(
|
|
222
|
-
setupUserData(
|
|
227
|
+
setupUserData(
|
|
228
|
+
properties.email,
|
|
229
|
+
properties.grantAccess,
|
|
230
|
+
properties.serverVersion,
|
|
231
|
+
),
|
|
223
232
|
).toString("base64"),
|
|
224
233
|
MinCount: count,
|
|
225
234
|
MaxCount: count,
|
package/src/cli.ts
CHANGED
|
@@ -218,6 +218,11 @@ export const cli = async (args?: string[]) => {
|
|
|
218
218
|
describe:
|
|
219
219
|
"Setup a testing domain with SSL (no guarantess on how long the domain will be available)",
|
|
220
220
|
builder: {
|
|
221
|
+
email: {
|
|
222
|
+
describe: "Email for Lets security messages",
|
|
223
|
+
type: "string",
|
|
224
|
+
demandOption: true,
|
|
225
|
+
},
|
|
221
226
|
outdir: {
|
|
222
227
|
describe: "Output path for Nginx config",
|
|
223
228
|
type: "string",
|
|
@@ -232,7 +237,7 @@ export const cli = async (args?: string[]) => {
|
|
|
232
237
|
},
|
|
233
238
|
handler: async (args) => {
|
|
234
239
|
const domain = await createTestDomain();
|
|
235
|
-
await startCertbot(domain, args.wait);
|
|
240
|
+
await startCertbot(domain, args.email, args.wait);
|
|
236
241
|
exit();
|
|
237
242
|
},
|
|
238
243
|
})
|
|
@@ -300,7 +305,7 @@ export const cli = async (args?: string[]) => {
|
|
|
300
305
|
}
|
|
301
306
|
: undefined,
|
|
302
307
|
});
|
|
303
|
-
await startCertbot(args.domain, args.wait);
|
|
308
|
+
await startCertbot(args.domain, args.email, args.wait);
|
|
304
309
|
exit();
|
|
305
310
|
},
|
|
306
311
|
})
|
|
@@ -371,6 +376,12 @@ export const cli = async (args?: string[]) => {
|
|
|
371
376
|
alias: "d",
|
|
372
377
|
default: getHomeConfigDir(),
|
|
373
378
|
});
|
|
379
|
+
awsArgs.option("email", {
|
|
380
|
+
describe: "Email for Let's security messages",
|
|
381
|
+
type: "string",
|
|
382
|
+
alias: "e",
|
|
383
|
+
demandOption: true,
|
|
384
|
+
});
|
|
374
385
|
awsArgs.option("server-version", {
|
|
375
386
|
describe:
|
|
376
387
|
"@peerbit/server version or tag to install on the instance (e.g. 5.7.0-58d3d09)",
|
|
@@ -380,17 +391,18 @@ export const cli = async (args?: string[]) => {
|
|
|
380
391
|
return awsArgs;
|
|
381
392
|
},
|
|
382
393
|
handler: async (args) => {
|
|
394
|
+
const self = (
|
|
395
|
+
await getKeypair(args.directory)
|
|
396
|
+
).publicKey.toPeerId();
|
|
383
397
|
const accessGrant: PeerId[] =
|
|
384
398
|
args["grant-access"]?.length > 0
|
|
385
399
|
? (args["grant-access"] as string[]).map((x) =>
|
|
386
400
|
peerIdFromString(x),
|
|
387
401
|
)
|
|
388
|
-
: [
|
|
389
|
-
|
|
390
|
-
await getKeypair(args.directory)
|
|
391
|
-
).publicKey.toPeerId(),
|
|
392
|
-
];
|
|
402
|
+
: [];
|
|
403
|
+
accessGrant.push(self);
|
|
393
404
|
const nodes = await launchNodes({
|
|
405
|
+
email: args.email as string,
|
|
394
406
|
count: args.count,
|
|
395
407
|
namePrefix: args.name,
|
|
396
408
|
region: args.region,
|
package/src/domain.ts
CHANGED
|
@@ -121,11 +121,23 @@ export const createTestDomain = async () => {
|
|
|
121
121
|
return domain;
|
|
122
122
|
};
|
|
123
123
|
|
|
124
|
+
const validateEmail = (email: any) => {
|
|
125
|
+
return String(email)
|
|
126
|
+
.toLowerCase()
|
|
127
|
+
.match(
|
|
128
|
+
/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
|
|
129
|
+
);
|
|
130
|
+
};
|
|
131
|
+
|
|
124
132
|
export const startCertbot = async (
|
|
125
133
|
domain: string,
|
|
134
|
+
email: string,
|
|
126
135
|
waitForUp = false,
|
|
127
136
|
dockerProcessName = "nginx-certbot",
|
|
128
137
|
): Promise<void> => {
|
|
138
|
+
if (!validateEmail(email)) {
|
|
139
|
+
throw new Error("Email for SSL renenewal is invalid");
|
|
140
|
+
}
|
|
129
141
|
const { installDocker, startContainer } = await import("./docker.js");
|
|
130
142
|
|
|
131
143
|
const nginxConfigPath = await getNginxFolderPath();
|
|
@@ -141,7 +153,7 @@ export const startCertbot = async (
|
|
|
141
153
|
// copy ui from node_modules to home for permission reasons (volume will not work otherwise)
|
|
142
154
|
const certbotDockerCommand = `cp -r ${uiPath} $(pwd)/ui && docker pull jonasal/nginx-certbot:latest && docker run -d --net=host \
|
|
143
155
|
--restart unless-stopped \
|
|
144
|
-
${isTest ? "--env STAGING=1" : ""}\
|
|
156
|
+
--env CERTBOT_EMAIL=${email} ${isTest ? "--env STAGING=1" : ""}\
|
|
145
157
|
-v $(pwd)/nginx_secrets:/etc/letsencrypt \
|
|
146
158
|
-v ${nginxConfigPath}:/etc/nginx/user_conf.d:ro \
|
|
147
159
|
-v $(pwd)/ui:/usr/share/nginx/html:ro \
|