@hasna/shortlinks 0.1.11 → 0.1.13

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.
@@ -4,9 +4,13 @@ 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="rds!db-7a451ce6-83a9-40fa-b24a-81e5d5943511"
8
- export RDS_HOST="hasnaxyz-prod-opensource.c4limg0qgqvk.us-east-1.rds.amazonaws.com"
9
- export RDS_USERNAME="hasna_admin"
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 database_url}"
13
+ : "${SHORTLINKS_DOMAIN:?Set SHORTLINKS_DOMAIN to the public host served by Caddy}"
10
14
 
11
15
  dnf update -y
12
16
  dnf install -y awscli jq tar gzip shadow-utils libcap
@@ -15,28 +19,29 @@ if ! id shortlinks >/dev/null 2>&1; then
15
19
  useradd --system --create-home --home-dir "${SHORTLINKS_HOME}" --shell /sbin/nologin shortlinks
16
20
  fi
17
21
 
18
- install -d -o shortlinks -g shortlinks "${SHORTLINKS_HOME}/.hasna/cloud"
22
+ install -d -o shortlinks -g shortlinks "${SHORTLINKS_HOME}/.hasna/shortlinks/storage"
19
23
  install -d -o shortlinks -g shortlinks "${SHORTLINKS_HOME}/.hasna/shortlinks"
20
24
 
21
- cat > "${SHORTLINKS_HOME}/.hasna/cloud/config.json" <<CLOUD_CONFIG
25
+ if [ -n "${RDS_HOST}" ] && [ -n "${RDS_USERNAME}" ]; then
26
+ cat > "${SHORTLINKS_HOME}/.hasna/shortlinks/storage/config.json" <<CLOUD_CONFIG
22
27
  {
23
28
  "rds": {
24
29
  "host": "${RDS_HOST}",
25
30
  "port": 5432,
26
31
  "username": "${RDS_USERNAME}",
27
- "password_env": "HASNA_RDS_PASSWORD",
32
+ "password_env": "SHORTLINKS_CLOUD_DATABASE_PASSWORD",
28
33
  "ssl": true
29
34
  },
30
35
  "mode": "hybrid",
31
- "feedback_endpoint": "https://feedback.hasna.com/api/v1/feedback",
32
36
  "auto_sync_interval_minutes": 0,
33
37
  "sync": {
34
38
  "schedule_minutes": 0
35
39
  }
36
40
  }
37
41
  CLOUD_CONFIG
38
- chown shortlinks:shortlinks "${SHORTLINKS_HOME}/.hasna/cloud/config.json"
39
- chmod 600 "${SHORTLINKS_HOME}/.hasna/cloud/config.json"
42
+ chown shortlinks:shortlinks "${SHORTLINKS_HOME}/.hasna/shortlinks/storage/config.json"
43
+ chmod 600 "${SHORTLINKS_HOME}/.hasna/shortlinks/storage/config.json"
44
+ fi
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,22 @@ 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 database_url}"
59
+
53
60
  secret_json="$(aws secretsmanager get-secret-value \
54
61
  --region "${AWS_REGION}" \
55
- --secret-id "rds!db-7a451ce6-83a9-40fa-b24a-81e5d5943511" \
62
+ --secret-id "${RDS_SECRET_ID}" \
56
63
  --query SecretString \
57
64
  --output text)"
58
65
 
59
- export HASNA_RDS_PASSWORD
60
- HASNA_RDS_PASSWORD="$(jq -r '.password' <<<"${secret_json}")"
66
+ export HASNA_SHORTLINKS_DATABASE_URL
67
+ HASNA_SHORTLINKS_DATABASE_URL="$(jq -r '.database_url // empty' <<<"${secret_json}")"
68
+ if [ -n "${HASNA_SHORTLINKS_DATABASE_URL}" ]; then
69
+ export SHORTLINKS_DATABASE_URL="${HASNA_SHORTLINKS_DATABASE_URL}"
70
+ else
71
+ export SHORTLINKS_CLOUD_DATABASE_PASSWORD
72
+ SHORTLINKS_CLOUD_DATABASE_PASSWORD="$(jq -r '.password // empty' <<<"${secret_json}")"
73
+ fi
61
74
 
62
75
  exec "$@"
63
76
  RUNNER
@@ -66,6 +79,15 @@ chown root:shortlinks /usr/local/bin/shortlinks-env-exec
66
79
 
67
80
  su -s /bin/bash shortlinks -c 'PATH=/var/lib/shortlinks/.bun/bin:$PATH shortlinks --version'
68
81
 
82
+ cat > /etc/default/shortlinks <<SHORTLINKS_ENV
83
+ AWS_REGION=${AWS_REGION}
84
+ RDS_SECRET_ID=${RDS_SECRET_ID}
85
+ SHORTLINKS_DOMAIN=${SHORTLINKS_DOMAIN}
86
+ SHORTLINKS_STORE=remote
87
+ SHORTLINKS_ENV
88
+ chmod 640 /etc/default/shortlinks
89
+ chown root:shortlinks /etc/default/shortlinks
90
+
69
91
  caddy_version="$(curl -fsSL https://api.github.com/repos/caddyserver/caddy/releases/latest | jq -r '.tag_name // "v2.10.2"' | sed 's/^v//')"
70
92
  case "$(uname -m)" in
71
93
  aarch64|arm64) caddy_arch="arm64" ;;
@@ -90,8 +112,8 @@ Group=shortlinks
90
112
  WorkingDirectory=/var/lib/shortlinks
91
113
  Environment=HOME=/var/lib/shortlinks
92
114
  Environment=PATH=/var/lib/shortlinks/.bun/bin:/usr/local/bin:/usr/bin:/bin
93
- Environment=SHORTLINKS_STORE=cloud
94
- ExecStart=/usr/local/bin/shortlinks-env-exec shortlinks serve --cloud --host 127.0.0.1 --port 8787 --default-host has.na
115
+ EnvironmentFile=/etc/default/shortlinks
116
+ ExecStart=/usr/local/bin/shortlinks-env-exec shortlinks serve --remote --host 127.0.0.1 --port 8787 --default-host ${SHORTLINKS_DOMAIN}
95
117
  Restart=always
96
118
  RestartSec=5
97
119
 
@@ -123,8 +145,8 @@ WantedBy=multi-user.target
123
145
  SERVICE
124
146
 
125
147
  install -d /etc/caddy
126
- cat > /etc/caddy/Caddyfile <<'CADDY'
127
- has.na {
148
+ cat > /etc/caddy/Caddyfile <<CADDY
149
+ ${SHORTLINKS_DOMAIN} {
128
150
  encode zstd gzip
129
151
  reverse_proxy 127.0.0.1:8787
130
152
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hasna/shortlinks",
3
- "version": "0.1.11",
4
- "description": "CLI-only shortlink manager for custom domains, click tracking, Cloudflare setup, and @hasna cloud sync",
3
+ "version": "0.1.13",
4
+ "description": "CLI-only shortlink manager for custom domains, click tracking, Cloudflare setup, and repo-native storage sync",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -20,6 +20,10 @@
20
20
  "./cloudflare": {
21
21
  "types": "./dist/cloudflare.d.ts",
22
22
  "import": "./dist/cloudflare.js"
23
+ },
24
+ "./storage": {
25
+ "types": "./dist/storage.d.ts",
26
+ "import": "./dist/storage.js"
23
27
  }
24
28
  },
25
29
  "files": [
@@ -31,7 +35,7 @@
31
35
  "SECURITY.md"
32
36
  ],
33
37
  "scripts": {
34
- "build": "rm -rf dist && bun build src/cli/index.ts --outdir dist/cli --target bun --external @hasna/cloud && bun build src/index.ts --outdir dist --target bun --external @hasna/cloud && bun build src/server.ts --outdir dist --target bun --external @hasna/cloud && bun build src/cloudflare.ts --outdir dist --target bun && tsc -p tsconfig.build.json --emitDeclarationOnly --outDir dist",
38
+ "build": "rm -rf dist && bun build src/cli/index.ts --outdir dist/cli --target bun && bun build src/index.ts src/storage.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
39
  "typecheck": "tsc --noEmit",
36
40
  "test": "bun test",
37
41
  "dev:cli": "bun run src/cli/index.ts",
@@ -66,13 +70,14 @@
66
70
  "author": "Andrei Hasna <andrei@hasna.com>",
67
71
  "license": "Apache-2.0",
68
72
  "dependencies": {
69
- "@hasna/cloud": "0.1.30",
70
- "@hasna/events": "^0.1.6",
71
73
  "chalk": "^5.4.1",
72
- "commander": "^13.1.0"
74
+ "commander": "^13.1.0",
75
+ "pg": "^8.13.3",
76
+ "@hasna/events": "^0.1.6"
73
77
  },
74
78
  "devDependencies": {
75
79
  "@types/bun": "^1.2.4",
80
+ "@types/pg": "^8.11.11",
76
81
  "typescript": "^5.7.3"
77
82
  }
78
83
  }