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

Feature/469713 #656

Merged
merged 21 commits into from
Apr 27, 2021
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
e8a682f
Refactoring - avoid duplicating getQueryString and other URL resolvin…
anastasiya29 Apr 15, 2021
de15eb8
Reorganize modules related to layout service - move them into their o…
anastasiya29 Apr 15, 2021
ab7990b
Add directory for test data
anastasiya29 Apr 15, 2021
6be3970
bug fix
anastasiya29 Apr 16, 2021
520832b
Use proper querystring types from @types/node/querystring
anastasiya29 Apr 16, 2021
649a1ba
Refactor sitecore-jss package
anastasiya29 Apr 21, 2021
f4e5019
Move test data for unit tests into a separate json file
anastasiya29 Apr 21, 2021
47b564d
This package.lock file shows as changes when i run lerna reset, so ch…
anastasiya29 Apr 21, 2021
e075aac
Undo encapsulation of axios dependency to axios-fetcher - this adds u…
anastasiya29 Apr 21, 2021
14777a7
Update properties in sitecore-jss/package.json
anastasiya29 Apr 21, 2021
d69d810
Enable syntax highlighting on graphql string via prettier
anastasiya29 Apr 23, 2021
6477eee
shuffle tests around to align with new structure. move app root resol…
anastasiya29 Apr 23, 2021
6a7129e
Remove console.log statements
anastasiya29 Apr 26, 2021
4f62658
Add unit tests for resolve url
anastasiya29 Apr 26, 2021
1907524
set noUnusedLocals to true in sitecore-jss-nextjs
anastasiya29 Apr 27, 2021
33696e8
Debugging import
anastasiya29 Apr 27, 2021
21f7da3
Use querystring type in data-fetcher
anastasiya29 Apr 27, 2021
59cc361
Fix build: move testData folder under /src, allow any again on tracki…
ambrauer Apr 27, 2021
c5d387f
resolveLayoutServiceUrl - add comments and rename param "verb" to "ap…
anastasiya29 Apr 27, 2021
4d1d131
Move appRootId query to utils, as agreed upon by team
anastasiya29 Apr 27, 2021
5c73134
lint
anastasiya29 Apr 27, 2021
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
1 change: 1 addition & 0 deletions packages/sitecore-jss-angular/src/layout.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { from as fromPromise, Observable, throwError as observableThrow } from '
import { catchError } from 'rxjs/operators';
import { LayoutServiceError } from './layout-service-error';

// TODO: these are deprecated and we should switch to using new methods
anastasiya29 marked this conversation as resolved.
Show resolved Hide resolved
const { fetchRouteData, fetchPlaceholderData } = dataApi;

@Injectable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import nock from 'nock';
import { GraphQLSitemapService } from './graphql-sitemap-service';
import rootItemQueryResult from '../testData/rootItemQueryResult.json';
import sitemapQueryResult from '../testData/sitemapQueryResult.json';
import sitemapServiceResult from '../testData/sitemapServiceResult';

describe('GraphQLSitemapService', () => {
const rootItemPath = '/sitecore/next/home';
Expand Down Expand Up @@ -59,33 +60,6 @@ describe('GraphQLSitemapService', () => {
);
};

const expectedSSGSitemap = [
{
params: {
path: [''],
},
locale: 'ua',
},
{
params: {
path: ['x1'],
},
locale: 'ua',
},
{
params: {
path: ['y1', 'y2', 'y3', 'y4'],
},
locale: 'ua',
},
{
params: {
path: ['y1', 'y2'],
},
locale: 'ua',
},
];

describe('Fetch sitemap in SSG mode', () => {
// language param tests

Expand All @@ -95,7 +69,7 @@ describe('GraphQLSitemapService', () => {

const service = new GraphQLSitemapService({ endpoint, apiKey });
const sitemap = await service.fetchSSGSitemap(['ua'], rootItemPath);
expect(sitemap).to.deep.equal(expectedSSGSitemap);
expect(sitemap).to.deep.equal(sitemapServiceResult);

return expect(nock.isDone()).to.be.true;
});
Expand Down Expand Up @@ -239,7 +213,7 @@ describe('GraphQLSitemapService', () => {
const service = new GraphQLSitemapService({ endpoint, apiKey, pageSize: customPageSize });
const sitemap = await service.fetchSSGSitemap(['ua'], rootItemPath);

expect(sitemap).to.deep.equal(expectedSSGSitemap);
expect(sitemap).to.deep.equal(sitemapServiceResult);
return expect(nock.isDone()).to.be.true;
});

Expand All @@ -252,7 +226,7 @@ describe('GraphQLSitemapService', () => {
const service = new GraphQLSitemapService({ endpoint, apiKey, pageSize: undefined });
const sitemap = await service.fetchSSGSitemap(['ua'], rootItemPath);

expect(sitemap).to.deep.equal(expectedSSGSitemap);
expect(sitemap).to.deep.equal(sitemapServiceResult);
return expect(nock.isDone()).to.be.true;
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,37 @@ const DEFAULTS = Object.freeze({
pageSize: 10,
});

const query = `
query SitePageQuery(
$rootItemId: String!,
$language: String!,
$pageSize: Int = 10,
$after: String
) {
search(
where: {
AND:[
{ name: "_path", value: $rootItemId },
{ name: "_language", value: $language },
{ name: "_hasLayout", value: "true" }
]
}
first: $pageSize
after: $after
const query = /* GraphQL */ `
query SitePageQuery(
$rootItemId: String!
$language: String!
$pageSize: Int = 10
$after: String
) {
total
pageInfo {
endCursor
hasNext
}
results {
url {
path
search(
where: {
AND: [
{ name: "_path", value: $rootItemId }
{ name: "_language", value: $language }
{ name: "_hasLayout", value: "true" }
]
}
first: $pageSize
after: $after
) {
total
pageInfo {
endCursor
hasNext
}
results {
url {
path
}
}
}
}
}`;
`;

/**
* Configuration options for @see GraphQLDictionaryService instances
Expand Down
26 changes: 26 additions & 0 deletions packages/sitecore-jss-nextjs/src/testData/sitemapServiceResult.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export default [
{
params: {
path: [''],
},
locale: 'ua',
},
{
params: {
path: ['x1'],
},
locale: 'ua',
},
{
params: {
path: ['y1', 'y2', 'y3', 'y4'],
},
locale: 'ua',
},
{
params: {
path: ['y1', 'y2'],
},
locale: 'ua',
},
];
22 changes: 4 additions & 18 deletions packages/sitecore-jss-tracking/src/trackingApi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HttpDataFetcher, HttpResponse, isServer } from '@sitecore-jss/sitecore-jss';
import { HttpDataFetcher, HttpResponse, isServer, resolveUrl } from '@sitecore-jss/sitecore-jss';
import {
CampaignInstance,
EventInstance,
Expand All @@ -7,6 +7,7 @@ import {
PageViewInstance,
} from './dataModels';
import { TrackingRequestOptions } from './trackingRequestOptions';
import querystring from 'querystring';

class ResponseError extends Error {
response: HttpResponse<unknown>;
Expand All @@ -31,18 +32,6 @@ function checkStatus(response: HttpResponse<unknown>) {
throw error;
}

/**
* note: encodeURIComponent is available via browser (window) or natively in node.js
* if you use another js engine for server-side rendering you may not have native encodeURIComponent
* and would then need to install a package for that functionality
* @param {Object} params
*/
function getQueryString(params: { [key: string]: unknown }) {
return Object.keys(params)
.map((k) => `${encodeURIComponent(k)}=${encodeURIComponent(params[k] as string)}`)
.join('&');
}

/**
* Note: axios needs to use `withCredentials: true` in order for Sitecore cookies to be included in CORS requests
* which is necessary for analytics and such
Expand All @@ -57,12 +46,9 @@ function fetchData<T>(
data: any,
fetcher: HttpDataFetcher<T>,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
params: { [key: string]: any } = {}
params: querystring.ParsedUrlQueryInput = {}
) {
const qs = getQueryString(params);
const fetchUrl = url.indexOf('?') !== -1 ? `${url}&${qs}` : `${url}?${qs}`;

return fetcher(fetchUrl, data)
return fetcher(resolveUrl(url, params), data)
.then(checkStatus)
.then((response) => {
// axios auto-parses JSON responses, don't need to JSON.parse
Expand Down
3 changes: 2 additions & 1 deletion packages/sitecore-jss-tracking/src/trackingRequestOptions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import querystring from 'querystring';
import { HttpDataFetcher } from '@sitecore-jss/sitecore-jss';

export interface TrackingRequestOptions {
Expand All @@ -13,7 +14,7 @@ export interface TrackingRequestOptions {
/**
* An object of key:value pairs to be stringified and used as querystring parameters.
*/
querystringParams?: { [key: string]: unknown };
querystringParams?: querystring.ParsedUrlQueryInput;

/** Type of tracking request action. Default: 'event' */
action?: string;
Expand Down
8 changes: 6 additions & 2 deletions packages/sitecore-jss/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@
},
"author": {
"name": "Sitecore Corporation",
"url": "https://jss.sitecore.net"
"url": "https://jss.sitecore.com"
},
"repository": {
"type": "git",
"url": "https://github.com/Sitecore/jss"
},
"license": "Apache-2.0",
"homepage": "https://jss.sitecore.net",
"homepage": "https://jss.sitecore.com",
"bugs": {
"url": "https://github.com/sitecore/jss/issues"
},
Expand Down
133 changes: 0 additions & 133 deletions packages/sitecore-jss/src/data-api.test.ts

This file was deleted.

Loading