// Node 22+, no dependencies. Set APP_ORIGIN and BEARER in a trusted shell. // create HOST [A|CNAME] | list | verify BINDING_ID | remove BINDING_ID const [action='list',value,recordType='A'] = process.argv.slice(2); const base = new URL((process.env.APP_ORIGIN || 'https://invalid').replace(/\/$/,'')+'/'); if (!process.env.BEARER || base.hostname === 'invalid') throw Error('Set APP_ORIGIN and BEARER.'); if (base.protocol !== 'https:' && !['localhost','127.0.0.1'].includes(base.hostname)) throw Error('Owner credentials require HTTPS.'); if (!['create','list','verify','remove'].includes(action)) throw Error('Use create, list, verify or remove.'); if (['verify','remove'].includes(action) && !/^dom_[a-f0-9]{32}$/.test(value || '')) throw Error('Supply the returned bindingId.'); const suffix = action === 'verify' ? `/${value}/verify` : action === 'remove' ? `/${value}` : ''; const response = await fetch(new URL(`api/domains${suffix}`,base),{ method:action==='list'?'GET':action==='remove'?'DELETE':'POST',redirect:'error', headers:{authorization:`Bearer ${process.env.BEARER}`,'content-type':'application/json'}, body:action==='create'?JSON.stringify({hostname:value,recordType}):undefined }); const result=await response.json();console.log(JSON.stringify(result,null,2)); if (!response.ok) process.exitCode=1;