UNPKG

braintree-web

Version:

A suite of tools for integrating Braintree in the browser

64 lines (47 loc) 1.45 kB
"use strict"; var features = { tokenize_credit_cards: "payment_methods/credit_cards", // eslint-disable-line camelcase configuration: "configuration", }; var disallowedInputPaths = ["creditCard.options.unionPayEnrollment"]; function GraphQL(config) { this._config = config.graphQL; } GraphQL.prototype.getGraphQLEndpoint = function () { return this._config.url; }; GraphQL.prototype.isGraphQLRequest = function (url, body) { var featureEnabled; var path = this.getClientApiPath(url); if (!this._isGraphQLEnabled() || !path) { return false; } featureEnabled = this._config.features.some(function (feature) { return features[feature] === path; }); if (containsDisallowedlistedKeys(body)) { return false; } return featureEnabled; }; GraphQL.prototype.getClientApiPath = function (url) { var path; var clientApiPrefix = "/client_api/v1/"; var pathParts = url.split(clientApiPrefix); if (pathParts.length > 1) { path = pathParts[1].split("?")[0]; } return path; }; GraphQL.prototype._isGraphQLEnabled = function () { return Boolean(this._config); }; function containsDisallowedlistedKeys(body) { return disallowedInputPaths.some(function (keys) { var value = keys.split(".").reduce(function (accumulator, key) { return accumulator && accumulator[key]; }, body); return value !== undefined; // eslint-disable-line no-undefined }); } module.exports = GraphQL;