Best JavaScript code snippet using wpt
cache.js
Source:cache.js
1/* Copyright (C) 2013-2014 Computer Sciences Corporation2 *3 * Licensed under the Apache License, Version 2.0 (the "License");4 * you may not use this file except in compliance with the License.5 * You may obtain a copy of the License at6 *7 * http://www.apache.org/licenses/LICENSE-2.08 *9 * Unless required by applicable law or agreed to in writing, software10 * distributed under the License is distributed on an "AS IS" BASIS,11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12 * See the License for the specific language governing permissions and13 * limitations under the License. */14/**15 *16 * Created by jhastings on 1/15/15.17 */18var _ = require('lodash-node');19var cache_manager = require('cache-manager');20var ezbakeBaseTypes = require('./thrift/ezbakeBaseTypes_types');21var TokenRequest = ezbakeBaseTypes.TokenRequest;22var TokenType = ezbakeBaseTypes.TokenType;23var TokenTypeStrings = Object.keys(TokenType);24function generate_cache_key(token_type, subject, target_app, exclude_auths, request_chain) {25 // Allow TokenRequest object to be passed in as the first argument26 if (_.isObject(token_type) && token_type instanceof TokenRequest) {27 var token_request = token_type;28 token_type = token_request.type;29 if (token_type === TokenType.APP) {30 subject = token_request.securityId;31 } else {32 // Deserialize the proxy principal33 var pp = JSON.parse(token_request.proxyPrincipal.proxyToken);34 if (_.has(pp, 'x509') && _.has(pp.x509, 'subject')) {35 subject = pp.x509.subject; 36 } else {37 throw new Error("Invalid ProxyPrincipal object. No property proxyToken.x509.subject");38 }39 }40 target_app = token_request.targetSecurityId;41 exclude_auths = token_request.excludeAuthorizations;42 if (_.has(token_request, "tokenPrincipal") && token_request.tokenPrincipal) {43 request_chain = token_request.tokenPrincipal.validity.requestChain;44 }45 }46 // Validate arguments47 if ((_.isNumber(token_type) && token_type >= TokenTypeStrings.length || token_type < 0) ||48 (_.isString(token_type) && !_.contains(TokenTypeStrings, token_type))) {49 throw new Error("Invalid token type: "+token_type);50 }51 if (!_.isString(subject) || _.isNull(subject)) {52 throw new Error("Invalid subject: "+subject);53 }54 if (!_.isString(target_app) && !_.isEmpty(target_app)) {55 throw new Error("Invalid target_app: "+target_app);56 }57 if (exclude_auths && !_.isArray(exclude_auths)) {58 throw new Error("Invalid exclude_auths: "+exclude_auths);59 }60 if (request_chain && !_.isArray(request_chain)) {61 throw new Error("Invalid request_chain: "+request_chain);62 }63 var key_token_type = (_.isString(token_type))? token_type : Object.keys(TokenType)[token_type];64 var key_subject = subject;65 var key_target_app = target_app;66 var key_exclude_auths = (exclude_auths)? exclude_auths.join(",") : '';67 var key_request_chain = (request_chain)? request_chain.join(",") : '';68 return [key_token_type, key_subject, key_target_app, key_exclude_auths, key_request_chain].join('');69}...
api.js
Source:api.js
1import _ from 'lodash';2const api_root = '/api/v1';3const public_client_id = 'admin_public';4const public_client_secret = 'czZCaGRSa3F0MzpnWDFmQmF0M2JW';5const default_headers = {6 'Accept': 'application/json',7 'Content-Type': 'application/json',8};9const handleResponse = (response) => {10 if (response.ok) {11 return response.json();12 }13 console.dir(response);14 throw response;15};16const fetchToken = (request, headers = {}) => (17 fetch(api_root + '/oauth/token', {18 method: 'POST',19 headers: _.extend(default_headers, headers),20 body: JSON.stringify(request),21 })22 .then(handleResponse)23);24export const fetchClientToken = (/*success, error*/) => {25 let token_request = {26 client_id: public_client_id,27 client_secret: public_client_secret,28 grant_type: 'client_credentials',29 };30 return fetchToken(token_request)31};32export const fetchUserToken = (credentials/*, success, error*/) => {33 let token_request = _.extend({34 client_id: public_client_id,35 client_secret: public_client_secret,36 grant_type: 'password',37 }, credentials);38 return fetchToken(token_request)39};40export const fetchRefreshUserToken = (access_token, refresh_token/*, success, error*/) => {41 console.log("REFRESH");42 let token_request = _.extend({43 client_id: public_client_id,44 client_secret: public_client_secret,45 grant_type: 'refresh_token',46 refresh_token: refresh_token,47 });48 return fetchToken(token_request, {49 Authorization: `Bearer ${access_token}`,50 })...
token.js
Source:token.js
1import { refreshAccessToken } from '../api';2const TOKEN_REQUEST = 'TOKEN_REQUEST';3const TOKEN_RECEIVED = 'TOKEN_RECEIVED';4const TOKEN_FAILURE = 'TOKEN_FAILURE';5function requestAccessToken() {6 return {7 type: TOKEN_REQUEST,8 };9}10function accessTokenReceived(token) {11 return {12 type: TOKEN_RECEIVED,13 token: token.access,14 };15}16function accessTokenError(error) {17 return {18 type: TOKEN_FAILURE,19 error20 };21}22function refreshAccessAction(refreshToken) {23 return function refreshAccessActionThunk(dispatch) {24 dispatch(requestAccessToken(refreshToken));25 refreshAccessToken(refreshToken)26 .then(({ accessToken }) => {27 dispatch(accessTokenReceived(accessToken));28 })29 .catch(error => {30 dispatch(accessTokenError(error.toString()));31 });32 };33}34export {35 TOKEN_REQUEST,36 TOKEN_RECEIVED,37 TOKEN_FAILURE,38 refreshAccessAction,...
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org', 'API_KEY');3 if (err) return console.error(err);4 console.log('Test status:', data.statusText);5 if (data.statusCode === 200) {6 console.log('Test started at:', data.data.jsonUrl);7 console.log('Test results will be available at:', data.data.userUrl);8 }9});10var wpt = require('webpagetest');11var wpt = new WebPageTest('www.webpagetest.org', 'API_KEY');12 if (err) return console.error(err);13 console.log('Test status:', data.statusText);14 if (data.statusCode === 200) {15 console.log('Test started at:', data.data.jsonUrl);16 console.log('Test results will be available at:', data.data.userUrl);17 }18});19var wpt = require('webpagetest');20var wpt = new WebPageTest('www.webpagetest.org', 'API_KEY');21 if (err) return console.error(err);22 console.log('Test status:', data.statusText);23 if (data.statusCode === 200) {24 console.log('Test started at:', data.data.jsonUrl);25 console.log('Test results will be available at:', data.data.userUrl);26 }27});28var wpt = require('webpagetest');29var wpt = new WebPageTest('www.webpagetest.org', 'API_KEY');30 if (err) return console.error(err);31 console.log('Test status:', data.statusText);32 if (data.statusCode === 200) {33 console.log('Test started at:', data.data.jsonUrl);34 console.log('Test results will be available at:', data.data.userUrl);35 }36});
Using AI Code Generation
1var wptools = require('wptools');2var options = {3};4var page = wptools.page('Barack Obama', options);5page.token_request(function(err, resp) {6 if (err) {7 console.log(err);8 } else {9 console.log(resp);10 }11});12var wptools = require('wptools');13var options = {14};15var page = wptools.page('Barack Obama', options);16page.token_request(function(err, resp) {17 if (err) {18 console.log(err);19 } else {20 console.log(resp);21 }22});23var wptools = require('wptools');24var options = {25};26var page = wptools.page('Barack Obama', options);27page.token_request(function(err, resp) {28 if (err) {29 console.log(err);30 } else {31 console.log(resp);32 }33});34var wptools = require('wptools');35var options = {36};37var page = wptools.page('Barack Obama', options);38page.token_request(function(err, resp) {39 if (err) {40 console.log(err);41 } else {42 console.log(resp);43 }44});45var wptools = require('wptools');46var options = {47};48var page = wptools.page('Barack Obama
Using AI Code Generation
1const wptools = require('wptools');2const fs = require('fs');3wptools.page('Wikipedia:Sandbox').edit('Hello World!', 'edit summary', token, function(resp){4 console.log(resp);5});6wptools.page('Wikipedia:Sandbox/Hello_World').create('Hello World!', 'edit summary', token, function(resp){7 console.log(resp);8});
Using AI Code Generation
1var wptools = require('wptools');2var token = wptools.token_request('enwiki');3console.log(token);4var wptools = require('wptools');5var token = wptools.token_request('enwiki');6console.log(token);7var wptools = require('wptools');8var token = wptools.token_request('enwiki');9console.log(token);10var wptools = require('wptools');11var token = wptools.token_request('enwiki');12console.log(token);13var wptools = require('wptools');14var token = wptools.token_request('enwiki');15console.log(token);16var wptools = require('wptools');17var token = wptools.token_request('enwiki');18console.log(token);19var wptools = require('wptools');20var token = wptools.token_request('enwiki');21console.log(token);22var wptools = require('wptools');23var token = wptools.token_request('enwiki');24console.log(token);
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!