diff --git a/scripts/welcome.js b/scripts/welcome.js index de03339b..6d487950 100755 --- a/scripts/welcome.js +++ b/scripts/welcome.js @@ -19,10 +19,16 @@ if (!FETCH_AFTER) { usage() } +const SN_API_KEY = process.env.SN_API_KEY +if (!SN_API_KEY) { + console.log('SN_API_KEY must be set in environment') + process.exit(1) +} + async function gql (query, variables = {}) { const response = await fetch(`${SN_API_URL}/api/graphql`, { method: 'POST', - headers: { 'Content-Type': 'application/json' }, + headers: { 'Content-Type': 'application/json', 'x-api-key': SN_API_KEY }, body: JSON.stringify({ query, variables }) }) @@ -38,6 +44,31 @@ async function gql (query, variables = {}) { return json.data } +async function assertSettings () { + const { me } = await gql(` + query me { + me { + id + name + privates { + wildWestMode + satsFilter + } + } + } + `) + + console.log(`> logged in as @${me.name}`) + + if (!me.privates.wildWestMode) { + throw new Error('wild west mode must be enabled') + } + + if (me.privates.satsFilter !== 0) { + throw new Error('sats filter must be set to 0') + } +} + function fetchRecentBios () { // fetch all recent bios. we assume here there won't be more than 21 // since the last bio we already included in a post as defined by FETCH_AFTER. @@ -154,7 +185,8 @@ async function fetchUserItems (name) { return data.items.items } -fetchRecentBios() +assertSettings() + .then(fetchRecentBios) .then(data => filterBios(data.items.items)) .then(populate) .then(printTable)