@sitecore-feaas/clientside 0.5.5 → 0.5.7

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 (62) hide show
  1. package/build/cdn.js +3 -2
  2. package/build/cdn.js.map +1 -1
  3. package/build/dom/rendering.js +20 -11
  4. package/build/dom/rendering.js.map +1 -1
  5. package/build/dom/stylesheet.js +17 -8
  6. package/build/dom/stylesheet.js.map +1 -1
  7. package/build/fetch.js +21 -21
  8. package/build/fetch.js.map +1 -1
  9. package/build/utils/data.js +11 -8
  10. package/build/utils/data.js.map +1 -1
  11. package/dist/browser/headless.cjs +7 -4
  12. package/dist/browser/headless.cjs.map +3 -3
  13. package/dist/browser/headless.esm.js +8 -5
  14. package/dist/browser/headless.esm.js.map +1 -1
  15. package/dist/browser/index.cjs +8 -5
  16. package/dist/browser/index.cjs.map +3 -3
  17. package/dist/browser/index.esm.js +8 -5
  18. package/dist/browser/index.esm.js.map +1 -1
  19. package/dist/browser/react.cjs +8 -5
  20. package/dist/browser/react.cjs.map +3 -3
  21. package/dist/browser/react.esm.js +8 -5
  22. package/dist/browser/react.esm.js.map +1 -1
  23. package/dist/node/headless.cjs +8 -5
  24. package/dist/node/headless.cjs.map +3 -3
  25. package/dist/node/headless.esm.js +8 -5
  26. package/dist/node/headless.esm.js.map +3 -3
  27. package/dist/node/index.cjs +7 -4
  28. package/dist/node/index.cjs.map +3 -3
  29. package/dist/node/index.esm.js +7 -4
  30. package/dist/node/index.esm.js.map +3 -3
  31. package/dist/node/react.cjs +7 -4
  32. package/dist/node/react.cjs.map +3 -3
  33. package/dist/node/react.esm.js +7 -4
  34. package/dist/node/react.esm.js.map +3 -3
  35. package/headless.cjs +8 -5
  36. package/headless.cjs.map +3 -3
  37. package/headless.js +8 -5
  38. package/headless.js.map +3 -3
  39. package/package.json +2 -2
  40. package/react.cjs +8 -5
  41. package/react.cjs.map +3 -3
  42. package/react.js +8 -5
  43. package/react.js.map +3 -3
  44. package/src/cdn.ts +3 -1
  45. package/src/dom/rendering.ts +31 -16
  46. package/src/dom/stylesheet.ts +19 -9
  47. package/src/dom/thumbnail.ts +1 -1
  48. package/src/fetch.ts +29 -29
  49. package/src/utils/data.ts +11 -7
  50. package/test/FEAASComponent.react.test.tsx +85 -7
  51. package/test/FEAASStylesheet.test.tsx +104 -2
  52. package/test/dom.test.ts +8 -0
  53. package/types/cdn.d.ts.map +1 -1
  54. package/types/dom/rendering.d.ts.map +1 -1
  55. package/types/dom/stylesheet.d.ts.map +1 -1
  56. package/types/dom/thumbnail.d.ts +1 -1
  57. package/types/dom/thumbnail.d.ts.map +1 -1
  58. package/types/fetch.d.ts +15 -15
  59. package/types/fetch.d.ts.map +1 -1
  60. package/types/utils/data.d.ts +2 -2
  61. package/types/utils/data.d.ts.map +1 -1
  62. package/types/utils/settings.d.ts +5 -5
package/src/cdn.ts CHANGED
@@ -108,6 +108,9 @@ export function getStylesheetURL(props: FEAASCDNStylesheetProps) {
108
108
  props = { src: props }
109
109
  }
110
110
  if ('src' in props) {
111
+ // edge url are always well formed
112
+ if (String(props.src).includes('v1/files/components/styles')) return props.src
113
+
111
114
  props = {
112
115
  ...parseStylesheetSource(props.src)
113
116
  }
@@ -188,7 +191,6 @@ export async function fetchAndRevalidateStylesheet(
188
191
  props: FEAASCDNStylesheetProps,
189
192
  callback: ValidatableStylesheetCallback
190
193
  ) {
191
- if (typeof props == 'string') props = { src: props }
192
194
  return fetchAndRevalidate(
193
195
  getStylesheetURL(props),
194
196
  {
@@ -96,23 +96,33 @@ export function setDOMAttribute(element: HTMLElement, attribute: string, value:
96
96
  } else if (attribute == 'data-embed-src') {
97
97
  loadScript(element, value)
98
98
  } else if (attribute == 'data-path-attributes') {
99
- const oldKeys = element.getAttribute('data-attributes-keys')?.split(',').filter(Boolean) || []
100
- if (!Array.isArray(value))
101
- for (var property in value) {
102
- var subvalue = value[property]
103
- setDOMAttribute(
104
- element,
105
- property,
106
- typeof subvalue == 'object' && subvalue ? JSON.stringify(subvalue) : subvalue,
107
- config
108
- )
109
- }
110
- for (var i = 0; i < oldKeys.length; i++) {
111
- if (value == null || !(oldKeys[i] in value)) {
112
- setDOMAttribute(element, oldKeys[i], null, config)
99
+ if (!Array.isArray(value)) {
100
+ const oldKeys = element.getAttribute('data-attributes-keys')?.split(',').filter(Boolean) || []
101
+ if (!Array.isArray(value))
102
+ for (var property in value) {
103
+ var subvalue = value[property]
104
+ setDOMAttribute(
105
+ element,
106
+ property,
107
+ typeof subvalue == 'object' && subvalue ? JSON.stringify(subvalue) : subvalue,
108
+ config
109
+ )
110
+ }
111
+ for (var i = 0; i < oldKeys.length; i++) {
112
+ if (value == null || !(oldKeys[i] in value)) {
113
+ setDOMAttribute(element, oldKeys[i], null, config)
114
+ }
113
115
  }
116
+ setDOMAttribute(element, 'data-attributes-keys', Object.keys(value || {}).join(','))
117
+ }
118
+ // BYOC components also accept their data object in datasources attribute.
119
+ if (element.tagName == 'FEAAS-EXTERNAL') {
120
+ const datasourceId =
121
+ String(element.getAttribute('data-path-attributes') || '')
122
+ .slice(0, -1)
123
+ .split('.')[0] || '_'
124
+ setDOMAttribute(element, 'datasources', JSON.stringify({ [datasourceId]: value }))
114
125
  }
115
- setDOMAttribute(element, 'data-attributes-keys', Object.keys(value || {}).join(','))
116
126
  return
117
127
  }
118
128
  if (typeof value == 'boolean') {
@@ -198,7 +208,12 @@ export function renderDOMElement(
198
208
  for (var i = 0; i < attrs.length; i++) {
199
209
  const { name, value: datapath } = attrs[i]
200
210
  if (name.startsWith('data-path') && name != 'data-path-scope') {
201
- setDOMAttribute(element, name, queryScopes(datascopes, datapath, true), config)
211
+ setDOMAttribute(
212
+ element,
213
+ name,
214
+ queryScopes(datascopes, datapath, true, undefined, element.tagName != 'FEAAS-EXTERNAL'),
215
+ config
216
+ )
202
217
  }
203
218
  if (name == 'data-embed-src') {
204
219
  setDOMAttribute(element, name, element.getAttribute(name), config)
@@ -2,6 +2,7 @@ import {
2
2
  FEAASCDNStylesheetProps,
3
3
  fetchAndRevalidateStylesheet,
4
4
  getStylesheetURL,
5
+ parseStylesheetSource,
5
6
  ValidatableStylesheetCallback
6
7
  } from '../cdn.js'
7
8
 
@@ -19,15 +20,18 @@ export function renderStylesheetPromise(props: FEAASCDNStylesheetProps, styleshe
19
20
 
20
21
  const validatedStylesheets = new WeakSet<HTMLStyleElement | HTMLLinkElement>()
21
22
  export function loadStylesheet(props: FEAASCDNStylesheetProps, callback?: ValidatableStylesheetCallback) {
22
- var foundStylesheet: HTMLStyleElement | HTMLLinkElement
23
23
  var writableStylesheet: HTMLStyleElement
24
+ var foundStylesheet = findStylesheet(props)
24
25
 
25
- if (foundStylesheet && validatedStylesheets.has(foundStylesheet)) {
26
- return Promise.resolve(foundStylesheet)
26
+ if (foundStylesheet) {
27
+ if (validatedStylesheets.has(foundStylesheet)) {
28
+ return Promise.resolve(foundStylesheet)
29
+ }
30
+ // it can be that page already have stylesheet using alternative URL (e.g. edge url), use that instead
31
+ props = foundStylesheet.getAttribute('data-href') || foundStylesheet.getAttribute('href')
27
32
  }
28
33
 
29
34
  return fetchAndRevalidateStylesheet(props, (cssText, phase) => {
30
- foundStylesheet ||= findStylesheet(props)
31
35
  // dont need to write stylesheet for cached state if we already found a stylesheet
32
36
  if (!(phase == 'initial' && foundStylesheet)) {
33
37
  writableStylesheet ||=
@@ -35,7 +39,7 @@ export function loadStylesheet(props: FEAASCDNStylesheetProps, callback?: Valida
35
39
  writableStylesheet.textContent = cssText
36
40
  }
37
41
  callback?.(cssText, phase)
38
- }).then(() => foundStylesheet || writableStylesheet)
42
+ }).then(() => writableStylesheet || foundStylesheet)
39
43
  }
40
44
 
41
45
  export function loadStylesheetAllowStale(props: FEAASCDNStylesheetProps) {
@@ -44,11 +48,17 @@ export function loadStylesheetAllowStale(props: FEAASCDNStylesheetProps) {
44
48
  })
45
49
  }
46
50
 
51
+ // Find stylesheet on the page for given props, also check by alternative edge url
47
52
  export function findStylesheet(props: FEAASCDNStylesheetProps) {
48
- return (document.head.querySelector(`style[data-href="${getStylesheetURL(props)}"]`) ||
49
- document.querySelector(`link[rel="stylesheet"][href="${getStylesheetURL(props)}"]`)) as
50
- | HTMLStyleElement
51
- | HTMLLinkElement
53
+ const cdnURL = getStylesheetURL(props)
54
+ const { library } = parseStylesheetSource(cdnURL)
55
+ const edgeURL = `/files/components/styles/${library}.css`
56
+ return document.querySelector(
57
+ `style[data-href="${cdnURL}"],
58
+ link[rel="stylesheet"][href="${cdnURL}"],
59
+ style[data-href*="${edgeURL}"],
60
+ link[rel="stylesheet"][href*="${edgeURL}"]`
61
+ ) as HTMLStyleElement | HTMLLinkElement
52
62
  }
53
63
 
54
64
  export function createStylesheet(props: FEAASCDNStylesheetProps) {
@@ -2,7 +2,7 @@ import type { SDK, Style, VersionModel, ComponentModel, StylesheetModel } from '
2
2
  import { fetchAndRevalidate } from '../fetch.js'
3
3
  import { renderComponent } from './component.js'
4
4
 
5
- export type Callback = (image: HTMLImageElement, isCached: boolean) => void
5
+ export type Callback = (image: HTMLImageElement | null, isCached: boolean) => void
6
6
 
7
7
  export const convertBase64toBlob = (base64: string) => fetch(base64).then((res) => res.blob())
8
8
 
package/src/fetch.ts CHANGED
@@ -1,17 +1,5 @@
1
1
  import { ControlledPromise } from './utils/promise.js'
2
2
 
3
- /**
4
- * Utility to cache-bust static files. It relies on reading Date header to detect cached response, so it requires CORS
5
- * settings to be set.
6
- *
7
- * It accepts validator function that determines if response is usable. If response was pulled from cache and is valid,
8
- * the optional callback function is fired right away. Then HEAD request is made bypassing the cache, to see if the
9
- * response has an newer Last-Modified header. In case it does and it passes validation, third request is fired that
10
- * actually fetches the new content and callback is invoked the second time.
11
- *
12
- * It works as promise, but also accepts callback to use cached blobs mid-flight and have access to headers. Any network
13
- * errors will not be caught. Function throws when unable to fetch valid response.
14
- */
15
3
  const phases = ['initial', 'check', 'updated'] as const
16
4
  export type ValidatableRequestPhase = (typeof phases)[number]
17
5
  export type FetchCache = Record<string, FetchCacheRequest>
@@ -38,6 +26,18 @@ export function clearFetchCache() {
38
26
  fetchCache = {}
39
27
  }
40
28
 
29
+ /**
30
+ * Utility to cache-bust static files. It relies on reading Date header to detect cached response, so it requires CORS
31
+ * settings to be set.
32
+ *
33
+ * It accepts validator function that determines if response is usable. If response was pulled from cache and is valid,
34
+ * the optional callback function is fired right away. Then HEAD request is made bypassing the cache, to see if the
35
+ * response has an newer Last-Modified header. In case it does and it passes validation, third request is fired that
36
+ * actually fetches the new content and callback is invoked the second time.
37
+ *
38
+ * It works as promise, but also accepts callback to use cached blobs mid-flight and have access to headers. Any network
39
+ * errors will not be caught. Function throws when unable to fetch valid response.
40
+ */
41
41
  export async function fetchAndRevalidate(
42
42
  url: ValidatableRequest['url'],
43
43
  options?: ValidatableRequest['options'],
@@ -51,23 +51,6 @@ export async function fetchAndRevalidate(
51
51
  .then((result) => result.response)
52
52
  }
53
53
 
54
- export function getFetchCache(url: Parameters<typeof fetch>[0], dontCreate = false) {
55
- const key = String(url).replace('?head', '')
56
- var cache = fetchCache[key]
57
- if (!cache && !dontCreate) {
58
- cache = fetchCache[key] = {
59
- phase: null,
60
- initial: ControlledPromise(),
61
- check: ControlledPromise(),
62
- updated: ControlledPromise(),
63
- final: ControlledPromise()
64
- }
65
- }
66
- return cache
67
- }
68
-
69
- export class InvalidResponse extends Error {}
70
-
71
54
  /**
72
55
  * Executes a fetch request optionally validating and handling the response. Using callback function it's possible to
73
56
  * observe successful response twice: Cached version first, and up-to-date later.
@@ -123,6 +106,23 @@ export async function fetchWithCacheAwareness(
123
106
  }
124
107
  }
125
108
 
109
+ export function getFetchCache(url: Parameters<typeof fetch>[0], dontCreate = false) {
110
+ const key = String(url).replace('?head', '')
111
+ var cache = fetchCache[key]
112
+ if (!cache && !dontCreate) {
113
+ cache = fetchCache[key] = {
114
+ phase: null,
115
+ initial: ControlledPromise(),
116
+ check: ControlledPromise(),
117
+ updated: ControlledPromise(),
118
+ final: ControlledPromise()
119
+ }
120
+ }
121
+ return cache
122
+ }
123
+
124
+ export class InvalidResponse extends Error {}
125
+
126
126
  /**
127
127
  * Validates cache of previousl fetch If the resource is cached and there is a newer version available, it will be
128
128
  * re-fetched.
package/src/utils/data.ts CHANGED
@@ -7,11 +7,15 @@ export function queryObjectRaw(json: any, path: string) {
7
7
  return []
8
8
  }
9
9
  }
10
- export function queryObject(json: any, path: string) {
11
- return queryObjectRaw(json, path)?.flat(Infinity) || []
10
+ export function queryObject(json: any, path: string, flatten = true) {
11
+ const data = queryObjectRaw(json, path) || []
12
+ if (flatten) {
13
+ return data.flat(Infinity)
14
+ }
15
+ return data
12
16
  }
13
17
 
14
- export function queryScopes(scopes: any, datapath: string, singleValue = false, json: any = scopes) {
18
+ export function queryScopes(scopes: any, datapath: string, singleValue = false, json: any = scopes, flatten = true) {
15
19
  var path = datapath
16
20
  /* find closest parent scope */
17
21
  const keys = Object.keys(scopes).sort((b, a) => a.length - b.length)
@@ -30,11 +34,11 @@ export function queryScopes(scopes: any, datapath: string, singleValue = false,
30
34
  }
31
35
  }
32
36
 
33
- var collection = queryObject(json, path)
37
+ var collection = queryObject(json, path, flatten)
34
38
 
35
39
  // If regular path didn't match any data, try fallbacks
36
40
  // datasourceId.wrapper.$.path
37
- if (Array.isArray(collection) && collection?.length == 0) {
41
+ if (collection.length == 0) {
38
42
  collection = [
39
43
  // look up in `_` datasource id (catch-all id is used in JSS)
40
44
  // _.wrapper.$.path
@@ -56,11 +60,11 @@ export function queryScopes(scopes: any, datapath: string, singleValue = false,
56
60
  ]
57
61
  .filter((v, i, a) => a.indexOf(v) === i)
58
62
  .reduce((v, path) => {
59
- return v.length > 0 ? v : queryObject(json, path)
63
+ return v.length > 0 ? v : queryObject(json, path, flatten)
60
64
  }, [] as any[])
61
65
  }
62
66
 
63
- if (singleValue && Array.isArray(collection)) {
67
+ if (singleValue) {
64
68
  return collection[0]
65
69
  } else {
66
70
  return collection
@@ -9,9 +9,11 @@ function Hello(props: { firstName: string; telephone: string }) {
9
9
  return React.createElement(
10
10
  'div',
11
11
  {},
12
- `Hello my name is ${props.firstName} (${typeof props.firstName}) and my tel is ${
13
- props.telephone
14
- } (${typeof props.telephone}). And context value is ${context}`
12
+ `
13
+ Hello my name is ${props.firstName || 'Unknown'} (${typeof props.firstName}) and my tel is ${
14
+ props.telephone || 'Unknown'
15
+ } (${typeof props.telephone}).
16
+ And context value is ${context}`
15
17
  )
16
18
  }
17
19
  const helloSchema = {
@@ -26,6 +28,36 @@ const helloSchema = {
26
28
  }
27
29
  } as const
28
30
 
31
+ function HelloData(props: { firstName: string; telephone: string; datasources: any; superobject: any }) {
32
+ const context = useContext(DataContext)
33
+
34
+ return React.createElement(
35
+ 'div',
36
+ {},
37
+ `
38
+ Hello my name is ${props.firstName || 'Unknown'} (${typeof props.firstName}) and my tel is ${
39
+ props.telephone || 'Unknown'
40
+ } (${typeof props.telephone}).
41
+ And context value is ${context}.
42
+ Typeof datasources: ${typeof props.datasources} with keys ${Object.keys(props.datasources || {})})
43
+ Typeof superobject ${typeof props.superobject}, ${JSON.stringify(props.superobject)})`
44
+ )
45
+ }
46
+ const helloDataSchema = {
47
+ name: 'MyTestDataComponent',
48
+ properties: {
49
+ firstName: {
50
+ type: 'string'
51
+ },
52
+ telephone: {
53
+ type: 'number'
54
+ },
55
+ superobject: {
56
+ type: 'object'
57
+ }
58
+ }
59
+ } as const
60
+
29
61
  export async function validate(react: any, html: string) {
30
62
  const div = document.createElement('div')
31
63
  document.body.appendChild(div)
@@ -123,7 +155,9 @@ describe('React', () => {
123
155
  <section>
124
156
  <ExternalComponent componentName='MyTestComponent' telephone={'12345'} firstName='Yarik' />
125
157
  </section>,
126
- '<section><feaas-external data-external-id="MyTestComponent" telephone="12345" first-name="Yarik" hydrate="false"><div>Hello my name is Yarik (string) and my tel is 12345 (number). And context value is DEFAULT</div></feaas-external></section>'
158
+ '<section><feaas-external data-external-id="MyTestComponent" telephone="12345" first-name="Yarik" hydrate="false"><div>\n' +
159
+ 'Hello my name is Yarik (string) and my tel is 12345 (number).\n' +
160
+ 'And context value is DEFAULT</div></feaas-external></section>'
127
161
  )
128
162
  })
129
163
  it('render wrapped external component with parsed values', async () => {
@@ -137,7 +171,29 @@ describe('React', () => {
137
171
  data={{ abc: 321 }}
138
172
  ></Component>
139
173
  </section>,
140
- '<section><feaas-component class="-feaas" data="{&quot;abc&quot;:321}"><feaas-external data-external-id="MyTestComponent" telephone="12345" first-name="Yarik" hydrate="false"><div>Hello my name is Yarik (string) and my tel is 12345 (number). And context value is DEFAULT</div></feaas-external></feaas-component></section>'
174
+ '<section><feaas-component class="-feaas" data="{&quot;abc&quot;:321}"><feaas-external data-external-id="MyTestComponent" telephone="12345" first-name="Yarik" hydrate="false"><div>\n' +
175
+ 'Hello my name is Yarik (string) and my tel is 12345 (number).\n' +
176
+ 'And context value is DEFAULT</div></feaas-external></feaas-component></section>'
177
+ )
178
+ })
179
+ it('render wrapped external component and parse data object', async () => {
180
+ registerComponent(HelloData, helloDataSchema)
181
+ validate(
182
+ <DataContext.Provider value='INHERITED'>
183
+ <section>
184
+ <Component
185
+ template={
186
+ '<feaas-external data-path-attributes="my.$" first-name="Yarik" data-external-id="MyTestDataComponent"></feaas-external>'
187
+ }
188
+ data={{ my: { telephone: 321, superobject: { a: 1, b: 2 } } }}
189
+ ></Component>
190
+ </section>
191
+ </DataContext.Provider>,
192
+ `<section><feaas-component class="-feaas" data="{&quot;my&quot;:{&quot;telephone&quot;:321,&quot;superobject&quot;:{&quot;a&quot;:1,&quot;b&quot;:2}}}"><feaas-external data-external-id="MyTestDataComponent" telephone="321" superobject="{&quot;a&quot;:1,&quot;b&quot;:2}" data-path-attributes="my.$" first-name="Yarik" data-attributes-keys="telephone,superobject" datasources="{&quot;my&quot;:{&quot;telephone&quot;:321,&quot;superobject&quot;:{&quot;a&quot;:1,&quot;b&quot;:2}}}" hydrate="false"><div>
193
+ Hello my name is Yarik (string) and my tel is 321 (number).
194
+ And context value is INHERITED.
195
+ Typeof datasources: object with keys my)
196
+ Typeof superobject object, {"a":1,"b":2})</div></feaas-external></feaas-component></section>`
141
197
  )
142
198
  })
143
199
  it('render wrapped external component with context provider', async () => {
@@ -153,7 +209,9 @@ describe('React', () => {
153
209
  ></Component>
154
210
  </section>
155
211
  </DataContext.Provider>,
156
- '<section><feaas-component class="-feaas" data="{&quot;abc&quot;:321}"><feaas-external data-external-id="MyTestComponent" telephone="12345" first-name="Yarik" hydrate="false"><div>Hello my name is Yarik (string) and my tel is 12345 (number). And context value is INHERITED</div></feaas-external></feaas-component></section>'
212
+ '<section><feaas-component class="-feaas" data="{&quot;abc&quot;:321}"><feaas-external data-external-id="MyTestComponent" telephone="12345" first-name="Yarik" hydrate="false"><div>\n' +
213
+ 'Hello my name is Yarik (string) and my tel is 12345 (number).\n' +
214
+ 'And context value is INHERITED</div></feaas-external></feaas-component></section>'
157
215
  )
158
216
  })
159
217
  it('render wrapped external component with context provider and data mapping', async () => {
@@ -169,7 +227,27 @@ describe('React', () => {
169
227
  ></Component>
170
228
  </section>
171
229
  </DataContext.Provider>,
172
- '<section><feaas-component class="-feaas" data="{&quot;telephone&quot;:321}"><feaas-external data-external-id="MyTestComponent" data-path-attributes="$" first-name="Yarik" telephone="321" data-attributes-keys="telephone" hydrate="false"><div>Hello my name is Yarik (string) and my tel is 321 (number). And context value is INHERITED</div></feaas-external></feaas-component></section>'
230
+ '<section><feaas-component class="-feaas" data="{&quot;telephone&quot;:321}"><feaas-external data-external-id="MyTestComponent" telephone="321" data-path-attributes="$" first-name="Yarik" data-attributes-keys="telephone" datasources="{&quot;_&quot;:{&quot;telephone&quot;:321}}" hydrate="false"><div>\n' +
231
+ 'Hello my name is Yarik (string) and my tel is 321 (number).\n' +
232
+ 'And context value is INHERITED</div></feaas-external></feaas-component></section>'
233
+ )
234
+ })
235
+ it('render not map attributes of external component with given array', async () => {
236
+ registerComponent(Hello, helloSchema)
237
+ validate(
238
+ <DataContext.Provider value='INHERITED'>
239
+ <section>
240
+ <Component
241
+ template={
242
+ '<feaas-external first-name="Yarik" data-path-attributes="$" data-external-id="MyTestComponent"></feaas-external>'
243
+ }
244
+ data={[{ telephone: 321 }]}
245
+ ></Component>
246
+ </section>
247
+ </DataContext.Provider>,
248
+ '<section><feaas-component class="-feaas" data="[{&quot;telephone&quot;:321}]"><feaas-external data-external-id="MyTestComponent" first-name="Yarik" data-path-attributes="$" datasources="{&quot;_&quot;:[{&quot;telephone&quot;:321}]}" hydrate="false"><div>\n' +
249
+ 'Hello my name is Yarik (string) and my tel is Unknown (undefined).\n' +
250
+ 'And context value is INHERITED</div></feaas-external></feaas-component></section>'
173
251
  )
174
252
  })
175
253
  })
@@ -1,7 +1,7 @@
1
1
  import { afterAll, beforeEach, beforeAll, describe, expect, it, vi } from 'vitest'
2
2
  import { FEAASStylesheet } from '../src/components/FEAASStylesheet.js'
3
3
  import { renderDOMContent } from '../src/dom/rendering.js'
4
- import { clearFetchCache, DEFAULT_CDN_URL, loadStylesheet } from '../src/headless.js'
4
+ import { clearFetchCache, DEFAULT_CDN_URL, findStylesheet, loadStylesheet } from '../src/headless.js'
5
5
 
6
6
  const earliest = new Date(2000, 1, 1, 0, 0, 0)
7
7
  const earlier = new Date(2000, 1, 2, 0, 0, 0)
@@ -179,5 +179,107 @@ describe('Stylesheet', () => {
179
179
  await expect(loadStylesheet(`http://CDN/L/published.css`).then((r) => r.textContent)).resolves.toEqual('FRESH {}')
180
180
  })
181
181
 
182
- it('should ')
182
+ describe('.findStylesheet', () => {
183
+ it('should find FEAASStylesheet', async () => {
184
+ const spy = vi.spyOn(global, 'fetch')
185
+ spy.mockImplementation(async (url: string, options: Parameters<typeof fetch>[1] = {}) => {
186
+ // Serve from cache
187
+ return new Response('CSS {}', {
188
+ headers: {
189
+ date: earlier.toUTCString(),
190
+ 'last-modified': earliest.toUTCString()
191
+ }
192
+ })
193
+ })
194
+
195
+ document.body.innerHTML = '<feaas-stylesheet library="L" cdn="https://CDN" revision="staged"></feaas-stylesheet>'
196
+ const stylesheet = document.body.firstElementChild as FEAASStylesheet
197
+ await stylesheet.whenRendered
198
+ expect(findStylesheet({ library: 'L', cdn: 'https://CDN', revision: 'staged' })?.textContent).toEqual('CSS {}')
199
+ })
200
+ })
201
+ it('should find stylesheet by its edge url', async () => {
202
+ document.body.innerHTML =
203
+ '<link rel="http://edge-platform-staging.sitecore-staging.cloud/v1/files/components/styles/L.css?sitecoreContextId=abc/>'
204
+ expect(findStylesheet({ library: 'L', cdn: 'https://CDN', revision: 'staged' })).toEqual(
205
+ document.body.firstElementChild
206
+ )
207
+ expect(findStylesheet({ library: 'L', cdn: 'https://CDN', revision: 'published' })).toEqual(
208
+ document.body.firstElementChild
209
+ )
210
+ expect(findStylesheet({ library: 'T', cdn: 'https://CDN', revision: 'staged' })).toEqual(null)
211
+ expect(findStylesheet({ library: 'T', cdn: 'https://CDN', revision: 'published' })).toEqual(null)
212
+ })
213
+ it('should reload stylesheet embedded as edge url', async () => {
214
+ const spy = vi.spyOn(global, 'fetch')
215
+ spy.mockImplementation(async (url: string, options: Parameters<typeof fetch>[1] = {}) => {
216
+ if (
217
+ !url.includes(
218
+ 'http://edge-platform-staging.sitecore-staging.cloud/v1/files/components/styles/L.css?sitecoreContextId=abc'
219
+ )
220
+ )
221
+ return
222
+
223
+ if (options?.method != 'HEAD') {
224
+ // Serve from cache
225
+ return new Response('YESTERDAY {}', {
226
+ headers: {
227
+ date: earlier.toUTCString(),
228
+ 'last-modified': earliest.toUTCString()
229
+ }
230
+ })
231
+ } else if (options?.method == 'HEAD') {
232
+ return new Response(null, {
233
+ headers: {
234
+ date: now.toUTCString(),
235
+ 'last-modified': earlier.toUTCString()
236
+ }
237
+ })
238
+ } else {
239
+ return new Response('FRESH {}', {
240
+ headers: {
241
+ date: now.toUTCString(),
242
+ 'last-modified': earlier.toUTCString()
243
+ }
244
+ })
245
+ }
246
+ })
247
+
248
+ document.body.innerHTML =
249
+ '<link rel="stylesheet" href="http://edge-platform-staging.sitecore-staging.cloud/v1/files/components/styles/L.css?sitecoreContextId=abc" />'
250
+
251
+ const stylesheet = await loadStylesheet({ library: 'L', cdn: 'https://CDN', revision: 'staged' })
252
+ expect(stylesheet?.tagName).toEqual('STYLE')
253
+ expect(stylesheet?.getAttribute('data-href')).toEqual(
254
+ 'http://edge-platform-staging.sitecore-staging.cloud/v1/files/components/styles/L.css?sitecoreContextId=abc'
255
+ )
256
+ })
257
+ it("should not attempt to reload edge stylesheet if it's up to date", async () => {
258
+ const spy = vi.spyOn(global, 'fetch')
259
+ spy.mockImplementation(async (url: string, options: Parameters<typeof fetch>[1] = {}) => {
260
+ if (
261
+ !url.includes(
262
+ 'http://edge-platform-staging.sitecore-staging.cloud/v1/files/components/styles/L.css?sitecoreContextId=abc'
263
+ )
264
+ )
265
+ return
266
+
267
+ if (options?.method != 'HEAD') {
268
+ // Serve from cache
269
+ return new Response('YESTERDAY {}', {
270
+ headers: {
271
+ date: now.toUTCString(),
272
+ 'last-modified': earliest.toUTCString()
273
+ }
274
+ })
275
+ }
276
+ })
277
+
278
+ document.body.innerHTML =
279
+ '<link rel="stylesheet" href="http://edge-platform-staging.sitecore-staging.cloud/v1/files/components/styles/L.css?sitecoreContextId=abc" />'
280
+
281
+ const stylesheet = await loadStylesheet({ library: 'L', cdn: 'https://CDN', revision: 'staged' })
282
+ expect(stylesheet?.tagName).toEqual('LINK')
283
+ expect(stylesheet).toEqual(document.body.firstElementChild)
284
+ })
183
285
  })
package/test/dom.test.ts CHANGED
@@ -173,6 +173,14 @@ describe('DOM Clientside', function () {
173
173
  '<div data-path-attributes="test" a="a.jpg" b="2" c="{&quot;user&quot;:&quot;yarik&quot;}" data-attributes-keys="a,b,c"></div>'
174
174
  )
175
175
  })
176
+ /*
177
+ it('should render attributes object with global top level fallback', function () {
178
+ assertRenderedHTML(
179
+ `<div data-path-attributes="test"></div>`,
180
+ { a: 'a.jpg', b: 2, c: { user: 'yarik' } },
181
+ '<div data-path-attributes="test" a="a.jpg" b="2" c="{&quot;user&quot;:&quot;yarik&quot;}" data-attributes-keys="a,b,c"></div>'
182
+ )
183
+ }) */
176
184
  it('should render attributes in dynamic html', function () {
177
185
  assertRenderedHTML(
178
186
  `<div data-path="html"></div>`,
@@ -1 +1 @@
1
- {"version":3,"file":"cdn.d.ts","sourceRoot":"","sources":["../src/cdn.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,uBAAuB,EACxB,MAAM,YAAY,CAAA;AAEnB,eAAO,MAAM,eAAe,wCAAwC,CAAA;AACpE,MAAM,MAAM,uBAAuB,GAAG;IACpC,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,QAAQ,CAAC,EAAE,QAAQ,GAAG,WAAW,GAAG,OAAO,GAAG,MAAM,CAAA;IACpD,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,CAAA;AACD,MAAM,MAAM,uBAAuB,GAAG;IACpC,GAAG,EAAE,MAAM,CAAA;CACZ,CAAA;AACD,MAAM,MAAM,qCAAqC,GAAG;IAClD,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,CAAA;AACD,MAAM,MAAM,sBAAsB,GAAG,CAAC,uBAAuB,GAAG,uBAAuB,CAAC,GACtF,qCAAqC,CAAA;AAEvC,MAAM,WAAW,wBAAwB;IACvC,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,QAAQ,GAAG,WAAW,GAAG,OAAO,GAAG,MAAM,CAAA;IAEpD;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,MAAM,wBAAwB,GAAG;IACrC,GAAG,EAAE,MAAM,CAAA;CACZ,CAAA;AACD,MAAM,MAAM,uBAAuB,GAAG,wBAAwB,GAAG,wBAAwB,GAAG,MAAM,CAAA;AAElG,wBAAgB,oBAAoB,CAAC,MAAM,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,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,uBAAuB,EAAE,UAAU,CAAC,EAAE,gBAAgB,6BAKpG;AAGD,wBAAgB,cAAc,CAAC,KAAK,EAAE,uBAAuB,EAAE,QAAQ,CAAC,EAAE,6BAA6B,6BAkBtG;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,uBAAuB,oBAItE;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,uBAAuB,sCAK5D;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,uBAAuB,oBAM9D"}
1
+ {"version":3,"file":"stylesheet.d.ts","sourceRoot":"","sources":["../../src/dom/stylesheet.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EAIvB,6BAA6B,EAC9B,MAAM,WAAW,CAAA;AAElB,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,uBAAuB,EAAE,KAAK,CAAC,EAAE,gBAAgB,oBAGxF;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,uBAAuB,EAAE,UAAU,CAAC,EAAE,gBAAgB,6BAKpG;AAGD,wBAAgB,cAAc,CAAC,KAAK,EAAE,uBAAuB,EAAE,QAAQ,CAAC,EAAE,6BAA6B,6BAqBtG;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,uBAAuB,oBAItE;AAGD,wBAAgB,cAAc,CAAC,KAAK,EAAE,uBAAuB,sCAU5D;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,uBAAuB,oBAM9D"}
@@ -1,5 +1,5 @@
1
1
  import type { VersionModel, ComponentModel, StylesheetModel } from '@sitecore-feaas/sdk';
2
- export type Callback = (image: HTMLImageElement, isCached: boolean) => void;
2
+ export type Callback = (image: HTMLImageElement | null, isCached: boolean) => void;
3
3
  export declare const convertBase64toBlob: (base64: string) => Promise<Blob>;
4
4
  /** Parse fetch response as blob and turn it into HTMLImageElement off thread */
5
5
  export declare const responseToImage: (response: Response) => Promise<HTMLImageElement>;
@@ -1 +1 @@
1
- {"version":3,"file":"thumbnail.d.ts","sourceRoot":"","sources":["../../src/dom/thumbnail.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAc,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAIpG,MAAM,MAAM,QAAQ,GAAG,CAAC,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAA;AAE3E,eAAO,MAAM,mBAAmB,WAAY,MAAM,kBAA4C,CAAA;AAE9F,gFAAgF;AAChF,eAAO,MAAM,eAAe,aAAc,QAAQ,KAAG,QAAQ,gBAAgB,CAUzE,CAAA;AAEJ;;;;;;;;;GASG;AACH,wBAAsB,sBAAsB,CAAC,SAAS,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC,CAG7F;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,GAAG,CAAC,SAAS,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE,YAAY,EAAE,QAAQ,CAAC,EAAE,QAAQ,6BAqB/F;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,IAAI,CACxB,SAAS,EAAE,cAAc,EACzB,OAAO,CAAC,EAAE,YAAY,EACtB,QAAQ,CAAC,EAAE,QAAQ,GAClB,OAAO,CAAC,gBAAgB,CAAC,CAmC3B;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,QAAQ,CAAC,SAAS,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE,YAAY,EAAE,gBAAgB,CAAC,EAAE,eAAe,6BAsBnH;AAuFD;;;;;;;;;;;GAWG;AACH,wBAAsB,MAAM,CAAC,SAAS,EAAE,cAAc,EAAE,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CA+B1G"}
1
+ {"version":3,"file":"thumbnail.d.ts","sourceRoot":"","sources":["../../src/dom/thumbnail.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAc,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAIpG,MAAM,MAAM,QAAQ,GAAG,CAAC,KAAK,EAAE,gBAAgB,GAAG,IAAI,EAAE,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAA;AAElF,eAAO,MAAM,mBAAmB,WAAY,MAAM,kBAA4C,CAAA;AAE9F,gFAAgF;AAChF,eAAO,MAAM,eAAe,aAAc,QAAQ,KAAG,QAAQ,gBAAgB,CAUzE,CAAA;AAEJ;;;;;;;;;GASG;AACH,wBAAsB,sBAAsB,CAAC,SAAS,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC,CAG7F;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,GAAG,CAAC,SAAS,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE,YAAY,EAAE,QAAQ,CAAC,EAAE,QAAQ,6BAqB/F;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,IAAI,CACxB,SAAS,EAAE,cAAc,EACzB,OAAO,CAAC,EAAE,YAAY,EACtB,QAAQ,CAAC,EAAE,QAAQ,GAClB,OAAO,CAAC,gBAAgB,CAAC,CAmC3B;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,QAAQ,CAAC,SAAS,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE,YAAY,EAAE,gBAAgB,CAAC,EAAE,eAAe,6BAsBnH;AAuFD;;;;;;;;;;;GAWG;AACH,wBAAsB,MAAM,CAAC,SAAS,EAAE,cAAc,EAAE,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CA+B1G"}
package/types/fetch.d.ts CHANGED
@@ -1,16 +1,4 @@
1
1
  import { ControlledPromise } from './utils/promise.js';
2
- /**
3
- * Utility to cache-bust static files. It relies on reading Date header to detect cached response, so it requires CORS
4
- * settings to be set.
5
- *
6
- * It accepts validator function that determines if response is usable. If response was pulled from cache and is valid,
7
- * the optional callback function is fired right away. Then HEAD request is made bypassing the cache, to see if the
8
- * response has an newer Last-Modified header. In case it does and it passes validation, third request is fired that
9
- * actually fetches the new content and callback is invoked the second time.
10
- *
11
- * It works as promise, but also accepts callback to use cached blobs mid-flight and have access to headers. Any network
12
- * errors will not be caught. Function throws when unable to fetch valid response.
13
- */
14
2
  declare const phases: readonly ["initial", "check", "updated"];
15
3
  export type ValidatableRequestPhase = (typeof phases)[number];
16
4
  export type FetchCache = Record<string, FetchCacheRequest>;
@@ -32,10 +20,19 @@ export type FetchCacheRequest = {
32
20
  };
33
21
  export declare var fetchCache: Record<string, FetchCacheRequest>;
34
22
  export declare function clearFetchCache(): void;
23
+ /**
24
+ * Utility to cache-bust static files. It relies on reading Date header to detect cached response, so it requires CORS
25
+ * settings to be set.
26
+ *
27
+ * It accepts validator function that determines if response is usable. If response was pulled from cache and is valid,
28
+ * the optional callback function is fired right away. Then HEAD request is made bypassing the cache, to see if the
29
+ * response has an newer Last-Modified header. In case it does and it passes validation, third request is fired that
30
+ * actually fetches the new content and callback is invoked the second time.
31
+ *
32
+ * It works as promise, but also accepts callback to use cached blobs mid-flight and have access to headers. Any network
33
+ * errors will not be caught. Function throws when unable to fetch valid response.
34
+ */
35
35
  export declare function fetchAndRevalidate(url: ValidatableRequest['url'], options?: ValidatableRequest['options'], validator?: ValidatableRequest['validator'], callback?: ValidatableRequest['callback'], cache?: FetchCache): Promise<Response>;
36
- export declare function getFetchCache(url: Parameters<typeof fetch>[0], dontCreate?: boolean): FetchCacheRequest;
37
- export declare class InvalidResponse extends Error {
38
- }
39
36
  /**
40
37
  * Executes a fetch request optionally validating and handling the response. Using callback function it's possible to
41
38
  * observe successful response twice: Cached version first, and up-to-date later.
@@ -61,6 +58,9 @@ export declare function fetchWithCacheAwareness({ url, options, validator, callb
61
58
  callback: (response: Response, status: "initial" | "check" | "updated", isCached: boolean) => any;
62
59
  cache: FetchCache;
63
60
  }>;
61
+ export declare function getFetchCache(url: Parameters<typeof fetch>[0], dontCreate?: boolean): FetchCacheRequest;
62
+ export declare class InvalidResponse extends Error {
63
+ }
64
64
  /**
65
65
  * Validates cache of previousl fetch If the resource is cached and there is a newer version available, it will be
66
66
  * re-fetched.