@agility/content-fetch 2.0.0-rc21 → 2.0.0-rc24
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/.nyc_output/713b1ec2-05ec-4b67-8061-b6cad0a45ad5.json +1 -0
- package/README.md +36 -32
- package/coverage/base.css +223 -0
- package/coverage/block-navigation.js +79 -0
- package/coverage/index.html +123 -0
- package/coverage/prettify.css +1 -0
- package/coverage/prettify.js +2 -0
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +170 -0
- package/coverage/src/api-client.js.html +549 -0
- package/coverage/src/content-fetch.js.html +336 -0
- package/coverage/src/index.html +123 -0
- package/coverage/src/methods/getContentItem.js.html +285 -0
- package/coverage/src/methods/getContentList.js.html +486 -0
- package/coverage/src/methods/getGallery.js.html +243 -0
- package/coverage/src/methods/getPage.js.html +273 -0
- package/coverage/src/methods/getSitemapFlat.js.html +240 -0
- package/coverage/src/methods/getSitemapNested.js.html +231 -0
- package/coverage/src/methods/getSyncContent.js.html +258 -0
- package/coverage/src/methods/getSyncPages.js.html +258 -0
- package/coverage/src/methods/getUrlRedirections.js.html +339 -0
- package/coverage/src/methods/index.html +201 -0
- package/coverage/src/methods/syncContentItems.js.html +186 -0
- package/coverage/src/methods/syncPageItems.js.html +186 -0
- package/coverage/src/types/FilterLogicOperator.js.html +129 -0
- package/coverage/src/types/FilterOperator.js.html +156 -0
- package/coverage/src/types/SortDirection.js.html +129 -0
- package/coverage/src/types/index.html +123 -0
- package/coverage/src/utils.js.html +330 -0
- package/dist/browser.js +30 -10
- package/dist/index.d.ts +2 -1
- package/dist/methods/getContentItem.d.ts +1 -1
- package/dist/node.js +30 -10
- package/dist/types/Config.d.ts +29 -0
- package/dist/types/ContentItemReference.d.ts +5 -0
- package/dist/types/ContentReference.d.ts +5 -0
- package/dist/types/ContentZone.d.ts +2 -1
- package/dist/types/Filter.d.ts +2 -2
- package/dist/utils.d.ts +10 -3
- package/package.json +2 -2
- package/dist/agility-content-fetch.node.js +0 -11377
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<title>Code coverage report for src/utils.js</title>
|
|
5
|
+
<meta charset="utf-8" />
|
|
6
|
+
<link rel="stylesheet" href="../prettify.css" />
|
|
7
|
+
<link rel="stylesheet" href="../base.css" />
|
|
8
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
9
|
+
<style type='text/css'>
|
|
10
|
+
.coverage-summary .sorter {
|
|
11
|
+
background-image: url(../sort-arrow-sprite.png);
|
|
12
|
+
}
|
|
13
|
+
</style>
|
|
14
|
+
</head>
|
|
15
|
+
<body>
|
|
16
|
+
<div class='wrapper'>
|
|
17
|
+
<div class='pad1'>
|
|
18
|
+
<h1>
|
|
19
|
+
<a href="../index.html">All files</a> / <a href="index.html">src</a> utils.js
|
|
20
|
+
</h1>
|
|
21
|
+
<div class='clearfix'>
|
|
22
|
+
<div class='fl pad1y space-right2'>
|
|
23
|
+
<span class="strong">83.08% </span>
|
|
24
|
+
<span class="quiet">Statements</span>
|
|
25
|
+
<span class='fraction'>54/65</span>
|
|
26
|
+
</div>
|
|
27
|
+
<div class='fl pad1y space-right2'>
|
|
28
|
+
<span class="strong">73.68% </span>
|
|
29
|
+
<span class="quiet">Branches</span>
|
|
30
|
+
<span class='fraction'>28/38</span>
|
|
31
|
+
</div>
|
|
32
|
+
<div class='fl pad1y space-right2'>
|
|
33
|
+
<span class="strong">66.67% </span>
|
|
34
|
+
<span class="quiet">Functions</span>
|
|
35
|
+
<span class='fraction'>8/12</span>
|
|
36
|
+
</div>
|
|
37
|
+
<div class='fl pad1y space-right2'>
|
|
38
|
+
<span class="strong">85.71% </span>
|
|
39
|
+
<span class="quiet">Lines</span>
|
|
40
|
+
<span class='fraction'>30/35</span>
|
|
41
|
+
</div>
|
|
42
|
+
</div>
|
|
43
|
+
<p class="quiet">
|
|
44
|
+
Press <em>n</em> or <em>j</em> to go to the next uncovered block, <em>b</em>, <em>p</em> or <em>k</em> for the previous block.
|
|
45
|
+
</p>
|
|
46
|
+
</div>
|
|
47
|
+
<div class='status-line high'></div>
|
|
48
|
+
<pre><table class="coverage">
|
|
49
|
+
<tr><td class="line-count quiet"><a name='L1'></a><a href='#L1'>1</a>
|
|
50
|
+
<a name='L2'></a><a href='#L2'>2</a>
|
|
51
|
+
<a name='L3'></a><a href='#L3'>3</a>
|
|
52
|
+
<a name='L4'></a><a href='#L4'>4</a>
|
|
53
|
+
<a name='L5'></a><a href='#L5'>5</a>
|
|
54
|
+
<a name='L6'></a><a href='#L6'>6</a>
|
|
55
|
+
<a name='L7'></a><a href='#L7'>7</a>
|
|
56
|
+
<a name='L8'></a><a href='#L8'>8</a>
|
|
57
|
+
<a name='L9'></a><a href='#L9'>9</a>
|
|
58
|
+
<a name='L10'></a><a href='#L10'>10</a>
|
|
59
|
+
<a name='L11'></a><a href='#L11'>11</a>
|
|
60
|
+
<a name='L12'></a><a href='#L12'>12</a>
|
|
61
|
+
<a name='L13'></a><a href='#L13'>13</a>
|
|
62
|
+
<a name='L14'></a><a href='#L14'>14</a>
|
|
63
|
+
<a name='L15'></a><a href='#L15'>15</a>
|
|
64
|
+
<a name='L16'></a><a href='#L16'>16</a>
|
|
65
|
+
<a name='L17'></a><a href='#L17'>17</a>
|
|
66
|
+
<a name='L18'></a><a href='#L18'>18</a>
|
|
67
|
+
<a name='L19'></a><a href='#L19'>19</a>
|
|
68
|
+
<a name='L20'></a><a href='#L20'>20</a>
|
|
69
|
+
<a name='L21'></a><a href='#L21'>21</a>
|
|
70
|
+
<a name='L22'></a><a href='#L22'>22</a>
|
|
71
|
+
<a name='L23'></a><a href='#L23'>23</a>
|
|
72
|
+
<a name='L24'></a><a href='#L24'>24</a>
|
|
73
|
+
<a name='L25'></a><a href='#L25'>25</a>
|
|
74
|
+
<a name='L26'></a><a href='#L26'>26</a>
|
|
75
|
+
<a name='L27'></a><a href='#L27'>27</a>
|
|
76
|
+
<a name='L28'></a><a href='#L28'>28</a>
|
|
77
|
+
<a name='L29'></a><a href='#L29'>29</a>
|
|
78
|
+
<a name='L30'></a><a href='#L30'>30</a>
|
|
79
|
+
<a name='L31'></a><a href='#L31'>31</a>
|
|
80
|
+
<a name='L32'></a><a href='#L32'>32</a>
|
|
81
|
+
<a name='L33'></a><a href='#L33'>33</a>
|
|
82
|
+
<a name='L34'></a><a href='#L34'>34</a>
|
|
83
|
+
<a name='L35'></a><a href='#L35'>35</a>
|
|
84
|
+
<a name='L36'></a><a href='#L36'>36</a>
|
|
85
|
+
<a name='L37'></a><a href='#L37'>37</a>
|
|
86
|
+
<a name='L38'></a><a href='#L38'>38</a>
|
|
87
|
+
<a name='L39'></a><a href='#L39'>39</a>
|
|
88
|
+
<a name='L40'></a><a href='#L40'>40</a>
|
|
89
|
+
<a name='L41'></a><a href='#L41'>41</a>
|
|
90
|
+
<a name='L42'></a><a href='#L42'>42</a>
|
|
91
|
+
<a name='L43'></a><a href='#L43'>43</a>
|
|
92
|
+
<a name='L44'></a><a href='#L44'>44</a>
|
|
93
|
+
<a name='L45'></a><a href='#L45'>45</a>
|
|
94
|
+
<a name='L46'></a><a href='#L46'>46</a>
|
|
95
|
+
<a name='L47'></a><a href='#L47'>47</a>
|
|
96
|
+
<a name='L48'></a><a href='#L48'>48</a>
|
|
97
|
+
<a name='L49'></a><a href='#L49'>49</a>
|
|
98
|
+
<a name='L50'></a><a href='#L50'>50</a>
|
|
99
|
+
<a name='L51'></a><a href='#L51'>51</a>
|
|
100
|
+
<a name='L52'></a><a href='#L52'>52</a>
|
|
101
|
+
<a name='L53'></a><a href='#L53'>53</a>
|
|
102
|
+
<a name='L54'></a><a href='#L54'>54</a>
|
|
103
|
+
<a name='L55'></a><a href='#L55'>55</a>
|
|
104
|
+
<a name='L56'></a><a href='#L56'>56</a>
|
|
105
|
+
<a name='L57'></a><a href='#L57'>57</a>
|
|
106
|
+
<a name='L58'></a><a href='#L58'>58</a>
|
|
107
|
+
<a name='L59'></a><a href='#L59'>59</a>
|
|
108
|
+
<a name='L60'></a><a href='#L60'>60</a>
|
|
109
|
+
<a name='L61'></a><a href='#L61'>61</a>
|
|
110
|
+
<a name='L62'></a><a href='#L62'>62</a>
|
|
111
|
+
<a name='L63'></a><a href='#L63'>63</a>
|
|
112
|
+
<a name='L64'></a><a href='#L64'>64</a>
|
|
113
|
+
<a name='L65'></a><a href='#L65'>65</a>
|
|
114
|
+
<a name='L66'></a><a href='#L66'>66</a>
|
|
115
|
+
<a name='L67'></a><a href='#L67'>67</a>
|
|
116
|
+
<a name='L68'></a><a href='#L68'>68</a>
|
|
117
|
+
<a name='L69'></a><a href='#L69'>69</a>
|
|
118
|
+
<a name='L70'></a><a href='#L70'>70</a>
|
|
119
|
+
<a name='L71'></a><a href='#L71'>71</a>
|
|
120
|
+
<a name='L72'></a><a href='#L72'>72</a>
|
|
121
|
+
<a name='L73'></a><a href='#L73'>73</a>
|
|
122
|
+
<a name='L74'></a><a href='#L74'>74</a>
|
|
123
|
+
<a name='L75'></a><a href='#L75'>75</a>
|
|
124
|
+
<a name='L76'></a><a href='#L76'>76</a>
|
|
125
|
+
<a name='L77'></a><a href='#L77'>77</a>
|
|
126
|
+
<a name='L78'></a><a href='#L78'>78</a>
|
|
127
|
+
<a name='L79'></a><a href='#L79'>79</a>
|
|
128
|
+
<a name='L80'></a><a href='#L80'>80</a>
|
|
129
|
+
<a name='L81'></a><a href='#L81'>81</a>
|
|
130
|
+
<a name='L82'></a><a href='#L82'>82</a>
|
|
131
|
+
<a name='L83'></a><a href='#L83'>83</a>
|
|
132
|
+
<a name='L84'></a><a href='#L84'>84</a>
|
|
133
|
+
<a name='L85'></a><a href='#L85'>85</a>
|
|
134
|
+
<a name='L86'></a><a href='#L86'>86</a>
|
|
135
|
+
<a name='L87'></a><a href='#L87'>87</a>
|
|
136
|
+
<a name='L88'></a><a href='#L88'>88</a></td><td class="line-coverage quiet"><span class="cline-any cline-yes">58x</span>
|
|
137
|
+
<span class="cline-any cline-no"> </span>
|
|
138
|
+
<span class="cline-any cline-neutral"> </span>
|
|
139
|
+
<span class="cline-any cline-neutral"> </span>
|
|
140
|
+
<span class="cline-any cline-neutral"> </span>
|
|
141
|
+
<span class="cline-any cline-no"> </span>
|
|
142
|
+
<span class="cline-any cline-neutral"> </span>
|
|
143
|
+
<span class="cline-any cline-neutral"> </span>
|
|
144
|
+
<span class="cline-any cline-neutral"> </span>
|
|
145
|
+
<span class="cline-any cline-yes">29x</span>
|
|
146
|
+
<span class="cline-any cline-neutral"> </span>
|
|
147
|
+
<span class="cline-any cline-yes">29x</span>
|
|
148
|
+
<span class="cline-any cline-yes">5x</span>
|
|
149
|
+
<span class="cline-any cline-neutral"> </span>
|
|
150
|
+
<span class="cline-any cline-yes">24x</span>
|
|
151
|
+
<span class="cline-any cline-neutral"> </span>
|
|
152
|
+
<span class="cline-any cline-neutral"> </span>
|
|
153
|
+
<span class="cline-any cline-yes">29x</span>
|
|
154
|
+
<span class="cline-any cline-yes">29x</span>
|
|
155
|
+
<span class="cline-any cline-neutral"> </span>
|
|
156
|
+
<span class="cline-any cline-neutral"> </span>
|
|
157
|
+
<span class="cline-any cline-neutral"> </span>
|
|
158
|
+
<span class="cline-any cline-yes">9x</span>
|
|
159
|
+
<span class="cline-any cline-yes">9x</span>
|
|
160
|
+
<span class="cline-any cline-neutral"> </span>
|
|
161
|
+
<span class="cline-any cline-yes">9x</span>
|
|
162
|
+
<span class="cline-any cline-yes">1x</span>
|
|
163
|
+
<span class="cline-any cline-yes">1x</span>
|
|
164
|
+
<span class="cline-any cline-no"> </span>
|
|
165
|
+
<span class="cline-any cline-neutral"> </span>
|
|
166
|
+
<span class="cline-any cline-neutral"> </span>
|
|
167
|
+
<span class="cline-any cline-neutral"> </span>
|
|
168
|
+
<span class="cline-any cline-yes">9x</span>
|
|
169
|
+
<span class="cline-any cline-no"> </span>
|
|
170
|
+
<span class="cline-any cline-neutral"> </span>
|
|
171
|
+
<span class="cline-any cline-neutral"> </span>
|
|
172
|
+
<span class="cline-any cline-yes">9x</span>
|
|
173
|
+
<span class="cline-any cline-no"> </span>
|
|
174
|
+
<span class="cline-any cline-neutral"> </span>
|
|
175
|
+
<span class="cline-any cline-neutral"> </span>
|
|
176
|
+
<span class="cline-any cline-yes">9x</span>
|
|
177
|
+
<span class="cline-any cline-yes">2x</span>
|
|
178
|
+
<span class="cline-any cline-yes">2x</span>
|
|
179
|
+
<span class="cline-any cline-yes">4x</span>
|
|
180
|
+
<span class="cline-any cline-yes">4x</span>
|
|
181
|
+
<span class="cline-any cline-neutral"> </span>
|
|
182
|
+
<span class="cline-any cline-yes">2x</span>
|
|
183
|
+
<span class="cline-any cline-neutral"> </span>
|
|
184
|
+
<span class="cline-any cline-neutral"> </span>
|
|
185
|
+
<span class="cline-any cline-yes">9x</span>
|
|
186
|
+
<span class="cline-any cline-yes">1x</span>
|
|
187
|
+
<span class="cline-any cline-neutral"> </span>
|
|
188
|
+
<span class="cline-any cline-neutral"> </span>
|
|
189
|
+
<span class="cline-any cline-yes">9x</span>
|
|
190
|
+
<span class="cline-any cline-neutral"> </span>
|
|
191
|
+
<span class="cline-any cline-neutral"> </span>
|
|
192
|
+
<span class="cline-any cline-neutral"> </span>
|
|
193
|
+
<span class="cline-any cline-yes">29x</span>
|
|
194
|
+
<span class="cline-any cline-neutral"> </span>
|
|
195
|
+
<span class="cline-any cline-neutral"> </span>
|
|
196
|
+
<span class="cline-any cline-neutral"> </span>
|
|
197
|
+
<span class="cline-any cline-yes">29x</span>
|
|
198
|
+
<span class="cline-any cline-yes">27x</span>
|
|
199
|
+
<span class="cline-any cline-neutral"> </span>
|
|
200
|
+
<span class="cline-any cline-neutral"> </span>
|
|
201
|
+
<span class="cline-any cline-yes">29x</span>
|
|
202
|
+
<span class="cline-any cline-neutral"> </span>
|
|
203
|
+
<span class="cline-any cline-neutral"> </span>
|
|
204
|
+
<span class="cline-any cline-neutral"> </span>
|
|
205
|
+
<span class="cline-any cline-neutral"> </span>
|
|
206
|
+
<span class="cline-any cline-neutral"> </span>
|
|
207
|
+
<span class="cline-any cline-neutral"> </span>
|
|
208
|
+
<span class="cline-any cline-neutral"> </span>
|
|
209
|
+
<span class="cline-any cline-yes">51x</span>
|
|
210
|
+
<span class="cline-any cline-yes">1x</span>
|
|
211
|
+
<span class="cline-any cline-neutral"> </span>
|
|
212
|
+
<span class="cline-any cline-yes">50x</span>
|
|
213
|
+
<span class="cline-any cline-neutral"> </span>
|
|
214
|
+
<span class="cline-any cline-neutral"> </span>
|
|
215
|
+
<span class="cline-any cline-neutral"> </span>
|
|
216
|
+
<span class="cline-any cline-neutral"> </span>
|
|
217
|
+
<span class="cline-any cline-neutral"> </span>
|
|
218
|
+
<span class="cline-any cline-neutral"> </span>
|
|
219
|
+
<span class="cline-any cline-neutral"> </span>
|
|
220
|
+
<span class="cline-any cline-neutral"> </span>
|
|
221
|
+
<span class="cline-any cline-neutral"> </span>
|
|
222
|
+
<span class="cline-any cline-neutral"> </span>
|
|
223
|
+
<span class="cline-any cline-neutral"> </span></td><td class="text"><pre class="prettyprint lang-js">function logError(consoleMessage) {<span class="cstat-no" title="statement not covered" ><span class="cstat-no" title="statement not covered" ><span class="cstat-no" title="statement not covered" ><span class="cstat-no" title="statement not covered" ><span class="cstat-no" title="statement not covered" ><span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" ><span class="fstat-no" title="function not covered" ><span class="fstat-no" title="function not covered" ><span class="missing-if-branch" title="if path not taken" >I</span><span class="missing-if-branch" title="else path not taken" >E</span><span class="branch-1 cbranch-no" title="branch not covered" ><span class="missing-if-branch" title="else path not taken" >E</span><span class="missing-if-branch" title="else path not taken" >E</span></span></span></span></span></span></span></span></span></span></span>
|
|
224
|
+
<span class="cstat-no" title="statement not covered" > console.error('\x1b[41m%s\x1b[0m', consoleMessage)</span>;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function <span class="fstat-no" title="function not covered" >logDebug(</span>consoleMessage) {
|
|
228
|
+
<span class="cstat-no" title="statement not covered" > console.log('\x1b[33m%s\x1b[0m', consoleMessage)</span>;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function buildRequestUrlPath(config, locale) {
|
|
232
|
+
let apiFetchOrPreview = null;
|
|
233
|
+
|
|
234
|
+
if(config.isPreview === true || config.isPreview === 'true') {
|
|
235
|
+
apiFetchOrPreview = 'preview';
|
|
236
|
+
} else {
|
|
237
|
+
apiFetchOrPreview = 'fetch';
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
let urlPath = `${config.baseUrl}/${apiFetchOrPreview}/${locale}`;
|
|
241
|
+
return urlPath;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function buildPathUrl(contentType, referenceName, skip, take, sort, direction, filters, filtersLogicOperator, contentLinkDepth, expandAllContentLinks) {
|
|
245
|
+
let url = `/${contentType}/${referenceName}?contentLinkDepth=${contentLinkDepth}&`;
|
|
246
|
+
filtersLogicOperator = filtersLogicOperator ? ` ${filtersLogicOperator} ` : ' AND ';
|
|
247
|
+
|
|
248
|
+
if (sort) {
|
|
249
|
+
url += `sort=${sort}&`;
|
|
250
|
+
<span class="missing-if-branch" title="if path not taken" >I</span> if (direction) {
|
|
251
|
+
<span class="cstat-no" title="statement not covered" > url += `direction=${direction}&`;</span>
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
<span class="missing-if-branch" title="if path not taken" >I</span> if (skip) {
|
|
256
|
+
<span class="cstat-no" title="statement not covered" > url += `skip=${skip}&`;</span>
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
<span class="missing-if-branch" title="if path not taken" >I</span> if (take) {
|
|
260
|
+
<span class="cstat-no" title="statement not covered" > url += `take=${take}&`;</span>
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
if (filters && filters.length > 0) {
|
|
264
|
+
url += 'filter='
|
|
265
|
+
for (let i = 0; i < filters.length; i++) {
|
|
266
|
+
let filter = filters[i];
|
|
267
|
+
url += `${filter.property}[${filter.operator}]${filter.value}` + (i < filters.length - 1 ? filtersLogicOperator : '');
|
|
268
|
+
}
|
|
269
|
+
url += '&';
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
if(expandAllContentLinks) {
|
|
273
|
+
url += `expandAllContentLinks=${expandAllContentLinks}&`;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
return url;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function buildAuthHeader(config) {
|
|
280
|
+
let defaultAuthHeaders = {
|
|
281
|
+
'APIKey': config.apiKey
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
if(config.requiresGuidInHeaders) {
|
|
285
|
+
defaultAuthHeaders.Guid = config.guid;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
return {
|
|
289
|
+
...defaultAuthHeaders,
|
|
290
|
+
...config.headers
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function isHttps(url) {
|
|
296
|
+
if(!url.toLowerCase().startsWith('https://')) {
|
|
297
|
+
return false;
|
|
298
|
+
}
|
|
299
|
+
return true;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
export {
|
|
304
|
+
buildPathUrl,
|
|
305
|
+
buildAuthHeader,
|
|
306
|
+
buildRequestUrlPath,
|
|
307
|
+
isHttps,
|
|
308
|
+
logError,
|
|
309
|
+
logDebug
|
|
310
|
+
}</pre></td></tr>
|
|
311
|
+
</table></pre>
|
|
312
|
+
<div class='push'></div><!-- for sticky footer -->
|
|
313
|
+
</div><!-- /wrapper -->
|
|
314
|
+
<div class='footer quiet pad2 space-top1 center small'>
|
|
315
|
+
Code coverage
|
|
316
|
+
generated by <a href="https://istanbul.js.org/" target="_blank">istanbul</a> at Wed Apr 06 2022 10:12:52 GMT-0400 (Eastern Daylight Time)
|
|
317
|
+
</div>
|
|
318
|
+
</div>
|
|
319
|
+
<script src="../prettify.js"></script>
|
|
320
|
+
<script>
|
|
321
|
+
window.onload = function () {
|
|
322
|
+
if (typeof prettyPrint === 'function') {
|
|
323
|
+
prettyPrint();
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
</script>
|
|
327
|
+
<script src="../sorter.js"></script>
|
|
328
|
+
<script src="../block-navigation.js"></script>
|
|
329
|
+
</body>
|
|
330
|
+
</html>
|
package/dist/browser.js
CHANGED
|
@@ -6,11 +6,20 @@
|
|
|
6
6
|
};
|
|
7
7
|
|
|
8
8
|
// src/utils.ts
|
|
9
|
-
function
|
|
10
|
-
|
|
9
|
+
function logDebug({ config, message }) {
|
|
10
|
+
if (config.logLevel !== "debug" && !config.debug)
|
|
11
|
+
return;
|
|
12
|
+
console.log("\x1B[33m%s\x1B[0m", message);
|
|
13
|
+
}
|
|
14
|
+
function logInfo({ config, message }) {
|
|
15
|
+
if (config.logLevel !== "debug" && config.logLevel !== "info")
|
|
16
|
+
return;
|
|
17
|
+
console.log("\x1B[33m%s\x1B[0m", message);
|
|
11
18
|
}
|
|
12
|
-
function
|
|
13
|
-
|
|
19
|
+
function logError({ config, message }) {
|
|
20
|
+
if (config.logLevel === "silent")
|
|
21
|
+
return;
|
|
22
|
+
console.error("\x1B[41m%s\x1B[0m", message);
|
|
14
23
|
}
|
|
15
24
|
function buildRequestUrlPath(config, locale) {
|
|
16
25
|
let apiFetchOrPreview = "";
|
|
@@ -392,6 +401,7 @@
|
|
|
392
401
|
locale: null,
|
|
393
402
|
headers: {},
|
|
394
403
|
requiresGuidInHeaders: false,
|
|
404
|
+
logLevel: "warn",
|
|
395
405
|
debug: false,
|
|
396
406
|
caching: {
|
|
397
407
|
maxAge: 0
|
|
@@ -416,7 +426,7 @@
|
|
|
416
426
|
}
|
|
417
427
|
function validateConfigParams(configParams) {
|
|
418
428
|
if (!configParams.guid || configParams.guid.length == 0) {
|
|
419
|
-
throw new TypeError("You must provide
|
|
429
|
+
throw new TypeError("You must provide a guid.");
|
|
420
430
|
} else if (!configParams.apiKey || configParams.apiKey.length == 0) {
|
|
421
431
|
throw new TypeError("You must provide an access token.");
|
|
422
432
|
} else if (configParams.caching && isNaN(configParams.caching.maxAge)) {
|
|
@@ -470,12 +480,12 @@
|
|
|
470
480
|
}
|
|
471
481
|
//the function that actually makes ALL our requests
|
|
472
482
|
async makeRequest(reqConfig) {
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
}
|
|
483
|
+
const isPreview = !!this.config.isPreview;
|
|
484
|
+
logDebug({ config: this.config, message: `AgilityCMS Fetch API LOG: ${reqConfig.baseURL}${reqConfig.url}` });
|
|
476
485
|
try {
|
|
477
486
|
const fullUrl = `${reqConfig.baseURL}${reqConfig.url}`;
|
|
478
487
|
let init = {
|
|
488
|
+
...this.config.fetchConfig,
|
|
479
489
|
method: "GET",
|
|
480
490
|
headers: {
|
|
481
491
|
...reqConfig.headers,
|
|
@@ -483,9 +493,17 @@
|
|
|
483
493
|
"Accept": "application/json"
|
|
484
494
|
}
|
|
485
495
|
};
|
|
496
|
+
if (isPreview) {
|
|
497
|
+
init.cache = "no-store";
|
|
498
|
+
delete init.next;
|
|
499
|
+
}
|
|
486
500
|
const response = await fetch(fullUrl, init);
|
|
487
501
|
if (!response.ok) {
|
|
488
|
-
|
|
502
|
+
if (response.status === 404) {
|
|
503
|
+
logInfo({ config: this.config, message: `AgilityCMS Fetch API: Request returned a ${response.status} response for ${reqConfig.baseURL}${reqConfig.url}. ${response.statusText}` });
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
logError({ config: this.config, message: `AgilityCMS Fetch API ERROR: Request returned a ${response.status} response for ${reqConfig.baseURL}${reqConfig.url}. ${response.statusText}` });
|
|
489
507
|
return;
|
|
490
508
|
}
|
|
491
509
|
let data = await response.json();
|
|
@@ -494,12 +512,14 @@
|
|
|
494
512
|
}
|
|
495
513
|
return data;
|
|
496
514
|
} catch (error) {
|
|
497
|
-
logError(`AgilityCMS Fetch API ERROR: Request failed for ${reqConfig.baseURL}${reqConfig.url} ... ${error}
|
|
515
|
+
logError({ config: this.config, message: `AgilityCMS Fetch API ERROR: Request failed for ${reqConfig.baseURL}${reqConfig.url} ... ${error}` });
|
|
498
516
|
}
|
|
499
517
|
}
|
|
500
518
|
};
|
|
501
519
|
function getApi(config) {
|
|
502
520
|
validateConfigParams(config);
|
|
521
|
+
if (!config.fetchConfig)
|
|
522
|
+
config.fetchConfig = {};
|
|
503
523
|
return new ApiClient(config);
|
|
504
524
|
}
|
|
505
525
|
|
package/dist/index.d.ts
CHANGED
|
@@ -4,5 +4,6 @@ import { ContentList } from "./types/ContentList";
|
|
|
4
4
|
import { Gallery } from "./types/Gallery";
|
|
5
5
|
import { Page } from "./types/Page";
|
|
6
6
|
import { ApiClientInstance, getApi } from "./api-client";
|
|
7
|
-
|
|
7
|
+
import { ContentReference } from "./types/ContentReference";
|
|
8
|
+
export type { ApiClientInstance, Config, ContentItem, ContentList, ContentReference, Gallery, Page };
|
|
8
9
|
export { getApi };
|
|
@@ -38,5 +38,5 @@ export interface ContentItemRequestParams {
|
|
|
38
38
|
contentLinkDepth?: number;
|
|
39
39
|
expandAllContentLinks?: boolean;
|
|
40
40
|
}
|
|
41
|
-
declare function getContentItem(this: ApiClientInstance, requestParams: ContentItemRequestParams): Promise<ContentItem
|
|
41
|
+
declare function getContentItem<T>(this: ApiClientInstance, requestParams: ContentItemRequestParams): Promise<ContentItem<T>>;
|
|
42
42
|
export default getContentItem;
|
package/dist/node.js
CHANGED
|
@@ -24,11 +24,20 @@ __export(src_exports, {
|
|
|
24
24
|
module.exports = __toCommonJS(src_exports);
|
|
25
25
|
|
|
26
26
|
// src/utils.ts
|
|
27
|
-
function
|
|
28
|
-
|
|
27
|
+
function logDebug({ config, message }) {
|
|
28
|
+
if (config.logLevel !== "debug" && !config.debug)
|
|
29
|
+
return;
|
|
30
|
+
console.log("\x1B[33m%s\x1B[0m", message);
|
|
31
|
+
}
|
|
32
|
+
function logInfo({ config, message }) {
|
|
33
|
+
if (config.logLevel !== "debug" && config.logLevel !== "info")
|
|
34
|
+
return;
|
|
35
|
+
console.log("\x1B[33m%s\x1B[0m", message);
|
|
29
36
|
}
|
|
30
|
-
function
|
|
31
|
-
|
|
37
|
+
function logError({ config, message }) {
|
|
38
|
+
if (config.logLevel === "silent")
|
|
39
|
+
return;
|
|
40
|
+
console.error("\x1B[41m%s\x1B[0m", message);
|
|
32
41
|
}
|
|
33
42
|
function buildRequestUrlPath(config, locale) {
|
|
34
43
|
let apiFetchOrPreview = "";
|
|
@@ -410,6 +419,7 @@ var defaultConfig = {
|
|
|
410
419
|
locale: null,
|
|
411
420
|
headers: {},
|
|
412
421
|
requiresGuidInHeaders: false,
|
|
422
|
+
logLevel: "warn",
|
|
413
423
|
debug: false,
|
|
414
424
|
caching: {
|
|
415
425
|
maxAge: 0
|
|
@@ -434,7 +444,7 @@ function buildBaseUrl(guid) {
|
|
|
434
444
|
}
|
|
435
445
|
function validateConfigParams(configParams) {
|
|
436
446
|
if (!configParams.guid || configParams.guid.length == 0) {
|
|
437
|
-
throw new TypeError("You must provide
|
|
447
|
+
throw new TypeError("You must provide a guid.");
|
|
438
448
|
} else if (!configParams.apiKey || configParams.apiKey.length == 0) {
|
|
439
449
|
throw new TypeError("You must provide an access token.");
|
|
440
450
|
} else if (configParams.caching && isNaN(configParams.caching.maxAge)) {
|
|
@@ -488,12 +498,12 @@ var ApiClient = class {
|
|
|
488
498
|
}
|
|
489
499
|
//the function that actually makes ALL our requests
|
|
490
500
|
async makeRequest(reqConfig) {
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
}
|
|
501
|
+
const isPreview = !!this.config.isPreview;
|
|
502
|
+
logDebug({ config: this.config, message: `AgilityCMS Fetch API LOG: ${reqConfig.baseURL}${reqConfig.url}` });
|
|
494
503
|
try {
|
|
495
504
|
const fullUrl = `${reqConfig.baseURL}${reqConfig.url}`;
|
|
496
505
|
let init = {
|
|
506
|
+
...this.config.fetchConfig,
|
|
497
507
|
method: "GET",
|
|
498
508
|
headers: {
|
|
499
509
|
...reqConfig.headers,
|
|
@@ -501,9 +511,17 @@ var ApiClient = class {
|
|
|
501
511
|
"Accept": "application/json"
|
|
502
512
|
}
|
|
503
513
|
};
|
|
514
|
+
if (isPreview) {
|
|
515
|
+
init.cache = "no-store";
|
|
516
|
+
delete init.next;
|
|
517
|
+
}
|
|
504
518
|
const response = await fetch(fullUrl, init);
|
|
505
519
|
if (!response.ok) {
|
|
506
|
-
|
|
520
|
+
if (response.status === 404) {
|
|
521
|
+
logInfo({ config: this.config, message: `AgilityCMS Fetch API: Request returned a ${response.status} response for ${reqConfig.baseURL}${reqConfig.url}. ${response.statusText}` });
|
|
522
|
+
return;
|
|
523
|
+
}
|
|
524
|
+
logError({ config: this.config, message: `AgilityCMS Fetch API ERROR: Request returned a ${response.status} response for ${reqConfig.baseURL}${reqConfig.url}. ${response.statusText}` });
|
|
507
525
|
return;
|
|
508
526
|
}
|
|
509
527
|
let data = await response.json();
|
|
@@ -512,12 +530,14 @@ var ApiClient = class {
|
|
|
512
530
|
}
|
|
513
531
|
return data;
|
|
514
532
|
} catch (error) {
|
|
515
|
-
logError(`AgilityCMS Fetch API ERROR: Request failed for ${reqConfig.baseURL}${reqConfig.url} ... ${error}
|
|
533
|
+
logError({ config: this.config, message: `AgilityCMS Fetch API ERROR: Request failed for ${reqConfig.baseURL}${reqConfig.url} ... ${error}` });
|
|
516
534
|
}
|
|
517
535
|
}
|
|
518
536
|
};
|
|
519
537
|
function getApi(config) {
|
|
520
538
|
validateConfigParams(config);
|
|
539
|
+
if (!config.fetchConfig)
|
|
540
|
+
config.fetchConfig = {};
|
|
521
541
|
return new ApiClient(config);
|
|
522
542
|
}
|
|
523
543
|
|
package/dist/types/Config.d.ts
CHANGED
|
@@ -1,15 +1,44 @@
|
|
|
1
1
|
export interface Config {
|
|
2
|
+
/**
|
|
3
|
+
* The optional baseUrl for the API. If not provided, the API will use the default baseUrl for the instance.
|
|
4
|
+
* This is mostly used for testing purposes.
|
|
5
|
+
*/
|
|
2
6
|
baseUrl?: string | null;
|
|
7
|
+
/**
|
|
8
|
+
* If true, the API will use the Preview API. If false, it will use the Fetch API. Default is false.
|
|
9
|
+
* Make sure the API Key provided matches this value.
|
|
10
|
+
*/
|
|
3
11
|
isPreview?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* The guid that represents your instance.
|
|
14
|
+
*/
|
|
4
15
|
guid?: string | null;
|
|
16
|
+
/**
|
|
17
|
+
* The Fetch or Preview API key.
|
|
18
|
+
*/
|
|
5
19
|
apiKey?: string | null;
|
|
6
20
|
locale?: string | null;
|
|
21
|
+
/**
|
|
22
|
+
* Additional headers to include in the request.
|
|
23
|
+
*/
|
|
7
24
|
headers?: {
|
|
8
25
|
[key: string]: string;
|
|
9
26
|
};
|
|
10
27
|
requiresGuidInHeaders?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* The logging level. Default is 'warn'.
|
|
30
|
+
*/
|
|
31
|
+
logLevel?: 'debug' | 'info' | 'warn' | 'error' | 'silent';
|
|
32
|
+
/**
|
|
33
|
+
* Used for debugging purposes. Default is false.
|
|
34
|
+
*/
|
|
11
35
|
debug?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Optional Caching options. Caching is disabled by default.
|
|
38
|
+
* This is mostly used for Next.js and other server-side rendering frameworks.
|
|
39
|
+
*/
|
|
12
40
|
caching?: {
|
|
13
41
|
maxAge?: number;
|
|
14
42
|
};
|
|
43
|
+
fetchConfig?: any;
|
|
15
44
|
}
|
|
@@ -6,8 +6,9 @@
|
|
|
6
6
|
* @property {AgilityFetch.Types.ContentItem} item - The contentItem representing the content of this module.
|
|
7
7
|
*/
|
|
8
8
|
import { ContentItem } from "./ContentItem";
|
|
9
|
+
import { ContentReference } from "./ContentReference";
|
|
9
10
|
export interface ContentZone {
|
|
10
11
|
module: string;
|
|
11
|
-
item: ContentItem;
|
|
12
|
+
item: ContentItem | ContentReference;
|
|
12
13
|
customData?: any;
|
|
13
14
|
}
|
package/dist/types/Filter.d.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
export interface Filter {
|
|
10
10
|
property: string;
|
|
11
|
-
operator: FilterOperator | "eq" | "ne" | "gt" | "lt" | "ge" | "le" | "
|
|
11
|
+
operator: FilterOperator | "eq" | "ne" | "gt" | "lt" | "ge" | "le" | "contains";
|
|
12
12
|
value: string;
|
|
13
13
|
}
|
|
14
|
-
export type FilterOperator = "eq" | "ne" | "gt" | "lt" | "ge" | "le" | "
|
|
14
|
+
export type FilterOperator = "eq" | "ne" | "gt" | "lt" | "ge" | "le" | "contains";
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { Config } from "./types/Config";
|
|
2
|
+
interface LogProps {
|
|
3
|
+
config: Config;
|
|
4
|
+
message: string;
|
|
5
|
+
}
|
|
6
|
+
declare function logDebug({ config, message }: LogProps): void;
|
|
7
|
+
declare function logInfo({ config, message }: LogProps): void;
|
|
8
|
+
declare function logWarning({ config, message }: LogProps): void;
|
|
9
|
+
declare function logError({ config, message }: LogProps): void;
|
|
3
10
|
declare function buildRequestUrlPath(config: any, locale: any): string;
|
|
4
11
|
declare function buildPathUrl(contentType: any, referenceName: any, skip: any, take: any, sort: any, direction: any, filters: any, filtersLogicOperator: any, contentLinkDepth: any, expandAllContentLinks: any): string;
|
|
5
12
|
declare function buildAuthHeader(config: any): any;
|
|
6
13
|
declare function isHttps(url: any): boolean;
|
|
7
|
-
export { buildPathUrl, buildAuthHeader, buildRequestUrlPath, isHttps, logError, logDebug };
|
|
14
|
+
export { buildPathUrl, buildAuthHeader, buildRequestUrlPath, isHttps, logError, logDebug, logInfo, logWarning };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agility/content-fetch",
|
|
3
|
-
"version": "2.0.0-
|
|
3
|
+
"version": "2.0.0-rc24",
|
|
4
4
|
"description": "JavaScript library for the Agility Fetch API (node and browser)",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -52,4 +52,4 @@
|
|
|
52
52
|
"typescript": "^5.1.6"
|
|
53
53
|
},
|
|
54
54
|
"packageManager": "yarn@3.6.1"
|
|
55
|
-
}
|
|
55
|
+
}
|