@storyblok/js 3.0.1 → 3.0.2
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/storyblok-js.js +2 -2
- package/dist/storyblok-js.mjs +360 -342
- package/package.json +2 -2
package/dist/storyblok-js.mjs
CHANGED
@@ -1,76 +1,76 @@
|
|
1
|
-
let
|
2
|
-
const
|
3
|
-
if (typeof window > "u" || (window.storyblokRegisterEvent = (
|
1
|
+
let I = !1;
|
2
|
+
const v = [], w = (i) => new Promise((e, t) => {
|
3
|
+
if (typeof window > "u" || (window.storyblokRegisterEvent = (s) => {
|
4
4
|
if (window.location === window.parent.location) {
|
5
5
|
console.warn("You are not in Draft Mode or in the Visual Editor.");
|
6
6
|
return;
|
7
7
|
}
|
8
|
-
|
8
|
+
I ? s() : v.push(s);
|
9
9
|
}, document.getElementById("storyblok-javascript-bridge")))
|
10
10
|
return;
|
11
|
-
const
|
12
|
-
|
13
|
-
|
14
|
-
}, document.getElementsByTagName("head")[0].appendChild(
|
11
|
+
const r = document.createElement("script");
|
12
|
+
r.async = !0, r.src = i, r.id = "storyblok-javascript-bridge", r.onerror = (s) => t(s), r.onload = (s) => {
|
13
|
+
v.forEach((o) => o()), I = !0, e(s);
|
14
|
+
}, document.getElementsByTagName("head")[0].appendChild(r);
|
15
15
|
});
|
16
|
-
var
|
17
|
-
function
|
18
|
-
return !(
|
16
|
+
var j = Object.defineProperty, U = (i, e, t) => e in i ? j(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t, h = (i, e, t) => (U(i, typeof e != "symbol" ? e + "" : e, t), t);
|
17
|
+
function N(i) {
|
18
|
+
return !(i !== i || i === 1 / 0 || i === -1 / 0);
|
19
19
|
}
|
20
|
-
function
|
21
|
-
if (!
|
20
|
+
function H(i, e, t) {
|
21
|
+
if (!N(e))
|
22
22
|
throw new TypeError("Expected `limit` to be a finite number");
|
23
|
-
if (!
|
23
|
+
if (!N(t))
|
24
24
|
throw new TypeError("Expected `interval` to be a finite number");
|
25
|
-
const
|
26
|
-
let
|
27
|
-
const
|
28
|
-
|
25
|
+
const r = [];
|
26
|
+
let s = [], o = 0;
|
27
|
+
const n = function() {
|
28
|
+
o++;
|
29
29
|
const a = setTimeout(function() {
|
30
|
-
|
30
|
+
o--, r.length > 0 && n(), s = s.filter(function(u) {
|
31
31
|
return u !== a;
|
32
32
|
});
|
33
33
|
}, t);
|
34
|
-
|
35
|
-
const l =
|
36
|
-
l.resolve(
|
34
|
+
s.indexOf(a) < 0 && s.push(a);
|
35
|
+
const l = r.shift();
|
36
|
+
l.resolve(i.apply(l.self, l.args));
|
37
37
|
}, c = function(...a) {
|
38
38
|
const l = this;
|
39
39
|
return new Promise(function(u, d) {
|
40
|
-
|
40
|
+
r.push({
|
41
41
|
resolve: u,
|
42
42
|
reject: d,
|
43
43
|
args: a,
|
44
44
|
self: l
|
45
|
-
}),
|
45
|
+
}), o < e && n();
|
46
46
|
});
|
47
47
|
};
|
48
48
|
return c.abort = function() {
|
49
|
-
|
49
|
+
s.forEach(clearTimeout), s = [], r.forEach(function(a) {
|
50
50
|
a.reject(function() {
|
51
51
|
Error.call(this, "Throttled function aborted"), this.name = "AbortError";
|
52
52
|
});
|
53
|
-
}),
|
53
|
+
}), r.length = 0;
|
54
54
|
}, c;
|
55
55
|
}
|
56
56
|
class b {
|
57
57
|
constructor() {
|
58
|
-
h(this, "isCDNUrl", (e = "") => e.indexOf("/cdn/") > -1), h(this, "getOptionsPage", (e, t = 25,
|
58
|
+
h(this, "isCDNUrl", (e = "") => e.indexOf("/cdn/") > -1), h(this, "getOptionsPage", (e, t = 25, r = 1) => ({
|
59
59
|
...e,
|
60
60
|
per_page: t,
|
61
|
-
page:
|
61
|
+
page: r
|
62
62
|
})), h(this, "delay", (e) => new Promise((t) => setTimeout(t, e))), h(this, "arrayFrom", (e = 0, t) => [...Array(e)].map(t)), h(this, "range", (e = 0, t = e) => {
|
63
|
-
const
|
64
|
-
return this.arrayFrom(
|
65
|
-
}), h(this, "asyncMap", async (e, t) => Promise.all(e.map(t))), h(this, "flatMap", (e = [], t) => e.map(t).reduce((
|
63
|
+
const r = Math.abs(t - e) || 0, s = e < t ? 1 : -1;
|
64
|
+
return this.arrayFrom(r, (o, n) => n * s + e);
|
65
|
+
}), h(this, "asyncMap", async (e, t) => Promise.all(e.map(t))), h(this, "flatMap", (e = [], t) => e.map(t).reduce((r, s) => [...r, ...s], [])), h(this, "escapeHTML", function(e) {
|
66
66
|
const t = {
|
67
67
|
"&": "&",
|
68
68
|
"<": "<",
|
69
69
|
">": ">",
|
70
70
|
'"': """,
|
71
71
|
"'": "'"
|
72
|
-
},
|
73
|
-
return e &&
|
72
|
+
}, r = /[&<>"']/g, s = RegExp(r.source);
|
73
|
+
return e && s.test(e) ? e.replace(r, (o) => t[o]) : e;
|
74
74
|
});
|
75
75
|
}
|
76
76
|
/**
|
@@ -80,20 +80,20 @@ class b {
|
|
80
80
|
* @param {Boolean} isArray
|
81
81
|
* @return {String} Stringified object
|
82
82
|
*/
|
83
|
-
stringify(e, t,
|
84
|
-
const
|
85
|
-
for (const
|
86
|
-
if (!Object.prototype.hasOwnProperty.call(e,
|
83
|
+
stringify(e, t, r) {
|
84
|
+
const s = [];
|
85
|
+
for (const o in e) {
|
86
|
+
if (!Object.prototype.hasOwnProperty.call(e, o))
|
87
87
|
continue;
|
88
|
-
const
|
88
|
+
const n = e[o], c = r ? "" : encodeURIComponent(o);
|
89
89
|
let a;
|
90
|
-
typeof
|
91
|
-
|
90
|
+
typeof n == "object" ? a = this.stringify(
|
91
|
+
n,
|
92
92
|
t ? t + encodeURIComponent("[" + c + "]") : c,
|
93
|
-
Array.isArray(
|
94
|
-
) : a = (t ? t + encodeURIComponent("[" + c + "]") : c) + "=" + encodeURIComponent(
|
93
|
+
Array.isArray(n)
|
94
|
+
) : a = (t ? t + encodeURIComponent("[" + c + "]") : c) + "=" + encodeURIComponent(n), s.push(a);
|
95
95
|
}
|
96
|
-
return
|
96
|
+
return s.join("&");
|
97
97
|
}
|
98
98
|
/**
|
99
99
|
* @method getRegionURL
|
@@ -101,91 +101,91 @@ class b {
|
|
101
101
|
* @return {String} The base URL of the region
|
102
102
|
*/
|
103
103
|
getRegionURL(e) {
|
104
|
-
const t = "api.storyblok.com",
|
104
|
+
const t = "api.storyblok.com", r = "api-us.storyblok.com", s = "app.storyblokchina.cn", o = "api-ap.storyblok.com", n = "api-ca.storyblok.com";
|
105
105
|
switch (e) {
|
106
106
|
case "us":
|
107
|
-
return s;
|
108
|
-
case "cn":
|
109
107
|
return r;
|
108
|
+
case "cn":
|
109
|
+
return s;
|
110
110
|
case "ap":
|
111
|
-
return i;
|
112
|
-
case "ca":
|
113
111
|
return o;
|
112
|
+
case "ca":
|
113
|
+
return n;
|
114
114
|
default:
|
115
115
|
return t;
|
116
116
|
}
|
117
117
|
}
|
118
118
|
}
|
119
|
-
const
|
119
|
+
const P = function(i, e) {
|
120
120
|
const t = {};
|
121
|
-
for (const
|
122
|
-
const
|
123
|
-
e.indexOf(
|
121
|
+
for (const r in i) {
|
122
|
+
const s = i[r];
|
123
|
+
e.indexOf(r) > -1 && s !== null && (t[r] = s);
|
124
124
|
}
|
125
125
|
return t;
|
126
|
-
},
|
126
|
+
}, x = (i) => i === "email", C = () => ({
|
127
127
|
singleTag: "hr"
|
128
|
-
}),
|
128
|
+
}), G = () => ({
|
129
129
|
tag: "blockquote"
|
130
|
-
}),
|
130
|
+
}), L = () => ({
|
131
131
|
tag: "ul"
|
132
|
-
}),
|
132
|
+
}), $ = (i) => ({
|
133
133
|
tag: [
|
134
134
|
"pre",
|
135
135
|
{
|
136
136
|
tag: "code",
|
137
|
-
attrs:
|
137
|
+
attrs: i.attrs
|
138
138
|
}
|
139
139
|
]
|
140
|
-
}),
|
140
|
+
}), M = () => ({
|
141
141
|
singleTag: "br"
|
142
|
-
}),
|
143
|
-
tag: `h${
|
144
|
-
}),
|
142
|
+
}), B = (i) => ({
|
143
|
+
tag: `h${i.attrs.level}`
|
144
|
+
}), D = (i) => ({
|
145
145
|
singleTag: [
|
146
146
|
{
|
147
147
|
tag: "img",
|
148
|
-
attrs:
|
148
|
+
attrs: P(i.attrs, ["src", "alt", "title"])
|
149
149
|
}
|
150
150
|
]
|
151
|
-
}),
|
151
|
+
}), V = () => ({
|
152
152
|
tag: "li"
|
153
|
-
}),
|
153
|
+
}), F = () => ({
|
154
154
|
tag: "ol"
|
155
|
-
}),
|
155
|
+
}), z = () => ({
|
156
156
|
tag: "p"
|
157
|
-
}),
|
157
|
+
}), W = (i) => ({
|
158
158
|
tag: [
|
159
159
|
{
|
160
160
|
tag: "span",
|
161
161
|
attrs: {
|
162
162
|
"data-type": "emoji",
|
163
|
-
"data-name":
|
164
|
-
emoji:
|
163
|
+
"data-name": i.attrs.name,
|
164
|
+
emoji: i.attrs.emoji
|
165
165
|
}
|
166
166
|
}
|
167
167
|
]
|
168
|
-
}),
|
168
|
+
}), K = () => ({
|
169
169
|
tag: "b"
|
170
|
-
}),
|
170
|
+
}), X = () => ({
|
171
171
|
tag: "s"
|
172
|
-
}),
|
172
|
+
}), J = () => ({
|
173
173
|
tag: "u"
|
174
|
-
}),
|
174
|
+
}), Y = () => ({
|
175
175
|
tag: "strong"
|
176
|
-
}),
|
176
|
+
}), q = () => ({
|
177
177
|
tag: "code"
|
178
|
-
}),
|
178
|
+
}), Q = () => ({
|
179
179
|
tag: "i"
|
180
|
-
}),
|
181
|
-
if (!
|
180
|
+
}), Z = (i) => {
|
181
|
+
if (!i.attrs)
|
182
182
|
return {
|
183
183
|
tag: ""
|
184
184
|
};
|
185
|
-
const e = new b().escapeHTML, t = { ...
|
186
|
-
if (delete t.linktype, t.href && (t.href = e(
|
187
|
-
for (const
|
188
|
-
t[
|
185
|
+
const e = new b().escapeHTML, t = { ...i.attrs }, { linktype: r = "url" } = i.attrs;
|
186
|
+
if (delete t.linktype, t.href && (t.href = e(i.attrs.href || "")), x(r) && (t.href = `mailto:${t.href}`), t.anchor && (t.href = `${t.href}#${t.anchor}`, delete t.anchor), t.custom) {
|
187
|
+
for (const s in t.custom)
|
188
|
+
t[s] = t.custom[s];
|
189
189
|
delete t.custom;
|
190
190
|
}
|
191
191
|
return {
|
@@ -196,94 +196,94 @@ const N = function(n, e) {
|
|
196
196
|
}
|
197
197
|
]
|
198
198
|
};
|
199
|
-
}, ee = (
|
199
|
+
}, ee = (i) => ({
|
200
200
|
tag: [
|
201
201
|
{
|
202
202
|
tag: "span",
|
203
|
-
attrs:
|
203
|
+
attrs: i.attrs
|
204
204
|
}
|
205
205
|
]
|
206
206
|
}), te = () => ({
|
207
207
|
tag: "sub"
|
208
|
-
}),
|
208
|
+
}), re = () => ({
|
209
209
|
tag: "sup"
|
210
|
-
}),
|
210
|
+
}), se = (i) => ({
|
211
211
|
tag: [
|
212
212
|
{
|
213
213
|
tag: "span",
|
214
|
-
attrs:
|
214
|
+
attrs: i.attrs
|
215
215
|
}
|
216
216
|
]
|
217
|
-
}),
|
217
|
+
}), oe = (i) => {
|
218
218
|
var e;
|
219
|
-
return (e =
|
219
|
+
return (e = i.attrs) != null && e.color ? {
|
220
220
|
tag: [
|
221
221
|
{
|
222
222
|
tag: "span",
|
223
223
|
attrs: {
|
224
|
-
style: `background-color:${
|
224
|
+
style: `background-color:${i.attrs.color};`
|
225
225
|
}
|
226
226
|
}
|
227
227
|
]
|
228
228
|
} : {
|
229
229
|
tag: ""
|
230
230
|
};
|
231
|
-
}, ne = (
|
231
|
+
}, ne = (i) => {
|
232
232
|
var e;
|
233
|
-
return (e =
|
233
|
+
return (e = i.attrs) != null && e.color ? {
|
234
234
|
tag: [
|
235
235
|
{
|
236
236
|
tag: "span",
|
237
237
|
attrs: {
|
238
|
-
style: `color:${
|
238
|
+
style: `color:${i.attrs.color}`
|
239
239
|
}
|
240
240
|
}
|
241
241
|
]
|
242
242
|
} : {
|
243
243
|
tag: ""
|
244
244
|
};
|
245
|
-
},
|
245
|
+
}, ie = {
|
246
246
|
nodes: {
|
247
|
-
horizontal_rule:
|
248
|
-
blockquote:
|
249
|
-
bullet_list:
|
250
|
-
code_block:
|
251
|
-
hard_break:
|
252
|
-
heading:
|
253
|
-
image:
|
254
|
-
list_item:
|
255
|
-
ordered_list:
|
256
|
-
paragraph:
|
257
|
-
emoji:
|
247
|
+
horizontal_rule: C,
|
248
|
+
blockquote: G,
|
249
|
+
bullet_list: L,
|
250
|
+
code_block: $,
|
251
|
+
hard_break: M,
|
252
|
+
heading: B,
|
253
|
+
image: D,
|
254
|
+
list_item: V,
|
255
|
+
ordered_list: F,
|
256
|
+
paragraph: z,
|
257
|
+
emoji: W
|
258
258
|
},
|
259
259
|
marks: {
|
260
|
-
bold:
|
261
|
-
strike:
|
262
|
-
underline:
|
263
|
-
strong:
|
264
|
-
code:
|
265
|
-
italic:
|
266
|
-
link:
|
260
|
+
bold: K,
|
261
|
+
strike: X,
|
262
|
+
underline: J,
|
263
|
+
strong: Y,
|
264
|
+
code: q,
|
265
|
+
italic: Q,
|
266
|
+
link: Z,
|
267
267
|
styled: ee,
|
268
268
|
subscript: te,
|
269
|
-
superscript:
|
270
|
-
anchor:
|
271
|
-
highlight:
|
269
|
+
superscript: re,
|
270
|
+
anchor: se,
|
271
|
+
highlight: oe,
|
272
272
|
textStyle: ne
|
273
273
|
}
|
274
|
-
}, ae = function(
|
274
|
+
}, ae = function(i) {
|
275
275
|
const e = {
|
276
276
|
"&": "&",
|
277
277
|
"<": "<",
|
278
278
|
">": ">",
|
279
279
|
'"': """,
|
280
280
|
"'": "'"
|
281
|
-
}, t = /[&<>"']/g,
|
282
|
-
return
|
281
|
+
}, t = /[&<>"']/g, r = RegExp(t.source);
|
282
|
+
return i && r.test(i) ? i.replace(t, (s) => e[s]) : i;
|
283
283
|
};
|
284
|
-
class
|
284
|
+
class T {
|
285
285
|
constructor(e) {
|
286
|
-
h(this, "marks"), h(this, "nodes"), e || (e =
|
286
|
+
h(this, "marks"), h(this, "nodes"), e || (e = ie), this.marks = e.marks || [], this.nodes = e.nodes || [];
|
287
287
|
}
|
288
288
|
addNode(e, t) {
|
289
289
|
this.nodes[e] = t;
|
@@ -293,10 +293,10 @@ class v {
|
|
293
293
|
}
|
294
294
|
render(e, t = { optimizeImages: !1 }) {
|
295
295
|
if (e && e.content && Array.isArray(e.content)) {
|
296
|
-
let
|
297
|
-
return e.content.forEach((
|
298
|
-
|
299
|
-
}), t.optimizeImages ? this.optimizeImages(
|
296
|
+
let r = "";
|
297
|
+
return e.content.forEach((s) => {
|
298
|
+
r += this.renderNode(s);
|
299
|
+
}), t.optimizeImages ? this.optimizeImages(r, t.optimizeImages) : r;
|
300
300
|
}
|
301
301
|
return console.warn(
|
302
302
|
`The render method must receive an Object with a "content" field.
|
@@ -326,9 +326,9 @@ class v {
|
|
326
326
|
), "";
|
327
327
|
}
|
328
328
|
optimizeImages(e, t) {
|
329
|
-
let
|
330
|
-
typeof t != "boolean" && (typeof t.width == "number" && t.width > 0 && (
|
331
|
-
const c =
|
329
|
+
let r = 0, s = 0, o = "", n = "";
|
330
|
+
typeof t != "boolean" && (typeof t.width == "number" && t.width > 0 && (o += `width="${t.width}" `, r = t.width), typeof t.height == "number" && t.height > 0 && (o += `height="${t.height}" `, s = t.height), (t.loading === "lazy" || t.loading === "eager") && (o += `loading="${t.loading}" `), typeof t.class == "string" && t.class.length > 0 && (o += `class="${t.class}" `), t.filters && (typeof t.filters.blur == "number" && t.filters.blur >= 0 && t.filters.blur <= 100 && (n += `:blur(${t.filters.blur})`), typeof t.filters.brightness == "number" && t.filters.brightness >= -100 && t.filters.brightness <= 100 && (n += `:brightness(${t.filters.brightness})`), t.filters.fill && (t.filters.fill.match(/[0-9A-Fa-f]{6}/g) || t.filters.fill === "transparent") && (n += `:fill(${t.filters.fill})`), t.filters.format && ["webp", "png", "jpeg"].includes(t.filters.format) && (n += `:format(${t.filters.format})`), typeof t.filters.grayscale == "boolean" && t.filters.grayscale && (n += ":grayscale()"), typeof t.filters.quality == "number" && t.filters.quality >= 0 && t.filters.quality <= 100 && (n += `:quality(${t.filters.quality})`), t.filters.rotate && [90, 180, 270].includes(t.filters.rotate) && (n += `:rotate(${t.filters.rotate})`), n.length > 0 && (n = "/filters" + n))), o.length > 0 && (e = e.replace(/<img/g, `<img ${o.trim()}`));
|
331
|
+
const c = r > 0 || s > 0 || n.length > 0 ? `${r}x${s}${n}` : "";
|
332
332
|
return e = e.replace(
|
333
333
|
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g,
|
334
334
|
`a.storyblok.com/f/$1/$2.$3/m/${c}`
|
@@ -338,49 +338,49 @@ class v {
|
|
338
338
|
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g
|
339
339
|
);
|
340
340
|
if (d && d.length > 0) {
|
341
|
-
const
|
342
|
-
srcset: (l = t.srcset) == null ? void 0 : l.map((
|
343
|
-
if (typeof
|
344
|
-
return `//${d}/m/${
|
345
|
-
if (typeof
|
346
|
-
let
|
347
|
-
return typeof
|
341
|
+
const m = {
|
342
|
+
srcset: (l = t.srcset) == null ? void 0 : l.map((p) => {
|
343
|
+
if (typeof p == "number")
|
344
|
+
return `//${d}/m/${p}x0${n} ${p}w`;
|
345
|
+
if (typeof p == "object" && p.length === 2) {
|
346
|
+
let y = 0, O = 0;
|
347
|
+
return typeof p[0] == "number" && (y = p[0]), typeof p[1] == "number" && (O = p[1]), `//${d}/m/${y}x${O}${n} ${y}w`;
|
348
348
|
}
|
349
349
|
}).join(", "),
|
350
|
-
sizes: (u = t.sizes) == null ? void 0 : u.map((
|
350
|
+
sizes: (u = t.sizes) == null ? void 0 : u.map((p) => p).join(", ")
|
351
351
|
};
|
352
|
-
let
|
353
|
-
return
|
352
|
+
let _ = "";
|
353
|
+
return m.srcset && (_ += `srcset="${m.srcset}" `), m.sizes && (_ += `sizes="${m.sizes}" `), a.replace(/<img/g, `<img ${_.trim()}`);
|
354
354
|
}
|
355
355
|
return a;
|
356
356
|
})), e;
|
357
357
|
}
|
358
358
|
renderNode(e) {
|
359
359
|
const t = [];
|
360
|
-
e.marks && e.marks.forEach((
|
361
|
-
const
|
362
|
-
|
360
|
+
e.marks && e.marks.forEach((s) => {
|
361
|
+
const o = this.getMatchingMark(s);
|
362
|
+
o && o.tag !== "" && t.push(this.renderOpeningTag(o.tag));
|
363
363
|
});
|
364
|
-
const
|
365
|
-
return
|
366
|
-
t.push(this.renderNode(
|
367
|
-
}) : e.text ? t.push(ae(e.text)) :
|
368
|
-
const
|
369
|
-
|
364
|
+
const r = this.getMatchingNode(e);
|
365
|
+
return r && r.tag && t.push(this.renderOpeningTag(r.tag)), e.content ? e.content.forEach((s) => {
|
366
|
+
t.push(this.renderNode(s));
|
367
|
+
}) : e.text ? t.push(ae(e.text)) : r && r.singleTag ? t.push(this.renderTag(r.singleTag, " /")) : r && r.html ? t.push(r.html) : e.type === "emoji" && t.push(this.renderEmoji(e)), r && r.tag && t.push(this.renderClosingTag(r.tag)), e.marks && e.marks.slice(0).reverse().forEach((s) => {
|
368
|
+
const o = this.getMatchingMark(s);
|
369
|
+
o && o.tag !== "" && t.push(this.renderClosingTag(o.tag));
|
370
370
|
}), t.join("");
|
371
371
|
}
|
372
372
|
renderTag(e, t) {
|
373
|
-
return e.constructor === String ? `<${e}${t}>` : e.map((
|
374
|
-
if (
|
375
|
-
return `<${
|
373
|
+
return e.constructor === String ? `<${e}${t}>` : e.map((r) => {
|
374
|
+
if (r.constructor === String)
|
375
|
+
return `<${r}${t}>`;
|
376
376
|
{
|
377
|
-
let
|
378
|
-
if (
|
379
|
-
for (const
|
380
|
-
const
|
381
|
-
|
377
|
+
let s = `<${r.tag}`;
|
378
|
+
if (r.attrs)
|
379
|
+
for (const o in r.attrs) {
|
380
|
+
const n = r.attrs[o];
|
381
|
+
n !== null && (s += ` ${o}="${n}"`);
|
382
382
|
}
|
383
|
-
return `${
|
383
|
+
return `${s}${t}>`;
|
384
384
|
}
|
385
385
|
}).join("");
|
386
386
|
}
|
@@ -419,7 +419,7 @@ class v {
|
|
419
419
|
}
|
420
420
|
class le {
|
421
421
|
constructor(e) {
|
422
|
-
h(this, "baseURL"), h(this, "timeout"), h(this, "headers"), h(this, "responseInterceptor"), h(this, "fetch"), h(this, "ejectInterceptor"), h(this, "url"), h(this, "parameters"), this.baseURL = e.baseURL, this.headers = e.headers || new Headers(), this.timeout = e != null && e.timeout ? e.timeout * 1e3 : 0, this.responseInterceptor = e.responseInterceptor, this.fetch = (...t) => e.fetch ? e.fetch(...t) : fetch(...t), this.ejectInterceptor = !1, this.url = "", this.parameters = {};
|
422
|
+
h(this, "baseURL"), h(this, "timeout"), h(this, "headers"), h(this, "responseInterceptor"), h(this, "fetch"), h(this, "ejectInterceptor"), h(this, "url"), h(this, "parameters"), h(this, "fetchOptions"), this.baseURL = e.baseURL, this.headers = e.headers || new Headers(), this.timeout = e != null && e.timeout ? e.timeout * 1e3 : 0, this.responseInterceptor = e.responseInterceptor, this.fetch = (...t) => e.fetch ? e.fetch(...t) : fetch(...t), this.ejectInterceptor = !1, this.url = "", this.parameters = {}, this.fetchOptions = {};
|
423
423
|
}
|
424
424
|
/**
|
425
425
|
*
|
@@ -440,40 +440,43 @@ class le {
|
|
440
440
|
return this.url = e, this.parameters = t, this._methodHandler("delete");
|
441
441
|
}
|
442
442
|
async _responseHandler(e) {
|
443
|
-
const t = [],
|
443
|
+
const t = [], r = {
|
444
444
|
data: {},
|
445
445
|
headers: {},
|
446
446
|
status: 0,
|
447
447
|
statusText: ""
|
448
448
|
};
|
449
|
-
e.status !== 204 && await e.json().then((
|
450
|
-
|
449
|
+
e.status !== 204 && await e.json().then((s) => {
|
450
|
+
r.data = s;
|
451
451
|
});
|
452
|
-
for (const
|
453
|
-
t[
|
454
|
-
return
|
452
|
+
for (const s of e.headers.entries())
|
453
|
+
t[s[0]] = s[1];
|
454
|
+
return r.headers = { ...t }, r.status = e.status, r.statusText = e.statusText, r;
|
455
455
|
}
|
456
456
|
async _methodHandler(e) {
|
457
|
-
let t = `${this.baseURL}${this.url}`,
|
457
|
+
let t = `${this.baseURL}${this.url}`, r = null;
|
458
458
|
if (e === "get") {
|
459
459
|
const a = new b();
|
460
460
|
t = `${this.baseURL}${this.url}?${a.stringify(
|
461
461
|
this.parameters
|
462
462
|
)}`;
|
463
463
|
} else
|
464
|
-
|
465
|
-
const
|
464
|
+
r = JSON.stringify(this.parameters);
|
465
|
+
const s = new URL(t), o = new AbortController(), { signal: n } = o;
|
466
466
|
let c;
|
467
|
-
this.timeout && (c = setTimeout(() =>
|
467
|
+
this.timeout && (c = setTimeout(() => o.abort(), this.timeout));
|
468
468
|
try {
|
469
|
-
const a = await fetch(`${
|
469
|
+
const a = await fetch(`${s}`, {
|
470
470
|
method: e,
|
471
471
|
headers: this.headers,
|
472
|
-
body:
|
473
|
-
signal:
|
472
|
+
body: r,
|
473
|
+
signal: n,
|
474
|
+
...this.fetchOptions
|
474
475
|
});
|
475
476
|
this.timeout && clearTimeout(c);
|
476
|
-
const l = await this._responseHandler(
|
477
|
+
const l = await this._responseHandler(
|
478
|
+
a
|
479
|
+
);
|
477
480
|
return this.responseInterceptor && !this.ejectInterceptor ? this._statusHandler(this.responseInterceptor(l)) : this._statusHandler(l);
|
478
481
|
} catch (a) {
|
479
482
|
return {
|
@@ -481,31 +484,34 @@ class le {
|
|
481
484
|
};
|
482
485
|
}
|
483
486
|
}
|
487
|
+
setFetchOptions(e = {}) {
|
488
|
+
Object.keys(e).length > 0 && "method" in e && delete e.method, this.fetchOptions = { ...e };
|
489
|
+
}
|
484
490
|
eject() {
|
485
491
|
this.ejectInterceptor = !0;
|
486
492
|
}
|
487
493
|
_statusHandler(e) {
|
488
494
|
const t = /20[0-6]/g;
|
489
|
-
return new Promise((
|
495
|
+
return new Promise((r, s) => {
|
490
496
|
if (t.test(`${e.status}`))
|
491
|
-
return
|
492
|
-
const
|
497
|
+
return r(e);
|
498
|
+
const o = {
|
493
499
|
message: e.statusText,
|
494
500
|
status: e.status,
|
495
501
|
response: Array.isArray(e.data) ? e.data[0] : e.data.error || e.data.slug
|
496
502
|
};
|
497
|
-
|
503
|
+
s(o);
|
498
504
|
});
|
499
505
|
}
|
500
506
|
}
|
501
|
-
var ce = {
|
502
|
-
const
|
507
|
+
var ce = { GITHUB_TOKEN: "ghs_SY9hAvLQ8nuSfh6VtsLyQYlPrM7NAw095mxm", GITHUB_STATE: "/home/runner/work/_temp/_runner_file_commands/save_state_0680fa51-273e-4603-9ba8-00c19d52aa53", GIT_COMMITTER_NAME: "semantic-release-bot", STATS_TRP: "true", DEPLOYMENT_BASEPATH: "/opt/runner", DOTNET_NOLOGO: "1", USER: "runner", npm_config_user_agent: "npm/10.2.3 node/v18.19.0 linux x64 workspaces/false ci/github-actions", GIT_AUTHOR_EMAIL: "semantic-release-bot@martynus.net", CI: "true", RUNNER_ENVIRONMENT: "github-hosted", GITHUB_ENV: "/home/runner/work/_temp/_runner_file_commands/set_env_0680fa51-273e-4603-9ba8-00c19d52aa53", PIPX_HOME: "/opt/pipx", npm_node_execpath: "/opt/hostedtoolcache/node/18.19.0/x64/bin/node", GIT_ASKPASS: "echo", npm_package_resolved: "/home/runner/work/storyblok-js-client/storyblok-js-client", JAVA_HOME_8_X64: "/usr/lib/jvm/temurin-8-jdk-amd64", SHLVL: "1", npm_config_noproxy: "", HOME: "/home/runner", RUNNER_TEMP: "/home/runner/work/_temp", GITHUB_EVENT_PATH: "/home/runner/work/_temp/_github_workflow/event.json", npm_package_json: "/home/runner/work/storyblok-js-client/storyblok-js-client/package.json", JAVA_HOME_11_X64: "/usr/lib/jvm/temurin-11-jdk-amd64", PIPX_BIN_DIR: "/opt/pipx_bin", GITHUB_REPOSITORY_OWNER: "storyblok", GRADLE_HOME: "/usr/share/gradle-8.5", ANDROID_NDK_LATEST_HOME: "/usr/local/lib/android/sdk/ndk/26.1.10909125", JAVA_HOME_21_X64: "/usr/lib/jvm/temurin-21-jdk-amd64", STATS_RDCL: "true", GITHUB_RETENTION_DAYS: "90", GIT_AUTHOR_NAME: "semantic-release-bot", GITHUB_REPOSITORY_OWNER_ID: "13880908", POWERSHELL_DISTRIBUTION_CHANNEL: "GitHub-Actions-ubuntu22", AZURE_EXTENSION_DIR: "/opt/az/azcliextensions", GITHUB_HEAD_REF: "", npm_config_userconfig: "/tmp/f9cb367b92d80a35a8a750840547b152/.npmrc", npm_config_local_prefix: "/home/runner/work/storyblok-js-client/storyblok-js-client", npm_package_integrity: "null", SYSTEMD_EXEC_PID: "593", GITHUB_GRAPHQL_URL: "https://api.github.com/graphql", COLOR: "0", GOROOT_1_20_X64: "/opt/hostedtoolcache/go/1.20.12/x64", NVM_DIR: "/home/runner/.nvm", NPM_TOKEN: "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", DOTNET_SKIP_FIRST_TIME_EXPERIENCE: "1", GOROOT_1_21_X64: "/opt/hostedtoolcache/go/1.21.5/x64", JAVA_HOME_17_X64: "/usr/lib/jvm/temurin-17-jdk-amd64", ImageVersion: "20240107.1.0", RUNNER_OS: "Linux", GITHUB_API_URL: "https://api.github.com", SWIFT_PATH: "/usr/share/swift/usr/bin", RUNNER_USER: "runner", STATS_V3PS: "true", CHROMEWEBDRIVER: "/usr/local/share/chromedriver-linux64", JOURNAL_STREAM: "8:17159", GITHUB_WORKFLOW: "release", _: "/opt/hostedtoolcache/node/18.19.0/x64/bin/npx", npm_config_prefix: "/opt/hostedtoolcache/node/18.19.0/x64", npm_config_npm_version: "10.2.3", ACTIONS_RUNNER_ACTION_ARCHIVE_CACHE: "/opt/actionarchivecache", GITHUB_RUN_ID: "7493474777", npm_config_cache: "/home/runner/.npm", GITHUB_REF_TYPE: "branch", BOOTSTRAP_HASKELL_NONINTERACTIVE: "1", GITHUB_WORKFLOW_SHA: "b51aed5f473d8899277db2413a431150934793bc", GITHUB_BASE_REF: "", ImageOS: "ubuntu22", GITHUB_WORKFLOW_REF: "storyblok/storyblok-js-client/.github/workflows/release.yml@refs/heads/main", PERFLOG_LOCATION_SETTING: "RUNNER_PERFLOG", GITHUB_ACTION_REPOSITORY: "", npm_config_node_gyp: "/opt/hostedtoolcache/node/18.19.0/x64/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js", PATH: "/home/runner/work/storyblok-js-client/storyblok-js-client/node_modules/.bin:/home/runner/work/storyblok-js-client/node_modules/.bin:/home/runner/work/node_modules/.bin:/home/runner/node_modules/.bin:/home/node_modules/.bin:/node_modules/.bin:/opt/hostedtoolcache/node/18.19.0/x64/lib/node_modules/npm/node_modules/@npmcli/run-script/lib/node-gyp-bin:/home/runner/work/storyblok-js-client/storyblok-js-client/node_modules/.bin:/home/runner/work/storyblok-js-client/node_modules/.bin:/home/runner/work/node_modules/.bin:/home/runner/node_modules/.bin:/home/node_modules/.bin:/node_modules/.bin:/opt/hostedtoolcache/node/18.19.0/x64/lib/node_modules/npm/node_modules/@npmcli/run-script/lib/node-gyp-bin:/home/runner/work/storyblok-js-client/storyblok-js-client/node_modules/.bin:/home/runner/work/storyblok-js-client/node_modules/.bin:/home/runner/work/node_modules/.bin:/home/runner/node_modules/.bin:/home/node_modules/.bin:/node_modules/.bin:/opt/hostedtoolcache/node/18.19.0/x64/bin:/home/runner/.npm/_npx/cdf31b77322f1d44/node_modules/.bin:/home/runner/work/storyblok-js-client/storyblok-js-client/node_modules/.bin:/home/runner/work/storyblok-js-client/node_modules/.bin:/home/runner/work/node_modules/.bin:/home/runner/node_modules/.bin:/home/node_modules/.bin:/node_modules/.bin:/opt/hostedtoolcache/node/18.19.0/x64/lib/node_modules/npm/node_modules/@npmcli/run-script/lib/node-gyp-bin:/opt/hostedtoolcache/node/18.19.0/x64/bin:/snap/bin:/home/runner/.local/bin:/opt/pipx_bin:/home/runner/.cargo/bin:/home/runner/.config/composer/vendor/bin:/usr/local/.ghcup/bin:/home/runner/.dotnet/tools:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin", ANT_HOME: "/usr/share/ant", DOTNET_MULTILEVEL_LOOKUP: "0", RUNNER_TRACKING_ID: "github_bcef4b2d-d4af-4ca4-91ab-56a4509bf353", INVOCATION_ID: "6c9f22e5fd0d4fc98bc67fbac8a9476c", RUNNER_TOOL_CACHE: "/opt/hostedtoolcache", GOROOT_1_19_X64: "/opt/hostedtoolcache/go/1.19.13/x64", NODE: "/opt/hostedtoolcache/node/18.19.0/x64/bin/node", npm_package_name: "storyblok-js-client", GITHUB_ACTION: "__run_2", GITHUB_RUN_NUMBER: "16", GITHUB_TRIGGERING_ACTOR: "thiagosaife", RUNNER_ARCH: "X64", XDG_RUNTIME_DIR: "/run/user/1001", AGENT_TOOLSDIRECTORY: "/opt/hostedtoolcache", LANG: "C.UTF-8", VCPKG_INSTALLATION_ROOT: "/usr/local/share/vcpkg", CONDA: "/usr/share/miniconda", RUNNER_NAME: "GitHub Actions 3", XDG_CONFIG_HOME: "/home/runner/.config", STATS_VMD: "true", GITHUB_REF_NAME: "main", GITHUB_REPOSITORY: "storyblok/storyblok-js-client", npm_lifecycle_script: "node vite.build.mjs && tsc", STATS_UE: "true", ANDROID_NDK_ROOT: "/usr/local/lib/android/sdk/ndk/25.2.9519653", GITHUB_ACTION_REF: "", DEBIAN_FRONTEND: "noninteractive", GITHUB_REPOSITORY_ID: "116555786", GITHUB_ACTIONS: "true", npm_package_version: "6.5.0", npm_lifecycle_event: "build", GIT_TERMINAL_PROMPT: "0", GITHUB_REF_PROTECTED: "true", GITHUB_WORKSPACE: "/home/runner/work/storyblok-js-client/storyblok-js-client", ACCEPT_EULA: "Y", GITHUB_JOB: "release", RUNNER_PERFLOG: "/home/runner/perflog", GITHUB_SHA: "b51aed5f473d8899277db2413a431150934793bc", GITHUB_RUN_ATTEMPT: "3", GITHUB_REF: "refs/heads/main", GITHUB_ACTOR: "thiagosaife", ANDROID_SDK_ROOT: "/usr/local/lib/android/sdk", LEIN_HOME: "/usr/local/lib/lein", npm_config_globalconfig: "/opt/hostedtoolcache/node/18.19.0/x64/etc/npmrc", npm_config_init_module: "/home/runner/.npm-init.js", GIT_COMMITTER_EMAIL: "semantic-release-bot@martynus.net", GITHUB_PATH: "/home/runner/work/_temp/_runner_file_commands/add_path_0680fa51-273e-4603-9ba8-00c19d52aa53", JAVA_HOME: "/usr/lib/jvm/temurin-11-jdk-amd64", PWD: "/home/runner/work/storyblok-js-client/storyblok-js-client", GITHUB_ACTOR_ID: "10601682", RUNNER_WORKSPACE: "/home/runner/work/storyblok-js-client", npm_execpath: "/opt/hostedtoolcache/node/18.19.0/x64/lib/node_modules/npm/bin/npm-cli.js", HOMEBREW_CLEANUP_PERIODIC_FULL_DAYS: "3650", STATS_TIS: "mining", GITHUB_EVENT_NAME: "push", HOMEBREW_NO_AUTO_UPDATE: "1", ANDROID_HOME: "/usr/local/lib/android/sdk", GITHUB_SERVER_URL: "https://github.com", GECKOWEBDRIVER: "/usr/local/share/gecko_driver", LEIN_JAR: "/usr/local/lib/lein/self-installs/leiningen-2.10.0-standalone.jar", GHCUP_INSTALL_BASE_PREFIX: "/usr/local", GITHUB_OUTPUT: "/home/runner/work/_temp/_runner_file_commands/set_output_0680fa51-273e-4603-9ba8-00c19d52aa53", npm_config_global_prefix: "/opt/hostedtoolcache/node/18.19.0/x64", EDGEWEBDRIVER: "/usr/local/share/edge_driver", STATS_EXT: "true", npm_command: "run-script", ANDROID_NDK: "/usr/local/lib/android/sdk/ndk/25.2.9519653", SGX_AESM_ADDR: "1", CHROME_BIN: "/usr/bin/google-chrome", SELENIUM_JAR_PATH: "/usr/share/java/selenium-server.jar", STATS_EXTP: "https://provjobdsettingscdn.blob.core.windows.net/settings/provjobdsettings-0.5.154/provjobd.data", ANDROID_NDK_HOME: "/usr/local/lib/android/sdk/ndk/25.2.9519653", GITHUB_STEP_SUMMARY: "/home/runner/work/_temp/_runner_file_commands/step_summary_0680fa51-273e-4603-9ba8-00c19d52aa53", INIT_CWD: "/home/runner/work/storyblok-js-client/storyblok-js-client", EDITOR: "vi", NODE_ENV: "production" };
|
508
|
+
const A = "SB-Agent", R = {
|
503
509
|
defaultAgentName: "SB-JS-CLIENT",
|
504
510
|
defaultAgentVersion: "SB-Agent-Version",
|
505
511
|
packageVersion: ce.npm_package_version
|
506
512
|
};
|
507
|
-
let
|
508
|
-
const
|
513
|
+
let f = {};
|
514
|
+
const g = {};
|
509
515
|
class he {
|
510
516
|
/**
|
511
517
|
*
|
@@ -514,83 +520,83 @@ class he {
|
|
514
520
|
*/
|
515
521
|
constructor(e, t) {
|
516
522
|
h(this, "client"), h(this, "maxRetries"), h(this, "throttle"), h(this, "accessToken"), h(this, "cache"), h(this, "helpers"), h(this, "resolveCounter"), h(this, "relations"), h(this, "links"), h(this, "richTextResolver"), h(this, "resolveNestedRelations"), h(this, "stringifiedStoriesCache");
|
517
|
-
let
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
k.defaultAgentVersion,
|
528
|
-
k.packageVersion
|
523
|
+
let r = e.endpoint || t;
|
524
|
+
const s = new b().getRegionURL, o = e.https === !1 ? "http" : "https";
|
525
|
+
e.oauthToken ? r = `${o}://${s(e.region)}/v1` : r = `${o}://${s(e.region)}/v2`;
|
526
|
+
const n = new Headers();
|
527
|
+
if (n.set("Content-Type", "application/json"), n.set("Accept", "application/json"), e.headers)
|
528
|
+
for (const a in e.headers)
|
529
|
+
n.set(a, e.headers[a]);
|
530
|
+
n.has(A) || (n.set(A, R.defaultAgentName), n.set(
|
531
|
+
R.defaultAgentVersion,
|
532
|
+
R.packageVersion
|
529
533
|
));
|
530
|
-
let
|
531
|
-
e.oauthToken && (
|
532
|
-
baseURL:
|
534
|
+
let c = 5;
|
535
|
+
e.oauthToken && (n.set("Authorization", e.oauthToken), c = 3), e.rateLimit && (c = e.rateLimit), e.richTextSchema ? this.richTextResolver = new T(e.richTextSchema) : this.richTextResolver = new T(), e.componentResolver && this.setComponentResolver(e.componentResolver), this.maxRetries = e.maxRetries || 5, this.throttle = H(this.throttledRequest, c, 1e3), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.helpers = new b(), this.resolveCounter = 0, this.resolveNestedRelations = e.resolveNestedRelations || !0, this.stringifiedStoriesCache = {}, this.client = new le({
|
536
|
+
baseURL: r,
|
533
537
|
timeout: e.timeout || 0,
|
534
|
-
headers:
|
538
|
+
headers: n,
|
535
539
|
responseInterceptor: e.responseInterceptor,
|
536
540
|
fetch: e.fetch
|
537
541
|
});
|
538
542
|
}
|
539
543
|
setComponentResolver(e) {
|
540
544
|
this.richTextResolver.addNode("blok", (t) => {
|
541
|
-
let
|
542
|
-
return t.attrs.body && t.attrs.body.forEach((
|
543
|
-
|
545
|
+
let r = "";
|
546
|
+
return t.attrs.body && t.attrs.body.forEach((s) => {
|
547
|
+
r += e(s.component, s);
|
544
548
|
}), {
|
545
|
-
html:
|
549
|
+
html: r
|
546
550
|
};
|
547
551
|
});
|
548
552
|
}
|
549
553
|
parseParams(e) {
|
550
|
-
return e.token || (e.token = this.getToken()), e.cv || (e.cv =
|
554
|
+
return e.token || (e.token = this.getToken()), e.cv || (e.cv = g[e.token]), Array.isArray(e.resolve_relations) && (e.resolve_relations = e.resolve_relations.join(",")), e;
|
551
555
|
}
|
552
556
|
factoryParamOptions(e, t) {
|
553
557
|
return this.helpers.isCDNUrl(e) ? this.parseParams(t) : t;
|
554
558
|
}
|
555
|
-
makeRequest(e, t,
|
556
|
-
const
|
559
|
+
makeRequest(e, t, r, s) {
|
560
|
+
const o = this.factoryParamOptions(
|
557
561
|
e,
|
558
|
-
this.helpers.getOptionsPage(t,
|
562
|
+
this.helpers.getOptionsPage(t, r, s)
|
559
563
|
);
|
560
|
-
return this.cacheResponse(e,
|
564
|
+
return this.cacheResponse(e, o);
|
561
565
|
}
|
562
|
-
get(e, t) {
|
566
|
+
get(e, t, r) {
|
563
567
|
t || (t = {});
|
564
|
-
const s = `/${e}`,
|
565
|
-
return this.cacheResponse(s,
|
566
|
-
}
|
567
|
-
async getAll(e, t, s) {
|
568
|
-
const
|
569
|
-
|
570
|
-
|
568
|
+
const s = `/${e}`, o = this.factoryParamOptions(s, t);
|
569
|
+
return this.client.setFetchOptions(r), this.cacheResponse(s, o);
|
570
|
+
}
|
571
|
+
async getAll(e, t, r, s) {
|
572
|
+
const o = (t == null ? void 0 : t.per_page) || 25, n = `/${e}`, c = n.split("/"), a = r || c[c.length - 1], l = 1, u = await this.makeRequest(n, t, o, l), d = u.total ? Math.ceil(u.total / o) : 1;
|
573
|
+
this.client.setFetchOptions(s);
|
574
|
+
const m = await this.helpers.asyncMap(
|
575
|
+
this.helpers.range(l, d),
|
576
|
+
(_) => this.makeRequest(n, t, o, _ + 1)
|
571
577
|
);
|
572
578
|
return this.helpers.flatMap(
|
573
|
-
[
|
574
|
-
(
|
579
|
+
[u, ...m],
|
580
|
+
(_) => Object.values(_.data[a])
|
575
581
|
);
|
576
582
|
}
|
577
|
-
post(e, t) {
|
583
|
+
post(e, t, r) {
|
578
584
|
const s = `/${e}`;
|
579
|
-
return Promise.resolve(this.throttle("post", s, t));
|
585
|
+
return this.client.setFetchOptions(r), Promise.resolve(this.throttle("post", s, t));
|
580
586
|
}
|
581
|
-
put(e, t) {
|
587
|
+
put(e, t, r) {
|
582
588
|
const s = `/${e}`;
|
583
|
-
return Promise.resolve(this.throttle("put", s, t));
|
589
|
+
return this.client.setFetchOptions(r), Promise.resolve(this.throttle("put", s, t));
|
584
590
|
}
|
585
|
-
delete(e, t) {
|
591
|
+
delete(e, t, r) {
|
586
592
|
const s = `/${e}`;
|
587
|
-
return Promise.resolve(this.throttle("delete", s, t));
|
593
|
+
return this.client.setFetchOptions(r), Promise.resolve(this.throttle("delete", s, t));
|
588
594
|
}
|
589
|
-
getStories(e) {
|
590
|
-
return this.get("cdn/stories", e);
|
595
|
+
getStories(e, t) {
|
596
|
+
return this.client.setFetchOptions(t), this.get("cdn/stories", e);
|
591
597
|
}
|
592
|
-
getStory(e, t) {
|
593
|
-
return this.get(`cdn/stories/${e}`, t);
|
598
|
+
getStory(e, t, r) {
|
599
|
+
return this.client.setFetchOptions(r), this.get(`cdn/stories/${e}`, t);
|
594
600
|
}
|
595
601
|
getToken() {
|
596
602
|
return this.accessToken;
|
@@ -601,9 +607,9 @@ class he {
|
|
601
607
|
_cleanCopy(e) {
|
602
608
|
return JSON.parse(JSON.stringify(e));
|
603
609
|
}
|
604
|
-
_insertLinks(e, t,
|
605
|
-
const
|
606
|
-
|
610
|
+
_insertLinks(e, t, r) {
|
611
|
+
const s = e[t];
|
612
|
+
s && s.fieldtype == "multilink" && s.linktype == "story" && typeof s.id == "string" && this.links[r][s.id] ? s.story = this._cleanCopy(this.links[r][s.id]) : s && s.linktype === "story" && typeof s.uuid == "string" && this.links[r][s.uuid] && (s.story = this._cleanCopy(this.links[r][s.uuid]));
|
607
613
|
}
|
608
614
|
/**
|
609
615
|
*
|
@@ -616,115 +622,126 @@ class he {
|
|
616
622
|
this.relations[e][t]
|
617
623
|
)), JSON.parse(this.stringifiedStoriesCache[t])) : t;
|
618
624
|
}
|
619
|
-
_insertRelations(e, t,
|
620
|
-
|
621
|
-
}
|
622
|
-
iterateTree(e, t,
|
623
|
-
const
|
624
|
-
if (
|
625
|
-
if (
|
626
|
-
for (let
|
627
|
-
|
628
|
-
else if (
|
629
|
-
if (
|
625
|
+
_insertRelations(e, t, r, s) {
|
626
|
+
r.indexOf(`${e.component}.${t}`) > -1 && (typeof e[t] == "string" ? e[t] = this.getStoryReference(s, e[t]) : Array.isArray(e[t]) && (e[t] = e[t].map((o) => this.getStoryReference(s, o)).filter(Boolean)));
|
627
|
+
}
|
628
|
+
iterateTree(e, t, r) {
|
629
|
+
const s = (o) => {
|
630
|
+
if (o != null) {
|
631
|
+
if (o.constructor === Array)
|
632
|
+
for (let n = 0; n < o.length; n++)
|
633
|
+
s(o[n]);
|
634
|
+
else if (o.constructor === Object) {
|
635
|
+
if (o._stopResolving)
|
630
636
|
return;
|
631
|
-
for (const
|
632
|
-
(
|
633
|
-
i,
|
637
|
+
for (const n in o)
|
638
|
+
(o.component && o._uid || o.type === "link") && (this._insertRelations(
|
634
639
|
o,
|
640
|
+
n,
|
635
641
|
t,
|
636
|
-
|
642
|
+
r
|
637
643
|
), this._insertLinks(
|
638
|
-
i,
|
639
644
|
o,
|
640
|
-
|
641
|
-
|
645
|
+
n,
|
646
|
+
r
|
647
|
+
)), s(o[n]);
|
642
648
|
}
|
643
649
|
}
|
644
650
|
};
|
645
|
-
|
651
|
+
s(e.content);
|
646
652
|
}
|
647
|
-
async resolveLinks(e, t,
|
648
|
-
let
|
653
|
+
async resolveLinks(e, t, r) {
|
654
|
+
let s = [];
|
649
655
|
if (e.link_uuids) {
|
650
|
-
const
|
651
|
-
for (let a = 0; a <
|
652
|
-
const l = Math.min(
|
653
|
-
|
656
|
+
const o = e.link_uuids.length, n = [], c = 50;
|
657
|
+
for (let a = 0; a < o; a += c) {
|
658
|
+
const l = Math.min(o, a + c);
|
659
|
+
n.push(e.link_uuids.slice(a, l));
|
654
660
|
}
|
655
|
-
for (let a = 0; a <
|
661
|
+
for (let a = 0; a < n.length; a++)
|
656
662
|
(await this.getStories({
|
657
663
|
per_page: c,
|
658
664
|
language: t.language,
|
659
665
|
version: t.version,
|
660
|
-
by_uuids:
|
666
|
+
by_uuids: n[a].join(",")
|
661
667
|
})).data.stories.forEach(
|
662
668
|
(l) => {
|
663
|
-
|
669
|
+
s.push(l);
|
664
670
|
}
|
665
671
|
);
|
666
672
|
} else
|
667
|
-
|
668
|
-
|
669
|
-
this.links[
|
670
|
-
...
|
673
|
+
s = e.links;
|
674
|
+
s.forEach((o) => {
|
675
|
+
this.links[r][o.uuid] = {
|
676
|
+
...o,
|
671
677
|
_stopResolving: !0
|
672
678
|
};
|
673
679
|
});
|
674
680
|
}
|
675
|
-
async resolveRelations(e, t,
|
676
|
-
let
|
681
|
+
async resolveRelations(e, t, r) {
|
682
|
+
let s = [];
|
677
683
|
if (e.rel_uuids) {
|
678
|
-
const
|
679
|
-
for (let a = 0; a <
|
680
|
-
const l = Math.min(
|
681
|
-
|
684
|
+
const o = e.rel_uuids.length, n = [], c = 50;
|
685
|
+
for (let a = 0; a < o; a += c) {
|
686
|
+
const l = Math.min(o, a + c);
|
687
|
+
n.push(e.rel_uuids.slice(a, l));
|
682
688
|
}
|
683
|
-
for (let a = 0; a <
|
689
|
+
for (let a = 0; a < n.length; a++)
|
684
690
|
(await this.getStories({
|
685
691
|
per_page: c,
|
686
692
|
language: t.language,
|
687
693
|
version: t.version,
|
688
|
-
by_uuids:
|
694
|
+
by_uuids: n[a].join(","),
|
689
695
|
excluding_fields: t.excluding_fields
|
690
696
|
})).data.stories.forEach((l) => {
|
691
|
-
|
697
|
+
s.push(l);
|
692
698
|
});
|
693
699
|
} else
|
694
|
-
|
695
|
-
|
696
|
-
this.relations[
|
697
|
-
...
|
700
|
+
s = e.rels;
|
701
|
+
s && s.length > 0 && s.forEach((o) => {
|
702
|
+
this.relations[r][o.uuid] = {
|
703
|
+
...o,
|
698
704
|
_stopResolving: !0
|
699
705
|
};
|
700
706
|
});
|
701
707
|
}
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
708
|
+
/**
|
709
|
+
*
|
710
|
+
* @param responseData
|
711
|
+
* @param params
|
712
|
+
* @param resolveId
|
713
|
+
* @description Resolves the relations and links of the stories
|
714
|
+
* @returns Promise<void>
|
715
|
+
*
|
716
|
+
*/
|
717
|
+
async resolveStories(e, t, r) {
|
718
|
+
var s, o;
|
719
|
+
let n = [];
|
720
|
+
if (this.links[r] = {}, this.relations[r] = {}, typeof t.resolve_relations < "u" && t.resolve_relations.length > 0 && (typeof t.resolve_relations == "string" && (n = t.resolve_relations.split(",")), await this.resolveRelations(e, t, r)), t.resolve_links && ["1", "story", "url", "link"].indexOf(t.resolve_links) > -1 && ((s = e.links) != null && s.length || (o = e.link_uuids) != null && o.length) && await this.resolveLinks(e, t, r), this.resolveNestedRelations)
|
721
|
+
for (const c in this.relations[r])
|
707
722
|
this.iterateTree(
|
708
|
-
this.relations[
|
709
|
-
|
710
|
-
|
723
|
+
this.relations[r][c],
|
724
|
+
n,
|
725
|
+
r
|
711
726
|
);
|
712
|
-
e.story ? this.iterateTree(e.story,
|
713
|
-
this.iterateTree(c,
|
714
|
-
}), this.stringifiedStoriesCache = {}, delete this.links[
|
727
|
+
e.story ? this.iterateTree(e.story, n, r) : e.stories.forEach((c) => {
|
728
|
+
this.iterateTree(c, n, r);
|
729
|
+
}), this.stringifiedStoriesCache = {}, delete this.links[r], delete this.relations[r];
|
715
730
|
}
|
716
|
-
async cacheResponse(e, t,
|
717
|
-
(typeof
|
718
|
-
const
|
731
|
+
async cacheResponse(e, t, r) {
|
732
|
+
(typeof r > "u" || !r) && (r = 0);
|
733
|
+
const s = this.helpers.stringify({ url: e, params: t }), o = this.cacheProvider();
|
719
734
|
if (this.cache.clear === "auto" && t.version === "draft" && await this.flushCache(), t.version === "published" && e != "/cdn/spaces/me") {
|
720
|
-
const
|
721
|
-
if (
|
722
|
-
return Promise.resolve(
|
735
|
+
const n = await o.get(s);
|
736
|
+
if (n)
|
737
|
+
return Promise.resolve(n);
|
723
738
|
}
|
724
|
-
return new Promise(async (
|
739
|
+
return new Promise(async (n, c) => {
|
725
740
|
var a;
|
726
741
|
try {
|
727
742
|
const l = await this.throttle("get", e, t);
|
743
|
+
if (l.status === 429 && (r = r ? r + 1 : 0, r < this.maxRetries))
|
744
|
+
return console.log(`Hit rate limit. Retrying in ${r} seconds.`), await this.helpers.delay(1e3 * r), this.cacheResponse(e, t, r).then(n).catch(c);
|
728
745
|
if (l.status !== 200)
|
729
746
|
return c(l);
|
730
747
|
let u = { data: l.data, headers: l.headers };
|
@@ -735,38 +752,39 @@ class he {
|
|
735
752
|
const d = this.resolveCounter = ++this.resolveCounter % 1e3;
|
736
753
|
await this.resolveStories(u.data, t, `${d}`);
|
737
754
|
}
|
738
|
-
return t.version === "published" && e != "/cdn/spaces/me" && await
|
755
|
+
return t.version === "published" && e != "/cdn/spaces/me" && await o.set(s, u), u.data.cv && t.token && (t.version === "draft" && g[t.token] != u.data.cv && await this.flushCache(), g[t.token] = t.cv ? t.cv : u.data.cv), n(u);
|
739
756
|
} catch (l) {
|
740
|
-
if (l.response && l.response.status === 429 && (s = s ? s + 1 : 0, s < this.maxRetries))
|
741
|
-
return console.log(`Hit rate limit. Retrying in ${s} seconds.`), await this.helpers.delay(1e3 * s), this.cacheResponse(e, t, s).then(o).catch(c);
|
742
757
|
c(l);
|
743
758
|
}
|
744
759
|
});
|
745
760
|
}
|
746
|
-
throttledRequest(e, t,
|
747
|
-
return this.client[e](t,
|
761
|
+
throttledRequest(e, t, r) {
|
762
|
+
return this.client[e](t, r);
|
748
763
|
}
|
749
764
|
cacheVersions() {
|
750
|
-
return
|
765
|
+
return g;
|
751
766
|
}
|
752
767
|
cacheVersion() {
|
753
|
-
return
|
768
|
+
return g[this.accessToken];
|
769
|
+
}
|
770
|
+
setCacheVersion(e) {
|
771
|
+
this.accessToken && (g[this.accessToken] = e);
|
754
772
|
}
|
755
773
|
cacheProvider() {
|
756
774
|
switch (this.cache.type) {
|
757
775
|
case "memory":
|
758
776
|
return {
|
759
777
|
get(e) {
|
760
|
-
return Promise.resolve(
|
778
|
+
return Promise.resolve(f[e]);
|
761
779
|
},
|
762
780
|
getAll() {
|
763
|
-
return Promise.resolve(
|
781
|
+
return Promise.resolve(f);
|
764
782
|
},
|
765
783
|
set(e, t) {
|
766
|
-
return
|
784
|
+
return f[e] = t, Promise.resolve(void 0);
|
767
785
|
},
|
768
786
|
flush() {
|
769
|
-
return
|
787
|
+
return f = {}, Promise.resolve(void 0);
|
770
788
|
}
|
771
789
|
};
|
772
790
|
case "custom":
|
@@ -793,8 +811,8 @@ class he {
|
|
793
811
|
return await this.cacheProvider().flush(), this;
|
794
812
|
}
|
795
813
|
}
|
796
|
-
const de = (
|
797
|
-
const { apiOptions: e } =
|
814
|
+
const de = (i = {}) => {
|
815
|
+
const { apiOptions: e } = i;
|
798
816
|
if (!e.accessToken) {
|
799
817
|
console.error(
|
800
818
|
"You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication"
|
@@ -802,12 +820,12 @@ const de = (n = {}) => {
|
|
802
820
|
return;
|
803
821
|
}
|
804
822
|
return { storyblokApi: new he(e) };
|
805
|
-
}, pe = (
|
806
|
-
if (typeof
|
823
|
+
}, pe = (i) => {
|
824
|
+
if (typeof i != "object" || typeof i._editable > "u")
|
807
825
|
return {};
|
808
826
|
try {
|
809
827
|
const e = JSON.parse(
|
810
|
-
|
828
|
+
i._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, "")
|
811
829
|
);
|
812
830
|
return e ? {
|
813
831
|
"data-blok-c": JSON.stringify(e),
|
@@ -817,69 +835,69 @@ const de = (n = {}) => {
|
|
817
835
|
return {};
|
818
836
|
}
|
819
837
|
};
|
820
|
-
let
|
821
|
-
const
|
838
|
+
let k, E = "https://app.storyblok.com/f/storyblok-v2-latest.js";
|
839
|
+
const me = (i, e, t = {}) => {
|
822
840
|
var c;
|
823
|
-
const
|
841
|
+
const s = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", n = +new URL((c = window.location) == null ? void 0 : c.href).searchParams.get(
|
824
842
|
"_storyblok"
|
825
|
-
) ===
|
826
|
-
if (!(!
|
827
|
-
if (!
|
843
|
+
) === i;
|
844
|
+
if (!(!s || !n)) {
|
845
|
+
if (!i) {
|
828
846
|
console.warn("Story ID is not defined. Please provide a valid ID.");
|
829
847
|
return;
|
830
848
|
}
|
831
849
|
window.storyblokRegisterEvent(() => {
|
832
850
|
new window.StoryblokBridge(t).on(["input", "published", "change"], (l) => {
|
833
|
-
l.action === "input" && l.story.id ===
|
851
|
+
l.action === "input" && l.story.id === i ? e(l.story) : (l.action === "change" || l.action === "published") && l.storyId === i && window.location.reload();
|
834
852
|
});
|
835
853
|
});
|
836
854
|
}
|
837
|
-
},
|
838
|
-
var d,
|
855
|
+
}, _e = (i = {}) => {
|
856
|
+
var d, m;
|
839
857
|
const {
|
840
858
|
bridge: e,
|
841
859
|
accessToken: t,
|
842
|
-
use:
|
843
|
-
apiOptions:
|
844
|
-
richText:
|
845
|
-
bridgeUrl:
|
846
|
-
} =
|
847
|
-
|
848
|
-
const c = { bridge: e, apiOptions:
|
860
|
+
use: r = [],
|
861
|
+
apiOptions: s = {},
|
862
|
+
richText: o = {},
|
863
|
+
bridgeUrl: n
|
864
|
+
} = i;
|
865
|
+
s.accessToken = s.accessToken || t;
|
866
|
+
const c = { bridge: e, apiOptions: s };
|
849
867
|
let a = {};
|
850
|
-
|
851
|
-
a = { ...a, ...
|
852
|
-
}),
|
853
|
-
const u = !(typeof window > "u") && ((
|
854
|
-
return e !== !1 && u &&
|
855
|
-
},
|
856
|
-
|
857
|
-
let
|
858
|
-
return t.attrs.body.forEach((
|
859
|
-
|
868
|
+
r.forEach((_) => {
|
869
|
+
a = { ...a, ..._(c) };
|
870
|
+
}), n && (E = n);
|
871
|
+
const u = !(typeof window > "u") && ((m = (d = window.location) == null ? void 0 : d.search) == null ? void 0 : m.includes("_storyblok_tk"));
|
872
|
+
return e !== !1 && u && w(E), k = new T(o.schema), o.resolver && S(k, o.resolver), a;
|
873
|
+
}, S = (i, e) => {
|
874
|
+
i.addNode("blok", (t) => {
|
875
|
+
let r = "";
|
876
|
+
return t.attrs.body.forEach((s) => {
|
877
|
+
r += e(s.component, s);
|
860
878
|
}), {
|
861
|
-
html:
|
879
|
+
html: r
|
862
880
|
};
|
863
881
|
});
|
864
|
-
}, ue = (
|
865
|
-
let
|
866
|
-
if (!
|
882
|
+
}, ue = (i) => !i || !(i != null && i.content.some((e) => e.content || e.type === "blok" || e.type === "horizontal_rule")), ge = (i, e, t) => {
|
883
|
+
let r = t || k;
|
884
|
+
if (!r) {
|
867
885
|
console.error(
|
868
886
|
"Please initialize the Storyblok SDK before calling the renderRichText function"
|
869
887
|
);
|
870
888
|
return;
|
871
889
|
}
|
872
|
-
return ue(
|
873
|
-
},
|
890
|
+
return ue(i) ? "" : (e && (r = new T(e.schema), e.resolver && S(r, e.resolver)), r.render(i));
|
891
|
+
}, fe = () => w(E);
|
874
892
|
export {
|
875
|
-
|
876
|
-
|
893
|
+
T as RichTextResolver,
|
894
|
+
ie as RichTextSchema,
|
877
895
|
de as apiPlugin,
|
878
896
|
ue as isRichTextEmpty,
|
879
|
-
|
880
|
-
|
881
|
-
|
897
|
+
fe as loadStoryblokBridge,
|
898
|
+
me as registerStoryblokBridge,
|
899
|
+
ge as renderRichText,
|
882
900
|
pe as storyblokEditable,
|
883
|
-
|
884
|
-
|
901
|
+
_e as storyblokInit,
|
902
|
+
me as useStoryblokBridge
|
885
903
|
};
|