1#!/usr/bin/env node2'use strict';34// Captures the source store's OWN configuration — business address, currency, which countries5// it sells to, whether tax is calculated — into the run's data directory.6//7// node capture-store-settings.js <projectDir>8// -> <projectDir>/data/store-settings-general.json9//10// WHY THIS IS A SCRIPT AND NOT A DISCOVERY RULE. Two independent reasons the generic sweep11// can never reach this route, each of which looks like a dead end on its own:12//13// 1. The REST index advertises only the PARAMETERIZED form `/wc/v3/settings/(?P<group>...)`,14// never the literal group route. Nothing in the generic sweep resolves a route template
49 throw new Error(`capture-store-settings: source config not found at ${configPath}`);
50 }
51 const env = readEnvFile(configPath);
52 for (const key of ['WP_BASE_URL', 'WP_USERNAME', 'WP_APPLICATION_PASSWORD']) {
53 if (!env[key]) {
54 throw new Error(`capture-store-settings: ${key} is missing from ${configPath} — the store consumer key cannot read this route, only the WordPress application password can`);
55 }
56 }
57
58 const base = env.WP_BASE_URL.replace(/\/+$/, '');
65 throw new Error(`capture-store-settings: GET ${ROUTE} returned ${response.status}${code}. If this is a 401, the run is using the WooCommerce consumer key — this route needs the WordPress application password.`);