@vue-storefront/middleware
Advanced tools
Comparing version 2.3.0-rc.2 to 2.3.0-rc.3
@@ -92,3 +92,3 @@ 'use strict'; | ||
.reduce(function (prev, curr) { return __spreadArray(__spreadArray([], prev), lookUpExternal(curr)); }, []); }; | ||
var registerIntegrations = function (integrations) { | ||
var registerIntegrations = function (app, integrations) { | ||
return Object.entries(integrations).reduce(function (prev, _a) { | ||
@@ -102,4 +102,7 @@ var _b; | ||
extensions.forEach(function (_a) { | ||
var name = _a.name; | ||
var name = _a.name, extendApp = _a.extendApp; | ||
consola.info("- Loading: " + tag + " extension: " + name); | ||
if (extendApp) { | ||
extendApp(app); | ||
} | ||
}); | ||
@@ -124,6 +127,6 @@ consola.success("- Integration: " + tag + " loaded!"); | ||
consola.info('Loading integartions...'); | ||
var integrations = registerIntegrations(config.integrations); | ||
var integrations = registerIntegrations(app, config.integrations); | ||
consola.success('Integrations loaded!'); | ||
app.post('/:integrationName/:functionName', function (req, res) { return __awaiter(_this, void 0, void 0, function () { | ||
var _a, integrationName, functionName, _b, apiClient, configuration, extensions, customQueries, middlewareContext, createApiClient, apiClientInstance, apiFunction, platformResponse; | ||
var _a, integrationName, functionName, _b, apiClient, configuration, extensions, customQueries, middlewareContext, createApiClient, apiClientInstance, apiFunction, platformResponse, error_1; | ||
return __generator(this, function (_c) { | ||
@@ -138,7 +141,16 @@ switch (_c.label) { | ||
apiFunction = apiClientInstance.api[functionName]; | ||
_c.label = 1; | ||
case 1: | ||
_c.trys.push([1, 3, , 4]); | ||
return [4 /*yield*/, apiFunction.apply(void 0, req.body)]; | ||
case 1: | ||
case 2: | ||
platformResponse = _c.sent(); | ||
res.send(platformResponse); | ||
return [2 /*return*/]; | ||
return [3 /*break*/, 4]; | ||
case 3: | ||
error_1 = _c.sent(); | ||
res.status(500); | ||
res.send(error_1); | ||
return [3 /*break*/, 4]; | ||
case 4: return [2 /*return*/]; | ||
} | ||
@@ -145,0 +157,0 @@ }); |
@@ -86,3 +86,3 @@ import express from 'express'; | ||
.reduce(function (prev, curr) { return __spreadArray(__spreadArray([], prev), lookUpExternal(curr)); }, []); }; | ||
var registerIntegrations = function (integrations) { | ||
var registerIntegrations = function (app, integrations) { | ||
return Object.entries(integrations).reduce(function (prev, _a) { | ||
@@ -96,4 +96,7 @@ var _b; | ||
extensions.forEach(function (_a) { | ||
var name = _a.name; | ||
var name = _a.name, extendApp = _a.extendApp; | ||
consola.info("- Loading: " + tag + " extension: " + name); | ||
if (extendApp) { | ||
extendApp(app); | ||
} | ||
}); | ||
@@ -118,6 +121,6 @@ consola.success("- Integration: " + tag + " loaded!"); | ||
consola.info('Loading integartions...'); | ||
var integrations = registerIntegrations(config.integrations); | ||
var integrations = registerIntegrations(app, config.integrations); | ||
consola.success('Integrations loaded!'); | ||
app.post('/:integrationName/:functionName', function (req, res) { return __awaiter(_this, void 0, void 0, function () { | ||
var _a, integrationName, functionName, _b, apiClient, configuration, extensions, customQueries, middlewareContext, createApiClient, apiClientInstance, apiFunction, platformResponse; | ||
var _a, integrationName, functionName, _b, apiClient, configuration, extensions, customQueries, middlewareContext, createApiClient, apiClientInstance, apiFunction, platformResponse, error_1; | ||
return __generator(this, function (_c) { | ||
@@ -132,7 +135,16 @@ switch (_c.label) { | ||
apiFunction = apiClientInstance.api[functionName]; | ||
_c.label = 1; | ||
case 1: | ||
_c.trys.push([1, 3, , 4]); | ||
return [4 /*yield*/, apiFunction.apply(void 0, req.body)]; | ||
case 1: | ||
case 2: | ||
platformResponse = _c.sent(); | ||
res.send(platformResponse); | ||
return [2 /*return*/]; | ||
return [3 /*break*/, 4]; | ||
case 3: | ||
error_1 = _c.sent(); | ||
res.status(500); | ||
res.send(error_1); | ||
return [3 /*break*/, 4]; | ||
case 4: return [2 /*return*/]; | ||
} | ||
@@ -139,0 +151,0 @@ }); |
@@ -0,1 +1,2 @@ | ||
import { Express } from 'express'; | ||
import { ApiClientFactory, ApiClientExtension, IntegrationsSection, CustomQuery } from '@vue-storefront/core'; | ||
@@ -9,3 +10,3 @@ interface IntegrationLoaded { | ||
declare type IntegrationsLoaded = Record<string, IntegrationLoaded>; | ||
declare const registerIntegrations: (integrations: IntegrationsSection) => IntegrationsLoaded; | ||
declare const registerIntegrations: (app: Express, integrations: IntegrationsSection) => IntegrationsLoaded; | ||
export { registerIntegrations }; |
{ | ||
"name": "@vue-storefront/middleware", | ||
"version": "2.3.0-rc.2", | ||
"version": "2.3.0-rc.3", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.cjs.js", |
@@ -29,3 +29,3 @@ import express, { Request, Response, Express } from 'express'; | ||
const integrations = registerIntegrations(config.integrations); | ||
const integrations = registerIntegrations(app, config.integrations); | ||
@@ -41,5 +41,11 @@ consola.success('Integrations loaded!'); | ||
const apiFunction = apiClientInstance.api[functionName]; | ||
const platformResponse = await apiFunction(...req.body); | ||
try { | ||
const platformResponse = await apiFunction(...req.body); | ||
res.send(platformResponse); | ||
res.send(platformResponse); | ||
} catch (error) { | ||
res.status(500); | ||
res.send(error); | ||
} | ||
}); | ||
@@ -46,0 +52,0 @@ |
import consola from 'consola'; | ||
import { Express } from 'express'; | ||
import { | ||
@@ -14,3 +15,3 @@ Integration, | ||
extensions: ApiClientExtension[]; | ||
customQueries?: Record<string, CustomQuery>; | ||
customQueries?: Record<string, CustomQuery> | ||
} | ||
@@ -32,3 +33,3 @@ | ||
const registerIntegrations = (integrations: IntegrationsSection): IntegrationsLoaded => | ||
const registerIntegrations = (app: Express, integrations: IntegrationsSection): IntegrationsLoaded => | ||
Object.entries<Integration>(integrations).reduce((prev, [tag, integration]) => { | ||
@@ -41,4 +42,8 @@ consola.info(`- Loading: ${tag} ${integration.location}`); | ||
extensions.forEach(({ name }) => { | ||
extensions.forEach(({ name, extendApp }) => { | ||
consola.info(`- Loading: ${tag} extension: ${name}`); | ||
if (extendApp) { | ||
extendApp(app); | ||
} | ||
}); | ||
@@ -45,0 +50,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
35331
430