Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.

Cancel

Juniper - Customer Success

node v8.17.0
version: 1.2.1
endpointsharetweet
const runkitExpress = require('@runkit/runkit/express-endpoint/1.0.0'); const app = runkitExpress(exports); // const express = require('express'); // const app = express(); const bodyParser = require('body-parser'); app.use(bodyParser.urlencoded({ extended: false })); app.use(bodyParser.json()); app.use(function(req, res, next) { res.header('Access-Control-Allow-Origin', '*'); res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept'); next(); }); // app.listen(5000, () => console.log(`Example app listening on port ${5000}!`)); function getAllParams(req) { return Object.assign({}, req.query, req.body); } const BASE_DATE = '2018-07-10T05:56:57.712Z'; const INDUSTRY_KEY = 'industry'; const SOLUTION_KEY = 'solution'; const REGION_KEY = 'region'; const SORT_KEY = 'sort'; const SORT_FN = { // Sort by featured and then by timestamp default: (a, b) => a.featured && !b.featured ? -1 : !a.featured && b.featured ? 1 : a.timestamp > b.timestamp ? -1 : 1, // Sort alphabetically a-z 'a-z': (a, b) => a.companyName < b.companyName ? -1 : a.companyName > b.companyName ? 1 : 0, // Sort alphabetically z-a 'z-a': (a, b) => a.companyName > b.companyName ? -1 : a.companyName < b.companyName ? 1 : 0, }; const LOGO_SIZES = [ { w: 220, h: 30 }, { w: 200, h: 50 }, { w: 400, h: 50 }, { w: 250, h: 75 }, { w: 150, h: 75 } ]; const MOCK_LOGOS = [ 'https://jnpr-assets.swirl-staging.net/jnpr2/images/acme-logos/acme01-1x.png', 'https://jnpr-assets.swirl-staging.net/jnpr2/images/acme-logos/acme02-1x.png', 'https://jnpr-assets.swirl-staging.net/jnpr2/images/acme-logos/acme03-1x.png', 'https://jnpr-assets.swirl-staging.net/jnpr2/images/acme-logos/acme04-1x.png', 'https://jnpr-assets.swirl-staging.net/jnpr2/images/acme-logos/acme05-1x.png', 'https://jnpr-assets.swirl-staging.net/jnpr2/images/acme-logos/acme06-1x.png', 'https://jnpr-assets.swirl-staging.net/jnpr2/images/acme-logos/acme07-1x.png', 'https://jnpr-assets.swirl-staging.net/jnpr2/images/acme-logos/acme08-1x.png', 'https://jnpr-assets.swirl-staging.net/jnpr2/images/acme-logos/acme09-1x.png', 'https://jnpr-assets.swirl-staging.net/jnpr2/images/acme-logos/acme10-1x.png' ]; const ARRAY_PARAMS = [INDUSTRY_KEY, SOLUTION_KEY, REGION_KEY]; const handleRoot = (req, res) => { /** Get all params */ const params = getAllParams(req); const filters = Object.keys(params).reduce((acc, key) => { // Skip empty values if (!params[key]) return acc; // Coerce array where applicable acc[key] = ARRAY_PARAMS.indexOf(key) > -1 ? [].concat(params[key]) : params[key]; // Return return acc; }, {}); const filterKeys = Object.keys(filters); // Select sort function if provided or fallback to default const sortFn = SORT_KEY in filters && filters[SORT_KEY] in SORT_FN ? SORT_FN[filters[SORT_KEY]] : SORT_FN.default; const data = getAllCustomerSuccessStoriesData().filter(record => { const industry = !(INDUSTRY_KEY in filters) ? true : filters[INDUSTRY_KEY].every(t => record[INDUSTRY_KEY].indexOf(t) > -1); const solution = !(SOLUTION_KEY in filters) ? true : filters[SOLUTION_KEY].every(t => record[SOLUTION_KEY].indexOf(t) > -1); const region = !(REGION_KEY in filters) ? true : filters[REGION_KEY].every(t => record[REGION_KEY].indexOf(t) > -1); return industry && solution && region; }).sort(sortFn); const message = filterKeys.length > 0 ? `Juniper Customer Success Stories tagged with: \`${filterKeys.join('`, `')}\`.` : `All Customer Success Stories`; res.json({ message, length: data.length, data }); }; app.get('/', handleRoot); app.post('/', handleRoot); app.options('/*', function(req, res, next) { res.header('Access-Control-Allow-Origin', '*'); res.header('Access-Control-Allow-Methods', 'GET,PUT,OPTIONS'); res.send(200); }); app.all('/debug', (req, res) => { res.json({ message: 'See `/debug/params` to debug params being passed' }); }); app.all('/debug/params', (req, res) => { res.json({ message: 'Params found in `body` take precedence over `query`', data: getAllParams(req) }); }); app.all('/debug/data', (req, res) => { const data = getAllCustomerSuccessStoriesData(); res.json({ message: 'All Customer Success Stories', length: data.length, data }); }); /* The function below simply returns the whole data set. It's wrapped by a function for cleanliness: It allows us to place it at the bottom but still have access to it from the top because of hoisting. */ function getAllCustomerSuccessStoriesData() { const INDUSTRY = { E_COMMERCE: 'e-commerce', EDUCATION: 'education', ENERGY: 'energy', FINANCIAL_SERVICES: 'financial-services', GOVERNMENT: 'government', HEALTHCARE: 'healthcare', INSURANCE: 'insurance', MANUFACTURING: 'manufacturing', MEDIA_ENTERTAINMENT: 'media-entertainment', RESELLER_AND_SERVICE_PROVIDER: 'reseller-and-service-provider', RETAIL: 'retail', SCIENTIFIC_RESEARCH: 'scientific-research', SERVICE_PROVIDER: 'service-provider', TECHNOLOGY: 'technology', TELECOMMUNICATIONS: 'telecommunications', TRAVEL_AND_HOSPITALITY: 'travel-and-hospitality', WEB_SERVICES: 'web-services' }; const SOLUTION = { IDENTITY_AND_POLICY_CONTROL: 'identity-and-policy-control', NETWORK_MANAGEMENT: 'network-management', NETWORK_OPERATING_SYSTEM: 'network-operating-system', ROUTERS: 'routers', SECURITY: 'security', SERVICES: 'services', SOFTWARE_DEFINED_NETWORKING: 'software-defined-networking', SWITCHES: 'switches', WIRELESS: 'wireless' }; const REGION = { EN_US: 'en-us', ES_LA: 'es-la', DE_DE: 'de-de', FR_FR: 'fr-fr', EN_UK: 'en-uk', ZH_CH: 'zh-ch', JP_JP: 'jp-jp', KR_KR: 'kr-kr' }; return [ { [REGION_KEY]: [REGION.EN_US], [SOLUTION_KEY]: [SOLUTION.NETWORK_MANAGEMENT], [INDUSTRY_KEY]: [INDUSTRY.MEDIA_ENTERTAINMENT], title: 'Far far away, behind the word mountains, far from the countries Vokalia.' }, { [REGION_KEY]: [REGION.ES_LA], [SOLUTION_KEY]: [SOLUTION.SWITCHES, SOLUTION.SECURITY], [INDUSTRY_KEY]: [INDUSTRY.EDUCATION, INDUSTRY.GOVERNMENT], title: 'Separated they live in Bookmarksgrove right at the coast of the Semantics.' }, { [REGION_KEY]: [REGION.JP_JP], [SOLUTION_KEY]: [SOLUTION.ROUTERS, SOLUTION.WIRELESS], [INDUSTRY_KEY]: [INDUSTRY.WEB_SERVICES, INDUSTRY.TECHNOLOGY], title: 'A small river named Duden flows by their place.' }, { [REGION_KEY]: [REGION.EN_US, REGION.EN_UK], [SOLUTION_KEY]: [SOLUTION.IDENTITY_AND_POLICY_CONTROL], [INDUSTRY_KEY]: [INDUSTRY.SERVICE_PROVIDER], title: 'It is a paradisematic country, in which roasted parts of sentences fly.' }, { [REGION_KEY]: [REGION.ZH_CH], [SOLUTION_KEY]: [SOLUTION.SOFTWARE_DEFINED_NETWORKING], [INDUSTRY_KEY]: [INDUSTRY.MANUFACTURING, INDUSTRY.RESELLER_AND_SERVICE_PROVIDER], title: 'Even the all-powerful Pointing has no control about the blind texts.' }, { [REGION_KEY]: [REGION.FR_FR, REGION.DE_DE], [SOLUTION_KEY]: [SOLUTION.NETWORK_MANAGEMENT, SOLUTION.NETWORK_OPERATING_SYSTEM], [INDUSTRY_KEY]: [INDUSTRY.GOVERNMENT], title: 'It is an almost unorthographic life.' }, { [REGION_KEY]: [REGION.KR_KR], [SOLUTION_KEY]: [SOLUTION.NETWORK_MANAGEMENT, SOLUTION.SWITCHES], [INDUSTRY_KEY]: [INDUSTRY.RETAIL, INDUSTRY.E_COMMERCE], title: 'One day however a small line of blind text by the name of Lorem Ipsum.' }, { [REGION_KEY]: [REGION.EN_US, REGION.ES_LA], [SOLUTION_KEY]: [SOLUTION.IDENTITY_AND_POLICY_CONTROL], [INDUSTRY_KEY]: [INDUSTRY.TRAVEL_AND_HOSPITALITY], title: 'The Big Oxmox advised her not to do so.' }, { [REGION_KEY]: [REGION.EN_US], [SOLUTION_KEY]: [SOLUTION.WIRELESS, SOLUTION.SOFTWARE_DEFINED_NETWORKING], [INDUSTRY_KEY]: [INDUSTRY.ENERGY], title: 'there were thousands of bad Commas, wild Question Marks and devious Semikoli.' }, { [REGION_KEY]: [REGION.EN_US], [SOLUTION_KEY]: [SOLUTION.SECURITY], [INDUSTRY_KEY]: [INDUSTRY.SCIENTIFIC_RESEARCH, INDUSTRY.EDUCATION], title: 'The Little Blind Text didn’t listen.' }, { [REGION_KEY]: [REGION.ZH_CH], [SOLUTION_KEY]: [SOLUTION.ROUTERS, SOLUTION.SERVICES], [INDUSTRY_KEY]: [INDUSTRY.MEDIA_ENTERTAINMENT, INDUSTRY.TECHNOLOGY], title: 'She packed her seven versalia and made herself on the way.' }, { [REGION_KEY]: [REGION.DE_DE, REGION.EN_UK], [SOLUTION_KEY]: [SOLUTION.NETWORK_OPERATING_SYSTEM], [INDUSTRY_KEY]: [INDUSTRY.TELECOMMUNICATIONS, INDUSTRY.RETAIL], title: 'When she reached the first hills of the Italic Mountains.' }, { [REGION_KEY]: [REGION.ES_LA], [SOLUTION_KEY]: [SOLUTION.SECURITY], [INDUSTRY_KEY]: [INDUSTRY.HEALTHCARE], title: 'She had a last view back on the skyline of her hometown Bookmarksgrove.' }, { [REGION_KEY]: [REGION.JP_JP], [SOLUTION_KEY]: [SOLUTION.IDENTITY_AND_POLICY_CONTROL], [INDUSTRY_KEY]: [INDUSTRY.TECHNOLOGY, INDUSTRY.HEALTHCARE], title: 'The headline of Alphabet Village and the subline of her own road.' }, { [REGION_KEY]: [REGION.EN_US, REGION.EN_UK], [SOLUTION_KEY]: [SOLUTION.WIRELESS, SOLUTION.SERVICES], [INDUSTRY_KEY]: [INDUSTRY.WEB_SERVICES], title: 'Pityful a rethoric question ran over her cheek, then she continued her way.' }, { [REGION_KEY]: [REGION.EN_UK], [SOLUTION_KEY]: [SOLUTION.ROUTERS], [INDUSTRY_KEY]: [INDUSTRY.INSURANCE], title: 'The copy warned the Little Blind Text.' } ].map((n, i) => { const date = new Date(BASE_DATE); date.setMonth(date.getMonth() - i * 3); const { w, h } = LOGO_SIZES[i % LOGO_SIZES.length]; const featured = i % 3 === 0; const logo = MOCK_LOGOS[i % MOCK_LOGOS.length]; const hasLogo = i % 5 === 0 && !featured; return Object.assign( {}, n, { id: i, companyName: `ACME Co #${i}`, url: `https://example.com?case-study${i}`, img: `https://picsum.photos/320?image=${Math.pow(i, 2)}`, imgAlt: `ACME Co #${i} Image`, logo: hasLogo ? '' : logo, timestamp: `${date.toISOString()}`, featured }) }); }
Loading…

no comments

    sign in to comment