Skip to content

Commit 65ddc0d

Browse files
Remove use of deprecated dataApi (#744)
* Replace dataApi by RestLayoutService * update docs * Update react-native, embedded-jss-app * Remove 'default' * Changes after review * Remove redundant interfaces * Removed remaining LayoutServiceRequestOptions refs * fix 'jss-layout.service' import in angular sample Co-authored-by: Adam Brauer <[email protected]>
1 parent a9e3ff2 commit 65ddc0d

File tree

38 files changed

+228
-604
lines changed

38 files changed

+228
-604
lines changed

docs/data/routes/docs/client-frameworks/angular/sample-app/en.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ There are several mechanisms of using/outputting translated values with `ngx-tra
199199
200200
#### `JssTranslationLoaderService`
201201
202-
This implementation loads the Sitecore dictionary from the Dictionary Service provided by JSS, found at `/sitecore/api/jss/dictionary/`, using `HttpClient`. It is used as a "fallback" during both client and server rendering.
202+
This implementation loads the Sitecore dictionary from the Dictionary Service provided by JSS, found at `/sitecore/api/jss/dictionary/`, using `RestDictionaryService`. It is used as a "fallback" during both client and server rendering.
203203
204204
#### `JssTranslationServerLoaderService`
205205

docs/data/routes/docs/fundamentals/services/layout-service/en.md

+24-29
Original file line numberDiff line numberDiff line change
@@ -97,38 +97,33 @@ If you don't want analytics tracking for your JSS app, or for particular Layout
9797
9898
## Invoking the Layout Service from JSS
9999
100-
The Sitecore JSS SDK provides a simple API to make utilizing the Layout Service easier. Enter your configuration into the `fetchOptions` object and pass it into `dataApi.fetchRouteData()`. The `fetcher` option enables you to implement whichever data access method you wish. JSS ships with axios, which can be imported from `src\dataFetcher.js`.
100+
The Sitecore JSS SDK provides a simple API to make utilizing the Layout Service easier. Create instance of `RestLayoutService` and pass your configuration into the constructor and call `layoutService.fetchLayoutData()`. The optional `dataFetcherResolver` option enables you to implement whichever data access method you wish. JSS ships with Axios by default.
101101
102-
The `dataApi` object is found in the `@sitecore-jss\sitecore-jss` package but is also exposed via the framework-specific SDKs
102+
The `RestLayoutService` class is found in the `@sitecore-jss\sitecore-jss` package but is also exposed via the framework-specific SDKs
103103
104104
```javascript
105-
import { dataApi } from '@sitecore-jss/sitecore-jss-react';
106-
import { dataFetcher } from './dataFetcher';
107-
108-
const fetchOptions = {
109-
fetcher: dataFetcher,
110-
layoutServiceConfig: {
111-
host: 'http://mysitecore',
112-
configurationName: 'jss',
113-
},
114-
querystringParams: {
115-
sc_lang: 'en',
116-
tracking: false,
117-
sc_apikey: '{00000000-0000-0000-0000-000000000000}',
118-
sc_camp: 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'
119-
},
120-
requestConfig: {
121-
// AxiosRequestConfig -- https://github.com/axios/axios#request-config
122-
// Note: `withCredentials: true` is added automatically
123-
timeout: 3000,
124-
headers: {
125-
'X-JSS': 'Experience is asynchronous'
126-
}
127-
},
128-
}
129-
130-
dataApi.fetchRouteData('/', fetchOptions).then(route => {
131-
console.log(JSON.stringify(route, null, 2));
105+
// ./layout-service.js
106+
107+
import { RestLayoutService } from '@sitecore-jss/sitecore-jss-react';
108+
import { dataFetcher } from './dataFetcher';
109+
110+
export const layoutService = new RestLayoutService({
111+
apiHost: 'http://mysitecore',
112+
apiKey: '{00000000-0000-0000-0000-000000000000}',
113+
siteName: 'jssappname',
114+
tracking: false,
115+
dataFetcherResolver: () => dataFetcher,
116+
});
117+
```
118+
119+
```javascript
120+
import { layoutService } from './layout-service';
121+
122+
const language = 'en';
123+
const sitecoreRoutePath = '/styleguide';
124+
125+
layoutService.fetchLayoutData(sitecoreRoutePath, language).then((route) => {
126+
console.log(JSON.stringify(route, null, 2));
132127
});
133128
```
134129

docs/data/routes/docs/fundamentals/services/tracking/en.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ The tracking API ships with TypeScript typings, so with TS-aware editors like VS
7272

7373
The tracking API supports tracking arbitrary page view events. This can be useful for things like tracking route changes that do not involve a Layout Service request (cached, custom routes, etc). When tracking page views, it's important to know:
7474

75-
* Requests to [Layout Service](/docs/fundamentals/services/layout-service) will track a page view by default. This can be disabled by adding `tracking=false` to the Layout Service request query string (configurable via the `dataApi` object in JSS apps). Disabling LS tracking may make sense if all page tracking is to be handled using the tracking API.
75+
* Requests to [Layout Service](/docs/fundamentals/services/layout-service) will track a page view by default. This can be disabled by adding `tracking=false` to the Layout Service request query string (configurable via the `RestLayoutService` class in JSS apps). Disabling LS tracking may make sense if all page tracking is to be handled using the tracking API.
7676
* Page view events require a Sitecore Item ID to track against, even though the URL tracked is arbitrary. If tracking non-item-based routes, you may need to create surrogate items to track against.
7777

7878
```js

docs/data/routes/docs/techniques/extending-layout-service/extending-layout-service-overview/en.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,13 @@ After patching in your custom configuration, you can utilize it in your JSS App
180180
</javaScriptServices>
181181
```
182182

183-
You'll need to ensure that you provide this configuration name in your client code as well when invoking Layout Service via the `dataApi` (see examples above).
183+
Provide configuration name in your client code as well when invoking Layout Service via the `RestLayoutService`.
184+
185+
```javascript
186+
const layoutService = new RestLayoutService({
187+
apiHost: 'http://mysitecore',
188+
apiKey: '{00000000-0000-0000-0000-000000000000}',
189+
siteName: 'jssappname',
190+
configurationName: 'my-jss-config',
191+
});
192+
```

docs/data/routes/help/en.md

-15
Original file line numberDiff line numberDiff line change
@@ -135,21 +135,6 @@ Attempt to connect to Node timed out after 60000ms.
135135

136136
* Placeholders defined in JSS will use the global `key` field on their Placeholder Settings. This means that conflicts may arise if non-JSS and JSS apps use the same placeholder key on a multi-site Sitecore installation. This is not a JSS-specific issue, and to avoid it give JSS apps unique placeholder names such as `myapp-main`. Note that JSS apps will _not_ conflict with each other when using the same placeholder keys, if there are multiple JSS sites.
137137

138-
* Site detection that is not based on `hostName` but on `virtualFolder` / `physicalFolder` attributes requires additional configuration and query string based site name specification. Search your app for `dataApi`, and find where the dataApi's `fetchRouteData()` function is being called. Add `sc_site` to the options passed to `fetchRouteData` like so:
139-
140-
```
141-
const fetchOptions = {
142-
// ...
143-
querystringParams: {
144-
// ... (i.e. 'sc_lang')
145-
sc_site: 'name of your site definition in Sitecore'
146-
},
147-
};
148-
149-
// pseudocode
150-
dataApi.fetchRouteData(route, fetchOptions);
151-
```
152-
153138
## Troubleshooting
154139

155140
### Missing Layout Service Placeholder Data

packages/sitecore-jss-angular/src/layout-service-error.ts

-7
This file was deleted.

packages/sitecore-jss-angular/src/layout.service.ts

-47
This file was deleted.

packages/sitecore-jss-angular/src/lib.module.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import { RichTextDirective } from './components/rich-text.directive';
2525
import { RouterLinkDirective } from './components/router-link.directive';
2626
import { TextDirective } from './components/text.directive';
2727
import { JssComponentFactoryService } from './jss-component-factory.service';
28-
import { LayoutService } from './layout.service';
2928

3029
@NgModule({
3130
imports: [CommonModule],
@@ -72,7 +71,7 @@ export class JssModule {
7271
static forRoot(): ModuleWithProviders<JssModule> {
7372
return {
7473
ngModule: JssModule,
75-
providers: [LayoutService, DatePipe, JssComponentFactoryService],
74+
providers: [DatePipe, JssComponentFactoryService],
7675
};
7776
}
7877

packages/sitecore-jss-angular/src/public_api.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,23 @@ export {
1717
} from './components/rendering-field';
1818
export { RichTextDirective } from './components/rich-text.directive';
1919
export { TextDirective } from './components/text.directive';
20-
export { LayoutService } from './layout.service';
21-
export { LayoutServiceError } from './layout-service-error';
2220
export { JssModule } from './lib.module';
2321
export {
24-
dataApi,
2522
mediaApi,
2623
isEditorActive,
2724
resetEditorChromes,
2825
constants,
2926
isExperienceEditorActive,
3027
resetExperienceEditorChromes,
28+
RestDictionaryService,
29+
RestLayoutService,
30+
LayoutService,
3131
LayoutServiceData,
3232
LayoutServiceContextData,
33+
PlaceholderData,
3334
RouteData,
3435
Field,
3536
HtmlElementRendering,
36-
LayoutServiceRequestOptions,
3737
getChildPlaceholder,
3838
getFieldValue,
3939
ComponentRendering,

packages/sitecore-jss-nextjs/src/index.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export {
2-
dataApi,
32
mediaApi,
43
constants,
54
// generic data access
@@ -21,7 +20,6 @@ export {
2120
LayoutServicePageState,
2221
LayoutServiceContext,
2322
LayoutServiceContextData,
24-
LayoutServiceRequestOptions,
2523
GraphQLLayoutService,
2624
GraphQLLayoutServiceConfig,
2725
RestLayoutService,

packages/sitecore-jss-nextjs/src/utils.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe('utils', () => {
3737
process.env.VERCEL_URL = 'jss.uniqueid.vercel.com';
3838
const result = getPublicUrl();
3939
expect(result).to.equal('https://jss.uniqueid.vercel.com');
40-
})
40+
});
4141
});
4242
describe('getJssEditingSecret', () => {
4343
after(() => {

packages/sitecore-jss-react-native/src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
export {
2-
dataApi,
32
mediaApi,
43
isEditorActive,
54
resetEditorChromes,
65
isExperienceEditorActive,
76
resetExperienceEditorChromes,
7+
RestLayoutService,
8+
LayoutService,
89
LayoutServiceData,
910
LayoutServiceContextData,
1011
RouteData,
1112
Field,
1213
HtmlElementRendering,
13-
LayoutServiceRequestOptions,
1414
getChildPlaceholder,
1515
getFieldValue,
1616
ComponentRendering,

packages/sitecore-jss-react/src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
export {
2-
dataApi,
32
mediaApi,
43
isEditorActive,
54
resetEditorChromes,
65
constants,
76
isExperienceEditorActive,
87
resetExperienceEditorChromes,
98
DictionaryPhrases,
9+
LayoutService,
10+
RestLayoutService,
1011
LayoutServiceData,
1112
LayoutServicePageState,
1213
LayoutServiceContext,
@@ -15,7 +16,6 @@ export {
1516
Field,
1617
Item,
1718
HtmlElementRendering,
18-
LayoutServiceRequestOptions,
1919
getChildPlaceholder,
2020
getFieldValue,
2121
ComponentRendering,

packages/sitecore-jss-vue/src/index.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
export {
2-
dataApi,
32
mediaApi,
43
isEditorActive,
54
resetEditorChromes,
65
constants,
76
isExperienceEditorActive,
87
resetExperienceEditorChromes,
8+
DictionaryService,
9+
RestDictionaryService,
10+
LayoutService,
11+
RestLayoutService,
912
LayoutServiceData,
1013
LayoutServiceContextData,
1114
RouteData,
1215
Field,
1316
HtmlElementRendering,
14-
LayoutServiceRequestOptions,
1517
getChildPlaceholder,
1618
getFieldValue,
1719
ComponentRendering,

packages/sitecore-jss/src/i18n/rest-dictionary-service.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ export class RestDictionaryService extends DictionaryServiceBase {
4040
* Provides default @see AxiosDataFetcher data fetcher
4141
*/
4242
get defaultFetcher(): HttpDataFetcher<RestDictionaryServiceData> {
43-
const dataFetcher = new AxiosDataFetcher({ debugger: debug.dictionary });
43+
const dataFetcher = new AxiosDataFetcher({
44+
debugger: debug.dictionary,
45+
// CORS issue: Sitecore provides 'Access-Control-Allow-Origin' as wildcard '*', so we can't include credentials for the dictionary service
46+
withCredentials: false,
47+
});
4448
return (url: string) => dataFetcher.fetch<RestDictionaryServiceData>(url);
4549
}
4650

packages/sitecore-jss/src/index.ts

-7
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,6 @@ export {
3636
RestLayoutService,
3737
RestLayoutServiceConfig,
3838
DataFetcherResolver,
39-
LayoutServiceConfig,
40-
LayoutServiceRequestOptions,
4139
} from './layout/rest-layout-service';
4240

4341
export { GraphQLLayoutService, GraphQLLayoutServiceConfig } from './layout/graphql-layout-service';
44-
45-
// TODO: these are deprecated and we should stop exporting them
46-
import { fetchRouteData, fetchPlaceholderData } from './layout/rest-layout-service';
47-
const dataApi = { fetchRouteData, fetchPlaceholderData };
48-
export { dataApi };

0 commit comments

Comments
 (0)