when(this) .then(this.resolve.bind(this)) .then(this.cache.bind(this)) .then(this.bundle.bind(this)) .then(this.rewriteGraph.bind(this)) .catch(function (err) { console.error(chalk.red('! failed to resolve tarball for %s'), this.getId()); console.error(err); }.bind(this))
// implementation function getUnusedDependencies(config) { return when(config.deps.reduce(updateIndex, clone(config.bundle))); function updateIndex(unused, dependency) { var location = dependency.getPathToBundle(); if (location in unused) { delete unused[location]; } return unused; } function clone(value) { return JSON.parse(JSON.stringify(value)); } }
// implementation function pruneOptionalDependencies(config) { return config.options.keepOptional ? when(config.graph) : getPackageJson(); function getPackageJson() { return fs.readFile(config.path.manifest, {encoding: 'utf8'}) .then(onSuccess, onError); function onSuccess(manifest) { var pkg = JSON.parse(manifest); if (pkg.optionalDependencies) { for (var name in pkg.optionalDependencies) { // eslint-disable-line guard-for-in delete config.graph.dependencies[name]; } } return config.graph; } function onError() { throw new Error('! failed to prune optional dependencies'); } } }
// implementation function getDependencies(config) { Dependency.setConfig(config); var dependencies = []; var handler = config.options.keepOptional ? addDependency : addIfMandatory; forEachNestedDependency(config.graph, handler); return when(dependencies); function addDependency(key, node) { dependencies.push(new Dependency(key, node)); } function addIfMandatory(key, node, parentNode) { if (node.optional === true) { delete parentNode[key]; } else { addDependency(key, node); } } }
var cached = unbundled.length - uncached.length; return when({ bundled: { used: bundled.length,
return when({options: options, startTime: new Date()}) .then(getConfigWithPaths) .then(getConfigWithGraph)
fsp.stat(dirPath) .then((stats) => { if (stats.isDir()) { return when(dirPath); } return when.reject(new Error('dir not found or is a reference to a file')); })
describe('#Spark.eventsGet()', () => { it('returns an array of spark event objects', () => spark.eventsGet(10) .then((events) => { orgEvents = events; return when(assert(validator.isEvents(events), 'invalid response')); })); });
strPayload.then((pl) => { hmac.update(pl); if (cryptoTimingSafeEqualStr(signature, hmac.digest('hex'))) { return when(payload); } return when.reject(new Error('received an invalid payload')); })
describe('#Spark.eventGet(eventId)', () => { it('returns spark event object', () => { if (!(orgEvents instanceof Array && orgEvents.length > 0)) { this.skip(); return when.reject(new Error('org events not found')); } return spark.eventGet(orgEvents[0].id) .then(event => when(assert(validator.isEvent(event), 'invalid response'))); }); });
describe('#Spark.roomAdd()', () => { it('returns a spark room object', () => spark.roomAdd('! node-sparky roomAdd() test :: (safe to delete)') .then((room) => { newRoom = validator.isRoom(room) ? room : false; return when(assert(validator.isRoom(room), 'invalid response')); })); });
describe('#Spark.licensesGet(orgId)', () => { it('returns an array of spark license objects', () => spark.personMe() .then(me => when(me.orgId)) .then(orgId => spark.licensesGet(orgId)) .then((licenses) => { orgLicenses = licenses; return when(assert(validator.isLicenses(licenses), 'invalid response')); })); });
describe('#Spark.webhookAuth()', () => { it('calculates hmac-sha1 and verifies on test data.', () => { const secret = 'testSecret1234'; const sig = 'e514a9a0d82760314204c2b9d9eff2fef2b51511'; const payload = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean vitae sodales elit. Mauris eleifend odio lacus. Integer eu volutpat neque, id varius magna. Nullam ac ex blandit orci blandit varius. Maecenas sollicitudin, lacus ut pharetra cursus, lorem dui egestas massa, a pharetra massa velit sed enim. Sed maximus enim elit, eget tincidunt ante semper eget. Donec vitae tincidunt est. Ut tincidunt erat a tellus dignissim, sit amet egestas diam aliquet. Proin ante massa, vulputate id facilisis vel, faucibus ut diam. Integer nec enim laoreet, ultrices sapien vitae, suscipit urna. Suspendisse bibendum elit eros, et pellentesque nisl tincidunt sed. Proin at auctor magna. Vestibulum blandit, arcu in consectetur varius, neque neque suscipit velit, quis venenatis ipsum dolor non odio. Suspendisse potenti. Mauris volutpat lorem id lacus convallis scelerisque. Pellentesque efficitur ullamcorper metus, sed aliquam ex volutpat in.'; return spark.webhookAuth(secret, sig, payload) .then(ok => when(assert(ok, 'invalid response'))); }); });
describe('#Spark.membershipGet(membershipId)', () => { it('returns a spark membership object', () => { // skip membershipGet if personMemberships is not defined if (!(personMemberships instanceof Array && personMemberships.length > 0)) { this.skip(); return when.reject(new Error('membership not found')); } return spark.membershipGet(personMemberships[0].id) .then(membership => when(assert(validator.isMembership(membership), 'invalid response'))); }); });