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

@servicenow/ui-effect-graphql

Package Overview
Dependencies
Maintainers
4
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@servicenow/ui-effect-graphql - npm Package Compare versions

Comparing version 17.0.1 to 18.2.5

lib/utils/addDomainContextToGraphQLDocument.js

20

lib/apollo/batchHttpLink.js

@@ -40,3 +40,3 @@ /**

var DEFAULT_GQL_ENDPOINT = '/api/now/graphql';
var DEFAULT_BATCH_INTERVAL_MS = 10;
var DEFAULT_BATCH_INTERVAL_MS = 50;
var root = (0, _utils.getGlobalObject)(); // By default, apollo-link-http doesn't send cookies

@@ -48,5 +48,21 @@

headers: _extends({}, options.headers, {
'X-Transaction-Source': root.transaction_source,
'X-UserToken': root.g_ck
})
}));
})).then(function (response) {
// DEF0106841: The graphql endpoint changed their response status code from 401 to 200
// for when the user is no longer logged in. This breaks components depending on the
// 401 error. This looks for the x-is-logged-in header and throws a pseudo 401 error to
// remain backwards compatible
if (response.headers.get('x-is-logged-in') === 'false') {
var error = new Error();
error.response = _extends({}, response, {
status: 401,
statusText: 'Unauthorized'
});
throw error;
}
return response;
});
};

@@ -53,0 +69,0 @@

24

lib/apollo/sendRequest.js

@@ -35,12 +35,22 @@ /**

function _extends() { _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; }; return _extends.apply(this, arguments); }
function sendRequest() {
var document = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var variables = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var operation = {
var operationName = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
var document = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var variables = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var headers = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
var operation = _extends({
query: document,
variables: variables // operationName: {} //optional
// context: {} //optional
// extensions: {} //optional
variables: variables
}, Object.keys(headers).length && {
context: {
headers: headers
}
}, {
operationName: operationName // extensions: {} //optional
};
});
return new Promise(function (resolve, reject) {

@@ -47,0 +57,0 @@ (0, _apolloLink.makePromise)((0, _apolloLink.execute)(_batchHttpLink["default"], operation)).then(function (results) {

@@ -39,6 +39,4 @@ /**

var _pick = _interopRequireDefault(require("lodash/pick"));
var _uiInternal = require("@servicenow/ui-internal");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
var _marked =

@@ -68,2 +66,4 @@ /*#__PURE__*/

templateVarList,
_options$headerList,
headerList,
_options$startActionT,

@@ -77,6 +77,11 @@ startActionType,

dispatch,
host,
_action$payload,
payload,
variables,
templateVars,
headers,
actionMetaData,
operationName,
domainContext,
updatedQuery,

@@ -108,7 +113,8 @@ document,

coeffects = _args.length > 5 ? _args[5] : undefined;
_options$variableList = options.variableList, variableList = _options$variableList === void 0 ? [] : _options$variableList, _options$templateVarL = options.templateVarList, templateVarList = _options$templateVarL === void 0 ? [] : _options$templateVarL, _options$startActionT = options.startActionType, startActionType = _options$startActionT === void 0 ? GRAPHQL_REQUEST_STARTED : _options$startActionT, _options$successActio = options.successActionType, successActionType = _options$successActio === void 0 ? GRAPHQL_REQUEST_SUCCEEDED : _options$successActio, _options$errorActionT = options.errorActionType, errorActionType = _options$errorActionT === void 0 ? GRAPHQL_REQUEST_FAILED : _options$errorActionT;
action = coeffects.action, dispatch = coeffects.dispatch;
payload = action.payload;
variables = (0, _pick["default"])(payload, variableList);
templateVars = (0, _pick["default"])(payload, templateVarList);
_options$variableList = options.variableList, variableList = _options$variableList === void 0 ? [] : _options$variableList, _options$templateVarL = options.templateVarList, templateVarList = _options$templateVarL === void 0 ? [] : _options$templateVarL, _options$headerList = options.headerList, headerList = _options$headerList === void 0 ? [] : _options$headerList, _options$startActionT = options.startActionType, startActionType = _options$startActionT === void 0 ? GRAPHQL_REQUEST_STARTED : _options$startActionT, _options$successActio = options.successActionType, successActionType = _options$successActio === void 0 ? GRAPHQL_REQUEST_SUCCEEDED : _options$successActio, _options$errorActionT = options.errorActionType, errorActionType = _options$errorActionT === void 0 ? GRAPHQL_REQUEST_FAILED : _options$errorActionT;
action = coeffects.action, dispatch = coeffects.dispatch, host = coeffects.host;
_action$payload = action.payload, payload = _action$payload === void 0 ? {} : _action$payload;
variables = (0, _uiInternal.pick)(payload, variableList);
templateVars = (0, _uiInternal.pick)(payload, templateVarList);
headers = (0, _uiInternal.pick)(payload, headerList);
actionMetaData = _extends({}, action.meta, {

@@ -118,21 +124,20 @@ options: {

variables: variables,
templateVars: templateVars
templateVars: templateVars,
headers: headers
}
});
_context.prev = 11;
_context.prev = 12;
operationName = (0, _utils.getOperationName)(host.tagName);
domainContext = (0, _uiEffectHelpers.resolveDomainContext)(host);
updatedQuery = (0, _utils.replaceQueryTemplateVariables)(query, templateVars);
document = (0, _utils.createGraphQLDocument)(updatedQuery);
_context.next = 16;
return (0, _uiEffectHelpers.exec)(dispatch, startActionType, {}, actionMetaData);
document = (0, _utils.addQueryNameToGraphQLDocument)((0, _utils.addDomainContextToGraphQLDocument)((0, _utils.createGraphQLDocument)(updatedQuery), domainContext), operationName);
if (domainContext) actionMetaData.domainContext = domainContext;
dispatch(startActionType, {}, actionMetaData);
_context.next = 21;
return (0, _apollo.sendRequest)(operationName, document, variables, headers);
case 16:
_context.next = 18;
return (0, _uiEffectHelpers.exec)(_apollo.sendRequest, document, variables);
case 18:
case 21:
result = _context.sent;
_context.next = 21;
return (0, _uiEffectHelpers.exec)(dispatch, successActionType, result, actionMetaData);
dispatch(successActionType, result, actionMetaData);
case 21:
if ((0, _utils.isSubscription)(document)) {

@@ -147,15 +152,11 @@ data = result.data;

case 24:
_context.prev = 24;
_context.t0 = _context["catch"](11);
_context.next = 28;
return (0, _uiEffectHelpers.exec)(dispatch, errorActionType, _context.t0, actionMetaData, true);
case 26:
_context.prev = 26;
_context.t0 = _context["catch"](12);
dispatch(errorActionType, _context.t0, actionMetaData, true); // Standard action dispatched on HTTP errors from the server
case 28:
// Standard action dispatched on HTTP errors from the server
_error$response = _context.t0.response, response = _error$response === void 0 ? {} : _error$response, _result = _context.t0.result;
status = response.status, statusText = response.statusText;
_createHttpErrorActio = (0, _uiEffectHelpers.createHttpErrorAction)(status, statusText, '', _result, actionMetaData), type = _createHttpErrorActio.type, _payload = _createHttpErrorActio.payload, meta = _createHttpErrorActio.meta, httpError = _createHttpErrorActio.error;
_context.next = 33;
return (0, _uiEffectHelpers.exec)(dispatch, type, _payload, meta, httpError);
dispatch(type, _payload, meta, httpError);

@@ -167,3 +168,3 @@ case 33:

}
}, _marked, null, [[11, 24]]);
}, _marked, null, [[12, 26]]);
}

@@ -206,6 +207,7 @@ /**

* @param {Array<String>} options.templateVarList - Template variables to use from action payload
* @param {Object<String>} options.headerList - GraphQL request headers
* @param {String} options.startActionType - Action to be dispatched when the GraphQL request has been issued
* @param {String} options.successActionType - Action to be dispatched when the GraphQL request has successfully completed
* @param {String} options.errorActionType - Action to be dispatched when the GraphQL request has failed
* @param {String} options.subscriptionStartedActionType - Action to be dispatched when the GraphQL subscription has started
* @param {String} options.subscriptionStartedActionType - Action to be dispatched when the GraphQL request has failed
* @param {String} options.subscriptionSuccessActionType - Action to be dispatched when GraphQL subscription succeeds

@@ -212,0 +214,0 @@ * @param {String} options.subscriptionFailedActionType - Action to be dispatched when GraphQL subscription fails

@@ -29,12 +29,4 @@ /**

var _values = _interopRequireDefault(require("lodash/values"));
var _uiInternal = require("@servicenow/ui-internal");
var _map = _interopRequireDefault(require("lodash/map"));
var _get = _interopRequireDefault(require("lodash/get"));
var _filter = _interopRequireDefault(require("lodash/filter"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
/**

@@ -49,13 +41,18 @@ * Gets a list of channel ids and serialized graphql subscriptions from a given subscription query result.

function getChannelsFromSubscriptionQuery(data) {
var items = (0, _values["default"])((0, _get["default"])(data, 'GlideRecord_Subscription'));
var channels = (0, _map["default"])(items, function (item) {
return {
channelId: (0, _get["default"])(item, '_subscription.subscription_channel'),
serializedSubscription: (0, _get["default"])(item, '_subscription.serialized_subscription')
};
});
return (0, _filter["default"])(channels, function (channel) {
return channel.channelId && channel.serializedSubscription;
});
var items = (0, _uiInternal.values)((0, _uiInternal.get)(data, 'GlideRecord_Subscription'));
var channels = [];
var itemsLength = items.length;
for (var i = 0; i < itemsLength; i++) {
var item = items[i];
var channelId = (0, _uiInternal.get)(item, '_subscription.subscription_channel');
var serializedSubscription = (0, _uiInternal.get)(item, '_subscription.serialized_subscription');
if (channelId && serializedSubscription) channels.push({
channelId: channelId,
serializedSubscription: serializedSubscription
});
}
return channels;
}
//# sourceMappingURL=getChannelsFromSubscriptionQuery.js.map

@@ -30,8 +30,4 @@ /**

var _forEach = _interopRequireDefault(require("lodash/forEach"));
var _uiInternal = require("@servicenow/ui-internal");
var _get = _interopRequireDefault(require("lodash/get"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
var ENTER = 'enter';

@@ -135,7 +131,8 @@ var CHANGE = 'change';

channelListener.subscribe(function (message) {
var fields = (0, _get["default"])(message, 'data.data.GlideRecord_Subscription', {});
(0, _forEach["default"])(fields, function (field, fieldName) {
if (fieldName === '__typename') return;
var state = (0, _get["default"])(field, '_subscription.subscription_state');
var fields = (0, _uiInternal.get)(message, 'data.data.GlideRecord_Subscription', {});
for (var key in fields) {
if (key === '__typename') return;
var state = (0, _uiInternal.get)(fields[key], '_subscription.subscription_state');
switch (state) {

@@ -154,3 +151,3 @@ case CHANGE:

}
});
}
});

@@ -157,0 +154,0 @@ } else if (isSubscribed && !shouldSubscribe) {

@@ -33,4 +33,2 @@ /**

var _forEach = _interopRequireDefault(require("lodash/forEach"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

@@ -58,7 +56,9 @@

var channels = (0, _getChannelsFromSubscriptionQuery["default"])(resultData);
(0, _forEach["default"])(channels, function (channel) {
var channelsLength = channels.length;
for (var i = 0; i < channelsLength; i++) {
(0, _handleAMBSubscription["default"])(_extends({
shouldSubscribe: shouldSubscribe,
subscriptionId: subscriptionId
}, channel, {
}, channels[i], {
ambClient: ambClient,

@@ -70,4 +70,4 @@ ambChannelRegistry: ambChannelRegistry,

}));
});
}
}
//# sourceMappingURL=handleGraphQLSubscription.js.map

@@ -27,2 +27,14 @@ /**

});
Object.defineProperty(exports, "addDomainContextToGraphQLDocument", {
enumerable: true,
get: function get() {
return _addDomainContextToGraphQLDocument["default"];
}
});
Object.defineProperty(exports, "addQueryNameToGraphQLDocument", {
enumerable: true,
get: function get() {
return _addQueryNameToGraphQLDocument["default"];
}
});
Object.defineProperty(exports, "getGlobalObject", {

@@ -52,3 +64,13 @@ enumerable: true,

});
Object.defineProperty(exports, "getOperationName", {
enumerable: true,
get: function get() {
return _getOperationName["default"];
}
});
var _addDomainContextToGraphQLDocument = _interopRequireDefault(require("./addDomainContextToGraphQLDocument"));
var _addQueryNameToGraphQLDocument = _interopRequireDefault(require("./addQueryNameToGraphQLDocument"));
var _getGlobalObject = _interopRequireDefault(require("./getGlobalObject"));

@@ -62,3 +84,5 @@

var _getOperationName = _interopRequireDefault(require("./getOperationName"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
//# sourceMappingURL=index.js.map

@@ -29,11 +29,9 @@ /**

var _get = _interopRequireDefault(require("lodash/get"));
var _uiInternal = require("@servicenow/ui-internal");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function isSubscription() {
var document = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var operation = (0, _get["default"])(document, 'definitions[0].operation');
var operation = (0, _uiInternal.get)(document, 'definitions[0].operation');
return operation && operation === 'subscription';
}
//# sourceMappingURL=isSubscription.js.map

@@ -31,10 +31,4 @@ /**

var _forEach = _interopRequireDefault(require("lodash/forEach"));
var _uiInternal = require("@servicenow/ui-internal");
var _has = _interopRequireDefault(require("lodash/has"));
var _includes = _interopRequireDefault(require("lodash/includes"));
var _memoize = _interopRequireDefault(require("lodash/memoize"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

@@ -65,5 +59,7 @@

function assertValidTemplateVars(queryStr, templateParts, templateVars) {
(0, _forEach["default"])(templateParts, function (part) {
if (!(0, _has["default"])(templateVars, part)) throw new TemplateVarsMissingException(queryStr, templateParts);
});
var templatePartsLength = templateParts.length;
for (var i = 0; i < templatePartsLength; i++) {
if (!templateVars[templateParts[i]]) throw new TemplateVarsMissingException(queryStr, templateParts);
}
}

@@ -82,11 +78,14 @@ /**

var tokens = parts.filter(function (part) {
return (0, _includes["default"])(mustacheTokens, part[0]);
}).map(function (part) {
return part[1];
});
var tokens = [];
var partsLength = parts.length;
for (var i = 0; i < partsLength; i++) {
var part = parts[i];
if (mustacheTokens.indexOf(part[0]) !== -1) tokens.push(part[1]);
}
return tokens;
}
var memGetTokens = (0, _memoize["default"])(getTokens);
var memGetTokens = (0, _uiInternal.memoize)(getTokens);

@@ -93,0 +92,0 @@ function replaceQueryTemplateVariables() {

{
"name": "@servicenow/ui-effect-graphql",
"version": "17.0.1",
"version": "18.2.5",
"description": "Now Experience UI Framework Effect - GraphQL",
"main": "lib/index.js",
"module": "module/index.js",
"typings": "typings",

@@ -11,7 +12,9 @@ "author": "",

"lib",
"module",
"typings"
],
"dependencies": {
"@servicenow/ui-effect-helpers": "17.0.1",
"amb-client-js": "17.0.1",
"@servicenow/ui-effect-helpers": "18.2.5",
"@servicenow/ui-internal": "18.2.5",
"amb-client-js": "18.0.0",
"apollo-link": "1.2.3",

@@ -25,15 +28,22 @@ "apollo-link-batch-http": "1.2.3",

},
"devDependencies": {
"lodash": "4.17.4"
},
"scripts": {
"test": "BABEL_ENV=test ../../../node_modules/.bin/jest --config=../../../jest.config.js",
"test:coverage": "BABEL_ENV=test ../../../node_modules/.bin/jest --config=../../../jest.config.js --coverage",
"lint": "../../../node_modules/.bin/eslint --config ../../../.eslintrc.js src",
"document": "../../../node_modules/.bin/jsdoc2md --partial ../../../docs/header.hbs --files src/{,**/}*.js > api.md",
"test": "npm run test:unit -- --saucelabs",
"test:coverage": "npm run test:unit -- --coverage",
"test:unit": "../../../node_modules/.bin/karma start ../../../karma.conf.js",
"prettier-eslint": "../../../node_modules/.bin/prettier-eslint --list-different --eslint-config-path=../../../.eslintrc.js 'src/**/*.js'",
"eslint": "../../../node_modules/.bin/eslint --config ../../../.eslintrc.js src",
"document": "../../../node_modules/.bin/jsdoc2md --partial ../../../docs/header.hbs --files 'src/{,**/}*.js' > api.md",
"build": "npm run build:prod",
"build:prod": "BABEL_ENV=production ../../../node_modules/.bin/babel src --out-dir lib --source-maps --root-mode upward --ignore 'src/**/__tests__/**'",
"build:dev": "BABEL_ENV=development ../../../node_modules/.bin/babel src --out-dir lib --root-mode upward --source-maps --ignore 'src/**/__tests__/**'",
"build:watch": "BABEL_ENV=development ../../../node_modules/.bin/babel src --out-dir lib --watch --root-mode upward --source-maps --ignore 'src/**/__tests__/**' --verbose",
"verify": "npm run lint && npm run test",
"prepublishOnly": "npm run verify"
"build:prod": "BABEL_ENV=production npm run build:lib && BABEL_ENV=production npm run build:module",
"build:dev": "BABEL_ENV=development npm run build:lib -- --verbose && BABEL_ENV=development npm run build:module -- --verbose",
"build:watch": "BABEL_ENV=development npm run build:js -- --verbose --watch & BABEL_ENV=development npm run build:module -- --verbose --watch",
"build:lib": "npm run build:js -- --out-dir lib",
"build:module": "BABEL_MODULE=true npm run build:js -- --out-dir module",
"build:js": "../../../node_modules/.bin/babel src --root-mode upward --source-maps --ignore 'src/**/__tests__/**'",
"verify": "npm run lint && npm run test && npm run document"
},
"gitHead": "fd38979069b402a47eb2a41093ffd69e55a2cc07"
"gitHead": "02dbca17b53121fbaed6b2c31c4cafefd757c4cd"
}
# @servicenow/ui-effect-graphql
Effect to handle GraphQL requests and responses.
Visit https://developer.servicenow.com/now-experience-ui-framework/support for more information.
Effect to handle GraphQL requests and responses.

@@ -1,2 +0,2 @@

// @servicenow/ui-effect-amb type definitions
// @servicenow/ui-effect-graphql type definitions
// TypeScript Version: 3.7

@@ -13,2 +13,3 @@

* @param options.templateVarList - Template variables to use from action payload
* @param options.headerList - GraphQL request headers
* @param options.startActionType - Action to be dispatched when the GraphQL request has been issued

@@ -26,3 +27,3 @@ * @param options.successActionType - Action to be dispatched when the GraphQL request has successfully completed

*/
export function createGraphQLEffect(query: string, options?: GraphQLEffectOptions): Object;
export function createGraphQLEffect(query: string, options?: GraphQLEffectOptions): object;

@@ -36,2 +37,5 @@ interface GraphQLEffectOptions {

/** GraphQL request headers */
headerList?: object;
/** Action to be dispatched when the GraphQL request has been issued */

@@ -38,0 +42,0 @@ startActionType?: string;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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