Skip to content

Commit

Permalink
Merge 7cc5349 into 96164fc
Browse files Browse the repository at this point in the history
  • Loading branch information
andrzejewsky committed Mar 30, 2021
2 parents 96164fc + 7cc5349 commit bc938cc
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 123 deletions.
3 changes: 2 additions & 1 deletion packages/core/core/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* istanbul ignore file */

import { Ref } from '@vue/composition-api';
import type { Request, Response } from 'express';
import type { Request, Response, Express } from 'express';

export type ComputedProperty<T> = Readonly<Ref<Readonly<T>>>;

Expand Down Expand Up @@ -668,6 +668,7 @@ export type ApiClientMethod = (...args: any) => Promise<any>
export interface ApiClientExtension {
name: string;
extendApiMethods?: Record<string, ApiClientMethod>;
extendApp?: (app: Express) => void;
hooks?: (req: Request, res: Response) => ApiClientExtensionHooks;
}

Expand Down
2 changes: 2 additions & 0 deletions packages/core/docs/advanced/server-middleware.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const extension = {
extendApiMethods: {
getProduct: async () => { /* ... */ }
},
extendApp: (app) => { /* ... */ },
hooks: (req, res) => {
return {
beforeCreate: ({ configuration }) => configuration,
Expand All @@ -88,6 +89,7 @@ const extension = {

- `name` - defines the unique name of an extension
- `extendApiMethods` - overrides the original functions from API-client
- `extendApp` - a function that gives you access to the express.js app
- `hooks` - defines lifecycle hooks of API-client
- `hooks:beforeCreate` - called before API-client creates a connection, takes the given configuration as an argument, and must return the configuration. Here you can attach something else to the configuration or even change it.
- `hooks:afterCreate` - Similar to the previous one, but called after the connection has been created. It also returns a configuration and you can change it.
Expand Down
8 changes: 8 additions & 0 deletions packages/core/docs/changelog/5714.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
description: 'Add ability to access express instance in the middleware extensions',
link: 'https://github.com/vuestorefront/vue-storefront/pull/5714',
isBreaking: false,
breakingChanges: [],
author: 'andrzejewsky',
linkToGitHubAccount: 'https://github.com/andrzejewsky'
};
2 changes: 1 addition & 1 deletion packages/core/middleware/src/createServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function createServer (config: MiddlewareConfig): Express {
consola.info('Middleware starting....');
consola.info('Loading integartions...');

const integrations = registerIntegrations(config.integrations);
const integrations = registerIntegrations(app, config.integrations);

consola.success('Integrations loaded!');

Expand Down
11 changes: 8 additions & 3 deletions packages/core/middleware/src/integrations.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import consola from 'consola';
import { Express } from 'express';
import {
Integration,
ApiClientFactory,
Expand All @@ -11,7 +12,7 @@ interface IntegrationLoaded {
apiClient: ApiClientFactory;
configuration: any;
extensions: ApiClientExtension[];
customQueries?: Record<string, CustomQuery>;
customQueries?: Record<string, CustomQuery>
}

type IntegrationsLoaded = Record<string, IntegrationLoaded>
Expand All @@ -28,16 +29,20 @@ const lookUpExternal = (curr: string | ApiClientExtension): ApiClientExtension[]
const createExtensions = (rawExtensions: ApiClientExtension[]): ApiClientExtension[] => rawExtensions
.reduce((prev, curr) => [...prev, ...lookUpExternal(curr)], []);

const registerIntegrations = (integrations: IntegrationsSection): IntegrationsLoaded =>
const registerIntegrations = (app: Express, integrations: IntegrationsSection): IntegrationsLoaded =>
Object.entries<Integration>(integrations).reduce((prev, [tag, integration]) => {
consola.info(`- Loading: ${tag} ${integration.location}`);

const apiClient: ApiClientFactory = require(integration.location);
const rawExtensions: ApiClientExtension[] = createRawExtensions(apiClient, integration);
const extensions: ApiClientExtension[] = createExtensions(rawExtensions);

extensions.forEach(({ name }) => {
extensions.forEach(({ name, extendApp }) => {
consola.info(`- Loading: ${tag} extension: ${name}`);

if (extendApp) {
extendApp(app);
}
});

consola.success(`- Integration: ${tag} loaded!`);
Expand Down
121 changes: 3 additions & 118 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.12.11.tgz#f4ad435aa263db935b8f10f2c552d23fb716a63f"
integrity sha512-Zt1yodBx1UcyiePMSkWnU4hPqhwq7hGi2nFL1LeA3EUl+q2LQx16MISgJ0+z7dnmgvP9QtIleuETGOiOH1RcIw==
dependencies:
"@babel/highlight" "^7.12.13"
"@babel/highlight" "^7.10.4"

"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.12.13", "@babel/code-frame@^7.5.5", "@babel/code-frame@^7.8.3":
version "7.12.13"
Expand Down Expand Up @@ -270,7 +270,7 @@
"@babel/traverse" "^7.13.0"
"@babel/types" "^7.13.0"

"@babel/highlight@^7.10.4", "@babel/highlight@^7.12.13":
"@babel/highlight@^7.12.13":
version "7.13.10"
resolved "https://registry.yarnpkg.com/@babel/highlight/-/highlight-7.13.10.tgz#a8b2a66148f5b27d666b15d81774347a731d52d1"
integrity sha512-5aPpe5XQPzflQrFwL1/QoeHkP2MsA4JCntcXHRhEsdsfPVkvPi2w7Qix4iV7t5S/oC9OodGrggd8aco1g3SZFg==
Expand Down Expand Up @@ -2485,11 +2485,6 @@
resolved "https://registry.yarnpkg.com/@storefront-ui/shared/-/shared-0.10.2.tgz#144d3a7d5508563ad97c1882fbd291abb0166349"
integrity sha512-EWwct/pMYcXhMKGEE2h7blw0XIvcVokhzdzfl5VROSajtflJkJ11hfaOxFWkB5Zgd6IdS9iwR2ayzVjunVRuEA==

"@storefront-ui/shared@0.9.2":
version "0.9.2"
resolved "https://registry.yarnpkg.com/@storefront-ui/shared/-/shared-0.9.2.tgz#b50d6c8baec1a479054fd4a14b786f2809f0598e"
integrity sha512-2JX76IgwTrP/7Ksa5mF9+r1vlaZojKiqrPh9HCDo2yznnseqNOzKVgWn9vIRKxWqofMzmZeleNdriKfoulfFoQ==

"@storefront-ui/vue@0.10.3", "@storefront-ui/vue@^0.10.3":
version "0.10.3"
resolved "https://registry.yarnpkg.com/@storefront-ui/vue/-/vue-0.10.3.tgz#949b69a0888f85aa0f17fcdaf396972e5c210016"
Expand All @@ -2509,25 +2504,6 @@
vue-fragment "^1.5.1"
vue2-leaflet "^2.5.2"

"@storefront-ui/vue@0.9.2":
version "0.9.2"
resolved "https://registry.yarnpkg.com/@storefront-ui/vue/-/vue-0.9.2.tgz#56593b1cbfe62a5e03c965b5ccc2320edabbf504"
integrity sha512-yHaXY14fswtie4ULw64hbI8HGQ8wGOCdaGvZ1nwkcai0JJtCqLw7VWzCy0kPobZPXzc1fCFTt2KEUBbqPI342A==
dependencies:
"@glidejs/glide" "^3.3.0"
"@storefront-ui/shared" "0.9.2"
body-scroll-lock "^3.0.1"
core-js "^3.6.5"
hammerjs "^2.0.8"
leaflet "^1.5.1"
lozad "^1.14.0"
node-sass "^4.13.1"
sass-loader "^8.0.2"
simplebar-vue "^1.4.0"
vue-drag-drop "^1.1.4"
vue-fragment "^1.5.1"
vue2-leaflet "^2.5.2"

"@szmarczak/http-timer@^1.1.2":
version "1.1.2"
resolved "https://registry.yarnpkg.com/@szmarczak/http-timer/-/http-timer-1.1.2.tgz#b1665e2c461a2cd92f4c1bbf50d5454de0d4b421"
Expand Down Expand Up @@ -3015,92 +2991,6 @@
resolved "https://registry.yarnpkg.com/@ungap/global-this/-/global-this-0.4.4.tgz#8a1b2cfcd3e26e079a847daba879308c924dd695"
integrity sha512-mHkm6FvepJECMNthFuIgpAEFmPOk71UyXuIxYfjytvFTnSDBIz7jmViO+LfHI/AjrazWije0PnSP3+/NlwzqtA==

"@vue-storefront/commercetools-api@^1.1.7":
version "1.1.7"
resolved "https://registry.yarnpkg.com/@vue-storefront/commercetools-api/-/commercetools-api-1.1.7.tgz#deeb78597e65b7da299d953408a3d725ce95967a"
integrity sha512-0Idke1vVvNrLZ+UKjMXgQgnatH9QwX7p7vaGeuKVsBNu31q+WyU5y+NXI1VGol735i2uWeBJNfqrfPAcf08+lQ==
dependencies:
"@apollo/client" "^3.2.9"
"@commercetools/sdk-auth" "^3.0.1"
"@vue-storefront/core" "^2.2.3"
apollo-cache-inmemory "^1.6.6"
apollo-client "^2.6.10"
apollo-link "^1.2.14"
apollo-link-context "^1.0.20"
apollo-link-error "^1.1.13"
apollo-link-http "^1.5.17"
apollo-link-retry "^2.2.16"
graphql "^14.5.8"
graphql-tag "^2.10.1"
isomorphic-fetch "^2.2.1"

"@vue-storefront/commercetools-theme@./packages/commercetools/theme":
version "1.2.0-rc.2"
dependencies:
"@nuxtjs/pwa" "^3.2.2"
"@storefront-ui/vue" "0.10.3"
"@vue-storefront/commercetools" "^1.2.0-rc.2"
"@vue-storefront/middleware" "^2.3.0-rc.2"
"@vue-storefront/nuxt" "^2.3.0-rc.2"
"@vue-storefront/nuxt-theme" "^2.3.0-rc.2"
cookie-universal-nuxt "^2.1.3"
core-js "^2.6.5"
nuxt "^2.13.3"
nuxt-i18n "^6.5.0"
vee-validate "^3.2.3"
vue-scrollto "^2.17.1"

"@vue-storefront/commercetools@^1.1.1":
version "1.1.7"
resolved "https://registry.yarnpkg.com/@vue-storefront/commercetools/-/commercetools-1.1.7.tgz#6da3a6c0f017843c0e0ecdbb7b2a1a6e556155ce"
integrity sha512-skw2iVG6xtdYedeZ9GbSC7Y0w8pfE9n/YHVo3CM3k4QDx3y3OBeixf3ZMgxwmc2gYm8tZMNvWhNoB2QQ+vkozg==
dependencies:
"@vue-storefront/commercetools-api" "^1.1.7"
"@vue-storefront/core" "^2.2.3"
js-cookie "^2.2.1"
vue "^2.6.x"

"@vue-storefront/core@^2.2.3":
version "2.2.3"
resolved "https://registry.yarnpkg.com/@vue-storefront/core/-/core-2.2.3.tgz#08b215fd3101d56ae3377d28ad80c92cfc9f4b8e"
integrity sha512-EQnVcNJb+LpSV03gLkNzO6Pr5qjDmeIEo0Br4LdXBGMBj7a0kov2X7zrgf59WoVYl/bnYhQeCzi+Ikuuq87Bjg==
dependencies:
"@vue/composition-api" "1.0.0-beta.21"
express "^4.17.1"
lodash-es "^4.17.15"
vue "^2.6.11"

"@vue-storefront/nuxt-theme@./packages/core/nuxt-theme-module":
version "2.3.0-rc.2"
dependencies:
ejs "^3.0.2"
lodash.debounce "^4.0.8"
lodash.merge "^4.6.2"
vue-lazy-hydration "^2.0.0-beta.4"

"@vue-storefront/nuxt-theme@^2.2.1":
version "2.2.3"
resolved "https://registry.yarnpkg.com/@vue-storefront/nuxt-theme/-/nuxt-theme-2.2.3.tgz#7a4f5555b051296bf58fd78c5b95501ffb98beaf"
integrity sha512-1zR8L1PvO0bkGQJDe3Nfo+yz20MrYVS4g8B6I74vboFRtsKbKw7LkStmVWSs0dpx9mSRlVmBSmjPfFMMJcPShQ==
dependencies:
lodash.merge "^4.6.2"
vue-lazy-hydration "^2.0.0-beta.4"

"@vue-storefront/nuxt@^2.2.1":
version "2.2.3"
resolved "https://registry.yarnpkg.com/@vue-storefront/nuxt/-/nuxt-2.2.3.tgz#f1420204b293fad16a41bf4a6001c339e906e356"
integrity sha512-1JmHULb+cDhHpLHN6iKZKyAs9+sFhzekluHaBAFbCznSkt43RA69apRnNt8vBQsEYwqbXWcRdi9XgrLyDlKtpQ==
dependencies:
"@nuxt/typescript-build" "^2.0.0"
"@nuxtjs/composition-api" "0.17.0"
"@nuxtjs/style-resources" "^1.0.0"
"@vue/composition-api" "1.0.0-beta.21"
chalk "^2.4.2"
chokidar "^3.3.1"
consola "^2.10.1"
lodash "^4.17.15"
nuxt-purgecss "^1.0.0"

"@vue/babel-helper-vue-jsx-merge-props@^1.2.1":
version "1.2.1"
resolved "https://registry.yarnpkg.com/@vue/babel-helper-vue-jsx-merge-props/-/babel-helper-vue-jsx-merge-props-1.2.1.tgz#31624a7a505fb14da1d58023725a4c5f270e6a81"
Expand Down Expand Up @@ -6830,7 +6720,7 @@ err-code@^1.0.0:
resolved "https://registry.yarnpkg.com/err-code/-/err-code-1.1.2.tgz#06e0116d3028f6aef4806849eb0ea6a748ae6960"
integrity sha1-BuARbTAo9q70gGhJ6w6mp0iuaWA=

errno@^0.1.3:
errno@^0.1.3, errno@~0.1.7:
version "0.1.8"
resolved "https://registry.yarnpkg.com/errno/-/errno-0.1.8.tgz#8bb3e9c7d463be4976ff888f76b4809ebc2e811f"
integrity sha512-dJ6oBr5SQ1VSd9qkk7ByRgb/1SH4JZjCHSW/mr63/QcXO9zLVxvJ6Oy13nio03rxpSnVDDjFor75SjVeZWPW/A==
Expand Down Expand Up @@ -10852,11 +10742,6 @@ lowercase-keys@^2.0.0:
resolved "https://registry.yarnpkg.com/lowercase-keys/-/lowercase-keys-2.0.0.tgz#2603e78b7b4b0006cbca2fbcc8a3202558ac9479"
integrity sha512-tqNXrS78oMOE73NMxK4EMLQsQowWf8jKooH9g7xPavRT706R6bkQJ6DY2Te7QukaZsulxa30wQ7bk0pm4XiHmA==

lozad@^1.14.0:
version "1.16.0"
resolved "https://registry.yarnpkg.com/lozad/-/lozad-1.16.0.tgz#86ce732c64c69926ccdebb81c8c90bb3735948b4"
integrity sha512-JBr9WjvEFeKoyim3svo/gsQPTkgG/mOHJmDctZ/+U9H3ymUuvEkqpn8bdQMFsvTMcyRJrdJkLv0bXqGm0sP72w==

lru-cache@^4.0.1, lru-cache@^4.1.2, lru-cache@^4.1.5:
version "4.1.5"
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-4.1.5.tgz#8bbe50ea85bed59bc9e33dcab8235ee9bcf443cd"
Expand Down

0 comments on commit bc938cc

Please sign in to comment.