Accounts 1.9.0, @crosscode/demo 1.0.0: messaging.get, WhatsApp opt-out, demo scenarios
Accounts 1.9.0 (one migration): - messaging.get (sealed settings) and the messaging.changed hint to products that asked, on admin or product changes - the WhatsApp opt-out for every product: whatsapp.optout, Accounts' own WAWP webhook, WhatsAppOptOut kept per number, whatsapp_opted_out in user.updated, no WhatsApp from Accounts to an opted-out person, "Turn WhatsApp back on" - demo scenarios: npm run demo -- --profile <scenario> --force replaces the church profile (with an SVG logo and icon at /api/demo-assets/) and the demo people, ids kept across loads @crosscode/demo 1.0.0 (new): the eight scenarios' churches, people and logos. crosscode script: crosscode demo <church> accounts, --scenario on every demo, Accounts installs and builds packages/demo. Checked on PostgreSQL 18: migrations, scenario loads, opt-out, npm run demo. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+53
-2
@@ -16,6 +16,11 @@ crosscode demo <church> website --profile <profile>
|
||||
bold-plant, community-family, community-town,
|
||||
clean-modern, clean-campus); a backup is taken
|
||||
first; the church's profile, settings and admins stay
|
||||
crosscode demo <church> accounts --profile <scenario> [--scenario <scenario>]
|
||||
a demo scenario's church (profile, logo, icon) and
|
||||
people in Accounts (the eight scenarios, as the
|
||||
Website's profiles); a backup is taken first;
|
||||
real people and admins stay
|
||||
crosscode env <church> <product> the product's .env values (secrets hidden)
|
||||
crosscode env <church> <product> [--file backend/.env] --set NAME=value … [--unset NAME …] [--restart]
|
||||
change values (a copy is kept; never secrets or
|
||||
@@ -91,24 +96,41 @@ cmd_restart() {
|
||||
DEMO_PROFILES="small events ministry multicampus"
|
||||
# The Website's (contracts WEBSITE_DEMO_PROFILES): two per template.
|
||||
WEBSITE_DEMO_PROFILES="heritage-parish heritage-city bold-youth bold-plant community-family community-town clean-modern clean-campus"
|
||||
# The demo scenarios (contracts agent.DEMO_SCENARIO_KEYS, 1.21.0): one per Website profile. Accounts'
|
||||
# profiles are the scenarios themselves.
|
||||
DEMO_SCENARIOS="$WEBSITE_DEMO_PROFILES"
|
||||
|
||||
# Replaces Events' data with a demo set (apps/events/backend/scripts/set-demo.js), as the site's
|
||||
# user (its .env is readable only by that user). The Hub sends it only for installs marked as demo
|
||||
# sites. Afterwards Events is reloaded: the demo switches campuses on or off.
|
||||
# `crosscode demo <church> website --profile <p>`: the Website's content instead (cmd_demo_website).
|
||||
# `crosscode demo <church> accounts --profile <scenario>`: a scenario's church and people (cmd_demo_accounts).
|
||||
# `--scenario <s>` (agent 1.7.0): part of loading that scenario; the profile must be the scenario's.
|
||||
cmd_demo() {
|
||||
local church="" product="events" profile="" email="" dir user app
|
||||
local church="" product="events" profile="" email="" scenario="" dir user app
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
--profile) [ $# -ge 2 ] || die "--profile needs a value."; profile="$2"; shift 2 ;;
|
||||
--admin-email) [ $# -ge 2 ] || die "--admin-email needs a value."; email="$2"; shift 2 ;;
|
||||
--scenario) [ $# -ge 2 ] || die "--scenario needs a value."; scenario="$2"; shift 2 ;;
|
||||
-h|--help) manage_usage; return 0 ;;
|
||||
-*) die "Unknown option $1 (crosscode help demo)." ;;
|
||||
events|website) [ -n "$church" ] || die "Name the church first (crosscode demo hope website …)."; product="$1"; shift ;;
|
||||
events|website|accounts) [ -n "$church" ] || die "Name the church first (crosscode demo hope website …)."; product="$1"; shift ;;
|
||||
*) [ -z "$church" ] || die "One church at a time."; church="$1"; shift ;;
|
||||
esac
|
||||
done
|
||||
[ -n "$church" ] || die "Name the church."
|
||||
if [ -n "$scenario" ]; then
|
||||
[[ " $DEMO_SCENARIOS " == *" $scenario "* ]] || die "--scenario: one of $DEMO_SCENARIOS."
|
||||
# Every product loads the profile named after the scenario (contracts DEMO_SCENARIOS).
|
||||
[ "$profile" = "$scenario" ] || die "--scenario $scenario loads the $scenario profile in $product, not $profile."
|
||||
fi
|
||||
if [ "$product" = accounts ]; then
|
||||
[[ " $DEMO_SCENARIOS " == *" $profile "* ]] || die "--profile: one of $DEMO_SCENARIOS."
|
||||
[ -z "$email" ] || die "--admin-email: Accounts' demo keeps every admin."
|
||||
cmd_demo_accounts "$church" "$profile"
|
||||
return
|
||||
fi
|
||||
if [ "$product" = website ]; then
|
||||
[[ " $WEBSITE_DEMO_PROFILES " == *" $profile "* ]] || die "--profile: one of $WEBSITE_DEMO_PROFILES."
|
||||
[ -z "$email" ] || die "--admin-email: the Website's demo keeps every admin."
|
||||
@@ -144,6 +166,35 @@ cmd_demo() {
|
||||
die "Events didn't answer after the reload (sudo -u $user pm2 logs)."
|
||||
}
|
||||
|
||||
# Accounts' part of a demo scenario (Accounts 1.9.0+, backend/scripts/demo.ts): the scenario's
|
||||
# church profile (with its logo and icon) and its people; real people and admins stay. Backup first;
|
||||
# Accounts tells the linked products the church changed. Loaded before the other products'.
|
||||
cmd_demo_accounts() {
|
||||
local church="$1" profile="$2" dir user app
|
||||
require_root
|
||||
load_church "$church"
|
||||
church_has_product accounts || die "$church has no Accounts."
|
||||
# shellcheck source=/dev/null
|
||||
source "$CROSSCODE_HOME/products/accounts.sh"
|
||||
dir="$(pvar accounts DIR)"
|
||||
user="$(pvar accounts USER)"
|
||||
app="$(accounts_app "$dir")"
|
||||
[ -f "$app/backend/scripts/demo.ts" ] || die "This release of Accounts ($(checkout_ref "$dir" accounts)) has no demo scenarios (1.9.0 or later has)."
|
||||
|
||||
step "Accounts: backup first"
|
||||
accounts_backup "$dir" "$user" || die "The backup failed, so the demo wasn't loaded."
|
||||
|
||||
step "Accounts: demo scenario ($profile)"
|
||||
run_as "$user" "$app/backend" npm run --silent demo -- --profile "$profile" --force ||
|
||||
die "The demo wasn't loaded (see above). If it got as far as changing anything, the backup from just now has the data from before."
|
||||
|
||||
step "Accounts: reloading PM2"
|
||||
accounts_reload "$dir" "$user"
|
||||
step "Accounts: waiting for it to answer"
|
||||
wait_for_version "$(accounts_health_url)" "$(accounts_expected_version "$dir")" 60 ||
|
||||
die "Accounts didn't answer after the reload (sudo -u $user pm2 logs)."
|
||||
}
|
||||
|
||||
# The Website's demo (Website 1.3.0+, backend/src/demo/seeds.ts): its content replaced with one of
|
||||
# the eight demo churches, keeping the church's profile, the site settings and the admins. Backup
|
||||
# first; then reloaded, so nothing cached from before is shown.
|
||||
|
||||
@@ -17,10 +17,11 @@ accounts_expected_version() {
|
||||
node -p 'require(process.argv[1]).version' "$(accounts_app "$1")/backend/package.json"
|
||||
}
|
||||
|
||||
# The shared packages Accounts is built with (contracts, auth-client for its tests, ui for its pages).
|
||||
# The shared packages Accounts is built with (contracts, auth-client for its tests, ui for its pages,
|
||||
# 1.9.0: demo for the demo scenarios).
|
||||
accounts_shared_packages() {
|
||||
local p
|
||||
for p in packages/contracts packages/ui packages/auth-client; do
|
||||
for p in packages/contracts packages/ui packages/auth-client packages/demo; do
|
||||
[ -f "$1/$p/package.json" ] && printf '%s\n' "$p"
|
||||
done
|
||||
}
|
||||
@@ -54,7 +55,7 @@ accounts_migrate() {
|
||||
|
||||
accounts_build() {
|
||||
local p
|
||||
for p in packages/contracts packages/auth-client; do
|
||||
for p in packages/contracts packages/auth-client packages/demo; do
|
||||
[ ! -f "$1/$p/package.json" ] || run_as "$2" "$1/$p" npm run build || return 1
|
||||
done
|
||||
run_as "$2" "$(accounts_app "$1")/backend" npm run build &&
|
||||
|
||||
+48
-1
@@ -19,6 +19,15 @@ setup() {
|
||||
touch "$TMP/sites/hope/events/apps/events/backend/scripts/set-demo.js"
|
||||
mkdir -p "$TMP/sites/hope/website/apps/website/backend/src/demo"
|
||||
touch "$TMP/sites/hope/website/apps/website/backend/src/demo/seeds.ts"
|
||||
mkdir -p "$TMP/sites/hope/accounts/apps/accounts/backend/scripts"
|
||||
touch "$TMP/sites/hope/accounts/apps/accounts/backend/scripts/demo.ts"
|
||||
cat > "$CROSSCODE_HOME/products/accounts.sh" <<EOF3
|
||||
accounts_app() { printf '%s/apps/accounts' "\$1"; }
|
||||
accounts_backup() { echo "backup \$2" >> "$CALLS"; [ -z "\${FAIL_BACKUP:-}" ]; }
|
||||
accounts_reload() { echo "reload \$2" >> "$CALLS"; }
|
||||
accounts_health_url() { echo http://127.0.0.1:5200/api/health; }
|
||||
accounts_expected_version() { echo 1.9.0; }
|
||||
EOF3
|
||||
cat > "$CROSSCODE_HOME/products/website.sh" <<EOF2
|
||||
website_app() { printf '%s/apps/website' "\$1"; }
|
||||
website_backup() { echo "backup \$2" >> "$CALLS"; [ -z "\${FAIL_BACKUP:-}" ]; }
|
||||
@@ -35,7 +44,7 @@ events_expected_version() { echo 2.4.1; }
|
||||
EOF
|
||||
require_root() { :; }
|
||||
load_church() { [ "$1" = hope ] || die "There's no church $1 here."; }
|
||||
church_has_product() { [ "$1" = events ] || [ "$1" = website ]; }
|
||||
church_has_product() { [ "$1" = events ] || [ "$1" = website ] || [ "$1" = accounts ]; }
|
||||
pvar() { case "$2" in DIR) echo "$TMP/sites/hope/$1" ;; USER) echo "cc-hope-$1" ;; esac; }
|
||||
checkout_ref() { echo "$2@1.0.0"; }
|
||||
wait_for_version() { echo "wait $2" >> "$CALLS"; }
|
||||
@@ -114,3 +123,41 @@ wait 1.3.0" ]
|
||||
[[ "$output" == *"no demo profiles"* ]]
|
||||
[ ! -s "$CALLS" ]
|
||||
}
|
||||
|
||||
@test "accounts: backup, then the scenario's church and people as the site's user, then a reload" {
|
||||
run cmd_demo hope accounts --profile community-family --scenario community-family
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$(cat "$CALLS")" = "backup cc-hope-accounts
|
||||
run cc-hope-accounts sites/hope/accounts/apps/accounts/backend npm run --silent demo -- --profile community-family --force
|
||||
reload cc-hope-accounts
|
||||
wait 1.9.0" ]
|
||||
}
|
||||
|
||||
@test "accounts: only a scenario, no admin email, and only a release that has scenarios" {
|
||||
run cmd_demo hope accounts --profile small
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" == *"clean-campus"* ]]
|
||||
run cmd_demo hope accounts --profile bold-youth --admin-email jane@hope.test
|
||||
[ "$status" -eq 1 ]
|
||||
rm "$TMP/sites/hope/accounts/apps/accounts/backend/scripts/demo.ts"
|
||||
run cmd_demo hope accounts --profile bold-youth
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" == *"no demo scenarios"* ]]
|
||||
[ ! -s "$CALLS" ]
|
||||
}
|
||||
|
||||
@test "--scenario: a known one, and the profile must be the scenario's" {
|
||||
run cmd_demo hope website --profile bold-plant --scenario bold-youth
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" == *"loads the bold-youth profile"* ]]
|
||||
run cmd_demo hope accounts --profile bold-youth --scenario nowhere
|
||||
[ "$status" -eq 1 ]
|
||||
run cmd_demo hope website --profile bold-youth --scenario bold-youth
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
||||
@test "a failed Accounts demo isn't followed by a reload" {
|
||||
FAIL_SEED=1 run cmd_demo hope accounts --profile clean-modern
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$(cat "$CALLS")" != *"reload"* ]]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user