@contentful/content-source-maps
Advanced tools
Comparing version 0.11.6 to 0.11.7
@@ -1,2 +0,2 @@ | ||
import type { SourceMapMetadata } from './types.js'; | ||
import { SourceMapMetadata } from './types.js'; | ||
export declare function combine(text: string, metadata: SourceMapMetadata): string; | ||
@@ -3,0 +3,0 @@ export declare function encode(metadata: SourceMapMetadata): string; |
@@ -1,2 +0,2 @@ | ||
import type { CreateSourceMapParams } from '../types.js'; | ||
import { CreateSourceMapParams } from '../types.js'; | ||
export declare const encodeGraphQLResponse: <TResponse extends { | ||
@@ -3,0 +3,0 @@ data: any; |
@@ -1,17 +0,17 @@ | ||
var R = { 0: 8203, 1: 8204, 2: 8205, 3: 8290, 4: 8291, 5: 8288, 6: 65279, 7: 8289, 8: 119155, 9: 119156, a: 119157, b: 119158, c: 119159, d: 119160, e: 119161, f: 119162 }, b = { 0: 8203, 1: 8204, 2: 8205, 3: 65279 }, V = new Array(4).fill(String.fromCodePoint(b[0])).join(""), J = "\0"; | ||
function _(e) { | ||
let t = JSON.stringify(e); | ||
return `${V}${Array.from(t).map((o) => { | ||
let n = o.charCodeAt(0); | ||
if (n > 255) throw new Error(`Only ASCII edit info can be encoded. Error attempting to encode ${t} on character ${o} (${n})`); | ||
return Array.from(n.toString(4).padStart(4, "0")).map((r) => String.fromCodePoint(b[r])).join(""); | ||
var W = { 0: 8203, 1: 8204, 2: 8205, 3: 8290, 4: 8291, 5: 8288, 6: 65279, 7: 8289, 8: 119155, 9: 119156, a: 119157, b: 119158, c: 119159, d: 119160, e: 119161, f: 119162 }, L = { 0: 8203, 1: 8204, 2: 8205, 3: 65279 }, j = new Array(4).fill(String.fromCodePoint(L[0])).join(""), V = "\0"; | ||
function U(t) { | ||
let n = JSON.stringify(t); | ||
return `${j}${Array.from(n).map((o) => { | ||
let e = o.charCodeAt(0); | ||
if (e > 255) throw new Error(`Only ASCII edit info can be encoded. Error attempting to encode ${n} on character ${o} (${e})`); | ||
return Array.from(e.toString(4).padStart(4, "0")).map((r) => String.fromCodePoint(L[r])).join(""); | ||
}).join("")}`; | ||
} | ||
function D(e) { | ||
return !Number.isNaN(Number(e)) || /[a-z]/i.test(e) && !/\d+(?:[-:\/]\d+){2}(?:T\d+(?:[-:\/]\d+){1,2}(\.\d+)?Z?)?/.test(e) ? !1 : !!Date.parse(e); | ||
function Z(t) { | ||
return !Number.isNaN(Number(t)) || /[a-z]/i.test(t) && !/\d+(?:[-:\/]\d+){2}(?:T\d+(?:[-:\/]\d+){1,2}(\.\d+)?Z?)?/.test(t) ? !1 : !!Date.parse(t); | ||
} | ||
function Q(e) { | ||
function q(t) { | ||
try { | ||
new URL(e, e.startsWith("/") ? "https://acme.com" : void 0); | ||
} catch (t) { | ||
new URL(t, t.startsWith("/") ? "https://acme.com" : void 0); | ||
} catch (n) { | ||
return !1; | ||
@@ -21,44 +21,44 @@ } | ||
} | ||
function z(e, t, o = "auto") { | ||
return o === !0 || o === "auto" && (D(e) || Q(e)) ? e : `${e}${_(t)}`; | ||
function G(t, n, o = "auto") { | ||
return o === !0 || o === "auto" && (Z(t) || q(t)) ? t : `${t}${U(n)}`; | ||
} | ||
var Z = Object.fromEntries(Object.entries(b).map((e) => e.reverse())), k = Object.fromEntries(Object.entries(R).map((e) => e.reverse())), G = `${Object.values(R).map((e) => `\\u{${e.toString(16)}}`).join("")}`, O = new RegExp(`[${G}]{4,}`, "gu"); | ||
function H(e) { | ||
let t = e.match(O); | ||
if (t) return K(t[0], !0)[0]; | ||
var H = Object.fromEntries(Object.entries(L).map((t) => t.reverse())), k = Object.fromEntries(Object.entries(W).map((t) => t.reverse())), K = `${Object.values(W).map((t) => `\\u{${t.toString(16)}}`).join("")}`, O = new RegExp(`[${K}]{4,}`, "gu"); | ||
function X(t) { | ||
let n = t.match(O); | ||
if (n) return Y(n[0], !0)[0]; | ||
} | ||
function K(e, t = !1) { | ||
let o = Array.from(e); | ||
function Y(t, n = !1) { | ||
let o = Array.from(t); | ||
if (o.length % 2 === 0) { | ||
if (o.length % 4 || !e.startsWith(V)) return X(o, t); | ||
if (o.length % 4 || !t.startsWith(j)) return ee(o, n); | ||
} else throw new Error("Encoded data has invalid length"); | ||
let n = []; | ||
let e = []; | ||
for (let r = o.length * 0.25; r--; ) { | ||
let s = o.slice(r * 4, r * 4 + 4).map((i) => Z[i.codePointAt(0)]).join(""); | ||
n.unshift(String.fromCharCode(parseInt(s, 4))); | ||
let s = o.slice(r * 4, r * 4 + 4).map((c) => H[c.codePointAt(0)]).join(""); | ||
e.unshift(String.fromCharCode(parseInt(s, 4))); | ||
} | ||
if (t) { | ||
n.shift(); | ||
let r = n.indexOf(J); | ||
return r === -1 && (r = n.length), [JSON.parse(n.slice(0, r).join(""))]; | ||
if (n) { | ||
e.shift(); | ||
let r = e.indexOf(V); | ||
return r === -1 && (r = e.length), [JSON.parse(e.slice(0, r).join(""))]; | ||
} | ||
return n.join("").split(J).filter(Boolean).map((r) => JSON.parse(r)); | ||
return e.join("").split(V).filter(Boolean).map((r) => JSON.parse(r)); | ||
} | ||
function X(e, t) { | ||
function ee(t, n) { | ||
var o; | ||
let n = []; | ||
for (let c = e.length * 0.5; c--; ) { | ||
let u = `${k[e[c * 2].codePointAt(0)]}${k[e[c * 2 + 1].codePointAt(0)]}`; | ||
n.unshift(String.fromCharCode(parseInt(u, 16))); | ||
let e = []; | ||
for (let i = t.length * 0.5; i--; ) { | ||
let u = `${k[t[i * 2].codePointAt(0)]}${k[t[i * 2 + 1].codePointAt(0)]}`; | ||
e.unshift(String.fromCharCode(parseInt(u, 16))); | ||
} | ||
let r = [], s = [n.join("")], i = 10; | ||
let r = [], s = [e.join("")], c = 10; | ||
for (; s.length; ) { | ||
let c = s.shift(); | ||
let i = s.shift(); | ||
try { | ||
if (r.push(JSON.parse(c)), t) return r; | ||
if (r.push(JSON.parse(i)), n) return r; | ||
} catch (u) { | ||
if (!i--) throw u; | ||
let f = +((o = u.message.match(/\sposition\s(\d+)$/)) == null ? void 0 : o[1]); | ||
if (!f) throw u; | ||
s.unshift(c.substring(0, f), c.substring(f)); | ||
if (!c--) throw u; | ||
let a = +((o = u.message.match(/\sposition\s(\d+)$/)) == null ? void 0 : o[1]); | ||
if (!a) throw u; | ||
s.unshift(i.substring(0, a), i.substring(a)); | ||
} | ||
@@ -68,164 +68,177 @@ } | ||
} | ||
function Y(e) { | ||
var t; | ||
return { cleaned: e.replace(O, ""), encoded: ((t = e.match(O)) == null ? void 0 : t[0]) || "" }; | ||
function te(t) { | ||
var n; | ||
return { cleaned: t.replace(O, ""), encoded: ((n = t.match(O)) == null ? void 0 : n[0]) || "" }; | ||
} | ||
function T(e, t) { | ||
return z(e, t); | ||
function w(t, n) { | ||
return G(t, n); | ||
} | ||
function se(e) { | ||
return _(e); | ||
function ce(t) { | ||
return U(t); | ||
} | ||
function ce(e) { | ||
return H(e); | ||
function ie(t) { | ||
return X(t); | ||
} | ||
function ie(e) { | ||
return Y(e); | ||
function ae(t) { | ||
return te(t); | ||
} | ||
var q = Object.prototype.hasOwnProperty, ee = Object.prototype.toString, te = function(t, o, n) { | ||
if (ee.call(o) !== "[object Function]") | ||
throw new TypeError("iterator must be a function"); | ||
var r = t.length; | ||
if (r === +r) | ||
for (var s = 0; s < r; s++) | ||
o.call(n, t[s], s, t); | ||
else | ||
for (var i in t) | ||
q.call(t, i) && o.call(n, t[i], i, t); | ||
}, ne = te, y = a; | ||
function a(e, t, o) { | ||
if (arguments.length === 3) | ||
return a.set(e, t, o); | ||
if (arguments.length === 2) | ||
return a.get(e, t); | ||
var n = a.bind(a, e); | ||
for (var r in a) | ||
a.hasOwnProperty(r) && (n[r] = a[r].bind(n, e)); | ||
return n; | ||
var x, F; | ||
function ne() { | ||
if (F) return x; | ||
F = 1; | ||
var t = Object.prototype.hasOwnProperty, n = Object.prototype.toString; | ||
return x = function(e, r, s) { | ||
if (n.call(r) !== "[object Function]") | ||
throw new TypeError("iterator must be a function"); | ||
var c = e.length; | ||
if (c === +c) | ||
for (var i = 0; i < c; i++) | ||
r.call(s, e[i], i, e); | ||
else | ||
for (var u in e) | ||
t.call(e, u) && r.call(s, e[u], u, e); | ||
}, x; | ||
} | ||
a.get = function(t, o) { | ||
for (var n = Array.isArray(o) ? o : a.parse(o), r = 0; r < n.length; ++r) { | ||
var s = n[r]; | ||
if (!(typeof t == "object" && s in t)) | ||
throw new Error("Invalid reference token: " + s); | ||
t = t[s]; | ||
var I, _; | ||
function re() { | ||
if (_) return I; | ||
_ = 1; | ||
var t = ne(); | ||
I = n; | ||
function n(o, e, r) { | ||
if (arguments.length === 3) | ||
return n.set(o, e, r); | ||
if (arguments.length === 2) | ||
return n.get(o, e); | ||
var s = n.bind(n, o); | ||
for (var c in n) | ||
n.hasOwnProperty(c) && (s[c] = n[c].bind(s, o)); | ||
return s; | ||
} | ||
return t; | ||
}; | ||
a.set = function(t, o, n) { | ||
var r = Array.isArray(o) ? o : a.parse(o), s = r[0]; | ||
if (r.length === 0) | ||
throw Error("Can not set the root object"); | ||
for (var i = 0; i < r.length - 1; ++i) { | ||
var c = r[i]; | ||
typeof c != "string" && typeof c != "number" && (c = String(c)), !(c === "__proto__" || c === "constructor" || c === "prototype") && (c === "-" && Array.isArray(t) && (c = t.length), s = r[i + 1], c in t || (s.match(/^(\d+|-)$/) ? t[c] = [] : t[c] = {}), t = t[c]); | ||
} | ||
return s === "-" && Array.isArray(t) && (s = t.length), t[s] = n, this; | ||
}; | ||
a.remove = function(e, t) { | ||
var o = Array.isArray(t) ? t : a.parse(t), n = o[o.length - 1]; | ||
if (n === void 0) | ||
throw new Error('Invalid JSON pointer for remove: "' + t + '"'); | ||
var r = a.get(e, o.slice(0, -1)); | ||
if (Array.isArray(r)) { | ||
var s = +n; | ||
if (n === "" && isNaN(s)) | ||
throw new Error('Invalid array index: "' + n + '"'); | ||
Array.prototype.splice.call(r, s, 1); | ||
} else | ||
delete r[n]; | ||
}; | ||
a.dict = function(t, o) { | ||
var n = {}; | ||
return a.walk(t, function(r, s) { | ||
n[s] = r; | ||
}, o), n; | ||
}; | ||
a.walk = function(t, o, n) { | ||
var r = []; | ||
n = n || function(s) { | ||
var i = Object.prototype.toString.call(s); | ||
return i === "[object Object]" || i === "[object Array]"; | ||
}, function s(i) { | ||
ne(i, function(c, u) { | ||
r.push(String(u)), n(c) ? s(c) : o(c, a.compile(r)), r.pop(); | ||
}); | ||
}(t); | ||
}; | ||
a.has = function(t, o) { | ||
try { | ||
a.get(t, o); | ||
} catch (n) { | ||
return !1; | ||
} | ||
return !0; | ||
}; | ||
a.escape = function(t) { | ||
return t.toString().replace(/~/g, "~0").replace(/\//g, "~1"); | ||
}; | ||
a.unescape = function(t) { | ||
return t.replace(/~1/g, "/").replace(/~0/g, "~"); | ||
}; | ||
a.parse = function(t) { | ||
if (t === "") | ||
return []; | ||
if (t.charAt(0) !== "/") | ||
throw new Error("Invalid JSON pointer: " + t); | ||
return t.substring(1).split(/\//).map(a.unescape); | ||
}; | ||
a.compile = function(t) { | ||
return t.length === 0 ? "" : "/" + t.map(a.escape).join("/"); | ||
}; | ||
const re = ({ | ||
pointer: e, | ||
mappings: t, | ||
return n.get = function(e, r) { | ||
for (var s = Array.isArray(r) ? r : n.parse(r), c = 0; c < s.length; ++c) { | ||
var i = s[c]; | ||
if (!(typeof e == "object" && i in e)) | ||
throw new Error("Invalid reference token: " + i); | ||
e = e[i]; | ||
} | ||
return e; | ||
}, n.set = function(e, r, s) { | ||
var c = Array.isArray(r) ? r : n.parse(r), i = c[0]; | ||
if (c.length === 0) | ||
throw Error("Can not set the root object"); | ||
for (var u = 0; u < c.length - 1; ++u) { | ||
var a = c[u]; | ||
typeof a != "string" && typeof a != "number" && (a = String(a)), !(a === "__proto__" || a === "constructor" || a === "prototype") && (a === "-" && Array.isArray(e) && (a = e.length), i = c[u + 1], a in e || (i.match(/^(\d+|-)$/) ? e[a] = [] : e[a] = {}), e = e[a]); | ||
} | ||
return i === "-" && Array.isArray(e) && (i = e.length), e[i] = s, this; | ||
}, n.remove = function(o, e) { | ||
var r = Array.isArray(e) ? e : n.parse(e), s = r[r.length - 1]; | ||
if (s === void 0) | ||
throw new Error('Invalid JSON pointer for remove: "' + e + '"'); | ||
var c = n.get(o, r.slice(0, -1)); | ||
if (Array.isArray(c)) { | ||
var i = +s; | ||
if (s === "" && isNaN(i)) | ||
throw new Error('Invalid array index: "' + s + '"'); | ||
Array.prototype.splice.call(c, i, 1); | ||
} else | ||
delete c[s]; | ||
}, n.dict = function(e, r) { | ||
var s = {}; | ||
return n.walk(e, function(c, i) { | ||
s[i] = c; | ||
}, r), s; | ||
}, n.walk = function(e, r, s) { | ||
var c = []; | ||
s = s || function(i) { | ||
var u = Object.prototype.toString.call(i); | ||
return u === "[object Object]" || u === "[object Array]"; | ||
}, function i(u) { | ||
t(u, function(a, l) { | ||
c.push(String(l)), s(a) ? i(a) : r(a, n.compile(c)), c.pop(); | ||
}); | ||
}(e); | ||
}, n.has = function(e, r) { | ||
try { | ||
n.get(e, r); | ||
} catch (s) { | ||
return !1; | ||
} | ||
return !0; | ||
}, n.escape = function(e) { | ||
return e.toString().replace(/~/g, "~0").replace(/\//g, "~1"); | ||
}, n.unescape = function(e) { | ||
return e.replace(/~1/g, "/").replace(/~0/g, "~"); | ||
}, n.parse = function(e) { | ||
if (e === "") | ||
return []; | ||
if (e.charAt(0) !== "/") | ||
throw new Error("Invalid JSON pointer: " + e); | ||
return e.substring(1).split(/\//).map(n.unescape); | ||
}, n.compile = function(e) { | ||
return e.length === 0 ? "" : "/" + e.map(n.escape).join("/"); | ||
}, I; | ||
} | ||
var p = re(); | ||
const oe = ({ | ||
pointer: t, | ||
mappings: n, | ||
data: o, | ||
hiddenStrings: n | ||
hiddenStrings: e | ||
}) => { | ||
const r = t[e]; | ||
delete t[e]; | ||
const s = F(o, e); | ||
for (const i of s) { | ||
t[i] = r; | ||
const c = y.get(o, i), u = T(c, n); | ||
y.set(o, i, u); | ||
const r = n[t]; | ||
if (r) { | ||
delete n[t]; | ||
const s = C(o, t); | ||
for (const c of s) { | ||
n[c] = r; | ||
const i = p.get(o, c), u = w(i, e); | ||
p.set(o, c, u); | ||
} | ||
} else { | ||
const s = C(o, t); | ||
for (const c of s) { | ||
const i = p.get(o, c), u = w(i, e); | ||
p.set(o, c, u); | ||
} | ||
} | ||
}, F = (e, t = "") => { | ||
const o = [], n = y.get(e, t); | ||
if (n.content) | ||
for (let r = 0; r < n.content.length; r++) | ||
n.content[r].nodeType === "text" ? o.push(`${t}/content/${r}/value`) : o.push(...F(e, `${t}/content/${r}`)); | ||
}, C = (t, n = "") => { | ||
const o = [], e = p.get(t, n); | ||
if (e.content) | ||
for (let r = 0; r < e.content.length; r++) | ||
e.content[r].nodeType === "text" ? o.push(`${n}/content/${r}/value`) : o.push(...C(t, `${n}/content/${r}`)); | ||
return o; | ||
}, x = ({ | ||
entityId: e, | ||
entityType: t, | ||
}, b = ({ | ||
entityId: t, | ||
entityType: n, | ||
space: o, | ||
environment: n, | ||
environment: e, | ||
field: r, | ||
locale: s, | ||
editorInterface: i, | ||
fieldType: c, | ||
editorInterface: c, | ||
fieldType: i, | ||
targetOrigin: u, | ||
platform: f | ||
platform: a | ||
}) => { | ||
const d = { | ||
origin: "contentful.com", | ||
href: `${`${u || "https://app.contentful.com"}/spaces/${o}/environments/${n}`}/${t === "Entry" ? "entries" : "assets"}/${e}/?focusedField=${r}&focusedLocale=${s}&source=vercel-content-link`, | ||
href: `${`${u || "https://app.contentful.com"}/spaces/${o}/environments/${e}`}/${n === "Entry" ? "entries" : "assets"}/${t}/?focusedField=${r}&focusedLocale=${s}&source=vercel-content-link`, | ||
contentful: { | ||
editorInterface: i, | ||
fieldType: c | ||
editorInterface: c, | ||
fieldType: i | ||
} | ||
}; | ||
return f === "vercel" && delete d.contentful, d; | ||
}, W = (e) => ["builtin", "sidebar-builtin", "editor-builtin"].includes(e), U = (e) => oe.includes(e); | ||
function j(e) { | ||
return a === "vercel" && delete d.contentful, d; | ||
}, B = (t) => ["builtin", "sidebar-builtin", "editor-builtin"].includes(t), D = (t) => se.includes(t); | ||
function Q(t) { | ||
if (typeof structuredClone == "function") | ||
return structuredClone(e); | ||
return structuredClone(t); | ||
try { | ||
return JSON.parse(JSON.stringify(e)); | ||
} catch (t) { | ||
return console.warn("Failed to clone data:", e, t), e; | ||
return JSON.parse(JSON.stringify(t)); | ||
} catch (n) { | ||
return console.warn("Failed to clone data:", t, n), t; | ||
} | ||
} | ||
const oe = [ | ||
const se = [ | ||
"singleLine", | ||
@@ -238,20 +251,20 @@ "tagEditor", | ||
]; | ||
function C(e, t, o, n, r, s, i) { | ||
const c = i ? t[i] : t; | ||
switch (e) { | ||
function P(t, n, o, e, r, s, c) { | ||
const i = c ? n[c] : n; | ||
switch (t) { | ||
case "Symbol": { | ||
const u = T(c, o); | ||
y.set(n, r, u); | ||
const u = w(i, o); | ||
p.set(e, r, u); | ||
break; | ||
} | ||
case "Text": { | ||
const u = T(c, o); | ||
y.set(n, r, u); | ||
const u = w(i, o); | ||
p.set(e, r, u); | ||
break; | ||
} | ||
case "RichText": { | ||
re({ | ||
oe({ | ||
pointer: "", | ||
mappings: s, | ||
data: c, | ||
data: i, | ||
hiddenStrings: o | ||
@@ -262,4 +275,4 @@ }); | ||
case "Array": { | ||
const u = c.map((f) => typeof f == "string" ? T(f, o) : f); | ||
y.set(n, r, u); | ||
const u = i.map((a) => typeof a == "string" ? w(a, o) : a); | ||
p.set(e, r, u); | ||
break; | ||
@@ -269,48 +282,48 @@ } | ||
} | ||
const ae = (e, t, o) => { | ||
if (!e || !e.extensions || !e.extensions.contentSourceMaps) | ||
const ue = (t, n, o) => { | ||
if (!t || !t.extensions || !t.extensions.contentSourceMaps) | ||
return console.error( | ||
"GraphQL response does not contain Content Source Maps information.", | ||
e | ||
), e; | ||
const n = j(e), { | ||
t | ||
), t; | ||
const e = Q(t), { | ||
spaces: r, | ||
environments: s, | ||
editorInterfaces: i, | ||
fields: c, | ||
editorInterfaces: c, | ||
fields: i, | ||
locales: u, | ||
entries: f, | ||
assets: p, | ||
mappings: g, | ||
entries: a, | ||
assets: l, | ||
mappings: m, | ||
fieldTypes: v | ||
} = n.extensions.contentSourceMaps, h = n; | ||
for (const d in g) { | ||
const { source: l } = g[d], m = "entry" in l ? f[l.entry] : p[l.asset], P = "entry" in l ? "Entry" : "Asset"; | ||
if (!m) | ||
return n; | ||
const S = r[m.space], A = s[m.environment], E = m.id, w = c[l.field], I = u[l.locale], N = i[l.editorInterface], L = v[l.fieldType]; | ||
if (!(W(N.widgetNamespace) && !U(N.widgetId)) && y.has(h, d)) { | ||
const M = y.get(h, d); | ||
if (M !== null) { | ||
const B = x({ | ||
} = e.extensions.contentSourceMaps, y = e; | ||
for (const d in m) { | ||
const { source: f } = m[d], h = "entry" in f ? a[f.entry] : l[f.asset], M = "entry" in f ? "Entry" : "Asset"; | ||
if (!h) | ||
return e; | ||
const g = r[h.space], A = s[h.environment], E = h.id, S = i[f.field], T = u[f.locale], N = c[f.editorInterface], J = v[f.fieldType]; | ||
if (!(B(N.widgetNamespace) && !D(N.widgetId)) && p.has(y, d)) { | ||
const R = p.get(y, d); | ||
if (R !== null) { | ||
const z = b({ | ||
entityId: E, | ||
entityType: P, | ||
space: S, | ||
entityType: M, | ||
space: g, | ||
environment: A, | ||
field: w, | ||
locale: I, | ||
field: S, | ||
locale: T, | ||
editorInterface: N, | ||
fieldType: L, | ||
targetOrigin: t, | ||
fieldType: J, | ||
targetOrigin: n, | ||
platform: o | ||
}); | ||
C(L, M, B, h, d, g); | ||
P(J, R, z, y, d, m); | ||
} | ||
} | ||
} | ||
return n; | ||
}, $ = (e, t, o, n, r) => { | ||
if (!e.fields) | ||
return e; | ||
}, $ = (t, n, o, e, r) => { | ||
if (!t.fields) | ||
return; | ||
const { contentSourceMaps: s } = e.sys; | ||
const { contentSourceMaps: s } = t.sys; | ||
if (!s) { | ||
@@ -320,54 +333,54 @@ console.error("Content source maps data is missing"); | ||
} | ||
const { mappings: i } = s; | ||
for (const c in i) { | ||
const { source: u } = i[c], f = e.sys.space.sys.id, p = e.sys.environment.sys.id, g = e.sys.id, v = e.sys.type, h = t[u.fieldType], d = o[u.editorInterface]; | ||
if (W(d.widgetNamespace) && !U(d.widgetId)) | ||
const { mappings: c } = s; | ||
for (const i in c) { | ||
const { source: u } = c[i], a = t.sys.space.sys.id, l = t.sys.environment.sys.id, m = t.sys.id, v = t.sys.type, y = n[u.fieldType], d = o[u.editorInterface]; | ||
if (B(d.widgetNamespace) && !D(d.widgetId)) | ||
continue; | ||
const l = c.startsWith("/") ? c : `/${c}`; | ||
if (y.has(e, l)) { | ||
const m = y.get(e, l); | ||
if (m === null) | ||
const f = i.startsWith("/") ? i : `/${i}`; | ||
if (p.has(t, f)) { | ||
const h = p.get(t, f); | ||
if (h === null) | ||
return; | ||
const S = l.split("/").pop(); | ||
if (!S) { | ||
console.error("Field name could not be extracted from the pointer", l); | ||
const g = f.split("/").pop(); | ||
if (!g) { | ||
console.error("Field name could not be extracted from the pointer", f); | ||
return; | ||
} | ||
const A = e.sys.locale; | ||
const A = t.sys.locale; | ||
if (A) { | ||
const E = x({ | ||
entityId: g, | ||
const E = b({ | ||
entityId: m, | ||
entityType: v, | ||
space: f, | ||
environment: p, | ||
field: S, | ||
space: a, | ||
environment: l, | ||
field: g, | ||
locale: A, | ||
editorInterface: d, | ||
fieldType: h, | ||
targetOrigin: n, | ||
fieldType: y, | ||
targetOrigin: e, | ||
platform: r | ||
}); | ||
C(h, m, E, e, l, i); | ||
P(y, h, E, t, f, c); | ||
} else | ||
Object.keys(m).forEach((w) => { | ||
const I = x({ | ||
entityId: g, | ||
Object.keys(h).forEach((S) => { | ||
const T = b({ | ||
entityId: m, | ||
entityType: v, | ||
space: f, | ||
environment: p, | ||
field: S, | ||
locale: w, | ||
space: a, | ||
environment: l, | ||
field: g, | ||
locale: S, | ||
editorInterface: d, | ||
fieldType: h, | ||
targetOrigin: n, | ||
fieldType: y, | ||
targetOrigin: e, | ||
platform: r | ||
}); | ||
C( | ||
P( | ||
y, | ||
h, | ||
m, | ||
I, | ||
e, | ||
`${l}/${w}`, | ||
i, | ||
w | ||
T, | ||
t, | ||
`${f}/${S}`, | ||
c, | ||
S | ||
); | ||
@@ -377,23 +390,23 @@ }); | ||
} | ||
}, ue = (e, t, o) => { | ||
}, fe = (t, n, o) => { | ||
var r; | ||
const n = j( | ||
e | ||
const e = Q( | ||
t | ||
); | ||
if (n.sys && "items" in n) { | ||
const s = n; | ||
if (e.sys && "items" in e) { | ||
const s = e; | ||
if (!((r = s.sys) != null && r.contentSourceMapsLookup)) | ||
return console.error("Content source maps lookup data is missing"), s; | ||
const { | ||
contentSourceMapsLookup: { fieldTypes: i, editorInterfaces: c } | ||
} = s.sys, { items: u, includes: f } = s; | ||
contentSourceMapsLookup: { fieldTypes: c, editorInterfaces: i } | ||
} = s.sys, { items: u, includes: a } = s; | ||
u.forEach( | ||
(p) => $(p, i, c, t, o) | ||
), f && f.Entry && f.Entry.forEach( | ||
(p) => $(p, i, c, t, o) | ||
), f && f.Asset && f.Asset.forEach( | ||
(p) => $(p, i, c, t, o) | ||
(l) => $(l, c, i, n, o) | ||
), a && a.Entry && a.Entry.forEach( | ||
(l) => $(l, c, i, n, o) | ||
), a && a.Asset && a.Asset.forEach( | ||
(l) => $(l, c, i, n, o) | ||
); | ||
} else { | ||
const s = n; | ||
const s = e; | ||
if (!s.sys.contentSourceMapsLookup) | ||
@@ -405,23 +418,23 @@ return console.error("Content source maps lookup data is missing"), s; | ||
s.sys.contentSourceMapsLookup.editorInterfaces, | ||
t, | ||
n, | ||
o | ||
); | ||
} | ||
return n; | ||
return e; | ||
}; | ||
export { | ||
oe as SUPPORTED_WIDGETS, | ||
j as clone, | ||
T as combine, | ||
x as createSourceMapMetadata, | ||
ce as decode, | ||
se as encode, | ||
ue as encodeCPAResponse, | ||
C as encodeField, | ||
ae as encodeGraphQLResponse, | ||
re as encodeRichTextValue, | ||
W as isBuiltinNamespace, | ||
U as isSupportedWidget, | ||
ie as splitEncoding | ||
se as SUPPORTED_WIDGETS, | ||
Q as clone, | ||
w as combine, | ||
b as createSourceMapMetadata, | ||
ie as decode, | ||
ce as encode, | ||
fe as encodeCPAResponse, | ||
P as encodeField, | ||
ue as encodeGraphQLResponse, | ||
oe as encodeRichTextValue, | ||
B as isBuiltinNamespace, | ||
D as isSupportedWidget, | ||
ae as splitEncoding | ||
}; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import type { CPAEntry, CPAEntryCollection, CreateSourceMapParams } from '../types.js'; | ||
import { CPAEntry, CPAEntryCollection, CreateSourceMapParams } from '../types.js'; | ||
export declare const encodeCPAResponse: (CPAResponse: CPAEntry | CPAEntryCollection, targetOrigin?: CreateSourceMapParams["targetOrigin"], platform?: CreateSourceMapParams["platform"]) => CPAEntry | CPAEntryCollection; |
@@ -1,2 +0,2 @@ | ||
import type { CPAMappings, GraphQLMappings, SourceMapMetadata } from './types.js'; | ||
import { CPAMappings, GraphQLMappings, SourceMapMetadata } from './types.js'; | ||
export declare const encodeRichTextValue: ({ pointer, mappings, data, hiddenStrings, }: { | ||
@@ -3,0 +3,0 @@ pointer: string; |
@@ -1,2 +0,2 @@ | ||
import type { AssetSys, Entry as ContentfulEntry, EntryCollection as ContentfulEntryCollection, EntrySys as ContentfulEntrySys, EntrySkeletonType } from 'contentful'; | ||
import { AssetSys, Entry as ContentfulEntry, EntryCollection as ContentfulEntryCollection, EntrySys as ContentfulEntrySys, EntrySkeletonType } from 'contentful'; | ||
type ContentfulMetadata = { | ||
@@ -3,0 +3,0 @@ editorInterface: { |
@@ -1,2 +0,2 @@ | ||
import type { CPAEntry, CPAMappings, CreateSourceMapParams, FieldType, GraphQLMappings, GraphQLResponse, SourceMapMetadata, WidgetId, WidgetNamespace } from './types.js'; | ||
import { CPAEntry, CPAMappings, CreateSourceMapParams, FieldType, GraphQLMappings, GraphQLResponse, SourceMapMetadata, WidgetId, WidgetNamespace } from './types.js'; | ||
export declare const createSourceMapMetadata: ({ entityId, entityType, space, environment, field, locale, editorInterface, fieldType, targetOrigin, platform, }: CreateSourceMapParams) => SourceMapMetadata; | ||
@@ -3,0 +3,0 @@ export declare const isBuiltinNamespace: (namespace: WidgetNamespace) => boolean; |
{ | ||
"name": "@contentful/content-source-maps", | ||
"author": "Contentful GmbH", | ||
"version": "0.11.6", | ||
"version": "0.11.7", | ||
"description": "Base SDK for building Content Source Maps with Contentful", | ||
@@ -49,3 +49,3 @@ "license": "MIT", | ||
}, | ||
"gitHead": "99360eebf6fd0f39f26aa0180ba113d6b6a762f6" | ||
"gitHead": "4fc7a93deabec197570c952f8638afe4a0c19846" | ||
} |
@@ -141,2 +141,4 @@ > ⚠️ **Content Source Maps are only available on our Premium plan. Vercel Content Links are only available on Vercel Pro and Enterprise plans.** | ||
- For usage with @apollo/client, a custom link is needed to add the extensions to forward the extionsions to the response. [Example](../../examples/content-source-maps-apollo/lib/api-graphql.ts) | ||
## Limitations | ||
@@ -143,0 +145,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
110050
618
151