Comparing version 0.19.0 to 0.20.0
@@ -10,4 +10,4 @@ #!/usr/bin/env node | ||
global.ponr == true | ||
? console.log(" Disconnected".green, "-", "Past point of no return, completing in background.") | ||
: console.log(" Cancelled".yellow, "-", "Upload aborted, publish not initiated.") | ||
? console.log(" Disconnected".green + "- Expected to complete.".grey) | ||
: console.log(" Aborted".yellow + " - Deployment not initiated.".grey) | ||
console.log() | ||
@@ -14,0 +14,0 @@ process.exit(1) |
@@ -9,78 +9,33 @@ var request = require("request") | ||
module.exports = function(req, next, abort){ | ||
var count = 0 | ||
var label = " password:".grey | ||
var auth = function(){ | ||
var out = req.config.output | ||
if (out) out.isTTY = false | ||
var authenticateAndSave = function(callback){ | ||
if (req.creds){ | ||
helpers.space() | ||
} | ||
helpers.trunc("Login (or create surge account) by entering email & password.".grey) | ||
helpers.space() | ||
helpers.loginForm(req, function(creds){ | ||
localCreds(req.endpoint).set(creds.email, creds.token) | ||
req.creds = creds | ||
return accountOrAuthenticate(callback) | ||
}) | ||
} | ||
req.read({ | ||
prompt: label, | ||
silent: true, | ||
edit: false, | ||
output: out, | ||
input: req.config.input | ||
}, function(err, password){ | ||
if (password === undefined) return abort("not authenticated.") | ||
helpers.fetchToken(req.argv.endpoint || req.config.endpoint || 'surge.' + req.config.platform)(req.email, password, function(err, obj){ | ||
if (err) { | ||
count++ | ||
if (err.hasOwnProperty("details") && err["details"].hasOwnProperty("email")) process.exit(1) | ||
if (count >=3) { | ||
req.read({ | ||
prompt: " forgot password?".grey, | ||
default: "yes", | ||
terminal: req.config.terminal, | ||
output: req.config.output, | ||
input: req.config.input | ||
}, function(err, reply){ | ||
if (reply == "yes" || reply == "y" || reply == "Y") { | ||
var options = { | ||
'url': url.resolve(req.endpoint, "/token/reset/" + req.email), | ||
'method': 'post' | ||
} | ||
request(options, function(e, r, obj){ | ||
if (e) throw e | ||
if (r.statusCode == 201) { | ||
console.log() | ||
console.log(" Password Recovery".yellow, "- reset instructions sent to", req.email.green) | ||
console.log() | ||
process.exit(1) | ||
} else { | ||
console.log() | ||
console.log(" Oops".red, "- something went wrong trying to reset your password.") | ||
console.log() | ||
process.exit(1) | ||
} | ||
}) | ||
} else { | ||
console.log() | ||
console.log(" Aborted".yellow, "- no password reset sent.", req.email.green) | ||
console.log() | ||
process.exit(1) | ||
} | ||
}) | ||
} else { | ||
return auth() | ||
} | ||
} else { | ||
req.creds = localCreds(req.argv.endpoint || req.config.endpoint || 'surge.' + req.config.platform).set(obj.email, obj.token) | ||
return next() | ||
} | ||
}) | ||
var accountOrAuthenticate = function(callback){ | ||
helpers.fetchAccount(req.endpoint)(req.creds.email, req.creds.token, function(error, account){ | ||
if (account){ | ||
req.account = account | ||
return callback() | ||
} else { | ||
return authenticateAndSave(callback) | ||
} | ||
}) | ||
} | ||
if (req.authed) { | ||
console.log(" token:".grey, "*****************".grey) | ||
return next() | ||
if (req.creds){ | ||
return accountOrAuthenticate(next) | ||
} else { | ||
return auth() | ||
return authenticateAndSave(next) | ||
} | ||
} |
@@ -8,4 +8,4 @@ var path = require("path") | ||
module.exports = function(req, next){ | ||
req.creds = localCreds(req.argv.endpoint || req.config.endpoint || "surge." + req.config.platform).get() | ||
req.creds = localCreds(req.endpoint).get() | ||
next() | ||
} |
@@ -5,3 +5,3 @@ var fs = require("fs") | ||
var localCreds = require("./util/creds.js") | ||
var tar = require('tar') | ||
var tar = require('tarr') | ||
var zlib = require('zlib') | ||
@@ -17,4 +17,4 @@ var fsReader = require('fstream-ignore') | ||
module.exports = function(req, next){ | ||
req.success = false; | ||
/** | ||
@@ -27,3 +27,5 @@ * Some useful metadata | ||
"file-count": req.fileCount, | ||
"project-size": req.projectSize | ||
"cmd": req.config.cmd, | ||
"project-size": req.projectSize, | ||
"timestamp": new Date().toJSON() | ||
} | ||
@@ -63,2 +65,4 @@ | ||
req.headers = headers | ||
/** | ||
@@ -76,2 +80,4 @@ * Progress Bars | ||
var tick = function(tick){ | ||
//console.log("tick", tick.toString()) | ||
if (Object.keys(progress).length > 1) global.ponr = true | ||
@@ -104,14 +110,16 @@ | ||
if (payload.hasOwnProperty("type") && payload.type === "users") { | ||
helpers.log(" users:".grey, payload.users.join(", ")) | ||
helpers.log(helpers.smart("users:").grey, payload.users.join(", ")) | ||
} else | ||
if (payload.hasOwnProperty("type") && payload.type === "collect") { | ||
var msg = " Project requires the ".blue + payload.plan.name.yellow + " plan. ".blue + ("$" + (payload.plan.amount / 100) + "/mo").yellow + " (cancel anytime).".blue | ||
//console.log("payload:collect", payload) | ||
var msg = (" " + payload.plan.name.underline + " plan requred. ").grey + ("$" + (payload.plan.amount / 100) + "/mo with a " + payload.plan.trial_period_days + " day trial").underline.grey | ||
helpers.log() | ||
if (payload.hasOwnProperty("perks")) { | ||
helpers.log(msg += " This plan provides...".blue) | ||
helpers.log(msg += "\n\n Includes...".blue) | ||
payload.perks.forEach(function(perk){ | ||
helpers.log((" - " + perk).blue) | ||
helpers.log((" - " + perk).blue) | ||
}) | ||
helpers.log() | ||
} else { | ||
@@ -121,5 +129,8 @@ helpers.log(msg) | ||
req.plan = payload.plan.name | ||
helpers.payment(req, payload["stripe_pk"], payload.card)(function(token){ | ||
//console.log(token) | ||
var uri = url.resolve(req.endpoint, req.domain + "/subscription") | ||
// can this be passed in? | ||
var uri = url.resolve(req.endpoint, "subscription") | ||
request({ | ||
@@ -134,11 +145,14 @@ uri: uri, | ||
form: { | ||
plan: payload.plan, | ||
token: token | ||
plan: payload.plan.id, | ||
token: token, | ||
timestamp: req.headers.timestamp | ||
} | ||
}, function(e,r,b){ | ||
if (r.statusCode == 201 || r.statusCode == 200) { | ||
console.log() | ||
//if (token === null) console.log() | ||
//var sub = JSON.parse(b) | ||
//console.log(" plan:".grey, sub.plan.name) | ||
//console.log("here") | ||
if (token === null) console.log() | ||
// var sub = JSON.parse(b) | ||
// console.log(" plan:".grey, sub.plan.name) | ||
} else { | ||
console.log("ERROR") | ||
} | ||
@@ -151,4 +165,5 @@ }) | ||
if (payload.hasOwnProperty("type") && payload.type === "ip") { | ||
req.success = true | ||
if (payload.data) { | ||
console.log(" IP Address:".grey, payload.data.ip) | ||
helpers.log(helpers.smart("IP:").grey + " " + payload.data.ip) | ||
} | ||
@@ -212,5 +227,5 @@ } else | ||
if (payload.data) { | ||
console.log(" plan:".grey, payload.data.plan.name) | ||
//console.log(" plan:".grey, payload.data.plan.name) | ||
} else { | ||
console.log(" plan:".grey, "Free") | ||
//console.log(" plan:".grey, "Free") | ||
} | ||
@@ -221,4 +236,4 @@ } else { | ||
var displays = { | ||
"upload": (' upload:').grey + ' [:bar] :percent, eta: :etas', | ||
"cdn": (' propagate on CDN:').grey + ' [:bar] :percent :file' | ||
"upload": helpers.smart('upload:').grey + ' [:bar] :percent eta: :etas'+ ( " (" + req.fileCount +' files, ' + req.projectSize + ' bytes)').grey, | ||
"cdn": helpers.smart('CDN:').grey + ' [:bar] :percent' | ||
} | ||
@@ -277,11 +292,24 @@ | ||
// done | ||
handshake.on("end", next) | ||
handshake.on("end", function(){ | ||
if (req.success === true){ | ||
return next() | ||
} else { | ||
helpers.log() | ||
helpers.log() | ||
helpers.log(" Error".red + " - Deployment did not succeed.".grey) | ||
helpers.log() | ||
process.exit(1) | ||
} | ||
}) | ||
handshake.on("response", function(rsp){ | ||
if (rsp.statusCode == 403) { | ||
helpers.log() | ||
if(rsp.headers.hasOwnProperty("reason")){ | ||
helpers.log(" Aborted".yellow + " - " + rsp.headers["reason"]) | ||
helpers.trunc("Aborted".yellow + " - " + rsp.headers["reason"]) | ||
} else { | ||
helpers.log(" Aborted".yellow + " - you do not have permission to publish to " + req.domain) | ||
helpers.trunc("Aborted".yellow + (" - you do not have permission to publish to " + req.domain.underline).grey) | ||
} | ||
@@ -294,5 +322,5 @@ helpers.log() | ||
if(rsp.headers.hasOwnProperty("reason")){ | ||
helpers.log(" Aborted".yellow + " - " + rsp.headers["reason"]) | ||
helpers.trunc("Aborted".yellow + " - " + rsp.headers["reason"]) | ||
} else { | ||
helpers.log(" Aborted".yellow + " - local token has expired and cleared. please try again.") | ||
helpers.trunc("Aborted".yellow + " - local token has expired and cleared. please try again.") | ||
} | ||
@@ -299,0 +327,0 @@ helpers.log() |
@@ -8,3 +8,3 @@ var helpers = require("./util/helpers") | ||
module.exports = function(req, next, abort){ | ||
var label = " domain:".grey | ||
var label = helpers.smart("domain:").grey | ||
@@ -35,5 +35,5 @@ // try { | ||
}, function(err, domain){ | ||
if (domain === undefined) return abort("Please try again with a valid domain name.") | ||
if (domain === undefined) return abort("Not initiated.".grey) | ||
if (err || !helpers.validDomain(domain)) { | ||
console.log(" ", "Please enter valid domain name…".grey) | ||
//console.log(" ", "Please enter valid domain name…".grey) | ||
return getDomain(domain) | ||
@@ -45,5 +45,4 @@ } | ||
} | ||
if (helpers.validDomain(req.domain)) { | ||
console.log(label, req.domain) | ||
helpers.log(label, req.domain) | ||
next() | ||
@@ -53,3 +52,3 @@ } else { | ||
req.domain = [moniker.choose(), req.config.platform].join(".") | ||
console.log(label, req.domain) | ||
helpers.log(label, req.domain) | ||
next() | ||
@@ -56,0 +55,0 @@ } else { |
var pattern = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i | ||
var helpers = require("./util/helpers") | ||
module.exports = function(req, next, abort){ | ||
var label = " email:".grey | ||
//var label = " email:".grey | ||
var label = helpers.smart("email:").grey | ||
if (req.authed) { | ||
console.log(label, req.creds.email) | ||
return next() | ||
@@ -20,3 +22,5 @@ } else { | ||
}, function(err, answer){ | ||
if (answer === undefined) return abort("not authenticated.") | ||
if (answer === undefined) { | ||
return abort("Not authenticated.".grey) | ||
} | ||
if (!pattern.test(answer)){ | ||
@@ -23,0 +27,0 @@ // console.log() |
@@ -7,10 +7,8 @@ var helpers = require("./util/helpers") | ||
.log() | ||
.log(" Surge".bold, "– Single-command web publishing.", ("(v" + req.pkg.version + ")"). grey) | ||
.log(" Surge".bold, "– Single-command web publishing.".grey, ("(v" + req.pkg.version + ")"). grey) | ||
.log() | ||
.log(" Usage:".grey) | ||
.log(" surge [options]") | ||
.log(" surge <project> <domain>") | ||
.log() | ||
.log(" Options:".grey) | ||
.log(" -p, --project path to projects asset directory (./)") | ||
.log(" -d, --domain domain of your project (<random>."+ req.config.platform +")") | ||
.log(" -a, --add adds user to list of collaborators (email address)") | ||
@@ -21,5 +19,2 @@ .log(" -r, --remove removes user from list of collaborators (email address)") | ||
.log() | ||
.log(" Shorthand usage:".grey) | ||
.log(" surge [project path] [domain]") | ||
.log() | ||
.log(" Additional commands:".grey) | ||
@@ -31,3 +26,8 @@ .log(" surge whoami show who you are logged in as") | ||
.log(" surge teardown tear down a published project") | ||
.log(" surge plan set account plan") | ||
.log() | ||
// .log(" Examples:".grey) | ||
// .log(" surge ./www example.com") | ||
// .log(" surge .") | ||
// .log() | ||
.log(" Guides:".grey) | ||
@@ -34,0 +34,0 @@ .log(" Getting started " + "surge.sh/help/getting-started-with-surge".underline.grey) |
@@ -22,2 +22,3 @@ module.exports = [ | ||
require("./domain"), | ||
require("./domainOrSilent"), | ||
require("./protocol"), | ||
@@ -24,0 +25,0 @@ require("./deploy"), |
module.exports = function(req, next){ | ||
if (req.status) { | ||
if (req.success === true) { | ||
console.log() | ||
console.log(" Success!".green + (" - Published to " + (req.domain).underline).grey) | ||
console.log() | ||
} else { | ||
console.log() | ||
console.log(" Success!".green + " Project is published and running at " + req.domain.green.underline) | ||
console.log("") | ||
console.log(" Error".red + " - Deployment failed. ".grey) | ||
console.log() | ||
} | ||
next() | ||
return next() | ||
} |
var url = require("url") | ||
var request = require("request") | ||
var Table = require("cli-table2") | ||
var helpers = require("./util/helpers") | ||
@@ -7,3 +9,3 @@ module.exports = function(req, next){ | ||
var options = { | ||
'url': url.resolve(req.endpoint, '/list'), | ||
'url': url.resolve(req.endpoint.format(), '/list'), | ||
'method': 'get', | ||
@@ -20,9 +22,40 @@ 'auth': { | ||
var list = JSON.parse(obj) | ||
console.log() | ||
var table = new Table({ | ||
//head: ["cmd".underline.grey, 'REV DOMAIN'.grey, 'AGE'.grey, 'MODE'.grey], | ||
chars: { 'top': '' , 'top-mid': '' , 'top-left': '' , 'top-right': '' | ||
, 'bottom': '' , 'bottom-mid': '' , 'bottom-left': '' , 'bottom-right': '' | ||
, 'left': ' ' , 'left-mid': '' , 'mid': '' , 'mid-mid': '' | ||
, 'right': '' , 'right-mid': '' , 'middle': ' ' }, | ||
style: { 'padding-left': 1, 'padding-right': 1 } | ||
}) | ||
//console.log(req) | ||
var lastcmd = "" | ||
if (list.length != 0) { | ||
list.forEach(function(project){ | ||
console.log(" " + project) | ||
var perm = project.rev ? (project.rev + " ").grey + project.domain : "" | ||
if (project.planName) { | ||
if (project.planName.indexOf("Standard") !== -1){ | ||
var pn = project.planName.grey | ||
}else{ | ||
var pn = project.planName.blue | ||
} | ||
} | ||
var row = [ | ||
perm || project.domain, | ||
project.timeAgoInWords.grey, | ||
project.cmd.grey, | ||
project.platform.grey, | ||
pn || "", | ||
//lastcmd !== project.cmd ? (project.cmd).grey : "", | ||
] | ||
table.push(row) | ||
lastcmd = project.cmd | ||
}) | ||
helpers.space() | ||
helpers.log(table.toString()) | ||
} else { | ||
console.log(" Empty".yellow, "- No Projects found.") | ||
helpers.space() | ||
helpers.trunc(("Empty").grey) | ||
} | ||
@@ -29,0 +62,0 @@ next() |
@@ -0,5 +1,6 @@ | ||
var helpers = require("./util/helpers") | ||
module.exports = function(req, next){ | ||
console.log(req.argv) | ||
console.log(req.args) | ||
next() | ||
helpers.show() | ||
return next() | ||
} |
@@ -6,3 +6,3 @@ var path = require("path") | ||
helpers.log() | ||
helpers.log(" Logged in as " + req.creds.email.green + ".") | ||
helpers.trunc( "Success".green + (" - Logged in as " + req.creds.email.underline + ".").grey) | ||
next() | ||
@@ -9,0 +9,0 @@ |
@@ -6,9 +6,9 @@ var helpers = require("./util/helpers") | ||
module.exports = function(req, next){ | ||
var creds = localCreds(req.argv.endpoint || req.config.endpoint || 'surge.' + req.config.platform).set(null) | ||
var creds = localCreds(req.endpoint).set(null) | ||
if (req.creds) { | ||
var filePath = path.join(process.env[(/^win/.test(process.platform)) ? 'USERPROFILE' : 'HOME'], ".netrc") | ||
helpers.log(" Token removed from " + filePath.grey + " file.") | ||
helpers.trunc(("Success").green + (" - Token removed from " + filePath.underline + " file.").grey) | ||
} else { | ||
helpers.log(" Not currently authenticated.") | ||
helpers.trunc("Not Authenticated.".grey) | ||
} | ||
@@ -15,0 +15,0 @@ |
@@ -30,3 +30,3 @@ | ||
helpers.log() | ||
helpers.space() | ||
if (payload.hasOwnProperty("perks")) { | ||
@@ -57,16 +57,18 @@ helpers.log(msg += " This plan provides...".blue) | ||
if (r.statusCode == 201) { | ||
if (token === null) console.log() | ||
if (token === null){ | ||
helpers.space() | ||
} | ||
var sub = JSON.parse(b) | ||
console.log(" plan:".grey, sub.plan.name) | ||
console.log() | ||
console.log((" You are now upgraded to " + sub.plan.name + "!").green) | ||
console.log() | ||
helpers.log(helpers.smart("plan:").grey + " " + sub.plan.name) | ||
helpers.space() | ||
helpers.trunc(("You are now upgraded to " + sub.plan.name + "!").green) | ||
helpers.space() | ||
} else if (r.statusCode == 200) { | ||
var sub = JSON.parse(b) | ||
console.log(" plan:".grey, sub.plan.name) | ||
console.log() | ||
console.log((" No charge created. You are already upgraded to " + sub.plan.name + "!").green) | ||
console.log() | ||
helpers.log(helpers.smart("plan:").grey + " " + sub.plan.name) | ||
helpers.space() | ||
helpers.trunc(("No charge created. You are already upgraded to " + sub.plan.name + "!").green) | ||
helpers.space() | ||
} else { | ||
console.log(r.statusCode) | ||
helpers.trunc(r.statusCode) | ||
} | ||
@@ -73,0 +75,0 @@ }) |
var fs = require("fs") | ||
var path = require("path") | ||
var tar = require('tar') | ||
var tar = require('tarr') | ||
var zlib = require('zlib') | ||
@@ -5,0 +5,0 @@ var fsReader = require('fstream-ignore') |
@@ -6,3 +6,3 @@ var path = require("path") | ||
module.exports = function(req, next, abort){ | ||
var label = " project path:".grey | ||
var label = " project:".grey | ||
@@ -14,9 +14,8 @@ if (req.project || req.argv.project || req.argv["_"][0]) { | ||
if (exists) { | ||
helpers.log(" project path:".grey, req.project) | ||
helpers.log(helpers.smart("project:").grey + " " + req.project) | ||
next() | ||
} else { | ||
helpers.log() | ||
helpers.log(" Aborted".yellow, "-", "No such file or directory.") | ||
helpers.log(" ", req.project.red) | ||
helpers.log() | ||
helpers.space() | ||
helpers.trunc("Aborted".yellow + " - No such file or directory: ".grey + req.project.red) | ||
helpers.space() | ||
process.exit(1) | ||
@@ -36,3 +35,6 @@ } | ||
}, function(err, projectPath){ | ||
if (projectPath === undefined) return abort("publishing not initiated.") | ||
if (projectPath === undefined) { | ||
return abort("Publishing not initiated.".grey) | ||
} | ||
if (!fs.existsSync(path.resolve(projectPath))){ | ||
@@ -39,0 +41,0 @@ console.log(" ", "please enter valid project path...".grey) |
@@ -21,3 +21,3 @@ var du = require("du") | ||
//process.stdout.write(" size:".grey, "checking...") | ||
process.stdout.write(" size: ".grey) | ||
//process.stdout.write(" size: ".grey) | ||
@@ -35,3 +35,3 @@ req.projectSize = 0; | ||
}).on("close", function(){ | ||
helpers.log(req.fileCount + " files,", humanFileSize(req.projectSize)) | ||
//helpers.log(req.fileCount + " files,", humanFileSize(req.projectSize)) | ||
next() | ||
@@ -38,0 +38,0 @@ }) |
@@ -12,141 +12,106 @@ var request = require("request") | ||
var upload = function(req, next, abort){ | ||
var uri = url.resolve(req.endpoint, path.join(req.domain, "ssl")) | ||
var handshake = request.put(uri, { "version" : req.pkg.version }) | ||
var uri = url.resolve(req.endpoint, path.join(req.domain, "ssl")) | ||
var handshake = request.put(uri, { "version" : req.pkg.version }) | ||
// apply basic auth | ||
handshake.auth("token", req.creds.token, true) | ||
// apply basic auth | ||
handshake.auth("token", req.creds.token, true) | ||
// catch errors | ||
handshake.on('error', function(d){ | ||
console.log(d) | ||
}) | ||
// catch errors | ||
handshake.on('error', function(d){ | ||
console.log(d) | ||
}) | ||
// split replies on new line | ||
handshake.pipe(split()) | ||
// split replies on new line | ||
handshake.pipe(split()) | ||
// output result | ||
handshake.on("data", function(data){ | ||
var payload = JSON.parse(data.toString()) | ||
if (payload.hasOwnProperty("type") && payload["type"] == "collect"){ | ||
var msg = " Project requires the ".blue + payload.plan.name.yellow + " plan. ".blue + ("$" + (payload.plan.amount / 100) + "/mo").yellow + " (cancel anytime).".blue | ||
helpers.log() | ||
if (payload.hasOwnProperty("perks")) { | ||
helpers.log(msg += " This plan provides...".blue) | ||
payload.perks.forEach(function(perk){ | ||
helpers.log((" - " + perk).blue) | ||
}) | ||
} else { | ||
helpers.log(msg) | ||
// output result | ||
handshake.on("data", function(data){ | ||
var payload = JSON.parse(data.toString()) | ||
if (payload.hasOwnProperty("type") && payload["type"] == "collect"){ | ||
var msg = " Project requires the ".blue + payload.plan.name.yellow + " plan. ".blue + ("$" + (payload.plan.amount / 100) + "/mo").yellow + " (cancel anytime).".blue | ||
helpers.log() | ||
if (payload.hasOwnProperty("perks")) { | ||
helpers.log(msg += " This plan provides...".blue) | ||
payload.perks.forEach(function(perk){ | ||
helpers.log((" - " + perk).blue) | ||
}) | ||
} else { | ||
helpers.log(msg) | ||
} | ||
helpers.payment(req, payload["stripe_pk"], payload.card)(function(token){ | ||
var uri = url.resolve(req.endpoint, req.domain + "/subscription") | ||
request({ | ||
uri: uri, | ||
method: "PUT", | ||
auth: { | ||
'user': 'token', | ||
'pass': req.creds.token, | ||
'sendImmediately': true | ||
}, | ||
form: { | ||
plan: payload.plan, | ||
token: token | ||
} | ||
helpers.payment(req, payload["stripe_pk"], payload.card)(function(token){ | ||
var uri = url.resolve(req.endpoint, req.domain + "/subscription") | ||
request({ | ||
uri: uri, | ||
method: "PUT", | ||
auth: { | ||
'user': 'token', | ||
'pass': req.creds.token, | ||
'sendImmediately': true | ||
}, | ||
form: { | ||
plan: payload.plan, | ||
token: token | ||
} | ||
}, function(e,r,b){ | ||
if (r.statusCode == 201) { | ||
//if (token === null) console.log() | ||
//next() | ||
//var sub = JSON.parse(b) | ||
//console.log(" plan:".grey, sub.plan.name) | ||
} | ||
}) | ||
}) | ||
} else if (payload.hasOwnProperty("type") && payload["type"] == "subscription"){ | ||
// if (payload.data) { | ||
// console.log(" plan:".grey, payload.data.plan.name) | ||
// } else { | ||
// console.log(" plan:".grey, "Free") | ||
// } | ||
} else if (payload.hasOwnProperty("type") && payload["type"] == "msg"){ | ||
console.log() | ||
if (payload.payload["status"] == "ok") { | ||
console.log(" Success".green, "-", payload.payload["msg"]) | ||
} else { | ||
console.log(" Error".yellow, "-", payload.payload["msg"]) | ||
}, function(e,r,b){ | ||
if (r.statusCode == 201) { | ||
//if (token === null) console.log() | ||
//next() | ||
//var sub = JSON.parse(b) | ||
//console.log(" plan:".grey, sub.plan.name) | ||
} | ||
console.log() | ||
} | ||
}) | ||
}) | ||
// done | ||
handshake.on("end", function(){ | ||
// console.log() | ||
// console.log(" Success!".green, "-", "ssl cert has been added to", req.domain) | ||
// console.log() | ||
// process.exit() | ||
}) | ||
handshake.on("response", function(rsp){ | ||
console.log() | ||
// if (rsp.statusCode == 403) { | ||
// helpers.log() | ||
// helpers.log(" Unauthorized".yellow + " - you do not have publish access to", req.domain) | ||
// helpers.log() | ||
// process.exit() | ||
// } else if (rsp.statusCode == 400) { | ||
// helpers.log() | ||
// helpers.log(" SSL Fail".red, "-", "pem file is invalid.") | ||
// helpers.log() | ||
// process.exit() | ||
// } else if (rsp.statusCode == 202) { | ||
// helpers.log() | ||
// helpers.log(" SSL Pass".green, "-", "your pem file has been added to", req.domain) | ||
// helpers.log() | ||
// process.exit() | ||
// } | ||
}) | ||
var pem = fs.createReadStream(req.pem) | ||
pem.pipe(handshake) | ||
} else if (payload.hasOwnProperty("type") && payload["type"] == "subscription"){ | ||
// if (payload.data) { | ||
// console.log(" plan:".grey, payload.data.plan.name) | ||
// } else { | ||
// console.log(" plan:".grey, "Free") | ||
// } | ||
} else if (payload.hasOwnProperty("type") && payload["type"] == "msg"){ | ||
helpers.space() | ||
if (payload.payload["status"] == "ok") { | ||
helpers.trunc("Success".green + (" - " + payload.payload["msg"]).grey) | ||
} else { | ||
helpers.trunc("Error".yellow + (" - " + payload.payload["msg"]).grey) | ||
} | ||
helpers.space() | ||
} | ||
}) | ||
var mPem = function(req, next, abort){ | ||
var label = " pem file:".grey | ||
var pemPath | ||
var getPem = function(placeholder){ | ||
req.read({ | ||
prompt: label, | ||
default: placeholder, | ||
edit: true, | ||
terminal: req.config.terminal, | ||
output: req.config.output, | ||
input: req.config.input | ||
}, function(err, pem){ | ||
if (pem === undefined) return abort("no PEM file provided") | ||
if (pem === "") return getPem() | ||
var pemPath = path.resolve(pem || "") | ||
if (!fs.existsSync(pemPath)) return getPem(pem) | ||
req.pem = pemPath | ||
return upload(req, next, abort) | ||
}) | ||
} | ||
// done | ||
handshake.on("end", function(){ | ||
// console.log() | ||
// console.log(" Success!".green, "-", "ssl cert has been added to", req.domain) | ||
// console.log() | ||
// process.exit() | ||
}) | ||
var pem = req.argv["pem"] | ||
pemPath = path.resolve(pem || "") | ||
if (pem && fs.existsSync(pemPath)) { | ||
req.pem = pemPath | ||
console.log(label, pemPath) | ||
return upload(req, next, abort) | ||
handshake.on("response", function(rsp){ | ||
if (rsp.statusCode == 403) { | ||
helpers.space() | ||
if(rsp.headers.hasOwnProperty("reason")){ | ||
helpers.trunc("Aborted".yellow + " - " + rsp.headers["reason"]) | ||
} else { | ||
return getPem() | ||
helpers.trunc("Aborted".yellow + (" - Unauthorized to aplly ssl to " + req.domain.underline).grey) | ||
} | ||
helpers.log() | ||
process.exit(1) | ||
} else if (rsp.statusCode == 401) { | ||
localCreds(req.argv.endpoint).set(null) | ||
helpers.log() | ||
if(rsp.headers.hasOwnProperty("reason")){ | ||
helpers.trunc("Aborted".yellow + " - " + rsp.headers["reason"]) | ||
} else { | ||
helpers.trunc("Aborted".yellow + " - Local token has expired. please try again.".grey) | ||
} | ||
helpers.log() | ||
process.exit(1) | ||
} | ||
}) | ||
return mPem(req, next, abort) | ||
var pem = fs.createReadStream(req.pem) | ||
pem.pipe(handshake) | ||
} |
@@ -27,15 +27,15 @@ | ||
if (r.statusCode == 200 || r.statusCode == 204 || r.statusCode == 210) { | ||
helpers.log() | ||
helpers.log(" Success".green + " - " + domain + " has been removed.") | ||
helpers.log() | ||
helpers.space() | ||
helpers.trunc("Success".green + (" - " + domain.underline + " has been removed.").grey) | ||
helpers.space() | ||
process.exit() | ||
} else if (r.statusCode == 403) { | ||
helpers.log() | ||
helpers.log(" Aborted".yellow + " - unable to remove", domain) | ||
helpers.log() | ||
helpers.space() | ||
helpers.trunc("Aborted".yellow + (" - Unable to remove " + domain.underline + ".").grey) | ||
helpers.space() | ||
process.exit(1) | ||
} else { | ||
helpers.log() | ||
helpers.space() | ||
helpers.log(obj) | ||
helpers.log() | ||
helpers.space() | ||
process.exit() | ||
@@ -42,0 +42,0 @@ } |
@@ -5,4 +5,6 @@ var path = require("path") | ||
module.exports = function(req, next){ | ||
helpers.log(" token: ".grey + req.creds.token) | ||
//console.log(req.authed) | ||
helpers.space() | ||
helpers.trunc(req.creds.token.grey) | ||
next() | ||
} |
@@ -11,2 +11,4 @@ var request = require("request") | ||
req.authed = true | ||
helpers.trunc(("As " + "brock@sintaxi.com".underline + " on " + "Student" + " plan.").grey) | ||
helpers.log() | ||
next() | ||
@@ -13,0 +15,0 @@ // helpers.fetchToken(req.argv.endpoint)("token", req.creds.token, function(err, obj){ |
@@ -9,3 +9,2 @@ var path = require("path") | ||
module.exports = function(endpoint){ | ||
var endpoint = address.parse(endpoint) | ||
var host = endpoint.host | ||
@@ -12,0 +11,0 @@ |
@@ -8,5 +8,8 @@ var prompt = require('prompt') | ||
var urlAddy = require("url-parse-as-address") | ||
var read = require("read") | ||
var isDomain = require("is-domain") | ||
var read = require("read") | ||
var isDomain = require("is-domain") | ||
var s = 0 | ||
var pkg = require("../../../package.json") | ||
exports.read = read | ||
@@ -18,2 +21,23 @@ | ||
var reset = exports.reset = function(){ | ||
s = 0 | ||
} | ||
var show = exports.show = function(){ | ||
process.stdout.write(s.toString()) | ||
} | ||
var space = exports.space = function(){ | ||
if (s === 0){ | ||
s++ | ||
console.log() | ||
} | ||
} | ||
var span = exports.gap = function(){ | ||
s = 1 | ||
} | ||
var log = exports.log = function(){ | ||
@@ -24,11 +48,26 @@ var args = Array.prototype.slice.call(arguments) | ||
console.log.apply(console, args) | ||
s = 0 | ||
return this | ||
}; | ||
exports.hr = function(){ | ||
this.log() | ||
return this | ||
var hr = exports.hr = function(){ | ||
return console.log() | ||
}; | ||
var smart = exports.smart = function(str){ | ||
var difference = 16 - str.length | ||
var rsp = "" | ||
for(var i=0; i < difference; i++){ | ||
rsp += " " | ||
} | ||
return rsp + str | ||
} | ||
var trunc = exports.trunc = function(arg){ | ||
log(" " + arg) | ||
s = 0 | ||
return this | ||
} | ||
exports.stacktrace = function(str, options){ | ||
@@ -59,6 +98,44 @@ var lineno = options.lineno || -1 | ||
var fetchAccount = exports.fetchAccount = function(endpoint){ | ||
return function(email, pass, callback){ | ||
var options = { | ||
'url': url.resolve(endpoint.format(), '/account'), | ||
'method': 'get', | ||
headers: { version: pkg.version }, | ||
'auth': { | ||
'user': "token", | ||
'pass': pass || "", | ||
'sendImmediately': true | ||
} | ||
} | ||
request(options, function(e, r, obj){ | ||
if (e) throw e | ||
if (r.statusCode == 200){ | ||
return callback(null, JSON.parse(obj)) | ||
} else if (r.statusCode == 417){ | ||
space() | ||
trunc("Aborted".yellow + " - your client requires upgrade".grey) | ||
space() | ||
process.exit(1) | ||
} else if (r.statusCode == 503){ | ||
space() | ||
trunc("Error".red + " - Deployment endpoint temporarily unreachable".grey) | ||
space() | ||
process.exit(1) | ||
}else{ | ||
return callback(JSON.parse(obj)) | ||
} | ||
}) | ||
} | ||
} | ||
var fetchToken = exports.fetchToken = function(endpoint){ | ||
return function(email, pass, callback){ | ||
var options = { | ||
'url': url.resolve(urlAddy.parse(endpoint).format(), '/token'), | ||
'url': url.resolve(endpoint.format(), '/token'), | ||
'method': 'post', | ||
@@ -71,2 +148,3 @@ 'auth': { | ||
} | ||
request(options, function(e, r, obj){ | ||
@@ -85,5 +163,5 @@ if (e) throw e | ||
try { | ||
var obj = JSON.parse(obj) | ||
var c = localCreds(endpoint).set(obj.email, obj.token.replace(os.EOL, "")) | ||
return callback(null, c) | ||
var o = JSON.parse(obj) | ||
localCreds(endpoint).set(obj.email, o.token.replace(os.EOL, "")) | ||
return callback(null, o) | ||
} catch(e){ | ||
@@ -98,31 +176,162 @@ return callback({"messages": ["password required"]}) | ||
var abort = function(msg){ | ||
console.log() | ||
console.log() | ||
console.log(" Aborted".yellow + " -", msg) | ||
console.log() | ||
process.exit(1) | ||
var pattern = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i | ||
exports.loginForm = function(req, callback){ | ||
var count = 0 | ||
var abort = function(msg){ | ||
console.log() | ||
console.log(" " + "Aborted".yellow + (" - " + msg).grey) | ||
console.log() | ||
process.exit(1) | ||
} | ||
var promptEmail = function(suggestion, cb){ | ||
req.read({ | ||
silent: false, | ||
prompt: smart("email:").grey, | ||
default: suggestion, | ||
edit: true, | ||
terminal: req.config.terminal, | ||
output: req.config.output, | ||
input: req.config.input | ||
}, function(err, answer){ | ||
if (answer === undefined) { | ||
console.log() | ||
return abort("Not authenticated.".grey) | ||
} | ||
if (!pattern.test(answer)){ | ||
return promptEmail(answer, cb) | ||
} else { | ||
req.email = answer | ||
return cb() | ||
} | ||
}) | ||
} | ||
var promptPassword = function(cb){ | ||
var out = req.config.output | ||
s = 0 | ||
if (out) out.isTTY = false | ||
read({ | ||
prompt: smart("password:").grey, | ||
silent: true, | ||
edit: false, | ||
output: out, | ||
input: req.config.input | ||
}, function(err, password){ | ||
if (password === undefined){ | ||
console.log() | ||
return abort("Not authenticated.".grey) | ||
} | ||
fetchToken(req.endpoint)(req.email, password, function(err, obj){ | ||
if (err) { | ||
count++ | ||
if (err.hasOwnProperty("details") && err["details"].hasOwnProperty("email")) process.exit(1) | ||
if (count >=3) { | ||
req.read({ | ||
prompt: smart("forgot?").grey, | ||
default: "yes", | ||
terminal: req.config.terminal, | ||
output: req.config.output, | ||
input: req.config.input | ||
}, function(err, reply){ | ||
if (reply == "yes" || reply == "y" || reply == "Y") { | ||
var options = { | ||
'url': url.resolve(req.endpoint, "/token/reset/" + req.email), | ||
'method': 'post' | ||
} | ||
request(options, function(e, r, obj){ | ||
if (e) throw e | ||
if (r.statusCode == 201) { | ||
console.log() | ||
trunc("Password Recovery".yellow + " - reset instructions sent to".grey, req.email.green) | ||
console.log() | ||
process.exit(1) | ||
} else { | ||
console.log() | ||
trunc("Oops".red + " - something went wrong trying to reset your password.".grey) | ||
console.log() | ||
process.exit(1) | ||
} | ||
}) | ||
} else { | ||
console.log() | ||
trunc("Aborted".yellow + (" - No password reset sent to " + req.email.underline + ".").grey) | ||
console.log() | ||
process.exit(1) | ||
} | ||
}) | ||
} else { | ||
return promptPassword() | ||
} | ||
} else { | ||
// req.creds = localCreds(req.argv.endpoint || req.config.endpoint || 'surge.' + req.config.platform).set(obj.email, obj.token) | ||
return callback({ | ||
email: obj.email, | ||
token: obj.token | ||
}) | ||
} | ||
}) | ||
}) | ||
} | ||
promptEmail("", function(){ | ||
promptPassword(function(token){ | ||
console.log("token", token) | ||
console.log("hi", req.email) | ||
}) | ||
}) | ||
} | ||
exports.payment = function(req, stripe_pk, existing){ | ||
var abort = function(msg){ | ||
if (req.plan){ | ||
console.log() | ||
try{ | ||
console.log(" " + "Aborted".yellow + " - You remain on the ".grey + req.subscription.plan.name.underline.grey + " plan.".grey) | ||
}catch(e) { | ||
console.log(" " + "Aborted".yellow + " - No charge processed.".grey) | ||
} | ||
} else { | ||
console.log() | ||
console.log(" " + "Aborted".yellow + " - Changed not made.".grey) | ||
} | ||
console.log() | ||
process.exit(1) | ||
} | ||
function card(cc, ep, cv, cb){ | ||
read({ | ||
silent: false, | ||
prompt: " card number:".grey, | ||
prompt: smart("card number:").grey, | ||
default: cc, | ||
edit: true, | ||
}, function(er, cc){ | ||
if (cc === undefined) return abort("Payment not received.") | ||
if (cc === undefined){ | ||
console.log() | ||
return abort("Plan not changed.") | ||
} | ||
read({ | ||
prompt: " exp (mo/yr):".grey, | ||
prompt: smart("exp (mo/yr):").grey, | ||
default: ep, | ||
edit: true, | ||
}, function(er, ep){ | ||
if (ep === undefined) return abort("Payment not received.") | ||
if (ep === undefined){ | ||
console.log() | ||
return abort("Plan not changed.") | ||
} | ||
read({ | ||
prompt: " cvc:".grey, | ||
prompt: smart("cvc:").grey, | ||
default: cv, | ||
edit: true, | ||
}, function(er, cv){ | ||
if (cv === undefined) return abort("Payment not received.") | ||
if (cv === undefined){ | ||
console.log() | ||
return abort("Plan not changed.") | ||
} | ||
request({ | ||
@@ -140,20 +349,34 @@ uri: "https://"+ stripe_pk +":@api.stripe.com/v1/tokens", | ||
}, function(e,r,b) { | ||
//console.log("POST TOKEN RSP:", r.statusCode) | ||
if (r.statusCode == 417){ | ||
console.log() | ||
console.log(" Update Required".yellow, "-", obj) | ||
console.log() | ||
space() | ||
trunc("Update Required".yellow, "-", obj) | ||
space() | ||
process.exit(1) | ||
} else if (r.statusCode == 401){ | ||
console.log(r) | ||
} else if (r.statusCode == 402){ | ||
var data = JSON.parse(b) | ||
var msg = "Card appears to be invalid" | ||
var msg | ||
if (data.hasOwnProperty("error")) | ||
msg = data["error"]["param"] + " appears to be invalid. " | ||
if (data.hasOwnProperty("error")){ | ||
msg = data["error"]["message"] | ||
// console.log(data["error"]) | ||
// if (data["error"]["param"] === "number"){ | ||
// msg = 'Invalid "card number". ' | ||
// } else if (data["error"]["param"] === "exp_year"){ | ||
// msg = 'Invalid "exp" year. Please try again.' | ||
// } else if (data["error"]["param"] === "exp_month"){ | ||
// msg = 'Invalid "exp" month. Please try again.' | ||
// } else { | ||
// msg = data["error"]["param"] + "is invalid. " | ||
// } | ||
}else{ | ||
msg = "Card appears to be invalid. Please try again." | ||
} | ||
//msg = msg.charAt(0).toUpperCase() + msg.substring(1) | ||
msg += "Please try again." | ||
msg = msg.charAt(0).toUpperCase() + msg.substring(1) | ||
log() | ||
log(" ", msg.yellow) | ||
log(" ", msg.grey) | ||
log() | ||
return card(cc, ep, cv, cb) | ||
@@ -163,2 +386,12 @@ } else if(r.statusCode == 200) { | ||
return cb(data.id) | ||
}else{ | ||
log() | ||
req.plan | ||
? log((" Enter playment info to change to the " + req.plan.underline + " plan.").grey) | ||
: log((" Default message").grey) | ||
log() | ||
return card(cc, ep, cv, cb) | ||
} | ||
@@ -173,17 +406,29 @@ }) | ||
if (existing !== null) { | ||
return function(callback){ | ||
var prompt = req.plan | ||
? (" Change to the " + req.plan.underline + " plan using " + existing.brand.underline.grey + " ending in ".grey + existing.last4.underline.grey + "?".grey).grey | ||
: (" Use " + existing.brand.underline + " ending in ".grey + existing.last4.underline.grey + "?".grey).grey | ||
read({ | ||
prompt: (" Would you like to charge " + existing.brand + " ending in " + existing.last4.yellow + "?".blue).blue, | ||
prompt: prompt, | ||
default: "yes", | ||
edit: true | ||
}, function(err, reply){ | ||
if (err) console.log(err) | ||
if (err){ | ||
console.log() | ||
return abort("whatever") | ||
} | ||
if (reply === undefined) return abort("Payment not received.") | ||
if (reply === undefined){ | ||
console.log() | ||
return abort("Plan not changed.") | ||
} | ||
if (["Y", "y", "Yes", "yes"].indexOf(reply) !== -1){ | ||
callback(null) | ||
return callback(null) | ||
} else { | ||
//log() | ||
//log(" Enter new payment method.".grey) | ||
log() | ||
log(" Please enter new payment method..." + " [all payment transfers are PCI compliant]".grey) | ||
card("", "", "", callback) | ||
return card("", "", "", callback) | ||
} | ||
@@ -194,4 +439,12 @@ }) | ||
return function(callback){ | ||
//log() | ||
if (req.plan){ | ||
log((" Enter payment info to change to the " + req.plan.underline + " plan.").grey) | ||
} else { | ||
//log() | ||
log((" Enter payment method to be used").grey) | ||
} | ||
log() | ||
log(" Please enter your payment info..." + " [all payment transfers are PCI compliant]".grey) | ||
card("", "", "", callback) | ||
@@ -198,0 +451,0 @@ } |
@@ -9,4 +9,4 @@ | ||
msg === null | ||
? console.log(" Aborted".yellow) | ||
: console.log(" Aborted".yellow, "-", msg) | ||
? console.log(" Aborted".yellow) | ||
: console.log(" Aborted".yellow + " - ".grey + msg) | ||
console.log() | ||
@@ -13,0 +13,0 @@ } |
var pkg = require("../../package.json") | ||
var helpers = require("./util/helpers.js") | ||
module.exports = function(req, next){ | ||
if (req.argv.version || req.argv.V) { | ||
console.log(pkg.version) | ||
helpers.space() | ||
helpers.trunc(("v" + pkg.version).grey) | ||
helpers.space() | ||
} else { | ||
@@ -7,0 +10,0 @@ next() |
var helpers = require("./util/helpers.js") | ||
module.exports = function(req, next){ | ||
module.exports = function(req, next){ | ||
if (req.creds == null) { | ||
helpers.log(" Welcome to " + (req.config.name || "Surge").bold + "! (" + req.config.platform +")" ) | ||
if (req.config.name) { | ||
helpers.log(" Powered by Surge".grey).hr() | ||
} | ||
helpers.log(" Please login or create an account by entering your email and password:").hr() | ||
} else { | ||
if(req.config.name){ | ||
helpers.log(" " + req.config.name.bold + " - " + (req.config.platform || "surge.sh")) | ||
helpers.log(" Powered by Surge".grey) | ||
} else { | ||
helpers.log(" Surge".bold + " - surge.sh") | ||
} | ||
helpers.hr() | ||
helpers.trunc(("Welcome to " + (req.config.name || "Surge").underline + "!").blue + (" (" + req.config.platform +")").grey) | ||
} | ||
next() | ||
return next() | ||
} |
var helpers = require("./util/helpers") | ||
module.exports = function(req, next){ | ||
var commands = ['h','b', 'd','e','a','r','v','V','p','endpoint','project','domain','add','remove','version','verbose','token','help','pem', 'build','$0','_']; | ||
//req.endpoint = req.argv.endpoint || req.config.endpoint || 'surge.' + req.config.platform | ||
var commands = ['h','b', 'd','e','a','r','v','V','p','endpoint','project','domain','add','remove','version','verbose','token','help','pem', 'promo', 'build','$0','_']; | ||
var args = []; | ||
for (param in req.argv) { | ||
args.push(param); | ||
args.push(param) | ||
} | ||
@@ -15,6 +17,6 @@ | ||
helpers.log() | ||
helpers.log(" surge: `--" + filteredSet[0] + "` is not a surge command.").hr() | ||
helpers.trunc("Aborted - `" + filteredSet[0] + "` is not a surge command.").hr() | ||
} else { | ||
next() | ||
return next() | ||
} | ||
} |
var helpers = require("./util/helpers") | ||
var creds = require("./util/creds") | ||
module.exports = function(req, next){ | ||
//if (req.argv["_"]["0"] === "whoami") { | ||
if (req.creds) { | ||
helpers.log(" Logged in as " + req.creds.email.green + ".") | ||
helpers.log() | ||
} else { | ||
helpers.log(" Not currently authenticated.") | ||
helpers.log() | ||
} | ||
if (req.creds && req.creds.token) { | ||
helpers.fetchAccount(req.endpoint)(req.creds.email, req.creds.token, function(error, account){ | ||
if (account){ | ||
req.account = account | ||
helpers.space() | ||
var str = req.creds.email.underline.grey | ||
if (req.account.plan){ | ||
str = str + (" - " + req.account.plan.name).grey | ||
if (req.account.plan.comped === true){ | ||
str = str + " (comped by surge)".grey | ||
} | ||
} | ||
helpers.trunc(str) | ||
helpers.space() | ||
return next() | ||
} else { | ||
creds(req.endpoint).set(req.creds.email, null) | ||
helpers.space() | ||
helpers.trunc("You are not Authenticated. It is not true. You are not authed. You are not!".grey) | ||
helpers.space() | ||
process.exit() | ||
} | ||
}) | ||
} else { | ||
helpers.space() | ||
helpers.trunc("Not Authenticated".grey) | ||
helpers.space() | ||
process.exit() | ||
// } else { | ||
// next() | ||
// } | ||
} | ||
} |
106
lib/surge.js
@@ -26,2 +26,4 @@ | ||
var deploy = require("./middleware/deploy") | ||
var domainOrSilent = require("./middleware/domainOrSilent") | ||
var pemOrSilent = require("./middleware/pemOrSilent") | ||
var ipaddress = require("./middleware/ipaddress") | ||
@@ -35,8 +37,34 @@ var login = require("./middleware/login") | ||
var plus = require("./middleware/plus") | ||
var subscription= require("./middleware/subscription") | ||
var plans = require("./middleware/plans") | ||
var plan = require("./middleware/plan") | ||
var payment = require("./middleware/payment") | ||
var card = require("./middleware/card") | ||
var setcard = require("./middleware/setcard") | ||
var subscribe = require("./middleware/subscribe") | ||
var ssl = require("./middleware/ssl") | ||
var log = require("./middleware/log") | ||
var helpers = require('./middleware/util/helpers') | ||
var space = function(req, next){ console.log(); next() } | ||
var exitifcurrentplan = function(req, next){ | ||
if (req.plans.current && req.plans.current.id === req.selectedPlan.id){ | ||
helpers.trunc("Success".green + (" - You remain on the " + req.plans.current.name.underline + " plan.").grey) | ||
helpers.space() | ||
process.exit() | ||
}else{ | ||
return next() | ||
} | ||
} | ||
var space = function(req, next){ | ||
helpers.space() | ||
next() | ||
} | ||
var parse = function(arg){ | ||
@@ -73,2 +101,11 @@ if(arg.hasOwnProperty("parent") && arg.parent.hasOwnProperty("rawArgs")){ | ||
var authInfo = function(req, next){ | ||
var str = ("Running as " + req.account.email.underline).grey | ||
if (req.account.plan){ str = str + (" (" + req.account.plan.name + ")").grey } | ||
helpers.space() | ||
helpers.trunc(str) | ||
helpers.space() | ||
return next() | ||
} | ||
var surge = function(args){ | ||
@@ -81,3 +118,3 @@ // will be one of: | ||
var commands = ["login", "logout", "whoami", "list", "publish", "teardown", "token", "plus", "ssl"] | ||
var commands = ["login", "logout", "whoami", "list", "publish", "teardown", "token", "plus", "ssl", "plan", "card"] | ||
@@ -100,3 +137,3 @@ if (commands.indexOf(cmd) !== -1) { | ||
whitelist, endpoint, pkg, help, version, space, | ||
preAuth, creds, welcome, tokencheck, email, auth, postAuth, | ||
preAuth, creds, auth, postAuth, | ||
token, space | ||
@@ -120,3 +157,3 @@ ] | ||
whitelist, endpoint, pkg, help, version, space, | ||
preAuth, creds, welcome, email, auth, postAuth, | ||
preAuth, auth, postAuth, | ||
login, space | ||
@@ -164,8 +201,7 @@ ] | ||
whitelist, endpoint, pkg, help, version, space, | ||
preAuth, creds, welcome, tokencheck, email, auth, postAuth, shorthand, | ||
preAuth, creds, welcome, auth, authInfo, postAuth, shorthand, | ||
preProject, project, postProject, | ||
preSize, size, postSize, | ||
preDomain, discovery.setDomainFromCname, discovery.suggestDomainFromGenerator, domain, postDomain, | ||
prePublish, protocol, deploy, postPublish, | ||
ipaddress | ||
prePublish, protocol, deploy, postPublish, ipaddress | ||
] | ||
@@ -186,3 +222,3 @@ return function(){ | ||
whitelist, endpoint, pkg, help, version, space, | ||
creds, tokencheck, whoami | ||
creds, whoami | ||
] | ||
@@ -205,3 +241,3 @@ return function(){ | ||
whitelist, endpoint, pkg, help, version, space, | ||
preAuth, creds, welcome, tokencheck, email, auth, postAuth, | ||
preAuth, creds, welcome, auth, postAuth, shorthand, | ||
list, space | ||
@@ -225,4 +261,4 @@ ] | ||
whitelist, endpoint, pkg, help, version, space, | ||
preAuth, creds, welcome, tokencheck, email, auth, postAuth, | ||
shorthand, discovery.setDomainFromArgs, discovery.suggestDomainFromCname, domain, | ||
preAuth, creds, auth, postAuth, | ||
shorthand, discovery.setDomainFromArgs, discovery.suggestDomainFromCname, domainOrSilent, | ||
teardown, space | ||
@@ -260,2 +296,44 @@ ] | ||
surge.plan = function(hooks){ | ||
var hooks = hooks || {} | ||
var preAuth = hooks.preAuth || stub | ||
var postAuth = hooks.postAuth || stub | ||
var onion = [ | ||
whitelist, endpoint, pkg, help, version, | ||
preAuth, creds, auth, postAuth, | ||
shorthand, discovery.setDomainFromArgs, | ||
plans, plan, exitifcurrentplan, | ||
payment, subscribe, | ||
space | ||
] | ||
return function(){ | ||
var argv = parse(arguments[arguments.length -1]) | ||
skin({ | ||
config: config, | ||
argv: argv, | ||
read: read | ||
}, onion) | ||
} | ||
} | ||
surge.card = function(hooks){ | ||
var hooks = hooks || {} | ||
var preAuth = hooks.preAuth || stub | ||
var postAuth = hooks.postAuth || stub | ||
var onion = [ | ||
whitelist, endpoint, pkg, help, version, space, | ||
preAuth, creds, welcome, auth, postAuth, | ||
plans, card, setcard, | ||
space | ||
] | ||
return function(){ | ||
var argv = parse(arguments[arguments.length -1]) | ||
skin({ | ||
config: config, | ||
argv: argv, | ||
read: read | ||
}, onion) | ||
} | ||
} | ||
surge.ssl = function(hooks){ | ||
@@ -267,5 +345,5 @@ var hooks = hooks || {} | ||
whitelist, endpoint, pkg, help, version, space, | ||
preAuth, creds, welcome, tokencheck, email, auth, postAuth, | ||
shorthand, discovery.setDomainFromArgs, discovery.suggestDomainFromCname, domain, | ||
ssl, space | ||
preAuth, creds, auth, postAuth, | ||
shorthand, discovery.setDomainFromArgs, discovery.suggestDomainFromCname, domainOrSilent, | ||
pemOrSilent, ssl, space | ||
] | ||
@@ -272,0 +350,0 @@ return function(){ |
{ | ||
"name": "surge", | ||
"version": "0.19.0", | ||
"version": "0.20.0", | ||
"description": "CDN for front-end developers", | ||
@@ -8,17 +8,20 @@ "author": "Brock Whitten <brock@chloi.io>", | ||
"dependencies": { | ||
"cli-table": "^0.3.1", | ||
"cli-table2": "^0.2.0", | ||
"du": "0.1.0", | ||
"fstream-ignore": "1.0.2", | ||
"inquirer": "", | ||
"is-domain": "0.0.1", | ||
"minimist": "1.1.1", | ||
"moniker": "0.1.2", | ||
"netrc": "0.1.4", | ||
"progress": "1.1.8", | ||
"prompt": "~0.2.14", | ||
"progress": "1.1.8", | ||
"request": "2.40.0", | ||
"read": "1.0.5", | ||
"request": "2.83.0", | ||
"split": "0.3.1", | ||
"surge-ignore": "0.2.0", | ||
"tar": "1.0.0", | ||
"tarr": "1.0.3", | ||
"tar.gz": "0.1.1", | ||
"url-parse-as-address": "1.0.0", | ||
"read": "1.0.5", | ||
"minimist": "1.1.1" | ||
"url-parse-as-address": "1.0.0" | ||
}, | ||
@@ -34,6 +37,8 @@ "devDependencies": { | ||
"main": "./lib/surge.js", | ||
"ignore": ["test"], | ||
"ignore": [ | ||
"test" | ||
], | ||
"scripts": { | ||
"test": "mocha -t 5000", | ||
"test:local": "ENDPOINT='localhost:5001' ./node_modules/.bin/mocha" | ||
"test": "mocha ./test/basic.js -t 5000", | ||
"test:local": "ENDPOINT='surge.lvh.me' mocha ./test/basic -t 4000" | ||
}, | ||
@@ -40,0 +45,0 @@ "repository": { |
@@ -34,3 +34,3 @@ # surge(.sh) | ||
Shorthand usage: | ||
surge [project path] [domain] | ||
surge [project] [domain] | ||
@@ -37,0 +37,0 @@ Additional commands: |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
32
74901
18
48
2175
1
+ Addedcli-table@^0.3.1
+ Addedcli-table2@^0.2.0
+ Addedinquirer@
+ Addedtarr@1.0.3
+ Added@inquirer/confirm@5.0.1(transitive)
+ Added@inquirer/core@10.0.1(transitive)
+ Added@inquirer/editor@4.0.1(transitive)
+ Added@inquirer/expand@4.0.1(transitive)
+ Added@inquirer/figures@1.0.7(transitive)
+ Added@inquirer/input@4.0.1(transitive)
+ Added@inquirer/number@3.0.1(transitive)
+ Added@inquirer/password@4.0.1(transitive)
+ Added@inquirer/prompts@7.0.1(transitive)
+ Added@inquirer/rawlist@4.0.1(transitive)
+ Added@inquirer/search@3.0.1(transitive)
+ Added@inquirer/select@4.0.1(transitive)
+ Added@inquirer/type@3.0.0(transitive)
+ Added@types/node@22.9.0(transitive)
+ Addedajv@5.5.2(transitive)
+ Addedansi-escapes@4.3.2(transitive)
+ Addedansi-regex@2.1.15.0.1(transitive)
+ Addedansi-styles@4.3.0(transitive)
+ Addedasn1@0.2.6(transitive)
+ Addedassert-plus@1.0.0(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedaws-sign2@0.7.0(transitive)
+ Addedaws4@1.13.2(transitive)
+ Addedbcrypt-pbkdf@1.0.2(transitive)
+ Addedboom@4.3.15.3.3(transitive)
+ Addedcaseless@0.12.0(transitive)
+ Addedchardet@0.7.0(transitive)
+ Addedcli-table@0.3.11(transitive)
+ Addedcli-table2@0.2.0(transitive)
+ Addedcli-width@4.1.0(transitive)
+ Addedco@4.6.0(transitive)
+ Addedcode-point-at@1.1.0(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedcolors@1.0.31.4.0(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedcore-util-is@1.0.2(transitive)
+ Addedcryptiles@3.2.1(transitive)
+ Addeddashdash@1.14.1(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedecc-jsbn@0.1.2(transitive)
+ Addedemoji-regex@8.0.0(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedexternal-editor@3.1.0(transitive)
+ Addedextsprintf@1.3.0(transitive)
+ Addedfast-deep-equal@1.1.0(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedforever-agent@0.6.1(transitive)
+ Addedform-data@2.3.3(transitive)
+ Addedgetpass@0.1.7(transitive)
+ Addedhar-schema@2.0.0(transitive)
+ Addedhar-validator@5.0.3(transitive)
+ Addedhawk@6.0.2(transitive)
+ Addedhoek@4.3.1(transitive)
+ Addedhttp-signature@1.2.0(transitive)
+ Addediconv-lite@0.4.24(transitive)
+ Addedinquirer@12.0.1(transitive)
+ Addedis-fullwidth-code-point@1.0.03.0.0(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedjsbn@0.1.1(transitive)
+ Addedjson-schema@0.4.0(transitive)
+ Addedjson-schema-traverse@0.3.1(transitive)
+ Addedjsprim@1.4.2(transitive)
+ Addedlodash@3.10.1(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedmute-stream@2.0.0(transitive)
+ Addednumber-is-nan@1.0.1(transitive)
+ Addedoauth-sign@0.8.2(transitive)
+ Addedos-tmpdir@1.0.2(transitive)
+ Addedperformance-now@2.1.0(transitive)
+ Addedpunycode@1.4.1(transitive)
+ Addedqs@6.5.3(transitive)
+ Addedrequest@2.83.0(transitive)
+ Addedrun-async@3.0.0(transitive)
+ Addedrxjs@7.8.1(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsignal-exit@4.1.0(transitive)
+ Addedsntp@2.1.0(transitive)
+ Addedsshpk@1.18.0(transitive)
+ Addedstring-width@1.0.24.2.3(transitive)
+ Addedstrip-ansi@3.0.16.0.1(transitive)
+ Addedtarr@1.0.3(transitive)
+ Addedtmp@0.0.33(transitive)
+ Addedtough-cookie@2.3.4(transitive)
+ Addedtslib@2.8.1(transitive)
+ Addedtunnel-agent@0.6.0(transitive)
+ Addedtweetnacl@0.14.5(transitive)
+ Addedtype-fest@0.21.3(transitive)
+ Addedundici-types@6.19.8(transitive)
+ Addeduuid@3.4.0(transitive)
+ Addedverror@1.10.0(transitive)
+ Addedwrap-ansi@6.2.0(transitive)
+ Addedyoctocolors-cjs@2.1.2(transitive)
- Removedtar@1.0.0
- Removedasn1@0.1.11(transitive)
- Removedassert-plus@0.1.5(transitive)
- Removedasync@0.9.2(transitive)
- Removedaws-sign2@0.5.0(transitive)
- Removedboom@0.4.2(transitive)
- Removedcombined-stream@0.0.7(transitive)
- Removedcryptiles@0.2.2(transitive)
- Removedctype@0.5.3(transitive)
- Removeddelayed-stream@0.0.5(transitive)
- Removedforever-agent@0.5.2(transitive)
- Removedform-data@0.1.4(transitive)
- Removedhawk@1.1.1(transitive)
- Removedhoek@0.9.1(transitive)
- Removedhttp-signature@0.10.1(transitive)
- Removedmime@1.2.11(transitive)
- Removedmime-types@1.0.2(transitive)
- Removednode-uuid@1.4.8(transitive)
- Removedoauth-sign@0.3.0(transitive)
- Removedqs@1.0.2(transitive)
- Removedrequest@2.40.0(transitive)
- Removedsntp@0.2.4(transitive)
- Removedtar@1.0.0(transitive)
- Removedtldts@6.1.59(transitive)
- Removedtldts-core@6.1.59(transitive)
- Removedtough-cookie@5.0.0(transitive)
- Removedtunnel-agent@0.4.3(transitive)
Updatedrequest@2.83.0