Skip to content

Commit

Permalink
Bump dependencies 0922 (#95)
Browse files Browse the repository at this point in the history
* remove /spa /graphiql default production urls from redirect uri

* - add support for keycloak 19 post logout redirect uri
- extend default token lifespan to 30 mins

* add .env.example

* re-add missing MIGRATION env variables

* fix: use correct redirect uri for graphiql post logout

* add missing MIGRATION env variables to .env.example

* bump dependencies to latest

* chore: graphql always exposes extensions object (empty when no extensions)

* fix: pass missing url parameter

* feat: retry keycloak connection in migration

* fix: retry keycloak connection for master token
  • Loading branch information
coeit authored Sep 9, 2022
1 parent 0ffbbfa commit 8e08d1a
Show file tree
Hide file tree
Showing 8 changed files with 7,954 additions and 10,628 deletions.
18,400 changes: 7,846 additions & 10,554 deletions package-lock.json

Large diffs are not rendered by default.

86 changes: 43 additions & 43 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,58 +12,58 @@
"license": "ISC",
"dependencies": {
"acl": "^0.4.11",
"adm-zip": "^0.4.14",
"ajv": "^6.12.2",
"adm-zip": "^0.5.9",
"ajv": "^8.11.0",
"awaitify-stream": "^1.0.2",
"aws-sdk": "^2.874.0",
"aws-sdk": "^2.1206.0",
"bcrypt": "^5.0.1",
"bcryptjs": "^2.4.3",
"cassandra-driver": "^4.5.2",
"chai": "^4.2.0",
"cassandra-driver": "^4.6.4",
"chai": "^4.3.6",
"chai-as-promised": "^7.1.1",
"cors": "^2.8.5",
"csv-parse": "^4.9.1",
"dataloader": "^2.0.0",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"express-fileupload": "^1.1.6",
"express-graphql": "^0.9.0",
"express-jwt": "^5.3.3",
"faker": "^4.1.0",
"graphql": "^14.6.0",
"graphql-iso-date": "^3.6.1",
"graphql-type-json": "^0.3.2",
"jsonpath-plus": "^4.0.0",
"csv-parse": "^5.3.0",
"dataloader": "^2.1.0",
"dotenv": "^16.0.2",
"express": "^4.18.1",
"express-fileupload": "^1.4.0",
"express-graphql": "^0.12.0",
"express-jwt": "^7.7.5",
"faker": "^6.6.6",
"graphql": "^15.8.0",
"graphql-scalars": "^1.18.0",
"@graphql-tools/merge": "^8.3.4",
"@graphql-tools/load-files": "^6.6.1",
"jsonpath-plus": "^7.1.0",
"jsonwebtoken": "^8.5.1",
"linked-list": "^2.1.0",
"lodash": "^4.17.15",
"mariadb": "^2.4.2",
"mathjs": "^7.0.0",
"merge-graphql-schemas": "^1.7.8",
"moment": "^2.25.3",
"mongodb": "^3.6.3",
"mysql2": "^2.1.0",
"neo4j-driver": "^4.2.3",
"node-jq": "^1.11.1",
"nodemailer": "^6.4.6",
"linked-list": "^3.0.2",
"lodash": "^4.17.21",
"mariadb": "^3.0.1",
"mathjs": "^11.1.0",
"moment": "^2.29.4",
"mongodb": "^4.9.0",
"mysql2": "^2.3.3",
"neo4j-driver": "^4.4.7",
"node-jq": "^2.3.3",
"nodemailer": "^6.7.8",
"nodemailer-smtp-transport": "^2.7.4",
"pg": "^8.2.1",
"pg-hstore": "^2.3.3",
"presto-client": "^0.10.0",
"rewire": "^5.0.0",
"sequelize": "^5.21.10",
"sequelize-cli": "^5.5.1",
"sqlite3": "^5.0.2",
"supertest": "^4.0.2",
"pg": "^8.8.0",
"pg-hstore": "^2.3.4",
"presto-client": "^0.12.2",
"rewire": "^6.0.0",
"sequelize": "^6.21.4",
"sequelize-cli": "^6.4.1",
"sqlite3": "^5.0.11",
"supertest": "^6.2.4",
"sync-request": "^6.1.0",
"uuidv4": "^6.0.8",
"wait-on": "^6.0.0",
"xlsx": "^0.16.1"
"uuidv4": "^6.2.13",
"wait-on": "^6.0.1",
"xlsx": "^0.18.5"
},
"devDependencies": {
"axios": "^0.19.2",
"form-data": "^3.0.0",
"mocha": "^7.1.2",
"nodemon": "^2.0.12"
"axios": "^0.27.2",
"form-data": "^4.0.0",
"mocha": "^10.0.0",
"nodemon": "^2.0.19"
}
}
2 changes: 1 addition & 1 deletion server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var express = require("express");
var path = require("path");
var graphqlHTTP = require("express-graphql");
var { graphqlHTTP } = require("express-graphql");
const bodyParser = require("body-parser");
const globals = require("./config/globals");
const execute = require("./utils/custom-graphql-execute");
Expand Down
4 changes: 2 additions & 2 deletions utils/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ module.exports.handleErrorsInGraphQlResponse = function (
* @return {object} the extensions object.
*/
module.exports.formatGraphQLErrorExtensions = function (error) {
if (helper.isNotUndefinedAndNotNull(error.extensions)) {
if (helper.isNotUndefinedAndNotNull(error.extensions) && Object.keys(error.extensions).length > 0) {
return error.extensions;
} else if (error.message === "validation failed") {
return {
Expand Down Expand Up @@ -183,7 +183,7 @@ module.exports.handleCaughtErrorAndBenignErrors = function (
if (!module.exports.isRemoteGraphQlError(error)) {
// Non remote error:
// Was it a time out of the connection?
module.exports.ifTimeOutErrorAdjustMessage(error);
module.exports.ifTimeOutErrorAdjustMessage(error, url);
throw error;
} else {
// STATUS CODE is NOT 200,
Expand Down
2 changes: 1 addition & 1 deletion utils/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const {
GraphQLDateTime,
GraphQLDate,
GraphQLTime,
} = require("graphql-iso-date");
} = require("graphql-scalars");
var { graphql } = require("graphql");
const searchArg = require("./search-argument");
const { Sequelize } = require("sequelize");
Expand Down
12 changes: 7 additions & 5 deletions utils/merge-schemas.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

var { fileLoader, mergeTypes } = require('merge-graphql-schemas');

const {mergeTypeDefs} = require('@graphql-tools/merge');
const {loadFilesSync} = require('@graphql-tools/load-files')
const { print } = require('graphql')

/**
* @function - Merge graphql schemas stored in a same directory
Expand All @@ -9,7 +10,8 @@ var { fileLoader, mergeTypes } = require('merge-graphql-schemas');
* @return {string} Merged graphql schema.
*/
module.exports = function( schemas_folder ) {
const typesArray = fileLoader( schemas_folder);
let merged = mergeTypes(typesArray);
return merged;
const typesArray = loadFilesSync( schemas_folder);
let merged = mergeTypeDefs(typesArray);
let printedTypeDefs = print(merged);
return printedTypeDefs;
}
50 changes: 37 additions & 13 deletions utils/setup-keycloak.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,47 @@ async function keycloakDeleteRequest(token, url) {
});
}

/**
* sleep helper function
*
* @param {number} ms time to wait in ms
*/
function sleep(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}


/**
* getMasterToken - get Accesstoken for keycloak rest API
*/
async function getMasterToken() {
const res = await axios({
method: "post",
url: `${KEYCLOAK_BASEURL}/realms/master/protocol/openid-connect/token`,
data: `username=${KEYCLOAK_USER}&password=${KEYCLOAK_PASSWORD}&grant_type=password&client_id=admin-cli`,
headers: {
"content-type": "application/x-www-form-urlencoded;charset=utf-8",
},
});
if (res && res.data) {
return res.data.access_token;
} else {
throw new Error("Failed requesting an API token");
}
try {
const retries = 5;
for (let i = 0; i < retries; i++) {
try {
const res = await axios({
method: "post",
url: `${KEYCLOAK_BASEURL}/realms/master/protocol/openid-connect/token`,
data: `username=${KEYCLOAK_USER}&password=${KEYCLOAK_PASSWORD}&grant_type=password&client_id=admin-cli`,
headers: {
"content-type": "application/x-www-form-urlencoded;charset=utf-8",
},
});
if (res && res.data) {
return res.data.access_token;
} else {
console.error("Failed requesting an API token, ...retrying");
}
} catch (error) {
console.error("Failed requesting an API token, ...retrying");
}
await sleep(1000);
}
} catch (error) {
throw new Error("Failed requesting an API token")
}
}

/**
Expand Down
26 changes: 17 additions & 9 deletions utils/validatorUtil.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
const gd = require("graphql-iso-date");
const {
GraphQLDateTime,
GraphQLDate,
GraphQLTime,
} = require("graphql-scalars");
const Ajv = require("ajv");

/**
Expand Down Expand Up @@ -95,7 +99,7 @@ module.exports.bulkValidateData = async function (
/**
* Adds AJV asynchronous keywords to the argument AJV instance that define ISO
* Date, ISO Time, and ISO DateTime strings or the respective GraphQL instances
* (see package 'graphql-iso-date'). Use in a schema as in the following
* (see package 'graphql-scalars'). Use in a schema as in the following
* example: let schema = { '$async': true, properties: { startDate: { isoDate:
* true } } }
*
Expand All @@ -106,12 +110,13 @@ module.exports.bulkValidateData = async function (
* and used.
*/
module.exports.addDateTimeAjvKeywords = function (ajv) {
ajv.addKeyword("isoDate", {
ajv.addKeyword({
keyword: "isoDate",
async: true,
compile: function (schema, parentSchema) {
return async function (data) {
try {
gd.GraphQLDate.serialize(data);
GraphQLDate.serialize(data);
return true;
} catch (e) {
return new Promise(function (resolve, reject) {
Expand All @@ -134,12 +139,13 @@ module.exports.addDateTimeAjvKeywords = function (ajv) {
errors: true,
});

ajv.addKeyword("isoTime", {
ajv.addKeyword({
keyword: "isoTime",
async: true,
compile: function (schema, parentSchema) {
return async function (data) {
try {
gd.GraphQLTime.serialize(data);
GraphQLTime.serialize(data);
return true;
} catch (e) {
return new Promise(function (resolve, reject) {
Expand All @@ -162,12 +168,13 @@ module.exports.addDateTimeAjvKeywords = function (ajv) {
errors: true,
});

ajv.addKeyword("isoDateTime", {
ajv.addKeyword({
keyword: "isoDateTime",
async: true,
compile: function (schema, parentSchema) {
return async function (data) {
try {
gd.GraphQLDateTime.serialize(data);
GraphQLDateTime.serialize(data);
return true;
} catch (e) {
return new Promise(function (resolve, reject) {
Expand Down Expand Up @@ -203,7 +210,8 @@ module.exports.addDateTimeAjvKeywords = function (ajv) {
* and used.
*/
module.exports.addValidatorFunc = function addValFuncKeyword(ajv) {
ajv.addKeyword("asyncValidatorFunction", {
ajv.addKeyword({
keyword: "asyncValidatorFunction",
async: true,
errors: "full",
compile: function (schema, parentSchema) {
Expand Down

0 comments on commit 8e08d1a

Please sign in to comment.