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

[Angular XMC Proxy] Extract SXP related things from the base Angular template #1838

Merged
merged 39 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
09862c1
move disconnected data to angular-sxp
yavorsk Jul 16, 2024
3b560f8
add bootstrap to angular-sxp; remove disconnected logic from bootstra…
yavorsk Jul 16, 2024
7816a60
move disconnected-mode-proxy
yavorsk Jul 16, 2024
d0996a4
move styleguide components to angular-xp
yavorsk Jul 16, 2024
6d75859
move/modify routing files for angular/angular-sxp
yavorsk Jul 16, 2024
044850e
move proxy.config to angular-sxp, copy and modify package json
yavorsk Jul 16, 2024
5633db5
add angular-sxp initializer
yavorsk Jul 17, 2024
ffce18c
update changelog
yavorsk Jul 17, 2024
b8df21b
add proxy config for the base angular template
yavorsk Jul 22, 2024
b3ddbdc
lint:yml script only for angular-sxp
yavorsk Jul 22, 2024
64e67a1
move lint-yml script to angular-sxp
yavorsk Jul 22, 2024
8a8eb8a
move entire sitecore folder under angular-sxp template
yavorsk Jul 22, 2024
9de7bb0
update readme
yavorsk Jul 22, 2024
9cedabe
introduce plugin functionality for angular addons
yavorsk Jul 23, 2024
5face19
move styleguide fragment types out of sngular base template
yavorsk Jul 23, 2024
4105f5a
move jss-data-fetcher.service.ts to angular-sxp addon
yavorsk Jul 23, 2024
d56ed91
reintroduce navigation component to base package and remove unnecesar…
yavorsk Jul 23, 2024
87bff57
update changelog
yavorsk Jul 23, 2024
f73f319
removed sitecoreLayoutServiceConfig config property; layoutServiceCo…
yavorsk Jul 23, 2024
8a1bd4b
update import
yavorsk Jul 23, 2024
0f45f02
use no manifest parameter for scaffold script in angular base template
yavorsk Jul 23, 2024
0944bc8
exstract scaffold script call from angular base to angular add ons
yavorsk Jul 23, 2024
25b2d19
update call to generateConfig
yavorsk Jul 24, 2024
34d3c4e
fix graphql-fragmentent-types location
yavorsk Jul 24, 2024
ebf8e7f
update to changelog entry
yavorsk Jul 24, 2024
00623a6
remove scaffold script from xmcloud add on and add it to base template
yavorsk Jul 24, 2024
08f4e01
fix jssconfig comment
yavorsk Jul 24, 2024
4e4e7e9
update readme link
yavorsk Jul 24, 2024
1dd105a
update base graphql introspection data
yavorsk Jul 24, 2024
090b24a
update navigation links
yavorsk Jul 24, 2024
c7684ab
generateConfig function now has default value for the defaultConfig p…
yavorsk Jul 24, 2024
18b23d2
Merge branch 'feature/angular-xmc-proxy' into feature/jss-3538
yavorsk Jul 25, 2024
fd01056
move rest services to base template and conditionaly render them in t…
yavorsk Jul 25, 2024
c9de496
Moved "src/lib/config" -> "src/app/lib/config"
illiakovalenko Jul 25, 2024
f4b6d64
Conditionally applied "layoutServiceConfigurationName" config property
illiakovalenko Jul 25, 2024
5b23ce6
Renamed "client-factory" -> "graphql-client-factory"
illiakovalenko Jul 25, 2024
b3450f8
De-composed modules, added Scripts component
illiakovalenko Jul 25, 2024
f112c16
Cleaned up extra dependencies
illiakovalenko Jul 25, 2024
1074f08
Applied updates related to review comments
illiakovalenko Jul 26, 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
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ Our versioning strategy is as follows:

### 🎉 New Features & Improvements

### 🛠 Breaking Change
* `[create-sitecore-jss]` `[template/angular]` `[template/angular-sxp]` `[template/angular-xmcloud]` Introduced "angular-sxp", "angular-xmcloud" addons ([#1838](https://github.com/Sitecore/jss/pull/1838))([#1845](https://github.com/Sitecore/jss/pull/1845)):
* The Angular app should now be initialized by providing both templates (or using CLI prompts):
* SXP-based: 'angular,angular-sxp'
* XMCloud-based: 'angular,angular-xmcloud'
* Rework Angular initializer to support XMCloud and SXP journeys;

* `[create-sitecore-jss]` Rework Angular initializer to support XMCloud and SXP journeys ([#1845](https://github.com/Sitecore/jss/pull/1845))
### 🛠 Breaking Change

### 🧹 Chores

Expand All @@ -36,6 +40,7 @@ Our versioning strategy is as follows:
* `[sitecore-jss]` _GraphQLRequestClient_ now can accept custom 'headers' in the constructor or via _createClientFactory_ ([#1806](https://github.com/Sitecore/jss/pull/1806))
* `[templates/nextjs]` Removed cors header for API endpoints from _lib/next-config/plugins/cors-header_ plugin since cors is handled by API handlers / middlewares ([#1806](https://github.com/Sitecore/jss/pull/1806))
* `[sitecore-jss-nextjs]` Updates to Next.js editing integration to further support secure hosting scenarios (on XM Cloud & Vercel) ([#1832](https://github.com/Sitecore/jss/pull/1832))
* `[create-sitecore-jss]` `[template/angular]` `[template/angular-sxp]` Extracts all SXP related code from the base Angular template into a new 'angular-sxp' addon template. The regular Angular app should now be initialized by providing both templates: 'angular,angular-sxp' ([#1838](https://github.com/Sitecore/jss/pull/1838))
yavorsk marked this conversation as resolved.
Show resolved Hide resolved
illiakovalenko marked this conversation as resolved.
Show resolved Hide resolved

### 🛠 Breaking Change

Expand Down
25 changes: 22 additions & 3 deletions packages/create-sitecore-jss/src/initializers/angular-sxp/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
import { ClientAppArgs, DEFAULT_APPNAME, Initializer } from '../../common';
import path, { sep } from 'path';
art-alexeyenko marked this conversation as resolved.
Show resolved Hide resolved
import {
Initializer,
openPackageJson,
transform,
DEFAULT_APPNAME,
ClientAppArgs,
} from '../../common';
import { InitializerResults } from '../../common/Initializer';

export default class AngularXmCloudInitializer implements Initializer {
export default class AngularSxpInitializer implements Initializer {
get isBase(): boolean {
return false;
}

async init(args: ClientAppArgs) {
const pkg = openPackageJson(`${args.destination}${sep}package.json`);

const mergedArgs = {
...args,
appName: args.appName || pkg?.config?.appName || DEFAULT_APPNAME,
appPrefix: args.appPrefix || pkg?.config?.prefix || false,
};

const templatePath = path.resolve(__dirname, '../../templates/angular-sxp');

await transform(templatePath, mergedArgs);

const response: InitializerResults = {
nextSteps: [],
appName: args.appName || DEFAULT_APPNAME,
appName: mergedArgs.appName,
};

return response;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"scripts": {
"start": "cross-env-shell JSS_MODE=disconnected \"npm-run-all --serial bootstrap --parallel start:angular start:proxy start:watch-components\"",
"start:proxy": "ts-node --project src/tsconfig.webpack-server.json scripts/disconnected-mode-proxy.ts",
"lint:yml": "ts-node ./scripts/lint-yml.ts",
"lint": "ng lint <%- appName %> --fix && npm run lint:yml",
"scaffold": "ng generate @sitecore-jss/sitecore-jss-angular-schematics:jss-component"
},
"devDependencies": {
"yaml-lint": "^1.2.4"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
When the app runs in disconnected mode, and Sitecore is not present, we need to give
the app copies of the Sitecore APIs it depends on (layout service, dictionary service, content service)
to talk to so that the app can run using the locally defined disconnected data.

When the app runs in connected mode, Sitecore is present and some of the requests should be
proxied to the Sitecore API

This is accomplished by spinning up a small Express server that mocks the APIs, and then
telling angular-cli to proxy requests to the API paths to this express instance.

*/
const constants = require('@sitecore-jss/sitecore-jss-angular/cjs').constants;
const environment = require('./src/environments/environment.js').environment;

const port = 3043;

const PROXY_CONFIG =
process.env.JSS_MODE === constants.JSS_MODE.DISCONNECTED
? [
{
context: ['/data', '/sitecore'],
target: `http://localhost:${port}`,
secure: false,
},
]
: [
yavorsk marked this conversation as resolved.
Show resolved Hide resolved
{
context: [
// API endpoints
'/sitecore',
// media items
'/-',
// visitor identification
'/layouts',
],
target: environment.sitecoreApiHost,
secure: false,
changeOrigin: true,
},
];

module.exports = PROXY_CONFIG;
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { JssConfig } from 'lib/config';
import { ConfigPlugin } from '..';
import { constants } from '@sitecore-jss/sitecore-jss-angular/cjs';
const chalk = require('chalk');

/**
* This plugin will check if fetchwith graphgl is beeing used in disconnected mode and throw error if so
*/
class DisconnectedPlugin implements ConfigPlugin {
// should come before other plugins
order = 0;

async exec(config: JssConfig) {
const disconnected = process.env.JSS_MODE === constants.JSS_MODE.DISCONNECTED;
if (disconnected && process.env.FETCH_WITH === constants.FETCH_WITH.GRAPHQL) {
throw new Error(
chalk.red(
'GraphQL requests to Dictionary and Layout services are not supported in disconnected mode.'
)
);
}

return config;
}
}

export const disconnectedPlugin = new DisconnectedPlugin();
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { TranslateModule } from '@ngx-translate/core';
import { RouterModule } from '@angular/router';
import { StyleguideSpecimenComponent } from './shared/styleguide-specimen/styleguide-specimen.component';
import { JssModule } from '@sitecore-jss/sitecore-jss-angular';

/*
This module is imported by the generated app-components.module.ts.
You can use this module to provide shared Angular components that are not
JSS components, etc to the generated module.

Don't want code generation? See ./.gitignore for instructions to turn it off.
*/
@NgModule({
imports: [
CommonModule,
TranslateModule,
RouterModule,
JssModule,
FormsModule,
],
exports: [
CommonModule,
TranslateModule,
RouterModule,
FormsModule,
StyleguideSpecimenComponent
],
declarations: [
StyleguideSpecimenComponent
],
})
export class AppComponentsSharedModule { }
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import { HttpResponse } from '@sitecore-jss/sitecore-jss-angular';
import { Observable, lastValueFrom } from 'rxjs';

@Injectable()
@Injectable({
providedIn: 'root'
})
export class JssDataFetcherService {
constructor(
private readonly httpClient: HttpClient,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<div
class="d-flex flex-column flex-md-row align-items-center p-3 px-md-4 mb-3 bg-white border-bottom"
>
<h5 class="my-0 me-md-auto fw-normal">
<a routerLink="/" class="text-dark" class="logo"></a>
</h5>
<nav class="my-2 my-md-0 me-md-3">
<a
class="p-2 text-dark"
href="https://jss.sitecore.com"
target="_blank"
rel="noopener noreferrer"
>
{{ 'Documentation' | translate }}
</a>
<a routerLink="/styleguide" class="p-2 text-dark">
{{ 'Styleguide' | translate }}
</a>
<a routerLink="/graphql" class="p-2 text-dark">
{{ 'GraphQL' | translate }}
</a>
</nav>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div>
<app-visitor-identification></app-visitor-identification>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { NgModule } from '@angular/core';
import { ScriptsComponent } from './scripts.component';
import { VisitorIdentificationComponent } from './visitor-identification/visitor-identification.component';

@NgModule({
exports: [ScriptsComponent],
declarations: [ScriptsComponent, VisitorIdentificationComponent],
})
export class ScriptsModule {}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, OnInit, OnDestroy } from '@angular/core';
import { Subscription } from 'rxjs';
import { JssContextService } from '../../jss-context.service';
import { JssContextService } from '../../../jss-context.service';

let emittedVI = false;

Expand All @@ -13,15 +13,21 @@ let emittedVI = false;
*/
@Component({
selector: 'app-visitor-identification',
template: `<meta *ngIf="visitorIdentificationTimestamp" name="VIcurrentDateTime" [content]="visitorIdentificationTimestamp" />`,
template: `
<meta
*ngIf="visitorIdentificationTimestamp"
name="VIcurrentDateTime"
[content]="visitorIdentificationTimestamp"
/>
`,
})
export class VisitorIdentificationComponent implements OnInit, OnDestroy {
visitorIdentificationTimestamp: number;

private contextSubscription: Subscription;

// inject the JssContextService, which maintains the current Sitecore Context
constructor(private jssContext: JssContextService) { }
constructor(private jssContext: JssContextService) {}

ngOnInit() {
this.contextSubscription = this.jssContext.state.subscribe((state) => {
Expand Down
Loading