Skip to content

Commit

Permalink
Merge branch 'main' into feat/UST-1087-nuxt-package
Browse files Browse the repository at this point in the history
  • Loading branch information
jagoral authored Dec 22, 2023
2 parents 5794dc1 + 0ce9506 commit 0417c90
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 35 deletions.
42 changes: 10 additions & 32 deletions docs/content/3.middleware/2.guides/4.orchestration.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
# Orchestration
# Data Integration and Orchestration

Orchestration is a powerful way to optimize server requests. This guide will take you through the key aspects of using the orchestration feature, focusing on integrating extensions and how to get the best out of your frontend code.
Optimizing server requests through data integration and orchestration is essential for frontend performance. This guide introduces the orchestration feature, highlighting its role in integrating extensions and streamlining frontend code.

## Orchestration for Frontend Optimization
## Enhancing Frontend Performance through Data Orchestration

One of the primary advantages of orchestration is the ability to combine multiple requests into a single endpoint. This can drastically reduce the overhead on the frontend, especially in applications where numerous server requests might be initiated simultaneously.
Data orchestration allows for consolidating multiple server requests into a single endpoint, which significantly eases the burden on the frontend. This is particularly beneficial in scenarios involving numerous simultaneous server requests.

### Benefits:

- Reduced Network Calls: Fewer calls to the server means reduced latency and faster performance.
- Simplified Frontend Logic: Grouping related server requests can help simplify frontend code and logic.
- Consistent Data Retrieval: With orchestration, you can ensure data from multiple integrations is fetched consistently and returned in a unified format.
### Advantages:
- **Minimized Network Traffic**: Fewer server calls lead to reduced latency and enhanced responsiveness.
- **Simplified Frontend Architecture**: By grouping related server requests, the frontend logic becomes less complex.
- **Uniform Data Collection**: Ensures that data fetched from different sources is consistent and provided in a standard format.

### Implementation:

Expand Down Expand Up @@ -84,30 +83,9 @@ To call the orchestration endpoint, you need to send a POST request to the endpo

When it comes to extending the Vue Storefront integrations like `sapcc` or `contentful`, you can use the SDK extension mechanism as described in the [Extending a Module](/sdk/advanced/extending-module) guide.

To extend the `sapcc-sdk` with our new `getPDP` method, we would need to create a new extension:

```javascript [sapccExtension.ts]
import { client } from "@vsf-enterprise/sapcc-sdk";

export const sapccExtension = {
extend: {
getPDP: async (params: { id: string }) => {
const { product, content } = await client.post("/getPDP", params);

return {
product,
content,
};
},
},
};
```

Of course, you can use another fetching mechanism, like `axios` or `fetch`, but the `client` is already configured with the correct URL and headers.

## Examples
## Real-World Examples

Let's take a look at some examples of how you can use orchestration.
The examples provided demonstrate practical uses of data orchestration:

### Example 1: Fetching Custom Product Properties from Legacy Systems

Expand Down
1 change: 1 addition & 0 deletions docs/content/enterprise/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The Enterprise license offers everything available in our open-source projects,

::list{type="success"}
- [**Vue Storefront Cloud**](/cloud) infrastructure optimized for performance and safety, which includes CDN, DDoS protection, and high SLA
- [**Vue Storefront Console**](/console) to manage your Vue Storefront Cloud projects
- Additional [**Integrations**](/integrations) with Enterprise-grade eCommerce platforms and third-party services
- **Technical Support and SLA** to ensure you're set for success
- and more...
Expand Down
8 changes: 7 additions & 1 deletion packages/middleware/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change log

## 3.6.2

### Patch Changes

- 6c769c7a8: Fix status code resolving for the apollo client

## 3.6.1

### Patch Changes
Expand Down Expand Up @@ -86,4 +92,4 @@ This release decoupled the middleware from the core.

### Chores

- stable release.
- stable release.
2 changes: 1 addition & 1 deletion packages/middleware/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vue-storefront/middleware",
"version": "3.6.1",
"version": "3.6.2",
"main": "lib/index.cjs.js",
"module": "lib/index.es.js",
"types": "lib/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/middleware/src/errors/defaultErrorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const defaultErrorHandler = (
consola.error(error);
const status = getAgnosticStatusCode(error);
res.status(status);
if (status >= 400 && status < 500) {
if (status < 500) {
/**
* For all 4xx error codes or client error codes we wanted to send the error message
*/
Expand Down
5 changes: 5 additions & 0 deletions packages/middleware/src/helpers/getAgnosticStatusCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ function getApolloStatusCode(error: ApolloError) {
if (error.code) {
return typeof error.code === "string" ? 400 : error.code;
}

if (error?.graphQLErrors?.length > 0) {
return 200;
}

return undefined;
}

Expand Down
1 change: 1 addition & 0 deletions packages/middleware/src/types/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export type AxiosError = {
export type ApolloError = {
networkError?: number;
code?: string | number;
graphQLErrors: Array<any>;
};

export type StatusCode = number | null;
Expand Down

0 comments on commit 0417c90

Please sign in to comment.