@prismicio/client 5.1.0 → 5.1.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 (41) hide show
  1. package/README.md +1 -1
  2. package/cjs/@prismicio/client.js +1200 -1200
  3. package/cjs/@prismicio/client.js.map +1 -1
  4. package/cjs/@prismicio/client.min.js.map +1 -1
  5. package/esm/@prismicio/client.min.mjs.map +1 -1
  6. package/esm/@prismicio/client.mjs +1200 -1200
  7. package/esm/@prismicio/client.mjs.map +1 -1
  8. package/package.json +1 -1
  9. package/types/Api.d.ts +27 -27
  10. package/types/ApiSearchResponse.d.ts +11 -11
  11. package/types/Cookies.d.ts +9 -9
  12. package/types/HttpClient.d.ts +16 -16
  13. package/types/LazySearchForm.d.ts +24 -24
  14. package/types/Predicates.d.ts +58 -58
  15. package/types/PreviewResolver.d.ts +9 -9
  16. package/types/ResolvedApi.d.ts +126 -126
  17. package/types/SearchForm.d.ts +47 -47
  18. package/types/TagsForm.d.ts +7 -7
  19. package/types/cache.d.ts +17 -17
  20. package/types/client.d.ts +34 -34
  21. package/types/documents.d.ts +20 -20
  22. package/types/experiments.d.ts +22 -22
  23. package/types/form.d.ts +25 -25
  24. package/types/index.d.ts +129 -129
  25. package/types/lru.d.ts +25 -25
  26. package/types/request.d.ts +13 -13
  27. package/umd/@prismicio/client.js +1200 -1200
  28. package/umd/@prismicio/client.js.map +1 -1
  29. package/umd/@prismicio/client.min.js.map +1 -1
  30. package/cjs/prismic-javascript.js +0 -1282
  31. package/cjs/prismic-javascript.js.map +0 -1
  32. package/cjs/prismic-javascript.min.js +0 -16
  33. package/cjs/prismic-javascript.min.js.map +0 -1
  34. package/esm/prismic-javascript.min.mjs +0 -16
  35. package/esm/prismic-javascript.min.mjs.map +0 -1
  36. package/esm/prismic-javascript.mjs +0 -1278
  37. package/esm/prismic-javascript.mjs.map +0 -1
  38. package/umd/prismic-javascript.js +0 -1286
  39. package/umd/prismic-javascript.js.map +0 -1
  40. package/umd/prismic-javascript.min.js +0 -17
  41. package/umd/prismic-javascript.min.js.map +0 -1
@@ -1,1282 +0,0 @@
1
- 'use strict';
2
-
3
- function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
4
-
5
- var crossFetch = _interopDefault(require('cross-fetch'));
6
-
7
- /*! *****************************************************************************
8
- Copyright (c) Microsoft Corporation. All rights reserved.
9
- Licensed under the Apache License, Version 2.0 (the "License"); you may not use
10
- this file except in compliance with the License. You may obtain a copy of the
11
- License at http://www.apache.org/licenses/LICENSE-2.0
12
-
13
- THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
- KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
15
- WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
16
- MERCHANTABLITY OR NON-INFRINGEMENT.
17
-
18
- See the Apache Version 2.0 License for specific language governing permissions
19
- and limitations under the License.
20
- ***************************************************************************** */
21
-
22
- var __assign = function() {
23
- __assign = Object.assign || function __assign(t) {
24
- for (var s, i = 1, n = arguments.length; i < n; i++) {
25
- s = arguments[i];
26
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
27
- }
28
- return t;
29
- };
30
- return __assign.apply(this, arguments);
31
- };
32
-
33
- var Variation = /** @class */ (function () {
34
- function Variation(data) {
35
- this.data = {};
36
- this.data = data;
37
- }
38
- Variation.prototype.id = function () {
39
- return this.data.id;
40
- };
41
- Variation.prototype.ref = function () {
42
- return this.data.ref;
43
- };
44
- Variation.prototype.label = function () {
45
- return this.data.label;
46
- };
47
- return Variation;
48
- }());
49
- var Experiment = /** @class */ (function () {
50
- function Experiment(data) {
51
- this.data = {};
52
- this.data = data;
53
- this.variations = (data.variations || []).map(function (v) {
54
- return new Variation(v);
55
- });
56
- }
57
- Experiment.prototype.id = function () {
58
- return this.data.id;
59
- };
60
- Experiment.prototype.googleId = function () {
61
- return this.data.googleId;
62
- };
63
- Experiment.prototype.name = function () {
64
- return this.data.name;
65
- };
66
- return Experiment;
67
- }());
68
- var Experiments = /** @class */ (function () {
69
- function Experiments(data) {
70
- if (data) {
71
- this.drafts = (data.drafts || []).map(function (exp) {
72
- return new Experiment(exp);
73
- });
74
- this.running = (data.running || []).map(function (exp) {
75
- return new Experiment(exp);
76
- });
77
- }
78
- }
79
- Experiments.prototype.current = function () {
80
- if (this.running.length > 0) {
81
- return this.running[0];
82
- }
83
- else {
84
- return null;
85
- }
86
- };
87
- Experiments.prototype.refFromCookie = function (cookie) {
88
- if (!cookie || cookie.trim() === '')
89
- return null;
90
- var splitted = cookie.trim().split(' ');
91
- if (splitted.length < 2)
92
- return null;
93
- var expId = splitted[0];
94
- var varIndex = parseInt(splitted[1], 10);
95
- var exp = this.running.filter(function (exp) {
96
- return exp.googleId() === expId && exp.variations.length > varIndex;
97
- })[0];
98
- return exp ? exp.variations[varIndex].ref() : null;
99
- };
100
- return Experiments;
101
- }());
102
-
103
- var LazySearchForm = /** @class */ (function () {
104
- function LazySearchForm(id, api) {
105
- this.id = id;
106
- this.api = api;
107
- this.fields = {};
108
- }
109
- LazySearchForm.prototype.set = function (key, value) {
110
- this.fields[key] = value;
111
- return this;
112
- };
113
- LazySearchForm.prototype.ref = function (ref) {
114
- return this.set('ref', ref);
115
- };
116
- LazySearchForm.prototype.query = function (query) {
117
- return this.set('q', query);
118
- };
119
- LazySearchForm.prototype.pageSize = function (size) {
120
- return this.set('pageSize', size);
121
- };
122
- LazySearchForm.prototype.fetch = function (fields) {
123
- console.warn('Warning: Using Fetch is deprecated. Use the property `graphQuery` instead.');
124
- return this.set('fetch', fields);
125
- };
126
- LazySearchForm.prototype.fetchLinks = function (fields) {
127
- console.warn('Warning: Using FetchLinks is deprecated. Use the property `graphQuery` instead.');
128
- return this.set('fetchLinks', fields);
129
- };
130
- LazySearchForm.prototype.graphQuery = function (query) {
131
- return this.set('graphQuery', query);
132
- };
133
- LazySearchForm.prototype.lang = function (langCode) {
134
- return this.set('lang', langCode);
135
- };
136
- LazySearchForm.prototype.page = function (p) {
137
- return this.set('page', p);
138
- };
139
- LazySearchForm.prototype.after = function (documentId) {
140
- return this.set('after', documentId);
141
- };
142
- LazySearchForm.prototype.orderings = function (orderings) {
143
- return this.set('orderings', orderings);
144
- };
145
- LazySearchForm.prototype.url = function () {
146
- var _this = this;
147
- return this.api.get().then(function (api) {
148
- return LazySearchForm.toSearchForm(_this, api).url();
149
- });
150
- };
151
- LazySearchForm.prototype.submit = function (cb) {
152
- var _this = this;
153
- return this.api.get().then(function (api) {
154
- return LazySearchForm.toSearchForm(_this, api).submit(cb);
155
- });
156
- };
157
- LazySearchForm.toSearchForm = function (lazyForm, api) {
158
- var form = api.form(lazyForm.id);
159
- if (form) {
160
- return Object.keys(lazyForm.fields).reduce(function (form, fieldKey) {
161
- var fieldValue = lazyForm.fields[fieldKey];
162
- if (fieldKey === 'q') {
163
- return form.query(fieldValue);
164
- }
165
- else if (fieldKey === 'pageSize') {
166
- return form.pageSize(fieldValue);
167
- }
168
- else if (fieldKey === 'fetch') {
169
- return form.fetch(fieldValue);
170
- }
171
- else if (fieldKey === 'fetchLinks') {
172
- return form.fetchLinks(fieldValue);
173
- }
174
- else if (fieldKey === 'graphQuery') {
175
- return form.graphQuery(fieldValue);
176
- }
177
- else if (fieldKey === 'lang') {
178
- return form.lang(fieldValue);
179
- }
180
- else if (fieldKey === 'page') {
181
- return form.page(fieldValue);
182
- }
183
- else if (fieldKey === 'after') {
184
- return form.after(fieldValue);
185
- }
186
- else if (fieldKey === 'orderings') {
187
- return form.orderings(fieldValue);
188
- }
189
- else {
190
- return form.set(fieldKey, fieldValue);
191
- }
192
- }, form);
193
- }
194
- else {
195
- throw new Error("Unable to access to form " + lazyForm.id);
196
- }
197
- };
198
- return LazySearchForm;
199
- }());
200
- var SearchForm = /** @class */ (function () {
201
- function SearchForm(form, httpClient) {
202
- this.httpClient = httpClient;
203
- this.form = form;
204
- this.data = {};
205
- for (var field in form.fields) {
206
- if (form.fields[field]['default']) {
207
- this.data[field] = [form.fields[field]['default']];
208
- }
209
- }
210
- }
211
- SearchForm.prototype.set = function (field, value) {
212
- var fieldDesc = this.form.fields[field];
213
- if (!fieldDesc)
214
- throw new Error('Unknown field ' + field);
215
- var checkedValue = value === '' || value === undefined ? null : value;
216
- var values = this.data[field] || [];
217
- if (fieldDesc.multiple) {
218
- values = checkedValue ? values.concat([checkedValue]) : values;
219
- }
220
- else {
221
- values = checkedValue ? [checkedValue] : values;
222
- }
223
- this.data[field] = values;
224
- return this;
225
- };
226
- /**
227
- * Sets a ref to query on for this SearchForm. This is a mandatory
228
- * method to call before calling submit(), and api.form('everything').submit()
229
- * will not work.
230
- */
231
- SearchForm.prototype.ref = function (ref) {
232
- return this.set('ref', ref);
233
- };
234
- /**
235
- * Sets a predicate-based query for this SearchForm. This is where you
236
- * paste what you compose in your prismic.io API browser.
237
- */
238
- SearchForm.prototype.query = function (query) {
239
- if (typeof query === 'string') {
240
- return this.query([query]);
241
- }
242
- else if (Array.isArray(query)) {
243
- return this.set('q', "[" + query.join('') + "]");
244
- }
245
- else {
246
- throw new Error("Invalid query : " + query);
247
- }
248
- };
249
- /**
250
- * Sets a page size to query for this SearchForm. This is an optional method.
251
- *
252
- * @param {number} size - The page size
253
- * @returns {SearchForm} - The SearchForm itself
254
- */
255
- SearchForm.prototype.pageSize = function (size) {
256
- return this.set('pageSize', size);
257
- };
258
- /**
259
- * Restrict the results document to the specified fields
260
- */
261
- SearchForm.prototype.fetch = function (fields) {
262
- console.warn('Warning: Using Fetch is deprecated. Use the property `graphQuery` instead.');
263
- var strFields = Array.isArray(fields) ? fields.join(',') : fields;
264
- return this.set('fetch', strFields);
265
- };
266
- /**
267
- * Include the requested fields in the DocumentLink instances in the result
268
- */
269
- SearchForm.prototype.fetchLinks = function (fields) {
270
- console.warn('Warning: Using FetchLinks is deprecated. Use the property `graphQuery` instead.');
271
- var strFields = Array.isArray(fields) ? fields.join(',') : fields;
272
- return this.set('fetchLinks', strFields);
273
- };
274
- /**
275
- * Sets the graphquery to query for this SearchForm. This is an optional method.
276
- */
277
- SearchForm.prototype.graphQuery = function (query) {
278
- return this.set('graphQuery', query);
279
- };
280
- /**
281
- * Sets the language to query for this SearchForm. This is an optional method.
282
- */
283
- SearchForm.prototype.lang = function (langCode) {
284
- return this.set('lang', langCode);
285
- };
286
- /**
287
- * Sets the page number to query for this SearchForm. This is an optional method.
288
- */
289
- SearchForm.prototype.page = function (p) {
290
- return this.set('page', p);
291
- };
292
- /**
293
- * Remove all the documents except for those after the specified document in the list. This is an optional method.
294
- */
295
- SearchForm.prototype.after = function (documentId) {
296
- return this.set('after', documentId);
297
- };
298
- /**
299
- * Sets the orderings to query for this SearchForm. This is an optional method.
300
- */
301
- SearchForm.prototype.orderings = function (orderings) {
302
- if (!orderings) {
303
- return this;
304
- }
305
- else {
306
- return this.set('orderings', "[" + orderings.join(',') + "]");
307
- }
308
- };
309
- /**
310
- * Build the URL to query
311
- */
312
- SearchForm.prototype.url = function () {
313
- var url = this.form.action;
314
- if (this.data) {
315
- var sep = (url.indexOf('?') > -1 ? '&' : '?');
316
- for (var key in this.data) {
317
- if (Object.prototype.hasOwnProperty.call(this.data, key)) {
318
- var values = this.data[key];
319
- if (values) {
320
- for (var i = 0; i < values.length; i++) {
321
- url += sep + key + '=' + encodeURIComponent(values[i]);
322
- sep = '&';
323
- }
324
- }
325
- }
326
- }
327
- }
328
- return url;
329
- };
330
- /**
331
- * Submits the query, and calls the callback function.
332
- */
333
- SearchForm.prototype.submit = function (cb) {
334
- return this.httpClient.cachedRequest(this.url()).then(function (response) {
335
- cb && cb(null, response);
336
- return response;
337
- }).catch(function (error) {
338
- cb && cb(error);
339
- throw error;
340
- });
341
- };
342
- return SearchForm;
343
- }());
344
-
345
- var OPERATOR = {
346
- at: 'at',
347
- not: 'not',
348
- missing: 'missing',
349
- has: 'has',
350
- any: 'any',
351
- in: 'in',
352
- fulltext: 'fulltext',
353
- similar: 'similar',
354
- numberGt: 'number.gt',
355
- numberLt: 'number.lt',
356
- numberInRange: 'number.inRange',
357
- dateBefore: 'date.before',
358
- dateAfter: 'date.after',
359
- dateBetween: 'date.between',
360
- dateDayOfMonth: 'date.day-of-month',
361
- dateDayOfMonthAfter: 'date.day-of-month-after',
362
- dateDayOfMonthBefore: 'date.day-of-month-before',
363
- dateDayOfWeek: 'date.day-of-week',
364
- dateDayOfWeekAfter: 'date.day-of-week-after',
365
- dateDayOfWeekBefore: 'date.day-of-week-before',
366
- dateMonth: 'date.month',
367
- dateMonthBefore: 'date.month-before',
368
- dateMonthAfter: 'date.month-after',
369
- dateYear: 'date.year',
370
- dateHour: 'date.hour',
371
- dateHourBefore: 'date.hour-before',
372
- dateHourAfter: 'date.hour-after',
373
- GeopointNear: 'geopoint.near',
374
- };
375
- function encode(value) {
376
- if (typeof value === 'string') {
377
- return "\"" + value + "\"";
378
- }
379
- else if (typeof value === 'number') {
380
- return value.toString();
381
- }
382
- else if (value instanceof Date) {
383
- return value.getTime().toString();
384
- }
385
- else if (Array.isArray(value)) {
386
- return "[" + value.map(function (v) { return encode(v); }).join(',') + "]";
387
- }
388
- else if (typeof value === "boolean") {
389
- return value.toString();
390
- }
391
- else {
392
- throw new Error("Unable to encode " + value + " of type " + typeof value);
393
- }
394
- }
395
- var geopoint = {
396
- near: function (fragment, latitude, longitude, radius) {
397
- return "[" + OPERATOR.GeopointNear + "(" + fragment + ", " + latitude + ", " + longitude + ", " + radius + ")]";
398
- },
399
- };
400
- var date = {
401
- before: function (fragment, before) {
402
- return "[" + OPERATOR.dateBefore + "(" + fragment + ", " + encode(before) + ")]";
403
- },
404
- after: function (fragment, after) {
405
- return "[" + OPERATOR.dateAfter + "(" + fragment + ", " + encode(after) + ")]";
406
- },
407
- between: function (fragment, before, after) {
408
- return "[" + OPERATOR.dateBetween + "(" + fragment + ", " + encode(before) + ", " + encode(after) + ")]";
409
- },
410
- dayOfMonth: function (fragment, day) {
411
- return "[" + OPERATOR.dateDayOfMonth + "(" + fragment + ", " + day + ")]";
412
- },
413
- dayOfMonthAfter: function (fragment, day) {
414
- return "[" + OPERATOR.dateDayOfMonthAfter + "(" + fragment + ", " + day + ")]";
415
- },
416
- dayOfMonthBefore: function (fragment, day) {
417
- return "[" + OPERATOR.dateDayOfMonthBefore + "(" + fragment + ", " + day + ")]";
418
- },
419
- dayOfWeek: function (fragment, day) {
420
- return "[" + OPERATOR.dateDayOfWeek + "(" + fragment + ", " + encode(day) + ")]";
421
- },
422
- dayOfWeekAfter: function (fragment, day) {
423
- return "[" + OPERATOR.dateDayOfWeekAfter + "(" + fragment + ", " + encode(day) + ")]";
424
- },
425
- dayOfWeekBefore: function (fragment, day) {
426
- return "[" + OPERATOR.dateDayOfWeekBefore + "(" + fragment + ", " + encode(day) + ")]";
427
- },
428
- month: function (fragment, month) {
429
- return "[" + OPERATOR.dateMonth + "(" + fragment + ", " + encode(month) + ")]";
430
- },
431
- monthBefore: function (fragment, month) {
432
- return "[" + OPERATOR.dateMonthBefore + "(" + fragment + ", " + encode(month) + ")]";
433
- },
434
- monthAfter: function (fragment, month) {
435
- return "[" + OPERATOR.dateMonthAfter + "(" + fragment + ", " + encode(month) + ")]";
436
- },
437
- year: function (fragment, year) {
438
- return "[" + OPERATOR.dateYear + "(" + fragment + ", " + year + ")]";
439
- },
440
- hour: function (fragment, hour) {
441
- return "[" + OPERATOR.dateHour + "(" + fragment + ", " + hour + ")]";
442
- },
443
- hourBefore: function (fragment, hour) {
444
- return "[" + OPERATOR.dateHourBefore + "(" + fragment + ", " + hour + ")]";
445
- },
446
- hourAfter: function (fragment, hour) {
447
- return "[" + OPERATOR.dateHourAfter + "(" + fragment + ", " + hour + ")]";
448
- },
449
- };
450
- var number = {
451
- gt: function (fragment, value) {
452
- return "[" + OPERATOR.numberGt + "(" + fragment + ", " + value + ")]";
453
- },
454
- lt: function (fragment, value) {
455
- return "[" + OPERATOR.numberLt + "(" + fragment + ", " + value + ")]";
456
- },
457
- inRange: function (fragment, before, after) {
458
- return "[" + OPERATOR.numberInRange + "(" + fragment + ", " + before + ", " + after + ")]";
459
- },
460
- };
461
- var Predicates = {
462
- at: function (fragment, value) {
463
- return "[" + OPERATOR.at + "(" + fragment + ", " + encode(value) + ")]";
464
- },
465
- not: function (fragment, value) {
466
- return "[" + OPERATOR.not + "(" + fragment + ", " + encode(value) + ")]";
467
- },
468
- missing: function (fragment) {
469
- return "[" + OPERATOR.missing + "(" + fragment + ")]";
470
- },
471
- has: function (fragment) {
472
- return "[" + OPERATOR.has + "(" + fragment + ")]";
473
- },
474
- any: function (fragment, values) {
475
- return "[" + OPERATOR.any + "(" + fragment + ", " + encode(values) + ")]";
476
- },
477
- in: function (fragment, values) {
478
- return "[" + OPERATOR.in + "(" + fragment + ", " + encode(values) + ")]";
479
- },
480
- fulltext: function (fragment, value) {
481
- return "[" + OPERATOR.fulltext + "(" + fragment + ", " + encode(value) + ")]";
482
- },
483
- similar: function (documentId, maxResults) {
484
- return "[" + OPERATOR.similar + "(\"" + documentId + "\", " + maxResults + ")]";
485
- },
486
- date: date,
487
- dateBefore: date.before,
488
- dateAfter: date.after,
489
- dateBetween: date.between,
490
- dayOfMonth: date.dayOfMonth,
491
- dayOfMonthAfter: date.dayOfMonthAfter,
492
- dayOfMonthBefore: date.dayOfMonthBefore,
493
- dayOfWeek: date.dayOfWeek,
494
- dayOfWeekAfter: date.dayOfWeekAfter,
495
- dayOfWeekBefore: date.dayOfWeekBefore,
496
- month: date.month,
497
- monthBefore: date.monthBefore,
498
- monthAfter: date.monthAfter,
499
- year: date.year,
500
- hour: date.hour,
501
- hourBefore: date.hourBefore,
502
- hourAfter: date.hourAfter,
503
- number: number,
504
- gt: number.gt,
505
- lt: number.lt,
506
- inRange: number.inRange,
507
- near: geopoint.near,
508
- geopoint: geopoint,
509
- };
510
-
511
- /* eslint-disable */
512
- // Some portions of code from https://github.com/jshttp/cookie
513
- var decode = decodeURIComponent;
514
- function tryDecode(str, decode) {
515
- try {
516
- return decode(str);
517
- }
518
- catch (e) {
519
- return str;
520
- }
521
- }
522
- function parse(str, options) {
523
- if (typeof str !== 'string') {
524
- throw new TypeError('argument str must be a string');
525
- }
526
- var obj = {};
527
- var opt = options || {};
528
- var pairs = str.split(/; */);
529
- var dec = opt.decode || decode;
530
- pairs.forEach(function (pair) {
531
- var eq_idx = pair.indexOf('=');
532
- // skip things that don't look like key=value
533
- if (eq_idx < 0) {
534
- return;
535
- }
536
- var key = pair.substr(0, eq_idx).trim();
537
- var val = pair.substr(++eq_idx, pair.length).trim();
538
- // quoted values
539
- if ('"' == val[0]) {
540
- val = val.slice(1, -1);
541
- }
542
- // only assign once
543
- if (undefined == obj[key]) {
544
- obj[key] = tryDecode(val, dec);
545
- }
546
- });
547
- return obj;
548
- }
549
- var Cookies = { parse: parse };
550
-
551
- function createPreviewResolver(token, documentId, getDocByID) {
552
- var resolve = function (linkResolver, defaultUrl, cb) {
553
- if (documentId && getDocByID) {
554
- return getDocByID(documentId, { ref: token }).then(function (document) {
555
- if (!document) {
556
- cb && cb(null, defaultUrl);
557
- return defaultUrl;
558
- }
559
- else {
560
- var url = (linkResolver && linkResolver(document)) || document.url || defaultUrl;
561
- cb && cb(null, url);
562
- return url;
563
- }
564
- });
565
- }
566
- else {
567
- return Promise.resolve(defaultUrl);
568
- }
569
- };
570
- return { token: token, documentId: documentId, resolve: resolve };
571
- }
572
-
573
- var PREVIEW_COOKIE = 'io.prismic.preview';
574
- var EXPERIMENT_COOKIE = 'io.prismic.experiment';
575
- var ResolvedApi = /** @class */ (function () {
576
- function ResolvedApi(data, httpClient, options) {
577
- this.data = data;
578
- this.masterRef = data.refs.filter(function (ref) { return ref.isMasterRef; })[0];
579
- this.experiments = new Experiments(data.experiments);
580
- this.bookmarks = data.bookmarks;
581
- this.httpClient = httpClient;
582
- this.options = options;
583
- this.refs = data.refs;
584
- this.tags = data.tags;
585
- this.types = data.types;
586
- this.languages = data.languages;
587
- }
588
- /**
589
- * Returns a useable form from its id, as described in the RESTful description of the API.
590
- * For instance: api.form("everything") works on every repository (as "everything" exists by default)
591
- * You can then chain the calls: api.form("everything").query('[[:d = at(document.id, "UkL0gMuvzYUANCpf")]]').ref(ref).submit()
592
- */
593
- ResolvedApi.prototype.form = function (formId) {
594
- var form = this.data.forms[formId];
595
- if (form) {
596
- return new SearchForm(form, this.httpClient);
597
- }
598
- return null;
599
- };
600
- ResolvedApi.prototype.everything = function () {
601
- var f = this.form('everything');
602
- if (!f)
603
- throw new Error('Missing everything form');
604
- return f;
605
- };
606
- /**
607
- * The ID of the master ref on this prismic.io API.
608
- * Do not use like this: searchForm.ref(api.master()).
609
- * Instead, set your ref once in a variable, and call it when you need it; this will allow to change the ref you're viewing easily for your entire page.
610
- */
611
- ResolvedApi.prototype.master = function () {
612
- return this.masterRef.ref;
613
- };
614
- /**
615
- * Returns the ref ID for a given ref's label.
616
- * Do not use like this: searchForm.ref(api.ref("Future release label")).
617
- * Instead, set your ref once in a variable, and call it when you need it; this will allow to change the ref you're viewing easily for your entire page.
618
- */
619
- ResolvedApi.prototype.ref = function (label) {
620
- var ref = this.data.refs.filter(function (ref) { return ref.label === label; })[0];
621
- return ref ? ref.ref : null;
622
- };
623
- ResolvedApi.prototype.currentExperiment = function () {
624
- return this.experiments.current();
625
- };
626
- /**
627
- * Query the repository
628
- */
629
- ResolvedApi.prototype.query = function (q, optionsOrCallback, cb) {
630
- if (cb === void 0) { cb = function () { }; }
631
- var _a = typeof optionsOrCallback === 'function'
632
- ? { options: {}, callback: optionsOrCallback }
633
- : { options: optionsOrCallback || {}, callback: cb }, options = _a.options, callback = _a.callback;
634
- var form = this.everything();
635
- for (var key in options) {
636
- form = form.set(key, options[key]);
637
- }
638
- if (!options.ref) {
639
- // Look in cookies if we have a ref (preview or experiment)
640
- var cookieString = '';
641
- if (this.options.req) { // NodeJS
642
- cookieString = this.options.req.headers['cookie'] || '';
643
- }
644
- else if (typeof window !== 'undefined' && window.document) { // Browser
645
- cookieString = window.document.cookie || '';
646
- }
647
- var cookies = Cookies.parse(cookieString);
648
- var previewRef = cookies[PREVIEW_COOKIE];
649
- var experimentRef = this.experiments.refFromCookie(cookies[EXPERIMENT_COOKIE]);
650
- form = form.ref(previewRef || experimentRef || this.masterRef.ref);
651
- }
652
- if (q) {
653
- form.query(q);
654
- }
655
- return form.submit(callback);
656
- };
657
- /**
658
- * Retrieve the document returned by the given query
659
- * @param {string|array|Predicate} the query
660
- * @param {object} additional parameters. In NodeJS, pass the request as 'req'.
661
- * @param {function} callback(err, doc)
662
- */
663
- ResolvedApi.prototype.queryFirst = function (q, optionsOrCallback, cb) {
664
- var _a = typeof optionsOrCallback === 'function'
665
- ? { options: {}, callback: optionsOrCallback }
666
- : { options: optionsOrCallback || {}, callback: cb || (function () { }) }, options = _a.options, callback = _a.callback;
667
- options.page = 1;
668
- options.pageSize = 1;
669
- return this.query(q, options).then(function (response) {
670
- var document = response && response.results && response.results[0];
671
- callback(null, document);
672
- return document;
673
- }).catch(function (error) {
674
- callback(error);
675
- throw error;
676
- });
677
- };
678
- /**
679
- * Retrieve the document with the given id
680
- */
681
- ResolvedApi.prototype.getByID = function (id, maybeOptions, cb) {
682
- var options = maybeOptions ? __assign({}, maybeOptions) : {};
683
- if (!options.lang)
684
- options.lang = '*';
685
- return this.queryFirst(Predicates.at('document.id', id), options, cb);
686
- };
687
- /**
688
- * Retrieve multiple documents from an array of id
689
- */
690
- ResolvedApi.prototype.getByIDs = function (ids, maybeOptions, cb) {
691
- var options = maybeOptions ? __assign({}, maybeOptions) : {};
692
- if (!options.lang)
693
- options.lang = '*';
694
- return this.query(Predicates.in('document.id', ids), options, cb);
695
- };
696
- /**
697
- * Retrieve the document with the given uid
698
- */
699
- ResolvedApi.prototype.getByUID = function (type, uid, maybeOptions, cb) {
700
- var options = maybeOptions ? __assign({}, maybeOptions) : {};
701
- if (options.lang === '*')
702
- throw new Error("FORBIDDEN. You can't use getByUID with *, use the predicates instead.");
703
- if (!options.page)
704
- options.page = 1;
705
- return this.queryFirst(Predicates.at("my." + type + ".uid", uid), options, cb);
706
- };
707
- /**
708
- * Retrieve the singleton document with the given type
709
- */
710
- ResolvedApi.prototype.getSingle = function (type, maybeOptions, cb) {
711
- var options = maybeOptions ? __assign({}, maybeOptions) : {};
712
- return this.queryFirst(Predicates.at('document.type', type), options, cb);
713
- };
714
- /**
715
- * Retrieve the document with the given bookmark
716
- */
717
- ResolvedApi.prototype.getBookmark = function (bookmark, maybeOptions, cb) {
718
- var id = this.data.bookmarks[bookmark];
719
- if (id) {
720
- return this.getByID(id, maybeOptions, cb);
721
- }
722
- else {
723
- return Promise.reject('Error retrieving bookmarked id');
724
- }
725
- };
726
- ResolvedApi.prototype.getPreviewResolver = function (token, documentId) {
727
- return createPreviewResolver(token, documentId, this.getByID.bind(this));
728
- };
729
- ResolvedApi.prototype.previewSession = function (token, linkResolver, defaultUrl, cb) {
730
- var _this = this;
731
- console.warn('previewSession function is deprecated in favor of getPreviewResolver function.');
732
- return new Promise(function (resolve, reject) {
733
- _this.httpClient.request(token, function (e, result) {
734
- if (e) {
735
- cb && cb(e);
736
- reject(e);
737
- }
738
- else if (result) {
739
- if (!result.mainDocument) {
740
- cb && cb(null, defaultUrl);
741
- resolve(defaultUrl);
742
- }
743
- else {
744
- return _this.getByID(result.mainDocument, { ref: token }).then(function (document) {
745
- if (!document) {
746
- cb && cb(null, defaultUrl);
747
- resolve(defaultUrl);
748
- }
749
- else {
750
- var url = (linkResolver && linkResolver(document)) || document.url || defaultUrl;
751
- cb && cb(null, url);
752
- resolve(url);
753
- }
754
- }).catch(reject);
755
- }
756
- }
757
- });
758
- });
759
- };
760
- return ResolvedApi;
761
- }());
762
-
763
- /* eslint-disable */
764
- /**
765
- * A doubly linked list-based Least Recently Used (LRU) cache. Will keep most
766
- * recently used items while discarding least recently used items when its limit
767
- * is reached.
768
- *
769
- * Licensed under MIT. Copyright (c) 2010 Rasmus Andersson <http://hunch.se/>
770
- * Typescript-ified by Oleksandr Nikitin <https://tvori.info>
771
- *
772
- * Illustration of the design:
773
- *
774
- * entry entry entry entry
775
- * ______ ______ ______ ______
776
- * | head |.newer => | |.newer => | |.newer => | tail |
777
- * | A | | B | | C | | D |
778
- * |______| <= older.|______| <= older.|______| <= older.|______|
779
- *
780
- * removed <-- <-- <-- <-- <-- <-- <-- <-- <-- <-- <-- added
781
- */
782
- function MakeLRUCache(limit) {
783
- return new LRUCache(limit);
784
- }
785
- function LRUCache(limit) {
786
- // Current size of the cache. (Read-only).
787
- this.size = 0;
788
- // Maximum number of items this cache can hold.
789
- this.limit = limit;
790
- this._keymap = {};
791
- }
792
- /**
793
- * Put <value> into the cache associated with <key>. Returns the entry which was
794
- * removed to make room for the new entry. Otherwise undefined is returned
795
- * (i.e. if there was enough room already).
796
- */
797
- LRUCache.prototype.put = function (key, value) {
798
- var entry = { key: key, value: value };
799
- // Note: No protection agains replacing, and thus orphan entries. By design.
800
- this._keymap[key] = entry;
801
- if (this.tail) {
802
- // link previous tail to the new tail (entry)
803
- this.tail.newer = entry;
804
- entry.older = this.tail;
805
- }
806
- else {
807
- // we're first in -- yay
808
- this.head = entry;
809
- }
810
- // add new entry to the end of the linked list -- it's now the freshest entry.
811
- this.tail = entry;
812
- if (this.size === this.limit) {
813
- // we hit the limit -- remove the head
814
- return this.shift();
815
- }
816
- else {
817
- // increase the size counter
818
- this.size++;
819
- }
820
- };
821
- /**
822
- * Purge the least recently used (oldest) entry from the cache. Returns the
823
- * removed entry or undefined if the cache was empty.
824
- *
825
- * If you need to perform any form of finalization of purged items, this is a
826
- * good place to do it. Simply override/replace this function:
827
- *
828
- * var c = new LRUCache(123);
829
- * c.shift = function() {
830
- * var entry = LRUCache.prototype.shift.call(this);
831
- * doSomethingWith(entry);
832
- * return entry;
833
- * }
834
- */
835
- LRUCache.prototype.shift = function () {
836
- // todo: handle special case when limit == 1
837
- var entry = this.head;
838
- if (entry) {
839
- if (this.head.newer) {
840
- this.head = this.head.newer;
841
- this.head.older = undefined;
842
- }
843
- else {
844
- this.head = undefined;
845
- }
846
- // Remove last strong reference to <entry> and remove links from the purged
847
- // entry being returned:
848
- entry.newer = entry.older = undefined;
849
- // delete is slow, but we need to do this to avoid uncontrollable growth:
850
- delete this._keymap[entry.key];
851
- }
852
- console.log('purging ', entry.key);
853
- return entry;
854
- };
855
- /**
856
- * Get and register recent use of <key>. Returns the value associated with <key>
857
- * or undefined if not in cache.
858
- */
859
- LRUCache.prototype.get = function (key, returnEntry) {
860
- // First, find our cache entry
861
- var entry = this._keymap[key];
862
- if (entry === undefined)
863
- return; // Not cached. Sorry.
864
- // As <key> was found in the cache, register it as being requested recently
865
- if (entry === this.tail) {
866
- // Already the most recently used entry, so no need to update the list
867
- return returnEntry ? entry : entry.value;
868
- }
869
- // HEAD--------------TAIL
870
- // <.older .newer>
871
- // <--- add direction --
872
- // A B C <D> E
873
- if (entry.newer) {
874
- if (entry === this.head)
875
- this.head = entry.newer;
876
- entry.newer.older = entry.older; // C <-- E.
877
- }
878
- if (entry.older)
879
- entry.older.newer = entry.newer; // C. --> E
880
- entry.newer = undefined; // D --x
881
- entry.older = this.tail; // D. --> E
882
- if (this.tail)
883
- this.tail.newer = entry; // E. <-- D
884
- this.tail = entry;
885
- return returnEntry ? entry : entry.value;
886
- };
887
- // ----------------------------------------------------------------------------
888
- // Following code is optional and can be removed without breaking the core
889
- // functionality.
890
- /**
891
- * Check if <key> is in the cache without registering recent use. Feasible if
892
- * you do not want to chage the state of the cache, but only "peek" at it.
893
- * Returns the entry associated with <key> if found, or undefined if not found.
894
- */
895
- LRUCache.prototype.find = function (key) {
896
- return this._keymap[key];
897
- };
898
- /**
899
- * Update the value of entry with <key>. Returns the old value, or undefined if
900
- * entry was not in the cache.
901
- */
902
- LRUCache.prototype.set = function (key, value) {
903
- var oldvalue;
904
- var entry = this.get(key, true);
905
- if (entry) {
906
- oldvalue = entry.value;
907
- entry.value = value;
908
- }
909
- else {
910
- oldvalue = this.put(key, value);
911
- if (oldvalue)
912
- oldvalue = oldvalue.value;
913
- }
914
- return oldvalue;
915
- };
916
- /**
917
- * Remove entry <key> from cache and return its value. Returns undefined if not
918
- * found.
919
- */
920
- LRUCache.prototype.remove = function (key) {
921
- var entry = this._keymap[key];
922
- if (!entry)
923
- return;
924
- delete this._keymap[entry.key]; // need to do delete unfortunately
925
- if (entry.newer && entry.older) {
926
- // relink the older entry with the newer entry
927
- entry.older.newer = entry.newer;
928
- entry.newer.older = entry.older;
929
- }
930
- else if (entry.newer) {
931
- // remove the link to us
932
- entry.newer.older = undefined;
933
- // link the newer entry to head
934
- this.head = entry.newer;
935
- }
936
- else if (entry.older) {
937
- // remove the link to us
938
- entry.older.newer = undefined;
939
- // link the newer entry to head
940
- this.tail = entry.older;
941
- }
942
- else { // if(entry.older === undefined && entry.newer === undefined) {
943
- this.head = this.tail = undefined;
944
- }
945
- this.size--;
946
- return entry.value;
947
- };
948
- /** Removes all entries */
949
- LRUCache.prototype.removeAll = function () {
950
- // This should be safe, as we never expose strong refrences to the outside
951
- this.head = this.tail = undefined;
952
- this.size = 0;
953
- this._keymap = {};
954
- };
955
- /**
956
- * Return an array containing all keys of entries stored in the cache object, in
957
- * arbitrary order.
958
- */
959
- if (typeof Object.keys === 'function') {
960
- LRUCache.prototype.keys = function () { return Object.keys(this._keymap); };
961
- }
962
- else {
963
- LRUCache.prototype.keys = function () {
964
- var keys = [];
965
- for (var k in this._keymap)
966
- keys.push(k);
967
- return keys;
968
- };
969
- }
970
- /**
971
- * Call `fun` for each entry. Starting with the newest entry if `desc` is a true
972
- * value, otherwise starts with the oldest (head) enrty and moves towards the
973
- * tail.
974
- *
975
- * `fun` is called with 3 arguments in the context `context`:
976
- * `fun.call(context, Object key, Object value, LRUCache self)`
977
- */
978
- LRUCache.prototype.forEach = function (fun, context, desc) {
979
- var entry;
980
- if (context === true) {
981
- desc = true;
982
- context = undefined;
983
- }
984
- else if (typeof context !== 'object')
985
- context = this;
986
- if (desc) {
987
- entry = this.tail;
988
- while (entry) {
989
- fun.call(context, entry.key, entry.value, this);
990
- entry = entry.older;
991
- }
992
- }
993
- else {
994
- entry = this.head;
995
- while (entry) {
996
- fun.call(context, entry.key, entry.value, this);
997
- entry = entry.newer;
998
- }
999
- }
1000
- };
1001
- /** Returns a JSON (array) representation */
1002
- //LRUCache.prototype.toJSON = function () {
1003
- // var s: IEntry[] = [], entry = this.head;
1004
- // while (entry) {
1005
- // s.push({ key: entry.key.toJSON(), value: entry.value.toJSON() });
1006
- // entry = entry.newer;
1007
- // }
1008
- // return s;
1009
- //};
1010
- /** Returns a String representation */
1011
- LRUCache.prototype.toString = function () {
1012
- var s = '', entry = this.head;
1013
- while (entry) {
1014
- s += String(entry.key) + ':' + entry.value;
1015
- entry = entry.newer;
1016
- if (entry)
1017
- s += ' < ';
1018
- }
1019
- return s;
1020
- };
1021
- // Export ourselves
1022
- //if (typeof this === 'object') this.LRUCache = LRUCache;
1023
-
1024
- var DefaultApiCache = /** @class */ (function () {
1025
- function DefaultApiCache(limit) {
1026
- if (limit === void 0) { limit = 1000; }
1027
- this.lru = MakeLRUCache(limit);
1028
- }
1029
- DefaultApiCache.prototype.isExpired = function (key) {
1030
- var value = this.lru.get(key, false);
1031
- if (value) {
1032
- return value.expiredIn !== 0 && value.expiredIn < Date.now();
1033
- }
1034
- else {
1035
- return false;
1036
- }
1037
- };
1038
- DefaultApiCache.prototype.get = function (key, cb) {
1039
- var value = this.lru.get(key, false);
1040
- if (value && !this.isExpired(key)) {
1041
- cb(null, value.data);
1042
- }
1043
- else {
1044
- cb && cb(null);
1045
- }
1046
- };
1047
- DefaultApiCache.prototype.set = function (key, value, ttl, cb) {
1048
- this.lru.remove(key);
1049
- this.lru.put(key, {
1050
- data: value,
1051
- expiredIn: ttl ? (Date.now() + (ttl * 1000)) : 0,
1052
- });
1053
- cb && cb(null);
1054
- };
1055
- DefaultApiCache.prototype.remove = function (key, cb) {
1056
- this.lru.remove(key);
1057
- cb && cb(null);
1058
- };
1059
- DefaultApiCache.prototype.clear = function (cb) {
1060
- this.lru.removeAll();
1061
- cb && cb(null);
1062
- };
1063
- return DefaultApiCache;
1064
- }());
1065
-
1066
- function fetchRequest(url, options, callback) {
1067
- var fetchOptions = {
1068
- headers: {
1069
- Accept: 'application/json',
1070
- },
1071
- };
1072
- if (options && options.proxyAgent) {
1073
- fetchOptions.agent = options.proxyAgent;
1074
- }
1075
- // can't use number because of NodeJS globals included
1076
- var timeoutId;
1077
- var fetchPromise = crossFetch(url, fetchOptions);
1078
- var promise = options.timeoutInMs ? Promise.race([
1079
- fetchPromise,
1080
- new Promise(function (_, reject) {
1081
- timeoutId = setTimeout(function () { return reject(new Error(url + " response timeout")); }, options.timeoutInMs);
1082
- })
1083
- ]) : fetchPromise;
1084
- promise.then(function (resp) {
1085
- clearTimeout(timeoutId);
1086
- if (~~(resp.status / 100 !== 2)) {
1087
- /**
1088
- * @description
1089
- * drain the resp before throwing an error to prevent memory leaks
1090
- * @link https://github.com/bitinn/node-fetch/issues/83
1091
- */
1092
- return resp.text().then(function () {
1093
- var e = new Error("Unexpected status code [" + resp.status + "] on URL " + url);
1094
- e.status = resp.status;
1095
- throw e;
1096
- });
1097
- }
1098
- return resp.json().then(function (result) {
1099
- var cacheControl = resp.headers.get('cache-control');
1100
- var parsedCacheControl = cacheControl ? /max-age=(\d+)/.exec(cacheControl) : null;
1101
- var ttl = parsedCacheControl ? parseInt(parsedCacheControl[1], 10) : undefined;
1102
- callback(null, result, resp, ttl);
1103
- });
1104
- }).catch(function (err) {
1105
- clearTimeout(timeoutId);
1106
- callback(err);
1107
- });
1108
- }
1109
- var DefaultRequestHandler = /** @class */ (function () {
1110
- function DefaultRequestHandler(options) {
1111
- this.options = options || {};
1112
- }
1113
- DefaultRequestHandler.prototype.request = function (url, callback) {
1114
- fetchRequest(url, this.options, callback);
1115
- };
1116
- return DefaultRequestHandler;
1117
- }());
1118
-
1119
- var HttpClient = /** @class */ (function () {
1120
- function HttpClient(requestHandler, cache, proxyAgent, timeoutInMs) {
1121
- this.requestHandler = requestHandler || new DefaultRequestHandler({ proxyAgent: proxyAgent, timeoutInMs: timeoutInMs });
1122
- this.cache = cache || new DefaultApiCache();
1123
- }
1124
- HttpClient.prototype.request = function (url, callback) {
1125
- this.requestHandler.request(url, function (err, result, xhr, ttl) {
1126
- if (err) {
1127
- callback && callback(err, null, xhr, ttl);
1128
- }
1129
- else if (result) {
1130
- callback && callback(null, result, xhr, ttl);
1131
- }
1132
- });
1133
- };
1134
- /**
1135
- * Fetch a URL corresponding to a query, and parse the response as a Response object
1136
- */
1137
- HttpClient.prototype.cachedRequest = function (url, maybeOptions) {
1138
- var _this = this;
1139
- var options = maybeOptions || {};
1140
- var run = function (cb) {
1141
- var cacheKey = options.cacheKey || url;
1142
- _this.cache.get(cacheKey, function (cacheGetError, cacheGetValue) {
1143
- if (cacheGetError || cacheGetValue) {
1144
- cb(cacheGetError, cacheGetValue);
1145
- }
1146
- else {
1147
- _this.request(url, function (fetchError, fetchValue, _, ttlReq) {
1148
- if (fetchError) {
1149
- cb(fetchError, null);
1150
- }
1151
- else {
1152
- var ttl = ttlReq || options.ttl;
1153
- if (ttl) {
1154
- _this.cache.set(cacheKey, fetchValue, ttl, cb);
1155
- }
1156
- cb(null, fetchValue);
1157
- }
1158
- });
1159
- }
1160
- });
1161
- };
1162
- return new Promise(function (resolve, reject) {
1163
- run(function (err, value) {
1164
- if (err)
1165
- reject(err);
1166
- if (value)
1167
- resolve(value);
1168
- });
1169
- });
1170
- };
1171
- return HttpClient;
1172
- }());
1173
-
1174
- function separator(url) {
1175
- return url.indexOf('?') > -1 ? '&' : '?';
1176
- }
1177
- var Api = /** @class */ (function () {
1178
- function Api(url, options) {
1179
- this.options = options || {};
1180
- this.url = url;
1181
- if (this.options.accessToken) {
1182
- var accessTokenParam = "access_token=" + this.options.accessToken;
1183
- this.url += separator(url) + accessTokenParam;
1184
- }
1185
- if (this.options.routes) {
1186
- this.url += separator(url) + ("routes=" + encodeURIComponent(JSON.stringify(this.options.routes)));
1187
- }
1188
- this.apiDataTTL = this.options.apiDataTTL || 5;
1189
- this.httpClient = new HttpClient(this.options.requestHandler, this.options.apiCache, this.options.proxyAgent, this.options.timeoutInMs);
1190
- }
1191
- /**
1192
- * Fetches data used to construct the api client, from cache if it's
1193
- * present, otherwise from calling the prismic api endpoint (which is
1194
- * then cached).
1195
- */
1196
- Api.prototype.get = function (cb) {
1197
- var _this = this;
1198
- return this.httpClient.cachedRequest(this.url, { ttl: this.apiDataTTL }).then(function (data) {
1199
- var resolvedApi = new ResolvedApi(data, _this.httpClient, _this.options);
1200
- cb && cb(null, resolvedApi);
1201
- return resolvedApi;
1202
- }).catch(function (error) {
1203
- cb && cb(error);
1204
- throw error;
1205
- });
1206
- };
1207
- return Api;
1208
- }());
1209
-
1210
- var DefaultClient = /** @class */ (function () {
1211
- function DefaultClient(url, options) {
1212
- this.api = new Api(url, options);
1213
- }
1214
- DefaultClient.prototype.getApi = function () {
1215
- return this.api.get();
1216
- };
1217
- DefaultClient.prototype.everything = function () {
1218
- return this.form('everything');
1219
- };
1220
- DefaultClient.prototype.form = function (formId) {
1221
- return new LazySearchForm(formId, this.api);
1222
- };
1223
- DefaultClient.prototype.query = function (q, optionsOrCallback, cb) {
1224
- return this.getApi().then(function (api) { return api.query(q, optionsOrCallback, cb); });
1225
- };
1226
- DefaultClient.prototype.queryFirst = function (q, optionsOrCallback, cb) {
1227
- return this.getApi().then(function (api) { return api.queryFirst(q, optionsOrCallback, cb); });
1228
- };
1229
- DefaultClient.prototype.getByID = function (id, options, cb) {
1230
- return this.getApi().then(function (api) { return api.getByID(id, options, cb); });
1231
- };
1232
- DefaultClient.prototype.getByIDs = function (ids, options, cb) {
1233
- return this.getApi().then(function (api) { return api.getByIDs(ids, options, cb); });
1234
- };
1235
- DefaultClient.prototype.getByUID = function (type, uid, options, cb) {
1236
- return this.getApi().then(function (api) { return api.getByUID(type, uid, options, cb); });
1237
- };
1238
- DefaultClient.prototype.getSingle = function (type, options, cb) {
1239
- return this.getApi().then(function (api) { return api.getSingle(type, options, cb); });
1240
- };
1241
- DefaultClient.prototype.getBookmark = function (bookmark, options, cb) {
1242
- return this.getApi().then(function (api) { return api.getBookmark(bookmark, options, cb); });
1243
- };
1244
- DefaultClient.prototype.previewSession = function (token, linkResolver, defaultUrl, cb) {
1245
- return this.getApi().then(function (api) { return api.previewSession(token, linkResolver, defaultUrl, cb); });
1246
- };
1247
- DefaultClient.prototype.getPreviewResolver = function (token, documentId) {
1248
- var _this = this;
1249
- var getDocById = function (documentId, maybeOptions) { return _this.getApi().then(function (api) {
1250
- return api.getByID(documentId, maybeOptions);
1251
- }); };
1252
- return createPreviewResolver(token, documentId, getDocById);
1253
- };
1254
- DefaultClient.getApi = function (url, options) {
1255
- var api = new Api(url, options);
1256
- return api.get();
1257
- };
1258
- return DefaultClient;
1259
- }());
1260
-
1261
- var index = {
1262
- experimentCookie: EXPERIMENT_COOKIE,
1263
- previewCookie: PREVIEW_COOKIE,
1264
- Predicates: Predicates,
1265
- Experiments: Experiments,
1266
- Api: Api,
1267
- client: client,
1268
- getApi: getApi,
1269
- api: api,
1270
- };
1271
- function client(url, options) {
1272
- return new DefaultClient(url, options);
1273
- }
1274
- function getApi(url, options) {
1275
- return DefaultClient.getApi(url, options);
1276
- }
1277
- function api(url, options) {
1278
- return getApi(url, options);
1279
- }
1280
-
1281
- module.exports = index;
1282
- //# sourceMappingURL=prismic-javascript.js.map