Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[XM Cloud Proxy] API /api/editing/render endpoint #1908

Merged
merged 44 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
acb2953
Initial changes
illiakovalenko Aug 22, 2024
196919c
Merge branch 'feature/jss-3541' into feature/jss-3528
yavorsk Aug 22, 2024
8f35003
Update
illiakovalenko Aug 22, 2024
6becaae
Added unit tests chunk
illiakovalenko Aug 22, 2024
926670b
Update
illiakovalenko Aug 22, 2024
87658dd
Updated unit test
illiakovalenko Aug 22, 2024
6ec93ca
Updated CHANGELOG, UPGRADE_GUIDE
illiakovalenko Aug 22, 2024
e93eeda
Merge branch 'dev' of https://github.com/Sitecore/jss into feature/JS…
illiakovalenko Aug 22, 2024
63501a2
Updated lock file
illiakovalenko Aug 22, 2024
a4d677f
Updated unit tests
illiakovalenko Aug 22, 2024
f6dd5c6
Fixed lint step
illiakovalenko Aug 22, 2024
de55f36
initial commit - wip
yavorsk Aug 23, 2024
8fe0556
Merge branch 'feature/jss-3541' into feature/jss-3528
yavorsk Aug 23, 2024
692db32
fix render config call
yavorsk Aug 23, 2024
3586769
move MetadataQueryParams model to base; update render middleware
yavorsk Aug 23, 2024
37b3e46
unit tests wip
yavorsk Aug 23, 2024
a27e0e8
minor updates
yavorsk Aug 23, 2024
03acf72
Merge branch 'dev' of https://github.com/Sitecore/jss into feature/js…
illiakovalenko Aug 26, 2024
802b9bd
pass layout kind to grapqhl request
apathania22 Aug 26, 2024
8ea475b
update changelog
apathania22 Aug 26, 2024
c266155
refactor
apathania22 Aug 27, 2024
048da12
resolve merge conflicts
apathania22 Aug 27, 2024
900d960
remove only
apathania22 Aug 27, 2024
b2ebb9f
Refactoring and updates
illiakovalenko Aug 27, 2024
649cf83
Moved MetadataQueryParams to Editing models
illiakovalenko Aug 27, 2024
53a4f1b
Merge branch 'feature/jss-3978-layout-kind' of https://github.com/Sit…
illiakovalenko Aug 27, 2024
42ddeef
Updated RenderMetadataQueryParams to include sc_layoutKind property
illiakovalenko Aug 27, 2024
4f49551
Reverted back LayoutKind
illiakovalenko Aug 27, 2024
b97b002
Updated UT
illiakovalenko Aug 27, 2024
1837d9d
Remove apiKey, siteName from server.exports in xmcloud addon
illiakovalenko Aug 27, 2024
7fdce85
Updated response
illiakovalenko Aug 27, 2024
dbb64de
Update CHANGELOG.md
addy-pathania Aug 27, 2024
aae85a3
Update packages/sitecore-jss/src/editing/graphql-editing-service.ts
addy-pathania Aug 27, 2024
a6ae9f9
Update packages/sitecore-jss/src/editing/graphql-editing-service.ts
addy-pathania Aug 27, 2024
f4ddba6
Quick change
illiakovalenko Aug 27, 2024
f66926f
Updated CHANGELOG
illiakovalenko Aug 27, 2024
318cc20
resolve review comments
apathania22 Aug 27, 2024
7138f5a
Update CHANGELOG.md
addy-pathania Aug 27, 2024
2aba3c2
Merge branch 'feature/jss-3978-layout-kind' of https://github.com/Sit…
illiakovalenko Aug 27, 2024
2c92103
Merge branch 'dev' of https://github.com/Sitecore/jss into feature/js…
illiakovalenko Aug 27, 2024
dfe0ce3
Extra line
illiakovalenko Aug 27, 2024
d0731c9
remove duplicate import
yavorsk Aug 28, 2024
c3afdc3
Updated unit tests
illiakovalenko Aug 28, 2024
c89c079
Merge branch 'feature/jss-3528' of https://github.com/Sitecore/jss in…
illiakovalenko Aug 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ Our versioning strategy is as follows:
* `[create-sitecore-jss]` Rework Angular initializer to support XMCloud and SXP journeys ([#1845](https://github.com/Sitecore/jss/pull/1845))([#1858](https://github.com/Sitecore/jss/pull/1858))([#1868](https://github.com/Sitecore/jss/pull/1868))([#1881](https://github.com/Sitecore/jss/pull/1881))([#1882](https://github.com/Sitecore/jss/pull/1882))
* `[create-sitecore-jss]` Allow node-xmcloud-proxy app to be installed alongside Angular SPA application
* `proxyAppDestination` arg can be passed into `create-sitecore-jss` command to define path for proxy to be installed in
* `[create-sitecore-jss]` `[template/angular]` `[template/angular-xmcloud]` `[template/node-xmcloud-proxy]` Introduced /api/editing/config endpoint ([#1903](https://github.com/Sitecore/jss/pull/1903))
* `[templates/angular]` `[templates/angular-xmcloud]` `[template/node-xmcloud-proxy]` `[sitecore-jss-proxy]` Introduced /api/editing/config endpoint ([#1903](https://github.com/Sitecore/jss/pull/1903))
* `[templates/angular]` `[templates/angular-xmcloud]` `[template/node-xmcloud-proxy]` `[sitecore-jss-proxy]` Introduced /api/editing/render endpoint ([#1908](https://github.com/Sitecore/jss/pull/1908))
* `[create-sitecore-jss]``[sitecore-jss-angular]``[template/angular-xmcloud]` Angular SXA components
* Angular placeholder now supports SXA components ([#1870](https://github.com/Sitecore/jss/pull/1870))
* Title component ([#1904](https://github.com/Sitecore/jss/pull/1904))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,10 @@ import metadata from './src/environments/metadata.json';
* Define the required configuration values to be exported from the server.bundle.ts.
*/

const apiKey = environment.sitecoreApiKey;
const siteName = environment.sitecoreSiteName;
const defaultLanguage = environment.defaultLanguage;
const getClientFactoryConfig = getGraphQLClientFactoryConfig;

export {
apiKey,
siteName,
clientFactory,
getClientFactoryConfig,
dictionaryServiceFactory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const requiredProperties = [
'parseRouteUrl',
'clientFactory',
'getClientFactoryConfig',
'siteName',
'defaultLanguage',
'layoutServiceFactory',
'dictionaryServiceFactory',
Expand All @@ -41,12 +40,16 @@ if (missingProperties.length > 0) {
);
}

const layoutService = layoutServiceFactory.create();

const dictionaryService = dictionaryServiceFactory.create();

const clientFactoryConfig = config.serverBundle.getClientFactoryConfig();

/**
* GraphQL endpoint resolution to meet the requirements of the http-proxy-middleware
*/
const graphQLEndpoint = (() => {
const clientFactoryConfig = config.serverBundle.getClientFactoryConfig();

try {
const graphQLEndpoint = new URL(clientFactoryConfig.endpoint);
// Browser request path to the proxy. Includes only the pathname.
Expand All @@ -66,10 +69,6 @@ const graphQLEndpoint = (() => {
}
})();

const layoutService = layoutServiceFactory.create();

const dictionaryService = dictionaryServiceFactory.create();

/**
* Parse requested url in order to detect current route and language
* @param {string} reqRoute requested route
Expand Down Expand Up @@ -138,6 +137,10 @@ server.use(
components: config.serverBundle.components,
metadata: config.serverBundle.metadata,
},
render: {
clientFactory: config.serverBundle.clientFactory,
renderView,
},
})
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export interface ServerBundle {
parseRouteUrl: RouteUrlParser;
clientFactory: GraphQLRequestClientFactory;
getClientFactoryConfig: () => GraphQLRequestClientFactoryConfig;
siteName: string;
defaultLanguage: string;
layoutServiceFactory: { create: () => LayoutService };
dictionaryServiceFactory: { create: () => DictionaryService };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { EditingDataService, EditingPreviewData } from './editing-data-service';
import {
EDITING_ALLOWED_ORIGINS,
QUERY_PARAM_EDITING_SECRET,
RenderMetadataQueryParams,
} from '@sitecore-jss/sitecore-jss/editing';
import {
QUERY_PARAM_VERCEL_PROTECTION_BYPASS,
Expand All @@ -17,7 +18,6 @@ import { EE_PATH, EE_LANGUAGE, EE_LAYOUT, EE_DICTIONARY, EE_BODY } from '../test
import {
ChromesHandler,
EditingRenderMiddleware,
MetadataQueryParams,
isEditingMetadataPreviewData,
} from './editing-render-middleware';
import { spy, match } from 'sinon';
Expand All @@ -38,7 +38,7 @@ const allowedOrigin = 'https://allowed.com';

const mockRequest = (
body?: any,
query?: Query | MetadataQueryParams,
query?: Query | RenderMetadataQueryParams,
method?: string,
headers?: { [key: string]: string }
) => {
Expand Down Expand Up @@ -182,7 +182,7 @@ describe('EditingRenderMiddleware', () => {
sc_version: 'latest',
secret: secret,
sc_layoutKind: 'shared',
} as MetadataQueryParams;
} as RenderMetadataQueryParams;

it('should handle request', async () => {
const req = mockRequest(EE_BODY, query, 'GET');
Expand Down Expand Up @@ -221,7 +221,7 @@ describe('EditingRenderMiddleware', () => {
sc_site: 'website',
secret: secret,
sc_variant: 'id-1,id-2,id-3',
} as MetadataQueryParams;
} as RenderMetadataQueryParams;

const req = mockRequest(EE_BODY, query, 'GET');
const res = mockResponse();
Expand Down Expand Up @@ -251,7 +251,7 @@ describe('EditingRenderMiddleware', () => {
sc_lang: 'en',
sc_site: 'website',
secret: secret,
} as MetadataQueryParams;
} as RenderMetadataQueryParams;
const req = mockRequest(EE_BODY, queryWithoutOptionalParams, 'GET');
const res = mockResponse();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { LayoutKind } from '@sitecore-jss/sitecore-jss/editing';
import {
QUERY_PARAM_EDITING_SECRET,
EDITING_ALLOWED_ORIGINS,
RenderMetadataQueryParams,
LayoutKind,
} from '@sitecore-jss/sitecore-jss/editing';
import { EditingData } from './editing-data';
import { EditingDataService, editingDataService } from './editing-data-service';
Expand Down Expand Up @@ -265,27 +267,11 @@ export type EditingRenderMiddlewareMetadataConfig = Pick<
'resolvePageUrl'
>;

/**
* Query parameters appended to the page route URL
* Appended when XMCloud Pages preview (editing) Metadata Edit Mode is used
*/
export type MetadataQueryParams = {
secret: string;
sc_lang: string;
sc_itemid: string;
sc_site: string;
route: string;
mode: Exclude<LayoutServicePageState, 'normal'>;
sc_variant?: string;
sc_version?: string;
sc_layoutKind?: LayoutKind;
};

/**
* Next.js API request with Metadata query parameters.
*/
type MetadataNextApiRequest = NextApiRequest & {
query: MetadataQueryParams;
query: RenderMetadataQueryParams;
};

/**
Expand Down Expand Up @@ -330,7 +316,7 @@ export class MetadataHandler {

const startTimestamp = Date.now();

const requiredQueryParams: (keyof MetadataQueryParams)[] = [
const requiredQueryParams: (keyof RenderMetadataQueryParams)[] = [
'sc_site',
'sc_itemid',
'sc_lang',
Expand Down
4 changes: 3 additions & 1 deletion packages/sitecore-jss-proxy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"build": "npm run clean && tsc -p tsconfig.json && tsc -p tsconfig-esm.json",
"clean": "del-cli dist types",
"lint": "eslint \"./src/**/*.ts\"",
"test": "mocha --require ts-node/register \"./src/**/*.test.ts\"",
"test": "mocha --require ts-node/register \"./src/**/*.test.ts\" --exit",
"prepublishOnly": "npm run build",
"coverage": "nyc npm test",
"generate-docs": "npx typedoc --plugin typedoc-plugin-markdown --readme none --out ../../ref-docs/sitecore-jss-proxy src/index.ts --githubPages false"
Expand Down Expand Up @@ -38,13 +38,15 @@
"@types/mocha": "^10.0.1",
"@types/node": "^20.14.2",
"@types/set-cookie-parser": "^2.4.2",
"@types/sinon": "^17.0.3",
"@types/supertest": "^6.0.2",
"chai": "^4.3.7",
"del-cli": "^5.0.0",
"eslint": "^8.33.0",
"express": "^4.19.2",
"mocha": "^10.2.0",
"nyc": "^15.1.0",
"sinon": "^17.0.1",
"supertest": "^7.0.0",
"ts-node": "^10.9.1",
"typescript": "~4.9.5"
Expand Down
4 changes: 2 additions & 2 deletions packages/sitecore-jss-proxy/src/middleware/editing/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Request, RequestHandler, Response } from 'express';
import { Request, Response } from 'express';
import { debug } from '@sitecore-jss/sitecore-jss';
import { EditMode } from '@sitecore-jss/sitecore-jss/layout';
import { Metadata } from '@sitecore-jss/sitecore-jss/utils';
Expand Down Expand Up @@ -28,7 +28,7 @@ export type EditingConfigEndpointOptions = {
* @param {EditingConfigEndpointOptions} config Configuration for the endpoint
* @returns {RequestHandler} Middleware function
*/
export const editingConfigMiddleware = (config: EditingConfigEndpointOptions): RequestHandler => (
export const editingConfigMiddleware = (config: EditingConfigEndpointOptions) => (
illiakovalenko marked this conversation as resolved.
Show resolved Hide resolved
_req: Request,
res: Response
): void => {
Expand Down
Loading