@financial-times/cp-content-pipeline-schema 2.4.2 → 2.5.1

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.
Files changed (36) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/lib/datasources/capi.d.ts +2 -4
  3. package/lib/datasources/capi.js +8 -12
  4. package/lib/datasources/capi.js.map +1 -1
  5. package/lib/datasources/instrumented.d.ts +5 -5
  6. package/lib/datasources/instrumented.js +36 -27
  7. package/lib/datasources/instrumented.js.map +1 -1
  8. package/lib/datasources/origami-image.d.ts +2 -3
  9. package/lib/datasources/origami-image.js +4 -4
  10. package/lib/datasources/origami-image.js.map +1 -1
  11. package/lib/datasources/twitter.d.ts +2 -2
  12. package/lib/datasources/twitter.js +3 -3
  13. package/lib/datasources/twitter.js.map +1 -1
  14. package/lib/model/CapiResponse.d.ts +1 -50
  15. package/lib/model/CapiResponse.js +40 -19
  16. package/lib/model/CapiResponse.js.map +1 -1
  17. package/lib/resolvers/content-tree/bodyXMLToTree.d.ts +1 -1
  18. package/lib/resolvers/content-tree/tagMappings.d.ts +2 -1
  19. package/lib/resolvers/content-tree/tagMappings.js +1 -1
  20. package/lib/resolvers/content-tree/tagMappings.js.map +1 -1
  21. package/lib/resolvers/content-tree/tagMappings.test.js +9 -2
  22. package/lib/resolvers/content-tree/tagMappings.test.js.map +1 -1
  23. package/lib/types/cache.d.ts +1 -1
  24. package/lib/types/cache.js +4 -1
  25. package/lib/types/cache.js.map +1 -1
  26. package/package.json +2 -2
  27. package/src/datasources/capi.ts +9 -15
  28. package/src/datasources/instrumented.ts +62 -43
  29. package/src/datasources/origami-image.ts +6 -10
  30. package/src/datasources/twitter.ts +5 -11
  31. package/src/model/CapiResponse.ts +64 -28
  32. package/src/resolvers/content-tree/bodyXMLToTree.ts +1 -1
  33. package/src/resolvers/content-tree/tagMappings.test.ts +18 -3
  34. package/src/resolvers/content-tree/tagMappings.ts +6 -2
  35. package/src/types/cache.ts +6 -2
  36. package/tsconfig.tsbuildinfo +1 -1
@@ -1,5 +1,19 @@
1
+ import { AnyNode, OldClip } from './Workarounds'
1
2
  import tagMappings, { getBooleanAttributeValue } from './tagMappings'
2
3
  import cheerio from 'cheerio'
4
+
5
+ function expectNotArray<T>(thing: T | T[]): asserts thing is T {
6
+ expect(thing).not.toBeInstanceOf(Array)
7
+ }
8
+
9
+ function expectNodeType<T extends AnyNode>(
10
+ node: AnyNode | AnyNode[],
11
+ type: T['type']
12
+ ): asserts node is T {
13
+ expectNotArray(node)
14
+ expect(node.type).toBe(type)
15
+ }
16
+
3
17
  describe('tagMappings test', () => {
4
18
  it('getBooleanAttributeValue attrubute', () => {
5
19
  let $el = cheerio.load('<ft-content autoplay></ft-content>')('ft-content')
@@ -20,7 +34,7 @@ describe('tagMappings test', () => {
20
34
  const bodyXML = `
21
35
  <body>
22
36
  <experimental>
23
- <ft-content autoplay=\"false\" caption=\"caption data\" data-asset-type=\"clip\" data-copyright=\"Reuters\"
37
+ <ft-content autoplay=\"false\" caption=\"caption data\" data-asset-type=\"clip\" data-copyright=\"Reuters\"
24
38
  data-layout=\"in-line\" description=\"description\" href=\"https://storytelling-clips.s3.amazonaws.com/World/Joe%20Biden%20on%20debt%20ceiling%20deal%20v1.mp4\"
25
39
  loop=\"true\" muted=\"false\" poster=\"https://d1e00ek4ebabms.cloudfront.net/production/65233b7d-5260-4acc-b01c-38ff470068e0.jpg\"
26
40
  poster-alt=\"\" poster-copyright=\"Reuters\" poster-id=\"db0a46c6-9e60-4f46-bc0b-c158cb8394d0\" type=\"http://www.ft.com/ontology/content/clip\">
@@ -30,8 +44,9 @@ describe('tagMappings test', () => {
30
44
  const selector =
31
45
  'ft-content[type="http://www.ft.com/ontology/content/clip"]'
32
46
  const $el = cheerio.load(bodyXML)(selector)
33
- const mapping: any = tagMappings[selector]($el, () => [])
34
- expect(mapping.type).toBe('clip')
47
+ const mapping = tagMappings[selector]($el, () => [])
48
+
49
+ expectNodeType<OldClip>(mapping, 'clip')
35
50
  expect(mapping.url).toBe(
36
51
  'https://storytelling-clips.s3.amazonaws.com/World/Joe%20Biden%20on%20debt%20ceiling%20deal%20v1.mp4'
37
52
  )
@@ -20,6 +20,7 @@ import {
20
20
  import * as scrollytelling from '@financial-times/n-scrollytelling-image/server'
21
21
  import { LiteralToPrimitiveDeep } from 'type-fest'
22
22
  import { CapiResponse } from '../../model/CapiResponse'
23
+ import type { Cheerio, Element } from 'cheerio'
23
24
 
24
25
  const tableResponsiveStyleMap: Record<string, Table['responsiveStyle']> = {
25
26
  stacked: 'flat',
@@ -623,8 +624,11 @@ const commonTagMappings: TagMappings = {
623
624
  // We can't trust cheerio.attr() method since with attributes like "autoplay"
624
625
  //doesn't return the value instead return "autoplay" and "autoplay" = "false"
625
626
  //should be interpreted as false
626
- export const getBooleanAttributeValue = ($el: any, attribute: string) => {
627
- const value = $el.get(0).attribs[attribute]
627
+ export const getBooleanAttributeValue = (
628
+ $el: Cheerio<Element>,
629
+ attribute: string
630
+ ) => {
631
+ const value = $el.get(0)?.attribs[attribute]
628
632
  return [null, undefined, 'false', false].includes(value) ? false : true
629
633
  }
630
634
 
@@ -11,7 +11,11 @@ interface ContextableCache<TContext extends QueryContext> {
11
11
  }
12
12
 
13
13
  export function isContextableCache<TContext extends QueryContext>(
14
- cache: any
14
+ cache: unknown
15
15
  ): cache is ContextableCache<TContext> {
16
- return 'withContext' in cache
16
+ if (cache && typeof cache === 'object' && 'withContext' in cache) {
17
+ return true
18
+ }
19
+
20
+ return false
17
21
  }