Skip to content

Commit

Permalink
Merge branch 'develop-6.5.x' into epic/opf
Browse files Browse the repository at this point in the history
  • Loading branch information
FollowTheFlo committed Sep 27, 2023
2 parents a1c0cb6 + 0dd42d4 commit 25c7469
Show file tree
Hide file tree
Showing 228 changed files with 7,888 additions and 1,200 deletions.
7 changes: 6 additions & 1 deletion .env-cmdrc
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,15 @@
"CX_BASE_URL": "https://api.cg79x9wuu9-eccommerc1-s8-public.model-t.myhybris.cloud",
"CX_B2B": "true",
"CX_S4OM": "true",
"CX_REQUESTED_DELIVERY_DATE": "true"
"CX_REQUESTED_DELIVERY_DATE": "true",
"CX_PDF_INVOICES": "true"
},
"requested-delivery-date": {
"CX_BASE_URL": "https://api.cg79x9wuu9-eccommerc1-s8-public.model-t.myhybris.cloud",
"CX_REQUESTED_DELIVERY_DATE": "true"
},
"pdf-invoices": {
"CX_BASE_URL": "https://api.cg79x9wuu9-eccommerc1-s5-public.model-t.myhybris.cloud",
"CX_PDF_INVOICES": "true"
}
}
2 changes: 1 addition & 1 deletion .github/workflows/cache-node-modules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
name: Cache node modules

env:
NODE_VERSION: '16'
NODE_VERSION: '18'

jobs:
cacheNodeModules:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
# empty as it is used only to manually trigger the workflow

env:
NODE_VERSION: '16'
NODE_VERSION: '18'
NX_BASE: origin/${{ github.event.pull_request.base.ref }}
NX_HEAD: origin/${{ github.event.pull_request.head.ref }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-merge-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
env:
CYPRESS_KEY: ${{ secrets.CYPRESS_KEY }}
GH_TOKEN: ${{ github.token }}
NODE_VERSION: '16'
NODE_VERSION: '18'

concurrency:
group: ci-merge-checks-${{ github.head_ref || github.run_id }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:

env:
CYPRESS_KEY: ${{ secrets.CYPRESS_KEY }}
NODE_VERSION: '16'
NODE_VERSION: '18'

concurrency:
group: ci-${{ github.head_ref || github.run_id }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lighthouse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
# empty as it is used only to manually trigger the workflow
env:
CYPRESS_KEY: ${{ secrets.CYPRESS_KEY }}
NODE_VERSION: '16'
NODE_VERSION: '18'

concurrency:
group: lighthouse-${{ github.head_ref || github.run_id }}
Expand Down
2 changes: 2 additions & 0 deletions ci-scripts/e2e-cypress.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ fi
echo '-----'
echo "Building Spartacus libraries"

export NODE_OPTIONS=--dns-result-order=ipv4first

npm ci

(cd projects/storefrontapp-e2e-cypress && npm ci)
Expand Down
1 change: 1 addition & 0 deletions ci-scripts/lhci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
set -e

export SPA_ENV='lighthouse'
export NODE_OPTIONS=--dns-result-order=ipv4first

npm install -g @lhci/[email protected]

Expand Down
16 changes: 8 additions & 8 deletions core-libs/setup/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@spartacus/setup",
"version": "6.3.0-1",
"version": "6.5.0-1",
"description": "Includes features that makes Spartacus and it's setup easier and streamlined.",
"keywords": [
"spartacus",
Expand All @@ -16,17 +16,17 @@
"test": "../../node_modules/.bin/jest --config ./jest.config.js"
},
"dependencies": {
"tslib": "^2.4.0"
"tslib": "^2.6.2"
},
"peerDependencies": {
"@angular/core": "^15.2.4",
"@spartacus/cart": "6.3.0-1",
"@spartacus/core": "6.3.0-1",
"@spartacus/order": "6.3.0-1",
"@spartacus/user": "6.3.0-1"
"@angular/core": "^15.2.9",
"@spartacus/cart": "6.5.0-1",
"@spartacus/core": "6.5.0-1",
"@spartacus/order": "6.5.0-1",
"@spartacus/user": "6.5.0-1"
},
"optionalDependencies": {
"@angular/platform-server": "^15.2.4",
"@angular/platform-server": "^15.2.9",
"@nguniversal/express-engine": "^15.2.0",
"express": "^4.18.2"
},
Expand Down
2 changes: 2 additions & 0 deletions core-libs/setup/ssr/optimized-engine/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@
export * from './optimized-ssr-engine';
export * from './rendering-cache';
export * from './ssr-optimization-options';
export * from './rendering-strategy-resolver';
export * from './rendering-strategy-resolver-options';
37 changes: 22 additions & 15 deletions core-libs/setup/ssr/optimized-engine/optimized-ssr-engine.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,7 @@ describe('OptimizedSsrEngine', () => {
"maxRenderTime": 300000,
"reuseCurrentRendering": true,
"debug": false,
"renderingStrategyResolver": "(request) => {\\n return shouldFallbackToCsr(request, options)\\n ? ssr_optimization_options_1.RenderingStrategy.ALWAYS_CSR\\n : ssr_optimization_options_1.RenderingStrategy.DEFAULT;\\n}",
"logger": true
}
}
Expand All @@ -1206,20 +1207,25 @@ describe('OptimizedSsrEngine', () => {
logger: new MockExpressServerLogger() as ExpressServerLogger,
});
expect(consoleLogSpy.mock.lastCall).toMatchInlineSnapshot(`
[
"[spartacus] SSR optimization engine initialized",
{
"options": {
"concurrency": 10,
"debug": false,
"forcedSsrTimeout": 60000,
"logger": "MockExpressServerLogger",
"maxRenderTime": 300000,
"reuseCurrentRendering": true,
"timeout": 3000,
},
},
]
[
"[spartacus] SSR optimization engine initialized",
{
"options": {
"concurrency": 10,
"debug": false,
"forcedSsrTimeout": 60000,
"logger": "MockExpressServerLogger",
"maxRenderTime": 300000,
"renderingStrategyResolver": "(request) => {
return shouldFallbackToCsr(request, options)
? ssr_optimization_options_1.RenderingStrategy.ALWAYS_CSR
: ssr_optimization_options_1.RenderingStrategy.DEFAULT;
}",
"reuseCurrentRendering": true,
"timeout": 3000,
},
},
]
`);
});
it('should use the legacy server logger, if logger option not specified', () => {
Expand All @@ -1232,7 +1238,8 @@ describe('OptimizedSsrEngine', () => {
"forcedSsrTimeout": 60000,
"maxRenderTime": 300000,
"reuseCurrentRendering": true,
"debug": false
"debug": false,
"renderingStrategyResolver": "(request) => {\\n return shouldFallbackToCsr(request, options)\\n ? ssr_optimization_options_1.RenderingStrategy.ALWAYS_CSR\\n : ssr_optimization_options_1.RenderingStrategy.DEFAULT;\\n}"
}",
]
`);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* SPDX-FileCopyrightText: 2023 SAP Spartacus team <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

export interface RenderingStrategyResolverOptions {
excludedUrls?: string[];
excludedParams?: string[];
}

export const defaultRenderingStrategyResolverOptions: RenderingStrategyResolverOptions =
{
excludedUrls: ['checkout', 'my-account', 'cx-preview'],
excludedParams: ['asm'],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/// <reference types="jest" />

import { RenderingStrategy } from './ssr-optimization-options';
import { Request } from 'express';

import { defaultRenderingStrategyResolver } from './rendering-strategy-resolver';

describe('RenderingStrategyResolver', () => {
let resolver: (req: Request) => RenderingStrategy =
defaultRenderingStrategyResolver({
excludedUrls: ['checkout', 'my-account'],
excludedParams: ['asm'],
});

it('should return DEFAULT rendering strategy if no excluded parameters or URLs match', () => {
const request: Partial<Request> = {
query: {},
url: '/some-page',
};

const strategy = resolver(request as Request);

expect(strategy).toBe(RenderingStrategy.DEFAULT);
});

it('should return ALWAYS_CSR rendering strategy if an excluded parameter matches', () => {
const request: Partial<Request> = {
query: {
asm: 'true',
},
url: '/some-page',
};

const strategy = resolver(request as Request);

expect(strategy).toBe(RenderingStrategy.ALWAYS_CSR);
});

it('should return ALWAYS_CSR rendering strategy if the URL matches an excluded URL', () => {
const request: Partial<Request> = {
query: {},
url: '/checkout/confirm',
};

const strategy = resolver(request as Request);

expect(strategy).toBe(RenderingStrategy.ALWAYS_CSR);
});

it('should return ALWAYS_CSR rendering strategy if both excluded parameters and URLs match', () => {
const request: Partial<Request> = {
query: {
asm: 'true',
},
url: '/checkout/confirm',
};

const strategy = resolver(request as Request);

expect(strategy).toBe(RenderingStrategy.ALWAYS_CSR);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* SPDX-FileCopyrightText: 2023 SAP Spartacus team <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

import { Request } from 'express';
import { RenderingStrategy } from './ssr-optimization-options';
import { RenderingStrategyResolverOptions } from './rendering-strategy-resolver-options';

const hasExcludedParams = (
request: Request,
excludedParams: string[] | undefined
): boolean => {
const params: string[] = request.query
? Object.getOwnPropertyNames(request.query)
: [];

if (!excludedParams) {
return false;
}

return excludedParams.some((excludedParam: string) =>
params.some((param: string): boolean => excludedParam === param)
);
};

const hasExcludedUrl = (
request: Request,
excludedUrls: string[] | undefined
) => {
return request.url && excludedUrls
? excludedUrls.some((url) => request.url.search(url) > -1)
: false;
};

const shouldFallbackToCsr = (
request: Request,
{ excludedParams, excludedUrls }: RenderingStrategyResolverOptions
) => {
return (
hasExcludedParams(request, excludedParams) ||
hasExcludedUrl(request, excludedUrls)
);
};

/**
* Creates a rendering strategy resolver function with the specified options.
*
* @function
* @param options - The options to configure the rendering strategy resolver.
* @param [options.excludedUrls] - An optional array of URLs for which server-side rendering (SSR) should be disabled.
* @param [options.excludedParams] - An optional array of Query parameters for which SSR should be disabled.
* @returns A rendering strategy resolver function that takes a Request object
* as a parameter and returns the rendering strategy to be applied for the request, which can be either
* `RenderingStrategy.ALWAYS_CSR` or `RenderingStrategy.DEFAULT`.
*/
export const defaultRenderingStrategyResolver =
(options: RenderingStrategyResolverOptions) =>
(request: Request): RenderingStrategy => {
return shouldFallbackToCsr(request, options)
? RenderingStrategy.ALWAYS_CSR
: RenderingStrategy.DEFAULT;
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import { Request } from 'express';
import { ExpressServerLogger } from '../logger';
import { defaultRenderingStrategyResolver } from './rendering-strategy-resolver';
import { defaultRenderingStrategyResolverOptions } from './rendering-strategy-resolver-options';

export interface SsrOptimizationOptions {
/**
Expand Down Expand Up @@ -54,7 +56,10 @@ export interface SsrOptimizationOptions {
renderKeyResolver?: (req: Request) => string;

/**
* Allows defining custom rendering strategy per request
* This function allows for the definition of a custom rendering strategy on a per-request basis.
* By default, we provide a defaultRenderingStrategyResolver,
* which has a default parameter defaultRenderingStrategyResolverOptions.
* This default option disables server-side rendering (SSR) on pages such as 'checkout' and 'my-account'.
*
* @param req
*/
Expand Down Expand Up @@ -139,6 +144,9 @@ export const defaultSsrOptimizationOptions: SsrOptimizationOptions = {
maxRenderTime: 300_000,
reuseCurrentRendering: true,
debug: false,
renderingStrategyResolver: defaultRenderingStrategyResolver(
defaultRenderingStrategyResolverOptions
),
//CXSPA-3680 - set ExpressServerLogger as default
//logger: new ExpressServerLogger(),
};
16 changes: 16 additions & 0 deletions core-libs/setup/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,22 @@
"@spartacus/organization/user-registration/root": [
"../../feature-libs/organization/user-registration/root/public_api"
],
"@spartacus/pdf-invoices/assets": [
"../../feature-libs/pdf-invoices/assets/public_api"
],
"@spartacus/pdf-invoices/components": [
"../../feature-libs/pdf-invoices/components/public_api"
],
"@spartacus/pdf-invoices/core": [
"../../feature-libs/pdf-invoices/core/public_api"
],
"@spartacus/pdf-invoices": ["../../feature-libs/pdf-invoices/public_api"],
"@spartacus/pdf-invoices/occ": [
"../../feature-libs/pdf-invoices/occ/public_api"
],
"@spartacus/pdf-invoices/root": [
"../../feature-libs/pdf-invoices/root/public_api"
],
"@spartacus/pickup-in-store/assets": [
"../../feature-libs/pickup-in-store/assets/public_api"
],
Expand Down
Binary file removed docs/assets/github-branch-selector.png
Binary file not shown.
Loading

0 comments on commit 25c7469

Please sign in to comment.