nightpay 0.3.11 → 0.4.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.

Potentially problematic release.


This version of nightpay might be problematic. Click here for more details.

@@ -1,237 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
-
4
- usage() {
5
- cat <<'EOF'
6
- Usage:
7
- bash scripts/server-sync-start.sh \
8
- --host <hostname-or-ip> \
9
- --ssh-key <path-to-private-key> \
10
- [--remote-dir /opt/nightpay] \
11
- [--site-url https://board.nightpay.dev] \
12
- [--api-url https://api.nightpay.dev] \
13
- [--bridge-url https://bridge.nightpay.dev] \
14
- [--skip-install] \
15
- [--require-onchain]
16
-
17
- What this script does:
18
- 1) Verifies SSH access and server architecture.
19
- 2) Backs up remote env files with a timestamp.
20
- 3) Syncs this repo to the server.
21
- 4) Initializes/starts NightPay services.
22
- 5) Runs doctor and health checks (Masumi local + public URLs).
23
- EOF
24
- }
25
-
26
- HOST=""
27
- SSH_KEY=""
28
- REMOTE_DIR="/opt/nightpay"
29
- SKIP_INSTALL=0
30
- SITE_URL="https://board.nightpay.dev"
31
- API_URL="https://api.nightpay.dev"
32
- BRIDGE_URL="https://bridge.nightpay.dev"
33
- REQUIRE_ONCHAIN=0
34
-
35
- while [[ $# -gt 0 ]]; do
36
- case "$1" in
37
- --host)
38
- HOST="${2:-}"
39
- shift 2
40
- ;;
41
- --ssh-key)
42
- SSH_KEY="${2:-}"
43
- shift 2
44
- ;;
45
- --remote-dir)
46
- REMOTE_DIR="${2:-}"
47
- shift 2
48
- ;;
49
- --site-url)
50
- SITE_URL="${2:-}"
51
- shift 2
52
- ;;
53
- --api-url)
54
- API_URL="${2:-}"
55
- shift 2
56
- ;;
57
- --bridge-url)
58
- BRIDGE_URL="${2:-}"
59
- shift 2
60
- ;;
61
- --skip-install)
62
- SKIP_INSTALL=1
63
- shift 1
64
- ;;
65
- --require-onchain)
66
- REQUIRE_ONCHAIN=1
67
- shift 1
68
- ;;
69
- -h|--help)
70
- usage
71
- exit 0
72
- ;;
73
- *)
74
- echo "ERROR: unknown arg $1" >&2
75
- usage
76
- exit 1
77
- ;;
78
- esac
79
- done
80
-
81
- if [[ -z "$HOST" || -z "$SSH_KEY" ]]; then
82
- usage
83
- exit 1
84
- fi
85
-
86
- if [[ ! -f "$SSH_KEY" ]]; then
87
- echo "ERROR: SSH key not found: $SSH_KEY" >&2
88
- exit 1
89
- fi
90
-
91
- ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
92
- SSH_OPTS=(
93
- -i "$SSH_KEY"
94
- -o BatchMode=yes
95
- -o StrictHostKeyChecking=accept-new
96
- -o ConnectTimeout=20
97
- -o ServerAliveInterval=15
98
- -o ServerAliveCountMax=4
99
- )
100
-
101
- run_ssh() {
102
- local remote_cmd="$1"
103
- ssh "${SSH_OPTS[@]}" "root@${HOST}" "$remote_cmd"
104
- }
105
-
106
- echo "[1/6] Verify SSH connectivity..."
107
- run_ssh "echo connected: \$(hostname)"
108
-
109
- echo "[2/6] Verify server architecture..."
110
- ARCH="$(run_ssh "uname -m")"
111
- if [[ "$ARCH" != "x86_64" ]]; then
112
- echo "ERROR: expected x86_64 server for Masumi compatibility; found: $ARCH" >&2
113
- exit 1
114
- fi
115
-
116
- echo "[3/6] Backup remote env files..."
117
- run_ssh "\
118
- set -euo pipefail; \
119
- mkdir -p '${REMOTE_DIR}/.backups'; \
120
- ts=\$(date +%Y%m%d-%H%M%S); \
121
- for f in '${REMOTE_DIR}/.agent-playground.env' '${REMOTE_DIR}/.env' '/opt/masumi-services-dev-quickstart/.env'; do \
122
- if [[ -f \"\$f\" ]]; then cp \"\$f\" '${REMOTE_DIR}/.backups/'\"\$(basename \"\$f\")\"'.'\"\$ts\"; fi; \
123
- done; \
124
- echo backup_timestamp=\$ts"
125
-
126
- echo "[4/6] Sync repo to ${HOST}:${REMOTE_DIR}..."
127
- tar \
128
- --exclude=.git \
129
- --exclude=node_modules \
130
- --exclude=ui/node_modules \
131
- --exclude=.agent-playground \
132
- --exclude=.env \
133
- --exclude=.env.* \
134
- --exclude=.private \
135
- --exclude=hetzner_* \
136
- -czf - -C "$ROOT_DIR" . \
137
- | ssh "${SSH_OPTS[@]}" "root@${HOST}" "\
138
- set -euo pipefail; \
139
- mkdir -p '${REMOTE_DIR}'; \
140
- find '${REMOTE_DIR}' -mindepth 1 -maxdepth 1 \
141
- ! -name '.backups' \
142
- ! -name '.agent-playground' \
143
- ! -name '.agent-playground.env' \
144
- ! -name '.env' \
145
- -exec rm -rf {} +; \
146
- tar -xzf - -C '${REMOTE_DIR}'; \
147
- if ! id -u deploy >/dev/null 2>&1; then useradd -m -s /bin/bash -G sudo,docker deploy; fi; \
148
- chown -R deploy:deploy '${REMOTE_DIR}'; \
149
- find '${REMOTE_DIR}' -type f -name '*.sh' -exec sed -i 's/\r$//' {} +"
150
-
151
- echo "[5/6] Install deps and start NightPay..."
152
- ssh "${SSH_OPTS[@]}" "root@${HOST}" "REMOTE_DIR='${REMOTE_DIR}' SKIP_INSTALL='${SKIP_INSTALL}' bash -s" <<'REMOTE'
153
- set -euo pipefail
154
-
155
- if [[ "$SKIP_INSTALL" != "1" ]]; then
156
- su - deploy -c "cd '$REMOTE_DIR' && npm install --no-audit --no-fund"
157
- if [[ -f "$REMOTE_DIR/ui/package.json" ]]; then
158
- su - deploy -c "cd '$REMOTE_DIR/ui' && npm install --no-audit --no-fund"
159
- else
160
- echo "WARN: $REMOTE_DIR/ui/package.json missing; skipping UI npm install."
161
- fi
162
- fi
163
-
164
- if [[ ! -f "$REMOTE_DIR/.agent-playground.env" ]]; then
165
- su - deploy -c "cd '$REMOTE_DIR' && bash scripts/agent-playground-setup.sh init"
166
- fi
167
-
168
- su - deploy -c "cd '$REMOTE_DIR' && bash scripts/agent-playground-setup.sh stop || true"
169
- su - deploy -c "cd '$REMOTE_DIR' && bash scripts/agent-playground-setup.sh start"
170
- REMOTE
171
-
172
- echo "[6/6] Doctor + endpoint checks..."
173
- ssh "${SSH_OPTS[@]}" "root@${HOST}" "REMOTE_DIR='${REMOTE_DIR}' SITE_URL='${SITE_URL}' API_URL='${API_URL}' BRIDGE_URL='${BRIDGE_URL}' REQUIRE_ONCHAIN='${REQUIRE_ONCHAIN}' bash -s" <<'REMOTE'
174
- set -euo pipefail
175
-
176
- set +e
177
- su - deploy -c "cd '$REMOTE_DIR' && bash scripts/agent-playground-setup.sh doctor"
178
- doctor_exit=$?
179
- set -e
180
-
181
- echo "doctor_exit=$doctor_exit (non-zero usually means env placeholders still need to be filled)"
182
- echo "Masumi payment health (local 3001):"
183
- curl -fsS http://127.0.0.1:3001/api/v1/health || true
184
- echo
185
- echo "Masumi registry health (local 3000):"
186
- curl -fsS http://127.0.0.1:3000/api/v1/health || true
187
- echo
188
- echo "MIP availability:"
189
- curl -fsS "${API_URL%/}/availability"
190
- echo
191
- echo "UI status:"
192
- curl -sS -o /dev/null -w "%{http_code}\n" "${SITE_URL%/}/"
193
- echo "Bridge health:"
194
- bridge_health="$(curl -fsS "${BRIDGE_URL%/}/health")"
195
- echo "$bridge_health"
196
- echo "$bridge_health" | python3 - "$REQUIRE_ONCHAIN" <<'PY'
197
- import json
198
- import sys
199
-
200
- require_onchain = sys.argv[1] == "1"
201
- try:
202
- payload = json.loads(sys.stdin.read())
203
- except Exception as exc: # noqa: BLE001
204
- print(f"WARN: bridge health was not valid JSON: {exc}")
205
- sys.exit(0)
206
-
207
- status = str(payload.get("status", "")).lower()
208
- network = str(payload.get("network", "")).lower()
209
- stub = bool(payload.get("stub", False))
210
- init_error = payload.get("initError")
211
-
212
- if status != "ok":
213
- print(f"WARN: bridge status is '{status}'")
214
-
215
- if network and network != "preprod":
216
- print(f"WARN: bridge network is '{network}', expected 'preprod' until mainnet cutover")
217
-
218
- if stub:
219
- msg = "WARN: bridge is in STUB mode (Midnight on-chain not active)"
220
- if init_error:
221
- msg += f"; initError={init_error}"
222
- print(msg)
223
- if require_onchain:
224
- print("ERROR: --require-onchain set and bridge is still stub=true")
225
- sys.exit(2)
226
- else:
227
- print("OK: bridge is in on-chain mode (stub=false)")
228
- PY
229
- REMOTE
230
-
231
- echo "done."
232
- echo "next:"
233
- echo " 1) ssh -i '$SSH_KEY' root@'$HOST'"
234
- echo " 2) su - deploy && cd '$REMOTE_DIR'"
235
- echo " 3) edit .agent-playground.env with MASUMI_API_KEY / OPERATOR_ADDRESS / RECEIPT_CONTRACT_ADDRESS / BRIDGE_URL"
236
- echo " 4) bash scripts/agent-playground-setup.sh stop && bash scripts/agent-playground-setup.sh start"
237
- echo " 5) bash scripts/agent-playground-setup.sh doctor"