Преглед изворни кода

Merge branch 'master' into ja-restore-files

James Allen пре 8 година
родитељ
комит
9e525702c1
41 измењених фајлова са 597 додато и 4729 уклоњено
  1. 17 10
      services/web/app/coffee/Features/DocumentUpdater/DocumentUpdaterHandler.coffee
  2. 11 7
      services/web/app/coffee/Features/Editor/EditorController.coffee
  3. 1 0
      services/web/app/coffee/Features/Project/ProjectController.coffee
  4. 43 17
      services/web/app/coffee/Features/Project/ProjectEntityMongoUpdateHandler.coffee
  5. 141 83
      services/web/app/coffee/Features/Project/ProjectEntityUpdateHandler.coffee
  6. 2 2
      services/web/app/coffee/infrastructure/ExpressLocals.coffee
  7. 2 2
      services/web/app/coffee/infrastructure/Features.coffee
  8. 7 0
      services/web/app/coffee/infrastructure/Modules.coffee
  9. 5 0
      services/web/app/coffee/models/Project.coffee
  10. 2 0
      services/web/app/views/project/editor.pug
  11. 1 0
      services/web/app/views/project/editor/editor.pug
  12. 3 0
      services/web/app/views/project/editor/header.pug
  13. 1 2
      services/web/app/views/project/editor/history.pug
  14. 0 1
      services/web/app/views/project/editor/pdf.pug
  15. 0 1
      services/web/app/views/project/editor/share.pug
  16. 2 5
      services/web/app/views/project/list/side-bar.pug
  17. 34 43
      services/web/app/views/subscriptions/new.pug
  18. 6 12
      services/web/app/views/subscriptions/plans.pug
  19. 126 8
      services/web/npm-shrinkwrap.json
  20. 4 0
      services/web/package.json
  21. 7 0
      services/web/public/coffee/ide/directives/layout.coffee
  22. 0 9
      services/web/public/coffee/ide/history/controllers/HistoryListController.coffee
  23. 2 18
      services/web/public/coffee/main/account-upgrade.coffee
  24. 20 35
      services/web/public/coffee/main/new-subscription.coffee
  25. 1 167
      services/web/public/coffee/main/plans.coffee
  26. 0 2
      services/web/public/coffee/main/subscription-dashboard.coffee
  27. 0 4218
      services/web/public/js/libs/recurly-3.0.5.js
  28. 0 0
      services/web/public/js/libs/recurly-4.8.5.js
  29. 0 0
      services/web/public/js/libs/recurly.min.js
  30. 1 5
      services/web/public/stylesheets/_style_includes.less
  31. 2 8
      services/web/public/stylesheets/app/editor.less
  32. 5 0
      services/web/public/stylesheets/app/recurly.less
  33. 2 1
      services/web/public/stylesheets/components/forms.less
  34. 5 2
      services/web/test/acceptance/coffee/LinkedFilesTests.coffee
  35. 3 0
      services/web/test/acceptance/coffee/ProjectDuplicateNameTests.coffee
  36. 12 3
      services/web/test/acceptance/coffee/ProjectStructureTests.coffee
  37. 7 5
      services/web/test/unit/coffee/Editor/EditorControllerTests.coffee
  38. 50 7
      services/web/test/unit/coffee/Project/ProjectEntityMongoUpdateHandlerTests.coffee
  39. 68 53
      services/web/test/unit/coffee/Project/ProjectEntityUpdateHandlerTests.coffee
  40. 3 1
      services/web/webpack.config.js
  41. 1 2
      services/web/webpack.config.prod.js

+ 17 - 10
services/web/app/coffee/Features/DocumentUpdater/DocumentUpdaterHandler.coffee

@@ -174,6 +174,23 @@ module.exports = DocumentUpdaterHandler =
 		oldEntitiesHash = _.indexBy oldEntities, (entity) -> entity[entityType]._id.toString()
 		newEntitiesHash = _.indexBy newEntities, (entity) -> entity[entityType]._id.toString()
 
+		# Send deletes before adds (and renames) to keep a 1:1 mapping between
+		# paths and ids
+		#
+		# When a file is replaced, we first delete the old file and then add the
+		# new file. If the 'add' operation is sent to project history before the
+		# 'delete' then we would have two files with the same path at that point
+		# in time.
+		for id, oldEntity of oldEntitiesHash
+			newEntity = newEntitiesHash[id]
+
+			if !newEntity?
+				# entity deleted
+				updates.push
+					id: id
+					pathname: oldEntity.path
+					newPathname: ''
+
 		for id, newEntity of newEntitiesHash
 			oldEntity = oldEntitiesHash[id]
 
@@ -191,16 +208,6 @@ module.exports = DocumentUpdaterHandler =
 					pathname: oldEntity.path
 					newPathname: newEntity.path
 
-		for id, oldEntity of oldEntitiesHash
-			newEntity = newEntitiesHash[id]
-
-			if !newEntity?
-				# entity deleted
-				updates.push
-					id: id
-					pathname: oldEntity.path
-					newPathname: ''
-
 		updates
 
 PENDINGUPDATESKEY = "PendingUpdates"

+ 11 - 7
services/web/app/coffee/Features/Editor/EditorController.coffee

@@ -41,11 +41,13 @@ module.exports = EditorController =
 			callback err, doc
 
 	upsertFile: (project_id, folder_id, fileName, fsPath, linkedFileData, source, user_id, callback = (err, file) ->) ->
-		ProjectEntityUpdateHandler.upsertFile project_id, folder_id, fileName, fsPath, linkedFileData, user_id, (err, file, didAddFile) ->
+		ProjectEntityUpdateHandler.upsertFile project_id, folder_id, fileName, fsPath, linkedFileData, user_id, (err, newFile, didAddFile, existingFile) ->
 			return callback(err) if err?
-			if didAddFile
-				EditorRealTimeController.emitToRoom project_id, 'reciveNewFile', folder_id, file, source, linkedFileData
-			callback null, file
+			if not didAddFile # replacement, so remove the existing file from the client
+				EditorRealTimeController.emitToRoom project_id, 'removeEntity', existingFile._id, source
+			# now add the new file on the client
+			EditorRealTimeController.emitToRoom project_id, 'reciveNewFile', folder_id, newFile, source, linkedFileData
+			callback null, newFile
 
 	upsertDocWithPath: (project_id, elementPath, docLines, source, user_id, callback) ->
 		ProjectEntityUpdateHandler.upsertDocWithPath project_id, elementPath, docLines, source, user_id, (err, doc, didAddNewDoc, newFolders, lastFolder) ->
@@ -57,12 +59,14 @@ module.exports = EditorController =
 				callback()
 
 	upsertFileWithPath: (project_id, elementPath, fsPath, linkedFileData, source, user_id, callback) ->
-		ProjectEntityUpdateHandler.upsertFileWithPath project_id, elementPath, fsPath, linkedFileData, user_id, (err, file, didAddFile, newFolders, lastFolder) ->
+		ProjectEntityUpdateHandler.upsertFileWithPath project_id, elementPath, fsPath, linkedFileData, user_id, (err, newFile, didAddFile, existingFile, newFolders, lastFolder) ->
 			return callback(err) if err?
 			EditorController._notifyProjectUsersOfNewFolders project_id, newFolders, (err) ->
 				return callback(err) if err?
-				if didAddFile
-					EditorRealTimeController.emitToRoom project_id, 'reciveNewFile', lastFolder._id, file, source, linkedFileData
+				if not didAddFile # replacement, so remove the existing file from the client
+					EditorRealTimeController.emitToRoom project_id, 'removeEntity', existingFile._id, source
+				# now add the new file on the client
+				EditorRealTimeController.emitToRoom project_id, 'reciveNewFile', lastFolder._id, newFile, source, linkedFileData
 				callback()
 
 	addFolder : (project_id, folder_id, folderName, source, callback = (error, folder)->)->

+ 1 - 0
services/web/app/coffee/Features/Project/ProjectController.coffee

@@ -301,6 +301,7 @@ module.exports = ProjectController =
 					themes: THEME_LIST
 					maxDocLength: Settings.max_doc_length
 					useV2History: !!project.overleaf?.history?.display
+					showRichText: req.query?.rt == 'true'
 				timer.done()
 
 	_buildProjectList: (allProjects, v1Projects = [])->

+ 43 - 17
services/web/app/coffee/Features/Project/ProjectEntityMongoUpdateHandler.coffee

@@ -48,28 +48,28 @@ module.exports = ProjectEntityMongoUpdateHandler = self =
 			self._confirmFolder project, folder_id, (folder_id)->
 				self._putElement project, folder_id, fileRef, "file", callback
 
-	replaceFile: wrapWithLock (project_id, file_id, linkedFileData, callback) ->
+	replaceFileWithNew: wrapWithLock (project_id, file_id, newFileRef, callback) ->
 		ProjectGetter.getProjectWithoutLock project_id, {rootFolder: true, name:true}, (err, project) ->
 			return callback(err) if err?
 			ProjectLocator.findElement {project:project, element_id: file_id, type: 'file'}, (err, fileRef, path)=>
 				return callback(err) if err?
-				conditions = _id:project._id
-				inc = {}
-				inc["#{path.mongo}.rev"] = 1
-				# currently we do not need to increment the project version number for changes that are replacements
-				# but when we make switch to having immutable files the replace operation will add a new file, and
-				# this will require a version increase.  We will start incrementing the project version now as it does
-				# no harm and will help to test it.
-				inc['version'] = 1
-				set = {}
-				set["#{path.mongo}.created"] = new Date()
-				set["#{path.mongo}.linkedFileData"] = linkedFileData
-				update =
-					"$inc": inc
-					"$set": set
-				Project.update conditions, update, {}, (err) ->
+				ProjectEntityMongoUpdateHandler._insertDeletedFileReference project_id, fileRef, (err) ->
 					return callback(err) if err?
-					callback null, fileRef, project, path
+					conditions = _id:project._id
+					inc = {}
+					# increment the project structure version as we are adding a new file here
+					inc['version'] = 1
+					set = {}
+					set["#{path.mongo}._id"] = newFileRef._id
+					set["#{path.mongo}.created"] = new Date()
+					set["#{path.mongo}.linkedFileData"] = newFileRef.linkedFileData
+					set["#{path.mongo}.rev"] = 1
+					update =
+						"$inc": inc
+						"$set": set
+					Project.update conditions, update, {}, (err) ->
+						return callback(err) if err?
+						callback null, fileRef, project, path
 
 	mkdirp: wrapWithLock (project_id, path, callback) ->
 		folders = path.split('/')
@@ -300,3 +300,29 @@ module.exports = ProjectEntityMongoUpdateHandler = self =
 					if isNestedFolder
 						return callback(new Errors.InvalidNameError("destination folder is a child folder of me"))
 				callback()
+
+	_insertDeletedDocReference: (project_id, doc, callback = (error) ->) ->
+		Project.update {
+			_id: project_id
+		}, {
+			$push: {
+				deletedDocs: {
+					_id:  doc._id
+					name: doc.name
+				}
+			}
+		}, {}, callback
+
+	_insertDeletedFileReference: (project_id, fileRef, callback = (error) ->) ->
+		Project.update {
+			_id: project_id
+		}, {
+			$push: {
+				deletedFiles: {
+					_id:  fileRef._id
+					name: fileRef.name
+					linkedFileData: fileRef.linkedFileData
+					deletedAt: new Date()
+				}
+			}
+		}, {}, callback

+ 141 - 83
services/web/app/coffee/Features/Project/ProjectEntityUpdateHandler.coffee

@@ -24,12 +24,25 @@ wrapWithLock = (methodWithoutLock) ->
 	# This lock is used to make sure that the project structure updates are made
 	# sequentially. In particular the updates must be made in mongo and sent to
 	# the doc-updater in the same order.
-	methodWithLock = (project_id, args..., callback) ->
-		LockManager.runWithLock LOCK_NAMESPACE, project_id,
-			(cb) -> methodWithoutLock project_id, args..., cb
-			callback
-	methodWithLock.withoutLock = methodWithoutLock
-	methodWithLock
+	if typeof methodWithoutLock is 'function'
+		methodWithLock = (project_id, args..., callback) ->
+			LockManager.runWithLock LOCK_NAMESPACE, project_id,
+				(cb) -> methodWithoutLock project_id, args..., cb
+				callback
+		methodWithLock.withoutLock = methodWithoutLock
+		methodWithLock
+	else
+		# handle case with separate setup and locked stages
+		wrapWithSetup = methodWithoutLock.beforeLock  # a function to set things up before the lock
+		mainTask = methodWithoutLock.withLock # function to execute inside the lock
+		methodWithLock = wrapWithSetup (project_id, args..., callback) ->
+			LockManager.runWithLock(LOCK_NAMESPACE, project_id, (cb) ->
+				mainTask(project_id, args..., cb)
+			callback)
+		methodWithLock.withoutLock = wrapWithSetup mainTask
+		methodWithLock.beforeLock = methodWithoutLock.beforeLock
+		methodWithLock.mainTask = methodWithoutLock.withLock
+		methodWithLock
 
 module.exports = ProjectEntityUpdateHandler = self =
 	# this doesn't need any locking because it's only called by ProjectDuplicator
@@ -120,31 +133,72 @@ module.exports = ProjectEntityUpdateHandler = self =
 				return callback(error) if error?
 				callback null, doc, folder_id
 
-	addFile: wrapWithLock (project_id, folder_id, fileName, fsPath, linkedFileData, userId, callback = (error, fileRef, folder_id) ->)->
-		self.addFileWithoutUpdatingHistory.withoutLock project_id, folder_id, fileName, fsPath, linkedFileData, userId, (error, fileRef, folder_id, path, fileStoreUrl) ->
-			return callback(error) if error?
-			newFiles = [
-				file: fileRef
-				path: path
-				url: fileStoreUrl
-			]
-			DocumentUpdaterHandler.updateProjectStructure project_id, userId, {newFiles}, (error) ->
-				return callback(error) if error?
-				callback null, fileRef, folder_id
+	_uploadFile: (project_id, folder_id, fileName, fsPath, linkedFileData, userId, callback = (error, fileRef, fileStoreUrl) ->)->
+		if not SafePath.isCleanFilename fileName
+			return callback new Errors.InvalidNameError("invalid element name")
+		fileRef = new File(
+			name: fileName
+			linkedFileData: linkedFileData
+		)
+		FileStoreHandler.uploadFileFromDisk project_id, fileRef._id, fsPath, (err, fileStoreUrl)->
+			if err?
+				logger.err err:err, project_id: project_id, folder_id: folder_id, file_name: fileName, fileRef:fileRef, "error uploading image to s3"
+				return callback(err)
+			callback(null, fileRef, fileStoreUrl)
 
-	replaceFile: wrapWithLock (project_id, file_id, fsPath, linkedFileData, userId, callback)->
-		FileStoreHandler.uploadFileFromDisk project_id, file_id, fsPath, (err, fileStoreUrl)->
-			return callback(err) if err?
-			ProjectEntityMongoUpdateHandler.replaceFile project_id, file_id, linkedFileData, (err, fileRef, project, path) ->
+	_addFileAndSendToTpds: (project_id, folder_id, fileName, fileRef, callback = (error) ->)->
+		ProjectEntityMongoUpdateHandler.addFile project_id, folder_id, fileRef, (err, result, project) ->
+			if err?
+				logger.err err:err, project_id: project_id, folder_id: folder_id, file_name: fileName, fileRef:fileRef, "error adding file with project"
+				return callback(err)
+			TpdsUpdateSender.addFile {project_id:project_id, file_id:fileRef._id, path:result?.path?.fileSystem, project_name:project.name, rev:fileRef.rev}, (err) ->
+				return callback(err) if err?
+				callback(null, result, project)
+
+	addFile: wrapWithLock
+		beforeLock: (next) ->
+			(project_id, folder_id, fileName, fsPath, linkedFileData, userId, callback) ->
+				ProjectEntityUpdateHandler._uploadFile project_id, folder_id, fileName, fsPath, linkedFileData, userId, (error, fileRef, fileStoreUrl) ->
+					return callback(error) if error?
+					next(project_id, folder_id, fileName, fsPath, linkedFileData, userId, fileRef, fileStoreUrl, callback)
+		withLock: (project_id, folder_id, fileName, fsPath, linkedFileData, userId, fileRef, fileStoreUrl, callback = (error, fileRef, folder_id) ->)->
+			ProjectEntityUpdateHandler._addFileAndSendToTpds project_id, folder_id, fileName, fileRef, (err, result, project) ->
 				return callback(err) if err?
 				newFiles = [
 					file: fileRef
+					path: result?.path?.fileSystem
+					url: fileStoreUrl
+				]
+				DocumentUpdaterHandler.updateProjectStructure project_id, userId, {newFiles}, (error) ->
+					return callback(error) if error?
+					callback(null, fileRef, folder_id)
+
+	replaceFile: wrapWithLock
+		beforeLock: (next) ->
+			(project_id, file_id, fsPath, linkedFileData, userId, callback)->
+				# create a new file
+				fileRef = new File(
+					name: "dummy-upload-filename"
+					linkedFileData: linkedFileData
+				)
+				FileStoreHandler.uploadFileFromDisk project_id, fileRef._id, fsPath, (err, fileStoreUrl)->
+					return callback(err) if err?
+					next project_id, file_id, fsPath, linkedFileData, userId, fileRef, fileStoreUrl, callback
+		withLock: (project_id, file_id, fsPath, linkedFileData, userId, newFileRef, fileStoreUrl, callback)->
+			ProjectEntityMongoUpdateHandler.replaceFileWithNew project_id, file_id, newFileRef, (err, oldFileRef, project, path) ->
+				return callback(err) if err?
+				oldFiles = [
+					file: oldFileRef
+					path: path.fileSystem
+				]
+				newFiles = [
+					file: newFileRef
 					path: path.fileSystem
 					url: fileStoreUrl
 				]
-				TpdsUpdateSender.addFile {project_id:project._id, file_id:fileRef._id, path:path.fileSystem, rev:fileRef.rev+1, project_name:project.name}, (err) ->
+				TpdsUpdateSender.addFile {project_id:project._id, file_id:newFileRef._id, path:path.fileSystem, rev:newFileRef.rev+1, project_name:project.name}, (err) ->
 					return callback(err) if err?
-					DocumentUpdaterHandler.updateProjectStructure project_id, userId, {newFiles}, callback
+					DocumentUpdaterHandler.updateProjectStructure project_id, userId, {oldFiles, newFiles}, callback
 
 	addDocWithoutUpdatingHistory: wrapWithLock (project_id, folder_id, docName, docLines, userId, callback = (error, doc, folder_id) ->)=>
 		# This method should never be called directly, except when importing a project
@@ -171,29 +225,19 @@ module.exports = ProjectEntityUpdateHandler = self =
 					return callback(err) if err?
 					callback(null, doc, folder_id, result?.path?.fileSystem)
 
-	addFileWithoutUpdatingHistory: wrapWithLock (project_id, folder_id, fileName, fsPath, linkedFileData, userId, callback = (error, fileRef, folder_id, path, fileStoreUrl) ->)->
+	addFileWithoutUpdatingHistory: wrapWithLock
 		# This method should never be called directly, except when importing a project
 		# from Overleaf. It skips sending updates to the project history, which will break
 		# the history unless you are making sure it is updated in some other way.
-
-		if not SafePath.isCleanFilename fileName
-			return callback new Errors.InvalidNameError("invalid element name")
-
-		fileRef = new File(
-			name: fileName
-			linkedFileData: linkedFileData
-		)
-		FileStoreHandler.uploadFileFromDisk project_id, fileRef._id, fsPath, (err, fileStoreUrl)->
-			if err?
-				logger.err err:err, project_id: project_id, folder_id: folder_id, file_name: fileName, fileRef:fileRef, "error uploading image to s3"
-				return callback(err)
-			ProjectEntityMongoUpdateHandler.addFile project_id, folder_id, fileRef, (err, result, project) ->
-				if err?
-					logger.err err:err, project_id: project_id, folder_id: folder_id, file_name: fileName, fileRef:fileRef, "error adding file with project"
-					return callback(err)
-				TpdsUpdateSender.addFile {project_id:project_id, file_id:fileRef._id, path:result?.path?.fileSystem, project_name:project.name, rev:fileRef.rev}, (err) ->
-					return callback(err) if err?
-					callback(null, fileRef, folder_id, result?.path?.fileSystem, fileStoreUrl)
+		beforeLock: (next) ->
+			(project_id, folder_id, fileName, fsPath, linkedFileData, userId, callback) ->
+				ProjectEntityUpdateHandler._uploadFile project_id, folder_id, fileName, fsPath, linkedFileData, userId, (error, fileRef, fileStoreUrl) ->
+					return callback(error) if error?
+					next(project_id, folder_id, fileName, fsPath, linkedFileData, userId, fileRef, fileStoreUrl, callback)
+		withLock: (project_id, folder_id, fileName, fsPath, linkedFileData, userId, fileRef, fileStoreUrl, callback = (error, fileRef, folder_id, path, fileStoreUrl) ->)->
+			ProjectEntityUpdateHandler._addFileAndSendToTpds project_id, folder_id, fileName, fileRef, (err, result, project) ->
+				return callback(err) if err?
+				callback(null, fileRef, folder_id, result?.path?.fileSystem, fileStoreUrl)
 
 	upsertDoc: wrapWithLock (project_id, folder_id, docName, docLines, source, userId, callback = (err, doc, folder_id, isNewDoc)->)->
 		ProjectLocator.findElement project_id: project_id, element_id: folder_id, type: "folder", (error, folder) ->
@@ -215,23 +259,36 @@ module.exports = ProjectEntityUpdateHandler = self =
 					return callback(err) if err?
 					callback null, doc, !existingDoc?
 
-	upsertFile: wrapWithLock (project_id, folder_id, fileName, fsPath, linkedFileData, userId, callback = (err, file, isNewFile)->)->
-		ProjectLocator.findElement project_id: project_id, element_id: folder_id, type: "folder", (error, folder) ->
-			return callback(error) if error?
-			return callback(new Error("Couldn't find folder")) if !folder?
-			existingFile = null
-			for fileRef in folder.fileRefs
-				if fileRef.name == fileName
-					existingFile = fileRef
-					break
-			if existingFile?
-				self.replaceFile.withoutLock project_id, existingFile._id, fsPath, linkedFileData, userId, (err) ->
-					return callback(err) if err?
-					callback null, existingFile, !existingFile?
-			else
-				self.addFile.withoutLock project_id, folder_id, fileName, fsPath, linkedFileData, userId, (err, file) ->
+	upsertFile: wrapWithLock
+		beforeLock: (next) ->
+			(project_id, folder_id, fileName, fsPath, linkedFileData, userId, callback)->
+				# create a new file
+				fileRef = new File(
+					name: fileName
+					linkedFileData: linkedFileData
+				)
+				FileStoreHandler.uploadFileFromDisk project_id, fileRef._id, fsPath, (err, fileStoreUrl)->
 					return callback(err) if err?
-					callback null, file, !existingFile?
+					next(project_id, folder_id, fileName, fsPath, linkedFileData, userId, fileRef, fileStoreUrl, callback)
+		withLock: (project_id, folder_id, fileName, fsPath, linkedFileData, userId, newFileRef, fileStoreUrl, callback = (err, file, isNewFile, existingFile)->)->
+			ProjectLocator.findElement project_id: project_id, element_id: folder_id, type: "folder", (error, folder) ->
+				return callback(error) if error?
+				return callback(new Error("Couldn't find folder")) if !folder?
+				existingFile = null
+				for fileRef in folder.fileRefs
+					if fileRef.name == fileName
+						existingFile = fileRef
+						break
+				if existingFile?
+					# this calls directly into the replaceFile main task (without the beforeLock part)
+					self.replaceFile.mainTask project_id, existingFile._id, fsPath, linkedFileData, userId, newFileRef, fileStoreUrl, (err) ->
+						return callback(err) if err?
+						callback null, newFileRef, !existingFile?, existingFile
+				else
+					# this calls directly into the addFile main task (without the beforeLock part)
+					self.addFile.mainTask project_id, folder_id, fileName, fsPath, linkedFileData, userId, newFileRef, fileStoreUrl, (err) ->
+						return callback(err) if err?
+						callback null, newFileRef, !existingFile?, existingFile
 
 	upsertDocWithPath: wrapWithLock (project_id, elementPath, docLines, source, userId, callback) ->
 		docName = path.basename(elementPath)
@@ -242,14 +299,26 @@ module.exports = ProjectEntityUpdateHandler = self =
 				return callback(err) if err?
 				callback null, doc, isNewDoc, newFolders, folder
 
-	upsertFileWithPath: wrapWithLock (project_id, elementPath, fsPath, linkedFileData, userId, callback) ->
-		fileName = path.basename(elementPath)
-		folderPath = path.dirname(elementPath)
-		self.mkdirp.withoutLock project_id, folderPath, (err, newFolders, folder) ->
-			return callback(err) if err?
-			self.upsertFile.withoutLock project_id, folder._id, fileName, fsPath, linkedFileData, userId, (err, file, isNewFile) ->
+	upsertFileWithPath: wrapWithLock
+		beforeLock: (next) ->
+			(project_id, elementPath, fsPath, linkedFileData, userId, callback)->
+				fileName = path.basename(elementPath)
+				folderPath = path.dirname(elementPath)
+				# create a new file
+				fileRef = new File(
+					name: fileName
+					linkedFileData: linkedFileData
+				)
+				FileStoreHandler.uploadFileFromDisk project_id, fileRef._id, fsPath, (err, fileStoreUrl)->
+					return callback(err) if err?
+					next project_id, folderPath, fileName, fsPath, linkedFileData, userId, fileRef, fileStoreUrl, callback
+		withLock: (project_id, folderPath, fileName, fsPath, linkedFileData, userId, fileRef, fileStoreUrl, callback) ->
+			self.mkdirp.withoutLock project_id, folderPath, (err, newFolders, folder) ->
 				return callback(err) if err?
-				callback null, file, isNewFile, newFolders, folder
+				# this calls directly into the upsertFile main task (without the beforeLock part)
+				self.upsertFile.mainTask project_id, folder._id, fileName, fsPath, linkedFileData, userId, fileRef, fileStoreUrl, (err, newFile, isNewFile, existingFile) ->
+					return callback(err) if err?
+					callback null, newFile, isNewFile, existingFile, newFolders, folder
 
 	deleteEntity: wrapWithLock (project_id, entity_id, entityType, userId, callback = (error) ->)->
 		logger.log entity_id:entity_id, entityType:entityType, project_id:project_id, "deleting project entity"
@@ -326,7 +395,7 @@ module.exports = ProjectEntityUpdateHandler = self =
 					path: file.path
 					url: FileStoreHandler._buildUrl(project_id, file.file._id)
 
-				DocumentUpdaterHandler.resyncProjectHistory project_id, docs, files, callback 
+				DocumentUpdaterHandler.resyncProjectHistory project_id, docs, files, callback
 	_cleanUpEntity: (project, entity, entityType, path, userId, callback = (error) ->) ->
 		if(entityType.indexOf("file") != -1)
 			self._cleanUpFile project, entity, path, userId, callback
@@ -348,7 +417,7 @@ module.exports = ProjectEntityUpdateHandler = self =
 
 		unsetRootDocIfRequired (error) ->
 			return callback(error) if error?
-			self._insertDeletedDocReference project._id, doc, (error) ->
+			ProjectEntityMongoUpdateHandler._insertDeletedDocReference project._id, doc, (error) ->
 				return callback(error) if error?
 				DocumentUpdaterHandler.deleteDoc project_id, doc_id, (error) ->
 					return callback(error) if error?
@@ -358,11 +427,12 @@ module.exports = ProjectEntityUpdateHandler = self =
 						DocumentUpdaterHandler.updateProjectStructure project_id, userId, changes, callback
 
 	_cleanUpFile: (project, file, path, userId, callback = (error) ->) ->
-		project_id = project._id.toString()
-		file_id = file._id.toString()
-		FileStoreHandler.deleteFile project_id, file_id, (error) ->
+		ProjectEntityMongoUpdateHandler._insertDeletedFileReference project._id, file, (error) ->
 			return callback(error) if error?
+			project_id = project._id.toString()
 			changes = oldFiles: [ {file, path} ]
+			# we are now keeping a copy of every file versio so we no longer delete
+			# the file from the filestore
 			DocumentUpdaterHandler.updateProjectStructure project_id, userId, changes, callback
 
 	_cleanUpFolder: (project, folder, folderPath, userId, callback = (error) ->) ->
@@ -383,15 +453,3 @@ module.exports = ProjectEntityUpdateHandler = self =
 				jobs.push (callback) -> self._cleanUpFolder project, childFolder, folderPath, userId, callback
 
 		async.series jobs, callback
-
-	_insertDeletedDocReference: (project_id, doc, callback = (error) ->) ->
-		Project.update {
-			_id: project_id
-		}, {
-			$push: {
-				deletedDocs: {
-					_id:  doc._id
-					name: doc.name
-				}
-			}
-		}, {}, callback

+ 2 - 2
services/web/app/coffee/infrastructure/ExpressLocals.coffee

@@ -15,6 +15,7 @@ htmlEncoder = new require("node-html-encoder").Encoder("numerical")
 hashedFiles = {}
 Path = require 'path'
 Features = require "./Features"
+Modules = require "./Modules"
 
 jsPath =
 	if Settings.useMinifiedJs
@@ -41,10 +42,9 @@ pathList = [
 	"#{jsPath}ide.js"
 	"#{jsPath}main.js"
 	"#{jsPath}libraries.js"
-	"#{jsPath}es/richText.js"
 	"/stylesheets/style.css"
 	"/stylesheets/ol-style.css"
-]
+].concat(Modules.moduleAssetFiles(jsPath))
 
 if !Settings.useMinifiedJs 
 	logger.log "not using minified JS, not hashing static files"

+ 2 - 2
services/web/app/coffee/infrastructure/Features.coffee

@@ -14,8 +14,8 @@ module.exports = Features =
 				return Settings.enableGithubSync
 			when 'v1-return-message'
 				return Settings.accountMerge? and Settings.overleaf?
-			when 'rich-text'
-				return Settings.showRichText
+			when 'publish-modal'
+				return Settings.showPublishModal
 			when 'custom-togglers'
 				return Settings.overleaf?
 			else

+ 7 - 0
services/web/app/coffee/infrastructure/Modules.coffee

@@ -43,6 +43,13 @@ module.exports = Modules =
 	moduleIncludesAvailable: (view) ->
 		return (Modules.viewIncludes[view] or []).length > 0
 	
+	moduleAssetFiles: (pathPrefix) ->
+		assetFiles = []
+		for module in @modules
+			for assetFile in module.assetFiles or []
+				assetFiles.push "#{pathPrefix}#{assetFile}"
+		return assetFiles
+
 	attachHooks: () ->
 		for module in @modules
 			if module.hooks?

+ 5 - 0
services/web/app/coffee/models/Project.coffee

@@ -12,6 +12,10 @@ ObjectId = Schema.ObjectId
 DeletedDocSchema = new Schema
 	name: String
 
+DeletedFileSchema = new Schema
+	name: String
+	deletedAt: {type: Date}
+
 ProjectSchema = new Schema
 	name              :   {type:String, default:'new project'}
 	lastUpdated       :   {type:Date, default: () -> new Date()}
@@ -30,6 +34,7 @@ ProjectSchema = new Schema
 	description : {type:String, default:''}
 	archived          : { type: Boolean }
 	deletedDocs       : [DeletedDocSchema]
+	deletedFiles      : [DeletedFileSchema]
 	imageName         : { type: String }
 	track_changes     : { type: Object }
 	tokens            :

+ 2 - 0
services/web/app/views/project/editor.pug

@@ -55,6 +55,7 @@ block content
 				include ./editor/header
 
 				include ./editor/share
+				!= moduleIncludes("publish:body", locals)
 
 				#ide-body(
 					ng-cloak,
@@ -137,6 +138,7 @@ block requirejs
 				"ide": "#{buildJsPath('ide.js', {hashedPath:settings.useMinifiedJs, removeExtension:true})}",
 				"libraries": "#{buildJsPath('libraries.js', {hashedPath:settings.useMinifiedJs, removeExtension:true})}",
 				!{moduleIncludes("editor:script", locals)}
+				!{moduleIncludes("publish:script", locals)}
 			},
 			"waitSeconds": 0,
 			"shim": {

+ 1 - 0
services/web/app/views/project/editor/editor.pug

@@ -39,6 +39,7 @@ div.full-size(
 			ace-editor="editor",
 			ng-if="!editor.richText",
 			ng-show="!!editor.sharejs_doc && !editor.opening",
+			style=showRichText ? "top: 40px" : "",
 			theme="settings.theme",
 			keybindings="settings.mode",
 			font-size="settings.fontSize",

+ 3 - 0
services/web/app/views/project/editor/header.pug

@@ -107,6 +107,9 @@ header.toolbar.toolbar-header.toolbar-with-labels(
 		)
 			i.fa.fa-fw.fa-group
 			p.toolbar-label #{translate("share")}
+
+		!= moduleIncludes('publish:button', locals)
+
 		a.btn.btn-full-height(
 			href,
 			ng-click="toggleHistory();",

+ 1 - 2
services/web/app/views/project/editor/history.pug

@@ -1,5 +1,5 @@
 div#history(ng-show="ui.view == 'history'")
-	span(ng-controller="HistoryPremiumPopup")
+	span
 		.upgrade-prompt(ng-if="project.features.versioning === false && ui.view === 'history'")
 			.message(ng-if="project.owner._id == user.id")
 				p.text-center: strong #{translate("upgrade_to_get_feature", {feature:"full Project History"})}
@@ -33,7 +33,6 @@ div#history(ng-show="ui.view == 'history'")
 						href
 						ng-class="buttonClass"
 						ng-click="startFreeTrial('history')"
-						sixpack-convert="teaser-history"
 					) #{translate("start_free_trial")}
 
 			.message(ng-show="project.owner._id != user.id")

+ 0 - 1
services/web/app/views/project/editor/pdf.pug

@@ -402,7 +402,6 @@ div.full-size.pdf(ng-controller="PdfController")
 					a.btn.btn-success.row-spaced-small(
 						href
 						ng-class="buttonClass"
-						sixpack-convert="track_changes_feature_info"
 						ng-click="startFreeTrial('compile-timeout')"
 					) #{translate("start_free_trial")}
 

+ 0 - 1
services/web/app/views/project/editor/share.pug

@@ -173,7 +173,6 @@ script(type='text/ng-template', id='shareProjectModalTemplate')
 						a.btn.btn-success(
 							href
 							ng-class="buttonClass"
-							sixpack-convert="track_changes_feature_info"
 							ng-click="startFreeTrial('projectMembers')"
 						) #{translate("start_free_trial")}
 

+ 2 - 5
services/web/app/views/project/list/side-bar.pug

@@ -10,19 +10,16 @@
 		li
 			a(
 				href,
-				sixpack-convert="first_sign_up",
 				ng-click="openCreateProjectModal()"
 			) #{translate("blank_project")}
 		li
 			a(
 				href,
-				sixpack-convert="first_sign_up",
 				ng-click="openCreateProjectModal('example')"
 			) #{translate("example_project")}
 		li
 			a(
 				href,
-				sixpack-convert="first_sign_up",
 				ng-click="openUploadProjectModal()"
 			) #{translate("upload_project")}
 		!= moduleIncludes("newProjectMenu", locals)
@@ -31,7 +28,7 @@
 			li.dropdown-header #{translate("templates")}
 			each item in templates
 				li
-					a.menu-indent(href=item.url, sixpack-convert="first_sign_up") #{translate(item.name)}
+					a.menu-indent(href=item.url) #{translate(item.name)}
 
 .row-spaced(ng-if="projects.length > 0", ng-cloak)
 	ul.list-unstyled.folders-menu(
@@ -133,7 +130,7 @@
 			hr
 			p.small #{translate("on_free_sl")}
 			p
-				a(href="/user/subscription/plans", sixpack-convert="left-menu-upgraed-rotation").btn.btn-primary #{translate("upgrade")}
+				a(href="/user/subscription/plans").btn.btn-primary #{translate("upgrade")}
 			p.small.text-centered
 				| #{translate("or_unlock_features_bonus")} 
 				a(href="/user/bonus") #{translate("sharing_sl")} .

+ 34 - 43
services/web/app/views/subscriptions/new.pug

@@ -1,8 +1,6 @@
 extends ../layout
 
 block scripts
-	script(src="https://js.recurly.com/v3/recurly.js")
-
 	script(type='text/javascript').
 		window.countryCode = '#{countryCode}'
 		window.plan_code = '#{plan_code}'
@@ -41,19 +39,20 @@ block content
 										span !{translate("first_few_days_free", {trialLen:'{{trialLength}}'})}
 										span(ng-if="discountMonths && discountRate")   -  {{discountMonths}} #{translate("month")}s {{discountRate}}% Off
 									div(ng-if="price")
-										strong {{price.currency.symbol}}{{price.next.total}} 
+										strong {{plans[currencyCode]['symbol']}}{{price.next.total}} 
 										span(ng-if="monthlyBilling")  #{translate("every")} #{translate("month")}
 										span(ng-if="!monthlyBilling")  #{translate("every")} #{translate("year")}
 									div(ng-if="normalPrice")
-										span.small Normally {{price.currency.symbol}}{{normalPrice}}
+										span.small Normally {{plans[currencyCode]['symbol']}}{{normalPrice}}
 						.row
 							div()
 								.col-md-12()
 									form(
-										ng-if="planName"
 										name="simpleCCForm"
 										novalidate
 									)
+
+										
 										div.payment-method-toggle
 											a.payment-method-toggle-switch(
 												href
@@ -75,10 +74,10 @@ block content
 										.alert.alert-warning.small(ng-show="genericError")
 											strong {{genericError}}
 
-										div(ng-if="paymentMethod.value === 'credit_card'")
+										div(ng-show="paymentMethod.value === 'credit_card'")
 											.row
 												.col-xs-6
-													.form-group(ng-class="validation.errorFields.first_name || inputHasError(simpleCCForm.firstName) ? 'has-error' : ''")
+													.form-group(ng-class="validation.errorFields.first_name || inputHasError(simpleCCForm.firstName) ? 'has-external-error' : ''")
 														label(for="first-name") #{translate('first_name')}
 														input#first-name.form-control(
 															type="text"
@@ -90,7 +89,7 @@ block content
 														)
 														span.input-feedback-message  {{ simpleCCForm.firstName.$error.required ? 'This field is required' : '' }}
 												.col-xs-6
-													.form-group(for="last-name",ng-class="validation.errorFields.last_name || inputHasError(simpleCCForm.lastName)? 'has-error' : ''")
+													.form-group(for="last-name",ng-class="validation.errorFields.last_name || inputHasError(simpleCCForm.lastName)? 'has-external-error' : ''")
 														label(for="last-name") #{translate('last_name')}
 														input#last-name.form-control(
 															type="text"
@@ -100,47 +99,41 @@ block content
 															ng-model="data.last_name"
 															required
 														)
-														span.input-feedback-message {{ simpleCCForm.lastName.$error.required ? 'This field is required' : '' }}
 
-											.form-group(ng-class="validation.correctCardNumber == false || validation.errorFields.number || inputHasError(simpleCCForm.ccNumber) ? 'has-error' : ''")
+											.form-group(ng-class="validation.errorFields.number ? 'has-external-error' : ''")
 												label(for="card-no") #{translate("credit_card_number")}
-												input#card-no.form-control(
+												div#card-no(
 													type="text"
-													ng-model="data.number"
 													name="ccNumber"
-													ng-focus="validation.correctCardNumber = true; validation.errorFields.number = false;"
-													ng-blur="validateCardNumber();"
-													required
-													cc-format-card-number
+													data-recurly='number'
 												)
-												span.input-feedback-message {{ simpleCCForm.ccNumber.$error.required ? 'This field is required' : 'Please re-check the card number' }}
 
 											.row
-												.col-xs-6
-													.form-group.has-feedback(ng-class="validation.correctExpiry == false || validation.errorFields.expiry || inputHasError(simpleCCForm.expiry) ? 'has-error' : ''")
-														label #{translate("expiry")}
-														input.form-control(
-															type="text"
-															ng-model="data.mmYY"
-															name="expiry"
-															placeholder="MM / YY"
-															ng-focus="validation.correctExpiry = true; validation.errorFields.expiry = false;"
-															ng-blur="updateExpiry(); validateExpiry()"
-															required
-															cc-format-expiry
+												.col-xs-3
+													.form-group.has-feedback(ng-class="validation.errorFields.month ? 'has-external-error' : ''")
+														label(for="month") #{translate("month")}
+														div(
+															type="number"
+															name="month"
+															data-recurly="month"
 														)
-														span.input-feedback-message {{ simpleCCForm.expiry.$error.required ? 'This field is required' : 'Please re-check the expiry date' }}
-
+												.col-xs-3
+													.form-group.has-feedback(ng-class="validation.errorFields.year ? 'has-external-error' : ''")
+														label(for="year") #{translate("year")}
+														div(
+															type="number"
+															name="year"
+															data-recurly="year"
+														)
+							
 												.col-xs-6
-													.form-group.has-feedback(ng-class="validation.correctCvv == false || validation.errorFields.cvv || inputHasError(simpleCCForm.cvv) ? 'has-error' : ''")
+													.form-group.has-feedback(ng-class="validation.errorFields.cvv ? 'has-external-error' : ''")
 														label #{translate("security_code")}
-														input.form-control(
-															type="text"
+														div(
+															type="number"
 															ng-model="data.cvv"
-															ng-focus="validation.correctCvv = true; validation.errorFields.cvv = false;"
-															ng-blur="validateCvv()"
+															data-recurly="cvv"
 															name="cvv"
-															required
 															cc-format-sec-code
 														)
 														.form-control-feedback
@@ -151,11 +144,9 @@ block content
 																tooltip-trigger="mouseenter"
 																tooltip-append-to-body="true"
 															) ?
-														span.input-feedback-message {{ simpleCCForm.cvv.$error.required ? 'This field is required' : 'Please re-check the security code' }}
 
-										
 										div
-											.form-group(ng-class="validation.errorFields.country || inputHasError(simpleCCForm.country) ? 'has-error' : ''")
+											.form-group(ng-class="validation.errorFields.country || inputHasError(simpleCCForm.country) ? 'has-external-error' : ''")
 												label(for="country") #{translate('country')}
 												select#country.form-control(
 													data-recurly="country"
@@ -189,8 +180,8 @@ block content
 											div.price-breakdown(ng-if="price.next.tax !== '0.00'")
 												hr.thin
 												span Total: 
-												strong {{price.currency.symbol}}{{price.next.total}} 
-												span ({{price.currency.symbol}}{{price.next.subtotal}} + {{price.currency.symbol}}{{price.next.tax}} tax) 
+												strong {{plans[currencyCode]['symbol']}}{{price.next.total}} 
+												span ({{plans[currencyCode]['symbol']}}{{price.next.subtotal}} + {{plans[currencyCode]['symbol']}}{{price.next.tax}} tax) 
 												span(ng-if="monthlyBilling") #{translate("every")} #{translate("month")}
 												span(ng-if="!monthlyBilling") #{translate("every")} #{translate("year")}
 												hr.thin
@@ -198,7 +189,7 @@ block content
 											div.payment-submit
 												button.btn.btn-success.btn-block(
 													ng-click="submit()"
-													ng-disabled="processing || !isFormValid(simpleCCForm);"
+													ng-disabled="processing  || !isFormValid(simpleCCForm);" 
 												) 
 													span(ng-show="processing") 
 														i.fa.fa-spinner.fa-spin

+ 6 - 12
services/web/app/views/subscriptions/plans.pug

@@ -76,7 +76,7 @@ block content
 													br
 													a.btn.btn-info(
 														href="/register"
-														style=(getLoggedInUserId() === undefined ? "" : "visibility: hidden")
+														style=(getLoggedInUserId() === null ? "" : "visibility: hidden")
 													) #{translate("sign_up_now")}
 									.col-md-4
 										.card.card-highlighted
@@ -90,10 +90,8 @@ block content
 													| {{plans[currencyCode]['collaborator']['annual']}}
 													span.small /yr
 											ul.list-unstyled
-												li 
-													strong(ng-show="plansVariant == 'default'") #{translate("collabs_per_proj", {collabcount:10})}
-													strong(ng-show="plansVariant == 'heron'") #{translate("collabs_per_proj", {collabcount:8})}
-													strong(ng-show="plansVariant == 'ibis'") #{translate("collabs_per_proj", {collabcount:12})}
+												li
+													strong #{translate("collabs_per_proj", {collabcount:10})}
 												li #{translate("full_doc_history")}
 												li #{translate("sync_to_dropbox")}
 												li #{translate("sync_to_github")}
@@ -144,7 +142,7 @@ block content
 													br
 													a.btn.btn-info(
 														href="/register"
-														style=(getLoggedInUserId() === undefined ? "" : "visibility: hidden")
+														style=(getLoggedInUserId() === null ? "" : "visibility: hidden")
 													) #{translate("sign_up_now")}
 
 									.col-md-4
@@ -157,9 +155,7 @@ block content
 													span.small /mo
 											ul.list-unstyled
 												li
-													strong(ng-show="plansVariant == 'default'") #{translate("collabs_per_proj", {collabcount:6})}
-													strong(ng-show="plansVariant == 'heron'") #{translate("collabs_per_proj", {collabcount:4})}
-													strong(ng-show="plansVariant == 'ibis'") #{translate("collabs_per_proj", {collabcount:8})}
+													strong #{translate("collabs_per_proj", {collabcount:6})}
 												li #{translate("full_doc_history")}
 												li #{translate("sync_to_dropbox")}
 												li #{translate("sync_to_github")}
@@ -180,9 +176,7 @@ block content
 													span.small /yr
 											ul.list-unstyled
 												li
-													strong(ng-show="plansVariant == 'default'") #{translate("collabs_per_proj", {collabcount:6})}
-													strong(ng-show="plansVariant == 'heron'") #{translate("collabs_per_proj", {collabcount:4})}
-													strong(ng-show="plansVariant == 'ibis'") #{translate("collabs_per_proj", {collabcount:8})}
+													strong #{translate("collabs_per_proj", {collabcount:6})}
 												li #{translate("full_doc_history")}
 												li #{translate("sync_to_dropbox")}
 												li #{translate("sync_to_github")}

+ 126 - 8
services/web/npm-shrinkwrap.json

@@ -533,6 +533,12 @@
       "resolved": "https://registry.npmjs.org/babel-helper-builder-binary-assignment-operator-visitor/-/babel-helper-builder-binary-assignment-operator-visitor-6.24.1.tgz",
       "dev": true
     },
+    "babel-helper-builder-react-jsx": {
+      "version": "6.26.0",
+      "from": "babel-helper-builder-react-jsx@>=6.24.1 <7.0.0",
+      "resolved": "https://registry.npmjs.org/babel-helper-builder-react-jsx/-/babel-helper-builder-react-jsx-6.26.0.tgz",
+      "dev": true
+    },
     "babel-helper-call-delegate": {
       "version": "6.24.1",
       "from": "babel-helper-call-delegate@>=6.24.1 <7.0.0",
@@ -629,6 +635,18 @@
       "resolved": "https://registry.npmjs.org/babel-plugin-syntax-exponentiation-operator/-/babel-plugin-syntax-exponentiation-operator-6.13.0.tgz",
       "dev": true
     },
+    "babel-plugin-syntax-flow": {
+      "version": "6.18.0",
+      "from": "babel-plugin-syntax-flow@>=6.18.0 <7.0.0",
+      "resolved": "https://registry.npmjs.org/babel-plugin-syntax-flow/-/babel-plugin-syntax-flow-6.18.0.tgz",
+      "dev": true
+    },
+    "babel-plugin-syntax-jsx": {
+      "version": "6.18.0",
+      "from": "babel-plugin-syntax-jsx@>=6.3.13 <7.0.0",
+      "resolved": "https://registry.npmjs.org/babel-plugin-syntax-jsx/-/babel-plugin-syntax-jsx-6.18.0.tgz",
+      "dev": true
+    },
     "babel-plugin-syntax-trailing-function-commas": {
       "version": "6.22.0",
       "from": "babel-plugin-syntax-trailing-function-commas@>=6.22.0 <7.0.0",
@@ -779,6 +797,36 @@
       "resolved": "https://registry.npmjs.org/babel-plugin-transform-exponentiation-operator/-/babel-plugin-transform-exponentiation-operator-6.24.1.tgz",
       "dev": true
     },
+    "babel-plugin-transform-flow-strip-types": {
+      "version": "6.22.0",
+      "from": "babel-plugin-transform-flow-strip-types@>=6.22.0 <7.0.0",
+      "resolved": "https://registry.npmjs.org/babel-plugin-transform-flow-strip-types/-/babel-plugin-transform-flow-strip-types-6.22.0.tgz",
+      "dev": true
+    },
+    "babel-plugin-transform-react-display-name": {
+      "version": "6.25.0",
+      "from": "babel-plugin-transform-react-display-name@>=6.23.0 <7.0.0",
+      "resolved": "https://registry.npmjs.org/babel-plugin-transform-react-display-name/-/babel-plugin-transform-react-display-name-6.25.0.tgz",
+      "dev": true
+    },
+    "babel-plugin-transform-react-jsx": {
+      "version": "6.24.1",
+      "from": "babel-plugin-transform-react-jsx@>=6.24.1 <7.0.0",
+      "resolved": "https://registry.npmjs.org/babel-plugin-transform-react-jsx/-/babel-plugin-transform-react-jsx-6.24.1.tgz",
+      "dev": true
+    },
+    "babel-plugin-transform-react-jsx-self": {
+      "version": "6.22.0",
+      "from": "babel-plugin-transform-react-jsx-self@>=6.22.0 <7.0.0",
+      "resolved": "https://registry.npmjs.org/babel-plugin-transform-react-jsx-self/-/babel-plugin-transform-react-jsx-self-6.22.0.tgz",
+      "dev": true
+    },
+    "babel-plugin-transform-react-jsx-source": {
+      "version": "6.22.0",
+      "from": "babel-plugin-transform-react-jsx-source@>=6.22.0 <7.0.0",
+      "resolved": "https://registry.npmjs.org/babel-plugin-transform-react-jsx-source/-/babel-plugin-transform-react-jsx-source-6.22.0.tgz",
+      "dev": true
+    },
     "babel-plugin-transform-regenerator": {
       "version": "6.26.0",
       "from": "babel-plugin-transform-regenerator@>=6.22.0 <7.0.0",
@@ -805,6 +853,18 @@
         }
       }
     },
+    "babel-preset-flow": {
+      "version": "6.23.0",
+      "from": "babel-preset-flow@>=6.23.0 <7.0.0",
+      "resolved": "https://registry.npmjs.org/babel-preset-flow/-/babel-preset-flow-6.23.0.tgz",
+      "dev": true
+    },
+    "babel-preset-react": {
+      "version": "6.24.1",
+      "from": "babel-preset-react@>=6.16.0 <7.0.0",
+      "resolved": "https://registry.npmjs.org/babel-preset-react/-/babel-preset-react-6.24.1.tgz",
+      "dev": true
+    },
     "babel-register": {
       "version": "6.26.0",
       "from": "babel-register@>=6.26.0 <7.0.0",
@@ -2031,6 +2091,11 @@
       "resolved": "https://registry.npmjs.org/create-hmac/-/create-hmac-1.1.6.tgz",
       "dev": true
     },
+    "create-react-class": {
+      "version": "15.6.3",
+      "from": "create-react-class@>=15.6.0 <16.0.0",
+      "resolved": "https://registry.npmjs.org/create-react-class/-/create-react-class-15.6.3.tgz"
+    },
     "cross-spawn": {
       "version": "5.1.0",
       "from": "cross-spawn@>=5.0.1 <6.0.0",
@@ -3429,6 +3494,23 @@
       "resolved": "https://registry.npmjs.org/faye-websocket/-/faye-websocket-0.10.0.tgz",
       "dev": true
     },
+    "fbjs": {
+      "version": "0.8.16",
+      "from": "fbjs@>=0.8.9 <0.9.0",
+      "resolved": "https://registry.npmjs.org/fbjs/-/fbjs-0.8.16.tgz",
+      "dependencies": {
+        "core-js": {
+          "version": "1.2.7",
+          "from": "core-js@>=1.0.0 <2.0.0",
+          "resolved": "https://registry.npmjs.org/core-js/-/core-js-1.2.7.tgz"
+        },
+        "promise": {
+          "version": "7.3.1",
+          "from": "promise@>=7.1.1 <8.0.0",
+          "resolved": "https://registry.npmjs.org/promise/-/promise-7.3.1.tgz"
+        }
+      }
+    },
     "fd-slicer": {
       "version": "1.0.1",
       "from": "fd-slicer@>=1.0.1 <1.1.0",
@@ -3744,6 +3826,11 @@
       "resolved": "https://registry.npmjs.org/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz",
       "dev": true
     },
+    "fuse.js": {
+      "version": "3.2.0",
+      "from": "fuse.js@>=3.0.0 <4.0.0",
+      "resolved": "https://registry.npmjs.org/fuse.js/-/fuse.js-3.2.0.tgz"
+    },
     "gauge": {
       "version": "2.7.4",
       "from": "gauge@>=2.7.3 <2.8.0",
@@ -5307,8 +5394,7 @@
     "is-stream": {
       "version": "1.1.0",
       "from": "is-stream@>=1.1.0 <2.0.0",
-      "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz",
-      "dev": true
+      "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz"
     },
     "is-symbol": {
       "version": "1.0.1",
@@ -5355,6 +5441,11 @@
       "resolved": "https://registry.npmjs.org/isobject/-/isobject-3.0.1.tgz",
       "dev": true
     },
+    "isomorphic-fetch": {
+      "version": "2.2.1",
+      "from": "isomorphic-fetch@>=2.1.1 <3.0.0",
+      "resolved": "https://registry.npmjs.org/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz"
+    },
     "isstream": {
       "version": "0.1.2",
       "from": "isstream@>=0.1.2 <0.2.0",
@@ -5391,8 +5482,7 @@
     "js-tokens": {
       "version": "3.0.2",
       "from": "js-tokens@>=3.0.2 <4.0.0",
-      "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz",
-      "dev": true
+      "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz"
     },
     "js-yaml": {
       "version": "2.0.5",
@@ -6858,8 +6948,7 @@
     "loose-envify": {
       "version": "1.3.1",
       "from": "loose-envify@>=1.0.0 <2.0.0",
-      "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.3.1.tgz",
-      "dev": true
+      "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.3.1.tgz"
     },
     "loud-rejection": {
       "version": "1.6.0",
@@ -7620,6 +7709,11 @@
       "from": "nocache@2.0.0",
       "resolved": "https://registry.npmjs.org/nocache/-/nocache-2.0.0.tgz"
     },
+    "node-fetch": {
+      "version": "1.7.3",
+      "from": "node-fetch@>=1.0.1 <2.0.0",
+      "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz"
+    },
     "node-forge": {
       "version": "0.2.24",
       "from": "node-forge@0.2.24",
@@ -8663,6 +8757,11 @@
       "resolved": "https://registry.npmjs.org/prompt/-/prompt-0.2.14.tgz",
       "dev": true
     },
+    "prop-types": {
+      "version": "15.6.1",
+      "from": "prop-types@>=15.5.10 <16.0.0",
+      "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.6.1.tgz"
+    },
     "proxy-addr": {
       "version": "1.0.10",
       "from": "proxy-addr@>=1.0.8 <1.1.0",
@@ -8967,6 +9066,16 @@
         }
       }
     },
+    "react": {
+      "version": "15.6.2",
+      "from": "react@>=15.4.2 <16.0.0",
+      "resolved": "https://registry.npmjs.org/react/-/react-15.6.2.tgz"
+    },
+    "react-dom": {
+      "version": "15.6.2",
+      "from": "react-dom@>=15.4.2 <16.0.0",
+      "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-15.6.2.tgz"
+    },
     "read": {
       "version": "1.0.7",
       "from": "read@>=1.0.0 <1.1.0",
@@ -9676,8 +9785,7 @@
     "setimmediate": {
       "version": "1.0.5",
       "from": "setimmediate@>=1.0.4 <2.0.0",
-      "resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz",
-      "dev": true
+      "resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz"
     },
     "setprototypeof": {
       "version": "1.0.3",
@@ -10945,6 +11053,11 @@
       "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz",
       "dev": true
     },
+    "ua-parser-js": {
+      "version": "0.7.17",
+      "from": "ua-parser-js@>=0.7.9 <0.8.0",
+      "resolved": "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-0.7.17.tgz"
+    },
     "uglify-js": {
       "version": "2.4.24",
       "from": "uglify-js@>=2.4.0 <2.5.0",
@@ -12061,6 +12174,11 @@
       "resolved": "https://registry.npmjs.org/websocket-extensions/-/websocket-extensions-0.1.3.tgz",
       "dev": true
     },
+    "whatwg-fetch": {
+      "version": "2.0.4",
+      "from": "whatwg-fetch@>=0.10.0",
+      "resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-2.0.4.tgz"
+    },
     "when": {
       "version": "3.7.8",
       "from": "when@>=3.7.7 <4.0.0",

+ 4 - 0
services/web/package.json

@@ -42,6 +42,7 @@
     "express-http-proxy": "^1.1.0",
     "express-session": "^1.14.2",
     "fs-extra": "^4.0.2",
+    "fuse.js": "^3.0.0",
     "heapdump": "^0.3.7",
     "helmet": "^3.8.1",
     "http-proxy": "^1.8.1",
@@ -72,6 +73,8 @@
     "passport-oauth2-refresh": "^1.0.0",
     "passport-saml": "^0.15.0",
     "pug": "^2.0.0-beta6",
+    "react": "^15.4.2",
+    "react-dom": "^15.4.2",
     "redis-sharelatex": "git+https://github.com/sharelatex/redis-sharelatex.git#v1.0.4",
     "request": "^2.69.0",
     "requestretry": "^1.13.0",
@@ -95,6 +98,7 @@
     "babel-core": "^6.26.0",
     "babel-loader": "^7.1.2",
     "babel-preset-env": "^1.6.1",
+    "babel-preset-react": "^6.16.0",
     "bunyan": "0.22.1",
     "chai": "3.5.0",
     "chai-spies": "",

+ 7 - 0
services/web/public/coffee/ide/directives/layout.coffee

@@ -119,6 +119,7 @@ define [
 						customTogglerScope = scope.$new()
 
 						customTogglerScope.isOpen = true
+						customTogglerScope.isVisible = true
 
 						if state[customTogglerPane]?.initClosed == true
 							customTogglerScope.isOpen = false
@@ -132,6 +133,7 @@ define [
 							repositionCustomToggler()
 						customTogglerEl = $compile("
 							<a href 
+							   ng-show=\"isVisible\"
 							   class=\"custom-toggler #{ 'custom-toggler-' + customTogglerPane }\"
 							   ng-class=\"isOpen ? 'custom-toggler-open' : 'custom-toggler-closed'\"
 							   tooltip=\"{{ isOpen ? tooltipMsgWhenOpen : tooltipMsgWhenClosed }}\"
@@ -186,6 +188,11 @@ define [
 								element.layout().hide("east")
 							else
 								element.layout().show("east")
+							if hasCustomToggler
+								customTogglerEl.scope().$applyAsync () ->
+									customTogglerEl.scope().isOpen = !value
+									customTogglerEl.scope().isVisible = !value
+
 
 				post: (scope, element, attrs) ->
 					name = attrs.layout

+ 0 - 9
services/web/public/coffee/ide/history/controllers/HistoryListController.coffee

@@ -3,15 +3,6 @@ define [
 	"ide/history/util/displayNameForUser"
 ], (App, displayNameForUser) ->
 
-	App.controller "HistoryPremiumPopup", ($scope, ide, sixpack)->
-		$scope.$watch "ui.view", ->
-			if $scope.ui.view == "history"
-				if $scope.project?.features?.versioning
-					$scope.versioningPopupType = "default"
-				else if $scope.ui.view == "history"
-					sixpack.participate 'history-discount', ['default', 'discount'], (chosenVariation, rawResponse)->
-						$scope.versioningPopupType = chosenVariation
-
 	App.controller "HistoryListController", ["$scope", "ide", ($scope, ide) ->
 		$scope.hoveringOverListSelectors = false
 

+ 2 - 18
services/web/public/coffee/main/account-upgrade.coffee

@@ -19,24 +19,8 @@ define [
 						url = "#{url}&cc=#{couponCode}"
 				$scope.startedFreeTrial = true
 
-				switch source
-					when "dropbox"
-						sixpack.participate 'teaser-dropbox-text', ['default', 'dropbox-focused'], (variant) ->
-							event_tracking.sendMB "subscription-start-trial", { source, plan, variant }
-
-					when "history"
-						sixpack.participate 'teaser-history', ['default', 'focused'], (variant) ->
-							event_tracking.sendMB "subscription-start-trial", { source, plan, variant }
-
-					else
-						event_tracking.sendMB "subscription-start-trial", { source, plan }
+				event_tracking.sendMB "subscription-start-trial", { source, plan }
 
 				w.location = url
 
-			if $scope.shouldABTestPlans
-				sixpack.participate 'plans-1610', ['default', 'heron', 'ibis'], (chosenVariation, rawResponse)->
-					if chosenVariation in ['heron', 'ibis']
-						plan = "collaborator_#{chosenVariation}"
-					go()
-			else
-				go()
+			go()

+ 20 - 35
services/web/public/coffee/main/new-subscription.coffee

@@ -1,6 +1,7 @@
 define [
 	"base",
 	"directives/creditCards"
+	"libs/recurly-4.8.5"
 ], (App)->
 
 	App.controller "NewSubscriptionController", ($scope, MultiCurrencyPricing, abTestManager, $http, sixpack, event_tracking, ccUtils)->
@@ -21,10 +22,6 @@ define [
 			value: "credit_card"
 
 		$scope.data =
-			number: ""
-			month: ""
-			year: ""
-			cvv: ""
 			first_name: ""
 			last_name: ""
 			postal_code: ""
@@ -34,16 +31,25 @@ define [
 			city:""
 			country:window.countryCode
 			coupon: window.couponCode
-			mmYY: ""
-
-		$scope.validation =
-			correctCardNumber : true
-			correctExpiry: true
-			correctCvv: true
+			
+		$scope.validation = {}
 
 		$scope.processing = false
 
-		recurly.configure window.recurlyApiKey
+		recurly.configure 
+			publicKey: window.recurlyApiKey
+			style: 
+				all: 
+					fontFamily: '"Open Sans", sans-serif',
+					fontSize: '16px',
+					fontColor: '#7a7a7a'
+				month: 
+					placeholder: 'MM'
+				year: 
+					placeholder: 'YY'
+				cvv:
+					placeholder: 'CVV'
+
 
 		pricing = recurly.Pricing()
 		window.pricing = pricing
@@ -73,6 +79,8 @@ define [
 					$scope.normalPrice += (basePrice * pricing.price.taxes[0].rate)
 			$scope.$apply()
 
+
+
 		$scope.applyCoupon = ->
 			pricing.coupon($scope.data.coupon).done()
 
@@ -83,26 +91,6 @@ define [
 			$scope.currencyCode = newCurrency
 			pricing.currency(newCurrency).done()
 
-		$scope.updateExpiry = () ->
-			parsedDateObj = ccUtils.parseExpiry $scope.data.mmYY
-			if parsedDateObj?
-				$scope.data.month = parsedDateObj.month
-				$scope.data.year = parsedDateObj.year
-
-		$scope.validateCardNumber = validateCardNumber = ->
-			$scope.validation.errorFields = {}
-			if $scope.data.number?.length != 0
-				$scope.validation.correctCardNumber = recurly.validate.cardNumber($scope.data.number)
-
-		$scope.validateExpiry = validateExpiry = ->
-			$scope.validation.errorFields = {}
-			if $scope.data.month?.length != 0 and $scope.data.year?.length != 0
-				$scope.validation.correctExpiry = recurly.validate.expiry($scope.data.month, $scope.data.year)
-
-		$scope.validateCvv = validateCvv = ->
-			$scope.validation.errorFields = {}
-			if $scope.data.cvv?.length != 0
-				$scope.validation.correctCvv = recurly.validate.cvv($scope.data.cvv)
 
 		$scope.inputHasError = inputHasError = (formItem) ->
 			if !formItem?
@@ -114,10 +102,7 @@ define [
 			if $scope.paymentMethod.value == 'paypal' 
 				return $scope.data.country != ""
 			else 
-				return (form.$valid and 
-						$scope.validation.correctCardNumber and
-						$scope.validation.correctExpiry and
-						$scope.validation.correctCvv)
+				return form.$valid
 
 		$scope.updateCountry = ->
 			pricing.address({country:$scope.data.country}).done()

+ 1 - 167
services/web/public/coffee/main/plans.coffee

@@ -1,6 +1,6 @@
 define [
 	"base"
-	"libs/recurly-3.0.5"
+	"libs/recurly-4.8.5"
 ], (App, recurly) ->
 
 
@@ -11,164 +11,6 @@ define [
 		return {
 			currencyCode:currencyCode
 
-			heron:
-				USD:
-					student:
-						monthly: "$6"
-						annual: "$60"
-					collaborator:
-						monthly: "$12"
-						annual: "$144"
-				EUR:
-					student:
-						monthly: "€5"
-						annual: "€50"
-					collaborator:
-						monthly: "€11"
-						annual: "€132"
-				GBP:
-					student:
-						monthly: "£5"
-						annual: "£50"
-					collaborator:
-						monthly: "£10"
-						annual: "£120"
-				SEK:
-					student:
-						monthly: "45 kr"
-						annual: "450 kr"
-					collaborator:
-						monthly: "90 kr"
-						annual: "1080 kr"
-				CAD:
-					student:
-						monthly: "$7"
-						annual: "$70"
-					collaborator:
-						monthly: "$14"
-						annual: "$168"
-				NOK:
-					student:
-						monthly: "45 kr"
-						annual: "450 kr"
-					collaborator:
-						monthly: "90 kr"
-						annual: "1080 kr"
-				DKK:
-					student:
-						monthly: "40 kr"
-						annual: "400 kr"
-					collaborator:
-						monthly: "70 kr"
-						annual: "840 kr"
-				AUD:
-					student:
-						monthly: "$8"
-						annual: "$80"
-					collaborator:
-						monthly: "$15"
-						annual: "$180"
-				NZD:
-					student:
-						monthly: "$8"
-						annual: "$80"
-					collaborator:
-						monthly: "$15"
-						annual: "$180"
-				CHF:
-					student:
-						monthly: "Fr 6"
-						annual: "Fr 60"
-					collaborator:
-						monthly: "Fr 12"
-						annual: "Fr 144"
-				SGD:
-					student:
-						monthly: "$8"
-						annual: "$80"
-					collaborator:
-						monthly: "$16"
-						annual: "$192"
-
-			ibis:
-				USD:
-					student:
-						monthly: "$10"
-						annual: "$100"
-					collaborator:
-						monthly: "$18"
-						annual: "$216"
-				EUR:
-					student:
-						monthly: "€9"
-						annual: "€90"
-					collaborator:
-						monthly: "€17"
-						annual: "€204"
-				GBP:
-					student:
-						monthly: "£7"
-						annual: "£70"
-					collaborator:
-						monthly: "£14"
-						annual: "£168"
-				SEK:
-					student:
-						monthly: "75 kr"
-						annual: "750 kr"
-					collaborator:
-						monthly: "140 kr"
-						annual: "1680 kr"
-				CAD:
-					student:
-						monthly: "$12"
-						annual: "$120"
-					collaborator:
-						monthly: "$22"
-						annual: "$264"
-				NOK:
-					student:
-						monthly: "75 kr"
-						annual: "750 kr"
-					collaborator:
-						monthly: "140 kr"
-						annual: "1680 kr"
-				DKK:
-					student:
-						monthly: "68 kr"
-						annual: "680 kr"
-					collaborator:
-						monthly: "110 kr"
-						annual: "1320 kr"
-				AUD:
-					student:
-						monthly: "$13"
-						annual: "$130"
-					collaborator:
-						monthly: "$22"
-						annual: "$264"
-				NZD:
-					student:
-						monthly: "$14"
-						annual: "$140"
-					collaborator:
-						monthly: "$22"
-						annual: "$264"
-				CHF:
-					student:
-						monthly: "Fr 10"
-						annual: "Fr 100"
-					collaborator:
-						monthly: "Fr 18"
-						annual: "Fr 216"
-				SGD:
-					student:
-						monthly: "$14"
-						annual: "$140"
-					collaborator:
-						monthly: "$25"
-						annual: "$300"
-
 			plans:
 				USD:
 					symbol: "$"
@@ -312,14 +154,6 @@ define [
 		$scope.shouldABTestPlans = window.shouldABTestPlans
 
 		if $scope.shouldABTestPlans
-			sixpack.participate 'plans-1610', ['default', 'heron', 'ibis'], (chosenVariation, rawResponse)->
-				$scope.plansVariant = chosenVariation
-				event_tracking.sendMB 'plans-page', {plans_variant: chosenVariation}
-				if chosenVariation in ['heron', 'ibis']
-					# overwrite student plans with alternative
-					for currency, _v of $scope.plans
-						$scope.plans[currency]['student'] = MultiCurrencyPricing[chosenVariation][currency]['student']
-						$scope.plans[currency]['collaborator'] = MultiCurrencyPricing[chosenVariation][currency]['collaborator']
 				$scope.showPlans = true
 		else
 			$scope.showPlans = true

+ 0 - 2
services/web/public/coffee/main/subscription-dashboard.coffee

@@ -3,8 +3,6 @@ define [
 ], (App)->
 
 	App.controller 'SuccessfulSubscriptionController', ($scope, sixpack) ->
-		sixpack.convert 'plans-1610', () ->
-
 
 	SUBSCRIPTION_URL = "/user/subscription/update"
 

+ 0 - 4218
services/web/public/js/libs/recurly-3.0.5.js

@@ -1,4218 +0,0 @@
-;(function(){
-
-/**
- * Require the given path.
- *
- * @param {String} path
- * @return {Object} exports
- * @api public
- */
-
-function require(path, parent, orig) {
-  var resolved = require.resolve(path);
-
-  // lookup failed
-  if (null == resolved) {
-    orig = orig || path;
-    parent = parent || 'root';
-    var err = new Error('Failed to require "' + orig + '" from "' + parent + '"');
-    err.path = orig;
-    err.parent = parent;
-    err.require = true;
-    throw err;
-  }
-
-  var module = require.modules[resolved];
-
-  // perform real require()
-  // by invoking the module's
-  // registered function
-  if (!module._resolving && !module.exports) {
-    var mod = {};
-    mod.exports = {};
-    mod.client = mod.component = true;
-    module._resolving = true;
-    module.call(this, mod.exports, require.relative(resolved), mod);
-    delete module._resolving;
-    module.exports = mod.exports;
-  }
-
-  return module.exports;
-}
-
-/**
- * Registered modules.
- */
-
-require.modules = {};
-
-/**
- * Registered aliases.
- */
-
-require.aliases = {};
-
-/**
- * Resolve `path`.
- *
- * Lookup:
- *
- *   - PATH/index.js
- *   - PATH.js
- *   - PATH
- *
- * @param {String} path
- * @return {String} path or null
- * @api private
- */
-
-require.resolve = function(path) {
-  if (path.charAt(0) === '/') path = path.slice(1);
-
-  var paths = [
-    path,
-    path + '.js',
-    path + '.json',
-    path + '/index.js',
-    path + '/index.json'
-  ];
-
-  for (var i = 0; i < paths.length; i++) {
-    var path = paths[i];
-    if (require.modules.hasOwnProperty(path)) return path;
-    if (require.aliases.hasOwnProperty(path)) return require.aliases[path];
-  }
-};
-
-/**
- * Normalize `path` relative to the current path.
- *
- * @param {String} curr
- * @param {String} path
- * @return {String}
- * @api private
- */
-
-require.normalize = function(curr, path) {
-  var segs = [];
-
-  if ('.' != path.charAt(0)) return path;
-
-  curr = curr.split('/');
-  path = path.split('/');
-
-  for (var i = 0; i < path.length; ++i) {
-    if ('..' == path[i]) {
-      curr.pop();
-    } else if ('.' != path[i] && '' != path[i]) {
-      segs.push(path[i]);
-    }
-  }
-
-  return curr.concat(segs).join('/');
-};
-
-/**
- * Register module at `path` with callback `definition`.
- *
- * @param {String} path
- * @param {Function} definition
- * @api private
- */
-
-require.register = function(path, definition) {
-  require.modules[path] = definition;
-};
-
-/**
- * Alias a module definition.
- *
- * @param {String} from
- * @param {String} to
- * @api private
- */
-
-require.alias = function(from, to) {
-  if (!require.modules.hasOwnProperty(from)) {
-    throw new Error('Failed to alias "' + from + '", it does not exist');
-  }
-  require.aliases[to] = from;
-};
-
-/**
- * Return a require function relative to the `parent` path.
- *
- * @param {String} parent
- * @return {Function}
- * @api private
- */
-
-require.relative = function(parent) {
-  var p = require.normalize(parent, '..');
-
-  /**
-   * lastIndexOf helper.
-   */
-
-  function lastIndexOf(arr, obj) {
-    var i = arr.length;
-    while (i--) {
-      if (arr[i] === obj) return i;
-    }
-    return -1;
-  }
-
-  /**
-   * The relative require() itself.
-   */
-
-  function localRequire(path) {
-    var resolved = localRequire.resolve(path);
-    return require(resolved, parent, path);
-  }
-
-  /**
-   * Resolve relative to the parent.
-   */
-
-  localRequire.resolve = function(path) {
-    var c = path.charAt(0);
-    if ('/' == c) return path.slice(1);
-    if ('.' == c) return require.normalize(p, path);
-
-    // resolve deps by returning
-    // the dep in the nearest "deps"
-    // directory
-    var segs = parent.split('/');
-    var i = lastIndexOf(segs, 'deps') + 1;
-    if (!i) i = 0;
-    path = segs.slice(0, i + 1).join('/') + '/deps/' + path;
-    return path;
-  };
-
-  /**
-   * Check if module is defined at `path`.
-   */
-
-  localRequire.exists = function(path) {
-    return require.modules.hasOwnProperty(localRequire.resolve(path));
-  };
-
-  return localRequire;
-};
-require.register("visionmedia-node-querystring/index.js", function(exports, require, module){
-/**
- * Object#toString() ref for stringify().
- */
-
-var toString = Object.prototype.toString;
-
-/**
- * Object#hasOwnProperty ref
- */
-
-var hasOwnProperty = Object.prototype.hasOwnProperty;
-
-/**
- * Array#indexOf shim.
- */
-
-var indexOf = typeof Array.prototype.indexOf === 'function'
-  ? function(arr, el) { return arr.indexOf(el); }
-  : function(arr, el) {
-      for (var i = 0; i < arr.length; i++) {
-        if (arr[i] === el) return i;
-      }
-      return -1;
-    };
-
-/**
- * Array.isArray shim.
- */
-
-var isArray = Array.isArray || function(arr) {
-  return toString.call(arr) == '[object Array]';
-};
-
-/**
- * Object.keys shim.
- */
-
-var objectKeys = Object.keys || function(obj) {
-  var ret = [];
-  for (var key in obj) {
-    if (obj.hasOwnProperty(key)) {
-      ret.push(key);
-    }
-  }
-  return ret;
-};
-
-/**
- * Array#forEach shim.
- */
-
-var forEach = typeof Array.prototype.forEach === 'function'
-  ? function(arr, fn) { return arr.forEach(fn); }
-  : function(arr, fn) {
-      for (var i = 0; i < arr.length; i++) fn(arr[i]);
-    };
-
-/**
- * Array#reduce shim.
- */
-
-var reduce = function(arr, fn, initial) {
-  if (typeof arr.reduce === 'function') return arr.reduce(fn, initial);
-  var res = initial;
-  for (var i = 0; i < arr.length; i++) res = fn(res, arr[i]);
-  return res;
-};
-
-/**
- * Cache non-integer test regexp.
- */
-
-var isint = /^[0-9]+$/;
-
-function promote(parent, key) {
-  if (parent[key].length == 0) return parent[key] = {}
-  var t = {};
-  for (var i in parent[key]) {
-    if (hasOwnProperty.call(parent[key], i)) {
-      t[i] = parent[key][i];
-    }
-  }
-  parent[key] = t;
-  return t;
-}
-
-function parse(parts, parent, key, val) {
-  var part = parts.shift();
-  
-  // illegal
-  if (Object.getOwnPropertyDescriptor(Object.prototype, key)) return;
-  
-  // end
-  if (!part) {
-    if (isArray(parent[key])) {
-      parent[key].push(val);
-    } else if ('object' == typeof parent[key]) {
-      parent[key] = val;
-    } else if ('undefined' == typeof parent[key]) {
-      parent[key] = val;
-    } else {
-      parent[key] = [parent[key], val];
-    }
-    // array
-  } else {
-    var obj = parent[key] = parent[key] || [];
-    if (']' == part) {
-      if (isArray(obj)) {
-        if ('' != val) obj.push(val);
-      } else if ('object' == typeof obj) {
-        obj[objectKeys(obj).length] = val;
-      } else {
-        obj = parent[key] = [parent[key], val];
-      }
-      // prop
-    } else if (~indexOf(part, ']')) {
-      part = part.substr(0, part.length - 1);
-      if (!isint.test(part) && isArray(obj)) obj = promote(parent, key);
-      parse(parts, obj, part, val);
-      // key
-    } else {
-      if (!isint.test(part) && isArray(obj)) obj = promote(parent, key);
-      parse(parts, obj, part, val);
-    }
-  }
-}
-
-/**
- * Merge parent key/val pair.
- */
-
-function merge(parent, key, val){
-  if (~indexOf(key, ']')) {
-    var parts = key.split('[')
-      , len = parts.length
-      , last = len - 1;
-    parse(parts, parent, 'base', val);
-    // optimize
-  } else {
-    if (!isint.test(key) && isArray(parent.base)) {
-      var t = {};
-      for (var k in parent.base) t[k] = parent.base[k];
-      parent.base = t;
-    }
-    set(parent.base, key, val);
-  }
-
-  return parent;
-}
-
-/**
- * Compact sparse arrays.
- */
-
-function compact(obj) {
-  if ('object' != typeof obj) return obj;
-
-  if (isArray(obj)) {
-    var ret = [];
-
-    for (var i in obj) {
-      if (hasOwnProperty.call(obj, i)) {
-        ret.push(obj[i]);
-      }
-    }
-
-    return ret;
-  }
-
-  for (var key in obj) {
-    obj[key] = compact(obj[key]);
-  }
-
-  return obj;
-}
-
-/**
- * Parse the given obj.
- */
-
-function parseObject(obj){
-  var ret = { base: {} };
-
-  forEach(objectKeys(obj), function(name){
-    merge(ret, name, obj[name]);
-  });
-
-  return compact(ret.base);
-}
-
-/**
- * Parse the given str.
- */
-
-function parseString(str){
-  var ret = reduce(String(str).split('&'), function(ret, pair){
-    var eql = indexOf(pair, '=')
-      , brace = lastBraceInKey(pair)
-      , key = pair.substr(0, brace || eql)
-      , val = pair.substr(brace || eql, pair.length)
-      , val = val.substr(indexOf(val, '=') + 1, val.length);
-
-    // ?foo
-    if ('' == key) key = pair, val = '';
-    if ('' == key) return ret;
-
-    return merge(ret, decode(key), decode(val));
-  }, { base: {} }).base;
-
-  return compact(ret);
-}
-
-/**
- * Parse the given query `str` or `obj`, returning an object.
- *
- * @param {String} str | {Object} obj
- * @return {Object}
- * @api public
- */
-
-exports.parse = function(str){
-  if (null == str || '' == str) return {};
-  return 'object' == typeof str
-    ? parseObject(str)
-    : parseString(str);
-};
-
-/**
- * Turn the given `obj` into a query string
- *
- * @param {Object} obj
- * @return {String}
- * @api public
- */
-
-var stringify = exports.stringify = function(obj, prefix) {
-  if (isArray(obj)) {
-    return stringifyArray(obj, prefix);
-  } else if ('[object Object]' == toString.call(obj)) {
-    return stringifyObject(obj, prefix);
-  } else if ('string' == typeof obj) {
-    return stringifyString(obj, prefix);
-  } else {
-    return prefix + '=' + encodeURIComponent(String(obj));
-  }
-};
-
-/**
- * Stringify the given `str`.
- *
- * @param {String} str
- * @param {String} prefix
- * @return {String}
- * @api private
- */
-
-function stringifyString(str, prefix) {
-  if (!prefix) throw new TypeError('stringify expects an object');
-  return prefix + '=' + encodeURIComponent(str);
-}
-
-/**
- * Stringify the given `arr`.
- *
- * @param {Array} arr
- * @param {String} prefix
- * @return {String}
- * @api private
- */
-
-function stringifyArray(arr, prefix) {
-  var ret = [];
-  if (!prefix) throw new TypeError('stringify expects an object');
-  for (var i = 0; i < arr.length; i++) {
-    ret.push(stringify(arr[i], prefix + '[' + i + ']'));
-  }
-  return ret.join('&');
-}
-
-/**
- * Stringify the given `obj`.
- *
- * @param {Object} obj
- * @param {String} prefix
- * @return {String}
- * @api private
- */
-
-function stringifyObject(obj, prefix) {
-  var ret = []
-    , keys = objectKeys(obj)
-    , key;
-
-  for (var i = 0, len = keys.length; i < len; ++i) {
-    key = keys[i];
-    if ('' == key) continue;
-    if (null == obj[key]) {
-      ret.push(encodeURIComponent(key) + '=');
-    } else {
-      ret.push(stringify(obj[key], prefix
-        ? prefix + '[' + encodeURIComponent(key) + ']'
-        : encodeURIComponent(key)));
-    }
-  }
-
-  return ret.join('&');
-}
-
-/**
- * Set `obj`'s `key` to `val` respecting
- * the weird and wonderful syntax of a qs,
- * where "foo=bar&foo=baz" becomes an array.
- *
- * @param {Object} obj
- * @param {String} key
- * @param {String} val
- * @api private
- */
-
-function set(obj, key, val) {
-  var v = obj[key];
-  if (Object.getOwnPropertyDescriptor(Object.prototype, key)) return;
-  if (undefined === v) {
-    obj[key] = val;
-  } else if (isArray(v)) {
-    v.push(val);
-  } else {
-    obj[key] = [v, val];
-  }
-}
-
-/**
- * Locate last brace in `str` within the key.
- *
- * @param {String} str
- * @return {Number}
- * @api private
- */
-
-function lastBraceInKey(str) {
-  var len = str.length
-    , brace
-    , c;
-  for (var i = 0; i < len; ++i) {
-    c = str[i];
-    if (']' == c) brace = false;
-    if ('[' == c) brace = true;
-    if ('=' == c && !brace) return i;
-  }
-}
-
-/**
- * Decode `str`.
- *
- * @param {String} str
- * @return {String}
- * @api private
- */
-
-function decode(str) {
-  try {
-    return decodeURIComponent(str.replace(/\+/g, ' '));
-  } catch (err) {
-    return str;
-  }
-}
-
-});
-require.register("component-emitter/index.js", function(exports, require, module){
-
-/**
- * Expose `Emitter`.
- */
-
-module.exports = Emitter;
-
-/**
- * Initialize a new `Emitter`.
- *
- * @api public
- */
-
-function Emitter(obj) {
-  if (obj) return mixin(obj);
-};
-
-/**
- * Mixin the emitter properties.
- *
- * @param {Object} obj
- * @return {Object}
- * @api private
- */
-
-function mixin(obj) {
-  for (var key in Emitter.prototype) {
-    obj[key] = Emitter.prototype[key];
-  }
-  return obj;
-}
-
-/**
- * Listen on the given `event` with `fn`.
- *
- * @param {String} event
- * @param {Function} fn
- * @return {Emitter}
- * @api public
- */
-
-Emitter.prototype.on =
-Emitter.prototype.addEventListener = function(event, fn){
-  this._callbacks = this._callbacks || {};
-  (this._callbacks[event] = this._callbacks[event] || [])
-    .push(fn);
-  return this;
-};
-
-/**
- * Adds an `event` listener that will be invoked a single
- * time then automatically removed.
- *
- * @param {String} event
- * @param {Function} fn
- * @return {Emitter}
- * @api public
- */
-
-Emitter.prototype.once = function(event, fn){
-  var self = this;
-  this._callbacks = this._callbacks || {};
-
-  function on() {
-    self.off(event, on);
-    fn.apply(this, arguments);
-  }
-
-  on.fn = fn;
-  this.on(event, on);
-  return this;
-};
-
-/**
- * Remove the given callback for `event` or all
- * registered callbacks.
- *
- * @param {String} event
- * @param {Function} fn
- * @return {Emitter}
- * @api public
- */
-
-Emitter.prototype.off =
-Emitter.prototype.removeListener =
-Emitter.prototype.removeAllListeners =
-Emitter.prototype.removeEventListener = function(event, fn){
-  this._callbacks = this._callbacks || {};
-
-  // all
-  if (0 == arguments.length) {
-    this._callbacks = {};
-    return this;
-  }
-
-  // specific event
-  var callbacks = this._callbacks[event];
-  if (!callbacks) return this;
-
-  // remove all handlers
-  if (1 == arguments.length) {
-    delete this._callbacks[event];
-    return this;
-  }
-
-  // remove specific handler
-  var cb;
-  for (var i = 0; i < callbacks.length; i++) {
-    cb = callbacks[i];
-    if (cb === fn || cb.fn === fn) {
-      callbacks.splice(i, 1);
-      break;
-    }
-  }
-  return this;
-};
-
-/**
- * Emit `event` with the given args.
- *
- * @param {String} event
- * @param {Mixed} ...
- * @return {Emitter}
- */
-
-Emitter.prototype.emit = function(event){
-  this._callbacks = this._callbacks || {};
-  var args = [].slice.call(arguments, 1)
-    , callbacks = this._callbacks[event];
-
-  if (callbacks) {
-    callbacks = callbacks.slice(0);
-    for (var i = 0, len = callbacks.length; i < len; ++i) {
-      callbacks[i].apply(this, args);
-    }
-  }
-
-  return this;
-};
-
-/**
- * Return array of callbacks for `event`.
- *
- * @param {String} event
- * @return {Array}
- * @api public
- */
-
-Emitter.prototype.listeners = function(event){
-  this._callbacks = this._callbacks || {};
-  return this._callbacks[event] || [];
-};
-
-/**
- * Check if this emitter has `event` handlers.
- *
- * @param {String} event
- * @return {Boolean}
- * @api public
- */
-
-Emitter.prototype.hasListeners = function(event){
-  return !! this.listeners(event).length;
-};
-
-});
-require.register("component-indexof/index.js", function(exports, require, module){
-module.exports = function(arr, obj){
-  if (arr.indexOf) return arr.indexOf(obj);
-  for (var i = 0; i < arr.length; ++i) {
-    if (arr[i] === obj) return i;
-  }
-  return -1;
-};
-});
-require.register("component-object/index.js", function(exports, require, module){
-
-/**
- * HOP ref.
- */
-
-var has = Object.prototype.hasOwnProperty;
-
-/**
- * Return own keys in `obj`.
- *
- * @param {Object} obj
- * @return {Array}
- * @api public
- */
-
-exports.keys = Object.keys || function(obj){
-  var keys = [];
-  for (var key in obj) {
-    if (has.call(obj, key)) {
-      keys.push(key);
-    }
-  }
-  return keys;
-};
-
-/**
- * Return own values in `obj`.
- *
- * @param {Object} obj
- * @return {Array}
- * @api public
- */
-
-exports.values = function(obj){
-  var vals = [];
-  for (var key in obj) {
-    if (has.call(obj, key)) {
-      vals.push(obj[key]);
-    }
-  }
-  return vals;
-};
-
-/**
- * Merge `b` into `a`.
- *
- * @param {Object} a
- * @param {Object} b
- * @return {Object} a
- * @api public
- */
-
-exports.merge = function(a, b){
-  for (var key in b) {
-    if (has.call(b, key)) {
-      a[key] = b[key];
-    }
-  }
-  return a;
-};
-
-/**
- * Return length of `obj`.
- *
- * @param {Object} obj
- * @return {Number}
- * @api public
- */
-
-exports.length = function(obj){
-  return exports.keys(obj).length;
-};
-
-/**
- * Check if `obj` is empty.
- *
- * @param {Object} obj
- * @return {Boolean}
- * @api public
- */
-
-exports.isEmpty = function(obj){
-  return 0 == exports.length(obj);
-};
-});
-require.register("component-event/index.js", function(exports, require, module){
-var bind = window.addEventListener ? 'addEventListener' : 'attachEvent',
-    unbind = window.removeEventListener ? 'removeEventListener' : 'detachEvent',
-    prefix = bind !== 'addEventListener' ? 'on' : '';
-
-/**
- * Bind `el` event `type` to `fn`.
- *
- * @param {Element} el
- * @param {String} type
- * @param {Function} fn
- * @param {Boolean} capture
- * @return {Function}
- * @api public
- */
-
-exports.bind = function(el, type, fn, capture){
-  el[bind](prefix + type, fn, capture || false);
-  return fn;
-};
-
-/**
- * Unbind `el` event `type`'s callback `fn`.
- *
- * @param {Element} el
- * @param {String} type
- * @param {Function} fn
- * @param {Boolean} capture
- * @return {Function}
- * @api public
- */
-
-exports.unbind = function(el, type, fn, capture){
-  el[unbind](prefix + type, fn, capture || false);
-  return fn;
-};
-});
-require.register("component-clone/index.js", function(exports, require, module){
-/**
- * Module dependencies.
- */
-
-var type;
-try {
-  type = require('component-type');
-} catch (_) {
-  type = require('type');
-}
-
-/**
- * Module exports.
- */
-
-module.exports = clone;
-
-/**
- * Clones objects.
- *
- * @param {Mixed} any object
- * @api public
- */
-
-function clone(obj){
-  switch (type(obj)) {
-    case 'object':
-      var copy = {};
-      for (var key in obj) {
-        if (obj.hasOwnProperty(key)) {
-          copy[key] = clone(obj[key]);
-        }
-      }
-      return copy;
-
-    case 'array':
-      var copy = new Array(obj.length);
-      for (var i = 0, l = obj.length; i < l; i++) {
-        copy[i] = clone(obj[i]);
-      }
-      return copy;
-
-    case 'regexp':
-      // from millermedeiros/amd-utils - MIT
-      var flags = '';
-      flags += obj.multiline ? 'm' : '';
-      flags += obj.global ? 'g' : '';
-      flags += obj.ignoreCase ? 'i' : '';
-      return new RegExp(obj.source, flags);
-
-    case 'date':
-      return new Date(obj.getTime());
-
-    default: // string, number, boolean, …
-      return obj;
-  }
-}
-
-});
-require.register("component-bind/index.js", function(exports, require, module){
-
-/**
- * Slice reference.
- */
-
-var slice = [].slice;
-
-/**
- * Bind `obj` to `fn`.
- *
- * @param {Object} obj
- * @param {Function|String} fn or string
- * @return {Function}
- * @api public
- */
-
-module.exports = function(obj, fn){
-  if ('string' == typeof fn) fn = obj[fn];
-  if ('function' != typeof fn) throw new Error('bind() requires a function');
-  var args = [].slice.call(arguments, 2);
-  return function(){
-    return fn.apply(obj, args.concat(slice.call(arguments)));
-  }
-};
-
-});
-require.register("component-props/index.js", function(exports, require, module){
-/**
- * Global Names
- */
-
-var globals = /\b(this|Array|Date|Object|Math|JSON)\b/g;
-
-/**
- * Return immediate identifiers parsed from `str`.
- *
- * @param {String} str
- * @param {String|Function} map function or prefix
- * @return {Array}
- * @api public
- */
-
-module.exports = function(str, fn){
-  var p = unique(props(str));
-  if (fn && 'string' == typeof fn) fn = prefixed(fn);
-  if (fn) return map(str, p, fn);
-  return p;
-};
-
-/**
- * Return immediate identifiers in `str`.
- *
- * @param {String} str
- * @return {Array}
- * @api private
- */
-
-function props(str) {
-  return str
-    .replace(/\.\w+|\w+ *\(|"[^"]*"|'[^']*'|\/([^/]+)\//g, '')
-    .replace(globals, '')
-    .match(/[$a-zA-Z_]\w*/g)
-    || [];
-}
-
-/**
- * Return `str` with `props` mapped with `fn`.
- *
- * @param {String} str
- * @param {Array} props
- * @param {Function} fn
- * @return {String}
- * @api private
- */
-
-function map(str, props, fn) {
-  var re = /\.\w+|\w+ *\(|"[^"]*"|'[^']*'|\/([^/]+)\/|[a-zA-Z_]\w*/g;
-  return str.replace(re, function(_){
-    if ('(' == _[_.length - 1]) return fn(_);
-    if (!~props.indexOf(_)) return _;
-    return fn(_);
-  });
-}
-
-/**
- * Return unique array.
- *
- * @param {Array} arr
- * @return {Array}
- * @api private
- */
-
-function unique(arr) {
-  var ret = [];
-
-  for (var i = 0; i < arr.length; i++) {
-    if (~ret.indexOf(arr[i])) continue;
-    ret.push(arr[i]);
-  }
-
-  return ret;
-}
-
-/**
- * Map with prefix `str`.
- */
-
-function prefixed(str) {
-  return function(_){
-    return str + _;
-  };
-}
-
-});
-require.register("component-to-function/index.js", function(exports, require, module){
-/**
- * Module Dependencies
- */
-
-var expr = require('props');
-
-/**
- * Expose `toFunction()`.
- */
-
-module.exports = toFunction;
-
-/**
- * Convert `obj` to a `Function`.
- *
- * @param {Mixed} obj
- * @return {Function}
- * @api private
- */
-
-function toFunction(obj) {
-  switch ({}.toString.call(obj)) {
-    case '[object Object]':
-      return objectToFunction(obj);
-    case '[object Function]':
-      return obj;
-    case '[object String]':
-      return stringToFunction(obj);
-    case '[object RegExp]':
-      return regexpToFunction(obj);
-    default:
-      return defaultToFunction(obj);
-  }
-}
-
-/**
- * Default to strict equality.
- *
- * @param {Mixed} val
- * @return {Function}
- * @api private
- */
-
-function defaultToFunction(val) {
-  return function(obj){
-    return val === obj;
-  }
-}
-
-/**
- * Convert `re` to a function.
- *
- * @param {RegExp} re
- * @return {Function}
- * @api private
- */
-
-function regexpToFunction(re) {
-  return function(obj){
-    return re.test(obj);
-  }
-}
-
-/**
- * Convert property `str` to a function.
- *
- * @param {String} str
- * @return {Function}
- * @api private
- */
-
-function stringToFunction(str) {
-  // immediate such as "> 20"
-  if (/^ *\W+/.test(str)) return new Function('_', 'return _ ' + str);
-
-  // properties such as "name.first" or "age > 18" or "age > 18 && age < 36"
-  return new Function('_', 'return ' + get(str));
-}
-
-/**
- * Convert `object` to a function.
- *
- * @param {Object} object
- * @return {Function}
- * @api private
- */
-
-function objectToFunction(obj) {
-  var match = {}
-  for (var key in obj) {
-    match[key] = typeof obj[key] === 'string'
-      ? defaultToFunction(obj[key])
-      : toFunction(obj[key])
-  }
-  return function(val){
-    if (typeof val !== 'object') return false;
-    for (var key in match) {
-      if (!(key in val)) return false;
-      if (!match[key](val[key])) return false;
-    }
-    return true;
-  }
-}
-
-/**
- * Built the getter function. Supports getter style functions
- *
- * @param {String} str
- * @return {String}
- * @api private
- */
-
-function get(str) {
-  var props = expr(str);
-  if (!props.length) return '_.' + str;
-
-  var val;
-  for(var i = 0, prop; prop = props[i]; i++) {
-    val = '_.' + prop;
-    val = "('function' == typeof " + val + " ? " + val + "() : " + val + ")";
-    str = str.replace(new RegExp(prop, 'g'), val);
-  }
-
-  return str;
-}
-
-});
-require.register("component-each/index.js", function(exports, require, module){
-
-/**
- * Module dependencies.
- */
-
-var type = require('type');
-var toFunction = require('to-function');
-
-/**
- * HOP reference.
- */
-
-var has = Object.prototype.hasOwnProperty;
-
-/**
- * Iterate the given `obj` and invoke `fn(val, i)`
- * in optional context `ctx`.
- *
- * @param {String|Array|Object} obj
- * @param {Function} fn
- * @param {Object} [ctx]
- * @api public
- */
-
-module.exports = function(obj, fn, ctx){
-  fn = toFunction(fn);
-  ctx = ctx || this;
-  switch (type(obj)) {
-    case 'array':
-      return array(obj, fn, ctx);
-    case 'object':
-      if ('number' == typeof obj.length) return array(obj, fn, ctx);
-      return object(obj, fn, ctx);
-    case 'string':
-      return string(obj, fn, ctx);
-  }
-};
-
-/**
- * Iterate string chars.
- *
- * @param {String} obj
- * @param {Function} fn
- * @param {Object} ctx
- * @api private
- */
-
-function string(obj, fn, ctx) {
-  for (var i = 0; i < obj.length; ++i) {
-    fn.call(ctx, obj.charAt(i), i);
-  }
-}
-
-/**
- * Iterate object keys.
- *
- * @param {Object} obj
- * @param {Function} fn
- * @param {Object} ctx
- * @api private
- */
-
-function object(obj, fn, ctx) {
-  for (var key in obj) {
-    if (has.call(obj, key)) {
-      fn.call(ctx, key, obj[key]);
-    }
-  }
-}
-
-/**
- * Iterate array-ish.
- *
- * @param {Array|Object} obj
- * @param {Function} fn
- * @param {Object} ctx
- * @api private
- */
-
-function array(obj, fn, ctx) {
-  for (var i = 0; i < obj.length; ++i) {
-    fn.call(ctx, obj[i], i);
-  }
-}
-
-});
-require.register("component-find/index.js", function(exports, require, module){
-
-/**
- * Module dependencies.
- */
-
-var toFunction = require('to-function');
-
-/**
- * Find the first value in `arr` with when `fn(val, i)` is truthy.
- *
- * @param {Array} arr
- * @param {Function} fn
- * @return {Array}
- * @api public
- */
-
-module.exports = function(arr, fn){
-  // callback
-  if ('function' != typeof fn) {
-    if (Object(fn) === fn) fn = objectToFunction(fn);
-    else fn = toFunction(fn);
-  }
-
-  // filter
-  for (var i = 0, len = arr.length; i < len; ++i) {
-    if (fn(arr[i], i)) return arr[i];
-  }
-};
-
-/**
- * Convert `obj` into a match function.
- *
- * @param {Object} obj
- * @return {Function}
- * @api private
- */
-
-function objectToFunction(obj) {
-  return function(o){
-    for (var key in obj) {
-      if (o[key] != obj[key]) return false;
-    }
-    return true;
-  }
-}
-});
-require.register("component-json/index.js", function(exports, require, module){
-
-module.exports = 'undefined' == typeof JSON
-  ? require('component-json-fallback')
-  : JSON;
-
-});
-require.register("component-type/index.js", function(exports, require, module){
-
-/**
- * toString ref.
- */
-
-var toString = Object.prototype.toString;
-
-/**
- * Return the type of `val`.
- *
- * @param {Mixed} val
- * @return {String}
- * @api public
- */
-
-module.exports = function(val){
-  switch (toString.call(val)) {
-    case '[object Function]': return 'function';
-    case '[object Date]': return 'date';
-    case '[object RegExp]': return 'regexp';
-    case '[object Arguments]': return 'arguments';
-    case '[object Array]': return 'array';
-    case '[object String]': return 'string';
-  }
-
-  if (val === null) return 'null';
-  if (val === undefined) return 'undefined';
-  if (val && val.nodeType === 1) return 'element';
-  if (val === Object(val)) return 'object';
-
-  return typeof val;
-};
-
-});
-require.register("component-trim/index.js", function(exports, require, module){
-
-exports = module.exports = trim;
-
-function trim(str){
-  if (str.trim) return str.trim();
-  return str.replace(/^\s*|\s*$/g, '');
-}
-
-exports.left = function(str){
-  if (str.trimLeft) return str.trimLeft();
-  return str.replace(/^\s*/, '');
-};
-
-exports.right = function(str){
-  if (str.trimRight) return str.trimRight();
-  return str.replace(/\s*$/, '');
-};
-
-});
-require.register("component-map/index.js", function(exports, require, module){
-
-/**
- * Module dependencies.
- */
-
-var toFunction = require('to-function');
-
-/**
- * Map the given `arr` with callback `fn(val, i)`.
- *
- * @param {Array} arr
- * @param {Function} fn
- * @return {Array}
- * @api public
- */
-
-module.exports = function(arr, fn){
-  var ret = [];
-  fn = toFunction(fn);
-  for (var i = 0; i < arr.length; ++i) {
-    ret.push(fn(arr[i], i));
-  }
-  return ret;
-};
-});
-require.register("yields-merge/index.js", function(exports, require, module){
-
-/**
- * merge `b`'s properties with `a`'s.
- *
- * example:
- *
- *        var user = {};
- *        merge(user, console);
- *        // > { log: fn, dir: fn ..}
- *
- * @param {Object} a
- * @param {Object} b
- * @return {Object}
- */
-
-module.exports = function (a, b) {
-  for (var k in b) a[k] = b[k];
-  return a;
-};
-
-});
-require.register("learnboost-jsonp/index.js", function(exports, require, module){
-/**
- * Module dependencies
- */
-
-var debug = require('debug')('jsonp');
-
-/**
- * Module exports.
- */
-
-module.exports = jsonp;
-
-/**
- * Callback index.
- */
-
-var count = 0;
-
-/**
- * Noop function.
- */
-
-function noop(){}
-
-/**
- * JSONP handler
- *
- * Options:
- *  - param {String} qs parameter (`callback`)
- *  - timeout {Number} how long after a timeout error is emitted (`60000`)
- *
- * @param {String} url
- * @param {Object|Function} optional options / callback
- * @param {Function} optional callback
- */
-
-function jsonp(url, opts, fn){
-  if ('function' == typeof opts) {
-    fn = opts;
-    opts = {};
-  }
-  if (!opts) opts = {};
-
-  var prefix = opts.prefix || '__jp';
-  var param = opts.param || 'callback';
-  var timeout = null != opts.timeout ? opts.timeout : 60000;
-  var enc = encodeURIComponent;
-  var target = document.getElementsByTagName('script')[0] || document.head;
-  var script;
-  var timer;
-
-  // generate a unique id for this request
-  var id = prefix + (count++);
-
-  if (timeout) {
-    timer = setTimeout(function(){
-      cleanup();
-      if (fn) fn(new Error('Timeout'));
-    }, timeout);
-  }
-
-  function cleanup(){
-    script.parentNode.removeChild(script);
-    window[id] = noop;
-  }
-
-  window[id] = function(data){
-    debug('jsonp got', data);
-    if (timer) clearTimeout(timer);
-    cleanup();
-    if (fn) fn(null, data);
-  };
-
-  // add qs component
-  url += (~url.indexOf('?') ? '&' : '?') + param + '=' + enc(id);
-  url = url.replace('?&', '?');
-
-  debug('jsonp req "%s"', url);
-
-  // create script
-  script = document.createElement('script');
-  script.src = url;
-  target.parentNode.insertBefore(script, target);
-}
-
-});
-require.register("visionmedia-debug/debug.js", function(exports, require, module){
-
-/**
- * Expose `debug()` as the module.
- */
-
-module.exports = debug;
-
-/**
- * Create a debugger with the given `name`.
- *
- * @param {String} name
- * @return {Type}
- * @api public
- */
-
-function debug(name) {
-  if (!debug.enabled(name)) return function(){};
-
-  return function(fmt){
-    fmt = coerce(fmt);
-
-    var curr = new Date;
-    var ms = curr - (debug[name] || curr);
-    debug[name] = curr;
-
-    fmt = name
-      + ' '
-      + fmt
-      + ' +' + debug.humanize(ms);
-
-    // This hackery is required for IE8
-    // where `console.log` doesn't have 'apply'
-    window.console
-      && console.log
-      && Function.prototype.apply.call(console.log, console, arguments);
-  }
-}
-
-/**
- * The currently active debug mode names.
- */
-
-debug.names = [];
-debug.skips = [];
-
-/**
- * Enables a debug mode by name. This can include modes
- * separated by a colon and wildcards.
- *
- * @param {String} name
- * @api public
- */
-
-debug.enable = function(name) {
-  try {
-    localStorage.debug = name;
-  } catch(e){}
-
-  var split = (name || '').split(/[\s,]+/)
-    , len = split.length;
-
-  for (var i = 0; i < len; i++) {
-    name = split[i].replace('*', '.*?');
-    if (name[0] === '-') {
-      debug.skips.push(new RegExp('^' + name.substr(1) + '$'));
-    }
-    else {
-      debug.names.push(new RegExp('^' + name + '$'));
-    }
-  }
-};
-
-/**
- * Disable debug output.
- *
- * @api public
- */
-
-debug.disable = function(){
-  debug.enable('');
-};
-
-/**
- * Humanize the given `ms`.
- *
- * @param {Number} m
- * @return {String}
- * @api private
- */
-
-debug.humanize = function(ms) {
-  var sec = 1000
-    , min = 60 * 1000
-    , hour = 60 * min;
-
-  if (ms >= hour) return (ms / hour).toFixed(1) + 'h';
-  if (ms >= min) return (ms / min).toFixed(1) + 'm';
-  if (ms >= sec) return (ms / sec | 0) + 's';
-  return ms + 'ms';
-};
-
-/**
- * Returns true if the given mode name is enabled, false otherwise.
- *
- * @param {String} name
- * @return {Boolean}
- * @api public
- */
-
-debug.enabled = function(name) {
-  for (var i = 0, len = debug.skips.length; i < len; i++) {
-    if (debug.skips[i].test(name)) {
-      return false;
-    }
-  }
-  for (var i = 0, len = debug.names.length; i < len; i++) {
-    if (debug.names[i].test(name)) {
-      return true;
-    }
-  }
-  return false;
-};
-
-/**
- * Coerce `val`.
- */
-
-function coerce(val) {
-  if (val instanceof Error) return val.stack || val.message;
-  return val;
-}
-
-// persist
-
-try {
-  if (window.localStorage) debug.enable(localStorage.debug);
-} catch(e){}
-
-});
-require.register("johntron-asap/asap.js", function(exports, require, module){
-"use strict";
-
-// Use the fastest possible means to execute a task in a future turn
-// of the event loop.
-
-// linked list of tasks (single, with head node)
-var head = {task: void 0, next: null};
-var tail = head;
-var flushing = false;
-var requestFlush = void 0;
-var hasSetImmediate = typeof setImmediate === "function";
-var domain;
-
-if (typeof global != 'undefined') {
-	// Avoid shims from browserify.
-	// The existence of `global` in browsers is guaranteed by browserify.
-	var process = global.process;
-}
-
-// Note that some fake-Node environments,
-// like the Mocha test runner, introduce a `process` global.
-var isNodeJS = !!process && ({}).toString.call(process) === "[object process]";
-
-function flush() {
-    /* jshint loopfunc: true */
-
-    while (head.next) {
-        head = head.next;
-        var task = head.task;
-        head.task = void 0;
-
-        try {
-            task();
-
-        } catch (e) {
-            if (isNodeJS) {
-                // In node, uncaught exceptions are considered fatal errors.
-                // Re-throw them to interrupt flushing!
-
-                // Ensure continuation if an uncaught exception is suppressed
-                // listening process.on("uncaughtException") or domain("error").
-                requestFlush();
-
-                throw e;
-
-            } else {
-                // In browsers, uncaught exceptions are not fatal.
-                // Re-throw them asynchronously to avoid slow-downs.
-                    throw e;
-            }
-        }
-    }
-
-    flushing = false;
-}
-
-if (isNodeJS) {
-    // Node.js
-    requestFlush = function () {
-        // Ensure flushing is not bound to any domain.
-        var currentDomain = process.domain;
-        if (currentDomain) {
-            domain = domain || (1,require)("domain");
-            domain.active = process.domain = null;
-        }
-
-        // Avoid tick recursion - use setImmediate if it exists.
-        if (flushing && hasSetImmediate) {
-            setImmediate(flush);
-        } else {
-            process.nextTick(flush);
-        }
-
-        if (currentDomain) {
-            domain.active = process.domain = currentDomain;
-        }
-    };
-
-} else if (hasSetImmediate) {
-    // In IE10, or https://github.com/NobleJS/setImmediate
-    requestFlush = function () {
-        setImmediate(flush);
-    };
-
-} else if (typeof MessageChannel !== "undefined") {
-    // modern browsers
-    // http://www.nonblocking.io/2011/06/windownexttick.html
-    var channel = new MessageChannel();
-    // At least Safari Version 6.0.5 (8536.30.1) intermittently cannot create
-    // working message ports the first time a page loads.
-    channel.port1.onmessage = function () {
-        requestFlush = requestPortFlush;
-        channel.port1.onmessage = flush;
-        flush();
-    };
-    var requestPortFlush = function () {
-        // Opera requires us to provide a message payload, regardless of
-        // whether we use it.
-        channel.port2.postMessage(0);
-    };
-    requestFlush = function () {
-        setTimeout(flush, 0);
-        requestPortFlush();
-    };
-
-} else {
-    // old browsers
-    requestFlush = function () {
-        setTimeout(flush, 0);
-    };
-}
-
-function asap(task) {
-    if (isNodeJS && process.domain) {
-        task = process.domain.bind(task);
-    }
-
-    tail = tail.next = {task: task, next: null};
-
-    if (!flushing) {
-        requestFlush();
-        flushing = true;
-    }
-};
-
-module.exports = asap;
-
-});
-require.register("chrissrogers-promise/index.js", function(exports, require, module){
-'use strict';
-
-//This file contains then/promise specific extensions to the core promise API
-
-var Promise = require('./core.js')
-var asap = require('asap')
-
-module.exports = Promise
-
-/* Static Functions */
-
-function ValuePromise(value) {
-  this.then = function (onFulfilled) {
-    if (typeof onFulfilled !== 'function') return this
-    return new Promise(function (resolve, reject) {
-      asap(function () {
-        try {
-          resolve(onFulfilled(value))
-        } catch (ex) {
-          reject(ex);
-        }
-      })
-    })
-  }
-}
-ValuePromise.prototype = Promise.prototype
-
-var TRUE = new ValuePromise(true)
-var FALSE = new ValuePromise(false)
-var NULL = new ValuePromise(null)
-var UNDEFINED = new ValuePromise(undefined)
-var ZERO = new ValuePromise(0)
-var EMPTYSTRING = new ValuePromise('')
-
-Promise.resolve = function (value) {
-  if (value instanceof Promise) return value
-
-  if (value === null) return NULL
-  if (value === undefined) return UNDEFINED
-  if (value === true) return TRUE
-  if (value === false) return FALSE
-  if (value === 0) return ZERO
-  if (value === '') return EMPTYSTRING
-
-  if (typeof value === 'object' || typeof value === 'function') {
-    try {
-      var then = value.then
-      if (typeof then === 'function') {
-        return new Promise(then.bind(value))
-      }
-    } catch (ex) {
-      return new Promise(function (resolve, reject) {
-        reject(ex)
-      })
-    }
-  }
-
-  return new ValuePromise(value)
-}
-
-Promise.from = Promise.cast = function (value) {
-  var err = new Error('Promise.from and Promise.cast are deprecated, use Promise.resolve instead')
-  err.name = 'Warning'
-  console.warn(err.stack)
-  return Promise.resolve(value)
-}
-
-Promise.denodeify = function (fn, argumentCount) {
-  argumentCount = argumentCount || Infinity
-  return function () {
-    var self = this
-    var args = Array.prototype.slice.call(arguments)
-    return new Promise(function (resolve, reject) {
-      while (args.length && args.length > argumentCount) {
-        args.pop()
-      }
-      args.push(function (err, res) {
-        if (err) reject(err)
-        else resolve(res)
-      })
-      fn.apply(self, args)
-    })
-  }
-}
-Promise.nodeify = function (fn) {
-  return function () {
-    var args = Array.prototype.slice.call(arguments)
-    var callback = typeof args[args.length - 1] === 'function' ? args.pop() : null
-    try {
-      return fn.apply(this, arguments).nodeify(callback)
-    } catch (ex) {
-      if (callback === null || typeof callback == 'undefined') {
-        return new Promise(function (resolve, reject) { reject(ex) })
-      } else {
-        asap(function () {
-          callback(ex)
-        })
-      }
-    }
-  }
-}
-
-Promise.all = function () {
-  var calledWithArray = arguments.length === 1 && Array.isArray(arguments[0])
-  var args = Array.prototype.slice.call(calledWithArray ? arguments[0] : arguments)
-
-  if (!calledWithArray) {
-    var err = new Error('Promise.all should be called with a single array, calling it with multiple arguments is deprecated')
-    err.name = 'Warning'
-    console.warn(err.stack)
-  }
-
-  return new Promise(function (resolve, reject) {
-    if (args.length === 0) return resolve([])
-    var remaining = args.length
-    function res(i, val) {
-      try {
-        if (val && (typeof val === 'object' || typeof val === 'function')) {
-          var then = val.then
-          if (typeof then === 'function') {
-            then.call(val, function (val) { res(i, val) }, reject)
-            return
-          }
-        }
-        args[i] = val
-        if (--remaining === 0) {
-          resolve(args);
-        }
-      } catch (ex) {
-        reject(ex)
-      }
-    }
-    for (var i = 0; i < args.length; i++) {
-      res(i, args[i])
-    }
-  })
-}
-
-Promise.reject = function (value) {
-  return new Promise(function (resolve, reject) { 
-    reject(value);
-  });
-}
-
-Promise.race = function (values) {
-  return new Promise(function (resolve, reject) { 
-    values.forEach(function(value){
-      Promise.resolve(value).then(resolve, reject);
-    })
-  });
-}
-
-/* Prototype Methods */
-
-Promise.prototype.done = function (onFulfilled, onRejected) {
-  var self = arguments.length ? this.then.apply(this, arguments) : this
-  self.then(null, function (err) {
-    asap(function () {
-      throw err
-    })
-  })
-}
-
-Promise.prototype.nodeify = function (callback) {
-  if (typeof callback != 'function') return this
-
-  this.then(function (value) {
-    asap(function () {
-      callback(null, value)
-    })
-  }, function (err) {
-    asap(function () {
-      callback(err)
-    })
-  })
-}
-
-Promise.prototype['catch'] = function (onRejected) {
-  return this.then(null, onRejected);
-}
-
-});
-require.register("chrissrogers-promise/core.js", function(exports, require, module){
-'use strict';
-
-var asap = require('asap')
-
-module.exports = Promise
-function Promise(fn) {
-  if (typeof this !== 'object') throw new TypeError('Promises must be constructed via new')
-  if (typeof fn !== 'function') throw new TypeError('not a function')
-  var state = null
-  var value = null
-  var deferreds = []
-  var self = this
-
-  this.then = function(onFulfilled, onRejected) {
-    return new self.constructor(function(resolve, reject) {
-      handle(new Handler(onFulfilled, onRejected, resolve, reject))
-    })
-  }
-
-  function handle(deferred) {
-    if (state === null) {
-      deferreds.push(deferred)
-      return
-    }
-    asap(function() {
-      var cb = state ? deferred.onFulfilled : deferred.onRejected
-      if (cb === null) {
-        (state ? deferred.resolve : deferred.reject)(value)
-        return
-      }
-      var ret
-      try {
-        ret = cb(value)
-      }
-      catch (e) {
-        deferred.reject(e)
-        return
-      }
-      deferred.resolve(ret)
-    })
-  }
-
-  function resolve(newValue) {
-    try { //Promise Resolution Procedure: https://github.com/promises-aplus/promises-spec#the-promise-resolution-procedure
-      if (newValue === self) throw new TypeError('A promise cannot be resolved with itself.')
-      if (newValue && (typeof newValue === 'object' || typeof newValue === 'function')) {
-        var then = newValue.then
-        if (typeof then === 'function') {
-          doResolve(then.bind(newValue), resolve, reject)
-          return
-        }
-      }
-      state = true
-      value = newValue
-      finale()
-    } catch (e) { reject(e) }
-  }
-
-  function reject(newValue) {
-    state = false
-    value = newValue
-    finale()
-  }
-
-  function finale() {
-    for (var i = 0, len = deferreds.length; i < len; i++)
-      handle(deferreds[i])
-    deferreds = null
-  }
-
-  doResolve(fn, resolve, reject)
-}
-
-
-function Handler(onFulfilled, onRejected, resolve, reject){
-  this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null
-  this.onRejected = typeof onRejected === 'function' ? onRejected : null
-  this.resolve = resolve
-  this.reject = reject
-}
-
-/**
- * Take a potentially misbehaving resolver function and make sure
- * onFulfilled and onRejected are only called once.
- *
- * Makes no guarantees about asynchrony.
- */
-function doResolve(fn, onFulfilled, onRejected) {
-  var done = false;
-  try {
-    fn(function (value) {
-      if (done) return
-      done = true
-      onFulfilled(value)
-    }, function (reason) {
-      if (done) return
-      done = true
-      onRejected(reason)
-    })
-  } catch (ex) {
-    if (done) return
-    done = true
-    onRejected(ex)
-  }
-}
-
-});
-require.register("kewah-mixin/index.js", function(exports, require, module){
-if (typeof Object.keys === 'function') {
-  module.exports = function(to, from) {
-    Object.keys(from).forEach(function(property) {
-      Object.defineProperty(to, property, Object.getOwnPropertyDescriptor(from, property));
-    });
-  };
-} else {
-  module.exports = function(to, from) {
-    for (var property in from) {
-      if (from.hasOwnProperty(property)) {
-        to[property] = from[property];
-      }
-    }
-  };
-}
-
-});
-require.register("pluma-par/dist/par.js", function(exports, require, module){
-/*! par 0.3.0 Original author Alan Plum <me@pluma.io>. Released into the Public Domain under the UNLICENSE. @preserve */
-var slice = Array.prototype.slice;
-
-function par(fn) {
-    var args0 = slice.call(arguments, 1);
-    return function() {
-        var argsN = slice.call(arguments, 0),
-            args = [];
-        args.push.apply(args, args0);
-        args.push.apply(args, argsN);
-        return fn.apply(this, args);
-    };
-}
-
-function rpartial(fn) {
-    var argsN = slice.call(arguments, 1);
-    return function() {
-        var args = slice.call(arguments, 0);
-        args.push.apply(args, argsN);
-        return fn.apply(this, args);
-    };
-}
-
-par.rpartial = rpartial;
-par.lpartial = par;
-
-module.exports = par;
-
-});
-require.register("ianstormtaylor-to-no-case/index.js", function(exports, require, module){
-
-/**
- * Expose `toNoCase`.
- */
-
-module.exports = toNoCase;
-
-
-/**
- * Test whether a string is camel-case.
- */
-
-var hasSpace = /\s/;
-var hasCamel = /[a-z][A-Z]/;
-var hasSeparator = /[\W_]/;
-
-
-/**
- * Remove any starting case from a `string`, like camel or snake, but keep
- * spaces and punctuation that may be important otherwise.
- *
- * @param {String} string
- * @return {String}
- */
-
-function toNoCase (string) {
-  if (hasSpace.test(string)) return string.toLowerCase();
-
-  if (hasSeparator.test(string)) string = unseparate(string);
-  if (hasCamel.test(string)) string = uncamelize(string);
-  return string.toLowerCase();
-}
-
-
-/**
- * Separator splitter.
- */
-
-var separatorSplitter = /[\W_]+(.|$)/g;
-
-
-/**
- * Un-separate a `string`.
- *
- * @param {String} string
- * @return {String}
- */
-
-function unseparate (string) {
-  return string.replace(separatorSplitter, function (m, next) {
-    return next ? ' ' + next : '';
-  });
-}
-
-
-/**
- * Camelcase splitter.
- */
-
-var camelSplitter = /(.)([A-Z]+)/g;
-
-
-/**
- * Un-camelcase a `string`.
- *
- * @param {String} string
- * @return {String}
- */
-
-function uncamelize (string) {
-  return string.replace(camelSplitter, function (m, previous, uppers) {
-    return previous + ' ' + uppers.toLowerCase().split('').join(' ');
-  });
-}
-});
-require.register("ianstormtaylor-to-space-case/index.js", function(exports, require, module){
-
-var clean = require('to-no-case');
-
-
-/**
- * Expose `toSpaceCase`.
- */
-
-module.exports = toSpaceCase;
-
-
-/**
- * Convert a `string` to space case.
- *
- * @param {String} string
- * @return {String}
- */
-
-
-function toSpaceCase (string) {
-  return clean(string).replace(/[\W_]+(.|$)/g, function (matches, match) {
-    return match ? ' ' + match : '';
-  });
-}
-});
-require.register("ianstormtaylor-to-slug-case/index.js", function(exports, require, module){
-
-var toSpace = require('to-space-case');
-
-
-/**
- * Expose `toSlugCase`.
- */
-
-module.exports = toSlugCase;
-
-
-/**
- * Convert a `string` to slug case.
- *
- * @param {String} string
- * @return {String}
- */
-
-
-function toSlugCase (string) {
-  return toSpace(string).replace(/\s/g, '-');
-}
-});
-require.register("recurly/lib/index.js", function(exports, require, module){
-
-/*!
- * Module dependencies.
- */
-
-var Recurly = require('./recurly');
-
-/**
- * Export a single instance.
- */
-
-module.exports = exports = new Recurly();
-
-/**
- * Hack for testing.
- */
-
-exports.Recurly = Recurly;
-
-});
-require.register("recurly/lib/recurly.js", function(exports, require, module){
-
-/*!
- * Module dependencies.
- */
-
-var bind = require('bind');
-var json = require('json');
-var each = require('each');
-var type = require('type');
-var merge = require('merge');
-var mixin = require('mixin');
-var jsonp = require('jsonp');
-var qs = require('querystring');
-var Emitter = require('emitter');
-var errors = require('./errors');
-var version = require('./version');
-var debug = require('debug')('recurly');
-
-/**
- * Default configuration values.
- *
- * @private
- * @type {Object}
- */
-
-var defaults = {
-    currency: 'USD'
-  , timeout: 60000
-  , publicKey: ''
-  , api: 'https://api.recurly.com/js/v1'
-};
-
-/**
- * API mixins.
- *
- * @type {Array}
- * @private
- */
-
-var mixins = [
-    'open'
-  , 'coupon'
-  , 'paypal'
-  , 'plan'
-  , 'tax'
-  , 'token'
-  , 'pricing'
-  , 'validate'
-];
-
-/**
- * Export `Recurly`.
- */
-
-module.exports = Recurly;
-
-/**
- * Initialize defaults.
- *
- * @param {Object} options
- * @constructor
- * @public
- */
-
-function Recurly (options) {
-  this.id = 0;
-  this.version = version;
-  this.configured = false;
-  this.config = merge({}, defaults);
-  if (options) this.configure(options);
-}
-
-/**
- * Inherits `Emitter`.
- */
-
-Emitter(Recurly.prototype);
-
-/**
- * Configure settings.
- *
- * @param {String|Object} options Either publicKey or object containing
- *                                publicKey and other optional members
- * @param {String} options.publicKey
- * @param {String} [options.currency]
- * @param {String} [options.api]
- * @public
- */
-
-Recurly.prototype.configure = function configure (options) {
-  if (this.configured) throw errors('already-configured');
-
-  debug('configure');
-
-  if (type(options) === 'string') options = { publicKey: options };
-
-  if ('publicKey' in options) {
-    this.config.publicKey = options.publicKey;
-  } else {
-    throw errors('missing-public-key');
-  }
-
-  if ('api' in options) {
-    this.config.api = options.api;
-  }
-
-  if ('currency' in options) {
-    this.config.currency = options.currency;
-  }
-
-  this.configured = true;
-};
-
-/**
- * Assembles the API endpoint.
- *
- * @return {String} route
- * @private
- */
-
-Recurly.prototype.url = function url (route) {
-  return this.config.api + route;
-};
-
-/**
- * Issues an API request.
- *
- * @param {String} route
- * @param {Object} [data]
- * @param {Function} done
- * @throws {Error} If `configure` has not been called.
- * @private
- */
-
-Recurly.prototype.request = function request (route, data, done) {
-  debug('request');
-
-  if (false === this.configured) {
-    throw errors('not-configured');
-  }
-
-  if ('function' == type(data)) {
-    done = data;
-    data = {};
-  }
-
-  var url = this.url(route);
-  var timeout = this.config.timeout;
-
-  data.version = this.version;
-  data.key = this.config.publicKey;
-
-  url += '?' + qs.stringify(data);
-
-  this.cache(url, function (res, set) {
-    if (res) return done(null, res);
-    jsonp(url, { timeout: timeout }, function (err, res) {
-      if (err) return done(err);
-      if (res.error) {
-        done(errors('api-error', res.error));
-      } else {
-        done(null, set(res));
-      }
-    });
-  });
-};
-
-/**
- * Caches an object
- *
- * TODO: figure out invalidation & expiry
- *
- * @param {String} url
- * @param {Function} done
- * @private
- */
- 
-Recurly.prototype.cache = function cache (url, done) {
-  debug('cache');
-  var stored = localStorage.getItem(url);
-  if (stored) {
-    debug('cache found ' + url);
-    return done(json.parse(stored));
-  } else {
-    debug('cache set ' + url);
-    return done(null, set);
-  }
-  function set (obj) {
-    // disabled for now
-    // localStorage.setItem(url, json.stringify(obj));
-    return obj;
-  }
-};
-
-/**
- * Load the `mixins` onto Recurly.prototype.
- */
-
-each(mixins, function (name) {
-  mixin(Recurly.prototype, require('./recurly/' + name));
-});
-
-});
-require.register("recurly/lib/version.js", function(exports, require, module){
-
-/**
- * Current package/component version.
- */
-
-module.exports = '3.0.5';
-
-});
-require.register("recurly/lib/errors.js", function(exports, require, module){
-/**
- * dependencies
- */
-
-var mixin = require('mixin');
-
-/**
- * Export `errors`.
- */
-
-module.exports = exports = errors;
-
-/**
- * Error accessor.
- *
- * @param {String} name
- * @param {Object} options
- * @return {Error}
- */
-
-function errors (name, options) {
-  return errors.get(name, options);
-}
-
-/**
- * Defined errors.
- *
- * @type {Object}
- * @private
- */
-
-errors.map = {};
-
-/**
- * Base url for documention.
- *
- * @type {String}
- * @private
- */
-
-errors.baseURL = '';
-
-/**
- * Sets the `baseURL` for docs.
- *
- * @param {String} url
- * @public
- */
-
-errors.doc = function (baseURL) {
-  errors.baseURL = baseURL;
-};
-
-/**
- * Gets errors defined by `name`.
- *
- * @param {String} name
- * @param {Object} context
- * @return {Error}
- * @public
- */
-
-errors.get = function (name, context) {
-  if (!(name in errors.map)) {
-    throw new Error('invalid error');
-  } else {
-    return new errors.map[name](context);
-  }
-};
-
-/**
- * Registers an error defined by `name` with `config`.
- *
- * @param {String} name
- * @param {Object} config
- * @return {Error}
- * @public
- */
-
-errors.add = function (name, config) {
-  config = config || {};
-
-  function RecurlyError (context) {
-    Error.call(this);
-
-    this.name = this.code = name;
-    this.message = config.message;
-    mixin(this, context || {});
-
-    if (config.help) {
-      this.help = errors.baseURL + config.help;
-      this.message += ' (need help? ' + this.help + ')';
-    }
-  };
-
-  RecurlyError.prototype = new Error();
-  return errors.map[name] = RecurlyError;
-};
-
-/**
- * Internal definations.
- *
- * TODO(gjohnson): open source this as a component
- * and move these out.
- */
-
-errors.doc('https://docs.recurly.com/js');
-
-errors.add('already-configured', {
-  message: 'Configuration may only be set once.',
-  help: '#identify-your-site'
-});
-
-errors.add('not-configured', {
-  message: 'Not configured. You must first call recurly.configure().',
-  help: '#identify-your-site'
-});
-
-errors.add('missing-public-key', {
-  message: 'The publicKey setting is required.',
-  help: '#identify-your-site'
-});
-
-errors.add('api-error', {
-  message: 'There was an error with your request.'
-});
-
-errors.add('validation', {
-  message: 'There was an error validating your request.'
-});
-
-errors.add('missing-callback', {
-  message: 'Missing callback'
-});
-
-errors.add('invalid-options', {
-  message: 'Options must be an object'
-});
-
-errors.add('missing-plan', {
-  message: 'A plan must be specified.'
-});
-
-errors.add('missing-coupon', {
-  message: 'A coupon must be specified.'
-});
-
-errors.add('invalid-item', {
-  message: 'The given item does not appear to be a valid recurly plan, coupon, addon, or taxable address.'
-});
-
-errors.add('invalid-addon', {
-  message: 'The given addon_code is not among the valid addons for the specified plan.'
-});
-
-errors.add('invalid-currency', {
-  message: 'The given currency is not among the valid codes for the specified plan.'
-});
-
-errors.add('unremovable-item', {
-  message: 'The given item cannot be removed.'
-});
-
-});
-require.register("recurly/lib/util/dom.js", function(exports, require, module){
-/**
- * dependencies
- */
-
-var slug = require('to-slug-case');
-var type = require('type');
-var each = require('each');
-var map = require('map');
-
-/**
- * expose
- */
-
-module.exports = {
-  element: element,
-  value: value,
-  data: data
-};
-
-/**
- * Detects whether an object is an html element.
- *
- * @param {Mixed} node
- * @return {HTMLElement|Boolean} node
- */
-
-function element (node) {
-  var isJQuery = window.jQuery && node instanceof jQuery;
-  var isArray = type(node) === 'array';
-  if (isJQuery || isArray) node = node[0];
-
-  var isElem = typeof HTMLElement !== 'undefined'
-    ? node instanceof HTMLElement
-    : node && node.nodeType === 1;
-
-  return isElem && node;
-};
-
-/**
- * Gets or sets the value of a given HTML form element
- *
- * supports text inputs, radio inputs, and selects
- *
- * @param {HTMLElement} node
- * @return {String} value of the element
- */
-
-function value (node, value) {
-  if (!element(node)) return null;
-  return typeof value !== 'undefined'
-    ? valueSet(node, value)
-    : valueGet(node);
-}
-
-/**
- * Gets an HTMLElement's value property in the context of a form
- *
- * @param {HTMLElement} node
- * @return {String} node's value
- */
-
-function valueGet (node) {
-  node = element(node);
-
-  var nodeType = node && node.type && node.type.toLowerCase();
-  var value;
-
-  if (!nodeType) {
-    value = '';
-  } else if ('options' in node) {
-    value = node.options[node.selectedIndex].value;
-  } else if (nodeType === 'checkbox') {
-    if (node.checked) value = node.value;
-  } else if (nodeType === 'radio') {
-    var radios = document.querySelectorAll('input[data-recurly="' + data(node, 'recurly') + '"]');
-    each(radios, function (radio) {
-      if (radio.checked) value = radio.value;
-    });
-  } else if ('value' in node) {
-    value = node.value;
-  }
-
-  return value;
-}
-
-/**
- * Updates an element's value property if
- * one exists; else innerText if it exists
- *
- * @param {Array[HTMLElement]} nodes
- * @param {Mixed} value
- */
-
-function valueSet (nodes, value) {
-  if (type(nodes) !== 'array') nodes = [nodes];
-  each(nodes, function (node) {
-    if (!node) return;
-    else if ('value' in node)
-      node.value = value;
-    else if ('textContent' in node)
-      node.textContent = value;
-    else if ('innerText' in node)
-      node.innerText = value;
-  });
-}
-
-/**
- * Gets or sets a node's data attribute
- *
- * @param {HTMLElement} node
- * @param {String} key
- * @param {Mixed} [value]
- */
-
-function data (node, key, value) {
-  node = element(node);
-  if (!node) return;
-  return typeof value !== 'undefined'
-    ? dataSet(node, key, value)
-    : dataGet(node, key);
-}
-
-/**
- * Gets a node's data attribute
- *
- * @param {HTMLElement} node
- * @param {String} key
- */
-
-function dataGet (node, key) {
-  return node.dataset
-    ? node.dataset[key]
-    : node.getAttribute('data-' + slug(key));
-}
-
-/**
- * sets a node's data attribute
- *
- * @param {HTMLElement} node
- * @param {String} key
- * @param {Mixed} value
- */
-
-function dataSet (node, key, value) {
-  if (node.dataset) node.dataset[key] = value;
-  else node.setAttribute('data-' + slug(key), value);
-}
-
-});
-require.register("recurly/lib/util/parse-card.js", function(exports, require, module){
-
-/**
- * Removes dashes and spaces from a card number.
- *
- * @param {Number|String} number
- * @return {String} parsed card number
- */
-
-module.exports = function parseCard (number) {
-  return number && number.toString().replace(/[-\s]/g, '');
-};
-
-});
-require.register("recurly/lib/recurly/open.js", function(exports, require, module){
-
-/*!
- * Module dependencies.
- */
-
-var bind = require('bind');
-var type = require('type');
-var json = require('json');
-var events = require('event');
-var qs = require('querystring');
-var errors = require('../errors');
-var debug = require('debug')('recurly:open');
-
-/**
- * Issues an API request to a popup window.
- *
- * TODO(*): configurable window name?
- * TODO(*): configurable window properties?
- *
- * @param {String} url
- * @param {Object} [data]
- * @param {Function} [done]
- * @throws {Error} If `configure` has not been called.
- * @return {Window}
- * @private
- */
-
-exports.open = function (url, data, done) {
-  debug('open');
-  
-  if (false === this.configured) {
-    throw errors('not-configured');
-  }
-
-  if ('function' == type(data)) {
-    done = data;
-    data = {};
-  }
-
-  data = data || {};
-  data.version = this.version;
-  data.event = 'recurly-open-' + this.id++;
-  data.key = this.config.publicKey;
-  this.once(data.event, done);
-
-  if (!/^https?:\/\//.test(url)) url = this.url(url);
-  url += (~url.indexOf('?') ? '&' : '?') + qs.stringify(data);
-
-  this.relay(function () {
-    window.open(url);
-  });
-};
-
-/**
- * Relay mixin.
- *
- * Inspects the window for intent to relay a message,
- * then attempts to send it off. closes the window once
- * dispatched.
- *
- * @param {Function} done
- * @private
- */
-
-exports.relay = function (done) {
-  var self = this;
-
-  if (false === this.configured) {
-    throw errors('not-configured');
-  }
-
-  events.bind(window, 'message', function listener (event) {
-    var data = json.parse(event.data);
-    var name = data.recurly_event;
-    var body = data.recurly_message;
-    var err = body.error ? errors('api-error', body.error) : null;
-    events.unbind(window, 'message', listener);
-    if (name) self.emit(name, err, body);
-    if (frame) document.body.removeChild(frame);
-  });
-
-  if ('documentMode' in document) {
-    var frame = document.createElement('iframe');
-    frame.width = frame.height = 0;
-    frame.src = this.url('/relay');
-    frame.name = 'recurly-relay';
-    frame.style.display = 'none';
-    frame.onload = bind(this, done);
-    document.body.appendChild(frame);
-  } else {
-    done();
-  }
-};
-
-});
-require.register("recurly/lib/recurly/coupon.js", function(exports, require, module){
-
-/*!
- * Module dependencies.
- */
-
-var type = require('type');
-var debug = require('debug')('recurly:coupon');
-var errors = require('../errors');
-
-/**
- * Coupon mixin.
- *
- * Retrieves coupon information for the `plan`. The `callback` signature
- * is `err, plan` where `err` may be a request or server error, and `plan`
- * is a representation of the requested plan.
- *
- * @param {Object} options
- * @param {Function} callback
- */
-
-exports.coupon = function (options, callback) {
-  debug('%j', options);
-
-  if ('function' !== type(callback)) {
-    throw errors('missing-callback');
-  }
-
-  if ('object' !== type(options)) {
-    throw errors('invalid-options');
-  }
-
-  if (!('plan' in options)) {
-    throw errors('missing-plan');
-  }
-
-  if (!('coupon' in options)) {
-    throw errors('missing-coupon');
-  }
-
-  this.request('/plans/' + options.plan + '/coupons/' + options.coupon, options, callback);
-};
-
-});
-require.register("recurly/lib/recurly/paypal.js", function(exports, require, module){
-
-/*!
- * Module dependencies.
- */
-
-var debug = require('debug')('recurly:paypal');
-
-/**
- * Paypal mixin.
- *
- * @param {Object} data
- * @param {Function} done callback
- */
-
-exports.paypal = function (data, done) {
-  debug('start');
-  this.open('/paypal/start', data, done);
-};
-
-});
-require.register("recurly/lib/recurly/plan.js", function(exports, require, module){
-
-/*!
- * Module dependencies.
- */
-
-var type = require('type');
-var debug = require('debug')('recurly:plan');
-
-/**
- * Plan mixin.
- *
- * Retrieves information for the `plan`. The `callback` signature
- * is `err, plan` where `err` may be a request or server error, and `plan`
- * is a representation of the requested plan.
- *
- * @param {String} code
- * @param {Function} callback
- */
-
-exports.plan = function (code, callback) {
-  debug('%s', code);
-
-  if ('function' != type(callback)) {
-    throw new Error('Missing callback');
-  }
-
-  if ('undefined' == type(code)) {
-    return callback(new Error('Missing plan code'));
-  }
-
-  this.request('/plans/' + code, callback);
-};
-
-});
-require.register("recurly/lib/recurly/tax.js", function(exports, require, module){
-
-/*!
- * Module dependencies.
- */
-
-var type = require('type');
-var clone = require('clone');
-var debug = require('debug')('recurly:tax');
-
-/**
- * Tax mixin.
- *
- * Provides a tax estiamte for the given address.
- *
- * @param {Object} options
- * @param {Object} options.postal_code
- * @param {Object} options.country
- * @param {Object} [options.vat_number] Used for VAT exemptions
- * @param {Function} callback
- */
-
-exports.tax = function (options, callback) {
-  var request = clone(options);
-
-  if ('function' != type(callback)) {
-    throw new Error('Missing callback');
-  }
-
-  if (!('currency' in request)) {
-    request.currency = this.config.currency;
-  }
-
-  this.request('/tax', request, callback);
-};
-
-});
-require.register("recurly/lib/recurly/token.js", function(exports, require, module){
-
-/*!
- * Module dependencies.
- */
-
-var bind = require('bind');
-var each = require('each');
-var type = require('type');
-var index = require('indexof');
-var debug = require('debug')('recurly:token');
-var dom = require('../util/dom');
-var parseCard = require('../util/parse-card');
-var errors = require('../errors');
-
-/**
- * Fields that are sent to API.
- *
- * @type {Array}
- * @private
- */
-
-var fields = [
-    'first_name'
-  , 'last_name'
-  , 'number'
-  , 'month'
-  , 'year'
-  , 'cvv'
-  , 'address1'
-  , 'address2'
-  , 'country'
-  , 'city'
-  , 'state'
-  , 'postal_code'
-  , 'phone'
-  , 'vat_number'
-  , 'token'
-];
-
-/**
- * Generates a token from customer data.
- *
- * The callback signature: `err, response` where `err` is a
- * connection, request, or server error, and `response` is the
- * recurly service response. The generated token is accessed
- * at `response.token`.
- *
- * @param {Object|HTMLFormElement} options Billing properties or an HTMLFormElement
- * with children corresponding to billing properties via 'data-reurly' attributes.
- * @param {String} options.first_name customer first name
- * @param {String} options.last_name customer last name
- * @param {String|Number} options.number card number
- * @param {String|Number} options.month card expiration month
- * @param {String|Number} options.year card expiration year
- * @param {String|Number} options.cvv card verification value
- * @param {String} [options.address1]
- * @param {String} [options.address2]
- * @param {String} [options.country]
- * @param {String} [options.city]
- * @param {String} [options.state]
- * @param {String|Number} [options.postal_code]
- * @param {Function} done callback
- */
-
-exports.token = function (options, done) {
-  var open = bind(this, this.open);
-  var data = normalize(options);
-  var input = data.values;
-  var userErrors = validate.call(this, input);
-
-  if ('function' !== type(done)) {
-    throw errors('missing-callback');
-  }
-
-  if (userErrors.length) {
-    return done(errors('validation', { fields: userErrors }));
-  }
-
-  this.request('/token', input, function (err, res) {
-    if (err) return done(err);
-    if (data.fields.token && res.id) {
-      data.fields.token.value = res.id;
-    }
-    done(null, res);
-  });
-};
-
-/**
- * Parses options out of a form element and normalizes according to rules.
- *
- * @param {Object|HTMLFormElement} options
- * @return {Object}
- */
-
-function normalize (options) {
-  var el = dom.element(options);
-  var data = { fields: {}, values: {} };
-
-  if (el && 'form' === el.nodeName.toLowerCase()) {
-    each(el.querySelectorAll('[data-recurly]'), function (field) {
-      var name = dom.data(field, 'recurly');
-      if (~index(fields, name)) {
-        data.fields[name] = field;
-        data.values[name] = dom.value(field);
-      }
-    });
-  } else {
-    data.values = options;
-  }
-
-  data.values.number = parseCard(data.values.number);
-
-  return data;
-}
-
-/**
- * Checks user input on a token call
- *
- * @param {Object} input
- * @return {Array} indicates which fields are not valid
- */
-
-function validate (input) {
-  var errors = [];
-
-  if (!this.validate.cardNumber(input.number)) {
-    errors.push('number');
-  }
-
-  if (!this.validate.expiry(input.month, input.year)) {
-    errors.push('month', 'year');
-  }
-
-  if (!input.first_name) {
-    errors.push('first_name');
-  }
-
-  if (!input.last_name) {
-    errors.push('last_name');
-  }
-
-  return errors;
-}
-
-});
-require.register("recurly/lib/recurly/validate.js", function(exports, require, module){
-
-/*!
- * Module dependencies.
- */
-
-var find = require('find');
-var trim = require('trim');
-var index = require('indexof');
-var parseCard = require('../util/parse-card');
-
-/**
- * Card patterns.
- *
- * @private
- */
-
-var types = [
-  {
-    type: 'discover',
-    pattern: /^(6011|622|64[4-9]|65)/,
-    lengths: [16]
-  }
-  , {
-    type: 'master',
-    pattern: /^5[0-5]/,
-    lengths: [16]
-  }
-  , {
-    type: 'american_express',
-    pattern: /^3[47]/,
-    lengths: [15]
-  }
-  , {
-    type: 'visa',
-    pattern: /^4/,
-    lengths: [13, 16]
-  }
-  , {
-    type: 'jcb',
-    pattern: /^35[2-8]\d/,
-    lengths: [16]
-  }
-  , {
-    type: 'diners_club',
-    pattern: /^(30[0-5]|309|36|3[89]|54|55|2014|2149)/,
-    lengths: [14]
-  }
-];
-
-/**
- * Validate mixin.
- *
- * @public
- */
-
-exports.validate = {
-
-  /**
-   * Validates a credit card number via luhn algorithm.
-   *
-   * @param {Number|String} number The card number.
-   * @return {Boolean}
-   * @see https://sites.google.com/site/abapexamples/javascript/luhn-validation
-   */
-
-  cardNumber: function (number) {
-    var str = parseCard(number);
-    var ca, sum = 0, mul = 1;
-    var i = str.length;
-
-    while (i--) {
-      ca = parseInt(str.charAt(i), 10) * mul;
-      sum += ca - (ca > 9) * 9;
-      mul ^= 3;
-    }
-
-    return sum % 10 === 0 && sum > 0;
-  },
-
-  /**
-   * Returns the type of the card number as a string.
-   *
-   * TODO(chrissrogers): Maybe undefined instread of "unknown"?
-   *
-   * @param {Number|String} number The card number
-   * @return {String} card type
-   */
-
-  cardType: function (number) {
-    var str = parseCard(number);
-    var card = find(types, function (card) {
-      return card.pattern.test(str) && ~index(card.lengths, str.length);
-    });
-    return card && card.type || 'unknown';
-  },
-
-  /**
-   * Validates whether an expiry month is present or future.
-   *
-   * @param {Numer|String} month The 2 digit month
-   * @param {Numer|String} year The 2 or 4 digit year
-   * @return {Boolean}
-   */
-
-  expiry: function (month, year) {
-    month = parseInt(month, 10) - 1;
-    if (month < 0 || month > 11) return false;
-    year = parseInt(year, 10);
-    year += year < 100 ? 2000 : 0;
-
-    var expiry = new Date;
-    expiry.setYear(year);
-    expiry.setDate(1);
-    expiry.setHours(0);
-    expiry.setMinutes(0);
-    expiry.setSeconds(0);
-    expiry.setMonth(month + 1);
-    return new Date < expiry;
-  },
-
-  /**
-   * Validates whether a number looks like a cvv.
-   *
-   * e.g.: '123', '0321'
-   *
-   * @param {Number|String} number The card verification value
-   * @return {Boolean}
-   */
-
-  cvv: function (number) {
-    number = trim(number + '');
-    return /^\d+$/.test(number) && (number.length === 3 || number.length === 4);
-  }
-
-};
-
-});
-require.register("recurly/lib/recurly/pricing/index.js", function(exports, require, module){
-/**
- * dependencies
- */
-
-var Emitter = require('emitter');
-var index = require('indexof');
-var each = require('each');
-var type = require('type');
-var bind = require('bind');
-var find = require('find');
-var mixin = require('mixin');
-var keys = require('object').keys;
-var json = require('json');
-var debug = require('debug')('recurly:pricing');
-var PricingPromise = require('./promise');
-var Calculations = require('./calculations');
-var errors = require('../../errors');
-
-/**
- * expose
- */
-
-exports.Pricing = Pricing;
-
-/**
- * Pricing
- *
- * @constructor
- * @param {Recurly} recurly
- * @public
- */
-
-function Pricing (recurly) {
-  if (this instanceof require('../../recurly')) return new Pricing(this);
-  this.recurly = recurly;
-  this.reset();
-}
-
-Emitter(Pricing.prototype);
-
-/**
- * Subscription properties
- */
-
-Pricing.properties = [
-    'plan'
-  , 'addon'
-  , 'coupon'
-  , 'address'
-  , 'currency'
-];
-
-/**
- * Resets the pricing calculator
- *
- * @public
- */
-
-Pricing.prototype.reset = function () {
-  this.items = {};
-  this.items.addons = [];
-  this.currency(this.recurly.config.currency);
-};
-
-/**
- * Removes an object from the pricing model
- *
- * example
- *
- *   .remove({ plan: 'plan_code' });
- *   .remove({ addon: 'addon_code' });
- *   .remove({ coupon: 'coupon_code' });
- *   .remove({ address: true }); // to remove without specifying a code
- *
- * @param {Object} opts
- * @param {Function} [done] callback
- * @public
- */
-
-Pricing.prototype.remove = function (opts, done) {
-  var self = this;
-  var item;
-  debug('remove');
-
-  return new PricingPromise(function (resolve, reject) {
-    var prop = keys(opts)[0];
-    var id = opts[prop];
-    if (!~index(Pricing.properties, prop)) return reject(errors('invalid-item'));
-    if (prop === 'addon') {
-      var pos = index(self.items.addons, findAddon(self.items.addons, { code: id }));
-      if (~pos) {
-        item = self.items.addons.splice(pos);
-      }
-    } else if (self.items[prop] && (id === self.items[prop].code || id === true)) {
-      item = self.items[prop]
-      delete self.items[prop];
-    } else {
-      return reject(errors('unremovable-item', {
-          type: prop
-        , id: id
-        , reason: 'does not exist on this pricing instance.'
-      }));
-    }
-  }, this).nodeify(done);
-};
-
-/**
- * Provides a subscription price estimate using current state
- *
- * @param {Function} [done] callback
- * @public
- */
-
-Pricing.prototype.reprice = function (done) {
-  var self = this;
-  debug('reprice');
-
-  return new PricingPromise(function (resolve, reject) {
-    if (!self.items.plan) return reject(errors('missing-plan'));
-
-    Calculations(self, function (price) {
-      if (json.stringify(price) === json.stringify(self.price)) return resolve(price);
-      self.price = price;
-      self.emit('change', price);
-      resolve(price);
-    });
-  }, this).nodeify(done);
-};
-
-/**
- * Updates plan
- *
- * @param {String} planCode
- * @param {Object} [meta]
- * @param {Number} [meta.quantity]
- * @param {Function} [done] callback
- * @public
- */
-
-Pricing.prototype.plan = function (planCode, meta, done) {
-  var self = this;
-  var plan = this.items.plan;
-  var quantity;
-
-  if (type(meta) === 'function') {
-    done = meta;
-    meta = undefined;
-  }
-
-  meta = meta || {};
-
-  // meta.quantity, plan.quantity, 1
-  if (plan && plan.quantity) quantity = plan.quantity;
-  if (meta.quantity) quantity = parseInt(meta.quantity, 10);
-  if (!quantity || quantity < 1) quantity = 1;
-
-  return new PricingPromise(function (resolve, reject) {
-    if (plan && plan.code === planCode) {
-      plan.quantity = quantity;
-      return resolve(plan);
-    }
-
-    self.recurly.plan(planCode, function (err, plan) {
-      if (err) return reject(err);
-
-      plan.quantity = quantity;
-      self.items.plan = plan;
-
-      if (!(self.items.currency in plan.price)) {
-        self.currency(keys(plan.price)[0]);
-      }
-
-      debug('set.plan');
-      self.emit('set.plan', plan);
-      resolve(plan);
-    });
-  }, this).nodeify(done);
-};
-
-/**
- * Updates addon
- *
- * @param {String} addonCode
- * @param {Object} [meta]
- * @param {Number} [meta.quantity]
- * @param {Function} [done] callback
- * @public
- */
-
-Pricing.prototype.addon = function (addonCode, meta, done) {
-  var self = this;
-
-  if (type(meta) === 'function') {
-    done = meta;
-    meta = undefined;
-  }
-
-  meta = meta || {};
-
-  return new PricingPromise(function (resolve, reject) {
-    if (!self.items.plan) return reject(errors('missing-plan'));
-
-    var planAddon = findAddon(self.items.plan.addons, addonCode);
-    if (!planAddon) {
-      return reject(errors('invalid-addon', {
-          planCode: self.items.plan.code
-        , addonCode: addonCode
-      }));
-    }
-
-    var quantity = addonQuantity(meta, planAddon);
-    var addon = findAddon(self.items.addons, addonCode);
-
-    if (quantity === 0) {
-      self.remove({ addon: addonCode });
-    }
-
-    if (addon) {
-      addon.quantity = quantity;
-    } else {
-      addon = json.parse(json.stringify(planAddon));
-      addon.quantity = quantity;
-      self.items.addons.push(addon);
-    }
-
-    debug('set.addon');
-    self.emit('set.addon', addon);
-    resolve(addon);
-  }, this).nodeify(done);
-};
-
-/**
- * Updates coupon
- *
- * @param {String} couponCode
- * @param {Function} [done] callback
- * @public
- */
-
-Pricing.prototype.coupon = function (couponCode, done) {
-  var self = this;
-  var coupon = this.items.coupon;
-
-  return new PricingPromise(function (resolve, reject) {
-    if (!self.items.plan) return reject(errors('missing-plan'));
-    if (coupon) {
-      if (coupon.code === couponCode) return resolve(coupon);
-      else self.remove({ coupon: coupon.code });
-    }
-    if (!couponCode) return resolve();
-
-    self.recurly.coupon({ plan: self.items.plan.code, coupon: couponCode }, function (err, coupon) {
-      if (err && err.code !== 'not_found') return reject(err);
-
-      self.items.coupon = coupon;
-
-      debug('set.coupon');
-      self.emit('set.coupon', coupon);
-      resolve(coupon);
-    });
-  }, this).nodeify(done);
-};
-
-/**
- * Updates address
- *
- * @param {Object} address
- * @param {String} address.country
- * @param {String|Number} address.postal_code
- * @param {String} address.vat_number
- * @param {Function} [done] callback
- * @public
- */
-
-Pricing.prototype.address = function (address, done) {
-  var self = this;
-
-  return new PricingPromise(function (resolve, reject) {
-    if (json.stringify(address) === json.stringify(self.items.address)) {
-      return resolve(self.items.address);
-    }
-
-    self.items.address = address;
-
-    debug('set.address');
-    self.emit('set.address', address);
-    resolve(address);
-  }, this).nodeify(done);
-};
-
-/**
- * Updates or retrieves currency code
- *
- * @param {String} code
- * @param {Function} [done] callback
- * @public
- */
-
-Pricing.prototype.currency = function (code, done) {
-  var self = this;
-  var plan = this.items.plan
-  var currency = this.items.currency;
-
-  return new PricingPromise(function (resolve, reject) {
-    if (currency === code) return resolve(currency);
-    if (plan && !(code in plan.price)) {
-      return reject(errors('invalid-currency', {
-          currencyCode: code
-        , planCurrencies: keys(plan.price)
-      }));
-    }
-
-    self.items.currency = code;
-
-    debug('set.currency');
-    self.emit('set.currency', code);
-    resolve(code);
-  }, this).nodeify(done);
-};
-
-/**
- * DOM attachment mixin
- */
-
-mixin(Pricing.prototype, require('./attach'));
-
-/**
- * Utility functions
- */
-
-function addonQuantity (meta, planAddon) {
-  var qty = 1;
-  if ('quantity' in planAddon) qty = planAddon.quantity;
-  if ('quantity' in meta) qty = meta.quantity;
-  return parseInt(qty, 10) || 0;
-}
-
-function findAddon (addons, code) {
-  return addons && find(addons, { code: code });
-}
-
-});
-require.register("recurly/lib/recurly/pricing/promise.js", function(exports, require, module){
-/**
- * Dependencies
- */
-
-var Promise = require('promise');
-var mixin = require('mixin');
-var bind = require('bind');
-var each = require('each');
-var type = require('type');
-var par = require('par');
-var debug = require('debug')('recurly:pricing:promise');
-
-/**
- * Expose
- */
-
-module.exports = PricingPromise;
-
-/**
- * PricingPromise
- *
- * issues repricing when .done
- *
- * contains .then wrappers for Pricing property methods
- *
- * Usage
- *
- *   var pricing = recurly.Pricing();
- *   
- *   pricing
- *     .plan('basic')
- *     .addon('addon1')
- *     .then(process)
- *     .catch(errors)
- *     .done();
- *
- * @param {Function} resolver
- * @param {Pricing} pricing bound instance
- * @constructor
- * @public
- */
-
-function PricingPromise (resolver, pricing) {
-  if (!(this instanceof PricingPromise)) return new PricingPromise(resolver, pricing);
-
-  var self = this;
-  this.pricing = pricing;
-  this.constructor = par.rpartial(this.constructor, pricing);
-
-  Promise.call(this, resolver);
-
-  // for each pricing method, create a promise wrapper method
-  each(require('./').Pricing.prototype, function (method) {
-    self[method] = function () {
-      var args = arguments;
-      return self.then(function () {
-        return self.pricing[method].apply(self.pricing, args);
-      });
-    };
-  });
-}
-
-mixin(PricingPromise.prototype, Promise.prototype);
-PricingPromise.prototype.constructor = PricingPromise;
-
-/**
- * Adds a reprice and completes the control flow
- *
- * @param {Function} onFulfilled
- * @param {Function} onRejected
- * @return {Pricing} bound pricing instance
- * @public
- */
-
-PricingPromise.prototype.done = function () {
-  Promise.prototype.done.apply(this.then(this.reprice), arguments);
-  return this.pricing;
-};
-
-/**
- * Adds a reprice if a callback is passed
- *
- * @param {Function} [done] callback
- * @public
- */
-
-PricingPromise.prototype.nodeify = function (done) {
-  if (type(done) === 'function') this.reprice();
-  return Promise.prototype.nodeify.apply(this, arguments);
-};
-
-});
-require.register("recurly/lib/recurly/pricing/calculations.js", function(exports, require, module){
-/**
- * dependencies
- */
-
-var each = require('each');
-var bind = require('bind');
-var find = require('find');
-
-/**
- * expose
- */
-
-module.exports = Calculations;
-
-/**
- * Subscription calculation calculation
- *
- * @param {Pricing} pricing
- * @constructor
- * @public
- */
-
-function Calculations (pricing, done) {
-  if (!(this instanceof Calculations)) {
-    return new Calculations(pricing, done);
-  }
-
-  this.pricing = pricing;
-  this.items = pricing.items;
-
-  this.price = {
-    now: {},
-    next: {},
-    addons: {},
-    currency: {
-      code: this.items.currency,
-      symbol: this.planPrice().symbol
-    }
-  };
-
-  this.subtotal();
-
-  this.tax(function () {
-    this.total();
-    each(this.price.now, decimal, this.price.now);
-    each(this.price.next, decimal, this.price.next);
-    each(this.price.addons, decimal, this.price.addons);
-    done(this.price);
-  });
-}
-
-/**
- * Calculates subtotal
- *
- * @private
- */
-
-Calculations.prototype.subtotal = function () {
-  var subtotal = this.planPrice().amount;
-
-  this.price.now.subtotal = subtotal;
-  this.price.next.subtotal = subtotal;
-
-  if (this.items.plan.trial) this.price.now.subtotal = 0;
-
-  this.addons();
-  this.price.now.subtotal += this.price.now.addons;
-  this.price.next.subtotal += this.price.next.addons;
-
-  this.discount();
-  this.price.now.subtotal -= this.price.now.discount;
-  this.price.next.subtotal -= this.price.next.discount;
-
-  this.setupFee();
-  this.price.now.subtotal += this.price.now.setup_fee;
-};
-
-/**
- * Calculates tax
- * 
- * @param {Function} done
- * @private
- */
-
-Calculations.prototype.tax = function (done) {
-  this.price.now.tax = 0;
-  this.price.next.tax = 0;
-
-  if (this.items.address) {
-    var self = this;
-    this.pricing.recurly.tax(this.items.address, function applyTax (err, taxes) {
-      if (err) {
-        self.pricing.emit('error', err);
-      } else {
-        each(taxes, function (tax) {
-          if (tax.type === 'usst' && self.items.plan.tax_exempt) return;
-          self.price.now.tax += self.price.now.subtotal * tax.rate;
-          self.price.next.tax += self.price.next.subtotal * tax.rate;
-        });
-
-        // tax estimation prefers partial cents to always round up
-        self.price.now.tax = Math.ceil(self.price.now.tax * 100) / 100;
-        self.price.next.tax = Math.ceil(self.price.next.tax * 100) / 100;
-      }
-      done.call(self);
-    });
-  } else done.call(this);
-};
-
-/**
- * Calculates total
- *
- * @private
- */
-
-Calculations.prototype.total = function () {
-  this.price.now.total = this.price.now.subtotal + this.price.now.tax;
-  this.price.next.total = this.price.next.subtotal + this.price.next.tax;
-};
-
-/**
- * Computes addon prices and applies addons to the subtotal
- *
- * @private
- */
-
-Calculations.prototype.addons = function () {
-  this.price.now.addons = 0;
-  this.price.next.addons = 0;
-
-  each(this.items.plan.addons, function (addon) {
-    var price = addon.price[this.items.currency].unit_amount;
-
-    this.price.addons[addon.code] = price;
-
-    var selected = find(this.items.addons, { code: addon.code });
-    if (selected) {
-      price = price * selected.quantity;
-      if (!this.items.plan.trial) this.price.now.addons += price;
-      this.price.next.addons += price;
-    }
-  }, this);
-};
-
-/**
- * Applies coupon discount to the subtotal
- *
- * @private
- */
-
-Calculations.prototype.discount = function () {
-  var coupon = this.items.coupon;
-
-  this.price.now.discount = 0;
-  this.price.next.discount = 0;
-
-  if (coupon) {
-    if (coupon.discount.rate) {
-      this.price.now.discount = Math.round(this.price.now.subtotal * coupon.discount.rate * 100) / 100;
-      this.price.next.discount = Math.round(this.price.next.subtotal * coupon.discount.rate * 100) / 100;
-    } else {
-      this.price.now.discount = coupon.discount.amount[this.items.currency];
-      this.price.next.discount = coupon.discount.amount[this.items.currency];
-    }
-  }
-};
-
-/**
- * Applies plan setup fee to the subtotal
- *
- * @private
- */
-
-Calculations.prototype.setupFee = function () {
-  this.price.now.setup_fee = this.planPrice().setup_fee;
-  this.price.next.setup_fee = 0;
-};
-
-/**
- * Get the price structure of a plan based on currency
- *
- * @return {Object}
- * @private
- */
-
-Calculations.prototype.planPrice = function () {
-  var plan = this.items.plan;
-  var price = plan.price[this.items.currency];
-  price.amount = price.unit_amount * (plan.quantity || 1);
-  return price;
-};
-
-/**
- * Applies a decimal transform on an object's member
- *
- * @param {String} prop Property on {this} to transform
- * @this {Object} on which to apply decimal transformation
- * @private
- */
-
-function decimal (prop) {
-  this[prop] = (Math.round(Math.max(this[prop], 0) * 100) / 100).toFixed(2);
-}
-
-});
-require.register("recurly/lib/recurly/pricing/attach.js", function(exports, require, module){
-/**
- * dependencies
- */
-
-var each = require('each');
-var events = require('event');
-var find = require('find');
-var type = require('type');
-var dom = require('../../util/dom');
-var debug = require('debug')('recurly:pricing:attach');
-
-/**
- * bind a dom element to pricing values
- *
- * @param {HTMLElement} el
- */
-
-exports.attach = function (el) {
-  var self = this;
-  var elems = {};
-  var el = dom.element(el);
-
-  if (!el) throw new Error('invalid dom element');
-
-  if (this.attach.detatch) this.attach.detatch();
-
-  self.on('change', update);
-
-  each(el.querySelectorAll('[data-recurly]'), function (elem) {
-    // 'zip' -> 'postal_code'
-    if (dom.data(elem, 'recurly') === 'zip') dom.data(elem, 'recurly', 'postal_code');
-
-    var name = dom.data(elem, 'recurly');
-    if (!elems[name]) elems[name] = [];
-    elems[name].push(elem);
-    events.bind(elem, 'change', change);
-    events.bind(elem, 'propertychange', change);
-  });
-
-  this.attach.detatch = detatch;
-
-  change();
-
-  function change (event) {
-    debug('change');
-
-    var targetName = event && event.target && dom.data(event.target, 'recurly');
-        targetName = targetName || window.event && window.event.srcElement;
-
-    var pricing = self.plan(dom.value(elems.plan), { quantity: dom.value(elems.plan_quantity) });
-    
-    if (target('currency')) {
-      pricing = pricing.currency(dom.value(elems.currency));
-    }
-
-    if (target('addon') && elems.addon) {
-      addons();
-    }
-
-    if (target('coupon') && elems.coupon) {
-      pricing = pricing.coupon(dom.value(elems.coupon)).then(null, ignoreBadCoupons);
-    }
-
-    if (target('country') || target('postal_code') || target('vat_number')) {
-      pricing = pricing.address({
-        country: dom.value(elems.country),
-        postal_code: dom.value(elems.postal_code),
-        vat_number: dom.value(elems.vat_number)
-      });
-    }
-
-    pricing.done();
-
-    function addons () {
-      each(elems.addon, function (node) {
-        var plan = self.items.plan;
-        var addonCode = dom.data(node, 'recurlyAddon');
-        if (plan.addons && find(plan.addons, { code: addonCode })) {
-          pricing = pricing.addon(addonCode, { quantity: dom.value(node) });
-        }
-      });
-    }
-
-    function target (name) {
-      if (!targetName) return true;
-      if (targetName === name) return true;
-      return false
-    }
-  };
-
-  function update (price) {
-    dom.value(elems.currency_code, price.currency.code);
-    dom.value(elems.currency_symbol, price.currency.symbol);
-    each(['addons', 'discount', 'setup_fee', 'subtotal', 'tax', 'total'], function (value) {
-      dom.value(elems[value + '_now'], price.now[value]);
-      dom.value(elems[value + '_next'], price.next[value]);
-    });
-    if (elems.addonPrice) {
-      each(elems.addonPrice, function (elem) {
-        var addonPrice = price.addons[dom.data(elem, 'recurlyAddon')];
-        if (addonPrice) dom.value(elem, addonPrice);
-      });
-    }
-  }
-
-  function detatch () {
-    each(elems, function (name, elems) {
-      each(elems, function (elem) {
-        events.unbind(elem, 'change', change);
-        events.unbind(elem, 'propertychange', change);
-      }, this);
-    }, this);
-  }
-};
-
-function ignoreBadCoupons (err) {
-  if (err.code === 'not-found') return;
-  else throw err;
-}
-
-/**
- * Backward-compatibility
- *
- * @deprecated
- */
-
-exports.binding = exports.attach;
-
-});
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-require.alias("visionmedia-node-querystring/index.js", "recurly/deps/querystring/index.js");
-require.alias("visionmedia-node-querystring/index.js", "querystring/index.js");
-
-require.alias("component-emitter/index.js", "recurly/deps/emitter/index.js");
-require.alias("component-emitter/index.js", "emitter/index.js");
-
-require.alias("component-indexof/index.js", "recurly/deps/indexof/index.js");
-require.alias("component-indexof/index.js", "indexof/index.js");
-
-require.alias("component-object/index.js", "recurly/deps/object/index.js");
-require.alias("component-object/index.js", "object/index.js");
-
-require.alias("component-event/index.js", "recurly/deps/event/index.js");
-require.alias("component-event/index.js", "event/index.js");
-
-require.alias("component-clone/index.js", "recurly/deps/clone/index.js");
-require.alias("component-clone/index.js", "clone/index.js");
-require.alias("component-type/index.js", "component-clone/deps/type/index.js");
-
-require.alias("component-bind/index.js", "recurly/deps/bind/index.js");
-require.alias("component-bind/index.js", "bind/index.js");
-
-require.alias("component-each/index.js", "recurly/deps/each/index.js");
-require.alias("component-each/index.js", "each/index.js");
-require.alias("component-to-function/index.js", "component-each/deps/to-function/index.js");
-require.alias("component-props/index.js", "component-to-function/deps/props/index.js");
-
-require.alias("component-type/index.js", "component-each/deps/type/index.js");
-
-require.alias("component-find/index.js", "recurly/deps/find/index.js");
-require.alias("component-find/index.js", "find/index.js");
-require.alias("component-to-function/index.js", "component-find/deps/to-function/index.js");
-require.alias("component-props/index.js", "component-to-function/deps/props/index.js");
-
-require.alias("component-json/index.js", "recurly/deps/json/index.js");
-require.alias("component-json/index.js", "json/index.js");
-
-require.alias("component-type/index.js", "recurly/deps/type/index.js");
-require.alias("component-type/index.js", "type/index.js");
-
-require.alias("component-trim/index.js", "recurly/deps/trim/index.js");
-require.alias("component-trim/index.js", "trim/index.js");
-
-require.alias("component-map/index.js", "recurly/deps/map/index.js");
-require.alias("component-map/index.js", "map/index.js");
-require.alias("component-to-function/index.js", "component-map/deps/to-function/index.js");
-require.alias("component-props/index.js", "component-to-function/deps/props/index.js");
-
-require.alias("yields-merge/index.js", "recurly/deps/merge/index.js");
-require.alias("yields-merge/index.js", "merge/index.js");
-
-require.alias("learnboost-jsonp/index.js", "recurly/deps/jsonp/index.js");
-require.alias("learnboost-jsonp/index.js", "recurly/deps/jsonp/index.js");
-require.alias("learnboost-jsonp/index.js", "jsonp/index.js");
-require.alias("visionmedia-debug/debug.js", "learnboost-jsonp/deps/debug/debug.js");
-require.alias("visionmedia-debug/debug.js", "learnboost-jsonp/deps/debug/index.js");
-require.alias("visionmedia-debug/debug.js", "visionmedia-debug/index.js");
-require.alias("learnboost-jsonp/index.js", "learnboost-jsonp/index.js");
-require.alias("visionmedia-debug/debug.js", "recurly/deps/debug/debug.js");
-require.alias("visionmedia-debug/debug.js", "recurly/deps/debug/index.js");
-require.alias("visionmedia-debug/debug.js", "debug/index.js");
-require.alias("visionmedia-debug/debug.js", "visionmedia-debug/index.js");
-require.alias("chrissrogers-promise/index.js", "recurly/deps/promise/index.js");
-require.alias("chrissrogers-promise/core.js", "recurly/deps/promise/core.js");
-require.alias("chrissrogers-promise/index.js", "promise/index.js");
-require.alias("johntron-asap/asap.js", "chrissrogers-promise/deps/asap/asap.js");
-require.alias("johntron-asap/asap.js", "chrissrogers-promise/deps/asap/index.js");
-require.alias("johntron-asap/asap.js", "johntron-asap/index.js");
-require.alias("kewah-mixin/index.js", "recurly/deps/mixin/index.js");
-require.alias("kewah-mixin/index.js", "recurly/deps/mixin/index.js");
-require.alias("kewah-mixin/index.js", "mixin/index.js");
-require.alias("kewah-mixin/index.js", "kewah-mixin/index.js");
-require.alias("pluma-par/dist/par.js", "recurly/deps/par/dist/par.js");
-require.alias("pluma-par/dist/par.js", "recurly/deps/par/index.js");
-require.alias("pluma-par/dist/par.js", "par/index.js");
-require.alias("pluma-par/dist/par.js", "pluma-par/index.js");
-require.alias("ianstormtaylor-to-slug-case/index.js", "recurly/deps/to-slug-case/index.js");
-require.alias("ianstormtaylor-to-slug-case/index.js", "to-slug-case/index.js");
-require.alias("ianstormtaylor-to-space-case/index.js", "ianstormtaylor-to-slug-case/deps/to-space-case/index.js");
-require.alias("ianstormtaylor-to-no-case/index.js", "ianstormtaylor-to-space-case/deps/to-no-case/index.js");
-
-require.alias("recurly/lib/index.js", "recurly/index.js");if (typeof exports == "object") {
-  module.exports = require("recurly");
-} else if (typeof define == "function" && define.amd) {
-  define([], function(){ return require("recurly"); });
-} else {
-  this["recurly"] = require("recurly");
-}})();

Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
services/web/public/js/libs/recurly-4.8.5.js


Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
services/web/public/js/libs/recurly.min.js


+ 1 - 5
services/web/public/stylesheets/_style_includes.less

@@ -84,8 +84,4 @@
 @import	"../js/libs/pdfListView/TextLayer.css";
 @import	"../js/libs/pdfListView/AnnotationsLayer.css";
 @import	"../js/libs/pdfListView/HighlightsLayer.css";
-
-// CodeMirror
-& when (@show-rich-text) {
-  @import "vendor/codemirror.css";
-}
+@import "vendor/codemirror.css";

+ 2 - 8
services/web/public/stylesheets/app/editor.less

@@ -12,9 +12,7 @@
 @import "./editor/online-users.less";
 @import "./editor/hotkeys.less";
 @import "./editor/review-panel.less";
-& when (@show-rich-text) {
-	@import "./editor/rich-text.less";
-}
+@import "./editor/rich-text.less";
 
 @ui-layout-toggler-def-height: 50px;
 @ui-resizer-size: 7px;
@@ -82,10 +80,7 @@
 	.full-size;
 }
 
-#editor when (@show-rich-text = true) {
-	top: 40px; // TODO: replace with toolbar height var
-}
-#editor-rich-text when (@show-rich-text = true) {
+#editor-rich-text {
 	top: 40px; // TODO: replace with toolbar height var
 }
 
@@ -305,7 +300,6 @@
 }
 
 .ui-layout-resizer when (@is-overleaf = true) {
-	z-index: 5 !important;
 	width: @ui-resizer-size !important;
 	background-color: @editor-resizer-bg-color;
 	&.ui-layout-resizer-closed {

+ 5 - 0
services/web/public/stylesheets/app/recurly.less

@@ -1,3 +1,8 @@
+.recurly-hosted-field {
+	&:extend(.form-control);
+}
+
+
 .recurly {
 	display: block;
 	position: relative;

+ 2 - 1
services/web/public/stylesheets/components/forms.less

@@ -309,8 +309,9 @@ input[type="checkbox"],
 .has-warning {
   .form-control-validation(@state-warning-text; @state-warning-text; @state-warning-bg);
 }
-.has-error {
+.has-external-error {
   .form-control-validation(@state-danger-text; @state-danger-text; @state-danger-bg);
+  color:@red;
 }
 
 .form-control.ng-dirty.ng-invalid:not(:focus) {

+ 5 - 2
services/web/test/acceptance/coffee/LinkedFilesTests.coffee

@@ -1,7 +1,9 @@
 async = require "async"
 expect = require("chai").expect
 _ = require 'underscore'
+mkdirp = require "mkdirp"
 
+Settings = require "settings-sharelatex"
 MockFileStoreApi = require './helpers/MockFileStoreApi'
 request = require "./helpers/request"
 User = require "./helpers/User"
@@ -22,7 +24,8 @@ describe "LinkedFiles", ->
 		LinkedUrlProxy.listen 6543, (error) =>
 			return done(error) if error?
 			@owner = new User()
-			@owner.login done
+			@owner.login ->
+				mkdirp Settings.path.dumpFolder, done
 
 	describe "creating a URL based linked file", ->
 		before (done) ->
@@ -181,4 +184,4 @@ describe "LinkedFiles", ->
 						done()
 
 		# TODO: Add test for asking for host that return ENOTFOUND
-		# (This will probably end up handled by the proxy)
+		# (This will probably end up handled by the proxy)

+ 3 - 0
services/web/test/acceptance/coffee/ProjectDuplicateNameTests.coffee

@@ -186,10 +186,13 @@ describe "ProjectDuplicateNames", ->
 									contentType: 'image/jpeg'
 					, (err, res, body) =>
 						@body = body
+						# update the image id because we have replaced the file
+						@imageFile._id = @body.entity_id
 						done()
 
 				it "should succeed (overwriting the file)", ->
 					expect(@body.success).to.equal true
+				# at this point the @imageFile._id has changed
 
 		describe "for an existing folder", ->
 			describe "trying to add a doc with the same name", ->

+ 12 - 3
services/web/test/acceptance/coffee/ProjectStructureTests.coffee

@@ -56,7 +56,6 @@ describe "ProjectStructureChanges", ->
 	describe "duplicating a project", ->
 		before (done) ->
 			MockDocUpdaterApi.clearProjectStructureUpdates()
-			console.log(example_project_id)
 			@owner.request.post {
 				uri: "/Project/#{example_project_id}/clone",
 				json:
@@ -219,11 +218,17 @@ describe "ProjectStructureChanges", ->
 				if res.statusCode < 200 || res.statusCode >= 300
 					throw new Error("failed to upload file #{res.statusCode}")
 
+				example_file_id = JSON.parse(body).entity_id
+
 				{fileUpdates:updates, version} = MockDocUpdaterApi.getProjectStructureUpdates(example_project_id)
-				expect(updates.length).to.equal(1)
+				expect(updates.length).to.equal(2)
 				update = updates[0]
 				expect(update.userId).to.equal(@owner._id)
 				expect(update.pathname).to.equal("/1pixel.png")
+				#expect(update.url).to.be.a('string');
+				update = updates[1]
+				expect(update.userId).to.equal(@owner._id)
+				expect(update.pathname).to.equal("/1pixel.png")
 				expect(update.url).to.be.a('string');
 				expect(version).to.equal(@project_0.version + 1)
 
@@ -591,10 +596,14 @@ describe "ProjectStructureChanges", ->
 					throw new Error("failed to upload file #{res.statusCode}")
 
 				{fileUpdates:updates, version} = MockDocUpdaterApi.getProjectStructureUpdates(@tpds_project_id)
-				expect(updates.length).to.equal(1)
+				expect(updates.length).to.equal(2)
 				update = updates[0]
 				expect(update.userId).to.equal(@owner._id)
 				expect(update.pathname).to.equal("/1pixel.png")
+				#expect(update.url).to.be.a('string');
+				update = updates[1]
+				expect(update.userId).to.equal(@owner._id)
+				expect(update.pathname).to.equal("/1pixel.png")
 				expect(update.url).to.be.a('string');
 				expect(version).to.equal(@project_0.version + 1)
 

+ 7 - 5
services/web/test/unit/coffee/Editor/EditorControllerTests.coffee

@@ -20,6 +20,8 @@ describe "EditorController", ->
 		@fsPath = "/folder/file.png"
 		@linkedFileData = {provider: 'url'}
 
+		@newFile = _id: "new-file-id"
+
 		@folder_id = "123ksajdn"
 		@folder = _id: @folder_id
 		@folderName = "folder"
@@ -107,7 +109,7 @@ describe "EditorController", ->
 
 	describe 'upsertFile', ->
 		beforeEach ->
-			@ProjectEntityUpdateHandler.upsertFile = sinon.stub().yields(null, @file, false)
+			@ProjectEntityUpdateHandler.upsertFile = sinon.stub().yields(null, @newFile, false, @file)
 			@EditorController.upsertFile @project_id, @folder_id, @fileName, @fsPath, @linkedFileData, @source, @user_id, @callback
 
 		it 'upserts the file using the project entity handler', ->
@@ -116,7 +118,7 @@ describe "EditorController", ->
 				.should.equal true
 
 		it 'returns the file', ->
-			@callback.calledWith(null, @file).should.equal true
+			@callback.calledWith(null, @newFile).should.equal true
 
 		describe 'file does not exist', ->
 			beforeEach ->
@@ -171,7 +173,7 @@ describe "EditorController", ->
 		beforeEach ->
 			@filePath = '/folder/file'
 
-			@ProjectEntityUpdateHandler.upsertFileWithPath = sinon.stub().yields(null, @file, false, [], @folder)
+			@ProjectEntityUpdateHandler.upsertFileWithPath = sinon.stub().yields(null, @newFile, false, @file, [], @folder)
 			@EditorController.upsertFileWithPath @project_id, @filePath, @fsPath, @linkedFileData, @source, @user_id, @callback
 
 		it 'upserts the file using the project entity handler', ->
@@ -181,7 +183,7 @@ describe "EditorController", ->
 
 		describe 'file does not exist', ->
 			beforeEach ->
-				@ProjectEntityUpdateHandler.upsertFileWithPath = sinon.stub().yields(null, @file, true, [], @folder)
+				@ProjectEntityUpdateHandler.upsertFileWithPath = sinon.stub().yields(null, @file, true, undefined, [], @folder)
 				@EditorController.upsertFileWithPath @project_id, @filePath, @fsPath, @linkedFileData, @source, @user_id, @callback
 
 			it 'should send the update for the file out to users in the project', ->
@@ -195,7 +197,7 @@ describe "EditorController", ->
 					@folderA = { _id: 2, parentFolder_id: 1}
 					@folderB = { _id: 3, parentFolder_id: 2}
 				]
-				@ProjectEntityUpdateHandler.upsertFileWithPath = sinon.stub().yields(null, @file, true, folders, @folderB)
+				@ProjectEntityUpdateHandler.upsertFileWithPath = sinon.stub().yields(null, @file, true, undefined, folders, @folderB)
 				@EditorController.upsertFileWithPath @project_id, @filePath, @fsPath, @linkedFileData, @source, @user_id, @callback
 
 			it 'should send the update for each folder to users in the project', ->

+ 50 - 7
services/web/test/unit/coffee/Project/ProjectEntityMongoUpdateHandlerTests.coffee

@@ -93,33 +93,50 @@ describe 'ProjectEntityMongoUpdateHandler', ->
 				.calledWith(@project, folder_id, @file, 'file', @callback)
 				.should.equal true
 
-	describe 'replaceFile', ->
+	describe 'replaceFileWithNew', ->
 		beforeEach ->
 			@file = _id: file_id
 			@path = mongo: 'file.png'
-			@linkedFileData = {provider: 'url'}
+			@newFile = _id: 'new-file-id'
+			@newFile.linkedFileData = @linkedFileData = {provider: 'url'}
 			@ProjectLocator.findElement = sinon.stub().yields(null, @file, @path)
 			@ProjectModel.update = sinon.stub().yields()
 
-			@subject.replaceFile project_id, file_id, @linkedFileData, @callback
+			@subject.replaceFileWithNew project_id, file_id, @newFile, @callback
 
 		it 'gets the project', ->
 			@ProjectGetter.getProjectWithoutLock
 				.calledWith(project_id, {rootFolder:true, name: true})
 				.should.equal true
 
-		it 'finds the element', ->
+		it 'finds the existing element', ->
 			@ProjectLocator.findElement
 				.calledWith({ @project, element_id: file_id, type: 'file' })
 				.should.equal true
 
-		it 'increments the rev and sets the created_at', ->
+		it 'inserts a deletedFile reference for the old file', ->
+			@ProjectModel.update
+				.calledWith({ _id: project_id },
+					{
+						$push: {
+							deletedFiles: {
+								_id:  file_id
+								name: @file.name
+								linkedFileData: @file.linkedFileData
+								deletedAt: new Date()
+							}
+						}
+					}
+				)
+				.should.equal true
+
+		it 'increments the project version and sets the rev and created_at', ->
 			@ProjectModel.update
 				.calledWith(
 					{ _id: project_id },
 					{
-						'$inc': { 'file.png.rev': 1, 'version': 1 }
-						'$set': { 'file.png.created': new Date(), 'file.png.linkedFileData': @linkedFileData }
+						'$inc': { 'version': 1 }
+						'$set': { 'file.png._id': @newFile._id, 'file.png.created': new Date(), 'file.png.linkedFileData': @linkedFileData, 'file.png.rev': 1 }
 					}
 					{}
 				)
@@ -596,3 +613,29 @@ describe 'ProjectEntityMongoUpdateHandler', ->
 			folder = name: 'folder_name'
 			@subject._checkValidMove @project, 'folder', folder, fileSystem: '/foo', @destFolder._id, (err) =>
 				expect(err).to.deep.equal new Errors.InvalidNameError("destination folder is a child folder of me")
+
+	describe "_insertDeletedDocReference", ->
+		beforeEach ->
+			@doc =
+				_id: ObjectId()
+				name: "test.tex"
+			@callback = sinon.stub()
+			@ProjectModel.update = sinon.stub().yields()
+			@subject._insertDeletedDocReference project_id, @doc, @callback
+
+		it "should insert the doc into deletedDocs", ->
+			@ProjectModel.update
+				.calledWith({
+					_id: project_id
+				}, {
+					$push: {
+						deletedDocs: {
+							_id: @doc._id
+							name: @doc.name
+						}
+					}
+				})
+				.should.equal true
+
+		it "should call the callback", ->
+			@callback.called.should.equal true

+ 68 - 53
services/web/test/unit/coffee/Project/ProjectEntityUpdateHandlerTests.coffee

@@ -14,6 +14,7 @@ describe 'ProjectEntityUpdateHandler', ->
 	file_id = "4eecaffcbffa66588e000009"
 	folder_id = "4eecaffcbffa66588e000008"
 	rootFolderId = "4eecaffcbffa66588e000007"
+	new_file_id = "4eecaffcbffa66588e000099"
 	userId = 1234
 
 	beforeEach ->
@@ -31,7 +32,11 @@ describe 'ProjectEntityUpdateHandler', ->
 		@FileModel = class File
 			constructor:(options)->
 				{@name} = options
-				@._id = file_id
+				# use a new id for replacement files
+				if @name is 'dummy-upload-filename'
+					@._id = new_file_id
+				else
+					@._id = file_id
 				@rev = 0
 
 		@docName = "doc-name"
@@ -274,14 +279,33 @@ describe 'ProjectEntityUpdateHandler', ->
 		beforeEach ->
 			@path = "/path/to/file"
 
-			@newFile = _id: file_id
-			@ProjectEntityUpdateHandler.addFileWithoutUpdatingHistory =
-				withoutLock: sinon.stub().yields(null, @newFile, folder_id, @path, @fileUrl)
-			@ProjectEntityUpdateHandler.addFile project_id, folder_id, @docName, @fileSystemPath, @linkedFileData, userId, @callback
+			@newFile = {_id: file_id, rev: 0, name: @fileName}
+			@TpdsUpdateSender.addFile = sinon.stub().yields()
+			@ProjectEntityMongoUpdateHandler.addFile = sinon.stub().yields(null, {path: fileSystem: @path}, @project)
+			@ProjectEntityUpdateHandler.addFile project_id, folder_id, @fileName, @fileSystemPath, @linkedFileData, userId, @callback
 
-		it "creates the doc without history", () ->
-			@ProjectEntityUpdateHandler.addFileWithoutUpdatingHistory.withoutLock
-				.calledWith(project_id, folder_id, @docName, @fileSystemPath, @linkedFileData, userId)
+		it "updates the file in the filestore", () ->
+			@FileStoreHandler.uploadFileFromDisk
+				.calledWith(project_id, file_id, @fileSystemPath)
+				.should.equal true
+
+		it "updates the file in mongo", () ->
+			fileMatcher = sinon.match (file) =>
+				file.name == @fileName
+
+			@ProjectEntityMongoUpdateHandler.addFile
+				.calledWithMatch(project_id, folder_id, fileMatcher)
+				.should.equal true
+
+		it "notifies the tpds", () ->
+			@TpdsUpdateSender.addFile
+				.calledWith({
+					project_id: project_id
+					project_name: @project.name
+					file_id: file_id
+					rev: 0
+					path: @path
+				})
 				.should.equal true
 
 		it "sends the change in project structure to the doc updater", () ->
@@ -296,21 +320,26 @@ describe 'ProjectEntityUpdateHandler', ->
 
 	describe 'replaceFile', ->
 		beforeEach ->
-			@newFile = _id: file_id, rev: 0
+			# replacement file now creates a new file object
+			@newFileUrl = "new-file-url"
+			@FileStoreHandler.uploadFileFromDisk = sinon.stub().yields(null, @newFileUrl)
+
+			@newFile = _id: new_file_id, name: "dummy-upload-filename", rev: 0
+			@oldFile = _id: file_id
 			@path = "/path/to/file"
 			@project = _id: project_id, name: 'some project'
-			@ProjectEntityMongoUpdateHandler.replaceFile = sinon.stub().yields(null, @newFile, @project, fileSystem: @path)
-
+			@ProjectEntityMongoUpdateHandler._insertDeletedFileReference = sinon.stub().yields()
+			@ProjectEntityMongoUpdateHandler.replaceFileWithNew = sinon.stub().yields(null, @oldFile, @project, fileSystem: @path)
 			@ProjectEntityUpdateHandler.replaceFile project_id, file_id, @fileSystemPath, @linkedFileData, userId, @callback
 
 		it 'uploads a new version of the file', ->
 			@FileStoreHandler.uploadFileFromDisk
-				.calledWith(project_id, file_id, @fileSystemPath)
+				.calledWith(project_id, new_file_id, @fileSystemPath)
 				.should.equal true
 
 		it 'replaces the file in mongo', ->
-			@ProjectEntityMongoUpdateHandler.replaceFile
-				.calledWith(project_id, file_id, @linkedFileData)
+			@ProjectEntityMongoUpdateHandler.replaceFileWithNew
+				.calledWith(project_id, file_id, @newFile)
 				.should.equal true
 
 		it 'notifies the tpds', ->
@@ -318,20 +347,24 @@ describe 'ProjectEntityUpdateHandler', ->
 				.calledWith({
 					project_id: project_id
 					project_name: @project.name
-					file_id: file_id
+					file_id: new_file_id
 					rev: @newFile.rev + 1
 					path: @path
 				})
 				.should.equal true
 
 		it 'updates the project structure in the doc updater', ->
+			oldFiles = [
+				file: @oldFile
+				path: @path
+			]
 			newFiles = [
 				file: @newFile
 				path: @path
-				url: @fileUrl
+				url: @newFileUrl
 			]
 			@DocumentUpdaterHandler.updateProjectStructure
-				.calledWith(project_id, userId, {newFiles})
+				.calledWith(project_id, userId, {oldFiles, newFiles})
 				.should.equal true
 
 	describe 'addDocWithoutUpdatingHistory', ->
@@ -490,12 +523,12 @@ describe 'ProjectEntityUpdateHandler', ->
 				@existingFile = _id: file_id, name: @fileName
 				@folder = _id: folder_id, fileRefs: [@existingFile]
 				@ProjectLocator.findElement = sinon.stub().yields(null, @folder)
-				@ProjectEntityUpdateHandler.replaceFile = withoutLock: sinon.stub().yields(null, @newFile)
+				@ProjectEntityUpdateHandler.replaceFile = mainTask: sinon.stub().yields(null, @newFile)
 
 				@ProjectEntityUpdateHandler.upsertFile project_id, folder_id, @fileName, @fileSystemPath, @linkedFileData, userId, @callback
 
 			it 'replaces the file', ->
-				@ProjectEntityUpdateHandler.replaceFile.withoutLock
+				@ProjectEntityUpdateHandler.replaceFile.mainTask
 					.calledWith(project_id, file_id, @fileSystemPath, @linkedFileData, userId)
 					.should.equal true
 
@@ -507,7 +540,7 @@ describe 'ProjectEntityUpdateHandler', ->
 				@folder = _id: folder_id, fileRefs: []
 				@newFile = _id: file_id
 				@ProjectLocator.findElement = sinon.stub().yields(null, @folder)
-				@ProjectEntityUpdateHandler.addFile = withoutLock: sinon.stub().yields(null, @newFile)
+				@ProjectEntityUpdateHandler.addFile = mainTask: sinon.stub().yields(null, @newFile)
 
 				@ProjectEntityUpdateHandler.upsertFile project_id, folder_id, @fileName, @fileSystemPath, @linkedFileData, userId, @callback
 
@@ -517,7 +550,7 @@ describe 'ProjectEntityUpdateHandler', ->
 					.should.equal true
 
 			it 'adds the file', ->
-				@ProjectEntityUpdateHandler.addFile.withoutLock
+				@ProjectEntityUpdateHandler.addFile.mainTask
 					.calledWith(project_id, folder_id, @fileName, @fileSystemPath, @linkedFileData, userId)
 					.should.equal true
 
@@ -563,7 +596,7 @@ describe 'ProjectEntityUpdateHandler', ->
 			@ProjectEntityUpdateHandler.mkdirp =
 				withoutLock: sinon.stub().yields(null, @newFolders, @folder)
 			@ProjectEntityUpdateHandler.upsertFile =
-				withoutLock: sinon.stub().yields(null, @file, @isNewFile)
+				mainTask: sinon.stub().yields(null, @file, @isNewFile)
 
 			@ProjectEntityUpdateHandler.upsertFileWithPath project_id, @path, @fileSystemPath, @linkedFileData, userId, @callback
 
@@ -573,13 +606,13 @@ describe 'ProjectEntityUpdateHandler', ->
 				.should.equal true
 
 		it 'upserts the file', ->
-			@ProjectEntityUpdateHandler.upsertFile.withoutLock
+			@ProjectEntityUpdateHandler.upsertFile.mainTask
 				.calledWith(project_id, @folder._id, 'file.png', @fileSystemPath, @linkedFileData, userId)
 				.should.equal true
 
 		it 'calls the callback', ->
 			@callback
-				.calledWith(null, @file, @isNewFile, @newFolders, @folder)
+				.calledWith(null, @file, @isNewFile, undefined, @newFolders, @folder)
 				.should.equal true
 
 	describe 'deleteEntity', ->
@@ -798,6 +831,7 @@ describe 'ProjectEntityUpdateHandler', ->
 			@FileStoreHandler.deleteFile = sinon.stub().yields()
 			@DocumentUpdaterHandler.deleteDoc = sinon.stub().yields()
 			@ProjectEntityUpdateHandler.unsetRootDoc = sinon.stub().yields()
+			@ProjectEntityMongoUpdateHandler._insertDeletedFileReference = sinon.stub().yields()
 
 		describe "a file", ->
 			beforeEach (done) ->
@@ -805,8 +839,13 @@ describe 'ProjectEntityUpdateHandler', ->
 				@entity = _id: @entity_id
 				@ProjectEntityUpdateHandler._cleanUpEntity @project, @entity, 'file', @path, userId, done
 
-			it "should delete the file from FileStoreHandler", ->
-				@FileStoreHandler.deleteFile.calledWith(project_id, @entity_id).should.equal true
+			it "should insert the file into the deletedFiles array", ->
+				@ProjectEntityMongoUpdateHandler._insertDeletedFileReference
+					.calledWith(@project._id, @entity)
+					.should.equal true
+
+			it "should not delete the file from FileStoreHandler", ->
+				@FileStoreHandler.deleteFile.calledWith(project_id, @entity_id).should.equal false
 
 			it "should not attempt to delete from the document updater", ->
 				@DocumentUpdaterHandler.deleteDoc.called.should.equal false
@@ -871,7 +910,7 @@ describe 'ProjectEntityUpdateHandler', ->
 				name: "test.tex"
 			@path = "/path/to/doc"
 			@ProjectEntityUpdateHandler.unsetRootDoc = sinon.stub().yields()
-			@ProjectEntityUpdateHandler._insertDeletedDocReference = sinon.stub().yields()
+			@ProjectEntityMongoUpdateHandler._insertDeletedDocReference = sinon.stub().yields()
 			@DocumentUpdaterHandler.deleteDoc = sinon.stub().yields()
 			@DocstoreManager.deleteDoc = sinon.stub().yields()
 			@callback = sinon.stub()
@@ -891,7 +930,7 @@ describe 'ProjectEntityUpdateHandler', ->
 					.calledWith(project_id, @doc._id.toString())
 
 			it "should insert the doc into the deletedDocs array", ->
-				@ProjectEntityUpdateHandler._insertDeletedDocReference
+				@ProjectEntityMongoUpdateHandler._insertDeletedDocReference
 					.calledWith(@project._id, @doc)
 					.should.equal true
 
@@ -920,28 +959,4 @@ describe 'ProjectEntityUpdateHandler', ->
 			it "should call the callback", ->
 				@callback.called.should.equal true
 
-	describe "_insertDeletedDocReference", ->
-		beforeEach ->
-			@doc =
-				_id: ObjectId()
-				name: "test.tex"
-			@callback = sinon.stub()
-			@ProjectModel.update = sinon.stub().yields()
-			@ProjectEntityUpdateHandler._insertDeletedDocReference project_id, @doc, @callback
-
-		it "should insert the doc into deletedDocs", ->
-			@ProjectModel.update
-				.calledWith({
-					_id: project_id
-				}, {
-					$push: {
-						deletedDocs: {
-							_id: @doc._id
-							name: @doc.name
-						}
-					}
-				})
-				.should.equal true
-
-		it "should call the callback", ->
-			@callback.called.should.equal true
+	

+ 3 - 1
services/web/webpack.config.js

@@ -52,6 +52,7 @@ module.exports = {
 				loader: 'babel-loader',
 				options: {
 					presets: [
+						'react',
 						['env', { modules: false }]
 					],
 					// Configure babel-loader to cache compiled output so that subsequent
@@ -64,4 +65,5 @@ module.exports = {
 
 	// TODO
 	// plugins: {}
-}
+}
+

+ 1 - 2
services/web/webpack.config.prod.js

@@ -5,8 +5,7 @@ const merge = require('webpack-merge')
 const base = require('./webpack.config')
 
 module.exports = merge(base, {
-  // Enable a full source map.
-  devtool: 'source-map',
+  devtool: false,
 
   output: {
     // Override output path to minjs dir

Неке датотеке нису приказане због велике количине промена