@hasna/shortlinks 0.1.8 → 0.1.10
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 +4 -5
- package/dist/cli/index.js +5992 -765
- package/dist/cloud-config.d.ts +13 -0
- package/dist/cloud-sync.d.ts +28 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5310 -84
- package/dist/pg-migrate.d.ts +7 -0
- package/dist/remote-storage.d.ts +11 -0
- package/infra/aws-ec2-user-data.sh +32 -16
- package/package.json +6 -5
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class PgAdapterAsync {
|
|
2
|
+
private readonly pool;
|
|
3
|
+
constructor(connectionString: string);
|
|
4
|
+
run(sql: string, ...params: unknown[]): Promise<{
|
|
5
|
+
changes: number;
|
|
6
|
+
}>;
|
|
7
|
+
get(sql: string, ...params: unknown[]): Promise<unknown>;
|
|
8
|
+
all(sql: string, ...params: unknown[]): Promise<unknown[]>;
|
|
9
|
+
exec(sql: string): Promise<void>;
|
|
10
|
+
close(): Promise<void>;
|
|
11
|
+
}
|
|
@@ -4,9 +4,15 @@ set -euo pipefail
|
|
|
4
4
|
export AWS_REGION="${AWS_REGION:-us-east-1}"
|
|
5
5
|
export SHORTLINKS_HOME="/var/lib/shortlinks"
|
|
6
6
|
export SHORTLINKS_PACKAGE="@hasna/shortlinks@latest"
|
|
7
|
-
export RDS_SECRET_ID="
|
|
8
|
-
export RDS_HOST="
|
|
9
|
-
export RDS_USERNAME="
|
|
7
|
+
export RDS_SECRET_ID="${RDS_SECRET_ID:-}"
|
|
8
|
+
export RDS_HOST="${RDS_HOST:-}"
|
|
9
|
+
export RDS_USERNAME="${RDS_USERNAME:-}"
|
|
10
|
+
export SHORTLINKS_DOMAIN="${SHORTLINKS_DOMAIN:-}"
|
|
11
|
+
|
|
12
|
+
: "${RDS_SECRET_ID:?Set RDS_SECRET_ID to the AWS Secrets Manager secret for the PostgreSQL password}"
|
|
13
|
+
: "${RDS_HOST:?Set RDS_HOST to the PostgreSQL host}"
|
|
14
|
+
: "${RDS_USERNAME:?Set RDS_USERNAME to the PostgreSQL username}"
|
|
15
|
+
: "${SHORTLINKS_DOMAIN:?Set SHORTLINKS_DOMAIN to the public host served by Caddy}"
|
|
10
16
|
|
|
11
17
|
dnf update -y
|
|
12
18
|
dnf install -y awscli jq tar gzip shadow-utils libcap
|
|
@@ -15,28 +21,27 @@ if ! id shortlinks >/dev/null 2>&1; then
|
|
|
15
21
|
useradd --system --create-home --home-dir "${SHORTLINKS_HOME}" --shell /sbin/nologin shortlinks
|
|
16
22
|
fi
|
|
17
23
|
|
|
18
|
-
install -d -o shortlinks -g shortlinks "${SHORTLINKS_HOME}/.hasna/cloud"
|
|
24
|
+
install -d -o shortlinks -g shortlinks "${SHORTLINKS_HOME}/.hasna/shortlinks/cloud"
|
|
19
25
|
install -d -o shortlinks -g shortlinks "${SHORTLINKS_HOME}/.hasna/shortlinks"
|
|
20
26
|
|
|
21
|
-
cat > "${SHORTLINKS_HOME}/.hasna/cloud/config.json" <<CLOUD_CONFIG
|
|
27
|
+
cat > "${SHORTLINKS_HOME}/.hasna/shortlinks/cloud/config.json" <<CLOUD_CONFIG
|
|
22
28
|
{
|
|
23
29
|
"rds": {
|
|
24
30
|
"host": "${RDS_HOST}",
|
|
25
31
|
"port": 5432,
|
|
26
32
|
"username": "${RDS_USERNAME}",
|
|
27
|
-
"password_env": "
|
|
33
|
+
"password_env": "SHORTLINKS_CLOUD_DATABASE_PASSWORD",
|
|
28
34
|
"ssl": true
|
|
29
35
|
},
|
|
30
36
|
"mode": "hybrid",
|
|
31
|
-
"feedback_endpoint": "https://feedback.hasna.com/api/v1/feedback",
|
|
32
37
|
"auto_sync_interval_minutes": 0,
|
|
33
38
|
"sync": {
|
|
34
39
|
"schedule_minutes": 0
|
|
35
40
|
}
|
|
36
41
|
}
|
|
37
42
|
CLOUD_CONFIG
|
|
38
|
-
chown shortlinks:shortlinks "${SHORTLINKS_HOME}/.hasna/cloud/config.json"
|
|
39
|
-
chmod 600 "${SHORTLINKS_HOME}/.hasna/cloud/config.json"
|
|
43
|
+
chown shortlinks:shortlinks "${SHORTLINKS_HOME}/.hasna/shortlinks/cloud/config.json"
|
|
44
|
+
chmod 600 "${SHORTLINKS_HOME}/.hasna/shortlinks/cloud/config.json"
|
|
40
45
|
|
|
41
46
|
su -s /bin/bash shortlinks -c 'curl -fsSL https://bun.sh/install | bash'
|
|
42
47
|
su -s /bin/bash shortlinks -c "${SHORTLINKS_HOME}/.bun/bin/bun install -g ${SHORTLINKS_PACKAGE} --no-cache"
|
|
@@ -50,14 +55,16 @@ export HOME="/var/lib/shortlinks"
|
|
|
50
55
|
export PATH="/var/lib/shortlinks/.bun/bin:/usr/local/bin:/usr/bin:/bin"
|
|
51
56
|
export NODE_TLS_REJECT_UNAUTHORIZED="0"
|
|
52
57
|
|
|
58
|
+
: "${RDS_SECRET_ID:?Set RDS_SECRET_ID to the AWS Secrets Manager secret for the PostgreSQL password}"
|
|
59
|
+
|
|
53
60
|
secret_json="$(aws secretsmanager get-secret-value \
|
|
54
61
|
--region "${AWS_REGION}" \
|
|
55
|
-
--secret-id "
|
|
62
|
+
--secret-id "${RDS_SECRET_ID}" \
|
|
56
63
|
--query SecretString \
|
|
57
64
|
--output text)"
|
|
58
65
|
|
|
59
|
-
export
|
|
60
|
-
|
|
66
|
+
export SHORTLINKS_CLOUD_DATABASE_PASSWORD
|
|
67
|
+
SHORTLINKS_CLOUD_DATABASE_PASSWORD="$(jq -r '.password' <<<"${secret_json}")"
|
|
61
68
|
|
|
62
69
|
exec "$@"
|
|
63
70
|
RUNNER
|
|
@@ -66,6 +73,15 @@ chown root:shortlinks /usr/local/bin/shortlinks-env-exec
|
|
|
66
73
|
|
|
67
74
|
su -s /bin/bash shortlinks -c 'PATH=/var/lib/shortlinks/.bun/bin:$PATH shortlinks --version'
|
|
68
75
|
|
|
76
|
+
cat > /etc/default/shortlinks <<SHORTLINKS_ENV
|
|
77
|
+
AWS_REGION=${AWS_REGION}
|
|
78
|
+
RDS_SECRET_ID=${RDS_SECRET_ID}
|
|
79
|
+
SHORTLINKS_DOMAIN=${SHORTLINKS_DOMAIN}
|
|
80
|
+
SHORTLINKS_STORE=cloud
|
|
81
|
+
SHORTLINKS_ENV
|
|
82
|
+
chmod 640 /etc/default/shortlinks
|
|
83
|
+
chown root:shortlinks /etc/default/shortlinks
|
|
84
|
+
|
|
69
85
|
caddy_version="$(curl -fsSL https://api.github.com/repos/caddyserver/caddy/releases/latest | jq -r '.tag_name // "v2.10.2"' | sed 's/^v//')"
|
|
70
86
|
case "$(uname -m)" in
|
|
71
87
|
aarch64|arm64) caddy_arch="arm64" ;;
|
|
@@ -90,8 +106,8 @@ Group=shortlinks
|
|
|
90
106
|
WorkingDirectory=/var/lib/shortlinks
|
|
91
107
|
Environment=HOME=/var/lib/shortlinks
|
|
92
108
|
Environment=PATH=/var/lib/shortlinks/.bun/bin:/usr/local/bin:/usr/bin:/bin
|
|
93
|
-
|
|
94
|
-
ExecStart=/usr/local/bin/shortlinks-env-exec shortlinks serve --cloud --host 127.0.0.1 --port 8787 --default-host
|
|
109
|
+
EnvironmentFile=/etc/default/shortlinks
|
|
110
|
+
ExecStart=/usr/local/bin/shortlinks-env-exec shortlinks serve --cloud --host 127.0.0.1 --port 8787 --default-host ${SHORTLINKS_DOMAIN}
|
|
95
111
|
Restart=always
|
|
96
112
|
RestartSec=5
|
|
97
113
|
|
|
@@ -123,8 +139,8 @@ WantedBy=multi-user.target
|
|
|
123
139
|
SERVICE
|
|
124
140
|
|
|
125
141
|
install -d /etc/caddy
|
|
126
|
-
cat > /etc/caddy/Caddyfile <<
|
|
127
|
-
|
|
142
|
+
cat > /etc/caddy/Caddyfile <<CADDY
|
|
143
|
+
${SHORTLINKS_DOMAIN} {
|
|
128
144
|
encode zstd gzip
|
|
129
145
|
reverse_proxy 127.0.0.1:8787
|
|
130
146
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hasna/shortlinks",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "CLI-only shortlink manager for custom domains, click tracking, Cloudflare setup, and
|
|
3
|
+
"version": "0.1.10",
|
|
4
|
+
"description": "CLI-only shortlink manager for custom domains, click tracking, Cloudflare setup, and repo-native cloud sync",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"SECURITY.md"
|
|
32
32
|
],
|
|
33
33
|
"scripts": {
|
|
34
|
-
"build": "rm -rf dist && bun build src/cli/index.ts --outdir dist/cli --target bun
|
|
34
|
+
"build": "rm -rf dist && bun build src/cli/index.ts --outdir dist/cli --target bun && bun build src/index.ts --outdir dist --target bun && bun build src/server.ts --outdir dist --target bun && bun build src/cloudflare.ts --outdir dist --target bun && tsc -p tsconfig.build.json --emitDeclarationOnly --outDir dist",
|
|
35
35
|
"typecheck": "tsc --noEmit",
|
|
36
36
|
"test": "bun test",
|
|
37
37
|
"dev:cli": "bun run src/cli/index.ts",
|
|
@@ -66,12 +66,13 @@
|
|
|
66
66
|
"author": "Andrei Hasna <andrei@hasna.com>",
|
|
67
67
|
"license": "Apache-2.0",
|
|
68
68
|
"dependencies": {
|
|
69
|
-
"@hasna/cloud": "^0.1.30",
|
|
70
69
|
"chalk": "^5.4.1",
|
|
71
|
-
"commander": "^13.1.0"
|
|
70
|
+
"commander": "^13.1.0",
|
|
71
|
+
"pg": "^8.13.3"
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
74
|
"@types/bun": "^1.2.4",
|
|
75
|
+
"@types/pg": "^8.11.11",
|
|
75
76
|
"typescript": "^5.7.3"
|
|
76
77
|
}
|
|
77
78
|
}
|