Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gooddata

Package Overview
Dependencies
Maintainers
10
Versions
200
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gooddata - npm Package Compare versions

Comparing version 6.0.0-alpha1 to 6.0.0-alpha2

19

index.d.ts

@@ -124,2 +124,12 @@ // Copyright (C) 2007-2017, GoodData(R) Corporation. All rights reserved.

setCustomDomain(d: string): void;
getCustomDomain(): string;
setJsPackage(name: string, version: string): void;
getJsPackage(): { name: string, version: string };
setRequestHeader(key: string, value: string): void;
getRequestHeader(key: string): string;
}

@@ -382,5 +392,10 @@

export interface IXhrMockInBeforeSend {
setRequestHeader(key: string, value: string): void;
}
export interface IXhrSettings {
method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'HEAD';
data?: any;
beforeSend?(xhr: IXhrMockInBeforeSend, url: string): void;
}

@@ -393,5 +408,6 @@

ajax<T>(uri: string, settings?: IXhrSettings): Promise<T>;
ajaxSetup(settings: IXhrSettings): void;
}
export interface ISdk {
export interface ISdk { // TODO extends Clonable?
xhr: IXhr;

@@ -404,2 +420,3 @@ project: IProject;

user: IUser;
clone(): ISdk;
utils: IUtils;

@@ -406,0 +423,0 @@ }

@@ -6,4 +6,12 @@ 'use strict';

});
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; // Copyright (C) 2007-2014, GoodData(R) Corporation. All rights reserved.
exports.sanitizeDomain = sanitizeDomain;
exports.sanitizeConfig = sanitizeConfig;
exports.createModule = createModule;
// Copyright (C) 2007-2014, GoodData(R) Corporation. All rights reserved.
var _lodash = require('lodash');
/**

@@ -23,4 +31,43 @@ * Config module holds SDK configuration variables

function createModule() {
var domain = void 0;
function sanitizeDomain(domain) {
if (domain === null) {
return undefined;
}
var sanitizedDomain = domain || '';
var link = sanitizedDomain.match(URL_REGEXP);
if (!link) {
throw new Error(domain + ' is not a valid url');
}
// ensure https:// prefix and strip possible trailing /
return 'https://' + link[0].replace(/^https?:\/\/|\/$/g, '');
}
/**
* Returns sanitized config
*
* @method sanitizeConfig
* @return {object|undefiend} config with sanitized domain
*/
function sanitizeConfig(config) {
var sanitized = _extends({}, config);
if (config.domain) {
sanitized.domain = sanitizeDomain(config.domain);
}
return sanitized;
}
/**
* Config factory
*
* @param {object|null} configStorage config object
* @method createModule
* @return SDK config module
*/
function createModule(configStorage) {
if (arguments.length !== 1) {
throw new Error('Config module has to be called with exactly one argument.');
}
/**

@@ -32,31 +79,60 @@ * Sets custom domain. Parameter is url which has always to be https://

* https://github.com/jarib/google-closure-library/blob/master/closure/goog/string/linkify.js
* @param {String|null} d valid domain starting with https:// or null for removing
* @param {String|null} domain valid domain starting with https:// or null for removing
* @method setCustomDomain
*/
function setCustomDomain(d) {
var sanitizedDomain = d || '';
var link = sanitizedDomain.match(URL_REGEXP);
function setCustomDomain(domain) {
configStorage.domain = sanitizeDomain(domain); // eslint-disable-line no-param-reassign
}
if (d === null) {
domain = undefined;
return;
}
/**
* Returns current domain
*
* @method getCustomDomain
*/
function getCustomDomain() {
return configStorage.domain;
}
if (!link) {
throw new Error(d + ' is not a valid url');
/**
* Sets JS package and version info
*
* @method setJsPackage
* @param {String} name package name
* @param {String} version package version (semver)
* @private
*/
function setJsPackage(name, version) {
if (!configStorage.originPackage) {
// only set the first (topmost) package
configStorage.originPackage = { name: name, version: version }; // eslint-disable-line no-param-reassign
}
}
// ensure https:// prefix
// and strip possible trailing /
domain = 'https://' + link[0].replace(/^https:\/\//, '').replace(/\/$/, '');
/**
* Returns JS package and version info
*
* @method getJsPackage
* @return {object} with 'name' and 'version' properties
* @private
*/
function getJsPackage() {
return configStorage.originPackage;
}
function getDomain() {
return domain;
function setRequestHeader(key, value) {
(0, _lodash.set)(configStorage, ['xhrSettings', 'headers', key], value);
}
function getRequestHeader(key) {
return (0, _lodash.get)(configStorage, ['xhrSettings', 'headers', key]);
}
return {
setCustomDomain: setCustomDomain,
getDomain: getDomain
getCustomDomain: getCustomDomain,
setJsPackage: setJsPackage,
getJsPackage: getJsPackage,
setRequestHeader: setRequestHeader,
getRequestHeader: getRequestHeader
};
}

78

lib/gooddata.js

@@ -6,4 +6,10 @@ 'use strict';

});
exports.factory = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); // Copyright (C) 2007-2014, GoodData(R) Corporation. All rights reserved.
exports.factory = factory;
var _lodash = require('lodash');
var _xhr = require('./xhr');

@@ -29,2 +35,4 @@

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**

@@ -47,36 +55,50 @@ * # JS SDK

*/
var SDK = function () {
function SDK() {
var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
// Copyright (C) 2007-2014, GoodData(R) Corporation. All rights reserved.
function factory() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
_classCallCheck(this, SDK);
var config = (0, _config.createModule)();
if (options.domain) {
config.setCustomDomain(options.domain);
this.configStorage = (0, _config.sanitizeConfig)(config); // must be plain object, SDK modules MUST use this storage
this.config = (0, _config.createModule)(this.configStorage);
this.xhr = (0, _xhr.createModule)(this.configStorage);
this.user = (0, _user.createModule)(this.xhr);
this.md = (0, _metadata.createModule)(this.xhr);
this.execution = (0, _execution.createModule)(this.xhr, this.md);
this.project = (0, _project.createModule)(this.xhr);
this.catalogue = (0, _catalogue.createModule)(this.xhr, this.execution);
this.admin = (0, _admin.createModule)(this.xhr);
this.utils = {
loadAttributesMap: (0, _attributesMapLoader.createModule)(this.md),
getAttributesDisplayForms: _visualizationObjectHelper.getAttributesDisplayForms
};
}
var xhr = (0, _xhr.createModule)(config);
var md = (0, _metadata.createModule)(xhr);
var execution = (0, _execution.createModule)(xhr, md);
return {
config: config,
xhr: xhr,
user: (0, _user.createModule)(xhr),
md: md,
execution: execution,
project: (0, _project.createModule)(xhr),
catalogue: (0, _catalogue.createModule)(xhr, execution),
admin: (0, _admin.createModule)(xhr),
utils: {
loadAttributesMap: (0, _attributesMapLoader.createModule)(md),
getAttributesDisplayForms: _visualizationObjectHelper.getAttributesDisplayForms
_createClass(SDK, [{
key: 'clone',
value: function clone() {
return new SDK((0, _lodash.cloneDeep)(this.configStorage));
}
};
}
}]);
var defaultInstance = void 0; // eslint-disable-line import/no-mutable-exports
if (!defaultInstance) {
defaultInstance = factory();
return SDK;
}();
/**
* # Factory for creating SDK instances
*
* @param {object|null} config object to be passed to SDK constructor
* @method setCustomDomain
*/
function factory() {
var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
return new SDK(config);
}
exports.factory = factory;
var defaultInstance = factory();
exports.default = defaultInstance;

@@ -6,3 +6,3 @@ 'use strict';

});
exports.handlePolling = exports.getIn = undefined;
exports.handlePolling = exports.getIn = exports.thisPackage = undefined;

@@ -17,2 +17,4 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; // Copyright (C) 2007-2017, GoodData(R) Corporation. All rights reserved.

var _package = require('../package.json');
/**

@@ -27,2 +29,8 @@ * Utility methods. Mostly private

/**
* Gooddata-js package signature
* @private
*/
var thisPackage = exports.thisPackage = { name: _package.name, version: _package.version };
/**
* Create getter function for accessing nested objects

@@ -29,0 +37,0 @@ *

@@ -6,3 +6,7 @@ 'use strict';

});
exports.parseJSON = undefined;
exports.originPackageHeaders = exports.parseJSON = undefined;
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; // Copyright (C) 2007-2013, GoodData(R) Corporation. All rights reserved.
exports.handlePolling = handlePolling;

@@ -13,2 +17,4 @@ exports.createModule = createModule;

var _util = require('./util');
var _fetch = require('./utils/fetch');

@@ -32,7 +38,6 @@

// Copyright (C) 2007-2013, GoodData(R) Corporation. All rights reserved.
var DEFAULT_POLL_DELAY = 1000;
function simulateBeforeSend(settings, url) {
var xhr = {
var xhrMockInBeforeSend = {
setRequestHeader: function setRequestHeader(key, value) {

@@ -44,3 +49,3 @@ (0, _lodash.set)(settings, ['headers', key], value);

if ((0, _lodash.isFunction)(settings.beforeSend)) {
settings.beforeSend(xhr, url);
settings.beforeSend(xhrMockInBeforeSend, url);
}

@@ -104,13 +109,23 @@ }

function createModule(config) {
var commonXhrSettings = {};
var tokenRequest = void 0;
var originPackageHeaders = exports.originPackageHeaders = function originPackageHeaders(_ref) {
var name = _ref.name,
version = _ref.version;
return {
'X-GDC-JS-PKG': name,
'X-GDC-JS-PKG-VERSION': version
};
};
function createSettings(customSettings) {
function createModule(configStorage) {
var tokenRequest = void 0; // TODO make app-wide persitent (ie. extract outside of the SDK)
(0, _lodash.defaults)(configStorage, { xhrSettings: {} });
function createRequestSettings(customSettings) {
var settings = (0, _lodash.merge)({
headers: {
headers: _extends({
Accept: 'application/json; charset=utf-8',
'Content-Type': 'application/json'
}
}, commonXhrSettings, customSettings);
}, originPackageHeaders(configStorage.originPackage || _util.thisPackage))
}, configStorage.xhrSettings, customSettings);

@@ -130,2 +145,3 @@ settings.pollDelay = settings.pollDelay !== undefined ? settings.pollDelay : DEFAULT_POLL_DELAY;

}
/**

@@ -139,3 +155,3 @@ * Back compatible method for setting common XHR settings

function ajaxSetup(settings) {
commonXhrSettings = Object.assign({}, commonXhrSettings, settings);
Object.assign(configStorage.xhrSettings, settings);
}

@@ -163,3 +179,3 @@

// If token request exist, just listen for it's end.
var _enrichSettingWithCus = enrichSettingWithCustomDomain('/gdc/account/token', createSettings({}), config.getDomain()),
var _enrichSettingWithCus = enrichSettingWithCustomDomain('/gdc/account/token', createRequestSettings({}), configStorage.domain),
url = _enrichSettingWithCus.url,

@@ -190,11 +206,12 @@ settings = _enrichSettingWithCus.settings;

function ajax(originalUrl) {
var tempSettings = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var customSettings = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var firstSettings = createSettings(tempSettings);
// TODO refactor to: getRequestParams(originalUrl, customSettings);
var firstSettings = createRequestSettings(customSettings);
var _enrichSettingWithCus2 = enrichSettingWithCustomDomain(originalUrl, firstSettings, config.getDomain()),
var _enrichSettingWithCus2 = enrichSettingWithCustomDomain(originalUrl, firstSettings, configStorage.domain),
url = _enrichSettingWithCus2.url,
settings = _enrichSettingWithCus2.settings;
simulateBeforeSend(settings, url);
simulateBeforeSend(settings, url); // mutates `settings` param

@@ -201,0 +218,0 @@ if (tokenRequest) {

{
"name": "gooddata",
"version": "6.0.0-alpha1",
"version": "6.0.0-alpha2",
"author": "GoodData",

@@ -5,0 +5,0 @@ "description": "GoodData JavaScript SDK",

// Copyright (C) 2007-2014, GoodData(R) Corporation. All rights reserved.
import { set as _set, get as _get } from 'lodash';
/**

@@ -16,4 +18,44 @@ * Config module holds SDK configuration variables

export function createModule() {
let domain;
export function sanitizeDomain(domain) {
if (domain === null) {
return undefined;
}
const sanitizedDomain = domain || '';
const link = sanitizedDomain.match(URL_REGEXP);
if (!link) {
throw new Error(`${domain} is not a valid url`);
}
// ensure https:// prefix and strip possible trailing /
return `https://${link[0].replace(/^https?:\/\/|\/$/g, '')}`;
}
/**
* Returns sanitized config
*
* @method sanitizeConfig
* @return {object|undefiend} config with sanitized domain
*/
export function sanitizeConfig(config) {
const sanitized = { ...config };
if (config.domain) {
sanitized.domain = sanitizeDomain(config.domain);
}
return sanitized;
}
/**
* Config factory
*
* @param {object|null} configStorage config object
* @method createModule
* @return SDK config module
*/
export function createModule(configStorage) {
if (arguments.length !== 1) {
throw new Error('Config module has to be called with exactly one argument.');
}
/**

@@ -25,33 +67,59 @@ * Sets custom domain. Parameter is url which has always to be https://

* https://github.com/jarib/google-closure-library/blob/master/closure/goog/string/linkify.js
* @param {String|null} d valid domain starting with https:// or null for removing
* @param {String|null} domain valid domain starting with https:// or null for removing
* @method setCustomDomain
*/
function setCustomDomain(d) {
const sanitizedDomain = d || '';
const link = sanitizedDomain.match(URL_REGEXP);
function setCustomDomain(domain) {
configStorage.domain = sanitizeDomain(domain); // eslint-disable-line no-param-reassign
}
if (d === null) {
domain = undefined;
return;
}
/**
* Returns current domain
*
* @method getCustomDomain
*/
function getCustomDomain() {
return configStorage.domain;
}
if (!link) {
throw new Error(`${d} is not a valid url`);
/**
* Sets JS package and version info
*
* @method setJsPackage
* @param {String} name package name
* @param {String} version package version (semver)
* @private
*/
function setJsPackage(name, version) {
if (!configStorage.originPackage) { // only set the first (topmost) package
configStorage.originPackage = { name, version }; // eslint-disable-line no-param-reassign
}
}
// ensure https:// prefix
// and strip possible trailing /
domain = `https://${link[0]
.replace(/^https:\/\//, '')
.replace(/\/$/, '')}`;
/**
* Returns JS package and version info
*
* @method getJsPackage
* @return {object} with 'name' and 'version' properties
* @private
*/
function getJsPackage() {
return configStorage.originPackage;
}
function getDomain() {
return domain;
function setRequestHeader(key, value) {
_set(configStorage, ['xhrSettings', 'headers', key], value);
}
function getRequestHeader(key) {
return _get(configStorage, ['xhrSettings', 'headers', key]);
}
return {
setCustomDomain,
getDomain
getCustomDomain,
setJsPackage,
getJsPackage,
setRequestHeader,
getRequestHeader
};
}
// Copyright (C) 2007-2014, GoodData(R) Corporation. All rights reserved.
import { cloneDeep } from 'lodash';
import { createModule as xhrFactory } from './xhr';

@@ -7,3 +8,3 @@ import { createModule as userFactory } from './user';

import { createModule as projectFactory } from './project';
import { createModule as configFactory } from './config';
import { createModule as configFactory, sanitizeConfig } from './config';
import { createModule as catalogueFactory } from './catalogue';

@@ -14,2 +15,3 @@ import { createModule as adminFactory } from './admin';

import { getAttributesDisplayForms } from './utils/visualizationObjectHelper';
/**

@@ -32,36 +34,37 @@ * # JS SDK

*/
class SDK {
constructor(config = {}) {
this.configStorage = sanitizeConfig(config); // must be plain object, SDK modules MUST use this storage
function factory(options = {}) {
const config = configFactory();
if (options.domain) {
config.setCustomDomain(options.domain);
this.config = configFactory(this.configStorage);
this.xhr = xhrFactory(this.configStorage);
this.user = userFactory(this.xhr);
this.md = metadataFactory(this.xhr);
this.execution = executionFactory(this.xhr, this.md);
this.project = projectFactory(this.xhr);
this.catalogue = catalogueFactory(this.xhr, this.execution);
this.admin = adminFactory(this.xhr);
this.utils = {
loadAttributesMap: loadAttributesMapFactory(this.md),
getAttributesDisplayForms
};
}
const xhr = xhrFactory(config);
const md = metadataFactory(xhr);
const execution = executionFactory(xhr, md);
return {
config,
xhr,
user: userFactory(xhr),
md,
execution,
project: projectFactory(xhr),
catalogue: catalogueFactory(xhr, execution),
admin: adminFactory(xhr),
utils: {
loadAttributesMap: loadAttributesMapFactory(md),
getAttributesDisplayForms
}
};
clone() {
return new SDK(cloneDeep(this.configStorage));
}
}
let defaultInstance; // eslint-disable-line import/no-mutable-exports
if (!defaultInstance) {
defaultInstance = factory();
/**
* # Factory for creating SDK instances
*
* @param {object|null} config object to be passed to SDK constructor
* @method setCustomDomain
*/
export function factory(config = {}) {
return new SDK(config);
}
export {
factory
};
const defaultInstance = factory();
export default defaultInstance;

@@ -5,2 +5,3 @@ // Copyright (C) 2007-2017, GoodData(R) Corporation. All rights reserved.

import { delay } from './utils/promise';
import { name as pkgName, version as pkgVersion } from '../package.json';

@@ -16,2 +17,8 @@ /**

/**
* Gooddata-js package signature
* @private
*/
export const thisPackage = { name: pkgName, version: pkgVersion };
/**
* Create getter function for accessing nested objects

@@ -18,0 +25,0 @@ *

@@ -6,3 +6,4 @@ // Copyright (C) 2007-2013, GoodData(R) Corporation. All rights reserved.

has,
set,
set as _set,
defaults,
merge,

@@ -12,2 +13,3 @@ result

import { thisPackage } from './util';
import fetch from './utils/fetch';

@@ -30,5 +32,5 @@

function simulateBeforeSend(settings, url) {
const xhr = {
const xhrMockInBeforeSend = {
setRequestHeader(key, value) {
set(settings, ['headers', key], value);
_set(settings, ['headers', key], value);
}

@@ -38,3 +40,3 @@ };

if (isFunction(settings.beforeSend)) {
settings.beforeSend(xhr, url);
settings.beforeSend(xhrMockInBeforeSend, url);
}

@@ -96,7 +98,13 @@ }

export function createModule(config) {
let commonXhrSettings = {};
let tokenRequest;
export const originPackageHeaders = ({ name, version }) => ({
'X-GDC-JS-PKG': name,
'X-GDC-JS-PKG-VERSION': version
});
function createSettings(customSettings) {
export function createModule(configStorage) {
let tokenRequest; // TODO make app-wide persitent (ie. extract outside of the SDK)
defaults(configStorage, { xhrSettings: {} });
function createRequestSettings(customSettings) {
const settings = merge(

@@ -106,6 +114,7 @@ {

Accept: 'application/json; charset=utf-8',
'Content-Type': 'application/json'
'Content-Type': 'application/json',
...originPackageHeaders(configStorage.originPackage || thisPackage)
}
},
commonXhrSettings,
configStorage.xhrSettings,
customSettings

@@ -127,2 +136,3 @@ );

}
/**

@@ -136,3 +146,3 @@ * Back compatible method for setting common XHR settings

function ajaxSetup(settings) {
commonXhrSettings = Object.assign({}, commonXhrSettings, settings);
Object.assign(configStorage.xhrSettings, settings);
}

@@ -160,3 +170,3 @@

// If token request exist, just listen for it's end.
const { url, settings } = enrichSettingWithCustomDomain('/gdc/account/token', createSettings({}), config.getDomain());
const { url, settings } = enrichSettingWithCustomDomain('/gdc/account/token', createRequestSettings({}), configStorage.domain);

@@ -184,7 +194,8 @@ tokenRequest = fetch(url, settings).then((response) => {

function ajax(originalUrl, tempSettings = {}) {
const firstSettings = createSettings(tempSettings);
const { url, settings } = enrichSettingWithCustomDomain(originalUrl, firstSettings, config.getDomain());
function ajax(originalUrl, customSettings = {}) {
// TODO refactor to: getRequestParams(originalUrl, customSettings);
const firstSettings = createRequestSettings(customSettings);
const { url, settings } = enrichSettingWithCustomDomain(originalUrl, firstSettings, configStorage.domain);
simulateBeforeSend(settings, url);
simulateBeforeSend(settings, url); // mutates `settings` param

@@ -191,0 +202,0 @@ if (tokenRequest) {

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc