@weatherboard/cms 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -0
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +4 -4
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +4 -4
- package/dist/next.cjs +2 -2
- package/dist/next.cjs.map +2 -2
- package/dist/next.mjs +2 -2
- package/dist/next.mjs.map +2 -2
- package/dist/portable/sections.d.cts +43 -6
- package/dist/portable/sections.d.mts +43 -6
- package/dist/portable/sections.d.ts +43 -6
- package/dist/portable/site-content.d.cts +41 -10
- package/dist/portable/site-content.d.mts +41 -10
- package/dist/portable/site-content.d.ts +41 -10
- package/dist/server.cjs +2 -2
- package/dist/server.cjs.map +2 -2
- package/dist/server.mjs +2 -2
- package/dist/server.mjs.map +2 -2
- package/dist/site-content.cjs +7 -4
- package/dist/site-content.cjs.map +4 -4
- package/dist/site-content.d.cts +2 -2
- package/dist/site-content.d.mts +2 -2
- package/dist/site-content.d.ts +2 -2
- package/dist/site-content.mjs +7 -4
- package/dist/site-content.mjs.map +4 -4
- package/package.json +2 -1
package/dist/next.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import"server-only";function v(e){if(!Array.isArray(e))return!1;for(let n=0;n<e.length;n+=1)if(!Object.hasOwn(e,n))return!1;return!0}var I=["stacked","columns"],
|
|
1
|
+
import"server-only";function v(e){if(!Array.isArray(e))return!1;for(let n=0;n<e.length;n+=1)if(!Object.hasOwn(e,n))return!1;return!0}var I=["stacked","columns"],x=["none","playful"],M={layout:"stacked",decoration:"none"},R=`_type, _id, _rev, _updatedAt, title, locationKeys, note, signOff,
|
|
2
2
|
variants[]{_key, label, note, sections[]{_key, title, service, items[]{
|
|
3
3
|
_key, name, description, priceNote, dietary, allergenNote, availability,
|
|
4
4
|
prices[]{_key, label, amount{minor, currency}}, extras[]{_key, name, amount{minor, currency}}
|
|
5
|
-
}}}`;function W(e,n){return k(e,{types:["menu"],...n===void 0?{}:{ids:[n]}})}function d(e,n){throw new T("menu",[`${e} ${n}`])}function P(e,n,t=new Set,o){if(e===null||typeof e=="string"||typeof e=="boolean"||typeof e=="number"&&Number.isFinite(e))return e;if(typeof e!="object"||e===null)return d(n,"is not plain JSON data");try{if(t.has(e))return d(n,"is not acyclic JSON data");let r=Array.isArray(e),s=Object.getPrototypeOf(e);if(r?s!==Array.prototype:s!==Object.prototype&&s!==null)return d(n,"is not an ordinary saved object");t.add(e);let l=Reflect.ownKeys(e),u=r?[]:{},c=0,m=0;for(let i of l){if(typeof i!="string")return d(n,"has a symbol key");let a=r&&i!=="length"?`${n}[${i}]`:`${n}.${i}`,p;try{p=i==="_id"&&o!==void 0?o:Object.getOwnPropertyDescriptor(e,i)}catch{return d(a,"could not be snapshotted as plain JSON data")}if(!p||!Object.hasOwn(p,"value"))return d(a,"is not a saved data property");if(r&&i==="length"){let w=p.value;if(typeof w!="number"||!Number.isSafeInteger(w)||w<0)return d(a,"is not a saved list length");c=w;continue}if(!p.enumerable||r&&!/^(0|[1-9]\d*)$/.test(i))return d(a,"is not a JSON data property");let f=p.value,g=P(f,a,t);Object.defineProperty(u,i,{value:g,enumerable:!0,writable:!0,configurable:!0}),m++}return r&&(m!==c||u.length!==c)?d(n,"is not a complete saved list"):u}catch(r){if(r instanceof T)throw r;return d(n,"could not be snapshotted as plain JSON data")}finally{t.delete(e)}}function _(e,n){return e===null||typeof e!="object"||Array.isArray(e)||Object.getPrototypeOf(e)!==Object.prototype&&Object.getPrototypeOf(e)!==null?d(n,"is not an ordinary saved object"):e}function y(e,n,t=!0){return typeof e!="string"||t&&e.trim()===""?d(n,"is not saved text"):e}function C(e,n,t){return e[n]===void 0||e[n]===null?{}:{[n]:y(e[n],`${t}.${n}`,!1)}}function $(e,n,t){return e==null?[]:v(e)?e.map((o,r)=>t(o,`${n}[${String(r)}]`)):d(n,"is not a complete saved list")}function j(e,n){let t=_(e,n);if(typeof t.minor!="number"||!Number.isSafeInteger(t.minor)||t.minor<0)return d(`${n}.minor`,"is not a whole non-negative safe amount");let o=y(t.currency,`${n}.currency`);return/^[A-Z]{3}$/.test(o)?{minor:t.minor,currency:o}:d(`${n}.currency`,"is not a three-letter currency code")}function G(e,n){let t=_(e,n);return{_key:y(t._key,`${n}._key`),amount:j(t.amount,`${n}.amount`),...C(t,"label",n)}}function Z(e,n){let t=_(e,n);return{_key:y(t._key,`${n}._key`),name:y(t.name,`${n}.name`),amount:j(t.amount,`${n}.amount`)}}function V(e,n){let t=_(e,n),o=t.availability??"available";return o!=="available"&&o!=="sold-out"&&o!=="hidden"?d(`${n}.availability`,"is not an availability choice"):{_key:y(t._key,`${n}._key`),name:y(t.name,`${n}.name`),...C(t,"description",n),...C(t,"priceNote",n),...C(t,"allergenNote",n),prices:$(t.prices,`${n}.prices`,G),extras:$(t.extras,`${n}.extras`,Z),dietary:$(t.dietary,`${n}.dietary`,y),availability:o}}function K(e,n){let t=_(e,n);return{_key:y(t._key,`${n}._key`),title:y(t.title,`${n}.title`),...C(t,"service",n),items:$(t.items,`${n}.items`,V)}}function X(e,n){let t=_(e,n);return{_key:y(t._key,`${n}._key`),label:y(t.label,`${n}.label`),...C(t,"note",n),sections:$(t.sections,`${n}.sections`,K)}}function ee(e){if(e===null||typeof e!="object"||Array.isArray(e))return!1;let n=e._id;return typeof n=="string"&&n.trim()!==""&&!/^(drafts|versions)\./.test(n)}function R(e,n="menu"){return ne(P(e,n),n)}function ne(e,n){let t=_(e,n);if(t._type!=="menu")return d(`${n}._type`,"is not menu");if(!ee(t))return d(`${n}._id`,"is not a published menu identity");let o=y(t._updatedAt,`${n}._updatedAt`);if(!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/.test(o)||!Number.isFinite(Date.parse(o)))return d(`${n}._updatedAt`,"is not an update date");let r=$(t.variants,`${n}.variants`,X);return r.length===0?d(`${n}.variants`,"has no menu choices"):{_type:"menu",_id:y(t._id,`${n}._id`),_rev:y(t._rev,`${n}._rev`),_updatedAt:o,title:y(t.title,`${n}.title`),locationKeys:$(t.locationKeys,`${n}.locationKeys`,y),variants:r,...C(t,"note",n),...Object.hasOwn(t,"signOff")?{signOff:t.signOff}:{}}}function U(e){if(e===null)return!0;try{return R(e),!0}catch{return!1}}var L="malformed-content",T=class extends Error{code=L;documentId;problems;constructor(n,t){super(`${L}: ${n}: ${t.join("; ")}`),this.name="MalformedContentError",this.documentId=n,this.problems=t}};var q=`{..., "sections": coalesce(sections[]{..., _type == "menuBlock" => {menu->{${O}}}}, sections)}`,Te=`*[_type == "page" && defined(slug.current)]|order(slug.current asc)${q}`,Ae=`*[_type == "page" && slug.current == $slug][0]${q}`;var te=/^[A-Za-z][A-Za-z0-9_]{0,63}$/,oe=/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/,re=/^[a-z0-9]{6,12}\.[a-z][a-z0-9_-]{0,63}$/;function z(e){if(!e||!Array.isArray(e.types)||e.types.length===0)throw new TypeError("CMS dependencies require document types");let n=[...e.types];for(let o of n)if(typeof o!="string"||!te.test(o))throw new TypeError("Invalid CMS document type");if(e.ids!==void 0&&!Array.isArray(e.ids))throw new TypeError("Invalid CMS document IDs");let t=e.ids===void 0?void 0:[...e.ids];for(let o of t??[])if(typeof o!="string"||!oe.test(o)||/^(drafts|versions)\./.test(o))throw new TypeError("Invalid CMS document ID");if(new Set(n).size+new Set(t).size>128)throw new TypeError("Too many CMS tags");return Object.freeze({types:Object.freeze(n),...t===void 0?{}:{ids:Object.freeze(t)}})}function N(e){if(!e||typeof e.name!="string"||!/^[A-Za-z][A-Za-z0-9_.-]{0,127}$/.test(e.name)||typeof e.query!="string"||e.query.trim()===""||typeof e.resolve!="function")throw new TypeError("Invalid CMS query configuration");let n=e.params;if(!n||typeof n!="object"||Object.getPrototypeOf(n)!==Object.prototype&&Object.getPrototypeOf(n)!==null)throw new TypeError("CMS params must be plain JSON scalars");let t={};for(let o of Reflect.ownKeys(n)){let r=Object.getOwnPropertyDescriptor(n,o);if(typeof o!="string"||!r||!Object.hasOwn(r,"value")||!r.enumerable)throw new TypeError("CMS params must be plain JSON scalars");let s=r.value;if(!(s===null||typeof s=="string"||typeof s=="boolean"||typeof s=="number"&&Number.isFinite(s)))throw new TypeError("CMS params must be plain JSON scalars");Object.defineProperty(t,o,{value:s,enumerable:!0})}return Object.freeze({name:e.name,query:e.query,params:Object.freeze(t),dependencies:z(e.dependencies),resolve:e.resolve})}function k(e,n){if(typeof e!="string"||e.length>77||!re.test(e))throw new TypeError("Invalid CMS scope");let t=z(n),o=[...[...new Set(t.types)].sort().map(r=>`cms:${e}:type:${r}`),...[...new Set(t.ids??[])].sort().map(r=>`cms:${e}:id:${r}`)];return Object.freeze(o)}function se(e){return N({name:"menu.v1",query:`*[_type == "menu" && _id == $id && !(_id in path("drafts.**")) && !(_id in path("versions.**"))][0]{${O}}`,params:{id:e},dependencies:{types:["menu"],ids:[e]},resolve:(n,t)=>{if(!U(t)||t!==null&&t._id!==e)throw new TypeError("Invalid CMS menu fallback");if(n==null)return{data:t,fallbackFields:["$"]};let o=R(n);if(o._id!==e)throw new T("menu",["menu._id does not match the requested document"]);return{data:o,fallbackFields:[]}}})}function F(e){if(!e||!Object.hasOwn(e,"data")||!Array.isArray(e.fallbackFields)||![...e.fallbackFields].every(n=>typeof n=="string"&&(n==="$"||/^[A-Za-z][A-Za-z0-9_.[\]-]{0,127}$/.test(n))))throw new TypeError("Invalid CMS resolution");if(e.warnings!==void 0&&(!Array.isArray(e.warnings)||![...e.warnings].every(n=>n==="siteHero.layout.defaulted"||n==="siteHero.tagline.dropped"||n==="siteHero.taglines.defaulted")))throw new TypeError("Invalid CMS resolution warnings");return{data:e.data,fallbackFields:Object.freeze([...new Set(e.fallbackFields)]),...e.warnings?.length?{warnings:Object.freeze([...new Set(e.warnings)])}:{}}}function H(e){let n=e?.revalidateSeconds??3600;if(!Number.isSafeInteger(n)||n<3600||!e?.adapter||typeof e.adapter.read!="function"||e.onDiagnostic!==void 0&&typeof e.onDiagnostic!="function")throw new TypeError("Invalid CMS reader configuration");let t=e.adapter;k(t.scope,{types:["ScopeValidation"]});let o=r=>{try{e.onDiagnostic?e.onDiagnostic(r):console.warn(JSON.stringify(r))}catch{}};return{async read(r,s){let l,u,c;try{if(l=N(r),c=k(t.scope,l.dependencies),!s||!Object.hasOwn(s,"fallback"))throw new TypeError;u=F(l.resolve(null,s.fallback))}catch{throw new TypeError("Invalid CMS query or fallback configuration")}let m=(p,f,g)=>(o({event:"cms.fallback",query:l.name,reason:p,fields:["$"],...f===void 0?{}:{status:f},...g?{warnings:g}:{}}),{data:u.data,source:"fallback",fallbackFields:["$"],reason:p,...g?{warnings:g}:{}}),i;try{i=await t.read({name:l.name,query:l.query,params:l.params},{tags:c,revalidateSeconds:n})}catch{return m("network")}if(!i.ok){let f=["configuration","network","timeout","rate-limit","upstream","plan-limit","permission","malformed"].includes(i.reason)?i.reason:"malformed",g=Number.isInteger(i.status)&&(i.status??0)>=100&&(i.status??0)<=599?i.status:void 0;return m(f,g)}if(i.value===null||i.value===void 0)return m("missing");let a;try{a=F(l.resolve(i.value,s.fallback))}catch{return m("malformed")}return a.fallbackFields.includes("$")?{...m("invalid-field",void 0,a.warnings),data:a.data}:a.fallbackFields.length>0?(o({event:"cms.partial-fallback",query:l.name,reason:"invalid-field",fields:a.fallbackFields,...a.warnings?{warnings:a.warnings}:{}}),{...a,source:"mixed",reason:"invalid-field"}):{...a,source:"cms"}}}}var ie=H;import{revalidateTag as ce}from"next/cache.js";var D="sanity-webhook-signature",ae=/^t=(\d+)[, ]+v1=([^, ]+)$/;var B=new TextEncoder;function le(e){return crypto.subtle.importKey("raw",B.encode(e),{name:"HMAC",hash:"SHA-256"},!1,["sign","verify"])}function ue(e){if(!/^[A-Za-z0-9_-]+={0,2}$/.test(e))return null;let n=e.replace(/-/g,"+").replace(/_/g,"/");try{let t=atob(n),o=new Uint8Array(t.length);for(let r=0;r<t.length;r+=1)o[r]=t.charCodeAt(r);return o}catch{return null}}async function J(e){let{secret:n,rawBody:t,headers:o}=e,r=e.now??Date.now(),s=e.toleranceMs??3e5;if(!n||n.length===0)return{ok:!1,reason:"no-secret"};let l=o.get(D);if(!l)return{ok:!1,reason:"no-signature"};let u=ae.exec(l.trim());if(u===null)return{ok:!1,reason:"malformed-signature"};let c=Number(u[1]),m=u[2]??"";if(!Number.isSafeInteger(c))return{ok:!1,reason:"malformed-signature"};if(c<16094592e5)return{ok:!1,reason:"stale-timestamp"};if(Math.abs(r-c)>s)return{ok:!1,reason:"stale-timestamp"};let i=ue(m);if(i===null)return{ok:!1,reason:"malformed-signature"};let a=await le(n);return await crypto.subtle.verify("HMAC",a,i,B.encode(`${c}.${t}`))?{ok:!0}:{ok:!1,reason:"bad-signature"}}var de=16*1024,ye=1500,pe=new TextEncoder;function h(e,n,t={},o=!1){return new Response(o?null:JSON.stringify(n),{status:e,headers:{"Content-Type":"application/json","Cache-Control":"no-store",...t}})}function fe(e,n){if(!n||typeof n!="object"||Array.isArray(n)||Object.keys(n).length===0)throw new TypeError("Invalid CMS invalidation mapping");let t=Object.create(null);for(let o of Reflect.ownKeys(n)){let r=Object.getOwnPropertyDescriptor(n,o);if(typeof o!="string"||!r?.enumerable||!Object.hasOwn(r,"value"))throw new TypeError("Invalid CMS invalidation mapping");let s=r.value;if(!Array.isArray(s)||!s.includes(o))throw new TypeError("Invalid CMS invalidation mapping");k(e,{types:s,ids:["validation"]}),t[o]=Object.freeze([...s])}for(let o of Object.values(t))if(o.some(r=>!Object.hasOwn(t,r)))throw new TypeError("Invalid CMS invalidation mapping");return Object.freeze(t)}function Y(e){return typeof e=="string"&&e.trim()!==""&&pe.encode(e).byteLength>=32}var A=class extends Error{constructor(t){super("Invalid CMS webhook body");this.status=t}status};async function me(e){let n=e.body?.getReader();if(!n)return"";let t=new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0}),o,r=new Promise((s,l)=>{o=setTimeout(()=>l(new A(400)),ye)});try{let s=0,l="";for(;;){let{done:u,value:c}=await Promise.race([n.read(),r]);if(u)return l+t.decode();if(s+=c.byteLength,s>de)throw new A(413);l+=t.decode(c,{stream:!0})}}catch(s){throw n.cancel().catch(()=>{}),s}finally{clearTimeout(o),n.releaseLock()}}function ge(e){let n=e.scope,t=fe(n,e.typeToTags),o=e.secretEnv??"SANITY_REVALIDATE_SECRET",r=e.previousSecretEnv??"SANITY_REVALIDATE_SECRET_PREVIOUS",s=e.env??(()=>process.env),l=e.now??Date.now,u=async c=>{if(c.method!=="POST")return h(405,{error:"Method not allowed"},{Allow:"POST"},c.method==="HEAD");let m,i;try{let b=s(),E=b[o],S=b[r];if(!Y(E)||S!==void 0&&!Y(S))throw new Error;m=E,i=S}catch{return h(503,{error:"COULD NOT ANSWER: revalidation configuration unavailable"})}let a=c.headers.get(D);if(!a||a.length>512||!/^t=\d+[, ]+v1=[A-Za-z0-9_-]+={0,2}$/.test(a.trim()))return h(401,{error:"Unauthorized"});let p;try{p=await me(c)}catch(b){return b instanceof A&&b.status===413?h(413,{error:"Payload too large"}):h(400,{error:"Invalid body"})}try{let b=l();if(!Number.isFinite(b))throw new Error;if(!(await Promise.all([m,...i===void 0?[]:[i]].map(S=>J({secret:S,rawBody:p,headers:c.headers,now:b})))).some(S=>S.ok))return h(401,{error:"Unauthorized"})}catch{return h(401,{error:"Unauthorized"})}let f;try{f=JSON.parse(p)}catch{return h(400,{error:"Invalid payload"})}if(!f||typeof f!="object"||Array.isArray(f)||Object.keys(f).length!==2||!Object.hasOwn(f,"_type")||!Object.hasOwn(f,"_id"))return h(400,{error:"Invalid payload"});let{_type:g,_id:w}=f;if(typeof g!="string"||!/^[A-Za-z][A-Za-z0-9_]{0,63}$/.test(g)||typeof w!="string"||!/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/.test(w))return h(400,{error:"Invalid payload"});if(!Object.hasOwn(t,g)||/^(drafts|versions)\./.test(w))return h(400,{error:"Unsupported document"});let Q=k(n,{types:t[g],ids:[w]});try{for(let b of Q)ce(b,{expire:0})}catch{return h(500,{error:"Could not revalidate"})}return h(200,{revalidated:!0})};return Object.freeze({POST:u,GET:u,HEAD:u,PUT:u,PATCH:u,DELETE:u,OPTIONS:u})}export{M as MENU_DECORATIONS,I as MENU_LAYOUTS,x as MENU_LAYOUT_DEFAULTS,ie as createNextCmsReader,ge as createRevalidateRoute,se as menuQuery,W as menuTags,R as parseMenuDocument};
|
|
5
|
+
}}}`;function W(e,n){return w(e,{types:["menu"],...n===void 0?{}:{ids:[n]}})}function d(e,n){throw new T("menu",[`${e} ${n}`])}function N(e,n,t=new Set,o){if(e===null||typeof e=="string"||typeof e=="boolean"||typeof e=="number"&&Number.isFinite(e))return e;if(typeof e!="object"||e===null)return d(n,"is not plain JSON data");try{if(t.has(e))return d(n,"is not acyclic JSON data");let r=Array.isArray(e),i=Object.getPrototypeOf(e);if(r?i!==Array.prototype:i!==Object.prototype&&i!==null)return d(n,"is not an ordinary saved object");t.add(e);let l=Reflect.ownKeys(e),c=r?[]:{},u=0,m=0;for(let s of l){if(typeof s!="string")return d(n,"has a symbol key");let a=r&&s!=="length"?`${n}[${s}]`:`${n}.${s}`,p;try{p=s==="_id"&&o!==void 0?o:Object.getOwnPropertyDescriptor(e,s)}catch{return d(a,"could not be snapshotted as plain JSON data")}if(!p||!Object.hasOwn(p,"value"))return d(a,"is not a saved data property");if(r&&s==="length"){let k=p.value;if(typeof k!="number"||!Number.isSafeInteger(k)||k<0)return d(a,"is not a saved list length");u=k;continue}if(!p.enumerable||r&&!/^(0|[1-9]\d*)$/.test(s))return d(a,"is not a JSON data property");let f=p.value,g=N(f,a,t);Object.defineProperty(c,s,{value:g,enumerable:!0,writable:!0,configurable:!0}),m++}return r&&(m!==u||c.length!==u)?d(n,"is not a complete saved list"):c}catch(r){if(r instanceof T)throw r;return d(n,"could not be snapshotted as plain JSON data")}finally{t.delete(e)}}function C(e,n){return e===null||typeof e!="object"||Array.isArray(e)||Object.getPrototypeOf(e)!==Object.prototype&&Object.getPrototypeOf(e)!==null?d(n,"is not an ordinary saved object"):e}function y(e,n,t=!0){return typeof e!="string"||t&&e.trim()===""?d(n,"is not saved text"):e}function S(e,n,t){return e[n]===void 0||e[n]===null?{}:{[n]:y(e[n],`${t}.${n}`,!1)}}function _(e,n,t){return e==null?[]:v(e)?e.map((o,r)=>t(o,`${n}[${String(r)}]`)):d(n,"is not a complete saved list")}function P(e,n){let t=C(e,n);if(typeof t.minor!="number"||!Number.isSafeInteger(t.minor)||t.minor<0)return d(`${n}.minor`,"is not a whole non-negative safe amount");let o=y(t.currency,`${n}.currency`);return/^[A-Z]{3}$/.test(o)?{minor:t.minor,currency:o}:d(`${n}.currency`,"is not a three-letter currency code")}function G(e,n){let t=C(e,n);return{_key:y(t._key,`${n}._key`),amount:P(t.amount,`${n}.amount`),...S(t,"label",n)}}function Z(e,n){let t=C(e,n);return{_key:y(t._key,`${n}._key`),name:y(t.name,`${n}.name`),amount:P(t.amount,`${n}.amount`)}}function V(e,n){let t=C(e,n),o=t.availability??"available";return o!=="available"&&o!=="sold-out"&&o!=="hidden"?d(`${n}.availability`,"is not an availability choice"):{_key:y(t._key,`${n}._key`),name:y(t.name,`${n}.name`),...S(t,"description",n),...S(t,"priceNote",n),...S(t,"allergenNote",n),prices:_(t.prices,`${n}.prices`,G),extras:_(t.extras,`${n}.extras`,Z),dietary:_(t.dietary,`${n}.dietary`,y),availability:o}}function K(e,n){let t=C(e,n);return{_key:y(t._key,`${n}._key`),title:y(t.title,`${n}.title`),...S(t,"service",n),items:_(t.items,`${n}.items`,V)}}function X(e,n){let t=C(e,n);return{_key:y(t._key,`${n}._key`),label:y(t.label,`${n}.label`),...S(t,"note",n),sections:_(t.sections,`${n}.sections`,K)}}function ee(e){if(e===null||typeof e!="object"||Array.isArray(e))return!1;let n=e._id;return typeof n=="string"&&n.trim()!==""&&!/^(drafts|versions)\./.test(n)}function E(e,n="menu"){return ne(N(e,n),n)}function ne(e,n){let t=C(e,n);if(t._type!=="menu")return d(`${n}._type`,"is not menu");if(!ee(t))return d(`${n}._id`,"is not a published menu identity");let o=y(t._updatedAt,`${n}._updatedAt`);if(!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/.test(o)||!Number.isFinite(Date.parse(o)))return d(`${n}._updatedAt`,"is not an update date");let r=_(t.variants,`${n}.variants`,X);return r.length===0?d(`${n}.variants`,"has no menu choices"):{_type:"menu",_id:y(t._id,`${n}._id`),_rev:y(t._rev,`${n}._rev`),_updatedAt:o,title:y(t.title,`${n}.title`),locationKeys:_(t.locationKeys,`${n}.locationKeys`,y),variants:r,...S(t,"note",n),...Object.hasOwn(t,"signOff")?{signOff:t.signOff}:{}}}function U(e){if(e===null)return!0;try{return E(e),!0}catch{return!1}}var L="malformed-content",T=class extends Error{code=L;documentId;problems;constructor(n,t){super(`${L}: ${n}: ${t.join("; ")}`),this.name="MalformedContentError",this.documentId=n,this.problems=t}};var q=`{..., "sections": coalesce(sections[]{..., _type == "menuBlock" => {menu->{${R}}}, _type == "linkListBlock" => {links[]{..., "page": page->{title, "slug": slug.current}}}}, sections)}`,Te=`*[_type == "page" && defined(slug.current)]|order(slug.current asc)${q}`,Ae=`*[_type == "page" && slug.current == $slug][0]${q}`;var te=/^[A-Za-z][A-Za-z0-9_]{0,63}$/,oe=/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/,re=/^[a-z0-9]{6,12}\.[a-z][a-z0-9_-]{0,63}$/;function H(e){if(!e||!Array.isArray(e.types)||e.types.length===0)throw new TypeError("CMS dependencies require document types");let n=[...e.types];for(let o of n)if(typeof o!="string"||!te.test(o))throw new TypeError("Invalid CMS document type");if(e.ids!==void 0&&!Array.isArray(e.ids))throw new TypeError("Invalid CMS document IDs");let t=e.ids===void 0?void 0:[...e.ids];for(let o of t??[])if(typeof o!="string"||!oe.test(o)||/^(drafts|versions)\./.test(o))throw new TypeError("Invalid CMS document ID");if(new Set(n).size+new Set(t).size>128)throw new TypeError("Too many CMS tags");return Object.freeze({types:Object.freeze(n),...t===void 0?{}:{ids:Object.freeze(t)}})}function D(e){if(!e||typeof e.name!="string"||!/^[A-Za-z][A-Za-z0-9_.-]{0,127}$/.test(e.name)||typeof e.query!="string"||e.query.trim()===""||typeof e.resolve!="function")throw new TypeError("Invalid CMS query configuration");let n=e.params;if(!n||typeof n!="object"||Object.getPrototypeOf(n)!==Object.prototype&&Object.getPrototypeOf(n)!==null)throw new TypeError("CMS params must be plain JSON scalars");let t={};for(let o of Reflect.ownKeys(n)){let r=Object.getOwnPropertyDescriptor(n,o);if(typeof o!="string"||!r||!Object.hasOwn(r,"value")||!r.enumerable)throw new TypeError("CMS params must be plain JSON scalars");let i=r.value;if(!(i===null||typeof i=="string"||typeof i=="boolean"||typeof i=="number"&&Number.isFinite(i)))throw new TypeError("CMS params must be plain JSON scalars");Object.defineProperty(t,o,{value:i,enumerable:!0})}return Object.freeze({name:e.name,query:e.query,params:Object.freeze(t),dependencies:H(e.dependencies),resolve:e.resolve})}function w(e,n){if(typeof e!="string"||e.length>77||!re.test(e))throw new TypeError("Invalid CMS scope");let t=H(n),o=[...[...new Set(t.types)].sort().map(r=>`cms:${e}:type:${r}`),...[...new Set(t.ids??[])].sort().map(r=>`cms:${e}:id:${r}`)];return Object.freeze(o)}function ie(e){return D({name:"menu.v1",query:`*[_type == "menu" && _id == $id && !(_id in path("drafts.**")) && !(_id in path("versions.**"))][0]{${R}}`,params:{id:e},dependencies:{types:["menu"],ids:[e]},resolve:(n,t)=>{if(!U(t)||t!==null&&t._id!==e)throw new TypeError("Invalid CMS menu fallback");if(n==null)return{data:t,fallbackFields:["$"]};let o=E(n);if(o._id!==e)throw new T("menu",["menu._id does not match the requested document"]);return{data:o,fallbackFields:[]}}})}function B(e){if(!e||!Object.hasOwn(e,"data")||!Array.isArray(e.fallbackFields)||![...e.fallbackFields].every(n=>typeof n=="string"&&(n==="$"||/^[A-Za-z][A-Za-z0-9_.[\]-]{0,127}$/.test(n))))throw new TypeError("Invalid CMS resolution");if(e.warnings!==void 0&&(!Array.isArray(e.warnings)||![...e.warnings].every(n=>n==="siteHero.layout.defaulted"||n==="siteHero.tagline.dropped"||n==="siteHero.taglines.defaulted")))throw new TypeError("Invalid CMS resolution warnings");return{data:e.data,fallbackFields:Object.freeze([...new Set(e.fallbackFields)]),...e.warnings?.length?{warnings:Object.freeze([...new Set(e.warnings)])}:{}}}function z(e){let n=e?.revalidateSeconds??3600;if(!Number.isSafeInteger(n)||n<3600||!e?.adapter||typeof e.adapter.read!="function"||e.onDiagnostic!==void 0&&typeof e.onDiagnostic!="function")throw new TypeError("Invalid CMS reader configuration");let t=e.adapter;w(t.scope,{types:["ScopeValidation"]});let o=r=>{try{e.onDiagnostic?e.onDiagnostic(r):console.warn(JSON.stringify(r))}catch{}};return{async read(r,i){let l,c,u;try{if(l=D(r),u=w(t.scope,l.dependencies),!i||!Object.hasOwn(i,"fallback"))throw new TypeError;c=B(l.resolve(null,i.fallback))}catch{throw new TypeError("Invalid CMS query or fallback configuration")}let m=(p,f,g)=>(o({event:"cms.fallback",query:l.name,reason:p,fields:["$"],...f===void 0?{}:{status:f},...g?{warnings:g}:{}}),{data:c.data,source:"fallback",fallbackFields:["$"],reason:p,...g?{warnings:g}:{}}),s;try{s=await t.read({name:l.name,query:l.query,params:l.params},{tags:u,revalidateSeconds:n})}catch{return m("network")}if(!s.ok){let f=["configuration","network","timeout","rate-limit","upstream","plan-limit","permission","malformed"].includes(s.reason)?s.reason:"malformed",g=Number.isInteger(s.status)&&(s.status??0)>=100&&(s.status??0)<=599?s.status:void 0;return m(f,g)}if(s.value===null||s.value===void 0)return m("missing");let a;try{a=B(l.resolve(s.value,i.fallback))}catch{return m("malformed")}return a.fallbackFields.includes("$")?{...m("invalid-field",void 0,a.warnings),data:a.data}:a.fallbackFields.length>0?(o({event:"cms.partial-fallback",query:l.name,reason:"invalid-field",fields:a.fallbackFields,...a.warnings?{warnings:a.warnings}:{}}),{...a,source:"mixed",reason:"invalid-field"}):{...a,source:"cms"}}}}var se=z;import{revalidateTag as ue}from"next/cache.js";var j="sanity-webhook-signature",ae=/^t=(\d+)[, ]+v1=([^, ]+)$/;var F=new TextEncoder;function le(e){return crypto.subtle.importKey("raw",F.encode(e),{name:"HMAC",hash:"SHA-256"},!1,["sign","verify"])}function ce(e){if(!/^[A-Za-z0-9_-]+={0,2}$/.test(e))return null;let n=e.replace(/-/g,"+").replace(/_/g,"/");try{let t=atob(n),o=new Uint8Array(t.length);for(let r=0;r<t.length;r+=1)o[r]=t.charCodeAt(r);return o}catch{return null}}async function J(e){let{secret:n,rawBody:t,headers:o}=e,r=e.now??Date.now(),i=e.toleranceMs??3e5;if(!n||n.length===0)return{ok:!1,reason:"no-secret"};let l=o.get(j);if(!l)return{ok:!1,reason:"no-signature"};let c=ae.exec(l.trim());if(c===null)return{ok:!1,reason:"malformed-signature"};let u=Number(c[1]),m=c[2]??"";if(!Number.isSafeInteger(u))return{ok:!1,reason:"malformed-signature"};if(u<16094592e5)return{ok:!1,reason:"stale-timestamp"};if(Math.abs(r-u)>i)return{ok:!1,reason:"stale-timestamp"};let s=ce(m);if(s===null)return{ok:!1,reason:"malformed-signature"};let a=await le(n);return await crypto.subtle.verify("HMAC",a,s,F.encode(`${u}.${t}`))?{ok:!0}:{ok:!1,reason:"bad-signature"}}var de=16*1024,ye=1500,pe=new TextEncoder;function h(e,n,t={},o=!1){return new Response(o?null:JSON.stringify(n),{status:e,headers:{"Content-Type":"application/json","Cache-Control":"no-store",...t}})}function fe(e,n){if(!n||typeof n!="object"||Array.isArray(n)||Object.keys(n).length===0)throw new TypeError("Invalid CMS invalidation mapping");let t=Object.create(null);for(let o of Reflect.ownKeys(n)){let r=Object.getOwnPropertyDescriptor(n,o);if(typeof o!="string"||!r?.enumerable||!Object.hasOwn(r,"value"))throw new TypeError("Invalid CMS invalidation mapping");let i=r.value;if(!Array.isArray(i)||!i.includes(o))throw new TypeError("Invalid CMS invalidation mapping");w(e,{types:i,ids:["validation"]}),t[o]=Object.freeze([...i])}for(let o of Object.values(t))if(o.some(r=>!Object.hasOwn(t,r)))throw new TypeError("Invalid CMS invalidation mapping");return Object.freeze(t)}function Y(e){return typeof e=="string"&&e.trim()!==""&&pe.encode(e).byteLength>=32}var A=class extends Error{constructor(t){super("Invalid CMS webhook body");this.status=t}status};async function me(e){let n=e.body?.getReader();if(!n)return"";let t=new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0}),o,r=new Promise((i,l)=>{o=setTimeout(()=>l(new A(400)),ye)});try{let i=0,l="";for(;;){let{done:c,value:u}=await Promise.race([n.read(),r]);if(c)return l+t.decode();if(i+=u.byteLength,i>de)throw new A(413);l+=t.decode(u,{stream:!0})}}catch(i){throw n.cancel().catch(()=>{}),i}finally{clearTimeout(o),n.releaseLock()}}function ge(e){let n=e.scope,t=fe(n,e.typeToTags),o=e.secretEnv??"SANITY_REVALIDATE_SECRET",r=e.previousSecretEnv??"SANITY_REVALIDATE_SECRET_PREVIOUS",i=e.env??(()=>process.env),l=e.now??Date.now,c=async u=>{if(u.method!=="POST")return h(405,{error:"Method not allowed"},{Allow:"POST"},u.method==="HEAD");let m,s;try{let b=i(),O=b[o],$=b[r];if(!Y(O)||$!==void 0&&!Y($))throw new Error;m=O,s=$}catch{return h(503,{error:"COULD NOT ANSWER: revalidation configuration unavailable"})}let a=u.headers.get(j);if(!a||a.length>512||!/^t=\d+[, ]+v1=[A-Za-z0-9_-]+={0,2}$/.test(a.trim()))return h(401,{error:"Unauthorized"});let p;try{p=await me(u)}catch(b){return b instanceof A&&b.status===413?h(413,{error:"Payload too large"}):h(400,{error:"Invalid body"})}try{let b=l();if(!Number.isFinite(b))throw new Error;if(!(await Promise.all([m,...s===void 0?[]:[s]].map($=>J({secret:$,rawBody:p,headers:u.headers,now:b})))).some($=>$.ok))return h(401,{error:"Unauthorized"})}catch{return h(401,{error:"Unauthorized"})}let f;try{f=JSON.parse(p)}catch{return h(400,{error:"Invalid payload"})}if(!f||typeof f!="object"||Array.isArray(f)||Object.keys(f).length!==2||!Object.hasOwn(f,"_type")||!Object.hasOwn(f,"_id"))return h(400,{error:"Invalid payload"});let{_type:g,_id:k}=f;if(typeof g!="string"||!/^[A-Za-z][A-Za-z0-9_]{0,63}$/.test(g)||typeof k!="string"||!/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/.test(k))return h(400,{error:"Invalid payload"});if(!Object.hasOwn(t,g)||/^(drafts|versions)\./.test(k))return h(400,{error:"Unsupported document"});let Q=w(n,{types:t[g],ids:[k]});try{for(let b of Q)ue(b,{expire:0})}catch{return h(500,{error:"Could not revalidate"})}return h(200,{revalidated:!0})};return Object.freeze({POST:c,GET:c,HEAD:c,PUT:c,PATCH:c,DELETE:c,OPTIONS:c})}export{x as MENU_DECORATIONS,I as MENU_LAYOUTS,M as MENU_LAYOUT_DEFAULTS,se as createNextCmsReader,ge as createRevalidateRoute,ie as menuQuery,W as menuTags,E as parseMenuDocument};
|
|
6
6
|
//# sourceMappingURL=next.mjs.map
|