From 4bebe436ee393ac8eff190412e0527075592981b Mon Sep 17 00:00:00 2001 From: Jacob Bare Date: Thu, 19 May 2022 09:22:05 -0500 Subject: [PATCH 1/6] Remove apollo and associated deps from marko-web --- packages/marko-web/browser/apollo.js | 12 ------------ packages/marko-web/browser/index.js | 12 +----------- packages/marko-web/browser/vue.js | 3 --- packages/marko-web/package.json | 5 ----- 4 files changed, 1 insertion(+), 31 deletions(-) delete mode 100644 packages/marko-web/browser/apollo.js diff --git a/packages/marko-web/browser/apollo.js b/packages/marko-web/browser/apollo.js deleted file mode 100644 index 13a7a9e3a..000000000 --- a/packages/marko-web/browser/apollo.js +++ /dev/null @@ -1,12 +0,0 @@ -import VueApollo from 'vue-apollo'; -import { ApolloClient } from 'apollo-client'; -import { createHttpLink } from 'apollo-link-http'; -import { InMemoryCache } from 'apollo-cache-inmemory'; -import fragmentMatcher from '@parameter1/base-cms-graphql-fragment-types/fragment-matcher'; - -export default new VueApollo({ - defaultClient: new ApolloClient({ - link: createHttpLink({ uri: '/__graphql' }), - cache: new InMemoryCache({ fragmentMatcher }), - }), -}); diff --git a/packages/marko-web/browser/index.js b/packages/marko-web/browser/index.js index e2cea817e..73070d2ac 100644 --- a/packages/marko-web/browser/index.js +++ b/packages/marko-web/browser/index.js @@ -4,11 +4,8 @@ import Vue from './vue'; import Components from './components'; import EventBus from './event-bus'; -const apollo = () => import(/* webpackChunkName: "apollo" */ './apollo'); - const components = {}; const providers = {}; -const requiresApollo = {}; const listeners = {}; const load = async ({ @@ -21,26 +18,19 @@ const load = async ({ if (!el || !name) throw new Error('A Vue component name and element must be provided.'); const Component = components[name]; if (!Component) throw new Error(`No Vue component found for '${name}'`); - let apolloProvider; - if (requiresApollo[name]) { - const { default: provider } = await apollo(); - apolloProvider = provider; - } const component = new Vue({ provide: providers[name], - apolloProvider, render: h => h(Component, { props, on: { ...on, ...listeners[name] } }), }); component.$mount(el, hydrate); }; -const register = async (name, Component, { provide, withApollo, on } = {}) => { +const register = async (name, Component, { provide, on } = {}) => { if (!name) throw new Error('A Vue component name must be provided.'); if (components[name]) throw new Error(`A Vue component already exists for '${name}'`); components[name] = Component; providers[name] = provide; listeners[name] = on; - if (withApollo) requiresApollo[name] = true; }; /** diff --git a/packages/marko-web/browser/vue.js b/packages/marko-web/browser/vue.js index 6e2263aa2..6016c0860 100644 --- a/packages/marko-web/browser/vue.js +++ b/packages/marko-web/browser/vue.js @@ -1,6 +1,3 @@ import Vue from 'vue'; -import VueApollo from 'vue-apollo'; - -Vue.use(VueApollo); export default Vue; diff --git a/packages/marko-web/package.json b/packages/marko-web/package.json index 13a70bcd9..b6b345ee6 100644 --- a/packages/marko-web/package.json +++ b/packages/marko-web/package.json @@ -26,10 +26,6 @@ "@parameter1/base-cms-tenant-context": "^2.0.0", "@parameter1/base-cms-utils": "^2.75.1", "@parameter1/base-cms-web-common": "^2.80.0", - "apollo-cache-inmemory": "^1.6.6", - "apollo-client": "^2.6.10", - "apollo-link": "^1.2.14", - "apollo-link-http": "^1.5.17", "cookie-parser": "^1.4.5", "express": "^4.17.1", "express-http-proxy": "^1.6.2", @@ -41,7 +37,6 @@ "marko": "~4.20.0", "moment": "^2.29.1", "vue": "^2.6.14", - "vue-apollo": "^3.0.8", "vue-server-renderer": "^2.6.14", "whatwg-fetch": "^3.6.1" }, From 95b6843bdc1130fdf5d14df5bcd2b7b3c870ae82 Mon Sep 17 00:00:00 2001 From: Jacob Bare Date: Thu, 19 May 2022 09:22:40 -0500 Subject: [PATCH 2/6] Replace apollo with simple graphql client --- .../leaders-program/apollo/create-client.js | 9 ---- .../leaders-program/apollo/create-provider.js | 22 --------- .../apollo/fragment-matcher.js | 4 -- packages/leaders-program/package.json | 9 +--- packages/leaders-program/public/index.html | 8 ++-- .../src/components/containers/section.vue | 3 +- .../src/components/leaders.vue | 9 ++-- packages/leaders-program/src/dev.js | 19 ++++---- .../src/graphql/create-client.js | 48 +++++++++++++++++++ packages/leaders-program/src/graphql/parse.js | 1 + .../src/graphql/queries/all-sections.js | 2 +- .../graphql/queries/content-for-section.js | 2 +- .../src/graphql/queries/content.js | 2 +- .../graphql/queries/sections-from-content.js | 2 +- .../src/graphql/queries/sections-from-ids.js | 2 +- packages/leaders-program/src/graphql/sha1.js | 12 +++++ packages/leaders-program/src/index.js | 2 + packages/marko-web-leaders/browser/index.js | 6 ++- packages/marko-web-leaders/package.json | 2 - yarn.lock | 21 +++----- 20 files changed, 101 insertions(+), 84 deletions(-) delete mode 100644 packages/leaders-program/apollo/create-client.js delete mode 100644 packages/leaders-program/apollo/create-provider.js delete mode 100644 packages/leaders-program/apollo/fragment-matcher.js create mode 100644 packages/leaders-program/src/graphql/create-client.js create mode 100644 packages/leaders-program/src/graphql/parse.js create mode 100644 packages/leaders-program/src/graphql/sha1.js diff --git a/packages/leaders-program/apollo/create-client.js b/packages/leaders-program/apollo/create-client.js deleted file mode 100644 index 63f7ccef0..000000000 --- a/packages/leaders-program/apollo/create-client.js +++ /dev/null @@ -1,9 +0,0 @@ -import { ApolloClient } from 'apollo-client'; -import { createHttpLink } from 'apollo-link-http'; -import { InMemoryCache } from 'apollo-cache-inmemory'; -import fragmentMatcher from './fragment-matcher'; - -export default ({ uri, headers }) => new ApolloClient({ - link: createHttpLink({ uri, headers }), - cache: new InMemoryCache({ fragmentMatcher }), -}); diff --git a/packages/leaders-program/apollo/create-provider.js b/packages/leaders-program/apollo/create-provider.js deleted file mode 100644 index ac7249359..000000000 --- a/packages/leaders-program/apollo/create-provider.js +++ /dev/null @@ -1,22 +0,0 @@ -import VueApollo from 'vue-apollo'; -import createApolloClient from './create-client'; - -export default ({ - graphqlUri, - tenantKey, - siteId, - baseApiUri, -} = {}) => { - const apiUri = baseApiUri || window.location.origin; - if (!graphqlUri || !tenantKey || !apiUri) { - throw new Error('The graphqlUri, tenantKey, and baseApiUri options are required to create the BaseCMS Apollo Provider.'); - } - const headers = { - 'x-tenant-key': tenantKey, - 'x-base4-api-uri': apiUri, - }; - if (siteId) headers['x-site-id'] = siteId; - return new VueApollo({ - defaultClient: createApolloClient({ uri: graphqlUri, headers }), - }); -}; diff --git a/packages/leaders-program/apollo/fragment-matcher.js b/packages/leaders-program/apollo/fragment-matcher.js deleted file mode 100644 index 98bb02f18..000000000 --- a/packages/leaders-program/apollo/fragment-matcher.js +++ /dev/null @@ -1,4 +0,0 @@ -import { IntrospectionFragmentMatcher } from 'apollo-cache-inmemory'; -import introspectionQueryResultData from '@parameter1/base-cms-graphql-fragment-types'; - -export default new IntrospectionFragmentMatcher({ introspectionQueryResultData }); diff --git a/packages/leaders-program/package.json b/packages/leaders-program/package.json index a32aecb55..04269e989 100644 --- a/packages/leaders-program/package.json +++ b/packages/leaders-program/package.json @@ -14,12 +14,9 @@ }, "dependencies": { "core-js": "^3.18.2", - "graphql": "^14.7.0", - "graphql-tag": "^2.12.5", "object-path": "^0.11.8", "portal-vue": "^2.1.7", - "vue": "^2.6.14", - "vue-apollo": "^3.0.8" + "vue": "^2.6.14" }, "devDependencies": { "@parameter1/base-cms-graphql-fragment-types": "^2.45.0", @@ -27,10 +24,6 @@ "@vue/cli-plugin-eslint": "^4.5.13", "@vue/cli-service": "^4.5.13", "@vue/eslint-config-airbnb": "^4.0.1", - "apollo-cache-inmemory": "^1.6.6", - "apollo-client": "^2.6.10", - "apollo-link": "^1.2.14", - "apollo-link-http": "^1.5.17", "babel-eslint": "^10.1.0", "eslint": "^5.16.0", "eslint-plugin-vue": "^5.0.0", diff --git a/packages/leaders-program/public/index.html b/packages/leaders-program/public/index.html index e2ebac24b..6f20dbb84 100644 --- a/packages/leaders-program/public/index.html +++ b/packages/leaders-program/public/index.html @@ -10,7 +10,7 @@ diff --git a/packages/leaders-program/src/components/containers/section.vue b/packages/leaders-program/src/components/containers/section.vue index 8c9a85bba..f9e5de30c 100644 --- a/packages/leaders-program/src/components/containers/section.vue +++ b/packages/leaders-program/src/components/containers/section.vue @@ -58,6 +58,7 @@ import query from '../../graphql/queries/content-for-section'; import getEdgeNodes from '../../utils/get-edge-nodes'; export default { + inject: ['$graphql'], components: { PlusIcon, MinusIcon, @@ -197,7 +198,7 @@ export default { promotionLimit: this.promotionLimit, videoLimit: this.videoLimit, }; - const { data } = await this.$apollo.query({ query, variables }); + const { data } = await this.$graphql.query({ query, variables }); this.items = getEdgeNodes(data, 'websiteScheduledContent'); this.hasLoaded = true; } catch (e) { diff --git a/packages/leaders-program/src/components/leaders.vue b/packages/leaders-program/src/components/leaders.vue index 90ed1b811..f4a3c8bf3 100644 --- a/packages/leaders-program/src/components/leaders.vue +++ b/packages/leaders-program/src/components/leaders.vue @@ -50,6 +50,7 @@ import getEdgeNodes from '../utils/get-edge-nodes'; import getAsObject from '../utils/get-as-object'; export default { + inject: ['$graphql'], components: { Loading, LeadersHeader, @@ -253,7 +254,7 @@ export default { const { sectionIds } = this; if (sectionIds && sectionIds.length) { const variables = { sectionIds }; - const r = await this.$apollo.query({ query: fromIdsQuery, variables }); + const r = await this.$graphql.query({ query: fromIdsQuery, variables }); const sections = getEdgeNodes(r, 'data.websiteSections') .filter(s => s.hierarchy.some(({ alias }) => alias === this.sectionAlias)); if (sections.length) return sections; @@ -269,7 +270,7 @@ export default { async loadContentSections() { if (!this.contentId) return []; const variables = { contentId: this.contentId }; - const r1 = await this.$apollo.query({ query: contentQuery, variables }); + const r1 = await this.$graphql.query({ query: contentQuery, variables }); const taxonomyIds = getEdgeNodes(r1, 'data.content.taxonomy').map(t => t.id); const sectionIds = []; this.taxonomyIds = taxonomyIds; @@ -279,7 +280,7 @@ export default { } if (!taxonomyIds.length && !sectionIds.length) return []; const v2 = { taxonomyIds, relatedSectionIds: sectionIds }; - const r2 = await this.$apollo.query({ query: fromContentQuery, variables: v2 }); + const r2 = await this.$graphql.query({ query: fromContentQuery, variables: v2 }); const sections = getEdgeNodes(r2, 'data.websiteSections'); return sections .filter(s => s.hierarchy.some(({ alias }) => alias === this.sectionAlias)); @@ -287,7 +288,7 @@ export default { async loadAllSections() { const variables = { sectionAlias: this.sectionAlias }; - const { data } = await this.$apollo.query({ query: allQuery, variables }); + const { data } = await this.$graphql.query({ query: allQuery, variables }); this.loadType = 'all'; return getEdgeNodes(data, 'websiteSectionAlias.children'); }, diff --git a/packages/leaders-program/src/dev.js b/packages/leaders-program/src/dev.js index 457bb713c..df101efa7 100644 --- a/packages/leaders-program/src/dev.js +++ b/packages/leaders-program/src/dev.js @@ -1,12 +1,10 @@ /* eslint-disable no-new */ import Vue from 'vue'; -import VueApollo from 'vue-apollo'; import Leaders from './components/leaders.vue'; -import createProvider from '../apollo/create-provider'; +import createGraphQLClient from './graphql/create-client'; Vue.config.productionTip = false; -Vue.use(VueApollo); const components = { Leaders, @@ -15,21 +13,22 @@ const components = { const loadComponent = ({ el, name, - apollo = {}, + graphql = {}, props = {}, on, } = {}) => { - const { uri, tenant, siteId } = apollo; + const { uri, tenant, siteId } = graphql; if (!uri || !tenant || !siteId) throw new Error('The provided apollo config is invalid.'); if (!components[name]) throw new Error(`No BaseCMS Management Component found for '${name}'`); const Component = components[name]; new Vue({ el, - apolloProvider: createProvider({ - graphqlUri: uri, - tenantKey: tenant, - siteId, - }), + provide: { + $graphql: createGraphQLClient({ + uri, + headers: { 'x-tenant-key': tenant, 'x-site-id': siteId }, + }), + }, render: h => h(Component, { props, on }), }); }; diff --git a/packages/leaders-program/src/graphql/create-client.js b/packages/leaders-program/src/graphql/create-client.js new file mode 100644 index 000000000..dc35bca06 --- /dev/null +++ b/packages/leaders-program/src/graphql/create-client.js @@ -0,0 +1,48 @@ +import sha1 from './sha1'; + +const getOperationName = (string) => { + const matches = /query\s+([a-z0-9]+)[(]?.+{/gi.exec(string); + if (matches && matches[1]) return matches[1]; + return undefined; +}; + +export default ({ uri, headers: globalHeaders }) => { + const cache = new Map(); + return Object.create({ + query: async ({ query, variables, headers }) => { + const body = JSON.stringify({ + operationName: getOperationName(query), + variables, + query, + }); + const hash = await sha1(body); + if (hash && cache.has(hash)) return cache.get(hash); + + const res = await fetch(uri, { + method: 'POST', + headers: { + ...globalHeaders, + ...headers, + 'content-type': 'application/json', + }, + body, + }); + const json = await res.json(); + if (!res.ok || (json && json.errors)) { + if (!json || !json.errors) { + const err = new Error(`An unknown, fatal GraphQL error was encountered (${res.status})`); + err.statusCode = res.status; + throw err; + } + const [networkError] = json.errors; + const err = new Error(networkError.message); + const { extensions } = networkError; + if (extensions) err.code = extensions.code; + if (extensions && extensions.exception) err.statusCode = extensions.exception.statusCode; + throw err; + } + if (hash) cache.set(hash, json); + return json; + }, + }); +}; diff --git a/packages/leaders-program/src/graphql/parse.js b/packages/leaders-program/src/graphql/parse.js new file mode 100644 index 000000000..33a997c13 --- /dev/null +++ b/packages/leaders-program/src/graphql/parse.js @@ -0,0 +1 @@ +export default (strings, ...rest) => [...strings, ...rest].join('\n'); diff --git a/packages/leaders-program/src/graphql/queries/all-sections.js b/packages/leaders-program/src/graphql/queries/all-sections.js index 178e357a1..c58d82cad 100644 --- a/packages/leaders-program/src/graphql/queries/all-sections.js +++ b/packages/leaders-program/src/graphql/queries/all-sections.js @@ -1,4 +1,4 @@ -import gql from 'graphql-tag'; +import gql from '../parse'; export default gql` diff --git a/packages/leaders-program/src/graphql/queries/content-for-section.js b/packages/leaders-program/src/graphql/queries/content-for-section.js index c3ec0cff5..ba180c9fd 100644 --- a/packages/leaders-program/src/graphql/queries/content-for-section.js +++ b/packages/leaders-program/src/graphql/queries/content-for-section.js @@ -1,4 +1,4 @@ -import gql from 'graphql-tag'; +import gql from '../parse'; export default gql` diff --git a/packages/leaders-program/src/graphql/queries/content.js b/packages/leaders-program/src/graphql/queries/content.js index 0c0a3b19b..fdf4cfe6c 100644 --- a/packages/leaders-program/src/graphql/queries/content.js +++ b/packages/leaders-program/src/graphql/queries/content.js @@ -1,4 +1,4 @@ -import gql from 'graphql-tag'; +import gql from '../parse'; export default gql` diff --git a/packages/leaders-program/src/graphql/queries/sections-from-content.js b/packages/leaders-program/src/graphql/queries/sections-from-content.js index 1ed5a3121..f6798d120 100644 --- a/packages/leaders-program/src/graphql/queries/sections-from-content.js +++ b/packages/leaders-program/src/graphql/queries/sections-from-content.js @@ -1,4 +1,4 @@ -import gql from 'graphql-tag'; +import gql from '../parse'; export default gql` diff --git a/packages/leaders-program/src/graphql/queries/sections-from-ids.js b/packages/leaders-program/src/graphql/queries/sections-from-ids.js index bca40ca07..ed2ca5773 100644 --- a/packages/leaders-program/src/graphql/queries/sections-from-ids.js +++ b/packages/leaders-program/src/graphql/queries/sections-from-ids.js @@ -1,4 +1,4 @@ -import gql from 'graphql-tag'; +import gql from '../parse'; export default gql` diff --git a/packages/leaders-program/src/graphql/sha1.js b/packages/leaders-program/src/graphql/sha1.js new file mode 100644 index 000000000..ede41afa2 --- /dev/null +++ b/packages/leaders-program/src/graphql/sha1.js @@ -0,0 +1,12 @@ +export default async (string) => { + if (process.server) return null; + const buffer = new TextEncoder('utf-8').encode(string); + const digest = await crypto.subtle.digest('SHA-1', buffer); + const hexCodes = []; + const view = new DataView(digest); + for (let i = 0; i < view.byteLength; i += 1) { + const byte = view.getUint8(i).toString(16).padStart(2, '0'); + hexCodes.push(byte); + } + return hexCodes.join(''); +}; diff --git a/packages/leaders-program/src/index.js b/packages/leaders-program/src/index.js index f6c194687..c0dc4b603 100644 --- a/packages/leaders-program/src/index.js +++ b/packages/leaders-program/src/index.js @@ -1,3 +1,5 @@ import Leaders from './components/leaders.vue'; +export { default as createGraphQLClient } from './graphql/create-client'; + export default Leaders; diff --git a/packages/marko-web-leaders/browser/index.js b/packages/marko-web-leaders/browser/index.js index 70117ac1a..7e48daed1 100644 --- a/packages/marko-web-leaders/browser/index.js +++ b/packages/marko-web-leaders/browser/index.js @@ -1,3 +1,5 @@ +import { createGraphQLClient } from '@parameter1/base-cms-leaders-program'; + const LeadersProgram = () => import(/* webpackChunkName: "leaders-program" */ '@parameter1/base-cms-leaders-program'); const LeadersCompanyWebsiteLink = () => import(/* webpackChunkName: "leaders-company-website-link" */ './company-website-link.vue'); const LeadersCompanySocialLink = () => import(/* webpackChunkName: "leaders-company-social-link" */ './company-social-link.vue'); @@ -10,7 +12,9 @@ export default (Browser, { withGTM = true, withP1Events = true } = {}) => { if (withGTM) Browser.register('LeadersGTMTracker', LeadersGTMTracker, { provide: { EventBus } }); if (withP1Events) Browser.register('LeadersP1EventsTracker', LeadersP1EventsTracker, { provide: { EventBus } }); Browser.register('LeadersProgram', LeadersProgram, { - withApollo: true, + provide: { + $graphql: createGraphQLClient({ uri: '/__graphql' }), + }, on: { action: (...args) => EventBus.$emit('leaders-action', ...args) }, }); Browser.register('LeadersCompanyWebsiteLink', LeadersCompanyWebsiteLink, { diff --git a/packages/marko-web-leaders/package.json b/packages/marko-web-leaders/package.json index dc180f0ef..711f21c9d 100644 --- a/packages/marko-web-leaders/package.json +++ b/packages/marko-web-leaders/package.json @@ -16,8 +16,6 @@ "@parameter1/base-cms-leaders-program": "^2.45.0", "@parameter1/base-cms-marko-web-icons": "^2.46.3", "@parameter1/base-cms-object-path": "^2.75.1", - "graphql": "^14.7.0", - "graphql-tag": "^2.12.5", "object-path": "^0.11.8" }, "peerDependencies": { diff --git a/yarn.lock b/yarn.lock index b4068fc2d..43308418c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10006,6 +10006,13 @@ graphql-subscriptions@^1.0.0: dependencies: iterall "^1.2.1" +graphql-tag@^2.10.1: + version "2.12.6" + resolved "https://registry.yarnpkg.com/graphql-tag/-/graphql-tag-2.12.6.tgz#d441a569c1d2537ef10ca3d1633b48725329b5f1" + integrity sha512-FdSNcu2QQcWnM2VNvSCCDCVS5PpPqpzgFT8+GXzqJuoDd0CBncxCY278u4mhRO7tMgo2JjgJA5aZ+nWSQ/Z+xg== + dependencies: + tslib "^2.1.0" + graphql-tag@^2.11.0: version "2.11.0" resolved "https://registry.yarnpkg.com/graphql-tag/-/graphql-tag-2.11.0.tgz#1deb53a01c46a7eb401d6cb59dec86fa1cccbffd" @@ -18008,11 +18015,6 @@ thread-loader@^2.1.3: loader-utils "^1.1.0" neo-async "^2.6.0" -throttle-debounce@^2.1.0: - version "2.1.0" - resolved "https://registry.yarnpkg.com/throttle-debounce/-/throttle-debounce-2.1.0.tgz#257e648f0a56bd9e54fe0f132c4ab8611df4e1d5" - integrity sha512-AOvyNahXQuU7NN+VVvOOX+uW6FPaWdAOdRP5HfwYxAfCzXTFKRMoIMk+n+po318+ktcChx+F1Dd91G3YHeMKyg== - through2-filter@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/through2-filter/-/through2-filter-3.0.0.tgz#700e786df2367c2c88cd8aa5be4cf9c1e7831254" @@ -18865,15 +18867,6 @@ vm-browserify@^1.0.1: resolved "https://registry.yarnpkg.com/vm-browserify/-/vm-browserify-1.1.0.tgz#bd76d6a23323e2ca8ffa12028dc04559c75f9019" integrity sha512-iq+S7vZJE60yejDYM0ek6zg308+UZsdtPExWP9VZoCFCz1zkJoXFnAX7aZfd/ZwrkidzdUZL0C/ryW+JwAiIGw== -vue-apollo@^3.0.8: - version "3.0.8" - resolved "https://registry.yarnpkg.com/vue-apollo/-/vue-apollo-3.0.8.tgz#6609a006daf5ba38c19a7ed7d802b907e7361a86" - integrity sha512-RnkC75PMoGwl1sdZdVO3R9P51wqmgOVi4QmljkBaTzlVThVlqfkJhrBcPiw2K9EohvSagvZclNqXktyOCcXbBA== - dependencies: - chalk "^2.4.2" - serialize-javascript "^4.0.0" - throttle-debounce "^2.1.0" - vue-eslint-parser@^5.0.0: version "5.0.0" resolved "https://registry.yarnpkg.com/vue-eslint-parser/-/vue-eslint-parser-5.0.0.tgz#00f4e4da94ec974b821a26ff0ed0f7a78402b8a1" From fcffc3ebd428dd55899f53dab91724b4bbca27f6 Mon Sep 17 00:00:00 2001 From: Jacob Bare Date: Thu, 19 May 2022 09:56:56 -0500 Subject: [PATCH 3/6] Swap `bcrypt` with `bcryptjs` --- services/graphql-server/package.json | 2 +- .../graphql-server/src/user/token-service.js | 2 +- .../graphql-server/src/user/user-service.js | 2 +- yarn.lock | 85 ++----------------- 4 files changed, 11 insertions(+), 80 deletions(-) diff --git a/services/graphql-server/package.json b/services/graphql-server/package.json index d59c443dd..3114fb0fe 100644 --- a/services/graphql-server/package.json +++ b/services/graphql-server/package.json @@ -28,7 +28,7 @@ "@parameter1/base-cms-utils": "^2.75.1", "apollo-newrelic-extension": "^0.1.1", "apollo-server-express": "^2.25.2", - "bcrypt": "^5.0.1", + "bcryptjs": "^2.4.3", "cheerio": "^1.0.0-rc.10", "cors": "^2.8.5", "dataloader": "^1.4.0", diff --git a/services/graphql-server/src/user/token-service.js b/services/graphql-server/src/user/token-service.js index df689ac6e..af8bf3322 100644 --- a/services/graphql-server/src/user/token-service.js +++ b/services/graphql-server/src/user/token-service.js @@ -2,7 +2,7 @@ const { AuthenticationError } = require('apollo-server-express'); const jwt = require('jsonwebtoken'); const uuidv4 = require('uuid/v4'); const uuidv5 = require('uuid/v5'); -const bcrypt = require('bcrypt'); +const bcrypt = require('bcryptjs'); const { TOKEN_SECRET, TOKEN_NAMESPACE } = require('../env'); class TokenService { diff --git a/services/graphql-server/src/user/user-service.js b/services/graphql-server/src/user/user-service.js index 436df129e..eb7c4879a 100644 --- a/services/graphql-server/src/user/user-service.js +++ b/services/graphql-server/src/user/user-service.js @@ -1,5 +1,5 @@ const { AuthenticationError } = require('apollo-server-express'); -const bcrypt = require('bcrypt'); +const bcrypt = require('bcryptjs'); const TokenService = require('./token-service'); const UserService = class UserService { diff --git a/yarn.lock b/yarn.lock index 43308418c..dbd91f515 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2872,21 +2872,6 @@ npmlog "^4.1.2" write-file-atomic "^2.3.0" -"@mapbox/node-pre-gyp@^1.0.0": - version "1.0.5" - resolved "https://registry.yarnpkg.com/@mapbox/node-pre-gyp/-/node-pre-gyp-1.0.5.tgz#2a0b32fcb416fb3f2250fd24cb2a81421a4f5950" - integrity sha512-4srsKPXWlIxp5Vbqz5uLfBN+du2fJChBoYn/f2h991WLdk7jUvcSk/McVLSv/X+xQIPI8eGD5GjrnygdyHnhPA== - dependencies: - detect-libc "^1.0.3" - https-proxy-agent "^5.0.0" - make-dir "^3.1.0" - node-fetch "^2.6.1" - nopt "^5.0.0" - npmlog "^4.1.2" - rimraf "^3.0.2" - semver "^7.3.4" - tar "^6.1.0" - "@mrmlnc/readdir-enhanced@^2.2.1": version "2.2.1" resolved "https://registry.yarnpkg.com/@mrmlnc/readdir-enhanced/-/readdir-enhanced-2.2.1.tgz#524af240d1a360527b730475ecfa1344aa540dde" @@ -5411,13 +5396,10 @@ bcrypt-pbkdf@^1.0.0: dependencies: tweetnacl "^0.14.3" -bcrypt@^5.0.1: - version "5.0.1" - resolved "https://registry.yarnpkg.com/bcrypt/-/bcrypt-5.0.1.tgz#f1a2c20f208e2ccdceea4433df0c8b2c54ecdf71" - integrity sha512-9BTgmrhZM2t1bNuDtrtIMVSmmxZBrJ71n8Wg+YgdjHuIWYF7SjjmCPZFB+/5i/o/PIeRpwVJR3P+NrpIItUjqw== - dependencies: - "@mapbox/node-pre-gyp" "^1.0.0" - node-addon-api "^3.1.0" +bcryptjs@^2.4.3: + version "2.4.3" + resolved "https://registry.yarnpkg.com/bcryptjs/-/bcryptjs-2.4.3.tgz#9ab5627b93e60621ff7cdac5da9733027df1d0cb" + integrity sha512-V/Hy/X9Vt7f3BbPJEi8BdVFMByHi+jNXrYkW3huaybV/kQ0KJg0Y6PkEMbn+zeT+i+SiKZ/HMqJGIIt4LZDqNQ== before-after-hook@^2.0.0: version "2.1.0" @@ -6246,11 +6228,6 @@ chownr@^1.1.1, chownr@^1.1.2: resolved "https://registry.yarnpkg.com/chownr/-/chownr-1.1.2.tgz#a18f1e0b269c8a6a5d3c86eb298beb14c3dd7bf6" integrity sha512-GkfeAQh+QNy3wquu9oIZr6SS5x7wGdSgNQvD10X3r+AZr1Oys22HW8kAmDMvNg2+Dm0TeGaEuO8gFwdBXxwO8A== -chownr@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/chownr/-/chownr-2.0.0.tgz#15bfbe53d2eab4cf70f18a8cd68ebe5b3cb1dece" - integrity sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ== - chrome-trace-event@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/chrome-trace-event/-/chrome-trace-event-1.0.2.tgz#234090ee97c7d4ad1a2c4beae27505deffc608a4" @@ -7704,7 +7681,7 @@ detect-indent@^5.0.0: resolved "https://registry.yarnpkg.com/detect-indent/-/detect-indent-5.0.0.tgz#3871cc0a6a002e8c3e5b3cf7f336264675f06b9d" integrity sha1-OHHMCmoALow+Wzz38zYmRnXwa50= -detect-libc@^1.0.2, detect-libc@^1.0.3: +detect-libc@^1.0.2: version "1.0.3" resolved "https://registry.yarnpkg.com/detect-libc/-/detect-libc-1.0.3.tgz#fa137c4bd698edf55cd5cd02ac559f91a4c4ba9b" integrity sha1-+hN8S9aY7fVc1c0CrFWfkaTEups= @@ -9454,13 +9431,6 @@ fs-minipass@^1.2.5: dependencies: minipass "^2.2.1" -fs-minipass@^2.0.0: - version "2.1.0" - resolved "https://registry.yarnpkg.com/fs-minipass/-/fs-minipass-2.1.0.tgz#7f5036fdbf12c63c169190cbe4199c852271f9fb" - integrity sha512-V/JgOLFCS+R6Vcq0slCuaeWEdNC3ouDlJMNIsacH2VtALiu9mV4LPrHc5cDl8k5aw6J8jwgWWpiTo5RYhmIzvg== - dependencies: - minipass "^3.0.0" - fs-mkdirp-stream@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/fs-mkdirp-stream/-/fs-mkdirp-stream-1.0.0.tgz#0b7815fc3201c6a69e14db98ce098c16935259eb" @@ -13043,7 +13013,7 @@ minipass@^2.2.1, minipass@^2.3.5: safe-buffer "^5.1.2" yallist "^3.0.0" -minipass@^3.0.0, minipass@^3.1.1: +minipass@^3.1.1: version "3.1.3" resolved "https://registry.yarnpkg.com/minipass/-/minipass-3.1.3.tgz#7d42ff1f39635482e15f9cdb53184deebd5815fd" integrity sha512-Mgd2GdMVzY+x3IJ+oHnVM+KG3lA5c8tnabyJKmHSaG2kAGpudxuOf8ToDkhumF7UzME7DecbQE9uOZhNm7PuJg== @@ -13057,14 +13027,6 @@ minizlib@^1.2.1: dependencies: minipass "^2.2.1" -minizlib@^2.1.1: - version "2.1.2" - resolved "https://registry.yarnpkg.com/minizlib/-/minizlib-2.1.2.tgz#e90d3466ba209b932451508a11ce3d3632145931" - integrity sha512-bAxsR8BVfj60DWXHE3u30oHzfl4G7khkSuPW+qvpd7jFRHm7dLxOjUk1EHACJ/hxLY8phGJ0YhYHZo7jil7Qdg== - dependencies: - minipass "^3.0.0" - yallist "^4.0.0" - mississippi@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/mississippi/-/mississippi-3.0.0.tgz#ea0a3291f97e0b5e8776b363d5f0a12d94c67022" @@ -13096,7 +13058,7 @@ mkdirp-promise@^5.0.1: dependencies: mkdirp "*" -mkdirp@*, mkdirp@^1.0.3: +mkdirp@*: version "1.0.4" resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-1.0.4.tgz#3eb5ed62622756d79a5f0e2a221dfebad75c2f7e" integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw== @@ -13395,11 +13357,6 @@ nocache@2.1.0, nocache@^2.1.0: resolved "https://registry.yarnpkg.com/nocache/-/nocache-2.1.0.tgz#120c9ffec43b5729b1d5de88cd71aa75a0ba491f" integrity sha512-0L9FvHG3nfnnmaEQPjT9xhfN4ISk0A8/2j4M37Np4mcDesJjHgEUfgPhdCyZuFI954tjokaIj/A3NdpFNdEh4Q== -node-addon-api@^3.1.0: - version "3.2.1" - resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-3.2.1.tgz#81325e0a2117789c0128dab65e7e38f07ceba161" - integrity sha512-mmcei9JghVNDYydghQmeDX8KoAm0FAiYyIcUt/N4nhyAipB17pllZQDOJD2fotxABnt4Mdz+dKTO7eftLg4d0A== - node-environment-flags@1.0.5: version "1.0.5" resolved "https://registry.yarnpkg.com/node-environment-flags/-/node-environment-flags-1.0.5.tgz#fa930275f5bf5dae188d6192b24b4c8bbac3d76a" @@ -13591,13 +13548,6 @@ nopt@^4.0.1, nopt@~4.0.1: abbrev "1" osenv "^0.1.4" -nopt@^5.0.0: - version "5.0.0" - resolved "https://registry.yarnpkg.com/nopt/-/nopt-5.0.0.tgz#530942bb58a512fccafe53fe210f13a25355dc88" - integrity sha512-Tbj67rffqceeLpcRXrT7vKAN8CwfPeIBgM7E6iBkmKLV7bEMwpGgYLGv0jACUsECaa/vuxP0IjEont6umdMgtQ== - dependencies: - abbrev "1" - normalize-package-data@^2.0.0, normalize-package-data@^2.3.0, normalize-package-data@^2.3.4, normalize-package-data@^2.3.5, normalize-package-data@^2.4.0: version "2.4.0" resolved "https://registry.yarnpkg.com/normalize-package-data/-/normalize-package-data-2.4.0.tgz#12f95a307d58352075a04907b84ac8be98ac012f" @@ -16468,13 +16418,6 @@ rimraf@2.6.3, rimraf@~2.6.2: dependencies: glob "^7.1.3" -rimraf@^3.0.2: - version "3.0.2" - resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-3.0.2.tgz#f1a5402ba6220ad52cc1282bac1ae3aa49fd061a" - integrity sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA== - dependencies: - glob "^7.1.3" - ripemd160@^2.0.0, ripemd160@^2.0.1: version "2.0.2" resolved "https://registry.yarnpkg.com/ripemd160/-/ripemd160-2.0.2.tgz#a1c1a6f624751577ba5d07914cbc92850585890c" @@ -16704,7 +16647,7 @@ semver@^6.0.0, semver@^6.1.0, semver@^6.1.1, semver@^6.1.2, semver@^6.2.0, semve resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d" integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw== -semver@^7.3.4, semver@^7.3.5: +semver@^7.3.5: version "7.3.5" resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.5.tgz#0b621c879348d8998e4b0e4be94b3f12e6018ef7" integrity sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ== @@ -17886,18 +17829,6 @@ tar@^4, tar@^4.4.10, tar@^4.4.8: safe-buffer "^5.1.2" yallist "^3.0.3" -tar@^6.1.0: - version "6.1.11" - resolved "https://registry.yarnpkg.com/tar/-/tar-6.1.11.tgz#6760a38f003afa1b2ffd0ffe9e9abbd0eab3d621" - integrity sha512-an/KZQzQUkZCkuoAA64hM92X0Urb6VpRhAFllDzz44U2mcD5scmT3zBc4VgVpkugF580+DQn8eAFSyoQt0tznA== - dependencies: - chownr "^2.0.0" - fs-minipass "^2.0.0" - minipass "^3.0.0" - minizlib "^2.1.1" - mkdirp "^1.0.3" - yallist "^4.0.0" - temp-dir@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/temp-dir/-/temp-dir-1.0.0.tgz#0a7c0ea26d3a39afa7e0ebea9c1fc0bc4daa011d" From ed95cc0adb3ee072e2ca37c48d5c193590ceceb6 Mon Sep 17 00:00:00 2001 From: Jacob Bare Date: Thu, 19 May 2022 09:57:11 -0500 Subject: [PATCH 4/6] Catch sha1 errors and return empty hash --- packages/leaders-program/src/graphql/sha1.js | 24 ++++++++++++-------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/packages/leaders-program/src/graphql/sha1.js b/packages/leaders-program/src/graphql/sha1.js index ede41afa2..f8bff715b 100644 --- a/packages/leaders-program/src/graphql/sha1.js +++ b/packages/leaders-program/src/graphql/sha1.js @@ -1,12 +1,18 @@ +const { error } = console; + export default async (string) => { - if (process.server) return null; - const buffer = new TextEncoder('utf-8').encode(string); - const digest = await crypto.subtle.digest('SHA-1', buffer); - const hexCodes = []; - const view = new DataView(digest); - for (let i = 0; i < view.byteLength; i += 1) { - const byte = view.getUint8(i).toString(16).padStart(2, '0'); - hexCodes.push(byte); + try { + const buffer = new TextEncoder('utf-8').encode(string); + const digest = await crypto.subtle.digest('SHA-1', buffer); + const hexCodes = []; + const view = new DataView(digest); + for (let i = 0; i < view.byteLength; i += 1) { + const byte = view.getUint8(i).toString(16).padStart(2, '0'); + hexCodes.push(byte); + } + return hexCodes.join(''); + } catch (e) { + error('Unable to create SHA1 - GraphQL cache will be disabled.', e); + return null; } - return hexCodes.join(''); }; From 057e48d7dc97eb37ec83aa0a313849aca4b011d9 Mon Sep 17 00:00:00 2001 From: Jacob Bare Date: Thu, 19 May 2022 09:57:23 -0500 Subject: [PATCH 5/6] Install marko-web-leaders into example website --- services/example-website/browser/index.js | 2 ++ services/example-website/package.json | 1 + .../example-website/server/styles/index.scss | 1 + .../server/templates/index.marko | 21 +++++++++++++++++++ 4 files changed, 25 insertions(+) diff --git a/services/example-website/browser/index.js b/services/example-website/browser/index.js index cf650c455..24aa40ec2 100644 --- a/services/example-website/browser/index.js +++ b/services/example-website/browser/index.js @@ -1,9 +1,11 @@ import Browser from '@parameter1/base-cms-marko-web/browser'; import OmedaIdentityX from '@parameter1/base-cms-marko-web-omeda-identity-x/browser'; import GTM from '@parameter1/base-cms-marko-web-gtm/browser'; +import Leaders from '@parameter1/base-cms-marko-web-leaders/browser'; GTM(Browser); OmedaIdentityX(Browser); +Leaders(Browser); const { EventBus } = Browser; const { log } = console; diff --git a/services/example-website/package.json b/services/example-website/package.json index 676aeff6f..b3b594024 100644 --- a/services/example-website/package.json +++ b/services/example-website/package.json @@ -21,6 +21,7 @@ "@parameter1/base-cms-marko-web": "^2.81.0", "@parameter1/base-cms-marko-web-gtm": "^2.88.0", "@parameter1/base-cms-marko-web-identity-x": "^2.90.2", + "@parameter1/base-cms-marko-web-leaders": "^2.75.1", "@parameter1/base-cms-marko-web-omeda": "^2.79.0", "@parameter1/base-cms-marko-web-omeda-identity-x": "^2.90.2", "@parameter1/base-cms-marko-web-theme-default": "^2.90.0", diff --git a/services/example-website/server/styles/index.scss b/services/example-website/server/styles/index.scss index 235dcd9db..893bb0d7b 100644 --- a/services/example-website/server/styles/index.scss +++ b/services/example-website/server/styles/index.scss @@ -1,4 +1,5 @@ @import "../../node_modules/@parameter1/base-cms-marko-web-theme-default/scss/theme"; +@import "../../node_modules/@parameter1/base-cms-marko-web-leaders/scss/leaders"; body { -webkit-font-smoothing: antialiased; diff --git a/services/example-website/server/templates/index.marko b/services/example-website/server/templates/index.marko index ace650705..7bdaabda2 100644 --- a/services/example-website/server/templates/index.marko +++ b/services/example-website/server/templates/index.marko @@ -3,6 +3,9 @@ title="Test Page" description="This is a test page." > + <@above-container> + + <@page>

Hello World!