@newskit-render/core 1.30.0 → 1.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,28 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [1.32.0](https://github.com/newscorp-ghfb/ncu-newskit-render/compare/@newskit-render/core@1.31.0...@newskit-render/core@1.32.0) (2022-03-09)
7
+
8
+
9
+ ### Features
10
+
11
+ * **PPDSR-633:** Update payment failure to MAIN ([#618](https://github.com/newscorp-ghfb/ncu-newskit-render/issues/618)) ([3de75ac](https://github.com/newscorp-ghfb/ncu-newskit-render/commit/3de75acaed7fbd2e994d36f2c070fced6c2ea123))
12
+
13
+
14
+
15
+
16
+
17
+ # [1.31.0](https://github.com/newscorp-ghfb/ncu-newskit-render/compare/@newskit-render/core@1.30.0...@newskit-render/core@1.31.0) (2022-03-09)
18
+
19
+
20
+ ### Features
21
+
22
+ * **PPDSR-678:** add feed package ([#620](https://github.com/newscorp-ghfb/ncu-newskit-render/issues/620)) ([903cbdf](https://github.com/newscorp-ghfb/ncu-newskit-render/commit/903cbdf24e0ed0a1dea301a03f9d78cf7357187e))
23
+
24
+
25
+
26
+
27
+
6
28
  # [1.30.0](https://github.com/newscorp-ghfb/ncu-newskit-render/compare/@newskit-render/core@1.29.5...@newskit-render/core@1.30.0) (2022-03-07)
7
29
 
8
30
 
@@ -59,12 +59,18 @@ const props: ArticleSlug = {
59
59
  gscId: '4320982',
60
60
  }
61
61
 
62
- const userMock = {}
62
+ const user = {
63
+ paymentFailure: {
64
+ active: false,
65
+ startDate: null,
66
+ },
67
+ subscriptions: [{ endDate: null }],
68
+ }
63
69
 
64
70
  jest.mock('cross-fetch', () =>
65
71
  jest.fn().mockImplementation(() =>
66
72
  Promise.resolve({
67
- json: () => Promise.resolve(userMock),
73
+ json: () => Promise.resolve(user),
68
74
  })
69
75
  )
70
76
  )
@@ -80,13 +86,12 @@ jest.mock('@newskit-render/api', () => ({
80
86
  }),
81
87
  })
82
88
  }),
83
- getMainSession: jest.fn(),
89
+ getAcsCookie: jest.fn().mockReturnValue({ Cookie: 'something' }),
84
90
  }))
85
91
 
86
92
  jest.mock('@newskit-render/my-account', () => {
87
93
  return {
88
94
  PastDueBannerExternal: 'PastDueBannerExternal',
89
- getMainSession: jest.fn(),
90
95
  }
91
96
  })
92
97
 
@@ -125,7 +130,7 @@ describe('Article', () => {
125
130
  req: { headers: { cookie: 'some-cookie' } },
126
131
  res: { setHeader: setHeaderMock },
127
132
  })
128
- expect(response).toEqual({ props: { ...props, showAds: true } })
133
+ expect(response).toEqual({ props: { ...props, showAds: true, user } })
129
134
  expect(setHeaderMock).toHaveBeenCalledWith(
130
135
  'Cache-Control',
131
136
  'public, s-maxage=10, stale-while-revalidate=59'
@@ -573,10 +573,6 @@ exports[`getServerSideProps Homepage 1`] = `
573
573
  </div>
574
574
  </div>
575
575
  </div>
576
- <pastduebannerexternal
577
- pastduebanner="[object Object]"
578
- wrapper="NO_COMPONENT_SELECTOR"
579
- />
580
576
  @media screen {
581
577
  .emotion-0 {
582
578
  background-color: #FFFFFF;
@@ -7,6 +7,14 @@ jest.mock('../../helpers/getYear', () => ({
7
7
  getYear: jest.fn().mockReturnValue('YYYY'),
8
8
  }))
9
9
 
10
+ const user = {
11
+ paymentFailure: {
12
+ active: false,
13
+ startDate: null,
14
+ },
15
+ subscriptions: [{ endDate: null }],
16
+ }
17
+
10
18
  jest.mock('@newskit-render/api', () => ({
11
19
  ClientTypes: { nkapi: 'nkapi' },
12
20
  createApolloClient: jest.fn().mockImplementation(() => {
@@ -23,16 +31,13 @@ jest.mock('@newskit-render/api', () => ({
23
31
  }),
24
32
  })
25
33
  }),
26
- getMainSession: jest.fn(),
34
+ getAcsCookie: jest.fn().mockReturnValue({ Cookie: 'something' }),
27
35
  }))
28
36
 
29
37
  jest.mock('cross-fetch', () =>
30
38
  jest.fn().mockImplementation(() =>
31
39
  Promise.resolve({
32
- json: () =>
33
- Promise.resolve({
34
- vxInstances: null,
35
- }),
40
+ json: () => Promise.resolve(user),
36
41
  })
37
42
  )
38
43
  )
@@ -66,6 +71,7 @@ describe('getServerSideProps', () => {
66
71
  },
67
72
  },
68
73
  showAds: true,
74
+ user,
69
75
  },
70
76
  })
71
77
  )
@@ -573,10 +573,6 @@ exports[`Article should render tile and sub title 1`] = `
573
573
  </div>
574
574
  </div>
575
575
  </div>
576
- <pastduebannerexternal
577
- pastduebanner="[object Object]"
578
- wrapper="NO_COMPONENT_SELECTOR"
579
- />
580
576
  @media screen {
581
577
  .emotion-0 {
582
578
  background-color: #FFFFFF;
@@ -2,8 +2,10 @@ import { fireEvent } from '@testing-library/react'
2
2
  import { renderWithTheme } from '../../helpers/test-utils'
3
3
  import Header from '.'
4
4
 
5
- jest.mock('@newskit-render/my-account', () => {
5
+ jest.mock('@newskit-render/shared-components', () => {
6
6
  return {
7
+ // @ts-ignore
8
+ ...jest.requireActual('@newskit-render/shared-components'),
7
9
  PastDueBannerExternal: 'PastDueBannerExternal',
8
10
  }
9
11
  })
@@ -12,13 +12,14 @@ import {
12
12
  IconFilledMenu,
13
13
  Image,
14
14
  } from 'newskit'
15
- import { PastDueBannerExternal, UserData } from '@newskit-render/my-account'
15
+ import { UserData } from '@newskit-render/my-account'
16
16
  import {
17
17
  NextLink,
18
18
  theSunTheme,
19
19
  timesTheme,
20
20
  virginRadioTheme,
21
21
  ThemeDropdown,
22
+ PastDueBannerExternal,
22
23
  } from '@newskit-render/shared-components'
23
24
  import {
24
25
  renderCustomLightTheme as LightTheme,
@@ -13,7 +13,10 @@ describe('getUser function', () => {
13
13
  it("should call console.error with 'Bad response from server' when Response.status >= 400", async () => {
14
14
  jest.spyOn(console, 'error')
15
15
  fetchMock.mockImplementation(() => Promise.resolve({ status: 500 }))
16
- await fetchUser('', 'http://localhost:3000/api/account/query')
16
+ await fetchUser(
17
+ { Cookie: 'test' },
18
+ 'http://localhost:3000/api/account/query'
19
+ )
17
20
  expect(console.error).toHaveBeenCalledWith('Bad response from server')
18
21
  })
19
22
 
@@ -22,7 +25,22 @@ describe('getUser function', () => {
22
25
  fetchMock.mockImplementation(() =>
23
26
  Promise.resolve({ status: 200, json: mockJson })
24
27
  )
25
- await fetchUser('', 'http://localhost:3000/api/account/query')
28
+ await fetchUser(
29
+ { Cookie: 'test' },
30
+ 'http://localhost:3000/api/account/query'
31
+ )
26
32
  expect(mockJson).toHaveBeenCalled()
27
33
  })
34
+
35
+ it('should return null if no cookie', async () => {
36
+ const mockJson = jest.fn()
37
+ fetchMock.mockImplementation(() =>
38
+ Promise.resolve({ status: 200, json: mockJson })
39
+ )
40
+ await fetchUser(
41
+ "I'm not a cookie",
42
+ 'http://localhost:3000/api/account/query'
43
+ )
44
+ expect(mockJson).not.toHaveBeenCalled()
45
+ })
28
46
  })
@@ -1,5 +1,6 @@
1
1
  import fetch from 'cross-fetch'
2
2
  import { UserData } from '@newskit-render/my-account'
3
+ import { MainAcsCookie } from '@newskit-render/api'
3
4
 
4
5
  interface UserHeaders {
5
6
  [key: string]: string
@@ -10,23 +11,26 @@ interface UserConfig {
10
11
  body: string
11
12
  }
12
13
 
13
- const userConfig = (session: string): UserConfig => ({
14
+ const userConfig = (acsCookie: { Cookie: string }): UserConfig => ({
14
15
  method: 'POST',
15
16
  headers: {
16
17
  'Content-Type': 'application/json',
17
- 'X-MAIN-SESSION': session,
18
+ ...acsCookie,
18
19
  },
19
- body: JSON.stringify({ queryFragment: 'UserPaymentInstance' }),
20
+ body: JSON.stringify({ queryFragment: 'UserPaymentInfo' }),
20
21
  })
21
22
 
22
23
  export const fetchUser = async (
23
- session: string,
24
+ acsCookie: MainAcsCookie,
24
25
  url: string
25
26
  ): Promise<UserData | null> => {
26
- const response = await fetch(url, userConfig(session))
27
- if (response.status >= 400) {
28
- console.error('Bad response from server')
29
- return null
27
+ if (typeof acsCookie === 'object') {
28
+ const response = await fetch(url, userConfig(acsCookie))
29
+ if (response.status >= 400) {
30
+ console.error('Bad response from server')
31
+ return null
32
+ }
33
+ return (await response.json()) as UserData
30
34
  }
31
- return (await response.json()) as UserData
35
+ return null
32
36
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@newskit-render/core",
3
- "version": "1.30.0",
3
+ "version": "1.32.0",
4
4
  "description": "Newskit Render - Core package",
5
5
  "author": "",
6
6
  "license": "UNLICENSED",
@@ -35,10 +35,10 @@
35
35
  "@apollo/client": "3.4.16",
36
36
  "@newskit-render/api": "^0.15.0",
37
37
  "@newskit-render/auth": "^0.29.0",
38
- "@newskit-render/checkout": "^0.24.2",
38
+ "@newskit-render/checkout": "^0.24.3",
39
39
  "@newskit-render/feature-flags": "^0.11.0",
40
- "@newskit-render/my-account": "^0.143.0",
41
- "@newskit-render/shared-components": "^0.37.2",
40
+ "@newskit-render/my-account": "^0.144.0",
41
+ "@newskit-render/shared-components": "^0.38.0",
42
42
  "@newskit-render/sitemap": "^0.35.0",
43
43
  "@newskit-render/validation": "^0.37.0",
44
44
  "cross-fetch": "3.1.5",
@@ -1,12 +1,16 @@
1
1
  import React from 'react'
2
2
  import newrelic from 'newrelic'
3
- import { createApolloClient, ClientTypes } from '@newskit-render/api'
3
+ import {
4
+ createApolloClient,
5
+ ClientTypes,
6
+ getAcsCookie,
7
+ } from '@newskit-render/api'
4
8
  import { UserData } from '@newskit-render/my-account'
5
9
  import { GET_UNIVERSAL_ARTICLE } from '../../../queries'
6
10
  import ArticlePage, { UniversalArticle } from '../../../components/article'
7
11
  import { highlights, relatedArticles } from '../../../helpers/mocks/articleMock'
8
- // import { fetchUser } from '../../../helpers/getUser'
9
- // import { ACCOUNT_QUERY_URL } from '../../../constants'
12
+ import { fetchUser } from '../../../helpers/getUser'
13
+ import { ACCOUNT_QUERY_URL } from '../../../constants'
10
14
  import { addCacheHeaders } from '../../../helpers/addCacheHeaders'
11
15
 
12
16
  export type ArticleSlug = {
@@ -41,7 +45,9 @@ const Article: React.FC<ArticleSlug> = ({
41
45
 
42
46
  export async function getServerSideProps(context) {
43
47
  const apolloClient = await createApolloClient(ClientTypes.nkapi)
44
- // const mainSession = getMainSession(context.req.headers.cookie)
48
+ const acsCookie = context.req.headers.cookie
49
+ ? getAcsCookie(ClientTypes.main, context.req.headers.cookie)
50
+ : ''
45
51
 
46
52
  const {
47
53
  params: { articleId, section, articleSlug },
@@ -51,15 +57,12 @@ export async function getServerSideProps(context) {
51
57
  `Article: /${section}/${articleId}/${articleSlug}`
52
58
  )
53
59
 
54
- const [
55
- { data },
56
- // user
57
- ] = await Promise.all([
60
+ const [{ data }, user] = await Promise.all([
58
61
  apolloClient.query({
59
62
  query: GET_UNIVERSAL_ARTICLE,
60
63
  variables: { publisher: 'DEMO', id: articleId },
61
64
  }),
62
- // await fetchUser(mainSession, ACCOUNT_QUERY_URL),
65
+ await fetchUser(acsCookie, ACCOUNT_QUERY_URL),
63
66
  ])
64
67
 
65
68
  addCacheHeaders(context.res)
@@ -71,7 +74,7 @@ export async function getServerSideProps(context) {
71
74
  siteHost: process.env.SITE_HOST || '',
72
75
  gscId: process.env.GSC_ID || '',
73
76
  showAds: true,
74
- // user,
77
+ user,
75
78
  },
76
79
  }
77
80
  }
@@ -1,13 +1,13 @@
1
1
  import newrelic from 'newrelic'
2
2
  import {
3
3
  createApolloClient,
4
- // getMainSession,
4
+ getAcsCookie,
5
5
  ClientTypes,
6
6
  } from '@newskit-render/api'
7
7
  import { GET_PAGE } from '../../queries'
8
8
  import SectionPage from '../../components/section'
9
- // import { fetchUser } from '../../helpers/getUser'
10
- // import { ACCOUNT_QUERY_URL } from '../../constants'
9
+ import { fetchUser } from '../../helpers/getUser'
10
+ import { ACCOUNT_QUERY_URL } from '../../constants'
11
11
  import { addCacheHeaders } from '../../helpers/addCacheHeaders'
12
12
 
13
13
  export async function getServerSideProps(context) {
@@ -17,20 +17,17 @@ export async function getServerSideProps(context) {
17
17
  params: { section },
18
18
  } = context
19
19
 
20
- // const mainSession = getMainSession(context.req.headers.cookie)
20
+ const acsCookie = context.req.headers.cookie
21
+ ? getAcsCookie(ClientTypes.main, context.req.headers.cookie)
22
+ : ''
21
23
 
22
24
  newrelic.setTransactionName(`Section: ${section}`)
23
- const [
24
- { data },
25
- // user
26
- ] = await Promise.all([
25
+ const [{ data }, user] = await Promise.all([
27
26
  apolloClient.query({
28
27
  query: GET_PAGE,
29
28
  variables: { channel: section, publisher: 'DEMO' },
30
29
  }),
31
-
32
- // TODO: Enable once Main add Subscriptions
33
- // await fetchUser(mainSession, ACCOUNT_QUERY_URL),
30
+ await fetchUser(acsCookie, ACCOUNT_QUERY_URL),
34
31
  ])
35
32
 
36
33
  addCacheHeaders(context.res)
@@ -39,7 +36,7 @@ export async function getServerSideProps(context) {
39
36
  page: data.page,
40
37
  isIndexPage: true,
41
38
  showAds: true,
42
- // user,
39
+ user,
43
40
  },
44
41
  }
45
42
  }
package/pages/index.tsx CHANGED
@@ -1,13 +1,13 @@
1
1
  import newrelic from 'newrelic'
2
2
  import {
3
3
  createApolloClient,
4
- // getMainSession,
4
+ getAcsCookie,
5
5
  ClientTypes,
6
6
  } from '@newskit-render/api'
7
7
  import { GET_PAGE } from '../queries'
8
8
  import SectionPage from '../components/section'
9
- // import { fetchUser } from '../helpers/getUser'
10
- // import { ACCOUNT_QUERY_URL } from '../constants'
9
+ import { fetchUser } from '../helpers/getUser'
10
+ import { ACCOUNT_QUERY_URL } from '../constants'
11
11
  import { addCacheHeaders } from '../helpers/addCacheHeaders'
12
12
 
13
13
  export async function getServerSideProps(context) {
@@ -16,18 +16,16 @@ export async function getServerSideProps(context) {
16
16
  console.warn(context.req && context.req.headers)
17
17
 
18
18
  const apolloClient = await createApolloClient(ClientTypes.nkapi)
19
- // const mainSession = getMainSession(context.req.headers.cookie)
19
+ const acsCookie = context.req.headers.cookie
20
+ ? getAcsCookie(ClientTypes.main, context.req.headers.cookie)
21
+ : ''
20
22
 
21
- const [
22
- { data },
23
- // user
24
- ] = await Promise.all([
23
+ const [{ data }, user] = await Promise.all([
25
24
  apolloClient.query({
26
25
  query: GET_PAGE,
27
26
  variables: { channel: 'homepage', publisher: 'DEMO' },
28
27
  }),
29
- // TODO: Enable once Main add Subscriptions
30
- // await fetchUser(mainSession, ACCOUNT_QUERY_URL),
28
+ await fetchUser(acsCookie, ACCOUNT_QUERY_URL),
31
29
  ])
32
30
 
33
31
  addCacheHeaders(context.res)
@@ -36,10 +34,9 @@ export async function getServerSideProps(context) {
36
34
  props: {
37
35
  page,
38
36
  showAds: true,
39
- // user: (user || null),
37
+ user,
40
38
  },
41
39
  }
42
40
  }
43
41
 
44
- // TEST RELEASE_CLI
45
42
  export default SectionPage
package/temp/header.tsx CHANGED
@@ -11,14 +11,13 @@ import {
11
11
  Block,
12
12
  IconFilledMenu,
13
13
  } from 'newskit'
14
- import { NextLink } from '@newskit-render/shared-components'
15
- import { PastDueBannerExternal } from '@newskit-render/my-account'
14
+ import { UserData } from '@newskit-render/my-account'
15
+ import { NextLink, PastDueBannerExternal } from '@newskit-render/shared-components'
16
16
  import { MainGrid } from '../layout/MainGrid'
17
17
  import NewsKitLogoFull from '../common/NewskitLogo'
18
18
  import NewsKitLogoShort from '../common/NewskitLogoShort'
19
19
  import NavLink from '../common/NavLink'
20
20
  import { handleEnterKeyPress } from '../../helpers/a11y'
21
- import { UserData } from '../../helpers/global-types'
22
21
 
23
22
  export const headerSize = 'sizing090'
24
23
 
@@ -229,7 +228,7 @@ const Header: React.FC<{ user: UserData }> = ({ user }) => {
229
228
  </StyledHeader>
230
229
  <PastDueBannerExternal
231
230
  pastDueBanner={pastDueBanner}
232
- vxInstances={user?.vxInstances}
231
+ user={user}
233
232
  wrapper={BannerContainer}
234
233
  />
235
234
  </>